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:
- READ
- WRITE
- PRINT
- OPEN
- CLOSE
- INQUIRE
- BACKSPACE
- ENDFILE
- 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).
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:
- Formatted
- Unformatted
- Endfile
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.
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).
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.
A
file
is a sequence (
2.1) of records.
There are two kinds of files:
- External
- Internal
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.
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.
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.
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.
When connected for sequential access, a file has the following properties:
- 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.
- 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.
- The records of the file must not be read or written
by direct access input/output statements (
12.8.1).
When connected for direct access, a file has the following properties:
- The order of the records is the order of their record
numbers. The records may be read or written in any
order.
- 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.
- Reading and writing records is accomplished only
by direct access input/output statements (
12.8.1).
- All records of the file have the same length.
- 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.
- 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.
- The records of the file must not be read or written
using list-directed formatting.
Internal files provide a means of transferring and
converting data from internal storage to internal storage.
An internal file has the following properties:
- The file is a character variable, character array
element, character array, or character substring.
- A record of an internal file is a character variable,
character array element, or character substring.
- 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.
- 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.
- A record may be read only if the variable, array
element, or substring that is the record is defined.
- 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.
- An internal file is always positioned at the beginning
of the first record prior to data transfer.
An internal file has the following restrictions:
- Reading and writing records is accomplished only
by sequential access
formatted input/output statements (
12.8.1) that do not
specify list-directed formatting.
- An auxiliary input/output statement must not specify
an internal file.
A
unit
is a means of referring to a file.
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.
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.
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:
- An integer expression
i
whose value must be zero
or positive
- 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:
-
SUBROUTINE A
-
READ (6) X
-
SUBROUTINE B
-
N=6
-
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.
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:
- The statement label of a FORMAT statement that appears in the
same program unit as the format identifier.
- 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).
- A character array name (
13.1.2).
- 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.
- 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=.
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.
The set of input/output error conditions is processor dependent.
An end-of-file condition exists if either of the following events
occurs:
- 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.
- 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.
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:
- with a zero value if neither an error condition nor an end-of-file
condition is encountered by the processor,
- with a processor-dependent positive integer value if an error
condition is encountered, or
- with a processor-dependent negative integer value if
an end-of-file condition is
encountered and no error condition is encountered.
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:
- execution of the input/output statement terminates,
- the position of the file specified in the input/output statement
becomes indeterminate,
- 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
- execution continues with the statement labeled
s
.
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:
- execution of the READ statement terminates,
- 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
- execution continues with the statement labeled
s
.
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]
- where:
cilist
is a control information list (
12.8.1) that
includes:
- (1)A reference to the source or destination
of the data to be transferred
- (2)Optional specification of= editing processes
- (3)Optional specifiers that determine the
execution sequence on the occurrence of
certain events
- (4)Optional specification to identify a record
- (5)Optional specification to provide t|%he
return of the input/output status
-
f
is a format identifier (
12.4)
-
iolist
is an input/output list (
12.8.2) specifying
the data to be transferred
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.
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.
An
input list item
must be one of the following:
- A variable name
- An array element name
- A character substring name
- An array name
Only input list items may appear as input/output list items
in an input statement.
An
output list item
must be one of the following:
- A variable name
- An array element name
- A character substring name
- An array name
- 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.
An
implied-DO list
is of the form:
( dlist, i = e , e [,e ] )
1 2 3
- where:
i
,
e
1
,
e
2
, and
e
3
are as specified for the DO
statement (
11.10)
-
dlistunde>r
is an input/output list
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
.
The effect of executing a data transfer input/output
statement must be as if the following operations were
performed in the order specified:
- Determine the direction of data transfer
- Identify the unit
- Establish the format if any is specified
- Position the file prior to data transfer
- Transfer data between the file and the entities
specified by the input/output list (if any)
- Position the file after data transfer
- Cause the specified integer variable or array element
in the input/output status specifier (if any) to become defined
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
If list-directed formatting has been established, editing
is performed as described in
13.6.
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.
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.
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.
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:
-
IOSTAT = ios
- is an input/output status specifier (
12.7).
Execution of an OPEN statement containing this 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.
-
ERR = s
- is an error specifier (
12.7.1).
-
FILE = fin
-
fin
is a character expression whose value when any
trailing blanks are removed is the name of the file
to be connected to the specified unit.
The file
name must be a name that is allowed by the processor.
If this specifier is omitted and the unit is not
connected to a file, it becomes connected to a
processor-determined file.
(See also
12.10.1.1.)
-
STATUS = sta
-
sta
is a character expression whose value when any
trailing blanks are removed is OLD, NEW, SCRATCH,
or UNKNOWN.
If OLD or NEW is specified, a FILE=
specifier must be given.
If OLD is specified, the
file must exist. If NEW is specified, the file must
not exist. Successful execution of an OPEN statement
with NEW specified creates the file and changes the
status to OLD (
12.10.1.1).
If SCRATCH is specified
with an unnamed file, the file is connected to the
specified unit for use by the executable program
but is deleted (
12.2.1) at the execution of a CLOSE
statement referring to the same unit or at the
termination of the executable program.
SCRATCH
must not be specified with a named file.
If UNKNOWN
is specified, the status is processor dependent.
If this specifier is omitted, a value of UNKNOWN
is assumed.
-
ACCESS = acc
-
acc
is a character expression whose value when any
trailing blanks are removed is SEQUENTIAL
or DIRECT.
It specifies the access method for the connection of the file
as being sequential or direct (
12.2.4).
If this specifier is omitted, the assumed value is SEQUENTIAL.
For an existing file, the specified access method must be included in
the set of allowed access methods for the file (
12.2.4).
For a new file, the processor creates the file with a set of allowed
access methods that includes the specified method.
-
FORM = fm
-
fm
is a character expression whose value when any
trailing blanks are removed is FORMATTED or
UNFORMATTED.
It specifies that the file is being connected for formatted or
unformatted input/output, respectively.
If this specifier is omitted, a value of UNFORMATTED is assumed
if the file is being connected for direct access, and a value
of FORMATTED is assumed if the file is being connected for
sequential access.
For an existing file, the specified form must be included in the
set of allowed forms for the file (
12.2.2).
For a new file, the processor creates the file with a set of allowed forms
that includes the specified form.
-
RECL = rl
-
rl
is an integer
expression whose value must be positive.
It specifies the length of each record in a
file being connected for direct access.
If the file is being connected for formatted input/output, the length
is the number of characters.
If the file is being connected for unformatted input/output, the
length is measured in processor-dependent units.
For an existing file, the value of
rl
must be included in the set of
allowed record lengths for the file (
12.2.2).
For a new file, the processor creates the file with a set of allowed
record lengths that includes the specified value.
This specifier must be given when a file is being connected for direct
access; otherwise, it must be omitted.
-
BLANK = blnk
-
blnk
is a character expression whose value when any
trailing blanks are removed is NULL or ZERO.
If
NULL is specified, all blank characters in numeric
formatted input fields on the specified unit are
ignored, except that a field of all blanks has a
value of zero.
If ZERO is specified, all blanks
other than leading blanks are treated as zeros.
If this specifier is omitted, a value of NULL is
assumed.
This specifier is permitted only for a file being connected for
formatted input/output.
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.
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.
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:
-
IOSTAT = ios
- is an input/output status specifier (
12.7).
Execution of a CLOSE statement containing this 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.
-
ERR = s
- is an error specifier (
12.7.1).
-
STATUS = sta
-
sta
is a character expression whose value when any
trailing blanks are removed is KEEP or DELETE.
sta
determines the disposition of the file that is
connected to the specified unit.
KEEP must not be
specified for a file whose status prior to execution
of the CLOSE statement is SCRATCH. If KEEP is
specified for a file that exists, the file continues
to exist after the execution of the CLOSE statement.
If KEEP is specified for a file that does not exist,
the file will not exist after the execution of the
CLOSE statement.
If DELETE is specified, the file
will not exist after execution of the CLOSE
statement.
If this specifier is omitted, the assumed
value is KEEP, unless the file status prior to
execution of the CLOSE statement is SCRATCH, in
which case the assumed value is DELETE.
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.
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.
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.
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.
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.
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:
-
IOSTAT = ios
- is an input/output status specifier (
12.7).
Execution of an INQUIRE statement containing this 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.
-
ERR = s
- is an error specifier (
12.7.1).
-
EXIST = ex
-
ex
is a logical variable or logical array element.
Execution of an INQUIRE by file statement causes
ex
to be assigned the value true if there exists
a file with the specified name; otherwise,
ex
is
assigned the value false.
Execution of an
INQUIRE by unit statement causes
ex
to be assigned
the value true if the specified unit exists; otherwise,
ex
is assigned the value false.
-
OPENED = od
-
od
is a logical variable or logical array element.
Execution of an INQUIRE by file statement causes
od
to be assigned the value true if the file
specified is connected to a unit; otherwise,
od
is assigned the value false.
Execution of an
INQUIRE by unit statement causes
od
to be assigned
the value true if the specified unit is connected
to a file; otherwise,
od
is assigned the value false.
-
NUMBER = num
-
num
is an integer variable or integer array element
that is assigned the value of the external unit
identifier of the unit that is currently connected
to the file.
If there is no unit connected to the
file,
num
becomes undefined.
-
NAMED = nmd
-
nmd
is a logical variable or logical array element
that is assigned the value true if the file has a
name; otherwise, it is assigned the value false.
-
NAME = fn
-
fn
is a character variable or character array element
that is assigned the value of the name of the file,
if the file has a name; otherwise, it becomes
undefined.
Note that if this specifier appears in
an INQUIRE by file statement, its value is not
necessarily the same as the name given in the FILE=
specifier.
For example, the processor may return
a file name qualified by a user identification.
However, the value returned must be suitable for
use as the value of a FILE= specifier in an OPEN statement.
-
ACCESS = acc
-
acc
is a character variable or character array#
element that is assigned the value SEQUENTIAL if
the file is connected for sequential access, and DIRECT if the file
is connected for direct access.
If there is no connection,
acc
becomes undefined.
-
SEQUENTIAL = seq
-
seq
is a character variable or character array element that is
assigned the value YES if SEQUENTIAL is included in the set of allowed
access methods for the file, NO if SEQUENTIAL is not included in the
set of allowed access methods for the file, and UNKNOWN if the processor
is unable to determine whether or not SEQUENTIAL is included in
the set of allowed access methods for the file.
-
DIRECT = dir
-
dir
is a character variable or character array element that is
assigned the value YES if DIRECT is included in the set of allowed
access methods for the file, NO if DIRECT is not included in the set
of allowed access methods for the file, and UNKNOWN if the processor is
unable to determine whether or not DIRECT is included in the set of
allowed access methods for the file.
-
FORM = fm
-
fm
is a character variable or character array element
that is assigned the value FORMATTED if the
file is connected for formatted input/output, and is assigned the
value UNFORMATTED if the file is connected for unformatted input/output.
If there is no connection,
fm
becomes undefined.
-
FORMATTED = fmt
-
fmt
is a character variable or character array element that is
assigned the value YES if FORMATTED is included in the set of
allowed forms for the file, NO if FORMATTED is not included in the
set of allowed forms for the file, and UNKNOWN if the processor
is unable to determine whether or not FORMATTED is included in the
set of allowed forms for the file.
-
UNFORMATTED = unf
-
unf
is a character variable or character array element that is
assigned the value YES if UNFORMATTED is included in the set of
allowed forms for the file, NO if UNFORMATTED is not included in the
set of allowed forms for the file, and UNKNOWN if the processor is
unable to determine whether or not UNFORMATTED is included in the set
of allowed forms for the file.
-
RECL = rcl
-
rcl
is an integer variable or integer array element
that is assigned the value of the record length of
the file connected for direct access.
If the file is connected for formatted input/output, the length is
the number of
characters.
If the file is connected for unformatted input/output, the length is
measured in processor-dependent units.
If there is no connection or if the connection is not for direct access,
rcl
becomes undefined.
-
NEXTREC = nr
-
nr
is an integer variable or integer array element
that is assigned the value
n+1
, where
n
is the
record number of the last record read or written
on the file connected for direct access.
If the file is connected but no records
have been read or written since the connection,
nr
is assigned the value 1.
If the file is not connected for direct access
or if the position of the file
is indeterminate because of a previous error condition,
nr
becomes undefined.
-
BLANK = blnk
-
blnk
is a character variable or character array element
assigned the value NULL if null blank control is in effect for the file
connected for formatted input/output, and is assigned the value ZERO
if zero blank control is in effect for the file connected for formatted
input/output.
If there is no connection, or if the connection is not for formatted
input/output,
blnk
becomes undefined.
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.
The forms of the file positioning statements are:
- BACKSPACE
u
- BACKSPACE
(alist)
- ENDFILE
u
- ENDFILE
(alist)
- REWIND
u
- REWIND
(alist)
- where:
u
is an external unit identifier (
12.3.3)
-
alist
is a list (2.20) of specifiers:
_____________
| |
| [ 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.
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.
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.
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.
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.
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