NAG Library Manual, Mark 28.3
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
!   C06FXF Example Program Text
!   Mark 28.3 Release. NAG Copyright 2022.

    Module c06fxfe_mod

!     C06FXF Example Program Module:
!            Parameters and User-defined Routines

!     .. Use Statements ..
      Use nag_library, Only: nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Accessibility Statements ..
      Private
      Public                           :: readxy, writxy
!     .. Parameters ..
      Integer, Parameter, Public       :: nin = 5, nout = 6
    Contains
      Subroutine readxy(nin,x,y,n1,n2,n3)
!       Read 3-dimensional complex data

!       .. Scalar Arguments ..
        Integer, Intent (In)           :: n1, n2, n3, nin
!       .. Array Arguments ..
        Real (Kind=nag_wp), Intent (Out) :: x(n1,n2,n3), y(n1,n2,n3)
!       .. Local Scalars ..
        Integer                        :: i, j, k
!       .. Executable Statements ..
        Do i = 1, n1
          Do j = 1, n2
            Read (nin,*)(x(i,j,k),k=1,n3)
            Read (nin,*)(y(i,j,k),k=1,n3)
          End Do
        End Do
        Return
      End Subroutine readxy

      Subroutine writxy(nout,x,y,n1,n2,n3)
!       Print 3-dimensional complex data

!       .. Scalar Arguments ..
        Integer, Intent (In)           :: n1, n2, n3, nout
!       .. Array Arguments ..
        Real (Kind=nag_wp), Intent (In) :: x(n1,n2,n3), y(n1,n2,n3)
!       .. Local Scalars ..
        Integer                        :: i, j, k
!       .. Executable Statements ..
        Do i = 1, n1
          Write (nout,*)
          Write (nout,99998) 'z(i,j,k) for i =', i
          Do j = 1, n2
            Write (nout,*)
            Write (nout,99999) 'Real ', (x(i,j,k),k=1,n3)
            Write (nout,99999) 'Imag ', (y(i,j,k),k=1,n3)
          End Do
        End Do
        Return

99999   Format (1X,A,7F10.3,/,(6X,7F10.3))
99998   Format (1X,A,I6)
      End Subroutine writxy
    End Module c06fxfe_mod

    Program c06fxfe

!     C06FXF Example Main Program

!     .. Use Statements ..
      Use c06fxfe_mod, Only: nin, nout, readxy, writxy
      Use nag_library, Only: c06fxf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Local Scalars ..
      Integer                          :: ieof, ifail, n, n1, n2, n3
      Character (1)                    :: cdum
!     .. Local Arrays ..
      Real (Kind=nag_wp)               :: dum(1)
      Real (Kind=nag_wp), Allocatable  :: x(:), y(:)
!     .. Executable Statements ..
      Write (nout,*) 'C06FXF Example Program Results'
!     Skip heading in data file
      Read (nin,*)

loop: Do
        Read (nin,*,Iostat=ieof) n1, n2, n3
        If (ieof<0) Then
          Exit loop
        End If

        n = n1*n2*n3
        Allocate (x(n),y(n))

        Call readxy(nin,x,y,n1,n2,n3)
        Write (nout,*)
        Write (nout,*) 'Original data values'
        Call writxy(nout,x,y,n1,n2,n3)

!       ifail: behaviour on error exit
!              =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
        ifail = 0
!       -- Compute transform
        Call c06fxf(n1,n2,n3,x,y,cdum,dum,dum,dum,dum,ifail)

        Write (nout,*)
        Write (nout,*) 'Components of discrete Fourier transform'
        Call writxy(nout,x,y,n1,n2,n3)

!       -- Compute inverse transform
        y(1:n) = -y(1:n)
        Call c06fxf(n1,n2,n3,x,y,cdum,dum,dum,dum,dum,ifail)
        y(1:n) = -y(1:n)

        Write (nout,*)
        Write (nout,*) 'Original sequence as restored by inverse transform'
        Call writxy(nout,x,y,n1,n2,n3)
        Deallocate (x,y)
      End Do loop

    End Program c06fxfe