
C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LSM_CHEBVAL      **
C**************************
C
C **** LSM SERVICE ROUTINE ONLY ****
C
       REAL FUNCTION LSM_CHEBVAL (XMIN, XMAX, C, N, X)
C
       INCLUDE 'implicit_none.finc'
C
C Purpose: Evaluate Chebyshev function value
C
C Author:  Steffi Arzt, John Campbell, July 1997
C
C Arguments:
C
       DOUBLE PRECISION XMIN
       DOUBLE PRECISION XMAX
       DOUBLE PRECISION C(*)
       INTEGER N
       DOUBLE PRECISION X
C
C Parameters:  
C  XMIN      (R)    Minimum 'x' used in polynomials calculation
C  XMAX      (R)    Maximum 'x' used in polynomials calcualtion
C  C         (R)    The Chebyshev polynomial coefficients
C  N         (R)    Polynomial order + 1
C  X         (R)    The value of 'x' at which the function is to be evaluated
C
C
C====== GLOBALS:
C
C
C====== LOCALS:
C
      INTEGER J
      DOUBLE PRECISION D, DD, Y, Y2, SV
C
C-------------------------------------------------------------------------------
C
      LSM_CHEBVAL = 0.0
      IF (((X-XMIN)*(X-XMAX)).GT.0.0) RETURN
      D = 0.0
      DD = 0.0
      Y = (2.0*X-XMIN-XMAX)/(XMAX-XMIN)
      Y2 = 2.0*Y
      IF (N.GT.1) THEN
         DO 100 J = N,2,-1
            SV = D
            D = Y2*D - DD + C(J)
            DD = SV
100      CONTINUE
      END IF
      LSM_CHEBVAL = Y*D -DD + 0.5*C(1)
      RETURN
      END
