Example description
    Program g13adfe

!     G13ADF Example Program Text

!     Mark 27.0 Release. NAG Copyright 2019.

!     .. Use Statements ..
      Use nag_library, Only: g13adf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: rv, xv
      Integer                          :: ifail, nk, npar, nwa, pp, qp
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: par(:), r(:), wa(:)
      Integer                          :: isf(4), mr(7)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: max
!     .. Executable Statements ..
      Write (nout,*) 'G13ADF Example Program Results'
      Write (nout,*)

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

!     Read in problem size and variance
      Read (nin,*) nk
      Read (nin,*) xv

      Allocate (r(nk))

!     Read in data
      Read (nin,*) r(1:nk)

!     Read in the orders
      Read (nin,*) mr(1:7)

!     Calculate NPAR
      npar = mr(1) + mr(3) + mr(4) + mr(6)

      pp = max(mr(1),mr(4))
      qp = max(mr(3),mr(6))
      nwa = max(pp**2+pp,4*(qp+1))
      Allocate (par(npar),wa(nwa))

!     Calculate preliminary estimates
      ifail = -1
      Call g13adf(mr,r,nk,xv,npar,wa,nwa,par,rv,isf,ifail)
      If (ifail/=0) Then
        If (ifail<7) Then
          Go To 100
        End If
      End If

!     Display results
      Write (nout,99999) 'Parameter estimation success/failure indicator',     &
        isf(1:4)
      Write (nout,*)
      Write (nout,99998) 'ARIMA model parameter values ', par(1:npar)
      Write (nout,*)
      Write (nout,99998) 'Residual variance', rv

100   Continue

99999 Format (1X,A,4I4)
99998 Format (1X,A,5F10.5)
    End Program g13adfe