    PROGRAM g13cffe

!      G13CFF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g13cff, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, j, ng
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: gn(:), gnlw(:), gnup(:), ph(:),      &
                                          phlw(:), phup(:), xg(:), xyig(:),    &
                                          xyrg(:), yg(:)
       REAL (KIND=nag_wp)              :: stats(4)
!      .. Executable Statements ..
       WRITE (nout,*) 'G13CFF Example Program Results'
       WRITE (nout,*)

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

!      Read in problem size
       READ (nin,*) ng

       ALLOCATE (xg(ng),yg(ng),xyrg(ng),xyig(ng),gn(ng),gnlw(ng),gnup(ng), &
          ph(ng),phlw(ng),phup(ng))

!      Read in statistics
       READ (nin,*) stats(1:4)

!      Read in data
       READ (nin,*) (xg(i),yg(i),xyrg(i),xyig(i),i=1,ng)

!      Calculate gain and phase
       ifail = -1
       CALL g13cff(xg,yg,xyrg,xyig,ng,stats,gn,gnlw,gnup,ph,phlw,phup,ifail)
       IF (ifail/=0) THEN
          IF (ifail<2) THEN
             GO TO 20
          END IF
       END IF

!      Display results
       WRITE (nout,*) '              The gain'
       WRITE (nout,*)
       WRITE (nout,*) '                    Lower     Upper'
       WRITE (nout,*) '          Value     bound     bound'
       WRITE (nout,99999) (j-1,gn(j),gnlw(j),gnup(j),j=1,ng)
       WRITE (nout,*)
       WRITE (nout,*) '             The phase'
       WRITE (nout,*)
       WRITE (nout,*) '                    Lower     Upper'
       WRITE (nout,*) '          Value     bound     bound'
       WRITE (nout,99999) (j-1,ph(j),phlw(j),phup(j),j=1,ng)

20     CONTINUE

99999  FORMAT (1X,I5,3F10.4)
    END PROGRAM g13cffe
