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

NAG FL Interface Introduction
Example description
!   C06PXF Example Program Text
!   Mark 30.3 Release. nAG Copyright 2024.

    Module c06pxfe_mod

!     C06PXF 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                           :: readx, writx
!     .. Parameters ..
      Integer, Parameter, Public       :: nin = 5, nout = 6
    Contains
      Subroutine readx(nin,x,n1,n2,n3)
!       Read 3-dimensional complex data

!       .. Scalar Arguments ..
        Integer, Intent (In)           :: n1, n2, n3, nin
!       .. Array Arguments ..
        Complex (Kind=nag_wp), Intent (Out) :: x(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)
          End Do
        End Do
        Return
      End Subroutine readx

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

!       .. Scalar Arguments ..
        Integer, Intent (In)           :: n1, n2, n3, nout
!       .. Array Arguments ..
        Complex (Kind=nag_wp), Intent (In) :: x(n1,n2,n3)
!       .. Local Scalars ..
        Integer                        :: i, j, k
!       .. Intrinsic Procedures ..
        Intrinsic                      :: aimag, real
!       .. 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 ', (real(x(i,j,k)),k=1,n3)
            Write (nout,99999) 'Imag ', (aimag(x(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 writx
    End Module c06pxfe_mod

    Program c06pxfe

!     C06PXF Example Main Program

!     .. Use Statements ..
      Use c06pxfe_mod, Only: nin, nout, readx, writx
      Use nag_library, Only: c06pxf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Local Scalars ..
      Integer                          :: ieof, ifail, n, n1, n2, n3
!     .. Local Arrays ..
      Complex (Kind=nag_wp), Allocatable :: work(:), x(:)
!     .. Executable Statements ..
      Write (nout,*) 'C06PXF 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),work(n+n1+n2+n3+45))
        Call readx(nin,x,n1,n2,n3)
        Write (nout,*)
        Write (nout,*) 'Original data values'
        Call writx(nout,x,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 c06pxf('F',n1,n2,n3,x,work,ifail)

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

!       -- Compute inverse transform
        Call c06pxf('B',n1,n2,n3,x,work,ifail)

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

    End Program c06pxfe