SUBROUTINE APL_AROME ( KBL, KGPCOMP, KIDIA , KFDIA , KLON ,&
 & KTDIA  , KLEV , KGL1 , KGL2 , KSTEP ,&
 & KSGST, PDT,&
 & PGEMU,PGELAM,POROG,PGM,PMU0,PMU0M,PCLON, PSLON,PVO3ABC,PLSM,&
 & PAESEA , PAELAN , PAESOO , PAEDES ,&
 !---------------------------------------------------------------------
 ! - INPUT A M
 & PAPHIM,PAPHIFM,PAPRSM, PAPRSFM, PRDELPM, PDELPM, PTM, PQVM ,&
 & PCPM    , PRM     ,PALPHM , PLNPRM, &
 & PQCM    , PQIM    ,PQRM, PQSM, PQGM, PQHM,  PTKEM,PSIGM,PSVM,&
 & PUM    , PVM, PWM, &
 !---------------------------------------------------------------------
 !  - INOUT A S
 & PGPAR,PEMTD,PEMTU,PTRSO,PTS,&

 !  - OUT A S
 & PCLFS,PSIGS, &
 & PTENDT, PTENDR, PTENDU, PTENDV,PTENDW, PTENDTKE, PTENDEXT,&
 & PFRTH, PFRSO,PFRTHDS, PFRSODS, &
 !---------------------------------------------------------------------
 !  - IN FOR RADIATION IF NO SURFACE SCHEME
 & PALB,PEMIS, &
 !  - INOUT for easy diag
 & PEZDIAG,&
 !  - INOUT for CFU XFU
 & PCLCH,PCLCL,PCLCM,PCLCT,PFPLSL,PFPLSN,PFPLSG,PFPLSH,PSTRTU,PSTRTV,PFCS,PFCLL,&
 & PUCLS,PVCLS,PTCLS,PQCLS,PHUCLS,PUGST,PVGST   )   

!**** *APL_AROME * - CALL OF PHYSICAL PARAMETERISATIONS FOR ALARO/AROME

!     Sujet.
!     ------
!     - APPEL DES SOUS-PROGRAMMES DE PARAMETRISATION

!**   Interface.
!     ----------
!        *CALL* *APL_AROME*

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

! -   ARGUMENTS D'ENTREE.
! -   INPUT ARGUMENTS.
!     -------------------

! - NOM DES PARAMETRES DE DIMENSIONNEMENT DE LA PHYSIQUE.
! - DIMENSIONS.

! KBL  : NUMERO DE BLOC NPROMA
! KBL  : NPROMA-PACKETS NUMBER
! KGPCOMP : NOMBRE TOTAL DE POINTS DE GRILLE SUR LE DOMAINE
! KGPCOMP : TOTAL GRID POINTS NUMBER IN THE DOMAIN
! KIDIA, KFDIA : BORNES BOUCLES HORIZONTALES   (IST,IEND DANS CPG).
! KIDIA, KFDIA : START/END OF HORIZONTAL LOOP  (IST,IEND IN *CPG*).
! KLON : DIMENSION HORIZONTALE                 (NPROMA DANS CPG).
! KLON : HORIZONTAL DIMENSION                  (NPROMA IN *CPG*).
! KTDIA : DEBUT BOUCLE VERTICALE DANS LA PHYSIQUE.
! KTDIA : START OF THE VERTICAL LOOP IN THE PHYSICS (IF SOME LEVELS ARE
!                     SKIPPED AT THE TOP OF THE MODEL).
! KLEV : FIN BOUCLE VERTICE ET DIMENSION VERTICALE (NFLEVG DANS CPG).
! KLEV : END OF VERTICAL LOOP AND VERTICAL DIMENSION(NFLEVG IN *CPG*).
! KGL1, KGL2 : BORNES BANDES LATITUDES CONCATENEES DANS BOUCLE (1,KLON)
! KGL1, KGL2 : START/END CONCATENATED LATITUDES IN VECTOR OF KLON LENGTH
! KSTEP : TIME STEP NUMBER (starting with zero)
! KSGST : RADIATION FLUX DIMENSION
! PDT : TIME STEP (in s) 
!-----------------------------------------------------------------------
! PGEMU      : SINE OF GEOGRAPHICAL LATITUDE
! PGELAM     :  LONGITUDE
! POROG      : g * OROGRAPHY
! PGM        : MAP FACTOR (used in ALARO convection only)
! PMU0       : COSINUS LOCAL INSTANTANE DE L'ANGLE ZENITHAL SOLAIRE.
! PMU0       : LOCAL COSINE OF INSTANTANEOUS SOLAR ZENITH ANGLE.
! PMU0M      : COSINUS LOCAL MOYEN DE L'ANGLE ZENITHAL.
! PMU0M      : LOCAL COSINE OF AVERAGED SOLAR ZENITH ANGLE.
! PCLON      : cosine of geographical longitude.
! PSLON      : sine of geographical longitude.
! PVO3ABC    : OZONE COEFFICIENTS FOR ARPEGE PROFILES
! PLSM       : -ATMOSPHERIC MODEL- LAND-SEA MASK (! MAY BE DIFFERENT FROM 
!              THE SURFACE ONE) 
! PAESEA     : AEROSOLS MARINS (SI NVCLIA >= 4)
! PAESEA     : MARINE AEROSOLS (IF NVCLIA >= 4)
! PAELAN     : AEROSOLS CONTINENTAUX (SI NVCLIA >= 4)
! PAELAN     : CONTINENTAL AEROSOLS (IF NVCLIA >= 4)
! PAESOO     : AEROSOLS CARBONES (SI NVCLIA >= 4)
! PAESOO     : SOOT AEROSOLS (IF NVCLIA >= 4)
! PAEDES     : AEROSOLS DESERTIQUES (SI NVCLIA >= 4)
! PAEDES     : DESERT AEROSOLS (IF NVCLIA >= 4)


! FIELDS WITH SUBSCRIPT M FOR TIME T-DT IN 3TL OR T IN 2TL

! PAPHIM     : GEOPOTENTIAL ON HALF-LEVELS
! PAPHIFM    : GEOPOTENTIAL ON FULL-LEVELS
! PAPRSM     : PRESSURE ON HALF LEVELS
! PAPRSFM    : PRESSURE ON FULL LEVELS.
! PRDELPM    : INVERSE OF PDELP 
! PDELPM     : LAYER THICKNESS IN PRESSURE UNITS

! PTM        : TEMPERATURE.
! PQVM        : SPECIFIC HUMIDITY OF WATER VAPOR
! PCPM        : SPECIFIC HEAT AT CONSTANT PRESSURE FOR AIR
! PRM         : GAS CONSTANT FOR AIR
! PALPHM      : "alpha" on layers
! PLNPRM      : "delta" on layers

! PQCM        : SPECIFIC HUMIDITY OF CLOUD WATER
! PQIM        : SPECIFIC HUMIDITY OF ICE
! PQRM        : SPECIFIC HUMIDITY OF RAIN
! PQSM        : SPECIFIC HUMIDITY OF SNOW
! PQGM        : SPECIFIC HUMIDITY OF GRAUPEL
! PQHM        : SPECIFIC HUMIDITY OF HAIL
! PTKEM       : TURBULENT KINETIC ENERGY
! PSVM        : PASSIVE SCALARS
! PSIGM       : SIGMA FOR SUBGRIDCOND
! PUM         : ZONAL WIND
! PVM         : MERIDIAN WIND
! PWM         : VERTICAL VELOCITY (m/s)

!-----------------------------------------------------------------------
! - INOUT

! PGPAR       : BUFFER FOR 2D FIELDS - CONTAINS PRECIP, ALBEDO, EMISS, TS 
!             : SURFACE FLUXES
! PEMTD       : DOWNWARD LONGWAVE EMISSIVITY
! PEMTU       : UPWARD   LONGWAVE EMISSIVITY
! PTRSO       : SHORTWAVE TRANSMISSIVITY
! PTS         : SURFACE TEMPERATURE
!-----------------------------------------------------------------------
! - OUTPUT (SUBSCRIPT S FOR T+DT)

! PCLFS       : CLOUD FRACTION
! PSIGS       : SIGMA FOR SUBGRIDCOND
! PTENDT      : TEMPERATURE TENDENCY
! PTENDR      : HYDROMETEORE TENDENCIES
! PTENDU      : ZONAL WIND TENDENCY
! PTENDV      : MERIDIAN WIND TENDENCY
! PTENDW      : VERTICAL VELOCITY TENDENCY
! PTENDTKE    : TKE TENDENCY
! PTENDEXT    : PASSIVE SCALARS TENDENCY
! PFRTH       : LONGWAVE RADIATIVE FLUX
! PFRSO       : SHORTWAVE RADIATIVE FLUX
! PFRTH       : LONGWAVE DOWNWARD SURFACE RADIATIVE FLUX
! PFRSO       : SHORTWAVE DOWNWARD SURFACE RADIATIVE FLUX
 

!variables used in input for radiation in case no surface scheme is used 

! PALB       : MODEL SURFACE SHORTWAVE ALBEDO.
! PEMIS      : MODEL SURFACE LONGWAVE EMISSIVITY.

! Part of GFL strcture dedicated to easy diagnostics (to be used as a print...)
! PEZDIAG    : MULPITPLE ARRAY TO BE FILLED BY THE USER BY 3D FIELDS
!              (NGFL_EZDIAG ONES)
! output for CFU XFU
! PCLCH      : HIGH CLOUD COVER (DIAGNOSTIC).
! PCLCL      : LOW CLOUD COVER (DIAGNOSTIC).
! PCLCM      : MEDIUM CLOUD COVER (DIAGNOSTIC).
! PCLCT      : TOTAL CLOUD COVER (DIAGNOSTIC).
! PFPLSL     : RESOLVED PRECIPITATION AS RAIN.
! PFPLSN     : RESOLVED PRECIPITATION AS SNOW
! PFPLSG     : RESOLVED PRECIPITATION AS GRAUPEL
! PFPLSH     : RESOLVED PRECIPITATION AS HAIL
! PSTRTU     : TURBULENT FLUX OF MOMENTUM "U".
! PSTRTV     : TURBULENT FLUX OF MOMENTUM "V".
! PFCS       : SENSIBLE HEAT FLUX AT SURFACE LEVEL.
! PFCLL      : LATENT HEAT FLUX AT SURFACE LEVEL.
! PUCLS      : SORTIE DIAGNOSTIQUE DU VENT EN X A HUV METEO.
! PUCLS      : U-COMPONENT OF WIND AT 10 METERS (DIAGNOSTIC).
! PVCLS      : SORTIE DIAGNOSTIQUE DU VENT EN Y A HUV METEO.
! PVCLS      : V-COMPONENT OF WIND AT 10 METERS (DIAGNOSTIC).
! PTCLS      : SORTIE DIAGNOSTIQUE DE LA TEMPERATURE A HTQ METEO.
! PTCLS      : TEMPERATURE AT 2 METERS (DIAGNOSTIC).
! PQCLS      : SORTIE DIAGNOSTIQUE DE L'HUMIDITE SPECIFIQUE A HTQ METEO.
! PQCLS      : SPECIFIC HUMIDITY AT 2 METERS (DIAGNOSTIC).
! PHUCLS     : SORTIE DIAGNOSTIQUE DE L'HUMIDITE RELATIVE A HTQ METEO.
! PHUCLS     : RELATIVE HUMIDITY AT 2 METERS (DIAGNOSTIC).
! PUGST      : SORTIE DIAGNOSTIQUE DU VENT RAFALE EN X A HUV METEO.
! PUGST      : U-COMPONENT OF WIND GUST AT 10 METERS (DIAGNOSTIC).
! PVGST      : SORTIE DIAGNOSTIQUE DU VENT RAFALE EN Y A HUV METEO.
! PVGST      : V-COMPONENT OF WIND GUST AT 10 METERS (DIAGNOSTIC).

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

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

!     Method
!     ------
!     - convert aladin variables into mesonh variables (level inversion 
!       and q to r, t to theta) 
!     - call mesoNH physics and ECMWF radiation scheme
!     - convert mesoNH tendencies to aladin tendencies

!     Auteur.
!     -------
!      S.Malardel et Y. Seity
!      10-03-03
!      big cleaning (18/06/04) S. Malardel and Y. Seity
!     externalisation of surface scheme call + small cleaning (20-07-04) Y.Seity
!     Modifications
!     -------------
!      G. Hello 04-02-06: Add the call of KFB-convection scheme 
!                         for future use in ALARO
!      T.Kovacic 04-05-05: Added ZCVTENDPR and ZCVTENDPRS 
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!      F.Bouyssel 04-05-05: New arguments in ACRADIN
!     Y. Seity 30-Sept-2005 Add MNH Chemistry scheme
!     R. Zaaboul 15-feb-2006 add surface scheme call
!     T.Kovacic  2006-03-23: calls to subroutines for budgets 
!                             and new arguments PFRTH and PFRSO
!     Y. Seity   2007-05-07: add CFU and XFU calculations 
!                           and call aro_ground_diag
!     S.Ivatek-S 2007-04-17: Over dimensioning of PGPAR by NGPAR+1 just 
!                            (KLON,NGPAR) is used boundary checking bf
!     T.Kovacic  2007-03-16: Fourth dim. in APFT
!     JJMorcrette, ECMWF, 20080325: dummy arguments for RADACT to allow for 
!                        using a new sulphate climatology in the ECMWF model
!     Y. Seity   2008-06-15: correct calculations of PFRTHDS, PFRSODS and PFCLL
!     Y. Seity   2008-09-29: phasing Chemistry corrections
!     O.Riviere  2008-10-01: introduction of new data flow for DDH in Arome
!     Y. Seity   2009-05-03: new version of EDKF and implementation of EDMF
!     End modifications
!     --------------------------------------------------------------------------

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

! AROME SPECIFIC
USE YOMARAR   ,ONLY : NGPAR    ,NRR      ,NSV      ,MINPRR   ,MINPRS   , &
   &        MINPRG   ,MACPRR   ,MACPRG   ,MACPRS   , &
   &        LDIAGWMAX,NDIAGWMAX,LOSUBG_AUCV        ,LOSIGMAS , &
   &        LOSUBG_COND        ,NSWB_MNH ,MSWDIR   ,MSWDIF   ,MALBDIR  , &
   &        MALBSCA  ,MVEMIS   ,MVTS     ,NPRINTFR ,NPTP     ,LSQUALL  , &
   &        NRRI     ,NRRL     ,LOWARM   ,NSPLITR  ,NREFROI2 ,NREFROI1 , &
   &        XSW_BANDS,MVQS     , &
   &        LOSEDIC  ,CMF_UPDRAFT, CMF_CLOUD, LMIXUV
USE YOMARPHY  ,ONLY : LMICRO   ,LTURB    ,LMSE     ,LKFBCONV ,LUSECHEM , &
   &        LRDUST   ,LMPA     ,CCOUPLING, LRCO2,LMFSHAL,LRDEPOS

! OTHERS
USE YOMCST   , ONLY : RG       ,RCPD     ,RD       ,RATM     ,RTT      , &
   &        RCW      ,RCPV     ,RLVTT    ,RCS      ,RLSTT    ,RGAMW    , &
   &        RBETW    ,RALPW    ,RGAMS    ,RBETS    ,RALPS    ,RGAMD    , &
   &        RBETD    ,RALPD    ,RETV     ,RV
USE YOERAD   , ONLY : NAER     ,NMODE    ,NRADFR   ,NSW      ,NOZOCL
USE YOERDI   , ONLY : RCARDI
USE YOMPHY   , ONLY : LRAYFM   ,LO3ABC   ,LRNUMX
USE YOMPHY2  , ONLY : NTSHM    ,NTSML  
USE YOMLDDH  , ONLY : LFLEXDIA
USE SURFACE_FIELDS_MIX     , ONLY : YSD_VAD
USE YOMTOPH  , ONLY : NTQSAT  
USE YOMLUN   , ONLY : NULOUT
USE YOMCT0   , ONLY : LTWOTL
USE YOMGEM   , ONLY : NGPTOT 
USE YOMRIP   , ONLY : NINDAT   ,RHGMT   ,RSOVR    ,RCODEC   ,RSIDEC
USE YOM_YGFL , ONLY : NGFL_EXT ,NGFL_EZDIAG
USE YOMNSV   , ONLY : NSV_CO2
USE YOMDIM   , ONLY : NPROMA
USE DDH_MIX, ONLY: ADD_FIELD_3D ! for new diag data flow

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KLON
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEV
INTEGER(KIND=JPIM),INTENT(IN)    :: KBL 
INTEGER(KIND=JPIM),INTENT(IN)    :: KGPCOMP 
INTEGER(KIND=JPIM),INTENT(IN)    :: KIDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KTDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KGL1 
INTEGER(KIND=JPIM),INTENT(IN)    :: KGL2
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTEP 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSGST ! Argument NOT used
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDT 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEMU(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGELAM(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGM(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROG(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMU0(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMU0M(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLON(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSLON(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVO3ABC(KLON,3) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLSM(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAESEA(KLON)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAELAN(KLON)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAESOO(KLON)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAEDES(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHIM(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHIFM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRSM(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRSFM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDELPM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDELPM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQVM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCPM(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALPHM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPRM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQCM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQIM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQRM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQSM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQGM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQHM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTKEM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSVM(KLON,KLEV,NGFL_EXT)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSIGM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PWM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGPAR(KLON,NGPAR+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEMTD(KLON,0:KLEV)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEMTU(KLON,0:KLEV)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTRSO(KLON,0:KLEV)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTS(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLFS(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSIGS(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTENDT(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTENDR(KLON,KLEV,NRR) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTENDU(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTENDV(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTENDW(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTENDTKE(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTENDEXT(KLON,KLEV,NGFL_EXT)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALB(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRTH(KLON,0:KLEV,KSGST+1)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRSO(KLON,0:KLEV,KSGST+1)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRTHDS(KLON)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRSODS(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIS(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEZDIAG(KLON,KLEV,NGFL_EZDIAG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCLCH(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCLCL(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCLCM(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCLCT(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLSL(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLSN(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLSG(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLSH(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRTU(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRTV(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCS(KLON,KSGST+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCLL(KLON,KSGST+1)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUCLS(KLON)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVCLS(KLON)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTCLS(KLON)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQCLS(KLON)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PHUCLS(KLON)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUGST(KLON)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVGST(KLON)

!*
!     ------------------------------------------------------------------
!     DECLARATION DES TABLEAUX ARGUMENTS
! pour le rayonnement
!!    LOCAL VARIABLES :

!    4D arrays
REAL(KIND=JPRB), DIMENSION (KLON,1,KLEV+2,NRR) :: ZZI_RM, ZZI_RS, ZZI_RSAVE
!    3D arrays
REAL(KIND=JPRB), DIMENSION (KLON,1,KLEV+2) :: ZZZ, ZZZF, ZZI_PABSM, ZZI_THM, &
                & ZZI_THS, ZCIT, ZZI_MFM, ZZI_EXNREFM, ZZI_SIGM, ZZI_SIGS, &
                & ZZI_THSAVE, ZNEBMNH,ZEVAP
REAL(KIND=JPRB), DIMENSION (KLON,KLEV) ::  ZQDM, ZQV,ZGEOSLC

!    2D arrays
REAL(KIND=JPRB), DIMENSION (KLON,1) :: ZINPRR, ZACPRR, ZINPRS, ZACPRS, ZINPRG
REAL(KIND=JPRB), DIMENSION (KLON,1) :: ZACPRG, ZINPRR_NOTINCR, ZINPRS_NOTINCR
REAL(KIND=JPRB), DIMENSION (KLON,1) :: ZINPRG_NOTINCR,ZINPRH_NOTINCR,ZINPRH
REAL(KIND=JPRB), DIMENSION (KLON,1) :: ZLAT, ZLON, ZZENITH, ZZS, ZALB_UV
REAL(KIND=JPRB) :: ZEMIS (KLON)
!    Integers
INTEGER(KIND=JPIM) :: JLEV, JLON, JRR, JGFL
INTEGER (KIND=JPIM) :: IPOS,IOFF_MFSHAL, IEZDIAG_CHEM
INTEGER(KIND=JPIM) :: IMODE,JCHA,&
 & JSG,JL, JJ ,JK, JR, IFLUX, IRAD
INTEGER(KIND=JPIM) :: ILONMNH   ! useful size of klon arrays for mesonh physics
INTEGER(KIND=JPIM) :: ILEVFX    ! position de la pleine couche numero KLEV dans 
                                ! les tableaux a rangement vertical inverse

!       Real
REAL(KIND=JPRB) :: ZDT, ZDT2, ZINVDT, ZINVG, ZRSCP, ZINVATM, Z_WMAX, Z_WMIN, ZB1
REAL(KIND=JPRB) :: ZALBD(KLON,NSW), ZALBP(KLON,NSW),ZALB(KLON)
REAL(KIND=JPRB) :: ZTSURF(KLON),ZQS(KLON), ZGZ0(KLON), ZGZ0H(KLON) 
REAL(KIND=JPRB) :: ZFCLL(KLON), ZFCLN(KLON)
REAL(KIND=JPRB) :: ZQSAT(KLON,KLEV)
REAL(KIND=JPRB) :: ZLH(KLON,KLEV), ZLSCPE(KLON,KLEV)
REAL(KIND=JPRB) :: ZQW(KLON,KLEV), ZTW(KLON,KLEV), ZRH(KLON,KLEV)
REAL(KIND=JPRB) :: ZFRSODS(KLON), ZFRTHDS(KLON)
REAL(KIND=JPRB) :: ZFSDNN(KLON), ZFSDNV(KLON)
REAL(KIND=JPRB) :: ZQICE(KLON,KLEV), ZQLI(KLON,KLEV)
REAL(KIND=JPRB) :: ZQO3(KLON,0:KLEV), ZKAPM(KLON,KLEV)
REAL(KIND=JPRB) :: ZAER(KLON,KLEV,6), ZRAER(KLON,KLEV,6)
REAL(KIND=JPRB) :: ZAERD(KLON,KLEV)
REAL(KIND=JPRB) :: ZCARDI
REAL(KIND=JPRB) :: ZROZ(NGPTOT,KLEV)
REAL(KIND=JPRB) :: ZCHTIX(NGPTOT+2,KLEV+1), ZDUM(NGPTOT+2,KLEV)
REAL(KIND=JPRB) :: ZTENT(KLON,KLEV)
REAL(KIND=JPRB) :: ZTRSOD(KLON)
REAL(KIND=JPRB) :: ZCEMTR(KLON,KLEV+1), ZCTRSO(KLON,KLEV+1), ZFRSOC(KLON,2)
REAL(KIND=JPRB) :: ZFRTHC(KLON,2), ZSUDU(KLON), ZSDUR(KLON), ZDSRP(KLON)
REAL(KIND=JPRB) :: ZAESEA(KLON), ZAELAN(KLON), ZAESOO(KLON), ZAEDES(KLON)
REAL(KIND=JPRB) :: ZTM(KLON,KLEV), ZQVM(KLON,KLEV), ZQIM(KLON,KLEV)
REAL(KIND=JPRB) :: ZQCM(KLON,KLEV),ZQHM(KLON,KLEV), ZQHGM(KLON,KLEV)
REAL(KIND=JPRB) :: ZQRM(KLON,KLEV), ZQSM(KLON,KLEV), ZQGM(KLON,KLEV)
REAL(KIND=JPRB) :: ZCPM(KLON,KLEV), ZRHM(KLON,KLEV)
REAL(KIND=JPRB) :: ZZI_APHIM(KLON,0:KLEV), ZZI_APHIFM(KLON,KLEV)
! POUR GROUND 
REAL(KIND=JPRB) :: ZZSFSWDIR(KLON,NSW), ZZSFSWDIF(KLON,NSW)
REAL(KIND=JPRB) :: ZDEPTH_HEIGHT_LOW(KLON,KLEV)
! Variables concerning updraft rain/snow for EDMF
REAL(KIND=JPRB) :: TENDTUP(KLON,KLEV)
REAL(KIND=JPRB) :: TENDQVUP(KLON,KLEV)
REAL(KIND=JPRB) :: SURFPREP(KLON)
REAL(KIND=JPRB) :: SURFSNOW(KLON)
REAL(KIND=JPRB) :: SURFRHO(KLON)
! AJOUT POUR TURB
!    4D arrays
REAL(KIND=JPRB),  DIMENSION(KLON,1,KLEV+2,NGFL_EXT):: ZZI_SVS, ZZI_SVM
REAL(KIND=JPRB),  DIMENSION (KLON,KLEV,NGFL_EZDIAG):: ZZI_PEZDIAG

!    3D arrays
REAL(KIND=JPRB), DIMENSION (KLON,1,KLEV+2) :: ZTHVREFM  ! thetav de l etat 
  ! de reference dans mesoNH. En 1D, thetavref=thetavM, mais la question
  ! concernant la facon d initialiser cette variable dans le 3D reste ouverte. 
  ! (idem pour RHODREF)
REAL(KIND=JPRB), DIMENSION (KLON,1,KLEV+2) :: ZZI_RHODREFM, ZZI_RHODJM, ZZI_RHO
REAL(KIND=JPRB), DIMENSION (KLON,1,KLEV+2) :: ZZI_UM,ZZI_VM,ZZI_WM,&
                & ZZI_US, ZZI_VS, ZZI_WS, ZZI_USAVE, ZZI_VSAVE, ZZI_WSAVE  

REAL(KIND=JPRB), DIMENSION (KLON,1,KLEV+2) :: ZZI_TKEM, ZZI_TKES, ZZI_TKESAVE
REAL(KIND=JPRB), DIMENSION (KLON,1,KLEV+2) :: ZSRCS 
REAL(KIND=JPRB), DIMENSION (KLON,KLEV+2) :: ZZI_CVTENDT, ZZI_CVTENDRV,&
                & ZZI_CVTENDRC, ZZI_CVTENDRI, ZZI_MFS

REAL(KIND=JPRB), DIMENSION (KLON) :: ZCVTENDPR, ZCVTENDPRS

REAL(KIND=JPRB), DIMENSION(:,:,:), ALLOCATABLE :: ZEPSM ! Dissipation of TKE 
                                                     ! (eps) at time t-dt
REAL(KIND=JPRB), DIMENSION(:,:,:), ALLOCATABLE :: ZEPSS ! Dissipation  
                                                     ! of TKE at time t+dt
!    2D arrays
REAL(KIND=JPRB), DIMENSION(:,:),   ALLOCATABLE :: ZSFU  ! surface flux of x and
REAL(KIND=JPRB), DIMENSION(:,:),   ALLOCATABLE :: ZSFV  ! y component of wind
REAL(KIND=JPRB), DIMENSION(:,:),   ALLOCATABLE :: ZSFTH ! surface flux of theta
REAL(KIND=JPRB), DIMENSION(:,:),   ALLOCATABLE :: ZSFRV ! surface flux of vapor
REAL(KIND=JPRB), DIMENSION(:,:,:), ALLOCATABLE :: ZSFSV ! surf. flux of scalars
REAL(KIND=JPRB), DIMENSION(:,:),   ALLOCATABLE :: ZSFCO2 ! surface flux of CO2
REAL(KIND=JPRB) :: ZHOOK_HANDLE
LOGICAL :: LLD_NBLOCKTOT ! F par defaut, T pour traiter tous les blocs NPROMA
 ! dans un seul appel a aro_ground_param (comme dans surfext)
REAL(KIND=JPRB),  DIMENSION(KLON,1,KLEV+2,NGFL_EXT):: ZZI_SVSAVE
INTEGER (KIND=JPIM) :: IDAY,IYEAR,IMONTH
REAL(KIND=JPRB), DIMENSION(KLON,KLEV,NSWB_MNH):: ZPIZA_DST !Single scattering
                                             ! albedo of dust (points,lev,wvl)
REAL(KIND=JPRB), DIMENSION(KLON,KLEV,NSWB_MNH):: ZCGA_DST  !Assymetry factor
                                             ! for dust (points,lev,wvl)
REAL(KIND=JPRB), DIMENSION(KLON,KLEV,NSWB_MNH):: ZTAUREL_DST !tau/tau_{550} 
                                             !dust (points,lev,wvl)
 ! pas de temps pour la surface externalise
REAL(KIND=JPRB) :: ZDTMSE
REAL(KIND=JPRB), DIMENSION(:), ALLOCATABLE :: ZCFAQ, ZCFBQ, ZCFATH
REAL(KIND=JPRB), DIMENSION(:), ALLOCATABLE :: ZCFBTH, ZCFAU
REAL(KIND=JPRB), DIMENSION(:), ALLOCATABLE :: ZCFBU, ZCFBV
! Ajout pour MF scheme (Pergaud et al)
REAL(KIND=JPRB), DIMENSION (KLON,1,KLEV+2) :: ZSIGMF, ZRC_MF, ZCF_MF, ZFLXZTHVMF
REAL(KIND=JPRB), DIMENSION (KLON,1,KLEV+2) :: ZFLXZTHVMF_SUM
! Ajout pour MF Dual Scheme (KNMI et al)
! Updraft characteristics in Arpege/IFS world
REAL(KIND=JPRB), DIMENSION(:,:,:), ALLOCATABLE :: ZMF_UP, ZTHETAL_UP, ZQT_UP, &
  &   ZQC_UP, ZQI_UP, ZU_UP, ZV_UP,ZTHTV_UP
REAL(KIND=JPRB), DIMENSION (KLON) :: ZZSFTH,ZZSFRV,ZZSFU,ZZSFV
INTEGER(KIND=JPIM) :: IDRAFT,JDRAFT,NDRAFT
! Updraft characteristics for Meso-NH world (input of ARO_SHALLOW_MF)
REAL(KIND=JPRB), DIMENSION (KLON,1,KLEV+2)::ZZI_MF_UP,ZZI_THETAL_UP,ZZI_RT_UP,&
                ZZI_RC_UP,ZZI_RI_UP,ZZI_ZU_UP,ZZI_ZV_UP,ZZI_THETAV_UP

! specific to new data flow for diagnostics
REAL(KIND=JPRB)   :: ZTENDBKP(KLON,KLEV),ZTMPAF(KLON,KLEV)
CHARACTER(LEN=11) :: CLNAME
CHARACTER(LEN=2),DIMENSION(6):: CLVARNAME=&
&(/"QV","QL","QR","QI","QS","QG"/)

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

#include "abor1.intfb.h"
#include "acradin.intfb.h"
#include "actqsat.intfb.h"
#include "bri2acconv.intfb.h"
#include "gpgeo.intfb.h"
#include "gprcp.intfb.h"
#include "radheat.intfb.h"
#include "suozon.intfb.h"
#include "radaer.intfb.h"
#include "radact.intfb.h"
#include "radozc.intfb.h"
#include "arocldia.intfb.h"
#include "aro_rain_ice.h"
#include "aro_turb_mnh.h"
#include "aro_adjust.h"
#include "aro_mnhc.h"
#include "aro_mnhdust.h"
#include "aro_startbu.h"
#include "aro_convbu.h"
#include "aro_ground_param.h"
#include "aro_ground_diag.h"
#include "aro_shallow_mf.h"
#include "vdfhghthl.intfb.h"
#include "aro_rainaero.h"

!     ------------------------------------------------------------------
#include "fcttrm.h"
!     --------------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('APL_AROME',0,ZHOOK_HANDLE)
!     --------------------------------------------------------------------------

!    ------------------------------------------------------------------
!     1 - Initialisations
!    - --------------------------------------------------------------------
!        1.1 necessary allocations

! necessary if fourth dim = 0

ALLOCATE(ZCFAQ(KLON))
ALLOCATE(ZCFBQ(KLON))
ALLOCATE(ZCFATH(KLON))
ALLOCATE(ZCFBTH(KLON))
ALLOCATE(ZCFAU(KLON))
ALLOCATE(ZCFBU(KLON))
ALLOCATE(ZCFBV(KLON))
NSV=0
IPOS=1

! case  CTURBLEN =/ KEPS (anyway, option KEPS does not work well in MNH)
ALLOCATE(ZEPSM (0,0,0))
ALLOCATE(ZEPSS (0,0,0))

!        1.2 allocations of variables used in more than one parameterization

ALLOCATE(ZSFU  (KLON,1))         ! surface schemes + turbulence
ALLOCATE(ZSFV  (KLON,1))
ALLOCATE(ZSFTH (KLON,1))
ALLOCATE(ZSFRV (KLON,1))

ALLOCATE(ZSFSV (KLON,1,NGFL_EXT))
ALLOCATE(ZSFCO2 (KLON,1))

!         1.3 time step initialisation
!             the mesoNH physics (turb and microphysics) is written 
!             for leap frog scheme
!             !!! be carefull for 2TL or 3TL 

IF (LTWOTL) THEN
  ZDT=PDT/2._JPRB
ELSE
  IF (KSTEP/=0) THEN
    ZDT=PDT/2._JPRB
  ELSE
    ZDT=PDT
  ENDIF
ENDIF

ZINVDT=1/PDT

! initialisation de ZDTMSE

ZDTMSE=PDT

!  SETUP OF TENDENCIES

PTENDT=0.0_JPRB
PTENDU=0.0_JPRB
PTENDV=0.0_JPRB
PTENDW=0.0_JPRB
PTENDR=0.0_JPRB
PTENDTKE=0.0_JPRB
PTENDEXT=0.0_JPRB
!  FIELDS TO BE ADJUSTED (local arrays modified by ac_adjust)

ZQVM=PQVM
ZQIM=PQIM
ZQCM=PQCM
ZQRM=PQRM
ZQSM=PQSM
ZQGM=PQGM
IF (NRR==7) THEN
  ZQHM=PQHM
ELSE
  ZQHM=0._JPRB
ENDIF 
ZTM=PTM
ZZI_APHIM=PAPHIM
ZZI_APHIFM=PAPHIFM

!  SIZE OF ARRAY FOR TURB AND Microphysics
ILONMNH=KFDIA-KIDIA+1

!  SETUP

ZQSAT=0.0_JPRB
PFRSO=0.0_JPRB
ZFRSODS=0.0_JPRB
ZFRTHDS=0.0_JPRB
ZLH=0.0_JPRB
ZLSCPE=0.0_JPRB
ZGEOSLC=0.0_JPRB
ZQW=0.0_JPRB
ZRH=0.0_JPRB
ZTW=0.0_JPRB
ZZI_UM=0.0_JPRB
ZZI_VM=0.0_JPRB
ZZI_WM=0.0_JPRB
ZZI_THM=293._JPRB
ZZI_RM=0.0_JPRB
ZZI_SVM=0.0_JPRB
ZZI_RHODREFM=1.0_JPRB
ZZI_RHO=1.0_JPRB
ZZI_PABSM=101325._JPRB
ZZZ=0.0_JPRB
ZINPRR=0.0_JPRB
ZINPRS=0.0_JPRB
ZINPRG=0.0_JPRB
ZINPRH=0.0_JPRB
ZACPRR=0.0_JPRB
ZACPRS=0.0_JPRB
ZACPRG=0.0_JPRB
ZEVAP=0.0_JPRB
ZINPRR_NOTINCR=0.0_JPRB
ZINPRS_NOTINCR=0.0_JPRB
ZINPRG_NOTINCR=0.0_JPRB
ZINPRH_NOTINCR=0.0_JPRB
ZSFTH=0.0_JPRB
ZSFRV=0.0_JPRB
ZSFCO2=0.0_JPRB
ZEMIS=1.0_JPRB
ZQICE=0.0_JPRB
ZQLI=0.0_JPRB
ZQO3=0.0_JPRB
ZAER=0.0_JPRB
ZAERD=0.0_JPRB
ZPIZA_DST  = 0.0_JPRB
ZCGA_DST   = 0.0_JPRB
ZTAUREL_DST = 1E-12_JPRB
ZCARDI=0.0_JPRB
ZTENT=0.0_JPRB
ZTRSOD=0.0_JPRB
ZCEMTR=0.0_JPRB
ZCTRSO=0.0_JPRB
ZFRSOC=0.0_JPRB
ZFRTHC=0.0_JPRB 
ZSUDU=0.0_JPRB   
ZSDUR=0.0_JPRB
ZDSRP=0.0_JPRB
ZALBD=0.0_JPRB
ZALBP=0.0_JPRB
ZZSFSWDIR=0.0_JPRB
ZZSFSWDIF=0.0_JPRB
ZQV=0.0_JPRB
ZSFU=0.0_JPRB
ZSFV=0.0_JPRB
ZSFSV=0.0_JPRB
ZNEBMNH=0.0_JPRB
ZSRCS=0.0_JPRB
ZZI_MFM=0.0_JPRB
ZZI_MFS=0.0_JPRB
ZZI_SIGM=0.0_JPRB
ZZI_SIGS=0.0_JPRB
ZSIGMF=0.0_JPRB
ZRC_MF=0.0_JPRB
ZCF_MF=0.0_JPRB
ZFLXZTHVMF=0.0_JPRB
ZFLXZTHVMF_SUM=0.0_JPRB
ZZI_SVS=0.0_JPRB


!initialisation of first useful field for EZDIAG use in Chemistry/Dust
IOFF_MFSHAL=1

DO JLEV = KTDIA, KLEV
  DO JLON = KIDIA, KFDIA
    ZCPM(JLON,JLEV)=PCPM(JLON,JLEV)
  ENDDO
ENDDO
DO JCHA = 1, 6
  DO JLEV = KTDIA, KLEV
    DO JLON = KIDIA, KFDIA
      ZAER(JLON,JLEV,JCHA)=0.0_JPRB
    ENDDO
  ENDDO
ENDDO

!    ------------------------------------------------------------------
!     2 - CHANGEMENTS DE VARIABLES ET INVERSION DES NIVEAUX 
!     --------------------------------------------------------------------
IF (LMICRO.OR.LTURB.OR.LMSE.OR.LKFBCONV) THEN

  ZINVG=1/RG 
  !initialisation de ZZZ
  DO JLEV = 2 , KLEV+2
    DO JLON = KIDIA,KFDIA
      ZZZ(JLON,1,JLEV)=ZZI_APHIM(JLON,KLEV+2-JLEV)*ZINVG
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZZ(JLON,1,1)=2*ZZZ(JLON,1,2)-ZZZ(JLON,1,3)
  ENDDO
  !initialisation de ZZZF
  DO JLEV = 2 , KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZZF(JLON,1,JLEV)=ZZI_APHIFM(JLON,KLEV+2-JLEV)*ZINVG
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZZF(JLON,1,1)=1.5_JPRB*ZZZ(JLON,1,2)-0.5_JPRB*ZZZ(JLON,1,3)
    ZZZF(JLON,1,KLEV+2)=ZZZF(JLON,1,KLEV+1)+ (ZZZ(JLON,1,KLEV+2)-ZZZ(JLON,1,KLEV+1))
  ENDDO
   
   !initialisation de qdm (utile localement pour calculer rho  
   !et convertir q en r 
  DO JLEV=1,KLEV
    DO JLON= KIDIA, KFDIA
      ZQDM(JLON,JLEV)=1._JPRB-ZQVM(JLON,JLEV)-ZQCM(JLON,JLEV)-ZQRM(JLON,JLEV) &
       & -ZQIM(JLON,JLEV)-ZQSM(JLON,JLEV)-ZQGM(JLON,JLEV)-ZQHM(JLON,JLEV)   
    ENDDO
  ENDDO
   
   !initialisation de ZZI_RHODREFM (=qd*zrho) 
  DO JLEV = 2 , KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_RHO(JLON,1,JLEV)=PAPRSFM(JLON,KLEV+1+1-JLEV)/&
       & (PRM(JLON,KLEV+1+1-JLEV)*ZTM(JLON,KLEV+1+1-JLEV))
      ZZI_RHODREFM(JLON,1,JLEV)=ZZI_RHO(JLON,1,JLEV)*ZQDM(JLON,KLEV+1+1-JLEV)
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_RHODREFM(JLON,1,1)=ZZI_RHODREFM(JLON,1,2)
    ZZI_RHODREFM(JLON,1,KLEV+2)=ZZI_RHODREFM(JLON,1,KLEV+1)
    ZZI_RHO(JLON,1,1)=ZZI_RHO(JLON,1,2)
    ZZI_RHO(JLON,1,KLEV+2)=ZZI_RHO(JLON,1,KLEV+1)
  ENDDO

  !initialisation de RHODJM 
  DO JLEV = 2 , KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_RHODJM(JLON,1,JLEV)=PDELPM(JLON,KLEV+1+1-JLEV)*ZINVG
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_RHODJM(JLON,1,1) = ZZI_RHODJM(JLON,1,2)
    ZZI_RHODJM(JLON,1,KLEV+2) = ZZI_RHODJM(JLON,1,KLEV+1)
  ENDDO
   
  !initialisation de ZZI_EXNREFM
  ZRSCP=RD/RCPD
  ZINVATM=1/RATM
  DO JLEV = 2 , KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_EXNREFM(JLON,1,JLEV)=(PAPRSFM(JLON,KLEV+2-JLEV)*ZINVATM)**(ZRSCP)
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_EXNREFM(JLON,1,1)=ZZI_EXNREFM(JLON,1,2)
    ZZI_EXNREFM(JLON,1,KLEV+2)=ZZI_EXNREFM(JLON,1,KLEV+1)
  ENDDO
   
  !initialisation de ZZI_PABSM
  DO JLON = KIDIA,KFDIA
    DO JLEV = 2 , KLEV+1
      ZZI_PABSM(JLON,1,JLEV)=PAPRSFM(JLON,KLEV+1+1-JLEV)
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_PABSM(JLON,1,1)= ZZI_PABSM(JLON,1,2)
    ZZI_PABSM(JLON,1,KLEV+2)= ZZI_PABSM(JLON,1,KLEV+1)
  ENDDO

!!! initialisation des variables d etat MNH �t-dt

 ! vent horizontal et TKE
  DO JLEV = 2 , KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_UM(JLON,1,JLEV)= PUM(JLON,KLEV+1+1-JLEV)
      ZZI_VM(JLON,1,JLEV)= PVM(JLON,KLEV+1+1-JLEV)
      ZZI_WM(JLON,1,JLEV)= PWM(JLON,KLEV+1+1-JLEV)
      ZZI_TKEM(JLON,1,JLEV)= PTKEM(JLON,KLEV+1+1-JLEV)
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_UM(JLON,1,1)= ZZI_UM(JLON,1,2)
    ZZI_UM(JLON,1,KLEV+2)= ZZI_UM(JLON,1,KLEV+1)
    ZZI_VM(JLON,1,1)= ZZI_VM(JLON,1,2)
    ZZI_VM(JLON,1,KLEV+2)= ZZI_VM(JLON,1,KLEV+1)
    ZZI_WM(JLON,1,1)= ZZI_WM(JLON,1,2)
    ZZI_WM(JLON,1,KLEV+2)= ZZI_WM(JLON,1,KLEV+1)
    ZZI_TKEM(JLON,1,1)= ZZI_TKEM(JLON,1,2)
    ZZI_TKEM(JLON,1,KLEV+2)= ZZI_TKEM(JLON,1,KLEV+1)
  ENDDO
  !initialise sigma for subgrid condensation comming
  !from previous time step turbulence scheme
  IF (LOSIGMAS) THEN
    DO JLEV = 2 , KLEV+1
      DO JLON = KIDIA,KFDIA
        ZZI_SIGM(JLON,1,JLEV)= PSIGM(JLON,KLEV+1+1-JLEV)
      ENDDO
    ENDDO
    DO JLON = KIDIA,KFDIA
      ZZI_SIGM(JLON,1,1)= ZZI_SIGM(JLON,1,2)
      ZZI_SIGM(JLON,1,KLEV+2)= ZZI_SIGM(JLON,1,KLEV+1)
    ENDDO
  ENDIF
  !initialise convective mas flux for subgrid condensation comming 
  !from previous time step convection scheme
  IF ( LKFBCONV.AND.LOSUBG_COND.AND..NOT.LOSIGMAS) THEN
    DO JLEV = 2 , KLEV+1
      DO JLON = KIDIA,KFDIA
        ZZI_MFM(JLON,1,JLEV)=PSIGM(JLON,KLEV+1+1-JLEV) 
      ENDDO
    ENDDO
    DO JLON = KIDIA,KFDIA
      ZZI_MFM(JLON,1,1)=ZZI_MFM(JLON,1,2) 
      ZZI_MFM(JLON,1,KLEV+2)= ZZI_MFM(JLON,1,KLEV+1)
    ENDDO
  ENDIF
!!! initialisation des variables d etat MNH �t

  !initialisation de ZZI_THM
  DO JLEV = 2 , KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_THM(JLON,1,JLEV)=ZTM(JLON,KLEV+1+1-JLEV)/ZZI_EXNREFM(JLON,1,JLEV)
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_THM(JLON,1,1)= ZZI_THM(JLON,1,2)
    ZZI_THM(JLON,1,KLEV+2)= ZZI_THM(JLON,1,KLEV+1)
  ENDDO

  !initialisation de ZZI_RM pour les hydrometeores (ri=qi/qd)
  DO JLEV = 2, KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_RM(JLON,1,JLEV,1)=ZQVM(JLON,KLEV+1+1-JLEV)&
       & /ZQDM(JLON,KLEV+1+1-JLEV)  
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_RM(JLON,1,1,1)=0._JPRB
    ZZI_RM(JLON,1,KLEV+2,1)=0._JPRB
  ENDDO
   
  DO JLEV = 2, KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_RM(JLON,1,JLEV,2)=ZQCM(JLON,KLEV+1+1-JLEV)&
       & /ZQDM(JLON,KLEV+1+1-JLEV)  
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_RM(JLON,1,1,2)=0._JPRB
    ZZI_RM(JLON,1,KLEV+2,2)=0._JPRB
  ENDDO
   
  DO JLEV = 2, KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_RM(JLON,1,JLEV,3)=ZQRM(JLON,KLEV+1+1-JLEV)&
       & /ZQDM(JLON,KLEV+1+1-JLEV)  
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_RM(JLON,1,1,3)=0._JPRB
    ZZI_RM(JLON,1,KLEV+2,3)=0._JPRB
  ENDDO
   
  DO JLEV = 2, KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_RM(JLON,1,JLEV,4)=ZQIM(JLON,KLEV+1+1-JLEV)&
       & /ZQDM(JLON,KLEV+1+1-JLEV)  
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_RM(JLON,1,1,4)=0._JPRB
    ZZI_RM(JLON,1,KLEV+2,4)=0._JPRB
  ENDDO
   
  DO JLEV = 2, KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_RM(JLON,1,JLEV,5)=ZQSM(JLON,KLEV+1+1-JLEV)&
       & /ZQDM(JLON,KLEV+1+1-JLEV)  
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_RM(JLON,1,1,5)=0._JPRB
    ZZI_RM(JLON,1,KLEV+2,5)=0._JPRB
  ENDDO
   
  DO JLEV = 2, KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_RM(JLON,1,JLEV,6)=ZQGM(JLON,KLEV+1+1-JLEV)&
       & /ZQDM(JLON,KLEV+1+1-JLEV)  
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_RM(JLON,1,1,6)=0._JPRB
    ZZI_RM(JLON,1,KLEV+2,6)=0._JPRB
  ENDDO
  
  IF (NRR==7) THEN
    DO JLEV = 2, KLEV+1
      DO JLON = KIDIA,KFDIA
        ZZI_RM(JLON,1,JLEV,7)=ZQHM(JLON,KLEV+1+1-JLEV)&
         & /ZQDM(JLON,KLEV+1+1-JLEV)  
      ENDDO
    ENDDO
    DO JLON = KIDIA,KFDIA
      ZZI_RM(JLON,1,1,7)=0._JPRB
      ZZI_RM(JLON,1,KLEV+2,7)=0._JPRB
    ENDDO
  ENDIF
   
  IF (NRR==6) THEN
    !initialisation de ZTHVREFM
    DO JLEV = 2 , KLEV+1
      DO JLON = KIDIA,KFDIA
        ZTHVREFM(JLON,1,JLEV)=ZZI_THM(JLON,1,JLEV)*&
         & (1._JPRB+ZZI_RM(JLON,1,JLEV,1)*(RV/RD))/&
         & (1._JPRB+ZZI_RM(JLON,1,JLEV,1)+ZZI_RM(JLON,1,JLEV,2) +&
         &  ZZI_RM(JLON,1,JLEV,3)+ZZI_RM(JLON,1,JLEV,4)+   &
         &  ZZI_RM(JLON,1,JLEV,5)+ZZI_RM(JLON,1,JLEV,6))
      ENDDO
    ENDDO
    DO JLON = KIDIA,KFDIA
      ZTHVREFM(JLON,1,1)= ZTHVREFM(JLON,1,2)
      ZTHVREFM(JLON,1,KLEV+2)= ZTHVREFM(JLON,1,KLEV+1)
    ENDDO
  ELSEIF (NRR==7) THEN
    DO JLEV = 2 , KLEV+1
      DO JLON = KIDIA,KFDIA
        ZTHVREFM(JLON,1,JLEV)=ZZI_THM(JLON,1,JLEV)*&
         & (1._JPRB+ZZI_RM(JLON,1,JLEV,1)*(RV/RD))/&
         & (1._JPRB+ZZI_RM(JLON,1,JLEV,1)+ZZI_RM(JLON,1,JLEV,2) +&
         &  ZZI_RM(JLON,1,JLEV,3)+ZZI_RM(JLON,1,JLEV,4)+   &
         &  ZZI_RM(JLON,1,JLEV,5)+ZZI_RM(JLON,1,JLEV,6)+   &
         &  ZZI_RM(JLON,1,JLEV,7) )
      ENDDO
    ENDDO
    DO JLON = KIDIA,KFDIA
      ZTHVREFM(JLON,1,1)= ZTHVREFM(JLON,1,2)
      ZTHVREFM(JLON,1,KLEV+2)= ZTHVREFM(JLON,1,KLEV+1)
    ENDDO
  ENDIF
  !initialisation des scalaires passifs
  IF (NGFL_EXT/=0) THEN
    DO JGFL=1,NGFL_EXT
      DO JLEV=1,KLEV
        DO JLON=1,KLON
          ZZI_SVM(JLON,1,KLEV+2-JLEV,JGFL)=PSVM(JLON,JLEV,JGFL)
        ENDDO
      ENDDO
    ENDDO

    DO JGFL=1,NGFL_EXT
      DO JLON=1,KLON
        ZZI_SVM(JLON,1,KLEV+2,JGFL)=ZZI_SVM(JLON,1,KLEV+1,JGFL)
        ZZI_SVM(JLON,1,1,JGFL)=ZZI_SVM(JLON,1,2,JGFL)
      ENDDO
    ENDDO
  ENDIF

!!! initialisation des variables d etat MNH a t+dt
!!! division pas le pas de temps
!!!(la multiplication par rhodj est faite plus tard, si necessaire, 
!!! suivant les parametrisations)   

  ! vent horizontal
  DO JLEV = 2 , KLEV+1
    DO JLON=KIDIA,KFDIA
      ZZI_US(JLON,1,JLEV)= PUM(JLON,KLEV+1+1-JLEV)*ZINVDT
      ZZI_VS(JLON,1,JLEV)= PVM(JLON,KLEV+1+1-JLEV)*ZINVDT
      ZZI_WS(JLON,1,JLEV)= PWM(JLON,KLEV+1+1-JLEV)*ZINVDT
      ZZI_TKES(JLON,1,JLEV)= PTKEM(JLON,KLEV+1+1-JLEV)*ZINVDT
    ENDDO
  ENDDO
  DO JLON=KIDIA,KFDIA
    ZZI_US(JLON,1,1)= ZZI_US(JLON,1,2)
    ZZI_US(JLON,1,KLEV+2)= ZZI_US(JLON,1,KLEV+1)
    ZZI_VS(JLON,1,1)= ZZI_VS(JLON,1,2)
    ZZI_VS(JLON,1,KLEV+2)= ZZI_VS(JLON,1,KLEV+1)
    ZZI_WS(JLON,1,1)= ZZI_WS(JLON,1,2)
    ZZI_WS(JLON,1,KLEV+2)= ZZI_WS(JLON,1,KLEV+1)
    ZZI_TKES(JLON,1,1)= ZZI_TKES(JLON,1,2)
    ZZI_TKES(JLON,1,KLEV+2)= ZZI_TKES(JLON,1,KLEV+1)
  ENDDO

  !initialisation de ZZI_THS
  DO JLEV = 1, KLEV+2
    DO JLON = KIDIA,KFDIA
      ZZI_THS(JLON,1,JLEV)=ZZI_THM(JLON,1,JLEV)*ZINVDT
    ENDDO
  ENDDO

  !initialisation de ZZI_RS pour les hydrometeores
  DO JRR=1,NRR 
    DO JLEV = 1, KLEV+2
      DO JLON=KIDIA,KFDIA
        ZZI_RS(JLON,1,JLEV,JRR)=ZZI_RM(JLON,1,JLEV,JRR)*ZINVDT
      ENDDO
    ENDDO
  ENDDO

!!! Initialisations temporaires d'arguments non-utilises
  !initialisation de ZCIT
  DO JLEV = 1 , KLEV+2
    DO JLON = KIDIA,KFDIA
      ZCIT(JLON,1,JLEV)=0.0_JPRB
    ENDDO
  ENDDO
  
  !initialisation des tableaux de precipitations inst. and cumulated 
  !and surface fluxes for turbulence
  IF(LMSE) THEN
    DO JLON = KIDIA,KFDIA
      ZACPRR(JLON,1)=PGPAR(JLON,MACPRR)
      ZACPRS(JLON,1)=PGPAR(JLON,MACPRS)
      ZACPRG(JLON,1)=PGPAR(JLON,MACPRG)
      ZINPRR_NOTINCR(JLON,1)=PGPAR(JLON,MINPRR)
      ZINPRS_NOTINCR(JLON,1)=PGPAR(JLON,MINPRS)
      ZINPRG_NOTINCR(JLON,1)=PGPAR(JLON,MINPRG)
    ENDDO
  ENDIF
  !initialisation des scalaires passifs
  IF (NGFL_EXT/=0) THEN
   DO JGFL=1,NGFL_EXT
    DO JLEV = 1, KLEV+2
      DO JLON=KIDIA,KFDIA
        ZZI_SVS(JLON,1,JLEV,JGFL)=ZZI_SVM(JLON,1,JLEV,JGFL)*ZINVDT
      ENDDO
    ENDDO
   ENDDO
  ENDIF

ENDIF


!    ------------------------------------------------------------------
!     3 - PRINTS FOR DIAGNOSTICS IF NEEDED
!    ------------------------------------------------------------------
IF (LDIAGWMAX) THEN
  IF (MOD(KSTEP+1,NDIAGWMAX)==0) THEN
  ! calcul de wmax
    DO JLEV = 1 , KLEV
      Z_WMAX=0._JPRB
      Z_WMIN=0._JPRB
      DO JLON=KIDIA,KFDIA
        IF (PWM(JLON,JLEV)>Z_WMAX) THEN
          Z_WMAX=PWM(JLON,JLEV)
        ENDIF
        IF (PWM(JLON,JLEV)<Z_WMIN) THEN
          Z_WMIN=PWM(JLON,JLEV)
        ENDIF
      ENDDO
    ENDDO
  ENDIF
ENDIF



!    ------------------------------------------------------------------
!     4 - ADJUSTMENT (CALLED IF THE MICROPHYSICS IS SWITCH ON) 
!    ------------------------------------------------------------------
IF (LMICRO) THEN

  ZZI_THSAVE(:,:,:)=ZZI_THS(:,:,:)
  ZZI_RSAVE=ZZI_RS

IF (LMFSHAL .AND. (CMF_CLOUD=='DIRE')) THEN
  IOFF_MFSHAL=IOFF_MFSHAL+2
  IF (KSTEP==0) THEN
     ZRC_MF=0.
     ZCF_MF=0.
  ELSE
  DO JLEV = 2 , KLEV+1
    DO JLON = KIDIA,KFDIA
      ZRC_MF(JLON,1,JLEV)=PEZDIAG(JLON,KLEV+2-JLEV,1)
      ZCF_MF(JLON,1,JLEV)=PEZDIAG(JLON,KLEV+2-JLEV,2)
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZRC_MF(JLON,1,1)=ZRC_MF(JLON,1,2)
    ZRC_MF(JLON,1,KLEV+2)=ZRC_MF(JLON,1,KLEV+1)
    ZCF_MF(JLON,1,1)=ZCF_MF(JLON,1,2)
    ZCF_MF(JLON,1,KLEV+2)=ZCF_MF(JLON,1,KLEV+1)
  ENDDO
  ENDIF
PEZDIAG=0.
ENDIF

  IF (MOD(KSTEP+1,NPRINTFR)==0) THEN
    WRITE(NULOUT,*)'avant aro_adjust sous apl_arome'
    WRITE(NULOUT,*)'JLEV   ZZZF   RHODJM   EXNREFM   ',&
     & '    PABSM       THM      SIGM         MFM    '   
    DO JLEV=1,KLEV+1 
      WRITE(NULOUT,'(I2,x,7f10.3)')JLEV,ZZZF(NPTP,1,JLEV),ZZI_RHODJM(NPTP,1,JLEV),&
       & ZZI_EXNREFM(NPTP,1,JLEV),&
       & ZZI_PABSM(NPTP,1,JLEV), ZZI_THM(NPTP,1,JLEV), ZZI_SIGM(NPTP,1,JLEV),&
       & ZZI_MFM(NPTP,1,JLEV)  
    ENDDO 
    WRITE (NULOUT,*)'JLEV  rhoQv  rhoQc   rhoQr   rhoQi   rhoQs   rhoQg'
    DO JLEV=1,KLEV+2
      WRITE(NULOUT,'(I2,x,6e11.4)')JLEV,ZZI_RM(NPTP,1,JLEV,1), &
       & ZZI_RM(NPTP,1,JLEV,2),&
       & ZZI_RM(NPTP,1,JLEV,3),ZZI_RM(NPTP,1,JLEV,4),ZZI_RM(NPTP,1,JLEV,5),&
       & ZZI_RM(NPTP,1,JLEV,6)  
    ENDDO
    WRITE (NULOUT,*)'JLEV  ZRC_MF  ZCF_MF ZZI_THS  ZSRCS ZNEBMNH'
   DO JLEV=1,KLEV+2
      WRITE(NULOUT,'(I2,x,5e11.4)')JLEV,ZRC_MF(NPTP,1,JLEV), &
       & ZCF_MF(NPTP,1,JLEV),&
       & ZZI_THS(NPTP,1,JLEV),ZSRCS(NPTP,1,JLEV),&
       & ZNEBMNH(NPTP,1,JLEV)
   ENDDO
  ENDIF
  CALL ARO_ADJUST (ILONMNH,KLEV,NRR,KSTEP+1,&
   & LOSUBG_COND, LOSIGMAS, LOSUBG_AUCV,&
   & ZDT,ZZZF(KIDIA:KFDIA,:,:),&
   & ZZI_RHODJM(KIDIA:KFDIA,:,:),&
   & ZZI_EXNREFM(KIDIA:KFDIA,:,:),&
   & ZZI_PABSM(KIDIA:KFDIA,:,:),&
   & ZZI_THM(KIDIA:KFDIA,:,:),&
   & ZZI_RM(KIDIA:KFDIA,:,:,:),ZZI_SIGM(KIDIA:KFDIA,:,:),&
   & ZZI_MFM(KIDIA:KFDIA,:,:),ZRC_MF(KIDIA:KFDIA,:,:),ZCF_MF(KIDIA:KFDIA,:,:),&
   & ZZI_THS(KIDIA:KFDIA,:,:),ZZI_RS(KIDIA:KFDIA,:,:,:),&
   & ZSRCS(KIDIA:KFDIA,:,:),ZNEBMNH(KIDIA:KFDIA,:,:))  
  
  IF (MOD(KSTEP+1,NPRINTFR)==0) THEN
    WRITE(NULOUT,*)'apres aro_adjust sous apl_arome'
    WRITE(NULOUT,*)'JLEV   ZZZF   RHODJM   EXNREFM   ',&
     & '    PABSM       THM      SIGM         MFM    '   
    DO JLEV=1,KLEV+1 
      WRITE(NULOUT,'(I2,x,7f10.3)')JLEV,ZZZF(NPTP,1,JLEV),ZZI_RHODJM(NPTP,1,JLEV),&
       & ZZI_EXNREFM(NPTP,1,JLEV),&
       & ZZI_PABSM(NPTP,1,JLEV), ZZI_THM(NPTP,1,JLEV), ZZI_SIGM(NPTP,1,JLEV),&
       & ZZI_MFM(NPTP,1,JLEV)  
    ENDDO 
    WRITE (NULOUT,*)'JLEV  rhoQv  rhoQc   rhoQr   rhoQi   rhoQs   rhoQg'
    DO JLEV=1,KLEV+2
      WRITE(NULOUT,'(I2,x,6e11.4)')JLEV,ZZI_RS(NPTP,1,JLEV,1), &
       & ZZI_RS(NPTP,1,JLEV,2),&
       & ZZI_RS(NPTP,1,JLEV,3),ZZI_RS(NPTP,1,JLEV,4),ZZI_RS(NPTP,1,JLEV,5),&
       & ZZI_RS(NPTP,1,JLEV,6)  
    ENDDO
    WRITE (NULOUT,*)'JLEV  ZRC_MF  ZCF_MF ZZI_THS ZSRCS ZNEBMNH'
   DO JLEV=1,KLEV+2
      WRITE(NULOUT,'(I2,x,5e11.4)')JLEV,ZRC_MF(NPTP,1,JLEV), &
       & ZCF_MF(NPTP,1,JLEV),&
       & ZZI_THS(NPTP,1,JLEV),ZSRCS(NPTP,1,JLEV),&
       & ZNEBMNH(NPTP,1,JLEV)
   ENDDO
  ENDIF
  !adjusted zthm and zrm
  DO JLEV = 1, KLEV+2
    DO JLON = KIDIA,KFDIA
      ZZI_THM(JLON,1,JLEV)=ZZI_THS(JLON,1,JLEV)*PDT
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_THM(JLON,1,1)=ZZI_THS(JLON,1,2)*PDT
    ZZI_THM(JLON,1,KLEV+2)=ZZI_THS(JLON,1,KLEV+1)*PDT
  ENDDO

  DO JRR=1,NRR
    DO JLEV = 1, KLEV+2
      DO JLON = KIDIA,KFDIA
        ZZI_RM(JLON,1,JLEV,JRR)=ZZI_RS(JLON,1,JLEV,JRR)*PDT
      ENDDO
    ENDDO
    DO JLON = KIDIA,KFDIA
      ZZI_RM(JLON,1,1,JRR)=ZZI_RS(JLON,1,2,JRR)*PDT
      ZZI_RM(JLON,1,KLEV+2,JRR)=ZZI_RS(JLON,1,KLEV+1,JRR)*PDT
    ENDDO
  ENDDO

  !initialisation de qdm utile pour 
  !convertir tendance de r en tendance de q 
  IF (NRR==6) THEN
    DO JLEV=1,KLEV
      DO JLON= KIDIA, KFDIA
        ZQDM(JLON,JLEV)=1._JPRB/(1._JPRB+ZZI_RM(JLON,1,KLEV+2-JLEV,1)+  &
        &ZZI_RM(JLON,1,KLEV+2-JLEV,2)+ZZI_RM(JLON,1,KLEV+2-JLEV,3)+&
        &ZZI_RM(JLON,1,KLEV+2-JLEV,4)+ZZI_RM(JLON,1,KLEV+2-JLEV,5)+&
        &ZZI_RM(JLON,1,KLEV+2-JLEV,6) )
      ENDDO
    ENDDO
  ELSEIF (NRR==7) THEN
    DO JLEV=1,KLEV
      DO JLON= KIDIA, KFDIA
        ZQDM(JLON,JLEV)=1._JPRB/(1._JPRB+ZZI_RM(JLON,1,KLEV+2-JLEV,1)+  &
        &ZZI_RM(JLON,1,KLEV+2-JLEV,2)+ZZI_RM(JLON,1,KLEV+2-JLEV,3)+&
        &ZZI_RM(JLON,1,KLEV+2-JLEV,4)+ZZI_RM(JLON,1,KLEV+2-JLEV,5)+&
        &ZZI_RM(JLON,1,KLEV+2-JLEV,6)+ZZI_RM(JLON,1,KLEV+2-JLEV,7) )
      ENDDO
    ENDDO
  ENDIF 
  !reinitialisation des qi
  DO JLEV = 1, KLEV
    DO JLON = KIDIA,KFDIA
      ZQVM(JLON,JLEV)=ZZI_RM(JLON,1,KLEV+1+1-JLEV,1)*ZQDM(JLON,JLEV)
      ZQCM(JLON,JLEV)=ZZI_RM(JLON,1,KLEV+1+1-JLEV,2)*ZQDM(JLON,JLEV)
      ZQRM(JLON,JLEV)=ZZI_RM(JLON,1,KLEV+1+1-JLEV,3)*ZQDM(JLON,JLEV)
      ZQIM(JLON,JLEV)=ZZI_RM(JLON,1,KLEV+1+1-JLEV,4)*ZQDM(JLON,JLEV)
      ZQSM(JLON,JLEV)=ZZI_RM(JLON,1,KLEV+1+1-JLEV,5)*ZQDM(JLON,JLEV)
      ZQGM(JLON,JLEV)=ZZI_RM(JLON,1,KLEV+1+1-JLEV,6)*ZQDM(JLON,JLEV)
    ENDDO
  ENDDO

  IF (NRR==7) THEN
    DO JLEV = 1, KLEV
      DO JLON = KIDIA,KFDIA
        ZQHM(JLON,JLEV)=ZZI_RM(JLON,1,KLEV+1+1-JLEV,7)*ZQDM(JLON,JLEV)
      ENDDO
    ENDDO
  ENDIF

  !compute temperature tendency
  IF (LFLEXDIA) ZTENDBKP(:,:)=PTENDT(:,:)
  
  DO JLEV = 1 ,KLEV
    DO JLON = KIDIA,KFDIA
      PTENDT(JLON,JLEV)=PTENDT(JLON,JLEV)+(ZZI_THS(JLON,1,KLEV+2-JLEV)-&
       & ZZI_THSAVE(JLON,1,KLEV+2-JLEV))*ZZI_EXNREFM(JLON,1,KLEV+2-JLEV)  
    ENDDO
  ENDDO
  
  IF (LFLEXDIA) THEN
    ZTMPAF(:,:)=(PTENDT(:,:)-ZTENDBKP(:,:))*PDELPM(:,:)*ZINVG*ZCPM(:,:) 
    CALL ADD_FIELD_3D(ZTMPAF(:,:),'TCTADJU','T','ARP',.TRUE.,.TRUE.)
  ENDIF
  
  !inversion niveaux tendances des ri et conversion en qi en multipliant par qd 
  DO JR=1,NRR
    IF (LFLEXDIA) ZTENDBKP(:,:)=PTENDR(:,:,JR) 
    DO JLEV=1,KLEV
      DO JLON=KIDIA,KFDIA
        PTENDR(JLON,JLEV,JR)=PTENDR(JLON,JLEV,JR)   &
         & +(ZZI_RS(JLON,1,KLEV+2-JLEV,JR)         &
         & -ZZI_RSAVE(JLON,1,KLEV+2-JLEV,JR))*ZQDM(JLON,JLEV)  
      ENDDO
    ENDDO
    
    IF (LFLEXDIA) THEN
      CLNAME='T'//CLVARNAME(JR)//'ADJU'
      ZTMPAF(:,:)=(PTENDR(:,:,JR)-ZTENDBKP(:,:))*PDELPM(:,:)*ZINVG
      CALL ADD_FIELD_3D(ZTMPAF(:,:),CLNAME,'T','ARP',.TRUE.,.TRUE.)
    ENDIF 
  ENDDO
        
  !modif de R et CP
  ZQHGM=ZQHM+ZQGM
  CALL GPRCP(KLON,KIDIA,KFDIA,KLEV,&
   & PQ=ZQVM,PQI=ZQIM,PQL=ZQCM,&
   & PQR=ZQRM,PQS=ZQSM,PQG=ZQHGM,&
   & PCP=ZCPM,PR=ZRHM,PKAP=ZKAPM)  

  DO JLEV = 1 ,KLEV
    DO JLON = KIDIA,KFDIA
      ZTM(JLON,JLEV)=ZZI_THM(JLON,1,KLEV+2-JLEV)*ZZI_EXNREFM(JLON,1,KLEV+2-JLEV)
    ENDDO
  ENDDO

  !reinitialisation de ZZI_RHODREFM (=qd*zrho)
  DO JLEV = 2 , KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZI_RHO(JLON,1,JLEV)=PAPRSFM(JLON,KLEV+1+1-JLEV)/&
       & (ZRHM(JLON,KLEV+1+1-JLEV)*ZTM(JLON,KLEV+1+1-JLEV))
      ZZI_RHODREFM(JLON,1,JLEV)=ZZI_RHO(JLON,1,JLEV)*ZQDM(JLON,KLEV+1+1-JLEV)
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZI_RHODREFM(JLON,1,1)=ZZI_RHODREFM(JLON,1,2)
    ZZI_RHODREFM(JLON,1,KLEV+2)=ZZI_RHODREFM(JLON,1,KLEV+1)
    ZZI_RHO(JLON,1,1)=ZZI_RHO(JLON,1,2)
    ZZI_RHO(JLON,1,KLEV+2)=ZZI_RHO(JLON,1,KLEV+1)
  ENDDO

  !geopotentiel calculation
 
  CALL GPGEO(KLON,KIDIA,KFDIA,KLEV,ZZI_APHIM,ZZI_APHIFM,ZTM,ZRHM,PLNPRM,PALPHM)
  DO JLON = KIDIA,KFDIA
    IF(ZZI_APHIFM(JLON,KLEV) <= 0._JPRB) THEN
      WRITE(20,*)'sous apl_arome calcul PHIM',JLON,ZTM(JLON,KLEV),ZRHM(JLON,KLEV),&
 & PLNPRM(JLON,KLEV),PALPHM(JLON,KLEV),ZZI_APHIM(JLON,KLEV),ZZI_APHIFM(JLON,KLEV)
      WRITE(20,*)'sous apl_arome gprcp',ZQVM(JLON,KLEV),ZQIM(JLON,KLEV),&
&ZQCM(JLON,KLEV),ZQRM(JLON,KLEV),ZQSM(JLON,KLEV),ZQHGM(JLON,KLEV)
    ENDIF
  ENDDO
   
  !calcul de l'altitude
  DO JLEV = 2 , KLEV+2
    DO JLON = KIDIA,KFDIA
      ZZZ(JLON,1,JLEV)=ZZI_APHIM(JLON,KLEV+2-JLEV)*ZINVG
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZZ(JLON,1,1)=2*ZZZ(JLON,1,2)-ZZZ(JLON,1,3)
  ENDDO
  
  !initialisation de ZZZF
  DO JLEV = 2 , KLEV+1
    DO JLON = KIDIA,KFDIA
      ZZZF(JLON,1,JLEV)=ZZI_APHIFM(JLON,KLEV+2-JLEV)*ZINVG
    ENDDO
  ENDDO
  DO JLON = KIDIA,KFDIA
    ZZZF(JLON,1,1)=1.5_JPRB*ZZZ(JLON,1,2)-0.5_JPRB*ZZZ(JLON,1,3)
    ZZZF(JLON,1,KLEV+2)=ZZZF(JLON,1,KLEV+1)+ (ZZZ(JLON,1,KLEV+2)- &
     & ZZZ(JLON,1,KLEV+1))
  ENDDO

ENDIF
!initialisation of PCLFS outside LMICRO to be zero in case LMICRO=F
DO JLEV=1,KLEV
  DO JLON = KIDIA,KFDIA
    PCLFS(JLON,JLEV)=ZNEBMNH(JLON,1,KLEV+2-JLEV) 
  ENDDO
ENDDO
!     END ADJUTMENT
!     --------------------------------------------------------------------


! specific to new data flow for diagnostics

CALL ARO_SUINTBUDGET(KLON,KLEV,KSTEP,KFDIA,ZQDM,ZZI_EXNREFM,PCPM) 

!     --------------------------------------------------------------------
!     5 - COMPUTE DUST PROPERTIES FOR RADIATION IF LRDUST=T
!     --------------------------------------------------------------------
IF (LRDUST) THEN
  PEZDIAG(:,:,IOFF_MFSHAL:NGFL_EZDIAG)=0.0_JPRB
! input dust scalar concentration in ppp from
 IEZDIAG_CHEM=NGFL_EZDIAG-IOFF_MFSHAL+1

  ZZI_SVSAVE=ZZI_SVM
! input dust scalar concentration in ppp from
 CALL ARO_MNHDUST (ILONMNH,KLEV,NGFL_EXT, PDT,            &
        &          ZZI_SVM(KIDIA:KFDIA,:,:,1:NGFL_EXT),   &
        &          ZZZ(KIDIA:KFDIA,:,:),                  &
        &          ZZI_PABSM(KIDIA:KFDIA,:,:),            &
        &          ZZI_THM(KIDIA:KFDIA,:,:),              &
        &          ZZI_RHODREFM(KIDIA:KFDIA,:,:),         &
        &          NSWB_MNH,                              &
        &          KSTEP+1,                               &
        &          ZPIZA_DST(KIDIA:KFDIA,:,:),            &
        &          ZCGA_DST(KIDIA:KFDIA,:,:),             &
        &          ZTAUREL_DST(KIDIA:KFDIA,:,:),          &
        &          ZAERD(KIDIA:KFDIA,:),                  &
        &          IEZDIAG_CHEM,                           &
        &          ZZI_PEZDIAG(KIDIA:KFDIA,:,IOFF_MFSHAL:NGFL_EZDIAG)           )

PEZDIAG(KIDIA:KFDIA,:,IOFF_MFSHAL:NGFL_EZDIAG)=ZZI_PEZDIAG(KIDIA:KFDIA,:,IOFF_MFSHAL:NGFL_EZDIAG)




! return to tendency
     DO JGFL=1, NGFL_EXT
       DO JLEV = 1 ,KLEV
         DO JLON = KIDIA,KFDIA
           PTENDEXT(JLON,JLEV,JGFL)=PTENDEXT(JLON,JLEV,JGFL)+&
         & (ZZI_SVM(JLON,1,KLEV+2-JLEV,JGFL)-&
         & ZZI_SVSAVE(JLON,1,KLEV+2-JLEV,JGFL))*ZINVDT
         ENDDO
       ENDDO
     ENDDO
ENDIF

!     --------------------------------------------------------------------
!     6 - RADIATION (from ECMWF, but as in ARPEGE : same setup etc) 
!     --------------------------------------------------------------------

IF (LRAYFM) THEN
!     ------------------------------------------------------------------
!     - CALCUL de l'humidite saturante
!     ----------------------------

  CALL ACTQSAT ( KIDIA,KFDIA,KLON,NTQSAT,KLEV,&
   & PAPRSFM, ZCPM, ZQVM, ZTM,&
   & ZGEOSLC, ZLH, ZLSCPE, ZQSAT, ZQW, ZRH, ZTW, 'ACTQSAT')  
     
  ! initialisation des humidit� (dans le rayonnement, l'eau liquide nuageuse 
  ! e la glace sont donn� par des hu par rapport au gaz.
  ! (qi/qa+qv pour ice par ex. C'est donc different de ri ) 
  DO JLEV=KTDIA,KLEV
    DO JLON=KIDIA,KFDIA 
       ZQICE(JLON,JLEV)=MAX(0.0_JPRB, ZQIM(JLON,JLEV)/ &
        & (1.0_JPRB-ZQIM(JLON,JLEV)-ZQCM(JLON,JLEV)-ZQRM(JLON,JLEV)&
        & -ZQGM(JLON,JLEV)-ZQSM(JLON,JLEV)-ZQHM(JLON,JLEV)))
       ZQLI(JLON,JLEV)=MAX(0.0_JPRB, ZQCM(JLON,JLEV)/&
        & (1.0_JPRB-ZQIM(JLON,JLEV)-ZQCM(JLON,JLEV)-ZQRM(JLON,JLEV)&
        & -ZQGM(JLON,JLEV)-ZQSM(JLON,JLEV)-ZQHM(JLON,JLEV)))
       ZQV(JLON,JLEV)=MAX(0.0_JPRB, ZQVM(JLON,JLEV)/ &
        & (1.0_JPRB-ZQIM(JLON,JLEV)-ZQCM(JLON,JLEV)-ZQRM(JLON,JLEV)&
        & -ZQGM(JLON,JLEV)-ZQSM(JLON,JLEV)-ZQHM(JLON,JLEV)))
    ENDDO
  ENDDO

  ! test de coherence sur le nombre de bandes spectrales entre ce qui sort de
  ! la surface et ce qu'attend le rayonnement
  IF( NSWB_MNH /= NSW) THEN
    CALL ABOR1 (' NSWB_MNH must be equal to NSW !')
  ENDIF

  ! Albedo dans les intervalles, direct (parallel) et diffus (diffuse).
  IF(NSW==6.OR.NSW==1)THEN
    DO JSG=1,NSW
      DO JLON=KIDIA,KFDIA
        IF(LMSE) THEN 
          ZALBP(JLON,JSG)=PGPAR(JLON,MALBDIR-1+JSG)
          ZALBD(JLON,JSG)=PGPAR(JLON,MALBSCA-1+JSG)
        ELSE
      !pour pouvoir tourner sans la surface
          ZALBP(JLON,JSG)=PALB(JLON) 
          ZALBD(JLON,JSG)=PALB(JLON)
        ENDIF   
      ENDDO
    ENDDO

    DO JLON=KIDIA,KFDIA
      IF (LMSE) THEN
        ZEMIS(JLON)=PGPAR(JLON,MVEMIS)
        ZTSURF(JLON)=PGPAR(JLON,MVTS)
        ! We fill the Aladin surface temperature field here only to have it
        ! in historic FA files for Fullpos. 
        PTS(JLON)=PGPAR(JLON,MVTS)
        ! protection for E Zone, Where surface scheme send back EMIS and T =0
        ! the protection in aro_ground_paramn is not sufficient !!! WHY ??
        IF (ZEMIS(JLON)==0._JPRB) THEN
          ZEMIS(JLON)=1.0_JPRB
          ZTSURF(JLON)=288.0_JPRB
        ENDIF

      ELSE
        ZTSURF(JLON)=ZTM(JLON,KLEV)
        ZEMIS(JLON)=PEMIS(JLON)
      ENDIF
    ENDDO  
  ELSE
    CALL ABOR1 ('ALBEDO FOR NSW/= 1 or 6 not defined in apl_arome')
  ENDIF
  
  ! intermitant call to radiation scheme 
  IF (MOD(KSTEP,NRADFR) == 0) THEN
    
    !initialisation of aerosols
    !as in Meteo-France ( in clim files)
    IF((NAER /= 0).AND.(YSD_VAD%NUMFLDS < 4)) THEN
        CALL ABOR1('APL_AROME: PB AEROSOLS!')
    ENDIF
    IF(YSD_VAD%NUMFLDS >= 4) THEN
      DO JLON = KIDIA,KFDIA
        ZAESEA(JLON) = PAESEA(JLON)
        ZAELAN(JLON) = PAELAN(JLON)
        ZAESOO(JLON) = PAESOO(JLON)
        ZAEDES(JLON) = PAEDES(JLON)
      ENDDO
    ELSE
      DO JLON = KIDIA,KFDIA
        ZAESEA(JLON) = 0.0_JPRB
        ZAELAN(JLON) = 0.0_JPRB
        ZAESOO(JLON) = 0.0_JPRB
        ZAEDES(JLON) = 0.0_JPRB
      ENDDO
      ZDUM=1._JPRB
      CALL  RADACT (KIDIA, KFDIA, KLON, KLEV,&
       & 1 , NGPTOT , NGPTOT+2  ,0 , 1,&
       & PAPRSM , PGELAM, PGEMU , PCLON , PSLON, ZCHTIX,&
       & ZDUM   , ZDUM  , ZDUM  ,&
       & ZRAER , ZROZ  )  
   
      DO JJ=1,6
        DO JK=1,KLEV
          DO JL=KIDIA,KFDIA
            ZAER(JL,JK,JJ)=ZRAER(JL,JJ,JK)
          ENDDO
        ENDDO
      ENDDO
    ENDIF
    IF(LRAYFM.AND.NAER /= 0.AND.((YSD_VAD%NUMFLDS >= 4))) THEN
        CALL RADAER ( KIDIA , KFDIA , KLON  , KTDIA , KLEV,&
         & PAPRSM , PAPRSFM, ZTM    , ZTSURF,&
         & ZAESEA, ZAELAN, ZAESOO, ZAEDES,&
         & ZAER                                 )
    ENDIF

    IF (LRDUST) THEN
    ! We uses the extinction coefficient explicitely solved by ARO_MNHDUST
         ZAER(KIDIA:KFDIA,:,3) = ZAERD(KIDIA:KFDIA,:)
    ENDIF


    ! initialisation de l'Ozone 
    ! comme dans arpege a partir de profils clim si nozocl=2
    IF (NOZOCL==2) THEN
      CALL SUOZON ( KIDIA,KFDIA,KLON,KLEV,ZQO3,.FALSE.,PAPRSM,PRDELPM,&
       & LO3ABC,PVO3ABC )  
    ENDIF
    ! comme au CEP si nozocl=1
    IF (NOZOCL==1) THEN
      CALL RADOZC ( KIDIA, KFDIA , KLON, KLEV, &
      & 1 , NGPTOT , 0,  &
      & PAPRSM , PGEMU, &
      & ZROZ   )
      DO JK=1,KLEV
        DO JL=1,KLON
          ZQO3(JL,JK)=ZROZ(JL,JK)/PDELPM(JL,JK)
        ENDDO
      ENDDO

    ENDIF

       
    ! Appel de l'interface rayonnement
    ZCARDI=RCARDI
    IMODE=NMODE
    IFLUX=0
    IRAD=0
    
    CALL ACRADIN &
     & ( KIDIA , KFDIA,&
     & KLON  , KGL1 , KGL2  , KTDIA , KLEV,&
     & IMODE ,IFLUX,IRAD,&
     & ZALBD , ZALBP, PAPRSM    , PAPRSFM,&
     & ZCARDI, PCLFS , ZQO3(1,1), ZAER,&
     & PDELPM , ZEMIS, PMU0M, ZQV  , ZQSAT,&
     & ZQICE , ZQLI , PLSM     , ZTM    , ZTSURF,&
     & PEMTD , PEMTU, PTRSO,ZFRTHC,PFRTH,ZFRSOC,PFRSO,&
     & ZZSFSWDIR, ZZSFSWDIF,&
     & ZFSDNN, ZFSDNV,&
     & ZCTRSO, ZCEMTR, ZTRSOD,&
     & ZPIZA_DST,ZCGA_DST,ZTAUREL_DST,&
     & 'ACRADIN')

    !save SW surface fluxes
    IF(LMSE) THEN
      IF(NSW==6) THEN
        DO JSG=1,NSW
          DO JL=KIDIA,KFDIA
            PGPAR(JL,MSWDIR+JSG-1)= ZZSFSWDIR(JL,JSG)
            PGPAR(JL,MSWDIF+JSG-1)= ZZSFSWDIF(JL,JSG)
          ENDDO
        ENDDO
      ENDIF
      IF(NSW==1) THEN
        DO JL=KIDIA,KFDIA
          PGPAR (JL,MSWDIR)= ZFSDNN (JL)+ZFSDNV(JL)
          PGPAR (JL,MSWDIF)=0.0_JPRB
        ENDDO
      ENDIF
    ENDIF

  ENDIF
  
! Radiative fluxes calculation at every time-step
  DO JL=KIDIA,KFDIA
    ZTRSOD(JL) = PEMTU(JL,KLEV)
  ENDDO

  CALL RADHEAT &
   & (  KIDIA  , KFDIA  , KLON   , KLEV,&
   & PAPRSM  ,&
   & ZEMIS  , PEMTD  , PMU0,&
   & ZQVM,&
   & ZTENT  , PTRSO  , ZTRSOD , ZTSURF   , PDT,&
   & PFRSO  , PFRTH  , ZFRSODS, ZFRTHDS,&
   & ZCEMTR , ZCTRSO , ZFRSOC , ZFRTHC,&
   & ZSUDU  , ZSDUR  , ZDSRP &
   & )  

! A rajouter car flux calcules dans radheat pas corrects (cf aplpar)
  DO JLON=KIDIA,KFDIA
     IF (LMSE) THEN
        ZALB(JLON)=0.
        DO JSG=1,NSW
         ZALB(JLON)=ZALB(JLON)+ZALBD(JLON,JSG)+ZALBP(JLON,JSG)
        ENDDO
        ZALB(JLON)=ZALB(JLON)/FLOAT(NSW*2)
     ELSE
        ZALB(JLON)=PALB(JLON)
     ENDIF
     PFRSODS(JLON)=PFRSO(JLON,KLEV,1)/(1.0_JPRB-ZALB(JLON))
     PFRTHDS(JLON)=ZFRTHDS(JLON)
  ENDDO
  !   Caclul de la tendance de T
  PTENDT(:,:)=PTENDT(:,:)+ZTENT(:,:)

  IF( MOD(KSTEP+1,NPRINTFR)==0) THEN
    WRITE(NULOUT,*)'sous apl_arome apres rayonnement ZTENT=',ZTENT(NPTP,30:41)
    IF (LMSE) THEN
      DO JJ=1, NSW
        WRITE(NULOUT,*)'ZSFSWDIR ZSFSWDIF ZFSDNN ZFSDNV PFRSO',&
         & ZZSFSWDIR(NPTP,JJ),ZZSFSWDIF(NPTP,JJ),ZFSDNN(NPTP),&
         & ZFSDNV(NPTP),PFRSO(NPTP,KLEV,1)
        WRITE(NULOUT,*)'ZALBD ZALBP',ZALBD(NPTP,JJ),ZALBP(NPTP,JJ)
      ENDDO
    ENDIF
    WRITE(NULOUT,*)ZFSDNN(NPTP),ZFSDNV(NPTP)
    WRITE (NULOUT,*)'TSURF EMIS ZFRTH',ZTSURF(NPTP),ZEMIS(NPTP),ZFRTHDS(NPTP)
  ENDIF
  
  IF (LFLEXDIA) THEN
    CALL ADD_FIELD_3D(PFRSO(:,:,1),'FCTRAYSO','F','ARP',.TRUE.,.TRUE.)
    CALL ADD_FIELD_3D(PFRTH(:,:,1),'FCTRAYTH','F','ARP',.TRUE.,.TRUE.) 
  ENDIF
  
ENDIF

IF (LFLEXDIA) THEN
  CALL ARO_STARTBU( KIDIA, KFDIA, NRR,NGFL_EXT,ZZI_RHODJM, &
                  & ZZI_US, ZZI_VS, ZZI_WS, ZZI_THS, ZZI_RS, ZZI_TKES, ZZI_SVS)
ENDIF


!    ------------------------------------------------------------------
!     7 - CONVECTION. 
!     --------------------------------------------------------------------

IF(LKFBCONV) THEN

  ZZI_CVTENDRV(:,:)=0.0_JPRB
  ZZI_CVTENDRC(:,:)=0.0_JPRB
  ZZI_CVTENDRI(:,:)=0.0_JPRB
  ZZI_CVTENDT(:,:)=0.0_JPRB
  ZZI_RSAVE=ZZI_RS
  ZZI_THSAVE=ZZI_THS
  CALL BRI2ACCONV(KIDIA,KFDIA,ILONMNH,KLEV,PGM(KIDIA:KFDIA),&
   & ZZI_PABSM(KIDIA:KFDIA,:,:),ZZZF(KIDIA:KFDIA,:,:),&
   & ZTM(KIDIA:KFDIA,:),&
   & ZZI_RM(KIDIA:KFDIA,:,:,1),ZZI_RM(KIDIA:KFDIA,:,:,2),&
   & ZZI_RM(KIDIA:KFDIA,:,:,4),ZZI_RHODREFM(KIDIA:KFDIA,:,:),&
   & ZZI_UM(KIDIA:KFDIA,:,:),ZZI_VM(KIDIA:KFDIA,:,:),&
   & ZZI_WM(KIDIA:KFDIA,:,:),ZZI_MFS(KIDIA:KFDIA,:),&
   & ZZI_CVTENDT(KIDIA:KFDIA,:),&
   & ZZI_CVTENDRV(KIDIA:KFDIA,:),ZZI_CVTENDRC(KIDIA:KFDIA,:),&
   & ZZI_CVTENDRI(KIDIA:KFDIA,:),ZCVTENDPR(KIDIA:KFDIA),&
   & ZCVTENDPRS(KIDIA:KFDIA)&
   & )  

  IF(MOD(KSTEP+1,NPRINTFR)==0) THEN
    WRITE(NULOUT,*)"Pluie conv au sol", ZCVTENDPR(NPTP),MAXVAL(ZCVTENDPR(:))&
     & ,MINVAL(ZCVTENDPR(:))  
  ENDIF

  DO JLON = KIDIA, KFDIA
    DO JLEV = 1, KLEV
      PTENDT(JLON,JLEV)=PTENDT(JLON,JLEV) + ZZI_CVTENDT(JLON,KLEV+2-JLEV)
      PTENDR(JLON,JLEV,1) = PTENDR(JLON,JLEV,1) + ZZI_CVTENDRV(JLON,KLEV+2-JLEV)&
       & *ZQDM(JLON,JLEV)  
      PTENDR(JLON,JLEV,2) = PTENDR(JLON,JLEV,2) + ZZI_CVTENDRC(JLON,KLEV+2-JLEV)&
       & *ZQDM(JLON,JLEV)  
      PTENDR(JLON,JLEV,4) = PTENDR(JLON,JLEV,4) + ZZI_CVTENDRI(JLON,KLEV+2-JLEV)&
       & *ZQDM(JLON,JLEV)  
    ENDDO
  ENDDO
  DO JLON = KIDIA, KFDIA
    DO JLEV= 1, KLEV+2
      ZZI_RS(JLON,1,JLEV,1)=ZZI_RSAVE(JLON,1,JLEV,1)+ZZI_CVTENDRV(JLON,JLEV)
      ZZI_RS(JLON,1,JLEV,2)=ZZI_RSAVE(JLON,1,JLEV,2)+ZZI_CVTENDRC(JLON,JLEV)
      ZZI_RS(JLON,1,JLEV,4)=ZZI_RSAVE(JLON,1,JLEV,4)+ZZI_CVTENDRI(JLON,JLEV)
    ENDDO
    DO JLEV=2,KLEV+1
      ZZI_THS(JLON,1,JLEV)=ZZI_THSAVE(JLON,1,JLEV)+ZZI_CVTENDT(JLON,JLEV)*(RATM/&
       & PAPRSFM(JLON,KLEV+2-JLEV))**(RD/RCPD)  
    ENDDO
    ZZI_THS(JLON,1,1)=ZZI_THS(JLON,1,2)
    ZZI_THS(JLON,1,KLEV+2)=ZZI_THS(JLON,1,KLEV+1)
  ENDDO
  DO JLON =KIDIA, KFDIA
    ZINPRR(JLON,1)=ZINPRR(JLON,1)+ZCVTENDPR(JLON)-ZCVTENDPRS(JLON)
    ZACPRR(JLON,1)=ZACPRR(JLON,1)+(ZCVTENDPR(JLON)-ZCVTENDPRS(JLON))*PDT
    ZINPRS(JLON,1)=ZINPRS(JLON,1)+ZCVTENDPRS(JLON)
    ZACPRS(JLON,1)=ZACPRS(JLON,1)+ZCVTENDPRS(JLON)*PDT
  ENDDO
  ! avance temporelle et inversion niveau pour ZZI_MFS
  ! on utilise PSIGS pour le flux de masse pour la condensation sous maille 
  ! car PSIGS n est utilise que si LOSIGMAS=T
  IF (LOSUBG_COND.AND..NOT.LOSIGMAS) THEN
    DO JLEV = 1 ,KLEV
      DO JLON = KIDIA,KFDIA
        PSIGS(JLON,JLEV)=ZZI_MFS(JLON,KLEV+2-JLEV)
      ENDDO
    ENDDO
  ENDIF
  IF(MOD(KSTEP+1,NPRINTFR)==0) THEN
    WRITE(NULOUT,*)"aps CONV, TENRV, TENRC, TENRI"
    DO JLEV=1,KLEV
      WRITE(NULOUT,*)PTENDR(NPTP,JLEV,1),PTENDR(NPTP,JLEV,2),PTENDR(NPTP,JLEV,4)
    ENDDO
  ENDIF
  CALL ARO_CONVBU(ZZI_RHODJM,ZZI_RS,ZZI_THS)
ENDIF

!    ------------------------------------------------------------------
!     8 - SURFACE. 
!     --------------------------------------------------------------------
!RSH: Branchement de la physique de surface qui etait dans surfext 
!     SURFEXT est appele par GP_MODEL

IF (LMSE) THEN

! Initialisations 

  LLD_NBLOCKTOT=.FALSE.
  ILEVFX=2
  DO JLON=KIDIA,KFDIA
    ZDEPTH_HEIGHT_LOW(JLON,1)= ZINVG* &
    & ( ZZI_APHIFM(JLON,KLEV)-POROG(JLON) ) 
     ZZS(JLON,1)=POROG(JLON)*ZINVG
     IF (ZDEPTH_HEIGHT_LOW(JLON,1) <= 0._JPRB) THEN
       WRITE (20,*)'sous apl_arome pb height en', JLON,ZZI_APHIFM(JLON,KLEV),POROG(JLON)
     ENDIF
  ENDDO

  DO JSG=1,NSW
     DO JL=KIDIA,KFDIA
        ZZSFSWDIR(JL,JSG)=PGPAR(JL,MSWDIR+JSG-1)
        ZZSFSWDIF(JL,JSG)=PGPAR(JL,MSWDIF+JSG-1)
     ENDDO
  ENDDO

  CALL ARO_GROUND_PARAM( KBL,KGPCOMP,LLD_NBLOCKTOT, &
   & ILONMNH,KIDIA,KFDIA,   &
   & NRR,NSW,NGFL_EXT,LMPA,CCOUPLING,&
   & NINDAT,REAL(RHGMT,JPRB),RSOVR,RCODEC,RSIDEC, &
   & ZZI_UM(KIDIA:KFDIA,1,ILEVFX), &
   & ZZI_VM(KIDIA:KFDIA,1,ILEVFX), &
   & ZTM(KIDIA:KFDIA,KLEV),ZZI_RM(KIDIA:KFDIA,1,ILEVFX,1),&
   & ZZI_SVM(KIDIA:KFDIA,1,ILEVFX,1:NGFL_EXT), &
   & ZCARDI,ZZI_RHODREFM(KIDIA:KFDIA,1,ILEVFX), &
   & ZZI_PABSM(KIDIA:KFDIA,1,ILEVFX),PAPRSM(KIDIA:KFDIA,KLEV), &
   & ZDTMSE,ZDEPTH_HEIGHT_LOW(KIDIA:KFDIA,1),ZZS(KIDIA:KFDIA,1), &
   & PMU0(KIDIA:KFDIA),PGELAM(KIDIA:KFDIA),PGEMU(KIDIA:KFDIA),XSW_BANDS,&
   & ZINPRR_NOTINCR(KIDIA:KFDIA,1),ZINPRS_NOTINCR(KIDIA:KFDIA,1), &
   & ZINPRG_NOTINCR(KIDIA:KFDIA,1), &
   & ZFRTHDS(KIDIA:KFDIA),ZZSFSWDIF(KIDIA:KFDIA,1:NSW), &
   & ZZSFSWDIR(KIDIA:KFDIA,1:NSW),&
   & ZCFAQ(KIDIA:KFDIA), ZCFATH(KIDIA:KFDIA), ZCFAU(KIDIA:KFDIA), &
   & ZCFBQ(KIDIA:KFDIA), ZCFBTH(KIDIA:KFDIA), ZCFBU(KIDIA:KFDIA), &
   & ZCFBV(KIDIA:KFDIA), &
   & ZSFTH(KIDIA:KFDIA,1),ZSFRV(KIDIA:KFDIA,1), &
   & ZSFSV(KIDIA:KFDIA,1,1:NGFL_EXT),ZSFCO2(KIDIA:KFDIA,1), &
   & ZSFU(KIDIA:KFDIA,1),ZSFV(KIDIA:KFDIA,1), &
   & ZALBP(KIDIA:KFDIA,1:NSW),ZALBD(KIDIA:KFDIA,1:NSW), &
   & ZEMIS(KIDIA:KFDIA),ZTSURF(KIDIA:KFDIA))
   IF (LRCO2) THEN
     ZSFSV(KIDIA:KFDIA,1,NSV_CO2)= ZSFCO2(KIDIA:KFDIA,1)
!print*,' FLUX CO2 =', MINVAL(ZSFSV(KIDIA:KFDIA,1,NSV_CO2)),&
!                      MAXVAL(ZSFSV(KIDIA:KFDIA,1,NSV_CO2))
   ENDIF

!!!!! TEST DDH ATTENTION
!ZSFRV = 0._JPRB

  CALL ARO_GROUND_DIAG( KBL, KGPCOMP, LLD_NBLOCKTOT , &
   & ILONMNH,KIDIA,KFDIA,  &
   & ZZS(KIDIA:KFDIA,1), &
   & ZZI_UM(KIDIA:KFDIA,1,ILEVFX), &
   & ZZI_VM(KIDIA:KFDIA,1,ILEVFX), &
   & ZQS(KIDIA:KFDIA),ZGZ0(KIDIA:KFDIA),ZGZ0H(KIDIA:KFDIA), &
   & PTCLS(KIDIA:KFDIA),PQCLS(KIDIA:KFDIA),PHUCLS(KIDIA:KFDIA), &
   & PUCLS(KIDIA:KFDIA),PVCLS(KIDIA:KFDIA), &
   & ZFCLL(KIDIA:KFDIA),ZFCLN(KIDIA:KFDIA)) 

!* Compute PBL-diagnostics
   
   CALL AROCLDIA(KIDIA,KFDIA,ILONMNH,PUCLS(KIDIA:KFDIA), &
    & PVCLS(KIDIA:KFDIA),PTKEM(KIDIA:KFDIA,KLEV),PUGST(KIDIA:KFDIA),&
    & PVGST(KIDIA:KFDIA) ) 
      
    

ENDIF

!   CALL ARO_GROUND_DIAG( KBL, KGPCOMP, LLD_NBLOCKTOT , &
!    & ILONMNH,KIDIA,KFDIA,  &
!    & ZZS(KIDIA:KFDIA), &
!    & ZZI_UM(KIDIA:KFDIA,1:1,ILEVFX:ILEVFX), &
!    & ZZI_VM(KIDIA:KFDIA,1:1,ILEVFX:ILEVFX), &
!    & ZQS(KIDIA:KFDIA),ZGZ0(KIDIA:KFDIA),ZGZ0H(KIDIA:KFDIA), &
!    & PTCLS(KIDIA:KFDIA),PQCLS(KIDIA:KFDIA),PHUCLS(KIDIA:KFDIA), &
!    & PUCLS(KIDIA:KFDIA),PVCLS(KIDIA:KFDIA), &
!    & ZFCLL(KIDIA:KFDIA),ZFCLN(KIDIA:KFDIA))

!*            IDEALIZED TURBULENT SURFACE FLUXES FOR SQUALL LINE CASE
!                --------------------------------------------------------

IF (LSQUALL.AND.LTURB) THEN
  ! on n'a besoin que d'un flux sur V (U est nul). 
  DO JLON=KIDIA,KFDIA
    IF (ABS(ZZI_VM(JLON,1,2)) <= 1.E-12) THEN
      ZSFV(JLON,1)=0.
    ELSE
      ZSFV(JLON,1)=-(ZZI_VM(JLON,1,2))**2 * &
       & (0.4_JPRB  /(LOG(ZZZF(JLON,1,2)/0.2_JPRB) ) )**2 &
       & *ZZI_VM(JLON,1,2)/ABS(ZZI_VM(JLON,1,2))  
    ENDIF
  ENDDO
ENDIF


!    ------------------------------------------------------------------
!      Shallow Mass Flux Mixing
!    ------------------------------------------------------------------
IF (LMFSHAL) THEN
    IF (CMF_UPDRAFT=='DUAL') THEN
    ! Updraft computation from EDMF/ECMWF dual proposal
    ! Version May 2007
    ! 
    ! The following routine  are using arrays with the vertical Arpege/IFS fashion (as in the radiation scheme)

    IDRAFT = 2 ! beginning of the loop for MF tendency equation
               ! only 2 and 3 are used for tendency computation in ARO_SHALLOW_MF
    NDRAFT=3   ! 1 for test, 2 for dry, 3 for wet
    ALLOCATE(ZMF_UP(KLON,0:KLEV,NDRAFT))
    ALLOCATE(ZTHETAL_UP(KLON,0:KLEV,NDRAFT))
    ALLOCATE(ZQT_UP(KLON,0:KLEV,NDRAFT))
    ALLOCATE(ZTHTV_UP(KLON,0:KLEV,NDRAFT))
    ALLOCATE(ZQC_UP(KLON,0:KLEV,NDRAFT))
    ALLOCATE(ZQI_UP(KLON,0:KLEV,NDRAFT))
    ALLOCATE(ZU_UP(KLON,0:KLEV,NDRAFT))
    ALLOCATE(ZV_UP(KLON,0:KLEV,NDRAFT))

    ZZSFTH(:)=-1._JPRB*ZSFTH(:,1)*(PAPRSM(:,KLEV)*ZINVATM)**(ZRSCP)
    ZZSFRV(:)=-1._JPRB*ZSFRV(:,1)
    ZZSFU(:)=ZSFU(:,1)
    ZZSFV(:)=ZSFV(:,1)

    CALL VDFHGHTHL(KSTEP,KIDIA,KFDIA,KLON,KLEV,NDRAFT,&
     & ZDT, PUM, PVM,  &   
     & ZTM,ZQVM,ZQCM,ZQIM,PCLFS, &
     & PAPRSM, PAPRSFM, ZZI_APHIFM,ZZI_APHIM, &
     & ZZSFTH(KIDIA:KFDIA),ZZSFRV(KIDIA:KFDIA), &
     & ZZSFU(KIDIA:KFDIA),ZZSFV(KIDIA:KFDIA), &
     & ZMF_UP,ZTHETAL_UP,ZQT_UP,ZTHTV_UP,ZQC_UP,ZQI_UP, & 
     & ZU_UP, ZV_UP,&
     & NGFL_EZDIAG, PEZDIAG, &
     & TENDQVUP,TENDTUP,SURFPREP,SURFSNOW)

    !  tendtup, tendqvup  tendencies for non-conserved AROME
    !  variables due to updraft precipitation/snow (and its evaporation)
    DO JLEV = 2 ,KLEV
      DO JLON = KIDIA,KFDIA
        PTENDT(JLON,JLEV)=PTENDT(JLON,JLEV) + TENDTUP(JLON,JLEV)
        PTENDR(JLON,JLEV,1)=PTENDR(JLON,JLEV,1) + TENDQVUP(JLON,JLEV)
      ENDDO
    ENDDO

    !  add surface updraft precipitation to precipitation
    !  devide surfprep and surfsnow by rho to go from kg/(m2s) to m/s
    DO JLON =KIDIA, KFDIA
      SURFRHO(JLON)=PAPRSFM(JLON,KLEV)/(PRM(JLON,KLEV)*ZTM(JLON,KLEV))
      ZINPRR(JLON,1)=ZINPRR(JLON,1)+SURFPREP(JLON)/SURFRHO(JLON)
      ZACPRR(JLON,1)=ZACPRR(JLON,1)+(SURFPREP(JLON)/SURFRHO(JLON))*PDT
      ZINPRS(JLON,1)=ZINPRS(JLON,1)+SURFSNOW(JLON)/SURFRHO(JLON)
      ZACPRS(JLON,1)=ZACPRS(JLON,1)+(SURFSNOW(JLON)/SURFRHO(JLON))*PDT
    ENDDO
  ELSE
    NDRAFT=1
    IDRAFT=3 ! only a wet updraft
  ENDIF

  DO JDRAFT=IDRAFT,3
  !!! Call mass fluxes computations
  ! If CMF_UPDRAFT='DUAL', the updraft characteritics are already computed and will be passed as inputs of SHALLOW_MF
  ! if not, they will be computed in SHALLOW_MF itself (from Méso-NH type routines)

  ! JDRAFT=2 : dry updraft
  ! JDRAFT=3 : wet updraft

  IF (CMF_UPDRAFT=='DUAL') THEN
    ! Goes from one of the updraft from the IFS level world to the Méso-NH level world 
    ! (put levels upside down, go from q to r)
    DO JLEV = 2 , KLEV+2
      DO JLON = KIDIA,KFDIA
         ZZI_MF_UP(JLON,1,JLEV) = ZMF_UP(JLON,KLEV+1+1-JLEV,JDRAFT)
         ZZI_ZU_UP(JLON,1,JLEV) = ZU_UP(JLON,KLEV+1+1-JLEV,JDRAFT)
         ZZI_ZV_UP(JLON,1,JLEV) = ZV_UP(JLON,KLEV+1+1-JLEV,JDRAFT)
         ZZI_THETAL_UP(JLON,1,JLEV) = ZTHETAL_UP(JLON,KLEV+1+1-JLEV,JDRAFT)
         ZZI_THETAV_UP(JLON,1,JLEV) = ZTHTV_UP(JLON,KLEV+1+1-JLEV,JDRAFT)
         ZZI_RT_UP(JLON,1,JLEV)  = ZQT_UP(JLON,KLEV+1+1-JLEV,JDRAFT)/ &
          &                         (1.-ZQT_UP(JLON,KLEV+1+1-JLEV,JDRAFT))
         ZZI_RC_UP(JLON,1,JLEV)  = ZQC_UP(JLON,KLEV+1+1-JLEV,JDRAFT) / &
          &                         (1.-ZQT_UP(JLON,KLEV+1+1-JLEV,JDRAFT))
         ZZI_RI_UP(JLON,1,JLEV)  = ZQI_UP(JLON,KLEV+1+1-JLEV,JDRAFT)/ &
          &                         (1.-ZQT_UP(JLON,KLEV+1+1-JLEV,JDRAFT))
      ENDDO
    ENDDO
    DO JLON = KIDIA,KFDIA
      ZZI_MF_UP(JLON,1,1) = ZZI_MF_UP(JLON,1,2) 
      ZZI_ZU_UP(JLON,1,1) = ZZI_ZU_UP(JLON,1,2) 
      ZZI_ZV_UP(JLON,1,1) = ZZI_ZV_UP(JLON,1,2) 
      ZZI_THETAL_UP(JLON,1,1) = ZZI_THETAL_UP(JLON,1,2)
      ZZI_THETAV_UP(JLON,1,1) = ZZI_THETAV_UP(JLON,1,2)
      ZZI_RT_UP(JLON,1,1)  =  ZZI_RT_UP(JLON,1,2)
      ZZI_RC_UP(JLON,1,1)  = ZZI_RC_UP(JLON,1,2)
      ZZI_RI_UP(JLON,1,1)  = ZZI_RI_UP(JLON,1,2) 
    ENDDO
  ENDIF

  IF(MOD(KSTEP+1,NPRINTFR)==0) THEN
    WRITE(NULOUT,*)"apres surface zsfth zsfrv",ZSFTH(NPTP,1),ZSFRV(NPTP,1)
  ENDIF


  ! sauvegarde pour le calcul des tendances
  ZZI_USAVE=ZZI_US
  ZZI_VSAVE=ZZI_VS

  ZZI_THSAVE=ZZI_THS
  ZZI_RSAVE=ZZI_RS

  ZRC_MF = 0.0_JPRB
  ZCF_MF = 0.0_JPRB

  CALL ARO_SHALLOW_MF (ILONMNH,KLEV,NRR,NRRL,NRRI,NGFL_EXT, &
   & CMF_UPDRAFT, CMF_CLOUD, LMIXUV,                   &
   & KSTEP+1, ZDT,                                       &
   & ZZZ(KIDIA:KFDIA,:,:), ZZZF(KIDIA:KFDIA,:,:),        &
   & ZZI_RHODJM(KIDIA:KFDIA,:,:),ZZI_RHODREFM(KIDIA:KFDIA,:,:), &
   & ZZI_PABSM(KIDIA:KFDIA,:,:),                         &
   & ZZI_EXNREFM(KIDIA:KFDIA,:,:),                       &
   & ZSFTH(KIDIA:KFDIA,1),ZSFRV(KIDIA:KFDIA,1),      &
   & ZZI_THM(KIDIA:KFDIA,:,:),ZZI_RM(KIDIA:KFDIA,:,:,:), &
   & ZZI_UM(KIDIA:KFDIA,:,:),ZZI_VM(KIDIA:KFDIA,:,:),    &
   & ZZI_TKEM(KIDIA:KFDIA,:,:),ZZI_SVM(KIDIA:KFDIA,:,:,:), &
   & ZZI_MF_UP(KIDIA:KFDIA,:,:),ZZI_THETAL_UP(KIDIA:KFDIA,:,:), &
   & ZZI_THETAV_UP(KIDIA:KFDIA,:,:),ZZI_RT_UP(KIDIA:KFDIA,:,:), &
   & ZZI_RC_UP(KIDIA:KFDIA,:,:),ZZI_RI_UP(KIDIA:KFDIA,:,:), &
   & ZZI_ZU_UP(KIDIA:KFDIA,:,:),ZZI_ZV_UP(KIDIA:KFDIA,:,:),&
   & ZZI_THS(KIDIA:KFDIA,:,:),ZZI_RS(KIDIA:KFDIA,:,:,:), &
   & ZZI_US(KIDIA:KFDIA,:,:),ZZI_VS(KIDIA:KFDIA,:,:),ZZI_SVS(KIDIA:KFDIA,:,:,:),   &
   & ZSIGMF(KIDIA:KFDIA,:,:),ZRC_MF(KIDIA:KFDIA,:,:),ZCF_MF(KIDIA:KFDIA,:,:), &
   & ZFLXZTHVMF )
  ZFLXZTHVMF_SUM=ZFLXZTHVMF_SUM+ZFLXZTHVMF
  ! traitement des sorties pour repasser dans le monde Aladin

IF (CMF_CLOUD=='DIRE'.AND.JDRAFT==3) THEN
  ! sauvegarde pour le schéma de nuage
  DO JLEV = 1 ,KLEV
    DO JLON = KIDIA,KFDIA
      PEZDIAG(JLON,JLEV,1)=ZRC_MF(JLON,1,KLEV+2-JLEV)
      PEZDIAG(JLON,JLEV,2)=ZCF_MF(JLON,1,KLEV+2-JLEV)
    ENDDO
  ENDDO
ENDIF

  !calcul de tendance et inversion des niveaux pour le vent horizontal
  DO JLEV = 1 ,KLEV
    DO JLON = KIDIA,KFDIA
      PTENDU(JLON,JLEV)=PTENDU(JLON,JLEV)+(ZZI_US(JLON,1,KLEV+2-JLEV)-&
       & ZZI_USAVE(JLON,1,KLEV+2-JLEV))
      PTENDV(JLON,JLEV)=PTENDV(JLON,JLEV)+(ZZI_VS(JLON,1,KLEV+2-JLEV)-&
       & ZZI_VSAVE(JLON,1,KLEV+2-JLEV))
    ENDDO
  ENDDO

  !conversion de la tendance de theta en tendance de T et inversion niveau
  DO JLEV = 1 ,KLEV
    DO JLON = KIDIA,KFDIA
      PTENDT(JLON,JLEV)=PTENDT(JLON,JLEV)+(ZZI_THS(JLON,1,KLEV+2-JLEV)-&
       & ZZI_THSAVE(JLON,1,KLEV+2-JLEV))*ZZI_EXNREFM(JLON,1,KLEV+2-JLEV)
    ENDDO
  ENDDO

  !inversion niveaux tendances des ri et conversion en qi en multipliant par qd
  DO JR=1,NRR
    DO JLEV=1,KLEV
      DO JLON=KIDIA,KFDIA
        PTENDR(JLON,JLEV,JR)= PTENDR(JLON,JLEV,JR) &
         & +(ZZI_RS(JLON,1,KLEV+2-JLEV,JR)         &
         & -ZZI_RSAVE(JLON,1,KLEV+2-JLEV,JR))*ZQDM(JLON,JLEV)
      ENDDO
    ENDDO
  ENDDO

! End loop on JDRAFT
ENDDO

IF (ALLOCATED(ZMF_UP) ) &
  DEALLOCATE (ZMF_UP, ZTHETAL_UP, ZTHTV_UP, ZQT_UP, ZQC_UP, ZQI_UP, ZU_UP, ZV_UP)

! End test (IF LMFSHAL)
ENDIF


!    ------------------------------------------------------------------
!     9 - TURBULENCE. 
!     --------------------------------------------------------------------
IF (LTURB) THEN

  ! 8.1 sauvegarde pour le calcul des tendances
  ZZI_USAVE=ZZI_US
  ZZI_VSAVE=ZZI_VS
  ZZI_WSAVE=ZZI_WS
  ZZI_THSAVE=ZZI_THS
  ZZI_RSAVE=ZZI_RS
  ZZI_TKESAVE=ZZI_TKES
  IF (NGFL_EXT/=0) THEN
    ZZI_SVSAVE=ZZI_SVS
  ENDIF

  !prints
  IF(MOD(KSTEP+1,NPRINTFR)==0) THEN
    WRITE(NULOUT,*)'avant d entrer dans turb sous apl_arome U'
    WRITE(NULOUT,*)MAXVAL(ZZI_UM(KIDIA:KFDIA,1,2)), &
     & MINVAL(ZZI_UM(KIDIA:KFDIA,1,2))
    WRITE(NULOUT,*)'avant d entrer dans turb sous apl_arome V'
    WRITE(NULOUT,*)MAXVAL(ZZI_VM(KIDIA:KFDIA,1,2)), &
     & MINVAL(ZZI_VM(KIDIA:KFDIA,1,2))
    WRITE(NULOUT,*)'avant d entrer dans turb sous apl_arome W'
    WRITE(NULOUT,*)MAXVAL(ZZI_WM(KIDIA:KFDIA,1,2)), &
     & MINVAL(ZZI_WM(KIDIA:KFDIA,1,2))
    WRITE(NULOUT,*)'avant d entrer dans turb sous apl_arome TKE'
    WRITE(NULOUT,*)MAXVAL(ZZI_TKEM(KIDIA:KFDIA,1,2)), &
     & MINVAL(ZZI_TKEM(KIDIA:KFDIA,1,2))
    DO JLEV=1,KLEV+2
      WRITE(NULOUT,*)JLEV,ZZI_UM(NPTP,1,JLEV),ZZI_VM(NPTP,1,JLEV)&
      &,ZZI_WM(NPTP,1,JLEV),ZZI_TKEM(NPTP,1,JLEV)
    ENDDO
    WRITE(NULOUT,*)'u v w tke a S'
    DO JLEV=1,KLEV+2
      WRITE(NULOUT,*)JLEV,ZZI_US(NPTP,1,JLEV),ZZI_VS(NPTP,1,JLEV)&
      &,ZZI_WS(NPTP,1,JLEV),ZZI_TKES(NPTP,1,JLEV)
    ENDDO
    WRITE(NULOUT,*)'ZZI_THS avant turb'
    DO JLEV=1,KLEV+2
      WRITE(NULOUT,*)JLEV,ZZI_THS(NPTP,1,JLEV)
    ENDDO
  ENDIF
 
  ! 8.2 calcul TURB

  CALL ARO_TURB_MNH(ILONMNH,KLEV,NRR, NRRL, NRRI,NGFL_EXT,&
   & KSTEP+1, ZDT,                                       &
   & ZZZ(KIDIA:KFDIA,:,:), ZZZF(KIDIA:KFDIA,:,:),          &
   & ZZI_RHODJM(KIDIA:KFDIA,:,:), ZTHVREFM(KIDIA:KFDIA,:,:),&
   & ZZI_RHODREFM(KIDIA:KFDIA,:,:), 'M',                  &
   & ZSFTH(KIDIA:KFDIA,1),ZSFRV(KIDIA:KFDIA,1),ZSFSV(KIDIA:KFDIA,:,:),&
   & ZSFU(KIDIA:KFDIA,1),ZSFV(KIDIA:KFDIA,1),ZZI_PABSM(KIDIA:KFDIA,:,:),&
   & ZZI_UM(KIDIA:KFDIA,:,:),ZZI_VM(KIDIA:KFDIA,:,:),&
   & ZZI_WM(KIDIA:KFDIA,:,:),ZZI_TKEM(KIDIA:KFDIA,:,:),ZEPSM,&
   & ZZI_SVM(KIDIA:KFDIA,:,:,:),ZSRCS(KIDIA:KFDIA,:,:),            &
   & ZZI_UM(KIDIA:KFDIA,:,:),ZZI_VM(KIDIA:KFDIA,:,:),ZZI_WM(KIDIA:KFDIA,:,:),&
   & ZZI_THM(KIDIA:KFDIA,:,:),ZZI_RM(KIDIA:KFDIA,:,:,:),    &
   & ZZI_US(KIDIA:KFDIA,:,:),ZZI_VS(KIDIA:KFDIA,:,:),ZZI_WS(KIDIA:KFDIA,:,:),&
   & ZZI_THS(KIDIA:KFDIA,:,:),ZZI_RS(KIDIA:KFDIA,:,:,:),&
   & ZZI_SVS(KIDIA:KFDIA,:,:,:),ZZI_TKES(KIDIA:KFDIA,:,:),&
   & ZEPSS,ZZI_SIGS(KIDIA:KFDIA,:,:),LOSUBG_COND,ZFLXZTHVMF_SUM )  

  IF(MOD(KSTEP+1,NPRINTFR)==0) THEN
    WRITE(NULOUT,*)'u v w a S apres turb'
    DO JLEV=1,KLEV+2
      WRITE(NULOUT,*)JLEV,ZZI_US(NPTP,1,JLEV),ZZI_VS(NPTP,1,JLEV)&
       &,ZZI_WS(NPTP,1,JLEV),ZZI_TKES(NPTP,1,JLEV)
    ENDDO
    WRITE(NULOUT,*)'THS TKES SIGS apres turb'
    DO JLEV=1,KLEV+2
      WRITE(NULOUT,*)JLEV,ZZI_THS(NPTP,1,JLEV),ZZI_TKES(NPTP,1,JLEV)&
       &,ZZI_SIGS(NPTP,1,JLEV)
    ENDDO
  ENDIF

  ! avance temporelle et inversion niveau pour ZZI_SIGS
  IF (LOSUBG_COND .AND. LOSIGMAS) THEN
    DO JLEV = 1 ,KLEV
      DO JLON = KIDIA,KFDIA
        PSIGS(JLON,JLEV)=SQRT(ZZI_SIGS(JLON,1,KLEV+2-JLEV)**2+ZSIGMF(JLON,1,KLEV+2-JLEV)**2 )
      ENDDO
    ENDDO
  ENDIF
  
  !8.3. traitement des sorties pour repasser dans le monde Aladin
  !calcul de tendance et inversion des niveaux pour le vent horizontal et la TKE
           
  DO JLEV = 1 ,KLEV
    DO JLON = KIDIA,KFDIA
      PTENDU(JLON,JLEV)=PTENDU(JLON,JLEV)+(ZZI_US(JLON,1,KLEV+2-JLEV)-&
       & ZZI_USAVE(JLON,1,KLEV+2-JLEV))  
      PTENDV(JLON,JLEV)=PTENDV(JLON,JLEV)+(ZZI_VS(JLON,1,KLEV+2-JLEV)-&
       & ZZI_VSAVE(JLON,1,KLEV+2-JLEV))  
      ! for the moment, turbulence do not compute w tendency:
      PTENDW(JLON,JLEV)=0.0_JPRB
      ! PTENDW(JLON,JLEV)+(ZZI_WS(JLON,1,KLEV+2-JLEV)-&
      ! & ZZI_WSAVE(JLON,1,KLEV+2-JLEV))  
      PTENDTKE(JLON,JLEV)=PTENDTKE(JLON,JLEV)+(ZZI_TKES(JLON,1,KLEV+2-JLEV)-&
       & ZZI_TKESAVE(JLON,1,KLEV+2-JLEV))  
    ENDDO
  ENDDO
  
  IF(NGFL_EXT/=0) THEN
    DO JLEV = 1 ,KLEV
      DO JLON = KIDIA,KFDIA
        PTENDEXT(JLON,JLEV,:)=PTENDEXT(JLON,JLEV,:)+ &
         & (ZZI_SVS(JLON,1,KLEV+2-JLEV,:)- &
         & ZZI_SVSAVE(JLON,1,KLEV+2-JLEV,:))  
      ENDDO
    ENDDO
  ENDIF  


  !conversion de la tendance de theta en tendance de T et inversion niveau 
  DO JLEV = 1 ,KLEV
    DO JLON = KIDIA,KFDIA
      PTENDT(JLON,JLEV)=PTENDT(JLON,JLEV)+(ZZI_THS(JLON,1,KLEV+2-JLEV)-&
       & ZZI_THSAVE(JLON,1,KLEV+2-JLEV))*ZZI_EXNREFM(JLON,1,KLEV+2-JLEV)  
    ENDDO
  ENDDO
  !inversion niveaux tendances des ri et conversion en qi en multipliant par qd 
  DO JR=1,NRR
    DO JLEV=1,KLEV
      DO JLON=KIDIA,KFDIA
        PTENDR(JLON,JLEV,JR)= PTENDR(JLON,JLEV,JR) &
         & +(ZZI_RS(JLON,1,KLEV+2-JLEV,JR)         &
         & -ZZI_RSAVE(JLON,1,KLEV+2-JLEV,JR))*ZQDM(JLON,JLEV)  
      ENDDO
    ENDDO
  ENDDO
  
ENDIF

!    ------------------------------------------------------------------
!     10 - MICROPHYSIQUE. 
!     --------------------------------------------------------------------
IF (LMICRO) THEN

  ZZI_THSAVE=ZZI_THS
  ZZI_RSAVE=ZZI_RS
  
  !prints
  IF (MOD(KSTEP+1,NPRINTFR)==0) THEN
    WRITE(NULOUT,*)'avant rain_ice sous apl_arome'
    WRITE(NULOUT,*)'JLEV   ZZZF      ZZZ      ZRHODREF',&
     & '    ZRHODJ      ZZI_PABSM        ZZI_THS       ZZI_THM      '   
    DO JLEV=1,KLEV+1 
      WRITE(NULOUT,'(I2,x,7f10.3)')JLEV,ZZZF(NPTP,1,JLEV),ZZZ(NPTP,1,JLEV),&
       & ZZI_RHODREFM(NPTP,1,JLEV),&
       & ZZI_RHODJM(NPTP,1,JLEV), ZZI_PABSM(NPTP,1,JLEV), ZZI_THS(NPTP,1,JLEV),&
       & ZZI_THM(NPTP,1,JLEV)  
    ENDDO 
    WRITE(NULOUT,*)'JLEV        PDELPM        ZZI_PABSM         ZEXNREF',&
       &'          ZZI_SIGS'
    DO JLEV=2,KLEV
      WRITE(NULOUT,'(I2,x,4f10.3)')JLEV, PDELPM(NPTP,KLEV+2-JLEV),&
       & ZZI_PABSM(NPTP,1,JLEV),ZZI_EXNREFM(NPTP,1,JLEV),ZZI_SIGS(NPTP,1,JLEV)  
    ENDDO
    WRITE(NULOUT,*)'JLEV    PTM       PRM          PCPM'
    DO JLEV=1,KLEV
      WRITE(NULOUT,'(I2,x,3f10.3)')JLEV,ZTM(NPTP,KLEV+1-JLEV),&
       & ZRHM(NPTP,KLEV+1-JLEV)&
       & ,ZCPM(NPTP,KLEV+1-JLEV)  
    ENDDO
    WRITE (NULOUT,*)'JLEV  rhoQv  rhoQc   rhoQr   rhoQi   rhoQs   rhoQg'
    DO JLEV=1,KLEV+2
      WRITE(NULOUT,'(I2,x,6e11.4)')JLEV,ZZI_RM(NPTP,1,JLEV,1), &
       & ZZI_RM(NPTP,1,JLEV,2),&
       & ZZI_RM(NPTP,1,JLEV,3),ZZI_RM(NPTP,1,JLEV,4),ZZI_RM(NPTP,1,JLEV,5),&
       & ZZI_RM(NPTP,1,JLEV,6)  
    ENDDO
    WRITE (NULOUT,*)'JLEV  ZRSQv  ZRSQc   ZRSQr   ZRSQi   ZRSQs   ZRSQg'
    DO JLEV=1,KLEV+2
      WRITE(NULOUT,'(I2,x,6e11.4)')JLEV,ZZI_RS(NPTP,1,JLEV,1), &
       & ZZI_RS(NPTP,1,JLEV,2),&
       & ZZI_RS(NPTP,1,JLEV,3),ZZI_RS(NPTP,1,JLEV,4),ZZI_RS(NPTP,1,JLEV,5),&
       & ZZI_RS(NPTP,1,JLEV,6)  
    ENDDO
    WRITE(NULOUT,*)'ZDT=',ZDT
    WRITE(NULOUT,*)'NRR & co',NRR,KSTEP+1,NSPLITR,LOSUBG_COND,&
     & LOSIGMAS, LOSUBG_AUCV,LOWARM  
  ENDIF
  
  ! because of leap-frog time step supposed in mesoNH we have to divide ACPR*
  !  by two before calling AC_RAIN_ICE and multiply after 
  DO JLON=KIDIA,KFDIA
    ZACPRR(JLON,1)=0.5_JPRB*ZACPRR(JLON,1)
    ZACPRS(JLON,1)=0.5_JPRB*ZACPRS(JLON,1)
    ZACPRG(JLON,1)=0.5_JPRB*ZACPRG(JLON,1)
  ENDDO

  CALL ARO_RAIN_ICE (ILONMNH,KLEV,NRR,KSTEP+1,NSPLITR,&
   & LOSUBG_COND, LOSUBG_AUCV, LOSEDIC,&
   & ZDT,ZZZ(KIDIA:KFDIA,:,:) ,&
   & ZZI_RHODJM(KIDIA:KFDIA,:,:),ZZI_RHODREFM(KIDIA:KFDIA,:,:),&
   & ZZI_EXNREFM(KIDIA:KFDIA,:,:),&
   & ZZI_PABSM(KIDIA:KFDIA,:,:),&
   & ZZI_THM(KIDIA:KFDIA,:,:),ZZI_RM(KIDIA:KFDIA,:,:,:),&
   & ZZI_SIGS(KIDIA:KFDIA,:,:),&
   & ZZI_THS(KIDIA:KFDIA,:,:),ZZI_RS(KIDIA:KFDIA,:,:,:), &
   & ZEVAP(KIDIA:KFDIA,:,:), &
   & ZCIT(KIDIA:KFDIA,:,:),LOWARM,&
   & ZINPRR_NOTINCR(KIDIA:KFDIA,1),ZACPRR(KIDIA:KFDIA,1),&
   & ZINPRS_NOTINCR(KIDIA:KFDIA,1),ZACPRS(KIDIA:KFDIA,1),&
   & ZINPRG_NOTINCR(KIDIA:KFDIA,1),ZACPRG(KIDIA:KFDIA,1),&
   & ZINPRH_NOTINCR(KIDIA:KFDIA,1) )  

  DO JLON=KIDIA,KFDIA
    ZINPRR(JLON,1)=ZINPRR(JLON,1)+ZINPRR_NOTINCR(JLON,1)
    ZINPRS(JLON,1)=ZINPRS(JLON,1)+ZINPRS_NOTINCR(JLON,1)
    ZINPRG(JLON,1)=ZINPRG(JLON,1)+ZINPRG_NOTINCR(JLON,1)
    ZINPRH(JLON,1)=ZINPRH(JLON,1)+ZINPRH_NOTINCR(JLON,1)
    ZACPRR(JLON,1)=2._JPRB*ZACPRR(JLON,1)
    ZACPRS(JLON,1)=2._JPRB*ZACPRS(JLON,1)
    ZACPRG(JLON,1)=2._JPRB*ZACPRG(JLON,1)
  ENDDO

  !conversion de la tendance de theta en tendance de T et inversion niveau
  DO JLEV = 1 ,KLEV
    DO JLON = KIDIA,KFDIA
      PTENDT(JLON,JLEV)= PTENDT(JLON,JLEV)+(ZZI_THS(JLON,1,KLEV+2-JLEV)-&
       & ZZI_THSAVE(JLON,1,KLEV+2-JLEV))*ZZI_EXNREFM(JLON,1,KLEV+2-JLEV)  
    ENDDO
  ENDDO
  
  !inversion niveaux tendances des ri et conversion en qi en multipliant par qd
  DO JR=1,NRR
    DO JLEV=1,KLEV
      DO JLON=KIDIA,KFDIA
        PTENDR(JLON,JLEV,JR)=PTENDR(JLON,JLEV,JR)         &
         & +(ZZI_RS(JLON,1,KLEV+2-JLEV,JR)  &
         & -ZZI_RSAVE(JLON,1,KLEV+2-JLEV,JR))*ZQDM(JLON,JLEV)  
      ENDDO
    ENDDO
  ENDDO
        
  !prints    
  IF(MOD(KSTEP+1,NPRINTFR)==0) THEN
    WRITE(NULOUT,*)'PTENDT en sortie de rain_ice'
    WRITE(NULOUT,*)'ZZI_THS en sortie de rain_ice'
    DO JLEV=1,KLEV
      WRITE(NULOUT,*)PTENDT(NPTP,JLEV),ZZI_THS(NPTP,1,JLEV)
    ENDDO
    WRITE (NULOUT,*)'JLEV  ZTENDQv  ZTZNDQc   ZTENDQr   ZTENDQi'&
     & ,'ZTENDQs   ZTENDQg'  
    DO JLEV=1,KLEV
      WRITE(NULOUT,'(I2,x,6e11.4)')JLEV,PTENDR(NPTP,JLEV,1),&
       & PTENDR(NPTP,JLEV,2),&
       & PTENDR(NPTP,JLEV,3),PTENDR(NPTP,JLEV,4),PTENDR(NPTP,JLEV,5),&
       & PTENDR(NPTP,JLEV,6)  
    ENDDO
    WRITE (NULOUT,*) 'ZSRCS et ZNEBMNH',MAXVAL(ZSRCS),MAXVAL(ZNEBMNH) 
  ENDIF
  
  IF (LRDEPOS) THEN
    ZZI_SVSAVE=ZZI_SVM
    CALL ARO_RAINAERO(ILONMNH,KLEV,NGFL_EXT,NRR, PDT,        &
        &          ZZI_SVM(KIDIA:KFDIA,:,:,1:NGFL_EXT),   &
        &          ZZZ(KIDIA:KFDIA,:,:),                  &
        &          ZZI_PABSM(KIDIA:KFDIA,:,:),            &
        &          ZZI_THM(KIDIA:KFDIA,:,:),              &
        &          ZZI_RHODREFM(KIDIA:KFDIA,:,:),         &
        &          KSTEP+1,                               &
        &          ZZI_RM(KIDIA:KFDIA,:,:,:),             &
        &          ZEVAP(KIDIA:KFDIA,:,:),                &
        &          NSPLITR               )
! return to tendency
     DO JLEV = 1 ,KLEV
       DO JLON = KIDIA,KFDIA
         PTENDEXT(JLON,JLEV,:)=PTENDEXT(JLON,JLEV,:)+&
         & (ZZI_SVM(JLON,1,KLEV+2-JLEV,:)-&
         & ZZI_SVSAVE(JLON,1,KLEV+2-JLEV,:))*ZINVDT
       ENDDO
     ENDDO
  ENDIF

ENDIF
    
!    ------------------------------------------------------------------
!     11 - SAVE FIELDS FOR EXT. SURFACE.
!     --------------------------------------------------------------------
!    Cette partie n'est plus necessaire apres branchement de la physique 
!    de surface sous apl_arome

!    ------------------------------------------------------------------
!     12 - CALL CHEMICAL SCHEME.
!     --------------------------------------------------------------------
IF (LUSECHEM) THEN
! ANNEE
IYEAR = NINDAT / 10000
! MOIS
IMONTH = (NINDAT - 10000*IYEAR ) / 100
! JOUR DU MOIS
IDAY = NINDAT - 10000*IYEAR - 100*IMONTH

DO JLON = KIDIA,KFDIA
  ZLAT(JLON,1) = 180. * ASIN(PGEMU(JLON)) / (2.*ASIN(1.))
  ZLON(JLON,1) = 180. * PGELAM(JLON) / (2.*ASIN(1.))
  ZZENITH(JLON,1) = ACOS( PMU0(JLON) )
   ZZS(JLON,1)=POROG(JLON)/RG
   ZALB_UV(JLON,1)=ZALBP(JLON,1)
ENDDO

DO JGFL=1,NGFL_EXT
  DO JLEV=2,KLEV+1
    DO JLON= KIDIA,KFDIA
     ZZI_SVS(JLON,1,JLEV, JGFL)=MAX(0.0_JPRB, ZZI_SVS(JLON,1,JLEV, JGFL))
     ZZI_SVSAVE(JLON,1,JLEV, JGFL)=ZZI_SVS(JLON,1,JLEV, JGFL)
    ENDDO
  ENDDO
ENDDO
    IEZDIAG_CHEM=NGFL_EZDIAG-IOFF_MFSHAL+1
    CALL ARO_MNHC(ZZI_SVS(KIDIA:KFDIA,1:1,1:KLEV+2,1:NGFL_EXT),       &
             & ZZI_RHODREFM(KIDIA:KFDIA,1:1,1:KLEV+2),                &
             & PDT,ZZI_THM(KIDIA:KFDIA,1:1,1:KLEV+2),                 &
             & ZZI_PABSM(KIDIA:KFDIA,1:1,1:KLEV+2),                   &
             & ZZI_RM(KIDIA:KFDIA,1:1,1:KLEV+2,1:NRR),                &
             & ZLAT(KIDIA:KFDIA,1:1), ZLON(KIDIA:KFDIA,1:1),          &
             & ZALB_UV(KIDIA:KFDIA,1:1), ZZS(KIDIA:KFDIA,1:1),        &
             & ZZENITH(KIDIA:KFDIA,1:1),ZZZ(KIDIA:KFDIA,1:1,1:KLEV+2),&
             & IYEAR,IMONTH,IDAY, REAL(RHGMT,JPRB)+PDT/2.,            &
             & ILONMNH,KLEV,NGFL_EXT, NRR, KSTEP+1,NULOUT,IEZDIAG_CHEM,&
             & ZZI_PEZDIAG(KIDIA:KFDIA,:,IOFF_MFSHAL:NGFL_EZDIAG)           )
 
    PEZDIAG(KIDIA:KFDIA,:,IOFF_MFSHAL:NGFL_EZDIAG)=&
                       &ZZI_PEZDIAG(KIDIA:KFDIA,:,IOFF_MFSHAL:NGFL_EZDIAG)


!inversion niveau de la tendance des scalaires passifs

  DO JGFL=1,NGFL_EXT
    DO JLEV = 1 ,KLEV
      DO JLON = KIDIA,KFDIA
        PTENDEXT(JLON,JLEV,JGFL)=PTENDEXT(JLON,JLEV,JGFL)+&
        &(ZZI_SVS(JLON,1,KLEV+2-JLEV,JGFL)- &
        & ZZI_SVSAVE(JLON,1,KLEV+2-JLEV,JGFL))
      ENDDO
    ENDDO
  ENDDO

ENDIF


!    ------------------------------------------------------------------
!     13 - FINAL CALCULATIONS.
!     --------------------------------------------------------------------



!forcage pour declancher la ligne de grain 
IF (LSQUALL) THEN
  IF (LTWOTL) THEN
    ZDT2=2*ZDT
  ELSE
    ZDT2=ZDT
  ENDIF
  IF((KSTEP+1)*ZDT2 < 600.) THEN
    WRITE(NULOUT, *)'refroidissement impose de',NREFROI1,' a ',NREFROI2
    DO JLON=NREFROI1,NREFROI2
      DO JLEV=KLEV,KLEV-20,-1
        PTENDT(JLON,JLEV)=-0.01_JPRB
      ENDDO
    ENDDO
  ENDIF
ENDIF

!ecriture du buffer
IF(LMSE) THEN
  DO JLON = KIDIA,KFDIA
    PGPAR(JLON,MINPRR)=ZINPRR(JLON,1)
    PGPAR(JLON,MINPRS)=ZINPRS(JLON,1)
    PGPAR(JLON,MINPRG)=ZINPRG(JLON,1)+ZINPRH(JLON,1)
    PGPAR(JLON,MACPRR)=PGPAR(JLON,MACPRR)+ZINPRR(JLON,1)*PDT
    PGPAR(JLON,MACPRS)=PGPAR(JLON,MACPRS)+ZINPRS(JLON,1)*PDT
    PGPAR(JLON,MACPRG)=PGPAR(JLON,MACPRG)+(ZINPRG(JLON,1)+ZINPRH(JLON,1))*PDT
    PGPAR(JLON,MVTS)=ZTSURF(JLON)
    PGPAR(JLON,MVEMIS)=ZEMIS(JLON)
    PGPAR(JLON,MVQS)=ZQS(JLON)
  ENDDO
  DO JSG=1,NSW
    DO JLON = KIDIA,KFDIA
      PGPAR(JLON,MALBDIR-1+JSG)=ZALBP(JLON,JSG)
      PGPAR(JLON,MALBSCA-1+JSG)=ZALBD(JLON,JSG)
    ENDDO
  ENDDO
ENDIF

! initialisations for CFU and XFU
!     ------------------------------------------------------------------
!     NEBULOSITE (CONVECTIVE+STRATIFORME) A TROIS NIVEAUX.
!     DIAGNOSTIC OF THREE LEVELS (CONVECTIVE+STRATIFORM) CLOUDINESS.

DO JLON=KIDIA,KFDIA
  PCLCH(JLON)=1.0_JPRB
  PCLCL(JLON)=1.0_JPRB
  PCLCM(JLON)=1.0_JPRB
ENDDO

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

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

    IF (LRNUMX.AND.JLEV > KTDIA) THEN
      ZB1=(1.0_JPRB-MAX(PCLFS(JLON,JLEV),PCLFS(JLON,JLEV-1)))/(1.0_JPRB &
       & -PCLFS(JLON,JLEV-1))  
    ELSE
      ZB1=1.0_JPRB-PCLFS(JLON,JLEV)
    ENDIF
    PCLCH(JLON)=PCLCH(JLON)*ZB1
  ENDDO
ENDDO
DO JLEV=NTSHM+1,NTSML
  DO JLON=KIDIA,KFDIA

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

    IF (LRNUMX.AND.JLEV > NTSHM+1) THEN
      ZB1=(1.0_JPRB-MAX(PCLFS(JLON,JLEV),PCLFS(JLON,JLEV-1)))/(1.0_JPRB &
       & -PCLFS(JLON,JLEV-1))  
    ELSE
      ZB1=1.0_JPRB-PCLFS(JLON,JLEV)
    ENDIF
    PCLCM(JLON)=PCLCM(JLON)*ZB1
  ENDDO
ENDDO
DO JLEV=NTSML+1,KLEV
  DO JLON=KIDIA,KFDIA

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

    IF (LRNUMX.AND.JLEV > NTSML+1) THEN
      ZB1=(1.0_JPRB-MAX(PCLFS(JLON,JLEV),PCLFS(JLON,JLEV-1)))/(1.0_JPRB &
       & -PCLFS(JLON,JLEV-1))  
    ELSE
      ZB1=1.0_JPRB-PCLFS(JLON,JLEV)
    ENDIF
    PCLCL(JLON)=PCLCL(JLON)*ZB1
  ENDDO
ENDDO

!     ------------------------------------------------------------------
!     ON VEUT EN SORTIE LA NEBULOSITE ET NON SON COMPLEMENT A UN.
!     ONE NEEDS AS OUTPUT CLOUDINESS AND NOT ITS COMPLEMENT TO ONE.

DO JLON=KIDIA,KFDIA
  PCLCH(JLON)=1.0_JPRB-PCLCH(JLON)
  PCLCM(JLON)=1.0_JPRB-PCLCM(JLON)
  PCLCL(JLON)=1.0_JPRB-PCLCL(JLON)
ENDDO

DO JLON=KIDIA,KFDIA
  PCLCT(JLON)=1.0_JPRB
ENDDO
DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA

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

    IF (LRNUMX.AND.JLEV > KTDIA) THEN
      ZB1=(1.0_JPRB-MAX(PCLFS(JLON,JLEV),PCLFS(JLON,JLEV-1)))/(1.0_JPRB &
       & -PCLFS(JLON,JLEV-1))  
    ELSE
      ZB1=1.0_JPRB-PCLFS(JLON,JLEV)
    ENDIF
    PCLCT(JLON)=PCLCT(JLON)*ZB1
  ENDDO
ENDDO
DO JLON=KIDIA,KFDIA
  PCLCT(JLON)=1.0_JPRB-PCLCT(JLON)
ENDDO


! initialisations for CFU for Rainfalls
DO JLEV = 0,KLEV
  DO JLON = KIDIA,KFDIA
    ! conversion from m/s in mm/s
    PFPLSL(JLON,JLEV)= ZINPRR(JLON,1)*1000._JPRB
    PFPLSN(JLON,JLEV)= ZINPRS(JLON,1)*1000._JPRB
    PFPLSG(JLON,JLEV)= ZINPRG(JLON,1)*1000._JPRB
    PFPLSH(JLON,JLEV)= ZINPRH(JLON,1)*1000._JPRB
    PSTRTU(JLON,JLEV)= ZSFU(JLON,1) 
    PSTRTV(JLON,JLEV)= ZSFV(JLON,1) 
  ENDDO
ENDDO

!!! modif pour LMSE non activee
IF (LMSE) THEN
DO JLEV=1,KSGST+1
  DO JLON = KIDIA,KFDIA
    PFCS(JLON,JLEV)=-ZSFTH(JLON,1)*ZZI_RHODREFM(JLON,1,ILEVFX)*RCPD
    PFCLL(JLON,JLEV)=-ZSFRV(JLON,1)*ZZI_RHODREFM(JLON,1,ILEVFX)*ZLH(JLON,KLEV)
  ENDDO
ENDDO
ENDIF  

! case  CTURBLEN =/ KEPS (anyway, option KEPS does not work well in MNH)
DEALLOCATE(ZEPSM )
DEALLOCATE(ZEPSS )

!  deallocations of variables used in more than one parameterization
DEALLOCATE(ZSFU  )         ! surface schemes + turbulence
DEALLOCATE(ZSFV  )
DEALLOCATE(ZSFTH )
DEALLOCATE(ZSFRV )

DEALLOCATE(ZSFSV )
DEALLOCATE(ZSFCO2)

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