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

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