    Program c06hafe

!     C06HAF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

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

        Allocate (trig(2*n),work(m*n),x(m*n))
        Do j = 1, m
          Read (nin,*)(x((i-1)*m+j),i=1,n-1)
        End Do
        Write (nout,*)
        Write (nout,*) 'Original data values'
        Write (nout,*)
        Do j = 1, m
          Write (nout,99999)(x((i-1)*m+j),i=1,n-1)
        End Do

!       ifail: behaviour on error exit   
!              =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
        ifail = 0
!       -- Compute transform
        Call c06haf(m,n,x,'Initial',trig,work,ifail)

        Write (nout,*)
        Write (nout,*) 'Discrete Fourier sine transforms'
        Write (nout,*)
        Do j = 1, m
          Write (nout,99999)(x((i-1)*m+j),i=1,n-1)
        End Do

!       -- Compute inverse transform
        Call c06haf(m,n,x,'Subsequent',trig,work,ifail)

        Write (nout,*)
        Write (nout,*) 'Original data as restored by inverse transform'
        Write (nout,*)
        Do j = 1, m
          Write (nout,99999)(x((i-1)*m+j),i=1,n-1)
        End Do
        Deallocate (trig,work,x)
      End Do loop

99999 Format (6X,6F10.4)
    End Program c06hafe
