Next: Other I/O Statements
Up: Input / Output
Previous: FORMAT Statement / FMT=
Fortran contains a large number of output edit descriptors which means
that very complex I/O patterns can be specified, it is only intended
that a summary be presented here. Any good textbook will elaborate:
Where,
- w determines the number of the total number of characters (column
width)
that the data spans,
(on output if there are insufficient columns for the data then
numeric data will
not (cannot) be printed, CHARACTER data will be truncated).
- d specifies the number of decimal places that the data contains
and is contained in the total number of characters. The number will be
rounded (not truncated) to the desired accuracy.
and,
- I specifies that the data is of INTEGER type.
- E writes REAL using exponent form, 1.000E+00.
- F uses `decimal point' form, 1.000.
- for F and E the sign is included in the total number
of characters, by default plus signs are not output.
- L specifies LOGICAL data. .TRUE. and .FALSE. are output as a
single character T or F. If w is greater that one them
the single character is padded to the left with blanks.
- A specifies CHARACTER data. If w is specified strings
which are too long (more than w characters) will be truncated. If
w is not specified any length of string is appropriate.
- X skips the specified number of characters (n blanks are
output).
Descriptors or groups of descriptors can be repeated by prefixing or
parenthesesing and prefixing with the number of repeats, for example,
I4
can be repeated twice by specifying 2I4
and
I4,1X
can be repeated twice by specifying 2(I4,1X)
.
Many of the above edit descriptors can be demonstrated:
WRITE(*,FMT='(2X,2(I4,1X),''name '',A4,F13.5,1X,E13.5)') &
77778,3,'ABCDEFGHI',14.45,14.5666666
gives
bb****bbbb3bnamebABCDbbbbb14.45000bbb0.14567E+02
where the b signifies a blank!
In the above example, the first INTEGER is unable to be written as
the number is too long and the last REAL number is
rounded to fit into the spaces available. The string is truncated to fit
into the space available.
A READ statement could use the same format editor.
Type coercion is not performed so
INTEGER s cannot be written out as REAL s.
Return to corresponding overview page
Next: Other I/O Statements
Up: Input / Output
Previous: FORMAT Statement / FMT=
©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997Not for commercial use.