    PROGRAM g13aafe

!      G13AAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g13aaf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: ifail, nd, nds, ns, nx, nxd
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: x(:), xd(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G13AAF Example Program Results'
       WRITE (nout,*)

!      Skip heading in data file
       READ (nin,*)

!      Read in the problem size
       READ (nin,*) nx, nd, nds, ns

       ALLOCATE (x(nx),xd(nx))

!      Read in data
       READ (nin,*) x(1:nx)

!      Perform differencing
       ifail = 0
       CALL g13aaf(x,nx,nd,nds,ns,xd,nxd,ifail)

!      Display results
       WRITE (nout,99999) 'Non-seasonal differencing of order ', nd, &
          ' and seasonal differencing'
       WRITE (nout,99999) 'of order ', nds, ' with seasonality ', ns, &
          ' are applied'
       WRITE (nout,*)
       WRITE (nout,99998) 'The output array holds ', nx, &
          ' values, of which the first ', nxd, ' are differenced values'
       WRITE (nout,*)
       WRITE (nout,99997) xd(1:nx)

99999  FORMAT (1X,A,I1,A,I1,A)
99998  FORMAT (1X,A,I2,A,I2,A)
99997  FORMAT (1X,5F9.1)
    END PROGRAM g13aafe
