! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

! Example 5.16. (File input.) Sum and Product intrinsic functions.
  program F16
    implicit none
    integer, parameter :: N = 10
    real, dimension(N, N) :: Z
    real :: Z_Sum, Z_Average
! start program f16
    open (unit = 1, file = "f16.txt", status = "old", action = "read", position = "rewind")
    read (unit = 1, fmt = *) Z
    Z_Sum = sum (Z)
    Z_Average = Z_Sum / (N * N)
    Z = Z / Z_Average
    write (unit = *, fmt = "(2 es16.8)") Z_Sum, product (Z)   ! Explicit format: see Section 9.3.
    stop
  end program F16
