! E04NLF Example Program Text ! Mark 23 Release. NAG Copyright 2011. MODULE e04nlfe_mod ! E04NLF Example Program Module: ! Parameters and User-defined Routines ! .. Use Statements .. USE nag_library, ONLY : nag_wp ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: iset = 1, nin = 5, ninopt = 7, & nout = 6 CONTAINS SUBROUTINE qphx(nstate,ncolh,x,hx) ! Routine to compute H*x. (In this version of QPHX, the Hessian ! matrix H is not referenced explicitly.) ! .. Implicit None Statement .. IMPLICIT NONE ! .. Scalar Arguments .. INTEGER, INTENT (IN) :: ncolh, nstate ! .. Array Arguments .. REAL (KIND=nag_wp), INTENT (OUT) :: hx(ncolh) REAL (KIND=nag_wp), INTENT (IN) :: x(ncolh) ! .. Executable Statements .. IF (nstate==1) THEN ! First entry. WRITE (nout,*) WRITE (nout,99999) ncolh FLUSH (nout) END IF hx(1) = 2.0E0_nag_wp*x(1) hx(2) = 2.0E0_nag_wp*x(2) hx(3) = 2.0E0_nag_wp*(x(3)+x(4)) hx(4) = hx(3) hx(5) = 2.0E0_nag_wp*x(5) hx(6) = 2.0E0_nag_wp*(x(6)+x(7)) hx(7) = hx(6) IF (nstate>=2) THEN ! Final entry. WRITE (nout,*) WRITE (nout,99998) FLUSH (nout) END IF RETURN 99999 FORMAT (1X,'This is the E04NLF example. NCOLH =',I4,'.') 99998 FORMAT (1X,'Finished the E04NLF example.') END SUBROUTINE qphx END MODULE e04nlfe_mod PROGRAM e04nlfe ! E04NLF Example Main Program ! .. Use Statements .. USE nag_library, ONLY : e04nkf, e04nlf, e04nmf, nag_wp, x04abf, x04acf USE e04nlfe_mod, ONLY : iset, nin, ninopt, nout, qphx ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. CHARACTER (*), PARAMETER :: fname = 'e04nlfe.opt' ! .. Local Scalars .. REAL (KIND=nag_wp) :: obj, sinf INTEGER :: i, icol, ifail, inform, iobj, & jcol, leniz, lenz, m, miniz, & minz, mode, n, ncolh, ninf, & nname, nnz, ns, outchn CHARACTER (1) :: start ! .. Local Arrays .. REAL (KIND=nag_wp), ALLOCATABLE :: a(:), bl(:), bu(:), clamda(:), & xs(:), z(:) INTEGER, ALLOCATABLE :: ha(:), istate(:), iz(:), ka(:) CHARACTER (8), ALLOCATABLE :: crname(:) CHARACTER (8) :: names(5) ! .. Executable Statements .. WRITE (nout,99997) 'E04NLF Example Program Results' FLUSH (nout) ! Skip heading in data file. READ (nin,*) READ (nin,*) n, m READ (nin,*) nnz, iobj, ncolh, start, nname ALLOCATE (ha(nnz),ka(n+1),istate(n+m),a(nnz),bl(n+m),bu(n+m),xs(n+m), & clamda(n+m),crname(nname)) READ (nin,*) names(1:5) READ (nin,*) crname(1:nname) ! Read the matrix A from data file. Set up KA. jcol = 1 ka(jcol) = 1 DO i = 1, nnz ! Element ( HA( I ), ICOL ) is stored in A( I ). READ (nin,*) a(i), ha(i), icol IF (icoljcol+1) THEN ! Index in A of the start of the ICOL-th column equals I, ! but columns JCOL+1,JCOL+2,...,ICOL-1 are empty. Set the ! corresponding elements of KA to I. ka((jcol+1):icol) = i jcol = icol END IF END DO ka(n+1) = nnz + 1 ! Columns N,N-1,...,ICOL+1 are empty. Set the corresponding ! elements of KA accordingly. DO i = n, icol + 1, -1 ka(i) = ka(i+1) END DO READ (nin,*) bl(1:(n+m)) READ (nin,*) bu(1:(n+m)) IF (start=='C') THEN READ (nin,*) istate(1:n) ELSE IF (start=='W') THEN READ (nin,*) istate(1:(n+m)) END IF READ (nin,*) xs(1:n) ! Set the unit number for advisory messages to OUTCHN. outchn = nout CALL x04abf(iset,outchn) ! Set three options using E04NMF. CALL e04nmf(' Check Frequency = 10 ') CALL e04nmf(' Crash Tolerance = 0.05 ') CALL e04nmf(' Infinite Bound Size = 1.0E+25 ') ! 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 e04nlf(ninopt,inform) IF (inform/=0) THEN WRITE (nout,99999) 'E04NLF terminated with INFORM = ', inform FLUSH (nout) GO TO 20 END IF ! Solve the QP problem. ! First call is a workspace query leniz = 1 lenz = 1 ALLOCATE (iz(leniz),z(lenz)) ifail = 1 CALL e04nkf(n,m,nnz,iobj,ncolh,qphx,a,ha,ka,bl,bu,start,names,nname, & crname,ns,xs,istate,miniz,minz,ninf,sinf,obj,clamda,iz,leniz,z,lenz, & ifail) IF (ifail/=0 .AND. ifail/=12 .AND. ifail/=13) THEN WRITE (nout,99999) 'Query call to E04NKF failed with IFAIL =', ifail GO TO 20 END IF DEALLOCATE (iz,z) lenz = minz leniz = miniz ALLOCATE (iz(leniz),z(lenz)) ifail = 0 CALL e04nkf(n,m,nnz,iobj,ncolh,qphx,a,ha,ka,bl,bu,start,names,nname, & crname,ns,xs,istate,miniz,minz,ninf,sinf,obj,clamda,iz,leniz,z,lenz, & ifail) 20 CONTINUE 99999 FORMAT (1X,A,I5) 99998 FORMAT (1X,A,I5,A,I5,A,A) 99997 FORMAT (1X,A) END PROGRAM e04nlfe