Program NonOptEx1
    
INCLUDE 'link_fnl_static.h'
!DEC$ OBJCOMMENT LIB:'libiomp5md.lib'     
USE NNLPF_INT
USE WRRRN_INT
 
IMPLICIT   NONE
INTEGER    IBTYPE, M, ME
INTEGER    N,IPRINT,MAXITN
DOUBLE PRECISION FVALUE, X(24), XGUESS(24), XLB(24), XUB(24), XSCALE(24)
DOUBLE PRECISION EPSDIF,TAU0,DEL0 
EXTERNAL   FCN
PARAMETER  (IBTYPE=0, M=10, ME=10)
PARAMETER  (IPRINT =1, MAXITN=5000, N=24) 
PARAMETER  (TAU0=1.0, DEL0=1.0, EPSDIF = 1D-10)
!                                 
DATA XLB /24*0.0/
DATA XUB /24*50.0/                              
DATA XSCALE /24*1.0/
DATA XGUESS /24*3.0/
!DATA XGUESS /6, 2, 1, 1, 1, 3, 2, 21, 20, 1, 1, 1, 24, 1, 1, 1, 3, 2, 13, 5, 5, 12, 5, 5/
!
CALL NNLPF (FCN, M, ME, IBTYPE, XLB, XUB, X,N,XGUESS,XSCALE,IPRINT)
!CALL NNLPF (FCN, M, ME, IBTYPE, XLB, XUB, X,N,XGUESS,XSCALE,IPRINT,MAXITN,EPSDIF,TAU0,DEL0)
!
CALL WRRRN ('The solution is', X)

END program NonOptEx1
 
 
 
SUBROUTINE FCN (X, IACT, RESULT, IERR)
!
IMPLICIT NONE
INTEGER    IACT
INTEGER    i,j,k,mm,nn
LOGICAL    IERR
DOUBLE PRECISION X(*), RESULT
DOUBLE PRECISION , DIMENSION(24) :: c,d,r
DOUBLE PRECISION , DIMENSION(6) ::  a
DOUBLE PRECISION , DIMENSION(4) ::  b
!
DATA c(1:24) /300,270,460,800,740,600,540,380,300,490,380,760,430,250,390,600,210,830,470,680,360,290,400,310/
DATA d(1:24) / -7, -4, -6, -8,-12, -9,-14, -7,-13,-12, -8, -4, -7, -9,-16, -8, -4,-10,-21,-13,-17, -9, -8,-4/
DATA a (1:6) / 8 ,  24,  20,  24,  16,  12/
DATA b (1:4) /29 ,  41,  13,  21/
!  

SELECT CASE (IACT)
CASE(0)
DO i=1,24
   r(i) = c(i)*x(i) + d(i)*x(i)**2         
ENDDO     
RESULT = SUM(r)
     
CASE(1)   
     RESULT = x(1)  + x(2)  + x(3)  + x(4)  - a(1)
CASE(2)
     RESULT = x(5)  + x(6)  + x(7)  + x(8)  - a(2)
CASE(3)
     RESULT = x(9)  + x(10) + x(11) + x(12) - a(3)
CASE(4)
     RESULT = x(13) + x(14) + x(15) + x(16) - a(4)
CASE(5)
     RESULT = x(17) + x(18) + x(19) + x(20) - a(5)
CASE(6)
     RESULT = x(21) + x(22) + x(23) + x(24) - a(6)                    
CASE(7)
     RESULT = x(1)  + x(5)  + x(9)  + x(13) + x(17) + x(21) - b(1)
CASE(8)
     RESULT = x(2)  + x(6)  + x(10) + x(14) + x(18) + x(22) - b(2)
CASE(9) 
     RESULT = x(3)  + x(7)  + x(11) + x(15) + x(19) + x(23) - b(3)
CASE(10)
     RESULT = x(4)  + x(8)  + x(12) + x(16) + x(20) + x(24) - b(4)                      
END SELECT

RETURN
END       


