!OPTIONS XOPT(NOEVAL)
SUBROUTINE ACRADSTL ( KIDIA,KFDIA,KLON,KTDIA,KLEV,KJN,&
 !-----------------------------------------------------------------------
 ! - INPUT  2D .
 & PT5,PAPRSF5,PQ5,PDELP5,PRDELP5,PFPLC5,&
 & PT,PAPRSF,PQ,PDELP,PRDELP,PFPLC,&
 ! - INPUT  1D .
 & PALB,PEMIS,PMU0,PTS,&
 ! - CONSTANTES.
 & PAC,PCOR,&
 & PRAB3C,PRAB3N,PRAB4C,PRAB4N,PRAB6C,PRAB6N,&
 & PRAT1C,PRAT1N,PRAT2C,PRAT2N,PRAT3C,PRAT3N,&
 & PRAT4C,PRAT4N,PRAT5C,PRAT5N,&
 ! - OUTPUT 2D .
 & PFRSO5,PFRTH5,&
 & PFRSO,PFRTH,&
 ! - LOCK ARGUMENTS .
 & CDLOCK)  

!**** *ACRADSTL * - TANGENT LINEAR OF COMPUTATION OF RADIATIVE FLUXES.

!     Subject.
!     --------
!     Tangent linear of:
!     - ROUTINE FOR CALCULATION OF RADIATIVE FLUXES:
!         THERMAL RADIATION
!         SOLAR RADIATION

!**   Interface.
!     ----------
!        *CALL* *ACRADSTL*

! -   ARGUMENTS FOR INPUT
!     -------------------

! - DIMENSIONAL PARAMETERS OF PHYSICS

! KIDIA      : START OF HORIZONTAL LOOP (IST in CPG).
! KFDIA      : END OF HORIZONTAL LOOP (IEND in CPG).
! KLON       : HORIZONTAL DIMENSIONAL.
! KTDIA      : START OF THE VERTICAL LOOP IN THE PHYSIC (1 IN GENERAL).
! KLEV       : END OF VERTICAL LOOP AND VERTICAL DIMENSION "FULL LEVEL".
!              (NFLEVG in CPG).

! - THE NAME OF THE PHYSICAL VARIABLES

! - 2D (1:KLEV) .

! PT         : TEMPERATURE.
! PDELP      : LAYER THICKNESS IN PRESSURE UNITS.
! PRDELP     : INVERSE OF LAYER THICKNESS IN PRESSURE UNITS.
! PQ         : SPECIFIC HUMIDITY OF WATER VAPOR.
! PAPRSF     : PRESSURE ON FULL LEVELS.

! The same but for trajectory
! ---------------------------
! PT5        : TEMPERATURE.
! PDELP5     : LAYER THICKNESS IN PRESSURE UNITS.
! PRDELP5    : INVERSE OF LAYER THICKNESS IN PRESSURE UNITS.
! PQ5        : SPECIFIC HUMIDITY OF WATER VAPOR.
! PAPRSF5    : PRESSURE ON FULL LEVELS.

! - 2D (0:KLEV) .

! PFPLC      : CONVECTIVE PRECIPITATION (AS RAIN AND AS SNOW).

! The same but for trajectory
! ---------------------------
! PFPLC5     : CONVECTIVE PRECIPITATION (AS RAIN AND AS SNOW).

! - 1D

! PTS        : SURFACE TEMPERATURE

! - 1D (DIAGNOSTIC) .

! PMU0       : LOCAL COSINE OF INSTANTENOUS SOLAR ZENITH ANGLE.
! PALB       : MODEL SURFACE SHORTWAVE ALBEDO.
! PEMIS      : MODEL SURFACE LONGWAVE EMISSIVITY.

! - CONSTANTES

! PAC        : COURTIS MATRIX FOR THERMAL RADIATION FOR CLEAR SKY
! PCOR       : CORRECTION FOR CLOUDINESS FOR THERMAL RADIATION

! PRAB3C     : CLEAR-SKY PARALLEL/DIFFUSE REFLECTIVITY.  ---
! PRAB4C     : CLEAR-SKY DIFFUSE TRANSMISSIVITY.            | equivalent
! PRAB6C     : CLEAR-SKY DIFFUSE REFLECTIVITY.              | coefficients
! PRAB3N     : CLOUDY PARALLEL/DIFFUSE REFLECTIVITY.        | from bottom
! PRAB4N     : CLOUDY DIFFUSE TRANSMISSIVITY.               | to given
! PRAB6N     : CLOUDY DIFFUSE REFLECTIVITY.              ---  level

! PRAT1C     : CLEAR-SKY PARALLEL TRANSMISSIVITY.        ---
! PRAT2C     : CLEAR-SKY PARALLEL/DIFFUSE TRANSMISSIVITY.   |
! PRAT3C     : CLEAR-SKY PARALLEL/DIFFUSE REFLECTIVITY.     |
! PRAT4C     : CLEAR-SKY DIFFUSE TRANSMISSIVITY.            | equivalent
! PRAT5C     : CLEAR-SKY DIFFUSE REFLECTIVITY.              | coefficients
! PRAT1N     : CLOUDY PARALLEL TRANSMISSIVITY.              | from top
! PRAT2N     : CLOUDY PARALLEL/DIFFUSE TRANSMISSIVITY.      | to given
! PRAT3N     : CLOUDY PARALLEL/DIFFUSE REFLECTIVITY.        | level
! PRAT4N     : CLOUDY DIFFUSE TRANSMISSIVITY.               |
! PRAT5N     : CLOUDY DIFFUSE REFLECTIVITY.              ---

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

! -   OUTPUT ARGUMENTS.
!     -----------------

! - 2D (0:KLEV) .

! PFRSO      : SHORTWAVE RADIATIVE FLUX.
! PFRTH      : LONGWAVE RADIATIVE FLUX.

! The same but for trajectory
! ---------------------------
! PFRSO5     : SHORTWAVE RADIATIVE FLUX.
! PFRTH5     : LONGWAVE RADIATIVE FLUX.

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

! -   ARGUMENTS IMPLICITES.
!     ---------------------

! COMMON/YOMPHY /
! COMMON/YOMCST /
! COMMON/YOMPHY0/
! COMMON/YOMPHY3/
! COMMON/YOMGEM/
! COMMON/YOMSIMPHL/

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

!     Externals.
!     ----------

!     Method.
!     -------

!     Author.
!     -------
!        96-07, M. Janiskova

!     Modifications.
!     --------------
!        97-08, introduce CDLOCK - J.M. Piriou.
!        97-11, new cloudiness parametrization, correction of
!               computation B-matrix - M. Janiskova
!        98-01, code optimalization and cleaning - M. Janiskova
!        99-02, modifications in the thermal radiation due to mean
!               value of matrix PAC - M. Janiskova
!        M.Hamrud      01-Oct-2003 CY28 Cleaning

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

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

USE YOMPHY   , ONLY : LNEIGE
USE YOMCST   , ONLY : RSIGMA   ,RV       ,RCPV     ,&
 & RETV     ,RCW      ,RCS      ,RLVTT    ,RLSTT    ,&
 & RTT      ,RALPW    ,RBETW    ,RGAMW    ,RALPS    ,&
 & RBETS    ,RGAMS    ,RALPD    ,RBETD    ,RGAMD    ,&
 & RG  
USE YOMPHY0  , ONLY : NPCLO1   ,NPCLO2   ,HUCOE    ,HUTIL    ,&
 & QSNEBC   ,QSNEBS   ,QSSUSC   ,QSSUSS   ,QSUSXC   ,&
 & QSUSXS  
USE YOMPHY2  , ONLY : TSPHY
USE YOMPHY3  , ONLY : RII0
USE YOMGEM   , ONLY : VALH     ,VBH
USE YOMSIMPHL, ONLY : LCLOUDS  ,LSMOOTHA

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)    :: KTDIA 
INTEGER(KIND=JPIM)               :: KJN ! Argument NOT used
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRSF5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQ5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDELP5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDELP5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PFPLC5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRSF(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQ(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDELP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDELP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PFPLC(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALB(KLON) 
REAL(KIND=JPRB)                  :: PEMIS(KLON) ! Argument NOT used
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMU0(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTS(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAC(KLEV+1,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOR(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAB3C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAB3N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAB4C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAB4N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAB6C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAB6N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAT1C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAT1N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAT2C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAT2N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAT3C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAT3N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAT4C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAT4N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAT5C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAT5N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRSO5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRTH5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRSO(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRTH(KLON,0:KLEV) 
CHARACTER(LEN=7)  ,INTENT(IN)    :: CDLOCK 
!     ------------------------------------------------------------------

REAL(KIND=JPRB) :: ZPAC(0:KLEV,0:KLEV)

REAL(KIND=JPRB) :: ZAB3(KLON,KLEV),ZAB4(KLON,KLEV),ZAB6(KLON,KLEV)&
 & ,ZAT1(KLON,KLEV),ZAT2(KLON,KLEV),ZAT3(KLON,KLEV)&
 & ,ZAT4(KLON,KLEV),ZAT5(KLON,KLEV)  

REAL(KIND=JPRB) :: ZNEBEQ(KLON,0:KLEV,0:KLEV),ZAN(KLON,0:KLEV,0:KLEV)
REAL(KIND=JPRB) :: ZBC(0:KLEV,0:KLEV)

REAL(KIND=JPRB) :: ZFLS(KLON,0:KLEV),ZFLF(KLON,0:KLEV)&
 & ,ZFLM(KLON,0:KLEV),ZZBB(KLON,0:KLEV),ZZNEB(KLON,0:KLEV)  
REAL(KIND=JPRB) :: ZNEB(KLON,KLEV),ZQSAT(KLON,KLEV),ZNBSB(KLON,KLEV),ZNBST(KLON,KLEV)
REAL(KIND=JPRB) :: ZHUC(KLEV)
REAL(KIND=JPRB) :: ZALP(KLON)
REAL(KIND=JPRB) :: ZSUM1(KLON),ZSUM2(KLON)&
 & ,ZZSUM(KLON),ZBX1(KLON),ZBX2(KLON),ZBX3(KLON)  
REAL(KIND=JPRB) :: ZAB35(KLON,KLEV),ZAB45(KLON,KLEV),ZAB65(KLON,KLEV)&
 & ,ZAT15(KLON,KLEV),ZAT25(KLON,KLEV),ZAT35(KLON,KLEV)&
 & ,ZAT45(KLON,KLEV),ZAT55(KLON,KLEV)  

REAL(KIND=JPRB) :: ZNEBEQ5(KLON,0:KLEV,0:KLEV),ZAN5(KLON,0:KLEV,0:KLEV)
REAL(KIND=JPRB) :: ZFLS5(KLON,0:KLEV),ZFLF5(KLON,0:KLEV)&
 & ,ZFLM5(KLON,0:KLEV),ZZBB5(KLON,0:KLEV),ZZNEB5(KLON,0:KLEV)  
REAL(KIND=JPRB) :: ZNEB5(KLON,KLEV)&
 & ,ZQSAT5(KLON,KLEV),ZNBSB5(KLON,KLEV),ZNBST5(KLON,KLEV)  
REAL(KIND=JPRB) :: ZSUM15(KLON),ZSUM25(KLON),ZZSUM5(KLON),ZBX15(KLON)&
 & ,ZBX25(KLON),ZBX35(KLON)  
REAL(KIND=JPRB) :: ZVETAF(KLEV),ZVETAH(0:KLEV)

INTEGER(KIND=JPIM) :: I_KIFDIA(KJN),I_KIIDIA(KJN)

INTEGER(KIND=JPIM) :: IAUCR, JJ, JK, JLEV, JLON, JN

LOGICAL :: LLFDIA, LLIDIA

REAL(KIND=JPRB) :: ZALPHA, ZDELTA, ZEPS1, ZEPSNEB, ZESP1, ZESP15,&
 & ZEW1, ZEW15, ZNEBC, ZNEBC5, ZNEBS, ZNEBS5, &
 & ZQSC, ZQSC5, ZQSS, ZQSS5, ZSUM3, ZSUM4, ZZNC, &
 & ZZNC5, ZZNS1, ZZNS15, ZZNS2, ZZNS25  
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

#include "fcttrm.h"
#include "fcttrmtl.h"

!     CHECK RELIABILITY OF INPUT ARGUMENTS.

IF (LHOOK) CALL DR_HOOK('ACRADSTL',0,ZHOOK_HANDLE)
IF(CDLOCK /= 'RADSTL ') CALL ABOR1('BAD NUMBER OF ARGUMENTS!')

!*
!     ------------------------------------------------------------------
!     I. 1 - COMPUTATION OF DERIVED PARAMETERS, SECURITY CONSTANTS

ZEPS1=1.E-12_JPRB
ZEPSNEB=1.E-10_JPRB
ZALPHA=2.0_JPRB/3._JPRB

!*
!     -------------------------------------------------------------------
!     I. 2 - COMPUTATION OF SPECIFIC HUMIDITY OF SATURATION

! - TEMPORARY 2D.

! ZQSAT    : SPECIFIC HUMIDITY OF SATURATION

! The same but for trajectory
! ---------------------------
! ZQSAT5   : SPECIFIC HUMIDITY OF SATURATION

IF (LCLOUDS) THEN
  DO JLEV=KTDIA,KLEV
    DO JLON=KIDIA,KFDIA

!       SNOW OPTION DEPENDENT COMPUTATIONS.

      IF (LNEIGE) THEN
        ZDELTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,RTT-PT5(JLON,JLEV)))
      ELSE
        ZDELTA=0.0_JPRB
      ENDIF

!       COMPUTATION OF Qsat(PT)

      ZEW15=FOEW(PT5(JLON,JLEV),ZDELTA)
      ZEW1=FOEWTL(PT(JLON,JLEV),PT5(JLON,JLEV),ZDELTA)

      ZESP15=ZEW15/PAPRSF5(JLON,JLEV)
      ZESP1=ZEW1/PAPRSF5(JLON,JLEV)&
       & -(ZEW15/PAPRSF5(JLON,JLEV)**2)*PAPRSF(JLON,JLEV)  

      ZQSAT5(JLON,JLEV)= FOQS (ZESP15)
      IF ((1.0_JPRB-ZESP15) > 0.0_JPRB) THEN
        ZQSAT(JLON,JLEV)= FOQSTL1 (ZESP1,ZESP15)
      ELSE
        ZQSAT(JLON,JLEV)= FOQSTL2 (ZESP1,ZESP15)
      ENDIF
    ENDDO
  ENDDO
ENDIF

!*
!     ------------------------------------------------------------------
!     II - COMPUTATION OF DAY/NIGHT LIMITS.

! - TEMPORARY(S) 1D .

! KIIDIA     : ARRAY OF INDICES OF BEGINNING OF "DAYLIGHT" INTERVALS.
! KIFDIA     : ARRAY OF INDICES OF END OF "DAYLIGHT" INTERVALS.

IAUCR=0
LLIDIA=PMU0(KIDIA) > 0.0_JPRB
LLFDIA=.FALSE.

IF (LLIDIA) THEN
  IAUCR=1
  I_KIIDIA(1)=KIDIA
ENDIF

!     NON VECTORIZED LOOP.

DO JLON=KIDIA,KFDIA
  LLFDIA=PMU0(JLON) > 0.0_JPRB

  IF (LLFDIA.NEQV.LLIDIA) THEN

    IF (LLFDIA) THEN
      IAUCR=IAUCR+1
      I_KIIDIA(IAUCR)=JLON
    ELSE
      I_KIFDIA(IAUCR)=JLON-1
    ENDIF

    LLIDIA=LLFDIA
  ENDIF

ENDDO

IF (LLFDIA) THEN
  I_KIFDIA(IAUCR)=KFDIA
ENDIF

!*
!     ------------------------------------------------------------------
!     III - COMPUTATION OF THE CLOUDINES OF EACH LAYER

! - TEMPORARY 2D

! ZNEB       : FRACTIONAL CLOUDINESS FOR RADIATION.

! The same but for trajectory
! ---------------------------
! ZNEB5      : FRACTIONAL CLOUDINESS FOR RADIATION.

! - TEMPORARY 1D (KLEV)

! ZHUC       : CRITICAL MOISTURE FOR EACH LEVEL FOR ZNEB CALCULATION

IF (LCLOUDS) THEN

!        CRITICAL HUMIDITY

  ZVETAH(0)=VALH(0)+VBH(0)
  DO JLEV = KTDIA, KLEV
    ZVETAH(JLEV)=VALH(JLEV)+VBH(JLEV)
    ZVETAF(JLEV)=0.5_JPRB*(ZVETAH(JLEV)+ZVETAH(JLEV-1))
    ZHUC(JLEV)=1.0_JPRB-MAX( HUCOE*ZVETAF(JLEV)**NPCLO1*&
     & (1.0_JPRB-ZVETAF(JLEV))**NPCLO2*&
     & (1.0_JPRB+SQRT(HUTIL)*(ZVETAF(JLEV)-0.5_JPRB)),ZEPS1)  

  ENDDO

  DO JLEV=KTDIA,KLEV
    DO JLON=KIDIA,KFDIA

!           III. 1 - STRATIFORM PART
!                    ---------------

      ZQSS5=QSSUSS*MAX(0.0_JPRB,PQ5(JLON,JLEV)-ZHUC(JLEV)*ZQSAT5(JLON,JLEV))
      IF((PQ5(JLON,JLEV)-ZHUC(JLEV)*ZQSAT5(JLON,JLEV)) > 0.0_JPRB)THEN
        ZQSS=QSSUSS*(PQ(JLON,JLEV)-ZHUC(JLEV)*ZQSAT(JLON,JLEV))
      ELSE
        ZQSS=0.0_JPRB
      ENDIF

      ZQSS=EXP(-ZQSS5/QSUSXS)*ZQSS
      ZQSS5=QSUSXS*(1.0_JPRB-EXP(-ZQSS5/QSUSXS))

      ZNEBS5=MAX(ZEPSNEB,MIN(1.0_JPRB-ZEPSNEB,QSNEBS &
       & *SQRT(MAX(0.0_JPRB,ZQSS5/ZQSAT5(JLON,JLEV)))))  
      IF ((ZQSS5/ZQSAT5(JLON,JLEV)) > 0.0_JPRB) THEN
        ZZNS15=SQRT(ZQSS5/ZQSAT5(JLON,JLEV))
        ZZNS1=(0.5_JPRB*SQRT(ZQSS5/ZQSAT5(JLON,JLEV))/ZQSS5)&
         & *(ZQSS-(ZQSS5/ZQSAT5(JLON,JLEV))*ZQSAT(JLON,JLEV))  
      ELSE
        ZZNS15=0.0_JPRB
        ZZNS1=0.0_JPRB
      ENDIF
      IF ((QSNEBS*ZZNS15) < (1.0_JPRB-ZEPSNEB)) THEN
        ZZNS25=QSNEBS*ZZNS15
        ZZNS2=QSNEBS*ZZNS1
      ELSE
        ZZNS25=1.0_JPRB-ZEPSNEB
        ZZNS2=0.0_JPRB
      ENDIF
      IF (ZZNS25 > ZEPSNEB) THEN
        ZNEBS=ZZNS2
      ELSE
        ZNEBS=0.0_JPRB
      ENDIF

!           III. 2 - CONVECTIVE PART
!                    ---------------

      ZQSC5=MAX(0.0_JPRB,PFPLC5(JLON,JLEV)-PFPLC5(JLON,JLEV-1))&
       & *PRDELP5(JLON,JLEV)*RG*QSSUSC*TSPHY  
      IF ((PFPLC5(JLON,JLEV)-PFPLC5(JLON,JLEV-1)) > 0.0_JPRB) THEN
        ZQSC=RG*QSSUSC*TSPHY &
         & *(PFPLC5(JLON,JLEV)-PFPLC5(JLON,JLEV-1))&
         & *PRDELP(JLON,JLEV)&
         & +RG*QSSUSC*TSPHY*PRDELP5(JLON,JLEV)*PFPLC(JLON,JLEV)&
         & -RG*QSSUSC*TSPHY*PRDELP5(JLON,JLEV)*PFPLC(JLON,JLEV-1)  
      ELSE
        ZQSC=0.0_JPRB
      ENDIF

      ZQSC=EXP(-ZQSC5/QSUSXC)*ZQSC
      ZQSC5=QSUSXC*(1.0_JPRB-EXP(-ZQSC5/QSUSXC))

      ZNEBC5=MAX(ZEPSNEB,MIN(1.0_JPRB-ZEPSNEB,QSNEBC*ZQSC5))
      IF ((QSNEBC*ZQSC5) < (1.0_JPRB-ZEPSNEB)) THEN
        ZZNC5=QSNEBC*ZQSC5
        ZZNC=QSNEBC*ZQSC
      ELSE
        ZZNC5=1.0_JPRB-ZEPSNEB
        ZZNC=0.0_JPRB
      ENDIF
      IF (ZZNC5 > ZEPSNEB) THEN
        ZNEBC=ZZNC
      ELSE
        ZNEBC=0.0_JPRB
      ENDIF

!           III. 3 - TOTAL
!                    -----

      ZNEB5(JLON,JLEV)=ZNEBS5+(1.0_JPRB-ZNEBS5)*ZNEBC5
      IF (LSMOOTHA) THEN
        ZNEB(JLON,JLEV)=0.0_JPRB
      ELSE
        ZNEB(JLON,JLEV)=ZNEBS+(1.0_JPRB-ZNEBS5)*ZNEBC-ZNEBC5*ZNEBS
      ENDIF
    ENDDO
  ENDDO
ELSE
  ZNEB5(:,:)=0.0_JPRB
  ZNEB(:,:)=0.0_JPRB
ENDIF

!*
!    -------------------------------------------------------------------
!     IV - COMPUTATION OF THERMAL RADIATION

!*
!    -------------------------------------------------------------------
!    IV. 1 - COMPUTATION OF EQUIVALENT CLOUDINESS FOR THERMAL
!            RADIATION

! - TEMPORARY(S) 3D (0:KLEV,0:KLEV)

!   ZNEBEQ    : EQUIVALENT CLOUDINESS FOR THERMAL RADIATION

! The same but for trajectory
! ---------------------------
!   ZNEBEQ5   : EQUIVALENT CLOUDINESS FOR THERMAL RADIATION

IF (LCLOUDS) THEN
  DO JLON=KIDIA,KFDIA
    ZZNEB5(JLON,KLEV)=0.0_JPRB
    ZZNEB(JLON,KLEV)=0.0_JPRB
  ENDDO

  DO JLEV=KTDIA-1,KLEV-1
    DO JLON=KIDIA,KFDIA
      ZZNEB5(JLON,JLEV)=ZNEB5(JLON,JLEV+1)*PCOR(JLON,JLEV+1)
      ZZNEB(JLON,JLEV)=ZNEB(JLON,JLEV+1)*PCOR(JLON,JLEV+1)
    ENDDO
  ENDDO

  DO JLEV=KTDIA-1,KLEV
    DO JLON=KIDIA,KFDIA
      ZSUM15(JLON)=1.0_JPRB-ZZNEB5(JLON,JLEV)
      ZSUM1(JLON)=-ZZNEB(JLON,JLEV)

      ZNEBEQ5(JLON,JLEV,JLEV)=ZSUM15(JLON)
      ZNEBEQ(JLON,JLEV,JLEV)=ZSUM1(JLON)

      ZSUM25(JLON)=1.0_JPRB-ZZNEB5(JLON,JLEV)
      ZSUM2(JLON)=-ZZNEB(JLON,JLEV)
    ENDDO

    DO JJ=JLEV+1,KLEV
      DO JLON=KIDIA,KFDIA
        ZSUM1(JLON)=(1.0_JPRB-ZZNEB5(JLON,JJ))*ZSUM1(JLON)&
         & -ZSUM15(JLON)*ZZNEB(JLON,JJ)  
        ZSUM15(JLON)=ZSUM15(JLON)*(1.0_JPRB-ZZNEB5(JLON,JJ))

        ZNEBEQ5(JLON,JLEV,JJ)=ZSUM15(JLON)
        ZNEBEQ(JLON,JLEV,JJ)=ZSUM1(JLON)
      ENDDO
    ENDDO

    DO JJ=JLEV-1,KTDIA-1,-1
      DO JLON=KIDIA,KFDIA
        ZSUM2(JLON)=(1.0_JPRB-ZZNEB5(JLON,JJ))*ZSUM2(JLON)&
         & -ZSUM25(JLON)*ZZNEB(JLON,JJ)  
        ZSUM25(JLON)=ZSUM25(JLON)*(1.0_JPRB-ZZNEB5(JLON,JJ))

        ZNEBEQ5(JLON,JLEV,JJ)=ZSUM25(JLON)
        ZNEBEQ(JLON,JLEV,JJ)=ZSUM2(JLON)
      ENDDO
    ENDDO
  ENDDO
ELSE
  ZZNEB5(:,:)=0.0_JPRB
  ZZNEB(:,:)=0.0_JPRB

  ZNEBEQ5(:,:,:)=1.0_JPRB
  ZNEBEQ(:,:,:)=0.0_JPRB
ENDIF

!*
!     -------------------------------------------------------------------
!     IV. 2 - COMPUTATION OF COEFFICIENTS OF MATRIX Bc

! - TEMPORARY(S) 2D (0:KLEV,0:KLEV)

! ZBC    : MATRIX Bc

ZBC(:,:)=0.0_JPRB

DO JJ=1,KLEV+1
  DO JK=1,KLEV+1
    ZPAC(JJ-1,JK-1)=PAC(JJ,JK)
  ENDDO
ENDDO

DO JLEV=KTDIA,KLEV
  ZSUM3=0.0_JPRB

  DO JJ=JLEV-1,KTDIA-1,-1
    ZSUM3=ZSUM3+ZPAC(JLEV,JJ)
    ZBC(JLEV,JJ)=1.0_JPRB-ZSUM3
  ENDDO
ENDDO

DO JLEV=KTDIA-1,KLEV
  ZSUM4=0.0_JPRB

  DO JJ=JLEV,KLEV
    ZSUM4=ZSUM4+ZPAC(JLEV,JJ)
    ZBC(JLEV,JJ)=-(1.0_JPRB+ZSUM4)
  ENDDO
ENDDO

!*
!     -------------------------------------------------------------------
!     IV. 3 - COMPUTATION OF COEFFICIENTS OF MATRIX An AS A FUNCTION
!             OF MATRIX Ac (FOR CLEAR AIR) AND CLOUDINESS

! - TEMPORARY(S) 3D (0:KLEV,0:KLEV)

! ZAN    : COURTIS MATRIX FOR THERMAL RADIATION FOR CLOUDY ATMOSPHERE

! The same but for trajectory
! ---------------------------
! ZAN5   : COURTIS MATRIX FOR SOLAR RADIATION FOR CLOUDY ATMOSPHERE

DO JLEV=KTDIA-1,KLEV
  DO JK=KTDIA-1,KLEV
    DO JLON=KIDIA,KFDIA

      ZAN5(JLON,JLEV,JK)=ZNEBEQ5(JLON,JLEV,JK)*(ZPAC(JLEV,JK)&
       & +ZZNEB5(JLON,JK)*ZBC(JLEV,JK))  
      ZAN(JLON,JLEV,JK)=(ZPAC(JLEV,JK)+ZZNEB5(JLON,JK)&
       & *ZBC(JLEV,JK))*ZNEBEQ(JLON,JLEV,JK)&
       & +ZBC(JLEV,JK)*ZNEBEQ5(JLON,JLEV,JK)&
       & *ZZNEB(JLON,JK)  
    ENDDO
  ENDDO
ENDDO

!*
!     ------------------------------------------------------------------
!     IV. 4 - COMPUTATION OF THE BLACK-BODY FLUXES AT THE TOP OF LAYERS
!     (ASSUMED ISOTHERMAL) BLACK-BODY FLUXES ARE IN A (0:KLEV) ARRAY
!     SINCE THE SOIL IS CONSIDERED TO BE A LAYER OF INFINITE
!     OPTICAL DEPTH.

! - TEMPORARY(S) 2D (0:KLEV) .

! ZZBB      : BLACK-BODY FLUX AT THE TOP OF THE LAYERS.

! The same but for trajectory
! ---------------------------
! ZZBB5     : BLACK-BODY FLUX AT THE TOP OF THE LAYERS.

!     BLACK-BODY FLUX.

DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA
    ZZBB5(JLON,JLEV-1)=RSIGMA*(PT5(JLON,JLEV)*PT5(JLON,JLEV))&
     & *(PT5(JLON,JLEV)*PT5(JLON,JLEV))  
    ZZBB(JLON,JLEV-1)=RSIGMA*4._JPRB*(PT5(JLON,JLEV)*PT5(JLON,JLEV))&
     & *PT5(JLON,JLEV)*PT(JLON,JLEV)  
  ENDDO
ENDDO
DO JLON=KIDIA,KFDIA
  ZZBB5(JLON,KLEV)=RSIGMA*(PTS(JLON)*PTS(JLON))*(PTS(JLON)*PTS(JLON))
  ZZBB(JLON,KLEV)=0.0_JPRB
ENDDO

!*
!     ------------------------------------------------------------------
!     IV.5    COMPUTATION OF THE FINAL LONG-WAVE RADIATIVE FLUXES.

DO JLEV=KTDIA-1,KLEV
  DO JLON=KIDIA,KFDIA
    ZZSUM5(JLON)=0.0_JPRB
    ZZSUM(JLON)=0.0_JPRB
  ENDDO

  DO JJ=KTDIA-1,KLEV
    DO JLON=KIDIA,KFDIA
      ZZSUM5(JLON)=ZZSUM5(JLON)+ZAN5(JLON,JLEV,JJ)*ZZBB5(JLON,JJ)
      ZZSUM(JLON)=ZZSUM(JLON)+ZAN5(JLON,JLEV,JJ)*ZZBB(JLON,JJ)&
       & +ZZBB5(JLON,JJ)*ZAN(JLON,JLEV,JJ)  
    ENDDO
  ENDDO

  DO JLON=KIDIA,KFDIA
    PFRTH5(JLON,JLEV)=ZZSUM5(JLON)
    PFRTH(JLON,JLEV)=ZZSUM(JLON)
  ENDDO
ENDDO

!*
!     ------------------------------------------------------------------

!     V - COMPUTATION OF THE SOLAR ANGLE DEPENDENT ARRAYS AND OF THE
!     EFFECTIVE SURFACE ALBEDO.

!     INVERSE OF THE COSINE OF THE ZENITH ANGLE AND UPSCATTERED
!     FRACTIONS.

! - TEMPORARY(S) 1D .

! ZALP      : ALBEDO OF THE SURFACE FOR PARALLEL FLUX

DO JN=1,IAUCR
  DO JLON=I_KIIDIA(JN),I_KIFDIA(JN)
    ZALP(JLON)=(1.0_JPRB+0.5_JPRB*(PMU0(JLON)*(1.0_JPRB/PALB(JLON)-1.0_JPRB)))&
     & /(1.0_JPRB+(PMU0(JLON)*(1.0_JPRB/PALB(JLON)-1.0_JPRB)))**2  
  ENDDO
ENDDO

!*
!     ------------------------------------------------------------------
!     VI - SOLAR FLUXES' CALCULATION.

!*
!     -------------------------------------------------------------------
!     VI. 1 - COMPUTATION OF EQUIVALENT CLOUDINESS FOR SOLAR
!             RADIATION

! - TEMPORARY(S) 2D (1:KLEV)

! ZNBST    : THE EQUIVALENT CLOUDINESS OF THE LAYERS 1,...,JK
! ZNBSB    : THE EQUIVALENT CLOUDINESS OF THE LAYERS JK,...,NK

! The same but for trajectory
! ---------------------------
! ZNBST5   : THE EQUIVALENT CLOUDINESS OF THE LAYERS 1,...,JK
! ZNBSB5   : THE EQUIVALENT CLOUDINESS OF THE LAYERS JK,...,NK

IF (LCLOUDS) THEN
  DO JLEV=KTDIA,KLEV
    DO JLON=KIDIA,KFDIA
      ZBX15(JLON)=1.0_JPRB-ZNEB5(JLON,KTDIA)
      ZBX1(JLON)=-ZNEB(JLON,KTDIA)

      ZBX25(JLON)=ZNEB5(JLON,KTDIA)*PDELP5(JLON,KTDIA)
      ZBX2(JLON)=ZNEB5(JLON,KTDIA)*PDELP(JLON,KTDIA)&
       & +PDELP5(JLON,KTDIA)*ZNEB(JLON,KTDIA)  

      ZBX35(JLON)=PDELP5(JLON,KTDIA)
      ZBX3(JLON)=PDELP(JLON,KTDIA)
    ENDDO

    DO JJ=KTDIA+1,JLEV
      DO JLON=KIDIA,KFDIA
        ZBX1(JLON)=(1.0_JPRB-ZNEB5(JLON,JJ))*ZBX1(JLON)&
         & -ZBX15(JLON)*ZNEB(JLON,JJ)  
        ZBX15(JLON)=ZBX15(JLON)*(1.0_JPRB-ZNEB5(JLON,JJ))

        ZBX25(JLON)=ZBX25(JLON)+ZNEB5(JLON,JJ)*PDELP5(JLON,JJ)
        ZBX2(JLON)=ZBX2(JLON)+ZNEB5(JLON,JJ)*PDELP(JLON,JJ)&
         & +PDELP5(JLON,JJ)*ZNEB(JLON,JJ)  

        ZBX35(JLON)=ZBX35(JLON)+PDELP5(JLON,JJ)
        ZBX3(JLON)=ZBX3(JLON)+PDELP(JLON,JJ)
      ENDDO
    ENDDO

    DO JLON=KIDIA,KFDIA
      ZNBST5(JLON,JLEV)=ZALPHA*(1.0_JPRB-ZBX15(JLON))&
       & +(1.0_JPRB-ZALPHA)*ZBX25(JLON)/ZBX35(JLON)  
      ZNBST(JLON,JLEV)=-ZALPHA*ZBX1(JLON)&
       & +((1.0_JPRB-ZALPHA)/ZBX35(JLON))*ZBX2(JLON)&
       & -((1.0_JPRB-ZALPHA)*ZBX25(JLON)/ZBX35(JLON)**2)*ZBX3(JLON)  
    ENDDO
  ENDDO

  DO JLEV=KTDIA,KLEV-1
    DO JLON=KIDIA,KFDIA
      ZBX15(JLON)=1.0_JPRB-ZNEB5(JLON,JLEV+1)
      ZBX1(JLON)=-ZNEB(JLON,JLEV+1)

      ZBX25(JLON)=ZNEB5(JLON,JLEV+1)*PDELP5(JLON,JLEV+1)
      ZBX2(JLON)=ZNEB5(JLON,JLEV+1)*PDELP(JLON,JLEV+1)&
       & +PDELP5(JLON,JLEV+1)*ZNEB(JLON,JLEV+1)  

      ZBX35(JLON)=PDELP5(JLON,JLEV+1)
      ZBX3(JLON)=PDELP(JLON,JLEV+1)
    ENDDO

    DO JJ=JLEV+2,KLEV
      DO JLON=KIDIA,KFDIA
        ZBX1(JLON)=(1.0_JPRB-ZNEB5(JLON,JJ))*ZBX1(JLON)&
         & -ZBX15(JLON)*ZNEB(JLON,JJ)  
        ZBX15(JLON)=ZBX15(JLON)*(1.0_JPRB-ZNEB5(JLON,JJ))

        ZBX25(JLON)=ZBX25(JLON)+ZNEB5(JLON,JJ)*PDELP5(JLON,JJ)
        ZBX2(JLON)=ZBX2(JLON)+ZNEB5(JLON,JJ)*PDELP(JLON,JJ)&
         & +PDELP5(JLON,JJ)*ZNEB(JLON,JJ)  

        ZBX35(JLON)=ZBX35(JLON)+PDELP5(JLON,JJ)
        ZBX3(JLON)=ZBX3(JLON)+PDELP(JLON,JJ)
      ENDDO
    ENDDO

    DO JLON=KIDIA,KFDIA
      ZNBSB5(JLON,JLEV)=ZALPHA*(1.0_JPRB-ZBX15(JLON))&
       & +(1.0_JPRB-ZALPHA)*ZBX25(JLON)/ZBX35(JLON)  
      ZNBSB(JLON,JLEV)=-ZALPHA*ZBX1(JLON)&
       & +((1.0_JPRB-ZALPHA)/ZBX35(JLON))*ZBX2(JLON)&
       & -((1.0_JPRB-ZALPHA)*ZBX25(JLON)/ZBX35(JLON)**2)*ZBX3(JLON)  
    ENDDO
  ENDDO

  DO JLON=KIDIA,KFDIA
    ZNBSB5(JLON,KLEV)=ZNEB5(JLON,KLEV)
    ZNBSB(JLON,KLEV)=ZNEB(JLON,KLEV)
  ENDDO
ELSE
  ZNBST5(:,:)=0.0_JPRB
  ZNBST(:,:)=0.0_JPRB

  ZNBSB5(:,:)=0.0_JPRB
  ZNBSB(:,:)=0.0_JPRB
ENDIF

!*
!     --------------------------------------------------------------------
!     VI. 2 - COMPUTATION OF EQUIVALENT COEFFICIENTS a1c,...,a6c (FOR
!             CLEAR AIR) AND a1n,...,a6n (FOR CLOUD ~ LIQUID WATER) AS
!             A FUNCTION OF CLOUDINESS

! - TEMPORARY(S) 2D (1:KLEV)
!                                            ---
! ZAB3     : PARALLEL/DIFFUSE REFLECTIVITY.     | equivalent coefficients
! ZAB4     : DIFFUSE TRANSMISSIVITY.            | from bottom
! ZAB6     : DIFFUSE REFLECTIVITY.           ---  to given level

! ZAT1     : PARALLEL TRANSMISSIVITY.        ---  equivalent
! ZAT2     : PARALLEL/DIFFUSE TRANSMISSIVITY.   | coefficients
! ZAT3     : PARALLEL/DIFFUSE REFLECTIVITY.     | from top
! ZAT4     : DIFFUSE TRANSMISSIVITY.            | to given
! ZAT5     : DIFFUSE REFLECTIVITY.           ---  level

! The same but for trajectory
! ---------------------------
! ZAB35    : PARALLEL/DIFFUSE REFLECTIVITY.     | equivalent coefficients
! ZAB45    : DIFFUSE TRANSMISSIVITY.            | from bottom
! ZAB65    : DIFFUSE REFLECTIVITY.           ---  to given level

! ZAT15    : PARALLEL TRANSMISSIVITY.        ---  equivalent
! ZAT25    : PARALLEL/DIFFUSE TRANSMISSIVITY.   | coefficients
! ZAT35    : PARALLEL/DIFFUSE REFLECTIVITY.     | from top
! ZAT45    : DIFFUSE TRANSMISSIVITY.            | to given
! ZAT55    : DIFFUSE REFLECTIVITY.           ---  level

DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA

    ZAB35(JLON,JLEV)=(1.0_JPRB-ZNBSB5(JLON,JLEV))*PRAB3C(JLON,JLEV)&
     & +ZNBSB5(JLON,JLEV)*PRAB3N(JLON,JLEV)  
    ZAB3(JLON,JLEV)=(PRAB3N(JLON,JLEV)-PRAB3C(JLON,JLEV))*ZNBSB(JLON,JLEV)

    ZAB45(JLON,JLEV)=(1.0_JPRB-ZNBSB5(JLON,JLEV))*PRAB4C(JLON,JLEV)&
     & +ZNBSB5(JLON,JLEV)*PRAB4N(JLON,JLEV)  
    ZAB4(JLON,JLEV)=(PRAB4N(JLON,JLEV)-PRAB4C(JLON,JLEV))*ZNBSB(JLON,JLEV)

    ZAB65(JLON,JLEV)=(1.0_JPRB-ZNBSB5(JLON,JLEV))*PRAB6C(JLON,JLEV)&
     & +ZNBSB5(JLON,JLEV)*PRAB6N(JLON,JLEV)  
    ZAB6(JLON,JLEV)=(PRAB6N(JLON,JLEV)-PRAB6C(JLON,JLEV))*ZNBSB(JLON,JLEV)

    ZAT15(JLON,JLEV)=(1.0_JPRB-ZNBST5(JLON,JLEV))*PRAT1C(JLON,JLEV)&
     & +ZNBST5(JLON,JLEV)*PRAT1N(JLON,JLEV)  
    ZAT1(JLON,JLEV)=(PRAT1N(JLON,JLEV)-PRAT1C(JLON,JLEV))*ZNBST(JLON,JLEV)

    ZAT25(JLON,JLEV)=(1.0_JPRB-ZNBST5(JLON,JLEV))*PRAT2C(JLON,JLEV)&
     & +ZNBST5(JLON,JLEV)*PRAT2N(JLON,JLEV)  
    ZAT2(JLON,JLEV)=(PRAT2N(JLON,JLEV)-PRAT2C(JLON,JLEV))*ZNBST(JLON,JLEV)

    ZAT35(JLON,JLEV)=(1.0_JPRB-ZNBST5(JLON,JLEV))*PRAT3C(JLON,JLEV)&
     & +ZNBST5(JLON,JLEV)*PRAT3N(JLON,JLEV)  
    ZAT3(JLON,JLEV)=(PRAT3N(JLON,JLEV)-PRAT3C(JLON,JLEV))*ZNBST(JLON,JLEV)

    ZAT45(JLON,JLEV)=(1.0_JPRB-ZNBST5(JLON,JLEV))*PRAT4C(JLON,JLEV)&
     & +ZNBST5(JLON,JLEV)*PRAT4N(JLON,JLEV)  
    ZAT4(JLON,JLEV)=(PRAT4N(JLON,JLEV)-PRAT4C(JLON,JLEV))*ZNBST(JLON,JLEV)

    ZAT55(JLON,JLEV)=(1.0_JPRB-ZNBST5(JLON,JLEV))*PRAT5C(JLON,JLEV)&
     & +ZNBST5(JLON,JLEV)*PRAT5N(JLON,JLEV)  
    ZAT5(JLON,JLEV)=(PRAT5N(JLON,JLEV)-PRAT5C(JLON,JLEV))*ZNBST(JLON,JLEV)
  ENDDO
ENDDO

!*
!    --------------------------------------------------------------------
!     VI. 3 - TOP OF THE ATMOSPHERE.

! - TEMPORARY(S) 2D (0:KLEV)

! ZFLS     : DIRECT SOLAR FLUX
! ZFLF     : DIFFUSE DOWNWARD FLUX
! ZFLM     : DIFFUSE UPWARD FLUX

! The same but for trajectory
! ---------------------------
! ZFLS5    : DIRECT SOLAR FLUX
! ZFLF5    : DIFFUSE DOWNWARD FLUX
! ZFLM5    : DIFFUSE UPWARD FLUX

DO JN=1,IAUCR
  DO JLON=I_KIIDIA(JN),I_KIFDIA(JN)
    ZFLS5(JLON,KTDIA-1)=RII0*PMU0(JLON)
    ZFLS(JLON,KTDIA-1)=0.0_JPRB

    ZFLF5(JLON,KTDIA-1)=0.0_JPRB
    ZFLF(JLON,KTDIA-1)=0.0_JPRB

  ENDDO
ENDDO

!     -------------------------------------------------------------------
!     VI.4   SURFACE TREATMENT AND DIFFUSE UPWARD FLUX AT THE TOP
!             OF ATMOSPHERE

DO JN=1,IAUCR
  DO JLON=I_KIIDIA(JN),I_KIFDIA(JN)
    ZFLS5(JLON,KLEV)=ZAT15(JLON,KLEV)*ZFLS5(JLON,KTDIA-1)
    ZFLS(JLON,KLEV)=ZAT15(JLON,KLEV)*ZFLS(JLON,KTDIA-1)&
     & +ZFLS5(JLON,KTDIA-1)*ZAT1(JLON,KLEV)  

    ZFLF5(JLON,KLEV)=(ZAT25(JLON,KLEV)&
     & +ZAT55(JLON,KLEV)*ZAT15(JLON,KLEV)*PALB(JLON))&
     & *ZFLS5(JLON,KTDIA-1)&
     & /(1.0_JPRB-ZAT55(JLON,KLEV)*ZALP(JLON))  
    ZFLF(JLON,KLEV)=((ZAT25(JLON,KLEV)&
     & +ZAT55(JLON,KLEV)*ZAT15(JLON,KLEV)*PALB(JLON))&
     & /(1.0_JPRB-ZAT55(JLON,KLEV)*ZALP(JLON)))&
     & *ZFLS(JLON,KTDIA-1)&
     & +(ZFLS5(JLON,KTDIA-1)&
     & /(1.0_JPRB-ZAT55(JLON,KLEV)*ZALP(JLON)))*ZAT2(JLON,KLEV)&
     & +(PALB(JLON)*ZAT55(JLON,KLEV)*ZFLS5(JLON,KTDIA-1)&
     & /(1.0_JPRB-ZAT55(JLON,KLEV)*ZALP(JLON)))*ZAT1(JLON,KLEV)&
     & +((PALB(JLON)*ZFLS5(JLON,KTDIA-1)*ZAT15(JLON,KLEV)&
     & +ZALP(JLON)*ZFLS5(JLON,KTDIA-1)*ZAT25(JLON,KLEV))&
     & /(1.0_JPRB-ZAT55(JLON,KLEV)*ZALP(JLON))**2)&
     & *ZAT5(JLON,KLEV)  

    ZFLM5(JLON,KLEV)=PALB(JLON)*ZFLS5(JLON,KLEV)+ZALP(JLON)*ZFLF5(JLON,KLEV)
    ZFLM(JLON,KLEV)=PALB(JLON)*ZFLS(JLON,KLEV)+ZALP(JLON)*ZFLF(JLON,KLEV)

    ZFLM5(JLON,KTDIA-1)=ZAT35(JLON,KLEV)*ZFLS5(JLON,KTDIA-1)&
     & +ZAT45(JLON,KLEV)*ZFLM5(JLON,KLEV)  
    ZFLM(JLON,KTDIA-1)=ZAT35(JLON,KLEV)*ZFLS(JLON,KTDIA-1)&
     & +ZFLS5(JLON,KTDIA-1)*ZAT3(JLON,KLEV)&
     & +ZAT45(JLON,KLEV)*ZFLM(JLON,KLEV)&
     & +ZFLM5(JLON,KLEV)*ZAT4(JLON,KLEV)  
  ENDDO
ENDDO

!*
!     --------------------------------------------------------------------
!     VI.5   LOOP OVER THE LAYERS

DO JLEV=KTDIA,KLEV-1
  DO JN=1,IAUCR
    DO JLON=I_KIIDIA(JN),I_KIFDIA(JN)

      ZFLS5(JLON,JLEV)=ZAT15(JLON,JLEV)*ZFLS5(JLON,KTDIA-1)
      ZFLS(JLON,JLEV)=ZAT15(JLON,JLEV)*ZFLS(JLON,KTDIA-1)&
       & +ZFLS5(JLON,KTDIA-1)*ZAT1(JLON,JLEV)  

      ZFLM5(JLON,JLEV)=((ZAB35(JLON,JLEV)*ZAT15(JLON,JLEV)&
       & +ZAB65(JLON,JLEV)*ZAT25(JLON,JLEV))&
       & *ZFLS5(JLON,KTDIA-1)&
       & +ZAB45(JLON,JLEV)*ZFLM5(JLON,KLEV))&
       & /(1.0_JPRB-ZAB65(JLON,JLEV)*ZAT55(JLON,JLEV))  
      ZFLM(JLON,JLEV)=((ZAB35(JLON,JLEV)*ZAT15(JLON,JLEV)&
       & +ZAB65(JLON,JLEV)*ZAT25(JLON,JLEV))&
       & /(1.0_JPRB-ZAB65(JLON,JLEV)*ZAT55(JLON,JLEV)))&
       & *ZFLS(JLON,KTDIA-1)&
       & +(ZFLS5(JLON,KTDIA-1)*ZAB35(JLON,JLEV)&
       & /(1.0_JPRB-ZAB65(JLON,JLEV)*ZAT55(JLON,JLEV)))&
       & *ZAT1(JLON,JLEV)&
       & +(ZFLS5(JLON,KTDIA-1)*ZAT15(JLON,JLEV)&
       & /(1.0_JPRB-ZAB65(JLON,JLEV)*ZAT55(JLON,JLEV)))&
       & *ZAB3(JLON,JLEV)&
       & +(ZFLS5(JLON,KTDIA-1)*ZAB65(JLON,JLEV)&
       & /(1.0_JPRB-ZAB65(JLON,JLEV)*ZAT55(JLON,JLEV)))&
       & *ZAT2(JLON,JLEV)&
       & +(ZAB45(JLON,JLEV)/(1.0_JPRB-ZAB65(JLON,JLEV)&
       & *ZAT55(JLON,JLEV)))*ZFLM(JLON,KLEV)&
       & +(ZFLM5(JLON,KLEV)/(1.0_JPRB-ZAB65(JLON,JLEV)&
       & *ZAT55(JLON,JLEV)))*ZAB4(JLON,JLEV)&
       & +(((ZAB35(JLON,JLEV)*ZAT15(JLON,JLEV)&
       & +ZAB65(JLON,JLEV)*ZAT25(JLON,JLEV))&
       & *ZFLS5(JLON,KTDIA-1)&
       & +ZAB45(JLON,JLEV)*ZFLM5(JLON,KLEV))&
       & *ZAB65(JLON,JLEV)/(1.0_JPRB-ZAB65(JLON,JLEV)&
       & *ZAT55(JLON,JLEV))**2)*ZAT5(JLON,JLEV)&
       & +((ZFLS5(JLON,KTDIA-1)*ZAT25(JLON,JLEV)&
       & +ZAB35(JLON,JLEV)*ZAT15(JLON,JLEV)&
       & *ZFLS5(JLON,KTDIA-1)*ZAT55(JLON,JLEV)&
       & +ZAB45(JLON,JLEV)*ZFLM5(JLON,KLEV)&
       & *ZAT55(JLON,JLEV))/(1.0_JPRB-ZAB65(JLON,JLEV)&
       & *ZAT55(JLON,JLEV))**2)*ZAB6(JLON,JLEV)  

      ZFLF5(JLON,JLEV)=ZAT25(JLON,JLEV)*ZFLS5(JLON,KTDIA-1)&
       & +ZAT55(JLON,JLEV)*ZFLM5(JLON,JLEV)  
      ZFLF(JLON,JLEV)=ZAT25(JLON,JLEV)*ZFLS(JLON,KTDIA-1)&
       & +ZFLS5(JLON,KTDIA-1)*ZAT2(JLON,JLEV)&
       & +ZAT55(JLON,JLEV)*ZFLM(JLON,JLEV)&
       & +ZFLM5(JLON,JLEV)*ZAT5(JLON,JLEV)  

    ENDDO
  ENDDO
ENDDO

!*
!     --------------------------------------------------------------------
!     VI.6   FINAL COMPUTATIONS OF SHORTWAVE RADIATIVE FLUX.

DO JLEV=KTDIA-1,KLEV
  DO JN=1,IAUCR
    DO JLON=I_KIIDIA(JN),I_KIFDIA(JN)
      PFRSO5(JLON,JLEV)=ZFLS5(JLON,JLEV)+ZFLF5(JLON,JLEV)-ZFLM5(JLON,JLEV)
      PFRSO(JLON,JLEV)=ZFLS(JLON,JLEV)+ZFLF(JLON,JLEV)-ZFLM(JLON,JLEV)
    ENDDO
  ENDDO
ENDDO

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