📄 fio.gml
字号:
END
.exam end
.pc
After checking for an
.mono "I"
or
.mono "R"
as the first character of the character variable
.id INPUT,
the appropriate internal
.kw READ
statement is executed.
.endlevel
.*
.section *refid=units Units
.*
.np
Many FORTRAN 77 input/output statements refer to external files using a
mechanism called the
.us unit.
.ix unit
There are many units available to the FORTRAN 77 programmer.
&product numbers these units from 0 to 999;
thus the unit number is a non-negative integer less than 1000.
.np
A unit may be associated with a particular file.
This association is called
.us connection.
.ix connection unit
.ix connection file
Any unit may or may not be connected to a file.
There are a number of ways in which this connection may be
established.
.np
A unit may be
.us preconnected
.ix preconnection
to a file before execution of a program begins.
The User's Guide describes the mechanism for preconnecting
a unit to a file.
.np
Alternatively, a unit may become connected to a file by the
execution of an
.kw OPEN
statement.
.np
All input/output statements except
.kw OPEN,
.kw CLOSE,
and
.kw INQUIRE
must refer to a unit that is connected to a file.
&product automatically establishes a connection of the unit to a
file if no connection previously existed.
Consider the following example in which unit number 1 is not
previously connected to a file.
.exam begin
WRITE(1,*) 'Output on unit 1'
END
.exam end
.pc
&product constructs a file name using the specified unit number.
The format of the file name is described in the User's Guide
since it varies from one computer system to the next.
.np
Connection of a unit to a file does not imply that the file must
exist.
For example, it could be a new file.
When we speak of a unit being connected to a file, we can also say
that a file is connected to a unit.
Under the rules of FORTRAN, it is illegal to connect the same file
to more than one unit
.us at the same time.
However, a file may be connected to different units at different
times.
We shall explain how this is possible.
.np
.ix disconnection
A file may be
.us disconnected
from a unit by the use of the
.kw CLOSE
statement.
.exam begin
CLOSE(UNIT=1)
.exam end
.np
Under certain circumstances, the file may be disconnected from a unit
by the use of the
.kw OPEN
statement.
.exam begin
OPEN(UNIT=1,FILE='FILE1')
.
.
.
OPEN(UNIT=1,FILE='FILE2')
.exam end
.pc
In the above example, the second
.kw OPEN
statement disconnects unit 1 from one file and connects it to a
second file.
You may think of the second
.kw OPEN
statement as automatically closing the first file and then
establishing a connection to the second file.
.np
If a unit has been disconnected from a file through the execution of
a
.kw CLOSE
statement, the unit may subsequently be connected to the same
file or to a different file.
It also follows that a file which has been disconnected from one
unit number may be connected to the same unit number or a
different unit number.
The following example may help to illustrate this last point.
.exam begin
OPEN(UNIT=1,FILE='FILE1')
.
.
.
CLOSE(UNIT=1)
OPEN(UNIT=2,FILE='FILE1')
.exam end
.np
Once a file has been disconnected, the only means for referring to
the file is by its name in an
.kw OPEN
statement or an
.kw INQUIRE
statement.
.*
.section Specifiers
.*
.np
All input/output statements contain one or more specifiers.
They appear in a list separated by commas.
Some of the more common specifiers are those listed below.
Not all of them need be used in every input/output statement.
You should consult the description of the input/output statement
under consideration to discover which specifiers are allowed and
what they mean.
.begnote $setptnt 16
.ix 'UNIT='
.mnote [UNIT =] u
the unit specifier
.ix 'FMT='
.mnote [FMT =] f
the format specifier
.ix 'REC='
.mnote REC = rn
the record specifier
.ix 'IOSTAT='
.mnote IOSTAT = ios
the input/output status specifier
.ix 'ERR='
.mnote ERR = s
the error specifier
.ix 'END='
.mnote END = s
the end-of-file specifier
.endnote
.np
We shall look at these specifiers in more detail.
.*
.beglevel
.*
.section The Unit Specifier
.*
.np
.ix 'unit specifier'
.ix specifier unit
.np
The form of a unit specifier in an input/output statement is:
.begnote
.ix 'UNIT='
.mnote [UNIT =] u
.id u
is an
.us external unit identifier
or an
.us internal file identifier.
.autopoint
.point
An external unit identifier is a non-negative integer
expression or an asterisk
.mono (*)
in which case unit 5 is assumed for an input statement
and unit 6 is assumed for an output statement.
The unit identifier must not be an asterisk for the
.kw BACKSPACE,
.kw ENDFILE
and
.kw REWIND
statements.
.point
An internal file identifier is the name of a character variable,
character array, character array element, or character substring.
.endpoint
.endnote
.np
If the optional
.kw UNIT=
specifier is omitted then the unit specifier must be the first
item in the list of specifiers.
.*
.section Format Specifier
.*
.np
.ix 'format specifier'
.ix specifier format
.np
The form of a format specifier in an input/output statement is:
.begnote
.ix 'FMT='
.mnote [FMT =] f
.id f
is a
.us format identifier.
A format identifier is one of the following:
.autopoint
.point
A statement label of a
.kw FORMAT
statement that appears in the same program unit as the format
identifier.
.point
An integer variable name that has been assigned the statement label of
a
.kw FORMAT
statement that appears in the same program unit as the format
identifier (see the
.kw ASSIGN
statement).
.point
.xt on
An integer array name.
.xt off
.point
A character array name.
.point
Any character expression except one involving the concatenation of an
operand whose length specification is
.mono (*)
unless the operand is a symbolic constant (see the
.kw PARAMETER
statement).
.point
.ix 'list-directed format'
.ix format list-directed
An asterisk
.mono (*),
indicating
.us list-directed
formatting.
.point
.xt on
.ix 'namelist-directed format'
.ix format namelist-directed
A
.kw NAMELIST
name, indicating
.us namelist-directed
formatting.
.xt off
.endpoint
.endnote
.np
If the optional
.kw FMT=
specifier is omitted then the format specifier must be the second item
in the list of specifiers and
.kw UNIT=
must not be specified for the first item in the list.
.*
.section Record Specifier
.*
.np
.ix 'record specifier'
.ix specifier record
.np
The form of a record specifier in an input/output statement is:
.begnote
.ix 'REC='
.mnote REC = rn
.id rn
is an integer expression whose value must be positive.
It is the number of the record to be read when a file is
connected for
.us direct access.
.ix 'direct access'
.ix access direct
.endnote
.*
.section Input/Output Status Specifier
.*
.np
.ix 'status specifier'
.ix specifier status
.np
The form of an input/output status specifier in an input/output
statement is:
.begnote
.ix 'IOSTAT='
.mnote IOSTAT = ios
.id ios
is an integer variable or integer array element.
It is defined with zero if no error occurs, a positive integer value
if an error occurs, or a negative integer value if an end-of-file
occurs.
.endnote
.np
If an input/output error or end-of-file condition occurs during the
execution of an input/output statement and the input/output status
specifier is present then execution of the program is not
terminated.
Input/output errors may result from a violation of the rules of
FORTRAN or from a file system error.
For example, a negative unit number will result in an error since
this is a violation of the rules of FORTRAN.
An example of a file system error might be an attempt to create a
file on a non-existent file storage device.
.np
Consult the User's Guide for a list of &product diagnostic messages.
An input/output status of
.mono nn
corresponds to the message
.mono IO-nn.
For example, if the status returned is 3 then the error is:
.millust begin
IO-03 ENDFILE statement requires sequential access mode
.millust end
.*
.section Error Specifier
.*
.np
.ix 'error specifier'
.ix specifier error
The form of an error specifier in an input/output statement is:
.begnote
.ix 'ERR='
.mnote ERR = s
.id s
is a statement label.
When an error occurs, execution is transferred to the statement
labelled by
.id s.
.endnote
.np
If an input/output error occurs during the execution of an input/output
statement and the
.kw ERR=
specifier is present then execution of the program is not
terminated.
.*
.section End-of-File Specifier
.*
.np
.ix 'end-of-file specifier'
.ix specifier end-of-file
The form of an end-of-file specifier in an input/output statement is:
.begnote
.ix 'END='
.mnote END = s
.id s
is a statement label.
When an end-of-file condition occurs, execution is transferred to
the statement labelled by
.id s.
.endnote
.np
If an end-of-file condition occurs during the execution of an
input/output statement and the
.kw END=
specifier is present then execution of the program is not
terminated.
.endlevel
.*
.section Printing of Formatted Records
.*
.np
.ix printing
Printing occurs when
.us formatted
records are transferred to a device which interprets the first
character of the record as a special spacing command.
The remaining characters in the record are "printed".
Printing can be accomplished by use of either the
.kw PRINT
statement or the
.kw WRITE
statement.
What actually determines whether or not you are "printing" is the
device (or file) to which records are transferred.
.np
.ix ASA
.ix 'carriage control'
The first character of the record controls the vertical spacing.
This feature is quite often called ASA (American Standards
Association) carriage control.
.sk 1 c
.* .mbox on 1 13 45
.sr c0=&INDlvl+1
.sr c1=&INDlvl+13
.sr c2=&INDlvl+45
.mbox on &c0 &c1 &c2
Character Vertical Spacing Before Printing
.mbox
Blank One Line
0 Two Lines
- Three Lines
1 To First Line of Next Page
+ No Advance
.mbox off
.np
.xt begin
The "&minus." control character is an extension to the FORTRAN 77 language
that is supported by many "printing" devices.
.xt end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -