Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Variable Format Expressions

A variable format expression is a numeric expression enclosed in angle brackets (< >) that can be used in a FORMAT statement or in a character format specification.

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

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

If the value of a variable format expression does not obey the restrictions on magnitude applying to its use in the format, an error occurs.

Variable format expressions cannot be used with the H edit descriptor, and they are not allowed in character format specifications that are not character constant expressions.

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.

Examples

Consider the following statement:

  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.

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

The following shows another example:

        WRITE(6,20) INT1
 20     FORMAT(I<MAX(20,5)>)

        WRITE(6,FMT=30) REAL2(10), REAL3
 30     FORMAT(<J+K>X, <2*M>F8.3)

The value of the expression is reevaluated each time an input/output item is processed during the execution of the READ, WRITE, or PRINT statement. For example:

        INTEGER width, value
        width=2
        READ (*,10) width, value
 10     FORMAT(I1, I <width>)
        PRINT *, value
        END

When given input 3123, the program will print 123 and not 12.

See Also