    PROGRAM s21bdfe

!      S21BDF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, s21bdf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: r, rj, x, y, z
       INTEGER                         :: ifail, ix, iy, iz
!      .. Intrinsic Functions ..
       INTRINSIC                          real
!      .. Executable Statements ..
       WRITE (nout,*) 'S21BDF Example Program Results'

       WRITE (nout,*)
       WRITE (nout,*) '    X      Y      Z      R        S21BDF'
       WRITE (nout,*)

DATA:  DO ix = 1, 3
          x = real(ix,kind=nag_wp)*0.5E0_nag_wp

          DO iy = ix, 3
             y = real(iy,kind=nag_wp)*0.5E0_nag_wp

             DO iz = iy, 3
                z = real(iz,kind=nag_wp)*0.5E0_nag_wp
                r = 2.0E0_nag_wp

                ifail = -1
                rj = s21bdf(x,y,z,r,ifail)

                IF (ifail<0) THEN
                   EXIT DATA
                END IF

                WRITE (nout,99999) x, y, z, r, rj
             END DO

          END DO

       END DO DATA

99999  FORMAT (1X,4F7.2,F12.4)
    END PROGRAM s21bdfe
