    PROGRAM nag_fft_ex11

      ! Example Program Text for nag_fft
      ! NAG fl90, Release 4. NAG Copyright 2000.

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_in, nag_std_out
      USE nag_fft, ONLY : nag_fft_1d_basic, nag_key_cmplx, nag_fft_trig
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC AIMAG, CONJG, KIND, REAL
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, n
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: trig(:)
      COMPLEX (wp), ALLOCATABLE :: z(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_fft_ex11'
      WRITE (nag_std_out,*)

      READ (nag_std_in,*)          ! Skip heading in data file
      READ (nag_std_in,*) n

      ALLOCATE (z(n),trig(2*n))    ! Allocate storage

      READ (nag_std_in,*) z

      WRITE (nag_std_out,*) 'Original data values'
      DO i = 1, n
        WRITE (nag_std_out,'(1X,A,F7.4,A,F7.4,A)') ' (', REAL(z(i)), ',', &
         AIMAG(z(i)), ') '
      END DO

      CALL nag_fft_trig(trig)

      CALL nag_fft_1d_basic(nag_key_cmplx,z,trig=trig)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Discrete Fourier transform'
      DO i = 1, n
        WRITE (nag_std_out,'(1X,A,F7.4,A,F7.4,A)') ' (', REAL(z(i)), ',', &
         AIMAG(z(i)), ') '
      END DO

      z = CONJG(z)

      CALL nag_fft_1d_basic(nag_key_cmplx,z,trig=trig)

      z = CONJG(z)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Original data restored by inverse transform'
      DO i = 1, n
        WRITE (nag_std_out,'(1X,A,F7.4,A,F7.4,A)') ' (', REAL(z(i)), ',', &
         AIMAG(z(i)), ') '
      END DO

      DEALLOCATE (z,trig)          ! Deallocate storage

    END PROGRAM nag_fft_ex11
