    Program s30fafe

!     S30FAF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: nag_wp, s30faf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: h, k, q, r, s, sigma
      Integer                          :: i, ifail, j, ldp, m, n
      Character (1)                    :: calput
      Character (2)                    :: type
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: p(:,:), t(:), x(:)
!     .. Executable Statements ..
      Write (nout,*) 'S30FAF Example Program Results'

!     Skip heading in data file
      Read (nin,*)

      Read (nin,*) calput, type
      Read (nin,*) s, h, k, sigma, r, q
      Read (nin,*) m, n

      ldp = m
      Allocate (p(ldp,n),t(n),x(m))

      Read (nin,*)(x(i),i=1,m)
      Read (nin,*)(t(i),i=1,n)

      ifail = 0
      Call s30faf(calput,type,m,n,x,s,h,k,t,sigma,r,q,p,ldp,ifail)

      Write (nout,*)
      Write (nout,*) 'Standard Barrier Option'

      Select Case (calput)
      Case ('C','c')
        Write (nout,*) 'Call :'
      Case ('P','p')
        Write (nout,*) 'Put :'
      End Select

      Select Case (type)
      Case ('DI','di','Di','dI')
        Write (nout,*) 'Down-and-In'
      Case ('DO','do','Do','dO')
        Write (nout,*) 'Down-and-Out'
      Case ('UI','ui','Ui','uI')
        Write (nout,*) 'Up-and-In'
      Case ('UO','uo','Uo','uO')
        Write (nout,*) 'Up-and-Out'
      End Select

      Write (nout,99998) '  Spot       = ', s
      Write (nout,99998) '  Barrier    = ', h
      Write (nout,99998) '  Rebate     = ', k
      Write (nout,99998) '  Volatility = ', sigma
      Write (nout,99998) '  Rate       = ', r
      Write (nout,99998) '  Dividend   = ', q

      Write (nout,*)
      Write (nout,*) '   Strike    Expiry    Option Price'

      Do i = 1, m

        Do j = 1, n
          Write (nout,99999) x(i), t(j), p(i,j)
        End Do

      End Do

99999 Format (1X,2(F9.4,1X),6X,F9.4)
99998 Format (A,1X,F8.4)
    End Program s30fafe
