      FUNCTION LEFT(X,TAB,N) ! binary search in ordered table TAB(N)
*     (multiple table values allowed, e.g. for B-splines)
*     returned function value L with 
*        TAB(L) <= X < TAB(L+1), i.e. outlow: L=0; outhigh: L=N 
*     exception if X =TAB(N): TAB(L) <  X <= TAB(L+1) 
      INTEGER L,R,N,LR
      REAL TAB(N),X
      L=0
      R=N+1
   10 LR=(L+R)/2    ! middle index
      IF(LR.NE.L) THEN
         IF(X.GT.TAB(LR)) THEN
            L=LR     ! new left limit
         ELSE
            R=LR     ! new right limit
         END IF
         GOTO 10
      END IF
   20 IF(LR.LT.N) THEN ! check multiple keys
         IF(X.EQ.TAB(LR+1)) THEN
            LR=LR+1
            GOTO 20
         END IF
      ELSE 
         LR=N       ! check exception X=TAB(N)
   30    IF(X.LE.TAB(LR)) THEN ! multiple keys
            LR=LR-1
            GOTO 30  
       END IF
      END IF
      LEFT=LR
      END
