C**********************************************************
C
C     Subroutine for one dimensional searching.
C     Fibonacci searching technique.
C     =========
C**********************************************************
C     Neculai Andrei, 
C     Research Institute for Informatics
C     Advanced Modeling and Optimization Laboratory     
C**********************************************************
C
	SUBROUTINE L2(N,X,S,BL)
	DOUBLE PRECISION X(N),S(N),BL
	DOUBLE PRECISION X1(50),FIB(50)
	DOUBLE PRECISION D1,D2,R1,R2,F1,F2
	DOUBLE PRECISION EPS,EPSR
C
	COMMON /PREC/EPS
	COMMON /TYPE/NO
	COMMON /NOF/NBL
C
	NBL=0
	JTYPE=0
	FIB(1)=1.0
	FIB(2)=1.0
C
	DO 1 I=3,50
1	FIB(I)=FIB(I-1)+FIB(I-2)
C
	IF(NO.EQ.6) THEN
	OPEN(6,FILE='PRINT.DAT',ACCESS='SEQUENTIAL',
     +         FORM='FORMATTED')
	ENDIF
C
	IF(EPS.EQ.0.0) THEN
	WRITE(5,20)
20	FORMAT(10X,'Warning:  EPS = 0.0.',/,
     +         10X,'The Fibonacci searching method does not run',/,
     +         10X,'with this value of EPS  ! ',/,
     +         10X,'Please enter a finite, positive, small value',/,
     +         10X,'of the parameter EPS.')
	RETURN
	ENDIF
C
	EPSR=1.0/EPS
C
              IF(JTYPE.EQ.1) WRITE(NO,12)EPSR
12            FORMAT(10X,'EPSR = ',F20.9)
	I=2
2	IF(FIB(I).GE.EPSR) GO TO 3
	I=I+1
	GO TO 2
C
3	D1=0.0
	D2=FIB(I)
C
              IF(JTYPE.EQ.1) WRITE(NO,13)I
13            FORMAT(10X,'Number of Fibonacci numbers = ',I5)
C
4	R1=D1+FIB(I-2)
	R2=D1+FIB(I-1)
C
              IF(JTYPE.EQ.1) WRITE(NO,15)D1,D2,R1,R2
15            FORMAT(10X,'D1=',F12.6,5X,'D2=',F12.6,5X,'R1=',F12.6,5X,
     +             'R2=',F12.6)
C
	R11=R1*EPS
	R22=R2*EPS
C
              IF(JTYPE.EQ.1) WRITE(NO,11)R11,R22
11            FORMAT(10X,'Lambda1=',F12.6,5X,'Lambda2=',F12.6)
C
	DO 5 J=1,N
5	X1(J)=X(J)+R11*S(J)
	CALL FUNC(N,X1,F1)
	NBL=NBL+1
C
	DO 6 J=1,N
6	X1(J)=X(J)+R22*S(J)
	CALL FUNC(N,X1,F2)
	NBL=NBL+1
C
              IF(JTYPE.EQ.1) WRITE(NO,16)F1,F2
16            FORMAT(10X,'F1=',F12.6,5X,'F2=',F12.6)
C
	IF(F2.GT.F1) THEN
	D2=R2
	ELSE
	D1=R1
	ENDIF
C
	IF(R1.EQ.R2) GO TO 7
	I=I-1
	GO TO 4
C
7	BL=R11  
C
              IF(JTYPE.EQ.1) WRITE(NO,17)BL,NBL
17            FORMAT(10X,'BL = ',F12.6,/,
     +               10X,'Number of Func. Eval. = ',I5)
	RETURN
	END
C
C***************************************Last card of L2.FOR
