Formatted Input/Output [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Reference
Formatted Input/Output
Formatted input/output allows you to control the use of each character of
a data record. This control is specified in a FORMAT statement or in the
input/output statement itself.
Formatted Input
Formatted input is specified by the following input statements. Only the
brief forms of the relevant syntax elements are shown here. For the
complete syntax, refer to "READ Statement (Executable)" .
Syntax
READ fmt , list
READ ( unit , fmt ) list
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| fmt | Format designator. | See "Semantics". |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| unit | Unit number of the file. | None. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| list | List of variables that specifies | See "Semantics". |
| | where the data is to be | |
| | transferred. | |
| | | |
-----------------------------------------------------------------------------------------------
Semantics
The format designator, fmt, must be one of the following:
* The statement label of a FORMAT statement.
* A variable name that has been assigned the statement label of a
FORMAT statement.
* A character expression.
* A character array name that contains the representation of a
format specification.
* An asterisk, indicating list-directed formatting.
list can contain implied DO loops.
For information on implied DO loops, refer to the section "DO Statement
(Executable)" .
The first READ statement syntax shown above transfers information from
the standard input device (preconnected to unit 5). The second READ
statement transfers data from a file or device.
Reading always starts at the beginning of a record. Reading stops when
the list is satisfied, provided that the format specification and the
record length are in agreement with the list. If the list is omitted,
the file pointer is positioned at the next record without data transfer.
If the format specification is longer than the list, reading stops at the
first repeatable edit descriptor, colon, or right parenthesis terminating
the format after the list is satisfied. If the list is longer than the
format specification, reading skips to the next record, which is read
using part or all of the format specification again. However, if a
carriage return is entered but no value, the element is set to zero (0).
This process continues until the list is satisfied. If the list is
longer than the record and the format specification does not cause a skip
to the next record, error 910 (Access past end of record attempted)
occurs. The record is treated as if blanks were added to the end to
satisfy the input list.
After the READ, the file pointer is positioned at the beginning of the
next record. Each READ statement begins reading values from a fresh
record of the file; any values left unread in records accessed by
previous READ statements are ignored. For example, if the record
contains six data elements, a READ statement such as
READ (4,100) i,j
reads only the first two elements. The remaining four elements are not
read because any subsequent READ statement reads values from the next
record, unless the file pointer is repositioned (with BACKSPACE or
REWIND, for example) prior to the next READ.
You can use a comma (,) to terminate the input of noncharacter data or to
assign the value of zero to selected values. The next field starts
immediately after the comma.
You cannot use the comma to terminate the input field or to assign values
when using the A, R, M, or N format descriptors, because the comma has a
meaning for these descriptors.
For example, if the program
PROGRAM comma
INTEGER a, b, c, d, e
a = 1
b = 2
c = 3
d = 4
e = 5
READ(5,'(I2, 3I2, I2)') a, b, c, d, e
PRINT *, a, b, c, d, e
END
has this input (remember, Delta represents a space):
Delta 9 Delta 8,
the following is printed:
Delta 9 Delta 8 Delta 0 Delta 0 Delta 0
The program terminates reading values after the comma (that is, after
reading the value of b).
Similarly, if the input is
Delta 7 Delta 4, Delta 3 Delta 2
the following is printed:
7 4 0 3 2
The value zero is assigned to c.
Finally, if the input is
12,14,16
the following is printed:
Delta 12 Delta 0 Delta 14 Delta 0 Delta 16
An array name in a list represents all the elements in the array. Values
are transferred to the array elements in accordance with the standard
array storage order. Refer to "Variables" for details.
Formatted Output
Formatted output is specified by the following output statements. Only
the brief forms of the relevant syntax elements are shown here. For the
complete syntax, refer to "PRINT Statement (Executable)" and "WRITE
Statement (Executable)" .
Syntax
PRINT fmt , list
WRITE ( unit , fmt ) [,] list
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| fmt | Format designator. | See "Semantics". |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| unit | Unit number of the file. | None. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| list | List of variables or expressions | See "Semantics". |
| | that specifies the data to be | |
| | transferred. | |
| | | |
-----------------------------------------------------------------------------------------------
Semantics
The format designator, fmt, must be one of the following:
* The statement label of a FORMAT statement.
* A variable name that has been assigned the statement label of a
FORMAT statement by an ASSIGN statement.
* A character expression.
* A character array name that contains the representation of a
format specification.
* An asterisk, indicating list-directed formatting.
If list is omitted, a blank line is written (unless a literal appears in
the format before a repeatable format descriptor). list can contain
implied DO loops. For syntax and detailed information on implied DO
loops, see "DO Statement (Executable)" .
The PRINT statement transfers information to the standard output device
(preconnected to unit 6). The WRITE statement transfers information to
disk files or to output devices.
The optional comma (,) in the WRITE syntax is an extension to the ANSI 77
standard.
Each WRITE statement begins writing values into a fresh record of the
destination file; any space left unused in records accessed by previous
WRITE statements is ignored. After the transfer is completed, the file
record pointer is advanced.
Writing always starts at the beginning of a record. Writing stops when
the list is satisfied, provided that the format specification and the
record length agree with the list. If the format specification is longer
than the list, writing stops at the first repeatable edit descriptor,
colon, or right parenthesis terminating the format after the list is
satisfied. If the list is longer than the format specification, writing
skips to the next record, which is written using part or all of the
format specification again.
This process continues until the list is satisfied. If the list is
longer than the output record and the format specification does not cause
a skip to the next record, the record is truncated at the record length
of the file. After the write process, the file pointer is positioned at
the beginning of the next record.
Array names in the list represent all the elements of the array. Array
element values are transferred according to the standard array storage
order. See "Variables" .
NOTE Record names and aggregates are not permitted in formatted I/O.
Carriage Control
The first character of each output record is always considered to be a
carriage control character for devices that recognize carriage control.
The standard carriage control characters are listed in Table 4-1 .
Table 4-1. Carriage Control Characters
---------------------------------------------------------------------------------------------
| | |
| Character | Vertical Spacing Before Printing |
| | |
---------------------------------------------------------------------------------------------
| | |
| Delta (blank) | One line (single spacing) |
| | |
| 0 | Two lines (double spacing) |
| | |
| 1 | To first line of next page (page eject) |
| | |
| + | No advance (overprinting) |
| | |
| Any other character | Device dependent |
| | |
---------------------------------------------------------------------------------------------
MPE/iX 5.0 Documentation