    PROGRAM nag_fft_ex16

      ! 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_real, nag_key_herm, &
       nag_fft_trig, nag_conj_herm, nag_herm_to_cmplx
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC AIMAG, KIND, REAL
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, n
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: trig(:), z(:)
      COMPLEX (wp), ALLOCATABLE :: z_cmplx(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_fft_ex16'
      WRITE (nag_std_out,*)

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

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

      READ (nag_std_in,*) z

      WRITE (nag_std_out,*) 'Original data values'
      WRITE (nag_std_out,'(1X,F10.4)') z

      CALL nag_herm_to_cmplx(z,z_cmplx)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Original data written in full complex form'
      DO i = 1, n
        WRITE (nag_std_out,'(1X,A,F7.4,A,F7.4,A)') ' (', REAL(z_cmplx(i)), &
         ',', AIMAG(z_cmplx(i)), ') '
      END DO

      CALL nag_fft_trig(trig)

      CALL nag_fft_1d_basic(nag_key_herm,z,trig=trig)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Discrete Fourier transform (real values)'
      WRITE (nag_std_out,'(1X,F10.4)') z

      CALL nag_fft_1d_basic(nag_key_real,z,trig=trig)

      CALL nag_conj_herm(z)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Original data restored by inverse transform'
      WRITE (nag_std_out,'(1X,F10.4)') z

      DEALLOCATE (z,z_cmplx,trig)  ! Deallocate storage

    END PROGRAM nag_fft_ex16
