Visible to Intel only — GUID: GUID-3193BC37-D2F3-485C-83B7-917FE4F819D8
Visible to Intel only — GUID: GUID-3193BC37-D2F3-485C-83B7-917FE4F819D8
Scale-Factor Editing (P)
The P edit descriptor specifies a scale factor, which moves the location of the decimal point in real values and the two real parts of complex values. It takes the following form:
kP
The k is a signed (sign is optional if positive), integer literal constant specifying the number of positions, to the left or right, that the decimal point is to move (the scale factor). The range of k is -128 to 127.
At the beginning of a formatted I/O statement, the value of the scale factor is zero. If a scale editing descriptor is specified, the scale factor is set to the new value, which affects all subsequent real edit descriptors until another scale editing descriptor occurs.
To reinstate a scale factor of zero, you must explicitly specify 0P.
Format reversion does not affect the scale factor. (For more information on format reversion, see Interaction Between Format Specifications and I/O Lists.)
Rules for Input Processing
On input, a positive scale factor moves the decimal point to the left, and a negative scale factor moves the decimal point to the right. (On output, the effect is the reverse.)
On input, when an input field using an F, E, D, EN, ES, EX, or G real edit descriptor contains an explicit exponent, the scale factor has no effect. Otherwise, the internal value of the corresponding I/O list item is equal to the external field data multiplied by 10-k. For example, a 2P scale factor multiplies an input value by .01, moving the decimal point two places to the left. A -2P scale factor multiplies an input value by 100, moving the decimal point two places to the right.
The scale factor applies to decimal numbers without an exponent. For hexadecimal-significand numbers, the exponent is mandatory so the scale factor has no effect.
The following shows input using the P edit descriptor (the symbol ^ represents a nonprinting blank character):
Format Input Value 3PE10.5 ^^^37.614^ .037614 3PE10.5 ^^37.614E2 3761.4 -3PE10.5 ^^^^37.614 37614.0
The scale factor must precede the first real edit descriptor associated with it, but it need not immediately precede the descriptor. For example, the following all have the same effect:
(3P, I6, F6.3, E8.1) (I6, 3P, F6.3, E8.1) (I6, 3PF6.3, E8.1)
Note that if the scale factor immediately precedes the associated real edit descriptor, the comma separator is optional.
Rules for Output Processing
On output, a positive scale factor moves the decimal point to the right, and a negative scale factor moves the decimal point to the left. (On input, the effect is the reverse.)
On output, the effect of the scale factor depends on which kind of real editing is associated with it, as follows:
For F editing, the external value equals the internal value of the I/O list item multiplied by 10k. This changes the magnitude of the data.
For E and D editing, the external decimal field of the I/O list item is multiplied by 10k, and k is subtracted from the exponent. This changes the form of the data.
A positive scale factor decreases the exponent; a negative scale factor increases the exponent.
For a positive scale factor, k must be less than d + 2 or an output conversion error occurs.
For G editing, the scale factor has no effect if the magnitude of the data to be output is within the effective range of the descriptor (the G descriptor supplies its own scaling).
If the magnitude of the data field is outside G descriptor range, E editing is used, and the scale factor has the same effect as E output editing.
For EN, ES, and EX editing, the scale factor has no effect.
The following shows output using the P edit descriptor (the symbol ^ represents a nonprinting blank character):
Format Value Output 1PE12.3 -270.139 ^^-2.701E+02 1P,E12.2 -270.139 ^^^-2.70E+02 -1PE12.2 -270.139 ^^^-0.03E+04
Examples
The following shows a FORMAT statement containing a scale factor:
DIMENSION A(6)
DO 10 I=1,6
10 A(I) = 25.
WRITE (6, 100) A
100 FORMAT(' ', F8.2, 2PF8.2, F8.2)
The preceding statements produce the following results:
25.00 2500.00 2500.00 2500.00 2500.00 2500.00
The following code uses scale-factor editing when reading:
READ (*, 100) a, b, c, d
100 FORMAT (F10.6, 1P, F10.6, F10.6, -2P, F10.6)
WRITE (*, 200) a, b, c, d
200 FORMAT (4F11.3)
If the following data is entered:
12340000 12340000 12340000 12340000 12.34 12.34 12.34 12.34 12.34e0 12.34e0 12.34e0 12.34e0 12.34e3 12.34e3 12.34e3 12.34e3
The program's output is:
12.340 1.234 1.234 1234.000 12.340 1.234 1.234 1234.000 12.340 12.340 12.340 12.340 12340.000 12340.000 12340.000 12340.000
The next code shows scale-factor editing when writing:
a = 12.34
WRITE (*, 100) a, a, a, a, a, a
100 FORMAT (1X, F9.4, E11.4E2, 1P, F9.4, E11.4E2, &
& -2P, F9.4, E11.4E2)
This program's output is:
12.3400 0.1234E+02 123.4000 1.2340E+01 0.1234 0.0012E+04