        REAL FUNCTION LINVAL(X,Y,N,XVALUE)
        IMPLICIT NONE
C
C**********************************************************************
C
C   NAME- LINVAL
C
C   LANGUAGE-  FORTRAN  TYPE- FUNCTION        COMPUTER- IBM SP
C
C   VERSION- 1.0    DATE- 10/07/88   PROGRAMMER- KARL W. COX (SMSRC)
C   VERSION- 2.0    DATE- 06/17/04   PROGRAMMER- FRANK TILLEY (RAYTHEON)
C            RE-HOSTED FROM CEMSCS MVS MAINFRAME TO IBM SP UNIX
C            PLATFORM.
C
C   FUNCTION- BINARY SEARCH. THIS FUNCTION RETURNS THE FUNCTIONAL
C   VALUE, AT POINT XVALUE, OF THE PIECEWISE LINEAR REPRESENTATION
C   OF A FUNCTION GIVEN BY THE VECTOR X AND THE CORRESPONDING VECTOR
C   Y CONTAINING THE ABSCISSA AND ORDINATES AT EACH POINT.  THE VECTOR
C   X AND Y ARE OF LENGHT N.
C
C   CALLING SEQUENCE PARAMETERS-
C     VARIABLE          TYPE I/O  FUNCTION
C     --------          ---- ---  --------
C     X(N)              REAL  I   VECTOR OF LENGTH N CONTAINING
C                                 ABSCISSA VALUES
C     Y(N)              REAL  I   VECTOR OF LENGTH N CONTAINING
C                                 ORDINATE VALUES
C     N                 INT   I   NUMBER OF VALUES
C     XVALUE            REAL  I   ABSCISSA (E.E., X) VALUE TO BE
C                                 INTERPOLATED
C   COMMON AREA PARAMETERS -
C
       INCLUDE 'SPVAL'
C
C   LOCAL PARAMETERS-
C     VARIABLE          TYPE  FUNCTION
C     --------          ----  --------
C     INDEX             INT   COUNTER
C     INTVAL            REAL  INTERPOLATED VALUE
C
C  SUBROUTINES CALLED: LINTRP
C  FUNCTIONS USED: INTRVL
C
C**********************************************************************
C
C
         INTEGER   N
         REAL   X(N),Y(N),XVALUE,INTVAL
C
C  TEMPORARY VARIABLES
C
         LOGICAL   INTRVL
         INTEGER   INDEX
C
         LINVAL = R4SPV
         IF(INTRVL(X,N,XVALUE,INDEX))  THEN
           IF(XVALUE.EQ.X(INDEX))THEN
             LINVAL=Y(INDEX)
           ELSE
             IF(XVALUE.EQ.X(INDEX+1))THEN
               LINVAL=Y(INDEX+1)
             ELSE
               CALL LINTRP(X(INDEX),Y(INDEX),
     +                 X(INDEX+1),Y(INDEX+1),
     +                  XVALUE,INTVAL)
               LINVAL = INTVAL
             ENDIF
           ENDIF
         ENDIF
C
         RETURN
         END
