Accessing and Assigning Files

Most I/O operations involve a disk file, keyboard, or screen display. Other devices can also be used:

You can access the terminal screen or keyboard by using preconnected files.

Assigning Files to Logical Units

You can choose to assign files to logical units by using one of the following methods:

Using Default Values

In the following example, the PRINT statement is associated with a preconnected unit (stdout) by default.

PRINT *,100

The READ statement associates the logical unit 7 with the file fort.7 (because the FILE specifier was omitted) by default:

OPEN (UNIT=7,STATUS='NEW')

READ (7,100)

Supplying a File Name in an OPEN Statement

For example:

OPEN (UNIT=7, FILE='FILNAM.DAT', STATUS='OLD')

The FILE specifier in an OPEN statement typically specifies only a file name (such as testdata) or contains both a directory and file name (such as /usr/proj/testdata).

The DEFAULTFILE specifier in an OPEN statement typically specifies a pathname that contains only a directory (such as /usr/proj/) or both a directory and file name (such as /usr/proj/testdata).

Implied OPEN

Performing an implied OPEN means that the FILE and DEFAULTFILE specifier values are not specified and an environment variable is used, if present. Thus, if you used an implied OPEN, or if the FILE specifier in an OPEN statement did not specify a file name, you can use an environment variable to specify a file name or a pathname that contains both a directory and file name.

Using Environment Variables

You can use shell commands to set the appropriate environment variable to a value that indicates a directory (if needed) and a file name to associate a unit with an external file.

Intel Fortran recognizes environment variables for each logical I/O unit number in the form of FORTn, where n is the logical I/O unit number. If a file name is not specified in the OPEN statement and the corresponding FORTn environment variable is not set for that unit number, Intel Fortran generates a file name in the form fort.n , where n is the logical unit number.

Implied Intel Fortran Logical Unit Numbers

The ACCEPT, PRINT, and TYPE statements, and the use of an asterisk (*) in place of a unit number in READ and WRITE statements, do not include an explicit logical unit number.

Each of these Fortran statements uses an implicit internal logical unit number and environment variable. Each environment variable is in turn associated by default with one of the Fortran file names that are associated with standard I/O files. The table below shows these relationships:

Intel Fortran statement

Environment variable

Standard I/O file name

READ (*,f) iolist

FOR_READ

stdin

READ f,iolist

FOR_READ

stdin

ACCEPT f,iolist

FOR_ACCEPT

stdin

WRITE (*,f) iolist

FOR_PRINT

stdout

PRINT f,iolist

FOR_PRINT

stdout

TYPE f,iolist

FOR_TYPE

stdout

WRITE(0,f) iolist

FORT0

stderr

READ(5,f) iolist

FORT5

stdin

WRITE(6,f) iolist

FORT6

stdout

You can change the file associated with these Intel Fortran environment variables, as you would any other environment variable, by means of the environment variable assignment command. For example:

setenv FOR_READ /usr/users/smith/test.dat

After executing the preceding command, the environment variable for the READ statement using an asterisk refers to file test.dat in directory /usr/users/smith.