Fortran Wiki
IO list references in format strings

Proposal: allow integer values in a format statement to reference an value in the I/O list.

A variable FORMAT expression (VFE) is an extension that allows integers to be substituted with a variable name in angle brackets. This is a bad design because the variable name is in a string constant.

An alternative to VFE’s that is much less of a hack is to reference arguments in the I/O list similar to the use if an asterisk in C format strings. The colon character seems approriate for use as a deferred value reference. (I don’t think this will conflict with the existing colon usage, unless the comma preceding it is made optional.)

For example, the following would read lines split into 2 strings, with LEN1 defining the format width of the first string:

READ (LUN,'(A:,A)') LEN1, STR1, STR2

This is a VFE example from the Intel Fortran 10.0 manual:

      WRITE(6,FMT=30) INT2, INT3
  30  FORMAT(I<J+K>, I<2*M>)

Here is the equivalent WRITE statement using this proposal:

      WRITE(6,'(2I:)') J+K, INT2, 2*M, INT3

Many people have argued that VFEs are useful and should be standardized. This approach seems to be equally functional, without the string-embedded variable name references that make VFEs a hack. (NOTE: VFEs are less of a hack with FORMAT statements, but format strings are the preferred form in modern programming. It seems likely that FORMAT will eventually be deprecated.)