SUBROUTINE UVFLX &
 &( KIDIA , KFDIA , KLON  , KLEV , KUV   , &
 &  PALBD , PALBP , PCG   , PCLD , PCLEAR, &
 &  PDSIG , POMEGA, PRAYL , PRMU , PSEC  , &
 &  PTAU  , PCGAZ , PPIZAZ,PTAUAZ, PUD   , &
 &  PFD   , PCD   &
 &)  

!**** *UVFLX* - SHORTWAVE RADIATION, UV SPECTRAL INTERVAL

!     PURPOSE.
!     --------

!          THIS ROUTINE COMPUTES THE SHORTWAVE RADIATION FLUXES IN TWO
!     SPECTRAL INTERVALS FOLLOWING FOUQUART AND BONNEL (1980).

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

!          *UVFLX* IS CALLED FROM *UVRADI*.

!        IMPLICIT ARGUMENTS :
!        --------------------

!     ==== INPUTS ===
!     ==== OUTPUTS ===

!     METHOD.
!     -------

!          1. COMPUTES QUANTITIES FOR THE CLEAR-SKY FRACTION OF THE
!     COLUMN
!          2. COMPUTES UPWARD AND DOWNWARD FLUXES CORRESPONDING TO
!     CONTINUUM SCATTERING
!          3. MULTIPLY BY OZONE TRANSMISSION FUNCTION

!     EXTERNALS.
!     ----------

!          *UVCLR*, *UVR*

!     REFERENCE.
!     ----------

!        SEE RADIATION'S PART OF THE ECMWF RESEARCH DEPARTMENT
!        DOCUMENTATION, AND FOUQUART AND BONNEL (1980)

!     AUTHOR.
!     -------
!        JEAN-JACQUES MORCRETTE  *ECMWF*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 2005-10-04 from SW (but top to bottom)

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

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

USE YOE_UVRAD ,ONLY : RK250 

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)  :: KLON 
INTEGER(KIND=JPIM),INTENT(IN)  :: KLEV 
INTEGER(KIND=JPIM),INTENT(IN)  :: KIDIA 
INTEGER(KIND=JPIM),INTENT(IN)  :: KFDIA 
INTEGER(KIND=JPIM),INTENT(IN)  :: KUV 

REAL(KIND=JPRB)   ,INTENT(IN)  :: PALBD(KLON), PALBP(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)  :: PCG(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)  :: PCLD(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)  :: PCLEAR(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)  :: PDSIG(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)  :: POMEGA(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)  :: PRAYL(KLON), PRMU(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)  :: PSEC(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)  :: PTAU(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)  :: PCGAZ(KLON,KLEV), PPIZAZ(KLON,KLEV), PTAUAZ(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(IN)  :: PUD(KLON,2,KLEV+1)

REAL(KIND=JPRB)   ,INTENT(OUT) :: PFD(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT) :: PCD(KLON,KLEV+1) 
!     ------------------------------------------------------------------

!*       0.1   ARGUMENTS
!              ---------

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

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

REAL(KIND=JPRB) :: &
 &    ZDIFF(KLON)       , ZDIRF(KLON)        &
 & ,  ZFD(KLON,KLEV+1)  &
 & ,  ZRAY1(KLON,KLEV+1), ZRAY2(KLON,KLEV+1)&
 & ,  ZREFZ(KLON,2,KLEV+1)&
 & ,  ZRJ(KLON,6,KLEV+1), ZRJ0(KLON,6,KLEV+1)&
 & ,  ZRK(KLON,6,KLEV+1), ZRK0(KLON,6,KLEV+1)&
 & ,  ZRMUE(KLON,KLEV+1), ZRMU0(KLON,KLEV+1)&
 & ,  ZTRA1(KLON,KLEV+1), ZTRA2(KLON,KLEV+1)&
 & ,  ZTRCLD(KLON)      , ZTRCLR(KLON)&
 & ,  ZO(KLON,2)        , ZT(KLON,2)   

REAL(KIND=JPRB) :: ZRR0, ZRRE

INTEGER(KIND=JPIM) :: JAJ, JK, JL

REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "uvclr.intfb.h"
#include "uvr.intfb.h"
!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('UVFLX',0,ZHOOK_HANDLE)


!*         1.     VALID FOR SPECTRAL INTERVAL WITHIN 280-400 NM
!                 ---------------------------------------------


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

!*         2.    CONTINUUM SCATTERING CALCULATIONS
!                ---------------------------------

!*         2.1   CLEAR-SKY FRACTION OF THE COLUMN
!                --------------------------------

CALL UVCLR &
 &( KIDIA , KFDIA , KLON  , KLEV , &
 &  PALBP , PDSIG , PRAYL , PSEC , &
 &  PCGAZ , PPIZAZ, ZRAY1 , ZRAY2, ZREFZ, ZRJ0,&
 &  ZRK0  , ZRMU0 , PTAUAZ, ZTRA1, ZTRA2, ZTRCLR &
 &)  

!*         2.2   CLOUDY FRACTION OF THE COLUMN
!                -----------------------------

CALL UVR &
 &( KIDIA ,KFDIA ,KLON  ,KLEV  ,&
 &  PALBD ,PCG   ,PCLD  ,POMEGA, PSEC , PTAU,&
 &  PCGAZ ,PPIZAZ,ZRAY1 ,ZRAY2 , ZREFZ, ZRJ  ,ZRK , ZRMUE,&
 &  PTAUAZ,ZTRA1 ,ZTRA2 ,ZTRCLD &
 &)  

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

!*         3.    OZONE ABSORPTION OVER KUV SPECTRAL INTERVALS
!                --------------------------------------------

!*         3.1   DOWNWARD FLUXES
!                ---------------

JAJ = 2

DO JL = KIDIA,KFDIA
  ZO(JL,1)=0.0_JPRB
  ZO(JL,2)=0.0_JPRB
  PFD(JL,1)=((1.0_JPRB-PCLEAR(JL))*ZRJ(JL,JAJ,1)&
   & + PCLEAR(JL) *ZRJ0(JL,JAJ,1))  
  PCD(JL,1)= ZRJ0(JL,JAJ,1)
  ZFD(JL,1)= ZRJ(JL,JAJ,1)
ENDDO
DO JK = 1 , KLEV
  DO JL = KIDIA,KFDIA

!-- introduction of T effect on O3 absorber amounts:
!   now computed in *UVRADI* and included in PUD 

!-- cumulative amount of O3 absorber from TOA
    ZRR0=1.0_JPRB/ZRMU0(JL,JK)
    ZRRE=1.0_JPRB/ZRMUE(JL,JK)
    ZO(JL,1)=ZO(JL,1)+PUD(JL,1,JK+1)*ZRRE
    ZO(JL,2)=ZO(JL,2)+PUD(JL,1,JK+1)*ZRR0

!-- O3 molecular transmission function
    ZT(JL,1) = EXP(-RK250(KUV)*ZO(JL,1))
    ZT(JL,2) = EXP(-RK250(KUV)*ZO(JL,2))

!-- direct (clear-sky with aerosols) and diffuse (total with clouds) 
!   transmissivities
    ZDIFF(JL) = ZT(JL,1)*ZRJ(JL,JAJ,JK+1)
    ZDIRF(JL) = ZT(JL,2)*ZRJ0(JL,JAJ,JK+1)

!    print 9001,JK,PUD(JL,1,JK+1),ZRMU0(JL,JK),ZRMUE(JL,JK),ZEFACT,(ZO(JL,JA),ZT(JL,JA),JA=1,2),&
!      &ZRJ0(JL,JAJ,JK+1),ZRJ(JL,JAJ,JK+1),ZDIRF(JL),ZDIFF(JL) 
9001 format(1x,'FLX',I3,E10.3,2F8.4,9E10.3)

!-- downward fluxes, total and clear-sky
    ZFD(JL,JK+1)   = ZDIFF(JL)
    PFD(JL,JK+1) = ((1.0_JPRB-PCLEAR(JL)) * ZDIFF(JL)&
     & +PCLEAR(JL)  * ZDIRF(JL))
    PCD(JL,JK+1) = ZDIRF(JL)
  ENDDO
ENDDO
!JL=KIDIA
!print 9002,PCLEAR(JL),PCD(JL,KLEV+1),PFD(JL,KLEV+1),ZFD(JL,KLEV+1)
9002 format(1x,'UVFLX ',F10.7,3E12.5)

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

IF (LHOOK) CALL DR_HOOK('UVFLX',1,ZHOOK_HANDLE)
END SUBROUTINE UVFLX

