! 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.30. Where construct vs, merge intrinsic
  program F30
    implicit none
    real, dimension(5, 2), parameter :: A = 5.0
    real, dimension(2, 3), parameter :: B = 3.0
    real, dimension(5, 3) :: C, D
!  start program F30
    C = 1.0
    C(3, :) = 0.0
    C(:, 2) = 0.0
    D = C
    where (C /= 0.0)  ! Where construct
      C = matmul( A, B ) + 2.0 / C
    end where
    D = merge( matmul(A, B) + 2.0, D, D /= 0.0 )
    write (unit = *, fmt = *) all( C == D )
    write (unit = *, fmt = *) " C: ", C
    write (unit = *, fmt = *) " D: ", D
    stop
  end program F30
