*     D06AAF Example Program Text
*     Mark 20 Release. NAG Copyright 2001.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          NBEDMX, NVMAX, NELTMAX, LIWORK, LRWORK
      PARAMETER        (NBEDMX=100,NVMAX=250,NELTMAX=2*(NVMAX-1),
     +                 LIWORK=16*NVMAX+2*NBEDMX+(4*NVMAX+2)-14,
     +                 LRWORK=NVMAX)
*     .. Local Scalars ..
      DOUBLE PRECISION COEF, POWER
      INTEGER          I, I1, IFAIL, ITRACE, K, NEDGE, NELT, NV, NVB,
     +                 REFTK
      LOGICAL          SMOOTH
      CHARACTER        PMESH
*     .. Local Arrays ..
      DOUBLE PRECISION BSPACE(NVMAX), COOR(2,NVMAX), RWORK(LRWORK)
      INTEGER          CONN(3,NELTMAX), EDGE(3,NBEDMX), IWORK(LIWORK)
*     .. External Subroutines ..
*
      EXTERNAL         D06AAF
*     .. Executable Statements ..
      WRITE (NOUT,*) 'D06AAF Example Program Results'
      WRITE (NOUT,*)
*
*     Skip heading in data file
*
      READ (NIN,*)
*
*     Reading of the geometry
*     Coordinates of the boundary mesh vertices and
*     edges references.
*
      READ (NIN,*) NVB, NEDGE
*
      IF (NVB.GT.NVMAX .OR. NEDGE.GT.NBEDMX) THEN
         WRITE (NOUT,*) 'Problem with the array dimensions '
         WRITE (NOUT,99999) ' NVB MAX ', NVB, NVMAX
         WRITE (NOUT,99999) ' NEDGE MAX ', NEDGE, NBEDMX
         STOP
      END IF
*
      DO 20 I = 1, NVB
         READ (NIN,*) I1, COOR(1,I), COOR(2,I)
   20 CONTINUE
*
*     Boundary edges
*
      DO 40 I = 1, NEDGE
         READ (NIN,*) I1, EDGE(1,I), EDGE(2,I), EDGE(3,I)
   40 CONTINUE
*
*     Initialise mesh control parameters
*
      DO 60 I = 1, NVB
         BSPACE(I) = 0.05D0
   60 CONTINUE
      SMOOTH = .TRUE.
      ITRACE = 0
      COEF = 0.75D0
      POWER = 0.25D0
*
*     Call to the mesh generator
*
      IFAIL = 0
*
      CALL D06AAF(NVB,NVMAX,NEDGE,EDGE,NV,NELT,COOR,CONN,BSPACE,SMOOTH,
     +            COEF,POWER,ITRACE,RWORK,LRWORK,IWORK,LIWORK,IFAIL)
*
      READ (NIN,*) PMESH
*
      IF (PMESH.EQ.'N') THEN
         WRITE (NOUT,99998) 'NV   =', NV
         WRITE (NOUT,99998) 'NELT =', NELT
      ELSE IF (PMESH.EQ.'Y') THEN
*
*     Output the mesh to view it using the NAG Graphics Library
*
         WRITE (NOUT,99997) NV, NELT
         DO 80 I = 1, NV
            WRITE (NOUT,99996) COOR(1,I), COOR(2,I)
   80    CONTINUE
*
         REFTK = 0
         DO 100 K = 1, NELT
            WRITE (NOUT,99995) CONN(1,K), CONN(2,K), CONN(3,K), REFTK
  100    CONTINUE
      ELSE
         WRITE (NOUT,*) 'Problem with the printing option Y or N'
         STOP
      END IF
*
      STOP
*
99999 FORMAT (1X,A,2I6)
99998 FORMAT (1X,A,I6)
99997 FORMAT (1X,2I10)
99996 FORMAT (2(2X,E12.6))
99995 FORMAT (1X,4I10)
      END
