Most Fortran programmers of a “certain age” don’t give a lot of thought to the FORMAT statement – it’s been in the language “forever”, and many of us use only the capabilities that were provided by FORTRAN 77, or perhaps even FORTRAN IV. But as the Fortran standard has evolved, formats have too, and the Good Doctor decided it’s time to review what’s new in FORMAT since FORTRAN 77.
Zero width for integer and real editing – F95 added a nifty new feature, the ability to specify a field width of zero for integer output editing (I, B, O, Z descriptors) and real output editing (F descriptor.) If zero is specified, “the processor selects the field width”, which typically means that the width is just enough to display the actual significant digits. So, for example:
WRITE (*,"(A,I0,A)") "ABC",123,"DEF"
would write “ABC123DEF”. Note that the standard doesn’t exactly say this is what should happen, a processor (compiler) might “select” one of several preset widths, but minimal width is the intent of this feature and should be the widely implemented interpretation. Note that a zero width is not allowed on input. [Later standards require the minimal width that would not result in a field full of asterisks – Steve]
G format for any datatype – In Fortran 77, the G edit descriptor was usable only with REAL, DOUBLE PRECISION and COMPLEX values, but F90 extended G to INTEGER, LOGICAL and CHARACTER types as well. For these other types, G operates a lot like list-directed formatting, in that the corresponding specific edit descriptor (I, L, A) is used with the width specified (except that for INTEGER data, the width may not be specified as zero.)
EN and ES – Perhaps of more limited interest than the above additions, F90 added EN for “engineering notation” and ES for “scientific notation”. These variants of the E format modify how the fraction and exponent are formatted. With EN, the significand is always greater than or equal to 1 and less than 1000 (except if zero), and the exponent is always a multiple of 3, for example, 12345.0 in EN10.3 format would be “12.345E+03”. With ES, the significand is greater than or equal to 1 and less then 10, and there is no restriction on the exponent. Our value 12345.0 in ES10.4 format would be “1.2345E+04”. For comparison, the more familiar E11.5 format would display “0.12345E+05”. (Note that the standard would also allow “.12345E+05” here, but including the leading zero is the most common practice.)
Fortran 90 also added the widely implemented B, O and Z edit descriptors. You old-timers out there may not be familiar
with some F77 additions, such as TL and TR. All of these are described in the Language Reference manual. Happy formatting!
(From Intel Developer Zone, copied with permission)