! 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.20. Impedance matrix.
  program F20
    implicit none
    integer, parameter :: N = 11
    integer :: EoF
    real, dimension(N, N) :: Impedance
    real, dimension(N) :: Currents, Voltages
! start program F20
    open (unit = 1, file = "impedanc.txt", status = "old", action = "read", position = "rewind")
    read (unit = 1, fmt = *, iostat = EoF) Impedance
    if (EoF < 0) then
      write (unit = *, fmt = *) " Insufficient data in file. "
      stop
    end if
    read (unit = 1, fmt = * , iostat = EoF) Currents
    if (EoF < 0) then
      write (unit = *, fmt = *) " Insufficient data in file. "
      stop
    end if
    Voltages = matmul( Impedance, Currents )  ! Intrinsic function
    write (unit = *, fmt = *) Voltages
    stop
  end program F20
