    PROGRAM nag_fft_ex09

      ! 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_3d_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, j, m, n, p
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: trig_1(:), trig_2(:), trig_3(:)
      COMPLEX (wp), ALLOCATABLE :: z(:,:,:)
      CHARACTER (20), ALLOCATABLE :: title(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_fft_ex09'
      WRITE (nag_std_out,*)

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

      ALLOCATE (z(m,n,p),trig_1(2*m),trig_2(2*n),trig_3(2*p),title(m)) ! Allocate
      ! storage

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

      title(1) = 'Sequence z(1,:,:)'
      title(2) = 'Sequence z(2,:,:)'

      WRITE (nag_std_out,*) 'Original data'
      DO i = 1, m

        CALL nag_write_gen_mat(z(i,:,:),format='f7.4',int_row_labels=.TRUE., &
         title=title(i))

      END DO
      WRITE (nag_std_out,*)

      CALL nag_fft_trig(trig_1)

      CALL nag_fft_trig(trig_2)

      CALL nag_fft_trig(trig_3)

      CALL nag_fft_3d_basic(z,trig_1=trig_1,trig_2=trig_2,trig_3=trig_3)

      WRITE (nag_std_out,*) 'Components of discrete Fourier transform'
      DO i = 1, m

        CALL nag_write_gen_mat(z(i,:,:),format='f7.4',int_row_labels=.TRUE., &
         title=title(i))

      END DO
      WRITE (nag_std_out,*)

      z = CONJG(z)

      CALL nag_fft_3d_basic(z,trig_1=trig_1,trig_2=trig_2,trig_3=trig_3)

      z = CONJG(z)

      WRITE (nag_std_out,*) 'Original data restored by inverse transform'
      DO i = 1, m

        CALL nag_write_gen_mat(z(i,:,:),format='f7.4',int_row_labels=.TRUE., &
         title=title(i))

      END DO
      DEALLOCATE (z,trig_1,trig_2,trig_3) ! Deallocate storage

    END PROGRAM nag_fft_ex09
