    PROGRAM g13dxfe

!      G13DXF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g13dxf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, ip, k, kip, npar
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: par(:), ri(:), rmod(:), rr(:), work(:)
       INTEGER, ALLOCATABLE            :: iwork(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G13DXF Example Program Results'
       WRITE (nout,*)

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

!      Read in problem size
       READ (nin,*) k, ip

       kip = k*ip
       npar = k*kip
       ALLOCATE (par(npar),rr(kip),ri(kip),rmod(kip),work(ip*npar),iwork(kip))

!      Read the AR (or MA) parameters
       READ (nin,*) par(1:npar)

!      Calculate zeros
       ifail = 0
       CALL g13dxf(k,ip,par,rr,ri,rmod,work,iwork,ifail)

!      Display results
       WRITE (nout,*) '        Eigenvalues       Moduli'
       WRITE (nout,*) '        -----------       ------'
       DO i = 1, k*ip
          IF (ri(i)>=0.0E0_nag_wp) THEN
             WRITE (nout,99999) rr(i), ri(i), rmod(i)
          ELSE
             WRITE (nout,99998) rr(i), -ri(i), rmod(i)
          END IF
       END DO

99999  FORMAT (' ',F10.3,'  + ',F6.3,' i  ',F8.3)
99998  FORMAT (' ',F10.3,'  - ',F6.3,' i  ',F8.3)
    END PROGRAM g13dxfe
