HP Fortran Programmer's Reference (September 2007)

I/O formatting
Embedded format specification
Chapter 9264
Embedded format specification
A format specification can be embedded in a data transfer statement as a character
expression. Parentheses are included in the expression, and the first nonblank character must
be a left parenthesis. The matching right parenthesis must also be in the expression. A list of
edit descriptors appears between the parentheses. Any characters appearing after the
matching right parenthesis are ignored.
If the character expression is a character constant, it must be delimited by either apostrophes
or quotation marks. If the character constant contains another character constant, the nested
character constant must also be delimited. If the inner set of delimiters is the same as the
outer set they must be doubled. Each of the following statements is correct and will produce
the same results:
PRINT ”('i = ', i2)”, i
PRINT ”(””i = ””, i2)”, i
PRINT '(”i = ”, i2)', i
PRINT '(''i = '', i2)', i
WRITE (6, ”('i = ', i2)”) i
If the character expression is an array element, the entire specification must be within that
element. If the expression is a whole character array, the format specification is the
concatenation of the array elements in array element order. (As an extension, HP Fortran
allows the use of an integer array to contain a format specification.)
The following illustrates the use of a character array to hold the format specification:
CHARACTER(LEN=6), DIMENSION(2) :: fspec
fspec(1) = '(F8.3,'
fspec(2) = ' I5)'
PRINT fspec, fvar, ivar
If the value of fvar is 12.34567 and ivar is 123, the output would be:
bb
12.346
bb
123