



Format Control Descriptors READ or WRITE
statement has an empty data-transfer list.
|
n and k are integer constants, k may have a sign but n must be non-zero
and unsigned. The control descriptors such as SP, BN, kP affect all numbers
transferred subsequently. The settings are unaffected by forced reversion
but the system defaults are restored at the start of the next READ or WRITE
operation.
Any list of edit descriptors may be enclosed in parentheses and preceded by an
integer constant as a repetition count, e.g.
2(I2.2, '-'),I2.2
is equivalent to
I2.2, '-', I2.2, '-', I2.2
These sub-lists can be nested to any reasonable depth, but the presence of internal
pairs of parentheses can have special effects when forced reversion takes place, as
explained later.
Commas may be omitted between items in the following special cases: either side
of a slash (/) or colon (:) descriptor, and after a scale-factor (kP) if it immediately
precedes a D, E, F, or G descriptor.
The slash descriptor (/) starts a new record on output or skips to a new record on
input, ignoring anything left on the current record. On a text file a record normally
corresponds to a line of text. Note that a formatted transfer always process at least
one record: if the format contains N slashes then a total of (N+1) records are
processed. With N consecutive slashes in an output format there will be (N-1) blank
lines; on input then (N-1) lines will be ignored. Note that if a formatted
sequential file is sent to a printer the first character of every record may be used
for carriage-control (see section 10.11). It is good practice to put 1X at the
beginning of every format specification and after every slash to ensure single line
spacing. Here, for example, there is a blank line after the column headings.
WRITE(UNIT=LP, FMT=95) (NYEAR(I), POP(I), I=1,NYEARS) 95 FORMAT(1X,'Year Population', //, 100(1X, I4, F12.0, /)) |
Column Position Control (Tn, TLn, TRn, nX)
These descriptors cause subsequent values to be transferred starting at a different column position in the record. They can, for instance, be used to set up a table with headings positioned over each column. In all these descriptors the value of n must be 1 or more. Columns are numbered from 1 on the left (but remember that column 1 may be used for carriage-control if the output is sent to a printer).
|
TLn can be used to re-read the same field again, possibly using a different
data descriptor. On output these descriptors do not necessarily have any
direct effect on the record: they do not cause any existing characters to be
replaced by blanks, but when the record is complete any column positions
embedded in the record which are still unset will be replaced by blanks. Thus:
WRITE(UNIT=LP, FMT=9000)
9000 FORMAT('A', TR1000, TL950, 'Z')
|
Character Constant Output ('string')
The character constant descriptor can only be used with WRITE statements: the
character string is simply copied to the output record. As in all character constants
an apostrophe can be represented in the string by two successive apostrophes, and
blanks are significant.
After SP has been used, positive numbers will be written with a leading + sign;
after SS has been used the + sign is suppressed. The S descriptor restores the initial
default which is system-dependent. These descriptors have no effect on numerical
input. The initial default is restored at the start of every new formatted
transfer.
After BN is used all embedded and trailing blanks in numerical input fields are
treated as nulls, i.e. ignored. After BZ they are treated as zeros. These descriptors
have no effect on numerical output. The initial default, which depends on the BLANK=
item in the OPEN statement, is restored at the start of every new formatted
transfer.
The scale factor can be used to introduce a scaling by any power of 10 between
internal and external values when E, F, or G descriptors are used. In principle this
could be useful when dealing with data which are too large, or too small, for the
exponent range of the floating-point data types of the machine, but in other
difficulties usually make this impracticable. The scale factor can result in particularly
insidious errors when used with F descriptors and should be avoided by all sensible
programmers. The rules are as follows.
The initial scale factor in each formatted transfer is zero. It the descriptor kP is
used, where k is a small (optionally signed) integer, then it is set to k. It
affects all subsequent floating point values transferred by the statement.
On input there is no effect if the input field contains an explicit exponent,
otherwise
internal-value = external-value / 10k
On output the effect depends on the descriptor used. With E descriptors the
decimal point is moved k places to the right and the exponent reduced by
k so the effective value is unaltered. With F descriptors there is always a
scaling:
external-value = em internal-value * 10k
With G descriptors the scale-factor is ignored if the value is in the range for F-type
output, otherwise it has the same effects as with E descriptors.
Scan Control (:) and Forced Reversion
The list of edit descriptors is scanned from left to right (apart from the effect of
parentheses) starting at the beginning of the list whenever a new data transfer
statement is executed. The action of the I/O system depends jointly on the next edit
descriptor and the next item in data-transfer list. If a data descriptor comes next
then the next data item is transferred if one exists, otherwise the format scan comes
to an end. If a colon descriptor (:) comes next and the data-transfer list is empty the
format scan ends, otherwise the descriptor has no effect. If any other control
descriptor comes next then it is obeyed whether or not the data-transfer list is
empty.
If the format list is exhausted when there are still more items in the data-transfer list then forced reversion occurs: the file is positioned at the beginning of the next record and the format list is scanned again, starting at the left-parenthesis matching the last preceding right-parenthesis. If this is preceded by a repeat-count then this count is re-used. If there is no preceding right-parenthesis then the whole format is re-used. Forced reversion has no effect upon the settings for scale-factor, sign, or blank control. Forced reversion can be useful when reading or writing an array contained on a sequence of records since it is not necessary to know how many records there are in total, but when producing printed output it is easy to forget that a carriage-control character is required for each record, even those produced by forced reversion.