    PROGRAM g13cdfe

!      G13CDF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g13cdf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: pw, pxy
       INTEGER                         :: ifail, ish, j, kc, l, m, mtxy, mw,   &
                                          ng, nxy
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: xg(:), yg(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          ceiling, log, real
!      .. Executable Statements ..
       WRITE (nout,*) 'G13CDF Example Program Results'
       WRITE (nout,*)

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

!      Read in the problem size
       READ (nin,*) nxy, l

!      Read in control parameters
       READ (nin,*) mtxy, pxy, pw, mw, ish

!      Get a value for KC
       m = ceiling(log(2.0E0_nag_wp*real(nxy,kind=nag_wp)/real(l, &
          kind=nag_wp))/log(2.0E0_nag_wp))
       kc = (2**m)*l
       ALLOCATE (xg(kc),yg(kc))

!      Read in data
       READ (nin,*) xg(1:nxy)
       READ (nin,*) yg(1:nxy)

       ifail = 0
       CALL g13cdf(nxy,mtxy,pxy,mw,ish,pw,l,kc,xg,yg,ng,ifail)

!      Display results
       WRITE (nout,*) '                      Returned sample spectrum'
       WRITE (nout,*)
       WRITE (nout,*) &
          '      Real  Imaginary       Real  Imaginary       Real  Imaginary'
       WRITE (nout,*) &
          '      part     part         part     part         part     part'
       WRITE (nout,99999) (j,xg(j),yg(j),j=1,ng)

99999  FORMAT (1X,I3,F8.4,F9.4,I5,F8.4,F9.4,I5,F8.4,F9.4)
    END PROGRAM g13cdfe
