    PROGRAM g02qffe

!      G02QFF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g02qff, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: df
       INTEGER                         :: i, ifail, j, l, m, n, ntau
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: b(:,:), bl(:,:), bu(:,:), tau(:),    &
                                          x(:,:), y(:)
       INTEGER, ALLOCATABLE            :: info(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G02QFF Example Program Results'
       WRITE (nout,*)

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

!      Read in the problem size
       READ (nin,*) n, m, ntau

!      Read in the data
       ALLOCATE (y(n),tau(ntau),x(n,m))
       READ (nin,*) (x(i,1:m),y(i),i=1,n)

!      Read in the quantiles required
       READ (nin,*) tau(1:ntau)

!      Allocate memory for output arrays
       ALLOCATE (b(m,ntau),info(ntau),bl(m,ntau),bu(m,ntau))

!      Call the model fitting routine
       ifail = -1
       CALL g02qff(n,m,x,y,ntau,tau,df,b,bl,bu,info,ifail)
       IF (ifail/=0) THEN
          IF (ifail==111) THEN
             WRITE (nout,*) 'Additional error information (INFO): ', &
                info(1:ntau)
          ELSE
             GO TO 20
          END IF
       END IF

!      Display the parameter estimates
       DO l = 1, ntau
          WRITE (nout,99999) 'Quantile: ', tau(l)
          WRITE (nout,*)
          WRITE (nout,*) '        Lower   Parameter   Upper'
          WRITE (nout,*) '        Limit   Estimate    Limit'
          DO j = 1, m
             WRITE (nout,99998) j, bl(j,l), b(j,l), bu(j,l)
          END DO
          WRITE (nout,*)
          WRITE (nout,*)
       END DO

20     CONTINUE

99999  FORMAT (1X,A,F6.3)
99998  FORMAT (1X,I3,3(3X,F7.3))
    END PROGRAM g02qffe
