    PROGRAM nag_fft_ex07

      ! 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_2d_basic, nag_fft_trig
      USE nag_write_mat, ONLY : nag_write_gen_mat
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC CONJG, KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, m, n
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: trig_m(:), trig_n(:)
      COMPLEX (wp), ALLOCATABLE :: z(:,:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_fft_ex07'
      WRITE (nag_std_out,*)

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

      ALLOCATE (z(m,n),trig_m(2*m),trig_n(2*n)) ! Allocate storage

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

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

      WRITE (nag_std_out,*)

      CALL nag_fft_trig(trig_m)

      CALL nag_fft_trig(trig_n)

      CALL nag_fft_2d_basic(z,trig_m=trig_m,trig_n=trig_n)

      CALL nag_write_gen_mat(z,format='f7.4',int_row_labels=.TRUE., &
       title='Components of discrete Fourier transform')

      WRITE (nag_std_out,*)

      z = CONJG(z)

      CALL nag_fft_2d_basic(z,trig_m=trig_m,trig_n=trig_n)

      z = CONJG(z)

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

      DEALLOCATE (z,trig_m,trig_n) ! Deallocate storage

    END PROGRAM nag_fft_ex07
