8.4.4 Scale Factor Editing - the P Edit Descriptor

During either input or output processing, the scale factor lets you alter the location of the decimal point in real values and in the two parts of complex values. The scale factor takes the following form:

nP
n
Is a signed or unsigned integer constant in the range -128 through 127. It specifies the number of positions, to the left or right, that the decimal point is to move.

A scale factor can appear anywhere in a format specification but it must precede the first F, E, D, or G field descriptor that associates with it. The scale factor affects all subsequent real field descriptors in the same FORMAT statement (unless another scale factor appears).

Input Processing

On input, the scale factor associated with an F, E, D, or G field descriptor multiplies the data by 10**-n and assigns it to the corresponding I/O list element. 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. However, if the external field contains an explicit exponent, the scale factor has no effect.

The following list illustrates valid input processing using scale factor editing (the symbol ^ represents a nonprinting space character):

Format     External Field       Internal Value
3PE10.5    ^^^37.614^               .037614
3PE10.5    ^^37.614E2            3761.4
-3PE10.5   ^^^^37.614           37614.0

Output Processing

On output, the effect of the scale factor depends on the type of field descriptor associated with it. For the F field descriptor, the value of the I/O list element is multiplied by 10**n before transfer to the external record. A positive scale factor moves the decimal point to the right. A negative scale factor moves the decimal point to the left.

For the E or D field descriptor, the basic real constant part of the I/O list element is multiplied by 10**n, and n is subtracted from the exponent. For a positive scale factor, n must be less than (d + 2) or an output conversion error occurs. A positive scale factor moves the decimal point to the right and decreases the exponent. A negative scale factor moves the decimal point to the left and increases the exponent.

The following list illustrates valid output processing using scale factor editing (the symbol ^ represents a nonprinting space character):

Format      Internal Value       External Representation
1PE12.3     -270.139             ^^-2.701E+02
1P,E12.2    -270.139             ^^^-2.70E+02
-1PE12.2    -270.139            ^^^-0.03E+04

The effect of the scale factor for the G field descriptor is suspended if the magnitude of the data to be output is within the effective range of the descriptor, because the G field descriptor supplies its own scaling function. The G field descriptor functions as an E field descriptor if the magnitude of the data value is outside its range. In this case, the scale factor has the same effect as for the E field descriptor.

On input and on output under F field descriptor control, a scale factor actually alters the magnitude of the data. On output, a scale factor under E, D, or G field descriptor control merely alters the form in which the data is transferred.

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.

If you do not specify a scale factor with a field descriptor, a default scale factor of zero is assumed. In the following example, the scale factor 2PF8.2 affects all subsequent real field descriptors in the FORMAT statement:

     DIMENSION A(6)
     DO 10 I=1,6
10   A(I)  = 25.
     WRITE (6, 100) A
100  FORMAT(' ', F8.2, 2PF8.2, F8.2)

These statements produce the following results:

    25.00 2500.00 2500.00
  2500.00 2500.00 2500.00

If a second scale factor appears in the FORMAT statement, it takes control from the first scale factor.

Format reversion has no effect on the scale factor (see Section 8.10). A scale factor of zero can be reinstated only by an explicit 0P specification.


Previous Page Next Page Table of Contents