    PROGRAM g13ahfe

!      G13AHF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g13ahf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: c, rms
       INTEGER                         :: ifail, nfv, npar, nst, nwa
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: fsd(:), fva(:), par(:), st(:), wa(:)
       INTEGER                         :: mr(7)
!      .. Intrinsic Functions ..
       INTRINSIC                          max
!      .. Executable Statements ..
       WRITE (nout,*) 'G13AHF Example Program Results'
       WRITE (nout,*)

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

!      Read in problem size etc
       READ (nin,*) nfv, c

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

!      Calculate NPAR and various array lengths
       npar = mr(1) + mr(3) + mr(4) + mr(6)
       nst = mr(4)*mr(7) + mr(5)*mr(7) + mr(2) + mr(3) + &
          max(mr(1),mr(6)*mr(7))
       nwa = 4*npar + 3*nst

       ALLOCATE (fsd(nfv),fva(nfv),par(npar),st(nst),wa(nwa))

!      Read in parameter estimates
       READ (nin,*) par(1:npar)

!      Read in state set from G13AEF, G13AFF or G13AGF
       READ (nin,*) st(1:nst)

!      Read in residual variance
       READ (nin,*) rms

!      Produce forecasts
       ifail = 0
       CALL g13ahf(st,nst,mr,par,npar,c,rms,nfv,fva,fsd,wa,nwa,ifail)

       WRITE (nout,99998) 'The required', nfv, &
          ' forecast values are as follows'
       WRITE (nout,99999) fva(1:nfv)
       WRITE (nout,*)
       WRITE (nout,*) &
          'The standard deviations corresponding to the forecasts are'
       WRITE (nout,99999) fsd(1:nfv)

99999  FORMAT (1X,8F8.4)
99998  FORMAT (1X,A,I3,A)
    END PROGRAM g13ahfe
