! 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.27.
  program F27
    implicit none
    integer, parameter :: N = 10
    integer, dimension(2), parameter :: YShape = (/ 3, 2 /), ZShape = (/ N, N /)
    integer :: I, J, Loop  ! I and J are ACID variables.
    real, dimension(2) :: X
    real, dimension(3, 2) :: Y
    real, dimension(N * N) :: Q
    real, dimension(N, N) :: Z
! start program F27
    X = (/ 4.5, 4.5 /)
    Y = reshape ((/ (I + 0.2, I = 1, 3), X, 2.0 /), YShape)
    Q = (/ ((0.0, J = 1, I - 1), 1.0, (0.0, J = I + 1, N), I = 1, N) /)
    Z = reshape (Q, ZShape)
    write (unit = *, fmt = *) " X: ", X
    write (unit = *, fmt = *) " Y: "
    do Loop = 1, 3
      write (unit = *, fmt = *) " Row ", Loop
      write (unit = *, fmt = *) Y(Loop, :)
    end do
    write (unit = *, fmt = *) " Z: "
    do Loop = 1, N
      write (unit = *, fmt = *) " Row ", Loop
      write (unit = *, fmt = *) Z(Loop, :)
    end do
    write (unit = *, fmt = *) " Q: ", Q
    stop
  end program F27
