Try out NAG Library functions

Explore NAG maths and stats routines with interactive demos
Function ID
Single one-dimensional complex discrete Fourier transform, complex data type
Fast Fourier Transform | FFT | Fourier transforms, complex
This example reads in a sequence of complex data values and prints their discrete Fourier transform (as computed by C06PCF with DIRECT='F'). It then performs an inverse transform using C06PCF with DIRECT='B', and prints the sequence so obtained alongside the original data values.
The example data reflects that shown in the "Example" section of the routine documentation. You can change this here to try alternative inputs. The formatting will need to be kept as it is here, otherwise the program is likely to fail to run correctly.

Please note that incompatible data will however cause the example output to display an error message. These error messages are fully explained in the Routine document
    Program c06pcfe

!     C06PCF Example Program Text

!     Mark 26 Release. NAG Copyright 2016.

!     .. Use Statements ..
      Use nag_library, Only: c06pcf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: ieof, ifail, j, n
!     .. Local Arrays ..
      Complex (Kind=nag_wp), Allocatable :: work(:), x(:), xx(:)
!     .. Executable Statements ..
      Write (nout,*) 'C06PCF Example Program Results'
!     Skip heading in data file
      Read (nin,*)
loop: Do
        Read (nin,*,Iostat=ieof) n
        If (ieof<0) Then
          Exit loop
        End If

        Allocate (work(2*n+15),x(0:n-1),xx(0:n-1))
        Read (nin,*) x(0:n-1)
        xx(0:n-1) = x(0:n-1)

!       ifail: behaviour on error exit
!              =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
        ifail = 0
        Call c06pcf('F',x,n,work,ifail)

        Write (nout,*)
        Write (nout,*) 'Components of discrete Fourier transform'
        Write (nout,*)
        Write (nout,*) '              Real      Imag'
        Write (nout,*)
        Do j = 0, n - 1
          Write (nout,99999) j, x(j)
        End Do

        Call c06pcf('B',x,n,work,ifail)

        Write (nout,*)
        Write (nout,*) 'Original sequence as restored by inverse transform'
        Write (nout,*)
        Write (nout,*) '                 Original                 Restored'
        Write (nout,*) '              Real      Imag           Real      Imag'
        Write (nout,*)
        Do j = 0, n - 1
          Write (nout,99999) j, xx(j), x(j)
        End Do
        Deallocate (work,x,xx)
      End Do loop

99999 Format (1X,I5,2(:,5X,'(',F8.5,',',F8.5,')'))
    End Program c06pcfe
The NAG Library
The world’s largest collection of robust, documented, tested and maintained numerical algorithms.
Learn more here or contact us for purchasing information