List-Directed Input/Output [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Reference
List-Directed Input/Output
List-directed input/output allows you to transfer data without specifying
its exact format. The format of the data is determined by the data
itself.
List-Directed Input
List-directed 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 * , list
READ ( unit , * [...] ) list
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| unit | Unit number of the internal or | None. |
| | external file. | |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| list | List of variables that specifies | None. |
| | where the data is to be | |
| | transferred. | |
| | | |
-----------------------------------------------------------------------------------------------
If list is omitted, the file is positioned at the next record without
data transfer. The list can contain implied DO loops. For syntax and
detailed information on implied DO loops, refer to "DO Statement
(Executable)" .
The first READ statement syntax shown above transfers information from
the standard input device. Unit 5 is preconnected to the standard input
device.
The second READ statement transfers data from a disk file or device.
List-directed input from an internal file is an extension to the ANSI 77
standard.
Data for list-directed input consists of values separated by one or more
blanks, or by a slash or comma preceded or followed by any number of
blanks. An end-of-record also acts as a separator except within a
character constant. Leading blanks in the first record read are not
considered part of a value separator unless followed by a slash or comma.
Input data can also take either of the forms:
r*c
r*
where:
r is an unsigned, nonzero integer constant.
c is a constant.
The r*c form means r repetitions of the constant c, and the r* form means
r repetitions of null values. Neither form can contain embedded blanks,
except where permitted in the constant c.
Reading always starts at the beginning of a new record. As many records
as required to satisfy the list are read unless a slash in the input
record is encountered.
Embedded blanks in input values are not allowed (they are always
interpreted as value separators).
The forms of values in the input record are described in Table 4-5 .
See "Data Types" for more details.
Table 4-5. List-Directed Input Format
--------------------------------------------------------------------------------------------
| | |
| Data Type | Input Record Format |
| | |
--------------------------------------------------------------------------------------------
| | |
| INTEGER*2 | Same form as integer constants. |
| INTEGER*4 | |
| LOGICAL*1 | Note: LOGICAL*1 (BYTE) requires integer input, not logical input. |
| | |
--------------------------------------------------------------------------------------------
| | |
| REAL*4 | Any valid form for real constants. |
| REAL*8 | |
| REAL*16 | In addition, the exponent can be indicated by a signed integer |
| | constant (the D, E, or Q can be omitted), and the decimal point can |
| | be omitted for those values with no fractional part. |
| | |
--------------------------------------------------------------------------------------------
| | |
| COMPLEX*8 | Any valid form for complex constants. |
| COMPLEX*16 | |
| | Each of the numbers can be preceded or followed by blanks or the end |
| | of a record. |
| | |
--------------------------------------------------------------------------------------------
| | |
| LOGICAL*2 | A field of characters in which the first nonblank character |
| LOGICAL*4 | (excluding an optional leading decimal point) must be a T for true or |
| | an F for false. |
| | |
| | Note: LOGICAL*1 (BYTE) requires integer input, not logical input. |
| | |
--------------------------------------------------------------------------------------------
| | |
| CHARACTER | Same form as character constants. |
| | |
| | Character constants can be continued from one record to the next. |
| | The end-of-record does not cause a blank or any other character to |
| | become part of the constant. |
| | |
| | If the length of the character constant is greater than or equal to |
| | the length, len, of the list item, only the leftmost len characters |
| | of the constant are transferred. If the length of the constant is |
| | less than len, the constant is left-justified in the list item with |
| | trailing blanks. |
| | |
--------------------------------------------------------------------------------------------
The data in the input record is converted to that of the list item,
following the type conversion rules given in Table 3-3 .
Example
The statement:
READ *,s,t,x,y,z
and the input record:
Delta Delta 'TOTAL' Delta Delta (42 Delta , Delta 1),TRUE Delta Delta 362 Delta Delta Delta 563.63D6
cause the following assignments to take place, assuming the variable is
of the specified type:
----------------------------------------------------------------------------------------------
| | | |
| Variable | Data Type | Value Assigned |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| s | CHARACTER*5 | 'TOTAL' |
| | | |
| t | COMPLEX*8 | (42.,1.) |
| | | |
| x | LOGICAL*4 | .TRUE. |
| | | |
| y | REAL*4 | 362. |
| | | |
| z | REAL*8 | 563.63*106 |
| | | |
----------------------------------------------------------------------------------------------
A null value can be specified in place of a constant when you do not want
the value of the corresponding list item to change. If the value is
defined, it retains its value; if the value is undefined, it remains
undefined. A null value is indicated by two successive value separators
(two commas separated by any number of blanks) or by a comma before the
first input value on a line.
Example
The statement:
READ *,x,y,z
and the input record:
Delta ,5.12 Delta , Delta Delta
cause the following assignments to take place:
----------------------------------------------------------------------------------------------
| | | |
| Variable | Data Type | Value Assigned |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| x | REAL*4 | Retains previous value. |
| | | |
| y | REAL*4 | 5.12 |
| | | |
| z | REAL*4 | Retains previous value. |
| | | |
----------------------------------------------------------------------------------------------
Encountering an end-of-line (end-of-record) in the input record causes
the read to be continued on the next record until the input list items
are satisfied. If a slash (/) is encountered, the read terminates and
the remaining items in the input list are unchanged.
An end-of-record is treated like a blank. An end-of-record is not itself
data and is not placed in a character item when a character constant is
continued on another line. (That is, character constants can be
continued.)
List-Directed Output
List-directed 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 * , list
WRITE ( unit , * [...] ) list
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| unit | Unit number of the internal or | None. |
| | external file. | |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| list | List of variables or expressions | See "Semantics". |
| | that specifies the data to be | |
| | transferred. | |
| | | |
-----------------------------------------------------------------------------------------------
Semantics
If list contains a function reference, that function must not contain any
READ or WRITE statements. The list can contain implied DO loops. For
syntax and detailed information on implied DO loops, refer to "DO
Statement (Executable)" .
List-directed output to an internal file is an extension to the ANSI 77
standard.
The PRINT statement transfers information to the standard output unit.
The WRITE statement transfers information to external files or devices.
Unit number 6 is preconnected to the standard output file.
The forms of values in a list-directed output record are described in
Table 4-6 . See "Data Types" for more details.
Table 4-6. List-Directed Output Format
--------------------------------------------------------------------------------------------
| | |
| Data Type | Output Record Format |
| | |
--------------------------------------------------------------------------------------------
| | |
| INTEGER*2 | Output as integer constants. |
| INTEGER*4 | |
| LOGICAL*1 | Note: LOGICAL*1 (BYTE) produces integer output, not logical output. |
| | |
--------------------------------------------------------------------------------------------
| | |
| REAL*4 | Output with or without an exponent, depending on the magnitude of the |
| REAL*8 | value. |
| REAL*16 | |
| | |
--------------------------------------------------------------------------------------------
| | |
| COMPLEX*8 | Output as two REAL*4 or REAL*8 values, separated by commas and |
| COMPLEX*16 | enclosed in parentheses. |
| | |
--------------------------------------------------------------------------------------------
| | |
| LOGICAL*2 | Output as a T for the value true and an F for the value false. |
| LOGICAL*4 | |
| | Note: LOGICAL*1 (BYTE) produces integer output, not logical output. |
| | |
--------------------------------------------------------------------------------------------
| | |
| CHARACTER | A character value is not delimited by apostrophes or quotation marks, |
| | and each apostrophe or quotation mark within the value is written as |
| | one character. |
| | |
--------------------------------------------------------------------------------------------
Every value is preceded by exactly one blank, except character values.
Trailing zeros after a decimal point are omitted. A blank character is
also inserted at the beginning of each record to provide carriage control
when the file is printed.
Sample Program Data
---------------------------------------------------------------------------------------------
| | |
| Internal Values | Data Type |
| | |
---------------------------------------------------------------------------------------------
| | |
| a = 11.15 | REAL*4 |
| | |
| b = .11145D-05 | REAL*8 |
| | |
| c = (10 , 3.0) | COMPLEX*8 |
| | |
| d = (1.582D-03 , 4.9851) | COMPLEX*16 |
| | |
| e = .TRUE. | LOGICAL*2 |
| | |
| f = .FALSE. | LOGICAL*4 |
| | |
| i = 11250 | INTEGER*4 |
| | |
| j = -32799 | INTEGER*4 |
| | |
| n = 'PROGRAM NAME' | CHARACTER*15 |
| | |
| p = 'test.out' | CHARACTER*8 |
| | |
| r = 32Q-4300 | REAL*16 |
| | |
---------------------------------------------------------------------------------------------
Sample Output from Sample Program Data
---------------------------------------------------------------------------------------------
| | |
| Output Statement | Output Record |
| | |
---------------------------------------------------------------------------------------------
| | |
| PRINT *,a,i | Delta 11.15 Delta 11250 (Note) |
| | |
| WRITE(6,*)c | Delta (10.,3.) |
| | |
| WRITE(6,*)j,e | Delta -32799 Delta T |
| | |
| PRINT *,b | Delta 1.1145E-6 (Note) |
| | |
| WRITE(6,*)d | Delta (1.582E-3,4.9851) |
| | |
| WRITE(6,*)n,p | PROGRAM Delta NAME Delta Delta Delta |
| | test.out |
| | |
---------------------------------------------------------------------------------------------
Note: Output to the standard output unit. The
first output character (not shown) is
converted to provide single-spacing carriage
control.
The total length of each list-directed output record to an external file
is 72 bytes or less, including carriage control. Items that would
overflow the 72-byte record if added to the current record cause the
current record to be written out and a new record started. The item that
caused the overflow begins the new record. Character strings longer than
71 characters are broken into as many records as necessary, with each
record given a leading blank for carriage control.
List-directed output to an internal file uses the item length of the
internal file as the record length to determine where output items must
be broken. Slashes, as value separators, and null values are not output
by list-directed formatting.
MPE/iX 5.0 Documentation