Annotation of researchv10dc/vol2/f77/of77.ms, revision 1.1

1.1     ! root        1: .so ../ADM/mac
        !             2: .XX f77 315 "A Portable Fortran 77 Compiler"
        !             3: .de XX
        !             4: .IP "\f(CW\\$1\f1" 5
        !             5: ..
        !             6: .EQ
        !             7: delim $$
        !             8: .EN
        !             9: . \".ND "1 August 1978"
        !            10: .ND "30 June 1989"
        !            11: .TL
        !            12: A Portable Fortran 77 Compiler\(dg
        !            13: .AU
        !            14: S. I. Feldman
        !            15: P. J. Weinberger
        !            16: .AI
        !            17: .MH
        !            18: .AB
        !            19: .PP
        !            20: We report here on the first complete implementation of a compiler and run-time system for
        !            21: the current Fortran language, known as Fortran 77.
        !            22: The compiler is designed to be portable,
        !            23: to be correct and complete,
        !            24: and to generate code compatible with calling sequences produced by C compilers.
        !            25: In particular, this Fortran is quite usable on
        !            26: .UX
        !            27: systems.
        !            28: In this paper, we describe the language compiled,
        !            29: interfaces between procedures,
        !            30: and file formats assumed by the I/O system.
        !            31: An appendix describes the Fortran 77 language.
        !            32: .AE
        !            33: .2C
        !            34: .FS
        !            35: \(dg This is a version of |reference(f77 v7man) revised by D. M. Gay.
        !            36: .FE
        !            37: .NH 1
        !            38: Introduction
        !            39: .PP
        !            40: The current Fortran language, known as Fortran 77,
        !            41: became an official American National Standard|reference(standard f77)
        !            42: on April 3, 1978.
        !            43: Fortran 77 supplants 1966 Standard Fortran|reference(standard f66).
        !            44: We report here on a compiler and run-time system for Fortran 77.
        !            45: The compiler and computation library were written by SIF, the I/O system by PJW.
        !            46: We believe ours to be the first complete Fortran 77 system
        !            47: to have been implemented.
        !            48: This compiler is designed to be portable to a number of different machines,
        !            49: to be correct and complete,
        !            50: and to generate code compatible with calling sequences produced
        !            51: by compilers for the C language|reference(cbook).
        !            52: In particular,
        !            53: it is in use on
        !            54: .UX
        !            55: systems.
        !            56: The C compilers in use at Bell Labs include two families,
        !            57: one based on D. M. Ritchie's PDP-11 compiler|reference(%type pamphlet
        !            58: %author D. M. Ritchie
        !            59: %title private communication), another
        !            60: based on S. C. Johnson's portable C compiler|reference(pcc).
        !            61: This Fortran compiler can drive the second passes of either family.
        !            62: In this paper, we describe the language compiled,
        !            63: interfaces between procedures,
        !            64: and file formats assumed by the I/O system.
        !            65: .NH 2
        !            66: Usage
        !            67: .PP
        !            68: .I F77
        !            69: is a general-purpose command for compiling and loading Fortran and Fortran-related files.
        !            70: The command to run the compiler is
        !            71: .P1
        !            72: f77  \fIflags  file . . .\fR
        !            73: .P2
        !            74: EFL|reference(efl) and Ratfor|reference(ratfor)
        !            75: source files will be preprocessed before
        !            76: being presented to the Fortran compiler.
        !            77: C and assembler source files will be compiled by the appropriate programs.
        !            78: Object files will be loaded.
        !            79: (The
        !            80: .I f77
        !            81: and
        !            82: .I cc
        !            83: commands cause slightly different loading sequences to be generated,
        !            84: since Fortran programs need a few extra libraries and a different startup routine
        !            85: than do C programs.)
        !            86: The following file name suffixes are understood:
        !            87: .TS
        !            88: center;
        !            89: aFCW a.
        !            90: \&.f   Fortran source file
        !            91: \&.e   EFL source file
        !            92: \&.r   Ratfor source file
        !            93: \&.c   C source file
        !            94: \&.s   Assembler source file
        !            95: \&.o   Object file
        !            96: .TE
        !            97: .Tm Options    s
        !            98: The following flags are understood:
        !            99: .XX -S
        !           100: Generate assembler output for each source file, but do not assemble it.
        !           101: Assembler output for a source file
        !           102: .CW x.f ,
        !           103: .CW x.e ,
        !           104: .CW x.r ,
        !           105: or
        !           106: .CW x.c
        !           107: is put on file
        !           108: .CW x.s .
        !           109: .XX -c
        !           110: Compile but do not load.
        !           111: Output for
        !           112: .CW x.f ,
        !           113: .CW x.e ,
        !           114: .CW x.r ,
        !           115: .CW x.c ,
        !           116: or
        !           117: .CW x.s
        !           118: is put on file
        !           119: .CW x.o .
        !           120: .XX -m
        !           121: Apply the M4 macro preprocessor to each EFL or Ratfor source file before using the appropriate compiler.
        !           122: .XX -p
        !           123: Generate code to produce usage profiles.
        !           124: .XX "-o \fIf\fR"
        !           125: Put executable module on file
        !           126: .I f.
        !           127: (Default is
        !           128: .CW a.out ).
        !           129: .XX -w
        !           130: Suppress all warning messages.
        !           131: .XX -w66\ 
        !           132: Suppress warnings about Fortran 66 features used.
        !           133: .XX -O
        !           134: Invoke the C object code optimizer.
        !           135: .XX -C
        !           136: Compile code the checks that subscripts are within array bounds.
        !           137: .XX -onetrip\ \ 
        !           138: Compile code that performs every
        !           139: .CW do
        !           140: loop at least once.
        !           141: (See Section 2.12).
        !           142: .XX -U
        !           143: Do not convert upper case letters to lower case.
        !           144: The default is to convert Fortran programs to lower case.
        !           145: .XX -u
        !           146: Make the default type of a variable
        !           147: .CW undefined.
        !           148: (See Section 2.3).
        !           149: .XX -I2
        !           150: On machines which support short integers,
        !           151: make the default integer constants and variables short.
        !           152: (\f(CW-I4\fR is the standard value of this option).  (See Section 2.14).
        !           153: All logical quantities will be short.
        !           154: .XX -E
        !           155: The remaining characters in the argument are used as an EFL flag argument.
        !           156: .XX -R
        !           157: The remaining characters in the argument are used as a Ratfor flag argument.
        !           158: .XX -F
        !           159: Ratfor and EFL source programs are pre-processed into Fortran files,
        !           160: but those files are not compiled or removed.
        !           161: .in -1i
        !           162: .LP
        !           163: Other flags,
        !           164: all library names (arguments beginning \f(CW-l\fR),
        !           165: and any names not ending with one of the understood suffixes are passed to the loader.
        !           166: .NH 2
        !           167: Documentation Conventions
        !           168: .PP
        !           169: In running text, we write Fortran keywords and other literal strings in boldface lower case.
        !           170: Examples will be presented in lightface lower case.
        !           171: Names representing a class of values will be printed in italics.
        !           172: .NH 2
        !           173: Implementation Strategy
        !           174: .PP
        !           175: The compiler and library are written entirely in C.
        !           176: The compiler  generates C compiler intermediate code.
        !           177: Since there are C compilers running on a variety of machines,
        !           178: relatively small changes will make this Fortran compiler generate code for any of them.
        !           179: Furthermore, this approach guarantees that the resulting programs are compatible with C usage.
        !           180: The runtime computational library is complete.
        !           181: The mathematical functions rely on the functions in C's \fIlibm\fR.
        !           182: The runtime I/O library makes use of D. M. Ritchie's Standard C I/O package
        !           183: |reference(stdio)
        !           184: for transferring data.
        !           185: With the exception described below, only documented calls are used,
        !           186: so it should be relatively easy to modify the I/O library
        !           187: to run on other operating
        !           188: systems.
        !           189: .NH 1
        !           190: Language Extensions
        !           191: .PP
        !           192: Fortran 77 includes almost all of Fortran 66 as a subset.
        !           193: We describe the differences briefly in the Appendix.
        !           194: The most important additions are a character string data type,
        !           195: file-oriented input/output statements, and random access I/O.
        !           196: Also, the language has been cleaned up considerably.
        !           197: .PP
        !           198: In addition to implementing the language specified in the Fortran 77 Standard,
        !           199: our compiler implements a few extensions described in this section.
        !           200: Most are useful additions to the language.
        !           201: The remainder are extensions
        !           202: to make it easier to communicate with C procedures
        !           203: or to permit compilation of
        !           204: old (1966 Standard) programs.
        !           205: .NH 2
        !           206: Double Complex Data Type
        !           207: .PP
        !           208: The new type
        !           209: .CW "double complex"
        !           210: is defined.
        !           211: Each datum is represented by a pair of double precision real variables.
        !           212: A double complex version of every
        !           213: .CW complex
        !           214: built-in function is provided.
        !           215: The specific function names begin with \f(CWz\fR instead of \f(CWc\fR.
        !           216: .NH 2
        !           217: Internal Files
        !           218: .PP
        !           219: The Fortran 77 standard introduces ``internal files'' (memory arrays), but
        !           220: restricts their use to formatted sequential I/O statements.
        !           221: Our I/O system also permits internal files to be used
        !           222: in direct and unformatted reads and writes.
        !           223: .NH 2
        !           224: Implicit Undefined statement
        !           225: .PP
        !           226: Fortran 66 has a fixed rule that the type of a variable that does not appear in a type statement
        !           227: is
        !           228: .CW integer
        !           229: if its first letter is one of
        !           230: .CW ijklmn
        !           231: and
        !           232: .CW real
        !           233: otherwise.
        !           234: Fortran 77 has an
        !           235: .CW implicit
        !           236: statement for overriding this rule.
        !           237: As an aid to good programming practice, we permit an additional type,
        !           238: .CW undefined .
        !           239: The statement
        !           240: .P1
        !           241: implicit undefined(a-z)
        !           242: .P2
        !           243: turns off the automatic data typing mechanism,
        !           244: and the compiler will issue a diagnostic for each variable that is used but does
        !           245: not appear in a type statement.
        !           246: Specifying the
        !           247: .CW -u
        !           248: compiler flag is equivalent to beginning each procedure with this statement.
        !           249: .NH 2
        !           250: Recursion
        !           251: .PP
        !           252: Procedures may call themselves, directly or through a chain of other procedures.
        !           253: .NH 2
        !           254: Automatic Storage
        !           255: .PP
        !           256: Two new keywords are recognized,
        !           257: .CW static
        !           258: and
        !           259: .CW automatic .
        !           260: These keywords may appear as ``types'' in type statements and in
        !           261: .CW implicit
        !           262: statements.
        !           263: Local variables are static by default;
        !           264: there is exactly one copy of the datum, and its value is retained between calls.
        !           265: There is one copy of each variable declared
        !           266: .CW automatic
        !           267: for each invocation of the procedure.
        !           268: Automatic variables may not appear in
        !           269: .CW equivalence ,
        !           270: .CW data ,
        !           271: or
        !           272: .CW save
        !           273: statements.
        !           274: .NH 2
        !           275: Source Input Format
        !           276: .PP
        !           277: The Standard expects input to the compiler to be in 72 column format:
        !           278: except in comment lines,
        !           279: the first five characters are the statement number, the next is the continuation character,
        !           280: and the next sixty-six are the body of the line.
        !           281: (If there are fewer than seventy-two characters on a line, the compiler pads it with blanks;
        !           282: characters after the seventy-second are ignored).
        !           283: .PP
        !           284: To make typing Fortran programs easier,
        !           285: our compiler also accepts input in variable length lines.
        !           286: An ampersand
        !           287: .CW &
        !           288: in the first position of a line indicates a continuation
        !           289: line; the remaining characters form the body of the line.
        !           290: A tab character in one of the first six positions of a line signals the
        !           291: end of the statement number and continuation part of the line;
        !           292: the remaining characters form the body of the line.
        !           293: A tab elsewhere on the line is treated as another kind of blank by the
        !           294: compiler.
        !           295: .PP
        !           296: In the Standard, there are only 26 letters \(em Fortran is a one-case language.
        !           297: Consistent with ordinary
        !           298: .UX
        !           299: system usage, our compiler expects lower case input.
        !           300: By default, the compiler converts all upper case characters to lower case except those inside character constants.
        !           301: However, if the
        !           302: .CW -U
        !           303: compiler flag is specified, upper case letters are not transformed.
        !           304: In this mode, it is possible to specify external names with upper case letters in them,
        !           305: and to have distinct variables differing only in case,
        !           306: but then all Fortran keywords must be in lower case.
        !           307: .NH 2
        !           308: \f(CWinclude\fR Statement
        !           309: .PP
        !           310: The statement
        !           311: .P1
        !           312: include 'stuff'
        !           313: .P2
        !           314: is replaced by the contents of the file
        !           315: .CW stuff .
        !           316: .CW include s
        !           317: may be nested to a reasonable depth, currently ten.
        !           318: .NH 2
        !           319: Binary Initialization Constants
        !           320: .PP
        !           321: A
        !           322: .CW logical ,
        !           323: .CW real ,
        !           324: or
        !           325: .CW integer
        !           326: variable may be initialized in a
        !           327: .CW data
        !           328: statement
        !           329: by a binary constant, denoted by a letter followed by a quoted string.
        !           330: If the letter is
        !           331: .CW b ,
        !           332: the string is binary, and only zeros and ones are permitted.
        !           333: If the letter is
        !           334: .CW o ,
        !           335: the string is octal, with digits
        !           336: .CW 0-7 .
        !           337: If the letter is
        !           338: .CW z
        !           339: or
        !           340: .CW x ,
        !           341: the string is hexadecimal, with digits
        !           342: .CW 0-9a-f .
        !           343: Thus, the statements
        !           344: .P1
        !           345: integer a(3)
        !           346: data a / b'1010', o'12', z'a' /
        !           347: .P2
        !           348: initialize all three elements of
        !           349: .I a
        !           350: to ten.
        !           351: .NH 2
        !           352: Character Strings
        !           353: .PP
        !           354: For compatibility with C usage, the following backslash escapes are recognized:
        !           355: .TS
        !           356: center;
        !           357: aFCW a.
        !           358: \en    newline
        !           359: \et    tab
        !           360: \eb    backspace
        !           361: \ef    form feed
        !           362: \e0    null
        !           363: \e'    apostrophe (does not terminate a string)
        !           364: \e"    quotation mark (does not terminate a string)
        !           365: \e\e   \e
        !           366: \e\fIx\fP      \fIx\fR, where \fIx\fR is any other character
        !           367: .TE
        !           368: Fortran 77 only has one quoting character, the apostrophe.
        !           369: Our compiler and I/O system recognize
        !           370: both the apostrophe
        !           371: .CW '
        !           372: and the double-quote
        !           373: .CW \" .
        !           374: If a string begins with one variety of quote mark, the other may be embedded within it
        !           375: without using the repeated quote or backslash escapes.
        !           376: .PP
        !           377: Every unequivalenced scalar local character variable and every character string constant is aligned
        !           378: on an
        !           379: .CW integer
        !           380: word boundary.
        !           381: Each character string constant appearing outside a
        !           382: .CW data
        !           383: statement is followed by a
        !           384: null character to ease communication with C routines.
        !           385: .NH 2
        !           386: Hollerith
        !           387: .PP
        !           388: Fortran 77 does not have the old Hollerith (\fIn\|\f(CWh\fR)
        !           389: notation,
        !           390: though the new Standard recommends implementing the old Hollerith feature
        !           391: in order to improve compatibility with old programs.
        !           392: In our compiler, Hollerith data may be used in place of character string constants,
        !           393: and may also be used to initialize non-character variables in
        !           394: .CW data
        !           395: statements.
        !           396: .NH 2
        !           397: Equivalence Statements
        !           398: .PP
        !           399: As a very special and peculiar case,
        !           400: Fortran 66 permits an element of a multiply-dimensioned array to be represented by
        !           401: a singly-subscripted reference in
        !           402: .CW equivalence
        !           403: statements.
        !           404: Fortran 77 does not permit this usage, since
        !           405: subscript lower bounds may now be different from 1.
        !           406: Our compiler permits single subscripts in
        !           407: .CW equivalence
        !           408: statements,
        !           409: under the interpretation that all missing subscripts are equal to 1.
        !           410: A warning message is printed for each such incomplete subscript.
        !           411: .NH 2
        !           412: One-Trip \f(CWdo\fP Loops
        !           413: .PP
        !           414: The Fortran 77 Standard requires that the range of a
        !           415: .CW do
        !           416: loop not be performed
        !           417: if the initial value is already past the limit value,
        !           418: as in
        !           419: .P1
        !           420: do 10 i = 2, 1
        !           421: .P2
        !           422: The 1966 Standard stated that the effect of such a statement was undefined,
        !           423: but it was common practice that the range of a
        !           424: .CW do
        !           425: loop would be performed
        !           426: at least once.
        !           427: In order to accommodate old programs, though they were in violation of the 1966 Standard,
        !           428: the
        !           429: .CW -onetrip
        !           430: compiler flag causes non-standard loops to be generated.
        !           431: .NH 2
        !           432: Commas in Formatted Input
        !           433: .PP
        !           434: The I/O system attempts to be more lenient than the
        !           435: Standard when it seems worthwhile.
        !           436: In a formatted read of non-character variables,
        !           437: commas may be used as value separators in the input record,
        !           438: overriding the field lengths given in the format statement.
        !           439: Thus,
        !           440: the format
        !           441: .P1
        !           442: (i10, f20.10, i4)
        !           443: .P2
        !           444: will read the record
        !           445: .P1
        !           446: -345,.05e-3,12
        !           447: .P2
        !           448: correctly.
        !           449: .NH 2
        !           450: Short Integers
        !           451: .PP
        !           452: On machines that support halfword integers,
        !           453: the compiler accepts declarations of type
        !           454: .CW integer\(**2 .
        !           455: (Ordinary integers follow the Fortran rules about occupying the same
        !           456: space as a
        !           457: .CW real
        !           458: variable; they are assumed to be of C type
        !           459: .CW "long int" ;
        !           460: halfword integers are of C type
        !           461: .CW "short int" .)
        !           462: An expression involving only objects of type
        !           463: .CW integer\(**2
        !           464: is of that type.
        !           465: Generic functions return short or long integers depending on the actual types of their arguments.
        !           466: If a procedure is compiled using the
        !           467: .CW -I2
        !           468: flag, all small integer constants will be
        !           469: of type
        !           470: .CW integer\(**2 .
        !           471: If the precision of an integer-valued intrinsic function is not determined by the generic function rules,
        !           472: one will be chosen that returns the prevailing length
        !           473: (\f(CWinteger\(**2\fR when the \f(CW-I2\fR command flag is in effect).
        !           474: When the
        !           475: .CW -I2
        !           476: option is in effect, all quantities of type
        !           477: .CW logical
        !           478: will be short.
        !           479: Note that these short integer and logical quantities do not obey the standard rules for storage association.
        !           480: .NH 2
        !           481: Additional Intrinsic Functions
        !           482: .PP
        !           483: This compiler supports all of the intrinsic functions specified in the Fortran 77 Standard.
        !           484: In addition, there are functions for performing bitwise Boolean operations
        !           485: (\fIor\fR, \fIand\fR, \fIxor\fR, and \fInot\fR)
        !           486: and for accessing the
        !           487: .UX
        !           488: command arguments
        !           489: (\fIgetarg\fR and \fIiargc\fR).
        !           490: .NH 1
        !           491: Violations of the Standard
        !           492: .PP
        !           493: We know only two ways in which our Fortran system violates
        !           494: the Fortran 77 standard:
        !           495: .NH 2
        !           496: Double Precision Alignment
        !           497: .PP
        !           498: The Fortran standards (both 1966 and 1977)
        !           499: permit
        !           500: .CW common
        !           501: or
        !           502: .CW equivalence
        !           503: statements to force a double precision quantity onto an odd word boundary,
        !           504: as in the following example:
        !           505: .P1 I
        !           506: real a(4)
        !           507: double precision b,c
        !           508: .sp .5
        !           509: equivalence (a(1),b), (a(4),c)
        !           510: .P2
        !           511: Some machines (e.g., Honeywell 6000, IBM 360) require that double precision quantities be on double word boundaries;
        !           512: other machines (e.g., IBM 370), run inefficiently if this alignment rule is not observed.
        !           513: It is possible to tell which equivalenced and common variables suffer from a forced odd
        !           514: alignment, but every double precision argument would have to be assumed on a bad boundary.
        !           515: To load such a quantity on some machines,
        !           516: it would be necessary to use separate operations to move the upper and lower halves
        !           517: into the halves of an aligned temporary, then to load that double precision temporary; the reverse would be
        !           518: needed to store a result.
        !           519: We have chosen to require that all double precision real and complex quantities
        !           520: fall on even word boundaries on machines with corresponding hardware requirements,
        !           521: and to issue a diagnostic if the source code demands a violation of the rule.
        !           522: .NH 2
        !           523: \f(CWt\fR and \f(CWtl\fR Formats
        !           524: .PP
        !           525: The implementation of the
        !           526: .CW t
        !           527: (absolute tab)
        !           528: and
        !           529: .CW tl
        !           530: (leftward tab)
        !           531: format codes
        !           532: is defective.
        !           533: These codes allow rereading or rewriting part of the
        !           534: record which has already been processed.
        !           535: (See Section 6.3.2 in the Appendix.)
        !           536: The implementation uses seeks,
        !           537: so if the unit is not one which allows seeks,
        !           538: such as a terminal,
        !           539: the program is in error.
        !           540: (People who can make a case for using
        !           541: .CW tl
        !           542: should let us know.)
        !           543: A benefit of the implementation chosen is
        !           544: that there is no upper limit on the length of
        !           545: a record,
        !           546: nor is it necessary to predeclare any record
        !           547: lengths except where specifically required
        !           548: by Fortran or the operating system.
        !           549: .NH 1
        !           550: Inter-Procedure Interface
        !           551: .PP
        !           552: To be able to write C procedures that call or are called by Fortran procedures,
        !           553: it is necessary to know the conventions for procedure names,
        !           554: data representation,
        !           555: return values,
        !           556: and argument lists that the compiled code obeys.
        !           557: .NH 2
        !           558: Procedure Names
        !           559: .PP
        !           560: On
        !           561: .UX
        !           562: systems,
        !           563: the name of a common block or a Fortran procedure
        !           564: has an underscore appended to it by the compiler
        !           565: to distinguish it from a C procedure or external variable
        !           566: with the same user-assigned name.
        !           567: Fortran library procedure names have embedded underscores to avoid clashes
        !           568: with user-assigned subroutine names.
        !           569: .KF
        !           570: .TS
        !           571: center;
        !           572: c c
        !           573: l l.
        !           574: Fortran        C     
        !           575: .sp .5
        !           576: integer\(**2 x short int x;
        !           577: integer x      long int x;
        !           578: logical x      long int x;
        !           579: real x float x;
        !           580: double precision x     double x;
        !           581: complex x      struct { float r, i; } x;
        !           582: double complex x       struct { double dr, di; } x;
        !           583: character\(**6 x       char x[6];
        !           584: .TE
        !           585: .ce
        !           586: \fBTable 1. Fortran and C declarations
        !           587: .KE
        !           588: .NH 2
        !           589: Data Representations
        !           590: .PP
        !           591: Table 1 shows corresponding Fortran and C declarations:
        !           592: (By the rules of Fortran,
        !           593: .CW integer,
        !           594: .CW logical,
        !           595: and
        !           596: .CW real
        !           597: data occupy the same amount of memory).
        !           598: .NH 2
        !           599: Return Values
        !           600: .PP
        !           601: A function of type
        !           602: .CW integer ,
        !           603: .CW logical ,
        !           604: .CW real ,
        !           605: or
        !           606: .CW "double precision"
        !           607: must be declared as a C function that returns the corresponding type.
        !           608: A
        !           609: .CW complex
        !           610: or
        !           611: .CW "double complex"
        !           612: function is equivalent to a C routine
        !           613: with an additional
        !           614: initial argument that points to the place where the return value is to be stored.
        !           615: Thus,
        !           616: .P1
        !           617: complex function f( . . . )
        !           618: .P2
        !           619: is equivalent to
        !           620: .P1
        !           621: f_(temp, . . .)
        !           622: struct { float r, i; } \(**temp;
        !           623:  . . .
        !           624: .P2
        !           625: A character-valued function is equivalent to a C routine with
        !           626: two extra initial arguments:
        !           627: a data address and a length.
        !           628: Thus,
        !           629: .P1
        !           630: character\(**15 function g( . . . )
        !           631: .P2
        !           632: is equivalent to
        !           633: .P1
        !           634: g_(result, length, . . .)
        !           635: char result[ ];
        !           636: long int length;
        !           637:  . . .
        !           638: .P2
        !           639: and could be invoked in C by
        !           640: .P1
        !           641: char chars[15];
        !           642:  . . .
        !           643: g_(chars, 15L, . . . );
        !           644: .P2
        !           645: Subroutines are invoked as if they were
        !           646: .CW integer -valued
        !           647: functions
        !           648: whose value specifies which alternate return to use.
        !           649: Alternate return arguments (statement labels) are not passed to the function,
        !           650: but are used to do an indexed branch in the calling procedure.
        !           651: (If the subroutine has no entry points with alternate return arguments,
        !           652: the returned value is undefined.)
        !           653: The statement
        !           654: .P1
        !           655: call nret(\(**1, \(**2, \(**3)
        !           656: .P2
        !           657: is treated exactly as if it were the computed
        !           658: .CW goto
        !           659: .P1
        !           660: goto (1, 2, 3),  nret( )
        !           661: .P2
        !           662: .NH 2
        !           663: Argument Lists
        !           664: .PP
        !           665: All Fortran arguments are passed by address.
        !           666: In addition,
        !           667: for every non-function argument that is of type character,
        !           668: an argument giving the length of the value is passed.
        !           669: (The string lengths are
        !           670: .CW "long int"
        !           671: quantities passed by value).
        !           672: The order of arguments is then:
        !           673: extra arguments for complex and character functions,
        !           674: address for each datum or function,
        !           675: a \f(CWlong int\fR for each character argument (other than character-valued functions).
        !           676: Thus, the call in
        !           677: .P1
        !           678: external f
        !           679: character\(**7 s
        !           680: integer b(3)
        !           681:  . . .
        !           682: call sam(f, b(2), s)
        !           683: .P2
        !           684: is equivalent to that in
        !           685: .P1
        !           686: int f();
        !           687: char s[7];
        !           688: long int b[3];
        !           689:  . . .
        !           690: sam_(f, &b[1], s, 7L);
        !           691: .P2
        !           692: Note that the first element of a C array always has subscript zero,
        !           693: but Fortran arrays begin at 1 by default.
        !           694: Fortran arrays are stored in column-major order, C arrays are stored in row-major order.
        !           695: .NH 1
        !           696: File Formats
        !           697: .NH 2
        !           698: Structure of Fortran Files
        !           699: .PP
        !           700: Fortran requires four kinds of external files:
        !           701: sequential formatted and unformatted,
        !           702: and direct formatted and unformatted.
        !           703: On
        !           704: .UX
        !           705: systems,
        !           706: these are all implemented as ordinary files
        !           707: which are assumed to have the proper
        !           708: internal structure.
        !           709: .PP
        !           710: Fortran I/O is based on ``records''.
        !           711: When a direct file is opened in a Fortran program,
        !           712: the record length of the records must be given,
        !           713: and this is used by the Fortran I/O system to
        !           714: make the file look as if it is made up of records
        !           715: of the given length.
        !           716: In the special case that the record length is given
        !           717: as 1,
        !           718: the files are not considered to be divided into records,
        !           719: but are treated as byte-addressable byte strings;
        !           720: that is,
        !           721: as ordinary
        !           722: .UX
        !           723: file system files.
        !           724: (A read or write request on such a file keeps consuming bytes until
        !           725: satisfied, rather than being restricted to a single record.)
        !           726: .PP
        !           727: The peculiar requirements on sequential unformatted files
        !           728: make it unlikely that they will ever be read or written by any means except Fortran I/O statements.
        !           729: Each record is preceded and followed by
        !           730: an integer containing the record's length in bytes.
        !           731: .PP
        !           732: The Fortran I/O system breaks sequential formatted files
        !           733: into records while reading by using each newline
        !           734: as a record separator.
        !           735: The result of reading off the end of a record is undefined according to the Standard.
        !           736: The I/O system is permissive and
        !           737: treats the record as being extended by blanks.
        !           738: On output,
        !           739: the I/O system will write a newline at the end of each
        !           740: record.
        !           741: It is also possible for programs to write newlines
        !           742: for themselves.
        !           743: This is an error,
        !           744: but the only effect will be that the single record
        !           745: the user thought he wrote will be treated as
        !           746: more than one record when being read or
        !           747: backspaced over.
        !           748: .NH 2
        !           749: Portability Considerations
        !           750: .PP
        !           751: The Fortran I/O system uses only the facilities of the
        !           752: standard C I/O library,
        !           753: a widely available and fairly portable package,
        !           754: with the following exceptions.
        !           755: The I/O system needs to know whether a file
        !           756: can be used for direct I/O,
        !           757: and whether or not it is possible to backspace.
        !           758: Both of these facilities are implemented
        !           759: using the
        !           760: .I fseek
        !           761: routine,
        !           762: so there is a routine
        !           763: .I canseek
        !           764: which determines if
        !           765: .I fseek
        !           766: will have the desired effect.
        !           767: Combinations of the
        !           768: \f(CWbackspace\fR, \f(CWwrite\fR, \f(CWendfile\fR, and
        !           769: .CW close
        !           770: statements may require that a file be shortened.
        !           771: For efficiency, the \fIcopy\fR routine
        !           772: that does this job uses the
        !           773: .UX
        !           774: system calls \fIcreat\fR, \fIread\fR, \fIwrite\fR, and \fIclose\fR.
        !           775: Finally, to open write-only files, the I/O system must resort to the
        !           776: \fIcreat\fR and \fIopen\fR system calls.
        !           777: .NH 2
        !           778: Pre-Connected Files and File Positions
        !           779: .PP
        !           780: Units 5, 6, and 0 are preconnected when the program starts.
        !           781: Unit 5 is connected to the standard input,
        !           782: unit 6 is connected to the standard output,
        !           783: and unit 0 is connected to the standard error unit.
        !           784: All are connected for sequential formatted I/O.
        !           785: .PP
        !           786: All the other units are also preconnected when execution
        !           787: begins.
        !           788: Unit
        !           789: .I n
        !           790: is connected to a file named \f(CWfort.\fIn\fR.
        !           791: These files need not exist,
        !           792: nor will they be created unless their units are used
        !           793: without first executing an
        !           794: .CW open .
        !           795: The default connection is for sequential formatted I/O.
        !           796: .PP
        !           797: The Standard does not specify where a file which has been explicitly \f(CWopen\fRed
        !           798: for sequential I/O is initially positioned.
        !           799: Following common practice, the I/O system positions the file
        !           800: at its beginning (and has done so for several years).
        !           801: Originally it attempted to position the file
        !           802: at the end, but this was a frequent source of confusion, and it
        !           803: limited portability.
        !           804: . \"In fact,
        !           805: . \"the I/O system attempts to position the file at the end,
        !           806: . \"so a
        !           807: . \".B write
        !           808: . \"will append to the file and a
        !           809: . \".B read
        !           810: . \"will result in an end-of-file indication.
        !           811: . \"To position a file to its beginning,
        !           812: . \"use a
        !           813: . \".B rewind
        !           814: . \"statement.
        !           815: The preconnected units
        !           816: 0, 5, and 6 are positioned as they come
        !           817: from the program's parent process.
        !           818: .NH
        !           819: References
        !           820: .LP
        !           821: |reference_placement
        !           822: .NH
        !           823: Appendix.  Differences Between Fortran 66 and Fortran 77
        !           824: .PP
        !           825: The following is a very brief description of the differences
        !           826: between the 1966 and the 1977 Standard languages.
        !           827: We assume that the reader is familiar with Fortran 66.
        !           828: We do not pretend to be complete, precise,
        !           829: or unbiased,
        !           830: but plan to describe what we feel are the most important aspects of the new language.
        !           831: .NH 0
        !           832: Features Deleted from Fortran 66
        !           833: .NH 2
        !           834: Hollerith
        !           835: .PP
        !           836: All notions of ``Hollerith''
        !           837: (\fIn\|\f(CWh\fR)
        !           838: as data
        !           839: have been officially removed, although our compiler, like almost all in the foreseeable future,
        !           840: will continue to support this archaism.
        !           841: .NH 2
        !           842: Extended Range
        !           843: .PP
        !           844: In Fortran 66, under a set of very restrictive and rarely understood conditions, it is permissible
        !           845: to jump out of the range of a
        !           846: .CW do
        !           847: loop, then jump back into it.
        !           848: Extended range has been removed in the Fortran 77 language.
        !           849: The restrictions are so special, and the implementation of extended range is so unreliable in many compilers,
        !           850: that this change really counts as no loss.
        !           851: .NH 1
        !           852: Program Form
        !           853: .NH 2
        !           854: Blank Lines
        !           855: .PP
        !           856: Completely blank lines are now legal comment lines.
        !           857: .NH 2
        !           858: Program and Block Data Statements
        !           859: .PP
        !           860: A main program may now begin with a statement that gives that program an external name:
        !           861: .P1
        !           862: program work
        !           863: .P2
        !           864: Block data procedures may also have names.
        !           865: .P1
        !           866: block data stuff
        !           867: .P2
        !           868: There is now a rule that only
        !           869: .I one
        !           870: unnamed
        !           871: block data procedure may appear in a program.
        !           872: (This rule is not enforced by our system.)
        !           873: The Standard does not specify the effect of the program and block data names,
        !           874: but they are clearly intended to aid conventional loaders.
        !           875: .NH 2
        !           876: ENTRY Statement
        !           877: .PP
        !           878: Multiple entry points are now legal.
        !           879: Subroutine and function subprograms may have additional entry points,
        !           880: declared by an
        !           881: .CW entry
        !           882: statement with an optional argument list.
        !           883: .P1
        !           884: entry extra(a, b, c)
        !           885: .P2
        !           886: Execution begins at the first statement following the
        !           887: .CW entry
        !           888: line.
        !           889: All variable declarations must precede all executable statements in the procedure.
        !           890: If the procedure begins with a
        !           891: .CW subroutine
        !           892: statement,
        !           893: all entry points are subroutine names.
        !           894: If it begins with a
        !           895: .CW function
        !           896: statement, each entry is a function entry point,
        !           897: with type determined by the type declared for the entry name.
        !           898: If any entry is a character-valued function,
        !           899: then all entries must be.
        !           900: In a function, an entry name of the same type as that where control entered
        !           901: must be assigned a value.
        !           902: Arguments do not retain their values between calls.
        !           903: (The ancient trick of calling one entry point with a large number of arguments
        !           904: to cause the procedure to ``remember'' the locations of those arguments,
        !           905: then invoking an entry with just a few arguments for later calculation,
        !           906: is still illegal.
        !           907: Furthermore, the trick doesn't work in our implementation,
        !           908: since arguments are not kept in static storage.)
        !           909: .NH 2
        !           910: \f(CWdo\fP Loops
        !           911: .PP
        !           912: .CW do
        !           913: variables and range parameters may now be of integer, real, or double precision types.
        !           914: (The use of floating point
        !           915: .CW do
        !           916: variables is very dangerous
        !           917: because of the possibility of unexpected roundoff,
        !           918: and we strongly recommend against their use).
        !           919: The action of the
        !           920: .CW do
        !           921: statement is now defined for all values of the
        !           922: .CW do
        !           923: parameters.
        !           924: The statement
        !           925: .P1
        !           926: do 10 i = l, u, d
        !           927: .P2
        !           928: performs one iteration if $l ~=~ u$ and
        !           929: $ max (0^,^ left floor ( u - l ) / d^ right floor )$
        !           930: iterations otherwise.
        !           931: The
        !           932: .CW do
        !           933: variable has a predictable value when exiting a loop:
        !           934: the value at the time a
        !           935: .CW goto
        !           936: or
        !           937: .CW return
        !           938: terminates the loop;
        !           939: otherwise
        !           940: the value that failed the limit test.
        !           941: .NH 2
        !           942: Alternate Returns
        !           943: .PP
        !           944: In a
        !           945: .CW subroutine
        !           946: or subroutine
        !           947: .CW entry
        !           948: statement,
        !           949: some of the arguments may be noted by an asterisk, as in
        !           950: .P1
        !           951: subroutine s(a, \(**, b, \(**)
        !           952: .P2
        !           953: The meaning of the ``alternate returns'' is described in section 5.2 of the Appendix.
        !           954: .NH 1
        !           955: Declarations
        !           956: .NH 2
        !           957: \f(CWcharacter\fP Data Type
        !           958: .PP
        !           959: One of the biggest improvements to the language is the addition of a character-string data type.
        !           960: Local and
        !           961: common character variables must have a length denoted by a constant expression:
        !           962: .P1
        !           963: character\(**17 a, b(3,4)
        !           964: character\(**(6+3) c
        !           965: .P2
        !           966: If the length is omitted entirely, it is assumed equal to 1.
        !           967: A character string argument may have a constant length,
        !           968: or the length may be declared to be the same as that of the corresponding actual argument at run time
        !           969: by a statement like
        !           970: .P1
        !           971: character\(**(\(**) a
        !           972: .P2
        !           973: (There is an intrinsic function
        !           974: .CW len
        !           975: that returns the actual length of a character string).
        !           976: Character arrays and common blocks containing character variables must be packed:
        !           977: in an array of character variables, the first character of one element must follow the last character of
        !           978: the preceding element, without holes.
        !           979: .NH 2
        !           980: \f(CWimplicit\fP Statement
        !           981: .PP
        !           982: The traditional implied declaration rules still hold:
        !           983: a variable whose name begins with one of
        !           984: .CW ijklmn
        !           985: is of type
        !           986: .CW integer .
        !           987: Other variables are of type
        !           988: .CW real
        !           989: unless otherwise declared.
        !           990: This general rule may be overridden with an
        !           991: .CW implicit
        !           992: statement:
        !           993: .P1 0
        !           994: implicit real(a-c,g), complex(w-z)
        !           995: implicit character*(17) (s)
        !           996: .P2
        !           997: declares that variables whose name begins with one of
        !           998: .CW abcg
        !           999: are
        !          1000: .CW real ;
        !          1001: those beginning with
        !          1002: .CW wxyz
        !          1003: are assumed
        !          1004: .CW complex ,
        !          1005: and so on.
        !          1006: It is still poor practice to depend on implicit typing,
        !          1007: but this statement is an industry standard.
        !          1008: .NH 2
        !          1009: \f(CWparameter\fP Statement
        !          1010: .PP
        !          1011: It is now possible to give a constant a symbolic name, as in
        !          1012: .P1 0
        !          1013: parameter (pi=3.1415d0,y=pi/3,s='hello')
        !          1014: .P2
        !          1015: The type of each parameter name is governed by the same implicit and explicit rules as for a variable.
        !          1016: The right side of each equal sign must be a constant expression
        !          1017: (an expression made up of constants, operators, and already defined parameters).
        !          1018: .NH 2
        !          1019: Array Declarations
        !          1020: .PP
        !          1021: Arrays may now have as many as seven dimensions.
        !          1022: (Only three were permitted in 1966).
        !          1023: The lower bound of each dimension may be declared
        !          1024: to be other than 1 by
        !          1025: using a colon.
        !          1026: Furthermore, an adjustable array bound may be an integer expression involving constants,
        !          1027: arguments, and variables in
        !          1028: .CW common .
        !          1029: .P1 0
        !          1030: real a(-5:3, 7, m:n), b(n+1:2\(**n)
        !          1031: .P2
        !          1032: The upper bound on the last dimension of an array argument may be denoted by an asterisk
        !          1033: to indicate that the upper bound is not specified:
        !          1034: .P1 0
        !          1035: integer a(5, \(**),  b(\(**), c(0:1, -2:\(**)
        !          1036: .P2
        !          1037: .NH 2
        !          1038: \f(CWsave\fP Statement
        !          1039: .PP
        !          1040: A poorly known rule of Fortran 66 is that local variables in a procedure do not necessarily retain their values between
        !          1041: invocations of that procedure.
        !          1042: At any instant in the execution of a program,
        !          1043: if a common block is declared neither in the currently executing procedure
        !          1044: nor in any of the procedures in the chain of callers,
        !          1045: all of the variables in that common block also become undefined.
        !          1046: (The only exceptions are variables that have been defined in a
        !          1047: .CW data
        !          1048: statement and never changed).
        !          1049: These rules permit overlay and stack implementations for the affected variables.
        !          1050: Fortran 77 permits one to specify that certain variables and common blocks are to retain their
        !          1051: values between invocations.
        !          1052: The declaration
        !          1053: .P1
        !          1054: save a, /b/, c
        !          1055: .P2
        !          1056: leaves the values of the variables
        !          1057: .CW a
        !          1058: and
        !          1059: .CW c
        !          1060: and all of the contents of common block
        !          1061: .CW b
        !          1062: unaffected by a return.
        !          1063: The simple declaration
        !          1064: .P1
        !          1065: save
        !          1066: .P2
        !          1067: has this effect on all variables and common blocks in the procedure.
        !          1068: A common block must be
        !          1069: .CW save d
        !          1070: in every procedure in which it is declared if the desired effect is to occur.
        !          1071: .NH 2
        !          1072: \f(CWintrinsic\fP Statement
        !          1073: .PP
        !          1074: All of the functions specified in the Standard
        !          1075: are in the single category ``intrinsic functions'',
        !          1076: rather than being divided into ``intrinsic'' and ``basic external'' functions.
        !          1077: If an intrinsic function is to be passed to another procedure, it must be declared
        !          1078: .CW intrinsic .
        !          1079: Declaring it
        !          1080: .CW external
        !          1081: (as in Fortran 66) causes a function other than the built-in one to be passed.
        !          1082: .NH 1
        !          1083: Expressions
        !          1084: .NH 2
        !          1085: Character Constants
        !          1086: .PP
        !          1087: Character string constants are marked by strings surrounded by apostrophes.
        !          1088: If an apostrophe is to be included in a constant, it is repeated:
        !          1089: .P1
        !          1090:  'abc'
        !          1091:  'ain''t'
        !          1092: .P2
        !          1093: There are no null (zero-length) character strings in Fortran 77.
        !          1094: Our compiler has two different quotation marks,
        !          1095: .CW '
        !          1096: and
        !          1097: .CW \" .
        !          1098: (See Section 2.9 in the main text.)
        !          1099: .NH 2
        !          1100: Concatenation
        !          1101: .PP
        !          1102: One new operator has been added, character string concatenation, marked by a double slash
        !          1103: .CW // .
        !          1104: The result of a concatenation is the string containing the characters of the left operand followed by the characters of
        !          1105: the right operand.
        !          1106: The strings
        !          1107: .P1
        !          1108:  'ab' // 'cd'
        !          1109:  'abcd'
        !          1110: .P2
        !          1111: are equal.
        !          1112: The strings being concatenated must be of constant length in all concatenations
        !          1113: that are not the right sides of assignments.
        !          1114: (The only concatenation expressions in which a
        !          1115: character string declared adjustable with a
        !          1116: .CW *(*)
        !          1117: modifier
        !          1118: or a substring denotation with nonconstant position values may appear
        !          1119: are the right sides of assignments).
        !          1120: .NH 2
        !          1121: Character String Assignment
        !          1122: .PP
        !          1123: The left and right sides of a character assignment may not share storage.
        !          1124: (The assumed implementation of character assignment is to copy characters from the right to the left side.)
        !          1125: If the left side is longer than the right, it is padded with blanks.
        !          1126: If the left side is shorter than the right, trailing characters are discarded.
        !          1127: .NH 2
        !          1128: Substrings
        !          1129: .PP
        !          1130: It is possible to extract a substring of a character variable or character array element, using the colon notation:
        !          1131: .P1
        !          1132: a(i,\|j) (m:n)
        !          1133: .P2
        !          1134: is the string of $(n-m+1)$ characters beginning at the
        !          1135: $m sup th$ character of the character array element $a sub ij$.
        !          1136: Results are undefined unless $m<=n$.
        !          1137: Substrings may be used on the left sides of assignments and as procedure actual arguments.
        !          1138: .NH 2
        !          1139: Exponentiation
        !          1140: .PP
        !          1141: It is now permissible to raise real quantities to complex powers,
        !          1142: or complex quantities to real or complex powers.
        !          1143: (The principal part of the logarithm is used).
        !          1144: Also, multiple exponentiation is now defined:
        !          1145: .P1
        !          1146: a\(**\(**b\(**\(**c = a \(**\(** (b\(**\(**c)
        !          1147: .P2
        !          1148: .NH 2
        !          1149: Relaxation of Restrictions
        !          1150: .PP
        !          1151: Mixed mode expressions are now permitted.
        !          1152: (For instance,
        !          1153: it is permissible to combine integer and complex quantities in an expression.)
        !          1154: .PP
        !          1155: Constant expressions are permitted where a constant is allowed,
        !          1156: except in
        !          1157: .CW data
        !          1158: statements.
        !          1159: (A constant expression is made up of explicit constants and
        !          1160: .CW parameter s
        !          1161: and the Fortran operators,
        !          1162: except for exponentiation to a floating-point power).
        !          1163: An adjustable dimension may now be an integer expression involving constants,
        !          1164: arguments, and variables in
        !          1165: .CW common .
        !          1166: .PP
        !          1167: Subscripts may now be general integer expressions;
        !          1168: the old
        !          1169: $c v +- c'$
        !          1170: rules have been removed.
        !          1171: .CW do
        !          1172: loop bounds may be general integer, real, or double precision expressions.
        !          1173: Computed
        !          1174: .CW goto
        !          1175: expressions and I/O unit numbers may be general integer expressions.
        !          1176: .NH 1
        !          1177: Executable Statements
        !          1178: .NH 2
        !          1179: Block If
        !          1180: .PP
        !          1181: At last, an
        !          1182: if-then-else
        !          1183: branching structure (``Block If'') has been added to Fortran.
        !          1184: A Block If begins with a statement of the form
        !          1185: .P1
        !          1186: if ( . . . ) then
        !          1187: .P2
        !          1188: and ends with an
        !          1189: .P1
        !          1190: end if
        !          1191: .P2
        !          1192: statement.
        !          1193: Two other new statements may appear in a Block If.
        !          1194: There may be several
        !          1195: .P1
        !          1196: else if(. . .) then
        !          1197: .P2
        !          1198: statements,
        !          1199: followed by at most one
        !          1200: .P1
        !          1201: else
        !          1202: .P2
        !          1203: statement.
        !          1204: If the logical expression in the Block If statement is true,
        !          1205: the statements following it up to the
        !          1206: next
        !          1207: .CW elseif ,
        !          1208: .CW else ,
        !          1209: or
        !          1210: .CW endif
        !          1211: are executed.
        !          1212: Otherwise, the next
        !          1213: .CW elseif
        !          1214: statement in the group is executed.
        !          1215: If none of the
        !          1216: .CW elseif
        !          1217: conditions are true, control passes to the statements following the
        !          1218: .CW else
        !          1219: statement, if any.
        !          1220: (The
        !          1221: .CW else
        !          1222: must follow all
        !          1223: .CW elseif s
        !          1224: in a Block If.
        !          1225: Of course, there may be Block Ifs embedded inside of other Block If structures).
        !          1226: A case construct may be rendered
        !          1227: .P1
        !          1228: if (s .eq. 'ab') then
        !          1229:  . . .
        !          1230: else if (s .eq. 'cd') then
        !          1231:  . . .
        !          1232: else
        !          1233:  . . .
        !          1234: end if
        !          1235: .P2
        !          1236: .NH 2
        !          1237: Alternate Returns
        !          1238: .PP
        !          1239: Some of the arguments of a subroutine call may be statement labels preceded by an asterisk, as in
        !          1240: .P1
        !          1241: call joe(j, \(**10, m, \(**2)
        !          1242: .P2
        !          1243: A
        !          1244: .CW return
        !          1245: statement may have an integer expression, such as
        !          1246: .P1
        !          1247: return k
        !          1248: .P2
        !          1249: If the entry point has
        !          1250: $n$
        !          1251: alternate return (asterisk) arguments
        !          1252: and if $1<=k<=n$, the return is followed by a branch to the corresponding statement label;
        !          1253: otherwise the usual return to the statement following the
        !          1254: .CW call
        !          1255: is executed.
        !          1256: .NH 1
        !          1257: Input/Output
        !          1258: .NH 2
        !          1259: Format Variables
        !          1260: .PP
        !          1261: A format may be the value of a character expression (constant or otherwise),
        !          1262: or be stored in a character array, as in
        !          1263: .P1
        !          1264: write(6, '(i5)') x
        !          1265: .P2
        !          1266: .NH 2
        !          1267: \f(CWend=\fP, \f(CWerr=\fP, and \f(CWiostat=\fP Clauses
        !          1268: .PP
        !          1269: A
        !          1270: .CW read
        !          1271: or
        !          1272: .CW write
        !          1273: statement may contain
        !          1274: .CW end= ,
        !          1275: .CW err= ,
        !          1276: and
        !          1277: .CW iostat=
        !          1278: clauses, as in
        !          1279: .P1 0
        !          1280: write(6, 101, err=20, iostat=a(4))
        !          1281: read(5, 101, err=20, end=30, iostat=x)
        !          1282: .P2
        !          1283: Here 5 and 6 are the
        !          1284: .I unit s
        !          1285: on which the I/O is done,
        !          1286: 101 is the statement number of the associated format,
        !          1287: 20 and 30 are statement numbers,
        !          1288: and
        !          1289: .CW a
        !          1290: and
        !          1291: .CW x
        !          1292: are integers.
        !          1293: If an error occurs during I/O,
        !          1294: control returns to the program at statement 20.
        !          1295: If the end of the file is reached,
        !          1296: control returns to the program at statement 30.
        !          1297: In any case, the variable referred to in
        !          1298: the
        !          1299: .CW iostat=
        !          1300: clause is given a value when
        !          1301: the I/O statement finishes.
        !          1302: (Yes, the value is assigned to the name on the right side of the equal sign.)
        !          1303: This value is zero if all went well,
        !          1304: negative for end of file,
        !          1305: and some positive value for errors.
        !          1306: .NH 2
        !          1307: Formatted I/O
        !          1308: .NH 3
        !          1309: Character Constants
        !          1310: .PP
        !          1311: Character constants in formats are copied literally to the output.
        !          1312: Character constants cannot be read into.
        !          1313: .P1 0
        !          1314: write(6,'(i2,'' isn''''t '',i1)') 7, 4
        !          1315: .P2
        !          1316: produces
        !          1317: .P1
        !          1318:  7 isn't 4
        !          1319: .P2
        !          1320: Here the format is the character constant
        !          1321: .P1
        !          1322: (i2,' isn''t ',i1)
        !          1323: .P2
        !          1324: and the character constant
        !          1325: .P1
        !          1326:  isn't
        !          1327: .P2
        !          1328: is copied into the output.
        !          1329: .NH 3
        !          1330: Positional Editing Codes
        !          1331: .PP
        !          1332: .CW t ,
        !          1333: .CW tl ,
        !          1334: .CW tr ,
        !          1335: and
        !          1336: .CW x
        !          1337: codes
        !          1338: control where the
        !          1339: next character is in the record.
        !          1340: .CW tr\fIn
        !          1341: or \fIn\f(CWx\fR
        !          1342: specifies that the next character is
        !          1343: $n$ to the right of the current position.
        !          1344: .CW tl\fIn
        !          1345: specifies that the next character is
        !          1346: $n$ to the left of the current position,
        !          1347: allowing parts of the record to be reconsidered.
        !          1348: .CW t\fIn
        !          1349: says that the next character is to be character
        !          1350: number $n$ in the record.
        !          1351: (See section 3.2 in the main text.)
        !          1352: .NH 3
        !          1353: Colon
        !          1354: .PP
        !          1355: A colon in the format terminates the I/O operation
        !          1356: if there are no more data items in the I/O list,
        !          1357: otherwise it has no effect.
        !          1358: In the fragment
        !          1359: .P1
        !          1360: x='("hello", :, " there", i4)'
        !          1361: write(6, x) 12
        !          1362: write(6, x)
        !          1363: .P2
        !          1364: the first
        !          1365: .CW write
        !          1366: statement prints
        !          1367: .CW "hello there 12" ,
        !          1368: while the second only prints
        !          1369: .CW hello .
        !          1370: .NH 3
        !          1371: Optional Plus Signs
        !          1372: .PP
        !          1373: According to the Standard,
        !          1374: each implementation has the option of putting
        !          1375: plus signs in front of non-negative
        !          1376: numeric output.
        !          1377: The
        !          1378: .CW sp
        !          1379: format code may be used to make the optional plus
        !          1380: signs actually appear for all subsequent items
        !          1381: while the format is active.
        !          1382: The
        !          1383: .CW ss
        !          1384: format code guarantees that the I/O system will not
        !          1385: insert the optional plus signs,
        !          1386: and the
        !          1387: .CW s
        !          1388: format code restores the default behavior of
        !          1389: the I/O system.
        !          1390: (Since we never put out optional plus signs,
        !          1391: .CW ss
        !          1392: and
        !          1393: .CW s
        !          1394: codes have the same effect in our implementation.)
        !          1395: .NH 3
        !          1396: Blanks on Input
        !          1397: .PP
        !          1398: Blanks in numeric input fields,
        !          1399: other than leading blanks
        !          1400: will be ignored following a
        !          1401: .CW bn
        !          1402: code in a format
        !          1403: statement,
        !          1404: and will be treated as zeros following a
        !          1405: .CW bz
        !          1406: code in a format statement.
        !          1407: The default for a unit may be changed by using
        !          1408: the
        !          1409: .CW open
        !          1410: statement.
        !          1411: (Blanks are ignored by default.)
        !          1412: .NH 3
        !          1413: Unrepresentable Values
        !          1414: .PP
        !          1415: The Standard requires that if a numeric item
        !          1416: cannot be represented in the form required by a format code,
        !          1417: the output field must be filled with asterisks.
        !          1418: (We think this should have been an option.)
        !          1419: .NH 3
        !          1420: \f(CWI\fIw.m\fR Format
        !          1421: .PP
        !          1422: There is a new integer output code
        !          1423: .CW i\fIw.m
        !          1424: which is the same as
        !          1425: .CW i\fIw ,
        !          1426: except that there will be at least $m$
        !          1427: digits in the output field,
        !          1428: including,
        !          1429: if necessary,
        !          1430: leading zeros.
        !          1431: The case
        !          1432: .CW i\fIw\fP.0
        !          1433: is special,
        !          1434: in that if the value being printed is 0,
        !          1435: the output field is
        !          1436: entirely blank.
        !          1437: .CW i\fIw\fP.1
        !          1438: is the same as
        !          1439: .CW i\fIw .
        !          1440: .NH 3
        !          1441: Floating Point
        !          1442: .PP
        !          1443: On input, exponents may start with one of
        !          1444: .CW EeDd .
        !          1445: All have the same meaning.
        !          1446: On output we always use
        !          1447: .CW E .
        !          1448: The
        !          1449: .CW e
        !          1450: and
        !          1451: .CW d
        !          1452: format codes also have identical meanings.
        !          1453: A leading zero before the decimal point in
        !          1454: .CW e
        !          1455: output
        !          1456: without a scale factor is optional with the
        !          1457: implementation.
        !          1458: (We do not print it.)
        !          1459: There is a
        !          1460: .CW g\fIw.d
        !          1461: format code which is the same as
        !          1462: .CW e\fIw.d
        !          1463: and
        !          1464: .CW f\fIw.d
        !          1465: on input,
        !          1466: but which chooses
        !          1467: .CW f
        !          1468: or
        !          1469: .CW e
        !          1470: formats for output depending
        !          1471: on the size of the number and of $d$.
        !          1472: .NH 3
        !          1473: \f(CWa\fP Format
        !          1474: .PP
        !          1475: A codes are used for character values.
        !          1476: .CW a\fIw
        !          1477: use a field width of $w$,
        !          1478: while a plain
        !          1479: .CW a
        !          1480: uses the length of the character item.
        !          1481: .NH 2
        !          1482: Standard Units
        !          1483: .PP
        !          1484: There are default formatted input and output units.
        !          1485: The statement
        !          1486: .P1
        !          1487: read 10, a, b
        !          1488: .P2
        !          1489: reads from the standard unit using format statement 10.
        !          1490: The default unit may be explicitly specified by an asterisk, as in
        !          1491: .P1
        !          1492: read(*, 10) a,b
        !          1493: .P2
        !          1494: Similarly, the standard output units is specified by a
        !          1495: .CW print
        !          1496: statement or an asterisk unit:
        !          1497: .P1
        !          1498: print 10
        !          1499: write(*, 10)
        !          1500: .P2
        !          1501: .NH 2
        !          1502: List-Directed Formatting
        !          1503: .PP
        !          1504: List-directed I/O is a
        !          1505: kind of free form input for sequential I/O.
        !          1506: It is invoked by using an asterisk as the
        !          1507: format identifier, as in
        !          1508: .P1
        !          1509: read(6, *) a,b,c
        !          1510: .P2
        !          1511: .PP
        !          1512: On input,
        !          1513: values are separated by strings of blanks
        !          1514: and possibly a comma.
        !          1515: Values,
        !          1516: except for character strings,
        !          1517: cannot contain blanks.
        !          1518: End of record counts as a blank,
        !          1519: except in character strings,
        !          1520: where it is ignored.
        !          1521: Complex constants are given as two real constants
        !          1522: separated by a comma and enclosed in parentheses.
        !          1523: A null input field,
        !          1524: such as between two consecutive commas,
        !          1525: means the corresponding variable in the
        !          1526: I/O list is not changed.
        !          1527: Values may be preceded by repetition counts,
        !          1528: as in
        !          1529: .P1
        !          1530: 4*(3.,2.)  2*, 4*'hello'
        !          1531: .P2
        !          1532: which stands for 4 complex constants, 2 null values,
        !          1533: and 4 string constants.
        !          1534: .PP
        !          1535: For output, suitable formats are chosen for
        !          1536: each item.
        !          1537: The values of character strings are printed;
        !          1538: they are not enclosed in quotes, so they cannot be read back
        !          1539: using list-directed input.
        !          1540: .NH 2
        !          1541: Direct I/O
        !          1542: .PP
        !          1543: A file connected for direct access consists of
        !          1544: a set of equal-sized records each of which is
        !          1545: uniquely identified by a positive integer.
        !          1546: The records may be written or read in any order,
        !          1547: using direct access I/O statements.
        !          1548: .PP
        !          1549: Direct access
        !          1550: .CW read
        !          1551: and
        !          1552: .CW write
        !          1553: statements
        !          1554: have an extra argument,
        !          1555: .CW rec=,
        !          1556: which gives the record number to be read or written.
        !          1557: .P1 0
        !          1558: read(2, rec=13, err=20) (a(i), i=1, 203)
        !          1559: .P2
        !          1560: reads the thirteenth record into the array
        !          1561: .CW a.
        !          1562: .PP
        !          1563: The size of the records must be given by an
        !          1564: .CW open
        !          1565: statement
        !          1566: (see below).
        !          1567: Direct access files may be connected for either formatted
        !          1568: or unformatted I/O.
        !          1569: .NH 2
        !          1570: Internal Files
        !          1571: .PP
        !          1572: Internal files are character string objects,
        !          1573: such as variables or substrings,
        !          1574: or arrays of type character.
        !          1575: In the former cases there is only a single record
        !          1576: in the file,
        !          1577: in the latter case each array element is a record.
        !          1578: The Standard includes only sequential
        !          1579: formatted I/O on internal files.
        !          1580: (I/O is not a very precise term to use here,
        !          1581: but internal files are dealt with using
        !          1582: .CW read
        !          1583: and
        !          1584: .CW write ).
        !          1585: There is no list-directed I/O on internal files.
        !          1586: Internal files are used by giving the name of the
        !          1587: character object in place of the unit number, as in
        !          1588: .P1
        !          1589: character\(**80 x
        !          1590: read(5,"(a)") x
        !          1591: read(x,"(i3,i4)") n1,n2
        !          1592: .P2
        !          1593: which reads a card image into
        !          1594: .CW x
        !          1595: and then reads
        !          1596: two integers from the front of it.
        !          1597: A sequential
        !          1598: .CW read
        !          1599: or
        !          1600: .CW write
        !          1601: always starts at the beginning
        !          1602: of an internal file.
        !          1603: .PP
        !          1604: (We also support a compatible extension, direct I/O on internal files.
        !          1605: This is like direct I/O on external files,
        !          1606: except that the number of records in the file cannot be
        !          1607: changed.)
        !          1608: .NH 2
        !          1609: File Control Statements
        !          1610: .PP
        !          1611: These statements are used to connect and disconnect
        !          1612: units and files,
        !          1613: and to gather information about units and files.
        !          1614: .NH 3
        !          1615: \f(CWopen\fP Statement
        !          1616: .PP
        !          1617: The
        !          1618: .CW open
        !          1619: statement is used to connect a file with a
        !          1620: unit,
        !          1621: or to alter some properties of the connection.
        !          1622: The following is a minimal example.
        !          1623: .P1
        !          1624: open(1, file='fort.junk')
        !          1625: .P2
        !          1626: .CW open
        !          1627: takes a variety of arguments with meanings described below.
        !          1628: .RS
        !          1629: .      \" macros here
        !          1630: .EQ
        !          1631: delim off
        !          1632: .EN
        !          1633: .de HP
        !          1634: .RT
        !          1635: .if !\\(IP .nr IP +1
        !          1636: .sp \\n(PDu
        !          1637: .ne 3v
        !          1638: .in +\\n(PIu
        !          1639: .ti -\\n(PIu
        !          1640: \f(CW\\$1\fR\ \c
        !          1641: ..
        !          1642: .de TH
        !          1643: .RT
        !          1644: .sp \\n(PDu
        !          1645: .ne 3v
        !          1646: \f(CW\\$1\\$2\\$3\\$4\\$5\\$6\fR\ \c
        !          1647: ..
        !          1648: .      \" end of macros
        !          1649: .EQ
        !          1650: delim $$
        !          1651: .EN
        !          1652: .HP unit=
        !          1653: a small non-negative integer which is the unit to
        !          1654: which the file is to be connected.
        !          1655: We allow,
        !          1656: at the time of this writing,
        !          1657: 0 through 99.
        !          1658: If this parameter is the first one in the
        !          1659: .CW open
        !          1660: statement,
        !          1661: the
        !          1662: .CW unit=
        !          1663: can be omitted.
        !          1664: .HP iostat=
        !          1665: is the same as in
        !          1666: .CW read
        !          1667: or
        !          1668: .CW write.
        !          1669: .HP err=
        !          1670: is the same as in
        !          1671: .CW read
        !          1672: or
        !          1673: .CW write.
        !          1674: .HP file=
        !          1675: a character expression,
        !          1676: which when stripped of trailing blanks,
        !          1677: is the name of the file to be connected to the unit.
        !          1678: The filename should not be given if the
        !          1679: .CW status='scratch' .
        !          1680: .HP status=
        !          1681: one of
        !          1682: .CW 'old' ,
        !          1683: .CW 'new' ,
        !          1684: .CW 'scratch' ,
        !          1685: or
        !          1686: .CW 'unknown' .
        !          1687: If this parameter is not given,
        !          1688: .CW 'unknown'
        !          1689: is assumed.
        !          1690: If
        !          1691: .CW 'scratch'
        !          1692: is given,
        !          1693: a temporary file will be created.
        !          1694: Temporary files are destroyed at the end of execution.
        !          1695: If
        !          1696: .CW 'new'
        !          1697: is given,
        !          1698: the file will be created if it doesn't exist,
        !          1699: or truncated if it does.
        !          1700: The meaning of
        !          1701: .CW 'unknown'
        !          1702: is processor dependent;
        !          1703: our system complains if an
        !          1704: .CW 'old'
        !          1705: file does not exist,
        !          1706: and creates a nonexistent file
        !          1707: if it is
        !          1708: .CW 'unknown' .
        !          1709: .HP access=
        !          1710: .CW 'sequential'
        !          1711: or
        !          1712: .CW 'direct' ,
        !          1713: depending on whether the file is
        !          1714: to be opened for sequential or direct I/O.
        !          1715: .HP form=
        !          1716: .CW 'formatted'
        !          1717: or
        !          1718: .CW 'unformatted' .
        !          1719: .HP recl=
        !          1720: a positive integer specifying the record length of
        !          1721: the direct access file being opened.
        !          1722: We measure all record lengths in bytes.
        !          1723: On
        !          1724: .UX
        !          1725: systems a record length of 1 has the special meaning explained
        !          1726: in section 5.1 of the text.
        !          1727: .HP blank=
        !          1728: .CW 'null'
        !          1729: or
        !          1730: .CW 'zero' .
        !          1731: This parameter has meaning only for formatted I/O.
        !          1732: The default value is
        !          1733: .CW 'null' .
        !          1734: .CW 'zero'
        !          1735: means that blanks,
        !          1736: other than leading blanks,
        !          1737: in numeric input fields are to be treated as zeros.
        !          1738: .RE
        !          1739: .PP
        !          1740: Opening a new file on a unit which is already connected
        !          1741: has the effect of first closing the old file.
        !          1742: .NH 3
        !          1743: \f(CWclose\fP Statement
        !          1744: .PP
        !          1745: .CW close
        !          1746: severs the connection between a unit and a file.
        !          1747: The unit number must be given.
        !          1748: The optional parameters are
        !          1749: .CW iostat=
        !          1750: and
        !          1751: .CW err=
        !          1752: with
        !          1753: their usual meanings,
        !          1754: and
        !          1755: .CW status=
        !          1756: either
        !          1757: .CW 'keep'
        !          1758: or
        !          1759: .CW 'delete' .
        !          1760: Scratch files cannot be kept,
        !          1761: otherwise
        !          1762: .CW 'keep'
        !          1763: is the default.
        !          1764: .CW 'delete'
        !          1765: means the file will be removed.
        !          1766: A simple example is
        !          1767: .P1
        !          1768: close(3, err=17)
        !          1769: .P2
        !          1770: .NH 3
        !          1771: \f(CWinquire\fP Statement
        !          1772: .PP
        !          1773: The
        !          1774: .CW inquire
        !          1775: statement gives information about
        !          1776: a unit
        !          1777: (``inquire by unit'')
        !          1778: or a file (``inquire by file'').
        !          1779: Simple examples are:
        !          1780: .P1 0
        !          1781: inquire(unit=3, namexx)
        !          1782: inquire(file='junk', number=n, exist=l)
        !          1783: .P2
        !          1784: .RS
        !          1785: .HP file=
        !          1786: a character variable specifies the file the
        !          1787: .CW inquire
        !          1788: is about.
        !          1789: Trailing blanks in the file name are ignored.
        !          1790: .HP unit=
        !          1791: an integer variable specifies the unit the
        !          1792: .CW inquire
        !          1793: is about.
        !          1794: Exactly one of
        !          1795: .CW file=
        !          1796: or
        !          1797: .CW unit=
        !          1798: must be used.
        !          1799: .HP "iostat=, err="
        !          1800: are as before.
        !          1801: .HP exist=
        !          1802: a logical variable.
        !          1803: The logical variable is set to
        !          1804: .CW ".true."
        !          1805: if the file or unit
        !          1806: exists and is set to
        !          1807: .CW ".false."
        !          1808: otherwise.
        !          1809: .HP opened=
        !          1810: a logical variable.
        !          1811: The logical variable is set to
        !          1812: .CW ".true."
        !          1813: if the file
        !          1814: is connected to a unit or if the unit is connected
        !          1815: to a file,
        !          1816: and it is set to
        !          1817: .CW ".false."
        !          1818: otherwise.
        !          1819: .HP number=
        !          1820: an integer variable to which is assigned the
        !          1821: number of the unit connected to the file,
        !          1822: if any.
        !          1823: .HP named=
        !          1824: a logical variable to which is assigned
        !          1825: .CW ".true."
        !          1826: if the file has a name, or
        !          1827: .CW ".false."
        !          1828: otherwise.
        !          1829: .HP name=
        !          1830: a character variable to which is assigned the name
        !          1831: of the file (inquire by file) or, if known, the name of the
        !          1832: file connected to the unit (inquire by unit).
        !          1833: .HP access=
        !          1834: a character variable to which will be assigned
        !          1835: the value
        !          1836: .CW 'sequential'
        !          1837: if the connection is for
        !          1838: sequential I/O,
        !          1839: .CW 'direct'
        !          1840: if the connection is for direct I/O.
        !          1841: The value becomes undefined if there is no connection.
        !          1842: .HP sequential=
        !          1843: a character variable to which is assigned the
        !          1844: value
        !          1845: .CW 'yes'
        !          1846: if the file could be connected for
        !          1847: sequential I/O,
        !          1848: .CW 'no'
        !          1849: if the file could not be connected for sequential I/O,
        !          1850: and
        !          1851: .CW 'unknown'
        !          1852: if we can't tell.
        !          1853: .HP direct=
        !          1854: a character variable to which is assigned the value
        !          1855: .CW 'yes'
        !          1856: if the file could be connected for direct I/O,
        !          1857: .CW'no'
        !          1858: if the file could not be connected for direct
        !          1859: I/O,
        !          1860: and
        !          1861: .CW 'unknown'
        !          1862: if we can't tell.
        !          1863: .HP form=
        !          1864: a character variable to which is assigned the value
        !          1865: .CW 'formatted'
        !          1866: if the file is connected for formatted I/O,
        !          1867: or
        !          1868: .CW 'unformatted'
        !          1869: if the file is connected for unformatted
        !          1870: I/O.
        !          1871: .HP formatted=
        !          1872: a character variable to which is assigned the value
        !          1873: .CW 'yes'
        !          1874: if the file could be connected for formatted I/O,
        !          1875: .CW 'no'
        !          1876: if the file could not be connected for formatted I/O,
        !          1877: and
        !          1878: .CW 'unknown'
        !          1879: if we can't tell.
        !          1880: .HP unformatted=
        !          1881: a character variable to which is assigned the value
        !          1882: .CW 'yes'
        !          1883: if
        !          1884: the file could be connected for unformatted I/O,
        !          1885: .CW 'no'
        !          1886: if the file could not be connected for unformatted I/O,
        !          1887: and
        !          1888: .CW 'unknown'
        !          1889: if we can't tell.
        !          1890: .HP recl=
        !          1891: an integer variable to which is assigned the record length
        !          1892: of the records in the file if the file is connected
        !          1893: for direct access.
        !          1894: .HP nextrec=
        !          1895: an integer variable to which is assigned one more
        !          1896: than the number of the last record read from a file connected
        !          1897: for direct access.
        !          1898: .HP blank=
        !          1899: a character variable to which is assigned the value
        !          1900: .CW 'null'
        !          1901: if null blank control is in effect for the file
        !          1902: connected for formatted I/O,
        !          1903: .CW 'zero'
        !          1904: if blanks are being converted to zeros and
        !          1905: the file is connected for formatted I/O.
        !          1906: .RE
        !          1907: .PP
        !          1908: The gentle reader
        !          1909: will remember that the people who wrote the standard
        !          1910: probably weren't thinking of his needs.
        !          1911: Here is an example.
        !          1912: The declarations are omitted.
        !          1913: .P1
        !          1914: open(1, file="/dev/console")
        !          1915: .P2
        !          1916: On a
        !          1917: .UX
        !          1918: system this statement opens the console for formatted sequential
        !          1919: I/O.
        !          1920: An
        !          1921: .CW inquire
        !          1922: statement for either unit 1 or file
        !          1923: .CW "/dev/console"
        !          1924: would reveal that the file exists, is connected to unit 1,
        !          1925: has a name, namely 
        !          1926: .CW "/dev/console" ,
        !          1927: is opened for sequential I/O,
        !          1928: could be connected for sequential I/O,
        !          1929: could not be connected for direct I/O (can't seek),
        !          1930: is connected for formatted I/O,
        !          1931: could be connected for formatted I/O,
        !          1932: could not be connected for unformatted I/O
        !          1933: (can't seek),
        !          1934: has neither a record length nor a next record number,
        !          1935: and is ignoring blanks in numeric fields.
        !          1936: .PP
        !          1937: In the
        !          1938: .UX
        !          1939: system environment,
        !          1940: the only way to discover what permissions you have
        !          1941: for a file is to open it and try to read and write it.
        !          1942: The
        !          1943: .CW err=
        !          1944: parameter will return system error numbers.
        !          1945: The
        !          1946: .CW inquire
        !          1947: statement does not give a way of determining permissions.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.