    PROGRAM s30abfe

!      S30ABF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, s30abf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: q, r, s, sigma
       INTEGER                         :: i, ifail, j, ldp, m, n
       CHARACTER (1)                   :: calput
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: charm(:,:), colour(:,:), crho(:,:),  &
                                          delta(:,:), gamma(:,:), p(:,:),      &
                                          rho(:,:), speed(:,:), t(:),          &
                                          theta(:,:), vanna(:,:), vega(:,:),   &
                                          vomma(:,:), x(:), zomma(:,:)
!      .. Executable Statements ..
       WRITE (nout,*) 'S30ABF Example Program Results'

!      Skip heading in data file.
       READ (nin,*)

       READ (nin,*) calput
       READ (nin,*) s, sigma, r, q
       READ (nin,*) m, n

       ldp = m
       ALLOCATE (charm(ldp,n),colour(ldp,n),crho(ldp,n),delta(ldp,n), &
          gamma(ldp,n),p(ldp,n),rho(ldp,n),speed(ldp,n),t(n),theta(ldp,n), &
          vanna(ldp,n),vega(ldp,n),vomma(ldp,n),x(m),zomma(ldp,n))

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

       ifail = 0
       CALL s30abf(calput,m,n,x,s,t,sigma,r,q,p,ldp,delta,gamma,vega,theta, &
          rho,crho,vanna,charm,speed,colour,zomma,vomma,ifail)

       WRITE (nout,*)

       SELECT CASE (calput)
       CASE ('C','c')
          WRITE (nout,*) 'European Call :'
       CASE ('P','p')
          WRITE (nout,*) 'European Put :'
       END SELECT

       WRITE (nout,99997) '  Spot       = ', s
       WRITE (nout,99997) '  Volatility = ', sigma
       WRITE (nout,99997) '  Rate       = ', r
       WRITE (nout,99997) '  Dividend   = ', q

       WRITE (nout,*)

       DO j = 1, n
          WRITE (nout,*)
          WRITE (nout,99999) t(j)
          WRITE (nout,*) '  Strike    Price    Delta    Gamma     Vega    ' // &
             'Theta      Rho     CRho'

          DO i = 1, m
             WRITE (nout,99998) x(i), p(i,j), delta(i,j), gamma(i,j), &
                vega(i,j), theta(i,j), rho(i,j), crho(i,j)
          END DO

          WRITE (nout,*) '  Strike    Price    Vanna    Charm    Speed   ' // &
             'Colour    Zomma    Vomma'

          DO i = 1, m
             WRITE (nout,99998) x(i), p(i,j), vanna(i,j), charm(i,j), &
                speed(i,j), colour(i,j), zomma(i,j), vomma(i,j)
          END DO

       END DO

99999  FORMAT (1X,'Time to Expiry : ',1X,F8.4)
99998  FORMAT (1X,8(F8.4,1X))
99997  FORMAT (A,1X,F8.4)
    END PROGRAM s30abfe
