[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP Fortran for OpenVMS
Language Reference Manual


Previous Contents Index

Rules for Output Processing

On output, the A data edit descriptor transfers the contents of the corresponding I/O list item to an external field that is w characters long.

If w is greater than the size of the list item, the data is transferred to the output field, right-justified, with leading blanks. If w is less than or equal to the size of the list item, the leftmost w characters are transferred.

The following shows output using the A edit descriptor:

Format Value Output
A5 OHMS -OHMS
A5 VOLTS VOLTS
A5 AMPERES AMPER

11.3.7 Default Widths for Data Edit Descriptors

If w (the field width) is omitted for the data edit descriptors, the system applies default values. For the real data edit descriptors, the system also applies default values for d (the number of characters to the right of the decimal point), and e (the number of characters in the exponent).

These defaults are based on the data type of the I/O list item, and are listed in Table 11-4.

Table 11-4 Default Widths for Data Edit Descriptors
Edit Descriptor Data Type of I/O List Item w
I, B, O, Z, G BYTE 7
  INTEGER(1), LOGICAL(1) 7
  INTEGER(2), LOGICAL(2) 7
  INTEGER(4), LOGICAL(4) 12
  INTEGER(8), LOGICAL(8) 23
O, Z REAL(4) 12
  REAL(8) 23
  REAL(16) 44
  CHARACTER*len MAX(7, 3*len)
L, G LOGICAL(1), LOGICAL(2)
LOGICAL(4), LOGICAL(8)
2
F, E, EN, ES, G, D REAL(4), COMPLEX(4) 15 d: 7 e: 2
  REAL(8), COMPLEX(8) 25 d: 16 e: 2
  REAL(16), COMPLEX(16) 42 d: 33 e: 3
A 1, G LOGICAL(1) 1
  LOGICAL(2), INTEGER(2) 2
  LOGICAL(4), INTEGER(4) 4
  LOGICAL(8), INTEGER(8) 8
  REAL(4), COMPLEX(4) 4
  REAL(8), COMPLEX(8) 8
  REAL(16), COMPLEX(16) 16
  CHARACTER*len len

1The default is the actual length of the corresponding I/O list item.

11.3.8 Terminating Short Fields of Input Data

On input, an edit descriptor such as Fw.d specifies that w characters (the field width) are to be read from the external field.

If the field contains fewer than w characters, the input statement will read characters from the next data field in the record. You can prevent this by padding the short field with blanks or zeros, or by using commas to separate the input data.

Padding Short Fields

You can use the OPEN statement specifier PAD= ' YES ' to indicate blank padding for short fields of input data. However, blanks can be interpreted as blanks or zeros, depending on which default behavior is in effect at the time. Consider the following:


READ (2, '(I5)') J

If 3 is input for J, the value of J will be 30000 or 3 depending on which default behavior is in effect (BLANK='NULL' or BLANK='ZERO'). This can give unexpected results.

To ensure that the desired behavior is in effect, explicitly specify the BN or BZ edit descriptor. For example, the following ensures that blanks are interpreted as blanks (and not as zeros):


READ (2, '(BN, I5)') J

Using Commas to Separate Input Data

You can use a comma to terminate a short data field. The comma has no effect on the d part (the number of characters to the right of the decimal point) of the specification.

The comma overrides the w specified for the I, B, O, Z, F, E, D, EN, ES, G, and L edit descriptors. For example, suppose the following statements are executed:


     READ (5,100) I,J,A,B
100  FORMAT (2I6,2F10.2)

Suppose a record containing the following values is read:


1, -2, 1.0, 35

The following assignments occur:


I = 1
J = -2
A = 1.0
B = 0.35

A comma can only terminate fields less than w characters long. If a comma follows a field of w or more characters, the comma is considered part of the next field.

A null (zero-length) field is designated by two successive commas, or by a comma after a field of w characters. Depending on the field descriptor specified, the resulting value assigned is 0, 0.0, 0.0D0, 0.0Q0, or .FALSE.

For More Information:

On input processing, see Section 11.3.2.

11.4 Control Edit Descriptors

A control edit descriptor either directly determines how text is displayed or affects the conversions performed by subsequent data edit descriptors.

This section describes the forms for control edit descriptors and the individual descriptors themselves.

11.4.1 Forms for Control Edit Descriptors

A control edit descriptor takes one of the following forms:


  • c
  • cn
  • nc

c

Is one of the following format codes: T, TL, TR, X, S, SP, SS, BN, BZ, P, :, /, \, $, and Q.

n

Is a number of character positions. It must be a positive integer literal constant; or variable format expression; no kind parameter can be specified. It cannot be a named constant.

The range of n is 1 through 2147483647 (2**31--1). Actual useful ranges may be constrained by record sizes (RECL) and the file system.

Rules and Behavior

In general, control edit descriptors are nonrepeatable. The only exception is the slash (/) edit descriptor, which can be preceded by a repeat specification.

The control edit descriptors have the following specific forms:

Positional: Tn, TLn, TRn, and nX
Sign: S, SP, and SS
Blank interpretation: BN and BZ
Scale factor: kP
Miscellaneous: :, /, \, $, and Q

The P edit descriptor is an exception to the general control edit descriptor syntax. It is preceded by a scale factor, rather than a character position specifier.

Control edit descriptors can be grouped in parentheses and preceded by a group repeat specification.

For More Information:

11.4.2 Positional Editing

The T, TL, TR, and X edit descriptors specify the position where the next character is transferred to or from a record.

On output, these descriptors do not themselves cause characters to be transferred and do not affect the length of the record. If characters are transferred to positions at or after the position specified by one of these descriptors, positions skipped and not previously filled are filled with blanks. The result is as if the entire record was initially filled with blanks.

The TR and X edit descriptors produce the same results.

11.4.2.1 T Editing

The T edit descriptor specifies a character position in an I/O record. It takes the following form:


  • Tn

The n is a positive integer literal constant (with no kind parameter) indicating the character position of the record, relative to the left tab limit.

On input, the T descriptor positions the external record at the character position specified by n. On output, the T descriptor indicates that data transfer begins at the nth character position of the external record.

Examples

Suppose a file has a record containing the value ABC---XYZ , and the following statements are executed:


     READ (11,10) VALUE1, VALUE2
10   FORMAT (T7,A3,T1,A3)

The values read first are XYZ, then ABC.

Suppose the following statements are executed:


     PRINT 25
25   FORMAT (T51,'COLUMN 2',T21,'COLUMN 1')

The following line is printed at the positions indicated:


Position 20                    Position 50
   <downarrow symbol>                             <downarrow symbol>
   COLUMN 1                       COLUMN 2

Note that the first character of the record printed was reserved as a control character. (For more information, see Section 11.8.)

11.4.2.2 TL Editing

The TL edit descriptor specifies a character position to the left of the current position in an I/O record. It takes the following form:


  • TLn

The n is a positive integer literal constant (with no kind parameter) indicating the nth character position to the left of the current character.

If n is greater than or equal to the current position, the next character accessed is the first character of the record.

11.4.2.3 TR Editing

The TR edit descriptor specifies a character position to the right of the current position in an I/O record. It takes the following form:


  • TRn

The n is a positive integer literal constant (with no kind parameter) indicating the nth character position to the right of the current character.

11.4.2.4 X Editing

The X edit descriptor specifies a character position to the right of the current position in an I/O record. It takes the following form:


  • nX

The n is a positive integer literal constant (with no kind parameter) indicating the nth character position to the right of the current character.

On output, the X edit descriptor does not output any characters when it appears at the end of a format specification; for example:


     WRITE (6,99) K
99   FORMAT ('-K=',I6,5X)

This example writes a record of only 9 characters. To cause n trailing blanks to be output at the end of a record, specify a format of n('-') .

11.4.3 Sign Editing

The S, SP, and SS edit descriptors control the output of the optional plus (+) sign within numeric output fields. These descriptors have no effect during execution of input statements.

Within a format specification, a sign editing descriptor affects all subsequent I, F, E, EN, ES, D, and G descriptors until another sign editing descriptor occurs.

11.4.3.1 SP Editing

The SP edit descriptor causes the processor to produce a plus sign in any subsequent position where it would be otherwise optional. It takes the following form:


  • SP

11.4.3.2 SS Editing

The SS edit descriptor causes the processor to suppress a plus sign in any subsequent position where it would be otherwise optional. It takes the following form:


  • SS

11.4.3.3 S Editing

The S edit descriptor restores the plus sign as optional for all subsequent positive numeric fields. It takes the following form:


  • S

The S edit descriptor restores to the processor the discretion of producing plus characters on an optional basis.

11.4.4 Blank Editing

The BN and BZ descriptors control the interpretation of embedded and trailing blanks within numeric input fields. These descriptors have no effect during execution of output statements.

Within a format specification, a blank editing descriptor affects all subsequent I, B, O, Z, F, E, EN, ES, D, and G descriptors until another blank editing descriptor occurs.

The blank editing descriptors override the effect of the BLANK specifier during execution of a particular input data transfer statement. (For more information on the BLANK specifier in OPEN statements, see Section 12.6.4.)

11.4.4.1 BN Editing

The BN edit descriptor causes the processor to ignore all embedded and trailing blanks in numeric input fields. It takes the following form:


  • BN

The input field is treated as if all blanks have been removed and the remainder of the field is right-justified. An all-blank field is treated as zero.

11.4.4.2 BZ Editing

The BZ edit descriptor causes the processor to interpret all embedded and trailing blanks in numeric input fields as zeros. It takes the following form:


  • BZ

11.4.5 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 Section 11.9.)

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, 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 following shows input using the P edit descriptor:

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 and ES editing, the scale factor has no effect.

The following shows output using the P edit descriptor:

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

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


Previous Next Contents Index