Intel® Fortran Compiler 17.0 Developer Guide and Reference
Each type of record I/O statement can be coded in a variety of forms. The form you select depends on the nature of your data and how you want it treated. When opening a file, specify the form using the FORM specifier.
The following are the forms of I/O statements:
Formatted I/O statements contain explicit format specifiers that are used to control the translation of data from internal (binary) form within a program to external (readable character) form in the records, or vice versa.
List-directed and namelist I/O statements are similar to formatted statements in function. However, they use different mechanisms to control the translation of data: formatted I/O statements use explicit format specifiers, and list-directed and namelist I/O statements use data types.
Unformatted I/O statements do not contain format specifiers and therefore do not translate the data being transferred (important when writing data that will be read later).
Formatted, list-directed, and namelist I/O forms require translation of data from internal (binary) form within a program to external (readable character) form in the records. Consider using unformatted I/O for the following reasons:
Unformatted data avoids the translation process, so I/O tends to be faster.
Unformatted data avoids the loss of precision in floating-point numbers when the output data will subsequently be used as input data.
Unformatted data conserves file storage space (stored in binary form).
To write data to a file using formatted, list-directed, or namelist I/O statements, specify FORM= 'FORMATTED' when opening the file. To write data to a file using unformatted I/O statements, specify FORM= 'UNFORMATTED' when opening the file.
Data written using formatted, list-directed, or namelist I/O statements is referred to as formatted data. Data written using unformatted I/O statements is referred to as unformatted data.
When reading data from a file, you should use the same I/O statement form that was used to write the data to the file. For instance, if data was written to a file with a formatted I/O statement, you should read data from that file with a formatted I/O statement.
Although I/O statement form is usually the same for reading and writing data in a file, a program can read a file containing unformatted data (using unformatted input) and write it to a separate file containing formatted data (using formatted output). Similarly, a program can read a file containing formatted data and write it to a different file containing unformatted data.
You can access records in any sequential or relative file using sequential access. For relative files and certain (fixed-length) sequential files, you can also access records using direct access.
The table below shows categories for the main record I/O statements that can be used in Intel® Fortran programs.
File Type, Access, and I/O Form |
Available Statements |
---|---|
External file, sequential access |
|
Formatted |
READ, WRITE, PRINT, ACCEPT, TYPE, REWRITE |
List-directed |
READ, WRITE, PRINT, ACCEPT, TYPE |
Namelist |
READ, WRITE, PRINT, ACCEPT, TYPE |
Unformatted |
READ, WRITE, REWRITE |
External file, direct access |
|
Formatted |
READ, WRITE, REWRITE |
Unformatted |
READ, WRITE, REWRITE |
External file, stream access |
|
Formatted |
READ, WRITE |
List-directed |
READ, WRITE |
Namelist |
READ, WRITE |
Unformatted |
READ, WRITE |
Internal file |
|
Formatted |
READ, WRITE |
List-directed |
READ, WRITE |
Unformatted |
None |
You can use the REWRITE statement only for relative files, using direct access.