!OPTIONS XOPT(NOEVAL)
SUBROUTINE SW15 ( KIDIA,KFDIA,KLON,KTDIA,KLEV,&
 & KAER,&
 & PSCT , PCARDI, PPSOL , PALBD, PALBP , PWV, PQS,&
 & PRMU0, PCG   , PCLDSW, PDP  , POMEGA, POZ, PPMB,&
 & PTAU , PTAVE , PAER,&
 & PHEAT, PFDOWN, PFUP,&
 & PCHEAT, PCDOWN, PCUP,&
 & PFDNN, PFDNV , PFUPN, PFUPV,&
 & PFDNNC,PFDNVC, PFUPNC,PFUPVC )  

!**** *SW* - COMPUTES THE SHORTWAVE RADIATION FLUXES.
!****        FROZEN VERSION (CYCLE 15) OF SW

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

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

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

!          *SW* IS CALLED FROM *RADLSW*

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

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

!     METHOD.
!     -------

!          1. COMPUTES ABSORBER AMOUNTS                 (SWU)
!          2. COMPUTES FLUXES IN 1ST SPECTRAL INTERVAL  (SW1S)
!          3. COMPUTES FLUXES IN 2ND SPECTRAL INTERVAL  (SW2S)

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

!          *SWU*, *SW1S*, *SW2S*

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

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

!     AUTHOR.
!     -------
!        96-11: Ph. Dandin. Meteo-France
!        ORIGINAL : 89-07-14 BY JEAN-JACQUES MORCRETTE  *ECMWF*

!     MODIFICATIONS.
!     --------------
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        A.Alias       19-09-2005 Sulfate aerosols (Hu Rong Ming)
!     ------------------------------------------------------------------

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

USE YOMRDU15 , ONLY : RCDAY15

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)               :: KTDIA ! Argument NOT used
INTEGER(KIND=JPIM),INTENT(IN)    :: KAER 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSCT 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCARDI 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PPSOL(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALBD(KLON,2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALBP(KLON,2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PWV(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQS(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRMU0(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCG(KLON,2,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLDSW(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POMEGA(KLON,2,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POZ(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PPMB(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTAU(KLON,2,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTAVE(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAER(KLON,KLEV,6) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHEAT(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFDOWN(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFUP(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCHEAT(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCDOWN(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCUP(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFDNN(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFDNV(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFUPN(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFUPV(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFDNNC(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFDNVC(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFUPNC(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFUPVC(KLON) 
!     ------------------------------------------------------------------

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

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

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

REAL(KIND=JPRB) :: ZAKI(KLON,2)&
 & ,  ZCLD(KLON,KLEV) , ZCLEAR(KLON) &
 & ,  ZDSIG(KLON,KLEV), ZFACT(KLON)&
 & ,  ZFD(KLON,KLEV+1), ZFDOWN(KLON,KLEV+1)&
 & ,  ZFDC(KLON,KLEV+1), ZFDOWNC(KLON,KLEV+1)&
 & ,  ZFU(KLON,KLEV+1) , ZFUP(KLON,KLEV+1)&
 & ,  ZFUC(KLON,KLEV+1), ZFUPC(KLON,KLEV+1)&
 & ,  ZRMU(KLON), ZSEC(KLON)&
 & ,  ZUD(KLON,5,KLEV+1)  

INTEGER(KIND=JPIM) :: INU, JK, JKL, JL

REAL(KIND=JPRB) :: ZDFNET
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "sw1s15.intfb.h"
#include "sw2s15.intfb.h"
#include "swu15.intfb.h"

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

!*         1.     ABSORBER AMOUNTS AND OTHER USEFUL QUANTITIES
!                 --------------------------------------------

IF (LHOOK) CALL DR_HOOK('SW15',0,ZHOOK_HANDLE)
CALL SWU15 ( KIDIA,KFDIA ,KLON ,KLEV,KAER,&
 & PSCT ,PCARDI,PCLDSW,POZ  ,PPMB ,PPSOL,&
 & PRMU0,PTAVE ,PWV,&
 & ZAKI ,ZCLD  ,ZCLEAR,ZDSIG,ZFACT,ZRMU,ZSEC,ZUD )  

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

!*         2.     FIRST SPECTRAL INTERVAL (0.25-0.68 MICRON)
!                 ----------------------- ------------------

INU = 1

CALL SW1S15 ( KIDIA , KFDIA, KLON, KLEV, KAER  , INU,&
 & PAER , PALBD , PALBP, PCG  , ZCLD , ZCLEAR, PCLDSW,&
 & ZDSIG, POMEGA, POZ  , ZRMU , ZSEC , PTAU  , ZUD,&
 & ZFD  , ZFU   , ZFDC , ZFUC                         )  

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

!*         3.     SECOND SPECTRAL INTERVAL (0.68-4.00 MICRON)
!                 -------------------------------------------

INU = 2

CALL SW2S15 ( KIDIA, KFDIA, KLON, KLEV, KAER, INU,&
 & PAER  ,ZAKI , PALBD, PALBP, PCG  , ZCLD, ZCLEAR, PCLDSW,&
 & ZDSIG ,POMEGA,POZ  , ZRMU , ZSEC , PTAU, ZUD,&
 & PWV   ,PQS,&
 & ZFDOWN,ZFUP  ,ZFDOWNC,ZFUPC                            )  

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

!*         4.     FILL THE DIAGNOSTIC ARRAYS
!                 --------------------------

DO JL = KIDIA,KFDIA
  PFDNN(JL)=ZFDOWN(JL,1)*ZFACT(JL)
  PFDNV(JL)=ZFD(JL,1)*ZFACT(JL)
  PFUPN(JL)=ZFUP(JL,KLEV+1)*ZFACT(JL)
  PFUPV(JL)=ZFU(JL,KLEV+1)*ZFACT(JL)

  PFDNNC(JL)=ZFDOWNC(JL,1)*ZFACT(JL)
  PFDNVC(JL)=ZFDC(JL,1)*ZFACT(JL)
  PFUPNC(JL)=ZFUPC(JL,KLEV+1)*ZFACT(JL)
  PFUPVC(JL)=ZFUC(JL,KLEV+1)*ZFACT(JL)
ENDDO

DO JK = 1 , KLEV+1
  DO JL = KIDIA,KFDIA
    PFUP(JL,JK)   = (ZFUP(JL,JK)   + ZFU(JL,JK)) * ZFACT(JL)
    PFDOWN(JL,JK) = (ZFDOWN(JL,JK) + ZFD(JL,JK)) * ZFACT(JL)
    PCUP(JL,JK)   = (ZFUPC(JL,JK)   + ZFUC(JL,JK)) * ZFACT(JL)
    PCDOWN(JL,JK) = (ZFDOWNC(JL,JK) + ZFDC(JL,JK)) * ZFACT(JL)
  ENDDO
ENDDO

DO JKL = 1 , KLEV
  JK = KLEV+1 - JKL
  DO JL = KIDIA,KFDIA
    ZDFNET = PFUP(JL,JK+1) - PFDOWN(JL,JK+1)-PFUP(JL,JK  ) + PFDOWN(JL,JK  )
    PHEAT(JL,JK) = RCDAY15 * ZDFNET / PDP(JL,JKL)
    ZDFNET = PCUP(JL,JK+1) - PCDOWN(JL,JK+1)-PCUP(JL,JK  ) + PCDOWN(JL,JK  )
    PCHEAT(JL,JK) = RCDAY15 * ZDFNET / PDP(JL,JKL)
  ENDDO
ENDDO

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

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