SUBROUTINE GPPRS0D(KPROMA,KSTART,KPROF,KFLEV,PT,PQ,PQCLC,PQCLR,&
 & PQCLI,PQCLS,PQCLG,LDUCONV,PSIMRFC)

USE PARKIND1,ONLY : JPIM,  JPRB
USE YOMCST  ,ONLY : RPI,RTT
USE YOMHOOK ,ONLY : LHOOK, DR_HOOK
USE YOMCLMICST, ONLY : RXCCR,RXAS,RXBS,RXCCS,RXCXS,RXBI,RXAI, &
                     & RXLBI,RXLBEXI,RXALPHAI,RXNUI, &
                     & RXAG,RXBG,RXCCG,RXCXG,RXALPHAR,RXNUR, &
                     & RXALPHAS,RXNUS,RXALPHAG,RXNUG,RXLBEXR,RXLBR, &
                     & RXLBEXS,RXLBS,RXLBEXG,RXLBG,RXRTMIN,MOMG

!**** *GPPRS0D*  - Compute Simulated reflectivities - 0D -

!     PURPOSE.
!     --------
!        To Compute reflectivities knowing precipitating hydrometeores. 
!        The computation is done in 0Dimension, the geometry of the radar
!        is not considered. 
!**   INTERFACE.
!     ----------
!       *CALL* *GPPRS0D*

!        EXPLICIT ARGUMENTS
!        --------------------
!            INPUT :
!        KPROMA    : Horizontal dimension
!        KSTART    : start of work
!        KPROF     : depth of work
!        KFLEV     : number of vertical levels
!        PT        : temperature (KPROMA,KFLEV)
!        PQ        ; specific humidity (KPROMA,KFLEV)
!        PQCLC      : cloud water (KPROMA,KFLEV)
!        PQCLR      : cloud rain (KPROMA,KFLEV)
!        PQCLI      : cloud ice (KPROMA,KFLEV)
!        PQCLS      : cloud snow (KPROMA,KFLEV)
!        PQCLG      : cloud graupel (KRPOMA,KFLEV)
!            OUTPUT:
!        PSIMRF    : simulated reflectivies (KRPOMA,KLEV)

!        IMPLICIT ARGUMENTS
!        --------------------
!           NONE

!     METHOD.
!     -------
!        Derived from the radar obs operator (routine reflsim by E. Wattrelot)

!     EXTERNALS.
!     ----------
   
!     REFERENCE.
!     ----------
!        ECMWF Research Department documentation of the IFS

!     AUTHOR.
!     -------
!        Gwenaelle Hello *METEO-FRANCE*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 06-07-31
!        K. Yessad (Sep 2008): make coding norms compliant.
!        R. El Khatib  20-Mar-2009 Optimisation & bugfix
!     ------------------------------------------------------------------

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN) :: KPROMA,KSTART,KPROF,KFLEV
REAL(KIND=JPRB),INTENT(IN)  :: PT(KPROMA,KFLEV),PQ(KPROMA,KFLEV)
REAL(KIND=JPRB),INTENT(IN)  :: PQCLC(KPROMA,KFLEV),PQCLR(KPROMA,KFLEV)
REAL(KIND=JPRB),INTENT(IN)  :: PQCLI(KPROMA,KFLEV),PQCLS(KPROMA,KFLEV)
REAL(KIND=JPRB),INTENT(IN)  :: PQCLG(KPROMA,KFLEV)
REAL(KIND=JPRB),INTENT(OUT)  :: PSIMRFC(KPROMA,KFLEV)
LOGICAL,INTENT(IN) :: LDUCONV

!     ------------------------------------------------------------------

REAL(KIND=JPRB) :: ZRCLR(KPROMA,KFLEV),ZRCLS(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZRCLI(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZRCLG(KPROMA,KFLEV),ZQD(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZLBDA(KPROMA,KFLEV),ZREFL(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZREFL_MELT_CONV(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZXR, ZRHOLW, ZDMELT_FACT, ZEXP, ZEQICE
REAL(KIND=JPRB) :: ZFRAC_WATER
REAL(KIND=JPRB) :: ZEQWAT
REAL(KIND=JPRB) :: ZHOOK_HANDLE
INTEGER(KIND=JPIM) :: JROF,JLEV

!     ------------------------------------------------------------------

#include "suclmicst.intfb.h"

!     ------------------------------------------------------------------

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

!     ------------------------------------------------------------------
!*********************************************************
! 0. Initialization  
!*********************************************************

PSIMRFC=0._JPRB
ZLBDA=0._JPRB
ZREFL=0._JPRB


! From qx to mixing ratio

DO JLEV=1,KFLEV
  DO JROF=KSTART,KPROF
    ZQD(JROF,JLEV)=1.0_JPRB-PQ(JROF,JLEV)-PQCLC(JROF,JLEV)-PQCLR(JROF,JLEV) &
     &-PQCLI(JROF,JLEV) - PQCLS(JROF,JLEV) - PQCLG(JROF,JLEV)
  ENDDO
ENDDO

DO JLEV=1,KFLEV
  DO JROF=KSTART,KPROF
    ZRCLR(JROF,JLEV)=PQCLR(JROF,JLEV)/ZQD(JROF,JLEV)
    ZRCLS(JROF,JLEV)=PQCLS(JROF,JLEV)/ZQD(JROF,JLEV)
    ZRCLG(JROF,JLEV)=PQCLG(JROF,JLEV)/ZQD(JROF,JLEV)
    ZRCLI(JROF,JLEV)=PQCLI(JROF,JLEV)/ZQD(JROF,JLEV)
  ENDDO
ENDDO 

! Initialisation of clouds constants (Duplication of what is done in
! ini_rain_ice for MNH microphysics)

CALL SUCLMICST

! Initialisation of remaining constants

ZXR = -1.0_JPRB !Value of x_r in N_r = C_r lambda_r ** x_r
ZRHOLW = 1000.0_JPRB !density of liquid water in kgm-3
ZEQICE = 0.224_JPRB !?

!**********************************************************************
! 1. Compute reflectivities on each model vertical level (0D operator)*
!**********************************************************************

! 1.1. Rain
! -----------

DO JLEV=1,KFLEV
  DO JROF=KSTART,KPROF
    IF (ZRCLR(JROF,JLEV) > RXRTMIN(3)) THEN
      ZLBDA(JROF,JLEV) = RXLBR*( ZRCLR(JROF,JLEV) )**RXLBEXR
      IF (ZLBDA(JROF,JLEV) < 1.0E120_JPRB) THEN
        ZREFL(JROF,JLEV) = RXCCR*(ZLBDA(JROF,JLEV)**(ZXR-6.0_JPRB))&
         &*MOMG(RXALPHAR,RXNUR,6.0_JPRB)
      ENDIF
    ENDIF
  ENDDO
ENDDO

! 1.2. Ice
! --------
ZDMELT_FACT=(RXBI/3.0_JPRB)*((6.0_JPRB*RXAI)/(RPI*ZRHOLW))**(7.0_JPRB/3.0_JPRB)
ZEXP = 7.0_JPRB*RXBI/3.0_JPRB-1.0_JPRB
DO JLEV=1,KFLEV
  DO JROF=KSTART,KPROF
    IF (ZRCLI(JROF,JLEV) > RXRTMIN(4)) THEN
      ZLBDA(JROF,JLEV) = RXLBI*( ZRCLI(JROF,JLEV) )**RXLBEXI
      IF (ZLBDA(JROF,JLEV) < 1.0E120_JPRB) THEN
        ZREFL(JROF,JLEV) = ZREFL(JROF,JLEV)+ZEQICE*ZDMELT_FACT  &
         &  *(ZLBDA(JROF,JLEV)**(-ZEXP))*MOMG(RXALPHAI,RXNUI,ZEXP)
      ENDIF
    ENDIF
  ENDDO
ENDDO

! To be coded
!!$WHERE(PCIWF5(:,:) > XRTMINCIW)
!!$   ZDMELT_FACT = ( XBI/3.0 )*( (6.0*XAI)/(RPI*XRHOLW) )**(7.0/3.0)
!!$   ZEXP = 7.0*XBI/3.0-1.0
!!$   ZLBDA(:,:) = XLBI*( PCLWF5(:,:)/PCIT(:,:) )**XLBEXI
!!$   ZREFL(:,:) = ZREFL(:,:)+ZEQICE*ZDMELT_FACT                 &
!!$      &  *PCIT(:,:)*(ZLBDA(:,:)**(-ZEXP))*MOMG(XALPHAI,XNUI,ZEXP)
!!$END WHERE

! 1.3. Snow  
! ---------

ZDMELT_FACT=(RXBS/3.0_JPRB)*((6.0_JPRB*RXAS)/(RPI*ZRHOLW))**(7.0_JPRB/3.0_JPRB)
ZEXP = 7.0_JPRB*RXBS/3.0_JPRB-1.0_JPRB

DO JLEV=1,KFLEV
  DO JROF=KSTART,KPROF
    IF (ZRCLS(JROF,JLEV) > RXRTMIN(5)) THEN
      ZLBDA(JROF,JLEV) = RXLBS*( ZRCLS(JROF,JLEV) )**RXLBEXS
      IF (ZLBDA(JROF,JLEV) < 1.0E120_JPRB) THEN
        ZREFL(JROF,JLEV) = ZREFL(JROF,JLEV)+ZEQICE*ZDMELT_FACT      &
         &  *RXCCS*(ZLBDA(JROF,JLEV)**(RXCXS-ZEXP))*MOMG(RXALPHAS,RXNUS,ZEXP)
      ENDIF
    ENDIF
  ENDDO
ENDDO

! 1.4. Graupel
! ------------
ZFRAC_WATER = 0.14_JPRB
ZDMELT_FACT=(RXBG/3.0_JPRB)*((6.0_JPRB*RXAG)/(RPI*ZRHOLW))**(7.0_JPRB/3.0_JPRB)
ZEXP = 7.0_JPRB*RXBG/3.0_JPRB-1.0_JPRB
ZEQWAT=ZFRAC_WATER*(1.0_JPRB-ZEQICE)

DO JLEV=1,KFLEV
  DO JROF=KSTART,KPROF
    ZREFL_MELT_CONV(JROF,JLEV)=ZDMELT_FACT* &
     & (ZEQICE + ZEQWAT*MAX(SIGN(1._JPRB,PT(JROF,JLEV)-RTT),0._JPRB))
  ENDDO
ENDDO

DO JLEV=1,KFLEV
  DO JROF=KSTART,KPROF
    IF (ZRCLG(JROF,JLEV) > RXRTMIN(6)) THEN 
      ZLBDA(JROF,JLEV) = RXLBG*( ZRCLG(JROF,JLEV) )**RXLBEXG
      IF (ZLBDA(JROF,JLEV) < 1.0E120_JPRB) THEN
        ZREFL(JROF,JLEV) = ZREFL(JROF,JLEV)+ZREFL_MELT_CONV(JROF,JLEV) &
         & *RXCCG*(ZLBDA(JROF,JLEV)**(RXCXG-ZEXP))*MOMG(RXALPHAG,RXNUG,ZEXP)
      ENDIF
    ENDIF 
  ENDDO
ENDDO

! 1.5. Unit conversion
! --------------------
IF (LDUCONV) THEN
  DO JLEV=1,KFLEV
    DO JROF=KSTART,KPROF
!     PSIMRFC(JROF,JLEV) = 10.0*LOG10( 1.E18_JPRB*MAX(ZREFL(JROF,JLEV),1.E-18_JPRB) ) ! Z_e in dBZ
      PSIMRFC(JROF,JLEV) = (0.005_JPRB*1.E18_JPRB*ZREFL(JROF,JLEV))**0.625 ! Z_e in mmh-1
    ENDDO
  ENDDO
ELSE
  PSIMRFC(:,:)=ZREFL(:,:)
ENDIF

!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('GPPRS0D',1,ZHOOK_HANDLE)
END SUBROUTINE  GPPRS0D
