NAG Library Manual, Mark 30
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program c06pafe

!     C06PAF Example Program Text

!     Mark 30.0 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use nag_library, Only: c06paf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: ieof, ifail, j, n, nj
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: work(:), x(:), xx(:)
!     .. Executable Statements ..
      Write (nout,*) 'C06PAF Example Program Results'
!     Skip heading in data file
      Read (nin,*)
loop: Do
        Read (nin,*,Iostat=ieof) n
        If (ieof<0) Then
          Exit loop
        End If

        Allocate (work(3*n+100),x(0:n+1),xx(0:n-1))
        Read (nin,*) x(0:n-1)
        xx(0:n-1) = x(0:n-1)

!       ifail: behaviour on error exit
!              =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
        ifail = 0
        Call c06paf('F',x,n,work,ifail)

        Write (nout,*)
        Write (nout,*) 'Components of discrete Fourier transform'
        Write (nout,*)
        Write (nout,*) '          Real      Imag'
        Write (nout,*)
        Write (nout,99999)(j,x(2*j),x(2*j+1),j=0,n/2)
        Do j = n/2 + 1, n - 1
          nj = n - j
          Write (nout,99999) j, x(2*nj), -x(2*nj+1)
        End Do

        Call c06paf('B',x,n,work,ifail)

        Write (nout,*)
        Write (nout,*) 'Original sequence as restored by inverse transform'
        Write (nout,*)
        Write (nout,*) '        Original  Restored'
        Write (nout,*)
        Write (nout,99999)(j,xx(j),x(j),j=0,n-1)
        Deallocate (work,x,xx)
      End Do loop

99999 Format (1X,I5,2F10.5)
    End Program c06pafe