| United States-English |
|
|
|
![]() |
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 8 I/O
and file handlingSyntax of I/O statements |
|
The general syntactic form of file-positioning and auxiliary statements is:
where
The general form of a data-transfer statement is:
where
The following sections describe the I/O specifiers and the form of data-list. For detailed information about the syntax of individual I/O statements, see Chapter 10 “HP Fortran statements”. I/O specifiers provide I/O statements with additional information about a file or a data transfer operation. They can also be used (especially with the INQUIRE statement) to return information about a file. Table 8-7 “I/O statements and specifiers” lists all I/O specifiers supported by HP Fortran and identifies the statements in which each can appear. Note that the ACCEPT, DECODE, ENCODE, and TYPE statements are not listed in the table as they are nonstandard. All I/O specifiers and statements are fully described in Chapter 10 “HP Fortran statements”. Each I/O specifier is described under the I/O statement in which it may appear. Table 8-7 I/O statements and specifiers
The I/O data list can be used with any data transfer statement except namelist I/O; see “Namelist-directed I/O” for a description of this. The general form of the I/O data list is:
where item is a either a simple data element or an implied-DO loop. The following sections describe simple data elements and the implied-DO loop. In a read operation, the simple data element specifies a variable, which can include:
In a write operation, the simple data element can include any variable that is valid for a read operation, plus most expressions. Note that, if the expression includes a function reference, the function must not itself perform I/O. The output list in the following PRINT statement contains two simple list elements, a variable named radius and an expression formed from radius:
The next READ statement contains three simple elements: a character substring (name(1:10)), a variable (id), and an array name (scores):
If an array name is used as a simple data element in the I/O list of a WRITE statement, then every element in the array will be displayed. If a format specification is also used, then the format will be reused if necessary to display every element. For example, the following code
will output the following:
The following restrictions apply to the use of arrays in input and output:
The following restrictions apply to the use of structures and records in input and output:
An implied-DO loop consists of a list of data elements to be read, written, or initialized, and a set of indexing parameters. The syntax of an implied-DO loop in an I/O statement is:
where
Inner loops can use the indexes of outer loops. The implied-DO loop acts like a DO construct. The range of the implied-DO loop is the list of elements to be input or output. The implied-DO loop can transfer a list of data elements that are valid for a write operation. index is assigned the value of init at the start of the loop. Execution continues in the same manner as for DO loops (see “DO construct”). The implied-DO loop is generally used to transmit arrays and array elements, as in the following:
If b has been initialized with the values 1 through 10 in order, the PRINT statement will produce the following output:
If an nonsubscripted array name occurs in the list, the entire array is transmitted at each iteration. For example:
If x has been initialized to be [ 1 2 3 ], the output will be:
The list can contain expressions that use the index value. For example:
print the numbers
Implied-DO loops can also be nested. The form of a nested implied-DO loop in an I/O statement is:
Nested implied-DO loops follow the same rules as do other nested DO loops. For example, given the following statements:
the output will be:
The first, or nested DO loop, is completed once for each execution of the outer loop. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||