Index: /LMDZ5/branches/testing/DefLists/context_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/context_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/context_lmdz.xml	(revision 2594)
@@ -44,14 +44,21 @@
     <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> -->
+
+<!-- Cosp axis definitions-->
+    <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 id="temp" standard_name="temperature" unit="K"> 
+    </axis> 
+    <axis id="cth16" name="cth" standard_name="altitude" unit="m"> 
+    </axis> 
+
   </axis_definition>
 </context>
Index: /LMDZ5/branches/testing/DefLists/context_lmdz_XIOS1.0.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/context_lmdz_XIOS1.0.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/context_lmdz_XIOS1.0.xml	(revision 2594)
@@ -43,4 +43,6 @@
     <axis id="plev" standard_name="model_level_number" unit="Pa">
     </axis>
+
+<!-- Cosp axis definitions--> 
 <!--    <axis id="height" standard_name="Cosp levels" unit="m"> -->
 <!--    </axis> -->
@@ -53,4 +55,9 @@
 <!--    <axis id="column" standard_name="column" unit="count"> -->
 <!--    </axis> -->
+<!--    <axis id="temp" standard_name="temperature" unit="K"> -->
+<!--    </axis> -->
+<!--    <axis id="cth16" name="cth" standard_name="altitude" unit="m"> -->
+<!--    </axis> -->
+
   </axis_definition>
 </context>
Index: /LMDZ5/branches/testing/DefLists/field_def_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/field_def_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/field_def_lmdz.xml	(revision 2594)
@@ -422,16 +422,24 @@
     <field_group id="fields_3D" domain_ref="dom_glo" axis_ref="presnivs">
         <field id="tke"    long_name="TKE"    unit="m2/s2" />
-        <field id="tke_ter"    long_name="Max Turb. Kinetic Energy ter"    unit="-" />
-        <field id="tke_lic"    long_name="Max Turb. Kinetic Energy lic"    unit="-" />
-        <field id="tke_oce"    long_name="Max Turb. Kinetic Energy oce"    unit="-" />
-        <field id="tke_sic"    long_name="Max Turb. Kinetic Energy sic"    unit="-" />
-        <field id="tke_max_ter"    long_name="Max Turb. Kinetic Energy ter"    unit="-" />
-        <field id="tke_max_lic"    long_name="Max Turb. Kinetic Energy lic"    unit="-" />
-        <field id="tke_max_oce"    long_name="Max Turb. Kinetic Energy oce"    unit="-" />
-        <field id="tke_max_sic"    long_name="Max Turb. Kinetic Energy sic"    unit="-" />
-        <field id="dltpbltke_ter"    long_name="TKE difference (w - x)"    unit="-" />
-        <field id="dltpbltke_lic"    long_name="TKE difference (w - x)"    unit="-" />
-        <field id="dltpbltke_oce"    long_name="TKE difference (w - x)"    unit="-" />
-        <field id="dltpbltke_sic"    long_name="TKE difference (w - x)"    unit="-" />
+        <field id="tke_ter"    long_name="Max Turb. Kinetic Energy ter"    unit="m2/s2" />
+        <field id="tke_lic"    long_name="Max Turb. Kinetic Energy lic"    unit="m2/s2" />
+        <field id="tke_oce"    long_name="Max Turb. Kinetic Energy oce"    unit="m2/s2" />
+        <field id="tke_sic"    long_name="Max Turb. Kinetic Energy sic"    unit="m2/s2" />
+        <field id="tke_max_ter"    long_name="Max Turb. Kinetic Energy ter"    unit="m2/s2" />
+        <field id="tke_max_lic"    long_name="Max Turb. Kinetic Energy lic"    unit="m2/s2" />
+        <field id="tke_max_oce"    long_name="Max Turb. Kinetic Energy oce"    unit="m2/s2" />
+        <field id="tke_max_sic"    long_name="Max Turb. Kinetic Energy sic"    unit="m2/s2" />
+        <field id="l_mix_ter"    long_name="PBL mixing length ter"    unit="m" />
+        <field id="l_mix_lic"    long_name="PBL mixing length lic"    unit="m" />
+        <field id="l_mix_oce"    long_name="PBL mixing length oce"    unit="m" />
+        <field id="l_mix_sic"    long_name="PBL mixing length sic"    unit="m" />
+        <field id="l_mixmin_ter"    long_name="min PBL mixing length ter"    unit="m" />
+        <field id="l_mixmin_lic"    long_name="min PBL mixing length lic"    unit="m" />
+        <field id="l_mixmin_oce"    long_name="min PBL mixing length oce"    unit="m" />
+        <field id="l_mixmin_sic"    long_name="min PBL mixing length sic"    unit="m" />
+        <field id="dltpbltke_ter"    long_name="TKE difference (w - x)"    unit="m2/s2" />
+        <field id="dltpbltke_lic"    long_name="TKE difference (w - x)"    unit="m2/s2" />
+        <field id="dltpbltke_oce"    long_name="TKE difference (w - x)"    unit="m2/s2" />
+        <field id="dltpbltke_sic"    long_name="TKE difference (w - x)"    unit="m2/s2" />
         <field id="cldtau"    long_name="Cloud optical thickness"    unit="1" />
         <field id="cldemi"    long_name="Cloud optical emissivity"    unit="1" />
@@ -452,5 +460,6 @@
         <field id="ovap"    long_name="Specific humidity"    unit="kg/kg" />
         <field id="ovapinit"    long_name="Specific humidity (begin of timestep)"    unit="kg/kg" />
-        <field id="oliq"    long_name="Condensed water"    unit="kg/kg" />
+        <field id="oliq"    long_name="Liquid water"    unit="kg/kg" />
+        <field id="ocond"    long_name="Condensed water"    unit="kg/kg" />
         <field id="geop"    long_name="Geopotential height"    unit="m2/s2" />
         <field id="vitu"    long_name="Zonal wind"    unit="m/s" />
@@ -726,8 +735,8 @@
       <field id="cltcalipsoun"    long_name="Lidar Undefined-Phase Total Cloud Fraction"   unit="%" />
       <field id="clcalipsoun"  long_name="Lidar Undefined-Phase Cloud Fraction (532 nm)" unit="%" axis_ref="height" />
-      <field id="clcalipsotmp"  long_name="Lidar Cloud Fraction (532 nm)" unit="%" axis_ref="height" />
-      <field id="clcalipsotmpliq"  long_name="Lidar Liq-Phase Cloud Fraction (532 nm)" unit="%" axis_ref="height" />
-      <field id="clcalipsotmpice"  long_name="Lidar Ice-Phase Cloud Fraction (532 nm)" unit="%" axis_ref="height" />
-      <field id="clcalipsotmpun"  long_name="Undefined-Phase Total Cloud Fraction"   unit="%" axis_ref="height" />
+      <field id="clcalipsotmp"  long_name="Lidar Cloud Fraction (532 nm)" unit="%" axis_ref="temp" />
+      <field id="clcalipsotmpliq"  long_name="Lidar Liq-Phase Cloud Fraction (532 nm)" unit="%" axis_ref="temp" />
+      <field id="clcalipsotmpice"  long_name="Lidar Ice-Phase Cloud Fraction (532 nm)" unit="%" axis_ref="temp" />
+      <field id="clcalipsotmpun"  long_name="Undefined-Phase Total Cloud Fraction"   unit="%" axis_ref="temp" />
     </field_group>  
 
@@ -801,4 +810,61 @@
     </field_group>
 
+    <field_group id="fields_COSP_MODIS" domain_ref="dom_glo" freq_op="3h">
+      <field id="cllmodis" long_name="MODIS Low-level Cloud Fraction" unit="1" />
+      <field id="clmmodis" long_name="MODIS Mid-level Cloud Fraction" unit="1" />
+      <field id="clhmodis" long_name="MODIS Hight-level Cloud Fraction" unit="1" />
+      <field id="cltmodis" long_name="MODIS Total Cloud Fraction" unit="1" />
+      <field id="clwmodis" long_name="MODIS Cloud Fraction water mean" unit="1" />
+      <field id="climodis" long_name="MODIS Cloud Fraction ice mean" unit="1" />
+      <field id="tautmodis" long_name="MODIS Optical_Thickness_Total_Mean" unit="1" />
+      <field id="tauwmodis" long_name="MODIS Optical_Thickness_Water_Mean" unit="1" />
+      <field id="tauimodis" long_name="MODIS Optical_Thickness_Ice_Mean" unit="1" />
+      <field id="tautlogmodis" long_name="MODIS Optical_Thickness_Total_logMean" unit="1" />
+      <field id="tauwlogmodis" long_name="MODIS Optical_Thickness_Water_logMean" unit="1" />
+      <field id="tauilogmodis" long_name="MODIS Optical_Thickness_Ice_logMean" unit="1" />
+      <field id="reffclwmodis"  long_name="Modis Cloud_Particle_Size_Water_Mean" unit="m" />
+      <field id="reffclimodis"  long_name="Modis Cloud_Particle_Size_Ice_Mean" unit="m" />
+      <field id="pctmodis"  long_name="Modis Cloud_Top_Pressure_Total_Mean" unit="Pa" />
+      <field id="lwpmodis" long_name="Modis Liquid_Water_Path_Mean" unit="kg m-2" />
+      <field id="iwpmodis" long_name="Modis Ice_Water_Path_Mean" unit="kg m-2" />
+      <field id="c01_clmodis" long_name="MODIS Cloud Area Fraction" unit="1" axis_ref="pressure2" />
+      <field id="c02_clmodis" long_name="MODIS Cloud Area Fraction" unit="1" axis_ref="pressure2" />
+      <field id="c03_clmodis" long_name="MODIS Cloud Area Fraction" unit="1" axis_ref="pressure2" />
+      <field id="c04_clmodis" long_name="MODIS Cloud Area Fraction" unit="1" axis_ref="pressure2" />
+      <field id="c05_clmodis" long_name="MODIS Cloud Area Fraction" unit="1" axis_ref="pressure2" />
+      <field id="c06_clmodis" long_name="MODIS Cloud Area Fraction" unit="1" axis_ref="pressure2" />
+      <field id="c07_clmodis" long_name="MODIS Cloud Area Fraction" unit="1" axis_ref="pressure2" />
+    </field_group>
+
+    <field_group id="fields_AIRS" domain_ref="dom_glo" operation="instant" freq_op="3h">
+      <field id="alt_tropo" long_name="Tropopause pressure" unit="hPa" />
+      <field id="map_prop_hc" long_name="Proportion of high clouds" unit=" "/>
+      <field id="map_prop_hist" long_name="Proportion of high ice semi-transp clouds" unit=" "/>
+      <field id="map_emis_hc" long_name="Emissivity of high clouds" unit=" "/>
+      <field id="map_iwp_hc" long_name="Ice water path of high clouds" unit="g/m2"/>
+      <field id="map_deltaz_hc" long_name="geom thickness of high clouds" unit="m"/>
+      <field id="map_pcld_hc" long_name="cloud pressure of high clouds" unit="hPa"/>
+      <field id="map_tcld_hc" long_name="cloud temperature of high clouds" unit="K"/>
+      <field id="map_emis_hist" long_name="Emissivity of high ice st clouds" unit=" "/>
+      <field id="map_iwp_hist" long_name="Ice water path of high ice st clouds" unit="g/m2"/>
+      <field id="map_deltaz_hist" long_name="geom thickness of high ice st clouds" unit="m"/>
+      <field id="map_rad_hist" long_name="ice crystals radius in high ice st clouds" unit="m"/>
+      <field id="map_emis_Cb" long_name="Emissivity of high Cb clouds" unit=" "/>
+      <field id="map_pcld_Cb" long_name="cloud pressure of high Cb clouds" unit="hPa"/>
+      <field id="map_tcld_Cb" long_name="cloud temperature of high Cb clouds" unit="K"/>
+      <field id="map_emis_Anv" long_name="Emissivity of high Anv clouds" unit=" "/>
+      <field id="map_pcld_Anv" long_name="cloud pressure of high Anv clouds" unit="hPa"/>
+      <field id="map_tcld_Anv" long_name="cloud temperature of high Anv clouds" unit="K"/>
+      <field id="map_emis_ThCi" long_name="Emissivity of high ThCi clouds" unit=" "/>
+      <field id="map_pcld_ThCi" long_name="cloud pressure of high ThCi clouds" unit="hPa"/>
+      <field id="map_tcld_ThCi" long_name="cloud temperature of high ThCi clouds" unit="K"/>
+      <field id="map_ntot" long_name="total AIRS cloud fraction" unit=" "/>
+      <field id="map_hc" long_name="high clouds AIRS cloud fraction" unit=" "/>
+      <field id="map_hist" long_name="high clouds ice st AIRS cloud fraction" unit=" "/>
+      <field id="map_Cb" long_name="high clouds Cb AIRS cloud fraction" unit=" "/>
+      <field id="map_ThCi" long_name="high clouds ThCi AIRS cloud fraction" unit=" "/>
+      <field id="map_Anv" long_name="high clouds Anv AIRS cloud fraction" unit=" "/>
+    </field_group>
+
 </field_definition>
 
Index: /LMDZ5/branches/testing/DefLists/file_def_histLES_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histLES_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histLES_lmdz.xml	(revision 2594)
@@ -282,4 +282,12 @@
                 <field field_ref="tke_max_oce" level="10" operation="maximum" />
                 <field field_ref="tke_max_sic" level="10" operation="maximum" />
+                <field field_ref="l_mix_ter" level="10" />
+                <field field_ref="l_mix_lic" level="10" />
+                <field field_ref="l_mix_oce" level="10" />
+                <field field_ref="l_mix_sic" level="10" />
+                <field field_ref="l_mixmin_ter" level="10" />
+                <field field_ref="l_mixmin_lic" level="10" />
+                <field field_ref="l_mixmin_oce" level="10" />
+                <field field_ref="l_mixmin_sic" level="10" />
                 <field field_ref="SWnetOR" level="10" />
                 <field field_ref="SWdownOR" level="10" />
@@ -423,4 +431,5 @@
                 <field field_ref="ovapinit" level="10" />
                 <field field_ref="oliq" level="10" />
+                <field field_ref="ocond" level="10" />
                 <field field_ref="geop" level="10" />
                 <field field_ref="vitu" level="10" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histdayCOSP_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histdayCOSP_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histdayCOSP_lmdz.xml	(revision 2594)
@@ -1,5 +1,5 @@
 <file_definition>
      <file_group id="defile">
-        <file id="histdayCOSP" name="histdayCOSP" output_freq="1d" output_level="1"  enabled=".TRUE.">
+        <file id="histdayCOSP" name="histdayCOSP" output_freq="1d" output_level="1"  enabled="_AUTO_">
 
             <!-- VARS Calipso and PARASOL -->
@@ -25,8 +25,8 @@
                 <field field_ref="clcalipsoliq"  level="1" axis_ref="height" />
                 <field field_ref="clcalipsoun"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmp"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmpice"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmpliq"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmpun"  level="1" axis_ref="height" />
+                <field field_ref="clcalipsotmp"  level="1" axis_ref="temp" />
+                <field field_ref="clcalipsotmpice"  level="1" axis_ref="temp" />
+                <field field_ref="clcalipsotmpliq"  level="1" axis_ref="temp" />
+                <field field_ref="clcalipsotmpun"  level="1" axis_ref="temp" />
                 <field field_ref="parasol_refl"  level="1" axis_ref="sza" />
                 <field field_ref="parasol_crefl"  level="1" axis_ref="sza" />
@@ -139,4 +139,31 @@
             </field_group>
 
+            <field_group operation="average" freq_op="3h" detect_missing_value=".true.">
+                <field field_ref="cllmodis" level="1" />
+                <field field_ref="clmmodis" level="1" />
+                <field field_ref="clhmodis" level="1" />
+                <field field_ref="cltmodis" level="1" />
+                <field field_ref="clwmodis" level="1" />
+                <field field_ref="climodis" level="1" />
+                <field field_ref="tautmodis" level="1" />
+                <field field_ref="tauwmodis" level="1" />
+                <field field_ref="tauimodis" level="1" />
+                <field field_ref="tautlogmodis" level="1" />
+                <field field_ref="tauilogmodis" level="1" />
+                <field field_ref="tauwlogmodis" level="1" />
+                <field field_ref="reffclwmodis" level="1" />
+                <field field_ref="reffclimodis" level="1" />
+                <field field_ref="pctmodis"  unit="1" />
+                <field field_ref="lwpmodis" level="1" />
+                <field field_ref="iwpmodis" level="1" />
+                <field field_ref="c01_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c02_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c03_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c04_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c05_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c06_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c07_clmodis" level="1" axis_ref="pressure2" />
+            </field_group>
+
         </file>
      </file_group>
Index: /LMDZ5/branches/testing/DefLists/file_def_histdayNMC_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histdayNMC_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histdayNMC_lmdz.xml	(revision 2594)
@@ -1,5 +1,5 @@
 <file_definition>
     <file_group id="defile">
-        <file id="histdayNMC" name="histdayNMC" output_freq="1d" output_level="5" enabled=".FALSE.">
+        <file id="histdayNMC" name="histdayNMC" output_freq="1d" output_level="5" enabled="_AUTO_">
 
             <!-- VARS 3D -->
Index: /LMDZ5/branches/testing/DefLists/file_def_histday_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histday_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histday_lmdz.xml	(revision 2594)
@@ -1,5 +1,5 @@
 <file_definition>
     <file_group id="defile">
-        <file id="histday" name="histday" output_freq="1d" output_level="2" enabled=".FALSE.">
+        <file id="histday" name="histday" output_freq="1d" output_level="2" enabled="_AUTO_">
             
             <!-- VARS 1D -->
@@ -282,4 +282,12 @@
                 <field field_ref="tke_max_oce" level="4" operation="maximum" />
                 <field field_ref="tke_max_sic" level="4" operation="maximum" />
+                <field field_ref="l_mix_ter" level="10" />
+                <field field_ref="l_mix_lic" level="10" />
+                <field field_ref="l_mix_oce" level="10" />
+                <field field_ref="l_mix_sic" level="10" />
+                <field field_ref="l_mixmin_ter" level="10" />
+                <field field_ref="l_mixmin_lic" level="10" />
+                <field field_ref="l_mixmin_oce" level="10" />
+                <field field_ref="l_mixmin_sic" level="10" />
                 <field field_ref="SWnetOR" level="10" />
                 <field field_ref="SWdownOR" level="10" />
@@ -423,4 +431,5 @@
                 <field field_ref="ovapinit" level="10" />
                 <field field_ref="oliq" level="3" />
+                <field field_ref="ocond" level="3" />
                 <field field_ref="geop" level="3" />
                 <field field_ref="vitu" level="3" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histhfCOSP_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histhfCOSP_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histhfCOSP_lmdz.xml	(revision 2594)
@@ -1,8 +1,8 @@
 <file_definition>
      <file_group id="defile">
-        <file id="histhfCOSP" name="XhisthfCOSP" output_freq="3h" output_level="1"  enabled=".TRUE.">
+        <file id="histhfCOSP" name="histhfCOSP" output_freq="3h" output_level="1"  enabled="_AUTO_">
 
             <!-- VARS Calipso and PARASOL -->
-            <field_group operation="average" freq_op="3h" detect_missing_value=".true.">
+            <field_group operation="instant" freq_op="3h" detect_missing_value=".true.">
                 <field field_ref="cllcalipso"         level="1" />
                 <field field_ref="clmcalipso"         level="1" />
@@ -25,8 +25,8 @@
                 <field field_ref="clcalipsoliq"  level="1" axis_ref="height" />
                 <field field_ref="clcalipsoun"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmp"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmpice"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmpliq"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmpun"  level="1" axis_ref="height" />
+                <field field_ref="clcalipsotmp"  level="1" axis_ref="temp" />
+                <field field_ref="clcalipsotmpice"  level="1" axis_ref="temp" />
+                <field field_ref="clcalipsotmpliq"  level="1" axis_ref="temp" />
+                <field field_ref="clcalipsotmpun"  level="1" axis_ref="temp" />
                 <field field_ref="parasol_refl"  level="1" axis_ref="sza" />
                 <field field_ref="parasol_crefl"  level="1" axis_ref="sza" />
@@ -70,5 +70,5 @@
               </field_group>
              <!-- VARS CLOUDSAT et/ou Calipso -->
-            <field_group operation="average" freq_op="3h" detect_missing_value=".true."> 
+            <field_group operation="instant" freq_op="3h" detect_missing_value=".true."> 
                <field field_ref="cltlidarradar"  level="1"/>
                <field field_ref="clcalipso2"  level="1" axis_ref="height" />
@@ -110,5 +110,5 @@
               </field_group>
              <!-- VARS ISCCP -->
-            <field_group operation="average" freq_op="3h" detect_missing_value=".true.">
+            <field_group operation="instant" freq_op="3h" detect_missing_value=".true.">
                 <field field_ref="sunlit" level="1" />
                 <field field_ref="c01_clisccp2" level="1" axis_ref="pressure2" />
@@ -129,5 +129,5 @@
              </field_group>
              <!-- VARS MISR -->
-            <field_group operation="average" freq_op="3h" detect_missing_value=".true.">
+            <field_group operation="instant" freq_op="3h" detect_missing_value=".true.">
                 <field field_ref="c01_clMISR" level="1" axis_ref="cth16" />
                 <field field_ref="c02_clMISR" level="1" axis_ref="cth16" />
@@ -139,4 +139,31 @@
             </field_group>
 
+            <field_group operation="instant" freq_op="3h" detect_missing_value=".true.">
+                <field field_ref="cllmodis" level="1" />
+                <field field_ref="clmmodis" level="1" />
+                <field field_ref="clhmodis" level="1" />
+                <field field_ref="cltmodis" level="1" />
+                <field field_ref="clwmodis" level="1" />
+                <field field_ref="climodis" level="1" />
+                <field field_ref="tautmodis" level="1" />
+                <field field_ref="tauwmodis" level="1" />
+                <field field_ref="tauimodis" level="1" />
+                <field field_ref="tautlogmodis" level="1" />
+                <field field_ref="tauilogmodis" level="1" />
+                <field field_ref="tauwlogmodis" level="1" />
+                <field field_ref="reffclwmodis" level="1" />
+                <field field_ref="reffclimodis" level="1" />
+                <field field_ref="pctmodis"  unit="1" />
+                <field field_ref="lwpmodis" level="1" />
+                <field field_ref="iwpmodis" level="1" />
+                <field field_ref="c01_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c02_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c03_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c04_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c05_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c06_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c07_clmodis" level="1" axis_ref="pressure2" />
+            </field_group>
+
         </file>
      </file_group>
Index: /LMDZ5/branches/testing/DefLists/file_def_histhfNMC_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histhfNMC_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histhfNMC_lmdz.xml	(revision 2594)
@@ -1,5 +1,5 @@
 <file_definition>
     <file_group id="defile">
-        <file id="histhfNMC" name="histhfNMC" output_freq="6h" output_level="5" enabled=".FALSE.">
+        <file id="histhfNMC" name="histhfNMC" output_freq="6h" output_level="5" enabled="_AUTO_">
 
             <!-- VARS 3D -->
Index: /LMDZ5/branches/testing/DefLists/file_def_histhf_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histhf_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histhf_lmdz.xml	(revision 2594)
@@ -1,5 +1,5 @@
 <file_definition>
     <file_group id="defile">
-        <file id="histhf" name="histhf" output_freq="6h" output_level="5" enabled=".FALSE.">
+        <file id="histhf" name="histhf" output_freq="6h" output_level="5" enabled="_AUTO_">
             
             <!-- VARS 1D -->
@@ -282,4 +282,12 @@
                 <field field_ref="tke_max_oce" level="10" operation="maximum" />
                 <field field_ref="tke_max_sic" level="10" operation="maximum" />
+                <field field_ref="l_mix_ter" level="10" />
+                <field field_ref="l_mix_lic" level="10" />
+                <field field_ref="l_mix_oce" level="10" />
+                <field field_ref="l_mix_sic" level="10" />
+                <field field_ref="l_mixmin_ter" level="10" />
+                <field field_ref="l_mixmin_lic" level="10" />
+                <field field_ref="l_mixmin_oce" level="10" />
+                <field field_ref="l_mixmin_sic" level="10" />
                 <field field_ref="SWnetOR" level="10" />
                 <field field_ref="SWdownOR" level="10" />
@@ -403,4 +411,34 @@
             </field_group>
 
+            <field_group operation="instant" freq_op="1ts" >
+                 <field field_ref="alt_tropo" level="10" />
+                 <field field_ref="map_prop_hc" level="10" />
+                 <field field_ref="map_prop_hist" level="10" />
+                 <field field_ref="map_emis_hc" level="10" />
+                 <field field_ref="map_iwp_hc" level="10" />
+                 <field field_ref="map_deltaz_hc" level="10" />
+                 <field field_ref="map_pcld_hc" level="10" />
+                 <field field_ref="map_tcld_hc" level="10" />
+                 <field field_ref="map_emis_hist" level="10" />
+                 <field field_ref="map_iwp_hist" level="10" />
+                 <field field_ref="map_deltaz_hist" level="10" />
+                 <field field_ref="map_rad_hist" level="10" />
+                 <field field_ref="map_emis_Cb" level="10" />
+                 <field field_ref="map_pcld_Cb" level="10" />
+                 <field field_ref="map_tcld_Cb" level="10" />
+                 <field field_ref="map_emis_Anv" level="10" />
+                 <field field_ref="map_pcld_Anv" level="10" />
+                 <field field_ref="map_tcld_Anv" level="10" />
+                 <field field_ref="map_emis_ThCi" level="10" />
+                 <field field_ref="map_pcld_ThCi" level="10" />
+                 <field field_ref="map_tcld_ThCi" level="10" />
+                 <field field_ref="map_ntot" level="10" />
+                 <field field_ref="map_hc" level="10" />
+                 <field field_ref="map_hist" level="10" />
+                 <field field_ref="map_Cb" level="10" />
+                 <field field_ref="map_ThCi" level="10" />
+                 <field field_ref="map_Anv" level="10" />
+            </field_group>
+
             <!-- VARS 3D -->
             <field_group operation="average" freq_op="1ts" axis_ref="presnivs">
@@ -423,4 +461,5 @@
                 <field field_ref="ovapinit" level="10" />
                 <field field_ref="oliq" level="10" />
+                <field field_ref="ocond" level="10" />
                 <field field_ref="geop" level="10" />
                 <field field_ref="vitu" level="6" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histins_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histins_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histins_lmdz.xml	(revision 2594)
@@ -282,4 +282,12 @@
                 <field field_ref="tke_max_oce" level="10" operation="maximum" />
                 <field field_ref="tke_max_sic" level="10" operation="maximum" />
+                <field field_ref="l_mix_ter" level="10" />
+                <field field_ref="l_mix_lic" level="10" />
+                <field field_ref="l_mix_oce" level="10" />
+                <field field_ref="l_mix_sic" level="10" />
+                <field field_ref="l_mixmin_ter" level="10" />
+                <field field_ref="l_mixmin_lic" level="10" />
+                <field field_ref="l_mixmin_oce" level="10" />
+                <field field_ref="l_mixmin_sic" level="10" />
                 <field field_ref="SWnetOR" level="2" />
                 <field field_ref="SWdownOR" level="2" />
@@ -423,4 +431,5 @@
                 <field field_ref="ovapinit" level="10" />
                 <field field_ref="oliq" level="4" />
+                <field field_ref="ocond" level="4" />
                 <field field_ref="geop" level="10" />
                 <field field_ref="vitu" level="4" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histmthCOSP_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histmthCOSP_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histmthCOSP_lmdz.xml	(revision 2594)
@@ -1,5 +1,5 @@
 <file_definition>
      <file_group id="defile">
-        <file id="histmthCOSP" name="histmthCOSP" output_freq="30d" output_level="1"  enabled=".TRUE.">
+        <file id="histmthCOSP" name="histmthCOSP" output_freq="30d" output_level="1"  enabled="_AUTO_">
 
             <!-- VARS Calipso and PARASOL -->
@@ -25,8 +25,8 @@
                 <field field_ref="clcalipsoliq"  level="1" axis_ref="height" />
                 <field field_ref="clcalipsoun"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmp"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmpice"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmpliq"  level="1" axis_ref="height" />
-                <field field_ref="clcalipsotmpun"  level="1" axis_ref="height" />
+                <field field_ref="clcalipsotmp"  level="1" axis_ref="temp" />
+                <field field_ref="clcalipsotmpice"  level="1" axis_ref="temp" />
+                <field field_ref="clcalipsotmpliq"  level="1" axis_ref="temp" />
+                <field field_ref="clcalipsotmpun"  level="1" axis_ref="temp" />
                 <field field_ref="parasol_refl"  level="1" axis_ref="sza" />
                 <field field_ref="parasol_crefl"  level="1" axis_ref="sza" />
@@ -138,4 +138,30 @@
                 <field field_ref="c07_clMISR" level="1" axis_ref="cth16" />
             </field_group>
+            <field_group operation="average" freq_op="3h" detect_missing_value=".true.">
+                <field field_ref="cllmodis" level="1" />
+                <field field_ref="clmmodis" level="1" />
+                <field field_ref="clhmodis" level="1" />
+                <field field_ref="cltmodis" level="1" />
+                <field field_ref="clwmodis" level="1" />
+                <field field_ref="climodis" level="1" />
+                <field field_ref="tautmodis" level="1" />
+                <field field_ref="tauwmodis" level="1" />
+                <field field_ref="tauimodis" level="1" />
+                <field field_ref="tautlogmodis" level="1" />
+                <field field_ref="tauilogmodis" level="1" />
+                <field field_ref="tauwlogmodis" level="1" />
+                <field field_ref="reffclwmodis" level="1" />
+                <field field_ref="reffclimodis" level="1" />
+                <field field_ref="pctmodis"  unit="1" />
+                <field field_ref="lwpmodis" level="1" />
+                <field field_ref="iwpmodis" level="1" />
+                <field field_ref="c01_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c02_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c03_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c04_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c05_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c06_clmodis" level="1" axis_ref="pressure2" />
+                <field field_ref="c07_clmodis" level="1" axis_ref="pressure2" />
+            </field_group>
 
         </file>
Index: /LMDZ5/branches/testing/DefLists/file_def_histmthNMC_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histmthNMC_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histmthNMC_lmdz.xml	(revision 2594)
@@ -1,5 +1,5 @@
 <file_definition>
     <file_group id="defile">
-        <file id="histmthNMC" name="histmthNMC" output_freq="1mo" output_level="5" enabled=".FALSE.">
+        <file id="histmthNMC" name="histmthNMC" output_freq="1mo" output_level="5" enabled="_AUTO_">
 
             <!-- VARS 3D -->
Index: /LMDZ5/branches/testing/DefLists/file_def_histmth_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histmth_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histmth_lmdz.xml	(revision 2594)
@@ -1,5 +1,5 @@
 <file_definition>
         <file_group id="defile">
-        <file id="histmth" name="histmth" output_freq="1mo" output_level="5"  enabled=".FALSE.">
+        <file id="histmth" name="histmth" output_freq="1mo" output_level="5"  enabled="_AUTO_">
 
             <!-- VARS 1D -->
@@ -282,4 +282,12 @@
                 <field field_ref="tke_max_oce" level="10" operation="maximum" />
                 <field field_ref="tke_max_sic" level="10" operation="maximum" />
+                <field field_ref="l_mix_ter" level="10" />
+                <field field_ref="l_mix_lic" level="10" />
+                <field field_ref="l_mix_oce" level="10" />
+                <field field_ref="l_mix_sic" level="10" />
+                <field field_ref="l_mixmin_ter" level="10" />
+                <field field_ref="l_mixmin_lic" level="10" />
+                <field field_ref="l_mixmin_oce" level="10" />
+                <field field_ref="l_mixmin_sic" level="10" />
                 <field field_ref="SWnetOR" level="10" />
                 <field field_ref="SWdownOR" level="10" />
@@ -423,4 +431,5 @@
                 <field field_ref="ovapinit" level="2" />
                 <field field_ref="oliq" level="2" />
+                <field field_ref="ocond" level="2" />
                 <field field_ref="geop" level="2" />
                 <field field_ref="vitu" level="2" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histstn_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histstn_lmdz.xml	(revision 2593)
+++ /LMDZ5/branches/testing/DefLists/file_def_histstn_lmdz.xml	(revision 2594)
@@ -1,5 +1,5 @@
 <file_definition>
     <file_group id="defile">
-        <file id="histstn" name="histstn" output_freq="1800s" output_level="5" enabled=".FALSE.">
+        <file id="histstn" name="histstn" output_freq="1800s" output_level="5" enabled="_AUTO_">
 
             <!-- VARS 1D -->
@@ -282,4 +282,12 @@
                 <field field_ref="tke_max_oce" level="10" operation="maximum" />
                 <field field_ref="tke_max_sic" level="10" operation="maximum" />
+                <field field_ref="l_mix_ter" level="10" />
+                <field field_ref="l_mix_lic" level="10" />
+                <field field_ref="l_mix_oce" level="10" />
+                <field field_ref="l_mix_sic" level="10" />
+                <field field_ref="l_mixmin_ter" level="10" />
+                <field field_ref="l_mixmin_lic" level="10" />
+                <field field_ref="l_mixmin_oce" level="10" />
+                <field field_ref="l_mixmin_sic" level="10" />
                 <field field_ref="SWnetOR" level="10" />
                 <field field_ref="SWdownOR" level="10" />
@@ -423,4 +431,5 @@
                 <field field_ref="ovapinit" level="10" />
                 <field field_ref="oliq" level="10" />
+                <field field_ref="ocond" level="10" />
                 <field field_ref="geop" level="10" />
                 <field field_ref="vitu" level="10" />
Index: /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.65
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.65	(revision 2594)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.65	(revision 2594)
@@ -0,0 +1,230 @@
+#
+# $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.6
+f_ri_cd_min=0.1
+#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
+
+ok_strato=y
+ok_hines=n
+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.0004
+cld_lc_con=0.0004
+#constante de temps pour eleminer eau lsc et convective (D: 3600. 3600.)
+cld_tau_lsc=900.
+cld_tau_con=900.
+#facteurs correctifs sur la vitesse de chute des cristaux de glace (D: 1 1)
+ffallv_lsc=.5
+ffallv_con=.5
+#coefficient sur la reevaporation de la pluie (D: 2.e-5 n)
+coef_eva=2e-4
+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.40
+ratqsp0=50000.
+ratqsdp=20000.
+#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=2
+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=0
+
+#
+lmixmin=10.
+
+#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=1
+pbcrit=150.0
+#altitude, in hPa, above LCL above which Ep=Epmax, def = original: 500, used only if flag_epKEorig=1
+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.00025
+#temperature in degre Celsius, at which Ep=Epmax, def=-55., original: -55, used only if flag_epKEorig=1
+tlcrit=-40.
+
Index: /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.67
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.67	(revision 2594)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_NPv5.67	(revision 2594)
@@ -0,0 +1,246 @@
+#
+# $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.6
+f_ri_cd_min=0.1
+#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
+
+ok_strato=y
+ok_hines=n
+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.0002
+cld_lc_con=0.0002
+#constante de temps pour eleminer eau lsc et convective (D: 3600. 3600.)
+cld_tau_lsc=900.
+cld_tau_con=900.
+#facteurs correctifs sur la vitesse de chute des cristaux de glace (D: 1 1)
+ffallv_lsc=.5
+ffallv_con=.5
+#coefficient sur la reevaporation de la pluie (D: 2.e-5 n)
+coef_eva=2e-4
+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.40
+ratqsp0=50000.
+ratqsdp=20000.
+#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=2
+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=0
+
+#
+lmixmin=10.
+
+#Bergeron
+iflag_bergeron=1
+
+################################################################################
+### Convection.def file
+
+### 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=1
+pbcrit=150.0
+#altitude, in hPa, above LCL above which Ep=Epmax, def = original: 500, used only if flag_epKEorig=1
+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.00025
+#temperature in degre Celsius, at which Ep=Epmax, def=-55., original: -55, used only if flag_epKEorig=1
+tlcrit=-40.
+
+### 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/libf/dyn3d_common/infotrac.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/infotrac.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/infotrac.F90	(revision 2594)
@@ -86,4 +86,7 @@
     INTEGER, ALLOCATABLE, DIMENSION(:) :: hadv  ! index of horizontal trasport schema
     INTEGER, ALLOCATABLE, DIMENSION(:) :: vadv  ! index of vertical trasport schema
+
+    INTEGER, ALLOCATABLE, DIMENSION(:) :: hadv_inca  ! index of horizontal trasport schema
+    INTEGER, ALLOCATABLE, DIMENSION(:) :: vadv_inca  ! index of vertical trasport schema
 
     CHARACTER(len=15), ALLOCATABLE, DIMENSION(:) :: tnom_0  ! tracer short name
@@ -205,4 +208,7 @@
 #endif       
        nqtrue=nbtr+nqo
+
+       ALLOCATE(hadv_inca(nbtr), vadv_inca(nbtr)) 
+
     END IF   ! type_trac
 !>jyg
@@ -226,4 +232,5 @@
 !
     ALLOCATE(tnom_0(nqtrue), hadv(nqtrue), vadv(nqtrue),tnom_transp(nqtrue))
+
 !
 !jyg<
@@ -375,33 +382,78 @@
 !>jyg
 ! le module de chimie fournit les noms des traceurs
-! et les schemas d'advection associes.
-     
+! et les schemas d'advection associes. excepte pour ceux lus 
+! dans traceur.def 
+       IF (ierr .eq. 0) then 
+          DO iq=1,nqo
+
+             write(*,*) 'infotrac 237: iq=',iq
+             ! CRisi: ajout du nom du fluide transporteur
+             ! mais rester retro compatible
+             READ(90,'(I2,X,I2,X,A)',IOSTAT=IOstatus) hadv(iq),vadv(iq),tchaine
+             write(lunout,*) 'iq,hadv(iq),vadv(iq)=',iq,hadv(iq),vadv(iq)
+             write(lunout,*) 'tchaine=',trim(tchaine)
+             write(*,*) 'infotrac 238: IOstatus=',IOstatus
+             if (IOstatus.ne.0) then
+                CALL abort_gcm('infotrac_init','Pb dans la lecture de traceur.def',1)
+             endif
+             ! Y-a-t-il 1 ou 2 noms de traceurs? -> On regarde s'il y a un
+             ! espace ou pas au milieu de la chaine.
+             continu=.true.
+             nouveau_traceurdef=.false.
+             iiq=1
+             do while (continu)
+                if (tchaine(iiq:iiq).eq.' ') then
+                  nouveau_traceurdef=.true.
+                  continu=.false.
+                else if (iiq.lt.LEN_TRIM(tchaine)) then
+                  iiq=iiq+1
+                else
+                  continu=.false.
+                endif
+             enddo
+             write(*,*) 'iiq,nouveau_traceurdef=',iiq,nouveau_traceurdef
+             if (nouveau_traceurdef) then
+                write(lunout,*) 'C''est la nouvelle version de traceur.def'
+                tnom_0(iq)=tchaine(1:iiq-1)
+                tnom_transp(iq)=tchaine(iiq+1:15)
+             else
+                write(lunout,*) 'C''est l''ancienne version de traceur.def'
+                write(lunout,*) 'On suppose que les traceurs sont tous d''air'
+                tnom_0(iq)=tchaine
+                tnom_transp(iq) = 'air'
+             endif
+             write(lunout,*) 'tnom_0(iq)=<',trim(tnom_0(iq)),'>'
+             write(lunout,*) 'tnom_transp(iq)=<',trim(tnom_transp(iq)),'>'
+
+          END DO !DO iq=1,nqtrue
+          CLOSE(90)  
+       ELSE  !! if traceur.def doesn't exist 
+          tnom_0(1)='H2Ov'
+          tnom_transp(1) = 'air'
+          tnom_0(2)='H2Ol'
+          tnom_transp(2) = 'air'
+          hadv(1) = 10
+          hadv(2) = 10 
+          vadv(1) = 10 
+          vadv(2) = 10 
+       ENDIF
+ 
 #ifdef INCA
        CALL init_transport( &
-            hadv, &
-            vadv, &
+            hadv_inca, &
+            vadv_inca, &
             conv_flg, &
             pbl_flg,  &
             solsym)
 #endif
-       tnom_0(1)='H2Ov'
-       tnom_transp(1) = 'air'
-       tnom_0(2)='H2Ol'
-       tnom_transp(2) = 'air'
-       IF (nqo == 3) then 
-          tnom_0(3)='H2Oi'     !! jyg
-          tnom_transp(3) = 'air'
-       endif
+
 
 !jyg<
        DO iq = nqo+1, nqtrue
+          hadv(iq) = hadv_inca(iq-nqo) 
+          vadv(iq) = vadv_inca(iq-nqo) 
           tnom_0(iq)=solsym(iq-nqo)
           tnom_transp(iq) = 'air'
        END DO
-!!       DO iq =3,nqtrue
-!!          tnom_0(iq)=solsym(iq-2)
-!!       END DO
-!!       nqo = 2
-!>jyg
 
     END IF ! (type_trac == 'inca')
Index: /LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F90	(revision 2594)
@@ -235,6 +235,7 @@
 
 !--- Tracers in file "start_trac.nc" (added by Anne)
+  lread_inca=.FALSE.
 !$OMP MASTER
-  lread_inca=.FALSE.; fil="start_trac.nc"
+  fil="start_trac.nc"
   IF(type_trac=='inca') INQUIRE(FILE=fil,EXIST=lread_inca)
   IF(lread_inca) CALL err(NF90_OPEN(fil,NF90_NOWRITE,nid_trac),"open")
Index: /LMDZ5/branches/testing/libf/dynphy_lonlat/inigeomphy_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynphy_lonlat/inigeomphy_mod.F90	(revision 2594)
+++ /LMDZ5/branches/testing/libf/dynphy_lonlat/inigeomphy_mod.F90	(revision 2594)
@@ -0,0 +1,224 @@
+!
+! $Id: $
+!
+MODULE inigeomphy_mod
+
+CONTAINS
+
+SUBROUTINE inigeomphy(iim,jjm,nlayer, &
+                     nbp, communicator, &
+                     rlatu,rlatv,rlonu,rlonv,aire,cu,cv)
+  USE mod_grid_phy_lmdz, ONLY: klon_glo,  & ! number of atmospheric columns (on full grid)
+                               regular_lonlat, &  ! regular longitude-latitude grid type
+                               nbp_lon, nbp_lat, nbp_lev
+  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
+                                klon_omp_begin, & ! start index of local omp subgrid
+                                klon_omp_end, & ! end index of local omp subgrid
+                                klon_mpi_begin ! start indes of columns (on local mpi grid)
+  USE geometry_mod, ONLY : init_geometry
+  USE physics_distribution_mod, ONLY : init_physics_distribution
+  USE regular_lonlat_mod, ONLY : init_regular_lonlat, &
+                                 east, west, north, south, &
+                                 north_east, north_west, &
+                                 south_west, south_east
+  USE mod_interface_dyn_phys, ONLY :  init_interface_dyn_phys
+  USE nrtype, ONLY: pi
+  IMPLICIT NONE
+
+  ! =======================================================================
+  ! Initialisation of the physical constants and some positional and
+  ! geometrical arrays for the physics
+  ! =======================================================================
+
+  include "iniprint.h"
+
+  INTEGER, INTENT (IN) :: nlayer ! number of atmospheric layers
+  INTEGER, INTENT (IN) :: iim ! number of atmospheric columns along longitudes
+  INTEGER, INTENT (IN) :: jjm ! number of atompsheric columns along latitudes
+  INTEGER, INTENT(IN) :: nbp ! number of physics columns for this MPI process
+  INTEGER, INTENT(IN) :: communicator ! MPI communicator
+  REAL, INTENT (IN) :: rlatu(jjm+1) ! latitudes of the physics grid
+  REAL, INTENT (IN) :: rlatv(jjm) ! latitude boundaries of the physics grid
+  REAL, INTENT (IN) :: rlonv(iim+1) ! longitudes of the physics grid
+  REAL, INTENT (IN) :: rlonu(iim+1) ! longitude boundaries of the physics grid
+  REAL, INTENT (IN) :: aire(iim+1,jjm+1) ! area of the dynamics grid (m2)
+  REAL, INTENT (IN) :: cu((iim+1)*(jjm+1)) ! cu coeff. (u_covariant = cu * u)
+  REAL, INTENT (IN) :: cv((iim+1)*jjm) ! cv coeff. (v_covariant = cv * v)
+
+  INTEGER :: ibegin, iend, offset
+  INTEGER :: i,j,k
+  CHARACTER (LEN=20) :: modname = 'inigeomphy'
+  CHARACTER (LEN=80) :: abort_message
+  REAL :: total_area_phy, total_area_dyn
+
+  ! boundaries, on global grid
+  REAL,ALLOCATABLE :: boundslon_reg(:,:)
+  REAL,ALLOCATABLE :: boundslat_reg(:,:)
+
+  ! global array, on full physics grid:
+  REAL,ALLOCATABLE :: latfi_glo(:)
+  REAL,ALLOCATABLE :: lonfi_glo(:)
+  REAL,ALLOCATABLE :: cufi_glo(:)
+  REAL,ALLOCATABLE :: cvfi_glo(:)
+  REAL,ALLOCATABLE :: airefi_glo(:)
+  REAL,ALLOCATABLE :: boundslonfi_glo(:,:)
+  REAL,ALLOCATABLE :: boundslatfi_glo(:,:)
+
+  ! local arrays, on given MPI/OpenMP domain:
+  REAL,ALLOCATABLE,SAVE :: latfi(:)
+  REAL,ALLOCATABLE,SAVE :: lonfi(:)
+  REAL,ALLOCATABLE,SAVE :: cufi(:)
+  REAL,ALLOCATABLE,SAVE :: cvfi(:)
+  REAL,ALLOCATABLE,SAVE :: airefi(:)
+  REAL,ALLOCATABLE,SAVE :: boundslonfi(:,:)
+  REAL,ALLOCATABLE,SAVE :: boundslatfi(:,:)
+!$OMP THREADPRIVATE (latfi,lonfi,cufi,cvfi,airefi,boundslonfi,boundslatfi)
+
+  ! Initialize Physics distibution and parameters and interface with dynamics
+  IF (iim*jjm>1) THEN ! general 3D case
+    CALL init_physics_distribution(regular_lonlat,4, &
+                                 nbp,iim,jjm+1,nlayer,communicator)
+  ELSE ! For 1D model
+    CALL init_physics_distribution(regular_lonlat,4, &
+                                 1,1,1,nlayer,communicator)
+  ENDIF
+  CALL init_interface_dyn_phys
+  
+  ! init regular global longitude-latitude grid points and boundaries
+  ALLOCATE(boundslon_reg(iim,2))
+  ALLOCATE(boundslat_reg(jjm+1,2))
+  
+  DO i=1,iim
+   boundslon_reg(i,east)=rlonu(i) 
+   boundslon_reg(i,west)=rlonu(i+1) 
+  ENDDO
+
+  boundslat_reg(1,north)= PI/2 
+  boundslat_reg(1,south)= rlatv(1)
+  DO j=2,jjm
+   boundslat_reg(j,north)=rlatv(j-1) 
+   boundslat_reg(j,south)=rlatv(j) 
+  ENDDO
+  boundslat_reg(jjm+1,north)= rlatv(jjm) 
+  boundslat_reg(jjm+1,south)= -PI/2
+
+  ! Write values in module regular_lonlat_mod
+  CALL init_regular_lonlat(iim,jjm+1, rlonv(1:iim), rlatu, &
+                           boundslon_reg, boundslat_reg)
+
+  ! Generate global arrays on full physics grid
+  ALLOCATE(latfi_glo(klon_glo),lonfi_glo(klon_glo))
+  ALLOCATE(cufi_glo(klon_glo),cvfi_glo(klon_glo))
+  ALLOCATE(airefi_glo(klon_glo))
+  ALLOCATE(boundslonfi_glo(klon_glo,4))
+  ALLOCATE(boundslatfi_glo(klon_glo,4))
+
+  IF (klon_glo>1) THEN ! general case
+    ! North pole
+    latfi_glo(1)=rlatu(1)
+    lonfi_glo(1)=0.
+    cufi_glo(1) = cu(1)
+    cvfi_glo(1) = cv(1)
+    boundslonfi_glo(1,north_east)=0
+    boundslatfi_glo(1,north_east)=PI/2
+    boundslonfi_glo(1,north_west)=2*PI
+    boundslatfi_glo(1,north_west)=PI/2
+    boundslonfi_glo(1,south_west)=2*PI
+    boundslatfi_glo(1,south_west)=rlatv(1)
+    boundslonfi_glo(1,south_east)=0
+    boundslatfi_glo(1,south_east)=rlatv(1)
+    DO j=2,jjm
+      DO i=1,iim
+        k=(j-2)*iim+1+i
+        latfi_glo(k)= rlatu(j)
+        lonfi_glo(k)= rlonv(i)
+        cufi_glo(k) = cu((j-1)*(iim+1)+i)
+        cvfi_glo(k) = cv((j-1)*(iim+1)+i)
+        boundslonfi_glo(k,north_east)=rlonu(i)
+        boundslatfi_glo(k,north_east)=rlatv(j-1)
+        boundslonfi_glo(k,north_west)=rlonu(i+1)
+        boundslatfi_glo(k,north_west)=rlatv(j-1)
+        boundslonfi_glo(k,south_west)=rlonu(i+1)
+        boundslatfi_glo(k,south_west)=rlatv(j)
+        boundslonfi_glo(k,south_east)=rlonu(i)
+        boundslatfi_glo(k,south_east)=rlatv(j)
+      ENDDO
+    ENDDO
+    ! South pole
+    latfi_glo(klon_glo)= rlatu(jjm+1)
+    lonfi_glo(klon_glo)= 0.
+    cufi_glo(klon_glo) = cu((iim+1)*jjm+1)
+    cvfi_glo(klon_glo) = cv((iim+1)*jjm-iim)
+    boundslonfi_glo(klon_glo,north_east)= 0
+    boundslatfi_glo(klon_glo,north_east)= rlatv(jjm)
+    boundslonfi_glo(klon_glo,north_west)= 2*PI
+    boundslatfi_glo(klon_glo,north_west)= rlatv(jjm)
+    boundslonfi_glo(klon_glo,south_west)= 2*PI
+    boundslatfi_glo(klon_glo,south_west)= -PI/2
+    boundslonfi_glo(klon_glo,south_east)= 0
+    boundslatfi_glo(klon_glo,south_east)= -Pi/2
+
+    ! build airefi(), mesh area on physics grid
+    CALL gr_dyn_fi(1,iim+1,jjm+1,klon_glo,aire,airefi_glo)
+    ! Poles are single points on physics grid
+    airefi_glo(1)=sum(aire(1:iim,1))
+    airefi_glo(klon_glo)=sum(aire(1:iim,jjm+1))
+
+    ! Sanity check: do total planet area match between physics and dynamics?
+    total_area_dyn=sum(aire(1:iim,1:jjm+1))
+    total_area_phy=sum(airefi_glo(1:klon_glo))
+    IF (total_area_dyn/=total_area_phy) THEN
+      WRITE (lunout, *) 'inigeomphy: planet total surface discrepancy !!!'
+      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
+      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
+      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
+        ! stop here if the relative difference is more than 0.001%
+        abort_message = 'planet total surface discrepancy'
+        CALL abort_gcm(modname, abort_message, 1)
+      ENDIF
+    ENDIF
+  ELSE ! klon_glo==1, running the 1D model
+    ! just copy over input values
+    latfi_glo(1)=rlatu(1)
+    lonfi_glo(1)=rlonv(1)
+    cufi_glo(1)=cu(1)
+    cvfi_glo(1)=cv(1)
+    airefi_glo(1)=aire(1,1)
+    boundslonfi_glo(1,north_east)=rlonu(1)
+    boundslatfi_glo(1,north_east)=PI/2
+    boundslonfi_glo(1,north_west)=rlonu(2)
+    boundslatfi_glo(1,north_west)=PI/2
+    boundslonfi_glo(1,south_west)=rlonu(2)
+    boundslatfi_glo(1,south_west)=rlatv(1)
+    boundslonfi_glo(1,south_east)=rlonu(1)
+    boundslatfi_glo(1,south_east)=rlatv(1)
+  ENDIF ! of IF (klon_glo>1)
+
+!$OMP PARALLEL 
+  ! Now generate local lon/lat/cu/cv/area/bounds arrays
+  ALLOCATE(latfi(klon_omp),lonfi(klon_omp),cufi(klon_omp),cvfi(klon_omp))
+  ALLOCATE(airefi(klon_omp))
+  ALLOCATE(boundslonfi(klon_omp,4))
+  ALLOCATE(boundslatfi(klon_omp,4))
+
+
+  offset = klon_mpi_begin - 1
+  airefi(1:klon_omp) = airefi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  cufi(1:klon_omp) = cufi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  cvfi(1:klon_omp) = cvfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  lonfi(1:klon_omp) = lonfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  latfi(1:klon_omp) = latfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  boundslonfi(1:klon_omp,:) = boundslonfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
+  boundslatfi(1:klon_omp,:) = boundslatfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
+
+  ! copy over local grid longitudes and latitudes
+  CALL init_geometry(klon_omp,lonfi,latfi,boundslonfi,boundslatfi, &
+                     airefi,cufi,cvfi)
+
+!$OMP END PARALLEL
+
+
+END SUBROUTINE inigeomphy
+
+END MODULE inigeomphy_mod
+
Index: /LMDZ5/branches/testing/libf/dynphy_lonlat/phydev/iniphysiq_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynphy_lonlat/phydev/iniphysiq_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/dynphy_lonlat/phydev/iniphysiq_mod.F90	(revision 2594)
@@ -12,25 +12,10 @@
                      prad,pg,pr,pcpp,iflag_phys)
   USE dimphy, ONLY: init_dimphy
-  USE mod_grid_phy_lmdz, ONLY: klon_glo,  & ! number of atmospheric columns (on full grid)
-                               regular_lonlat  ! regular longitude-latitude grid type
-  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
-                                klon_omp_begin, & ! start index of local omp subgrid
-                                klon_omp_end, & ! end index of local omp subgrid
-                                klon_mpi_begin ! start indes of columns (on local mpi grid)
-  USE geometry_mod, ONLY : init_geometry
+  USE inigeomphy_mod, ONLY: inigeomphy
+  USE mod_phys_lmdz_para, ONLY: klon_omp ! number of columns (on local omp grid)
   USE infotrac, ONLY: nqtot, type_trac
   USE infotrac_phy, ONLY: init_infotrac_phy
-!  USE comcstphy, ONLY: rradius, & ! planet radius (m)
-!                       rr, & ! recuced gas constant: R/molar mass of atm
-!                       rg, & ! gravity
-!                       rcpp  ! specific heat of the atmosphere
   USE inifis_mod, ONLY: inifis
   USE phyaqua_mod, ONLY: iniaqua
-  USE physics_distribution_mod, ONLY : init_physics_distribution
-  USE regular_lonlat_mod, ONLY : init_regular_lonlat, &
-                                 east, west, north, south, &
-                                 north_east, north_west, &
-                                 south_west, south_east
-  USE mod_interface_dyn_phys, ONLY :  init_interface_dyn_phys
   USE nrtype, ONLY: pi
   IMPLICIT NONE
@@ -69,147 +54,17 @@
   CHARACTER (LEN=20) :: modname='iniphysiq'
   CHARACTER (LEN=80) :: abort_message
-  REAL :: total_area_phy, total_area_dyn
 
-  ! boundaries, on global grid
-  REAL,ALLOCATABLE :: boundslon_reg(:,:)
-  REAL,ALLOCATABLE :: boundslat_reg(:,:)
 
-  ! global array, on full physics grid:
-  REAL,ALLOCATABLE :: latfi_glo(:)
-  REAL,ALLOCATABLE :: lonfi_glo(:)
-  REAL,ALLOCATABLE :: cufi_glo(:)
-  REAL,ALLOCATABLE :: cvfi_glo(:)
-  REAL,ALLOCATABLE :: airefi_glo(:)
-  REAL,ALLOCATABLE :: boundslonfi_glo(:,:)
-  REAL,ALLOCATABLE :: boundslatfi_glo(:,:)
+  ! --> initialize physics distribution, global fields and geometry
+  ! (i.e. things in phy_common or dynphy_lonlat)
+  CALL inigeomphy(iim,jjm,nlayer, &
+               nbp, communicator, &
+               rlatu,rlatv, &
+               rlonu,rlonv, &
+               aire,cu,cv)
 
-  ! local arrays, on given MPI/OpenMP domain:
-  REAL,ALLOCATABLE,SAVE :: latfi(:)
-  REAL,ALLOCATABLE,SAVE :: lonfi(:)
-  REAL,ALLOCATABLE,SAVE :: cufi(:)
-  REAL,ALLOCATABLE,SAVE :: cvfi(:)
-  REAL,ALLOCATABLE,SAVE :: airefi(:)
-  REAL,ALLOCATABLE,SAVE :: boundslonfi(:,:)
-  REAL,ALLOCATABLE,SAVE :: boundslatfi(:,:)
-!$OMP THREADPRIVATE (latfi,lonfi,cufi,cvfi,airefi,boundslonfi,boundslatfi)
-
-  ! Initialize Physics distibution and parameters and interface with dynamics
-  CALL init_physics_distribution(regular_lonlat,4, &
-                                 nbp,iim,jjm+1,nlayer,communicator)
-  CALL init_interface_dyn_phys
-  
-  ! init regular global longitude-latitude grid points and boundaries
-  ALLOCATE(boundslon_reg(iim,2))
-  ALLOCATE(boundslat_reg(jjm+1,2))
-  
-  DO i=1,iim
-   boundslon_reg(i,east)=rlonu(i) 
-   boundslon_reg(i,west)=rlonu(i+1) 
-  ENDDO
-
-  boundslat_reg(1,north)= PI/2 
-  boundslat_reg(1,south)= rlatv(1)
-  DO j=2,jjm
-   boundslat_reg(j,north)=rlatv(j-1) 
-   boundslat_reg(j,south)=rlatv(j) 
-  ENDDO
-  boundslat_reg(jjm+1,north)= rlatv(jjm) 
-  boundslat_reg(jjm+1,south)= -PI/2
-
-  ! Write values in module regular_lonlat_mod
-  CALL init_regular_lonlat(iim,jjm+1, rlonv(1:iim), rlatu, &
-                           boundslon_reg, boundslat_reg)
-
-  ! Generate global arrays on full physics grid
-  ALLOCATE(latfi_glo(klon_glo),lonfi_glo(klon_glo))
-  ALLOCATE(cufi_glo(klon_glo),cvfi_glo(klon_glo))
-  ALLOCATE(airefi_glo(klon_glo))
-  ALLOCATE(boundslonfi_glo(klon_glo,4))
-  ALLOCATE(boundslatfi_glo(klon_glo,4))
-
-    ! North pole
-    latfi_glo(1)=rlatu(1)
-    lonfi_glo(1)=0.
-    cufi_glo(1) = cu(1)
-    cvfi_glo(1) = cv(1)
-    boundslonfi_glo(1,north_east)=0
-    boundslatfi_glo(1,north_east)=PI/2
-    boundslonfi_glo(1,north_west)=2*PI
-    boundslatfi_glo(1,north_west)=PI/2
-    boundslonfi_glo(1,south_west)=2*PI
-    boundslatfi_glo(1,south_west)=rlatv(1)
-    boundslonfi_glo(1,south_east)=0
-    boundslatfi_glo(1,south_east)=rlatv(1)
-    DO j=2,jjm
-      DO i=1,iim
-        k=(j-2)*iim+1+i
-        latfi_glo(k)= rlatu(j)
-        lonfi_glo(k)= rlonv(i)
-        cufi_glo(k) = cu((j-1)*(iim+1)+i)
-        cvfi_glo(k) = cv((j-1)*(iim+1)+i)
-        boundslonfi_glo(k,north_east)=rlonu(i)
-        boundslatfi_glo(k,north_east)=rlatv(j-1)
-        boundslonfi_glo(k,north_west)=rlonu(i+1)
-        boundslatfi_glo(k,north_west)=rlatv(j-1)
-        boundslonfi_glo(k,south_west)=rlonu(i+1)
-        boundslatfi_glo(k,south_west)=rlatv(j)
-        boundslonfi_glo(k,south_east)=rlonu(i)
-        boundslatfi_glo(k,south_east)=rlatv(j)
-      ENDDO
-    ENDDO
-    ! South pole
-    latfi_glo(klon_glo)= rlatu(jjm+1)
-    lonfi_glo(klon_glo)= 0.
-    cufi_glo(klon_glo) = cu((iim+1)*jjm+1)
-    cvfi_glo(klon_glo) = cv((iim+1)*jjm-iim)
-    boundslonfi_glo(klon_glo,north_east)= 0
-    boundslatfi_glo(klon_glo,north_east)= rlatv(jjm)
-    boundslonfi_glo(klon_glo,north_west)= 2*PI
-    boundslatfi_glo(klon_glo,north_west)= rlatv(jjm)
-    boundslonfi_glo(klon_glo,south_west)= 2*PI
-    boundslatfi_glo(klon_glo,south_west)= -PI/2
-    boundslonfi_glo(klon_glo,south_east)= 0
-    boundslatfi_glo(klon_glo,south_east)= -Pi/2
-
-    ! build airefi(), mesh area on physics grid
-    CALL gr_dyn_fi(1,iim+1,jjm+1,klon_glo,aire,airefi_glo)
-    ! Poles are single points on physics grid
-    airefi_glo(1)=sum(aire(1:iim,1))
-    airefi_glo(klon_glo)=sum(aire(1:iim,jjm+1))
-
-    ! Sanity check: do total planet area match between physics and dynamics?
-    total_area_dyn=sum(aire(1:iim,1:jjm+1))
-    total_area_phy=sum(airefi_glo(1:klon_glo))
-    IF (total_area_dyn/=total_area_phy) THEN
-      WRITE (lunout, *) 'iniphysiq: planet total surface discrepancy !!!'
-      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
-      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
-      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
-        ! stop here if the relative difference is more than 0.001%
-        abort_message = 'planet total surface discrepancy'
-        CALL abort_gcm(modname, abort_message, 1)
-      ENDIF
-    ENDIF
+  ! --> now initialize things specific to the phydev physics package
 
 !$OMP PARALLEL 
-  ! Now generate local lon/lat/cu/cv/area/bounds arrays
-  ALLOCATE(latfi(klon_omp),lonfi(klon_omp),cufi(klon_omp),cvfi(klon_omp))
-  ALLOCATE(airefi(klon_omp))
-  ALLOCATE(boundslonfi(klon_omp,4))
-  ALLOCATE(boundslatfi(klon_omp,4))
-
-
-  offset = klon_mpi_begin - 1
-  airefi(1:klon_omp) = airefi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  cufi(1:klon_omp) = cufi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  cvfi(1:klon_omp) = cvfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  lonfi(1:klon_omp) = lonfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  latfi(1:klon_omp) = latfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  boundslonfi(1:klon_omp,:) = boundslonfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
-  boundslatfi(1:klon_omp,:) = boundslatfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
-
-  ! copy over local grid longitudes and latitudes
-  CALL init_geometry(klon_omp,lonfi,latfi,boundslonfi,boundslatfi, &
-                     airefi,cufi,cvfi)
 
   ! Initialize physical constants in physics:
Index: /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90	(revision 2594)
@@ -12,12 +12,7 @@
                      prad,pg,pr,pcpp,iflag_phys)
   USE dimphy, ONLY: init_dimphy
-  USE mod_grid_phy_lmdz, ONLY: klon_glo,  & ! number of atmospheric columns (on full grid)
-                               regular_lonlat, &  ! regular longitude-latitude grid type
-                               nbp_lon, nbp_lat, nbp_lev
-  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
-                                klon_omp_begin, & ! start index of local omp subgrid
-                                klon_omp_end, & ! end index of local omp subgrid
-                                klon_mpi_begin ! start indes of columns (on local mpi grid)
-  USE geometry_mod, ONLY : init_geometry
+  USE inigeomphy_mod, ONLY: inigeomphy
+  USE mod_grid_phy_lmdz, ONLY: klon_glo ! number of atmospheric columns (on full grid)
+  USE mod_phys_lmdz_para, ONLY: klon_omp ! number of columns (on local omp grid)
   USE vertical_layers_mod, ONLY : init_vertical_layers
   USE infotrac, ONLY: nqtot,nqo,nbtr,tname,ttext,type_trac,&
@@ -39,10 +34,4 @@
   USE phystokenc_mod, ONLY: init_phystokenc
   USE phyaqua_mod, ONLY: iniaqua
-  USE physics_distribution_mod, ONLY : init_physics_distribution
-  USE regular_lonlat_mod, ONLY : init_regular_lonlat, &
-                                 east, west, north, south, &
-                                 north_east, north_west, &
-                                 south_west, south_east
-  USE mod_interface_dyn_phys, ONLY :  init_interface_dyn_phys
 #ifdef INCA
   USE indice_sol_mod, ONLY: nbsrf, is_oce, is_sic, is_ter, is_lic
@@ -92,28 +81,5 @@
   CHARACTER (LEN=20) :: modname = 'iniphysiq'
   CHARACTER (LEN=80) :: abort_message
-  REAL :: total_area_phy, total_area_dyn
 
-  ! boundaries, on global grid
-  REAL,ALLOCATABLE :: boundslon_reg(:,:)
-  REAL,ALLOCATABLE :: boundslat_reg(:,:)
-
-  ! global array, on full physics grid:
-  REAL,ALLOCATABLE :: latfi_glo(:)
-  REAL,ALLOCATABLE :: lonfi_glo(:)
-  REAL,ALLOCATABLE :: cufi_glo(:)
-  REAL,ALLOCATABLE :: cvfi_glo(:)
-  REAL,ALLOCATABLE :: airefi_glo(:)
-  REAL,ALLOCATABLE :: boundslonfi_glo(:,:)
-  REAL,ALLOCATABLE :: boundslatfi_glo(:,:)
-
-  ! local arrays, on given MPI/OpenMP domain:
-  REAL,ALLOCATABLE,SAVE :: latfi(:)
-  REAL,ALLOCATABLE,SAVE :: lonfi(:)
-  REAL,ALLOCATABLE,SAVE :: cufi(:)
-  REAL,ALLOCATABLE,SAVE :: cvfi(:)
-  REAL,ALLOCATABLE,SAVE :: airefi(:)
-  REAL,ALLOCATABLE,SAVE :: boundslonfi(:,:)
-  REAL,ALLOCATABLE,SAVE :: boundslatfi(:,:)
-!$OMP THREADPRIVATE (latfi,lonfi,cufi,cvfi,airefi,boundslonfi,boundslatfi)
 
 #ifndef CPP_PARA
@@ -123,145 +89,15 @@
 #endif
 
-  ! Initialize Physics distibution and parameters and interface with dynamics
-  IF (ii*jj>1) THEN ! general 3D case
-    CALL init_physics_distribution(regular_lonlat,4, &
-                                 nbp,ii,jj+1,nlayer,communicator)
-  ELSE ! For 1D model
-    CALL init_physics_distribution(regular_lonlat,4, &
-                                 1,1,1,nlayer,communicator)  
-  ENDIF
-  CALL init_interface_dyn_phys
+  ! --> initialize physics distribution, global fields and geometry
+  ! (i.e. things in phy_common or dynphy_lonlat)
+  CALL inigeomphy(ii,jj,nlayer, &
+               nbp, communicator, &
+               rlatu,rlatv, &
+               rlonu,rlonv, &
+               aire,cu,cv)
+
+  ! --> now initialize things specific to the phylmd physics package
   
-  ! init regular global longitude-latitude grid points and boundaries
-  ALLOCATE(boundslon_reg(ii,2))
-  ALLOCATE(boundslat_reg(jj+1,2))
-  
-  DO i=1,ii
-   boundslon_reg(i,east)=rlonu(i) 
-   boundslon_reg(i,west)=rlonu(i+1) 
-  ENDDO
-
-  boundslat_reg(1,north)= PI/2 
-  boundslat_reg(1,south)= rlatv(1)
-  DO j=2,jj
-   boundslat_reg(j,north)=rlatv(j-1) 
-   boundslat_reg(j,south)=rlatv(j) 
-  ENDDO
-  boundslat_reg(jj+1,north)= rlatv(jj) 
-  boundslat_reg(jj+1,south)= -PI/2
-
-  ! Write values in module regular_lonlat_mod
-  CALL init_regular_lonlat(ii,jj+1, rlonv(1:ii), rlatu, &
-                           boundslon_reg, boundslat_reg)
-
-  ! Generate global arrays on full physics grid
-  ALLOCATE(latfi_glo(klon_glo),lonfi_glo(klon_glo))
-  ALLOCATE(cufi_glo(klon_glo),cvfi_glo(klon_glo))
-  ALLOCATE(airefi_glo(klon_glo))
-  ALLOCATE(boundslonfi_glo(klon_glo,4))
-  ALLOCATE(boundslatfi_glo(klon_glo,4))
-  
-
-  IF (klon_glo>1) THEN ! general case
-    ! North pole
-    latfi_glo(1)=rlatu(1)
-    lonfi_glo(1)=0.
-    cufi_glo(1) = cu(1)
-    cvfi_glo(1) = cv(1)
-    boundslonfi_glo(1,north_east)=0
-    boundslatfi_glo(1,north_east)=PI/2
-    boundslonfi_glo(1,north_west)=2*PI
-    boundslatfi_glo(1,north_west)=PI/2
-    boundslonfi_glo(1,south_west)=2*PI
-    boundslatfi_glo(1,south_west)=rlatv(1)
-    boundslonfi_glo(1,south_east)=0
-    boundslatfi_glo(1,south_east)=rlatv(1)
-    DO j=2,jj
-      DO i=1,ii
-        k=(j-2)*ii+1+i
-        latfi_glo(k)= rlatu(j)
-        lonfi_glo(k)= rlonv(i)
-        cufi_glo(k) = cu((j-1)*(ii+1)+i)
-        cvfi_glo(k) = cv((j-1)*(ii+1)+i)
-        boundslonfi_glo(k,north_east)=rlonu(i)
-        boundslatfi_glo(k,north_east)=rlatv(j-1)
-        boundslonfi_glo(k,north_west)=rlonu(i+1)
-        boundslatfi_glo(k,north_west)=rlatv(j-1)
-        boundslonfi_glo(k,south_west)=rlonu(i+1)
-        boundslatfi_glo(k,south_west)=rlatv(j)
-        boundslonfi_glo(k,south_east)=rlonu(i)
-        boundslatfi_glo(k,south_east)=rlatv(j)
-      ENDDO
-    ENDDO
-    ! South pole
-    latfi_glo(klon_glo)= rlatu(jj+1)
-    lonfi_glo(klon_glo)= 0.
-    cufi_glo(klon_glo) = cu((ii+1)*jj+1)
-    cvfi_glo(klon_glo) = cv((ii+1)*jj-ii)
-    boundslonfi_glo(klon_glo,north_east)= 0
-    boundslatfi_glo(klon_glo,north_east)= rlatv(jj)
-    boundslonfi_glo(klon_glo,north_west)= 2*PI
-    boundslatfi_glo(klon_glo,north_west)= rlatv(jj)
-    boundslonfi_glo(klon_glo,south_west)= 2*PI
-    boundslatfi_glo(klon_glo,south_west)= -PI/2
-    boundslonfi_glo(klon_glo,south_east)= 0
-    boundslatfi_glo(klon_glo,south_east)= -Pi/2
-
-    ! build airefi_glo(), mesh area on physics grid
-    CALL gr_dyn_fi(1,ii+1,jj+1,klon_glo,aire,airefi_glo)
-    ! Poles are single points on physics grid
-    airefi_glo(1)=sum(aire(1:ii,1))
-    airefi_glo(klon_glo)=sum(aire(1:ii,jj+1))
-
-    ! Sanity check: do total planet area match between physics and dynamics?
-    total_area_dyn=sum(aire(1:ii,1:jj+1))
-    total_area_phy=sum(airefi_glo(1:klon_glo))
-    IF (total_area_dyn/=total_area_phy) THEN
-      WRITE (lunout, *) 'iniphysiq: planet total surface discrepancy !!!'
-      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
-      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
-      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
-        ! stop here if the relative difference is more than 0.001%
-        abort_message = 'planet total surface discrepancy'
-        CALL abort_gcm(modname, abort_message, 1)
-      ENDIF
-    ENDIF
-  ELSE ! klon_glo==1, running the 1D model
-    ! just copy over input values
-    latfi_glo(1)=rlatu(1)
-    lonfi_glo(1)=rlonv(1)
-    cufi_glo(1)=cu(1)
-    cvfi_glo(1)=cv(1)
-    airefi_glo(1)=aire(1,1)
-    boundslonfi_glo(1,north_east)=rlonu(1)
-    boundslatfi_glo(1,north_east)=PI/2
-    boundslonfi_glo(1,north_west)=rlonu(2)
-    boundslatfi_glo(1,north_west)=PI/2
-    boundslonfi_glo(1,south_west)=rlonu(2)
-    boundslatfi_glo(1,south_west)=rlatv(1)
-    boundslonfi_glo(1,south_east)=rlonu(1)
-    boundslatfi_glo(1,south_east)=rlatv(1)
-  ENDIF ! of IF (klon_glo>1)
-
 !$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/)
-  ! Now generate local lon/lat/cu/cv/area/bounds arrays
-  ALLOCATE(latfi(klon_omp),lonfi(klon_omp),cufi(klon_omp),cvfi(klon_omp))
-  ALLOCATE(airefi(klon_omp))
-  ALLOCATE(boundslonfi(klon_omp,4))
-  ALLOCATE(boundslatfi(klon_omp,4))
-
-
-  offset = klon_mpi_begin - 1
-  airefi(1:klon_omp) = airefi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  cufi(1:klon_omp) = cufi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  cvfi(1:klon_omp) = cvfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  lonfi(1:klon_omp) = lonfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  latfi(1:klon_omp) = latfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  boundslonfi(1:klon_omp,:) = boundslonfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
-  boundslatfi(1:klon_omp,:) = boundslatfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
-
-  ! copy over local grid longitudes and latitudes
-  CALL init_geometry(klon_omp,lonfi,latfi,boundslonfi,boundslatfi, &
-                     airefi,cufi,cvfi)
 
   ! copy over preff , ap(), bp(), etc 
Index: /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/limit_netcdf.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/limit_netcdf.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/dynphy_lonlat/phylmd/limit_netcdf.F90	(revision 2594)
@@ -117,4 +117,7 @@
     ALLOCATE(pctsrf(klon,nbsrf))
     CALL start_init_subsurf(.FALSE.)
+  !--- TO MATCH EXACTLY WHAT WOULD BE DONE IN etat0phys_netcdf
+    WHERE(   masque(:,:)<EPSFRA) masque(:,:)=0.
+    WHERE(1.-masque(:,:)<EPSFRA) masque(:,:)=1.
   END IF
 
@@ -336,4 +339,5 @@
   REAL, ALLOCATABLE :: champan(:,:,:)
 !--- input files
+  CHARACTER(LEN=20) :: fnam_m, fnam_p     ! previous/next files names
   CHARACTER(LEN=20) :: cal_in             ! calendar
   CHARACTER(LEN=20) :: unit_sic           ! attribute unit in sea-ice file
@@ -345,5 +349,5 @@
   LOGICAL           :: extrp              ! flag for extrapolation
   REAL              :: chmin, chmax
-  INTEGER ierr
+  INTEGER ierr, idx
   integer n_extrap ! number of extrapolated points
   logical skip
@@ -360,4 +364,5 @@
   END SELECT
   extrp=.FALSE.; IF(PRESENT(flag).AND.mode=='SST') extrp=flag
+  idx=INDEX(fnam,'.nc')-1
 
 !--- GETTING SOME DIMENSIONAL VARIABLES FROM FILE -----------------------------
@@ -393,5 +398,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(MAX(lmdep,14)))
+  ALLOCATE(timeyear(lmdep+2))
   CALL ncerr(NF90_INQ_VARID(ncid, dnam, varid), fnam)
   cal_in=' '
@@ -412,19 +417,16 @@
   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).')
+    CALL msg(0,'Monthly input file(s) for '//TRIM(title)//'.')
   ELSE IF(lmdep==ndays_in) THEN
-    timeyear=[(REAL(k)-0.5,k=1,ndays_in)]
+    timeyear=[(REAL(k)-0.5,k=0,ndays_in+1)]
     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'
+      ' records, 12/',ndays_in,' (monthly/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, MAX(lmdep,14)))
+  ALLOCATE(champ(imdep, jmdep), champtime(iim, jjp1, lmdep+2))
   IF(extrp) ALLOCATE(work(imdep, jmdep))
   CALL msg(5,'')
@@ -446,14 +448,51 @@
       WHERE(NINT(mask)/=1) champint=0.001
     END IF
-    !--- Special case for periodic input file: index shifted
-    ll = l; IF(lmdep==12) ll = l + 1
-    champtime(:, :, ll)=champint
+    champtime(:, :, l+1)=champint
   END DO
-  IF(lmdep==12) THEN
-    champtime(:,:, 1)=champtime(:,:,13)
-    champtime(:,:,14)=champtime(:,:, 2)
-  END IF
   CALL ncerr(NF90_CLOSE(ncid), fnam)
 
+!--- FIRST RECORD: LAST ONE OF PREVIOUS YEAR (CURRENT YEAR IF UNAVAILABLE)
+  fnam_m=fnam(1:idx)//'_m.nc'
+  IF(NF90_OPEN(fnam_m,NF90_NOWRITE,ncid)==NF90_NOERR) THEN
+    CALL msg(0,'Reading previous year file ("'//TRIM(fnam_m)//'") last record for '//TRIM(title))
+    CALL ncerr(NF90_INQ_VARID(ncid, varname, varid),fnam_m)
+    CALL ncerr(NF90_INQUIRE_VARIABLE(ncid, varid, dimids=dids),fnam_m)
+    CALL ncerr(NF90_INQUIRE_DIMENSION(ncid, dids(3), len=l), fnam_m)
+    CALL ncerr(NF90_GET_VAR(ncid,varid,champ,[1,1,l],[imdep,jmdep,1]),fnam_m)
+    CALL ncerr(NF90_CLOSE(ncid), fnam_m)
+    CALL conf_dat2d(title, dlon_ini, dlat_ini, dlon, dlat, champ, .TRUE.)
+    IF(extrp) CALL extrapol(champ,imdep,jmdep,999999.,.TRUE.,.TRUE.,2,work)
+    IF(mode=='RUG') champ=LOG(champ)
+    CALL inter_barxy(dlon,dlat(:jmdep-1),champ,rlonu(:iim),rlatv,champint)
+    IF(mode=='RUG') THEN
+      champint=EXP(champint)
+      WHERE(NINT(mask)/=1) champint=0.001
+    END IF
+    champtime(:, :, 1)=champint
+  ELSE
+    CALL msg(0,'Using current year file ("'//TRIM(fnam)//'") last record for '//TRIM(title))
+    champtime(:, :, 1)=champtime(:, :, lmdep+1)
+  END IF
+
+!--- LAST RECORD: FIRST ONE OF NEXT YEAR (CURRENT YEAR IF UNAVAILABLE)
+  fnam_p=fnam(1:idx)//'_p.nc'
+  IF(NF90_OPEN(fnam_p,NF90_NOWRITE,ncid)==NF90_NOERR) THEN
+    CALL msg(0,'Reading previous year file ("'//TRIM(fnam_p)//'") first record for '//TRIM(title))
+    CALL ncerr(NF90_INQ_VARID(ncid, varname, varid),fnam_p)
+    CALL ncerr(NF90_GET_VAR(ncid,varid,champ,[1,1,1],[imdep,jmdep,1]),fnam_p)
+    CALL ncerr(NF90_CLOSE(ncid), fnam_p)
+    CALL conf_dat2d(title, dlon_ini, dlat_ini, dlon, dlat, champ, .TRUE.)
+    IF(extrp) CALL extrapol(champ,imdep,jmdep,999999.,.TRUE.,.TRUE.,2,work)
+    IF(mode=='RUG') champ=LOG(champ)
+    CALL inter_barxy(dlon,dlat(:jmdep-1),champ,rlonu(:iim),rlatv,champint)
+    IF(mode=='RUG') THEN
+      champint=EXP(champint)
+      WHERE(NINT(mask)/=1) champint=0.001
+    END IF
+    champtime(:, :, lmdep+2)=champint
+  ELSE
+    CALL msg(0,'Using current year file ("'//TRIM(fnam)//'") first record for '//TRIM(title))
+    champtime(:, :, lmdep+2)=champtime(:, :, 2)
+  END IF
   DEALLOCATE(dlon_ini, dlat_ini, dlon, dlat, champ)
   IF(extrp) DEALLOCATE(work)
@@ -477,5 +516,5 @@
      END IF
   END IF
-  ALLOCATE(yder(MAX(lmdep,14)), champan(iip1, jjp1, ndays))
+  ALLOCATE(yder(lmdep+2), champan(iip1, jjp1, ndays))
   IF(lmdep==ndays_in) THEN
      champan(1:iim,:,:)=champtime
@@ -546,4 +585,5 @@
 !
 !-------------------------------------------------------------------------------
+  USE grid_noro_m, ONLY: grid_noro0
   IMPLICIT NONE
 !===============================================================================
@@ -599,147 +639,4 @@
 
 END SUBROUTINE start_init_orog0
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE grid_noro0(xd,yd,zd,x,y,zphi,mask)
-!
-!===============================================================================
-! Purpose: Extracted from grid_noro to provide geopotential height for dynamics
-!          without any call to physics subroutines.
-!===============================================================================
-  IMPLICIT NONE 
-!-------------------------------------------------------------------------------
-! Arguments:
-  REAL, INTENT(IN)   :: xd(:), yd(:) !--- INPUT  COORDINATES     (imdp) (jmdp)
-  REAL, INTENT(IN)   :: zd(:,:)      !--- INPUT  FIELD           (imdp,jmdp)
-  REAL, INTENT(IN)   :: x(:), y(:)   !--- OUTPUT COORDINATES     (imar+1) (jmar)
-  REAL, INTENT(OUT)  :: zphi(:,:)    !--- GEOPOTENTIAL           (imar+1,jmar)
-  REAL, INTENT(INOUT):: mask(:,:)    !--- MASK                   (imar+1,jmar)
-!-------------------------------------------------------------------------------
-! Local variables:
-  CHARACTER(LEN=256) :: modname="grid_noro0"
-  REAL, ALLOCATABLE :: xusn(:), yusn(:)           ! dim (imdp+2*iext) (jmdp+2)
-  REAL, ALLOCATABLE :: zusn(:,:)                  ! dim (imdp+2*iext,jmdp+2)
-  REAL, ALLOCATABLE :: weight(:,:)                ! dim (imar+1,jmar)
-  REAL, ALLOCATABLE :: mask_tmp(:,:), zmea(:,:)   ! dim (imar+1,jmar)
-  REAL, ALLOCATABLE :: num_tot(:,:), num_lan(:,:) ! dim (imax,jmax)
-  REAL, ALLOCATABLE :: a(:), b(:)                 ! dim (imax)
-  REAL, ALLOCATABLE :: c(:), d(:)                 ! dim (jmax)
-  LOGICAL :: masque_lu
-  INTEGER :: i, ii, imdp, imar, iext
-  INTEGER :: j, jj, jmdp, jmar, nn
-  REAL    :: xpi, zlenx, weighx, xincr,  zbordnor, zmeanor, zweinor, zbordest
-  REAL    :: rad, zleny, weighy, masque, zbordsud, zmeasud, zweisud, zbordoue
-!-------------------------------------------------------------------------------
-  imdp=assert_eq(SIZE(xd),SIZE(zd,1),TRIM(modname)//" imdp")
-  jmdp=assert_eq(SIZE(yd),SIZE(zd,2),TRIM(modname)//" jmdp")
-  imar=assert_eq(SIZE(x),SIZE(zphi,1),SIZE(mask,1),TRIM(modname)//" imar")-1
-  jmar=assert_eq(SIZE(y),SIZE(zphi,2),SIZE(mask,2),TRIM(modname)//" jmar")
-  IF(imar/=iim)   CALL abort_gcm(TRIM(modname),'imar/=iim'  ,1)
-  IF(jmar/=jjm+1) CALL abort_gcm(TRIM(modname),'jmar/=jjm+1',1)
-  iext=imdp/10
-  xpi = ACOS(-1.)
-  rad = 6371229.
-
-!--- ARE WE USING A READ MASK ?
-  masque_lu=ANY(mask/=-99999.); IF(.NOT.masque_lu) mask=0.0
-  WRITE(lunout,*)'Masque lu: ',masque_lu
-
-!--- EXTENSION OF THE INPUT DATABASE TO PROCEED COMPUTATIONS AT BOUNDARIES:
-  ALLOCATE(xusn(imdp+2*iext))
-  xusn(1     +iext:imdp  +iext)=xd(:)
-  xusn(1          :       iext)=xd(1+imdp-iext:imdp)-2.*xpi
-  xusn(1+imdp+iext:imdp+2*iext)=xd(1          :iext)+2.*xpi
-
-  ALLOCATE(yusn(jmdp+2))
-  yusn(1       )=yd(1)   +(yd(1)   -yd(2))
-  yusn(2:jmdp+1)=yd(:)
-  yusn(  jmdp+2)=yd(jmdp)+(yd(jmdp)-yd(jmdp-1))
-
-  ALLOCATE(zusn(imdp+2*iext,jmdp+2))
-  zusn(1       +iext:imdp  +iext,2:jmdp+1)=zd  (:                   ,     :)
-  zusn(1            :       iext,2:jmdp+1)=zd  (imdp-iext+1:imdp    ,     :)
-  zusn(1+imdp  +iext:imdp+2*iext,2:jmdp+1)=zd  (1:iext              ,     :)
-  zusn(1            :imdp/2+iext,       1)=zusn(1+imdp/2:imdp  +iext,     2)
-  zusn(1+imdp/2+iext:imdp+2*iext,       1)=zusn(1       :imdp/2+iext,     2)
-  zusn(1            :imdp/2+iext,  jmdp+2)=zusn(1+imdp/2:imdp  +iext,jmdp+1)
-  zusn(1+imdp/2+iext:imdp+2*iext,  jmdp+2)=zusn(1       :imdp/2+iext,jmdp+1)
-
-!--- COMPUTE LIMITS OF MODEL GRIDPOINT AREA (REGULAR GRID)
-  ALLOCATE(a(imar+1),b(imar+1))
-  b(1:imar)=(x(1:imar  )+ x(2:imar+1))/2.0
-  b(imar+1)= x(  imar+1)+(x(  imar+1)-x(imar))/2.0
-  a(1)=x(1)-(x(2)-x(1))/2.0
-  a(2:imar+1)= b(1:imar)
-
-  ALLOCATE(c(jmar),d(jmar))
-  d(1:jmar-1)=(y(1:jmar-1)+ y(2:jmar))/2.0
-  d(  jmar  )= y(  jmar  )+(y(  jmar)-y(jmar-1))/2.0
-  c(1)=y(1)-(y(2)-y(1))/2.0
-  c(2:jmar)=d(1:jmar-1)
-
-!--- INITIALIZATIONS:
-  ALLOCATE(weight(imar+1,jmar)); weight(:,:)= 0.0
-  ALLOCATE(zmea  (imar+1,jmar)); zmea  (:,:)= 0.0
-
-!--- SUMMATION OVER GRIDPOINT AREA
-  zleny=xpi/REAL(jmdp)*rad
-  xincr=xpi/REAL(jmdp)/2.
-  ALLOCATE(num_tot(imar+1,jmar)); num_tot(:,:)=0.
-  ALLOCATE(num_lan(imar+1,jmar)); num_lan(:,:)=0.
-  DO ii = 1, imar+1
-    DO jj = 1, jmar
-      DO j = 2,jmdp+1 
-        zlenx  =zleny  *COS(yusn(j))
-        zbordnor=(xincr+c(jj)-yusn(j))*rad
-        zbordsud=(xincr-d(jj)+yusn(j))*rad
-        weighy=AMAX1(0.,AMIN1(zbordnor,zbordsud,zleny))
-        IF(weighy/=0) THEN
-          DO i = 2, imdp+2*iext-1
-            zbordest=(xusn(i)-a(ii)+xincr)*rad*COS(yusn(j))
-            zbordoue=(b(ii)+xincr-xusn(i))*rad*COS(yusn(j))
-            weighx=AMAX1(0.,AMIN1(zbordest,zbordoue,zlenx))
-            IF(weighx/=0)THEN
-              num_tot(ii,jj)=num_tot(ii,jj)+1.0
-              IF(zusn(i,j)>=1.)num_lan(ii,jj)=num_lan(ii,jj)+1.0
-              weight(ii,jj)=weight(ii,jj)+weighx*weighy
-              zmea  (ii,jj)=zmea  (ii,jj)+zusn(i,j)*weighx*weighy !--- MEAN
-            END IF
-          END DO
-        END IF
-      END DO
-    END DO
-  END DO
-
-!--- COMPUTE PARAMETERS NEEDED BY LOTT & MILLER (1997) AND LOTT (1999) SSO SCHEME
-  IF(.NOT.masque_lu) THEN
-    WHERE(weight(:,1:jmar-1)/=0.0) mask=num_lan(:,:)/num_tot(:,:)
-  END IF
-  nn=COUNT(weight(:,1:jmar-1)==0.0)
-  IF(nn/=0) WRITE(lunout,*)'Problem with weight ; vanishing occurrences: ',nn
-  WHERE(weight/=0.0) zmea(:,:)=zmea(:,:)/weight(:,:)
-
-!--- MASK BASED ON GROUND MAXIMUM, 10% THRESHOLD (<10%: SURF PARAMS MEANINGLESS)
-  ALLOCATE(mask_tmp(imar+1,jmar)); mask_tmp(:,:)=0.0
-  WHERE(mask>=0.1) mask_tmp = 1.
-  WHERE(weight(:,:)/=0.0)
-    zphi(:,:)=mask_tmp(:,:)*zmea(:,:)
-    zmea(:,:)=mask_tmp(:,:)*zmea(:,:)
-  END WHERE
-  WRITE(lunout,*)'  MEAN ORO:' ,MAXVAL(zmea)
-
-!--- Values at poles
-  zphi(imar+1,:)=zphi(1,:)
-
-  zweinor=SUM(weight(1:imar,   1),DIM=1)
-  zweisud=SUM(weight(1:imar,jmar),DIM=1)
-  zmeanor=SUM(weight(1:imar,   1)*zmea(1:imar,   1),DIM=1)
-  zmeasud=SUM(weight(1:imar,jmar)*zmea(1:imar,jmar),DIM=1)
-  zphi(:,1)=zmeanor/zweinor; zphi(:,jmar)=zmeasud/zweisud
-
-END SUBROUTINE grid_noro0
 !
 !-------------------------------------------------------------------------------
Index: /LMDZ5/branches/testing/libf/dynphy_lonlat/phymar/iniphysiq_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynphy_lonlat/phymar/iniphysiq_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/dynphy_lonlat/phymar/iniphysiq_mod.F90	(revision 2594)
@@ -12,11 +12,5 @@
                      prad,pg,pr,pcpp,iflag_phys)
   USE dimphy, ONLY: init_dimphy
-  USE mod_grid_phy_lmdz, ONLY: klon_glo,  & ! number of atmospheric columns (on full grid)
-                               regular_lonlat  ! regular longitude-latitude grid type
-  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
-                                klon_omp_begin, & ! start index of local omp subgrid
-                                klon_omp_end, & ! end index of local omp subgrid
-                                klon_mpi_begin ! start indes of columns (on local mpi grid)
-  USE geometry_mod, ONLY : init_geometry
+  USE inigeomphy_mod, ONLY: inigeomphy
   USE infotrac, ONLY: nqtot
   USE comcstphy, ONLY: rradius, & ! planet radius (m)
@@ -24,11 +18,4 @@
                        rg, & ! gravity
                        rcpp  ! specific heat of the atmosphere
-!  USE phyaqua_mod, ONLY: iniaqua
-  USE physics_distribution_mod, ONLY : init_physics_distribution
-  USE regular_lonlat_mod, ONLY : init_regular_lonlat, &
-                                 east, west, north, south, &
-                                 north_east, north_west, &
-                                 south_west, south_east
-  USE mod_interface_dyn_phys, ONLY :  init_interface_dyn_phys
   USE infotrac_phy, ONLY: init_infotrac_phy
   USE nrtype, ONLY: pi
@@ -68,165 +55,17 @@
   CHARACTER (LEN=20) :: modname='iniphysiq'
   CHARACTER (LEN=80) :: abort_message
-  REAL :: total_area_phy, total_area_dyn
-
-  ! boundaries, on global grid
-  REAL,ALLOCATABLE :: boundslon_reg(:,:)
-  REAL,ALLOCATABLE :: boundslat_reg(:,:)
-
-  ! global array, on full physics grid:
-  REAL,ALLOCATABLE :: latfi_glo(:)
-  REAL,ALLOCATABLE :: lonfi_glo(:)
-  REAL,ALLOCATABLE :: cufi_glo(:)
-  REAL,ALLOCATABLE :: cvfi_glo(:)
-  REAL,ALLOCATABLE :: airefi_glo(:)
-  REAL,ALLOCATABLE :: boundslonfi_glo(:,:)
-  REAL,ALLOCATABLE :: boundslatfi_glo(:,:)
-
-  ! local arrays, on given MPI/OpenMP domain:
-  REAL,ALLOCATABLE,SAVE :: latfi(:)
-  REAL,ALLOCATABLE,SAVE :: lonfi(:)
-  REAL,ALLOCATABLE,SAVE :: cufi(:)
-  REAL,ALLOCATABLE,SAVE :: cvfi(:)
-  REAL,ALLOCATABLE,SAVE :: airefi(:)
-  REAL,ALLOCATABLE,SAVE :: boundslonfi(:,:)
-  REAL,ALLOCATABLE,SAVE :: boundslatfi(:,:)
-!$OMP THREADPRIVATE (latfi,lonfi,cufi,cvfi,airefi,boundslonfi,boundslatfi)
-
-  ! Initialize Physics distibution and parameters and interface with dynamics
-  CALL init_physics_distribution(regular_lonlat,4, &
-                                 nbp,ii,jj+1,nlayer,communicator)
-  CALL init_interface_dyn_phys
-  
-  ! init regular global longitude-latitude grid points and boundaries
-  ALLOCATE(boundslon_reg(ii,2))
-  ALLOCATE(boundslat_reg(jj+1,2))
-  
-  DO i=1,ii
-   boundslon_reg(i,east)=rlonu(i) 
-   boundslon_reg(i,west)=rlonu(i+1) 
-  ENDDO
-
-  boundslat_reg(1,north)= PI/2 
-  boundslat_reg(1,south)= rlatv(1)
-  DO j=2,jj
-   boundslat_reg(j,north)=rlatv(j-1) 
-   boundslat_reg(j,south)=rlatv(j) 
-  ENDDO
-  boundslat_reg(jj+1,north)= rlatv(jj) 
-  boundslat_reg(jj+1,south)= -PI/2
-
-  ! Write values in module regular_lonlat_mod
-  CALL init_regular_lonlat(ii,jj+1, rlonv(1:ii), rlatu, &
-                           boundslon_reg, boundslat_reg)
-
-  ! Generate global arrays on full physics grid
-  ALLOCATE(latfi_glo(klon_glo),lonfi_glo(klon_glo))
-  ALLOCATE(cufi_glo(klon_glo),cvfi_glo(klon_glo))
-  ALLOCATE(airefi_glo(klon_glo))
-  ALLOCATE(boundslonfi_glo(klon_glo,4))
-  ALLOCATE(boundslatfi_glo(klon_glo,4))
-
-  IF (klon_glo>1) THEN ! general case
-    ! North pole
-    latfi_glo(1)=rlatu(1)
-    lonfi_glo(1)=0.
-    cufi_glo(1) = cu(1)
-    cvfi_glo(1) = cv(1)
-    boundslonfi_glo(1,north_east)=0
-    boundslatfi_glo(1,north_east)=PI/2
-    boundslonfi_glo(1,north_west)=2*PI
-    boundslatfi_glo(1,north_west)=PI/2
-    boundslonfi_glo(1,south_west)=2*PI
-    boundslatfi_glo(1,south_west)=rlatv(1)
-    boundslonfi_glo(1,south_east)=0
-    boundslatfi_glo(1,south_east)=rlatv(1)
-    DO j=2,jj
-      DO i=1,ii
-        k=(j-2)*ii+1+i
-        latfi_glo((j-2)*ii+1+i)= rlatu(j)
-        lonfi_glo((j-2)*ii+1+i)= rlonv(i)
-        cufi_glo((j-2)*ii+1+i) = cu((j-1)*(ii+1)+i)
-        cvfi_glo((j-2)*ii+1+i) = cv((j-1)*(ii+1)+i)
-        boundslonfi_glo(k,north_east)=rlonu(i)
-        boundslatfi_glo(k,north_east)=rlatv(j-1)
-        boundslonfi_glo(k,north_west)=rlonu(i+1)
-        boundslatfi_glo(k,north_west)=rlatv(j-1)
-        boundslonfi_glo(k,south_west)=rlonu(i+1)
-        boundslatfi_glo(k,south_west)=rlatv(j)
-        boundslonfi_glo(k,south_east)=rlonu(i)
-        boundslatfi_glo(k,south_east)=rlatv(j)
-      ENDDO
-    ENDDO
-    ! South pole
-    latfi_glo(klon_glo)= rlatu(jj+1)
-    lonfi_glo(klon_glo)= 0.
-    cufi_glo(klon_glo) = cu((ii+1)*jj+1)
-    cvfi_glo(klon_glo) = cv((ii+1)*jj-ii)
-    boundslonfi_glo(klon_glo,north_east)= 0
-    boundslatfi_glo(klon_glo,north_east)= rlatv(jj)
-    boundslonfi_glo(klon_glo,north_west)= 2*PI
-    boundslatfi_glo(klon_glo,north_west)= rlatv(jj)
-    boundslonfi_glo(klon_glo,south_west)= 2*PI
-    boundslatfi_glo(klon_glo,south_west)= -PI/2
-    boundslonfi_glo(klon_glo,south_east)= 0
-    boundslatfi_glo(klon_glo,south_east)= -Pi/2
-
-    ! build airefi(), mesh area on physics grid
-    CALL gr_dyn_fi(1,ii+1,jj+1,klon_glo,aire,airefi_glo)
-    ! Poles are single points on physics grid
-    airefi_glo(1)=sum(aire(1:ii,1))
-    airefi_glo(klon_glo)=sum(aire(1:ii,jj+1))
-
-    ! Sanity check: do total planet area match between physics and dynamics?
-    total_area_dyn=sum(aire(1:ii,1:jj+1))
-    total_area_phy=sum(airefi_glo(1:klon_glo))
-    IF (total_area_dyn/=total_area_phy) THEN
-      WRITE (lunout, *) 'iniphysiq: planet total surface discrepancy !!!'
-      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
-      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
-      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
-        ! stop here if the relative difference is more than 0.001%
-        abort_message = 'planet total surface discrepancy'
-        CALL abort_gcm(modname, abort_message, 1)
-      ENDIF
-    ENDIF
-  ELSE ! klon_glo==1, running the 1D model
-    ! just copy over input values
-    latfi_glo(1)=rlatu(1)
-    lonfi_glo(1)=rlonv(1)
-    cufi_glo(1)=cu(1)
-    cvfi_glo(1)=cv(1)
-    airefi_glo(1)=aire(1,1)
-    boundslonfi_glo(1,north_east)=rlonu(1)
-    boundslatfi_glo(1,north_east)=PI/2
-    boundslonfi_glo(1,north_west)=rlonu(2)
-    boundslatfi_glo(1,north_west)=PI/2
-    boundslonfi_glo(1,south_west)=rlonu(2)
-    boundslatfi_glo(1,south_west)=rlatv(1)
-    boundslonfi_glo(1,south_east)=rlonu(1)
-    boundslatfi_glo(1,south_east)=rlatv(1)
-  ENDIF ! of IF (klon_glo>1)
-
-!$OMP PARALLEL
-  ! Now generate local lon/lat/cu/cv/area/bounds arrays
-  ALLOCATE(latfi(klon_omp),lonfi(klon_omp),cufi(klon_omp),cvfi(klon_omp))
-  ALLOCATE(airefi(klon_omp))
-  ALLOCATE(boundslonfi(klon_omp,4))
-  ALLOCATE(boundslatfi(klon_omp,4))
 
 
-  offset = klon_mpi_begin - 1
-  airefi(1:klon_omp) = airefi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  cufi(1:klon_omp) = cufi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  cvfi(1:klon_omp) = cvfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  lonfi(1:klon_omp) = lonfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  latfi(1:klon_omp) = latfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
-  boundslonfi(1:klon_omp,:) = boundslonfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
-  boundslatfi(1:klon_omp,:) = boundslatfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
+  ! --> initialize physics distribution, global fields and geometry
+  ! (i.e. things in phy_common or dynphy_lonlat)
+  CALL inigeomphy(ii,jj,nlayer, &
+               nbp, communicator, &
+               rlatu,rlatv, &
+               rlonu,rlonv, &
+               aire,cu,cv)
 
-  ! copy over local grid longitudes and latitudes
-  CALL init_geometry(klon_omp,lonfi,latfi,boundslonfi,boundslatfi, &
-                     airefi,cufi,cvfi)
-
+  ! --> now initialize things specific to the phymar physics package
+  
+!$OMP PARALLEL
 
   ! Initialize tracer names, numbers, etc. for physics
Index: /LMDZ5/branches/testing/libf/phydev/iophy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phydev/iophy.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phydev/iophy.F90	(revision 2594)
@@ -44,5 +44,5 @@
                                 jj_nb, jj_begin, jj_end, ii_begin, ii_end, &
                                 mpi_size, mpi_rank, klon_mpi, &
-                                is_sequential, is_south_pole
+                                is_sequential, is_south_pole_dyn
   USE mod_grid_phy_lmdz, only: nbp_lon, nbp_lat, klon_glo
   USE print_control_mod, ONLY: lunout, prt_level
@@ -141,5 +141,5 @@
       write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
       write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
-      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," is_south_pole=",is_south_pole
+      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," is_south_pole=",is_south_pole_dyn
     endif
 
@@ -148,5 +148,5 @@
                             1, nbp_lon, ii_begin, ii_end, jj_begin, jj_end,             &
                             klon_mpi+2*(nbp_lon-1), data_ibegin, data_iend,             &
-                            io_lat, io_lon,is_south_pole,mpi_rank)
+                            io_lat, io_lon,is_south_pole_dyn,mpi_rank)
 #endif
 !$OMP END MASTER
Index: /LMDZ5/branches/testing/libf/phylmd/aero_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/aero_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/aero_mod.F90	(revision 2594)
@@ -88,6 +88,7 @@
 
 ! Number of diagnostics wavelengths (5 SW + 1 LW @ 10 um)
-  INTEGER, PARAMETER :: nwave = 5
+  INTEGER, PARAMETER :: nwave_sw = 5
   INTEGER, PARAMETER :: nwave_lw = 1
+  INTEGER, PARAMETER :: nwave = nwave_sw + nwave_lw
 
 ! Number of modes spectral bands
Index: /LMDZ5/branches/testing/libf/phylmd/aeropt_2bands.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/aeropt_2bands.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/aeropt_2bands.F90	(revision 2594)
@@ -1128,8 +1128,10 @@
   ENDDO
 
-  inu=1
+  inu=1         ! visible wavaband
+  mrfspecies=2  ! total aerosol AER	 
   DO i=1, KLON
-     absvisaer(i)=SUM((1-piz_allaer(i,:,:,inu))*tau_allaer(i,:,:,inu))
+     absvisaer(i)=SUM((1-piz_allaer(i,:,mrfspecies,inu))*tau_allaer(i,:,mrfspecies,inu))
   ENDDO
+  STOP
 
   DEALLOCATE(aerosol_name) 
Index: /LMDZ5/branches/testing/libf/phylmd/aeropt_5wv.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/aeropt_5wv.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/aeropt_5wv.F90	(revision 2594)
@@ -74,5 +74,5 @@
   ! Local
   !
-  INTEGER, PARAMETER :: las = nwave
+  INTEGER, PARAMETER :: las = nwave_sw
   LOGICAL :: soluble
   
Index: /LMDZ5/branches/testing/libf/phylmd/alpale.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/alpale.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/alpale.F90	(revision 2594)
@@ -4,5 +4,5 @@
                     wake_pe, wake_fip,  &
                     Ale_bl, Ale_bl_trig, Alp_bl, &
-                    Ale, Alp )
+                    Ale, Alp, Ale_wake, Alp_wake )
 
 ! **************************************************************
@@ -46,4 +46,5 @@
 !----------------
   REAL, DIMENSION(klon), INTENT(OUT)                         :: Ale, Alp
+  REAL, DIMENSION(klon), INTENT(OUT)                         :: Ale_wake, Alp_wake
 
   include "thermcell.h"
@@ -55,5 +56,4 @@
   INTEGER                                                    :: i, k
   REAL, DIMENSION(klon)                                      :: www
-  REAL, DIMENSION(klon)                                      :: ale_wake, alp_wake
   REAL, SAVE                                                 :: ale_max=1000.
   REAL, SAVE                                                 :: alp_max=2.
Index: /LMDZ5/branches/testing/libf/phylmd/alpale_th.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/alpale_th.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/alpale_th.F90	(revision 2594)
@@ -1,6 +1,7 @@
-SUBROUTINE alpale_th ( dtime, lmax_th, t_seri,  &
+SUBROUTINE alpale_th ( dtime, lmax_th, t_seri, cell_area,  &
                        cin, s2, n2,  &
                        ale_bl_trig, ale_bl_stat, ale_bl,  &
-                       alp_bl, alp_bl_stat )
+                       alp_bl, alp_bl_stat, &
+                       proba_notrig, random_notrig)
 
 ! **************************************************************
@@ -27,4 +28,5 @@
 !----------------
   REAL, INTENT(IN)                                           :: dtime
+  REAL, DIMENSION(klon), INTENT(IN)                          :: cell_area
   INTEGER, DIMENSION(klon), INTENT(IN)                       :: lmax_th
   REAL, DIMENSION(klon,klev), INTENT(IN)                     :: t_seri
@@ -37,4 +39,6 @@
   REAL, DIMENSION(klon), INTENT(INOUT)                       :: alp_bl_stat
 
+  REAL, DIMENSION(klon), INTENT(OUT)                         :: proba_notrig, random_notrig
+
   include "thermcell.h"
 
@@ -44,10 +48,38 @@
   LOGICAL, SAVE                                              :: first = .TRUE.
   REAL, SAVE                                                 :: random_notrig_max=1.
-  REAL, DIMENSION(klon)                                      :: proba_notrig, tau_trig, random_notrig
+  REAL, SAVE                                                 :: cv_feed_area
+  REAL                                                       :: birth_number
+  REAL, DIMENSION(klon)                                      :: ale_bl_ref
+  REAL, DIMENSION(klon)                                      :: tau_trig
+  REAL, DIMENSION(klon)                                      :: birth_rate
 !
     !$OMP THREADPRIVATE(random_notrig_max) 
+    !$OMP THREADPRIVATE(cv_feed_area) 
     !$OMP THREADPRIVATE(first)
 !
+ REAL umexp  ! expression of (1.-exp(-x))/x valid for all x, especially when x->0
+ REAL x
+ umexp(x) = max(sign(1.,x-1.e-3),0.)*(1.-exp(-x))/max(x,1.e-3) + &
+            (1.-max(sign(1.,x-1.e-3),0.))*(1.-0.5*x*(1.-x/3.*(1.-0.25*x)))
+!
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+!  JYG, 20160513 : Introduction of the Effective Lifting Power (ELP), which 
+! takes into account the area (cv_feed_area) covered by thermals contributing 
+! to each cumulonimbus.
+!   The use of ELP prevents singularities when the trigger probability tends to
+! zero. It is activated by iflag_clos_bl = 3.
+!   The ELP values are stored in the ALP_bl variable.
+!   
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+!
+!---------------------------------------
+  IF (iflag_clos_bl .LT. 3) THEN
+!---------------------------------------
+!
+!      Original code (Nicolas Rochetin)
+!     --------------------------------
+
     IF (first) THEN
+       random_notrig_max=1.
        CALL getin_p('random_notrig_max',random_notrig_max)
        first=.FALSE.
@@ -155,4 +187,94 @@
           endif !(iflag_clos_bl)
 
+!
+!---------------------------------------
+  ELSEIF (iflag_clos_bl .EQ. 3) THEN  ! (iflag_clos_bl .LT. 3)
+!---------------------------------------
+!
+!      New code with Effective Lifting Power
+!     -------------------------------------
+    IF (first) THEN
+       cv_feed_area = 1.e10   ! m2
+       CALL getin_p('cv_feed_area', cv_feed_area)
+       first=.FALSE.
+    ENDIF
+
+          !-----------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
+
+        ! Use ale_bl_stat (Rochetin's code) or ale_bl (old code) according to 
+        ! iflag_trig_bl value.
+        IF (iflag_trig_bl.eq.1) then         ! use ale_bl_stat (Rochetin computation)
+         do i=1,klon
+              ale_bl_ref(i)=ale_bl_stat(i)
+         enddo
+        ELSE IF (iflag_trig_bl.ge.2) then    ! use ale_bl (old computation)
+         do i=1,klon
+              ale_bl_ref(i)=Ale_bl(i)
+         enddo
+        ENDIF ! (iflag_trig_bl.eq.1)
+
+
+        !----Initializations and random number generation
+        do i=1,klon
+           proba_notrig(i)=1.
+           random_notrig(i)=1e6*ale_bl_stat(i)-int(1e6*ale_bl_stat(i))
+           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
+
+        !----alp_bl computation
+        do i=1,klon
+           if ( (ale_bl_ref(i) .gt. abs(cin(i))+1.e-10) )  then
+              birth_number = n2(i)*exp(-s_trig/s2(i))
+              birth_rate(i) = birth_number/(tau_trig(i)*cell_area(i))
+              proba_notrig(i)=exp(-birth_number*dtime/tau_trig(i))
+              Alp_bl(i) = Alp_bl(i)* &
+                          umexp(-birth_number*cv_feed_area/cell_area(i))/ &
+                          umexp(-birth_number*dtime/tau_trig(i))*  &
+                          tau_trig(i)*cv_feed_area/(dtime*cell_area(i))
+          else 
+              proba_notrig(i)=1.
+              random_notrig(i)=0.
+              alp_bl(i)=0.
+           endif
+        enddo
+
+        !----ale_bl_trig computation
+         do i=1,klon
+           if (random_notrig(i) .ge. proba_notrig(i)) then 
+              ale_bl_trig(i)=ale_bl_ref(i)
+           else
+              ale_bl_trig(i)=0.
+           endif
+         enddo
+
+        !
+        IF (prt_level .GE. 10) THEN
+           print *,'proba_notrig, ale_bl_trig ', &
+                proba_notrig, ale_bl_trig
+        ENDIF
+
+     endif !(iflag_trig_bl .ge. 1)
+
+!---------------------------------------
+  ENDIF ! (iflag_clos_bl .LT. 3)
+!---------------------------------------
+
           IF (prt_level .GE. 10) THEN
              print *,'ale_bl_trig, alp_bl_stat ',ale_bl_trig, alp_bl_stat
@@ -160,13 +282,5 @@
 
           !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
@@ -180,6 +294,7 @@
                 endif
              enddo
+    print *,'In order to run with iflag_coupl=2, you have to comment out the following stop'
+             STOP
           endif
-!
    RETURN
    END
Index: /LMDZ5/branches/testing/libf/phylmd/clesphys.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/clesphys.h	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/clesphys.h	(revision 2594)
@@ -40,4 +40,5 @@
 !IM, MAFo fmagic, pmagic : parametres - additionnel et multiplicatif - 
 !                          pour regler l albedo sur ocean
+       REAL pbl_lmixmin_alpha
        REAL fmagic, pmagic
 ! Hauteur (imposee) du contenu en eau du sol
@@ -77,6 +78,7 @@
        REAL ecrit_LES
        REAL freq_ISCCP, ecrit_ISCCP
-       REAL freq_COSP
+       REAL freq_COSP, freq_AIRS
        LOGICAL :: ok_cosp,ok_mensuelCOSP,ok_journeCOSP,ok_hfCOSP
+       LOGICAL :: ok_airs
        INTEGER :: ip_ebil_phy, iflag_rrtm, iflag_ice_thermo, NSW, iflag_albedo
        LOGICAL :: ok_chlorophyll
@@ -94,5 +96,5 @@
      &     , CH4_ppb, N2O_ppb, CFC11_ppt, CFC12_ppt                     &
      &     , CH4_ppb_per, N2O_ppb_per, CFC11_ppt_per, CFC12_ppt_per     &
-     &     , cdmmax, cdhmax, ksta, ksta_ter, f_ri_cd_min                &
+     &     , cdmmax,cdhmax,ksta,ksta_ter,f_ri_cd_min,pbl_lmixmin_alpha  &
      &     , fmagic, pmagic                                             &
      &     , f_cdrag_ter,f_cdrag_oce,f_rugoro,z0min                     &
@@ -101,5 +103,5 @@
      &     , pasphys            , freq_outNMC, freq_calNMC              &
      &     , lonmin_ins, lonmax_ins, latmin_ins, latmax_ins             &
-     &     , freq_ISCCP, ecrit_ISCCP, freq_COSP                         &
+     &     , freq_ISCCP, ecrit_ISCCP, freq_COSP, freq_AIRS              &
      &     , cvl_corr                                                   &
      &     , qsol0,albsno0,evap0                                        &
@@ -120,5 +122,5 @@
      &     , lev_histins, lev_histLES, lev_histdayNMC, levout_histNMC   &
      &     , ok_histNMC                                                 &
-     &     , type_run, ok_regdyn, ok_cosp                               &
+     &     , type_run, ok_regdyn, ok_cosp, ok_airs                      &
      &     , ok_mensuelCOSP,ok_journeCOSP,ok_hfCOSP                     &
      &     , ip_ebil_phy                                                &
Index: /LMDZ5/branches/testing/libf/phylmd/cloudth.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cloudth.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/cloudth.F90	(revision 2594)
@@ -5,5 +5,4 @@
 
 
-      USE IOIPSL, ONLY : getin
       IMPLICIT NONE
 
@@ -20,4 +19,5 @@
 #include "FCTTRE.h"
 #include "thermcell.h"
+#include "nuage.h"
 
       INTEGER itap,ind1,ind2
@@ -54,5 +54,5 @@
       REAL sth,senv,sigma1s,sigma2s,xth,xenv
       REAL Tbef,zdelta,qsatbef,zcor
-      REAL alpha,qlbef  
+      REAL qlbef  
       REAL ratqs(ngrid,klev) ! determine la largeur de distribution de vapeur
       
@@ -62,34 +62,19 @@
       REAL erf
 
-      REAL, SAVE :: iflag_cloudth_vert, iflag_cloudth_vert_omp=0
-
-
-      LOGICAL, SAVE :: first=.true.
-
-
 
 
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-! Astuce pour gérer deux versions de cloudth en attendant
-! de converger sur une version nouvelle
+! Gestion de deux versions de cloudth
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      IF (first) THEN
-     !$OMP MASTER
-     CALL getin('iflag_cloudth_vert',iflag_cloudth_vert_omp)
-     !$OMP END MASTER
-     !$OMP BARRIER
-     iflag_cloudth_vert=iflag_cloudth_vert_omp
-      first=.false.
-      ENDIF
-       IF (iflag_cloudth_vert==1) THEN
-       CALL cloudth_vert(ngrid,klev,ind2,  &
+
+      IF (iflag_cloudth_vert.GE.1) THEN
+      CALL cloudth_vert(ngrid,klev,ind2,  &
      &           ztv,po,zqta,fraca, & 
      &           qcloud,ctot,zpspsk,paprs,ztla,zthl, &
      &           ratqs,zqs,t)
-       RETURN
-       ENDIF
+      RETURN
+      ENDIF
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
 
 
@@ -185,15 +170,8 @@
       cenv(ind1,ind2)=0.5*(1.+1.*erf(xenv)) 
       ctot(ind1,ind2)=fraca(ind1,ind2)*cth(ind1,ind2)+(1.-1.*fraca(ind1,ind2))*cenv(ind1,ind2)   
-!      ctot(ind1,ind2)=alpha*cth(ind1,ind2)+(1.-1.*alpha)*cenv(ind1,ind2) 
-
-
 
       qlth(ind1,ind2)=sigma2s*((exp(-1.*xth**2)/sqrt2pi)+xth*sqrt(2.)*cth(ind1,ind2))
       qlenv(ind1,ind2)=sigma1s*((exp(-1.*xenv**2)/sqrt2pi)+xenv*sqrt(2.)*cenv(ind1,ind2))   
       qltot(ind1,ind2)=fraca(ind1,ind2)*qlth(ind1,ind2)+(1.-1.*fraca(ind1,ind2))*qlenv(ind1,ind2)
-!      qltot(ind1,ind2)=alpha*qlth(ind1,ind2)+(1.-1.*alpha)*qlenv(ind1,ind2)
-     
-
-!      print*,senv,sth,sigma1s,sigma2s,fraca(ind1,ind2),'senv et sth et sig1 et sig2 et alpha'
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -269,8 +247,4 @@
      &           ratqs,zqs,t)
 
-
-      IMPLICIT NONE
-
-
 !===========================================================================
 ! Auteur : Arnaud Octavio Jam (LMD/CNRS)
@@ -280,9 +254,14 @@
 
 
+      USE ioipsl_getin_p_mod, ONLY : getin_p
+
+      IMPLICIT NONE
+
 #include "YOMCST.h"
 #include "YOETHF.h"
 #include "FCTTRE.h"
 #include "thermcell.h"
-
+#include "nuage.h"
+      
       INTEGER itap,ind1,ind2
       INTEGER ngrid,klev,klon,l,ig 
@@ -320,6 +299,10 @@
       REAL IntJ,IntI1,IntI2,IntI3,coeffqlenv,coeffqlth
       REAL Tbef,zdelta,qsatbef,zcor
-      REAL alpha,qlbef  
+      REAL qlbef  
       REAL ratqs(ngrid,klev) ! determine la largeur de distribution de vapeur
+      ! Change the width of the PDF used for vertical subgrid scale heterogeneity
+      ! (J Jouhaud, JL Dufresne, JB Madeleine)
+      REAL,SAVE :: vert_alpha
+      LOGICAL, SAVE :: firstcall = .TRUE.
       
       REAL zpdf_sig(ngrid),zpdf_k(ngrid),zpdf_delta(ngrid)
@@ -327,8 +310,4 @@
       REAL zqs(ngrid), qcloud(ngrid)
       REAL erf
-
-
-
-
 
 !------------------------------------------------------------------------------
@@ -355,5 +334,10 @@
       sqrtpi=sqrt(pi)
 
-
+      IF (firstcall) THEN
+        vert_alpha=0.5
+        CALL getin_p('cloudth_vert_alpha',vert_alpha)
+        WRITE(*,*) 'cloudth_vert_alpha = ', vert_alpha
+        firstcall=.FALSE.
+      ENDIF
 
 !-------------------------------------------------------------------------------
@@ -425,17 +409,10 @@
       cenv(ind1,ind2)=0.5*(1.+1.*erf(xenv)) 
       ctot(ind1,ind2)=fraca(ind1,ind2)*cth(ind1,ind2)+(1.-1.*fraca(ind1,ind2))*cenv(ind1,ind2)   
-!      ctot(ind1,ind2)=alpha*cth(ind1,ind2)+(1.-1.*alpha)*cenv(ind1,ind2) 
-
-
 
       qlth(ind1,ind2)=sigma2s*((exp(-1.*xth**2)/sqrt2pi)+xth*sqrt(2.)*cth(ind1,ind2))
       qlenv(ind1,ind2)=sigma1s*((exp(-1.*xenv**2)/sqrt2pi)+xenv*sqrt(2.)*cenv(ind1,ind2))   
       qltot(ind1,ind2)=fraca(ind1,ind2)*qlth(ind1,ind2)+(1.-1.*fraca(ind1,ind2))*qlenv(ind1,ind2)
-!      qltot(ind1,ind2)=alpha*qlth(ind1,ind2)+(1.-1.*alpha)*qlenv(ind1,ind2)
      
-
-!      print*,senv,sth,sigma1s,sigma2s,fraca(ind1,ind2),'senv et sth et sig1 et sig2 et alpha'
-
-
+       IF (iflag_cloudth_vert == 1) THEN
 !-------------------------------------------------------------------------------
 !  Version 2: Modification selon J.-Louis. On condense ?? partir de qsat-ratqs
@@ -479,5 +456,57 @@
       qltot(ind1,ind2)=fraca(ind1,ind2)*qlth(ind1,ind2)+(1.-1.*fraca(ind1,ind2))*qlenv(ind1,ind2)
 
+      ELSE IF (iflag_cloudth_vert == 2) THEN
+
+!-------------------------------------------------------------------------------
+!  Version 3: Modification Jean Jouhaud. On condense a partir de -delta s
+!-------------------------------------------------------------------------------
+!      deltasenv=aenv*ratqs(ind1,ind2)*po(ind1)
+!      deltasth=ath*ratqs(ind1,ind2)*zqta(ind1,ind2)
+!      deltasenv=aenv*ratqs(ind1,ind2)*zqsatenv(ind1,ind2)
+!      deltasth=ath*ratqs(ind1,ind2)*zqsatth(ind1,ind2)
+      deltasenv=aenv*vert_alpha*sigma1s
+      deltasth=ath*vert_alpha*sigma2s
+      
+      xenv1=-(senv+deltasenv)/(sqrt(2.)*sigma1s)
+      xenv2=-(senv-deltasenv)/(sqrt(2.)*sigma1s)
+      xth1=-(sth+deltasth)/(sqrt(2.)*sigma2s)
+      xth2=-(sth-deltasth)/(sqrt(2.)*sigma2s)
+!     coeffqlenv=(sigma1s)**2/(2*sqrtpi*deltasenv)
+!     coeffqlth=(sigma2s)**2/(2*sqrtpi*deltasth)
+      
+      cth(ind1,ind2)=0.5*(1.-1.*erf(xth1))
+      cenv(ind1,ind2)=0.5*(1.-1.*erf(xenv1))
+      ctot(ind1,ind2)=fraca(ind1,ind2)*cth(ind1,ind2)+(1.-1.*fraca(ind1,ind2))*cenv(ind1,ind2)
+
+      IntJ=0.5*senv*(1-erf(xenv2))+(sigma1s/sqrt2pi)*exp(-1.*xenv2**2)
+      IntI1=(((senv+deltasenv)**2+(sigma1s)**2)/(8*deltasenv))*(erf(xenv2)-erf(xenv1))
+      IntI2=(sigma1s**2/(4*deltasenv*sqrtpi))*(xenv1*exp(-1.*xenv1**2)-xenv2*exp(-1.*xenv2**2))
+      IntI3=((sqrt2*sigma1s*(senv+deltasenv))/(4*sqrtpi*deltasenv))*(exp(-1.*xenv1**2)-exp(-1.*xenv2**2))
+
+!      IntI1=0.5*(0.5*sqrtpi*(erf(xenv2)-erf(xenv1))+xenv1*exp(-1.*xenv1**2)-xenv2*exp(-1.*xenv2**2))
+!      IntI2=xenv2*(exp(-1.*xenv2**2)-exp(-1.*xenv1**2))
+!      IntI3=0.5*sqrtpi*xenv2**2*(erf(xenv2)-erf(xenv1))
+
+      qlenv(ind1,ind2)=IntJ+IntI1+IntI2+IntI3
+!      qlenv(ind1,ind2)=IntJ 
+!      print*, qlenv(ind1,ind2),'VERIF EAU'
+
+      IntJ=0.5*sth*(1-erf(xth2))+(sigma2s/sqrt2pi)*exp(-1.*xth2**2)
+      IntI1=(((sth+deltasth)**2+(sigma2s)**2)/(8*deltasth))*(erf(xth2)-erf(xth1))
+      IntI2=(sigma2s**2/(4*deltasth*sqrtpi))*(xth1*exp(-1.*xth1**2)-xth2*exp(-1.*xth2**2))
+      IntI3=((sqrt2*sigma2s*(sth+deltasth))/(4*sqrtpi*deltasth))*(exp(-1.*xth1**2)-exp(-1.*xth2**2))
+      
+      qlth(ind1,ind2)=IntJ+IntI1+IntI2+IntI3
+!      qlth(ind1,ind2)=IntJ
+!      print*, IntJ,IntI1,IntI2,IntI3,qlth(ind1,ind2),'VERIF EAU2'
+      qltot(ind1,ind2)=fraca(ind1,ind2)*qlth(ind1,ind2)+(1.-1.*fraca(ind1,ind2))*qlenv(ind1,ind2)
+      
+
+
+
+      ENDIF ! of if (iflag_cloudth_vert==1 or 2)
+
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
       if (cenv(ind1,ind2).lt.1.e-10.or.cth(ind1,ind2).lt.1.e-10) then
       ctot(ind1,ind2)=0.
Index: /LMDZ5/branches/testing/libf/phylmd/coef_diff_turb_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/coef_diff_turb_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/coef_diff_turb_mod.F90	(revision 2594)
@@ -164,5 +164,5 @@
                iflag_pbl)
        ELSE IF (iflag_pbl<20) THEN
-          CALL yamada4(knon,dtime,RG,RD,ypaprs,yt, &
+          CALL yamada4(ni,nsrf,knon,dtime,RG,RD,ypaprs,yt, &
                yzlev,yzlay,yu,yv,yteta, &
                ycdragm,yq2,ykmm,ykmn,ykmq,yustar, &
Index: /LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90	(revision 2594)
@@ -98,5 +98,5 @@
     REAL,SAVE           :: bl95_b0_omp, bl95_b1_omp
     REAL,SAVE           :: freq_ISCCP_omp, ecrit_ISCCP_omp
-    REAL,SAVE           :: freq_COSP_omp
+    REAL,SAVE           :: freq_COSP_omp, freq_AIRS_omp 
     real,SAVE           :: fact_cldcon_omp, facttemps_omp,ratqsbas_omp
     real,SAVE           :: tau_cld_cv_omp, coefw_cld_cv_omp
@@ -165,4 +165,5 @@
     INTEGER,SAVE :: iflag_ice_thermo_omp
     INTEGER,SAVE :: iflag_t_glace_omp
+    INTEGER,SAVE :: iflag_cloudth_vert_omp
     REAL,SAVE :: rad_froid_omp, rad_chau1_omp, rad_chau2_omp
     REAL,SAVE :: t_glace_min_omp, t_glace_max_omp
@@ -178,4 +179,5 @@
     REAL,SAVE :: cdmmax_omp,cdhmax_omp,ksta_omp,ksta_ter_omp,f_ri_cd_min_omp
     LOGICAL,SAVE :: ok_kzmin_omp
+    REAL, SAVE   :: pbl_lmixmin_alpha_omp
     REAL, SAVE ::  fmagic_omp, pmagic_omp
     INTEGER,SAVE :: iflag_pbl_omp,lev_histhf_omp,lev_histday_omp,lev_histmth_omp
@@ -188,5 +190,5 @@
     REAL, SAVE :: freq_outNMC_omp(3), freq_calNMC_omp(3)
     CHARACTER*4, SAVE :: type_run_omp
-    LOGICAL,SAVE :: ok_cosp_omp
+    LOGICAL,SAVE :: ok_cosp_omp, ok_airs_omp
     LOGICAL,SAVE :: ok_mensuelCOSP_omp,ok_journeCOSP_omp,ok_hfCOSP_omp
     REAL,SAVE :: lonmin_ins_omp, lonmax_ins_omp, latmin_ins_omp, latmax_ins_omp
@@ -460,4 +462,13 @@
     call getin('freq_COSP', freq_COSP_omp)
 
+    !Config Key  = freq_AIRS
+    !Config Desc = Frequence d'appel du simulateur AIRS en secondes;
+    !              par defaut 10800, i.e. 3 heures
+    !Config Def  = 10800.
+    !Config Help = Used in ini_histdayAIRS.h
+    !
+    freq_AIRS_omp = 10800.
+    call getin('freq_AIRS', freq_AIRS_omp)
+
     !
     !Config Key  = ip_ebil_phy
@@ -1161,4 +1172,13 @@
 
     !
+    !Config Key  = iflag_cloudth_vert
+    !Config Desc =  
+    !Config Def  = 0
+    !Config Help = 
+    !
+    iflag_cloudth_vert_omp = 0
+    call getin('iflag_cloudth_vert',iflag_cloudth_vert_omp)
+
+    !
     !Config Key  = iflag_ice_thermo
     !Config Desc =  
@@ -1259,4 +1279,8 @@
     ok_kzmin_omp = .true.
     call getin('ok_kzmin',ok_kzmin_omp)
+
+    pbl_lmixmin_alpha_omp=0.0
+    call getin('pbl_lmixmin_alpha',pbl_lmixmin_alpha_omp)
+
 
     !
@@ -1594,4 +1618,13 @@
     ok_cosp_omp = .false.
     call getin('ok_cosp',ok_cosp_omp)
+
+    !
+    !Config Key  = ok_airs
+    !Config Desc =
+    !Config Def  = .false.
+    !Config Help =
+    !
+    ok_airs_omp = .false.
+    call getin('ok_airs',ok_airs_omp)
 
     !
@@ -2044,4 +2077,5 @@
     exposant_glace = exposant_glace_omp
     iflag_t_glace = iflag_t_glace_omp
+    iflag_cloudth_vert=iflag_cloudth_vert_omp
     iflag_ice_thermo = iflag_ice_thermo_omp
     rei_min = rei_min_omp
@@ -2055,4 +2089,5 @@
     f_ri_cd_min = f_ri_cd_min_omp
     ok_kzmin = ok_kzmin_omp
+    pbl_lmixmin_alpha=pbl_lmixmin_alpha_omp
     fmagic = fmagic_omp
     pmagic = pmagic_omp
@@ -2094,4 +2129,5 @@
     ecrit_ISCCP = ecrit_ISCCP_omp
     freq_COSP = freq_COSP_omp
+    freq_AIRS = freq_AIRS_omp
     ok_ade = ok_ade_omp
     ok_aie = ok_aie_omp
@@ -2144,4 +2180,6 @@
     type_run = type_run_omp
     ok_cosp = ok_cosp_omp
+    ok_airs = ok_airs_omp
+
     ok_mensuelCOSP = ok_mensuelCOSP_omp
     ok_journeCOSP = ok_journeCOSP_omp
@@ -2291,4 +2329,5 @@
     write(lunout,*)' Frequence appel simulateur ISCCP, ecrit_ISCCP =', ecrit_ISCCP
     write(lunout,*)' Frequence appel simulateur COSP, freq_COSP =', freq_COSP
+    write(lunout,*)' Frequence appel simulateur AIRS, freq_AIRS =', freq_AIRS
     write(lunout,*)' Sortie bilan d''energie, ip_ebil_phy =', ip_ebil_phy
     write(lunout,*)' Excentricite = ',R_ecc
@@ -2361,4 +2400,5 @@
     write(lunout,*)' exposant_glace = ',exposant_glace
     write(lunout,*)' iflag_t_glace = ',iflag_t_glace
+    write(lunout,*)' iflag_cloudth_vert = ',iflag_cloudth_vert
     write(lunout,*)' iflag_ice_thermo = ',iflag_ice_thermo
     write(lunout,*)' rei_min = ',rei_min
@@ -2371,4 +2411,5 @@
     write(lunout,*)' f_ri_cd_min = ',f_ri_cd_min 
     write(lunout,*)' ok_kzmin = ',ok_kzmin 
+    write(lunout,*)' pbl_lmixmin_alpha = ',pbl_lmixmin_alpha
     write(lunout,*)' fmagic = ',fmagic
     write(lunout,*)' pmagic = ',pmagic
@@ -2404,4 +2445,6 @@
     write(lunout,*)' type_run = ',type_run 
     write(lunout,*)' ok_cosp = ',ok_cosp
+    write(lunout,*)' ok_airs = ',ok_airs
+
     write(lunout,*)' ok_mensuelCOSP = ',ok_mensuelCOSP
     write(lunout,*)' ok_journeCOSP = ',ok_journeCOSP
Index: /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_constants.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_constants.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_constants.F90	(revision 2594)
@@ -108,5 +108,6 @@
                    -31.5,-28.5,-25.5,-22.5,-19.5,-16.5,-13.5,-10.5, -7.5, -4.5, &
                     -1.5,  1.5,  4.5,  7.5, 10.5, 13.5, 16.5, 19.5, 22.5, 25.5/)
-    real,parameter,dimension(2,LIDAR_NTEMP) :: LIDAR_PHASE_TEMP_BNDS=reshape(source=(/-273.15,-90.,-90.,-87.,-87.,-84.,-84.,-81.,-81.,-78., &
+    real,parameter,dimension(2,LIDAR_NTEMP) :: LIDAR_PHASE_TEMP_BNDS=reshape(source=&
+                    (/-273.15,-90.,-90.,-87.,-87.,-84.,-84.,-81.,-81.,-78., &
                    -78.,-75.,-75.,-72.,-72.,-69.,-69.,-66.,-66.,-63., &
                    -63.,-60.,-60.,-57.,-57.,-54.,-54.,-51.,-51.,-48., &
Index: /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_mod.F90	(revision 2594)
@@ -228,5 +228,5 @@
   real,dimension(2,SR_BINS) :: sratio_bounds
   real,dimension(SR_BINS)   ::  sratio_ax
-  CHARACTER(LEN=20), DIMENSION(3)  :: chfreq = (/ '1day', '1d', '3h' /)            
+  CHARACTER(LEN=20), DIMENSION(3)  :: chfreq = (/ '1day', '1d  ', '3h  ' /)            
 
 !!! Variables d'entree
@@ -363,6 +363,8 @@
       CALL histvert(cosp_nidfiles(iff),"column","column","count",Ncolumns,column_ax(1:Ncolumns),nvertcol(iff))
 
-      CALL histvert(cosp_nidfiles(iff),"temp","temperature","C",LIDAR_NTEMP,LIDAR_PHASE_TEMP,nverttemp(iff))                                       
-      CALL histvert(cosp_nidfiles(iff),"cth16","altitude","m",MISR_N_CTH,MISR_CTH,nvertmisr(iff))                                                                                                  
+      CALL histvert(cosp_nidfiles(iff),"temp","temperature","C",LIDAR_NTEMP,LIDAR_PHASE_TEMP,nverttemp(iff))
+
+      CALL histvert(cosp_nidfiles(iff),"cth16","altitude","m",MISR_N_CTH,MISR_CTH,nvertmisr(iff))
+
 !      CALL histvert(cosp_nidfiles(iff),"dbze","equivalent_reflectivity_factor","dBZ",DBZE_BINS,dbze_ax,nvertbze(iff))
      
Index: /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_write_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 2594)
@@ -322,4 +322,7 @@
     if(modis%Cloud_Particle_Size_Water_Mean(ip).eq.R_UNDEF)then
        modis%Cloud_Particle_Size_Water_Mean(ip)=Cosp_fill_value
+    endif
+    if(modis%Cloud_Particle_Size_Ice_Mean(ip).eq.R_UNDEF)then
+       modis%Cloud_Particle_Size_Ice_Mean(ip)=Cosp_fill_value
     endif
     if(modis%Cloud_Top_Pressure_Total_Mean(ip).eq.R_UNDEF)then
Index: /LMDZ5/branches/testing/libf/phylmd/cosp/phys_cosp.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cosp/phys_cosp.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/cosp/phys_cosp.F90	(revision 2594)
@@ -73,5 +73,5 @@
 
 !! AI rajouter
-  #include "cosp_defs.h" 
+#include "cosp_defs.h" 
   USE MOD_COSP_CONSTANTS
   USE MOD_COSP_TYPES
Index: /LMDZ5/branches/testing/libf/phylmd/cv3_routines.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3_routines.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3_routines.F90	(revision 2594)
@@ -3860,4 +3860,5 @@
       sigd(il) = sigd(il)/alpha_qpos(il)
       precip(il) = precip(il)/alpha_qpos(il)
+      cbmf(il) = cbmf(il)/alpha_qpos(il)
     END IF
   END DO
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/1DUTILS.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/1DUTILS.h	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/1DUTILS.h	(revision 2594)
@@ -3236,4 +3236,6 @@
      &           thlpcar(nlev_max),tracer(nlev_max,ntrac)
 
+        real height1(nlev_max)
+
         integer, parameter :: ilesfile=1
         integer :: ierr,k,itrac,nt1,nt2
@@ -3245,5 +3247,5 @@
         read (ilesfile,*) kmax
         do k=1,kmax
-          read (ilesfile,*) height(k),thlprof(k),qtprof (k),               &
+          read (ilesfile,*) height1(k),thlprof(k),qtprof (k),               &
      &                      uprof (k),vprof  (k),e12prof(k)
         enddo
@@ -3261,4 +3263,11 @@
           read (ilesfile,*) height(k),ugprof(k),vgprof(k),wfls(k),         &
      &                      dqtdxls(k),dqtdyls(k),dqtdtls(k),thlpcar(k)
+        end do
+        do k=1,kmax
+          if (height(k) .ne. height1(k)) then
+            print *, 'fichiers prof.inp et lscale.inp incompatibles :'
+            print *, 'les niveaux different : ',k,height1(k), height(k)
+            stop
+          endif
         end do
         close(ilesfile)
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_interp_cases.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_interp_cases.h	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_interp_cases.h	(revision 2594)
@@ -2,4 +2,13 @@
 ! $Id$
 !
+!---------------------------------------------------------------------
+! Forcing_LES case: constant dq_dyn
+!---------------------------------------------------------------------
+      if (forcing_LES) then
+        DO l = 1,llm
+          d_q_adv(l,1) = dq_dyn(l,1)
+        ENDDO
+      endif ! forcing_LES
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !---------------------------------------------------------------------
 ! Interpolation forcing in time and onto model levels
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/lmdz1d.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/lmdz1d.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/lmdz1d.F90	(revision 2594)
@@ -33,5 +33,5 @@
    USE mod_1D_cases_read
    USE mod_1D_amma_read
-   USE print_control_mod, ONLY: prt_level
+   USE print_control_mod, ONLY: lunout, prt_level
    USE iniphysiq_mod, ONLY: iniphysiq
    USE mod_const_mpi, ONLY: comm_lmdz
@@ -54,4 +54,5 @@
 #include "fcg_gcssold.h"
 !!!#include "fbforcing.h"
+#include "compbl.h"
 
 !=====================================================================
@@ -242,4 +243,5 @@
 !---------------------------------------------------------------------
       integer :: k,l,i,it=1,mxcalc
+      integer :: nsrf
       integer jcode
       INTEGER read_climoz 
@@ -738,6 +740,14 @@
         t_ancien(1,:)=temp(:)
         q_ancien(1,:)=q(:,1)
-        pbl_tke(:,:,:)=1.e-8
-        wake_delta_pbl_tke(:,:,:)=0.
+!jyg<
+!!        pbl_tke(:,:,:)=1.e-8
+        pbl_tke(:,:,:)=0.
+        pbl_tke(:,2,:)=1.e-2
+        PRINT *, ' pbl_tke dans lmdz1d '
+       DO nsrf = 1,4
+         PRINT *,'pbl_tke(1,:,',nsrf,') ',pbl_tke(1,:,nsrf)
+       ENDDO
+
+!>jyg
 
         rain_fall=0.
@@ -762,5 +772,5 @@
         wake_deltaq = 0.
         wake_deltat = 0.
-        wake_delta_pbl_TKE = 0.
+        wake_delta_pbl_TKE(:,:,:) = 0.
         delta_tsurf = 0.
         wake_fip = 0.
@@ -791,7 +801,12 @@
 ! run_off_lic_0,pbl_tke(:,1:klev,nsrf), zmax0,f0,sig1,w01
 ! wake_deltat,wake_deltaq,wake_s,wake_cstar,wake_fip,wake_delta_pbl_tke(:,1:klev,nsrf)
+!
+! NB2: The content of the startphy.nc file depends on some flags defined in
+! the ".def" files. However, since conf_phys is not called in lmdz1d.F90, these flags have 
+! to be set at some arbitratry convenient values.
 !------------------------------------------------------------------------
 !Al1 =============== restart option ==========================
         if (.not.restart) then
+          iflag_pbl = 5
           call phyredem ("startphy.nc")
         else
@@ -1075,5 +1090,5 @@
 !---------------------------------------------------------------------
 
-      IF (nudge_tsoil) THEN
+      IF (nudge_tsoil .AND. .NOT. lastcall) THEN
        ftsoil(1,isoil_nudge,:) = ftsoil(1,isoil_nudge,:)                     &
      &  -timestep/tau_soil_nudge*(ftsoil(1,isoil_nudge,:)-Tsoil_nudge)
Index: /LMDZ5/branches/testing/libf/phylmd/grid_noro_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/grid_noro_m.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/grid_noro_m.F90	(revision 2594)
@@ -3,6 +3,8 @@
 !*******************************************************************************
 
+  USE print_control_mod, ONLY: lunout
+  USE assert_eq_m,       ONLY: assert_eq
   PRIVATE
-  PUBLIC :: grid_noro
+  PUBLIC :: grid_noro, grid_noro0
 
 
@@ -45,8 +47,5 @@
 !    on the edge are contained in input cells.
 !===============================================================================
-  USE assert_eq_m, ONLY: assert_eq
-  USE print_control_mod, ONLY: lunout
-  IMPLICIT NONE 
-  REAL, PARAMETER :: epsfra = 1.e-5
+  IMPLICIT NONE
 !-------------------------------------------------------------------------------
 ! Arguments:
@@ -315,4 +314,147 @@
 !-------------------------------------------------------------------------------
 !
+SUBROUTINE grid_noro0(xd,yd,zd,x,y,zphi,mask)
+!
+!===============================================================================
+! Purpose: Extracted from grid_noro to provide geopotential height for dynamics
+!          without any call to physics subroutines.
+!===============================================================================
+  IMPLICIT NONE 
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL, INTENT(IN)   :: xd(:), yd(:) !--- INPUT  COORDINATES     (imdp) (jmdp)
+  REAL, INTENT(IN)   :: zd(:,:)      !--- INPUT  FIELD           (imdp,jmdp)
+  REAL, INTENT(IN)   :: x(:), y(:)   !--- OUTPUT COORDINATES     (imar+1) (jmar)
+  REAL, INTENT(OUT)  :: zphi(:,:)    !--- GEOPOTENTIAL           (imar+1,jmar)
+  REAL, INTENT(INOUT):: mask(:,:)    !--- MASK                   (imar+1,jmar)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname="grid_noro0"
+  REAL, ALLOCATABLE :: xusn(:), yusn(:)           ! dim (imdp+2*iext) (jmdp+2)
+  REAL, ALLOCATABLE :: zusn(:,:)                  ! dim (imdp+2*iext,jmdp+2)
+  REAL, ALLOCATABLE :: weight(:,:)                ! dim (imar+1,jmar)
+  REAL, ALLOCATABLE :: mask_tmp(:,:), zmea(:,:)   ! dim (imar+1,jmar)
+  REAL, ALLOCATABLE :: num_tot(:,:), num_lan(:,:) ! dim (imax,jmax)
+  REAL, ALLOCATABLE :: a(:), b(:)                 ! dim (imax)
+  REAL, ALLOCATABLE :: c(:), d(:)                 ! dim (jmax)
+  LOGICAL :: masque_lu
+  INTEGER :: i, ii, imdp, imar, iext
+  INTEGER :: j, jj, jmdp, jmar, nn
+  REAL    :: xpi, zlenx, weighx, xincr,  zbordnor, zmeanor, zweinor, zbordest
+  REAL    :: rad, zleny, weighy, masque, zbordsud, zmeasud, zweisud, zbordoue
+!-------------------------------------------------------------------------------
+  imdp=assert_eq(SIZE(xd),SIZE(zd,1),TRIM(modname)//" imdp")
+  jmdp=assert_eq(SIZE(yd),SIZE(zd,2),TRIM(modname)//" jmdp")
+  imar=assert_eq(SIZE(x),SIZE(zphi,1),SIZE(mask,1),TRIM(modname)//" imar")-1
+  jmar=assert_eq(SIZE(y),SIZE(zphi,2),SIZE(mask,2),TRIM(modname)//" jmar")
+! IF(imar/=iim)   CALL abort_gcm(TRIM(modname),'imar/=iim'  ,1)
+! IF(jmar/=jjm+1) CALL abort_gcm(TRIM(modname),'jmar/=jjm+1',1)
+  iext=imdp/10
+  xpi = ACOS(-1.)
+  rad = 6371229.
+
+!--- ARE WE USING A READ MASK ?
+  masque_lu=ANY(mask/=-99999.); IF(.NOT.masque_lu) mask=0.0
+  WRITE(lunout,*)'Masque lu: ',masque_lu
+
+!--- EXTENSION OF THE INPUT DATABASE TO PROCEED COMPUTATIONS AT BOUNDARIES:
+  ALLOCATE(xusn(imdp+2*iext))
+  xusn(1     +iext:imdp  +iext)=xd(:)
+  xusn(1          :       iext)=xd(1+imdp-iext:imdp)-2.*xpi
+  xusn(1+imdp+iext:imdp+2*iext)=xd(1          :iext)+2.*xpi
+
+  ALLOCATE(yusn(jmdp+2))
+  yusn(1       )=yd(1)   +(yd(1)   -yd(2))
+  yusn(2:jmdp+1)=yd(:)
+  yusn(  jmdp+2)=yd(jmdp)+(yd(jmdp)-yd(jmdp-1))
+
+  ALLOCATE(zusn(imdp+2*iext,jmdp+2))
+  zusn(1       +iext:imdp  +iext,2:jmdp+1)=zd  (:                   ,     :)
+  zusn(1            :       iext,2:jmdp+1)=zd  (imdp-iext+1:imdp    ,     :)
+  zusn(1+imdp  +iext:imdp+2*iext,2:jmdp+1)=zd  (1:iext              ,     :)
+  zusn(1            :imdp/2+iext,       1)=zusn(1+imdp/2:imdp  +iext,     2)
+  zusn(1+imdp/2+iext:imdp+2*iext,       1)=zusn(1       :imdp/2+iext,     2)
+  zusn(1            :imdp/2+iext,  jmdp+2)=zusn(1+imdp/2:imdp  +iext,jmdp+1)
+  zusn(1+imdp/2+iext:imdp+2*iext,  jmdp+2)=zusn(1       :imdp/2+iext,jmdp+1)
+
+!--- COMPUTE LIMITS OF MODEL GRIDPOINT AREA (REGULAR GRID)
+  ALLOCATE(a(imar+1),b(imar+1))
+  b(1:imar)=(x(1:imar  )+ x(2:imar+1))/2.0
+  b(imar+1)= x(  imar+1)+(x(  imar+1)-x(imar))/2.0
+  a(1)=x(1)-(x(2)-x(1))/2.0
+  a(2:imar+1)= b(1:imar)
+
+  ALLOCATE(c(jmar),d(jmar))
+  d(1:jmar-1)=(y(1:jmar-1)+ y(2:jmar))/2.0
+  d(  jmar  )= y(  jmar  )+(y(  jmar)-y(jmar-1))/2.0
+  c(1)=y(1)-(y(2)-y(1))/2.0
+  c(2:jmar)=d(1:jmar-1)
+
+!--- INITIALIZATIONS:
+  ALLOCATE(weight(imar+1,jmar)); weight(:,:)= 0.0
+  ALLOCATE(zmea  (imar+1,jmar)); zmea  (:,:)= 0.0
+
+!--- SUMMATION OVER GRIDPOINT AREA
+  zleny=xpi/REAL(jmdp)*rad
+  xincr=xpi/REAL(jmdp)/2.
+  ALLOCATE(num_tot(imar+1,jmar)); num_tot(:,:)=0.
+  ALLOCATE(num_lan(imar+1,jmar)); num_lan(:,:)=0.
+  DO ii = 1, imar+1
+    DO jj = 1, jmar
+      DO j = 2,jmdp+1 
+        zlenx  =zleny  *COS(yusn(j))
+        zbordnor=(xincr+c(jj)-yusn(j))*rad
+        zbordsud=(xincr-d(jj)+yusn(j))*rad
+        weighy=AMAX1(0.,AMIN1(zbordnor,zbordsud,zleny))
+        IF(weighy/=0) THEN
+          DO i = 2, imdp+2*iext-1
+            zbordest=(xusn(i)-a(ii)+xincr)*rad*COS(yusn(j))
+            zbordoue=(b(ii)+xincr-xusn(i))*rad*COS(yusn(j))
+            weighx=AMAX1(0.,AMIN1(zbordest,zbordoue,zlenx))
+            IF(weighx/=0)THEN
+              num_tot(ii,jj)=num_tot(ii,jj)+1.0
+              IF(zusn(i,j)>=1.)num_lan(ii,jj)=num_lan(ii,jj)+1.0
+              weight(ii,jj)=weight(ii,jj)+weighx*weighy
+              zmea  (ii,jj)=zmea  (ii,jj)+zusn(i,j)*weighx*weighy !--- MEAN
+            END IF
+          END DO
+        END IF
+      END DO
+    END DO
+  END DO
+
+!--- COMPUTE PARAMETERS NEEDED BY LOTT & MILLER (1997) AND LOTT (1999) SSO SCHEME
+  IF(.NOT.masque_lu) THEN
+    WHERE(weight(:,1:jmar-1)/=0.0) mask=num_lan(:,:)/num_tot(:,:)
+  END IF
+  nn=COUNT(weight(:,1:jmar-1)==0.0)
+  IF(nn/=0) WRITE(lunout,*)'Problem with weight ; vanishing occurrences: ',nn
+  WHERE(weight/=0.0) zmea(:,:)=zmea(:,:)/weight(:,:)
+
+!--- MASK BASED ON GROUND MAXIMUM, 10% THRESHOLD (<10%: SURF PARAMS MEANINGLESS)
+  ALLOCATE(mask_tmp(imar+1,jmar)); mask_tmp(:,:)=0.0
+  WHERE(mask>=0.1) mask_tmp = 1.
+  WHERE(weight(:,:)/=0.0)
+    zphi(:,:)=mask_tmp(:,:)*zmea(:,:)
+    zmea(:,:)=mask_tmp(:,:)*zmea(:,:)
+  END WHERE
+  WRITE(lunout,*)'  MEAN ORO:' ,MAXVAL(zmea)
+
+!--- Values at poles
+  zphi(imar+1,:)=zphi(1,:)
+
+  zweinor=SUM(weight(1:imar,   1),DIM=1)
+  zweisud=SUM(weight(1:imar,jmar),DIM=1)
+  zmeanor=SUM(weight(1:imar,   1)*zmea(1:imar,   1),DIM=1)
+  zmeasud=SUM(weight(1:imar,jmar)*zmea(1:imar,jmar),DIM=1)
+  zphi(:,1)=zmeanor/zweinor; zphi(:,jmar)=zmeasud/zweisud
+
+END SUBROUTINE grid_noro0
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
 SUBROUTINE MVA9(x)
 !
Index: /LMDZ5/branches/testing/libf/phylmd/nuage.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/nuage.h	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/nuage.h	(revision 2594)
@@ -9,9 +9,10 @@
       REAL tmax_fonte_cv
 
-      INTEGER iflag_t_glace,iflag_cld_cv
+      INTEGER iflag_t_glace, iflag_cloudth_vert, iflag_cld_cv
 
       common /nuagecom/ rad_froid,rad_chau1, rad_chau2,t_glace_max,     &
      &                  t_glace_min,exposant_glace,rei_min,rei_max,     &
      &                  tau_cld_cv,coefw_cld_cv,                        &
-     &                  iflag_t_glace,iflag_cld_cv,tmax_fonte_cv
+     &                  iflag_t_glace,iflag_cloudth_vert,iflag_cld_cv,  &
+     &                  tmax_fonte_cv
 !$OMP THREADPRIVATE(/nuagecom/)
Index: /LMDZ5/branches/testing/libf/phylmd/phyetat0.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phyetat0.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/phyetat0.F90	(revision 2594)
@@ -18,5 +18,5 @@
        wake_deltat, wake_delta_pbl_TKE, delta_tsurf, wake_fip, wake_pe, &
        wake_s, zgam, zmax0, zmea, zpic, zsig, &
-       zstd, zthe, zval, ale_bl, ale_bl_trig, alp_bl
+       zstd, zthe, zval, ale_bl, ale_bl_trig, alp_bl, u10m, v10m
   USE geometry_mod, ONLY : longitude_deg, latitude_deg
   USE iostart, ONLY : close_startphy, get_field, get_var, open_startphy
@@ -260,6 +260,7 @@
   ENDDO
 
-
-  
+  found=phyetat0_srf(1,u10m,"U10M","u a 10m",0.)
+  found=phyetat0_srf(1,v10m,"V10M","v a 10m",0.)
+
 !===================================================================
   ! Lecture des temperatures du sol profond:
Index: /LMDZ5/branches/testing/libf/phylmd/phyredem.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phyredem.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/phyredem.F90	(revision 2594)
@@ -21,5 +21,5 @@
                                 wake_pe, wake_fip, fm_therm, entr_therm,     &
                                 detr_therm, Ale_bl, Ale_bl_trig, Alp_bl,     &
-                                du_gwd_rando, du_gwd_front
+                                du_gwd_rando, du_gwd_front, u10m, v10m
   USE geometry_mod, ONLY : longitude_deg, latitude_deg
   USE iostart, ONLY: open_restartphy, close_restartphy, put_field, put_var
@@ -153,4 +153,9 @@
 
   
+  CALL put_field_srf1("U10M", "u a 10m", u10m)
+
+  CALL put_field_srf1("V10M", "v a 10m", v10m)
+
+
 ! ================== Tsoil =========================================
   CALL put_field_srf2("Tsoil","Temperature",tsoil(:,:,:))
Index: /LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90	(revision 2594)
@@ -16,4 +16,6 @@
       REAL, SAVE, ALLOCATABLE :: u_seri(:,:), v_seri(:,:)
       !$OMP THREADPRIVATE(u_seri, v_seri)
+      REAL, SAVE, ALLOCATABLE :: l_mixmin(:,:,:), l_mix(:,:,:)
+      !$OMP THREADPRIVATE(l_mixmin, l_mix)
 
       REAL, SAVE, ALLOCATABLE :: tr_seri(:,:,:)
@@ -406,4 +408,6 @@
       allocate(t_seri(klon,klev),q_seri(klon,klev),ql_seri(klon,klev),qs_seri(klon,klev))
       allocate(u_seri(klon,klev),v_seri(klon,klev))
+      allocate(l_mixmin(klon,klev,nbsrf), l_mix(klon,klev,nbsrf))
+      l_mix(:,:,:)=0. ; l_mixmin(:,:,:)=0. ! doit etre initialse car pas toujours remplis
 
       allocate(tr_seri(klon,klev,nbtr))
@@ -625,4 +629,5 @@
       deallocate(t_seri,q_seri,ql_seri,qs_seri)
       deallocate(u_seri,v_seri)
+      deallocate(l_mixmin,l_mix)
 
       deallocate(tr_seri)
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 2594)
@@ -41,4 +41,173 @@
 
 !!! 2D
+
+! Marine
+
+  TYPE(ctrl_out), SAVE :: o_alt_tropo = ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'alt_tropo','Tropopause pressure','hPa',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_prop_hc = ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_prop_hc','Proportion of high clouds',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_prop_hist = &
+  ctrl_out((/1,1,1,1,1,1,10,10,10/),&
+  'map_prop_hist','Proportion of high ice semi-transp clouds',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_emis_hc = &
+  ctrl_out((/1,1,1,1,1,1,10,10,10/),&
+  'map_emis_hc','Emissivity of high clouds',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_iwp_hc = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_iwp_hc','Ice water path of high clouds','g/m2',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_deltaz_hc = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_deltaz_hc','geom thickness of high clouds','m',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_pcld_hc = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_pcld_hc','cloud pressure of high clouds','hPa',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+   TYPE(ctrl_out), SAVE :: o_map_tcld_hc = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_tcld_hc','cloud temperature of high clouds','K',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+
+  TYPE(ctrl_out), SAVE :: o_map_emis_hist = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_emis_hist','Emissivity of high ice st clouds',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_iwp_hist = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_iwp_hist','Ice water path of high ice st clouds','g/m2',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_deltaz_hist = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_deltaz_hist','geom thickness of high ice st clouds','m',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_rad_hist = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_rad_hist','ice crystals radius in high ice st clouds','µm',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+
+ TYPE(ctrl_out), SAVE :: o_map_emis_Cb = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_emis_Cb','Emissivity of high Cb clouds',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+ TYPE(ctrl_out), SAVE :: o_map_pcld_Cb = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_pcld_Cb','cloud pressure of high Cb clouds','hPa',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+ TYPE(ctrl_out), SAVE :: o_map_tcld_Cb = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_tcld_Cb','cloud temperature of high Cb clouds','K',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+
+ TYPE(ctrl_out), SAVE :: o_map_emis_Anv = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_emis_Anv','Emissivity of high Anv clouds',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+ TYPE(ctrl_out), SAVE :: o_map_pcld_Anv = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_pcld_Anv','cloud pressure of high Anv clouds','hPa',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_tcld_Anv = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_tcld_Anv','cloud temperature of high Anv clouds','K',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_emis_ThCi = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_emis_ThCi','Emissivity of high ThCi clouds',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_pcld_ThCi = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_pcld_ThCi','cloud pressure of high ThCi clouds','hPa',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_tcld_ThCi = &
+  ctrl_out((/10,10,1,10,10,10,10,10,10/),&
+  'map_tcld_ThCi','cloud temperature of high ThCi clouds','K',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+   TYPE(ctrl_out), SAVE :: o_map_ntot = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_ntot','total AIRS cloud fraction',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_hc = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_hc','high clouds AIRS cloud fraction',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_hist = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_hist','high clouds ice st AIRS cloud fraction',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+  TYPE(ctrl_out), SAVE :: o_map_Cb = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_Cb','high clouds Cb AIRS cloud fraction',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+ TYPE(ctrl_out), SAVE :: o_map_ThCi = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_ThCi','high clouds ThCi AIRS cloud fraction',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+ TYPE(ctrl_out), SAVE :: o_map_Anv = &
+  ctrl_out((/1,1,1,1,1,10,10,10,10/),&
+  'map_Anv','high clouds Anv AIRS cloud fraction',' ',&
+   (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)",&
+    "inst(X)", "inst(X)","inst(X)" /))
+
+
+! Fin Marine
+
   TYPE(ctrl_out), SAVE :: o_flat = ctrl_out((/ 5, 1, 10, 10, 5, 10, 11, 11, 11 /), &
     'flat', 'Latent heat flux', 'W/m2', (/ ('', i=1, 9) /))
@@ -745,11 +914,31 @@
   TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_tke_srf      = (/             &
       ctrl_out((/ 10, 4, 10, 10, 10, 10, 11, 11, 11 /),'tke_ter',       &
-      "Max Turb. Kinetic Energy "//clnsurf(1),"-", (/ ('', i=1, 9) /)), &
+      "Max Turb. Kinetic Energy "//clnsurf(1),"m2/s2", (/ ('', i=1, 9) /)), &
       ctrl_out((/ 10, 4, 10, 10, 10, 10, 11, 11, 11 /),'tke_lic',       &
-      "Max Turb. Kinetic Energy "//clnsurf(2),"-", (/ ('', i=1, 9) /)), &
+      "Max Turb. Kinetic Energy "//clnsurf(2),"m2/s2", (/ ('', i=1, 9) /)), &
       ctrl_out((/ 10, 4, 10, 10, 10, 10, 11, 11, 11 /),'tke_oce',       &
-      "Max Turb. Kinetic Energy "//clnsurf(3),"-", (/ ('', i=1, 9) /)), &
+      "Max Turb. Kinetic Energy "//clnsurf(3),"m2/s2", (/ ('', i=1, 9) /)), &
       ctrl_out((/ 10, 4, 10, 10, 10, 10, 11, 11, 11 /),'tke_sic',       &
-      "Max Turb. Kinetic Energy "//clnsurf(4),"-", (/ ('', i=1, 9) /)) /)
+      "Max Turb. Kinetic Energy "//clnsurf(4),"m2/s2", (/ ('', i=1, 9) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_l_mixmin      = (/             &
+      ctrl_out((/ 10, 10, 10, 10, 10, 10, 11, 11, 11 /),'l_mixmin_ter',       &
+      "PBL mixing length "//clnsurf(1),"m", (/ ('', i=1, 9) /)), &
+      ctrl_out((/ 10, 10, 10, 10, 10, 10, 11, 11, 11 /),'l_mixmin_lic',       &
+      "PBL mixing length "//clnsurf(2),"m", (/ ('', i=1, 9) /)), &
+      ctrl_out((/ 10, 10, 10, 10, 10, 10, 11, 11, 11 /),'l_mixmin_oce',       &
+      "PBL mixing length "//clnsurf(3),"m", (/ ('', i=1, 9) /)), &
+      ctrl_out((/ 10, 10, 10, 10, 10, 10, 11, 11, 11 /),'l_mixmin_sic',       &
+      "PBL mixing length "//clnsurf(4),"m", (/ ('', i=1, 9) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_l_mix      = (/             &
+      ctrl_out((/ 10, 10, 10, 10, 10, 10, 11, 11, 11 /),'l_mix_ter',       &
+      "min PBL mixing length "//clnsurf(1),"m", (/ ('', i=1, 9) /)), &
+      ctrl_out((/ 10, 10, 10, 10, 10, 10, 11, 11, 11 /),'l_mix_lic',       &
+      "min PBL mixing length "//clnsurf(2),"m", (/ ('', i=1, 9) /)), &
+      ctrl_out((/ 10, 10, 10, 10, 10, 10, 11, 11, 11 /),'l_mix_oce',       &
+      "min PBL mixing length "//clnsurf(3),"m", (/ ('', i=1, 9) /)), &
+      ctrl_out((/ 10, 10, 10, 10, 10, 10, 11, 11, 11 /),'l_mix_sic',       &
+      "min PBL mixing length "//clnsurf(4),"m", (/ ('', i=1, 9) /)) /)
 
   TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_tke_max_srf  = (/                          &
@@ -968,5 +1157,7 @@
     'ovapinit', 'Specific humidity (begin of timestep)', 'kg/kg', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_oliq = ctrl_out((/ 2, 3, 4, 10, 10, 10, 11, 11, 11 /), &
-    'oliq', 'Condensed water', 'kg/kg', (/ ('', i=1, 9) /))
+    'oliq', 'Liquid water', 'kg/kg', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_ocond = ctrl_out((/ 2, 3, 4, 10, 10, 10, 11, 11, 11 /), &
+    'ocond', 'Condensed water', 'kg/kg', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_wvapp = ctrl_out((/ 2, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'wvapp', '', '', (/ ('', i=1, 9) /))
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90	(revision 2594)
@@ -56,4 +56,5 @@
     include "clesphys.h"
     include "thermcell.h"
+    include "YOMCST.h"
 
     ! ug Nouveaux arguments n\'ecessaires au histwrite_mod:
@@ -263,5 +264,5 @@
      ELSE
          CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
-         CALL ymds2ju(annee_ref, 1, day_ini, start_time, zjulian_start)
+         CALL ymds2ju(annee_ref, 1, day_ini, start_time*rday, zjulian_start)
      END IF
 
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90	(revision 2594)
@@ -16,13 +16,32 @@
   INTEGER, SAVE, ALLOCATABLE ::  itau_con(:)       ! Nombre de pas ou rflag <= 1
   !$OMP THREADPRIVATE(itau_con)
-  REAL, ALLOCATABLE :: bils_ec(:) ! Contribution of energy conservation
-  REAL, ALLOCATABLE :: bils_ech(:) ! Contribution of energy conservation
-  REAL, ALLOCATABLE :: bils_tke(:) ! Contribution of energy conservation
-  REAL, ALLOCATABLE :: bils_diss(:) ! Contribution of energy conservation
-  REAL, ALLOCATABLE :: bils_kinetic(:) ! bilan de chaleur au sol, kinetic
-  REAL, ALLOCATABLE :: bils_enthalp(:) ! bilan de chaleur au sol
-  REAL, ALLOCATABLE :: bils_latent(:) ! bilan de chaleur au sol
+  REAL, SAVE, ALLOCATABLE :: bils_ec(:) ! Contribution of energy conservation
+  REAL, SAVE, ALLOCATABLE :: bils_ech(:) ! Contribution of energy conservation
+  REAL, SAVE, ALLOCATABLE :: bils_tke(:) ! Contribution of energy conservation
+  REAL, SAVE, ALLOCATABLE :: bils_diss(:) ! Contribution of energy conservation
+  REAL, SAVE, ALLOCATABLE :: bils_kinetic(:) ! bilan de chaleur au sol, kinetic
+  REAL, SAVE, ALLOCATABLE :: bils_enthalp(:) ! bilan de chaleur au sol
+  REAL, SAVE, ALLOCATABLE :: bils_latent(:) ! bilan de chaleur au sol
   !$OMP THREADPRIVATE(bils_ec,bils_ech,bils_tke,bils_diss,bils_kinetic,bils_enthalp,bils_latent)
 
+! Marine
+! Variables de sortie du simulateur AIRS
+
+  REAL, SAVE, ALLOCATABLE :: map_prop_hc(:),map_prop_hist(:),alt_tropo(:)
+  !$OMP THREADPRIVATE(map_prop_hc,map_prop_hist,alt_tropo)
+  REAL, SAVE, ALLOCATABLE :: map_emis_hc(:),map_iwp_hc(:),map_deltaz_hc(:), &
+                       map_pcld_hc(:),map_tcld_hc(:)
+  !$OMP THREADPRIVATE(map_emis_hc,map_iwp_hc,map_deltaz_hc,map_pcld_hc,map_tcld_hc)
+  REAL, SAVE, ALLOCATABLE :: map_emis_hist(:),map_iwp_hist(:),map_deltaz_hist(:),map_rad_hist(:)         
+  !$OMP THREADPRIVATE(map_emis_hist,map_iwp_hist,map_deltaz_hist,map_rad_hist)
+  REAL, SAVE, ALLOCATABLE :: map_ntot(:),map_hc(:),map_hist(:)
+  REAL, SAVE, ALLOCATABLE :: map_Cb(:),map_ThCi(:),map_Anv(:)
+  !$OMP THREADPRIVATE(map_ntot,map_hc,map_hist,map_Cb,map_ThCi,map_Anv)
+  REAL, SAVE, ALLOCATABLE :: map_emis_Cb(:),map_pcld_Cb(:),map_tcld_Cb(:)
+  REAL, SAVE, ALLOCATABLE :: map_emis_ThCi(:),map_pcld_ThCi(:),map_tcld_ThCi(:)
+  !$OMP THREADPRIVATE(map_emis_Cb,map_pcld_Cb,map_tcld_Cb,map_emis_ThCi)
+  REAL, SAVE, ALLOCATABLE :: map_emis_Anv(:),map_pcld_Anv(:),map_tcld_Anv(:)
+  !$OMP THREADPRIVATE(map_pcld_ThCi,map_tcld_ThCi,map_emis_Anv,map_pcld_Anv,map_tcld_Anv)              
+   
 
   ! ug Plein de variables venues de phys_output_mod
@@ -103,4 +122,21 @@
     allocate (bils_ec(klon),bils_ech(klon),bils_tke(klon),bils_diss(klon),bils_kinetic(klon),bils_enthalp(klon),bils_latent(klon))
 
+! Marine
+! Variables de sortie simulateur AIRS
+
+!     if (ok_airs) then
+      allocate (map_prop_hc(klon),map_prop_hist(klon))
+      allocate (alt_tropo(klon))
+      allocate (map_emis_hc(klon),map_iwp_hc(klon),map_deltaz_hc(klon))
+      allocate (map_pcld_hc(klon),map_tcld_hc(klon))
+      allocate (map_emis_hist(klon),map_iwp_hist(klon),map_deltaz_hist(klon))
+      allocate (map_rad_hist(klon))
+      allocate (map_ntot(klon),map_hc(klon),map_hist(klon))
+      allocate (map_Cb(klon),map_ThCi(klon),map_Anv(klon))
+      allocate (map_emis_Cb(klon),map_pcld_Cb(klon),map_tcld_Cb(klon))
+      allocate (map_emis_ThCi(klon),map_pcld_ThCi(klon),map_tcld_ThCi(klon))
+      allocate (map_emis_Anv(klon),map_pcld_Anv(klon),map_tcld_Anv(klon))
+!     endif
+
     IF (ok_hines) allocate(zustr_gwd_hines(klon), zvstr_gwd_hines(klon))
     IF (.not.ok_hines.and.ok_gwd_rando) &
@@ -115,6 +151,25 @@
     IMPLICIT NONE
 
+    include "clesphys.h"
+
     deallocate(snow_o,zfra_o,itau_con)
     deallocate (bils_ec,bils_ech,bils_tke,bils_diss,bils_kinetic,bils_enthalp,bils_latent)
+
+! Marine
+! Variables de sortie simulateur AIRS
+
+ !    if (ok_airs) then
+      deallocate (map_prop_hc,map_prop_hist)
+      deallocate (alt_tropo)
+      deallocate (map_emis_hc,map_iwp_hc,map_deltaz_hc)
+      deallocate (map_pcld_hc,map_tcld_hc)
+      deallocate (map_emis_hist,map_iwp_hist,map_deltaz_hist)
+      deallocate (map_rad_hist)
+      deallocate (map_ntot,map_hc,map_hist)
+      deallocate (map_Cb,map_ThCi,map_Anv)
+      deallocate (map_emis_Cb,map_pcld_Cb,map_tcld_Cb)
+      deallocate (map_emis_ThCi,map_pcld_ThCi,map_tcld_ThCi)
+      deallocate (map_emis_Anv,map_pcld_Anv,map_tcld_Anv)
+  !   endif
 
   END SUBROUTINE phys_output_var_end
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_write_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_write_mod.F90	(revision 2594)
@@ -60,4 +60,5 @@
          o_fsw_srf, o_wbils_srf, o_wbilo_srf, &
          o_tke_srf, o_tke_max_srf,o_dltpbltke_srf, o_wstar, &
+         o_l_mixmin,o_l_mix, &
          o_cdrm, o_cdrh, o_cldl, o_cldm, o_cldh, &
          o_cldt, o_JrNt, o_cldljn, o_cldmjn, &
@@ -116,5 +117,5 @@
          o_lcc3dstra, o_reffclwtop, o_ec550aer, &
          o_lwcon, o_iwcon, o_temp, o_theta, &
-         o_ovapinit, o_ovap, o_oliq, o_geop, &
+         o_ovapinit, o_ovap, o_oliq, o_ocond, o_geop, &
          o_vitu, o_vitv, o_vitw, o_pres, o_paprs, &
          o_zfull, o_zhalf, o_rneb, o_rnebjn, o_rnebcon, &
@@ -167,5 +168,16 @@
          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
+         o_lat_prec_sol_oce, o_lat_prec_sol_sic, &
+! Marine
+         o_map_prop_hc, o_map_prop_hist, o_map_emis_hc, o_map_iwp_hc, &
+         o_map_deltaz_hc, o_map_pcld_hc, o_map_tcld_hc, &
+         o_map_emis_hist, o_map_iwp_hist, o_map_deltaz_hist, &
+         o_map_rad_hist, &
+         o_map_emis_Cb, o_map_pcld_Cb, o_map_tcld_Cb, &
+         o_map_emis_ThCi, o_map_pcld_ThCi, o_map_tcld_ThCi, &
+         o_map_emis_Anv, o_map_pcld_Anv, o_map_tcld_Anv, &
+         o_map_ntot, o_map_hc,o_map_hist,o_map_Cb,o_map_ThCi,o_map_Anv, &
+         o_alt_tropo
+
 
     USE phys_state_var_mod, only: pctsrf, paire_ter, rain_fall, snow_fall, &
@@ -198,4 +210,5 @@
     USE phys_local_var_mod, only: zxfluxlat, slp, ptstar, pt0, zxtsol, zt2m, &
          t2m_min_mon, t2m_max_mon, evap, &
+         l_mixmin,l_mix, &
          zu10m, zv10m, zq2m, zustar, zxqsurf, &
          rain_lsc, rain_num, snow_lsc, bils, sens, fder, &
@@ -237,5 +250,5 @@
          lcc, lcc3d, lcc3dcon, lcc3dstra, reffclwtop, &
          ec550aer, flwc, fiwc, t_seri, theta, q_seri, &
-         ql_seri, tr_seri, &
+         ql_seri, qs_seri, tr_seri, &
          zphi, u_seri, v_seri, omega, cldfra, &
          rneb, rnebjn, zx_rh, d_t_dyn,  & 
@@ -262,5 +275,18 @@
          zustr_gwd_hines, zvstr_gwd_hines,zustr_gwd_rando, zvstr_gwd_rando, &
          zustr_gwd_front, zvstr_gwd_front,     &
-         sens_prec_liq_o, sens_prec_sol_o, lat_prec_liq_o, lat_prec_sol_o
+         sens_prec_liq_o, sens_prec_sol_o, lat_prec_liq_o, lat_prec_sol_o, &
+! Marine
+         map_prop_hc, map_prop_hist, &
+         map_emis_hc,map_iwp_hc,map_deltaz_hc,&
+         map_pcld_hc,map_tcld_hc,&
+         map_emis_hist,map_iwp_hist,map_deltaz_hist,&
+         map_rad_hist,&
+         map_ntot,map_hc,map_hist,&
+         map_Cb,map_ThCi,map_Anv,&
+         map_emis_Cb,map_pcld_Cb,map_tcld_Cb,&
+         map_emis_ThCi,map_pcld_ThCi,map_tcld_ThCi,&
+         map_emis_Anv,map_pcld_Anv,map_tcld_Anv, &
+         alt_tropo
+
   
 
@@ -331,5 +357,5 @@
 
     ! On calcul le nouveau tau:
-    itau_w = itau_phy + itap + start_time * day_step_phy
+    itau_w = itau_phy + itap 
     ! On le donne à iophy pour que les histwrite y aient accès:
     CALL set_itau_iophy(itau_w)
@@ -378,4 +404,42 @@
        CALL histwrite_phy(o_aireTER, paire_ter)
 !!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Simulateur AIRS
+     IF (ok_airs) then
+      CALL histwrite_phy(o_alt_tropo,alt_tropo)
+ 
+      CALL histwrite_phy(o_map_prop_hc,map_prop_hc)
+      CALL histwrite_phy(o_map_prop_hist,map_prop_hist)
+
+      CALL histwrite_phy(o_map_emis_hc,map_emis_hc)
+      CALL histwrite_phy(o_map_iwp_hc,map_iwp_hc)
+      CALL histwrite_phy(o_map_deltaz_hc,map_deltaz_hc)
+      CALL histwrite_phy(o_map_pcld_hc,map_pcld_hc)
+      CALL histwrite_phy(o_map_tcld_hc,map_tcld_hc)
+
+      CALL histwrite_phy(o_map_emis_hist,map_emis_hist)
+      CALL histwrite_phy(o_map_iwp_hist,map_iwp_hist)
+      CALL histwrite_phy(o_map_deltaz_hist,map_deltaz_hist)
+
+      CALL histwrite_phy(o_map_ntot,map_ntot)
+      CALL histwrite_phy(o_map_hc,map_hc)
+      CALL histwrite_phy(o_map_hist,map_hist)
+
+      CALL histwrite_phy(o_map_Cb,map_Cb)
+      CALL histwrite_phy(o_map_ThCi,map_ThCi)
+      CALL histwrite_phy(o_map_Anv,map_Anv)
+
+      CALL histwrite_phy(o_map_emis_Cb,map_emis_Cb)
+      CALL histwrite_phy(o_map_pcld_Cb,map_pcld_Cb)
+      CALL histwrite_phy(o_map_tcld_Cb,map_tcld_Cb)
+
+      CALL histwrite_phy(o_map_emis_ThCi,map_emis_ThCi)
+      CALL histwrite_phy(o_map_pcld_ThCi,map_pcld_ThCi)
+      CALL histwrite_phy(o_map_tcld_ThCi,map_tcld_ThCi)
+
+      CALL histwrite_phy(o_map_emis_Anv,map_emis_Anv)
+      CALL histwrite_phy(o_map_pcld_Anv,map_pcld_Anv)
+      CALL histwrite_phy(o_map_tcld_Anv,map_tcld_Anv)
+     ENDIF
+
        CALL histwrite_phy(o_flat, zxfluxlat)
        CALL histwrite_phy(o_ptstar, ptstar)
@@ -619,4 +683,6 @@
           IF (iflag_pbl > 1) THEN
              CALL histwrite_phy(o_tke_srf(nsrf),  pbl_tke(:,1:klev,nsrf))
+             CALL histwrite_phy(o_l_mix(nsrf),  l_mix(:,1:klev,nsrf))
+             CALL histwrite_phy(o_l_mixmin(nsrf),  l_mixmin(:,1:klev,nsrf))
              CALL histwrite_phy(o_tke_max_srf(nsrf),  pbl_tke(:,1:klev,nsrf))
           ENDIF
@@ -1055,4 +1121,5 @@
        CALL histwrite_phy(o_ovap, q_seri)
        CALL histwrite_phy(o_oliq, ql_seri)
+       CALL histwrite_phy(o_ocond, ql_seri+qs_seri)
        CALL histwrite_phy(o_geop, zphi)
        CALL histwrite_phy(o_vitu, u_seri)
Index: /LMDZ5/branches/testing/libf/phylmd/physiq_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/physiq_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/physiq_mod.F90	(revision 2594)
@@ -1077,6 +1077,6 @@
        !RC
        ustar(:,:)=0.
-       u10m(:,:)=0.
-       v10m(:,:)=0.
+!       u10m(:,:)=0.
+!       v10m(:,:)=0.
        rain_con(:)=0.
        snow_con(:)=0.
@@ -1165,8 +1165,14 @@
 
        CALL phyetat0 ("startphy.nc",clesphy0,tabcntr0)
+!jyg<
        IF (klon_glo==1) THEN
-          coefh=0. ; coefm=0. ; pbl_tke=0.
-          coefh(:,2,:)=1.e-2 ; coefm(:,2,:)=1.e-2 ; pbl_tke(:,2,:)=1.e-2
-          PRINT*,'FH WARNING : lignes a supprimer'
+          pbl_tke(:,:,is_ave) = 0.
+          DO nsrf=1,nbsrf
+            DO k = 1,klev+1
+                 pbl_tke(:,k,is_ave) = pbl_tke(:,k,is_ave) &
+                     +pctsrf(:,nsrf)*pbl_tke(:,k,nsrf)
+            ENDDO
+          ENDDO
+!>jyg
        ENDIF
        !IM begin
@@ -1424,4 +1430,5 @@
                klon, &
                nqtot, &
+               nqo, &
                pdtphys, &
                annee_ref, &
@@ -2294,5 +2301,5 @@
                     wake_pe, wake_fip,  &
                     Ale_bl, Ale_bl_trig, Alp_bl, &
-                    Ale, Alp )
+                    Ale, Alp , Ale_wake, Alp_wake)
 !>jyg
 !
@@ -2776,8 +2783,18 @@
 !jyg<
 !
-          CALL alpale_th( dtime, lmax_th, t_seri, &
+          CALL alpale_th( dtime, lmax_th, t_seri, cell_area,  &
                           cin, s2, n2,  &
                           ale_bl_trig, ale_bl_stat, ale_bl,  &
-                          alp_bl, alp_bl_stat )
+                          alp_bl, alp_bl_stat, &
+                          proba_notrig, random_notrig)
+
+          ! ------------------------------------------------------------------
+          ! 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
+          ! -------------------------------------------------------------------
 
           do i=1,klon
@@ -3931,4 +3948,28 @@
 #endif
     ENDIF  !ok_cosp
+
+
+! Marine
+
+  IF (ok_airs) then
+
+  IF (itap.eq.1.or.MOD(itap,NINT(freq_airs/dtime)).EQ.0) THEN
+  write(*,*) 'je vais appeler simu_airs, ok_airs, freq_airs=', &
+     & ok_airs, freq_airs
+  call simu_airs(itap,rneb, t_seri, cldemi, fiwc, ref_ice, pphi, pplay, paprs,&
+     & map_prop_hc,map_prop_hist,&
+     & map_emis_hc,map_iwp_hc,map_deltaz_hc,map_pcld_hc,map_tcld_hc,&
+     & map_emis_Cb,map_pcld_Cb,map_tcld_Cb,&
+     & map_emis_ThCi,map_pcld_ThCi,map_tcld_ThCi,&
+     & map_emis_Anv,map_pcld_Anv,map_tcld_Anv,&
+     & map_emis_hist,map_iwp_hist,map_deltaz_hist,map_rad_hist,&
+     & map_ntot,map_hc,map_hist,&
+     & map_Cb,map_ThCi,map_Anv,&
+     & alt_tropo )
+  ENDIF
+
+  ENDIF  ! ok_airs
+
+
     ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     !AA
Index: /LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90	(revision 2594)
@@ -55,5 +55,5 @@
     data piz_strat  /0.9999998, 0.99762493/
     data cg_strat   /0.73107845,0.73229635/
-    real, dimension(nwave) :: alpha_strat_wave
+    real, dimension(nwave_sw) :: alpha_strat_wave
     data alpha_strat_wave/3.36780953,3.34667683,3.20444202,3.0293026,2.82108808/
 
@@ -153,5 +153,5 @@
 
 !--total vertical aod at the 6 wavelengths
-    DO wave=1, nwave
+    DO wave=1, nwave_sw
     DO k=1, klev
     tausum_aero(:,wave,id_STRAT_phy)=tausum_aero(:,wave,id_STRAT_phy)+tau_aer_strat(:,k)*alpha_strat_wave(wave)/alpha_strat_wave(2)
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/aeropt_5wv_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/aeropt_5wv_rrtm.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/aeropt_5wv_rrtm.F90	(revision 2594)
@@ -70,5 +70,5 @@
   ! Local
   !
-  INTEGER, PARAMETER :: las = nwave
+  INTEGER, PARAMETER :: las = nwave_sw
   LOGICAL :: soluble
   
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90	(revision 2594)
@@ -61,9 +61,9 @@
 !--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
+    real, dimension(nwave_sw) :: 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
+!--diagnostics AOD in the LW at 10 um (not normalised by the 550 nm ext coefficient
+    real :: alpha_lw_strat_wave(nwave_lw)
     data alpha_lw_strat_wave/0.2746812/
 !
@@ -171,8 +171,8 @@
 
 !--total vertical aod at the 5 SW wavelengths
-    DO wave=1, nwave
+    DO wave=1, nwave_sw
     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)
+      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
@@ -210,4 +210,12 @@
     ENDIF 
 
+!--total vertical aod at the 1 LW wavelength
+    DO wave=1, nwave_lw
+    DO k=1, klev
+      tausum_aero(:,nwave_sw+wave,id_STRAT_phy)=tausum_aero(:,nwave_sw+wave,id_STRAT_phy)+ &
+         tau_aer_strat(:,k)*alpha_lw_strat_wave(wave)/alpha_sw_strat_wave(2)
+    ENDDO
+    ENDDO
+
     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(:,:)
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90	(revision 2594)
@@ -269,10 +269,11 @@
 !--total vertical aod at the 5 SW wavelengths
 !--for now use band 3 AOD into all 5 wavelengths
+!--it is only a reasonable approximation for 550 nm (wave=2)
     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)
+        DO wave=1, nwave_sw
+          tausum_aero(i,wave,id_STRAT_phy)=tausum_aero(i,wave,id_STRAT_phy)+tau_aer_strat(i,k,band)
         ENDDO
       ENDIF
@@ -308,4 +309,17 @@
     ENDDO
 
+!--total vertical aod at 10 um
+!--this is approximated from band 7 of RRTM
+    band=7
+    DO i=1, klon
+    DO k=1, klev
+      IF (stratomask(i,k).GT.0.999999) THEN
+        DO wave=1, nwave_lw
+          tausum_aero(i,nwave_sw+wave,id_STRAT_phy)=tausum_aero(i,nwave_sw+wave,id_STRAT_phy)+taulw_aer_strat(i,k,band)
+        ENDDO
+      ENDIF
+    ENDDO
+    ENDDO
+
     DO band=1, NLW
     WHERE (stratomask.GT.0.999999)
Index: /LMDZ5/branches/testing/libf/phylmd/simu_airs.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/simu_airs.F90	(revision 2594)
+++ /LMDZ5/branches/testing/libf/phylmd/simu_airs.F90	(revision 2594)
@@ -0,0 +1,1300 @@
+        
+        module m_simu_airs
+
+        implicit none
+
+        real, parameter :: tau_thresh = 0.05 ! seuil nuages detectables
+        real, parameter :: p_thresh = 445.   ! seuil nuages hauts
+        real, parameter :: em_min = 0.2      ! seuils nuages semi-transp
+        real, parameter :: em_max = 0.85
+        real, parameter :: undef = 999.
+
+        contains
+
+        real function search_tropopause(P,T,alt,N) result(P_tropo)
+! this function searches for the tropopause pressure in [hPa].
+! The search is based on ideology described in
+! Reichler et al., Determining the tropopause height from gridded data,
+! GRL, 30(20) 2042, doi:10.1029/2003GL018240, 2003
+
+        integer N,i,i_lev,first_point,exit_flag,i_dir
+        real P(N),T(N),alt(N),slope(N)
+        real P_min, P_max, slope_limit,slope_2km, &
+     & delta_alt_limit,tmp,delta_alt
+        parameter(P_min=75.0, P_max=470.0)   ! hPa
+        parameter(slope_limit=0.002)         ! 2 K/km converted to K/m
+        parameter(delta_alt_limit=2000.0)    ! 2000 meters
+
+        do i=1,N-1
+        slope(i)=-(T(i+1)-T(i))/(alt(i+1)-alt(i))
+        end do
+        slope(N)=slope(N-1)
+
+        if (P(1).gt.P(N)) then
+        i_dir= 1
+        i=1
+        else
+        i_dir=-1
+        i=N
+        end if
+
+        first_point=0
+        exit_flag=0
+        do while(exit_flag.eq.0)
+        if (P(i).ge.P_min.and.P(i).le.P_max) then
+        if (first_point.gt.0) then
+        delta_alt=alt(i)-alt(first_point)
+        if (delta_alt.ge.delta_alt_limit) then
+        slope_2km=(T(first_point)-T(i))/delta_alt
+        if (slope_2km.lt.slope_limit) then
+        exit_flag=1
+        else
+        first_point=0
+        end if
+        end if
+        end if
+        if (first_point.eq.0.and.slope(i).lt.slope_limit) first_point=i
+        end if
+        i=i+i_dir
+        if (i.le.1.or.i.ge.N) exit_flag=1
+        end do
+
+        if (first_point.le.0) P_tropo=65.4321
+        if (first_point.eq.1) P_tropo=64.5432
+        if (first_point.gt.1) then
+        tmp=(slope_limit-slope(first_point))/(slope(first_point+1)- &
+     & slope(first_point))*(P(first_point+1)-P(first_point))
+        P_tropo=P(first_point)+tmp
+        ! print*, 'P_tropo= ', tmp, P(first_point), P_tropo
+        end if
+
+! Ajout Marine
+        if (P_tropo .lt. 60. .or. P_tropo .gt. 470.) then
+        P_tropo = 999.
+        endif
+
+        return
+        end function search_tropopause
+
+
+
+        subroutine cloud_structure(len_cs, rneb_cs, temp_cs, &
+     & emis_cs, iwco_cs, &
+     & pres_cs, dz_cs, rhodz_cs, rad_cs, &
+     & cc_tot_cs, cc_hc_cs, cc_hist_cs, &
+     & cc_Cb_cs, cc_ThCi_cs, cc_Anv_cs, &
+     & pcld_hc_cs, tcld_hc_cs, &
+     & em_hc_cs, iwp_hc_cs, deltaz_hc_cs, &
+     & pcld_Cb_cs, tcld_Cb_cs, em_Cb_cs, &
+     & pcld_ThCi_cs, tcld_ThCi_cs, em_ThCi_cs, &
+     & pcld_Anv_cs, tcld_Anv_cs, em_Anv_cs, &
+     & em_hist_cs, iwp_hist_cs, deltaz_hist_cs, rad_hist_cs)
+
+
+     
+        integer :: i, n, nss
+
+        integer, intent(in) :: len_cs
+        real, dimension(:), intent(in) :: rneb_cs, temp_cs
+        real, dimension(:), intent(in) :: emis_cs, iwco_cs, rad_cs
+        real, dimension(:), intent(in) :: pres_cs, dz_cs, rhodz_cs
+
+        real, intent(out) :: cc_tot_cs, cc_hc_cs, cc_hist_cs, &
+     & cc_Cb_cs, cc_ThCi_cs, cc_Anv_cs, &
+     & pcld_hc_cs, tcld_hc_cs, em_hc_cs, iwp_hc_cs, &
+     & pcld_Cb_cs, tcld_Cb_cs, em_Cb_cs, &
+     & pcld_ThCi_cs, tcld_ThCi_cs, em_ThCi_cs, &
+     & pcld_Anv_cs, tcld_Anv_cs, em_Anv_cs, &
+     & em_hist_cs, iwp_hist_cs, &
+     & deltaz_hc_cs, deltaz_hist_cs, rad_hist_cs
+
+        real, dimension(len_cs) :: rneb_ord
+        real :: rneb_min
+
+        real, dimension(:), allocatable :: s, s_hc, s_hist, rneb_max
+        real, dimension(:), allocatable :: sCb, sThCi, sAnv
+        real, dimension(:), allocatable :: iwp_ss, pcld_ss, tcld_ss,&
+     & emis_ss
+        real, dimension(:), allocatable :: deltaz_ss, rad_ss
+
+
+        write(*,*) 'dans cloud_structure'
+
+        call ordonne(len_cs, rneb_cs, rneb_ord)
+       
+
+! Definition des sous_sections
+
+        rneb_min = rneb_ord(1)
+        nss = 1
+
+        do i = 2, size(rneb_cs)
+        if (rneb_ord(i) .gt. rneb_min) then
+        nss = nss+1
+        rneb_min = rneb_ord(i)
+        endif
+        enddo
+
+        allocate (s(nss))
+        allocate (s_hc(nss))
+        allocate (s_hist(nss))
+        allocate (rneb_max(nss))
+        allocate (emis_ss(nss))
+        allocate (pcld_ss(nss))
+        allocate (tcld_ss(nss))
+        allocate (iwp_ss(nss))
+        allocate (deltaz_ss(nss))
+        allocate (rad_ss(nss))
+        allocate (sCb(nss))
+        allocate (sThCi(nss))
+        allocate (sAnv(nss))
+
+        rneb_min = rneb_ord(1)
+        n = 1
+        s(1) = rneb_ord(1)
+        s_hc(1) = rneb_ord(1)
+        s_hist(1) = rneb_ord(1)
+        sCb(1) = rneb_ord(1)
+        sThCi(1) = rneb_ord(1)
+        sAnv(1) = rneb_ord(1)
+
+        rneb_max(1) = rneb_ord(1)
+
+        do i = 2, size(rneb_cs)
+        if (rneb_ord(i) .gt. rneb_min) then
+        n = n+1
+        s(n) = rneb_ord(i)-rneb_min
+        s_hc(n) = rneb_ord(i)-rneb_min
+        s_hist(n) = rneb_ord(i)-rneb_min
+        sCb(n) = rneb_ord(i)-rneb_min
+        sThCi(n) = rneb_ord(i)-rneb_min
+        sAnv(n) = rneb_ord(i)-rneb_min
+
+        rneb_max(n) = rneb_ord(i)
+        rneb_min = rneb_ord(i)
+        endif
+        enddo
+
+! Appel de sous_section
+
+        do i = 1, nss
+         call sous_section(len_cs, rneb_cs, temp_cs, &
+     &  emis_cs, iwco_cs, &
+     &  pres_cs, dz_cs, rhodz_cs, rad_cs, rneb_ord, &
+     &  rneb_max(i),s(i),s_hc(i),s_hist(i), &
+     &  sCb(i), sThCi(i), sAnv(i), &
+     &  emis_ss(i), &
+     &  pcld_ss(i), tcld_ss(i), iwp_ss(i), deltaz_ss(i), rad_ss(i))
+        enddo
+
+! Caracteristiques de la structure nuageuse
+
+        cc_tot_cs = 0.
+        cc_hc_cs = 0.
+        cc_hist_cs = 0.
+
+        cc_Cb_cs = 0.
+        cc_ThCi_cs = 0.
+        cc_Anv_cs = 0.
+
+        em_hc_cs = 0.
+        iwp_hc_cs = 0.
+        deltaz_hc_cs = 0.
+
+        em_hist_cs = 0.
+        iwp_hist_cs = 0.
+        deltaz_hist_cs = 0.
+        rad_hist_cs = 0.
+
+        pcld_hc_cs = 0.
+        tcld_hc_cs = 0.
+
+        pcld_Cb_cs = 0.
+        tcld_Cb_cs = 0.
+        em_Cb_cs = 0.
+
+        pcld_ThCi_cs = 0.
+        tcld_ThCi_cs = 0.
+        em_ThCi_cs = 0.
+
+        pcld_Anv_cs = 0.
+        tcld_Anv_cs = 0.
+        em_Anv_cs = 0.
+
+         do i = 1, nss
+
+        cc_tot_cs = cc_tot_cs + s(i)
+        cc_hc_cs = cc_hc_cs + s_hc(i)
+        cc_hist_cs = cc_hist_cs + s_hist(i)
+
+        cc_Cb_cs = cc_Cb_cs + sCb(i)
+        cc_ThCi_cs = cc_ThCi_cs + sThCi(i)
+        cc_Anv_cs = cc_Anv_cs + sAnv(i)
+
+        iwp_hc_cs = iwp_hc_cs + s_hc(i)*iwp_ss(i)
+        em_hc_cs = em_hc_cs + s_hc(i)*emis_ss(i)
+        deltaz_hc_cs = deltaz_hc_cs + s_hc(i)*deltaz_ss(i)
+
+        iwp_hist_cs = iwp_hist_cs + s_hist(i)*iwp_ss(i)
+        em_hist_cs = em_hist_cs + s_hist(i)*emis_ss(i)
+        deltaz_hist_cs = deltaz_hist_cs + s_hist(i)*deltaz_ss(i)
+        rad_hist_cs = rad_hist_cs + s_hist(i)*rad_ss(i)
+
+        pcld_hc_cs = pcld_hc_cs + s_hc(i)*pcld_ss(i)
+        tcld_hc_cs = tcld_hc_cs + s_hc(i)*tcld_ss(i)
+
+        pcld_Cb_cs = pcld_Cb_cs + sCb(i)*pcld_ss(i)
+        tcld_Cb_cs = tcld_Cb_cs + sCb(i)*tcld_ss(i)
+        em_Cb_cs = em_Cb_cs + sCb(i)*emis_ss(i)
+
+        pcld_ThCi_cs = pcld_ThCi_cs + sThCi(i)*pcld_ss(i)
+        tcld_ThCi_cs = tcld_ThCi_cs + sThCi(i)*tcld_ss(i)
+        em_ThCi_cs = em_ThCi_cs + sThCi(i)*emis_ss(i)
+
+        pcld_Anv_cs = pcld_Anv_cs + sAnv(i)*pcld_ss(i)
+        tcld_Anv_cs = tcld_Anv_cs + sAnv(i)*tcld_ss(i)
+        em_Anv_cs = em_Anv_cs + sAnv(i)*emis_ss(i)
+
+        enddo
+
+        deallocate(s)
+        deallocate (s_hc)
+        deallocate (s_hist)
+        deallocate (rneb_max)
+        deallocate (emis_ss)
+        deallocate (pcld_ss)
+        deallocate (tcld_ss)
+        deallocate (iwp_ss)
+        deallocate (deltaz_ss)
+        deallocate (rad_ss)
+        deallocate (sCb)
+        deallocate (sThCi)
+        deallocate (sAnv)
+
+       call normal_undef(pcld_hc_cs,cc_hc_cs)
+       call normal_undef(tcld_hc_cs,cc_hc_cs)
+       call normal_undef(iwp_hc_cs,cc_hc_cs)
+       call normal_undef(em_hc_cs,cc_hc_cs)
+       call normal_undef(deltaz_hc_cs,cc_hc_cs)
+       
+       call normal_undef(iwp_hist_cs,cc_hist_cs)
+       call normal_undef(em_hist_cs,cc_hist_cs)
+       call normal_undef(deltaz_hist_cs,cc_hist_cs)
+       call normal_undef(rad_hist_cs,cc_hist_cs)
+
+       call normal_undef(pcld_Cb_cs,cc_Cb_cs)
+       call normal_undef(tcld_Cb_cs,cc_Cb_cs)
+       call normal_undef(em_Cb_cs,cc_Cb_cs)
+
+       call normal_undef(pcld_ThCi_cs,cc_ThCi_cs)
+       call normal_undef(tcld_ThCi_cs,cc_ThCi_cs)
+       call normal_undef(em_ThCi_cs,cc_ThCi_cs)
+    
+       call normal_undef(pcld_Anv_cs,cc_Anv_cs)
+       call normal_undef(tcld_Anv_cs,cc_Anv_cs)
+       call normal_undef(em_Anv_cs,cc_Anv_cs)
+
+
+! Tests
+
+        if (cc_tot_cs .gt. maxval(rneb_cs) .and. &
+     & abs(cc_tot_cs-maxval(rneb_cs)) .gt. 1.e-4 )  then
+        write(*,*) 'cc_tot_cs > max rneb_cs'
+        write(*,*) cc_tot_cs, maxval(rneb_cs)
+        STOP
+        endif
+
+        if (iwp_hc_cs .lt. 0.) then
+        write(*,*) 'cloud_structure:'
+        write(*,*) 'iwp_hc_cs < 0'
+        STOP
+        endif
+ 
+        end subroutine cloud_structure
+
+
+        subroutine normal_undef(num, den)
+
+        real, intent(in) :: den
+        real, intent(inout) :: num
+
+        if (den .ne. 0) then
+        num = num/den
+        else
+        num = undef
+        endif
+
+        end subroutine normal_undef
+
+
+        subroutine normal2_undef(res,num,den)
+
+        real, intent(in) :: den
+        real, intent(in) :: num
+        real, intent(out) :: res
+
+        if (den .ne. 0.) then
+        res = num/den
+        else
+        res = undef
+        endif
+
+        end subroutine normal2_undef
+
+
+        subroutine sous_section(len_cs, rneb_cs, temp_cs, &
+     & emis_cs, iwco_cs, &
+     & pres_cs, dz_cs, rhodz_cs, rad_cs, rneb_ord, &
+     & rnebmax, stot, shc, shist, &
+     & sCb, sThCi, sAnv, &
+     & emis, pcld, tcld, iwp, deltaz, rad)
+
+        integer, intent(in) :: len_cs
+        real, dimension(len_cs), intent(in) :: rneb_cs, temp_cs
+        real, dimension(len_cs), intent(in) :: emis_cs, iwco_cs, &
+     & rneb_ord
+        real, dimension(len_cs), intent(in) :: pres_cs, dz_cs, rad_cs
+        real, dimension(len_cs), intent(in) :: rhodz_cs
+        real, dimension(len_cs) :: tau_cs, w
+        real, intent(in) :: rnebmax
+        real, intent(inout) :: stot, shc, shist
+        real, intent(inout) :: sCb, sThCi, sAnv
+        real, intent(out) :: emis, pcld, tcld, iwp, deltaz, rad
+
+        integer :: i, ideb, ibeg, iend, nuage, visible
+        real :: som, som_tau, som_iwc, som_dz, som_rad, tau
+
+
+! Ponderation: 1 pour les nuages, 0 pour les trous
+
+        do i = 1, len_cs
+        if (rneb_cs(i) .ge. rnebmax) then
+        w(i) = 1.
+        else
+        w(i) = 0.
+        endif
+        enddo
+
+! Calcul des epaisseurs optiques a partir des emissivites
+
+        som = 0.
+        do i = 1, len_cs
+        if (emis_cs(i) .eq. 1.) then
+        tau_cs(i) = 10.
+        else
+        tau_cs(i) = -log(1.-emis_cs(i))
+        endif
+        som = som+tau_cs(i)
+        enddo
+
+
+        ideb = 1
+        nuage = 0
+        visible = 0
+
+
+! Boucle sur les nuages
+        do while (ideb .ne. 0 .and. ideb .le. len_cs)   
+
+
+! Definition d'un nuage de la sous-section
+
+        call topbot(ideb, w, ibeg, iend)
+        ideb = iend+1
+
+        if (ibeg .gt. 0) then
+
+        nuage = nuage + 1
+
+! On determine les caracteristiques du nuage
+! (ep. optique, ice water path, pression, temperature)
+
+        call caract(ibeg, iend, temp_cs, tau_cs, iwco_cs, &
+     & pres_cs, dz_cs, rhodz_cs, rad_cs, pcld, tcld, &
+     & som_tau, som_iwc, som_dz, som_rad)
+
+! On masque le nuage s'il n'est pas detectable
+
+        call masque(ibeg, iend, som_tau, visible, w)
+
+        endif
+
+! Fin boucle nuages
+        enddo
+
+
+! Analyse du nuage detecte
+
+        call topbot(1, w, ibeg, iend)
+
+        if (ibeg .gt. 0) then
+
+        call caract(ibeg, iend, temp_cs, tau_cs, iwco_cs, &
+     & pres_cs, dz_cs, rhodz_cs, rad_cs, pcld, tcld, &
+     & som_tau, som_iwc, som_dz, som_rad)
+
+        tau = som_tau
+        emis = 1. - exp(-tau)
+        iwp = som_iwc
+        deltaz = som_dz
+        rad = som_rad
+
+        if (pcld .gt. p_thresh) then
+
+        shc = 0.
+        shist = 0.
+        sCb = 0.
+        sThCi = 0.
+        sAnv = 0.
+
+        else
+
+        if (emis .lt. em_min .or. emis .gt. em_max  &
+     & .or. tcld .gt. 230.) then
+        shist = 0.
+        endif
+
+        if (emis .lt. 0.98) then
+        sCb = 0.
+        endif
+
+        if (emis .gt. 0.5 .or. emis .lt. 0.1) then
+        sThCi = 0.
+        endif
+
+        if (emis .le. 0.5 .or. emis .ge. 0.98) then
+        sAnv = 0.
+        endif
+
+        endif
+
+        else
+
+        tau = 0.
+        emis = 0.
+        iwp = 0.
+        deltaz = 0.
+        pcld = 0.
+        tcld = 0.
+        stot = 0.
+        shc = 0.
+        shist = 0.
+        rad = 0.
+        sCb = 0.
+        sThCi = 0.
+        sAnv = 0.
+
+        endif
+
+
+! Tests
+
+        if (iwp .lt. 0.) then
+        write(*,*) 'ideb iwp =', ideb, iwp
+        STOP
+        endif
+
+        if (deltaz .lt. 0.) then
+        write(*,*) 'ideb deltaz =', ideb, deltaz
+        STOP
+        endif
+
+        if (emis .lt. 0.048 .and. emis .ne. 0.) then
+        write(*,*) 'ideb emis =', ideb, emis
+        STOP
+        endif
+
+        end subroutine sous_section
+
+
+        subroutine masque (ibeg, iend, som_tau, &
+     & visible, w)
+
+        integer, intent(in) :: ibeg, iend
+        real, intent(in) :: som_tau
+
+        integer, intent(inout) :: visible
+        real, dimension(:), intent(inout) :: w
+
+        integer :: i
+
+
+
+! Masque
+
+! Cas ou il n'y a pas de nuage visible au-dessus
+
+        if (visible .eq. 0) then
+
+        if (som_tau .lt. tau_thresh) then
+        do i = ibeg, iend
+        w(i) = 0.
+        enddo
+        else
+        visible = 1
+        endif
+
+! Cas ou il y a un nuage visible au-dessus
+
+        else
+
+        do i = ibeg, iend
+        w(i) = 0.
+        enddo
+
+        endif
+
+
+        end subroutine masque
+
+
+         subroutine caract (ibeg, iend, temp_cs, tau_cs, iwco_cs, &
+     & pres_cs, dz_cs, rhodz_cs, rad_cs, pcld, tcld, &
+     & som_tau, som_iwc, som_dz, som_rad)
+
+        integer, intent(in) :: ibeg, iend
+        real, dimension(:), intent(in) :: tau_cs, iwco_cs, temp_cs
+        real, dimension(:), intent(in) :: pres_cs, dz_cs, rad_cs
+        real, dimension(:), intent(in) :: rhodz_cs
+        real, intent(out) :: som_tau, som_iwc, som_dz, som_rad
+        real , intent(out) :: pcld, tcld
+
+        integer :: i, ibase, imid
+
+! Somme des epaisseurs optiques et des contenus en glace sur le nuage
+
+        som_tau = 0.
+        som_iwc = 0.
+        som_dz = 0.
+        som_rad = 0.
+        ibase = -100
+
+        do i = ibeg, iend
+
+        som_tau = som_tau + tau_cs(i)
+
+        som_dz = som_dz + dz_cs(i)
+        som_iwc = som_iwc + iwco_cs(i)*1000*rhodz_cs(i)  ! en g/m2
+        som_rad = som_rad + rad_cs(i)*dz_cs(i)
+
+        if (som_tau .gt. 3. .and. ibase .eq. -100) then
+        ibase = i-1
+        endif
+
+        enddo
+
+        if (som_dz .ne. 0.) then
+        som_rad = som_rad/som_dz
+        else
+        write(*,*) 'som_dez = 0 STOP'
+        write(*,*) 'ibeg, iend =', ibeg, iend
+        do i = ibeg, iend
+        write(*,*) dz_cs(i), rhodz_cs(i)
+        enddo
+        STOP
+        endif
+
+! Determination de Pcld et Tcld
+
+       if (ibase .lt. ibeg) then
+       ibase = ibeg
+       endif
+
+       imid = (ibeg+ibase)/2
+
+       pcld = pres_cs(imid)/100.        ! pcld en hPa
+       tcld = temp_cs(imid)
+
+
+       end subroutine caract
+ 
+        subroutine topbot(ideb,w,ibeg,iend)
+
+        integer, intent(in) :: ideb
+        real, dimension(:), intent(in) :: w
+        integer, intent(out) :: ibeg, iend
+
+        integer :: i, itest
+
+        itest = 0
+        ibeg = 0
+        iend = 0
+
+        do i = ideb, size(w)
+
+        if (w(i) .eq. 1. .and. itest .eq. 0) then
+        ibeg = i
+        itest = 1
+        endif
+
+        enddo
+
+
+        i = ibeg
+        do while (w(i) .eq. 1. .and. i .le. size(w))
+        i = i+1
+        enddo
+        iend = i-1
+
+
+        end subroutine topbot
+
+        subroutine ordonne(len_cs, rneb_cs, rneb_ord)
+
+        integer, intent(in) :: len_cs
+        real, dimension(:), intent(in) :: rneb_cs
+        real, dimension(:), intent(out) :: rneb_ord
+
+        integer :: i, j, ind_min
+
+        real, dimension(len_cs) :: rneb
+        real :: rneb_max
+
+
+        do i = 1, size(rneb_cs)
+        rneb(i) = rneb_cs(i)
+        enddo
+
+        do j = 1, size(rneb_cs)
+
+        rneb_max = 100.
+
+        do i = 1, size(rneb_cs)
+        if (rneb(i) .lt. rneb_max) then
+        rneb_max = rneb(i)
+        ind_min = i
+        endif
+        enddo
+
+        rneb_ord(j) = rneb_max
+        rneb(ind_min) = 100.
+
+        enddo
+        
+        end subroutine ordonne
+
+ 
+        subroutine sim_mesh(rneb_1D, temp_1D, emis_1D, &
+     & iwcon_1D, rad_1D, &
+     & pres, dz, &
+     & rhodz_1D, cc_tot_mesh, cc_hc_mesh, cc_hist_mesh, pcld_hc_mesh,&
+     & tcld_hc_mesh, &
+     & em_hc_mesh, iwp_hc_mesh, deltaz_hc_mesh, &
+     & cc_Cb_mesh, cc_ThCi_mesh, cc_Anv_mesh, &
+     & pcld_Cb_mesh, tcld_Cb_mesh, em_Cb_mesh, &
+     & pcld_ThCi_mesh, tcld_ThCi_mesh, em_ThCi_mesh, &
+     & pcld_Anv_mesh, tcld_Anv_mesh, em_Anv_mesh, &
+     & em_hist_mesh, iwp_hist_mesh, deltaz_hist_mesh, rad_hist_mesh)
+
+       USE dimphy
+
+       real, dimension(klev), intent(in) :: rneb_1D, temp_1D, emis_1D, &
+     & iwcon_1D, rad_1D
+        real, dimension(klev), intent(in) :: pres, dz, rhodz_1D
+        real, intent(out) :: cc_tot_mesh, cc_hc_mesh, cc_hist_mesh
+        real, intent(out) :: cc_Cb_mesh, cc_ThCi_mesh, cc_Anv_mesh
+        real, intent(out) :: em_hc_mesh, pcld_hc_mesh, tcld_hc_mesh, &
+     & iwp_hc_mesh
+
+        real, intent(out) :: pcld_Cb_mesh, tcld_Cb_mesh, em_Cb_mesh
+        real, intent(out) :: pcld_ThCi_mesh, tcld_ThCi_mesh, &
+     & em_ThCi_mesh
+        real, intent(out) :: pcld_Anv_mesh, tcld_Anv_mesh, em_Anv_mesh
+
+        real, intent(out) :: em_hist_mesh, iwp_hist_mesh, rad_hist_mesh
+        real, intent(out) :: deltaz_hc_mesh, deltaz_hist_mesh
+
+        real, dimension(:), allocatable :: rneb_cs, temp_cs, emis_cs, &
+     & iwco_cs
+        real, dimension(:), allocatable :: pres_cs, dz_cs, rad_cs, &
+     & rhodz_cs
+
+        integer :: i,j,l
+        integer :: ltop, itop, ibot, num_cs, N_cs, len_cs, ics
+
+        real :: som_emi_hc,som_pcl_hc,som_tcl_hc,som_iwp_hc,som_hc,&
+     & som_hist
+        real :: som_emi_hist, som_iwp_hist, som_deltaz_hc, &
+     & som_deltaz_hist
+        real :: som_rad_hist
+        real :: som_Cb, som_ThCi, som_Anv
+        real :: som_emi_Cb, som_tcld_Cb, som_pcld_Cb
+        real :: som_emi_Anv, som_tcld_Anv, som_pcld_Anv
+        real :: som_emi_ThCi, som_tcld_ThCi, som_pcld_ThCi
+        real :: tsom_tot, tsom_hc, tsom_hist
+        real :: prod, prod_hh
+
+        real :: cc_tot_cs, cc_hc_cs, cc_hist_cs
+        real :: cc_Cb_cs, cc_ThCi_cs, cc_Anv_cs
+        real :: pcld_hc_cs, tcld_hc_cs
+        real :: em_hc_cs, iwp_hc_cs, deltaz_hc_cs
+        real :: pcld_Cb_cs, tcld_Cb_cs, em_Cb_cs
+        real :: pcld_ThCi_cs, tcld_ThCi_cs, em_ThCi_cs
+        real :: pcld_Anv_cs, tcld_Anv_cs, em_Anv_cs
+        real :: em_hist_cs, iwp_hist_cs, deltaz_hist_cs, rad_hist_cs
+
+        real, dimension(klev) :: test_tot, test_hc, test_hist
+        real, dimension(klev) :: test_pcld, test_tcld, test_em, test_iwp
+
+
+        do j = 1, klev
+        write(*,*) 'simu_airs, j, rneb_1D =', rneb_1D(j)
+        enddo
+
+! Definition des structures nuageuses, de la plus haute a la plus basse
+
+        num_cs = 0
+        ltop = klev-1
+
+        prod = 1.
+
+        som_emi_hc = 0.
+        som_emi_hist = 0.
+        som_pcl_hc = 0.
+        som_tcl_hc = 0.
+        som_iwp_hc = 0.
+        som_iwp_hist = 0.
+        som_deltaz_hc = 0.
+        som_deltaz_hist = 0.
+        som_rad_hist = 0.
+        som_hc = 0.
+        som_hist = 0.
+
+        som_Cb = 0.
+        som_ThCi = 0.
+        som_Anv = 0.
+
+        som_emi_Cb = 0.
+        som_pcld_Cb = 0.
+        som_tcld_Cb = 0.
+
+        som_emi_ThCi = 0.
+        som_pcld_ThCi = 0.
+        som_tcld_ThCi = 0.
+
+        som_emi_Anv = 0.
+        som_pcld_Anv = 0.
+        som_tcld_Anv = 0.
+
+        tsom_tot = 0.
+        tsom_hc = 0.
+        tsom_hist = 0.
+
+        do while (ltop .ge. 1)   ! Boucle sur toute la colonne
+
+        itop = 0
+
+        do l = ltop,1,-1
+
+        if (itop .eq. 0 .and. rneb_1D(l) .gt. 0.001 ) then
+        itop = l
+        endif
+
+        enddo
+
+        ibot = itop
+
+        do while (rneb_1D(ibot) .gt. 0.001 .and. ibot .ge. 1)
+        ibot = ibot -1
+        enddo
+
+
+        ibot = ibot+1
+
+        if (itop .gt. 0) then    ! itop > 0
+
+        num_cs = num_cs +1
+        len_cs = itop-ibot+1
+
+! Allocation et definition des variables de la structure nuageuse
+! le premier indice denote ce qui est le plus haut
+
+        allocate (rneb_cs(len_cs))
+        allocate (temp_cs(len_cs))
+        allocate (emis_cs(len_cs))
+        allocate (iwco_cs(len_cs))
+        allocate (pres_cs(len_cs))
+        allocate (dz_cs(len_cs))
+        allocate (rad_cs(len_cs))
+        allocate (rhodz_cs(len_cs))
+
+        ics = 0
+
+        do i = itop, ibot, -1
+        ics = ics + 1
+        rneb_cs(ics) = rneb_1D(i)
+        temp_cs(ics) = temp_1D(i)
+        emis_cs(ics) = emis_1D(i)
+        iwco_cs(ics) = iwcon_1D(i)
+        rad_cs(ics) = rad_1D(i)
+        pres_cs(ics) = pres(i)
+        dz_cs(ics) = dz(i)
+        rhodz_cs(ics) = rhodz_1D(i)
+        enddo
+
+! Appel du sous_programme cloud_structure
+
+        call cloud_structure(len_cs,rneb_cs,temp_cs,emis_cs,iwco_cs,&
+     & pres_cs, dz_cs, rhodz_cs, rad_cs, &
+     & cc_tot_cs, cc_hc_cs, cc_hist_cs, &
+     & cc_Cb_cs, cc_ThCi_cs, cc_Anv_cs, &
+     & pcld_hc_cs, tcld_hc_cs, &
+     & em_hc_cs, iwp_hc_cs, deltaz_hc_cs, &
+     & pcld_Cb_cs, tcld_Cb_cs, em_Cb_cs, &
+     & pcld_ThCi_cs, tcld_ThCi_cs, em_ThCi_cs, &
+     & pcld_Anv_cs, tcld_Anv_cs, em_Anv_cs, &
+     & em_hist_cs, iwp_hist_cs, deltaz_hist_cs, rad_hist_cs)
+
+
+        deallocate (rneb_cs)
+        deallocate (temp_cs)
+        deallocate (emis_cs)
+        deallocate (iwco_cs)
+        deallocate (pres_cs)
+        deallocate (dz_cs)
+        deallocate (rad_cs)
+        deallocate (rhodz_cs)
+
+
+! Pour la couverture nuageuse sur la maille
+
+        prod_hh = prod
+
+        prod = prod*(1.-cc_tot_cs)
+
+! Pour les autres variables definies sur la maille
+
+        som_emi_hc = som_emi_hc + em_hc_cs*cc_hc_cs*prod_hh
+        som_iwp_hc = som_iwp_hc + iwp_hc_cs*cc_hc_cs*prod_hh
+        som_deltaz_hc = som_deltaz_hc + deltaz_hc_cs*cc_hc_cs*prod_hh
+
+        som_emi_Cb = som_emi_Cb + em_Cb_cs*cc_Cb_cs*prod_hh
+        som_tcld_Cb = som_tcld_Cb + tcld_Cb_cs*cc_Cb_cs*prod_hh
+        som_pcld_Cb = som_pcld_Cb + pcld_Cb_cs*cc_Cb_cs*prod_hh
+
+        som_emi_ThCi = som_emi_ThCi + em_ThCi_cs*cc_ThCi_cs*prod_hh
+        som_tcld_ThCi = som_tcld_ThCi + tcld_ThCi_cs*cc_ThCi_cs*prod_hh
+        som_pcld_ThCi = som_pcld_ThCi + pcld_ThCi_cs*cc_ThCi_cs*prod_hh
+
+        som_emi_Anv = som_emi_Anv + em_Anv_cs*cc_Anv_cs*prod_hh
+        som_tcld_Anv = som_tcld_Anv + tcld_Anv_cs*cc_Anv_cs*prod_hh
+        som_pcld_Anv = som_pcld_Anv + pcld_Anv_cs*cc_Anv_cs*prod_hh
+
+        som_emi_hist = som_emi_hist + em_hist_cs*cc_hist_cs*prod_hh
+        som_iwp_hist = som_iwp_hist + iwp_hist_cs*cc_hist_cs*prod_hh
+        som_deltaz_hist = som_deltaz_hist + &
+     & deltaz_hist_cs*cc_hist_cs*prod_hh
+        som_rad_hist = som_rad_hist + rad_hist_cs*cc_hist_cs*prod_hh
+
+        som_pcl_hc = som_pcl_hc + pcld_hc_cs*cc_hc_cs*prod_hh
+        som_tcl_hc = som_tcl_hc + tcld_hc_cs*cc_hc_cs*prod_hh
+
+        som_hc = som_hc + cc_hc_cs*prod_hh
+        som_hist = som_hist + cc_hist_cs*prod_hh
+
+        som_Cb = som_Cb + cc_Cb_cs*prod_hh
+        som_ThCi = som_ThCi + cc_ThCi_cs*prod_hh
+        som_Anv = som_Anv + cc_Anv_cs*prod_hh
+
+
+! Pour test
+        
+        call test_bornes('cc_tot_cs     ',cc_tot_cs,1.,0.)
+        call test_bornes('cc_hc_cs      ',cc_hc_cs,1.,0.)
+        call test_bornes('cc_hist_cs    ',cc_hist_cs,1.,0.)
+        call test_bornes('pcld_hc_cs    ',pcld_hc_cs,1200.,0.)
+        call test_bornes('tcld_hc_cs    ',tcld_hc_cs,1000.,100.)
+        call test_bornes('em_hc_cs      ',em_hc_cs,1000.,0.048)
+
+        test_tot(num_cs) = cc_tot_cs
+        test_hc(num_cs) = cc_hc_cs
+        test_hist(num_cs) = cc_hist_cs
+        test_pcld(num_cs) = pcld_hc_cs
+        test_tcld(num_cs) = tcld_hc_cs
+        test_em(num_cs) = em_hc_cs
+        test_iwp(num_cs) = iwp_hc_cs
+
+        tsom_tot = tsom_tot + cc_tot_cs
+        tsom_hc = tsom_hc + cc_hc_cs
+        tsom_hist = tsom_hist + cc_hist_cs
+
+
+        endif                   ! itop > 0
+
+        ltop = ibot -1
+
+        enddo                   ! fin de la boucle sur la colonne
+
+        N_CS = num_cs
+
+
+! Determination des variables de sortie
+
+        if (N_CS .gt. 0) then   ! if N_CS>0
+
+        cc_tot_mesh = 1. - prod
+
+        cc_hc_mesh = som_hc
+        cc_hist_mesh = som_hist
+
+        cc_Cb_mesh = som_Cb
+        cc_ThCi_mesh = som_ThCi
+        cc_Anv_mesh = som_Anv
+
+        call normal2_undef(pcld_hc_mesh,som_pcl_hc, &
+     & cc_hc_mesh)
+        call normal2_undef(tcld_hc_mesh,som_tcl_hc, &
+     & cc_hc_mesh)
+        call normal2_undef(em_hc_mesh,som_emi_hc, &
+     & cc_hc_mesh)
+        call normal2_undef(iwp_hc_mesh,som_iwp_hc, &
+     & cc_hc_mesh)
+        call normal2_undef(deltaz_hc_mesh,som_deltaz_hc, &
+     & cc_hc_mesh)
+
+        call normal2_undef(em_Cb_mesh,som_emi_Cb, &
+     & cc_Cb_mesh)
+        call normal2_undef(tcld_Cb_mesh,som_tcld_Cb, &
+     & cc_Cb_mesh)
+        call normal2_undef(pcld_Cb_mesh,som_pcld_Cb, &
+     & cc_Cb_mesh)
+
+        call normal2_undef(em_ThCi_mesh,som_emi_ThCi, &
+     & cc_ThCi_mesh)
+        call normal2_undef(tcld_ThCi_mesh,som_tcld_ThCi, &
+     & cc_ThCi_mesh)
+        call normal2_undef(pcld_ThCi_mesh,som_pcld_ThCi, &
+     & cc_ThCi_mesh)
+
+       call normal2_undef(em_Anv_mesh,som_emi_Anv, &
+     & cc_Anv_mesh)
+        call normal2_undef(tcld_Anv_mesh,som_tcld_Anv, &
+     & cc_Anv_mesh)
+        call normal2_undef(pcld_Anv_mesh,som_pcld_Anv, &
+     & cc_Anv_mesh)
+
+
+        call normal2_undef(em_hist_mesh,som_emi_hist, &
+     & cc_hist_mesh)
+        call normal2_undef(iwp_hist_mesh,som_iwp_hist, &
+     & cc_hist_mesh)
+        call normal2_undef(deltaz_hist_mesh,som_deltaz_hist, &
+     & cc_hist_mesh)
+        call normal2_undef(rad_hist_mesh,som_rad_hist, &
+     & cc_hist_mesh)
+
+
+! Tests 
+
+        ! Tests
+
+       if (cc_tot_mesh .gt. tsom_tot .and. &
+     & abs(cc_tot_mesh-tsom_tot) .gt. 1.e-4) then
+        write(*,*) 'cc_tot_mesh > tsom_tot'
+        write(*,*) cc_tot_mesh, tsom_tot
+        STOP
+        endif
+
+        if (cc_tot_mesh .lt. maxval(test_tot(1:N_CS)) .and. &
+     & abs(cc_tot_mesh-maxval(test_tot(1:N_CS))) .gt. 1.e-4) then
+        write(*,*) 'cc_tot_mesh < max'
+        write(*,*) cc_tot_mesh, maxval(test_tot(1:N_CS))
+        STOP
+        endif
+
+        if (cc_hc_mesh .gt. tsom_hc .and. &
+     & abs(cc_hc_mesh-tsom_hc) .gt. 1.e-4) then
+        write(*,*) 'cc_hc_mesh > tsom_hc'
+        write(*,*) cc_hc_mesh, tsom_hc
+        STOP
+        endif
+
+        if (cc_hc_mesh .lt. maxval(test_hc(1:N_CS)) .and. &
+     & abs(cc_hc_mesh-maxval(test_hc(1:N_CS))) .gt. 1.e-4) then
+        write(*,*) 'cc_hc_mesh < max'
+        write(*,*) cc_hc_mesh, maxval(test_hc(1:N_CS))
+        STOP
+        endif
+
+        if (cc_hist_mesh .gt. tsom_hist .and. &
+     & abs(cc_hist_mesh-tsom_hist) .gt. 1.e-4) then
+        write(*,*) 'cc_hist_mesh > tsom_hist'
+        write(*,*) cc_hist_mesh, tsom_hist
+        STOP
+        endif
+
+        if (cc_hist_mesh .lt. 0.) then
+        write(*,*) 'cc_hist_mesh < 0'
+        write(*,*) cc_hist_mesh
+        STOP
+        endif
+
+        if ((pcld_hc_mesh .gt. maxval(test_pcld(1:N_CS)) .or. &
+     & pcld_hc_mesh .lt. minval(test_pcld(1:N_CS))) .and. &
+     & abs(pcld_hc_mesh-maxval(test_pcld(1:N_CS))) .gt. 1. .and. &
+     & maxval(test_pcld(1:N_CS)) .ne. 999. &
+     & .and. minval(test_pcld(1:N_CS)) .ne. 999.) then
+        write(*,*) 'pcld_hc_mesh est faux'
+        write(*,*) pcld_hc_mesh, maxval(test_pcld(1:N_CS)), &
+     & minval(test_pcld(1:N_CS))
+        STOP
+        endif
+
+       if ((tcld_hc_mesh .gt. maxval(test_tcld(1:N_CS)) .or. &
+     & tcld_hc_mesh .lt. minval(test_tcld(1:N_CS))) .and. &
+     & abs(tcld_hc_mesh-maxval(test_tcld(1:N_CS))) .gt. 0.1 .and. &
+     & maxval(test_tcld(1:N_CS)) .ne. 999. &
+     & .and. minval(test_tcld(1:N_CS)) .ne. 999.) then
+        write(*,*) 'tcld_hc_mesh est faux'
+        write(*,*) tcld_hc_mesh, maxval(test_tcld(1:N_CS)), &
+     & minval(test_tcld(1:N_CS))
+        endif
+
+        if ((em_hc_mesh .gt. maxval(test_em(1:N_CS)) .or. &
+     & em_hc_mesh .lt. minval(test_em(1:N_CS))) .and. &
+     & abs(em_hc_mesh-maxval(test_em(1:N_CS))) .gt. 1.e-4 .and. &
+     & minval(test_em(1:N_CS)) .ne. 999. .and. &
+     & maxval(test_em(1:N_CS)) .ne. 999. ) then
+        write(*,*) 'em_hc_mesh est faux'
+        write(*,*) em_hc_mesh, maxval(test_em(1:N_CS)), &
+     & minval(test_em(1:N_CS))
+        STOP
+        endif
+
+        else               ! if N_CS>0
+
+        cc_tot_mesh = 0.
+        cc_hc_mesh = 0.
+        cc_hist_mesh = 0.
+
+        cc_Cb_mesh = 0.
+        cc_ThCi_mesh = 0.
+        cc_Anv_mesh = 0.
+
+        iwp_hc_mesh = undef 
+        deltaz_hc_mesh = undef 
+        em_hc_mesh = undef 
+        iwp_hist_mesh = undef 
+        deltaz_hist_mesh = undef 
+        rad_hist_mesh = undef 
+        em_hist_mesh = undef 
+        pcld_hc_mesh = undef 
+        tcld_hc_mesh = undef 
+
+        pcld_Cb_mesh = undef 
+        tcld_Cb_mesh = undef 
+        em_Cb_mesh = undef 
+
+        pcld_ThCi_mesh = undef 
+        tcld_ThCi_mesh = undef 
+        em_ThCi_mesh = undef 
+
+        pcld_Anv_mesh = undef 
+        tcld_Anv_mesh = undef 
+        em_Anv_mesh = undef 
+
+
+        endif                  ! if N_CS>0
+
+        end subroutine sim_mesh
+
+        subroutine test_bornes(sx,x,bsup,binf)
+
+        real, intent(in) :: x, bsup, binf
+        character*14, intent(in) :: sx
+
+        if (x .gt. bsup .or. x .lt. binf) then
+        write(*,*) sx, 'est faux'
+        write(*,*) sx, x
+        STOP
+        endif
+ 
+        end subroutine test_bornes
+
+        end module m_simu_airs
+
+
+        subroutine simu_airs &
+     & (itap, rneb_airs, temp_airs, cldemi_airs, iwcon0_airs, rad_airs, &
+     & geop_airs, pplay_airs, paprs_airs, &
+     & map_prop_hc,map_prop_hist,&
+     & map_emis_hc,map_iwp_hc,map_deltaz_hc,map_pcld_hc,map_tcld_hc,&
+     & map_emis_Cb,map_pcld_Cb,map_tcld_Cb,&
+     & map_emis_ThCi,map_pcld_ThCi,map_tcld_ThCi,&
+     & map_emis_Anv,map_pcld_Anv,map_tcld_Anv,&
+     & map_emis_hist,map_iwp_hist,map_deltaz_hist,map_rad_hist,&
+     & map_ntot,map_hc,map_hist,&
+     & map_Cb,map_ThCi,map_Anv,alt_tropo )
+
+        USE dimphy
+        USE m_simu_airs
+
+        IMPLICIT NONE
+
+        include "YOMCST.h"
+
+        integer,intent(in) :: itap
+
+        real, dimension(klon,klev), intent(in) :: &
+     & rneb_airs, temp_airs, cldemi_airs, iwcon0_airs, &
+     & rad_airs, geop_airs, pplay_airs, paprs_airs
+
+       real, dimension(klon,klev) :: &
+     & rhodz_airs, rho_airs, iwcon_airs
+
+        real, dimension(klon),intent(out) :: alt_tropo
+
+        real, dimension(klev) :: rneb_1D, temp_1D, &
+     & emis_1D, rad_1D, pres_1D, alt_1D, &
+     & rhodz_1D, dz_1D, iwcon_1D
+
+        integer :: i, j
+
+        real :: cc_tot_mesh, cc_hc_mesh, cc_hist_mesh
+        real :: cc_Cb_mesh, cc_ThCi_mesh, cc_Anv_mesh
+        real :: pcld_hc_mesh, tcld_hc_mesh, em_hc_mesh, iwp_hc_mesh
+        real :: em_hist_mesh, iwp_hist_mesh
+        real :: deltaz_hc_mesh, deltaz_hist_mesh, rad_hist_mesh
+        real :: pcld_Cb_mesh, tcld_Cb_mesh, em_Cb_mesh
+        real :: pcld_ThCi_mesh, tcld_ThCi_mesh, em_ThCi_mesh
+        real :: pcld_Anv_mesh, tcld_Anv_mesh, em_Anv_mesh
+
+        real, dimension(klon),intent(out) :: map_prop_hc, map_prop_hist
+        real, dimension(klon),intent(out) :: map_emis_hc, map_iwp_hc
+        real, dimension(klon),intent(out) :: map_deltaz_hc, map_pcld_hc
+        real, dimension(klon),intent(out) :: map_tcld_hc
+        real, dimension(klon),intent(out) :: map_emis_Cb,map_pcld_Cb,map_tcld_Cb 
+        real, dimension(klon),intent(out) :: &
+     & map_emis_ThCi,map_pcld_ThCi,map_tcld_ThCi
+        real, dimension(klon),intent(out) :: &
+     & map_emis_Anv,map_pcld_Anv,map_tcld_Anv
+        real, dimension(klon),intent(out) :: &
+     & map_emis_hist,map_iwp_hist,map_deltaz_hist,&
+     & map_rad_hist
+       real, dimension(klon),intent(out) :: map_ntot,map_hc,map_hist
+       real, dimension(klon),intent(out) :: map_Cb,map_ThCi,map_Anv
+ 
+ 
+        write(*,*) 'simu_airs'
+        write(*,*) 'itap, klon, klev', itap, klon, klev
+        write(*,*) 'RG, RD =', RG, RD
+
+
+! Definition des variables 1D
+
+        do i = 1, klon
+        do j = 1, klev-1
+        rhodz_airs(i,j) = &
+     & (paprs_airs(i,j)-paprs_airs(i,j+1))/RG
+        enddo
+        rhodz_airs(i,klev) = 0.
+        enddo
+
+        do i = 1, klon
+        do j = 1,klev
+        rho_airs(i,j) = &
+     & pplay_airs(i,j)/(temp_airs(i,j)*RD)
+
+        if (rneb_airs(i,j) .gt. 0.001) then
+        iwcon_airs(i,j) = iwcon0_airs(i,j)/rneb_airs(i,j)
+        else
+        iwcon_airs(i,j) = 0.
+        endif
+ 
+        enddo
+        enddo
+
+!=============================================================================
+
+        do i = 1, klon  ! boucle sur les points de grille
+
+!=============================================================================
+        
+        do j = 1,klev
+
+        rneb_1D(j) = rneb_airs(i,j)
+        temp_1D(j) = temp_airs(i,j)
+        emis_1D(j) = cldemi_airs(i,j)
+        iwcon_1D(j) = iwcon_airs(i,j)
+        rad_1D(j) = rad_airs(i,j)
+        pres_1D(j) = pplay_airs(i,j)
+        alt_1D(j) = geop_airs(i,j)/RG
+        rhodz_1D(j) = rhodz_airs(i,j)
+        dz_1D(j) = rhodz_airs(i,j)/rho_airs(i,j)
+
+        enddo
+
+        alt_tropo(i) = &
+     & search_tropopause(pres_1D/100.,temp_1D,alt_1D,klev)
+
+
+! Appel du ss-programme sim_mesh
+
+!        if (itap .eq. 1 ) then
+
+        call sim_mesh(rneb_1D, temp_1D, emis_1D, iwcon_1D, rad_1D, &
+     & pres_1D, dz_1D, rhodz_1D, &
+     & cc_tot_mesh, cc_hc_mesh, cc_hist_mesh, &
+     & pcld_hc_mesh, tcld_hc_mesh, em_hc_mesh, iwp_hc_mesh, &
+     & deltaz_hc_mesh,&
+     & cc_Cb_mesh, cc_ThCi_mesh, cc_Anv_mesh, &
+     & pcld_Cb_mesh, tcld_Cb_mesh, em_Cb_mesh, &
+     & pcld_ThCi_mesh, tcld_ThCi_mesh, em_ThCi_mesh, &
+     & pcld_Anv_mesh, tcld_Anv_mesh, em_Anv_mesh, &
+     & em_hist_mesh, iwp_hist_mesh, deltaz_hist_mesh, rad_hist_mesh)
+
+         write(*,*) '===================================='
+         write(*,*) 'itap, i:', itap, i 
+         write(*,*) 'cc_tot, cc_hc, cc_hist, pcld_hc, tcld_hc, em_hc, &
+     & iwp_hc, em_hist, iwp_hist ='
+         write(*,*) cc_tot_mesh, cc_hc_mesh, cc_hist_mesh
+         write(*,*) pcld_hc_mesh, tcld_hc_mesh, em_hc_mesh, iwp_hc_mesh
+         write(*,*)  em_hist_mesh, iwp_hist_mesh
+
+!        endif
+
+! Definition des variables a ecrire dans le fichier de sortie
+
+        call normal2_undef(map_prop_hc(i),cc_hc_mesh, &
+     & cc_tot_mesh)
+        call normal2_undef(map_prop_hist(i),cc_hist_mesh, &
+     & cc_tot_mesh)
+
+       map_emis_hc(i) = em_hc_mesh
+       map_iwp_hc(i) = iwp_hc_mesh
+       map_deltaz_hc(i) = deltaz_hc_mesh
+       map_pcld_hc(i) = pcld_hc_mesh
+       map_tcld_hc(i) = tcld_hc_mesh
+
+       map_emis_Cb(i) = em_Cb_mesh
+       map_pcld_Cb(i) = pcld_Cb_mesh
+       map_tcld_Cb(i) = tcld_Cb_mesh
+
+       map_emis_ThCi(i) = em_ThCi_mesh
+       map_pcld_ThCi(i) = pcld_ThCi_mesh
+       map_tcld_ThCi(i) = tcld_ThCi_mesh
+
+       map_emis_Anv(i) = em_Anv_mesh
+       map_pcld_Anv(i) = pcld_Anv_mesh
+       map_tcld_Anv(i) = tcld_Anv_mesh
+
+       map_emis_hist(i) = em_hist_mesh
+       map_iwp_hist(i) = iwp_hist_mesh
+       map_deltaz_hist(i) = deltaz_hist_mesh
+       map_rad_hist(i) = rad_hist_mesh
+
+       map_ntot(i) = cc_tot_mesh
+       map_hc(i) = cc_hc_mesh
+       map_hist(i) = cc_hist_mesh
+
+       map_Cb(i) = cc_Cb_mesh
+       map_ThCi(i) = cc_ThCi_mesh
+       map_Anv(i) = cc_Anv_mesh
+
+
+        enddo         ! fin boucle sur les points de grille
+
+        
+
+        end subroutine simu_airs
+
Index: /LMDZ5/branches/testing/libf/phylmd/surf_land_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/surf_land_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/surf_land_mod.F90	(revision 2594)
@@ -24,9 +24,18 @@
     USE surface_data, ONLY    : ok_veget
 
+    ! See comments in each module surf_land_orchidee_xxx for compatiblity with ORCHIDEE
 #ifdef ORCHIDEE_NOOPENMP
+    ! Compilation with cpp key ORCHIDEE NOOPENMP
     USE surf_land_orchidee_noopenmp_mod
 #else
+#if ORCHIDEE_NOZ0H
+    ! Compilation with cpp key ORCHIDEE NOZ0H
+    USE surf_land_orchidee_noz0h_mod
+#else
+    ! Compilation with default interface
     USE surf_land_orchidee_mod
 #endif
+#endif
+
     USE surf_land_bucket_mod
     USE calcul_fluxs_mod
@@ -141,6 +150,5 @@
             evap, fluxsens, fluxlat, &              
             tsol_rad, tsurf_new, alb1_new, alb2_new, &
-            emis_new, z0m, qsurf)       
-        z0h(1:knon)=z0m(1:knon) ! En attendant mieux
+            emis_new, z0m, z0h, qsurf)       
 
 !  
Index: /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_mod.F90	(revision 2594)
@@ -2,11 +2,11 @@
 MODULE surf_land_orchidee_mod
 #ifndef ORCHIDEE_NOOPENMP
+#ifndef ORCHIDEE_NOZ0H
 !
 ! This module controles the interface towards the model ORCHIDEE.
 !
 ! Compatibility with ORCHIDIEE :
-! The current version can be used with ORCHIDEE/trunk from revision 2961.
-! This interface can also be used with ORCHIDEE/trunk revision 1078-2960 if changing 
-! coszang=yrmu0 into sinang=yrmu0 at 2 places later below in this module. 
+! The current version can be used with ORCHIDEE/trunk from revision 3525.
+! This interface is used if none of the cpp keys ORCHIDEE_NOOPENMP or ORCHIDEE_NOZ0H is set.
 !
 ! Subroutines in this module : surf_land_orchidee
@@ -44,5 +44,5 @@
        evap, fluxsens, fluxlat, &              
        tsol_rad, tsurf_new, alb1_new, alb2_new, &
-       emis_new, z0_new, qsurf)
+       emis_new, z0m_new, z0h_new, qsurf)
 
     USE mod_surf_para
@@ -104,5 +104,6 @@
 !   alb2_new     albedo in near IR interval
 !   emis_new     emissivite
-!   z0_new       surface roughness
+!   z0m_new      surface roughness for momentum
+!   z0h_new      surface roughness for heat
 !   qsurf        air moisture at surface
 !
@@ -137,5 +138,5 @@
     REAL, DIMENSION(klon), INTENT(OUT)        :: tsol_rad, tsurf_new
     REAL, DIMENSION(klon), INTENT(OUT)        :: alb1_new, alb2_new
-    REAL, DIMENSION(klon), INTENT(OUT)        :: emis_new, z0_new
+    REAL, DIMENSION(klon), INTENT(OUT)        :: emis_new, z0m_new, z0h_new
 
 ! Local
@@ -403,13 +404,12 @@
 
 #ifdef CPP_VEGET
-          CALL intersurf_main (itime+itau_phy-1, nbp_lon, nbp_lat, knon, ktindex, dtime, &
-               lrestart_read, lrestart_write, lalo, &
-               contfrac, neighbours, resolution, date0, &
-               zlev,  u1_lay, v1_lay, spechum, temp_air, epot_air, ccanopy, &
+         CALL intersurf_initialize_gathered (itime+itau_phy-1, nbp_lon, nbp_lat, knon, ktindex, dtime, &
+               lrestart_read, lrestart_write, lalo, contfrac, neighbours, resolution, date0, &
+               zlev,  u1_lay, v1_lay, spechum, temp_air, epot_air, &
                cdrag, petA_orc, peqA_orc, petB_orc, peqB_orc, &
                precip_rain, precip_snow, lwdown, swnet, swdown, ps, &
                evap, fluxsens, fluxlat, coastalflow, riverflow, &
-               tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0_new, &
-               lon_scat, lat_scat, q2m, t2m, coszang=yrmu0)
+               tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0m_new, &
+               lon_scat, lat_scat, q2m, t2m, z0h_new)
 #endif         
        ENDIF
@@ -427,5 +427,5 @@
     IF (knon > 0) THEN
 #ifdef CPP_VEGET    
-       CALL intersurf_main (itime+itau_phy, nbp_lon, nbp_lat, knon, ktindex, dtime,  &
+       CALL intersurf_main_gathered (itime+itau_phy, nbp_lon, nbp_lat, knon, ktindex, dtime,  &
             lrestart_read, lrestart_write, lalo, &
             contfrac, neighbours, resolution, date0, &
@@ -434,6 +434,6 @@
             precip_rain(1:knon), precip_snow(1:knon), lwdown(1:knon), swnet(1:knon), swdown_vrai(1:knon), ps(1:knon), &
             evap(1:knon), fluxsens(1:knon), fluxlat(1:knon), coastalflow(1:knon), riverflow(1:knon), &
-            tsol_rad(1:knon), tsurf_new(1:knon), qsurf(1:knon), albedo_out(1:knon,:), emis_new(1:knon), z0_new(1:knon), &
-            lon_scat, lat_scat, q2m, t2m, coszang=yrmu0(1:knon))
+            tsol_rad(1:knon), tsurf_new(1:knon), qsurf(1:knon), albedo_out(1:knon,:), emis_new(1:knon), z0m_new(1:knon), &
+            lon_scat, lat_scat, q2m, t2m, z0h_new(1:knon), coszang=yrmu0(1:knon))
 #endif       
     ENDIF
@@ -664,3 +664,4 @@
 !
 #endif
+#endif
 END MODULE surf_land_orchidee_mod
Index: /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noopenmp_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noopenmp_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noopenmp_mod.F90	(revision 2594)
@@ -38,5 +38,5 @@
        knindex, rlon, rlat, yrmu0, pctsrf, &
        debut, lafin, &
-       plev,  u1_lay, v1_lay, temp_air, spechum, epot_air, ccanopy, & 
+       plev,  u1_lay, v1_lay, gustiness, temp_air, spechum, epot_air, ccanopy, & 
        tq_cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
        precip_rain, precip_snow, lwdown, swnet, swdown, &
@@ -44,5 +44,5 @@
        evap, fluxsens, fluxlat, &              
        tsol_rad, tsurf_new, alb1_new, alb2_new, &
-       emis_new, z0_new, qsurf)
+       emis_new, z0_new, z0h_new, qsurf)
 !    
 ! Cette routine sert d'interface entre le modele atmospherique et le 
@@ -95,4 +95,5 @@
 !   emis_new     emissivite
 !   z0_new       surface roughness
+!   z0h_new      surface roughness, it is the same as z0_new
 !   qsurf        air moisture at surface
 !
@@ -121,5 +122,5 @@
     REAL, DIMENSION(klon), INTENT(IN)         :: yrmu0
     REAL, DIMENSION(klon), INTENT(IN)         :: plev
-    REAL, DIMENSION(klon), INTENT(IN)         :: u1_lay, v1_lay
+    REAL, DIMENSION(klon), INTENT(IN)         :: u1_lay, v1_lay, gustiness
     REAL, DIMENSION(klon), INTENT(IN)         :: temp_air, spechum
     REAL, DIMENSION(klon), INTENT(IN)         :: epot_air, ccanopy
@@ -136,5 +137,5 @@
     REAL, DIMENSION(klon), INTENT(OUT)        :: tsol_rad, tsurf_new
     REAL, DIMENSION(klon), INTENT(OUT)        :: alb1_new, alb2_new
-    REAL, DIMENSION(klon), INTENT(OUT)        :: emis_new, z0_new
+    REAL, DIMENSION(klon), INTENT(OUT)        :: emis_new, z0_new, z0h_new
 
 ! Local
@@ -496,4 +497,7 @@
 
     albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
+    
+    ! ORCHIDEE only gives one value for z0_new. Copy it into z0h_new.
+    z0h_new(:)=z0_new(:)
 
 !* Send to coupler
Index: /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noz0h_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noz0h_mod.F90	(revision 2594)
+++ /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noz0h_mod.F90	(revision 2594)
@@ -0,0 +1,671 @@
+!
+MODULE surf_land_orchidee_noz0h_mod
+#ifdef ORCHIDEE_NOZ0H
+!
+! This module controles the interface towards the model ORCHIDEE.
+!
+! Compatibility with ORCHIDIEE :
+! This module is compiled only if CPP key ORCHIDEE_NOZ0H is defined.
+! This version can be used with ORCHIDEE/trunk revision 2961-3525.
+! It is possible to use this interface with later versions of ORCHIDEE/trunk than 3525 but 
+! in that case the option ROUGH_DYN=y in ORCHIDEE should not be set. 
+! This interface can also be used with ORCHIDEE/trunk revision 1078-2960 if changing 
+! coszang=yrmu0 into sinang=yrmu0 at 2 places later below in this module. 
+!
+! Subroutines in this module : surf_land_orchidee
+!                              Init_orchidee_index
+!                              Get_orchidee_communicator
+!                              Init_neighbours
+
+  USE dimphy
+#ifdef CPP_VEGET
+  USE intersurf     ! module d'ORCHIDEE
+#endif
+  USE cpl_mod,      ONLY : cpl_send_land_fields
+  USE surface_data, ONLY : type_ocean
+  USE geometry_mod, ONLY : dx, dy
+  USE mod_grid_phy_lmdz
+  USE mod_phys_lmdz_para, mpi_root_rank=>mpi_master
+
+  IMPLICIT NONE
+
+  PRIVATE
+  PUBLIC  :: surf_land_orchidee
+
+  LOGICAL, ALLOCATABLE, SAVE :: flag_omp(:)
+CONTAINS
+!
+!****************************************************************************************
+!  
+  SUBROUTINE surf_land_orchidee(itime, dtime, date0, knon, &
+       knindex, rlon, rlat, yrmu0, pctsrf, &
+       debut, lafin, &
+       plev,  u1_lay, v1_lay, gustiness, temp_air, spechum, epot_air, ccanopy, & 
+       tq_cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
+       precip_rain, precip_snow, lwdown, swnet, swdown, &
+       ps, q2m, t2m, &
+       evap, fluxsens, fluxlat, &              
+       tsol_rad, tsurf_new, alb1_new, alb2_new, &
+       emis_new, z0_new, z0h_new, qsurf)
+
+    USE mod_surf_para
+    USE mod_synchro_omp
+    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
+    USE indice_sol_mod
+    USE print_control_mod, ONLY: lunout
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
+#ifdef CPP_VEGET
+    USE time_phylmdz_mod, ONLY: itau_phy 
+#endif
+!    
+! Cette routine sert d'interface entre le modele atmospherique et le 
+! modele de sol continental. Appel a sechiba
+!
+! L. Fairhead 02/2000
+!
+! input:
+!   itime        numero du pas de temps
+!   dtime        pas de temps de la physique (en s)
+!   nisurf       index de la surface a traiter (1 = sol continental)
+!   knon         nombre de points de la surface a traiter
+!   knindex      index des points de la surface a traiter
+!   rlon         longitudes de la grille entiere
+!   rlat         latitudes de la grille entiere
+!   pctsrf       tableau des fractions de surface de chaque maille
+!   debut        logical: 1er appel a la physique (lire les restart)
+!   lafin        logical: dernier appel a la physique (ecrire les restart)
+!                     (si false calcul simplifie des fluxs sur les continents)
+!   plev         hauteur de la premiere couche (Pa)      
+!   u1_lay       vitesse u 1ere couche
+!   v1_lay       vitesse v 1ere couche
+!   temp_air     temperature de l'air 1ere couche
+!   spechum      humidite specifique 1ere couche
+!   epot_air     temp pot de l'air
+!   ccanopy      concentration CO2 canopee, correspond au co2_send de 
+!                carbon_cycle_mod ou valeur constant co2_ppm
+!   tq_cdrag     cdrag
+!   petAcoef     coeff. A de la resolution de la CL pour t
+!   peqAcoef     coeff. A de la resolution de la CL pour q
+!   petBcoef     coeff. B de la resolution de la CL pour t
+!   peqBcoef     coeff. B de la resolution de la CL pour q
+!   precip_rain  precipitation liquide
+!   precip_snow  precipitation solide
+!   lwdown       flux IR descendant a la surface
+!   swnet        flux solaire net
+!   swdown       flux solaire entrant a la surface
+!   ps           pression au sol
+!   radsol       rayonnement net aus sol (LW + SW)
+!   
+!
+! output:
+!   evap         evaporation totale
+!   fluxsens     flux de chaleur sensible
+!   fluxlat      flux de chaleur latente
+!   tsol_rad     
+!   tsurf_new    temperature au sol
+!   alb1_new     albedo in visible SW interval
+!   alb2_new     albedo in near IR interval
+!   emis_new     emissivite
+!   z0_new       surface roughness
+!   z0h_new      surface roughness, it is a copy from z0_new
+!   qsurf        air moisture at surface
+!
+    INCLUDE "YOMCST.h"
+  
+!
+! Parametres d'entree
+!****************************************************************************************
+    INTEGER, INTENT(IN)                       :: itime
+    REAL, INTENT(IN)                          :: dtime
+    REAL, INTENT(IN)                          :: date0
+    INTEGER, INTENT(IN)                       :: knon
+    INTEGER, DIMENSION(klon), INTENT(IN)      :: knindex
+    LOGICAL, INTENT(IN)                       :: debut, lafin
+    REAL, DIMENSION(klon,nbsrf), INTENT(IN)   :: pctsrf
+    REAL, DIMENSION(klon), INTENT(IN)         :: rlon, rlat
+    REAL, DIMENSION(klon), INTENT(IN)         :: yrmu0 ! cosine of solar zenith angle
+    REAL, DIMENSION(klon), INTENT(IN)         :: plev
+    REAL, DIMENSION(klon), INTENT(IN)         :: u1_lay, v1_lay, gustiness
+    REAL, DIMENSION(klon), INTENT(IN)         :: temp_air, spechum
+    REAL, DIMENSION(klon), INTENT(IN)         :: epot_air, ccanopy
+    REAL, DIMENSION(klon), INTENT(IN)         :: tq_cdrag
+    REAL, DIMENSION(klon), INTENT(IN)         :: petAcoef, peqAcoef
+    REAL, DIMENSION(klon), INTENT(IN)         :: petBcoef, peqBcoef
+    REAL, DIMENSION(klon), INTENT(IN)         :: precip_rain, precip_snow
+    REAL, DIMENSION(klon), INTENT(IN)         :: lwdown, swnet, swdown, ps
+    REAL, DIMENSION(klon), INTENT(IN)         :: q2m, t2m
+
+! Parametres de sortie
+!****************************************************************************************
+    REAL, DIMENSION(klon), INTENT(OUT)        :: evap, fluxsens, fluxlat, qsurf
+    REAL, DIMENSION(klon), INTENT(OUT)        :: tsol_rad, tsurf_new
+    REAL, DIMENSION(klon), INTENT(OUT)        :: alb1_new, alb2_new
+    REAL, DIMENSION(klon), INTENT(OUT)        :: emis_new, z0_new, z0h_new
+
+! Local
+!****************************************************************************************
+    INTEGER                                   :: ij, jj, igrid, ireal, index
+    INTEGER                                   :: error
+    REAL, DIMENSION(klon)                     :: swdown_vrai
+    CHARACTER (len = 20)                      :: modname = 'surf_land_orchidee'
+    CHARACTER (len = 80)                      :: abort_message
+    LOGICAL,SAVE                              :: check = .FALSE.
+    !$OMP THREADPRIVATE(check)
+
+! type de couplage dans sechiba
+!  character (len=10)   :: coupling = 'implicit' 
+! drapeaux controlant les appels dans SECHIBA
+!  type(control_type), save   :: control_in
+! Preserved albedo
+    REAL, ALLOCATABLE, DIMENSION(:), SAVE     :: albedo_keep, zlev
+    !$OMP THREADPRIVATE(albedo_keep,zlev)
+! coordonnees geographiques
+    REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: lalo
+    !$OMP THREADPRIVATE(lalo)
+! pts voisins
+    INTEGER,ALLOCATABLE, DIMENSION(:,:), SAVE :: neighbours
+    !$OMP THREADPRIVATE(neighbours)
+! fractions continents
+    REAL,ALLOCATABLE, DIMENSION(:), SAVE      :: contfrac
+    !$OMP THREADPRIVATE(contfrac)
+! resolution de la grille
+    REAL, ALLOCATABLE, DIMENSION (:,:), SAVE  :: resolution
+    !$OMP THREADPRIVATE(resolution)
+
+    REAL, ALLOCATABLE, DIMENSION (:,:), SAVE  :: lon_scat, lat_scat  
+    !$OMP THREADPRIVATE(lon_scat,lat_scat)
+
+    LOGICAL, SAVE                             :: lrestart_read = .TRUE.
+    !$OMP THREADPRIVATE(lrestart_read)
+    LOGICAL, SAVE                             :: lrestart_write = .FALSE.
+    !$OMP THREADPRIVATE(lrestart_write)
+
+    REAL, DIMENSION(knon,2)                   :: albedo_out
+
+! Pb de nomenclature
+    REAL, DIMENSION(klon)                     :: petA_orc, peqA_orc
+    REAL, DIMENSION(klon)                     :: petB_orc, peqB_orc
+! Pb de correspondances de grilles
+    INTEGER, DIMENSION(:), SAVE, ALLOCATABLE  :: ig, jg
+    !$OMP THREADPRIVATE(ig,jg)
+    INTEGER :: indi, indj
+    INTEGER, SAVE, ALLOCATABLE,DIMENSION(:)   :: ktindex
+    !$OMP THREADPRIVATE(ktindex)
+
+! Essai cdrag
+    REAL, DIMENSION(klon)                     :: cdrag
+    INTEGER,SAVE                              :: offset
+    !$OMP THREADPRIVATE(offset)
+
+    REAL, DIMENSION(klon_glo)                 :: rlon_g,rlat_g
+    INTEGER, SAVE                             :: orch_comm
+    !$OMP THREADPRIVATE(orch_comm)
+
+    REAL, ALLOCATABLE, DIMENSION(:), SAVE     :: coastalflow
+    !$OMP THREADPRIVATE(coastalflow)
+    REAL, ALLOCATABLE, DIMENSION(:), SAVE     :: riverflow
+    !$OMP THREADPRIVATE(riverflow)
+    
+    INTEGER :: orch_omp_rank
+    INTEGER :: orch_omp_size
+!
+! Fin definition
+!****************************************************************************************
+
+    IF (check) WRITE(lunout,*)'Entree ', modname
+  
+! Initialisation
+  
+    IF (debut) THEN
+! Test of coherence between variable ok_veget and cpp key CPP_VEGET
+#ifndef CPP_VEGET
+       abort_message='Pb de coherence: ok_veget = .true. mais CPP_VEGET = .false.'
+       CALL abort_physic(modname,abort_message,1)
+#endif
+
+       CALL Init_surf_para(knon)
+       ALLOCATE(ktindex(knon))
+       IF ( .NOT. ALLOCATED(albedo_keep)) THEN
+!ym          ALLOCATE(albedo_keep(klon))
+!ym bizarre que non alloué en knon precedement
+          ALLOCATE(albedo_keep(knon))
+          ALLOCATE(zlev(knon))
+       ENDIF
+! Pb de correspondances de grilles
+       ALLOCATE(ig(klon))
+       ALLOCATE(jg(klon))
+       ig(1) = 1
+       jg(1) = 1
+       indi = 0
+       indj = 2
+       DO igrid = 2, klon - 1
+          indi = indi + 1
+          IF ( indi > nbp_lon) THEN
+             indi = 1
+             indj = indj + 1
+          ENDIF
+          ig(igrid) = indi
+          jg(igrid) = indj
+       ENDDO
+       ig(klon) = 1
+       jg(klon) = nbp_lat
+
+       IF ((.NOT. ALLOCATED(lalo))) THEN
+          ALLOCATE(lalo(knon,2), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation lalo'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       IF ((.NOT. ALLOCATED(lon_scat))) THEN
+          ALLOCATE(lon_scat(nbp_lon,nbp_lat), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation lon_scat'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       IF ((.NOT. ALLOCATED(lat_scat))) THEN
+          ALLOCATE(lat_scat(nbp_lon,nbp_lat), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation lat_scat'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       lon_scat = 0.
+       lat_scat = 0.
+       DO igrid = 1, knon
+          index = knindex(igrid)
+          lalo(igrid,2) = rlon(index)
+          lalo(igrid,1) = rlat(index)
+       ENDDO
+
+       
+       
+       CALL Gather(rlon,rlon_g)
+       CALL Gather(rlat,rlat_g)
+
+       IF (is_mpi_root) THEN
+          index = 1
+          DO jj = 2, nbp_lat-1
+             DO ij = 1, nbp_lon
+                index = index + 1
+                lon_scat(ij,jj) = rlon_g(index)
+                lat_scat(ij,jj) = rlat_g(index)
+             ENDDO
+          ENDDO
+          lon_scat(:,1) = lon_scat(:,2)
+          lat_scat(:,1) = rlat_g(1)
+          lon_scat(:,nbp_lat) = lon_scat(:,2)
+          lat_scat(:,nbp_lat) = rlat_g(klon_glo)
+       ENDIF
+   
+       CALL bcast(lon_scat)
+       CALL bcast(lat_scat)
+!
+! Allouer et initialiser le tableau des voisins et des fraction de continents
+!
+       IF ( (.NOT.ALLOCATED(neighbours))) THEN
+          ALLOCATE(neighbours(knon,8), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation neighbours'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       neighbours = -1.
+       IF (( .NOT. ALLOCATED(contfrac))) THEN
+          ALLOCATE(contfrac(knon), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation contfrac'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+
+       DO igrid = 1, knon
+          ireal = knindex(igrid)
+          contfrac(igrid) = pctsrf(ireal,is_ter)
+       ENDDO
+
+
+       CALL Init_neighbours(knon,neighbours,knindex,pctsrf(:,is_ter))
+
+!
+!  Allocation et calcul resolutions
+       IF ( (.NOT.ALLOCATED(resolution))) THEN
+          ALLOCATE(resolution(knon,2), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation resolution'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       DO igrid = 1, knon
+          ij = knindex(igrid)
+          resolution(igrid,1) = dx(ij)
+          resolution(igrid,2) = dy(ij)
+       ENDDO
+     
+       ALLOCATE(coastalflow(klon), stat = error)
+       IF (error /= 0) THEN
+          abort_message='Pb allocation coastalflow'
+          CALL abort_physic(modname,abort_message,1)
+       ENDIF
+       
+       ALLOCATE(riverflow(klon), stat = error)
+       IF (error /= 0) THEN
+          abort_message='Pb allocation riverflow'
+          CALL abort_physic(modname,abort_message,1)
+       ENDIF
+!
+! carbon_cycle_cpl not possible with this interface and version of ORHCHIDEE
+!
+       IF (carbon_cycle_cpl) THEN
+          abort_message='carbon_cycle_cpl not yet possible with this interface of ORCHIDEE'
+          CALL abort_physic(modname,abort_message,1)
+       END IF
+       
+    ENDIF                          ! (fin debut) 
+ 
+
+! 
+! Appel a la routine sols continentaux
+!
+    IF (lafin) lrestart_write = .TRUE.
+    IF (check) WRITE(lunout,*)'lafin ',lafin,lrestart_write
+     
+    petA_orc(1:knon) = petBcoef(1:knon) * dtime
+    petB_orc(1:knon) = petAcoef(1:knon)
+    peqA_orc(1:knon) = peqBcoef(1:knon) * dtime
+    peqB_orc(1:knon) = peqAcoef(1:knon)
+
+    cdrag = 0.
+    cdrag(1:knon) = tq_cdrag(1:knon)
+
+! zlev(1:knon) = (100.*plev(1:knon))/((ps(1:knon)/287.05*temp_air(1:knon))*9.80665)
+!    zlev(1:knon) = (100.*plev(1:knon))/((ps(1:knon)/RD*temp_air(1:knon))*RG)
+     zlev(1:knon) = plev(1:knon)*RD*temp_air(1:knon)/((ps(1:knon)*100.0)*RG)
+
+
+! PF et PASB
+!   where(cdrag > 0.01) 
+!     cdrag = 0.01
+!   endwhere
+!  write(*,*)'Cdrag = ',minval(cdrag),maxval(cdrag)
+
+  
+    IF (debut) THEN
+       CALL Init_orchidee_index(knon,knindex,offset,ktindex)
+       CALL Get_orchidee_communicator(orch_comm,orch_omp_size,orch_omp_rank)
+       CALL Init_synchro_omp
+       
+       IF (knon > 0) THEN
+#ifdef CPP_VEGET
+         CALL Init_intersurf(nbp_lon,nbp_lat,knon,ktindex,offset,orch_omp_size,orch_omp_rank,orch_comm)
+#endif
+       ENDIF
+
+       
+       IF (knon > 0) THEN
+
+#ifdef CPP_VEGET
+          CALL intersurf_main (itime+itau_phy-1, nbp_lon, nbp_lat, knon, ktindex, dtime, &
+               lrestart_read, lrestart_write, lalo, &
+               contfrac, neighbours, resolution, date0, &
+               zlev,  u1_lay, v1_lay, spechum, temp_air, epot_air, ccanopy, &
+               cdrag, petA_orc, peqA_orc, petB_orc, peqB_orc, &
+               precip_rain, precip_snow, lwdown, swnet, swdown, ps, &
+               evap, fluxsens, fluxlat, coastalflow, riverflow, &
+               tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0_new, &
+               lon_scat, lat_scat, q2m, t2m, coszang=yrmu0)
+#endif         
+       ENDIF
+
+       CALL Synchro_omp
+
+       albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
+
+    ENDIF
+
+    
+!  swdown_vrai(1:knon) = swnet(1:knon)/(1. - albedo_keep(1:knon))
+    swdown_vrai(1:knon) = swdown(1:knon)
+
+    IF (knon > 0) THEN
+#ifdef CPP_VEGET    
+       CALL intersurf_main (itime+itau_phy, nbp_lon, nbp_lat, knon, ktindex, dtime,  &
+            lrestart_read, lrestart_write, lalo, &
+            contfrac, neighbours, resolution, date0, &
+            zlev,  u1_lay(1:knon), v1_lay(1:knon), spechum(1:knon), temp_air(1:knon), epot_air(1:knon), ccanopy(1:knon), &
+            cdrag(1:knon), petA_orc(1:knon), peqA_orc(1:knon), petB_orc(1:knon), peqB_orc(1:knon), &
+            precip_rain(1:knon), precip_snow(1:knon), lwdown(1:knon), swnet(1:knon), swdown_vrai(1:knon), ps(1:knon), &
+            evap(1:knon), fluxsens(1:knon), fluxlat(1:knon), coastalflow(1:knon), riverflow(1:knon), &
+            tsol_rad(1:knon), tsurf_new(1:knon), qsurf(1:knon), albedo_out(1:knon,:), emis_new(1:knon), z0_new(1:knon), &
+            lon_scat, lat_scat, q2m, t2m, coszang=yrmu0(1:knon))
+#endif       
+    ENDIF
+    z0h_new(:)=z0_new(:)
+
+    CALL Synchro_omp
+    
+    albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
+
+!* Send to coupler
+!
+    IF (type_ocean=='couple') THEN
+       CALL cpl_send_land_fields(itime, knon, knindex, &
+            riverflow, coastalflow)
+    ENDIF
+
+    alb1_new(1:knon) = albedo_out(1:knon,1) 
+    alb2_new(1:knon) = albedo_out(1:knon,2)
+
+! Convention orchidee: positif vers le haut
+    fluxsens(1:knon) = -1. * fluxsens(1:knon)
+    fluxlat(1:knon)  = -1. * fluxlat(1:knon)
+    
+!  evap     = -1. * evap
+
+    IF (debut) lrestart_read = .FALSE.
+    
+    IF (debut) CALL Finalize_surf_para
+
+    
+  END SUBROUTINE surf_land_orchidee
+!
+!****************************************************************************************
+!
+  SUBROUTINE Init_orchidee_index(knon,knindex,offset,ktindex)
+  USE mod_surf_para
+  USE mod_grid_phy_lmdz
+  
+    INTEGER,INTENT(IN)    :: knon
+    INTEGER,INTENT(IN)    :: knindex(klon)    
+    INTEGER,INTENT(OUT)   :: offset
+    INTEGER,INTENT(OUT)   :: ktindex(klon)
+    
+    INTEGER               :: ktindex_glo(knon_glo)
+    INTEGER               :: offset_para(0:omp_size*mpi_size-1)
+    INTEGER               :: LastPoint
+    INTEGER               :: task
+    
+    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin-1)+(klon_omp_begin-1)+nbp_lon-1
+    
+    CALL gather_surf(ktindex(1:knon),ktindex_glo) 
+    
+    IF (is_mpi_root .AND. is_omp_root) THEN
+      LastPoint=0
+      DO Task=0,mpi_size*omp_size-1
+        IF (knon_glo_para(Task)>0) THEN
+           offset_para(task)= LastPoint-MOD(LastPoint,nbp_lon)
+           LastPoint=ktindex_glo(knon_glo_end_para(task))
+        ENDIF
+      ENDDO
+    ENDIF
+    
+    CALL bcast(offset_para)
+    
+    offset=offset_para(omp_size*mpi_rank+omp_rank)
+    
+    ktindex(1:knon)=ktindex(1:knon)-offset
+
+  END SUBROUTINE Init_orchidee_index
+
+!
+!************************* ***************************************************************
+! 
+
+  SUBROUTINE Get_orchidee_communicator(orch_comm,orch_omp_size,orch_omp_rank)
+  USE  mod_surf_para
+      
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif    
+
+    INTEGER,INTENT(OUT) :: orch_comm
+    INTEGER,INTENT(OUT) :: orch_omp_size
+    INTEGER,INTENT(OUT) :: orch_omp_rank
+    INTEGER             :: color
+    INTEGER             :: i,ierr
+!
+! End definition
+!****************************************************************************************
+    
+    
+    IF (is_omp_root) THEN          
+      
+      IF (knon_mpi==0) THEN 
+         color = 0
+      ELSE 
+         color = 1
+      ENDIF
+    
+#ifdef CPP_MPI    
+      CALL MPI_COMM_SPLIT(COMM_LMDZ_PHY,color,mpi_rank,orch_comm,ierr)
+#endif
+    
+    ENDIF
+    CALL bcast_omp(orch_comm)
+    
+    IF (knon_mpi /= 0) THEN
+      orch_omp_size=0
+      DO i=0,omp_size-1
+        IF (knon_omp_para(i) /=0) THEN
+          orch_omp_size=orch_omp_size+1
+          IF (i==omp_rank) orch_omp_rank=orch_omp_size-1
+        ENDIF
+      ENDDO
+    ENDIF
+   
+    
+  END SUBROUTINE Get_orchidee_communicator
+!
+!****************************************************************************************
+!  
+
+  SUBROUTINE Init_neighbours(knon,neighbours,knindex,pctsrf)
+    USE mod_grid_phy_lmdz
+    USE mod_surf_para    
+    USE indice_sol_mod
+
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif    
+
+! Input arguments
+!****************************************************************************************
+    INTEGER, INTENT(IN)                     :: knon
+    INTEGER, DIMENSION(klon), INTENT(IN)    :: knindex
+    REAL, DIMENSION(klon), INTENT(IN)       :: pctsrf
+    
+! Output arguments
+!****************************************************************************************
+    INTEGER, DIMENSION(knon,8), INTENT(OUT) :: neighbours
+
+! Local variables
+!****************************************************************************************
+    INTEGER                              :: i, igrid, jj, ij, iglob
+    INTEGER                              :: ierr, ireal, index
+    INTEGER, DIMENSION(8,3)              :: off_ini
+    INTEGER, DIMENSION(8)                :: offset  
+    INTEGER, DIMENSION(nbp_lon,nbp_lat)  :: correspond
+    INTEGER, DIMENSION(knon_glo)         :: ktindex_glo
+    INTEGER, DIMENSION(knon_glo,8)       :: neighbours_glo
+    REAL, DIMENSION(klon_glo)            :: pctsrf_glo
+    INTEGER                              :: ktindex(klon)
+!
+! End definition
+!****************************************************************************************
+
+    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin-1)+(klon_omp_begin-1)+nbp_lon-1
+    
+    CALL gather_surf(ktindex(1:knon),ktindex_glo)
+    CALL gather(pctsrf,pctsrf_glo)
+    
+    IF (is_mpi_root .AND. is_omp_root) THEN
+      neighbours_glo(:,:)=-1
+!  Initialisation des offset    
+!
+! offset bord ouest
+       off_ini(1,1) = - nbp_lon   ; off_ini(2,1) = - nbp_lon + 1     ; off_ini(3,1) = 1
+       off_ini(4,1) = nbp_lon + 1 ; off_ini(5,1) = nbp_lon           ; off_ini(6,1) = 2 * nbp_lon - 1
+       off_ini(7,1) = nbp_lon -1  ; off_ini(8,1) = - 1 
+! offset point normal
+       off_ini(1,2) = - nbp_lon   ; off_ini(2,2) = - nbp_lon + 1     ; off_ini(3,2) = 1
+       off_ini(4,2) = nbp_lon + 1 ; off_ini(5,2) = nbp_lon           ; off_ini(6,2) = nbp_lon - 1
+       off_ini(7,2) = -1          ; off_ini(8,2) = - nbp_lon - 1
+! offset bord   est
+       off_ini(1,3) = - nbp_lon   ; off_ini(2,3) = - 2 * nbp_lon + 1 ; off_ini(3,3) = - nbp_lon + 1
+       off_ini(4,3) =  1          ; off_ini(5,3) = nbp_lon           ; off_ini(6,3) = nbp_lon - 1
+       off_ini(7,3) = -1          ; off_ini(8,3) = - nbp_lon - 1
+!
+!
+! Attention aux poles
+!
+       DO igrid = 1, knon_glo
+          index = ktindex_glo(igrid)
+          jj = INT((index - 1)/nbp_lon) + 1
+          ij = index - (jj - 1) * nbp_lon
+          correspond(ij,jj) = igrid
+       ENDDO
+!sonia : Les mailles des voisines doivent etre toutes egales (pour couplage orchidee)
+       IF (knon_glo == 1) THEN
+         igrid = 1
+         DO i = 1,8
+           neighbours_glo(igrid, i) = igrid
+         ENDDO
+       ELSE
+       print*,'sonia : knon_glo,ij,jj', knon_glo, ij,jj
+       
+       DO igrid = 1, knon_glo
+          iglob = ktindex_glo(igrid)
+          
+          IF (MOD(iglob, nbp_lon) == 1) THEN
+             offset = off_ini(:,1)
+          ELSE IF(MOD(iglob, nbp_lon) == 0) THEN
+             offset = off_ini(:,3)
+          ELSE
+             offset = off_ini(:,2)
+          ENDIF
+          
+          DO i = 1, 8
+             index = iglob + offset(i)
+             ireal = (MIN(MAX(1, index - nbp_lon + 1), klon_glo))
+             IF (pctsrf_glo(ireal) > EPSFRA) THEN
+                jj = INT((index - 1)/nbp_lon) + 1
+                ij = index - (jj - 1) * nbp_lon
+                neighbours_glo(igrid, i) = correspond(ij, jj)
+             ENDIF
+          ENDDO
+       ENDDO
+       ENDIF !fin knon_glo == 1
+
+    ENDIF
+    
+    DO i = 1, 8
+      CALL scatter_surf(neighbours_glo(:,i),neighbours(1:knon,i))
+    ENDDO
+  END SUBROUTINE Init_neighbours
+
+!
+!****************************************************************************************
+!
+#endif
+END MODULE surf_land_orchidee_noz0h_mod
Index: /LMDZ5/branches/testing/libf/phylmd/time_phylmdz_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/time_phylmdz_mod.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/time_phylmdz_mod.F90	(revision 2594)
@@ -83,4 +83,5 @@
   USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
+  INCLUDE 'YOMCST.h'
     REAL,INTENT(IN) :: pdtphys_
     REAL            :: julian_date
@@ -94,8 +95,8 @@
     
     ! Update elapsed time since begining of run:
-    current_time=current_time+pdtphys
+    current_time=current_time+pdtphys/rday
 
     ! Compute corresponding Julian date and update calendar
-    CALL ymds2ju(annee_ref,1,day_ini,start_time+current_time,julian_date)
+    CALL ymds2ju(annee_ref,1,day_ini,(start_time+current_time)*rday,julian_date)
     CALL phys_cal_update(julian_date)
     
Index: /LMDZ5/branches/testing/libf/phylmd/yamada4.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/yamada4.F90	(revision 2593)
+++ /LMDZ5/branches/testing/libf/phylmd/yamada4.F90	(revision 2594)
@@ -1,15 +1,32 @@
-
-! $Header$
-
-SUBROUTINE yamada4(ngrid, dt, g, rconst, plev, temp, zlev, zlay, u, v, teta, &
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+SUBROUTINE yamada4(ni, nsrf, ngrid, dt, g, rconst, plev, temp, zlev, zlay, u, v, teta, &
     cd, q2, km, kn, kq, ustar, iflag_pbl)
+
   USE dimphy
-  USE print_control_mod, ONLY: prt_level
   USE ioipsl_getin_p_mod, ONLY : getin_p
 
   IMPLICIT NONE
-
+  include "iniprint.h"
+  ! .......................................................................
+  ! ym#include "dimensions.h"
+  ! ym#include "dimphy.h"
+  ! ************************************************************************************************
+  !
+  ! yamada4: subroutine qui calcule le transfert turbulent avec une fermeture d'ordre 2 ou 2.5
+  ! 
+  ! Reference: Simulation of nocturnal drainage flows by a q2l Turbulence Closure Model
+  !            Yamada T.
+  !            J. Atmos. Sci, 40, 91-106, 1983
+  !
+  !************************************************************************************************
+  ! Input :
+  !'======
+  ! ni: indice horizontal sur la grille de base, non restreinte
+  ! nsrf: type de surface
+  ! ngrid: nombre de mailles concern??es sur l'horizontal
   ! dt : pas de temps
   ! g  : g
+  ! rconst: constante de l'air sec
   ! zlev : altitude a chaque niveau (interface inferieure de la couche
   ! de meme indice)
@@ -17,11 +34,35 @@
   ! u,v : vitesse au centre de chaque couche
   ! (en entree : la valeur au debut du pas de temps)
-  ! teta : temperature potentielle au centre de chaque couche
+  ! teta : temperature potentielle virtuelle au centre de chaque couche
   ! (en entree : la valeur au debut du pas de temps)
-  ! cd : cdrag
+  ! cd : cdrag pour la quantit?? de mouvement
   ! (en entree : la valeur au debut du pas de temps)
+  ! ustar: vitesse de friction calcul??e par une formule diagnostique 
+  ! iflag_pbl: flag pour choisir des options du sch??ma de turbulence
+  !
+  !             iflag_pbl doit valoir entre 6 et 9
+  !             l=6, on prend  systematiquement une longueur d'equilibre
+  !             iflag_pbl=6 : MY 2.0
+  !             iflag_pbl=7 : MY 2.0.Fournier
+  !             iflag_pbl=8/9 : MY 2.5
+  !             iflag_pbl=8 with special obsolete treatments for convergence
+  !             with Cmpi5 NPv3.1 simulations
+  !             iflag_pbl=10/11 :  New scheme M2 and N2 explicit and dissiptation exact
+  !             iflag_pbl=12 = 11 with vertical diffusion off q2
+  !
+  !             2013/04/01 (FH hourdin@lmd.jussieu.fr)
+  !             Correction for very stable PBLs (iflag_pbl=10 and 11)
+  !             iflag_pbl=8 converges numerically with NPv3.1
+  !             iflag_pbl=11 -> the model starts with NP from start files created by ce0l
+  !                          -> the model can run with longer time-steps.
+  !
+  ! Inpout/Output :
+  !==============
   ! q2 : $q^2$ au bas de chaque couche
   ! (en entree : la valeur au debut du pas de temps)
   ! (en sortie : la valeur a la fin du pas de temps)
+ 
+  ! Outputs:
+  !==========
   ! km : diffusivite turbulente de quantite de mouvement (au bas de chaque
   ! couche)
@@ -29,22 +70,14 @@
   ! kn : diffusivite turbulente des scalaires (au bas de chaque couche)
   ! (en sortie : la valeur a la fin du pas de temps)
-
-  ! iflag_pbl doit valoir entre 6 et 9
-  ! l=6, on prend  systematiquement une longueur d'equilibre
-  ! iflag_pbl=6 : MY 2.0
-  ! iflag_pbl=7 : MY 2.0.Fournier
-  ! iflag_pbl=8/9 : MY 2.5
-  ! iflag_pbl=8 with special obsolete treatments for convergence
-  ! with Cmpi5 NPv3.1 simulations
-  ! iflag_pbl=10/11 :  New scheme M2 and N2 explicit and dissiptation exact
-  ! iflag_pbl=12 = 11 with vertical diffusion off q2
-
-  ! 2013/04/01 (FH hourdin@lmd.jussieu.fr)
-  ! Correction for very stable PBLs (iflag_pbl=10 and 11)
-  ! iflag_pbl=8 converges numerically with NPv3.1
-  ! iflag_pbl=11 -> the model starts with NP from start files created by ce0l
-  ! -> the model can run with longer time-steps.
-  ! .......................................................................
-
+  !
+  !.......................................................................
+
+  !=======================================================================
+  ! Declarations:
+  !=======================================================================
+
+
+  ! Inputs/Outputs
+  !----------------
   REAL dt, g, rconst
   REAL plev(klon, klev+1), temp(klon, klev)
@@ -57,18 +90,25 @@
   REAL teta(klon, klev)
   REAL cd(klon)
-  REAL q2(klon, klev+1), qpre
+  REAL q2(klon, klev+1)
   REAL unsdz(klon, klev)
   REAL unsdzdec(klon, klev+1)
-
+  REAL kn(klon, klev+1)
   REAL km(klon, klev+1)
-  REAL kmpre(klon, klev+1), tmp2
+  INTEGER iflag_pbl, ngrid, nsrf
+  INTEGER ni(klon)
+
+
+  ! Local
+  !-------
+
+  INCLUDE "clesphys.h"
+
+
+  REAL kmpre(klon, klev+1), tmp2, qpre
   REAL mpre(klon, klev+1)
-  REAL kn(klon, klev+1)
   REAL kq(klon, klev+1)
   REAL ff(klon, klev+1), delta(klon, klev+1)
   REAL aa(klon, klev+1), aa0, aa1
-  INTEGER iflag_pbl, ngrid
   INTEGER nlay, nlev
-
   LOGICAL first
   INTEGER ipas
@@ -77,50 +117,50 @@
   DATA first, ipas/.FALSE., 0/
   !$OMP THREADPRIVATE( first,ipas)
-  REAL,SAVE :: lmixmin=1.
-  !$OMP THREADPRIVATE(lmixmin) 
-
-
+  LOGICAL hboville
   INTEGER ig, k
-
-
   REAL ri, zrif, zalpha, zsm, zsn
   REAL rif(klon, klev+1), sm(klon, klev+1), alpha(klon, klev)
-
   REAL m2(klon, klev+1), dz(klon, klev+1), zq, n2(klon, klev+1)
   REAL dtetadz(klon, klev+1)
   REAL m2cstat, mcstat, kmcstat
   REAL l(klon, klev+1)
-  REAL, ALLOCATABLE, SAVE :: l0(:)
-  !$OMP THREADPRIVATE(l0)
-  REAL sq(klon), sqz(klon), zz(klon, klev+1)
+  REAL zz(klon, klev+1)
   INTEGER iter
-
   REAL ric, rifc, b1, kap
   SAVE ric, rifc, b1, kap
   DATA ric, rifc, b1, kap/0.195, 0.191, 16.6, 0.4/
   !$OMP THREADPRIVATE(ric,rifc,b1,kap)
+  REAL seuilsm, seuilalpha
+  REAL,SAVE :: lmixmin
+  !$OMP THREADPRIVATE(lmixmin)
   REAL frif, falpha, fsm
-  REAL fl, zzz, zl0, zq2, zn2
-
   REAL rino(klon, klev+1), smyam(klon, klev), styam(klon, klev), &
     lyam(klon, klev), knyam(klon, klev), w2yam(klon, klev), t2yam(klon, klev)
   LOGICAL, SAVE :: firstcall = .TRUE.
   !$OMP THREADPRIVATE(firstcall)
+
+
+  ! Fonctions utilis??es
+  !--------------------
+
   frif(ri) = 0.6588*(ri+0.1776-sqrt(ri*ri-0.3221*ri+0.03156))
   falpha(ri) = 1.318*(0.2231-ri)/(0.2341-ri)
   fsm(ri) = 1.96*(0.1912-ri)*(0.2341-ri)/((1.-ri)*(0.2231-ri))
-  fl(zzz, zl0, zq2, zn2) = max(min(l0(ig)*kap*zlev(ig, &
-    k)/(kap*zlev(ig,k)+l0(ig)),0.5*sqrt(q2(ig,k))/sqrt( &
-    max(n2(ig,k),1.E-10))), lmixmin)
-
-
-  nlay = klev
-  nlev = klev + 1
+  
 
   IF (firstcall) THEN
-    ALLOCATE (l0(klon))
     firstcall = .FALSE.
+    lmixmin=1.
     CALL getin_p('lmixmin',lmixmin)
   END IF
+
+
+
+!===============================================================================
+! Flags, tests et ??valuations de constantes
+!===============================================================================
+
+! On utilise ou non la routine de Holstalg Boville pour les cas tres stables
+   hboville=.TRUE.
 
 
@@ -129,19 +169,23 @@
   END IF
 
+! Seuil dans le code de turbulence 
+ seuilalpha=1.12
+ seuilsm=0.085
+
+  nlay = klev
+  nlev = klev + 1
   ipas = ipas + 1
 
 
-  ! .......................................................................
-  ! les increments verticaux
-  ! .......................................................................
-
-  ! !!!!! allerte !!!!!c
-  ! !!!!! zlev n'est pas declare a nlev !!!!!c
-  ! !!!!! ---->
+!========================================================================
+! Calcul des increments verticaux
+!=========================================================================
+
+  
+! Attention: zlev n'est pas declare a nlev
   DO ig = 1, ngrid
     zlev(ig, nlev) = zlay(ig, nlay) + (zlay(ig,nlay)-zlev(ig,nlev-1))
   END DO
-  ! !!!!! <----
-  ! !!!!! allerte !!!!!c
+
 
   DO k = 1, nlay
@@ -162,13 +206,17 @@
   END DO
 
-  ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-  ! Computing M^2, N^2, Richardson numbers, stability functions
-  ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    ! initialize arrays:
-  m2(:, :) = 0.0
-  sm(:, :) = 0.0
-  rif(:, :) = 0.0
-
+!=========================================================================
+! Richardson number and stability functions
+!=========================================================================
+ 
+! initialize arrays:
+
+  m2(1:ngrid, :) = 0.0
+  sm(1:ngrid, :) = 0.0
+  rif(1:ngrid, :) = 0.0
+
+!------------------------------------------------------------
   DO k = 2, klev
+
     DO ig = 1, ngrid
       dz(ig, k) = zlay(ig, k) - zlay(ig, k-1)
@@ -177,5 +225,4 @@
       dtetadz(ig, k) = (teta(ig,k)-teta(ig,k-1))/dz(ig, k)
       n2(ig, k) = g*2.*dtetadz(ig, k)/(teta(ig,k-1)+teta(ig,k))
-      ! n2(ig,k)=0.
       ri = n2(ig, k)/max(m2(ig,k), 1.E-10)
       IF (ri<ric) THEN
@@ -184,10 +231,11 @@
         rif(ig, k) = rifc
       END IF
+
       IF (rif(ig,k)<0.16) THEN
         alpha(ig, k) = falpha(rif(ig,k))
         sm(ig, k) = fsm(rif(ig,k))
       ELSE
-        alpha(ig, k) = 1.12
-        sm(ig, k) = 0.085
+        alpha(ig, k) = seuilalpha
+        sm(ig, k) = seuilsm
       END IF
       zz(ig, k) = b1*m2(ig, k)*(1.-rif(ig,k))*sm(ig, k)
@@ -196,78 +244,42 @@
 
 
-  ! ====================================================================
-  ! Computing the mixing length
-  ! ====================================================================
-
-  ! Mise a jour de l0
-  IF (iflag_pbl==8 .OR. iflag_pbl==10) THEN
-
-    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    ! Iterative computation of l0
-    ! This version is kept for iflag_pbl only for convergence
-    ! with NPv3.1 Cmip5 simulations
-    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-    DO ig = 1, ngrid
-      sq(ig) = 1.E-10
-      sqz(ig) = 1.E-10
-    END DO
-    DO k = 2, klev - 1
-      DO ig = 1, ngrid
-        zq = sqrt(q2(ig,k))
-        sqz(ig) = sqz(ig) + zq*zlev(ig, k)*(zlay(ig,k)-zlay(ig,k-1))
-        sq(ig) = sq(ig) + zq*(zlay(ig,k)-zlay(ig,k-1))
-      END DO
-    END DO
-    DO ig = 1, ngrid
-      l0(ig) = 0.2*sqz(ig)/sq(ig)
-    END DO
+
+! ====================================================================
+! Computing the mixing length
+! ====================================================================
+
+ 
+  CALL mixinglength(ni,nsrf,ngrid,iflag_pbl,pbl_lmixmin_alpha,lmixmin,zlay,zlev,u,v,q2,n2, l)
+
+
+
+  !=======================================================================
+  !     DIFFERENT TYPES  DE SCHEMA de  YAMADA
+  !=======================================================================
+
+  !--------------
+  ! Yamada 2.0
+  !--------------
+  IF (iflag_pbl==6) THEN
+ 
+    DO k = 2, klev
+      q2(1:ngrid, k) = l(1:ngrid, k)**2*zz(1:ngrid, k)
+    END DO
+
+
+  !------------------
+  ! Yamada 2.Fournier
+  !------------------
+
+  ELSE IF (iflag_pbl==7) THEN
+
+
+    ! Calcul de l,  km, au pas precedent
+    !....................................
     DO k = 2, klev
       DO ig = 1, ngrid
-        l(ig, k) = fl(zlev(ig,k), l0(ig), q2(ig,k), n2(ig,k))
-      END DO
-    END DO
-    ! print*,'L0 cas 8 ou 10 ',l0
-
-  ELSE
-
-    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    ! In all other case, the assymptotic mixing length l0 is imposed (100m)
-    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-    l0(:) = 150.
-    DO k = 2, klev
-      DO ig = 1, ngrid
-        l(ig, k) = fl(zlev(ig,k), l0(ig), q2(ig,k), n2(ig,k))
-      END DO
-    END DO
-    ! print*,'L0 cas autres ',l0
-
-  END IF
-
-
-  ! ====================================================================
-  ! Yamada 2.0
-  ! ====================================================================
-  IF (iflag_pbl==6) THEN
-
-    DO k = 2, klev
-      q2(:, k) = l(:, k)**2*zz(:, k)
-    END DO
-
-
-  ELSE IF (iflag_pbl==7) THEN
-    ! ====================================================================
-    ! Yamada 2.Fournier
-    ! ====================================================================
-
-    ! Calcul de l,  km, au pas precedent
-    DO k = 2, klev
-      DO ig = 1, ngrid
-        ! print*,'SMML=',sm(ig,k),l(ig,k)
         delta(ig, k) = q2(ig, k)/(l(ig,k)**2*sm(ig,k))
         kmpre(ig, k) = l(ig, k)*sqrt(q2(ig,k))*sm(ig, k)
         mpre(ig, k) = sqrt(m2(ig,k))
-        ! print*,'0L=',k,l(ig,k),delta(ig,k),km(ig,k)
       END DO
     END DO
@@ -278,8 +290,6 @@
         mcstat = sqrt(m2cstat)
 
-        ! print*,'M2 L=',k,mpre(ig,k),mcstat
-
-        ! -----{puis on ecrit la valeur de q qui annule l'equation de m
-        ! supposee en q3}
+     ! Puis on ecrit la valeur de q qui annule l'equation de m supposee en q3
+     !.........................................................................
 
         IF (k==2) THEN
@@ -293,25 +303,24 @@
             (unsdz(ig,k)+unsdz(ig,k-1))
         END IF
-        ! print*,'T2 L=',k,tmp2
+
         tmp2 = kmcstat/(sm(ig,k)/q2(ig,k))/l(ig, k)
         q2(ig, k) = max(tmp2, 1.E-12)**(2./3.)
-        ! print*,'Q2 L=',k,q2(ig,k)
 
       END DO
     END DO
 
+
+    ! ------------------------
+    ! Yamada 2.5 a la Didi
+    !-------------------------
+
   ELSE IF (iflag_pbl==8 .OR. iflag_pbl==9) THEN
-    ! ====================================================================
-    ! Yamada 2.5 a la Didi
-    ! ====================================================================
-
-
-    ! Calcul de l,  km, au pas precedent
+
+    ! Calcul de l, km, au pas precedent
+    !....................................
     DO k = 2, klev
       DO ig = 1, ngrid
-        ! print*,'SMML=',sm(ig,k),l(ig,k)
         delta(ig, k) = q2(ig, k)/(l(ig,k)**2*sm(ig,k))
         IF (delta(ig,k)<1.E-20) THEN
-          ! print*,'ATTENTION   L=',k,'   Delta=',delta(ig,k)
           delta(ig, k) = 1.E-20
         END IF
@@ -319,9 +328,6 @@
         aa0 = (m2(ig,k)-alpha(ig,k)*n2(ig,k)-delta(ig,k)/b1)
         aa1 = (m2(ig,k)*(1.-rif(ig,k))-delta(ig,k)/b1)
-        ! abder      print*,'AA L=',k,aa0,aa1,aa1/max(m2(ig,k),1.e-20)
         aa(ig, k) = aa1*dt/(delta(ig,k)*l(ig,k))
-        ! print*,'0L=',k,l(ig,k),delta(ig,k),km(ig,k)
         qpre = sqrt(q2(ig,k))
-        ! if (iflag_pbl.eq.8 ) then
         IF (aa(ig,k)>0.) THEN
           q2(ig, k) = (qpre+aa(ig,k)*qpre*qpre)**2
@@ -337,5 +343,4 @@
         ! endif
         q2(ig, k) = min(max(q2(ig,k),1.E-10), 1.E4)
-        ! print*,'Q2 L=',k,q2(ig,k),qpre*qpre
       END DO
     END DO
@@ -343,15 +348,10 @@
   ELSE IF (iflag_pbl>=10) THEN
 
-    ! print*,'Schema mixte D'
-    ! print*,'Longueur ',l(:,:)
     DO k = 2, klev - 1
-      DO ig = 1, ngrid
-        l(ig, k) = max(l(ig,k), lmixmin)
-        km(ig, k) = l(ig, k)*sqrt(q2(ig,k))*sm(ig, k)
-        q2(ig, k) = q2(ig, k) + dt*km(ig, k)*m2(ig, k)*(1.-rif(ig,k))
-        q2(ig, k) = min(max(q2(ig,k),1.E-10), 1.E4)
-        q2(ig, k) = 1./(1./sqrt(q2(ig,k))+dt/(2*l(ig,k)*b1))
-        q2(ig, k) = q2(ig, k)*q2(ig, k)
-      END DO
+      km(1:ngrid, k) = l(1:ngrid, k)*sqrt(q2(1:ngrid,k))*sm(1:ngrid, k)
+      q2(1:ngrid, k) = q2(1:ngrid, k) + dt*km(1:ngrid, k)*m2(1:ngrid, k)*(1.-rif(1:ngrid,k))
+      q2(1:ngrid, k) = min(max(q2(1:ngrid,k),1.E-10), 1.E4)
+      q2(1:ngrid, k) = 1./(1./sqrt(q2(1:ngrid,k))+dt/(2*l(1:ngrid,k)*b1))
+      q2(1:ngrid, k) = q2(1:ngrid, k)*q2(1:ngrid, k)
     END DO
 
@@ -362,41 +362,56 @@
   END IF ! Fin du cas 8
 
-  ! print*,'OK8'
 
   ! ====================================================================
-  ! Calcul des coefficients de m�ange
+  ! Calcul des coefficients de melange
   ! ====================================================================
+
   DO k = 2, klev
-    ! print*,'k=',k
     DO ig = 1, ngrid
-      ! abde      print*,'KML=',l(ig,k),q2(ig,k),sm(ig,k)
       zq = sqrt(q2(ig,k))
-      km(ig, k) = l(ig, k)*zq*sm(ig, k)
-      kn(ig, k) = km(ig, k)*alpha(ig, k)
-      kq(ig, k) = l(ig, k)*zq*0.2
-      ! print*,'KML=',km(ig,k),kn(ig,k)
-    END DO
-  END DO
+      km(ig, k) = l(ig, k)*zq*sm(ig, k)     ! For momentum
+      kn(ig, k) = km(ig, k)*alpha(ig, k)    ! For scalars
+      kq(ig, k) = l(ig, k)*zq*0.2           ! For TKE
+    END DO
+  END DO
+
+
+  !====================================================================
+  ! Transport diffusif vertical de la TKE par la TKE
+  !====================================================================
+
+
     ! initialize near-surface and top-layer mixing coefficients
-  kq(1:ngrid, 1) = kq(1:ngrid, 2) ! constant (ie no gradient) near the surface
-  kq(1:ngrid, klev+1) = 0 ! zero at the top
-
-  ! Transport diffusif vertical de la TKE.
+    !...........................................................
+
+  kq(1:ngrid, 1) = kq(1:ngrid, 2)    ! constant (ie no gradient) near the surface
+  kq(1:ngrid, klev+1) = 0            ! zero at the top
+
+    ! Transport diffusif vertical de la TKE.
+    !.......................................
+
   IF (iflag_pbl>=12) THEN
-    ! print*,'YAMADA VDIF'
-    q2(:, 1) = q2(:, 2)
+    q2(1:ngrid, 1) = q2(1:ngrid, 2)
     CALL vdif_q2(dt, g, rconst, ngrid, plev, temp, kq, q2)
   END IF
 
-  ! Traitement des cas noctrunes avec l'introduction d'une longueur
-  ! minilale.
-
-  ! ====================================================================
-  ! Traitement particulier pour les cas tres stables.
-  ! D'apres Holtslag Boville.
+
+  !====================================================================
+  ! Traitement particulier pour les cas tres stables, introduction d'une
+  ! longueur de m??lange minimale
+  !====================================================================
+  !
+  ! Reference: Local versus Nonlocal boundary-layer diffusion in a global climate model
+  !            Holtslag A.A.M. and Boville B.A.
+  !            J. Clim., 6, 1825-1842, 1993
+
+
+ IF (hboville) THEN
+
 
   IF (prt_level>1) THEN
     PRINT *, 'YAMADA4 0'
-  END IF !(prt_level>1) THEN
+  END IF 
+
   DO ig = 1, ngrid
     coriol(ig) = 1.E-4
@@ -404,7 +419,4 @@
   END DO
 
-  ! print*,'pblhmin ',pblhmin
-  ! Test a remettre 21 11 02
-  ! test abd 13 05 02      if(0.eq.1) then
   IF (1==1) THEN
     IF (iflag_pbl==8 .OR. iflag_pbl==10) THEN
@@ -419,11 +431,12 @@
           END IF
           IF (kn(ig,k)<kmin .OR. km(ig,k)<kmin) THEN
-            ! print*,'Seuil min Km K=',k,kmin,km(ig,k),kn(ig,k)
-            ! s           ,sqrt(q2(ig,k)),pblhmin(ig),qmin/sm(ig,k)
+
             kn(ig, k) = kmin
             km(ig, k) = kmin
             kq(ig, k) = kmin
-            ! la longueur de melange est suposee etre l= kap z
-            ! K=l q Sm d'ou q2=(K/l Sm)**2
+
+ ! la longueur de melange est suposee etre l= kap z
+ ! K=l q Sm d'ou q2=(K/l Sm)**2
+
             q2(ig, k) = (qmin/sm(ig,k))**2
           END IF
@@ -432,5 +445,4 @@
 
     ELSE
-
       DO k = 2, klev
         DO ig = 1, ngrid
@@ -442,11 +454,9 @@
           END IF
           IF (kn(ig,k)<kmin .OR. km(ig,k)<kmin) THEN
-            ! print*,'Seuil min Km K=',k,kmin,km(ig,k),kn(ig,k)
-            ! s           ,sqrt(q2(ig,k)),pblhmin(ig),qmin/sm(ig,k)
             kn(ig, k) = kmin
             km(ig, k) = kmin
             kq(ig, k) = kmin
-            ! la longueur de melange est suposee etre l= kap z
-            ! K=l q Sm d'ou q2=(K/l Sm)**2
+ ! la longueur de melange est suposee etre l= kap z
+ ! K=l q Sm d'ou q2=(K/l Sm)**2
             sm(ig, k) = 1.
             alpha(ig, k) = 1.
@@ -463,8 +473,21 @@
   END IF
 
+ END IF ! hboville
+
   IF (prt_level>1) THEN
     PRINT *, 'YAMADA4 1'
   END IF !(prt_level>1) THEN
+
+
+ !======================================================
+ ! Estimations de w'2 et T'2 d'apres Abdela et McFarlane
+ !======================================================
+ !
+ ! Reference: A New Second-Order Turbulence Closure Scheme for the Planetary Boundary Layer
+ !            Abdella K and McFarlane N
+ !            J. Atmos. Sci., 54, 1850-1867, 1997
+
   ! Diagnostique pour stokage
+  !..........................
 
   IF (1==0) THEN
@@ -482,5 +505,7 @@
     knyam(1:ngrid, 2:klev) = kn(1:ngrid, 2:klev)
 
-    ! Estimations de w'2 et T'2 d'apres Abdela et McFarlane
+
+  ! Calcul de w'2 et T'2
+  !.......................
 
     w2yam(1:ngrid, 2:klev) = q2(1:ngrid, 2:klev)*0.24 + &
@@ -493,13 +518,34 @@
   END IF
 
-  ! print*,'OKFIN'
+!============================================================================
+
   first = .FALSE.
   RETURN
+
+
 END SUBROUTINE yamada4
+
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 SUBROUTINE vdif_q2(timestep, gravity, rconst, ngrid, plev, temp, kmy, q2)
+
   USE dimphy
   IMPLICIT NONE
-
-  ! dt : pas de temps
+ 
+  include "dimensions.h"
+
+!    vdif_q2: subroutine qui calcule la diffusion de la TKE par la TKE
+!             avec un schema implicite en temps avec 
+!             inversion d'un syst??me tridiagonal
+! 
+!     Reference: Description of the interface with the surface and 
+!                the computation of the turbulet diffusion in LMDZ
+!                Technical note on LMDZ
+!                Dufresne, J-L, Ghattas, J. and Grandpeix, J-Y
+!
+!============================================================================
+! Declarations
+!============================================================================
 
   REAL plev(klon, klev+1)
@@ -516,11 +562,11 @@
   INTEGER i, k
 
-  ! print*,'RD=',rconst
+
+!=========================================================================
+! Calcul
+!=========================================================================
+
   DO k = 1, klev
     DO i = 1, ngrid
-      ! test
-      ! print*,'i,k',i,k
-      ! print*,'temp(i,k)=',temp(i,k)
-      ! print*,'(plev(i,k)-plev(i,k+1))=',plev(i,k),plev(i,k+1)
       zz = (plev(i,k)+plev(i,k+1))*gravity/(rconst*temp(i,k))
       kstar(i, k) = 0.125*(kmy(i,k+1)+kmy(i,k))*zz*zz/ &
@@ -546,5 +592,4 @@
       denom(i, k) = deltap(i, k) + (1.-beta(i,k+1))*kstar(i, k) + &
         kstar(i, k-1)
-      ! correction d'un bug 10 01 2001
       alpha(i, k) = (q2(i,k)*deltap(i,k)+kstar(i,k)*alpha(i,k+1))/denom(i, k)
       beta(i, k) = kstar(i, k-1)/denom(i, k)
@@ -553,4 +598,5 @@
 
   ! Si on recalcule q2(1)
+  !.......................
   IF (1==0) THEN
     DO i = 1, ngrid
@@ -559,5 +605,5 @@
     END DO
   END IF
-  ! sinon, on peut sauter cette boucle...
+
 
   DO k = 2, klev + 1
@@ -569,9 +615,23 @@
   RETURN
 END SUBROUTINE vdif_q2
-SUBROUTINE vdif_q2e(timestep, gravity, rconst, ngrid, plev, temp, kmy, q2)
-  USE dimphy
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ SUBROUTINE vdif_q2e(timestep, gravity, rconst, ngrid, plev, temp, kmy, q2)
+  
+   USE dimphy
   IMPLICIT NONE
 
-  ! dt : pas de temps
+  include "dimensions.h"
+!
+! vdif_q2e: subroutine qui calcule la diffusion de TKE par la TKE
+!           avec un schema explicite en temps
+
+
+!====================================================
+! Declarations
+!====================================================
 
   REAL plev(klon, klev+1)
@@ -585,6 +645,10 @@
   REAL denom(klon, klev+1), alpha(klon, klev+1), beta(klon, klev+1)
   INTEGER ngrid
-
   INTEGER i, k
+
+
+!==================================================
+! Calcul
+!==================================================
 
   DO k = 1, klev
@@ -621,2 +685,273 @@
   RETURN
 END SUBROUTINE vdif_q2e
+
+!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+SUBROUTINE mixinglength(ni, nsrf, ngrid,iflag_pbl,pbl_lmixmin_alpha,lmixmin,zlay,zlev,u,v,q2,n2, lmix)
+
+
+
+  USE dimphy
+  USE phys_state_var_mod, only: zstd, zsig, zmea
+  USE phys_local_var_mod, only: l_mixmin, l_mix
+
+ ! zstd: ecart type de la'altitud e sous-maille
+ ! zmea: altitude moyenne sous maille
+ ! zsig: pente moyenne de le maille
+
+  USE geometry_mod, only: cell_area
+  ! aire_cell: aire de la maille
+
+  IMPLICIT NONE
+!*************************************************************************
+! Subrourine qui calcule la longueur de m??lange dans le sch??ma de turbulence
+! avec la formule de Blackadar 
+! Calcul d'un  minimum en fonction de l'orographie sous-maille:
+! L'id??e est la suivante: plus il y a de relief, plus il y a du m??lange
+! induit par les circulations meso et submeso ??chelles.
+!
+! References: * The vertical distribution of wind and turbulent exchange in a neutral atmosphere
+!               Blackadar A.K.
+!               J. Geophys. Res., 64, No 8, 1962
+!
+!             * An evaluation of neutral and convective planetary boundary-layer parametrisations relative 
+!               to large eddy simulations
+!               Ayotte K et al 
+!               Boundary Layer Meteorology, 79, 131-175, 1996
+!
+!
+!             * Local Similarity in the Stable Boundary Layer and Mixing length Approaches: consistency of concepts
+!               Van de Wiel B.J.H et al
+!               Boundary-Lay Meteorol, 128, 103-166, 2008
+!
+!
+! Histoire:
+!----------
+! * premi??re r??daction, Etienne et Frederic, 09/06/2016
+!
+! ***********************************************************************
+
+!==================================================================
+! Declarations
+!==================================================================
+
+! Inputs
+!-------
+ INTEGER            ni(klon)           ! indice sur la grille original (non restreinte)
+ INTEGER            nsrf               ! Type de surface
+ INTEGER            ngrid              ! Nombre de points concern??s sur l'horizontal
+ INTEGER            iflag_pbl          ! Choix du sch??ma de turbulence
+ REAL            pbl_lmixmin_alpha  ! on active ou non le calcul de la longueur de melange minimum
+ REAL               lmixmin            ! Minimum absolu de la longueur de m??lange
+ REAL               zlay(klon, klev)   ! altitude du centre de la couche
+ REAL               zlev(klon, klev+1) ! atitude de l'interface inf??rieure de la couche
+ REAL               u(klon, klev)      ! vitesse du vent zonal
+ REAL               v(klon, klev)      ! vitesse du vent meridional
+ REAL               q2(klon, klev+1)   ! energie cin??tique turbulente 
+ REAL               n2(klon, klev+1)   ! frequence de Brunt-Vaisala
+
+!In/out
+!-------
+
+  LOGICAL, SAVE :: firstcall = .TRUE.
+  !$OMP THREADPRIVATE(firstcall)
+
+! Outputs
+!---------
+
+ REAL               lmix(klon, klev+1)    ! Longueur de melange  
+
+
+! Local
+!-------
+  
+ INTEGER  ig,jg, k
+ REAL     h_oro(klon)
+ REAL     hlim(klon)
+ REAL, SAVE :: kap=0.4,kapb=0.4
+ REAL zq
+ REAL sq(klon), sqz(klon)
+ REAL, ALLOCATABLE, SAVE :: l0(:)
+  !$OMP THREADPRIVATE(l0)
+ REAL fl, zzz, zl0, zq2, zn2
+ REAL famorti, zzzz, zh_oro, zhlim
+ REAL l1(klon, klev+1), l2(klon,klev+1)
+ REAL winds(klon, klev)
+ REAL xcell
+ REAL zstdslope(klon)  
+ REAL lmax
+ REAL l2strat, l2neutre, extent  
+ REAL l2limit(klon)
+!===============================================================
+! Fonctions utiles
+!===============================================================
+
+! Calcul de l suivant la formule de Blackadar 1962 adapt??e par Ayotte 1996
+!..........................................................................
+
+ fl(zzz, zl0, zq2, zn2) = max(min(l0(ig)*kap*zlev(ig, &
+    k)/(kap*zlev(ig,k)+l0(ig)),0.5*sqrt(q2(ig,k))/sqrt( &
+    max(n2(ig,k),1.E-10))), 1.E-5)
+ 
+! Fonction d'amortissement de la turbulence au dessus de la montagne
+! On augmente l'amortissement en diminuant la valeur de hlim (extent) dans le code
+!.....................................................................
+
+ famorti(zzzz, zh_oro, zhlim)=(-1.)*ATAN((zzzz-zh_oro)/(zhlim-zh_oro))*2./3.1416+1.    
+
+  IF (ngrid==0) RETURN
+
+  IF (firstcall) THEN
+    ALLOCATE (l0(klon))
+    firstcall = .FALSE.
+  END IF
+
+
+!=====================================================================
+!         CALCUL de la LONGUEUR de m??lange suivant BLACKADAR: l1
+!=====================================================================
+
+
+  IF (iflag_pbl==8 .OR. iflag_pbl==10) THEN
+
+    
+    ! Iterative computation of l0
+    ! This version is kept for iflag_pbl only for convergence
+    ! with NPv3.1 Cmip5 simulations
+    !...................................................................
+
+    DO ig = 1, ngrid
+      sq(ig) = 1.E-10
+      sqz(ig) = 1.E-10
+    END DO
+    DO k = 2, klev - 1
+      DO ig = 1, ngrid
+        zq = sqrt(q2(ig,k))
+        sqz(ig) = sqz(ig) + zq*zlev(ig, k)*(zlay(ig,k)-zlay(ig,k-1))
+        sq(ig) = sq(ig) + zq*(zlay(ig,k)-zlay(ig,k-1))
+      END DO
+    END DO
+    DO ig = 1, ngrid
+      l0(ig) = 0.2*sqz(ig)/sq(ig)
+    END DO
+    DO k = 2, klev
+      DO ig = 1, ngrid
+        l1(ig, k) = fl(zlev(ig,k), l0(ig), q2(ig,k), n2(ig,k))
+      END DO
+    END DO
+
+  ELSE
+
+    
+    ! In all other case, the assymptotic mixing length l0 is imposed (150m)
+    !......................................................................
+
+    l0(1:ngrid) = 150.
+    DO k = 2, klev
+      DO ig = 1, ngrid
+        l1(ig, k) = fl(zlev(ig,k), l0(ig), q2(ig,k), n2(ig,k))
+      END DO
+    END DO
+
+  END IF
+
+!=================================================================================
+!  CALCUL d'une longueur de melange en fonctions de la topographie sous maille: l2
+! si plb_lmixmin_alpha=TRUE et si on se trouve sur de la terre ( pas actif sur les 
+! glacier, la glace de mer et les oc??ans)
+!=================================================================================
+
+   l2(1:ngrid,:)=0.0
+   l_mixmin(1:ngrid,:,nsrf)=0.
+   l_mix(1:ngrid,:,nsrf)=0.
+
+   IF (nsrf .EQ. 1) THEN
+
+! coefficients 
+!--------------
+
+     extent=2.                                                         ! On ??tend l'impact du relief jusqu'?? extent*h, extent >1.  
+     lmax=150.                                                         ! Longueur de m??lange max dans l'absolu
+
+! calculs
+!---------
+
+     DO ig=1,ngrid
+
+      ! On calcule la hauteur du relief
+      !.................................
+      ! On ne peut pas prendre zstd seulement pour caracteriser le relief sous maille
+      ! car sur un terrain pentu mais sans relief, zstd est non nul (comme en Antarctique, C. Genthon)
+      ! On corrige donc zstd avec l'ecart type de l'altitude dans la maille sans relief 
+      ! (en gros, une maille de taille xcell avec une pente constante zstdslope)
+      jg=ni(ig) 
+!     IF (zsig(jg) .EQ. 0.) THEN
+!          zstdslope(ig)=0.         
+!     ELSE
+!     xcell=sqrt(cell_area(jg))
+!     zstdslope(ig)=max((xcell*zsig(jg)-zmea(jg))**3 /(3.*zsig(jg)),0.)
+!     zstdslope(ig)=sqrt(zstdslope(ig))
+!     END IF
+      
+!     h_oro(ig)=max(zstd(jg)-zstdslope(ig),0.)   ! Hauteur du relief
+      h_oro(ig)=zstd(jg)
+      hlim(ig)=extent*h_oro(ig)     
+     ENDDO
+
+     l2limit(1:ngrid)=0.
+
+     DO k=2,klev
+        DO ig=1,ngrid
+           winds(ig,k)=sqrt(u(ig,k)**2+v(ig,k)**2)
+           IF (zlev(ig,k) .LE. h_oro(ig)) THEN  ! sous l'orographie
+              l2strat= kapb*pbl_lmixmin_alpha*winds(ig,k)/sqrt(max(n2(ig,k),1.E-10))  ! si stratifi??, amplitude d'oscillation * kappab (voir Van de Wiel et al 2008)
+              l2neutre=kap*zlev(ig,k)*h_oro(ig)/(kap*zlev(ig,k)+h_oro(ig))            ! Dans le cas neutre, formule de blackadar. tend asymptotiquement vers h
+              l2neutre=MIN(l2neutre,lmax)                                             ! On majore par lmax 
+              l2limit(ig)=MIN(l2neutre,l2strat)                                       ! Calcule de l2 (minimum de la longueur en cas neutre et celle en situation stratifi??e)
+              l2(ig,k)=l2limit(ig)
+                                      
+           ELSE IF (zlev(ig,k) .LE. hlim(ig)) THEN ! Si on est au dessus des montagnes, mais affect?? encore par elles
+
+      ! Au dessus des montagnes, on prend la l2limit au sommet des montagnes 
+      ! (la derni??re calcul??e dans la boucle k, vu que k est un indice croissant avec z)
+      ! et on multiplie l2limit par une fonction qui d??croit entre h et hlim
+              l2(ig,k)=l2limit(ig)*famorti(zlev(ig,k),h_oro(ig), hlim(ig))
+           ELSE                                                                    ! Au dessus de extent*h, on prend l2=l0 
+              l2(ig,k)=0.
+           END IF
+        ENDDO
+     ENDDO
+   ENDIF                                                                        ! pbl_lmixmin_alpha
+
+!==================================================================================
+! On prend le max entre la longueur de melange de blackadar et celle calcul??e
+! en fonction de la topographie 
+!===================================================================================
+
+
+ DO k=2,klev
+    DO ig=1,ngrid
+       lmix(ig,k)=MAX(MAX(l1(ig,k), l2(ig,k)),lmixmin)
+   ENDDO
+ ENDDO
+
+! Diagnostics
+
+ DO k=2,klev
+    DO ig=1,ngrid
+       jg=ni(ig)
+       l_mix(jg,k,nsrf)=lmix(ig,k)
+       l_mixmin(jg,k,nsrf)=l2(ig,k)
+    ENDDO
+ ENDDO
+ DO ig=1,ngrid
+    jg=ni(ig)
+    l_mix(jg,1,nsrf)=hlim(ig)
+ ENDDO
+
+
+
+END SUBROUTINE mixinglength
