## 8.3.7 Variable Format Expressions

By enclosing an arithmetic expression in angle brackets, you can use it in a FORMAT statement wherever you can use an integer (except as the specification of the number of characters in the H field). For example:

    FORMAT (I<J+1>)

When the format is scanned, the preceding statement performs an I (integer) data transfer with a field width of J+1. The expression is reevaluated each time it is encountered in the normal format scan.

Rules and Behavior

If the variable format expression is not of integer data type, it is converted to integer type before being used.

The variable format expression can be any valid Fortran expression, including function calls and references to dummy arguments.

The value of a variable format expression must obey the restrictions on magnitude applying to its use in the format, or an error occurs.

Variable format expressions are not permitted in run-time formats.

Variable format expressions are evaluated each time they are encountered in the scan of the format. If the value of the variable used in the expression changes during the execution of the I/O statement, the new value is used the next time the format item containing the expression is processed.

Example

Consider the following statements:

         DIMENSION A(5)

         DATA A/1.,2.,3.,4.,5./

         DO 10 I=1,10

         WRITE (6,100) I

    100  FORMAT (I<MAX(I,5)>)

    10   CONTINUE

         DO 20 I=1,5

         WRITE (6,101) (A(I),  J=1,I)

    101  FORMAT (<I>F10.<I-1>)

    20   CONTINUE

         END

On execution, these statements produce the following output:

       1

       2

       3

       4

       5

        6

         7

          8

           9

           10

           1.

          2.0        2.0

         3.00       3.00     3.00

        4.000      4.000    4.000     4.000

       5.0000    5.0000    5.0000    5.0000    5.0000

For More Information:

For details on the synchronization of I/O lists with formats, see Section 8.10.

Previous Page Next Page Table of Contents