! 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 1.2. Absorption and Reflection at the Surface of a Metal.
  program B02
    implicit none  ! directive
    real :: Pi, Lambda, Alpha, Y, R  ! type declarations
    complex, dimension(3) :: N
    integer :: I
! start program B02
    Lambda = 598.3
    Pi = atan2( 0.0, -1.0 )
    write (unit = *, fmt = *) Lambda
    N(1) = (0.04, 2.4)  ! Complex index of refraction for Sodium.
    N(2) = (1.5, 5.3)  ! Complex index of refraction for Tin.
    N(3) = (3.7, 5.4)  ! Complex index of refraction for Gallium.
    do I = 1, 3
      Alpha = 4.0 * Pi * aimag( N(I) ) / Lambda  ! Absorption coefficient.
      Y = 1.0 / Alpha  ! Skin depth.
      R = abs( (N(I) - 1.0) / (N(I) + 1.0) ) ** 2  ! Reflectance.
      write (unit = *, fmt = *) N(I), Alpha, " Depth: ", Y, " Reflectance: ", R
    end do
    stop
  end program B02
