FUNCTION FCHEBY(PX,KN)

! Calcul de la valeur du polynome de Chebyshev d'ordre KN au point PX
!        A.Bogatchev : 25-Oct-2007 removing of severe breaks of coding rools
USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(INOUT) :: KN

REAL(KIND=JPRB),INTENT(IN) :: PX

REAL(KIND=JPRB) :: FCHEBY

INTEGER(KIND=JPIM) :: J

REAL(KIND=JPRB) :: Z0, Z1, Z2
REAL(KIND=JPRB) :: ZHOOK_HANDLE

IF (LHOOK) CALL DR_HOOK('FCHEBY',0,ZHOOK_HANDLE)
IF (KN < 0) KN= -KN

Z0= 1.0_JPRB
Z1= PX

IF (KN == 0) THEN
  FCHEBY= Z0
  IF (LHOOK) CALL DR_HOOK('FCHEBY',1,ZHOOK_HANDLE)
  RETURN

ELSEIF (KN == 1) THEN
  FCHEBY= Z1
  IF (LHOOK) CALL DR_HOOK('FCHEBY',1,ZHOOK_HANDLE)
  RETURN

ELSE
  DO J=2,KN
    Z2= 2.0_JPRB*PX*Z1 - Z0
    Z0= Z1
    Z1= Z2
  ENDDO
  FCHEBY= Z2
  IF (LHOOK) CALL DR_HOOK('FCHEBY',1,ZHOOK_HANDLE)
  RETURN

ENDIF
IF (LHOOK) CALL DR_HOOK('FCHEBY',1,ZHOOK_HANDLE)
END FUNCTION FCHEBY

