    PROGRAM nag_fft_ex04

      ! 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
      USE nag_write_mat, ONLY : nag_write_gen_mat
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, m, 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_ex04'
      WRITE (nag_std_out,*)

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

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

      DO i = 1, m
        READ (nag_std_in,*) z(i,:)
      END DO

      CALL nag_write_gen_mat(z,format='f10.4',int_row_labels=.TRUE., &
       title='Original data values')

      WRITE (nag_std_out,*)

      CALL nag_fft_trig(trig)

      CALL nag_fft_1d_basic(nag_key_real,z,trig=trig)

      CALL nag_write_gen_mat(z,format='f10.4',int_row_labels=.TRUE., &
       title='Discrete Fourier transforms in Hermitian form')

      WRITE (nag_std_out,*)

      CALL nag_herm_to_cmplx(z,z_cmplx)

      CALL nag_write_gen_mat(z_cmplx,format='f7.4',int_row_labels=.TRUE., &
       title='Fourier transforms in full complex form')

      WRITE (nag_std_out,*)

      CALL nag_conj_herm(z)

      CALL nag_fft_1d_basic(nag_key_herm,z,trig=trig)

      CALL nag_write_gen_mat(z,format='f10.4',int_row_labels=.TRUE., &
       title='Original data restored by inverse transform')

      DEALLOCATE (z,z_cmplx,trig)  ! Deallocate storage

    END PROGRAM nag_fft_ex04
