*     E04NFA Example Program Text
*     Mark 20 Release. NAG Copyright 2001.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          NMAX, NCMAX
      PARAMETER        (NMAX=10,NCMAX=10)
      INTEGER          LDA, LDH
      PARAMETER        (LDA=NCMAX,LDH=NMAX)
      INTEGER          LIWORK, LWORK
      PARAMETER        (LIWORK=1000,LWORK=10000)
      INTEGER          LCWSAV, LIWSAV, LLWSAV, LRWSAV
      PARAMETER        (LCWSAV=1,LIWSAV=610,LLWSAV=120,LRWSAV=475)
*     .. Local Scalars ..
      DOUBLE PRECISION OBJ
      INTEGER          I, IFAIL, ITER, J, N, NCLIN
*     .. Local Arrays ..
      DOUBLE PRECISION A(LDA,NMAX), AX(NCMAX), BL(NMAX+NCMAX),
     +                 BU(NMAX+NCMAX), CLAMDA(NMAX+NCMAX), CVEC(NMAX),
     +                 H(LDH,NMAX), RUSER(1), RWSAV(LRWSAV),
     +                 WORK(LWORK), X(NMAX)
      INTEGER          ISTATE(NMAX+NCMAX), IWORK(LIWORK), IWSAV(LIWSAV)
      LOGICAL          LWSAV(LLWSAV)
      CHARACTER*80     CWSAV(LCWSAV)
*     .. External Subroutines ..
      EXTERNAL         E04NFA, E04WBF, E54NFU
*     .. Executable Statements ..
      WRITE (NOUT,*) 'E04NFA Example Program Results'
*     Skip heading in data file
      READ (NIN,*)
      READ (NIN,*) N, NCLIN
      IF (N.LE.NMAX .AND. NCLIN.LE.NCMAX) THEN
*
*        Read CVEC, A, BL, BU, X and H from data file
*
         READ (NIN,*) (CVEC(I),I=1,N)
         READ (NIN,*) ((A(I,J),J=1,N),I=1,NCLIN)
         READ (NIN,*) (BL(I),I=1,N+NCLIN)
         READ (NIN,*) (BU(I),I=1,N+NCLIN)
         READ (NIN,*) (X(I),I=1,N)
         READ (NIN,*) ((H(I,J),J=1,N),I=1,N)
*
*        Initialise E04NFA and check for error exits
*
         IFAIL = 1
         CALL E04WBF('E04NFA',CWSAV,LCWSAV,LWSAV,LLWSAV,IWSAV,LIWSAV,
     +               RWSAV,LRWSAV,IFAIL)
         IF (IFAIL.NE.0) THEN
            WRITE (NOUT,99999) IFAIL
         ELSE
*
*           Solve the problem
*
            IFAIL = 1
*
            CALL E04NFA(N,NCLIN,A,LDA,BL,BU,CVEC,H,LDH,E54NFU,ISTATE,X,
     +                  ITER,OBJ,AX,CLAMDA,IWORK,LIWORK,WORK,LWORK,
     +                  IWSAV,RUSER,LWSAV,IWSAV,RWSAV,IFAIL)
*
*           Check for error exits
*
            WRITE (NOUT,*)
            IF (IFAIL.EQ.6) THEN
               WRITE (NOUT,99998)
            ELSE
               WRITE (NOUT,99997) IFAIL
               WRITE (NOUT,*)
               WRITE (NOUT,99996)
               WRITE (NOUT,*)
               DO 20 I = 1, N
                  WRITE (NOUT,99995) I, ISTATE(I), X(I), CLAMDA(I)
   20          CONTINUE
               IF (NCLIN.GT.0) THEN
                  WRITE (NOUT,*)
                  WRITE (NOUT,*)
                  WRITE (NOUT,99994)
                  WRITE (NOUT,*)
                  DO 40 I = N + 1, N + NCLIN
                     J = I - N
                     WRITE (NOUT,99993) J, ISTATE(I), AX(J), CLAMDA(I)
   40             CONTINUE
               END IF
               WRITE (NOUT,*)
               WRITE (NOUT,*)
               WRITE (NOUT,99992) OBJ
               WRITE (NOUT,*)
               WRITE (NOUT,*)
               WRITE (NOUT,99991) ITER
            END IF
         END IF
      END IF
      STOP
*
99999 FORMAT (1X,'E04WBF returned with IFAIL = ',I4)
99998 FORMAT (1X,'An input parameter is invalid')
99997 FORMAT (1X,'E04NFA returned with IFAIL = ',I4)
99996 FORMAT (1X,'Varbl',2X,'Istate',3X,'Value',9X,'Lagr Mult')
99995 FORMAT (1X,'V',2(1X,I3),4X,1P,G14.6,2X,1P,G12.4)
99994 FORMAT (1X,'L Con',2X,'Istate',3X,'Value',9X,'Lagr Mult')
99993 FORMAT (1X,'L',2(1X,I3),4X,1P,G14.6,2X,1P,G12.4)
99992 FORMAT (1X,'Final objective value = ',G15.7)
99991 FORMAT (1X,'Exit from problem after',1X,I6,1X,'iterations.')
      END
