Annotation of researchv10dc/vol2/f77/bwk.77.ms, revision 1.1.1.1

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