      SUBROUTINE FLEXI(Z,M1,FF,IPAR,PAR,IPA,IPAA)
C     NX      TOTAL NUMBER OF INDEPENDENT VARIABLES
C     NC      TOTAL NUMBER OF EQUALITY CONSTRAINTS
C     NIC     TOTAL NUMBER OF INEQUALITY CONSTRAINTS
C     SIZE    EDGE LENGHT OF THE INITIAL POLYHEDRON
C     CONVER  CONVERGENCE CRITERION FOR TERMINATION OF THE SEARCH
C     ALFA    THE REFLECTION COEFFICIENT
C     BETA    THE CONTRACTION COEFFICIENT
C     GAMA    THE EXPANSION COEFFICIENT
C     X(I)    THE ASSUMED VECTOR TO INITIATE THE SEARCH
C     FDIFER  THE TOLERANCE CRITERION FOR CONSTRAINT VIOLATION
C     ICONT   A COUNTER TO RECORD STAGE COMPUTATIONS
C     NCONT   A COUNTER TO PRINT INFORMATION EVERY (NX+1) STAGE
C     LOW     AN INDEX TO IDENTIFY INFORMATION RELATED TO THE LOWEST
C	      VALUE OF OBJ. FUNCTION IN MOST RECENT POLYHEDRON
C     LHIGH   AN INDEX TO IDENTIFY INFORMATION RELATED TO LARGEST VALUE
C	      OF OBJ. FUNCTION IN MOST RECENT POLYHEDRON
C     LSEC    AN INDEX TO IDENTIFY INFORMATION RELATED TO THE SECOND
C     LARGEST VALUE OF OBJ. FUNCTION IN MOST RECENT POLYHEDRON
      COMMON /U/NX,X(20)/V/STEP,K1,X1(29,20)/C/NC,NIC,R(100)
     1/D/K6,K7,K9/E/IN,K8,SEQL,SUM(29)/T/K2,K3,K4,INF,L5,
     2L6,L7,L8,L9,FDIFER,R1A,R2A,R3A,FOLD,SR(24),X2(24,20)
      COMMON /STATIS/IFAIL,ICONT,ITMIN,NF
      DIMENSION F(24)
      DIMENSION CMI(100)
      DIMENSION IPAR(30),PAR(30)
       DIMENSION Z(M1)
      NX=M1
      IFAIL=0
      CALL INWR32(Z,NX,FF,IPAR,PAR,IPA,IPAA)
      IF (IFAIL.EQ.10) RETURN
      IPRINT=IPAR(IPA+1)
      NFMAX=IPAR(IPA+2)
      NC=IPAR(IPA+3)
      NF=0
      NIC=IPAR(IPA+4)
      SIZE=PAR(IPAA+1)
      CONVER=PAR(IPAA+2)
      ALFA=1.
      DO 2005 I=1,NX
 2005 X(I) = Z(I)
      BETA=0.5
      GAMA=2.
       STEP=SIZE
      K1=NX+1
      K2=NX+2
      K3=NX+3
      K4=NX+4
      K5=NX+5
      K6=NC+NIC
      K7=NC+1
      K8=NC+NIC
      K9=K8+1
      N=NX-NC
      N1=N+1
      IF(N1.GE.3) GO TO 50
      N1=3
      N=2
   50 N2=N+2
      N3=N+3
      N4=N+4
      N5=N+5
      N6=N+6
      N7=N+7
      N8=N+8
      XN=FLOAT(N)
      XNX=FLOAT(NX)
      XN1=FLOAT(N1)
      R1A=0.5*(SQRT(5.)-1.)
      R2A=R1A*R1A
      R3A=R2A*R1A
      L5=NX+5
      L6=NX+6
      L7=NX+7
      L8=NX+8
      L9=NX+9
      ICONT=1
      NCONT=1
      FDIFER=2.*FLOAT(NC+1)*STEP
      FOLD=FDIFER
      IN=N1
      CALL SUMR
      SR(N1)=SQRT(SEQL)
      RK9=FI(X,NX)
      NF=NF+1
      FF=RK9
      INW1=1
      IF (IPRINT.GE.0) CALL SPAU32(INW1,ICONT,RK9,IPRINT)
      IF (SR(N1).LT.FDIFER) GO TO 2003
      INF=N1
      STEP=0.05*FDIFER
      CALL FEASBL
      IF (FOLD.GE.1.E-09) GO TO 341
      IFAIL=10
      ITMIN=0
      CALL INWR32(Z,NX,FF,IPAR,PAR,IPA,IPAA)
      RETURN
  341 INW1=2
      CALL SUMR
      RK9=FI(X,NX)
      NF=NF+1
      IF (IPRINT.GE.0) CALL SPAU32(INW1,ICONT,RK9,IPRINT)
 2003 CONTINUE
      FTER=RK9
      RMIN=RK9
      IF (K8.EQ.0) GO TO 3010
      DO 2040 I=1,K8
 2040 CMI(I)=R(I)
 3010 CONTINUE
      COMIN=SEQL
      DO 2070 I=1,NX
 2070 Z(I)=X(I)
C     COMPUTE CENTROID OF ALL VERTICES OF INITIAL POLYHEDRON
  237 STEP1=STEP*(SQRT(XNX+1.)+XNX-1.)/(XNX*SQRT(2.))
      STEP2=STEP*(SQRT(XNX+1.)-1.)/(XNX*SQRT(2.))
      ETA=(STEP1+(XNX-1.)*STEP2)/(XNX+1.)
      DO 4 J=1,NX
      X(J)=X(J)-ETA
    4 CONTINUE
      CALL START
      DO 9 I=1,N1
      DO 9 J=1,NX
      X2(I,J)=X1(I,J)
    9 CONTINUE
      DO 5 I=1,N1
      IN=I
      DO 6 J=1,NX
    6 X(J)=X2(I,J)
      CALL SUMR
      SR(I)=SQRT(SEQL)
      IF(SR(I).LT.FDIFER) GO TO 8
      CALL FEASBL
      IF(FOLD.LT.1.E-09) GO TO 80
    8 F(I)=FI(X,NX)
      NF=NF+1
    5 CONTINUE
 1000 STEP=0.05*FDIFER
      ICONT=ICONT+1
C  SELECT LARGEST VALUE OF OBJECTIVE FUNCTION FROM POLYHEDRON VERTICES
      FH=F(1)
      LHIGH=1
      DO 16 I=2,N1
      IF(F(I).LT.FH) GO TO 16
      FH=F(I)
      LHIGH=I
   16  CONTINUE
C   SELECT MINIMUM VALUE OF OBJECTIVE FUNCTION FROM POLYHEDRON VERTICES
   41 FL=F(1)
      LOW=1
      DO 17 I=2,N1
      IF(FL.LT.F(I)) GO TO 17
      FL=F(I)
      LOW=I
   17 CONTINUE
      DO 86 J=1,NX
   86 X(J)=X2(LOW,J)
      IN=LOW
      CALL SUMR
      SR(LOW)=SQRT(SEQL)
      IF(SR(LOW).LT.FDIFER) GO TO 87
      INF=LOW
      CALL FEASBL
      IF(FOLD.LT.1.E-09) GO TO 80
      F(LOW)=FI(X,NX)
      NF=NF+1
      GO TO 41
   87 CONTINUE
C     FIND CENTROID OF POINTS WITH I DIFFERENT THAN LHIGH
      DO 19 J=1,NX
      SUM2=0.
      DO 20 I=1,N1
   20 SUM2=SUM2+X2(I,J)
   19 X2(N2,J)=1./XN*(SUM2-X2(LHIGH,J))
      SUM2=0.
      DO 36 I=1,N1
      DO 36 J=1,NX
      SUM2=SUM2+(X2(I,J)-X2(N2,J))**2
   36 CONTINUE
      FDIFER=FLOAT(NC+1)/XN1*SQRT(SUM2)
      IF(FDIFER.LT.FOLD) GO TO 98
      FDIFER=FOLD
      GO TO 198
   98 FOLD=FDIFER
  198 CONTINUE
      FTER=F(LOW)
  137 NCONT=NCONT+1
      IF (NCONT.LT.4*N1) GO TO 337
      NCONT=1
      IF (ICONT.LT.1500) GO TO 337
      FOLD=0.5*FOLD
  337 INW1=3
      ITMIN=ICONT
      RK9=F(LOW)
      IF (COMIN.GT.SEQL.OR.RMIN.GE.RK9) GO TO 2020
      RK9=RMIN
      DO 2030 I=1,NX
 2030 X(I)=Z(I)
      IF (K8.EQ.0) GO TO 3020
      DO 2050 I=1,K8
 2050 R(I)=CMI(I)
 3020 CONTINUE
      ITMIN=0
 2020 CONTINUE
      IF (NF.LT.NFMAX) GO TO 2060
      IFAIL=2
      GO TO 81
 2060 CONTINUE
      IF (IPRINT.LE.0) GO TO 37
      IF (MOD(ICONT,IPRINT).EQ.0) CALL SPAU32(INW1,ICONT,RK9,IPRINT)
   37 IF (FDIFER.LT.CONVER) GO TO 81
C  SELECT SECOND LARGEST VALUE OF OBJECTIVE FUNCTION
      IF(LHIGH.EQ.1) GO TO 43
      FS=F(1)
      LSEC=1
      GO TO 44
   43 FS=F(2)
      LSEC=2
   44 DO 18 I=1,N1
       IF(LHIGH.EQ.I) GO TO 18
      IF(F(I).LT.FS) GO TO 18
      FS=F(I)
      LSEC=I
   18 CONTINUE
C     REFLECT HIGH POINT THROUGH CENTROID
      DO 61 J=1,NX
      X2(N3,J)=X2(N2,J)+ALFA*(X2(N2,J)-X2(LHIGH,J))
   61 X(J)=X2(N3,J)
      IN=N3
      CALL SUMR
      SR(N3)=SQRT(SEQL)
   89 IF(SR(N3).LT.FDIFER) GO TO 82
      INF=N3
      CALL FEASBL
      IF(FOLD.LT.1.E-09) GO TO 80
   82 F(N3)=FI(X,NX)
      NF=NF+1
      IF(F(N3).LT.F(LOW)) GO TO 84
      IF(F(N3).LT.F(LSEC)) GO TO 92
      GO TO 60
   92 DO 93 J=1,NX
   93 X2(LHIGH,J)=X2(N3,J)
      SR(LHIGH)=SR(N3)
      F(LHIGH)=F(N3)
      GO TO 1000
C   EXPAND VECTOR OF SEARCH ALONG DIRECTION THROUGH CENTROID AND
C     REFLECTED VECTOR
   84 DO 23 J=1,NX
      X2(N4,J)=X2(N3,J)+GAMA*(X2(N3,J)-X2(N2,J))
   23 X(J)=X2(N4,J)
      IN=N4
      CALL SUMR
      SR(N4)=SQRT(SEQL)
      IF(SR(N4).LT.FDIFER) GO TO 25
      INF=N4
      CALL FEASBL
      IF(FOLD.LT.1.E-09) GO TO 80
   25 F(N4)=FI(X,NX)
      NF=NF+1
      IF(F(LOW).LT.F(N4)) GO TO 92
      DO 26 J=1,NX
   26 X2(LHIGH,J)=X2(N4,J)
      F(LHIGH)=F(N4)
      SR(LHIGH)=SR(N4)
      GO TO 1000
   60 IF(F(N3).GT.F(LHIGH)) GO TO 64
      DO 65 J=1,NX
   65 X2(LHIGH,J)=X2(N3,J)
   64 DO 66 J=1,NX
      X2(N4,J)=BETA*X2(LHIGH,J)+(1.-BETA)*X2(N2,J)
   66 X(J)=X2(N4,J)
      IN=N4
      CALL SUMR
      SR(N4)=SQRT(SEQL)
      IF(SR(N4).LT.FDIFER) GO TO 67
      INF=N4
      CALL FEASBL
      IF(FOLD.LT.1.E-09) GO TO 80
   67 F(N4)=FI(X,NX)
      NF=NF+1
      IF(F(LHIGH).GT.F(N4)) GO TO 68
      DO 69 J=1,NX
      DO 69 I=1,N1
   69 X2(I,J)=0.5*(X2(I,J)+X2(LOW,J))
      DO 70 I=1,N1
      DO 71 J=1,NX
   71 X(J)=X2(I,J)
      IN=I
      CALL SUMR
      SR(I)=SQRT(SEQL)
      IF(SR(I).LT.FDIFER) GO TO 72
      INF=I
      CALL FEASBL
      IF(FOLD.LT.1.E-09) GO TO 80
   72 F(I)=FI(X,NX)
   70 NF=NF+1
      GO TO 1000
   68 DO 73 J=1,NX
   73 X2(LHIGH,J)=X2(N4,J)
      SR(LHIGH)=SR(N4)
      F(LHIGH)=F(N4)
      GO TO 1000
   80 IFAIL=1
      RK9=FI(X,NX)
      NF=NF+1
      IF (K8.NE.0) CALL CONSTR(X,NX,R,K8)
      ITMIN=ICONT
   81 CONTINUE
      DO 3000 I=1,NX
 3000 Z(I) = X(I)
      FF=RK9
      INW1=4
      IF (IPRINT.GE.0) CALL SPAU32(INW1,ICONT,RK9,IPRINT)
      RETURN
      END
      SUBROUTINE FEASBL
C*****SUBROUTINE FEASBL MINIMIZES THE SUM OF THE SQUARE VALUES OF THE
C     VIOLATED CONSTRAINTS. IT IS CALLED EVERY TIME THE COMBINED VALUE
C     OF THE VIOLATED CONSTRAINTS EXCEEDS THE THE VALUE OF THE TOLERANCE
C     CRITERION FOR THE CURRENT STAGE
      COMMON /U/NX,X(20)/V/STEP,K1,X1(29,20)/C/NC,NIC,R(100)
     1/D/K6,K7,K9/E/IN,K8,SEQL,SUM(29)/T/K2,K3,K4,INF,L5,
     2 L6,L7,L8,L9,FDIFER,R1A,R2A,R3A,FOLD,SR(24),X2(24,20)
     3/STATIS/IFAIL,IT,ITM,NF
      DIMENSION R1(100),R3(100),FLG(3),H(20)
      ALFA=1.
      BETA=0.5
      GAMA=2.
      XNX=FLOAT(NX)
      ICONT=0
      LCHEK=0
      ICHEK=0
   25 CALL START
      DO 3 I=1,K1
      DO 4 J=1,NX
    4 X(J)=X1(I,J)
      IN=I
      CALL SUMR
    3 CONTINUE
C  SELECT LARGEST VALUE OF SUM(I) IN SIMPLEX
   28 SUMH=SUM(1)
      INDEX=1
      DO 7 I=2,K1
      IF(SUM(I).LE.SUMH) GO TO 7
      SUMH=SUM(I)
      INDEX=I
    7 CONTINUE
C  SELECT MINIMUM VALUE OF SUM(I) IN SIMPLEX
      SUML=SUM(1)
      KOUNT=1
      DO 8 I=2,K1
      IF(SUML.LE.SUM(I)) GO TO 8
      SUML=SUM(I)
      KOUNT=I
    8 CONTINUE
C  FIND CENTROID OF POINTS WITH I DIFFERENT THAN INDEX
      DO 9 J=1,NX
      SUM2=0.
      DO 10 I=1,K1
   10 SUM2=SUM2+X1(I,J)
      X1(K2,J)=1./XNX*(SUM2-X1(INDEX,J))
C  FIND REFLECTION OF HIGH POINT THROUGH CENTROID
      X1(K3,J)=2.*X1(K2,J)-X1(INDEX,J)
    9 X(J)=X1(K3,J)
      IN=K3
      CALL SUMR
      IF(SUM(K3).LT.SUML) GO TO 11
C  SELECT SECOND LARGEST VALUE IN SIMPLEX
      IF(INDEX.EQ.1) GO TO 38
      SUMS=SUM(1)
      GO TO 39
   38 SUMS=SUM(2)
   39 DO 12 I=1,K1
      IF((INDEX-I).EQ.0) GO TO 12
      IF(SUM(I).LE.SUMS) GO TO 12
      SUMS=SUM(I)
   12 CONTINUE
      IF(SUM(K3).GE.SUMS) GO TO 13
      GO TO 14
C  FORM EXPANSION OF NFW MINIMUM IF REFLECTION HAS PRODUCED ONE MINIMUM
   11 DO 15 J=1,NX
      X1(K4,J)=X1(K2,J)+2.*(X1(K3,J)-X1(K2,J))
   15 X(J)=X1(K4,J)
      IN=K4
      CALL SUMR
      IF(SUM(K4).LT.SUML) GO TO 16
      GO TO 14
   13 IF(SUM(K3).GT.SUMH) GO TO 17
      DO 18 J=1,NX
   18 X1(INDEX,J)=X1(K3,J)
   17 DO 19 J=1,NX
      X1(K4,J)=0.5*X1(INDEX,J)+0.5*X1(K2,J)
   19 X(J)=X1(K4,J)
      IN=K4
      CALL SUMR
      IF(SUMH.GT.SUM(K4)) GO TO 6
C  REDUCE SIMPLEX BY HALF IF REFLECTION HAPPENS TO PRODUCE A LARGER VALL
C  UE THAH THE MAXIMUM
      DO 20 J=1,NX
      DO 20 I=1,K1
   20 X1(I,J)=0.5*(X1(I,J)+X1(KOUNT,J))
      DO 29 I=1,K1
      DO 30 J=1,NX
   30 X(J)=X1(I,J)
      IN=I
      CALL SUMR
   29 CONTINUE
    5 SUML=SUM(1)
      KOUNT=1
      DO 23 I=2,K1
      IF(SUML.LT.SUM(I)) GO TO 23
      SUML=SUM(I)
      KOUNT=I
   23 CONTINUE
      SR(INF)=SQRT(SUM(KOUNT))
      DO 27 J=1,NX
   27 X(J)=X1(KOUNT,J)
      GO TO 26
    6 DO 31 J=1,NX
   31 X1(INDEX,J)=X1(K4,J)
      SUM(INDEX)=SUM(K4)
      GO TO 5
   16  DO 21 J=1,NX
      X1(INDEX,J)=X1(K4,J)
   21 X(J)=X1(INDEX,J)
      SUM(INDEX)=SUM(K4)
      SR(INF)=SQRT(SUM(K4))
      GO TO 26
   14 DO 22 J=1,NX
      X1(INDEX,J)=X1(K3,J)
   22 X(J)=X1(INDEX,J)
      SUM(INDEX)=SUM(K3)
      SR(INF)=SQRT(SUM(K3))
   26 ICONT=ICONT+1
      DO 36 J=1,NX
   36 X2(INF,J)=X(J)
      IF(ICONT.LT.2*K1) GO TO 50
      ICONT=0
      DO 24 J=1,NX
   24 X(J)=X1(K2,J)
      IN=K2
      CALL SUMR
      DIFER=0.
      DO 57 I=1,K1
   57 DIFER=DIFER+(SUM(I)-SUM(K2))**2
      DIFER=1./(FLOAT(K7)*XNX)*SQRT(DIFER)
      IF (DIFER.LE.1.E-7 ) GO TO 51
      XABS=0.
      DO 110 J=1,NX
      D1=0.
      DO 111 I=1,K1
  111 D1=D1+ABS(X1(I,J)-X1(K2,J))
  110 XABS=XABS+D1/(ABS(X1(K2,J))+1.E-7)
      XABS=XABS/(XNX*FLOAT(K1))
      IF (XABS.GT.1.E-6) GO TO 50
C     IF FLEXIBLE SIMPLEX METHOD FAILED TO SATISFY THE CONSTRAINTS WITHI
C     N THE TOLERANCE CRITERION FOR THE CURRENT STAGE, THE SEARCH IS
C     PERTURBED FROM THE POSITION WHERE X VECTOR IS STUCK AND THEN
C     FEASBL IS REPEATED ONCE MORE FROM THE BEGINNING
   51 IN=K1
      STEP=20.*FDIFER
      CALL SUMR
      SR(INF)=SQRT(SEQL)
      DO 52 J=1,NX
   52 X1(K1,J)=X(J)
      DO 53 J=1,NX
      FACTOR=1.
      X(J)=X1(K1,J)+FACTOR*STEP
      X1(L9,J)=X(J)
      IN=L9
      CALL SUMR
      X(J)=X1(K1,J)-FACTOR*STEP
      X1(L5,J)=X(J)
      IN=L5
      CALL SUMR
   56 IF(SUM(L9).LT.SUM(K1)) GO TO 54
      IF(SUM(L5).LT.SUM(K1)) GO TO 55
      GO TO 97
   54 X1(L5,J)=X1(K1,J)
      SUM(L5)=SUM(K1)
      X1(K1,J)=X1(L9,J)
      SUM(K1)=SUM(L9)
      FACTOR=FACTOR+1.
      X(J)=X1(K1,J)+FACTOR*STEP
      IN=L9
      CALL SUMR
      GO TO 56
   55 X1(L9,J)=X1(K1,J)
      SUM(L9)=SUM(K1)
      X1(K1,J)=X1(L5,J)
      SUM(K1)=SUM(L5)
      FACTOR=FACTOR+1.
      X(J)=X1(K1,J)-FACTOR*STEP
      IN=L5
      CALL SUMR
      GO TO 56
C     ONE DIMENSIONAL SEARCH BY GOLDEN SECTION ALONG EACH COORDINATE
   97 H(J)=X1(L9,J)-X1(L5,J)
      IF (ABS(H(J))/AMAX1(ABS(X1(L9,J)),ABS(X1(L5,J))).LE.1.E-6)
     CGO TO 750
      X1(L6,J)=X1(L5,J)+H(J)*R1A
      X(J)=X1(L6,J)
      IN=L6
      CALL SUMR
      X1(L7,J)=X1(L5,J)+H(J)*R2A
      X(J)=X1(L7,J)
      IN=L7
      CALL SUMR
      IF(SUM(L6).GT.SUM(L7)) GO TO 68
      X1(L8,J)=X1(L5,J)+(1.-R3A)*H(J)
      X1(L5,J)=X1(L7,J)
      X(J)=X1(L8,J)
      IN=L8
      CALL SUMR
      IF(SUM(L8).GT.SUM(L6)) GO TO 76
      X1(L5,J)=X1(L6,J)
      SUM(L5)=SUM(L6)
      GO TO 75
   76 X1(L9,J)=X1(L8,J)
      SUM(L9)=SUM(L8)
      GO TO 75
   68 X1(L9,J)=X1(L6,J)
      X1(L8,J)=X1(L5,J)+R3A*H(J)
      X(J)=X1(L8,J)
      IN=L8
      CALL SUMR
      SUM(L9)=SUM(L6)
      IF(SUM(L7).GT.SUM(L8)) GO TO 71
      X1(L5,J)=X1(L8,J)
      SUM(L5)=SUM(L8)
      GO TO 75
   71 X1(L9,J)=X1(L7,J)
      SUM(L9)=SUM(L7)
   75 IF(ABS(X1(L9,J)-X1(L5,J)).GT.0.01*FDIFER) GO TO 97
  750 CONTINUE
      X1(K1,J)=X1(L7,J)
      X(J)=X1(L7,J)
      SUM(K1)=SUM(L5)
      SR(INF)=SQRT(SUM(K1))
      IF(SR(INF).LT.FDIFER) GO TO 760
   53 CONTINUE
      ICHEK=ICHEK+1
      STEP=FDIFER
      IF(ICHEK.LE.2) GO TO 25
      FOLD=1.E-10
      GO TO 46
  760 DO 761 J=1,NX
      X2(INF,J)=X1(K1,J)
  761 X(J)=X1(K1,J)
   50 IF(SR(INF).GT.FDIFER) GO TO 28
C  MODIFIED LAGRANGE INTERPOLATION FOR TIGHT INEQUALITIES
      IF(SR(INF).GT.0.)GO TO 35
      FINT=FI(X,NX)
      NF=NF+1
      DO 139 J=1,NX
  139 X(J)=X2(INF,J)
      CALL CONSTR(X,NX,R,K8)
      DO 40 J=K7,K8
   40 R1(J)=R(J)
      DO 41 J=1,NX
   41 X(J)=X1(KOUNT,J)
      CALL CONSTR(X,NX,R,K8)
      DO 42 J=K7,K8
   42 R3(J)=R(J)
      DO 43 J=1,NX
      H(J)=X1(KOUNT,J)-X2(INF,J)
   43 X(J)=X2(INF,J)+0.5*H(J)
      CALL CONSTR(X,NX,R,K8)
      FLG(1)=0.
      FLG(2)=0.
      FLG(3)=0.
      DO 44 J=K7,K8
      IF(R3(J).GE.0.) GO TO 44
      FLG(1)=FLG(1)+R1(J)*R1(J)
      FLG(2)=FLG(2)+R(J)*R(J)
      FLG(3)=FLG(3)+R3(J)*R3(J)
   44 CONTINUE
      SR(INF)=SQRT(FLG(1))
      IF(SR(INF).LT.FDIFER) GO TO 35
      ALFA1=FLG(1)-2.*FLG(2)+FLG(3)
      BETA1=3.*FLG(1)-4.*FLG(2)+FLG(3)
      RATIO=BETA1/(4.*ALFA1)
      DO 45 J=1,NX
   45 X(J)=X2(INF,J)+H(J)*RATIO
      IN=INF
      CALL SUMR
      SR(INF)=SQRT(SEQL)
      IF(SR(INF).LT.FDIFER) GO TO 465
      DO 49 I=1,20
      DO 48 J=1,NX
   48 X(J)=X(J)-0.05*H(J)
      CALL SUMR
      SR(INF)=SQRT(SEQL)
      IF(SR(INF).LT.FDIFER) GO TO 465
   49 CONTINUE
  465 RK9=FI(X,NX)
      NF=NF+1
      IF (FINT.GT.RK9) GO TO 46
      SR(INF)=0.
      GO TO 35
   46 DO 47 J=1,NX
   47 X2(INF,J)=X(J)
   35 CONTINUE
      DO 335 J=1,NX
  335 X(J)=X2(INF,J)
      RETURN
      END
      SUBROUTINE START
      COMMON /U/NX,X(20)/V/STEP,K1,X1(29,20)
      DIMENSION A(21,20)
      VN=FLOAT(NX)
      STEP1=STEP/(VN*SQRT(2.))*(SQRT(VN+1.)+VN-1.)
      STEP2=STEP/(VN*SQRT(2.))*(SQRT(VN+1.)-1.)
      DO 1 J=1,NX
    1 A(1,J)=0.
      DO 2 I=2,K1
      DO 4 J=1,NX
    4 A(I,J)=STEP2
      L=I-1
      A(I,L)=STEP1
    2 CONTINUE
      DO 3 I=1,K1
      DO 3 J=1,NX
    3 X1(I,J)=X(J)+A(I,J)
      RETURN
      END
      SUBROUTINE SUMR
C*****THIS SUBROUTINE COMPUTES THE SUM OF THE SQUARE VALUES OF THE
C     VIOLATED CONSTRAINTS IN ORDER TO BE COMPARED WITH THE TOLERANCE
C     CRITERION
      COMMON /U/NX,X(20)/C/NC,NIC,R(100)/D/K6,
     1K7,K9/E/IN,K8,SEQL,SUM(29)
      SUM(IN)=0.
      SEQL=0.
      IF (K8.EQ.0) GO TO 3
      CALL CONSTR(X,NX,R,K8)
      IF(NIC.EQ.0) GO TO 4
      DO 1 J=K7,K8
      IF(R(J).GE.0.) GO TO 1
      SEQL=SEQL+R(J)*R(J)
    1 CONTINUE
    4 IF(NC.EQ.0) GO TO 3
      DO 2 J=1,NC
    2 SEQL=SEQL+R(J)*R(J)
    3 SUM(IN)=SEQL
    5 RETURN
      END
      SUBROUTINE SPAU32(IN,ICONT,RK9,IPR)
      COMMON /C/NC,NIC,R(100)/D/K6,K7,K9/U/NX,X(20)
     1/STATIS/IFAIL,IT,ITM,NF
      NOUT=I1MACH(2)
      GO TO (10,50,60,70),IN
   10 WRITE (NOUT,320) RK9
   20 IF (K6.EQ.0) GO TO 30
      WRITE (NOUT,330)
      WRITE (NOUT,130) (R(J),J=1,K6)
   30 RETURN
   50 WRITE (NOUT,350)
      WRITE (NOUT,380)
      WRITE (NOUT,130) (X(J),J=1,NX)
      GO TO 10
   60 CONTINUE
      WRITE (NOUT,100)
      IF (ICONT.EQ.IPR) WRITE (NOUT,210)
      WRITE (NOUT,110) ICONT
      WRITE (NOUT,120) RK9
      WRITE (NOUT,140)
      WRITE (NOUT,130) (X(J),J=1,NX)
      GO TO 20
   70 WRITE (NOUT,170)
      WRITE (NOUT,180)
      WRITE (NOUT,150) RK9
      WRITE (NOUT,160)
      WRITE (NOUT,130) (X(I),I=1,NX)
      IF (NC.EQ.0.AND.NIC.EQ.0) GO TO 90
      WRITE (NOUT,330)
      WRITE (NOUT,130) (R(J),J=1,K6)
   90 WRITE (NOUT,390) NF,ICONT
      IF (IFAIL.EQ.0) WRITE (NOUT,400)
      IF (IFAIL.EQ.2) WRITE (NOUT,360)
      IF (IFAIL.EQ.1) WRITE (NOUT,410)
      WRITE (NOUT,370)
      WRITE (NOUT,170)
      RETURN
  100 FORMAT (/1X,34(2H -))
  110 FORMAT (2X,23HI T E R A T I O N  NR =,I6)
  120 FORMAT (/2X,19HFUNCTION VALUE F = ,E15.8)
  130 FORMAT(4(2X,E15.8))
  140 FORMAT (2X,13HCURRENT POINT)
  150 FORMAT (/2X,28HOPTIMAL FUNCTION VALUE FM = ,E15.8)
  160 FORMAT(2X,13HOPTIMAL POINT)
  170 FORMAT (/1X,34(2H *)/1X,34(2H *))
  180 FORMAT (/2X,13HR E S U L T S)
  210 FORMAT (1X,34(2H -))
  320 FORMAT (2X,19HFUNCTION VALUE F = ,E15.8)
  330 FORMAT (2X,11HCONSTRAINTS)
  350 FORMAT (/2X,27HSTARTING POINT - INFEASIBLE)
  360 FORMAT (/2X,52HIFAIL = 2. TERMINATION CRITERION: NUMBER OF FUNCTIO
     CN/2X,26HEVALUATIONS EXCEEDED LIMIT)
  370 FORMAT (/7X,16HFLEXI TERMINATED)
  380 FORMAT (2X,34HCALCULATED FEASIBLE STARTING POINT)
  390 FORMAT (/2X,34HNUMBER OF FUNCTION EVALUATIONS L =,I6/2X,
     C25HNUMBER OF ITERATIONS NR =,I6)
  400 FORMAT (/2X,66HIFAIL = 0. TERMINATION CRITERION:TOLERANCE CRITERIO
     CN LESS THAN EPS)
  410 FORMAT (/2X,58HIFAIL = 1. TERMINATION CRITERION: CONSTRAINTS ARE V
     CIOLATED/2X,29HMORE THAN TOLERANCE CRITERION)
      END
      SUBROUTINE INWR32(X,N,FM,IPAR,PAR,IPA,IPAA)
      COMMON /STATIS/IFAIL,ICT,ICTM,NF
      DIMENSION IPAR(30),PAR(30),X(N)
      MN=20
      MIP=30
      MAP=100
      K=4
      K1=2
      NOUT=I1MACH(2)
      IPRINT=IPAR(IPA+1)
      IF (IFAIL.EQ.10) GO TO 300
      IF (IPA.GE.0.AND.IPA+K.LE.MIP) GO TO 10
      WRITE (NOUT,520) K,MIP
      WRITE (NOUT,510) IPA
    5 IFAIL=10
      RETURN
   10 CONTINUE
      IF (IPRINT.LT.0) GO TO 110
      WRITE (NOUT,860)
      WRITE (NOUT,620)
      WRITE (NOUT,630) N
  110 IF (N.GT.0.AND.N.LE.MN) GO TO 20
      WRITE (NOUT,500) MN
      IF (IPRINT.LT.0) WRITE (NOUT,630) N
      GO TO 5
   20 CONTINUE
      M=IPAR(IPA+2)
      NC=IPAR(IPA+3)
      NIC=IPAR(IPA+4)
      IF (IPRINT.LT.0) GO TO 30
      WRITE (NOUT,640) IPRINT
      WRITE (NOUT,650) M
      WRITE (NOUT,870) NC
      WRITE (NOUT,890) NIC
   30 IF (M.GE.0) GO TO 40
      WRITE (NOUT,525)
      IF (IPRINT.LT.0) WRITE (NOUT,650) M
      GO TO 5
   40 IF (NC.GE.0) GO TO 50
      WRITE (NOUT,900)
      IF (IPRINT.LT.0) WRITE (NOUT,870) NC
      GO TO 5
   50 IF (NIC.GE.0) GO TO 70
      WRITE (NOUT,910)
      IF (IPRINT.LT.0) WRITE (NOUT,890) NIC
      GO TO 5
   70 IF (NC+NIC.LE.MAP) GO TO 120
      WRITE (NOUT,930) MAP
      IF (IPRINT.GE.0) GO TO 5
      WRITE (NOUT,870) NC
      WRITE (NOUT,890) NIC
      GO TO 5
  120 CONTINUE
      IF (IPAA.GE.0.AND.IPAA+K1.LE.MIP) GO TO 240
      WRITE (NOUT,710) K1,MIP
      WRITE (NOUT,700) IPAA
      GO TO 5
  240 CONTINUE
      IF (IPRINT.LT.0) GO TO 250
      DELTA=PAR(IPAA+1)
      EPS=PAR(IPAA+2)
      WRITE (NOUT,940) DELTA
      WRITE (NOUT,950) EPS
  250 CONTINUE
  255 IF (IPRINT.LT.0) GO TO 260
  256 CONTINUE
      WRITE (NOUT,820)
      WRITE (NOUT,580) (X(I),I=1,N)
  260 CONTINUE
      RETURN
  300 WRITE (NOUT,540)
      IF (IPRINT.LT.0) GO TO 256
      RETURN
  500 FORMAT (/2X,61H**E R R O R  I N  F L E X I** N LESS THAN 1 OR N GR
     CEATER THAN,I3)
  510 FORMAT (/2X,26HNUMBER OF PARAMETERS IPA =,I6)
  520 FORMAT (/2X,45H**E R R O R  I N  F L E X I** IPA LESS THAN 0/2X,
     C7HOR IPA+,I2,13H GREATER THAN,I3)
  525 FORMAT (/2X,43H**E R R O R  I N  F L E X I** M LESS THAN 1/)
  540 FORMAT (/2X,51H**E R R O R  I N  F L E X I** IMPOSSIBLE TO SATISFY
     C/2X,45HVIOLATED CONSTRAINTS FROM THIS STARTING POINT)
  580 FORMAT (4(2X,E15.8))
  620 FORMAT (/2X,22HI N I T I A L  D A T A)
  630 FORMAT (/2X,19HNUMBER OF VARIABLES,22X,3HN =,I6)
  640 FORMAT (/2X,18HPRINTING PARAMETER,21X,5HIPR =,I6)
  650 FORMAT (2X,44HMAXIMUM NUMBER OF FUNCTION EVALUATIONS   M =,I6)
  700 FORMAT (/2X,27HNUMBER OF PARAMETERS IPAA =,I3)
  710 FORMAT (/2X,46H**E R R O R  I N  F L E X I** IPAA LESS THAN 0/2X,
     C8HOR IPAA+,I2,13H GREATER THAN,I3)
  820 FORMAT (/2X,14HSTARTING POINT)
  860 FORMAT (////12X,9HF L E X I)
  870 FORMAT (2X,30HNUMBER OF EQUALITY CONSTRAINTS,10X,4HNC =,I6)
  890 FORMAT(2X,32HNUMBER OF INEQUALITY CONSTRAINTS,7X,5HNIC =,I6)
  900 FORMAT (/2X,44H**E R R O R  I N  F L E X I** NC LESS THAN 0/)
  910 FORMAT (/2X,45H**E R R O R  I N  F L E X I** NIC LESS THAN 0/)
  930 FORMAT (/2X,55H**E R R O R  I N  F L E X I** NUMBER OF ALL CONSTRA
     CINTS/2X,12HGREATER THAN,I4/)
  940 FORMAT (/2X,34HSIZE OF INITIAL POLYHEDRON DELTA =,E15.8)
  950 FORMAT (2X,19HDESIRED CONVERGENCE,10X,5HEPS =,E15.8)
      END
