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

NAG FL Interface Introduction
Example description
!   E04JYF Example Program Text
!   Mark 27.2 Release. NAG Copyright 2021.
    Module e04jyfe_mod

!     E04JYF Example Program Module:
!            Parameters and User-defined Routines

!     .. Use Statements ..
      Use nag_library, Only: nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Accessibility Statements ..
      Private
      Public                           :: funct1
!     .. Parameters ..
      Integer, Parameter, Public       :: n = 4, nout = 6
      Integer, Parameter, Public       :: liw = n + 2
      Integer, Parameter, Public       :: lw = n*(n-1)/2 + 12*n
    Contains
      Subroutine funct1(n,xc,fc,iuser,ruser)
!       Routine to evaluate objective function.

!       .. Scalar Arguments ..
        Real (Kind=nag_wp), Intent (Out) :: fc
        Integer, Intent (In)           :: n
!       .. Array Arguments ..
        Real (Kind=nag_wp), Intent (Inout) :: ruser(*)
        Real (Kind=nag_wp), Intent (In) :: xc(n)
        Integer, Intent (Inout)        :: iuser(*)
!       .. Local Scalars ..
        Real (Kind=nag_wp)             :: x1, x2, x3, x4
!       .. Executable Statements ..
        x1 = xc(1)
        x2 = xc(2)
        x3 = xc(3)
        x4 = xc(4)
        fc = (x1+10.0_nag_wp*x2)**2 + 5.0_nag_wp*(x3-x4)**2 +                  &
          (x2-2.0_nag_wp*x3)**4 + 10.0_nag_wp*(x1-x4)**4

        Return

      End Subroutine funct1
    End Module e04jyfe_mod
    Program e04jyfe

!     E04JYF Example Main Program

!     .. Use Statements ..
      Use e04jyfe_mod, Only: funct1, liw, lw, n, nout
      Use nag_library, Only: e04jyf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: f
      Integer                          :: ibound, ifail
!     .. Local Arrays ..
      Real (Kind=nag_wp)               :: bl(n), bu(n), ruser(n), w(lw), x(n)
      Integer                          :: iuser(n), iw(6)
!     .. Executable Statements ..
      Write (nout,*) 'E04JYF Example Program Results'
      Flush (nout)

      x(1:n) = (/3.0_nag_wp,-1.0_nag_wp,0.0_nag_wp,1.0_nag_wp/)
      ibound = 0

!     X(3) is unconstrained, so we set BL(3) to a large negative
!     number and BU(3) to a large positive number.

      bl(1:n) = (/1.0_nag_wp,-2.0_nag_wp,-1.0E6_nag_wp,1.0_nag_wp/)
      bu(1:n) = (/3.0_nag_wp,0.0_nag_wp,1.0E6_nag_wp,3.0_nag_wp/)

      ifail = -1
      Call e04jyf(n,ibound,funct1,bl,bu,x,f,iw,liw,w,lw,iuser,ruser,ifail)

      Select Case (ifail)
      Case (0,2:)
        Write (nout,*)
        Write (nout,99999) 'Function value on exit is ', f
        Write (nout,99998) 'at the point', x(1:n)
      End Select

99999 Format (1X,A,F8.4)
99998 Format (1X,A,4F9.4)
    End Program e04jyfe