!OPTIONS XOPT(NOEVAL)
SUBROUTINE ACRADCOEF ( KIDIA,KFDIA,KLON,KTDIA,KLEV,&
 !-----------------------------------------------------------------------
 ! - INPUT  2D .
 & PAPRS,PAPRSF,PDELP,PNEB,PQ,PQCO2,PQICE,PQLI,&
 & PQO3,PT,&
 ! - INPUT  1D .
 & PMU0,PDHSF,PEMIS,&
 ! - CONSTANTES .
 & PDAER,&
 ! - OUTPUT 2D .
 & POMPAC,PAC,PCOR,&
 & PRAB3C,PRAB3N,PRAB4C,PRAB4N,PRAB6C,PRAB6N,&
 & PRAT1C,PRAT1N,PRAT2C,PRAT2N,PRAT3C,PRAT3N,&
 & PRAT4C,PRAT4N,PRAT5C,PRAT5N,&
 ! - LOCK ARGUMENTS .
 & CDLOCK)  

!**** *ACRADCOEF* - COMPUTATION OF COEFFICIENTS FOR RADIATION.

!     Subject.
!     --------
!     - ROUTINE FOR CALCULATION OF COEFFICIENTS FOR RADIATION:
!       FOR SOLAR RADIATION a1n,...,a6n AND a1c,...,a6c
!     - COMPUTATION OF EQUIVALENT COEFFICIENTS COMBINING LAYERS
!       1 - JK AND JK - NLEV

!**   Interface.
!     ----------
!        *CALL* *ACRADCOEF*

! -   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 (0:KLEV) .

! PAPRS      : PRESSURE ON HALF LEVELS.
! PQO3       : OZONE MIXING RATIO (MASS).
!        (0) : AVERAGED-ABOVE.

! - 2D (1:KLEV) .

! PAPRSF     : PRESSURE ON FULL LEVELS.
! PDELP      : LAYER THICKNESS IN PRESSURE UNITS.
! PNEB       : FRACTIONAL CLOUDINESS FOR RADIATION.
! PQ         : SPECIFIC HUMIDITY OF WATER VAPOUR.
! PQCO2      : CO2 MIXING RATIO (MASS).
! PQICE      : SPECIFIC HUMIDITY OF SOLID WATER FOR RADIATION.
! PQLI       : SPECIFIC HUMIDITY OF LIQUID WATER FOR RADIATION.
! PT         : TEMPERATURE.

! - 1D (PROGNOSTIC)

! PEMIS      : MODEL SURFACE LONGWAVE EMISSIVITY

! - 1D (DIAGNOSTIC) .

! PMU0       : LOCAL COSINE OF INSTANTENOUS SOLAR ZENITH ANGLE.
! PDHSF      : DISTRIBUTION OF HORIZONTAL MEAN WEIGHTS.

! - CONSTANTES .

! PDAER(KLEV): OPTICAL DEPTH OF STANDARD AEROSOLS IN THE LAYER.

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

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

! - CONSTANTES

! POMPAC     : Horizontally variable Curtis matrix for thermal rad. (clear sky)
! PAC        : Horizontally cst Curtis matrix for thermal rad. (clear sky)

! 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.              ---

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

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

! COMMON/YOMPHY3/

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

!     Externes.
!     ---------

!     Methode.
!     --------

!     Auteur.
!     -------
!        89-12, J.F. Geleyn.

!     Modifications.
!     --------------
!        92-04, nuages "glace" pour proprietes physiques - L. Labbe.
!        92-05, ajout diagnostics - C. Dreveton.
!        94-01, nettoyage (albedo, emissivite, ozone) - M. Deque
! -----------
!        96-02, only part of ACRANEB taken for computation of coefficients
!               for solar radiation and computation of equivalent
!               coefficients - M. Janiskova
!        96-06, modification in thermal part of radiation for re-covering
!               of Curtis matrix - M. Janiskova
!        97-08, PZx variables > Zx, introduce CDLOCK - J.M. Piriou.
!        99-02, computation of mean value of matrix for thermal radiation
!               part - M. Janiskova
!        05-01 Replace call to obsolete GATHERSUM with call to MPL_REDUCE
!              - M.Hamrud
!      2002-10, Change definition of PQLI and PQICE: they become grid-size values - J.M. Piriou.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning

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

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

USE YOMPHY3  , ONLY : GCA      ,GCB      ,GCC      ,VDP      ,&
 & VNP      ,BSFSA    ,BSFSI    ,BSFSN    ,BSFTA    ,&
 & BSFTI    ,BSFTN    ,EARRT    ,EOASA    ,EOASI    ,&
 & EOASN    ,EOATA    ,EOATI    ,EOATN    ,EODSA    ,&
 & EODSI    ,EODSN    ,EODTA    ,EODTI    ,EODTN    ,&
 & EORAY    ,GCD4     ,GCE4     ,USAA     ,USAI     ,&
 & USAN     ,USBA     ,USBI     ,USBN  
USE YOMRCOEF , ONLY : LGLOBRAD ,TRWEIGHT ,TRMATSUM
USE YOMCT0   , ONLY : NPROC
USE MPL_MODULE

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 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRS(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRSF(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDELP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNEB(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQ(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQCO2(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQICE(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQLI(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQO3(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMU0(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDHSF(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIS(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDAER(KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: POMPAC(KLON,0:KLEV,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PAC(KLEV+1,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCOR(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAB3C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAB3N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAB4C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAB4N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAB6C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAB6N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAT1C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAT1N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAT2C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAT2N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAT3C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAT3N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAT4C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAT4N(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAT5C(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRAT5N(KLON,KLEV) 
CHARACTER(LEN=7)  ,INTENT(IN)    :: CDLOCK 
REAL(KIND=JPRB) :: ZFRTH(KLON,0:KLEV),ZZBB(KLON,0:KLEV)
REAL(KIND=JPRB) :: ZQLI(KLON,KLEV),ZQICE(KLON,KLEV)

REAL(KIND=JPRB) :: ZZA1C(KLON,KLEV),ZZA1N(KLON,KLEV),ZZA2C(KLON,KLEV)&
 & ,ZZA2N(KLON,KLEV),ZZA3C(KLON,KLEV),ZZA3N(KLON,KLEV)&
 & ,ZZA4C(KLON,KLEV),ZZA4N(KLON,KLEV),ZZA5C(KLON,K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LEV)  
REAL(KIND=JPRB) :: ZRAB1C(KLON,KLEV),ZRAB1N(KLON,KLEV),ZRAB2C(KLON,KLEV)&
 & ,ZRAB2N(KLON,KLEV),ZRAB5C(KLON,KLEV),ZRAB5N(KLON,KLEV)  
REAL(KIND=JPRB) :: ZRAT6C(KLON,KLEV),ZRAT6N(KLON,KLEV)

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

REAL(KIND=JPRB) :: ZAL, ZARGLI, ZDUC, ZDUH, ZDUO, ZEARRT, ZEO,&
 & ZEO1, ZEO1SA, ZEO1SI, ZEO1SN, ZEO1TA, ZEO1TI, &
 & ZEO1TN, ZEO2, ZEO2SA, ZEO2SI, ZEO2SN, ZEO2TA, &
 & ZEO2TI, ZEO2TN, ZEO3, ZEO4, ZEO5, ZEOSA, &
 & ZEOSI, ZEOSN, ZEPS, ZEPS1, ZEPS2, ZEPS3, &
 & ZEPS4, ZG1, ZG2, ZIEART, ZMD, ZMU0IC, ZMU0IN, &
 & ZP, ZPACTOT, ZQ, ZRHO, ZRT, ZSUMW, ZSUMWTOT, &
 & ZT2, ZT2I, ZT3, ZT4I, ZTAU, ZTD1, ZTD4, ZTDETA, &
 & ZTDS1, ZTI, ZWSC, ZWSH, ZWSO, ZWTC, ZWTH, &
 & ZWTO,ZEPSNEB  
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

!     CHECK RELIABILITY OF INPUT ARGUMENTS.

IF (LHOOK) CALL DR_HOOK('ACRADCOEF',0,ZHOOK_HANDLE)
IF(CDLOCK /= 'ACRADCO') CALL ABOR1('BAD NUMBER OF ARGUMENTS!')
!*
!     ------------------------------------------------------------------
!     0 - SET QL AND QI DEFINITIONS TO THEIR VALUE INSIDE THE CLOUD.

ZEPSNEB=1.E-10_JPRB

DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA
    ZQLI(JLON,JLEV)=PQLI(JLON,JLEV)/MAX(ZEPSNEB,PNEB(JLON,JLEV))
    ZQICE(JLON,JLEV)=PQICE(JLON,JLEV)/MAX(ZEPSNEB,PNEB(JLON,JLEV))
  ENDDO
ENDDO

!*
!     ------------------------------------------------------------------
!     I - COMPUTATION OF DERIVED PARAMETERS, SECURITY CONSTANTS (FOR THE
!     PRESSURE THICKNESS OF THE LAYER "ABOVE THE MODEL'S TOP, THE
!     SPECIFIC HUMIDITY AND THE CORRECTION TO AVOID A RESONNANT
!     ANALYTICAL SOLUTION BETWEEN PARALLEL AND SCATTERED RADIATION) AS
!     WELL AS A LIMIT ARGUMENT TO AVOID "UNDERFLOW" IN THE COMPUTATIONS
!     OF TRANSMISSIVITY.

DO JGA=1,6
  ZGAS2B(JGA)=GCA(JGA)/(2.0_JPRB*GCB(JGA))
  ZG4B(JGA)=4._JPRB*GCB(JGA)
ENDDO

ZEO2TA=2.0_JPRB*BSFTA*EODTA
ZEO1TA=ZEO2TA+2.0_JPRB*EOATA
ZEO2TI=2.0_JPRB*BSFTI*EODTI
ZEO1TI=ZEO2TI+2.0_JPRB*EOATI
ZEO2TN=2.0_JPRB*BSFTN*EODTN
ZEO1TN=ZEO2TN+2.0_JPRB*EOATN
ZEO2SA=2.0_JPRB*BSFSA*EODSA
ZEO1SA=ZEO2SA+2.0_JPRB*EOASA
ZEO2SI=2.0_JPRB*BSFSI*EODSI
ZEO1SI=ZEO2SI+2.0_JPRB*EOASI
ZEO2SN=2.0_JPRB*BSFSN*EODSN
ZEO1SN=ZEO2SN+2.0_JPRB*EOASN
ZEOSA=EODSA+EOASA
ZEOSI=EODSI+EOASI
ZEOSN=EODSN+EOASN

ZEPS1=1.E-03_JPRB
ZEPS2=1.E-09_JPRB
ZEPS3=1.E-12_JPRB
ZEPS4=1.E-15_JPRB

ZARGLI=-250._JPRB

!*

!*
!     ------------------------------------------------------------------
!     III - COMPUTATION OF GASEOUS OPTICAL DEPTHS. THE DESCENDING
!     CALCULATIONS ARE SYMETRICAL BETWEEN SOLAR AND THERMAL (EXCEPT FOR
!     THE DIFFUSIVITY FACTOR) BUT THE ASCENDING CALCULATIONS (DIFFUSE IN
!     BOTH CASES) ARE FOR A REFLECTED SOLAR FLUX AND FOR A THERMAL FLUX
!     CORRESPONDING TO THE EXCHANGE WITH THE SURFACE.

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

! ZDEOS     : GASEOUS OPTICAL DEPTH SOLAR DESCENDING.
! ZDEOT     : GASEOUS OPTICAL DEPTH THERMAL DESCENDING.
! ZUEOS     : GASEOUS OPTICAL DEPTH SOLAR ASCENDING.
! ZUEOT     : GASEOUS OPTICAL DEPTH THERMAL ASCENDING.

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     III.1   PRELIMINARY CALCULATIONS.

!     RADIATIVE GEOMETRY.

! - TEMPORARY(S) 1D .

! ZDM0I     : HALF INVERSE OF THE MODIFIED COSINE OF THE ZENITH ANGLE.

ZMD=0.5_JPRB*EXP(0.5_JPRB)
ZEARRT=EARRT*(EARRT+2.0_JPRB)
ZIEART=1.0_JPRB/EARRT
DO JLON=KIDIA,KFDIA
  ZDM0I(JLON)=0.5_JPRB*(SQRT(PMU0(JLON)*PMU0(JLON)+ZEARRT)-PMU0(JLON))*ZIEART
ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     III.2   TOP OF THE MODEL'S ATMOSPHERE (OR ARBITRARILY SMALL
!     PRESSURE VALUE).

! - TEMPORARY(S) 1D .

! ZNSH      : UNREDUCED ABSORBER AMOUNT SOLAR H2O.
! ZNSC      : UNREDUCED ABSORBER AMOUNT SOLAR CO2.
! ZNSO      : UNREDUCED ABSORBER AMOUNT SOLAR O3.
! ZNTH      : UNREDUCED ABSORBER AMOUNT THERMAL H2O.
! ZNTC      : UNREDUCED ABSORBER AMOUNT THERMAL CO2.
! ZNTO      : UNREDUCED ABSORBER AMOUNT THERMAL O3.
! ZRSH      : REDUCED (*P) ABSORBER AMOUNT SOLAR H2O.
! ZRSC      : REDUCED (*P) ABSORBER AMOUNT SOLAR CO2.
! ZRSO      : REDUCED (*P) ABSORBER AMOUNT SOLAR O3.
! ZRTH      : REDUCED (*P) ABSORBER AMOUNT THERMAL H2O (BANDS).
! ZCTH      : REDUCED (*P AND *ES) ABSORBER AMOUNT THERMAL H2O (CONT.).
! ZRTC      : REDUCED (*P) ABSORBER AMOUNT THERMAL CO2.
! ZRTO      : REDUCED (*P) ABSORBER AMOUNT THERMAL O3.
! ZNSOR     : DOUBLED OZONE QUANTITY ABOVE THE CONSIDERED LEVEL.
! ZEOS      : RESULT OF THE SOLAR OPTICAL DEPTH COMPUTATIONS.
! ZEOT      : RESULT OF THE THERMAL OPTICAL DEPTH COMPUTATIONS.
! ZEOSS     : SOLAR OPTICAL DEPTH "ABOVE THE MODEL'S TOP".
! ZEOTS     : THERM. "DOWNWARDS" OPTICAL DEPTH "ABOVE THE MODEL'S TOP".

DO JLON=KIDIA,KFDIA
  ZNSOR(JLON)=2.0_JPRB*MAX(PAPRS(JLON,0),ZEPS1)*PQO3(JLON,0)
ENDDO
DO JLEV=1,KTDIA-1
  DO JLON=KIDIA,KFDIA
    ZNSOR(JLON)=ZNSOR(JLON)+2.0_JPRB*PDELP(JLON,JLEV)*PQO3(JLON,JLEV)
  ENDDO
ENDDO
DO JLON=KIDIA,KFDIA
  ZP=MAX(ZEPS1,PAPRS(JLON,KTDIA-1))
  ZQ=MAX(ZEPS2,PQ(JLON,KTDIA))
  ZRT=SQRT(PT(JLON,KTDIA))
  ZTI=1.0_JPRB/PT(JLON,KTDIA)
  ZT2=PT(JLON,KTDIA)*PT(JLON,KTDIA)
  ZT2I=ZTI*ZTI
  ZT4I=ZT2I*ZT2I
  ZTDETA=ZRT**49*EXP(GCE4/PT(JLON,KTDIA))
  ZT3=ZT2*PT(JLON,KTDIA)
  ZNSH(JLON)=(2.0_JPRB*ZP)*ZQ
  ZNSC(JLON)=(2.0_JPRB*ZP)*PQCO2(JLON,KTDIA)
  ZNSO(JLON)=ZNSOR(JLON)
  ZNTH(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O(JLON)))-1.0_JPRB)+GCC(6)&
   & *ZRTO(JLON)  
  ZEOT(JLON)=(ZWTH*(1.0_JPRB+ZWTH*(VNP(1,4)+ZWTH*(VNP(2,4)+ZWTH*(VNP(3,&
   & 4)&
   & +ZWTH*(VNP(4,4)+ZWTH*VNP(5,4)))))))/(1.0_JPRB+ZWTH*(VDP(1,4)&
   & +ZWTH*(VDP(2,4)+ZWTH*(VDP(3,4)+ZWTH*(VDP(4,4)+ZWTH &
   & *VDP(5,4))))))+(ZWTC*(1.0_JPRB+ZWTC*(VNP(1,5)+ZWTC*(VNP(2,5)&
   & +ZWTC*(VNP(3,5)+ZWTC*(VNP(4,5)+ZWTC*VNP(5,5)))))))/(1.0_JPRB &
   & +ZWTC*(VDP(1,5)+ZWTC*(VDP(2,5)+ZWTC*(VDP(3,5)+ZWTC &
   & *(VDP(4,5)+ZWTC*VDP(5,5))))))+(ZWTO*(1.0_JPRB+ZWTO*(VNP(1,6)&
   & +ZWTO*(VNP(2,6)+ZWTO*(VNP(3,6)+ZWTO*(VNP(4,6)+ZWTO &
   & *VNP(5,6)))))))/(1.0_JPRB+ZWTO*(VDP(1,6)+ZWTO*(VDP(2,6)+ZWTO &
   & *(VDP(3,6)+ZWTO*(VDP(4,6)+ZWTO*VDP(5,6))))))  
  ZEOTS(JLON)=ZEOT(JLON)
ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     III.3   DESCENDING VERTICAL LOOP ON LAYERS.

! - TEMPORARY(S) 1D .

! ZEOSO     : "OLD" SOLAR OPTICAL DEPTH (FOR COMPUTING "NEW" ONE).
! ZEOTO     : "OLD" THERMAL OPTICAL DEPTH (FOR COMPUTING "NEW" ONE).

DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA
    ZEOSO(JLON)=ZEOS(JLON)
  ENDDO
  DO JLON=KIDIA,KFDIA
    ZEOTO(JLON)=ZEOT(JLON)
  ENDDO
  DO JLON=KIDIA,KFDIA
    Z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))))))/(1.0_JPRB+ZWTO*(VDP(1,6)+ZWTO*(VDP(2,6)+ZWTO &
     & *(VDP(3,6)+ZWTO*(VDP(4,6)+ZWTO*VDP(5,6))))))  
    ZDEOT(JLON,JLEV)=ZEOT(JLON)-ZEOTO(JLON)
  ENDDO
ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     III.4   SURFACE CONDITION FOR THE THERMAL CALCULATIONS.

DO JLON=KIDIA,KFDIA
  ZEOT(JLON)=0.0_JPRB
  ZNTH(JLON)=0.0_JPRB
  ZNTC(JLON)=0.0_JPRB
  ZNTO(JLON)=0.0_JPRB
  ZRTH(JLON)=0.0_JPRB
  ZCTH(JLON)=0.0_JPRB
  ZRTC(JLON)=0.0_JPRB
  ZRTO(JLON)=0.0_JPRB
ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     III.5   ASCENDING VERTICAL LOOP ON LAYERS.

DO JLEV=KLEV,KTDIA,-1
  DO JLON=KIDIA,KFDIA
    ZEOSO(JLON)=ZEOS(JLON)
  ENDDO
  DO JLON=KIDIA,KFDIA
    ZEOTO(JLON)=ZEOT(JLON)
  ENDDO
  DO JLON=KIDIA,KFDIA
    ZP=MAX(ZEPS1,PAPRS(JLON,JLEV-1))
    ZQ=MAX(ZEPS2,PQ(JLON,JLEV))
    ZRT=SQRT(PT(JLON,JLEV))
    ZTI=1.0_JPRB/PT(JLON,JLEV)
    ZT2=PT(JLON,JLEV)*PT(JLON,JLEV)
    ZT2I=ZTI*ZTI
    ZT4I=ZT2I*ZT2I
    ZTDETA=ZRT**49*EXP(GCE4/PT(JLON,JLEV))
    ZT3=ZT2*PT(JLON,JLEV)
    ZDUH=(2.0_JPRB*PDELP(JLON,JLEV))*ZQ
    ZDUC=(2.0_JPRB*PDELP(JLON,JLEV))*PQCO2(JLON,JLEV)
    ZDUO=(2.0_JPRB*PDELP(JLON,JLEV))*PQO3(JLON,JLEV)
    ZNSH(JLON)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CC(6)&
     & *ZRTO(JLON)  
    ZEOT(JLON)=(ZWTH*(1.0_JPRB+ZWTH*(VNP(1,4)+ZWTH*(VNP(2,4)+&
     & ZWTH*(VNP(3,4)&
     & +ZWTH*(VNP(4,4)+ZWTH*VNP(5,4)))))))/(1.0_JPRB+ZWTH*(VDP(1,4)&
     & +ZWTH*(VDP(2,4)+ZWTH*(VDP(3,4)+ZWTH*(VDP(4,4)+ZWTH &
     & *VDP(5,4))))))+(ZWTC*(1.0_JPRB+ZWTC*(VNP(1,5)+ZWTC*(VNP(2,5)&
     & +ZWTC*(VNP(3,5)+ZWTC*(VNP(4,5)+ZWTC*VNP(5,5)))))))/(1.0_JPRB &
     & +ZWTC*(VDP(1,5)+ZWTC*(VDP(2,5)+ZWTC*(VDP(3,5)+ZWTC &
     & *(VDP(4,5)+ZWTC*VDP(5,5))))))+(ZWTO*(1.0_JPRB+ZWTO*(VNP(1,6)&
     & +ZWTO*(VNP(2,6)+ZWTO*(VNP(3,6)+ZWTO*(VNP(4,6)+ZWTO &
     & *VNP(5,6)))))))/(1.0_JPRB+ZWTO*(VDP(1,6)+ZWTO*(VDP(2,6)+ZWTO &
     & *(VDP(3,6)+ZWTO*(VDP(4,6)+ZWTO*VDP(5,6))))))  
    ZUEOT(JLON,JLEV)=MIN(ZDEOT(JLON,JLEV),ZEOT(JLON)-ZEOTO(JLON))
!NEW      ZSEOT(JLON,JLEV)=ZEOT(JLON)-ZEOTO(JLON)
    ZSEOT(JLON,JLEV)=ZUEOT(JLON,JLEV)
  ENDDO
ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     III.6   TOP OF THE MODEL'S ATMOSPHERE (OR ARBITRARILY SMALL
!     PRESSURE VALUE) FOR THERMAL "EXCHANGE BETWEEN LAYERS"
!     COMPUTATIONS.

! - TEMPORARY(S) 1D .

! ZUETS    : "UPWARDS" THERMAL OPTICAL DEPTH ABOVE THE MODEL'S TOP.

DO JLON=KIDIA,KFDIA
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LON)/(ZRTC(JLON)/ZNTC(JLON)))-1.0_JPRB)+GCC(5)&
   & *ZRTC(JLON)  
  ZWTO=(ZGAS2B(6)*(ZRTO(JLON)/ZNTO(JLON)))*(SQRT(1.0_JPRB+ZG4B(6)&
   & *ZNTO(JLON)/(ZRTO(JLON)/ZNTO(JLON)))-1.0_JPRB)+GCC(6)&
   & *ZRTO(JLON)  
  ZEOT(JLON)=(ZWTH*(1.0_JPRB+ZWTH*(VNP(1,4)+ZWTH*(VNP(2,4)+ZWTH*(VNP(3,&
   & 4)&
   & +ZWTH*(VNP(4,4)+ZWTH*VNP(5,4)))))))/(1.0_JPRB+ZWTH*(VDP(1,4)&
   & +ZWTH*(VDP(2,4)+ZWTH*(VDP(3,4)+ZWTH*(VDP(4,4)+ZWTH &
   & *VDP(5,4))))))+(ZWTC*(1.0_JPRB+ZWTC*(VNP(1,5)+ZWTC*(VNP(2,5)&
   & +ZWTC*(VNP(3,5)+ZWTC*(VNP(4,5)+ZWTC*VNP(5,5)))))))/(1.0_JPRB &
   & +ZWTC*(VDP(1,5)+ZWTC*(VDP(2,5)+ZWTC*(VDP(3,5)+ZWTC &
   & *(VDP(4,5)+ZWTC*VDP(5,5))))))+(ZWTO*(1.0_JPRB+ZWTO*(VNP(1,6)&
   & +ZWTO*(VNP(2,6)+ZWTO*(VNP(3,6)+ZWTO*(VNP(4,6)+ZWTO &
   & *VNP(5,6)))))))/(1.0_JPRB+ZWTO*(VDP(1,6)+ZWTO*(VDP(2,6)+ZWTO &
   & *(VDP(3,6)+ZWTO*(VDP(4,6)+ZWTO*VDP(5,6))))))  
  ZUETS(JLON)=MIN(ZEOTS(JLON),ZEOT(JLON)-ZEOTO(JLON))
ENDDO

!*
!     ------------------------------------------------------------------
!     IV - COMPUTATION OF THE CLOUD GEOMETRY ELEMENTS. THE TERMS ZB ARE
!     USED AS TEMPORARY STORAGE FOR THE "ALPHA", "BETA", "GAMMA" AND
!     "DELTA" COEFFICIENTS OF THE MAXIMUM OVERLAP CALCULATIONS OR (IN
!     THAT CASE ZB1 ALONE) FOR THE COMPLEMENT TO ONE OF CLOUDINESS IN
!     THE RANDOM OVERLAP CALCULATIONS.

! - TEMPORAIRE(S) 2D (1:KLEV) .

! ZB1       : FIRST INTERMEDIATE STORAGE FOR CLOUD GEOMETRY.

!     THE CASE WITH RANDOM OVERLAP OF ALL CLOUD FRACTIONS) ONE COMPUTES
!     ONLY THE COMPLEMENT TO ONE OF CLOUDINESS.

DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA
    ZB1(JLON,JLEV)=1.0_JPRB-PNEB(JLON,JLEV)
  ENDDO
ENDDO

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     XX. LOOP FOR COMPUTING LINE BY LINE THE COEFFICIENTS OF CURTIS
!         MATRIX

DO JJ=KTDIA-1,KLEV

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

    ZZBB(JLON,JJ)=1.0_JPRB
  ENDDO

!*
!     ------------------------------------------------------------------
!     VI - COMPUTATION OF THE COMPLEMENTS TO ONE OF THE THERMAL FLUXES
!     IN A NORMALIZED ISOTHERMAL ATMOSPHERE VIA ELIMINATION/BACK-
!     SUBSTITUTION AND USE OF THE RESULT TO COMPUTE FLUXES. IN ALL THE
!     FOLLOWING THE QUANTITIES ZF (OR ZZF IN THE THERMAL CASE WITH
!     REAL TEMPERATURES) WILL INDICATE THE RIGHT HAND SIDES OF THE
!     "ADDING METHOD" LINEAR SYSTEMS AND THE QUANTITIES ZTU THE
!     SUPERDIAGONAL ELEMENTS TO BE USED IN THE BACK-SUBSTITUTION PART
!     OF THE ALGORITHM. ONE MUST ALSO MENTION THAT IN THE "RANDOM
!     OVERLAP" CASE THE SUFFIX "C" (CLEAR) REPRESENTS THE WHOLE LAYER
!     AND THAT THE SUFFIX "N" (NEBULOUS) REPRESENTS UNUSED ARRAYS.

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

! ZFDC      : RIGHT HAND SIDE TERM FOR CLEAR-SKY DOWNWARDS DIFF. FLUX.
! ZFMC      : RIGHT HAND SIDE TERM FOR CLEAR-SKY UPWARDS DIFF. FLUX.
! ZYFDC     : OTHER "R.H.S." TERM FOR CLEAR-SKY DOWNWARDS DIFF. FLUX.
! ZYFMC     : OTHER "R.H.S." TERM FOR CLEAR-SKY UPWARDS DIFF. FLUX.
! ZZFDC     : OTHER "R.H.S." TERM FOR CLEAR-SKY DOWNWARDS DIFF. FLUX.
! ZZFMC     : OTHER "R.H.S." TERM FOR CLEAR-SKY UPWARDS DIFF. FLUX.

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

! ZTU2      : SECOND SUPERDIAGONAL COEFF. FOR THE "ADDING" SYSTEM.
! ZTU6      : SIXTH SUPERDIAGONAL COEFF. FOR THE "ADDING" SYSTEM.

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VI.1   SOMMET DE L'ATMOSPHERE.

!            TOP OF THE ATMOSPHERE.

  DO JLON=KIDIA,KFDIA
    ZFDC(JLON,KTDIA-1)=EXP(MAX(-ZEOTS(JLON),ZARGLI))

!     CALCULS OPTIONNELS SUIVANT LA GEOMETRIE NUAGEUSE CHOISIE.
!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VI.2   FIRST LAYER : COMPUTATION OF OPTICAL DEPTHS, OF
!     TRANSMISSIVITIES/REFLECTIVITIES AND OF LOCAL COEFFICIENTS FOR THE
!     CLOUD GEOMETRY. FOR THE LATTER ONLY THE 4 AND 5 VALUES WILL BE
!     USED IN THE THERMAL CASE (NO PARALLEL FLUX).

! - TEMPORARY(S) 1D .

! ZA4C      : CLEAR-SKY DIFFUSE TRANSMISSIVITY.
! ZA5C      : CLEAR-SKY DIFFUSE REFLECTIVITY.
! ZA4N      : CLOUDY DIFFUSE TRANSMISSIVITY.
! ZA5N      : CLOUDY DIFFUSE REFLECTIVITY.
! ZAL1      : WEIGHT OF THE M OUTGOING C FLUX IN THE M INGOING C FLUX.
! ZDE1      : WEIGHT OF THE M OUTGOING N FLUX IN THE M INGOING N FLUX.

  DO JLON=KIDIA,KFDIA
    ZEO1=ZDEOT(JLON,KTDIA)+ZEO1TA*PDAER(KTDIA)
    ZEO2=ZEO2TA*PDAER(KTDIA)
    ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
    ZTAU=EXP(MAX(-ZEPS,ZARGLI))
    ZRHO=ZEO2/(ZEO1+ZEPS)
    ZA4C(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  
    ZA5C(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  
    ZEO1=ZEO1+ZEO1TN*(PDELP(JLON,KTDIA)*ZQLI(JLON,KTDIA))&
     & +ZEO1TI*(PDELP(JLON,KTDIA)*ZQICE(JLON,KTDIA))  
    ZEO2=ZEO2+ZEO2TN*(PDELP(JLON,KTDIA)*ZQLI(JLON,KTDIA))&
     & +ZEO2TI*(PDELP(JLON,KTDIA)*ZQICE(JLON,KTDIA))  
    ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
    ZTAU=EXP(MAX(-ZEPS,ZARGLI))
    ZRHO=ZEO2/(ZEO1+ZEPS)
    ZA4N(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  
    ZA5N(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

    ZA4C(JLON)=ZA4C(JLON)*ZB1(JLON,KTDIA)+ZA4N(JLON)*PNEB(JLON,KTDIA)
    ZA5C(JLON)=ZA5C(JLON)*ZB1(JLON,KTDIA)+ZA5N(JLON)*PNEB(JLON,KTDIA)

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VI.3   FIRST LEVEL, ELIMINATION (EASY).

  DO JLON=KIDIA,KFDIA

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

    ZFMC(JLON,KTDIA-1)=ZA5C(JLON)*ZFDC(JLON,KTDIA-1)
    ZFDC(JLON,KTDIA)=ZA4C(JLON)*ZFDC(JLON,KTDIA-1)
    ZTU2(JLON,KTDIA)=ZA4C(JLON)
    ZTU6(JLON,KTDIA)=ZA5C(JLON)

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VI.4   LOOP OVER LAYERS, PRELIMINARY COMPUTATIONS, THEN
!     ELIMINATION.

  DO JLEV=KTDIA+1,KLEV
    DO JLON=KIDIA,KFDIA
      ZEO1=ZDEOT(JLON,JLEV)+ZEO1TA*PDAER(JLEV)
      ZEO2=ZEO2TA*PDAER(JLEV)
      ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
      ZTAU=EXP(MAX(-ZEPS,ZARGLI))
      ZRHO=ZEO2/(ZEO1+ZEPS)
      ZA4C(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  
      ZA5C(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  
      ZEO1=ZEO1+ZEO1TN*(PDELP(JLON,JLEV)*ZQLI(JLON,JLEV))&
       & +ZEO1TI*(PDELP(JLON,JLEV)*ZQICE(JLON,JLEV))  
      ZEO2=ZEO2+ZEO2TN*(PDELP(JLON,JLEV)*ZQLI(JLON,JLEV))&
       & +ZEO2TI*(PDELP(JLON,JLEV)*ZQICE(JLON,JLEV))  
      ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
      ZTAU=EXP(MAX(-ZEPS,ZARGLI))
      ZRHO=ZEO2/(ZEO1+ZEPS)
      ZA4N(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  
      ZA5N(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZA4C(JLON)=ZA4C(JLON)*ZB1(JLON,JLEV)+ZA4N(JLON)*PNEB(JLON,JLEV)
      ZA5C(JLON)=ZA5C(JLON)*ZB1(JLON,JLEV)+ZA5N(JLON)*PNEB(JLON,JLEV)

    ENDDO
    DO JLON=KIDIA,KFDIA

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZTD1=1.0_JPRB/(1.0_JPRB-ZA5C(JLON)*ZTU6(JLON,JLEV-1))
      ZFMC(JLON,JLEV-1)=ZTD1*ZA5C(JLON)*ZFDC(JLON,JLEV-1)
      ZTU2(JLON,JLEV)=ZTD1*ZA4C(JLON)

    ENDDO
    DO JLON=KIDIA,KFDIA

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZTD4=ZA4C(JLON)*ZTU6(JLON,JLEV-1)
      ZFDC(JLON,JLEV)=ZA4C(JLON)*ZFDC(JLON,JLEV-1)+ZTD4*ZFMC(JLON,JLEV-1)
      ZTU6(JLON,JLEV)=ZA5C(JLON)+ZTD4*ZTU2(JLON,JLEV)

    ENDDO
  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VI.5   SURFACE TREATMENT.

  DO JLON=KIDIA,KFDIA
    ZAL=1.0_JPRB-PEMIS(JLON)
    ZTDS1=1.0_JPRB/(1.0_JPRB-ZAL*ZTU6(JLON,KLEV))
    ZFMC(JLON,KLEV)=(ZTDS1*ZAL)*ZFDC(JLON,KLEV)

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VI.6   BACK-SUBSTITUTION LAYER BY LAYER.

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

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZFDC(JLON,JLEV)=ZFDC(JLON,JLEV)+ZTU6(JLON,JLEV)*ZFMC(JLON,JLEV)
      ZFMC(JLON,JLEV-1)=ZFMC(JLON,JLEV-1)+ZTU2(JLON,JLEV)*ZFMC(JLON,JLEV)

    ENDDO
  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VI.7   FLUX COMPUTATION IN THE COOLING TO SPACE CASE.

! - TEMPORARY(S) 1D .

! ZTRS      : "Z" NET FLUX AT THE TOP OF A LAYER.
! ZTRB      : "Z" NET FLUX AT THE BOTTOM OF A LAYER.

  DO JLON=KIDIA,KFDIA
    ZTRS(JLON)=ZFDC(JLON,KLEV)-ZFMC(JLON,KLEV)

    ZFRTH(JLON,KLEV)=-ZZBB(JLON,KLEV)*ZTRS(JLON)
  ENDDO
  DO JLEV=KLEV,KTDIA,-1
    DO JLON=KIDIA,KFDIA
      ZTRB(JLON)=ZTRS(JLON)
    ENDDO
    DO JLON=KIDIA,KFDIA
      ZTRS(JLON)=ZFDC(JLON,JLEV-1)-ZFMC(JLON,JLEV-1)

      ZFRTH(JLON,JLEV-1)=ZFRTH(JLON,JLEV)+ZZBB(JLON,JLEV-1)&
       & *(ZTRB(JLON)-ZTRS(JLON))  
    ENDDO
  ENDDO

!*
!     ------------------------------------------------------------------
!     XVI - COMPUTATION OF THE COMPLEMENTS TO ONE OF THE THERMAL FLUXES
!     IN T = 0 ATMOSPHERE (NORMALISED SURFACE) VIA ELIMINATION/BACK-
!     SUBSTITUTION AND USE OF THE RESULT TO UPDATE FLUXES.

  DO JLEV=KTDIA-1,KLEV-1
    ZBBS(JLEV)=0.0_JPRB
  ENDDO
  ZBBS(KLEV)=1.0_JPRB

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!    XVI.1   TOP OF THE ATMOSPHERE.

  DO JLON=KIDIA,KFDIA
    ZYFDC(JLON,KTDIA-1)=0.0_JPRB

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     XVI.2   FIRST LAYER : COMPUTATION OF OPTICAL DEPTHS, OF
!     TRANSMISSIVITIES/REFLECTIVITIES AND OF LOCAL COEFFICIENTS FOR THE
!     CLOUD GEOMETRY. FOR THE LATTER ONLY THE 4 AND 5 VALUES WILL BE
!     USED IN THE THERMAL CASE (NO PARALLEL FLUX).

  DO JLON=KIDIA,KFDIA
    ZEO1=ZSEOT(JLON,KTDIA)+ZEO1TA*PDAER(KTDIA)
    ZEO2=ZEO2TA*PDAER(KTDIA)
    ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
    ZTAU=EXP(MAX(-ZEPS,ZARGLI))
    ZRHO=ZEO2/(ZEO1+ZEPS)
    ZA4C(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  
    ZA5C(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  
    ZEO1=ZEO1+ZEO1TN*(PDELP(JLON,KTDIA)*ZQLI(JLON,KTDIA))&
     & +ZEO1TI*(PDELP(JLON,KTDIA)*ZQICE(JLON,KTDIA))  
    ZEO2=ZEO2+ZEO2TN*(PDELP(JLON,KTDIA)*ZQLI(JLON,KTDIA))&
     & +ZEO2TI*(PDELP(JLON,KTDIA)*ZQICE(JLON,KTDIA))  
    ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
    ZTAU=EXP(MAX(-ZEPS,ZARGLI))
    ZRHO=ZEO2/(ZEO1+ZEPS)
    ZA4N(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  
    ZA5N(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

    ZA4C(JLON)=ZA4C(JLON)*ZB1(JLON,KTDIA)+ZA4N(JLON)*PNEB(JLON,KTDIA)
    ZA5C(JLON)=ZA5C(JLON)*ZB1(JLON,KTDIA)+ZA5N(JLON)*PNEB(JLON,KTDIA)

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     XVI.3   FIRST LEVEL, ELIMINATION (EASY).

  DO JLON=KIDIA,KFDIA

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

    ZYFMC(JLON,KTDIA-1)=0.0_JPRB
    ZYFDC(JLON,KTDIA)=0.0_JPRB
    ZTU2(JLON,KTDIA)=ZA4C(JLON)
    ZTU6(JLON,KTDIA)=ZA5C(JLON)

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     XVI.4   LOOP OVER LAYERS, PRELIMINARY COMPUTATIONS, THEN
!     ELIMINATION.

  DO JLEV=KTDIA+1,KLEV
    DO JLON=KIDIA,KFDIA
      ZEO1=ZSEOT(JLON,JLEV)+ZEO1TA*PDAER(JLEV)
      ZEO2=ZEO2TA*PDAER(JLEV)
      ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
      ZTAU=EXP(MAX(-ZEPS,ZARGLI))
      ZRHO=ZEO2/(ZEO1+ZEPS)
      ZA4C(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  
      ZA5C(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  
      ZEO1=ZEO1+ZEO1TN*(PDELP(JLON,JLEV)*ZQLI(JLON,JLEV))&
       & +ZEO1TI*(PDELP(JLON,JLEV)*ZQICE(JLON,JLEV))  
      ZEO2=ZEO2+ZEO2TN*(PDELP(JLON,JLEV)*ZQLI(JLON,JLEV))&
       & +ZEO2TI*(PDELP(JLON,JLEV)*ZQICE(JLON,JLEV))  
      ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
      ZTAU=EXP(MAX(-ZEPS,ZARGLI))
      ZRHO=ZEO2/(ZEO1+ZEPS)
      ZA4N(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  
      ZA5N(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZA4C(JLON)=ZA4C(JLON)*ZB1(JLON,JLEV)+ZA4N(JLON)*PNEB(JLON,JLEV)
      ZA5C(JLON)=ZA5C(JLON)*ZB1(JLON,JLEV)+ZA5N(JLON)*PNEB(JLON,JLEV)

    ENDDO
    DO JLON=KIDIA,KFDIA

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZTD1=1.0_JPRB/(1.0_JPRB-ZA5C(JLON)*ZTU6(JLON,JLEV-1))
      ZYFMC(JLON,JLEV-1)=ZTD1*ZA4C(JLON)*(ZBBS(JLEV-1)-ZBBS(JLEV))
      ZTU2(JLON,JLEV)=ZTD1*ZA4C(JLON)

    ENDDO
    DO JLON=KIDIA,KFDIA

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZTD4=ZA4C(JLON)*ZTU6(JLON,JLEV-1)
      ZYFDC(JLON,JLEV)=ZTD4*ZYFMC(JLON,JLEV-1)+ZA5C(JLON)&
       & *(ZBBS(JLEV-1)-ZBBS(JLEV))  
      ZTU6(JLON,JLEV)=ZA5C(JLON)+ZTD4*ZTU2(JLON,JLEV)

    ENDDO
  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     XVI.5   SURFACE TREATMENT.

  DO JLON=KIDIA,KFDIA
    ZAL=1.0_JPRB-PEMIS(JLON)
    ZTDS1=1.0_JPRB/(1.0_JPRB-ZAL*ZTU6(JLON,KLEV))
    ZYFMC(JLON,KLEV)=(ZTDS1*ZAL)*(ZYFDC(JLON,KLEV)+1.0_JPRB)

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     XVI.6   BACK-SUBSTITUTION LAYER BY LAYER.

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

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZYFDC(JLON,JLEV)=ZYFDC(JLON,JLEV)+ZTU6(JLON,JLEV)*ZYFMC(JLON,JLEV)
      ZYFMC(JLON,JLEV-1)=ZYFMC(JLON,JLEV-1)+ZTU2(JLON,JLEV)*ZYFMC(JLON,JLEV)

    ENDDO
  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     XVI.7   FLUX UPDATE IN THE EXCHANGE WITH SURFACE CASE.

  DO JLON=KIDIA,KFDIA
    ZTRB(JLON)=ZYFDC(JLON,KTDIA-1)-ZYFMC(JLON,KTDIA-1)

    ZFRB(JLON)=ZFRTH(JLON,KTDIA-1)
  ENDDO
  DO JLEV=KTDIA,KLEV
    DO JLON=KIDIA,KFDIA
      ZTRS(JLON)=ZTRB(JLON)
      ZFRS(JLON)=ZFRB(JLON)
    ENDDO
    DO JLON=KIDIA,KFDIA
      ZTRB(JLON)=ZYFDC(JLON,JLEV)-ZYFMC(JLON,JLEV)+ZBBS(JLEV)-ZBBS(JLEV-1)
!NEVA*            -ZBBS(JLEV)

      ZFRB(JLON)=ZFRTH(JLON,JLEV)
      ZFRTH(JLON,JLEV)=ZFRTH(JLON,JLEV-1)+ZFRB(JLON)-ZFRS(JLON)&
       & +(ZZBB(JLON,KLEV)-ZZBB(JLON,JLEV-1))&
       & *(ZTRS(JLON)-ZTRB(JLON))  
    ENDDO
  ENDDO

!*
!     ------------------------------------------------------------------
!     VII - COMPUTATION OF THE COMPLEMENTS TO THE BLACK-BODY FLUXES OF
!     "ANTI-SURESTIMATION" THERMAL FLUXES FOR THE REAL TEMPERATURE
!     PROFILE AND FOR THE PRECEEDING PROFILES IN ORDER TO
!     OBTAIN BY DIFFERENCIATION THE EXCHANGE TERMS THAT, ADDED TO THE
!     "C.T.S." AND "E.W.S." RESULTS, WILL GIVE THE FINAL THERMAL RADIATIVE
!     FLUXES' ARRAY.

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VII.1   TOP OF THE ATMOSPHERE.

  DO JLON=KIDIA,KFDIA
    ZFDC(JLON,KTDIA-1)=EXP(MAX(-ZUETS(JLON),ZARGLI))
    ZYFDC(JLON,KTDIA-1)=0.0_JPRB
    ZZFDC(JLON,KTDIA-1)=ZZBB(JLON,KTDIA-1)*ZFDC(JLON,KTDIA-1)

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VII.2   FIRST LAYER : COMPUTATION OF THE OPTICAL DEPTHS, OF THE
!     TRANSMISSIVITIES/REFLECTIVITIES AND OF THE LOCAL COEFFICIENTS FOR
!     THE CLOUD GEOMETRY.

  DO JLON=KIDIA,KFDIA
    ZEO1=ZUEOT(JLON,KTDIA)+ZEO1TA*PDAER(KTDIA)
    ZEO2=ZEO2TA*PDAER(KTDIA)
    ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
    ZTAU=EXP(MAX(-ZEPS,ZARGLI))
    ZRHO=ZEO2/(ZEO1+ZEPS)
    ZA4C(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  
    ZA5C(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  
    ZEO1=ZEO1+ZEO1TN*(PDELP(JLON,KTDIA)*ZQLI(JLON,KTDIA))&
     & +ZEO1TI*(PDELP(JLON,KTDIA)*ZQICE(JLON,KTDIA))  
    ZEO2=ZEO2+ZEO2TN*(PDELP(JLON,KTDIA)*ZQLI(JLON,KTDIA))&
     & +ZEO2TI*(PDELP(JLON,KTDIA)*ZQICE(JLON,KTDIA))  
    ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
    ZTAU=EXP(MAX(-ZEPS,ZARGLI))

    PCOR(JLON,KTDIA)=1.0_JPRB-ZTAU

    ZRHO=ZEO2/(ZEO1+ZEPS)
    ZA4N(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  
    ZA5N(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
     & *ZTAU)))  

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

    ZA4C(JLON)=ZA4C(JLON)*ZB1(JLON,KTDIA)+ZA4N(JLON)*PNEB(JLON,KTDIA)
    ZA5C(JLON)=ZA5C(JLON)*ZB1(JLON,KTDIA)+ZA5N(JLON)*PNEB(JLON,KTDIA)

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VII.3   FIRST LAYER, ELIMINATION (EASY).

  DO JLON=KIDIA,KFDIA

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

    ZFMC(JLON,KTDIA-1)=ZA5C(JLON)*ZFDC(JLON,KTDIA-1)
    ZYFMC(JLON,KTDIA-1)=0.0_JPRB
    ZZFMC(JLON,KTDIA-1)=ZA5C(JLON)*ZZFDC(JLON,KTDIA-1)&
     & +ZA4C(JLON)*(ZZBB(JLON,KTDIA-1)&
     & -ZZBB(JLON,KTDIA))  
    ZFDC(JLON,KTDIA)=ZA4C(JLON)*ZFDC(JLON,KTDIA-1)
    ZYFDC(JLON,KTDIA)=0.0_JPRB
    ZZFDC(JLON,KTDIA)=ZA4C(JLON)*ZZFDC(JLON,KTDIA-1)+ZA5C(JLON)&
     & *(ZZBB(JLON,KTDIA-1)-ZZBB(JLON,KTDIA))  
    ZTU2(JLON,KTDIA)=ZA4C(JLON)
    ZTU6(JLON,KTDIA)=ZA5C(JLON)

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VII.4   LOOP OVER THE LAYERS, PRELIMINARY COMPUTATIONS AND THEN
!     ELIMINATION.

  DO JLEV=KTDIA+1,KLEV
    DO JLON=KIDIA,KFDIA
      ZEO1=ZUEOT(JLON,JLEV)+ZEO1TA*PDAER(JLEV)
      ZEO2=ZEO2TA*PDAER(JLEV)
      ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
      ZTAU=EXP(MAX(-ZEPS,ZARGLI))
      ZRHO=ZEO2/(ZEO1+ZEPS)
      ZA4C(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  
      ZA5C(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  
      ZEO1=ZEO1+ZEO1TN*(PDELP(JLON,JLEV)*ZQLI(JLON,JLEV))&
       & +ZEO1TI*(PDELP(JLON,JLEV)*ZQICE(JLON,JLEV))  
      ZEO2=ZEO2+ZEO2TN*(PDELP(JLON,JLEV)*ZQLI(JLON,JLEV))&
       & +ZEO2TI*(PDELP(JLON,JLEV)*ZQICE(JLON,JLEV))  
      ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
      ZTAU=EXP(MAX(-ZEPS,ZARGLI))

      PCOR(JLON,JLEV)=1.0_JPRB-ZTAU

      ZRHO=ZEO2/(ZEO1+ZEPS)
      ZA4N(JLON)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  
      ZA5N(JLON)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)*(ZTAU &
       & *ZTAU)))  

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZA4C(JLON)=ZA4C(JLON)*ZB1(JLON,JLEV)+ZA4N(JLON)*PNEB(JLON,JLEV)
      ZA5C(JLON)=ZA5C(JLON)*ZB1(JLON,JLEV)+ZA5N(JLON)*PNEB(JLON,JLEV)

    ENDDO
    DO JLON=KIDIA,KFDIA

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZTD1=1.0_JPRB/(1.0_JPRB-ZA5C(JLON)*ZTU6(JLON,JLEV-1))
      ZFMC(JLON,JLEV-1)=ZTD1*ZA5C(JLON)*ZFDC(JLON,JLEV-1)
      ZYFMC(JLON,JLEV-1)=ZTD1*ZA4C(JLON)*(ZBBS(JLEV-1)-ZBBS(JLEV))
      ZZFMC(JLON,JLEV-1)=ZTD1*ZA5C(JLON)*ZZFDC(JLON,JLEV-1)+ZTD1 &
       & *(ZA4C(JLON)*(ZZBB(JLON,JLEV-1)&
       & -ZZBB(JLON,JLEV))+ZA5C(JLON)&
       & *(ZZBB(JLON,JLEV-1)-ZZBB(JLON,JLEV-2)))  
      ZTU2(JLON,JLEV)=ZTD1*ZA4C(JLON)

    ENDDO
    DO JLON=KIDIA,KFDIA

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZTD4=ZA4C(JLON)*ZTU6(JLON,JLEV-1)
      ZFDC(JLON,JLEV)=ZA4C(JLON)*ZFDC(JLON,JLEV-1)+ZTD4*ZFMC(JLON,JLEV-1)
      ZYFDC(JLON,JLEV)=ZTD4*ZYFMC(JLON,JLEV-1)+ZA5C(JLON)&
       & *(ZBBS(JLEV-1)-ZBBS(JLEV))  
      ZZFDC(JLON,JLEV)=ZA4C(JLON)*ZZFDC(JLON,JLEV-1)+ZTD4 &
       & *ZZFMC(JLON,JLEV-1)+ZA5C(JLON)&
       & *(ZZBB(JLON,JLEV-1)-ZZBB(JLON,JLEV))&
       & +ZA4C(JLON)*(ZZBB(JLON,JLEV-1)&
       & -ZZBB(JLON,JLEV-2))  
      ZTU6(JLON,JLEV)=ZA5C(JLON)+ZTD4*ZTU2(JLON,JLEV)

    ENDDO
  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VII.5   SURFACE TREATMENT.

  DO JLON=KIDIA,KFDIA
    ZAL=1.0_JPRB-PEMIS(JLON)
    ZTDS1=1.0_JPRB/(1.0_JPRB-ZAL*ZTU6(JLON,KLEV))
    ZFMC(JLON,KLEV)=(ZTDS1*ZAL)*ZFDC(JLON,KLEV)
    ZYFMC(JLON,KLEV)=(ZTDS1*ZAL)*(ZYFDC(JLON,KLEV)+1.0_JPRB)
    ZZFMC(JLON,KLEV)=(ZTDS1*ZAL)*ZZFDC(JLON,KLEV)+(ZTDS1*ZAL)&
     & *(ZZBB(JLON,KLEV)-ZZBB(JLON,KLEV-1))  

  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VII.6   BACK-SUBSTITUTION LAYER BY LAYER.

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

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

      ZFDC(JLON,JLEV)=ZFDC(JLON,JLEV)+ZTU6(JLON,JLEV)*ZFMC(JLON,JLEV)
      ZYFDC(JLON,JLEV)=ZYFDC(JLON,JLEV)+ZTU6(JLON,JLEV)*ZYFMC(JLON,JLEV)
      ZZFDC(JLON,JLEV)=ZZFDC(JLON,JLEV)+ZTU6(JLON,JLEV)*ZZFMC(JLON,JLEV)
      ZFMC(JLON,JLEV-1)=ZFMC(JLON,JLEV-1)+ZTU2(JLON,JLEV)*ZFMC(JLON,JLEV)
      ZYFMC(JLON,JLEV-1)=ZYFMC(JLON,JLEV-1)+ZTU2(JLON,JLEV)*ZYFMC(JLON,JLEV)
      ZZFMC(JLON,JLEV-1)=ZZFMC(JLON,JLEV-1)+ZTU2(JLON,JLEV)*ZZFMC(JLON,JLEV)

    ENDDO
  ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     VII.7   COMPUTATION OF THE FINAL FLUXES.

! - TEMPORARY(S) 1D .

! ZZTRS     : "ZZ" NET FLUX AT THE TOP OF THE LAYER.
! ZFRS      : NET TOP FLUX FOR COOLING TO SPACE.
! ZZTRB     : "ZZ" NET FLUX AT THE BOTTOM OF THE LAYER.
! ZFRB      : NET BOTTOM FLUX FOR COOLING TO SPACE.

  DO JLON=KIDIA,KFDIA
    ZTRS(JLON)=ZFDC(JLON,KLEV)-ZFMC(JLON,KLEV)
    ZZTRS(JLON)=ZZFDC(JLON,KLEV)-ZZFMC(JLON,KLEV)&
     & +ZZBB(JLON,KLEV)-ZZBB(JLON,KLEV-1)  

    ZFRS(JLON)=ZFRTH(JLON,KLEV)
    ZFRTH(JLON,KLEV)=ZFRS(JLON)+ZZBB(JLON,KLEV)*ZTRS(JLON)-ZZTRS(JLON)
  ENDDO
  DO JLEV=KLEV,KTDIA+1,-1
    DO JLON=KIDIA,KFDIA
      ZTRB(JLON)=ZTRS(JLON)
      ZZTRB(JLON)=ZZTRS(JLON)
      ZFRB(JLON)=ZFRS(JLON)
    ENDDO
    DO JLON=KIDIA,KFDIA
      ZTRS(JLON)=ZFDC(JLON,JLEV-1)-ZFMC(JLON,JLEV-1)
      ZZTRS(JLON)=ZZFDC(JLON,JLEV-1)-ZZFMC(JLON,JLEV-1)&
       & +ZZBB(JLON,JLEV-1)-ZZBB(JLON,JLEV-2)  

      ZFRS(JLON)=ZFRTH(JLON,JLEV-1)
      ZFRTH(JLON,JLEV-1)=ZFRTH(JLON,JLEV)+ZFRS(JLON)-ZFRB(JLON)&
       & -ZZBB(JLON,JLEV-1)*(ZTRB(JLON)-ZTRS(JLON))&
       & +ZZTRB(JLON)-ZZTRS(JLON)  
    ENDDO
  ENDDO
  DO JLON=KIDIA,KFDIA
    ZTRB(JLON)=ZTRS(JLON)
    ZZTRB(JLON)=ZZTRS(JLON)
    ZFRB(JLON)=ZFRS(JLON)
  ENDDO
  DO JLON=KIDIA,KFDIA
    ZTRS(JLON)=ZFDC(JLON,KTDIA-1)-ZFMC(JLON,KTDIA-1)
    ZZTRS(JLON)=ZZFDC(JLON,KTDIA-1)-ZZFMC(JLON,KTDIA-1)

    ZFRS(JLON)=ZFRTH(JLON,KTDIA-1)
    ZFRTH(JLON,KTDIA-1)=ZFRTH(JLON,KTDIA)+ZFRS(JLON)-ZFRB(JLON)&
     & -ZZBB(JLON,KTDIA-1)*(ZTRB(JLON)-ZTRS(JLON))&
     & +ZZTRB(JLON)-ZZTRS(JLON)  

    ZTRB(JLON)=ZYFDC(JLON,KTDIA-1)-ZYFMC(JLON,KTDIA-1)

    ZFRB(JLON)=ZFRTH(JLON,KTDIA-1)
  ENDDO
  DO JLEV=KTDIA,KLEV
    DO JLON=KIDIA,KFDIA
      ZTRS(JLON)=ZTRB(JLON)
      ZFRS(JLON)=ZFRB(JLON)
    ENDDO
    DO JLON=KIDIA,KFDIA
      ZTRB(JLON)=ZYFDC(JLON,JLEV)-ZYFMC(JLON,JLEV)+ZBBS(JLEV)-ZBBS(JLEV-1)
!NEVA*            -ZBBS(JLEV)

      ZFRB(JLON)=ZFRTH(JLON,JLEV)
      ZFRTH(JLON,JLEV)=ZFRTH(JLON,JLEV-1)+ZFRB(JLON)-ZFRS(JLON)&
       & -(ZZBB(JLON,KLEV)-ZZBB(JLON,JLEV-1))&
       & *(ZTRS(JLON)-ZTRB(JLON))  
    ENDDO
  ENDDO

!*
!     END OF LOOP FOR COMPUTATION OF COEFFICIENTS OF CURTIS MATRIX

  DO JLEV=KTDIA-1,KLEV
    DO JLON=KIDIA,KFDIA
      POMPAC(JLON,JJ,JLEV)=ZFRTH(JLON,JLEV)
    ENDDO
  ENDDO

ENDDO

!*
!     RE-ORDERING THE COEFFICIENTS OF CURTIS MATRIX FROM THE ARRAY
!     OF TYPE (0:KLEV,0:KLEV) TO THE ARRAY OF TYPE (KLEV+1,KLEV+1)
!     AND COMPUTATION MEAN VALUE USING HORIZONTAL MEAN WEIGHTS.

PAC(:,:)=0.0_JPRB
DO JJ=1,KLEV+1
  DO JK=1,KLEV+1
    ZSUMW=0.0_JPRB
    DO JLON=KIDIA,KFDIA
      PAC(JJ,JK)=PAC(JJ,JK)+POMPAC(JLON,JK-1,JJ-1)*PDHSF(JLON)
      ZSUMW=ZSUMW+PDHSF(JLON)
    ENDDO

    IF (LGLOBRAD) THEN
      IF (NPROC > 1) THEN
        ZPACTOT=PAC(JJ,JK)
        CALL MPL_ALLREDUCE(ZPACTOT,'SUM',LDREPROD=.FALSE.,CDSTRING='ACRADCOEF:')
        ZSUMWTOT = ZSUMW
        CALL MPL_ALLREDUCE(ZSUMWTOT,'SUM',LDREPROD=.FALSE.,CDSTRING='ACRADCOEF:')
        TRMATSUM(JJ,JK)=TRMATSUM(JJ,JK)+ZPACTOT
        TRWEIGHT(JJ,JK)=TRWEIGHT(JJ,JK)+ZSUMWTOT
      ELSE
        TRMATSUM(JJ,JK)=TRMATSUM(JJ,JK)+PAC(JJ,JK)
        TRWEIGHT(JJ,JK)=TRWEIGHT(JJ,JK)+ZSUMW
      ENDIF
    ELSE
      PAC(JJ,JK)=PAC(JJ,JK)/ZSUMW
    ENDIF

  ENDDO
ENDDO

!*
!     ------------------------------------------------------------------
!     WIII - 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 .

! ZMU0I     : INVERSE OF THE MODIFIED COSINE OF THE ZENITH ANGLE.
! ZUSA      : AEROSOLS' UPSCATTERED FRACTION.
! ZUSI      : ICE CLOUDS' UPSCATTERED FRACTION.
! ZUSN      : CLOUDS' UPSCATTERED FRACTION.

DO JLON=KIDIA,KFDIA
  ZMU0I(JLON)=2.0_JPRB*ZDM0I(JLON)
  ZUSA(JLON)=(0.5_JPRB+USAA*PMU0(JLON))/(1.0_JPRB+USBA*PMU0(JLON))
  ZUSI(JLON)=(0.5_JPRB+USAI*PMU0(JLON))/(1.0_JPRB+USBI*PMU0(JLON))
  ZUSN(JLON)=(0.5_JPRB+USAN*PMU0(JLON))/(1.0_JPRB+USBN*PMU0(JLON))
ENDDO

!*
!     ------------------------------------------------------------------
!     IX - COMPUTATION OF COEFFICIENTS FOR SOLAR FLUX

! - TEMPORARY(S) 2D .

! ZZA1C     : CLEAR-SKY PARALLEL TRANSMISSIVITY.
! ZZA2C     : CLEAR-SKY PARALLEL/DIFFUSE TRANSMISSIVITY.
! ZZA3C     : CLEAR-SKY PARALLEL/DIFFUSE REFLECTIVITY.
! ZZA4C     : CLEAR-SKY DIFFUSE TRANSMISSIVITY.
! ZZA5C     : CLEAR-SKY DIFFUSE REFLECTIVITY.
! ZZA1N     : CLOUDY PARALLEL TRANSMISSIVITY.
! ZZA2N     : CLOUDY PARALLEL/DIFFUSE TRANSMISSIVITY.
! ZZA3N     : CLOUDY PARALLEL/DIFFUSE REFLECTIVITY.
! ZZA4N     : CLOUDY DIFFUSE TRANSMISSIVITY.
! ZZA5N     : CLOUDY DIFFUSE REFLECTIVITY.

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     IX.2   FIRST LAYER : COMPUTATION OF THE OPTICAL DEPTHS, OF THE
!     TRANSMISSIVITIES/REFLECTIVITIES AND OF THE LOCAL COEFFICIENTS FOR
!     THE CLOUD GEOMETRY.

DO JLON=KIDIA,KFDIA
  ZEO1=ZUEOS(JLON,KTDIA)+ZEO1SA*PDAER(KTDIA)+(EORAY*PDELP(JLON,KTDIA))
  ZEO2=ZEO2SA*PDAER(KTDIA)+(EORAY*PDELP(JLON,KTDIA))
  ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
  ZTAU=EXP(MAX(-ZEPS,ZARGLI))
  ZRHO=ZEO2/(ZEO1+ZEPS)
  ZZA4C(JLON,KTDIA)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)&
   & *(ZTAU*ZTAU)))  
  ZZA5C(JLON,KTDIA)=ZRHO*(1.0_JPRB-(ZTAU*ZTAU))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)&
   & *(ZTAU*ZTAU)))  
  ZEO=0.5_JPRB*ZDEOS(JLON,KTDIA)+ZEOSA*PDAER(KTDIA)+(EORAY*PDELP(JLON,KTDIA))
  ZMU0IC=(ZEPS/ZEO)+SIGN(MAX(ABS(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(JLON,KTDIA))&
   & -ZG2*ZZA5N(JLON,KTDIA)  

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

  ZZA1C(JLON,KTDIA)=ZZA1C(JLON,KTDIA)*ZB1(JLON,KTDIA)&
   & +ZZA1N(JLON,KTDIA)*PNEB(JLON,KTDIA)  
  ZZA2C(JLON,KTDIA)=ZZA2C(JLON,KTDIA)*ZB1(JLON,KTDIA)&
   & +ZZA2N(JLON,KTDIA)*PNEB(JLON,KTDIA)  
  ZZA3C(JLON,KTDIA)=ZZA3C(JLON,KTDIA)*ZB1(JLON,KTDIA)&
   & +ZZA3N(JLON,KTDIA)*PNEB(JLON,KTDIA)  
  ZZA4C(JLON,KTDIA)=ZZA4C(JLON,KTDIA)*ZB1(JLON,KTDIA)&
   & +ZZA4N(JLON,KTDIA)*PNEB(JLON,KTDIA)  
  ZZA5C(JLON,KTDIA)=ZZA5C(JLON,KTDIA)*ZB1(JLON,KTDIA)&
   & +ZZA5N(JLON,KTDIA)*PNEB(JLON,KTDIA)  

ENDDO

!*
!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!     IX.4   LOOP OVER THE LAYERS, PRELIMINARY COMPUTATIONS AND THEN
!     ELIMINATION.

DO JLEV=KTDIA+1,KLEV
  DO JLON=KIDIA,KFDIA
    ZEO1=ZUEOS(JLON,JLEV)+ZEO1SA*PDAER(JLEV)+(EORAY*PDELP(JLON,JLEV))
    ZEO2=ZEO2SA*PDAER(JLEV)+(EORAY*PDELP(JLON,JLEV))
    ZEPS=SQRT(ZEO1*ZEO1-ZEO2*ZEO2)
    ZTAU=EXP(MAX(-ZEPS,ZARGLI))
    ZRHO=ZEO2/(ZEO1+ZEPS)
    ZZA4C(JLON,JLEV)=ZTAU*(1.0_JPRB-(ZRHO*ZRHO))*(1.0_JPRB/(1.0_JPRB-(ZRHO*ZRHO)&
     & *(ZTAU*ZTAU)))  
    ZZA5C(JLON,JLEV)=ZRHO*(1.0_JPR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ZZA1N(JLON,JLEV)-ZZA4N(JLON,JLEV))&
     & -ZG1*ZZA5N(JLON,JLEV)*ZZA1N(JLON,JLEV)  
    ZZA3N(JLON,JLEV)=ZG1*(1.0_JPRB-ZZA4N(JLON,JLEV)*ZZA1N(JLON,JLEV))&
     & -ZG2*ZZA5N(JLON,JLEV)  

!     OPTIONAL COMPUTATIONS ACCORDING TO THE CHOSEN GEOMETRY.

    ZZA1C(JLON,JLEV)=ZZA1C(JLON,JLEV)*ZB1(JLON,JLEV)&
     & +ZZA1N(JLON,JLEV)*PNEB(JLON,JLEV)  
    ZZA2C(JLON,JLEV)=ZZA2C(JLON,JLEV)*ZB1(JLON,JLEV)&
     & +ZZA2N(JLON,JLEV)*PNEB(JLON,JLEV)  
    ZZA3C(JLON,JLEV)=ZZA3C(JLON,JLEV)*ZB1(JLON,JLEV)&
     & +ZZA3N(JLON,JLEV)*PNEB(JLON,JLEV)  
    ZZA4C(JLON,JLEV)=ZZA4C(JLON,JLEV)*ZB1(JLON,JLEV)&
     & +ZZA4N(JLON,JLEV)*PNEB(JLON,JLEV)  
    ZZA5C(JLON,JLEV)=ZZA5C(JLON,JLEV)*ZB1(JLON,JLEV)&
     & +ZZA5N(JLON,JLEV)*PNEB(JLON,JLEV)  

  ENDDO
ENDDO

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

!  Computation of equivalent coefficients a1c,...,a6c and a1n,...,a6n
!  by combining layers JK and NK

DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA
    ZZA1C(JLON,JLEV)=MAX(ZEPS4,ZZA1C(JLON,JLEV))
    ZZA1N(JLON,JLEV)=MAX(ZEPS4,ZZA1N(JLON,JLEV))
    ZZA2C(JLON,JLEV)=MAX(ZEPS4,ZZA2C(JLON,JLEV))
    ZZA2N(JLON,JLEV)=MAX(ZEPS4,ZZA2N(JLON,JLEV))
    ZZA3C(JLON,JLEV)=MAX(ZEPS4,ZZA3C(JLON,JLEV))
    ZZA3N(JLON,JLEV)=MAX(ZEPS4,ZZA3N(JLON,JLEV))
    ZZA4C(JLON,JLEV)=MAX(ZEPS4,ZZA4C(JLON,JLEV))
    ZZA4N(JLON,JLEV)=MAX(ZEPS4,ZZA4N(JLON,JLEV))
    ZZA5C(JLON,JLEV)=MAX(ZEPS4,ZZA5C(JLON,JLEV))
    ZZA5N(JLON,JLEV)=MAX(ZEPS4,ZZA5N(JLON,JLEV))

    ZPOM11(JLON,JLEV)=ZZA1C(JLON,JLEV)
    ZPOM12(JLON,JLEV)=ZZA1N(JLON,JLEV)
    ZPOM21(JLON,JLEV)=ZZA2C(JLON,JLEV)
    ZPOM22(JLON,JLEV)=ZZA2N(JLON,JLEV)
    ZPOM31(JLON,JLEV)=ZZA3C(JLON,JLEV)
    ZPOM32(JLON,JLEV)=ZZA3N(JLON,JLEV)
    ZPOM41(JLON,JLEV)=ZZA4C(JLON,JLEV)
    ZPOM42(JLON,JLEV)=ZZA4N(JLON,JLEV)
    ZPOM51(JLON,JLEV)=ZZA5C(JLON,JLEV)
    ZPOM52(JLON,JLEV)=ZZA5N(JLON,JLEV)
    ZPOM61(JLON,JLEV)=ZZA5C(JLON,JLEV)
    ZPOM62(JLON,JLEV)=ZZA5N(JLON,JLEV)
  ENDDO
ENDDO

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

    DO JJ=JLEV+2,KLEV
      IF (JJ == (JLEV+2)) THEN
        ZPOM11(JLON,JJ)=ZZA1C(JLON,JJ-1)*ZZA1C(JLON,JJ)
        ZPOM12(JLON,JJ)=ZZA1N(JLON,JJ-1)*ZZA1N(JLON,JJ)

        ZPOM21(JLON,JJ)=((1.0_JPRB-ZZA5C(JLON,JJ-1)*ZZA5C(JLON,JJ))&
         & *ZZA2C(JLON,JJ)*ZZA1C(JLON,JJ-1)&
         & +ZZA4C(JLON,JJ)*ZZA2C(JLON,JJ-1)&
         & +ZZA4C(JLON,JJ)*ZZA1C(JLON,JJ-1)&
         & *ZZA5C(JLON,JJ-1)*ZZA3C(JLON,JJ))&
         & /(1.0_JPRB-ZZA5C(JLON,JJ-1)*ZZA5C(JLON,JJ))  
        ZPOM22(JLON,JJ)=((1.0_JPRB-ZZA5N(JLON,JJ-1)*ZZA5N(JLON,JJ))&
         & *ZZA2N(JLON,JJ)*ZZA1N(JLON,JJ-1)&
         & +ZZA4N(JLON,JJ)*ZZA2N(JLON,JJ-1)&
         & +ZZA4N(JLON,JJ)*ZZA1N(JLON,JJ-1)&
         & *ZZA5N(JLON,JJ-1)*ZZA3N(JLON,JJ))&
         & /(1.0_JPRB-ZZA5N(JLON,JJ-1)*ZZA5N(JLON,JJ))  

        ZPOM31(JLON,JJ)=((1.0_JPRB-ZZA5C(JLON,JJ-1)*ZZA5C(JLON,JJ))&
         & *ZZA3C(JLON,JJ-1)&
         & +ZZA4C(JLON,JJ-1)*ZZA1C(JLON,JJ-1)&
         & *ZZA3C(JLON,JJ)&
         & +ZZA4C(JLON,JJ-1)*ZZA2C(JLON,JJ-1)&
         & *ZZA5C(JLON,JJ))&
         & /(1.0_JPRB-ZZA5C(JLON,JJ-1)*ZZA5C(JLON,JJ))  
        ZPOM32(JLON,JJ)=((1.0_JPRB-ZZA5N(JLON,JJ-1)*ZZA5N(JLON,JJ))&
         & *ZZA3N(JLON,JJ-1)&
         & +ZZA4N(JLON,JJ-1)*ZZA1N(JLON,JJ-1)&
         & *ZZA3N(JLON,JJ)&
         & +ZZA4N(JLON,JJ-1)*ZZA2N(JLON,JJ-1)&
         & *ZZA5N(JLON,JJ))&
         & /(1.0_JPRB-ZZA5N(JLON,JJ-1)*ZZA5N(JLON,JJ))  

        ZPOM41(JLON,JJ)=ZZA4C(JLON,JJ-1)*ZZA4C(JLON,JJ)&
         & /(1.0_JPRB-ZZA5C(JLON,JJ-1)*ZZA5C(JLON,JJ))  
        ZPOM42(JLON,JJ)=ZZA4N(JLON,JJ-1)*ZZA4N(JLON,JJ)&
         & /(1.0_JPRB-ZZA5N(JLON,JJ-1)*ZZA5N(JLON,JJ))  

        ZPOM51(JLON,JJ)=(ZZA5C(JLON,JJ)&
         & +ZZA5C(JLON,JJ-1)*ZZA4C(JLON,JJ)**2 &
         & -ZZA5C(JLON,JJ-1)*ZZA5C(JLON,JJ)**2)&
         & /(1.0_JPRB-ZZA5C(JLON,JJ-1)*ZZA5C(JLON,JJ))  
        ZPOM52(JLON,JJ)=(ZZA5N(JLON,JJ)&
         & +ZZA5N(JLON,JJ-1)*ZZA4N(JLON,JJ)**2 &
         & -ZZA5N(JLON,JJ-1)*ZZA5N(JLON,JJ)**2)&
         & /(1.0_JPRB-ZZA5N(JLON,JJ-1)*ZZA5N(JLON,JJ))  

        ZPOM61(JLON,JJ)=(ZZA5C(JLON,JJ-1)&
         & +ZZA5C(JLON,JJ)*ZZA4C(JLON,JJ-1)**2 &
         & -ZZA5C(JLON,JJ)*ZZA5C(JLON,JJ-1)**2)&
         & /(1.0_JPRB-ZZA5C(JLON,JJ-1)*ZZA5C(JLON,JJ))  
        ZPOM62(JLON,JJ)=(ZZA5N(JLON,JJ-1)&
         & +ZZA5N(JLON,JJ)*ZZA4N(JLON,JJ-1)**2 &
         & -ZZA5N(JLON,JJ)*ZZA5N(JLON,JJ-1)**2)&
         & /(1.0_JPRB-ZZA5N(JLON,JJ-1)*ZZA5N(JLON,JJ))  
      ELSE
        ZPOM11(JLON,JJ)=ZPOM11(JLON,JJ-1)*ZZA1C(JLON,JJ)
        ZPOM12(JLON,JJ)=ZPOM12(JLON,JJ-1)*ZZA1N(JLON,JJ)

        ZPOM21(JLON,JJ)=((1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ))&
         & *ZZA2C(JLON,JJ)*ZPOM11(JLON,JJ-1)&
         & +ZZA4C(JLON,JJ)*ZPOM21(JLON,JJ-1)&
         & +ZZA4C(JLON,JJ)*ZPOM11(JLON,JJ-1)&
         & *ZPOM51(JLON,JJ-1)*ZZA3C(JLON,JJ))&
         & /(1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ))  
        ZPOM22(JLON,JJ)=((1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ))&
         & *ZZA2N(JLON,JJ)*ZPOM12(JLON,JJ-1)&
         & +ZZA4N(JLON,JJ)*ZPOM22(JLON,JJ-1)&
         & +ZZA4N(JLON,JJ)*ZPOM12(JLON,JJ-1)&
         & *ZPOM52(JLON,JJ-1)*ZZA3N(JLON,JJ))&
         & /(1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ))  

        ZPOM31(JLON,JJ)=((1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ))&
         & *ZPOM31(JLON,JJ-1)&
         & +ZPOM41(JLON,JJ-1)*ZPOM11(JLON,JJ-1)&
         & *ZZA3C(JLON,JJ)&
         & +ZPOM41(JLON,JJ-1)*ZPOM21(JLON,JJ-1)&
         & *ZZA5C(JLON,JJ))&
         & /(1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ))  
        ZPOM32(JLON,JJ)=((1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ))&
         & *ZPOM32(JLON,JJ-1)&
         & +ZPOM42(JLON,JJ-1)*ZPOM12(JLON,JJ-1)&
         & *ZZA3N(JLON,JJ)&
         & +ZPOM42(JLON,JJ-1)*ZPOM22(JLON,JJ-1)&
         & *ZZA5N(JLON,JJ))&
         & /(1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ))  

        ZPOM41(JLON,JJ)=ZPOM41(JLON,JJ-1)*ZZA4C(JLON,JJ)&
         & /(1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ))  
        ZPOM42(JLON,JJ)=ZPOM42(JLON,JJ-1)*ZZA4N(JLON,JJ)&
         & /(1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ))  

        ZPOM51(JLON,JJ)=(ZZA5C(JLON,JJ)&
         & +ZPOM51(JLON,JJ-1)*ZZA4C(JLON,JJ)**2 &
         & -ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ)**2)&
         & /(1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ))  
        ZPOM52(JLON,JJ)=(ZZA5N(JLON,JJ)&
         & +ZPOM52(JLON,JJ-1)*ZZA4N(JLON,JJ)**2 &
         & -ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ)**2)&
         & /(1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ))  

        ZPOM61(JLON,JJ)=(ZPOM61(JLON,JJ-1)&
         & +ZZA5C(JLON,JJ)*ZPOM41(JLON,JJ-1)**2 &
         & -ZZA5C(JLON,JJ)*ZPOM61(JLON,JJ-1)&
         & *ZPOM51(JLON,JJ-1))&
         & /(1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ))  
        ZPOM62(JLON,JJ)=(ZPOM62(JLON,JJ-1)&
         & +ZZA5N(JLON,JJ)*ZPOM42(JLON,JJ-1)**2 &
         & -ZZA5N(JLON,JJ)*ZPOM62(JLON,JJ-1)&
         & *ZPOM52(JLON,JJ-1))&
         & /(1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ))  
      ENDIF
    ENDDO

    ZRAB1C(JLON,JLEV)=ZPOM11(JLON,KLEV)
    ZRAB1N(JLON,JLEV)=ZPOM12(JLON,KLEV)
    ZRAB2C(JLON,JLEV)=ZPOM21(JLON,KLEV)
    ZRAB2N(JLON,JLEV)=ZPOM22(JLON,KLEV)
    PRAB3C(JLON,JLEV)=ZPOM31(JLON,KLEV)
    PRAB3N(JLON,JLEV)=ZPOM32(JLON,KLEV)
    PRAB4C(JLON,JLEV)=ZPOM41(JLON,KLEV)
    PRAB4N(JLON,JLEV)=ZPOM42(JLON,KLEV)
    ZRAB5C(JLON,JLEV)=ZPOM51(JLON,KLEV)
    ZRAB5N(JLON,JLEV)=ZPOM52(JLON,KLEV)
    PRAB6C(JLON,JLEV)=ZPOM61(JLON,KLEV)
    PRAB6N(JLON,JLEV)=ZPOM62(JLON,KLEV)
  ENDDO
ENDDO

DO JLEV=KLEV-1,KLEV
  DO JLON=KIDIA,KFDIA
    ZRAB1C(JLON,JLEV)=ZZA1C(JLON,JLEV)
    ZRAB1N(JLON,JLEV)=ZZA1N(JLON,JLEV)
    ZRAB2C(JLON,JLEV)=ZZA2C(JLON,JLEV)
    ZRAB2N(JLON,JLEV)=ZZA2N(JLON,JLEV)
    PRAB3C(JLON,JLEV)=ZZA3C(JLON,JLEV)
    PRAB3N(JLON,JLEV)=ZZA3N(JLON,JLEV)
    PRAB4C(JLON,JLEV)=ZZA4C(JLON,JLEV)
    PRAB4N(JLON,JLEV)=ZZA4N(JLON,JLEV)
    ZRAB5C(JLON,JLEV)=ZZA5C(JLON,JLEV)
    ZRAB5N(JLON,JLEV)=ZZA5N(JLON,JLEV)
    PRAB6C(JLON,JLEV)=ZZA5C(JLON,JLEV)
    PRAB6N(JLON,JLEV)=ZZA5N(JLON,JLEV)
  ENDDO
ENDDO

!  Computation of equivalent coefficients a1c,...,a6c and a1n,...,a6n
!  by combining layers 1 and JK

DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA
    ZPOM11(JLON,JLEV)=ZZA1C(JLON,JLEV)
    ZPOM12(JLON,JLEV)=ZZA1N(JLON,JLEV)
    ZPOM21(JLON,JLEV)=ZZA2C(JLON,JLEV)
    ZPOM22(JLON,JLEV)=ZZA2N(JLON,JLEV)
    ZPOM31(JLON,JLEV)=ZZA3C(JLON,JLEV)
    ZPOM32(JLON,JLEV)=ZZA3N(JLON,JLEV)
    ZPOM41(JLON,JLEV)=ZZA4C(JLON,JLEV)
    ZPOM42(JLON,JLEV)=ZZA4N(JLON,JLEV)
    ZPOM51(JLON,JLEV)=ZZA5C(JLON,JLEV)
    ZPOM52(JLON,JLEV)=ZZA5N(JLON,JLEV)
    ZPOM61(JLON,JLEV)=ZZA5C(JLON,JLEV)
    ZPOM62(JLON,JLEV)=ZZA5N(JLON,JLEV)
  ENDDO
ENDDO

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

    DO JJ=KTDIA+2,JLEV
      IF (JJ == (KTDIA+2)) THEN
        ZPOM11(JLON,JJ)=ZZA1C(JLON,JJ-2)*ZZA1C(JLON,JJ-1)
        ZPOM12(JLON,JJ)=ZZA1N(JLON,JJ-2)*ZZA1N(JLON,JJ-1)

        ZPOM21(JLON,JJ)=((1.0_JPRB-ZZA5C(JLON,JJ-2)*ZZA5C(JLON,JJ-1))&
         & *ZZA2C(JLON,JJ-1)*ZZA1C(JLON,JJ-2)&
         & +ZZA4C(JLON,JJ-1)*ZZA2C(JLON,JJ-2)&
         & +ZZA4C(JLON,JJ-1)*ZZA1C(JLON,JJ-2)&
         & *ZZA5C(JLON,JJ-2)*ZZA3C(JLON,JJ-1))&
         & /(1.0_JPRB-ZZA5C(JLON,JJ-2)*ZZA5C(JLON,JJ-1))  
        ZPOM22(JLON,JJ)=((1.0_JPRB-ZZA5N(JLON,JJ-2)*ZZA5N(JLON,JJ-1))&
         & *ZZA2N(JLON,JJ-1)*ZZA1N(JLON,JJ-2)&
         & +ZZA4N(JLON,JJ-1)*ZZA2N(JLON,JJ-2)&
         & +ZZA4N(JLON,JJ-1)*ZZA1N(JLON,JJ-2)&
         & *ZZA5N(JLON,JJ-2)*ZZA3N(JLON,JJ-1))&
         & /(1.0_JPRB-ZZA5N(JLON,JJ-2)*ZZA5N(JLON,JJ-1))  

        ZPOM31(JLON,JJ)=((1.0_JPRB-ZZA5C(JLON,JJ-2)*ZZA5C(JLON,JJ-1))&
         & *ZZA3C(JLON,JJ-2)&
         & +ZZA4C(JLON,JJ-2)*ZZA1C(JLON,JJ-2)&
         & *ZZA3C(JLON,JJ-1)&
         & +ZZA4C(JLON,JJ-2)*ZZA2C(JLON,JJ-2)&
         & *ZZA5C(JLON,JJ-1))&
         & /(1.0_JPRB-ZZA5C(JLON,JJ-2)*ZZA5C(JLON,JJ-1))  
        ZPOM32(JLON,JJ)=((1.0_JPRB-ZZA5N(JLON,JJ-2)*ZZA5N(JLON,JJ-1))&
         & *ZZA3N(JLON,JJ-2)&
         & +ZZA4N(JLON,JJ-2)*ZZA1N(JLON,JJ-2)&
         & *ZZA3N(JLON,JJ-1)&
         & +ZZA4N(JLON,JJ-2)*ZZA2N(JLON,JJ-2)&
         & *ZZA5N(JLON,JJ-1))&
         & /(1.0_JPRB-ZZA5N(JLON,JJ-2)*ZZA5N(JLON,JJ-1))  

        ZPOM41(JLON,JJ)=ZZA4C(JLON,JJ-2)*ZZA4C(JLON,JJ-1)&
         & /(1.0_JPRB-ZZA5C(JLON,JJ-2)*ZZA5C(JLON,JJ-1))  
        ZPOM42(JLON,JJ)=ZZA4N(JLON,JJ-2)*ZZA4N(JLON,JJ-1)&
         & /(1.0_JPRB-ZZA5N(JLON,JJ-2)*ZZA5N(JLON,JJ-1))  

        ZPOM51(JLON,JJ)=(ZZA5C(JLON,JJ-1)&
         & +ZZA5C(JLON,JJ-2)*ZZA4C(JLON,JJ-1)**2 &
         & -ZZA5C(JLON,JJ-2)*ZZA5C(JLON,JJ-1)**2)&
         & /(1.0_JPRB-ZZA5C(JLON,JJ-2)*ZZA5C(JLON,JJ-1))  
        ZPOM52(JLON,JJ)=(ZZA5N(JLON,JJ-1)&
         & +ZZA5N(JLON,JJ-2)*ZZA4N(JLON,JJ-1)**2 &
         & -ZZA5N(JLON,JJ-2)*ZZA5N(JLON,JJ-1)**2)&
         & /(1.0_JPRB-ZZA5N(JLON,JJ-2)*ZZA5N(JLON,JJ-1))  

        ZPOM61(JLON,JJ)=(ZZA5C(JLON,JJ-2)&
         & +ZZA5C(JLON,JJ-1)*ZZA4C(JLON,JJ-2)**2 &
         & -ZZA5C(JLON,JJ-1)*ZZA5C(JLON,JJ-2)**2)&
         & /(1.0_JPRB-ZZA5C(JLON,JJ-2)*ZZA5C(JLON,JJ-1))  
        ZPOM62(JLON,JJ)=(ZZA5N(JLON,JJ-2)&
         & +ZZA5N(JLON,JJ-1)*ZZA4N(JLON,JJ-2)**2 &
         & -ZZA5N(JLON,JJ-1)*ZZA5N(JLON,JJ-2)**2)&
         & /(1.0_JPRB-ZZA5N(JLON,JJ-2)*ZZA5N(JLON,JJ-1))  
      ELSE
        ZPOM11(JLON,JJ)=ZPOM11(JLON,JJ-1)*ZZA1C(JLON,JJ-1)
        ZPOM12(JLON,JJ)=ZPOM12(JLON,JJ-1)*ZZA1N(JLON,JJ-1)

        ZPOM21(JLON,JJ)=((1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ-1))&
         & *ZZA2C(JLON,JJ-1)*ZPOM11(JLON,JJ-1)&
         & +ZZA4C(JLON,JJ-1)*ZPOM21(JLON,JJ-1)&
         & +ZZA4C(JLON,JJ-1)*ZPOM11(JLON,JJ-1)&
         & *ZPOM51(JLON,JJ-1)*ZZA3C(JLON,JJ-1))&
         & /(1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ-1))  
        ZPOM22(JLON,JJ)=((1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ-1))&
         & *ZZA2N(JLON,JJ-1)*ZPOM12(JLON,JJ-1)&
         & +ZZA4N(JLON,JJ-1)*ZPOM22(JLON,JJ-1)&
         & +ZZA4N(JLON,JJ-1)*ZPOM12(JLON,JJ-1)&
         & *ZPOM52(JLON,JJ-1)*ZZA3N(JLON,JJ-1))&
         & /(1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ-1))  

        ZPOM31(JLON,JJ)=((1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ-1))&
         & *ZPOM31(JLON,JJ-1)&
         & +ZPOM41(JLON,JJ-1)*ZPOM11(JLON,JJ-1)&
         & *ZZA3C(JLON,JJ-1)&
         & +ZPOM41(JLON,JJ-1)*ZPOM21(JLON,JJ-1)&
         & *ZZA5C(JLON,JJ-1))&
         & /(1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ-1))  
        ZPOM32(JLON,JJ)=((1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ-1))&
         & *ZPOM32(JLON,JJ-1)&
         & +ZPOM42(JLON,JJ-1)*ZPOM12(JLON,JJ-1)&
         & *ZZA3N(JLON,JJ-1)&
         & +ZPOM42(JLON,JJ-1)*ZPOM22(JLON,JJ-1)&
         & *ZZA5N(JLON,JJ-1))&
         & /(1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ-1))  

        ZPOM41(JLON,JJ)=ZPOM41(JLON,JJ-1)*ZZA4C(JLON,JJ-1)&
         & /(1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ-1))  
        ZPOM42(JLON,JJ)=ZPOM42(JLON,JJ-1)*ZZA4N(JLON,JJ-1)&
         & /(1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ-1))  

        ZPOM51(JLON,JJ)=(ZZA5C(JLON,JJ-1)&
         & +ZPOM51(JLON,JJ-1)*ZZA4C(JLON,JJ-1)**2 &
         & -ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ-1)**2)&
         & /(1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ-1))  
        ZPOM52(JLON,JJ)=(ZZA5N(JLON,JJ-1)&
         & +ZPOM52(JLON,JJ-1)*ZZA4N(JLON,JJ-1)**2 &
         & -ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ-1)**2)&
         & /(1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ-1))  

        ZPOM61(JLON,JJ)=(ZPOM61(JLON,JJ-1)&
         & +ZZA5C(JLON,JJ-1)*ZPOM41(JLON,JJ-1)**2 &
         & -ZZA5C(JLON,JJ-1)*ZPOM61(JLON,JJ-1)&
         & *ZPOM51(JLON,JJ-1))&
         & /(1.0_JPRB-ZPOM51(JLON,JJ-1)*ZZA5C(JLON,JJ-1))  
        ZPOM62(JLON,JJ)=(ZPOM62(JLON,JJ-1)&
         & +ZZA5N(JLON,JJ-1)*ZPOM42(JLON,JJ-1)**2 &
         & -ZZA5N(JLON,JJ-1)*ZPOM62(JLON,JJ-1)&
         & *ZPOM52(JLON,JJ-1))&
         & /(1.0_JPRB-ZPOM52(JLON,JJ-1)*ZZA5N(JLON,JJ-1))  
      ENDIF
    ENDDO

    PRAT1C(JLON,JLEV)=ZPOM11(JLON,JLEV)
    PRAT1N(JLON,JLEV)=ZPOM12(JLON,JLEV)
    PRAT2C(JLON,JLEV)=ZPOM21(JLON,JLEV)
    PRAT2N(JLON,JLEV)=ZPOM22(JLON,JLEV)
    PRAT3C(JLON,JLEV)=ZPOM31(JLON,JLEV)
    PRAT3N(JLON,JLEV)=ZPOM32(JLON,JLEV)
    PRAT4C(JLON,JLEV)=ZPOM41(JLON,JLEV)
    PRAT4N(JLON,JLEV)=ZPOM42(JLON,JLEV)
    PRAT5C(JLON,JLEV)=ZPOM51(JLON,JLEV)
    PRAT5N(JLON,JLEV)=ZPOM52(JLON,JLEV)
    ZRAT6C(JLON,JLEV)=ZPOM61(JLON,JLEV)
    ZRAT6N(JLON,JLEV)=ZPOM62(JLON,JLEV)
  ENDDO
ENDDO

DO JLEV=KTDIA,KTDIA+1
  DO JLON=KIDIA,KFDIA
    PRAT1C(JLON,JLEV)=ZPOM11(JLON,JLEV)
    PRAT1N(JLON,JLEV)=ZPOM12(JLON,JLEV)
    PRAT2C(JLON,JLEV)=ZPOM21(JLON,JLEV)
    PRAT2N(JLON,JLEV)=ZPOM22(JLON,JLEV)
    PRAT3C(JLON,JLEV)=ZPOM31(JLON,JLEV)
    PRAT3N(JLON,JLEV)=ZPOM32(JLON,JLEV)
    PRAT4C(JLON,JLEV)=ZPOM41(JLON,JLEV)
    PRAT4N(JLON,JLEV)=ZPOM42(JLON,JLEV)
    PRAT5C(JLON,JLEV)=ZPOM51(JLON,JLEV)
    PRAT5N(JLON,JLEV)=ZPOM52(JLON,JLEV)
    ZRAT6C(JLON,JLEV)=ZPOM61(JLON,JLEV)
    ZRAT6N(JLON,JLEV)=ZPOM62(JLON,JLEV)
  ENDDO
ENDDO

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