Index: LMDZ6/branches/cirrus/libf/phylmd/Dust/phys_output_write_spl_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/Dust/phys_output_write_spl_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/Dust/phys_output_write_spl_mod.F90	(revision 5202)
@@ -325,5 +325,5 @@
          sissnow, runoff, albsol3_lic, evap_pot, &
          t2m, fluxt, fluxlat, fsollw, fsolsw, &
-         wfbils, wfbilo, cdragm, cdragh, cldl, cldm, &
+         wfbils, cdragm, cdragh, cldl, cldm, &
          cldh, cldt, JrNt, &
          ! cldljn, cldmjn, cldhjn, cldtjn &
@@ -353,6 +353,6 @@
          toplwad_aero, toplwad0_aero, sollwad_aero, &
          sollwad0_aero, toplwai_aero, sollwai_aero, &
-         scdnc, cldncl, reffclws, reffclwc, cldnvi, &
-         lcc, lcc3d, lcc3dcon, lcc3dstra, reffclwtop, &
+         !scdnc, cldncl, reffclws, reffclwc, cldnvi, &
+         !lcc, lcc3d, lcc3dcon, lcc3dstra, reffclwtop, &
          ec550aer, flwc, fiwc, t_seri, theta, q_seri, &
 !jyg<
@@ -377,5 +377,7 @@
     USE phys_output_var_mod, ONLY: vars_defined, snow_o, zfra_o, bils_diss, &
          bils_ec,bils_ech, bils_tke, bils_kinetic, bils_latent, bils_enthalp, &
-         itau_con, nfiles, clef_files, nid_files, zvstr_gwd_rando
+         itau_con, nfiles, clef_files, nid_files, zvstr_gwd_rando, &
+         scdnc, cldncl, reffclws, reffclwc, cldnvi, &
+         lcc, lcc3d, lcc3dcon, lcc3dstra, reffclwtop
     USE ocean_slab_mod, ONLY: tslab, slab_bilg, tice, seaice
     USE pbl_surface_mod, ONLY: snow
@@ -721,6 +723,4 @@
           IF (vars_defined)         zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
           CALL histwrite_phy(o_wbils_srf(nsrf), zx_tmp_fi2d)
-          IF (vars_defined)         zx_tmp_fi2d(1 : klon) = wfbilo( 1 : klon, nsrf)
-          CALL histwrite_phy(o_wbilo_srf(nsrf), zx_tmp_fi2d)
 
           IF (iflag_pbl > 1) THEN
Index: LMDZ6/branches/cirrus/libf/phylmd/StratAer/aer_sedimnt.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/StratAer/aer_sedimnt.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/StratAer/aer_sedimnt.F90	(revision 5202)
@@ -17,5 +17,6 @@
 !-----------------------------------------------------------------------
 
-  USE phys_local_var_mod, ONLY: mdw, budg_sed_part, DENSO4, f_r_wet, vsed_aer
+  USE phys_local_var_mod, ONLY: mdw, budg_sed_part, DENSO4, DENSO4B, f_r_wet, f_r_wetB, vsed_aer
+  USE strataer_local_var_mod, ONLY: flag_new_strat_compo
   USE dimphy, ONLY : klon,klev
   USE infotrac_phy
@@ -89,7 +90,13 @@
 
       ! stokes-velocity with cunnigham slip- flow correction
-      ZVAER(JL,JK,nb) = 2./9.*(DENSO4(JL,JK)*1000.-ZRHO)*RG/zvis(JL,JK)*(f_r_wet(JL,JK)*mdw(nb)/2.)**2.* &
-         (1.+ 2.*zlair(JL,JK)/(f_r_wet(JL,JK)*mdw(nb))*(1.257+0.4*EXP(-0.55*f_r_wet(JL,JK)*mdw(nb)/zlair(JL,JK))))
-
+      IF(flag_new_strat_compo) THEN
+         ! stokes-velocity with cunnigham slip- flow correction
+         ZVAER(JL,JK,nb) = 2./9.*(DENSO4B(JL,JK,nb)*1000.-ZRHO)*RG/zvis(JL,JK)*(f_r_wetB(JL,JK,nb)*mdw(nb)/2.)**2.* &
+              (1.+ 2.*zlair(JL,JK)/(f_r_wetB(JL,JK,nb)*mdw(nb))*(1.257+0.4*EXP(-0.55*f_r_wetB(JL,JK,nb)*mdw(nb)/zlair(JL,JK))))
+      ELSE
+         ZVAER(JL,JK,nb) = 2./9.*(DENSO4(JL,JK)*1000.-ZRHO)*RG/zvis(JL,JK)*(f_r_wet(JL,JK)*mdw(nb)/2.)**2.* &
+              (1.+ 2.*zlair(JL,JK)/(f_r_wet(JL,JK)*mdw(nb))*(1.257+0.4*EXP(-0.55*f_r_wet(JL,JK)*mdw(nb)/zlair(JL,JK))))
+      ENDIF
+      
       ZSEDFLX(JL,nb)=ZVAER(JL,JK,nb)*ZRHO
       ZSOLAERB(nb)=ZSOLAERB(nb)+ZDTGDP*ZSEDFLX(JL,nb)
Index: LMDZ6/branches/cirrus/libf/phylmd/StratAer/aerophys.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/StratAer/aerophys.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/StratAer/aerophys.F90	(revision 5202)
@@ -5,23 +5,28 @@
   IMPLICIT NONE
 !
-  REAL,PARAMETER                         :: ropx=1500.0              ! default aerosol particle mass density [kg/m3]
-  REAL,PARAMETER                         :: dens_aer_dry=1848.682308 ! dry aerosol particle mass density at T_0=293K[kg/m3]
-  REAL,PARAMETER                         :: dens_aer_ref=1483.905336 ! aerosol particle mass density with 75% H2SO4 at T_0=293K[kg/m3]
-  REAL,PARAMETER                         :: mdwmin=0.002e-6          ! dry diameter of smallest aerosol particles [m]
-  REAL,PARAMETER                         :: V_rat=2.0                ! volume ratio of neighboring size bins
-  REAL,PARAMETER                         :: mfrac_H2SO4=0.75         ! default mass fraction of H2SO4 in the aerosol
-  REAL, PARAMETER                        :: mAIRmol=28.949*1.66E-27  ! Average mass of an air molecule [kg]
-  REAL, PARAMETER                        :: mH2Omol=18.016*1.66E-27  ! Mass of an H2O molecule [kg]
-  REAL, PARAMETER                        :: mH2SO4mol=98.082*1.66E-27! Mass of an H2SO4 molecule [kg]
-  REAL, PARAMETER                        :: mSO2mol=64.06*1.66E-27   ! Mass of an SO2 molecule [kg]
-  REAL, PARAMETER                        :: mSatom=32.06*1.66E-27    ! Mass of a S atom [kg]
-  REAL, PARAMETER                        :: mOCSmol=60.07*1.66E-27   ! Mass of an OCS molecule [kg]
-  REAL, PARAMETER                        :: mClatom=35.45*1.66E-27   ! Mass of an Cl atom [kg]
-  REAL, PARAMETER                        :: mHClmol=36.46*1.66E-27   ! Mass of an HCl molecule [kg]
-  REAL, PARAMETER                        :: mBratom=79.90*1.66E-27   ! Mass of an Br atom [kg]
-  REAL, PARAMETER                        :: mHBrmol=80.92*1.66E-27   ! Mass of an HBr molecule [kg]
-  REAL, PARAMETER                        :: mNOmol=30.01*1.66E-27    ! Mass of an NO molecule [kg]
-  REAL, PARAMETER                        :: mNO2mol=46.01*1.66E-27   ! Mass of an NO2 molecule [kg]
-  REAL, PARAMETER                        :: mNatome=14.0067*1.66E-27 ! Mass of an N atome [kg] 
+  REAL,PARAMETER    :: ropx=1500.0              ! default aerosol particle mass density [kg/m3]
+  REAL,PARAMETER    :: dens_aer_dry=1848.682308 ! dry aerosol particle mass density at T_0=293K[kg/m3]
+  REAL,PARAMETER    :: dens_aer_ref=1483.905336 ! aerosol particle mass density with 75% H2SO4 at T_0=293K[kg/m3]
+  REAL,PARAMETER    :: mdwmin=0.002e-6          ! dry diameter of smallest aerosol particles [m]
+  REAL,PARAMETER    :: V_rat=2.0                ! volume ratio of neighboring size bins
+  REAL,PARAMETER    :: mfrac_H2SO4=0.75         ! default mass fraction of H2SO4 in the aerosol
+  REAL, PARAMETER   :: mAIRmol=28.949*1.66E-27  ! Average mass of an air molecule [kg]
+  REAL, PARAMETER   :: mH2Omol=18.016*1.66E-27  ! Mass of an H2O molecule [kg]
+  REAL, PARAMETER   :: mH2SO4mol=98.082*1.66E-27! Mass of an H2SO4 molecule [kg]
+  REAL, PARAMETER   :: mSO2mol=64.06*1.66E-27   ! Mass of an SO2 molecule [kg]
+  REAL, PARAMETER   :: mSatom=32.06*1.66E-27    ! Mass of a S atom [kg]
+  REAL, PARAMETER   :: mOCSmol=60.07*1.66E-27   ! Mass of an OCS molecule [kg]
+  REAL, PARAMETER   :: mClatom=35.45*1.66E-27   ! Mass of an Cl atom [kg]
+  REAL, PARAMETER   :: mHClmol=36.46*1.66E-27   ! Mass of an HCl molecule [kg]
+  REAL, PARAMETER   :: mBratom=79.90*1.66E-27   ! Mass of an Br atom [kg]
+  REAL, PARAMETER   :: mHBrmol=80.92*1.66E-27   ! Mass of an HBr molecule [kg]
+  REAL, PARAMETER   :: mNOmol=30.01*1.66E-27    ! Mass of an NO molecule [kg]
+  REAL, PARAMETER   :: mNO2mol=46.01*1.66E-27   ! Mass of an NO2 molecule [kg]
+  REAL, PARAMETER   :: mNatome=14.0067*1.66E-27 ! Mass of an N atome [kg]
+  REAL, PARAMETER   :: rgas=8.3145 ! molar gas cste (J⋅K−1⋅mol−1=m3⋅Pa⋅K−1⋅mol−1=kg⋅m2⋅s−2⋅K−1⋅mol−1)
+  ! 
+  REAL, PARAMETER   :: MH2O  =1000.*mH2Omol     ! Mass of 1 molec [g] (18.016*1.66E-24)
+  REAL, PARAMETER   :: MH2SO4=1000.*mH2SO4mol   ! Mass of 1 molec [g] (98.082*1.66E-24)
+  REAL, PARAMETER   :: BOLZ  =1.381E-16         ! Boltzmann constant [dyn.cm/K]
 !
 END MODULE aerophys
Index: LMDZ6/branches/cirrus/libf/phylmd/StratAer/coagulate.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/StratAer/coagulate.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/StratAer/coagulate.F90	(revision 5202)
@@ -26,6 +26,7 @@
   USE aerophys
   USE infotrac_phy
-  USE phys_local_var_mod, ONLY: DENSO4, f_r_wet
-
+  USE phys_local_var_mod, ONLY: DENSO4, DENSO4B, f_r_wet, f_r_wetB
+  USE strataer_local_var_mod, ONLY: flag_new_strat_compo
+  
   IMPLICIT NONE
 
@@ -43,9 +44,11 @@
   ! local variables in coagulation routine
   INTEGER                                       :: i,j,k,nb,ilon,ilev
-  REAL, DIMENSION(nbtr_bin)                     :: radius ! aerosol particle radius in each bin [m]
+  REAL, DIMENSION(nbtr_bin)                     :: radiusdry ! dry aerosol particle radius in each bin [m]
+  REAL, DIMENSION(nbtr_bin)                     :: radiuswet ! wet aerosol particle radius in each bin [m]
   REAL, DIMENSION(klon,klev,nbtr_bin)           :: tr_t ! Concentration Traceur at time t [U/KgA]
   REAL, DIMENSION(klon,klev,nbtr_bin)           :: tr_tp1 ! Concentration Traceur at time t+1 [U/KgA]
   REAL, DIMENSION(nbtr_bin,nbtr_bin,nbtr_bin)   :: ff   ! Volume fraction of intermediate particles
-  REAL, DIMENSION(nbtr_bin)                     :: V    ! Volume of bins
+  REAL, DIMENSION(nbtr_bin)                     :: Vdry ! Volume dry of bins
+  REAL, DIMENSION(nbtr_bin)                     :: Vwet ! Volume wet of bins
   REAL, DIMENSION(nbtr_bin,nbtr_bin)            :: Vij  ! Volume sum of i and j
   REAL                                          :: eta  ! Dynamic viscosity of air
@@ -82,15 +85,20 @@
   include "YOMCST.h"
 
-  DO i=1, nbtr_bin
-   radius(i)=mdw(i)/2.
-   V(i)= radius(i)**3.  !neglecting factor 4*RPI/3
-  ENDDO
-
-  DO j=1, nbtr_bin
-  DO i=1, nbtr_bin
-   Vij(i,j)= V(i)+V(j)
-  ENDDO
-  ENDDO
-
+! ff(i,j,k): Volume fraction of Vi,j that is partitioned to each model bin k
+! just need to be calculated in model initialization because mdw(:) size is fixed
+! no need to recalculate radius, Vdry, Vij, and ff every timestep because it is for  
+! dry aerosols
+  DO i=1, nbtr_bin
+     radiusdry(i)=mdw(i)/2.
+     Vdry(i)=radiusdry(i)**3.  !neglecting factor 4*RPI/3
+     Vwet(i)=0.0
+  ENDDO
+
+  DO j=1, nbtr_bin
+     DO i=1, nbtr_bin
+        Vij(i,j)= Vdry(i)+Vdry(j)
+     ENDDO
+  ENDDO
+  
 !--pre-compute the f(i,j,k) from Jacobson equation 13
   ff=0.0 
@@ -100,19 +108,20 @@
     IF (k.EQ.1) THEN
       ff(i,j,k)= 0.0
-    ELSEIF (k.GT.1.AND.V(k-1).LT.Vij(i,j).AND.Vij(i,j).LT.V(k)) THEN
+    ELSEIF (k.GT.1.AND.Vdry(k-1).LT.Vij(i,j).AND.Vij(i,j).LT.Vdry(k)) THEN
       ff(i,j,k)= 1.-ff(i,j,k-1)
     ELSEIF (k.EQ.nbtr_bin) THEN
-      IF (Vij(i,j).GE.v(k)) THEN
+      IF (Vij(i,j).GE.Vdry(k)) THEN
         ff(i,j,k)= 1.
       ELSE
         ff(i,j,k)= 0.0
       ENDIF
-    ELSEIF (k.LE.(nbtr_bin-1).AND.V(k).LE.Vij(i,j).AND.Vij(i,j).LT.V(k+1)) THEN
-      ff(i,j,k)= V(k)/Vij(i,j)*(V(k+1)-Vij(i,j))/(V(k+1)-V(k))
+    ELSEIF (k.LE.(nbtr_bin-1).AND.Vdry(k).LE.Vij(i,j).AND.Vij(i,j).LT.Vdry(k+1)) THEN
+      ff(i,j,k)= Vdry(k)/Vij(i,j)*(Vdry(k+1)-Vij(i,j))/(Vdry(k+1)-Vdry(k))
     ENDIF
   ENDDO
   ENDDO
   ENDDO
-
+! End of just need to be calculated at initialization because mdw(:) size is fixed
+  
   DO ilon=1, klon
   DO ilev=1, klev 
@@ -120,9 +129,18 @@
   IF (is_strato(ilon,ilev)) THEN
   !compute actual wet particle radius & volume for every grid box
-  DO i=1, nbtr_bin
-   radius(i)=f_r_wet(ilon,ilev)*mdw(i)/2.
-   V(i)= radius(i)**3.  !neglecting factor 4*RPI/3
-  ENDDO
-
+  IF(flag_new_strat_compo) THEN
+     DO i=1, nbtr_bin
+        radiuswet(i)=f_r_wetB(ilon,ilev,i)*mdw(i)/2.
+        Vwet(i)= radiuswet(i)**3.  !neglecting factor 4*RPI/3
+!!      Vwet(i)= Vdry(i)*(f_r_wetB(ilon,ilev,i)**3)
+     ENDDO
+  ELSE
+     DO i=1, nbtr_bin
+        radiuswet(i)=f_r_wet(ilon,ilev)*mdw(i)/2.
+        Vwet(i)= radiuswet(i)**3.  !neglecting factor 4*RPI/3
+!!      Vwet(i)= Vdry(i)*(f_r_wet(ilon,ilev)**3)
+     ENDDO
+  ENDIF
+  
 !--Calculations for the coagulation kernel---------------------------------------------------------
 
@@ -150,14 +168,21 @@
   Di=0.0
   DO i=1, nbtr_bin
-   Kn(i)=mnfrpth/radius(i)
-   Di(i)=RKBOL*t_seri(ilon,ilev)/(6.*RPI*radius(i)*eta)*(1.+Kn(i)*(1.249+0.42*exp(-0.87/Kn(i))))
+      Kn(i)=mnfrpth/radiuswet(i)
+      Di(i)=RKBOL*t_seri(ilon,ilev)/(6.*RPI*radiuswet(i)*eta)*(1.+Kn(i)*(1.249+0.42*exp(-0.87/Kn(i))))
   ENDDO
 
 !--pre-compute the thermal velocity of a particle thvelpar(i) from equation 20
   thvelpar=0.0
-  DO i=1, nbtr_bin
-   m_par(i)=4./3.*RPI*radius(i)**3.*DENSO4(ilon,ilev)*1000.
-   thvelpar(i)=sqrt(8.*RKBOL*t_seri(ilon,ilev)/(RPI*m_par(i)))
-  ENDDO
+  IF(flag_new_strat_compo) THEN
+     DO i=1, nbtr_bin
+        m_par(i)=4./3.*RPI*radiuswet(i)**3.*DENSO4B(ilon,ilev,i)*1000.
+        thvelpar(i)=sqrt(8.*RKBOL*t_seri(ilon,ilev)/(RPI*m_par(i)))
+     ENDDO
+  ELSE
+     DO i=1, nbtr_bin
+        m_par(i)=4./3.*RPI*radiuswet(i)**3.*DENSO4(ilon,ilev)*1000.
+        thvelpar(i)=sqrt(8.*RKBOL*t_seri(ilon,ilev)/(RPI*m_par(i)))
+     ENDDO
+  ENDIF
 
 !--pre-compute the particle mean free path mfppar(i) from equation 22
@@ -171,8 +196,9 @@
   delta=0.0
   DO i=1, nbtr_bin
-   delta(i)=((2.*radius(i)+mfppar(i))**3.-(4.*radius(i)**2.+mfppar(i)**2.)**1.5)/ &
-           & (6.*radius(i)*mfppar(i))-2.*radius(i)
-  ENDDO
-
+      delta(i)=((2.*radiuswet(i)+mfppar(i))**3.-(4.*radiuswet(i)**2.+mfppar(i)**2.)**1.5)/ &
+           & (6.*radiuswet(i)*mfppar(i))-2.*radiuswet(i)
+  ENDDO
+
+!   beta(i,j): coagulation kernel (rate coefficient) of 2 colliding particles i,j 
 !--pre-compute the beta(i,j) from equation 17 in Jacobson
   num=0.0
@@ -180,20 +206,20 @@
   DO i=1, nbtr_bin
 !
-   num=4.*RPI*(radius(i)+radius(j))*(Di(i)+Di(j))
-   denom=(radius(i)+radius(j))/(radius(i)+radius(j)+sqrt(delta(i)**2.+delta(j)**2.))+ &
-        & 4.*(Di(i)+Di(j))/(sqrt(thvelpar(i)**2.+thvelpar(j)**2.)*(radius(i)+radius(j)))
-   beta(i,j)=num/denom
+     num=4.*RPI*(radiuswet(i)+radiuswet(j))*(Di(i)+Di(j))
+     denom=(radiuswet(i)+radiuswet(j))/(radiuswet(i)+radiuswet(j)+sqrt(delta(i)**2.+delta(j)**2.))+ &
+          & 4.*(Di(i)+Di(j))/(sqrt(thvelpar(i)**2.+thvelpar(j)**2.)*(radiuswet(i)+radiuswet(j)))
+     beta(i,j)=num/denom
 !
 !--compute enhancement factor due to van der Waals forces
    IF (ok_vdw .EQ. 0) THEN      !--no enhancement factor
-     Evdw=1.0
+      Evdw=1.0
    ELSEIF (ok_vdw .EQ. 1) THEN  !--E(0) case
-     AvdWi = AvdW/(RKBOL*t_seri(ilon,ilev))*(4.*radius(i)*radius(j))/(radius(i)+radius(j))**2.
-     xvdW = LOG(1.+AvdWi)
-     EvdW = 1. + avdW1*xvdW + avdW3*xvdW**3
+      AvdWi = AvdW/(RKBOL*t_seri(ilon,ilev))*(4.*radiuswet(i)*radiuswet(j))/(radiuswet(i)+radiuswet(j))**2.
+      xvdW = LOG(1.+AvdWi)
+      EvdW = 1. + avdW1*xvdW + avdW3*xvdW**3
    ELSEIF (ok_vdw .EQ. 2) THEN  !--E(infinity) case
-     AvdWi = AvdW/(RKBOL*t_seri(ilon,ilev))*(4.*radius(i)*radius(j))/(radius(i)+radius(j))**2.
-     xvdW = LOG(1.+AvdWi)
-     EvdW = 1. + SQRT(AvdWi/3.)/(1.+bvdW0*SQRT(AvdWi)) + bvdW1*xvdW + bvdW3*xvdW**3.
+      AvdWi = AvdW/(RKBOL*t_seri(ilon,ilev))*(4.*radiuswet(i)*radiuswet(j))/(radiuswet(i)+radiuswet(j))**2.
+      xvdW = LOG(1.+AvdWi)
+      EvdW = 1. + SQRT(AvdWi/3.)/(1.+bvdW0*SQRT(AvdWi)) + bvdW1*xvdW + bvdW3*xvdW**3.
    ENDIF
 !
@@ -209,5 +235,6 @@
   denom=0.0
   DO j=1, nbtr_bin
-  denom=denom+(1.-ff(k,j,k))*beta(k,j)*tr_t(ilon,ilev,j)
+     !    fraction of coagulation of k and j that is not giving k
+     denom=denom+(1.-ff(k,j,k))*beta(k,j)*tr_t(ilon,ilev,j)
   ENDDO
 
@@ -219,13 +246,34 @@
     num=0.0
     DO j=1, k
-    numi=0.0
-    DO i=1, k-1
-    numi=numi+ff(i,j,k)*beta(i,j)*V(i)*tr_tp1(ilon,ilev,i)*tr_t(ilon,ilev,j)
+       numi=0.0
+       DO i=1, k-1
+!           
+!           see Jacobson: " In order to conserve volume and volume concentration (which
+!           coagulation physically does) while giving up some accuracy in number concentration" 
+!
+!           Coagulation of i and j giving k
+!           with V(i) and then V(j) because it considers i,j and j,i with the double loop
+!
+!           BUT WHY WET VOLUME V(i) in old STRATAER? tracers are already dry aerosols and coagulation 
+!           kernel beta(i,j) accounts for wet aerosols -> reply below
+!
+!             numi=numi+ff(i,j,k)*beta(i,j)*V(i)*tr_tp1(ilon,ilev,i)*tr_t(ilon,ilev,j)
+            numi=numi+ff(i,j,k)*beta(i,j)*Vdry(i)*tr_tp1(ilon,ilev,i)*tr_t(ilon,ilev,j)
+       ENDDO
+       num=num+numi
     ENDDO
-    num=num+numi
-    ENDDO
 
 !--calculate new concentration of other bins
-    tr_tp1(ilon,ilev,k)=(V(k)*tr_t(ilon,ilev,k)+pdtcoag*num)/(1.+pdtcoag*denom)/V(k)
+!      tr_tp1(ilon,ilev,k)=(V(k)*tr_t(ilon,ilev,k)+pdtcoag*num)/( (1.+pdtcoag*denom)*V(k) )
+    tr_tp1(ilon,ilev,k)=(Vdry(k)*tr_t(ilon,ilev,k)+pdtcoag*num)/( (1.+pdtcoag*denom)*Vdry(k) )
+!
+!       In constant composition (no dependency on aerosol size because no kelvin effect)
+!       V(l)= (f_r_wet(ilon,ilev)**3)*((mdw(l)/2.)**3) = (f_r_wet(ilon,ilev)**3)*Vdry(i)
+!       so numi and num are proportional (f_r_wet(ilon,ilev)**3)
+!       and so 
+!        tr_tp1(ilon,ilev,k)=(V(k)*tr_t(ilon,ilev,k)+pdtcoag*num)/( (1.+pdtcoag*denom)*V(k) )
+!                     =(Vdry(k)*tr_t(ilon,ilev,k)+pdtcoag*num_dry)/( (1.+pdtcoag*denom)*Vdry(k) ) 
+!          with num_dry=...beta(i,j)*Vdry(i)*....
+!       so in old STRATAER (.not.flag_new_strat_compo), it was correct
   ENDIF
 
@@ -234,5 +282,5 @@
 !--convert tracer concentration back from [number/m3] to [number/KgA] and write into tr_seri
   DO i=1, nbtr_bin
-   tr_seri(ilon,ilev,i+nbtr_sulgas) = tr_tp1(ilon,ilev,i) / zrho
+     tr_seri(ilon,ilev,i+nbtr_sulgas) = tr_tp1(ilon,ilev,i) / zrho
   ENDDO
 
@@ -240,4 +288,5 @@
   ENDDO !--end of loop klev
   ENDDO !--end of loop klon
+! *********************************************
 
 END SUBROUTINE COAGULATE
Index: LMDZ6/branches/cirrus/libf/phylmd/StratAer/cond_evap_tstep_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/StratAer/cond_evap_tstep_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/StratAer/cond_evap_tstep_mod.F90	(revision 5202)
@@ -9,6 +9,162 @@
 CONTAINS
 
+      SUBROUTINE condens_evapor_rate_kelvin(R2SO4G,t_seri,pplay,R2SO4, &
+          & DENSO4,f_r_wet,R2SO4ik,DENSO4ik,f_r_wetik,FL,ASO4,DNDR)
+!
+!     INPUT: 
+!     R2SO4G: number density of gaseous H2SO4 [molecules/cm3]
+!     t_seri: temperature (K)
+!     pplay: pressure (Pa)
+!     R2SO4: aerosol H2SO4 weight fraction (percent) - flat surface (does not depend on aerosol size)
+!     DENSO4: aerosol density (gr/cm3) 
+!     f_r_wet: factor for converting dry to wet radius 
+!        assuming 'flat surface' composition (does not depend on aerosol size)
+!     variables that depends on aerosol size because of Kelvin effect
+!     R2SO4Gik: number density of gaseous H2SO4 [molecules/cm3] - depends on aerosol size
+!     DENSO4ik: aerosol density (gr/cm3) - depends on aerosol size
+!     f_r_wetik: factor for converting dry to wet radius - depends on aerosol size
+!     RRSI: radius [cm]
+
+      USE aerophys
+      USE infotrac_phy
+      USE YOMCST, ONLY : RPI
+      USE sulfate_aer_mod, ONLY : wph2so4, surftension, solh2so4, rpmvh2so4
+      USE strataer_local_var_mod, ONLY : ALPH2SO4, RRSI
+      
+      IMPLICIT NONE
+      
+      REAL, PARAMETER :: third=1./3.
+      
+      ! input variables
+      REAL            :: R2SO4G !H2SO4 number density [molecules/cm3]
+      REAL            :: t_seri
+      REAL            :: pplay
+      REAL            :: R2SO4
+      REAL            :: DENSO4
+      REAL            :: f_r_wet
+      REAL            :: R2SO4ik(nbtr_bin), DENSO4ik(nbtr_bin), f_r_wetik(nbtr_bin)
+      
+      ! output variables
+      REAL            :: FL(nbtr_bin)
+      REAL            :: ASO4(nbtr_bin)
+      REAL            :: DNDR(nbtr_bin)
+      
+      ! local variables
+      INTEGER            :: IK
+      REAL            :: ALPHA,CST
+      REAL            :: WH2(nbtr_bin)
+      REAL            :: RP,VTK,AA,FL1,RKNUD
+      REAL            :: DND
+      REAL            :: ATOT,AH2O
+      REAL            :: RRSI_wet(nbtr_bin)
+      REAL            :: FPATH, WPP, XA, FKELVIN
+      REAL            :: surtens, mvh2so4, temp
+      
+! ///    MOLEC CONDENSATION GROWTH (DUE TO CHANGES IN H2SO4 AND SO H2O)
+!    ------------------------------------------------------------------
+!                                  EXCEPT CN
+!       RK:H2SO4 WEIGHT PERCENT DOESN'T CHANGE
+!     BE CAREFUL,H2SO4 WEIGHT PERCENTAGE
+
+!                   MOLECULAR ACCOMODATION OF H2SO4
+!     H2SO4 accommodation  coefficient [condensation/evaporation]
+      ALPHA = ALPH2SO4
+!      FPLAIR=(2.281238E-5)*TAIR/PAIR
+!     1.E2 (m to cm), 
+      CST=1.E2*2.281238E-5
+!     same expression as in coagulate
+!     in coagulate: mean free path of air (Pruppacher and Klett, 2010, p.417) [m]
+!     mnfrpth=6.6E-8*(1.01325E+5/pplay(ilon,ilev))*(t_seri(ilon,ilev)/293.15)
+!     mnfrpth=2.28E-5*t_seri/pplay
+      
+      temp = min( max(t_seri, 190.), 300.) ! 190K <= temp <= 300K
+      
+      RRSI_wet(:)=RRSI(:)*f_r_wetik(:)
+
+!     Pruppa and Klett
+      FPATH=CST*t_seri/pplay
+    
+!     H2SO4 mass fraction in aerosol
+      WH2(:)=R2SO4ik(:)*1.0E-2
+
+!                               ACTIVITY COEFFICIENT(SEE GIAUQUE,1951)
+!                               AYERS ET AL (1980)
+!                                  (MU-MU0)
+!      RP=-10156.0/t_seri +16.259-(ACTSO4*4.184)/(8.31441*t_seri)
+!                                  DROPLET H2SO4 PRESSURE IN DYN.CM-2
+!      RP=EXP(RP)*1.01325E6/0.086
+!!      RP=EXP(RP)*1.01325E6
+!                                  H2SO4 NUMBER DENSITY NEAR DROPLET
+
+!      DND=RP*6.02E23/(8.31E7*t_seri)
+
+!                                 KELVIN EFFECT FACTOR
+!CK 20160613: bug fix, removed factor 250 (from original code by S. Bekki)
+!!      AA =2.0*MH2O*72.0/(DENSO4*BOLZ*t_seri*250.0)
+!      AA =2.0*MH2O*72.0/(DENSO4*BOLZ*t_seri)
+
+!                                  MEAN KINETIC VELOCITY
+!     DYN*CM*K/(K*GR)=(CM/SEC2)*CM
+!                                  IN CM/SEC
+      VTK=SQRT(8.0*BOLZ*t_seri/(RPI*MH2SO4))
+!                                 KELVIN EFFECT FACTOR
+
+!     Loop on bin radius (RRSI in cm)
+      DO IK=1,nbtr_bin
+
+      IF(R2SO4ik(IK) > 0.0) THEN
+
+!       h2so4 mass fraction (0<wpp<1)
+        wpp=R2SO4ik(IK)*1.e-2    
+        xa=18.*wpp/(18.*wpp+98.*(1.-wpp)) 
+!       equilibrium h2so4 number density over H2SO4/H2O solution (molec/cm3)
+        DND=solh2so4(t_seri,xa)
+!          KELVIN EFFECT:  
+!       surface tension (mN/m=1.e-3.kg/s2) = f(T,h2so4 mole fraction)
+        surtens=surftension(temp,xa)
+!       partial molar volume of h2so4 (cm3.mol-1 =1.e-6.m3.mol-1)
+        mvh2so4= rpmvh2so4(temp,R2SO4ik(IK))
+!       Kelvin factor (MKS)
+        fkelvin=exp( 2.*1.e-3*surtens*1.e-6*mvh2so4/ (1.e-2*RRSI_wet(IK)*rgas*temp) )
+!                              
+        DNDR(IK) =DND*fkelvin
+
+        FL1=RPI*ALPHA*VTK*(R2SO4G-DNDR(IK))
+
+!       TURCO(1979) FOR HNO3:ALH2SO4 CONDENSATION= ALH2SO4 EVAPORATION
+!       RPI*R2*VTK IS EQUIVALENT TO DIFFUSION COEFFICIENT
+!       EXTENSION OF THE RELATION FOR DIFFUSION KINETICS
+!       KNUDSEN NUMBER FPATH/RRSI
+!       NEW VERSION (SEE NOTES)
+        RKNUD=FPATH/RRSI_wet(IK)
+!       SENFELD
+        FL(IK)=FL1*RRSI_wet(IK)**2*( 1.0 +RKNUD ) & 
+     &     /( 1.0 +ALPHA/(2.0*RKNUD) +RKNUD )
+!       TURCO
+!        RL= (4.0/3.0 +0.71/RKNUD)/(1.0+1.0/RKNUD)
+!     *         +4.0*(1.0-ALPHA)/(3.0*ALPHA)
+!        FL=FL1*RRSI(IK)*RRSI(IK)
+!     *         /( (3.0*ALPHA/4.0)*(1.0/RKNUD+RL*ALPHA) )
+
+!                         INITIAL NUMBER OF H2SO4 MOLEC OF 1 DROPLET
+        ATOT=4.0*RPI*DENSO4ik(IK)*(RRSI_wet(IK)**3)/3.0 !attention: g and cm
+        ASO4(IK)=WH2(IK)*ATOT/MH2SO4 !attention: g
+!        ATOT=4.0*RPI*dens_aer(I,J)/1000.*(RRSI(IK)**3)/3.0
+!        ASO4=mfrac_H2SO4*ATOT/MH2SO4
+!                        INITIAL NUMBER OF H2O MOLEC OF 1 DROPLET
+        AH2O=(1.0-WH2(IK))*ATOT/MH2O !attention: g
+
+!       CHANGE OF THE NUMBER OF H2SO4 MOLEC OF 1 DROPLET DURING DT
+!       IT IS FOR KEM BUT THERE ARE OTHER WAYS
+
+      ENDIF  
+
+      ENDDO !loop over bins
+
+      END SUBROUTINE condens_evapor_rate_kelvin
+      
+!********************************************************************
       SUBROUTINE condens_evapor_rate(R2SO4G,t_seri,pplay,ACTSO4,R2SO4, &
-                   & DENSO4,f_r_wet,RRSI,Vbin,FL,ASO4,DNDR)
+                   & DENSO4,f_r_wet,FL,ASO4,DNDR)
 !
 !     INPUT: 
@@ -22,4 +178,5 @@
       USE infotrac_phy
       USE YOMCST, ONLY : RPI
+      USE strataer_local_var_mod, ONLY : ALPH2SO4, RRSI
 
       IMPLICIT NONE
@@ -33,7 +190,5 @@
       REAL DENSO4
       REAL f_r_wet
-      REAL RRSI(nbtr_bin)
-      REAL Vbin(nbtr_bin)
-
+      
       ! output variables
       REAL FL(nbtr_bin)
@@ -48,6 +203,5 @@
       REAL ATOT,AH2O
       REAL RRSI_wet(nbtr_bin)
-      REAL Vbin_wet(nbtr_bin)
-      REAL MH2SO4,MH2O,BOLZ,FPATH
+      REAL FPATH
 
 ! ///    MOLEC CONDENSATION GROWTH (DUE TO CHANGES IN H2SO4 AND SO H2O)
@@ -57,20 +211,14 @@
 !     BE CAREFUL,H2SO4 WEIGHT PERCENTAGE
 
-!                   WEIGHT OF 1 MOLEC IN G
-      MH2O  =1000.*mH2Omol !18.016*1.66E-24
-      MH2SO4=1000.*mH2SO4mol !98.082*1.66E-24
-!                   BOLTZMANN CONSTANTE IN DYN.CM/K
-      BOLZ  =1.381E-16
 !                   MOLECULAR ACCOMODATION OF H2SO4
-!     raes and van dingen
-      ALPHA =0.1    
+!     H2SO4 accommodation coefficient [condensation/evaporation]
+      ALPHA = ALPH2SO4
 !      FPLAIR=(2.281238E-5)*TAIR/PAIR
 !     1.E2 (m to cm), 
       CST=1.E2*2.281238E-5
 
-      ! compute local wet particle radius and volume
+      ! compute local wet particle radius [cm]
       RRSI_wet(:)=RRSI(:)*f_r_wet
-      Vbin_wet(:)=Vbin(:)*f_r_wet**3
-
+      
 !     Pruppa and Klett
       FPATH=CST*t_seri/pplay
@@ -138,10 +286,11 @@
 
 !********************************************************************
-      SUBROUTINE cond_evap_part(dt,FL,ASO4,f_r_wet,RRSI,Vbin,tr_seri)
+      SUBROUTINE condens_evapor_part(dt,FL,ASO4,f_r_wet,tr_seri)
 
       USE aerophys
       USE infotrac_phy
       USE YOMCST, ONLY : RPI
-
+      USE strataer_local_var_mod, ONLY : RRSI,Vbin
+      
       IMPLICIT NONE
 
@@ -151,10 +300,8 @@
       REAL ASO4(nbtr_bin)
       REAL f_r_wet
-      REAL RRSI(nbtr_bin)
-      REAL Vbin(nbtr_bin)
-
+      
       ! output variables
       REAL tr_seri(nbtr)
-
+      
       ! local variables
       REAL tr_seri_new(nbtr)
@@ -211,5 +358,5 @@
       tr_seri(:)=tr_seri_new(:)
 
-      END SUBROUTINE cond_evap_part
+      END SUBROUTINE condens_evapor_part
 
 END MODULE cond_evap_tstep_mod
Index: LMDZ6/branches/cirrus/libf/phylmd/StratAer/micphy_tstep.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/StratAer/micphy_tstep.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/StratAer/micphy_tstep.F90	(revision 5202)
@@ -8,5 +8,6 @@
   USE aerophys
   USE infotrac_phy, ONLY : nbtr_bin, nbtr_sulgas, nbtr, id_H2SO4_strat
-  USE phys_local_var_mod, ONLY: mdw, budg_3D_nucl, budg_3D_cond_evap, budg_h2so4_to_part, R2SO4, DENSO4, f_r_wet
+  USE phys_local_var_mod, ONLY: mdw, budg_3D_nucl, budg_3D_cond_evap, budg_h2so4_to_part, R2SO4, DENSO4, &
+       f_r_wet, R2SO4B, DENSO4B, f_r_wetB
   USE nucleation_tstep_mod
   USE cond_evap_tstep_mod
@@ -14,5 +15,5 @@
   USE YOMCST, ONLY : RPI, RD, RG
   USE print_control_mod, ONLY: lunout
-  USE strataer_local_var_mod
+  USE strataer_local_var_mod ! contains also RRSI and Vbin
   
   IMPLICIT NONE
@@ -35,10 +36,8 @@
   REAL                      :: ntot !total number of molecules in the critical cluster (ntot>4)
   REAL                      :: x    ! molefraction of H2SO4 in the critical cluster     
-  REAL Vbin(nbtr_bin)
   REAL a_xm, b_xm, c_xm
   REAL PDT, dt
   REAL H2SO4_init
   REAL ACTSO4(klon,klev)
-  REAL RRSI(nbtr_bin)
   REAL nucl_rate
   REAL cond_evap_rate
@@ -48,9 +47,6 @@
   REAL DNDR(nbtr_bin)
   REAL H2SO4_sat
-
-  DO it=1,nbtr_bin
-    Vbin(it)=4.0*RPI*((mdw(it)/2.)**3)/3.0
-  ENDDO
-
+  REAL R2SO4ik(nbtr_bin), DENSO4ik(nbtr_bin), f_r_wetik(nbtr_bin)
+  
   !coefficients for H2SO4 density parametrization used for nucleation if ntot<4
   a_xm = 0.7681724 + 1.*(2.1847140 + 1.*(7.1630022 + 1.*(-44.31447 + &
@@ -61,12 +57,9 @@
        & 1.*(7.990811e-4 + 1.*(-7.458060e-4 + 1.*2.58139e-4 )))))
 
-  ! STRAACT (R2SO4, t_seri -> H2SO4 activity coefficient (ACTSO4)) for cond/evap
-  CALL STRAACT(ACTSO4)
-
-  ! compute particle radius in cm RRSI from diameter in m 
-  DO it=1,nbtr_bin
-    RRSI(it)=mdw(it)/2.*100.
-  ENDDO
-
+  IF(.not.flag_new_strat_compo) THEN
+     ! STRAACT (R2SO4, t_seri -> H2SO4 activity coefficient (ACTSO4)) for cond/evap
+     CALL STRAACT(ACTSO4)
+  ENDIF
+  
   DO ilon=1, klon
 !
@@ -104,7 +97,16 @@
       ENDIF
       ! compute cond/evap rate in kg(H2SO4)/kgA/s
-      CALL condens_evapor_rate(rhoa,t_seri(ilon,ilev),pplay(ilon,ilev), &
-             & ACTSO4(ilon,ilev),R2SO4(ilon,ilev),DENSO4(ilon,ilev),f_r_wet(ilon,ilev), &
-             & RRSI,Vbin,FL,ASO4,DNDR)
+      IF(flag_new_strat_compo) THEN
+         R2SO4ik(:)   = R2SO4B(ilon,ilev,:)
+         DENSO4ik(:)  = DENSO4B(ilon,ilev,:)
+         f_r_wetik(:) = f_r_wetB(ilon,ilev,:)
+         CALL condens_evapor_rate_kelvin(rhoa,t_seri(ilon,ilev),pplay(ilon,ilev), &
+              & R2SO4(ilon,ilev),DENSO4(ilon,ilev),f_r_wet(ilon,ilev), &
+              & R2SO4ik,DENSO4ik,f_r_wetik,FL,ASO4,DNDR)
+      ELSE
+         CALL condens_evapor_rate(rhoa,t_seri(ilon,ilev),pplay(ilon,ilev), &
+              & ACTSO4(ilon,ilev),R2SO4(ilon,ilev),DENSO4(ilon,ilev),f_r_wet(ilon,ilev), &
+              & FL,ASO4,DNDR)
+      ENDIF
       ! Compute H2SO4 saturate vapor for big particules
       H2SO4_sat = DNDR(nbtr_bin)/(pplay(ilon,ilev)/t_seri(ilon,ilev)/RD/1.E6/mH2SO4mol)
@@ -127,7 +129,7 @@
       tr_seri(ilon,ilev,id_H2SO4_strat)=MAX(0.,tr_seri(ilon,ilev,id_H2SO4_strat)-(nucl_rate+cond_evap_rate)*dt)
       ! apply cond to bins
-      CALL cond_evap_part(dt,FL,ASO4,f_r_wet(ilon,ilev),RRSI,Vbin,tr_seri(ilon,ilev,:))
+      CALL condens_evapor_part(dt,FL,ASO4,f_r_wet(ilon,ilev),tr_seri(ilon,ilev,:))
       ! apply nucl. to bins
-      CALL nucleation_part(nucl_rate,ntot,x,dt,Vbin,tr_seri(ilon,ilev,:))
+      CALL nucleation_part(nucl_rate,ntot,x,dt,tr_seri(ilon,ilev,:))
       ! compute fluxes as diagnostic in [kg(S)/m2/layer/s] (now - for evap and + for cond)
       budg_3D_cond_evap(ilon,ilev)=budg_3D_cond_evap(ilon,ilev)+mSatom/mH2SO4mol &
@@ -142,7 +144,13 @@
         & *pplay(ilon,ilev)/t_seri(ilon,ilev)/RD/1.E6/mH2SO4mol
     ! compute cond/evap rate in kg(H2SO4)/kgA/s (now only evap for pdtphys)
-    CALL condens_evapor_rate(rhoa,t_seri(ilon,ilev),pplay(ilon,ilev), &
-           & ACTSO4(ilon,ilev),R2SO4(ilon,ilev),DENSO4(ilon,ilev),f_r_wet(ilon,ilev), &
-           & RRSI,Vbin,FL,ASO4,DNDR)
+    IF(flag_new_strat_compo) THEN
+       CALL condens_evapor_rate_kelvin(rhoa,t_seri(ilon,ilev),pplay(ilon,ilev), &
+            & R2SO4(ilon,ilev),DENSO4(ilon,ilev),f_r_wet(ilon,ilev), &
+            & R2SO4ik,DENSO4ik,f_r_wetik,FL,ASO4,DNDR)
+    ELSE
+       CALL condens_evapor_rate(rhoa,t_seri(ilon,ilev),pplay(ilon,ilev), &
+            & ACTSO4(ilon,ilev),R2SO4(ilon,ilev),DENSO4(ilon,ilev),f_r_wet(ilon,ilev), &
+            & FL,ASO4,DNDR)
+    ENDIF
     ! limit evaporation (negative FL) over one physics time step to H2SO4 content of the droplet
     DO it=1,nbtr_bin
@@ -159,5 +167,5 @@
     tr_seri(ilon,ilev,id_H2SO4_strat)=MAX(0.,tr_seri(ilon,ilev,id_H2SO4_strat)-evap_rate*pdtphys)
     ! apply evap to bins
-    CALL cond_evap_part(pdtphys,FL,ASO4,f_r_wet(ilon,ilev),RRSI,Vbin,tr_seri(ilon,ilev,:))
+    CALL condens_evapor_part(pdtphys,FL,ASO4,f_r_wet(ilon,ilev),tr_seri(ilon,ilev,:))
     ! compute fluxes as diagnostic in [kg(S)/m2/layer/s] (now - for evap and + for cond)
     budg_3D_cond_evap(ilon,ilev)=budg_3D_cond_evap(ilon,ilev)+mSatom/mH2SO4mol &
Index: LMDZ6/branches/cirrus/libf/phylmd/StratAer/miecalc_aer.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/StratAer/miecalc_aer.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/StratAer/miecalc_aer.F90	(revision 5202)
@@ -16,5 +16,5 @@
 
   USE phys_local_var_mod, ONLY: tr_seri, mdw, alpha_bin, piz_bin, cg_bin
-  USE aerophys
+  USE aerophys, ONLY: dens_aer_dry, dens_aer_ref, V_rat
   USE aero_mod
   USE infotrac_phy, ONLY : nbtr, nbtr_bin, nbtr_sulgas, id_SO2_strat
@@ -226,19 +226,5 @@
     40000.000,    0.2500,   1.48400,   1.0000E-08, &
     50000.000,    0.2000,   1.49800,   1.0000E-08 /), (/nb_lambda_h2so4,4/), order=(/2,1/) )
-
-  !--initialising dry diameters to geometrically spaced mass/volume (see Jacobson 1994)
-    mdw(1)=mdwmin
-    IF (V_rat.LT.1.62) THEN ! compensate for dip in second bin for lower volume ratio
-      mdw(2)=mdw(1)*2.**(1./3.)
-      DO it=3, nbtr_bin
-        mdw(it)=mdw(it-1)*V_rat**(1./3.)
-      ENDDO 
-    ELSE
-      DO it=2, nbtr_bin
-        mdw(it)=mdw(it-1)*V_rat**(1./3.)
-      ENDDO
-    ENDIF
-    WRITE(lunout,*) 'init mdw=', mdw
-
+     
     !--compute particle radius for a composition of 75% H2SO4 / 25% H2O at T=293K
     DO bin_number=1, nbtr_bin
Index: LMDZ6/branches/cirrus/libf/phylmd/StratAer/nucleation_tstep_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/StratAer/nucleation_tstep_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/StratAer/nucleation_tstep_mod.F90	(revision 5202)
@@ -70,9 +70,10 @@
 !--------------------------------------------------------------------------------------------------
 
-SUBROUTINE nucleation_part(nucl_rate,ntot,x,dt,Vbin,tr_seri)
+SUBROUTINE nucleation_part(nucl_rate,ntot,x,dt,tr_seri)
 
   USE aerophys
   USE infotrac_phy
-
+  USE strataer_local_var_mod, ONLY : Vbin
+  
   IMPLICIT NONE
 
@@ -82,6 +83,5 @@
   REAL x    ! mole raction of H2SO4 in the critical cluster
   REAL dt
-  REAL Vbin(nbtr_bin)
-
+  
   ! output variable
   REAL tr_seri(nbtr)
Index: LMDZ6/branches/cirrus/libf/phylmd/StratAer/strataer_local_var_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/StratAer/strataer_local_var_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/StratAer/strataer_local_var_mod.F90	(revision 5202)
@@ -51,4 +51,8 @@
   
   !============= NUCLEATION VARS =============
+  ! MOLECULAR ACCOMODATION OF H2SO4 (Raes and Van Dingen)
+  REAL,SAVE    :: ALPH2SO4               ! H2SO4 accommodation  coefficient [condensation/evaporation]
+  !$OMP THREADPRIVATE(ALPH2SO4)
+  
   ! flag to constraint nucleation rate in a lat/pres box
   LOGICAL,SAVE :: flag_nuc_rate_box      ! Nucleation rate limit or not to a lat/pres
@@ -64,6 +68,4 @@
   INTEGER,SAVE :: flh2o  ! ds stratemit : flh2o =0 (tr_seri), flh2o=1 (dq) 
   !$OMP THREADPRIVATE(flh2o)
-!  REAL,ALLOCATABLE,SAVE    :: d_q_emiss(:,:)
-!  !$OMP THREADPRIVATE(d_q_emiss)
   
   REAL,ALLOCATABLE,SAVE    :: budg_emi(:,:)            !DIMENSION(klon,n)
@@ -144,4 +146,7 @@
   !$OMP THREADPRIVATE(day_emit_roc)
   
+  REAL,ALLOCATABLE,SAVE    :: RRSI(:) ! radius [cm] for each aerosol size
+  REAL,ALLOCATABLE,SAVE    :: Vbin(:) ! volume [m3] for each aerosol size  
+  !$OMP THREADPRIVATE(RRSI, Vbin)
   REAL,SAVE    :: dlat, dlon             ! delta latitude and d longitude of grid in degree
   !$OMP THREADPRIVATE(dlat, dlon)
@@ -153,5 +158,10 @@
     USE print_control_mod, ONLY : lunout
     USE mod_phys_lmdz_para, ONLY : is_master
-    USE infotrac_phy, ONLY: id_OCS_strat,id_SO2_strat,id_H2SO4_strat,nbtr_sulgas
+    USE infotrac_phy, ONLY: id_OCS_strat,id_SO2_strat,id_H2SO4_strat,nbtr_sulgas,nbtr_bin
+    USE phys_local_var_mod, ONLY : mdw
+    USE aerophys, ONLY: mdwmin, V_rat
+    USE YOMCST  , ONLY : RPI
+    
+    INTEGER :: it
     
     WRITE(lunout,*) 'IN STRATAER_LOCAL_VAR INIT WELCOME!'
@@ -185,4 +195,5 @@
     
     ! nuc init
+    ALPH2SO4 = 0.1
     flag_nuc_rate_box = .FALSE.
     nuclat_min=0  ; nuclat_max=0
@@ -238,4 +249,33 @@
     ENDIF ! if master
     
+    !--initialising dry diameters to geometrically spaced mass/volume (see Jacobson 1994)
+    mdw(1)=mdwmin
+    IF (V_rat.LT.1.62) THEN ! compensate for dip in second bin for lower volume ratio
+       mdw(2)=mdw(1)*2.**(1./3.)
+       DO it=3, nbtr_bin
+          mdw(it)=mdw(it-1)*V_rat**(1./3.)
+       ENDDO
+    ELSE
+       DO it=2, nbtr_bin
+          mdw(it)=mdw(it-1)*V_rat**(1./3.)
+       ENDDO
+    ENDIF
+    IF (is_master) WRITE(lunout,*) 'init mdw=', mdw
+    
+    !   compute particle radius RRSI [cm] and volume Vbin [m3] from diameter mdw [m]
+    ALLOCATE(RRSI(nbtr_bin), Vbin(nbtr_bin))
+    
+    DO it=1,nbtr_bin
+       !     [cm]
+       RRSI(it)=mdw(it)/2.*100.
+       !     [m3]
+       Vbin(it)=4.0*RPI*((mdw(it)/2.)**3)/3.0
+    ENDDO
+    
+    IF (is_master) THEN
+       WRITE(lunout,*) 'init RRSI=', RRSI
+       WRITE(lunout,*) 'init Vbin=', Vbin
+    ENDIF
+    
     WRITE(lunout,*) 'IN STRATAER INIT END'
     
Index: LMDZ6/branches/cirrus/libf/phylmd/StratAer/strataer_nuc_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/StratAer/strataer_nuc_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/StratAer/strataer_nuc_mod.F90	(revision 5202)
@@ -13,5 +13,6 @@
     USE print_control_mod, ONLY : lunout
     USE mod_phys_lmdz_para, ONLY : is_master
-    USE strataer_local_var_mod, ONLY: flag_nuc_rate_box,nuclat_min,nuclat_max,nucpres_min,nucpres_max
+    USE strataer_local_var_mod, ONLY: ALPH2SO4,flag_nuc_rate_box,nuclat_min,nuclat_max, &
+         nucpres_min,nucpres_max
     
     !Config Key  = flag_nuc_rate_box
@@ -30,6 +31,10 @@
     CALL getin_p('nucpres_max',nucpres_max)
     
+    ! Read argument H2SO4 accommodation  coefficient [condensation/evaporation]
+    CALL getin_p('alph2so4',ALPH2SO4)
+    
     !============= Print params =============
     IF (is_master) THEN
+       WRITE(lunout,*) 'IN STRATAER_NUC : ALPH2SO4 = ',alph2so4
        WRITE(lunout,*) 'IN STRATAER_NUC : flag_nuc_rate_box = ',flag_nuc_rate_box
        IF (flag_nuc_rate_box) THEN
Index: LMDZ6/branches/cirrus/libf/phylmd/StratAer/sulfate_aer_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/StratAer/sulfate_aer_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/StratAer/sulfate_aer_mod.F90	(revision 5202)
@@ -7,73 +7,145 @@
 
 !*******************************************************************
-  SUBROUTINE STRACOMP_BIN(sh,t_seri,pplay)
-!
-!   Aerosol H2SO4 weight fraction as a function of PH2O and temperature
-!   INPUT:
-!   sh: VMR of H2O
-!   t_seri: temperature (K)
-!   pplay: middle layer pression (Pa)
-!
-!   OUTPUT:
-!   R2SO4: aerosol H2SO4 weight fraction (percent)
+      SUBROUTINE STRACOMP_KELVIN(sh,t_seri,pplay)
+!
+!     Aerosol H2SO4 weight fraction as a function of PH2O and temperature
+!     INPUT:
+!     sh: MMR of H2O
+!     t_seri: temperature (K)
+!     pplay: middle layer pression (Pa)
+!
+!     Modified in modules:
+!     R2SO4: aerosol H2SO4 weight fraction (percent)
+!     R2SO4B: aerosol H2SO4 weight fraction (percent) for each aerosol bin
+!     DENSO4: aerosol density (gr/cm3)
+!     DENSO4B: aerosol density (gr/cm3)for each aerosol bin
+!     f_r_wet: factor for converting dry to wet radius 
+!        assuming 'flat surface' composition (does not depend on aerosol size)
+!     f_r_wetB: factor for converting dry to wet radius 
+!        assuming 'curved surface' composition (depends on aerosol size)
     
-    USE dimphy, ONLY : klon,klev ! nb of longitude and altitude bands
-    USE aerophys
-    USE phys_local_var_mod, ONLY: R2SO4
+      USE dimphy, ONLY : klon,klev ! nb of longitude and altitude bands
+      USE infotrac_phy, ONLY : nbtr_bin
+      USE aerophys
+      USE phys_local_var_mod, ONLY: R2SO4, R2SO4B, DENSO4, DENSO4B, f_r_wet, f_r_wetB
+      USE strataer_local_var_mod, ONLY: RRSI
+!     WARNING: in phys_local_var_mod R2SO4B, DENSO4B, f_r_wetB (klon,klev,nbtr_bin)
+!          and dens_aer_dry must be declared somewhere
     
-    IMPLICIT NONE
+      IMPLICIT NONE
     
-    REAL,DIMENSION(klon,klev),INTENT(IN)          :: t_seri  ! Temperature
-    REAL,DIMENSION(klon,klev),INTENT(IN)          :: pplay   ! pression in the middle of each layer (Pa)
-    REAL,DIMENSION(klon,klev),INTENT(IN)          :: sh      ! specific humidity
+      REAL,DIMENSION(klon,klev),INTENT(IN)    :: t_seri  ! Temperature
+      REAL,DIMENSION(klon,klev),INTENT(IN)    :: pplay   ! pression in the middle of each layer (Pa)
+      REAL,DIMENSION(klon,klev),INTENT(IN)    :: sh      ! specific humidity (kg h2o/kg air)
+      
+!     local variables
+      integer         :: ilon,ilev,ik
+      real, parameter :: rath2oair = mAIRmol/mH2Omol  
+      real, parameter :: third = 1./3.
+      real            :: pph2ogas(klon,klev) 
+      real            :: temp, wpp, xa, surtens, mvh2o, radwet, fkelvin, pph2okel, r2so4ik, denso4ik
+!----------------------------------------
+  
+!     gas-phase h2o partial pressure (Pa) 
+!                                vmr=sh*rath2oair
+      pph2ogas(:,:) = pplay(:,:)*sh(:,:)*rath2oair
     
-    REAL ks(7)
-    REAL t,qh2o,ptot,pw
-    REAL a,b,c,det
-    REAL xsb,msb
+      DO ilon=1,klon
+      DO ilev=1,klev
+          
+        temp = max(t_seri(ilon,ilev),190.)
+        temp = min(temp,300.)
+
+!    ***   H2SO4-H2O flat surface ***
+!!       equilibrium H2O pressure over pure flat liquid water (Pa)
+!!        pflath2o=psh2o(temp)
+!       h2so4 weight percent(%) = f(P_h2o(Pa),T)
+        R2SO4(ilon,ilev)=wph2so4(pph2ogas(ilon,ilev),temp)  
+!       h2so4 mass fraction (0<wpp<1)
+        wpp=R2SO4(ilon,ilev)*1.e-2     
+!       mole fraction
+        xa=18.*wpp/(18.*wpp+98.*(1.-wpp))
+
+!        CHECK:compare h2so4 sat/ pressure (see Marti et al., 97 & reef. therein)
+!               R2SO4(ilon,ilev)=70.    temp=298.15
+!        equilibrium h2so4 number density over H2SO4/H2O solution (molec/cm3)
+!        include conversion from molec/cm3 to Pa
+!        ph2so4=solh2so4(temp,xa)*(1.38065e-16*temp)/10.
+!        print*,' ph2so4=',ph2so4,temp,R2SO4(ilon,ilev)
+!        good match with Martin, et Ayers, not with Gmitro (the famous 0.086)
+
+!       surface tension (mN/m=1.e-3.kg/s2) = f(T,h2so4 mole fraction)
+        surtens=surftension(temp,xa)
+!       molar volume of pure h2o (cm3.mol-1 =1.e-6.m3.mol-1)
+        mvh2o= rmvh2o(temp)
+!       aerosol density (gr/cm3) = f(T,h2so4 mass fraction)
+        DENSO4(ilon,ilev)=density(temp,wpp) 
+!           ->x1000., to have it in kg/m3
+!       factor for converting dry to wet radius
+        f_r_wet(ilon,ilev) = (dens_aer_dry/(DENSO4(ilon,ilev)*1.e3)/ & 
+                   &    (R2SO4(ilon,ilev)*1.e-2))**third
+!    ***   End of H2SO4-H2O flat surface ***
+
+
+!          Loop on bin radius (RRSI in cm)
+           DO IK=1,nbtr_bin 
+ 
+!      ***   H2SO4-H2O curved surface - Kelvin effect factor ***
+!            wet radius (m) (RRSI(IK) in [cm])
+             if (f_r_wetB(ilon,ilev,IK) .gt. 1.0) then 
+               radwet = 1.e-2*RRSI(IK)*f_r_wetB(ilon,ilev,IK)
+             else 
+!              H2SO4-H2O flat surface, only on the first timestep
+               radwet = 1.e-2*RRSI(IK)*f_r_wet(ilon,ilev)
+             endif
+!            Kelvin factor: 
+!            surface tension (mN/m=1.e-3.kg/s2) 
+!            molar volume of pure h2o (cm3.mol-1 =1.e-6.m3.mol-1)
+             fkelvin=exp( 2.*1.e-3*surtens*1.e-6*mvh2o/ (radwet*rgas*temp) )
+!            equilibrium: pph2o(gas) = pph2o(liq) = pph2o(liq_flat) * fkelvin
+!            equilibrium: pph2o(liq_flat) = pph2o(gas) / fkelvin
+!            h2o liquid partial pressure before Kelvin effect (Pa)
+             pph2okel = pph2ogas(ilon,ilev) / fkelvin
+!            h2so4 weight percent(%) = f(P_h2o(Pa),temp)
+             r2so4ik=wph2so4(pph2okel,temp)
+!            h2so4 mass fraction (0<wpp<1)
+             wpp=r2so4ik*1.e-2    
+!            mole fraction
+             xa=18.*wpp/(18.*wpp+98.*(1.-wpp)) 
+!            aerosol density (gr/cm3) = f(T,h2so4 mass fraction)
+             denso4ik=density(temp,wpp)
+!           
+!            recalculate Kelvin factor with surface tension and radwet 
+!                              with new R2SO4B and DENSO4B
+             surtens=surftension(temp,xa)
+!            wet radius (m)
+             radwet = 1.e-2*RRSI(IK)*(dens_aer_dry/(denso4ik*1.e3)/ & 
+                   &    (r2so4ik*1.e-2))**third
+             fkelvin=exp( 2.*1.e-3*surtens*1.e-6*mvh2o / (radwet*rgas*temp) ) 
+             pph2okel=pph2ogas(ilon,ilev) / fkelvin
+!            h2so4 weight percent(%) = f(P_h2o(Pa),temp)
+             R2SO4B(ilon,ilev,IK)=wph2so4(pph2okel,temp)
+!            h2so4 mass fraction (0<wpp<1)
+             wpp=R2SO4B(ilon,ilev,IK)*1.e-2    
+             xa=18.*wpp/(18.*wpp+98.*(1.-wpp)) 
+!            aerosol density (gr/cm3) = f(T,h2so4 mass fraction)
+             DENSO4B(ilon,ilev,IK)=density(temp,wpp)
+!            factor for converting dry to wet radius
+             f_r_wetB(ilon,ilev,IK) = (dens_aer_dry/(DENSO4B(ilon,ilev,IK)*1.e3)/ & 
+                   &    (R2SO4B(ilon,ilev,IK)*1.e-2))**third
+!
+!             print*,'R,Rwet(m),kelvin,h2so4(%),ro=',RRSI(ik),radwet,fkelvin, &
+!              &  R2SO4B(ilon,ilev,IK),DENSO4B(ilon,ilev,IK)
+!             print*,' equil.h2so4(molec/cm3), & 
+!              & sigma',solh2so4(temp,xa),surftension(temp,xa)
+
+           ENDDO
+
+      ENDDO
+      ENDDO
+
+      RETURN
     
-    INTEGER ilon,ilev
-    DATA ks/-21.661,2724.2,51.81,-15732.0,47.004,-6969.0,-4.6183/
-    
-!*******************************************************************
-!***     liquid aerosols process
-!*******************************************************************
-!        BINARIES LIQUID AEROROLS:
-    
-    DO ilon=1,klon
-       DO ilev=1,klev
-          
-          t = max(t_seri(ilon,ilev),185.)
-          qh2o=sh(ilon,ilev)/18.*28.9
-          ptot=pplay(ilon,ilev)/100.
-          pw = qh2o*ptot/1013.0
-          pw = min(pw,2.e-3/1013.)
-          pw = max(pw,2.e-5/1013.)
-          
-!*******************************************************************
-!***     binaries aerosols h2so4/h2o
-!*******************************************************************
-          a = ks(3) + ks(4)/t
-          b = ks(1) + ks(2)/t
-          c = ks(5) + ks(6)/t + ks(7)*log(t) - log(pw)
-          
-          det = b**2 - 4.*a*c
-          
-          IF (det > 0.) THEN
-             xsb = (-b - sqrt(det))/(2.*a)
-             msb = 55.51*xsb/(1.0 - xsb)
-          ELSE
-             msb = 0.
-          ENDIF
-          R2SO4(ilon,ilev) = 100*msb*0.098076/(1.0 + msb*0.098076)
-          
-          ! H2SO4 min dilution: 0.5%
-          R2SO4(ilon,ilev) = max( R2SO4(ilon,ilev), 0.005 )
-       ENDDO
-    ENDDO
-100 RETURN
-    
-  END SUBROUTINE STRACOMP_BIN
-
+  END SUBROUTINE STRACOMP_KELVIN
 !********************************************************************
     SUBROUTINE STRACOMP(sh,t_seri,pplay)
@@ -544,76 +616,4 @@
 
     END SUBROUTINE
-
-!****************************************************************
-    SUBROUTINE DENH2SA_TABA(t_seri)
-
-!   AERSOL DENSITY AS A FUNCTION OF H2SO4 WEIGHT PERCENT AND T
-!   from Tabazadeh et al. (1994) abaques
-!   ---------------------------------------------
-
-!   
-!   INPUT: 
-!   R2SO4: aerosol H2SO4 weight fraction (percent)
-!   t_seri: temperature (K)
-!   klon: number of latitude bands in the model domain
-!   klev: number of altitude bands in the model domain
-!   for IFS: perhaps add another dimension for longitude
-!
-!   OUTPUT: 
-!   DENSO4: aerosol mass density (gr/cm3 = aerosol mass/aerosol volume)
-!   
-    USE dimphy, ONLY : klon,klev
-    USE phys_local_var_mod, ONLY: R2SO4, DENSO4
-    
-    IMPLICIT NONE
-    
-    REAL,DIMENSION(klon,klev),INTENT(IN)   :: t_seri  ! Temperature
-        
-    INTEGER i,j
-    
-!----------------------------------------------------------------------
-!	... Local variables
-!----------------------------------------------------------------------
-      real, parameter :: a9 = -268.2616e4, a10 = 576.4288e3
-      
-      real :: a0, a1, a2, a3, a4, a5, a6, a7 ,a8
-      real :: c1, c2, c3, c4, w
-      
-      
-!   Loop on model domain (2 dimension for UPMC model; 3 for IFS)
-    DO i=1,klon
-       DO j=1,klev
-!----------------------------------------------------------------------
-!	... Temperature variables
-!----------------------------------------------------------------------
-          c1 = t_seri(I,J)- 273.15
-          c2 = c1**2
-          c3 = c1*c2
-          c4 = c1*c3
-!----------------------------------------------------------------------
-!	Polynomial Coefficients
-!----------------------------------------------------------------------
-          a0 = 999.8426 + 334.5402e-4*c1 - 569.1304e-5*c2
-          a1 = 547.2659 - 530.0445e-2*c1 + 118.7671e-4*c2 + 599.0008e-6*c3
-          a2 = 526.295e1 + 372.0445e-1*c1 + 120.1909e-3*c2 - 414.8594e-5*c3 + 119.7973e-7*c4
-          a3 = -621.3958e2 - 287.7670*c1 - 406.4638e-3*c2 + 111.9488e-4*c3 + 360.7768e-7*c4
-          a4 = 409.0293e3 + 127.0854e1*c1 + 326.9710e-3*c2 - 137.7435e-4*c3 - 263.3585e-7*c4
-          a5 = -159.6989e4 - 306.2836e1*c1 + 136.6499e-3*c2 + 637.3031e-5*c3
-          a6 = 385.7411e4 + 408.3717e1*c1 - 192.7785e-3*c2
-          a7 = -580.8064e4 - 284.4401e1*c1
-          a8 = 530.1976e4 + 809.1053*c1
-!----------------------------------------------------------------------
-!	... Summation
-!----------------------------------------------------------------------
-!     w : H2SO4 Weight fraction
-          w=r2SO4(i,j)*0.01
-          DENSO4(i,j) = 0.001*(a0 + w*(a1 + w*(a2 + w*(a3 + w*(a4 +  & 
-               w*(a5 + w*(a6 + w*(a7 + w*(a8 + w*(a9 + w*a10))))))))))
-          DENSO4(i,j) = max (0.0, DENSO4(i,j) )
-
-       ENDDO
-    ENDDO
-
-  END SUBROUTINE DENH2SA_TABA
   
 !****************************************************************
@@ -764,4 +764,299 @@
        RETURN
        END SUBROUTINE
-
+!********************************************************************
+!-----------------------------------------------------------------------
+      real function psh2so4(T) result(psh2so4_out)
+!     equilibrium H2SO4 pressure over pure H2SO4 solution (Pa)
+!
+!---->Ayers et.al. (1980), GRL (7) pp 433-436
+!     plus corrections for lower temperatures by Kulmala and Laaksonen (1990)
+!     and Noppel et al. (1990)
+
+      implicit none
+      real, intent(in) :: T
+      real, parameter ::      &
+              &  b1=1.01325e5, &
+              &  b2=11.5,  &
+              &  b3=1.0156e4,  &
+              &  b4=0.38/545., &
+              &  tref=360.15
+
+!     saturation vapor pressure ( N/m2 = Pa = kg/(m.s2) )
+      psh2so4_out=b1*exp(  -b2 +b3*( 1./tref-1./T  &
+           &  +b4*(1.+log(tref/T)-tref/T) )   )  
+
+       return
+    end function psh2so4
+!-----------------------------------------------------------------------
+    real function ndsh2so4(T) result(ndsh2so4_out)
+!     equilibrium H2SO4 number density over pure H2SO4 (molec/cm3)
+
+      implicit none
+      real, intent(in) :: T
+      real :: presat
+
+!     Boltzmann constant ( 1.38065e-23 J/K = m2⋅kg/(s2⋅K) )
+!      akb idem in cm2⋅g/(s2⋅K) 
+      real, parameter :: akb=1.38065e-16
+
+!     pure h2so4 saturation vapor pressure (Pa)
+      presat=psh2so4(T)
+!     saturation number density (1/cm3) - (molec/cm3)
+      ndsh2so4_out=presat*10./(akb*T)
+
+       return
+     end function ndsh2so4
+!-----------------------------------------------------------------------
+     real function psh2o(T) result(psh2o_out)
+!     equilibrium H2O pressure over pure liquid water (Pa)
+!
+      implicit none
+      real, intent(in) :: T
+
+      if(T.gt.229.) then
+!        Preining et al., 1981 (from Kulmala et al., 1998)
+!        saturation vapor pressure (N/m2 = 1 Pa = 1 kg/(m·s2))
+         psh2o_out=exp( 77.34491296  -7235.424651/T &
+             &                 -8.2*log(T) + 5.7133e-3*T )
+      else
+!        Tabazadeh et al., 1997, parameterization for 185<T<260
+!        saturation water vapor partial pressure (mb = hPa =1.E2 kg/(m·s2))
+!        or from Clegg and Brimblecombe , J. Chem. Eng., p43, 1995.
+;
+         psh2o_out=18.452406985 -3505.1578807/T &
+              &    -330918.55082/(T*T)             &
+              &    +12725068.262/(T*T*T)
+!        in Pa
+         psh2o_out=100.*exp(psh2o_out)
+      end if
+!      print*,psh2o_out
+      
+       return
+     end function psh2o
+!-----------------------------------------------------------------------
+     real function density(T,so4mfrac) result(density_out)
+!        calculation of particle density (gr/cm3)
+
+!        requires Temperature (T) and acid mass fraction (so4mfrac)
+!---->Vehkamaeki et al. (2002)
+
+      implicit none
+      real, intent(in) :: T, so4mfrac
+      real, parameter :: &
+           &      a1= 0.7681724,&
+           &      a2= 2.184714, &
+           &      a3= 7.163002, &
+           &      a4=-44.31447, &
+           &      a5= 88.74606, &
+           &      a6=-75.73729, &
+           &      a7= 23.43228
+      real, parameter :: &
+           &      b1= 1.808225e-3, &
+           &      b2=-9.294656e-3, &
+           &      b3=-3.742148e-2, &
+           &      b4= 2.565321e-1, &
+           &      b5=-5.362872e-1, &
+           &      b6= 4.857736e-1, &
+           &      b7=-1.629592e-1
+      real, parameter :: &
+           &      c1=-3.478524e-6, &
+           &      c2= 1.335867e-5, &
+           &      c3= 5.195706e-5, &
+           &      c4=-3.717636e-4, &
+           &      c5= 7.990811e-4, &
+           &      c6=-7.458060e-4, &
+           &      c7= 2.581390e-4
+      real :: a,b,c,so4m2,so4m3,so4m4,so4m5,so4m6
+      
+      so4m2=so4mfrac*so4mfrac
+      so4m3=so4mfrac*so4m2
+      so4m4=so4mfrac*so4m3
+      so4m5=so4mfrac*so4m4
+      so4m6=so4mfrac*so4m5
+
+      a=+a1+a2*so4mfrac+a3*so4m2+a4*so4m3 &
+         &     +a5*so4m4+a6*so4m5+a7*so4m6
+      b=+b1+b2*so4mfrac+b3*so4m2+b4*so4m3 &
+         &     +b5*so4m4+b6*so4m5+b7*so4m6
+      c=+c1+c2*so4mfrac+c3*so4m2+c4*so4m3 &
+         &     +c5*so4m4+c6*so4m5+c7*so4m6
+      density_out=(a+b*T+c*T*T) ! units are gm/cm**3
+
+       return
+     end function density
+!-----------------------------------------------------------------------
+     real function surftension(T,so4frac) result(surftension_out)
+!        calculation of surface tension (mN/meter)
+!        requires Temperature (T) and acid mole fraction (so4frac)
+!---->Vehkamaeki et al. (2002)
+
+      implicit none
+      real,intent(in) :: T, so4frac
+      real :: a,b,so4mfrac,so4m2,so4m3,so4m4,so4m5,so4sig
+      real, parameter :: &
+            &     a1= 0.11864, &
+            &     a2=-0.11651, &
+            &     a3= 0.76852, &
+            &     a4=-2.40909, &
+            &     a5= 2.95434, &
+            &     a6=-1.25852
+      real, parameter :: &
+            &     b1=-1.5709e-4, &
+            &     b2= 4.0102e-4, &
+            &     b3=-2.3995e-3, &
+            &     b4= 7.611235e-3, &
+            &     b5=-9.37386e-3, &
+            &     b6= 3.89722e-3
+      real, parameter :: convfac=1.e3  ! convert from newton/m to dyne/cm
+      real, parameter :: Mw=18.01528, Ma=98.079
+
+!     so4 mass fraction
+      so4mfrac=Ma*so4frac/( Ma*so4frac+Mw*(1.-so4frac) )
+      so4m2=so4mfrac*so4mfrac
+      so4m3=so4mfrac*so4m2
+      so4m4=so4mfrac*so4m3
+      so4m5=so4mfrac*so4m4
+
+      a=+a1+a2*so4mfrac+a3*so4m2+a4*so4m3+a5*so4m4+a6*so4m5
+      b=+b1+b2*so4mfrac+b3*so4m2+b4*so4m3+b5*so4m4+b6*so4m5
+      so4sig=a+b*T
+      surftension_out=so4sig*convfac
+
+       return
+     end function surftension
+!-----------------------------------------------------------------------
+     real function wph2so4(pph2o,T) result(wph2so4_out)
+!     Calculates the equilibrium composition of h2so4 aerosols
+!     as a function of temperature and  H2O pressure, using
+!     the parameterization of Tabazadeh et al., GRL, p1931, 1997.
+!
+!   Parameters
+!
+!    input:
+!      T.....temperature (K)
+!      pph2o..... amhbiant 2o pressure (Pa)
+!
+!    output:
+!      wph2so4......sulfuric acid composition (weight percent wt % h2so4)
+!                     = h2so4 mass fraction*100.
+!
+      implicit none
+      real, intent(in) :: pph2o, T 
+      
+      real :: aw, rh, y1, y2, sulfmolal
+  
+!       psh2o(T): equilibrium H2O pressure over pure liquid water (Pa)
+!       relative humidity 
+        rh=pph2o/psh2o(T)
+!       water activity
+!        aw=min( 0.999,max(1.e-3,rh) )
+        aw=min( 0.999999999,max(1.e-8,rh) ) 
+
+!       composition
+!       calculation of h2so4 molality
+            if(aw .le. 0.05 .and. aw .gt. 0.) then
+               y1=12.372089320*aw**(-0.16125516114) &
+                 &  -30.490657554*aw -2.1133114241
+               y2=13.455394705*aw**(-0.19213122550) &
+                 &  -34.285174607*aw -1.7620073078
+            else if(aw .le. 0.85 .and. aw .gt. 0.05) then
+               y1=11.820654354*aw**(-0.20786404244) &
+                 &  -4.8073063730*aw -5.1727540348
+               y2=12.891938068*aw**(-0.23233847708) &
+                 &  -6.4261237757*aw -4.9005471319
+            else
+               y1=-180.06541028*aw**(-0.38601102592) &
+                 &  -93.317846778*aw +273.88132245
+               y2=-176.95814097*aw**(-0.36257048154) &
+                 &  -90.469744201*aw +267.45509988
+            end if
+!        h2so4 molality (m=moles of h2so4 (solute)/ kg of h2o(solvent))
+         sulfmolal = y1+((T-190.)*(y2-y1)/70.)
+
+!        for a solution containing mh2so4 and mh2o: 
+!        sulfmolal = (mh2so4(gr)/h2so4_molar_mass(gr/mole)) / (mh2o(gr)*1.e-3)
+!        mh2o=1.e3*(mh2so4/Mh2so4)/sulfmolal=1.e3*mh2so4/(Mh2so4*sulfmolal)
+!        h2so4_mass_fraction = mfh2so4 = mh2so4/(mh2o + mh2so4)
+!        mh2o=mh2so4*(1-mfh2so4)/mfh2so4
+!        combining the 2 equations
+!        1.e3*mh2so4/(Mh2so4*sulfmolal) = mh2so4*(1-mfh2so4)/mfh2so4
+!        1.e3/(Mh2so4*sulfmolal) = (1-mfh2so4)/mfh2so4
+!        1000*mfh2so4 = (1-mfh2so4)*Mh2so4*sulfmolal
+!        mfh2so4*(1000.+Mh2so4*sulfmolal) = Mh2so4*sulfmolal
+!        mfh2so4 = Mh2so4*sulfmolal / (1000.+Mh2so4*sulfmolal) 
+!        wph2so4 (% mass fraction)= 100.*Mh2so4*sulfmolal / (1000.+Mh2so4*sulfmolal) 
+!        recall activity of i = a_i = P_i/P_pure_i and 
+!          activity coefficient of i = gamma_i = a_i/X_i (X_i: mole fraction of i)
+!        so  P_i = gamma_i*X_i*P_pure_i
+!        if ideal solution, gamma_i=1, P_i = X_i*P_pure_i
+
+!        h2so4 weight precent
+         wph2so4_out = 9800.*sulfmolal/(98.*sulfmolal+1000.)
+!         print*,rh,pph2o,psh2o(T),vpice(T)
+!         print*,T,aw,sulfmolal,wph2so4_out
+         wph2so4_out = max(wph2so4_out,15.)
+         wph2so4_out = min(wph2so4_out,99.999)
+
+       return
+     end function wph2so4
+!-----------------------------------------------------------------------
+     real function solh2so4(T,xa) result(solh2so4_out)
+!     equilibrium h2so4 number density over H2SO4/H2O solution (molec/cm3)
+
+      implicit none
+      real, intent(in) :: T, xa       ! T(K)  xa(H2SO4 mass fraction)
+      
+      real :: xw, a12,b12, cacta, presat
+      
+      xw=1.0-xa
+
+!     pure h2so4 saturation number density (molec/cm3)
+      presat=ndsh2so4(T)
+!     compute activity of acid 
+      a12=5.672E3 -4.074E6/T +4.421E8/(T*T)
+      b12=1./0.527
+      cacta=10.**(a12*xw*xw/(xw+b12*xa)**2/T)
+!     h2so4 saturation number density over H2SO4/H2O solution (molec/cm3)
+      solh2so4_out=cacta*xa*presat
+
+       return
+     end function solh2so4
+!-----------------------------------------------------------------------      
+     real function rpmvh2so4(T,ws) result(rpmvh2so4_out)
+!     partial molar volume of h2so4 in h2so4/h2o solution (cm3/mole)
+
+      implicit none
+      real, intent(in) :: T, ws
+      real, dimension(22),parameter :: x=(/  &
+       & 2.393284E-02,-4.359335E-05,7.961181E-08,0.0,-0.198716351, &
+       & 1.39564574E-03,-2.020633E-06,0.51684706,-3.0539E-03,4.505475E-06, &
+       & -0.30119511,1.840408E-03,-2.7221253742E-06,-0.11331674116, &
+       & 8.47763E-04,-1.22336185E-06,0.3455282,-2.2111E-03,3.503768245E-06, &
+       & -0.2315332,1.60074E-03,-2.5827835E-06/)
+      
+      real :: w
+
+        w=ws*0.01
+        rpmvh2so4_out=x(5)+x(6)*T+x(7)*T*T+(x(8)+x(9)*T+x(10)*T*T)*w &
+          +(x(11)+x(12)*T+x(13)*T*T)*w*w
+!       h2so4 partial molar volume in h2so4/h2o solution (cm3/mole)
+        rpmvh2so4_out=rpmvh2so4_out*1000.
+        
+       return
+     end function rpmvh2so4
+!-----------------------------------------------------------------------
+     real function rmvh2o(T) result(rmvh2o_out)
+!     molar volume of pure h2o (cm3/mole)
+
+       implicit none
+       real, intent(in) :: T 
+       real, parameter :: x1=2.393284E-02,x2=-4.359335E-05,x3=7.961181E-08
+
+!      1000: L/mole ->  cm3/mole
+!      pure h2o molar volume (cm3/mole)
+       rmvh2o_out=(x1+x2*T+x3*T*T)*1000.
+       
+       return
+     end function rmvh2o
+!
 END MODULE sulfate_aer_mod
Index: LMDZ6/branches/cirrus/libf/phylmd/StratAer/traccoag_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/StratAer/traccoag_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/StratAer/traccoag_mod.F90	(revision 5202)
@@ -9,8 +9,9 @@
        presnivs, xlat, xlon, pphis, pphi, &
        t_seri, pplay, paprs, sh, rh, tr_seri)
-
+    
     USE phys_local_var_mod, ONLY: mdw, R2SO4, DENSO4, f_r_wet, surf_PM25_sulf, & 
-        & budg_emi_ocs, budg_emi_so2, budg_emi_h2so4, budg_emi_part 
-
+        & budg_emi_ocs, budg_emi_so2, budg_emi_h2so4, budg_emi_part, &
+        & R2SO4B, DENSO4B, f_r_wetB, sulfmmr, SAD_sulfate, sulfmmr_mode, nd_mode, reff_sulfate
+    
     USE dimphy
     USE infotrac_phy, ONLY : nbtr_bin, nbtr_sulgas, nbtr, id_SO2_strat
@@ -56,5 +57,5 @@
     REAL                                   :: m_aer_emiss_vol_daily ! daily injection mass emission
     REAL                                   :: m_aer               ! aerosol mass
-    INTEGER                                :: it, k, i, ilon, ilev, itime, i_int, ieru
+    INTEGER                                :: it, k, i, j, ilon, ilev, itime, i_int, ieru
     LOGICAL,DIMENSION(klon,klev)           :: is_strato           ! true = above tropopause, false = below
     REAL,DIMENSION(klon,klev)              :: m_air_gridbox       ! mass of air in every grid box [kg]
@@ -82,4 +83,5 @@
     INTEGER                                :: injdur_sai          ! injection duration for SAI case [days]
     INTEGER                                :: yr, is_bissext
+    REAL                                   :: samoment2, samoment3! 2nd and 3rd order moments of size distribution
 
     IF (is_mpi_root .AND. flag_verbose_strataer) THEN
@@ -88,4 +90,5 @@
     ENDIF
     
+    !   radius [m]
     DO it=1, nbtr_bin
       r_bin(it)=mdw(it)/2.
@@ -117,13 +120,9 @@
 
     IF(flag_new_strat_compo) THEN
-       IF(debutphy) WRITE(lunout,*) 'traccoag: USE STRAT COMPO from Tabazadeh 1994', flag_new_strat_compo
-       ! STRACOMP (H2O, P, t_seri -> aerosol composition (R2SO4)) : binary routine (from reprobus)
-       ! H2SO4 mass fraction in aerosol (%) from Tabazadeh et al. (1994).
-       CALL stracomp_bin(sh,t_seri,pplay)
-       
-       ! aerosol density (gr/cm3) - from Tabazadeh
-       CALL denh2sa_taba(t_seri)
+       IF(debutphy) WRITE(lunout,*) 'traccoag: COMPO/DENSITY (Tabazadeh 97) + H2O kelvin effect', flag_new_strat_compo
+       ! STRACOMP (H2O, P, t_seri, R -> R2SO4 + Kelvin effect) : Taba97, Socol, etc...
+       CALL stracomp_kelvin(sh,t_seri,pplay)
     ELSE
-       IF(debutphy) WRITE(lunout,*) 'traccoag: USE STRAT COMPO from Bekki 2D model', flag_new_strat_compo
+       IF(debutphy) WRITE(lunout,*) 'traccoag: COMPO from Bekki 2D model', flag_new_strat_compo
        ! STRACOMP (H2O, P, t_seri -> aerosol composition (R2SO4)) 
        ! H2SO4 mass fraction in aerosol (%)
@@ -132,9 +131,9 @@
        ! aerosol density (gr/cm3)
        CALL denh2sa(t_seri)
+       
+       ! compute factor for converting dry to wet radius (for every grid box)
+       f_r_wet(:,:) = (dens_aer_dry/(DENSO4(:,:)*1000.)/(R2SO4(:,:)/100.))**(1./3.)
     ENDIF
     
-! compute factor for converting dry to wet radius (for every grid box)
-    f_r_wet(:,:) = (dens_aer_dry/(DENSO4(:,:)*1000.)/(R2SO4(:,:)/100.))**(1./3.)
-
 !--calculate mass of air in every grid box
     DO ilon=1, klon
@@ -348,4 +347,68 @@
     ENDDO
     
+!--compute 
+!     sulfmmr: Sulfate aerosol concentration (dry mixing ratio) (condensed H2SO4 mmr)
+!     SAD_sulfate: SAD all aerosols (cm2/cm3) (must be WET)
+!     sulfmmr_mode: sulfate(=H2SO4 if dry) MMR in different modes (ambiguous but based on sulfmmr, it mus be DRY(?) mmr)
+!     nd_mode: DRY(?) particle concentration in different modes (part/m3)
+     sulfmmr(:,:)=0.0
+     SAD_sulfate(:,:)=0.0
+     sulfmmr_mode(:,:,:)=0.0
+     nd_mode(:,:,:)=0.0
+     reff_sulfate(:,:)=0.0
+     
+     DO i=1,klon
+        DO j=1,klev
+           samoment2=0.0
+           samoment3=0.0
+           DO it=1, nbtr_bin
+              !surf_PM25_sulf(i)=surf_PM25_sulf(i)+tr_seri(i,1,it+nbtr_sulgas)*m_part(i,1,it) &
+              !assume that particles consist of ammonium sulfate at the surface (132g/mol) 
+              !and are dry at T = 20 deg. C and 50 perc. humidity
+              
+              !     sulfmmr_mode: sulfate(=H2SO4 if dry) MMR in different modes (based on sulfmmr, it must be DRY mmr)
+              !     equivalent to condensed H2SO4 mmr= H2SO4 kg / kgA in bin it
+              sulfmmr_mode(i,j,it) = tr_seri(i,j,it+nbtr_sulgas) &        ! [DRY part/kgA in bin it] 
+                   &  *(4./3.)*RPI*(mdw(it)/2.)**3.   &                   ! [mdw: dry diameter in m] 
+                   &  *dens_aer_dry                                       ! [dry aerosol mass density in kg/m3] 
+              
+              !     sulfmmr: Sulfate aerosol concentration (dry mass mixing ratio) 
+              !     equivalent to total condensed H2SO4 mmr (H2SO4 kg / kgA
+              sulfmmr(i,j) = sulfmmr(i,j) + sulfmmr_mode(i,j,it)
+              
+              !     nd_mode: particle concentration in different modes (DRY part/m3)
+              nd_mode(i,j,it) = tr_seri(i,j,it+nbtr_sulgas) &             ! [DRY part/kgA in bin it] 
+                   & *pplay(i,j)/t_seri(i,j)/RD                           ! [air mass concentration in kg air /m3A]
+              
+              IF(flag_new_strat_compo) THEN
+                 !     SAD_sulfate: SAD WET sulfate aerosols (cm2/cm3)
+                 SAD_sulfate(i,j) = SAD_sulfate(i,j) + nd_mode(i,j,it) &     ! [DRY part/m3A (in bin it)] 
+                      &  *4.*RPI*( mdw(it)*f_r_wetB(i,j,it)/2. )**2. &       ! [WET SA of part it in m2] 
+                      &  *1.e-2                                              ! conversion from m2/m3 to cm2/cm3A
+!    samoment2 : 2nd order moment of WET sulfate aerosols (m2/m3)
+                 samoment2 = samoment2 + nd_mode(i,j,it) &     ! [DRY part/m3A (in bin it)]
+                      &  *( mdw(it)*f_r_wetB(i,j,it)/2. )**2.                     ! [WET SA of part it in m2]
+!    samoment3 : 3nd order moment of WET sulfate aerosols (cm2/cm3)
+                 samoment3 = samoment3 + nd_mode(i,j,it) &     ! [DRY part/m3A (in bin it)]
+                      &  *( mdw(it)*f_r_wetB(i,j,it)/2. )**3.                     ! [WET SA of part it in m2]
+              ELSE
+!     SAD_sulfate: SAD WET sulfate aerosols (cm2/cm3)
+                 SAD_sulfate(i,j) = SAD_sulfate(i,j) + nd_mode(i,j,it) &     ! [DRY part/m3A (in bin it)] 
+                      &  *4.*RPI*( mdw(it)*f_r_wet(i,j)/2. )**2. &           ! [WET SA of part it in m2] 
+                      &  *1.e-2                                              ! conversion from m2/m3 to cm2/cm3A
+!    samoment2 : 2nd order moment of WET sulfate aerosols (m2/m3)
+                 samoment2 = samoment2 + nd_mode(i,j,it) &     ! [DRY part/m3A (in bin it)]
+                      &  *( mdw(it)*f_r_wet(i,j)/2. )**2.                          ! [WET SA of part it in m2]
+!    samoment3 : 3nd order moment of WET sulfate aerosols (cm2/cm3)
+                 samoment3 = samoment3 + nd_mode(i,j,it) &     ! [DRY part/m3A (in bin it)]
+                      &  *( mdw(it)*f_r_wet(i,j)/2. )**3.                          ! [WET SA of part it in m2]
+              ENDIF
+           ENDDO
+!     reff_sulfate: effective radius of WET sulfate aerosols (cm)
+           reff_sulfate(i,j) = (samoment3 / samoment2) &
+                & *1.e2                                              ! conversion from m to cm
+        ENDDO
+     ENDDO
+     
   END SUBROUTINE traccoag
 
Index: LMDZ6/branches/cirrus/libf/phylmd/add_phys_tend_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/add_phys_tend_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/add_phys_tend_mod.F90	(revision 5202)
@@ -774,5 +774,5 @@
       bilh_bnd = (-(rcw-rcpd)*t_seri(1,1) + rlvtt) * rain_lsc(1) &
     &         + (-(rcs-rcpd)*t_seri(1,1) + rlstt) * snow_lsc(1)
-  CASE("bs") param
+  CASE("bsss") param
       bilq_bnd = - bs_fall(1)
       bilh_bnd = (-(rcs-rcpd)*t_seri(1,1) + rlstt) * bs_fall(1)
Index: LMDZ6/branches/cirrus/libf/phylmd/cdrag_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/cdrag_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/cdrag_mod.F90	(revision 5202)
@@ -23,4 +23,6 @@
 
   USE dimphy
+  USE coare_cp_mod, ONLY: coare_cp
+  USE coare30_flux_cnrm_mod, ONLY: coare30_flux_cnrm
   USE indice_sol_mod
   USE print_control_mod, ONLY: lunout, prt_level
@@ -341,8 +343,16 @@
          LPWG    = .false.
          call ini_csts
-         call coare30_flux_cnrm(z_0m,t1(i),tsurf(i), q1(i),  &
-             sqrt(zdu2),zgeop1(i)/RG,zgeop1(i)/RG,psol(i),qsurf(i),PQSAT, &
-             PSFTH,PFSTQ,PUSTAR,PCD,PCDN,PCH,PCE,PRI, &
-             PRESA,prain,pat1(i),z_0h, LPRECIP, LPWG, coeffs) 
+         block
+           real, dimension(1) :: z0m_1d, z_0h_1d, sqrt_zdu2_1d, zgeop1_rg_1d  ! convert scalar to 1D for call
+           z0m_1d = z0m
+           z_0h_1d = z0h
+           sqrt_zdu2_1d = sqrt(zdu2)
+           zgeop1_rg_1d=zgeop1(i)/RG
+           call coare30_flux_cnrm(z0m_1d,t1(i),tsurf(i), q1(i),  &
+               sqrt_zdu2_1d,zgeop1_rg_1d,zgeop1_rg_1d,psol(i),qsurf(i),PQSAT, &
+               PSFTH,PFSTQ,PUSTAR,PCD,PCDN,PCH,PCE,PRI, &
+               PRESA,prain,pat1(i),z_0h_1d, LPRECIP, LPWG, coeffs)
+
+         end block
          cdmm(i) = coeffs(1)
          cdhh(i) = coeffs(2)
Index: LMDZ6/branches/cirrus/libf/phylmd/clesphys.h
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/clesphys.h	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/clesphys.h	(revision 5202)
@@ -110,4 +110,7 @@
        LOGICAL :: ok_3Deffect
 
+!OB flag to activate water mass fixer in physiq
+       LOGICAL :: ok_water_mass_fixer
+
        COMMON/clesphys/                                                 &
 ! REAL FIRST
@@ -161,5 +164,5 @@
      &     , iflag_phytrac, ok_new_lscp, ok_bs, ok_rad_bs               &
      &     ,  iflag_thermals,nsplit_thermals, tau_thermals              &
-     &     , iflag_physiq, ok_3Deffect
+     &     , iflag_physiq, ok_3Deffect, ok_water_mass_fixer
        save /clesphys/
 !$OMP THREADPRIVATE(/clesphys/)
Index: LMDZ6/branches/cirrus/libf/phylmd/coare30_flux_cnrm.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/coare30_flux_cnrm.F90	(revision 5165)
+++ 	(revision )
@@ -1,631 +1,0 @@
-!SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
-!SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
-!SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt  
-!SFX_LIC for details. version 1.
-!     #########
-
-!------------------------ Modif Olivier Torres pour rajout fonction et pas appel ----------------
-
-
-
-real function PSIFCTT(zet)
-
-  real, intent(in) :: zet
-
-  if(zet<0) then
-     x=(1.-(15*zet))**.5 
-     psik=2*log((1+x)/2) 
-     x=(1.-(34.15*zet))**.3333 
-     psic=1.5*log((1.+x+x*x)/3.)-sqrt(3.)*atan((1.+2.*x)/sqrt(3.))+4.*atan(1.)/sqrt(3.) 
-     f=zet*zet/(1+zet*zet) 
-     PSIFCTT=(1-f)*psik+f*psic   
-
-  else
-     c=min(50.,.35*zet) 
-     PSIFCTT=-((1.+2./3.*zet)**1.5+.6667*(zet-14.28)/exp(c)+8.525)
-  endif
-end FUNCTION PSIFCTT
-
-real function PSIFCTU(zet)
-
-  real, intent(in) :: zet
-
-  if (zet<0) then 
-
-     x=(1.-15.*zet)**.25 
-     psik=2.*log((1.+x)/2.)+log((1.+x*x)/2.)-2.*atan(x)+2.*atan(1.) 
-     x=(1.-10.15*zet)**.3333 
-     psic=1.5*log((1.+x+x*x)/3.)-sqrt(3.)*atan((1.+2.*x)/sqrt(3.))+4.*atan(1.)/sqrt(3.) 
-     f=zet*zet/(1+zet*zet) 
-     PSIFCTU=(1-f)*psik+f*psic                                                
-  else
-     c=min(50.,.35*zet) 
-     PSIFCTU=-((1+1.0*zet)**1.0+.667*(zet-14.28)/exp(c)+8.525)
-  endif
-END FUNCTION PSIFCTU
-
-!----------------------------------- Fin Modif ---------------------------------------------------
-
-
-SUBROUTINE COARE30_FLUX_CNRM(PZ0SEA,PTA,PSST,PQA,  &
-            PVMOD,PZREF,PUREF,PPS,PQSATA,PQSAT,PSFTH,PSFTQ,PUSTAR,PCD,PCDN,PCH,PCE,PRI,&
-            PRESA,PRAIN,PPA,PZ0HSEA,LPRECIP, LPWG,coeffs )  
-!     #######################################################################
-!
-!
-!!****  *COARE25_FLUX*  
-!!
-!!    PURPOSE
-!!    -------
-!      Calculate the surface fluxes of heat, moisture, and momentum over
-!      sea surface with bulk algorithm COARE3.0. 
-!     
-!!**  METHOD
-!!    ------
-!      transfer coefficients were obtained using a dataset which combined COARE
-!      data with those from three other ETL field experiments, and reanalysis of
-!      the HEXMAX data (DeCosmos et al. 1996). 
-!      ITERMAX=3 
-!      Take account of the surface gravity waves on the velocity roughness and 
-!      hence the momentum transfer coefficient
-!        NGRVWAVES=0 no gravity waves action (Charnock) !default value
-!        NGRVWAVES=1 wave age parameterization of Oost et al. 2002
-!        NGRVWAVES=2 model of Taylor and Yelland 2001
-!
-!!    EXTERNAL
-!!    --------
-!!
-!!    IMPLICIT ARGUMENTS
-!!    ------------------ 
-!!      
-!!    REFERENCE
-!!    ---------
-!!      Fairall et al (2003), J. of Climate, vol. 16, 571-591
-!!      Fairall et al (1996), JGR, 3747-3764
-!!      Gosnell et al (1995), JGR, 437-442
-!!      Fairall et al (1996), JGR, 1295-1308
-!!      
-!!    AUTHOR
-!!    ------
-!!     C. Lebeaupin  *Météo-France* (adapted from C. Fairall's code)
-!!
-!!    MODIFICATIONS
-!!    -------------
-!!      Original     1/06/2006
-!!      B. Decharme    06/2009 limitation of Ri
-!!      B. Decharme    09/2012 Bug in Ri calculation and limitation of Ri in surface_ri.F90
-!!      B. Decharme    06/2013 bug in z0 (output) computation 
-!!      J.Escobar      06/2013  for REAL4/8 add EPSILON management
-!!      C. Lebeaupin   03/2014 bug if PTA=PSST and PEXNA=PEXNS: set a minimum value
-!!                             add abort if no convergence
-!-------------------------------------------------------------------------------
-!
-!*       0.     DECLARATIONS
-!               ------------
-!
-!
-!USE MODD_SEAFLUX_n, ONLY : SEAFLUX_t
-!
-
-!----------Rajout Olive ---------
-USE dimphy
-USE indice_sol_mod
-
-!--------------------------------
-
-USE MODD_CSTS,       ONLY : XKARMAN, XG, XSTEFAN, XRD, XRV, XPI, &
-                            XLVTT, XCL, XCPD, XCPV, XRHOLW, XTT, &
-                            XP00
-
-!USE MODD_SURF_ATM,   ONLY : XVZ0CM
-!
-!USE MODD_SURF_PAR,   ONLY : XUNDEF, XSURF_EPSILON
-!USE MODD_WATER_PAR
-!
-!USE MODI_SURFACE_RI
-!USE MODI_WIND_THRESHOLD
-!USE MODE_COARE30_PSI
-!
-!USE MODE_THERMOS
-!
-!
-!USE MODI_ABOR1_SFX
-!
-!
-!USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
-!USE PARKIND1  ,ONLY : JPRB
-!
-IMPLICIT NONE
-!
-!*      0.1    declarations of arguments
-!
-!
-!
-!TYPE(SEAFLUX_t), INTENT(INOUT) :: S
-!
-REAL, DIMENSION(klon), INTENT(IN)       :: PTA   ! air temperature at atm. level (K)
-REAL, DIMENSION(klon), INTENT(IN)       :: PQA   ! air humidity at atm. level (kg/kg)
-!REAL, DIMENSION(:), INTENT(IN)       :: PEXNA ! Exner function at atm. level
-!REAL, DIMENSION(:), INTENT(IN)       :: PRHOA ! air density at atm. level
-REAL, DIMENSION(klon), INTENT(IN)       :: PVMOD ! module of wind at atm. wind level (m/s)
-REAL, DIMENSION(klon), INTENT(IN)       :: PZREF ! atm. level for temp. and humidity (m)
-REAL, DIMENSION(klon), INTENT(IN)       :: PUREF ! atm. level for wind (m)
-REAL, DIMENSION(klon), INTENT(IN)       :: PSST  ! Sea Surface Temperature (K)
-!REAL, DIMENSION(:), INTENT(IN)       :: PEXNS ! Exner function at sea surface
-REAL, DIMENSION(klon), INTENT(IN)       :: PPS   ! air pressure at sea surface (Pa)
-REAL, DIMENSION(klon), INTENT(IN)       :: PRAIN !precipitation rate (kg/s/m2)
-REAL, DIMENSION(klon), INTENT(IN)       :: PPA        ! air pressure at atm level (Pa)
-REAL, DIMENSION(klon), INTENT(IN)       :: PQSATA        ! air pressure at atm level (Pa)
-!
-REAL, DIMENSION(klon), INTENT(INOUT)    :: PZ0SEA! roughness length over the ocean
-!                                                                                 
-!  surface fluxes : latent heat, sensible heat, friction fluxes
-REAL, DIMENSION(klon), INTENT(OUT)      :: PSFTH ! heat flux (W/m2)
-REAL, DIMENSION(klon), INTENT(OUT)      :: PSFTQ ! water flux (kg/m2/s)
-REAL, DIMENSION(klon), INTENT(OUT)      :: PUSTAR! friction velocity (m/s)
-!
-! diagnostics
-REAL, DIMENSION(klon), INTENT(OUT)      :: PQSAT ! humidity at saturation
-REAL, DIMENSION(klon), INTENT(OUT)      :: PCD   ! heat drag coefficient
-REAL, DIMENSION(klon), INTENT(OUT)      :: PCDN  ! momentum drag coefficient
-REAL, DIMENSION(klon), INTENT(OUT)      :: PCH   ! neutral momentum drag coefficient
-REAL, DIMENSION(klon), INTENT(OUT)      :: PCE  !transfer coef. for latent heat flux
-REAL, DIMENSION(klon), INTENT(OUT)      :: PRI   ! Richardson number
-REAL, DIMENSION(klon), INTENT(OUT)      :: PRESA ! aerodynamical resistance
-REAL, DIMENSION(klon), INTENT(OUT)      :: PZ0HSEA ! heat roughness length
-
-LOGICAL,            INTENT(IN)    :: LPRECIP   !
-LOGICAL,            INTENT(IN)    :: LPWG    ! 
-real, dimension(3), intent(inout)      :: coeffs
-!
-!
-
-!INCLUDE "YOMCST.h"
-!INCLUDE "clesphys.h"
-
-!*      0.2    declarations of local variables
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZVMOD    ! wind intensity
-REAL, DIMENSION(SIZE(PTA))      :: ZPA      ! Pressure at atm. level
-REAL, DIMENSION(SIZE(PTA))      :: ZTA      ! Temperature at atm. level
-REAL, DIMENSION(SIZE(PTA))      :: ZQASAT   ! specific humidity at saturation  at atm. level (kg/kg)
-!
-!rajout
-REAL, DIMENSION(SIZE(PTA))       :: PEXNA      ! Exner function at atm level
-REAL, DIMENSION(SIZE(PTA))       :: PEXNS      ! Exner function at atm level
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZO       ! rougness length ref 
-REAL, DIMENSION(SIZE(PTA))      :: ZWG      ! gustiness factor (m/s)
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZDU,ZDT,ZDQ,ZDUWG !differences
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZUSR        !velocity scaling parameter "ustar" (m/s) = friction velocity
-REAL, DIMENSION(SIZE(PTA))      :: ZTSR        !temperature sacling parameter "tstar" (degC)
-REAL, DIMENSION(SIZE(PTA))      :: ZQSR        !humidity scaling parameter "qstar" (kg/kg)
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZU10,ZT10   !vertical profils (10-m height) 
-REAL, DIMENSION(SIZE(PTA))      :: ZVISA       !kinematic viscosity of dry air
-REAL, DIMENSION(SIZE(PTA))      :: ZO10,ZOT10  !roughness length at 10m
-REAL, DIMENSION(SIZE(PTA))      :: ZCD,ZCT,ZCC
-REAL, DIMENSION(SIZE(PTA))      :: ZCD10,ZCT10 !transfer coef. at 10m
-REAL, DIMENSION(SIZE(PTA))      :: ZRIBU,ZRIBCU
-REAL, DIMENSION(SIZE(PTA))      :: ZETU,ZL10
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZCHARN                      !Charnock number depends on wind module
-REAL, DIMENSION(SIZE(PTA))      :: ZTWAVE,ZHWAVE,ZCWAVE,ZLWAVE !to compute gravity waves' impact
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZZL,ZZTL!,ZZQL    !Obukhovs stability 
-                                                     !param. z/l for u,T,q
-REAL, DIMENSION(SIZE(PTA))      :: ZRR
-REAL, DIMENSION(SIZE(PTA))      :: ZOT,ZOQ           !rougness length ref
-REAL, DIMENSION(SIZE(PTA))      :: ZPUZ,ZPTZ,ZPQZ    !PHI funct. for u,T,q 
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZBF               !constants to compute gustiness factor
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZTAU       !momentum flux (W/m2)
-REAL, DIMENSION(SIZE(PTA))      :: ZHF        !sensible heat flux (W/m2)
-REAL, DIMENSION(SIZE(PTA))      :: ZEF        !latent heat flux (W/m2)
-REAL, DIMENSION(SIZE(PTA))      :: ZWBAR      !diag for webb correction but not used here after
-REAL, DIMENSION(SIZE(PTA))      :: ZTAUR      !momentum flux due to rain (W/m2)
-REAL, DIMENSION(SIZE(PTA))      :: ZRF        !sensible heat flux due to rain (W/m2)
-REAL, DIMENSION(SIZE(PTA))      :: ZCHN,ZCEN  !neutral coef. for heat and vapor
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZLV      !latent heat constant
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZTAC,ZDQSDT,ZDTMP,ZDWAT,ZALFAC ! for precipitation impact
-REAL, DIMENSION(SIZE(PTA))      :: ZXLR                           ! vaporisation  heat  at a given temperature
-REAL, DIMENSION(SIZE(PTA))      :: ZCPLW                          ! specific heat for water at a given temperature 
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZUSTAR2  ! square of friction velocity
-!
-REAL, DIMENSION(SIZE(PTA))      :: ZDIRCOSZW! orography slope cosine (=1 on water!)
-REAL, DIMENSION(SIZE(PTA))      :: ZAC      ! Aerodynamical conductance
-!
-!
-INTEGER, DIMENSION(SIZE(PTA))   :: ITERMAX             ! maximum number of iterations
-!
-REAL    :: ZRVSRDM1,ZRDSRV,ZR2 ! thermodynamic constants
-REAL    :: ZBETAGUST           !gustiness factor
-REAL    :: ZZBL                !atm. boundary layer depth (m)
-REAL    :: ZVISW               !m2/s kinematic viscosity of water
-REAL    :: ZS                  !height of rougness length ref
-REAL    :: ZCH10               !transfer coef. at 10m
-
-REAL    :: QSAT_SEAWATER
-REAL    :: QSATSEAW_1D
-REAL, EXTERNAL :: PSIFCTU, PSIFCTT
-!
-INTEGER :: J, JLOOP    !loop indice
-!REAL(KIND=JPRB) :: ZHOOK_HANDLE
-
-!--------- Modif Olive -----------------
-REAL, DIMENSION(SIZE(PTA))        :: PRHOA
-REAL, PARAMETER                   :: XUNDEF = 1.E+20
-
-REAL       :: XVCHRNK = 0.021
-REAL       :: XVZ0CM = 1.0E-5 
-!REAL       :: XRIMAX
-
-
-INTEGER :: PREF             ! reference pressure for exner function
-INTEGER :: NGRVWAVES        ! Pour le choix du z0
-
-INCLUDE "YOMCST.h"
-INCLUDE "clesphys.h"
-
-!--------------------------------------
-
-
-PRHOA(:) = PPS(:) / (287.1 * PTA(:) * (1.+.61*PQA(:)))
-
-PREF = 100000.                     ! = 1000 hPa
-NGRVWAVES = 1
-
-PEXNA = (PPA/PREF)**(RD/RCPD)
-PEXNS = (PPS/PREF)**(RD/RCPD)
-
-!
-!-------------------------------------------------------------------------------
-!
-!       1.     Initializations
-!              ---------------
-!
-!       1.1   Constants and parameters
-!
-!IF (LHOOK) CALL DR_HOOK('COARE30_FLUX',0,ZHOOK_HANDLE)
-!
-ZRVSRDM1  = XRV/XRD-1. ! 0.607766
-ZRDSRV    = XRD/XRV    ! 0.62198
-ZR2       = 1.-ZRDSRV  ! pas utilisé dans cette routine
-ZBETAGUST = 1.2        ! value based on TOGA-COARE experiment
-ZZBL      = 600.       ! Set a default value for boundary layer depth
-ZS        = 10.        ! Standard heigth =10m
-ZCH10     = 0.00115
-!
-ZVISW     = 1.E-6
-!
-!       1.2   Array initialization by undefined values
-!
-PSFTH (:)=XUNDEF
-PSFTQ (:)=XUNDEF
-PUSTAR(:)=XUNDEF
-!
-PCD(:) = XUNDEF
-PCDN(:) = XUNDEF
-PCH(:) = XUNDEF
-PCE(:) =XUNDEF
-PRI(:) = XUNDEF
-!
-PRESA(:)=XUNDEF
-!
-!-------------------------------------------------------------------------------
-!       2. INITIAL GUESS FOR THE ITERATIVE METHOD 
-!          -------------------------------------
-!
-!       2.0     Temperature 
-!
-! Set a non-zero value for the temperature gradient
-!
-WHERE((PTA(:)*PEXNS(:)/PEXNA(:)-PSST(:))==0.) 
-      ZTA(:)=PTA(:)-1E-3
-ELSEWHERE
-      ZTA(:)=PTA(:)      
-ENDWHERE
-
-!       2.1     Wind and humidity 
-!
-! Sea surface specific humidity 
-!
-!PQSAT(:)=QSAT_SEAWATER(PSST(:),PPS(:))  
-PQSAT(:)=QSATSEAW_1D(PSST(:),PPS(:)) 
-
-
-       
-!              
-! Set a minimum value to wind 
-!
-!ZVMOD(:) = WIND_THRESHOLD(PVMOD(:),PUREF(:))
-
-
-ZVMOD = MAX(PVMOD , 0.1 * MIN(10.,PUREF) )    !set a minimum value to wind
-!ZVMOD = PVMOD    !set a minimum value to wind
-
-!
-! Specific humidity at saturation at the atm. level 
-!
-ZPA(:) = XP00* (PEXNA(:)**(XCPD/XRD))
-!ZQASAT(:) = QSAT_SEAWATER(ZTA(:),ZPA(:)) 
-ZQASAT = QSATSEAW_1D(ZTA(:),ZPA(:)) 
-
-
-!
-!
-ZO(:)  = 0.0001
-ZWG(:) = 0.
-IF (LPWG) ZWG(:) = 0.5
-!
-ZCHARN(:) = 0.011  
-!
-DO J=1,SIZE(PTA)
-  !
-  !      2.2       initial guess
-  !    
-  ZDU(J) = ZVMOD(J)   !wind speed difference with surface current(=0) (m/s)
-                      !initial guess for gustiness factor
-  ZDT(J) = -(ZTA(J)/PEXNA(J)) + (PSST(J)/PEXNS(J)) !potential temperature difference
-  ZDQ(J) = PQSAT(J)-PQA(J)                         !specific humidity difference
-  !
-  ZDUWG(J) = SQRT(ZDU(J)**2+ZWG(J)**2)     !wind speed difference including gustiness ZWG
-  !
-  !      2.3   initialization of neutral coefficients
-  !
-  ZU10(J)  = ZDUWG(J)*LOG(ZS/ZO(J))/LOG(PUREF(J)/ZO(J))
-  ZUSR(J)  = 0.035*ZU10(J)
-  ZVISA(J) = 1.326E-5*(1.+6.542E-3*(ZTA(J)-XTT)+&
-             8.301E-6*(ZTA(J)-XTT)**2-4.84E-9*(ZTA(J)-XTT)**3) !Andrea (1989) CRREL Rep. 89-11
-  ! 
-  ZO10(J) = ZCHARN(J)*ZUSR(J)*ZUSR(J)/XG+0.11*ZVISA(J)/ZUSR(J)
-  ZCD(J)  = (XKARMAN/LOG(PUREF(J)/ZO10(J)))**2  !drag coefficient
-  ZCD10(J)= (XKARMAN/LOG(ZS/ZO10(J)))**2
-  ZCT10(J)= ZCH10/SQRT(ZCD10(J))
-  ZOT10(J)= ZS/EXP(XKARMAN/ZCT10(J))
-  !
-  !-------------------------------------------------------------------------------
-  !             Grachev and Fairall (JAM, 1997)
-  ZCT(J) = XKARMAN/LOG(PZREF(J)/ZOT10(J))      !temperature transfer coefficient
-  ZCC(J) = XKARMAN*ZCT(J)/ZCD(J)               !z/L vs Rib linear coef.
-  !
-  ZRIBCU(J) = -PUREF(J)/(ZZBL*0.004*ZBETAGUST**3) !saturation or plateau Rib
-  !ZRIBU(J) =-XG*PUREF(J)*(ZDT(J)+ZRVSRDM1*(ZTA(J)-XTT)*ZDQ)/&
-  !     &((ZTA(J)-XTT)*ZDUWG(J)**2)
-  ZRIBU(J)  = -XG*PUREF(J)*(ZDT(J)+ZRVSRDM1*ZTA(J)*ZDQ(J))/&
-               (ZTA(J)*ZDUWG(J)**2)  
-  !
-  IF (ZRIBU(J)<0.) THEN
-    ZETU(J) = ZCC(J)*ZRIBU(J)/(1.+ZRIBU(J)/ZRIBCU(J))    !Unstable G and F
-  ELSE
-    ZETU(J) = ZCC(J)*ZRIBU(J)/(1.+27./9.*ZRIBU(J)/ZCC(J))!Stable 
-  ENDIF
-  !
-  ZL10(J) = PUREF(J)/ZETU(J) !MO length
-  !
-ENDDO
-!
-!  First guess M-O stability dependent scaling params. (u*,T*,q*) to estimate ZO and z/L (ZZL)
-ZUSR(:) = ZDUWG(:)*XKARMAN/(LOG(PUREF(:)/ZO10(:))-PSIFCTU(PUREF/ZL10))
-ZTSR(:) = -ZDT(:)*XKARMAN/(LOG(PZREF(:)/ZOT10(:))-PSIFCTT(PZREF/ZL10))
-ZQSR(:) = -ZDQ(:)*XKARMAN/(LOG(PZREF(:)/ZOT10(:))-PSIFCTT(PZREF/ZL10))
-!
-ZZL(:) = 0.0
-!
-DO J=1,SIZE(PTA)
-  !
-  IF (ZETU(J)>50.) THEN
-    ITERMAX(J) = 1
-  ELSE
-    ITERMAX(J) = 3 !number of iterations
-  ENDIF
-  !
-  !then modify Charnork for high wind speeds Chris Fairall's data
-  IF (ZDUWG(J)>10.) ZCHARN(J) = 0.011 + (0.018-0.011)*(ZDUWG(J)-10.)/(18.-10.)
-  IF (ZDUWG(J)>18.) ZCHARN(J) = 0.018
-  !
-  !                3.  ITERATIVE LOOP TO COMPUTE USR, TSR, QSR 
-  !                -------------------------------------------
-  !
-  ZHWAVE(J) = 0.018*ZVMOD(J)*ZVMOD(J)*(1.+0.015*ZVMOD(J))
-  ZTWAVE(J) = 0.729*ZVMOD(J)
-  ZCWAVE(J) = XG*ZTWAVE(J)/(2.*XPI)
-  ZLWAVE(J) = ZTWAVE(J)*ZCWAVE(J)
-  !
-ENDDO
-!
-   
-!
-DO JLOOP=1,MAXVAL(ITERMAX) ! begin of iterative loop
-  !
-  DO J=1,SIZE(PTA)
-    !
-    IF (JLOOP.GT.ITERMAX(J)) CYCLE
-    !
-    IF (NGRVWAVES==0) THEN
-      ZO(J) = ZCHARN(J)*ZUSR(J)*ZUSR(J)/XG + 0.11*ZVISA(J)/ZUSR(J) !Smith 1988
-    ELSE IF (NGRVWAVES==1) THEN
-      ZO(J) = (50./(2.*XPI))*ZLWAVE(J)*(ZUSR(J)/ZCWAVE(J))**4.5 &
-              + 0.11*ZVISA(J)/ZUSR(J)                       !Oost et al. 2002  
-    ELSE IF (NGRVWAVES==2) THEN
-      ZO(J) = 1200.*ZHWAVE(J)*(ZHWAVE(J)/ZLWAVE(J))**4.5 &
-              + 0.11*ZVISA(J)/ZUSR(J)                       !Taulor and Yelland 2001  
-    ENDIF
-    !
-    ZRR(J) = ZO(J)*ZUSR(J)/ZVISA(J)
-    ZOQ(J) = MIN(1.15E-4 , 5.5E-5/ZRR(J)**0.6)
-    ZOT(J) = ZOQ(J)
-    !
-    ZZL(J) = XKARMAN * XG * PUREF(J) * &
-              ( ZTSR(J)*(1.+ZRVSRDM1*PQA(J)) + ZRVSRDM1*ZTA(J)*ZQSR(J) ) / &
-              ( ZTA(J)*ZUSR(J)*ZUSR(J)*(1.+ZRVSRDM1*PQA(J)) )  
-    ZZTL(J)= ZZL(J)*PZREF(J)/PUREF(J)  ! for T 
-!    ZZQL(J)=ZZL(J)*PZREF(J)/PUREF(J)  ! for Q
-  ENDDO
-  !
-  ZPUZ(:) = PSIFCTU(ZZL(:))     
-  ZPTZ(:) = PSIFCTT(ZZTL(:))
-  !
-  DO J=1,SIZE(PTA)
-    !
-    ! ZPQZ(J)=PSIFCTT(ZZQL(J))    
-    ZPQZ(J) = ZPTZ(J)
-    !
-    !             3.1 scale parameters
-    !
-    ZUSR(J) = ZDUWG(J)*XKARMAN/(LOG(PUREF(J)/ZO(J)) -ZPUZ(J))
-    ZTSR(J) = -ZDT(J)  *XKARMAN/(LOG(PZREF(J)/ZOT(J))-ZPTZ(J))
-    ZQSR(J) = -ZDQ(J)  *XKARMAN/(LOG(PZREF(J)/ZOQ(J))-ZPQZ(J))
-    !
-    !             3.2 Gustiness factor (ZWG)
-    !
-    IF(LPWG) THEN
-      ZBF(J) = -XG/ZTA(J)*ZUSR(J)*(ZTSR(J)+ZRVSRDM1*ZTA(J)*ZQSR(J))
-      IF (ZBF(J)>0.) THEN
-        ZWG(J) = ZBETAGUST*(ZBF(J)*ZZBL)**(1./3.)
-      ELSE
-        ZWG(J) = 0.2
-      ENDIF
-    ENDIF  
-    ZDUWG(J) = SQRT(ZVMOD(J)**2 + ZWG(J)**2)
-    !
-  ENDDO
-  !
-ENDDO
-!-------------------------------------------------------------------------------
-!
-!            4.  COMPUTE transfer coefficients PCD, PCH, ZCE and SURFACE FLUXES
-!                --------------------------------------------------------------
-!
-ZTAU(:) = XUNDEF
-ZHF(:)  = XUNDEF
-ZEF(:)  = XUNDEF
-!
-ZWBAR(:) = 0.
-ZTAUR(:) = 0.
-ZRF(:)   = 0.
-!
-DO J=1,SIZE(PTA)
-  !
-  !
-  !            4. transfert coefficients PCD, PCH and PCE 
-  !                 and neutral PCDN, ZCHN, ZCEN 
-  !
-  PCD(J) = (ZUSR(J)/ZDUWG(J))**2.
-  PCH(J) = ZUSR(J)*ZTSR(J)/(ZDUWG(J)*(ZTA(J)*PEXNS(J)/PEXNA(J)-PSST(J)))
-  PCE(J) = ZUSR(J)*ZQSR(J)/(ZDUWG(J)*(PQA(J)-PQSAT(J)))
-  !
-  PCDN(J) = (XKARMAN/LOG(ZS/ZO(J)))**2.
-  ZCHN(J) = (XKARMAN/LOG(ZS/ZO(J)))*(XKARMAN/LOG(ZS/ZOT(J)))
-  ZCEN(J) = (XKARMAN/LOG(ZS/ZO(J)))*(XKARMAN/LOG(ZS/ZOQ(J)))
-  !
-  ZLV(J) = XLVTT + (XCPV-XCL)*(PSST(J)-XTT)
-  !
-  !            4. 2 surface fluxes 
-  !
-  IF (ABS(PCDN(J))>1.E-2) THEN   !!!! secure COARE3.0 CODE 
-    write(*,*) 'pb PCDN in COARE30: ',PCDN(J)
-    write(*,*) 'point: ',J,"/",SIZE(PTA)
-    write(*,*) 'roughness: ', ZO(J)
-    write(*,*) 'ustar: ',ZUSR(J)
-    write(*,*) 'wind: ',ZDUWG(J)
-    CALL abort_physic('COARE30',': PCDN too large -> no convergence',1)
-  ELSE
-    ZTSR(J) = -ZTSR(J)
-    ZQSR(J) = -ZQSR(J)
-    ZTAU(J) = -PRHOA(J)*ZUSR(J)*ZUSR(J)*ZVMOD(J)/ZDUWG(J)
-    ZHF(J)  =  PRHOA(J)*XCPD*ZUSR(J)*ZTSR(J)
-    ZEF(J)  =  PRHOA(J)*ZLV(J)*ZUSR(J)*ZQSR(J)
-    !    
-    !           4.3 Contributions to surface  fluxes due to rainfall
-    !
-    ! SB: a priori, le facteur ZRDSRV=XRD/XRV est introduit pour
-    !     adapter la formule de Clausius-Clapeyron (pour l'air
-    !     sec) au cas humide.
-    IF (LPRECIP) THEN
-      ! 
-      ! heat surface  fluxes
-      !
-      ZTAC(J)  = ZTA(J)-XTT
-      !
-      ZXLR(J)  = XLVTT + (XCPV-XCL)* ZTAC(J)                            ! latent heat of rain vaporization
-      ZDQSDT(J)= ZQASAT(J) * ZXLR(J) / (XRD*ZTA(J)**2)                  ! Clausius-Clapeyron relation
-      ZDTMP(J) = (1.0 + 3.309e-3*ZTAC(J) -1.44e-6*ZTAC(J)*ZTAC(J)) * &  !heat diffusivity
-                  0.02411 / (PRHOA(J)*XCPD)
-      !
-      ZDWAT(J) = 2.11e-5 * (XP00/ZPA(J)) * (ZTA(J)/XTT)**1.94           ! water vapour diffusivity from eq (13.3)
-      !                                                                 ! of Pruppacher and Klett (1978)      
-      ZALFAC(J)= 1.0 / (1.0 + &                                         ! Eq.11 in GoF95
-                   ZRDSRV*ZDQSDT(J)*ZXLR(J)*ZDWAT(J)/(ZDTMP(J)*XCPD))   ! ZALFAC=wet-bulb factor (sans dim)     
-      ZCPLW(J) = 4224.8482 + ZTAC(J) * &
-                              ( -4.707 + ZTAC(J) * &
-                                (0.08499 + ZTAC(J) * &
-                                  (1.2826e-3 + ZTAC(J) * &
-                                    (4.7884e-5 - 2.0027e-6* ZTAC(J))))) ! specific heat  
-      !       
-      ZRF(J)   = PRAIN(J) * ZCPLW(J) * ZALFAC(J) * &                    !Eq.12 in GoF95 !SIGNE?
-                   (PSST(J) - ZTA(J) + (PQSAT(J)-PQA(J))*ZXLR(J)/XCPD )
-      !
-      ! Momentum flux due to rainfall  
-      !
-      ZTAUR(J)=-0.85*(PRAIN(J) *ZVMOD(J)) !pp3752 in FBR96
-      !
-    ENDIF
-    !
-    !             4.4   Webb correction to latent heat flux
-    ! 
-    ZWBAR(J)=- (1./ZRDSRV)*ZUSR(J)*ZQSR(J) / (1.0+(1./ZRDSRV)*PQA(J)) &
-               - ZUSR(J)*ZTSR(J)/ZTA(J)                        ! Eq.21*rhoa in FBR96    
-    !
-    !             4.5   friction velocity which contains correction du to rain            
-    !
-    ZUSTAR2(J)= - (ZTAU(J) + ZTAUR(J)) / PRHOA(J)
-    PUSTAR(J) =  SQRT(ZUSTAR2(J))
-    !
-    !             4.6   Total surface fluxes
-    !           
-    PSFTH (J) =  ZHF(J) + ZRF(J)
-    PSFTQ (J) =  ZEF(J) / ZLV(J)
-    ! 
-  ENDIF
-ENDDO 
-
-
-coeffs = [PCD,&
-       PCE,&
-       PCH]
-                     
-!-------------------------------------------------------------------------------
-!
-!       5.  FINAL STEP : TOTAL SURFACE FLUXES AND DERIVED DIAGNOSTICS 
-!           -----------
-!       5.1    Richardson number
-!             
-!
-!------------STOP LA --------------------
-!ZDIRCOSZW(:) = 1.
-! CALL SURFACE_RI(PSST,PQSAT,PEXNS,PEXNA,ZTA,ZQASAT,&
-!                PZREF,PUREF,ZDIRCOSZW,PVMOD,PRI   )  
-!!
-!!       5.2     Aerodynamical conductance and resistance
-!!             
-!ZAC(:) = PCH(:)*ZVMOD(:)
-!PRESA(:) = 1. / MAX(ZAC(:),XSURF_EPSILON)
-!
-!!       5.3 Z0 and Z0H over sea
-!!
-!PZ0SEA(:) =  ZCHARN(:) * ZUSTAR2(:) / XG + XVZ0CM * PCD(:) / PCDN(:)
-!!
-!!PZ0HSEA(:) = PZ0SEA(:)
-!!
-!IF (LHOOK) CALL DR_HOOK('COARE30_FLUX',1,ZHOOK_HANDLE)
-!
-!-------------------------------------------------------------------------------
-!
-END SUBROUTINE COARE30_FLUX_CNRM
Index: LMDZ6/branches/cirrus/libf/phylmd/coare30_flux_cnrm_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/coare30_flux_cnrm_mod.F90	(revision 5202)
+++ LMDZ6/branches/cirrus/libf/phylmd/coare30_flux_cnrm_mod.F90	(revision 5202)
@@ -0,0 +1,598 @@
+!SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
+!SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
+!SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt  
+!SFX_LIC for details. version 1.
+!     #########
+
+module coare30_flux_cnrm_mod
+  implicit none
+  private
+  public COARE30_FLUX_CNRM
+
+contains
+
+
+SUBROUTINE COARE30_FLUX_CNRM(PZ0SEA,PTA,PSST,PQA,  &
+            PVMOD,PZREF,PUREF,PPS,PQSATA,PQSAT,PSFTH,PSFTQ,PUSTAR,PCD,PCDN,PCH,PCE,PRI,&
+            PRESA,PRAIN,PPA,PZ0HSEA,LPRECIP, LPWG,coeffs )
+!     #######################################################################
+!
+!
+!!****  *COARE25_FLUX*
+!!
+!!    PURPOSE
+!!    -------
+!      Calculate the surface fluxes of heat, moisture, and momentum over
+!      sea surface with bulk algorithm COARE3.0.
+!
+!!**  METHOD
+!!    ------
+!      transfer coefficients were obtained using a dataset which combined COARE
+!      data with those from three other ETL field experiments, and reanalysis of
+!      the HEXMAX data (DeCosmos et al. 1996).
+!      ITERMAX=3
+!      Take account of the surface gravity waves on the velocity roughness and
+!      hence the momentum transfer coefficient
+!        NGRVWAVES=0 no gravity waves action (Charnock) !default value
+!        NGRVWAVES=1 wave age parameterization of Oost et al. 2002
+!        NGRVWAVES=2 model of Taylor and Yelland 2001
+!
+!!    EXTERNAL
+!!    --------
+!!
+!!    IMPLICIT ARGUMENTS
+!!    ------------------
+!!
+!!    REFERENCE
+!!    ---------
+!!      Fairall et al (2003), J. of Climate, vol. 16, 571-591
+!!      Fairall et al (1996), JGR, 3747-3764
+!!      Gosnell et al (1995), JGR, 437-442
+!!      Fairall et al (1996), JGR, 1295-1308
+!!
+!!    AUTHOR
+!!    ------
+!!     C. Lebeaupin  *Météo-France* (adapted from C. Fairall's code)
+!!
+!!    MODIFICATIONS
+!!    -------------
+!!      Original     1/06/2006
+!!      B. Decharme    06/2009 limitation of Ri
+!!      B. Decharme    09/2012 Bug in Ri calculation and limitation of Ri in surface_ri.F90
+!!      B. Decharme    06/2013 bug in z0 (output) computation
+!!      J.Escobar      06/2013  for REAL4/8 add EPSILON management
+!!      C. Lebeaupin   03/2014 bug if PTA=PSST and PEXNA=PEXNS: set a minimum value
+!!                             add abort if no convergence
+!-------------------------------------------------------------------------------
+!
+!*       0.     DECLARATIONS
+!               ------------
+!
+!
+!USE MODD_SEAFLUX_n, ONLY : SEAFLUX_t
+!
+
+!----------Rajout Olive ---------
+USE dimphy
+USE indice_sol_mod
+USE coare_cp_mod, ONLY: PSIFCTT=>psit_30, PSIFCTU=>psiuo
+
+!--------------------------------
+
+USE MODD_CSTS,       ONLY : XKARMAN, XG, XSTEFAN, XRD, XRV, XPI, &
+                            XLVTT, XCL, XCPD, XCPV, XRHOLW, XTT, &
+                            XP00
+
+!USE MODD_SURF_ATM,   ONLY : XVZ0CM
+!
+!USE MODD_SURF_PAR,   ONLY : XUNDEF, XSURF_EPSILON
+!USE MODD_WATER_PAR
+!
+!USE MODI_SURFACE_RI
+!USE MODI_WIND_THRESHOLD
+!USE MODE_COARE30_PSI
+!
+!USE MODE_THERMOS
+!
+!
+!USE MODI_ABOR1_SFX
+!
+!
+!USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
+!USE PARKIND1  ,ONLY : JPRB
+!
+IMPLICIT NONE
+!
+!*      0.1    declarations of arguments
+!
+!
+!
+!TYPE(SEAFLUX_t), INTENT(INOUT) :: S
+!
+REAL, DIMENSION(klon), INTENT(IN)       :: PTA   ! air temperature at atm. level (K)
+REAL, DIMENSION(klon), INTENT(IN)       :: PQA   ! air humidity at atm. level (kg/kg)
+!REAL, DIMENSION(:), INTENT(IN)       :: PEXNA ! Exner function at atm. level
+!REAL, DIMENSION(:), INTENT(IN)       :: PRHOA ! air density at atm. level
+REAL, DIMENSION(klon), INTENT(IN)       :: PVMOD ! module of wind at atm. wind level (m/s)
+REAL, DIMENSION(klon), INTENT(IN)       :: PZREF ! atm. level for temp. and humidity (m)
+REAL, DIMENSION(klon), INTENT(IN)       :: PUREF ! atm. level for wind (m)
+REAL, DIMENSION(klon), INTENT(IN)       :: PSST  ! Sea Surface Temperature (K)
+!REAL, DIMENSION(:), INTENT(IN)       :: PEXNS ! Exner function at sea surface
+REAL, DIMENSION(klon), INTENT(IN)       :: PPS   ! air pressure at sea surface (Pa)
+REAL, DIMENSION(klon), INTENT(IN)       :: PRAIN !precipitation rate (kg/s/m2)
+REAL, DIMENSION(klon), INTENT(IN)       :: PPA        ! air pressure at atm level (Pa)
+REAL, DIMENSION(klon), INTENT(IN)       :: PQSATA        ! air pressure at atm level (Pa)
+!
+REAL, DIMENSION(klon), INTENT(INOUT)    :: PZ0SEA! roughness length over the ocean
+!
+!  surface fluxes : latent heat, sensible heat, friction fluxes
+REAL, DIMENSION(klon), INTENT(OUT)      :: PSFTH ! heat flux (W/m2)
+REAL, DIMENSION(klon), INTENT(OUT)      :: PSFTQ ! water flux (kg/m2/s)
+REAL, DIMENSION(klon), INTENT(OUT)      :: PUSTAR! friction velocity (m/s)
+!
+! diagnostics
+REAL, DIMENSION(klon), INTENT(OUT)      :: PQSAT ! humidity at saturation
+REAL, DIMENSION(klon), INTENT(OUT)      :: PCD   ! heat drag coefficient
+REAL, DIMENSION(klon), INTENT(OUT)      :: PCDN  ! momentum drag coefficient
+REAL, DIMENSION(klon), INTENT(OUT)      :: PCH   ! neutral momentum drag coefficient
+REAL, DIMENSION(klon), INTENT(OUT)      :: PCE  !transfer coef. for latent heat flux
+REAL, DIMENSION(klon), INTENT(OUT)      :: PRI   ! Richardson number
+REAL, DIMENSION(klon), INTENT(OUT)      :: PRESA ! aerodynamical resistance
+REAL, DIMENSION(klon), INTENT(OUT)      :: PZ0HSEA ! heat roughness length
+
+LOGICAL,            INTENT(IN)    :: LPRECIP   !
+LOGICAL,            INTENT(IN)    :: LPWG    !
+real, dimension(3), intent(inout)      :: coeffs
+!
+!
+
+!INCLUDE "YOMCST.h"
+!INCLUDE "clesphys.h"
+
+!*      0.2    declarations of local variables
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZVMOD    ! wind intensity
+REAL, DIMENSION(SIZE(PTA))      :: ZPA      ! Pressure at atm. level
+REAL, DIMENSION(SIZE(PTA))      :: ZTA      ! Temperature at atm. level
+REAL, DIMENSION(SIZE(PTA))      :: ZQASAT   ! specific humidity at saturation  at atm. level (kg/kg)
+!
+!rajout
+REAL, DIMENSION(SIZE(PTA))       :: PEXNA      ! Exner function at atm level
+REAL, DIMENSION(SIZE(PTA))       :: PEXNS      ! Exner function at atm level
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZO       ! rougness length ref
+REAL, DIMENSION(SIZE(PTA))      :: ZWG      ! gustiness factor (m/s)
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZDU,ZDT,ZDQ,ZDUWG !differences
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZUSR        !velocity scaling parameter "ustar" (m/s) = friction velocity
+REAL, DIMENSION(SIZE(PTA))      :: ZTSR        !temperature sacling parameter "tstar" (degC)
+REAL, DIMENSION(SIZE(PTA))      :: ZQSR        !humidity scaling parameter "qstar" (kg/kg)
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZU10,ZT10   !vertical profils (10-m height)
+REAL, DIMENSION(SIZE(PTA))      :: ZVISA       !kinematic viscosity of dry air
+REAL, DIMENSION(SIZE(PTA))      :: ZO10,ZOT10  !roughness length at 10m
+REAL, DIMENSION(SIZE(PTA))      :: ZCD,ZCT,ZCC
+REAL, DIMENSION(SIZE(PTA))      :: ZCD10,ZCT10 !transfer coef. at 10m
+REAL, DIMENSION(SIZE(PTA))      :: ZRIBU,ZRIBCU
+REAL, DIMENSION(SIZE(PTA))      :: ZETU,ZL10
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZCHARN                      !Charnock number depends on wind module
+REAL, DIMENSION(SIZE(PTA))      :: ZTWAVE,ZHWAVE,ZCWAVE,ZLWAVE !to compute gravity waves' impact
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZZL,ZZTL!,ZZQL    !Obukhovs stability
+                                                     !param. z/l for u,T,q
+REAL, DIMENSION(SIZE(PTA))      :: ZRR
+REAL, DIMENSION(SIZE(PTA))      :: ZOT,ZOQ           !rougness length ref
+REAL, DIMENSION(SIZE(PTA))      :: ZPUZ,ZPTZ,ZPQZ    !PHI funct. for u,T,q
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZBF               !constants to compute gustiness factor
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZTAU       !momentum flux (W/m2)
+REAL, DIMENSION(SIZE(PTA))      :: ZHF        !sensible heat flux (W/m2)
+REAL, DIMENSION(SIZE(PTA))      :: ZEF        !latent heat flux (W/m2)
+REAL, DIMENSION(SIZE(PTA))      :: ZWBAR      !diag for webb correction but not used here after
+REAL, DIMENSION(SIZE(PTA))      :: ZTAUR      !momentum flux due to rain (W/m2)
+REAL, DIMENSION(SIZE(PTA))      :: ZRF        !sensible heat flux due to rain (W/m2)
+REAL, DIMENSION(SIZE(PTA))      :: ZCHN,ZCEN  !neutral coef. for heat and vapor
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZLV      !latent heat constant
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZTAC,ZDQSDT,ZDTMP,ZDWAT,ZALFAC ! for precipitation impact
+REAL, DIMENSION(SIZE(PTA))      :: ZXLR                           ! vaporisation  heat  at a given temperature
+REAL, DIMENSION(SIZE(PTA))      :: ZCPLW                          ! specific heat for water at a given temperature
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZUSTAR2  ! square of friction velocity
+!
+REAL, DIMENSION(SIZE(PTA))      :: ZDIRCOSZW! orography slope cosine (=1 on water!)
+REAL, DIMENSION(SIZE(PTA))      :: ZAC      ! Aerodynamical conductance
+!
+!
+INTEGER, DIMENSION(SIZE(PTA))   :: ITERMAX             ! maximum number of iterations
+!
+REAL    :: ZRVSRDM1,ZRDSRV,ZR2 ! thermodynamic constants
+REAL    :: ZBETAGUST           !gustiness factor
+REAL    :: ZZBL                !atm. boundary layer depth (m)
+REAL    :: ZVISW               !m2/s kinematic viscosity of water
+REAL    :: ZS                  !height of rougness length ref
+REAL    :: ZCH10               !transfer coef. at 10m
+
+REAL    :: QSAT_SEAWATER
+REAL    :: QSATSEAW_1D
+!
+INTEGER :: J, JLOOP    !loop indice
+!REAL(KIND=JPRB) :: ZHOOK_HANDLE
+
+!--------- Modif Olive -----------------
+REAL, DIMENSION(SIZE(PTA))        :: PRHOA
+REAL, PARAMETER                   :: XUNDEF = 1.E+20
+
+REAL       :: XVCHRNK = 0.021
+REAL       :: XVZ0CM = 1.0E-5
+!REAL       :: XRIMAX
+
+
+INTEGER :: PREF             ! reference pressure for exner function
+INTEGER :: NGRVWAVES        ! Pour le choix du z0
+
+INCLUDE "YOMCST.h"
+INCLUDE "clesphys.h"
+
+!--------------------------------------
+
+
+PRHOA(:) = PPS(:) / (287.1 * PTA(:) * (1.+.61*PQA(:)))
+
+PREF = 100000.                     ! = 1000 hPa
+NGRVWAVES = 1
+
+PEXNA = (PPA/PREF)**(RD/RCPD)
+PEXNS = (PPS/PREF)**(RD/RCPD)
+
+!
+!-------------------------------------------------------------------------------
+!
+!       1.     Initializations
+!              ---------------
+!
+!       1.1   Constants and parameters
+!
+!IF (LHOOK) CALL DR_HOOK('COARE30_FLUX',0,ZHOOK_HANDLE)
+!
+ZRVSRDM1  = XRV/XRD-1. ! 0.607766
+ZRDSRV    = XRD/XRV    ! 0.62198
+ZR2       = 1.-ZRDSRV  ! pas utilisé dans cette routine
+ZBETAGUST = 1.2        ! value based on TOGA-COARE experiment
+ZZBL      = 600.       ! Set a default value for boundary layer depth
+ZS        = 10.        ! Standard heigth =10m
+ZCH10     = 0.00115
+!
+ZVISW     = 1.E-6
+!
+!       1.2   Array initialization by undefined values
+!
+PSFTH (:)=XUNDEF
+PSFTQ (:)=XUNDEF
+PUSTAR(:)=XUNDEF
+!
+PCD(:) = XUNDEF
+PCDN(:) = XUNDEF
+PCH(:) = XUNDEF
+PCE(:) =XUNDEF
+PRI(:) = XUNDEF
+!
+PRESA(:)=XUNDEF
+!
+!-------------------------------------------------------------------------------
+!       2. INITIAL GUESS FOR THE ITERATIVE METHOD
+!          -------------------------------------
+!
+!       2.0     Temperature
+!
+! Set a non-zero value for the temperature gradient
+!
+WHERE((PTA(:)*PEXNS(:)/PEXNA(:)-PSST(:))==0.)
+      ZTA(:)=PTA(:)-1E-3
+ELSEWHERE
+      ZTA(:)=PTA(:)
+ENDWHERE
+
+!       2.1     Wind and humidity
+!
+! Sea surface specific humidity
+!
+!PQSAT(:)=QSAT_SEAWATER(PSST(:),PPS(:))
+PQSAT(:)=QSATSEAW_1D(PSST(:),PPS(:))
+
+
+
+!
+! Set a minimum value to wind
+!
+!ZVMOD(:) = WIND_THRESHOLD(PVMOD(:),PUREF(:))
+
+
+ZVMOD = MAX(PVMOD , 0.1 * MIN(10.,PUREF) )    !set a minimum value to wind
+!ZVMOD = PVMOD    !set a minimum value to wind
+
+!
+! Specific humidity at saturation at the atm. level
+!
+ZPA(:) = XP00* (PEXNA(:)**(XCPD/XRD))
+!ZQASAT(:) = QSAT_SEAWATER(ZTA(:),ZPA(:))
+ZQASAT = QSATSEAW_1D(ZTA(:),ZPA(:))
+
+
+!
+!
+ZO(:)  = 0.0001
+ZWG(:) = 0.
+IF (LPWG) ZWG(:) = 0.5
+!
+ZCHARN(:) = 0.011
+!
+DO J=1,SIZE(PTA)
+  !
+  !      2.2       initial guess
+  !
+  ZDU(J) = ZVMOD(J)   !wind speed difference with surface current(=0) (m/s)
+                      !initial guess for gustiness factor
+  ZDT(J) = -(ZTA(J)/PEXNA(J)) + (PSST(J)/PEXNS(J)) !potential temperature difference
+  ZDQ(J) = PQSAT(J)-PQA(J)                         !specific humidity difference
+  !
+  ZDUWG(J) = SQRT(ZDU(J)**2+ZWG(J)**2)     !wind speed difference including gustiness ZWG
+  !
+  !      2.3   initialization of neutral coefficients
+  !
+  ZU10(J)  = ZDUWG(J)*LOG(ZS/ZO(J))/LOG(PUREF(J)/ZO(J))
+  ZUSR(J)  = 0.035*ZU10(J)
+  ZVISA(J) = 1.326E-5*(1.+6.542E-3*(ZTA(J)-XTT)+&
+             8.301E-6*(ZTA(J)-XTT)**2-4.84E-9*(ZTA(J)-XTT)**3) !Andrea (1989) CRREL Rep. 89-11
+  !
+  ZO10(J) = ZCHARN(J)*ZUSR(J)*ZUSR(J)/XG+0.11*ZVISA(J)/ZUSR(J)
+  ZCD(J)  = (XKARMAN/LOG(PUREF(J)/ZO10(J)))**2  !drag coefficient
+  ZCD10(J)= (XKARMAN/LOG(ZS/ZO10(J)))**2
+  ZCT10(J)= ZCH10/SQRT(ZCD10(J))
+  ZOT10(J)= ZS/EXP(XKARMAN/ZCT10(J))
+  !
+  !-------------------------------------------------------------------------------
+  !             Grachev and Fairall (JAM, 1997)
+  ZCT(J) = XKARMAN/LOG(PZREF(J)/ZOT10(J))      !temperature transfer coefficient
+  ZCC(J) = XKARMAN*ZCT(J)/ZCD(J)               !z/L vs Rib linear coef.
+  !
+  ZRIBCU(J) = -PUREF(J)/(ZZBL*0.004*ZBETAGUST**3) !saturation or plateau Rib
+  !ZRIBU(J) =-XG*PUREF(J)*(ZDT(J)+ZRVSRDM1*(ZTA(J)-XTT)*ZDQ)/&
+  !     &((ZTA(J)-XTT)*ZDUWG(J)**2)
+  ZRIBU(J)  = -XG*PUREF(J)*(ZDT(J)+ZRVSRDM1*ZTA(J)*ZDQ(J))/&
+               (ZTA(J)*ZDUWG(J)**2)
+  !
+  IF (ZRIBU(J)<0.) THEN
+    ZETU(J) = ZCC(J)*ZRIBU(J)/(1.+ZRIBU(J)/ZRIBCU(J))    !Unstable G and F
+  ELSE
+    ZETU(J) = ZCC(J)*ZRIBU(J)/(1.+27./9.*ZRIBU(J)/ZCC(J))!Stable
+  ENDIF
+  !
+  ZL10(J) = PUREF(J)/ZETU(J) !MO length
+  !
+ENDDO
+!
+!  First guess M-O stability dependent scaling params. (u*,T*,q*) to estimate ZO and z/L (ZZL)
+ZUSR(:) = ZDUWG(:)*XKARMAN/(LOG(PUREF(:)/ZO10(:))-PSIFCTU(PUREF(1)/ZL10(1)))
+ZTSR(:) = -ZDT(:)*XKARMAN/(LOG(PZREF(:)/ZOT10(:))-PSIFCTT(PZREF(1)/ZL10(1)))
+ZQSR(:) = -ZDQ(:)*XKARMAN/(LOG(PZREF(:)/ZOT10(:))-PSIFCTT(PZREF(1)/ZL10(1)))
+!
+ZZL(:) = 0.0
+!
+DO J=1,SIZE(PTA)
+  !
+  IF (ZETU(J)>50.) THEN
+    ITERMAX(J) = 1
+  ELSE
+    ITERMAX(J) = 3 !number of iterations
+  ENDIF
+  !
+  !then modify Charnork for high wind speeds Chris Fairall's data
+  IF (ZDUWG(J)>10.) ZCHARN(J) = 0.011 + (0.018-0.011)*(ZDUWG(J)-10.)/(18.-10.)
+  IF (ZDUWG(J)>18.) ZCHARN(J) = 0.018
+  !
+  !                3.  ITERATIVE LOOP TO COMPUTE USR, TSR, QSR
+  !                -------------------------------------------
+  !
+  ZHWAVE(J) = 0.018*ZVMOD(J)*ZVMOD(J)*(1.+0.015*ZVMOD(J))
+  ZTWAVE(J) = 0.729*ZVMOD(J)
+  ZCWAVE(J) = XG*ZTWAVE(J)/(2.*XPI)
+  ZLWAVE(J) = ZTWAVE(J)*ZCWAVE(J)
+  !
+ENDDO
+!
+
+!
+DO JLOOP=1,MAXVAL(ITERMAX) ! begin of iterative loop
+  !
+  DO J=1,SIZE(PTA)
+    !
+    IF (JLOOP>ITERMAX(J)) CYCLE
+    !
+    IF (NGRVWAVES==0) THEN
+      ZO(J) = ZCHARN(J)*ZUSR(J)*ZUSR(J)/XG + 0.11*ZVISA(J)/ZUSR(J) !Smith 1988
+    ELSE IF (NGRVWAVES==1) THEN
+      ZO(J) = (50./(2.*XPI))*ZLWAVE(J)*(ZUSR(J)/ZCWAVE(J))**4.5 &
+              + 0.11*ZVISA(J)/ZUSR(J)                       !Oost et al. 2002
+    ELSE IF (NGRVWAVES==2) THEN
+      ZO(J) = 1200.*ZHWAVE(J)*(ZHWAVE(J)/ZLWAVE(J))**4.5 &
+              + 0.11*ZVISA(J)/ZUSR(J)                       !Taulor and Yelland 2001
+    ENDIF
+    !
+    ZRR(J) = ZO(J)*ZUSR(J)/ZVISA(J)
+    ZOQ(J) = MIN(1.15E-4 , 5.5E-5/ZRR(J)**0.6)
+    ZOT(J) = ZOQ(J)
+    !
+    ZZL(J) = XKARMAN * XG * PUREF(J) * &
+              ( ZTSR(J)*(1.+ZRVSRDM1*PQA(J)) + ZRVSRDM1*ZTA(J)*ZQSR(J) ) / &
+              ( ZTA(J)*ZUSR(J)*ZUSR(J)*(1.+ZRVSRDM1*PQA(J)) )
+    ZZTL(J)= ZZL(J)*PZREF(J)/PUREF(J)  ! for T
+!    ZZQL(J)=ZZL(J)*PZREF(J)/PUREF(J)  ! for Q
+  ENDDO
+  !
+  ZPUZ(:) = PSIFCTU(ZZL(1))
+  ZPTZ(:) = PSIFCTT(ZZTL(1))
+  !
+  DO J=1,SIZE(PTA)
+    !
+    ! ZPQZ(J)=PSIFCTT(ZZQL(J))
+    ZPQZ(J) = ZPTZ(J)
+    !
+    !             3.1 scale parameters
+    !
+    ZUSR(J) = ZDUWG(J)*XKARMAN/(LOG(PUREF(J)/ZO(J)) -ZPUZ(J))
+    ZTSR(J) = -ZDT(J)  *XKARMAN/(LOG(PZREF(J)/ZOT(J))-ZPTZ(J))
+    ZQSR(J) = -ZDQ(J)  *XKARMAN/(LOG(PZREF(J)/ZOQ(J))-ZPQZ(J))
+    !
+    !             3.2 Gustiness factor (ZWG)
+    !
+    IF(LPWG) THEN
+      ZBF(J) = -XG/ZTA(J)*ZUSR(J)*(ZTSR(J)+ZRVSRDM1*ZTA(J)*ZQSR(J))
+      IF (ZBF(J)>0.) THEN
+        ZWG(J) = ZBETAGUST*(ZBF(J)*ZZBL)**(1./3.)
+      ELSE
+        ZWG(J) = 0.2
+      ENDIF
+    ENDIF
+    ZDUWG(J) = SQRT(ZVMOD(J)**2 + ZWG(J)**2)
+    !
+  ENDDO
+  !
+ENDDO
+!-------------------------------------------------------------------------------
+!
+!            4.  COMPUTE transfer coefficients PCD, PCH, ZCE and SURFACE FLUXES
+!                --------------------------------------------------------------
+!
+ZTAU(:) = XUNDEF
+ZHF(:)  = XUNDEF
+ZEF(:)  = XUNDEF
+!
+ZWBAR(:) = 0.
+ZTAUR(:) = 0.
+ZRF(:)   = 0.
+!
+DO J=1,SIZE(PTA)
+  !
+  !
+  !            4. transfert coefficients PCD, PCH and PCE
+  !                 and neutral PCDN, ZCHN, ZCEN
+  !
+  PCD(J) = (ZUSR(J)/ZDUWG(J))**2.
+  PCH(J) = ZUSR(J)*ZTSR(J)/(ZDUWG(J)*(ZTA(J)*PEXNS(J)/PEXNA(J)-PSST(J)))
+  PCE(J) = ZUSR(J)*ZQSR(J)/(ZDUWG(J)*(PQA(J)-PQSAT(J)))
+  !
+  PCDN(J) = (XKARMAN/LOG(ZS/ZO(J)))**2.
+  ZCHN(J) = (XKARMAN/LOG(ZS/ZO(J)))*(XKARMAN/LOG(ZS/ZOT(J)))
+  ZCEN(J) = (XKARMAN/LOG(ZS/ZO(J)))*(XKARMAN/LOG(ZS/ZOQ(J)))
+  !
+  ZLV(J) = XLVTT + (XCPV-XCL)*(PSST(J)-XTT)
+  !
+  !            4. 2 surface fluxes
+  !
+  IF (ABS(PCDN(J))>1.E-2) THEN   !!!! secure COARE3.0 CODE
+    write(*,*) 'pb PCDN in COARE30: ',PCDN(J)
+    write(*,*) 'point: ',J,"/",SIZE(PTA)
+    write(*,*) 'roughness: ', ZO(J)
+    write(*,*) 'ustar: ',ZUSR(J)
+    write(*,*) 'wind: ',ZDUWG(J)
+    CALL abort_physic('COARE30',': PCDN too large -> no convergence',1)
+  ELSE
+    ZTSR(J) = -ZTSR(J)
+    ZQSR(J) = -ZQSR(J)
+    ZTAU(J) = -PRHOA(J)*ZUSR(J)*ZUSR(J)*ZVMOD(J)/ZDUWG(J)
+    ZHF(J)  =  PRHOA(J)*XCPD*ZUSR(J)*ZTSR(J)
+    ZEF(J)  =  PRHOA(J)*ZLV(J)*ZUSR(J)*ZQSR(J)
+    !
+    !           4.3 Contributions to surface  fluxes due to rainfall
+    !
+    ! SB: a priori, le facteur ZRDSRV=XRD/XRV est introduit pour
+    !     adapter la formule de Clausius-Clapeyron (pour l'air
+    !     sec) au cas humide.
+    IF (LPRECIP) THEN
+      !
+      ! heat surface  fluxes
+      !
+      ZTAC(J)  = ZTA(J)-XTT
+      !
+      ZXLR(J)  = XLVTT + (XCPV-XCL)* ZTAC(J)                            ! latent heat of rain vaporization
+      ZDQSDT(J)= ZQASAT(J) * ZXLR(J) / (XRD*ZTA(J)**2)                  ! Clausius-Clapeyron relation
+      ZDTMP(J) = (1.0 + 3.309e-3*ZTAC(J) -1.44e-6*ZTAC(J)*ZTAC(J)) * &  !heat diffusivity
+                  0.02411 / (PRHOA(J)*XCPD)
+      !
+      ZDWAT(J) = 2.11e-5 * (XP00/ZPA(J)) * (ZTA(J)/XTT)**1.94           ! water vapour diffusivity from eq (13.3)
+      !                                                                 ! of Pruppacher and Klett (1978)
+      ZALFAC(J)= 1.0 / (1.0 + &                                         ! Eq.11 in GoF95
+                   ZRDSRV*ZDQSDT(J)*ZXLR(J)*ZDWAT(J)/(ZDTMP(J)*XCPD))   ! ZALFAC=wet-bulb factor (sans dim)
+      ZCPLW(J) = 4224.8482 + ZTAC(J) * &
+                              ( -4.707 + ZTAC(J) * &
+                                (0.08499 + ZTAC(J) * &
+                                  (1.2826e-3 + ZTAC(J) * &
+                                    (4.7884e-5 - 2.0027e-6* ZTAC(J))))) ! specific heat
+      !
+      ZRF(J)   = PRAIN(J) * ZCPLW(J) * ZALFAC(J) * &                    !Eq.12 in GoF95 !SIGNE?
+                   (PSST(J) - ZTA(J) + (PQSAT(J)-PQA(J))*ZXLR(J)/XCPD )
+      !
+      ! Momentum flux due to rainfall
+      !
+      ZTAUR(J)=-0.85*(PRAIN(J) *ZVMOD(J)) !pp3752 in FBR96
+      !
+    ENDIF
+    !
+    !             4.4   Webb correction to latent heat flux
+    !
+    ZWBAR(J)=- (1./ZRDSRV)*ZUSR(J)*ZQSR(J) / (1.0+(1./ZRDSRV)*PQA(J)) &
+               - ZUSR(J)*ZTSR(J)/ZTA(J)                        ! Eq.21*rhoa in FBR96
+    !
+    !             4.5   friction velocity which contains correction du to rain
+    !
+    ZUSTAR2(J)= - (ZTAU(J) + ZTAUR(J)) / PRHOA(J)
+    PUSTAR(J) =  SQRT(ZUSTAR2(J))
+    !
+    !             4.6   Total surface fluxes
+    !
+    PSFTH (J) =  ZHF(J) + ZRF(J)
+    PSFTQ (J) =  ZEF(J) / ZLV(J)
+    !
+  ENDIF
+ENDDO
+
+
+coeffs = [PCD,&
+       PCE,&
+       PCH]
+
+!-------------------------------------------------------------------------------
+!
+!       5.  FINAL STEP : TOTAL SURFACE FLUXES AND DERIVED DIAGNOSTICS
+!           -----------
+!       5.1    Richardson number
+!
+!
+!------------STOP LA --------------------
+!ZDIRCOSZW(:) = 1.
+! CALL SURFACE_RI(PSST,PQSAT,PEXNS,PEXNA,ZTA,ZQASAT,&
+!                PZREF,PUREF,ZDIRCOSZW,PVMOD,PRI   )
+!!
+!!       5.2     Aerodynamical conductance and resistance
+!!
+!ZAC(:) = PCH(:)*ZVMOD(:)
+!PRESA(:) = 1. / MAX(ZAC(:),XSURF_EPSILON)
+!
+!!       5.3 Z0 and Z0H over sea
+!!
+!PZ0SEA(:) =  ZCHARN(:) * ZUSTAR2(:) / XG + XVZ0CM * PCD(:) / PCDN(:)
+!!
+!!PZ0HSEA(:) = PZ0SEA(:)
+!!
+!IF (LHOOK) CALL DR_HOOK('COARE30_FLUX',1,ZHOOK_HANDLE)
+!
+!-------------------------------------------------------------------------------
+!
+END SUBROUTINE COARE30_FLUX_CNRM
+
+end module coare30_flux_cnrm_mod
Index: LMDZ6/branches/cirrus/libf/phylmd/coare_cp.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/coare_cp.F90	(revision 5165)
+++ 	(revision )
@@ -1,252 +1,0 @@
-real function psit_30(zet)
-
-  real, intent(in) :: zet
-
-  if(zet<0) then
-     x=(1.-(15*zet))**.5 
-     psik=2*log((1+x)/2) 
-     x=(1.-(34.15*zet))**.3333 
-     psic=1.5*log((1.+x+x*x)/3.)-sqrt(3.)*atan((1.+2.*x)/sqrt(3.))+4.*atan(1.)/sqrt(3.) 
-     f=zet*zet/(1+zet*zet) 
-     psit_30=(1-f)*psik+f*psic   
-
-  else
-     c=min(50.,.35*zet) 
-     psit_30=-((1.+2./3.*zet)**1.5+.6667*(zet-14.28)/exp(c)+8.525)
-  endif
-end FUNCTION psit_30
-
-real function psiuo(zet)
-
-  real, intent(in) :: zet
-
-  if (zet<0) then 
-
-     x=(1.-15.*zet)**.25 
-     psik=2.*log((1.+x)/2.)+log((1.+x*x)/2.)-2.*atan(x)+2.*atan(1.) 
-     x=(1.-10.15*zet)**.3333 
-     psic=1.5*log((1.+x+x*x)/3.)-sqrt(3.)*atan((1.+2.*x)/sqrt(3.))+4.*atan(1.)/sqrt(3.) 
-     f=zet*zet/(1+zet*zet) 
-     psiuo=(1-f)*psik+f*psic                                                
-  else
-     c=min(50.,.35*zet) 
-     psiuo=-((1+1.0*zet)**1.0+.667*(zet-14.28)/exp(c)+8.525)
-  endif
-END FUNCTION psiuo
-
-
-real function gen_q1(ts,p,dq)
-
-  real, intent(in) :: ts,p,dq
-  real es,qs
-
-  es = 6.112*exp(17.502*(ts-273.15)/(ts-32.18))*.98*(1.0007+3.46e-8*p)
-  qs = es*62.197/(p-37.8*es)
-
-  q1 = dq + qs  
-
-end function gen_q1
-
-
-
-
-subroutine coare_cp(du,dt,dq,&
-     t,q,&
-     zu,zt,zq,&
-     p,zi,&
-     nits,&
-     coeffs,rugosm,rugosh)
-  !     zo,tau,hsb,hlb,&
-  !     var)
-  !version with shortened iteration  modified Rt and Rq
-  !uses wave information wave period in s and wave ht in m
-  !no wave, standard coare 2.6 charnock:  jwave=0 
-  !Oost et al.  zo=50/2/pi L (u*/c)**4.5 if jwave=1
-  !taylor and yelland  zo=1200 h*(L/h)**4.5 jwave=2
-  !
-  USE MODD_CSTS,       ONLY : XKARMAN, XG, XSTEFAN, XRD, XRV, XPI, &
-                            XLVTT, XCL, XCPD, XCPV, XRHOLW, XTT, &
-                            XP00
-
-  IMPLICIT NONE
-
-  real, intent(in) :: du,dt,dq,t,q
-  real, intent(in) :: zu,zt,zq,p,zi
-  integer, intent(in) :: nits
-  ! real, dimension (nits), intent(out) :: zo,tau,hsb,hlb
-  ! real, dimension(nits,3), intent(out) :: var
-  real, dimension(3), intent(out) :: coeffs
-  real, intent(out) :: rugosm
-  real, intent(out) :: rugosh
-
-  real, parameter ::  beta=1.2, von=.4, fdg = 1. ,&
-       tdk = 273.16, pi = 3.141593, grav = 9.82,&
-       rgas = 287.1
-
-  integer, dimension(3) :: shape_input
-
-  real bf, cc, rhoa, visa,&
-       u10, ut, uts, ut0, ug,&
-       cd10, ch10, ct, ct10,&
-       charn, ribu,&
-       l, l10, &
-       ribcu,rr,&
-       zet,zetu, zom10, zoh10, zot, zoq, zot10,&
-       cd, ch, le, cpa, cpv,&
-       usr,qsr,tsr,&
-       zom, t_c
-
-!, ZTWAVE, ZHWAVE, ZCWAVE, ZLWAVE
-
-
-
-
-  real old_usr, old_tsr, old_qsr,tmp
-
-  real, external :: psit_30, psiuo, grv
-  integer i,j,k
-!---------------- Rajout pour prendre en compte différent Z0 --------------------------------!
-!  INTEGER :: NGRVWAVES        ! Pour le choix du z0
-!  NGRVWAVES = 2
-!---------------------------------------------------------------------------------------------
-!-------------------- Attention Modif réalisée pas SURRR -------------------------------------
-!---------------------------------------------------------------------------------------------
-
-  Ribcu=-zu/zi/.004/Beta**3 
-  cpa=1004.67 
-
-  t_c = t - 273.15
-
-
-  Le=(2.501-.00237*(t_c-dt))*1e6 
-
-
-  visa=1.326e-5*(1+6.542e-3*(t_c)+8.301e-6*t_c**2-4.84e-9*t_c**3) 
-
-
-  cpv=cpa*(1+0.84*Q) 
-  rhoa=P/(Rgas*t*(1+0.61*Q)) 
-
-
-
-
-
-
-  ug=.2 
-
-  ut=sqrt(du*du+ug*ug) 
-  ut=MAX(ut , 0.1 * MIN(10.,zu) )
-
-  u10=ut*log(10/1e-4)/log(zu/1e-4) 
-  usr=.035*u10                              ! turbulent friction velocity (m/s), including gustiness
-  zom10=0.011*usr*usr/grav+0.11*visa/usr     ! roughness length for u (smith 88)
-  Cd10=(von/log(10/zom10))**2 
-!  zoh10=0.40*visa/usr+1.4e-5
-!  Ch10=((von**2)/((log(10/zom10))*(log(10/zoh10)))) !ammener à devenir ca 
-  Ch10=0.00115 
-  Ct10=Ch10/sqrt(Cd10) 
-  zot10=10/exp(von/Ct10)                    ! roughness length for t
-  Cd=(von/log(zu/zom10))**2 
-  Ct=von/log(zt/zot10) 
-  CC=von*Ct/Cd 
-
-  ut0 = ut
-
-
-  ut = ut0
-  Ribu=grav*zu/t*(dt+.61*t*dq)/ut**2 
-
-  if (Ribu .LT. 0) then 
-     zetu=CC*Ribu/(1+Ribu/Ribcu) 
-  else 
-     zetu=CC*Ribu*(1+27/9*Ribu/CC) 
-  endif
-
-  L10=zu/zetu 
-
-  ! if (zetu .GT. 50) then 
-  !    nits=1 
-  ! endif
-
-  usr=ut*von/(log(zu/zom10)-psiuo(zetu))
-  tsr=dt*von*fdg/(log(zt/zot10)-psit_30(zt/L10)) 
-  qsr=dq*von*fdg/(log(zq/zot10)-psit_30(zq/L10)) 
-  !  tkt=.001
-
-  ! charnock constant - lin par morceau - constant
-  if ( ut <= 10. ) then
-     charn=0.011 
-  else
-     if (ut .GT. 18) then
-        charn=0.018
-     else
-        charn=0.011+(ut-10)/(18-10)*(0.018-0.011) 
-     endif
-  endif
-
-!  ZHWAVE = 0.018*ut*ut*(1.+0.015*ut)
-!  ZTWAVE = 0.729*ut
-!  ZCWAVE = XG*ZTWAVE/(2.*pi)
-!  ZLWAVE = ZTWAVE*ZCWAVE
-
-
-  !***************  bulk loop ************
-  do i=1, nits 
-
-     zet=von*grav*zu/t*(tsr*(1+0.61*Q)+.61*t*qsr)/(usr*usr)/(1+0.61*Q)
-
-!     IF (NGRVWAVES==0) THEN
-!       zom = charn*usr*usr/XG + 0.11*visa/usr !Smith 1988
-!     ELSE IF (NGRVWAVES==1) THEN
-!       zom = (50./(2.*pi))*ZLWAVE*(usr/ZCWAVE)**4.5 &
-!               + 0.11*visa/usr                       !Oost et al. 2002  
-!     ELSE IF (NGRVWAVES==2) THEN
-!       zom = 1200.*ZHWAVE*(ZHWAVE/ZLWAVE)**4.5 &
-!               + 0.11*visa/usr                       !Taulor and Yelland 2001  
-!     ENDIF 
-
-     zom=charn*usr*usr/grav+0.11*visa/usr 
-
-     rr=zom*usr/visa 
-     L=zu/zet 
-     zoq=min(1.15e-4,5.5e-5/rr**.6)  ! a modifier
-     zot=zoq                         ! a modifier
-!     zot=0.40*visa/usr+1.4e-5 
-
-     old_usr = usr
-     old_tsr = tsr
-     old_qsr = qsr
-
-     usr=ut*von/(log(zu/zom)-psiuo(zu/L)) 
-     tsr=dt*von*fdg/(log(zt/zot)-psit_30(zt/L)) 
-     qsr=dq*von*fdg/(log(zq/zoq)-psit_30(zq/L)) 
-
-     Bf=-grav/t*usr*(tsr+.61*t*qsr) 
-
-     if (Bf .GT. 0) then 
-        ug=Beta*(Bf*zi)**.333 
-     else 
-        ug=.2 
-     endif
-
-     ut=sqrt(du*du+ug*ug) 
-     ut=MAX(ut , 0.1 * MIN(10.,zu) )
-
-
-  enddo !bulk iter loop
-
-  ! coeffs(m1,m2,m3,m4,m5,1)=rhoa*usr*usr*du/ut !stress
-  ! coeffs(m1,m2,m3,m4,m5,2)=rhoa*cpa*usr*tsr 
-  ! coeffs(m1,m2,m3,m4,m5,3)=rhoa*Le*usr*qsr 
-
-  tmp = (von/(log(zu/zom)-psiuo(zu/L)) ) * ut / du
-
-  coeffs = [tmp**2,&
-       von*fdg/(log(zt/zot)-psit_30(zt/L)) * tmp,&
-       von*fdg/(log(zq/zoq)-psit_30(zq/L)) * tmp]
-
-  rugosm = zom
-  rugosh = zot
-
-
-end subroutine coare_cp
Index: LMDZ6/branches/cirrus/libf/phylmd/coare_cp_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/coare_cp_mod.F90	(revision 5202)
+++ LMDZ6/branches/cirrus/libf/phylmd/coare_cp_mod.F90	(revision 5202)
@@ -0,0 +1,249 @@
+module coare_cp_mod
+  implicit none
+  private
+  public psit_30, psiuo, coare_cp
+
+contains
+
+  real function psit_30(zet)
+    implicit none
+    real, intent(in) :: zet
+
+    real :: x, psik, psic, f, c
+
+    if(zet<0) then
+      x=(1.-(15.*zet))**.5
+      psik=2.*log((1.+x)/2)
+      x=(1.-(34.15*zet))**.3333
+      psic=1.5*log((1.+x+x*x)/3.)-sqrt(3.)*atan((1.+2.*x)/sqrt(3.))+4.*atan(1.)/sqrt(3.)
+      f=zet*zet/(1.+zet*zet)
+      psit_30=(1.-f)*psik+f*psic
+    else
+      c=min(50.,.35*zet)
+      psit_30=-((1.+2./3.*zet)**1.5+.6667*(zet-14.28)/exp(c)+8.525)
+    endif
+
+  end function psit_30
+
+  real function psiuo(zet)
+    implicit none
+    real, intent(in) :: zet
+
+    real :: x, psik, psic, f, c
+
+    if (zet<0) then
+       x=(1.-15.*zet)**.25
+       psik=2.*log((1.+x)/2.)+log((1.+x*x)/2.)-2.*atan(x)+2.*atan(1.)
+       x=(1.-10.15*zet)**.3333
+       psic=1.5*log((1.+x+x*x)/3.)-sqrt(3.)*atan((1.+2.*x)/sqrt(3.))+4.*atan(1.)/sqrt(3.)
+       f=zet*zet/(1+zet*zet)
+       psiuo=(1-f)*psik+f*psic
+    else
+     c=min(50.,.35*zet)
+     psiuo=-((1.+1.0*zet)**1.0+.667*(zet-14.28)/exp(c)+8.525)
+  endif
+
+end function psiuo
+
+
+subroutine coare_cp(du,dt,dq,&
+     t,q,&
+     zu,zt,zq,&
+     p,zi,&
+     nits,&
+     coeffs,rugosm,rugosh)
+  !     zo,tau,hsb,hlb,&
+  !     var)
+  !version with shortened iteration  modified Rt and Rq
+  !uses wave information wave period in s and wave ht in m
+  !no wave, standard coare 2.6 charnock:  jwave=0
+  !Oost et al.  zo=50/2/pi L (u*/c)**4.5 if jwave=1
+  !taylor and yelland  zo=1200 h*(L/h)**4.5 jwave=2
+  !
+  USE MODD_CSTS,       ONLY : XKARMAN, XG, XSTEFAN, XRD, XRV, XPI, &
+                            XLVTT, XCL, XCPD, XCPV, XRHOLW, XTT, &
+                            XP00
+
+  IMPLICIT NONE
+
+  real, intent(in) :: du,dt,dq,t,q
+  real, intent(in) :: zu,zt,zq,p,zi
+  integer, intent(in) :: nits
+  ! real, dimension (nits), intent(out) :: zo,tau,hsb,hlb
+  ! real, dimension(nits,3), intent(out) :: var
+  real, dimension(3), intent(out) :: coeffs
+  real, intent(out) :: rugosm
+  real, intent(out) :: rugosh
+
+  real, parameter ::  beta=1.2, von=.4, fdg = 1. ,&
+       tdk = 273.16, pi = 3.141593, grav = 9.82,&
+       rgas = 287.1
+
+  integer, dimension(3) :: shape_input
+
+  real bf, cc, rhoa, visa,&
+       u10, ut, uts, ut0, ug,&
+       cd10, ch10, ct, ct10,&
+       charn, ribu,&
+       l, l10, &
+       ribcu,rr,&
+       zet,zetu, zom10, zoh10, zot, zoq, zot10,&
+       cd, ch, le, cpa, cpv,&
+       usr,qsr,tsr,&
+       zom, t_c
+
+!, ZTWAVE, ZHWAVE, ZCWAVE, ZLWAVE
+
+
+
+
+  real old_usr, old_tsr, old_qsr,tmp
+
+  real, external :: grv
+  integer i,j,k
+!---------------- Rajout pour prendre en compte différent Z0 --------------------------------!
+!  INTEGER :: NGRVWAVES        ! Pour le choix du z0
+!  NGRVWAVES = 2
+!---------------------------------------------------------------------------------------------
+!-------------------- Attention Modif réalisée pas SURRR -------------------------------------
+!---------------------------------------------------------------------------------------------
+
+  Ribcu=-zu/zi/.004/Beta**3
+  cpa=1004.67
+
+  t_c = t - 273.15
+
+
+  Le=(2.501-.00237*(t_c-dt))*1e6
+
+
+  visa=1.326e-5*(1+6.542e-3*(t_c)+8.301e-6*t_c**2-4.84e-9*t_c**3)
+
+
+  cpv=cpa*(1+0.84*Q)
+  rhoa=P/(Rgas*t*(1+0.61*Q))
+
+
+
+
+
+
+  ug=.2
+
+  ut=sqrt(du*du+ug*ug)
+  ut=MAX(ut , 0.1 * MIN(10.,zu) )
+
+  u10=ut*log(10/1e-4)/log(zu/1e-4)
+  usr=.035*u10                              ! turbulent friction velocity (m/s), including gustiness
+  zom10=0.011*usr*usr/grav+0.11*visa/usr     ! roughness length for u (smith 88)
+  Cd10=(von/log(10/zom10))**2
+!  zoh10=0.40*visa/usr+1.4e-5
+!  Ch10=((von**2)/((log(10/zom10))*(log(10/zoh10)))) !ammener à devenir ca
+  Ch10=0.00115
+  Ct10=Ch10/sqrt(Cd10)
+  zot10=10/exp(von/Ct10)                    ! roughness length for t
+  Cd=(von/log(zu/zom10))**2
+  Ct=von/log(zt/zot10)
+  CC=von*Ct/Cd
+
+  ut0 = ut
+
+
+  ut = ut0
+  Ribu=grav*zu/t*(dt+.61*t*dq)/ut**2
+
+  if (Ribu < 0) then
+     zetu=CC*Ribu/(1+Ribu/Ribcu)
+  else
+     zetu=CC*Ribu*(1+27/9*Ribu/CC)
+  endif
+
+  L10=zu/zetu
+
+  ! if (zetu .GT. 50) then
+  !    nits=1
+  ! endif
+
+  usr=ut*von/(log(zu/zom10)-psiuo(zetu))
+  tsr=dt*von*fdg/(log(zt/zot10)-psit_30(zt/L10))
+  qsr=dq*von*fdg/(log(zq/zot10)-psit_30(zq/L10))
+  !  tkt=.001
+
+  ! charnock constant - lin par morceau - constant
+  if ( ut <= 10. ) then
+     charn=0.011
+  else
+     if (ut > 18) then
+        charn=0.018
+     else
+        charn=0.011+(ut-10)/(18-10)*(0.018-0.011)
+     endif
+  endif
+
+!  ZHWAVE = 0.018*ut*ut*(1.+0.015*ut)
+!  ZTWAVE = 0.729*ut
+!  ZCWAVE = XG*ZTWAVE/(2.*pi)
+!  ZLWAVE = ZTWAVE*ZCWAVE
+
+
+  !***************  bulk loop ************
+  do i=1, nits
+
+     zet=von*grav*zu/t*(tsr*(1+0.61*Q)+.61*t*qsr)/(usr*usr)/(1+0.61*Q)
+
+!     IF (NGRVWAVES==0) THEN
+!       zom = charn*usr*usr/XG + 0.11*visa/usr !Smith 1988
+!     ELSE IF (NGRVWAVES==1) THEN
+!       zom = (50./(2.*pi))*ZLWAVE*(usr/ZCWAVE)**4.5 &
+!               + 0.11*visa/usr                       !Oost et al. 2002
+!     ELSE IF (NGRVWAVES==2) THEN
+!       zom = 1200.*ZHWAVE*(ZHWAVE/ZLWAVE)**4.5 &
+!               + 0.11*visa/usr                       !Taulor and Yelland 2001
+!     ENDIF
+
+     zom=charn*usr*usr/grav+0.11*visa/usr
+
+     rr=zom*usr/visa
+     L=zu/zet
+     zoq=min(1.15e-4,5.5e-5/rr**.6)  ! a modifier
+     zot=zoq                         ! a modifier
+!     zot=0.40*visa/usr+1.4e-5
+
+     old_usr = usr
+     old_tsr = tsr
+     old_qsr = qsr
+
+     usr=ut*von/(log(zu/zom)-psiuo(zu/L))
+     tsr=dt*von*fdg/(log(zt/zot)-psit_30(zt/L))
+     qsr=dq*von*fdg/(log(zq/zoq)-psit_30(zq/L))
+
+     Bf=-grav/t*usr*(tsr+.61*t*qsr)
+
+     if (Bf > 0) then
+        ug=Beta*(Bf*zi)**.333
+     else
+        ug=.2
+     endif
+
+     ut=sqrt(du*du+ug*ug)
+     ut=MAX(ut , 0.1 * MIN(10.,zu) )
+
+
+  enddo !bulk iter loop
+
+  ! coeffs(m1,m2,m3,m4,m5,1)=rhoa*usr*usr*du/ut !stress
+  ! coeffs(m1,m2,m3,m4,m5,2)=rhoa*cpa*usr*tsr
+  ! coeffs(m1,m2,m3,m4,m5,3)=rhoa*Le*usr*qsr
+
+  tmp = (von/(log(zu/zom)-psiuo(zu/L)) ) * ut / du
+
+  coeffs = [tmp**2,&
+       von*fdg/(log(zt/zot)-psit_30(zt/L)) * tmp,&
+       von*fdg/(log(zq/zoq)-psit_30(zq/L)) * tmp]
+
+  rugosm = zom
+  rugosh = zot
+
+end subroutine coare_cp
+
+end module coare_cp_mod
Index: LMDZ6/branches/cirrus/libf/phylmd/ecrad/lmdz/calcul_cloud_overlap_decorr_len.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/ecrad/lmdz/calcul_cloud_overlap_decorr_len.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/ecrad/lmdz/calcul_cloud_overlap_decorr_len.F90	(revision 5202)
@@ -146,7 +146,7 @@
 !  ENDIF
 ENDIF
-CALL writefield_phy('latitude',latitude_deg,1)
-CALL writefield_phy('pressure_hl',pressure_hl,klev+1)
-CALL writefield_phy('Ldecorel',PDECORR_LEN_EDGES_M,klev)
+!CALL writefield_phy('latitude',latitude_deg,1)
+!CALL writefield_phy('pressure_hl',pressure_hl,klev+1)
+!CALL writefield_phy('Ldecorel',PDECORR_LEN_EDGES_M,klev)
 ! -------------------------------------------------------------------
 
Index: LMDZ6/branches/cirrus/libf/phylmd/ecrad/lmdz/radiation_setup.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/ecrad/lmdz/radiation_setup.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/ecrad/lmdz/radiation_setup.F90	(revision 5202)
@@ -141,5 +141,4 @@
            &  -9, &
            &   4 /)
-!   rad_config%aerosol_optics_override_file_name = 'aerosol_optics_lmdz.nc'
 
 
Index: LMDZ6/branches/cirrus/libf/phylmd/ecrad/lmdz/readaerosol_optic_ecrad.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/ecrad/lmdz/readaerosol_optic_ecrad.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/ecrad/lmdz/readaerosol_optic_ecrad.F90	(revision 5202)
@@ -4,5 +4,5 @@
      flag_aerosol, flag_bc_internal_mixture, itap, rjourvrai, &
      pdtphys, pplay, paprs, t_seri, rhcl, presnivs, &
-     tr_seri, mass_solu_aero, mass_solu_aero_pi) 
+     tr_seri, mass_solu_aero, mass_solu_aero_pi, m_allaer) 
 !     tau_aero, piz_aero, cg_aero, &
 !     tausum_aero, drytausum_aero, tau3d_aero )
@@ -18,5 +18,5 @@
        concso4,concno3,concoa,concbc,concss,concdust,loadso4,loadoa,loadbc,loadss,loaddust, &
        loadno3,load_tmp1,load_tmp2,load_tmp3,load_tmp4,load_tmp5,load_tmp6,load_tmp7, & 
-       load_tmp8,load_tmp9,load_tmp10,m_allaer
+       load_tmp8,load_tmp9,load_tmp10
 
   USE infotrac_phy, ONLY: tracers, nqtot, nbtr
@@ -49,4 +49,8 @@
   REAL, DIMENSION(klon,klev), INTENT(OUT)     :: mass_solu_aero    ! Total mass for all soluble aerosols
   REAL, DIMENSION(klon,klev), INTENT(OUT)     :: mass_solu_aero_pi !     -"-     preindustrial values
+  REAL, DIMENSION(klon,klev,naero_tot), INTENT(OUT) :: m_allaer
+  ! AI a passer par la suite en argument si besoin pour ecrad
+  !REAL, DIMENSION(klon,klev,naero_tot), INTENT(OUT) :: m_allaer_pi !RAF
+
 !  REAL, DIMENSION(klon,klev,2,NSW), INTENT(OUT) :: tau_aero    ! Aerosol optical thickness
 !  REAL, DIMENSION(klon,klev,2,NSW), INTENT(OUT) :: piz_aero    ! Single scattering albedo aerosol
@@ -86,6 +90,5 @@
   REAL, DIMENSION(klon,klev)   :: nitrinscoarse_pi
   REAL, DIMENSION(klon,klev)   :: pdel, zrho
-!  REAL, DIMENSION(klon,klev,naero_tot) :: m_allaer
-  REAL, DIMENSION(klon,klev,naero_tot) :: m_allaer_pi !RAF  
+  REAL, DIMENSION(klon,klev,naero_tot) :: m_allaer_pi
 
   integer :: id_ASBCM, id_ASPOMM, id_ASSO4M, id_ASMSAM, id_CSSO4M, id_CSMSAM, id_SSSSM
Index: LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_mcica_lw.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_mcica_lw.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_mcica_lw.F90	(revision 5202)
@@ -18,6 +18,4 @@
 !   2017-07-12  R. Hogan  Call fast adding method if only clouds scatter
 !   2017-10-23  R. Hogan  Renamed single-character variables
-
-#include "ecrad_config.h"
 
 module radiation_mcica_lw
@@ -126,11 +124,4 @@
     ! Identify clear-sky layers
     logical :: is_clear_sky_layer(nlev)
-
-    ! Temporary storage for more efficient summation
-#ifdef DWD_REDUCTION_OPTIMIZATIONS
-    real(jprb), dimension(nlev+1,2) :: sum_aux
-#else
-    real(jprb) :: sum_up, sum_dn
-#endif
 
     ! Index of the highest cloudy layer
@@ -188,28 +179,6 @@
 
       ! Sum over g-points to compute broadband fluxes
-#ifdef DWD_REDUCTION_OPTIMIZATIONS
-      sum_aux(:,:) = 0.0_jprb
-      do jg = 1,ng
-        do jlev = 1,nlev+1
-          sum_aux(jlev,1) = sum_aux(jlev,1) + flux_up_clear(jg,jlev)
-          sum_aux(jlev,2) = sum_aux(jlev,2) + flux_dn_clear(jg,jlev)
-        end do
-      end do
-      flux%lw_up_clear(jcol,:) = sum_aux(:,1)
-      flux%lw_dn_clear(jcol,:) = sum_aux(:,2)
-#else
-      do jlev = 1,nlev+1
-        sum_up = 0.0_jprb
-        sum_dn = 0.0_jprb
-        !$omp simd reduction(+:sum_up, sum_dn)
-        do jg = 1,ng
-          sum_up = sum_up + flux_up_clear(jg,jlev)
-          sum_dn = sum_dn + flux_dn_clear(jg,jlev)
-        end do
-        flux%lw_up_clear(jcol,jlev) = sum_up
-        flux%lw_dn_clear(jcol,jlev) = sum_dn
-      end do
-#endif
-
+      flux%lw_up_clear(jcol,:) = sum(flux_up_clear,1)
+      flux%lw_dn_clear(jcol,:) = sum(flux_dn_clear,1)
       ! Store surface spectral downwelling fluxes
       flux%lw_dn_surf_clear_g(:,jcol) = flux_dn_clear(:,nlev+1)
@@ -310,10 +279,8 @@
           else
             ! Clear-sky layer: copy over clear-sky values
-            do jg = 1,ng
-              reflectance(jg,jlev) = ref_clear(jg,jlev)
-              transmittance(jg,jlev) = trans_clear(jg,jlev)
-              source_up(jg,jlev) = source_up_clear(jg,jlev)
-              source_dn(jg,jlev) = source_dn_clear(jg,jlev)
-            end do
+            reflectance(:,jlev) = ref_clear(:,jlev)
+            transmittance(:,jlev) = trans_clear(:,jlev)
+            source_up(:,jlev) = source_up_clear(:,jlev)
+            source_dn(:,jlev) = source_dn_clear(:,jlev)
           end if
         end do
@@ -340,36 +307,13 @@
         
         ! Store overcast broadband fluxes
-#ifdef DWD_REDUCTION_OPTIMIZATIONS
-        sum_aux(:,:) = 0._jprb
-        do jg = 1, ng
-          do jlev = 1, nlev+1
-            sum_aux(jlev,1) = sum_aux(jlev,1) + flux_up(jg,jlev)
-            sum_aux(jlev,2) = sum_aux(jlev,2) + flux_dn(jg,jlev)
-          end do
-        end do
-        flux%lw_up(jcol,:) = sum_aux(:,1)
-        flux%lw_dn(jcol,:) = sum_aux(:,2)
-#else
-        do jlev = 1,nlev+1
-          sum_up = 0.0_jprb
-          sum_dn = 0.0_jprb
-          !$omp simd reduction(+:sum_up, sum_dn)
-          do jg = 1,ng
-            sum_up = sum_up + flux_up(jg,jlev)
-            sum_dn = sum_dn + flux_dn(jg,jlev)
-          end do
-          flux%lw_up(jcol,jlev) = sum_up
-          flux%lw_dn(jcol,jlev) = sum_dn
-        end do
-#endif
+        flux%lw_up(jcol,:) = sum(flux_up,1)
+        flux%lw_dn(jcol,:) = sum(flux_dn,1)
 
         ! Cloudy flux profiles currently assume completely overcast
         ! skies; perform weighted average with clear-sky profile
-        do jlev = 1,nlev+1
-          flux%lw_up(jcol,jlev) =  total_cloud_cover *flux%lw_up(jcol,jlev) &
-             &       + (1.0_jprb - total_cloud_cover)*flux%lw_up_clear(jcol,jlev)
-          flux%lw_dn(jcol,jlev) =  total_cloud_cover *flux%lw_dn(jcol,jlev) &
-             &       + (1.0_jprb - total_cloud_cover)*flux%lw_dn_clear(jcol,jlev)
-        end do
+        flux%lw_up(jcol,:) =  total_cloud_cover *flux%lw_up(jcol,:) &
+             &  + (1.0_jprb - total_cloud_cover)*flux%lw_up_clear(jcol,:)
+        flux%lw_dn(jcol,:) =  total_cloud_cover *flux%lw_dn(jcol,:) &
+             &  + (1.0_jprb - total_cloud_cover)*flux%lw_dn_clear(jcol,:)
         ! Store surface spectral downwelling fluxes
         flux%lw_dn_surf_g(:,jcol) = total_cloud_cover*flux_dn(:,nlev+1) &
@@ -391,8 +335,6 @@
         ! No cloud in profile and clear-sky fluxes already
         ! calculated: copy them over
-        do jlev = 1,nlev+1
-          flux%lw_up(jcol,jlev) = flux%lw_up_clear(jcol,jlev)
-          flux%lw_dn(jcol,jlev) = flux%lw_dn_clear(jcol,jlev)
-        end do
+        flux%lw_up(jcol,:) = flux%lw_up_clear(jcol,:)
+        flux%lw_dn(jcol,:) = flux%lw_dn_clear(jcol,:)
         flux%lw_dn_surf_g(:,jcol) = flux%lw_dn_surf_clear_g(:,jcol)
         if (config%do_lw_derivatives) then
Index: LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_mcica_sw.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_mcica_sw.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_mcica_sw.F90	(revision 5202)
@@ -17,6 +17,4 @@
 !   2017-04-22  R. Hogan  Store surface fluxes at all g-points
 !   2017-10-23  R. Hogan  Renamed single-character variables
-
-#include "ecrad_config.h"
 
 module radiation_mcica_sw
@@ -121,11 +119,4 @@
     ! Total cloud cover output from the cloud generator
     real(jprb) :: total_cloud_cover
-
-    ! Temporary storage for more efficient summation
-#ifdef DWD_REDUCTION_OPTIMIZATIONS
-    real(jprb), dimension(nlev+1,3) :: sum_aux
-#else
-    real(jprb) :: sum_up, sum_dn_diff, sum_dn_dir
-#endif
 
     ! Number of g points
@@ -184,47 +175,18 @@
         
         ! Sum over g-points to compute and save clear-sky broadband
-        ! fluxes. Note that the built-in "sum" function is very slow,
-        ! and before being replaced by the alternatives below
-        ! accounted for around 40% of the total cost of this routine.
-#ifdef DWD_REDUCTION_OPTIMIZATIONS
-        ! Optimized summation for the NEC architecture
-        sum_aux(:,:) = 0.0_jprb
-        do jg = 1,ng
-          do jlev = 1,nlev+1
-            sum_aux(jlev,1) = sum_aux(jlev,1) + flux_up(jg,jlev)
-            sum_aux(jlev,2) = sum_aux(jlev,2) + flux_dn_direct(jg,jlev)
-            sum_aux(jlev,3) = sum_aux(jlev,3) + flux_dn_diffuse(jg,jlev)
-          end do
-        end do
-        flux%sw_up_clear(jcol,:) = sum_aux(:,1)
-        flux%sw_dn_clear(jcol,:) = sum_aux(:,2) + sum_aux(:,3)
+        ! fluxes
+        flux%sw_up_clear(jcol,:) = sum(flux_up,1)
         if (allocated(flux%sw_dn_direct_clear)) then
-          flux%sw_dn_direct_clear(jcol,:) = sum_aux(:,2)
+          flux%sw_dn_direct_clear(jcol,:) &
+               &  = sum(flux_dn_direct,1)
+          flux%sw_dn_clear(jcol,:) = sum(flux_dn_diffuse,1) &
+               &  + flux%sw_dn_direct_clear(jcol,:)
+        else
+          flux%sw_dn_clear(jcol,:) = sum(flux_dn_diffuse,1) &
+               &  + sum(flux_dn_direct,1)
         end if
-#else
-        ! Optimized summation for the x86-64 architecture
-        do jlev = 1,nlev+1
-          sum_up      = 0.0_jprb
-          sum_dn_diff = 0.0_jprb
-          sum_dn_dir  = 0.0_jprb
-          !$omp simd reduction(+:sum_up, sum_dn_diff, sum_dn_dir)
-          do jg = 1,ng
-            sum_up      = sum_up      + flux_up(jg,jlev)
-            sum_dn_diff = sum_dn_diff + flux_dn_diffuse(jg,jlev)
-            sum_dn_dir  = sum_dn_dir  + flux_dn_direct(jg,jlev)
-          end do
-          flux%sw_up_clear(jcol,jlev) = sum_up
-          flux%sw_dn_clear(jcol,jlev) = sum_dn_diff + sum_dn_dir
-          if (allocated(flux%sw_dn_direct_clear)) then
-            flux%sw_dn_direct_clear(jcol,jlev) = sum_dn_dir
-          end if
-        end do
-#endif
-        
         ! Store spectral downwelling fluxes at surface
-        do jg = 1,ng
-          flux%sw_dn_diffuse_surf_clear_g(jg,jcol) = flux_dn_diffuse(jg,nlev+1)
-          flux%sw_dn_direct_surf_clear_g(jg,jcol)  = flux_dn_direct(jg,nlev+1)
-        end do
+        flux%sw_dn_diffuse_surf_clear_g(:,jcol) = flux_dn_diffuse(:,nlev+1)
+        flux%sw_dn_direct_surf_clear_g(:,jcol)  = flux_dn_direct(:,nlev+1)
 
         ! Do cloudy-sky calculation
@@ -287,11 +249,9 @@
             else
               ! Clear-sky layer: copy over clear-sky values
-              do jg = 1,ng
-                reflectance(jg,jlev) = ref_clear(jg,jlev)
-                transmittance(jg,jlev) = trans_clear(jg,jlev)
-                ref_dir(jg,jlev) = ref_dir_clear(jg,jlev)
-                trans_dir_diff(jg,jlev) = trans_dir_diff_clear(jg,jlev)
-                trans_dir_dir(jg,jlev) = trans_dir_dir_clear(jg,jlev)
-              end do
+              reflectance(:,jlev) = ref_clear(:,jlev)
+              transmittance(:,jlev) = trans_clear(:,jlev)
+              ref_dir(:,jlev) = ref_dir_clear(:,jlev)
+              trans_dir_diff(:,jlev) = trans_dir_diff_clear(:,jlev)
+              trans_dir_dir(:,jlev) = trans_dir_dir_clear(:,jlev)
             end if
           end do
@@ -304,73 +264,42 @@
           
           ! Store overcast broadband fluxes
-#ifdef DWD_REDUCTION_OPTIMIZATIONS
-          sum_aux(:,:) = 0.0_jprb
-          do jg = 1,ng
-            do jlev = 1,nlev+1
-              sum_aux(jlev,1) = sum_aux(jlev,1) + flux_up(jg,jlev)
-              sum_aux(jlev,2) = sum_aux(jlev,2) + flux_dn_direct(jg,jlev)
-              sum_aux(jlev,3) = sum_aux(jlev,3) + flux_dn_diffuse(jg,jlev)
-            end do
-          end do
-          flux%sw_up(jcol,:) = sum_aux(:,1)
-          flux%sw_dn(jcol,:) = sum_aux(:,2) + sum_aux(:,3)
+          flux%sw_up(jcol,:) = sum(flux_up,1)
           if (allocated(flux%sw_dn_direct)) then
-            flux%sw_dn_direct(jcol,:) = sum_aux(:,2)
+            flux%sw_dn_direct(jcol,:) = sum(flux_dn_direct,1)
+            flux%sw_dn(jcol,:) = sum(flux_dn_diffuse,1) &
+                 &  + flux%sw_dn_direct(jcol,:)
+          else
+            flux%sw_dn(jcol,:) = sum(flux_dn_diffuse,1) &
+                 &  + sum(flux_dn_direct,1)
           end if
-#else
-          do jlev = 1,nlev+1
-            sum_up      = 0.0_jprb
-            sum_dn_diff = 0.0_jprb
-            sum_dn_dir  = 0.0_jprb
-            !$omp simd reduction(+:sum_up, sum_dn_diff, sum_dn_dir)
-            do jg = 1,ng
-              sum_up      = sum_up      + flux_up(jg,jlev)
-              sum_dn_diff = sum_dn_diff + flux_dn_diffuse(jg,jlev)
-              sum_dn_dir  = sum_dn_dir  + flux_dn_direct(jg,jlev)
-            end do
-            flux%sw_up(jcol,jlev) = sum_up
-            flux%sw_dn(jcol,jlev) = sum_dn_diff + sum_dn_dir
-            if (allocated(flux%sw_dn_direct)) then
-              flux%sw_dn_direct(jcol,jlev) = sum_dn_dir
-            end if
-          end do
-#endif
-          
+
           ! Cloudy flux profiles currently assume completely overcast
           ! skies; perform weighted average with clear-sky profile
-          do jlev = 1, nlev+1
-            flux%sw_up(jcol,jlev) =  total_cloud_cover *flux%sw_up(jcol,jlev) &
-                 &     + (1.0_jprb - total_cloud_cover)*flux%sw_up_clear(jcol,jlev)
-            flux%sw_dn(jcol,jlev) =  total_cloud_cover *flux%sw_dn(jcol,jlev) &
-                 &     + (1.0_jprb - total_cloud_cover)*flux%sw_dn_clear(jcol,jlev)
-            if (allocated(flux%sw_dn_direct)) then
-              flux%sw_dn_direct(jcol,jlev) = total_cloud_cover *flux%sw_dn_direct(jcol,jlev) &
-                   &  + (1.0_jprb - total_cloud_cover)*flux%sw_dn_direct_clear(jcol,jlev)
-            end if
-          end do
+          flux%sw_up(jcol,:) =  total_cloud_cover *flux%sw_up(jcol,:) &
+               &  + (1.0_jprb - total_cloud_cover)*flux%sw_up_clear(jcol,:)
+          flux%sw_dn(jcol,:) =  total_cloud_cover *flux%sw_dn(jcol,:) &
+               &  + (1.0_jprb - total_cloud_cover)*flux%sw_dn_clear(jcol,:)
+          if (allocated(flux%sw_dn_direct)) then
+            flux%sw_dn_direct(jcol,:) = total_cloud_cover *flux%sw_dn_direct(jcol,:) &
+                 &  + (1.0_jprb - total_cloud_cover)*flux%sw_dn_direct_clear(jcol,:)
+          end if
           ! Likewise for surface spectral fluxes
-          do jg = 1,ng
-            flux%sw_dn_diffuse_surf_g(jg,jcol) = flux_dn_diffuse(jg,nlev+1)
-            flux%sw_dn_direct_surf_g(jg,jcol)  = flux_dn_direct(jg,nlev+1)
-            flux%sw_dn_diffuse_surf_g(jg,jcol) = total_cloud_cover *flux%sw_dn_diffuse_surf_g(jg,jcol) &
-                 &                 + (1.0_jprb - total_cloud_cover)*flux%sw_dn_diffuse_surf_clear_g(jg,jcol)
-            flux%sw_dn_direct_surf_g(jg,jcol)  = total_cloud_cover *flux%sw_dn_direct_surf_g(jg,jcol) &
-                 &                 + (1.0_jprb - total_cloud_cover)*flux%sw_dn_direct_surf_clear_g(jg,jcol)
-          end do
-
+          flux%sw_dn_diffuse_surf_g(:,jcol) = flux_dn_diffuse(:,nlev+1)
+          flux%sw_dn_direct_surf_g(:,jcol)  = flux_dn_direct(:,nlev+1)
+          flux%sw_dn_diffuse_surf_g(:,jcol) = total_cloud_cover *flux%sw_dn_diffuse_surf_g(:,jcol) &
+               &     + (1.0_jprb - total_cloud_cover)*flux%sw_dn_diffuse_surf_clear_g(:,jcol)
+          flux%sw_dn_direct_surf_g(:,jcol) = total_cloud_cover *flux%sw_dn_direct_surf_g(:,jcol) &
+               &     + (1.0_jprb - total_cloud_cover)*flux%sw_dn_direct_surf_clear_g(:,jcol)
+          
         else
           ! No cloud in profile and clear-sky fluxes already
           ! calculated: copy them over
-          do jlev = 1, nlev+1
-            flux%sw_up(jcol,jlev) = flux%sw_up_clear(jcol,jlev)
-            flux%sw_dn(jcol,jlev) = flux%sw_dn_clear(jcol,jlev)
-            if (allocated(flux%sw_dn_direct)) then
-              flux%sw_dn_direct(jcol,jlev) = flux%sw_dn_direct_clear(jcol,jlev)
-            end if
-          end do
-          do jg = 1,ng
-            flux%sw_dn_diffuse_surf_g(jg,jcol) = flux%sw_dn_diffuse_surf_clear_g(jg,jcol)
-            flux%sw_dn_direct_surf_g(jg,jcol)  = flux%sw_dn_direct_surf_clear_g(jg,jcol)
-          end do
+          flux%sw_up(jcol,:) = flux%sw_up_clear(jcol,:)
+          flux%sw_dn(jcol,:) = flux%sw_dn_clear(jcol,:)
+          if (allocated(flux%sw_dn_direct)) then
+            flux%sw_dn_direct(jcol,:) = flux%sw_dn_direct_clear(jcol,:)
+          end if
+          flux%sw_dn_diffuse_surf_g(:,jcol) = flux%sw_dn_diffuse_surf_clear_g(:,jcol)
+          flux%sw_dn_direct_surf_g(:,jcol)  = flux%sw_dn_direct_surf_clear_g(:,jcol)
 
         end if ! Cloud is present in profile
@@ -378,22 +307,18 @@
       else
         ! Set fluxes to zero if sun is below the horizon
-        do jlev = 1, nlev+1
-          flux%sw_up(jcol,jlev) = 0.0_jprb
-          flux%sw_dn(jcol,jlev) = 0.0_jprb
-          if (allocated(flux%sw_dn_direct)) then
-            flux%sw_dn_direct(jcol,jlev) = 0.0_jprb
-          end if
-          flux%sw_up_clear(jcol,jlev) = 0.0_jprb
-          flux%sw_dn_clear(jcol,jlev) = 0.0_jprb
-          if (allocated(flux%sw_dn_direct_clear)) then
-            flux%sw_dn_direct_clear(jcol,jlev) = 0.0_jprb
-          end if
-        end do
-        do jg = 1,ng
-          flux%sw_dn_diffuse_surf_g(jg,jcol) = 0.0_jprb
-          flux%sw_dn_direct_surf_g(jg,jcol)  = 0.0_jprb
-          flux%sw_dn_diffuse_surf_clear_g(jg,jcol) = 0.0_jprb
-          flux%sw_dn_direct_surf_clear_g(jg,jcol)  = 0.0_jprb
-        end do
+        flux%sw_up(jcol,:) = 0.0_jprb
+        flux%sw_dn(jcol,:) = 0.0_jprb
+        if (allocated(flux%sw_dn_direct)) then
+          flux%sw_dn_direct(jcol,:) = 0.0_jprb
+        end if
+        flux%sw_up_clear(jcol,:) = 0.0_jprb
+        flux%sw_dn_clear(jcol,:) = 0.0_jprb
+        if (allocated(flux%sw_dn_direct_clear)) then
+          flux%sw_dn_direct_clear(jcol,:) = 0.0_jprb
+        end if
+        flux%sw_dn_diffuse_surf_g(:,jcol) = 0.0_jprb
+        flux%sw_dn_direct_surf_g(:,jcol)  = 0.0_jprb
+        flux%sw_dn_diffuse_surf_clear_g(:,jcol) = 0.0_jprb
+        flux%sw_dn_direct_surf_clear_g(:,jcol)  = 0.0_jprb
       end if ! Sun above horizon
 
Index: LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_tripleclouds_lw.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_tripleclouds_lw.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_tripleclouds_lw.F90	(revision 5202)
@@ -170,7 +170,4 @@
     logical :: is_clear_sky_layer(0:nlev+1)
 
-    ! Temporaries to speed up summations
-    real(jprb) :: sum_dn, sum_up
-    
     ! Index of the highest cloudy layer
     integer :: i_cloud_top
@@ -264,21 +261,9 @@
       if (config%do_clear) then
         ! Sum over g-points to compute broadband fluxes
-        do jlev = 1,nlev+1
-          sum_up = 0.0_jprb
-          sum_dn = 0.0_jprb
-          !$omp simd reduction(+:sum_up, sum_dn)
-          do jg = 1,ng
-            sum_up = sum_up + flux_up_clear(jg,jlev)
-            sum_dn = sum_dn + flux_dn_clear(jg,jlev)
-          end do
-          flux%lw_up_clear(jcol,jlev) = sum_up
-          flux%lw_dn_clear(jcol,jlev) = sum_dn
-        end do
-
+        flux%lw_up_clear(jcol,:) = sum(flux_up_clear,1)
+        flux%lw_dn_clear(jcol,:) = sum(flux_dn_clear,1)
         ! Store surface spectral downwelling fluxes / TOA upwelling
-        do jg = 1,ng
-          flux%lw_dn_surf_clear_g(jg,jcol) = flux_dn_clear(jg,nlev+1)
-          flux%lw_up_toa_clear_g (jg,jcol) = flux_up_clear(jg,1)
-        end do
+        flux%lw_dn_surf_clear_g(:,jcol) = flux_dn_clear(:,nlev+1)
+        flux%lw_up_toa_clear_g (:,jcol) = flux_up_clear(:,1)
         ! Save the spectral fluxes if required
         if (config%do_save_spectral_flux) then
@@ -468,10 +453,5 @@
           end if
         else
-          sum_dn = 0.0_jprb
-          !$omp simd reduction(+:sum_dn)
-          do jg = 1,ng
-            sum_dn = sum_dn + flux_dn_clear(jg,jlev)
-          end do
-          flux%lw_dn(jcol,jlev) = sum_dn
+          flux%lw_dn(jcol,:) = sum(flux_dn_clear(:,jlev))
           if (config%do_save_spectral_flux) then
             call indexed_sum(flux_dn_clear(:,jlev), &
@@ -490,12 +470,5 @@
            &  + total_albedo(:,1,i_cloud_top)*flux_dn_clear(:,i_cloud_top)
       flux_up(:,2:) = 0.0_jprb
-
-      sum_up = 0.0_jprb
-      !$omp simd reduction(+:sum_up)
-      do jg = 1,ng
-        sum_up = sum_up + flux_up(jg,1)
-      end do
-      flux%lw_up(jcol,i_cloud_top) = sum_up
-
+      flux%lw_up(jcol,i_cloud_top) = sum(flux_up(:,1))
       if (config%do_save_spectral_flux) then
         call indexed_sum(flux_up(:,1), &
@@ -505,10 +478,5 @@
       do jlev = i_cloud_top-1,1,-1
         flux_up(:,1) = trans_clear(:,jlev)*flux_up(:,1) + source_up_clear(:,jlev)
-        sum_up = 0.0_jprb
-        !$omp simd reduction(+:sum_up)
-        do jg = 1,ng
-          sum_up = sum_up + flux_up(jg,1)
-        end do
-        flux%lw_up(jcol,jlev) = sum_up
+        flux%lw_up(jcol,jlev) = sum(flux_up(:,1))
         if (config%do_save_spectral_flux) then
           call indexed_sum(flux_up(:,1), &
@@ -560,15 +528,6 @@
 
         ! Store the broadband fluxes
-        sum_up = 0.0_jprb
-        sum_dn = 0.0_jprb
-        do jreg = 1,nregions
-          !$omp simd reduction(+:sum_up, sum_dn)
-          do jg = 1,ng
-            sum_up = sum_up + flux_up(jg,jreg)
-            sum_dn = sum_dn + flux_dn(jg,jreg)
-          end do
-        end do
-        flux%lw_up(jcol,jlev+1) = sum_up
-        flux%lw_dn(jcol,jlev+1) = sum_dn
+        flux%lw_up(jcol,jlev+1) = sum(sum(flux_up,1))
+        flux%lw_dn(jcol,jlev+1) = sum(sum(flux_dn,1))
 
         ! Save the spectral fluxes if required
Index: LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_tripleclouds_lw.F90.or
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_tripleclouds_lw.F90.or	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_tripleclouds_lw.F90.or	(revision 5202)
@@ -170,4 +170,7 @@
     logical :: is_clear_sky_layer(0:nlev+1)
 
+    ! Temporaries to speed up summations
+    real(jprb) :: sum_dn, sum_up
+    
     ! Index of the highest cloudy layer
     integer :: i_cloud_top
@@ -249,5 +252,5 @@
         call calc_ref_trans_lw(ng*nlev, &
              &  od(:,:,jcol), ssa(:,:,jcol), g(:,:,jcol), &
-             &  planck_hl(:,1:jlev,jcol), planck_hl(:,2:jlev+1,jcol), &
+             &  planck_hl(:,1:nlev,jcol), planck_hl(:,2:nlev+1,jcol), &
              &  ref_clear, trans_clear, &
              &  source_up_clear, source_dn_clear)
@@ -261,9 +264,21 @@
       if (config%do_clear) then
         ! Sum over g-points to compute broadband fluxes
-        flux%lw_up_clear(jcol,:) = sum(flux_up_clear,1)
-        flux%lw_dn_clear(jcol,:) = sum(flux_dn_clear,1)
+        do jlev = 1,nlev+1
+          sum_up = 0.0_jprb
+          sum_dn = 0.0_jprb
+          !$omp simd reduction(+:sum_up, sum_dn)
+          do jg = 1,ng
+            sum_up = sum_up + flux_up_clear(jg,jlev)
+            sum_dn = sum_dn + flux_dn_clear(jg,jlev)
+          end do
+          flux%lw_up_clear(jcol,jlev) = sum_up
+          flux%lw_dn_clear(jcol,jlev) = sum_dn
+        end do
+
         ! Store surface spectral downwelling fluxes / TOA upwelling
-        flux%lw_dn_surf_clear_g(:,jcol) = flux_dn_clear(:,nlev+1)
-        flux%lw_up_toa_clear_g (:,jcol) = flux_up_clear(:,1)
+        do jg = 1,ng
+          flux%lw_dn_surf_clear_g(jg,jcol) = flux_dn_clear(jg,nlev+1)
+          flux%lw_up_toa_clear_g (jg,jcol) = flux_up_clear(jg,1)
+        end do
         ! Save the spectral fluxes if required
         if (config%do_save_spectral_flux) then
@@ -453,5 +468,10 @@
           end if
         else
-          flux%lw_dn(jcol,:) = sum(flux_dn_clear(:,jlev))
+          sum_dn = 0.0_jprb
+          !$omp simd reduction(+:sum_dn)
+          do jg = 1,ng
+            sum_dn = sum_dn + flux_dn_clear(jg,jlev)
+          end do
+          flux%lw_dn(jcol,jlev) = sum_dn
           if (config%do_save_spectral_flux) then
             call indexed_sum(flux_dn_clear(:,jlev), &
@@ -470,5 +490,12 @@
            &  + total_albedo(:,1,i_cloud_top)*flux_dn_clear(:,i_cloud_top)
       flux_up(:,2:) = 0.0_jprb
-      flux%lw_up(jcol,i_cloud_top) = sum(flux_up(:,1))
+
+      sum_up = 0.0_jprb
+      !$omp simd reduction(+:sum_up)
+      do jg = 1,ng
+        sum_up = sum_up + flux_up(jg,1)
+      end do
+      flux%lw_up(jcol,i_cloud_top) = sum_up
+
       if (config%do_save_spectral_flux) then
         call indexed_sum(flux_up(:,1), &
@@ -478,5 +505,10 @@
       do jlev = i_cloud_top-1,1,-1
         flux_up(:,1) = trans_clear(:,jlev)*flux_up(:,1) + source_up_clear(:,jlev)
-        flux%lw_up(jcol,jlev) = sum(flux_up(:,1))
+        sum_up = 0.0_jprb
+        !$omp simd reduction(+:sum_up)
+        do jg = 1,ng
+          sum_up = sum_up + flux_up(jg,1)
+        end do
+        flux%lw_up(jcol,jlev) = sum_up
         if (config%do_save_spectral_flux) then
           call indexed_sum(flux_up(:,1), &
@@ -528,6 +560,15 @@
 
         ! Store the broadband fluxes
-        flux%lw_up(jcol,jlev+1) = sum(sum(flux_up,1))
-        flux%lw_dn(jcol,jlev+1) = sum(sum(flux_dn,1))
+        sum_up = 0.0_jprb
+        sum_dn = 0.0_jprb
+        do jreg = 1,nregions
+          !$omp simd reduction(+:sum_up, sum_dn)
+          do jg = 1,ng
+            sum_up = sum_up + flux_up(jg,jreg)
+            sum_dn = sum_dn + flux_dn(jg,jreg)
+          end do
+        end do
+        flux%lw_up(jcol,jlev+1) = sum_up
+        flux%lw_dn(jcol,jlev+1) = sum_dn
 
         ! Save the spectral fluxes if required
Index: LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_tripleclouds_sw.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_tripleclouds_sw.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/ecrad/radiation/radiation_tripleclouds_sw.F90	(revision 5202)
@@ -74,11 +74,12 @@
     ! Gas and aerosol optical depth, single-scattering albedo and
     ! asymmetry factor at each shortwave g-point
-    real(jprb), intent(in), dimension(config%n_g_sw,nlev,istartcol:iendcol) &
-         &  :: od, ssa, g
+!    real(jprb), intent(in), dimension(istartcol:iendcol,nlev,config%n_g_sw) :: &
+    real(jprb), intent(in), dimension(config%n_g_sw,nlev,istartcol:iendcol) :: &
+         &  od, ssa, g
 
     ! Cloud and precipitation optical depth, single-scattering albedo and
     ! asymmetry factor in each shortwave band
-    real(jprb), intent(in), dimension(config%n_bands_sw,nlev,istartcol:iendcol) &
-         &  :: od_cloud, ssa_cloud, g_cloud
+    real(jprb), intent(in), dimension(config%n_bands_sw,nlev,istartcol:iendcol) :: &
+         &  od_cloud, ssa_cloud, g_cloud
 
     ! Optical depth, single scattering albedo and asymmetry factor in
@@ -91,6 +92,6 @@
     ! flux into a plane perpendicular to the incoming radiation at
     ! top-of-atmosphere in each of the shortwave g points
-    real(jprb), intent(in), dimension(config%n_g_sw,istartcol:iendcol) &
-         &  :: albedo_direct, albedo_diffuse, incoming_sw
+    real(jprb), intent(in), dimension(config%n_g_sw,istartcol:iendcol) :: &
+         &  albedo_direct, albedo_diffuse, incoming_sw
 
     ! Output
@@ -165,8 +166,4 @@
     real(jprb) :: scat_od, scat_od_cloud
 
-    ! Temporaries to speed up summations
-    real(jprb) :: sum_dn_diff, sum_dn_dir, sum_up
-
-    ! Local cosine of solar zenith angle
     real(jprb) :: mu0
 
@@ -447,33 +444,13 @@
       end if
       
-      ! Store the TOA broadband fluxes, noting that there is no
-      ! diffuse downwelling at TOA. The intrinsic "sum" command has
-      ! been found to be very slow; better performance is found on
-      ! x86-64 architecture with explicit loops and the "omp simd
-      ! reduction" directive.
-      sum_up     = 0.0_jprb
-      sum_dn_dir = 0.0_jprb
-      do jreg = 1,nregions
-        !$omp simd reduction(+:sum_up, sum_dn_dir)
-        do jg = 1,ng
-          sum_up     = sum_up     + flux_up(jg,jreg)
-          sum_dn_dir = sum_dn_dir + direct_dn(jg,jreg)
-        end do
-      end do
-      flux%sw_up(jcol,1) = sum_up
-      flux%sw_dn(jcol,1) = mu0 * sum_dn_dir
+      ! Store the TOA broadband fluxes
+      flux%sw_up(jcol,1) = sum(sum(flux_up,1))
+      flux%sw_dn(jcol,1) = mu0 * sum(sum(direct_dn,1))
       if (allocated(flux%sw_dn_direct)) then
         flux%sw_dn_direct(jcol,1) = flux%sw_dn(jcol,1)
       end if
       if (config%do_clear) then
-        sum_up     = 0.0_jprb
-        sum_dn_dir = 0.0_jprb
-        !$omp simd reduction(+:sum_up, sum_dn_dir)
-        do jg = 1,ng
-          sum_up     = sum_up     + flux_up_clear(jg)
-          sum_dn_dir = sum_dn_dir + direct_dn_clear(jg)
-        end do
-        flux%sw_up_clear(jcol,1) = sum_up
-        flux%sw_dn_clear(jcol,1) = mu0 * sum_dn_dir
+        flux%sw_up_clear(jcol,1) = sum(flux_up_clear)
+        flux%sw_dn_clear(jcol,1) = mu0 * sum(direct_dn_clear)
         if (allocated(flux%sw_dn_direct_clear)) then
           flux%sw_dn_direct_clear(jcol,1) = flux%sw_dn_clear(jcol,1)
@@ -490,5 +467,6 @@
              &           config%i_spec_from_reordered_g_sw, &
              &           flux%sw_dn_band(:,jcol,1))
-        flux%sw_dn_band(:,jcol,1) = mu0 * flux%sw_dn_band(:,jcol,1)
+        flux%sw_dn_band(:,jcol,1) = &
+             &  mu0 * flux%sw_dn_band(:,jcol,1)
         if (allocated(flux%sw_dn_direct_band)) then
           flux%sw_dn_direct_band(:,jcol,1) = flux%sw_dn_band(:,jcol,1)
@@ -571,38 +549,22 @@
                ! nothing to do
 
-        ! Store the broadband fluxes. The intrinsic "sum" command has
-        ! been found to be very slow; better performance is found on
-        ! x86-64 architecture with explicit loops and the "omp simd
-        ! reduction" directive.
-        sum_up      = 0.0_jprb
-        sum_dn_dir  = 0.0_jprb
-        sum_dn_diff = 0.0_jprb
-        do jreg = 1,nregions
-          !$omp simd reduction(+:sum_up, sum_dn_diff, sum_dn_dir)
-          do jg = 1,ng
-            sum_up      = sum_up      + flux_up(jg,jreg)
-            sum_dn_diff = sum_dn_diff + flux_dn(jg,jreg)
-            sum_dn_dir  = sum_dn_dir  + direct_dn(jg,jreg)
-          end do
-        end do
-        flux%sw_up(jcol,jlev+1) = sum_up
-        flux%sw_dn(jcol,jlev+1) = mu0 * sum_dn_dir + sum_dn_diff
+        ! Store the broadband fluxes
+        flux%sw_up(jcol,jlev+1) = sum(sum(flux_up,1))
         if (allocated(flux%sw_dn_direct)) then
-          flux%sw_dn_direct(jcol,jlev+1) = mu0 * sum_dn_dir
+          flux%sw_dn_direct(jcol,jlev+1) = mu0 * sum(sum(direct_dn,1))
+          flux%sw_dn(jcol,jlev+1) &
+               &  = flux%sw_dn_direct(jcol,jlev+1) + sum(sum(flux_dn,1))
+        else
+          flux%sw_dn(jcol,jlev+1) = mu0 * sum(sum(direct_dn,1)) + sum(sum(flux_dn,1))   
         end if
         if (config%do_clear) then
-          sum_up      = 0.0_jprb
-          sum_dn_dir  = 0.0_jprb
-          sum_dn_diff = 0.0_jprb
-          !$omp simd reduction(+:sum_up, sum_dn_diff, sum_dn_dir)
-          do jg = 1,ng
-            sum_up      = sum_up      + flux_up_clear(jg)
-            sum_dn_diff = sum_dn_diff + flux_dn_clear(jg)
-            sum_dn_dir  = sum_dn_dir  + direct_dn_clear(jg)
-          end do
-          flux%sw_up_clear(jcol,jlev+1) = sum_up
-          flux%sw_dn_clear(jcol,jlev+1) = mu0 * sum_dn_dir + sum_dn_diff
+          flux%sw_up_clear(jcol,jlev+1) = sum(flux_up_clear)
           if (allocated(flux%sw_dn_direct_clear)) then
-            flux%sw_dn_direct_clear(jcol,jlev+1) = mu0 * sum_dn_dir
+            flux%sw_dn_direct_clear(jcol,jlev+1) = mu0 * sum(direct_dn_clear)
+            flux%sw_dn_clear(jcol,jlev+1) &
+                 &  = flux%sw_dn_direct_clear(jcol,jlev+1) + sum(flux_dn_clear)
+          else
+            flux%sw_dn_clear(jcol,jlev+1) = mu0 * sum(direct_dn_clear) &
+                 &  + sum(flux_dn_clear)
           end if
         end if
@@ -643,4 +605,5 @@
           end if
         end if
+
       end do ! Final loop over levels
       
Index: LMDZ6/branches/cirrus/libf/phylmd/fonte_neige_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/fonte_neige_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/fonte_neige_mod.F90	(revision 5202)
@@ -36,4 +36,18 @@
   REAL, ALLOCATABLE, DIMENSION(:)             :: runofflic_global
   !$OMP THREADPRIVATE(runofflic_global)
+#ifdef ISO
+  REAL, ALLOCATABLE, DIMENSION(:,:), PRIVATE  :: xtrun_off_ter
+  !$OMP THREADPRIVATE(xtrun_off_ter)
+  REAL, ALLOCATABLE, DIMENSION(:,:)           :: xtrun_off_lic
+  !$OMP THREADPRIVATE(xtrun_off_lic)
+  REAL, ALLOCATABLE, DIMENSION(:,:), PRIVATE  :: xtrun_off_lic_0 
+  !$OMP THREADPRIVATE(xtrun_off_lic_0)
+  REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE:: fxtfonte_global
+  !$OMP THREADPRIVATE(fxtfonte_global)
+  REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE:: fxtcalving_global
+  !$OMP THREADPRIVATE(fxtcalving_global)
+  REAL, ALLOCATABLE, DIMENSION(:,:), PRIVATE  :: xtrunofflic_global
+  !$OMP THREADPRIVATE(xtrunofflic_global)
+#endif
 
 CONTAINS
@@ -123,4 +137,93 @@
 
   END SUBROUTINE fonte_neige_init
+
+#ifdef ISO
+  SUBROUTINE fonte_neige_init_iso(xtrestart_runoff)
+
+! This subroutine allocates and initialize variables in the module. 
+! The variable run_off_lic_0 is initialized to the field read from
+! restart file. The other variables are initialized to zero.
+
+    USE infotrac_phy, ONLY: niso
+#ifdef ISOVERIF
+    USE isotopes_mod, ONLY: iso_eau,iso_HDO
+    USE isotopes_verif_mod
+#endif
+!
+!****************************************************************************************
+! Input argument
+    REAL, DIMENSION(niso,klon), INTENT(IN) :: xtrestart_runoff 
+
+! Local variables
+    INTEGER                           :: error
+    CHARACTER (len = 80)              :: abort_message 
+    CHARACTER (len = 20)              :: modname = 'fonte_neige_init'
+    INTEGER                           :: i
+
+
+!****************************************************************************************
+! Allocate run-off at landice and initilize with field read from restart
+!
+!****************************************************************************************
+
+    ALLOCATE(xtrun_off_lic_0(niso,klon), stat = error)
+    IF (error /= 0) THEN
+       abort_message='Pb allocation run_off_lic'
+       CALL abort_gcm(modname,abort_message,1)
+    ENDIF    
+    
+    xtrun_off_lic_0(:,:) = xtrestart_runoff(:,:)        
+
+#ifdef ISOVERIF 
+      IF (iso_eau > 0) THEN   
+        CALL iso_verif_egalite_vect1D( &
+     &           xtrun_off_lic_0,run_off_lic_0,'fonte_neige 100', &
+     &           niso,klon)
+      ENDIF !IF (iso_eau > 0) THEN
+#endif        
+
+!****************************************************************************************
+! Allocate other variables and initilize to zero
+!
+!****************************************************************************************
+
+    ALLOCATE(xtrun_off_ter(niso,klon), stat = error)
+    IF (error /= 0) THEN
+       abort_message='Pb allocation xtrun_off_ter'
+       CALL abort_gcm(modname,abort_message,1)
+    ENDIF
+    xtrun_off_ter(:,:) = 0.
+    
+    ALLOCATE(xtrun_off_lic(niso,klon), stat = error)
+    IF (error /= 0) THEN
+       abort_message='Pb allocation xtrun_off_lic'
+       CALL abort_gcm(modname,abort_message,1)
+    ENDIF
+    xtrun_off_lic(:,:) = 0.
+
+    ALLOCATE(fxtfonte_global(niso,klon,nbsrf))
+    IF (error /= 0) THEN
+       abort_message='Pb allocation fxtfonte_global'
+       CALL abort_gcm(modname,abort_message,1)
+    ENDIF
+    fxtfonte_global(:,:,:) = 0.0
+
+    ALLOCATE(fxtcalving_global(niso,klon,nbsrf))
+    IF (error /= 0) THEN
+       abort_message='Pb allocation fxtcalving_global'
+       CALL abort_gcm(modname,abort_message,1)
+    ENDIF
+    fxtcalving_global(:,:,:) = 0.0
+
+    ALLOCATE(xtrunofflic_global(niso,klon))
+    IF (error /= 0) THEN
+       abort_message='Pb allocation xtrunofflic_global'
+       CALL abort_gcm(modname,abort_message,1)
+    ENDIF
+    xtrunofflic_global(:,:) = 0.0
+
+  END SUBROUTINE fonte_neige_init_iso
+#endif
+
 !
 !****************************************************************************************
@@ -128,7 +231,19 @@
   SUBROUTINE fonte_neige( knon, nisurf, knindex, dtime, &
        tsurf, precip_rain, precip_snow, &
-       snow, qsol, tsurf_new, evap)
-
-  USE indice_sol_mod
+       snow, qsol, tsurf_new, evap &
+#ifdef ISO    
+     & ,fq_fonte_diag,fqfonte_diag,snow_evap_diag,fqcalving_diag   &
+     & ,max_eau_sol_diag,runoff_diag,run_off_lic_diag,coeff_rel_diag   &
+#endif
+     &   )
+
+    USE indice_sol_mod
+#ifdef ISO
+    USE infotrac_phy, ONLY: niso
+    !use isotopes_mod, ONLY: ridicule_snow,iso_eau,iso_HDO
+#ifdef ISOVERIF
+    USE isotopes_verif_mod
+#endif
+#endif
         
 ! Routine de traitement de la fonte de la neige dans le cas du traitement
@@ -172,4 +287,16 @@
     REAL, DIMENSION(klon), INTENT(INOUT) :: tsurf_new
     REAL, DIMENSION(klon), INTENT(INOUT) :: evap
+
+#ifdef ISO    
+        ! sortie de quelques diagnostiques
+    REAL, DIMENSION(klon), INTENT(OUT) :: fq_fonte_diag
+    REAL, DIMENSION(klon), INTENT(OUT) :: fqfonte_diag
+    REAL, DIMENSION(klon), INTENT(OUT) ::  snow_evap_diag 
+    REAL, DIMENSION(klon), INTENT(OUT) ::  fqcalving_diag  
+    REAL,                  INTENT(OUT) :: max_eau_sol_diag  
+    REAL, DIMENSION(klon), INTENT(OUT) ::  runoff_diag   
+    REAL, DIMENSION(klon), INTENT(OUT) :: run_off_lic_diag  
+    REAL,                  INTENT(OUT) :: coeff_rel_diag
+#endif
 
 ! Local variables
@@ -193,4 +320,9 @@
 
     LOGICAL               :: neige_fond
+
+#ifdef ISO
+        max_eau_sol_diag=max_eau_sol
+#endif
+
 
 !****************************************************************************************
@@ -231,4 +363,9 @@
     
     bil_eau_s(:) = (precip_rain(:) * dtime) - (evap(:) - snow_evap(:)) * dtime
+#ifdef ISO
+    snow_evap_diag(:) = snow_evap(:)
+    coeff_rel_diag    = coeff_rel
+#endif
+
 
 
@@ -254,4 +391,8 @@
           bil_eau_s(i) = bil_eau_s(i) + fq_fonte 
           tsurf_new(i) = tsurf_new(i) - fq_fonte * chasno  
+#ifdef ISO
+          fq_fonte_diag(i) = fq_fonte
+#endif
+
 
 !IM cf JLD OK     
@@ -273,4 +414,11 @@
        snow(i)=MIN(snow(i),snow_max)
     ENDDO
+#ifdef ISO
+    DO i = 1, knon
+       fqcalving_diag(i) = fqcalving(i)
+       fqfonte_diag(i)   = fqfonte(i)
+    ENDDO !DO i = 1, knon
+#endif
+
 
     IF (nisurf == is_ter) THEN
@@ -278,4 +426,7 @@
           qsol(i) = qsol(i) + bil_eau_s(i)
           run_off_ter(i) = run_off_ter(i) + MAX(qsol(i) - max_eau_sol, 0.0)
+#ifdef ISO
+          runoff_diag(i) = MAX(qsol(i) - max_eau_sol, 0.0)
+#endif
           qsol(i) = MIN(qsol(i), max_eau_sol) 
        ENDDO
@@ -290,4 +441,10 @@
        ENDDO
     ENDIF
+
+#ifdef ISO
+    DO i = 1, klon    
+      run_off_lic_diag(i) = run_off_lic(i)
+    ENDDO ! DO i = 1, knon    
+#endif
     
 !****************************************************************************************
@@ -312,14 +469,52 @@
 !****************************************************************************************
 !
-  SUBROUTINE fonte_neige_final(restart_runoff)
+  SUBROUTINE fonte_neige_final(restart_runoff &
+#ifdef ISO      
+     &                        ,xtrestart_runoff &
+#endif   
+     &                        )
 !
 ! This subroutine returns run_off_lic_0 for later writing to restart file.
 !
+#ifdef ISO
+    USE infotrac_phy, ONLY: niso
+#ifdef ISOVERIF
+    USE isotopes_mod, ONLY: iso_eau
+    USE isotopes_verif_mod
+#endif
+#endif
+!
 !****************************************************************************************
     REAL, DIMENSION(klon), INTENT(OUT) :: restart_runoff
+#ifdef ISO     
+    REAL, DIMENSION(niso,klon), INTENT(OUT) :: xtrestart_runoff
+#ifdef ISOVERIF
+    INTEGER :: i
+#endif  
+#endif
+
+
 
 !****************************************************************************************
 ! Set the output variables
     restart_runoff(:) = run_off_lic_0(:)
+#ifdef ISO
+    xtrestart_runoff(:,:) = xtrun_off_lic_0(:,:)
+#ifdef ISOVERIF 
+    IF (iso_eau > 0) THEN   
+      DO i=1,klon
+        IF (iso_verif_egalite_nostop(run_off_lic_0(i) &
+     &                              ,xtrun_off_lic_0(iso_eau,i) &
+     &                              ,'fonte_neige 413') &
+     &      == 1) then
+          WRITE(*,*) 'i=',i
+          STOP
+        ENDIF
+      ENDDO !DO i=1,klon
+    ENDIF !IF (iso_eau > 0) then 
+#endif    
+#endif
+
+
 
 ! Deallocation of all varaibles in the module
@@ -334,4 +529,13 @@
     IF (ALLOCATED(fqcalving_global)) DEALLOCATE(fqcalving_global)
     IF (ALLOCATED(runofflic_global)) DEALLOCATE(runofflic_global)
+#ifdef ISO
+    IF (ALLOCATED(xtrun_off_lic_0)) DEALLOCATE(xtrun_off_lic_0)
+    IF (ALLOCATED(xtrun_off_ter)) DEALLOCATE(xtrun_off_ter)
+    IF (ALLOCATED(xtrun_off_lic)) DEALLOCATE(xtrun_off_lic)
+    IF (ALLOCATED(fxtfonte_global)) DEALLOCATE(fxtfonte_global)
+    IF (ALLOCATED(fxtcalving_global)) DEALLOCATE(fxtcalving_global)
+    IF (ALLOCATED(xtrunofflic_global)) DEALLOCATE(xtrunofflic_global)
+#endif
+
 
   END SUBROUTINE fonte_neige_final
@@ -340,5 +544,9 @@
 !
   SUBROUTINE fonte_neige_get_vars(pctsrf, fqcalving_out, &
-       fqfonte_out, ffonte_out, run_off_lic_out)
+              fqfonte_out, ffonte_out, run_off_lic_out &
+#ifdef ISO     
+     &       ,fxtcalving_out, fxtfonte_out,xtrun_off_lic_out &
+#endif     
+     &       )
 
 
@@ -349,5 +557,8 @@
 !****************************************************************************************
 
-  USE indice_sol_mod
+    USE indice_sol_mod
+#ifdef ISO
+    USE infotrac_phy, ONLY: niso
+#endif
 
     REAL, DIMENSION(klon,nbsrf), INTENT(IN) :: pctsrf
@@ -358,4 +569,11 @@
     REAL, DIMENSION(klon), INTENT(OUT)      :: run_off_lic_out
 
+#ifdef ISO
+    REAL, DIMENSION(niso,klon), INTENT(OUT) :: fxtcalving_out
+    REAL, DIMENSION(niso,klon), INTENT(OUT) :: fxtfonte_out
+    REAL, DIMENSION(niso,klon), INTENT(OUT) :: xtrun_off_lic_out
+    INTEGER   :: i,ixt
+#endif
+ 
     INTEGER   :: nisurf
 !****************************************************************************************
@@ -364,4 +582,8 @@
     fqfonte_out(:)   = 0.0
     fqcalving_out(:) = 0.0
+#ifdef ISO        
+    fxtfonte_out(:,:)   = 0.0
+    fxtcalving_out(:,:) = 0.0
+#endif
 
     DO nisurf = 1, nbsrf
@@ -373,7 +595,123 @@
     run_off_lic_out(:)=runofflic_global(:)
 
+#ifdef ISO
+    DO nisurf = 1, nbsrf
+      DO i=1,klon
+        DO ixt=1,niso
+          fxtfonte_out(ixt,i) = fxtfonte_out(ixt,i) + fxtfonte_global(ixt,i,nisurf)*pctsrf(i,nisurf)
+          fxtcalving_out(ixt,i) = fxtcalving_out(ixt,i) + fxtcalving_global(ixt,i,nisurf)*pctsrf(i,nisurf)
+        ENDDO !DO ixt=1,niso
+      ENDDO !DO i=1,klon
+    ENDDO !DO nisurf = 1, nbsrf
+    xtrun_off_lic_out(:,:) = xtrunofflic_global(:,:)
+#endif
+
   END SUBROUTINE fonte_neige_get_vars
 !
 !****************************************************************************************
 !
+!#ifdef ISO
+!  subroutine fonte_neige_export_xtrun_off_lic_0(knon,xtrun_off_lic_0_diag)
+!    use infotrac_phy, ONLY: niso
+!
+!    ! inputs
+!    INTEGER, INTENT(IN)                      :: knon
+!    real, INTENT(IN), DIMENSION(niso,klon)   :: xtrun_off_lic_0_diag
+!
+!    xtrun_off_lic_0(:,:)=xtrun_off_lic_0_diag(:,:)
+!
+!  end subroutine fonte_neige_export_xtrun_off_lic_0
+!#endif 
+
+#ifdef ISO
+  SUBROUTINE gestion_neige_besoin_varglob_fonte_neige(klon,knon, &
+     &           xtprecip_snow,xtprecip_rain, &
+     &           fxtfonte_neige,fxtcalving, &
+     &           knindex,nisurf,run_off_lic_diag,coeff_rel_diag)
+
+        ! dans cette routine, on a besoin des variables globales de
+        ! fonte_neige_mod. Il faut donc la mettre dans fonte_neige_mod
+        ! le reste de gestion_neige est dans isotopes_routines_mod car sinon pb
+        ! de dépendance circulaire.
+
+    USE infotrac_phy, ONLY: ntiso,niso
+    USE isotopes_mod, ONLY: iso_eau    
+    USE indice_sol_mod    
+#ifdef ISOVERIF
+    USE isotopes_verif_mod
+#endif
+    IMPLICIT NONE
+
+    ! inputs
+    INTEGER, INTENT(IN)                     :: klon,knon
+    REAL, DIMENSION(ntiso,klon), INTENT(IN) :: xtprecip_snow, xtprecip_rain
+    REAL, DIMENSION(niso,klon), INTENT(IN)  :: fxtfonte_neige,fxtcalving
+    INTEGER, INTENT(IN)                     :: nisurf
+    INTEGER, DIMENSION(klon), INTENT(IN)    :: knindex
+    REAL, DIMENSION(klon), INTENT(IN)       :: run_off_lic_diag  
+    REAL, INTENT(IN)                        :: coeff_rel_diag  
+
+    ! locals
+    INTEGER :: i,ixt,j
+        
+#ifdef ISOVERIF
+    IF (nisurf == is_lic) THEN
+      IF (iso_eau > 0) THEN  
+        DO i = 1, knon
+           j = knindex(i)
+           CALL iso_verif_egalite(xtrun_off_lic_0(iso_eau,j), &
+     &             run_off_lic_0(j),'gestion_neige_besoin_varglob_fonte_neige 625')
+        ENDDO
+      ENDIF
+    ENDIF
+#endif
+
+! calcul de run_off_lic 
+
+    IF (nisurf == is_lic) THEN
+!         coeff_rel = dtime/(tau_calv * rday)
+
+      DO i = 1, knon
+        j = knindex(i)
+        DO ixt = 1, niso
+          xtrun_off_lic(ixt,i)   = (coeff_rel_diag *  fxtcalving(ixt,i)) &
+     &                            +(1. - coeff_rel_diag) * xtrun_off_lic_0(ixt,j)
+          xtrun_off_lic_0(ixt,j) = xtrun_off_lic(ixt,i)
+          xtrun_off_lic(ixt,i)   = xtrun_off_lic(ixt,i) + fxtfonte_neige(ixt,i) + xtprecip_rain(ixt,i)
+        ENDDO !DO ixt=1,niso
+#ifdef ISOVERIF
+          IF (iso_eau > 0) THEN             
+            IF (iso_verif_egalite_choix_nostop(xtrun_off_lic(iso_eau,i), &
+     &                  run_off_lic_diag(i),'gestion_neige_besoin_varglob_fonte_neige 1201a', &
+     &                  errmax,errmaxrel) == 1) THEN 
+               WRITE(*,*) 'i,j=',i,j   
+               WRITE(*,*) 'coeff_rel_diag=',coeff_rel_diag
+               STOP
+            ENDIF
+          ENDIF
+#endif
+      ENDDO
+    ENDIF !IF (nisurf == is_lic) THEN  
+
+! Save ffonte, fqfonte and fqcalving in global arrays for each 
+! sub-surface separately
+    DO i = 1, knon
+      DO ixt = 1, niso
+        fxtfonte_global(ixt,knindex(i),nisurf)   = fxtfonte_neige(ixt,i)
+        fxtcalving_global(ixt,knindex(i),nisurf) = fxtcalving(ixt,i)
+      ENDDO !do ixt=1,niso
+    ENDDO   
+
+    IF (nisurf == is_lic) THEN
+      DO i = 1, knon    
+        DO ixt = 1, niso   
+        xtrunofflic_global(ixt,knindex(i)) = xtrun_off_lic(ixt,i)
+        ENDDO ! DO ixt=1,niso   
+      ENDDO
+    ENDIF
+       
+  END SUBROUTINE gestion_neige_besoin_varglob_fonte_neige
+#endif
+
+
 END MODULE fonte_neige_mod
Index: LMDZ6/branches/cirrus/libf/phylmd/grid_index.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/grid_index.F90	(revision 5202)
+++ LMDZ6/branches/cirrus/libf/phylmd/grid_index.F90	(revision 5202)
@@ -0,0 +1,21 @@
+function grid_index(lon_deg,lat_deg)
+!--------------------------------------------------------------------------------
+! Get local index of grid point of longitude,latitude lon_deg,lat_deg
+! Author : FH 2024/07/18
+! Please do not put this function in a m*odule not to complexify the replay script
+!--------------------------------------------------------------------------------
+USE dimphy, only : klon
+USE geometry_mod, ONLY: latitude_deg, longitude_deg
+implicit none
+real, intent(in) :: lon_deg,lat_deg
+integer :: grid_index
+integer i
+grid_index=0
+do i=1,klon
+   if ( abs(lon_deg-longitude_deg(i)) < 0.02 .and.  abs(lat_deg-latitude_deg(i)) < 0.02 ) then
+        grid_index=i
+        exit
+   endif
+enddo
+return
+end
Index: LMDZ6/branches/cirrus/libf/phylmd/infotrac_phy.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/infotrac_phy.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/infotrac_phy.F90	(revision 5202)
@@ -5,6 +5,6 @@
    USE       strings_mod, ONLY: msg, fmsg, maxlen, cat, dispTable, int2str, bool2str, strStack, strParse, strIdx
    USE readTracFiles_mod, ONLY: trac_type, readTracersFiles, tracers, setGeneration, itZonIso, nzone, tran0, isoZone, &
-        delPhase, niso, getKey, isot_type, readIsotopesFile, isotope, maxTableWidth, iqIsoPha, nphas, ixIso, isoPhas, &
-        addPhase, iH2O, addKey, isoSelect, testTracersFiles, isoKeys, indexUpdate,   isoCheck, nbIso, ntiso, isoName
+        delPhase, niso, getKey, isot_type, processIsotopes,  isotope, maxTableWidth, iqIsoPha, nphas, ixIso, isoPhas, &
+        addPhase, iH2O, addKey, isoSelect, testTracersFiles, isoKeys, indexUpdate,  iqWIsoPha, nbIso, ntiso, isoName, isoCheck
    IMPLICIT NONE
 
@@ -20,10 +20,7 @@
    PUBLIC :: id_OCS_strat, id_SO2_strat, id_H2SO4_strat, id_BIN01_strat, id_TEST_strat
 #endif
-#ifdef REPROBUS
-   PUBLIC :: nbtr_bin, nbtr_sulgas
-   PUBLIC :: id_OCS_strat, id_SO2_strat, id_H2SO4_strat, id_BIN01_strat, &
-             id_TEST_strat
-#endif
-
+
+   !=== FOR WATER
+   PUBLIC :: ivap, iliq, isol
    !=== FOR ISOTOPES: General
    PUBLIC :: isot_type, nbIso                              !--- Derived type, full isotopes families database + nb of families
@@ -37,4 +34,6 @@
    PUBLIC :: itZonIso                                      !--- idx "it" (in "isoName(1:niso)") = function(tagging idx, isotope idx)
    PUBLIC :: iqIsoPha                                      !--- idx "iq" (in "qx") = function(isotope idx, phase idx) + aliases
+   PUBLIC :: iqWIsoPha                                      !--- Same as iqIsoPha but with normal water phases
+
    PUBLIC :: isoCheck                                      !--- Run isotopes checking routines
    !=== FOR BOTH TRACERS AND ISOTOPES
@@ -73,5 +72,5 @@
 !  | longName    | Long name (with adv. scheme suffix) for outputs      | ttext       |                        |
 !  | type        | Type (so far: tracer or tag)                         | /           | tracer,tag             |
-!  | phase       | Phases list ("g"as / "l"iquid / "s"olid / "b"lowing) | /           | [g][l][s][b]           |
+!  | phase       | Phases list ("g"as / "l"iquid / "s"olid)             | /           | [g][l][s]              |
 !  | component   | Name(s) of the merged/cumulated section(s)           | /           | coma-separated names   |
 !  | iGeneration | Generation (>=1)                                     | /           |                        |
@@ -98,6 +97,7 @@
 !  | trac   | ntiso  | Isotopes + tagging tracers list + number         | / | ntraciso       |                 |
 !  | zone   | nzone  | Geographic tagging zones   list + number         | / | ntraceurs_zone |                 |
-!  | phase  | nphas  | Phases                     list + number         |                    |[g][l][s][b] 1:4 |
+!  | phase  | nphas  | Phases                     list + number         |                    | [g][l][s], 1:3  |
 !  | iqIsoPha        | Index in "qx"           = f(name(1:ntiso)),phas) | iqiso              | 1:nqtot         |
+!  | iqWIsoPha       | Index in "qx"           = f(name(1:ntiso)),phas) | iqiso              | 1:nqtot         |
 !  | itZonIso        | Index in "trac(1:ntiso)"= f(zone, name(1:niso))  | index_trac         | 1:ntiso         |
 !  +-----------------+--------------------------------------------------+--------------------+-----------------+
@@ -112,4 +112,8 @@
 !$OMP THREADPRIVATE(nqtot, nbtr, nqo, nqtottr, nqCO2, type_trac)
 
+   !=== INDICES OF WATER
+   INTEGER,               SAVE :: ivap,iliq,isol ! Indices for vap, liq and ice
+!$OMP THREADPRIVATE(ivap,iliq,isol)
+
    !=== VARIABLES FOR INCA
    INTEGER,               SAVE, ALLOCATABLE :: conv_flg(:), &   !--- Convection     activation ; needed for INCA        (nbtr)
@@ -123,12 +127,4 @@
   INTEGER, SAVE ::  id_OCS_strat, id_SO2_strat, id_H2SO4_strat, id_BIN01_strat, id_TEST_strat
 !$OMP THREADPRIVATE(id_OCS_strat, id_SO2_strat, id_H2SO4_strat, id_BIN01_strat, id_TEST_strat)
-#endif
-#ifdef REPROBUS
-  INTEGER, SAVE ::  nbtr_bin, nbtr_sulgas
-!$OMP THREADPRIVATE(nbtr_bin, nbtr_sulgas)
-  INTEGER, SAVE ::  id_OCS_strat, id_SO2_strat, id_H2SO4_strat, id_BIN01_strat,&
-                    id_TEST_strat
-!$OMP THREADPRIVATE(id_OCS_strat, id_SO2_strat, id_H2SO4_strat, id_BIN01_strat)
-!$OMP THREADPRIVATE(id_TEST_strat)
 #endif
 
@@ -182,10 +178,8 @@
    INTEGER :: nqtrue                                                 !--- Tracers nb from tracer.def (no higher order moments)
    INTEGER :: iad                                                    !--- Advection scheme number
-   INTEGER :: ic, iq, jq, it, nt, im, nm, iz, k                      !--- Indexes and temporary variables
-   LOGICAL :: lerr, ll, lInit
-   CHARACTER(LEN=1) :: p
+   INTEGER :: iq, jq, nt, im, nm, k                                 !--- Indexes and temporary variables
+   LOGICAL :: lerr, lInit
    TYPE(trac_type), ALLOCATABLE, TARGET :: ttr(:)
    TYPE(trac_type), POINTER             :: t1, t(:)
-   INTEGER :: ierr
    CHARACTER(LEN=maxlen),   ALLOCATABLE :: types_trac(:)  !--- Keyword for tracers type(s), parsed version
    
@@ -262,5 +256,5 @@
 !##############################################################################################################################
    IF(lInit) THEN
-      IF(readTracersFiles(ttp, type_trac == 'repr')) CALL abort_physic(modname, 'problem with tracers file(s)',1)
+      IF(readTracersFiles(ttp, lRepr=type_trac=='repr')) CALL abort_physic(modname, 'problem with tracers file(s)',1)
    ELSE
       CALL msg('No tracers description file(s) reading needed: already done in the dynamics', modname)
@@ -388,5 +382,5 @@
 
    !--- SET FIELDS %iqParent, %nqChildren, %iGeneration, %iqDescen, %nqDescen
-   CALL indexUpdate(tracers)
+   IF(indexUpdate(tracers)) CALL abort_gcm(modname, 'problem when processing isotopes parameters', 1)
 
 !##############################################################################################################################
@@ -404,5 +398,5 @@
    !=== READ PHYSICAL PARAMETERS FOR ISOTOPES
    niso = 0; nzone = 0; nphas = nqo; ntiso = 0; isoCheck = .FALSE.
-   IF(readIsotopesFile()) CALL abort_physic(modname, 'Problem when reading isotopes parameters', 1)
+   IF(processIsotopes()) CALL abort_physic(modname, 'Problem when processing isotopes parameters', 1)
 
 !##############################################################################################################################
@@ -416,5 +410,5 @@
    nqtottr = nqtot - COUNT(delPhase(tracers%gen0Name) == 'H2O' .AND. tracers%component == 'lmdz')
    IF(COUNT(tracers%iso_iName == 0) - COUNT(delPhase(tracers%name) == 'H2O' .AND. tracers%component == 'lmdz') /= nqtottr) &
-      CALL abort_physic(modname, 'pb dans le calcul de nqtottr', 1)
+      CALL abort_physic(modname, 'problem with the computation of nqtottr', 1)
 
    !=== DISPLAY THE RESULTS
@@ -431,7 +425,6 @@
    t => tracers
    CALL msg('Information stored in infotrac_phy :', modname)
-   IF(dispTable('issssssssiiiiiiii', &
-      ['iq    ', 'name  ', 'lName ', 'gen0N ', 'parent', 'type  ', 'phase ', 'compon', 'isPhy ',           &
-                 'iGen  ', 'iqPar ', 'nqDes ', 'nqChld', 'iGroup', 'iName ', 'iZone ', 'iPhase'],          &
+   IF(dispTable('issssssssiiiiiiii', ['iq  ', 'name', 'lNam', 'g0Nm', 'prnt', 'type', 'phas', 'comp',      &
+                              'isPh', 'iGen', 'iqPr', 'nqDe', 'nqCh', 'iGrp', 'iNam', 'iZon', 'iPha'],     &
       cat(t%name, t%longName, t%gen0Name, t%parent, t%type, t%phase, t%component, bool2str(t%isInPhysics)),&
       cat([(iq, iq=1, nqtot)], t%iGeneration, t%iqParent, t%nqDescen, t%nqChildren, t%iso_iGroup,          &
Index: LMDZ6/branches/cirrus/libf/phylmd/lmdz_atke_exchange_coeff.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/lmdz_atke_exchange_coeff.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/lmdz_atke_exchange_coeff.F90	(revision 5202)
@@ -7,5 +7,5 @@
 subroutine atke_compute_km_kh(ngrid,nlay,dtime, &
                         wind_u,wind_v,temp,qvap,play,pinterf,cdrag_uv, &
-                        tke,eps,Km_out,Kh_out)
+                        tke,eps,tke_shear,tke_buoy,tke_trans,Km_out,Kh_out)
 
 !========================================================================
@@ -79,4 +79,7 @@
 
 REAL, DIMENSION(ngrid,nlay+1), INTENT(OUT)    :: eps      ! output: TKE dissipation rate at interface between layers (m2/s3)
+REAL, DIMENSION(ngrid,nlay+1), INTENT(OUT)    :: tke_shear! output: TKE shear production rate (m2/s3)
+REAL, DIMENSION(ngrid,nlay+1), INTENT(OUT)    :: tke_buoy ! output: TKE buoyancy production rate (m2/s3)
+REAL, DIMENSION(ngrid,nlay+1), INTENT(OUT)    :: tke_trans! output: TKE transport (diffusion) term (m2/s3)
 REAL, DIMENSION(ngrid,nlay), INTENT(OUT)      :: Km_out   ! output: Exchange coefficient for momentum at interface between layers (m2/s)
 REAL, DIMENSION(ngrid,nlay), INTENT(OUT)      :: Kh_out   ! output: Exchange coefficient for heat flux at interface between layers (m2/s)
@@ -261,4 +264,7 @@
                 shear2(igrid,ilay) * (1. - Ri(igrid,ilay) / Prandtl(igrid,ilay))
                 eps(igrid,ilay) = (tke(igrid,ilay)**(3./2))/(cepsilon*l_exchange(igrid,ilay))
+                tke_shear(igrid,ilay)=l_exchange(igrid,ilay)*Sm(igrid,ilay)*sqrt(tke(igrid,ilay))*shear2(igrid,ilay) 
+                tke_buoy(igrid,ilay)=-l_exchange(igrid,ilay)*Sm(igrid,ilay)*sqrt(tke(igrid,ilay))*shear2(igrid,ilay) &
+                                    *(Ri(igrid,ilay) / Prandtl(igrid,ilay))
             ENDDO
         ENDDO
@@ -278,5 +284,8 @@
             qq=max(0.,qq)
             tke(igrid,ilay)=0.5*(qq**2)
-            eps(igrid,ilay) = (tke(igrid,ilay)**(3./2))/(cepsilon*l_exchange(igrid,ilay)) 
+            eps(igrid,ilay) = (tke(igrid,ilay)**(3./2))/(cepsilon*l_exchange(igrid,ilay))
+            tke_shear(igrid,ilay)=l_exchange(igrid,ilay)*Sm(igrid,ilay)*sqrt(tke(igrid,ilay))*shear2(igrid,ilay)
+            tke_buoy(igrid,ilay)=-l_exchange(igrid,ilay)*Sm(igrid,ilay)*sqrt(tke(igrid,ilay))*shear2(igrid,ilay) &
+                                *(Ri(igrid,ilay) / Prandtl(igrid,ilay)) 
             ENDDO
         ENDDO
@@ -293,5 +302,8 @@
             qq=(qq+l_exchange(igrid,ilay)*Sm(igrid,ilay)*dtime/sqrt(2.)      & 
                 *shear2(igrid,ilay)*(1.-Ri(igrid,ilay)/Prandtl(igrid,ilay))) &
-                /(1.+qq*dtime/(cepsilon*l_exchange(igrid,ilay)*2.*sqrt(2.))) 
+                /(1.+qq*dtime/(cepsilon*l_exchange(igrid,ilay)*2.*sqrt(2.)))
+            tke_shear(igrid,ilay)=l_exchange(igrid,ilay)*Sm(igrid,ilay)*qq/sqrt(2.)*shear2(igrid,ilay)
+            tke_buoy(igrid,ilay)=-l_exchange(igrid,ilay)*Sm(igrid,ilay)*qq/sqrt(2.)*shear2(igrid,ilay) &
+                                *(Ri(igrid,ilay) / Prandtl(igrid,ilay)) 
             tke(igrid,ilay)=0.5*(qq**2) 
             eps(igrid,ilay) = (tke(igrid,ilay)**(3./2))/(cepsilon*l_exchange(igrid,ilay))
@@ -308,4 +320,7 @@
             eps(igrid,ilay) = (tke(igrid,ilay)**(3./2))/(cepsilon*l_exchange(igrid,ilay))
             qq=max(sqrt(2.*tke(igrid,ilay)),1.e-10)
+            tke_shear(igrid,ilay)=l_exchange(igrid,ilay)*Sm(igrid,ilay)*qq/sqrt(2.)*shear2(igrid,ilay)
+            tke_buoy(igrid,ilay)=-l_exchange(igrid,ilay)*Sm(igrid,ilay)*qq/sqrt(2.)*shear2(igrid,ilay) &
+                                *(Ri(igrid,ilay) / Prandtl(igrid,ilay))
             IF (Ri(igrid,ilay) .LT. 0.) THEN
                 netloss=qq/(2.*sqrt(2.)*cepsilon*l_exchange(igrid,ilay))
@@ -327,4 +342,7 @@
             DO igrid=1,ngrid
             qq=max(sqrt(2.*tke(igrid,ilay)),1.e-10)
+            tke_shear(igrid,ilay)=l_exchange(igrid,ilay)*Sm(igrid,ilay)*qq/sqrt(2.)*shear2(igrid,ilay)
+            tke_buoy(igrid,ilay)=-l_exchange(igrid,ilay)*Sm(igrid,ilay)*qq/sqrt(2.)*shear2(igrid,ilay) &
+                                *(Ri(igrid,ilay) / Prandtl(igrid,ilay))
             qq=(l_exchange(igrid,ilay)*Sm(igrid,ilay)/sqrt(2.)*shear2(igrid,ilay)*(1.-Ri(igrid,ilay)/Prandtl(igrid,ilay)) &
                 +qq*(1.+dtime*qq/(cepsilon*l_exchange(igrid,ilay)*2.*sqrt(2.)))) &
@@ -349,4 +367,6 @@
     tke(igrid,nlay+1)=0.
     eps(igrid,nlay+1)=0.
+    tke_shear(igrid,nlay+1)=0.
+    tke_buoy(igrid,nlay+1)=0.
 END DO
 
@@ -359,4 +379,6 @@
     tke(igrid,1)=ctkes*(ustar**2)
     eps(igrid,1)=0. ! arbitrary as TKE is not properly defined at the surface
+    tke_shear(igrid,1)=0.
+    tke_buoy(igrid,1)=0.
 END DO
 
@@ -364,6 +386,7 @@
 ! vertical diffusion of TKE 
 !==========================
+tke_trans(:,:)=0.
 IF (atke_ok_vdiff) THEN
-    CALL atke_vdiff_tke(ngrid,nlay,dtime,z_lay,z_interf,temp,play,l_exchange,Sm,tke)
+    CALL atke_vdiff_tke(ngrid,nlay,dtime,z_lay,z_interf,temp,play,l_exchange,Sm,tke,tke_trans)
 ENDIF
 
@@ -387,5 +410,5 @@
 
 !===============================================================================================
-subroutine atke_vdiff_tke(ngrid,nlay,dtime,z_lay,z_interf,temp,play,l_exchange,Sm,tke)
+subroutine atke_vdiff_tke(ngrid,nlay,dtime,z_lay,z_interf,temp,play,l_exchange,Sm,tke,tke_trans)
 
 ! routine that computes the vertical diffusion of TKE by the turbulence
@@ -408,5 +431,5 @@
 
 REAL, DIMENSION(ngrid,nlay+1), INTENT(INOUT)  :: tke    ! turbulent kinetic energy at interface between layers
-
+REAL, DIMENSION(ngrid,nlay+1), INTENT(INOUT)  :: tke_trans ! turbulent kinetic energy transport term (m2/s3)
 
 
@@ -480,4 +503,5 @@
 ! update TKE
 tke(:,:)=tke(:,:)+dtke(:,:)
+tke_trans(:,:)=dtke(:,:)/dtime
 
 
Index: LMDZ6/branches/cirrus/libf/phylmd/lmdz_atke_turbulence_ini.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/lmdz_atke_turbulence_ini.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/lmdz_atke_turbulence_ini.F90	(revision 5202)
@@ -50,5 +50,6 @@
       !!
       !! ** Purpose :   Initialization of the atke module and choice of some constants
-      !!               
+      !!                Default values correspond to the  'best' configuration
+      !!                from tuning on GABLS1 in Vignon et al. 2024, JAMES
       !!----------------------------------------------------------------------
 
@@ -73,9 +74,9 @@
 
       ! flag that controls options in atke_compute_km_kh
-      iflag_atke=0
+      iflag_atke=1
       CALL getin_p('iflag_atke',iflag_atke)
 
       ! flag that controls the calculation of mixing length in atke
-      iflag_atke_lmix=0
+      iflag_atke_lmix=3
       CALL getin_p('iflag_atke_lmix',iflag_atke_lmix)
 
@@ -86,5 +87,5 @@
 
       ! activate vertical diffusion of TKE or not
-      atke_ok_vdiff=.false.
+      atke_ok_vdiff=.true.
       CALL getin_p('atke_ok_vdiff',atke_ok_vdiff)
 
@@ -101,13 +102,13 @@
       ! Sun et al 2011, JAMC 
       ! between 10 and 40
-      l0=15.0 
+      l0=42.5279652116005 
       CALL getin_p('atke_l0',l0)
 
       ! critical Richardson number 
-      ric=0.25
+      ric=0.190537327781655
       CALL getin_p('atke_ric',ric)
 
       ! constant for tke dissipation calculation
-      cepsilon=5.87 ! default value as in yamada4
+      cepsilon=8.89273387537601
       CALL getin_p('atke_cepsilon',cepsilon)
 
@@ -131,5 +132,5 @@
 
       ! slope of Pr=f(Ri) for stable conditions
-      pr_slope=5.0 ! default value from Zilitinkevich et al. 2005
+      pr_slope=4.67885738180385
       CALL getin_p('atke_pr_slope',pr_slope)
       if (pr_slope .le. 1) then
@@ -139,5 +140,5 @@
 
       ! value of turbulent prandtl number in neutral conditions (Ri=0)
-      pr_neut=0.8
+      pr_neut=0.837372701768868
       CALL getin_p('atke_pr_neut',pr_neut)
 
@@ -151,5 +152,5 @@
 
       ! coefficient for mixing length depending on local stratification
-      clmix=0.5
+      clmix=0.648055235325291
       CALL getin_p('atke_clmix',clmix)
 
@@ -160,10 +161,10 @@
       ! minimum anisotropy coefficient (defined here as minsqrt(Ez/Ek)) at large Ri. 
       ! From Zilitinkevich et al. 2013, it equals sqrt(0.03)~0.17  
-      smmin=0.17
+      smmin=0.0960838631869678
       CALL getin_p('atke_smmin',smmin)
 
       ! ratio between the eddy diffusivity coeff for tke wrt that for momentum
       ! default value from Lenderink et al. 2004
-      cke=2.
+      cke=2.47069655134662
       CALL getin_p('atke_cke',cke)
 
Index: LMDZ6/branches/cirrus/libf/phylmd/lmdz_call_atke.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/lmdz_call_atke.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/lmdz_call_atke.F90	(revision 5202)
@@ -8,5 +8,5 @@
 contains
 
-subroutine call_atke(dtime,ngrid,nlay,cdrag_uv,cdrag_t,u_surf,v_surf,temp_surf, &
+subroutine call_atke(dtime,ngrid,nlay,nsrf,ni,cdrag_uv,cdrag_t,u_surf,v_surf,temp_surf, &
                         wind_u,wind_v,temp,qvap,play,pinterf, &
                         tke,eps,Km_out,Kh_out)
@@ -16,4 +16,5 @@
 
 USE lmdz_atke_turbulence_ini, ONLY : iflag_num_atke, rg, rd
+USE phys_local_var_mod, ONLY: tke_shear, tke_buoy, tke_trans
 
 implicit none
@@ -26,4 +27,6 @@
 INTEGER, INTENT(IN) :: ngrid ! number of horizontal index (flat grid)
 INTEGER, INTENT(IN) :: nlay ! number of vertical index  
+INTEGER, INTENT(IN) :: nsrf ! surface tile index
+INTEGER, DIMENSION(ngrid), INTENT(IN) :: ni ! array of indices to move from knon to klon arrays
 
 
@@ -50,12 +53,13 @@
 
 
+REAL, DIMENSION(ngrid,nlay+1) :: tke_shear_term,tke_buoy_term,tke_trans_term
 REAL, DIMENSION(ngrid,nlay) :: wind_u_predict, wind_v_predict
 REAL, DIMENSION(ngrid) ::  wind1
-INTEGER i
+INTEGER i,j,k
 
 
 call atke_compute_km_kh(ngrid,nlay,dtime,&
                         wind_u,wind_v,temp,qvap,play,pinterf,cdrag_uv,&
-                        tke,eps,Km_out,Kh_out)
+                        tke,eps,tke_shear_term,tke_buoy_term,tke_trans_term,Km_out,Kh_out)
 
 
@@ -76,10 +80,19 @@
    call atke_compute_km_kh(ngrid,nlay,dtime,&
                         wind_u_predict,wind_v_predict,temp,qvap,play,pinterf,cdrag_uv, &
-                        tke,eps,Km_out,Kh_out)
+                        tke,eps,tke_shear_term,tke_buoy_term,tke_trans_term,Km_out,Kh_out)
 
 end if
 
 
+! Diagnostics of tke loss/source terms
 
+ DO k=1,nlay+1
+    DO i=1,ngrid
+       j=ni(i)
+       tke_shear(j,k,nsrf)=tke_shear_term(i,k)
+       tke_buoy(j,k,nsrf)=tke_buoy_term(i,k)
+       tke_trans(j,k,nsrf)=tke_trans_term(i,k)
+    ENDDO
+ ENDDO
 
 
Index: LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp.F90	(revision 5202)
@@ -7,13 +7,16 @@
 !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 SUBROUTINE lscp(klon,klev,dtime,missing_val,            &
-     paprs,pplay,temp,qt,ptconv,ratqs,                  &
+     paprs,pplay,temp,qt,qice_save,ptconv,ratqs,        &
      d_t, d_q, d_ql, d_qi, rneb, rneblsvol,             &
-     pfraclr,pfracld,                                   &
+     pfraclr, pfracld,                                  &
+     cldfraliq, sigma2_icefracturb,mean_icefracturb,    &
      radocond, radicefrac, rain, snow,                  &
      frac_impa, frac_nucl, beta,                        &
-     prfl, psfl, rhcl, qta, fraca,                     &
-     tv, pspsk, tla, thl, iflag_cld_th,             &
-     iflag_ice_thermo, distcltop, temp_cltop, cell_area,&
-     cf_seri, rvc_seri, u_seri, v_seri, pbl_eps,        &
+     prfl, psfl, rhcl, qta, fraca,                      &
+     tv, pspsk, tla, thl, iflag_cld_th,                 &
+     iflag_ice_thermo, distcltop, temp_cltop,           &
+     tke, tke_dissip,                                   &
+     cell_area,                                         &
+     cf_seri, rvc_seri, u_seri, v_seri,                 &
      qsub, qissr, qcld, subfra, issrfra, gamma_cond,    &
      ratio_qi_qtot, dcf_sub, dcf_con, dcf_mix,          &
@@ -100,5 +103,6 @@
 ! USE de modules contenant des fonctions.
 USE lmdz_cloudth, ONLY : cloudth, cloudth_v3, cloudth_v6, cloudth_mpc 
-USE lmdz_lscp_tools, ONLY : calc_qsat_ecmwf, icefrac_lscp, calc_gammasat
+USE lmdz_lscp_tools, ONLY : calc_qsat_ecmwf, calc_gammasat
+USE lmdz_lscp_tools, ONLY : icefrac_lscp, icefrac_lscp_turb
 USE lmdz_lscp_tools, ONLY : fallice_velocity, distance_to_cloud_top
 USE lmdz_lscp_condensation, ONLY : condensation_lognormal, condensation_ice_supersat
@@ -115,5 +119,5 @@
 USE lmdz_lscp_ini, ONLY : RCPD, RLSTT, RLVTT, RLMLT, RVTMP2, RTT, RD, RG
 USE lmdz_lscp_ini, ONLY : ok_poprecip
-USE lmdz_lscp_ini, ONLY : ok_external_lognormal, ok_ice_supersat, ok_unadjusted_clouds
+USE lmdz_lscp_ini, ONLY : ok_external_lognormal, ok_ice_supersat, ok_unadjusted_clouds, iflag_icefrac
 
 IMPLICIT NONE
@@ -134,4 +138,5 @@
   REAL, DIMENSION(klon,klev),      INTENT(IN)   :: temp            ! temperature (K)
   REAL, DIMENSION(klon,klev),      INTENT(IN)   :: qt              ! total specific humidity (in vapor phase in input) [kg/kg] 
+  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: qice_save       ! ice specific from previous time step [kg/kg]
   INTEGER,                         INTENT(IN)   :: iflag_cld_th    ! flag that determines the distribution of convective clouds
   INTEGER,                         INTENT(IN)   :: iflag_ice_thermo! flag to activate the ice thermodynamics
@@ -141,15 +146,17 @@
   !Inputs associated with thermal plumes
 
-  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: tv             ! virtual potential temperature [K]
-  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: qta            ! specific humidity within thermals [kg/kg]
-  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: fraca          ! fraction of thermals within the mesh [-]
-  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: pspsk          ! exner potential (p/100000)**(R/cp) 
-  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: tla            ! liquid temperature within thermals [K]
+  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: tv                  ! virtual potential temperature [K]
+  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: qta                 ! specific humidity within thermals [kg/kg]
+  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: fraca               ! fraction of thermals within the mesh [-]
+  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: pspsk               ! exner potential (p/100000)**(R/cp) 
+  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: tla                 ! liquid temperature within thermals [K]
+  REAL, DIMENSION(klon,klev+1),      INTENT(IN)   :: tke                 !--turbulent kinetic energy [m2/s2]
+  REAL, DIMENSION(klon,klev+1),      INTENT(IN)   :: tke_dissip          !--TKE dissipation [m2/s3]
 
   ! INPUT/OUTPUT variables
   !------------------------
   
-  REAL, DIMENSION(klon,klev),      INTENT(INOUT)   :: thl          ! liquid potential temperature [K]
-  REAL, DIMENSION(klon,klev),      INTENT(INOUT)   :: ratqs        ! function of pressure that sets the large-scale
+  REAL, DIMENSION(klon,klev),      INTENT(INOUT)   :: thl              ! liquid potential temperature [K]
+  REAL, DIMENSION(klon,klev),      INTENT(INOUT)   :: ratqs            ! function of pressure that sets the large-scale
 
   ! INPUT/OUTPUT condensation and ice supersaturation
@@ -160,5 +167,4 @@
   REAL, DIMENSION(klon,klev),      INTENT(IN)   :: u_seri           ! eastward wind [m/s]
   REAL, DIMENSION(klon,klev),      INTENT(IN)   :: v_seri           ! northward wind [m/s]
-  REAL, DIMENSION(klon,klev+1),    INTENT(IN)   :: pbl_eps          ! TKE dissipation [?]
   REAL, DIMENSION(klon),           INTENT(IN)   :: cell_area        ! area of each cell [m2]
 
@@ -179,4 +185,7 @@
   REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: pfraclr          ! precip fraction clear-sky part [-]
   REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: pfracld          ! precip fraction cloudy part [-]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: cldfraliq           ! liquid fraction of cloud [-]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: sigma2_icefracturb  ! Variance of the diagnostic supersaturation distribution (icefrac_turb) [-]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: mean_icefracturb    ! Mean of the diagnostic supersaturation distribution (icefrac_turb) [-]
   REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: radocond         ! condensed water used in the radiation scheme [kg/kg]
   REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: radicefrac       ! ice fraction of condensed water for radiation scheme
@@ -190,8 +199,8 @@
   REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: beta             ! conversion rate of condensed water
 
-  ! fraction of aerosol scavenging through impaction and nucleation (for on-line)
+  ! fraction of aerosol scavenging through impaction and nucleation    (for on-line)
   
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: frac_impa        ! scavenging fraction due tu impaction [-]
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: frac_nucl        ! scavenging fraction due tu nucleation [-]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: frac_impa           ! scavenging fraction due tu impaction [-]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: frac_nucl           ! scavenging fraction due tu nucleation [-]
   
   ! for condensation and ice supersaturation
@@ -255,6 +264,5 @@
   ! LOCAL VARIABLES:
   !----------------
-
-  REAL,DIMENSION(klon) :: qsl, qsi
+  REAL,DIMENSION(klon) :: qsl, qsi                                ! saturation threshold at current vertical level
   REAL :: zct, zcl,zexpo
   REAL, DIMENSION(klon,klev) :: ctot
@@ -263,10 +271,10 @@
   REAL :: zdelta, zcor, zcvm5
   REAL, DIMENSION(klon) :: zdqsdT_raw
-  REAL, DIMENSION(klon) :: gammasat,dgammasatdt                ! coefficient to make cold condensation at the correct RH and derivative wrt T
-  REAL, DIMENSION(klon) :: Tbef,qlbef,DT
+  REAL, DIMENSION(klon) :: gammasat,dgammasatdt                   ! coefficient to make cold condensation at the correct RH and derivative wrt T
+  REAL, DIMENSION(klon) :: Tbef,qlbef,DT                          ! temperature, humidity and temp. variation during lognormal iteration
   REAL :: num,denom
   REAL :: cste
-  REAL, DIMENSION(klon) :: zpdf_sig,zpdf_k,zpdf_delta
-  REAL, DIMENSION(klon) :: Zpdf_a,zpdf_b,zpdf_e1,zpdf_e2
+  REAL, DIMENSION(klon) :: zpdf_sig,zpdf_k,zpdf_delta             ! lognormal parameters
+  REAL, DIMENSION(klon) :: Zpdf_a,zpdf_b,zpdf_e1,zpdf_e2          ! lognormal intermediate variables
   REAL :: erf
   REAL, DIMENSION(klon) :: zfice_th
@@ -285,4 +293,5 @@
   REAL :: zmelt,zrain,zsnow,zprecip
   REAL, DIMENSION(klon) :: dzfice
+  REAL, DIMENSION(klon) :: zfice_turb, dzfice_turb
   REAL :: zsolid
   REAL, DIMENSION(klon) :: qtot, qzero
@@ -315,5 +324,6 @@
   REAL, DIMENSION(klon,klev) :: radocondi, radocondl
   REAL :: effective_zneb
-  REAL, DIMENSION(klon) :: distcltop1D, temp_cltop1D
+  REAL, DIMENSION(klon) :: zdistcltop, ztemp_cltop
+  REAL, DIMENSION(klon) :: zqliq, zqice, zqvapcl        ! for icefrac_lscp_turb
   
   ! for condensation and ice supersaturation
@@ -328,5 +338,4 @@
   REAL :: min_qParent, min_ratio
 
-
   INTEGER i, k, n, kk, iter
   INTEGER, DIMENSION(klon) :: n_i
@@ -382,4 +391,7 @@
 pfraclr(:,:)=0.0
 pfracld(:,:)=0.0
+cldfraliq(:,:)=0.
+sigma2_icefracturb(:,:)=0.
+mean_icefracturb(:,:)=0.
 radocond(:,:) = 0.0
 radicefrac(:,:) = 0.0
@@ -391,4 +403,6 @@
 zfice(:)=0.0
 dzfice(:)=0.0
+zfice_turb(:)=0.0
+dzfice_turb(:)=0.0
 zqprecl(:)=0.0
 zqpreci(:)=0.0
@@ -405,6 +419,6 @@
 d_tot_zneb(:) = 0.0
 qzero(:) = 0.0
-distcltop1D(:)=0.0
-temp_cltop1D(:) = 0.0
+zdistcltop(:)=0.0
+ztemp_cltop(:) = 0.0
 ztupnew(:)=0.0
 
@@ -459,5 +473,4 @@
 
 
-
 !c_iso: variable initialisation for iso 
 
@@ -478,4 +491,9 @@
 
     ! Initialisation temperature and specific humidity
+    ! temp(klon,klev) is not modified by the routine, instead all changes in temperature are made on zt
+    ! at the end of the klon loop, a temperature incremtent d_t due to all processes
+    ! (thermalization, evap/sub incoming precip, cloud formation, precipitation processes) is calculated 
+    ! d_t = temperature tendency due to lscp
+    ! The temperature of the overlying layer is updated here because needed for thermalization
     DO i = 1, klon
         zt(i)=temp(i,k)
@@ -812,5 +830,5 @@
                 ELSEIF (iflag_cloudth_vert .EQ. 7) THEN
                    ! Updated version of Arnaud Jam (correction by E. Vignon) + adapted treatment
-                   ! for boundary-layer mixed phase clouds following Vignon et al.  
+                   ! for boundary-layer mixed phase clouds 
                     CALL cloudth_mpc(klon,klev,k,mpc_bl_points,zt,zq,qta(:,k),fraca(:,k), &
                                      pspsk(:,k),paprs(:,k+1),paprs(:,k),pplay(:,k), tla(:,k), &
@@ -834,15 +852,15 @@
             
                 ! lognormal 
-            lognormale = .TRUE.
+            lognormale(:) = .TRUE.
 
         ELSEIF (iflag_cld_th .GE. 6) THEN
             
                 ! lognormal distribution when no thermals 
-            lognormale = fraca(:,k) < min_frac_th_cld
+            lognormale(:) = fraca(:,k) < min_frac_th_cld
 
         ELSE
                 ! When iflag_cld_th=5, we always assume
                 ! bi-gaussian distribution
-            lognormale = .FALSE.
+            lognormale(:) = .FALSE.
         
         ENDIF
@@ -900,8 +918,8 @@
                   IF (iflag_t_glace.GE.4) THEN
                   ! For iflag_t_glace GE 4 the phase partition function dependends on temperature AND distance to cloud top
-                       CALL distance_to_cloud_top(klon,klev,k,temp,pplay,paprs,rneb,distcltop1D,temp_cltop1D)
+                       CALL distance_to_cloud_top(klon,klev,k,temp,pplay,paprs,rneb,zdistcltop,ztemp_cltop)
                   ENDIF
-                  CALL icefrac_lscp(klon, zt(:), iflag_ice_thermo, distcltop1D(:),temp_cltop1D(:),zfice(:),dzfice(:))
-
+
+                  CALL icefrac_lscp(klon, zt(:), iflag_ice_thermo, zdistcltop(:),ztemp_cltop(:),zfice(:),dzfice(:))
 
                   !--AB Activates a condensation scheme that allows for
@@ -938,5 +956,5 @@
                         pplay(:,k), paprs(:,k), paprs(:,k+1), &
                         cf_seri(:,k), rvc_seri(:,k), ratio_qi_qtot(:,k), &
-                        shear(:), pbl_eps(:,k), cell_area(:), &
+                        shear(:), tke_dissip(:,k), cell_area(:), &
                         Tbef(:), zq(:), zqs(:), gammasat(:), ratqs(:,k), keepgoing(:), &
                         rneb(:,k), zqn(:), qvc(:), issrfra(:,k), qissr(:,k), &
@@ -1017,5 +1035,6 @@
                             cste=RLSTT
                         ENDIF
-
+                        
+                        ! LEA_R : check formule
                         IF ( ok_unadjusted_clouds ) THEN
                           !--AB We relax the saturation adjustment assumption
@@ -1059,17 +1078,25 @@
         ! For iflag_t_glace GE 4 the phase partition function dependends on temperature AND distance to cloud top
         IF (iflag_t_glace.GE.4) THEN
-            CALL distance_to_cloud_top(klon,klev,k,temp,pplay,paprs,rneb,distcltop1D,temp_cltop1D)
-            distcltop(:,k)=distcltop1D(:)
-            temp_cltop(:,k)=temp_cltop1D(:)
-        ENDIF   
-        ! Partition function in stratiform clouds (will be overwritten in boundary-layer MPCs)
-        CALL icefrac_lscp(klon,zt,iflag_ice_thermo,distcltop1D,temp_cltop1D,zfice,dzfice)
-
+           CALL distance_to_cloud_top(klon,klev,k,temp,pplay,paprs,rneb,zdistcltop,ztemp_cltop)
+           distcltop(:,k)=zdistcltop(:)
+           temp_cltop(:,k)=ztemp_cltop(:)
+        ENDIF
+
+        ! Partition function depending on temperature
+        CALL icefrac_lscp(klon, zt, iflag_ice_thermo, zdistcltop, ztemp_cltop, zfice, dzfice)
+
+        ! Partition function depending on tke for non shallow-convective clouds 
+        IF (iflag_icefrac .GE. 1) THEN
+
+           CALL icefrac_lscp_turb(klon, dtime, Tbef, pplay(:,k), paprs(:,k), paprs(:,k+1), qice_save(:,k), ziflcld, zqn, &
+           rneb(:,k), tke(:,k), tke_dissip(:,k), zqliq, zqvapcl, zqice, zfice_turb, dzfice_turb, cldfraliq(:,k),sigma2_icefracturb(:,k), mean_icefracturb(:,k))
+
+        ENDIF
 
         ! Water vapor update, Phase determination and subsequent latent heat exchange
         DO i=1, klon
-
+            ! Overwrite phase partitioning in boundary layer mixed phase clouds when the 
+            ! iflag_cloudth_vert=7 and specific param is activated
             IF (mpc_bl_points(i,k) .GT. 0) THEN
-               
                 zcond(i) = MAX(0.0,qincloud_mpc(i))*rneb(i,k)
                 ! following line is very strange and probably wrong
@@ -1078,7 +1105,5 @@
                 zq(i) = zq(i) - zcond(i)        
                 zfice(i)=zfice_th(i)
-
             ELSE
-
                 ! Checks on rneb, rhcl and zqn
                 IF (rneb(i,k) .LE. 0.0) THEN
@@ -1108,4 +1133,12 @@
                     ! following line is very strange and probably wrong:
                     rhcl(i,k)=(zqs(i)+zq(i))/2./zqs(i)
+                    ! Overwrite partitioning for non shallow-convective clouds if iflag_icefrac>1 (icefrac turb param) 
+                    IF (iflag_icefrac .GE. 1) THEN
+                        IF (lognormale(i)) THEN  
+                           zcond(i)  = zqliq(i) + zqice(i)
+                           zfice(i)=zfice_turb(i)
+                           rhcl(i,k) = zqvapcl(i) * rneb(i,k) + (zq(i) - zqn(i)) * (1.-rneb(i,k))
+                        ENDIF
+                    ENDIF
                 ENDIF
 
@@ -1493,5 +1526,8 @@
                 znebprecipcld(i)=0.0
             ENDIF
-
+        !IF ( ((1-zfice(i))*zoliq(i) .GT. 0.) .AND. (zt(i) .LE. 233.15) ) THEN
+        !print*,'WARNING LEA OLIQ A <-40°C '
+        !print*,'zt,Tbef,oliq,oice,cldfraliq,icefrac,rneb',zt(i),Tbef(i),(1-zfice(i))*zoliq(i),zfice(i)*zoliq(i),cldfraliq(i,k),zfice(i),rneb(i,k)
+        !ENDIF 
         ENDDO
 
Index: LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp_ini.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp_ini.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp_ini.F90	(revision 5202)
@@ -67,29 +67,33 @@
   !$OMP THREADPRIVATE(iflag_t_glace)
 
-  INTEGER, SAVE, PROTECTED :: iflag_cloudth_vert=0         ! option for determining cloud fraction and content in convective boundary layers
+  INTEGER, SAVE, PROTECTED :: iflag_cloudth_vert=0          ! option for determining cloud fraction and content in convective boundary layers
   !$OMP THREADPRIVATE(iflag_cloudth_vert)
 
-  INTEGER, SAVE, PROTECTED :: iflag_gammasat=0             ! which threshold for homogeneous nucleation below -40oC
+  INTEGER, SAVE, PROTECTED :: iflag_gammasat=0              ! which threshold for homogeneous nucleation below -40oC
   !$OMP THREADPRIVATE(iflag_gammasat)
 
-  INTEGER, SAVE, PROTECTED :: iflag_rain_incloud_vol=0     ! use of volume cloud fraction for rain autoconversion 
+  INTEGER, SAVE, PROTECTED :: iflag_rain_incloud_vol=0      ! use of volume cloud fraction for rain autoconversion 
   !$OMP THREADPRIVATE(iflag_rain_incloud_vol)
 
-  INTEGER, SAVE, PROTECTED :: iflag_bergeron=0             ! bergeron effect for liquid precipitation treatment  
+  INTEGER, SAVE, PROTECTED :: iflag_bergeron=0              ! bergeron effect for liquid precipitation treatment  
   !$OMP THREADPRIVATE(iflag_bergeron)
 
-  INTEGER, SAVE, PROTECTED :: iflag_fisrtilp_qsat=0        ! qsat adjustment (iterative) during autoconversion
+  INTEGER, SAVE, PROTECTED :: iflag_fisrtilp_qsat=0         ! qsat adjustment (iterative) during autoconversion
   !$OMP THREADPRIVATE(iflag_fisrtilp_qsat)
 
-  INTEGER, SAVE, PROTECTED :: iflag_pdf=0                  ! type of subgrid scale qtot pdf
+  INTEGER, SAVE, PROTECTED :: iflag_pdf=0                   ! type of subgrid scale qtot pdf
   !$OMP THREADPRIVATE(iflag_pdf)
 
-  INTEGER, SAVE, PROTECTED :: iflag_autoconversion=0       ! autoconversion option
+  INTEGER, SAVE, PROTECTED :: iflag_icefrac=0               ! which phase partitioning function to use
+  !$OMP THREADPRIVATE(iflag_icefrac)
+
+  INTEGER, SAVE, PROTECTED :: iflag_autoconversion=0        ! autoconversion option
   !$OMP THREADPRIVATE(iflag_autoconversion)
 
-  LOGICAL, SAVE, PROTECTED :: reevap_ice=.false.           ! no liquid precip for T< threshold
+
+  LOGICAL, SAVE, PROTECTED :: reevap_ice=.false.            ! no liquid precip for T< threshold
   !$OMP THREADPRIVATE(reevap_ice)
 
-  REAL, SAVE, PROTECTED :: cld_lc_lsc=2.6e-4               ! liquid autoconversion coefficient, stratiform rain
+  REAL, SAVE, PROTECTED :: cld_lc_lsc=2.6e-4                ! liquid autoconversion coefficient, stratiform rain
   !$OMP THREADPRIVATE(cld_lc_lsc)
 
@@ -118,5 +122,5 @@
   !$OMP THREADPRIVATE(coef_eva)
 
-  REAL, SAVE, PROTECTED :: coef_sub                        ! tuning coefficient ice precip sublimation
+  REAL, SAVE, PROTECTED :: coef_sub                         ! tuning coefficient ice precip sublimation
   !$OMP THREADPRIVATE(coef_sub)
 
@@ -124,5 +128,5 @@
   !$OMP THREADPRIVATE(expo_eva)
 
-  REAL, SAVE, PROTECTED :: expo_sub                       ! tuning coefficient ice precip sublimation
+  REAL, SAVE, PROTECTED :: expo_sub                         ! tuning coefficient ice precip sublimation
   !$OMP THREADPRIVATE(expo_sub)
 
@@ -226,4 +230,22 @@
   !$OMP THREADPRIVATE(thresh_precip_frac)
 
+  REAL, SAVE, PROTECTED :: tau_mixenv=100000                ! Homogeneization time of mixed phase clouds [s]
+  !$OMP THREADPRIVATE(tau_mixenv)
+
+    REAL, SAVE, PROTECTED :: capa_crystal=1.                ! Sursaturation of ice part in mixed phase clouds [-]
+  !$OMP THREADPRIVATE(capa_crystal)
+
+  REAL, SAVE, PROTECTED :: lmix_mpc=1000                    ! Length of turbulent zones in Mixed Phase Clouds [m]
+  !$OMP THREADPRIVATE(lmix_mpc)
+
+  REAL, SAVE, PROTECTED :: naero5=0.5                       ! Number concentration of aerosol larger than 0.5 microns [scm-3]
+  !$OMP THREADPRIVATE(naero5)
+
+  REAL, SAVE, PROTECTED :: gamma_snwretro = 0.              ! Proportion of snow taken into account in ice retroaction in icefrac_turb [-]
+  !$OMP THREADPRIVATE(gamma_snwretro)
+
+  REAL, SAVE, PROTECTED :: gamma_taud = 1.                  ! Tuning coeff for tau_dissipturb [-]
+  !$OMP THREADPRIVATE(gamma_taud)
+
   REAL, SAVE, PROTECTED :: gamma_col=1.                     ! A COMMENTER TODO [-]
   !$OMP THREADPRIVATE(gamma_col)
@@ -235,17 +257,17 @@
   !$OMP THREADPRIVATE(gamma_rim)
 
-  REAL, SAVE, PROTECTED :: rho_rain=1000.                    ! A COMMENTER TODO [kg/m3]
+  REAL, SAVE, PROTECTED :: rho_rain=1000.                   ! Rain density [kg/m3]
   !$OMP THREADPRIVATE(rho_rain)
 
-  REAL, SAVE, PROTECTED :: rho_ice=920.                    ! A COMMENTER TODO [kg/m3]
+  REAL, SAVE, PROTECTED :: rho_ice=920.                     ! Ice density  [kg/m3]
   !$OMP THREADPRIVATE(rho_ice)
 
-  REAL, SAVE, PROTECTED :: r_rain=500.E-6                   ! A COMMENTER TODO [m]
+  REAL, SAVE, PROTECTED :: r_rain=500.E-6                   ! Rain droplets radius for POPRECIP [m]
   !$OMP THREADPRIVATE(r_rain)
 
-  REAL, SAVE, PROTECTED :: r_snow=1.E-3                    ! A COMMENTER TODO [m]
+  REAL, SAVE, PROTECTED :: r_snow=1.E-3                     ! Ice crystals radius for POPRECIP [m]
   !$OMP THREADPRIVATE(r_snow)
 
-  REAL, SAVE, PROTECTED :: tau_auto_snow_min=100.          ! A COMMENTER TODO [s]
+  REAL, SAVE, PROTECTED :: tau_auto_snow_min=100.           ! A COMMENTER TODO [s]
   !$OMP THREADPRIVATE(tau_auto_snow_min)
 
@@ -256,32 +278,32 @@
   !$OMP THREADPRIVATE(eps)
 
-  REAL, SAVE, PROTECTED :: gamma_melt=1.                   ! A COMMENTER TODO [-]
+  REAL, SAVE, PROTECTED :: gamma_melt=1.                    ! A COMMENTER TODO [-]
   !$OMP THREADPRIVATE(gamma_melt)
 
-  REAL, SAVE, PROTECTED :: alpha_freez=4.                 ! A COMMENTER TODO [-]
+  REAL, SAVE, PROTECTED :: alpha_freez=4.                   ! A COMMENTER TODO [-]
   !$OMP THREADPRIVATE(alpha_freez)
 
-  REAL, SAVE, PROTECTED :: beta_freez=0.1                 ! A COMMENTER TODO [m-3.s-1]
+  REAL, SAVE, PROTECTED :: beta_freez=0.1                   ! A COMMENTER TODO [m-3.s-1]
   !$OMP THREADPRIVATE(beta_freez)
 
-  REAL, SAVE, PROTECTED :: gamma_freez=1.                 ! A COMMENTER TODO [-]
+  REAL, SAVE, PROTECTED :: gamma_freez=1.                   ! A COMMENTER TODO [-]
   !$OMP THREADPRIVATE(gamma_freez)
 
-  REAL, SAVE, PROTECTED :: rain_fallspeed=4.              ! A COMMENTER TODO [m/s]
+  REAL, SAVE, PROTECTED :: rain_fallspeed=4.                ! A COMMENTER TODO [m/s]
   !$OMP THREADPRIVATE(rain_fallspeed)
 
-  REAL, SAVE, PROTECTED :: rain_fallspeed_clr              ! A COMMENTER TODO [m/s]
+  REAL, SAVE, PROTECTED :: rain_fallspeed_clr                ! A COMMENTER TODO [m/s]
   !$OMP THREADPRIVATE(rain_fallspeed_clr)
 
-  REAL, SAVE, PROTECTED :: rain_fallspeed_cld             ! A COMMENTER TODO [m/s]
+  REAL, SAVE, PROTECTED :: rain_fallspeed_cld               ! A COMMENTER TODO [m/s]
   !$OMP THREADPRIVATE(rain_fallspeed_cld)
 
-  REAL, SAVE, PROTECTED :: snow_fallspeed=1.             ! A COMMENTER TODO [m/s]
+  REAL, SAVE, PROTECTED :: snow_fallspeed=1.               ! A COMMENTER TODO [m/s]
   !$OMP THREADPRIVATE(snow_fallspeed)
 
-  REAL, SAVE, PROTECTED :: snow_fallspeed_clr             ! A COMMENTER TODO [m/s]
+  REAL, SAVE, PROTECTED :: snow_fallspeed_clr               ! A COMMENTER TODO [m/s]
   !$OMP THREADPRIVATE(snow_fallspeed_clr)
 
-  REAL, SAVE, PROTECTED :: snow_fallspeed_cld             ! A COMMENTER TODO [m/s]
+  REAL, SAVE, PROTECTED :: snow_fallspeed_cld               ! A COMMENTER TODO [m/s]
   !$OMP THREADPRIVATE(snow_fallspeed_cld)
   !--End of the parameters for poprecip
@@ -325,5 +347,5 @@
     RLMLT=RLMLT_in
     RTT=RTT_in
-    RG=RG_in
+    RV=RV_in
     RVTMP2=RVTMP2_in
     RPI=RPI_in
@@ -347,4 +369,5 @@
     CALL getin_p('iflag_fisrtilp_qsat',iflag_fisrtilp_qsat)
     CALL getin_p('iflag_pdf',iflag_pdf)
+    CALL getin_p('iflag_icefrac',iflag_icefrac)
     CALL getin_p('reevap_ice',reevap_ice)
     CALL getin_p('cld_lc_lsc',cld_lc_lsc)
@@ -368,4 +391,10 @@
     CALL getin_p('dist_liq',dist_liq)
     CALL getin_p('tresh_cl',tresh_cl)
+    CALL getin_p('tau_mixenv',tau_mixenv)
+    CALL getin_p('capa_crystal',capa_crystal)
+    CALL getin_p('lmix_mpc',lmix_mpc)
+    CALL getin_p('naero5',naero5)
+    CALL getin_p('gamma_snwretro',gamma_snwretro)
+    CALL getin_p('gamma_taud',gamma_taud)
     CALL getin_p('iflag_oldbug_fisrtilp',iflag_oldbug_fisrtilp)
     CALL getin_p('temp_nowater',temp_nowater)
@@ -430,4 +459,5 @@
     WRITE(lunout,*) 'lscp_ini, iflag_fisrtilp_qsat:', iflag_fisrtilp_qsat
     WRITE(lunout,*) 'lscp_ini, iflag_pdf', iflag_pdf
+    WRITE(lunout,*) 'lscp_ini, iflag_icefrac', iflag_icefrac
     WRITE(lunout,*) 'lscp_ini, reevap_ice', reevap_ice
     WRITE(lunout,*) 'lscp_ini, cld_lc_lsc', cld_lc_lsc
@@ -448,4 +478,10 @@
     WRITE(lunout,*) 'lscp_ini, dist_liq', dist_liq
     WRITE(lunout,*) 'lscp_ini, tresh_cl', tresh_cl
+    WRITE(lunout,*) 'lscp_ini, tau_mixenv', tau_mixenv
+    WRITE(lunout,*) 'lscp_ini, capa_crystal', capa_crystal
+    WRITE(lunout,*) 'lscp_ini, lmix_mpc', lmix_mpc
+    WRITE(lunout,*) 'lscp_ini, naero5', naero5
+    WRITE(lunout,*) 'lscp_ini, gamma_snwretro', gamma_snwretro
+    WRITE(lunout,*) 'lscp_ini, gamma_taud', gamma_taud
     WRITE(lunout,*) 'lscp_ini, iflag_oldbug_fisrtilp', iflag_oldbug_fisrtilp
     WRITE(lunout,*) 'lscp_ini, fl_cor_ebil', fl_cor_ebil
Index: LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp_poprecip.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp_poprecip.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp_poprecip.F90	(revision 5202)
@@ -559,7 +559,10 @@
 
     !--Same as for aggregation
-    !--Eff_snow_liq formula: following Milbrandt and Yau 2005,
+    !--Eff_snow_liq formula:
     !--it s a product of a collection efficiency and a sticking efficiency
-    Eff_snow_ice = 0.05 * EXP( 0.1 * ( temp(i) - RTT ) )
+    ! Milbrandt and Yau formula that gives very low values:
+    ! Eff_snow_ice = 0.05 * EXP( 0.1 * ( temp(i) - RTT ) )
+    ! Lin 1983's formula 
+    Eff_snow_ice = EXP( 0.025 * MIN( ( temp(i) - RTT ), 0.) ) 
     !--rho_snow formula follows Brandes et al. 2007 (JAMC)
     rho_snow = 1.e3 * 0.178 * ( r_snow * 2. * 1000. )**(-0.922)
@@ -653,7 +656,7 @@
     !--NB.: this process needs a temperature adjustment
 
-    !--Eff_snow_liq formula: following Seifert and Beheng 2006,
-    !--assuming a cloud droplet diameter of 20 microns.
-    Eff_snow_liq = 0.2
+    !--Eff_snow_liq formula: following Ferrier 1994,
+    !--assuming 1
+    Eff_snow_liq = 1.0
     !--rho_snow formula follows Brandes et al. 2007 (JAMC)
     rho_snow = 1.e3 * 0.178 * ( r_snow * 2. * 1000. )**(-0.922)
Index: LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp_tools.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp_tools.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/lmdz_lscp_tools.F90	(revision 5202)
@@ -136,5 +136,5 @@
     CHARACTER (len = 80) :: abort_message
 
-    IF ((iflag_t_glace.LT.2) .OR. (iflag_t_glace.GT.6)) THEN
+    IF ((iflag_t_glace.LT.2)) THEN !.OR. (iflag_t_glace.GT.6)) THEN
        abort_message = 'lscp cannot be used if iflag_t_glace<2 or >6'
        CALL abort_physic(modname,abort_message,1)
@@ -194,5 +194,5 @@
 
         ! with CMIP6 function of temperature at cloud top
-        IF (iflag_t_glace .EQ. 5) THEN 
+        IF ((iflag_t_glace .EQ. 5) .OR. (iflag_t_glace .EQ. 7)) THEN 
                 liqfrac_tmp = (temp(i)-t_glace_min) / (t_glace_max-t_glace_min)
                 liqfrac_tmp =  MIN(MAX(liqfrac_tmp,0.0),1.0)
@@ -232,8 +232,7 @@
                 ENDIF 
         ENDIF
-
+      
 
      ENDDO ! klon
- 
      RETURN
  
@@ -241,4 +240,275 @@
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
+SUBROUTINE ICEFRAC_LSCP_TURB(klon, dtime, temp, pplay, paprsdn, paprsup, qice_ini, snowcld, qtot_incl, cldfra, tke, tke_dissip, qliq, qvap_cld, qice, icefrac, dicefracdT, cldfraliq, sigma2_icefracturb, mean_icefracturb)
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  ! Compute the liquid, ice and vapour content (+ice fraction) based 
+  ! on turbulence (see Fields 2014, Furtado 2016, Raillard 2025)
+  ! L.Raillard (30/08/24)
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+   USE lmdz_lscp_ini, ONLY : prt_level, lunout
+   USE lmdz_lscp_ini, ONLY : RCPD, RLSTT, RLVTT, RLMLT, RVTMP2, RTT, RD, RG, RV, RPI
+   USE lmdz_lscp_ini, ONLY : seuil_neb, temp_nowater
+   USE lmdz_lscp_ini, ONLY : tau_mixenv, lmix_mpc, naero5, gamma_snwretro, gamma_taud, capa_crystal
+   USE lmdz_lscp_ini, ONLY : eps
+
+   IMPLICIT NONE
+
+   INTEGER,   INTENT(IN)                           :: klon              !--number of horizontal grid points
+   REAL,      INTENT(IN)                           :: dtime             !--time step [s]
+
+   REAL,      INTENT(IN),       DIMENSION(klon)    :: temp              !--temperature
+   REAL,      INTENT(IN),       DIMENSION(klon)    :: pplay             !--pressure in the middle of the layer       [Pa]
+   REAL,      INTENT(IN),       DIMENSION(klon)    :: paprsdn           !--pressure at the bottom interface of the layer [Pa]
+   REAL,      INTENT(IN),       DIMENSION(klon)    :: paprsup           !--pressure at the top interface of the layer [Pa]
+   REAL,      INTENT(IN),       DIMENSION(klon)    :: qtot_incl         !--specific total cloud water content, in-cloud content [kg/kg]
+   REAL,      INTENT(IN),       DIMENSION(klon)    :: cldfra            !--cloud fraction in gridbox [-]
+   REAL,      INTENT(IN),       DIMENSION(klon)    :: tke               !--turbulent kinetic energy [m2/s2]
+   REAL,      INTENT(IN),       DIMENSION(klon)    :: tke_dissip        !--TKE dissipation [m2/s3]
+
+   REAL,      INTENT(IN),       DIMENSION(klon)    :: qice_ini          !--initial specific ice content gridbox-mean [kg/kg]
+   REAL,      INTENT(IN),       DIMENSION(klon)    :: snowcld
+   REAL,      INTENT(OUT),      DIMENSION(klon)    :: qliq              !--specific liquid content gridbox-mean [kg/kg]
+   REAL,      INTENT(OUT),      DIMENSION(klon)    :: qvap_cld          !--specific cloud vapor content, gridbox-mean [kg/kg]
+   REAL,      INTENT(OUT),      DIMENSION(klon)    :: qice              !--specific ice content gridbox-mean [kg/kg]
+   REAL,      INTENT(OUT),      DIMENSION(klon)    :: icefrac           !--fraction of ice in condensed water [-]
+   REAL,      INTENT(OUT),      DIMENSION(klon)    :: dicefracdT
+
+   REAL,      INTENT(OUT),      DIMENSION(klon)    :: cldfraliq         !--fraction of cldfra which is liquid only
+   REAL,      INTENT(OUT),      DIMENSION(klon)    :: sigma2_icefracturb     !--Temporary 
+   REAL,      INTENT(OUT),      DIMENSION(klon)    :: mean_icefracturb      !--Temporary 
+
+   REAL, DIMENSION(klon) :: qzero, qsatl, dqsatl, qsati, dqsati         !--specific humidity saturation values
+   INTEGER :: i
+
+   REAL :: qvap_incl, qice_incl, qliq_incl, qiceini_incl                !--In-cloud specific quantities [kg/kg]
+   REAL :: qsnowcld_incl
+   !REAL :: capa_crystal                                                 !--Capacitance of ice crystals  [-]
+   REAL :: water_vapor_diff                                             !--Water-vapour diffusion coefficient in air [m2/s] (function of T&P)
+   REAL :: air_thermal_conduct                                          !--Thermal conductivity of air [J/m/K/s] (function of T)
+   REAL :: C0                                                           !--Lagrangian structure function [-]
+   REAL :: tau_mixingenv
+   REAL :: tau_dissipturb
+   REAL :: invtau_phaserelax
+   REAL :: sigma2_pdf, mean_pdf
+   REAL :: ai, bi, B0
+   REAL :: sursat_iceliq
+   REAL :: sursat_env
+   REAL :: liqfra_max
+   REAL :: sursat_iceext
+   REAL :: nb_crystals                                                  !--number concentration of ice crystals [#/m3]
+   REAL :: moment1_PSD                                                  !--1st moment of ice PSD 
+   REAL :: N0_PSD, lambda_PSD                                           !--parameters of the exponential PSD
+
+   REAL :: rho_ice                                                      !--ice density [kg/m3]
+   REAL :: cldfra1D
+   REAL :: deltaz, rho_air
+   REAL :: psati                                                        !--saturation vapor pressure wrt i [Pa]
+   
+   C0            = 10.                                                  !--value assumed in Field2014            
+   rho_ice       = 950.
+   sursat_iceext = -0.1
+   !capa_crystal  = 1. !r_ice                                       
+   qzero(:)      = 0.
+   cldfraliq(:)  = 0.
+   icefrac(:)    = 0.
+   dicefracdT(:) = 0.
+
+   sigma2_icefracturb(:) = 0.
+   mean_icefracturb(:)  = 0.
+
+   !--wrt liquid water
+   CALL calc_qsat_ecmwf(klon,temp(:),qzero(:),pplay(:),RTT,1,.false.,qsatl(:),dqsatl(:))
+   !--wrt ice
+   CALL calc_qsat_ecmwf(klon,temp(:),qzero(:),pplay(:),RTT,2,.false.,qsati(:),dqsati(:))
+
+
+    DO i=1,klon
+
+
+     rho_air  = pplay(i) / temp(i) / RD
+     !deltaz   = ( paprsdn(i) - paprsup(i) ) / RG / rho_air(i)
+     ! because cldfra is intent in, but can be locally modified due to test 
+     cldfra1D = cldfra(i)
+     IF (cldfra(i) .LE. 0.) THEN
+        qvap_cld(i)   = 0.
+        qliq(i)       = 0.
+        qice(i)       = 0.
+        cldfraliq(i)  = 0.
+        icefrac(i)    = 0.
+        dicefracdT(i) = 0.
+
+     ! If there is a cloud
+     ELSE
+        IF (cldfra(i) .GE. 1.0) THEN
+           cldfra1D = 1.0
+        END IF
+        
+        ! T>0°C, no ice allowed
+        IF ( temp(i) .GE. RTT ) THEN
+           qvap_cld(i)   = qsatl(i) * cldfra1D
+           qliq(i)       = MAX(0.0,qtot_incl(i)-qsatl(i))  * cldfra1D
+           qice(i)       = 0.
+           cldfraliq(i)  = 1.
+           icefrac(i)    = 0.
+           dicefracdT(i) = 0.
+        
+        ! T<-38°C, no liquid allowed
+        ELSE IF ( temp(i) .LE. temp_nowater) THEN
+           qvap_cld(i)   = qsati(i) * cldfra1D
+           qliq(i)       = 0.
+           qice(i)       = MAX(0.0,qtot_incl(i)-qsati(i)) * cldfra1D
+           cldfraliq(i)  = 0.
+           icefrac(i)    = 1.
+           dicefracdT(i) = 0.
+
+        ! MPC temperature
+        ELSE
+           ! Not enough TKE     
+           IF ( tke_dissip(i) .LE. eps )  THEN
+              qvap_cld(i)   = qsati(i) * cldfra1D
+              qliq(i)       = 0.
+              qice(i)       = MAX(0.,qtot_incl(i)-qsati(i)) * cldfra1D   
+              cldfraliq(i)  = 0.
+              icefrac(i)    = 1.
+              dicefracdT(i) = 0.
+           
+           ! Enough TKE   
+           ELSE  
+              print*,"MOUCHOIRACTIVE"
+              !---------------------------------------------------------
+              !--               ICE SUPERSATURATION PDF   
+              !--------------------------------------------------------- 
+              !--If -38°C< T <0°C and there is enough turbulence, 
+              !--we compute the cloud liquid properties with a Gaussian PDF 
+              !--of ice supersaturation F(Si) (Field2014, Furtado2016). 
+              !--Parameters of the PDF are function of turbulence and 
+              !--microphysics/existing ice.
+
+              sursat_iceliq = qsatl(i)/qsati(i) - 1.
+              psati         = qsati(i) * pplay(i) / (RD/RV)
+
+              !-------------- MICROPHYSICAL TERMS --------------
+              !--We assume an exponential ice PSD whose parameters 
+              !--are computed following Morrison&Gettelman 2008
+              !--Ice number density is assumed equals to INP density 
+              !--which is a function of temperature (DeMott 2010)  
+              !--bi and B0 are microphysical function characterizing 
+              !--vapor/ice interactions
+              !--tau_phase_relax is the typical time of vapor deposition
+              !--onto ice crystals
+              
+              qiceini_incl  = qice_ini(i) / cldfra1D
+              qsnowcld_incl = snowcld(i) * RG * dtime / ( paprsdn(i) - paprsup(i) ) / cldfra1D
+              sursat_env    = max(0., (qtot_incl(i) - qiceini_incl)/qsati(i) - 1.)
+              IF ( qiceini_incl .GT. eps ) THEN
+                nb_crystals = 1.e3 * 5.94e-5 * ( RTT - temp(i) )**3.33 * naero5**(0.0264*(RTT-temp(i))+0.0033)
+                lambda_PSD  = ( (RPI*rho_ice*nb_crystals) / (rho_air*(qiceini_incl + gamma_snwretro * qsnowcld_incl)) ) ** (1./3.)
+                N0_PSD      = nb_crystals * lambda_PSD
+                moment1_PSD = N0_PSD/lambda_PSD**2
+              ELSE
+                moment1_PSD = 0.
+              ENDIF
+
+              !--Formulae for air thermal conductivity and water vapor diffusivity 
+              !--comes respectively from Beard and Pruppacher (1971) 
+              !--and  Hall and Pruppacher (1976)
+
+              air_thermal_conduct = ( 5.69 + 0.017 * ( temp(i) - RTT ) ) * 1.e-3 * 4.184
+              water_vapor_diff    = 2.11*1e-5 * ( temp(i) / RTT )**1.94 * ( 101325 / pplay(i) )
+              
+              bi = 1./((qsati(i)+qsatl(i))/2.) + RLSTT**2 / RCPD / RV / temp(i)**2
+              B0 = 4. * RPI * capa_crystal * 1. / (  RLSTT**2 / air_thermal_conduct / RV / temp(i)**2  &
+                                                  +  RV * temp(i) / psati / water_vapor_diff  )
+
+              invtau_phaserelax  = (bi * B0 * moment1_PSD )
+
+!             Old way of estimating moment1 : spherical crystals + monodisperse PSD              
+!             nb_crystals = rho_air * qiceini_incl / ( 4. / 3. * RPI * r_ice**3. * rho_ice )
+!             moment1_PSD = nb_crystals * r_ice 
+
+              !----------------- TURBULENT SOURCE/SINK TERMS -----------------
+              !--Tau_mixingenv is the time needed to homogeneize the parcel 
+              !--with its environment by turbulent diffusion over the parcel
+              !--length scale
+              !--if lmix_mpc <0, tau_mixigenv value is prescribed
+              !--else tau_mixigenv value is derived from tke_dissip and lmix_mpc
+              !--Tau_dissipturb is the time needed turbulence to decay due to
+              !--viscosity
+
+              ai = RG / RD / temp(i) * ( RD * RLSTT / RCPD / RV / temp(i) - 1. )
+              IF ( lmix_mpc .GT. 0 ) THEN 
+                 tau_mixingenv = ( lmix_mpc**2. / tke_dissip(i) )**(1./3.)
+              ELSE 
+                 tau_mixingenv = tau_mixenv
+              ENDIF 
+              
+              tau_dissipturb = gamma_taud * 2. * 2./3. * tke(i) / tke_dissip(i) / C0
+
+              !--------------------- PDF COMPUTATIONS ---------------------
+              !--Formulae for sigma2_pdf (variance), mean of PDF in Furtado2016
+              !--cloud liquid fraction and in-cloud liquid content are given 
+              !--by integrating resp. F(Si) and Si*F(Si)
+              !--Liquid is limited by the available water vapor trough a 
+              !--maximal liquid fraction
+
+              liqfra_max = MAX(0., (MIN (1.,( qtot_incl(i) - qiceini_incl - qsati(i) * (1 + sursat_iceext ) ) / ( qsatl(i) - qsati(i) ) ) ) )
+              sigma2_pdf = 1./2. * ( ai**2 ) *  2./3. * tke(i) * tau_dissipturb / ( invtau_phaserelax + 1./tau_mixingenv )
+              mean_pdf   = sursat_env * 1./tau_mixingenv / ( invtau_phaserelax + 1./tau_mixingenv )
+              cldfraliq(i) = 0.5 * (1. - erf( ( sursat_iceliq - mean_pdf) / (SQRT(2.* sigma2_pdf) ) ) )
+              IF (cldfraliq(i) .GT. liqfra_max) THEN
+                  cldfraliq(i) = liqfra_max
+              ENDIF 
+              
+              qliq_incl = qsati(i) * SQRT(sigma2_pdf) / SQRT(2.*RPI) * EXP( -1.*(sursat_iceliq - mean_pdf)**2. / (2.*sigma2_pdf) )  &
+                        - qsati(i) * cldfraliq(i) * (sursat_iceliq - mean_pdf )
+              
+              sigma2_icefracturb(i)= sigma2_pdf
+              mean_icefracturb(i)  = mean_pdf 
+     
+              !------------ SPECIFIC VAPOR CONTENT AND WATER CONSERVATION  ------------
+
+              IF ( (qliq_incl .LE. eps) .OR. (cldfraliq(i) .LE. eps) ) THEN
+                  qliq_incl    = 0.
+                  cldfraliq(i) = 0.
+              END IF
+               
+              !--Specific humidity is the max between qsati and the weighted mean between 
+              !--qv in MPC patches and qv in ice-only parts. We assume that MPC parts are
+              !--always at qsatl and ice-only parts slightly subsaturated (qsati*sursat_iceext+1)
+              !--The whole cloud can therefore be supersaturated but never subsaturated.
+
+              qvap_incl = MAX(qsati(i), ( 1. - cldfraliq(i) ) * (sursat_iceext + 1.) * qsati(i) + cldfraliq(i) * qsatl(i) )
+
+
+              IF ( qvap_incl  .GE. qtot_incl(i) ) THEN
+                 qvap_incl = qsati(i)
+                 qliq_incl = qtot_incl(i) - qvap_incl
+                 qice_incl = 0.
+
+              ELSEIF ( (qvap_incl + qliq_incl) .GE. qtot_incl(i) ) THEN
+                 qliq_incl = MAX(0.0,qtot_incl(i) - qvap_incl)
+                 qice_incl = 0.
+              ELSE
+                 qice_incl = qtot_incl(i) - qvap_incl - qliq_incl
+              END IF
+
+              qvap_cld(i)   = qvap_incl * cldfra1D
+              qliq(i)       = qliq_incl * cldfra1D
+              qice(i)       = qice_incl * cldfra1D
+              icefrac(i)    = qice(i) / ( qice(i) + qliq(i) )
+              dicefracdT(i) = 0.
+              !print*,'MPC turb'
+
+           END IF ! Enough TKE
+
+        END IF ! ! MPC temperature
+
+     END IF ! cldfra
+   
+   ENDDO ! klon
+END SUBROUTINE ICEFRAC_LSCP_TURB
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 
Index: LMDZ6/branches/cirrus/libf/phylmd/lmdz_thermcell_plume_6A.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/lmdz_thermcell_plume_6A.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/lmdz_thermcell_plume_6A.F90	(revision 5202)
@@ -63,5 +63,5 @@
       REAL,dimension(ngrid,nlay) :: zeps
 
-      REAL, dimension(ngrid) ::    wmaxa(ngrid)
+      REAL, dimension(ngrid) ::    wmaxa
 
       INTEGER ig,l,k,lt,it,lm
Index: LMDZ6/branches/cirrus/libf/phylmd/ocean_forced_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/ocean_forced_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/ocean_forced_mod.F90	(revision 5202)
@@ -22,5 +22,10 @@
        radsol, snow, agesno, & 
        qsurf, evap, fluxsens, fluxlat, flux_u1, flux_v1, &
-       tsurf_new, dflux_s, dflux_l, sens_prec_liq, rhoa)
+       tsurf_new, dflux_s, dflux_l, sens_prec_liq, rhoa &
+#ifdef ISO
+       ,xtprecip_rain, xtprecip_snow, xtspechum,Roce,rlat, &
+       xtsnow,xtevap,h1 &  
+#endif            
+       )
 !
 ! This subroutine treats the "open ocean", all grid points that are not entierly covered
@@ -36,4 +41,13 @@
     USE phys_output_var_mod, ONLY : sens_prec_liq_o, sens_prec_sol_o, lat_prec_liq_o, lat_prec_sol_o
     use config_ocean_skin_m, only: activate_ocean_skin
+#ifdef ISO
+    USE infotrac_phy, ONLY: ntiso,niso
+    USE isotopes_routines_mod, ONLY: calcul_iso_surf_oce_vectall, calcul_iso_surf_sic_vectall    
+#ifdef ISOVERIF
+    USE isotopes_mod, ONLY: iso_eau,ridicule
+    !USE isotopes_verif_mod, ONLY: errmax,errmaxrel,iso_verif_egalite_choix
+    USE isotopes_verif_mod
+#endif
+#endif
 
     INCLUDE "YOMCST.h"
@@ -57,4 +71,10 @@
     real, intent(in):: rhoa(:) ! (knon) density of moist air  (kg / m3)
 
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(IN)  :: xtprecip_rain, xtprecip_snow
+    REAL, DIMENSION(ntiso,klon), INTENT(IN)  :: xtspechum
+    REAL, DIMENSION(klon),       INTENT(IN)  :: rlat
+#endif
+
 ! In/Output arguments
 !****************************************************************************************
@@ -62,5 +82,9 @@
     REAL, DIMENSION(klon), INTENT(INOUT)     :: snow
     REAL, DIMENSION(klon), INTENT(INOUT)     :: agesno !? put to 0 in ocean
-  
+#ifdef ISO     
+    REAL, DIMENSION(niso,klon), INTENT(IN)   :: xtsnow
+    REAL, DIMENSION(niso,klon), INTENT(INOUT):: Roce
+#endif
+
 ! Output arguments
 !****************************************************************************************
@@ -72,4 +96,9 @@
     REAL, intent(out):: sens_prec_liq(:) ! (knon)
 
+#ifdef ISO     
+    REAL, DIMENSION(ntiso,klon), INTENT(OUT) :: xtevap ! isotopes in evaporation flux
+    REAL, DIMENSION(klon),       INTENT(OUT) :: h1 ! just a diagnostic, not useful for the simulation
+#endif
+
 ! Local variables
 !****************************************************************************************
@@ -80,6 +109,10 @@
     REAL, DIMENSION(klon)       :: u1_lay, v1_lay
     LOGICAL                     :: check=.FALSE.
-    REAL sens_prec_sol(knon) 
-    REAL, DIMENSION(klon) :: lat_prec_liq, lat_prec_sol    
+    REAL, DIMENSION(knon)       :: sens_prec_sol
+    REAL, DIMENSION(klon)       :: lat_prec_liq, lat_prec_sol    
+#ifdef ISO   
+    REAL, PARAMETER :: t_coup = 273.15      
+#endif
+
 
 !****************************************************************************************
@@ -87,5 +120,20 @@
 !****************************************************************************************
     IF (check) WRITE(*,*)' Entering ocean_forced_noice'
-    
+
+#ifdef ISO
+#ifdef ISOVERIF
+    DO i = 1, knon
+      IF (iso_eau > 0) THEN         
+        CALL iso_verif_egalite_choix(xtspechum(iso_eau,i), &
+     &                  spechum(i),'ocean_forced_mod 111', &
+     &                  errmax,errmaxrel)     
+        CALL iso_verif_egalite_choix(snow(i), &
+     &                  xtsnow(iso_eau,i),'ocean_forced_mod 117', &
+     &                  errmax,errmaxrel)
+      ENDIF !IF (iso_eau > 0) THEN
+    ENDDO !DO i=1,knon
+#endif      
+#endif 
+
 !****************************************************************************************
 ! 1)    
@@ -103,5 +151,9 @@
 
     else ! GCM
-      CALL limit_read_sst(knon,knindex,tsurf_lim)
+      CALL limit_read_sst(knon,knindex,tsurf_lim &
+#ifdef ISO
+     &     ,Roce,rlat &
+#endif     
+     &     )
     endif ! knon
 !sb--
@@ -161,4 +213,27 @@
          flux_u1, flux_v1)  
 
+#ifdef ISO     
+    CALL calcul_iso_surf_oce_vectall(klon, knon,t_coup, &
+     &    ps,tsurf_new,spechum,u1_lay, v1_lay, xtspechum, &
+     &    evap, Roce,xtevap,h1 &
+#ifdef ISOTRAC
+     &    ,knindex &
+#endif
+     &    )
+#endif         
+
+#ifdef ISO
+#ifdef ISOVERIF
+!          write(*,*) 'ocean_forced_mod 176: sortie de ocean_forced_noice'
+    IF (iso_eau > 0) THEN
+      DO i = 1, knon               
+        CALL iso_verif_egalite_choix(snow(i), &
+     &          xtsnow(iso_eau,i),'ocean_forced_mod 180', &
+     &          errmax,errmaxrel)
+      ENDDO ! DO j=1,knon
+    ENDIF !IF (iso_eau > 0) THEN
+#endif
+#endif   
+
   END SUBROUTINE ocean_forced_noice
 !
@@ -173,5 +248,10 @@
        radsol, snow, qsol, agesno, tsoil, &
        qsurf, alb1_new, alb2_new, evap, fluxsens, fluxlat, flux_u1, flux_v1, &
-       tsurf_new, dflux_s, dflux_l, rhoa)
+       tsurf_new, dflux_s, dflux_l, rhoa &
+#ifdef ISO
+       ,xtprecip_rain, xtprecip_snow, xtspechum,Roce, &
+       xtsnow, xtsol,xtevap,Rland_ice &  
+#endif            
+       )
 !
 ! This subroutine treats the ocean where there is ice. 
@@ -187,4 +267,13 @@
     USE indice_sol_mod
     USE phys_output_var_mod, ONLY : sens_prec_liq_o, sens_prec_sol_o, lat_prec_liq_o, lat_prec_sol_o
+#ifdef ISO
+    USE infotrac_phy, ONLY: niso, ntiso
+    USE isotopes_routines_mod, ONLY: calcul_iso_surf_oce_vectall, calcul_iso_surf_sic_vectall 
+#ifdef ISOVERIF
+    USE isotopes_mod, ONLY: iso_eau,ridicule
+    !USE isotopes_verif_mod, ONLY: errmax,errmaxrel,iso_verif_egalite_choix
+    USE isotopes_verif_mod
+#endif
+#endif
 
 !   INCLUDE "indicesol.h"
@@ -209,4 +298,10 @@
     REAL, DIMENSION(klon), INTENT(IN)    :: u1, v1, gustiness
     real, intent(in):: rhoa(:) ! (knon) density of moist air  (kg / m3)
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(IN) :: xtprecip_rain, xtprecip_snow
+    REAL, DIMENSION(ntiso,klon), INTENT(IN) :: xtspechum
+    REAL, DIMENSION(niso,klon),  INTENT(IN) :: Roce 
+    REAL, DIMENSION(niso,klon),  INTENT(IN) :: Rland_ice
+#endif
 
 ! In/Output arguments
@@ -216,4 +311,8 @@
     REAL, DIMENSION(klon), INTENT(INOUT)          :: agesno
     REAL, DIMENSION(klon, nsoilmx), INTENT(INOUT) :: tsoil
+#ifdef ISO     
+    REAL, DIMENSION(niso,klon), INTENT(INOUT)     :: xtsnow
+    REAL, DIMENSION(niso,klon), INTENT(IN)        :: xtsol
+#endif
 
 ! Output arguments
@@ -226,4 +325,7 @@
     REAL, DIMENSION(klon), INTENT(OUT)            :: tsurf_new
     REAL, DIMENSION(klon), INTENT(OUT)            :: dflux_s, dflux_l      
+#ifdef ISO     
+    REAL, DIMENSION(ntiso,klon), INTENT(OUT)      :: xtevap
+#endif      
 
 ! Local variables
@@ -238,7 +340,21 @@
     REAL, DIMENSION(klon)       :: u0, v0
     REAL, DIMENSION(klon)       :: u1_lay, v1_lay
-    REAL sens_prec_liq(knon), sens_prec_sol (knon)   
+    REAL, DIMENSION(knon)       :: sens_prec_liq, sens_prec_sol
     REAL, DIMENSION(klon)       :: lat_prec_liq, lat_prec_sol    
 
+#ifdef ISO
+    REAL, PARAMETER :: t_coup = 273.15
+    REAL, DIMENSION(klon) :: fq_fonte_diag
+    REAL, DIMENSION(klon) :: fqfonte_diag
+    REAL, DIMENSION(klon) :: snow_evap_diag 
+    REAL, DIMENSION(klon) :: fqcalving_diag 
+    REAL, DIMENSION(klon) :: run_off_lic_diag
+    REAL :: coeff_rel_diag
+    REAL :: max_eau_sol_diag  
+    REAL, DIMENSION(klon) :: runoff_diag    
+    INTEGER IXT
+    REAL, DIMENSION(niso,klon) :: xtsnow_prec, xtsol_prec
+    REAL, DIMENSION(klon) :: snow_prec, qsol_prec  
+#endif
 
 !****************************************************************************************
@@ -307,7 +423,68 @@
 !
 !****************************************************************************************
+#ifdef ISO
+   ! verif
+#ifdef ISOVERIF
+    DO i = 1, knon
+      IF (iso_eau > 0) THEN
+        IF (snow(i) > ridicule) THEN
+          CALL iso_verif_egalite_choix(xtsnow(iso_eau,i),snow(i), &
+   &              'interfsurf 964',errmax,errmaxrel)
+        ENDIF !IF ((snow(i) > ridicule)) THEN
+      ENDIF !IF (iso_eau > 0) THEN      
+    ENDDO !DO i=1,knon  
+#endif
+   ! end verif
+
+    DO i = 1, knon
+      snow_prec(i) = snow(i)
+      DO ixt = 1, niso
+      xtsnow_prec(ixt,i) = xtsnow(ixt,i)
+      ENDDO !DO ixt=1,niso
+      ! initialisation:
+      fq_fonte_diag(i) = 0.0
+      fqfonte_diag(i)  = 0.0
+      snow_evap_diag(i)= 0.0
+    ENDDO !DO i=1,knon
+#endif
+
+
     CALL fonte_neige( knon, is_sic, knindex, dtime, &
          tsurf_tmp, precip_rain, precip_snow, &
-         snow, qsol, tsurf_new, evap)
+         snow, qsol, tsurf_new, evap &
+#ifdef ISO    
+     &  ,fq_fonte_diag,fqfonte_diag,snow_evap_diag,fqcalving_diag   &
+     &  ,max_eau_sol_diag,runoff_diag,run_off_lic_diag,coeff_rel_diag   &
+#endif
+     &   )
+
+
+#ifdef ISO
+! isotopes: tout est externalisé
+!#ifdef ISOVERIF
+!        write(*,*) 'ocean_forced_mod 377: call calcul_iso_surf_sic_vectall'
+!        write(*,*) 'klon,knon=',klon,knon
+!#endif
+    CALL calcul_iso_surf_sic_vectall(klon,knon, &
+     &          evap,snow_evap_diag,Tsurf_new,Roce,snow, &
+     &          fq_fonte_diag,fqfonte_diag,dtime,t_coup, &
+     &          precip_snow,xtprecip_snow,xtprecip_rain, snow_prec,xtsnow_prec, &
+     &          xtspechum,spechum,ps, &
+     &          xtevap,xtsnow,fqcalving_diag, &
+     &          knindex,is_sic,run_off_lic_diag,coeff_rel_diag,Rland_ice &
+     &   )
+#ifdef ISOVERIF
+        !write(*,*) 'ocean_forced_mod 391: sortie calcul_iso_surf_sic_vectall'
+    IF (iso_eau > 0) THEN
+      DO i = 1, knon  
+        CALL iso_verif_egalite_choix(snow(i), &
+     &           xtsnow(iso_eau,i),'ocean_forced_mod 396', &
+     &           errmax,errmaxrel)
+      ENDDO ! DO j=1,knon
+    ENDIF !IF (iso_eau > 0) then
+#endif 
+!#ifdef ISOVERIF
+#endif   
+!#ifdef ISO
     
 ! Calculation of albedo at snow (alb_neig) and update the age of snow (agesno)
Index: LMDZ6/branches/cirrus/libf/phylmd/pbl_surface_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/pbl_surface_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/pbl_surface_mod.F90	(revision 5202)
@@ -33,4 +33,7 @@
                                   wx_pbl_check, wx_pbl_dts_check, wx_evappot
   use config_ocean_skin_m, only: activate_ocean_skin
+#ifdef ISO
+  USE infotrac_phy, ONLY: niso,ntraciso=>ntiso    
+#endif
 
   IMPLICIT NONE
@@ -49,8 +52,19 @@
   !$OMP THREADPRIVATE(ydTs0, ydqs0)
 
+#ifdef ISO
+  REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE   :: xtsnow   ! snow at surface
+  !$OMP THREADPRIVATE(xtsnow)
+  REAL, ALLOCATABLE, DIMENSION(:,:), PRIVATE, SAVE   :: Rland_ice   ! snow at surface
+  !$OMP THREADPRIVATE(Rland_ice)  
+  REAL, ALLOCATABLE, DIMENSION(:,:), PRIVATE, SAVE   :: Roce   ! snow at surface
+  !$OMP THREADPRIVATE(Roce)  
+#endif
+
   INTEGER, SAVE :: iflag_pbl_surface_t2m_bug
   !$OMP THREADPRIVATE(iflag_pbl_surface_t2m_bug)
   INTEGER, SAVE :: iflag_new_t2mq2m
   !$OMP THREADPRIVATE(iflag_new_t2mq2m)
+  LOGICAL, SAVE :: ok_bug_zg_wk_pbl
+  !$OMP THREADPRIVATE(ok_bug_zg_wk_pbl)
 
 !FC
@@ -176,4 +190,69 @@
 
   END SUBROUTINE pbl_surface_init
+
+#ifdef ISO
+  SUBROUTINE pbl_surface_init_iso(xtsnow_rst,Rland_ice_rst)
+
+! This routine should be called after the restart file has been read.
+! This routine initialize the restart variables and does some validation tests
+! for the index of the different surfaces and tests the choice of type of ocean.
+
+    USE indice_sol_mod
+    USE print_control_mod, ONLY: lunout
+#ifdef ISOVERIF
+    USE isotopes_mod, ONLY: iso_eau,ridicule
+    USE isotopes_verif_mod
+#endif
+    IMPLICIT NONE
+
+    INCLUDE "dimsoil.h"
+ 
+! Input variables
+!****************************************************************************************
+    REAL, DIMENSION(niso,klon, nbsrf), INTENT(IN)          :: xtsnow_rst
+    REAL, DIMENSION(niso,klon), INTENT(IN)          :: Rland_ice_rst
+  
+! Local variables
+!****************************************************************************************
+    INTEGER                       :: ierr
+    CHARACTER(len=80)             :: abort_message
+    CHARACTER(len = 20)           :: modname = 'pbl_surface_init'
+    integer i,ixt
+    
+!****************************************************************************************
+! Allocate and initialize module variables with fields read from restart file.
+!
+!****************************************************************************************    
+
+    ALLOCATE(xtsnow(niso,klon,nbsrf), stat=ierr)
+    IF (ierr /= 0) CALL abort_gcm('pbl_surface_init', 'pb in allocation',1)
+
+    ALLOCATE(Rland_ice(niso,klon), stat=ierr)
+    IF (ierr /= 0) CALL abort_gcm('pbl_surface_init', 'pb in allocation',1)
+
+    ALLOCATE(Roce(niso,klon), stat=ierr)
+    IF (ierr /= 0) CALL abort_gcm('pbl_surface_init', 'pb in allocation',1)
+
+    xtsnow(:,:,:)  = xtsnow_rst(:,:,:)
+    Rland_ice(:,:) = Rland_ice_rst(:,:)
+    Roce(:,:)      = 0.0
+
+#ifdef ISOVERIF 
+      IF (iso_eau >= 0) THEN
+         CALL iso_verif_egalite_vect2D( &
+     &           xtsnow,snow, &
+     &           'pbl_surface_mod 170',niso,klon,nbsrf)
+         DO i=1,klon  
+            IF (iso_eau >= 0) THEN  
+              CALL iso_verif_egalite(Rland_ice(iso_eau,i),1.0, &
+     &         'pbl_surf_mod 177')
+            ENDIF
+         ENDDO
+      ENDIF
+#endif
+
+  END SUBROUTINE pbl_surface_init_iso
+#endif
+
 !  
 !****************************************************************************************
@@ -239,5 +318,12 @@
 !FC
 !!!
-                        )
+#ifdef ISO
+     &   ,xtrain_f, xtsnow_f,xt, &
+     &   wake_dlxt,zxxtevap,xtevap, &
+     &   d_xt,d_xt_w,d_xt_x, &
+     &   xtsol,dflux_xt,zxxtsnow,zxfluxxt,flux_xt, &
+     &   h1_diag,runoff_diag,xtrunoff_diag &
+#endif      
+     &   )
 !****************************************************************************************
 ! Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
@@ -314,4 +400,13 @@
     USE mod_grid_phy_lmdz,  ONLY : nbp_lon, nbp_lat, grid1dto2d_glo
     USE print_control_mod,  ONLY : prt_level,lunout
+#ifdef ISO
+  USE isotopes_mod, ONLY: Rdefault,iso_eau
+#ifdef ISOVERIF
+        USE isotopes_verif_mod
+#endif
+#ifdef ISOTRAC
+        USE isotrac_mod, only: index_iso
+#endif
+#endif
     USE ioipsl_getin_p_mod, ONLY : getin_p
     use phys_state_var_mod, only: ds_ns, dt_ns, delta_sst, delta_sal, dter, &
@@ -366,5 +461,11 @@
     REAL, DIMENSION(klon),        INTENT(IN)        :: gustiness ! gustiness
 
-    REAL, DIMENSION(klon),        INTENT(IN)        :: cldt    ! total cloud fraction
+    REAL, DIMENSION(klon),        INTENT(IN)        :: cldt    ! total cloud 
+
+#ifdef ISO
+    REAL, DIMENSION(ntraciso,klon,klev),   INTENT(IN)        :: xt       ! water vapour (kg/kg)
+    REAL, DIMENSION(ntraciso,klon),        INTENT(IN)        :: xtrain_f  ! rain fall
+    REAL, DIMENSION(ntraciso,klon),        INTENT(IN)        :: xtsnow_f  ! snow fall
+#endif
 
 !!! nrlmd+jyg le 02/05/2011 et le 20/02/2012
@@ -379,5 +480,7 @@
     REAL, DIMENSION(klon),        INTENT(IN)        :: wake_dens
 !!!
-
+#ifdef ISO
+    REAL, DIMENSION(ntraciso,klon,klev),   INTENT(IN)        :: wake_dlxt   
+#endif
 ! Input/Output variables
 !****************************************************************************************
@@ -448,4 +551,14 @@
     REAL, INTENT(OUT):: zcoefm(:, :, :) ! (klon, klev, nbsrf + 1)
     ! coef for turbulent diffusion of U and V (?), mean for each grid point
+#ifdef ISO
+    REAL, DIMENSION(ntraciso,klon),        INTENT(OUT)       :: zxxtevap     ! water vapour flux at surface, positiv upwards
+    REAL, DIMENSION(ntraciso,klon, klev),  INTENT(OUT)       :: d_xt        ! change in water vapour
+    REAL, DIMENSION(klon),                 INTENT(OUT)       :: runoff_diag
+    REAL, DIMENSION(niso,klon),            INTENT(OUT)       :: xtrunoff_diag
+    REAL, DIMENSION(ntraciso,klon,klev),   INTENT(OUT)       :: d_xt_w
+    REAL, DIMENSION(ntraciso,klon,klev),   INTENT(OUT)       :: d_xt_x
+#endif
+
+
 
 !!! nrlmd+jyg le 02/05/2011 et le 20/02/2012
@@ -511,5 +624,10 @@
     REAL, DIMENSION(klon, klev, nbsrf), INTENT(OUT) :: flux_v     ! v wind tension (kg m/s)/(m**2 s) or Pascal
 !FC
-    REAL, DIMENSION(klon, klev, nbsrf), INTENT(INOUT)  :: treedrg      ! tree drag (m)               
+    REAL, DIMENSION(klon, klev, nbsrf), INTENT(INOUT) :: treedrg  ! tree drag (m)               
+#ifdef ISO        
+    REAL, DIMENSION(niso,klon),   INTENT(OUT)       :: xtsol      ! water height in the soil (mm)
+    REAL, DIMENSION(ntraciso,klon, nbsrf)           :: xtevap     ! evaporation at surface
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: h1_diag    ! just diagnostic, not useful
+#endif
 
 
@@ -525,4 +643,10 @@
     REAL, DIMENSION(klon, klev, nbsrf), INTENT(OUT) :: flux_qbs   ! blowind snow vertical flux (kg/m**2
 
+#ifdef ISO   
+    REAL, DIMENSION(ntraciso,klon),              INTENT(OUT) :: dflux_xt    ! change of water vapour flux
+    REAL, DIMENSION(niso,klon),                  INTENT(OUT) :: zxxtsnow    ! snow at surface, mean for each grid point
+    REAL, DIMENSION(ntraciso,klon, klev),        INTENT(OUT) :: zxfluxxt    ! water vapour flux, mean for each grid point 
+    REAL, DIMENSION(ntraciso,klon, klev, nbsrf), INTENT(OUT) :: flux_xt     ! water vapour flux(latent flux) (kg/m**2/s)  
+#endif
 
 ! Martin
@@ -573,4 +697,12 @@
     REAL, DIMENSION(klon)              :: ysnow, yqsurf, yagesno, yqsol
     REAL, DIMENSION(klon)              :: yrain_f, ysnow_f, ybs_f
+#ifdef ISO
+    REAL, DIMENSION(ntraciso,klon)     :: yxt1
+    REAL, DIMENSION(niso,klon)         :: yxtsnow, yxtsol   
+    REAL, DIMENSION(ntraciso,klon)     :: yxtrain_f, yxtsnow_f 
+    REAL, DIMENSION(klon)              :: yrunoff_diag
+    REAL, DIMENSION(niso,klon)         :: yxtrunoff_diag
+    REAL, DIMENSION(niso,klon)         :: yRland_ice    
+#endif
     REAL, DIMENSION(klon)              :: ysolsw, ysollw
     REAL, DIMENSION(klon)              :: yfder
@@ -581,4 +713,8 @@
     REAL, DIMENSION(klon)              :: y_flux_t1, y_flux_q1
     REAL, DIMENSION(klon)              :: y_dflux_t, y_dflux_q
+#ifdef ISO
+    REAL, DIMENSION(ntraciso,klon)     ::  y_flux_xt1
+    REAL, DIMENSION(ntraciso,klon)     ::  y_dflux_xt
+#endif
     REAL, DIMENSION(klon)              :: y_flux_u1, y_flux_v1
     REAL, DIMENSION(klon)              :: y_flux_bs, y_flux0
@@ -608,4 +744,7 @@
     REAL, DIMENSION(klon)              :: AcoefH_0, AcoefQ_0, BcoefH_0, BcoefQ_0
     REAL, DIMENSION(klon)              :: AcoefH, AcoefQ, BcoefH, BcoefQ
+#ifdef ISO
+    REAL, DIMENSION(ntraciso,klon)     :: AcoefXT, BcoefXT
+#endif
     REAL, DIMENSION(klon)              :: AcoefU, AcoefV, BcoefU, BcoefV
     REAL, DIMENSION(klon)              :: AcoefQBS, BcoefQBS
@@ -626,4 +765,10 @@
     REAL, DIMENSION(klon,klev)         :: yu, yv
     REAL, DIMENSION(klon,klev)         :: yt, yq, yqbs
+#ifdef ISO
+    REAL, DIMENSION(ntraciso,klon)      :: yxtevap
+    REAL, DIMENSION(ntraciso,klon,klev) :: y_d_xt
+    REAL, DIMENSION(ntraciso,klon,klev) :: y_flux_xt
+    REAL, DIMENSION(ntraciso,klon,klev) :: yxt   
+#endif
     REAL, DIMENSION(klon,klev)         :: ypplay, ydelp
     REAL, DIMENSION(klon,klev)         :: delp
@@ -697,4 +842,17 @@
     REAL, DIMENSION(klon,klev)         :: Kcoef_hq_w, Kcoef_m_w, gama_h_w, gama_q_w
     REAL, DIMENSION(klon)              :: alf_1, alf_2, alf_1_x, alf_2_x, alf_1_w, alf_2_w
+#ifdef ISO
+    REAL, DIMENSION(ntraciso,klon,klev)         :: yxt_x, yxt_w
+    REAL, DIMENSION(ntraciso,klon)              :: y_flux_xt1_x , y_flux_xt1_w   
+    REAL, DIMENSION(ntraciso,klon,klev)         :: y_flux_xt_x,y_d_xt_x,zxfluxxt_x
+    REAL, DIMENSION(ntraciso,klon,klev)         :: y_flux_xt_w,y_d_xt_w,zxfluxxt_w
+    REAL, DIMENSION(ntraciso,klon,klev,nbsrf)   :: flux_xt_x, flux_xt_w
+    REAL, DIMENSION(ntraciso,klon)              :: AcoefXT_x, BcoefXT_x
+    REAL, DIMENSION(ntraciso,klon)              :: AcoefXT_w, BcoefXT_w
+    REAL, DIMENSION(ntraciso,klon,klev)         :: CcoefXT, DcoefXT
+    REAL, DIMENSION(ntraciso,klon,klev)         :: CcoefXT_x, DcoefXT_x
+    REAL, DIMENSION(ntraciso,klon,klev)         :: CcoefXT_w, DcoefXT_w
+    REAL, DIMENSION(ntraciso,klon,klev)         :: gama_xt,gama_xt_x,gama_xt_w
+#endif
 !!!
 !!!jyg le 08/02/2012
@@ -889,5 +1047,5 @@
     REAL, DIMENSION(klon)              :: yrmu0
     ! Martin
-    REAL, DIMENSIOn(klon)              :: yri0
+    REAL, DIMENSION(klon)              :: yri0
 
     REAL, DIMENSION(klon):: ydelta_sst, ydelta_sal, yds_ns, ydt_ns, ydter, &
@@ -896,4 +1054,12 @@
     ! dt_ds, tkt, tks, taur, sss on ocean points
     REAL :: missing_val
+#ifdef ISO
+    REAL, DIMENSION(klon)       :: h1
+    INTEGER                     :: ixt
+!#ifdef ISOVERIF
+!    integer iso_verif_positif_nostop
+!#endif    
+#endif
+
 !****************************************************************************************
 ! End of declarations
@@ -924,4 +1090,42 @@
       iflag_split = iflag_split_ref
 
+#ifdef ISO      
+#ifdef ISOVERIF
+      DO i=1,klon
+        DO ixt=1,niso
+          CALL iso_verif_noNaN(xtsol(ixt,i),'pbl_surface 608')
+        ENDDO
+      ENDDO
+#endif
+#ifdef ISOVERIF
+      DO i=1,klon  
+        IF (iso_eau >= 0) THEN  
+          CALL iso_verif_egalite_choix(Rland_ice(iso_eau,i),1.0, &
+     &         'pbl_surf_mod 585',errmax,errmaxrel)
+          CALL iso_verif_egalite_choix(xtsnow_f(iso_eau,i),snow_f(i), &
+     &         'pbl_surf_mod 594',errmax,errmaxrel)
+          IF (iso_verif_egalite_choix_nostop(xtsol(iso_eau,i),qsol(i), &
+     &         'pbl_surf_mod 596',errmax,errmaxrel) == 1) THEN
+                WRITE(*,*) 'i=',i
+                STOP
+          ENDIF
+          DO nsrf=1,nbsrf
+            CALL iso_verif_egalite_choix(xtsnow(iso_eau,i,nsrf),snow(i,nsrf), &
+     &         'pbl_surf_mod 598',errmax,errmaxrel)
+          ENDDO
+        ENDIF !IF (iso_eau >= 0) THEN   
+      ENDDO !DO i=1,knon  
+      DO k=1,klev
+        DO i=1,klon  
+          IF (iso_eau >= 0) THEN  
+            CALL iso_verif_egalite_choix(xt(iso_eau,i,k),q(i,k), &
+     &           'pbl_surf_mod 595',errmax,errmaxrel)
+          ENDIF !IF (iso_eau >= 0) THEN  
+        ENDDO !DO i=1,knon  
+      ENDDO !DO k=1,klev
+#endif
+#endif
+
+
 !****************************************************************************************
 ! 1) Initialisation and validation tests 
@@ -935,4 +1139,8 @@
        CALL getin_p('iflag_new_t2mq2m',iflag_new_t2mq2m)
        WRITE(lunout,*) 'pbl_iflag_new_t2mq2m=',iflag_new_t2mq2m
+
+       ok_bug_zg_wk_pbl=.TRUE.
+       CALL getin_p('ok_bug_zg_wk_pbl',ok_bug_zg_wk_pbl)
+       WRITE(lunout,*) 'ok_bug_zg_wk_pbl=',ok_bug_zg_wk_pbl
 
        print*,'PBL SURFACE AVEC GUSTINESS'
@@ -984,4 +1192,14 @@
       PRINT*,'WARNING : On impose qsol=',qsol0
       qsol(:)=qsol0
+#ifdef ISO
+      DO ixt=1,niso
+        xtsol(ixt,:)=qsol0*Rdefault(ixt)
+      ENDDO
+#ifdef ISOTRAC      
+      DO ixt=1+niso,ntraciso
+        xtsol(ixt,:)=qsol0*Rdefault(index_iso(ixt))
+      ENDDO
+#endif       
+#endif
     ENDIF
 !****************************************************************************************
@@ -1034,4 +1252,13 @@
  qsnow(:)=0. ; snowhgt(:)=0. ; to_ice(:)=0. ; sissnow(:)=0.
  runoff(:)=0.
+#ifdef ISO
+zxxtevap(:,:)=0.
+ d_xt(:,:,:)=0. 
+ d_xt_x(:,:,:)=0.
+ d_xt_w(:,:,:)=0.
+ flux_xt(:,:,:,:)=0. 
+! xtsnow(:,:,:)=0.! attention, xtsnow est l'équivalent de snow et non de qsnow
+ xtevap(:,:,:)=0.
+#endif
     IF (iflag_pbl<20.or.iflag_pbl>=30) THEN
        zcoefh(:,:,:) = 0.0
@@ -1123,4 +1350,17 @@
 !FC
 
+#ifdef ISO
+   yxtrain_f = 0.0 ; yxtsnow_f = 0.0
+   yxtsnow  = 0.0
+   yxt = 0.0
+   yxtsol = 0.0
+   flux_xt = 0.0
+   yRland_ice = 0.0
+!   d_xt = 0.0      
+   y_dflux_xt = 0.0  
+   dflux_xt=0.0 
+   y_d_xt_x=0.      ; y_d_xt_w=0.       
+#endif 
+
 ! >> PC
 !the yfields_out variable is defined in (klon,nbcf_out) even if it is used on
@@ -1149,4 +1389,7 @@
     fluxlat_x(:,:)=0. ;           fluxlat_w(:,:)=0. 
 !>jyg
+#ifdef ISO
+    flux_xt_x(:,:,:,:)=0. ;          flux_xt_w(:,:,:,:)=0.
+#endif
 !
 !jyg<
@@ -1448,4 +1691,34 @@
           yfluxbs(j)=0.0
           y_flux_bs(j) = 0.0
+!!!
+#ifdef ISO
+          DO ixt=1,ntraciso
+            yxtrain_f(ixt,j) = xtrain_f(ixt,i)
+            yxtsnow_f(ixt,j) = xtsnow_f(ixt,i)  
+          ENDDO
+          DO ixt=1,niso
+            yxtsnow(ixt,j)   = xtsnow(ixt,i,nsrf)
+          ENDDO    
+          !IF (nsrf == is_lic) THEN
+          DO ixt=1,niso
+            yRland_ice(ixt,j)= Rland_ice(ixt,i)  
+          ENDDO    
+          !endif !IF (nsrf == is_lic) THEN
+#ifdef ISOVERIF
+          IF (iso_eau >= 0) THEN
+              call iso_verif_egalite_choix(ysnow_f(j), &
+     &          yxtsnow_f(iso_eau,j),'pbl_surf_mod 862', &
+     &          errmax,errmaxrel)
+              call iso_verif_egalite_choix(ysnow(j), &
+     &          yxtsnow(iso_eau,j),'pbl_surf_mod 872', &
+     &          errmax,errmaxrel)
+          ENDIF
+#endif
+#ifdef ISOVERIF
+         DO ixt=1,ntraciso
+           call iso_verif_noNaN(yxtsnow_f(ixt,j),'pbl_surf_mod 921')
+         ENDDO
+#endif
+#endif
        ENDDO
 ! >> PC
@@ -1487,4 +1760,9 @@
              yq(j,k) = q(i,k)
              yqbs(j,k)=qbs(i,k)
+#ifdef ISO
+             DO ixt=1,ntraciso   
+               yxt(ixt,j,k) = xt(ixt,i,k)
+             ENDDO !DO ixt=1,ntraciso
+#endif
           ENDDO
         ENDDO
@@ -1504,4 +1782,10 @@
              yq_w(j,k) = q(i,k)+(1.-wake_s(i))*wake_dlq(i,k)
 !!!
+#ifdef ISO
+             DO ixt=1,ntraciso
+               yxt_x(ixt,j,k) = xt(ixt,i,k)-wake_s(i)*wake_dlxt(ixt,i,k)
+               yxt_w(ixt,j,k) = xt(ixt,i,k)+(1.-wake_s(i))*wake_dlxt(ixt,i,k)
+             ENDDO
+#endif
           ENDDO
         ENDDO
@@ -1559,4 +1843,9 @@
              i = ni(j)
              yqsol(j) = qsol(i)
+#ifdef ISO
+             DO ixt=1,niso
+               yxtsol(ixt,j) = xtsol(ixt,i)
+             ENDDO
+#endif
           ENDDO
        ENDIF
@@ -1664,6 +1953,9 @@
             ycdragm_w, ycdragh_w, zri1_w, pref_w, rain_f, zxtsol, ypplay(:,1) )
 !
-!!!bug !!        zgeo1(:) = wake_s(:)*zgeo1_w(:) + (1.-wake_s(:))*zgeo1_x(:)
-        zgeo1(1:knon) = wake_s(1:knon)*zgeo1_w(1:knon) + (1.-wake_s(1:knon))*zgeo1_x(1:knon)
+        IF(ok_bug_zg_wk_pbl) THEN
+         zgeo1(1:knon) = wake_s(1:knon)*zgeo1_w(1:knon) + (1.-wake_s(1:knon))*zgeo1_x(1:knon)
+        ELSE
+         zgeo1(1:knon) = ywake_s(1:knon)*zgeo1_w(1:knon) + (1.-ywake_s(1:knon))*zgeo1_x(1:knon)
+        ENDIF
 
 ! --- special Dice. JYG+MPL 25112013 puis BOMEX
@@ -1704,5 +1996,5 @@
 
         IF (iflag_pbl>=50) THEN
-        CALL call_atke(dtime,knon,klev,ycdragm(1:knon), ycdragh(1:knon),yus0(1:knon),yvs0(1:knon),yts(1:knon), &
+        CALL call_atke(dtime,knon,klev,nsrf,ni,ycdragm(1:knon), ycdragh(1:knon),yus0(1:knon),yvs0(1:knon),yts(1:knon), &
                   yu(1:knon,:),yv(1:knon,:),yt(1:knon,:),yq(1:knon,:),ypplay(1:knon,:),ypaprs(1:knon,:),       &
                   ytke(1:knon,:),yeps(1:knon,:), ycoefm(1:knon,:), ycoefh(1:knon,:))
@@ -1749,5 +2041,5 @@
         IF (iflag_pbl>=50) THEN
      
-        CALL call_atke(dtime,knon,klev,ycdragm_x(1:knon),ycdragh_x(1:knon),yus0(1:knon),yvs0(1:knon),yts_x(1:knon),    &
+        CALL call_atke(dtime,knon,klev,nsrf,ni,ycdragm_x(1:knon),ycdragh_x(1:knon),yus0(1:knon),yvs0(1:knon),yts_x(1:knon),    &
                        yu_x(1:knon,:),yv_x(1:knon,:),yt_x(1:knon,:),yq_x(1:knon,:),ypplay(1:knon,:),ypaprs(1:knon,:),  &
                        ytke_x(1:knon,:),yeps_x(1:knon,:),ycoefm_x(1:knon,:), ycoefh_x(1:knon,:))
@@ -1789,5 +2081,5 @@
         IF (iflag_pbl>=50) THEN
         
-        CALL call_atke(dtime,knon,klev,ycdragm_w(1:knon),ycdragh_w(1:knon),yus0(1:knon),yvs0(1:knon),yts_w(1:knon), &
+        CALL call_atke(dtime,knon,klev,nsrf,ni,ycdragm_w(1:knon),ycdragh_w(1:knon),yus0(1:knon),yvs0(1:knon),yts_w(1:knon), &
                 yu_w(1:knon,:),yv_w(1:knon,:),yt_w(1:knon,:),yq_w(1:knon,:),ypplay(1:knon,:),ypaprs(1:knon,:),      &
                 ytke_w(1:knon,:),yeps_w(1:knon,:),ycoefm_w(1:knon,:),ycoefh_w(1:knon,:))
@@ -1850,5 +2142,9 @@
             Kcoef_hq, gama_q, gama_h, &
 !!!
-            AcoefH, AcoefQ, BcoefH, BcoefQ)
+            AcoefH, AcoefQ, BcoefH, BcoefQ &
+#ifdef ISO
+         &   ,yxt, CcoefXT, DcoefXT, gama_xt, AcoefXT, BcoefXT & 
+#endif               
+         &   )
        ELSE  !(iflag_split .eq.0)
         CALL climb_hq_down(knon, ycoefh_x, ypaprs, ypplay, &
@@ -1858,5 +2154,9 @@
             Kcoef_hq_x, gama_q_x, gama_h_x, &
 !!!
-            AcoefH_x, AcoefQ_x, BcoefH_x, BcoefQ_x)
+            AcoefH_x, AcoefQ_x, BcoefH_x, BcoefQ_x &
+#ifdef ISO
+         &   ,yxt_x, CcoefXT_x, DcoefXT_x, gama_xt_x, AcoefXT_x, BcoefXT_x & 
+#endif               
+         &   )
 !!!
        IF (prt_level >=10) THEN
@@ -1873,5 +2173,9 @@
             Kcoef_hq_w, gama_q_w, gama_h_w, &
 !!!
-            AcoefH_w, AcoefQ_w, BcoefH_w, BcoefQ_w)
+            AcoefH_w, AcoefQ_w, BcoefH_w, BcoefQ_w &
+#ifdef ISO
+         &   ,yxt_w, CcoefXT_w, DcoefXT_w, gama_xt_w, AcoefXT_w, BcoefXT_w & 
+#endif               
+         &   )
 !!!
        IF (prt_level >=10) THEN
@@ -1955,5 +2259,13 @@
          yt1(:) = yt(:,1)
          yq1(:) = yq(:,1)
+#ifdef ISO
+         yxt1(:,:) = yxt(:,:,1)
+#endif
+
        ELSE IF (iflag_split .ge. 1) THEN
+#ifdef ISO
+        call abort_gcm('pbl_surface_mod 2149','isos pas encore dans iflag_split=1',1)
+#endif
+
 !
 ! Cdragq computation
@@ -2117,5 +2429,11 @@
                yqsurf, ytsurf_new, y_dflux_t, y_dflux_q, &
                y_flux_u1, y_flux_v1, &
-               yveget,ylai,yheight )
+               yveget,ylai,yheight   &
+#ifdef ISO
+         &      ,yxtrain_f, yxtsnow_f,yxt1, &
+         &      yxtsnow,yxtsol,yxtevap,h1, &
+         &      yrunoff_diag,yxtrunoff_diag,yRland_ice &
+#endif               
+         &      )
  
 !FC quid qd yveget ylai yheight ne sont pas definit
@@ -2147,5 +2465,27 @@
           ENDDO
       ENDIF
-     
+
+#ifdef ISOVERIF
+        DO j=1,knon
+          DO ixt=1,ntraciso
+            CALL iso_verif_noNaN(yxtevap(ixt,j), &
+         &      'pbl_surface 1056a: apres surf_land')
+          ENDDO
+          DO ixt=1,niso
+            CALL iso_verif_noNaN(yxtsol(ixt,j), &
+         &      'pbl_surface 1056b: apres surf_land')
+          ENDDO
+        ENDDO
+#endif
+#ifdef ISOVERIF
+!        write(*,*) 'pbl_surface_mod 1038: sortie surf_land'
+        DO j=1,knon
+          IF (iso_eau >= 0) THEN     
+                 CALL iso_verif_egalite(yxtsnow(iso_eau,j), &
+     &                                  ysnow(j),'pbl_surf_mod 1043')
+          ENDIF !if (iso_eau.gt.0) then
+        ENDDO !DO i=1,klon
+#endif
+    
        CASE(is_lic)
           ! Martin
@@ -2168,5 +2508,10 @@
                   ysnowhgt, yqsnow, ytoice, ysissnow, &
                   yalb3_new, yrunoff, &
-                  y_flux_u1, y_flux_v1)
+                  y_flux_u1, y_flux_v1 &
+#ifdef ISO
+                  &    ,yxtrain_f, yxtsnow_f,yxt1,yRland_ice &
+                  &    ,yxtsnow,yxtsol,yxtevap &
+#endif              
+                  &    )
              
              !jyg<
@@ -2190,5 +2535,27 @@
                 ENDDO
              ENDIF
-             
+
+#ifdef ISOVERIF
+             DO j=1,knon
+               DO ixt=1,ntraciso
+                 CALL iso_verif_noNaN(yxtevap(ixt,j), &
+                        &             'pbl_surface 1095a: apres surf_landice')
+               ENDDO
+                do ixt=1,niso
+                   call iso_verif_noNaN(yxtsol(ixt,j), &
+                        &      'pbl_surface 1095b: apres surf_landice')
+                enddo
+             enddo
+#endif
+#ifdef ISOVERIF
+             !write(*,*) 'pbl_surface_mod 1060: sortie surf_landice'
+             do j=1,knon
+               IF (iso_eau >= 0) THEN     
+                 CALL iso_verif_egalite(yxtsnow(iso_eau,j), &
+                        &               ysnow(j),'pbl_surf_mod 1064')
+               ENDIF !if (iso_eau >= 0) THEN
+             ENDDO !DO i=1,klon
+#endif
+            
           END IF
           
@@ -2207,5 +2574,10 @@
                y_flux_u1, y_flux_v1, ydelta_sst(:knon), ydelta_sal(:knon), &
                yds_ns(:knon), ydt_ns(:knon), ydter(:knon), ydser(:knon), &
-               ydt_ds(:knon), ytkt(:knon), ytks(:knon), ytaur(:knon), ysss)
+               ydt_ds(:knon), ytkt(:knon), ytks(:knon), ytaur(:knon), ysss &
+#ifdef ISO
+         &      ,yxtrain_f, yxtsnow_f,yxt1,Roce, &
+         &      yxtsnow,yxtevap,h1 &
+#endif               
+         &      )
       IF (prt_level >=10) THEN
           print *,'arg de surf_ocean: ycdragh ',ycdragh(1:knon)
@@ -2248,5 +2620,10 @@
 !albedo SB <<<
                ytsurf_new, y_dflux_t, y_dflux_q, &
-               y_flux_u1, y_flux_v1)
+               y_flux_u1, y_flux_v1 &
+#ifdef ISO
+         &      ,yxtrain_f, yxtsnow_f,yxt1,Roce, &
+         &      yxtsnow,yxtsol,yxtevap,Rland_ice &
+#endif               
+         &      )
           
 ! Special DICE MPL 05082013 puis BOMEX MPL 20150410
@@ -2256,5 +2633,27 @@
           y_flux_v1(j)=ycdragm(j)*(1.+sqrt(yu(j,1)*yu(j,1)+yv(j,1)*yv(j,1)))*yv(j,1)*ypplay(j,1)/RD/yt(j,1)
           ENDDO
-      ENDIF
+       ENDIF
+
+#ifdef ISOVERIF
+        DO j=1,knon
+          DO ixt=1,ntraciso
+            CALL iso_verif_noNaN(yxtevap(ixt,j), &
+         &                       'pbl_surface 1165a: apres surf_seaice')
+          ENDDO
+          DO ixt=1,niso
+            CALL iso_verif_noNaN(yxtsol(ixt,j), &
+         &      'pbl_surface 1165b: apres surf_seaice')
+          ENDDO
+        ENDDO
+#endif
+#ifdef ISOVERIF
+        !write(*,*) 'pbl_surface_mod 1077: sortie surf_seaice'
+        DO j=1,knon
+          IF (iso_eau >= 0) THEN     
+                 CALL iso_verif_egalite(yxtsnow(iso_eau,j), &
+     &                                  ysnow(j),'pbl_surf_mod 1106')
+          ENDIF !IF (iso_eau >= 0) THEN
+        ENDDO !DO i=1,klon
+#endif
 
        CASE DEFAULT
@@ -2316,4 +2715,9 @@
             yt1_new=(1./RCPD)*(AcoefH(j)+BcoefH(j)*y_flux_t1(j)*dtime)
             ytsurf_new(j)=yt1_new-y_flux_t1(j)/(Kech_h(j)*RCPD)
+            ! for cases forced in flux and for which forcing in Ts is needed
+            ! to prevent the latter to reach unrealistic value (even if not used,
+            ! Ts is calculated and hgardfou can appear during the calculation
+            ! of surface saturation humidity for example
+            if (ok_forc_tsurf) ytsurf_new(j)=tg
           ENDDO
 
@@ -2326,4 +2730,7 @@
           y_flux_t1(j) =  yfluxsens(j)
           y_flux_q1(j) = -yevap(j)
+#ifdef ISO
+          y_flux_xt1(:,:) = -yxtevap(:,:)
+#endif
           ENDDO
         ENDIF ! (ok_flux_surf)
@@ -2341,4 +2748,8 @@
 
        IF (iflag_split .GE. 1) THEN
+#ifdef ISO
+        call abort_gcm('pbl_surface_mod 2607','isos pas encore dans iflag_split=1',1)
+#endif
+!
 !
          IF (nsrf .ne. is_oce) THEN
@@ -2558,5 +2969,11 @@
             Kcoef_hq, gama_q, gama_h, &
 !!!
-            y_flux_q(:,:), y_flux_t(:,:), y_d_q(:,:), y_d_t(:,:))    
+            y_flux_q(:,:), y_flux_t(:,:), y_d_q(:,:), y_d_t(:,:) &
+#ifdef ISO
+        &    ,yxt,y_flux_xt1 &
+        &    ,AcoefXT,BcoefXT,CcoefXT,DcoefXT,gama_xt &
+        &    ,y_flux_xt(:,:,:),y_d_xt(:,:,:) &
+#endif
+        &    )    
        ELSE  !(iflag_split .eq.0)
         CALL climb_hq_up(knon, dtime, yt_x, yq_x, &
@@ -2567,5 +2984,11 @@
             Kcoef_hq_x, gama_q_x, gama_h_x, &
 !!!
-            y_flux_q_x(:,:), y_flux_t_x(:,:), y_d_q_x(:,:), y_d_t_x(:,:))    
+            y_flux_q_x(:,:), y_flux_t_x(:,:), y_d_q_x(:,:), y_d_t_x(:,:) &
+#ifdef ISO
+        &    ,yxt_x,y_flux_xt1_x &
+        &    ,AcoefXT_x,BcoefXT_x,CcoefXT_x,DcoefXT_x,gama_xt_x &
+        &    ,y_flux_xt_x(:,:,:),y_d_xt_x(:,:,:) &
+#endif
+        &    )    
 !
        CALL climb_hq_up(knon, dtime, yt_w, yq_w, &
@@ -2576,5 +2999,11 @@
             Kcoef_hq_w, gama_q_w, gama_h_w, &
 !!!
-            y_flux_q_w(:,:), y_flux_t_w(:,:), y_d_q_w(:,:), y_d_t_w(:,:))    
+            y_flux_q_w(:,:), y_flux_t_w(:,:), y_d_q_w(:,:), y_d_t_w(:,:) &
+#ifdef ISO
+        &    ,yxt_w,y_flux_xt1_w &
+        &    ,AcoefXT_w,BcoefXT_w,CcoefXT_w,DcoefXT_w,gama_xt_w &
+        &    ,y_flux_xt_w(:,:,:),y_d_xt_w(:,:,:) &
+#endif
+        &    )    
 !!!
        ENDIF  ! (iflag_split .eq.0)
@@ -2694,6 +3123,25 @@
              flux_u(i,k,nsrf) = y_flux_u(j,k)
              flux_v(i,k,nsrf) = y_flux_v(j,k)
+
+#ifdef ISO
+             DO ixt=1,ntraciso
+                y_d_xt(ixt,j,k)  = y_d_xt(ixt,j,k) * ypct(j)
+                flux_xt(ixt,i,k,nsrf) = y_flux_xt(ixt,j,k)
+             ENDDO ! DO ixt=1,ntraciso
+             h1_diag(i)=h1(j)
+#endif
+
            ENDDO
         ENDDO
+
+#ifdef ISO
+#ifdef ISOVERIF
+        if (iso_eau.gt.0) then
+         call iso_verif_egalite_vect2D( &
+                y_d_xt,y_d_q, &
+                'pbl_surface_mod 2600',ntraciso,klon,klev)
+        endif       
+#endif
+#endif
 
        ELSE  !(iflag_split .eq.0)
@@ -2713,4 +3161,11 @@
             flux_u_x(i,k,nsrf) = y_flux_u_x(j,k)
             flux_v_x(i,k,nsrf) = y_flux_v_x(j,k)
+
+#ifdef ISO
+            DO ixt=1,ntraciso
+              y_d_xt_x(ixt,j,k)  = y_d_xt_x(ixt,j,k) * ypct(j)
+              flux_xt_x(ixt,i,k,nsrf) = y_flux_xt_x(ixt,j,k)
+            ENDDO ! DO ixt=1,ntraciso
+#endif
           ENDDO
         ENDDO
@@ -2730,4 +3185,12 @@
             flux_u_w(i,k,nsrf) = y_flux_u_w(j,k)
             flux_v_w(i,k,nsrf) = y_flux_v_w(j,k)
+
+#ifdef ISO
+            DO ixt=1,ntraciso
+              y_d_xt_w(ixt,j,k)  = y_d_xt_w(ixt,j,k) * ypct(j)
+              flux_xt_w(ixt,i,k,nsrf) = y_flux_xt_w(ixt,j,k)
+            ENDDO ! do ixt=1,ntraciso
+#endif
+
           ENDDO
         ENDDO
@@ -2741,4 +3204,9 @@
             flux_u(i,k,nsrf) = flux_u_x(i,k,nsrf)+ywake_s(j)*(flux_u_w(i,k,nsrf)-flux_u_x(i,k,nsrf))
             flux_v(i,k,nsrf) = flux_v_x(i,k,nsrf)+ywake_s(j)*(flux_v_w(i,k,nsrf)-flux_v_x(i,k,nsrf))
+#ifdef ISO
+            DO ixt=1,ntraciso
+              flux_xt(ixt,i,k,nsrf) = flux_xt_x(ixt,i,k,nsrf)+ywake_s(j)*(flux_xt_w(ixt,i,k,nsrf)-flux_xt_x(ixt,i,k,nsrf))
+            ENDDO ! do ixt=1,ntraciso
+#endif
           ENDDO
         ENDDO
@@ -2798,4 +3266,24 @@
           dflux_t(i) = dflux_t(i) + y_dflux_t(j)*ypct(j)
           dflux_q(i) = dflux_q(i) + y_dflux_q(j)*ypct(j)
+#ifdef ISO
+        DO ixt=1,niso
+          xtsnow(ixt,i,nsrf) = yxtsnow(ixt,j)  
+        ENDDO
+        DO ixt=1,ntraciso
+          xtevap(ixt,i,nsrf) = - flux_xt(ixt,i,1,nsrf)
+          dflux_xt(ixt,i) = dflux_xt(ixt,i) + y_dflux_xt(ixt,j)*ypct(j)
+        ENDDO  
+        IF (nsrf == is_lic) THEN
+          DO ixt=1,niso
+            Rland_ice(ixt,i) = yRland_ice(ixt,j)  
+          ENDDO
+        ENDIF !IF (nsrf == is_lic) THEN     
+#ifdef ISOVERIF
+        IF (iso_eau.gt.0) THEN  
+          call iso_verif_egalite_choix(Rland_ice(iso_eau,i),1.0, &
+     &         'pbl_surf_mod 1230',errmax,errmaxrel)
+        ENDIF !if (iso_eau.gt.0) then
+#endif        
+#endif
        ENDDO
 
@@ -2902,4 +3390,11 @@
              i = ni(j)
              qsol(i) = yqsol(j)
+#ifdef ISO
+             runoff_diag(i)=yrunoff_diag(j)   
+             DO ixt=1,niso
+               xtsol(ixt,i) = yxtsol(ixt,j)
+               xtrunoff_diag(ixt,i)=yxtrunoff_diag(ixt,j)
+             ENDDO
+#endif
           ENDDO
        ENDIF
@@ -2914,5 +3409,22 @@
           ENDDO
        ENDDO
-       
+
+#ifdef ISO
+#ifdef ISOVERIF
+       !write(*,*) 'pbl_surface 2858'
+       DO i = 1, klon
+         DO ixt=1,niso
+           call iso_verif_noNaN(xtsol(ixt,i),'pbl_surface 1405')
+         ENDDO
+       ENDDO
+#endif
+#ifdef ISOVERIF
+     IF (iso_eau.gt.0) THEN
+        call iso_verif_egalite_vect2D( &
+                y_d_xt,y_d_q, &
+                'pbl_surface_mod 1261',ntraciso,klon,klev)
+     ENDIF !if (iso_eau.gt.0) then
+#endif
+#endif
 !!! jyg le 07/02/2012
        IF (iflag_split .ge.1) THEN
@@ -2933,4 +3445,11 @@
            d_u_w(i,k) = d_u_w(i,k) + y_d_u_w(j,k)
            d_v_w(i,k) = d_v_w(i,k) + y_d_v_w(j,k)
+#ifdef ISO
+           DO ixt=1,ntraciso
+             d_xt_x(ixt,i,k) = d_xt_x(ixt,i,k) + y_d_xt_x(ixt,j,k)
+             d_xt_w(ixt,i,k) = d_xt_w(ixt,i,k) + y_d_xt_w(ixt,j,k)
+           ENDDO ! DO ixt=1,ntraciso
+#endif
+
 !
 !!           d_wake_dlt(i,k) = d_wake_dlt(i,k) + y_d_t_w(i,k)-y_d_t_x(i,k)
@@ -2948,4 +3467,9 @@
              d_t(i,k) = d_t(i,k) + y_d_t(j,k)
              d_q(i,k) = d_q(i,k) + y_d_q(j,k)
+#ifdef ISO
+             DO ixt=1,ntraciso
+               d_xt(ixt,i,k) = d_xt(ixt,i,k) + y_d_xt(ixt,j,k)
+             ENDDO !DO ixt=1,ntraciso
+#endif
              d_u(i,k) = d_u(i,k) + y_d_u(j,k)
              d_v(i,k) = d_v(i,k) + y_d_v(j,k)
@@ -2962,4 +3486,24 @@
          ENDDO
         ENDIF
+
+#ifdef ISO
+#ifdef ISOVERIF
+!        write(*,*) 'd_q,d_xt(iso_eau,554,19)=',d_q(554,19),d_xt(iso_eau,554,19)
+!        write(*,*) 'pbl_surface 2929: d_q,d_xt(iso_eau,2,1)=',d_q(2,1),d_xt(iso_eau,2,1)
+!        write(*,*) 'y_d_q,y_d_xt(iso_eau,2,1)=',y_d_q(2,1),y_d_xt(iso_eau,2,1)
+!        write(*,*) 'iso_eau.gt.0=',iso_eau.gt.0
+        call iso_verif_noNaN_vect2D( &
+     &           d_xt, &
+     &           'pbl_surface 1385',ntraciso,klon,klev)  
+     IF (iso_eau >= 0) THEN
+        call iso_verif_egalite_vect2D( &
+                y_d_xt,y_d_q, &
+                'pbl_surface_mod 2945',ntraciso,klon,klev)
+        call iso_verif_egalite_vect2D( &
+                d_xt,d_q, &
+                'pbl_surface_mod 1276',ntraciso,klon,klev)
+     ENDIF !IF (iso_eau >= 0) THEN
+#endif
+#endif
 
 !      print*,'Dans pbl OK4'
@@ -3349,4 +3893,15 @@
    iflag_split=iflag_split_ref
 
+#ifdef ISO
+#ifdef ISOVERIF
+!        write(*,*) 'pbl_surface tmp 3249: d_q,d_xt(iso_eau,2,1)=',d_q(2,1),d_xt(iso_eau,2,1)
+    IF (iso_eau >= 0) THEN
+        call iso_verif_egalite_vect2D( &
+                d_xt,d_q, &
+                'pbl_surface_mod 1276',ntraciso,klon,klev)
+    ENDIF !IF (iso_eau >= 0) THEN
+#endif
+#endif
+
 !****************************************************************************************
 ! 16) Calculate the mean value over all sub-surfaces for some variables
@@ -3370,4 +3925,10 @@
     zxfluxt_w(:,:) = 0.0 ; zxfluxq_w(:,:) = 0.0
     zxfluxu_w(:,:) = 0.0 ; zxfluxv_w(:,:) = 0.0
+#ifdef ISO
+      zxfluxxt(:,:,:) = 0.0 
+      zxfluxxt_x(:,:,:) = 0.0
+      zxfluxxt_w(:,:,:) = 0.0
+#endif
+
 
 !!! jyg le 07/02/2012
@@ -3388,4 +3949,10 @@
               zxfluxu_w(i,k) = zxfluxu_w(i,k) + flux_u_w(i,k,nsrf) * pctsrf(i,nsrf)
               zxfluxv_w(i,k) = zxfluxv_w(i,k) + flux_v_w(i,k,nsrf) * pctsrf(i,nsrf)
+#ifdef ISO
+              DO ixt=1,ntraciso
+                zxfluxxt_x(ixt,i,k) = zxfluxxt_x(ixt,i,k) + flux_xt_x(ixt,i,k,nsrf) * pctsrf(i,nsrf)
+                zxfluxxt_w(ixt,i,k) = zxfluxxt_w(ixt,i,k) + flux_xt_w(ixt,i,k,nsrf) * pctsrf(i,nsrf)
+              ENDDO ! DO ixt=1,ntraciso
+#endif
             ENDDO
           ENDDO
@@ -3407,4 +3974,9 @@
              zxfluxu(i,k) = zxfluxu(i,k) + flux_u(i,k,nsrf) * pctsrf(i,nsrf)
              zxfluxv(i,k) = zxfluxv(i,k) + flux_v(i,k,nsrf) * pctsrf(i,nsrf)
+#ifdef ISO
+             DO ixt=1,niso
+               zxfluxxt(ixt,i,k) = zxfluxxt(ixt,i,k) + flux_xt(ixt,i,k,nsrf) * pctsrf(i,nsrf)
+             ENDDO ! DO ixt=1,niso
+#endif
           ENDDO
        ENDDO
@@ -3431,4 +4003,12 @@
        END DO
     endif
+
+#ifdef ISO
+    DO i = 1, klon
+      DO ixt=1,ntraciso
+        zxxtevap(ixt,i)     = - zxfluxxt(ixt,i,1)
+      ENDDO
+    ENDDO
+#endif
 
 !!!
@@ -3606,8 +4186,17 @@
     zxqsurf(:) = 0.0
     zxsnow(:)  = 0.0
+#ifdef ISO
+    zxxtsnow(:,:)  = 0.0
+#endif
+
     DO nsrf = 1, nbsrf
        DO i = 1, klon
           zxqsurf(i) = zxqsurf(i) + MAX(qsurf(i,nsrf),0.0) * pctsrf(i,nsrf)
           zxsnow(i)  = zxsnow(i)  + snow(i,nsrf)  * pctsrf(i,nsrf)
+#ifdef ISO
+          DO ixt=1,niso
+            zxxtsnow(ixt,i)  = zxxtsnow(ixt,i)  + xtsnow(ixt,i,nsrf)  * pctsrf(i,nsrf)
+          ENDDO ! DO ixt=1,niso
+#endif
        ENDDO
     ENDDO
@@ -3621,7 +4210,17 @@
 !****************************************************************************************
 !
-  SUBROUTINE pbl_surface_final(fder_rst, snow_rst, qsurf_rst, ftsoil_rst)
+  SUBROUTINE pbl_surface_final(fder_rst, snow_rst, qsurf_rst, ftsoil_rst &
+#ifdef ISO
+       ,xtsnow_rst,Rland_ice_rst &
+#endif       
+       )
 
     USE indice_sol_mod
+#ifdef ISO
+#ifdef ISOVERIF
+    USE isotopes_mod, ONLY: iso_eau,ridicule
+    USE isotopes_verif_mod, ONLY: errmax,errmaxrel
+#endif    
+#endif
 
     INCLUDE "dimsoil.h"
@@ -3633,4 +4232,8 @@
     REAL, DIMENSION(klon, nbsrf), INTENT(OUT)          :: qsurf_rst
     REAL, DIMENSION(klon, nsoilmx, nbsrf), INTENT(OUT) :: ftsoil_rst
+#ifdef ISO
+    REAL, DIMENSION(niso,klon, nbsrf), INTENT(OUT)     :: xtsnow_rst
+    REAL, DIMENSION(niso,klon), INTENT(OUT)            :: Rland_ice_rst
+#endif
 
  
@@ -3643,4 +4246,8 @@
     qsurf_rst(:,:)    = qsurf(:,:)
     ftsoil_rst(:,:,:) = ftsoil(:,:,:)
+#ifdef ISO
+    xtsnow_rst(:,:,:)  = xtsnow(:,:,:) 
+    Rland_ice_rst(:,:) = Rland_ice(:,:)
+#endif
 
 !****************************************************************************************
@@ -3655,4 +4262,9 @@
     IF (ALLOCATED(ydTs0)) DEALLOCATE(ydTs0)
     IF (ALLOCATED(ydqs0)) DEALLOCATE(ydqs0)
+#ifdef ISO
+    IF (ALLOCATED(xtsnow)) DEALLOCATE(xtsnow)
+    IF (ALLOCATED(Rland_ice)) DEALLOCATE(Rland_ice)
+    IF (ALLOCATED(Roce)) DEALLOCATE(Roce)
+#endif
 
 !jyg<
@@ -3673,5 +4285,9 @@
   SUBROUTINE pbl_surface_newfrac(itime, pctsrf_new, pctsrf_old, &
        evap, z0m, z0h, agesno,                                  &
-       tsurf,alb_dir,alb_dif, ustar, u10m, v10m, tke)  
+       tsurf,alb_dir,alb_dif, ustar, u10m, v10m, tke &
+#ifdef ISO
+      ,xtevap  &
+#endif
+&      )  
     !albedo SB <<<
     ! Give default values where new fraction has appread
@@ -3702,4 +4318,7 @@
     REAL, DIMENSION(klon,nbsrf+1), INTENT(INOUT)        :: z0m,z0h
     REAL, DIMENSION(klon,klev+1,nbsrf+1), INTENT(INOUT) :: tke
+#ifdef ISO
+    REAL, DIMENSION(ntraciso,klon,nbsrf), INTENT(INOUT)        :: xtevap
+#endif
 
 ! Local variables
@@ -3709,4 +4328,7 @@
     CHARACTER(len=20) :: modname = 'pbl_surface_newfrac'
     INTEGER, DIMENSION(nbsrf) :: nfois=0, mfois=0, pfois=0
+#ifdef ISO
+    INTEGER           :: ixt
+#endif
 !
 ! All at once !! 
@@ -3754,4 +4376,9 @@
                 u10m(i,nsrf)  = u10m(i,nsrf_comp1)
                 v10m(i,nsrf)  = v10m(i,nsrf_comp1)
+#ifdef ISO
+                DO ixt=1,ntraciso
+                  xtevap(ixt,i,nsrf) = xtevap(ixt,i,nsrf_comp1)       
+                ENDDO       
+#endif
                 IF (iflag_pbl > 1) THEN
                  tke(i,:,nsrf) = tke(i,:,nsrf_comp1)
@@ -3809,4 +4436,10 @@
                 u10m(i,nsrf)  = u10m(i,nsrf_comp2) *pctsrf_old(i,nsrf_comp2) + u10m(i,nsrf_comp3) *pctsrf_old(i,nsrf_comp3)
                 v10m(i,nsrf)  = v10m(i,nsrf_comp2) *pctsrf_old(i,nsrf_comp2) + v10m(i,nsrf_comp3) *pctsrf_old(i,nsrf_comp3)
+#ifdef ISO
+                DO ixt=1,ntraciso
+                  xtevap(ixt,i,nsrf) = xtevap(ixt,i,nsrf_comp2) *pctsrf_old(i,nsrf_comp2) &
+                                     + xtevap(ixt,i,nsrf_comp3) *pctsrf_old(i,nsrf_comp3) 
+                ENDDO       
+#endif
                 IF (iflag_pbl > 1) THEN
                  tke(i,:,nsrf) = tke(i,:,nsrf_comp2)*pctsrf_old(i,nsrf_comp2) + tke(i,:,nsrf_comp3)*pctsrf_old(i,nsrf_comp3)
@@ -3821,4 +4454,7 @@
              agesno(i,nsrf)   = 0.
              ftsoil(i,:,nsrf) = tsurf(i,nsrf)
+#ifdef ISO            
+             xtsnow(:,i,nsrf) = 0.
+#endif
           ELSE
              pfois(nsrf) = pfois(nsrf)+ 1
Index: LMDZ6/branches/cirrus/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/phys_local_var_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/phys_local_var_mod.F90	(revision 5202)
@@ -14,4 +14,8 @@
       REAL, SAVE, ALLOCATABLE :: ql_seri(:,:),qs_seri(:,:)
       !$OMP THREADPRIVATE(ql_seri,qs_seri)
+! SN 15/07/2024 ISO 4D
+      REAL, SAVE, ALLOCATABLE :: qx_seri(:,:,:)
+      !$OMP THREADPRIVATE(qx_seri)
+! SN
       REAL, SAVE, ALLOCATABLE :: qbs_seri(:,:)
       !$OMP THREADPRIVATE(qbs_seri)
@@ -24,4 +28,6 @@
       REAL, SAVE, ALLOCATABLE :: pbl_eps(:,:,:)
       !$OMP THREADPRIVATE(pbl_eps)
+      REAL, SAVE, ALLOCATABLE :: tke_shear(:,:,:), tke_buoy(:,:,:), tke_trans(:,:,:)
+      !$OMP THREADPRIVATE(tke_shear,tke_buoy,tke_trans)
       REAL, SAVE, ALLOCATABLE :: tr_seri(:,:,:)
       !$OMP THREADPRIVATE(tr_seri)
@@ -64,4 +70,8 @@
       REAL, SAVE, ALLOCATABLE :: d_t_eva(:,:),d_q_eva(:,:),d_ql_eva(:,:),d_qi_eva(:,:)
       !$OMP THREADPRIVATE(d_t_eva,d_q_eva,d_ql_eva,d_qi_eva)
+! SN 15/07/2024 ISO 4D
+      REAL, SAVE, ALLOCATABLE :: d_qx_eva(:,:,:)
+      !$OMP THREADPRIVATE(d_qx_eva)
+! SN
       REAL, SAVE, ALLOCATABLE :: d_t_lscst(:,:),d_q_lscst(:,:)
       !$OMP THREADPRIVATE(d_t_lscst,d_q_lscst)
@@ -84,6 +94,6 @@
       REAL, SAVE, ALLOCATABLE :: d_t_vdf_x(:,:), d_q_vdf_x(:,:)
       !$OMP THREADPRIVATE( d_t_vdf_x, d_q_vdf_x)
-      REAL, SAVE, ALLOCATABLE :: d_t_bs(:,:), d_q_bs(:,:), d_qbs_bs(:,:)
-      !$OMP THREADPRIVATE( d_t_bs,d_q_bs, d_qbs_bs)
+      REAL, SAVE, ALLOCATABLE :: d_t_bsss(:,:), d_q_bsss(:,:), d_qbs_bsss(:,:)
+      !$OMP THREADPRIVATE( d_t_bsss,d_q_bsss, d_qbs_bsss)
 !>nrlmd+jyg
       REAL, SAVE, ALLOCATABLE :: d_t_oro(:,:)
@@ -117,4 +127,48 @@
       REAL, SAVE, ALLOCATABLE :: d_q_ch4(:,:)
       !$OMP THREADPRIVATE(d_q_ch4)
+#ifdef ISO
+      REAL, SAVE, ALLOCATABLE :: xt_seri(:,:,:)
+      !$OMP THREADPRIVATE( xt_seri)
+      REAL, SAVE, ALLOCATABLE :: xtl_seri(:,:,:)
+      !$OMP THREADPRIVATE( xtl_seri)
+      REAL, SAVE, ALLOCATABLE :: xts_seri(:,:,:)
+      !$OMP THREADPRIVATE( xts_seri)
+      REAL, SAVE, ALLOCATABLE :: xtbs_seri(:,:,:)
+      !$OMP THREADPRIVATE( xtbs_seri)
+      REAL, SAVE, ALLOCATABLE :: d_xt_eva(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_eva)
+      REAL, SAVE, ALLOCATABLE :: d_xtl_eva(:,:,:)
+      !$OMP THREADPRIVATE( d_xtl_eva)
+      REAL, SAVE, ALLOCATABLE :: d_xti_eva(:,:,:)
+      !$OMP THREADPRIVATE( d_xti_eva)
+      REAL, SAVE, ALLOCATABLE :: d_xt_vdf(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_vdf)
+      REAL, SAVE, ALLOCATABLE :: d_xt_dyn(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_dyn)
+      REAL, SAVE, ALLOCATABLE :: d_xtl_dyn(:,:,:), d_xts_dyn(:,:,:), d_xtbs_dyn(:,:,:)
+      !$OMP THREADPRIVATE(d_xtl_dyn, d_xts_dyn, d_xtbs_dyn)
+      REAL, SAVE, ALLOCATABLE :: d_xt_con(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_con)
+      REAL, SAVE, ALLOCATABLE :: d_xt_wake(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_wake)
+      REAL, SAVE, ALLOCATABLE :: d_xt_lsc(:,:,:),d_xtl_lsc(:,:,:),d_xti_lsc(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_lsc,d_xtl_lsc,d_xti_lsc)
+      REAL, SAVE, ALLOCATABLE :: d_xt_ajsb(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_ajsb)
+      REAL, SAVE, ALLOCATABLE :: d_xt_ajs(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_ajs)
+      REAL, SAVE, ALLOCATABLE :: d_xt_ajs_w(:,:,:), d_xt_ajs_x(:,:,:)
+      !$OMP THREADPRIVATE(d_xt_ajs_w, d_xt_ajs_x)
+      REAL, SAVE, ALLOCATABLE :: d_xt_vdf_w(:,:,:), d_xt_vdf_x(:,:,:)
+      !$OMP THREADPRIVATE(d_xt_vdf_w, d_xt_vdf_x)
+      REAL, SAVE, ALLOCATABLE :: d_xt_ch4(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_ch4)
+      REAL, SAVE, ALLOCATABLE :: d_xt_prod_nucl(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_prod_nucl)
+      REAL, SAVE, ALLOCATABLE :: d_xt_cosmo(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_cosmo)
+      REAL, SAVE, ALLOCATABLE :: d_xt_decroiss(:,:,:)
+      !$OMP THREADPRIVATE( d_xt_decroiss)
+#endif
 
 ! tendance du a la conersion Ec -> E thermique
@@ -124,7 +178,4 @@
       !$OMP THREADPRIVATE(d_ts, d_tr)
 
-! aerosols
-      REAL, SAVE, ALLOCATABLE :: m_allaer (:,:,:)
-      !$OMP THREADPRIVATE(m_allaer)
 ! diagnostique pour le rayonnement
       REAL, SAVE, ALLOCATABLE :: topswad_aero(:),  solswad_aero(:)      ! diag
@@ -307,5 +358,17 @@
 !!!OMP THREADPRIVATE(d_s_the, d_dens_the)
       REAL,ALLOCATABLE,SAVE,DIMENSION(:,:)           :: d_deltat_ajs_cv, d_deltaq_ajs_cv
-!$OMP THREADPRIVATE(d_deltat_ajs_cv, d_deltaq_ajs_cv)                       
+!$OMP THREADPRIVATE(d_deltat_ajs_cv, d_deltaq_ajs_cv)
+#ifdef ISO
+    REAL, SAVE, ALLOCATABLE,DIMENSION(:,:,:)          :: d_deltaxt_wk
+!$OMP THREADPRIVATE(d_deltaxt_wk)
+    REAL, SAVE, ALLOCATABLE,DIMENSION(:,:,:)          :: d_deltaxt_wk_gw
+!$OMP THREADPRIVATE(d_deltaxt_wk_gw)
+    REAL, SAVE, ALLOCATABLE,DIMENSION(:,:,:)          ::  d_deltaxt_the
+!$OMP THREADPRIVATE(d_deltaxt_the)
+    REAL, SAVE, ALLOCATABLE,DIMENSION(:,:,:)          ::  d_deltaxt_vdf
+!$OMP THREADPRIVATE(d_deltaxt_vdf)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)           ::  d_deltaxt_ajs_cv
+!$OMP THREADPRIVATE(d_deltaxt_ajs_cv)
+#endif                       
 !!         End of Wake variables
 !!
@@ -343,8 +406,24 @@
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zxfluxlat, zxtsol, snow_lsc, zxfqfonte
 !$OMP THREADPRIVATE(zxfluxlat, zxtsol, snow_lsc, zxfqfonte)
-      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zxrunofflic
-!$OMP THREADPRIVATE(zxrunofflic)
+!SN runoffdiag
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zxrunofflic, runoff_diag
+!$OMP THREADPRIVATE(zxrunofflic, runoff_diag)
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zxqsurf, rain_lsc, rain_num
 !$OMP THREADPRIVATE(zxqsurf, rain_lsc, rain_num)
+#ifdef ISO
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: xtevap,xtprw
+!$OMP THREADPRIVATE(xtevap,xtprw)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: h1_diag
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: xtrunoff_diag
+!$OMP THREADPRIVATE(h1_diagv,xtrunoff_diag)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: zxfxtcalving
+!$OMP THREADPRIVATE(zxfxtcalving)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: xtsnow_lsc, zxfxtfonte
+!$OMP THREADPRIVATE(xtsnow_lsc, zxfxtfonte)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: zxxtrunofflic
+!$OMP THREADPRIVATE(zxxtrunofflic)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: xtrain_lsc
+!$OMP THREADPRIVATE(xtrain_lsc)
+#endif
 !
 !jyg+nrlmd<
@@ -384,4 +463,10 @@
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: kh, kh_x, kh_w
 !$OMP THREADPRIVATE(kh, kh_x, kh_w)
+#ifdef ISO
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:) :: dxtvdf_x, dxtvdf_w
+!$OMP THREADPRIVATE(dxtvdf_x, dxtvdf_w)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:) :: xt_therm
+!$OMP THREADPRIVATE(xt_therm)
+#endif
 !!!
 !!!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
@@ -446,4 +531,50 @@
       REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:):: sij
 !$OMP THREADPRIVATE(sij)
+#ifdef ISO
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: xtwdtrainA
+!$OMP THREADPRIVATE(xtwdtrainA)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: xtev
+!$OMP THREADPRIVATE(xtev)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: xttaa
+!$OMP THREADPRIVATE(xttaa)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: xtclw
+!$OMP THREADPRIVATE(xtclw)
+#ifdef DIAGISO
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:)  :: qlp
+!$OMP THREADPRIVATE(qlp)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:)  :: qvp
+!$OMP THREADPRIVATE(qvp)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:)  :: fq_detrainement
+!$OMP THREADPRIVATE(fq_detrainement)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:)  :: fq_ddft
+!$OMP THREADPRIVATE(fq_ddft)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:)  :: fq_fluxmasse
+!$OMP THREADPRIVATE(fq_fluxmasse)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:)  :: fq_evapprecip
+!$OMP THREADPRIVATE(fq_evapprecip)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:)  :: f_detrainement
+!$OMP THREADPRIVATE(f_detrainement)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:)  :: q_detrainement
+!$OMP THREADPRIVATE(q_detrainement)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: xt_detrainement
+!$OMP THREADPRIVATE(xt_detrainement)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: xtlp
+!$OMP THREADPRIVATE(xtlp)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: xtvp
+!$OMP THREADPRIVATE(xtvp)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:)  :: q_the
+!$OMP THREADPRIVATE(q_the)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: xt_the
+!$OMP THREADPRIVATE(xt_the)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: fxt_detrainement
+!$OMP THREADPRIVATE(fxt_detrainement)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: fxt_ddft
+!$OMP THREADPRIVATE(fxt_ddft)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: fxt_fluxmasse
+!$OMP THREADPRIVATE(fxt_fluxmasse)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:)  :: fxt_evapprecip
+!$OMP THREADPRIVATE(fxt_evapprecip)
+#endif
+#endif
 !
 !      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: coefh, coefm, lambda_th
@@ -481,4 +612,10 @@
       REAL, ALLOCATABLE, SAVE, DIMENSION(:,:) :: pfraclr,pfracld
 !$OMP THREADPRIVATE(pfraclr,pfracld)
+      REAL, SAVE, ALLOCATABLE :: cldfraliq(:,:)
+!$OMP THREADPRIVATE(cldfraliq)
+      REAL, SAVE, ALLOCATABLE ::mean_icefracturb(:,:)
+!$OMP THREADPRIVATE(mean_icefracturb)
+      REAL, SAVE, ALLOCATABLE :: sigma2_icefracturb(:,:)
+!$OMP THREADPRIVATE(sigma2_icefracturb)
 
 ! variables de sorties MM
@@ -487,4 +624,12 @@
 !$OMP THREADPRIVATE(zxsnow,snowhgt,qsnow,to_ice)
 !$OMP THREADPRIVATE(sissnow,runoff,albsol3_lic)
+#ifdef ISO
+      REAL, ALLOCATABLE, SAVE, DIMENSION(:,:) :: zxxtsnow
+!$OMP THREADPRIVATE(zxxtsnow)     
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:) :: xtVprecip,xtVprecipi
+!$OMP THREADPRIVATE(xtVprecip,xtVprecipi) 
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:) :: pxtrfl, pxtsfl
+!$OMP THREADPRIVATE(pxtrfl, pxtsfl) 
+#endif
 
       REAL, ALLOCATABLE, SAVE, DIMENSION(:) :: p_tropopause, z_tropopause, t_tropopause
@@ -567,8 +712,14 @@
       REAL, ALLOCATABLE, SAVE, DIMENSION(:,:) :: R2SO4
 !$OMP THREADPRIVATE(R2SO4)
+      REAL, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: R2SO4B
+!$OMP THREADPRIVATE(R2SO4B)
       REAL, ALLOCATABLE, SAVE, DIMENSION(:,:) :: DENSO4
 !$OMP THREADPRIVATE(DENSO4)
+      REAL, ALLOCATABLE, SAVE, DIMENSION(:,:, :) :: DENSO4B
+!$OMP THREADPRIVATE(DENSO4B)      
       REAL, ALLOCATABLE, SAVE, DIMENSION(:,:) :: f_r_wet
 !$OMP THREADPRIVATE(f_r_wet)
+      REAL, ALLOCATABLE, SAVE, DIMENSION(:,:, :) :: f_r_wetB
+!$OMP THREADPRIVATE(f_r_wetB)
       REAL, ALLOCATABLE, SAVE, DIMENSION(:,:) :: decfluxaer
 !$OMP THREADPRIVATE(decfluxaer)
@@ -599,4 +750,19 @@
       REAL, ALLOCATABLE, SAVE, DIMENSION(:,:) :: vsed_aer
 !$OMP THREADPRIVATE(vsed_aer)
+!     Sulfate aerosol concentration (dry mixing ratio) (condensed H2SO4 mmr)
+      REAL, ALLOCATABLE, SAVE, DIMENSION(:,:) :: sulfmmr
+!$OMP THREADPRIVATE(sulfmmr)
+!     SAD all aerosols (cm2/cm3)
+      REAL, ALLOCATABLE, SAVE, DIMENSION(:,:) :: SAD_sulfate
+!$OMP THREADPRIVATE(SAD_sulfate)
+!     Effective radius of wet surface aerosols (cm)
+      REAL, ALLOCATABLE, SAVE, DIMENSION(:,:) :: reff_sulfate
+!$OMP THREADPRIVATE(reff_sulfate)
+!     sulfate MMR in different modes (based on sulfmmr, it must be dry mmr)
+      REAL, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: sulfmmr_mode
+!$OMP THREADPRIVATE(sulfmmr_mode)
+!     particle concentration in different modes (part/m3)
+      REAL, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: nd_mode
+!$OMP THREADPRIVATE(nd_mode)
 !
 !---3D budget variables
@@ -647,17 +813,28 @@
 SUBROUTINE phys_local_var_init
 USE dimphy
-USE infotrac_phy, ONLY : nbtr
+USE infotrac_phy, ONLY : nbtr,nqtot
+#ifdef ISO
+USE infotrac_phy, ONLY : ntraciso=>ntiso,niso
+#endif
 USE aero_mod
 USE indice_sol_mod
 USE phys_output_var_mod
 USE phys_state_var_mod
+#ifdef CPP_StratAer
+USE infotrac_phy, ONLY : nbtr_bin
+#endif
 
 IMPLICIT NONE
       ALLOCATE(t_seri(klon,klev),q_seri(klon,klev),ql_seri(klon,klev),qs_seri(klon,klev), qbs_seri(klon,klev))
+! SN 4D ISO
+      ALLOCATE(qx_seri(klon,klev,nqtot))
+! SN
       ALLOCATE(u_seri(klon,klev),v_seri(klon,klev))
       ALLOCATE(cf_seri(klon,klev),rvc_seri(klon,klev))
       ALLOCATE(l_mixmin(klon,klev+1,nbsrf),l_mix(klon,klev+1,nbsrf),wprime(klon,klev+1,nbsrf))
       ALLOCATE(pbl_eps(klon,klev+1,nbsrf+1))
+      ALLOCATE(tke_shear(klon,klev+1,nbsrf), tke_buoy(klon,klev+1,nbsrf), tke_trans(klon,klev+1,nbsrf))
       pbl_eps(:,:,:)=0.
+      tke_shear(:,:,:)=0.; tke_buoy(:,:,:)=0.; tke_trans(:,:,:)=0.
       l_mix(:,:,:)=0.;l_mixmin(:,:,:)=0.;wprime(:,:,:)=0. ! doit etre initialse car pas toujours remplis
       ALLOCATE(rhcl(klon,klev))
@@ -684,4 +861,7 @@
       ALLOCATE(d_u_ajs(klon,klev),d_v_ajs(klon,klev))
       ALLOCATE(d_t_eva(klon,klev),d_q_eva(klon,klev))
+! SN 4D ISO
+      ALLOCATE(d_qx_eva(klon,klev,nqtot))
+! SN 
       ALLOCATE(d_ql_eva(klon,klev),d_qi_eva(klon,klev))
       ALLOCATE(d_t_lscst(klon,klev),d_q_lscst(klon,klev))
@@ -690,7 +870,36 @@
       ALLOCATE(d_t_vdf(klon,klev),d_q_vdf(klon,klev),d_t_diss(klon,klev))
       ALLOCATE (d_qbs_vdf(klon,klev))
-      ALLOCATE(d_t_bs(klon,klev),d_q_bs(klon,klev),d_qbs_bs(klon,klev))
+      ALLOCATE(d_t_bsss(klon,klev),d_q_bsss(klon,klev),d_qbs_bsss(klon,klev))
       ALLOCATE(d_t_vdf_w(klon,klev),d_q_vdf_w(klon,klev))
       ALLOCATE(d_t_vdf_x(klon,klev),d_q_vdf_x(klon,klev))
+#ifdef ISO
+      allocate(xt_seri(ntraciso,klon,klev))
+      allocate(xtl_seri(ntraciso,klon,klev))
+      allocate(xts_seri(ntraciso,klon,klev))
+      allocate(xtbs_seri(ntraciso,klon,klev))
+      allocate(d_xt_dyn(ntraciso,klon,klev))
+      allocate(d_xtl_dyn(ntraciso,klon,klev))
+      allocate(d_xts_dyn(ntraciso,klon,klev))
+      allocate(d_xtbs_dyn(ntraciso,klon,klev))
+      allocate(d_xt_con(ntraciso,klon,klev))
+      allocate(d_xt_wake(ntraciso,klon,klev))
+      allocate(d_xt_lsc(ntraciso,klon,klev))
+      allocate(d_xtl_lsc(ntraciso,klon,klev))
+      allocate(d_xti_lsc(ntraciso,klon,klev))
+      allocate(d_xt_ajsb(ntraciso,klon,klev))
+      allocate(d_xt_ajs(ntraciso,klon,klev))
+      allocate(d_xt_ajs_w(ntraciso,klon,klev))
+      allocate(d_xt_ajs_x(ntraciso,klon,klev))
+      allocate(d_xt_eva(ntraciso,klon,klev))
+      allocate(d_xtl_eva(ntraciso,klon,klev))
+      allocate(d_xti_eva(ntraciso,klon,klev))
+      allocate(d_xt_vdf(ntraciso,klon,klev))  
+      allocate(d_xt_vdf_w(ntraciso,klon,klev))
+      allocate(d_xt_vdf_x(ntraciso,klon,klev))
+      allocate(d_xt_ch4(ntraciso,klon,klev))
+      allocate(d_xt_prod_nucl(ntraciso,klon,klev))
+      allocate(d_xt_cosmo(ntraciso,klon,klev))
+      allocate(d_xt_decroiss(ntraciso,klon,klev))
+#endif
 
       ALLOCATE(d_u_vdf(klon,klev),d_v_vdf(klon,klev))
@@ -704,6 +913,4 @@
       ALLOCATE(d_ts(klon,nbsrf), d_tr(klon,klev,nbtr))
 
-! aerosols
-      ALLOCATE(m_allaer(klon,klev,naero_tot))
 ! Special RRTM
       ALLOCATE(ZLWFT0_i(klon,klev+1),ZSWFT0_i(klon,klev+1),ZFLDN0(klon,klev+1))
@@ -813,4 +1020,11 @@
 !!      ALLOCATE( d_s_the(klon), d_dens_the(klon))
       ALLOCATE(d_deltat_ajs_cv(klon, klev), d_deltaq_ajs_cv(klon, klev))
+#ifdef ISO
+      ALLOCATE(d_deltaxt_wk(ntraciso,klon, klev))
+      ALLOCATE(d_deltaxt_wk_gw(ntraciso,klon, klev))
+      ALLOCATE(d_deltaxt_the(ntraciso,klon, klev))
+      ALLOCATE(d_deltaxt_vdf(ntraciso,klon, klev))
+      ALLOCATE(d_deltaxt_ajs_cv(ntraciso,klon, klev))
+#endif
 !!         End of wake variables
 !!
@@ -834,5 +1048,7 @@
       ALLOCATE(zxfqcalving(klon), zxfluxlat(klon))
       ALLOCATE(zxtsol(klon), snow_lsc(klon), zxfqfonte(klon), zxqsurf(klon))
-      ALLOCATE(zxrunofflic(klon))
+! SN add runoff_diag
+      ALLOCATE(zxrunofflic(klon), runoff_diag(klon))
+      runoff_diag(:)=0.
       ALLOCATE(zxustartlic(klon), zxrhoslic(klon), zxqsaltlic(klon))
       zxustartlic(:)=0. ; zxrhoslic(:)=0. ; zxqsaltlic(:)=0.
@@ -841,4 +1057,17 @@
       ALLOCATE(qlth(klon,klev), qith(klon,klev), qsith(klon,klev), wiceth(klon,klev))
       !
+#ifdef ISO
+      ALLOCATE(xtevap(ntraciso,klon))
+      ALLOCATE(xtprw(ntraciso,klon))
+      ALLOCATE(zxfxtcalving(niso,klon))
+      ALLOCATE(xtsnow_lsc(ntraciso,klon), zxfxtfonte(niso,klon)) 
+      ALLOCATE(zxxtrunofflic(niso,klon)) 
+      ALLOCATE(xtrain_lsc(ntraciso,klon))
+      ALLOCATE(xtrunoff_diag(niso,klon))
+      ALLOCATE(h1_diag(klon))
+!SN
+      xtrunoff_diag(:,:)=0. ! because variables are only given values on knon grid points
+#endif
+!
       ALLOCATE(sens_x(klon), sens_w(klon))
       ALLOCATE(zxfluxlat_x(klon), zxfluxlat_w(klon))
@@ -857,4 +1086,8 @@
       ALLOCATE(cdragm_x(klon), cdragm_w(klon))
       ALLOCATE(kh(klon), kh_x(klon), kh_w(klon))
+#ifdef ISO
+      ALLOCATE(dxtvdf_x(ntraciso,klon,klev), dxtvdf_w(ntraciso,klon,klev))
+      ALLOCATE(xt_therm(ntraciso,klon,klev))
+#endif
 !
       ALLOCATE(ptconv(klon,klev))
@@ -912,4 +1145,27 @@
       ALLOCATE(epmlmMm(klon,klev,klev), eplaMm(klon,klev))
       ALLOCATE(sij(klon,klev,klev))
+#ifdef ISO
+      ALLOCATE(xtwdtrainA(ntraciso,klon,klev))
+      ALLOCATE(xtev(ntraciso,klon,klev) )
+      ALLOCATE(xttaa(ntraciso,klon,klev) )
+      ALLOCATE(xtclw(ntraciso,klon,klev) )
+#ifdef DIAGISO
+      ALLOCATE(qlp(klon,klev))
+      ALLOCATE(qvp(klon,klev))
+      ALLOCATE(fq_detrainement(klon,klev))
+      ALLOCATE(fq_ddft(klon,klev))
+      ALLOCATE(fq_fluxmasse(klon,klev))
+      ALLOCATE(fq_evapprecip(klon,klev))
+      ALLOCATE(f_detrainement(klon,klev), q_detrainement(klon,klev))
+      ALLOCATE(xtlp(ntraciso,klon,klev))
+      ALLOCATE(xtvp(ntraciso,klon,klev))
+      ALLOCATE(q_the(klon,klev), xt_the(ntraciso,klon,klev))
+      ALLOCATE(fxt_detrainement(ntraciso,klon,klev))
+      ALLOCATE(fxt_ddft(ntraciso,klon,klev))
+      ALLOCATE(fxt_fluxmasse(ntraciso,klon,klev))
+      ALLOCATE(fxt_evapprecip(ntraciso,klon,klev))
+      ALLOCATE(xt_detrainement(ntraciso,klon,klev))
+#endif
+#endif
 
       ALLOCATE(prfl(klon, klev+1))
@@ -931,4 +1187,7 @@
       ALLOCATE(pfraclr(klon,klev),pfracld(klon,klev))
       pfraclr(:,:)=0. ; pfracld(:,:)=0. ! because not always defined
+      ALLOCATE(cldfraliq(klon,klev))
+      ALLOCATE(sigma2_icefracturb(klon,klev))
+      ALLOCATE(mean_icefracturb(klon,klev))
       ALLOCATE(distcltop(klon,klev))
       ALLOCATE(temp_cltop(klon,klev))
@@ -937,4 +1196,9 @@
       ALLOCATE (zxsnow(klon),snowhgt(klon),qsnow(klon),to_ice(klon))
       ALLOCATE (sissnow(klon),runoff(klon),albsol3_lic(klon))
+#ifdef ISO
+      ALLOCATE (zxxtsnow(niso,klon))
+      ALLOCATE(xtVprecip(ntraciso,klon, klev+1),xtVprecipi(ntraciso,klon, klev+1))
+      ALLOCATE(pxtsfl(ntraciso,klon, klev+1),pxtrfl(ntraciso,klon, klev+1))
+#endif
 
       ALLOCATE (p_tropopause(klon))
@@ -968,6 +1232,9 @@
       ALLOCATE (d_q_emiss(klon,klev))
       ALLOCATE (R2SO4(klon,klev))
+      ALLOCATE (R2SO4B(klon,klev,nbtr_bin))
       ALLOCATE (DENSO4(klon,klev))
+      ALLOCATE (DENSO4B(klon,klev,nbtr_bin))
       ALLOCATE (f_r_wet(klon,klev))
+      ALLOCATE (f_r_wetB(klon,klev,nbtr_bin))
       ALLOCATE (decfluxaer(klon,nbtr))
       ALLOCATE (mdw(nbtr))
@@ -1006,4 +1273,9 @@
       ALLOCATE (surf_PM25_sulf(klon))
       ALLOCATE (vsed_aer(klon,klev))
+      ALLOCATE (sulfmmr(klon,klev))
+      ALLOCATE (SAD_sulfate(klon,klev))
+      ALLOCATE (reff_sulfate(klon,klev))
+      ALLOCATE (sulfmmr_mode(klon,klev,nbtr_bin))
+      ALLOCATE (nd_mode(klon,klev,nbtr_bin))
 #endif
 
@@ -1016,7 +1288,11 @@
 IMPLICIT NONE
       DEALLOCATE(t_seri,q_seri,ql_seri,qs_seri, qbs_seri)
+! SN 4D ISO
+      DEALLOCATE(qx_seri)
+! SN
       DEALLOCATE(u_seri,v_seri)
       DEALLOCATE(cf_seri,rvc_seri)
       DEALLOCATE(l_mixmin,l_mix,wprime)
+      DEALLOCATE(tke_shear,tke_buoy,tke_trans)
       DEALLOCATE(pbl_eps)
       DEALLOCATE(rhcl)
@@ -1043,4 +1319,7 @@
       DEALLOCATE(d_u_ajs,d_v_ajs)
       DEALLOCATE(d_t_eva,d_q_eva)
+! SN 4D ISO
+      DEALLOCATE(d_qx_eva)
+! SN
       DEALLOCATE(d_ql_eva,d_qi_eva)
       DEALLOCATE(d_t_lscst,d_q_lscst)
@@ -1049,5 +1328,27 @@
       DEALLOCATE(d_t_vdf,d_q_vdf,d_t_diss)
       DEALLOCATE(d_qbs_vdf)
-      DEALLOCATE(d_t_bs,d_q_bs,d_qbs_bs)
+      DEALLOCATE(d_t_bsss,d_q_bsss,d_qbs_bsss)
+#ifdef ISO
+      deallocate(xt_seri,xtl_seri,xts_seri,xtbs_seri)
+      DEALLOCATE(d_xtl_eva,d_xti_eva)
+      deallocate(d_xt_dyn,d_xtl_dyn,d_xts_dyn,d_xtbs_dyn)
+      deallocate(d_xt_con)
+      deallocate(d_xt_wake)
+      deallocate(d_xt_lsc)
+      deallocate(d_xtl_lsc,d_xti_lsc)
+      deallocate(d_xt_ajsb)
+      deallocate(d_xt_ajs)
+      deallocate(d_xt_ajs_w,d_xt_ajs_x)
+      deallocate(d_xt_eva)
+      deallocate(d_xtl_eva)
+      deallocate(d_xti_eva)
+      deallocate(d_xt_vdf)
+      deallocate(d_xt_vdf_w,d_xt_vdf_x)
+      deallocate(d_xt_ch4)
+      deallocate(d_xt_prod_nucl)
+      deallocate(d_xt_cosmo)
+      deallocate(d_xt_decroiss)
+#endif
+
       DEALLOCATE(d_u_vdf,d_v_vdf)
       DEALLOCATE(d_t_oli,d_t_oro)
@@ -1121,6 +1422,4 @@
       DEALLOCATE(solsw_aerop, solsw0_aerop)
       DEALLOCATE(topswcf_aerop, solswcf_aerop)
-!AI Aerosols
-      DEALLOCATE(m_allaer)
 !CK LW diagnostics
       DEALLOCATE(toplwad_aerop, sollwad_aerop)
@@ -1155,4 +1454,10 @@
 !!      DEALLOCATE( d_s_the, d_dens_the)
       DEALLOCATE(d_deltat_ajs_cv, d_deltaq_ajs_cv)
+#ifdef ISO
+      DEALLOCATE(d_deltaxt_wk)
+      DEALLOCATE(d_deltaxt_wk_gw)
+      DEALLOCATE(d_deltaxt_ajs_cv)
+      DEALLOCATE(d_deltaxt_vdf)
+#endif
 !
       DEALLOCATE(bils)
@@ -1173,5 +1478,6 @@
       DEALLOCATE(uwat, vwat)
       DEALLOCATE(zxfqcalving, zxfluxlat)
-      DEALLOCATE(zxrunofflic)
+! SN runoff_diag
+      DEALLOCATE(zxrunofflic, runoff_diag)
       DEALLOCATE(zxustartlic, zxrhoslic, zxqsaltlic)
       DEALLOCATE(zxtsol, snow_lsc, zxfqfonte, zxqsurf)
@@ -1194,4 +1500,14 @@
       DEALLOCATE(cdragm_x, cdragm_w)
       DEALLOCATE(kh, kh_x, kh_w)
+#ifdef ISO
+      DEALLOCATE(xtevap,xtprw)
+      DEALLOCATE(zxfxtcalving)
+      DEALLOCATE(zxxtrunofflic)
+      DEALLOCATE(xtsnow_lsc, zxfxtfonte)
+      DEALLOCATE(xtrain_lsc)
+      DEALLOCATE(dxtvdf_x, dxtvdf_w)
+      DEALLOCATE(xt_therm)
+      DEALLOCATE(h1_diag,xtrunoff_diag)
+#endif
 !
       DEALLOCATE(ptconv)
@@ -1243,4 +1559,27 @@
       DEALLOCATE(epmlmMm, eplaMm)
       DEALLOCATE(sij)
+#ifdef ISO
+      DEALLOCATE(xtwdtrainA)
+      DEALLOCATE(xttaa )
+      DEALLOCATE(xtclw )
+      DEALLOCATE(xtev )
+#ifdef DIAGISO
+      DEALLOCATE(qlp)
+      DEALLOCATE(qvp)
+      DEALLOCATE(fq_detrainement)
+      DEALLOCATE(fq_ddft)
+      DEALLOCATE(fq_fluxmasse)
+      DEALLOCATE(fq_evapprecip)
+      DEALLOCATE(f_detrainement,q_detrainement)
+      DEALLOCATE(xtlp)
+      DEALLOCATE(xtvp)
+      DEALLOCATE(q_the,xt_the)
+      DEALLOCATE(fxt_detrainement)
+      DEALLOCATE(fxt_ddft)
+      DEALLOCATE(fxt_fluxmasse)
+      DEALLOCATE(fxt_evapprecip)
+      DEALLOCATE(xt_detrainement)
+#endif
+#endif
 
 
@@ -1259,7 +1598,14 @@
       DEALLOCATE(rneb)
       DEALLOCATE(pfraclr,pfracld)
+      DEALLOCATE(cldfraliq)
+      DEALLOCATE(sigma2_icefracturb)
+      DEALLOCATE(mean_icefracturb)
       DEALLOCATE (zxsnow,snowhgt,qsnow,to_ice,sissnow,runoff,albsol3_lic)
       DEALLOCATE(distcltop)
       DEALLOCATE(temp_cltop)
+#ifdef ISO
+      DEALLOCATE (zxxtsnow,xtVprecip,xtVprecipi,pxtrfl,pxtsfl)
+#endif
+
       DEALLOCATE (p_tropopause)
       DEALLOCATE (z_tropopause)
@@ -1291,7 +1637,7 @@
 ! variables for strat. aerosol CK
       DEALLOCATE (d_q_emiss)
-      DEALLOCATE (R2SO4)
-      DEALLOCATE (DENSO4)
-      DEALLOCATE (f_r_wet)
+      DEALLOCATE (R2SO4, R2SO4B)
+      DEALLOCATE (DENSO4, DENSO4B)
+      DEALLOCATE (f_r_wet, f_r_wetB)
       DEALLOCATE (decfluxaer)
       DEALLOCATE (mdw)
@@ -1308,4 +1654,9 @@
       DEALLOCATE (surf_PM25_sulf)
       DEALLOCATE (vsed_aer)
+      DEALLOCATE (sulfmmr)
+      DEALLOCATE (SAD_sulfate)
+      DEALLOCATE (reff_sulfate)
+      DEALLOCATE (sulfmmr_mode)
+      DEALLOCATE (nd_mode)
       DEALLOCATE (budg_3D_ocs_to_so2)
       DEALLOCATE (budg_3D_so2_to_h2so4)
Index: LMDZ6/branches/cirrus/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 5202)
@@ -1112,6 +1112,13 @@
   TYPE(ctrl_out), SAVE :: o_tke = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11, 11/), &
     'tke ', 'TKE', 'm2/s2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_tke_shear = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'tke_shear ', 'TKE shear term', 'm2/s3', (/ ('', i=1, 10) /))  
+  TYPE(ctrl_out), SAVE :: o_tke_buoy = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'tke_buoy ', 'TKE buoyancy term', 'm2/s3', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_tke_trans = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'tke_trans ', 'TKE transport term', 'm2/s3', (/ ('', i=1, 10) /))
   TYPE(ctrl_out), SAVE :: o_tke_dissip = ctrl_out((/ 10, 10, 10, 10, 10, 10, 11, 11, 11, 11/), &
-    'tke_dissip ', 'TKE DISSIPATION', 'm2/s3', (/ ('', i=1, 10) /))   
+    'tke_dissip ', 'TKE dissipation term', 'm2/s3', (/ ('', i=1, 10) /))
+
   TYPE(ctrl_out), SAVE :: o_tke_max = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11, 11/), &
     'tke_max', 'TKE max', 'm2/s2',                                  &
@@ -1442,4 +1449,12 @@
   TYPE(ctrl_out), SAVE :: o_tau_strat_1020 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 1/), &
     'OD1020_strat_only', 'Stratospheric Aerosol Optical depth at 1020 nm ', '1', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SAD_sulfate = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 1/), &
+    'SAD_sulfate', 'SAD WET sulfate aerosols', 'cm2/cm3', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_reff_sulfate = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 1/), &
+    'reff_sulfate', 'Effective radius of WET sulfate aerosols', 'cm', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_sulfmmr = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 1/), &
+    'sulfMMR', 'Sulfate aerosol concentration (dry mass mixing ratio)', 'kg(H2SO4)/kg(air)', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_nd_mode(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_sulfmmr_mode(:)
 !--chemistry
   TYPE(ctrl_out), SAVE :: o_R2SO4 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 1/), &
@@ -1551,4 +1566,11 @@
   TYPE(ctrl_out), SAVE :: o_rneb = ctrl_out((/ 2, 5, 10, 10, 10, 10, 11, 11, 11, 11/), &
     'rneb', 'Cloud fraction', '-', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_cldfraliq = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'cldfraliq', 'Liquid fraction of the cloud', '-', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_sigma2_icefracturb = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'sigma2_icefracturb', 'Variance of the diagnostic supersaturation distribution (icefrac_turb) [-]', '-', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_mean_icefracturb = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'mean_icefracturb', 'Mean of the diagnostic supersaturation distribution (icefrac_turb) [-]', '-', (/ ('', i=1, 10) /))
+ 
   TYPE(ctrl_out), SAVE :: o_rnebjn = ctrl_out((/ 2, 5, 10, 10, 10, 10, 11, 11,11, 11/), &      
     'rnebjn', 'Cloud fraction in day', '-', (/ ('', i=1, 10) /))
@@ -1981,4 +2003,28 @@
   TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dtr_dry(:)
 
+#ifdef ISO
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_xtprecip(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_xtevap(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_xtevap_srf(:,:) ! ajout Camille 8 mai 2023
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_xtplul(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_xtpluc(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_xtovap(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_xtoliq(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_xtcond(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_xtrunoff_diag(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxtdyn(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxtldyn(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxtvdf(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxtcon(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxtlsc(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxteva(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxtajs(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxtthe(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxtch4(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxtprod_nucl(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxtcosmo(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_dxtdecroiss(:)
+#endif
+
   TYPE(ctrl_out), SAVE :: o_rsu = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11, 11/), &
     'rsu', 'SW upward radiation', 'W m-2', (/ ('', i=1, 10) /))
@@ -2064,4 +2110,9 @@
   TYPE(ctrl_out), SAVE :: o_runoff = ctrl_out((/ 1, 1, 10, 1, 10, 10, 11, 11, 11, 11/), &
     'runoff', 'Run-off rate land ice', 'kg/m2/s', (/ ('', i=1, 10) /))
+! SN add runoff_diag
+!#ifdef ISO
+  TYPE(ctrl_out), SAVE :: o_runoff_diag = ctrl_out((/ 1, 1, 10, 1, 10, 10, 11, 11, 11, 11/), &
+    'runoffland', 'Run-off rate land for bucket', 'kg/m2/s', (/ ('', i=1, 10) /))
+!#endif
   TYPE(ctrl_out), SAVE :: o_albslw3 = ctrl_out((/ 1, 1, 1, 1, 10, 10, 11, 11, 11, 11/), &
     'albslw3', 'Surface albedo LW3', '-', (/ ('', i=1, 10) /))
Index: LMDZ6/branches/cirrus/libf/phylmd/phys_output_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/phys_output_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/phys_output_mod.F90	(revision 5202)
@@ -35,5 +35,5 @@
     USE iophy 
     USE dimphy
-    USE infotrac_phy, ONLY: nqtot, tracers, niso
+    USE infotrac_phy, ONLY: nqtot, tracers, niso, ntraciso=>ntiso
     USE strings_mod,  ONLY: maxlen
     USE ioipsl
@@ -49,4 +49,13 @@
     ! ug Pour les sorties XIOS
     USE wxios
+#ifdef CPP_StratAer
+   USE infotrac_phy, ONLY: nbtr_bin
+#endif
+#ifdef ISO
+    USE isotopes_mod, ONLY: isoName,iso_HTO
+#ifdef ISOTRAC
+    use isotrac_mod, only: index_zone,index_iso,strtrac
+#endif
+#endif
 
     IMPLICIT NONE
@@ -93,5 +102,5 @@
     CHARACTER(LEN=4), DIMENSION(nlevSTD)  :: clevSTD
     REAL, DIMENSION(nlevSTD)              :: rlevSTD
-    INTEGER                               :: nsrf, k, iq, iff, i, j, ilev, itr, ixt, iiso, izone
+    INTEGER                               :: nsrf, k, iq, iff, i, j, ilev, itr, itrb, ixt, iiso, izone
     INTEGER                               :: naero
     LOGICAL                               :: ok_veget
@@ -112,4 +121,8 @@
     LOGICAL, DIMENSION(nfiles)            :: phys_out_filestations
 
+#ifdef ISO
+    CHARACTER(LEN=maxlen) :: outiso
+    CHARACTER(LEN=20) :: unit
+#endif
     CHARACTER(LEN=maxlen) :: tnam, lnam, dn
     INTEGER :: flag(nfiles)
@@ -158,4 +171,32 @@
     ALLOCATE(o_dtr_sscav(nqtot),o_dtr_sat(nqtot),o_dtr_uscav(nqtot))
     ALLOCATE(o_dtr_dry(nqtot),o_dtr_vdf(nqtot))
+#ifdef CPP_StratAer
+    ALLOCATE(o_nd_mode(nbtr_bin),o_sulfmmr_mode(nbtr_bin))
+#endif
+#ifdef ISO
+    ALLOCATE(o_xtprecip(ntraciso))
+    ALLOCATE(o_xtplul(ntraciso))
+    ALLOCATE(o_xtpluc(ntraciso))
+    ALLOCATE(o_xtevap(ntraciso))
+    ALLOCATE(o_xtevap_srf(ntraciso,4))
+    ALLOCATE(o_xtovap(ntraciso))
+    ALLOCATE(o_xtoliq(ntraciso))
+    ALLOCATE(o_xtcond(ntraciso))
+    ALLOCATE(o_xtrunoff_diag(ntraciso))
+    ALLOCATE(o_dxtdyn(ntraciso))
+    ALLOCATE(o_dxtldyn(ntraciso))
+    ALLOCATE(o_dxtcon(ntraciso))
+    ALLOCATE(o_dxtlsc(ntraciso))
+    ALLOCATE(o_dxteva(ntraciso))
+    ALLOCATE(o_dxtajs(ntraciso))
+    ALLOCATE(o_dxtvdf(ntraciso))
+    ALLOCATE(o_dxtthe(ntraciso))
+    ALLOCATE(o_dxtch4(ntraciso))
+    if (iso_HTO.gt.0) then
+      ALLOCATE(o_dxtprod_nucl(ntraciso))
+      ALLOCATE(o_dxtcosmo(ntraciso))
+      ALLOCATE(o_dxtdecroiss(ntraciso))
+    endif
+#endif
 
     levmax = [klev, klev, klev, klev, klev, klev, nlevSTD, nlevSTD, nlevSTD, klev]
@@ -467,5 +508,5 @@
      ENDIF ! clef_files
 
-          itr = 0
+          itr = 0; itrb = 0
           DO iq = 1, nqtot 
             IF(.NOT.(tracers(iq)%isAdvected .AND. tracers(iq)%isInPhysics)) CYCLE
@@ -503,9 +544,74 @@
             lnam = 'Cumulated tracer '//TRIM(tracers(iq)%longName)
             tnam = 'cum'//TRIM(tracers(iq)%name); o_trac_cum(itr) = ctrl_out(flag, tnam, lnam, "-", [('',i=1,nfiles)])
-          ENDDO
+            
+#ifdef CPP_StratAer
+            if(tracers(iq)%name(1:3)=='BIN') then
+               itrb = itrb + 1
+               flag = [11, 11, 11, 11, 11, 11, 11, 11, 11, 1]
+               lnam = 'Dry particle concentration in '//TRIM(tracers(iq)%longName)
+               tnam = TRIM(tracers(iq)%name)//'_nd_mode';     o_nd_mode       (itrb) = ctrl_out(flag, tnam, lnam, "part/m3", [('',i=1,nfiles)])
+               lnam = 'Sulfate MMR in '//TRIM(tracers(iq)%longName)
+               tnam = TRIM(tracers(iq)%name)//'_sulfmmr_mode';o_sulfmmr_mode  (itrb) = ctrl_out(flag, tnam, lnam, "kg(H2SO4)/kg(air)", [('',i=1,nfiles)])
+            endif
+#endif
+         ENDDO
 
    ENDDO !  iff
 
-    ! Updated write frequencies due to phys_out_filetimesteps. 
+#ifdef ISO
+    write(*,*) 'phys_output_mid 589'
+    do ixt=1,ntraciso
+      outiso = TRIM(isoName(ixt))
+      i = INDEX(outiso, '_', .TRUE.)
+      outiso = outiso(1:i-1)//outiso(i+1:LEN_TRIM(outiso))
+
+      flag = [1,  1,  1, 10,  5, 10, 11, 11, 11, 11]; unit = 'kg/(s*m2)'
+      o_xtprecip(ixt)=ctrl_out(flag, 'precip'//TRIM(outiso), 'Precip Totale liq+sol', unit, [('',i=1,nfiles)])
+      o_xtpluc  (ixt)=ctrl_out(flag,   'pluc'//TRIM(outiso),    'Convective Precip.', unit, [('',i=1,nfiles)])
+
+      flag = [1,  1,  1, 10, 10, 10, 11, 11, 11, 11]
+      o_xtplul  (ixt)=ctrl_out(flag,   'plul'//TRIM(outiso),   'Large-scale Precip.', unit, [('',i=1,nfiles)])
+      o_xtevap  (ixt)=ctrl_out(flag,   'evap'//TRIM(outiso),             'Evaporat.', unit, [('',i=1,nfiles)])
+
+      ! ajout Camille 8 mai 2023
+      flag = [1, 6, 10, 10, 10, 10, 11, 11, 11, 11]
+      o_xtevap_srf (ixt,1)=ctrl_out(flag,   'evap_ter'//TRIM(outiso), 'Evap sfc'//clnsurf(1), unit, [('',i=1,nfiles)])
+      o_xtevap_srf (ixt,2)=ctrl_out(flag,   'evap_lic'//TRIM(outiso), 'Evap sfc'//clnsurf(2), unit, [('',i=1,nfiles)])
+      o_xtevap_srf (ixt,3)=ctrl_out(flag,   'evap_oce'//TRIM(outiso), 'Evap sfc'//clnsurf(3), unit, [('',i=1,nfiles)])
+      o_xtevap_srf (ixt,4)=ctrl_out(flag,   'evap_sic'//TRIM(outiso), 'Evap sfc'//clnsurf(4), unit, [('',i=1,nfiles)])
+
+      flag = [2,  3,  4, 10, 10, 10, 11, 11, 11, 11]; unit = 'kg/kg'
+      o_xtovap  (ixt)=ctrl_out(flag,   'ovap'//TRIM(outiso),     'Specific humidity', unit, [('',i=1,nfiles)])
+      o_xtoliq  (ixt)=ctrl_out(flag,   'oliq'//TRIM(outiso),          'Liquid water', unit, [('',i=1,nfiles)])
+      o_xtcond  (ixt)=ctrl_out(flag,  'ocond'//TRIM(outiso),       'Condensed water', unit, [('',i=1,nfiles)])
+
+      flag = [1,  1,  1, 10, 5, 10, 11, 11, 11, 11]; unit = 'kg/m2/s'
+      o_xtrunoff_diag  (ixt)=ctrl_out(flag, 'runoffland'//TRIM(outiso), 'Run-off rate land for bucket', unit, [('',i=1,nfiles)])
+
+      flag = [4, 10, 10, 10, 10, 10, 11, 11, 11, 11]; unit = '(kg/kg)/s'
+      o_dxtdyn  (ixt)=ctrl_out(flag,  'dqdyn'//TRIM(outiso),           'Dynamics dQ', unit, [('',i=1,nfiles)])
+      o_dxtldyn (ixt)=ctrl_out(flag, 'dqldyn'//TRIM(outiso),          'Dynamics dQL', unit, [('',i=1,nfiles)])
+      o_dxtcon  (ixt)=ctrl_out(flag,  'dqcon'//TRIM(outiso),         'Convection dQ', unit, [('',i=1,nfiles)])
+      o_dxteva  (ixt)=ctrl_out(flag,  'dqeva'//TRIM(outiso),      'Reevaporation dQ', unit, [('',i=1,nfiles)])
+      o_dxtlsc  (ixt)=ctrl_out(flag,  'dqlsc'//TRIM(outiso),       'Condensation dQ', unit, [('',i=1,nfiles)])
+      o_dxtajs  (ixt)=ctrl_out(flag,  'dqajs'//TRIM(outiso),        'Dry adjust. dQ', unit, [('',i=1,nfiles)])
+      o_dxtvdf  (ixt)=ctrl_out(flag,  'dqvdf'//TRIM(outiso),     'Boundary-layer dQ', unit, [('',i=1,nfiles)])
+      o_dxtthe  (ixt)=ctrl_out(flag,  'dqthe'//TRIM(outiso),            'Thermal dQ', unit, [('',i=1,nfiles)])
+
+      IF(ok_qch4) o_dxtch4(ixt)=ctrl_out(flag, 'dqch4'//TRIM(outiso), 'H2O due to CH4 oxidation & photolysis', &
+                                                                                      unit, [('',i=1,nfiles)])
+      IF(ixt == iso_HTO) THEN
+      o_dxtprod_nucl(ixt)=ctrl_out(flag, 'dqprodnucl'//TRIM(outiso), 'dHTO/dt due to nuclear production',      &
+                                                                                      unit, [('',i=1,nfiles)])
+      o_dxtcosmo    (ixt)=ctrl_out(flag,    'dqcosmo'//TRIM(outiso), 'dHTO/dt due to cosmogenic production',   &
+                                                                                      unit, [('',i=1,nfiles)])
+      o_dxtdecroiss (ixt)=ctrl_out(flag, 'dqdecroiss'//TRIM(outiso), 'dHTO/dt due to radiative destruction',   &
+                                                                                      unit, [('',i=1,nfiles)])
+      END IF
+    enddo !do ixt=1,niso
+    write(*,*) 'phys_output_mid 596'
+#endif
+
+   ! Updated write frequencies due to phys_out_filetimesteps. 
     ! Write frequencies are now in seconds.  
     ecrit_mth = ecrit_files(1)
Index: LMDZ6/branches/cirrus/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/phys_output_write_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/phys_output_write_mod.F90	(revision 5202)
@@ -65,5 +65,6 @@
          o_fder, o_ffonte, o_fqcalving, o_fqfonte, o_mrroli, o_runofflic, &
          o_taux, o_tauy, o_snowsrf, o_qsnow, &
-         o_snowhgt, o_toice, o_sissnow, o_runoff, &
+! SN runoff_diag
+         o_snowhgt, o_toice, o_sissnow, o_runoff, o_runoff_diag, &
          o_albslw3, o_pourc_srf, o_fract_srf, &
          o_taux_srf, o_tauy_srf, o_tsol_srf, &
@@ -141,5 +142,5 @@
          o_zfull, o_zhalf, o_rneb, o_rnebjn, o_rnebcon, &
          o_rnebls, o_rneblsvol, o_rhum, o_rhl, o_rhi, o_ozone, o_ozone_light, &
-         o_pfraclr, o_pfracld, &
+         o_pfraclr, o_pfracld, o_cldfraliq, o_sigma2_icefracturb, o_mean_icefracturb,  &
          o_qrainlsc, o_qsnowlsc, o_dqreva, o_dqrauto, o_dqrcol, o_dqrmelt, o_dqrfreez, &
          o_dqssub, o_dqsauto, o_dqsagg, o_dqsrim, o_dqsmelt, o_dqsfreez, &
@@ -147,5 +148,5 @@
          o_dqsphy, o_dqsphy2d, o_dqbsphy, o_dqbsphy2d, o_albe_srf, o_z0m_srf, o_z0h_srf, &
          o_ages_srf, o_snow_srf, o_alb1, o_alb2, o_tke, o_tke_dissip, &
-         o_tke_max, o_kz, o_kz_max, o_clwcon, &
+         o_tke_max, o_kz, o_kz_max, o_clwcon, o_tke_shear, o_tke_buoy, o_tke_trans,  &
          o_dtdyn, o_dqdyn, o_dqdyn2d, o_dqldyn, o_dqldyn2d, & 
          o_dqsdyn, o_dqsdyn2d, o_dqbsdyn, o_dqbsdyn2d, o_dudyn, o_dvdyn, &
@@ -208,4 +209,5 @@
 ! Isotopes
          o_xtprecip,o_xtplul,o_xtpluc,o_xtovap,o_xtoliq,o_xtcond, &
+         o_xtrunoff_diag, &
          o_xtevap,o_dxtdyn,o_dxtldyn,o_dxtcon,o_dxtlsc,o_dxteva, &
          o_dxtajs,o_dxtvdf,o_dxtthe, o_dxtch4, &
@@ -248,4 +250,5 @@
 
 #ifdef CPP_StratAer
+    USE infotrac_phy, ONLY: nbtr_bin
     USE phys_output_ctrlout_mod, ONLY:  & 
          o_budg_3D_nucl, o_budg_3D_cond_evap, o_budg_3D_ocs_to_so2, o_budg_3D_so2_to_h2so4, &
@@ -259,5 +262,6 @@
          o_budg_ocs_to_so2, o_budg_so2_to_h2so4, o_budg_h2so4_to_part, &
          o_surf_PM25_sulf, o_ext_strat_550, o_tau_strat_550, &
-         o_vsed_aer, o_tau_strat_1020, o_ext_strat_1020, o_f_r_wet
+         o_vsed_aer, o_tau_strat_1020, o_ext_strat_1020, o_f_r_wet, &
+         o_SAD_sulfate, o_reff_sulfate, o_sulfmmr, o_nd_mode, o_sulfmmr_mode
 #endif
 
@@ -314,10 +318,11 @@
          zn2mout, t2m_min_mon, t2m_max_mon, evap, &
          snowerosion, zxustartlic, zxrhoslic, zxqsaltlic, &
-         l_mixmin,l_mix, pbl_eps, &
+         l_mixmin,l_mix, pbl_eps, tke_shear, tke_buoy, tke_trans, &
          zu10m, zv10m, zq2m, zustar, zxqsurf, &
          rain_lsc, rain_num, snow_lsc, bils, sens, fder, &
          zxffonte, zxfqcalving, zxfqfonte, zxrunofflic, fluxu, &
          fluxv, zxsnow, qsnow, snowhgt, to_ice, &
-         sissnow, runoff, albsol3_lic, evap_pot, &
+! SN runoff_diag
+         sissnow, runoff, runoff_diag, albsol3_lic, evap_pot, &
          t2m, fluxt, fluxlat, fsollw, fsolsw, &
          wfbils, wfevap, &
@@ -367,6 +372,7 @@
          ql_seri, qs_seri, qbs_seri, tr_seri, qbs_seri,&
          zphi, u_seri, v_seri, omega, cldfra, &
-         rneb, rnebjn, rneblsvol, zx_rh, zx_rhl, zx_rhi, &
-         pfraclr, pfracld,  &
+         rneb, rnebjn, rneblsvol,  &
+         zx_rh, zx_rhl, zx_rhi, &
+         pfraclr, pfracld, cldfraliq, sigma2_icefracturb, mean_icefracturb, &
          qraindiag, qsnowdiag, dqreva, dqssub, &
          dqrauto,dqrcol,dqrmelt,dqrfreez, &
@@ -382,5 +388,5 @@
          d_t_lscst, d_q_lscth, d_q_lscst, plul_th, &
          plul_st, d_t_vdf, d_t_diss, d_q_vdf, d_q_eva, &
-         d_t_bs, d_q_bs, d_qbs_bs, d_qbs_vdf, &
+         d_t_bsss, d_q_bsss, d_qbs_bsss, d_qbs_vdf, &
          zw2, fraca, zmax_th, d_q_ajsb, d_t_ec, d_u_vdf, &
          d_v_vdf, d_u_oro, d_v_oro, d_t_oro, d_u_lif, &
@@ -395,4 +401,5 @@
         d_xt_ajs, d_xt_ajsb, &
         d_xt_prod_nucl,d_xt_cosmo,d_xt_decroiss, &
+        xtrunoff_diag, &
 #endif
          ep, epmax_diag, &  ! epmax_cape
@@ -416,5 +423,6 @@
          budg_ocs_to_so2, budg_so2_to_h2so4, budg_h2so4_to_part, & 
          surf_PM25_sulf, tau_strat_550, tausum_strat, &
-         vsed_aer, tau_strat_1020, f_r_wet
+         vsed_aer, tau_strat_1020, f_r_wet, &
+         SAD_sulfate, reff_sulfate, sulfmmr, nd_mode, sulfmmr_mode
 #endif
 
@@ -449,5 +457,5 @@
     USE indice_sol_mod, ONLY: nbsrf
 #ifdef ISO
-    USE isotopes_mod, ONLY: iso_HTO
+    USE isotopes_mod, ONLY: iso_HTO, isoName
 #endif
     USE geometry_mod, ONLY: cell_area, latitude_deg, longitude_deg
@@ -530,4 +538,9 @@
     CHARACTER(LEN=maxlen) :: unt
 #endif
+
+#ifdef ISO
+    CHARACTER(LEN=maxlen) :: outiso
+#endif
+
     REAL,DIMENSION(klon,klev) :: z, dz
     REAL,DIMENSION(klon)      :: zrho, zt
@@ -1310,6 +1323,6 @@
 
        ENDDO
-       
-                
+
+
         IF (iflag_pbl > 1) THEN
           zx_tmp_fi3d=0.
@@ -1323,5 +1336,43 @@
           ENDIF
           
-          CALL histwrite_phy(o_tke_dissip, zx_tmp_fi3d)    
+          CALL histwrite_phy(o_tke_dissip, zx_tmp_fi3d)   
+
+          zx_tmp_fi3d=0.
+          IF (vars_defined) THEN
+             DO nsrf=1,nbsrf
+                DO k=1,klev
+                   zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k) &
+                        +pctsrf(:,nsrf)*tke_shear(:,k,nsrf)
+                ENDDO
+             ENDDO
+          ENDIF
+
+          CALL histwrite_phy(o_tke_shear, zx_tmp_fi3d)
+
+          zx_tmp_fi3d=0.
+          IF (vars_defined) THEN
+             DO nsrf=1,nbsrf
+                DO k=1,klev
+                   zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k) &
+                        +pctsrf(:,nsrf)*tke_buoy(:,k,nsrf)
+                ENDDO
+             ENDDO
+          ENDIF
+
+          CALL histwrite_phy(o_tke_buoy, zx_tmp_fi3d)
+
+
+          zx_tmp_fi3d=0.
+          IF (vars_defined) THEN
+             DO nsrf=1,nbsrf
+                DO k=1,klev
+                   zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k) &
+                        +pctsrf(:,nsrf)*tke_trans(:,k,nsrf)
+                ENDDO
+             ENDDO
+          ENDIF
+
+          CALL histwrite_phy(o_tke_trans, zx_tmp_fi3d)
+
        ENDIF
 
@@ -1814,4 +1865,12 @@
           CALL histwrite_phy(o_tau_strat_550, tausum_strat(:,1))
           CALL histwrite_phy(o_tau_strat_1020, tausum_strat(:,2))
+          CALL histwrite_phy(o_SAD_sulfate, SAD_sulfate)
+          CALL histwrite_phy(o_reff_sulfate, reff_sulfate)
+          CALL histwrite_phy(o_sulfmmr, sulfmmr)
+          ! All BINs fields
+          DO itr = 1, nbtr_bin
+             CALL histwrite_phy(o_nd_mode(itr), nd_mode(:,:,itr))
+             CALL histwrite_phy(o_sulfmmr_mode(itr), sulfmmr_mode(:,:,itr))
+          ENDDO !--itr
        ENDIF
 #endif
@@ -2005,4 +2064,7 @@
            CALL histwrite_phy(o_pfraclr, pfraclr)
            CALL histwrite_phy(o_pfracld, pfracld)
+           CALL histwrite_phy(o_cldfraliq, cldfraliq)
+           CALL histwrite_phy(o_sigma2_icefracturb, sigma2_icefracturb)
+           CALL histwrite_phy(o_mean_icefracturb, mean_icefracturb)
            IF (ok_poprecip) THEN
            CALL histwrite_phy(o_qrainlsc, qraindiag)
@@ -2306,9 +2368,9 @@
           IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_qbs_vdf(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dqbsvdf, zx_tmp_fi3d)
-          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_qbs_bs(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_qbs_bsss(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dqbsbs, zx_tmp_fi3d)
-          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_bs(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_bsss(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dqbs, zx_tmp_fi3d)
-          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_bs(1:klon,1:klev)/pdtphys
+          IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_bsss(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dtbs, zx_tmp_fi3d)
        ENDIF
@@ -2810,7 +2872,12 @@
        end if
 
+    !! runoff land bucket - ajout S. Nguyen 23 07 2024
+    CALL histwrite_phy(o_runoff_diag, runoff_diag)
+
 #ifdef ISO
-    do ixt=1,ntiso
-!        write(*,*) 'ixt'
+    !write(*,*) 'tmp phys_output_write: ntiso=',ntiso
+
+    DO ixt = 1, ntiso
+        !write(*,*) 'ixt,o_xtovap(ixt)=',ixt,o_xtovap(ixt)
         IF (vars_defined) zx_tmp_fi2d(:) = xtrain_fall(ixt,:) + xtsnow_fall(ixt,:)
         CALL histwrite_phy(o_xtprecip(ixt), zx_tmp_fi2d)
@@ -2824,4 +2891,8 @@
         CALL histwrite_phy(o_xtovap(ixt),  xt_seri(ixt,:,:))
         CALL histwrite_phy(o_xtoliq(ixt), xtl_seri(ixt,:,:))
+
+        !! runoff land bucket - ajout S. Nguyen 25 avril 2024
+        CALL histwrite_phy(o_xtrunoff_diag(ixt), xtrunoff_diag(ixt,:))
+
 
         DO nsrf = 1, nbsrf ! ajout Camille 8 mai 2023
@@ -2884,4 +2955,17 @@
           ENDDO !  iff
 #endif
+
+!SN activate water isotopes present in tracer.def
+#ifdef ISO
+          DO ixt = 1, ntiso
+            outiso = TRIM(isoName(ixt))
+            i = INDEX(outiso, '_', .TRUE.)
+            outiso = outiso(1:i-1)//outiso(i+1:LEN_TRIM(outiso))
+
+            CALL xios_set_fieldgroup_attr("iso2D_"//TRIM(outiso), enabled=.TRUE.)
+            CALL xios_set_fieldgroup_attr("iso3D_"//TRIM(outiso), enabled=.TRUE.)
+
+          ENDDO
+#endif
           !On finalise l'initialisation:
           IF (using_xios) CALL wxios_closedef()
Index: LMDZ6/branches/cirrus/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/phys_state_var_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/phys_state_var_mod.F90	(revision 5202)
@@ -87,6 +87,7 @@
 !$OMP THREADPRIVATE(prw_ancien, prlw_ancien, prsw_ancien, prbsw_ancien)
 #ifdef ISO
-      REAL, ALLOCATABLE, SAVE :: xt_ancien(:,:,:),xtl_ancien(:,:,:),xts_ancien(:,:,:)
-!$OMP THREADPRIVATE(xt_ancien,xtl_ancien,xts_ancien)
+      REAL, ALLOCATABLE, SAVE :: xt_ancien(:,:,:),xtl_ancien(:,:,:),xts_ancien(:,:,:), &
+              xtbs_ancien(:,:,:)
+!$OMP THREADPRIVATE(xt_ancien,xtl_ancien,xts_ancien,xtbs_ancien)
 #endif
       REAL, ALLOCATABLE, SAVE :: u_ancien(:,:), v_ancien(:,:)
@@ -760,4 +761,5 @@
       ALLOCATE(xtl_ancien(ntraciso,klon,klev))
       ALLOCATE(xts_ancien(ntraciso,klon,klev))
+      ALLOCATE(xtbs_ancien(ntraciso,klon,klev))
       ALLOCATE(xtrain_fall(ntraciso,klon))
       ALLOCATE(xtsnow_fall(ntraciso,klon))
@@ -950,5 +952,5 @@
 #ifdef ISO    
       DEALLOCATE(xtsol,fxtevap)  
-      DEALLOCATE(xt_ancien,xtl_ancien,xts_ancien, fxtd, wake_deltaxt)
+      DEALLOCATE(xt_ancien,xtl_ancien,xts_ancien,xtbs_ancien, fxtd, wake_deltaxt)
       DEALLOCATE(xtrain_fall, xtsnow_fall, xtrain_con, xtsnow_con)
 #ifdef ISOTRAC 
Index: LMDZ6/branches/cirrus/libf/phylmd/physiq_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/physiq_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/physiq_mod.F90	(revision 5202)
@@ -1,3 +1,3 @@
-!
+
 ! $Id$
 !
@@ -184,5 +184,5 @@
        d_ts, &
        !
-       d_t_bs,d_q_bs,d_qbs_bs, &
+       d_t_bsss,d_q_bsss,d_qbs_bsss, &
        !
 !       d_t_oli,d_u_oli,d_v_oli, &
@@ -333,6 +333,6 @@
        !
        rneblsvol, &
-       pfraclr,pfracld, &
-       distcltop,temp_cltop, &
+       pfraclr, pfracld, cldfraliq, sigma2_icefracturb, mean_icefracturb,  &
+       distcltop, temp_cltop,  &
        !-- LSCP - condensation and ice supersaturation variables
        qsub, qissr, qcld, subfra, issrfra, gamma_cond, ratio_qi_qtot, &
@@ -909,5 +909,4 @@
     REAL zdtime, zdtime1, zdtime2, zlongi
     !
-    REAL qcheck
     REAL z_avant(klon), z_apres(klon), z_factor(klon)
     LOGICAL zx_ajustq
@@ -1133,4 +1132,5 @@
     REAL, DIMENSION(klon,klev)     :: mass_solu_aero_pi
     ! - " - (pre-industrial value)
+    REAL, DIMENSION(klon,klev,naero_tot) :: m_allaer
 
     ! Parameters
@@ -1271,5 +1271,4 @@
 
     !--OB variables for mass fixer (hard coded for now)
-    LOGICAL, PARAMETER :: mass_fixer=.FALSE.
     REAL qql1(klon),qql2(klon),corrqql
 
@@ -1401,15 +1400,4 @@
        IF (read_climoz>=1 .AND. create_etat0_limit .AND. grid_type==unstructured) & 
           CALL regr_horiz_time_climoz(read_climoz,ok_daily_climoz)
-
-#ifdef REPROBUS
-       CALL strataer_init
-       CALL strataer_emiss_init
-#endif
-
-#ifdef CPP_StratAer
-       CALL strataer_init
-       CALL strataer_nuc_init
-       CALL strataer_emiss_init
-#endif
 
        print*, '================================================='
@@ -1527,4 +1515,7 @@
        iflag_phytrac = 1 ! by default we do want to call phytrac
        CALL getin_p('iflag_phytrac',iflag_phytrac)
+
+       ok_water_mass_fixer=.FALSE.  ! OB: by default we do not apply the mass fixer
+       CALL getin_p('ok_water_mass_fixer',ok_water_mass_fixer)
 #ifdef CPP_Dust
        IF (iflag_phytrac.EQ.0) THEN 
@@ -1551,4 +1542,5 @@
        WRITE(lunout,*) 'fl_cor_ebil=',        fl_cor_ebil
        WRITE(lunout,*) 'iflag_phytrac=',      iflag_phytrac
+       WRITE(lunout,*) 'ok_water_mass_fixer=',ok_water_mass_fixer
        WRITE(lunout,*) 'NVM=',                nvm_lmdz
 
@@ -1802,7 +1794,8 @@
       IF (.NOT. create_etat0_limit) CALL init_readaerosolstrato(flag_aerosol_strat)  !! initialise aero strato from file for XIOS interpolation (unstructured_grid)
 
+      ! A.I : Initialisations pour le 1er passage a Cosp
       if (ok_cosp) then
+
 #ifdef CPP_COSP
-        ! A.I : Initialisations pour le 1er passage a Cosp
         CALL ini_COSP(ref_liq_cosp0,ref_ice_cosp0,pctsrf_cosp0,zu10m_cosp0,zv10m_cosp0, &
                zxtsol_cosp0,zx_rh_cosp0,cldfra_cosp0,rnebcon_cosp0,flwc_cosp0, &
@@ -1824,39 +1817,24 @@
 #endif
 
-#ifdef CPP_COSP2
-        CALL ini_COSP(ref_liq_cosp0,ref_ice_cosp0,pctsrf_cosp0,zu10m_cosp0,zv10m_cosp0, &
+#ifdef CPP_COSPV2
+          CALL ini_COSP(ref_liq_cosp0,ref_ice_cosp0,pctsrf_cosp0,zu10m_cosp0,zv10m_cosp0, &
                zxtsol_cosp0,zx_rh_cosp0,cldfra_cosp0,rnebcon_cosp0,flwc_cosp0, &
                fiwc_cosp0,prfl_cosp0,psfl_cosp0,pmflxr_cosp0,pmflxs_cosp0, &
                mr_ozone_cosp0,cldtau_cosp0,cldemi_cosp0,JrNt_cosp0)
-     
-        CALL phys_cosp2(itap,phys_tstep,freq_cosp, &
-               ok_mensuelCOSP,ok_journeCOSP,ok_hfCOSP, &
-               ecrit_mth,ecrit_day,ecrit_hf, ok_all_xml, missing_val, &
-               klon,klev,longitude_deg,latitude_deg,presnivs,overlap, &
-               JrNt,ref_liq,ref_ice, &
-               pctsrf(:,is_ter)+pctsrf(:,is_lic), &
-               zu10m,zv10m,pphis, &
-               zphi,paprs(:,1:klev),pplay,zxtsol,t_seri, &
-               qx(:,:,ivap),zx_rh,cldfra,rnebcon,flwc,fiwc, &
-               prfl(:,1:klev),psfl(:,1:klev), &
-               pmflxr(:,1:klev),pmflxs(:,1:klev), &
-               mr_ozone,cldtau, cldemi)
-#endif
-
-#ifdef CPP_COSPV2
+
           CALL lmdz_cosp_interface(itap,phys_tstep,freq_cosp, &
                ok_mensuelCOSP,ok_journeCOSP,ok_hfCOSP, &
                ecrit_mth,ecrit_day,ecrit_hf, ok_all_xml, missing_val, &
                klon,klev,longitude_deg,latitude_deg,presnivs,overlap, &
-               JrNt,ref_liq,ref_ice, &
-               pctsrf(:,is_ter)+pctsrf(:,is_lic), &
-               zu10m,zv10m,pphis, &
-               phicosp,paprs(:,1:klev),pplay,zxtsol,t_seri, &
-               qx(:,:,ivap),zx_rh,cldfra,rnebcon,flwc,fiwc, &
-               prfl(:,1:klev),psfl(:,1:klev), &
-               pmflxr(:,1:klev),pmflxs(:,1:klev), &
-               mr_ozone,cldtau, cldemi)
+               JrNt_cosp0,ref_liq_cosp0,ref_ice_cosp0, &
+               pctsrf_cosp0, &
+               zu10m_cosp0,zv10m_cosp0,pphis, &
+               pphi,paprs(:,1:klev),pplay,zxtsol_cosp0,t, &
+               qx(:,:,ivap),zx_rh_cosp0,cldfra_cosp0,rnebcon_cosp0,flwc_cosp0,fiwc_cosp0, &
+               prfl_cosp0(:,1:klev),psfl_cosp0(:,1:klev), &
+               pmflxr_cosp0(:,1:klev),pmflxs_cosp0(:,1:klev), &
+               mr_ozone_cosp0,cldtau_cosp0, cldemi_cosp0)
 #endif
-      ENDIF 
+      endif  ! ok_cosp
 
        !
@@ -1908,4 +1886,14 @@
        !
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#ifdef REPROBUS
+       CALL strataer_init
+       CALL strataer_emiss_init
+#endif
+
+#ifdef CPP_StratAer
+       CALL strataer_init
+       CALL strataer_nuc_init
+       CALL strataer_emiss_init
+#endif
 
 #ifdef CPP_Dust
@@ -1948,8 +1936,11 @@
        ELSE IF (klon_glo==1) THEN
           pbl_tke(:,:,is_ave) = 0.
+          pbl_eps(:,:,is_ave) = 0.
           DO nsrf=1,nbsrf
             DO k = 1,klev+1
                  pbl_tke(:,k,is_ave) = pbl_tke(:,k,is_ave) &
                      +pctsrf(:,nsrf)*pbl_tke(:,k,nsrf)
+                 pbl_eps(:,k,is_ave) = pbl_eps(:,k,is_ave) &
+                     +pctsrf(:,nsrf)*pbl_eps(:,k,nsrf)
             ENDDO
           ENDDO
@@ -1957,4 +1948,5 @@
           pbl_tke(:,:,is_ave) = 0. !ym missing init : maybe must be initialized in the same way that for klon_glo==1 ??
 !>jyg
+          pbl_eps(:,:,is_ave) = 0.
        ENDIF
        !IM begin
@@ -2470,6 +2462,6 @@
     ENDDO
     !
-    !--OB mass fixer 
-    IF (mass_fixer) THEN
+    !--OB water mass fixer 
+    IF (ok_water_mass_fixer) THEN
     !--store initial water burden
     qql1(:)=0.0
@@ -3024,7 +3016,7 @@
     ! Blowing snow sublimation and sedimentation
 
-    d_t_bs(:,:)=0.
-    d_q_bs(:,:)=0.
-    d_qbs_bs(:,:)=0.
+    d_t_bsss(:,:)=0.
+    d_q_bsss(:,:)=0.
+    d_qbs_bsss(:,:)=0.
     bsfl(:,:)=0.
     bs_fall(:)=0.
@@ -3032,9 +3024,9 @@
 
      CALL call_blowing_snow_sublim_sedim(klon,klev,phys_tstep,t_seri,q_seri,qbs_seri,pplay,paprs, &
-                                        d_t_bs,d_q_bs,d_qbs_bs,bsfl,bs_fall)
+                                        d_t_bsss,d_q_bsss,d_qbs_bsss,bsfl,bs_fall)
 
      CALL add_phys_tend &
-               (du0,dv0,d_t_bs,d_q_bs,dql0,dqi0,d_qbs_bs,paprs,&
-               'bs',abortphy,flag_inhib_tend,itap,0)
+               (du0,dv0,d_t_bsss,d_q_bsss,dql0,dqi0,d_qbs_bsss,paprs,&
+               'bsss',abortphy,flag_inhib_tend,itap,0)
 
     ENDIF
@@ -3079,21 +3071,4 @@
        ENDDO
     ENDDO
-    IF (check) THEN
-       za = qcheck(klon,klev,paprs,q_seri,ql_seri,cell_area)
-       WRITE(lunout,*) "avantcon=", za
-    ENDIF
-    zx_ajustq = .FALSE.
-    IF (iflag_con.EQ.2) zx_ajustq=.TRUE.
-    IF (zx_ajustq) THEN
-       DO i = 1, klon
-          z_avant(i) = 0.0
-       ENDDO
-       DO k = 1, klev
-          DO i = 1, klon
-             z_avant(i) = z_avant(i) + (q_seri(i,k)+ql_seri(i,k)) &
-                  *(paprs(i,k)-paprs(i,k+1))/RG
-          ENDDO
-       ENDDO
-    ENDIF
 
     ! Calcule de vitesse verticale a partir de flux de masse verticale
@@ -3488,42 +3463,4 @@
        CALL writefield_phy('q_seri',q_seri,nbp_lev)
     ENDIF
-
-    IF (check) THEN
-       za = qcheck(klon,klev,paprs,q_seri,ql_seri,cell_area)
-       WRITE(lunout,*)"aprescon=", za
-       zx_t = 0.0
-       za = 0.0
-       DO i = 1, klon
-          za = za + cell_area(i)/REAL(klon)
-          zx_t = zx_t + (rain_con(i)+ &
-               snow_con(i))*cell_area(i)/REAL(klon)
-       ENDDO
-       zx_t = zx_t/za*phys_tstep
-       WRITE(lunout,*)"Precip=", zx_t
-    ENDIF
-    IF (zx_ajustq) THEN
-       DO i = 1, klon
-          z_apres(i) = 0.0
-       ENDDO
-       DO k = 1, klev
-          DO i = 1, klon
-             z_apres(i) = z_apres(i) + (q_seri(i,k)+ql_seri(i,k)) &
-                  *(paprs(i,k)-paprs(i,k+1))/RG
-          ENDDO
-       ENDDO
-       DO i = 1, klon
-          z_factor(i) = (z_avant(i)-(rain_con(i)+snow_con(i))*phys_tstep) &
-               /z_apres(i)
-       ENDDO
-       DO k = 1, klev
-          DO i = 1, klon
-             IF (z_factor(i).GT.(1.0+1.0E-08) .OR. &
-                  z_factor(i).LT.(1.0-1.0E-08)) THEN
-                q_seri(i,k) = q_seri(i,k) * z_factor(i)
-             ENDIF
-          ENDDO
-       ENDDO
-    ENDIF
-    zx_ajustq=.FALSE.
 
     !
@@ -3921,13 +3858,15 @@
 
     CALL lscp(klon,klev,phys_tstep,missing_val,paprs,pplay, &
-         t_seri, q_seri,ptconv,ratqs, &
+         t_seri, q_seri,qs_ancien,ptconv,ratqs, &
          d_t_lsc, d_q_lsc, d_ql_lsc, d_qi_lsc, rneb, rneblsvol, & 
-         pfraclr,pfracld, &
+         pfraclr, pfracld, cldfraliq, sigma2_icefracturb, mean_icefracturb,  &
          radocond, picefra, rain_lsc, snow_lsc, &
          frac_impa, frac_nucl, beta_prec_fisrt, &
          prfl, psfl, rhcl,  &
          zqasc, fraca,ztv,zpspsk,ztla,zthl,iflag_cld_th, &
-         iflag_ice_thermo, distcltop, temp_cltop, cell_area, &
-         cf_seri, rvc_seri, u_seri, v_seri, pbl_eps(:,:,is_ave), &
+         iflag_ice_thermo, distcltop, temp_cltop,   &
+         pbl_tke(:,:,is_ave), pbl_eps(:,:,is_ave), &
+         cell_area, &
+         cf_seri, rvc_seri, u_seri, v_seri, &
          qsub, qissr, qcld, subfra, issrfra, gamma_cond, ratio_qi_qtot, &
          dcf_sub, dcf_con, dcf_mix, dqi_adj, dqi_sub, dqi_con, dqi_mix, &
@@ -4021,18 +3960,4 @@
        ENDIF
 
-    ENDIF
-
-    IF (check) THEN
-       za = qcheck(klon,klev,paprs,q_seri,ql_seri,cell_area)
-       WRITE(lunout,*)"apresilp=", za
-       zx_t = 0.0
-       za = 0.0
-       DO i = 1, klon
-          za = za + cell_area(i)/REAL(klon)
-          zx_t = zx_t + (rain_lsc(i) &
-               + snow_lsc(i))*cell_area(i)/REAL(klon)
-       ENDDO
-       zx_t = zx_t/za*phys_tstep
-       WRITE(lunout,*)"Precip=", zx_t
     ENDIF
 
@@ -4405,5 +4330,5 @@
                   flag_aerosol, flag_bc_internal_mixture, itap, jD_cur-jD_ref, &
                   pdtphys, pplay, paprs, t_seri, rhcl, presnivs,  &
-                  tr_seri, mass_solu_aero, mass_solu_aero_pi)  
+                  tr_seri, mass_solu_aero, mass_solu_aero_pi, m_allaer)  
 #else
                 abort_message='You should compile with -rad ecrad if running with iflag_rrtm=2'
@@ -4651,5 +4576,5 @@
                ! Rajoute par OB pour RRTM
                tau_aero_lw_rrtm, & 
-               cldtaupirad, &
+               cldtaupirad, m_allaer, &
 !              zqsat, flwcrad, fiwcrad, &
                zqsat, flwc, fiwc, &
@@ -4729,5 +4654,5 @@
                                 ! Rajoute par OB pour RRTM
                      tau_aero_lw_rrtm, &
-                     cldtaupi, &
+                     cldtaupi, m_allaer, &
 !                    zqsat, flwcrad, fiwcrad, &
                      zqsat, flwc, fiwc, &
@@ -4775,5 +4700,5 @@
                      tau_aero_sw_rrtm, piz_aero_sw_rrtm, cg_aero_sw_rrtm, &
                      tau_aero_lw_rrtm, &
-                     cldtaupi, &
+                     cldtaupi, m_allaer, &
                      zqsat, flwc, fiwc, &
                      ref_liq, ref_ice, ref_liq_pi, ref_ice_pi, &
@@ -5508,5 +5433,5 @@
     !--currently flag is turned off
     !==================================================================
-    IF (mass_fixer) THEN
+    IF (ok_water_mass_fixer) THEN
     qql2(:)=0.0
     DO k = 1, klev
Index: LMDZ6/branches/cirrus/libf/phylmd/phystokenc_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/phystokenc_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/phystokenc_mod.F90	(revision 5202)
@@ -46,4 +46,6 @@
 ! Objet: Ecriture des variables pour transport offline
 !
+!  Note (A Cozic - July 2024): when coupled with inca, offline fields are no 
+!  longer calculated in this routine but directly in the physics code.
 !======================================================================
 
Index: LMDZ6/branches/cirrus/libf/phylmd/radlwsw_m.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/radlwsw_m.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/radlwsw_m.F90	(revision 5202)
@@ -21,5 +21,5 @@
        tau_aero_sw_rrtm, piz_aero_sw_rrtm, cg_aero_sw_rrtm,& ! rajoute par OB RRTM
        tau_aero_lw_rrtm, &              ! rajoute par C.Kleinschmitt pour RRTM
-       cldtaupi, &
+       cldtaupi, m_allaer, &
        qsat, flwc, fiwc, &
        ref_liq, ref_ice, ref_liq_pi, ref_ice_pi, &
@@ -80,5 +80,4 @@
     ! Besoin pour ECRAD de pctsrf, zmasq, longitude, altitude
 #ifdef CPP_ECRAD
-    USE phys_local_var_mod, ONLY: rhcl, m_allaer
     USE geometry_mod, ONLY: latitude, longitude
     USE phys_state_var_mod, ONLY: pctsrf
@@ -247,4 +246,5 @@
     REAL,    INTENT(in)  :: ref_liq_pi(klon,klev) ! cloud droplet radius pre-industrial from newmicro
     REAL,    INTENT(in)  :: ref_ice_pi(klon,klev) ! ice crystal radius   pre-industrial from newmicro
+    REAL,    INTENT(in)  :: m_allaer(klon,klev,naero_tot) ! mass aero
 
     CHARACTER(len=512), INTENT(in) :: namelist_ecrad_file
@@ -706,4 +706,6 @@
              zsollw0(i)=0.
              zsollwdown(i)=0.
+             ztoplwad0aero(i) = 0.
+             ztoplwadaero(i) = 0.
           ENDDO
           ! Old radiation scheme, used for AR4 runs
Index: LMDZ6/branches/cirrus/libf/phylmd/surf_land_bucket_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/surf_land_bucket_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/surf_land_bucket_mod.F90	(revision 5202)
@@ -16,5 +16,11 @@
        snow, qsol, agesno, tsoil, &
        qsurf, z0_new, alb1_new, alb2_new, evap, &
-       fluxsens, fluxlat, tsurf_new, dflux_s, dflux_l)
+       fluxsens, fluxlat, tsurf_new, dflux_s, dflux_l &
+#ifdef ISO
+       ,xtprecip_rain, xtprecip_snow,xtspechum, &
+       xtsnow, xtsol,xtevap,h1, &
+       runoff_diag,xtrunoff_diag,Rland_ice &
+#endif           
+            )
 
     USE limit_read_mod
@@ -28,4 +34,14 @@
     USE mod_phys_lmdz_para
     USE indice_sol_mod
+#ifdef ISO
+    use infotrac_phy, ONLY: ntiso,niso
+    USE isotopes_mod, ONLY: iso_eau, iso_HDO, iso_O18, iso_O17, &
+        ridicule_qsol
+    USE isotopes_routines_mod, ONLY: calcul_iso_surf_ter_vectall
+#ifdef ISOVERIF
+    USE isotopes_verif_mod, ONLY: errmax,errmaxrel,iso_verif_noNaN, &
+        iso_verif_aberrant_o17,iso_verif_egalite_choix,iso_verif_egalite
+#endif
+#endif
 !****************************************************************************************
 ! Bucket calculations for surface. 
@@ -52,4 +68,8 @@
     REAL, DIMENSION(klon), INTENT(IN)       :: rugoro
     REAL, DIMENSION(klon), INTENT(IN)       :: swnet, lwnet
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(IN) :: xtprecip_rain, xtprecip_snow
+    REAL, DIMENSION(ntiso,klon), INTENT(IN) :: xtspechum    
+#endif
 
 ! In/Output variables
@@ -58,4 +78,7 @@
     REAL, DIMENSION(klon), INTENT(INOUT)          :: agesno
     REAL, DIMENSION(klon, nsoilmx), INTENT(INOUT) :: tsoil
+#ifdef ISO
+    REAL, DIMENSION(niso,klon), INTENT(INOUT)       :: xtsnow,xtsol
+#endif
 
 ! Output variables
@@ -67,4 +90,11 @@
     REAL, DIMENSION(klon), INTENT(OUT)       :: tsurf_new
     REAL, DIMENSION(klon), INTENT(OUT)       :: dflux_s, dflux_l      
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(OUT) :: xtevap
+    REAL, DIMENSION(klon),       INTENT(OUT) :: h1
+    REAL, DIMENSION(niso,klon),  INTENT(OUT) :: xtrunoff_diag
+    REAL, DIMENSION(klon),       INTENT(OUT) :: runoff_diag
+    REAL, DIMENSION(niso,klon),  INTENT(IN)  :: Rland_ice
+#endif
 
 ! Local variables
@@ -78,7 +108,43 @@
     REAL, DIMENSION(klon) :: dummy_riverflow,dummy_coastalflow 
     INTEGER               :: i
-!
-!****************************************************************************************
-
+#ifdef ISO
+    INTEGER               :: ixt
+    REAL, DIMENSION(niso,klon) :: xtsnow_prec,xtsol_prec
+    REAL, DIMENSION(klon) :: snow_prec,qsol_prec
+    REAL, PARAMETER       :: t_coup = 273.15
+    REAL, DIMENSION(klon) :: fq_fonte_diag
+    REAL, DIMENSION(klon) :: fqfonte_diag
+    REAL, DIMENSION(klon) :: snow_evap_diag 
+    REAL, DIMENSION(klon) :: fqcalving_diag 
+    REAL                  :: max_eau_sol_diag  
+    REAL, DIMENSION(klon) :: run_off_lic_diag 
+    REAL :: coeff_rel_diag
+#endif 
+!
+!****************************************************************************************
+
+#ifdef ISO
+#ifdef ISOVERIF
+        !write(*,*) 'surf_land_bucket 152'
+        DO i=1,knon
+          IF (iso_eau > 0) THEN
+            CALL iso_verif_egalite_choix(precip_snow(i), &
+     &                                   xtprecip_snow(iso_eau,i),'surf_land_bucket 131', &
+     &                                   errmax,errmaxrel)
+            CALL iso_verif_egalite_choix(qsol(i), &
+     &                                   xtsol(iso_eau,i),'surf_land_bucket 134', &
+     &                                   errmax,errmaxrel)
+          ENDIF
+        ENDDO
+#endif 
+#ifdef ISOVERIF
+        DO i=1,knon
+          DO ixt=1,niso
+            CALL iso_verif_noNaN(xtsol(ixt,i),'surf_land_mod_bucket 142')
+          ENDDO !do ixt=1,niso
+        ENDDO !do i=1,knon
+        !write(*,*) 'surf_land_bucket 152'
+#endif
+#endif
 
 !
@@ -131,4 +197,41 @@
          tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l)
     
+#ifdef ISO
+   ! verif
+#ifdef ISOVERIF
+    !write(*,*) 'surf_land_bucket 211'
+    DO i=1,knon
+      IF (iso_eau > 0) THEN
+        CALL iso_verif_egalite_choix(xtsnow(iso_eau,i), &
+     &           snow(i),'surf_land_bucket 522', &
+     &           errmax,errmaxrel) 
+      ENDIF !IF (iso_eau > 0) then
+    ENDDO !DO i=1,knon 
+#endif
+   ! end verif
+#endif         
+#ifdef ISO
+    DO i=1,knon
+      snow_prec(i)=snow(i)
+      qsol_prec(i)=qsol(i)
+      DO ixt=1,niso
+        xtsnow_prec(ixt,i)=xtsnow(ixt,i)
+        xtsol_prec(ixt,i) =xtsol(ixt,i)
+      ENDDO !DO ixt=1,niso
+      ! initialisation:
+      fqfonte_diag(i)  =0.0
+      fq_fonte_diag(i) =0.0
+      snow_evap_diag(i)=0.0
+    ENDDO !DO i=1,knon 
+#ifdef ISOVERIF
+    ! write(*,*) 'surf_land_bucket 235'
+    DO i=1,knon  
+      IF (iso_eau > 0) THEN
+        CALL iso_verif_egalite(qsol_prec(i),xtsol_prec(iso_eau,i), &
+    &                              'surf_land_bucket 141')
+      ENDIF
+    ENDDO !DO i=1,knon
+#endif    
+#endif    
 !
 !* Calculate snow height, run_off, age of snow
@@ -136,5 +239,64 @@
     CALL fonte_neige( knon, is_ter, knindex, dtime, &
          tsurf, precip_rain, precip_snow, &
-         snow, qsol, tsurf_new, evap)
+         snow, qsol, tsurf_new, evap &
+#ifdef ISO    
+     & ,fq_fonte_diag,fqfonte_diag,snow_evap_diag,fqcalving_diag   &
+     & ,max_eau_sol_diag,runoff_diag,run_off_lic_diag,coeff_rel_diag   &
+#endif
+     &   )
+
+#ifdef ISO
+#ifdef ISOVERIF
+        DO i=1,knon
+          DO ixt=1,niso
+            CALL iso_verif_noNaN(xtsol_prec(ixt,i),'surf_land_burcket 237')
+          ENDDO
+        ENDDO
+#endif
+#ifdef ISOVERIF
+        !write(*,*) 'surf_land_bucket 235'
+        DO i=1,knon
+          IF (iso_eau > 0) THEN
+            CALL iso_verif_egalite_choix(qsol_prec(i), &
+     &                                   xtsol_prec(iso_eau,i),'surf_land_bucket 628', &
+     &                                   errmax,errmaxrel)
+            CALL iso_verif_egalite_choix(precip_snow(i), &
+     &                                   xtprecip_snow(iso_eau,i),'surf_land_bucket 227', &
+     &                                   errmax,errmaxrel)
+             ! attention, dans fonte_neige, on modifie snow sans modifier
+             ! xtsnow
+             ! c'est fait plus tard dans gestion_neige
+!            write(*,*) 'surf_land_bucket 287: i=',i
+!            write(*,*) 'snow(i)=',snow(i)
+            CALL iso_verif_egalite_choix(xtsnow(iso_eau,i), &
+     &                                   snow_prec(i),'surf_land_bucket 245', &
+     &                                   errmax,errmaxrel) 
+          ENDIF  
+          IF ((iso_O17 > 0).AND.(iso_O18 > 0)) THEN
+              IF (qsol_prec(i) > ridicule_qsol) THEN
+                CALL iso_verif_aberrant_o17(xtsol_prec(iso_O17,i)/qsol_prec(i) &
+     &                                     ,xtsol_prec(iso_O18,i)/qsol_prec(i) &
+     &                                     ,'surf_land_bucket 642')
+              ENDIF !IF ((qsol_prec(i) > ridicule_qsol) &
+          ENDIF !IF ((iso_O17 > 0).AND.(iso_O18 > 0)) THEN
+        ENDDO  !DO i=1,knon 
+        !write(*,*) 'surf_land_mod 291'
+        !write(*,*) 'snow_evap_diag(1)=',snow_evap_diag(1)
+#endif          
+        CALL calcul_iso_surf_ter_vectall(klon,knon, &
+     &           evap,snow_evap_diag,snow, &
+     &           fq_fonte_diag,fqfonte_diag,dtime,precip_rain,xtprecip_rain, &
+     &           precip_snow,xtprecip_snow, snow_prec,xtsnow_prec, &
+     &           tsurf_new,xtspechum,pref,spechum,t_coup,u1_lay,v1_lay,p1lay, &
+     &           qsol,xtsol,qsol_prec,xtsol_prec, &
+     &           max_eau_sol_diag, &
+     &           xtevap,xtsnow,h1,runoff_diag,xtrunoff_diag,fqcalving_diag, &
+     &           knindex,is_ter,run_off_lic_diag,coeff_rel_diag,Rland_ice &
+     &   )
+!#ifdef ISOVERIF
+!        write(*,*) 'surf_land_bucket 303'
+!#endif
+#endif
+
 !
 !* Calculate the age of snow
Index: LMDZ6/branches/cirrus/libf/phylmd/surf_land_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/surf_land_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/surf_land_mod.F90	(revision 5202)
@@ -20,5 +20,11 @@
        qsurf, tsurf_new, dflux_s, dflux_l, &
        flux_u1, flux_v1 , & 
-       veget,lai,height)
+       veget,lai,height &
+#ifdef ISO
+       ,xtprecip_rain, xtprecip_snow,xtspechum, &
+       xtsnow, xtsol,xtevap,h1, &
+       runoff_diag,xtrunoff_diag,Rland_ice &
+#endif               
+               )
 
     USE dimphy
@@ -59,4 +65,12 @@
     USE calcul_fluxs_mod
     USE indice_sol_mod
+#ifdef ISO
+    use infotrac_phy, ONLY: ntiso,niso
+    use isotopes_mod, ONLY: nudge_qsol, iso_eau
+#ifdef ISOVERIF
+    use isotopes_verif_mod
+#endif
+#endif
+
     USE print_control_mod, ONLY: lunout
 
@@ -92,5 +106,8 @@
                                                          ! corresponds to previous sollwdown
     REAL, DIMENSION(klon), INTENT(IN)       :: q2m, t2m
-
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(IN)       :: xtprecip_rain, xtprecip_snow
+    REAL, DIMENSION(ntiso,klon), INTENT(IN)       :: xtspechum
+#endif 
 ! In/Output variables
 !****************************************************************************************
@@ -98,4 +115,7 @@
     REAL, DIMENSION(klon), INTENT(INOUT)          :: agesno
     REAL, DIMENSION(klon, nsoilmx), INTENT(INOUT) :: tsoil
+#ifdef ISO
+    REAL, DIMENSION(niso,klon), INTENT(INOUT)    :: xtsnow, xtsol
+#endif
 
 ! Output variables
@@ -116,4 +136,11 @@
     REAL, DIMENSION(klon,nvm_lmdz), INTENT(OUT) :: veget,lai
     REAL, DIMENSION(klon,nvm_lmdz), INTENT(OUT) :: height
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(OUT)      :: xtevap
+    REAL, DIMENSION(klon), INTENT(OUT)      :: h1
+    REAL, DIMENSION(niso,klon), INTENT(OUT)      :: xtrunoff_diag
+    REAL, DIMENSION(klon), INTENT(OUT)      :: runoff_diag
+    REAL, DIMENSION(niso,klon), INTENT(IN)        :: Rland_ice
+#endif
 
 ! Local variables
@@ -132,5 +159,11 @@
 !albedo SB <<<
 
-
+#ifdef ISO       
+      real, parameter :: t_coup = 273.15
+      real, dimension(klon) :: fqfonte_diag
+      real, dimension(klon) :: snow_evap_diag 
+      real, dimension(klon) :: fqcalving_diag 
+      integer :: ixt
+#endif 
 !****************************************************************************************
 !Total solid precip
@@ -142,4 +175,27 @@
 ENDIF
 !****************************************************************************************
+#ifdef ISO
+#ifdef ISOVERIF
+!        write(*,*) 'surf_land_mod 162'
+        do i=1,knon
+          if (iso_eau.gt.0) then
+            call iso_verif_egalite_choix(precip_snow(i), &
+     &          xtprecip_snow(iso_eau,i),'surf_land_mod 129', &
+     &          errmax,errmaxrel)
+            call iso_verif_egalite_choix(qsol(i), &
+     &          xtsol(iso_eau,i),'surf_land_mod 139', &
+     &          errmax,errmaxrel)
+          endif  
+        enddo
+#endif 
+#ifdef ISOVERIF
+!       write(*,*) 'surf_land 169: ok_veget=',ok_veget
+        do i=1,knon
+         do ixt=1,ntiso
+           call iso_verif_noNaN(xtprecip_snow(ixt,i),'surf_land 146')
+         enddo
+        enddo
+#endif
+#endif
 
 
@@ -172,4 +228,7 @@
        END DO
 
+#ifdef ISO
+      CALL abort_gcm('surf_land_mod 220','isos pas prevus dans orchidee',1)
+#endif
        ! temporary for keeping same results using lwdown_m instead of lwdown
        CALL surf_land_orchidee(itime, dtime, date0, knon, &
@@ -183,5 +242,21 @@
             tsol_rad, tsurf_new, alb1_new, alb2_new, &
             emis_new, z0m, z0h, qsurf, &
-            veget, lai, height)       
+            veget, lai, height &
+!#ifdef ISO
+!            , xtprecip_rain, xtprecip_snow, xtspechum, xtevap &
+!#endif
+            )                  
+
+#ifdef ISO
+#ifdef ISOVERIF
+     write(*,*) 'surf_land 193: apres surf_land_orchidee'   
+     do i=1,knon
+        if (iso_eau.gt.0) then
+             call iso_verif_egalite_choix(xtevap(iso_eau,i),evap(i), &
+    &            'surf_land 197',errmax,errmaxrel)
+        endif !if (iso_eau.gt.0) then      
+      enddo !do i=1,knon  
+#endif
+#endif
 !  
 !* Add contribution of relief to surface roughness
@@ -196,4 +271,18 @@
 !
 !****************************************************************************************
+#ifdef ISO
+#ifdef ISOVERIF
+!       write(*,*) 'surf_land 247'
+        call iso_verif_egalite_vect1D( &
+     &           xtsnow,snow,'surf_land_mod 207',niso,klon)
+#endif
+#endif
+
+#ifdef ISO
+        if (nudge_qsol.eq.1) then
+          call surf_land_nudge_qsol(knon,rlat,rlon,qsol,xtsol,knindex)
+        endif
+        !write(*,*) 'surf_land 258'
+#endif
        CALL surf_land_bucket(itime, jour, knon, knindex, debut, dtime,&
             tsurf, p1lay, cdragh, precip_rain, precip_totsnow, temp_air, &
@@ -202,5 +291,11 @@
             snow, qsol, agesno, tsoil, &
             qsurf, z0m, alb1_new, alb2_new, evap, &
-            fluxsens, fluxlat, tsurf_new, dflux_s, dflux_l)
+            fluxsens, fluxlat, tsurf_new, dflux_s, dflux_l &
+#ifdef ISO
+            ,xtprecip_rain, xtprecip_snow,xtspechum, &
+            xtsnow, xtsol,xtevap,h1, &
+     &      runoff_diag, xtrunoff_diag,Rland_ice &
+#endif           
+     &       )
         z0h(1:knon)=z0m(1:knon) ! En attendant mieux
 
@@ -224,4 +319,16 @@
          p1lay, temp_air, &
          flux_u1, flux_v1)
+
+#ifdef ISO
+#ifdef ISOVERIF
+!     write(*,*) 'surf_land 237: sortie'   
+      DO i=1,knon
+        IF (iso_eau >= 0) THEN
+             call iso_verif_egalite_choix(xtsnow(iso_eau,i),snow(i), &
+    &            'surf_land 241',errmax,errmaxrel)
+        ENDIF !if (iso_eau.gt.0) then      
+      ENDDO !do i=1,knon  
+#endif
+#endif
 
 !albedo SB >>>
@@ -248,4 +355,79 @@
     
   END SUBROUTINE surf_land
+
+
+#ifdef ISO
+  SUBROUTINE surf_land_nudge_qsol(knon,rlat,rlon,qsol,xtsol,knindex)
+
+    USE dimphy   
+    USE infotrac_phy, ONLY: niso
+    USE isotopes_mod, ONLY: region_nudge_qsol    
+    INTEGER, INTENT(IN)                       :: knon         
+    REAL, DIMENSION(klon), INTENT(IN)         :: rlon, rlat
+    REAL, DIMENSION(klon), INTENT(INOUT)      :: qsol
+    INTEGER, DIMENSION(klon), INTENT(IN)      :: knindex    
+    REAL, DIMENSION(niso,klon), INTENT(INOUT) :: xtsol 
+    REAL :: lat_min_nudge_qsol,lat_max_nudge_qsol
+    REAL :: lon_min_nudge_qsol,lon_max_nudge_qsol
+    INTEGER :: i,ixt
+    REAL :: qsol_new
+
+    IF (region_nudge_qsol == 1) THEN
+        ! Aamzonie du Sud
+        lat_min_nudge_qsol=-15.0
+        lat_max_nudge_qsol=-5.0
+        lon_min_nudge_qsol=-70.0
+        lon_max_nudge_qsol=-50.0
+    ELSE IF (region_nudge_qsol == 2) THEN
+        ! Aamzonie du Nord
+        lat_min_nudge_qsol=-5.0
+        lat_max_nudge_qsol=5.0
+        lon_min_nudge_qsol=-70.0
+        lon_max_nudge_qsol=-50.0
+    ELSE
+        WRITE(*,*) 'surf_land 298: cas pas prevu'
+        WRITE(*,*) 'region_nudge_qsol=',region_nudge_qsol
+        stop
+    ENDIF
+
+!    write(*,*) 'surf_land 314: knon=',knon
+!    write(*,*) 'rlat=',rlat
+!    write(*,*) 'rlon=',rlon
+!    write(*,*) 'region_nudge_qsol=',region_nudge_qsol
+
+    DO i=1,knon
+      IF ((rlat(knindex(i)) >= lat_min_nudge_qsol).and. &
+  &       (rlat(knindex(i)) <= lat_max_nudge_qsol).and. &
+  &       (rlon(knindex(i)) >= lon_min_nudge_qsol).and. &
+  &       (rlon(knindex(i)) <= lon_max_nudge_qsol)) THEN
+!        write(*,*) 'surf_land 324: bon domaine: rlat,rlon,qsol=', &
+!  &             rlat(knindex(i)),rlon(knindex(i)),qsol(knindex(i))
+        qsol_new=qsol(i)
+        IF (region_nudge_qsol == 1) THEN   
+           qsol_new=max(qsol(i),50.0)   
+        ELSE IF (region_nudge_qsol == 2) THEN      
+           qsol_new=max(qsol(i),120.0)
+        ELSE !if (region_nudge_qsol.eq.1) then
+           WRITE(*,*) 'surf_land 317: cas pas prevu'
+           WRITE(*,*) 'region_nudge_qsol=',region_nudge_qsol
+           STOP
+        ENDIF !if (region_nudge_qsol.eq.1) then
+        IF (qsol(i) > 0.0) THEN
+           DO ixt=1,niso
+              xtsol(ixt,i)=xtsol(ixt,i)*qsol_new/qsol(i)
+           ENDDO
+        ELSE !IF (qsol(i) > 0.0) THEN
+           DO ixt=1,niso
+             xtsol(ixt,i)=0.0
+           ENDDO
+        ENDIF !IF (qsol(i) > 0.0) THEN
+        qsol(i)=qsol_new
+        WRITE(*,*) 'surf_land 346: qsol_new=',qsol(i)      
+     ENDIF ! if ((rlat(i).ge.lat_min_nudge_qsol).and.
+  ENDDO !DO i=1,knon
+
+  END SUBROUTINE surf_land_nudge_qsol
+#endif
+
 !
 !****************************************************************************************
Index: LMDZ6/branches/cirrus/libf/phylmd/surf_landice_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/surf_landice_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/surf_landice_mod.F90	(revision 5202)
@@ -23,5 +23,10 @@
        snowhgt, qsnow, to_ice, sissnow, &
        alb3, runoff, &
-       flux_u1, flux_v1)
+       flux_u1, flux_v1 &
+#ifdef ISO
+         &      ,xtprecip_rain, xtprecip_snow,xtspechum,Rland_ice &
+         &      ,xtsnow,xtsol,xtevap &
+#endif               
+           &    )
 
     USE dimphy
@@ -33,4 +38,14 @@
     USE phys_local_var_mod, ONLY : zxrhoslic, zxustartlic, zxqsaltlic
     USE phys_output_var_mod, ONLY : snow_o,zfra_o
+#ifdef ISO   
+    USE fonte_neige_mod,  ONLY : xtrun_off_lic
+    USE infotrac_phy,     ONLY : ntiso,niso
+    USE isotopes_routines_mod, ONLY: calcul_iso_surf_lic_vectall
+#ifdef ISOVERIF
+    USE isotopes_mod, ONLY: iso_eau,ridicule
+    USE isotopes_verif_mod
+#endif
+#endif
+ 
 !FC
     USE ioipsl_getin_p_mod, ONLY : getin_p
@@ -68,4 +83,9 @@
     REAL, DIMENSION(klon), INTENT(IN)             :: rugoro
     REAL, DIMENSION(klon,nbsrf), INTENT(IN)       :: pctsrf
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(IN)       :: xtprecip_rain, xtprecip_snow 
+    REAL, DIMENSION(ntiso,klon), INTENT(IN)       :: xtspechum 
+#endif
+
 
     LOGICAL,  INTENT(IN)                          :: debut   !true if first step
@@ -85,4 +105,9 @@
     REAL, DIMENSION(klon), INTENT(INOUT)          :: agesno
     REAL, DIMENSION(klon, nsoilmx), INTENT(INOUT) :: tsoil
+#ifdef ISO
+    REAL, DIMENSION(niso,klon), INTENT(INOUT)     :: xtsnow, xtsol 
+    REAL, DIMENSION(niso,klon), INTENT(INOUT)     :: Rland_ice
+#endif
+
 
 ! Output variables
@@ -108,4 +133,9 @@
     REAL, DIMENSION(klon), INTENT(OUT)           :: sissnow
     REAL, DIMENSION(klon), INTENT(OUT)           :: runoff  !Land ice runoff
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(OUT)     :: xtevap     
+!    real, DIMENSION(niso,klon) :: xtrun_off_lic_0_diag ! est une variable globale de
+!    fonte_neige
+#endif
  
 
@@ -120,4 +150,21 @@
     REAL, DIMENSION(klon)    :: fqfonte,ffonte
     REAL, DIMENSION(klon)    :: run_off_lic_frac
+#ifdef ISO       
+    REAL, PARAMETER          :: t_coup = 273.15
+    REAL, DIMENSION(klon)    :: fqfonte_diag
+    REAL, DIMENSION(klon)    :: fq_fonte_diag
+    REAL, DIMENSION(klon)    ::  snow_evap_diag 
+    REAL, DIMENSION(klon)    ::  fqcalving_diag 
+    REAL max_eau_sol_diag  
+    REAL, DIMENSION(klon)    ::  runoff_diag 
+    REAL, DIMENSION(klon)    ::    run_off_lic_diag 
+    REAL                     ::  coeff_rel_diag
+    INTEGER                  :: ixt
+    REAL, DIMENSION(niso,klon) :: xtsnow_prec,xtsol_prec
+    REAL, DIMENSION(klon) :: snow_prec,qsol_prec
+!    real, DIMENSION(klon) :: run_off_lic_0_diag
+#endif
+
+
     REAL, DIMENSION(klon)    :: emis_new                  !Emissivity
     REAL, DIMENSION(klon)    :: swdown,lwdown
@@ -146,4 +193,6 @@
     REAL, DIMENSION(klon)  :: fluxbs_1, fluxbs_2, bsweight_fresh
     LOGICAL, DIMENSION(klon) :: ok_remaining_freshsnow
+    REAL  :: ta1, ta2, ta3, z01, z02, z03, coefa, coefb, coefc, coefd
+
 
 ! End definition
@@ -161,4 +210,16 @@
 !FC firtscall initializations
 !******************************************************************************************
+#ifdef ISO
+#ifdef ISOVERIF
+!     write(*,*) 'surf_land_ice 1499'   
+  DO i=1,knon
+    IF (iso_eau > 0) THEN
+      CALL iso_verif_egalite_choix(xtsnow(iso_eau,i),snow(i), &
+    &                              'surf_land_ice 126',errmax,errmaxrel)
+    ENDIF !IF (iso_eau > 0) THEN      
+  ENDDO !DO i=1,knon  
+#endif
+#endif
+
   IF (firstcall) THEN
   alb_vis_sno_lic=0.77
@@ -200,4 +261,8 @@
 !****************************************************************************************
 #ifdef CPP_INLANDSIS
+
+#ifdef ISO
+        CALL abort_gcm('surf_landice 235','isotopes pas dans INLANDSIS',1)
+#endif
 
         debut_is=debut
@@ -321,4 +386,29 @@
          tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l)
 
+#ifdef ISO
+#ifdef ISOVERIF
+     !write(*,*) 'surf_land_ice 1499'   
+     DO i=1,knon
+       IF (iso_eau > 0) THEN
+         IF (snow(i) > ridicule) THEN
+           CALL iso_verif_egalite_choix(xtsnow(iso_eau,i),snow(i), &
+    &                                   'surf_land_ice 1151',errmax,errmaxrel)
+         ENDIF !IF ((snow(i) > ridicule)) THEN
+       ENDIF !IF (iso_eau > 0) THEN
+     ENDDO !DO i=1,knon  
+#endif
+
+    DO i=1,knon
+      snow_prec(i)=snow(i)
+      DO ixt=1,niso
+        xtsnow_prec(ixt,i)=xtsnow(ixt,i)
+      ENDDO !DO ixt=1,niso
+      ! initialisation:
+      fq_fonte_diag(i)=0.0
+      fqfonte_diag(i)=0.0
+      snow_evap_diag(i)=0.0 
+    ENDDO !DO i=1,knon 
+#endif         
+
     CALL calcul_flux_wind(knon, dtime, &
          u0, v0, u1, v1, gustiness, cdragm, &
@@ -350,8 +440,36 @@
 !
 !****************************************************************************************
-    z0m = z0m_landice
-    z0h = z0h_landice
-    !z0m = SQRT(z0m**2+rugoro**2)
-
+
+if (z0m_landice .GT. 0.) then
+    z0m(1:knon) = z0m_landice
+    z0h(1:knon) = z0h_landice
+else
+    ! parameterization of z0=f(T) following measurements in Adelie Land by Amory et al 2018
+    coefa = 0.1658 !0.1862 !Ant
+    coefb = -50.3869 !-55.7718 !Ant
+    ta1 = 253.15 !255. Ant
+    ta2 = 273.15
+    ta3 = 273.15+3
+    z01 = exp(coefa*ta1 + coefb) !~0.2 ! ~0.25 mm
+    z02 = exp(coefa*ta2 + coefb) !~6  !~7 mm
+    z03 = z01
+    coefc = log(z03/z02)/(ta3-ta2)
+    coefd = log(z03)-coefc*ta3
+    do j=1,knon 
+      if (temp_air(j) .lt. ta1) then
+        z0m(j) = z01
+      else if (temp_air(j).ge.ta1 .and. temp_air(j).lt.ta2) then
+        z0m(j) = exp(coefa*temp_air(j) + coefb)
+      else if (temp_air(j).ge.ta2 .and. temp_air(j).lt.ta3) then
+        ! if st > 0, melting induce smooth surface
+        z0m(j) = exp(coefc*temp_air(j) + coefd)
+      else
+        z0m(j) = z03
+      endif
+      z0h(j)=z0m(j)
+    enddo
+
+endif    
+ 
 
 !****************************************************************************************
@@ -366,5 +484,5 @@
    if (ok_bs) then
        fluxbs(:)=0.
-       do j=1,klon
+       do j=1,knon
           ws1(j)=(u1(j)**2+v1(j)**2)**0.5
           ustar(j)=(cdragm(j)*(u1(j)**2+v1(j)**2))**0.5
@@ -493,8 +611,36 @@
  
     CALL fonte_neige(knon, is_lic, knindex, dtime, &
-         tsurf, precip_rain, precip_totsnow,  &
-         snow, qsol, tsurf_new, evap_totsnow)
+         tsurf, precip_rain, precip_totsnow, &
+         snow, qsol, tsurf_new, evap_totsnow &
+#ifdef ISO    
+     &  ,fq_fonte_diag,fqfonte_diag,snow_evap_diag,fqcalving_diag     &
+     &  ,max_eau_sol_diag,runoff_diag,run_off_lic_diag,coeff_rel_diag &
+#endif
+     &   )
+
+
+#ifdef ISO
+#ifdef ISOVERIF
+    DO i=1,knon  
+      IF (iso_eau > 0) THEN  
+        CALL iso_verif_egalite_choix(Rland_ice(iso_eau,i),1.0, &
+     &                               'surf_landice_mod 217',errmax,errmaxrel)
+      ENDIF !IF (iso_eau > 0) THEN
+    ENDDO !DO i=1,knon
+#endif
+
+    CALL calcul_iso_surf_lic_vectall(klon,knon, &
+     &    evap,snow_evap_diag,Tsurf_new,snow, &
+     &    fq_fonte_diag,fqfonte_diag,dtime,t_coup, &
+     &    precip_snow,xtprecip_snow,precip_rain,xtprecip_rain, snow_prec,xtsnow_prec, &
+     &    xtspechum,spechum,ps,Rland_ice, &
+     &    xtevap,xtsnow,fqcalving_diag, &
+     &    knindex,is_lic,run_off_lic_diag,coeff_rel_diag &
+     &   ) 
+
+!        call fonte_neige_export_xtrun_off_lic_0(knon,xtrun_off_lic_0_diag)
+
+#endif
    
-    
     WHERE (snow(1 : knon) .LT. 0.0001) agesno(1 : knon) = 0.                                         
     zfra(1:knon) = MAX(0.0,MIN(1.0,snow(1:knon)/(snow(1:knon)+10.0)))  
Index: LMDZ6/branches/cirrus/libf/phylmd/surf_ocean_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/surf_ocean_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/surf_ocean_mod.F90	(revision 5202)
@@ -21,5 +21,10 @@
        tsurf_new, dflux_s, dflux_l, lmt_bils, &
        flux_u1, flux_v1, delta_sst, delta_sal, ds_ns, dt_ns, dter, dser, &
-       dt_ds, tkt, tks, taur, sss)
+       dt_ds, tkt, tks, taur, sss &
+#ifdef ISO
+        &       ,xtprecip_rain, xtprecip_snow,xtspechum,Roce, &
+        &       xtsnow,xtevap,h1 &
+#endif               
+        &       )
 
     use albedo, only: alboc, alboc_cd
@@ -31,6 +36,13 @@
     USE ocean_cpl_mod, ONLY    : ocean_cpl_noice
     USE indice_sol_mod, ONLY : nbsrf, is_oce
+#ifdef ISO
+    USE infotrac_phy, ONLY : ntraciso=>ntiso,niso
+#ifdef ISOVERIF
+    USE isotopes_mod, ONLY: iso_eau,ridicule
+    USE isotopes_verif_mod
+#endif
+#endif
     USE limit_read_mod
-    use config_ocean_skin_m, only: activate_ocean_skin
+    USE config_ocean_skin_m, ONLY: activate_ocean_skin
     !
     ! This subroutine will make a call to ocean_XXX_noice according to the ocean mode (force, 
@@ -68,4 +80,8 @@
     REAL, DIMENSION(klon), INTENT(IN)        :: rugoro
     REAL, DIMENSION(klon,nbsrf), INTENT(IN)  :: pctsrf
+#ifdef ISO
+    REAL, DIMENSION(ntraciso,klon), INTENT(IN) :: xtprecip_rain, xtprecip_snow 
+    REAL, DIMENSION(ntraciso,klon), INTENT(IN) :: xtspechum
+#endif
 
     ! In/Output variables
@@ -75,4 +91,8 @@
     REAL, DIMENSION(klon), INTENT(INOUT)     :: agesno
     REAL, DIMENSION(klon), INTENT(inOUT)     :: z0h
+#ifdef ISO
+    REAL, DIMENSION(niso,klon), INTENT(IN)   :: xtsnow 
+    REAL, DIMENSION(niso,klon), INTENT(INOUT):: Roce  
+#endif
 
     REAL, intent(inout):: delta_sst(:) ! (knon)
@@ -136,4 +156,9 @@
     ! size klon because of the coupling machinery.)
 
+#ifdef ISO
+    REAL, DIMENSION(ntraciso,klon), INTENT(out) :: xtevap ! isotopes in surface evaporation flux 
+    REAL, DIMENSION(klon), INTENT(out)          :: h1 ! just a diagnostic, not useful for the simulation   
+#endif
+
     ! Local variables
     !*************************************************************************
@@ -146,12 +171,26 @@
     REAL, DIMENSION(klon) :: precip_totsnow
     CHARACTER(len=20),PARAMETER :: modname="surf_ocean"
-    real rhoa(knon) ! density of moist air  (kg / m3)
+    REAL rhoa(knon) ! density of moist air  (kg / m3)
     REAL sens_prec_liq(knon)
 
     REAL t_int(knon) ! ocean-air interface temperature, in K
-    real s_int(knon) ! ocean-air interface salinity, in ppt
+    REAL s_int(knon) ! ocean-air interface salinity, in ppt
 
     !**************************************************************************
 
+#ifdef ISO
+#ifdef ISOVERIF
+    DO i = 1, knon
+      IF (iso_eau > 0) THEN         
+        CALL iso_verif_egalite_choix(xtspechum(iso_eau,i), &
+     &          spechum(i),'surf_ocean_mod 117', &
+     &          errmax,errmaxrel)          
+        CALL iso_verif_egalite_choix(xtsnow(iso_eau,i), &
+     &          snow(i),'surf_ocean_mod 127', &
+     &          errmax,errmaxrel) 
+      ENDIF !IF (iso_eau > 0) then
+    ENDDO !DO i=1,klon
+#endif      
+#endif
 
     !******************************************************************************
@@ -230,5 +269,10 @@
             radsol, snow, agesno, &
             qsurf, evap, fluxsens, fluxlat, flux_u1, flux_v1, &
-            tsurf_new, dflux_s, dflux_l, sens_prec_liq, rhoa)
+            tsurf_new, dflux_s, dflux_l, sens_prec_liq, rhoa &
+#ifdef ISO
+            ,xtprecip_rain, xtprecip_snow, xtspechum,Roce,rlat, &
+            xtsnow,xtevap,h1 &  
+#endif            
+            )
     END SELECT
 
Index: LMDZ6/branches/cirrus/libf/phylmd/surf_seaice_mod.F90
===================================================================
--- LMDZ6/branches/cirrus/libf/phylmd/surf_seaice_mod.F90	(revision 5165)
+++ LMDZ6/branches/cirrus/libf/phylmd/surf_seaice_mod.F90	(revision 5202)
@@ -21,5 +21,10 @@
        z0m, z0h, SFRWL, alb_dir_new, alb_dif_new, evap, fluxsens, fluxlat, &  
        tsurf_new, dflux_s, dflux_l, &
-       flux_u1, flux_v1)
+       flux_u1, flux_v1 &
+#ifdef ISO
+         &      ,xtprecip_rain, xtprecip_snow,xtspechum,Roce, &
+         &      xtsnow,xtsol,xtevap,Rland_ice &
+#endif               
+         &      )
 
   USE dimphy
@@ -29,4 +34,7 @@
   USE ocean_slab_mod, ONLY   : ocean_slab_ice
   USE indice_sol_mod
+#ifdef ISO
+  USE infotrac_phy, ONLY : ntiso,niso
+#endif
 
 !
@@ -62,4 +70,10 @@
     REAL, DIMENSION(klon), INTENT(IN)        :: u1, v1, gustiness
     REAL, DIMENSION(klon,nbsrf), INTENT(IN)  :: pctsrf
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(IN)  :: xtprecip_rain, xtprecip_snow 
+    REAL, DIMENSION(klon),       INTENT(IN)  :: xtspechum
+    REAL, DIMENSION(niso,klon),  INTENT(IN)  :: Roce
+    REAL, DIMENSION(niso,klon),  INTENT(IN)  :: Rland_ice
+#endif
 
 ! In/Output arguments
@@ -68,4 +82,8 @@
     REAL, DIMENSION(klon), INTENT(INOUT)          :: agesno
     REAL, DIMENSION(klon, nsoilmx), INTENT(INOUT) :: tsoil
+#ifdef ISO
+    REAL, DIMENSION(niso,klon), INTENT(INOUT)     :: xtsnow  
+    REAL, DIMENSION(niso,klon), INTENT(IN)        :: xtsol 
+#endif
 
 ! Output arguments
@@ -82,8 +100,16 @@
     REAL, DIMENSION(klon), INTENT(OUT)       :: dflux_s, dflux_l      
     REAL, DIMENSION(klon), INTENT(OUT)       :: flux_u1, flux_v1
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(OUT) :: xtevap
+#endif
 
 ! Local arguments
 !****************************************************************************************
     REAL, DIMENSION(klon)  :: radsol
+#ifdef ISO
+#ifdef ISOVERIF
+    INTEGER :: j
+#endif
+#endif
 
 !albedo SB >>>
@@ -145,5 +171,10 @@
             radsol, snow, qsol, agesno, tsoil, &
             qsurf, alb1_new, alb2_new, evap, fluxsens, fluxlat, flux_u1, flux_v1, &
-            tsurf_new, dflux_s, dflux_l, rhoa)
+            tsurf_new, dflux_s, dflux_l, rhoa &
+#ifdef ISO
+            ,xtprecip_rain, xtprecip_snow, xtspechum,Roce, &
+            xtsnow, xtsol,xtevap,Rland_ice &  
+#endif            
+            )
 
     END IF
