Printing REALs with the E Descriptor

WARNING: This example assumes the output is sent to a printer, and as a result, every formatted output contains printer control.

Problem Statement

Write a program that for x = 2.0, 1.8, 1.6, 1.4, ..., 0.8, 0.6, 0.4 and 0.2, prints the sequence number of the value (i.e., 1, 2, 3 and so on), the value itself, and its LOG(x) four times using E, E with three digits for the exponent, ES and EN descriptors. You should generate the output as shown below.
         1    1    2    2    3    3    4    4    5    5    6    6    7    7
....5....0....5....0....5....0....5....0....5....0....5....0....5....0....5
  1   2.00000    0.69315E+00   0.69315E+000    6.93147E-01  693.14718E-03
  2   1.80000    0.58779E+00   0.58779E+000    5.87787E-01  587.78661E-03
  3   1.60000    0.47000E+00   0.47000E+000    4.70004E-01  470.00358E-03
                                   :
                                   :
                                   :
 10   0.20000   -0.16094E+01  -0.16094E+001   -1.60944E+00   -1.60944E+00

Solution

PROGRAM  LogFunction
   IMPLICIT   NONE
   REAL, PARAMETER   :: Initial =  2.0
   REAL, PARAMETER   :: Final   =  0.0
   REAL, PARAMETER   :: Step    = -0.2
   REAL              :: x
   INTEGER           :: Count
   CHARACTER(LEN=80) :: FMT

   FMT   = "(I3, F10.5, E15.5, E15.5E3, ES15.5, EN15.5)"
   Count = 1
   x     = Initial
   DO
      IF (x <= Final)  EXIT
      WRITE(*,FMT)     Count, x, LOG(x), LOG(x), LOG(x), LOG(x)
      x     = x + Step
      Count = Count + 1
   END DO
END PROGRAM  LogFunction
Click here to download this program.

Program Input and Output

The output of the program is:
         1    1    2    2    3    3    4    4    5    5    6    6    7    7
....5....0....5....0....5....0....5....0....5....0....5....0....5....0....5
  1   2.00000    0.69315E+00   0.69315E+000    6.93147E-01  693.14718E-03
  2   1.80000    0.58779E+00   0.58779E+000    5.87787E-01  587.78661E-03
  3   1.60000    0.47000E+00   0.47000E+000    4.70004E-01  470.00358E-03
  4   1.40000    0.33647E+00   0.33647E+000    3.36472E-01  336.47212E-03
  5   1.20000    0.18232E+00   0.18232E+000    1.82321E-01  182.32140E-03
  6   1.00000   -0.17881E-06  -0.17881E-006   -1.78814E-07 -178.81395E-09
  7   0.80000   -0.22314E+00  -0.22314E+000   -2.23144E-01 -223.14376E-03
  8   0.60000   -0.51083E+00  -0.51083E+000   -5.10826E-01 -510.82587E-03
  9   0.40000   -0.91629E+00  -0.91629E+000   -9.16291E-01 -916.29112E-03
 10   0.20000   -0.16094E+01  -0.16094E+001   -1.60944E+00   -1.60944E+00

Discussion