Index: /LMDZ5/branches/testing/DefLists/config.def_LMDZ5_AGCM
===================================================================
--- /LMDZ5/branches/testing/DefLists/config.def_LMDZ5_AGCM	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/config.def_LMDZ5_AGCM	(revision 2542)
@@ -81,6 +81,6 @@
 ###  If aerosol offline : type of coupled aerosol =0 (pas d aerosol) =1 (sulphate only default) =2 => bc  only =3 => pom only =4 => seasalt only =5 => dust only =6 => all aerosol 
 flag_aerosol=6 
-# Use stratospheric aerosols (default no)
-flag_aerosol_strat=n
+# Use stratospheric aerosols (0, 1, 2 - default 0)
+flag_aerosol_strat=0
 ### bl95_b0 =    Parameter in CDNC-maer link (Boucher&Lohmann 1995)
 bl95_b0=1.7
Index: /LMDZ5/branches/testing/DefLists/context_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/context_lmdz.xml	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/context_lmdz.xml	(revision 2542)
@@ -1,4 +1,5 @@
 <!-- Context LMDZ -->
-<context id="LMDZ" calendar_type="D360" start_date="1980-01-01 00:00:00">
+<context id="LMDZ">
+<!--  <calendar type="D360" start_date="1980-01-01 00:00:00" /> -->
   
   <!-- Define available variables -->
@@ -27,7 +28,7 @@
   
   <!-- Need to define a grid? Do it here -->
-  <grid_definition>
+<!--  <grid_definition>
     <grid_group id="vertical" axis_ref="presnivs" />
-  </grid_definition>
+  </grid_> -->
   
   <!-- Define groups of vertical axes -->
Index: /LMDZ5/branches/testing/DefLists/context_lmdz_XIOS1.0.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/context_lmdz_XIOS1.0.xml	(revision 2542)
+++ /LMDZ5/branches/testing/DefLists/context_lmdz_XIOS1.0.xml	(revision 2542)
@@ -0,0 +1,56 @@
+<!-- Context LMDZ -->
+<context id="LMDZ" calendar_type="D360" start_date="1980-01-01 00:00:00">
+  
+  <!-- Define available variables -->
+  <field_definition src="./field_def_lmdz.xml"/> 
+  
+  <!-- Define output files
+       Each file contains the list of variables and their output levels -->
+  
+  <file_definition src="./file_def_histday_lmdz.xml"/>
+  <file_definition src="./file_def_histhf_lmdz.xml"/>
+  <file_definition src="./file_def_histins_lmdz.xml"/>
+  <file_definition src="./file_def_histLES_lmdz.xml"/>
+  <file_definition src="./file_def_histmth_lmdz.xml"/> 
+  <file_definition src="./file_def_histstn_lmdz.xml"/>
+  <file_definition src="./file_def_histmthNMC_lmdz.xml"/>
+  <file_definition src="./file_def_histdayNMC_lmdz.xml"/>
+  <file_definition src="./file_def_histhfNMC_lmdz.xml"/>
+  <file_definition src="./file_def_histmthCOSP_lmdz.xml"/>
+  <file_definition src="./file_def_histdayCOSP_lmdz.xml"/>
+  <file_definition src="./file_def_histhfCOSP_lmdz.xml"/>
+  
+  <!-- Define domains and groups of domains -->
+  <domain_definition>
+    <domain id="dom_glo" data_dim="2" />
+  </domain_definition>
+  
+  <!-- Need to define a grid? Do it here -->
+  <grid_definition>
+    <grid_group id="vertical" axis_ref="presnivs" />
+  </grid_definition>
+  
+  <!-- Define groups of vertical axes -->
+  <axis_definition>
+    <axis id="presnivs" standard_name="Vertical levels" unit="Pa">
+    </axis>
+    <axis id="Ahyb" standard_name="Ahyb comp of Hyb Cord" unit="Pa">
+    </axis> 
+    <axis id="Bhyb" standard_name="Bhyb comp of Hyb Cord" unit="">
+    </axis>
+    <axis id="Alt" standard_name="Height approx for scale heigh of 8km at levels" unit="km">
+    </axis>
+    <axis id="plev" standard_name="model_level_number" unit="Pa">
+    </axis>
+<!--    <axis id="height" standard_name="Cosp levels" unit="m"> -->
+<!--    </axis> -->
+<!--    <axis id="height_mlev" standard_name="height_mlev" unit="m"> -->
+<!--    </axis> -->
+<!--    <axis id="sza" standard_name="solar_zenith_angle" unit="degrees"> -->
+<!--    </axis> -->
+<!--    <axis id="pressure2" standard_name="pressure" unit="mb"> -->
+<!--    </axis> -->
+<!--    <axis id="column" standard_name="column" unit="count"> -->
+<!--    </axis> -->
+  </axis_definition>
+</context>
Index: DZ5/branches/testing/DefLists/convection.def
===================================================================
--- /LMDZ5/branches/testing/DefLists/convection.def	(revision 2541)
+++ 	(revision )
@@ -1,43 +1,0 @@
-### Convection
-#altitude, in hPa, above LCL at which buoybase is computed, def = original: -40
-dpbase=-40.
-#altitude, in hPa, above LCL below which Ep=0, def = original: 150, used only if flag_epKEorig=0
-pbcrit=150.0
-#altitude, in hPa, above LCL above which Ep=Epmax, def = original: 500, used only if flag_epKEorig=0
-ptcrit=500.0
-#reference fractional area of precipitating downdraughts, def = original: 0.01
-sigdz=0.01
-#unsaturated fraction of precipitating downdraughts, def = original: 0.15
-spfac=0.15
-#relaxation time of cloud base mass flux, def = original: 8000
-tau=8000.
-#flag for wb (= vert velocity at LFC); 0->wb=wbmax, 1->wb=f(plfc) bounded, 2->wb=f(plfc) linear, def = 1
-flag_wb=1
-#parameter used in the computation of wb, def = 6.
-wbmax=6.
-#
-ok_convstop=.False.
-#
-tau_stop=15000.
-#
-ok_intermittent=.False.
-#shedding coefficient (used when iflag_mix_adiab=1)
-coef_peel=0.25
-#
-### Clouds
-#Conversion cld water->precip: Ep=f(pressure) if 0; Ep=f(temperature) if 1, def=1
-flag_epKEorig=1
-#max condensed water concentration in kg/kg, def=0.0003, original: 0.0011, used only if flag_epKEorig=1
-elcrit=0.0003
-#temperature in degre Celsius, at which Ep=Epmax, def=-55., original: -55, used only if flag_epKEorig=1
-tlcrit=-55.0
-
-### Wakes
-#coefficient in Wape->C_star formula: C_star=stark*sqrt(2*Wape), def: 0.33
-stark=0.33
-#lifting efficiency of wakes; Alp=Alpk*Fip, Fip=power provided by wakes, def: 0.25
-alpk=0.25
-#wake density = number of wake centers per m2, def: 8.E-12
-wdens_ref=8.E-12
-#multiplicative factor of the damping by gravity waves, def: 4.
-coefgw=4.
Index: /LMDZ5/branches/testing/DefLists/field_def_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/field_def_lmdz.xml	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/field_def_lmdz.xml	(revision 2542)
@@ -64,4 +64,5 @@
         <field id="precip"      long_name="Precip Totale liq+sol"       unit="kg/(s*m2)" />
         <field id="plul"    long_name="Large-scale Precip."     unit="kg/(s*m2)" />
+        <field id="plun"    long_name="Numerical Precip."       unit="kg/(s*m2)" />
         <field id="pluc"    long_name="Convective Precip."      unit="kg/(s*m2)" />
         <field id="snow"    long_name="Snow fall"               unit="kg/(s*m2)" />
@@ -124,4 +125,5 @@
         <field id="fqcalving"    long_name="Ice Calving"    unit="kg/m2/s" />
         <field id="fqfonte"    long_name="Land ice melt"    unit="kg/m2/s" />
+        <field id="runofflic"  long_name="Land ice melt to ocean" unit="kg/m2/s" />
         <field id="taux"    long_name="Zonal wind stress"    unit="Pa" />
         <field id="tauy"    long_name="Meridional wind stress"    unit="Pa" />
@@ -195,4 +197,6 @@
         <field id="wbeff"    long_name="Conv. updraft velocity at LFC (inf100)"    unit="m/s" />
         <field id="prw"    long_name="Precipitable water"    unit="kg/m2" />
+        <field id="prlw"   long_name="Precipitable liquid water"  unit="kg/m2" />
+        <field id="prsw"   long_name="Precipitable solid water"  unit="kg/m2" />
         <field id="s_pblh"    long_name="Boundary Layer Height"    unit="m" />
         <field id="s_pblt"    long_name="t at Boundary Layer Height"    unit="K" />
@@ -375,4 +379,12 @@
         <field id="z0h_oce"    long_name="roughness length, enthalpy oce"    unit="m" />
         <field id="z0h_sic"    long_name="roughness length, enthalpy sic"    unit="m" />
+        <field id="sens_rain_oce"  long_name="Sensible heat flux associated withliquid prec. over ocean"    unit="W/m2" />
+        <field id="sens_rain_sic"  long_name="Sensible heat flux associated with liquid prec. over seaice"    unit="W/m2" />
+        <field id="sens_snow_oce"  long_name="Sensible heat flux associated with solid prec. over ocean"    unit="W/m2" />
+        <field id="sens_snow_sic"  long_name="Sensible heat flux associated with solid prec. over seaice"    unit="W/m2" />
+        <field id="lat_rain_oce"  long_name="Latent heat flux associated with liquid prec. over ocean"    unit="W/m2" />
+        <field id="lat_rain_sic"  long_name="Latent heat flux associated with liquid prec. over seaice"    unit="W/m2" />
+        <field id="lat_snow_oce"  long_name="Latent heat flux associated with solid prec. over ocean"    unit="W/m2" />
+        <field id="lat_snow_sic"  long_name="Latent heat flux associated with solid prec. over seaice"    unit="W/m2" />
         <field id="alb1"    long_name="Surface VIS albedo"    unit="-" />
         <field id="alb2"    long_name="Surface Near IR albedo"    unit="-" />
@@ -392,5 +404,9 @@
         <field id="rlutcs4co2"    long_name="TOA Out CS LW in 4xCO2 atmosphere"    unit="W/m2" />
         <field id="dqphy2d"    long_name="Physics dQ"    unit="(kg/m2)/s" />
+        <field id="dqlphy2d"    long_name="Physics dQL"    unit="(kg/m2)/s" />
+        <field id="dqsphy2d"    long_name="Physics dQS"    unit="(kg/m2)/s" />
         <field id="dqdyn2d"    long_name="Dynamics dQ"    unit="(kg/m2)/s" />
+        <field id="dqldyn2d"   long_name="Dynamics dQL"    unit="(kg/m2)/s" />
+        <field id="dqsdyn2d"   long_name="Dynamics dQS"    unit="(kg/m2)/s" />
         <field id="dqcon2d"    long_name="Convection dQ"    unit="(kg/m2)/s" />
         <field id="dqwak2d"    long_name="Wake dQ"    unit="(kg/m2)/s" />
@@ -456,4 +472,6 @@
         <field id="dtphy"    long_name="Physics dT"    unit="K/s" />
         <field id="dqphy"    long_name="Physics dQ"    unit="(kg/kg)/s" />
+        <field id="dqlphy"   long_name="Physics dQL"    unit="(kg/kg)/s" />
+        <field id="dqsphy"   long_name="Physics dQS"    unit="(kg/kg)/s" />
         <field id="pr_con_l"    long_name="Convective precipitation lic"    unit="-" />
         <field id="pr_con_i"    long_name="Convective precipitation ice"    unit="-" />
@@ -475,4 +493,6 @@
         <field id="dtdyn"    long_name="Dynamics dT"    unit="K/s" />
         <field id="dqdyn"    long_name="Dynamics dQ"    unit="(kg/kg)/s" />
+        <field id="dqldyn"    long_name="Dynamics dQL"    unit="(kg/kg)/s" />
+        <field id="dqsdyn"    long_name="Dynamics dQS"    unit="(kg/kg)/s" />
         <field id="dudyn"    long_name="Dynamics dU"    unit="m/s2" />
         <field id="dvdyn"    long_name="Dynamics dV"    unit="m/s2" />
@@ -569,4 +589,5 @@
         <field id="rsdcs4co2"    long_name="Downwelling CS SW 4xCO2 atmosphere"    unit="W/m2" />
         <field id="rldcs4co2"    long_name="Downwelling CS LW 4xCO2 atmosphere"    unit="W/m2" />
+        <field id="stratomask"    long_name="Stratospheric fraction"    unit="-" />
     </field_group>
     
@@ -584,6 +605,5 @@
       <field id="tro3_daylight" long_name="Daylight ozone mole fraction" unit="1e-9" />
       <field id="uv" long_name="uv" unit="m2/s2" />
-      <!-- a field called "vq" is already defined...
-      <field id="vq" long_name="vq" unit="m/s * (kg/kg)" /> -->
+      <field id="vxq" long_name="vxq" unit="m/s * (kg/kg)" />
       <field id="vT" long_name="vT" unit="mK/s" />
       <field id="wq" long_name="wq" unit="(Pa/s)*(kg/kg)" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histLES_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histLES_lmdz.xml	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/file_def_histLES_lmdz.xml	(revision 2542)
@@ -60,4 +60,5 @@
                 <field field_ref="precip" level="5" />
                 <field field_ref="plul" level="10" />
+                <field field_ref="plun" level="10" />
                 <field field_ref="pluc" level="5" />
                 <field field_ref="snow" level="5" />
@@ -111,4 +112,5 @@
                 <field field_ref="fqcalving" level="10" />
                 <field field_ref="fqfonte" level="10" />
+                <field field_ref="runofflic" level="10" />
                 <field field_ref="taux" level="10" />
                 <field field_ref="tauy" level="10" />
@@ -182,4 +184,6 @@
                 <field field_ref="wbeff" level="10" />
                 <field field_ref="prw" level="10" />
+                <field field_ref="prlw" level="10" />
+                <field field_ref="prsw" level="10" />
                 <field field_ref="s_pblh" level="10" />
                 <field field_ref="s_pblt" level="10" />
@@ -383,5 +387,9 @@
                 <field field_ref="rlutcs4co2" level="10" />
                 <field field_ref="dqphy2d" level="10" />
+                <field field_ref="dqlphy2d" level="10" />
+                <field field_ref="dqsphy2d" level="10" />
                 <field field_ref="dqdyn2d" level="10" />
+                <field field_ref="dqldyn2d" level="10" />
+                <field field_ref="dqsdyn2d" level="10" />
                 <field field_ref="dqcon2d" level="10" />
                 <field field_ref="dqwak2d" level="10" />
@@ -433,4 +441,6 @@
                 <field field_ref="dtphy" level="10" />
                 <field field_ref="dqphy" level="10" />
+                <field field_ref="dqlphy" level="10" />
+                <field field_ref="dqsphy" level="10" />
                 <field field_ref="pr_con_l" level="10" />
                 <field field_ref="pr_con_i" level="10" />
@@ -452,4 +462,6 @@
                 <field field_ref="dtdyn" level="10" />
                 <field field_ref="dqdyn" level="10" />
+                <field field_ref="dqldyn" level="10" />
+                <field field_ref="dqsdyn" level="10" />
                 <field field_ref="dudyn" level="10" />
                 <field field_ref="dvdyn" level="10" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histday_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histday_lmdz.xml	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/file_def_histday_lmdz.xml	(revision 2542)
@@ -60,4 +60,5 @@
                 <field field_ref="precip" level="1" />
                 <field field_ref="plul" level="1" />
+                <field field_ref="plun" level="1" />
                 <field field_ref="pluc" level="1" />
                 <field field_ref="snow" level="1" />
@@ -111,4 +112,5 @@
                 <field field_ref="fqcalving" level="10" />
                 <field field_ref="fqfonte" level="10" />
+                <field field_ref="runofflic" level="10" />
                 <field field_ref="taux" level="10" />
                 <field field_ref="tauy" level="10" />
@@ -182,4 +184,6 @@
                 <field field_ref="wbeff" level="10" />
                 <field field_ref="prw" level="1" />
+                <field field_ref="prlw" level="1" />
+                <field field_ref="prsw" level="1" />
                 <field field_ref="s_pblh" level="10" />
                 <field field_ref="s_pblt" level="10" />
@@ -383,5 +387,9 @@
                 <field field_ref="rlutcs4co2" level="10" />
                 <field field_ref="dqphy2d" level="10" />
+                <field field_ref="dqlphy2d" level="10" />
+                <field field_ref="dqsphy2d" level="10" />
                 <field field_ref="dqdyn2d" level="10" />
+                <field field_ref="dqldyn2d" level="10" />
+                <field field_ref="dqsdyn2d" level="10" />
                 <field field_ref="dqcon2d" level="10" />
                 <field field_ref="dqwak2d" level="10" />
@@ -433,4 +441,6 @@
                 <field field_ref="dtphy" level="10" />
                 <field field_ref="dqphy" level="10" />
+                <field field_ref="dqlphy" level="10" />
+                <field field_ref="dqsphy" level="10" />
                 <field field_ref="pr_con_l" level="10" />
                 <field field_ref="pr_con_i" level="10" />
@@ -452,4 +462,6 @@
                 <field field_ref="dtdyn" level="10" />
                 <field field_ref="dqdyn" level="10" />
+                <field field_ref="dqldyn" level="10" />
+                <field field_ref="dqsdyn" level="10" />
                 <field field_ref="dudyn" level="10" />
                 <field field_ref="dvdyn" level="10" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histhf_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histhf_lmdz.xml	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/file_def_histhf_lmdz.xml	(revision 2542)
@@ -60,4 +60,5 @@
                 <field field_ref="precip" level="10" />
                 <field field_ref="plul" level="10" />
+                <field field_ref="plun" level="10" />
                 <field field_ref="pluc" level="10" />
                 <field field_ref="snow" level="10" />
@@ -111,4 +112,5 @@
                 <field field_ref="fqcalving" level="10" />
                 <field field_ref="fqfonte" level="10" />
+                <field field_ref="runofflic" level="10" />
                 <field field_ref="taux" level="10" />
                 <field field_ref="tauy" level="10" />
@@ -182,4 +184,6 @@
                 <field field_ref="wbeff" level="10" />
                 <field field_ref="prw" level="10" />
+                <field field_ref="prlw" level="10" />
+                <field field_ref="prsw" level="10" />
                 <field field_ref="s_pblh" level="10" />
                 <field field_ref="s_pblt" level="10" />
@@ -383,5 +387,9 @@
                 <field field_ref="rlutcs4co2" level="10" />
                 <field field_ref="dqphy2d" level="10" />
+                <field field_ref="dqlphy2d" level="10" />
+                <field field_ref="dqsphy2d" level="10" />
                 <field field_ref="dqdyn2d" level="10" />
+                <field field_ref="dqldyn2d" level="10" />
+                <field field_ref="dqsdyn2d" level="10" />
                 <field field_ref="dqcon2d" level="10" />
                 <field field_ref="dqwak2d" level="10" />
@@ -433,4 +441,6 @@
                 <field field_ref="dtphy" level="10" />
                 <field field_ref="dqphy" level="10" />
+                <field field_ref="dqlphy" level="10" />
+                <field field_ref="dqsphy" level="10" />
                 <field field_ref="pr_con_l" level="10" />
                 <field field_ref="pr_con_i" level="10" />
@@ -452,4 +462,6 @@
                 <field field_ref="dtdyn" level="10" />
                 <field field_ref="dqdyn" level="10" />
+                <field field_ref="dqldyn" level="10" />
+                <field field_ref="dqsdyn" level="10" />
                 <field field_ref="dudyn" level="10" />
                 <field field_ref="dvdyn" level="10" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histins_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histins_lmdz.xml	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/file_def_histins_lmdz.xml	(revision 2542)
@@ -60,4 +60,5 @@
                 <field field_ref="precip" level="1" />
                 <field field_ref="plul" level="1" />
+                <field field_ref="plun" level="1" />
                 <field field_ref="pluc" level="1" />
                 <field field_ref="snow" level="10" />
@@ -111,4 +112,5 @@
                 <field field_ref="fqcalving" level="10" />
                 <field field_ref="fqfonte" level="10" />
+                <field field_ref="runofflic" level="10" />
                 <field field_ref="taux" level="10" />
                 <field field_ref="tauy" level="10" />
@@ -182,4 +184,6 @@
                 <field field_ref="wbeff" level="10" />
                 <field field_ref="prw" level="10" />
+                <field field_ref="prlw" level="10" />
+                <field field_ref="prsw" level="10" />
                 <field field_ref="s_pblh" level="10" />
                 <field field_ref="s_pblt" level="10" />
@@ -383,5 +387,9 @@
                 <field field_ref="rlutcs4co2" level="10" />
                 <field field_ref="dqphy2d" level="10" />
+                <field field_ref="dqlphy2d" level="10" />
+                <field field_ref="dqsphy2d" level="10" />
                 <field field_ref="dqdyn2d" level="10" />
+                <field field_ref="dqldyn2d" level="10" />
+                <field field_ref="dqsdyn2d" level="10" />
                 <field field_ref="dqcon2d" level="10" />
                 <field field_ref="dqwak2d" level="10" />
@@ -433,4 +441,6 @@
                 <field field_ref="dtphy" level="10" />
                 <field field_ref="dqphy" level="10" />
+                <field field_ref="dqlphy" level="10" />
+                <field field_ref="dqsphy" level="10" />
                 <field field_ref="pr_con_l" level="10" />
                 <field field_ref="pr_con_i" level="10" />
@@ -452,4 +462,6 @@
                 <field field_ref="dtdyn" level="10" />
                 <field field_ref="dqdyn" level="10" />
+                <field field_ref="dqldyn" level="10" />
+                <field field_ref="dqsdyn" level="10" />
                 <field field_ref="dudyn" level="10" />
                 <field field_ref="dvdyn" level="10" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histmth_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histmth_lmdz.xml	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/file_def_histmth_lmdz.xml	(revision 2542)
@@ -60,4 +60,5 @@
                 <field field_ref="precip"   level="1" />
                 <field field_ref="plul"     level="1" />
+                <field field_ref="plun"     level="1" />
                 <field field_ref="pluc"     level="1" />
                 <field field_ref="snow"     level="1" />
@@ -111,4 +112,5 @@
                 <field field_ref="fqcalving" level="1" />
                 <field field_ref="fqfonte" level="1" />
+                <field field_ref="runofflic" level="1" />
                 <field field_ref="taux" level="1" />
                 <field field_ref="tauy" level="1" />
@@ -182,4 +184,6 @@
                 <field field_ref="wbeff" level="1" />
                 <field field_ref="prw" level="1" />
+                <field field_ref="prlw" level="1" />
+                <field field_ref="prsw" level="1" />
                 <field field_ref="s_pblh" level="1" />
                 <field field_ref="s_pblt" level="1" />
@@ -383,5 +387,9 @@
                 <field field_ref="rlutcs4co2" level="5" />
                 <field field_ref="dqphy2d" level="2" />
+                <field field_ref="dqlphy2d" level="2" />
+                <field field_ref="dqsphy2d" level="2" />
                 <field field_ref="dqdyn2d" level="4" />
+                <field field_ref="dqldyn2d" level="4" />
+                <field field_ref="dqsdyn2d" level="4" />
                 <field field_ref="dqcon2d" level="4" />
                 <field field_ref="dqwak2d" level="4" />
@@ -433,4 +441,6 @@
                 <field field_ref="dtphy" level="2" />
                 <field field_ref="dqphy" level="2" />
+                <field field_ref="dqlphy" level="2" />
+                <field field_ref="dqsphy" level="2" />
                 <field field_ref="pr_con_l" level="2" />
                 <field field_ref="pr_con_i" level="2" />
@@ -452,4 +462,6 @@
                 <field field_ref="dtdyn" level="4" />
                 <field field_ref="dqdyn" level="4" />
+                <field field_ref="dqldyn" level="4" />
+                <field field_ref="dqsdyn" level="4" />
                 <field field_ref="dudyn" level="4" />
                 <field field_ref="dvdyn" level="4" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histstn_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histstn_lmdz.xml	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/file_def_histstn_lmdz.xml	(revision 2542)
@@ -60,4 +60,5 @@
                 <field field_ref="precip" level="10" />
                 <field field_ref="plul" level="10" />
+                <field field_ref="plun" level="10" />
                 <field field_ref="pluc" level="10" />
                 <field field_ref="snow" level="10" />
@@ -111,4 +112,5 @@
                 <field field_ref="fqcalving" level="10" />
                 <field field_ref="fqfonte" level="10" />
+                <field field_ref="runofflic" level="10" />
                 <field field_ref="taux" level="10" />
                 <field field_ref="tauy" level="10" />
@@ -182,4 +184,6 @@
                 <field field_ref="wbeff" level="10" />
                 <field field_ref="prw" level="10" />
+                <field field_ref="prlw" level="10" />
+                <field field_ref="prsw" level="10" />
                 <field field_ref="s_pblh" level="10" />
                 <field field_ref="s_pblt" level="10" />
@@ -383,5 +387,9 @@
                 <field field_ref="rlutcs4co2" level="10" />
                 <field field_ref="dqphy2d" level="10" />
+                <field field_ref="dqlphy2d" level="10" />
+                <field field_ref="dqsphy2d" level="10" />
                 <field field_ref="dqdyn2d" level="10" />
+                <field field_ref="dqldyn2d" level="10" />
+                <field field_ref="dqsdyn2d" level="10" />
                 <field field_ref="dqcon2d" level="10" />
                 <field field_ref="dqwak2d" level="10" />
@@ -433,4 +441,6 @@
                 <field field_ref="dtphy" level="10" />
                 <field field_ref="dqphy" level="10" />
+                <field field_ref="dqlphy" level="10" />
+                <field field_ref="dqsphy" level="10" />
                 <field field_ref="pr_con_l" level="10" />
                 <field field_ref="pr_con_i" level="10" />
@@ -452,4 +462,6 @@
                 <field field_ref="dtdyn" level="10" />
                 <field field_ref="dqdyn" level="10" />
+                <field field_ref="dqldyn" level="10" />
+                <field field_ref="dqsdyn" level="10" />
                 <field field_ref="dudyn" level="10" />
                 <field field_ref="dvdyn" level="10" />
Index: /LMDZ5/branches/testing/DefLists/iodef.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/iodef.xml	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/iodef.xml	(revision 2542)
@@ -10,5 +10,5 @@
 
         	<variable_group id="parameters" >
-        		<variable id="using_server" type="boolean">true</variable>
+        		<variable id="using_server" type="bool">true</variable>
         		<variable id="info_level" type="int">0</variable>
         	</variable_group>
Index: /LMDZ5/branches/testing/DefLists/iodef_XIOS1.0.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/iodef_XIOS1.0.xml	(revision 2542)
+++ /LMDZ5/branches/testing/DefLists/iodef_XIOS1.0.xml	(revision 2542)
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<simulation> 
+	
+	<context  id="xios">
+		<variable_definition>
+       		<variable_group id="buffer">
+            	buffer_size = 85000000
+            	buffer_server_factor_size = 2 
+         	</variable_group>
+
+        	<variable_group id="parameters" >
+        		<variable id="using_server" type="boolean">true</variable>
+        		<variable id="info_level" type="int">0</variable>
+        	</variable_group>
+		</variable_definition>
+	</context>
+	
+
+	<context id="LMDZ" src="./context_lmdz.xml"/>
+
+
+</simulation>
Index: /LMDZ5/branches/testing/DefLists/physiq.def_L79_NPv5.4
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_L79_NPv5.4	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_L79_NPv5.4	(revision 2542)
@@ -185,2 +185,45 @@
 iflag_cloudth_vert=1
 
+### Convection
+#altitude, in hPa, above LCL at which buoybase is computed, def = original: -40
+dpbase=-40.
+#altitude, in hPa, above LCL below which Ep=0, def = original: 150, used only if flag_epKEorig=0
+pbcrit=150.0
+#altitude, in hPa, above LCL above which Ep=Epmax, def = original: 500, used only if flag_epKEorig=0
+ptcrit=500.0
+#reference fractional area of precipitating downdraughts, def = original: 0.01
+sigdz=0.01
+#unsaturated fraction of precipitating downdraughts, def = original: 0.15
+spfac=0.15
+#relaxation time of cloud base mass flux, def = original: 8000
+tau=8000.
+#flag for wb (= vert velocity at LFC); 0->wb=wbmax, 1->wb=f(plfc) bounded, 2->wb=f(plfc) linear, def = 1
+flag_wb=1
+#parameter used in the computation of wb, def = 6.
+wbmax=6.
+#
+ok_convstop=.False.
+#
+tau_stop=15000.
+#
+ok_intermittent=.False.
+#shedding coefficient (used when iflag_mix_adiab=1)
+coef_peel=0.25
+#
+### Clouds
+#Conversion cld water->precip: Ep=f(pressure) if 0; Ep=f(temperature) if 1, def=1
+flag_epKEorig=1
+#max condensed water concentration in kg/kg, def=0.0003, original: 0.0011, used only if flag_epKEorig=1
+elcrit=0.0003
+#temperature in degre Celsius, at which Ep=Epmax, def=-55., original: -55, used only if flag_epKEorig=1
+tlcrit=-55.0
+
+### Wakes
+#coefficient in Wape->C_star formula: C_star=stark*sqrt(2*Wape), def: 0.33
+stark=0.33
+#lifting efficiency of wakes; Alp=Alpk*Fip, Fip=power provided by wakes, def: 0.25
+alpk=0.25
+#wake density = number of wake centers per m2, def: 8.E-12
+wdens_ref=8.E-12
+#multiplicative factor of the damping by gravity waves, def: 4.
+coefgw=4.
Index: /LMDZ5/branches/testing/DefLists/physiq.def_L79_NPv5.5
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_L79_NPv5.5	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_L79_NPv5.5	(revision 2542)
@@ -190,2 +190,47 @@
 #Bergeron
 iflag_bergeron=1
+
+
+### Convection
+#altitude, in hPa, above LCL at which buoybase is computed, def = original: -40
+dpbase=-40.
+#altitude, in hPa, above LCL below which Ep=0, def = original: 150, used only if flag_epKEorig=0
+pbcrit=150.0
+#altitude, in hPa, above LCL above which Ep=Epmax, def = original: 500, used only if flag_epKEorig=0
+ptcrit=500.0
+#reference fractional area of precipitating downdraughts, def = original: 0.01
+sigdz=0.01
+#unsaturated fraction of precipitating downdraughts, def = original: 0.15
+spfac=0.15
+#relaxation time of cloud base mass flux, def = original: 8000
+tau=8000.
+#flag for wb (= vert velocity at LFC); 0->wb=wbmax, 1->wb=f(plfc) bounded, 2->wb=f(plfc) linear, def = 1
+flag_wb=1
+#parameter used in the computation of wb, def = 6.
+wbmax=6.
+#
+ok_convstop=.False.
+#
+tau_stop=15000.
+#
+ok_intermittent=.False.
+#shedding coefficient (used when iflag_mix_adiab=1)
+coef_peel=0.25
+#
+### Clouds
+#Conversion cld water->precip: Ep=f(pressure) if 0; Ep=f(temperature) if 1, def=1
+flag_epKEorig=1
+#max condensed water concentration in kg/kg, def=0.0003, original: 0.0011, used only if flag_epKEorig=1
+elcrit=0.0003
+#temperature in degre Celsius, at which Ep=Epmax, def=-55., original: -55, used only if flag_epKEorig=1
+tlcrit=-55.0
+
+### Wakes
+#coefficient in Wape->C_star formula: C_star=stark*sqrt(2*Wape), def: 0.33
+stark=0.33
+#lifting efficiency of wakes; Alp=Alpk*Fip, Fip=power provided by wakes, def: 0.25
+alpk=0.25
+#wake density = number of wake centers per m2, def: 8.E-12
+wdens_ref=8.E-12
+#multiplicative factor of the damping by gravity waves, def: 4.
+coefgw=4.
Index: /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.4
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.4	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.4	(revision 2542)
@@ -185,2 +185,45 @@
 iflag_cloudth_vert=1
 
+### Convection: le fichier convection.def
+#altitude, in hPa, above LCL at which buoybase is computed, def = original: -40
+dpbase=-40.
+#altitude, in hPa, above LCL below which Ep=0, def = original: 150, used only if flag_epKEorig=0
+pbcrit=150.0
+#altitude, in hPa, above LCL above which Ep=Epmax, def = original: 500, used only if flag_epKEorig=0
+ptcrit=500.0
+#reference fractional area of precipitating downdraughts, def = original: 0.01
+sigdz=0.01
+#unsaturated fraction of precipitating downdraughts, def = original: 0.15
+spfac=0.15
+#relaxation time of cloud base mass flux, def = original: 8000
+tau=8000.
+#flag for wb (= vert velocity at LFC); 0->wb=wbmax, 1->wb=f(plfc) bounded, 2->wb=f(plfc) linear, def = 1
+flag_wb=1
+#parameter used in the computation of wb, def = 6.
+wbmax=6.
+#
+ok_convstop=.False.
+#
+tau_stop=15000.
+#
+ok_intermittent=.False.
+#shedding coefficient (used when iflag_mix_adiab=1)
+coef_peel=0.25
+#
+### Clouds
+#Conversion cld water->precip: Ep=f(pressure) if 0; Ep=f(temperature) if 1, def=1
+flag_epKEorig=1
+#max condensed water concentration in kg/kg, def=0.0003, original: 0.0011, used only if flag_epKEorig=1
+elcrit=0.0003
+#temperature in degre Celsius, at which Ep=Epmax, def=-55., original: -55, used only if flag_epKEorig=1
+tlcrit=-55.0
+
+### Wakes
+#coefficient in Wape->C_star formula: C_star=stark*sqrt(2*Wape), def: 0.33
+stark=0.33
+#lifting efficiency of wakes; Alp=Alpk*Fip, Fip=power provided by wakes, def: 0.25
+alpk=0.25
+#wake density = number of wake centers per m2, def: 8.E-12
+wdens_ref=8.E-12
+#multiplicative factor of the damping by gravity waves, def: 4.
+coefgw=4.
Index: /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.5
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.5	(revision 2542)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.5	(revision 2542)
@@ -0,0 +1,239 @@
+#
+# $Id$
+#
+##############################################################################
+# PARAMETRES ET CLES DE LA PHYSIQUE LMDZ
+##############################################################################
+# D: Valeur par default
+#
+#Parametres Orographiques et cdrags
+#**********************************
+##   Si=.T. ,  lecture du fichier limit avec la bonne annee 
+ok_limitvrai=n
+iflag_albedo=1
+#Cdrags 
+f_cdrag_stable=1.
+f_cdrag_ter=1.
+f_cdrag_oce=0.7
+f_ri_cd_min=0.6
+#cdmmax
+cdmmax=2.5E-3
+#cdhmax
+cdhmax=2.0E-3
+##  Orodr  ou  non   pour l orographie
+ok_orodr=y
+##  Orolf  ou  non   pour l orographie              
+ok_orolf=y
+#Rugoro
+f_rugoro=0.
+#
+### Random gravity waves
+#Activitate the stochastic parameterization of convective GWs (should be equal to ok_strato)
+ok_gwd_rando=y
+# Scale the momentum fluxes due to convective GWs
+gwd_rando_ruwmax=2.5
+#Scale the saturated momentum flux of  convective GWs 
+gwd_rando_sat=0.2
+
+sso_gkdrag=0.2
+sso_gfrcri=0.70
+sso_gkwake=0.40
+#
+# Rayonnement
+#*********************
+# activation du nouveau code de rayonnement RRTM
+# 0 : Ancien code et 1 : RRTM (D=0)
+iflag_rrtm=1
+NSW=6
+#
+# Parametres nuages
+#******************
+#seuils de la precipitation des nuages strateformes (D: 2.6e-4 2.6e-4)
+cld_lc_lsc=0.00022
+cld_lc_con=0.00022
+#constante de temps pour eleminer eau lsc et convective (D: 3600. 3600.)
+cld_tau_lsc=1200.
+cld_tau_con=1200.
+#facteurs correctifs sur la vitesse de chute des cristaux de glace (D: 1 1)
+ffallv_lsc=0.67
+ffallv_con=0.67
+#coefficient sur la reevaporation de la pluie (D: 2.e-5 n)
+coef_eva=2e-5
+reevap_ice=y
+#calcul des proprietes des nuages convectifs (D:1 0.375 1.e-4) 
+iflag_cldcon=6
+fact_cldcon=1.
+facttemps=0.
+#calcul eau condensee et fraction nuageuse a partir des PDF (D:0, 0:version avec ratqs sinon nouvelles PDFs)  
+iflag_pdf=1
+#calcul epaisseur optique et emmissivite des nuages (D: y 1 0.01 0.3)
+ok_newmicro=y
+iflag_ratqs=4
+ratqsbas=0.002
+ratqshaut=0.312
+#rayon effectif pour les nuages de glace (D:35)
+rad_froid=35
+#rayons effectifs pour les nuages eau liq (tailles des gouttes d eau nuageuse, D: 13 9)
+rad_chau1=12
+rad_chau2=11
+##  Choix ou non  de  New oliq               
+new_oliq=y
+#Rayons min et max effectifs des particules des nuages
+rei_min=16.
+rei_max=61.29
+#
+# Flags Convection 
+#*****************
+#Convection scheme switch (D:2, 1:LMD, 2:Tiedtke, 3:KE New Physics, 30:KE AR4)
+iflag_con=3
+#output level of energy conservation diagnostics
+if_ebil=0
+#maximum efficiency of cld water->precipitation conversion (D: 0.993)
+epmax=0.999
+#dry convective adjustment at beginning of Emanuel convective scheme (D: n 0)
+ok_adj_ema=n
+iflag_clw=0
+#Convective closure (D:1, 0:AR4, 2:ALE and ALP)
+iflag_clos=2
+#Convective entrainment mixing law (D:1, 0:AR4=flat PDF, 1=PDF)
+iflag_mix=1
+#weights of the bell shaped and flat PDF (used only if iflag_mix=1) (D: 1 0)
+qqa1=1.
+qqa2=0.
+#Parameters of the bell shaped PDF; Fmax=center (D= 0.65), Gammas=width (D=0.05)
+cvl_corr=1.0
+#Multiplicative factor of Emanuel convective scheme precipitation (D: 1.)
+Fmax=0.65
+#
+# Flags Couche limite
+#********************
+#shema de CL des thermiques (D:0, 0:ajustement sec,=>1:versions thermiques) 
+iflag_thermals=18
+#pas de temps du spliting pour les thermiques
+nsplit_thermals=1
+tau_thermals=0.
+iflag_thermals_ed=8
+fact_thermals_ed_dz=0.1
+iflag_thermals_optflux=0
+#shema de la couche de surface (D:1, 1:LMD, 8:Mellor-Yamada) 
+iflag_pbl=11
+#diffusion turbulente
+ksta_ter=1.e-7
+ksta=1.e-10
+#ok_kzmin : calcul Kzmin dans la CL de surface
+ok_kzmin=y
+#couplage ou non avec la convection
+iflag_coupl=5 (0:AR4 et 1:nouvelle physique)
+seuil_inversion=-0.08
+#rendement sur la puissance fournie par les thermiques a la convection
+alp_bl_k=0.5
+#
+## temperature dependency of qsat for iterative procedure
+## temporary flag to switch between the old (CMIP5, D=0) and new versions (=1) versions 
+iflag_fisrtilp_qsat=4 
+## Reactivation du calcul d'un zmax continu pour les thermiques
+## reactivation d'une fermeture humide des thermiques  iflag_thermals_closure=2 (D=1)
+iflag_thermals_closure=1
+#
+# Flags wakes
+#************
+#Wake scheme switch (D:0, 0:AR4, 1:New Physics)
+iflag_wake=1
+#Constant value to be added to Alp (D: 0.)
+alp_offset=0.
+
+### nrlmd le 10/04/2012: Declenchement ###
+#Déclelenchement par couche-limite (0: deterministe, 1: stochastique)
+iflag_trig_bl=1
+#Surface critique au LCL
+s_trig=1.2e7
+#Temps de decorrelation entre scenes de cumulus
+tau_trig_shallow=1200
+#Temps de decorrelation entre scenes de cumulonimbus
+tau_trig_deep=1200
+# Pour la stabilisation
+random_notrig_max=0.99
+ok_adjwk=y
+tmax_fonte_cv=278.15
+
+
+### nrlmd le 10/04/2012: Fermeture ###
+#Fermeture par couche-limite (0: deterministe, 1: statistique, 2: statistique+convergence grande échelle)
+iflag_clos_bl=1
+### fin nrlmd le 10/04/2012
+
+## Modification de la plage de temperature pour la phase mixte liquide/glace des nuages
+## Controle par les t_glace_min/max, exposant_glace, iflag_t_glace (D=0)
+t_glace_min=233.13
+t_glace_max=273.13
+exposant_glace=1.
+iflag_t_glace=1
+iflag_ice_thermo=1
+
+#
+## The source terms of the TKE prognostic equation are diagnosed from tendencies (du, dv, dT) 
+## associated with subrgrid scaleamotions and treated as an additional heat source.
+## Controled by a key, iflag_ener_conserv (D=-1):
+## 0 : no conservation, -1 : old adhoc correction for kinetic E only (used for CMIP5) 
+## 1 : conservation, 101 : conversion from kinetic to heat only, 110 conversion from potential to heat only
+iflag_ener_conserv=1
+
+#Activation of corrections for water conservation (D: n). 
+##The default is n for compatibility with earlier versions.
+##generally it should be y.
+ok_conserv_q=y 
+
+iflag_cloudth_vert=1
+
+#
+lmixmin=10.
+
+#Bergeron
+iflag_bergeron=1
+
+################################################################################
+### Convection.def file
+#altitude, in hPa, above LCL at which buoybase is computed, def = original: -40
+dpbase=-40.
+#altitude, in hPa, above LCL below which Ep=0, def = original: 150, used only if flag_epKEorig=0
+pbcrit=150.0
+#altitude, in hPa, above LCL above which Ep=Epmax, def = original: 500, used only if flag_epKEorig=0
+ptcrit=500.0
+#reference fractional area of precipitating downdraughts, def = original: 0.01
+sigdz=0.01
+#unsaturated fraction of precipitating downdraughts, def = original: 0.15
+spfac=0.15
+#relaxation time of cloud base mass flux, def = original: 8000
+tau=8000.
+#flag for wb (= vert velocity at LFC); 0->wb=wbmax, 1->wb=f(plfc) bounded, 2->wb=f(plfc) linear, def = 1
+flag_wb=1
+#parameter used in the computation of wb, def = 6.
+wbmax=6.
+#
+ok_convstop=.False.
+#
+tau_stop=15000.
+#
+ok_intermittent=.False.
+#shedding coefficient (used when iflag_mix_adiab=1)
+coef_peel=0.25
+#
+### Clouds
+#Conversion cld water->precip: Ep=f(pressure) if 0; Ep=f(temperature) if 1, def=1
+flag_epKEorig=1
+#max condensed water concentration in kg/kg, def=0.0003, original: 0.0011, used only if flag_epKEorig=1
+elcrit=0.0003
+#temperature in degre Celsius, at which Ep=Epmax, def=-55., original: -55, used only if flag_epKEorig=1
+tlcrit=-55.0
+
+### Wakes
+#coefficient in Wape->C_star formula: C_star=stark*sqrt(2*Wape), def: 0.33
+stark=0.33
+#lifting efficiency of wakes; Alp=Alpk*Fip, Fip=power provided by wakes, def: 0.25
+alpk=0.25
+#wake density = number of wake centers per m2, def: 8.E-12
+wdens_ref=8.E-12
+#multiplicative factor of the damping by gravity waves, def: 4.
+coefgw=4.
+##################################################################################
+#### End of convection.def inclusion
Index: /LMDZ5/branches/testing/DefLists/traceur.def
===================================================================
--- /LMDZ5/branches/testing/DefLists/traceur.def	(revision 2541)
+++ /LMDZ5/branches/testing/DefLists/traceur.def	(revision 2542)
@@ -1,5 +1,7 @@
-4
+6
 14 14 H2Ov
 10 10 H2Ol
+10 10 H2Oi
+10 10 Aga
 10 10 RN
 10 10 PB
Index: /LMDZ5/branches/testing/libf/dynphy_lonlat/grid_atob_m.f90
===================================================================
--- /LMDZ5/branches/testing/libf/dynphy_lonlat/grid_atob_m.f90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/dynphy_lonlat/grid_atob_m.f90	(revision 2542)
@@ -29,14 +29,16 @@
 ! Local variables:
   CHARACTER(LEN=256) :: modname="fine2coarse"
-  INTEGER :: mi, ni, ii, ji, mo, no, io, jo, nr(2), m1, n1, m2, n2, mx, my, nn
-  LOGICAL :: li, lo
-  REAL    :: inc
+  INTEGER :: mi, ni, ii, ji, mo, no, io, jo, nr(2), m1,m2, n1,n2, mx,my, nn, i,j
+  LOGICAL :: li, lo, first=.TRUE.
+  REAL    :: inc, cpa, spa, crlo(SIZE(x_i))
+  REAL, SAVE :: pi, hpi
   INTEGER, DIMENSION(SIZE(x_o),SIZE(y_o)) :: num_tot
   LOGICAL, DIMENSION(SIZE(x_o),SIZE(y_o)) :: found, mask
-  REAL,    DIMENSION(SIZE(x_o),SIZE(y_o)) :: dist
+  REAL,    DIMENSION(SIZE(x_i),SIZE(y_i)) :: dist
   REAL,    DIMENSION(SIZE(x_o))           :: a, b
   REAL,    DIMENSION(SIZE(y_o))           :: c, d
   REAL,    PARAMETER :: thresh=1.E-5
 !-------------------------------------------------------------------------------
+  IF(first) THEN; pi=4.0*ATAN(1.0); hpi=pi/2.0; first=.FALSE.; END IF
   mi=SIZE(x_i); ni=SIZE(y_i); mo=SIZE(x_o); no=SIZE(y_o)
   m1=m1; m2=mo; mx=mo; IF(PRESENT(msk)) mx=SIZE(msk,1)
@@ -91,5 +93,7 @@
       IF(found(io,jo)) CYCLE
 !      IF(prt_level>=1) PRINT*, "Problem: point out of domain (i,j)=", io,jo
-      CALL dist_sphe(x_o(io),y_o(jo),x_i,y_i,dist(:,:))
+      crlo(:)=COS(x_o(io)-x_i(:))     !--- COS of points 1 and 2 angle
+      cpa=COS(y_o(jo)); spa=SIN(y_o(jo))
+      DO j=1,ni; dist(:,j)=ACOS(spa*SIN(y_i(j))+cpa*COS(y_i(j))*crlo(:)); END DO
       nr=MINLOC(dist(:,:))!; IF(prt_level>=1) PRINT*, "Solution: ", nr
       inc=1.0; IF(li) inc=d_i(nr(1),nr(2))
@@ -252,39 +256,4 @@
 !-------------------------------------------------------------------------------
 
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE dist_sphe(rf_lon,rf_lat,rlon,rlat,distance)
-!
-!-------------------------------------------------------------------------------
-! Author:  Laurent Li (december 30th 1996).
-! Purpose: Compute min. distance (along big circle) between 2 points in radians.
-!-------------------------------------------------------------------------------
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  REAL, INTENT(IN) :: rf_lon, rf_lat  !--- Reference point coordinates (radians)
-  REAL, INTENT(IN) :: rlon(:), rlat(:)!--- Points longitudes/latitudes (radians)
-  REAL, INTENT(OUT):: distance(SIZE(rlon),SIZE(rlat)) !--- Distance    (radians)
-!-------------------------------------------------------------------------------
-! Local variables:
-  LOGICAL, SAVE :: first=.TRUE.
-  REAL,    SAVE :: pi, hpi
-  REAL    :: pa, pb, cpa, spa, crlo(SIZE(rlon))
-  INTEGER :: i, j
-!-------------------------------------------------------------------------------
-  IF(first) THEN; pi=4.0*ATAN(1.0); hpi=pi/2.0; first=.FALSE.; END IF
-  crlo(:)=COS(rf_lon-rlon(:))         !--- COS of points 1 and 2 angle
-  pa=hpi-rf_lat                       !--- North Pole - Point 1 distance
-  cpa=COS(pa); spa=SIN(pa)
-  DO j=1,SIZE(rlat)
-    pb=hpi-rlat(j)                    !--- North Pole - Point 2 distance
-    distance(:,j)=ACOS(cpa*COS(pb)+spa*SIN(pb)*crlo(:))
-  END DO
-
-END SUBROUTINE dist_sphe
-!
-!-------------------------------------------------------------------------------
-
 END MODULE grid_atob_m
 !
Index: /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/etat0phys_netcdf.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/etat0phys_netcdf.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/etat0phys_netcdf.F90	(revision 2542)
@@ -111,5 +111,5 @@
   LOGICAL :: ok_ade, ok_aie, ok_cdnc, aerosol_couple
   INTEGER :: flag_aerosol
-  LOGICAL :: flag_aerosol_strat
+  INTEGER :: flag_aerosol_strat
   LOGICAL :: new_aod
   REAL    :: bl95_b0, bl95_b1
Index: /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/limit_netcdf.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/limit_netcdf.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/limit_netcdf.F90	(revision 2542)
@@ -60,4 +60,5 @@
 !  *    11/2009: L. Guez     (ozone day & night climatos, see etat0_netcdf.F90)
 !  *    12/2009: D. Cugnet   (f77->f90, calendars, files from coupled runs)
+!  *    04/2016: D. Cugnet   (12/14 recs SST/SIC files: cyclic/interannual runs)
 !-------------------------------------------------------------------------------
 #ifndef CPP_1D
@@ -339,7 +340,7 @@
   INTEGER           :: ndays_in           ! number of days
 !--- misc
-  INTEGER           :: i, j, k, l         ! loop counters
+  INTEGER           :: i, j, k, l, ll     ! loop counters
   REAL, ALLOCATABLE :: work(:,:)          ! used for extrapolation
-  CHARACTER(LEN=25) :: title              ! for messages
+  CHARACTER(LEN=128):: title, mess        ! for messages
   LOGICAL           :: extrp              ! flag for extrapolation
   REAL              :: chmin, chmax
@@ -392,5 +393,5 @@
 !--- Time (variable is not needed - it is rebuilt - but calendar is)
   CALL ncerr(NF90_INQUIRE_DIMENSION(ncid, dids(3), name=dnam, len=lmdep), fnam)
-  ALLOCATE(timeyear(lmdep))
+  ALLOCATE(timeyear(MAX(lmdep,14)))
   CALL ncerr(NF90_INQ_VARID(ncid, dnam, varid), fnam)
   cal_in=' '
@@ -405,16 +406,25 @@
   CALL msg(5,'var, calendar, dim: '//TRIM(dnam)//' '//TRIM(cal_in), lmdep)
   
-!--- CONSTRUCTING THE INPUT TIME VECTOR FOR INTERPOLATION --------------------
-  !--- Determining input file number of days, depending on calendar
+!--- Determining input file number of days, depending on calendar
   ndays_in=year_len(anneeref, cal_in)
 
-!--- Time vector reconstruction (time vector from file is not trusted)
-!--- If input records are not monthly, time sampling has to be constant !
-  timeyear=mid_months(anneeref, cal_in, lmdep)
-  IF (lmdep /= 12) WRITE(lunout,*) 'Note : les fichiers de ', TRIM(mode), &
-       ' ne comportent pas 12, mais ', lmdep, ' enregistrements.'
+!--- Rebuilding input time vector (field from input file might be unreliable)
+  IF(lmdep==12) THEN
+    timeyear=mid_month(anneeref, cal_in, ndays_in)
+    CALL msg(0,'Monthly periodic input file (perpetual run).')
+  ELSE IF(lmdep==14) THEN
+    timeyear=mid_month(anneeref, cal_in, ndays_in)
+    CALL msg(0,'Monthly 14-records input file (interannual run).')
+  ELSE IF(lmdep==ndays_in) THEN
+    timeyear=[(REAL(k)-0.5,k=1,ndays_in)]
+    CALL msg(0,'Daily input file (no time interpolation).')
+  ELSE
+    WRITE(mess,'(a,i3,a,i3,a)')'Mismatching input file: found',lmdep,        &
+      ' records, 12/14/',ndays_in,' (periodic/interannual/daily) needed'
+    CALL abort_physic('mid_months',TRIM(mess),1)
+  END IF
 
 !--- GETTING THE FIELD AND INTERPOLATING IT ----------------------------------
-  ALLOCATE(champ(imdep, jmdep), champtime(iim, jjp1, lmdep))
+  ALLOCATE(champ(imdep, jmdep), champtime(iim, jjp1, MAX(lmdep,14)))
   IF(extrp) ALLOCATE(work(imdep, jmdep))
   CALL msg(5,'')
@@ -436,6 +446,12 @@
       WHERE(NINT(mask)/=1) champint=0.001
     END IF
-    champtime(:, :, l)=champint
+    !--- Special case for periodic input file: index shifted
+    ll = l; IF(lmdep==12) ll = l + 1
+    champtime(:, :, ll)=champint
   END DO
+  IF(lmdep==12) THEN
+    champtime(:,:, 1)=champtime(:,:,13)
+    champtime(:,:,14)=champtime(:,:, 2)
+  END IF
   CALL ncerr(NF90_CLOSE(ncid), fnam)
 
@@ -444,27 +460,39 @@
 
 !--- TIME INTERPOLATION ------------------------------------------------------
-  IF(prt_level>5) THEN
-     WRITE(lunout, *)
-     WRITE(lunout, *)'INTERPOLATION TEMPORELLE.'
-     WRITE(lunout, *)' Vecteur temps en entree: ', timeyear
-     WRITE(lunout, *)' Vecteur temps en sortie de 0 a ', ndays
-  END IF
-
-  ALLOCATE(yder(lmdep), champan(iip1, jjp1, ndays))
-  skip = .false.
-  n_extrap = 0
-  DO j=1, jjp1
-    DO i=1, iim
-      yder = pchsp_95(timeyear, champtime(i, j, :), ibeg=2, iend=2, &
-           vc_beg=0., vc_end=0.)
-      CALL pchfe_95(timeyear, champtime(i, j, :), yder, skip, &
-           arth(0., real(ndays_in) / ndays, ndays), champan(i, j, :), ierr)
-      if (ierr < 0) stop 1
-      n_extrap = n_extrap + ierr
-    END DO
-  END DO
-  if (n_extrap /= 0) then
-     WRITE(lunout,*) "get_2Dfield pchfe_95: n_extrap = ", n_extrap
-  end if
+  IF(prt_level>0) THEN
+     IF(ndays/=ndays_in) THEN
+        WRITE(lunout, *)
+        WRITE(lunout,*)'DIFFERENTES LONGEURS D ANNEES:'
+        WRITE(lunout,*)' Dans le fichier d entree: ',ndays_in
+        WRITE(lunout,*)' Dans le fichier de sortie: ',ndays
+     END IF
+     IF(lmdep==ndays_in) THEN
+        WRITE(lunout, *)
+        WRITE(lunout, *)'PAS D INTERPOLATION TEMPORELLE.'
+        WRITE(lunout, *)' Fichier journalier en entree.'
+     ELSE
+        WRITE(lunout, *)'INTERPOLATION TEMPORELLE.'
+        WRITE(lunout, *)' Vecteur temps en entree: ', timeyear
+        WRITE(lunout, *)' Vecteur temps en sortie de 0 a ', ndays-1
+     END IF
+  END IF
+  ALLOCATE(yder(MAX(lmdep,14)), champan(iip1, jjp1, ndays))
+  IF(lmdep==ndays_in) THEN
+     champan(1:iim,:,:)=champtime
+  ELSE
+     skip = .false.
+     n_extrap = 0
+     DO j=1, jjp1
+       DO i=1, iim
+         yder = pchsp_95(timeyear, champtime(i, j, :), ibeg=2, iend=2, &
+              vc_beg=0., vc_end=0.)
+         CALL pchfe_95(timeyear, champtime(i, j, :), yder, skip, &
+              arth(0., real(ndays_in) / ndays, ndays), champan(i, j, :), ierr)
+         if (ierr < 0) stop 1
+         n_extrap = n_extrap + ierr
+       END DO
+     END DO
+     IF(n_extrap /= 0) WRITE(lunout,*) "get_2Dfield pchfe_95: n_extrap = ", n_extrap
+  END IF
   champan(iip1, :, :)=champan(1, :, :)
   DEALLOCATE(yder, champtime, timeyear)
@@ -752,5 +780,5 @@
 !-------------------------------------------------------------------------------
 !
-FUNCTION mid_months(y,cal_in,nm)
+FUNCTION mid_month(y,cal_in,ndays_out)
 !
 !-------------------------------------------------------------------------------
@@ -758,48 +786,35 @@
 !-------------------------------------------------------------------------------
 ! Arguments:
-  INTEGER,                INTENT(IN) :: y               ! year
-  CHARACTER(LEN=*),       INTENT(IN) :: cal_in          ! calendar
-  INTEGER,                INTENT(IN) :: nm              ! months/year number
-  REAL,    DIMENSION(nm)             :: mid_months      ! mid-month times
+  INTEGER,          INTENT(IN) :: y           ! year
+  CHARACTER(LEN=*), INTENT(IN) :: cal_in      ! calendar
+  INTEGER,          INTENT(IN) :: ndays_out   ! days   number
+  REAL,          DIMENSION(14) :: mid_month   ! mid-bins times
 !-------------------------------------------------------------------------------
 ! Local variables:
-  CHARACTER(LEN=99)                  :: mess            ! error message
-  CHARACTER(LEN=20)                  :: cal_out         ! calendar (for outputs)
-  INTEGER, DIMENSION(nm)             :: mnth            ! months lengths (days)
-  INTEGER                            :: m               ! months counter
-  INTEGER                            :: nd              ! number of days
-!-------------------------------------------------------------------------------
-  nd=year_len(y,cal_in)
-
-  IF(nm==12) THEN
-
-  !--- Getting the input calendar to reset at the end of the function
-    CALL ioget_calendar(cal_out)
-
-  !--- Unlocking calendar and setting it to wanted one
-    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
-
-  !--- Getting the length of each month
-    DO m=1,nm; mnth(m)=ioget_mon_len(y,m); END DO
+  CHARACTER(LEN=99)      :: mess              ! error message
+  CHARACTER(LEN=20)      :: cal_out           ! output calendar
+  INTEGER, DIMENSION(14) :: tlen              ! months lengths (days)
+  INTEGER                :: m                 ! months counter
+  INTEGER                :: nd                ! number of days
+!-------------------------------------------------------------------------------
+  !--- Save the input calendar to reset it at the end of the function
+  CALL ioget_calendar(cal_out)
+
+  !--- Unlock calendar and set it to "cal_in"
+  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
+
+  !--- Get the length of each month
+  tlen(1 )=ioget_mon_len(y-1,12)
+  DO m=1,12; tlen(m+1)=ioget_mon_len(y,m); END DO
+  tlen(14)=ioget_mon_len(y+1, 1)
+
+  !--- Mid-bins times
+  mid_month(1)=-0.5*REAL(tlen(1))
+  DO m=2,14; mid_month(m)=mid_month(m-1)+0.5*REAL(tlen(m-1)+tlen(m)); END DO
 
   !--- Back to original calendar
-    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
-
-  ELSE IF(MODULO(nd,nm)/=0) THEN
-    WRITE(mess,'(a,i3,a,i3,a)')'Unconsistent calendar: ',nd,' days/year, but ',&
-      nm,' months/year. Months number should divide days number.'
-    CALL abort_physic('mid_months',TRIM(mess),1)
-
-  ELSE
-    mnth=[(m,m=1,nm,nd/nm)]
-  END IF
-
-!--- Mid-months times
-  mid_months(1)=0.5*REAL(mnth(1))
-  DO k=2,nm
-    mid_months(k)=mid_months(k-1)+0.5*REAL(mnth(k-1)+mnth(k))
-  END DO
-
-END FUNCTION mid_months
+  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
+
+END FUNCTION mid_month
 !
 !-------------------------------------------------------------------------------
@@ -863,2 +878,3 @@
 !
 !*******************************************************************************
+
Index: /LMDZ5/branches/testing/libf/misc/wxios.F90
===================================================================
--- /LMDZ5/branches/testing/libf/misc/wxios.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/misc/wxios.F90	(revision 2542)
@@ -1,3 +1,3 @@
-! $Id: wxios.F90 $
+! $Id$
 #ifdef CPP_XIOS
 MODULE wxios
@@ -33,5 +33,9 @@
     SUBROUTINE reformadate(odate, ndate)
         CHARACTER(len=*), INTENT(IN) :: odate
+#ifdef XIOS1
         CHARACTER(len=100), INTENT(OUT) :: ndate
+#else
+        TYPE(xios_duration) :: ndate
+#endif
         
         INTEGER :: i = 0
@@ -48,15 +52,27 @@
         i = INDEX(odate, "day")
         IF (i > 0) THEN
+#ifdef XIOS1
             ndate = odate(1:i-1)//"d"
+#else
+            read(odate(1:i-1),*) ndate%day
+#endif
         END IF
 
         i = INDEX(odate, "hr")
         IF (i > 0) THEN
+#ifdef XIOS1
             ndate = odate(1:i-1)//"h"
+#else
+            read(odate(1:i-1),*) ndate%hour
+#endif
         END IF
 
         i = INDEX(odate, "mth")
         IF (i > 0) THEN
+#ifdef XIOS1
             ndate = odate(1:i-1)//"mo"
+#else
+            read(odate(1:i-1),*) ndate%month
+#endif
         END IF
         
@@ -99,6 +115,6 @@
 
     SUBROUTINE wxios_init(xios_ctx_name, locom, outcom, type_ocean)
-        IMPLICIT NONE
-        INCLUDE 'iniprint.h'
+        USE print_control_mod, ONLY : prt_level, lunout
+        IMPLICIT NONE
 
       CHARACTER(len=*), INTENT(IN) :: xios_ctx_name
@@ -140,9 +156,11 @@
 
     SUBROUTINE wxios_context_init()
-        IMPLICIT NONE
-        INCLUDE 'iniprint.h'
+        USE print_control_mod, ONLY : prt_level, lunout
+!        USE mod_phys_lmdz_mpi_data, ONLY : COMM_LMDZ_PHY
+        IMPLICIT NONE
 
         TYPE(xios_context) :: xios_ctx
 
+!$OMP MASTER
         !Initialisation du contexte:
         CALL xios_context_initialize(g_ctx_name, g_comm)
@@ -157,4 +175,5 @@
         !Une première analyse des héritages:
         CALL xios_solve_inheritance()
+!$OMP END MASTER
     END SUBROUTINE wxios_context_init
 
@@ -164,6 +183,6 @@
 
     SUBROUTINE wxios_set_cal(pasdetemps, calendrier, annee, mois, jour, heure, ini_an, ini_mois, ini_jour, ini_heure)
-        IMPLICIT NONE
-        INCLUDE 'iniprint.h'
+        USE print_control_mod, ONLY : prt_level, lunout
+        IMPLICIT NONE
 
      !Paramètres:
@@ -178,10 +197,19 @@
      
      !Variables pour xios:
+#ifdef XIOS1
      TYPE(xios_time) :: mdtime
+#else
+     TYPE(xios_duration) :: mdtime
+#endif
      !REAL(kind = 8) :: year=0, month=0, day=0, hour=0, minute=0, second=0
      
+#ifdef XIOS1
         mdtime = xios_time(0, 0, 0, 0, 0, pasdetemps)
+#else
+        mdtime%second=pasdetemps
+#endif
 
         !Réglage du calendrier:
+#ifdef XIOS1
         SELECT CASE (calendrier)
             CASE('earth_360d')
@@ -198,11 +226,30 @@
                 CALL abort_gcm('Gcm:Xios',abort_message,1)
         END SELECT
+#else
+        SELECT CASE (calendrier)
+            CASE('earth_360d')
+                CALL xios_define_calendar("D360")
+                IF (prt_level >= 10) WRITE(lunout,*) 'wxios_set_cal: Calendrier terrestre a 360 jours/an'
+            CASE('earth_365d')
+                CALL xios_define_calendar("NoLeap")
+                IF (prt_level >= 10) WRITE(lunout,*) 'wxios_set_cal: Calendrier terrestre a 365 jours/an'
+            CASE('gregorian')
+                CALL xios_define_calendar("Gregorian")
+                IF (prt_level >= 10) WRITE(lunout,*) 'wxios_set_cal: Calendrier gregorien'
+            CASE DEFAULT
+                abort_message = 'wxios_set_cal: Mauvais choix de calendrier'
+                CALL abort_gcm('Gcm:Xios',abort_message,1)
+        END SELECT
+#endif
         
         !Formatage de la date d'origine:
-        WRITE(date, "(i4.4,'-',i2.2,'-',i2.2,' ',i2.2,':00:00')") annee, mois, jour, int(heure)
+        WRITE(date, "(i4.4,'-',i2.2,'-',i2.2,' ',i2.2,':00:00')") annee, mois, jour, int(heure) 
         
         IF (prt_level >= 10) WRITE(lunout,*) "wxios_set_cal: Time origin: ", date
-        
+#ifdef XIOS1
         CALL xios_set_context_attr_hdl(g_ctx, time_origin = date)
+#else
+        CALL xios_set_time_origin(xios_date(annee,mois,jour,int(heure),0,0))
+#endif
 
         !Formatage de la date de debut:
@@ -212,5 +259,9 @@
         IF (prt_level >= 10) WRITE(lunout,*) "wxios_set_cal: Start date: ", date
         
+#ifdef XIOS1
         CALL xios_set_context_attr_hdl(g_ctx, start_date = date)
+#else
+        CALL xios_set_start_date(xios_date(ini_an,ini_mois,ini_jour,int(ini_heure),0,0))
+#endif
         
         !Et enfin,le pas de temps:
@@ -221,7 +272,13 @@
     SUBROUTINE wxios_set_timestep(ts)
         REAL, INTENT(IN) :: ts
+#ifdef XIOS1
         TYPE(xios_time) :: mdtime     
 
         mdtime = xios_time(0, 0, 0, 0, 0, ts)
+#else
+        TYPE(xios_duration) :: mdtime     
+
+        mdtime%timestep = ts
+#endif
 
         CALL xios_set_timestep(mdtime)
@@ -237,6 +294,6 @@
          
 
-        IMPLICIT NONE
-        INCLUDE 'iniprint.h'
+        USE print_control_mod, ONLY : prt_level, lunout
+        IMPLICIT NONE
 
         CHARACTER(len=*),INTENT(IN) :: dom_id ! domain identifier
@@ -277,8 +334,13 @@
         
         !On parametrise le domaine:
+#ifdef XIOS1
         CALL xios_set_domain_attr_hdl(dom, ni_glo=ni_glo, ibegin=ibegin, ni=ni)
         CALL xios_set_domain_attr_hdl(dom, nj_glo=nj_glo, jbegin=jbegin, nj=nj, data_dim=2)
         CALL xios_set_domain_attr_hdl(dom, lonvalue=io_lon(ibegin:iend), latvalue=io_lat(jbegin:jend))
-
+#else
+        CALL xios_set_domain_attr_hdl(dom, ni_glo=ni_glo, ibegin=ibegin-1, ni=ni, type="rectilinear")
+        CALL xios_set_domain_attr_hdl(dom, nj_glo=nj_glo, jbegin=jbegin-1, nj=nj, data_dim=2)
+        CALL xios_set_domain_attr_hdl(dom, lonvalue_1d=io_lon(ibegin:iend), latvalue_1d=io_lat(jbegin:jend))
+#endif
         IF (.NOT.is_sequential) THEN
             mask(:,:)=.TRUE.
@@ -291,5 +353,9 @@
               WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," mask(:,nj)=",mask(:,nj)
             ENDIF
+#ifdef XIOS1
             CALL xios_set_domain_attr_hdl(dom, mask=mask)
+#else
+            CALL xios_set_domain_attr_hdl(dom, mask_2d=mask)
+#endif
         END IF
 
@@ -307,6 +373,6 @@
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     SUBROUTINE wxios_add_vaxis(axis_id, axis_size, axis_value)
-        IMPLICIT NONE
-        INCLUDE 'iniprint.h'
+        USE print_control_mod, ONLY : prt_level, lunout
+        IMPLICIT NONE
 
         CHARACTER (len=*), INTENT(IN) :: axis_id
@@ -335,6 +401,9 @@
         
         ! Ehouarn: New way to declare axis, without axis_group:
+#ifdef XIOS1
         CALL xios_set_axis_attr(trim(axis_id),size=axis_size,value=axis_value)
-        
+#else
+        CALL xios_set_axis_attr(trim(axis_id),n_glo=axis_size,value=axis_value)
+#endif        
         !Vérification:
         IF (xios_is_valid_axis(TRIM(ADJUSTL(axis_id)))) THEN
@@ -351,6 +420,6 @@
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     SUBROUTINE wxios_add_file(fname, ffreq, flvl)
-        IMPLICIT NONE
-        INCLUDE 'iniprint.h'
+        USE print_control_mod, ONLY : prt_level, lunout
+        IMPLICIT NONE
 
         CHARACTER(len=*), INTENT(IN) :: fname
@@ -360,5 +429,9 @@
         TYPE(xios_file) :: x_file
         TYPE(xios_filegroup) :: x_fg
+#ifdef XIOS1
         CHARACTER(len=100) :: nffreq
+#else
+        TYPE(xios_duration) :: nffreq
+#endif
         
         !On regarde si le fichier n'est pas défini par XML:
@@ -372,15 +445,28 @@
         
             !On configure:
+#ifdef XIOS1
             CALL xios_set_file_attr_hdl(x_file, name="X"//fname,&
                 output_freq=TRIM(ADJUSTL(nffreq)), output_level=flvl, enabled=.TRUE.)
-        
+#else
+            CALL xios_set_file_attr_hdl(x_file, name="X"//fname,&
+                output_freq=nffreq, output_level=flvl, enabled=.TRUE.)
+#endif
+       
             IF (xios_is_valid_file("X"//fname)) THEN
                 IF (prt_level >= 10) THEN
                   WRITE(lunout,*) "wxios_add_file: New file: ", "X"//fname
+#ifdef XIOS1
                   WRITE(lunout,*) "wxios_add_file: output_freq=",TRIM(ADJUSTL(nffreq)),"; output_lvl=",flvl
+#else
+                  WRITE(lunout,*) "wxios_add_file: output_freq=",nffreq,"; output_lvl=",flvl
+#endif
                 ENDIF
             ELSE
                 WRITE(lunout,*) "wxios_add_file: Error, invalid file: ", "X"//trim(fname)
+#ifdef XIOS1
                 WRITE(lunout,*) "wxios_add_file: output_freq=",TRIM(ADJUSTL(nffreq)),"; output_lvl=",flvl
+#else
+                WRITE(lunout,*) "wxios_add_file: output_freq=",nffreq,"; output_lvl=",flvl
+#endif
             END IF
         ELSE
@@ -435,6 +521,6 @@
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     SUBROUTINE wxios_add_field_to_file(fieldname, fdim, fid, fname, fieldlongname, fieldunit, field_level, op, nam_axvert)
-        IMPLICIT NONE
-        INCLUDE 'iniprint.h'
+        USE print_control_mod, ONLY : prt_level, lunout
+        IMPLICIT NONE
 
         CHARACTER(len=*), INTENT(IN) :: fieldname
@@ -452,4 +538,7 @@
         TYPE(xios_field) :: field
         TYPE(xios_fieldgroup) :: fieldgroup
+#ifndef XIOS1
+        TYPE(xios_duration) :: freq_op
+#endif
         LOGICAL :: bool=.FALSE.
         INTEGER :: lvl =0
@@ -510,5 +599,10 @@
             
             !L'operation, sa frequence:
+#ifdef XIOS1
             CALL xios_set_field_attr_hdl(field, field_ref=fieldname, operation=TRIM(ADJUSTL(operation)), freq_op="1ts", prec=4)
+#else
+            freq_op%timestep=1
+            CALL xios_set_field_attr_hdl(field, field_ref=fieldname, operation=TRIM(ADJUSTL(operation)), freq_op=freq_op, prec=4)
+#endif
 
             
Index: /LMDZ5/branches/testing/libf/phylmd/alpale.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/alpale.F90	(revision 2542)
+++ /LMDZ5/branches/testing/libf/phylmd/alpale.F90	(revision 2542)
@@ -0,0 +1,197 @@
+SUBROUTINE alpale ( debut, itap, dtime, paprs, omega, t_seri,   &
+                    alp_offset, it_wape_prescr,  wape_prescr, fip_prescr, &
+                    ale_bl_prescr, alp_bl_prescr, &
+                    wake_pe, wake_fip,  &
+                    Ale_bl, Ale_bl_trig, Alp_bl, &
+                    Ale, Alp )
+
+! **************************************************************
+! *
+! ALPALE                                                       *
+! *
+! *
+! written by   : Jean-Yves Grandpeix, 12/05/2016              *
+! modified by :                                               *
+! **************************************************************
+
+  USE dimphy
+  USE ioipsl_getin_p_mod, ONLY : getin_p
+  USE print_control_mod, ONLY: mydebug=>debug , lunout, prt_level
+  USE phys_local_var_mod, ONLY: zw2       ! Variables internes non sauvegardees de la physique
+!
+  IMPLICIT NONE
+
+!================================================================
+! Auteur(s)   : Jean-Yves Grandpeix, 12/05/2016
+! Objet : Sums up all contributions to Ale and Alp
+!================================================================
+
+! Input arguments
+!----------------
+  LOGICAL, INTENT(IN)                                        :: debut
+  INTEGER, INTENT(IN)                                        :: itap
+  REAL, INTENT(IN)                                           :: dtime
+  INTEGER, INTENT(IN)                                        :: it_wape_prescr
+  REAL, INTENT(IN)                                           :: wape_prescr, fip_prescr
+  REAL, INTENT(IN)                                           :: Ale_bl_prescr, Alp_bl_prescr
+  REAL, INTENT(IN)                                           :: alp_offset
+  REAL, DIMENSION(klon,klev+1), INTENT(IN)                   :: paprs
+  REAL, DIMENSION(klon,klev), INTENT(IN)                     :: t_seri
+  REAL, DIMENSION(klon,klev), INTENT(IN)                     :: omega
+  REAL, DIMENSION(klon), INTENT(IN)                          :: wake_pe, wake_fip
+  REAL, DIMENSION(klon), INTENT(IN)                          :: Ale_bl, Ale_bl_trig, Alp_bl
+
+
+! Output arguments
+!----------------
+  REAL, DIMENSION(klon), INTENT(OUT)                         :: Ale, Alp
+
+  include "thermcell.h"
+  include "YOMCST.h"
+  include "YOETHF.h"
+
+! Local variables
+!----------------
+  INTEGER                                                    :: i, k
+  REAL, DIMENSION(klon)                                      :: www
+  REAL, DIMENSION(klon)                                      :: ale_wake, alp_wake
+  REAL, SAVE                                                 :: ale_max=1000.
+  REAL, SAVE                                                 :: alp_max=2.
+  CHARACTER*20 modname
+  CHARACTER*80 abort_message
+
+
+    !$OMP THREADPRIVATE(ale_max,alp_max)
+
+       ! Calcul de l'energie disponible ALE (J/kg) et de la puissance
+       ! disponible ALP (W/m2) pour le soulevement des particules dans
+       ! le modele convectif
+       !
+       do i = 1,klon
+          ALE(i) = 0.
+          ALP(i) = 0.
+       enddo
+       !
+       !calcul de ale_wake et alp_wake
+       if (iflag_wake>=1) then
+          if (itap .le. it_wape_prescr) then
+             do i = 1,klon
+                ale_wake(i) = wape_prescr
+                alp_wake(i) = fip_prescr
+             enddo
+          else
+             do i = 1,klon
+                !jyg  ALE=WAPE au lieu de ALE = 1/2 Cstar**2
+                !cc           ale_wake(i) = 0.5*wake_cstar(i)**2
+                ale_wake(i) = wake_pe(i)
+                alp_wake(i) = wake_fip(i)
+             enddo
+          endif
+       else
+          do i = 1,klon
+             ale_wake(i) = 0.
+             alp_wake(i) = 0.
+          enddo
+       endif
+       !combinaison avec ale et alp de couche limite: constantes si pas
+       !de couplage, valeurs calculees dans le thermique sinon
+       if (iflag_coupl.eq.0) then
+          if (debut.and.prt_level.gt.9) &
+               WRITE(lunout,*)'ALE et ALP imposes'
+          do i = 1,klon
+             !on ne couple que ale
+             !           ALE(i) = max(ale_wake(i),Ale_bl(i))
+             ALE(i) = max(ale_wake(i),ale_bl_prescr)
+             !on ne couple que alp
+             !           ALP(i) = alp_wake(i) + Alp_bl(i)
+             ALP(i) = alp_wake(i) + alp_bl_prescr
+          enddo
+       else
+          IF(prt_level>9)WRITE(lunout,*)'ALE et ALP couples au thermique'
+          !         do i = 1,klon
+          !             ALE(i) = max(ale_wake(i),Ale_bl(i))
+          ! avant        ALP(i) = alp_wake(i) + Alp_bl(i)
+          !             ALP(i) = alp_wake(i) + Alp_bl(i) + alp_offset ! modif sb
+          !         write(20,*)'ALE',ALE(i),Ale_bl(i),ale_wake(i)
+          !         write(21,*)'ALP',ALP(i),Alp_bl(i),alp_wake(i)
+          !         enddo
+
+          ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+          ! Modif FH 2010/04/27. Sans doute temporaire.
+          ! Deux options pour le alp_offset : constant si >?? 0 ou
+          ! proportionnel ??a w si <0
+          ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+          ! Estimation d'une vitesse verticale effective pour ALP
+          if (1==0) THEN
+             www(1:klon)=0.
+             do k=2,klev-1
+                do i=1,klon
+                   www(i)=max(www(i),-omega(i,k)*RD*t_seri(i,k) &
+                        /(RG*paprs(i,k)) *zw2(i,k)*zw2(i,k))
+                   ! if (paprs(i,k)>pbase(i)) then
+                   ! calcul approche de la vitesse verticale en m/s
+                   !  www(i)=max(www(i),-omega(i,k)*RD*temp(i,k)/(RG*paprs(i,k))
+                   !             endif
+                   !   Le 0.1 est en gros H / ps = 1e4 / 1e5
+                enddo
+             enddo
+             do i=1,klon
+                if (www(i)>0. .and. ale_bl(i)>0. ) www(i)=www(i)/ale_bl(i)
+             enddo
+          ENDIF
+
+
+          do i = 1,klon
+             ALE(i) = max(ale_wake(i),Ale_bl(i))
+             !cc nrlmd le 10/04/2012----------Stochastic triggering------------
+             if (iflag_trig_bl.ge.1) then
+                ALE(i) = max(ale_wake(i),Ale_bl_trig(i))
+             endif
+             !cc fin nrlmd le 10/04/2012
+             if (alp_offset>=0.) then
+                ALP(i) = alp_wake(i) + Alp_bl(i) + alp_offset ! modif sb
+             else
+                abort_message ='Ne pas passer la car www non calcule'
+                CALL abort_physic (modname,abort_message,1)
+
+                ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+                !                                _                  _
+                ! Ajout d'une composante 3 * A * w w'2 a w'3 avec
+                ! w=www : w max sous pbase ou A est la fraction
+                ! couverte par les ascendances w' on utilise le fait
+                ! que A * w'3 = ALP et donc A * w'2 ~ ALP / sqrt(ALE)
+                ! (on ajoute 0.1 pour les singularites)
+                ALP(i)=alp_wake(i)*(1.+3.*www(i)/( sqrt(ale_wake(i))+0.1) ) &
+                     +alp_bl(i)  *(1.+3.*www(i)/( sqrt(ale_bl(i))  +0.1) )
+                !    ALP(i)=alp_wake(i)+Alp_bl(i)+alp_offset*min(omega(i,6),0.)
+                !             if (alp(i)<0.) then
+                !                print*,'ALP ',alp(i),alp_wake(i) &
+                !                     ,Alp_bl(i),alp_offset*min(omega(i,6),0.)
+                !             endif
+             endif
+          enddo
+          ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+       endif
+       do i=1,klon
+          if (alp(i)>alp_max) then
+             IF(prt_level>9)WRITE(lunout,*)                             &
+                  'WARNING SUPER ALP (seuil=',alp_max, &
+                  '): i, alp, alp_wake,ale',i,alp(i),alp_wake(i),ale(i)
+             alp(i)=alp_max
+          endif
+          if (ale(i)>ale_max) then
+             IF(prt_level>9)WRITE(lunout,*)                             &
+                  'WARNING SUPER ALE (seuil=',ale_max, &
+                  '): i, alp, alp_wake,ale',i,ale(i),ale_wake(i),alp(i)
+             ale(i)=ale_max
+          endif
+       enddo
+
+       !fin calcul ale et alp
+       !=======================================================================
+
+
+  RETURN
+  END
+
Index: /LMDZ5/branches/testing/libf/phylmd/alpale_th.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/alpale_th.F90	(revision 2542)
+++ /LMDZ5/branches/testing/libf/phylmd/alpale_th.F90	(revision 2542)
@@ -0,0 +1,186 @@
+SUBROUTINE alpale_th ( dtime, lmax_th, t_seri,  &
+                       cin, s2, n2,  &
+                       ale_bl_trig, ale_bl_stat, ale_bl,  &
+                       alp_bl, alp_bl_stat )
+
+! **************************************************************
+! *
+! ALPALE_TH                                                    *
+! *
+! *
+! written by   : Jean-Yves Grandpeix, 11/05/2016              *
+! modified by :                                               *
+! **************************************************************
+
+  USE dimphy
+  USE ioipsl_getin_p_mod, ONLY : getin_p
+  USE print_control_mod, ONLY: mydebug=>debug , lunout, prt_level
+!
+  IMPLICIT NONE
+
+!================================================================
+! Auteur(s)   : Jean-Yves Grandpeix, 11/05/2016
+! Objet : Contribution of the thermal scheme to Ale and Alp
+!================================================================
+
+! Input arguments
+!----------------
+  REAL, INTENT(IN)                                           :: dtime
+  INTEGER, DIMENSION(klon), INTENT(IN)                       :: lmax_th
+  REAL, DIMENSION(klon,klev), INTENT(IN)                     :: t_seri
+  REAL, DIMENSION(klon), INTENT(IN)                          :: ale_bl_stat
+  REAL, DIMENSION(klon), INTENT(IN)                          :: cin
+  REAL, DIMENSION(klon), INTENT(IN)                          :: s2, n2
+                                                                
+  REAL, DIMENSION(klon), INTENT(INOUT)                       :: ale_bl_trig, ale_bl
+  REAL, DIMENSION(klon), INTENT(INOUT)                       :: alp_bl
+  REAL, DIMENSION(klon), INTENT(INOUT)                       :: alp_bl_stat
+
+  include "thermcell.h"
+
+! Local variables
+!----------------
+  INTEGER                                                    :: i
+  LOGICAL, SAVE                                              :: first = .TRUE.
+  REAL, SAVE                                                 :: random_notrig_max=1.
+  REAL, DIMENSION(klon)                                      :: proba_notrig, tau_trig, random_notrig
+!
+    !$OMP THREADPRIVATE(random_notrig_max) 
+    !$OMP THREADPRIVATE(first)
+!
+    IF (first) THEN
+       CALL getin_p('random_notrig_max',random_notrig_max)
+       first=.FALSE.
+    ENDIF
+          !cc nrlmd le 10/04/2012
+          !-----------Stochastic triggering-----------
+          if (iflag_trig_bl.ge.1) then
+             !
+             IF (prt_level .GE. 10) THEN
+                print *,'cin, ale_bl_stat, alp_bl_stat ', &
+                     cin, ale_bl_stat, alp_bl_stat
+             ENDIF
+
+
+             !----Initialisations
+             do i=1,klon
+                proba_notrig(i)=1.
+                random_notrig(i)=1e6*ale_bl_stat(i)-int(1e6*ale_bl_stat(i))
+                if ( random_notrig(i) > random_notrig_max ) random_notrig(i)=0.
+                if ( ale_bl_trig(i) .lt. abs(cin(i))+1.e-10 ) then 
+                   tau_trig(i)=tau_trig_shallow
+                else
+                   tau_trig(i)=tau_trig_deep
+                endif
+             enddo
+             !
+             IF (prt_level .GE. 10) THEN
+                print *,'random_notrig, tau_trig ', &
+                     random_notrig, tau_trig
+                print *,'s_trig,s2,n2 ', &
+                     s_trig,s2,n2
+             ENDIF
+
+             !Option pour re-activer l'ancien calcul de Ale_bl (iflag_trig_bl=2)
+             IF (iflag_trig_bl.eq.1) then
+
+                !----Tirage al\'eatoire et calcul de ale_bl_trig
+                do i=1,klon
+                   if ( (ale_bl_stat(i) .gt. abs(cin(i))+1.e-10) )  then
+                      proba_notrig(i)=(1.-exp(-s_trig/s2(i)))** &
+                           (n2(i)*dtime/tau_trig(i))
+                      !        print *, 'proba_notrig(i) ',proba_notrig(i)
+                      if (random_notrig(i) .ge. proba_notrig(i)) then 
+                         ale_bl_trig(i)=ale_bl_stat(i)
+                      else
+                         ale_bl_trig(i)=0.
+                      endif
+                   else
+                      proba_notrig(i)=1.
+                      random_notrig(i)=0.
+                      ale_bl_trig(i)=0.
+                   endif
+                enddo
+
+             ELSE IF (iflag_trig_bl.ge.2) then
+
+                do i=1,klon
+                   if ( (Ale_bl(i) .gt. abs(cin(i))+1.e-10) )  then
+                      proba_notrig(i)=(1.-exp(-s_trig/s2(i)))** &
+                           (n2(i)*dtime/tau_trig(i))
+                      !        print *, 'proba_notrig(i) ',proba_notrig(i)
+                      if (random_notrig(i) .ge. proba_notrig(i)) then 
+                         ale_bl_trig(i)=Ale_bl(i)
+                      else
+                         ale_bl_trig(i)=0.
+                      endif
+                   else
+                      proba_notrig(i)=1.
+                      random_notrig(i)=0.
+                      ale_bl_trig(i)=0.
+                   endif
+                enddo
+
+             ENDIF
+
+             !
+             IF (prt_level .GE. 10) THEN
+                print *,'proba_notrig, ale_bl_trig ', &
+                     proba_notrig, ale_bl_trig
+             ENDIF
+
+          endif !(iflag_trig_bl)
+
+          !-----------Statistical closure-----------
+          if (iflag_clos_bl.eq.1) then 
+
+             do i=1,klon
+                !CR: alp probabiliste
+                if (ale_bl_trig(i).gt.0.) then
+                   alp_bl(i)=alp_bl(i)/(1.-min(proba_notrig(i),0.999))
+                endif
+             enddo
+
+          else if (iflag_clos_bl.eq.2) then
+
+             !CR: alp calculee dans thermcell_main
+             do i=1,klon
+                alp_bl(i)=alp_bl_stat(i)
+             enddo
+
+          else
+
+             alp_bl_stat(:)=0.
+
+          endif !(iflag_clos_bl)
+
+          IF (prt_level .GE. 10) THEN
+             print *,'ale_bl_trig, alp_bl_stat ',ale_bl_trig, alp_bl_stat
+          ENDIF
+
+          !cc fin nrlmd le 10/04/2012
+
+          ! ------------------------------------------------------------------
+          ! Transport de la TKE par les panaches thermiques.
+          ! FH : 2010/02/01
+          !     if (iflag_pbl.eq.10) then
+          !     call thermcell_dtke(klon,klev,nbsrf,pdtphys,fm_therm,entr_therm,
+          !    s           rg,paprs,pbl_tke)
+          !     endif
+          ! -------------------------------------------------------------------
+          !IM/FH: 2011/02/23 
+          ! Couplage Thermiques/Emanuel seulement si T<0
+          if (iflag_coupl==2) then
+             IF (prt_level .GE. 10) THEN
+                print*,'Couplage Thermiques/Emanuel seulement si T<0'
+             ENDIF
+             do i=1,klon
+                if (t_seri(i,lmax_th(i))>273.) then
+                   Ale_bl(i)=0.
+                endif
+             enddo
+          endif
+!
+   RETURN
+   END
+
Index: /LMDZ5/branches/testing/libf/phylmd/calcratqs.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/calcratqs.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/calcratqs.F90	(revision 2542)
@@ -1,5 +1,6 @@
 SUBROUTINE calcratqs(klon,klev,prt_level,lunout,       &
            iflag_ratqs,iflag_con,iflag_cld_th,pdtphys, &
-           ratqsbas,ratqshaut,tau_ratqs,fact_cldcon,   &
+           ratqsbas,ratqshaut,ratqsp0,ratqsdp, &
+           tau_ratqs,fact_cldcon,   &
            ptconv,ptconvth,clwcon0th, rnebcon0th,      &
            paprs,pplay,q_seri,zqsat,fm_therm,          &
@@ -21,4 +22,5 @@
 integer,intent(in) :: iflag_con,iflag_cld_th,iflag_ratqs
 real,intent(in) :: pdtphys,ratqsbas,ratqshaut,fact_cldcon,tau_ratqs
+real,intent(in) :: ratqsp0, ratqsdp
 real, dimension(klon,klev+1),intent(in) :: paprs
 real, dimension(klon,klev),intent(in) :: pplay,q_seri,zqsat,fm_therm
@@ -125,5 +127,6 @@
          do k=1,klev
            ratqss(:,k)=ratqsbas+0.5*(ratqshaut-ratqsbas) &
-           *( tanh( (50000.-pplay(:,k))/20000.) + 1.)
+!          *( tanh( (50000.-pplay(:,k))/20000.) + 1.)
+           *( tanh( (ratqsp0-pplay(:,k))/ratqsdp) + 1.)
          enddo
 
Index: /LMDZ5/branches/testing/libf/phylmd/calcul_fluxs_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/calcul_fluxs_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/calcul_fluxs_mod.F90	(revision 2542)
@@ -1,2 +1,4 @@
+!
+! $Id$
 !
 MODULE calcul_fluxs_mod
@@ -9,5 +11,7 @@
        radsol, dif_grnd, t1lay, q1lay, u1lay, v1lay, gustiness, &
        fqsat, petAcoef, peqAcoef, petBcoef, peqBcoef, &
-       tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l)
+       tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l, &
+       sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol)
+ 
     
     USE dimphy, ONLY : klon
@@ -49,5 +53,8 @@
 !   dflux_s      derivee du flux de chaleur sensible / Ts
 !   dflux_l      derivee du flux de chaleur latente  / Ts
-!
+!   sens_prec_liq flux sensible lié aux echanges de precipitations liquides
+!   sens_prec_sol                                    precipitations solides
+!   lat_prec_liq  flux latent lié aux echanges de precipitations liquides
+!   lat_prec_sol                                  precipitations solides
 
     INCLUDE "YOETHF.h"
@@ -77,4 +84,6 @@
     REAL, DIMENSION(klon), INTENT(OUT)   :: tsurf_new, evap, fluxsens, fluxlat
     REAL, DIMENSION(klon), INTENT(OUT)   :: dflux_s, dflux_l
+    REAL, DIMENSION(klon), OPTIONAL      :: sens_prec_liq, sens_prec_sol
+    REAL, DIMENSION(klon), OPTIONAL      :: lat_prec_liq, lat_prec_sol
 
 ! Variables locales
@@ -130,4 +139,8 @@
     dflux_s = 0.
     dflux_l = 0.
+    if (PRESENT(sens_prec_liq)) sens_prec_liq = 0.
+    if (PRESENT(sens_prec_sol)) sens_prec_sol = 0.
+    if (PRESENT(lat_prec_liq)) lat_prec_liq = 0.
+    if (PRESENT(lat_prec_sol)) lat_prec_sol = 0.
 !
 ! zx_qs = qsat en kg/kg
@@ -243,5 +256,34 @@
 !!$     &  run_off(i) = run_off(i) + max(qsol(i) - max_eau_sol, 0.0)
 !!$    qsol(i) = min(qsol(i), max_eau_sol) 
+!
+! calcul de l'enthalpie des precipitations liquides et solides
+!
+!       if (PRESENT(enth_prec_liq))                   &
+!       enth_prec_liq(i) = rcw * (t1lay(i) - tsurf(i)) * &
+!                          precip_rain(i)
+!       if (PRESENT(enth_prec_sol))                  &
+!       enth_prec_sol(i) = rcs * (t1lay(i) - tsurf(i)) * &
+!                          precip_snow(i)
+! On calcule par rapport a T=0
+       if (PRESENT(sens_prec_liq))                   &
+         sens_prec_liq(i) = rcw * (t1lay(i) - RTT) * &
+                          precip_rain(i)
+       if (PRESENT(sens_prec_sol))                   &
+         sens_prec_sol(i) = rcs * (t1lay(i) - RTT) * &
+                          precip_snow(i)
+       if (PRESENT(lat_prec_liq))                    &
+         lat_prec_liq(i) =  precip_rain(i) * (RLVTT - RLVTT) 
+       if (PRESENT(lat_prec_sol))                    &
+         lat_prec_sol(i) = precip_snow(i) * (RLSTT - RLVTT)
     ENDDO
+
+    
+!       if (PRESENT(sens_prec_liq))                  &
+!          WRITE(*,*)' calculs_fluxs sens_prec_liq (min, max)', &
+!          MINVAL(sens_prec_liq(1:knon)), MAXVAL(sens_prec_liq(1:knon))
+!       if (PRESENT(sens_prec_sol))                  &
+!          WRITE(*,*)' calculs_fluxs sens_prec_sol (min, max)', &
+!          MINVAL(sens_prec_sol(1:knon)), MAXVAL(sens_prec_sol(1:knon))
+ 
 !
 !****************************************************************************************
Index: /LMDZ5/branches/testing/libf/phylmd/clesphys.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/clesphys.h	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/clesphys.h	(revision 2542)
@@ -15,4 +15,5 @@
        INTEGER nbapp_rad, iflag_con,iflag_ener_conserv
        REAL co2_ppm, co2_ppm0, solaire
+       LOGICAL ok_suntime_rrtm
        REAL(kind=8) RCO2, RCH4, RN2O, RCFC11, RCFC12  
        REAL(kind=8) RCO2_act, RCH4_act, RN2O_act, RCFC11_act, RCFC12_act  
@@ -110,7 +111,8 @@
      &     , top_height                                                 &
      &     , cycle_diurne, soil_model, new_oliq                         &
-     &     ,ok_orodr, ok_orolf, ok_limitvrai, nbapp_rad, iflag_con      &
+     &     , ok_orodr, ok_orolf, ok_limitvrai, nbapp_rad, iflag_con     &
      &     , iflag_ener_conserv                                         &
      &     , ok_4xCO2atm                                                & 
+     &     , ok_suntime_rrtm                                            & 
      &     , overlap                                                    &
      &     , ok_kzmin                                                   &
@@ -129,3 +131,2 @@
        save /clesphys/
 !$OMP THREADPRIVATE(/clesphys/)
- 
Index: /LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90	(revision 2542)
@@ -76,5 +76,5 @@
     LOGICAL              :: ok_ade, ok_aie, ok_cdnc, aerosol_couple
     INTEGER              :: flag_aerosol
-    LOGICAL              :: flag_aerosol_strat
+    INTEGER              :: flag_aerosol_strat
     LOGICAL              :: new_aod
     REAL                 :: bl95_b0, bl95_b1
@@ -94,5 +94,5 @@
     LOGICAL,SAVE        :: ok_ade_omp, ok_aie_omp, ok_cdnc_omp, aerosol_couple_omp
     INTEGER, SAVE       :: flag_aerosol_omp
-    LOGICAL, SAVE       :: flag_aerosol_strat_omp
+    INTEGER, SAVE       :: flag_aerosol_strat_omp
     LOGICAL, SAVE       :: new_aod_omp
     REAL,SAVE           :: bl95_b0_omp, bl95_b1_omp
@@ -148,4 +148,5 @@
 
     REAL,SAVE :: R_ecc_omp,R_peri_omp,R_incl_omp,solaire_omp
+    LOGICAL,SAVE :: ok_suntime_rrtm_omp
     REAL,SAVE :: co2_ppm_omp, RCO2_omp, co2_ppm_per_omp, RCO2_per_omp
     REAL,SAVE :: CH4_ppb_omp, RCH4_omp, CH4_ppb_per_omp, RCH4_per_omp
@@ -385,10 +386,13 @@
     !
     !Config Key  = flag_aerosol_strat
-    !Config Desc = use stratospheric aerosols T/F
-    !Config Def  = false
+    !Config Desc = use stratospheric aerosols 0, 1, 2
+    ! - 0 = no stratospheric aerosols 
+    ! - 1 = stratospheric aerosols scaled from 550 nm AOD 
+    ! - 2 = stratospheric aerosol properties from CMIP6
+    !Config Def  = 0
     !Config Help = Used in physiq.F
     !
     !
-    flag_aerosol_strat_omp = .false.
+    flag_aerosol_strat_omp = 0
     CALL getin('flag_aerosol_strat',flag_aerosol_strat_omp)
 
@@ -514,4 +518,14 @@
     solaire_omp = 1365.
     call getin('solaire', solaire_omp)
+    !
+    !Config Key  = ok_sun_time
+    !Config Desc = oui ou non variabilite solaire
+    !Config Def  = .false.
+    !Config Help =
+    !
+    !
+    !valeur AMIP II
+    ok_suntime_rrtm_omp = .false.
+    call getin('ok_suntime_rrtm',ok_suntime_rrtm_omp)
     !
     !Config Key  = co2_ppm
@@ -1967,4 +1981,5 @@
     R_incl = R_incl_omp
     solaire = solaire_omp
+    ok_suntime_rrtm = ok_suntime_rrtm_omp
     co2_ppm = co2_ppm_omp
     RCO2 = RCO2_omp
@@ -2281,4 +2296,5 @@
     write(lunout,*)' Inclinaison =',R_incl
     write(lunout,*)' Constante solaire =',solaire
+    write(lunout,*)' ok_suntime_rrtm =',ok_suntime_rrtm
     write(lunout,*)' co2_ppm =',co2_ppm
     write(lunout,*)' RCO2_act = ',RCO2_act
Index: /LMDZ5/branches/testing/libf/phylmd/cpl_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cpl_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/cpl_mod.F90	(revision 2542)
@@ -52,4 +52,6 @@
   REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_windsp
   !$OMP THREADPRIVATE(cpl_windsp)
+  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_sens_rain, cpl_sens_snow
+  !$OMP THREADPRIVATE(cpl_sens_rain, cpl_sens_snow)
   REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_taumod
   !$OMP THREADPRIVATE(cpl_taumod)
@@ -90,4 +92,6 @@
   REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_windsp2D
   !$OMP THREADPRIVATE(cpl_windsp2D)
+  REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE   :: cpl_sens_rain2D, cpl_sens_snow2D
+  !$OMP THREADPRIVATE(cpl_sens_rain2D, cpl_sens_snow2D)
   REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_atm_co22D
   !$OMP THREADPRIVATE(cpl_atm_co22D)
@@ -168,5 +172,7 @@
     ALLOCATE(cpl_windsp(klon,2), stat = error)
     sum_error = sum_error + error
-    ALLOCATE(cpl_taumod(klon,2), stat = error)
+    ALLOCATE(cpl_sens_rain(klon,2), stat = error)
+    sum_error = sum_error + error
+    ALLOCATE(cpl_sens_snow(klon,2), stat = error)
     sum_error = sum_error + error
     ALLOCATE(cpl_rriv2D(nbp_lon,jj_nb), stat=error)
@@ -531,5 +537,6 @@
   SUBROUTINE cpl_send_ocean_fields(itime, knon, knindex, &
        swdown, lwdown, fluxlat, fluxsens, &
-       precip_rain, precip_snow, evap, tsurf, fder, albsol, taux, tauy, windsp)
+       precip_rain, precip_snow, evap, tsurf, fder, albsol, taux, tauy, windsp,&
+       sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol)
 !
 ! This subroutine cumulates some fields for each time-step during a coupling 
@@ -552,4 +559,6 @@
     REAL, DIMENSION(klon), INTENT(IN)       :: evap, tsurf, fder, albsol
     REAL, DIMENSION(klon), INTENT(IN)       :: taux, tauy, windsp
+    REAL, DIMENSION(klon), INTENT(IN)       :: sens_prec_liq, sens_prec_sol
+    REAL, DIMENSION(klon), INTENT(IN)       :: lat_prec_liq, lat_prec_sol
 
 ! Local variables
@@ -583,4 +592,6 @@
        cpl_tauy(1:knon,cpl_index) = 0.0
        cpl_windsp(1:knon,cpl_index) = 0.0
+       cpl_sens_rain(1:knon,cpl_index) = 0.0
+       cpl_sens_snow(1:knon,cpl_index) = 0.0
        cpl_taumod(1:knon,cpl_index) = 0.0
        IF (carbon_cycle_cpl) cpl_atm_co2(1:knon,cpl_index) = 0.0
@@ -614,4 +625,8 @@
        cpl_windsp(ig,cpl_index) = cpl_windsp(ig,cpl_index) + &
             windsp(ig)      / REAL(nexca)
+       cpl_sens_rain(ig,cpl_index) = cpl_sens_rain(ig,cpl_index) + &
+            sens_prec_liq(ig)      / REAL(nexca)
+       cpl_sens_snow(ig,cpl_index) = cpl_sens_snow(ig,cpl_index) + &
+            sens_prec_sol(ig)      / REAL(nexca)
        cpl_taumod(ig,cpl_index) =   cpl_taumod(ig,cpl_index) + &
           SQRT ( taux(ig)*taux(ig)+tauy(ig)*tauy(ig) ) / REAL (nexca)
@@ -654,4 +669,8 @@
           sum_error = sum_error + error
           ALLOCATE(cpl_windsp2D(nbp_lon,jj_nb), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_sens_rain2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_sens_snow2D(nbp_lon,jj_nb,2), stat=error)
           sum_error = sum_error + error
           ALLOCATE(cpl_taumod2D(nbp_lon,jj_nb,2), stat=error)
@@ -706,4 +725,10 @@
             knon, knindex)
 
+       CALL gath2cpl(cpl_sens_rain(:,cpl_index), cpl_sens_rain2D(:,:,cpl_index), &
+            knon, knindex)
+
+       CALL gath2cpl(cpl_sens_snow(:,cpl_index), cpl_sens_snow2D(:,:,cpl_index), &
+            knon, knindex)
+
        CALL gath2cpl(cpl_taumod(:,cpl_index), cpl_taumod2D(:,:,cpl_index), &
             knon, knindex)
@@ -722,5 +747,6 @@
        pctsrf, lafin, rlon, rlat, &
        swdown, lwdown, fluxlat, fluxsens, &
-       precip_rain, precip_snow, evap, tsurf, fder, albsol, taux, tauy)
+       precip_rain, precip_snow, evap, tsurf, fder, albsol, taux, tauy,&
+       sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol)
 !
 ! This subroutine cumulates some fields for each time-step during a coupling 
@@ -746,4 +772,6 @@
     REAL, DIMENSION(klon), INTENT(IN)       :: albsol, taux, tauy
     REAL, DIMENSION(klon,nbsrf), INTENT(IN) :: pctsrf
+    REAL, DIMENSION(klon), INTENT(IN)       :: sens_prec_liq, sens_prec_sol
+    REAL, DIMENSION(klon), INTENT(IN)       :: lat_prec_liq, lat_prec_sol
     LOGICAL, INTENT(IN)                     :: lafin
 
@@ -778,4 +806,6 @@
        cpl_taux(1:knon,cpl_index) = 0.0
        cpl_tauy(1:knon,cpl_index) = 0.0
+       cpl_sens_rain(1:knon,cpl_index) = 0.0
+       cpl_sens_snow(1:knon,cpl_index) = 0.0
        cpl_taumod(1:knon,cpl_index) = 0.0
     ENDIF
@@ -806,4 +836,8 @@
        cpl_tauy(ig,cpl_index) = cpl_tauy(ig,cpl_index) + &
             tauy(ig)        / REAL(nexca)     
+       cpl_sens_rain(ig,cpl_index) = cpl_sens_rain(ig,cpl_index) + &
+            sens_prec_liq(ig)      / REAL(nexca)
+       cpl_sens_snow(ig,cpl_index) = cpl_sens_snow(ig,cpl_index) + &
+            sens_prec_sol(ig)      / REAL(nexca)
        cpl_taumod(ig,cpl_index) = cpl_taumod(ig,cpl_index) + &
             SQRT ( taux(ig)*taux(ig)+tauy(ig)*tauy(ig) ) / REAL(nexca) 
@@ -839,4 +873,8 @@
           sum_error = sum_error + error
           ALLOCATE(cpl_windsp2D(nbp_lon,jj_nb), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_sens_rain2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_sens_snow2D(nbp_lon,jj_nb,2), stat=error)
           sum_error = sum_error + error
           ALLOCATE(cpl_taumod2D(nbp_lon,jj_nb,2), stat=error)
@@ -889,4 +927,10 @@
 
        CALL gath2cpl(cpl_tauy(:,cpl_index), cpl_tauy2D(:,:,cpl_index), &
+            knon, knindex)
+
+       CALL gath2cpl(cpl_sens_rain(:,cpl_index), cpl_sens_rain2D(:,:,cpl_index), &
+            knon, knindex)
+
+       CALL gath2cpl(cpl_sens_snow(:,cpl_index), cpl_sens_snow2D(:,:,cpl_index), &
             knon, knindex)
 
@@ -1078,4 +1122,8 @@
     tab_flds(:,:,ids_nsfice) = cpl_nsol2D(:,:,2)
     tab_flds(:,:,ids_dflxdt) = cpl_fder2D(:,:,2)
+    tab_flds(:,:,ids_qraioc) = cpl_sens_rain2D(:,:,1)
+    tab_flds(:,:,ids_qsnooc) = cpl_sens_snow2D(:,:,1)
+    tab_flds(:,:,ids_qraiic) = cpl_sens_rain2D(:,:,2)
+    tab_flds(:,:,ids_qsnoic) = cpl_sens_snow2D(:,:,2)
     
     IF (version_ocean=='nemo') THEN
@@ -1279,4 +1327,7 @@
     DEALLOCATE(cpl_taux2D, cpl_tauy2D, cpl_windsp2D, cpl_taumod2D, stat=error )
     sum_error = sum_error + error
+    DEALLOCATE(cpl_sens_rain2D, cpl_sens_snow2D, stat=error)
+    sum_error = sum_error + error
+
     
     IF (carbon_cycle_cpl) THEN
Index: /LMDZ5/branches/testing/libf/phylmd/cv30_routines.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv30_routines.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/cv30_routines.F90	(revision 2542)
@@ -407,6 +407,5 @@
 
   DO i = 1, len !convect3
-    icb1(i) = max(icb(i), 2) !convect3
-    icb1(i) = min(icb(i), nl) !convect3
+    icb1(i) = min(max(icb(i), 2), nl)
     ! if icb is below LCL, start loop at ICB+1:
     ! (icbs est le premier niveau au-dessus du LCL)
Index: /LMDZ5/branches/testing/libf/phylmd/cv3_routines.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3_routines.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3_routines.F90	(revision 2542)
@@ -105,4 +105,6 @@
      ok_intermittent=.False.
      CALL getin_p('ok_intermittent',ok_intermittent)
+     ok_optim_yield=.False.
+     CALL getin_p('ok_optim_yield',ok_optim_yield)
      coef_peel=0.25
      CALL getin_p('coef_peel',coef_peel)
@@ -126,4 +128,5 @@
     WRITE (*, *) 'tau_stop=', tau_stop
     WRITE (*, *) 'ok_intermittent=', ok_intermittent
+    WRITE (*, *) 'ok_optim_yield =', ok_optim_yield
     WRITE (*, *) 'coef_peel=', coef_peel
 
@@ -580,6 +583,5 @@
 
   DO i = 1, len                                           !convect3
-    icb1(i) = max(icb(i), 2)                              !convect3
-    icb1(i) = min(icb(i), nl)                             !convect3
+    icb1(i) = min(max(icb(i), 2), nl)
 ! if icb is below LCL, start loop at ICB+1:
 ! (icbs est le premier niveau au-dessus du LCL)
@@ -2605,15 +2607,25 @@
 !
 
-          d6 = bfac*wdtrain(il) - 100.*sigd(il)*bfac*(ph(il,i)-ph(il,i+1))*evap(il, i)
-          e6 = bfac*wdtrain(il)
-          f6 = -100.*sigd(il)*bfac*(ph(il,i)-ph(il,i+1))*evap(il, i)
-
+!jyg<
+          d6 = prec(il,i)-prec(il,i+1)
+
+!!          d6 = bfac*wdtrain(il) - 100.*sigd(il)*bfac*(ph(il,i)-ph(il,i+1))*evap(il, i)
+!!          e6 = bfac*wdtrain(il)
+!!          f6 = -100.*sigd(il)*bfac*(ph(il,i)-ph(il,i+1))*evap(il, i)
+!>jyg
 !CR:tmax_fonte_cv: T for which ice is totally melted (used to be 275.15)
           thaw = (t(il,i)-273.15)/(tmax_fonte_cv-273.15)
           thaw = min(max(thaw,0.0), 1.0)
+!jyg<
           water(il, i) = water(il, i+1) + (1-fraci(il,i))*d6
-          water(il, i) = max(water(il,i), 0.)
-          ice(il, i) = ice(il, i+1) + fraci(il, i)*d6
-          ice(il, i) = max(ice(il,i), 0.)
+          ice(il, i)   = ice(il, i+1)   + fraci(il, i)*d6
+          water(il, i) = min(prec(il,i), max(water(il,i), 0.))
+          ice(il, i)   = min(prec(il,i), max(ice(il,i),   0.))
+
+!!          water(il, i) = water(il, i+1) + (1-fraci(il,i))*d6
+!!          water(il, i) = max(water(il,i), 0.)
+!!          ice(il, i) = ice(il, i+1) + fraci(il, i)*d6
+!!          ice(il, i) = max(ice(il,i), 0.)
+!>jyg
           fondue(il, i) = ice(il, i)*thaw
           water(il, i) = water(il, i) + fondue(il, i)
@@ -2967,21 +2979,26 @@
 !
 !local variables:
-      INTEGER i, k, il, n, j, num1
-      REAL rat, delti
-      REAL ax, bx, cx, dx, ex
-      REAL cpinv, rdcp, dpinv
-      REAL awat(nloc)
-      REAL lvcp(nloc, na), lfcp(nloc, na)                  ! , mke(nloc, na) ! unused . jyg
-      REAL am(nloc), work(nloc), ad(nloc), amp1(nloc)
+      INTEGER                                            :: i, k, il, n, j, num1
+      REAL                                               :: rat, delti
+      REAL                                               :: ax, bx, cx, dx, ex
+      REAL                                               :: cpinv, rdcp, dpinv
+      REAL, DIMENSION (nloc)                             ::  awat
+      REAL, DIMENSION (nloc, nd)                         :: lvcp, lfcp              ! , mke ! unused . jyg
+      REAL, DIMENSION (nloc)                             :: am, work, ad, amp1
 !!      real up1(nloc), dn1(nloc)
-      REAL up1(nloc, nd, nd), dn1(nloc, nd, nd)
-      REAL asum(nloc), bsum(nloc), csum(nloc), dsum(nloc)
-      REAL esum(nloc), fsum(nloc), gsum(nloc), hsum(nloc)
-      REAL th_wake(nloc, nd)
-      REAL alpha_qpos(nloc), alpha_qpos1(nloc)
-      REAL qcond(nloc, nd), nqcond(nloc, nd), wa(nloc, nd) ! cld
-      REAL siga(nloc, nd), sax(nloc, nd), mac(nloc, nd) ! cld
-      REAL sument(nloc), sigment(nloc,nd), qtment(nloc,nd) ! cld
-      REAL qnk(nloc)
+      REAL, DIMENSION (nloc, nd, nd)                     :: up1, dn1
+!jyg<
+      REAL, DIMENSION (nloc, nd)                         :: up_to, up_from
+      REAL, DIMENSION (nloc, nd)                         :: dn_to, dn_from
+!>jyg
+      REAL, DIMENSION (nloc)                             :: asum, bsum, csum, dsum
+      REAL, DIMENSION (nloc)                             :: esum, fsum, gsum, hsum
+      REAL, DIMENSION (nloc, nd)                         :: th_wake
+      REAL, DIMENSION (nloc)                             :: alpha_qpos, alpha_qpos1
+      REAL, DIMENSION (nloc, nd)                         :: qcond, nqcond, wa           ! cld
+      REAL, DIMENSION (nloc, nd)                         :: siga, sax, mac              ! cld
+      REAL, DIMENSION (nloc)                             :: sument
+      REAL, DIMENSION (nloc, nd)                         :: sigment, qtment             ! cld
+      REAL, DIMENSION (nloc)                             :: qnk
       REAL sumdq !jyg
 ! 
@@ -3223,4 +3240,107 @@
 ! print*,'cv3_yield apres ft'
 
+!jyg<
+!-----------------------------------------------------------
+           IF (ok_optim_yield) THEN                       !|
+!-----------------------------------------------------------
+!
+!***                                                      ***
+!***    Compute convective mass fluxes upwd and dnwd      ***
+
+upwd(:,:) = 0.
+up_to(:,:) = 0.
+up_from(:,:) = 0.
+dnwd(:,:) = 0.
+dn_to(:,:) = 0.
+dn_from(:,:) = 0.
+!
+! =================================================
+!              upward fluxes                      |
+! ------------------------------------------------
+DO i = 2, nl
+  DO il = 1, ncum
+    IF (i<=inb(il)) THEN
+      up_to(il,i) = m(il,i)
+    ENDIF
+  ENDDO
+  DO j = 1, i-1
+    DO il = 1, ncum
+      IF (i<=inb(il)) THEN
+        up_to(il,i) = up_to(il,i) + ment(il,j,i)
+      ENDIF
+    ENDDO
+  ENDDO
+ENDDO
+!
+DO i = 1, nl
+  DO il = 1, ncum
+    IF (i<=inb(il)) THEN
+      up_from(il,i) = cbmf(il)*wghti(il,i)
+    ENDIF
+  ENDDO
+ENDDO
+!!DO i = 2, nl
+!!  DO j = i+1, nl          !! Permuter les boucles i et j
+DO j = 3, nl
+  DO i = 2, j-1
+    DO il = 1, ncum
+      IF (j<=inb(il)) THEN
+        up_from(il,i) = up_from(il,i) + ment(il,i,j)
+      ENDIF
+    ENDDO
+  ENDDO
+ENDDO
+!
+! The difference between upwd(il,i) and upwd(il,i-1) is due to updrafts ending in layer 
+!(i-1) (theses drafts cross interface (i-1) but not interface(i)) and to updrafts starting 
+!from layer (i-1) (theses drafts cross interface (i) but not interface(i-1)): 
+! 
+DO i = 2, nlp
+  DO il = 1, ncum
+    upwd(il,i) = max(0., upwd(il,i-1) - up_to(il,i-1) + up_from(il,i-1))
+  ENDDO
+ENDDO
+!
+! =================================================
+!              downward fluxes                    |
+! ------------------------------------------------
+DO i = 1, nl
+  DO j = i+1, nl
+    DO il = 1, ncum
+      IF (j<=inb(il)) THEN
+        dn_to(il,i) = dn_to(il,i) + ment(il,j,i)
+      ENDIF
+    ENDDO
+  ENDDO
+ENDDO
+!
+!!DO i = 2, nl
+!!  DO j = 1, i-1          !! Permuter les boucles i et j 
+DO j = 1, nl
+  DO i = j+1, nl
+    DO il = 1, ncum
+      IF (i<=inb(il)) THEN
+        dn_from(il,i) = dn_from(il,i) + ment(il,i,j)
+      ENDIF
+    ENDDO
+  ENDDO
+ENDDO
+!
+! The difference between dnwd(il,i) and dnwd(il,i+1) is due to downdrafts ending in layer 
+!(i) (theses drafts cross interface (i+1) but not interface(i)) and to downdrafts 
+!starting from layer (i) (theses drafts cross interface (i) but not interface(i+1)): 
+!
+DO i = nl-1, 1, -1
+  DO il = 1, ncum
+    dnwd(il,i) = max(0., dnwd(il,i+1) - dn_to(il,i) + dn_from(il,i))
+  ENDDO
+ENDDO
+! =================================================
+!
+!-----------------------------------------------------------
+        ENDIF !(ok_optim_yield)                           !|
+!-----------------------------------------------------------
+!>jyg
+
 ! ***  calculate tendencies of potential temperature and mixing ratio  ***
 ! ***               at levels above the lowest level                   ***
@@ -3230,5 +3350,8 @@
 
 
-  DO i = 2, nl + 1 ! newvecto: mettre nl au lieu nl+1?
+!jyg<
+!!  DO i = 2, nl + 1 ! newvecto: mettre nl au lieu nl+1?
+  DO i = 2, nl
+!>jyg 
 
     num1 = 0
@@ -3238,12 +3361,21 @@
     IF (num1<=0) GO TO 500
 
+!
 !jyg<
-!!    CALL zilch(amp1, ncum)
-!!    CALL zilch(ad, ncum)
+!-----------------------------------------------------------
+           IF (ok_optim_yield) THEN                       !|
+!-----------------------------------------------------------
+DO il = 1, ncum
+   amp1(il) = upwd(il,i+1)
+   ad(il) = dnwd(il,i)
+ENDDO
+!-----------------------------------------------------------
+        ELSE !(ok_optim_yield)                            !|
+!-----------------------------------------------------------
+!>jyg
     DO il = 1,ncum
       amp1(il) = 0.
       ad(il) = 0.
     ENDDO
-!>jyg
 
     DO k = 1, nl + 1
@@ -3262,18 +3394,24 @@
     END DO
 
-    DO k = 1, i
-      DO j = i + 1, nl + 1
+    DO j = i + 1, nl + 1         
+       DO k = 1, i
+          !yor! reverted j and k loops 
+          DO il = 1, ncum
+!yor!        IF (i<=inb(il) .AND. j<=(inb(il)+1)) THEN ! the second condition implies the first !
+             IF (j<=(inb(il)+1)) THEN  
+                amp1(il) = amp1(il) + ment(il, k, j)
+             END IF
+          END DO
+       END DO
+    END DO
+
+    DO k = 1, i - 1
+!jyg<
+!!      DO j = i, nl + 1 ! newvecto: nl au lieu nl+1?
+      DO j = i, nl
+!>jyg
         DO il = 1, ncum
-          IF (i<=inb(il) .AND. j<=(inb(il)+1)) THEN
-            amp1(il) = amp1(il) + ment(il, k, j)
-          END IF
-        END DO
-      END DO
-    END DO
-
-    DO k = 1, i - 1
-      DO j = i, nl + 1 ! newvecto: nl au lieu nl+1?
-        DO il = 1, ncum
-          IF (i<=inb(il) .AND. j<=inb(il)) THEN
+!yor!        IF (i<=inb(il) .AND. j<=inb(il)) THEN ! the second condition implies the 1st !
+             IF (j<=inb(il)) THEN   
             ad(il) = ad(il) + ment(il, j, k)
           END IF
@@ -3281,4 +3419,10 @@
       END DO
     END DO
+!
+!-----------------------------------------------------------
+        ENDIF !(ok_optim_yield)                           !|
+!-----------------------------------------------------------
+!
+!!   print *,'yield, i, amp1, ad', i, amp1(1), ad(1)
 
     DO il = 1, ncum
@@ -3428,5 +3572,8 @@
 !AC!      enddo
 
-    DO k = i, nl + 1
+!jyg<
+!!    DO k = i, nl + 1
+    DO k = i, nl
+!>jyg
 
       IF (iflag_mix/=0) THEN
@@ -3731,6 +3878,22 @@
     END DO
   END DO
+!jyg<
+!-----------------------------------------------------------
+           IF (ok_optim_yield) THEN                       !|
+!-----------------------------------------------------------
   DO i = 1, nl
-    DO j = 1, nl
+    DO il = 1, ncum
+      IF (iflag(il)<=1) THEN
+        upwd(il, i) = upwd(il, i)/alpha_qpos(il)
+        dnwd(il, i) = dnwd(il, i)/alpha_qpos(il)
+      END IF
+    END DO
+  END DO
+!-----------------------------------------------------------
+        ENDIF !(ok_optim_yield)                           !|
+!-----------------------------------------------------------
+!>jyg
+  DO j = 1, nl !yor! inverted i and j loops
+     DO i = 1, nl
       DO il = 1, ncum
         IF (iflag(il)<=1) THEN
@@ -3766,11 +3929,4 @@
   DO i = 1, nl
     DO il = 1, ncum
-      upwd(il, i) = 0.0
-      dnwd(il, i) = 0.0
-    END DO
-  END DO
-
-  DO i = 1, nl
-    DO il = 1, ncum
       dnwd0(il, i) = -mp(il, i)
     END DO
@@ -3785,12 +3941,23 @@
 
 
+!jyg<
+!-----------------------------------------------------------
+           IF (.NOT.ok_optim_yield) THEN                  !|
+!-----------------------------------------------------------
   DO i = 1, nl
     DO il = 1, ncum
-      IF (i>=icb(il) .AND. i<=inb(il)) THEN
-        upwd(il, i) = 0.0
-        dnwd(il, i) = 0.0
-      END IF
-    END DO
-  END DO
+      upwd(il, i) = 0.0
+      dnwd(il, i) = 0.0
+    END DO
+  END DO
+
+!!  DO i = 1, nl                                           ! useless; jyg
+!!    DO il = 1, ncum                                      ! useless; jyg
+!!      IF (i>=icb(il) .AND. i<=inb(il)) THEN              ! useless; jyg
+!!        upwd(il, i) = 0.0                                ! useless; jyg
+!!        dnwd(il, i) = 0.0                                ! useless; jyg
+!!      END IF                                             ! useless; jyg
+!!    END DO                                               ! useless; jyg
+!!  END DO                                                 ! useless; jyg
 
   DO i = 1, nl
@@ -3803,11 +3970,24 @@
   END DO
 
+!yor! commented original
+!  DO i = 1, nl
+!    DO k = i, nl
+!      DO n = 1, i - 1
+!        DO il = 1, ncum
+!          IF (i>=icb(il) .AND. i<=inb(il) .AND. k<=inb(il)) THEN
+!            up1(il, k, i) = up1(il, k, i) + ment(il, n, k)
+!            dn1(il, k, i) = dn1(il, k, i) - ment(il, k, n)
+!          END IF
+!        END DO
+!      END DO
+!    END DO
+!  END DO
+!yor! replaced with
   DO i = 1, nl
     DO k = i, nl
       DO n = 1, i - 1
         DO il = 1, ncum
-          IF (i>=icb(il) .AND. i<=inb(il) .AND. k<=inb(il)) THEN
-            up1(il, k, i) = up1(il, k, i) + ment(il, n, k)
-            dn1(il, k, i) = dn1(il, k, i) - ment(il, k, n)
+          IF (i>=icb(il) .AND. k<=inb(il)) THEN ! yor ! as i always <= k
+             up1(il, k, i) = up1(il, k, i) + ment(il, n, k)
           END IF
         END DO
@@ -3815,4 +3995,16 @@
     END DO
   END DO
+  DO i = 1, nl
+    DO n = 1, i - 1
+      DO k = i, nl
+        DO il = 1, ncum
+          IF (i>=icb(il) .AND. k<=inb(il)) THEN ! yor !  i always <= k
+             dn1(il, k, i) = dn1(il, k, i) - ment(il, k, n)
+          END IF
+        END DO
+      END DO
+    END DO
+  END DO
+!yor! end replace 
 
   DO i = 1, nl
@@ -3865,4 +4057,8 @@
 !!!!
 !!!!      ENDDO
+!-----------------------------------------------------------
+        ENDIF !(.NOT.ok_optim_yield)                      !|
+!-----------------------------------------------------------
+!>jyg
 
 ! ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Index: /LMDZ5/branches/testing/libf/phylmd/cv3p1_closure.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3p1_closure.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3p1_closure.F90	(revision 2542)
@@ -113,5 +113,5 @@
   IF (prt_level>=20) PRINT *, 'cv3p1_param nloc ncum nd icb inb nl', nloc, &
     ncum, nd, icb(nloc), inb(nloc), nl
-  DO k = 1, nl
+  DO k = 1, nd          !jyg: initialization up to nd
     DO il = 1, ncum
       m(il, k) = 0.0
@@ -120,5 +120,5 @@
 
 !CR: initializations for erosion of adiabatic ascent 
-  DO k = 1,nl
+  DO k = 1,nd           !jyg: initialization up to nd
     DO il = 1, ncum
         mad(il,k)=0.
@@ -628,5 +628,5 @@
 
 !Verification sum(me)=sum(m)
-  DO k = 1,nl+1
+  DO k = 1,nd                         !jyg: initialization up to nd
     DO il = 1, ncum
        md(il,k)=0.
Index: /LMDZ5/branches/testing/libf/phylmd/cv3p2_closure.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3p2_closure.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3p2_closure.F90	(revision 2542)
@@ -126,11 +126,10 @@
   DO k = 1, nl
     DO il = 1, ncum
-      m(il, k) = 0.0
       rhodp(il,k) = 0.007*p(il, k)*(ph(il,k)-ph(il,k+1))/tv(il, k)
     END DO
   END DO
 
-!CR: initializations for erosion of adiabatic ascent 
-  DO k = 1,nl
+!CR+jyg: initializations (up to nd) for erosion of adiabatic ascent and of m and wlim
+  DO k = 1,nd
     DO il = 1, ncum
         mad(il,k)=0.
@@ -138,4 +137,5 @@
         betalim(il,k)=1.
         wlim(il,k)=0.
+        m(il, k) = 0.0
     ENDDO
   ENDDO
@@ -711,5 +711,5 @@
 
 !Verification sum(me)=sum(m)
-  DO k = 1,nl+1
+  DO k = 1,nd
     DO il = 1, ncum
        md(il,k)=0.
Index: /LMDZ5/branches/testing/libf/phylmd/cv3param.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3param.h	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3param.h	(revision 2542)
@@ -7,4 +7,5 @@
 !------------------------------------------------------------
 
+      logical ok_optim_yield
       logical ok_convstop
       logical ok_intermittent
@@ -36,5 +37,6 @@
                       ,flag_wb &
                       ,noff, minorig, nl, nlp, nlm  &
-                      ,ok_convstop, ok_intermittent
+                      ,ok_convstop, ok_intermittent &
+                      ,ok_optim_yield
 !$OMP THREADPRIVATE(/cv3param/)
 
Index: /LMDZ5/branches/testing/libf/phylmd/fisrtilp.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/fisrtilp.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/fisrtilp.F90	(revision 2542)
@@ -21,4 +21,10 @@
   ! Objet: condensation et precipitation stratiforme.
   !        schema de nuage
+  ! Fusion de fisrt (physique sursaturation, P. LeVan K. Laval)
+  !             et ilp (il pleut, L. Li)
+  ! Principales parties:
+  ! P1> Evaporation de la precipitation (qui vient du niveau k+1)
+  ! P2> Formation du nuage (en k) 
+  ! P3> Formation de la precipitation (en k)
   !======================================================================
   !======================================================================
@@ -28,5 +34,5 @@
 
   !
-  ! Arguments:
+  ! Principaux inputs:
   !
   REAL dtime ! intervalle du temps (s)
@@ -35,4 +41,7 @@
   REAL t(klon,klev) ! temperature (K)
   REAL q(klon,klev) ! humidite specifique (kg/kg)
+  !
+  ! Principaux outputs:
+  !
   REAL d_t(klon,klev) ! incrementation de la temperature (K)
   REAL d_q(klon,klev) ! incrementation de la vapeur d'eau
@@ -46,4 +55,7 @@
   REAL prfl(klon,klev+1) ! flux d'eau precipitante aux interfaces (kg/m2/s)
   REAL psfl(klon,klev+1) ! flux d'eau precipitante aux interfaces (kg/m2/s) 
+  !
+  ! Autres arguments
+  ! 
   REAL ztv(klon,klev)
   REAL zqta(klon,klev),fraca(klon,klev) 
@@ -155,11 +167,10 @@
   !     Pour la conversion eau-neige
   REAL zlh_solid(klon), zm_solid
-  !IM 
-  !ym      INTEGER klevm1
   !---------------------------------------------------------------
   !
   ! Fonctions en ligne:
   !
-  REAL fallvs,fallvc ! vitesse de chute pour crystaux de glace
+  REAL fallvs,fallvc ! Vitesse de chute pour cristaux de glace
+                     ! (Heymsfield & Donner, 1990)
   REAL zzz
   include "YOETHF.h"
@@ -278,15 +289,14 @@
   zfrac_lessi = 0.
 
-  !AA----------------------------------------------------------
+  !AA==================================================================
   !
   ncoreczq=0
-  ! Boucle verticale (du haut vers le bas)
-  !
-  !IM : klevm1
-  !ym      klevm1=klev-1
+  ! BOUCLE VERTICALE (DU HAUT VERS LE BAS)
+  !
   DO k = klev, 1, -1
      !
-     !AA----------------------------------------------------------
-     !
+     !AA===============================================================
+     !
+     ! Initialisation temperature et vapeur
      DO i = 1, klon
         zt(i)=t(i,k)
@@ -312,14 +322,7 @@
         ENDDO
      ENDIF
-     !
-     !
-     ! Calculer l'evaporation de la precipitation
-     !
-
-
-     ! Calculer l'evaporation de la precipitation
-     !
-
-
+     ! ----------------------------------------------------------------
+     ! P1> Debut evaporation de la precipitation
+     ! ----------------------------------------------------------------
      IF (evap_prec) THEN
         DO i = 1, klon
@@ -328,4 +331,5 @@
            IF (zrfl(i)+zifl(i).GT.0.) THEN
 !>AJ
+              ! Calcul du qsat
               IF (thermcep) THEN
                  zdelta=MAX(0.,SIGN(1.,RTT-zt(i)))
@@ -350,22 +354,23 @@
            IF (zrfl(i)+zifl(i).GT.0.) THEN
 !>AJ
+                ! Evap max pour ne pas saturer la fraction sous le nuage
                 zqev = MAX (0.0, (zqs(i)-zq(i))*zneb(i) )
+                ! Calcul de l'evaporation du flux de precip herite
+                !   d'au-dessus
                 zqevt = coef_eva * (1.0-zq(i)/zqs(i)) * SQRT(zrfl(i)) &
                      * (paprs(i,k)-paprs(i,k+1))/pplay(i,k)*zt(i)*RD/RG
                 zqevt = MAX(0.0,MIN(zqevt,zrfl(i))) &
                      * RG*dtime/(paprs(i,k)-paprs(i,k+1))
+                ! Seuil pour ne pas saturer la fraction sous le nuage
                 zqev = MIN (zqev, zqevt)
+                ! Nouveau flux de precip
                 zrfln(i) = zrfl(i) - zqev*(paprs(i,k)-paprs(i,k+1)) &
                      /RG/dtime
-       
-                ! pour la glace, on ré-évapore toute la précip dans la
-                ! couche du dessous
-                ! la glace venant de la couche du dessus est simplement
-                ! dans la couche du dessous.
-       
+                ! Aucun flux liquide pour T < t_coup
                 IF (zt(i) .LT. t_coup.and.reevap_ice) zrfln(i)=0.
-       
+                ! Nouvelle vapeur 
                 zq(i) = zq(i) - (zrfln(i)-zrfl(i)) &
                      * (RG/(paprs(i,k)-paprs(i,k+1)))*dtime
+                ! Nouvelle temperature (chaleur latente)
                 zt(i) = zt(i) + (zrfln(i)-zrfl(i)) &
                      * (RG/(paprs(i,k)-paprs(i,k+1)))*dtime &
@@ -384,18 +389,19 @@
 !>AJ
      !JAM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-     ! Modification de l'évaporation avec la glace
-     ! Différentiation entre précipitation liquide et solide 
-     ! On suppose que coef_evai=2*coef_eva
+     ! Modification de l'evaporation avec la glace
+     ! Differentiation entre precipitation liquide et solide 
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  
      
+     ! Evap max pour ne pas saturer la fraction sous le nuage
          zqev0 = MAX (0.0, (zqs(i)-zq(i))*zneb(i) )
      !    zqev0 = MAX (0.0, zqs(i)-zq(i) ) 
 
      !JAM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-     ! On différencie qsat pour l'eau et la glace
+     ! On differencie qsat pour l'eau et la glace
      ! Si zdelta=1. --> glace
      ! Si zdelta=0. --> eau liquide
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-         
+        
+         ! Calcul du qsat par rapport a l'eau liquide
          qsl= R2ES*FOEEW(zt(i),0.)/pplay(i,k)
          qsl= MIN(0.5,qsl)
@@ -403,4 +409,8 @@
          qsl= qsl*zcor
          
+         ! Calcul de l'evaporation du flux de precip herite
+         !   d'au-dessus
+         ! Formulation en racine du flux de precip
+         ! (Klemp & Wilhelmson, 1978; Sundqvist, 1988)
          zqevt = 1.*coef_eva*(1.0-zq(i)/qsl)*SQRT(zrfl(i)) &
               *(paprs(i,k)-paprs(i,k+1))/pplay(i,k)*zt(i)*RD/RG
@@ -408,4 +418,6 @@
               *RG*dtime/(paprs(i,k)-paprs(i,k+1)) 
 
+         
+         ! Calcul du qsat par rapport a la glace
          qsi= R2ES*FOEEW(zt(i),1.)/pplay(i,k)
          qsi= MIN(0.5,qsi)
@@ -413,4 +425,6 @@
          qsi= qsi*zcor
 
+         ! Calcul de la sublimation du flux de precip solide herite
+         !   d'au-dessus
          zqevti = 1.*coef_eva*(1.0-zq(i)/qsi)*SQRT(zifl(i)) &
               *(paprs(i,k)-paprs(i,k+1))/pplay(i,k)*zt(i)*RD/RG
@@ -420,5 +434,9 @@
               
      !JAM!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-     ! Vérification sur l'évaporation
+     ! Verification sur l'evaporation
+     ! On s'assure qu'on ne sature pas 
+     ! la fraction sous le nuage sinon on
+     ! repartit zqev0 en gardant la proportion
+     ! liquide / glace
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      
@@ -436,16 +454,11 @@
              ENDIF
          ENDIF
-     
+         ! Nouveaux flux de precip liquide et solide 
          zrfln(i) = Max(0.,zrfl(i) - zqev*(paprs(i,k)-paprs(i,k+1)) &
                                  /RG/dtime)
          zifln(i) = Max(0.,zifl(i) - zqevi*(paprs(i,k)-paprs(i,k+1)) &
                                  /RG/dtime)
-         
-     ! Pour la glace, on révapore toute la précip dans la couche du dessous
-     ! la glace venant de la couche du dessus est simplement dans la couche
-     ! du dessous.
-     
-     !    IF (zt(i) .LT. t_coup.and.reevap_ice) zrfln(i)=0.
-!         print*,zrfl(i),zrfln(i),zqevt,zqevti,RLMLT,'fluxdeprecip'
+
+         ! Mise a jour de la vapeur, temperature et flux de precip
          zq(i) = zq(i) - (zrfln(i)+zifln(i)-zrfl(i)-zifl(i)) &
                   * (RG/(paprs(i,k)-paprs(i,k+1)))*dtime
@@ -466,7 +479,9 @@
            zmelt = ((zt(i)-273.15)/(ztfondue-273.15))             ! jyg
            zmelt = MIN(MAX(zmelt,0.),1.)
+           ! Fusion de la glace
            zrfl(i)=zrfl(i)+zmelt*zifl(i)
            zifl(i)=zifl(i)*(1.-zmelt)
 !           print*,zt(i),'octavio1'
+           ! Chaleur latente de fusion
            zt(i)=zt(i)-zifl(i)*zmelt*(RG*dtime)/(paprs(i,k)-paprs(i,k+1)) &
                       *RLMLT/RCPD/(1.0+RVTMP2*zq(i))
@@ -481,4 +496,7 @@
       ENDIF ! (.NOT. ice_thermo) 
      
+     ! ----------------------------------------------------------------
+     ! Fin evaporation de la precipitation
+     ! ----------------------------------------------------------------
      ENDIF ! (evap_prec)
      !
@@ -518,4 +536,7 @@
 !       endif
 
+     ! ----------------------------------------------------------------
+     ! P2> Formation du nuage
+     ! ----------------------------------------------------------------
      IF (cpartiel) THEN
 
@@ -534,4 +555,5 @@
         if (iflag_pdf.eq.0) then
 
+           ! version creneau de (Li, 1998)
            do i=1,klon
               zdelq = min(ratqs(i,k),0.99) * zq(i)
@@ -575,5 +597,5 @@
            end if
 
-!CR: variation de qsat avec T en présence de glace ou non
+!CR: variation de qsat avec T en presence de glace ou non
 !initialisations
            do i=1,klon
@@ -587,4 +609,6 @@
 !Boucle iterative: ATTENTION, l'option -1 n'est plus activable ici
            if (iflag_fisrtilp_qsat.ge.0) then
+             ! Iteration pour condensation avec variation de qsat(T) 
+             ! -----------------------------------------------------
              do iter=1,iflag_fisrtilp_qsat+1
                 
@@ -599,8 +623,9 @@
                     if (iflag_t_glace.eq.0) then
                     zdelta = MAX(0.,SIGN(1.,t_glace_min_old-Tbef(i)))
-                    else if (iflag_t_glace.eq.1) then
+                    else if (iflag_t_glace.ge.1) then
                     zdelta = MAX(0.,SIGN(1.,t_glace_min-Tbef(i)))
                     endif
                  endif
+                 ! Calcul des PDF lognormales
                  zcvm5 = R5LES*RLVTT*(1.-zdelta) + R5IES*RLSTT*zdelta
                  zcvm5 = zcvm5 /RCPD/(1.0+RVTMP2*zq(i))
@@ -647,13 +672,6 @@
 
                  else
-
-!calcul de la fraction de glace
-!CR: on utilise la nouvelle fonction de JBM pour l ancien calcul
-!                 zfice(i) = icefrac_lsc(Tbef(i), t_glace_min, &
-!                                     t_glace_max, exposant_glace)
-!                 zfice(i) = 1.0 - (Tbef(i)-ztglace) / (RTT-ztglace)
-!                 zfice(i) = MIN(MAX(zfice(i),0.0),1.0)
-!                 zfice(i) = zfice(i)**nexpo
-                 if (iflag_t_glace.eq.1) then
+                 ! Iteration pour convergence avec qsat(T)
+                 if (iflag_t_glace.ge.1) then
                  CALL icefrac_lsc(klon,zt(:),pplay(:,k)/paprs(:,1),zfice(:))
                  endif
@@ -669,5 +687,5 @@
                  endif
                  
-                 if (iflag_t_glace.eq.1) then
+                 if (iflag_t_glace.ge.1) then
                  dzfice(i)= exposant_glace * zfice(i)**(exposant_glace-1) / (t_glace_min - t_glace_max)
                  endif
@@ -699,5 +717,7 @@
   
           
-             enddo
+             enddo ! iter=1,iflag_fisrtilp_qsat+1
+             ! Fin d'iteration pour condensation avec variation de qsat(T) 
+             ! -----------------------------------------------------------
            endif
 
@@ -707,5 +727,8 @@
 
 !        if (iflag_fisrtilp_qsat.eq.-1) then 
-!CR: ATTENTION option fausse mais a existe: pour la re-activer, prendre iflag_fisrtilp_qsat=0 et activer les lignes suivantes: 
+!------------------------------------------
+!CR: ATTENTION option fausse mais a existe:
+! pour la re-activer, prendre iflag_fisrtilp_qsat=0 et
+! activer les lignes suivantes: 
        IF (1.eq.0) THEN 
        DO i=1,klon
@@ -724,9 +747,14 @@
               rhcl(i,k)=(zqs(i)+zq(i)-zdelq)/2./zqs(i)
            ENDIF
-        ENDDO
-        ENDIF
+       ENDDO
+       ENDIF
+!------------------------------------------
 
 !        ELSE
 
+        ! Calcul de l'eau in-cloud (zqn),
+        ! moyenne dans la maille (zcond),
+        ! fraction nuageuse (rneb) et
+        ! humidite relative ciel-clair (rhcl)
         DO i=1,klon
            IF (rneb(i,k) .LE. 0.0) THEN
@@ -749,21 +777,6 @@
 !        ENDIF
 
-        !         do i=1,klon
-        !            IF (rneb(i,k) .LE. 0.0) zqn(i) = 0.0
-        !            IF (rneb(i,k) .GE. 1.0) zqn(i) = zq(i)
-        !            rneb(i,k) = MAX(0.0,MIN(1.0,rneb(i,k)))
-        !c           zcond(i) = MAX(0.0,zqn(i)-zqs(i))*rneb(i,k)/(1.+zdqs(i))
-        !c  On ne divise pas par 1+zdqs pour forcer a avoir l'eau predite par
-        !c  la convection.
-        !c  ATTENTION !!! Il va falloir verifier tout ca.
-        !            zcond(i) = MAX(0.0,zqn(i)-zqs(i))*rneb(i,k)
-        !c           print*,'ZDQS ',zdqs(i)
-        !c--Olivier
-        !            rhcl(i,k)=(zqs(i)+zq(i)-zdelq)/2./zqs(i)
-        !            IF (rneb(i,k) .LE. 0.0) rhcl(i,k)=zq(i)/zqs(i)
-        !            IF (rneb(i,k) .GE. 1.0) rhcl(i,k)=1.0
-        !c--fin
-        !           ENDDO
-     ELSE
+     ELSE ! de IF (cpartiel) 
+        ! Cas "tout ou rien"
         DO i = 1, klon
            IF (zq(i).GT.zqs(i)) THEN
@@ -775,5 +788,9 @@
         ENDDO
      ENDIF
-     !
+     ! ----------------------------------------------------------------
+     ! Fin de formation du nuage
+     ! ----------------------------------------------------------------
+     !
+     ! Mise a jour vapeur d'eau
      DO i = 1, klon
         zq(i) = zq(i) - zcond(i)
@@ -781,4 +798,6 @@
      ENDDO
 !AJ<
+     ! Chaleur latente apres formation nuage
+     ! -------------------------------------
      IF (.NOT. ice_thermo) THEN
         if (iflag_fisrtilp_qsat.lt.1) then
@@ -792,5 +811,5 @@
         endif
      ELSE
-         if (iflag_t_glace.eq.1) then
+         if (iflag_t_glace.ge.1) then
             CALL icefrac_lsc(klon,zt(:),pplay(:,k)/paprs(:,1),zfice(:))
          endif
@@ -825,7 +844,12 @@
        ENDIF
 !>AJ
+     ! ----------------------------------------------------------------
+     ! P3> Formation des precipitations
+     ! ----------------------------------------------------------------
      !
      ! Partager l'eau condensee en precipitation et eau liquide nuageuse
      !
+
+     ! Initialisation de zoliq (eau condensee moyenne dans la maille)
      DO i = 1, klon
         IF (rneb(i,k).GT.0.0) THEN
@@ -858,4 +882,11 @@
        ENDIF
      ENDIF
+
+     ! Calcul de radliq (eau condensee pour le rayonnement)
+     ! Iteration pour realiser une moyenne de l'eau nuageuse lors de la precip
+     ! Remarque: ce n'est donc pas l'eau restante en fin de precip mais une
+     ! eau moyenne restante dans le nuage sur la duree du pas de temps qui est
+     ! transmise au rayonnement;
+     ! ----------------------------------------------------------------
      DO i = 1, klon
         IF (rneb(i,k).GT.0.0) THEN
@@ -878,6 +909,6 @@
                  ztot = 0.0
               ELSE
-                 !  quantite d'eau a eliminer: zchau
-                 !  meme chose pour la glace: zfroi
+                 !  quantite d'eau a eliminer: zchau (Sundqvist, 1978)
+                 !  meme chose pour la glace: zfroi (Zender & Kiehl, 1997)
                  if (ptconv(i,k)) then
                     zcl   =cld_lc_con
@@ -916,4 +947,5 @@
         ENDDO  ! i = 1,klon
      ENDDO     ! n = 1,ninter
+     ! ----------------------------------------------------------------
      !
      IF (.NOT. ice_thermo) THEN
@@ -1028,5 +1060,5 @@
      ELSE
      ! JAM*************************************************
-     ! Revoir partie ci-dessous: à quoi servent psfl et prfl?
+     ! Revoir partie ci-dessous: a quoi servent psfl et prfl?
      ! *****************************************************
 
@@ -1040,4 +1072,7 @@
        ENDDO
      ENDIF
+     ! ----------------------------------------------------------------
+     ! Fin de formation des precipitations
+     ! ----------------------------------------------------------------
      !
      !
@@ -1110,9 +1145,9 @@
      ENDDO
      !
-     !AA----------------------------------------------------------
-     !                     FIN DE BOUCLE SUR K   
+     !AA===============================================================
+     !                     FIN DE LA BOUCLE VERTICALE  
   end DO
   !
-  !AA-----------------------------------------------------------
+  !AA==================================================================
   !
   ! Pluie ou neige au sol selon la temperature de la 1ere couche
Index: /LMDZ5/branches/testing/libf/phylmd/fonte_neige_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/fonte_neige_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/fonte_neige_mod.F90	(revision 2542)
@@ -313,6 +313,5 @@
 !
   SUBROUTINE fonte_neige_get_vars(pctsrf, fqcalving_out, &
-       fqfonte_out, ffonte_out)
-
+       fqfonte_out, ffonte_out, run_off_lic_out)
 
 
@@ -330,4 +329,5 @@
     REAL, DIMENSION(klon), INTENT(OUT)      :: fqfonte_out
     REAL, DIMENSION(klon), INTENT(OUT)      :: ffonte_out
+    REAL, DIMENSION(klon), INTENT(OUT)      :: run_off_lic_out
 
     INTEGER   :: nisurf
@@ -343,4 +343,5 @@
        fqcalving_out(:) = fqcalving_out(:) + fqcalving_global(:,nisurf)*pctsrf(:,nisurf)
     ENDDO
+    run_off_lic_out(:)=run_off_lic(:)
 
   END SUBROUTINE fonte_neige_get_vars
@@ -349,5 +350,2 @@
 !
 END MODULE fonte_neige_mod
-
-
-
Index: /LMDZ5/branches/testing/libf/phylmd/icefrac_lsc_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/icefrac_lsc_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/icefrac_lsc_mod.F90	(revision 2542)
@@ -14,6 +14,7 @@
   ! Doutriaux-Boucher & Quaas 2004, section 2.2.)
   !
-  ! (JBM 3/14 8/14)
+  ! (JBM 3/14 8/14 5/16)
   
+  USE print_control_mod, ONLY: lunout, prt_level
   INCLUDE "nuage.h"
 
@@ -33,5 +34,12 @@
 
   DO ip=1,np
-     www=(max(sig(ip)-sig0,0.))/(1.-sig0) ! w=1 at the surface and 0 for sig < sig0
+     IF (iflag_t_glace.EQ.1) THEN
+       ! Transition to ice close to surface for T<Tmax
+       ! w=1 at the surface and 0 for sig < sig0
+       www=(max(sig(ip)-sig0,0.))/(1.-sig0) 
+     ELSEIF (iflag_t_glace.GE.2) THEN
+       ! No convertion to ice close to surface
+       www = 0.
+     ENDIF
      tmin_tmp=www*t_glace_max+(1.-www)*t_glace_min
      icefrac_tmp= 1.0 - (temp(ip)-tmin_tmp) / (t_glace_max-tmin_tmp)
Index: /LMDZ5/branches/testing/libf/phylmd/iophy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/iophy.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/iophy.F90	(revision 2542)
@@ -633,6 +633,11 @@
     ENDIF
 
-    ! Set swaero_diag=true if at least one of the concerned variables are defined 
-    IF (var%name=='topswad' .OR. var%name=='topswai' .OR. var%name=='solswad' .OR. var%name=='solswai' ) THEN
+    ! Set swaero_diag=true if at least one of the concerned variables are
+    ! defined
+    !--OB 30/05/2016 use wider set of variables
+    IF ( var%name=='topswad' .OR. var%name=='topswad0' .OR. var%name=='solswad' .OR. var%name=='solswad0' .OR. &
+         var%name=='topswai' .OR. var%name=='solswai'  .OR. ( iflag_rrtm==1 .AND. (                            &
+         var%name=='toplwad' .OR. var%name=='toplwad0' .OR. var%name=='sollwad' .OR. var%name=='sollwad0' .OR. &
+         var%name=='toplwai' .OR. var%name=='sollwai'  ) ) ) THEN
        IF  ( var%flag(iff)<=lev_files(iff) ) THEN
           swaero_diag=.TRUE.
Index: /LMDZ5/branches/testing/libf/phylmd/limit_slab.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/limit_slab.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/limit_slab.F90	(revision 2542)
@@ -42,7 +42,13 @@
   lmt_pas = NINT(86400./dtime)
   
+! Initialize saved variables
+     IF (.NOT. ALLOCATED(bils_save)) THEN
+        ALLOCATE(bils_save(klon), diff_sst_save(klon), diff_siv_save(klon), stat=ierr)
+        IF (ierr /= 0) CALL abort_physic('limit_slab', 'pb in allocation',1)
+     END IF
+
   ! F. Codron 5/14: add defaults for bils, diff_sst (0)
   IF (MOD(itime-1, lmt_pas) == 0) THEN   ! time to read
-     !$OMP MASTER  ! Only master thread
+!$OMP MASTER  ! Only master thread
      IF (is_mpi_root) THEN ! Only master processus
         print*,'in limit_slab time to read, itime=',itime
@@ -53,4 +59,5 @@
         ierr = NF90_OPEN ('limit_slab.nc', NF90_NOWRITE, nid)
         IF (ierr /= NF90_NOERR) THEN
+            PRINT *,'LIMIT_SLAB file not found'
             read_bils=.FALSE.
             read_sst=.FALSE.
@@ -112,5 +119,5 @@
         ierr = NF90_CLOSE(nid)
         IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Pb when closing file', 1)
-        END IF ! Read File
+        END IF ! Read File 
         IF (read_sst) THEN
 ! Calculate difference in temperature between this day and one ahead
@@ -128,11 +135,12 @@
 
 !$OMP END MASTER
+!$OMP BARRIER
        
-     IF (.NOT. ALLOCATED(bils_save)) THEN
-        ALLOCATE(bils_save(klon), diff_sst_save(klon), diff_siv_save(klon), stat=ierr)
-        IF (ierr /= 0) CALL abort_physic('limit_slab', 'pb in allocation',1)
-     END IF
-
+! Send fields to all processes
 ! Give default values if needed
+     CALL bcast(read_bils)
+     CALL bcast(read_sst)
+     CALL bcast(read_siv)
+     PRINT *,'limit_slab sst',read_sst,'siv',read_siv,'qflux',read_bils
      IF (read_bils) THEN
          CALL Scatter(bils_glo, bils_save)
@@ -156,5 +164,8 @@
   diff_sst(:) = diff_sst_save(:)
   diff_siv(:) = diff_siv_save(:)
+! For Debug purpose
+!  PRINT *,'limit_slab sst',MINVAL(diff_sst(:)),MAXVAL(diff_sst(:))
+!  PRINT *,'limit_slab siv',MINVAL(diff_siv(:)),MAXVAL(diff_siv(:))
+!  PRINT *,'limit_slab bils',MINVAL(lmt_bils(:)),MAXVAL(lmt_bils(:))
 
-  
 END SUBROUTINE limit_slab
Index: /LMDZ5/branches/testing/libf/phylmd/oasis.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/oasis.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/oasis.F90	(revision 2542)
@@ -55,5 +55,9 @@
   INTEGER, PARAMETER :: ids_atmco2 = 24
   INTEGER, PARAMETER :: ids_taumod = 25
-  INTEGER, PARAMETER :: maxsend    = 25  ! Maximum number of fields to send
+  INTEGER, PARAMETER :: ids_qraioc = 26
+  INTEGER, PARAMETER :: ids_qsnooc = 27
+  INTEGER, PARAMETER :: ids_qraiic = 28
+  INTEGER, PARAMETER :: ids_qsnoic = 29
+  INTEGER, PARAMETER :: maxsend    = 29  ! Maximum number of fields to send
   
   ! Id for fields received from ocean
@@ -177,4 +181,8 @@
             infosend(ids_atmco2)%action = .TRUE. ; infosend(ids_atmco2)%name = 'COATMCO2'
         ENDIF
+        infosend(ids_qraioc)%action = .TRUE. ; infosend(ids_qraioc)%name = 'COQRAIOC'
+        infosend(ids_qsnooc)%action = .TRUE. ; infosend(ids_qsnooc)%name = 'COQSNOOC'
+        infosend(ids_qraiic)%action = .TRUE. ; infosend(ids_qraiic)%name = 'COQRAIIC'
+        infosend(ids_qsnoic)%action = .TRUE. ; infosend(ids_qsnoic)%name = 'COQSNOIC'
         
     ELSE IF (version_ocean=='opa8') THEN
Index: /LMDZ5/branches/testing/libf/phylmd/ocean_cpl_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ocean_cpl_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/ocean_cpl_mod.F90	(revision 2542)
@@ -1,2 +1,4 @@
+!
+! $Id$
 !
 MODULE ocean_cpl_mod
@@ -10,4 +12,5 @@
 
   PUBLIC :: ocean_cpl_init, ocean_cpl_noice, ocean_cpl_ice
+
 
 !****************************************************************************************
@@ -63,4 +66,6 @@
     USE calcul_fluxs_mod
     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
+    USE cpl_mod,             ONLY : gath2cpl
 
     INCLUDE "YOMCST.h"
@@ -99,8 +104,9 @@
     REAL, DIMENSION(klon), INTENT(OUT)       :: tsurf_new
     REAL, DIMENSION(klon), INTENT(OUT)       :: dflux_s, dflux_l      
+  
 
 ! Local variables
 !****************************************************************************************
-    INTEGER               :: i
+    INTEGER               :: i, j
     INTEGER, DIMENSION(1) :: iloc
     REAL, DIMENSION(klon) :: cal, beta, dif_grnd
@@ -110,4 +116,6 @@
     REAL, DIMENSION(klon) :: u1_lay, v1_lay
     LOGICAL               :: check=.FALSE.
+    REAL, DIMENSION(klon) :: sens_prec_liq, sens_prec_sol    
+    REAL, DIMENSION(klon) :: lat_prec_liq, lat_prec_sol    
 
 ! End definitions
@@ -130,4 +138,6 @@
     dif_grnd = 0.
     agesno(:) = 0.
+    sens_prec_liq = 0.; sens_prec_sol = 0.; lat_prec_liq = 0.; lat_prec_sol = 0.
+    
 
     DO i = 1, knon
@@ -141,5 +151,15 @@
          radsol, dif_grnd, temp_air, spechum, u1_lay, v1_lay, gustiness, &
          f_qsat_oce,AcoefH, AcoefQ, BcoefH, BcoefQ, &
-         tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l)
+         tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l, &
+         sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol)
+    do j = 1, knon
+      i = knindex(j)
+      sens_prec_liq_o(i,1) = sens_prec_liq(j)
+      sens_prec_sol_o(i,1) = sens_prec_sol(j)
+      lat_prec_liq_o(i,1) = lat_prec_liq(j)
+      lat_prec_sol_o(i,1) = lat_prec_sol(j)
+    enddo
+
+
     
 ! - Flux calculation at first modele level for U and V
@@ -171,5 +191,6 @@
     CALL cpl_send_ocean_fields(itime, knon, knindex, &
          swnet, lwnet, fluxlat, fluxsens, &
-         precip_rain, precip_snow, evap, tsurf_new, fder_new, alb1, flux_u1, flux_v1, windsp)
+         precip_rain, precip_snow, evap, tsurf_new, fder_new, alb1, flux_u1, flux_v1, windsp,&
+         sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol)
     
 
@@ -199,4 +220,5 @@
     USE calcul_fluxs_mod
     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
 
     INCLUDE "YOMCST.h"
@@ -237,8 +259,9 @@
     REAL, DIMENSION(klon), INTENT(OUT)       :: tsurf_new
     REAL, DIMENSION(klon), INTENT(OUT)       :: dflux_s, dflux_l      
+  
 
 ! Local variables
 !****************************************************************************************
-    INTEGER                 :: i
+    INTEGER                 :: i, j
     INTEGER, DIMENSION(1)   :: iloc
     LOGICAL                 :: check=.FALSE.
@@ -249,4 +272,6 @@
     REAL, DIMENSION(klon)   :: u0, v0
     REAL, DIMENSION(klon)   :: u1_lay, v1_lay
+    REAL, DIMENSION(klon) :: sens_prec_liq, sens_prec_sol    
+    REAL, DIMENSION(klon) :: lat_prec_liq, lat_prec_sol    
 
 ! End definitions
@@ -254,4 +279,6 @@
     
     IF (check) WRITE(*,*)'Entering surface_seaice, knon=',knon 
+
+    sens_prec_liq = 0.; sens_prec_sol = 0.; lat_prec_liq = 0.; lat_prec_sol = 0.
 
 !****************************************************************************************
@@ -285,5 +312,13 @@
          radsol, dif_grnd, temp_air, spechum, u1_lay, v1_lay, gustiness, &
          f_qsat_oce,AcoefH, AcoefQ, BcoefH, BcoefQ, &
-         tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l)
+         tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l, &
+         sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol)
+    do j = 1, knon
+      i = knindex(j)
+      sens_prec_liq_o(i,2) = sens_prec_liq(j)
+      sens_prec_sol_o(i,2) = sens_prec_sol(j)
+      lat_prec_liq_o(i,2) = lat_prec_liq(j)
+      lat_prec_sol_o(i,2) = lat_prec_sol(j)
+    enddo
 
 
@@ -317,5 +352,7 @@
        pctsrf, lafin, rlon, rlat, &
        swnet, lwnet, fluxlat, fluxsens, &
-       precip_rain, precip_snow, evap, tsurf_new, fder_new, alb1, flux_u1, flux_v1)
+       precip_rain, precip_snow, evap, tsurf_new, fder_new, alb1, flux_u1, flux_v1,&
+       sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol)
+
  
 
Index: /LMDZ5/branches/testing/libf/phylmd/ocean_forced_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ocean_forced_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/ocean_forced_mod.F90	(revision 2542)
@@ -1,2 +1,4 @@
+!
+! $Id$
 !
 MODULE ocean_forced_mod
@@ -32,4 +34,6 @@
     USE mod_grid_phy_lmdz
     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
+
     INCLUDE "YOMCST.h"
     INCLUDE "clesphys.h"
@@ -66,5 +70,5 @@
 ! Local variables
 !****************************************************************************************
-    INTEGER                     :: i
+    INTEGER                     :: i, j
     REAL, DIMENSION(klon)       :: cal, beta, dif_grnd
     REAL, DIMENSION(klon)       :: alb_neig, tsurf_lim, zx_sl
@@ -72,4 +76,6 @@
     REAL, DIMENSION(klon)       :: u1_lay, v1_lay
     LOGICAL                     :: check=.FALSE.
+    REAL, DIMENSION(klon) :: sens_prec_liq, sens_prec_sol    
+    REAL, DIMENSION(klon) :: lat_prec_liq, lat_prec_sol    
 
 !****************************************************************************************
@@ -103,4 +109,6 @@
     alb_neig(:) = 0.
     agesno(:) = 0.
+    sens_prec_liq = 0.; sens_prec_sol = 0.; lat_prec_liq = 0.; lat_prec_sol = 0.
+
 ! Suppose zero surface speed
     u0(:)=0.0
@@ -115,5 +123,15 @@
          radsol, dif_grnd, temp_air, spechum, u1_lay, v1_lay, gustiness, &
          f_qsat_oce,AcoefH, AcoefQ, BcoefH, BcoefQ, &
-         tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l)
+         tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l, &
+         sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol)
+
+    do j = 1, knon
+      i = knindex(j)
+      sens_prec_liq_o(i,1) = sens_prec_liq(j)
+      sens_prec_sol_o(i,1) = sens_prec_sol(j)
+      lat_prec_liq_o(i,1) = lat_prec_liq(j)
+      lat_prec_sol_o(i,1) = lat_prec_sol(j)
+    enddo
+
 
 ! - Flux calculation at first modele level for U and V
@@ -148,4 +166,5 @@
     USE fonte_neige_mod,  ONLY : fonte_neige
     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
 
 !    INCLUDE "indicesol.h"
@@ -189,5 +208,5 @@
 !****************************************************************************************
     LOGICAL                     :: check=.FALSE.
-    INTEGER                     :: i
+    INTEGER                     :: i, j
     REAL                        :: zfra
     REAL, PARAMETER             :: t_grnd=271.35
@@ -197,4 +216,7 @@
     REAL, DIMENSION(klon)       :: u0, v0
     REAL, DIMENSION(klon)       :: u1_lay, v1_lay
+    REAL, DIMENSION(klon)       :: sens_prec_liq, sens_prec_sol    
+    REAL, DIMENSION(klon)       :: lat_prec_liq, lat_prec_sol    
+
 
 !****************************************************************************************
@@ -208,4 +230,5 @@
 !                    dflux_s, dflux_l and qsurf
 !****************************************************************************************
+
     tsurf_tmp(:) = tsurf_in(:)
 
@@ -227,4 +250,6 @@
 
     beta = 1.0
+    sens_prec_liq = 0.; sens_prec_sol = 0.; lat_prec_liq = 0.; lat_prec_sol = 0.
+
 ! Suppose zero surface speed
     u0(:)=0.0
@@ -237,5 +262,13 @@
          radsol, dif_grnd, temp_air, spechum, u1_lay, v1_lay, gustiness, &
          f_qsat_oce,AcoefH, AcoefQ, BcoefH, BcoefQ, &
-         tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l)
+         tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l, &
+         sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol)
+    do j = 1, knon
+      i = knindex(j)
+      sens_prec_liq_o(i,2) = sens_prec_liq(j)
+      sens_prec_sol_o(i,2) = sens_prec_sol(j)
+      lat_prec_liq_o(i,2) = lat_prec_liq(j)
+      lat_prec_sol_o(i,2) = lat_prec_sol(j)
+    enddo
 
 ! - Flux calculation at first modele level for U and V
Index: /LMDZ5/branches/testing/libf/phylmd/phyetat0.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phyetat0.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/phyetat0.F90	(revision 2542)
@@ -12,11 +12,10 @@
        qsol, fevap, z0m, z0h, agesno, &
        du_gwd_rando, du_gwd_front, entr_therm, f0, fm_therm, &
-       falb_dir, falb_dif, &
-       ftsol, pbl_tke, pctsrf, q_ancien, radpas, radsol, rain_fall, ratqs, &
+       falb_dir, falb_dif, prw_ancien, prlw_ancien, prsw_ancien, &
+       ftsol, pbl_tke, pctsrf, q_ancien, ql_ancien, qs_ancien, radpas, radsol, rain_fall, ratqs, &
        rnebcon, rugoro, sig1, snow_fall, solaire_etat0, sollw, sollwdown, &
        solsw, t_ancien, u_ancien, v_ancien, w01, wake_cstar, wake_deltaq, &
        wake_deltat, wake_delta_pbl_TKE, delta_tsurf, wake_fip, wake_pe, &
-       wake_s, zgam, &
-       zmax0, zmea, zpic, zsig, &
+       wake_s, zgam, zmax0, zmea, zpic, zsig, &
        zstd, zthe, zval, ale_bl, ale_bl_trig, alp_bl
   USE geometry_mod, ONLY : longitude_deg, latitude_deg
@@ -324,6 +323,24 @@
   ancien_ok=ancien_ok.AND.phyetat0_get(klev,t_ancien,"TANCIEN","TANCIEN",0.)
   ancien_ok=ancien_ok.AND.phyetat0_get(klev,q_ancien,"QANCIEN","QANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(klev,ql_ancien,"QLANCIEN","QLANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(klev,qs_ancien,"QSANCIEN","QSANCIEN",0.)
   ancien_ok=ancien_ok.AND.phyetat0_get(klev,u_ancien,"UANCIEN","UANCIEN",0.)
   ancien_ok=ancien_ok.AND.phyetat0_get(klev,v_ancien,"VANCIEN","VANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(1,prw_ancien,"PRWANCIEN","PRWANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(1,prlw_ancien,"PRLWANCIEN","PRLWANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(1,prsw_ancien,"PRSWANCIEN","PRSWANCIEN",0.)
+
+  ! Ehouarn: addtional tests to check if t_ancien, q_ancien contain
+  !          dummy values (as is the case when generated by ce0l,
+  !          or by iniaqua)
+  if ( (maxval(q_ancien).eq.minval(q_ancien))       .or. &
+       (maxval(ql_ancien).eq.minval(ql_ancien))     .or. &
+       (maxval(qs_ancien).eq.minval(qs_ancien))     .or. &
+       (maxval(prw_ancien).eq.minval(prw_ancien))   .or. &
+       (maxval(prlw_ancien).eq.minval(prlw_ancien)) .or. &
+       (maxval(prsw_ancien).eq.minval(prsw_ancien)) .or. &
+       (maxval(t_ancien).eq.minval(t_ancien)) ) then
+    ancien_ok=.false.
+  endif
 
   found=phyetat0_get(klev,clwcon,"CLWCON","CLWCON",0.)
Index: /LMDZ5/branches/testing/libf/phylmd/phyredem.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phyredem.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/phyredem.F90	(revision 2542)
@@ -9,14 +9,16 @@
   USE fonte_neige_mod,  ONLY : fonte_neige_final
   USE pbl_surface_mod,  ONLY : pbl_surface_final
-  USE phys_state_var_mod, ONLY: radpas, zmasq, pctsrf, ftsol, falb_dir, &
+  USE phys_state_var_mod, ONLY: radpas, zmasq, pctsrf, ftsol, falb_dir,      &
                                 falb_dif, qsol, fevap, radsol, solsw, sollw, &
-                                sollwdown, rain_fall, snow_fall, z0m, z0h, &
-                                agesno, zmea, zstd, zsig, zgam, zthe, zpic, &
-                                zval, rugoro, t_ancien, q_ancien, u_ancien, &
-                                v_ancien, clwcon, rnebcon, ratqs, pbl_tke, &
-                                wake_delta_pbl_tke, zmax0, f0, sig1, w01, &
-                                wake_deltat, wake_deltaq, wake_s, wake_cstar, &
-                                wake_pe, wake_fip, fm_therm, entr_therm, &
-                                detr_therm, Ale_bl, Ale_bl_trig, Alp_bl, &
+                                sollwdown, rain_fall, snow_fall, z0m, z0h,   &
+                                agesno, zmea, zstd, zsig, zgam, zthe, zpic,  &
+                                zval, rugoro, t_ancien, q_ancien,            &
+                                prw_ancien, prlw_ancien, prsw_ancien,        &
+                                ql_ancien, qs_ancien,  u_ancien,             &
+                                v_ancien, clwcon, rnebcon, ratqs, pbl_tke,   &
+                                wake_delta_pbl_tke, zmax0, f0, sig1, w01,    &
+                                wake_deltat, wake_deltaq, wake_s, wake_cstar,&
+                                wake_pe, wake_fip, fm_therm, entr_therm,     &
+                                detr_therm, Ale_bl, Ale_bl_trig, Alp_bl,     &
                                 du_gwd_rando, du_gwd_front
   USE geometry_mod, ONLY : longitude_deg, latitude_deg
@@ -201,7 +203,17 @@
   CALL put_field("QANCIEN", "QANCIEN", q_ancien)
 
-  CALL put_field("UANCIEN", "", u_ancien)
-
-  CALL put_field("VANCIEN", "", v_ancien)
+  CALL put_field("QLANCIEN", "QLANCIEN", ql_ancien)
+
+  CALL put_field("QSANCIEN", "QSANCIEN", qs_ancien)
+
+  CALL put_field("PRWANCIEN", "PRWANCIEN", prw_ancien)
+
+  CALL put_field("PRLWANCIEN", "PRLWANCIEN", prlw_ancien)
+
+  CALL put_field("PRSWANCIEN", "PRSWANCIEN", prsw_ancien)
+
+  CALL put_field("UANCIEN", "UANCIEN", u_ancien)
+
+  CALL put_field("VANCIEN", "VANCIEN", v_ancien)
 
   CALL put_field("CLWCON", "Eau liquide convective", clwcon)
Index: /LMDZ5/branches/testing/libf/phylmd/phys_cal_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_cal_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_cal_mod.F90	(revision 2542)
@@ -15,5 +15,5 @@
   INTEGER,SAVE :: year_len      ! number of days in the current year
 !$OMP THREADPRIVATE(year_len)
-  REAL,SAVE    :: hour
+  REAL,SAVE    :: hour         ! seconds elapsed (in the current day) since midnight
 !$OMP THREADPRIVATE(hour)
   REAL,SAVE    :: jD_1jan
Index: /LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90	(revision 2542)
@@ -21,4 +21,8 @@
       REAL, SAVE, ALLOCATABLE :: d_t_dyn(:,:), d_q_dyn(:,:)
       !$OMP THREADPRIVATE(d_t_dyn, d_q_dyn)
+      REAL, SAVE, ALLOCATABLE :: d_ql_dyn(:,:), d_qs_dyn(:,:)
+      !$OMP THREADPRIVATE(d_ql_dyn, d_qs_dyn)
+      REAL, SAVE, ALLOCATABLE :: d_q_dyn2d(:), d_ql_dyn2d(:), d_qs_dyn2d(:)
+      !$OMP THREADPRIVATE(d_q_dyn2d, d_ql_dyn2d, d_qs_dyn2d)
       REAL, SAVE, ALLOCATABLE :: d_u_dyn(:,:), d_v_dyn(:,:)
       !$OMP THREADPRIVATE(d_u_dyn, d_v_dyn)
@@ -133,4 +137,6 @@
       !$OMP THREADPRIVATE(ZFSDN0,ZFSUP0)
 !
+      REAL, SAVE, ALLOCATABLE :: stratomask(:,:) 
+      !$OMP THREADPRIVATE(stratomask) 
       REAL, SAVE, ALLOCATABLE :: tausum_aero(:,:,:) 
       !$OMP THREADPRIVATE(tausum_aero) 
@@ -255,6 +261,6 @@
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: JrNt
 !$OMP THREADPRIVATE(JrNt)
-      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: dthmin, evap, fder, plcl, plfc, prw
-!$OMP THREADPRIVATE(dthmin, evap, fder, plcl, plfc, prw)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: dthmin, evap, fder, plcl, plfc, prw, prlw, prsw
+!$OMP THREADPRIVATE(dthmin, evap, fder, plcl, plfc, prw, prlw, prsw)
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zustar, zu10m, zv10m, rh2m
 !$OMP THREADPRIVATE(zustar, zu10m, zv10m, rh2m)
@@ -277,6 +283,8 @@
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zxfluxlat, zxtsol, snow_lsc, zxfqfonte
 !$OMP THREADPRIVATE(zxfluxlat, zxtsol, snow_lsc, zxfqfonte)
-      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zxqsurf, rain_lsc
-!$OMP THREADPRIVATE(zxqsurf, rain_lsc)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zxrunofflic
+!$OMP THREADPRIVATE(zxrunofflic)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zxqsurf, rain_lsc, rain_num
+!$OMP THREADPRIVATE(zxqsurf, rain_lsc, rain_num)
 !
 !jyg+nrlmd<
@@ -401,4 +409,6 @@
       allocate(tr_seri(klon,klev,nbtr))
       allocate(d_t_dyn(klon,klev),d_q_dyn(klon,klev))
+      allocate(d_ql_dyn(klon,klev),d_qs_dyn(klon,klev))
+      allocate(d_q_dyn2d(klon),d_ql_dyn2d(klon),d_qs_dyn2d(klon))
       allocate(d_u_dyn(klon,klev),d_v_dyn(klon,klev))
       allocate(d_tr_dyn(klon,klev,nbtr))                   !RomP
@@ -455,4 +465,5 @@
 !      allocate(tausum_aero(klon,nwave,naero_spc))
 !      allocate(tau3d_aero(klon,klev,nwave,naero_spc)) 
+      allocate(stratomask(klon,klev))
 !--correction mini bug OB
       allocate(tausum_aero(klon,nwave,naero_tot))
@@ -521,5 +532,5 @@
       ALLOCATE(JrNt(klon))
       ALLOCATE(dthmin(klon), evap(klon), fder(klon), plcl(klon), plfc(klon))
-      ALLOCATE(prw(klon), zustar(klon), zu10m(klon), zv10m(klon), rh2m(klon))
+      ALLOCATE(prw(klon), prlw(klon), prsw(klon), zustar(klon), zu10m(klon), zv10m(klon), rh2m(klon))
       ALLOCATE(s_lcl(klon))
       ALLOCATE(s_pblh(klon), s_pblt(klon), s_therm(klon))
@@ -534,5 +545,7 @@
       ALLOCATE(zxfqcalving(klon), zxfluxlat(klon))
       ALLOCATE(zxtsol(klon), snow_lsc(klon), zxfqfonte(klon), zxqsurf(klon))
+      ALLOCATE(zxrunofflic(klon))
       ALLOCATE(rain_lsc(klon))
+      ALLOCATE(rain_num(klon))
 !
       ALLOCATE(sens_x(klon), sens_w(klon))
@@ -615,4 +628,6 @@
       deallocate(tr_seri)
       deallocate(d_t_dyn,d_q_dyn)
+      deallocate(d_ql_dyn,d_qs_dyn)
+      deallocate(d_q_dyn2d,d_ql_dyn2d,d_qs_dyn2d)
       deallocate(d_u_dyn,d_v_dyn)
       deallocate(d_tr_dyn)                      !RomP
@@ -658,4 +673,5 @@
       deallocate(topsw0_aero,solsw0_aero)
       deallocate(topswcf_aero,solswcf_aero)
+      deallocate(stratomask) 
       deallocate(tausum_aero) 
       deallocate(tau3d_aero) 
@@ -725,5 +741,5 @@
       DEALLOCATE(cldljn, cldmjn, cldhjn, cldtjn, JrNt)
       DEALLOCATE(dthmin, evap, fder, plcl, plfc)
-      DEALLOCATE(prw, zustar, zu10m, zv10m, rh2m, s_lcl)
+      DEALLOCATE(prw, prlw, prsw, zustar, zu10m, zv10m, rh2m, s_lcl)
       DEALLOCATE(s_pblh, s_pblt, s_therm)
 !
@@ -736,6 +752,8 @@
       DEALLOCATE(uq, ve, vq, zxffonte)
       DEALLOCATE(zxfqcalving, zxfluxlat)
+      DEALLOCATE(zxrunofflic)
       DEALLOCATE(zxtsol, snow_lsc, zxfqfonte, zxqsurf)
       DEALLOCATE(rain_lsc)
+      DEALLOCATE(rain_num)
 !
       DEALLOCATE(sens_x, sens_w)
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 2542)
@@ -154,4 +154,6 @@
   TYPE(ctrl_out), SAVE :: o_plul = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
     'plul', 'Large-scale Precip.', 'kg/(s*m2)', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_plun = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
+    'plun', 'Numerical Precip.', 'kg/(s*m2)', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_pluc = ctrl_out((/ 1, 1, 1, 10, 5, 10, 11, 11, 11 /), &
     'pluc', 'Convective Precip.', 'kg/(s*m2)', (/ ('', i=1, 9) /))
@@ -160,4 +162,22 @@
   TYPE(ctrl_out), SAVE :: o_evap = ctrl_out((/ 1, 1, 10, 10, 10, 10, 11, 11, 11 /), &
     'evap', 'Evaporat', 'kg/(s*m2)', (/ ('', i=1, 9) /))
+
+  TYPE(ctrl_out), SAVE :: o_sens_prec_liq_oce = ctrl_out((/ 5, 5, 10, 10, 5, 10, 11, 11, 11 /), &
+    'sens_rain_oce', 'Sensible heat flux of liquid prec. over ocean', 'W/m2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_sens_prec_liq_sic = ctrl_out((/ 5, 5, 10, 10, 5, 10, 11, 11, 11 /), &
+    'sens_rain_sic', 'Sensible heat flux of liquid prec. over seaice', 'W/m2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_sens_prec_sol_oce = ctrl_out((/ 5, 5, 10, 10, 5, 10, 11, 11, 11 /), &
+    'sens_snow_oce', 'Sensible heat flux of solid prec. over ocean', 'W/m2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_sens_prec_sol_sic = ctrl_out((/ 5, 5, 10, 10, 5, 10, 11, 11, 11 /), &
+    'sens_snow_sic', 'Sensible heat flux of solid prec. over seaice', 'W/m2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_lat_prec_liq_oce = ctrl_out((/ 5, 5, 10, 10, 5, 10, 11, 11, 11 /), &
+    'lat_rain_oce', 'Latent heat flux of liquid prec. over ocean', 'W/m2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_lat_prec_liq_sic = ctrl_out((/ 5, 5, 10, 10, 5, 10, 11, 11, 11 /), &
+    'lat_rain_sic', 'Latent heat flux of liquid prec. over seaice', 'W/m2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_lat_prec_sol_oce = ctrl_out((/ 5, 5, 10, 10, 5, 10, 11, 11, 11 /), &
+    'lat_snow_oce', 'Latent heat flux of solid prec. over ocean', 'W/m2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_lat_prec_sol_sic = ctrl_out((/ 5, 5, 10, 10, 5, 10, 11, 11, 11 /), &
+    'lat_snow_sic', 'Latent heat flux of solid prec. over seaice', 'W/m2', (/ ('', i=1, 9) /))
+
 
   TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_evap_srf     = (/ &
@@ -271,4 +291,6 @@
   TYPE(ctrl_out), SAVE :: o_fqfonte = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'fqfonte', 'Land ice melt', 'kg/m2/s', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_runofflic = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'runofflic', 'Land ice melt to ocean', 'kg/m2/s', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_taux = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'taux', 'Zonal wind stress', 'Pa', (/ ('', i=1, 9) /))
@@ -449,4 +471,8 @@
   TYPE(ctrl_out), SAVE :: o_prw = ctrl_out((/ 1, 1, 10, 10, 10, 10, 11, 11, 11 /), &
     'prw', 'Precipitable water', 'kg/m2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_prlw = ctrl_out((/ 1, 1, 10, 10, 10, 10, 11, 11, 11 /), &
+    'prlw', 'Precipitable liquid water', 'kg/m2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_prsw = ctrl_out((/ 1, 1, 10, 10, 10, 10, 11, 11, 11 /), &
+    'prsw', 'Precipitable solid water', 'kg/m2', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_s_pblh = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     's_pblh', 'Boundary Layer Height', 'm', (/ ('', i=1, 9) /))
@@ -842,7 +868,4 @@
        ctrl_out((/ 2, 6, 10, 10, 10, 10, 11, 11, 11 /),'OD550_'//name_aero_tau(14),       &
        "Aerosol Optical depth at 550 nm "//name_aero_tau(14),"14", (/ ('', i=1, 9) /)) /)
-  
-
-
 !
   TYPE(ctrl_out), SAVE :: o_tausumaero_lw = ctrl_out((/ 2, 6, 10, 10, 10, 10, 11, 11, 11 /), &
@@ -992,4 +1015,12 @@
   TYPE(ctrl_out), SAVE :: o_dqphy2d = ctrl_out((/ 2, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'dqphy2d', 'Physics dQ', '(kg/m2)/s', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_dqlphy = ctrl_out((/ 2, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'dqlphy', 'Physics dQL', '(kg/kg)/s', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_dqlphy2d = ctrl_out((/ 2, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'dqlphy2d', 'Physics dQL', '(kg/m2)/s', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_dqsphy = ctrl_out((/ 2, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'dqsphy', 'Physics dQS', '(kg/kg)/s', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_dqsphy2d = ctrl_out((/ 2, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'dqsphy2d', 'Physics dQS', '(kg/m2)/s', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_pr_con_l = ctrl_out((/ 2, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'pr_con_l', 'Convective precipitation lic', ' ', (/ ('', i=1, 9) /))
@@ -1016,4 +1047,6 @@
   TYPE(ctrl_out), SAVE :: o_lcc3dstra = ctrl_out((/ 2,  6, 10, 10, 10, 10, 11, 11, 11 /), &
     'lcc3dstra', 'Stratiform cloud liquid fraction', '1', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_stratomask = ctrl_out((/ 2,  6, 10, 10, 10, 10, 11, 11, 11 /), &
+    'stratomask', 'Stratospheric fraction', '1', (/ ('', i=1, 9) /))
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -1071,4 +1104,12 @@
   TYPE(ctrl_out), SAVE :: o_dqdyn2d = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'dqdyn2d', 'Dynamics dQ', '(kg/m2)/s', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_dqldyn = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'dqldyn', 'Dynamics dQL', '(kg/kg)/s', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_dqldyn2d = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'dqldyn2d', 'Dynamics dQL', '(kg/m2)/s', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_dqsdyn = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'dqsdyn', 'Dynamics dQS', '(kg/kg)/s', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_dqsdyn2d = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'dqsdyn2d', 'Dynamics dQS', '(kg/m2)/s', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_dudyn = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'dudyn', 'Dynamics dU', 'm/s2', (/ ('', i=1, 9) /))
@@ -1402,5 +1443,5 @@
        "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)"  /))
   TYPE(ctrl_out), SAVE :: o_vxq = ctrl_out((/ 11, 11, 11, 11, 11, 11, 6, 6, 6 /), &
-       'vq', 'vq', 'm/s * (kg/kg)', (/ "inst(X)", "inst(X)", "inst(X)", &
+       'vxq', 'vxq', 'm/s * (kg/kg)', (/ "inst(X)", "inst(X)", "inst(X)", &
        "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)"  /))                                                                                                    
   TYPE(ctrl_out), SAVE :: o_vxT = ctrl_out((/ 11, 11, 11, 11, 11, 11, 6, 6, 6 /), &
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90	(revision 2542)
@@ -81,5 +81,6 @@
     INTEGER                               :: nlevSTD, radpas
     LOGICAL                               :: ok_mensuel, ok_journe, ok_hf, ok_instan
-    LOGICAL                               :: ok_LES,ok_ade,ok_aie,flag_aerosol_strat
+    LOGICAL                               :: ok_LES,ok_ade,ok_aie
+    INTEGER                               :: flag_aerosol_strat
     LOGICAL                               :: new_aod, aerosol_couple
     INTEGER, INTENT(IN)::  read_climoz ! read ozone climatology
@@ -255,5 +256,9 @@
      idayref = day_ref
      IF (klon_glo==1) THEN
-         CALL ymds2ju(annee_ref, 1, idayref, hour, zjulian)     !jyg
+       ! current_time (used to compute hour) is updated at the begining of
+       ! the physics; to set the correct outputs "initial time" we thus 
+       ! have to use (hour-dtphys).
+         CALL ymds2ju(annee_ref, 1, idayref, hour-pdtphys, zjulian)
+         print *,'phys_output_mod: annee,iday,hour,zjulian=',annee_ref,idayref, hour, zjulian
      ELSE
          CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90	(revision 2542)
@@ -47,5 +47,7 @@
 
   ! swaero_diag : flag indicates if it is necessary to do calculation for some aerosol diagnostics
-  LOGICAL, SAVE                                :: swaero_diag=.FALSE.
+  !--OB: this needs to be set to TRUE by default and changed back to FALSE after first radiation call
+  !--    and corrected back to TRUE based on output requests
+  LOGICAL, SAVE                                :: swaero_diag=.TRUE.
   !$OMP THREADPRIVATE(swaero_diag)
 
@@ -74,4 +76,8 @@
   END TYPE ctrl_out
 
+  REAL, SAVE, ALLOCATABLE :: sens_prec_liq_o(:,:), sens_prec_sol_o(:,:)
+  REAL, SAVE, ALLOCATABLE :: lat_prec_liq_o(:,:), lat_prec_sol_o(:,:)
+ !$OMP THREADPRIVATE(sens_prec_liq_o, sens_prec_sol_o,lat_prec_liq_o,lat_prec_sol_o)
+
 CONTAINS
 
@@ -88,4 +94,11 @@
     allocate(snow_o(klon), zfra_o(klon))
     allocate(itau_con(klon))
+    allocate(sens_prec_liq_o(klon,2))
+    allocate(sens_prec_sol_o(klon,2))
+    allocate(lat_prec_liq_o(klon,2))
+    allocate(lat_prec_sol_o(klon,2))
+    sens_prec_liq_o = 0.0 ; sens_prec_sol_o = 0.0
+    lat_prec_liq_o = 0.0 ; lat_prec_sol_o = 0.0
+
     allocate (bils_ec(klon),bils_ech(klon),bils_tke(klon),bils_diss(klon),bils_kinetic(klon),bils_enthalp(klon),bils_latent(klon))
 
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_write_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_write_mod.F90	(revision 2542)
@@ -17,5 +17,5 @@
   SUBROUTINE phys_output_write(itap, pdtphys, paprs, pphis, &
        pplay, lmax_th, aerosol_couple,         &
-       ok_ade, ok_aie, ivap, new_aod, ok_sync, &
+       ok_ade, ok_aie, ivap, iliq, isol, new_aod, ok_sync, &
        ptconv, read_climoz, clevSTD, ptconvth, &
        d_t, qx, d_qx, zmasse, flag_aerosol, flag_aerosol_strat, ok_cdnc)
@@ -36,5 +36,5 @@
          o_wind10m, o_wind10max, o_gusts, o_sicf, &
          o_psol, o_mass, o_qsurf, o_qsol, &
-         o_precip, o_ndayrain, o_plul, o_pluc, &
+         o_precip, o_ndayrain, o_plul, o_pluc, o_plun, &
          o_snow, o_msnow, o_fsnow, o_evap, o_ep,o_epmax_diag, & ! epmax_cape
          o_tops, o_tops0, o_topl, o_topl0, &
@@ -50,5 +50,5 @@
          o_bils_ec,o_bils_ech, o_bils_tke, o_bils_kinetic, &
          o_bils_latent, o_bils_enthalp, o_sens, &
-         o_fder, o_ffonte, o_fqcalving, o_fqfonte, &
+         o_fder, o_ffonte, o_fqcalving, o_fqfonte, o_runofflic, &
          o_taux, o_tauy, o_snowsrf, o_qsnow, &
          o_snowhgt, o_toice, o_sissnow, o_runoff, &
@@ -67,5 +67,5 @@
          o_wbeff, o_cape_max, o_upwd, o_ep,o_epmax_diag, o_Ma, &
          o_dnwd, o_dnwd0, o_ftime_con, o_mc, &
-         o_prw, o_s_pblh, o_s_pblt, o_s_lcl, &
+         o_prw, o_prlw, o_prsw, o_s_pblh, o_s_pblt, o_s_lcl, &
          o_s_therm, o_uSTDlevs, o_vSTDlevs, &
          o_wSTDlevs, o_zSTDlevs, o_qSTDlevs, &
@@ -112,5 +112,5 @@
          o_swtoacf_zero, o_swsrfcf_zero, &
          o_topswai, o_solswai, o_scdnc, &
-         o_cldncl, o_reffclws, o_reffclwc, &
+         o_cldncl, o_reffclws, o_reffclwc, o_stratomask,&
          o_cldnvi, o_lcc, o_lcc3d, o_lcc3dcon, &
          o_lcc3dstra, o_reffclwtop, o_ec550aer, &
@@ -120,8 +120,10 @@
          o_zfull, o_zhalf, o_rneb, o_rnebjn, o_rnebcon, &
          o_rnebls, o_rhum, o_ozone, o_ozone_light, &
-         o_dtphy, o_dqphy, o_dqphy2d, o_albe_srf, o_z0m_srf, o_z0h_srf, &
+         o_dtphy, o_dqphy, o_dqphy2d, o_dqlphy, o_dqlphy2d, &
+         o_dqsphy, o_dqsphy2d, o_albe_srf, o_z0m_srf, o_z0h_srf, &
          o_ages_srf, o_snow_srf, o_alb1, o_alb2, o_tke, &
          o_tke_max, o_kz, o_kz_max, o_clwcon, &
-         o_dtdyn, o_dqdyn, o_dqdyn2d, o_dudyn, o_dvdyn, &
+         o_dtdyn, o_dqdyn, o_dqdyn2d, o_dqldyn, o_dqldyn2d, & 
+         o_dqsdyn, o_dqsdyn2d, o_dudyn, o_dvdyn, &
          o_dtcon, o_tntc, o_ducon, o_dvcon, &
          o_dqcon, o_dqcon2d, o_tnhusc, o_tnhusc, o_dtlsc, &
@@ -161,5 +163,9 @@
          o_dtr_sat, o_dtr_uscav, o_trac_cum, o_du_gwd_rando, o_dv_gwd_rando, &
          o_ustr_gwd_hines,o_vstr_gwd_hines,o_ustr_gwd_rando,o_vstr_gwd_rando, &
-         o_ustr_gwd_front,o_vstr_gwd_front
+         o_ustr_gwd_front,o_vstr_gwd_front, &
+         o_sens_prec_liq_oce, o_sens_prec_liq_sic, &
+         o_sens_prec_sol_oce, o_sens_prec_sol_sic, &
+         o_lat_prec_liq_oce, o_lat_prec_liq_sic, &
+         o_lat_prec_sol_oce, o_lat_prec_sol_sic
 
     USE phys_state_var_mod, only: pctsrf, paire_ter, rain_fall, snow_fall, &
@@ -193,6 +199,6 @@
          t2m_min_mon, t2m_max_mon, evap, &
          zu10m, zv10m, zq2m, zustar, zxqsurf, &
-         rain_lsc, snow_lsc, bils, sens, fder, &
-         zxffonte, zxfqcalving, zxfqfonte, fluxu, &
+         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, &
@@ -201,5 +207,5 @@
          cldh, cldt, JrNt, cldljn, cldmjn, cldhjn, &
          cldtjn, cldq, flwp, fiwp, ue, ve, uq, vq, &
-         plcl, plfc, wbeff, upwd, dnwd, dnwd0, prw, &
+         plcl, plfc, wbeff, upwd, dnwd, dnwd0, prw, prlw, prsw, &
          s_pblh, s_pblt, s_lcl, s_therm, uwriteSTD, &
          vwriteSTD, wwriteSTD, phiwriteSTD, qwriteSTD, &
@@ -228,13 +234,12 @@
          toplwad_aero, toplwad0_aero, sollwad_aero, &
          sollwad0_aero, toplwai_aero, sollwai_aero, &
-         scdnc, cldncl, reffclws, reffclwc, cldnvi, &
+         scdnc, cldncl, reffclws, reffclwc, cldnvi, stratomask,&
          lcc, lcc3d, lcc3dcon, lcc3dstra, reffclwtop, &
          ec550aer, flwc, fiwc, t_seri, theta, q_seri, &
-!jyg<
-!!         ql_seri, zphi, u_seri, v_seri, omega, cldfra, &
          ql_seri, tr_seri, &
          zphi, u_seri, v_seri, omega, cldfra, &
-!>jyg
-         rneb, rnebjn, zx_rh, d_t_dyn, d_q_dyn, &
+         rneb, rnebjn, zx_rh, d_t_dyn,  & 
+         d_q_dyn,  d_ql_dyn, d_qs_dyn, &
+         d_q_dyn2d,  d_ql_dyn2d, d_qs_dyn2d, &
          d_u_dyn, d_v_dyn, d_t_con, d_t_ajsb, d_t_ajs, &
          d_u_ajs, d_v_ajs, &
@@ -256,5 +261,8 @@
          itau_con, nfiles, clef_files, nid_files, &
          zustr_gwd_hines, zvstr_gwd_hines,zustr_gwd_rando, zvstr_gwd_rando, &
-         zustr_gwd_front, zvstr_gwd_front                                   
+         zustr_gwd_front, zvstr_gwd_front,     &
+         sens_prec_liq_o, sens_prec_sol_o, lat_prec_liq_o, lat_prec_sol_o
+  
+
     USE ocean_slab_mod, only: tslab, slab_bils, slab_bilg, tice, seaice
     USE pbl_surface_mod, only: snow
@@ -288,5 +296,5 @@
 
     ! Input
-    INTEGER :: itap, ivap, read_climoz
+    INTEGER :: itap, ivap, iliq, isol, read_climoz
     INTEGER, DIMENSION(klon) :: lmax_th
     LOGICAL :: aerosol_couple, ok_sync
@@ -301,5 +309,5 @@
     REAL, DIMENSION(klon,klev,nqtot) :: qx, d_qx
     REAL, DIMENSION(klon, klev) :: zmasse
-    LOGICAL :: flag_aerosol_strat
+    INTEGER :: flag_aerosol_strat
     INTEGER :: flag_aerosol 
     LOGICAL :: ok_cdnc
@@ -440,4 +448,5 @@
        ENDIF
        CALL histwrite_phy(o_plul, zx_tmp_fi2d)
+       CALL histwrite_phy(o_plun, rain_num)
 
        IF (vars_defined) THEN
@@ -545,4 +554,5 @@
        CALL histwrite_phy(o_fqcalving, zxfqcalving)
        CALL histwrite_phy(o_fqfonte, zxfqfonte)
+       CALL histwrite_phy(o_runofflic, zxrunofflic)
        IF (vars_defined) THEN
           zx_tmp_fi2d=0.
@@ -618,4 +628,23 @@
 
        ENDDO
+
+       IF (vars_defined) zx_tmp_fi2d(1 : klon) = sens_prec_liq_o(1 : klon, 1)
+       CALL histwrite_phy(o_sens_prec_liq_oce, zx_tmp_fi2d)       
+       IF (vars_defined) zx_tmp_fi2d(1 : klon) = sens_prec_liq_o(1 : klon, 2)
+       CALL histwrite_phy(o_sens_prec_liq_sic, zx_tmp_fi2d)       
+       IF (vars_defined) zx_tmp_fi2d(1 : klon) = sens_prec_sol_o(1 : klon, 1)
+       CALL histwrite_phy(o_sens_prec_sol_oce, zx_tmp_fi2d)       
+       IF (vars_defined) zx_tmp_fi2d(1 : klon) = sens_prec_sol_o(1 : klon, 2)
+       CALL histwrite_phy(o_sens_prec_sol_sic, zx_tmp_fi2d)       
+
+       IF (vars_defined) zx_tmp_fi2d(1 : klon) = lat_prec_liq_o(1 : klon, 1)
+       CALL histwrite_phy(o_lat_prec_liq_oce, zx_tmp_fi2d)       
+       IF (vars_defined) zx_tmp_fi2d(1 : klon) = lat_prec_liq_o(1 : klon, 2)
+       CALL histwrite_phy(o_lat_prec_liq_sic, zx_tmp_fi2d)       
+       IF (vars_defined) zx_tmp_fi2d(1 : klon) = lat_prec_sol_o(1 : klon, 1)
+       CALL histwrite_phy(o_lat_prec_sol_oce, zx_tmp_fi2d)       
+       IF (vars_defined) zx_tmp_fi2d(1 : klon) = lat_prec_sol_o(1 : klon, 2)
+       CALL histwrite_phy(o_lat_prec_sol_sic, zx_tmp_fi2d)       
+
        DO nsrf=1,nbsrf+1
           CALL histwrite_phy(o_wstar(nsrf), wstar(1 : klon, nsrf))
@@ -671,4 +700,6 @@
        ENDIF !iflag_con .GE. 3
        CALL histwrite_phy(o_prw, prw)
+       CALL histwrite_phy(o_prlw, prlw)
+       CALL histwrite_phy(o_prsw, prsw)
        CALL histwrite_phy(o_s_pblh, s_pblh)
        CALL histwrite_phy(o_s_pblt, s_pblt)
@@ -938,5 +969,5 @@
              !--STRAT AER
           ENDIF
-          IF (flag_aerosol.GT.0.OR.flag_aerosol_strat) THEN
+          IF (flag_aerosol.GT.0.OR.flag_aerosol_strat.GT.0) THEN
 !             DO naero = 1, naero_spc
 !--correction mini bug OB
@@ -946,5 +977,5 @@
              END DO
           ENDIF
-          IF (flag_aerosol_strat) THEN
+          IF (flag_aerosol_strat.GT.0) THEN
              CALL histwrite_phy(o_tausumaero_lw, &
                   tausum_aero(:,6,id_STRAT_phy) )
@@ -1032,4 +1063,8 @@
        CALL histwrite_phy(o_zfull,zphi/RG)
 
+       IF (flag_aerosol_strat.EQ.2) THEN
+         CALL histwrite_phy(o_stratomask, stratomask)
+       ENDIF
+      
        IF (vars_defined)  THEN
         zx_tmp_fi3d(:,1)= pphis(:)/RG
@@ -1064,7 +1099,24 @@
 
        CALL histwrite_phy(o_dtphy, d_t)
+
        CALL histwrite_phy(o_dqphy,  d_qx(:,:,ivap))
        CALL water_int(klon,klev,d_qx(:,:,ivap),zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqphy2d,  zx_tmp_fi2d)
+
+       CALL histwrite_phy(o_dqlphy,  d_qx(:,:,iliq))
+       CALL water_int(klon,klev,d_qx(:,:,iliq),zmasse,zx_tmp_fi2d)
+       CALL histwrite_phy(o_dqlphy2d,  zx_tmp_fi2d)
+
+       IF (nqo.EQ.3) THEN
+       CALL histwrite_phy(o_dqsphy,  d_qx(:,:,isol))
+       CALL water_int(klon,klev,d_qx(:,:,isol),zmasse,zx_tmp_fi2d)
+       CALL histwrite_phy(o_dqsphy2d,  zx_tmp_fi2d)
+       ELSE 
+       zx_tmp_fi3d=0.0
+       CALL histwrite_phy(o_dqsphy,  zx_tmp_fi3d)
+       zx_tmp_fi2d=0.0
+       CALL histwrite_phy(o_dqsphy2d,  zx_tmp_fi2d)
+       ENDIF
+
        DO nsrf=1, nbsrf
           IF (vars_defined) zx_tmp_fi2d(1 : klon) = falb1( 1 : klon, nsrf)
@@ -1103,7 +1155,17 @@
        CALL histwrite_phy(o_clwcon, clwcon0)
        CALL histwrite_phy(o_dtdyn, d_t_dyn)
+
        CALL histwrite_phy(o_dqdyn, d_q_dyn)
-       CALL water_int(klon,klev,d_q_dyn,zmasse,zx_tmp_fi2d)
-       CALL histwrite_phy(o_dqdyn2d,zx_tmp_fi2d)
+
+       CALL histwrite_phy(o_dqdyn2d,d_q_dyn2d)
+
+       CALL histwrite_phy(o_dqldyn, d_ql_dyn)
+
+       CALL histwrite_phy(o_dqldyn2d, d_ql_dyn2d)
+
+       CALL histwrite_phy(o_dqsdyn, d_qs_dyn)
+
+       CALL histwrite_phy(o_dqsdyn2d, d_qs_dyn2d)
+
        CALL histwrite_phy(o_dudyn, d_u_dyn)
        CALL histwrite_phy(o_dvdyn, d_v_dyn)
Index: /LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90	(revision 2542)
@@ -64,4 +64,8 @@
       REAL, ALLOCATABLE, SAVE :: t_ancien(:,:), q_ancien(:,:)
 !$OMP THREADPRIVATE(t_ancien, q_ancien)
+      REAL, ALLOCATABLE, SAVE :: ql_ancien(:,:), qs_ancien(:,:)
+!$OMP THREADPRIVATE(ql_ancien, qs_ancien)
+      REAL, ALLOCATABLE, SAVE :: prw_ancien(:), prlw_ancien(:), prsw_ancien(:)
+!$OMP THREADPRIVATE(prw_ancien, prlw_ancien, prsw_ancien)
       REAL, ALLOCATABLE, SAVE :: u_ancien(:,:), v_ancien(:,:)
 !$OMP THREADPRIVATE(u_ancien, v_ancien)
@@ -441,4 +445,6 @@
       ALLOCATE(rugoro(klon))
       ALLOCATE(t_ancien(klon,klev), q_ancien(klon,klev))
+      ALLOCATE(ql_ancien(klon,klev), qs_ancien(klon,klev))
+      ALLOCATE(prw_ancien(klon), prlw_ancien(klon), prsw_ancien(klon))
       ALLOCATE(u_ancien(klon,klev), v_ancien(klon,klev))
 !!! Rom P >>>
@@ -601,7 +607,9 @@
       deallocate(zthe, zpic, zval)
       deallocate(rugoro, t_ancien, q_ancien, clwcon, rnebcon)
+      deallocate(qs_ancien, ql_ancien)
+      deallocate(prw_ancien, prlw_ancien, prsw_ancien)
       deallocate(qtc_cv,sigt_cv)
-      deallocate(        u_ancien, v_ancien                 )
-      deallocate(        tr_ancien)                           !RomP
+      deallocate(u_ancien, v_ancien)
+      deallocate(tr_ancien)                           !RomP
       deallocate(ratqs, pbl_tke,coefh,coefm)
 !nrlmd<
Index: /LMDZ5/branches/testing/libf/phylmd/physiq_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/physiq_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/physiq_mod.F90	(revision 2542)
@@ -68,5 +68,6 @@
 
 #ifdef CPP_RRTM
-    USE YOERAD   , ONLY : NRADLP
+    USE YOERAD, ONLY : NRADLP
+    USE YOESW, ONLY : RSUN
 #endif
     USE ioipsl_getin_p_mod, ONLY : getin_p
@@ -115,4 +116,6 @@
     !! d_t_dyn-input-R-tendance dynamique pour "t" (K/s)
     !! d_q_dyn-input-R-tendance dynamique pour "q" (kg/kg/s)
+    !! d_ql_dyn-input-R-tendance dynamique pour "ql" (kg/kg/s)
+    !! d_qs_dyn-input-R-tendance dynamique pour "qs" (kg/kg/s)
     !! flxmass_w -input-R- flux de masse verticale
     !! d_u-----output-R-tendance physique de "u" (m/s/s)
@@ -366,11 +369,7 @@
     real, save :: ale_bl_prescr=0.
 
-    real, save :: ale_max=1000.
-    real, save :: alp_max=2.
-
     real, save :: wake_s_min_lsp=0.1
 
     !$OMP THREADPRIVATE(alp_bl_prescr,ale_bl_prescr)
-    !$OMP THREADPRIVATE(ale_max,alp_max)
     !$OMP THREADPRIVATE(wake_s_min_lsp)
 
@@ -436,5 +435,4 @@
     LOGICAL,SAVE :: ok_adjwk=.FALSE.
     !$OMP THREADPRIVATE(ok_adjwk) 
-    REAL, dimension(klon) :: www
     REAL, SAVE :: alp_offset
     !$OMP THREADPRIVATE(alp_offset)
@@ -681,4 +679,6 @@
     save ratqsbas,ratqshaut,tau_ratqs
     !$OMP THREADPRIVATE(ratqsbas,ratqshaut,tau_ratqs)
+    REAL, SAVE :: ratqsp0=50000., ratqsdp=20000.
+    !$OMP THREADPRIVATE(ratqsp0, ratqsdp)
 
     ! Parametres lies au nouveau schema de nuages (SB, PDF)
@@ -835,5 +835,5 @@
     !
     !--STRAT AEROSOL
-    LOGICAL, SAVE :: flag_aerosol_strat
+    INTEGER, SAVE :: flag_aerosol_strat
     !$OMP THREADPRIVATE(flag_aerosol_strat)
     !c-fin STRAT AEROSOL
@@ -1041,6 +1041,4 @@
     forall (k=1: nbp_lev) zmasse(:, k) = (paprs(:, k)-paprs(:, k+1)) / rg
 
-
-
     modname = 'physiq'
     !IM
@@ -1055,4 +1053,6 @@
        CALL getin_p('random_notrig_max',random_notrig_max)
        CALL getin_p('ok_adjwk',ok_adjwk)
+       CALL getin_p('ratqsp0',ratqsp0)
+       CALL getin_p('ratqsdp',ratqsdp)
     ENDIF
 
@@ -1597,8 +1597,6 @@
     !--store initial water burden
     qql1(:)=0.0
-    DO i = 1, klon
-      DO k = 1, klev
-        qql1(i)=qql1(i)+(q_seri(i,k)+ql_seri(i,k))*zmasse(i,k)
-      ENDDO
+    DO k = 1, klev
+      qql1(:)=qql1(:)+(q_seri(:,k)+ql_seri(:,k)+qs_seri(:,k))*zmasse(:,k)
     ENDDO
     ENDIF
@@ -1654,51 +1652,38 @@
     !
     IF (ancien_ok) THEN
-       DO k = 1, klev
-          DO i = 1, klon
-             d_u_dyn(i,k) = (u_seri(i,k)-u_ancien(i,k))/dtime
-             d_v_dyn(i,k) = (v_seri(i,k)-v_ancien(i,k))/dtime
-             d_t_dyn(i,k) = (t_seri(i,k)-t_ancien(i,k))/dtime
-             d_q_dyn(i,k) = (q_seri(i,k)-q_ancien(i,k))/dtime
-          ENDDO
-       ENDDO
+    !
+       d_u_dyn(:,:)  = (u_seri(:,:)-u_ancien(:,:))/dtime
+       d_v_dyn(:,:)  = (v_seri(:,:)-v_ancien(:,:))/dtime
+       d_t_dyn(:,:)  = (t_seri(:,:)-t_ancien(:,:))/dtime
+       d_q_dyn(:,:)  = (q_seri(:,:)-q_ancien(:,:))/dtime
+       d_ql_dyn(:,:) = (ql_seri(:,:)-ql_ancien(:,:))/dtime
+       d_qs_dyn(:,:) = (qs_seri(:,:)-qs_ancien(:,:))/dtime
+       CALL water_int(klon,klev,q_seri,zmasse,zx_tmp_fi2d)
+       d_q_dyn2d(:)=(zx_tmp_fi2d(:)-prw_ancien(:))/dtime
+       CALL water_int(klon,klev,ql_seri,zmasse,zx_tmp_fi2d)
+       d_ql_dyn2d(:)=(zx_tmp_fi2d(:)-prlw_ancien(:))/dtime
+       CALL water_int(klon,klev,qs_seri,zmasse,zx_tmp_fi2d)
+       d_qs_dyn2d(:)=(zx_tmp_fi2d(:)-prsw_ancien(:))/dtime
        ! !! RomP >>>   td dyn traceur
-       !!     IF (nqtot.GE.3) THEN       ! jyg
-       !!        DO iq = 3, nqtot        ! jyg
-       IF (nqtot.GE.nqo+1) THEN     ! jyg
+       IF (nqtot.GT.nqo) THEN     ! jyg
           DO iq = nqo+1, nqtot      ! jyg
-             DO k = 1, klev
-                DO i = 1, klon
-                   !! d_tr_dyn(i,k,iq-2)= &                               ! jyg
-                   !!    (tr_seri(i,k,iq-2)-tr_ancien(i,k,iq-2))/dtime    ! jyg
-                   d_tr_dyn(i,k,iq-nqo)= &                                ! jyg
-                        (tr_seri(i,k,iq-nqo)-tr_ancien(i,k,iq-nqo))/dtime ! jyg
-                   !         iiq=niadv(iq)
-                   ! print*,i,k," d_tr_dyn",d_tr_dyn(i,k,iq-nqo),"tra:",iq,&
-                   !  tname(iiq)
-                ENDDO
-             ENDDO
+              d_tr_dyn(:,:,iq-nqo)=(tr_seri(:,:,iq-nqo)-tr_ancien(:,:,iq-nqo))/dtime ! jyg
           ENDDO
        ENDIF
        ! !! RomP <<<
     ELSE
-       DO k = 1, klev
-          DO i = 1, klon
-             d_u_dyn(i,k) = 0.0
-             d_v_dyn(i,k) = 0.0
-             d_t_dyn(i,k) = 0.0
-             d_q_dyn(i,k) = 0.0
-          ENDDO
-       ENDDO
+       d_u_dyn(:,:)  = 0.0
+       d_v_dyn(:,:)  = 0.0
+       d_t_dyn(:,:)  = 0.0
+       d_q_dyn(:,:)  = 0.0
+       d_ql_dyn(:,:) = 0.0
+       d_qs_dyn(:,:) = 0.0
+       d_q_dyn2d(:)  = 0.0
+       d_ql_dyn2d(:) = 0.0
+       d_qs_dyn2d(:) = 0.0
        ! !! RomP >>>   td dyn traceur
-       !!     IF (nqtot.GE.3) THEN                                     ! jyg
-       !!        DO iq = 3, nqtot                                      ! jyg
-       IF (nqtot.GE.nqo+1) THEN                                        ! jyg
-          DO iq = nqo+1, nqtot                                         ! jyg
-             DO k = 1, klev
-                DO i = 1, klon
-                   !! d_tr_dyn(i,k,iq-2)= 0.0                            ! jyg
-                   d_tr_dyn(i,k,iq-nqo)= 0.0                             ! jyg
-                ENDDO
-             ENDDO
+       IF (nqtot.GT.nqo) THEN                                       ! jyg
+          DO iq = nqo+1, nqtot                                      ! jyg
+              d_tr_dyn(:,:,iq-nqo)= 0.0                             ! jyg
           ENDDO
        ENDIF
@@ -2303,134 +2288,13 @@
        !>jyg
        !
-
-       ! Calcul de l'energie disponible ALE (J/kg) et de la puissance
-       ! disponible ALP (W/m2) pour le soulevement des particules dans
-       ! le modele convectif
-       !
-       do i = 1,klon
-          ALE(i) = 0.
-          ALP(i) = 0.
-       enddo
-       !
-       !calcul de ale_wake et alp_wake
-       if (iflag_wake>=1) then
-          if (itap .le. it_wape_prescr) then
-             do i = 1,klon
-                ale_wake(i) = wape_prescr
-                alp_wake(i) = fip_prescr
-             enddo
-          else
-             do i = 1,klon
-                !jyg  ALE=WAPE au lieu de ALE = 1/2 Cstar**2
-                !cc           ale_wake(i) = 0.5*wake_cstar(i)**2
-                ale_wake(i) = wake_pe(i)
-                alp_wake(i) = wake_fip(i)
-             enddo
-          endif
-       else
-          do i = 1,klon
-             ale_wake(i) = 0.
-             alp_wake(i) = 0.
-          enddo
-       endif
-       !combinaison avec ale et alp de couche limite: constantes si pas
-       !de couplage, valeurs calculees dans le thermique sinon
-       if (iflag_coupl.eq.0) then
-          if (debut.and.prt_level.gt.9) &
-               WRITE(lunout,*)'ALE et ALP imposes'
-          do i = 1,klon
-             !on ne couple que ale
-             !           ALE(i) = max(ale_wake(i),Ale_bl(i))
-             ALE(i) = max(ale_wake(i),ale_bl_prescr)
-             !on ne couple que alp
-             !           ALP(i) = alp_wake(i) + Alp_bl(i)
-             ALP(i) = alp_wake(i) + alp_bl_prescr
-          enddo
-       else
-          IF(prt_level>9)WRITE(lunout,*)'ALE et ALP couples au thermique'
-          !         do i = 1,klon
-          !             ALE(i) = max(ale_wake(i),Ale_bl(i))
-          ! avant        ALP(i) = alp_wake(i) + Alp_bl(i)
-          !             ALP(i) = alp_wake(i) + Alp_bl(i) + alp_offset ! modif sb
-          !         write(20,*)'ALE',ALE(i),Ale_bl(i),ale_wake(i)
-          !         write(21,*)'ALP',ALP(i),Alp_bl(i),alp_wake(i)
-          !         enddo
-
-          ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-          ! Modif FH 2010/04/27. Sans doute temporaire.
-          ! Deux options pour le alp_offset : constant si >?? 0 ou
-          ! proportionnel ??a w si <0
-          ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-          ! Estimation d'une vitesse verticale effective pour ALP
-          if (1==0) THEN
-             www(1:klon)=0.
-             do k=2,klev-1
-                do i=1,klon
-                   www(i)=max(www(i),-omega(i,k)*RD*t_seri(i,k) &
-                        /(RG*paprs(i,k)) *zw2(i,k)*zw2(i,k))
-                   ! if (paprs(i,k)>pbase(i)) then
-                   ! calcul approche de la vitesse verticale en m/s
-                   !  www(i)=max(www(i),-omega(i,k)*RD*temp(i,k)/(RG*paprs(i,k))
-                   !             endif
-                   !   Le 0.1 est en gros H / ps = 1e5 / 1e4
-                enddo
-             enddo
-             do i=1,klon
-                if (www(i)>0. .and. ale_bl(i)>0. ) www(i)=www(i)/ale_bl(i)
-             enddo
-          ENDIF
-
-
-          do i = 1,klon
-             ALE(i) = max(ale_wake(i),Ale_bl(i))
-             !cc nrlmd le 10/04/2012----------Stochastic triggering------------
-             if (iflag_trig_bl.ge.1) then
-                ALE(i) = max(ale_wake(i),Ale_bl_trig(i))
-             endif
-             !cc fin nrlmd le 10/04/2012
-             if (alp_offset>=0.) then
-                ALP(i) = alp_wake(i) + Alp_bl(i) + alp_offset ! modif sb
-             else
-                abort_message ='Ne pas passer la car www non calcule'
-                CALL abort_physic (modname,abort_message,1)
-
-                ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-                !                                _                  _
-                ! Ajout d'une composante 3 * A * w w'2 a w'3 avec
-                ! w=www : w max sous pbase ou A est la fraction
-                ! couverte par les ascendances w' on utilise le fait
-                ! que A * w'3 = ALP et donc A * w'2 ~ ALP / sqrt(ALE)
-                ! (on ajoute 0.1 pour les singularites)
-                ALP(i)=alp_wake(i)*(1.+3.*www(i)/( sqrt(ale_wake(i))+0.1) ) &
-                     +alp_bl(i)  *(1.+3.*www(i)/( sqrt(ale_bl(i))  +0.1) )
-                !    ALP(i)=alp_wake(i)+Alp_bl(i)+alp_offset*min(omega(i,6),0.)
-                !             if (alp(i)<0.) then
-                !                print*,'ALP ',alp(i),alp_wake(i) &
-                !                     ,Alp_bl(i),alp_offset*min(omega(i,6),0.)
-                !             endif
-             endif
-          enddo
-          ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-       endif
-       do i=1,klon
-          if (alp(i)>alp_max) then
-             IF(prt_level>9)WRITE(lunout,*)                             &
-                  'WARNING SUPER ALP (seuil=',alp_max, &
-                  '): i, alp, alp_wake,ale',i,alp(i),alp_wake(i),ale(i)
-             alp(i)=alp_max
-          endif
-          if (ale(i)>ale_max) then
-             IF(prt_level>9)WRITE(lunout,*)                             &
-                  'WARNING SUPER ALE (seuil=',ale_max, &
-                  '): i, alp, alp_wake,ale',i,ale(i),ale_wake(i),alp(i)
-             ale(i)=ale_max
-          endif
-       enddo
-
-       !fin calcul ale et alp
-       !=======================================================================
-
-
+!jyg<
+       CALL alpale( debut, itap, dtime, paprs, omega, t_seri,   &
+                    alp_offset, it_wape_prescr,  wape_prescr, fip_prescr, &
+                    ale_bl_prescr, alp_bl_prescr, &
+                    wake_pe, wake_fip,  &
+                    Ale_bl, Ale_bl_trig, Alp_bl, &
+                    Ale, Alp )
+!>jyg
+!
        ! sb, oct02:
        ! Schema de convection modularise et vectorise:
@@ -2910,133 +2774,10 @@
           ENDIF
           !>jyg
-
-          !cc nrlmd le 10/04/2012
-          !-----------Stochastic triggering-----------
-          if (iflag_trig_bl.ge.1) then
-             !
-             IF (prt_level .GE. 10) THEN
-                print *,'cin, ale_bl_stat, alp_bl_stat ', &
-                     cin, ale_bl_stat, alp_bl_stat
-             ENDIF
-
-
-             !----Initialisations
-             do i=1,klon
-                proba_notrig(i)=1.
-                random_notrig(i)=1e6*ale_bl_stat(i)-int(1e6*ale_bl_stat(i))
-                if ( random_notrig(i) > random_notrig_max ) random_notrig(i)=0.
-                if ( ale_bl_trig(i) .lt. abs(cin(i))+1.e-10 ) then 
-                   tau_trig(i)=tau_trig_shallow
-                else
-                   tau_trig(i)=tau_trig_deep
-                endif
-             enddo
-             !
-             IF (prt_level .GE. 10) THEN
-                print *,'random_notrig, tau_trig ', &
-                     random_notrig, tau_trig
-                print *,'s_trig,s2,n2 ', &
-                     s_trig,s2,n2
-             ENDIF
-
-             !Option pour re-activer l'ancien calcul de Ale_bl (iflag_trig_bl=2)
-             IF (iflag_trig_bl.eq.1) then
-
-                !----Tirage al\'eatoire et calcul de ale_bl_trig
-                do i=1,klon
-                   if ( (ale_bl_stat(i) .gt. abs(cin(i))+1.e-10) )  then
-                      proba_notrig(i)=(1.-exp(-s_trig/s2(i)))** &
-                           (n2(i)*dtime/tau_trig(i))
-                      !        print *, 'proba_notrig(i) ',proba_notrig(i)
-                      if (random_notrig(i) .ge. proba_notrig(i)) then 
-                         ale_bl_trig(i)=ale_bl_stat(i)
-                      else
-                         ale_bl_trig(i)=0.
-                      endif
-                   else
-                      proba_notrig(i)=1.
-                      random_notrig(i)=0.
-                      ale_bl_trig(i)=0.
-                   endif
-                enddo
-
-             ELSE IF (iflag_trig_bl.ge.2) then
-
-                do i=1,klon
-                   if ( (Ale_bl(i) .gt. abs(cin(i))+1.e-10) )  then
-                      proba_notrig(i)=(1.-exp(-s_trig/s2(i)))** &
-                           (n2(i)*dtime/tau_trig(i))
-                      !        print *, 'proba_notrig(i) ',proba_notrig(i)
-                      if (random_notrig(i) .ge. proba_notrig(i)) then 
-                         ale_bl_trig(i)=Ale_bl(i)
-                      else
-                         ale_bl_trig(i)=0.
-                      endif
-                   else
-                      proba_notrig(i)=1.
-                      random_notrig(i)=0.
-                      ale_bl_trig(i)=0.
-                   endif
-                enddo
-
-             ENDIF
-
-             !
-             IF (prt_level .GE. 10) THEN
-                print *,'proba_notrig, ale_bl_trig ', &
-                     proba_notrig, ale_bl_trig
-             ENDIF
-
-          endif !(iflag_trig_bl)
-
-          !-----------Statistical closure-----------
-          if (iflag_clos_bl.eq.1) then 
-
-             do i=1,klon
-                !CR: alp probabiliste
-                if (ale_bl_trig(i).gt.0.) then
-                   alp_bl(i)=alp_bl(i)/(1.-min(proba_notrig(i),0.999))
-                endif
-             enddo
-
-          else if (iflag_clos_bl.eq.2) then
-
-             !CR: alp calculee dans thermcell_main
-             do i=1,klon
-                alp_bl(i)=alp_bl_stat(i)
-             enddo
-
-          else
-
-             alp_bl_stat(:)=0.
-
-          endif !(iflag_clos_bl)
-
-          IF (prt_level .GE. 10) THEN
-             print *,'ale_bl_trig, alp_bl_stat ',ale_bl_trig, alp_bl_stat
-          ENDIF
-
-          !cc fin nrlmd le 10/04/2012
-
-          ! ------------------------------------------------------------------
-          ! Transport de la TKE par les panaches thermiques.
-          ! FH : 2010/02/01
-          !     if (iflag_pbl.eq.10) then
-          !     call thermcell_dtke(klon,klev,nbsrf,pdtphys,fm_therm,entr_therm,
-          !    s           rg,paprs,pbl_tke)
-          !     endif
-          ! -------------------------------------------------------------------
-          !IM/FH: 2011/02/23 
-          ! Couplage Thermiques/Emanuel seulement si T<0
-          if (iflag_coupl==2) then
-             IF (prt_level .GE. 10) THEN
-                print*,'Couplage Thermiques/Emanuel seulement si T<0'
-             ENDIF
-             do i=1,klon
-                if (t_seri(i,lmax_th(i))>273.) then
-                   Ale_bl(i)=0.
-                endif
-             enddo
-          endif
+!jyg<
+!
+          CALL alpale_th( dtime, lmax_th, t_seri, &
+                          cin, s2, n2,  &
+                          ale_bl_trig, ale_bl_stat, ale_bl,  &
+                          alp_bl, alp_bl_stat )
 
           do i=1,klon
@@ -3114,5 +2855,6 @@
     CALL  calcratqs(klon,klev,prt_level,lunout,        &
          iflag_ratqs,iflag_con,iflag_cld_th,pdtphys,  &
-         ratqsbas,ratqshaut,tau_ratqs,fact_cldcon,   &
+         ratqsbas,ratqshaut,ratqsp0, ratqsdp, &
+         tau_ratqs,fact_cldcon,   &
          ptconv,ptconvth,clwcon0th, rnebcon0th,     &
          paprs,pplay,q_seri,zqsat,fm_therm, &
@@ -3301,5 +3043,7 @@
                 ENDIF
 
-                CALL aeropt_lw_rrtm
+                !--call LW optical properties for tropospheric aerosols 
+                !--only works for INCA aerosol (aerosol_couple = TRUE)
+                CALL aeropt_lw_rrtm(aerosol_couple,paprs,tr_seri)
                 !
 #else
@@ -3327,15 +3071,27 @@
        !--STRAT AEROSOL
        !--updates tausum_aero,tau_aero,piz_aero,cg_aero
-       IF (flag_aerosol_strat) THEN
+       IF (flag_aerosol_strat.GT.0) THEN
           IF (prt_level .GE.10) THEN
              PRINT *,'appel a readaerosolstrat', mth_cur
           ENDIF
           IF (iflag_rrtm.EQ.0) THEN
+           IF (flag_aerosol_strat.EQ.1) THEN
              CALL readaerosolstrato(debut)
+           ELSE
+             abort_message='flag_aerosol_strat must equal 1 for rrtm=0'
+             call abort_physic(modname,abort_message,1)
+           ENDIF
           ELSE
 #ifdef CPP_RRTM
-             CALL readaerosolstrato_rrtm(debut)
+            IF (flag_aerosol_strat.EQ.1) THEN
+             CALL readaerosolstrato1_rrtm(debut)
+            ELSEIF (flag_aerosol_strat.EQ.2) THEN
+             CALL stratosphere_mask(t_seri, pplay, latitude_deg)
+             CALL readaerosolstrato2_rrtm(debut)
+            ELSE
+             abort_message='flag_aerosol_strat must equal 1 or 2 for rrtm=1'
+             call abort_physic(modname,abort_message,1)
+            ENDIF
 #else
-
              abort_message='You should compile with -rrtm if running ' &
                   // 'with iflag_rrtm=1'
@@ -3345,5 +3101,4 @@
        ENDIF
        !--fin STRAT AEROSOL
-
 
        !   On prend la somme des fractions nuageuses et des contenus en eau
@@ -3673,4 +3428,13 @@
        !albedo SB <<<
 
+!--if ok_suntime_rrtm we use ancillay data for RSUN 
+!--previous values are therefore overwritten
+!--this is needed for CMIP6 runs
+!--and only possible for new radiation scheme
+       IF (iflag_rrtm.EQ.1.AND.ok_suntime_rrtm) THEN 
+#ifdef CPP_RRTM
+         CALL read_rsun_rrtm(debut)
+#endif
+       ENDIF
 
        if (mydebug) then
@@ -3726,4 +3490,5 @@
              print *,' ->radlwsw, number 1 '
           ENDIF
+
           !
           CALL radlwsw &
@@ -3735,5 +3500,5 @@
                t_seri,q_seri,wo, &
                cldfrarad, cldemirad, cldtaurad, &
-               ok_ade.OR.flag_aerosol_strat, ok_aie, flag_aerosol, &
+               ok_ade.OR.flag_aerosol_strat.GT.0, ok_aie, flag_aerosol, &
                flag_aerosol_strat, &
                tau_aero, piz_aero, cg_aero, &
@@ -3764,4 +3529,9 @@
                ZSWFT0_i, ZFSDN0, ZFSUP0)
 
+          !--OB 30/05/2016
+          !--here we return swaero_diag to FALSE
+          !--and histdef will switch it back to TRUE if necessary
+          !--this is necessary to get the right swaero at first step
+          IF (debut) swaero_diag = .FALSE.
           !
           !IM 2eme calcul radiatif pour le cas perturbe ou au moins un
@@ -3792,5 +3562,5 @@
                      t_seri,q_seri,wo, &
                      cldfra, cldemi, cldtau, &
-                     ok_ade.OR.flag_aerosol_strat, ok_aie, flag_aerosol, &
+                     ok_ade.OR.flag_aerosol_strat.GT.0, ok_aie, flag_aerosol, &
                      flag_aerosol_strat, &
                      tau_aero, piz_aero, cg_aero, &
@@ -4297,11 +4067,14 @@
     CALL diag_slp(klon,t_seri,paprs,pplay,pphis,ptstar,pt0,slp)
     !
-    !cc prw = eau precipitable
-    DO i = 1, klon
-       prw(i) = 0.
-       DO k = 1, klev
-          prw(i) = prw(i) + &
-               q_seri(i,k)*(paprs(i,k)-paprs(i,k+1))/RG
-       ENDDO
+    !cc prw  = eau precipitable
+    !   prlw = colonne eau liquide 
+    !   prlw = colonne eau solide
+    prw(:) = 0.
+    prlw(:) = 0.
+    prsw(:) = 0.
+    DO k = 1, klev
+       prw(:)  = prw(:)  + q_seri(:,k)*zmasse(:,k)
+       prlw(:) = prlw(:) + ql_seri(:,k)*zmasse(:,k)
+       prsw(:) = prsw(:) + qs_seri(:,k)*zmasse(:,k)
     ENDDO
     !
@@ -4377,27 +4150,38 @@
     !
 
+    !--OB mass fixer 
+    !--profile is corrected to force mass conservation of water
+    IF (mass_fixer) THEN
+    qql2(:)=0.0
+    DO k = 1, klev
+      qql2(:)=qql2(:)+(q_seri(:,k)+ql_seri(:,k)+qs_seri(:,k))*zmasse(:,k)
+    ENDDO
+    DO i = 1, klon
+      !--compute ratio of what q+ql should be with conservation to what it is
+      corrqql=(qql1(i)+(evap(i)-rain_fall(i)-snow_fall(i))*pdtphys)/qql2(i)
+      DO k = 1, klev
+        q_seri(i,k) =q_seri(i,k)*corrqql
+        ql_seri(i,k)=ql_seri(i,k)*corrqql
+      ENDDO
+    ENDDO
+    ENDIF
+    !--fin mass fixer
+
     ! Sauvegarder les valeurs de t et q a la fin de la physique:
     !
-    DO k = 1, klev
-       DO i = 1, klon
-          u_ancien(i,k) = u_seri(i,k)
-          v_ancien(i,k) = v_seri(i,k)
-          t_ancien(i,k) = t_seri(i,k)
-          q_ancien(i,k) = q_seri(i,k)
-       ENDDO
-    ENDDO
-
+    u_ancien(:,:)  = u_seri(:,:)
+    v_ancien(:,:)  = v_seri(:,:)
+    t_ancien(:,:)  = t_seri(:,:)
+    q_ancien(:,:)  = q_seri(:,:)
+    ql_ancien(:,:) = ql_seri(:,:)
+    qs_ancien(:,:) = qs_seri(:,:)
+    CALL water_int(klon,klev,q_ancien,zmasse,prw_ancien)
+    CALL water_int(klon,klev,ql_ancien,zmasse,prlw_ancien)
+    CALL water_int(klon,klev,qs_ancien,zmasse,prsw_ancien)
     ! !! RomP >>>
     !CR: nb de traceurs eau: nqo
-    !  IF (nqtot.GE.3) THEN
-    IF (nqtot.GE.(nqo+1)) THEN
-       !     DO iq = 3, nqtot
+    IF (nqtot.GT.nqo) THEN
        DO iq = nqo+1, nqtot
-          DO k = 1, klev
-             DO i = 1, klon
-                !              tr_ancien(i,k,iq-2) = tr_seri(i,k,iq-2)
-                tr_ancien(i,k,iq-nqo) = tr_seri(i,k,iq-nqo)
-             ENDDO
-          ENDDO
+          tr_ancien(:,:,iq-nqo) = tr_seri(:,:,iq-nqo)
        ENDDO
     ENDIF
@@ -4483,7 +4267,5 @@
     ! Get some variables from module fonte_neige_mod
     CALL fonte_neige_get_vars(pctsrf,  &
-         zxfqcalving, zxfqfonte, zxffonte)
-
-
+         zxfqcalving, zxfqfonte, zxffonte, zxrunofflic)
 
 
@@ -4521,6 +4303,6 @@
     CALL phys_output_write(itap, pdtphys, paprs, pphis,  &
          pplay, lmax_th, aerosol_couple,                 &
-         ok_ade, ok_aie, ivap, new_aod, ok_sync,         &
-         ptconv, read_climoz, clevSTD,                   &
+         ok_ade, ok_aie, ivap, iliq, isol, new_aod,      & 
+         ok_sync, ptconv, read_climoz, clevSTD,          &
          ptconvth, d_t, qx, d_qx, zmasse,                &
          flag_aerosol, flag_aerosol_strat, ok_cdnc)
@@ -4544,24 +4326,4 @@
        CALL abort_physic (modname,abort_message,1)
     ENDIF
-
-    !--OB mass fixer 
-    !--profile is corrected to force mass conservation of water
-    IF (mass_fixer) THEN
-    qql2(:)=0.0
-    DO i = 1, klon
-      DO k = 1, klev
-        qql2(i)=qql2(i)+(q_seri(i,k)+ql_seri(i,k))*zmasse(i,k)
-      ENDDO
-    ENDDO
-    DO i = 1, klon
-      !--compute ratio of what q+ql should be with conservation to what it is
-      corrqql=(qql1(i)+(evap(i)-rain_fall(i)-snow_fall(i))*pdtphys)/qql2(i)
-      DO k = 1, klev
-        q_seri(i,k) =q_seri(i,k)*corrqql
-        ql_seri(i,k)=ql_seri(i,k)*corrqql
-      ENDDO
-    ENDDO
-    ENDIF
-    !--fin mass fixer
 
     ! 22.03.04 END
Index: /LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90	(revision 2542)
@@ -101,5 +101,5 @@
   ! ok_aie---input-L- apply the Aerosol Indirect Effect or not?
   ! flag_aerosol-input-I- aerosol flag from 0 to 6
-  ! flag_aerosol_strat-input-I- use stratospheric aerosols flag (T/F)
+  ! flag_aerosol_strat-input-I- use stratospheric aerosols flag (0, 1, 2)
   ! tau_ae, piz_ae, cg_ae-input-R- aerosol optical properties (calculated in aeropt.F)
   ! cldtaupi-input-R- epaisseur optique des nuages dans le visible
@@ -190,5 +190,5 @@
   LOGICAL              :: lldebug
   INTEGER, INTENT(in)  :: flag_aerosol                                   ! takes value 0 (no aerosol) or 1 to 6 (aerosols)
-  LOGICAL, INTENT(in)  :: flag_aerosol_strat                             ! use stratospheric aerosols
+  INTEGER, INTENT(in)  :: flag_aerosol_strat                             ! use stratospheric aerosols
   REAL,    INTENT(in)  :: cldfra(KLON,KLEV), cldemi(KLON,KLEV), cldtaupd(KLON,KLEV)
   REAL,    INTENT(in)  :: tau_aero(KLON,KLEV,naero_grp,2)                        ! aerosol optical properties (see aeropt.F)
Index: /LMDZ5/branches/testing/libf/phylmd/readaerosol_interp.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/readaerosol_interp.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/readaerosol_interp.F90	(revision 2542)
@@ -313,6 +313,6 @@
           ! the second half of the month
           im2=im+1
-          day2 = month_mid(im+1)
-          day1 = month_mid(im2+1)
+          day1 = month_mid(im+1)
+          day2 = month_mid(im2+1)
           IF (im2 > 12) THEN
              ! the month is december, the following thus january
@@ -330,6 +330,6 @@
           ! the second half of the month
           im2=im+1
-          day2 = month_mid(im)
-          day1 = month_mid(im2)
+          day1 = month_mid(im)
+          day2 = month_mid(im2)
        END IF
      ELSE
Index: /LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90	(revision 2542)
@@ -9,4 +9,5 @@
                                  grid2dto1d_glo
     USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
     USE mod_phys_lmdz_para 
     USE phys_state_var_mod
@@ -64,5 +65,6 @@
     IF (debut.OR.mth_cur.NE.mth_pre) THEN
 
-    IF (is_mpi_root) THEN
+!--only root reads
+    IF (is_mpi_root.AND.is_omp_root) THEN
 
     IF (nbands.NE.2) THEN 
@@ -128,5 +130,7 @@
     CALL grid2dTo1d_glo(tauaerstrat_mois,tauaerstrat_mois_glo)
 
-    ENDIF !--is_mpi_root
+    ENDIF !--is_mpi_root and is_omp_root
+
+!$OMP BARRIER
 
 !--scatter on all proc
@@ -136,5 +140,5 @@
     mth_pre=mth_cur
 !
-    IF (is_mpi_root) THEN
+    IF (is_mpi_root.AND.is_omp_root) THEN
 !
     DEALLOCATE(tauaerstrat)
@@ -142,5 +146,7 @@
     DEALLOCATE(tauaerstrat_mois_glo)
 !
-    ENDIF !-is_mpi_root
+    ENDIF !-is_mpi_root and is_omp_root
+
+!$OMP BARRIER
 
     ENDIF !--debut ou nouveau mois
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/aeropt_lw_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/aeropt_lw_rrtm.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/aeropt_lw_rrtm.F90	(revision 2542)
@@ -1,13 +1,108 @@
 !
 ! aeropt_lw_rrtm.F90 2014-05-13 C. Kleinschmitt
+!                    2016-05-03 O. Boucher 
 !
+! This routine feeds aerosol LW properties to RRTM
+! we only consider absorption (not scattering)
 
-SUBROUTINE AEROPT_LW_RRTM
+SUBROUTINE AEROPT_LW_RRTM(aerosol_couple,paprs,tr_seri)
 
+  USE dimphy
+  USE aero_mod
+  USE infotrac_phy
   USE phys_state_var_mod, ONLY : tau_aero_lw_rrtm
+  USE YOERAD, ONLY : NLW
 
   IMPLICIT NONE
 
-  tau_aero_lw_rrtm(:,:,:,:) = 1.e-15
+  INCLUDE "YOMCST.h"
+  INCLUDE "clesphys.h"
+  !
+  ! Input arguments:
+  !
+  LOGICAL, INTENT(IN)                         :: aerosol_couple
+  REAL, DIMENSION(klon,klev+1), INTENT(in)    :: paprs
+  REAL, DIMENSION(klon,klev,nbtr), INTENT(in) :: tr_seri
+  !
+  REAL, DIMENSION(klon,klev) :: zdp, mass_temp
+  ! 
+  !
+  INTEGER inu, i, k
+  INTEGER :: id_ASBCM, id_ASPOMM, id_ASSO4M, id_ASMSAM, id_CSSO4M, id_CSMSAM, id_SSSSM
+  INTEGER :: id_CSSSM, id_ASSSM, id_CIDUSTM, id_AIBCM, id_AIPOMM, id_ASNO3M, id_CSNO3M, id_CINO3M
 
+  !
+  !--absorption coefficient for CIDUST
+  REAL:: alpha_abs_CIDUST_16bands(nbands_lw_rrtm)   !--unit m2/g 
+  DATA alpha_abs_CIDUST_16bands /              & 
+       0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, & 
+       0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0  /
+  !
+  IF (NLW.NE.nbands_lw_rrtm) THEN
+     print *,'Erreur NLW doit etre egal a 16 pour cette routine'
+     stop
+  ENDIF
+  ! 
+  IF (aerosol_couple) THEN 
+  ! 
+      do i=1,nbtr
+      select case(trim(solsym(i)))
+         case ("ASBCM")
+            id_ASBCM = i
+         case ("ASPOMM")
+            id_ASPOMM = i
+         case ("ASSO4M")
+            id_ASSO4M = i
+         case ("ASMSAM")
+            id_ASMSAM = i
+         case ("CSSO4M")
+            id_CSSO4M = i
+         case ("CSMSAM")
+            id_CSMSAM = i
+         case ("SSSSM")
+            id_SSSSM = i
+         case ("CSSSM")
+            id_CSSSM = i
+         case ("ASSSM")
+            id_ASSSM = i
+         case ("CIDUSTM")
+            id_CIDUSTM = i
+         case ("AIBCM")
+            id_AIBCM = i
+         case ("AIPOMM")
+            id_AIPOMM = i
+         case ("ASNO3M")
+            id_ASNO3M = i
+         case ("CSNO3M")
+            id_CSNO3M = i
+         case ("CINO3M")
+            id_CINO3M = i
+         end select
+    enddo
+    !
+    DO k=1, klev
+       zdp(:,k) = (paprs(:,k)-paprs(:,k+1))/RG !--kg/m2
+    ENDDO
+    !
+    !--for now only consider dust
+    mass_temp(:,:)=tr_seri(:,:,id_CIDUSTM)  !--kg/kg
+    !
+    DO inu=1,NLW
+      !
+      !--total aerosol
+      tau_aero_lw_rrtm(:,:,2,inu) = mass_temp(:,:)*zdp(:,:)*1000.*alpha_abs_CIDUST_16bands(inu)
+      !--no aerosol at all
+      tau_aero_lw_rrtm(:,:,1,inu) = 0.0
+      !
+    ENDDO
+    !
+    !--avoid very small values
+    tau_aero_lw_rrtm = MAX(tau_aero_lw_rrtm,1.e-15)
+    ! 
+  ELSE !--not aerosol_couple
+    !
+    !--no LW effects if not coupled to INCA
+    tau_aero_lw_rrtm = 1.e-15
+  ENDIF
+  !
 END SUBROUTINE AEROPT_LW_RRTM
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/read_rsun_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/read_rsun_rrtm.F90	(revision 2542)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/read_rsun_rrtm.F90	(revision 2542)
@@ -0,0 +1,100 @@
+SUBROUTINE read_rsun_rrtm(debut)
+
+!****************************************************************************************
+! This routine will read the solar constant fraction per band
+!
+! Olivier Boucher with inputs from Marion Marchand 
+!****************************************************************************************
+
+  USE netcdf95, ONLY: nf95_close, nf95_inq_varid, nf95_open, nf95_gw_var
+  USE netcdf, ONLY: nf90_get_var, nf90_noerr, nf90_nowrite
+
+  USE phys_cal_mod, ONLY : day_cur, year_len
+
+  USE mod_phys_lmdz_mpi_data, ONLY: is_mpi_root
+  USE mod_phys_lmdz_omp_data, ONLY: is_omp_root
+  USE mod_phys_lmdz_para
+
+  USE YOESW    , ONLY : RSUN
+
+  IMPLICIT NONE
+
+  INCLUDE "clesphys.h"
+
+  ! Input arguments
+  LOGICAL, INTENT(IN)          :: debut
+
+! Local variables
+  INTEGER               :: ncid, dimid, varid, ncerr, nbday
+  REAL, POINTER :: wlen(:), time(:)
+  REAL, ALLOCATABLE, SAVE, DIMENSION(:,:)   :: SSI_FRAC
+!$OMP THREADPRIVATE(SSI_FRAC)
+  REAL, ALLOCATABLE, SAVE, DIMENSION(:) :: TSI(:)
+!$OMP THREADPRIVATE(TSI)
+
+  INTEGER, SAVE :: day_pre
+
+!--only one processor reads
+    IF (debut) THEN 
+
+    ALLOCATE(SSI_FRAC(NSW,year_len))
+    ALLOCATE(TSI(year_len))
+
+    IF (is_mpi_root.AND.is_omp_root) THEN
+
+       CALL nf95_open('solarforcing.nc', NF90_NOWRITE, ncid)
+
+       CALL nf95_inq_varid(ncid, 'wlen', varid)
+       CALL nf95_gw_var(ncid, varid, wlen)
+
+       CALL nf95_inq_varid(ncid, 'time', varid)
+       CALL nf95_gw_var(ncid, varid, time)
+
+       IF (NSW.NE.size(wlen)) THEN 
+         PRINT *,'read_rsun_rrtm NSW <> wlen = ',NSW, size(wlen)
+         CALL abort_physic('read_rsun_rrtm','size of SSI is different from NSW',1)
+       ENDIF
+
+       IF (size(time).NE.year_len) THEN 
+         PRINT *,'read_rsun_rrtm time <> year_len = ', size(time), year_len
+         CALL abort_physic('read_rsun_rrtm','time dim should be the number of days in year',1)
+       ENDIF
+
+       CALL nf95_inq_varid(ncid, 'ssi_frac', varid)
+       ncerr = nf90_get_var(ncid, varid, SSI_FRAC)
+
+       CALL nf95_inq_varid(ncid, 'tsi', varid)
+       ncerr = nf90_get_var(ncid, varid, TSI)
+
+       CALL nf95_close(ncid)
+
+       DO nbday=1, year_len
+         IF (ABS(SUM(SSI_FRAC(:,nbday))-1.).GT.1.e-6) THEN 
+           PRINT *,'somme SSI_FRAC=', SUM(SSI_FRAC(:,nbday))
+           CALL abort_physic('read_rsun_rrtm','somme SSI_FRAC <> 1',1)
+         ENDIF
+       ENDDO
+     
+    ENDIF ! is_mpi_root .AND. is_omp_root
+
+!$OMP BARRIER
+    CALL bcast(SSI_FRAC)
+    CALL bcast(TSI)
+
+    ENDIF
+
+!--only read at beginning of month
+    IF (debut.OR.day_cur.NE.day_pre) THEN
+
+!--keep memory of previous month
+      day_pre=day_cur
+
+!--copy 
+      RSUN(:)=SSI_FRAC(:,day_cur)
+      solaire=TSI(day_cur)
+
+      print *,'READ_RSUN_RRTM day=', day_cur,' solaire=', solaire, ' RSUN=', RSUN(1:NSW)
+
+    ENDIF !--fin allocation
+
+END SUBROUTINE read_rsun_rrtm
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosol_optic_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosol_optic_rrtm.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosol_optic_rrtm.F90	(revision 2542)
@@ -19,5 +19,5 @@
        load_tmp1,load_tmp2,load_tmp3,load_tmp4,load_tmp5,load_tmp6,load_tmp7
 
-  USE infotrac
+  USE infotrac_phy
 
   IMPLICIT NONE
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90	(revision 2542)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90	(revision 2542)
@@ -0,0 +1,231 @@
+!
+! $Id: readaerosolstrato1_rrtm.F90 2526 2016-05-26 22:13:40Z oboucher $
+!
+subroutine readaerosolstrato1_rrtm(debut)
+
+    use netcdf95, only: nf95_close, nf95_gw_var, nf95_inq_dimid, & 
+                        nf95_inq_varid, nf95_open
+    use netcdf, only: nf90_get_var, nf90_noerr, nf90_nowrite
+
+    USE phys_cal_mod, ONLY : mth_cur
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
+    USE mod_phys_lmdz_para 
+    USE phys_state_var_mod
+    USE phys_local_var_mod
+    USE aero_mod
+    USE dimphy
+    USE YOERAD   , ONLY : NLW
+
+    implicit none
+
+    include "YOMCST.h"
+
+! Variable input
+    logical debut
+
+! Variables locales
+    integer n_lat   ! number of latitudes in the input data
+    integer n_lon   ! number of longitudes in the input data
+    integer n_lev   ! number of levels in the input data
+    integer n_month ! number of months in the input data
+    real, pointer:: latitude(:)
+    real, pointer:: longitude(:)
+    real, pointer:: time(:)
+    real, pointer:: lev(:)
+    integer k, band, wave, i
+    integer, save :: mth_pre
+
+    real, allocatable, dimension(:,:), save :: tau_aer_strat
+!$OMP THREADPRIVATE(tau_aer_strat)
+
+! Champs reconstitues
+    real, allocatable:: tauaerstrat(:, :, :, :)
+    real, allocatable:: tauaerstrat_mois(:, :, :)
+    real, allocatable:: tauaerstrat_mois_glo(:, :)
+
+    real, allocatable:: sum_tau_aer_strat(:)
+
+! For NetCDF:
+    integer ncid_in  ! IDs for input files
+    integer varid, ncerr
+
+! Stratospheric aerosols optical properties
+! alpha_sw_strat over the 6 bands is normalised by the 550 nm extinction coefficient
+    real, dimension(nbands_sw_rrtm) :: alpha_sw_strat, piz_sw_strat, cg_sw_strat
+    data alpha_sw_strat/0.8545564, 0.8451642, 0.9821724, 0.8145110, 0.3073565, 7.7966176E-02/
+    data cg_sw_strat   /0.6997170, 0.6810035, 0.7403592, 0.7562674, 0.6676504, 0.3478689/
+    data piz_sw_strat  /0.9999998, 0.9999998, 1.000000000, 0.9999958, 0.9977155, 0.4510679/
+!
+!--diagnostics AOD in the SW
+! alpha_sw_strat_wave is *not* normalised by the 550 nm extinction coefficient
+    real, dimension(nwave) :: alpha_sw_strat_wave
+    data alpha_sw_strat_wave/3.708007,4.125824,4.136584,3.887478,3.507738/
+!
+!--diagnostics AOD in the LW at 10 um 
+    real :: alpha_lw_strat_wave
+    data alpha_lw_strat_wave/0.2746812/
+!
+    real, dimension(nbands_lw_rrtm) :: alpha_lw_abs_rrtm
+    data alpha_lw_abs_rrtm/   8.8340312E-02, 6.9856711E-02, 6.2652975E-02, 5.7188231E-02, &
+                              6.3157059E-02, 5.5072524E-02, 5.0571125E-02, 0.1349073, &    
+                              0.1381676, 9.6506312E-02, 5.1312990E-02, 2.4256418E-02, &
+                              2.7191756E-02, 3.3862915E-02, 1.6132960E-02, 1.4275438E-02/ ! calculated with Mie_SW_LW_RRTM_V2.4 (bimodal, corrected)
+                                                                                          ! for r_0=/0.13E-6, 0.41E-6/ m, sigma_g=/1.26, 1.30/
+                                                                                          ! order: increasing wavelength!
+!--------------------------------------------------------
+
+    IF (.not.ALLOCATED(tau_aer_strat)) ALLOCATE(tau_aer_strat(klon,klev))
+    IF (.not.ALLOCATED(sum_tau_aer_strat)) ALLOCATE(sum_tau_aer_strat(klon))
+
+!--we only read monthly strat aerosol data
+    IF (debut.OR.mth_cur.NE.mth_pre) THEN
+
+!--only root reads the data
+    IF (is_mpi_root.AND.is_omp_root) THEN
+
+    IF (nbands_sw_rrtm.NE.6) THEN 
+        print *,'nbands_sw_rrtm doit etre egal a 6 dans readaerosolstrat_rrtm'
+        STOP
+    ENDIF
+
+    CALL nf95_open("taustrat.nc", nf90_nowrite, ncid_in)
+
+    CALL nf95_inq_varid(ncid_in, "LEV", varid)
+    CALL nf95_gw_var(ncid_in, varid, lev)
+    n_lev = size(lev)
+    IF (n_lev.NE.klev) THEN 
+       print *,'Le nombre de niveaux n est pas egal a klev'
+       STOP
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "LAT", varid)
+    CALL nf95_gw_var(ncid_in, varid, latitude)
+    n_lat = size(latitude)
+    print *, 'LAT aerosol strato=', n_lat, latitude
+    IF (n_lat.NE.nbp_lat) THEN 
+       print *,'Le nombre de lat n est pas egal a nbp_lat'
+       STOP
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "LON", varid)
+    CALL nf95_gw_var(ncid_in, varid, longitude)
+    n_lon = size(longitude)
+    print *, 'LON aerosol strato=', n_lon, longitude
+    IF (n_lon.NE.nbp_lon) THEN 
+       print *,'Le nombre de lon n est pas egal a nbp_lon'
+       STOP
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "TIME", varid)
+    CALL nf95_gw_var(ncid_in, varid, time)
+    n_month = size(time)
+    print *, 'TIME aerosol strato=', n_month, time
+    IF (n_month.NE.12) THEN 
+       print *,'Le nombre de month n est pas egal a 12'
+       STOP
+    ENDIF
+
+    ALLOCATE(tauaerstrat(n_lon, n_lat, n_lev, n_month))
+    ALLOCATE(tauaerstrat_mois(n_lon, n_lat, n_lev))
+    ALLOCATE(tauaerstrat_mois_glo(klon_glo, n_lev))
+
+!--reading stratospheric AOD at 550 nm
+    CALL nf95_inq_varid(ncid_in, "TAUSTRAT", varid)
+    ncerr = nf90_get_var(ncid_in, varid, tauaerstrat)
+    print *,'code erreur readaerosolstrato=', ncerr, varid
+
+    CALL nf95_close(ncid_in)
+
+!---select the correct month
+    IF (mth_cur.LT.1.OR.mth_cur.GT.12) THEN
+      print *,'probleme avec le mois dans readaerosolstrat =', mth_cur
+    ENDIF
+    tauaerstrat_mois(:,:,:) = tauaerstrat(:,:,:,mth_cur)
+
+!---reduce to a klon_glo grid 
+    CALL grid2dTo1d_glo(tauaerstrat_mois,tauaerstrat_mois_glo)
+
+    ENDIF !--is_mpi_root and is_omp_root
+
+!$OMP BARRIER
+
+!--keep memory of previous month
+    mth_pre=mth_cur
+
+!--scatter on all proc
+    CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
+
+    IF (is_mpi_root.AND.is_omp_root) THEN
+!
+    DEALLOCATE(tauaerstrat)
+    DEALLOCATE(tauaerstrat_mois)
+    DEALLOCATE(tauaerstrat_mois_glo)
+!
+    ENDIF !--is_mpi_root and is_omp_root
+
+!$OMP BARRIER
+
+    ENDIF !--debut ou nouveau mois
+
+!--total vertical aod at the 5 SW wavelengths
+    DO wave=1, nwave
+    DO k=1, klev
+    tausum_aero(:,wave,id_STRAT_phy)=tausum_aero(:,wave,id_STRAT_phy)+ &
+       tau_aer_strat(:,k)*alpha_sw_strat_wave(wave)/alpha_sw_strat_wave(2)
+    ENDDO
+    ENDDO
+
+!--weighted average for cg, piz and tau, adding strat aerosols on top of tropospheric ones
+    DO band=1, nbands_sw_rrtm
+!--anthropogenic aerosols bands 1 to nbands_sw_rrtm 
+    cg_aero_sw_rrtm(:,:,2,band)  = ( cg_aero_sw_rrtm(:,:,2,band)*piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) + &
+                                  cg_sw_strat(band)*piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:) ) /           &
+                             MAX( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                                &
+                                  piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:), 1.e-15 )
+    piz_aero_sw_rrtm(:,:,2,band)  = ( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                            &
+                              piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:) ) /                                 &
+                              MAX( tau_aero_sw_rrtm(:,:,2,band) + alpha_sw_strat(band)*tau_aer_strat(:,:), 1.e-15 )
+    tau_aero_sw_rrtm(:,:,2,band)  = tau_aero_sw_rrtm(:,:,2,band) + alpha_sw_strat(band)*tau_aer_strat(:,:)
+!--natural aerosols bands 1 to nbands_sw_rrtm
+    cg_aero_sw_rrtm(:,:,1,band)  = ( cg_aero_sw_rrtm(:,:,1,band)*piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) + &
+                             cg_sw_strat(band)*piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:) ) /                &
+                             MAX( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                                &
+                                  piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:), 1.e-15 )
+    piz_aero_sw_rrtm(:,:,1,band)  = ( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                            &
+                              piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:) ) /                                 &
+                              MAX( tau_aero_sw_rrtm(:,:,1,band) + alpha_sw_strat(band)*tau_aer_strat(:,:),1.e-15 )
+    tau_aero_sw_rrtm(:,:,1,band)  = tau_aero_sw_rrtm(:,:,1,band) + alpha_sw_strat(band)*tau_aer_strat(:,:)
+!--no stratospheric aerosol in index 1 for these tests
+!    cg_aero_sw_rrtm(:,:,1,band)  =  cg_aero_sw_rrtm(:,:,1,band)
+!    piz_aero_sw_rrtm(:,:,1,band)  = piz_aero_sw_rrtm(:,:,1,band)
+!    tau_aero_sw_rrtm(:,:,1,band)  = tau_aero_sw_rrtm(:,:,1,band)
+    ENDDO
+
+!--stratospheric AOD in LW
+    IF (nbands_lw_rrtm .NE. NLW) then
+      print*, 'different values for NLW (=',NLW,') and nbands_lw_rrtm (=', nbands_lw_rrtm, ')'
+      STOP
+    ENDIF 
+
+    DO band=1, nbands_lw_rrtm
+    tau_aero_lw_rrtm(:,:,2,band)  = tau_aero_lw_rrtm(:,:,2,band) + alpha_lw_abs_rrtm(band)*tau_aer_strat(:,:)
+    tau_aero_lw_rrtm(:,:,1,band)  = tau_aero_lw_rrtm(:,:,1,band) + alpha_lw_abs_rrtm(band)*tau_aer_strat(:,:) 
+!--no stratospheric aerosols in index 1 for these tests
+!    tau_aero_lw_rrtm(:,:,1,band)  = tau_aero_lw_rrtm(:,:,1,band) 
+    ENDDO
+
+!--default SSA value if there is no aerosol
+!--to avoid 0 values that seems to cause some problem to RRTM
+    WHERE (tau_aero_sw_rrtm.LT.1.e-14)
+      piz_aero_sw_rrtm = 1.0
+    ENDWHERE
+
+!--in principle this should not be necessary 
+!--as these variables have min values already but just in case
+!--put 1e-15 min value to both SW and LW AOD
+    tau_aero_sw_rrtm = MAX(tau_aero_sw_rrtm,1.e-15)
+    tau_aero_lw_rrtm = MAX(tau_aero_lw_rrtm,1.e-15)
+
+end subroutine readaerosolstrato1_rrtm
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90	(revision 2542)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90	(revision 2542)
@@ -0,0 +1,331 @@
+!
+! $Id: readaerosolstrato2_rrtm.F90 2526 2016-05-26 22:13:40Z oboucher $
+!
+subroutine readaerosolstrato2_rrtm(debut)
+
+    use netcdf95, only: nf95_close, nf95_gw_var, nf95_inq_dimid, & 
+                        nf95_inq_varid, nf95_open
+    use netcdf, only: nf90_get_var, nf90_noerr, nf90_nowrite
+
+    USE phys_cal_mod, ONLY : mth_cur
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
+    USE mod_phys_lmdz_para 
+    USE phys_state_var_mod
+    USE phys_local_var_mod
+    USE aero_mod
+    USE dimphy
+    USE YOERAD   , ONLY : NLW
+
+    implicit none
+
+    include "YOMCST.h"
+    INCLUDE "clesphys.h"
+
+    CHARACTER (len = 80) :: abort_message
+    CHARACTER (LEN=20) :: modname = 'readaerosolstrato2'
+
+! Variable input
+    logical, intent(in) ::  debut
+
+! Variables locales
+    integer n_lat   ! number of latitudes in the input data
+    integer n_lon   ! number of longitudes
+    integer n_lev   ! number of levels in the input data
+    integer n_month ! number of months in the input data
+    integer n_wav   ! number of wavelengths in the input data
+    real, pointer:: latitude(:)
+    real, pointer:: longitude(:)
+    real, pointer:: time(:)
+    real, pointer:: lev(:)
+    real, pointer:: wav(:)
+    integer i,k,wave,band
+    integer, save :: mth_pre
+
+    real, allocatable, dimension(:,:,:), save :: tau_aer_strat
+    real, allocatable, dimension(:,:,:), save :: piz_aer_strat
+    real, allocatable, dimension(:,:,:), save :: cg_aer_strat
+    real, allocatable, dimension(:,:,:), save :: taulw_aer_strat
+!$OMP THREADPRIVATE(tau_aer_strat,piz_aer_strat,cg_aer_strat,taulw_aer_strat)
+
+! Champs reconstitues
+    real, allocatable:: tauaerstrat(:, :, :, :)
+    real, allocatable:: pizaerstrat(:, :, :, :)
+    real, allocatable:: cgaerstrat(:, :, :, :)
+    real, allocatable:: taulwaerstrat(:, :, :, :)
+
+    real, allocatable:: tauaerstrat_mois(:, :, :, :)
+    real, allocatable:: pizaerstrat_mois(:, :, :, :)
+    real, allocatable:: cgaerstrat_mois(:, :, :, :)
+    real, allocatable:: taulwaerstrat_mois(:, :, :, :)
+
+    real, allocatable:: tauaerstrat_mois_glo(:, :, :)
+    real, allocatable:: pizaerstrat_mois_glo(:, :, :)
+    real, allocatable:: cgaerstrat_mois_glo(:, :, :)
+    real, allocatable:: taulwaerstrat_mois_glo(:, :, :)
+
+! For NetCDF:
+    integer ncid_in  ! IDs for input files
+    integer varid, ncerr
+
+!--------------------------------------------------------
+
+    IF (.not.ALLOCATED(tau_aer_strat)) ALLOCATE(tau_aer_strat(klon,klev,NSW))
+    IF (.not.ALLOCATED(piz_aer_strat)) ALLOCATE(piz_aer_strat(klon,klev,NSW))
+    IF (.not.ALLOCATED(cg_aer_strat))  ALLOCATE(cg_aer_strat(klon,klev,NSW))
+
+    IF (.not.ALLOCATED(taulw_aer_strat)) ALLOCATE(taulw_aer_strat(klon,klev,NLW))
+
+!--we only read monthly strat aerosol data
+    IF (debut.OR.mth_cur.NE.mth_pre) THEN
+
+!--only root reads the data
+    IF (is_mpi_root.AND.is_omp_root) THEN
+
+!--check mth_cur
+    IF (mth_cur.LT.1.OR.mth_cur.GT.12) THEN
+      print *,'probleme avec le mois dans readaerosolstrat =', mth_cur
+    ENDIF
+
+!--initialize n_lon as input data is 2D (lat-alt) only
+    n_lon = nbp_lon
+
+!--Starts with SW optical properties
+
+    CALL nf95_open("tauswstrat.2D.nc", nf90_nowrite, ncid_in)
+
+    CALL nf95_inq_varid(ncid_in, "LEV", varid)
+    CALL nf95_gw_var(ncid_in, varid, lev)
+    n_lev = size(lev)
+    IF (n_lev.NE.klev) THEN 
+       abort_message='Le nombre de niveaux n est pas egal a klev'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "LAT", varid)
+    CALL nf95_gw_var(ncid_in, varid, latitude)
+    n_lat = size(latitude)
+    IF (n_lat.NE.nbp_lat) THEN 
+       print *, 'latitude=', n_lat, nbp_lat
+       abort_message='Le nombre de lat n est pas egal a nbp_lat'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "TIME", varid)
+    CALL nf95_gw_var(ncid_in, varid, time)
+    n_month = size(time)
+    IF (n_month.NE.12) THEN 
+       abort_message='Le nombre de month n est pas egal a 12'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "WAV", varid)
+    CALL nf95_gw_var(ncid_in, varid, wav)
+    n_wav = size(wav)
+    print *, 'WAV aerosol strato=', n_wav, wav
+    IF (n_wav.NE.NSW) THEN 
+       abort_message='Le nombre de wav n est pas egal a NSW'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+
+    ALLOCATE(tauaerstrat(n_lat, n_lev, n_wav, n_month))
+    ALLOCATE(pizaerstrat(n_lat, n_lev, n_wav, n_month))
+    ALLOCATE(cgaerstrat(n_lat, n_lev, n_wav, n_month))
+
+    ALLOCATE(tauaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+    ALLOCATE(pizaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+    ALLOCATE(cgaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+
+    ALLOCATE(tauaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+    ALLOCATE(pizaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+    ALLOCATE(cgaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+
+!--reading stratospheric aerosol tau per layer
+    CALL nf95_inq_varid(ncid_in, "TAU_SUN", varid)
+    ncerr = nf90_get_var(ncid_in, varid, tauaerstrat)
+    print *,'code erreur readaerosolstrato=', ncerr, varid
+
+!--reading stratospheric aerosol omega per layer
+    CALL nf95_inq_varid(ncid_in, "OME_SUN", varid)
+    ncerr = nf90_get_var(ncid_in, varid, pizaerstrat)
+    print *,'code erreur readaerosolstrato=', ncerr, varid
+
+!--reading stratospheric aerosol g per layer
+    CALL nf95_inq_varid(ncid_in, "GGG_SUN", varid)
+    ncerr = nf90_get_var(ncid_in, varid, cgaerstrat)
+    print *,'code erreur readaerosolstrato sw=', ncerr, varid
+
+    CALL nf95_close(ncid_in)
+
+!--select the correct month
+!--and copy into 1st longitude
+    tauaerstrat_mois(1,:,:,:) = tauaerstrat(:,:,:,mth_cur)
+    pizaerstrat_mois(1,:,:,:) = pizaerstrat(:,:,:,mth_cur)
+    cgaerstrat_mois(1,:,:,:)  = cgaerstrat(:,:,:,mth_cur)
+
+!--copy longitudes
+    DO i=2, n_lon
+     tauaerstrat_mois(i,:,:,:) = tauaerstrat_mois(1,:,:,:)
+     pizaerstrat_mois(i,:,:,:) = pizaerstrat_mois(1,:,:,:)
+      cgaerstrat_mois(i,:,:,:)  = cgaerstrat_mois(1,:,:,:)
+    ENDDO
+
+!---reduce to a klon_glo grid 
+    DO band=1, NSW
+      CALL grid2dTo1d_glo(tauaerstrat_mois(:,:,:,band),tauaerstrat_mois_glo(:,:,band))
+      CALL grid2dTo1d_glo(pizaerstrat_mois(:,:,:,band),pizaerstrat_mois_glo(:,:,band))
+      CALL grid2dTo1d_glo(cgaerstrat_mois(:,:,:,band),cgaerstrat_mois_glo(:,:,band))
+    ENDDO
+
+!--Now LW optical properties
+!
+    CALL nf95_open("taulwstrat.2D.nc", nf90_nowrite, ncid_in)
+
+    CALL nf95_inq_varid(ncid_in, "LEV", varid)
+    CALL nf95_gw_var(ncid_in, varid, lev)
+    n_lev = size(lev)
+    IF (n_lev.NE.klev) THEN 
+       abort_message='Le nombre de niveaux n est pas egal a klev'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "LAT", varid)
+    CALL nf95_gw_var(ncid_in, varid, latitude)
+    n_lat = size(latitude)
+    IF (n_lat.NE.nbp_lat) THEN 
+       abort_message='Le nombre de lat n est pas egal a nbp_lat'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "TIME", varid)
+    CALL nf95_gw_var(ncid_in, varid, time)
+    n_month = size(time)
+    IF (n_month.NE.12) THEN 
+       abort_message='Le nombre de month n est pas egal a 12'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "WAV", varid)
+    CALL nf95_gw_var(ncid_in, varid, wav)
+    n_wav = size(wav)
+    print *, 'WAV aerosol strato=', n_wav, wav
+    IF (n_wav.NE.NLW) THEN 
+       abort_message='Le nombre de wav n est pas egal a NLW'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+
+    ALLOCATE(taulwaerstrat(n_lat, n_lev, n_wav, n_month))
+    ALLOCATE(taulwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+    ALLOCATE(taulwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+
+!--reading stratospheric aerosol lw tau per layer
+    CALL nf95_inq_varid(ncid_in, "TAU_EAR", varid)
+    ncerr = nf90_get_var(ncid_in, varid, taulwaerstrat)
+    print *,'code erreur readaerosolstrato lw=', ncerr, varid
+
+    CALL nf95_close(ncid_in)
+
+!--select the correct month
+!--and copy into 1st longitude
+    taulwaerstrat_mois(1,:,:,:) = taulwaerstrat(:,:,:,mth_cur)
+!--copy longitudes
+    DO i=2, n_lon
+      taulwaerstrat_mois(i,:,:,:) = taulwaerstrat_mois(1,:,:,:)
+    ENDDO
+
+!---reduce to a klon_glo grid 
+    DO band=1, NLW
+      CALL grid2dTo1d_glo(taulwaerstrat_mois(:,:,:,band),taulwaerstrat_mois_glo(:,:,band))
+    ENDDO
+
+    ENDIF !--is_mpi_root and is_omp_root
+
+!$OMP BARRIER
+
+!--keep memory of previous month
+    mth_pre=mth_cur
+
+!--scatter on all proc
+    CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
+    CALL scatter(pizaerstrat_mois_glo,piz_aer_strat)
+    CALL scatter(cgaerstrat_mois_glo,cg_aer_strat)
+    CALL scatter(taulwaerstrat_mois_glo,taulw_aer_strat)
+
+    IF (is_mpi_root.AND.is_omp_root) THEN
+!
+    DEALLOCATE(tauaerstrat, pizaerstrat, cgaerstrat)
+    DEALLOCATE(tauaerstrat_mois, pizaerstrat_mois, cgaerstrat_mois)
+    DEALLOCATE(tauaerstrat_mois_glo,pizaerstrat_mois_glo,cgaerstrat_mois_glo)
+
+    DEALLOCATE(taulwaerstrat,taulwaerstrat_mois,taulwaerstrat_mois_glo)
+!
+    ENDIF !--is_mpi_root and is_omp_root
+
+!$OMP BARRIER
+
+    ENDIF !--debut ou nouveau mois
+
+!--total vertical aod at the 5 SW wavelengths
+!--for now use band 3 AOD into all 5 wavelengths
+    band=3
+    DO i=1, klon
+    DO k=1, klev
+      IF (stratomask(i,k).GT.0.999999) THEN
+        DO wave=1, nwave
+          tausum_aero(:,wave,id_STRAT_phy)=tausum_aero(:,wave,id_STRAT_phy)+tau_aer_strat(:,k,band)
+        ENDDO
+      ENDIF
+    ENDDO
+    ENDDO
+
+!--weighted average for cg, piz and tau, adding strat aerosols on top of tropospheric ones
+    DO band=1, NSW
+    WHERE (stratomask.GT.0.999999)
+!--anthropogenic aerosols bands 1 to NSW 
+    cg_aero_sw_rrtm(:,:,2,band)  = ( cg_aero_sw_rrtm(:,:,2,band)*piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) + &
+                                     cg_aer_strat(:,:,band)*piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /              &
+                                MAX( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
+                                     piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band), 1.e-15 )
+    piz_aero_sw_rrtm(:,:,2,band) = ( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
+                                     piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /                                     &
+                                MAX( tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band), 1.e-15 )
+    tau_aero_sw_rrtm(:,:,2,band)  = tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band)
+!--natural aerosols bands 1 to NSW
+    cg_aero_sw_rrtm(:,:,1,band)  = ( cg_aero_sw_rrtm(:,:,1,band)*piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) + &
+                                     cg_aer_strat(:,:,band)*piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /              &
+                                MAX( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                             &
+                                     piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band), 1.e-15 )
+    piz_aero_sw_rrtm(:,:,1,band) = ( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                             &
+                                     piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /                                     &
+                                MAX( tau_aero_sw_rrtm(:,:,1,band) + tau_aer_strat(:,:,band), 1.e-15 )
+    tau_aero_sw_rrtm(:,:,1,band)  = tau_aero_sw_rrtm(:,:,1,band) + tau_aer_strat(:,:,band)
+!--no stratospheric aerosol in index 1 for these tests
+!    cg_aero_sw_rrtm(:,:,1,band)  =  cg_aero_sw_rrtm(:,:,1,band)
+!    piz_aero_sw_rrtm(:,:,1,band)  = piz_aero_sw_rrtm(:,:,1,band)
+!    tau_aero_sw_rrtm(:,:,1,band)  = tau_aero_sw_rrtm(:,:,1,band)
+    ENDWHERE
+    ENDDO
+
+    DO band=1, NLW
+    WHERE (stratomask.GT.0.999999)
+    tau_aero_lw_rrtm(:,:,2,band)  = tau_aero_lw_rrtm(:,:,2,band) + taulw_aer_strat(:,:,band)
+    tau_aero_lw_rrtm(:,:,1,band)  = tau_aero_lw_rrtm(:,:,1,band) + taulw_aer_strat(:,:,band)
+!--no stratospheric aerosols in index 1 for these tests
+!    tau_aero_lw_rrtm(:,:,1,band)  = tau_aero_lw_rrtm(:,:,1,band) 
+    ENDWHERE
+    ENDDO
+
+!--default SSA value if there is no aerosol
+!--to avoid 0 values that seems to cause some problem to RRTM
+    WHERE (tau_aero_sw_rrtm.LT.1.e-14)
+      piz_aero_sw_rrtm = 1.0
+    ENDWHERE
+
+!--in principle this should not be necessary 
+!--as these variables have min values already but just in case
+!--put 1e-15 min value to both SW and LW AOD
+    tau_aero_sw_rrtm = MAX(tau_aero_sw_rrtm,1.e-15)
+    tau_aero_lw_rrtm = MAX(tau_aero_lw_rrtm,1.e-15)
+
+end subroutine readaerosolstrato2_rrtm
Index: DZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato_rrtm.F90	(revision 2541)
+++ 	(revision )
@@ -1,224 +1,0 @@
-!
-! $Id$
-!
-subroutine readaerosolstrato_rrtm(debut)
-
-    use netcdf95, only: nf95_close, nf95_gw_var, nf95_inq_dimid, & 
-                        nf95_inq_varid, nf95_open
-    use netcdf, only: nf90_get_var, nf90_noerr, nf90_nowrite
-
-    USE phys_cal_mod, ONLY : mth_cur
-    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    USE mod_phys_lmdz_para 
-    USE phys_state_var_mod
-    USE phys_local_var_mod
-    USE aero_mod
-    USE dimphy
-    USE YOERAD   , ONLY : NLW
-
-    implicit none
-
-    include "YOMCST.h"
-
-! Variable input
-    logical debut
-
-! Variables locales
-    integer n_lat   ! number of latitudes in the input data
-    integer n_lon   ! number of longitudes in the input data
-    integer n_lev   ! number of levels in the input data
-    integer n_month ! number of months in the input data
-    real, pointer:: latitude(:)
-    real, pointer:: longitude(:)
-    real, pointer:: time(:)
-    real, pointer:: lev(:)
-    integer k, band, wave, i
-    integer, save :: mth_pre
-
-    real, allocatable, dimension(:,:), save :: tau_aer_strat
-!$OMP THREADPRIVATE(tau_aer_strat)
-
-! Champs reconstitues
-    real, allocatable:: tauaerstrat(:, :, :, :)
-    real, allocatable:: tauaerstrat_mois(:, :, :)
-    real, allocatable:: tauaerstrat_mois_glo(:, :)
-
-    real, allocatable:: sum_tau_aer_strat(:)
-
-! For NetCDF:
-    integer ncid_in  ! IDs for input files
-    integer varid, ncerr
-
-! Stratospheric aerosols optical properties
-! alpha_sw_strat over the 6 bands is normalised by the 550 nm extinction coefficient
-    real, dimension(nbands_sw_rrtm) :: alpha_sw_strat, piz_sw_strat, cg_sw_strat
-    data alpha_sw_strat/0.8545564, 0.8451642, 0.9821724, 0.8145110, 0.3073565, 7.7966176E-02/
-    data cg_sw_strat   /0.6997170, 0.6810035, 0.7403592, 0.7562674, 0.6676504, 0.3478689/
-    data piz_sw_strat  /0.9999998, 0.9999998, 1.000000000, 0.9999958, 0.9977155, 0.4510679/
-!
-!--diagnostics AOD in the SW
-! alpha_sw_strat_wave is *not* normalised by the 550 nm extinction coefficient
-    real, dimension(nwave) :: alpha_sw_strat_wave
-    data alpha_sw_strat_wave/3.708007,4.125824,4.136584,3.887478,3.507738/
-!
-!--diagnostics AOD in the LW at 10 um 
-    real :: alpha_lw_strat_wave
-    data alpha_lw_strat_wave/0.2746812/
-!
-    real, dimension(nbands_lw_rrtm) :: alpha_lw_abs_rrtm
-    data alpha_lw_abs_rrtm/   8.8340312E-02, 6.9856711E-02, 6.2652975E-02, 5.7188231E-02, &
-                              6.3157059E-02, 5.5072524E-02, 5.0571125E-02, 0.1349073, &    
-                              0.1381676, 9.6506312E-02, 5.1312990E-02, 2.4256418E-02, &
-                              2.7191756E-02, 3.3862915E-02, 1.6132960E-02, 1.4275438E-02/ ! calculated with Mie_SW_LW_RRTM_V2.4 (bimodal, corrected)
-                                                                                          ! for r_0=/0.13E-6, 0.41E-6/ m, sigma_g=/1.26, 1.30/
-                                                                                          ! order: increasing wavelength!
-!--------------------------------------------------------
-
-    IF (.not.ALLOCATED(tau_aer_strat)) ALLOCATE(tau_aer_strat(klon,klev))
-    IF (.not.ALLOCATED(sum_tau_aer_strat)) ALLOCATE(sum_tau_aer_strat(klon))
-
-    IF (debut.OR.mth_cur.NE.mth_pre) THEN
-
-    IF (is_mpi_root) THEN
-
-    IF (nbands_sw_rrtm.NE.6) THEN 
-        print *,'nbands_sw_rrtm doit etre egal a 6 dans readaerosolstrat_rrtm'
-        STOP
-    ENDIF
-
-    CALL nf95_open("taustrat.nc", nf90_nowrite, ncid_in)
-
-    CALL nf95_inq_varid(ncid_in, "LEV", varid)
-    CALL nf95_gw_var(ncid_in, varid, lev)
-    n_lev = size(lev)
-    IF (n_lev.NE.klev) THEN 
-       print *,'Le nombre de niveaux n est pas egal a klev'
-       STOP
-    ENDIF
-
-    CALL nf95_inq_varid(ncid_in, "LAT", varid)
-    CALL nf95_gw_var(ncid_in, varid, latitude)
-    n_lat = size(latitude)
-    print *, 'LAT aerosol strato=', n_lat, latitude
-    IF (n_lat.NE.nbp_lat) THEN 
-       print *,'Le nombre de lat n est pas egal a nbp_lat'
-       STOP
-    ENDIF
-
-    CALL nf95_inq_varid(ncid_in, "LON", varid)
-    CALL nf95_gw_var(ncid_in, varid, longitude)
-    n_lon = size(longitude)
-    print *, 'LON aerosol strato=', n_lon, longitude
-    IF (n_lon.NE.nbp_lon) THEN 
-       print *,'Le nombre de lon n est pas egal a nbp_lon'
-       STOP
-    ENDIF
-
-    CALL nf95_inq_varid(ncid_in, "TIME", varid)
-    CALL nf95_gw_var(ncid_in, varid, time)
-    n_month = size(time)
-    print *, 'TIME aerosol strato=', n_month, time
-    IF (n_month.NE.12) THEN 
-       print *,'Le nombre de month n est pas egal a 12'
-       STOP
-    ENDIF
-
-    ALLOCATE(tauaerstrat(n_lon, n_lat, n_lev, n_month))
-    ALLOCATE(tauaerstrat_mois(n_lon, n_lat, n_lev))
-    ALLOCATE(tauaerstrat_mois_glo(klon_glo, n_lev))
-
-!--reading stratospheric AOD at 550 nm
-    CALL nf95_inq_varid(ncid_in, "TAUSTRAT", varid)
-    ncerr = nf90_get_var(ncid_in, varid, tauaerstrat)
-    print *,'code erreur readaerosolstrato=', ncerr, varid
-
-    CALL nf95_close(ncid_in)
-
-!---select the correct month
-    IF (mth_cur.LT.1.OR.mth_cur.GT.12) THEN
-      print *,'probleme avec le mois dans readaerosolstrat =', mth_cur
-    ENDIF
-    tauaerstrat_mois(:,:,:) = tauaerstrat(:,:,:,mth_cur)
-
-!---reduce to a klon_glo grid 
-    CALL grid2dTo1d_glo(tauaerstrat_mois,tauaerstrat_mois_glo)
-
-    ENDIF !--is_mpi_root
-
-!--keep memory of previous month
-    mth_pre=mth_cur
-
-!--scatter on all proc
-    CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
-
-    IF (is_mpi_root) THEN
-!
-    DEALLOCATE(tauaerstrat)
-    DEALLOCATE(tauaerstrat_mois)
-    DEALLOCATE(tauaerstrat_mois_glo)
-!
-    ENDIF !--is_mpi_root
-
-    ENDIF !--debut ou nouveau mois
-
-!--total vertical aod at the 5 SW wavelengths
-    DO wave=1, nwave
-    DO k=1, klev
-    tausum_aero(:,wave,id_STRAT_phy)=tausum_aero(:,wave,id_STRAT_phy)+ &
-       tau_aer_strat(:,k)*alpha_sw_strat_wave(wave)/alpha_sw_strat_wave(2)
-    ENDDO
-    ENDDO
-
-!--weighted average for cg, piz and tau, adding strat aerosols on top of tropospheric ones
-    DO band=1, nbands_sw_rrtm
-!--anthropogenic aerosols bands 1 to nbands_sw_rrtm 
-    cg_aero_sw_rrtm(:,:,2,band)  = ( cg_aero_sw_rrtm(:,:,2,band)*piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) + &
-                                  cg_sw_strat(band)*piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:) ) /           &
-                             MAX( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                                &
-                                  piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:), 1.e-15 )
-    piz_aero_sw_rrtm(:,:,2,band)  = ( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                            &
-                              piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:) ) /                                 &
-                              MAX( tau_aero_sw_rrtm(:,:,2,band) + alpha_sw_strat(band)*tau_aer_strat(:,:), 1.e-15 )
-    tau_aero_sw_rrtm(:,:,2,band)  = tau_aero_sw_rrtm(:,:,2,band) + alpha_sw_strat(band)*tau_aer_strat(:,:)
-!--natural aerosols bands 1 to nbands_sw_rrtm
-    cg_aero_sw_rrtm(:,:,1,band)  = ( cg_aero_sw_rrtm(:,:,1,band)*piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) + &
-                             cg_sw_strat(band)*piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:) ) /                &
-                             MAX( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                                &
-                                  piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:), 1.e-15 )
-    piz_aero_sw_rrtm(:,:,1,band)  = ( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                            &
-                              piz_sw_strat(band)*alpha_sw_strat(band)*tau_aer_strat(:,:) ) /                                 &
-                              MAX( tau_aero_sw_rrtm(:,:,1,band) + alpha_sw_strat(band)*tau_aer_strat(:,:),1.e-15 )
-    tau_aero_sw_rrtm(:,:,1,band)  = tau_aero_sw_rrtm(:,:,1,band) + alpha_sw_strat(band)*tau_aer_strat(:,:)
-!--no stratospheric aerosol in index 1 for these tests
-!    cg_aero_sw_rrtm(:,:,1,band)  =  cg_aero_sw_rrtm(:,:,1,band)
-!    piz_aero_sw_rrtm(:,:,1,band)  = piz_aero_sw_rrtm(:,:,1,band)
-!    tau_aero_sw_rrtm(:,:,1,band)  = tau_aero_sw_rrtm(:,:,1,band)
-    ENDDO
-
-!--stratospheric AOD in LW
-    IF (nbands_lw_rrtm .NE. NLW) then
-      print*, 'different values for NLW (=',NLW,') and nbands_lw_rrtm (=', nbands_lw_rrtm, ')'
-      STOP
-    ENDIF 
-
-    DO band=1, nbands_lw_rrtm
-    tau_aero_lw_rrtm(:,:,2,band)  = tau_aero_lw_rrtm(:,:,2,band) + alpha_lw_abs_rrtm(band)*tau_aer_strat(:,:)
-    tau_aero_lw_rrtm(:,:,1,band)  = tau_aero_lw_rrtm(:,:,1,band) + alpha_lw_abs_rrtm(band)*tau_aer_strat(:,:) 
-!--no stratospheric aerosols in index 1 for these tests
-!    tau_aero_lw_rrtm(:,:,1,band)  = tau_aero_lw_rrtm(:,:,1,band) 
-    ENDDO
-
-!--default SSA value if there is no aerosol
-!--to avoid 0 values that seems to cause some problem to RRTM
-    WHERE (tau_aero_sw_rrtm.LT.1.e-14)
-      piz_aero_sw_rrtm = 1.0
-    ENDWHERE
-
-!--in principle this should not be necessary 
-!--as these variables have min values already but just in case
-!--put 1e-15 min value to both SW and LW AOD
-    tau_aero_sw_rrtm = MAX(tau_aero_sw_rrtm,1.e-15)
-    tau_aero_lw_rrtm = MAX(tau_aero_lw_rrtm,1.e-15)
-
-end subroutine readaerosolstrato_rrtm
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/recmwf_aero.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/recmwf_aero.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/recmwf_aero.F90	(revision 2542)
@@ -161,5 +161,4 @@
 IMPLICIT NONE
 INCLUDE "clesphys.h"
-
 
 INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
@@ -306,7 +305,7 @@
 ! not ok_ade and not ok_aie = 1 to proceed
 ! therefore the cases have the following corresponding switches
-! 1 = not ok_ade or not ok_aie
-! 2 = ok_aie
-! 3 = ok_ade
+! 1 = not ok_ade and not ok_aie OR not ok_ade and ok_aie and swaero_diag OR ok_ade and not ok_aie and swaero_diag
+! 2 = not ok_ade and ok_aie OR ok_aie and ok_ade and swaero_diag
+! 3 = ok_ade and not ok_aie OR ok_aie and ok_ade and swaero_diag
 ! 4 = ok_ade and ok_aie
 ! 5 = no aerosol feedback wanted or no aerosol at all 
@@ -445,5 +444,8 @@
 IF (flag_aerosol .GT. 0 .OR. flag_aerosol_strat) THEN
 
-IF ( .not. ok_ade .or. .not. ok_aie ) THEN
+!--Case 1
+IF ( ( .not. ok_ade .AND. .not. ok_aie ) .OR.             & 
+   & ( .not. ok_ade .AND. ok_aie .AND. swaero_diag ) .OR. & 
+   & ( ok_ade .AND. .not. ok_aie .AND. swaero_diag ) ) THEN
 
 ! natural aerosols for direct and indirect effect 
@@ -483,5 +485,7 @@
 ENDIF 
 
-IF (ok_aie) THEN
+!--Case 2
+IF ( ( .not. ok_ade .AND. ok_aie ) .OR. & 
+   & ( ok_ade .AND. ok_aie .AND. swaero_diag ) ) THEN
 
 ! natural aerosols for direct indirect effect 
@@ -521,5 +525,7 @@
 ENDIF ! ok_aie      
 
-IF (ok_ade) THEN
+!--Case 3
+IF ( ( ok_ade .AND. .not. ok_aie ) .OR. &
+   & ( ok_ade .AND. ok_aie .AND. swaero_diag ) ) THEN
 
 ! direct effect of total aerosol activated
@@ -559,4 +565,5 @@
 ENDIF !-end ok_ade
 
+!--Case 4
 IF (ok_ade .and. ok_aie) THEN
 
Index: /LMDZ5/branches/testing/libf/phylmd/stratosphere_mask.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/stratosphere_mask.F90	(revision 2542)
+++ /LMDZ5/branches/testing/libf/phylmd/stratosphere_mask.F90	(revision 2542)
@@ -0,0 +1,245 @@
+SUBROUTINE stratosphere_mask(t_seri, pplay, xlat)
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! determination of tropopause height and temperature from gridded temperature data
+!
+! reference: Reichler, T., M. Dameris, and R. Sausen (2003):
+! modified: 6/28/06 tjr
+! adapted to LMDZ by C. Kleinschmitt (2016-02-15)
+!
+! input:    temp(nlon,nlat,nlev)    3D-temperature field 
+!       ps(nlon,nlat)       2D-surface pressure field
+!       zs(nlon,nlat)       2D-surface height
+!       nlon            grid points in x
+!       nlat            grid points in y
+!       pfull(nlon,nlat,nlev)   full pressure levels in Pa
+!       plimu           upper limit for tropopause pressure
+!       pliml           lower limit for tropopause pressure 
+!       gamma           tropopause criterion, e.g. -0.002 K/m
+!
+! output:   tp(nlon, nlat)      tropopause pressure in Pa, -999. if undefined
+!           ttp(nlon, nlat)     tropopause temperature in K, -999. if undefined
+!           ztp(nlon, nlat)     tropopause height in m, -999. if undefined
+!       tperr           # of undetermined values
+!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+USE dimphy
+USE phys_local_var_mod, ONLY: stratomask
+
+IMPLICIT NONE
+
+REAL,DIMENSION(klon,klev),INTENT(IN)   :: t_seri  ! Temperature
+REAL,DIMENSION(klon,klev),INTENT(IN)   :: pplay   ! pression pour le mileu de chaque couche (en Pa)
+REAL,DIMENSION(klon),INTENT(IN)        :: xlat    ! latitudes pour chaque point 
+
+REAL, PARAMETER                        :: plimu=45000.
+REAL, PARAMETER                        :: pliml=7500.
+REAL, PARAMETER                        :: gamma=-0.002
+LOGICAL, PARAMETER                     :: dofill=.true.
+REAL,DIMENSION(klon)                   :: tp, ttp, ztp
+REAL,DIMENSION(klev)                   :: t, p
+INTEGER                                :: tperr, i, k, invert, ifil
+REAL                                   :: ptrp, ttrp, ztrp, psrf, zsrf, pi
+
+pi     = 4.*ATAN(1.)
+
+tperr = 0
+DO i=1,klon
+  DO k=1,klev 
+    t(k)=t_seri(i,klev+1-k) 
+    p(k)=pplay(i,klev+1-k)
+  ENDDO
+  psrf=pplay(i,1)
+  zsrf=0.0
+  call twmo(klev, t, p, psrf, zsrf, plimu, pliml, gamma, ptrp, ttrp, ztrp)
+  tp(i)=ptrp
+  ttp(i)=ttrp
+  ztp(i)=ztrp
+  IF (ptrp.lt.0.0) THEN 
+    tperr = tperr+1 
+  ENDIF
+ENDDO
+
+! fill holes
+IF (dofill) THEN
+  ifil=0
+  DO i=1,klon
+  IF (tp(i).lt.-990.) THEN
+    !set missing values to very simple profile (neighbour averaging too expensive in LMDZ)
+    tp(i)=50000.-20000.*cos(xlat(i)/360.*2.*pi)
+    ifil=ifil+1
+  ENDIF
+  ENDDO
+!
+  IF (ifil.ne.tperr) THEN
+    CALL abort_physic('stratosphere_mask', 'inconsistency',1)
+  ENDIF
+ENDIF
+!
+DO i=1, klon
+DO k=1, klev
+  IF (pplay(i,k).LT.tp(i)) THEN
+    stratomask(i,k)=1.0
+  ELSE
+    stratomask(i,k)=0.0
+  ENDIF
+ENDDO
+ENDDO
+
+!!--diagnostic not used for now
+!!p_tropopause(:)=tp(:)
+
+IF (ifil.gt.0) THEN
+  print *,'Tropopause: number of undetermined values =', ifil
+ENDIF
+
+RETURN
+END SUBROUTINE stratosphere_mask
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! twmo
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+subroutine twmo(level, t, p, ps, zs, plimu, pliml, gamma, ptrp, ttrp, ztrp)
+
+implicit none
+
+include "YOMCST.h"
+
+integer,intent(in)              :: level
+real,intent(in),dimension(level):: t, p
+real,intent(in)                 :: plimu, pliml, gamma, ps, zs
+real,intent(out)                :: ptrp, ttrp, ztrp
+
+real,parameter                  :: deltaz = 2000.0
+
+real     :: faktor
+real     :: pmk, pm, a, b, tm, dtdp, dtdz, dlnp, tdlnp
+real     :: ag, bg, ptph, ttph, a0, b0
+real     :: pm0, tm0, pmk0, dtdz0
+real     :: p2km, asum, aquer
+real     :: pmk2, pm2, a2, b2, tm2, dtdp2, dtdz2
+integer  :: icount, jj, j
+
+ptrp=-999.0             
+ttrp=-999.0                 
+ztrp=-999.0                 
+
+faktor = -RG/R
+
+do j=level,2,-1
+
+   ! dt/dz
+   pmk= 0.5 * (p(j-1)**rkappa+p(j)**rkappa)        ! p**k at half level
+   pm = pmk**(1./rkappa)                    ! p at half level
+   a = (t(j-1)-t(j))/(p(j-1)**rkappa-p(j)**rkappa)    ! dT/dp^k
+   b = t(j)-(a*p(j)**rkappa)
+   tm = a * pmk + b                    ! T at half level         
+   dtdp = a * rkappa * pm**(rkappa-1.) ! dT/dp at half level
+   dtdz = faktor*dtdp*pm/tm            ! dT/dz at half level
+
+   ! dt/dz valid?
+   if (j.eq.level)     go to 999                 ! no, start level, initialize first
+   if (dtdz.le.gamma)  go to 999                 ! no, dt/dz < -2 K/km
+   if (dtdz0.gt.gamma) go to 999                 ! no, dt/dz below > -2 K/km
+   if (pm.gt.plimu)    go to 999                 ! no, pm too low
+
+   ! dtdz is valid, calculate tropopause pressure ptph
+   ag = (dtdz-dtdz0) / (pmk-pmk0)     
+   bg = dtdz0 - (ag * pmk0)          
+   ptph = exp(log((gamma-bg)/ag)/rkappa)
+
+   ! calculate temperature at this ptph assuming linear gamma
+   ! interpolation
+   ttph = tm0
+   ttph = ttph - (bg * log(pm0)  + ag * (pm0**rkappa) /rkappa) / faktor*t(j)
+   ttph = ttph + (bg * log(ptph) + ag * (ptph**rkappa)/rkappa) / faktor*t(j)
+
+   if (ptph.lt.pliml) go to 999 
+   if (ptph.gt.plimu) go to 999     
+
+   ! 2nd test: dtdz above 2 km must not exceed gamma
+   p2km = ptph + deltaz*(pm/tm)*faktor      ! p at ptph + 2km
+   asum = 0.0                               ! dtdz above
+   icount = 0                               ! number of levels above
+
+   ! test until apm < p2km
+   do jj=j,2,-1
+
+       pmk2 = .5 * (p(jj-1)**rkappa+p(jj)**rkappa)    ! p mean ^kappa
+       pm2 = pmk2**(1/rkappa)                      ! p mean
+       if(pm2.gt.ptph) go to 110                ! doesn't happen
+       if(pm2.lt.p2km) go to 888                ! ptropo is valid
+
+       a2 = (t(jj-1)-t(jj))                     ! a
+       a2 = a2/(p(jj-1)**rkappa-p(jj)**rkappa)
+       b2 = t(jj)-(a2*p(jj)**rkappa)               ! b
+       tm2 = a2 * pmk2 + b2                     ! T mean
+       dtdp2 = a2 * rkappa * (pm2**(rkappa-1))        ! dt/dp
+       dtdz2 = faktor*dtdp2*pm2/tm2
+       asum = asum+dtdz2
+       icount = icount+1
+       aquer = asum/float(icount)               ! dt/dz mean
+   
+       ! discard ptropo ?
+        if (aquer.le.gamma) go to 999           ! dt/dz above < gamma
+
+110 continue 
+    enddo                   ! test next level
+
+888 continue                    ! ptph is valid
+    ptrp = ptph
+    ttrp = ttph
+
+! now calculate height of tropopause by integrating hypsometric equation
+! from ps to ptrp
+! linearly interpolate in p (results are identical to p^kappa)
+
+jj = LEVEL                                       ! bottom
+do while ((P(jj).gt.PS) .or. (T(jj).lt.100))     ! T must be valid too
+  jj=jj-1
+enddo
+
+DLNP = log(PS/P(jj))                             ! from surface pressure
+TM = T(jj)                                       ! take TM of lowest level (better: extrapolate)
+TDLNP = TM*DLNP
+
+do while ( (JJ.ge.2) .and. (PTRP.lt.P(jj-1)) ) 
+  DLNP = log(P(jj)/P(jj-1))
+  TM = 0.5 * (T(jj) + T(jj-1))
+  TDLNP = TDLNP + TM*DLNP
+  JJ=JJ-1
+enddo
+
+DLNP = log(P(jj)/PTRP)                           ! up to tropopause pressure
+TM = 0.5 * (T(jj) + TTRP)                        ! use TTRP to get TM of this level
+TDLNP = TDLNP + TM*DLNP
+
+ZTRP = ZS + TDLNP*R/RG
+
+if (ZTRP .lt. 0) then
+  print*,ZTRP
+  print*,PS
+  print*,P
+  print*,T
+  print*,ZS
+  stop
+endif
+
+return
+
+999 continue                    ! continue search at next higher level 
+    tm0 = tm
+    pm0 = pm
+    pmk0 = pmk
+    dtdz0  = dtdz
+    a0 = a
+    b0 = b
+
+enddo 
+
+! no tropopouse found
+return
+end subroutine twmo
Index: /LMDZ5/branches/testing/libf/phylmd/surf_ocean_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/surf_ocean_mod.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/surf_ocean_mod.F90	(revision 2542)
@@ -1,2 +1,4 @@
+!
+! $Id$
 !
 MODULE surf_ocean_mod
Index: /LMDZ5/branches/testing/libf/phylmd/surface_data.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/surface_data.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/surface_data.F90	(revision 2542)
@@ -1,4 +1,4 @@
 !
-! $Header$
+! $Id$
 !
 MODULE surface_data
Index: /LMDZ5/branches/testing/libf/phylmd/sw_aeroAR4.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/sw_aeroAR4.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/sw_aeroAR4.F90	(revision 2542)
@@ -139,5 +139,5 @@
 
   LOGICAL ok_ade, ok_aie    ! use aerosol forcings or not?
-  LOGICAL flag_aerosol_strat ! use stratospehric aerosols
+  INTEGER flag_aerosol_strat ! use stratospehric aerosols
   INTEGER flag_aerosol      ! global flag for aerosol 0 (no aerosol) or 1-5 (aerosols)
   REAL(KIND=8) tauaero(kdlon,kflev,naero_grp,2)  ! aerosol optical properties
@@ -309,5 +309,5 @@
      ENDIF ! swaero_diag .or. .not. AEROSOLFEEDBACK_ACTIVE
 
-     IF (flag_aerosol .GT. 0 .OR. flag_aerosol_strat) THEN
+     IF (flag_aerosol.GT.0 .OR. flag_aerosol_strat.GT.0) THEN
 
      IF (ok_ade.and.swaero_diag .or. .not. ok_ade) THEN
@@ -500,5 +500,5 @@
      ENDIF ! ok_aie      
 
-     ENDIF !--if flag_aerosol GT 0 OR flag_aerosol_strat
+     ENDIF !--if flag_aerosol GT 0 OR flag_aerosol_strat GT 0
 
      itapsw = 0
@@ -506,5 +506,5 @@
   itapsw = itapsw + 1
 
-  IF  ( AEROSOLFEEDBACK_ACTIVE .AND. (flag_aerosol .GT. 0 .OR. flag_aerosol_strat) ) THEN
+  IF  ( AEROSOLFEEDBACK_ACTIVE .AND. (flag_aerosol.GT.0 .OR. flag_aerosol_strat.GT.0) ) THEN
   IF ( ok_ade .and. ok_aie  ) THEN
     ZFSUP(:,:) =    ZFSUP_AERO(:,:,4)
Index: /LMDZ5/branches/testing/libf/phylmd/wake.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/wake.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/wake.F90	(revision 2542)
@@ -625,5 +625,5 @@
     z(i) = 1.
     dz(i) = 1.
-    sum_thvu(i) = thu(i, 1)*(1.+eps*qu(i,1))*dz(i)
+    sum_thvu(i) = thu(i, 1)*(1.+epsim1*qu(i,1))*dz(i)
     sum_dth(i) = 0.
   END DO
@@ -637,5 +637,5 @@
         sum_tu(i) = sum_tu(i) + tu(i, k)*dz(i)
         sum_qu(i) = sum_qu(i) + qu(i, k)*dz(i)
-        sum_thvu(i) = sum_thvu(i) + thu(i, k)*(1.+eps*qu(i,k))*dz(i)
+        sum_thvu(i) = sum_thvu(i) + thu(i, k)*(1.+epsim1*qu(i,k))*dz(i)
         sum_dth(i) = sum_dth(i) + dth(i, k)*dz(i)
         sum_dq(i) = sum_dq(i) + deltaqw(i, k)*dz(i)
@@ -671,5 +671,5 @@
     av_dqdwn(i) = sum_dqdwn(i)/hw0(i)
 
-    wape(i) = -rg*hw0(i)*(av_dth(i)+eps*(av_thu(i)*av_dq(i)+av_dth(i)*av_qu(i &
+    wape(i) = -rg*hw0(i)*(av_dth(i)+epsim1*(av_thu(i)*av_dq(i)+av_dth(i)*av_qu(i &
       )+av_dth(i)*av_dq(i)))/av_thvu(i)
   END DO
@@ -1398,5 +1398,5 @@
         z(i) = 1.
         dz(i) = 1.
-        sum_thvu(i) = thu(i, 1)*(1.+eps*qu(i,1))*dz(i)
+        sum_thvu(i) = thu(i, 1)*(1.+epsim1*qu(i,1))*dz(i)
         sum_dth(i) = 0.
       END IF
@@ -1412,5 +1412,5 @@
             sum_tu(i) = sum_tu(i) + tu(i, k)*dz(i)
             sum_qu(i) = sum_qu(i) + qu(i, k)*dz(i)
-            sum_thvu(i) = sum_thvu(i) + thu(i, k)*(1.+eps*qu(i,k))*dz(i)
+            sum_thvu(i) = sum_thvu(i) + thu(i, k)*(1.+epsim1*qu(i,k))*dz(i)
             sum_dth(i) = sum_dth(i) + dth(i, k)*dz(i)
             sum_dq(i) = sum_dq(i) + deltaqw(i, k)*dz(i)
@@ -1449,5 +1449,5 @@
         av_dqdwn(i) = sum_dqdwn(i)/hw0(i)
 
-        wape(i) = -rg*hw0(i)*(av_dth(i)+eps*(av_thu(i)*av_dq(i)+av_dth(i)* &
+        wape(i) = -rg*hw0(i)*(av_dth(i)+epsim1*(av_thu(i)*av_dq(i)+av_dth(i)* &
           av_qu(i)+av_dth(i)*av_dq(i)))/av_thvu(i)
       END IF
@@ -1578,5 +1578,5 @@
       z(i) = 1.
       dz(i) = 1.
-      sum_thvu(i) = thu(i, 1)*(1.+eps*qu(i,1))*dz(i)
+      sum_thvu(i) = thu(i, 1)*(1.+epsim1*qu(i,1))*dz(i)
       sum_dth(i) = 0.
     END IF
@@ -1594,5 +1594,5 @@
           sum_tu(i) = sum_tu(i) + tu(i, k)*dz(i)
           sum_qu(i) = sum_qu(i) + qu(i, k)*dz(i)
-          sum_thvu(i) = sum_thvu(i) + thu(i, k)*(1.+eps*qu(i,k))*dz(i)
+          sum_thvu(i) = sum_thvu(i) + thu(i, k)*(1.+epsim1*qu(i,k))*dz(i)
           sum_dth(i) = sum_dth(i) + dth(i, k)*dz(i)
           sum_dq(i) = sum_dq(i) + deltaqw(i, k)*dz(i)
@@ -1632,5 +1632,5 @@
       av_dqdwn(i) = sum_dqdwn(i)/hw0(i)
 
-      wape2(i) = -rg*hw0(i)*(av_dth(i)+eps*(av_thu(i)*av_dq(i)+av_dth(i)* &
+      wape2(i) = -rg*hw0(i)*(av_dth(i)+epsim1*(av_thu(i)*av_dq(i)+av_dth(i)* &
         av_qu(i)+av_dth(i)*av_dq(i)))/av_thvu(i)
     END IF
Index: /LMDZ5/branches/testing/libf/phylmd/water_int.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/water_int.F90	(revision 2541)
+++ /LMDZ5/branches/testing/libf/phylmd/water_int.F90	(revision 2542)
@@ -5,8 +5,4 @@
 !  OB (obolmd@lmd.jussieu.fr)
 !=============================================================
-
-USE phys_local_var_mod, ONLY : d_u_vdf,d_v_vdf,d_t_vdf,d_u_ajs,d_v_ajs,d_t_ajs,d_u_con,d_v_con,d_t_con,d_t_diss
-USE phys_local_var_mod, ONLY : d_t_eva,d_t_lsc,d_q_eva,d_q_lsc
-USE phys_output_var_mod, ONLY : bils_ec,bils_ech,bils_tke,bils_kinetic,bils_enthalp,bils_latent,bils_diss
 
 IMPLICIT none
