    PROGRAM nag_fft_ex12

      ! 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, nag_fft_trig
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      CHARACTER (*), PARAMETER :: fmt = '(1X,"(",F7.4,",",F7.4,")")'
      ! .. Local Scalars ..
      INTEGER :: n
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: trig(:)
      COMPLEX (wp), ALLOCATABLE :: z(:), zhat(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_fft_ex12'

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

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

      READ (nag_std_in,*) z
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Original data'
      WRITE (nag_std_out,fmt) z

      CALL nag_fft_trig(trig)

      zhat = nag_fft_1d(z,trig=trig)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Transformed data'
      WRITE (nag_std_out,fmt) zhat

      z = nag_fft_1d(zhat,inverse=.TRUE.,trig=trig)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Original data restored by inverse transform'
      WRITE (nag_std_out,fmt) z

      DEALLOCATE (z,zhat,trig)     ! Deallocate storage

    END PROGRAM nag_fft_ex12
