A file is an internal or external sequence of records or file storage units. You determine the file access method when connecting a file to a unit. You can access an external file using three methods:
You can only access an internal file sequentially.
You must associate an external file with an I/O device such as a disk, or terminal. An external file exists for a program when a program creates that file, or the file is available to that program for reading and writing. Deleting an external file ends the existence of that file. An external file can exist and contain no records.
+-------------------------------IBM Extension--------------------------------+
To specify an external file by a file name, you must designate a valid operating system file name. Each file name can contain a maximum of 255 characters. If you specify a full path name, it can contain a maximum of 1023 characters.
+----------------------------End of IBM Extension----------------------------+
The preceding I/O statement determines the position of an external file. You can position an external file to:
Using sequential access, records in a file are read or written based on the logical order of records in that file. Sequential access supports both internal and external files.
A file connected for sequential access contains records in the order they
were written. The records must be either all formatted or all unformatted; the last record of the file
must be an endfile record. The records must
not be read or written by direct
or stream access
I/O statements during the time the file is connected for sequential
access.
An internal file is a character variable that is not an array section with a vector subscript. You do not need to create internal files. They always exist, and are available to the application.
If an internal file is a scalar character variable, the file consists of one record with a length equal to that of the scalar variable. If an internal file is a character array, each element of the array is a record of the file, with each record having the same length.
An internal file must contain only formatted records. READ and WRITE are the only statements that can specify an internal file. If a WRITE statement writes less than an entire record, blanks fill the remainder of that record.
Using direct access, the records of an external file can be read or written in any order. The records must be either all formatted or all unformatted. The records must not be read or written using sequential or stream access, list-directed or namelist formatting, or a nonadvancing input/output statement. If the file was previously connected for sequential access, the last record of the file is an endfile record. The endfile record is not considered a part of the file connected for direct access.
Each record in a file connected for direct access has a record number that identifies its order in the file. The record number is an integer value that must be specified when the record is read or written. Records are numbered sequentially. The first record is number 1. Records need not be read or written in the order of their record numbers. For example, records 9, 5, and 11 can be written in that order without writing the intermediate records.
All records in a file connected for direct access must have the same length, which is specified in the OPEN statement when the file is connected.
Records in a file connected for direct access cannot be deleted, but they can be rewritten with a new value. A record cannot be read unless it has first been written.
+------------------------Fortran 2003 Draft Standard-------------------------+
+-------------------------------IBM Extension--------------------------------+
You can connect external files for stream access as either formatted or unformatted. Both forms use external stream files composed of one byte file storage units. While a file connected for unformatted stream access has only a stream structure, files connected for formatted stream access have both a record and a stream structure. These dual structure files have the following characteristics:
The first file storage unit of a file connected for formatted stream access has a position of 1. The position of each subsequent storage unit is greater than the storage unit immediately before it. The positions of successive storage units are not always consecutive and positionable files need not be read or written to in order of position. To determine the position of a file storage unit connected for formatted stream access, use the POS= specifier of the INQUIRE statement. If the file can be positioned, you can use the value obtained using the INQUIRE statement to position that file. You read from the file while connected to the file, as long as the storage unit has been written to since file creation and that the connection permits a READ statement. File storage units of a file connected for formatted stream access can only be read or written by formatted stream access input/output statements.
The first file storage unit of a file connected for unformatted stream access has a position of 1. The position value of successive storage units is incrementally one greater than the storage unit it follows. Positionable files need not be read or written to in order of position. Any storage unit can be read from the file while connected to the file, if the storage unit has been written to since file creation and that the connection permits a READ statement. File storage units of a file connected for unformatted stream access can only be read or written by stream access input/output statements.
+----------------------------End of IBM Extension----------------------------+
+----------------------------End of IBM Extension----------------------------+