SUBROUTINE MF_PHYS &
 !---------------------------------------------------------------------
 ! - INPUT .
 & (CDCONF,KBL,KGPCOMP,KST,KEND,KGL1,KGL2,KGL3,KGL4,KOFF,KSTGLO, &
 & LDRETCFOU,LDWRTCFOU0,LDLADNMI,LDLADVI,LDLADVL,LDLADVS, &
 & LDLADVR,LDLADVG,LDLADVH,LDLADVTKE,LDLADVEXT, &
 & PDTPHY, &
 & PGAW, &
 & PGECLO,PGESLO,PGELAM,PGEMU,PGM,POROG,PRCORI, &
 & PUT0,PVT0,PWT0,PTT0,PQT0,PQT0L,PQT0M,PLT0,PIT0,PO3T0,&
 & PST0,PRT0,PGT0,PHT0,PTKET0,PCLF0,PSRC0,PSDSAT0,PCVVT0,PQVAT0,PEXTT0,PDIVT0, &
 & PVORT0,PCP0,PR0,PDELP0,PRDELP0,PHI0,PHIF0, &
 & PRE0,PRE0F,PREPHY0,PREPHY0F,PALPH0,PLNPR0, &
 & PVCASRS0H, &
 & PDDAL  , PDDOM  ,PENTCH , PUDAL  , PUDOM  ,PUNEBH, &
 & PUT9,PVT9,PWT9,PTT9,PQT9,PLT9,PIT9,PST9,PRT9,PGT9,PHT9,PTKET9,PSRC9, &
 & PSDSAT9,PCVVT9,PO3T9, &
 & PEXTT9, PSPT9, &
 & PCP9,PR9,PDELP9,PRDELP9,PHI9,PHIF9, &
 & PRE9,PRE9F,PREPHY9,PREPHY9F,PALPH9,PLNPR9, &
 & PKOZO,PFPLCH,PFPLSH,PCVGQSL,PQSLT0L,PQSLT0M,&
 !---------------------------------------------------------------------
 ! - Input arrays required for SCM extraction (writephysio)
 & POROGL,POROGM,PRATATH,PRATATX,  &
 & PSPT0,PSPT0L,PSPT0M,            &
 & PTT0L,PTT0M,                    &
 & PVORT9, &
 ! - INPUT/OUTPUT .
 & PEVEL0,PVVEL0,PSDFI0,PSDVBC0, &
 & PB1,PGMVT1,PGMVT1S,PGFLT1,&
 & PSP_SB,PSP_SG,PSP_RR,&
 & PSD_VF,PSD_VP,PSD_VV,PSD_VH,PSD_VA,PSD_VC,&
 & PEMTD, PEMTU, PTRSW,PRMOON,&
 & PGPAR,PCLF1,PSRC1, &
 !---------------------------------------------------------------------
 ! - OUTPUT .
 & PDHSF, &
 & PALB,PCAPE,PCLCC,PCLCH,PCLCL,PCLCM,PCLCT,PCLPH,PCT, &
 & PDIFCQ,PDIFCQI,PDIFCQL,PDIFCS,PDIFTQ,PDIFTQI,PDIFTQL,PDIFTS, &
 & PFCCQL,PFCCQN,PFCHOZ,PFCHSP,PFCLL,PFCLN,PFCQING,PFCQLNG,PFCQNG,PFCS, &
 & PFCSQL,PFCSQN,PFEVL,PFEVN,PFEVV,PFGEL,PFGELS,PFLWSP,PFONTE, &
 & PFPLCL,PFPLCN,PFPLCG,PFPLCHL,PFPLSL,PFPLSN,PFPLSG,PFPLSHL,&
 & PFRMH,PFRSO,PFRSOC,PFRSODS,PFRSOLU, &
 & PFRSOPS,PFRSOPT,PFRTH,PFRTHC,PFRTHDS,PFTR,PGZ0,PGZ0H,PNEB, &
 & PQCLS,PQICE,PQLI,PQS, &
 & PRH,PRHCLS,PRUISL,PRUISP,PRUISS, &
 & PSTRCU,PSTRCV,PSTRDU,PSTRDV,PSTRMU,PSTRMV,PSTRTU,PSTRTV, &
 & PUCLS,PVCLS,PTCLS,PUGST,PVGST, &
 & PMOCON,PFDIS, &
 & PFHPCL,PFHPCN,PFHPSL,PFHPSN,PFHSCL,PFHSCN,PFHSSL,PFHSSN, &
 & PFEPFP, PFCMPCQ, PFCMPSN, PFCMPSL,&
 & PTENDU,PTENDV, &
 & PQSOL, &
 & PFPFPSL,PFPFPSN,PFPFPCL,PFPFPCN,PFPEVPSL,PFPEVPSN, &
 & PFPEVPCL,PFPEVPCN,PDERNSHF,&
 & PFCQRNG, PFCQSNG,&
 & PEZDIAG)

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

USE YOMDIM   , ONLY : NFLSA    ,NFLEN    ,NFLEVG   ,NFLSUL   ,NPROMA   ,&
 & NPROMM   ,NPROMVC
USE YOMCT0   , ONLY : LSLAG    ,LTWOTL   ,LVERCOR  ,NSTOP    ,LNHDYN  
USE YOMCT3   , ONLY : NSTEP
USE YOMCVER  , ONLY : LVERTFE  ,LVFE_GWMPA
USE YOMDYNA  , ONLY : LGWADV   ,LNH_PDVD ,LNH_GEOGW
USE YOMSC2   , ONLY : NFLDSLB1
USE YOMNUD   , ONLY : NFNUDG   ,LNUDG    ,LNDRIV
USE YOMSNU   , ONLY : XPNUDG
USE YOMIOP   , ONLY : NG3D95   ,NG2D95   ,NG2DS5
USE YOEPHY   , ONLY : LEPHYS   ,LAGPHY
USE YOMPHY   , ONLY : NDPSFI   ,LMPHYS   ,LOZONE   ,LRRGUST  ,&
 & LNEBN     ,LNEBR   ,LCVPRO  ,LCDDPRO  ,LCVPGY   ,&
 & LSTRAPRO  , L3MT, LPHSPSH ,LSOLV    ,CGMIXLEN
USE YOMPHY2  , ONLY : TSPHY
USE YOMSIMPHL, ONLY : LSIMPH   ,LTRAJPS  ,LRAYSP
USE YOMRCOEF , ONLY : LRCOEF   ,LTLADDIA ,NG3SR    ,NGMTR
USE YOMDPHY  , ONLY : NVCLIS   ,NTSSG 
USE SURFACE_FIELDS_MIX  , ONLY :  &
 & YSP_SBD, YSP_SB, YSP_SGD, YSP_SG, &
 & YSP_RRD, YSP_RR,           &
 & YSD_VFD, YSD_VF, YSD_VPD, YSD_VP, YSD_VVD, YSD_VV, YSD_VHD, YSD_VH,&
 & YSD_VAD, YSD_VA, YSD_VCD, YSD_VC
 
USE YOMLDDH  , ONLY : LSDDH
USE YOM_YGFL , ONLY : YGFL     , YQ      , YL      , YI      ,&
 & YS        ,YR      ,YG      ,YTKE     , YO3     ,YCPF     ,&
 & YSPF      ,YEXT    ,NGFL_EXT, YCVV    ,NGFL_EZDIAG ,&
 & YQVA      ,YA      ,YH      , &
 & YDAL      ,YDOM    , YUAL   , YUOM    ,YUNEBH   ,YUEN
USE YOMFFTTC , ONLY : RBASCOTC ,RBASSITC
USE YOMFOUTC , ONLY : RFORAB3C ,RFORAB4C ,RFORAB6C ,RFORAB3N ,&
 & RFORAB4N ,RFORAB6N ,RFORAT1C ,RFORAT2C ,RFORAT3C ,&
 & RFORAT4C ,RFORAT5C ,RFORAT1N ,RFORAT2N ,RFORAT3N ,&
 & RFORAT4N ,RFORAT5N ,RFOCOR   ,RFOAC  
USE PTRSLB1  , ONLY : MSLB1U9  ,MSLB1V9  ,MSLB1T9  ,MSLB1GFL9  ,&
 & MSLB1SP9  , MSLB1VD9
USE YOMGMV   , ONLY : YT1
USE YOMSCM   , ONLY : LGSCM
USE YOMARPHY , ONLY : LMPA, LMSE
USE YOMARAR  , ONLY : NRR, NGPAR
USE YOMCST   , ONLY : RG
USE YOMCHET  , ONLY : GCHETN
USE YHLOPTION, ONLY : LHL

!**** *MF_PHYS* METEO-FRANCE PHYSICS.

!     Purpose.
!     --------
!         Call METEO-FRANCE physics and physical tendencies.

!**   Interface.
!     ----------
!        *CALL* *MF_PHYS(...)*

!        Explicit arguments :
!        --------------------

!     INPUT:
!     ------
!        CDCONF    : configuration of work
!        KBL       : NPROMA-packets number
!        KGPCOMP   : total number of grid points in the domain
!        KST       : first element of work.
!        KEND      : last element of work.
!        KGL1,KGL2 : first and last latitude of computations.
!                    - bounds NGPTOT-packets for DM calculations.
!        KGL3,KGL4 : DM-local first and last latitude of computations
!                    - bounds NPROMA-packets for calculations.
!        KOFF      : index offset between NPROMM-arrays and NGPTOT-arrays.
!        KSTGLO    : global offset.
!        LDRETCFOU : .T. -> CPPFTTCINV is called.
!        LDWRTCFOU0: .T. -> CPPFTTCDIR is called.
!        LDLADNMI  : .T. if adiabatic NNMI iteration.
!        LDLADVL   : .T. if advection of cloud liquid water.
!        LDLADVI   : .T. if advection of cloud ice.
!        LDLADVR   : .T. if advection of precipating water.
!        LDLADVS   : .T. if advection of precipating snow.
!        LDLADVG   : .T. if advection of precipating graupel.
!        LDLADVH   : .T. if advection of precipating hail.
!        LDLADVTKE : .T. if advection of tke.
!        LDLADVEXT : .T. if advection of gflext.
!        PDTPHY    : timestep used in the physics.
!        PGAW      : Gauss weights of grid points.
!        PGECLO    : cosine of geographical longitude.
!        PGESLO    : sine of geographical longitude.
!        PGELAM    : geographical longitude.
!        PGEMU     : sine of geographical latitude.
!        PGM       : mapping factor.
!        POROG     : surface orography.
!        PRCORI    : Coriolis parameter "f = 2 Omega sin(theta)".
!        PUT0      : zonal wind time t.
!        PVT0      : meridian wind time t.
!        PWT0      : vertical wind time t.
!        PTT0      : temperature at time t.
!        PQT0      : humidity at time t.
!        PQT0L     : zonal derivative of humidity at time t.
!        PQT0M     : meridian derivative of humidity at time t.
!        PQSLT0L   : zonal derivative of spectral humidity at time t.
!        PQSLT0M   : meridian derivative of spectral humidity at time t.
!        PLT0      : liquid water at time t.
!        PIT0      : ice at time t.
!        PST0      : snow at time t.
!        PGT0      : graupel at time t.
!        PHT0      : hail at time t.
!        PRT0      : rain at time t.
!        PTKET0    : TKE at time t.
!        PCLF0     : cloud fraction at time t.
!        PQVAT0    : amplitude of total humidity variation.
!        PSRC0     : turb. flux. for AROME microphys. at time t.
!        PO3T0     : ozone at time t.
!        PSDSAT0   : SDSAT at time t.
!        PCVVT0    : CVV at time t.
!        PEXTT0    : extra GFL at time t.
!        PDIVT0    : horizontal divergence at time t.
!        PVORT0    : horizontal vorticity at time t.
!        PCP0      : "cp" at time t.
!        PR0       : "R" at time t.
!        PDELP0    : pressure depth "delta prehyd" of layers at time t.
!        PRDELP0   : inverse of "delta prehyd" of layers at time t.
!        PHI0      : geopotential height on interlayers at time t.
!        PHIF0     : geopotential height on layers at time t.
!        PRE0      : hydrostatic pressure "prehyd" on interlayers at time t.
!        PRE0F     : hydrostatic pressure "prehyd" on layers at time t.
!        PREPHY0   : input pressure "pre" for AROME on interlayers at time t.
!        PREPHY0F  : input pressure "pre" for AROME on layers at time t.
!        PALPH0    : "alpha" on layers at time t.
!        PLNPR0    : "delta" on layers at time t.
!        PVCASRS0H : "a/rs" on interlayers at time t.
!        PDDAL     : downdraught mesh fraction
!        PDDOM     : downdraught vertical velocity
!        PUDAL     : updraught mesh fraction
!        PUDOM     : updraught vertical velocity
!        PUNEBH    : Pseudo-historical convective cloudiness
!        PENTCH    : prognostic/ pseudo historic  entrainment
!        PUT9      : zonal wind time t-dt.
!        PVT9      : meridian wind time t-dt.
!        PWT9      : Vertical wind time t-dt.
!        PTT9      : temperature at time t-dt.
!        PQT9      : humidity at time t-dt.
!        PLT9      : liquid water at time t-dt.
!        PIT9      : ice at time t-dt.
!        PST9      : snow at time t-dt.
!        PRT9      : rain at time t-dt.
!        PGT9      : graupel at time t-dt.
!        PHT9      : hail at time t-dt.
!        PTKET9    : turb. kin. energy at time t-dt.
!        PSRC9     : turb. flux. for AROME microphys. at time t-dt.
!        PO3T9     : ozone at time t-dt.
!        PSDSAT9   : SDSAT at time t-dt.
!        PCVVT9    : CVV at time t-dt.
!        PEXTT9    : extra GFL at time t-dt
!        PSPT9     : surface pressure variable at time t-dt.
!        PCP9      : "cp" at time t-dt.
!        PR9       : "R" at time t-dt.
!        PDELP9    : pressure depth "delta prehyd" of layers at time t-dt.
!        PRDELP9   : inverse of "delta prehyd" of layers at time t-dt.
!        PHI9      : geopotential height on interlayers at time t-dt.
!        PHIF9     : geopotential height on layers at time t-dt.
!        PRE9      : hydrostatic pressure "prehyd" on interlayers at time t-dt.
!        PRE9F     : hydrostatic pressure "prehyd" on layers at time t-dt.
!        PREPHY9   : input pressure "pre" for AROME on interlayers at time t-dt.
!        PREPHY9F  : input pressure "pre" for AROME on layers at time t-dt.
!        PALPH9    : "alpha" on layers at time t-dt.
!        PLNPR9    : "delta" on layers at time t-dt.
!        PKOZO     : fields for photochemistery of ozon.
!        PFPLCH    : convective precipitation flux
!        PFPLSH    : stratiform precipitation flux
!        PCVGQSL   : TSPHY time SL Moisture Convergence
!        POROGL,POROGM: components of grad(orography).
!        PRATATH,PRATATX: curvature terms.
!        PSPT0     : hydrostatic pressure variable at t
!        PSPT0L,PSPT0M: components of grad(hyd pressure variable) at t
!        PTT0L,PTT0M: components of grad(T) at time t.
!        PVORT9    : vorticity at time t-dt

!     INPUT/OUTPUT:
!     -------------
!        PEVEL0    : "etadot d prehyd / d eta" at time t.
!                    On interlayers (resp. layers) if LVERTFE=.F. (resp. .T.).
!        PVVEL0    : "omega/prehyd" on layers at time t.
!        PSDFI0    : vertical integral of divergence with
!                    "lrubc" and with "delta m=1" contributions
!                    for "etadot d prehyd / d eta", and with the
!                    physics of "delta m=1".
!        PSDVBC0   : vertical integral of divergence with
!                    "lrubc" and with "delta m=1" contributions
!                    for "etadot d prehyd / d eta", but without the
!                    physics of "delta m=1".
!        PB1       : "SLB1"-buffer, used for interpolations in the SL scheme.
!        PGFLT1    : GFL t+dt
!        PGPAR     : surface fields for AROME.

!     OUTPUT:
!     -------
!        PDHSF     : distribution of horizontal mean weights used for
!                    simplified radiation scheme.
!        ---------------------- output of aplpar ------------------------------
!        PALB      : modele surface shortwave albedo (diagnostic).
!        PCAPE     : CAPE.
!        PCLCC     : convective cloud cover (diagnostic).
!        PCLCH     : high cloud cover (diagnostic).
!        PCLCL     : low cloud cover (diagnostic).
!        PCLCM     : medium cloud cover (diagnostic).
!        PCLCT     : total cloud cover (diagnostic).
!        PCLPH     : height (in meters) of the PBL.
!        PCT       : thermical coefficient of soil-vegetation middle.
!        PDIFCQ    : convective flux of specific humidity (not rain/snow).
!        PDIFCQI   : convective flux of solid water (not rain/snow).
!        PDIFCQL   : convective flux of liquid water (not rain/snow).
!        PDIFCS    : convective flux of enthalpy (not rain/snow).
!        PDIFTQ    : turbulent flux (inc. "q" negative) of specific humidity.
!        PDIFTQI   : turbulent flux (inc. "q" negative) of solid water.
!        PDIFTQL   : turbulent flux (inc. "q" negative) of liquid water.
!        PDIFTS    : turbulent flux of enthalpy (or dry static energy).
!        PFCCQL    : convective condensation flux for liquid water.
!        PFCCQN    : convective condensation flux for ice.
!        PFCHOZ    : ozon photo-chemical flux.
!        PFPFPSL   : flux of liquid resol. precipitation: the generation term. 
!        PFPFPSN   : flux of solid resolved precipitation: the generation term. 
!        PFPFPCL   : flux of liquid conv. precipitation: the generation term. 
!        PFPFPCN   : flux of solid conv. precipitation: the generation term. 
!        PFPEVPSL  : resolved precipitation flux due to evaporation.
!        PFPEVPSN  : resolved precipitation flux due to sublimation.
!        PFPEVPCL  : convective precipitation flux due to evaporation.
!        PFPEVPCN  : convective precipitation flux due to sublimation.
!        PFCHSP    : heat flux from surface to deep soil.
!        PFCLL     : latent heat flux over liquid water (or wet soil).
!        PFCLN     : latent heat flux over snow (or ice).
!        PFCQING   : pseudo-flux of ice to correct for "qi"<0.
!        PFCQLNG   : pseudo-flux of liquid water to correct for "ql"<0.
!        PFCQNG    : pseudo-flux of water to correct for Q<0.
!        PFCS      : sensible heat flux at surface level.
!        PFCSQL    : stratiform condensation flux for liquid water.
!        PFCSQN    : stratiform condensation flux for ice.
!        PFEVL     : water vapour flux over liquid water (or wet soil).
!        PFEVN     : water vapour flux over snow (or ice) and frozen soil.
!        PFEVV     : evapotranspiration flux.
!        PFGEL     : freezing flux of soil water.
!        PFGELS    : freezing flux of soil water at surface level.
!        PFLWSP    : water flux from surface to deep soil.
!        PFONTE    : water flux corresponding to surface snow melt.
!        PFPLCL    : convective precipitation as rain.
!        PFPLCN    : convective precipitation as snow.
!        PFPLCG    : convective precipitation as graupel.
!        PFPLCHL   : convective precipitation as hail.
!        PFPLSL    : stratiform precipitation as rain.
!        PFPLSN    : stratiform precipitation as snow.
!        PFPLSG    : stratiform precipitation as graupel.
!        PFPLSHL   : stratiform precipitation as hail.
!        PFRMH     : mesospheric enthalpy flux.
!        PFRSO     : shortwave radiative flux.
!        PFRSOC    : shortwave clear sky radiative flux.
!        PFRSODS   : surface downwards solar flux.
!        PFRSOLU   : downward lunar flux at surface.
!        PFRSOPS   : surface parallel solar flux.
!        PFRSOPT   : top parallel solar flux.
!        PFRTH     : longwave radiative flux.
!        PFRTHC    : longwave clear sky radiative flux.
!        PFRTHDS   : surface downwards IR flux.
!        PFTR      : transpiration flux.
!        PGZ0      : g*roughness length (current).
!        PGZ0H     : current g*thermal roughness length (if KVCLIV >=8).
!        PNEB      : fractional cloudiness for radiation.
!        PQCLS     : specific humidity at 2 meters (diagnostic).
!        PQICE     : specific humidity of solid water for radiation.
!        PQLI      : specific humidity of liquid water for radiation.
!        PQS       : specific humidity at surface level.
!        PRH       : relative humidity.
!        PRHCLS    : relative humidity at 2 meters (diagnostic).
!        PRUISL    : run-off flux out the interception water-tank.
!        PRUISP    : run-off flux in soil.
!        PRUISS    : run-off flux at surface level.
!        PSTRCU    : convective flux of momentum "U".
!        PSTRCV    : convective flux of momentum "V".
!        PSTRDU    : gravity wave drag flux "U".
!        PSTRDV    : gravity wave drag flux "V".
!        PSTRMU    : mesospheric flux for "U"-momentum.
!        PSTRMV    : mesospheric flux for "V"-momentum.
!        PSTRTU    : turbulent flux of momentum "U".
!        PSTRTV    : turbulent flux of momentum "V".
!        PUCLS     : U-component of wind at 10 meters (diagnostic).
!        PVCLS     : V-component of wind at 10 meters (diagnostic).
!        PTCLS     : temperature at 2 meters (diagnostic).
!        PUGST     : U-component of gusts (diagnostic).
!        PVGST     : V-component of gusts (diagnostic).
!        PDERNSHF  : derivative of the non solar surface with respect to Tsurf
!        ---------------------- end of output of aplpar -----------------------
!        PMOCON    : moisture convergence.
!        PFDIS     : enthalpy flux due to dissipation of kinetic energy. 
!        PFHPCL    : liquid water convective condensation enthalpy flux.
!        PFHPCN    : snow convective condensation enthalpy flux.
!        PFHPSL    : liquid water stratiform condensation enthalpy flux.
!        PFHPSN    : snow stratiform condensation enthalpy flux.
!        PFHSCL    : sensible heat flux due to liquid convective precipitations
!        PFHSCN    : sensible heat flux due to snow convective precipitations.
!        PFHSSL    : sensible heat flux due to liquid stratiform precipitations
!        PFHSSN    : sensible heat flux due to snow stratiform precipitations.
!        PTENDU    : "U"-wind tendency due to physics.
!        PTENDV    : "V"-wind tendency due to physics.
!        PQSOL     : surface specific humidity used in case "delta m=1".
!        PFCQRNG   : pseudo-flux of rain to correct for Q<0
!        PFCQSNG   : pseudo-flux of snow to correct for Q<0

!        Implicit arguments :
!        --------------------

!     Method.
!     -------

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

!     Reference.
!     ----------

!     Author.
!     -------
!        2000-12-04: F. Bouyssel & J.M. Piriou

!     Modifications.
!     --------------
!      Modified :
!       K. YESSAD and F. BOUYSSEL (FEB 2001): debug code for SL2TL.
!       01-03, mesospheric drag - F. Bouyssel
!       K. YESSAD and F. BOUYSSEL (AUG 2001): strong cleaning.
!       K. YESSAD and F. BOUYSSEL (FEB 2001): debug code for SL2TL.
!       01-03, mesospheric drag - F. Bouyssel
!       01-09-24 R. El Khatib : vectorization-doctorization
!       02-06-25 F. Bouyssel : new pseudo-historical variables (RRCV,RRST,CVPP)
!       02-03-29 Y.Bouteloup : Climatological ozone profiles
!       02-04-22 C. Fischer : remove call to wrnhtrajm
!       02-09-03 E. Bazile : new fields for APLPAR (MVVALS, MVVALV)
!       K. YESSAD (10-2002): option lwrtcfou=T: allow to store a temporal
!        average of transmission coefficients.
!       2003-04-20 M. Bellus: calling aplparint instead of aplpar (interface
!                      for PNEBH splitting), changed arguments in aplpar
!                      (aplparint) callings - removed 14 arguments
!       2003-10-03 M. Tudor: MVNNEBH split into 2D arrays MVXCCH and MVPBLH
!       2003-10-06 Y. Bouteloup : Extraction of SCM profile
!       M.Hamrud      01-Oct-2003 CY28 Cleaning
!       K. YESSAD (Jan 2004): physics interpolated at O in the TL and AD code.
!       K. YESSAD (Jan 2004): make the code valid for any value of NFLSA.
!       2003-10-17 M. Tudor: CPF and SPF in GFL, ZFPLXH, PFPLXH
!       2003-12-10 F. Vinit : new fields in output
!        (from APLPAR: PALB,PGZ0,PGZ0H).
!       2004-03-05 Y.Bouteloup : Snow, Rain and TKE 
!       2004-03-26 Y.Bouteloup : introduction of MTS radiance
!       2004-03-01 T. Kovacic : diagnostics on physical tendencies
!       2004-09-15 F.Bouyssel : introduction of INITAPLPAR
!       2004-07-01 K. Yessad: cleaning (WRITEPHYSIO and tests for PC scheme).
!       2004-07-06 K. Yessad: use GFL ozone instead of obsolete pas. scalar one
!       2004-11-18 Y.Seity : AROME new arguments and calls
!       2004-12-20 K. Yessad : Rewrite part 4 (AROME) and add case LGWADV=T.
!       2005-04-21 K. Yessad and Y.Seity: reformulation of "delta m=1".
!       2005-09-21 Y.Seity: add LDLADVEXT and PEXTT9 and PEXTT0 for AROME use
!       2005-10-20 Y. Bouteloup: add facilies for CVGQ
!       2005-10-26 A. Alias : GMGEC/EAC modifs
!            M. Deque : grid point nudging
!            Humidity Mesopheric flux (ZFRMQ) added
!            JF. Royer : Derivative of non solar surface fluxes 'PDERNSHF' added
!       2005-12-22 A. Alias : add sulfate and volcano aerosols
!       2006-03-23 T. Kovacic: new arguments in APL_AROME; PFRTH AND PFRSO
!       2006-02-15 R. Zaaboul: add arguments KBL and KGPCOMP for ARO_GROUND_PARAM
!       2006-03-20 A. Alias : add SDSAT and CVV fields (JF Gueremy)
!       2006-04-15 E. Bazile : TKE flux in CPTEND.
!       2006-06-01 B.H. Sass : Call to HIRLAM physics and modified call of CPCHET
!       2006-06-15 K. Yessad : Bug correction + some indentation cleanings
!     ---------------------------------------------------------------------------
!        M.Hamrud      01-Jul-2006 Revised surface fields
!       2006-10-02 M. Bellus : ALARO-0 phasing (prognostic convection, p-TKE)
!       2006-10-26 E. Bazile : Corrections of the surface fields for APLPAR.
!       2006-10-25 A. Alias  : Call to APLPAR and CPNUDG modified following
!                              introduction of surface fields 
!       2007-05-07 Y. Seity  : Add graupel and hail precipitation fluxes
!       2007-04-17 S.Ivatek-S: Over dimensioning of PGPAR to NGPAR+1, boundary
!                              checking problem if NGPAR=0
!       2007-03-12-07 A.Alias : grid point nudging in stretched mode (M.Deque)
!       2007-04-03 A.Alias : Ts nudging with land-sea mask (M.Deque)
!       2007-05-07 F. Bouyssel : Change in CPTEND and CPTEND_NEW calling, 
!                                Add PFCLL, PFCLN in some diagnostics
!       2007-05-31 T.Kovacic: New arguments PFCQRNG, PFCQSNG (former ZFCQRNG, 
!                              ZFCQSNG) and  PFEPFP, PFCMPCQ, PFCMPSN, PFCMPSL
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!       2007-12-18 Y.Seity : Add Hail for AROME (YH)  
!    4-Mar-2008 Y. Seity : Cleaning IR and WV similated sat pictures
!                            (replaced by Fullpos Calculations)
!   22-Oct-2008 R. Brozkova: Protection of arrays PUNEBH, PENTCH
!   K. Yessad (Dec 2008): remove dummy CDLOCK + cleanings
!     -------------------------------------------------------------------------

IMPLICIT NONE

CHARACTER(LEN=1)  ,INTENT(IN)    :: CDCONF
INTEGER(KIND=JPIM),INTENT(IN)    :: KBL 
INTEGER(KIND=JPIM),INTENT(IN)    :: KGPCOMP 
INTEGER(KIND=JPIM),INTENT(IN)    :: KST 
INTEGER(KIND=JPIM),INTENT(IN)    :: KEND 
INTEGER(KIND=JPIM),INTENT(IN)    :: KGL1 
INTEGER(KIND=JPIM),INTENT(IN)    :: KGL2 
INTEGER(KIND=JPIM),INTENT(IN)    :: KGL3 
INTEGER(KIND=JPIM),INTENT(IN)    :: KGL4 
INTEGER(KIND=JPIM),INTENT(IN)    :: KOFF 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTGLO 
LOGICAL           ,INTENT(IN)    :: LDRETCFOU 
LOGICAL           ,INTENT(IN)    :: LDWRTCFOU0 
LOGICAL           ,INTENT(IN)    :: LDLADNMI 
LOGICAL           ,INTENT(IN)    :: LDLADVI 
LOGICAL           ,INTENT(IN)    :: LDLADVL 
LOGICAL           ,INTENT(IN)    :: LDLADVS 
LOGICAL           ,INTENT(IN)    :: LDLADVR 
LOGICAL           ,INTENT(IN)    :: LDLADVG 
LOGICAL           ,INTENT(IN)    :: LDLADVH 
LOGICAL           ,INTENT(IN)    :: LDLADVTKE 
LOGICAL           ,INTENT(IN)    :: LDLADVEXT 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDTPHY 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGECLO(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGESLO(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGELAM(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEMU(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGAW(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGM(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROG(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRCORI(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCVGQSL(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PWT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQT0L(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQT0M(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQSLT0L(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQSLT0M(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PIT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PST0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PRT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PHT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTKET0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLF0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQVAT0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSRC0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSDSAT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCVVT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PO3T0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEXTT0(NPROMA,NFLEVG,NGFL_EXT)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDIVT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVORT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCP0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PR0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDELP0(NPROMA,0:NFLEVG+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDELP0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PHI0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PHIF0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRE0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRE0F(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PREPHY0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PREPHY0F(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALPH0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPR0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCASRS0H(NPROMVC,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDDAL(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDDOM(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PENTCH(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUDAL(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUDOM(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUNEBH(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PWT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PIT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PST9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PRT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PHT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTKET9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSRC9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSDSAT9(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCVVT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PO3T9(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEXTT9(NPROMA,NFLEVG,NGFL_EXT)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPT9(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCP9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PR9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDELP9(NPROMA,0:NFLEVG+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDELP9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PHI9(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PHIF9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRE9(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRE9F(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PREPHY9(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PREPHY9F(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALPH9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPR9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PKOZO(NPROMA,NFLEVG*NVCLIS+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLCH(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLSH(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROGL(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROGM(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRATATH(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRATATX(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPT0(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPT0L(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPT0M(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTT0L(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTT0M(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVORT9(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEVEL0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVVEL0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSDFI0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSDVBC0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PB1(NPROMA,NFLDSLB1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMVT1(NPROMA,NFLEVG,YT1%NDIM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMVT1S(NPROMA,YT1%NDIMS) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGFLT1(NPROMA,NFLEVG,YGFL%NDIM1)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSP_SB(NPROMA,YSP_SBD%NLEVS,YSP_SBD%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSP_SG(NPROMA,YSP_SGD%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSP_RR(NPROMA,YSP_RRD%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSD_VF(NPROMA,YSD_VFD%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSD_VP(NPROMA,YSD_VPD%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSD_VV(NPROMA,YSD_VVD%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSD_VH(NPROMA,YSD_VHD%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSD_VA(NPROMA,YSD_VAD%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSD_VC(NPROMA,YSD_VCD%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEMTD(NPROMA,1:NFLEVG+1)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEMTU(NPROMA,1:NFLEVG+1)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTRSW(NPROMA,1:NFLEVG+1)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PRMOON(NPROMA)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGPAR(NPROMA,NGPAR+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLF1(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSRC1(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDHSF(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PALB(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCAPE(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCLCC(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCLCH(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCLCL(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCLCM(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCLCT(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCLPH(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCT(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDIFCQ(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDIFCQI(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDIFCQL(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDIFCS(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDIFTQ(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDIFTQI(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDIFTQL(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDIFTS(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCCQL(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCCQN(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCHOZ(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPFPSL(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPFPSN(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPFPCL(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPFPCN(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPEVPSL(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPEVPSN(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPEVPCL(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPEVPCN(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCHSP(NPROMM,YSP_SBD%NLEVS) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCLL(NPROMM,NTSSG+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCLN(NPROMM,NTSSG+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFCQING(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCQLNG(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCQNG(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCS(NPROMM,NTSSG+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCSQL(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFCSQN(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFEVL(NPROMM,NTSSG+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFEVN(NPROMM,NTSSG+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFEVV(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFGEL(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFGELS(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFLWSP(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFONTE(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLCL(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLCN(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLCG(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLCHL(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLSL(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLSN(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLSG(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLSHL(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFRMH(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFRSO(NPROMM,0:NFLEVG,NTSSG+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRSOC(NPROMM,0:1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRSODS(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRSOLU(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRSOPS(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRSOPT(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFRTH(NPROMM,0:NFLEVG,NTSSG+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRTHC(NPROMM,0:1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRTHDS(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFTR(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGZ0(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGZ0H(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PNEB(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQCLS(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQICE(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQLI(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQS(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PRH(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRHCLS(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PRUISL(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PRUISP(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PRUISS(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRCU(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRCV(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRDU(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRDV(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRMU(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRMV(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRTU(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRTV(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUCLS(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVCLS(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTCLS(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PUGST(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVGST(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PMOCON(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFDIS(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFHPCL(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFHPCN(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFHPSL(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFHPSN(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFHSCL(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFHSCN(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFHSSL(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFHSSN(NPROMM,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFEPFP(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFCMPCQ(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFCMPSN(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFCMPSL(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTENDU(NPROMM,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTENDV(NPROMM,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PQSOL(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDERNSHF(NPROMM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEZDIAG(NPROMA,NFLEVG,NGFL_EZDIAG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFCQRNG(NPROMM,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFCQSNG(NPROMM,0:NFLEVG)

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

LOGICAL :: LL_CALL_CPPFTTCDIR       ! CPPFTTCDIR is called if .T.
LOGICAL :: LLDIAB
LOGICAL :: LL_SAVE_PHSURF
LOGICAL :: LLACTIVE_HV
LOGICAL :: LLACTIVE_Z0F
LOGICAL :: LLACTIVE_Z0H
LOGICAL :: LLACTIVE_PBLH
LOGICAL :: LLACTIVE_SPSH

INTEGER(KIND=JPIM) :: IFIELDS, IFIELDSS, IFIELDST
INTEGER(KIND=JPIM) :: IJL,IBLK
INTEGER(KIND=JPIM) :: IPI,IPL,IPQ,IPS,IPR,IPG,IPH,IPTKE,IPO3,IPEXT,ITDIA
INTEGER(KIND=JPIM) :: INSTEP_DEB,INSTEP_FIN
INTEGER(KIND=JPIM) :: JL1, JL2, JLEV
INTEGER(KIND=JPIM) :: JROF
INTEGER(KIND=JPIM) :: IVCLIA

INTEGER(KIND=JPIM) :: ICLPH(NPROMA)          ! cf. KCLPH in APLPAR.

!     --- UPPER AIR PHYSICAL TENDENCIES.
REAL(KIND=JPRB) :: ZTENDH(NPROMM,NFLEVG)     ! Enthalpy tendency.
REAL(KIND=JPRB) :: ZTENDQ(NPROMM,NFLEVG)     ! Moisture tendency.
REAL(KIND=JPRB) :: ZTENDQI(NPROMM,NFLEVG)    ! Cloud Ice tendency.
REAL(KIND=JPRB) :: ZTENDQL(NPROMM,NFLEVG)    ! Cloud Liquid water tendency.
REAL(KIND=JPRB) :: ZTENDQR(NPROMM,NFLEVG)    ! Liquid Precipitation tendency
REAL(KIND=JPRB) :: ZTENDQS(NPROMM,NFLEVG)    ! Solid Precipitation tendency
REAL(KIND=JPRB) :: ZTENDPTKE(NPROMM,NFLEVG)  ! Pseudo progn. TKE

REAL(KIND=JPRB) :: ZUDOM(NPROMA,NFLEVG),ZUDAL(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZDDOM(NPROMA,NFLEVG),ZDDAL(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZUNEBH(NPROMA,NFLEVG),ZENTCH(NPROMA,NFLEVG)

!     --- UPPER AIR PHYSICAL TENDENCIES FOR AROME.
!       (the previous one are not used in AROME)
REAL(KIND=JPRB) :: ZTENDT (NPROMA,NFLEVG)        ! temperature tendency
REAL(KIND=JPRB) :: ZTENDR (NPROMA, NFLEVG, NRR)  ! microphisical tendency (including Q)
REAL(KIND=JPRB) :: ZTENDTKE (NPROMA,NFLEVG)      ! TKE tendency
REAL(KIND=JPRB) :: ZTENDW (NPROMA,NFLEVG)        ! W  tendency
REAL(KIND=JPRB) :: ZTENDD (NPROMA,NFLEVG)        ! d  tendency
REAL(KIND=JPRB) :: ZTENDEXT(NPROMA,NFLEVG,NGFL_EXT)      ! GFL EXTRA tendency

!     --- SURFACE AND DEEP RESERVOIR PHYSICAL TENDENCIES.
REAL(KIND=JPRB) :: ZTDTS(NPROMM)             ! Surface temperature tendency.
REAL(KIND=JPRB) :: ZTDTP(NPROMM,YSP_SBD%NLEVS)        ! Deep temperature tendency.
REAL(KIND=JPRB) :: ZTDWS(NPROMM)             ! Surface water res. tendency.
REAL(KIND=JPRB) :: ZTDWP(NPROMM)             ! Deep water res. tendency.
REAL(KIND=JPRB) :: ZTDWL(NPROMM)             ! Interception water res. tendency
REAL(KIND=JPRB) :: ZTDSNS(NPROMM)            ! Snow res. tendency. 
REAL(KIND=JPRB) :: ZTDWPI(NPROMM)            ! Deep ice res. tendency.
REAL(KIND=JPRB) :: ZTDWSI(NPROMM)            ! Surface ice res. tendency.
REAL(KIND=JPRB) :: ZTDALBNS(NPROMA)          ! Snow albedo tendency.
REAL(KIND=JPRB) :: ZTDRHONS(NPROMA)          ! Snow density tendency.

!     --- FLUXES FROM PARAMETERISATIONS AND TENDENCIES COMP.
REAL(KIND=JPRB) :: ZFP(NPROMM,0:NFLEVG)      ! Total rainfall flux.
REAL(KIND=JPRB) :: ZFEPFP(NPROMM,0:NFLEVG)   ! Entalpy pseudo-flux rainfall
                                             ! energy.
REAL(KIND=JPRB) :: ZFPLCH(NPROMM,0:NFLEVG)   ! convective precipitation flux,
                                             ! local
REAL(KIND=JPRB) :: ZFPLSH(NPROMM,0:NFLEVG)   ! stratiform precipitation flux,
                                             ! local
REAL(KIND=JPRB) :: ZFTKE(NPROMM,0:NFLEVG)    ! TKE flux.

!     --- Fields of potential use for HIRLAM .
REAL(KIND=JPRB) :: ZCVGQL(NPROMM,NFLEVG)     ! local array for cloud water tendency 
REAL(KIND=JPRB) :: ZCVGQI(NPROMM,NFLEVG)     ! local array for cloud ice tendency
REAL(KIND=JPRB) :: ZCVGT(NPROMM,NFLEVG)      ! local array for temperature tendency

!     --- MISCELLANEOUS PARAMETERISATIONS, 2D ARRAYS ---
REAL(KIND=JPRB) :: ZCVGQ(NPROMM,NFLEVG)      ! convergence of humidity
                                             ! ("Kuo" condition).
REAL(KIND=JPRB) :: ZFHP(NPROMM,0:NFLEVG)     ! Total enthalpy flux
                                             ! + sensible heat flux.
REAL(KIND=JPRB) :: ZLCVQ(NPROMA,NFLEVG)      ! limited physical contribution to
                                             ! the diagnostic of moisture
                                             ! convergence (remove
                                             ! large scale precip. contrib.).
REAL(KIND=JPRB) :: ZLSCPE(NPROMM,NFLEVG)     ! cf. PLSCPE in APLPAR.
REAL(KIND=JPRB) :: ZLH(NPROMM,NFLEVG)        ! cf. PLH in APLPAR.
REAL(KIND=JPRB) :: ZQW(NPROMM,NFLEVG)        ! cf. PQW in APLPAR.
REAL(KIND=JPRB) :: ZTW(NPROMM,NFLEVG)        ! cf. PTW in APLPAR.

REAL(KIND=JPRB) :: ZFRMQ(NPROMM,0:NFLEVG)    ! cf. MESOSPHERIC humidity flux in APLPAR.

!     --- 1D DIAGNOSTIC FIELDS, SURFACE FLUXES
REAL(KIND=JPRB) :: ZCD(NPROMM)               ! cf. PCD in APLPAR.
REAL(KIND=JPRB) :: ZCDN(NPROMM)              ! cf. PCDN in APLPAR.
REAL(KIND=JPRB) :: ZCH(NPROMM)               ! cf. PCH in APLPAR.
REAL(KIND=JPRB) :: ZEMIS(NPROMM)             ! cf. PEMIS in APLPAR.
REAL(KIND=JPRB) :: ZFEVI(NPROMM,NTSSG+1)     ! cf. PFEVI in APLPAR.
REAL(KIND=JPRB) :: ZNEIJ(NPROMM)             ! cf. PNEIJ in APLPAR.
REAL(KIND=JPRB) :: ZVEG(NPROMM)              ! cf. PVEG in APLPAR.
REAL(KIND=JPRB) :: ZQSAT(NPROMA,NFLEVG)      ! specific humidity at saturation.
REAL(KIND=JPRB) :: ZQSATS(NPROMA)            ! cf. PQSATS in APLPAR.
REAL(KIND=JPRB) :: ZQS1(NPROMM)              ! cf. PQS1 in APLPARS.

!     --- DIAGNOSTIC FIELDS STATE OF SURFACE AIR ---
REAL(KIND=JPRB) :: ZC1(NPROMM)               ! cf. PC1 in APLPAR.
REAL(KIND=JPRB) :: ZC2(NPROMM)               ! cf. PC2 in APLPAR.
REAL(KIND=JPRB) :: ZCPS(NPROMM)              ! cf. PCPS in APLPAR.
REAL(KIND=JPRB) :: ZLHS(NPROMM)              ! cf. PLHS in APLPAR.
REAL(KIND=JPRB) :: ZRS(NPROMM)               ! cf. PRS in APLPAR.

!     --- RADIATION COEFFICIENTS FOR SIMPLIFIED PHYSICS IN GRID-POINT ---
REAL(KIND=JPRB) :: ZRAB3C(NPROMM,NFLEVG) ! clear-sky parallel/diffuse
                                         ! reflectivity.
REAL(KIND=JPRB) :: ZRAB4C(NPROMM,NFLEVG) ! clear-sky diffuse transmissivity.
REAL(KIND=JPRB) :: ZRAB6C(NPROMM,NFLEVG) ! clear-sky diffuse reflectivity.
REAL(KIND=JPRB) :: ZRAB3N(NPROMM,NFLEVG) ! cloudy parallel/diffuse reflectivity
REAL(KIND=JPRB) :: ZRAB4N(NPROMM,NFLEVG) ! cloudy diffuse transmissivity.
REAL(KIND=JPRB) :: ZRAB6N(NPROMM,NFLEVG) ! cloudy diffuse reflectivity.
REAL(KIND=JPRB) :: ZRAT1C(NPROMM,NFLEVG) ! clear-sky parallel transmissivity.
REAL(KIND=JPRB) :: ZRAT2C(NPROMM,NFLEVG) ! clear-sky parallel/diffuse
                                         ! transmissivity.
REAL(KIND=JPRB) :: ZRAT3C(NPROMM,NFLEVG) ! clear-sky parallel/diffuse
                                         ! reflectivity.
REAL(KIND=JPRB) :: ZRAT4C(NPROMM,NFLEVG) ! clear-sky diffuse transmissivity.
REAL(KIND=JPRB) :: ZRAT5C(NPROMM,NFLEVG) ! clear-sky diffuse reflectivity.
REAL(KIND=JPRB) :: ZRAT1N(NPROMM,NFLEVG) ! cloudy parallel transmissivity.
REAL(KIND=JPRB) :: ZRAT2N(NPROMM,NFLEVG) ! cloudy parallel/diffuse
                                         ! transmissivity.
REAL(KIND=JPRB) :: ZRAT3N(NPROMM,NFLEVG) ! cloudy parallel/diffuse reflectivity
REAL(KIND=JPRB) :: ZRAT4N(NPROMM,NFLEVG) ! cloudy diffuse transmissivity.
REAL(KIND=JPRB) :: ZRAT5N(NPROMM,NFLEVG) ! cloudy diffuse reflectivity.
REAL(KIND=JPRB) :: ZCOR(NPROMM,NFLEVG)   ! correction for cloudiness for
                                         ! thermal rad.
REAL(KIND=JPRB) :: ZAC(NPROMM,(NFLEVG+1)*(NFLEVG+1)) ! Curtis matrix.
REAL(KIND=JPRB) :: ZAC_HC(NFLEVG+1,NFLEVG+1)         ! horizontally-constant
                                                     ! field for ZAC.

!     --- GEOMETRY FOR RADIATION ---
REAL(KIND=JPRB) :: ZMMU0(NPROMA)  ! mean solar angle (for given day for
                                  ! simpl. rad. scheme)
REAL(KIND=JPRB) :: ZMU0(NPROMA)   ! local cosine of instantaneous solar zenith
                                  ! angle.
REAL(KIND=JPRB) :: ZMU0LU(NPROMM) ! local cosine of instantaneous lunar zenith
                                  ! angle.
REAL(KIND=JPRB) :: ZMU0M(NPROMA)  ! local cosine of averaged solar zenith angle

!     ---FOR AROME PHYSICS  ---
REAL(KIND=JPRB) :: ZDT   !pour cputqy_arome, a changer peut etre plus tard...
REAL(KIND=JPRB) :: ZGWT1(NPROMA,0:NFLEVG)     ! vertical velocity calculated by 
                                              ! cputqy_arome before convertion in d
REAL(KIND=JPRB) :: ZTT1(NPROMA,NFLEVG)       ! Temperature at t1 for gnhgw2svd

!     --- Buffers to save the initial value of   ---
!     --- some pseudo-historical surface buffers ---
REAL(KIND=JPRB) :: ZHV(NPROMM)
REAL(KIND=JPRB) :: ZGZ0F(NPROMM)
REAL(KIND=JPRB) :: ZGZ0HF(NPROMM)
REAL(KIND=JPRB) :: ZPBLH(NPROMM)
REAL(KIND=JPRB) :: ZFHPS(NPROMM)

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "abor1.intfb.h"
#include "apl_arome.intfb.h"
#include "aplpar.intfb.h"
#include "hl_aplpar.intfb.h"
#include "aplpars.intfb.h"
#include "aplpassh.intfb.h"
#include "cpchet.intfb.h"
#include "cpfhpfs.intfb.h"
#include "cpmvvps.intfb.h"
#include "cpnudg.intfb.h"
#include "cpozo.intfb.h"
#include "cppfttcdir.intfb.h"
#include "cppfttcinv.intfb.h"
#include "cpphinp.intfb.h"
#include "cppsolan.intfb.h"
#include "cpqsol.intfb.h"
#include "cptend.intfb.h"
#include "cptend_new.intfb.h"
#include "cptends.intfb.h"
#include "cptendsm.intfb.h"
#include "cputqy_arome.intfb.h"
#include "cputqy.intfb.h"
#include "cputqys.intfb.h"
#include "cpwts.intfb.h"
#include "gnhgw2svdarome.intfb.h"
#include "gpinither.intfb.h"
#include "initaplpar.intfb.h"
#include "profilechet.intfb.h"
#include "rdradcoef.intfb.h"
#include "writephysio.intfb.h"
#include "wrphtrajm.intfb.h"
#include "wrphtrsf.intfb.h"
#include "wrradcoef.intfb.h"

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

IF (LHOOK) CALL DR_HOOK('MF_PHYS',0,ZHOOK_HANDLE)

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

!        1.    Preliminary calculations necessary
!              for all types of physics.
!              ------------------------------------

IBLK=(KSTGLO-1)/NPROMA+1
LL_CALL_CPPFTTCDIR=LDWRTCFOU0
IF (LL_CALL_CPPFTTCDIR) THEN
  INSTEP_DEB=1
  INSTEP_FIN=NSTOP-1
ELSE
  INSTEP_DEB=1
  INSTEP_FIN=1
ENDIF

! Complete physics is called.
LLDIAB=(LMPHYS.OR.LEPHYS).AND.(.NOT.LAGPHY)

IF(LNDRIV) THEN
! IN CASE OF MASQUED GRID POINT NUDGING:
  IVCLIA=YSD_VAD%NUMFLDS-1
ELSE
  IVCLIA=YSD_VAD%NUMFLDS
ENDIF

IF (LRAYSP.AND.(NSTEP >= INSTEP_DEB .AND. NSTEP <= INSTEP_FIN) &
   & .AND.(.NOT.LDLADNMI)) THEN  
  CALL CPPSOLAN(KST,KEND,PGEMU,PGELAM,ZMMU0)
  IF (.NOT.LSDDH) THEN
    CALL GPINITHER(KST,KEND,PDHSF,KSTGLO)
  ENDIF
ENDIF

IF ((LLDIAB.OR.LSIMPH).AND.(.NOT.LDLADNMI)) THEN
  CALL CPPHINP(KST,KEND,&
   & PGEMU,PGELAM,&
   & PUT0,PVT0,PQT0,PQT0L,PQT0M,PQSLT0L,PQSLT0M,&
   & PRDELP0,PEVEL0,PCVGQSL,&
   & ZMU0,ZMU0LU,ZMU0M,ZCVGQ)  
  ZLCVQ(KST:KEND,1:NFLEVG)=ZCVGQ(KST:KEND,1:NFLEVG)
ENDIF

DO JLEV=1,NFLEVG
  DO JROF=KST,KEND
    ZCVGQL(JROF,JLEV)=0._JPRB
    ZCVGQI(JROF,JLEV)=0._JPRB
    ZCVGT (JROF,JLEV)=0._JPRB
  ENDDO
ENDDO

DO JROF=KST,KEND
  ZQSATS(JROF)=0.0_JPRB
  ZFPLCH(JROF,0)=0.0_JPRB
  ZFPLSH(JROF,0)=0.0_JPRB
ENDDO

IF(LNEBN.OR.LNEBR.OR.LRRGUST) THEN
  DO JLEV=1,NFLEVG
    DO JROF=KST,KEND
      ZFPLCH(JROF,JLEV)=PFPLCH(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF
IF(LRRGUST) THEN
  DO JLEV=1,NFLEVG
    DO JROF=KST,KEND
      ZFPLSH(JROF,JLEV)=PFPLSH(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

! * In some cases, some pseudo-historic surface buffers (like z0) should
!   not be modified between the entrance and the output of MF_PHYS
!   (this is the case for example for CDCONF='X').
!   For the time being, we must save:
!   - HV: resistance to evapotranspiration
!   - Z0F: gravity * surface roughness length
!   - Z0H: gravity * roughness length for heat
!   - PBLH: PBL height
!   - SPSH: ??? (for ALARO)
!   Value of the keys LLACTIVE_... should be consistent with the tests done
!   in su_surf_flds.F90 (in the future it would be more convenient to add
!   an attribute LACTIVE in the definition of types TYPE_SURF_PTR_3D
!   and TYPE_SURF_PTR_2D).
LL_SAVE_PHSURF=LLDIAB.AND.(.NOT.LDLADNMI).AND.((CDCONF == 'X').OR.(CDCONF == 'M'))
LLACTIVE_HV=LMPHYS.AND.LSOLV
LLACTIVE_Z0F=LMPHYS.AND.(.NOT.LMSE)
LLACTIVE_Z0H=LMPHYS.AND.LSOLV
LLACTIVE_PBLH=LMPHYS.AND.(LNEBR.OR.(TRIM(CGMIXLEN) == 'TM'))
LLACTIVE_SPSH=LMPHYS.AND.LPHSPSH
IF (LL_SAVE_PHSURF) THEN
  IF(LLACTIVE_HV) ZHV(1:NPROMA)=PSD_VV(1:NPROMA,YSD_VV%YHV%MP)
  IF(LLACTIVE_Z0F) ZGZ0F(1:NPROMA)=PSD_VF(1:NPROMA,YSD_VF%YZ0F%MP)
  IF(LLACTIVE_Z0H) ZGZ0HF(1:NPROMA)=PSD_VV(1:NPROMA,YSD_VV%YZ0H%MP)
  IF(LLACTIVE_PBLH) ZPBLH(1:NPROMA)=PSD_VH(1:NPROMA,YSD_VH%YPBLH%MP)
  IF(LLACTIVE_SPSH) ZFHPS(1:NPROMA)=PSD_VH(1:NPROMA,YSD_VH%YSPSH%MP)
  IF(LCVPRO) THEN
    ZUDAL(:,:)=PUDAL(:,:)
    ZUDOM(:,:)=PUDOM(:,:)
    IF(LCDDPRO) THEN
      ZDDAL(:,:)=PDDAL(:,:)
      ZDDOM(:,:)=PDDOM(:,:)
    ENDIF
  ENDIF
  IF(YUNEBH%LACTIVE) ZUNEBH(:,:)=PUNEBH(:,:)
  IF(YUEN%LACTIVE)   ZENTCH(:,:)=PENTCH(:,:)
ENDIF

CALL INITAPLPAR ( KST, KEND, NPROMA, NFLEVG, NTSSG, YSP_SBD%NLEVS,&
  & PSD_VF(1,YSD_VF%YVEG%MP  ) ,&
  & PDIFCQ , PDIFCQI, PDIFCQL, PDIFCS , PDIFTQ , PDIFTQI, PDIFTQL,&
  & PDIFTS , PFCCQL , PFCCQN , PFCSQL , PFCSQN , PFCQNG , PFCQING,&
  & PFCQLNG, PFCQRNG, PFCQSNG, &
  & PFPLCL , PFPLCN , PFPLCG , PFPLCHL, PFPLSL , PFPLSN ,PFPLSG ,&
  & PFPLSHL, PFRSO  , PFRSOC ,&
  & PFRTH  , PFRTHC , PSTRCU , PSTRCV , PSTRDU , PSTRDV , PSTRTU ,&
  & PSTRTV , PSTRMU , PSTRMV , PFRMH  , PFCHOZ , ZCPS   , ZLHS   ,&
  & ZRS    , ZLH    , ZLSCPE , PNEB   , PQICE  , PQLI   , ZQSAT  ,&
  & ZQW    , PRH    , ZTW    , PALB   , ZCD    , ZCDN   , ZCH    ,&
  & ZC1    , ZC2    , PCT    , ZEMIS  , PFCHSP , PFCLL  , PFCLN  ,&
  & PFCS   , ZFEVI  , PFEVL  , PFEVN  , PFEVV  , PFTR   , PFLWSP ,&
  & PFONTE , &
  & PFGEL  , PFGELS , PFRSODS, PFRSOPS, PFRSOPT, PFRSOLU, PFRTHDS,&
  & PFPFPSL, PFPFPSN, PFPFPCL, PFPFPCN, PFPEVPSL,PFPEVPSN,&
  & PFPEVPCL, PFPEVPCN, ZFTKE, PGZ0   , PGZ0H  , ZNEIJ  , ZVEG   ,PQS,&
  & ZQSATS , PRUISL , PRUISP , PRUISS , PUCLS  , PVCLS  , PTCLS  ,&
  & PQCLS  , PRHCLS , PCLCT  , PCLCH  , PCLCM  , PCLCL  , PCLCC  ,&
  & PCAPE  , ICLPH  , PCLPH  , PUGST  , PVGST  )
!*       2.    Complete physics.
!              -----------------

!        2.2  Complete physics.
!             -----------------

IF (LLDIAB.AND.(.NOT.LDLADNMI).AND.(.NOT.LMPA)) THEN

  ! PAS DE TEMPS DE LA PHYSIQUE (/YOMPHY2/)
  ! Dans le cas des iterations de l'initialisation par modes normaux,
  ! le pas de temps pour la physique ne peux pas etre nul pour APLPAR et
  ! CPATY (par contre c'est bien PDTPHY qui est passe en argument aux autres
  ! sous-prog. de la physique). Ceci est du a l'impossibilite de prendre en
  ! compte des flux qui deviennent infinis pour TSPHY=0 (flux de masse du au
  ! reajustement des sursaturations par exemple...). Mais les tendances phys.
  ! sont bien nulles dans le cas de la configuration 'E' (Modes Normaux).
  ! PHYSICS TIME STEP (/YOMPHY2/)
  ! In case of normal mode initialisation iterations, the physics time
  ! step cannot be zero for APLPAR and CPATY (nevertheless it is PDTPHY
  ! which is passed to other physics subroutines). This is due to the
  ! impossibility to take into account fluxes which are infinite for TSPHY=0
  ! (e.g.: mass flux due to oversaturation...). But the physical tendencies
  ! are indeed zero in configuration 'E' (NMI).

  TSPHY = MAX(PDTPHY,1.0_JPRB)

  ! CALL PARAMETERISATIONS

  DO JROF=KST,KEND
    PSD_VF(JROF,YSD_VF%YLSM%MP)=REAL(NINT(PSD_VF(JROF,YSD_VF%YLSM%MP)),JPRB)
  ENDDO
  
  IF (.NOT. LHL) THEN
    IF (LTWOTL) THEN

      ITDIA=1_JPRB
      CALL APLPAR ( KST    , KEND   , NPROMA ,&
       & ITDIA  , NFLEVG  , KGL1   , KGL2   , KSTGLO,&
       & NVCLIS , YSD_VVD%NUMFLDS ,&
       & NSTEP  ,&
       & NTSSG  , YSP_SBD%NLEVS   ,&
       & KBL    , KGPCOMP,&
       & PHI0  , PRE0  , PHIF0 , PRE0F , PALPH0 , PSD_VV(1,YSD_VV%YARG%MP)   ,&
       & PSD_VV(1,YSD_VV%YD2%MP)    ,&
       & PDELP0(1,1),PSD_VV(1,YSD_VV%YIVEG%MP),PSD_VV(1,YSD_VV%YLAI%MP)   , PLNPR0 ,&
       & PRDELP0,&
       & PSD_VV(1,YSD_VV%YRSMIN%MP) , PSD_VV(1,YSD_VV%YSAB%MP  ) ,&
       & PSD_VV(1,YSD_VV%YZ0H%MP  ) , PSD_VA(1,YSD_VA%YSEA%MP  ) , PSD_VA(1,YSD_VA%YLAN%MP ) ,&
       & PSD_VA(1,YSD_VA%YSOO%MP ) , PSD_VA(1,YSD_VA%YDES%MP ) , PSD_VA(1,YSD_VA%YSUL%MP ) ,&
       & PSD_VA(1,YSD_VA%YVOL%MP ) , PRCORI          ,&
       & PUT0   , PVT0   , PTT0   , PQT0   , PIT0   , PLT0   ,&
       & PST0   , PRT0   , PTKET0 ,  PSDSAT0,  PCVVT0 ,&
       & PO3T0  ,&
       & PVORT0 ,&
       & PCP0   , ZCVGQ  , PR0    , PKOZO  , ZFPLCH , ZFPLSH ,&
       & PDDAL  , PDDOM  ,PENTCH , PUDAL  , PUDOM  , PUNEBH, PEVEL0, &
       & PSD_VH(1,YSD_VH%YTCCH%MP  ) ,  PSD_VH(1,YSD_VH%YSCCH%MP  ) , PSD_VH(1,YSD_VH%YBCCH%MP  ) ,&
       & PSD_VH(1,YSD_VH%YSPSH%MP  ) ,PSD_VH(1,YSD_VH%YPBLH%MP  ) , &
       & PGPAR , &
       & PSP_SG(1,YSP_SG%YF%MP0) , PSP_SG(1,YSP_SG%YA%MP0), PSP_SG(1,YSP_SG%YR%MP0),&
       & PSP_SB(1,1,YSP_SB%YT%MP0 ) , PSP_RR(1,YSP_RR%YT%MP0 ) , PSP_RR(1,YSP_RR%YFC%MP0) ,&
       & PSP_SB(1,1,YSP_SB%YQ%MP0 ) , PSP_SB(1,1,YSP_SB%YTL%MP0), PSP_RR(1,YSP_RR%YW%MP0)  ,&
       & PSP_RR(1,YSP_RR%YIC%MP0),&
       & PSD_VV(1,YSD_VV%YHV%MP)    , PVVEL0,&
       & PEMTD , PEMTU ,PTRSW ,&
       & PGECLO , PGESLO , PSD_VV(1,YSD_VV%YALV%MP )  ,&
       & PSD_VF(1,YSD_VF%YALBF%MP ) , PSD_VF(1,YSD_VF%YALBSF%MP) , PSD_VF(1,YSD_VF%YEMISF%MP) ,&
       & PSD_VF(1,YSD_VF%YGETRL%MP) , PSD_VF(1,YSD_VF%YLSM%MP  ) , PSD_VF(1,YSD_VF%YVEG%MP  ) ,&
       & PSD_VF(1,YSD_VF%YZ0F%MP  ) , PSD_VF(1,YSD_VF%YZ0RLF%MP ),&
       & PSD_VF(1,YSD_VF%YVRLAN%MP) , PSD_VF(1,YSD_VF%YVRLDI%MP) , PSD_VC(1,YSD_VC%YVC(1)%MP)  ,&
       & PRMOON ,&
       & ZMU0   , ZMU0LU , ZMU0M  , PGAW   ,PGELAM, PGEMU  , PGM    ,&
       & ZAC    , ZAC_HC , ZCOR   , ZMMU0  , PDHSF  ,&
       & ZRAB3C , ZRAB3N , ZRAB4C , ZRAB4N , ZRAB6C , ZRAB6N ,&
       & ZRAT1C , ZRAT1N , ZRAT2C , ZRAT2N , ZRAT3C , ZRAT3N ,&
       & ZRAT4C , ZRAT4N , ZRAT5C , ZRAT5N ,&
       & POROG  , &
       & PDIFCQ , PDIFCQI, PDIFCQL, PDIFCS , PDIFTQ , PDIFTQI,&
       & PDIFTQL,&
       & PDIFTS , PFCCQL , PFCCQN , PFCSQL , PFCSQN , PFCQNG ,&
       & PFCQING, PFCQLNG, PFCQRNG, PFCQSNG,&
       & PFPLCL , PFPLCN , PFPLSL , PFPLSN , PFRSO  ,&
       & PFRSOC ,&
       & PFRTH  , PFRTHC , PSTRCU , PSTRCV , PSTRDU , PSTRDV ,&
       & PSTRTU ,&
       & PSTRTV , PSTRMU , PSTRMV , PFRMH  , ZFRMQ  , PFCHOZ ,&
       & ZCPS   , ZLHS   ,&
       & ZRS    , ZLH    , ZLSCPE , PNEB   , PQICE  , PQLI   ,&
       & ZQSAT  ,&
       & ZQW    , PRH    , ZTW    , PALB   , ZCD    , ZCDN   ,&
       & ZCH    ,&
       & ZC1    , ZC2    , PCT    , ZEMIS  , PFCHSP , PFCLL  ,&
       & PFCLN  ,&
       & PFCS   , ZFEVI  , PFEVL  , PFEVN  , PFEVV  , PFTR   ,&
       & PFLWSP , PFONTE , PSP_SG(1,YSP_SG%YT%MP1), PFGEL  , PFGELS ,&
       & PFRSODS, PFRSOPS, PFRSOPT, PFRSOLU, PFRTHDS, &
       & PFPFPSL, PFPFPSN, PFPFPCL, PFPFPCN, PFPEVPSL,PFPEVPSN,PFPEVPCL,&
       & PFPEVPCN,ZFTKE  , PGZ0   , PGZ0H  , ZNEIJ  , ZVEG   , PQS,&
       & ZQSATS , PRUISL , PRUISP , PRUISS , PUCLS  , PVCLS  ,&
       & PTCLS  ,&
       & PQCLS  , PRHCLS , PCLCT  , PCLCH  , PCLCM  , PCLCL  ,&
       & PCLCC  , PCAPE  , ICLPH  , PCLPH  , PUGST  , PVGST  ,&
       & ZTENDPTKE, &
       & PDERNSHF,&
       & 'APLPAR' )  


      !-------------------------------------------------
      ! Extract Single Column Model profiles.
      !-------------------------------------------------

      IF(LGSCM) CALL WRITEPHYSIO &
       & (KEND, &
       & KST, KGL1, KGL2, KSTGLO, &
       & PGELAM, PGEMU, &
       & PGM, ZMU0, POROG, POROGL, POROGM, PRCORI, PRATATH, PRATATX, &
       & PSD_VF(1,YSD_VF%YLSM%MP ), PSD_VV(1,YSD_VV%YARG%MP), PSD_VV(1,YSD_VV%YSAB%MP), PSD_VF(1,YSD_VF%YALBF%MP), &
       & PSD_VF(1,YSD_VF%YALBSF%MP), PSD_VF(1,YSD_VF%YEMISF%MP), PSD_VV(1,YSD_VV%YD2%MP), PSD_VV(1,YSD_VV%YIVEG%MP), &
       & PSD_VV(1,YSD_VV%YLAI%MP), PCT, PSD_VF(1,YSD_VF%YZ0F%MP), PSD_VV(1,YSD_VV%YZ0H%MP), PSD_VF(1,YSD_VF%YZ0RLF%MP), &
       & PSD_VF(1,YSD_VF%YGETRL%MP), PSD_VF(1,YSD_VF%YVRLAN%MP), PSD_VF(1,YSD_VF%YVRLDI%MP), PSD_VV(1,YSD_VV%YRSMIN%MP), &
       & PSD_VF(1,YSD_VF%YVEG%MP), PSD_VV(1,YSD_VV%YHV%MP), PSD_VA(1,YSD_VA%YSEA%MP), PSD_VA(1,YSD_VA%YLAN%MP), &
       & PSD_VA(1,YSD_VA%YSOO%MP), PSD_VA(1,YSD_VA%YDES%MP), PSD_VC(1,YSD_VC%YVC(1)%MP), &
       & PSPT0, PSPT0L, PSPT0M, PTT0, PTT0L, PTT0M, PQT0, PQT0L, PQT0M, &
       & PUT0, PVT0, PVORT0, PDIVT0, ZCVGQ, ZLCVQ, &
       & PSP_RR(1,YSP_RR%YT%MP9), PSP_SB(1,1,YSP_SB%YT%MP9), PSP_RR(1,YSP_RR%YFC%MP9), PSP_RR(1,YSP_RR%YW%MP9), &
       & PSP_RR(1,YSP_RR%YIC%MP9), PSP_SB(1,1,YSP_SB%YQ%MP9), PSP_SB(1,1,YSP_SB%YTL%MP9), PSP_SG(1,YSP_SG%YF%MP9), &
       & PDIFCQ, PDIFCQI, PDIFCQL, PDIFCS, PDIFTQ, PDIFTQI, PDIFTQL, &
       & PDIFTS, PFCCQL, PFCCQN, PFCSQL, PFCSQN, PFCQNG, PFCQING, &
       & PFCQLNG, PFPLCL, PFPLCN, PFPLSL, PFPLSN, PFRSO, PFRTH, &
       & PSTRCU, PSTRCV, PSTRDU, PSTRDV, PSTRTU, PSTRTV, PSTRMU, PSTRMV, &
       & PFRMH, PFCHOZ, PNEB, PQICE, PQLI, PRH, &
       & PFCS, PFCLL, PFCLN, PFEVL, PFEVN, PFEVV, PFTR, PFLWSP, PFONTE, &
       & PFGEL, PFGELS, PFRSODS, PFRSOPS, PFRSOPT, PFRTHDS, &
       & PQS, PRUISL, PRUISP, PRUISS, &
       & PUCLS, PVCLS, PTCLS, PQCLS, PRHCLS, &
       & PCLCT, PCLCH, PCLCM, PCLCL, PCLCC, &
       & ZFPLCH, ZFPLSH, &
       & PSD_VH(1,YSD_VH%YTCCH%MP),  PSD_VH(1,YSD_VH%YSCCH%MP), PSD_VH(1,YSD_VH%YBCCH%MP), PSD_VH(1,YSD_VH%YPBLH%MP) )

    ELSE

      ITDIA=1_JPRB 
      CALL APLPAR ( KST    , KEND   , NPROMA ,&
       & ITDIA  , NFLEVG  , KGL1   , KGL2   ,KSTGLO ,&
       & NVCLIS , YSD_VVD%NUMFLDS ,&
       & NSTEP  ,&
       & NTSSG  , YSP_SBD%NLEVS   ,&
       & KBL    , KGPCOMP,&
       & PHI9  , PRE9  , PHIF9 , PRE9F , PALPH9 , PSD_VV(1,YSD_VV%YARG%MP)   ,&
       & PSD_VV(1,YSD_VV%YD2%MP)    ,&
       & PDELP9(1,1),PSD_VV(1,YSD_VV%YIVEG%MP),PSD_VV(1,YSD_VV%YLAI%MP)   , PLNPR9 ,&
       & PRDELP9,&
       & PSD_VV(1,YSD_VV%YRSMIN%MP) , PSD_VV(1,YSD_VV%YSAB%MP  ) ,&
       & PSD_VV(1,YSD_VV%YZ0H%MP  ) , PSD_VA(1,YSD_VA%YSEA%MP ) , PSD_VA(1,YSD_VA%YLAN%MP ) ,&
       & PSD_VA(1,YSD_VA%YSOO%MP ) , PSD_VA(1,YSD_VA%YDES%MP ) , PSD_VA(1,YSD_VA%YSUL%MP ) ,&
       & PSD_VA(1,YSD_VA%YVOL%MP ), PRCORI          ,&
       & PUT9   , PVT9   , PTT9   , PQT9   , PIT9   , PLT9   ,&
       & PST9   , PRT9   , PTKET9 ,PSDSAT9, PCVVT9 ,&
       & PO3T9  ,&
       & PVORT9 ,&
       & PCP9   , ZCVGQ  , PR9    , PKOZO  , ZFPLCH, ZFPLSH  ,&
       & PDDAL  , PDDOM  ,PENTCH , PUDAL  , PUDOM  , PUNEBH, PEVEL0, &
       & PSD_VH(1,YSD_VH%YTCCH%MP  ) ,  PSD_VH(1,YSD_VH%YSCCH%MP  ) , PSD_VH(1,YSD_VH%YBCCH%MP  ) ,&
       & PSD_VH(1,YSD_VH%YSPSH%MP  ) ,&
       & PSD_VH(1,YSD_VH%YPBLH%MP  ) , PGPAR, &
       & PSP_SG(1,YSP_SG%YF%MP9) , PSP_SG(1,YSP_SG%YA%MP9), PSP_SG(1,YSP_SG%YR%MP9),&
       & PSP_SB(1,1,YSP_SB%YT%MP9 ) , PSP_RR(1,YSP_RR%YT%MP9 ) , PSP_RR(1,YSP_RR%YFC%MP9) ,&
       & PSP_SB(1,1,YSP_SB%YQ%MP9 ) , PSP_SB(1,1,YSP_SB%YTL%MP9), PSP_RR(1,YSP_RR%YW%MP9 )  ,&
       & PSP_RR(1,YSP_RR%YIC%MP9),&
       & PSD_VV(1,YSD_VV%YHV%MP)    , PVVEL0, &
       & PEMTD , PEMTU ,PTRSW ,&
       & PGECLO , PGESLO , PSD_VV(1,YSD_VV%YALV%MP )  ,&
       & PSD_VF(1,YSD_VF%YALBF%MP ) , PSD_VF(1,YSD_VF%YALBSF%MP) , PSD_VF(1,YSD_VF%YEMISF%MP) ,&
       & PSD_VF(1,YSD_VF%YGETRL%MP) , PSD_VF(1,YSD_VF%YLSM%MP  ) , PSD_VF(1,YSD_VF%YVEG%MP  ) ,&
       & PSD_VF(1,YSD_VF%YZ0F%MP  ) , PSD_VF(1,YSD_VF%YZ0RLF%MP ),&
       & PSD_VF(1,YSD_VF%YVRLAN%MP) , PSD_VF(1,YSD_VF%YVRLDI%MP) , PSD_VC(1,YSD_VC%YVC(1)%MP)  ,&
       & PRMOON ,&
       & ZMU0   , ZMU0LU , ZMU0M  , PGAW   ,PGELAM, PGEMU  , PGM    ,&
       & ZAC    , ZAC_HC , ZCOR   , ZMMU0  , PDHSF  ,&
       & ZRAB3C , ZRAB3N , ZRAB4C , ZRAB4N , ZRAB6C , ZRAB6N ,&
       & ZRAT1C , ZRAT1N , ZRAT2C , ZRAT2N , ZRAT3C , ZRAT3N ,&
       & ZRAT4C , ZRAT4N , ZRAT5C , ZRAT5N ,&
       & POROG  , &
       & PDIFCQ , PDIFCQI, PDIFCQL, PDIFCS , PDIFTQ , PDIFTQI,&
       & PDIFTQL,&
       & PDIFTS , PFCCQL , PFCCQN , PFCSQL , PFCSQN , PFCQNG ,&
       & PFCQING, PFCQLNG, PFCQRNG, PFCQSNG, &
       & PFPLCL , PFPLCN , PFPLSL , PFPLSN , PFRSO  ,&
       & PFRSOC ,&
       & PFRTH  , PFRTHC , PSTRCU , PSTRCV , PSTRDU , PSTRDV ,&
       & PSTRTU ,&
       & PSTRTV , PSTRMU , PSTRMV , PFRMH  , ZFRMQ  , PFCHOZ ,&
       & ZCPS   , ZLHS   ,&
       & ZRS    , ZLH    , ZLSCPE , PNEB   , PQICE  , PQLI   ,&
       & ZQSAT  ,&
       & ZQW    , PRH    , ZTW    , PALB   , ZCD    , ZCDN   ,&
       & ZCH    ,&
       & ZC1    , ZC2    , PCT    , ZEMIS  , PFCHSP , PFCLL  ,&
       & PFCLN  ,&
       & PFCS   , ZFEVI  , PFEVL  , PFEVN  , PFEVV  , PFTR   ,&
       & PFLWSP , PFONTE , PSP_SG(1,YSP_SG%YT%MP1), PFGEL  , PFGELS ,&
       & PFRSODS, PFRSOPS, PFRSOPT, PFRSOLU, PFRTHDS, &
       & PFPFPSL, PFPFPSN, PFPFPCL, PFPFPCN, PFPEVPSL,PFPEVPSN,PFPEVPCL,&
       & PFPEVPCN,ZFTKE  , PGZ0   , PGZ0H  , ZNEIJ  , ZVEG   , PQS    ,&
       & ZQSATS , PRUISL , PRUISP , PRUISS , PUCLS  , PVCLS  ,&
       & PTCLS  ,&
       & PQCLS  , PRHCLS , PCLCT  , PCLCH  , PCLCM  , PCLCL  ,&
       & PCLCC  , PCAPE  , ICLPH  , PCLPH  , PUGST  , PVGST  ,&
       & ZTENDPTKE, &
       & PDERNSHF,&
       & 'APLPAR' )  

    ENDIF
  ENDIF

  IF (LHL) THEN
    IF (LTWOTL) THEN

      ITDIA=1_JPRB
      CALL HL_APLPAR ( KST    , KEND   , NPROMA ,&
       & ITDIA  , NFLEVG  ,&
       & NVCLIS , YSD_VVD%NUMFLDS ,&
       & NSTEP  ,&
       & NTSSG  , YSP_SBD%NLEVS   ,&
       & KBL    , KGPCOMP,&
       & PVVEL0 ,&
       & PHI0  , PRE0  , PHIF0 , PRE0F , PALPH0 , PSD_VV(1,YSD_VV%YARG%MP)   ,&
       & PSD_VV(1,YSD_VV%YD2%MP)    ,&
       & PDELP0(1,1),PSD_VV(1,YSD_VV%YIVEG%MP),PSD_VV(1,YSD_VV%YLAI%MP)   , PLNPR0 ,&
       & PRDELP0,&
       & PSD_VV(1,YSD_VV%YRSMIN%MP) , PSD_VV(1,YSD_VV%YSAB%MP  ) ,&
       & PSD_VV(1,YSD_VV%YZ0H%MP  ), PRCORI          ,&
       & PUT0   , PVT0   , PTT0   , PQT0   , PIT0   , PLT0   ,&
       & PST0   , PRT0   , PTKET0 ,  PCVVT0 ,&
       & PCLF0  , PQVAT0 , & 
       & PO3T0  ,&
       & PCP0   , ZCVGQ  , ZCVGQL , ZCVGQI  , ZCVGT  , PR0    , PKOZO  ,&
       & ZFPLCH , ZFPLSH ,&
       & PTENDU , PTENDV , ZTENDT , ZTENDTKE, ZTENDQ , &
       & ZTENDQL, ZTENDQI, ZTENDH , &
       & PENTCH , PUNEBH ,&
       & PSD_VH(1,YSD_VH%YTCCH%MP  ) ,  PSD_VH(1,YSD_VH%YSCCH%MP  ) , PSD_VH(1,YSD_VH%YBCCH%MP  ) ,&
       & PSD_VH(1,YSD_VH%YSPSH%MP  ) ,PSD_VH(1,YSD_VH%YPBLH%MP  ) , &
       & PGPAR , &
       & PSP_SG(1,YSP_SG%YF%MP0) , PSP_SG(1,YSP_SG%YA%MP0), PSP_SG(1,YSP_SG%YR%MP0),&
       & PSP_SB(1,1,YSP_SB%YT%MP0 ) , PSP_RR(1,YSP_RR%YT%MP0 ) , PSP_RR(1,YSP_RR%YFC%MP0) ,&
       & PSP_SB(1,1,YSP_SB%YQ%MP0 ) , PSP_SB(1,1,YSP_SB%YTL%MP0), PSP_RR(1,YSP_RR%YW%MP0)  ,&
       & PSP_RR(1,YSP_RR%YIC%MP0),&
       & PSD_VV(1,YSD_VV%YHV%MP)    ,&
       & PSD_VV(1,YSD_VV%YALV%MP )  ,&
       & PSD_VF(1,YSD_VF%YALBF%MP ) , PSD_VF(1,YSD_VF%YALBSF%MP) , PSD_VF(1,YSD_VF%YEMISF%MP) ,&
       & PSD_VF(1,YSD_VF%YGETRL%MP) , PSD_VF(1,YSD_VF%YLSM%MP  ) , PSD_VF(1,YSD_VF%YVEG%MP  ) ,&
       & PSD_VF(1,YSD_VF%YZ0F%MP  ) , PSD_VF(1,YSD_VF%YZ0RLF%MP ),&
       & PSD_VF(1,YSD_VF%YVRLAN%MP) , PSD_VF(1,YSD_VF%YVRLDI%MP) , PSD_VC(1,YSD_VC%YVC(1)%MP)  ,&
       & ZMU0   , PGELAM, PGEMU  , &
       & POROG  , &
       & PDIFCQ , PDIFCQI, PDIFCQL, PDIFCS , PDIFTQ , PDIFTQI,&
       & PDIFTQL,&
       & PDIFTS , PFCCQL , PFCCQN , PFCSQL , PFCSQN , &
       & PFPLCL , PFPLCN , PFPLSL , PFPLSN , PFRSO  ,&
       & PFRTH  , PSTRCU , PSTRCV , PSTRDU , PSTRDV ,&
       & PSTRTU ,&
       & PSTRTV , PSTRMU , PSTRMV , PFRMH  , ZFRMQ  , PFCHOZ ,&
       & ZCPS   , ZLHS   ,&
       & ZRS    , ZLH    , ZLSCPE , PNEB   , PQICE  , PQLI   ,&
       & ZQSAT  ,&
       & ZQW    , PRH    , ZTW    , PALB   , ZCD    , ZCDN   ,&
       & ZCH    ,&
       & ZC1    , ZC2    , PCT    , ZEMIS  , PFCHSP , PFCLL  ,&
       & PFCLN  ,&
       & PFCS   , ZFEVI  , PFEVL  , PFEVN  , PFEVV  , PFTR   ,&
       & PFLWSP , PFONTE , PSP_SG(1,YSP_SG%YT%MP1), PFGEL  , PFGELS ,&
       & PFRSODS, PFRSOPT, PFRTHDS, &
       & ZFTKE  , PGZ0   , PGZ0H  , ZNEIJ  , ZVEG   , PQS,&
       & ZQSATS , PRUISL , PRUISP , PRUISS , PUCLS  , PVCLS  ,&
       & PTCLS  ,&
       & PQCLS  , PRHCLS , PCLCT  , PCLCH  , PCLCM  , PCLCL  ,&
       & ICLPH  , PCLPH  , PUGST  , PVGST  ,&
       & ZTENDPTKE, &
       & PDERNSHF,&
       & 'HL_APLPAR' )

      !-------------------------------------------------
      ! Extract Single Column Model profiles.
      !-------------------------------------------------

      IF(LGSCM) CALL WRITEPHYSIO &
       & (KEND, &
       & KST, KGL1, KGL2, KSTGLO, &
       & PGELAM, PGEMU, &
       & PGM, ZMU0, POROG, POROGL, POROGM, PRCORI, PRATATH, PRATATX, &
       & PSD_VF(1,YSD_VF%YLSM%MP ), PSD_VV(1,YSD_VV%YARG%MP), PSD_VV(1,YSD_VV%YSAB%MP), PSD_VF(1,YSD_VF%YALBF%MP), &
       & PSD_VF(1,YSD_VF%YALBSF%MP), PSD_VF(1,YSD_VF%YEMISF%MP), PSD_VV(1,YSD_VV%YD2%MP), PSD_VV(1,YSD_VV%YIVEG%MP), &
       & PSD_VV(1,YSD_VV%YLAI%MP), PCT, PSD_VF(1,YSD_VF%YZ0F%MP), PSD_VV(1,YSD_VV%YZ0H%MP), PSD_VF(1,YSD_VF%YZ0RLF%MP), &
       & PSD_VF(1,YSD_VF%YGETRL%MP), PSD_VF(1,YSD_VF%YVRLAN%MP), PSD_VF(1,YSD_VF%YVRLDI%MP), PSD_VV(1,YSD_VV%YRSMIN%MP), &
       & PSD_VF(1,YSD_VF%YVEG%MP), PSD_VV(1,YSD_VV%YHV%MP), PSD_VA(1,YSD_VA%YSEA%MP), PSD_VA(1,YSD_VA%YLAN%MP), &
       & PSD_VA(1,YSD_VA%YSOO%MP), PSD_VA(1,YSD_VA%YDES%MP), PSD_VC(1,YSD_VC%YVC(1)%MP), &
       & PSPT0, PSPT0L, PSPT0M, PTT0, PTT0L, PTT0M, PQT0, PQT0L, PQT0M, &
       & PUT0, PVT0, PVORT0, PDIVT0, ZCVGQ, ZLCVQ, &
       & PSP_RR(1,YSP_RR%YT%MP9), PSP_SB(1,1,YSP_SB%YT%MP9), PSP_RR(1,YSP_RR%YFC%MP9), PSP_RR(1,YSP_RR%YW%MP9), &
       & PSP_RR(1,YSP_RR%YIC%MP9), PSP_SB(1,1,YSP_SB%YQ%MP9), PSP_SB(1,1,YSP_SB%YTL%MP9), PSP_SG(1,YSP_SG%YF%MP9), &
       & PDIFCQ, PDIFCQI, PDIFCQL, PDIFCS, PDIFTQ, PDIFTQI, PDIFTQL, &
       & PDIFTS, PFCCQL, PFCCQN, PFCSQL, PFCSQN, PFCQNG, PFCQING, &
       & PFCQLNG, PFPLCL, PFPLCN, PFPLSL, PFPLSN, PFRSO, PFRTH, &
       & PSTRCU, PSTRCV, PSTRDU, PSTRDV, PSTRTU, PSTRTV, PSTRMU, PSTRMV, &
       & PFRMH, PFCHOZ, PNEB, PQICE, PQLI, PRH, &
       & PFCS, PFCLL, PFCLN, PFEVL, PFEVN, PFEVV, PFTR, PFLWSP, PFONTE, &
       & PFGEL, PFGELS, PFRSODS, PFRSOPS, PFRSOPT, PFRTHDS, &
       & PQS, PRUISL, PRUISP, PRUISS, &
       & PUCLS, PVCLS, PTCLS, PQCLS, PRHCLS, &
       & PCLCT, PCLCH, PCLCM, PCLCL, PCLCC, &
       & ZFPLCH, ZFPLSH, &
       & PSD_VH(1,YSD_VH%YTCCH%MP),  PSD_VH(1,YSD_VH%YSCCH%MP), PSD_VH(1,YSD_VH%YBCCH%MP), PSD_VH(1,YSD_VH%YPBLH%MP) )

    ELSE

      ITDIA=1_JPRB
      CALL HL_APLPAR ( KST    , KEND   , NPROMA ,&
       & ITDIA  , NFLEVG  ,&
       & NVCLIS , YSD_VVD%NUMFLDS ,&
       & NSTEP  ,&
       & NTSSG  , YSP_SBD%NLEVS   ,&
       & KBL    , KGPCOMP,&
       & PVVEL0 ,&
       & PHI0  , PRE0  , PHIF0 , PRE0F , PALPH0 , PSD_VV(1,YSD_VV%YARG%MP)   ,&
       & PSD_VV(1,YSD_VV%YD2%MP)    ,&
       & PDELP0(1,1),PSD_VV(1,YSD_VV%YIVEG%MP),PSD_VV(1,YSD_VV%YLAI%MP)   , PLNPR0 ,&
       & PRDELP0,&
       & PSD_VV(1,YSD_VV%YRSMIN%MP) , PSD_VV(1,YSD_VV%YSAB%MP  ) ,&
       & PSD_VV(1,YSD_VV%YZ0H%MP  ), PRCORI          ,&
       & PUT0   , PVT0   , PTT0   , PQT0   , PIT0   , PLT0   ,&
       & PST0   , PRT0   , PTKET0 ,  PCVVT0 ,&
       & PCLF0  , PQVAT0 , & 
       & PO3T0  ,&
       & PCP0   , ZCVGQ  , ZCVGQL , ZCVGQI  , ZCVGT  , PR0    , PKOZO  ,&
       & ZFPLCH , ZFPLSH ,&
       & PTENDU , PTENDV , ZTENDT , ZTENDTKE, ZTENDQ , &
       & ZTENDQL, ZTENDQI, ZTENDH , &
       & PENTCH , PUNEBH ,&
       & PSD_VH(1,YSD_VH%YTCCH%MP  ) ,  PSD_VH(1,YSD_VH%YSCCH%MP  ) , PSD_VH(1,YSD_VH%YBCCH%MP  ) ,&
       & PSD_VH(1,YSD_VH%YSPSH%MP  ) ,PSD_VH(1,YSD_VH%YPBLH%MP  ) , &
       & PGPAR , &
       & PSP_SG(1,YSP_SG%YF%MP0) , PSP_SG(1,YSP_SG%YA%MP0), PSP_SG(1,YSP_SG%YR%MP0),&
       & PSP_SB(1,1,YSP_SB%YT%MP0 ) , PSP_RR(1,YSP_RR%YT%MP0 ) , PSP_RR(1,YSP_RR%YFC%MP0) ,&
       & PSP_SB(1,1,YSP_SB%YQ%MP0 ) , PSP_SB(1,1,YSP_SB%YTL%MP0), PSP_RR(1,YSP_RR%YW%MP0)  ,&
       & PSP_RR(1,YSP_RR%YIC%MP0),&
       & PSD_VV(1,YSD_VV%YHV%MP)    ,&
       & PSD_VV(1,YSD_VV%YALV%MP )  ,&
       & PSD_VF(1,YSD_VF%YALBF%MP ) , PSD_VF(1,YSD_VF%YALBSF%MP) , PSD_VF(1,YSD_VF%YEMISF%MP) ,&
       & PSD_VF(1,YSD_VF%YGETRL%MP) , PSD_VF(1,YSD_VF%YLSM%MP  ) , PSD_VF(1,YSD_VF%YVEG%MP  ) ,&
       & PSD_VF(1,YSD_VF%YZ0F%MP  ) , PSD_VF(1,YSD_VF%YZ0RLF%MP ),&
       & PSD_VF(1,YSD_VF%YVRLAN%MP) , PSD_VF(1,YSD_VF%YVRLDI%MP) , PSD_VC(1,YSD_VC%YVC(1)%MP)  ,&
       & ZMU0   , PGELAM, PGEMU  , &
       & POROG  , &
       & PDIFCQ , PDIFCQI, PDIFCQL, PDIFCS , PDIFTQ , PDIFTQI,&
       & PDIFTQL,&
       & PDIFTS , PFCCQL , PFCCQN , PFCSQL , PFCSQN , &
       & PFPLCL , PFPLCN , PFPLSL , PFPLSN , PFRSO  ,&
       & PFRTH  , PSTRCU , PSTRCV , PSTRDU , PSTRDV ,&
       & PSTRTU ,&
       & PSTRTV , PSTRMU , PSTRMV , PFRMH  , ZFRMQ  , PFCHOZ ,&
       & ZCPS   , ZLHS   ,&
       & ZRS    , ZLH    , ZLSCPE , PNEB   , PQICE  , PQLI   ,&
       & ZQSAT  ,&
       & ZQW    , PRH    , ZTW    , PALB   , ZCD    , ZCDN   ,&
       & ZCH    ,&
       & ZC1    , ZC2    , PCT    , ZEMIS  , PFCHSP , PFCLL  ,&
       & PFCLN  ,&
       & PFCS   , ZFEVI  , PFEVL  , PFEVN  , PFEVV  , PFTR   ,&
       & PFLWSP , PFONTE , PSP_SG(1,YSP_SG%YT%MP1), PFGEL  , PFGELS ,&
       & PFRSODS, PFRSOPT, PFRTHDS, &
       & ZFTKE  , PGZ0   , PGZ0H  , ZNEIJ  , ZVEG   , PQS,&
       & ZQSATS , PRUISL , PRUISP , PRUISS , PUCLS  , PVCLS  ,&
       & PTCLS  ,&
       & PQCLS  , PRHCLS , PCLCT  , PCLCH  , PCLCM  , PCLCL  ,&
       & ICLPH  , PCLPH  , PUGST  , PVGST  ,&
       & ZTENDPTKE, &
       & PDERNSHF,&
       & 'HL_APLPAR' )

    ENDIF
  ENDIF
ENDIF

!        2.3  Computes MOCON in the CLP.
!             --------------------------

IF (LLDIAB.AND.(.NOT.LDLADNMI).AND.(.NOT.LMPA)) THEN

  PMOCON(KST:KEND)=0.0_JPRB
  IF (LTWOTL) THEN
    DO JLEV=1,NFLEVG
      DO JROF = KST, KEND
        PMOCON(JROF) = PMOCON(JROF)+(ZLCVQ(JROF,JLEV)-PQT0(JROF,JLEV)*&
         & PDIVT0(JROF,JLEV))*PDELP0(JROF,JLEV)&
         & *MAX(0,SIGN(1,JLEV-ICLPH(JROF)))  
      ENDDO
    ENDDO
    DO JROF = KST, KEND
      PMOCON(JROF) = PMOCON(JROF)/(PRE0(JROF,NFLEVG)-PRE0(JROF,ICLPH(JROF)-1))
    ENDDO
  ELSE
    DO JLEV=1,NFLEVG
      DO JROF = KST, KEND
        PMOCON(JROF) = PMOCON(JROF)+(ZLCVQ(JROF,JLEV)-PQT9(JROF,JLEV)*&
         & PDIVT0(JROF,JLEV))*PDELP9(JROF,JLEV)&
         & *MAX(0,SIGN(1,JLEV-ICLPH(JROF)))  
      ENDDO
    ENDDO
    DO JROF = KST, KEND
      PMOCON(JROF) = PMOCON(JROF)/(PRE9(JROF,NFLEVG)-PRE9(JROF,ICLPH(JROF)-1))
    ENDDO
  ENDIF
ENDIF

!        2.4  Stores radiation coefficients.
!             ------------------------------

! * transforms grid-point into Fourier transmission coefficients
!   for simplified physics.

IF (LL_CALL_CPPFTTCDIR) THEN
  CALL CPPFTTCDIR(KGL3,KGL4,KOFF,&
   & RBASCOTC(1,KOFF),RBASSITC(1,KOFF),&
   & ZRAB3C,ZRAB4C,ZRAB6C,ZRAB3N,ZRAB4N,ZRAB6N,&
   & ZRAT1C,ZRAT2C,ZRAT3C,ZRAT4C,ZRAT5C,&
   & ZRAT1N,ZRAT2N,ZRAT3N,ZRAT4N,ZRAT5N,&
   & ZCOR,ZAC,&
   & RFORAB3C(1,0,KGL3),RFORAB4C(1,0,KGL3),RFORAB6C(1,0,KGL3),&
   & RFORAB3N(1,0,KGL3),RFORAB4N(1,0,KGL3),RFORAB6N(1,0,KGL3),&
   & RFORAT1C(1,0,KGL3),RFORAT2C(1,0,KGL3),RFORAT3C(1,0,KGL3),&
   & RFORAT4C(1,0,KGL3),RFORAT5C(1,0,KGL3),&
   & RFORAT1N(1,0,KGL3),RFORAT2N(1,0,KGL3),RFORAT3N(1,0,KGL3),&
   & RFORAT4N(1,0,KGL3),RFORAT5N(1,0,KGL3),&
   & RFOCOR(1,0,KGL3),RFOAC(1,0,KGL3))  
ENDIF

! * writes grid-point transmission coefficients
!   for simplified physics.

IF (LRCOEF.AND.(NSTEP == 1).AND.LLDIAB.AND.(.NOT.LDLADNMI) &
   & .AND.(.NOT.LMPA)) THEN
  IFIELDSS=NG3SR*NFLEVG
  IFIELDST=NGMTR*(NFLEVG+1)
  CALL WRRADCOEF(KST,KEND,KSTGLO,IFIELDSS,&
   & ZRAB3C,ZRAB3N,ZRAB4C,ZRAB4N,ZRAB6C,ZRAB6N,&
   & ZRAT1C,ZRAT1N,ZRAT2C,ZRAT2N,ZRAT3C,ZRAT3N,&
   & ZRAT4C,ZRAT4N,ZRAT5C,ZRAT5N,ZCOR,ZAC_HC)  
ENDIF

!       2.5   Ozone
!             -----

IF (LLDIAB.AND.(.NOT.LDLADNMI).AND.LOZONE.AND.(.NOT.LMPA)) THEN
  ! * Caution: this part has not been yet validated relative
  !   to the GFL implementation, and LOZONE (the setup of
  !   which has not yet been updated) can be true only if
  !   the GFL ozone is activated as a prognostic and advected
  !   variable.
  IPO3=(YO3%MP-1)*(NFLEVG+2*NFLSUL)
  IF (LSLAG) THEN
    IF (LTWOTL) THEN
      CALL CPOZO (NPROMA,KST,KEND,NFLEVG,PDTPHY,PFCHOZ,&
       & PB1(1,MSLB1GFL9+IPO3+1-NFLSA),PRDELP0)  
    ELSE
      CALL CPOZO (NPROMA,KST,KEND,NFLEVG,PDTPHY,PFCHOZ,&
       & PB1(1,MSLB1GFL9+IPO3+1-NFLSA),PRDELP9)  
    ENDIF
  ELSE
    CALL CPOZO (NPROMA,KST,KEND,NFLEVG,PDTPHY,PFCHOZ,&
     & PGFLT1(1,1,YO3%MP1),PRDELP9)
  ENDIF
ENDIF

!        2.6   surface specific humidity necessary to compute the vertical
!              advection of q in the case "delta m=1" (unlagged physics only).
!              ---------------------------------------------------------------

IF (LLDIAB.AND.(.NOT.LDLADNMI).AND.(NDPSFI == 1)) THEN
  CALL CPQSOL(NPROMA,KST,KEND,PRE0,PSP_RR(1,YSP_RR%YT%MP0),PQS,ZQSATS,PQSOL)
ENDIF

!        2.7  Computation of tendencies T,u,v and Q.
!             --------------------------------------

IF (LLDIAB.AND.(.NOT.LDLADNMI).AND.(.NOT.LSIMPH).AND.(.NOT.LMPA)) THEN

  TSPHY = MAX(PDTPHY,1.0_JPRB)

  ! * CPTEND+CPUTQY = Old( CPATY + CPDUP + CPDTHP )
  ! Calcul des tendances de T , U et de Q et modifications
  ! eventuelles de W et de OMEGA/P

  IF (LTWOTL) THEN

    IF ( .NOT.LHL ) THEN

      CALL CPTEND_NEW( NPROMA, KST, KEND, NFLEVG,&
       & PDIFCQ , PDIFCQI, PDIFCQL, PDIFCS ,&
       & PDIFTQ , PDIFTQI, PDIFTQL, PDIFTS ,&
       & PFCCQL , PFCCQN , PFCSQL , PFCSQN ,&
       & PFPLSL , PFPLSN , PFPLCL,  PFPLCN, &
       & PFPEVPSL,PFPEVPSN,PFPEVPCL,PFPEVPCN,&
       & PFPFPSL, PFPFPSN, PFPFPCL ,PFPFPCN ,&
       & PFCQLNG, PFCQING, PFCQRNG, PFCQSNG, &
       & PFCQNG , PFRMH  , PFRSO  , PFRTH  ,&
       & PSTRCU , PSTRCV , PSTRDU , PSTRDV ,&
       & PSTRTU , PSTRTV , PSTRMU , PSTRMV ,&
       & ZFTKE  ,&
       & PRDELP0, PHIF0  , PCP0   ,&
       & PUT0   , PVT0   , PTT0   ,&
       & PQT0   , PIT0   , PLT0   ,&
       & PRT0   , PST0   ,&
       & ZCPS   , PSP_RR(1,YSP_RR%YT%MP0)  ,&
       & PFHSCL ,PFHSCN,PFHSSL,PFHSSN,&
       & PFHPCL ,PFHPCN,PFHPSL,PFHPSN,&
       & ZFHP   ,ZFP   ,  PFEPFP, PFCMPCQ, PFCMPSN, PFCMPSL,&
       & PTENDU , PTENDV , ZTENDH ,&
       & ZTENDQ , ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
       & ZTENDTKE )

    ELSE

      CALL CPFHPFS( NPROMA, KST, KEND, NFLEVG,&
       & PFCCQL , PFCCQN , PFCSQL , PFCSQN ,&
       & PFPLCL , PFPLCN , PFPLSL , PFPLSN ,&
       & PFPEVPSL,PFPEVPSN,&
       & PCP0   , PTT0   ,&
       & ZCPS   , PSP_RR(1,YSP_RR%YT%MP0)  ,&
       & PFHSCL , PFHSCN , PFHSSL , PFHSSN ,&
       & PFHPCL , PFHPCN , PFHPSL , PFHPSN ,&
       & ZFHP   , ZFP    , ZFEPFP )  

      CALL CPTEND( NPROMA, KST, KEND, NFLEVG,&
       & PDIFCQ , PDIFCQI, PDIFCQL, PDIFCS ,&
       & PDIFTQ , PDIFTQI, PDIFTQL, PDIFTS ,&
       & PFCCQL , PFCCQN , PFCSQL , PFCSQN ,&
       & PFPLCL , PFPLCN , PFPLSL , PFPLSN ,&
       & PFPFPSL, PFPFPSN, PFPFPCL, PFPFPCN,&
       & PFPEVPSL,PFPEVPSN,PFPEVPCL,PFPEVPCN,&
       & PFRMH  , PFRSO  , PFRTH  , ZFTKE  ,&
       & ZFHP   , ZFP    ,&
       & PSTRCU , PSTRCV , PSTRDU , PSTRDV ,&
       & PSTRTU , PSTRTV , PSTRMU , PSTRMV ,&
       & PRDELP0, &
       & PQT0   , PIT0   , PLT0   ,&
       & PQS    , &
       & PTENDU , PTENDV , ZTENDH ,&
       & ZTENDQ , ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
       & ZTENDTKE, ZTENDT )  

    ENDIF  ! .NOT.LHL

  ELSE

    IF ( .NOT.LHL ) THEN

      CALL CPTEND_NEW( NPROMA, KST, KEND, NFLEVG,&
       & PDIFCQ , PDIFCQI, PDIFCQL, PDIFCS ,&
       & PDIFTQ , PDIFTQI, PDIFTQL, PDIFTS ,&
       & PFCCQL , PFCCQN , PFCSQL , PFCSQN ,&
       & PFPLSL , PFPLSN , PFPLCL,  PFPLCN, &
       & PFPEVPSL,PFPEVPSN,PFPEVPCL,PFPEVPCN,&
       & PFPFPSL, PFPFPSN, PFPFPCL ,PFPFPCN, &
       & PFCQLNG, PFCQING, PFCQRNG, PFCQSNG, &
       & PFCQNG , PFRMH  , PFRSO  , PFRTH  ,&
       & PSTRCU , PSTRCV , PSTRDU , PSTRDV ,&
       & PSTRTU , PSTRTV , PSTRMU , PSTRMV ,&
       & ZFTKE  ,&
       & PRDELP9, PHIF9  , PCP9   ,&
       & PUT9   , PVT9   , PTT9   ,&
       & PQT9   , PIT9   , PLT9   ,&
       & PRT9   , PST9   ,&
       & ZCPS   , PSP_RR(1,YSP_RR%YT%MP9 ),&
       & PFHSCL ,PFHSCN,PFHSSL,PFHSSN,&
       & PFHPCL ,PFHPCN,PFHPSL,PFHPSN,&
       & ZFHP   ,ZFP   ,  PFEPFP, PFCMPCQ, PFCMPSN, PFCMPSL,&
       & PTENDU , PTENDV , ZTENDH ,&
       & ZTENDQ , ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
       & ZTENDTKE )

    ELSE

      CALL CPFHPFS( NPROMA, KST, KEND, NFLEVG,&
       & PFCCQL , PFCCQN , PFCSQL , PFCSQN ,&
       & PFPLCL , PFPLCN , PFPLSL , PFPLSN ,&
       & PFPEVPSL,PFPEVPSN,&
       & PCP9   , PTT9   ,&
       & ZCPS   , PSP_RR(1,YSP_RR%YT%MP9 ) ,&
       & PFHSCL , PFHSCN , PFHSSL , PFHSSN ,&
       & PFHPCL , PFHPCN , PFHPSL , PFHPSN ,&
       & ZFHP   , ZFP    , ZFEPFP )  

      CALL CPTEND( NPROMA, KST, KEND, NFLEVG,&
       & PDIFCQ , PDIFCQI, PDIFCQL, PDIFCS ,&
       & PDIFTQ , PDIFTQI, PDIFTQL, PDIFTS ,&
       & PFCCQL , PFCCQN , PFCSQL , PFCSQN ,&
       & PFPLCL , PFPLCN , PFPLSL , PFPLSN ,&
       & PFPFPSL, PFPFPSN, PFPFPCL, PFPFPCN,&
       & PFPEVPSL,PFPEVPSN,PFPEVPCL,PFPEVPCN,&
       & PFRMH  , PFRSO  , PFRTH  , ZFTKE  ,&
       & ZFHP   , ZFP    ,&
       & PSTRCU , PSTRCV , PSTRDU , PSTRDV ,&
       & PSTRTU , PSTRTV , PSTRMU , PSTRMV ,&
       & PRDELP9, &
       & PQT9   , PIT9   , PLT9   ,&
       & PQS    ,&
       & PTENDU , PTENDV , ZTENDH ,&
       & ZTENDQ , ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
       & ZTENDTKE, ZTENDT )  

    ENDIF  ! .NOT.LHL

    IF ( L3MT.OR.LSTRAPRO.OR.(NDPSFI==1)) THEN
!     PFEPFP was ZFEPFP in CPTEND_NEW, before, ZFEPFP still in CPFHPFS
      DO JLEV= 0, NFLEVG 
        DO JROF = 1, NPROMA
          PFEPFP(JROF,JLEV) = 0.0_JPRB
          PFCMPCQ(JROF,JLEV) = 0.0_JPRB
          PFCMPSN(JROF,JLEV) = 0.0_JPRB
          PFCMPSL(JROF,JLEV) = 0.0_JPRB
        ENDDO
      ENDDO
    ENDIF

  ENDIF


!        2.7.1  Diagnostics on physical tendencies
!               ----------------------------------

  IF (CDCONF /= 'X') THEN
    IF ((GCHETN%LFREQD).OR.(GCHETN%LCOORD).OR.(GCHETN%LPROFV)) THEN
      IF (LTWOTL) THEN
        CALL CPCHET(  NPROMA, KST, KEND, NFLEVG, NSTEP,&
        & PFHSCL , PFHSCN , PFHSSL , PFHSSN ,&
        & PFHPCL , PFHPCN , PFHPSL , PFHPSN ,&
        & PDIFCQ , PDIFCQI, PDIFCQL, PDIFCS ,&
        & PDIFTQ , PDIFTQI, PDIFTQL, PDIFTS ,&
        & PFCCQL , PFCCQN , PFCSQL , PFCSQN ,&
        & PFPLCL , PFPLCN , PFPLSL , PFPLSN ,&
        & PFPFPSL, PFPFPSN, PFPFPCL, PFPFPCN,&
        & PFPEVPSL,PFPEVPSN,PFPEVPCL,PFPEVPCN,&
        & PFRMH  , PFRSO  , PFRTH  ,         &
        & PSTRCU , PSTRCV , PSTRDU , PSTRDV ,&
        & PSTRTU , PSTRTV , PSTRMU , PSTRMV ,&
        & PRDELP0, PCP0   ,                  &
        & PTT0   , PQT0   , PIT0   , PLT0   ,&
        & ZCPS   , PSP_RR(1,YSP_RR%YT%MP0 ) , PQS  , &
        & PTENDU , PTENDV , ZTENDH , ZTENDQ , ZTENDQI, ZTENDQL,&
        & ZTENDQR, ZTENDQS,&
        & PGEMU  , PGELAM , PHI0   , PHIF0  )
      ELSE
        CALL CPCHET(  NPROMA, KST, KEND, NFLEVG, NSTEP,&
        & PFHSCL , PFHSCN , PFHSSL , PFHSSN ,&
        & PFHPCL , PFHPCN , PFHPSL , PFHPSN ,&
        & PDIFCQ , PDIFCQI, PDIFCQL, PDIFCS ,&
        & PDIFTQ , PDIFTQI, PDIFTQL, PDIFTS ,&
        & PFCCQL , PFCCQN , PFCSQL , PFCSQN ,&
        & PFPLCL , PFPLCN , PFPLSL , PFPLSN ,&
        & PFPFPSL, PFPFPSN, PFPFPCL, PFPFPCN,&
        & PFPEVPSL,PFPEVPSN,PFPEVPCL,PFPEVPCN,&
        & PFRMH  , PFRSO  , PFRTH  ,         &
        & PSTRCU , PSTRCV , PSTRDU , PSTRDV ,&
        & PSTRTU , PSTRTV , PSTRMU , PSTRMV ,&
        & PRDELP9, PCP9   ,                  &
        & PTT9   , PQT9   , PIT9   , PLT9   ,&
        & ZCPS   , PSP_RR(1,YSP_RR%YT%MP9)  , PQS    , &
        & PTENDU , PTENDV , ZTENDH , ZTENDQ , ZTENDQI, ZTENDQL,&
        & ZTENDQR, ZTENDQS,&
        & PGEMU  , PGELAM , PHI9   , PHIF9  )
      ENDIF
    ENDIF
    
    IF (GCHETN%LPROFV) &
     & CALL PROFILECHET &
     & (KEND, &
     & PGELAM, PGEMU, &
     & PGM, ZMU0, POROG, POROGL, POROGM, PRCORI, PRATATH, PRATATX, &
     & PSD_VF(1,YSD_VF%YLSM%MP ), PSD_VV(1,YSD_VV%YARG%MP), PSD_VV(1,YSD_VV%YSAB%MP), PSD_VF(1,YSD_VF%YALBF%MP), &
     & PSD_VF(1,YSD_VF%YALBSF%MP), PSD_VF(1,YSD_VF%YEMISF%MP), PSD_VV(1,YSD_VV%YD2%MP), PSD_VV(1,YSD_VV%YIVEG%MP), &
     & PSD_VV(1,YSD_VV%YLAI%MP), PCT, PSD_VF(1,YSD_VF%YZ0F%MP), PSD_VV(1,YSD_VV%YZ0H%MP), PSD_VF(1,YSD_VF%YZ0RLF%MP), &
     & PSD_VF(1,YSD_VF%YGETRL%MP), PSD_VF(1,YSD_VF%YVRLAN%MP), PSD_VF(1,YSD_VF%YVRLDI%MP), PSD_VV(1,YSD_VV%YRSMIN%MP), &
     & PSD_VF(1,YSD_VF%YVEG%MP), PSD_VV(1,YSD_VV%YHV%MP), PSD_VA(1,YSD_VA%YSEA%MP), PSD_VA(1,YSD_VA%YLAN%MP), &
     & PSD_VA(1,YSD_VA%YSOO%MP), PSD_VA(1,YSD_VA%YDES%MP), PSD_VC(1,YSD_VC%YVC(1)%MP), &
     & PSPT0, PSPT0L, PSPT0M, PTT0, PTT0L, PTT0M, PQT0, PQT0L, PQT0M, &
     & PUT0, PVT0, PVORT0, PDIVT0, ZCVGQ, ZLCVQ, &
     & PSP_RR(1,YSP_RR%YT%MP9), PSP_SB(1,1,YSP_SB%YT%MP9), PSP_RR(1,YSP_RR%YFC%MP9), PSP_RR(1,YSP_RR%YW%MP9), &
     & PSP_RR(1,YSP_RR%YIC%MP9), PSP_SB(1,1,YSP_SB%YQ%MP9), PSP_SB(1,1,YSP_SB%YTL%MP9), PSP_SG(1,YSP_SG%YF%MP9), &
     & PDIFCQ, PDIFCQI, PDIFCQL, PDIFCS, PDIFTQ, PDIFTQI, PDIFTQL, &
     & PDIFTS, PFCCQL, PFCCQN, PFCSQL, PFCSQN, PFCQNG, PFCQING, &
     & PFCQLNG, PFPLCL, PFPLCN, PFPLSL, PFPLSN, PFRSO, PFRTH, &
     & PSTRCU, PSTRCV, PSTRDU, PSTRDV, PSTRTU, PSTRTV, PSTRMU, PSTRMV, &
     & PFRMH, PFCHOZ, PNEB, PQICE, PQLI, PRH, &
     & PFCS, PFCLL, PFCLN, PFEVL, PFEVN, PFEVV, PFTR, PFLWSP, PFONTE, &
     & PFGEL, PFGELS, PFRSODS, PFRSOPS, PFRSOPT, PFRTHDS, &
     & PQS, PRUISL, PRUISP, PRUISS, &
     & PUCLS, PVCLS, PTCLS, PQCLS, PRHCLS, &
     & PCLCT, PCLCH, PCLCM, PCLCL, PCLCC, &
     & ZFPLCH, ZFPLSH, &
     & PSD_VH(1,YSD_VH%YTCCH%MP),  PSD_VH(1,YSD_VH%YSCCH%MP), PSD_VH(1,YSD_VH%YBCCH%MP), PSD_VH(1,YSD_VH%YPBLH%MP) )

  ENDIF

ENDIF

!        2.8  Modification of vertical velocities
!             by some physics output when required.
!             -------------------------------------

IF (LLDIAB.AND.(.NOT.LDLADNMI).AND.(.NOT.LSIMPH)) THEN

  ! * MODIFICATION DE LA VITESSE VERTICALE ET DE LA TENDANCE DE
  ! PRESSION DE SURFACE SI NDPSFI=1 ( MASSE VARIABLE ).
  ! Ajout de la physique dans l'equation de continuite/Add physics
  ! in continuity equation.

  IF (NDPSFI == 1) THEN
    IF (LSLAG .AND. LTWOTL) THEN
      CALL CPMVVPS(LVERCOR,NPROMA,NPROMVC,KST,KEND,NFLEVG,PDTPHY,&
       & PVCASRS0H,ZFP,PRE0(1,NFLEVG),PFEVL,PFEVN,&
       & PEVEL0,PSDVBC0,PSDFI0,PB1(1,MSLB1SP9))
    ELSEIF (LSLAG .AND. (.NOT.LTWOTL)) THEN
      CALL CPMVVPS(LVERCOR,NPROMA,NPROMVC,KST,KEND,NFLEVG,PDTPHY,&
       & PVCASRS0H,ZFP,PRE9(1,NFLEVG),PFEVL,PFEVN,&
       & PEVEL0,PSDVBC0,PSDFI0,PB1(1,MSLB1SP9))
    ELSE
      CALL CPMVVPS(LVERCOR,NPROMA,NPROMVC,KST,KEND,NFLEVG,PDTPHY,&
       & PVCASRS0H,ZFP,PRE9(1,NFLEVG),PFEVL,PFEVN,&
       & PEVEL0,PSDVBC0,PSDFI0,PGMVT1S(1,YT1%MSP))
    ENDIF
  ENDIF

ENDIF

!        2.9  Computation of evolution of T, u, v and Q.
!             ------------------------------------------

! * Calculation of IPQ,IPL,IPI, since the old pointers
!   MSLB1[X]9 (=MSLB1GFL9+IP[X]) do not exist any longer in PTRSLB1.
!   (In the future, CPTEND, CPTENDSM, CPUTQY and CPUTQYS must be
!   rewritten in order to treat the GFL globally and not
!   individually).

IPQ=(YQ%MP_SL1-1)*(NFLEVG+2*NFLSUL)
IPL=(YL%MP_SL1-1)*(NFLEVG+2*NFLSUL)
IPI=(YI%MP_SL1-1)*(NFLEVG+2*NFLSUL)
IPS=(YS%MP_SL1-1)*(NFLEVG+2*NFLSUL)
IPR=(YR%MP_SL1-1)*(NFLEVG+2*NFLSUL)
IPG=(YG%MP_SL1-1)*(NFLEVG+2*NFLSUL)
IPH=(YH%MP_SL1-1)*(NFLEVG+2*NFLSUL)
IPTKE=(YTKE%MP_SL1-1)*(NFLEVG+2*NFLSUL)
IPEXT=(YEXT(1)%MP_SL1-1)*(NFLEVG+2*NFLSUL)

IF (LLDIAB.AND.(.NOT.LDLADNMI).AND.(.NOT.LSIMPH).AND.(.NOT.LMPA)) THEN

  ! Calcul de T , Q et du Vent a l'instant 1
  IF (LSLAG) THEN
    IF (LTWOTL) THEN
      IF (LDLADVL.AND.LDLADVI) THEN
        IF (LDLADVR.AND.LDLADVS) THEN
          IF (LDLADVTKE) THEN
             CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
           & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
           & ZTENDPTKE, PTENDU, PTENDV,&
           & ZTENDTKE, ZTENDT, &
           & PCP0, PDELP0(1,1), PTT0, PUT0, PVT0,&
           & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPI+1-NFLSA),PB1(1,MSLB1GFL9+IPL+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPR+1-NFLSA),PB1(1,MSLB1GFL9+IPS+1-NFLSA),&
           & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPTKE+1-NFLSA)) 
           ELSE
             CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
           & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
           & ZTENDPTKE, PTENDU, PTENDV,&
           & ZTENDTKE, ZTENDT, &
           & PCP0, PDELP0(1,1), PTT0, PUT0, PVT0,&
           & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPI+1-NFLSA),PB1(1,MSLB1GFL9+IPL+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPR+1-NFLSA),PB1(1,MSLB1GFL9+IPS+1-NFLSA),&
           & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
           & PGFLT1(1,1,YTKE%MP1))  
           ENDIF
        ELSE
          CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
           & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
           & ZTENDPTKE, PTENDU, PTENDV,&
           & ZTENDTKE, ZTENDT, &
           & PCP0, PDELP0(1,1), PTT0, PUT0, PVT0,&
           & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPI+1-NFLSA),PB1(1,MSLB1GFL9+IPL+1-NFLSA),&
           & PGFLT1(1,1,YR%MP1),PGFLT1(1,1,YS%MP1),&
           & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
           & PGFLT1(1,1,YTKE%MP1))  
        ENDIF
      ELSEIF ((.NOT.LDLADVL).AND.LDLADVI) THEN
        CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
         & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
         & ZTENDPTKE, PTENDU, PTENDV,&
         & ZTENDTKE, ZTENDT, &
         & PCP0, PDELP0(1,1), PTT0, PUT0, PVT0,&
         & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
         & PB1(1,MSLB1GFL9+IPI+1-NFLSA),PGFLT1(1,1,YL%MP1),&
         & PGFLT1(1,1,YR%MP1),PGFLT1(1,1,YS%MP1),&
         & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
         & PGFLT1(1,1,YTKE%MP1))  
      ELSEIF (LDLADVL.AND.(.NOT.LDLADVI)) THEN
        CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
         & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
         & ZTENDPTKE, PTENDU, PTENDV,&
         & ZTENDTKE, ZTENDT, &
         & PCP0, PDELP0(1,1), PTT0, PUT0, PVT0,&
         & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
         & PGFLT1(1,1,YI%MP1),PB1(1,MSLB1GFL9+IPL+1-NFLSA),&
         & PGFLT1(1,1,YR%MP1),PGFLT1(1,1,YS%MP1),&
         & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
         & PGFLT1(1,1,YTKE%MP1))  
      ELSE
        CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
         & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
         & ZTENDPTKE, PTENDU, PTENDV,&
         & ZTENDTKE, ZTENDT, &
         & PCP0, PDELP0(1,1), PTT0, PUT0, PVT0,&
         & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
         & PGFLT1(1,1,YI%MP1),PGFLT1(1,1,YL%MP1),&
         & PGFLT1(1,1,YR%MP1),PGFLT1(1,1,YS%MP1),&
         & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
         & PGFLT1(1,1,YTKE%MP1))  
      ENDIF
    ELSE
      IF (LDLADVL.AND.LDLADVI) THEN
        IF (LDLADVR.AND.LDLADVS) THEN
          IF (LDLADVTKE) THEN
            CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
           & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
           & ZTENDPTKE, PTENDU, PTENDV,&
           & ZTENDTKE, ZTENDT, &
           & PCP9, PDELP9(1,1), PTT9, PUT9, PVT9,&
           & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPI+1-NFLSA),PB1(1,MSLB1GFL9+IPL+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPR+1-NFLSA),PB1(1,MSLB1GFL9+IPS+1-NFLSA),&
           & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPTKE+1-NFLSA))
          ELSE
            CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
           & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
           & ZTENDPTKE, PTENDU, PTENDV,&
           & ZTENDTKE, ZTENDT, &
           & PCP9, PDELP9(1,1), PTT9, PUT9, PVT9,&
           & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPI+1-NFLSA),PB1(1,MSLB1GFL9+IPL+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPR+1-NFLSA),PB1(1,MSLB1GFL9+IPS+1-NFLSA),&
           & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
           & PGFLT1(1,1,YTKE%MP1))  
          ENDIF
        ELSE
          CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
           & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
           & ZTENDPTKE, PTENDU, PTENDV,&
           & ZTENDTKE, ZTENDT, &
           & PCP9, PDELP9(1,1), PTT9, PUT9, PVT9,&
           & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
           & PB1(1,MSLB1GFL9+IPI+1-NFLSA),PB1(1,MSLB1GFL9+IPL+1-NFLSA),&
           & PGFLT1(1,1,YR%MP1),PGFLT1(1,1,YS%MP1),&
           & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
           & PGFLT1(1,1,YTKE%MP1))  
        ENDIF
      ELSEIF ((.NOT.LDLADVL).AND.LDLADVI) THEN
        CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
         & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
         & ZTENDPTKE, PTENDU, PTENDV,&
         & ZTENDTKE, ZTENDT, &
         & PCP9, PDELP9(1,1), PTT9, PUT9, PVT9,&
         & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
         & PB1(1,MSLB1GFL9+IPI+1-NFLSA),PGFLT1(1,1,YL%MP1),&
         & PGFLT1(1,1,YR%MP1),PGFLT1(1,1,YS%MP1),&
         & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
         & PGFLT1(1,1,YTKE%MP1))  
     ELSEIF (LDLADVL.AND.(.NOT.LDLADVI)) THEN
        CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
         & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
         & ZTENDPTKE, PTENDU, PTENDV,&
         & ZTENDTKE, ZTENDT, &
         & PCP9, PDELP9(1,1), PTT9, PUT9, PVT9,&
         & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
         & PGFLT1(1,1,YI%MP1),PB1(1,MSLB1GFL9+IPL+1-NFLSA),&
         & PGFLT1(1,1,YR%MP1),PGFLT1(1,1,YS%MP1),&
         & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
         & PGFLT1(1,1,YTKE%MP1))  
      ELSE
        CALL CPUTQY( NPROMA, KST,KEND,NFLEVG, PDTPHY,&
         & ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
         & ZTENDPTKE, PTENDU, PTENDV,&
         & ZTENDTKE, ZTENDT, &
         & PCP9, PDELP9(1,1), PTT9, PUT9, PVT9,&
         & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
         & PGFLT1(1,1,YI%MP1),PGFLT1(1,1,YL%MP1),&
         & PGFLT1(1,1,YR%MP1),PGFLT1(1,1,YS%MP1),&
         & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
         & PGFLT1(1,1,YTKE%MP1))  
      ENDIF
    ENDIF
  ELSE
    CALL CPUTQY( NPROMA, KST,KEND, NFLEVG, PDTPHY,&
      &ZTENDH, ZTENDQ, ZTENDQI, ZTENDQL, ZTENDQR, ZTENDQS,&
      & ZTENDPTKE, PTENDU, PTENDV,&
      & ZTENDTKE, ZTENDT, &
      &PCP9, PDELP9(1,1), PTT9, PUT9, PVT9,&
      &PFDIS, PGMVT1(1,1,YT1%MT),  PGFLT1(1,1,YQ%MP1),&
      &PGFLT1(1,1,YI%MP1), PGFLT1(1,1,YL%MP1),&
      &PGFLT1(1,1,YR%MP1), PGFLT1(1,1,YS%MP1),&
      &PGMVT1(1,1,YT1%MU), PGMVT1(1,1,YT1%MV),&
      &PGFLT1(1,1,YTKE%MP1) )
  ENDIF
ENDIF

!        2.9a Evolution of precipitation fluxes
!             ------------------------------------------

IF(LNEBN.OR.LNEBR.OR.LRRGUST) THEN
  DO JLEV=1,NFLEVG
    DO JROF=KST,KEND
      PGFLT1(JROF,JLEV,YCPF%MP1)=ZFPLCH(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF
IF(LRRGUST) THEN
  DO JLEV=1,NFLEVG
    DO JROF=KST,KEND
      PGFLT1(JROF,JLEV,YSPF%MP1)=ZFPLSH(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

!        2.9b Evolution of humidity amplitude YQVA
!             (put values into the new time level,
!             to be swapped later in routine "scan2m"
!             Save cloud cover field.
!             --------------------------------------------

IF( LHL ) THEN
  DO JLEV=1,NFLEVG
    DO JROF=KST,KEND
      PGFLT1(JROF,JLEV,YQVA%MP1)=PQVAT0(JROF,JLEV)
      PGFLT1(JROF,JLEV,YA%MP)=PCLF0(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

!       2.9c Prognostic convection etc.
!            --------------------------

! TRANSFER NOT ADVECTED VARIABLES INTO PGFLT1
IF (LCVPRO) THEN
   IF (.NOT.YUAL%LADV) THEN
      PGFLT1(KST:KEND,1:NFLEVG,YUAL%MP1)=PUDAL(KST:KEND,1:NFLEVG)
      PGFLT1(KST:KEND,1:NFLEVG,YUOM%MP1)=PUDOM(KST:KEND,1:NFLEVG)
   ENDIF
   IF (LCDDPRO) THEN
    IF (.NOT.YDAL%LADV) THEN
      PGFLT1(KST:KEND,1:NFLEVG,YDAL%MP1)=PDDAL(KST:KEND,1:NFLEVG)
      PGFLT1(KST:KEND,1:NFLEVG,YDOM%MP1)=PDDOM(KST:KEND,1:NFLEVG)
    ENDIF
   ENDIF
ENDIF
IF (YUNEBH%LACTIVE.AND..NOT.YUNEBH%LADV)THEN
   PGFLT1(KST:KEND,1:NFLEVG,YUNEBH%MP1)=PUNEBH(KST:KEND,1:NFLEVG)
ENDIF
IF (YUEN%LACTIVE.AND..NOT.YUEN%LADV) THEN
   PGFLT1(KST:KEND,1:NFLEVG,YUEN%MP1)=PENTCH(KST:KEND,1:NFLEVG)
ENDIF

!        2.10  Surface variables.
!              ------------------

IF (LLDIAB.AND.(.NOT.LDLADNMI).AND.LMPHYS.AND.(.NOT.LMPA).AND.(.NOT.LMSE)) THEN

  CALL CPTENDS( NPROMA, KST, KEND, NFLEVG, YSP_SBD%NLEVS, PDTPHY,&
   & PFPLCL, PFPLSL, PFPLCN, PFPLSN,&
   & PFRSO, PFRTH,&
   & PSP_SG(1,YSP_SG%YA%MP1),PCT, ZC1, ZC2,&
   & PFCHSP, PFCLL, PFCLN, PFCS,&
   & ZFEVI,PFEVL, PFEVN,&
   & PFEVV, PFGEL, PFGELS, PFLWSP, PFONTE, PFTR,&
   & PSD_VF(1,YSD_VF%YLSM%MP), PSP_SG(1,YSP_SG%YR%MP1),&
   & PRUISL, PRUISP, PRUISS, PSP_SG(1,YSP_SG%YF%MP1), ZVEG,&
   & ZTDTS, ZTDTP, ZTDWS, ZTDWSI, ZTDWP, ZTDWPI, ZTDWL,&
   & ZTDSNS, ZTDALBNS, ZTDRHONS)  

  CALL CPWTS ( NPROMA, KST,KEND, YSP_SBD%NLEVS, PDTPHY,&
   & ZTDTS, ZTDTP, ZTDWS, ZTDWSI, ZTDWP, ZTDWPI, ZTDWL,&
   & ZTDSNS, ZTDALBNS, ZTDRHONS,&
   & PSD_VP(1,YSD_VP%YTPC%MP),PSD_VP(1,YSD_VP%YWPC%MP),PSD_VF(1,YSD_VF%YLSM%MP),PSD_VV(1,YSD_VV%YIVEG%MP),&
   & PSP_RR(1,YSP_RR%YT%MP1),PSP_SB(1,1,YSP_SB%YT%MP1),PSP_RR(1,YSP_RR%YW%MP1),&
   & PSP_RR(1,YSP_RR%YIC%MP1),&
   & PSP_SB(1,1,YSP_SB%YQ%MP1),PSP_SB(1,1,YSP_SB%YTL%MP1),PSP_RR(1,YSP_RR%YFC%MP1),&
   & PSP_SG(1,YSP_SG%YF%MP1),PSP_SG(1,YSP_SG%YA%MP1),PSP_SG(1,YSP_SG%YR%MP1))  

  IF(LNUDG)THEN

    ! * Calculation of IPQ since the old pointers
    !   MSLB1[X]9 (=MSLB1GFL9+IP[X]) do not exist any longer in PTRSLB1.
    IPQ=(YQ%MP_SL1-1)*(NFLEVG+2*NFLSUL)

    CALL CPNUDG ( NPROMA, KST,KEND, NFNUDG, NFLEVG, IBLK,&
     & XPNUDG,&
     & PSD_VA(1,YSD_VA%YNUD%MP),&
     & PSP_RR(1,YSP_RR%YT%MP1),PSP_RR(1,YSP_RR%YW%MP1),&
     & PSP_SB(1,1,YSP_SB%YQ%MP1),PSP_SG(1,YSP_SG%YF%MP1),& 
     & PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
     & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),&
     & PB1(1,MSLB1SP9),&
     & PTT0,PQT0,PUT0,PVT0,PRE0(1,NFLEVG),PGM,PSD_VF(1,YSD_VF%YLSM%MP))
  ENDIF

ENDIF

!        2.11 Evolution of SDSAT and CVV (GY)
!             --------------------------

IF(LCVPGY) THEN
  DO JLEV=1,NFLEVG
    DO JROF=KST,KEND
      PGFLT1(JROF,JLEV,YCVV%MP1)=PCVVT0(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

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

!*       3.    Simplified physics.
!              -------------------

!        3.1  Preliminary calculations necessary for simplified physics.
!             ----------------------------------------------------------

IF (.NOT.LDLADNMI) THEN

  ! * transforms Fourier into grid-point transmission coefficients
  !   for simplified physics.
  !   Can be called even if lsimph=.false. for validation, but output
  !   of CPPFTTCINV is needed only if lsimph=.true.

  IF (LDRETCFOU) THEN
    CALL CPPFTTCINV(KGL3,KGL4,KOFF,&
     & RBASCOTC(1,KOFF),RBASSITC(1,KOFF),&
     & RFORAB3C(1,0,KGL3),RFORAB4C(1,0,KGL3),RFORAB6C(1,0,KGL3),&
     & RFORAB3N(1,0,KGL3),RFORAB4N(1,0,KGL3),RFORAB6N(1,0,KGL3),&
     & RFORAT1C(1,0,KGL3),RFORAT2C(1,0,KGL3),RFORAT3C(1,0,KGL3),&
     & RFORAT4C(1,0,KGL3),RFORAT5C(1,0,KGL3),&
     & RFORAT1N(1,0,KGL3),RFORAT2N(1,0,KGL3),RFORAT3N(1,0,KGL3),&
     & RFORAT4N(1,0,KGL3),RFORAT5N(1,0,KGL3),&
     & RFOCOR(1,0,KGL3),RFOAC(1,0,KGL3),&
     & ZRAB3C,ZRAB4C,ZRAB6C,ZRAB3N,ZRAB4N,ZRAB6N,&
     & ZRAT1C,ZRAT2C,ZRAT3C,ZRAT4C,ZRAT5C,&
     & ZRAT1N,ZRAT2N,ZRAT3N,ZRAT4N,ZRAT5N,&
     & ZCOR,ZAC)  
    ! * Simplified physics now reads a horizontally-constant field for ZAC:
    !   take RFOAC(..,0,kgl3) to initialize ZAC_HC.
    DO JL2=1,NFLEVG+1
      DO JL1=1,NFLEVG+1
        IJL=JL1+(JL2-1)*(NFLEVG+1)
        ZAC_HC(JL2,JL1)=RFOAC(IJL,0,KGL3)
      ENDDO
    ENDDO
  ENDIF

ENDIF

IF (LSIMPH.AND.(.NOT.LDLADNMI)) THEN

  ! * read grid-point transmission coefficients
  !   for simplified physics.

  IF (LRAYSP.AND.LRCOEF.AND.(NSTEP > 1.OR.LTLADDIA)) THEN
    IFIELDSS=NG3SR*NFLEVG
    IFIELDST=NGMTR*(NFLEVG+1)
    CALL RDRADCOEF(KST,KEND,KSTGLO,IFIELDSS,&
     & ZRAB3C,ZRAB3N,ZRAB4C,ZRAB4N,ZRAB6C,ZRAB6N,&
     & ZRAT1C,ZRAT1N,ZRAT2C,ZRAT2N,ZRAT3C,ZRAT3N,&
     & ZRAT4C,ZRAT4N,ZRAT5C,ZRAT5N,ZCOR,ZAC_HC)  
  ENDIF

ENDIF

!        3.2  Simplified physics.
!             -------------------

IF (LSIMPH.AND.(.NOT.LDLADNMI)) THEN

  TSPHY = MAX(PDTPHY,1.0_JPRB)

  IF (LTWOTL) THEN

    CALL APLPASSH (KST,KEND,NPROMA,NFLEVG,&
     & PRE0,PQT0,&
     & PSP_SG(1,YSP_SG%YF%MP1),PSP_RR(1,YSP_RR%YT%MP1),PSP_RR(1,YSP_RR%YW%MP1),&
     & PSD_VF(1,YSD_VF%YLSM%MP),PSD_VF(1,YSD_VF%YVEG%MP),&
     & ZQS1)  

    IF (.NOT.LLDIAB) THEN
      CALL APLPASSH (KST,KEND,NPROMA,NFLEVG,&
       & PRE0,PQT0,&
       & PSP_SG(1,YSP_SG%YF%MP0),PSP_RR(1,YSP_RR%YT%MP0),PSP_RR(1,YSP_RR%YW%MP0),&
       & PSD_VF(1,YSD_VF%YLSM%MP),PSD_VF(1,YSD_VF%YVEG%MP),&
       & PQS)  
    ENDIF

    CALL APLPARS (KST,KEND,NPROMA,1,NFLEVG,NTSSG,NSTEP,&
     & PHI0,PRE0,PHIF0,PRE0F,PDELP0(1,1),PRDELP0,&
     & PUT0,PVT0,PTT0,PQT0,PCP0,ZCVGQ,&
     & PSP_SG(1,YSP_SG%YF%MP0),PSP_RR(1,YSP_RR%YT%MP0),PQS,&
     & PSP_RR(1,YSP_RR%YT%MP1),ZQS1,&
     & PSD_VF(1,YSD_VF%YGETRL%MP),PSD_VF(1,YSD_VF%YLSM%MP),PSD_VF(1,YSD_VF%YVEG%MP),&
     & PSD_VF(1,YSD_VF%YZ0F%MP),PSD_VF(1,YSD_VF%YVRLAN%MP),PSD_VF(1,YSD_VF%YVRLDI%MP),&
     & PSD_VF(1,YSD_VF%YALBF%MP),PSD_VF(1,YSD_VF%YEMISF%MP),ZMU0,PGM,&
     & ZAC_HC,ZCOR,&
     & ZRAB3C,ZRAB3N,ZRAB4C,ZRAB4N,ZRAB6C,ZRAB6N,&
     & ZRAT1C,ZRAT1N,ZRAT2C,ZRAT2N,ZRAT3C,ZRAT3N,&
     & ZRAT4C,ZRAT4N,ZRAT5C,ZRAT5N,&
     & PDIFCQ,PDIFCS,PDIFTQ,PDIFTS,&
     & PFCCQL,PFCCQN,PFCSQL,PFCSQN,&
     & PFPLCL,PFPLCN,PFPLSL,PFPLSN,PFRSO,PFRTH,&
     & PSTRCU,PSTRCV,PSTRDU,PSTRDV,PSTRTU,PSTRTV,&
     & PSTRMU,PSTRMV,PFRMH,'APLPARS')  

  ELSE

    CALL APLPASSH (KST,KEND,NPROMA,NFLEVG,&
     & PRE0,PQT0,&
     & PSP_SG(1,YSP_SG%YF%MP1),PSP_RR(1,YSP_RR%YT%MP1),PSP_RR(1,YSP_RR%YW%MP1),&
     & PSD_VF(1,YSD_VF%YLSM%MP),PSD_VF(1,YSD_VF%YVEG%MP),&
     & ZQS1)  

    IF (.NOT.LLDIAB) THEN
      CALL APLPASSH (KST,KEND,NPROMA,NFLEVG,&
       & PRE9,PQT9,&
       & PSP_SG(1,YSP_SG%YF%MP0),PSP_RR(1,YSP_RR%YT%MP9),PSP_RR(1,YSP_RR%YW%MP9),&
       & PSD_VF(1,YSD_VF%YLSM%MP),PSD_VF(1,YSD_VF%YVEG%MP),&
       & PQS)  
    ENDIF

    CALL APLPARS (KST,KEND,NPROMA,1,NFLEVG,NTSSG,NSTEP,&
     & PHI9,PRE9,PHIF9,PRE9F,PDELP9(1,1),PRDELP9,&
     & PUT9,PVT9,PTT9,PQT9,PCP9,ZCVGQ,&
     & PSP_SG(1,YSP_SG%YF%MP0),PSP_RR(1,YSP_RR%YT%MP9),PQS,&
     & PSP_RR(1,YSP_RR%YT%MP1),ZQS1,&
     & PSD_VF(1,YSD_VF%YGETRL%MP),PSD_VF(1,YSD_VF%YLSM%MP),PSD_VF(1,YSD_VF%YVEG%MP),&
     & PSD_VF(1,YSD_VF%YZ0F%MP),PSD_VF(1,YSD_VF%YVRLAN%MP),PSD_VF(1,YSD_VF%YVRLDI%MP),&
     & PSD_VF(1,YSD_VF%YALBF%MP),PSD_VF(1,YSD_VF%YEMISF%MP),ZMU0,PGM,&
     & ZAC_HC,ZCOR,&
     & ZRAB3C,ZRAB3N,ZRAB4C,ZRAB4N,ZRAB6C,ZRAB6N,&
     & ZRAT1C,ZRAT1N,ZRAT2C,ZRAT2N,ZRAT3C,ZRAT3N,&
     & ZRAT4C,ZRAT4N,ZRAT5C,ZRAT5N,&
     & PDIFCQ,PDIFCS,PDIFTQ,PDIFTS,&
     & PFCCQL,PFCCQN,PFCSQL,PFCSQN,&
     & PFPLCL,PFPLCN,PFPLSL,PFPLSN,PFRSO,PFRTH,&
     & PSTRCU,PSTRCV,PSTRDU,PSTRDV,PSTRTU,PSTRTV,&
     & PSTRMU,PSTRMV,PFRMH,'APLPARS')  

  ENDIF

ENDIF

!        3.3  Store the model trajectory at t-dt (leap-frog) or t (sl2tl).
!             ------------------------------------------------------------

IF (LTRAJPS.AND.(.NOT.LDLADNMI)) THEN
  IFIELDS=NG3D95*NFLEVG+NG2D95
  IF (LTWOTL) THEN
    CALL WRPHTRSF(NSTEP,KST,KEND,KSTGLO,NG2DS5,&
     & PQS,PSP_RR(1,YSP_RR%YT%MP0),PSP_SG(1,YSP_SG%YF%MP0))  
  ELSE
    CALL WRPHTRAJM(NSTEP,KST,KEND,KSTGLO,IFIELDS,&
     & PUT9,PVT9,PTT9,PQT9,PSPT9)  
    CALL WRPHTRSF(NSTEP,KST,KEND,KSTGLO,NG2DS5,&
     & PQS,PSP_RR(1,YSP_RR%YT%MP9),PSP_SG(1,YSP_SG%YF%MP9))  
  ENDIF
ENDIF

!        3.4  Computation of tendencies T,u,v and Q.
!             --------------------------------------

IF (LSIMPH.AND.(.NOT.LDLADNMI)) THEN

  TSPHY = MAX(PDTPHY,1.0_JPRB)

  IF (LTWOTL) THEN
    CALL CPTENDSM (NPROMA,KST,KEND,NFLEVG,&
     & PDIFCQ,PDIFCS,PDIFTQ,PDIFTS,&
     & PFCCQL,PFCCQN,PFCSQL,PFCSQN,&
     & PFPLCL,PFPLCN,PFPLSL,PFPLSN,&
     & PFRSO,PFRTH,&
     & PSTRCU,PSTRCV,PSTRDU,PSTRDV,&
     & PSTRTU,PSTRTV,&
     & PSTRMU,PSTRMV,PFRMH,&
     & PRDELP0,PHIF0,&
     & PUT0,PVT0,PTT0,PQT0,&
     & PQS,PSP_RR(1,YSP_RR%YT%MP0),POROG,&
     & PTENDU,PTENDV,ZTENDH,ZTENDQ,&
     & PFHPCL,PFHPCN,PFHPSL,PFHPSN,&
     & PFHSCL,PFHSCN,PFHSSL,PFHSSN)  
  ELSE
    CALL CPTENDSM (NPROMA,KST,KEND,NFLEVG,&
     & PDIFCQ,PDIFCS,PDIFTQ,PDIFTS,&
     & PFCCQL,PFCCQN,PFCSQL,PFCSQN,&
     & PFPLCL,PFPLCN,PFPLSL,PFPLSN,&
     & PFRSO,PFRTH,&
     & PSTRCU,PSTRCV,PSTRDU,PSTRDV,&
     & PSTRTU,PSTRTV,&
     & PSTRMU,PSTRMV,PFRMH,&
     & PRDELP9,PHIF9,&
     & PUT9,PVT9,PTT9,PQT9,&
     & PQS,PSP_RR(1,YSP_RR%YT%MP9),POROG,&
     & PTENDU,PTENDV,ZTENDH,ZTENDQ,&
     & PFHPCL,PFHPCN,PFHPSL,PFHPSN,&
     & PFHSCL,PFHSCN,PFHSSL,PFHSSN)  
  ENDIF

ENDIF

!        3.5  Computation of evolution of T, u, v and Q.
!             ------------------------------------------

IF (LSIMPH.AND.(.NOT.LDLADNMI)) THEN

  IF (LSLAG) THEN
    IF (LTWOTL) THEN
      CALL CPUTQYS (NPROMA,KST,KEND,NFLEVG,PDTPHY,&
       & ZTENDH,ZTENDQ,PTENDU,PTENDV,&
       & PCP0,PDELP0(1,1),PTT0,PUT0,PVT0,&
       & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
       & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA))  
    ELSE
      CALL CPUTQYS (NPROMA,KST,KEND,NFLEVG,PDTPHY,&
       & ZTENDH,ZTENDQ,PTENDU,PTENDV,&
       & PCP9,PDELP9(1,1),PTT9,PUT9,PVT9,&
       & PFDIS,PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
       & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA))  
    ENDIF
  ELSE
    CALL CPUTQYS (NPROMA,KST,KEND,NFLEVG,PDTPHY,&
     & ZTENDH,ZTENDQ,PTENDU,PTENDV,&
     & PCP9,PDELP9(1,1),PTT9,PUT9,PVT9,&
     & PFDIS,PGMVT1(1,1,YT1%MT),PGFLT1(1,1,YQ%MP1),&
     & PGMVT1(1,1,YT1%MU),PGMVT1(1,1,YT1%MV))  
  ENDIF

ENDIF

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

!*       4.    AROME  physics.
!              ---------------

IF (LMPA.AND.(.NOT.LDLADNMI)) THEN

  !      4.1  CALL APL_AROME
  !           --------------

  IF(LTWOTL) THEN
    CALL APL_AROME( KBL, KGPCOMP, KST  , KEND   , NPROMA ,&
     & 1      , NFLEVG , KGL1   , KGL2  , NSTEP  ,&
     & NTSSG   ,  PDTPHY,   &
     & PGEMU,PGELAM, POROG,PGM, ZMU0,ZMU0M,PGECLO,PGESLO,PSD_VC(1,YSD_VC%YVC(1)%MP),PSD_VF(1,YSD_VF%YLSM%MP),&
     & PSD_VA(1,YSD_VA%YSEA%MP ) , PSD_VA(1,YSD_VA%YLAN%MP ) ,PSD_VA(1,YSD_VA%YSOO%MP ) , PSD_VA(1,YSD_VA%YDES%MP ) ,&
     & PHI0,PHIF0,PREPHY0,PREPHY0F,PRDELP0(1,1), PDELP0(1,1),PTT0,PQT0,&
     & PCP0    , PR0   ,PALPH0 , PLNPR0, &
     & PLT0,PIT0,PRT0,PST0,PGT0,PHT0,PTKET0,PSRC0,PEXTT0, &
     & PUT0    , PVT0, PWT0, &
     & PGPAR,&
     & PEMTD , PEMTU ,PTRSW ,PSP_RR(1,YSP_RR%YT%MP1), &
     ! outputs
     & PCLF1,PSRC1,&
     & ZTENDT, ZTENDR, PTENDU, PTENDV,ZTENDW, ZTENDTKE,ZTENDEXT,&
     & PFRTH, PFRSO,PFRTHDS, PFRSODS, &
     & PSD_VF(1,YSD_VF%YALBF%MP), PSD_VF(1,YSD_VF%YEMISF%MP), PEZDIAG,&
     & PCLCH,PCLCL,PCLCM,PCLCT,PFPLSL,PFPLSN,PFPLSG,PFPLSHL,PSTRTU,PSTRTV,&
     & PFCS,PFCLL,PUCLS,PVCLS,PTCLS,PQCLS,PRHCLS,PUGST,PVGST )
  ELSE    
    CALL APL_AROME( KBL, KGPCOMP, KST  , KEND   , NPROMA ,&
     & 1      , NFLEVG , KGL1   , KGL2  , NSTEP  ,&
     & NTSSG   ,  PDTPHY,   &
     & PGEMU,PGELAM,POROG, PGM, ZMU0,ZMU0M,PGECLO,PGESLO,PSD_VC(1,YSD_VC%YVC(1)%MP),PSD_VF(1,YSD_VF%YLSM%MP),&
     & PSD_VA(1,YSD_VA%YSEA%MP ) , PSD_VA(1,YSD_VA%YLAN%MP ) ,PSD_VA(1,YSD_VA%YSOO%MP ) , PSD_VA(1,YSD_VA%YDES%MP ) ,&
     & PHI9,PHIF9,PREPHY9,PREPHY9F,PRDELP9(1,1),PDELP9(1,1),PTT9,PQT9,&
     & PCP9    , PR9   ,PALPH9, PLNPR9, &
     & PLT9,PIT9,PRT9,PST9,PGT9,PHT9,PTKET9,PSRC9,PEXTT9, &
     & PUT9    , PVT9, PWT9, &
     & PGPAR,&
     & PEMTD , PEMTU ,PTRSW ,PSP_RR(1,YSP_RR%YT%MP1),&
     ! outputs
     & PCLF1,PSRC1,&
     & ZTENDT, ZTENDR, PTENDU, PTENDV,ZTENDW, ZTENDTKE,ZTENDEXT,&
     & PFRTH, PFRSO, PFRTHDS, PFRSODS,&
     & PSD_VF(1,YSD_VF%YALBF%MP), PSD_VF(1,YSD_VF%YEMISF%MP), PEZDIAG, &
     & PCLCH,PCLCL,PCLCM,PCLCT,PFPLSL,PFPLSN,PFPLSG,PFPLSHL,PSTRTU,PSTRTV, &
     & PFCS,PFCLL,PUCLS,PVCLS,PTCLS,PQCLS,PRHCLS,PUGST,PVGST )
  ENDIF 

  !      4.2  COMPUTE THE PHYS. TENDENCY FOR "T" AND "w"
  !           ------------------------------------------

  IF ((.NOT.LNH_GEOGW).AND.LVERTFE.AND.LVFE_GWMPA) THEN
    ! * case LVFE_GWMPA not yet coded.
    !   (in this case ZGWT1 must be computed at full levels and
    !   not at half levels)
    CALL ABOR1(' MF_PHYS: case LVFE_GWMPA not yet coded if LMPA=T!')
  ENDIF
  IF (LNH_GEOGW.AND.(.NOT.LVERTFE)) THEN
    CALL ABOR1(' MF_PHYS: case LNH_GEOGW.AND.(.NOT.LVERTFE) not yet coded!')
  ENDIF

  ZDT = PDTPHY

  ZTENDD=0.0_JPRB

  ! * compute ZTT1:
  IF (LSLAG.AND.LTWOTL) THEN
    DO JLEV=1,NFLEVG
      DO JROF=KST,KEND
        ZTT1(JROF,JLEV)=PTT0(JROF,JLEV)+ZDT*ZTENDT(JROF,JLEV)
      ENDDO
    ENDDO
  ELSE
    DO JLEV=1,NFLEVG
      DO JROF=KST,KEND
        ZTT1(JROF,JLEV)=PTT9(JROF,JLEV)+ZDT*ZTENDT(JROF,JLEV)
      ENDDO
    ENDDO
  ENDIF

  ! * compute ZGWT1 = tendency of gw:
  IF (LNHDYN) THEN
    IF (LNH_PDVD) THEN
      ! Valid for LVFE_GWMPA=F only; ZGWT1 assumed to be half level values.
      DO JLEV=1,NFLEVG-1
        DO JROF=KST,KEND
          ZGWT1(JROF,JLEV)=0.5_JPRB*RG*(ZTENDW(JROF,JLEV)+ZTENDW(JROF,JLEV+1))
        ENDDO
      ENDDO
      DO JROF=KST,KEND
        ZGWT1(JROF,NFLEVG)=0.0_JPRB
        ZGWT1(JROF,0)=0.0_JPRB
      ENDDO
    ELSEIF (LNH_GEOGW) THEN
      ! Valid for LVERTFE=T only; ZGWT1 assumed to be full level values.
      ! Surface value of ZTENDW is assumed to be 0.
      ZGWT1(KST:KEND,1:NFLEVG)=RG*ZTENDW(KST:KEND,1:NFLEVG)
      ZGWT1(KST:KEND,0)=0.0_JPRB
    ENDIF
  ENDIF

  ! * convert gw tendency in d tendency:
  IF(LNHDYN) THEN
    IF ((LNH_PDVD.AND.LGWADV).OR.LNH_GEOGW) THEN
      ZTENDD(KST:KEND,1:NFLEVG)=ZGWT1(KST:KEND,1:NFLEVG)
    ELSE
      IF (LSLAG.AND.LTWOTL) THEN
        CALL GNHGW2SVDAROME(KST,KEND,PRE0F,PLNPR0,ZTT1,PREPHY0F,ZGWT1,&
         & ZTENDD)  
      ELSE
        CALL GNHGW2SVDAROME(KST,KEND,PRE9F,PLNPR9,ZTT1,PREPHY9F,ZGWT1,&
         & ZTENDD)  
      ENDIF
    ENDIF
  ELSE
    ZTENDD=0.0_JPRB
  ENDIF

  !      4.3  PUT THE TENDENCIES IN PB1/GFLT1/GMVT1.
  !           --------------------------------------

  IF (LSLAG.AND.LTWOTL) THEN
    IF (LDLADVL.AND.LDLADVI.AND.LDLADVS.AND.&
     & LDLADVR.AND.LDLADVG.AND.(LDLADVH.OR.(.NOT.YH%LACTIVE))&
     & .AND.LDLADVTKE.AND.((NGFL_EXT == 0).OR.LDLADVEXT)) THEN
      CALL CPUTQY_AROME(NPROMA,KST,KEND,NFLEVG,NFLSA,NFLEN,ZDT,&
       & ZTENDT, ZTENDR, PTENDU, PTENDV, ZTENDD, ZTENDTKE,ZTENDEXT,&
       & PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
       & PB1(1,MSLB1GFL9+IPL+1-NFLSA),PB1(1,MSLB1GFL9+IPI+1-NFLSA),&
       & PB1(1,MSLB1GFL9+IPR+1-NFLSA),PB1(1,MSLB1GFL9+IPS+1-NFLSA),&
       & PB1(1,MSLB1GFL9+IPG+1-NFLSA),PB1(1,MSLB1GFL9+IPH+1-NFLSA),&
       & PB1(1,MSLB1GFL9+IPTKE+1-NFLSA),PB1(1,MSLB1GFL9+IPEXT),&
       & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),PB1(1,MSLB1VD9+1-NFLSA))   
    ELSEIF ((.NOT.LDLADVL).AND.(.NOT.LDLADVI).AND.(.NOT.LDLADVS).AND.&
     & (.NOT.LDLADVR).AND.(.NOT.LDLADVG).AND.(.NOT.LDLADVTKE).AND.&
     & (.NOT.LDLADVH).AND.&
     & ((NGFL_EXT == 0).OR.(.NOT.LDLADVEXT))) THEN  
      CALL CPUTQY_AROME(NPROMA,KST,KEND,NFLEVG,1,NFLEVG,ZDT,&
       & ZTENDT, ZTENDR, PTENDU, PTENDV,ZTENDD, ZTENDTKE,ZTENDEXT,&
       & PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
       & PGFLT1(1,1,YL%MP1),PGFLT1(1,1,YI%MP1),&
       & PGFLT1(1,1,YR%MP1),PGFLT1(1,1,YS%MP1),&
       & PGFLT1(1,1,YG%MP1),PGFLT1(1,1,YH%MP1),&
       & PGFLT1(1,1,YTKE%MP1),PGFLT1(1,1,YEXT(1)%MP1),&
       & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),PB1(1,MSLB1VD9+1-NFLSA))  
    ELSEIF (LDLADVL.AND.LDLADVI.AND.LDLADVS.AND.&
     & LDLADVR.AND.LDLADVG.AND.(LDLADVH.OR.(.NOT.YH%LACTIVE))&
     &.AND.(.NOT.LDLADVTKE).AND.&
     &((NGFL_EXT == 0).OR.LDLADVEXT)) THEN
      CALL CPUTQY_AROME(NPROMA,KST,KEND,NFLEVG,NFLSA,NFLEN,ZDT,&
       & ZTENDT, ZTENDR, PTENDU, PTENDV, ZTENDD, ZTENDTKE,ZTENDEXT,&
       & PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
       & PB1(1,MSLB1GFL9+IPL+1-NFLSA),PB1(1,MSLB1GFL9+IPI+1-NFLSA),&
       & PB1(1,MSLB1GFL9+IPR+1-NFLSA),PB1(1,MSLB1GFL9+IPS+1-NFLSA),&
       & PB1(1,MSLB1GFL9+IPG+1-NFLSA),PB1(1,MSLB1GFL9+IPH+1-NFLSA),&
       & PGFLT1(1,1,YTKE%MP1),PB1(1,MSLB1GFL9+IPEXT),&
       & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),PB1(1,MSLB1VD9+1-NFLSA))
    ELSE
      CALL ABOR1('seule l advection de tous au aucuns GFL code dans AROME')
    ENDIF
  ELSEIF (LSLAG.AND.(.NOT.LTWOTL)) THEN
    IF (LDLADVL.AND.LDLADVI.AND.LDLADVS.AND.&
     & LDLADVR.AND.LDLADVG.AND.(LDLADVH.OR.(.NOT.YH%LACTIVE))&
     & .AND.LDLADVTKE.AND.&
     &((NGFL_EXT == 0).OR.LDLADVEXT)) THEN  
      CALL CPUTQY_AROME(NPROMA,KST,KEND,NFLEVG,NFLSA,NFLEN,ZDT,&
       & ZTENDT, ZTENDR, PTENDU, PTENDV,ZTENDD, ZTENDTKE,ZTENDEXT,&
       & PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
       & PB1(1,MSLB1GFL9+IPL+1-NFLSA),PB1(1,MSLB1GFL9+IPI+1-NFLSA),&
       & PB1(1,MSLB1GFL9+IPR+1-NFLSA),PB1(1,MSLB1GFL9+IPS+1-NFLSA),&
       & PB1(1,MSLB1GFL9+IPG+1-NFLSA),PB1(1,MSLB1GFL9+IPH+1-NFLSA),&
       & PB1(1,MSLB1GFL9+IPTKE+1-NFLSA),PB1(1,MSLB1GFL9+IPEXT),&
       & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),PB1(1,MSLB1VD9+1-NFLSA))   
    ELSEIF ((.NOT.LDLADVL).AND.(.NOT.LDLADVI).AND.(.NOT.LDLADVS).AND.&
     & (.NOT.LDLADVR).AND.(.NOT.LDLADVG).AND.(.NOT.LDLADVTKE).AND.&
     & (.NOT.LDLADVH).AND.&
     & ((NGFL_EXT == 0).OR.(.NOT.LDLADVEXT))) THEN  
      CALL CPUTQY_AROME(NPROMA,KST,KEND,NFLEVG,1,NFLEVG,ZDT,&
       & ZTENDT, ZTENDR, PTENDU, PTENDV,ZTENDD,ZTENDTKE,ZTENDEXT,&
       & PB1(1,MSLB1T9+1-NFLSA),PB1(1,MSLB1GFL9+IPQ+1-NFLSA),&
       & PGFLT1(1,1,YL%MP1),PGFLT1(1,1,YI%MP1),&
       & PGFLT1(1,1,YR%MP1),PGFLT1(1,1,YS%MP1),&
       & PGFLT1(1,1,YG%MP1),PGFLT1(1,1,YH%MP1),&
       & PGFLT1(1,1,YTKE%MP1),PGFLT1(1,1,YEXT(1)%MP1),&
       & PB1(1,MSLB1U9+1-NFLSA),PB1(1,MSLB1V9+1-NFLSA),PB1(1,MSLB1VD9+1-NFLSA))   
    ELSE
      CALL ABOR1('seule l advection de tous au aucuns GFL code dans AROME et avec LTWOTL=F')
    ENDIF
  ELSE
    CALL CPUTQY_AROME(NPROMA,KST,KEND,NFLEVG,1,NFLEVG,ZDT,&
     & ZTENDT, ZTENDR, PTENDU, PTENDV,ZTENDD, ZTENDTKE,ZTENDEXT,&
     & PGMVT1(1,1,YT1%MT),PGFLT1(1,1,YQ%MP1),&
     & PGFLT1(1,1,YL%MP1),PGFLT1(1,1,YI%MP1),&
     & PGFLT1(1,1,YR%MP1),PGFLT1(1,1,YS%MP1),&
     & PGFLT1(1,1,YG%MP1),PGFLT1(1,1,YH%MP1),&
     & PGFLT1(1,1,YTKE%MP1),PGFLT1(1,1,YEXT(1)%MP1),&
     & PGMVT1(1,1,YT1%MU),PGMVT1(1,1,YT1%MV),PGMVT1(1,1,YT1%MSVD))  
  ENDIF

ENDIF

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

!*       5.    Final calculations.
!              -------------------

! * Restore the initial value of some pseudo-historical surface buffers
!   if relevant.
IF (LL_SAVE_PHSURF) THEN
  IF(LLACTIVE_HV) PSD_VV(1:NPROMA,YSD_VV%YHV%MP)=ZHV(1:NPROMA)
  IF(LLACTIVE_Z0F) PSD_VF(1:NPROMA,YSD_VF%YZ0F%MP)=ZGZ0F(1:NPROMA)
  IF(LLACTIVE_Z0H) PSD_VV(1:NPROMA,YSD_VV%YZ0H%MP)=ZGZ0HF(1:NPROMA)
  IF(LLACTIVE_PBLH) PSD_VH(1:NPROMA,YSD_VH%YPBLH%MP)=ZPBLH(1:NPROMA)
  IF(LLACTIVE_SPSH) PSD_VH(1:NPROMA,YSD_VH%YSPSH%MP)=ZFHPS(1:NPROMA)
  IF(LCVPRO) THEN
    PUDAL(:,:)=ZUDAL(:,:)
    PUDOM(:,:)=ZUDOM(:,:)
    IF(LCDDPRO) THEN
      PDDAL(:,:)=ZDDAL(:,:)
      PDDOM(:,:)=ZDDOM(:,:)
    ENDIF
  ENDIF
  IF(YUNEBH%LACTIVE) PUNEBH(:,:)=ZUNEBH(:,:)
  IF(YUEN%LACTIVE)   PENTCH(:,:)=ZENTCH(:,:)
ENDIF

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

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