SUBROUTINE fcserf_tl(PX,PX_PRIME,PERF_PRIME)

!**** *fcserf_tl* - Operator routine for gps radio occultation observations.

!     S. Healy             ECMWF          2004/10/26

!     PURPOSE
!     -------
!     Tangent linear of the error function calculation :

!**   INTERFACE
!     ---------
!    CALL gpsro_op(...)  

!     fcserf_tl is called from gpscalc_alphatl

!**   METHOD
!     ------
!     1) Abrmowitz and Stegun, Page 299, 7.1.25

!**   EXTERNALS
!     ---------

!**   MODIFICATIONS
!     -------------
!     Sean Healy      2004/01/05 : Original
!     -------------------------------------------------------------------------


USE PARKIND1  ,ONLY : JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK


IMPLICIT NONE

REAL(KIND=JPRB), INTENT(IN)  :: PX
REAL(KIND=JPRB), INTENT(IN)  :: PX_PRIME
REAL(KIND=JPRB), INTENT(OUT) :: PERF_PRIME
REAL(KIND=JPRB) :: ZT,ZT_PRIME
REAL(KIND=JPRB) :: ZHOOK_HANDLE

IF (LHOOK) CALL DR_HOOK('FCSERF_TL',0,ZHOOK_HANDLE)
 

ZT = 0.0_JPRB
      
IF (ABS(PX) < 9.0_JPRB) THEN
      
   IF (PX == 0_JPRB) THEN 
      
       PERF_PRIME = 0.0_JPRB
      
   ELSEIF (PX > 0.0_JPRB) THEN
      
      ZT=1.0_JPRB/(1.0_JPRB+0.47047_JPRB*PX)
    
      ZT_PRIME = -ZT/(1.0_JPRB+0.47047_JPRB*PX)*0.47047_JPRB*PX_PRIME
      
            
      PERF_PRIME=&
       & -(0.3480242_JPRB-(0.1917596_JPRB-2.2435668_JPRB*ZT)*ZT)*EXP(-(PX*PX))*ZT_PRIME + &
       & (0.3480242_JPRB-(0.0958798_JPRB-0.7478556_JPRB*ZT)*ZT)*ZT*EXP(-(PX*PX))* &
       & 2.0_JPRB*PX*PX_PRIME


   ELSE   !(PX < 0.0)!
      
      ZT=1.0_JPRB/(1.0_JPRB-0.47047_JPRB*PX)
     
      ZT_PRIME = ZT/(1.0_JPRB-0.47047_JPRB*PX)*0.47047_JPRB*PX_PRIME
     
      PERF_PRIME = &
      & (0.3480242_JPRB-(0.1917596_JPRB-2.2435668_JPRB*ZT)*ZT)*EXP(-(PX*PX))*ZT_PRIME - &
      & (0.3480242_JPRB-(0.0958798_JPRB-0.7478556_JPRB*ZT)*ZT)*ZT*EXP(-(PX*PX))* &
      & 2.0_JPRB*PX*PX_PRIME

   ENDIF   

ELSE
  
   PERF_PRIME = 0.0_JPRB
         
ENDIF 

IF (LHOOK) CALL DR_HOOK('FCSERF_TL',1,ZHOOK_HANDLE)

      
END SUBROUTINE fcserf_tl
