    PROGRAM g01asfe

!      G01ASF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g01asf, nag_wp, x04abf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: iset = 1, nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: ifail, j, ldplot, ldx, m, nstepx,    &
                                          nstepy, outchn
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: work(:), x(:,:)
       INTEGER, ALLOCATABLE            :: iwork(:), n(:)
       CHARACTER (1), ALLOCATABLE      :: plot(:,:)
!      .. Intrinsic Functions ..
       INTRINSIC                          maxval
!      .. Executable Statements ..
       WRITE (nout,*) 'G01ASF Example Program Results'
       WRITE (nout,*)
       FLUSH (nout)

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

!      Read in the problem size
       READ (nin,*) m, nstepx, nstepy

       ldplot = nstepy
       ALLOCATE (n(m))

!      Read in number of observations in each batch
       READ (nin,*) n(1:m)

       ldx = maxval(n(1:m))
       ALLOCATE (iwork(ldx),x(ldx,m),work(5*m),plot(ldplot,nstepx))

!      Read in data
       READ (nin,*) (x(1:n(j),j),j=1,m)

!      Set advisory channel
       outchn = nout
       CALL x04abf(iset,outchn)

!      Produce the plot
       ifail = 0
       CALL g01asf('Print',m,n,x,ldx,nstepx,nstepy,plot,ldplot,work,iwork, &
          ifail)

    END PROGRAM g01asfe
