! 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.1. Complex Impedance of a Circuit Element.
  program B01
    implicit none  ! directive
    complex, parameter :: J_OMEGA = (0.0, 98.7e6)  ! Frequency is 98.7 megaHertz
    real :: VA, VP, R, L, Average_Power  ! type declarations
    complex :: V0, Current, Voltage, Impedance
! start program B01
    write (unit = *, fmt = *) " Please enter source voltage amplitude and phase. "
    read (unit = *, fmt = *) VA, VP
    V0 = cmplx( VA * cos( VP ), VA * sin( VP ) )
    write (unit = *, fmt = *) " Please enter resistance and inductance values. "
    read (unit = *, fmt = *) R, L
    Current = V0 / (R + J_OMEGA * L)
    Average_Power = 0.5 * real( Current * conjg (V0) )
    write (unit = *, fmt = *) Current, Average_Power
    write (unit = *, fmt = *) "Please enter amplitude and phase of voltage across an element. "
    read (unit = *, fmt = *) VA, VP
    Voltage = cmplx( VA * cos( VP ), VA * sin( VP ) )
    Impedance = Voltage / Current
    write (unit = *, fmt = *) Impedance
    stop
  end program B01
