SUBROUTINE gpscalc_refrac2d(KLEV,  &
 & KHORIZ, &
 & pres, &
 & P_TEMP, &
 & P_Q,    &
 & P_REFRAC)  

!**** *gpscalc_refrac* - part of the GPSRO observation operator.

!     S. Healy             ECMWF          2004/10/26
!     Based on a EUMETSAT GRAS-SAF routine that was Dr'd automatically by the CY27 merge.  

!     PURPOSE
!     -------
!     It calculates the refractivity values on the model levels :

!**   INTERFACE
!     ---------

!     CALL gpscalc_refrac(KLEV,pres,P_TEMP,P_Q,P_REFRAC)  
!     WHERE KLEV   =  number of full model levels
!           pres     =  pressure on the full model levels
!           P_TEMP   =  temperature on the full model levels
!           P_Q      =  specific humidity on full model levels
!           P_REFRAC =  refractivity on full model levels 


!     gpscalc_refrac is called from gpsro_op and gpsro_ad

!**   METHOD
!     ------
!     1) calculate the dry and wey refractivity terms and add them. 

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

!**   MODIFICATIONS
!     -------------
!     Sean Healy      2004/10/26 : Original
!     -------------------------------------------------------------------------

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

USE YOMANCS, ONLY : RMDI

USE YOMCST, ONLY : rmv, &
 & rmd   

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KLEV
INTEGER(KIND=JPIM),INTENT(IN)    :: KHORIZ 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRES(KLEV,KHORIZ) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: P_TEMP(KLEV,KHORIZ) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: P_Q(KLEV,KHORIZ) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: P_REFRAC(KLEV,KHORIZ) 
! local variables

REAL(KIND=JPRB), PARAMETER :: aval = 0.776_JPRB
REAL(KIND=JPRB), PARAMETER :: bval = 3.73E3_JPRB

INTEGER(KIND=JPIM) :: i,j              ! counters
REAL(KIND=JPRB)    :: Z_NDRY,Z_NWET    ! dry and wet refractivity
REAL(KIND=JPRB)    :: Z_EPS            ! ratio of water vapour/ dry molecular weights   
REAL(KIND=JPRB) :: ZHOOK_HANDLE

! set the ratio of molecular weights (vapour/dry)

IF (LHOOK) CALL DR_HOOK('GPSCALC_REFRAC2D',0,ZHOOK_HANDLE)
Z_EPS = rmv/rmd

! initialise the refractivity to missing

P_REFRAC(:,:)  = RMDI

DO j = 1, KHORIZ

   DO i = 1, KLEV

      Z_NDRY = aval*pres(i,j)/P_TEMP(i,j)
   
      Z_NWET = bval*pres(i,j)*P_Q(i,j)/ &
   &  (P_TEMP(i,j)*P_TEMP(i,j)*(Z_EPS+(1.0_JPRB-Z_EPS)*P_Q(i,j)))  
   
      P_REFRAC(i,j) = Z_NDRY + Z_NWET
      
            
   ENDDO

ENDDO

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

END SUBROUTINE gpscalc_refrac2d
