typestar

Format descriptors in Fortran

The format string is a little language: i0, f9.2, and es for scientific.

program format_descriptors
    implicit none
    real :: price = 1234.5
    integer :: stock = 87

    ! Edit descriptors: i0 bare integer, f fixed point, a text, x space.
    print '(a, i0, a)', "on the shelf: ", stock, " tins"
    print '(a, f9.2)', "invoice: ", price
    ! Repeat counts stamp columns; es gives scientific notation.
    print '(3(i4))', 61, 68, 74
    print '(a, es10.3)', "in shorthand: ", price
end program format_descriptors

How it works

  1. '(a, i0, a)' prints text, a bare integer, text — no width guessing.
  2. f9.2 fixes the decimal layout for money-like output.
  3. 3(i4) repeats a column three times, and es10.3 goes scientific.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
411
Tokens
47
Three-star pace
60 tpm

At the three-star pace of 60 tokens a minute, this run takes about 47 seconds.

Type this snippet

Step 2 of 3 in Strings & formats, step 17 of 27 in Language basics.

← Previous Next →