NAG Library Manual, Mark 27.3
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program e04ndfe

!     E04NDF Example Program Text

!     Mark 27.3 Release. NAG Copyright 2021.

!     .. Use Statements ..
      Use nag_library, Only: e04ncf, e04ndf, e04nef, nag_wp, x04abf, x04acf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: iset = 1, nin = 5, ninopt = 7,       &
                                          nout = 6
      Character (*), Parameter         :: fname = 'e04ndfe.opt'
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: obj
      Integer                          :: i, ifail, inform, iter, lda, ldc,    &
                                          liwork, lwork, m, mode, n, nclin,    &
                                          outchn, sdc
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:,:), b(:), bl(:), bu(:), c(:,:),  &
                                          clamda(:), cvec(:), work(:), x(:)
      Integer, Allocatable             :: istate(:), iwork(:), kx(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: max
!     .. Executable Statements ..
      Write (nout,99998) 'E04NDF Example Program Results'
      Flush (nout)

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

      Read (nin,*) m, n, nclin
      liwork = n
      ldc = max(1,nclin)
      lda = max(1,m)

      If (nclin>0) Then
        sdc = n
      Else
        sdc = 1
      End If

!     This particular example problem is of type QP2, so we allocate
!     A(LDA,N), CVEC(N), B(1) and define LWORK as below

      If (nclin>0) Then
        lwork = 2*n**2 + 10*n + 6*nclin
      Else
        lwork = 10*n
      End If

      Allocate (istate(n+nclin),kx(n),iwork(liwork),c(ldc,sdc),bl(n+nclin),    &
        bu(n+nclin),cvec(n),x(n),a(lda,n),b(1),clamda(n+nclin),work(lwork))

      Read (nin,*) cvec(1:n)
      Read (nin,*)(a(i,1:n),i=1,m)
      Read (nin,*)(c(i,1:sdc),i=1,nclin)
      Read (nin,*) bl(1:(n+nclin))
      Read (nin,*)
      Read (nin,*) bu(1:(n+nclin))
      Read (nin,*)
      Read (nin,*) x(1:n)

!     Set the unit number for advisory messages to OUTCHN

      outchn = nout
      Call x04abf(iset,outchn)

!     Set one option using E04NEF

      Call e04nef(' Problem Type = QP2 ')

!     Open the options file for reading

      mode = 0

      ifail = 0
      Call x04acf(ninopt,fname,mode,ifail)

!     Read the options file for the remaining options

      Call e04ndf(ninopt,inform)

      If (inform/=0) Then
        Write (nout,99999) ' ** E04NDF terminated with INFORM =', inform
        Flush (nout)
        Go To 100
      End If

!     Solve the problem

      ifail = 0
      Call e04ncf(m,n,nclin,ldc,lda,c,bl,bu,cvec,istate,kx,x,a,b,iter,obj,     &
        clamda,iwork,liwork,work,lwork,ifail)

100   Continue

99999 Format (1X,A,I5)
99998 Format (1X,A)
    End Program e04ndfe