12 INPUT/OUTPUT STATEMENTS

Input statements provide the means of transferring data from external media to internal storage or from an internal file to internal storage. This process is called reading. Output statements provide the means of transferring data from internal storage to external media or from internal storage to an internal file. This process is called writing. Some input/output statements specify that editing of the data is to be performed.

In addition to the statements that transfer data, there are auxiliary input/output statements to manipulate the external medium, or to inquire about or describe the properties of the connection to the external medium.

There are nine input/output statements:

  1. READ
  2. WRITE
  3. PRINT
  4. OPEN
  5. CLOSE
  6. INQUIRE
  7. BACKSPACE
  8. ENDFILE
  9. REWIND

The READ, WRITE, and PRINT statements are data transfer input/output statements ( 12.8). The OPEN, CLOSE, INQUIRE, BACKSPACE, ENDFILE, and REWIND statements are auxiliary input/output statements ( 12.10). The BACKSPACE, ENDFILE, and REWIND statements are file positioning input/output statements ( 12.10.4).

12.1 Records

A record is a sequence ( 2.1) of values or a sequence of characters. For example, a punched card is usually considered to be a record. However, a record does not necessarily correspond to a physical entity. There are three kinds of records:
  1. Formatted
  2. Unformatted
  3. Endfile

12.1.1 Formatted Record.

A formatted record consists of a sequence of characters that are capable of representation in the processor. The length of a formatted record is measured in characters and depends primarily on the number of characters put into the record when it is written. However, it may depend on the processor and the external medium. The length may be zero. Formatted records may be read or written only by formatted input/output statements ( 12.8.1).

Formatted records may be prepared by some means other than FORTRAN; for example, by some manual input device.

12.1.2 Unformatted Record.

An unformatted record consists of a sequence of values in a processor-dependent form and may contain both character and noncharacter data or may contain no data. The length of an unformatted record is measured in processor-dependent units and depends on the output list ( 12.8.2) used when it is written, as well as on the processor and the external medium. The length may be zero.

Unformatted records may be read or written only by unformatted input/output statements ( 12.8.1).

12.1.3 Endfile Record.

An endfile record is written by an ENDFILE statement. An endfile record may occur only as the last record of a file. An endfile record does not have a length property.

12.2 Files

A file is a sequence ( 2.1) of records.

There are two kinds of files:

  1. External
  2. Internal

12.2.1 File Existence.

At any given time, there is a processor-determined set of files that are said to exist for an executable program. A file may be known to the processor, yet not exist for an executable program at a particular time. For example, security reasons may prevent a file from existing for an executable program. A file may exist and contain no records; an example is a newly created file not yet written.

To create a file means to cause a file to exist that did not previously exist. To delete a file means to terminate the existence of the file.

All input/output statements may refer to files that exist. The INQUIRE, OPEN, CLOSE, WRITE, PRINT, and ENDFILE statements may also refer to files that do not exist.

12.2.2 File Properties.

At any given time, there is a processor-determined set of allowed access methods, a processor-determined set of allowed forms, and a processor-determined set of allowed record lengths for a file.

A file may have a name; a file that has a name is called a named file. The name of a named file is a character string. The set of allowable names is processor dependent and may be empty.

12.2.3 File Position.

A file that is connected to a unit ( 12.3) has a position property. Execution of certain input/output statements affects the position of a file. Certain circumstances can cause the position of a file to become indeterminate.

The initial point of a file is the position just before the first record The terminal point is the position just after the last record.

If a file is positioned within a record, that record is the current record; otherwise, there is no current record.

Let n be the number of records in the file. If 1 < i <= n and a file is positioned within the ith record or between the (i-1)th record and the ith record, the (i-1)th record is the preceding record. If n >=1 and the file is positioned at its terminal point, the preceding record is the nth and last record. If n=0 or if a file is positioned at its initial point or within the first record, there is no preceding record.

If 1 <= i < n and a file is positioned within the ith record or between the ith and (i+1)th record, the (i+1)th record is the next record. If n >= 1 and the file is positioned at its initial point, the first record is the next record. If n=0 or if a file is positioned at its terminal point or within the nth and last record, there is no next record.

12.2.4 File Access.

There are two methods of accessing the records of an external file: sequential and direct. Some files may have more than one allowed access method; other files may be restricted to one access method. For example, a processor may allow only sequential access to a file on magnetic tape. Thus, the set of allowed access methods depends on the file and the processor.

The method of accessing the file is determined when the file is connected to a unit ( 12.3.2).

An internal file must be accessed sequentially.

12.2.4.1 Sequential Access.

When connected for sequential access, a file has the following properties:
  1. The order of the records is the order in which they were written if the direct access method is not a member of the set of allowed access methods for the file. If the direct access method is also a member of the set of allowed access methods for the file, the order of the records is the same as that specified for direct access ( 12.2.4.2). The first record accessed by sequential access is the record whose record number is 1 for direct access. The second record accessed by sequential access is the record whose record number is 2 for direct access, etc. A record that has not been written since the file was created must not be read.
  2. The records of the file are either all formatted or all unformatted, except that the last record of the file may be an endfile record.
  3. The records of the file must not be read or written by direct access input/output statements ( 12.8.1).

12.2.4.2 Direct Access.

When connected for direct access, a file has the following properties:
  1. The order of the records is the order of their record numbers. The records may be read or written in any order.
  2. The records of the file are either all formatted or all unformatted. If the sequential access method is also a member of the set of allowed access methods for the file, its endfile record, if any, is not considered to be part of the file while it is connected for direct access. If the sequential access method is not a member of the set of allowed access methods for the file, the file must not contain an endfile record.
  3. Reading and writing records is accomplished only by direct access input/output statements ( 12.8.1).
  4. All records of the file have the same length.
  5. Each record of the file is uniquely identified by a positive integer called the record number. The record number of a record is specified when the record is written. Once established, the record number of a record can never be changed.

    Note that a record may not be deleted; however, a record may be rewritten.

  6. Records need not be read or written in the order of their record numbers. Any record may be written into the file while it is connected ( 12.3.2) to a unit. For example, it is permissible to write record 3, even though records 1 and 2 have not been written. Any record may be read from the file while it is connected to a unit, provided that the record was written since the file was created.
  7. The records of the file must not be read or written using list-directed formatting.

12.2.5 Internal Files.

Internal files provide a means of transferring and converting data from internal storage to internal storage.

12.2.5.1 Internal File Properties.

An internal file has the following properties:
  1. The file is a character variable, character array element, character array, or character substring.
  2. A record of an internal file is a character variable, character array element, or character substring.
  3. If the file is a character variable, character array element, or character substring, it consists of a single record whose length is the same as the length of the variable, array element, or substring, respectively. If the file is a character array, it is treated as a sequence of character array elements. Each array element is a record of the file. The ordering of the records of the file is the same as the ordering of the array elements in the array ( 5.2.4). Every record of the file has the same length, which is the length of an array element in the array.
  4. The variable, array element, or substring that is the record of the internal file becomes defined by writing the record. If the number of characters written in a record is less than the length of the record, the remaining portion of the record is filled with blanks.
  5. A record may be read only if the variable, array element, or substring that is the record is defined.
  6. A variable, array element, or substring that is a record of an internal file may become defined (or undefined) by means other than an output statement. For example, the variable, array element, or substring may become defined by a character assignment statement.
  7. An internal file is always positioned at the beginning of the first record prior to data transfer.

12.2.5.2 Internal File Restrictions.

An internal file has the following restrictions:
  1. Reading and writing records is accomplished only by sequential access formatted input/output statements ( 12.8.1) that do not specify list-directed formatting.
  2. An auxiliary input/output statement must not specify an internal file.

12.3 Units

A unit is a means of referring to a file.

12.3.1 Unit Existence.

At any given time, there is a processor-determined set of units that are said to exist for an executable program.

All input/output statements may refer to units that exist. The INQUIRE and CLOSE statements may also refer to units that do not exist.

12.3.2 Connection of a Unit.

A unit has a property of being connected or not connected. If connected, it refers to a file. A unit may become connected by preconnection or by the execution of an OPEN statement. The property of connection is symmetric: if a unit is connected to a file, the file is connected to the unit.

Preconnection means that the unit is connected to a file at the beginning of execution of the executable program and therefore may be referenced by input/output statements without the prior execution of an OPEN statement.

All input/output statements except OPEN, CLOSE, and INQUIRE must reference a unit that is connected to a file and thereby make use of or affect that file.

A file may be connected and not exist. An example is a preconnected new file.

A unit must not be connected to more than one file at the same time, and a file must not be connected to more than one unit at the same time. However, means are provided to change the status of a unit and to connect a unit to a different file.

After a unit has been disconnected by the execution of a CLOSE statement, it may be connected again within the same executable program to the same file or a different file. After a file has been disconnected by the execution of a CLOSE statement, it may be connected again within the same executable program to the same unit or a different unit. Note, however, that the only means to refer to a file that has been disconnected is by its name in an OPEN or INQUIRE statement. Therefore, there may be no means of reconnecting an unnamed file once it is disconnected.

12.3.3 Unit Specifier and Identifier.

The form of a unit specifier is:
[UNIT =] u
where u is an external unit identifier or an internal file identifier.

An external unit identifier is used to refer to an external file. An internal file identifier is used to refer to an internal file.

An external unit identifier is one of the following:

  1. An integer expression i whose value must be zero or positive
  2. An asterisk, identifying a particular processor-determined external unit that is preconnected for formatted sequential access ( 12.9.2)

The external unit identified by the value of i is the same external unit in all program units of the executable program. In the example:

  1. SUBROUTINE A
  2. READ (6) X

  3. SUBROUTINE B
  4. N=6
  5. REWIND N

the value 6 used in both program units identifies the same external unit.

An external unit identifier in an auxiliary input/output statement ( 12.10) must not be an asterisk.

An internal file identifier is the name of a character variable, character array, character array element, or character substring.

If the optional characters UNIT= are omitted from the unit specifier, the unit specifier must be the first item in a list of specifiers.

12.4 Format Specifier and Identifier

The form of a format specifier is:
[FMT =] f
where f is a format identifier.

A format identifier identifies a format. A format identifier must be one of the following:

  1. The statement label of a FORMAT statement that appears in the same program unit as the format identifier.
  2. An integer variable name that has been assigned the statement label of a FORMAT statement that appears in the same program unit as the format identifier ( 10.3).
  3. A character array name ( 13.1.2).
  4. Any character expression except a character expression involving concatenation of an operand whose length specification is an asterisk in parentheses unless the operand is the symbolic name of a constant. Note that a character constant is permitted.
  5. An asterisk, specifying list-directed formatting.

If the optional characters FMT= are omitted from the format specifier, the format specifier must be the second item in the control information list and the first item must be the unit specifier without the optional characters UNIT=.

12.5 Record Specifier

The form of a record specifier is:
REC = rn
where rn is an integer expression whose value is positive. It specifies the number of the record that is to be read or written in a file connected for direct access.

12.6 Error and End-of-File Conditions

The set of input/output error conditions is processor dependent.

An end-of-file condition exists if either of the following events occurs:

  1. An endfile record is encountered during the reading of a file connected for sequential access. In this case, the file is positioned after the endfile record.
  2. An attempt is made to read a record beyond the end of an internal file.

If an error condition occurs during execution of an input/output statement, execution of the input/output statement terminates and the position of the file becomes indeterminate.

If an error condition or an end-of-file condition occurs during execution of a READ statement, execution of the READ statement terminates and the entities specified by the input list and implied-DO-variables in the input list become undefined. Note that variables and array elements appearing only in subscripts, substring expressions, and implied-DO parameters in an input list do not become undefined when the entities specified by the list become undefined.

If an error condition occurs during execution of an output statement, execution of the output statement terminates and implied-DO-variables in the output list become undefined.

If an error condition occurs during execution of an input/output statement that contains neither an input/output status specifier ( 12.7) nor an error specifier ( 12.7.1), or if an end-of-file condition occurs during execution of a READ statement that contains neither an input/output status specifier nor an end-of-file specifier ( 12.7.2), execution of the executable program is terminated.

12.7 Input/Output Status, Error, and End-of-File Specifiers

The form of an input/output status specifier is:
IOSTAT = ios
where ios is an integer variable or integer array element.

Execution of an input/output statement containing this specifier causes ios to become defined:

  1. with a zero value if neither an error condition nor an end-of-file condition is encountered by the processor,
  2. with a processor-dependent positive integer value if an error condition is encountered, or
  3. with a processor-dependent negative integer value if an end-of-file condition is encountered and no error condition is encountered.

12.7.1 Error Specifier.

The form of an error specifier is:
ERR = s
where s is the statement label of an executable statement that appears in the same program unit as the error specifier.

If an input/output statement contains an error specifier and the processor encounters an error condition during execution of the statement:

  1. execution of the input/output statement terminates,
  2. the position of the file specified in the input/output statement becomes indeterminate,
  3. if the input/output statement contains an input/output status specifier ( 12.7), the variable or array element ios becomes defined with a processor-dependent positive integer value, and
  4. execution continues with the statement labeled s .

12.7.2 End-of-File Specifier.

The form of an end-of-file specifier is:
END = s
where s is the statement label of an executable statement that appears in the same program unit as the end-of-file specifier.

If a READ statement contains an end-of-file specifier and the processor encounters an end-of-file condition and no error condition during execution of the statement:

  1. execution of the READ statement terminates,
  2. if the READ statement contains an input/output status specifier ( 12.7), the variable or array element ios becomes defined with a processor-dependent negative integer value, and
  3. execution continues with the statement labeled s .

12.8 READ, WRITE, and PRINT Statements

The READ statement is the data transfer input statement. The WRITE and PRINT statements are the data transfer output statements. The forms of the data transfer input/output statements are:
READ (cilist) [iolist]
READ f [,iolist]
WRITE (cilist) [iolist]
PRINT f [,iolist]

12.8.1 Control Information List.

A control information list, cilist, is a list ( 2.10) whose list items may be any of the following:
______________
                      |             |
                      | [UNIT =] u  |
                      | [FMT =] f   |
                      | REC = rn    |
                      | IOSTAT = ios|
                      | ERR = s     |
                      |_END_=_s_____|

A control information list must contain exactly one unit specifier ( 12.3.3), at most one format specifier ( 12.4), at most one record specifier ( 12.5), at most one input/output status specifier ( 12.7), at most one error specifier ( 12.7.1), and at most one end-of-file specifier ( 12.7.2).

If the control information list contains a format specifier, the statement is a formatted input/output statement; otherwise, it is an unformatted input/output statement.

If the control information list contains a record specifier, the statement is a direct access input/output statement; otherwise, it is a sequential access input/output statement.

If the optional characters UNIT= are omitted from the unit specifier, the unit specifier must be the first item in the control information list.

If the optional characters FMT= are omitted from the format specifier, the format specifier must be the second item in the control information list and the first item must be the unit specifier without the optional characters UNIT=.

A control information list must not contain both a record specifier and an end-of-file specifier.

If the format identifier is an asterisk, the statement is a list-directed input/output statement and a record specifier must not be present.

In a WRITE statement, the control information list must not contain an end-of-file specifier.

If the unit specifier specifies an internal file, the control information list must contain a format identifier other than an asterisk and must not contain a record specifier.

12.8.2 Input/Output List.

An input/output list, iolist, specifies the entities whose values are transferred by a data transfer input/output statement.

An input/output list is a list ( 2.10) of input/output list items and implied-DO lists ( 12.8.2.3). An input/output list item is either an input list item or an output list item.

If an array name appears as an input/output list item, it is treated as if all of the elements of the array were specified in the order given by array element ordering ( 5.2.4). The name of an assumed-size dummy array must not appear as an input/output list item.

12.8.2.1 Input List Items.

An input list item must be one of the following:
  1. A variable name
  2. An array element name
  3. A character substring name
  4. An array name

Only input list items may appear as input/output list items in an input statement.

12.8.2.2 Output List Items.

An output list item must be one of the following:
  1. A variable name
  2. An array element name
  3. A character substring name
  4. An array name
  5. Any other expression except a character expression involving concatenation of an operand whose length specification is an asterisk in parentheses unless the operand is the symbolic name of a constant

Note that a constant, an expression involving operators or function references, or an expression enclosed in parentheses may appear as an output list item but must not appear as an input list item.

12.8.2.3 Implied-DO List.

An implied-DO list is of the form:
( dlist, i = e , e  [,e  ] )
                              1   2    3

The range of an implied-DO list is the list dlist . Note that dlist may contain implied-DO . lists. The iteration count and the values of the DO-variable i are established from e 1 , e 2 , and e 3 exactly as for a DO-loop. In an input statement, the DO-variable i , or an associated entity, must not appear as an input list item in dlist . When an implied-DO list appears in an input/output list, the list items in dlist are specified once for each iteration of the implied-DO list with appropriate substitution of values for any occurrence of the DO-variable i .

12.9 Execution of a Data Transfer Input/Output Statement

The effect of executing a data transfer input/output statement must be as if the following operations were performed in the order specified:
  1. Determine the direction of data transfer
  2. Identify the unit
  3. Establish the format if any is specified
  4. Position the file prior to data transfer
  5. Transfer data between the file and the entities specified by the input/output list (if any)
  6. Position the file after data transfer
  7. Cause the specified integer variable or array element in the input/output status specifier (if any) to become defined

12.9.1 Direction of Data Transfer.

Execution of a READ statement causes values to be transferred from a file to the entities specified by the input list, if one is specified.

Execution of a WRITE or PRINT statement causes values to be transferred to a file from the entities specified by the output list and format specification (if any). Execution of a WRITE or PRINT statement for a file that does not exist creates the file, unless an error condition occurs.

12.9.2 Identifying a Unit.

A data transfer input/output statement that contains a control information list ( 12.8.1) includes a unit specifier that identifies an external unit or an internal file. A READ statement that does not contain a control information list specifies a particular processor-determined unit, which is the same as the unit identified by an asterisk in a READ statement that contains a control information list. A PRINT statement specifies some other processor-determined unit, which is the same as the unit identified by an asterisk in a WRITE statement. Thus, each data transfer input/output statement identifies an external unit or an internal file.

The unit identified by a data transfer input/output statement must be connected to a file when execution of the statement begins.

12.9.3 Establishing a Format.

If the control information list contains a format identifier other than an asterisk, the format specification identified by the format identifier is established. If the format identifier is an asterisk, list-directed formatting is established.

On output, if an internal file has been specified, a format specification ( 13.1) that is in the file or is associated ( 17.1) with the file must not be specified.

12.9.4 File Position Prior to Data Transfer.

The positioning of the file prior to data transfer depends on the method of access: sequential or direct.

If the file contains an endfile record, the file must not be positioned after the endfile record prior to data transfer.

12.9.4.1 Sequential Access.

On input, the file is positioned at the beginning of the next record. This record becomes the current record. On output, a new record is created and becomes the last record of the file.

An internal file is always positioned at the beginning of the first record of the file. This record becomes the current record.

12.9.4.2 Direct Access.

For direct access, the file is positioned at the beginning of the record specified by the record specifier ( 12.5). This record becomes the current record.

12.9.5 Data Transfer.

Data are transferred between records and entities specified by the input/output list. The list items are processed in the order of the input/output list.

All values needed to determine which entities are specified by an input/output list item are determined at the beginning of the processing of that item. All values are transmitted to or from the entities specified by a list item prior to the processing of any succeeding list item. In the example,

READ (3) N, A(N)
two values are read; one is assigned to N, and the second is assigned to A(N) for the new value of N.

An input list item, or an entity associated with it ( 17.1.3), must not contain any portion of the established format specification.

If an intern file has been specified, an input/output list item must not be in the file or associated with the file.

A DO-variable becomes defined at the beginning of processing of the items that constitute the range of an implied-DO list.

On output, every entity whose value is to be transferred must be defined.

On input, an attempt to read a record of a file connected for direct access that has not previously been written causes all entities specified by the input list to become undefined.

12.9.5.1 Unformatted Data Transfer.

During unformatted data transfer, data are transferred without editing between the current record and the entities specified by the input/output list. Exactly one record is read or written.

On input, the file must be positioned so that the record read is an unformatted record or an endfile record.

On input, the number of values required by the input list must be less than or equal to the number of values in the record.

On input, the type of each value in the record must agree with the type of the corresponding entity in the input list, except that one complex value may correspond to two real list entities or two real values may correspond to one complex list entity. If an entity in the input list is of type character, the length of the character entity must agree with the length of the character value.

On output to a file connected for direct access, the output list must not specify more values than can fit into a record.

On output, if the file is connected for direct access and the values specified by the output list do not fill the record, the remainder of the record is undefined.

If the file is connected for formatted input/output, unformatted data transfer is prohibited.

The unit specified must be an external unit.

12.9.5.2 Formatted Data Transfer.

During formatted data transfer, data are transferred with editing between the entities specified by the input/output list and the file. The current record and possibly additional records are read or written.

On input, the file must be positioned so that the record read is a formatted record or an endfile record.

If the file is connected for unformatted input/output, formatted data transfer is prohibited.

12.9.5.2.1 Using a Format Specification.
If a format specification has been established, format control ( 13.3) is initiated and editing is performed as described in 13.3 through 13.5.

On input, the input list and format specification must not require more characters from a record than the record contains.

If the file is connected for direct access, the record number is increased by one as each succeeding record is read or written.

On output, if the file is connected for direct access or is an internal file and the characters specified by the output list and format do not fill a record, blank characters are added to fill the record.

On output, if the file is connected for direct access or is an internal file, the output list and format specification must not specify more characters for a record than can fit into the record.

12.9.5.2.2 List-Directed Formatting.
If list-directed formatting has been established, editing is performed as described in 13.6.

12.9.5.2.3 Printing of Formatted Records.
The transfer of information in a formatted record to certain devices determined by the processor is called printing. If a formatted record is printed, the first character of the record is not printed. The remaining characters of the record, if any, are printed in one line beginning at the left margin.

The first character of such a record determines vertical spacing as follows:

       __________ __________________________________
      |          |                                  |
      |_Character|__Vertical_Spacing_Before_Printing|
      |          |                                  |
      |   Blank  |  One Line                        |
      |     0    |  Two Lines                       |
      |     1    |  To First Line of Next Page      |
      |     +    |  No Advance                      |
      |__________|__________________________________|

If there are no characters in the record ( 13.5.4), the vertical spacing is one line and no characters other than blank are printed in that line.

A PRINT statement does not imply that printing will occur, and a WRITE statement does not imply that printing will not occur.

12.9.6 File Position After Data Transfer.

If an end-of-file condition exists as a result of reading an endfile record, the file is positioned after the endfile record.

If no error condition or end-of-file condition exists, the file is positioned after the last record read or written and that record becomes the preceding record. A record written on a file connected for sequential access becomes the last record of the file.

If the file is positioned after the endfile record, execution of a data transfer input/output statement is prohibited. However, a BACKSPACE or REWIND statement may be used to reposition the file.

If an error condition exists, the position of the file is indeterminate.

12.9.7 Input/Output Status Specifier Definition.

If the data transfer input/output statement contains an input/output status specifier, the integer variable or array element ios becomes defined. If no error condition or end-of-file condition exists, the value of ios is zero. If an error condition exists, the value of ios is positive. If an end-of-file condition exists and no error condition exists, the value of ios is negative.

12.10 Auxiliary Input/Output Statements

12.10.1 OPEN Statement.

An OPEN statement may be used to connect ( 12.3.2) an existing file to a unit, create a file ( 12.2.1) that is preconnected, create a file and connect it to a unit, or change certain specifiers of a connection between a file and a unit.

The form of an OPEN statement is:

OPEN (olist)
where olist is a list ( 2.10) of specifiers:
                       _____________
                      |             |
                      | [UNIT =] u  |
                      | IOSTAT = ios|
                      | ERR = s     |
                      | FILE = fin  |
                      | STATUS = sta|
                      | ACCESS = acc|
                      | FORM = fm   |
                      | RECL = rl   |
                      |_BLANK_=_blnk|

olist must contain exactly one external unit specifier ( 12.3.3) and may contain at most one of each of the other specifiers.

The other specifiers are described as follows:

The unit specifier is required to appear; all other specifiers are optional, except that the record length rl must be specified if a file is being connected for direct access. Note that some of the specifications have an assumed value if they are omitted.

The unit specified must exist.

A unit may be connected by execution of an OPEN statement in any program unit of an executable program and, once connected, may be referenced in any program unit of the executable program.

12.10.1.1 Open of a Connected Unit.

If a unit is connected to a file that exists, execution of an OPEN statement for that unit is permitted. If the FILE= specifier is not included in the OPEN statement, the file to be connected to the unit is the same as the file to which the unit is connected.

If the file to be connected to the unit does not exist, but is the same as the file to which the unit is preconnected, the properties specified by the OPEN statement become a part of the connection.

If the file to be connected to the unit is not the same as the file to which the unit is connected, the effect is as if a CLOSE statement ( 12.10.2) without a STATUS= specifier had been executed for the unit immediately prior to the execution of the OPEN statement.

If the file to be connected to the unit is the same as the file to which the unit is connected, only the BLANK= specifier may have a value different from the one currently in effect. Execution of the OPEN statement causes the new value of the BLANK= specifier to be in effect. The position of the file is unaffected.

If a file is connected to a unit, execution of an OPEN statement on that file and a different unit is not permitted.

12.10.2 CLOSE Statement.

A CLOSE statement is used to terminate the connection of a particular file to a unit.

The form of a CLOSE statement is:

CLOSE (cllist)
where cllist is a list ( 2.10) of specifiers:
                       _____________
                      |             |
                      | [UNIT =] u  |
                      | IOSTAT = ios|
                      | ERR = s     |
                      |_STATUS_=_sta|

cllist must contain exactly one external unit specifier ( 12.3.3) and may contain at most one of each of the other specifiers.

The other specifiers are described as follows:

Execution of a CLOSE statement that refers to a unit may occur in any program unit of an executable program and need not occur in the same program unit as the execution of an OPEN statement referring to that unit.

Execution of a CLOSE statement specifying a unit that does not exist or has no file connected to it is permitted and affects no file.

After a unit has been disconnected by execution of a CLOSE statement, it may be connected again within the same executable program, either to the same file or to a different file. After a file has been disconnected by execution of a CLOSE statement, it may be connected again within the same executable program, either to the same unit or to a different unit, provided that the file still exists.

12.10.2.1 Implicit Close at Termination of Execution.

At termination of execution of an executable program for reasons other than an error condition, all units that are connected are closed. Each unit is closed with status KEEP unless the file status prior to termination of execution was SCRATCH, in which case the unit is closed with status DELETE. Note that the effect is as though a CLOSE statement without a STATUS= specifier were executed on each connected unit.

12.10.3 INQUIRE Statement.

An INQUIRE statement may be used to inquire about properties of a particular named file or of the connection to a particular unit. There are two forms of the INQUIRE statement: inquire by file and inquire by unit. All value assignments are done according to the rules for assignment statements.

The INQUIRE statement may be executed before, while, or after a file is connected to a unit. All values assigned by the INQUIRE statement are those that are current at the time the statement is executed.

12.10.3.1 INQUIRE by File.

The form of an INQUIRE by file statement is:
INQUIRE (iflist)
where iflist is a list ( 2.10) of specifiers that must contain exactly one file specifier and may contain other inquiry specifiers. The iflist may contain at most one of each of the inquiry specifiers described in 12.10.3.3.

The form of a file specifier is:

FILE = fin
where fin is a character expression whose value when any trailing blanks are removed specifies the name of the file being inquired about. The named file need not exist or be connected to a unit. The value of fin must be of a form acceptable to the processor as a file name.

12.10.3.2 INQUIRE by Unit.

The form of an INQUIRE by unit statement is:
INQUIRE (iulist)
where iulist is a list ( 2.10) of specifiers that must contain exactly one external unit specifier ( 12.3.3) and may contain other inquiry specifiers. The iulist may contain at most one of each of the inquiry specifiers described in 12.10.3.3. The unit specified need not exist or be connected to a file. If it is connected to a file, the inquiry is being made about the connection and about the file connected.

12.10.3.3 Inquiry Specifiers.

The following inquiry specifiers may be used in either form of the INQUIRE statement:
                    __________________
                   |                  |
                   | IOSTAT = ios     |
                   | ERR = s          |
                   | EXIST = ex       |
                   | OPENED = od      |
                   | NUMBER = num     |
                   | NAMED = nmd      |
                   | NAME = fn        |
                   | ACCESS = acc     |
                   | SEQUENTIAL = seq |
                   | DIRECT = dir     |
                   | FORM = fm        |
                   | FORMATTED = fmt  |
                   | UNFORMATTED = unf|
                   | RECL = rcl       |
                   | NEXTREC = nr     |
                   |_BLANK_=_blnk_____|

The specifiers are described as follows:

A variable or array element that may become defined or undefined as a result of its use as a specifier in an INQUIRE statement, or any associated entity, must not be referenced by any other specifier in the same INQUIRE statement.

Execution of an INQUIRE by file statement causes the specifier variables or array elements nmd, fn, seq, dir, fmt, and unf to be assigned values only if the value of fin is acceptable to the processor as a file name and if there exists a file by that name; otherwise, they become undefined. Note that num becomes defined it and only if od becomes defined with the value true. Note also that the specifier variables or array elements acc, fm, rcl, nr, and blnk may become defined only if od becomes defined with the value true.

Execution of an INQUIRE by unit statement causes the specifier variables or array elements num, nmd, fn, acc, seq, dir, fm, fmt, unf, rcl, nr, and blnk to be assigned values only if the specified unit exists and if a file is connected to the unit; otherwise, they become undefined.

If an error condition occurs during execution of an INQUIRE statement, all of the inquiry specifier variables and array elements except ios become undefined.

Note that the specifier variables or array elements ex and od always become defined unless an error condition occurs.

12.10.4 File Positioning Statements.

The forms of the file positioning statements are:
  1. BACKSPACE u
  2. BACKSPACE (alist)

  3. ENDFILE u
  4. ENDFILE (alist)

  5. REWIND u
  6. REWIND (alist)
                       _____________
                      |             |
                      | [ UNIT =] u |
                      | IOSTAT = ios|
                      |_ERR_=_s_____|

alist must contain exactly one external unit specifier ( 12.3.3) and may contain at most one of each of the other specifiers.

The external unit specified by a BACKSPACE, ENDFILE, or REWIND statement must be connected for sequential access.

Execution of a file positioning statement containing an input/output status specifier causes ios to become defined with a zero value if no error condition exists or with a processor-dependent positive integer value if an error condition exists.

12.10.4.1 BACKSPACE Statement.

Execution of a BACKSPACE statement causes the file connected to the specified unit to be positioned before the preceding record. If there is no preceding record, the position of the file is not changed. Note that if the preceding record is an endfile record, the file becomes positioned before the endfile record.

Backspacing a file that is connected but does not exist is prohibited.

Backspacing over records written using list-directed formatting is prohibited.

12.10.4.2 ENDFILE Statement.

Execution of an ENDFILE statement writes an endfile record as the next record of the file. The file is then positioned after the endfile record. If the file may also be connected for direct access, only those records before the endfile record are considered to have been written. Thus, only those records may be read during subsequent direct access connections to the file.

After execution of an ENDFILE statement, a BACKSPACE or REWIND statement must be used to reposition the file prior to execution of any data transfer input/output statement.

Execution of an ENDFILE statement for a file that is connected but does not exist creates the file.

12.10.4.3 REWIND Statement.

Execution of a REWIND statement causes the specified file to be positioned at its initial point. Note that if the file is already positioned at its initial point, execution of this statement has no effect on the position of the file.

Execution of a REWIND statement for a file that is connected but does not exist is permitted but has no effect.

12.11 Restrictions on Function References and List Items

A function must not be referenced within an expression appearing anywhere in an input/output statement if such a reference causes an input/output statement to be executed. Note that a restriction in the evaluation of expressions ( 6.6) prohibits certain side effects.

12.12 Restriction on Input/Output Statements

If a unit, or a file connected to a unit, does not have all of the properties required for the execution of certain input/output statements, those statements must not refer to the unit.


[Contents] [Previous] [Next] [Home]

 

NDP77
http://www.ndp77.net
webmaster MFA (main)
webmaster@ndp77.net