    PROGRAM d06abfe

!      D06ABF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : d06abf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: dnvint
       INTEGER                         :: i, i1, ifail, itrace, j, k, liwork,  &
                                          lrwork, nedge, nelt, npropa, nv,     &
                                          nvb, nvint, nvmax, reftk
       CHARACTER (1)                   :: pmesh
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: coor(:,:), rwork(:), weight(:)
       INTEGER, ALLOCATABLE            :: conn(:,:), edge(:,:), iwork(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          real
!      .. Executable Statements ..
       WRITE (nout,*) 'D06ABF Example Program Results'

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

!      Reading of the geometry
!      Coordinates of the boundary mesh vertices and
!      edges references.

       READ (nin,*) nvb, nvint, nvmax, nedge
       lrwork = 12*nvmax + 15
       liwork = 6*nedge + 32*nvmax + 2*nvb + 78
       ALLOCATE (coor(2,nvmax),rwork(lrwork),weight(nvint),conn(3,2*nvmax+5), &
          edge(3,nedge),iwork(liwork))

       DO i = 1, nvb
          READ (nin,*) i1, coor(1,i), coor(2,i)
       END DO

!      Boundary edges

       DO i = 1, nedge
          READ (nin,*) i1, edge(1,i), edge(2,i), edge(3,i)
       END DO

       READ (nin,*) pmesh

!      Initialise mesh control parameters

       itrace = 0

!      Generation of interior vertices on the
!      RAE airfoil's wake

       dnvint = 2.5E0_nag_wp/real(nvint+1,kind=nag_wp)

       DO i = 1, nvint
          i1 = nvb + i
          coor(1,i1) = 1.38E0_nag_wp + real(i,kind=nag_wp)*dnvint
          coor(2,i1) = -0.27E0_nag_wp*coor(1,i1) + 0.2E0_nag_wp
       END DO

       weight(1:nvint) = 0.01E0_nag_wp

       WRITE (nout,*)

!      Loop on the propagation coef

PCOEF: DO j = 1, 4

          SELECT CASE (j)
          CASE (1)
             npropa = -5
          CASE (2)
             npropa = -1
          CASE (3)
             npropa = 1
          CASE DEFAULT
             npropa = 5
          END SELECT

!         Call to the 2D Delaunay-Voronoi mesh generator

          ifail = 0
          CALL d06abf(nvb,nvint,nvmax,nedge,edge,nv,nelt,coor,conn,weight, &
             npropa,itrace,rwork,lrwork,iwork,liwork,ifail)

          SELECT CASE (pmesh)
          CASE ('N')
             WRITE (nout,99999) 'Mesh characteristics with NPROPA =', npropa
             WRITE (nout,99999) 'NV   =', nv
             WRITE (nout,99999) 'NELT =', nelt
          CASE ('Y')

!            Output the mesh

             WRITE (nout,99998) nv, nelt

             DO i = 1, nv
                WRITE (nout,99997) coor(1,i), coor(2,i)
             END DO

             reftk = 0

             DO k = 1, nelt
                WRITE (nout,99996) conn(1,k), conn(2,k), conn(3,k), reftk
             END DO

          CASE DEFAULT
             WRITE (nout,*) 'Problem with the printing option Y or N'
             EXIT PCOEF
          END SELECT

       END DO PCOEF

99999  FORMAT (1X,A,I6)
99998  FORMAT (1X,2I10)
99997  FORMAT (2(2X,E13.6))
99996  FORMAT (1X,4I10)
    END PROGRAM d06abfe
