Index: LMDZ6/branches/LMDZ_ECRad/DefLists/README
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/README	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/README	(revision 4482)
@@ -11,2 +11,7 @@
 physiq.def_NPv5.70         IPSL-CM6.0.5
 physiq.def_NPv5.67         IPSL-CM6.0.5 / THC1 (test de sensibilité)
+physiq.def_NPv6.1          IPSL-CM6A
+physiq.def_NPv6.2          IPSL-CM6A for QUEST (without 2 CM6A bugs)
+physiq.def_NPv6.3          IPSL-CM6A + new flags added since CMIP6 end 2018
+physiq.def_NPv6.4          NPv6.3 without 2 CM6A bugs
+physiq.def_LUDOBest2       Ludovic' physic tuned by Frederic 
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/context_lmdz.xml
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/context_lmdz.xml	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/context_lmdz.xml	(revision 4482)
@@ -63,4 +63,5 @@
     <axis id="time_year" unit="day" />
     <axis id="presnivs" standard_name="Vertical levels" unit="Pa"/>
+    <axis id="presinter" standard_name="Pressure at interface of vertical levels" unit="Pa"/>
     <axis id="Ahyb" standard_name="Ahyb comp of Hyb Cord" unit="Pa"/>
     <axis id="Bhyb" standard_name="Bhyb comp of Hyb Cord" unit=""/>
@@ -75,4 +76,7 @@
     <axis id="axis_lat" standard_name="Latitude axis">
         <reduce_domain operation="average" direction="iDir" />
+    </axis>
+    <axis id="axis_lat_greordered" standard_name="Latitude axis">
+      <reduce_domain operation="average" direction="iDir" />
     </axis>
 
@@ -119,4 +123,13 @@
      </grid>
 
+     <grid id="grid_glo_presinter">
+        <domain domain_ref="dom_glo" />
+        <axis axis_ref="presinter" />
+     </grid>
+     <grid id="grid_out_presinter">
+        <domain domain_ref="dom_out" />
+        <axis axis_ref="presinter" />
+     </grid>
+
      <grid id="grid_out_plev17">
         <domain id="dom_out" />
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/field_def_lmdz.xml
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/field_def_lmdz.xml	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/field_def_lmdz.xml	(revision 4482)
@@ -576,6 +576,4 @@
         <field id="cldemi"    long_name="Cloud optical emissivity"    unit="1" />
         <field id="tke_max"    long_name="TKE max"    unit="m2/s2" operation="maximum"/>
-        <field id="kz"    long_name="Kz melange"    unit="m2/s" enabled="FALSE" />
-        <field id="kz_max"    long_name="Kz melange max"    unit="m2/s" enabled="FALSE" operation="maximum" />
         <field id="concso4"    long_name="Concentration of Sulfate "    unit="kg/m3" />
         <field id="concno3"    long_name="Concentration of Nitrate "    unit="kg/m3" /> 
@@ -585,6 +583,6 @@
         <field id="concdust"    long_name="Concentration of Dust "    unit="kg/m3" />
         <field id="ec550aer"    long_name="Extinction at 550nm"    unit="m^-1" />
-        <field id="lwcon"    long_name="Cloud liquid water content"    unit="kg/kg" />
-        <field id="iwcon"    long_name="Cloud ice water content"    unit="kg/kg" />
+        <field id="lwcon"    long_name="Cloud liquid water content seen by radiation"    unit="kg/kg" />
+        <field id="iwcon"    long_name="Cloud ice water content seen by radiation"    unit="kg/kg" />
         <field id="temp"    long_name="Air temperature"    unit="K" />
         <field id="theta"    long_name="Potential air temperature"    unit="K" />
@@ -659,5 +657,4 @@
         <field id="wdtrainS"    long_name="precipitation from shedding of AA"    unit="-" />
         <field id="wdtrainM"    long_name="precipitation from mixture"    unit="-" />
-        <field id="Vprecip"    long_name="precipitation vertical profile"    unit="-" />
         <field id="qtaa"    long_name="specific total water in adiabatic ascents"    unit="kg/kg" /> 
         <field id="Clwaa"   long_name="specific condensed water in adiabatic ascents"    unit="kg/kg" />
@@ -687,10 +684,7 @@
         <field id="duthe"    long_name="Thermal du"    unit="m/s2" />
         <field id="dvthe"    long_name="Thermal dv"    unit="m/s2" />
-        <field id="f_th"    long_name="Thermal plume mass flux"    unit="kg/(m2*s)" />
         <field id="e_th"    long_name="Thermal plume entrainment"    unit="K/s" />
-        <field id="w_th"    long_name="Thermal plume vertical velocity"    unit="m/s" />
         <field id="lambda_th"    long_name="Thermal plume vertical velocity"    unit="m/s" />
         <field id="q_th"    long_name="Thermal plume total humidity"    unit="kg/kg" />
-        <field id="a_th"    long_name="Thermal plume fraction"    unit="-" />
         <field id="s_th"    long_name="Thermal plume saturation deficit"    unit="kg/kg" />
         <field id="s_env"    long_name="Environment saturation deficit"    unit="kg/kg" />
@@ -723,14 +717,4 @@
         <field id="dtlif"    long_name="Orography dT"    unit="K/s" />
         <field id="dthin"    long_name="Hines GWD dT"    unit="K/s" />
-        <field id="rsu"    long_name="SW upward radiation"    unit="W m-2" />
-        <field id="rsd"    long_name="SW downward radiation"    unit="W m-2" />
-        <field id="rlu"    long_name="LW upward radiation"    unit="W m-2" />
-        <field id="rld"    long_name="LW downward radiation"    unit="W m-2" />
-        <field id="rsucsaf"  long_name="SW clean (no aerosol) CS upward radiation"    unit="W m-2" />
-        <field id="rsdcsaf"  long_name="SW clean (no aerosol) CS downward radiation"    unit="W m-2" />
-        <field id="rsucs"    long_name="SW CS upward radiation"    unit="W m-2" />
-        <field id="rsdcs"    long_name="SW CS downward radiation"    unit="W m-2" />
-        <field id="rlucs"    long_name="LW CS upward radiation"    unit="W m-2" />
-        <field id="rldcs"    long_name="LW CS downward radiation"    unit="W m-2" />
         <field id="tnt"    long_name="Tendency of air temperature"    unit="K s-1" />
         <field id="tntc"    long_name="Tendency of air temperature due to Moist Convection"    unit="K s-1" />
@@ -740,5 +724,4 @@
         <field id="tnhusc"    long_name="Tendency of specific humidity due to convection"    unit="s-1" />
         <field id="tnhusscpbl"    long_name="Tendency of Specific humidity due to ST cl, precip and BL mixing"    unit="s-1" />
-        <field id="evu"    long_name="Eddy viscosity coefficient for Momentum Variables"    unit="m2 s-1" />
         <field id="h2o"    long_name="Mass Fraction of Water"    unit="1" />
         <field id="mcd"    long_name="Downdraft COnvective Mass Flux"    unit="kg/(m2*s)" />
@@ -746,12 +729,4 @@
         <field id="ref_liq"    long_name="Effective radius of convective cloud liquid water particle"    unit="m" />
         <field id="ref_ice"    long_name="Effective radius of startiform cloud ice particle"    unit="m" />
-        <field id="rsu4co2"    long_name="Upwelling SW 4xCO2 atmosphere"    unit="W/m2" />
-        <field id="rlu4co2"    long_name="Upwelling LW 4xCO2 atmosphere"    unit="W/m2" />
-        <field id="rsucs4co2"    long_name="Upwelling CS SW 4xCO2 atmosphere"    unit="W/m2" />
-        <field id="rlucs4co2"    long_name="Upwelling CS LW 4xCO2 atmosphere"    unit="W/m2" />
-        <field id="rsd4co2"    long_name="Downwelling SW 4xCO2 atmosphere"    unit="W/m2" />
-        <field id="rld4co2"    long_name="Downwelling LW 4xCO2 atmosphere"    unit="W/m2" />
-        <field id="rsdcs4co2"    long_name="Downwelling CS SW 4xCO2 atmosphere"    unit="W/m2" />
-        <field id="rldcs4co2"    long_name="Downwelling CS LW 4xCO2 atmosphere"    unit="W/m2" />
         <field id="stratomask"    long_name="Stratospheric fraction"    unit="-" />
         <field id="heat_volc"    long_name="SW heating rate from volcano"    unit="K/s" />
@@ -783,4 +758,32 @@
     </field_group>
 
+    <field_group id="fields_3Dkp1" grid_ref="grid_glo_presinter" >
+        <field id="a_th"    long_name="Thermal plume fraction"    unit="-" />
+        <field id="f_th"    long_name="Thermal plume mass flux"    unit="kg/(m2*s)" />
+        <field id="w_th"    long_name="Thermal plume vertical velocity"    unit="m/s" />
+        <field id="rsucs"    long_name="SW CS upward radiation"    unit="W m-2" />
+        <field id="rsdcs"    long_name="SW CS downward radiation"    unit="W m-2" />
+        <field id="rlucs"    long_name="LW CS upward radiation"    unit="W m-2" />
+        <field id="rldcs4co2"    long_name="Downwelling CS LW 4xCO2 atmosphere"    unit="W/m2" />
+        <field id="rlucs4co2"    long_name="Upwelling CS LW 4xCO2 atmosphere"    unit="W/m2" />
+        <field id="rsdcs4co2"    long_name="Downwelling CS SW 4xCO2 atmosphere"    unit="W/m2" />
+        <field id="rsucs4co2"    long_name="Upwelling CS SW 4xCO2 atmosphere"    unit="W/m2" />
+        <field id="rld4co2"    long_name="Downwelling LW 4xCO2 atmosphere"    unit="W/m2" />
+        <field id="rsd4co2"    long_name="Downwelling SW 4xCO2 atmosphere"    unit="W/m2" />
+        <field id="rlu4co2"    long_name="Upwelling LW 4xCO2 atmosphere"    unit="W/m2" />
+        <field id="rsu4co2"    long_name="Upwelling SW 4xCO2 atmosphere"    unit="W/m2" />
+        <field id="rsdcsaf"  long_name="SW clean (no aerosol) CS downward radiation"    unit="W m-2" />
+        <field id="rsucsaf"  long_name="SW clean (no aerosol) CS upward radiation"    unit="W m-2" />
+        <field id="Vprecip"    long_name="precipitation vertical profile"    unit="-" />
+        <field id="kz_max"    long_name="Kz melange max"    unit="m2/s" enabled="FALSE" operation="maximum" />
+        <field id="rldcs"    long_name="LW CS downward radiation"    unit="W m-2" />
+        <field id="rsu"    long_name="SW upward radiation"    unit="W m-2" />
+        <field id="rsd"    long_name="SW downward radiation"    unit="W m-2" />
+        <field id="rlu"    long_name="LW upward radiation"    unit="W m-2" />
+        <field id="rld"    long_name="LW downward radiation"    unit="W m-2" />
+        <field id="kz"    long_name="Kz melange"    unit="m2/s" enabled="FALSE" />
+        <field id="evu"    long_name="Eddy viscosity coefficient for Momentum Variables"    unit="m2 s-1" />
+    </field_group>
+    
     <field_group id="fields_strataer_trac_3D" grid_ref="grid_glo_presnivs" operation="average"/>
     <field_group id="fields_strataer_trac_2D" grid_ref="grid_glo" operation="average"/>
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histLES_lmdz.xml
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histLES_lmdz.xml	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histLES_lmdz.xml	(revision 4482)
@@ -454,6 +454,4 @@
                 <field field_ref="cldemi" level="10" />
                 <field field_ref="tke_max" level="10" operation="maximum" />
-                <field field_ref="kz" level="10" />
-                <field field_ref="kz_max" level="10" operation="maximum" />
                 <field field_ref="concso4" level="10" />
                 <field field_ref="concoa" level="10" />
@@ -533,5 +531,4 @@
                 <field field_ref="wdtrainA" level="1" />
                 <field field_ref="wdtrainM" level="1" />
-                <field field_ref="Vprecip" level="10" />
                 <field field_ref="ftd" level="10" />
                 <field field_ref="fqd" level="10" />
@@ -557,10 +554,7 @@
                 <field field_ref="ratqs" level="10" />
                 <field field_ref="dtthe" level="10" />
-                <field field_ref="f_th" level="10" />
                 <field field_ref="e_th" level="10" />
-                <field field_ref="w_th" level="10" />
                 <field field_ref="lambda_th" level="10" />
                 <field field_ref="q_th" level="10" />
-                <field field_ref="a_th" level="10" />
                 <field field_ref="s_th" level="10" />
                 <field field_ref="s_env" level="10" />
@@ -591,12 +585,4 @@
                 <field field_ref="dtlif" level="10" />
                 <field field_ref="dthin" level="10" />
-                <field field_ref="rsu" level="10" />
-                <field field_ref="rsd" level="10" />
-                <field field_ref="rlu" level="10" />
-                <field field_ref="rld" level="10" />
-                <field field_ref="rsucs" level="10" />
-                <field field_ref="rsdcs" level="10" />
-                <field field_ref="rlucs" level="10" />
-                <field field_ref="rldcs" level="10" />
                 <field field_ref="tnt" level="10" />
                 <field field_ref="tntc" level="10" />
@@ -606,5 +592,4 @@
                 <field field_ref="tnhusc" level="10" />
                 <field field_ref="tnhusscpbl" level="10" />
-                <field field_ref="evu" level="10" />
                 <field field_ref="h2o" level="10" />
                 <field field_ref="mcd" level="10" />
@@ -612,12 +597,29 @@
                 <field field_ref="ref_liq" level="10" />
                 <field field_ref="ref_ice" level="10" />
+            </field_group>
+            <field_group operation="average" grid_ref="grid_out_presinter">
+                <field field_ref="a_th" level="9" />
+                <field field_ref="f_th" level="7" />
+                <field field_ref="w_th" level="7" />
+                <field field_ref="rsucs" level="10" />
+                <field field_ref="rsdcs" level="10" />
+                <field field_ref="rlucs" level="10" />
+                <field field_ref="rldcs" level="10" />
+                <field field_ref="rldcs4co2" level="10" />
+                <field field_ref="rlucs4co2" level="10" />
+                <field field_ref="rsdcs4co2" level="10" />
+                <field field_ref="rsucs4co2" level="10" />
                 <field field_ref="rsu4co2" level="10" />
                 <field field_ref="rlu4co2" level="10" />
-                <field field_ref="rsucs4co2" level="10" />
-                <field field_ref="rlucs4co2" level="10" />
                 <field field_ref="rsd4co2" level="10" />
                 <field field_ref="rld4co2" level="10" />
-                <field field_ref="rsdcs4co2" level="10" />
-                <field field_ref="rldcs4co2" level="10" />
+                <field field_ref="Vprecip" level="11" />
+                <field field_ref="rsu" level="5" />
+                <field field_ref="rsd" level="5" />
+                <field field_ref="rlu" level="5" />
+                <field field_ref="rld" level="5" />
+                <field field_ref="kz" level="4" />
+                <field field_ref="kz_max" level="4" operation="maximum" />
+                <field field_ref="evu" level="10" />
             </field_group>
           </field_group>
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histday_lmdz.xml
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histday_lmdz.xml	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histday_lmdz.xml	(revision 4482)
@@ -196,5 +196,5 @@
                 <field field_ref="cdrh" level="10" />
                 <field field_ref="cldl" level="1" />
-                <field field_ref="cumCO2" level="5" />
+                <field field_ref="cumCO2" level="5" />  <!-- Added PC -->
                 <field field_ref="cldm" level="1" />
                 <field field_ref="cldh" level="1" />
@@ -245,4 +245,11 @@
                 <field field_ref="colO3_strat" level="6" />     <!-- Added ThL -->
                 <field field_ref="colO3_trop"  level="6" />     <!-- Added ThL -->
+                <field field_ref="flx_co2_ocean"  level="5" /> <!-- Added PC -->
+                <field field_ref="flx_co2_land"   level="5" /> <!-- Added PC -->
+                <field field_ref="flx_co2_ocean_cor" level="5" /> <!-- Added PC -->
+                <field field_ref="flx_co2_land_cor"  level="5" /> <!-- Added PC -->
+                <field field_ref="flx_co2_ff"  level="5" /> <!-- Added PC -->
+                <field field_ref="flx_co2_bb"  level="5" /> <!-- Added PC -->
+
 
                 <field_group operation="average" detect_missing_value=".true.">
@@ -444,5 +451,5 @@
             <!-- VARS 3D -->
             <field_group operation="average" grid_ref="grid_out_presnivs">
-                <field field_ref="CO2" level="5" />
+                <field field_ref="CO2" level="5" /> <!-- Added PC -->
                 <field field_ref="dCO2_vdf" level="5" />
                 <field field_ref="dCO2_the" level="5" />
@@ -451,6 +458,4 @@
                 <field field_ref="cldemi" level="5" />
                 <field field_ref="tke_max" level="10" operation="maximum" />
-                <field field_ref="kz" level="10" />
-                <field field_ref="kz_max" level="10" operation="maximum" />
                 <field field_ref="concso4" level="6" />
                 <field field_ref="concoa" level="6" />
@@ -529,5 +534,4 @@
                 <field field_ref="wdtrainA" level="1" />
                 <field field_ref="wdtrainM" level="1" />
-                <field field_ref="Vprecip" level="10" />
                 <field field_ref="ftd" level="5" />
                 <field field_ref="fqd" level="5" />
@@ -553,10 +557,7 @@
                 <field field_ref="ratqs" level="10" />
                 <field field_ref="dtthe" level="10" />
-                <field field_ref="f_th" level="10" />
                 <field field_ref="e_th" level="10" />
-                <field field_ref="w_th" level="10" />
                 <field field_ref="lambda_th" level="10" />
                 <field field_ref="q_th" level="10" />
-                <field field_ref="a_th" level="10" />
                 <field field_ref="s_th" level="10" />
                 <field field_ref="s_env" level="10" />
@@ -587,12 +588,4 @@
                 <field field_ref="dtlif" level="10" />
                 <field field_ref="dthin" level="10" />
-                <field field_ref="rsu" level="10" />
-                <field field_ref="rsd" level="10" />
-                <field field_ref="rlu" level="10" />
-                <field field_ref="rld" level="10" />
-                <field field_ref="rsucs" level="10" />
-                <field field_ref="rsdcs" level="10" />
-                <field field_ref="rlucs" level="10" />
-                <field field_ref="rldcs" level="10" />
                 <field field_ref="tnt" level="10" />
                 <field field_ref="tntc" level="10" />
@@ -602,5 +595,4 @@
                 <field field_ref="tnhusc" level="10" />
                 <field field_ref="tnhusscpbl" level="10" />
-                <field field_ref="evu" level="10" />
                 <field field_ref="h2o" level="10" />
                 <field field_ref="mcd" level="10" />
@@ -608,12 +600,4 @@
                 <field field_ref="ref_liq" level="10" />
                 <field field_ref="ref_ice" level="10" />
-                <field field_ref="rsu4co2" level="10" />
-                <field field_ref="rlu4co2" level="10" />
-                <field field_ref="rsucs4co2" level="10" />
-                <field field_ref="rlucs4co2" level="10" />
-                <field field_ref="rsd4co2" level="10" />
-                <field field_ref="rld4co2" level="10" />
-                <field field_ref="rsdcs4co2" level="10" />
-                <field field_ref="rldcs4co2" level="10" />
                 <field field_ref="treedrg_ter" level="6" />
                 <field field_ref="treedrg_lic" level="6" />
@@ -638,27 +622,29 @@
                 <field field_ref="l_mixmin_sic" level="10" />
                 <field field_ref="ozone_daylight" level="10" />
-                <field field_ref="oclr" level="10" />
-                <field field_ref="ocld" level="10" />
-                <field field_ref="oss" level="10" />
-                <field field_ref="ovc" level="10" />
-                <field field_ref="rnebclr" level="10" />
-                <field field_ref="rnebss" level="10" />
-                <field field_ref="rnebseri" level="10" />
-                <field field_ref="gammass" level="10" />
-                <field field_ref="N1ss" level="10" />
-                <field field_ref="N2ss" level="10" />
-                <field field_ref="drnebsub" level="10" />
-                <field field_ref="drnebcon" level="10" />
-                <field field_ref="drnebtur" level="10" />
-                <field field_ref="drnebavi" level="10" />
-                <field field_ref="qsatl" level="10" />
-                <field field_ref="qsats" level="10" />
-                <field field_ref="flightm" level="10" />
-                <field field_ref="flighth2o" level="10" />
-                <field field_ref="fcontrP" level="10" />
-                <field field_ref="fcontrN" level="10" />
-                <field field_ref="qcontr" level="10" />
-                <field field_ref="qcontr2" level="10" />
-                <field field_ref="Tcontr" level="10" />
+            </field_group>
+            <field_group operation="average" grid_ref="grid_out_presinter">
+                <field field_ref="a_th" level="9" />
+                <field field_ref="f_th" level="7" />
+                <field field_ref="w_th" level="7" />
+                <field field_ref="rsucs" level="10" />
+                <field field_ref="rsdcs" level="10" />
+                <field field_ref="rlucs" level="10" />
+                <field field_ref="rldcs" level="10" />
+                <field field_ref="rldcs4co2" level="10" />
+                <field field_ref="rlucs4co2" level="10" />
+                <field field_ref="rsdcs4co2" level="10" />
+                <field field_ref="rsucs4co2" level="10" />
+                <field field_ref="rsu4co2" level="10" />
+                <field field_ref="rlu4co2" level="10" />
+                <field field_ref="rsd4co2" level="10" />
+                <field field_ref="rld4co2" level="10" />
+                <field field_ref="Vprecip" level="11" />
+                <field field_ref="rsu" level="5" />
+                <field field_ref="rsd" level="5" />
+                <field field_ref="rlu" level="5" />
+                <field field_ref="rld" level="5" />
+                <field field_ref="kz" level="4" />
+                <field field_ref="kz_max" level="4" operation="maximum" />
+                <field field_ref="evu" level="10" />
             </field_group>
             
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histhf_lmdz.xml
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histhf_lmdz.xml	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histhf_lmdz.xml	(revision 4482)
@@ -430,4 +430,11 @@
                 <field field_ref="dqthe2d" level="10" />
                 <field field_ref="dqajs2d" level="10" />
+                <field field_ref="flx_co2_ocean"  level="10" /> <!-- Added PC -->
+                <field field_ref="flx_co2_land"   level="10" /> <!-- Added PC -->
+                <field field_ref="flx_co2_ocean_cor" level="10" /> <!-- Added PC -->
+                <field field_ref="flx_co2_land_cor"  level="10" /> <!-- Added PC -->
+                <field field_ref="flx_co2_ff"  level="10" /> <!-- Added PC -->
+                <field field_ref="flx_co2_bb"  level="10" /> <!-- Added PC -->
+
             </field_group>
 
@@ -464,4 +471,5 @@
             <!-- VARS 3D -->
             <field_group operation="average" grid_ref="grid_out_presnivs">
+                <field field_ref="CO2" level="10" /> <!-- Added PC -->
                 <field field_ref="tke" level="10" />
                 <field field_ref="tke_ter" level="10" />
@@ -488,6 +496,4 @@
                 <field field_ref="cldemi" level="10" />
                 <field field_ref="tke_max" level="10" operation="maximum" />
-                <field field_ref="kz" level="10" />
-                <field field_ref="kz_max" level="10" operation="maximum" />
                 <field field_ref="concso4" level="10" />
                 <field field_ref="concoa" level="10" />
@@ -566,5 +572,4 @@
                 <field field_ref="wdtrainA" level="10" />
                 <field field_ref="wdtrainM" level="10" />
-                <field field_ref="Vprecip" level="10" />
                 <field field_ref="ftd" level="10" />
                 <field field_ref="fqd" level="10" />
@@ -590,10 +595,7 @@
                 <field field_ref="ratqs" level="10" />
                 <field field_ref="dtthe" level="10" />
-                <field field_ref="f_th" level="10" />
                 <field field_ref="e_th" level="10" />
-                <field field_ref="w_th" level="10" />
                 <field field_ref="lambda_th" level="10" />
                 <field field_ref="q_th" level="10" />
-                <field field_ref="a_th" level="10" />
                 <field field_ref="s_th" level="10" />
                 <field field_ref="s_env" level="10" />
@@ -624,12 +626,4 @@
                 <field field_ref="dtlif" level="10" />
                 <field field_ref="dthin" level="10" />
-                <field field_ref="rsu" level="10" />
-                <field field_ref="rsd" level="10" />
-                <field field_ref="rlu" level="10" />
-                <field field_ref="rld" level="10" />
-                <field field_ref="rsucs" level="10" />
-                <field field_ref="rsdcs" level="10" />
-                <field field_ref="rlucs" level="10" />
-                <field field_ref="rldcs" level="10" />
                 <field field_ref="tnt" level="10" />
                 <field field_ref="tntc" level="10" />
@@ -639,5 +633,4 @@
                 <field field_ref="tnhusc" level="10" />
                 <field field_ref="tnhusscpbl" level="10" />
-                <field field_ref="evu" level="10" />
                 <field field_ref="h2o" level="10" />
                 <field field_ref="mcd" level="10" />
@@ -645,33 +638,29 @@
                 <field field_ref="ref_liq" level="10" />
                 <field field_ref="ref_ice" level="10" />
+              </field_group>
+              <field_group operation="average" grid_ref="grid_out_presinter">
+                <field field_ref="a_th" level="9" />
+                <field field_ref="f_th" level="7" />
+                <field field_ref="w_th" level="7" />
+                <field field_ref="rsucs" level="10" />
+                <field field_ref="rsdcs" level="10" />
+                <field field_ref="rlucs" level="10" />
+                <field field_ref="rldcs" level="10" />
+                <field field_ref="rldcs4co2" level="10" />
+                <field field_ref="rlucs4co2" level="10" />
+                <field field_ref="rsdcs4co2" level="10" />
+                <field field_ref="rsucs4co2" level="10" />
                 <field field_ref="rsu4co2" level="10" />
                 <field field_ref="rlu4co2" level="10" />
-                <field field_ref="rsucs4co2" level="10" />
-                <field field_ref="rlucs4co2" level="10" />
                 <field field_ref="rsd4co2" level="10" />
                 <field field_ref="rld4co2" level="10" />
-                <field field_ref="rsdcs4co2" level="10" />
-                <field field_ref="rldcs4co2" level="10" />
-                <field field_ref="oclr" level="10" />
-                <field field_ref="ocld" level="10" />
-                <field field_ref="oss" level="10" />
-                <field field_ref="ovc" level="10" />
-                <field field_ref="rnebclr" level="10" />
-                <field field_ref="rnebss" level="10" operation="instant" />
-                <field field_ref="rnebseri" level="10" />
-                <field field_ref="gammass" level="10" />
-                <field field_ref="N1ss" level="10" />
-                <field field_ref="N2ss" level="10" />
-                <field field_ref="drnebsub" level="10" />
-                <field field_ref="drnebcon" level="10" />
-                <field field_ref="drnebtur" level="10" />
-                <field field_ref="drnebavi" level="10" />
-                <field field_ref="qsatl" level="10" />
-                <field field_ref="qsats" level="10" />
-                <field field_ref="fcontrP" level="10" />
-                <field field_ref="fcontrN" level="10" />
-                <field field_ref="qcontr" level="10" operation="instant" />
-                <field field_ref="qcontr2" level="10" operation="instant" />
-                <field field_ref="Tcontr" level="10" operation="instant" />
+                <field field_ref="Vprecip" level="11" />
+                <field field_ref="rsu" level="5" />
+                <field field_ref="rsd" level="5" />
+                <field field_ref="rlu" level="5" />
+                <field field_ref="rld" level="5" />
+                <field field_ref="kz" level="4" />
+                <field field_ref="kz_max" level="4" operation="maximum" />
+                <field field_ref="evu" level="10" />
               </field_group>
 
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histins_lmdz.xml
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histins_lmdz.xml	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histins_lmdz.xml	(revision 4482)
@@ -460,6 +460,4 @@
                 <field field_ref="cldemi" level="10" />
                 <field field_ref="tke_max" level="10" operation="maximum" />
-                <field field_ref="kz" level="10" />
-                <field field_ref="kz_max" level="10" operation="maximum" />
                 <field field_ref="concso4" level="10" />
                 <field field_ref="concoa" level="10" />
@@ -538,5 +536,4 @@
                 <field field_ref="wdtrainA" level="4" />
                 <field field_ref="wdtrainM" level="4" />
-                <field field_ref="Vprecip" level="10" />
                 <field field_ref="ftd" level="10" />
                 <field field_ref="fqd" level="10" />
@@ -562,10 +559,7 @@
                 <field field_ref="ratqs" level="10" />
                 <field field_ref="dtthe" level="10" />
-                <field field_ref="f_th" level="10" />
                 <field field_ref="e_th" level="10" />
-                <field field_ref="w_th" level="10" />
                 <field field_ref="lambda_th" level="10" />
                 <field field_ref="q_th" level="10" />
-                <field field_ref="a_th" level="10" />
                 <field field_ref="s_th" level="10" />
                 <field field_ref="s_env" level="10" />
@@ -596,12 +590,4 @@
                 <field field_ref="dtlif" level="10" />
                 <field field_ref="dthin" level="10" />
-                <field field_ref="rsu" level="10" />
-                <field field_ref="rsd" level="10" />
-                <field field_ref="rlu" level="10" />
-                <field field_ref="rld" level="10" />
-                <field field_ref="rsucs" level="10" />
-                <field field_ref="rsdcs" level="10" />
-                <field field_ref="rlucs" level="10" />
-                <field field_ref="rldcs" level="10" />
                 <field field_ref="tnt" level="10" />
                 <field field_ref="tntc" level="10" />
@@ -611,5 +597,4 @@
                 <field field_ref="tnhusc" level="10" />
                 <field field_ref="tnhusscpbl" level="10" />
-                <field field_ref="evu" level="10" />
                 <field field_ref="h2o" level="10" />
                 <field field_ref="mcd" level="10" />
@@ -617,13 +602,29 @@
                 <field field_ref="ref_liq" level="10" />
                 <field field_ref="ref_ice" level="10" />
+            </field_group>
+            <field_group operation="instant" freq_op="1ts" grid_ref="grid_out_presinter">
+                <field field_ref="a_th" level="9" />
+                <field field_ref="f_th" level="7" />
+                <field field_ref="w_th" level="7" />
+                <field field_ref="rsucs" level="10" />
+                <field field_ref="rsdcs" level="10" />
+                <field field_ref="rlucs" level="10" />
+                <field field_ref="rldcs" level="10" />
+                <field field_ref="rldcs4co2" level="10" />
+                <field field_ref="rlucs4co2" level="10" />
+                <field field_ref="rsdcs4co2" level="10" />
+                <field field_ref="rsucs4co2" level="10" />
                 <field field_ref="rsu4co2" level="10" />
                 <field field_ref="rlu4co2" level="10" />
-                <field field_ref="rsucs4co2" level="10" />
-                <field field_ref="rlucs4co2" level="10" />
                 <field field_ref="rsd4co2" level="10" />
                 <field field_ref="rld4co2" level="10" />
-                <field field_ref="rsdcs4co2" level="10" />
-                <field field_ref="rldcs4co2" level="10" />
-                <field field_ref="ozone_daylight" level="10" />
+                <field field_ref="Vprecip" level="11" />
+                <field field_ref="rsu" level="5" />
+                <field field_ref="rsd" level="5" />
+                <field field_ref="rlu" level="5" />
+                <field field_ref="rld" level="5" />
+                <field field_ref="kz" level="4" />
+                <field field_ref="kz_max" level="4" operation="maximum" />
+                <field field_ref="evu" level="10" />
             </field_group>
           </field_group>
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histmth_lmdz.xml
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histmth_lmdz.xml	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histmth_lmdz.xml	(revision 4482)
@@ -234,4 +234,5 @@
                 <field field_ref="cldt" level="1" />
                 <field field_ref="cldq" level="1" />
+                <field field_ref="cumCO2" level="5" />  <!-- Added PC -->
                 <field field_ref="lwp" level="1" />
                 <field field_ref="iwp" level="1" />
@@ -498,4 +499,8 @@
             <!-- VARS 3D -->
             <field_group operation="average" grid_ref="grid_out_presnivs">
+                <field field_ref="CO2" level="5" />  <!-- Added PC -->
+                <field field_ref="dCO2_vdf" level="5" />  <!-- Added PC -->
+                <field field_ref="dCO2_the" level="5" />  <!-- Added PC -->
+                <field field_ref="dCO2_con" level="5" />  <!-- Added PC -->
                 <field field_ref="tke" level="7" />
                 <field field_ref="tke_ter" level="10" />
@@ -524,6 +529,4 @@
                 <field field_ref="cldemi" level="10" />
                 <field field_ref="tke_max" level="4" operation="maximum" />
-                <field field_ref="kz" level="4" />
-                <field field_ref="kz_max" level="4" operation="maximum" />
                 <field field_ref="concso4" level="2" />
                 <field field_ref="concoa" level="2" />
@@ -603,5 +606,4 @@
                 <field field_ref="wdtrainA" level="9" />
                 <field field_ref="wdtrainM" level="9" />
-                <field field_ref="Vprecip" level="11" />
                 <field field_ref="ftd" level="7" />
                 <field field_ref="fqd" level="7" />
@@ -627,10 +629,7 @@
                 <field field_ref="ratqs" level="7" />
                 <field field_ref="dtthe" level="7" />
-                <field field_ref="f_th" level="7" />
                 <field field_ref="e_th" level="9" />
-                <field field_ref="w_th" level="7" />
                 <field field_ref="lambda_th" level="10" />
                 <field field_ref="q_th" level="9" />
-                <field field_ref="a_th" level="9" />
                 <field field_ref="s_th" level="9" />
                 <field field_ref="s_env" level="9" />
@@ -661,12 +660,4 @@
                 <field field_ref="dtlif" level="7" />
                 <field field_ref="dthin" level="7" />
-                <field field_ref="rsu" level="5" />
-                <field field_ref="rsd" level="10" />
-                <field field_ref="rlu" level="10" />
-                <field field_ref="rld" level="10" />
-                <field field_ref="rsucs" level="10" />
-                <field field_ref="rsdcs" level="10" />
-                <field field_ref="rlucs" level="10" />
-                <field field_ref="rldcs" level="10" />
                 <field field_ref="tnt"  level="10" />
                 <field field_ref="tntc" level="10" />
@@ -676,5 +667,4 @@
                 <field field_ref="tnhusc"   level="10" />
                 <field field_ref="tnhusscpbl" level="10" />
-                <field field_ref="evu" level="10" />
                 <field field_ref="h2o" level="10" />
                 <field field_ref="mcd" level="10" />
@@ -682,15 +672,33 @@
                 <field field_ref="ref_liq" level="5" />
                 <field field_ref="ref_ice" level="10" />
-                <field field_ref="rsu4co2" level="10" />
-                <field field_ref="rlu4co2" level="10" />
-                <field field_ref="rsucs4co2" level="10" />
-                <field field_ref="rlucs4co2" level="10" />
-                <field field_ref="rsd4co2" level="10" />
-                <field field_ref="rld4co2" level="10" />
-                <field field_ref="rsdcs4co2" level="10" />
-                <field field_ref="rldcs4co2" level="10" />
                 <field field_ref="stratomask" level="1" />
                 <field field_ref="cool_volc" level="1" />
                 <field field_ref="heat_volc" level="1" />
+            </field_group>
+
+            <field_group operation="average" grid_ref="grid_out_presinter">
+                <field field_ref="a_th" level="9" />
+                <field field_ref="f_th" level="7" />
+                <field field_ref="w_th" level="7" />
+                <field field_ref="rsucs" level="10" />
+                <field field_ref="rsdcs" level="10" />
+                <field field_ref="rlucs" level="10" />
+                <field field_ref="rldcs" level="10" />
+                <field field_ref="rldcs4co2" level="10" />
+                <field field_ref="rlucs4co2" level="10" />
+                <field field_ref="rsdcs4co2" level="10" />
+                <field field_ref="rsucs4co2" level="10" />
+                <field field_ref="rsu4co2" level="10" />
+                <field field_ref="rlu4co2" level="10" />
+                <field field_ref="rsd4co2" level="10" />
+                <field field_ref="rld4co2" level="10" />
+                <field field_ref="Vprecip" level="11" />
+                <field field_ref="rsu" level="5" />
+                <field field_ref="rsd" level="5" />
+                <field field_ref="rlu" level="5" />
+                <field field_ref="rld" level="5" />
+                <field field_ref="kz" level="4" />
+                <field field_ref="kz_max" level="4" operation="maximum" />
+                <field field_ref="evu" level="10" />
             </field_group>
 
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histstn_lmdz.xml
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histstn_lmdz.xml	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/file_def_histstn_lmdz.xml	(revision 4482)
@@ -454,6 +454,4 @@
                 <field field_ref="cldemi" level="10" />
                 <field field_ref="tke_max" level="10" operation="maximum" />
-                <field field_ref="kz" level="10" />
-                <field field_ref="kz_max" level="10" operation="maximum" />
                 <field field_ref="concso4" level="10" />
                 <field field_ref="concoa" level="10" />
@@ -533,5 +531,4 @@
                 <field field_ref="wdtrainA" level="10" />
                 <field field_ref="wdtrainM" level="10" />
-                <field field_ref="Vprecip" level="10" />
                 <field field_ref="ftd" level="10" />
                 <field field_ref="fqd" level="10" />
@@ -557,10 +554,7 @@
                 <field field_ref="ratqs" level="10" />
                 <field field_ref="dtthe" level="10" />
-                <field field_ref="f_th" level="10" />
                 <field field_ref="e_th" level="10" />
-                <field field_ref="w_th" level="10" />
                 <field field_ref="lambda_th" level="10" />
                 <field field_ref="q_th" level="10" />
-                <field field_ref="a_th" level="10" />
                 <field field_ref="s_th" level="10" />
                 <field field_ref="s_env" level="10" />
@@ -591,12 +585,4 @@
                 <field field_ref="dtlif" level="10" />
                 <field field_ref="dthin" level="10" />
-                <field field_ref="rsu" level="10" />
-                <field field_ref="rsd" level="10" />
-                <field field_ref="rlu" level="10" />
-                <field field_ref="rld" level="10" />
-                <field field_ref="rsucs" level="10" />
-                <field field_ref="rsdcs" level="10" />
-                <field field_ref="rlucs" level="10" />
-                <field field_ref="rldcs" level="10" />
                 <field field_ref="tnt" level="10" />
                 <field field_ref="tntc" level="10" />
@@ -606,5 +592,4 @@
                 <field field_ref="tnhusc" level="10" />
                 <field field_ref="tnhusscpbl" level="10" />
-                <field field_ref="evu" level="10" />
                 <field field_ref="h2o" level="10" />
                 <field field_ref="mcd" level="10" />
@@ -612,13 +597,30 @@
                 <field field_ref="ref_liq" level="10" />
                 <field field_ref="ref_ice" level="10" />
+            </field_group>
+            <field_group operation="average" grid_ref="grid_out_presinter">
+                <field field_ref="a_th" level="9" />
+                <field field_ref="f_th" level="7" />
+                <field field_ref="w_th" level="7" />
+                <field field_ref="rsucs" level="10" />
+                <field field_ref="rsdcs" level="10" />
+                <field field_ref="rlucs" level="10" />
+                <field field_ref="rldcs" level="10" />
+                <field field_ref="rldcs4co2" level="10" />
+                <field field_ref="rlucs4co2" level="10" />
+                <field field_ref="rsdcs4co2" level="10" />
+                <field field_ref="rsucs4co2" level="10" />
                 <field field_ref="rsu4co2" level="10" />
                 <field field_ref="rlu4co2" level="10" />
-                <field field_ref="rsucs4co2" level="10" />
-                <field field_ref="rlucs4co2" level="10" />
                 <field field_ref="rsd4co2" level="10" />
                 <field field_ref="rld4co2" level="10" />
-                <field field_ref="rsdcs4co2" level="10" />
-                <field field_ref="rldcs4co2" level="10" />
-            </field_group>
+                <field field_ref="Vprecip" level="11" />
+                <field field_ref="rsu" level="5" />
+                <field field_ref="rsd" level="5" />
+                <field field_ref="rlu" level="5" />
+                <field field_ref="rld" level="5" />
+                <field field_ref="kz" level="4" />
+                <field field_ref="kz_max" level="4" operation="maximum" />
+                <field field_ref="evu" level="10" />
+             </field_group>
           </field_group>
           
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/iso.def
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/iso.def	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/iso.def	(revision 4482)
@@ -0,0 +1,155 @@
+# paramètres isotopiques principaux
+
+# verif isotopes dans la dynamique?
+ok_iso_verif=y
+
+# lambda: supersaturation: valeurs typiques: 0.002. Range possible: 0 (pas de sursat) à 0.004 (forte sursat)
+lambda=0.002
+
+# thumxt1: gère le fractionnement cinétique lors de la réévaporation des gouttes. Valeur typique: 0.9. Range possible: 0 (rh au contact des gouttes = rh autour des gouttes, fort fractionnement cinétique) à 1 (rh=1 au contact des gouttes, pas de fractionnement cinétique)
+thumxt1=0.9
+
+# h_land_ice: hauteur caractéristique de la glace de terre: la glace de terre à t+1 est égale à h_land_ice de glace de terre à t + la precip neigeuse en t.
+#Valeur typique: 20m. Range possible: proche de 0 (-> la glace de terre prend la composition de la dernière précip neigeuse) à très grand (-> la compo de la glace de terre est constante)
+h_land_ice=20.
+
+# P_veg: fraction de l evaporation continentale provenant de la transpiration sans fractionnement de la végétation, au lieu de l évaporation avec fractionnement de sol nu ou d eau libre. Valeur standard: 1 (comme autres GCMs). Range possible: 0 à 1.
+P_veg=1.0
+
+# bidouille_anti_divergence: si T: on rappel régulièrement l isotope H2O16 vers l eau normale. Si F: pas de rappel. En général, on met T pour être sur, mais on a verifie que ça a peut d importance
+bidouille_anti_divergence=y
+
+# essai_convergence: si T, on fait tout exactement comme pour l eau normale, pour que les 2 versions convergent. Si F, on modifie un peu: ex: initialisations supplémentaires de variables, on zappe l homogénéisation sous le nuage dans cv3_yield...
+essai_convergence=n
+
+# initialisation_iso: la façon dont les isos sont initialisés.
+#   - Lors du lancement de gcm:
+#	Pour la physique:
+#	0: lecture d un fichier, souvent de start (phyiso_etat0_fichier.F)
+#	>0: initialisation des isotopes académique, donnée dans phyiso_etat0_dur.F
+#	Pour la dynamique:
+#	0: lecture d un fichier (dyniso_etat0_fichier.F)
+#	>0: initialisation académique:
+#		1: isos à 0 sauf H2016=eau normale
+#		2: distill de Rayleigh
+#		3: tout est uniforme au SMOW
+#	En général, on met initialisation_iso=0
+#   - Lors du lancement de create_etat0_limit:
+#	Pour la physique: initialisation en dure, toujours
+#	Pour la dynamique: initialisation académique toujours:
+#		1: isos à 0 sauf H2016=eau normale
+#		2 ou 0: distill de Rayleigh
+#		3: tout est uniforme au SMOW
+#	En général, on laisse à initialisation_iso=0
+initialisation_iso=2
+
+# initialisation_isotrac: comment initialiser les traceurs d'eau?
+# 1: idéalisé: on met toute l'eau dans le tag izone_init, 0 ailleurs
+# 0: en lisant dans un fichier. Possible seulement si initialisation_iso=0
+initialisation_isotrac=1
+
+# modif_sst: 0 par defaut, 1 si on veut modifier la sst de manière uniforme
+# si 2, on impose un profil de changement de SST, avec 0 entre sstlatcrit et - sstlatcrit en latitude. Ailleurs: +deltaTtestpoles (rlat(ii)**2-sstlatcrit**2) /(90.0**2-sstlatcrit**2)
+# si 2, on impose changement de SST linéaire par morceau: 0 entre sstlatcrit et - sstlatcrit, deltaTtestpoles poleward of sstlatcrit+dsstlatcrit, et linéaire entre les 2.
+modif_sst=0
+
+# deltaTtest: sensibilité à une variation uniforme de la SST. Utilise seulement si modif_sst=1
+deltaTtest=0.0
+
+deltaTtestpoles=-15.0
+sstlatcrit=30.0
+dsstlatcrit=20.0
+
+# deltaO18_oce: deltaO18 de l'océan: ex: +1.1 au LGM, 0 actuellement. On suppose que le dexcess et O17excess océan sont nuls.
+deltaO18_oce=0.0
+
+# deltaP_BL:  epaisseur de la couche limite avec laquelle l'eau du sol tend à se rééquilibrer. Par défaut: 10mb (optim dans ORCHIDEE_LMDZ)
+deltaP_BL=10.0 
+
+# ruissellement_pluie: qu'est-ce qui ruisselle? si 1: c'est la pluie qui ruisselle. elle ne s'infiltre. elle ne s'infiltre donc jamais dans un sol saturé. si 0: c'est le sol qui ruisselle. La pluie s'inglitre donc dans le sol saturé.
+ruissellement_pluie=1
+
+# alphak_stewart: si 1: alphak=(D/Diso)^nsol. si 0: alphak=1/(1-kcin(vsurf))
+alphak_stewart=1
+
+# tdifexp_sol: tdifexp_sol est l'exposant de D/Diso. Il paramétrise la turbulence. D'abitude, il est de 0.58. Mais d'après Mathieu et Bariac, il est entre 0.67 et 1: 0.67 pour les sols secs et 1 pour les sols saturés.
+tdifexp_sol=0.67
+
+# calendrier_guide: si 1, on fait en sorte que l'année puisse avoir 365 ou 366 jours. Si 0, l'année à 360 jours (c'est LMDZ par défaut).
+# mettre 1 quand on guide, 0 sinon.
+calendrier_guide=0
+
+# cste_surf_cond: si 2, la témprature et la rh de surface sont constantes: rhs=0.7 et Ts=15°=288K. si 1: la rh de surface est conste égale à 0.7. Par défaut, cste_surf_cond=0: tout est explicit.
+cste_surf_cond=0
+
+# lev_histiso
+# niveaux de sorties pour les isotopes et aussi sans les isotopes.
+# Pas encore utilisé
+lev_histiso=1
+
+# lev_histiso_diag
+# ne s applique que si DIAGISO. 1 par defaut. si 0, seul xtvp est outputé
+lev_histiso_diag=1
+
+# valeurs isotopiques aberrantes: si on les dépasse, on plante
+deltalim=1000.0
+dexcess_max=2000
+dexcess_min=-1000
+
+# valeurs aberrantes pour les traceurs
+deltalimtrac=1000000.0
+
+# est-ce qu'on verifie l'O17? 
+O17_verif=y
+o17excess_bas=-1000.0
+o17excess_haut=900.0
+nlevmaxO17=18
+
+# pour que les continents évaporent une compositon constante, pour voir si les cycles de dexcess en Amazonie sont liés à la compo de l''évap sur continent
+# par défaut: evap_cont_cste=0
+# si evap_cont_cste=1, préciser deltaO18 et dexcess de l''évap
+evap_cont_cste=0
+deltaO18_evap_cont=-5.0
+d_evap_cont=14.0
+
+# quand on utilise tag 17, on taggue la vapeur résiduelle quand la fraction condensée est supérieure à seuil_tag_tmin, c'est à dire quand l'évènement de condensation affecte suffisemment la compo de la vapeur résiduelle. Si seuil_tag_tmin=0, le moindre évènement de condensation même très faibel agit sur les tags, et les proportions de sfc, condensat et rev sont presques nulles.
+# par defaut: seuil_tag_tmin=0.01: 1% de condensation <-> 0.1 permil d'effet sur la vapeur résiduelle.
+seuil_tag_tmin=0.01
+
+# idem pour condensation dans LS: par defaut égal à seuil_tag_tmin
+seuil_tag_tmin_ls=0.01
+
+# option_seuil_tag_tmin: si 1, on recolorise la vapeur résiduelle dès que cond/qt>seuil_tag_tmin. Ca taggue bien la vap résiduelle mais le problème est que plus on humidifie par la microphysique, plus le seuil est facilement attent -> plus on retaggue -> au final, on n'a pas plus de tag mcrophysique alors que c'est la sourec d'humdification.
+# dans l'option 2: on taggue si (cond-qmicro)/((qt-qmicro)>seuil
+option_seuil_tag_tmin=2
+
+# desactivier post-condensational exchanges comme dans Field, Jones et Brown à réviewer
+no_pce=0
+
+# latitude de taggage des extra-tropiques quand option de taggage n° 20
+# 35.0 par défaut
+lim_tag20=35.0
+
+# quand tag9, recolorise t'on que le condensat convectif (option 2) ou aussi le condensat starti (otion 1)
+option_cond=2
+
+# quand tag 22, on recolorise la vapeur dans les zones ou precip>lim_precip_tag22
+# 10.0 par défaut
+lim_precip_tag22=10.0
+
+# quand adv 14, saturation limiter tel que on advec min (q,A_satlim*qs)
+# par defaut, A_satlim=1: c'est le code original de Francis Codron
+# ce param n'a d'effet que quand adv 14.
+A_satlim=0.8
+
+# si ok_restrict_A_satlim=1, alors on n'active adv 14 que dans les extra-tropiques
+# si ok_restrict_A_satlim=2, alors on n'active adv 14 que dans les tropiques
+# si ok_restrict_A_satlim=3, alors on n'active adv 14 nulle part
+ok_restrict_A_satlim=0
+
+slope_limiter=2.0
+# defaut: 2; pour adv 10: 0
+
+#on multiplie par 3 ratqs aux extraropiques si modif_ratqs=1.
+modif_ratqs=0
+
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/isotopes_params.def
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/isotopes_params.def	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/isotopes_params.def	(revision 4482)
@@ -1,49 +1,49 @@
 &H2O
 
-  params   deltaO18_oce=0.0        fac_coeff_eq17_liq=0.529                    \
-           fac_enrichoce18=0.0005  fac_coeff_eq17_ice=0.529                    \
-           talph1_O18=1137.        talps1_O18=11.839       tkcin0_O18=0.006    \
-           talph2_O18=-0.4156      talps2_O18=-0.028244    tkcin1_O18=0.000285 \
-           talph3_O18=-2.0667E-3   tdifrel_O18=1./0.9723   tkcin2_O18=0.00082  \
-           alpha_liq_sol_O18=1.00291
+  params deltaO18_oce=0.0        fac_coeff_eq17_liq=0.529                    \
+         fac_enrichoce18=0.0005  fac_coeff_eq17_ice=0.529                    \
+         talph1_O18=1137.        talps1_O18=11.839       tkcin0_O18=0.006    \
+         talph2_O18=-0.4156      talps2_O18=-0.028244    tkcin1_O18=0.000285 \
+         talph3_O18=-2.0667E-3   tdifrel_O18=1./0.9723   tkcin2_O18=0.00082  \
+         alpha_liq_sol_O18=1.00291
 
-  H2[16]O  alpha=1.000            toce=tnat                            \
-           tnat=1.0000            tcorr=1.0                            \
-           talph1=0.0             talps1=0.0               tkcin0=0.0  \
-           talph2=0.0             talps2=0.0               tkcin1=0.0  \
-           talph3=0.0             tdifrel=1.0              tkcin2=0.0  \
-           alpha_liq_sol=1.0      Rdefault=tnat*1.0        Rmethox=1.0
+  H216O  alpha=1.000            toce=tnat                            \
+         tnat=1.0000            tcorr=1.0                            \
+         talph1=0.0             talps1=0.0               tkcin0=0.0  \
+         talph2=0.0             talps2=0.0               tkcin1=0.0  \
+         talph3=0.0             tdifrel=1.0              tkcin2=0.0  \
+         alpha_liq_sol=1.0      Rdefault=tnat*1.0        Rmethox=1.0
 
-  H2[17]O  alpha=1.003            toce=tnat*(1.0+deltaO18_oce/1000.0)^pente_MWL          \
-           tnat=40.000e-6         tcorr=1.0+fac_enrichoce18*pente_MWL                    \
-           talph1=talph1_O18      talps1=talps1_O18        tkcin0=tkcin0_O18*fac_kcin    \
-           talph2=talph2_O18      talps2=talps2_O18        tkcin1=tkcin1_O18*fac_kcin    \
-           talph3=talph3_O18      tdifrel=1./0.98555       tkcin2=tkcin2_O18*fac_kcin    \
-           alpha_liq_sol=alpha_liq_sol_O18^fac_coeff_eq17_liq                            \
-           Rdefault=tnat*(1.0-3.15/1000.)                  Rmethox=tnat*(1.0+230./1000.) \              
-           fac_kcin=(tdifrel-1.0)/(tdifrel_O18-1.0)        pente_MWL=0.528
+  H217O  alpha=1.003            toce=tnat*(1.0+deltaO18_oce/1000.0)^pente_MWL          \
+         tnat=40.000e-6         tcorr=1.0+fac_enrichoce18*pente_MWL                    \
+         talph1=talph1_O18      talps1=talps1_O18        tkcin0=tkcin0_O18*fac_kcin    \
+         talph2=talph2_O18      talps2=talps2_O18        tkcin1=tkcin1_O18*fac_kcin    \
+         talph3=talph3_O18      tdifrel=1./0.98555       tkcin2=tkcin2_O18*fac_kcin    \
+         alpha_liq_sol=alpha_liq_sol_O18^fac_coeff_eq17_liq                            \
+         Rdefault=tnat*(1.0-3.15/1000.)                  Rmethox=tnat*(1.0+230./1000.) \              
+         fac_kcin=(tdifrel-1.0)/(tdifrel_O18-1.0)        pente_MWL=0.528
 
-  H2[18]O  alpha=1.006            toce=tnat*(1.0+deltaO18_oce/1000.0)         \
-           tnat=2005.2e-6         tcorr=1.0+fac_enrichoce18                   \
-           talph1=talph1_O18      talps1=talps1_O18        tkcin0=tkcin0_O18  \
-           talph2=talph2_O18      talps2=talps2_O18        tkcin1=tkcin1_O18  \
-           talph3=talph3_O18      tdifrel=tdifrel_O18      tkcin2=tkcin2_O18  \
-           alpha_liq_sol=alpha_liq_sol_O18                                    \
-           Rdefault=tnat*(1.0-6.00/1000.)                  Rmethox=tnat*(1.0+130./1000.)  
+  H218O  alpha=1.006            toce=tnat*(1.0+deltaO18_oce/1000.0)         \
+         tnat=2005.2e-6         tcorr=1.0+fac_enrichoce18                   \
+         talph1=talph1_O18      talps1=talps1_O18        tkcin0=tkcin0_O18  \
+         talph2=talph2_O18      talps2=talps2_O18        tkcin1=tkcin1_O18  \
+         talph3=talph3_O18      tdifrel=tdifrel_O18      tkcin2=tkcin2_O18  \
+         alpha_liq_sol=alpha_liq_sol_O18                                    \
+         Rdefault=tnat*(1.0-6.00/1000.)                  Rmethox=tnat*(1.0+130./1000.)  
 
-  H[2]HO   alpha=1.010            toce=tnat*(1.0+deltaO18_oce/1000.0*pente_MWL)          \
-           tnat=155.76e-6         tcorr=1.0+fac_enrichoce18*pente_MWL                    \
-           talph1=24844.          talps1=16288.            tkcin0=tkcin0_O18*fac_kcin    \
-           talph2=-76.248         talps2=-0.0934           tkcin1=tkcin1_O18*fac_kcin    \
-           talph3=52.612E-3       tdifrel=1./0.9755        tkcin2=tkcin2_O18*fac_kcin    \
-           alpha_liq_sol=1.0212                                                          \
-           Rdefault=tnat*(1.0+(10.0-6.0*pente_MWL)/1000.)  Rmethox=tnat*(1.0-25.0/1000.) \
-           fac_kcin=(tdifrel-1.0)/(tdifrel_O18-1.0)        pente_MWL=8.0
+  HDO    alpha=1.010            toce=tnat*(1.0+deltaO18_oce/1000.0*pente_MWL)          \
+         tnat=155.76e-6         tcorr=1.0+fac_enrichoce18*pente_MWL                    \
+         talph1=24844.          talps1=16288.            tkcin0=tkcin0_O18*fac_kcin    \
+         talph2=-76.248         talps2=-0.0934           tkcin1=tkcin1_O18*fac_kcin    \
+         talph3=52.612E-3       tdifrel=1./0.9755        tkcin2=tkcin2_O18*fac_kcin    \
+         alpha_liq_sol=1.0212                                                          \
+         Rdefault=tnat*(1.0+(10.0-6.0*pente_MWL)/1000.)  Rmethox=tnat*(1.0-25.0/1000.) \
+         fac_kcin=(tdifrel-1.0)/(tdifrel_O18-1.0)        pente_MWL=8.0
 
-  H[3]HO   alpha=1.000            toce=4.0E-19                               \
-           tnat=0.0000            tcorr=1.0                                  \
-           talph1=46480.          talps1=46480.            tkcin0=0.01056    \
-           talph2=-103.87         talps2=-103.87           tkcin1=0.0005016  \
-           talph3=0.0             tdifrel=1./0.968         tkcin2=0.0014432  \
-           alpha_liq_sol=1.0      Rdefault=0.0             Rmethox=0.0
+  HTO    alpha=1.000            toce=4.0E-19                               \
+         tnat=0.0000            tcorr=1.0                                  \
+         talph1=46480.          talps1=46480.            tkcin0=0.01056    \
+         talph2=-103.87         talps2=-103.87           tkcin1=0.0005016  \
+         talph3=0.0             tdifrel=1./0.968         tkcin2=0.0014432  \
+         alpha_liq_sol=1.0      Rdefault=0.0             Rmethox=0.0
 
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/namelist_ecrad
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/namelist_ecrad	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/namelist_ecrad	(revision 4482)
@@ -12,6 +12,6 @@
  iverbose = 5, 
 
- fractional_std=0.75,                 ! (-)    vertically constant fractional standard deviation of in-cloud liquid water [0, 3]    *0.75*
- overlap_decorr_length=2000,          ! (m)    vertically constant overlap decorrelation length                           [0, 5000] *2000*
+ fractional_std=1.,                 ! (-)    vertically constant fractional standard deviation of in-cloud liquid water [0, 3]    *0.75*
+ overlap_decorr_length=1000,          ! (m)    vertically constant overlap decorrelation length                           [0, 5000] *2000*
                                       !        following Hogan and Illingworth 2000, if overlap_scheme_name=="Exp-Ran" 
                                       !        Ctrue(i,j) = a*Cmax(i,j) + (1-a)*Crand(i,j) ; a = exp(DZ(i,j)/overlap_decorr_length)
@@ -47,5 +47,4 @@
 do_3d_lw_multilayer_effects = true,
 directory_name		= "data",         ! Location of configuration files
-! directory_name		= "../../data",         ! Location of configuration files
 
 liquid_model_name = "SOCRATES",           ! Liquid droplet scattering model: "Monochromatic", "HuStamnes", *"SOCRATES"*, "Slingo"
@@ -53,6 +52,6 @@
 cloud_pdf_shape_name    = "Gamma",        ! To describe liquid water horizontal distribution: *"Gamma"*, "Lognormal"
 
-sw_solver_name          = "SPARTACUS",    ! Solver: "Homogeneous", *"McICA"*, "SPARTACUS", "Tripleclouds"
-lw_solver_name          = "SPARTACUS",    ! enable 3D effects
+sw_solver_name          = "Tripleclouds",    ! Solver: "Homogeneous", *"McICA"*, "SPARTACUS", "Tripleclouds"
+lw_solver_name          = "Tripleclouds",    ! enable 3D effects
 sw_encroachment_name    = "Computed",     ! "Maximum" = old behaviour (also "Minimum"/*"Computed"*)
 overlap_scheme_name     = "Exp-Ran",      ! Cloud overlap: *"Exp-Ran"*, "Max-Ran", "Exp-Exp"
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/physiq.def_LUDOBest2
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/physiq.def_LUDOBest2	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/physiq.def_LUDOBest2	(revision 4482)
@@ -87,5 +87,5 @@
 
           # Longueur de melange minimum pour Kz
-lmixmin=0.001
+lmixmin=0
 
           #shema de la couche de surface (D:1, 1:LMD, 8:Mellor-Yamada) 
@@ -170,13 +170,4 @@
 iflag_albedo=1
 
-    # Controle de la definition de l'inertie thermique du sol dans le modele "bucket":
-    #   0 (default) : constant
-    #   1 : fonction lineaire de qsol
-    #   2 : 2 fonctions lineaires de qsol :
-    #       une pour "sable" (boite lat/lon pour Sahara), une pour le reste (limons et argile)
-    #   3 : fonction lineaire de qsol, valeurs entre 900 pour qsol=0 et 2000 pour qsol=150
-iflag_inertie=0
-
-
           # Frequence appel convection. Nombre appels par jour
           # (nbapp_cv=0 ==> appel tous les pas de temps)
@@ -241,7 +232,4 @@
 iflag_fisrtilp_qsat=4
 
-          # Activation condensation de grande echelle epuree par E.Vignon : ok_new_lscp=y + ok_icefra_lscp=y
-ok_new_lscp=y
-ok_icefra_lscp=y
 
           #calcul des proprietes des nuages convectifs (D:1 0.375 1.e-4) 
@@ -571,13 +559,4 @@
 iflag_wk_pop_dyn=0
 
-          #Flag for the active wake ratio (D:1):
-          # iflag_wk_act=0: ==> active wake ratio = 0.
-          # iflag_wk_act=1: ==> active wake ratio = 1.
-          # iflag_wk_act=2: ==> active wake ratio = f(Wape)
-          # iflag_wk_act=3: ==> active wake ratio =
-          #     f(wake_dens, wake_radius, wape, Alp_wk, Alp_bl, birth rate fr cu)
-iflag_wk_act=1
-
-
 ####################################################################
 #  Conservation 
@@ -616,4 +595,9 @@
 cdnc_min=10.
 
+          # Activation condensation de grande echelle epuree par E.Vignon : ok_new_lscp=y + ok_icefra_lscp=y
+ok_new_lscp=y
+ok_icefra_lscp=y
+
           # min local intensity for rainfall before decrease of the associated precipitation fraction (mm/s)
+          # rain_int_min is used if iflag_evap_prec=4
 rain_int_min=1.44716149682657
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/physiq.def_NPv6.3
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/physiq.def_NPv6.3	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/physiq.def_NPv6.3	(revision 4482)
@@ -170,13 +170,4 @@
 iflag_albedo=1
 
-    # Controle de la definition de l'inertie thermique du sol dans le modele "bucket":
-    #   0 (default) : constant
-    #   1 : fonction lineaire de qsol
-    #   2 : 2 fonctions lineaires de qsol :
-    #       une pour "sable" (boite lat/lon pour Sahara), une pour le reste (limons et argile)
-    #   3 : fonction lineaire de qsol, valeurs entre 900 pour qsol=0 et 2000 pour qsol=150
-iflag_inertie=0
-
-
           # Frequence appel convection. Nombre appels par jour
           # (nbapp_cv=0 ==> appel tous les pas de temps)
@@ -526,4 +517,15 @@
 ok_bug_split_th=n
 
+          # contribution of buoyancy to the plume acceleration
+thermals_afact=.66666666666666666666
+
+          # drag term in the plume acceleration
+thermals_fact_epsilon=0.002
+
+          # scaling factor for entrainment and detrainment
+thermals_betalpha=0.9
+
+          # width of the environment subgrid scale water distribution
+cloudth_sigma1s_factor=1.1
 
 ##########################################################
@@ -555,13 +557,4 @@
           # iflag_wk_pop_dyn=1 ==> wake_dens is a prognostic variable
 iflag_wk_pop_dyn=0
-
-          #Flag for the active wake ratio (D:1):
-          # iflag_wk_act=0: ==> active wake ratio = 0.
-          # iflag_wk_act=1: ==> active wake ratio = 1.
-          # iflag_wk_act=2: ==> active wake ratio = f(Wape)
-          # iflag_wk_act=3: ==> active wake ratio =
-          #     f(wake_dens, wake_radius, wape, Alp_wk, Alp_bl, birth rate fr cu)
-iflag_wk_act=1
-
 
 ####################################################################
@@ -600,2 +593,5 @@
           #min cloud droplet number concentration
 cdnc_min=10.
+          # Activation condensation de grande echelle epuree par E.Vignon : ok_new_lscp=y + ok_icefra_lscp=y
+ok_new_lscp=n
+ok_icefra_lscp=n
Index: LMDZ6/branches/LMDZ_ECRad/DefLists/tracer_RN_PB.def_iso
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/DefLists/tracer_RN_PB.def_iso	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/DefLists/tracer_RN_PB.def_iso	(revision 4482)
@@ -1,7 +1,7 @@
 &version=1.0
 &lmdz
-default    type=tracer  phases=g    hadv=10   vadv=10   parent=air
-H2O                                 hadv=14   vadv=14
-H2O                     phases=ls
-H2[18]O,H[2]HO,H2[16]O  phases=gls                      parent=H2O
+default  type=tracer  phases=g    hadv=10   vadv=10   parent=air
+H2O                               hadv=14   vadv=14
+H2O                   phases=ls
+H218O,HDO,H216O       phases=gls                      parent=H2O
 RN,PB
Index: LMDZ6/branches/LMDZ_ECRad/arch/arch-X64_IRENE-AMD.path
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/arch/arch-X64_IRENE-AMD.path	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/arch/arch-X64_IRENE-AMD.path	(revision 4482)
@@ -1,14 +1,28 @@
-NETCDF_LIBDIR="-L$NETCDFFORTRAN_LIBDIR -L$NETCDF_LIBDIR -lnetcdf -lnetcdff"
-NETCDF_INCDIR=-I$NETCDFFORTRAN_INCDIR
-NETCDF95_INCDIR=$LMDGCM/../../include/NetCDF95
-NETCDF95_LIBDIR=$LMDGCM/../../lib
-IOIPSL_INCDIR="$LMDGCM/../../lib -I$LMDGCM/../IOIPSL/inc"
-IOIPSL_LIBDIR="$LMDGCM/../../lib -lioipsl -L$LMDGCM/../IOIPSL/lib"
-ORCH_INCDIR=$LMDGCM/../../lib
-ORCH_LIBDIR=$LMDGCM/../../lib
-OASIS_INCDIR=$LMDGCM/../../oasis3-mct/BLD/build/lib/psmile.MPI1
-OASIS_LIBDIR=$LMDGCM/../../oasis3-mct/BLD/lib
-INCA_LIBDIR=$LMDGCM/../INCA/build/lib
-INCA_INCDIR=$LMDGCM/../INCA/build/inc
-XIOS_INCDIR=$LMDGCM/../XIOS/inc
-XIOS_LIBDIR=$LMDGCM/../XIOS/lib
+NETCDF_INCDIR="-I$NETCDFFORTRAN_INCDIR"
+NETCDF_LIBDIR="-L$NETCDFFORTRAN_LIBDIR -L$NETCDF_LIBDIR"
+NETCDF_LIB="-lnetcdff -lnetcdf"
+
+NETCDF95_INCDIR=-I$LMDGCM/../../include/NetCDF95
+NETCDF95_LIBDIR=-L$LMDGCM/../../lib
+NETCDF95_LIB=-lnetcdf95
+
+IOIPSL_INCDIR="-I$LMDGCM/../../lib -I$LMDGCM/../IOIPSL/inc"
+IOIPSL_LIBDIR="-L$LMDGCM/../../lib -L$LMDGCM/../IOIPSL/lib"
+IOIPSL_LIB="-lioipsl"
+
+XIOS_INCDIR="-I$LMDGCM/../XIOS/inc"
+XIOS_LIBDIR="-L$LMDGCM/../XIOS/lib"
+XIOS_LIB="-lxios -lstdc++"
+
+ORCH_INCDIR="-I$LMDGCM/../../lib"
+ORCH_LIBDIR="-L$LMDGCM/../../lib"
+
+OASIS_INCDIR="-I$LMDGCM/../../oasis3-mct/BLD/build/lib/psmile.MPI1"
+OASIS_LIBDIR="-L$LMDGCM/../../oasis3-mct/BLD/lib"
+OASIS_LIB="-lpsmile.MPI1 -lscrip -lmct -lmpeu"
+
+INCA_INCDIR="-I$LMDGCM/../INCA/build/inc"
+INCA_LIBDIR="-L$LMDGCM/../INCA/build/lib"
+INCA_LIB="-lchimie"
+
+
Index: LMDZ6/branches/LMDZ_ECRad/arch/arch-X64_IRENE.path
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/arch/arch-X64_IRENE.path	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/arch/arch-X64_IRENE.path	(revision 4482)
@@ -1,14 +1,27 @@
-NETCDF_LIBDIR="-L$NETCDFFORTRAN_LIBDIR -L$NETCDF_LIBDIR -lnetcdf -lnetcdff"
-NETCDF_INCDIR=-I$NETCDFFORTRAN_INCDIR
-NETCDF95_INCDIR=$LMDGCM/../../include/NetCDF95
-NETCDF95_LIBDIR=$LMDGCM/../../lib
-IOIPSL_INCDIR="$LMDGCM/../../lib -I$LMDGCM/../IOIPSL/inc"
-IOIPSL_LIBDIR="$LMDGCM/../../lib -lioipsl -L$LMDGCM/../IOIPSL/lib"
-ORCH_INCDIR=$LMDGCM/../../lib
-ORCH_LIBDIR=$LMDGCM/../../lib
-OASIS_INCDIR=$LMDGCM/../../oasis3-mct/BLD/build/lib/psmile.MPI1
-OASIS_LIBDIR=$LMDGCM/../../oasis3-mct/BLD/lib
-INCA_LIBDIR=$LMDGCM/../INCA/build/lib
-INCA_INCDIR=$LMDGCM/../INCA/build/inc
-XIOS_INCDIR=$LMDGCM/../XIOS/inc
-XIOS_LIBDIR=$LMDGCM/../XIOS/lib
+
+NETCDF_INCDIR="-I$NETCDFFORTRAN_INCDIR"
+NETCDF_LIBDIR="-L$NETCDFFORTRAN_LIBDIR -L$NETCDF_LIBDIR"
+NETCDF_LIB="-lnetcdff -lnetcdf"
+
+NETCDF95_INCDIR=-I$LMDGCM/../../include/NetCDF95
+NETCDF95_LIBDIR=-L$LMDGCM/../../lib
+NETCDF95_LIB=-lnetcdf95
+
+IOIPSL_INCDIR="-I$LMDGCM/../../lib -I$LMDGCM/../IOIPSL/inc"
+IOIPSL_LIBDIR="-L$LMDGCM/../../lib -L$LMDGCM/../IOIPSL/lib"
+IOIPSL_LIB="-lioipsl"
+
+XIOS_INCDIR="-I$LMDGCM/../XIOS/inc"
+XIOS_LIBDIR="-L$LMDGCM/../XIOS/lib"
+XIOS_LIB="-lxios -lstdc++"
+
+ORCH_INCDIR="-I$LMDGCM/../../lib"
+ORCH_LIBDIR="-L$LMDGCM/../../lib"
+
+OASIS_INCDIR="-I$LMDGCM/../../oasis3-mct/BLD/build/lib/psmile.MPI1"
+OASIS_LIBDIR="-L$LMDGCM/../../oasis3-mct/BLD/lib"
+OASIS_LIB="-lpsmile.MPI1 -lscrip -lmct -lmpeu"
+
+INCA_INCDIR="-I$LMDGCM/../INCA/build/inc"
+INCA_LIBDIR="-L$LMDGCM/../INCA/build/lib"
+INCA_LIB="-lchimie"
Index: LMDZ6/branches/LMDZ_ECRad/arch/arch-X64_JEANZAY.path
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/arch/arch-X64_JEANZAY.path	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/arch/arch-X64_JEANZAY.path	(revision 4482)
@@ -2,16 +2,29 @@
 #NETCDF_LIBDIR="-L$NETCDFFORTRAN_LIBDIR -L$NETCDF_LIBDIR -lnetcdf -lnetcdff"
 #NETCDF_INCDIR=-I$NETCDFFORTRAN_INCDIR
-NETCDF_LIBDIR="-lnetcdf -lnetcdff"
-NETCDF_INCDIR=
-NETCDF95_INCDIR=$LMDGCM/../../include/NetCDF95
-NETCDF95_LIBDIR=$LMDGCM/../../lib
-IOIPSL_INCDIR="$LMDGCM/../../lib -I$LMDGCM/../IOIPSL/inc"
-IOIPSL_LIBDIR="$LMDGCM/../../lib -lioipsl -L$LMDGCM/../IOIPSL/lib"
-ORCH_INCDIR=$LMDGCM/../../lib
-ORCH_LIBDIR=$LMDGCM/../../lib
-OASIS_INCDIR=$LMDGCM/../../oasis3-mct/BLD/build/lib/psmile.MPI1
-OASIS_LIBDIR=$LMDGCM/../../oasis3-mct/BLD/lib
-INCA_LIBDIR=$LMDGCM/../INCA/build/lib
-INCA_INCDIR=$LMDGCM/../INCA/build/inc
-XIOS_INCDIR=$LMDGCM/../XIOS/inc
-XIOS_LIBDIR=$LMDGCM/../XIOS/lib
+NETCDF_INCDIR=""
+NETCDF_LIBDIR=""
+NETCDF_LIB="-lnetcdff -lnetcdf"
+
+NETCDF95_INCDIR=-I$LMDGCM/../../include/NetCDF95
+NETCDF95_LIBDIR=-L$LMDGCM/../../lib
+NETCDF95_LIB=-lnetcdf95
+
+IOIPSL_INCDIR="-I$LMDGCM/../../lib -I$LMDGCM/../IOIPSL/inc"
+IOIPSL_LIBDIR="-L$LMDGCM/../../lib -L$LMDGCM/../IOIPSL/lib"
+IOIPSL_LIB="-lioipsl"
+
+XIOS_INCDIR="-I$LMDGCM/../XIOS/inc"
+XIOS_LIBDIR="-L$LMDGCM/../XIOS/lib"
+XIOS_LIB="-lxios -lstdc++"
+
+ORCH_INCDIR="-I$LMDGCM/../../lib"
+ORCH_LIBDIR="-L$LMDGCM/../../lib"
+ORCH_LIB=
+
+OASIS_INCDIR="-I$LMDGCM/../../oasis3-mct/BLD/build/lib/psmile.MPI1"
+OASIS_LIBDIR="-L$LMDGCM/../../oasis3-mct/BLD/lib"
+OASIS_LIB="-lpsmile.MPI1 -lscrip -lmct -lmpeu"
+
+INCA_INCDIR="-I$LMDGCM/../INCA/build/inc"
+INCA_LIBDIR="-L$LMDGCM/../INCA/build/lib"
+INCA_LIB="-lchimie"
Index: LMDZ6/branches/LMDZ_ECRad/arch/arch-gfortran.fcm
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/arch/arch-gfortran.fcm	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/arch/arch-gfortran.fcm	(revision 4482)
@@ -1,16 +1,16 @@
-%COMPILER            gfortran
-%LINK                gfortran
+%COMPILER            mpifort
+%LINK                mpifort
 %AR                  ar
 %ARFLAGS             rs
 %MAKE                make
 %FPP_FLAGS           -P -traditional
-%FPP_DEF             NC_DOUBLE 
-%BASE_FFLAGS         -c -fdefault-real-8 -frecursive
+%FPP_DEF             NC_DOUBLE FFT_FFTW
+%BASE_FFLAGS         -c -fdefault-real-8 -frecursive -ffree-line-length-0
 %PROD_FFLAGS         -O3
 %DEV_FFLAGS          -O
 %DEBUG_FFLAGS        -ffpe-trap=invalid,zero,overflow -fbounds-check -g3 -O0 -fstack-protector-all
-%MPI_FFLAGS
-%OMP_FFLAGS          
-%BASE_LD      
+%MPI_FFLAGS -fcray-pointer -fallow-argument-mismatch
+%OMP_FFLAGS      -fopenmp    
+%BASE_LD      -lfftw3
 %MPI_LD
-%OMP_LD              
+%OMP_LD           -fopenmp   
Index: LMDZ6/branches/LMDZ_ECRad/arch/arch-gfortran.path
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/arch/arch-gfortran.path	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/arch/arch-gfortran.path	(revision 4482)
@@ -1,8 +1,26 @@
-NETCDF_LIBDIR="-L/usr/local/lib -lnetcdf"
-NETCDF_INCDIR=-I/usr/local/include
-NETCDF95_INCDIR=$LMDGCM/../../include
-NETCDF95_LIBDIR=$LMDGCM/../../lib
-IOIPSL_INCDIR=$LMDGCM/../../lib
-IOIPSL_LIBDIR=$LMDGCM/../../lib
-ORCH_INCDIR=$LMDGCM/../../lib
-ORCH_LIBDIR=$LMDGCM/../../lib
+NETCDF_INCDIR="-I/usr/include"
+NETCDF_LIBDIR=""
+NETCDF_LIB="-lnetcdff -lnetcdf"
+
+NETCDF95_INCDIR=-I$LMDGCM/../../include/NetCDF95
+NETCDF95_LIBDIR=-L$LMDGCM/../../lib
+NETCDF95_LIB=-lnetcdf95
+
+IOIPSL_INCDIR="-I$LMDGCM/../../lib -I$LMDGCM/../IOIPSL/inc"
+IOIPSL_LIBDIR="-L$LMDGCM/../../lib -L$LMDGCM/../IOIPSL/lib"
+IOIPSL_LIB="-lioipsl"
+
+XIOS_INCDIR="-I$LMDGCM/../XIOS/inc"
+XIOS_LIBDIR="-L$LMDGCM/../XIOS/lib"
+XIOS_LIB="-lxios -lstdc++"
+
+ORCH_INCDIR="-I$LMDGCM/../../lib"
+ORCH_LIBDIR="-L$LMDGCM/../../lib"
+
+OASIS_INCDIR="-I$LMDGCM/../../oasis3-mct/BLD/build/lib/psmile.MPI1"
+OASIS_LIBDIR="-L$LMDGCM/../../oasis3-mct/BLD/lib"
+OASIS_LIB="-lpsmile.MPI1 -lscrip -lmct -lmpeu"
+
+INCA_INCDIR="-I$LMDGCM/../INCA/build/inc"
+INCA_LIBDIR="-L$LMDGCM/../INCA/build/lib"
+INCA_LIB="-lchimie"
Index: LMDZ6/branches/LMDZ_ECRad/arch/arch-ifort_MESOIPSL.env
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/arch/arch-ifort_MESOIPSL.env	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/arch/arch-ifort_MESOIPSL.env	(revision 4482)
@@ -0,0 +1,10 @@
+# Compile and running environnement for Spirit and Spiritx at IPSL ESPRI Mesocenter 
+# 
+module purge
+module load intel/2021.4.0
+module load intel-mkl/2020.4.304
+module load openmpi/4.0.7
+module load hdf5/1.10.7-mpi
+module load netcdf-fortran/4.5.3-mpi
+module load netcdf-c/4.7.4-mpi
+
Index: LMDZ6/branches/LMDZ_ECRad/arch/arch-ifort_MESOIPSL.fcm
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/arch/arch-ifort_MESOIPSL.fcm	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/arch/arch-ifort_MESOIPSL.fcm	(revision 4482)
@@ -0,0 +1,19 @@
+%COMPILER            mpif90
+%LINK                mpif90
+%AR                  ar
+%ARFLAGS             rs
+%MAKE                make
+%FPP_FLAGS           -P -traditional
+%CPP_FLAGS           -P
+%FPP_DEF             NC_DOUBLE LAPACK FFT_MKL
+%BASE_FFLAGS         -integer-size 32 -real-size 64 -fp-model strict -auto -align all
+%PROD_FFLAGS         -O2 -ip
+%DEV_FFLAGS          -fp-model strict -p -g -O2 -traceback -fp-stack-check
+%DEBUG_FFLAGS        -fp-model strict -p -g -O0 -fpe-all=0 -traceback -fp-stack-check -ftrapuv -ftrapuv -check bounds,noarg_temp_created,pointers,stack,uninit -debug full -ftz -init=arrays,snan
+%C_COMPILER          gcc
+%C_OPTIM             -O3
+%MPI_FFLAGS
+%OMP_FFLAGS          -qopenmp 
+%BASE_LD             -i4 -r8 -auto -lmkl_intel_lp64 -lmkl_core -lmkl_sequential -lpthread
+%MPI_LD
+%OMP_LD              -qopenmp 
Index: LMDZ6/branches/LMDZ_ECRad/arch/arch-ifort_MESOIPSL.path
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/arch/arch-ifort_MESOIPSL.path	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/arch/arch-ifort_MESOIPSL.path	(revision 4482)
@@ -0,0 +1,25 @@
+NETCDF_INCDIR="-I $NETCDF_FORTRAN_ROOT/include -I${HDF5_ROOT}/include"
+NETCDF_LIBDIR="-L${NETCDF_FORTRAN_ROOT}/lib -L${NETCDF_C_ROOT}/lib -L${HDF5_ROOT}"
+NETCDF_LIB="-lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz -lcurl -lstdc++"
+
+IOIPSL_INCDIR="-I$LMDGCM/../../lib -I$LMDGCM/../IOIPSL/inc"
+IOIPSL_LIBDIR="-L$LMDGCM/../../lib -L$LMDGCM/../IOIPSL/lib"
+IOIPSL_LIB="-lioipsl"
+
+XIOS_INCDIR="-I$LMDGCM/../XIOS/inc"
+XIOS_LIBDIR="-L$LMDGCM/../XIOS/lib"
+XIOS_LIB="-lxios -lstdc++"
+
+ORCH_INCDIR="-I$LMDGCM/../../lib"
+ORCH_LIBDIR="-L$LMDGCM/../../lib"
+
+OASIS_INCDIR="-I$LMDGCM/../../oasis3-mct/BLD/build/lib/psmile.MPI1"
+OASIS_LIBDIR="-L$LMDGCM/../../oasis3-mct/BLD/lib"
+OASIS_LIB="-lpsmile.MPI1 -lscrip -lmct -lmpeu"
+
+INCA_INCDIR="-I$LMDGCM/../INCA/build/inc"
+INCA_LIBDIR="-L$LMDGCM/../INCA/build/lib"
+INCA_LIB="-lchimie"
+
+
+
Index: LMDZ6/branches/LMDZ_ECRad/bld.cfg
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/bld.cfg	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/bld.cfg	(revision 4482)
@@ -101,4 +101,6 @@
 bld::excl_dep        use::ixml_tree
 bld::excl_dep        use::netcdf95
+# The following for INCA used with CPL
+bld::excl_dep        use::incaoasis
 
 # Don't generate interface files
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/bilan_dyn.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/bilan_dyn.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/bilan_dyn.F	(revision 4482)
@@ -185,5 +185,5 @@
            WRITE(lunout,*)'dt_app=',dt_app
            WRITE(lunout,*)'dt_cum=',dt_cum
-           stop
+           call abort_gcm('bilan_dyn','stopped',1)
         endif
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/check_isotopes.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/check_isotopes.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/check_isotopes.F90	(revision 4482)
@@ -2,5 +2,5 @@
    USE strings_mod, ONLY: maxlen, msg, strIdx, strStack, int2str, real2str
    USE infotrac,    ONLY: nqtot, niso, nphas, isotope, isoCheck, iqIsoPha, isoSelect, &
-                          ntiso, iH2O, nzone, tracers, isoName,  itZonIso, tnat
+                          ntiso, iH2O, nzone, tracers, isoName,  itZonIso, getKey
    IMPLICIT NONE
    include "dimensions.h"
@@ -10,5 +10,6 @@
    CHARACTER(LEN=maxlen) :: modname, msg1, nm(2)
    INTEGER :: ixt, ipha, k, i, iq, iiso, izon, ieau, iqeau, iqpar
-   INTEGER, ALLOCATABLE :: ix(:)
+   INTEGER, ALLOCATABLE ::   ix(:)
+   REAL,    ALLOCATABLE, SAVE :: tnat(:)
    REAL    :: xtractot, xiiso, deltaD, q1, q2
    REAL, PARAMETER :: borne     = 1e19,  &
@@ -28,9 +29,10 @@
    IF(niso == 0)        RETURN                   !--- No isotopes => finished
    IF(first) THEN
-      iso_eau = strIdx(isoName,'H2[16]O')
-      iso_HDO = strIdx(isoName,'H[2]HO')
-      iso_O18 = strIdx(isoName,'H2[18]O')
-      iso_O17 = strIdx(isoName,'H2[17]O')
-      iso_HTO = strIdx(isoName,'H[3]HO')
+      iso_eau = strIdx(isoName,'H216O')
+      iso_HDO = strIdx(isoName,'HDO')
+      iso_O18 = strIdx(isoName,'H218O')
+      iso_O17 = strIdx(isoName,'H217O')
+      iso_HTO = strIdx(isoName,'HTO')
+      IF(getKey('tnat', tnat)) CALL abort_gcm(modname, 'missing isotopic parameter', 1)
       first = .FALSE.
    END IF
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/conf_gcm.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/conf_gcm.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/conf_gcm.F90	(revision 4482)
@@ -415,5 +415,5 @@
         write(lunout,*)'conf_gcm: La valeur de clat passee par run.def', &
              ' est differente de celle lue sur le fichier  start '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ENDIF
 
@@ -429,5 +429,5 @@
         write(lunout,*)'conf_gcm: La valeur de grossismx passee par ', &
              'run.def est differente de celle lue sur le fichier  start '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ENDIF
 
@@ -443,5 +443,5 @@
         write(lunout,*)'conf_gcm: La valeur de grossismy passee par ', &
              'run.def est differente de celle lue sur le fichier  start '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ENDIF
 
@@ -449,5 +449,5 @@
         write(lunout,*) &
              'conf_gcm: ***  ATTENTION !! grossismx < 1 .   *** '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ELSE
         alphax = 1. - 1./ grossismx
@@ -457,5 +457,5 @@
         write(lunout,*) &
              'conf_gcm: ***  ATTENTION !! grossismy < 1 .   *** '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ELSE
         alphay = 1. - 1./ grossismy
@@ -479,5 +479,5 @@
            write(lunout,*)' *** fxyhypb lu sur le fichier start est ', &
                 'F alors  qu il est  T  sur  run.def  ***'
-           STOP
+           CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ELSE
@@ -486,5 +486,5 @@
            write(lunout,*)' ***  fxyhypb lu sur le fichier start est ', &
                 'T alors  qu il est  F  sur  run.def  ****  '
-           STOP
+           CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ENDIF
@@ -502,5 +502,5 @@
            write(lunout,*)'conf_gcm: La valeur de dzoomx passee par ', &
                 'run.def est differente de celle lue sur le fichier  start '
-           STOP
+           CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ENDIF
@@ -518,5 +518,5 @@
            write(lunout,*)'conf_gcm: La valeur de dzoomy passee par ', &
                 'run.def est differente de celle lue sur le fichier  start '
-           STOP
+           CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ENDIF
@@ -533,5 +533,5 @@
            write(lunout,*)'conf_gcm: La valeur de taux passee par ', &
                 'run.def est differente de celle lue sur le fichier  start '
-           STOP
+           CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ENDIF
@@ -548,5 +548,5 @@
            write(lunout,*)'conf_gcm: La valeur de tauy passee par ', &
                 'run.def est differente de celle lue sur le fichier  start '
-           STOP
+           CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ENDIF
@@ -569,5 +569,5 @@
               write(lunout,*)' *** ysinus lu sur le fichier start est F', &
                    ' alors  qu il est  T  sur  run.def  ***'
-              STOP
+              CALL abort_gcm("conf_gcm","stopped",1)
            ENDIF
         ELSE
@@ -576,5 +576,5 @@
               write(lunout,*)' *** ysinus lu sur le fichier start est T', &
                    ' alors  qu il est  F  sur  run.def  ****  '
-              STOP
+              CALL abort_gcm("conf_gcm","stopped",1)
            ENDIF
         ENDIF
@@ -599,14 +599,4 @@
      type_trac = 'lmdz'
      CALL getin('type_trac',type_trac)
-
-     !Config  Key  = config_inca
-     !Config  Desc = Choix de configuration de INCA
-     !Config  Def  = none
-     !Config  Help = Choix de configuration de INCA :
-     !Config         'none' = sans INCA
-     !Config         'chem' = INCA avec calcul de chemie
-     !Config         'aero' = INCA avec calcul des aerosols 
-     config_inca = 'none'
-     CALL getin('config_inca',config_inca)
 
      !Config  Key  = ok_dynzon 
@@ -672,5 +662,4 @@
      write(lunout,*)' offline = ', offline
      write(lunout,*)' type_trac = ', type_trac
-     write(lunout,*)' config_inca = ', config_inca
      write(lunout,*)' ok_dynzon = ', ok_dynzon 
      write(lunout,*)' ok_dyn_ins = ', ok_dyn_ins 
@@ -712,5 +701,5 @@
         write(lunout,*) &
              'conf_gcm: ***  ATTENTION !! grossismx < 1 .   *** '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ELSE
         alphax = 1. - 1./ grossismx
@@ -719,5 +708,5 @@
      IF( grossismy.LT.1. )  THEN
         write(lunout,*) 'conf_gcm: ***ATTENTION !! grossismy < 1 . *** '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ELSE
         alphay = 1. - 1./ grossismy
@@ -795,14 +784,4 @@
      type_trac = 'lmdz'
      CALL getin('type_trac',type_trac)
-
-     !Config  Key  = config_inca
-     !Config  Desc = Choix de configuration de INCA
-     !Config  Def  = none
-     !Config  Help = Choix de configuration de INCA :
-     !Config         'none' = sans INCA
-     !Config         'chem' = INCA avec calcul de chemie
-     !Config         'aero' = INCA avec calcul des aerosols 
-     config_inca = 'none'
-     CALL getin('config_inca',config_inca)
 
      !Config  Key  = ok_dynzon 
@@ -912,5 +891,4 @@
      write(lunout,*)' offline = ', offline
      write(lunout,*)' type_trac = ', type_trac
-     write(lunout,*)' config_inca = ', config_inca
      write(lunout,*)' ok_dynzon = ', ok_dynzon
      write(lunout,*)' ok_dyn_ins = ', ok_dyn_ins 
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/dynetat0.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/dynetat0.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/dynetat0.F90	(revision 4482)
@@ -6,9 +6,9 @@
 ! Purpose: Initial state reading.
 !-------------------------------------------------------------------------------
-  USE infotrac,    ONLY: nqtot, tracers, niso, iqIsoPha, tnat, alpha_ideal, iH2O
+  USE infotrac,    ONLY: nqtot, tracers, niso, iqIsoPha, iH2O, isoName
   USE strings_mod, ONLY: maxlen, msg, strStack, real2str, int2str
   USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQ_VARID, &
                          NF90_CLOSE, NF90_GET_VAR, NF90_NoErr
-  USE readTracFiles_mod, ONLY: new2oldName
+  USE readTracFiles_mod, ONLY: new2oldH2O, newHNO3, oldHNO3, getKey
   USE control_mod, ONLY: planet_type
   USE assert_eq_m, ONLY: assert_eq
@@ -41,5 +41,6 @@
   INTEGER, PARAMETER :: length=100
   INTEGER :: iq, fID, vID, idecal, iqParent, iName, iZone, iPhase
-  REAL    :: time, tab_cntrl(length)               !--- RUN PARAMS TABLE
+  REAL    :: time, tnat, alpha_ideal, tab_cntrl(length)    !--- RUN PARAMS TABLE
+  LOGICAL :: lSkip, ll
 !-------------------------------------------------------------------------------
   modname="dynetat0"
@@ -127,21 +128,26 @@
 
 !--- Tracers
+  ll=.FALSE.
+#ifdef REPROBUS
+  ll = NF90_INQ_VARID(fID, 'HNO3tot', vID) /= NF90_NoErr                                 !--- DETECT OLD REPRO start.nc FILE
+#endif
   DO iq=1,nqtot
     var = tracers(iq)%name
-    oldVar = new2oldName(var)
-    !--------------------------------------------------------------------------------------------------------------------------
-    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr) THEN                                 !=== REGULAR CASE
+    oldVar = new2oldH2O(var)
+    lSkip = ll .AND. var == 'HNO3'                                                       !--- FORCE "HNO3_g" READING FOR "HNO3"
+#ifdef REPROBUS
+    ix = strIdx(newHNO3, var); IF(ix /= 0) oldVar = oldHNO3(ix)                          !--- REPROBUS HNO3 exceptions
+#endif
+#ifdef INCA
+    IF(var == 'O3') oldVar = 'OX'                                                        !--- DEAL WITH INCA OZONE EXCEPTION
+#endif
+    !--------------------------------------------------------------------------------------------------------------------------
+    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr .AND. .NOT.lSkip) THEN                !=== REGULAR CASE: AVAILABLE VARIABLE
       CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var)
     !--------------------------------------------------------------------------------------------------------------------------
-    ELSE IF(NF90_INQ_VARID(fID, oldVar, vID) == NF90_NoErr) THEN                         !=== OLD NAME
+    ELSE IF(NF90_INQ_VARID(fID, oldVar, vID) == NF90_NoErr) THEN                         !=== TRY WITH ALTERNATE NAME
       CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to <'//TRIM(oldVar)//'>', modname)
       CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",oldVar)
     !--------------------------------------------------------------------------------------------------------------------------
-#ifdef INCA
-    ELSE IF(NF90_INQ_VARID(fID, 'OX',   vID) == NF90_NoErr .AND. var == 'O3') THEN       !=== INCA: OX INSTEAD OF O3
-      CALL msg('Tracer <O3> is missing => initialized to <OX>', modname)
-      CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",'OX')
-    !--------------------------------------------------------------------------------------------------------------------------
-#endif
     ELSE IF(tracers(iq)%iso_iGroup == iH2O .AND. niso > 0) THEN                          !=== WATER ISOTOPES
       iName    = tracers(iq)%iso_iName
@@ -149,6 +155,8 @@
       iqParent = tracers(iq)%iqParent
       IF(tracers(iq)%iso_iZone == 0) THEN
+         IF(getKey('tnat', tnat, isoName(iName)) .OR. getKey('alpha', alpha_ideal, isoName(iName))) &
+            CALL abort_gcm(TRIM(modname), 'missing isotopic parameters', 1)
          CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized with a simplified Rayleigh distillation law.', modname)
-         q(:,:,:,iq) = q(:,:,:,iqParent)*tnat(iName)*(q(:,:,:,iqParent)/30.e-3)**(alpha_ideal(iName)-1.)
+         q(:,:,:,iq) = q(:,:,:,iqParent)*tnat*(q(:,:,:,iqParent)/30.e-3)**(alpha_ideal-1.)
       ELSE
          CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to its parent isotope concentration.', modname)
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/dynredem.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/dynredem.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/dynredem.F90	(revision 4482)
@@ -167,5 +167,5 @@
 !-------------------------------------------------------------------------------
   USE strings_mod, ONLY: maxlen
-  USE infotrac, ONLY: nqtot, tracers, types_trac
+  USE infotrac, ONLY: nqtot, tracers, type_trac
   USE control_mod
   USE netcdf,   ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_GET_VAR, NF90_INQ_VARID,  &
@@ -228,5 +228,5 @@
 !--- Tracers in file "start_trac.nc" (added by Anne)
   lread_inca=.FALSE.; fil="start_trac.nc"
-  IF(ANY(types_trac=='inca') .OR. ANY(types_trac=='inco')) INQUIRE(FILE=fil,EXIST=lread_inca)
+  IF(ANY(type_trac == ['inca','inco'])) INQUIRE(FILE=fil,EXIST=lread_inca)
   IF(lread_inca) CALL err(NF90_OPEN(fil,NF90_NOWRITE,nid_trac),"open")
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/gcm.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/gcm.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/gcm.F90	(revision 4482)
@@ -20,5 +20,5 @@
 
   USE filtreg_mod
-  USE infotrac
+  USE infotrac, ONLY: nqtot, init_infotrac
   USE control_mod
   USE mod_const_mpi, ONLY: COMM_LMDZ
@@ -178,5 +178,5 @@
 #ifdef CPP_IOIPSL
   if (calend == 'earth_360d') then
-     call ioconf_calendar('360d')
+     call ioconf_calendar('360_day')
      write(lunout,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
   else if (calend == 'earth_365d') then
@@ -205,5 +205,5 @@
   !  Choix du nombre de traceurs et du schema pour l'advection
   !  dans fichier traceur.def, par default ou via INCA
-  call infotrac_init
+  call init_infotrac
 
   ! Allocation de la tableau q : champs advectes   
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/groupe.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/groupe.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/groupe.F	(revision 4482)
@@ -51,5 +51,6 @@
       if (firstcall) then
          if (groupe_ok) then
-           if(mod(iim,2**ngroup).ne.0) stop'probleme du nombre de point'
+            if(mod(iim,2**ngroup).ne.0)         
+     &        CALL abort_gcm('groupe','probleme du nombre de point',1)
          endif
          firstcall=.false.
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/guide_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/guide_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/guide_mod.F90	(revision 4482)
@@ -39,4 +39,6 @@
   REAL, PRIVATE, SAVE     :: lon_min_g,lon_max_g
   REAL, PRIVATE, SAVE     :: tau_lon,tau_lat
+
+  REAL, PRIVATE, SAVE     :: plim_guide_BL
 
   REAL, ALLOCATABLE, DIMENSION(:), PRIVATE, SAVE     :: alpha_u,alpha_v 
@@ -67,4 +69,5 @@
   SUBROUTINE guide_init
 
+    use netcdf, only: nf90_noerr
     USE control_mod, ONLY: day_step
     USE serre_mod, ONLY: grossismx
@@ -113,4 +116,6 @@
     CALL getpar('gamma4',.false.,gamma4,'Zone sans rappel elargie')
     CALL getpar('guide_BL',.true.,guide_BL,'guidage dans C.Lim')
+    CALL getpar('plim_guide_BL',85000.,plim_guide_BL,'BL top presnivs value')
+
 
 ! Sauvegarde du for�age
@@ -169,5 +174,5 @@
        if (ncidpl.eq.-99) then
           rcod=nf90_open('apbp.nc',Nf90_NOWRITe, ncidpl)
-          if (rcod.NE.NF_NOERR) THEN
+          if (rcod.NE.NF90_NOERR) THEN
              abort_message=' Nudging error -> no file apbp.nc'
              CALL abort_gcm(modname,abort_message,1)
@@ -177,5 +182,5 @@
        if (ncidpl.EQ.-99) then
           rcod=nf90_open('P.nc',Nf90_NOWRITe,ncidpl)
-          if (rcod.NE.NF_NOERR) THEN
+          if (rcod.NE.NF90_NOERR) THEN
              abort_message=' Nudging error -> no file P.nc'
              CALL abort_gcm(modname,abort_message,1)
@@ -186,5 +191,5 @@
            if (ncidpl.eq.-99) then
                rcod=nf90_open('u.nc',Nf90_NOWRITe,ncidpl)
-               if (rcod.NE.NF_NOERR) THEN
+               if (rcod.NE.NF90_NOERR) THEN
                   CALL abort_gcm(modname, &
                        ' Nudging error -> no file u.nc',1)
@@ -195,5 +200,5 @@
            if (ncidpl.eq.-99) then
                rcod=nf90_open('v.nc',nf90_nowrite,ncidpl)
-               if (rcod.NE.NF_NOERR) THEN
+               if (rcod.NE.NF90_NOERR) THEN
                   CALL abort_gcm(modname, &
                        ' Nudging error -> no file v.nc',1)
@@ -203,5 +208,5 @@
            if (ncidpl.eq.-99) then
                rcod=nf90_open('T.nc',nf90_nowrite,ncidpl)
-               if (rcod.NE.NF_NOERR) THEN
+               if (rcod.NE.NF90_NOERR) THEN
                   CALL abort_gcm(modname, &
                        ' Nudging error -> no file T.nc',1)
@@ -211,5 +216,5 @@
            if (ncidpl.eq.-99) then
                rcod=nf90_open('hur.nc',nf90_nowrite, ncidpl)
-               if (rcod.NE.NF_NOERR) THEN
+               if (rcod.NE.NF90_NOERR) THEN
                   CALL abort_gcm(modname, &
                        ' Nudging error -> no file hur.nc',1)
@@ -220,6 +225,6 @@
     endif 
     error=NF_INQ_DIMID(ncidpl,'LEVEL',rid)
-    IF (error.NE.NF_NOERR) error=NF_INQ_DIMID(ncidpl,'PRESSURE',rid)
-    IF (error.NE.NF_NOERR) THEN
+    IF (error.NE.NF90_NOERR) error=NF_INQ_DIMID(ncidpl,'PRESSURE',rid)
+    IF (error.NE.NF90_NOERR) THEN
         CALL abort_gcm(modname,'Nudging: error reading pressure levels',1)
     ENDIF
@@ -354,4 +359,6 @@
     INCLUDE "dimensions.h"
     INCLUDE "paramet.h"
+    INCLUDE "iniprint.h"
+
 
     ! Variables entree
@@ -377,4 +384,6 @@
     INTEGER       :: l
     CHARACTER(LEN=20) :: modname="guide_main"
+    CHARACTER (len = 80)   :: abort_message
+
 
 !-----------------------------------------------------------------------
@@ -399,5 +408,5 @@
         else
             do l=1,llm
-                alpha_pcor(l)=(1.+tanh((0.85-presnivs(l)/preff)/0.05))/2.
+               alpha_pcor(l)=(1.+tanh(((plim_guide_BL-presnivs(l))/preff)/0.05))/2.
             enddo
         endif
@@ -442,7 +451,8 @@
       IF (reste.EQ.0.) THEN
           IF (itau_test.EQ.itau) THEN
-            write(*,*)trim(modname)//' second pass in advreel at itau=',&
+            write(lunout,*)trim(modname)//' second pass in advreel at itau=',&
             itau
-            stop
+              abort_message='stopped'
+              CALL abort_gcm(modname,abort_message,1) 
           ELSE
               IF (guide_v) vnat1=vnat2
@@ -937,4 +947,5 @@
     integer i,j,ilon,ilat
     character(len=20),parameter :: modname="tau2alpha"
+    CHARACTER (len = 80)   :: abort_message
 
 
@@ -1033,5 +1044,6 @@
               if (gamma.lt.1.e-5) then
                 write(*,*)trim(modname)//' gamma =',gamma,'<1e-5'
-                stop
+                abort_message='stopped'
+                CALL abort_gcm(modname,abort_message,1)
               endif
               gamma=log(0.5)/log(gamma)
@@ -1078,7 +1090,8 @@
   SUBROUTINE guide_read(timestep)
 
+    use netcdf, only: NF90_GET_VAR, nf90_noerr
+
     IMPLICIT NONE
 
-    include "netcdf.inc"
     include "dimensions.h"
     include "paramet.h"
@@ -1103,24 +1116,24 @@
     if (first) then
          ncidpl=-99
-         write(*,*),trim(modname)//': opening nudging files '
+         write(*,*) trim(modname)//': opening nudging files '
 ! Niveaux de pression si non constants
          if (guide_plevs.EQ.1) then
-             write(*,*),trim(modname)//' Reading nudging on model levels'
+             write(*,*) trim(modname)//' Reading nudging on model levels'
              rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no file apbp.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidpl, 'AP', varidap)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no AP variable in file apbp.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no BP variable in file apbp.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             write(*,*),trim(modname)//' ncidpl,varidap',ncidpl,varidap
+             write(*,*) trim(modname)//' ncidpl,varidap',ncidpl,varidap
          endif
 
@@ -1128,14 +1141,14 @@
          if (guide_plevs.EQ.2) then
              rcode = nf90_open('P.nc', nf90_nowrite, ncidp)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no file P.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidp, 'PRES', varidp)
-             IF (rcode.NE.NF_NOERR) THEN 
+             IF (rcode.NE.NF90_NOERR) THEN 
               abort_message='Nudging: error -> no PRES variable in file P.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             write(*,*),trim(modname)//' ncidp,varidp',ncidp,varidp
+             write(*,*) trim(modname)//' ncidp,varidp',ncidp,varidp
              if (ncidpl.eq.-99) ncidpl=ncidp
          endif
@@ -1144,14 +1157,14 @@
          if (guide_u) then
              rcode = nf90_open('u.nc', nf90_nowrite, ncidu)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no file u.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidu, 'UWND', varidu)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no UWND variable in file u.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             write(*,*),trim(modname)//' ncidu,varidu',ncidu,varidu
+             write(*,*) trim(modname)//' ncidu,varidu',ncidu,varidu
              if (ncidpl.eq.-99) ncidpl=ncidu
 
@@ -1175,14 +1188,14 @@
          if (guide_v) then
              rcode = nf90_open('v.nc', nf90_nowrite, ncidv)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no file v.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidv, 'VWND', varidv)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no VWND variable in file v.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             write(*,*),trim(modname)//' ncidv,varidv',ncidv,varidv
+             write(*,*) trim(modname)//' ncidv,varidv',ncidv,varidv
              if (ncidpl.eq.-99) ncidpl=ncidv
              
@@ -1208,14 +1221,14 @@
          if (guide_T) then
              rcode = nf90_open('T.nc', nf90_nowrite, ncidt)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no file T.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidt, 'AIR', varidt)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no AIR variable in file T.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             write(*,*),trim(modname)//' ncidT,varidT',ncidt,varidt
+             write(*,*) trim(modname)//' ncidT,varidT',ncidt,varidt
              if (ncidpl.eq.-99) ncidpl=ncidt
 
@@ -1239,14 +1252,14 @@
          if (guide_Q) then
              rcode = nf90_open('hur.nc', nf90_nowrite, ncidQ)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no file hur.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidQ, 'RH', varidQ)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no RH variable in file hur.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             write(*,*),trim(modname)//' ncidQ,varidQ',ncidQ,varidQ
+             write(*,*) trim(modname)//' ncidQ,varidQ',ncidQ,varidQ
              if (ncidpl.eq.-99) ncidpl=ncidQ
 
@@ -1270,14 +1283,14 @@
          if ((guide_P).OR.(guide_modele)) then
              rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no file ps.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidps, 'SP', varidps)
-             IF (rcode.NE.NF_NOERR) THEN
+             IF (rcode.NE.NF90_NOERR) THEN
               abort_message='Nudging: error -> no SP variable in file ps.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             write(*,*),trim(modname)//' ncidps,varidps',ncidps,varidps
+             write(*,*) trim(modname)//' ncidps,varidps',ncidps,varidps
          endif
 ! Coordonnee verticale
@@ -1285,21 +1298,12 @@
               rcode = nf90_inq_varid(ncidpl, 'LEVEL', varidpl)
               IF (rcode.NE.0) rcode = nf90_inq_varid(ncidpl, 'PRESSURE', varidpl)
-              write(*,*),trim(modname)//' ncidpl,varidpl',ncidpl,varidpl
+              write(*,*) trim(modname)//' ncidpl,varidpl',ncidpl,varidpl
          endif
 ! Coefs ap, bp pour calcul de la pression aux differents niveaux
          if (guide_plevs.EQ.1) then
-#ifdef NC_DOUBLE
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidap,1,nlevnc,apnc)
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidbp,1,nlevnc,bpnc)
-#else
-             status=NF_GET_VARA_REAL(ncidpl,varidap,1,nlevnc,apnc)
-             status=NF_GET_VARA_REAL(ncidpl,varidbp,1,nlevnc,bpnc)
-#endif
+             status=NF90_GET_VAR(ncidpl,varidap,apnc,[1],[nlevnc])
+             status=NF90_GET_VAR(ncidpl,varidbp,bpnc,[1],[nlevnc])
          ELSEIF (guide_plevs.EQ.0) THEN
-#ifdef NC_DOUBLE
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidpl,1,nlevnc,apnc)
-#else
-             status=NF_GET_VARA_REAL(ncidpl,varidpl,1,nlevnc,apnc)
-#endif
+             status=NF90_GET_VAR(ncidpl,varidpl,apnc,[1],[nlevnc])
 !FC Pour les corrections la pression est deja en Pascals on commente la ligne ci-dessous
              IF(convert_Pa) apnc=apnc*100.! conversion en Pascals
@@ -1326,9 +1330,5 @@
 ! Pression 
      if (guide_plevs.EQ.2) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidp,varidp,start,count,pnat2)
-#else
-         status=NF_GET_VARA_REAL(ncidp,varidp,start,count,pnat2)
-#endif
+         status=NF90_GET_VAR(ncidp,varidp,pnat2,start,count)
          IF (invert_y) THEN
 !           PRINT*,"Invertion impossible actuellement"
@@ -1340,9 +1340,5 @@
 !  Vent zonal
      if (guide_u) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidu,varidu,start,count,unat2)
-#else
-         status=NF_GET_VARA_REAL(ncidu,varidu,start,count,unat2)
-#endif
+         status=NF90_GET_VAR(ncidu,varidu,unat2,start,count)
          IF (invert_y) THEN
            CALL invert_lat(iip1,jjp1,nlevnc,unat2)
@@ -1352,9 +1348,5 @@
 !  Temperature
      if (guide_T) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidt,varidt,start,count,tnat2)
-#else
-         status=NF_GET_VARA_REAL(ncidt,varidt,start,count,tnat2)
-#endif
+         status=NF90_GET_VAR(ncidt,varidt,tnat2,start,count)
          IF (invert_y) THEN
            CALL invert_lat(iip1,jjp1,nlevnc,tnat2)
@@ -1364,9 +1356,5 @@
 !  Humidite
      if (guide_Q) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidQ,varidQ,start,count,qnat2)
-#else
-         status=NF_GET_VARA_REAL(ncidQ,varidQ,start,count,qnat2)
-#endif
+         status=NF90_GET_VAR(ncidQ,varidQ,qnat2,start,count)
          IF (invert_y) THEN
            CALL invert_lat(iip1,jjp1,nlevnc,qnat2)
@@ -1378,9 +1366,5 @@
      if (guide_v) then
          count(2)=jjm
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidv,varidv,start,count,vnat2)
-#else
-         status=NF_GET_VARA_REAL(ncidv,varidv,start,count,vnat2)
-#endif
+         status=NF90_GET_VAR(ncidv,varidv,vnat2,start,count)
          IF (invert_y) THEN
            CALL invert_lat(iip1,jjm,nlevnc,vnat2)
@@ -1395,9 +1379,5 @@
          count(3)=1
          count(4)=0
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidps,varidps,start,count,psnat2)
-#else
-         status=NF_GET_VARA_REAL(ncidps,varidps,start,count,psnat2)
-#endif
+         status=NF90_GET_VAR(ncidps,varidps,psnat2,start,count)
          IF (invert_y) THEN
            CALL invert_lat(iip1,jjp1,1,psnat2)
@@ -1410,7 +1390,8 @@
   SUBROUTINE guide_read2D(timestep)
 
+    use netcdf, only: nf90_get_var, nf90_noerr
+
     IMPLICIT NONE
 
-    include "netcdf.inc"
     include "dimensions.h"
     include "paramet.h"
@@ -1443,15 +1424,15 @@
            write(*,*)trim(modname)//' Reading nudging on model levels'
            rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no file apbp.nc'
            CALL abort_gcm(modname,abort_message,1)
            ENDIF
            rcode = nf90_inq_varid(ncidpl, 'AP', varidap)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no AP variable in file apbp.nc'
            CALL abort_gcm(modname,abort_message,1)
            ENDIF
            rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no BP variable in file apbp.nc'
              CALL abort_gcm(modname,abort_message,1)
@@ -1462,10 +1443,10 @@
          if (guide_plevs.EQ.2) then
            rcode = nf90_open('P.nc', nf90_nowrite, ncidp)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no file P.nc'
              CALL abort_gcm(modname,abort_message,1)
            ENDIF
            rcode = nf90_inq_varid(ncidp, 'PRES', varidp)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no PRES variable in file P.nc'
              CALL abort_gcm(modname,abort_message,1)
@@ -1477,10 +1458,10 @@
          if (guide_u) then
            rcode = nf90_open('u.nc', nf90_nowrite, ncidu)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no file u.nc'
              CALL abort_gcm(modname,abort_message,1)
            ENDIF
            rcode = nf90_inq_varid(ncidu, 'UWND', varidu)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no UWND variable in file u.nc'
              CALL abort_gcm(modname,abort_message,1)
@@ -1492,10 +1473,10 @@
          if (guide_v) then
            rcode = nf90_open('v.nc', nf90_nowrite, ncidv)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no file v.nc'
              CALL abort_gcm(modname,abort_message,1)
            ENDIF
            rcode = nf90_inq_varid(ncidv, 'VWND', varidv)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no VWND variable in file v.nc'
              CALL abort_gcm(modname,abort_message,1)
@@ -1507,10 +1488,10 @@
          if (guide_T) then
            rcode = nf90_open('T.nc', nf90_nowrite, ncidt)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no file T.nc'
              CALL abort_gcm(modname,abort_message,1)
            ENDIF
            rcode = nf90_inq_varid(ncidt, 'AIR', varidt)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no AIR variable in file T.nc'
              CALL abort_gcm(modname,abort_message,1)
@@ -1522,10 +1503,10 @@
          if (guide_Q) then
            rcode = nf90_open('hur.nc', nf90_nowrite, ncidQ)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no file hur.nc'
              CALL abort_gcm(modname,abort_message,1)
            ENDIF
            rcode = nf90_inq_varid(ncidQ, 'RH', varidQ)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no RH,variable in file hur.nc'
              CALL abort_gcm(modname,abort_message,1)
@@ -1537,10 +1518,10 @@
          if ((guide_P).OR.(guide_modele)) then
            rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no file ps.nc'
              CALL abort_gcm(modname,abort_message,1)
            ENDIF
            rcode = nf90_inq_varid(ncidps, 'SP', varidps)
-           IF (rcode.NE.NF_NOERR) THEN
+           IF (rcode.NE.NF90_NOERR) THEN
              abort_message='Nudging: error -> no SP variable in file ps.nc'
              CALL abort_gcm(modname,abort_message,1)
@@ -1556,17 +1537,8 @@
 ! Coefs ap, bp pour calcul de la pression aux differents niveaux
          if (guide_plevs.EQ.1) then
-#ifdef NC_DOUBLE
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidap,1,nlevnc,apnc)
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidbp,1,nlevnc,bpnc)
-#else
-             status=NF_GET_VARA_REAL(ncidpl,varidap,1,nlevnc,apnc)
-             status=NF_GET_VARA_REAL(ncidpl,varidbp,1,nlevnc,bpnc)
-#endif
+             status=NF90_GET_VAR(ncidpl,varidap,apnc,[1],[nlevnc])
+             status=NF90_GET_VAR(ncidpl,varidbp,bpnc,[1],[nlevnc])
          elseif (guide_plevs.EQ.0) THEN
-#ifdef NC_DOUBLE
-             status=NF_GET_VARA_DOUBLE(ncidpl,varidpl,1,nlevnc,apnc)
-#else
-             status=NF_GET_VARA_REAL(ncidpl,varidpl,1,nlevnc,apnc)
-#endif
+             status=NF90_GET_VAR(ncidpl,varidpl,apnc,[1],[nlevnc])
              apnc=apnc*100.! conversion en Pascals
              bpnc(:)=0.
@@ -1592,9 +1564,5 @@
 !  Pression
      if (guide_plevs.EQ.2) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidp,varidp,start,count,zu)
-#else
-         status=NF_GET_VARA_REAL(ncidp,varidp,start,count,zu)
-#endif
+         status=NF90_GET_VAR(ncidp,varidp,zu,start,count)
          DO i=1,iip1
              pnat2(i,:,:)=zu(:,:)
@@ -1609,9 +1577,5 @@
 !  Vent zonal
      if (guide_u) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidu,varidu,start,count,zu)
-#else
-         status=NF_GET_VARA_REAL(ncidu,varidu,start,count,zu)
-#endif
+         status=NF90_GET_VAR(ncidu,varidu,zu,start,count)
          DO i=1,iip1
              unat2(i,:,:)=zu(:,:)
@@ -1626,9 +1590,5 @@
 !  Temperature
      if (guide_T) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidt,varidt,start,count,zu)
-#else
-         status=NF_GET_VARA_REAL(ncidt,varidt,start,count,zu)
-#endif
+         status=NF90_GET_VAR(ncidt,varidt,zu,start,count)
          DO i=1,iip1
              tnat2(i,:,:)=zu(:,:)
@@ -1643,9 +1603,5 @@
 !  Humidite
      if (guide_Q) then
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidQ,varidQ,start,count,zu)
-#else
-         status=NF_GET_VARA_REAL(ncidQ,varidQ,start,count,zu)
-#endif
+         status=NF90_GET_VAR(ncidQ,varidQ,zu,start,count)
          DO i=1,iip1
              qnat2(i,:,:)=zu(:,:)
@@ -1661,9 +1617,5 @@
      if (guide_v) then
          count(2)=jjm
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidv,varidv,start,count,zv)
-#else
-         status=NF_GET_VARA_REAL(ncidv,varidv,start,count,zv)
-#endif
+         status=NF90_GET_VAR(ncidv,varidv,zv,start,count)
          DO i=1,iip1
              vnat2(i,:,:)=zv(:,:)
@@ -1683,9 +1635,5 @@
          count(3)=1
          count(4)=0
-#ifdef NC_DOUBLE
-         status=NF_GET_VARA_DOUBLE(ncidps,varidps,start,count,zu(:,1))
-#else
-         status=NF_GET_VARA_REAL(ncidps,varidps,start,count,zu(:,1))
-#endif
+         status=NF90_GET_VAR(ncidps,varidps,zu(:,1),start,count)
          DO i=1,iip1
              psnat2(i,:)=zu(:,1)
@@ -1706,5 +1654,5 @@
     USE comvert_mod, ONLY: presnivs
     use netcdf95, only: nf95_def_var, nf95_put_var
-    use netcdf, only: nf90_float
+    use netcdf, only: nf90_float, nf90_def_var
     
     IMPLICIT NONE
@@ -1748,13 +1696,13 @@
 
 ! Creation des variables dimensions
-        ierr=NF_DEF_VAR(nid,"LONU",NF_FLOAT,1,id_lonu,vid_lonu)
-        ierr=NF_DEF_VAR(nid,"LONV",NF_FLOAT,1,id_lonv,vid_lonv)
-        ierr=NF_DEF_VAR(nid,"LATU",NF_FLOAT,1,id_latu,vid_latu)
-        ierr=NF_DEF_VAR(nid,"LATV",NF_FLOAT,1,id_latv,vid_latv)
-        ierr=NF_DEF_VAR(nid,"LEVEL",NF_FLOAT,1,id_lev,vid_lev)
-        ierr=NF_DEF_VAR(nid,"cu",NF_FLOAT,2,(/id_lonu,id_latu/),vid_cu)
-        ierr=NF_DEF_VAR(nid,"cv",NF_FLOAT,2,(/id_lonv,id_latv/),vid_cv)
-        ierr=NF_DEF_VAR(nid,"au",NF_FLOAT,2,(/id_lonu,id_latu/),vid_au)
-        ierr=NF_DEF_VAR(nid,"av",NF_FLOAT,2,(/id_lonv,id_latv/),vid_av)
+        ierr=NF90_DEF_VAR(nid,"LONU",NF90_FLOAT,id_lonu,vid_lonu)
+        ierr=NF90_DEF_VAR(nid,"LONV",NF90_FLOAT,id_lonv,vid_lonv)
+        ierr=NF90_DEF_VAR(nid,"LATU",NF90_FLOAT,id_latu,vid_latu)
+        ierr=NF90_DEF_VAR(nid,"LATV",NF90_FLOAT,id_latv,vid_latv)
+        ierr=NF90_DEF_VAR(nid,"LEVEL",NF90_FLOAT,id_lev,vid_lev)
+        ierr=NF90_DEF_VAR(nid,"cu",NF90_FLOAT,(/id_lonu,id_latu/),vid_cu)
+        ierr=NF90_DEF_VAR(nid,"cv",NF90_FLOAT,(/id_lonv,id_latv/),vid_cv)
+        ierr=NF90_DEF_VAR(nid,"au",NF90_FLOAT,(/id_lonu,id_latu/),vid_au)
+        ierr=NF90_DEF_VAR(nid,"av",NF90_FLOAT,(/id_lonv,id_latv/),vid_av)
         call nf95_def_var(nid, "alpha_T", nf90_float, (/id_lonv, id_latu/), &
              varid_alpha_t)
@@ -1794,33 +1742,33 @@
 ! Pressure (GCM)
         dim4=(/id_lonv,id_latu,id_lev,id_tim/)
-        ierr = NF_DEF_VAR(nid,"SP",NF_FLOAT,4,dim4,varid)
+        ierr = NF90_DEF_VAR(nid,"SP",NF90_FLOAT,dim4,varid)
 ! Surface pressure (guidage)
         IF (guide_P) THEN
             dim3=(/id_lonv,id_latu,id_tim/)
-            ierr = NF_DEF_VAR(nid,"ps",NF_FLOAT,3,dim3,varid)
+            ierr = NF90_DEF_VAR(nid,"ps",NF90_FLOAT,dim3,varid)
         ENDIF
 ! Zonal wind
         IF (guide_u) THEN
             dim4=(/id_lonu,id_latu,id_lev,id_tim/)
-            ierr = NF_DEF_VAR(nid,"u",NF_FLOAT,4,dim4,varid)
-            ierr = NF_DEF_VAR(nid,"ua",NF_FLOAT,4,dim4,varid)
-            ierr = NF_DEF_VAR(nid,"ucov",NF_FLOAT,4,dim4,varid)
+            ierr = NF90_DEF_VAR(nid,"u",NF90_FLOAT,dim4,varid)
+            ierr = NF90_DEF_VAR(nid,"ua",NF90_FLOAT,dim4,varid)
+            ierr = NF90_DEF_VAR(nid,"ucov",NF90_FLOAT,dim4,varid)
         ENDIF
 ! Merid. wind
         IF (guide_v) THEN
             dim4=(/id_lonv,id_latv,id_lev,id_tim/)
-            ierr = NF_DEF_VAR(nid,"v",NF_FLOAT,4,dim4,varid)
-            ierr = NF_DEF_VAR(nid,"va",NF_FLOAT,4,dim4,varid)
-            ierr = NF_DEF_VAR(nid,"vcov",NF_FLOAT,4,dim4,varid)
+            ierr = NF90_DEF_VAR(nid,"v",NF90_FLOAT,dim4,varid)
+            ierr = NF90_DEF_VAR(nid,"va",NF90_FLOAT,dim4,varid)
+            ierr = NF90_DEF_VAR(nid,"vcov",NF90_FLOAT,dim4,varid)
         ENDIF
 ! Pot. Temperature
         IF (guide_T) THEN
             dim4=(/id_lonv,id_latu,id_lev,id_tim/)
-            ierr = NF_DEF_VAR(nid,"teta",NF_FLOAT,4,dim4,varid)
+            ierr = NF90_DEF_VAR(nid,"teta",NF90_FLOAT,dim4,varid)
         ENDIF
 ! Specific Humidity
         IF (guide_Q) THEN
             dim4=(/id_lonv,id_latu,id_lev,id_tim/)
-            ierr = NF_DEF_VAR(nid,"q",NF_FLOAT,4,dim4,varid)
+            ierr = NF90_DEF_VAR(nid,"q",NF90_FLOAT,dim4,varid)
         ENDIF
         
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/iniacademic.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/iniacademic.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/iniacademic.F90	(revision 4482)
@@ -5,5 +5,5 @@
 
   USE filtreg_mod, ONLY: inifilr
-  USE infotrac,    ONLY: nqtot, niso, tnat, alpha_ideal, iqIsoPha, tracers
+  USE infotrac,    ONLY: nqtot, niso, iqIsoPha, tracers, getKey, isoName
   USE control_mod, ONLY: day_step,planet_type
   use exner_hyb_m, only: exner_hyb
@@ -18,8 +18,11 @@
   USE comconst_mod, ONLY: cpp, kappa, g, daysec, dtvr, pi, im, jm
   USE logic_mod, ONLY: iflag_phys, read_start
-  USE comvert_mod, ONLY: ap, bp, preff, presnivs, pressure_exner
+  USE comvert_mod, ONLY: ap, bp, preff, pa, presnivs, pressure_exner
   USE temps_mod, ONLY: annee_ref, day_ini, day_ref
   USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
   USE readTracFiles_mod, ONLY: addPhase
+  use netcdf, only : NF90_NOWRITE,NF90_OPEN,NF90_NOERR,NF90_INQ_VARID
+  use netcdf, only : NF90_CLOSE, NF90_GET_VAR
+
 
   !   Author:    Frederic Hourdin      original: 15/01/93
@@ -64,4 +67,7 @@
   INTEGER i,j,l,lsup,ij, iq, iName, iPhase, iqParent
 
+  integer :: nid_relief,varid,ierr
+  real, dimension(iip1,jjp1) :: relief
+
   REAL teta0,ttp,delt_y,delt_z,eps ! Constantes pour profil de T
   REAL k_f,k_c_a,k_c_s         ! Constantes de rappel
@@ -73,5 +79,5 @@
   integer idum
 
-  REAL zdtvr
+  REAL zdtvr, tnat, alpha_ideal
   
   character(len=*),parameter :: modname="iniacademic"
@@ -118,19 +124,48 @@
   CALL inifilr
 
+
+  !------------------------------------------------------------------
   ! Initialize pressure and mass field if read_start=.false.
+  !------------------------------------------------------------------
+
   IF (.NOT. read_start) THEN
-     ! surface pressure
-     if (iflag_phys>2) then
-        ! specific value for CMIP5 aqua/terra planets
-        ! "Specify the initial dry mass to be equivalent to
-        !  a global mean surface pressure (101325 minus 245) Pa."
-        ps(:)=101080.  
-     else
-        ! use reference surface pressure
-        ps(:)=preff
+
+     !------------------------------------------------------------------
+     ! Lecture eventuelle d'un fichier de relief interpollee sur la grille
+     ! du modele.
+     ! On suppose que le fichier relief_in.nc est stoké sur une grille
+     ! iim*jjp1
+     ! Facile a créer à partir de la commande
+     ! cdo remapcon,fichier_output_phys.nc Relief.nc relief_in.nc
+     !------------------------------------------------------------------
+
+     relief=0.
+     ierr = NF90_OPEN ('relief_in.nc', NF90_NOWRITE,nid_relief)
+     if (ierr.EQ.NF90_NOERR) THEN
+         ierr=NF90_INQ_VARID(nid_relief,'RELIEF',varid)
+         if (ierr==NF90_NOERR) THEN
+              ierr=NF90_GET_VAR(nid_relief,varid,relief(1:iim,1:jjp1))
+              relief(iip1,:)=relief(1,:)
+         else
+              CALL abort_gcm ('iniacademic','variable RELIEF pas la',1)
+         endif
      endif
+     ierr = NF90_CLOSE (nid_relief)
+
+     !------------------------------------------------------------------
+     ! Initialisation du geopotentiel au sol et de la pression
+     !------------------------------------------------------------------
+
+     print*,'relief=',minval(relief),maxval(relief),'g=',g
+     do j=1,jjp1
+        do i=1,iip1
+           phis((j-1)*iip1+i)=g*relief(i,j)
+        enddo
+     enddo
+     print*,'phis=',minval(phis),maxval(phis),'g=',g
 
      ! ground geopotential
-     phis(:)=0.
+     !phis(:)=0.
+     ps(:)=preff
      CALL pression ( ip1jmp1, ap, bp, ps, p       )
 
@@ -286,5 +321,7 @@
               iqParent = tracers(iq)%iqParent
               IF(tracers(iq)%iso_iZone == 0) THEN
-                 q(:,:,iq) = q(:,:,iqParent)*tnat(iName)*(q(:,:,iqParent)/30.e-3)**(alpha_ideal(iName)-1.)
+                 IF(getKey('tnat', tnat, isoName(iName)) .OR. getKey('alpha', alpha_ideal, isoName(iName))) &
+                    CALL abort_gcm(TRIM(modname), 'missing isotopic parameters', 1)
+                 q(:,:,iq) = q(:,:,iqParent)*tnat*(q(:,:,iqParent)/30.e-3)**(alpha_ideal-1.)
               ELSE
                  q(:,:,iq) = q(:,:,iqIsoPha(iName,iPhase))
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/replay3d.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/replay3d.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/replay3d.F90	(revision 4482)
@@ -170,5 +170,5 @@
 
 CALL suphel
-open(82,file='dump_param.bin',form='unformatted',status='old')
+!open(82,file='dump_param.bin',form='unformatted',status='old')
 
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/vlsplt.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/vlsplt.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/vlsplt.F	(revision 4482)
@@ -184,6 +184,4 @@
             DO ij=iip2,ip1jm-1
                dxqu(ij)=q(ij+1,l,iq)-q(ij,l,iq)
-c              IF(u_m(ij,l).lt.0.) stop'limx n admet pas les U<0'
-c              sigu(ij)=u_m(ij,l)/masse(ij,l,iq)
             ENDDO
             DO ij=iip1+iip1,ip1jm,iip1
@@ -310,5 +308,4 @@
       ENDDO
 #endif
-c	stop
 
 c	go to 9999
@@ -437,5 +434,5 @@
         enddo
       enddo
-      do ifils=1,tracers(iq)%nqChilds
+      do ifils=1,tracers(iq)%nqChildren
         iq2=tracers(iq)%iqDescen(ifils)
         call vlx(Ratio,pente_max,masseq,u_mq,iq2)
@@ -969,5 +966,5 @@
 ! CRisi: appel récursif de l'advection sur les fils.
 ! Il faut faire ça avant d'avoir mis à jour q et masse
-      !write(*,*) 'vlsplt 942: iq,nqChilds(iq)=',iq,nqChilds(iq)
+      !write(*,*) 'vlsplt 942: iq,nqChildren(iq)=',iq,nqChildren(iq)
       do ifils=1,tracers(iq)%nqDescen
         iq2=tracers(iq)%iqDescen(ifils)
@@ -987,5 +984,5 @@
       enddo
         
-      do ifils=1,tracers(iq)%nqChilds
+      do ifils=1,tracers(iq)%nqChildren
         iq2=tracers(iq)%iqDescen(ifils)
         call vlz(Ratio,pente_max,masseq,wq,iq2)
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/vlspltqs.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/vlspltqs.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/vlspltqs.F	(revision 4482)
@@ -248,6 +248,4 @@
             DO ij=iip2,ip1jm-1
                dxqu(ij)=q(ij+1,l,iq)-q(ij,l,iq)
-c              IF(u_m(ij,l).lt.0.) stop'limx n admet pas les U<0'
-c              sigu(ij)=u_m(ij,l)/masse(ij,l,iq)
             ENDDO
             DO ij=iip1+iip1,ip1jm,iip1
@@ -479,5 +477,6 @@
 ! CRisi: appel récursif de l'advection sur les fils.
 ! Il faut faire ça avant d'avoir mis à jour q et masse
-      !write(*,*) 'vlspltqs 326: iq,nqChilds(iq)=',iq,tracers(iq)%nqChilds
+      !write(*,*) 'vlspltqs 326: iq,nqChildren(iq)=',iq,
+!     &                 tracers(iq)%nqChildren
       
       do ifils=1,tracers(iq)%nqDescen
@@ -491,5 +490,5 @@
         enddo
       enddo
-      do ifils=1,tracers(iq)%nqChilds
+      do ifils=1,tracers(iq)%nqChildren
         iq2=tracers(iq)%iqDescen(ifils)
         call vlx(Ratio,pente_max,masseq,u_mq,iq2)
@@ -786,5 +785,6 @@
 ! CRisi: appel récursif de l'advection sur les fils.
 ! Il faut faire ça avant d'avoir mis à jour q et masse
-      !write(*,*) 'vlyqs 689: iq,nqChilds(iq)=',iq,tracers(iq)%nqChilds
+      !write(*,*) 'vlyqs 689: iq,nqChildren(iq)=',iq,
+!     &              tracers(iq)%nqChildren
    
       do ifils=1,tracers(iq)%nqDescen
@@ -797,5 +797,5 @@
         enddo
       enddo
-      do ifils=1,tracers(iq)%nqChilds
+      do ifils=1,tracers(iq)%nqChildren
         iq2=tracers(iq)%iqDescen(ifils)
         !write(*,*) 'vlyqs 783: appel rec de vly, iq2=',iq2
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/wrgrads.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/wrgrads.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d/wrgrads.F	(revision 4482)
@@ -80,6 +80,5 @@
            print*,'nvar  ',nvar(if)
            print*,'vars ',(var(iv,if),iv=1,nvar(if))
-
-           stop
+           CALL abort_gcm("wrgrads","problem",1)
          endif
       endif
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/comvert_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/comvert_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/comvert_mod.F90	(revision 4482)
@@ -10,9 +10,11 @@
 
 PUBLIC :: ap,bp,presnivs,dpres,sig,ds,pa,preff,nivsigs,nivsig, &
-          aps,bps,scaleheight,pseudoalt,disvert_type, pressure_exner
+          aps,bps,scaleheight,pseudoalt,disvert_type, pressure_exner, &
+          presinter
 
 REAL ap(llm+1) ! hybrid pressure contribution at interlayers
 REAL bp (llm+1) ! hybrid sigma contribution at interlayer
 REAL presnivs(llm) ! (reference) pressure at mid-layers
+REAL presinter(llm+1) ! (reference) pressure at interlayers
 REAL dpres(llm)
 REAL sig(llm+1)
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/conf_planete.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/conf_planete.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/conf_planete.F90	(revision 4482)
@@ -30,36 +30,51 @@
 
 !Reference surface pressure (Pa)
-preff=101325.
+! 101080 : specific value for CMIP5 aqua/terra planets
+! "Specify the initial dry mass to be equivalent to
+!  a global mean surface pressure (101325 minus 245) Pa."
+preff=101080.
 CALL getin('preff', preff)
+
 ! Reference pressure at which hybrid coord. become purely pressure
 ! pa=50000.
 pa=preff/2.
 CALL getin('pa', pa)
+
 ! Gravity
 g=9.80665
+
 CALL getin('g',g)
 ! Molar mass of the atmosphere
+
 molmass = 28.9644
 CALL getin('molmass',molmass)
 ! kappa=R/Cp et Cp      
+
 kappa = 2./7.
 CALL getin('kappa',kappa)
+
 cpp=8.3145/molmass/kappa*1000.
 CALL getin('cpp',cpp)
 ! Radius of the planet
+
 rad = 6371229. 
 CALL getin('radius',rad)
+
 ! Length of a standard day (s)
 daysec=86400.
 CALL getin('daysec',daysec)
+
 ! Rotation rate of the planet:
 ! Length of a solar day, in standard days
 daylen = 1.
+
 CALL getin('daylen',daylen)
 ! Number of days (standard) per year:
+
 year_day = 365.25
 CALL getin('year_day',year_day)
 ! Omega
 ! omeg=2.*pi/86400.
+
 omeg=2.*pi/daysec*(1./daylen+1./year_day)
 CALL getin('omeg',omeg)
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/control_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/control_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/control_mod.F90	(revision 4482)
@@ -29,5 +29,4 @@
   INTEGER,SAVE :: ip_ebil_dyn
   LOGICAL,SAVE :: offline
-  CHARACTER(len=4),SAVE :: config_inca
   CHARACTER(len=10),SAVE :: planet_type ! planet type ('earth','mars',...)
   LOGICAL,SAVE :: output_grads_dyn ! output dynamics diagnostics in
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/disvert.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/disvert.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/disvert.F90	(revision 4482)
@@ -11,5 +11,5 @@
   use assert_m, only: assert
   USE comvert_mod, ONLY: ap, bp, aps, bps, nivsigs, nivsig, dpres, presnivs, &
-                         pseudoalt, pa, preff, scaleheight
+                         pseudoalt, pa, preff, scaleheight, presinter
   USE logic_mod, ONLY: ok_strato
 
@@ -35,4 +35,5 @@
 ! dpres(llm)                 !--- PRESSURE DIFFERENCE FOR EACH LAYER
 ! presnivs(llm)              !--- PRESSURE AT EACH MID-LAYER
+! presinter(llm+1)           !--- PRESSURE AT EACH INTERFACE
 ! scaleheight                !--- VERTICAL SCALE HEIGHT            (Earth: 8kms)
 ! nivsig(llm+1)              !--- SIGMA INDEX OF EACH LAYER INTERFACE
@@ -355,4 +356,8 @@
           max(ap(l+1)+bp(l+1)*preff, 1.e-10))
   ENDDO
+  DO l=1, llmp1
+     presinter(l)= ( ap(l)+bp(l)*preff)
+     write(lunout, *)'PRESINTER(', l, ')=', presinter(l)
+  ENDDO
 
   write(lunout, *) trim(modname),': PRESNIVS '
@@ -395,5 +400,5 @@
       ELSE IF(SIGN(f1,f4)/=f1) THEN; x2=xx; f2=f4
       ELSE IF(SIGN(f2,f4)/=f2) THEN; x1=xx; f1=f4
-      ELSE; CALL abort_gcm("ridders",'Algorithm failed (which is odd...')
+      ELSE; CALL abort_gcm("ridders",'Algorithm failed (which is odd...', 1)
       END IF
       IF(ABS(10.*LOG(ABS(x2-x1)))<=1E-5) EXIT       !--- ERROR ON SIG <= 0.01m            
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/grilles_gcm_netcdf_sub.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/grilles_gcm_netcdf_sub.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/grilles_gcm_netcdf_sub.F90	(revision 4482)
@@ -2,13 +2,17 @@
 ! $Id: $
 !
-! This subroutine creates the file grilles_gcm.nc containg longitudes and
-! latitudes in degrees for grid u and v. This subroutine is called from
-! ce0l. This subroutine corresponds to the first 
-! part in the program create_fausse_var.
+! This subroutine creates the grilles_gcm.nc file, containing:
+! -> longitudes and latitudes in degrees for dynamical grids u, v and scalaire,
+! and the following variables added for INCA (informative anyway)
+! -> vertical levels "presnivs"
+! -> mask (land/sea), area (grid), phis=surface geopotential height = phis/g
 !
+! The subroutine is called in dynphy_lonlat/phylmd/ce0l.F90.
+
 SUBROUTINE grilles_gcm_netcdf_sub(masque,phis)
 
   USE comconst_mod, ONLY: cpp, kappa, g, omeg, daysec, rad, pi
   USE comvert_mod, ONLY: presnivs, preff, pa
+  use netcdf, only: nf90_def_var, nf90_int, nf90_float, nf90_put_var
   
   IMPLICIT NONE
@@ -19,32 +23,35 @@
   INCLUDE "netcdf.inc"
 
-
+!======================== 
   REAL,DIMENSION(iip1,jjp1),INTENT(IN)  :: masque ! masque terre/mer
   REAL,DIMENSION(iip1,jjp1),INTENT(IN)  :: phis   ! geopotentiel au sol
 
-  REAL temp(iim+1,jjm+1)
-  ! Attributs netcdf sortie
+  INTEGER status,i,j
+  
+  ! Attributs netcdf output
   INTEGER ncid_out,rcode_out
-  INTEGER out_lonuid,out_lonvid,out_latuid,out_latvid,out_levid
-  INTEGER out_varid
+  
+  INTEGER out_lonuid,out_lonvid,out_latuid,out_latvid
+  INTEGER out_uid,out_vid,out_tempid
   INTEGER out_lonudim,out_lonvdim
-  INTEGER out_latudim,out_latvdim,out_dim(3)
+  INTEGER out_latudim,out_latvdim,out_dim(2)
   INTEGER out_levdim
-
-  INTEGER start(4),COUNT(4)
-
-  INTEGER status,i,j
-  REAL rlatudeg(jjp1),rlatvdeg(jjm),rlevdeg(llm)
+  !
+  INTEGER :: presnivs_id
+  INTEGER :: mask_id,area_id,phis_id
+  !
+  INTEGER start(2),COUNT(2)
+
+  ! Variables
+  REAL rlatudeg(jjp1),rlatvdeg(jjm),rlev(llm)
   REAL rlonudeg(iip1),rlonvdeg(iip1)
-
-  REAL dlon1(iip1),dlon2(iip1),dlat1(jjp1),dlat2(jjp1)
-  REAL acoslat,dxkm,dykm,resol(iip1,jjp1)
-  REAL,DIMENSION(iip1,jjp1)  :: phis_loc
+  REAL uwnd(iip1,jjp1),vwnd(iip1,jjm),temp(iip1,jjp1) 
+  !
   INTEGER masque_int(iip1,jjp1)
-  INTEGER :: phis_id
-  INTEGER :: area_id
-  INTEGER :: mask_id
-  INTEGER :: presnivs_id
-  
+  REAL :: phis_loc(iip1,jjp1)
+  
+  !======================== 
+  ! CALCULATION of latu, latv, lonu, lonv in deg.
+  ! ---------------------------------------------------
   rad = 6400000
   omeg = 7.272205e-05
@@ -64,4 +71,5 @@
      rlatudeg(j)=rlatu(j)*180./pi
   ENDDO
+  
   DO j=1,jjm
      rlatvdeg(j)=rlatv(j)*180./pi
@@ -72,12 +80,31 @@
      rlonvdeg(i)=rlonv(i)*180./pi + 360.
   ENDDO
-
-
-  !  2 ----- OUVERTURE DE LA SORTIE NETCDF
-  ! ---------------------------------------------------
-  ! CREATION OUTPUT
-  ! ouverture fichier netcdf de sortie out
+ 
+  ! CALCULATION of "false" variables on u, v, s grids
+  ! --------------------------------------------------- 
+   DO i=1,iip1
+     DO j=1,jjp1
+        uwnd(i,j)=MOD(i,2)+MOD(j,2)
+        temp(i,j)=MOD(i,2)+MOD(j,2)
+     ENDDO
+     DO j=1,jjm
+        vwnd(i,j)=MOD(i,2)+MOD(j,2)
+     END DO
+  ENDDO  
+
+  ! CALCULATION of local vars for presnivs, mask, sfc. geopot. height
+  ! --------------------------------------------------- 
+  rlev(:) = presnivs(:)
+  phis_loc(:,:) = phis(:,:)/g
+  masque_int(:,:) = nINT(masque(:,:))
+
+
+  ! OPEN output netcdf file
+  !-------------------------
   status=NF_CREATE('grilles_gcm.nc',IOR(NF_CLOBBER,NF_64BIT_OFFSET),ncid_out)
   CALL handle_err(status)
+  
+  ! DEFINE output dimensions
+  !-------------------------
   status=NF_DEF_DIM(ncid_out,'lonu',iim+1,out_lonudim)
   CALL handle_err(status)
@@ -88,166 +115,118 @@
   status=NF_DEF_DIM(ncid_out,'latv',jjm,out_latvdim)
   CALL handle_err(status)
-
-
-  !   Longitudes en u
-  status=NF_DEF_VAR(ncid_out,'lonu',NF_FLOAT,1,out_lonudim, out_lonuid)
+  !
+  status=NF_DEF_DIM(ncid_out,'lev',llm,out_levdim)
+  CALL handle_err(status)
+  
+  ! DEFINE output variables
+  !-------------------------
+  !   Longitudes on "u" dynamical grid
+  status=NF90_DEF_VAR(ncid_out,'lonu',NF90_FLOAT,out_lonudim, out_lonuid)
   CALL handle_err(status)
   status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'units', 12,'degrees_east')
-  status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'long_name',9,'Longitude en u')
-
-  !   Longitudes en v
-  status=NF_DEF_VAR(ncid_out,'lonv',NF_FLOAT,1,out_lonvdim, out_lonvid)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'long_name',19,'Longitude on u grid')
+  !   Longitudes on "v" dynamical grid
+  status=NF90_DEF_VAR(ncid_out,'lonv',NF90_FLOAT,out_lonvdim, out_lonvid)
   CALL handle_err(status)
   status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'units', 12,'degrees_east')
-  status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'long_name', 9,'Longitude en v')
-
-  !   Latitude en u
-  status=NF_DEF_VAR(ncid_out,'latu',NF_FLOAT,1,out_latudim, out_latuid)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'long_name', 19,'Longitude on v grid')
+  !   Latitudes on "u" dynamical grid
+  status=NF90_DEF_VAR(ncid_out,'latu',NF90_FLOAT,out_latudim, out_latuid)
   CALL handle_err(status)
   status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'units', 13,'degrees_north')
-  status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'long_name', 8,'Latitude en u')
-
-  !  Latitude en v
-  status=NF_DEF_VAR(ncid_out,'latv',NF_FLOAT,1,out_latvdim, out_latvid)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'long_name', 18,'Latitude on u grid')
+  !  Latitudes on "v" dynamical grid
+  status=NF90_DEF_VAR(ncid_out,'latv',NF90_FLOAT,out_latvdim, out_latvid)
   CALL handle_err(status)
   status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'units', 13,'degrees_north')
-  status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'long_name', 8,'Latitude en v')
-
-  !   ecriture de la grille u
+  status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'long_name', 18,'Latitude on v grid')
+  !  "u" lat/lon dynamical grid
   out_dim(1)=out_lonudim
   out_dim(2)=out_latudim
-  status=NF_DEF_VAR(ncid_out,'grille_u',NF_FLOAT,2,out_dim, out_varid)
-  CALL handle_err(status)
-  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
-  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name', 16,'Grille aux point u')
-
-  !   ecriture de la grille v
+  status=NF90_DEF_VAR(ncid_out,'grille_u',NF90_FLOAT,out_dim, out_uid)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_uid,'units', 3,'m/s')
+  status=NF_PUT_ATT_TEXT(ncid_out,out_uid,'long_name', 21,'u-wind dynamical grid')
+  !  "v" lat/lon dynamical grid
   out_dim(1)=out_lonvdim
   out_dim(2)=out_latvdim
-  status=NF_DEF_VAR(ncid_out,'grille_v',NF_FLOAT,2,out_dim, out_varid)
-  CALL handle_err(status)
-  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
-  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name', 16,'Grille aux point v')
-
-  !   ecriture de la grille u
+  status=NF90_DEF_VAR(ncid_out,'grille_v',NF90_FLOAT,out_dim, out_vid)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_vid,'units', 3,'m/s')
+  status=NF_PUT_ATT_TEXT(ncid_out,out_vid,'long_name', 21,'v-wind dynamical grid')
+  !  "s" (scalar) lat/lon dynamical grid
   out_dim(1)=out_lonvdim
   out_dim(2)=out_latudim
-  status=NF_DEF_VAR(ncid_out,'grille_s',NF_FLOAT,2,out_dim, out_varid)
-  CALL handle_err(status)
-  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
-  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name',16,'Grille aux point u')
-
-  status=NF_ENDDEF(ncid_out)
-  write(*,*) "COUCOU 6"
-  CALL handle_err(status)
-  ! 5) ----- FERMETURE DES FICHIERS NETCDF------------------
-  ! --------------------------------------------------------
-  ! 3-b- Ecriture de la grille pour la sortie
-  ! rajoute l'ecriture de la grille
-
-#ifdef NC_DOUBLE
-  status=NF_PUT_VARA_DOUBLE(ncid_out,out_lonuid,1,iim+1,rlonudeg)
-  CALL handle_err(status)
-  status=NF_PUT_VARA_DOUBLE(ncid_out,out_lonvid,1,iim+1,rlonvdeg)
-  CALL handle_err(status)
-  status=NF_PUT_VARA_DOUBLE(ncid_out,out_latuid,1,jjm+1,rlatudeg)
-  CALL handle_err(status)
-  status=NF_PUT_VARA_DOUBLE(ncid_out,out_latvid,1,jjm,rlatvdeg)
-  CALL handle_err(status)
-#else
-  status=NF_PUT_VARA_REAL(ncid_out,out_lonuid,1,iim+1,rlonudeg)
-  CALL handle_err(status)
-  status=NF_PUT_VARA_REAL(ncid_out,out_lonvid,1,iim+1,rlonvdeg)
-  CALL handle_err(status)
-  status=NF_PUT_VARA_REAL(ncid_out,out_latuid,1,jjm+1,rlatudeg)
-  CALL handle_err(status)
-  status=NF_PUT_VARA_REAL(ncid_out,out_latvid,1,jjm,rlatvdeg)
-  CALL handle_err(status)
-#endif
-
-  start(1)=1
-  start(2)=1
-  start(3)=1
-  start(4)=1
-
-  COUNT(1)=iim+1
-  COUNT(2)=jjm+1
-  COUNT(3)=1
-  COUNT(4)=1
-
-  DO j=1,jjm+1
-     DO i=1,iim+1
-        temp(i,j)=MOD(i,2)+MOD(j,2)
-     ENDDO
-  ENDDO
-
-#ifdef NC_DOUBLE
-  status=NF_PUT_VARA_DOUBLE(ncid_out,out_varid,start, count,temp)
-  CALL handle_err(status)
-#else
-  status=NF_PUT_VARA_REAL(ncid_out,out_varid,start, count,temp)
-  CALL handle_err(status)
-#endif
-
-  ! On re-ouvre le fichier pour rajouter 4 nouvelles variables necessaire pour INCA
-! lev - phis - aire - mask
-! rlevdeg(:) = presnivs
-  rlevdeg(:) = presnivs(:)
-  phis_loc(:,:) = phis(:,:)/g
-
-! niveaux de pression verticaux
-  status = NF_REDEF (ncid_out)
-  CALL handle_err(status)
-  status=NF_DEF_DIM(ncid_out,'lev',llm,out_levdim)
-  CALL handle_err(status)
-  status=NF_DEF_VAR(ncid_out,'presnivs',NF_FLOAT,1,out_levdim,&
-                    presnivs_id)
-  CALL handle_err(status)
-  
-! fields
+  status=NF90_DEF_VAR(ncid_out,'grille_s',NF90_FLOAT,out_dim, out_tempid)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,out_tempid,'units', 6,'Kelvin')
+  status=NF_PUT_ATT_TEXT(ncid_out,out_tempid,'long_name',21,'scalar dynamical grid')
+  !
+  ! for INCA :
+  ! vertical levels "presnivs"
+  status=NF90_DEF_VAR(ncid_out,'presnivs',NF90_FLOAT,out_levdim, presnivs_id)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,presnivs_id,'units', 2,'Pa')
+  status=NF_PUT_ATT_TEXT(ncid_out,presnivs_id,'long_name',15,'Vertical levels')
+  ! surface geopotential height: named "phis" as the sfc geopotential, is actually phis/g
   out_dim(1)=out_lonvdim
   out_dim(2)=out_latudim
-
-  status = nf_def_var(ncid_out,'phis',NF_FLOAT,2,out_dim,phis_id)
-  CALL handle_err(status)
-  status = nf_def_var(ncid_out,'aire',NF_FLOAT,2,out_dim,area_id)
-  CALL handle_err(status)
-  status = nf_def_var(ncid_out,'mask',NF_INT  ,2,out_dim,mask_id)
-  CALL handle_err(status)
-
-  status=NF_ENDDEF(ncid_out)
-  CALL handle_err(status)
-
-  ! ecriture des variables
-#ifdef NC_DOUBLE
-  status=NF_PUT_VARA_DOUBLE(ncid_out,presnivs_id,1,llm,rlevdeg)
-  CALL handle_err(status)
-#else
-  status=NF_PUT_VARA_REAL(ncid_out,out_levid,1,llm,rlevdeg)
-  CALL handle_err(status)
-#endif
-
-  start(1)=1
-  start(2)=1
-  start(3)=1
-  start(4)=0
+  status = nf90_def_var(ncid_out,'phis',NF90_FLOAT,out_dim,phis_id)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,phis_id,'units', 1,'m')
+  status=NF_PUT_ATT_TEXT(ncid_out,phis_id,'long_name',27,'surface geopotential height')
+  ! gridcell area
+  status = nf90_def_var(ncid_out,'aire',NF90_FLOAT,out_dim,area_id)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,area_id,'units', 2,'m2')
+  status=NF_PUT_ATT_TEXT(ncid_out,area_id,'long_name',13,'gridcell area')
+  ! land-sea mask (nearest integer approx)
+  status = nf90_def_var(ncid_out,'mask',NF90_INT,out_dim,mask_id)
+  CALL handle_err(status)
+  status=NF_PUT_ATT_TEXT(ncid_out,mask_id,'long_name',27,'land-sea mask (nINT approx)')
+  
+  ! END the 'define' mode in netCDF file
+  status=NF_ENDDEF(ncid_out)  
+  CALL handle_err(status)
+  
+  ! WRITE the variables
+  !-------------------------
+  ! 1D : lonu, lonv,latu,latv ; INCA : presnivs
+  status=NF90_PUT_VAR(ncid_out,out_lonuid,rlonudeg,[1],[iip1])
+  CALL handle_err(status)
+  status=NF90_PUT_VAR(ncid_out,out_lonvid,rlonvdeg,[1],[iip1])
+  CALL handle_err(status)
+  status=NF90_PUT_VAR(ncid_out,out_latuid,rlatudeg,[1],[jjp1])
+  CALL handle_err(status)
+  status=NF90_PUT_VAR(ncid_out,out_latvid,rlatvdeg,[1],[jjm])
+  CALL handle_err(status)
+  status=NF90_PUT_VAR(ncid_out,presnivs_id,rlev,[1],[llm])
+  CALL handle_err(status)
+
+  ! 2D : grille_u,grille_v,grille_s ; INCA: phis,aire,mask
+  start(:)=1 
   COUNT(1)=iip1
-  COUNT(2)=jjp1
-  COUNT(3)=1
-  COUNT(4)=0
-
-  status = nf_put_vara_double(ncid_out, phis_id,start,count, phis_loc)
-  CALL handle_err(status)
-  status = nf_put_vara_double(ncid_out, area_id,start,count, aire)
-  CALL handle_err(status)
-  masque_int(:,:) = nINT(masque(:,:))
-  status = nf_put_vara_int(ncid_out, mask_id,start,count,masque_int)
-  CALL handle_err(status)
-  
-  ! fermeture du fichier netcdf
+  
+  COUNT(2)=jjp1  ! for "u" and "s" grids
+  status=NF90_PUT_VAR(ncid_out,out_uid,uwnd,start, count)
+  CALL handle_err(status)
+  COUNT(2)=jjm  ! for "v" grid
+  status=NF90_PUT_VAR(ncid_out,out_vid,vwnd,start, count)
+  CALL handle_err(status) 
+  COUNT(2)=jjp1  ! as "s" grid, for all the following vars
+  status=NF90_PUT_VAR(ncid_out,out_tempid,temp,start, count)
+  CALL handle_err(status)
+  status = nf90_put_var(ncid_out, phis_id, phis_loc,start,count)
+  CALL handle_err(status) 
+  status = nf90_put_var(ncid_out, area_id, aire,start,count)
+  CALL handle_err(status) 
+  status = nf90_put_var(ncid_out, mask_id,masque_int,start,count)
+  CALL handle_err(status)
+  
+  ! CLOSE netcdf file
   CALL ncclos(ncid_out,rcode_out)
+  write(*,*) "END grilles_gcm_netcdf_sub OK"
 
 END SUBROUTINE grilles_gcm_netcdf_sub
-
 
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/infotrac.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/infotrac.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/infotrac.F90	(revision 4482)
@@ -3,10 +3,9 @@
 MODULE infotrac
 
-   USE       strings_mod, ONLY: msg, find, strIdx,  strFind, strParse, dispTable, int2str,  reduceExpr, &
-                          cat, fmsg, test, strTail, strHead, strStack, strReduce, bool2str, maxlen, testFile
-   USE readTracFiles_mod, ONLY: trac_type, readTracersFiles, addPhase, indexUpdate,  nphases, ancestor,  &
-                                isot_type, old2newName,      delPhase,               getKey_init, tran0, &
-                                keys_type, initIsotopes,     getPhase, known_phases, getKey, setGeneration, &
-                                maxTableWidth
+   USE       strings_mod, ONLY: msg, fmsg, maxlen, cat, dispTable, int2str, bool2str, strStack, strParse
+   USE readTracFiles_mod, ONLY: trac_type, readTracersFiles, tracers, setGeneration, itZonIso, nzone, tran0, isoZone, &
+        delPhase, niso, getKey, isot_type, readIsotopesFile, isotope, maxTableWidth, iqIsoPha, nphas, ixIso, isoPhas, &
+        addPhase, iH2O, nbIso,  isoSelect, testTracersFiles, isoKeys, indexUpdate,   isoCheck, nzone, ntiso, isoName, &
+        addKey
    IMPLICIT NONE
 
@@ -14,14 +13,14 @@
 
    !=== FOR TRACERS:
-   PUBLIC :: infotrac_init                                 !--- Initialization of the tracers
-   PUBLIC :: tracers, type_trac, types_trac                !--- Full tracers database, tracers type keyword
+   PUBLIC :: init_infotrac                                 !--- Initialization of the tracers
+   PUBLIC :: tracers, type_trac                            !--- Full tracers database, tracers type keyword
    PUBLIC :: nqtot,   nbtr,   nqo,   nqCO2,   nqtottr      !--- Main dimensions
    PUBLIC :: conv_flg, pbl_flg                             !--- Convection & boundary layer activation keys
 
    !=== FOR ISOTOPES: General
-   PUBLIC :: isotopes,  nbIso                              !--- Derived type, full isotopes families database + nb of families
+   PUBLIC :: isot_type, nbIso                              !--- Derived type, full isotopes families database + nb of families
    PUBLIC :: isoSelect, ixIso                              !--- Isotopes family selection tool + selected family index
    !=== FOR ISOTOPES: Specific to water
-   PUBLIC :: iH2O, tnat, alpha_ideal                       !--- H2O isotopes index, natural abundance, fractionning coeff.
+   PUBLIC :: iH2O                                          !--- H2O isotopes class index
    PUBLIC :: min_qParent, min_qMass, min_ratio             !--- Min. values for various isotopic quantities
    !=== FOR ISOTOPES: Depending on the selected isotopes family
@@ -34,6 +33,4 @@
    !=== FOR BOTH TRACERS AND ISOTOPES
    PUBLIC :: getKey                                        !--- Get a key from "tracers" or "isotope"
-
-   INTERFACE isoSelect; MODULE PROCEDURE isoSelectByIndex, isoSelectByName; END INTERFACE isoSelect
 
 !=== CONVENTIONS FOR TRACERS NUMBERS:
@@ -71,17 +68,17 @@
 !  | phase       | Phases list ("g"as / "l"iquid / "s"olid)             | /           | [g][l][s]              |
 !  | component   | Name(s) of the merged/cumulated section(s)           | /           | coma-separated names   |
-!  | iadv        | Advection scheme number                              | iadv        | 1-20,30 exc. 3-9,15,19 |
 !  | iGeneration | Generation (>=1)                                     | /           |                        |
-!  | isAdvected  | advected tracers flag (.TRUE. if iadv >= 0)          | /           | nqtrue  .TRUE. values  |
-!  | isInPhysics | tracers not extracted from the main table in physics | /           | nqtottr .TRUE. values  |
 !  | iqParent    | Index of the parent tracer                           | iqpere      | 1:nqtot                |
 !  | iqDescen    | Indexes of the childs       (all generations)        | iqfils      | 1:nqtot                |
 !  | nqDescen    | Number of the descendants   (all generations)        | nqdesc      | 1:nqtot                |
-!  | nqChilds    | Number of childs            (1st generation only)    | nqfils      | 1:nqtot                |
+!  | nqChildren  | Number of childs            (1st generation only)    | nqfils      | 1:nqtot                |
+!  | keys        | key/val pairs accessible with "getKey" routine       | /           |                        |
+!  | iadv        | Advection scheme number                              | iadv        | 1,2,10-20(exc.15,19),30|
+!  | isAdvected  | advected tracers flag (.TRUE. if iadv >= 0)          | /           | nqtrue  .TRUE. values  |
+!  | isInPhysics | tracers not extracted from the main table in physics | /           | nqtottr .TRUE. values  |
 !  | iso_iGroup  | Isotopes group index in isotopes(:)                  | /           | 1:nbIso                |
 !  | iso_iName   | Isotope  name  index in isotopes(iso_iGroup)%trac(:) | iso_indnum  | 1:niso                 |
 !  | iso_iZone   | Isotope  zone  index in isotopes(iso_iGroup)%zone(:) | zone_num    | 1:nzone                |
 !  | iso_iPhas   | Isotope  phase index in isotopes(iso_iGroup)%phas(:) | phase_num   | 1:nphas                |
-!  | keys        | key/val pairs accessible with "getKey" routine       | /           |                        |
 !  +-------------+------------------------------------------------------+-------------+------------------------+
 !
@@ -103,40 +100,19 @@
 
    !=== DIMENSIONS OF THE TRACERS TABLES AND OTHER SCALAR VARIABLES
-   INTEGER,                 SAVE :: nqtot,  &                   !--- Tracers nb in dynamics (incl. higher moments + H2O)
-                                    nbtr,   &                   !--- Tracers nb in physics  (excl. higher moments + H2O)
-                                    nqo,    &                   !--- Number of water phases
-                                    nbIso,  &                   !--- Number of available isotopes family
-                                    nqtottr, &                  !--- Number of tracers passed to phytrac (TO BE DELETED ?)
-                                    nqCO2                       !--- Number of tracers of CO2  (ThL)
-   CHARACTER(LEN=maxlen),   SAVE :: type_trac                   !--- Keyword for tracers type(s)
-   CHARACTER(LEN=maxlen),   SAVE, ALLOCATABLE :: types_trac(:)  !--- Keyword for tracers type(s), parsed version
-
-   !=== DERIVED TYPES EMBEDDING MOST INFORMATIONS ABOUT TRACERS AND ISOTOPES FAMILIES
-   TYPE(trac_type), TARGET, SAVE, ALLOCATABLE ::  tracers(:)    !=== TRACERS DESCRIPTORS VECTOR
-   TYPE(isot_type), TARGET, SAVE, ALLOCATABLE :: isotopes(:)    !=== ISOTOPES PARAMETERS VECTOR
-
-   !=== ALIASES FOR CURRENTLY SELECTED ISOTOPES FAMILY OF VARIABLES EMBEDDED IN THE VECTOR "isotopes"
-   TYPE(isot_type),         SAVE, POINTER :: isotope            !--- CURRENTLY SELECTED ISOTOPES FAMILY DESCRIPTOR
-   INTEGER,                 SAVE          :: ixIso, iH2O        !--- Index of the selected isotopes family and H2O family
-   LOGICAL,                 SAVE          :: isoCheck           !--- Flag to trigger the checking routines
-   TYPE(keys_type),         SAVE, POINTER :: isoKeys(:)         !--- ONE SET OF KEYS FOR EACH ISOTOPE (LISTED IN isoName)
-   CHARACTER(LEN=maxlen),   SAVE, POINTER :: isoName(:),   &    !--- ISOTOPES NAMES FOR THE CURRENTLY SELECTED FAMILY
-                                             isoZone(:),   &    !--- TAGGING ZONES  FOR THE CURRENTLY SELECTED FAMILY
-                                             isoPhas            !--- USED PHASES    FOR THE CURRENTLY SELECTED FAMILY
-   INTEGER,                 SAVE          ::  niso, nzone, &    !--- NUMBER OF ISOTOPES, TAGGING ZONES AND PHASES
-                                             nphas, ntiso       !--- NUMBER OF PHASES AND ISOTOPES + ISOTOPIC TAGGING TRACERS
-   INTEGER,                 SAVE, POINTER ::itZonIso(:,:), &    !--- INDEX IN "isoTrac" AS f(tagging zone idx,  isotope idx)
-                                            iqIsoPha(:,:)       !--- INDEX IN "qx"      AS f(isotopic tracer idx, phase idx)
-
-   !=== VARIABLES FOR ISOTOPES INITIALIZATION AND FOR INCA
-   REAL,                SAVE, ALLOCATABLE ::     tnat(:), &     !--- Natural relative abundance of water isotope        (niso)
-                                          alpha_ideal(:)        !--- Ideal fractionning coefficient (for initial state) (niso)
-   INTEGER,             SAVE, ALLOCATABLE :: conv_flg(:), &     !--- Convection     activation ; needed for INCA        (nbtr)
-                                              pbl_flg(:)        !--- Boundary layer activation ; needed for INCA        (nbtr)
+   INTEGER,               SAVE :: nqtot,  &                     !--- Tracers nb in dynamics (incl. higher moments + H2O)
+                                  nbtr,   &                     !--- Tracers nb in physics  (excl. higher moments + H2O)
+                                  nqo,    &                     !--- Number of water phases
+                                  nqtottr, &                    !--- Number of tracers passed to phytrac (TO BE DELETED ?)
+                                  nqCO2                         !--- Number of tracers of CO2  (ThL)
+   CHARACTER(LEN=maxlen), SAVE :: type_trac                     !--- Keyword for tracers type
+
+   !=== VARIABLES FOR INCA
+   INTEGER,               SAVE, ALLOCATABLE :: conv_flg(:), &   !--- Convection     activation ; needed for INCA        (nbtr)
+                                                pbl_flg(:)      !--- Boundary layer activation ; needed for INCA        (nbtr)
 
 CONTAINS
 
-SUBROUTINE infotrac_init
-   USE control_mod, ONLY: planet_type, config_inca
+SUBROUTINE init_infotrac
+   USE control_mod, ONLY: planet_type
 #ifdef REPROBUS
    USE CHEM_REP,    ONLY: Init_chem_rep_trac
@@ -176,21 +152,17 @@
    CHARACTER(LEN=2)      ::   suff(9)                                !--- Suffixes for schemes of order 3 or 4 (Prather)
    CHARACTER(LEN=3)      :: descrq(30)                               !--- Advection scheme description tags
-   CHARACTER(LEN=maxlen) :: msg1                                     !--- String for messages
+   CHARACTER(LEN=maxlen) :: msg1, texp, ttp                          !--- Strings for messages and expanded tracers type
    INTEGER :: fType                                                  !--- Tracers description file type ; 0: none
                                                                      !--- 1/2/3: "traceur.def"/"tracer.def"/"tracer_*.def"
    INTEGER :: nqtrue                                                 !--- Tracers nb from tracer.def (no higher order moments)
    INTEGER :: iad                                                    !--- Advection scheme number
-   INTEGER :: ic, ip, np, iq, jq, it, nt, im, nm, ix, iz, nz, k      !--- Indexes and temporary variables
+   INTEGER :: ic, iq, jq, it, nt, im, nm, iz, k                      !--- Indexes and temporary variables
    LOGICAL :: lerr, ll
    CHARACTER(LEN=1) :: p
    TYPE(trac_type), ALLOCATABLE, TARGET :: ttr(:)
    TYPE(trac_type), POINTER             :: t1, t(:)
-   TYPE(isot_type), POINTER             :: iso
-
-   CHARACTER(LEN=maxlen), ALLOCATABLE :: tnom_0(:), tnom_transp(:)   !--- Tracer short name + transporting fluid name
-   CHARACTER(LEN=maxlen)              :: tchaine
    INTEGER :: ierr
 
-   CHARACTER(LEN=*), PARAMETER :: modname="infotrac_init"
+   CHARACTER(LEN=*), PARAMETER :: modname="init_infotrac"
 !------------------------------------------------------------------------------------------------------------------------------
 ! Initialization :
@@ -202,62 +174,54 @@
     
    CALL msg('type_trac = "'//TRIM(type_trac)//'"', modname)
-   IF(strParse(type_trac, '|', types_trac, n=nt)) CALL abort_gcm(modname,'can''t parse "type_trac = '//TRIM(type_trac)//'"',1)
-
-   !---------------------------------------------------------------------------------------------------------------------------
-   DO it = 1, nt                                                          !--- nt>1=> "type_trac": coma-separated keywords list
-   !---------------------------------------------------------------------------------------------------------------------------
-      !--- MESSAGE ABOUT THE CHOSEN CONFIGURATION
-      msg1 = 'For type_trac = "'//TRIM(types_trac(it))//'":'
-      SELECT CASE(types_trac(it))
-         CASE('inca'); CALL msg(TRIM(msg1)//' coupling with INCA chemistry model, config_inca='//config_inca, modname)
-         CASE('inco'); CALL msg(TRIM(msg1)//' coupling jointly with INCA and CO2 cycle',  modname)
-         CASE('repr'); CALL msg(TRIM(msg1)//' coupling with REPROBUS chemistry model',    modname)
-         CASE('co2i'); CALL msg(TRIM(msg1)//' you have chosen to run with CO2 cycle',     modname)
-         CASE('coag'); CALL msg(TRIM(msg1)//' tracers are treated for COAGULATION tests', modname)
-         CASE('lmdz'); CALL msg(TRIM(msg1)//' tracers are treated in LMDZ only',          modname)
-         CASE DEFAULT; CALL abort_gcm(modname,'type_trac='//TRIM(types_trac(it))//' not possible yet.',1)
-      END SELECT
-
-      !--- COHERENCE TEST BETWEEN "type_trac" AND "config_inca"
-      IF(ANY(['inca', 'inco'] == types_trac(it)) .AND. ALL(['aero', 'aeNP', 'chem'] /= config_inca)) &
-         CALL abort_gcm(modname, 'Incoherence between type_trac and config_inca. Please modify "run.def"',1)
-
-      !--- COHERENCE TEST BETWEEN "type_trac" AND PREPROCESSING KEYS
-      SELECT CASE(types_trac(it))
-         CASE('inca', 'inco')
+
+   !--- MESSAGE ABOUT THE CHOSEN CONFIGURATION
+   msg1 = 'For type_trac = "'//TRIM(type_trac)//'":'
+   SELECT CASE(type_trac)
+      CASE('inca'); CALL msg(TRIM(msg1)//' coupling with INCA chemistry model',        modname)
+      CASE('inco'); CALL msg(TRIM(msg1)//' coupling jointly with INCA and CO2 cycle',  modname)
+      CASE('repr'); CALL msg(TRIM(msg1)//' coupling with REPROBUS chemistry model',    modname)
+      CASE('co2i'); CALL msg(TRIM(msg1)//' you have chosen to run with CO2 cycle',     modname)
+      CASE('coag'); CALL msg(TRIM(msg1)//' tracers are treated for COAGULATION tests', modname)
+      CASE('lmdz'); CALL msg(TRIM(msg1)//' tracers are treated in LMDZ only',          modname)
+      CASE DEFAULT; CALL abort_gcm(modname,'type_trac='//TRIM(type_trac)//' not possible yet.',1)
+   END SELECT
+
+   !--- COHERENCE TEST BETWEEN "type_trac" AND PREPROCESSING KEYS
+   SELECT CASE(type_trac)
+      CASE('inca', 'inco')
 #ifndef INCA
-            CALL abort_gcm(modname, 'You must add cpp key INCA and compile with INCA code', 1)
-#endif
-         CASE('repr')
+         CALL abort_gcm(modname, 'You must add cpp key INCA and compile with INCA code', 1)
+#endif
+      CASE('repr')
 #ifndef REPROBUS
-            CALL abort_gcm(modname, 'You must add cpp key REPROBUS and compile with REPROBUS code', 1)
-#endif
-         CASE('coag')
+         CALL abort_gcm(modname, 'You must add cpp key REPROBUS and compile with REPROBUS code', 1)
+#endif
+      CASE('coag')
 #ifndef CPP_StratAer
-            CALL abort_gcm(modname, 'You must add cpp key StratAer and compile with StratAer code', 1)
-#endif
-      END SELECT
-
-   !---------------------------------------------------------------------------------------------------------------------------
-   END DO
-   !---------------------------------------------------------------------------------------------------------------------------
-
-   !--- DISABLE "config_inca" OPTION FOR A RUN WITHOUT "INCA" IF IT DIFFERS FROM "none"
-   IF(fmsg('Setting config_inca="none" as you do not couple with INCA model', &
-         modname, ALL(types_trac /= 'inca') .AND. ALL(types_trac /= 'inco') .AND. config_inca /= 'none')) config_inca = 'none'
-
-   nqCO2 = 0; IF(ANY(types_trac == 'inco')) nqCO2 = 1
+         CALL abort_gcm(modname, 'You must add cpp key StratAer and compile with StratAer code', 1)
+#endif
+   END SELECT
+
+   nqCO2 = COUNT( [type_trac == 'inco', type_trac == 'co2i'] )
 
 !==============================================================================================================================
 ! 1) Get the numbers of: true (first order only) tracers "nqtrue", water tracers "nqo" (vapor/liquid/solid)
 !==============================================================================================================================
-   IF(readTracersFiles(type_trac, fType, tracers)) CALL abort_gcm(modname, 'problem with tracers file(s)',1)
+   texp = type_trac                                                  !=== EXPANDED VERSION OF "type_trac", WITH "|" SEPARATOR
+   IF(texp == 'inco') texp = 'co2i|inca'
+   IF(texp /= 'lmdz') texp = 'lmdz|'//TRIM(texp)
+
+   !=== DETERMINE THE TYPE OF THE INPUT TRACERS DESCRIPTION FILE
+   IF(testTracersFiles(modname, texp, fType, .TRUE.)) CALL abort_gcm(modname, 'problem with tracers file(s)',1)
+   ttp = type_trac; IF(fType /= 1) ttp = texp
+
+   IF(readTracersFiles(ttp, type_trac == 'repr'))     CALL abort_gcm(modname, 'problem with tracers file(s)',1)
+   !---------------------------------------------------------------------------------------------------------------------------
    IF(fType == 0) CALL abort_gcm(modname, 'Missing tracers file: "traceur.def", "tracer.def" or "tracer_<keyword>.def file.',1)
    !---------------------------------------------------------------------------------------------------------------------------
-   IF(fType == 1 .AND. ANY(['inca','inco'] == type_trac)) THEN       !=== FOUND OLD STYLE INCA "traceur.def" (single type_trac)
+   IF(fType == 1 .AND. ANY(['inca','inco']==type_trac)) THEN         !=== FOUND OLD STYLE INCA "traceur.def"
    !---------------------------------------------------------------------------------------------------------------------------
 #ifdef INCA
-      nqo = SIZE(tracers)
-      IF(nqCO2==1 .AND. nqo==4) nqo = 3                              !--- Force nqo to 3 (ThL)
+      nqo = SIZE(tracers) - nqCO2
       CALL Init_chem_inca_trac(nqINCA)                               !--- Get nqINCA from INCA
       nbtr = nqINCA + nqCO2                                          !--- Number of tracers passed to phytrac
@@ -268,21 +232,28 @@
       CALL init_transport(solsym_inca, conv_flg_inca, pbl_flg_inca, hadv_inca, vadv_inca)
       ALLOCATE(ttr(nqtrue))
-      ttr(1:nqo+nqCO2)                    = tracers
-      ttr(1    :      nqo   )%component   = 'lmdz'
-      ttr(1+nqo:nqCO2+nqo   )%component   = 'co2i'
-      ttr(1+nqo+nqCO2:nqtrue)%component   = 'inca'
-      ttr(1+nqo      :nqtrue)%name        = [('CO2     ', k=1, nqCO2), solsym_inca]
-      ttr(1+nqo+nqCO2:nqtrue)%parent      = tran0
-      ttr(1+nqo+nqCO2:nqtrue)%phase       = 'g'
+      ttr(1:nqo+nqCO2)                  = tracers
+      ttr(1    :      nqo   )%component = 'lmdz'
+      ttr(1+nqo:nqCO2+nqo   )%component = 'co2i'
+      ttr(1+nqo+nqCO2:nqtrue)%component = 'inca'
+      ttr(1+nqo      :nqtrue)%name      = [('CO2     ', k=1, nqCO2), solsym_inca]
+      ttr(1+nqo+nqCO2:nqtrue)%parent    = tran0
+      ttr(1+nqo+nqCO2:nqtrue)%phase     = 'g'
       lerr = getKey('hadv', had, ky=tracers(:)%keys)
       lerr = getKey('vadv', vad, ky=tracers(:)%keys)
-      hadv(1:nqo) = had(:); hadv(nqo+1:nqtrue) = hadv_inca
-      vadv(1:nqo) = vad(:); vadv(nqo+1:nqtrue) = vadv_inca
+      hadv(1:nqo+nqCO2) = had(:); hadv(1+nqo+nqCO2:nqtrue) = hadv_inca
+      vadv(1:nqo+nqCO2) = vad(:); vadv(1+nqo+nqCO2:nqtrue) = vadv_inca
       CALL MOVE_ALLOC(FROM=ttr, TO=tracers)
-      CALL setGeneration(tracers)                                    !--- SET FIELDS %iGeneration, %gen0Name
+      DO iq = 1, nqtrue
+         t1 => tracers(iq)
+         CALL addKey('name',      t1%name,      t1%keys)
+         CALL addKey('component', t1%component, t1%keys)
+         CALL addKey('parent',    t1%parent,    t1%keys)
+         CALL addKey('phase',     t1%phase,     t1%keys)
+      END DO
+      IF(setGeneration(tracers)) CALL abort_gcm(modname,'See above',1) !- SET FIELDS %iGeneration, %gen0Name
       DEALLOCATE(had, hadv_inca, vad, vadv_inca, conv_flg_inca, pbl_flg_inca, solsym_inca)
 #endif
    !---------------------------------------------------------------------------------------------------------------------------
-   ELSE                                                              !=== FOUND NEW STYLE TRACERS CONFIGURATION FILE(S)
+   ELSE                                                              !=== OTHER CASES (OLD OR NEW FORMAT, NO INCA MODULE)
    !---------------------------------------------------------------------------------------------------------------------------
       nqo    =        COUNT(delPhase(tracers(:)%name)     == 'H2O' &
@@ -300,11 +271,9 @@
    !---------------------------------------------------------------------------------------------------------------------------
 
-   CALL getKey_init(tracers)
-
+#ifdef REPROBUS
    !--- Transfert the number of tracers to Reprobus
-#ifdef REPROBUS
    CALL Init_chem_rep_trac(nbtr, nqo, tracers(:)%name)
-#endif
-
+
+#endif
 !==============================================================================================================================
 ! 2) Calculate nqtot, number of tracers needed (greater if advection schemes 20 or 30 have been chosen).
@@ -380,5 +349,5 @@
    CALL MOVE_ALLOC(FROM=ttr, TO=tracers)
 
-   !--- SET FIELDS %iqParent, %nqChilds, %iGeneration, %iqDescen, %nqDescen
+   !--- SET FIELDS %iqParent, %nqChildren, %iGeneration, %iqDescen, %nqDescen
    CALL indexUpdate(tracers)
 
@@ -404,36 +373,7 @@
    END DO
 
-   niso = 0; nzone=0; nphas=nqo; ntiso = 0; isoCheck=.FALSE.
-   IF(initIsotopes(tracers, isotopes)) CALL abort_gcm(modname, 'Problem when reading isotopes parameters', 1)
-   nbIso = SIZE(isotopes)
-   nqtottr = nqtot - COUNT(tracers%gen0Name == 'H2O' .AND. tracers%component == 'lmdz')
-   IF(nbIso/=0) THEN                        !--- ISOTOPES FOUND
-
-      !=== READ PHYSICAL PARAMETERS FROM "isotopes_params.def" FILE SPECIFIC TO WATER ISOTOPES
-      !    DONE HERE, AND NOT ONLY IN "infotrac_phy", BECAUSE SOME PHYSICAL PARAMS ARE NEEDED FOR RESTARTS (tnat, alpha_ideal)
-      CALL getKey_init(tracers, isotopes)
-      IF(isoSelect('H2O')) RETURN           !--- Select water isotopes ; finished if no water isotopes
-      iH2O = ixIso                          !--- Keep track of water family index
-      IF(getKey('tnat' , tnat,        isoName(1:niso))) CALL abort_gcm(modname, 'can''t read "tnat"', 1)
-      IF(getKey('alpha', alpha_ideal, isoName(1:niso))) CALL abort_gcm(modname, 'can''t read "alpha_ideal"', 1)
-
-      !=== MAKE SURE THE MEMBERS OF AN ISOTOPES FAMILY ARE PRESENT IN THE SAME PHASES
-      DO ix = 1, nbIso
-         iso => isotopes(ix)
-         !--- Check whether each isotope and tagging isotopic tracer is present in the same number of phases
-         DO it = 1, iso%ntiso
-            np = SUM([(COUNT(tracers(:)%name == addPhase(iso%trac(it), iso%phase(ip:ip))), ip=1, iso%nphas)])
-            IF(np == iso%nphas) CYCLE
-            WRITE(msg1,'("Found ",i0," phases for ",a," instead of ",i0)')np, TRIM(iso%trac(it)), iso%nphas
-            CALL abort_gcm(modname, msg1, 1)
-         END DO
-         DO it = 1, iso%niso
-            nz = SUM([(COUNT(iso%trac == TRIM(iso%trac(it))//'_'//iso%zone(iz)), iz=1, iso%nzone)])
-            IF(nz == iso%nzone) CYCLE
-            WRITE(msg1,'("Found ",i0," tagging zones for ",a," instead of ",i0)')nz, TRIM(iso%trac(it)), iso%nzone
-            CALL abort_gcm(modname, msg1, 1)
-         END DO
-      END DO
-   END IF
+   !=== READ PHYSICAL PARAMETERS FOR ISOTOPES ; DONE HERE BECAUSE dynetat0 AND iniacademic NEED "tnat" AND "alpha_ideal"
+   niso = 0; nzone = 0; nphas = nqo; ntiso = 0; isoCheck = .FALSE.
+   IF(readIsotopesFile()) CALL abort_gcm(modname, 'Problem when reading isotopes parameters', 1)
 
    !--- Convection / boundary layer activation for all tracers
@@ -442,6 +382,7 @@
 
    !--- Note: nqtottr can differ from nbtr when nmom/=0
-!   IF(COUNT(tracers%iso_iName == 0) - COUNT(delPhase(tracers%name) == 'H2O' .AND. tracers%component == 'lmdz') /= nqtottr) &
-!      CALL abort_gcm('infotrac_init', 'pb dans le calcul de nqtottr', 1)
+   nqtottr = nqtot - COUNT(delPhase(tracers%gen0Name) == 'H2O' .AND. tracers%component == 'lmdz')
+   IF(COUNT(tracers%iso_iName == 0) - COUNT(delPhase(tracers%name) == 'H2O' .AND. tracers%component == 'lmdz') /= nqtottr) &
+      CALL abort_gcm(modname, 'pb dans le calcul de nqtottr', 1)
 
    !=== DISPLAY THE RESULTS
@@ -459,14 +400,14 @@
    CALL msg('Information stored in infotrac :', modname)
    IF(dispTable('isssssssssiiiiiiiii', &
-      ['iq    ', 'name  ', 'lName ', 'gen0N ', 'parent', 'type  ', 'phase ', 'compon', 'isAdv ', 'isPhy ', &
+      ['iq    ', 'name  ', 'lName ', 'gen0N ', 'parent', 'type  ', 'phase ', 'compon', 'isPhy ', 'isAdv ', &
        'iadv  ', 'iGen  ', 'iqPar ', 'nqDes ', 'nqChld', 'iGroup', 'iName ', 'iZone ', 'iPhase'],          &
-      cat(t%name, t%longName, t%gen0Name, t%parent, t%type, t%phase, t%component, bool2str(t%isAdvected),  &
-                                                                                  bool2str(t%isInPhysics)),&
-      cat([(iq, iq=1, nqtot)], t%iadv, t%iGeneration, t%iqParent, t%nqDescen, t%nqChilds, t%iso_iGroup,    &
+      cat(t%name, t%longName, t%gen0Name, t%parent, t%type, t%phase, t%component, bool2str(t%isInPhysics), &
+                                                                                  bool2str(t%isAdvected)), &
+      cat([(iq, iq=1, nqtot)], t%iadv, t%iGeneration, t%iqParent, t%nqDescen, t%nqChildren, t%iso_iGroup,  &
                   t%iso_iName, t%iso_iZone, t%iso_iPhase), nColMax=maxTableWidth, nHead=2, sub=modname))   &
       CALL abort_gcm(modname, "problem with the tracers table content", 1)
    IF(niso > 0) THEN
       CALL msg('Where, for isotopes family "'//TRIM(isotope%parent)//'":', modname)
-      CALL msg('  isoKeys = '//strStack(isoKeys%name), modname)
+      CALL msg('  isoKeys%name = '//strStack(isoKeys%name), modname)
       CALL msg('  isoName = '//strStack(isoName),      modname)
       CALL msg('  isoZone = '//strStack(isoZone),      modname)
@@ -477,50 +418,5 @@
    CALL msg('end', modname)
 
-END SUBROUTINE infotrac_init
-
-
-!==============================================================================================================================
-!=== THE ROUTINE isoSelect IS USED TO SWITCH FROM AN ISOTOPE FAMILY TO ANOTHER: ISOTOPES DEPENDENT PARAMETERS ARE UPDATED
-!     Single generic "isoSelect" routine, using the predefined index of the parent (fast version) or its name (first call).
-!==============================================================================================================================
-LOGICAL FUNCTION isoSelectByName(iName, lVerbose) RESULT(lerr)
-   IMPLICIT NONE
-   CHARACTER(LEN=*),  INTENT(IN)  :: iName
-   LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
-   INTEGER :: iIso
-   LOGICAL :: lV
-   lV = .FALSE.; IF(PRESENT(lVerbose)) lV = lVerbose
-   iIso = strIdx(isotopes(:)%parent, iName)
-   lerr = iIso == 0
-   IF(lerr) THEN
-      niso = 0; ntiso = 0; nzone=0; nphas=nqo; isoCheck=.FALSE.
-      CALL msg('no isotope family named "'//TRIM(iName)//'"', ll=lV)
-      RETURN
-   END IF
-   lerr = isoSelectByIndex(iIso, lV)
-END FUNCTION isoSelectByName
-!==============================================================================================================================
-LOGICAL FUNCTION isoSelectByIndex(iIso, lVerbose) RESULT(lerr)
-   IMPLICIT NONE
-   INTEGER,           INTENT(IN) :: iIso
-   LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
-   LOGICAL :: lv
-   lv = .FALSE.; IF(PRESENT(lVerbose)) lv = lVerbose
-   lerr = .FALSE.
-   IF(iIso == ixIso) RETURN                                          !--- Nothing to do if the index is already OK
-   lerr = iIso<=0 .OR. iIso>nbIso
-   CALL msg('Inconsistent isotopes family index '//TRIM(int2str(iIso))//': should be > 0 and <= '//TRIM(int2str(nbIso))//'"',&
-            ll=lerr .AND. lV)
-   IF(lerr) RETURN
-   ixIso = iIso                                                      !--- Update currently selected family index
-   isotope  => isotopes(ixIso)                                       !--- Select corresponding component
-   isoKeys  => isotope%keys;     niso     = isotope%niso
-   isoName  => isotope%trac;     ntiso    = isotope%ntiso
-   isoZone  => isotope%zone;     nzone    = isotope%nzone
-   isoPhas  => isotope%phase;    nphas    = isotope%nphas
-   itZonIso => isotope%itZonIso; isoCheck = isotope%check
-   iqIsoPha => isotope%iqIsoPha
-END FUNCTION isoSelectByIndex
-!==============================================================================================================================
+END SUBROUTINE init_infotrac
 
 END MODULE infotrac
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/iso_verif_dyn.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/iso_verif_dyn.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3d_common/iso_verif_dyn.F	(revision 4482)
@@ -64,5 +64,5 @@
         function iso_verif_aberrant_nostop
      :           (x,iso,q,err_msg)
-        USE infotrac, ONLY: tnat
+        USE infotrac, ONLY: isoName, getKey
         implicit none
         
@@ -74,5 +74,5 @@
         ! locals
         real qmin,deltaD
-        real deltaDmax,deltaDmin
+        real deltaDmax,deltaDmin,tnat
         parameter (qmin=1e-11)
         parameter (deltaDmax=200.0,deltaDmin=-999.9)
@@ -85,5 +85,10 @@
         ! verifier que HDO est raisonable
          if (q.gt.qmin) then
-             deltaD=(x/q/tnat(iso)-1)*1000
+             IF(getKey('tnat', tnat, isoName(iso))) THEN
+                  err_msg = 'Missing isotopic parameter "tnat"'
+                  iso_verif_aberrant_nostop=1
+                  RETURN
+             END IF
+             deltaD=(x/q/tnat-1)*1000
              if ((deltaD.gt.deltaDmax).or.(deltaD.lt.deltaDmin)) then
                   write(*,*) 'erreur detectee par iso_verif_aberrant:'
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/advtrac_loc.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/advtrac_loc.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/advtrac_loc.F90	(revision 4482)
@@ -161,5 +161,5 @@
          !--------------------------------------------------------------------
 !           WRITE(*,*) 'advtrac 248: iq,q(1721,19,:)=',iq,q(1721,19,:)
-            STOP 'advtrac : appel a vlspltqs :schema non parallelise'
+            CALL abort_gcm("advtrac","appel a vlspltqs :schema non parallelise",1)
 !LF         CALL vlspltqs_p(q(1,1,1),2.,massem,wg,pbarug,pbarvg,dtvr,p,pk,teta )
 
@@ -167,5 +167,5 @@
          CASE(12)  !--- Schema de Frederic Hourdin
          !--------------------------------------------------------------------
-            STOP 'advtrac : appel a vlspltqs :schema non parallelise'
+            CALL abort_gcm("advtrac","appel a vlspltqs :schema non parallelise",1)
             CALL adaptdt(iadv,dtbon,n,pbarug,massem)   ! pas de temps adaptatif
             IF(n > 1) WRITE(*,*) 'WARNING horizontal dt=',dtbon,'dtvr=',dtvr,'n=',n
@@ -177,5 +177,5 @@
          CASE(13)  !--- Pas de temps adaptatif
          !--------------------------------------------------------------------
-            STOP 'advtrac : schema non parallelise'
+            CALL abort_gcm("advtrac","schema non parallelise",1)
             CALL adaptdt(iadv,dtbon,n,pbarug,massem)
             IF(n > 1) WRITE(*,*) 'WARNING horizontal dt=',dtbon,'dtvr=',dtvr,'n=',n
@@ -187,5 +187,5 @@
          CASE(20)  !--- Schema de pente SLOPES
          !--------------------------------------------------------------------
-            STOP 'advtrac : schema non parallelise'
+            CALL abort_gcm("advtrac","schema SLOPES non parallelise",1)
             CALL pentes_ini (q(1,1,iq),wg,massem,pbarug,pbarvg,0)
 
@@ -193,5 +193,5 @@
          CASE(30)  !--- Schema de Prather
          !--------------------------------------------------------------------
-            STOP 'advtrac : schema non parallelise'
+            CALL abort_gcm("advtrac","schema prather non parallelise",1)
             ! Pas de temps adaptatif
             CALL adaptdt(iadv,dtbon,n,pbarug,massem)
@@ -202,5 +202,5 @@
          CASE(11,16,17,18)   !--- Schemas PPM Lin et Rood
          !--------------------------------------------------------------------
-     	    STOP 'advtrac : schema non parallelise'
+            CALL abort_gcm("advtrac","schema PPM non parallelise",1)
             ! Test sur le flux horizontal
             CALL adaptdt(iadv,dtbon,n,pbarug,massem)   ! pas de temps adaptatif
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/bilan_dyn_loc.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/bilan_dyn_loc.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/bilan_dyn_loc.F	(revision 4482)
@@ -231,5 +231,5 @@
            WRITE(lunout,*)'dt_app=',dt_app
            WRITE(lunout,*)'dt_cum=',dt_cum
-           stop
+           CALL abort_gcm("conf_gcmbilan_dyn_loc","stopped",1)
         endif
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/check_isotopes_loc.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/check_isotopes_loc.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/check_isotopes_loc.F90	(revision 4482)
@@ -3,5 +3,5 @@
    USE strings_mod, ONLY: maxlen, msg, strIdx, strStack, int2str, real2str
    USE infotrac,    ONLY: nqtot, niso, nphas, isotope, isoCheck, iqIsoPha, isoSelect, &
-                          ntiso, iH2O, nzone, tracers, isoName,  itZonIso, tnat
+                          ntiso, iH2O, nzone, tracers, isoName,  itZonIso, getKey
    IMPLICIT NONE
    include "dimensions.h"
@@ -11,5 +11,6 @@
    CHARACTER(LEN=maxlen) :: modname, msg1, nm(2)
    INTEGER :: ixt, ipha, k, i, iq, iiso, izon, ieau, iqeau, iqpar
-   INTEGER, ALLOCATABLE :: ix(:)
+   INTEGER, ALLOCATABLE ::   ix(:)
+   REAL,    ALLOCATABLE, SAVE :: tnat(:)         !--- OpenMP shared variable
    REAL    :: xtractot, xiiso, deltaD, q1, q2
    REAL, PARAMETER :: borne     = 1e19,  &
@@ -31,9 +32,10 @@
    IF(first) THEN
 !$OMP MASTER
-      iso_eau = strIdx(isoName,'H2[16]O')
-      iso_HDO = strIdx(isoName,'H[2]HO')
-      iso_O18 = strIdx(isoName,'H2[18]O')
-      iso_O17 = strIdx(isoName,'H2[17]O')
-      iso_HTO = strIdx(isoName,'H[3]HO')
+      iso_eau = strIdx(isoName,'H216O')
+      iso_HDO = strIdx(isoName,'HDO')
+      iso_O18 = strIdx(isoName,'H218O')
+      iso_O17 = strIdx(isoName,'H217O')
+      iso_HTO = strIdx(isoName,'HTO')
+      IF(getKey('tnat', tnat)) CALL abort_gcm(modname, 'missing isotopic parameter', 1)
 !$OMP END MASTER
 !$OMP BARRIER
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/conf_gcm.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/conf_gcm.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/conf_gcm.F90	(revision 4482)
@@ -453,5 +453,5 @@
         write(lunout,*)'conf_gcm: La valeur de clat passee par run.def', &
              ' est differente de celle lue sur le fichier  start '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ENDIF
 
@@ -467,6 +467,6 @@
         write(lunout,*)'conf_gcm: La valeur de grossismx passee par ', &
              'run.def est differente de celle lue sur le fichier  start '
-        STOP
-     ENDIF
+        CALL abort_gcm("conf_gcm","stopped",1)
+      ENDIF
 
      !Config  Key  = grossismy
@@ -481,5 +481,5 @@
         write(lunout,*)'conf_gcm: La valeur de grossismy passee par ', &
              'run.def est differente de celle lue sur le fichier  start '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ENDIF
 
@@ -487,5 +487,5 @@
         write(lunout,*) &
              'conf_gcm: ***  ATTENTION !! grossismx < 1 .   *** '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ELSE
         alphax = 1. - 1./ grossismx
@@ -495,5 +495,5 @@
         write(lunout,*) &
              'conf_gcm: ***  ATTENTION !! grossismy < 1 .   *** '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ELSE
         alphay = 1. - 1./ grossismy
@@ -517,5 +517,5 @@
            write(lunout,*)' *** fxyhypb lu sur le fichier start est ', &
                 'F alors  qu il est  T  sur  run.def  ***'
-           STOP
+           CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ELSE
@@ -524,5 +524,5 @@
            write(lunout,*)' ***  fxyhypb lu sur le fichier start est ', &
                 'T alors  qu il est  F  sur  run.def  ****  '
-           STOP
+           CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ENDIF
@@ -540,5 +540,5 @@
            write(lunout,*)'conf_gcm: La valeur de dzoomx passee par ', &
                 'run.def est differente de celle lue sur le fichier  start '
-           STOP
+           CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ENDIF
@@ -556,5 +556,5 @@
            write(lunout,*)'conf_gcm: La valeur de dzoomy passee par ', &
                 'run.def est differente de celle lue sur le fichier  start '
-           STOP
+           CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ENDIF
@@ -571,5 +571,5 @@
            write(lunout,*)'conf_gcm: La valeur de taux passee par ', &
                 'run.def est differente de celle lue sur le fichier  start '
-           STOP
+           CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ENDIF
@@ -586,5 +586,5 @@
            write(lunout,*)'conf_gcm: La valeur de tauy passee par ', &
                 'run.def est differente de celle lue sur le fichier  start '
-           STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
         ENDIF
      ENDIF
@@ -607,5 +607,5 @@
               write(lunout,*)' *** ysinus lu sur le fichier start est F', &
                    ' alors  qu il est  T  sur  run.def  ***'
-              STOP
+              CALL abort_gcm("conf_gcm","stopped",1)
            ENDIF
         ELSE
@@ -614,5 +614,5 @@
               write(lunout,*)' *** ysinus lu sur le fichier start est T', &
                    ' alors  qu il est  F  sur  run.def  ****  '
-              STOP
+              CALL abort_gcm("conf_gcm","stopped",1)
            ENDIF
         ENDIF
@@ -644,14 +644,4 @@
      type_trac = 'lmdz'
      CALL getin('type_trac',type_trac)
-
-     !Config  Key  = config_inca
-     !Config  Desc = Choix de configuration de INCA
-     !Config  Def  = none
-     !Config  Help = Choix de configuration de INCA :
-     !Config         'none' = sans INCA
-     !Config         'chem' = INCA avec calcul de chemie
-     !Config         'aero' = INCA avec calcul des aerosols 
-     config_inca = 'none'
-     CALL getin('config_inca',config_inca)
 
      !Config  Key  = ok_dynzon 
@@ -725,5 +715,4 @@
      write(lunout,*)' offline = ', offline
      write(lunout,*)' type_trac = ', type_trac
-     write(lunout,*)' config_inca = ', config_inca
      write(lunout,*)' ok_dynzon = ', ok_dynzon 
      write(lunout,*)' ok_dyn_ins = ', ok_dyn_ins 
@@ -765,5 +754,5 @@
      IF( grossismx.LT.1. )  THEN
         write(lunout,*) 'conf_gcm: ***ATTENTION !! grossismx < 1 . *** '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ELSE
         alphax = 1. - 1./ grossismx
@@ -772,5 +761,5 @@
      IF( grossismy.LT.1. )  THEN
         write(lunout,*) 'conf_gcm: ***ATTENTION !! grossismy < 1 . *** '
-        STOP
+        CALL abort_gcm("conf_gcm","stopped",1)
      ELSE
         alphay = 1. - 1./ grossismy
@@ -855,14 +844,4 @@
      type_trac = 'lmdz'
      CALL getin('type_trac',type_trac)
-
-     !Config  Key  = config_inca
-     !Config  Desc = Choix de configuration de INCA
-     !Config  Def  = none
-     !Config  Help = Choix de configuration de INCA :
-     !Config         'none' = sans INCA
-     !Config         'chem' = INCA avec calcul de chemie
-     !Config         'aero' = INCA avec calcul des aerosols 
-     config_inca = 'none'
-     CALL getin('config_inca',config_inca)
 
      !Config  Key  = ok_dynzon 
@@ -1006,5 +985,4 @@
      write(lunout,*)' offline = ', offline
      write(lunout,*)' type_trac = ', type_trac
-     write(lunout,*)' config_inca = ', config_inca
      write(lunout,*)' ok_dynzon = ', ok_dynzon
      write(lunout,*)' ok_dyn_ins = ', ok_dyn_ins 
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/dynetat0_loc.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/dynetat0_loc.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/dynetat0_loc.F90	(revision 4482)
@@ -7,9 +7,9 @@
 !-------------------------------------------------------------------------------
   USE parallel_lmdz
-  USE infotrac,    ONLY: nqtot, tracers, niso, iqIsoPha, tnat, alpha_ideal, iH2O
-  USE strings_mod, ONLY: maxlen, msg, strStack, real2str
+  USE infotrac,    ONLY: nqtot, tracers, niso, iqIsoPha, iH2O, isoName
+  USE strings_mod, ONLY: maxlen, msg, strStack, real2str, int2str, strIdx
   USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQUIRE_DIMENSION, NF90_INQ_VARID, &
                          NF90_CLOSE, NF90_GET_VAR, NF90_INQUIRE_VARIABLE,  NF90_NoErr
-  USE readTracFiles_mod, ONLY: new2oldName
+  USE readTracFiles_mod, ONLY: new2oldH2O, newHNO3, oldHNO3, getKey
   USE control_mod, ONLY: planet_type
   USE assert_eq_m, ONLY: assert_eq
@@ -41,9 +41,10 @@
   CHARACTER(LEN=maxlen) :: mesg, var, modname, oldVar
   INTEGER, PARAMETER :: length=100
-  INTEGER :: iq, fID, vID, idecal, ierr, iqParent, iName, iZone, iPhase
-  REAL    :: time, tab_cntrl(length)               !--- RUN PARAMS TABLE
+  INTEGER :: iq, fID, vID, idecal, ierr, iqParent, iName, iZone, iPhase, ix
+  REAL    :: time, tnat, alpha_ideal, tab_cntrl(length)    !--- RUN PARAMS TABLE
   REAL,             ALLOCATABLE :: vcov_glo(:,:),masse_glo(:,:),   ps_glo(:)
   REAL,             ALLOCATABLE :: ucov_glo(:,:),    q_glo(:,:), phis_glo(:)
   REAL,             ALLOCATABLE :: teta_glo(:,:)
+  LOGICAL :: lSkip, ll
 !-------------------------------------------------------------------------------
   modname="dynetat0_loc"
@@ -151,21 +152,26 @@
 !--- Tracers
   ALLOCATE(q_glo(ip1jmp1,llm))
+  ll = .FALSE.
+#ifdef REPROBUS
+  ll = NF90_INQ_VARID(fID, 'HNO3tot', vID) /= NF90_NoErr                                 !--- DETECT OLD REPRO start.nc FILE
+#endif
   DO iq=1,nqtot
     var = tracers(iq)%name
-    oldVar = new2oldName(var)
-    !--------------------------------------------------------------------------------------------------------------------------
-    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr) THEN                                 !=== REGULAR CASE
+    oldVar = new2oldH2O(var)
+    lSkip = ll .AND. var == 'HNO3'                                                       !--- FORCE "HNO3_g" READING FOR "HNO3"
+#ifdef REPROBUS
+    ix = strIdx(newHNO3, var); IF(ix /= 0) oldVar = oldHNO3(ix)                          !--- REPROBUS HNO3 exceptions
+#endif
+#ifdef INCA
+    IF(var == 'O3') oldVar = 'OX'                                                        !--- DEAL WITH INCA OZONE EXCEPTION
+#endif
+    !--------------------------------------------------------------------------------------------------------------------------
+    IF(NF90_INQ_VARID(fID, var, vID) == NF90_NoErr .AND. .NOT.lSkip) THEN                !=== REGULAR CASE: AVAILABLE VARIABLE
       CALL get_var2(var,q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:)
     !--------------------------------------------------------------------------------------------------------------------------
-    ELSE IF(NF90_INQ_VARID(fID, oldVar, vID) == NF90_NoErr) THEN                         !=== OLD NAME
+    ELSE IF(NF90_INQ_VARID(fID, oldVar, vID) == NF90_NoErr) THEN                         !=== TRY WITH ALTERNATE NAME
       CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to <'//TRIM(oldVar)//'>', modname)
       CALL get_var2(oldVar, q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:)
     !--------------------------------------------------------------------------------------------------------------------------
-#ifdef INCA
-    ELSE IF(NF90_INQ_VARID(fID, 'OX',   vID) == NF90_NoErr .AND. var == 'O3') THEN       !=== INCA: OX INSTEAD OF O3
-      CALL msg('Tracer <O3> is missing => initialized to <OX>', modname)
-      CALL get_var2( 'OX' , q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:)
-    !--------------------------------------------------------------------------------------------------------------------------
-#endif
     ELSE IF(tracers(iq)%iso_iGroup == iH2O .AND. niso > 0) THEN                          !=== WATER ISOTOPES
       iName    = tracers(iq)%iso_iName
@@ -173,6 +179,8 @@
       iqParent = tracers(iq)%iqParent
       IF(tracers(iq)%iso_iZone == 0) THEN
+         IF(getKey('tnat', tnat, isoName(iName)) .OR. getKey('alpha', alpha_ideal, isoName(iName))) &
+            CALL abort_gcm(TRIM(modname), 'missing isotopic parameters', 1)
          CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized with a simplified Rayleigh distillation law.', modname)
-         q(ijb_u:ije_u,:,iq)= q(ijb_u:ije_u,:,iqParent)*tnat(iName)*(q(ijb_u:ije_u,:,iqParent)/30.e-3)**(alpha_ideal(iName)-1.)
+         q(ijb_u:ije_u,:,iq) = q(ijb_u:ije_u,:,iqParent)*tnat*(q(ijb_u:ije_u,:,iqParent)/30.e-3)**(alpha_ideal-1.)
       ELSE
          CALL msg('Tracer <'//TRIM(var)//'> is missing => initialized to its parent isotope concentration.', modname)
@@ -199,10 +207,6 @@
   CHARACTER(LEN=*), INTENT(IN) :: str1, str2
   CHARACTER(LEN=maxlen) :: s1, s2
-  IF(n1/=n2) THEN
-    s1='value of '//TRIM(str1)//' ='
-    s2=' read in starting file differs from parametrized '//TRIM(str2)//' ='
-    WRITE(mesg,'(10x,a,i4,2x,a,i4)')TRIM(ADJUSTL(s1)),n1,TRIM(ADJUSTL(s2)),n2
-    CALL ABORT_gcm(TRIM(modname),TRIM(mesg),1)
-  END IF
+  IF(n1/=n2) CALL abort_gcm(TRIM(modname), 'value of "'//TRIM(str1)//'" = '//TRIM(int2str(n1))// &
+   ' read in starting file differs from gcm value of "'//TRIM(str2)//'" = '//TRIM(int2str(n2)), 1)
 END SUBROUTINE check_dim
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/dynredem_loc.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/dynredem_loc.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/dynredem_loc.F90	(revision 4482)
@@ -176,5 +176,5 @@
   USE mod_hallo
   USE strings_mod, ONLY: maxlen
-  USE infotrac, ONLY: nqtot, tracers, types_trac
+  USE infotrac, ONLY: nqtot, tracers, type_trac
   USE control_mod
   USE netcdf,   ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_GET_VAR, NF90_INQ_VARID,  &
@@ -243,5 +243,5 @@
 !$OMP MASTER
   fil="start_trac.nc"
-  IF(ANY(types_trac=='inca') .OR. ANY(types_trac=='inco')) INQUIRE(FILE=fil,EXIST=lread_inca)
+  IF(ANY(type_trac == ['inca','inco'])) INQUIRE(FILE=fil,EXIST=lread_inca)
   IF(lread_inca) CALL err(NF90_OPEN(fil,NF90_NOWRITE,nid_trac),"open")
 !$OMP END MASTER
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/filtreg_p.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/filtreg_p.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/filtreg_p.F	(revision 4482)
@@ -99,11 +99,12 @@
 c-------------------------------------------------------c
 
-      IF(ifiltre.EQ.1.or.ifiltre.EQ.-1) 
-     &     STOP'Pas de transformee simple dans cette version'
+      IF(ifiltre.EQ.1.or.ifiltre.EQ.-1)
+     & CALL abort_gcm("fitreg_p","Pas de transformee simple 
+     &dans cette version",1)
       
       IF( iter.EQ. 2 )  THEN
          PRINT *,' Pas d iteration du filtre dans cette version !'
      &        , ' Utiliser old_filtreg et repasser !'
-         STOP
+         CALL abort_gcm("fitreg_p","stopped",1)
       ENDIF
 
@@ -111,5 +112,5 @@
          PRINT *,' Cette routine ne calcule le filtre inverse que '
      &        , ' sur la grille des scalaires !'
-         STOP
+         CALL abort_gcm("fitreg_p","stopped",1)
       ENDIF
 
@@ -117,6 +118,6 @@
          PRINT *,' Probleme dans filtreg car ifiltre NE 2 et NE -2'
      &        , ' corriger et repasser !'
-         STOP
-      ENDIF
+         CALL abort_gcm("fitreg_p","stopped",1)
+       ENDIF
 c
 
@@ -127,6 +128,5 @@
       IF( griscal )   THEN
          IF( nlat. NE. jjp1 )  THEN
-            PRINT  1111
-            STOP
+            CALL abort_gcm("fitreg_p","nlat. NE. jjp1",1)
          ELSE
 c     
@@ -146,6 +146,5 @@
       ELSE
          IF( nlat.NE.jjm )  THEN
-            PRINT  2222
-            STOP
+            CALL abort_gcm("fitreg_p","nlat. NE. jjm",1)
          ELSE
 c
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/gcm.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/gcm.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/gcm.F90	(revision 4482)
@@ -11,5 +11,5 @@
   USE mod_const_mpi, ONLY: init_const_mpi
   USE parallel_lmdz
-  USE infotrac, ONLY: nqtot, infotrac_init
+  USE infotrac, ONLY: nqtot, init_infotrac
 !#ifdef CPP_PHYS
 !  USE mod_interface_dyn_phys, ONLY: init_interface_dyn_phys
@@ -182,5 +182,5 @@
 #ifdef CPP_IOIPSL
   if (calend == 'earth_360d') then
-     call ioconf_calendar('360d')
+     call ioconf_calendar('360_day')
      write(lunout,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
      xios_cal_type='d360'
@@ -205,5 +205,5 @@
   !  Choix du nombre de traceurs et du schema pour l'advection
   !  dans fichier traceur.def, par default ou via INCA
-  call infotrac_init
+  call init_infotrac
 
   ! Allocation de la tableau q : champs advectes   
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/guide_loc_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/guide_loc_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/guide_loc_mod.F90	(revision 4482)
@@ -40,4 +40,6 @@
   REAL, PRIVATE, SAVE     :: lon_min_g,lon_max_g
   REAL, PRIVATE, SAVE     :: tau_lon,tau_lat
+
+  REAL, PRIVATE, SAVE     :: plim_guide_BL
 
   REAL, ALLOCATABLE, DIMENSION(:), PRIVATE, SAVE     :: alpha_u,alpha_v 
@@ -118,5 +120,6 @@
     CALL getpar('gamma4',.false.,gamma4,'Zone sans rappel elargie')
     CALL getpar('guide_BL',.true.,guide_BL,'guidage dans C.Lim')
-    
+    CALL getpar('plim_guide_BL',85000.,plim_guide_BL,'BL top presnivs value')
+
 ! Sauvegarde du for�age
     CALL getpar('guide_sav',.false.,guide_sav,'sauvegarde guidage')
@@ -453,5 +456,5 @@
         else
             do l=1,llm
-                alpha_pcor(l)=(1.+tanh((0.85-presnivs(l)/preff)/0.05))/2.
+                alpha_pcor(l)=(1.+tanh(((plim_guide_BL-presnivs(l))/preff)/0.05))/2.
             enddo
         endif
@@ -499,5 +502,5 @@
             write(*,*)trim(modname)//' second pass in advreel at itau=',&
             itau
-            stop
+            CALL abort_gcm("guide_loc_lod","stopped",1)
           ELSE
 !$OMP MASTER
@@ -1526,5 +1529,5 @@
               if (gamma.lt.1.e-5) then
                 write(*,*)trim(modname)//' gamma =',gamma,'<1e-5'
-                stop
+                CALL abort_gcm("guide_loc_mod","stopped",1)
               endif
               gamma=log(0.5)/log(gamma)
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/iniacademic_loc.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/iniacademic_loc.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/iniacademic_loc.F90	(revision 4482)
@@ -5,5 +5,5 @@
 
   USE filtreg_mod, ONLY: inifilr
-  USE infotrac,    ONLY: nqtot, niso, tnat, alpha_ideal, iqIsoPha, tracers
+  USE infotrac,    ONLY: nqtot, niso, iqIsoPha, tracers, getKey, isoName
   USE control_mod, ONLY: day_step,planet_type
   use exner_hyb_m, only: exner_hyb
@@ -19,8 +19,11 @@
   USE comconst_mod, ONLY: cpp, kappa, g, daysec, dtvr, pi, im, jm
   USE logic_mod, ONLY: iflag_phys, read_start
-  USE comvert_mod, ONLY: ap, bp, preff, presnivs, pressure_exner
+  USE comvert_mod, ONLY: ap, bp, preff, pa, presnivs, pressure_exner
   USE temps_mod, ONLY: annee_ref, day_ini, day_ref
   USE ener_mod, ONLY: etot0,ptot0,ztot0,stot0,ang0
   USE readTracFiles_mod, ONLY: addPhase
+  use netcdf, only : NF90_NOWRITE,NF90_OPEN,NF90_NOERR,NF90_INQ_VARID
+  use netcdf, only : NF90_CLOSE, NF90_GET_VAR
+
 
   !   Author:    Frederic Hourdin      original: 15/01/93
@@ -68,4 +71,8 @@
   INTEGER i,j,l,lsup,ij, iq, iName, iPhase, iqParent
 
+  integer :: nid_relief,varid,ierr
+  real, dimension(iip1,jjp1) :: relief
+
+
   REAL teta0,ttp,delt_y,delt_z,eps ! Constantes pour profil de T
   REAL k_f,k_c_a,k_c_s         ! Constantes de rappel
@@ -77,5 +84,5 @@
   integer idum
 
-  REAL zdtvr
+  REAL zdtvr, tnat, alpha_ideal
   
   character(len=*),parameter :: modname="iniacademic"
@@ -126,4 +133,5 @@
     ! allocate global fields:
 !    allocate(vcov_glo(ip1jm,llm))
+
     allocate(ucov_glo(ip1jmp1,llm))
     allocate(teta_glo(ip1jmp1,llm))
@@ -133,16 +141,41 @@
 
      ! surface pressure
-     if (iflag_phys>2) then
-        ! specific value for CMIP5 aqua/terra planets
-        ! "Specify the initial dry mass to be equivalent to
-        !  a global mean surface pressure (101325 minus 245) Pa."
-        ps_glo(:)=101080.  
-     else
-        ! use reference surface pressure
-        ps_glo(:)=preff
+     ps_glo(:)=preff
+
+     !------------------------------------------------------------------
+     ! Lecture eventuelle d'un fichier de relief interpollee sur la grille
+     ! du modele.
+     ! On suppose que le fichier relief_in.nc est stoké sur une grille
+     ! iim*jjp1
+     ! Facile a créer à partir de la commande
+     ! cdo remapcon,fichier_output_phys.nc Relief.nc relief_in.nc
+     !------------------------------------------------------------------
+
+     relief=0.
+     ierr = NF90_OPEN ('relief_in.nc', NF90_NOWRITE,nid_relief)
+     if (ierr.EQ.NF90_NOERR) THEN
+         ierr=NF90_INQ_VARID(nid_relief,'RELIEF',varid)
+         if (ierr==NF90_NOERR) THEN
+              ierr=NF90_GET_VAR(nid_relief,varid,relief(1:iim,1:jjp1))
+              relief(iip1,:)=relief(1,:)
+         else
+              CALL abort_gcm ('iniacademic','variable RELIEF pas la',1)
+         endif
      endif
-
-     ! ground geopotential
-     phis_glo(:)=0.
+     ierr = NF90_CLOSE (nid_relief)
+
+
+     !------------------------------------------------------------------
+     ! Initialisation du geopotentiel au sol et de la pression
+     !------------------------------------------------------------------
+
+     print*,'relief=',minval(relief),maxval(relief),'g=',g
+     do j=1,jjp1
+        do i=1,iip1
+           phis_glo((j-1)*iip1+i)=g*relief(i,j)
+        enddo
+     enddo
+     print*,'phis=',minval(phis),maxval(phis),'g=',g
+
      CALL pression ( ip1jmp1, ap, bp, ps_glo, p       )
      if (pressure_exner) then
@@ -290,6 +323,7 @@
               iqParent = tracers(iq)%iqParent
               IF(tracers(iq)%iso_iZone == 0) THEN
-                 q(ijb_u:ije_u,:,iq) = q(ijb_u:ije_u,:,iqParent)*tnat(iName) &
-                                     *(q(ijb_u:ije_u,:,iqParent)/30.e-3)**(alpha_ideal(iName)-1.)
+                 IF(getKey('tnat', tnat, isoName(iName)) .OR. getKey('alpha', alpha_ideal, isoName(iName))) &
+                    CALL abort_gcm(TRIM(modname), 'missing isotopic parameters', 1)
+                 q(ijb_u:ije_u,:,iq) = q(ijb_u:ije_u,:,iqParent)*tnat*(q(ijb_u:ije_u,:,iqParent)/30.e-3)**(alpha_ideal-1.)
               ELSE
                  q(ijb_u:ije_u,:,iq) = q(ijb_u:ije_u,:,iqIsoPha(iName,iPhase))
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/leapfrog_loc.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/leapfrog_loc.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/leapfrog_loc.F	(revision 4482)
@@ -1519,9 +1519,8 @@
 
 #ifdef INCA
-         if (ANY(types_trac == 'inca') .OR. 
-     &       ANY(types_trac == 'inco')) CALL finalize_inca
+         if (ANY(type_trac == ['inca','inco'])) CALL finalize_inca
 #endif
 #ifdef REPROBUS
-         if (ANY(types_trac == 'repr')) CALL finalize_reprobus
+         if (type_trac == 'repr') CALL finalize_reprobus
 #endif
 
@@ -1569,9 +1568,8 @@
 
 #ifdef INCA
-              if (ANY(types_trac == 'inca') .OR. 
-     &            ANY(types_trac == 'inco')) CALL finalize_inca
+              if (ANY(type_trac == ['inca','inco'])) CALL finalize_inca
 #endif
 #ifdef REPROBUS
-              if (ANY(types_trac == 'repr')) CALL finalize_reprobus
+              if (type_trac == 'repr') CALL finalize_reprobus
 #endif
 
@@ -1737,9 +1735,8 @@
 
 #ifdef INCA
-                 if (ANY(types_trac == 'inca') .OR. 
-     &               ANY(types_trac == 'inco')) CALL finalize_inca
+              if (ANY(type_trac == ['inca','inco'])) CALL finalize_inca
 #endif
 #ifdef REPROBUS
-                 if (ANY(types_trac == 'repr')) CALL finalize_reprobus
+                 if (type_trac == 'repr') CALL finalize_reprobus
 #endif
 
@@ -1845,9 +1842,8 @@
 
 #ifdef INCA
-      if (ANY(types_trac == 'inca') .OR. 
-     &    ANY(types_trac == 'inco')) CALL finalize_inca
+      if (ANY(type_trac == ['inca','inco'])) CALL finalize_inca
 #endif
 #ifdef REPROBUS
-      if (ANY(types_trac == 'repr')) CALL finalize_reprobus
+      if (type_trac == 'repr') CALL finalize_reprobus
 #endif
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/mod_filtreg_p.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/mod_filtreg_p.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/mod_filtreg_p.F	(revision 4482)
@@ -85,4 +85,5 @@
 
       INTEGER :: sdd1_type, sdd2_type
+      CHARACTER (LEN=132) :: abort_message
 
       IF (first) THEN
@@ -103,10 +104,11 @@
 
       IF(ifiltre.EQ.1.or.ifiltre.EQ.-1) 
-     &     STOP'Pas de transformee simple dans cette version'
+     &  CALL abort_gcm("mod_filtreg_p",'Pas de transformee 
+     &simple dans cette version',1)
       
       IF( iter.EQ. 2 )  THEN
          PRINT *,' Pas d iteration du filtre dans cette version !'
      &        , ' Utiliser old_filtreg et repasser !'
-         STOP
+         CALL abort_gcm("mod_filtreg_p","stopped",1)
       ENDIF
 
@@ -114,5 +116,5 @@
          PRINT *,' Cette routine ne calcule le filtre inverse que '
      &        , ' sur la grille des scalaires !'
-         STOP
+         CALL abort_gcm("mod_filtreg_p","stopped",1)
       ENDIF
 
@@ -120,5 +122,5 @@
          PRINT *,' Probleme dans filtreg car ifiltre NE 2 et NE -2'
      &        , ' corriger et repasser !'
-         STOP
+         CALL abort_gcm("mod_filtreg_p","stopped",1)
       ENDIF
 c
@@ -130,6 +132,5 @@
       IF( griscal )   THEN
          IF( nlat. NE. jjp1 )  THEN
-            PRINT  1111
-            STOP
+            CALL abort_gcm("mod_filtreg_p"," nlat. NE. jjp1",1)
          ELSE
 c     
@@ -149,6 +150,5 @@
       ELSE
          IF( nlat.NE.jjm )  THEN
-            PRINT  2222
-            STOP
+            CALL abort_gcm("mod_filtreg_p"," nlat. NE. jjm",1)
          ELSE
 c
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/mod_hallo.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/mod_hallo.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/mod_hallo.F90	(revision 4482)
@@ -154,10 +154,10 @@
     if (Buffer_pos(Index_pos)+Size>MaxBufferSize) then
       print *,'STOP :: La taille de MaxBufferSize dans mod_hallo.F90 est trop petite !!!!'
-      stop
+      CALL abort_gcm("mod_hallo","stopped",1)
     endif
     
     if (Index_pos>=ListSize) then
       print *,'STOP :: La taille de ListSize dans mod_hallo.F90 est trop petite !!!!'
-      stop
+      CALL abort_gcm("mod_hallo","stopped",1)
     endif
      
@@ -1416,5 +1416,5 @@
          IF (.NOT.using_mpi) THEN
            PRINT *,'Erreur, echange MPI en mode sequentiel !!!'
-           STOP
+           CALL abort_gcm("mod_hallo","stopped",1)
          ENDIF
 !         PRINT *,"-------------------------------------------------------------------"
@@ -1459,5 +1459,5 @@
              IF (.NOT.using_mpi) THEN
                PRINT *,'Erreur, echange MPI en mode sequentiel !!!'
-               STOP
+               CALL abort_gcm("mod_hallo","stopped",1)
              ENDIF
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/mod_xios_dyn3dmem.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/mod_xios_dyn3dmem.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/mod_xios_dyn3dmem.F90	(revision 4482)
@@ -29,4 +29,6 @@
      MODULE PROCEDURE writefield_dyn1d_v, writefield_dyn2d_v
   END INTERFACE writefield_dyn_v
+
+     REAL, ALLOCATABLE, SAVE :: NewField_U(:,:,:), NewField_V(:,:,:)
   
 
@@ -63,4 +65,11 @@
 ! 0 Initialisations
      pi = 4. * ATAN (1.)
+! allocation of fields passed to xios
+!$OMP BARRIER
+!$OMP MASTER
+     allocate(NewField_U(iip1, jj_begin:jj_end, llm))
+     allocate(NewField_V(iip1, jj_begin:jj_end, llm))     
+!$OMP END MASTER
+!$OMP BARRIER
 
 ! 1 Context initialisation
@@ -151,10 +160,17 @@
      CHARACTER(LEN=*)   :: name
      REAL, DIMENSION(ij_begin:ij_end,llm) :: Field
-     REAL, DIMENSION(iip1, jj_begin:jj_end,llm) :: NewField
+!     REAL, ALLOCATABLE, SAVE :: NewField(:,:,:)
      INTEGER :: i,j,l, count
 
-!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+!!!!!$OMP BARRIER
+!!!!!$OMP MASTER
+!!!!     allocate(NewField(iip1, jj_begin:jj_end, llm))
+!!!!!$OMP END MASTER
+!!!!!$OMP BARRIER
+
+
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK) 
      DO l = 1, llm
-       NewField(:,jj_begin:jj_end,l)=reshape(Field(ij_begin:ij_end,l),(/iip1,jj_nb/))
+       NewField_U(:,jj_begin:jj_end,l)=reshape(Field(ij_begin:ij_end,l),(/iip1,jj_nb/))
      ENDDO
 !$OMP ENDDO
@@ -162,8 +178,8 @@
 
 !$OMP MASTER
-!!     write(14,*)'iip1,ij_begin,ij_end,llm,jj_begin,jj_end,jj_nb ',iip1,ij_begin,ij_end,llm,jj_begin,jj_end,jj_nb
-
-     CALL xios_send_field(name, NewField)
-!$OMP END MASTER   
+     CALL xios_send_field(name, NewField_U)
+!!!!     DEALLOCATE(NewField)
+!$OMP END MASTER   
+!$OMP BARRIER
   
    END SUBROUTINE  writefield_dyn2d_u
@@ -207,6 +223,12 @@
      CHARACTER(LEN=*)   :: name
      REAL, DIMENSION(ij_begin:ij_end,llm) :: Field
-     REAL, DIMENSION(iip1,  jj_begin:jj_end,llm) :: NewField
+!!!!     REAL, ALLOCATABLE, SAVE :: NewField(:,:,:)
      INTEGER :: l, jje, ije, jjn
+
+!!!!!$OMP BARRIER
+!!!!!$OMP MASTER
+!!!!     allocate(NewField(iip1,  jj_begin:jj_end,llm))
+!!!!!$OMP END MASTER
+!!!!!$OMP BARRIER
 
      IF (pole_sud) THEN
@@ -223,12 +245,14 @@
 !$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
      DO l = 1, llm
-        NewField(:,jj_begin:jje,l)=reshape(Field(ij_begin:ije,l),(/iip1,jjn/))
+        NewField_V(:,jj_begin:jje,l)=reshape(Field(ij_begin:ije,l),(/iip1,jjn/))
      ENDDO
 !$OMP ENDDO
-
 !$OMP BARRIER       
-!$OMP MASTER
-     CALL xios_send_field(name, NewField(:,jj_begin:jje,:))
-!$OMP END MASTER   
+
+!$OMP MASTER
+     CALL xios_send_field(name, NewField_V(:,jj_begin:jje,:))
+!!!!     DEALLOCATE(NewField)
+!$OMP END MASTER   
+!$OMP BARRIER 
   
    END SUBROUTINE  writefield_dyn2d_v
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/parallel_lmdz.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/parallel_lmdz.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/parallel_lmdz.F90	(revision 4482)
@@ -676,5 +676,5 @@
         else
            write(lunout,*)ij  
-        stop 'erreur dans Gather_Field'
+        CALL abort_gcm("parallel_lmdz","erreur dans Gather_Field",1)
         endif
         
@@ -690,5 +690,5 @@
               Recv_count(i)=(min(jj_end_para(i),jjm)-jj_begin_para(i)+1)*ll*iip1
             else
-              stop 'erreur dans Gather_Field'
+              CALL abort_gcm("parallel_lmdz","erreur dans Gather_Field",1)
             endif
                    
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/qminimum_loc.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/qminimum_loc.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/qminimum_loc.F	(revision 4482)
@@ -55,4 +55,6 @@
 c
 
+c$OMP BARRIER
+
       !write(lunout,*) 'qminimum 52: entree'
       IF(first) THEN
@@ -66,10 +68,18 @@
       ije=ij_end
 
-      zx_defau_diag(ijb:ije,:,:)=0.0
-      q_follow(ijb:ije,:,1:2)=q(ijb:ije,:,1:2)  
+      DO k = 1, llm
+c$OMP DO SCHEDULE(STATIC)
+        DO i = ijb, ije
+          zx_defau_diag(i,k,1)=0.0
+          zx_defau_diag(i,k,2)=0.0
+          q_follow(i,k,1)=q(i,k,1)
+          q_follow(i,k,2)=q(i,k,2)
+        ENDDO
+c$OMP END DO NOWAIT
+      ENDDO
 
       !write(lunout,*) 'qminimum 57'
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)       
       DO 1000 k = 1, llm
+c$OMP DO SCHEDULE(STATIC)       
       DO 1040 i = ijb, ije
             if (seuil_liq - q(i,k,iq_liq) .gt. 0.d0 ) then
@@ -82,9 +92,6 @@
             endif
  1040 CONTINUE
+c$OMP END DO NOWAIT
  1000 CONTINUE
-c$OMP END DO NOWAIT
-c$OMP BARRIER
-c --->  SYNCHRO OPENMP ICI
-
 
 c
@@ -113,5 +120,4 @@
 c$OMP END DO NOWAIT
       ENDDO
-c$OMP BARRIER
 
 c
@@ -130,5 +136,5 @@
          ENDIF
       ENDDO
-c$OMP END DO  
+c$OMP END DO NOWAIT 
 !      pompe = SSUM(ije-ijb+1,zx_pump(ijb),1)
 
@@ -162,5 +168,5 @@
         endif !if (zx_pump(i).gt.0.0) then
       enddo !DO i = ijb, ije  
-c$OMP END DO
+c$OMP END DO NOWAIT
 
       ! 2) transfert de vap vers les couches plus hautes
@@ -206,5 +212,5 @@
                    write(*,*) 'q(i,k-1,iqIsoPha(ixt,iq_vap))=',
      :                   q(i,k-1,iqIsoPha(ixt,iq_vap))
-                   stop
+                CALL abort_gcm("qminimum_loc","stopped",1)
                 endif
               endif
@@ -231,5 +237,5 @@
                    write(*,*) 'q(i,k-1,iqIsoPha(ixt,iq_vap))=',
      :                   q(i,k-1,iqIsoPha(ixt,iq_vap))
-                   stop
+                   CALL abort_gcm("qminimum_loc","stopped",1)
                 endif
               endif 
@@ -243,5 +249,5 @@
           endif !if (zx_defau_diag(i,k,iq_vap).gt.0.0) then
         enddo !DO i = 1, ip1jmp1        
-c$OMP END DO
+c$OMP END DO NOWAIT
         enddo !do k=2,llm
 
@@ -272,5 +278,5 @@
           endif !if (zx_defau_diag(i,k,iq_vap).gt.0.0) then
         enddo !DO i = ijb, ije
-c$OMP END DO        
+c$OMP END DO NOWAIT       
        enddo !do k=2,llm  
 
@@ -279,4 +285,6 @@
       endif !if (niso > 0) then
       !write(*,*) 'qminimum 188'
+c$OMP BARRIER
+
 c
       RETURN
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/times.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/times.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/times.F90	(revision 4482)
@@ -55,5 +55,5 @@
     
       if (timer_state(no_timer)/=stopped) then
-        stop 'start_timer :: timer is already running or suspended'
+        CALL abort_gcm("times","start_timer :: timer is already running or suspended",1)
       else
         timer_state(no_timer)=running
@@ -73,5 +73,5 @@
     if (AllTimer_IsActive) then   
       if (timer_state(no_timer)/=running) then
-        stop 'suspend_timer :: timer is not running'
+         CALL abort_gcm("times","suspend_timer :: timer is not running",1)
       else
         timer_state(no_timer)=suspended
@@ -90,5 +90,5 @@
     if (AllTimer_IsActive) then   
       if (timer_state(no_timer)/=suspended) then
-        stop 'resume_timer :: timer is not suspended'
+        CALL abort_gcm("times","resume_timer :: timer is not suspended",1)
       else
         timer_state(no_timer)=running
@@ -110,5 +110,5 @@
        
       if (timer_state(no_timer)/=running) then
-        stop 'stop_timer :: timer is not running'
+        CALL abort_gcm("times","stop_timer :: timer is not running",1)
       else
         timer_state(no_timer)=stopped
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/vlsplt_loc.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/vlsplt_loc.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/vlsplt_loc.F	(revision 4482)
@@ -210,5 +210,4 @@
 c$OMP END DO NOWAIT
 #endif
-c	stop
 
 c	go to 9999
@@ -351,5 +350,5 @@
 c$OMP END DO NOWAIT
       enddo !do ifils=1,tracers(iq)%nqDescen
-      do ifils=1,tracers(iq)%nqChilds
+      do ifils=1,tracers(iq)%nqChildren
         iq2=tracers(iq)%iqDescen(ifils)
         call vlx_loc(Ratio,pente_max,masse,u_mq,ijb_x,ije_x,iq2)
@@ -726,5 +725,5 @@
 ! CRisi: appel récursif de l'advection sur les fils.
 ! Il faut faire ça avant d'avoir mis à jour q et masse
-      !write(*,*) 'vly 689: iq,nqChilds(iq)=',iq,tracers(iq)%nqChilds
+!     write(*,*)'vly 689: iq,nqChildren(iq)=',iq,tracers(iq)%nqChildren
 
       ijb=ij_begin-2*iip1
@@ -761,5 +760,5 @@
       enddo
 
-      do ifils=1,tracers(iq)%nqChilds
+      do ifils=1,tracers(iq)%nqChildren
         iq2=tracers(iq)%iqDescen(ifils)
         call vly_loc(Ratio,pente_max,masse,qbyv,iq2)
@@ -1148,5 +1147,5 @@
 ! CRisi: appel récursif de l'advection sur les fils.
 ! Il faut faire ça avant d'avoir mis à jour q et masse
-      !write(*,*) 'vlsplt 942: iq,nqChilds(iq)=',iq,tracers(iq)%nqChilds
+!     write(*,*)'vlsplt 942: iq,nqChildren(iq)=',iq,tracers(iq)%nqChildren
       do ifils=1,tracers(iq)%nqDescen
         iq2=tracers(iq)%iqDescen(ifils)
@@ -1169,5 +1168,5 @@
 c$OMP BARRIER
 
-      do ifils=1,tracers(iq)%nqChilds
+      do ifils=1,tracers(iq)%nqChildren
         iq2=tracers(iq)%iqDescen(ifils)
         call vlz_loc(Ratio,pente_max,masse,w,ijb_x,ije_x,iq2)
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/vlspltgen_loc.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/vlspltgen_loc.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/vlspltgen_loc.F	(revision 4482)
@@ -1,3 +1,4 @@
-!
+
+!     
 ! $Header$
 !
@@ -259,6 +260,5 @@
 c$OMP END MASTER 
           CASE DEFAULT
-          stop 'vlspltgen_p : schema non parallelise'
-      
+             CALL abort_gcm("vlspltgen_loc","schema non parallelise",1)
         END SELECT
       
@@ -302,6 +302,5 @@
 #endif    
           CASE DEFAULT
-          stop 'vlspltgen_p : schema non parallelise'
-      
+          CALL abort_gcm("vlspltgen_p","schema non parallelise",1)
         END SELECT
       
@@ -346,5 +345,5 @@
           CASE(14); call vlyqs_loc(zq,pente_max,zm,mv,qsat,iq)
           CASE DEFAULT
-          stop 'vlspltgen_p : schema non parallelise'
+          CALL abort_gcm("vlspltgen_p","schema non parallelise",1)
         END SELECT
        
@@ -392,7 +391,7 @@
 c$OMP BARRIER
           CASE DEFAULT
-          stop 'vlspltgen_p : schema non parallelise'
-      
-        END SELECT
+            
+            CALL abort_gcm("vlspltgen_p","schema non parallelise",1)
+         END SELECT
       
       enddo
@@ -429,5 +428,5 @@
 c$OMP BARRIER        
           CASE DEFAULT
-          stop 'vlspltgen_p : schema non parallelise'
+          CALL abort_gcm("vlspltgen_p","schema non parallelise",1)
         END SELECT
       
@@ -466,5 +465,6 @@
           CASE(10); call   vly_loc(zq,pente_max,zm,mv,     iq)
           CASE(14); call vlyqs_loc(zq,pente_max,zm,mv,qsat,iq)
-          CASE DEFAULT; stop 'vlspltgen_p : schema non parallelise'
+          CASE DEFAULT
+             CALL abort_gcm("vlspltgen_p","schema non parallelise",1)
         END SELECT
        
@@ -486,5 +486,6 @@
           CASE(14); call vlxqs_loc(zq,pente_max,zm,mu,
      &                 qsat, ij_begin,ij_end,iq)
-          CASE DEFAULT; stop 'vlspltgen_p : schema non parallelise'
+          CASE DEFAULT
+          CALL abort_gcm("vlspltgen_p","schema non parallelise",1)
         END SELECT
        
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/vlspltqs_loc.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/vlspltqs_loc.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/vlspltqs_loc.F	(revision 4482)
@@ -74,6 +74,4 @@
             DO ij=ijb,ije-1
                dxqu(ij)=q(ij+1,l,iq)-q(ij,l,iq)
-c              IF(u_m(ij,l).lt.0.) stop'limx n admet pas les U<0'
-c              sigu(ij)=u_m(ij,l)/masse(ij,l,iq)
             ENDDO
             DO ij=ijb+iip1-1,ije,iip1
@@ -337,6 +335,6 @@
 ! CRisi: appel recursif de l'advection sur les fils.
 ! Il faut faire ca avant d'avoir mis a jour q et masse
-      !write(*,*) 'vlspltqs 336: iq,ijb_x,nqChilds(iq)=',
-!     &     iq,ijb_x,tracers(iq)%nqChilds
+      !write(*,*) 'vlspltqs 336: iq,ijb_x,nqChildren(iq)=',
+!     &     iq,ijb_x,tracers(iq)%nqChildren
 
       do ifils=1,tracers(iq)%nqDescen
@@ -356,5 +354,5 @@
 c$OMP END DO NOWAIT
       enddo
-      do ifils=1,tracers(iq)%nqChilds
+      do ifils=1,tracers(iq)%nqChildren
         iq2=tracers(iq)%iqDescen(ifils)
         !write(*,*) 'vlxqs 349: on appelle vlx pour iq2=',iq2
@@ -729,5 +727,6 @@
 ! CRisi: appel recursif de l'advection sur les fils.
 ! Il faut faire ca avant d'avoir mis a jour q et masse
-      !write(*,*) 'vlyqs 689: iq,nqChilds(iq)=',iq,tracers(iq)%nqChilds
+!     write(*,*)'vlyqs 689: iq,nqChildren(iq)=',iq,
+!    &             tracers(iq)%nqChildren
       
       ijb=ij_begin-2*iip1
@@ -767,5 +766,5 @@
 c$OMP END DO NOWAIT
       enddo
-      do ifils=1,tracers(iq)%nqChilds
+      do ifils=1,tracers(iq)%nqChildren
         iq2=tracers(iq)%iqDescen(ifils)
         !write(lunout,*) 'vly: appel recursiv vly iq2=',iq2
Index: LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/wrgrads.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/wrgrads.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dyn3dmem/wrgrads.F	(revision 4482)
@@ -76,6 +76,5 @@
            print*,'nvar  ',nvar(if)
            print*,'vars ',(var(iv,if),iv=1,nvar(if))
-
-           stop
+           CALL abort_gcm("wrgrads","problem",1)
          endif
       endif
Index: LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/calfis.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/calfis.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/calfis.F	(revision 4482)
@@ -186,5 +186,5 @@
          write(lunout,*) '  ngridmx  jjm   iim   '
          write(lunout,*) ngridmx,jjm,iim
-         STOP
+         call abort_gcm("calfis", "", 1)
         ENDIF
       ELSE
Index: LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/calfis_loc.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/calfis_loc.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/calfis_loc.F	(revision 4482)
@@ -262,5 +262,5 @@
           write(lunout,*) '  ngridmx  jjm   iim   ' 
           write(lunout,*) ngridmx,jjm,iim
-          STOP
+          call abort_gcm("calfis_loc", "", 1)
         ENDIF
 c$OMP MASTER
@@ -1218,7 +1218,6 @@
 
 #else 
-      write(lunout,*) 
-     & "calfis_p: for now can only work with parallel physics" 
-      stop 
+      call abort_gcm("calfis_loc",
+     & "calfis_p: for now can only work with parallel physics", 1)
 #endif 
 ! of #ifdef CPP_PHYS
Index: LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/gr_dyn_fi.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/gr_dyn_fi.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/gr_dyn_fi.F	(revision 4482)
@@ -22,5 +22,7 @@
 c   -------
 
-      IF(ngrid.NE.2+(jm-2)*(im-1)) STOP 'probleme de dim'
+      IF (ngrid.NE.2+(jm-2)*(im-1)) then
+         call abort_gcm("gr_dyn_fi", 'probleme de dim', 1)
+      end if
 c   traitement des poles
       CALL SCOPY(nfield,pdyn,im*jm,pfi,ngrid)
Index: LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/inigeomphy_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/inigeomphy_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/inigeomphy_mod.F90	(revision 4482)
@@ -25,5 +25,5 @@
   USE nrtype, ONLY: pi
   USE comvert_mod, ONLY: preff, ap, bp, aps, bps, presnivs, &
-                         scaleheight, pseudoalt
+                         scaleheight, pseudoalt, presinter
   USE vertical_layers_mod, ONLY: init_vertical_layers
   IMPLICIT NONE
@@ -233,5 +233,5 @@
   ! copy over preff , ap(), bp(), etc 
   CALL init_vertical_layers(nlayer,preff,scaleheight, &
-                            ap,bp,aps,bps,presnivs,pseudoalt)
+                            ap,bp,aps,bps,presnivs,presinter,pseudoalt)
 
 !$OMP END PARALLEL
Index: LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/ce0l.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/ce0l.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/ce0l.F90	(revision 4482)
@@ -23,5 +23,5 @@
   USE netcdf,         ONLY: NF90_OPEN, NF90_NOWRITE, NF90_CLOSE, NF90_NOERR,    &
          NF90_INQUIRE_DIMENSION, NF90_INQ_DIMID, NF90_INQ_VARID, NF90_GET_VAR
-  USE infotrac,       ONLY: type_trac, infotrac_init
+  USE infotrac,       ONLY: init_infotrac
   USE dimphy,         ONLY: klon
   USE test_disvert_m, ONLY: test_disvert
@@ -108,5 +108,5 @@
   calnd='gregorian'
   SELECT CASE(calend)
-    CASE('earth_360d');CALL ioconf_calendar('360d');   calnd='with 360 days/year'
+    CASE('earth_360d');CALL ioconf_calendar('360_day');   calnd='with 360 days/year'
     CASE('earth_365d');CALL ioconf_calendar('noleap'); calnd='with no leap year'
     CASE('earth_366d');CALL ioconf_calendar('366d');   calnd='with leap years only'
@@ -132,5 +132,5 @@
 
 !--- Tracers initializations
-  CALL infotrac_init()
+  CALL init_infotrac()
 
   CALL inifilr()
Index: LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90	(revision 4482)
@@ -16,5 +16,5 @@
   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: nbtr,nqCO2,tracers,isotopes,type_trac,conv_flg,pbl_flg,nqtottr
+  USE infotrac, ONLY: nbtr, type_trac
 #ifdef CPP_StratAer
   USE infotrac_phy, ONLY: nbtr_bin, nbtr_sulgas, id_OCS_strat, &
@@ -30,5 +30,5 @@
   USE mod_phys_lmdz_omp_data, ONLY: klon_omp
 #endif
-  USE control_mod, ONLY: dayref,anneeref,day_step,nday,offline, iphysiq, config_inca
+  USE control_mod, ONLY: dayref,anneeref,day_step,nday,offline, iphysiq
   USE inifis_mod, ONLY: inifis
   USE time_phylmdz_mod, ONLY: init_time
@@ -137,5 +137,5 @@
 
   ! Initialize tracer names, numbers, etc. for physics
-  CALL init_infotrac_phy(type_trac, tracers, isotopes, nqtottr, nqCO2, pbl_flg, conv_flg)
+  CALL init_infotrac_phy
 
   ! Initializations for Reprobus
@@ -166,5 +166,5 @@
   END IF
 
-  IF (type_trac == 'inca' .OR. type_trac == 'inco') THEN
+  IF (ANY(type_trac == ['inca','inco'])) THEN
 #ifdef INCA
      CALL init_inca_dim_reg(nbp_lon, nbp_lat - 1, &
Index: LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/init_ssrf_m.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/init_ssrf_m.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/init_ssrf_m.F90	(revision 4482)
@@ -3,12 +3,13 @@
 !*******************************************************************************
 
-  USE indice_sol_mod, ONLY: is_ter, is_oce, is_oce, is_lic, epsfra
+  USE indice_sol_mod,     ONLY: is_ter, is_oce, is_oce, is_lic, epsfra
   USE dimphy,             ONLY: klon, zmasq
   USE phys_state_var_mod, ONLY: pctsrf
-  USE geometry_mod, ONLY : longitude_deg, latitude_deg
+  USE geometry_mod,       ONLY : longitude_deg, latitude_deg
   USE grid_atob_m,        ONLY: grille_m
   USE ioipsl,             ONLY: flininfo, flinopen, flinget, flinclo
   USE ioipsl_getin_p_mod, ONLY: getin_p
-  USE comconst_mod, ONLY: im, pi
+  USE comconst_mod,       ONLY: im, pi
+  USE surface_data,       ONLY: landice_opt
 
   CHARACTER(LEN=256), PARAMETER :: icefname="landiceref.nc", icevar="landice"
@@ -58,64 +59,75 @@
 ! Sub-surfaces initialization
 !*******************************************************************************
-!--- Read and interpolate on model T-grid soil fraction and soil ice fraction.
-  CALL flininfo(icefname, iml_lic, jml_lic, llm_tmp, ttm_tmp, fid)
-  ALLOCATE(lat_lic(iml_lic,jml_lic),lon_lic(iml_lic,jml_lic))
-  ALLOCATE(fraclic(iml_lic,jml_lic))
-  CALL flinopen(icefname, .FALSE., iml_lic, jml_lic, llm_tmp,  &
- &               lon_lic, lat_lic, lev, ttm_tmp, itaul, date, dt, fid)
-  CALL flinget(fid, icevar, iml_lic, jml_lic, llm_tmp, ttm_tmp, 1,1, fraclic)
-  CALL flinclo(fid)
-  WRITE(lunout,*)'landice dimensions: iml_lic, jml_lic : ',iml_lic,jml_lic
+  IF (landice_opt .LT. 2) THEN
+     ! Continue with reading landice.nc file
+     WRITE(lunout,*)"Read landice.nc file to attribute is_lic fraction"
 
-  ALLOCATE(dlon_lic(iml_lic),dlat_lic(jml_lic))
-  dlon_lic(:)=lon_lic(:,1); IF(MAXVAL(dlon_lic)>pi) dlon_lic=dlon_lic*pi/180.
-  dlat_lic(:)=lat_lic(1,:); IF(MAXVAL(dlat_lic)>pi) dlat_lic=dlat_lic*pi/180.
-  DEALLOCATE(lon_lic,lat_lic); ALLOCATE(flic_tmp(iip1,jjp1))
-  CALL grille_m(dlon_lic,dlat_lic,fraclic,rlonv(1:iim),rlatu,flic_tmp(1:iim,:))
-  flic_tmp(iip1,:)=flic_tmp(1,:)
-
-!--- To the physical grid
-  pctsrf(:,:) = 0.
-  CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp, pctsrf(:,is_lic))
-  DEALLOCATE(flic_tmp)
-
-!--- Adequation with soil/sea mask
-  WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0. 
-  WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
-  pctsrf(:,is_ter)=zmasq(:)
-  DO ji=1,klon
-    IF(zmasq(ji)>EPSFRA) THEN 
-      IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
-        pctsrf(ji,is_lic)=zmasq(ji)
-        pctsrf(ji,is_ter)=0.
-      ELSE
-        pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
-        IF(pctsrf(ji,is_ter)<EPSFRA) THEN
-          pctsrf(ji,is_ter)=0.
-          pctsrf(ji,is_lic)=zmasq(ji)
-        END IF 
-      END IF 
-    END IF 
-  END DO 
-
-
-  !--- Option no_ter_antartique removes all land fractions souther than 60S.
-  !--- Land ice is set instead of the land fractions on these latitudes.
-  !--- The ocean and sea-ice fractions are not changed.
-  no_ter_antartique=.FALSE.
-  CALL getin_p('no_ter_antartique',no_ter_antartique)
-  WRITE(lunout,*)"no_ter_antartique=",no_ter_antartique
-  IF (no_ter_antartique) THEN
-     ! Remove all land fractions souther than 60S and set land-ice instead
-     WRITE(lunout,*) "Remove land fractions souther than 60deg south by increasing"
-     WRITE(lunout,*) "the continental ice fractions. No land can now be found at Antartic."
-     DO ji=1, klon
-        IF (latitude_deg(ji)<-60.0) THEN
-           pctsrf(ji,is_lic) = pctsrf(ji,is_lic) + pctsrf(ji,is_ter)
-           pctsrf(ji,is_ter) = 0
+     !--- Read and interpolate on model T-grid soil fraction and soil ice fraction.
+     CALL flininfo(icefname, iml_lic, jml_lic, llm_tmp, ttm_tmp, fid)
+     ALLOCATE(lat_lic(iml_lic,jml_lic),lon_lic(iml_lic,jml_lic))
+     ALLOCATE(fraclic(iml_lic,jml_lic))
+     CALL flinopen(icefname, .FALSE., iml_lic, jml_lic, llm_tmp,  &
+          &               lon_lic, lat_lic, lev, ttm_tmp, itaul, date, dt, fid)
+     CALL flinget(fid, icevar, iml_lic, jml_lic, llm_tmp, ttm_tmp, 1,1, fraclic)
+     CALL flinclo(fid)
+     WRITE(lunout,*)'landice dimensions: iml_lic, jml_lic : ',iml_lic,jml_lic
+     
+     ALLOCATE(dlon_lic(iml_lic),dlat_lic(jml_lic))
+     dlon_lic(:)=lon_lic(:,1); IF(MAXVAL(dlon_lic)>pi) dlon_lic=dlon_lic*pi/180.
+     dlat_lic(:)=lat_lic(1,:); IF(MAXVAL(dlat_lic)>pi) dlat_lic=dlat_lic*pi/180.
+     DEALLOCATE(lon_lic,lat_lic); ALLOCATE(flic_tmp(iip1,jjp1))
+     CALL grille_m(dlon_lic,dlat_lic,fraclic,rlonv(1:iim),rlatu,flic_tmp(1:iim,:))
+     flic_tmp(iip1,:)=flic_tmp(1,:)
+     
+     !--- To the physical grid
+     pctsrf(:,:) = 0.
+     CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp, pctsrf(:,is_lic))
+     DEALLOCATE(flic_tmp)
+     
+     !--- Adequation with soil/sea mask
+     WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0. 
+     WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
+     pctsrf(:,is_ter)=zmasq(:)
+     DO ji=1,klon
+        IF(zmasq(ji)>EPSFRA) THEN 
+           IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
+              pctsrf(ji,is_lic)=zmasq(ji)
+              pctsrf(ji,is_ter)=0.
+           ELSE
+              pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
+              IF(pctsrf(ji,is_ter)<EPSFRA) THEN
+                 pctsrf(ji,is_ter)=0.
+                 pctsrf(ji,is_lic)=zmasq(ji)
+              END IF
+           END IF
         END IF
      END DO
+     
+     
+     !--- Option no_ter_antartique removes all land fractions souther than 60S.
+     !--- Land ice is set instead of the land fractions on these latitudes.
+     !--- The ocean and sea-ice fractions are not changed.
+     no_ter_antartique=.FALSE.
+     CALL getin_p('no_ter_antartique',no_ter_antartique)
+     WRITE(lunout,*)"no_ter_antartique=",no_ter_antartique
+     IF (no_ter_antartique) THEN
+        ! Remove all land fractions souther than 60S and set land-ice instead
+        WRITE(lunout,*) "Remove land fractions souther than 60deg south by increasing"
+        WRITE(lunout,*) "the continental ice fractions. No land can now be found at Antartic."
+        DO ji=1, klon
+           IF (latitude_deg(ji)<-60.0) THEN
+              pctsrf(ji,is_lic) = pctsrf(ji,is_lic) + pctsrf(ji,is_ter)
+              pctsrf(ji,is_ter) = 0
+           END IF
+        END DO
+     END IF
+     
+  ELSE
+     ! landice_opt=2 and higher
+     WRITE(lunout,*) 'No landice is attributed is_lic sub-surface because landice_opt=2 or higher.'
+     WRITE(lunout,*) 'This means that the land model will handel land ice as well as all other land areas.'
+     pctsrf(:,is_ter) = zmasq(:)
+     pctsrf(:,is_lic) = 0.0
   END IF
-
 
 !--- Sub-surface ocean and sea ice (sea ice set to zero for start).
Index: LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/limit_netcdf.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/limit_netcdf.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/dynphy_lonlat/phylmd/limit_netcdf.F90	(revision 4482)
@@ -424,5 +424,5 @@
   IF(NF90_GET_ATT(ncid, varid, 'calendar', cal_in)/=NF90_NOERR) THEN
     SELECT CASE(mode)
-      CASE('RUG', 'ALB'); cal_in='360d'
+      CASE('RUG', 'ALB'); cal_in='360_day'
       CASE('SIC', 'SST'); cal_in='gregorian'
     END SELECT
@@ -492,5 +492,5 @@
       !--- DROPPED FOR BCS DATA (FRACTIONS CAN BE HIGHER THAN 1)
       IF(ll.AND.ix_sic/=1.AND.mode=='SIC') &
-        CALL abort_physic(mode,'unrealistic '//TRIM(mode)//' found: '//TRIM(str))
+        CALL abort_physic(mode,'unrealistic '//TRIM(mode)//' found: '//TRIM(str), 1)
 
     END IF
@@ -599,5 +599,5 @@
          CALL pchfe_95(timeyear, champtime(i, j, :), yder, skip, &
               arth(0.5, real(ndays_in) / ndays, ndays), champan(i, j, :), ierr)
-         if (ierr < 0) stop 1
+         if (ierr < 0) call abort_physic("get_2Dfield", "", 1)
          n_extrap = n_extrap + ierr
        END DO
@@ -641,5 +641,5 @@
   ALLOCATE(champo(klon, ndays))
   DO k=1, ndays
-    CALL gr_dyn_fi(1, iip1, jjp1, klon, champan(1, 1, k), champo(1, k))
+    CALL gr_dyn_fi(1, iip1, jjp1, klon, champan(1, 1, k), champo(:, k))
   END DO
   DEALLOCATE(champan)
Index: LMDZ6/branches/LMDZ_ECRad/libf/filtrez/filtreg.F
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/filtrez/filtreg.F	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/filtrez/filtreg.F	(revision 4482)
@@ -71,4 +71,6 @@
 
       INTEGER :: sdd1_type, sdd2_type
+
+      if ( iim == 1 ) return ! no filtre in 2D y-z
 
       IF (first) THEN
Index: LMDZ6/branches/LMDZ_ECRad/libf/filtrez/filtreg_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/filtrez/filtreg_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/filtrez/filtreg_mod.F90	(revision 4482)
@@ -66,4 +66,5 @@
     !-----------------------------------------------------------
     !
+    if ( iim == 1 ) return ! No filtre in 2D y-z
 
     pi       = 2. * ASIN( 1. )
@@ -125,4 +126,5 @@
     !
     colat0  =  MIN( 0.5, dymin/dxmin )
+    ! colat0  =  1.
     !
     IF( .NOT.fxyhypb.AND.ysinus )  THEN
Index: LMDZ6/branches/LMDZ_ECRad/libf/filtrez/mod_fft_wrapper.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/filtrez/mod_fft_wrapper.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/filtrez/mod_fft_wrapper.F90	(revision 4482)
@@ -11,5 +11,6 @@
     INTEGER :: nb
     
-    STOP "wrapper fft : une FFT doit etre specifiee a l'aide d'une clee CPP, sinon utiliser le filtre classique"
+    print *, "wrapper fft : une FFT doit etre specifiee a l'aide d'une clee CPP, sinon utiliser le filtre classique"
+    stop 1
   END SUBROUTINE Init_fft
   
@@ -21,5 +22,6 @@
     COMPLEX,INTENT(INOUT) :: TF_vect(vsize/2+1,nb_vect)
     
-    STOP "wrapper fft : une FFT doit etre specifiee a l'aide d'une clee CPP, sinon utiliser le filtre classique"
+    print *, "wrapper fft : une FFT doit etre specifiee a l'aide d'une clee CPP, sinon utiliser le filtre classique"
+    stop 1
     
   END SUBROUTINE fft_forward
@@ -31,5 +33,6 @@
     COMPLEX,INTENT(IN ) :: TF_vect(vsize/2+1,nb_vect)
   
-    STOP "wrapper fft : une FFT doit etre specifiee a l'aide d'une clee CPP, sinon utiliser le filtre classique"
+    print *, "wrapper fft : une FFT doit etre specifiee a l'aide d'une clee CPP, sinon utiliser le filtre classique"
+    stop 1
     
   END SUBROUTINE fft_backward
Index: LMDZ6/branches/LMDZ_ECRad/libf/grid/dimension/makdim
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/grid/dimension/makdim	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/grid/dimension/makdim	(revision 4482)
@@ -12,5 +12,5 @@
 fi
 
-if (($1 % 8 != 0)) && (( $# == 3 ))
+if ( ( ($1 % 8 != 0)) && (( $# == 3 ) ) || ( $1 == 1 ) )
 then
     echo "The number of longitudes must be a multiple of 8."
Index: LMDZ6/branches/LMDZ_ECRad/libf/misc/readTracFiles_mod.f90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/misc/readTracFiles_mod.f90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/misc/readTracFiles_mod.f90	(revision 4482)
@@ -1,7 +1,6 @@
 MODULE readTracFiles_mod
 
-  USE strings_mod,    ONLY: msg, testFile,  strFind, strStack, strReduce,  strHead, strCount, find, fmsg, reduceExpr, &
-             removeComment, cat, checkList, str2int, strParse, strReplace, strTail, strIdx, maxlen, test, dispTable, get_in
-  USE trac_types_mod, ONLY: trac_type, isot_type, keys_type
+  USE strings_mod,    ONLY: msg, find, get_in, str2int, dispTable, strHead,  strReduce,  strFind, strStack, strIdx, &
+       test, removeComment, cat, fmsg, maxlen, int2str, checkList, strParse, strReplace, strTail, strCount, reduceExpr
 
   IMPLICIT NONE
@@ -9,34 +8,103 @@
   PRIVATE
 
-  PUBLIC :: initIsotopes, maxlen, trac_type, isot_type, keys_type
-  PUBLIC :: readTracersFiles, indexUpdate, setGeneration             !--- TOOLS ASSOCIATED TO TRACERS  DESCRIPTORS
-  PUBLIC :: readIsotopesFile                                         !--- TOOLS ASSOCIATED TO ISOTOPES DESCRIPTORS
-  PUBLIC :: getKey_init, getKey, fGetKey, setDirectKeys              !--- GET/SET KEYS FROM/TO tracers & isotopes
-
-  PUBLIC :: addPhase, new2oldName,  getPhase, &                      !--- FUNCTIONS RELATED TO THE PHASES
-            delPhase, old2newName, getiPhase, &                      !--- + ASSOCIATED VARIABLES
-            known_phases, old_phases, phases_sep, phases_names, nphases
-
-  PUBLIC :: oldH2OIso, newH2OIso                                     !--- NEEDED FOR BACKWARD COMPATIBILITY (OLD traceur.def)
-
-  PUBLIC :: tran0, idxAncestor, ancestor                             !--- GENERATION 0 TRACER + TOOLS FOR GENERATIONS
+  PUBLIC :: maxlen                                              !--- PARAMETER FOR CASUAL STRING LENGTH
+  PUBLIC :: tracers                                             !--- TRACERS  DESCRIPTION DATABASE
+  PUBLIC :: trac_type, setGeneration, indexUpdate               !--- TRACERS  DESCRIPTION ASSOCIATED TOOLS
+  PUBLIC :: testTracersFiles, readTracersFiles                  !--- TRACERS FILES READING ROUTINES
+  PUBLIC :: getKey, fGetKey, fGetKeys, addKey, setDirectKeys    !--- TOOLS TO GET/SET KEYS FROM/TO  tracers & isotopes
+  PUBLIC :: getKeysDBase,    setKeysDBase                       !--- TOOLS TO GET/SET THE DATABASE (tracers & isotopes)
+
+  PUBLIC :: addPhase, getiPhase,  old_phases, phases_sep, &     !--- FUNCTIONS RELATED TO THE PHASES
+   nphases, delPhase, getPhase, known_phases, phases_names      !--- + ASSOCIATED VARIABLES
+
+  PUBLIC :: oldH2OIso, newH2OIso, old2newH2O, new2oldH2O        !--- H2O ISOTOPES BACKWARD COMPATIBILITY (OLD traceur.def)
+  PUBLIC :: oldHNO3,   newHNO3                                  !--- HNO3 REPRO   BACKWARD COMPATIBILITY (OLD start.nc)
+
+  PUBLIC :: tran0, idxAncestor, ancestor                        !--- GENERATION 0 TRACER + TOOLS FOR GENERATIONS
+
+  !=== FOR ISOTOPES: GENERAL
+  PUBLIC :: isot_type, readIsotopesFile, isoSelect              !--- ISOTOPES DESCRIPTION TYPE + READING ROUTINE
+  PUBLIC :: ixIso, nbIso                                        !--- INDEX OF SELECTED ISOTOPES CLASS + NUMBER OF CLASSES
+
+  !=== FOR ISOTOPES: H2O FAMILY ONLY
+  PUBLIC :: iH2O
+
+  !=== FOR ISOTOPES: DEPENDING ON THE SELECTED ISOTOPES CLASS
+  PUBLIC :: isotope, isoKeys                                    !--- SELECTED ISOTOPES DATABASE + ASSOCIATED KEYS
+  PUBLIC :: isoName, isoZone, isoPhas                           !--- ISOTOPES AND TAGGING ZONES NAMES AND PHASES
+  PUBLIC :: niso,    nzone,   nphas,   ntiso                    !---  " " NUMBERS + ISOTOPES AND TAGGING TRACERS NUMBERS
+  PUBLIC :: itZonIso                                            !--- Idx IN isoName(1:niso) = f(tagging idx, isotope idx)
+  PUBLIC :: iqIsoPha                                            !--- Idx IN qx(1:nqtot)     = f(isotope idx,   phase idx)
+  PUBLIC :: isoCheck                                            !--- FLAG TO RUN ISOTOPES CHECKING ROUTINES
+
   PUBLIC :: maxTableWidth
 !------------------------------------------------------------------------------------------------------------------------------
-  TYPE :: dataBase_type                                              !=== TYPE FOR TRACERS SECTION
-    CHARACTER(LEN=maxlen)  :: name                                   !--- Section name
-    TYPE(trac_type), ALLOCATABLE :: trac(:)                          !--- Tracers descriptors
+  TYPE :: keys_type                                        !=== TYPE FOR A SET OF KEYS ASSOCIATED TO AN ELEMENT
+    CHARACTER(LEN=maxlen)              :: name             !--- Tracer name
+    CHARACTER(LEN=maxlen), ALLOCATABLE :: key(:)           !--- Keys string list
+    CHARACTER(LEN=maxlen), ALLOCATABLE :: val(:)           !--- Corresponding values string list
+  END TYPE keys_type
+!------------------------------------------------------------------------------------------------------------------------------
+  TYPE :: trac_type                                        !=== TYPE FOR A SINGLE TRACER NAMED "name"
+    CHARACTER(LEN=maxlen) :: name        = ''              !--- Name of the tracer
+    CHARACTER(LEN=maxlen) :: gen0Name    = ''              !--- First generation ancestor name
+    CHARACTER(LEN=maxlen) :: parent      = ''              !--- Parent name
+    CHARACTER(LEN=maxlen) :: longName    = ''              !--- Long name (with advection scheme suffix)
+    CHARACTER(LEN=maxlen) :: type        = 'tracer'        !--- Type  (so far: 'tracer' / 'tag')
+    CHARACTER(LEN=maxlen) :: phase       = 'g'             !--- Phase ('g'as / 'l'iquid / 's'olid)
+    CHARACTER(LEN=maxlen) :: component   = ''              !--- Coma-separated list of components (Ex: lmdz,inca)
+    INTEGER               :: iGeneration = -1              !--- Generation number (>=0)
+    INTEGER               :: iqParent    = 0               !--- Parent index
+    INTEGER,  ALLOCATABLE :: iqDescen(:)                   !--- Descendants index (in growing generation order)
+    INTEGER               :: nqDescen    = 0               !--- Number of descendants (all generations)
+    INTEGER               :: nqChildren  = 0               !--- Number of children  (first generation)
+    TYPE(keys_type)       :: keys                          !--- <key>=<val> pairs vector
+    INTEGER               :: iadv        = 10              !--- Advection scheme used
+    LOGICAL               :: isAdvected  = .FALSE.         !--- "true" tracers: iadv > 0.   COUNT(isAdvected )=nqtrue
+    LOGICAL               :: isInPhysics = .TRUE.          !--- "true" tracers: in tr_seri. COUNT(isInPhysics)=nqtottr
+    INTEGER               :: iso_iGroup  = 0               !--- Isotopes group index in isotopes(:)
+    INTEGER               :: iso_iName   = 0               !--- Isotope  name  index in isotopes(iso_iGroup)%trac(:)
+    INTEGER               :: iso_iZone   = 0               !--- Isotope  zone  index in isotopes(iso_iGroup)%zone(:)
+    INTEGER               :: iso_iPhase  = 0               !--- Isotope  phase index in isotopes(iso_iGroup)%phase
+  END TYPE trac_type
+!------------------------------------------------------------------------------------------------------------------------------
+  TYPE :: isot_type                                        !=== TYPE FOR AN ISOTOPES FAMILY DESCENDING ON TRACER "parent"
+    CHARACTER(LEN=maxlen)              :: parent           !--- Isotopes family name (parent tracer name ; ex: H2O)
+    LOGICAL                            :: check=.FALSE.    !--- Triggering of the checking routines
+    TYPE(keys_type),       ALLOCATABLE :: keys(:)          !--- Isotopes keys/values pairs list     (length: niso)
+    CHARACTER(LEN=maxlen), ALLOCATABLE :: trac(:)          !--- Isotopes + tagging tracers list     (length: ntiso)
+    CHARACTER(LEN=maxlen), ALLOCATABLE :: zone(:)          !--- Geographic tagging zones names list (length: nzone)
+    CHARACTER(LEN=maxlen)              :: phase = 'g'      !--- Phases list: [g][l][s]              (length: nphas)
+    INTEGER                            :: niso  = 0        !--- Number of isotopes, excluding tagging tracers
+    INTEGER                            :: nzone = 0        !--- Number of geographic tagging zones
+    INTEGER                            :: ntiso = 0        !--- Number of isotopes, including tagging tracers
+    INTEGER                            :: nphas = 0        !--- Number phases
+    INTEGER,               ALLOCATABLE :: iqIsoPha(:,:)    !--- Idx in "tracers(1:nqtot)" = f(name(1:ntiso)),phas)
+                                                           !---        "iqIsoPha" former name: "iqiso"
+    INTEGER,               ALLOCATABLE :: itZonIso(:,:)    !--- Idx in "trac(1:ntiso)" = f(zone, name(1:niso))
+                                                           !---        "itZonIso" former name: "index_trac"
+  END TYPE isot_type
+!------------------------------------------------------------------------------------------------------------------------------
+  TYPE :: dataBase_type                                         !=== TYPE FOR TRACERS SECTION
+    CHARACTER(LEN=maxlen)  :: name                              !--- Section name
+    TYPE(trac_type), ALLOCATABLE :: trac(:)                     !--- Tracers descriptors
   END TYPE dataBase_type
 !------------------------------------------------------------------------------------------------------------------------------
   INTERFACE getKey
-    MODULE PROCEDURE getKeyByName_s1, getKeyByName_i1, getKeyByName_r1, getKeyByName_sm, getKeyByName_im, getKeyByName_rm
+    MODULE PROCEDURE getKeyByName_s1, getKeyByName_s1m, getKeyByName_sm, getKey_sm, &
+                     getKeyByName_i1, getKeyByName_i1m, getKeyByName_im, getKey_im, &
+                     getKeyByName_r1, getKeyByName_r1m, getKeyByName_rm, getKey_rm, &
+                     getKeyByName_l1, getKeyByName_l1m, getKeyByName_lm, getKey_lm
   END INTERFACE getKey
 !------------------------------------------------------------------------------------------------------------------------------
-  INTERFACE fGetKey;       MODULE PROCEDURE fgetKeyByIndex_s1, fgetKeyByName_s1; END INTERFACE fGetKey
+  INTERFACE    isoSelect;  MODULE PROCEDURE  isoSelectByIndex,  isoSelectByName; END INTERFACE isoSelect
+  INTERFACE  old2newH2O;   MODULE PROCEDURE  old2newH2O_1,  old2newH2O_m;        END INTERFACE old2newH2O
+  INTERFACE  new2oldH2O;   MODULE PROCEDURE  new2oldH2O_1,  new2oldH2O_m;        END INTERFACE new2oldH2O
+  INTERFACE fGetKey;       MODULE PROCEDURE fgetKeyIdx_s1, fgetKeyNam_s1;        END INTERFACE fGetKey
   INTERFACE tracersSubset; MODULE PROCEDURE trSubset_Indx, trSubset_Name, trSubset_gen0Name; END INTERFACE tracersSubset
-  INTERFACE idxAncestor;   MODULE PROCEDURE idxAncestor_1, idxAncestor_m; END INTERFACE idxAncestor
-  INTERFACE    ancestor;   MODULE PROCEDURE    ancestor_1,    ancestor_m; END INTERFACE    ancestor
+  INTERFACE idxAncestor;   MODULE PROCEDURE idxAncestor_1, idxAncestor_m, idxAncestor_mt;    END INTERFACE idxAncestor
+  INTERFACE    ancestor;   MODULE PROCEDURE    ancestor_1,    ancestor_m,    ancestor_mt;    END INTERFACE    ancestor
+  INTERFACE      addKey;   MODULE PROCEDURE      addKey_1; END INTERFACE addKey!,      addKey_m,     addKey_mm;     END INTERFACE addKey
   INTERFACE    addPhase;   MODULE PROCEDURE   addPhase_s1,   addPhase_sm,   addPhase_i1,   addPhase_im; END INTERFACE addPhase
-  INTERFACE old2newName;   MODULE PROCEDURE old2newName_1, old2newName_m; END INTERFACE old2newName
-  INTERFACE new2oldName;   MODULE PROCEDURE new2oldName_1, new2oldName_m; END INTERFACE new2oldName
 !------------------------------------------------------------------------------------------------------------------------------
 
@@ -45,24 +113,42 @@
 
   !--- SOME PARAMETERS THAT ARE NOT LIKELY TO CHANGE OFTEN
-  CHARACTER(LEN=maxlen), SAVE      :: tran0        = 'air'           !--- Default transporting fluid
-  CHARACTER(LEN=maxlen), PARAMETER :: old_phases   = 'vlir'          !--- Old phases for water (no separator)
-  CHARACTER(LEN=maxlen), PARAMETER :: known_phases = 'glsr'          !--- Known phases initials
-  INTEGER,               PARAMETER :: nphases=LEN_TRIM(known_phases) !--- Number of phases
-  CHARACTER(LEN=maxlen), SAVE      :: phases_names(nphases) &        !--- Known phases names
-                                = ['gaseous', 'liquid ', 'solid  ', 'cloud  ']
-  CHARACTER(LEN=1), SAVE :: phases_sep  =  '_'                       !--- Phase separator
-  LOGICAL,          SAVE :: tracs_merge = .TRUE.                     !--- Merge/stack tracers lists
-  LOGICAL,          SAVE :: lSortByGen  = .TRUE.                     !--- Sort by growing generation
-
-  !--- KEPT JUST TO MANAGE OLD WATER ISOTOPES NAMES
-  !--- Apart from that context, on limitaion on isotopes names (as long as they have a corresponding line in isotopes_params.def)
-  CHARACTER(LEN=maxlen), SAVE :: oldH2OIso(5) = ['eau',     'HDO',     'O18',     'O17',     'HTO'    ]
-  CHARACTER(LEN=maxlen), SAVE :: newH2OIso(5) = ['H2[16]O', 'H[2]HO ', 'H2[18]O', 'H2[17]O', 'H[3]HO ']
-
-  !=== LOCAL COPIES OF THE TRACERS AND ISOTOPES DESCRIPTORS, USED BY getKey (INITIALIZED IN getKey_init)
+  CHARACTER(LEN=maxlen), SAVE      :: tran0        = 'air'      !--- Default transporting fluid
+  CHARACTER(LEN=maxlen), PARAMETER :: old_phases   = 'vlir'     !--- Old phases for water (no separator)
+  CHARACTER(LEN=maxlen), PARAMETER :: known_phases = 'glsr'     !--- Known phases initials
+  INTEGER, PARAMETER :: nphases = LEN_TRIM(known_phases)        !--- Number of phases
+  CHARACTER(LEN=maxlen), SAVE      :: phases_names(nphases) &   !--- Known phases names
+                                             = ['gaseous', 'liquid ', 'solid  ', 'cloud  ']
+  CHARACTER(LEN=1), SAVE :: phases_sep  =  '_'                  !--- Phase separator
+  LOGICAL,          SAVE :: tracs_merge = .TRUE.                !--- Merge/stack tracers lists
+  LOGICAL,          SAVE :: lSortByGen  = .TRUE.                !--- Sort by growing generation
+  CHARACTER(LEN=maxlen), SAVE :: isoFile = 'isotopes_params.def'!--- Name of the isotopes parameters file
+
+  !--- CORRESPONDANCE BETWEEN OLD AND NEW WATER NAMES
+  CHARACTER(LEN=maxlen), SAVE :: oldH2OIso(5) = ['eau',   'HDO',   'O18',   'O17',   'HTO'  ]
+  CHARACTER(LEN=maxlen), SAVE :: newH2OIso(5) = ['H216O', 'HDO  ', 'H218O', 'H217O', 'HTO  ']
+
+  !--- CORRESPONDANCE BETWEEN OLD AND NEW HNO3 RELATED SPECIES NAMES
+  CHARACTER(LEN=maxlen), SAVE ::   oldHNO3(2) = ['HNO3_g ', 'HNO3   ']
+  CHARACTER(LEN=maxlen), SAVE ::   newHNO3(2) = ['HNO3   ', 'HNO3tot']
+
+  !=== TRACERS AND ISOTOPES DESCRIPTORS, USED BY getKey
   TYPE(trac_type), ALLOCATABLE, TARGET, SAVE ::  tracers(:)
   TYPE(isot_type), ALLOCATABLE, TARGET, SAVE :: isotopes(:)
 
-  INTEGER,    PARAMETER :: maxTableWidth = 192                       !--- Maximum width of a table displayed with "dispTable"
+  !=== ALIASES OF VARIABLES FROM SELECTED ISOTOPES FAMILY EMBEDDED IN "isotope" (isotopes(ixIso))
+  TYPE(isot_type),         SAVE, POINTER :: isotope             !--- CURRENTLY SELECTED ISOTOPES FAMILY DESCRIPTOR
+  INTEGER,                 SAVE          :: ixIso, iH2O         !--- Index of the selected isotopes family and H2O family
+  INTEGER,                 SAVE          :: nbIso               !--- Number of isotopes classes
+  LOGICAL,                 SAVE          :: isoCheck            !--- Flag to trigger the checking routines
+  TYPE(keys_type),         SAVE, POINTER :: isoKeys(:)          !--- ONE SET OF KEYS FOR EACH ISOTOPE (LISTED IN isoName)
+  CHARACTER(LEN=maxlen),   SAVE, POINTER :: isoName(:),   &     !--- ISOTOPES NAMES FOR THE CURRENTLY SELECTED FAMILY
+                                            isoZone(:),   &     !--- TAGGING ZONES  FOR THE CURRENTLY SELECTED FAMILY
+                                            isoPhas             !--- USED PHASES    FOR THE CURRENTLY SELECTED FAMILY
+  INTEGER,                 SAVE          ::  niso, nzone, &     !--- NUMBER OF ISOTOPES, TAGGING ZONES AND PHASES
+                                            nphas, ntiso        !--- NUMBER OF PHASES AND ISOTOPES + ISOTOPIC TAGGING TRACERS
+  INTEGER,                 SAVE, POINTER ::itZonIso(:,:), &     !--- INDEX IN "isoTrac" AS f(tagging zone idx,  isotope idx)
+                                           iqIsoPha(:,:)        !--- INDEX IN "qx"      AS f(isotopic tracer idx, phase idx)
+
+  INTEGER,    PARAMETER :: maxTableWidth = 192                  !--- Maximum width of a table displayed with "dispTable"
   CHARACTER(LEN=maxlen) :: modname
 
@@ -72,5 +158,5 @@
 !==============================================================================================================================
 !=== READ ONE OR SEVERAL TRACER FILES AND FILL A "tr" TRACERS DESCRIPTOR DERIVED TYPE.
-!=== THE RETURN VALUE fType DEPENDS ON WHAT IS FOUND:
+!=== THE RETURNED VALUE fType DEPENDS ON WHAT IS FOUND:
 !===  0: NO ADEQUATE FILE FOUND ; DEFAULT VALUES MUST BE USED
 !===  1: AN "OLD STYLE" TRACERS FILE "traceur.def":
@@ -93,47 +179,27 @@
 !     * If you need to convert a %key/%val pair into a direct-access key, add the corresponding line in "setDirectKeys".
 !==============================================================================================================================
-LOGICAL FUNCTION readTracersFiles(type_trac, fType, tracs) RESULT(lerr)
-!------------------------------------------------------------------------------------------------------------------------------
-  CHARACTER(LEN=*),             INTENT(IN)  :: type_trac              !--- List of components used
-  INTEGER,                      INTENT(OUT) :: fType                  !--- Type of input file found
-  TYPE(trac_type), ALLOCATABLE, INTENT(OUT) :: tracs(:)
+LOGICAL FUNCTION readTracersFiles(type_trac, lRepr) RESULT(lerr)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=*),  INTENT(IN)  :: type_trac                        !--- List of components used
+  LOGICAL, OPTIONAL, INTENT(IN)  :: lRepr                            !--- Activate the HNNO3 exceptions for REPROBUS
   CHARACTER(LEN=maxlen),  ALLOCATABLE :: s(:), sections(:), trac_files(:)
-  CHARACTER(LEN=maxlen) :: str, fname, mesg
-  INTEGER               :: is, nsec, ierr, it, ntrac, ns, ip, ix
-  LOGICAL, ALLOCATABLE  :: ll(:), lGen3(:)
+  CHARACTER(LEN=maxlen) :: str, fname, tname, pname, cname
+  INTEGER               :: nsec, ierr, it, ntrac, ns, ip, ix, fType
+  LOGICAL :: lRep
+  TYPE(keys_type), POINTER :: k
 !------------------------------------------------------------------------------------------------------------------------------
   lerr = .FALSE.
   modname = 'readTracersFiles'
   IF(.NOT.ALLOCATED(dBase)) ALLOCATE(dBase(0))
-
-  !--- Required sections + corresponding files names (new style single section case)
-  IF(test(strParse(type_trac, '|', sections), lerr)) RETURN          !--- Parse "type_trac" list
-
-  nsec = SIZE(sections, DIM=1)
-  ALLOCATE(trac_files(nsec)); DO is=1, nsec; trac_files(is) = 'tracer_'//TRIM(sections(is))//'.def'; END DO
-
-  !--- LOOK AT AVAILABLE FILES
-  ll = .NOT.testFile(trac_files)
-  fType = 0
-  IF(.NOT.testFile('traceur.def') .AND. nsec==1) fType = 1           !--- OLD STYLE FILE
-  IF(.NOT.testFile('tracer.def'))                fType = 2           !--- NEW STYLE ; SINGLE  FILE, SEVERAL SECTIONS
-  IF(ALL(ll))                                    fType = 3           !--- NEW STYLE ; SEVERAL FILES, SINGLE SECTION USED
-  IF(ANY(ll) .AND. fType/=3) THEN                                    !--- MISSING FILES
-    IF(test(checkList(trac_files, .NOT.ll, 'Failed reading tracers description', 'files', 'missing'), lerr)) RETURN
-  END IF
-
-  !--- CHECK WHETHER type_trac AND FILE TYPE ARE COMPATIBLE
-  IF(test(fmsg('No multiple sections for the old format "traceur.def"', ll = SIZE(sections)>1 .AND. fType==1), lerr)) RETURN
-
-  !--- TELLS WHAT WAS IS ABOUT TO BE USED
-  IF (fmsg('No adequate tracers description file(s) found ; default values will be used',          modname, fType==0)) RETURN
-  CALL msg('Trying to read old-style tracers description file "traceur.def"',                      modname, fType==1)
-  CALL msg('Trying to read the new style multi-sections tracers description file "tracer.def"',    modname, fType==2)
-  CALL msg('Trying to read the new style single section tracers description files "tracer_*.def"', modname, fType==3)
+  lRep=.FALSE.; IF(PRESENT(lRepr)) lRep = lRepr
+
+  !--- Required sections + corresponding files names (new style single section case) for tests
+  IF(test(testTracersFiles(modname, type_trac, fType, .FALSE., trac_files, sections), lerr)) RETURN
+  nsec = SIZE(sections)
 
   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   SELECT CASE(fType)                         !--- Set %name, %genOName, %parent, %type, %phase, %component, %iGeneration, %keys
   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-    CASE(1)                                                               !=== OLD FORMAT "traceur.def"
+    CASE(1)                                                          !=== OLD FORMAT "traceur.def"
     !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       !--- OPEN THE "traceur.def" FILE
@@ -145,27 +211,54 @@
 
       !--- READ THE REMAINING LINES: <hadv> <vadv> <tracer> [<transporting fluid>]
-      ALLOCATE(tracs(ntrac))
+      IF(ALLOCATED(tracers)) DEALLOCATE(tracers)
+      ALLOCATE(tracers(ntrac))
       DO it=1,ntrac                                                  !=== READ RAW DATA: loop on the line/tracer number
         READ(90,'(a)',IOSTAT=ierr) str
         IF(test(fmsg('Invalid format for "' //TRIM(fname)//'"', modname, ierr>0), lerr)) RETURN
         IF(test(fmsg('Not enough lines in "'//TRIM(fname)//'"', modname, ierr<0), lerr)) RETURN
-        ll = strParse(str, ' ', s, n=ns)
+        lerr = strParse(str, ' ', s, ns)
         CALL msg('This file is for air tracers only',           modname, ns == 3 .AND. it == 1)
         CALL msg('This files specifies the transporting fluid', modname, ns == 4 .AND. it == 1)
-        tracs(it)%name   = old2newName(s(3), ip)                     !--- Set %name:   name   of the tracer
-        tracs(it)%parent = tran0                                     !--- Default transporting fluid name
-        IF(ns == 4) tracs(it)%parent = old2newName(s(4))             !--- Set %parent: parent of the tracer
-        tracs(it)%phase = known_phases(ip:ip)                        !--- Set %phase:  tracer phase (default: "g"azeous)
-        tracs(it)%component = TRIM(type_trac)                        !--- Set %component: model component name
-        tracs(it)%keys%key = ['hadv', 'vadv']                        !--- Set %keys%key
-        tracs(it)%keys%val = s(1:2)                                  !--- Set %keys%val
+        k => tracers(it)%keys
+
+        !=== NAME OF THE TRACER
+        tname = old2newH2O(s(3), ip)
+        ix = strIdx(oldHNO3, s(3))
+        IF(ix /= 0 .AND. lRep) tname = newHNO3(ix)                   !--- Exception for HNO3 (REPROBUS ONLY)
+        tracers(it)%name = tname                                     !--- Set %name
+        CALL addKey_1('name', tname, k)                              !--- Set the name of the tracer
+        tracers(it)%keys%name = tname                                !--- Copy tracers names in keys components
+
+        !=== NAME OF THE COMPONENT
+        cname = type_trac                                            !--- Name of the model component
+        IF(ANY([(addPhase('H2O', ip), ip = 1, nphases)] == tname)) cname = 'lmdz'
+        tracers(it)%component = cname                                !--- Set %component
+        CALL addKey_1('component', cname, k)                         !--- Set the name of the model component
+
+        !=== NAME OF THE PARENT
+        pname = tran0                                                !--- Default name: default transporting fluid (air)
+        IF(ns == 4) THEN
+          pname = old2newH2O(s(4))
+          ix = strIdx(oldHNO3, s(4))
+          IF(ix /= 0 .AND. lRep) pname = newHNO3(ix)                 !--- Exception for HNO3 (REPROBUS ONLY)
+        END IF
+        tracers(it)%parent = pname                                   !--- Set %parent
+        CALL addKey_1('parent', pname, k)
+
+        !=== PHASE AND ADVECTION SCHEMES NUMBERS
+        tracers(it)%phase = known_phases(ip:ip)                      !--- Set %phase:  tracer phase (default: "g"azeous)
+        CALL addKey_1('phase', known_phases(ip:ip), k)               !--- Set the phase  of the tracer (default: "g"azeous)
+        CALL addKey_1('hadv', s(1),  k)                              !--- Set the horizontal advection schemes number
+        CALL addKey_1('vadv', s(2),  k)                              !--- Set the vertical   advection schemes number
       END DO
       CLOSE(90)
-      CALL setGeneration(tracs)                                      !--- Set %iGeneration and %gen0Name
-      WHERE(tracs%iGeneration == 2) tracs%type = 'tag'               !--- Set %type:        'tracer' or 'tag'
-      IF(test(checkTracers(tracs, fname, fname), lerr)) RETURN       !--- Detect orphans and check phases
-      IF(test(checkUnique (tracs, fname, fname), lerr)) RETURN       !--- Detect repeated tracers
-      CALL sortTracers  (tracs)                                      !--- Sort the tracers
-      tracs(:)%keys%name = tracs(:)%name                             !--- Copy tracers names in keys components
+      IF(test(setGeneration(tracers), lerr)) RETURN                  !--- Set %iGeneration and %gen0Name
+      WHERE(tracers%iGeneration == 2) tracers(:)%type = 'tag'        !--- Set %type:        'tracer' or 'tag'
+      DO it=1,ntrac
+        CALL addKey_1('type', tracers(it)%type, tracers(it)%keys)    !--- Set the type of tracer
+      END DO
+      IF(test(checkTracers(tracers, fname, fname), lerr)) RETURN     !--- Detect orphans and check phases
+      IF(test(checkUnique (tracers, fname, fname), lerr)) RETURN     !--- Detect repeated tracers
+      CALL sortTracers    (tracers)                                  !--- Sort the tracers
     !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     CASE(2); IF(test(feedDBase(["tracer.def"], [type_trac], modname), lerr)) RETURN !=== SINGLE   FILE, MULTIPLE SECTIONS
@@ -175,19 +268,57 @@
   END SELECT
   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
   IF(ALL([2,3] /= fType)) RETURN
 
   IF(nsec  == 1) THEN; 
-    tracs = dBase(1)%trac
+    tracers = dBase(1)%trac
   ELSE IF(tracs_merge) THEN
     CALL msg('The multiple required sections will be MERGED.',    modname)
-    IF(test(mergeTracers(dBase, tracs), lerr)) RETURN
+    IF(test(mergeTracers(dBase, tracers), lerr)) RETURN
   ELSE
     CALL msg('The multiple required sections will be CUMULATED.', modname)
-    IF(test(cumulTracers(dBase, tracs), lerr)) RETURN
+    IF(test(cumulTracers(dBase, tracers), lerr)) RETURN
   END IF
-  WHERE(tracs%gen0Name(1:3) /= 'H2O') tracs%isInPhysics=.TRUE.       !--- Set %isInPhysics: passed to physics
-  CALL setDirectKeys(tracs)                                          !--- Set %iqParent, %iqDescen, %nqDescen, %nqChilds
+  CALL setDirectKeys(tracers)                                        !--- Set %iqParent, %iqDescen, %nqDescen, %nqChildren
 END FUNCTION readTracersFiles
+!==============================================================================================================================
+
+
+!==============================================================================================================================
+LOGICAL FUNCTION testTracersFiles(modname, type_trac, fType, lDisp, tracf, sects) RESULT(lerr)
+  CHARACTER(LEN=*),                             INTENT(IN)  :: modname, type_trac
+  INTEGER,                                      INTENT(OUT) :: fType
+  LOGICAL,                            OPTIONAL, INTENT(IN)  :: lDisp
+  CHARACTER(LEN=maxlen), ALLOCATABLE, OPTIONAL, INTENT(OUT) :: tracf(:), sects(:)
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: trac_files(:), sections(:)
+  LOGICAL, ALLOCATABLE :: ll(:)
+  LOGICAL :: lD, lFound
+  INTEGER :: is, nsec
+  lD = .FALSE.; IF(PRESENT(lDisp)) lD = lDisp
+  lerr = .FALSE.
+
+  !--- PARSE "type_trac" LIST AND DETERMINE THE TRACERS FILES NAMES (FOR CASE 3: MULTIPLE FILES, SINGLE SECTION PER FILE)
+  !--- If type_trac is a scalar (case 1), "sections" and "trac_files" are not usable, but are meaningless for case 1 anyway.
+  IF(test(strParse(type_trac, '|', sections,  n=nsec), lerr)) RETURN !--- Parse "type_trac" list
+  IF(PRESENT(sects)) sects = sections
+  ALLOCATE(trac_files(nsec), ll(nsec))
+  DO is=1, nsec
+     trac_files(is) = 'tracer_'//TRIM(sections(is))//'.def'
+     INQUIRE(FILE=TRIM(trac_files(is)), EXIST=ll(is))
+  END DO
+  IF(PRESENT(tracf)) tracf = trac_files
+  fType = 0
+  INQUIRE(FILE='traceur.def', EXIST=lFound); IF(lFound)  fType = 1   !--- OLD STYLE FILE
+  INQUIRE(FILE='tracer.def',  EXIST=lFound); IF(lFound)  fType = 2   !--- NEW STYLE ; SINGLE  FILE, SEVERAL SECTIONS
+                                             IF(ALL(ll)) fType = 3   !--- NEW STYLE ; SEVERAL FILES, SINGLE SECTION USED
+  IF(.NOT.lD) RETURN                                                 !--- NO CHECKING/DISPLAY NEEDED: JUST GET type_trac,fType
+  IF(ANY(ll) .AND. fType/=3) THEN                                    !--- MISSING FILES
+    IF(test(checkList(trac_files, .NOT.ll, 'Failed reading tracers description', 'files', 'missing'), lerr)) RETURN
+  END IF
+
+  !--- TELLS WHAT WAS IS ABOUT TO BE USED
+  CALL msg('Trying to read old-style tracers description file "traceur.def"',                      modname, fType==1)
+  CALL msg('Trying to read the new style multi-sections tracers description file "tracer.def"',    modname, fType==2)
+  CALL msg('Trying to read the new style single section tracers description files "tracer_*.def"', modname, fType==3)
+END FUNCTION testTracersFiles
 !==============================================================================================================================
 
@@ -206,5 +337,4 @@
   INTEGER,  ALLOCATABLE :: ndb(:)                                    !--- Number of sections for each file
   INTEGER,  ALLOCATABLE :: ixf(:)                                    !--- File index for each section of the expanded list
-  LOGICAL,  ALLOCATABLE :: lTg(:)                                    !--- Tagging tracers mask
   CHARACTER(LEN=maxlen) :: fnm, snm
   INTEGER               :: idb, i
@@ -224,5 +354,5 @@
     lerr = ANY([(dispTraSection('RAW CONTENT OF SECTION "'//TRIM(snm)//'"', snm, modname), idb=1, SIZE(dBase))])
     IF(test(expandSection(dBase(idb)%trac, snm, fnm), lerr)) RETURN  !--- EXPAND NAMES ;  set %parent, %type, %component
-    CALL setGeneration   (dBase(idb)%trac)                           !---                 set %iGeneration,   %genOName
+    IF(test(setGeneration(dBase(idb)%trac),           lerr)) RETURN  !---                 set %iGeneration,   %genOName
     IF(test(checkTracers (dBase(idb)%trac, snm, fnm), lerr)) RETURN  !--- CHECK ORPHANS AND PHASES
     IF(test(checkUnique  (dBase(idb)%trac, snm, fnm), lerr)) RETURN  !--- CHECK TRACERS UNIQUENESS
@@ -246,5 +376,5 @@
   CHARACTER(LEN=maxlen), ALLOCATABLE :: sec(:)
   INTEGER,               ALLOCATABLE ::  ix(:)
-  INTEGER :: n0, idb, ndb, i, j
+  INTEGER :: n0, idb, ndb
   LOGICAL :: ll
 !------------------------------------------------------------------------------------------------------------------------------
@@ -299,5 +429,5 @@
       CALL MOVE_ALLOC(FROM=tdb, TO=dBase)
     ELSE                                                             !=== TRACER LINE
-      ll = strParse(str,' ', keys = s, vals = v, n = n)              !--- Parse <key>=<val> pairs
+      ll = strParse(str,' ', s, n, v)                                !--- Parse <key>=<val> pairs
       tt = dBase(ndb)%trac(:)
       tmp%name = s(1); tmp%keys = keys_type(s(1), s(2:n), v(2:n))    !--- Set %name and %keys
@@ -330,6 +460,6 @@
   ky => t(jd)%keys
   DO k = 1, SIZE(ky%key)                                             !--- Loop on the keys of the tracer named "defName"
-!   CALL addKey_m(ky%key(k), ky%val(k), t(:)%keys)                   !--- Add key to all the tracers (no overwriting)
-    DO it = 1, SIZE(t); CALL addKey_1(ky%key(k), ky%val(k), t(it)%keys); END DO
+!   CALL addKey_m(ky%key(k), ky%val(k), t(:)%keys, .FALSE.)           !--- Add key to all the tracers (no overwriting)
+    DO it = 1, SIZE(t); CALL addKey_1(ky%key(k), ky%val(k), t(it)%keys, .FALSE.); END DO
   END DO
   tt = [t(1:jd-1),t(jd+1:SIZE(t))]; CALL MOVE_ALLOC(FROM=tt, TO=t)   !--- Remove the virtual tracer named "defName"
@@ -381,5 +511,5 @@
   CHARACTER(LEN=maxlen), ALLOCATABLE :: ta(:), pa(:)
   CHARACTER(LEN=maxlen) :: msg1, modname
-  INTEGER :: it, nt, iq, nq, itr, ntr, ipr, npr, i
+  INTEGER :: it, nt, iq, nq, itr, ntr, ipr, npr
   LOGICAL :: ll
   modname = 'expandSection'
@@ -394,4 +524,6 @@
     tr(it)%type      = fgetKey(it, 'type'  , tr(:)%keys, 'tracer')
     tr(it)%component = sname
+!   CALL addKey_m('component', sname, tr(:)%keys)
+    DO iq=1,SIZE(tr); CALL addKey_1('component', sname, tr(iq)%keys); END DO
 
     !--- Determine the number of tracers and parents ; coherence checking
@@ -409,5 +541,4 @@
   END DO
   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-  CALL delKey(['parent','type  '], tr)
 
   ALLOCATE(ttr(nq))
@@ -416,20 +547,18 @@
   DO it = 1, nt                                                      !=== EXPAND TRACERS AND PARENTS NAMES LISTS
   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-    ll = strParse(tr(it)%name,   ',', ta, n=ntr)                     !--- Number of tracers
-    ll = strParse(tr(it)%parent, ',', pa, n=npr)                     !--- Number of parents
+    ll = strParse(tr(it)%name,   ',', ta, ntr)                       !--- Number of tracers
+    ll = strParse(tr(it)%parent, ',', pa, npr)                       !--- Number of parents
     DO ipr=1,npr                                                     !--- Loop on parents list elts
       DO itr=1,ntr                                                   !--- Loop on tracers list elts
-        i = iq+itr-1+(ipr-1)*ntr
-        ttr(i)%name   = TRIM(ta(itr))
-        ttr(i)%parent = TRIM(pa(ipr))
-        ttr(i)%keys%name = ta(itr)
-        ttr(i)%keys%key  = tr(it)%keys%key
-        ttr(i)%keys%val  = tr(it)%keys%val
-!        ttr(i)%keys   = keys_type(ta(itr), tr(it)%keys%key, tr(it)%keys%val)
+        ttr(iq)%keys%key  = tr(it)%keys%key
+        ttr(iq)%keys%val  = tr(it)%keys%val
+        ttr(iq)%keys%name = ta(itr)
+        ttr(iq)%name      = TRIM(ta(itr));    CALL addKey_1('name',      ta(itr),          ttr(iq)%keys)
+        ttr(iq)%parent    = TRIM(pa(ipr));    CALL addKey_1('parent',    pa(ipr),          ttr(iq)%keys)
+        ttr(iq)%type      = tr(it)%type;      CALL addKey_1('type',      tr(it)%type,      ttr(iq)%keys)
+        ttr(iq)%component = tr(it)%component; CALL addKey_1('component', tr(it)%component, ttr(iq)%keys)
+        iq = iq+1
       END DO
     END DO
-    ttr(iq:iq+ntr*npr-1)%type      = tr(it)%type                     !--- Duplicating type
-    ttr(iq:iq+ntr*npr-1)%component = tr(it)%component                !--- Duplicating type
-    iq = iq + ntr*npr
   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   END DO
@@ -441,33 +570,33 @@
 !==============================================================================================================================
 
-!==============================================================================================================================
-SUBROUTINE setGeneration(tr)
+
+!==============================================================================================================================
+LOGICAL FUNCTION setGeneration(tr) RESULT(lerr)
 !------------------------------------------------------------------------------------------------------------------------------
 ! Purpose: Determine, for each tracer of "tr(:)":
 !   * %iGeneration: the generation number 
 !   * %gen0Name:    the generation 0 ancestor name
+!          Check also for orphan tracers (tracers not descending on "tran0").
 !------------------------------------------------------------------------------------------------------------------------------
   TYPE(trac_type),     INTENT(INOUT) :: tr(:)                        !--- Tracer derived type vector
-  INTEGER                            :: iq, nq, ig
-  LOGICAL,               ALLOCATABLE :: lg(:)
-  CHARACTER(LEN=maxlen), ALLOCATABLE :: prn(:)
-!------------------------------------------------------------------------------------------------------------------------------
-  tr(:)%iGeneration = -1                                             !--- error if -1
-  nq = SIZE(tr, DIM=1)                                               !--- Number of tracers lines
-  lg = tr(:)%parent == tran0                                         !--- Flag for generation 0 tracers
-  WHERE(lg) tr(:)%iGeneration = 0                                    !--- Generation 0 tracers
-
-  !=== Determine generation for each tracer
-  ig=-1; prn = [tran0]
-  DO                                                                 !--- Update current generation flag
-    IF(ig/=-1) prn = PACK( tr(:)%name, MASK=tr(:)%iGeneration == ig)
-    lg(:) = [(ANY(prn(:) == tr(iq)%parent), iq=1, nq)]               !--- Current generation tracers flag
-    IF( ALL( .NOT. lg ) ) EXIT                                       !--- Empty current generation
-    ig = ig+1; WHERE(lg) tr(:)%iGeneration = ig
-  END DO
-  tr(:)%gen0Name = ancestor(tr)                                      !--- First generation ancestor name
-
-END SUBROUTINE setGeneration
-!==============================================================================================================================
+  INTEGER                            :: iq, jq, ig
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: parent(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen) :: modname
+  modname = 'setGeneration'
+  IF(test(fmsg('missing "parent" attribute', modname, getKey('parent', parent, ky=tr(:)%keys)), lerr)) RETURN
+  DO iq = 1, SIZE(tr)
+    jq = iq; ig = 0
+    DO WHILE(parent(jq) /= tran0)
+      jq = strIdx(tr(:)%name, parent(jq))
+      IF(test(fmsg('Orphan tracer "'//TRIM(tr(iq)%name)//'"', modname, jq == 0), lerr)) RETURN
+      ig = ig + 1
+    END DO
+    tr(iq)%gen0Name = tr(jq)%name; CALL addKey_1('gen0Name',    tr(iq)%gen0Name,   tr(iq)%keys)
+    tr(iq)%iGeneration = ig;       CALL addKey_1('iGeneration', TRIM(int2str(ig)), tr(iq)%keys)
+  END DO
+END FUNCTION setGeneration
+!==============================================================================================================================
+
 
 !==============================================================================================================================
@@ -503,4 +632,5 @@
 END FUNCTION checkTracers
 !==============================================================================================================================
+
 
 !==============================================================================================================================
@@ -543,4 +673,5 @@
 !==============================================================================================================================
 
+
 !==============================================================================================================================
 SUBROUTINE expandPhases(tr)
@@ -552,8 +683,8 @@
   TYPE(trac_type), ALLOCATABLE :: ttr(:)
   INTEGER,   ALLOCATABLE ::  i0(:)
-  CHARACTER(LEN=maxlen)  :: nam, pha, trn
+  CHARACTER(LEN=maxlen)  :: nam, pha, tname
   CHARACTER(LEN=1) :: p
   INTEGER :: ip, np, iq, jq, nq, it, nt, nc, i, n
-  LOGICAL :: lTg, lEx
+  LOGICAL :: lTag, lExt
 !------------------------------------------------------------------------------------------------------------------------------
   nq = SIZE(tr, DIM=1)
@@ -561,7 +692,7 @@
   DO iq = 1, nq                                                      !--- GET THE NUMBER OF TRACERS
     IF(tr(iq)%iGeneration /= 0) CYCLE                                !--- Only deal with generation 0 tracers
-    nc = COUNT(tr(:)%gen0Name==tr(iq)%name .AND. tr%iGeneration/=0)  !--- Number of childs of tr(iq)
-    tr(iq)%phase = fgetKey(iq, 'phases', tr(:)%keys)                 !--- Phases list      of tr(iq)
-    np = LEN_TRIM(tr(iq)%phase)                                      !--- Number of phases of tr(iq)
+    nc = COUNT(tr(:)%gen0Name==tr(iq)%name .AND. tr%iGeneration/=0)  !--- Number of children of tr(iq)
+    tr(iq)%phase = fgetKey(iq, 'phases', tr(:)%keys)                 !--- Phases list        of tr(iq)
+    np = LEN_TRIM(tr(iq)%phase)                                      !--- Number of phases   of tr(iq)
     nt = nt + (1+nc) * np                                            !--- Number of tracers after expansion
   END DO
@@ -569,9 +700,9 @@
   it = 1                                                             !--- Current "ttr(:)" index
   DO iq = 1, nq                                                      !--- Loop on "tr(:)" indexes
-    lTg = tr(iq)%type=='tag'                                         !--- Current tracer is a tag
+    lTag = tr(iq)%type=='tag'                                        !--- Current tracer is a tag
     i0 = strFind(tr(:)%name, TRIM(tr(iq)%gen0Name), n)               !--- Indexes of first generation ancestor copies
     np = SUM([( LEN_TRIM(tr(i0(i))%phase),i=1,n )], 1)               !--- Number of phases for current tracer tr(iq)
-    lEx = np>1                                                       !--- Phase suffix only required if phases number is > 1
-    IF(lTg) lEx = lEx .AND. tr(iq)%iGeneration>0                     !--- No phase suffix for generation 0 tags
+    lExt = np>1                                                      !--- Phase suffix only required if phases number is > 1
+    IF(lTag) lExt = lExt .AND. tr(iq)%iGeneration>0                  !--- No phase suffix for generation 0 tags
     DO i=1,n                                                         !=== LOOP ON GENERATION 0 ANCESTORS
       jq = i0(i)                                                     !--- tr(jq): ith tracer with same gen 0 ancestor as tr(iq)
@@ -580,15 +711,19 @@
       DO ip = 1, LEN_TRIM(pha)                                       !=== LOOP ON PHASES LISTS
         p = pha(ip:ip)
-        trn = TRIM(tr(iq)%name); nam = trn                           !--- Tracer name (regular case)
-        IF(lTg) nam = TRIM(tr(iq)%parent)                            !--- Parent name (tagging case)
-        IF(lEx) nam = addPhase(nam, p )                              !--- Phase extension needed
-        IF(lTg) nam = TRIM(nam)//'_'//TRIM(trn)                      !--- <parent>_<name> for tags
+        tname = TRIM(tr(iq)%name); nam = tname                       !--- Tracer name (regular case)
+        IF(lTag) nam = TRIM(tr(iq)%parent)                           !--- Parent name (tagging case)
+        IF(lExt) nam = addPhase(nam, p )                             !--- Phase extension needed
+        IF(lTag) nam = TRIM(nam)//'_'//TRIM(tname)                   !--- <parent>_<name> for tags
         ttr(it) = tr(iq)                                             !--- Same <key>=<val> pairs
         ttr(it)%name      = TRIM(nam)                                !--- Name with possibly phase suffix
         ttr(it)%keys%name = TRIM(nam)                                !--- Name inside the keys decriptor
         ttr(it)%phase     = p                                        !--- Single phase entry
-        IF(lEx .AND. tr(iq)%iGeneration>0) THEN
-          ttr(it)%parent   = addPhase(ttr(it)%parent,   p)
-          ttr(it)%gen0Name = addPhase(ttr(it)%gen0Name, p)
+        CALL addKey_1('name', nam, ttr(it)%keys)
+        CALL addKey_1('phase', p,  ttr(it)%keys)
+        IF(lExt .AND. tr(iq)%iGeneration>0) THEN
+          ttr(it)%parent   = addPhase(tr(iq)%parent,   p)
+          ttr(it)%gen0Name = addPhase(tr(iq)%gen0Name, p)
+          CALL addKey_1('parent',   ttr(it)%parent,   ttr(it)%keys)
+          CALL addKey_1('gen0Name', ttr(it)%gen0Name, ttr(it)%keys)
         END IF
         it = it+1
@@ -603,4 +738,5 @@
 !==============================================================================================================================
 
+
 !==============================================================================================================================
 SUBROUTINE sortTracers(tr)
@@ -609,10 +745,13 @@
 !  * Put water at the beginning of the vector, in the "known_phases" order.
 !  * lGrowGen == T: in ascending generations numbers.
-!  * lGrowGen == F: tracer + its childs sorted by growing generation, one after the other.
+!  * lGrowGen == F: tracer + its children sorted by growing generation, one after the other.
 !   TO BE ADDED IF NECESSARY: HIGHER MOMENTS AT THE END
 !------------------------------------------------------------------------------------------------------------------------------
   TYPE(trac_type), ALLOCATABLE, INTENT(INOUT) :: tr(:)         !--- Tracer derived type vector
-  INTEGER,         ALLOCATABLE :: iy(:), iz(:)
-  INTEGER :: ig, ng, iq, jq, ip, nq, n, ix(SIZE(tr)), k
+!------------------------------------------------------------------------------------------------------------------------------
+  TYPE(trac_type), ALLOCATABLE        :: tr2(:)
+  INTEGER,         ALLOCATABLE        :: iy(:), iz(:)
+  INTEGER                             :: ig, ng, iq, jq, ip, nq, n, ix(SIZE(tr)), k
+!  tr2 is introduced in order to cope with a bug in gfortran 4.8.5 compiler
 !------------------------------------------------------------------------------------------------------------------------------
   nq = SIZE(tr)
@@ -620,5 +759,6 @@
     iq = strIdx(tr(:)%name, addPhase('H2O', ip))
     IF(iq == 0) CYCLE
-    tr = [tr(iq), tr(1:iq-1), tr(iq+1:nq)]
+    tr2 = tr(:)
+    tr = [tr2(iq), tr2(1:iq-1), tr2(iq+1:nq)]
   END DO
   IF(lSortByGen) THEN
@@ -637,5 +777,5 @@
       ix(iq) = jq                                                    !--- Generation 0 ancestor index first
       iq = iq + 1                                                    !--- Next "iq" for next generations tracers
-      iy = strFind(tr(:)%gen0Name, TRIM(tr(jq)%name))                !--- Indexes of "tr(jq)" childs in "tr(:)"
+      iy = strFind(tr(:)%gen0Name, TRIM(tr(jq)%name))                !--- Indexes of "tr(jq)" children in "tr(:)"
       ng = MAXVAL(tr(iy)%iGeneration, MASK=.TRUE., DIM=1)            !--- Number of generations of the "tr(jq)" family
       DO ig = 1, ng                                                  !--- Loop   on generations of the "tr(jq)" family
@@ -649,4 +789,5 @@
 END SUBROUTINE sortTracers
 !==============================================================================================================================
+
 
 !==============================================================================================================================
@@ -724,5 +865,5 @@
   TYPE(dataBase_type),  TARGET, INTENT(IN)  :: sections(:)
   TYPE(trac_type), ALLOCATABLE, INTENT(OUT) ::       tr(:)
-  TYPE(trac_type), POINTER     :: t1(:), t2(:)
+  TYPE(trac_type), POINTER     :: t(:)
   INTEGER,   ALLOCATABLE :: nt(:)
   CHARACTER(LEN=maxlen)  :: tnam, tnam_new
@@ -735,10 +876,10 @@
   DO is=1, nsec                                                      !=== LOOP ON SECTIONS
   !----------------------------------------------------------------------------------------------------------------------------
-    t1 => sections(is)%trac(:)
+    t => sections(is)%trac(:)
     !--------------------------------------------------------------------------------------------------------------------------
     DO iq=1, nt(is)                                                  !=== LOOP ON TRACERS
     !--------------------------------------------------------------------------------------------------------------------------
-      tnam = TRIM(t1(iq)%name)                                       !--- Original name
-      IF(COUNT(t1%name == tnam) == 1) CYCLE                          !--- Current tracer is not duplicated: finished
+      tnam = TRIM(t(iq)%name)                                        !--- Original name
+      IF(COUNT(t%name == tnam) == 1) CYCLE                           !--- Current tracer is not duplicated: finished
       tnam_new = TRIM(tnam)//'_'//TRIM(sections(is)%name)            !--- Same with section extension
       nq = SUM(nt(1:is-1))                                           !--- Number of tracers in previous sections
@@ -759,5 +900,5 @@
   TYPE(trac_type), INTENT(INOUT) :: tr(:)
 
-  !--- Update %iqParent, %iqDescen, %nqDescen, %nqChilds
+  !--- Update %iqParent, %iqDescen, %nqDescen, %nqChildren
   CALL indexUpdate(tr)
 
@@ -774,5 +915,5 @@
   INTEGER :: idb, iq, nq
   INTEGER, ALLOCATABLE :: hadv(:), vadv(:)
-  CHARACTER(LEN=maxlen), ALLOCATABLE :: phas(:)
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: phas(:), prnt(:)
   TYPE(trac_type), POINTER :: tm(:)
   lerr = .FALSE.
@@ -782,17 +923,20 @@
   !--- BEWARE ! Can't use the "getKeyByName" functions yet.
   !             Names must first include the phases for tracers defined on multiple lines.
-  hadv = str2int([(fgetKey(iq, 'hadv',  tm(:)%keys, '10'), iq=1, nq)])
-  vadv = str2int([(fgetKey(iq, 'vadv',  tm(:)%keys, '10'), iq=1, nq)])
-  phas =         [(fgetKey(iq, 'phases',tm(:)%keys, 'g' ), iq=1, nq)]
+  hadv = str2int(fgetKeys('hadv',  tm(:)%keys, '10'))
+  vadv = str2int(fgetKeys('vadv',  tm(:)%keys, '10'))
+  prnt =         fgetKeys('parent',tm(:)%keys,  '' )
+  IF(getKey('phases', phas, ky=tm(:)%keys)) phas = fGetKeys('phase', tm(:)%keys, 'g')
   CALL msg(TRIM(message)//':', modname)
-  IF(ALL(tm(:)%parent == '')) THEN
-    IF(test(dispTable('iiiss',   ['iq    ','hadv  ','vadv  ','name  ','phase '], cat(tm%name, phas), &
+  IF(ALL(prnt == 'air')) THEN
+    IF(test(dispTable('iiiss',   ['iq    ','hadv  ','vadv  ','name  ','phase '],                   cat(tm%name,       phas),  &
+                 cat([(iq, iq=1, nq)], hadv, vadv),                 nColMax=maxTableWidth, nHead=2, sub=modname), lerr)) RETURN
+  ELSE IF(ALL(tm%iGeneration == -1)) THEN
+    IF(test(dispTable('iiisss', ['iq    ','hadv  ','vadv  ','name  ','parent','phase '],           cat(tm%name, prnt, phas),  &
                  cat([(iq, iq=1, nq)], hadv, vadv),                 nColMax=maxTableWidth, nHead=2, sub=modname), lerr)) RETURN
   ELSE
-    IF(test(dispTable('iiissis', ['iq    ','hadv  ','vadv  ','name  ','parent','igen  ','phase '], cat(tm%name, tm%parent, &
-      tm%phase), cat([(iq, iq=1, nq)], hadv, vadv, tm%iGeneration), nColMax=maxTableWidth, nHead=2, sub=modname), lerr)) RETURN
+    IF(test(dispTable('iiissis', ['iq    ','hadv  ','vadv  ','name  ','parent','igen  ','phase '], cat(tm%name, prnt, phas),  &
+                 cat([(iq, iq=1, nq)], hadv, vadv, tm%iGeneration), nColMax=maxTableWidth, nHead=2, sub=modname), lerr)) RETURN
   END IF
 END FUNCTION dispTraSection
-!==============================================================================================================================
 !==============================================================================================================================
 
@@ -809,5 +953,5 @@
   out => NULL(); IF(it /= 0) out => t(it)
 END FUNCTION aliasTracer
-!------------------------------------------------------------------------------------------------------------------------------
+!==============================================================================================================================
 
 
@@ -830,5 +974,5 @@
   CALL indexUpdate(out)
 END FUNCTION trSubset_Name
-!------------------------------------------------------------------------------------------------------------------------------
+!==============================================================================================================================
 
 
@@ -843,5 +987,5 @@
   CALL indexUpdate(out)
 END FUNCTION trSubset_gen0Name
-!------------------------------------------------------------------------------------------------------------------------------
+!==============================================================================================================================
 
 
@@ -851,7 +995,7 @@
 SUBROUTINE indexUpdate(tr)
   TYPE(trac_type), INTENT(INOUT) :: tr(:)
-  INTEGER :: iq, ig, ng, igen, ngen
-  INTEGER, ALLOCATABLE :: ix(:)
+  INTEGER :: iq, ig, igen, ngen, ix(SIZE(tr))
   tr(:)%iqParent = strIdx( tr(:)%name, tr(:)%parent )                !--- Parent index
+  DO iq = 1, SIZE(tr); CALL addKey_1('iqParent', int2str(tr(iq)%iqParent), tr(iq)%keys); END DO
   ngen = MAXVAL(tr(:)%iGeneration, MASK=.TRUE.)
   DO iq = 1, SIZE(tr)
@@ -859,13 +1003,18 @@
     IF(ALLOCATED(tr(iq)%iqDescen)) DEALLOCATE(tr(iq)%iqDescen)
     ALLOCATE(tr(iq)%iqDescen(0))
-    ix = idxAncestor(tr, igen=ig)                                    !--- Ancestor of generation "ng" for each tr
+    CALL idxAncestor(tr, ix, ig)                                     !--- Ancestor of generation "ng" for each tr
     DO igen = ig+1, ngen
       tr(iq)%iqDescen = [tr(iq)%iqDescen, find(ix==iq .AND. tr%iGeneration==igen)]
       tr(iq)%nqDescen = SIZE(tr(iq)%iqDescen)
-      IF(igen == ig+1) tr(iq)%nqChilds=tr(iq)%nqDescen
+      IF(igen == ig+1) THEN
+        tr(iq)%nqChildren = tr(iq)%nqDescen
+        CALL addKey_1('nqChildren', int2str(tr(iq)%nqChildren), tr(iq)%keys)
+      END IF
     END DO
+    CALL addKey_1('iqDescen', strStack(int2str(tr(iq)%iqDescen)), tr(iq)%keys)
+    CALL addKey_1('nqDescen',          int2str(tr(iq)%nqDescen) , tr(iq)%keys)
   END DO
 END SUBROUTINE indexUpdate
-!------------------------------------------------------------------------------------------------------------------------------
+!==============================================================================================================================
   
   
@@ -875,5 +1024,5 @@
 !===  * For each isotopes class, the <key>=<val> vector of each tracer is moved into the isotopes descriptor "isot"        ====
 !=== NOTES:                                                                                                                ====
-!===  * Most of the "isot" components have been defined in the calling routine (initIsotopes):                             ====
+!===  * Most of the "isot" components have been defined in the calling routine (readIsotopes):                             ====
 !===      parent,  nzone, zone(:),  niso, keys(:)%name,  ntiso, trac(:),  nphas, phas,  iqIsoPha(:,:),  itZonPhi(:,:)      ====
 !===  * Same syntax for isotopes file and "tracer.def": a tracers section contains one line for each of its isotopes       ====
@@ -883,20 +1032,18 @@
 !===  * The routine gives an error if a required isotope is not available in the database stored in "fnam"                 ====
 !==============================================================================================================================
-LOGICAL FUNCTION readIsotopesFile(fnam, isot) RESULT(lerr)
+LOGICAL FUNCTION readIsotopesFile_prv(fnam, isot) RESULT(lerr)
   CHARACTER(LEN=*),        INTENT(IN)    :: fnam                     !--- Input file name
-  TYPE(isot_type), TARGET, INTENT(INOUT) :: isot(:)                  !--- Isotopes descriptors (field "prnt" must be defined !)
-  INTEGER :: ik, is, it, idb, nk0, i, iis
-  INTEGER :: nk, ns, nt, ndb, nb0, i0
-  CHARACTER(LEN=maxlen), POINTER     :: k(:), v(:), k0(:), v0(:)
+  TYPE(isot_type), TARGET, INTENT(INOUT) :: isot(:)                  !--- Isotopes descriptors (field %parent must be defined!)
+  LOGICAL :: lFound
+  INTEGER :: is, iis, it, idb, ndb, nb0
   CHARACTER(LEN=maxlen), ALLOCATABLE :: vals(:)
-  CHARACTER(LEN=maxlen)              :: val, modname
-  TYPE(keys_type),           POINTER ::   ky(:)
+  CHARACTER(LEN=maxlen)              :: modname
   TYPE(trac_type),           POINTER ::   tt(:), t
   TYPE(dataBase_type),   ALLOCATABLE ::  tdb(:)
-  LOGICAL,               ALLOCATABLE :: liso(:)
   modname = 'readIsotopesFile'
 
   !--- THE INPUT FILE MUST BE PRESENT
-  IF(test(fmsg('Missing isotopes parameters file "'//TRIM(fnam)//'"', modname, testFile(fnam)),lerr)) RETURN
+  INQUIRE(FILE=TRIM(fnam), EXIST=lFound); lerr = .NOT.lFound
+  IF(fmsg('Missing isotopes parameters file "'//TRIM(fnam)//'"', modname, lerr)) RETURN
 
   !--- READ THE FILE SECTIONS, ONE EACH PARENT TRACER
@@ -905,5 +1052,5 @@
   ndb = SIZE(dBase, DIM=1)                                           !--- Current database size
   DO idb = nb0, ndb
-   iis = idb-nb0+1
+    iis = idb-nb0+1
 
     !--- GET FEW GLOBAL KEYS FROM "def" FILES AND ADD THEM TO THE 'params' SECTION
@@ -920,14 +1067,12 @@
       is = strIdx(isot(iis)%keys(:)%name, t%name)                    !--- Index in "isot(iis)%keys(:)%name" of isotope "t%name"
       IF(is == 0) CYCLE
-      liso = reduceExpr(t%keys%val, vals)                            !--- Reduce expressions (for substituted variables)
-      IF(test(ANY(liso), lerr)) RETURN                               !--- Some non-numerical elements were found
-      isot(iis)%keys(is)%key = PACK(t%keys%key, MASK=.NOT.liso)
-      isot(iis)%keys(is)%val = PACK(  vals,     MASK=.NOT.liso)
+      IF(test(ANY(reduceExpr(t%keys%val, vals)), lerr)) RETURN       !--- Reduce expressions ; detect non-numerical elements
+      isot(iis)%keys(is)%key = t%keys%key
+      isot(iis)%keys(is)%val = vals
     END DO
 
     !--- CHECK FOR MISSING ISOTOPES (NO KEYS ALLOCATED)
-    liso = [( ALLOCATED(isot(iis)%keys(is)%key), is=1, SIZE(isot(iis)%keys) )]
-    IF(test(checkList(isot(iis)%keys(:)%name, .NOT.liso, &
-      'Check file "'//TRIM(fnam)//'" in section "'//TRIM(dBase(idb)%name)//'"', 'isotopes', 'missing'),lerr)) RETURN
+    IF(test(checkList(isot(iis)%keys(:)%name, .NOT.[( ALLOCATED(isot(iis)%keys(is)%key), is=1, SIZE(isot(iis)%keys) )], &
+      'Check file "'//TRIM(fnam)//'" in section "'//TRIM(dBase(idb)%name)//'"', 'isotopes', 'missing'), lerr)) RETURN
   END DO
 
@@ -942,8 +1087,36 @@
   CALL get_in('ok_iso_verif', isot(strIdx(isot%parent, 'H2O'))%check, .FALSE.)
 
-  lerr = dispIsotopes(isot, 'Isotopes parameters read from file "'//TRIM(fnam)//'"', modname)
-
-END FUNCTION readIsotopesFile
-!==============================================================================================================================
+  lerr = dispIsotopes()
+
+CONTAINS
+
+!------------------------------------------------------------------------------------------------------------------------------
+LOGICAL FUNCTION dispIsotopes() RESULT(lerr)
+  INTEGER :: ik, nk, ip, it, nt
+  CHARACTER(LEN=maxlen) :: prf
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: ttl(:), val(:,:)
+  CALL msg('Isotopes parameters read from file "'//TRIM(fnam)//'":', modname)
+  DO ip = 1, SIZE(isot)                                              !--- Loop on parents tracers
+    nk = SIZE(isot(ip)%keys(1)%key)                                  !--- Same keys for each isotope
+    nt = SIZE(isot(ip)%keys)                                         !--- Number of isotopes
+    prf = 'i'//REPEAT('s',nk+1)                                      !--- Profile for table printing
+    ALLOCATE(ttl(nk+2), val(nt,nk+1))
+    ttl(1:2) = ['it  ','name']; ttl(3:nk+2) = isot(ip)%keys(1)%key(:)!--- Titles line with keys names
+    val(:,1) = isot(ip)%keys(:)%name                                 !--- Values table 1st column: isotopes names  
+    DO ik = 1, nk
+      DO it = 1, nt
+        val(it,ik+1) = isot(ip)%keys(it)%val(ik)                     !--- Other columns: keys values
+      END DO
+    END DO
+    IF(test(fmsg('Problem with the table content', modname, dispTable(prf, ttl, val, &
+            cat([(it,it=1,nt)]), rFmt='(EN8.4)', nColMax=maxTableWidth, nHead=2, sub=modname)), lerr)) RETURN
+    DEALLOCATE(ttl, val)
+  END DO        
+END FUNCTION dispIsotopes
+!------------------------------------------------------------------------------------------------------------------------------
+
+END FUNCTION readIsotopesFile_prv
+!==============================================================================================================================
+
 
 !==============================================================================================================================
@@ -951,34 +1124,44 @@
 !===    * COMPUTE MOST OF THE RELATED QUANTITIES ("isot" COMPONENTS).                                                       ===
 !===    * COMPUTE FEW ISOTOPES-DEDICATED "trac" COMPONENTS                                                                  ===
-!===    * CALL readIsotopesFile TO GET PHYSICAL QUANTITIES (<key>=<val> PAIRS)                                              ===
+!===    * CALL readIsotopesFile_prv TO GET PHYSICAL QUANTITIES (<key>=<val> PAIRS)                                          ===
 !===      NOTE: THIS IS DONE HERE (IN A ROUTINE CALLED BY THE DYNAMIC), BECAUSE THE DYNAMIC NEEDS FEW PHYSICAL PARAMETERS.  ===
 !==============================================================================================================================
-LOGICAL FUNCTION initIsotopes(trac, isot) RESULT(lerr)
-  TYPE(trac_type), ALLOCATABLE, TARGET, INTENT(INOUT) :: trac(:)
-  TYPE(isot_type), ALLOCATABLE, TARGET, INTENT(INOUT) :: isot(:)
+LOGICAL FUNCTION readIsotopesFile(iNames) RESULT(lerr)
+  CHARACTER(LEN=maxlen), TARGET, OPTIONAL, INTENT(IN)  :: iNames(:)
   CHARACTER(LEN=maxlen), ALLOCATABLE :: p(:), str(:)                 !--- Temporary storage
-  CHARACTER(LEN=maxlen) :: iname
+  CHARACTER(LEN=maxlen) :: iName, modname
   CHARACTER(LEN=1)   :: ph                                           !--- Phase
-  INTEGER :: nbIso, ic, ip, iq, it, iz
+  INTEGER :: ic, ip, iq, it, iz
   LOGICAL, ALLOCATABLE :: ll(:)                                      !--- Mask
   TYPE(trac_type), POINTER   ::  t(:), t1
   TYPE(isot_type), POINTER   ::  i
   lerr = .FALSE.
-
-  t => trac
-
-  p = PACK(delPhase(t%parent), MASK = t%type=='tracer' .AND. t%iGeneration==1) !--- Parents of generation 1 isotopes
+  modname = 'readIsotopesFile'
+
+  t => tracers
+
+  !--- GET FROM "tracers" THE FULL LIST OF AVAILABLE ISOTOPES CLASSES
+  p = PACK(delPhase(t%parent), MASK = t%type=='tracer' .AND. t%iGeneration==1)
   CALL strReduce(p, nbIso)
-  ALLOCATE(isot(nbIso))
+
+  !--- CHECK WHETHER NEEDED ISOTOPES CLASSES "iNames" ARE AVAILABLE OR NOT
+  IF(PRESENT(iNames)) THEN
+    DO it = 1, SIZE(iNames)
+      IF(test(fmsg('No isotopes class "'//TRIM(iNames(it))//'" found among tracers', modname, ALL(p /= iNames(it))), lerr)) RETURN
+    END DO
+    p = iNames; nbIso = SIZE(p)
+  END IF
+  IF(ALLOCATED(isotopes)) DEALLOCATE(isotopes)
+  ALLOCATE(isotopes(nbIso))
 
   IF(nbIso==0) RETURN                                                !=== NO ISOTOPES: FINISHED
 
   !--- ISOTOPES RELATED VARIABLES ; NULL OR EMPTY IF NO ISOTOPES
-  isot(:)%parent = p
+  isotopes(:)%parent = p
   DO ic = 1, SIZE(p)                                                 !--- Loop on isotopes classes
-    i => isot(ic)
+    i => isotopes(ic)
     iname = i%parent                                                 !--- Current isotopes class name (parent tracer name)
 
-    !=== Isotopes childs of tracer "iname": mask, names, number (same for each phase of "iname")
+    !=== Isotopes children of tracer "iname": mask, names, number (same for each phase of "iname")
     ll = t(:)%type=='tracer' .AND. delPhase(t(:)%parent) == iname .AND. t(:)%phase == 'g'
     str = PACK(delPhase(t(:)%name), MASK = ll)                       !--- Effectively found isotopes of "iname"
@@ -989,9 +1172,9 @@
     !=== Geographic tagging tracers descending on tracer "iname": mask, names, number
     ll = t(:)%type=='tag'    .AND. delPhase(t(:)%gen0Name) == iname .AND. t(:)%iGeneration == 2
-    i%zone = PACK(strTail(t(:)%name,'_'), MASK = ll)                 !--- Tagging zones names  for isotopes category "iname"
+    i%zone = PACK(strTail(t(:)%name,'_',.TRUE.), MASK = ll)          !--- Tagging zones names  for isotopes category "iname"
     CALL strReduce(i%zone)
     i%nzone = SIZE(i%zone)                                           !--- Tagging zones number for isotopes category "iname"
 
-    !=== Geographic tracers of the isotopes childs of tracer "iname" (same for each phase of "iname")
+    !=== Geographic tracers of the isotopes children of tracer "iname" (same for each phase of "iname")
     !    NOTE: One might like to create a similar variable for 2nd generation tagging tracers (tagging the gen1 tracers)
     str = PACK(delPhase(t(:)%name), MASK=ll)
@@ -1009,9 +1192,9 @@
     !=== Tables giving the index in a table of effectively found items for each dynamical tracer (1<=iq<=nqtot)
     DO iq = 1, SIZE(t)
-      t1 => trac(iq)
+      t1 => tracers(iq)
       IF(delPhase(t1%gen0Name)/=iname .OR. t1%iGeneration==0) CYCLE  !--- Only deal with tracers descending on "iname"
       t1%iso_iGroup = ic                                             !--- Isotopes family       idx in list "isotopes(:)%parent"
-      t1%iso_iName  = strIdx(i%trac, delPhase(strHead(t1%name,'_'))) !--- Current isotope       idx in effective isotopes list
-      t1%iso_iZone  = strIdx(i%zone,          strTail(t1%name,'_') ) !--- Current isotope zone  idx in effective zones    list
+      t1%iso_iName  = strIdx(i%trac, strHead(delPhase(t1%name),'_',.TRUE.)) !--- Current isotope       idx in effective isotopes list
+      t1%iso_iZone  = strIdx(i%zone,          strTail(t1%name, '_',.TRUE.)) !--- Current isotope zone  idx in effective zones    list
       t1%iso_iPhase =  INDEX(i%phase,TRIM(t1%phase))                 !--- Current isotope phase idx in effective phases   list
       IF(t1%iGeneration /= 2) t1%iso_iZone = 0                       !--- Skip possible generation 1 tagging tracers
@@ -1020,5 +1203,5 @@
     !=== Table used to get iq (index in dyn array, size nqtot) from the isotope and phase indexes ; the full isotopes list
     !    (including tagging tracers) is sorted this way:  iso1, iso2, ..., iso1_zone1, iso2_zone1, ..., iso1_zoneN, iso2_zoneN
-    i%iqIsoPha = RESHAPE( [( (strIdx(t%name,  addPhase(i%trac(it),i%phase(ip:ip))),    it=1, i%ntiso), ip=1, i%nphas)], &
+    i%iqIsoPha = RESHAPE( [( (strIdx(t%name,  addPhase(i%trac(it),i%phase(ip:ip))),       it=1, i%ntiso), ip=1, i%nphas)], &
                          [i%ntiso, i%nphas] )
     !=== Table used to get ix (index in tagging tracers isotopes list, size ntiso) from the zone and isotope indexes
@@ -1027,59 +1210,108 @@
   END DO
 
-  !=== READ PHYSICAL PARAMETERS FROM "isotopes_params.def" FILE
-  !    DONE HERE, AND NOT ONLY IN "infotrac_phy", BECAUSE SOME PHYSICAL PARAMS ARE NEEDED FOR RESTARTS (tnat AND alpha_ideal)
-  lerr = readIsotopesFile('isotopes_params.def',isot)
-
-END FUNCTION initIsotopes
-!==============================================================================================================================
-
-
-!==============================================================================================================================
-LOGICAL FUNCTION dispIsotopes(ides, message, modname) RESULT(lerr)
-  TYPE(isot_type),  INTENT(IN) :: ides(:)                            !--- Isotopes descriptor vector
-  CHARACTER(LEN=*), INTENT(IN) :: message                            !--- Message to display
-  CHARACTER(LEN=*), INTENT(IN) :: modname                            !--- Calling subroutine name
-  INTEGER :: ik, nk, ip, it, nt
-  CHARACTER(LEN=maxlen) :: prf
-  CHARACTER(LEN=maxlen), ALLOCATABLE :: ttl(:), val(:,:)
-  CALL msg(TRIM(message)//':', modname)
-  DO ip = 1, SIZE(ides)                                              !--- Loop on parents tracers
-    nk = SIZE(ides(ip)%keys(1)%key)                                  !--- Same keys for each isotope
-    nt = SIZE(ides(ip)%keys)                                         !--- Number of isotopes
-    prf = 'i'//REPEAT('s',nk+1)                                      !--- Profile for table printing
-    ALLOCATE(ttl(nk+2), val(nt,nk+1))
-    ttl(1:2) = ['iq  ','name']; ttl(3:nk+2) = ides(ip)%keys(1)%key(:)!--- Titles line with keys names
-    val(:,1) = ides(ip)%keys(:)%name                                 !--- Values table 1st column: isotopes names  
-    DO ik = 1, nk
-      DO it = 1, nt
-        val(it,ik+1) = ides(ip)%keys(it)%val(ik)                     !--- Other columns: keys values
-      END DO
+  !=== READ PHYSICAL PARAMETERS FROM isoFile FILE
+  IF(test(readIsotopesFile_prv(isoFile, isotopes), lerr)) RETURN
+
+  !=== CHECK CONSISTENCY
+  IF(test(testIsotopes(), lerr)) RETURN
+
+  !=== SELECT FIRST ISOTOPES CLASS OR, IF POSSIBLE, WATER CLASS
+  IF(.NOT.test(isoSelect(1, .TRUE.), lerr)) THEN; IF(isotope%parent == 'H2O') iH2O = ixIso; END IF
+
+CONTAINS
+
+!------------------------------------------------------------------------------------------------------------------------------
+LOGICAL FUNCTION testIsotopes() RESULT(lerr)     !--- MAKE SURE MEMBERS OF AN ISOTOPES FAMILY ARE PRESENT IN THE SAME PHASES
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: ix, it, ip, np, iz, nz
+  TYPE(isot_type), POINTER :: i
+  DO ix = 1, nbIso
+    i => isotopes(ix)
+    !--- Check whether each isotope and tagging isotopic tracer is present in the same number of phases
+    DO it = 1, i%ntiso
+      np = SUM([(COUNT(tracers(:)%name == addPhase(i%trac(it), i%phase(ip:ip))), ip=1, i%nphas)])
+      IF(test(fmsg(TRIM(int2str(np))//' phases instead of '//TRIM(int2str(i%nphas))//' for '//TRIM(i%trac(it)), &
+        modname, np /= i%nphas), lerr)) RETURN
     END DO
-    IF(test(fmsg('Problem with the table content', modname, dispTable(prf, ttl, val, &
-            cat([(it,it=1,nt)]), rFmt='(EN8.4)', nColMax=maxTableWidth, nHead=2, sub=modname)), lerr)) RETURN
-    DEALLOCATE(ttl, val)
-  END DO        
-END FUNCTION dispIsotopes
-!==============================================================================================================================
-
-
+    DO it = 1, i%niso
+      nz = SUM([(COUNT(i%trac == TRIM(i%trac(it))//'_'//i%zone(iz)), iz=1, i%nzone)])
+      IF(test(fmsg(TRIM(int2str(nz))//' tagging zones instead of '//TRIM(int2str(i%nzone))//' for '//TRIM(i%trac(it)), &
+        modname, nz /= i%nzone), lerr)) RETURN
+    END DO
+  END DO
+END FUNCTION testIsotopes
+!------------------------------------------------------------------------------------------------------------------------------
+
+END FUNCTION readIsotopesFile
+!==============================================================================================================================
+
+
+!==============================================================================================================================
+!=== THE ROUTINE isoSelect IS USED TO SWITCH FROM AN ISOTOPE FAMILY TO ANOTHER: ISOTOPES DEPENDENT PARAMETERS ARE UPDATED
+!     Single generic "isoSelect" routine, using the predefined index of the parent (fast version) or its name (first call).
+!==============================================================================================================================
+LOGICAL FUNCTION isoSelectByName(iName, lVerbose) RESULT(lerr)
+   IMPLICIT NONE
+   CHARACTER(LEN=*),  INTENT(IN) :: iName
+   LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
+   INTEGER :: iIso
+   LOGICAL :: lV
+   lV = .FALSE.; IF(PRESENT(lVerbose)) lV = lVerbose
+   iIso = strIdx(isotopes(:)%parent, iName)
+   IF(test(iIso == 0, lerr)) THEN
+      niso = 0; ntiso = 0; nzone = 0; nphas = 0; isoCheck=.FALSE.
+      CALL msg('no isotope family named "'//TRIM(iName)//'"', ll=lV)
+      RETURN
+   END IF
+   lerr = isoSelectByIndex(iIso, lV)
+END FUNCTION isoSelectByName
+!==============================================================================================================================
+LOGICAL FUNCTION isoSelectByIndex(iIso, lVerbose) RESULT(lerr)
+   IMPLICIT NONE
+   INTEGER,           INTENT(IN) :: iIso
+   LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
+   LOGICAL :: lV
+   lv = .FALSE.; IF(PRESENT(lVerbose)) lv = lVerbose
+   lerr = .FALSE.
+   IF(iIso == ixIso) RETURN                                          !--- Nothing to do if the index is already OK
+   lerr = iIso<=0 .OR. iIso>SIZE(isotopes)
+   CALL msg('Inconsistent isotopes family index '//TRIM(int2str(iIso))//': should be > 0 and <= '&
+          //TRIM(int2str(SIZE(isotopes)))//'"', ll = lerr .AND. lV)
+   IF(lerr) RETURN
+   ixIso = iIso                                                      !--- Update currently selected family index
+   isotope  => isotopes(ixIso)                                       !--- Select corresponding component
+   isoKeys  => isotope%keys;     niso     = isotope%niso
+   isoName  => isotope%trac;     ntiso    = isotope%ntiso
+   isoZone  => isotope%zone;     nzone    = isotope%nzone
+   isoPhas  => isotope%phase;    nphas    = isotope%nphas
+   itZonIso => isotope%itZonIso; isoCheck = isotope%check
+   iqIsoPha => isotope%iqIsoPha
+END FUNCTION isoSelectByIndex
+!==============================================================================================================================
+
+
+!==============================================================================================================================
+!=== ADD THE <key>=<val> PAIR TO THE "ky[(:)]" KEY[S] DESCRIPTOR[S] OR THE <key>=<val(:)> PAIRS TO THE "ky(:)" KEYS DESCRIPTORS
 !==============================================================================================================================
 SUBROUTINE addKey_1(key, val, ky, lOverWrite)
-!------------------------------------------------------------------------------------------------------------------------------
-! Purpose: Add the <key>=<val> pair in the "ky" keys descriptor.
-!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=*),  INTENT(IN)    :: key, val
   TYPE(keys_type),   INTENT(INOUT) :: ky
   LOGICAL, OPTIONAL, INTENT(IN)    :: lOverWrite
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen), ALLOCATABLE :: k(:), v(:)
   INTEGER :: iky, nky
   LOGICAL :: lo
-!------------------------------------------------------------------------------------------------------------------------------
-  lo=.FALSE.; IF(PRESENT(lOverWrite)) lo=lOverWrite
+  lo=.TRUE.; IF(PRESENT(lOverWrite)) lo=lOverWrite
+  IF(.NOT.ALLOCATED(ky%key)) THEN
+    ALLOCATE(ky%key(1)); ky%key(1)=key
+    ALLOCATE(ky%val(1)); ky%val(1)=val
+    RETURN
+  END IF
   iky = strIdx(ky%key,key)
   IF(iky == 0) THEN
     nky = SIZE(ky%key)
-    IF(nky == 0) THEN; ky%key = [key]; ky%val = [val]; ELSE; ky%key = [ky%key, key]; ky%val = [ky%val, val]; END IF
-  ELSE IF(lo) THEN                                                   !--- Overwriting
+    ALLOCATE(k(nky+1)); k(1:nky) = ky%key; k(nky+1) = key; ky%key = k
+    ALLOCATE(v(nky+1)); v(1:nky) = ky%val; v(nky+1) = val; ky%val = v
+  ELSE IF(lo) THEN
     ky%key(iky) = key; ky%val(iky) = val
   END IF
@@ -1087,23 +1319,32 @@
 !==============================================================================================================================
 SUBROUTINE addKey_m(key, val, ky, lOverWrite)
-!------------------------------------------------------------------------------------------------------------------------------
-! Purpose: Add the <key>=<val> pair in all the components of the "ky" keys descriptor.
-!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=*),  INTENT(IN)    :: key, val
   TYPE(keys_type),   INTENT(INOUT) :: ky(:)
   LOGICAL, OPTIONAL, INTENT(IN)    :: lOverWrite
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: itr
-  LOGICAL :: lo
-!------------------------------------------------------------------------------------------------------------------------------
-  lo=.FALSE.; IF(PRESENT(lOverWrite)) lo=lOverWrite
-  DO itr = 1, SIZE(ky); CALL addKey_1(key, val, ky(itr), lo); END DO
+  DO itr = 1, SIZE(ky)
+    CALL addKey_1(key, val, ky(itr), lOverWrite)
+  END DO
 END SUBROUTINE addKey_m
 !==============================================================================================================================
+SUBROUTINE addKey_mm(key, val, ky, lOverWrite)
+  CHARACTER(LEN=*),  INTENT(IN)    :: key, val(:)
+  TYPE(keys_type),   INTENT(INOUT) :: ky(:)
+  LOGICAL, OPTIONAL, INTENT(IN)    :: lOverWrite
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: itr
+  DO itr = 1, SIZE(ky); CALL addKey_1(key, val(itr), ky(itr), lOverWrite); END DO
+END SUBROUTINE addKey_mm
+!==============================================================================================================================
+
+
+!==============================================================================================================================
+!=== OVERWRITE THE KEYS OF THE TRACER NAMED "tr0" WITH THE VALUES FOUND IN THE *.def FILES, IF ANY. ===========================
+!==============================================================================================================================
 SUBROUTINE addKeysFromDef(t, tr0)
-!------------------------------------------------------------------------------------------------------------------------------
-! Purpose: The values of the keys of the tracer named "tr0" are overwritten by the values found in the *.def files, if any.
-!------------------------------------------------------------------------------------------------------------------------------
   TYPE(trac_type), ALLOCATABLE, INTENT(INOUT) :: t(:)
   CHARACTER(LEN=*),             INTENT(IN)    :: tr0
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen) :: val
   INTEGER               :: ik, jd
@@ -1116,16 +1357,17 @@
 END SUBROUTINE addKeysFromDef
 !==============================================================================================================================
+
+
+!==============================================================================================================================
+!=== REMOVE THE KEYS NAMED "keyn(:)" FROM EITHER THE "itr"th OR ALL THE KEYS DESCRIPTORS OF "ky(:)" ===========================
+!==============================================================================================================================
 SUBROUTINE delKey_1(itr, keyn, ky)
-!------------------------------------------------------------------------------------------------------------------------------
-! Purpose: Internal routine.
-!   Remove <key>=<val> pairs in the "itr"th component of the "ky" keys descriptor.
-!------------------------------------------------------------------------------------------------------------------------------
   INTEGER,          INTENT(IN)    :: itr
   CHARACTER(LEN=*), INTENT(IN)    :: keyn(:)
   TYPE(trac_type),  INTENT(INOUT) :: ky(:)
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen), ALLOCATABLE :: k(:), v(:)
   LOGICAL,               ALLOCATABLE :: ll(:)
   INTEGER :: iky
-!------------------------------------------------------------------------------------------------------------------------------
   IF(itr<=0 .OR. itr>SIZE(ky, DIM=1)) RETURN                          !--- Index is out of range
   ll = [( ALL(keyn/=ky(itr)%keys%key(iky)), iky=1, SIZE(ky(itr)%keys%key) )]
@@ -1135,12 +1377,8 @@
 !==============================================================================================================================
 SUBROUTINE delKey(keyn, ky)
-!------------------------------------------------------------------------------------------------------------------------------
-! Purpose: Internal routine.
-!   Remove <key>=<val> pairs in all the components of the "t" tracers descriptor.
-!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=*), INTENT(IN)    :: keyn(:)
   TYPE(trac_type),  INTENT(INOUT) :: ky(:)
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: iky
-!------------------------------------------------------------------------------------------------------------------------------
   DO iky = 1, SIZE(ky); CALL delKey_1(iky, keyn, ky); END DO
 END SUBROUTINE delKey
@@ -1149,34 +1387,25 @@
 
 !==============================================================================================================================
-!=== PUBLIC ROUTINES: GET A KEY FROM A <key>=<val> LIST ; VECTORS, TRACER AND DATABASE VERSIONS ===============================
-!=== BEWARE !!! IF THE "ky" ARGUMENT IS NOT PRESENT, THEN THE VARIABLES "tracers" AND "isotopes" ARE USED. ====================
-!===     THEY ARE LOCAL TO THIS MODULE, SO MUST MUST BE INITIALIZED FIRST USING the "getKey_init" ROUTINE  ====================
-!==============================================================================================================================
-SUBROUTINE getKey_init(tracers_, isotopes_)
-  TYPE(trac_type), OPTIONAL, INTENT(IN) ::  tracers_(:)
-  TYPE(isot_type), OPTIONAL, INTENT(IN) :: isotopes_(:)
-  IF(PRESENT( tracers_))  tracers =  tracers_
-  IF(PRESENT(isotopes_)) isotopes = isotopes_
-END SUBROUTINE getKey_init
-!==============================================================================================================================
-CHARACTER(LEN=maxlen) FUNCTION fgetKeyByIndex_s1(itr, keyn, ky, def_val) RESULT(val)
-!------------------------------------------------------------------------------------------------------------------------------
-! Purpose: Internal function ; get a string formatted key value (returned argument) from its name and the tracer index.
-!------------------------------------------------------------------------------------------------------------------------------
-  INTEGER,                    INTENT(IN) :: itr
-  CHARACTER(LEN=*),           INTENT(IN) :: keyn
-  TYPE(keys_type),            INTENT(IN) :: ky(:)
-  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: def_val
+!================ GET THE VALUE OF A KEY FROM A "keys_type" DERIVED TYPE ; THE RESULT IS THE RETURNED VALUE ===================
+!==============================================================================================================================
+CHARACTER(LEN=maxlen) FUNCTION fgetKeyIdx_s1(itr, keyn, ky, def_val, lerr) RESULT(val)
+  INTEGER,                    INTENT(IN)  :: itr
+  CHARACTER(LEN=*),           INTENT(IN)  :: keyn
+  TYPE(keys_type),            INTENT(IN)  :: ky(:)
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN)  :: def_val
+  LOGICAL,          OPTIONAL, INTENT(OUT) :: lerr
 !------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: iky
-  iky = 0;  IF(itr >  0 .AND. itr <= SIZE(ky)) iky = strIdx(ky(itr)%key(:), keyn)
-  val = ''; IF(iky /= 0) val = ky(itr)%val(iky)                      !--- Key was found
-  IF(PRESENT(def_val) .AND. iky == 0) val = def_val                  !--- Default value from arguments
-END FUNCTION fgetKeyByIndex_s1
-!==============================================================================================================================
-CHARACTER(LEN=maxlen) FUNCTION fgetKeyByName_s1(tname, keyn, ky, def_val, lerr) RESULT(val)
-!------------------------------------------------------------------------------------------------------------------------------
-! Purpose: Internal function ; get a string formatted key value (returned argument) from its name and the tracer name.
-!------------------------------------------------------------------------------------------------------------------------------
+  LOGICAL :: ler
+  iky = 0; val = ''
+  IF(.NOT.test(itr <= 0 .OR. itr > SIZE(ky), ler)) iky = strIdx(ky(itr)%key(:), keyn)    !--- Correct index
+  IF(.NOT.test(iky == 0, ler))                     val = ky(itr)%val(iky)                !--- Found key
+  IF(iky == 0) THEN
+    IF(.NOT.test(.NOT.PRESENT(def_val), ler))      val = def_val                         !--- Default value
+  END IF
+  IF(PRESENT(lerr)) lerr = ler
+END FUNCTION fgetKeyIdx_s1
+!==============================================================================================================================
+CHARACTER(LEN=maxlen) FUNCTION fgetKeyNam_s1(tname, keyn, ky, def_val, lerr) RESULT(val)
   CHARACTER(LEN=*),           INTENT(IN)  :: tname, keyn
   TYPE(keys_type),            INTENT(IN)  :: ky(:)
@@ -1184,61 +1413,116 @@
   LOGICAL,          OPTIONAL, INTENT(OUT) :: lerr
 !------------------------------------------------------------------------------------------------------------------------------
-  INTEGER :: iky, itr
-  val = ''; iky = 0
-  itr = strIdx(ky(:)%name, tname)                                    !--- Get the index of the wanted tracer
-  IF(PRESENT(lerr)) lerr = itr==0; IF(itr == 0) RETURN
-  IF(itr >  0 .AND. itr <= SIZE(ky)) iky = strIdx(ky(itr)%key(:), keyn)
-  IF(iky /= 0) val = ky(itr)%val(iky)                                !--- Key was found
-  IF(PRESENT(def_val) .AND. iky == 0) val = def_val                  !--- Default value from arguments
-END FUNCTION fgetKeyByName_s1
+  val = fgetKeyIdx_s1(strIdx(ky(:)%name, tname), keyn, ky, def_val, lerr)
+END FUNCTION fgetKeyNam_s1
+!==============================================================================================================================
+FUNCTION fgetKeys(keyn, ky, def_val, lerr) RESULT(val)
+CHARACTER(LEN=maxlen),        ALLOCATABLE :: val(:)
+  CHARACTER(LEN=*),           INTENT(IN)  :: keyn
+  TYPE(keys_type),            INTENT(IN)  :: ky(:)
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN)  :: def_val
+  LOGICAL,          OPTIONAL, INTENT(OUT) :: lerr
+!------------------------------------------------------------------------------------------------------------------------------
+  LOGICAL :: ler(SIZE(ky))
+  INTEGER :: it
+  val = [(fgetKeyIdx_s1(it, keyn, ky, def_val, ler(it)), it = 1, SIZE(ky))]
+  IF(PRESENT(lerr)) lerr = ANY(ler)
+END FUNCTION fgetKeys
+!==============================================================================================================================
+
+
+!==============================================================================================================================
+!========== GET THE VALUE OF A KEY FROM A "keys_type" DERIVED TYPE ; THE RETURNED VALUE IS THE ERROR CODE        ==============
+!==========  The key "keyn" is searched in: 1)           "ky(:)%name" (if given)                                 ==============
+!==========                                 2)      "tracers(:)%name"                                            ==============
+!==========                                 3) "isotope%keys(:)%name"                                            ==============
+!==========  for the tracer[s] "tname[(:)]" (if given) or all the available tracers from the used set otherwise. ==============
+!==========  The type of the returned value(s) can be string, integer or real, scalar or vector                  ==============
 !==============================================================================================================================
 LOGICAL FUNCTION getKeyByName_s1(keyn, val, tname, ky) RESULT(lerr)
-  !--- Purpose: Get the value of the key named "keyn" for the tracer named "tnam".
-  !     * "ky" unspecified: try in "tracers" for "tnam" with phase and tagging suffixes, then in "isotopes" without.
-  !     * "ky"   specified: try in "ky"      for "tnam" with phase and tagging suffixes, then without.
-  !    The returned error code is always .FALSE.: an empty string is returned when the key hasn't been found.
   CHARACTER(LEN=*),          INTENT(IN)  :: keyn
   CHARACTER(LEN=maxlen),     INTENT(OUT) :: val
   CHARACTER(LEN=*),          INTENT(IN)  :: tname
   TYPE(keys_type), OPTIONAL, INTENT(IN)  :: ky(:)
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen) :: tnam
-  INTEGER, ALLOCATABLE  :: is(:)
-  INTEGER :: i, itr
-  tnam = delPhase(strHead(tname,'_',.FALSE.))                        !--- Remove tag and phase
-  IF(PRESENT(ky)) THEN
-    val = fgetKeyByName_s1(tname, keyn, ky, lerr=lerr)               !--- "ky" and "tname"
-    IF(val /= '' .OR. lerr)      RETURN
-    val = fgetKeyByName_s1(tnam,  keyn, ky, lerr=lerr)               !--- "ky" and "tnam"
+  tnam = strHead(delPhase(tname),'_',.TRUE.)                                             !--- Remove phase and tag
+  IF(PRESENT(ky)) THEN                                                                   !=== KEY FROM "ky"
+               val = fgetKeyNam_s1(tname, keyn, ky,           lerr=lerr)                 !--- "ky" and "tname"
+    IF( lerr ) val = fgetKeyNam_s1(tnam,  keyn, ky,           lerr=lerr)                 !--- "ky" and "tnam"
   ELSE
-    IF(.NOT.ALLOCATED(tracers))  RETURN
-    val = fgetKeyByName_s1(tname, keyn, tracers(:)%keys, lerr=lerr)  !--- "tracers" and "tname"
-    IF(val /= ''.AND..NOT.lerr)  RETURN
-    IF(.NOT.ALLOCATED(isotopes)) RETURN
-    IF(SIZE(isotopes) == 0)      RETURN
-    !--- Search the "is" isotopes class index of the isotope named "tnam"
-    is = find([(ANY(isotopes(i)%keys(:)%name == tnam), i=1, SIZE(isotopes))])
-    IF(test(SIZE(is) == 0,lerr)) RETURN
-    val = fgetKeyByName_s1(tname, keyn, isotopes(is(1))%keys(:),lerr=lerr)!--- "isotopes" and "tnam"
+    IF(         .NOT.test(.NOT.ALLOCATED(tracers ), lerr)) lerr = SIZE(tracers ) == 0    !=== KEY FROM "tracers"
+    IF(.NOT.lerr) THEN
+               val = fgetKeyNam_s1(tname, keyn, tracers%keys, lerr=lerr)                 !--- "ky" and "tname"
+      IF(lerr) val = fgetKeyNam_s1(tnam,  keyn, tracers%keys, lerr=lerr)                 !--- "ky" and "tnam"
+    END IF
+    IF(lerr.AND..NOT.test(.NOT.ALLOCATED(isotopes), lerr)) lerr = SIZE(isotopes) == 0    !=== KEY FROM "isotope"
+    IF(.NOT.lerr) THEN
+               val = fgetKeyNam_s1(tname, keyn, isotope%keys, lerr=lerr)                 !--- "ky" and "tname"
+      IF(lerr) val = fgetKeyNam_s1(tnam,  keyn, isotope%keys, lerr=lerr)                 !--- "ky" and "tnam"
+    END IF
   END IF
 END FUNCTION getKeyByName_s1
 !==============================================================================================================================
-LOGICAL FUNCTION getKeyByName_sm(keyn, val, tname, ky) RESULT(lerr)
+LOGICAL FUNCTION getKeyByName_s1m(keyn, val, tname, ky) RESULT(lerr)
   CHARACTER(LEN=*),                   INTENT(IN)  :: keyn
-  CHARACTER(LEN=maxlen), ALLOCATABLE, INTENT(OUT) ::   val(:)
-  CHARACTER(LEN=*),         OPTIONAL, INTENT(IN)  :: tname(:)
-  TYPE(keys_type),          OPTIONAL, INTENT(IN)  ::    ky(:)
-  TYPE(keys_type),           POINTER :: k(:)
-  CHARACTER(LEN=maxlen), ALLOCATABLE :: n(:)
+  CHARACTER(LEN=maxlen), ALLOCATABLE, INTENT(OUT) :: val(:)
+  CHARACTER(LEN=*),                   INTENT(IN)  :: tname
+  TYPE(keys_type),          OPTIONAL, INTENT(IN)  :: ky(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen) :: sval
+  lerr = getKeyByName_s1(keyn, sval, tname, ky)
+  IF(test(fmsg('missing key "'//TRIM(keyn)//'" for tracer "'//TRIM(tname)//'"', modname, lerr), lerr)) RETURN
+  lerr = strParse(sval, ',', val)
+END FUNCTION getKeyByName_s1m
+!==============================================================================================================================
+LOGICAL FUNCTION getKeyByName_sm(keyn, val, tname, ky, nam) RESULT(lerr)
+  CHARACTER(LEN=*),                             INTENT(IN)  :: keyn
+  CHARACTER(LEN=maxlen),           ALLOCATABLE, INTENT(OUT) :: val(:)
+  CHARACTER(LEN=*),                             INTENT(IN)  :: tname(:)
+  TYPE(keys_type),       OPTIONAL, TARGET,      INTENT(IN)  :: ky(:)
+  CHARACTER(LEN=maxlen), OPTIONAL, ALLOCATABLE, INTENT(OUT) :: nam(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  TYPE(keys_type), POINTER ::  keys(:)
+  LOGICAL :: lk, lt, li
   INTEGER :: iq, nq
-  IF(test(.NOT.(PRESENT(tname).OR.PRESENT(ky)), lerr)) RETURN
-  IF(PRESENT(ky   )) nq = SIZE(ky%name)
-  IF(PRESENT(tname)) nq = SIZE(  tname)
+
+  !--- DETERMINE THE DATABASE TO BE USED (ky, tracers or isotope)
+  lk = PRESENT(ky)
+  lt = .NOT.lk .AND. ALLOCATED(tracers);  IF(lt) lt = SIZE(tracers)  /= 0; IF(lt) lt = ANY(tracers(1)%keys%key(:) == keyn)
+  li = .NOT.lt .AND. ALLOCATED(isotopes); IF(li) li = SIZE(isotopes) /= 0; IF(li) li = ANY(isotope%keys(1)%key(:) == keyn)
+
+  !--- LINK "keys" TO THE RIGHT DATABASE
+  IF(test(.NOT.ANY([lk,lt,li]), lerr)) RETURN
+  IF(lk) keys => ky(:)
+  IF(lt) keys => tracers(:)%keys
+  IF(li) keys => isotope%keys(:)
+
+  !--- GET THE DATA
+  nq = SIZE(tname)
   ALLOCATE(val(nq))
-  IF(PRESENT(tname)) THEN
-    IF(     PRESENT(ky)) lerr = ANY([(getKeyByName_s1(keyn, val(iq), tname(iq),   ky), iq=1, nq)])
-    IF(.NOT.PRESENT(ky)) lerr = ANY([(getKeyByName_s1(keyn, val(iq), tname(iq)      ), iq=1, nq)])
-  ELSE;                  lerr = ANY([(getKeyByName_s1(keyn, val(iq), ky(iq)%name, ky), iq=1, nq)])
+  lerr = ANY([(getKeyByName_s1(keyn, val(iq), tname(iq), keys(:)), iq=1, nq)])
+  IF(PRESENT(nam)) nam = tname(:)
+
+END FUNCTION getKeyByName_sm
+!==============================================================================================================================
+LOGICAL FUNCTION getKey_sm(keyn, val, ky, nam) RESULT(lerr)
+  CHARACTER(LEN=*),                             INTENT(IN)  :: keyn
+  CHARACTER(LEN=maxlen),           ALLOCATABLE, INTENT(OUT) :: val(:)
+  TYPE(keys_type),       OPTIONAL,              INTENT(IN)  :: ky(:)
+  CHARACTER(LEN=maxlen), OPTIONAL, ALLOCATABLE, INTENT(OUT) :: nam(:)
+!------------------------------------------------------------------------------------------------------------------------------
+! Note: if names are repeated, getKeyByName_sm can't be used ; this routine, using indexes, must be used instead.
+  IF(PRESENT(ky)) THEN                                                                   !=== KEY FROM "ky"
+    val = fgetKeys(keyn, ky, lerr=lerr)
+    IF(PRESENT(nam)) nam = ky(:)%name
+  ELSE
+    IF(         .NOT.test(.NOT.ALLOCATED(tracers ), lerr)) lerr = SIZE(tracers ) == 0    !=== KEY FROM "tracers"
+    IF(.NOT.lerr) val = fgetKeys(keyn, tracers%keys, lerr=lerr)
+    IF(.NOT.lerr.AND.PRESENT(nam)) nam = tracers(:)%keys%name
+    IF(lerr.AND..NOT.test(.NOT.ALLOCATED(isotopes), lerr)) lerr = SIZE(isotopes) == 0    !=== KEY FROM "isotope"
+    IF(.NOT.lerr) val = fgetKeys(keyn, isotope%keys, lerr=lerr)
+    IF(.NOT.lerr.AND.PRESENT(nam)) nam = isotope%keys(:)%name
   END IF
-END FUNCTION getKeyByName_sm
+END FUNCTION getKey_sm
 !==============================================================================================================================
 LOGICAL FUNCTION getKeyByName_i1(keyn, val, tname, ky) RESULT(lerr)
@@ -1247,31 +1531,61 @@
   CHARACTER(LEN=*),          INTENT(IN)  :: tname
   TYPE(keys_type), OPTIONAL, INTENT(IN)  :: ky(:)
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen) :: sval
   INTEGER :: ierr
-  IF(     PRESENT(ky)) lerr = getKeyByName_s1(keyn, sval, tname, ky)
-  IF(.NOT.PRESENT(ky)) lerr = getKeyByName_s1(keyn, sval, tname)
-  IF(test(fmsg('key "'//TRIM(keyn)//'" or tracer "'//TRIM(tname)//'" is missing',        modname, lerr), lerr)) RETURN
+  lerr = getKeyByName_s1(keyn, sval, tname, ky)
+  IF(test(fmsg('key "'//TRIM(keyn)//'" or tracer "'//TRIM(tname)//'" is missing', modname, lerr), lerr)) RETURN
   READ(sval, *, IOSTAT=ierr) val
+  IF(test(fmsg('key "'//TRIM(keyn)//'" of tracer "'//TRIM(tname)//'" is not an integer', modname, ierr/=0), lerr)) RETURN
+END FUNCTION getKeyByName_i1
+!==============================================================================================================================
+LOGICAL FUNCTION getKeyByName_i1m(keyn, val, tname, ky) RESULT(lerr)
+  CHARACTER(LEN=*),          INTENT(IN)  :: keyn
+  INTEGER,      ALLOCATABLE, INTENT(OUT) :: val(:)
+  CHARACTER(LEN=*),          INTENT(IN)  :: tname
+  TYPE(keys_type), OPTIONAL, INTENT(IN)  ::  ky(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: sval(:)
+  INTEGER :: ierr, iq, nq
+  IF(test(getKeyByName_s1m(keyn, sval, tname, ky), lerr)) RETURN
+  nq = SIZE(sval); ALLOCATE(val(nq))
+  lerr = .FALSE.; DO iq=1, nq; READ(sval(iq), *, IOSTAT=ierr) val(iq); lerr = lerr .OR. ierr /= 0; END DO
   IF(test(fmsg('key "'//TRIM(keyn)//'" of tracer "'//TRIM(tname)//'" is not an integer', modname, lerr), lerr)) RETURN
-END FUNCTION getKeyByName_i1
-!==============================================================================================================================
-LOGICAL FUNCTION getKeyByName_im(keyn, val, tname, ky) RESULT(lerr)
-  CHARACTER(LEN=*),           INTENT(IN)  :: keyn
-  INTEGER,       ALLOCATABLE, INTENT(OUT) ::   val(:)
-  CHARACTER(LEN=*), OPTIONAL, INTENT(IN)  :: tname(:)
-  TYPE(keys_type),  OPTIONAL, INTENT(IN)  ::    ky(:)
-  TYPE(keys_type),           POINTER :: k(:)
-  CHARACTER(LEN=maxlen), ALLOCATABLE :: n(:)
-  INTEGER :: iq, nq
-  IF(test(.NOT.(PRESENT(tname).OR.PRESENT(ky)), lerr)) RETURN
-  IF(PRESENT(ky   )) nq = SIZE(ky%name)
-  IF(PRESENT(tname)) nq = SIZE(  tname)
-  ALLOCATE(val(nq))
-  IF(PRESENT(tname)) THEN
-    IF(     PRESENT(ky)) lerr = ANY([(getKeyByName_i1(keyn, val(iq), tname(iq),   ky), iq=1, nq)])
-    IF(.NOT.PRESENT(ky)) lerr = ANY([(getKeyByName_i1(keyn, val(iq), tname(iq)      ), iq=1, nq)])
-  ELSE;                  lerr = ANY([(getKeyByName_i1(keyn, val(iq), ky(iq)%name, ky), iq=1, nq)])
-  END IF
+END FUNCTION getKeyByName_i1m
+!==============================================================================================================================
+LOGICAL FUNCTION getKeyByName_im(keyn, val, tname, ky, nam) RESULT(lerr)
+  CHARACTER(LEN=*),                             INTENT(IN)  ::  keyn
+  INTEGER,                         ALLOCATABLE, INTENT(OUT) ::   val(:)
+  CHARACTER(LEN=*),                             INTENT(IN)  :: tname(:)
+  TYPE(keys_type),       OPTIONAL,              INTENT(IN)  ::    ky(:)
+  CHARACTER(LEN=maxlen), OPTIONAL, ALLOCATABLE, INTENT(OUT) ::   nam(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: sval(:), names(:)
+  INTEGER :: ierr, iq, nq
+  IF(test(getKeyByName_sm(keyn, sval, tname, ky, names), lerr)) RETURN
+  nq = SIZE(sval); ALLOCATE(val(nq))
+  DO iq = 1, nq                                                      !--- CONVERT THE KEYS TO INTEGERS
+    READ(sval(iq), *, IOSTAT=ierr) val(iq)
+    IF(test(fmsg('key "'//TRIM(keyn)//'" of tracer "'//TRIM(names(iq))//'" is not an integer', modname, ierr/=0), lerr)) RETURN
+  END DO
+  IF(PRESENT(nam)) nam = names(:)
 END FUNCTION getKeyByName_im
+!==============================================================================================================================
+LOGICAL FUNCTION getKey_im(keyn, val, ky, nam) RESULT(lerr)
+  CHARACTER(LEN=*),                             INTENT(IN)  :: keyn
+  INTEGER,                         ALLOCATABLE, INTENT(OUT) ::  val(:)
+  TYPE(keys_type),       OPTIONAL,              INTENT(IN)  ::   ky(:)
+  CHARACTER(LEN=maxlen), OPTIONAL, ALLOCATABLE, INTENT(OUT) ::  nam(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: sval(:), names(:)
+  INTEGER :: ierr, iq, nq
+  IF(test(getKey_sm(keyn, sval, ky, names), lerr)) RETURN
+  nq = SIZE(sval); ALLOCATE(val(nq))
+  DO iq = 1, nq
+    READ(sval(iq), *, IOSTAT=ierr) val(iq)
+    IF(test(fmsg('key "'//TRIM(keyn)//'" of tracer "'//TRIM(names(iq))//'" is not an integer', modname, ierr/=0), lerr)) RETURN
+  END DO
+  IF(PRESENT(nam)) nam = names
+END FUNCTION getKey_im
 !==============================================================================================================================
 LOGICAL FUNCTION getKeyByName_r1(keyn, val, tname, ky) RESULT(lerr)
@@ -1280,31 +1594,153 @@
   CHARACTER(LEN=*),          INTENT(IN)  :: tname
   TYPE(keys_type), OPTIONAL, INTENT(IN)  :: ky(:)
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen) :: sval
   INTEGER :: ierr
-  IF(     PRESENT(ky)) lerr = getKeyByName_s1(keyn, sval, tname, ky)
-  IF(.NOT.PRESENT(ky)) lerr = getKeyByName_s1(keyn, sval, tname)
+  lerr = getKeyByName_s1(keyn, sval, tname, ky)
   IF(test(fmsg('key "'//TRIM(keyn)//'" or tracer "'//TRIM(tname)//'" is missing',    modname, lerr), lerr)) RETURN
   READ(sval, *, IOSTAT=ierr) val
-  IF(test(fmsg('key "'//TRIM(keyn)//'" of tracer "'//TRIM(tname)//'" is not a real', modname, lerr), lerr)) RETURN
+  IF(test(fmsg('key "'//TRIM(keyn)//'" of tracer "'//TRIM(tname)//'" is not a real', modname, ierr/=0), lerr)) RETURN
 END FUNCTION getKeyByName_r1
 !==============================================================================================================================
-LOGICAL FUNCTION getKeyByName_rm(keyn, val, tname, ky) RESULT(lerr)
+LOGICAL FUNCTION getKeyByName_r1m(keyn, val, tname, ky) RESULT(lerr)
   CHARACTER(LEN=*),           INTENT(IN)  :: keyn
-  REAL,          ALLOCATABLE, INTENT(OUT) ::   val(:)
-  CHARACTER(LEN=*), OPTIONAL, INTENT(IN)  :: tname(:)
-  TYPE(keys_type),  OPTIONAL, INTENT(IN)  ::    ky(:)
-  TYPE(keys_type),           POINTER :: k(:)
-  CHARACTER(LEN=maxlen), ALLOCATABLE :: n(:)
+  REAL,          ALLOCATABLE, INTENT(OUT) :: val(:)
+  CHARACTER(LEN=*),           INTENT(IN)  :: tname
+  TYPE(keys_type),  OPTIONAL, INTENT(IN)  ::  ky(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: sval(:)
+  INTEGER :: ierr, iq, nq
+  IF(test(getKeyByName_s1m(keyn, sval, tname, ky), lerr)) RETURN
+  nq = SIZE(sval); ALLOCATE(val(nq))
+  lerr = .FALSE.; DO iq=1, nq; READ(sval(iq), *, IOSTAT=ierr) val(iq); lerr = lerr .OR. ierr /= 0; END DO
+  IF(test(fmsg('key "'//TRIM(keyn)//'" of tracer "'//TRIM(tname)//'" is not a vector of reals', modname, lerr), lerr)) RETURN
+END FUNCTION getKeyByName_r1m
+!==============================================================================================================================
+LOGICAL FUNCTION getKeyByName_rm(keyn, val, tname, ky, nam) RESULT(lerr)
+  CHARACTER(LEN=*),                             INTENT(IN)  ::  keyn
+  REAL,                            ALLOCATABLE, INTENT(OUT) ::   val(:)
+  CHARACTER(LEN=*),                             INTENT(IN)  :: tname(:)
+  TYPE(keys_type),       OPTIONAL,              INTENT(IN)  ::    ky(:)
+  CHARACTER(LEN=maxlen), OPTIONAL, ALLOCATABLE, INTENT(OUT) ::   nam(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: sval(:), names(:)
+  INTEGER :: ierr, iq, nq
+  IF(test(getKeyByName_sm(keyn, sval, tname, ky, names), lerr)) RETURN
+  nq = SIZE(sval); ALLOCATE(val(nq))
+  DO iq = 1, nq                                                      !--- CONVERT THE KEYS TO INTEGERS
+    READ(sval(iq), *, IOSTAT=ierr) val(iq)
+    IF(test(fmsg('key "'//TRIM(keyn)//'" of tracer "'//TRIM(names(iq))//'" is not a real', modname, ierr/=0), lerr)) RETURN
+  END DO
+  IF(PRESENT(nam)) nam = names
+END FUNCTION getKeyByName_rm
+!==============================================================================================================================
+LOGICAL FUNCTION getKey_rm(keyn, val, ky, nam) RESULT(lerr)
+  CHARACTER(LEN=*),                             INTENT(IN)  :: keyn
+  REAL,                            ALLOCATABLE, INTENT(OUT) ::  val(:)
+  TYPE(keys_type),       OPTIONAL,              INTENT(IN)  ::   ky(:)
+  CHARACTER(LEN=maxlen), OPTIONAL, ALLOCATABLE, INTENT(OUT) ::  nam(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: sval(:), names(:)
+  INTEGER :: ierr, iq, nq
+  IF(test(getKey_sm(keyn, sval, ky, names), lerr)) RETURN
+  nq = SIZE(sval); ALLOCATE(val(nq))
+  DO iq = 1, nq                                                      !--- CONVERT THE KEYS TO INTEGERS
+    READ(sval(iq), *, IOSTAT=ierr) val(iq)
+    IF(test(fmsg('key "'//TRIM(keyn)//'" of tracer "'//TRIM(names(iq))//'" is not a real', modname, ierr/=0), lerr)) RETURN
+  END DO
+  IF(PRESENT(nam)) nam = names
+END FUNCTION getKey_rm
+!==============================================================================================================================
+LOGICAL FUNCTION getKeyByName_l1(keyn, val, tname, ky) RESULT(lerr)
+  USE strings_mod, ONLY: str2bool
+  CHARACTER(LEN=*),          INTENT(IN)  :: keyn
+  LOGICAL,                   INTENT(OUT) :: val
+  CHARACTER(LEN=*),          INTENT(IN)  :: tname
+  TYPE(keys_type), OPTIONAL, INTENT(IN)  :: ky(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen) :: sval
+  lerr = getKeyByName_s1(keyn, sval, tname, ky)
+  IF(test(fmsg('key "'//TRIM(keyn)//'" or tracer "'//TRIM(tname)//'" is missing', modname, lerr), lerr)) RETURN
+  val = str2bool(sval)
+END FUNCTION getKeyByName_l1
+!==============================================================================================================================
+LOGICAL FUNCTION getKeyByName_l1m(keyn, val, tname, ky) RESULT(lerr)
+  USE strings_mod, ONLY: str2bool
+  CHARACTER(LEN=*),           INTENT(IN)  :: keyn
+  LOGICAL,       ALLOCATABLE, INTENT(OUT) :: val(:)
+  CHARACTER(LEN=*),           INTENT(IN)  :: tname
+  TYPE(keys_type),  OPTIONAL, INTENT(IN)  ::  ky(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: sval(:)
   INTEGER :: iq, nq
-  IF(test(.NOT.(PRESENT(tname).OR.PRESENT(ky)), lerr)) RETURN
-  IF(PRESENT(ky   )) nq = SIZE(ky%name)
-  IF(PRESENT(tname)) nq = SIZE(  tname)
-  ALLOCATE(val(nq))
-  IF(PRESENT(tname)) THEN
-    IF(     PRESENT(ky)) lerr = ANY([(getKeyByName_r1(keyn, val(iq), tname(iq),   ky), iq=1, nq)])
-    IF(.NOT.PRESENT(ky)) lerr = ANY([(getKeyByName_r1(keyn, val(iq), tname(iq)      ), iq=1, nq)])
-  ELSE;                  lerr = ANY([(getKeyByName_r1(keyn, val(iq), ky(iq)%name, ky), iq=1, nq)])
+  IF(test(getKeyByName_s1m(keyn, sval, tname, ky), lerr)) RETURN
+  nq = SIZE(sval); ALLOCATE(val(nq))
+  lerr = .FALSE.; DO iq=1, nq; val(iq)=str2bool(sval(iq)); END DO
+END FUNCTION getKeyByName_l1m
+!==============================================================================================================================
+LOGICAL FUNCTION getKeyByName_lm(keyn, val, tname, ky, nam) RESULT(lerr)
+  USE strings_mod, ONLY: str2bool
+  CHARACTER(LEN=*),                             INTENT(IN)  ::  keyn
+  LOGICAL,                         ALLOCATABLE, INTENT(OUT) ::   val(:)
+  CHARACTER(LEN=*),                             INTENT(IN)  :: tname(:)
+  TYPE(keys_type),       OPTIONAL,              INTENT(IN)  ::    ky(:)
+  CHARACTER(LEN=maxlen), OPTIONAL, ALLOCATABLE, INTENT(OUT) ::   nam(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: sval(:)
+  INTEGER :: iq, nq
+  IF(test(getKeyByName_sm(keyn, sval, tname, ky, nam), lerr)) RETURN
+  nq = SIZE(sval); ALLOCATE(val(nq))
+  lerr = .FALSE.; DO iq=1, nq; val(iq)=str2bool(sval(iq)); END DO
+END FUNCTION getKeyByName_lm
+!==============================================================================================================================
+LOGICAL FUNCTION getKey_lm(keyn, val, ky, nam) RESULT(lerr)
+  USE strings_mod, ONLY: str2bool
+  CHARACTER(LEN=*),                             INTENT(IN)  :: keyn
+  LOGICAL,                         ALLOCATABLE, INTENT(OUT) ::  val(:)
+  TYPE(keys_type),       OPTIONAL,              INTENT(IN)  ::   ky(:)
+  CHARACTER(LEN=maxlen), OPTIONAL, ALLOCATABLE, INTENT(OUT) ::  nam(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=maxlen), ALLOCATABLE :: sval(:)
+  INTEGER :: iq, nq
+  IF(test(getKey_sm(keyn, sval, ky, nam), lerr)) RETURN
+  nq = SIZE(sval); ALLOCATE(val(nq))
+  lerr = .FALSE.; DO iq=1, nq; val(iq)=str2bool(sval(iq)); END DO
+END FUNCTION getKey_lm
+!==============================================================================================================================
+
+
+!==============================================================================================================================
+!=== ROUTINES TO GET OR PUT TRACERS AND ISOTOPES DATABASES, SINCE tracers AND isotopes ARE PRIVATE VARIABLES ==================
+!==============================================================================================================================
+SUBROUTINE setKeysDBase(tracers_, isotopes_, isotope_)
+  TYPE(trac_type), OPTIONAL, INTENT(IN) ::  tracers_(:)
+  TYPE(isot_type), OPTIONAL, INTENT(IN) :: isotopes_(:)
+  TYPE(isot_type), OPTIONAL, INTENT(IN) :: isotope_
+!------------------------------------------------------------------------------------------------------------------------------
+  TYPE(isot_type), ALLOCATABLE :: iso(:)
+  INTEGER :: ix, nbIso
+  IF(PRESENT( tracers_)) THEN;  tracers =  tracers_; ELSE; ALLOCATE( tracers(0)); END IF
+  IF(PRESENT(isotopes_)) THEN; isotopes = isotopes_; ELSE; ALLOCATE(isotopes(0)); END IF
+  IF(PRESENT(isotope_ )) THEN
+    ix = strIdx(isotopes(:)%parent, isotope_%parent)
+    IF(ix /= 0) THEN
+      isotopes(ix) = isotope_
+    ELSE
+      nbIso = SIZE(isotopes); ALLOCATE(iso(nbIso+1)); iso(1:nbIso) = isotopes; iso(nbIso+1) = isotope_
+      CALL MOVE_ALLOC(FROM=iso, TO=isotopes)
+    END IF
   END IF
-END FUNCTION getKeyByName_rm
+END SUBROUTINE setKeysDBase
+!==============================================================================================================================
+SUBROUTINE getKeysDBase(tracers_, isotopes_, isotope_)
+  TYPE(trac_type), OPTIONAL, ALLOCATABLE, INTENT(OUT) ::  tracers_(:)
+  TYPE(isot_type), OPTIONAL, ALLOCATABLE, INTENT(OUT) :: isotopes_(:)
+  TYPE(isot_type), OPTIONAL,              INTENT(OUT) :: isotope_
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: ix
+  IF(PRESENT( tracers_)) THEN;  tracers_ =  tracers; ELSE; ALLOCATE( tracers_(0)); END IF
+  IF(PRESENT(isotopes_)) THEN; isotopes_ = isotopes; ELSE; ALLOCATE(isotopes_(0)); END IF
+  IF(PRESENT(isotope_ )) THEN; ix = strIdx(isotopes(:)%parent, isotope%parent); IF(ix /= 0) isotope_=isotopes(ix); END IF
+END SUBROUTINE getKeysDBase
 !==============================================================================================================================
 
@@ -1315,28 +1751,21 @@
 ELEMENTAL CHARACTER(LEN=maxlen) FUNCTION delPhase(s) RESULT(out)
   CHARACTER(LEN=*), INTENT(IN) :: s
-  INTEGER :: l, i, ix
-  CHARACTER(LEN=maxlen) :: sh, st
-  out = s
-  IF(s == '') RETURN                                                           !--- Empty string: nothing to do
-
-  !--- Special case: old phases for water, no phases separator
-  i = INDEX(s,'_'); sh = s; IF(i/=0) sh=s(1:i-1); st='H2O'; IF(i/=0) st='H2O_'//s(i+1:LEN_TRIM(s))
-  IF(ANY([('H2O'//old_phases(ix:ix), ix=1, nphases)] == sh)) THEN; out=st; RETURN; END IF
-
-  !--- Index of found phase in "known_phases"
-  ix = MAXLOC( [(i, i=1,nphases)], MASK=[( INDEX(s, phases_sep//known_phases(i:i))/=0, i=1, nphases)], DIM=1 )
-  IF(ix == 0) RETURN                                                           !--- No phase pattern found
-  i = INDEX(s, phases_sep//known_phases(ix:ix))                                !--- Index of <sep><pha> pattern in "str"
-  l = LEN_TRIM(s)
-  IF(i == l-1) THEN                                                            !--- <var><sep><pha>       => return <var>
-    out = s(1:l-2)
-  ELSE IF(s(i+2:i+2) == '_') THEN                                              !--- <var><sep><pha>_<tag> => return <var>_<tag>
-    out = s(1:i-1)//s(i+2:l)
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: ix, ip, ns
+  out = s; ns = LEN_TRIM(s)
+  IF(s == '' .OR. ns<=2) RETURN                                                !--- Empty string or LEN(name)<=2: nothing to do
+  IF(s(1:3)=='H2O' .AND. INDEX(old_phases,s(4:4))/=0 .AND. (ns==4 .OR. s(5:5)=='_')) THEN
+    out='H2O'//s(5:ns)                                                         !--- H2O<phase>[_<iso>][_<tag>]
+  ELSE IF(s(ns-1:ns-1)==phases_sep .AND. INDEX(known_phases,s(ns:ns))/=0) THEN
+    out = s(1:ns-2); RETURN                                                    !--- <var><phase_sep><phase>
+  ELSE; DO ip = 1, nphases; ix = INDEX(s, phases_sep//known_phases(ip:ip)//'_'); IF(ix /= 0) EXIT; END DO
+    IF(ip /= nphases+1) out = s(1:ix-1)//s(ix+2:ns)                            !--- <var><phase_sep><phase>_<tag>
   END IF
 END FUNCTION delPhase
-!------------------------------------------------------------------------------------------------------------------------------
+!==============================================================================================================================
 CHARACTER(LEN=maxlen) FUNCTION addPhase_s1(s,pha) RESULT(out)
   CHARACTER(LEN=*),           INTENT(IN) :: s
   CHARACTER(LEN=1),           INTENT(IN) :: pha
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: l, i
   out = s
@@ -1347,24 +1776,26 @@
   IF(i /= 0) out = s(1:i-1)//phases_sep//pha//'_'//s(i+1:l)                    !--- <var>_<tag> => return <var><sep><pha>_<tag>
 END FUNCTION addPhase_s1
-!------------------------------------------------------------------------------------------------------------------------------
+!==============================================================================================================================
 FUNCTION addPhase_sm(s,pha) RESULT(out)
   CHARACTER(LEN=*),           INTENT(IN) :: s(:)
   CHARACTER(LEN=1),           INTENT(IN) :: pha
   CHARACTER(LEN=maxlen),     ALLOCATABLE :: out(:)
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: k
   out = [( addPhase_s1(s(k), pha), k=1, SIZE(s) )]
 END FUNCTION addPhase_sm
-!------------------------------------------------------------------------------------------------------------------------------
+!==============================================================================================================================
 CHARACTER(LEN=maxlen) FUNCTION addPhase_i1(s,ipha,phases) RESULT(out)
   CHARACTER(LEN=*),           INTENT(IN) :: s
   INTEGER,                    INTENT(IN) :: ipha
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: phases
+!------------------------------------------------------------------------------------------------------------------------------
   out = s
   IF(s == '') RETURN                                                           !--- Empty string: nothing to do
-  IF(ipha==0) RETURN                                                           !--- Null index: no phase to add
+  IF(ipha == 0 .OR. ipha > nphases) RETURN                                     !--- Absurd index: no phase to add
   IF(     PRESENT(phases)) out = addPhase_s1(s,       phases(ipha:ipha))
   IF(.NOT.PRESENT(phases)) out = addPhase_s1(s, known_phases(ipha:ipha))
 END FUNCTION addPhase_i1
-!------------------------------------------------------------------------------------------------------------------------------
+!==============================================================================================================================
 FUNCTION addPhase_im(s,ipha,phases) RESULT(out)
   CHARACTER(LEN=*),           INTENT(IN) :: s(:)
@@ -1372,9 +1803,10 @@
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: phases
   CHARACTER(LEN=maxlen),     ALLOCATABLE :: out(:)
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: k
   IF(     PRESENT(phases)) out = [( addPhase_i1(s(k), ipha,       phases), k=1, SIZE(s) )]
   IF(.NOT.PRESENT(phases)) out = [( addPhase_i1(s(k), ipha, known_phases), k=1, SIZE(s) )]
 END FUNCTION addPhase_im
-!------------------------------------------------------------------------------------------------------------------------------
+!==============================================================================================================================
 
 
@@ -1385,15 +1817,17 @@
   CHARACTER(LEN=*),           INTENT(IN)  :: tname
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN)  :: phases
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen) :: phase
   IF(     PRESENT(phases)) phase = getPhase(tname,       phases, iPhase)
   IF(.NOT.PRESENT(phases)) phase = getPhase(tname, known_phases, iPhase)
 END FUNCTION getiPhase
-!------------------------------------------------------------------------------------------------------------------------------
+!==============================================================================================================================
 CHARACTER(LEN=1) FUNCTION getPhase(tname, phases, iPhase) RESULT(phase)
   CHARACTER(LEN=*),           INTENT(IN)  :: tname
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN)  :: phases
   INTEGER,          OPTIONAL, INTENT(OUT) :: iPhase
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: ip
-  phase = TRIM(strHead(strTail(tname, phases_sep, .TRUE.), '_', .TRUE.))
+  phase = TRIM(strHead(strTail(tname, phases_sep), '_', .TRUE.))     !--- <nam><sep><pha>[_<tag>] -> <pha>[_<tag>] -> <pha>
   IF(     PRESENT(phases)) ip = INDEX(      phases, phase)
   IF(.NOT.PRESENT(phases)) ip = INDEX(known_phases, phase)
@@ -1401,75 +1835,76 @@
   IF(PRESENT(iPhase)) iPhase = ip
 END FUNCTION getPhase
-!------------------------------------------------------------------------------------------------------------------------------
-
-
-!------------------------------------------------------------------------------------------------------------------------------
-CHARACTER(LEN=maxlen) FUNCTION old2newName_1(oldName, iPhase) RESULT(newName)
-  !--- Convert an old style name into a new one.
-  !    Only usable with old style "traceur.def" files, in which only water isotopes are allowed.
-  !    In these files, H2O descendants names are: H2O<phase>[_<isotope>][_<tag>], with:
-  !    phase = v, l or i ; isotope = eau, HDO, O18, O17 or HTO.
+!==============================================================================================================================
+
+
+!==============================================================================================================================
+!============ CONVERT WATER-DERIVED NAMES FROM FORMER TO CURRENT CONVENTION ; OTHER NAMES ARE LEFT UNTOUCHED ==================
+!======= NAMES STRUCTURE: H2O[<phase>][_<isotope>][_<tag>] (<phase> from "old_phases", <isotope> from "oldH2OIso") ============
+!==============================================================================================================================
+CHARACTER(LEN=maxlen) FUNCTION old2newH2O_1(oldName, iPhase) RESULT(newName)
   CHARACTER(LEN=*),  INTENT(IN)  :: oldName
   INTEGER, OPTIONAL, INTENT(OUT) :: iPhase
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen), ALLOCATABLE :: tmp(:)
-  INTEGER :: ix, ip, it, nt
-  LOGICAL :: lerr, lH2O
+  INTEGER :: ix, ip, nt
+  LOGICAL :: lerr
   newName = oldName
   IF(PRESENT(iPhase)) iPhase = 1                                               !--- Default: gaseous phase
-  lH2O=.FALSE.
-  IF(LEN_TRIM(oldName) > 3) THEN
-    lH2O = oldName(1:3)=='H2O' .AND. INDEX(old_phases,oldName(4:4))/=0         !--- H2O<phase>*,  with phase=="v", "l", "i" or "r"
-    IF(LEN_TRIM(oldName) > 4) lH2O = lH2O .AND. oldName(5:5) == '_'            !--- H2O<phase>_*, with phase=="v", "l", "i" or "r"
+  lerr = strParse(oldName, '_', tmp, nt)                                       !--- Parsing: 1 up to 3 elements.
+  ip = strIdx( [('H2O'//old_phases(ix:ix), ix=1, nphases)], tmp(1) )           !--- Phase index
+  IF(ip /= 0 .AND. PRESENT(iPhase)) iPhase = ip                                !--- Returning phase index
+  IF(ip == 0 .AND. tmp(1) /= 'H2O')   RETURN                                   !--- Not an old-style water-related species
+  IF(nt == 1) THEN
+    newName = addPhase('H2O',ip)                                               !=== WATER WITH OR WITHOUT PHASE
+  ELSE
+    ix = strIdx(oldH2OIso, tmp(2))                                             !--- Index in the known isotopes list
+    IF(ix /= 0) newName = newH2OIso(ix)                                        !--- Move to new isotope name
+    IF(ip /= 0) newName = addPhase(newName, ip)                                !--- Add phase to isotope name
+    IF(nt == 3) newName = TRIM(newName)//'_'//TRIM(tmp(3))                     !=== WATER ISOTOPE OR TAGGING TRACER
   END IF
-  IF(.NOT.lH2O) RETURN
-  IF(LEN_TRIM(oldName)>3) THEN; IF(INDEX(old_Phases,oldName(4:4))==0) RETURN; END IF 
-  lerr = strParse(oldName, '_', tmp, n=nt)
-  ip = strIdx([('H2O'//old_phases(ip:ip), ip=1, nphases)], tmp(1))             !--- Phase index (/=0 if any)
-  IF(PRESENT(iPhase)) iPhase = ip
-  newName = addPhase('H2O', ip)                                                !--- Water
-  IF(nt == 1) RETURN                                                           !--- Water: finished
-  ix = strIdx(oldH2OIso, tmp(2))                                               !--- Index in the known isotopes list
-  IF(ix == 0) newName = addPhase(tmp(2),        ip)                            !--- Not an isotope
-  IF(ix /= 0) newName = addPhase(newH2OIso(ix), ip)                            !--- Isotope
-  IF(nt == 3) newName = TRIM(newName)//'_'//TRIM(tmp(3))                       !--- Tagging tracer
-END FUNCTION old2newName_1
-!------------------------------------------------------------------------------------------------------------------------------
-FUNCTION old2newName_m(oldName, iPhase) RESULT(newName)
-  CHARACTER(LEN=*),  INTENT(IN)  :: oldName(:)
+END FUNCTION old2newH2O_1
+!==============================================================================================================================
+FUNCTION old2newH2O_m(oldName) RESULT(newName)
+  CHARACTER(LEN=*), INTENT(IN) :: oldName(:)
+  CHARACTER(LEN=maxlen)        :: newName(SIZE(oldName))
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: i
+  newName = [(old2newH2O_1(oldName(i)), i=1, SIZE(oldName))]
+END FUNCTION old2newH2O_m
+!==============================================================================================================================
+
+
+!==============================================================================================================================
+!============ CONVERT WATER-DERIVED NAMES FROM CURRENT TO FORMER CONVENTION ; OTHER NAMES ARE LEFT UNTOUCHED ==================
+!==== NAMES STRUCTURE: <var>[<phase_sep><phase>][_<tag>] (<phase> from "known_phases", <var> = 'H2O' or from "newH2OIso") =====
+!==============================================================================================================================
+CHARACTER(LEN=maxlen) FUNCTION new2oldH2O_1(newName, iPhase) RESULT(oldName)
+  CHARACTER(LEN=*),  INTENT(IN)  :: newName
   INTEGER, OPTIONAL, INTENT(OUT) :: iPhase
-  CHARACTER(LEN=maxlen)          :: newName(SIZE(oldName))
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: ix, ip
+  CHARACTER(LEN=maxlen) :: var
+  oldName = newName
+  ip = getiPhase(newName)                                                      !--- Phase index
+  IF(PRESENT(iPhase)) iPhase = MAX(ip, 1)                                      !--- Return phase index ; default: 1 (gazeous)
+  var = TRIM(strHead(newName, phases_sep, .TRUE.))                             !--- Variable without phase and tag
+  ix = strIdx(newH2OIso, var)                                                  !--- Index in the known H2O isotopes list
+  IF(ix == 0 .AND. var /= 'H2O') RETURN                                        !--- Neither H2O nor an H2O isotope => finished
+  oldName = 'H2O'
+  IF(ip /= 0) oldName = TRIM(oldName)//old_phases(ip:ip)                       !--- Add phase if needed
+  IF(ix /= 0) oldName = TRIM(oldName)//'_'//oldH2OIso(ix)                      !--- H2O isotope name
+  IF(newName /= addPhase(var, ip)) &
+    oldName = TRIM(oldName)//strTail(newName, '_', .TRUE.)                     !--- Add the tag suffix
+  IF(ip == 0 .AND. ix /= 0) oldName = strTail(oldName, '_')                    !--- Isotope with no phase: remove 'H2O_' prefix
+END FUNCTION new2oldH2O_1
+!==============================================================================================================================
+FUNCTION new2oldH2O_m(newName) RESULT(oldName)
+  CHARACTER(LEN=*), INTENT(IN) :: newName(:)
+  CHARACTER(LEN=maxlen)        :: oldName(SIZE(newName))
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: i
-  newName = [(old2newName_1(oldName(i), iPhase), i=1, SIZE(oldName))]
-END FUNCTION old2newName_m
-!------------------------------------------------------------------------------------------------------------------------------
-
-!------------------------------------------------------------------------------------------------------------------------------
-CHARACTER(LEN=maxlen) FUNCTION new2oldName_1(newName, iPhase) RESULT(oldName)
-  !--- Convert a new style name into an old one.
-  !    Only convertable names are water descendants names H2O_<phase>, <isotope>_<phase>, <isotope>_<phase>_<tag>, with:
-  !    phase = g, l or s ; isotope = H2[16]O, H[2]O, H2<[18]O, H2[17]O or H[3]O.
-  CHARACTER(LEN=*),  INTENT(IN)    :: newName
-  INTEGER, OPTIONAL, INTENT(OUT)   :: iPhase
-  INTEGER :: ix, ip, it, nt
-  LOGICAL :: lH2O
-  CHARACTER(LEN=maxlen) :: tag
-  ix = strIdx([(addPhase('H2O',ip), ip=1, nphases)], newName)                  !--- Phase index for H2O_<phase>
-  IF(ix /= 0) THEN; oldName = 'H2O'//old_phases(ix:ix); RETURN; END IF         !--- H2O_<phase> case
-  ix = strIdx(newH2OIso, strHead(newName, phases_sep, .TRUE.))                 !--- Isotope index
-  IF(ix == 0) THEN; oldName = newName;                  RETURN; END IF         !--- Not a water descendant
-  ip = getiPhase(newName)                                                      !--- Phase index
-  oldName = TRIM(oldH2OIso(ix))//old_phases(ip:ip)                             !--- <isotope>_<phase>
-  tag = strTail(delPhase(newName), TRIM(newH2OIso(ix)))                        !--- Get "_<tag>" if any
-  IF(tag /= delPhase(newName) .AND. tag /= '') oldName = TRIM(oldName)//tag    !--- Tagging tracer
-END FUNCTION new2oldName_1
-!------------------------------------------------------------------------------------------------------------------------------
-FUNCTION new2oldName_m(newName, iPhase) RESULT(oldName)
-  CHARACTER(LEN=*),  INTENT(IN)  :: newName(:)
-  INTEGER, OPTIONAL, INTENT(OUT) :: iPhase
-  CHARACTER(LEN=maxlen)          :: oldName(SIZE(newName))
-  INTEGER :: i
-  oldName = [(new2oldName_1(newName(i), iPhase), i=1, SIZE(newName))]
-END FUNCTION new2oldName_m
-!------------------------------------------------------------------------------------------------------------------------------
+  oldName = [(new2oldH2O_1(newName(i)), i=1, SIZE(newName))]
+END FUNCTION new2oldH2O_m
+!==============================================================================================================================
 
 
@@ -1477,56 +1912,70 @@
 !=== GET THE NAME(S) OF THE ANCESTOR(S) OF TRACER(S) "tname" AT GENERATION "igen"  IN THE TRACERS DESCRIPTORS LIST "tr" =======
 !==============================================================================================================================
-CHARACTER(LEN=maxlen) FUNCTION ancestor_1(t, tname, igen) RESULT(out)
-  TYPE(trac_type),   INTENT(IN) :: t(:)
-  CHARACTER(LEN=*),  INTENT(IN) :: tname
-  INTEGER, OPTIONAL, INTENT(IN) :: igen
-  INTEGER :: ig, ix
-  ig = 0; IF(PRESENT(igen)) ig = igen
-  ix = idxAncestor_1(t, tname, ig)
+SUBROUTINE ancestor_1(t, out, tname, igen)
+  TYPE(trac_type),       INTENT(IN)  :: t(:)
+  CHARACTER(LEN=maxlen), INTENT(OUT) :: out
+  CHARACTER(LEN=*),      INTENT(IN)  :: tname
+  INTEGER,     OPTIONAL, INTENT(IN)  :: igen
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: ix
+  CALL idxAncestor_1(t, ix, tname, igen)
   out = ''; IF(ix /= 0) out = t(ix)%name
-END FUNCTION ancestor_1
-!------------------------------------------------------------------------------------------------------------------------------
-FUNCTION ancestor_m(t, tname, igen) RESULT(out)
-  CHARACTER(LEN=maxlen), ALLOCATABLE     ::   out(:)
-  TYPE(trac_type),            INTENT(IN) ::     t(:)
-  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: tname(:)
-  INTEGER,          OPTIONAL, INTENT(IN) :: igen
-  INTEGER, ALLOCATABLE :: ix(:)
+END SUBROUTINE ancestor_1
+!==============================================================================================================================
+SUBROUTINE ancestor_mt(t, out, tname, igen)
+  TYPE(trac_type),       INTENT(IN)  :: t(:)
+  CHARACTER(LEN=*),      INTENT(IN)  :: tname(:)
+  CHARACTER(LEN=maxlen), INTENT(OUT) :: out(SIZE(tname))
+  INTEGER,     OPTIONAL, INTENT(IN)  :: igen
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: ix(SIZE(tname))
+  CALL idxAncestor_mt(t, ix, tname, igen)
+  out(:) = ''; WHERE(ix /= 0) out = t(ix)%name
+END SUBROUTINE ancestor_mt
+!==============================================================================================================================
+SUBROUTINE ancestor_m(t, out, igen)
+  TYPE(trac_type),       INTENT(IN)  :: t(:)
+  CHARACTER(LEN=maxlen), INTENT(OUT) :: out(SIZE(t))
+  INTEGER,     OPTIONAL, INTENT(IN)  :: igen
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: ix(SIZE(t))
+  CALL idxAncestor_m(t, ix, igen)
+  out(:) = ''; WHERE(ix /= 0) out = t(ix)%name
+END SUBROUTINE ancestor_m
+!==============================================================================================================================
+
+
+!==============================================================================================================================
+!=== GET THE INDEX(ES) OF THE GENERATION "igen" ANCESTOR(S) OF "tname" (t%name IF UNSPECIFIED) IN THE "t" LIST ================
+!==============================================================================================================================
+SUBROUTINE idxAncestor_1(t, idx, tname, igen)
+  TYPE(trac_type),   INTENT(IN)  :: t(:)
+  INTEGER,           INTENT(OUT) :: idx
+  CHARACTER(LEN=*),  INTENT(IN)  :: tname
+  INTEGER, OPTIONAL, INTENT(IN)  :: igen
   INTEGER :: ig
   ig = 0; IF(PRESENT(igen)) ig = igen
-  IF(     PRESENT(tname)) ix = idxAncestor_m(t, tname,     ig)
-  IF(.NOT.PRESENT(tname)) ix = idxAncestor_m(t, t(:)%name, ig)
-  ALLOCATE(out(SIZE(ix))); out(:) = ''
-  WHERE(ix /= 0) out = t(ix)%name
-END FUNCTION ancestor_m
-!==============================================================================================================================
-
-
-!==============================================================================================================================
-!=== GET THE INDEX(ES) OF THE ANCESTOR(S) OF TRACER(S) "tname" AT GENERATION "igen"  IN THE TRACERS DESCRIPTORS LIST "tr" =====
-!==============================================================================================================================
-INTEGER FUNCTION idxAncestor_1(t, tname, igen) RESULT(out)
-! Return the name of the generation "igen" (>=0) ancestor of "tname"
-  TYPE(trac_type),   INTENT(IN) :: t(:)
-  CHARACTER(LEN=*),  INTENT(IN) :: tname
-  INTEGER, OPTIONAL, INTENT(IN) :: igen
-  INTEGER :: ig
-  ig = 0; IF(PRESENT(igen)) ig = igen
-  out = strIdx(t(:)%name, tname)
-  IF(out == 0)                 RETURN            !--- Tracer not found
-  IF(t(out)%iGeneration <= ig) RETURN            !--- Tracer has a lower generation number than asked generation 'igen"
-  DO WHILE(t(out)%iGeneration > ig); out = strIdx(t(:)%name, t(out)%parent); END DO
-END FUNCTION idxAncestor_1
-!------------------------------------------------------------------------------------------------------------------------------
-FUNCTION idxAncestor_m(t, tname, igen) RESULT(out)
-  INTEGER,          ALLOCATABLE          ::   out(:)
-  TYPE(trac_type),            INTENT(IN) ::     t(:)
-  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: tname(:)
-  INTEGER,          OPTIONAL, INTENT(IN) :: igen
-  INTEGER :: ig, ix
-  ig = 0; IF(PRESENT(igen)) ig = igen
-  IF(     PRESENT(tname)) out = [(idxAncestor_1(t, tname(ix),  ig), ix=1, SIZE(tname))]
-  IF(.NOT.PRESENT(tname)) out = [(idxAncestor_1(t, t(ix)%name, ig), ix=1, SIZE(t))]
-END FUNCTION idxAncestor_m
+  idx = strIdx(t(:)%name, tname)
+  IF(idx == 0)                 RETURN            !--- Tracer not found
+  IF(t(idx)%iGeneration <= ig) RETURN            !--- Tracer has a lower generation number than asked generation 'igen"
+  DO WHILE(t(idx)%iGeneration > ig); idx = strIdx(t(:)%name, t(idx)%parent); END DO
+END SUBROUTINE idxAncestor_1
+!------------------------------------------------------------------------------------------------------------------------------
+SUBROUTINE idxAncestor_mt(t, idx, tname, igen)
+  TYPE(trac_type),   INTENT(IN)  :: t(:)
+  CHARACTER(LEN=*),  INTENT(IN)  :: tname(:)
+  INTEGER,           INTENT(OUT) :: idx(SIZE(tname))
+  INTEGER, OPTIONAL, INTENT(IN)  :: igen
+  INTEGER :: ix
+  DO ix = 1, SIZE(tname); CALL idxAncestor_1(t, idx(ix), tname(ix), igen); END DO
+END SUBROUTINE idxAncestor_mt
+!------------------------------------------------------------------------------------------------------------------------------
+SUBROUTINE idxAncestor_m(t, idx, igen)
+  TYPE(trac_type),   INTENT(IN)  :: t(:)
+  INTEGER,           INTENT(OUT) :: idx(SIZE(t))
+  INTEGER, OPTIONAL, INTENT(IN)  :: igen
+  INTEGER :: ix
+  DO ix = 1, SIZE(t); CALL idxAncestor_1(t, idx(ix), t(ix)%name, igen); END DO
+END SUBROUTINE idxAncestor_m
 !==============================================================================================================================
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/misc/strings_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/misc/strings_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/misc/strings_mod.F90	(revision 4482)
@@ -10,5 +10,5 @@
   PUBLIC :: is_numeric, bool2str, int2str, real2str, dble2str
   PUBLIC :: reduceExpr, str2bool, str2int, str2real, str2dble
-  PUBLIC :: addQuotes, testFile, checkList, removeComment, test
+  PUBLIC :: addQuotes, checkList, removeComment, test
 
   INTERFACE get_in;     MODULE PROCEDURE getin_s,  getin_i,  getin_r,  getin_l;  END INTERFACE get_in
@@ -21,5 +21,4 @@
   INTERFACE strIdx;     MODULE PROCEDURE     strIdx_1,                 strIdx_m; END INTERFACE strIdx
   INTERFACE strCount;   MODULE PROCEDURE  strCount_m1, strCount_11, strCount_1m; END INTERFACE strCount
-  INTERFACE strParse;   MODULE PROCEDURE   strParse_1,               strParse_m; END INTERFACE strParse
   INTERFACE strReplace; MODULE PROCEDURE strReplace_1,             strReplace_m; END INTERFACE strReplace
   INTERFACE cat;        MODULE PROCEDURE   horzcat_s1,  horzcat_i1,  horzcat_r1, &
@@ -30,5 +29,4 @@
   INTERFACE reduceExpr;   MODULE PROCEDURE   reduceExpr_1,   reduceExpr_m; END INTERFACE reduceExpr
   INTERFACE addQuotes;    MODULE PROCEDURE    addQuotes_1,    addQuotes_m; END INTERFACE addQuotes
-  INTERFACE testFile;     MODULE PROCEDURE     testFile_1,     testFile_m; END INTERFACE testFile
 
   INTEGER, PARAMETER :: maxlen    = 256                    !--- Standard maximum length for strings
@@ -38,4 +36,5 @@
 CONTAINS
 
+!==============================================================================================================================
 LOGICAL FUNCTION test(lcond, lout) RESULT(lerr)
   LOGICAL, INTENT(IN)  :: lcond
@@ -43,9 +42,12 @@
   lerr = lcond; lout = lcond
 END FUNCTION test
+!==============================================================================================================================
+
 
 !==============================================================================================================================
 SUBROUTINE init_printout(lunout_, prt_level_)
   INTEGER, INTENT(IN) :: lunout_, prt_level_
-  lunout = lunout_
+  lunout    = lunout_
+  prt_level = prt_level_
 END SUBROUTINE init_printout
 !==============================================================================================================================
@@ -105,4 +107,5 @@
   LOGICAL,          OPTIONAL, INTENT(IN) :: ll
   INTEGER,          OPTIONAL, INTENT(IN) :: unit
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen) :: subn
   INTEGER :: unt
@@ -121,4 +124,5 @@
   INTEGER,          OPTIONAL, INTENT(IN) :: unit
   INTEGER,          OPTIONAL, INTENT(IN) :: nmax
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen), ALLOCATABLE :: s(:)
   CHARACTER(LEN=maxlen) :: subn
@@ -138,4 +142,5 @@
   LOGICAL,          OPTIONAL, INTENT(IN) :: ll
   INTEGER,          OPTIONAL, INTENT(IN) :: unit
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen) :: subn
   INTEGER :: unt
@@ -152,4 +157,5 @@
   INTEGER,          OPTIONAL, INTENT(IN) :: unit
   INTEGER,          OPTIONAL, INTENT(IN)  :: nmax
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen) :: subn
   INTEGER :: unt, nmx
@@ -187,69 +193,73 @@
 
 !==============================================================================================================================
-!=== Extract the substring in front of the last (first if lFirst==TRUE) occurrence of separator "sep" in "str" ================
+!=== Extract the substring in front of the first (last if lBackward==TRUE) occurrence of "sep" in "str"        ================
 !=== Examples for str='a_b_c' and sep='_' and the bash command with the same effect:                           ================
 !===    * strHead(..,.FALSE.) = 'a'           ${str%%$sep*}                                                    ================
 !===    * strHead(..,.TRUE.)  = 'a_b'         ${str%$sep*}                                                     ================
 !==============================================================================================================================
-CHARACTER(LEN=maxlen) FUNCTION strHead_1(str,sep,lFirst) RESULT(out)
+CHARACTER(LEN=maxlen) FUNCTION strHead_1(str, sep, lBackward) RESULT(out)
   CHARACTER(LEN=*),           INTENT(IN) :: str
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
-  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
-  LOGICAL :: lf
-  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
+  LOGICAL,          OPTIONAL, INTENT(IN) :: lBackward
+!------------------------------------------------------------------------------------------------------------------------------
   IF(PRESENT(sep)) THEN
-    out = str(1:INDEX(str,sep,.NOT.lf)-1)
+    IF(     PRESENT(lBackWard)) out = str(1:INDEX(str,sep,lBackWard)-1)
+    IF(.NOT.PRESENT(lBackWard)) out = str(1:INDEX(str,sep)-1)
   ELSE
-    out = str(1:INDEX(str,'/',.NOT.lf)-1)
+    IF(     PRESENT(lBackWard)) out = str(1:INDEX(str,'/',lBackWard)-1)
+    IF(.NOT.PRESENT(lBackWard)) out = str(1:INDEX(str,'/')-1)
   END IF
   IF(out == '') out = str
 END FUNCTION strHead_1
 !==============================================================================================================================
-FUNCTION strHead_m(str,sep,lFirst) RESULT(out)
+FUNCTION strHead_m(str, sep, lBackward) RESULT(out)
   CHARACTER(LEN=maxlen),     ALLOCATABLE :: out(:)
   CHARACTER(LEN=*),           INTENT(IN) :: str(:)
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
-  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
-  LOGICAL :: lf
+  LOGICAL,          OPTIONAL, INTENT(IN) :: lBackward
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: k
-  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
   IF(PRESENT(sep)) THEN
-    out = [(strHead_1(str(k), sep,   lf), k=1, SIZE(str))]
+    IF(     PRESENT(lBackWard)) out = [(strHead_1(str(k), sep, lBackWard), k=1, SIZE(str))]
+    IF(.NOT.PRESENT(lBackWard)) out = [(strHead_1(str(k), sep),            k=1, SIZE(str))]
   ELSE
-    out = [(strHead_1(str(k), lFirst=lf), k=1, SIZE(str))]
+    IF(     PRESENT(lBackWard)) out = [(strHead_1(str(k), '/', lBackWard), k=1, SIZE(str))]
+    IF(.NOT.PRESENT(lBackWard)) out = [(strHead_1(str(k), '/'),            k=1, SIZE(str))]
   END IF
 END FUNCTION strHead_m
 !==============================================================================================================================
-!=== Extract the substring following the last (first if lFirst==TRUE) occurrence of separator "sep" in "str"   ================
+!=== Extract the substring following the first (last if lBackward==TRUE) occurrence of "sep" in "str"          ================
 !=== Examples for str='a_b_c' and sep='_' and the bash command with the same effect:                           ================
-!===    * strTail(..,.FALSE.) = 'c'           ${str#*$sep}                                                     ================
-!===    * strTail(..,.TRUE.)  = 'b_c'         ${str##*$sep}                                                    ================
-!==============================================================================================================================
-CHARACTER(LEN=maxlen) FUNCTION strTail_1(str,sep,lFirst) RESULT(out)
+!===    * strTail(str, '_', .FALSE.) = 'b_c'         ${str#*$sep}                                              ================
+!===    * strTail(str, '_', .TRUE.)  = 'c'           ${str##*$sep}                                             ================
+!==============================================================================================================================
+CHARACTER(LEN=maxlen) FUNCTION strTail_1(str, sep, lBackWard) RESULT(out)
   CHARACTER(LEN=*),           INTENT(IN) :: str
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
-  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
-  LOGICAL :: lf
-  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
+  LOGICAL,          OPTIONAL, INTENT(IN) :: lBackWard
+!------------------------------------------------------------------------------------------------------------------------------
   IF(PRESENT(sep)) THEN
-    out = str(INDEX(str,sep,.NOT.lf)+LEN(sep):LEN_TRIM(str))
+    IF(     PRESENT(lBackWard)) out = str(INDEX(str,sep,lBackWard)+LEN(sep):LEN_TRIM(str))
+    IF(.NOT.PRESENT(lBackWard)) out = str(INDEX(str,sep)          +LEN(sep):LEN_TRIM(str))
   ELSE
-    out = str(INDEX(str,'/',.NOT.lf)+1:LEN_TRIM(str))
+    IF(     PRESENT(lBackWard)) out = str(INDEX(str,'/',lBackWard)+1:LEN_TRIM(str))
+    IF(.NOT.PRESENT(lBackWard)) out = str(INDEX(str,'/')          +1:LEN_TRIM(str))
   END IF
   IF(out == '') out = str
 END FUNCTION strTail_1
 !==============================================================================================================================
-FUNCTION strTail_m(str,sep,lFirst) RESULT(out)
+FUNCTION strTail_m(str, sep, lBackWard) RESULT(out)
   CHARACTER(LEN=maxlen),     ALLOCATABLE :: out(:)
   CHARACTER(LEN=*),           INTENT(IN) :: str(:)
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
-  LOGICAL,          OPTIONAL, INTENT(IN) :: lFirst
-  LOGICAL :: lf
+  LOGICAL,          OPTIONAL, INTENT(IN) :: lBackWard
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: k
-  lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst
   IF(PRESENT(sep)) THEN
-    out = [(strTail_1(str(k), sep,   lf), k=1, SIZE(str))]
+    IF(     PRESENT(lBackWard)) out = [(strTail_1(str(k), sep, lBackWard), k=1, SIZE(str))]
+    IF(.NOT.PRESENT(lBackWard)) out = [(strTail_1(str(k), sep),            k=1, SIZE(str))]
   ELSE
-    out = [(strTail_1(str(k), lFirst=lf), k=1, SIZE(str))]
+    IF(     PRESENT(lBackWard)) out = [(strTail_1(str(k), '/', lBackWard), k=1, SIZE(str))]
+    IF(.NOT.PRESENT(lBackWard)) out = [(strTail_1(str(k), '/'),            k=1, SIZE(str))]
   END IF
 END FUNCTION strTail_m
@@ -265,4 +275,5 @@
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
   LOGICAL,          OPTIONAL, INTENT(IN) :: mask(:)
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=:), ALLOCATABLE :: s
   INTEGER :: is, i0
@@ -285,4 +296,5 @@
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep
   INTEGER,          OPTIONAL, INTENT(IN) :: nmax
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen), ALLOCATABLE :: t(:)
   CHARACTER(LEN=maxlen) :: sp
@@ -339,4 +351,5 @@
   CHARACTER(LEN=*), ALLOCATABLE, INTENT(INOUT) :: str(:)
   INTEGER,          OPTIONAL,    INTENT(OUT)   :: nb
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen), ALLOCATABLE :: s1(:)
   INTEGER :: k, n, n1
@@ -355,4 +368,5 @@
   CHARACTER(LEN=*),   ALLOCATABLE, INTENT(INOUT) :: str1(:)
   CHARACTER(LEN=*),                INTENT(IN)    :: str2(:)
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen), ALLOCATABLE :: s1(:), s2(:)
   INTEGER :: k
@@ -374,5 +388,6 @@
 
 !==============================================================================================================================
-!=== GET THE INDEX OF THE FIRST APPEARANCE IN THE STRING VECTOR "str(:)" OF THE STRING(s) "s" =================================
+!=== GET THE INDEX OF THE FIRST APPEARANCE IN THE STRING VECTOR "str(:)" OF THE STRING(s) "s[(:)]" ============================
+!=== OPTIONALY: GET THE NUMBER OF FOUND ELEMENTS "n". NB: UNFOUND => INDEX=0                       ============================
 !==============================================================================================================================
 INTEGER FUNCTION strIdx_1(str, s) RESULT(out)
@@ -386,4 +401,5 @@
   INTEGER, OPTIONAL, INTENT(OUT) :: n
   INTEGER,           ALLOCATABLE :: out(:)
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: k
   out = [(strIdx_1(str(:), s(k)), k=1, SIZE(s))]
@@ -400,4 +416,5 @@
   INTEGER, OPTIONAL, INTENT(OUT) :: n
   INTEGER,           ALLOCATABLE :: out(:)
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: k
   out = PACK( [(k, k=1, SIZE(str(:), DIM=1))], MASK = str(:) == s )
@@ -409,4 +426,5 @@
   INTEGER, OPTIONAL, INTENT(OUT) :: n
   INTEGER,           ALLOCATABLE :: out(:)
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: k
   out = PACK( [(k, k=1, SIZE(i(:), DIM=1))], MASK = i(:) == j )
@@ -418,15 +436,9 @@
   INTEGER, OPTIONAL, INTENT(OUT) :: n
   INTEGER,           ALLOCATABLE :: out(:)
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: k
   out = PACK( [(k, k=1, SIZE(l(:), DIM=1))], MASK = l(:) )
   IF(PRESENT(n)) n = SIZE(out(:), DIM=1)
 END FUNCTION find_boo
-!==============================================================================================================================
-
-
-
-!==============================================================================================================================
-!=== GET 1ST APPEARANCE INDEX OF EACH ELEMENT OF "t(:)" IN "s(:)" (UNFOUND: INDEX=0) ==========================================
-!=== OPTIONALY: GET THE NUMBER OF FOUND ELEMENTS "n"                                 ==========================================
 !==============================================================================================================================
 
@@ -444,54 +456,41 @@
   INTEGER,           INTENT(OUT) :: idel                             !--- Index of the identified delimiter (0 if idx==0)
   LOGICAL, OPTIONAL, INTENT(IN)  :: lSc                              !--- Care about nbs with front sign or in scient. notation
-
-  INTEGER               :: idx0                                      !--- Used to display an identified non-numeric string
-  INTEGER, ALLOCATABLE  :: ii(:)
-  LOGICAL               :: ll, ls
-  CHARACTER(LEN=maxlen) :: d
-!  modname = 'strIdx'
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: idx0                                                    !--- Used to display an identified non-numeric string
   lerr = .FALSE.
-  idx = strIdx1(rawList, del, ibeg, idel)                            !--- del(idel) appears in "rawList" at position idx
+  idx = strIdx1(rawList, del, ibeg, idel)                            !--- idx/=0: del(idel) is at position "idx" in "rawList" 
   IF(.NOT.PRESENT(lSc))               RETURN                         !--- No need to check exceptions for numbers => finished
   IF(.NOT.        lSc )               RETURN                         !--- No need to check exceptions for numbers => finished
-  IF(idx == 0) THEN                                                  !--- No element of "del" in "rawList":
-    lerr = .NOT.is_numeric(rawList(ibeg:))                           !--- String must be a number
-    IF(lerr) idx = LEN_TRIM(rawList); RETURN                         !--- Update idx => rawList(ibeg:idx-1) is the whole string
-  END IF
-  idx0 = idx
-  IF(test(idx==1.AND.INDEX('+-',del(idel))/=0, lerr)) RETURN         !--- Front separator different from +/-: error
-  IF(idx/=1.AND.is_numeric(rawList(ibeg:idx-1)))      RETURN         !--- The input string tail is a valid number
-  idx = strIdx1(rawList, del, idx+1, idel)                           !---   => TO THE NEXT DELIMITER
+
+  !=== No delimiter found: the whole string must be a valid number
+  IF(idx == 0) THEN                                                  !--- No element of "del" in "rawList"
+    lerr = .NOT.is_numeric(rawList(ibeg:LEN_TRIM(rawList)))          !--- String must be a number
+    IF(lerr) idx = LEN_TRIM(rawList); RETURN                         !--- Set idx so that rawList(ibeg:idx-1) = whole string
+  END IF
+
+  IF(test(idx == 1 .AND. INDEX('+-',del(idel)) /= 0, lerr)) RETURN   !--- The front delimiter is different from +/-: error
+  IF(     idx /= 1 .AND. is_numeric(rawList(ibeg:idx-1)))   RETURN   !--- The input string head is a valid number
+
+  !=== The string part in front of the 1st delimiter is not a valid number: search for next delimiter index "idx"
+  idx0 = idx ; idx = strIdx1(rawList, del, idx+1, idel)              !--- Keep start index because idx is recycled
   IF(idx == 0) THEN
-    lerr = .NOT.is_numeric(rawList(ibeg:))                           !--- No delimiter detected: string must be a number
+    lerr = .NOT.is_numeric(rawList(ibeg:LEN_TRIM(rawList)))          !--- No other delimiter: whole string must be a valid numb
     IF(lerr) idx = idx0; RETURN
   END IF
-  idx0 = idx
-  IF(is_numeric(rawList(ibeg:idx-1)))                 RETURN         !--- The input string tail is a valid number
-  IF(test(          INDEX('eE',rawList(idx-1:idx-1)) /= 0  &         !--- Sole possible exception: scientific notation: E+/-
-               .OR. INDEX('+-',del(idel)) /=0, lerr)) RETURN
-  idx = strIdx1(rawList, del, idx+1, idel)                           !---   => TO THE NEXT DELIMITER
-  IF(idx == 0) THEN
-    lerr = .NOT.is_numeric(rawList(ibeg:))                           !--- No separator detected: string must be a number
-    IF(lerr) idx = idx0; RETURN
-  END IF
   lerr = .NOT.is_numeric(rawList(ibeg:idx-1))
+
 CONTAINS
 
-INTEGER FUNCTION strIdx1(str, del, ib, id) RESULT(idx)
-  CHARACTER(LEN=*),  INTENT(IN)  :: str
-  CHARACTER(LEN=*),  INTENT(IN)  :: del(:)
+!------------------------------------------------------------------------------------------------------------------------------
+INTEGER FUNCTION strIdx1(str, del, ib, id) RESULT(i)
+!--- Get the index of the first appereance of one of the delimiters "del(:)" in "str" starting from position "ib".
+!--- "id" is the index in "del(:)" of the first delimiter found.
+  IMPLICIT NONE
+  CHARACTER(LEN=*),  INTENT(IN)  :: str, del(:)
   INTEGER,           INTENT(IN)  :: ib
   INTEGER,           INTENT(OUT) :: id
-
-  INTEGER              :: nd, ns, i
-  INTEGER, ALLOCATABLE :: ii(:)
-
-  nd  = SIZE(del)                                                    !--- Number of separators
-  ns  = LEN_TRIM(str)                                                !--- Length of the raw chain
-  ii  = [(INDEX( str(ib:ns), del(i) ), i = 1, nd)]                   !--- Determine the next separator start index
-  id  =  MINLOC( ii, MASK = ii /= 0, DIM = 1 )                       !--- Current delimiter index in the "delimiter(:)" list
-  idx = 0
-  IF(ANY(ii /= 0)) idx = MINVAL( ii, MASK = ii /= 0 ) + ib - 1       !--- Index in "str(1:ns)" of the delimiter first character
-  IF(idx == 0) id = 0
+!------------------------------------------------------------------------------------------------------------------------------
+  DO i = ib, LEN_TRIM(str); id = strIdx(del, str(i:i)); IF(id /= 0) EXIT; END DO
+  IF(i > LEN_TRIM(str)) THEN; i = 0; id = 0; END IF
 END FUNCTION strIdx1
 
@@ -501,42 +500,30 @@
 
 !==============================================================================================================================
-!=== Return the index of first appearance of "del" in "str" starting from index "ib"
-!==============================================================================================================================
-INTEGER FUNCTION strIndex(str, del, ib) RESULT(idx)
-  CHARACTER(LEN=*),  INTENT(IN)  :: str
-  CHARACTER(LEN=*),  INTENT(IN)  :: del
-  INTEGER,           INTENT(IN)  :: ib
-  idx  = INDEX( str(ib:LEN_TRIM(str)), del ) + ib -1
-END FUNCTION strIndex
-!==============================================================================================================================
-
-
-!==============================================================================================================================
 !=== Count the number of elements separated by "delimiter" in list "rawList". =================================================
 !==============================================================================================================================
-LOGICAL FUNCTION strCount_11(rawList, delimiter, nb, lSc) RESULT(out)
+LOGICAL FUNCTION strCount_11(rawList, delimiter, nb, lSc) RESULT(lerr)
   CHARACTER(LEN=*),  INTENT(IN)  :: rawList
   CHARACTER(LEN=*),  INTENT(IN)  :: delimiter
   INTEGER,           INTENT(OUT) :: nb
   LOGICAL, OPTIONAL, INTENT(IN)  :: lSc
+!------------------------------------------------------------------------------------------------------------------------------
   LOGICAL :: ll
   ll = .FALSE.; IF(PRESENT(lSc)) ll = lSc
-  out = strCount_1m(rawList, [delimiter], nb, ll)
+  lerr = strCount_1m(rawList, [delimiter], nb, ll)
 END FUNCTION strCount_11
 !==============================================================================================================================
-LOGICAL FUNCTION strCount_m1(rawList, delimiter, nb, lSc) RESULT(out)
+LOGICAL FUNCTION strCount_m1(rawList, delimiter, nb, lSc) RESULT(lerr)
   CHARACTER(LEN=*),     INTENT(IN)  :: rawList(:)
   CHARACTER(LEN=*),     INTENT(IN)  :: delimiter
   INTEGER, ALLOCATABLE, INTENT(OUT) :: nb(:)
   LOGICAL,    OPTIONAL, INTENT(IN)  :: lSc
-
+!------------------------------------------------------------------------------------------------------------------------------
   LOGICAL :: ll
   INTEGER :: id
-
   ll  = .FALSE.; IF(PRESENT(lSc)) ll = lSc .AND. INDEX('+-', delimiter) /= 0
-  out = .TRUE.
+  lerr = .TRUE.
   ALLOCATE(nb(SIZE(rawList)))
   DO id = 1, SIZE(rawList)
-    out = out .AND. strCount_1m(rawList(id), [delimiter], nb(id), ll)
+    lerr = lerr .AND. strCount_1m(rawList(id), [delimiter], nb(id), ll)
   END DO
 END FUNCTION strCount_m1
@@ -547,8 +534,8 @@
   INTEGER,           INTENT(OUT) :: nb
   LOGICAL, OPTIONAL, INTENT(IN)  :: lSc
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER              :: ib, ie, jd, nr
   LOGICAL              :: ll
   CHARACTER(LEN=1024)  :: r
-!  modname = 'strCount'
   lerr = .FALSE.
   ll   = .FALSE.; IF(PRESENT(lSc)) ll = lSc
@@ -559,5 +546,5 @@
     lerr = strIdx_prv(r, delimiter, ib, ie, jd, ll)
     IF(fmsg('"'//TRIM(r(ib:ie-1))//'" is not numeric', ll=lerr)) RETURN
-    IF(jd == 0) EXIT
+    IF(ie == 0 .OR. jd == 0) EXIT
     ib = ie + LEN(delimiter(jd))
     DO WHILE(r(ib:ib) == ' ' .AND. ib < nr); ib = ib + 1; END DO     !--- Skip spaces before next chain
@@ -572,31 +559,74 @@
 !===          Corresponding "vals" remains empty if the element does not contain "=" sign. ====================================
 !==============================================================================================================================
-LOGICAL FUNCTION strParse_1(rawList, delimiter, keys, lSc, vals, n) RESULT(lerr)
+LOGICAL FUNCTION strParse(rawList, delimiter, keys, n, vals) RESULT(lerr)
   CHARACTER(LEN=*),                             INTENT(IN)  :: rawList, delimiter
   CHARACTER(LEN=maxlen), ALLOCATABLE,           INTENT(OUT) :: keys(:)
-  LOGICAL,                            OPTIONAL, INTENT(IN)  :: lSc      !--- Take care about numbers in scientific notation
+  INTEGER,                            OPTIONAL, INTENT(OUT) :: n
   CHARACTER(LEN=maxlen), ALLOCATABLE, OPTIONAL, INTENT(OUT) :: vals(:)
-  INTEGER,                            OPTIONAL, INTENT(OUT) :: n
-  LOGICAL :: ll
-!  modname = 'strParse'
-  ll = .FALSE.; IF(PRESENT(lSc)) ll = lSc
-  IF(.NOT.PRESENT(vals)) lerr = strParse_m(rawList, [delimiter], keys, ll)
-  IF(     PRESENT(vals)) lerr = strParse_m(rawList, [delimiter], keys, ll, vals)
-  IF(PRESENT(n)) n = SIZE(keys)
-END FUNCTION strParse_1
-!==============================================================================================================================
-LOGICAL FUNCTION strParse_m(rawList, delimiter, keys, lSc, vals, n, id) RESULT(lerr)
+!------------------------------------------------------------------------------------------------------------------------------
+  CHARACTER(LEN=1024) :: r
+  INTEGER :: nr, nk
+  lerr = .FALSE.
+  r  = TRIM(ADJUSTL(rawList))
+  nr = LEN_TRIM(r); IF(nr == 0) THEN; keys = ['']; RETURN; END IF
+  CALL strParse_prv(nk)                                              !--- COUNT THE ELEMENTS
+  ALLOCATE(keys(nk))
+  IF(PRESENT(vals)) THEN
+    ALLOCATE(vals(nk)); CALL strParse_prv(nk, keys, vals)            !--- PARSE THE KEYS
+  ELSE
+    CALL strParse_prv(nk, keys)                                      !--- PARSE THE KEYS
+  END IF
+  IF(PRESENT(n)) n = nk
+
+CONTAINS
+
+!------------------------------------------------------------------------------------------------------------------------------
+SUBROUTINE strParse_prv(nkeys, keys, vals)
+!--- * Get the number of elements after parsing ("nkeys" only is present)
+!--- * Parse the <key>=<val> pairs and store result in "keys" and "vals" (already allocated)
+  IMPLICIT NONE
+  INTEGER,                         INTENT(OUT) :: nkeys
+  CHARACTER(LEN=maxlen), OPTIONAL, INTENT(OUT) :: keys(:)
+  CHARACTER(LEN=maxlen), OPTIONAL, INTENT(OUT) :: vals(:)
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: ib, ie
+  nkeys = 1; ib = 1
+  DO
+    ie = INDEX(rawList(ib:nr), delimiter)+ib-1                       !--- Determine the next separator start index
+    IF(ie == ib-1) EXIT
+    IF(PRESENT(keys)) keys(nkeys) = r(ib:ie-1)                       !--- Get the ikth key
+    IF(PRESENT(vals)) CALL parseKeys(keys(nkeys), vals(nkeys))       !--- Parse the ikth <key>=<val> pair
+    ib = ie + LEN(delimiter)
+    DO WHILE(r(ib:ib) == ' ' .AND. ib < nr); ib = ib + 1; END DO     !--- Skip spaces before next chain
+    nkeys = nkeys+1
+  END DO
+  IF(PRESENT(keys)) keys(nkeys) = r(ib:nr)                           !--- Get the last key
+  IF(PRESENT(vals)) CALL parseKeys(keys(nkeys), vals(nkeys))         !--- Parse the last <key>=<val> pair
+END SUBROUTINE strParse_prv
+
+!------------------------------------------------------------------------------------------------------------------------------
+SUBROUTINE parseKeys(key, val)
+  CHARACTER(LEN=*), INTENT(INOUT) :: key
+  CHARACTER(LEN=*), INTENT(OUT)   :: val
+!------------------------------------------------------------------------------------------------------------------------------
+  INTEGER :: ix
+  ix = INDEX(key, '='); IF(ix == 0) RETURN                           !--- First "=" index in "key"
+  val = ADJUSTL(key(ix+1:LEN_TRIM(key)))
+  key = ADJUSTL(key(1:ix-1))
+END SUBROUTINE parseKeys
+
+END FUNCTION strParse
+!==============================================================================================================================
+LOGICAL FUNCTION strParse_m(rawList, delimiter, keys, n, vals, lSc, id) RESULT(lerr)
   CHARACTER(LEN=*),                             INTENT(IN)  :: rawList, delimiter(:)
   CHARACTER(LEN=maxlen),           ALLOCATABLE, INTENT(OUT) :: keys(:)  !--- Parsed keys vector
+  INTEGER,               OPTIONAL,              INTENT(OUT) :: n        !--- Length of the parsed vector
+  CHARACTER(LEN=maxlen), OPTIONAL, ALLOCATABLE, INTENT(OUT) :: vals(:)  !--- Values for <name>=<value> keys
   LOGICAL,               OPTIONAL,              INTENT(IN)  :: lSc      !--- Take care about numbers in scientific notation
-  CHARACTER(LEN=maxlen), OPTIONAL, ALLOCATABLE, INTENT(OUT) :: vals(:)  !--- Values for <name>=<value> keys
-  INTEGER,               OPTIONAL,              INTENT(OUT) :: n        !--- Length of the parsed vector
   INTEGER,               OPTIONAL, ALLOCATABLE, INTENT(OUT) :: id(:)    !--- Indexes of the separators in "delimiter(:)" vector
-
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=1024) :: r
   INTEGER :: nr, ik, nk, ib, ie, jd
   LOGICAL :: ll
-
-!  modname = 'strParse'
   ll = .FALSE.; IF(PRESENT(lSc)) ll = lSc
   IF(test(fmsg("Couldn't parse list: non-numerical strings were found", ll=strCount_1m(rawList, delimiter, nk, ll)),lerr)) RETURN
@@ -625,7 +655,9 @@
 CONTAINS
 
+!------------------------------------------------------------------------------------------------------------------------------
 SUBROUTINE parseKeys(key, val)
   CHARACTER(LEN=*), INTENT(INOUT) :: key
   CHARACTER(LEN=*), INTENT(OUT)   :: val
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: ix
   ix = INDEX(key, '='); IF(ix == 0) RETURN                           !--- First "=" index in "key"
@@ -645,9 +677,7 @@
   CHARACTER(LEN=*),  INTENT(IN)    :: key, val   !--- "key" will be replaced by "val"
   LOGICAL, OPTIONAL, INTENT(IN)    :: lsurr      !--- TRUE => key must be surrounded by special characters to be substituted
-
-  CHARACTER(LEN=1024) :: s, t
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: i0, ix, nk, ns
   LOGICAL :: lsur, lb, le
-
   lsur = .FALSE.; IF(PRESENT(lsurr)) lsur = lsurr
   nk = LEN_TRIM(key)
@@ -688,4 +718,5 @@
   CHARACTER(LEN=*), OPTIONAL, TARGET, INTENT(IN) :: s1, s2, s3, s4, s5, s6, s7, s8, s9
   CHARACTER(LEN=maxlen), ALLOCATABLE :: out(:)
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen), POINTER     :: s
   LOGICAL :: lv(10)
@@ -707,4 +738,5 @@
   CHARACTER(LEN=*), OPTIONAL, TARGET, DIMENSION(:), INTENT(IN) :: s1, s2, s3, s4, s5, s6, s7, s8, s9
   CHARACTER(LEN=maxlen), ALLOCATABLE :: out(:,:)
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen), POINTER     :: s(:)
   LOGICAL :: lv(10)
@@ -729,4 +761,5 @@
   INTEGER, OPTIONAL, TARGET, INTENT(IN) :: i1, i2, i3, i4, i5, i6, i7, i8, i9
   INTEGER, ALLOCATABLE :: out(:)
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER, POINTER     :: i
   LOGICAL :: lv(10)
@@ -748,4 +781,5 @@
   INTEGER, OPTIONAL, TARGET, DIMENSION(:), INTENT(IN) :: i1, i2, i3, i4, i5, i6, i7, i8, i9
   INTEGER, ALLOCATABLE :: out(:,:)
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER, POINTER     :: i(:)
   LOGICAL :: lv(10)
@@ -770,4 +804,5 @@
   REAL, OPTIONAL, TARGET, INTENT(IN) :: r1, r2, r3, r4, r5, r6, r7, r8, r9
   REAL, ALLOCATABLE :: out(:)
+!------------------------------------------------------------------------------------------------------------------------------
   REAL, POINTER     :: r
   LOGICAL :: lv(10)
@@ -789,4 +824,5 @@
   REAL, OPTIONAL, TARGET, DIMENSION(:), INTENT(IN) :: r1, r2, r3, r4, r5, r6, r7, r8, r9
   REAL, ALLOCATABLE :: out(:,:)
+!------------------------------------------------------------------------------------------------------------------------------
   REAL, POINTER     :: r(:)
   LOGICAL :: lv(10)
@@ -811,4 +847,5 @@
   DOUBLE PRECISION, OPTIONAL, TARGET, INTENT(IN) :: d1, d2, d3, d4, d5, d6, d7, d8, d9
   DOUBLE PRECISION, ALLOCATABLE :: out(:)
+!------------------------------------------------------------------------------------------------------------------------------
   DOUBLE PRECISION, POINTER     :: d
   LOGICAL :: lv(10)
@@ -830,4 +867,5 @@
   DOUBLE PRECISION, OPTIONAL, TARGET, DIMENSION(:), INTENT(IN) :: d1, d2, d3, d4, d5, d6, d7, d8, d9
   DOUBLE PRECISION, ALLOCATABLE :: out(:,:)
+!------------------------------------------------------------------------------------------------------------------------------
   DOUBLE PRECISION, POINTER     :: d(:)
   LOGICAL :: lv(10)
@@ -869,5 +907,5 @@
   INTEGER,          OPTIONAL, INTENT(IN)  :: unit          !--- Output unit (default: screen)
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN)  :: sub           !--- Subroutine name
-
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=2048) :: row
   CHARACTER(LEN=maxlen)  :: rFm, el, subn
@@ -879,5 +917,4 @@
   INTEGER, PARAMETER   :: nm=1                             !--- Space between values & columns
   LOGICAL :: ls, li, lr
-
   subn = '';    IF(PRESENT(sub)) subn = sub
   rFm = '*';    IF(PRESENT(rFmt)) rFm = rFmt               !--- Specified format for reals
@@ -954,5 +991,5 @@
       nr = LEN_TRIM(row)-1                                           !--- Final separator removed
       CALL msg(row(1:nr), subn, unit=unt)
-      IF(ir /= 1) CYCLE                                              !--- Titles are underlined
+      IF(ir /= 1) CYCLE                                              !--- Titles only are underlined
       row=''; DO ic=1,nHd; row=TRIM(row)//REPEAT('-',n(ic))//'+'; END DO
       DO ic = ib,ncmx(it); row=TRIM(row)//REPEAT('-',n(ic))//'+'; END DO
@@ -975,5 +1012,5 @@
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN)  :: rFmt          !--- Format for reals
   LOGICAL,          OPTIONAL, INTENT(IN)  :: llast         !--- Last variable: no final ','
-
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen)  :: rFm, el
   CHARACTER(LEN=maxlen), ALLOCATABLE :: d(:,:)
@@ -983,6 +1020,4 @@
   INTEGER, ALLOCATABLE :: n(:)
   LOGICAL :: ls, li, lr, la
-
-!  modname = 'dispNamelist'
   rFm = '*';    IF(PRESENT(rFmt)) rFm = rFmt               !--- Specified format for reals
   ls = PRESENT(s); li = PRESENT(i); lr = PRESENT(r)
@@ -1056,5 +1091,4 @@
   REAL,                       INTENT(IN)  ::  a(:)                   !--- Linearized array of values
   INTEGER,                    INTENT(IN)  ::  n(:)                   !--- Profile before linearization
-
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN)  :: err_msg, nam(:), subn   !--- Error message, variables and calling subroutine names
   INTEGER,          OPTIONAL, INTENT(IN)  :: nRowMax                 !--- Maximum number of lines to display    (default: all)
@@ -1062,4 +1096,5 @@
   INTEGER,          OPTIONAL, INTENT(IN)  :: nHead                   !--- Number of front columns to duplicate  (default: 1)
   INTEGER,          OPTIONAL, INTENT(IN)  :: unit                    !--- Output unit                           (def: lunout)
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen),      ALLOCATABLE :: ttl(:)
   LOGICAL,                    ALLOCATABLE :: m(:)
@@ -1139,10 +1174,9 @@
   INTEGER,          OPTIONAL, INTENT(IN)  :: nHead                   !--- Number of front columns to duplicate  (default: 1)
   INTEGER,          OPTIONAL, INTENT(IN)  :: unit                    !--- Output unit                           (def: lunout)
-
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen)                   :: mes, sub, fm='(f12.9)', prf
   CHARACTER(LEN=maxlen),      ALLOCATABLE :: ttl(:), vnm(:)
-  LOGICAL,                    ALLOCATABLE :: m(:)
   INTEGER,                    ALLOCATABLE :: ki(:), kj(:), kl(:)
-  INTEGER                                 :: i, j, k, rk, ib, ie, itr, nm, nv, unt, nRmx, nCmx, nHd, rk1
+  INTEGER                                 :: i, j, k, rk, nv, unt, nRmx, nCmx, nHd
   REAL,                       ALLOCATABLE :: val(:,:)
 
@@ -1160,5 +1194,5 @@
   lerr= SIZE(a,1) /= PRODUCT(n); IF(fmsg('profile "n" does not match "a" and "ll"', sub, lerr, unt)) RETURN
 
-  SELECT CASE(rk1)                                                   !--- Indices list
+  SELECT CASE(rk)                                                   !--- Indices list
     CASE(0); IF(ll(1)) THEN; WRITE(unt,'(a,", ",a," = ",2f12.9)')TRIM(vnm(1)),TRIM(vnm(2)),a(1,1),a(1,2); RETURN; END IF
     CASE(1); ki = [  (i,i=1,n(1)) ]
@@ -1189,5 +1223,5 @@
   CHARACTER(LEN=*),      INTENT(IN)  :: str
   CHARACTER(LEN=maxlen), INTENT(OUT) :: val
-
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen)              :: v
   CHARACTER(LEN=1024)                :: s, vv
@@ -1196,5 +1230,4 @@
   INTEGER :: nl, nn, i, j, im, ix
   LOGICAL :: ll
-!  modname = 'reduceExpr_1'
   s = str
 
@@ -1243,15 +1276,13 @@
   CHARACTER(LEN=maxlen), ALLOCATABLE :: ky(:)
   CHARACTER(LEN=1),      ALLOCATABLE :: op(:)
-
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=1024) :: s
   DOUBLE PRECISION :: v, vm, vp
   INTEGER      :: i, ni, io
-
-!  modname = 'reduceExpr_basic'
   lerr = .FALSE.
   IF(is_numeric(str)) THEN; val=TRIM(str); RETURN; END IF
   op = ['^','/','*','+','-']                                                   !--- List of recognized operations
   s = str
-  IF(test(strParse_m(s, op, ky, .TRUE., id = id), lerr)) RETURN                !--- Parse the values
+  IF(test(strParse_m(s, op, ky, lSc=.TRUE., id = id), lerr)) RETURN            !--- Parse the values
   vl = str2dble(ky)                                                            !--- Conversion to doubles
   lerr = ANY(vl >= HUGE(1.d0))
@@ -1262,10 +1293,10 @@
       IF(id(i) /= io) CYCLE                                                    !--- Current found operator is not op(io)
       vm = vl(i); vp = vl(i+1)                                                 !--- Couple of values used for current operation
-      SELECT CASE(io)                                                          !--- Perform operation on the two values
-        CASE(1); v = vm**vp  !--- ^
-        CASE(2); v = vm/vp   !--- /
-        CASE(3); v = vm*vp   !--- *
-        CASE(4); v = vm+vp   !--- +
-        CASE(5); v = vm-vp   !--- +
+      SELECT CASE(op(io))                                                          !--- Perform operation on the two values
+        CASE('^'); v = vm**vp
+        CASE('/'); v = vm/vp
+        CASE('*'); v = vm*vp
+        CASE('+'); v = vm+vp
+        CASE('-'); v = vm-vp
       END SELECT
       IF(i == ni) THEN; vl = [vl(1:ni-1), v]; ELSE; vl = [vl(1:i-1), v, vl(i+2:ni+1)]; END IF
@@ -1283,4 +1314,5 @@
   CHARACTER(LEN=*),                   INTENT(IN)  :: str(:)
   CHARACTER(LEN=maxlen), ALLOCATABLE, INTENT(OUT) :: val(:)
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: i
   ALLOCATE(lerr(SIZE(str)),val(SIZE(str)))
@@ -1302,5 +1334,4 @@
   READ(str,fmt,IOSTAT=e) x
   out = e==0 .AND. INDEX('Ee',str(LEN_TRIM(str):LEN_TRIM(str)))==0
-  IF(str == '') out = .FALSE.
 END FUNCTION is_numeric
 !==============================================================================================================================
@@ -1348,4 +1379,5 @@
   INTEGER,           INTENT(IN) :: i
   INTEGER, OPTIONAL, INTENT(IN) :: nDigits
+!------------------------------------------------------------------------------------------------------------------------------
   WRITE(out,*)i
   out = ADJUSTL(out)
@@ -1357,4 +1389,5 @@
   REAL,                       INTENT(IN) :: r
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: fmt
+!------------------------------------------------------------------------------------------------------------------------------
   IF(     PRESENT(fmt)) WRITE(out,fmt)r
   IF(.NOT.PRESENT(fmt)) WRITE(out, * )r
@@ -1365,4 +1398,5 @@
   DOUBLE PRECISION,           INTENT(IN) :: d
   CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: fmt
+!------------------------------------------------------------------------------------------------------------------------------
   IF(     PRESENT(fmt)) WRITE(out,fmt)d
   IF(.NOT.PRESENT(fmt)) WRITE(out, * )d
@@ -1385,4 +1419,5 @@
 !==============================================================================================================================
 
+
 !==============================================================================================================================
 FUNCTION addQuotes_1(s) RESULT(out)
@@ -1395,4 +1430,5 @@
   CHARACTER(LEN=*), INTENT(IN)  :: s(:)
   CHARACTER(LEN=:), ALLOCATABLE :: out(:)
+!------------------------------------------------------------------------------------------------------------------------------
   INTEGER :: k, n
   n = MAXVAL(LEN_TRIM(s), MASK=.TRUE.)
@@ -1406,27 +1442,9 @@
   CHARACTER(LEN=*), INTENT(IN) :: s
   CHARACTER(LEN=1) :: b, e
+!------------------------------------------------------------------------------------------------------------------------------
   out = .TRUE.; IF(TRIM(s) == '') RETURN
   b = s(1:1); e = s(MAX(1,LEN_TRIM(s)):MAX(1,LEN_TRIM(s)))
   out = .NOT.is_numeric(s) .AND. (b /= "'" .OR. e /= "'") .AND. ( b /= '"' .OR. e /= '"')
 END FUNCTION needQuotes
-!==============================================================================================================================
-
-
-!==============================================================================================================================
-!=== TEST WHETHER A FILE IS PRESENT OR NOT ====================================================================================
-!==============================================================================================================================
-LOGICAL FUNCTION testFile_1(fname) RESULT(out)
-  CHARACTER(LEN=*), INTENT(IN) :: fname
-  INTEGER :: ierr
-  OPEN(90, FILE=fname, FORM='formatted', STATUS='old', IOSTAT=ierr); CLOSE(99)
-  out = ierr/=0
-END FUNCTION testFile_1
-!==============================================================================================================================
-FUNCTION testFile_m(fname) RESULT(out)
-  LOGICAL,         ALLOCATABLE ::   out(:)
-  CHARACTER(LEN=*), INTENT(IN) :: fname(:)
-  INTEGER :: k
-  out = [(testFile_1(fname(k)), k=1, SIZE(fname))]
-END FUNCTION testFile_m
 !==============================================================================================================================
 
@@ -1442,4 +1460,5 @@
   CHARACTER(LEN=*),   INTENT(IN)  :: message, items, reason
   INTEGER,  OPTIONAL, INTENT(IN)  :: nmax
+!------------------------------------------------------------------------------------------------------------------------------
   CHARACTER(LEN=maxlen), ALLOCATABLE :: s(:)
   INTEGER :: i, nmx
@@ -1464,4 +1483,3 @@
 
 
-
 END MODULE strings_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/misc/trac_types_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/misc/trac_types_mod.F90	(revision 4444)
+++ 	(revision )
@@ -1,55 +1,0 @@
-MODULE trac_types_mod
-
-  USE strings_mod, ONLY: maxlen
-  PRIVATE
-
-!=== TRACERS DESCRIPTOR DERIVED TYPE AND ASSOCIATED ROUTINES INTERFACES =======================================================
-  PUBLIC :: trac_type, isot_type, keys_type
-!------------------------------------------------------------------------------------------------------------------------------
-  TYPE :: keys_type                                        !=== TYPE FOR A SET OF KEYS ASSOCIATED TO AN ELEMENT
-    CHARACTER(LEN=maxlen)              :: name             !--- Tracer name
-    CHARACTER(LEN=maxlen), ALLOCATABLE :: key(:)           !--- Keys string list
-    CHARACTER(LEN=maxlen), ALLOCATABLE :: val(:)           !--- Corresponding values string list
-  END TYPE keys_type
-!------------------------------------------------------------------------------------------------------------------------------
-  TYPE :: trac_type                                        !=== TYPE FOR A SINGLE TRACER NAMED "name"
-    CHARACTER(LEN=maxlen) :: name        = ''              !--- Name of the tracer
-    CHARACTER(LEN=maxlen) :: gen0Name    = ''              !--- First generation ancestor name
-    CHARACTER(LEN=maxlen) :: parent      = ''              !--- Parent name
-    CHARACTER(LEN=maxlen) :: longName    = ''              !--- Long name (with advection scheme suffix)
-    CHARACTER(LEN=maxlen) :: type        = 'tracer'        !--- Type  (so far: 'tracer' / 'tag')
-    CHARACTER(LEN=maxlen) :: phase       = 'g'             !--- Phase ('g'as / 'l'iquid / 's'olid)
-    CHARACTER(LEN=maxlen) :: component   = ''              !--- Coma-separated list of components (Ex: lmdz,inca)
-    INTEGER               :: iadv        = 10              !--- Advection scheme used
-    INTEGER               :: iGeneration = -1              !--- Generation number (>=0)
-    LOGICAL               :: isAdvected  = .FALSE.         !--- "true" tracers: iadv > 0.   COUNT(isAdvected )=nqtrue
-    LOGICAL               :: isInPhysics = .TRUE.          !--- "true" tracers: in tr_seri. COUNT(isInPhysics)=nqtottr
-    INTEGER               :: iqParent    = 0               !--- Parent index
-    INTEGER,  ALLOCATABLE :: iqDescen(:)                   !--- Descendants index (in growing generation order)
-    INTEGER               :: nqDescen    = 0               !--- Number of descendants (all generations)
-    INTEGER               :: nqChilds    = 0               !--- Number of childs    (first generation)
-    INTEGER               :: iso_iGroup  = 0               !--- Isotopes group index in isotopes(:)
-    INTEGER               :: iso_iName   = 0               !--- Isotope  name  index in isotopes(iso_iGroup)%trac(:)
-    INTEGER               :: iso_iZone   = 0               !--- Isotope  zone  index in isotopes(iso_iGroup)%zone(:)
-    INTEGER               :: iso_iPhase  = 0               !--- Isotope  phase index in isotopes(iso_iGroup)%phas
-    TYPE(keys_type)       :: keys                          !--- <key>=<val> pairs vector
-  END TYPE trac_type
-!------------------------------------------------------------------------------------------------------------------------------
-  TYPE :: isot_type                                        !=== TYPE FOR AN ISOTOPES FAMILY DESCENDING ON TRACER "parent"
-    CHARACTER(LEN=maxlen)              :: parent           !--- Isotopes family name (parent tracer name ; ex: H2O)
-    LOGICAL                            :: check=.FALSE.    !--- Triggering of the checking routines
-    TYPE(keys_type),       ALLOCATABLE :: keys(:)          !--- Isotopes keys/values pairs list     (length: niso)
-    CHARACTER(LEN=maxlen), ALLOCATABLE :: trac(:)          !--- Isotopes + tagging tracers list     (length: ntiso)
-    CHARACTER(LEN=maxlen), ALLOCATABLE :: zone(:)          !--- Geographic tagging zones names list (length: nzone)
-    CHARACTER(LEN=maxlen)              :: phase = 'g'      !--- Phases list: [g][l][s]              (length: nphas)
-    INTEGER                            :: niso  = 0        !--- Number of isotopes, excluding tagging tracers
-    INTEGER                            :: nzone = 0        !--- Number of geographic tagging zones
-    INTEGER                            :: ntiso = 0        !--- Number of isotopes, including tagging tracers
-    INTEGER                            :: nphas = 0        !--- Number phases
-    INTEGER,               ALLOCATABLE :: iqIsoPha(:,:)    !--- Idx in "tracers(1:nqtot)" = f(name(1:ntiso)),phas)
-                                                           !---        "iqIsoPha" former name: "iqiso"
-    INTEGER,               ALLOCATABLE :: itZonIso(:,:)    !--- Idx in "trac(1:ntiso)" = f(zone, name(1:niso))
-                                                           !---        "itZonIso" former name: "index_trac"
-  END TYPE isot_type
-
-END MODULE trac_types_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/misc/wxios.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/misc/wxios.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/misc/wxios.F90	(revision 4482)
@@ -308,4 +308,8 @@
         IF (xios_is_valid_axis("axis_lat")) THEN
            CALL xios_set_axis_attr( "axis_lat", n_glo=nbp_lat, n=jj_nb, begin=jj_begin-1, value=io_lat(jj_begin:jj_end))
+        ENDIF
+        IF (xios_is_valid_axis("axis_lat_greordered")) THEN
+           CALL xios_set_axis_attr( "axis_lat_greordered", n_glo=nbp_lat, n=jj_nb, begin=jj_begin-1, &
+                                    value=io_lat(jj_begin:jj_end)*(-1.))
         ENDIF
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phy_common/abort_physic.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phy_common/abort_physic.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phy_common/abort_physic.F90	(revision 4482)
@@ -38,4 +38,11 @@
       if (ierr .eq. 0) then
         write(lunout,*) 'Everything is cool'
+#ifdef CPP_MPI
+        !$OMP CRITICAL (MPI_ABORT_PHYSIC)
+        call MPI_ABORT(COMM_LMDZ_PHY, 0, ierror_mpi)
+        !$OMP END CRITICAL (MPI_ABORT_PHYSIC)
+#else
+        stop 0
+#endif          
       else
         write(lunout,*) 'Houston, we have a problem, ierr = ', ierr
Index: LMDZ6/branches/LMDZ_ECRad/libf/phy_common/physics_distribution_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phy_common/physics_distribution_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phy_common/physics_distribution_mod.F90	(revision 4482)
@@ -13,5 +13,5 @@
   USE mod_grid_phy_lmdz, ONLY: init_grid_phy_lmdz
   USE dimphy, ONLY : Init_dimphy
-  USE infotrac_phy, ONLY : types_trac
+  USE infotrac_phy, ONLY : type_trac
 #ifdef REPROBUS
   USE CHEM_REP, ONLY : Init_chem_rep_phys
@@ -39,6 +39,5 @@
 #ifdef REPROBUS
 ! Initialization of Reprobus
-    IF (ANY(types_trac == 'repr')) CALL Init_chem_rep_phys(klon_omp,nbp_lev)
-    END IF
+    IF (type_trac == 'repr') CALL Init_chem_rep_phys(klon_omp,nbp_lev)
 #endif
 
@@ -51,5 +50,5 @@
 !  USE mod_grid_phy_lmdz, ONLY: Init_grid_phy_lmdz!, nbp_lev
 !  USE dimphy, ONLY : Init_dimphy
-!  USE infotrac_phy, ONLY : types_trac
+!  USE infotrac_phy, ONLY : type_trac
 !#ifdef REPROBUS
 !  USE CHEM_REP, ONLY : Init_chem_rep_phys
@@ -72,5 +71,5 @@
 !#ifdef REPROBUS
 !! Initialization of Reprobus
-!    IF (ANY(types_trac == 'repr')) CALL Init_chem_rep_phys(klon_omp,nbp_lev)
+!    IF (type_trac == 'repr') CALL Init_chem_rep_phys(klon_omp,nbp_lev)
 !    END IF
 !#endif
Index: LMDZ6/branches/LMDZ_ECRad/libf/phy_common/vertical_layers_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phy_common/vertical_layers_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phy_common/vertical_layers_mod.F90	(revision 4482)
@@ -15,8 +15,10 @@
    REAL,SAVE,ALLOCATABLE :: presnivs(:) ! reference pressure at mid-layer (Pa),
                                         ! based on preff, ap and bp
+   REAL,SAVE,ALLOCATABLE :: presinter(:) ! reference pressure at interface (Pa),
+                                        ! based on preff, ap and bp
    REAL,SAVE,ALLOCATABLE :: pseudoalt(:) ! pseudo-altitude of model layers (km),
                                          ! based on preff and scaleheight
    
-!$OMP THREADPRIVATE(preff,scaleheight,ap,bp,aps,bps,presnivs,pseudoalt)
+!$OMP THREADPRIVATE(preff,scaleheight,ap,bp,aps,bps,presnivs,presinter,pseudoalt)
 
 
@@ -24,5 +26,5 @@
 
   SUBROUTINE init_vertical_layers(nlayer,preff_,scaleheight_,ap_,bp_,&
-                                 aps_,bps_,presnivs_, pseudoalt_)
+                                 aps_,bps_,presnivs_, presinter_, pseudoalt_)
     IMPLICIT NONE
     INTEGER,INTENT(IN) :: nlayer ! number of atmospheric layers
@@ -34,4 +36,5 @@
     REAL,INTENT(IN)    :: bps_(nlayer) ! hybrid coordinate at mid-layer
     REAL,INTENT(IN)    :: presnivs_(nlayer) ! Appproximative pressure of atm. layers (Pa)
+    REAL,INTENT(IN)    :: presinter_(nlayer+1) ! Appproximative pressure of atm. layers (Pa)
     REAL,INTENT(IN)    :: pseudoalt_(nlayer) ! pseudo-altitude of atm. layers (km)
   
@@ -41,4 +44,5 @@
     ALLOCATE(bps(nlayer))
     ALLOCATE(presnivs(nlayer))
+    ALLOCATE(presinter(nlayer+1))
     ALLOCATE(pseudoalt(nlayer))
   
@@ -50,4 +54,5 @@
     bps(:) = bps_(:)
     presnivs(:) = presnivs_(:)
+    presinter(:) = presinter_(:)
     pseudoalt(:) = pseudoalt_(:)
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phydev/infotrac_phy.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phydev/infotrac_phy.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phydev/infotrac_phy.F90	(revision 4482)
@@ -4,23 +4,20 @@
 MODULE infotrac_phy
 
-! Information on tracers for physics;
-! nqtot : total number of tracers and higher order of moment, water vapor and liquid included
-  INTEGER, SAVE :: nqtot
-!$OMP THREADPRIVATE(nqtot)
-
-  CHARACTER(len=4),SAVE :: type_trac
-!$OMP THREADPRIVATE(type_trac)
+   USE strings_mod, ONLY: maxlen
+   INTEGER,                 SAVE :: nqtot                       !--- Tracers nb in dynamics (incl. higher moments + H2O)
+   CHARACTER(LEN=maxlen),   SAVE :: type_trac                   !--- Keyword for tracers type
+!$OMP THREADPRIVATE(nqtot, type_trac)
 
 CONTAINS
 
-  SUBROUTINE init_infotrac_phy(nqtot_,type_trac_)
-  ! transfer information on tracers from dynamics to physics
-  IMPLICIT NONE
-    INTEGER,INTENT(IN) :: nqtot_
-    CHARACTER(len=4),INTENT(IN) :: type_trac_
+SUBROUTINE init_infotrac_phy(nqtot_, type_trac_)
+   IMPLICIT NONE
+   INTEGER,          INTENT(IN) :: nqtot_
+   CHARACTER(LEN=*), INTENT(IN) :: type_trac_
+   CHARACTER(LEN=maxlen) :: modname='init_infotrac_phy'
 
-    nqtot=nqtot_
-    type_trac=type_trac_
-  
+   nqtot = nqtot_
+   type_trac = type_trac_
+
   END SUBROUTINE init_infotrac_phy
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/Dust/phys_output_write_spl_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/Dust/phys_output_write_spl_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/Dust/phys_output_write_spl_mod.F90	(revision 4482)
@@ -381,5 +381,5 @@
     USE pbl_surface_mod, ONLY: snow
     USE indice_sol_mod, ONLY: nbsrf
-    USE infotrac, ONLY: nqtot, nbtr, tracers, type_trac
+    USE infotrac, ONLY: nqtot, nbtr, tracers
     USE geometry_mod, ONLY: cell_area
     USE surface_data, ONLY: type_ocean, version_ocean, ok_veget, landice_opt
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/calcaerosolstrato_rrtm.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/calcaerosolstrato_rrtm.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/calcaerosolstrato_rrtm.F90	(revision 4482)
@@ -16,5 +16,4 @@
   INCLUDE "clesphys.h"
   INCLUDE "paramet.h"
-  INCLUDE "thermcell.h"
   INCLUDE "iniprint.h"
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/micphy_tstep.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/micphy_tstep.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/micphy_tstep.F90	(revision 4482)
@@ -7,5 +7,5 @@
   USE dimphy, ONLY : klon,klev
   USE aerophys
-  USE infotrac_phy
+  USE infotrac_phy, ONLY : nbtr_bin, nbtr_sulgas, nbtr, id_H2SO4_strat
   USE phys_local_var_mod, ONLY: mdw, budg_3D_nucl, budg_3D_cond_evap, budg_h2so4_to_part, R2SO4, DENSO4, f_r_wet
   USE nucleation_tstep_mod
@@ -47,5 +47,5 @@
   REAL ASO4(nbtr_bin)
   REAL DNDR(nbtr_bin)
-  REAL H2SO4_sat(nbtr_bin)
+  REAL H2SO4_sat
 
   DO it=1,nbtr_bin
@@ -107,4 +107,6 @@
              & ACTSO4(ilon,ilev),R2SO4(ilon,ilev),DENSO4(ilon,ilev),f_r_wet(ilon,ilev), &
              & RRSI,Vbin,FL,ASO4,DNDR)
+      ! Compute H2SO4 saturate vapor for big particules
+      H2SO4_sat = DNDR(nbtr_bin)/(pplay(ilon,ilev)/t_seri(ilon,ilev)/RD/1.E6/mH2SO4mol)
       ! consider only condensation (positive FL)
       DO it=1,nbtr_bin
@@ -117,5 +119,5 @@
       ENDDO
       ! determine appropriate time step
-      dt=(H2SO4_init-H2SO4_sat(nbtr_bin))/float(nbtstep)/MAX(1.e-30, nucl_rate+cond_evap_rate) !cond_evap_rate pos. for cond. and neg. for evap.
+      dt=(H2SO4_init-H2SO4_sat)/float(nbtstep)/MAX(1.e-30, nucl_rate+cond_evap_rate) !cond_evap_rate pos. for cond. and neg. for evap.
       IF (dt.LT.0.0) THEN
         dt=PDT
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/nucleation_tstep_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/nucleation_tstep_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/nucleation_tstep_mod.F90	(revision 4482)
@@ -604,5 +604,5 @@
      na_n=x_n*ntot_n
      IF (na_n .LT. 1.) THEN
-        print *, 'Warning: number of acid molecules < 1 in nucleation regime, setting na_n=1'
+!        print *, 'Warning: number of acid molecules < 1 in nucleation regime, setting na_n=1'
         na_n=1.0
      ENDIF
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/strataer_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/strataer_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/strataer_mod.F90	(revision 4482)
@@ -79,5 +79,6 @@
     !Config Help = Used in physiq.F
     !
-    flag_sulf_emit = 0
+    flag_sulf_emit = 0 ! Background (default)
+    flag_sulf_emit_distrib = 0 ! Gaussian (default)
     nErupt = 0 ! eruption number
     injdur = 0 ! init injection duration
@@ -87,4 +88,31 @@
        CALL getin_p('nErupt',nErupt)
        CALL getin_p('injdur',injdur)
+       CALL getin_p('flag_sulf_emit_distrib',flag_sulf_emit_distrib)
+
+       year_emit_vol=0 ; mth_emit_vol=0 ; day_emit_vol=0
+       m_aer_emiss_vol=0. ; altemiss_vol=0. ; sigma_alt_vol=0.
+       xlon_min_vol=0. ; xlon_max_vol=0.
+       xlat_min_vol=0. ; xlat_max_vol=0.
+
+       IF (nErupt.GT.0) THEN
+          ALLOCATE(year_emit_vol(nErupt),mth_emit_vol(nErupt),day_emit_vol(nErupt))
+          ALLOCATE(m_aer_emiss_vol(nErupt),altemiss_vol(nErupt),sigma_alt_vol(nErupt))
+          ALLOCATE(xlat_min_vol(nErupt),xlon_min_vol(nErupt))
+          ALLOCATE(xlat_max_vol(nErupt),xlon_max_vol(nErupt))
+       ELSE
+          WRITE(lunout,*) 'ERROR : Using flag_sulf_emit=1 (ie Volcanic eruption) but nErupt (',nErupt,') <=0 !'
+          CALL abort_physic('strataer_mod','No eruption define in physiq_def (nErupt=0). Add one or use background condition.',1)
+       ENDIF
+
+       CALL getin_p('year_emit_vol',year_emit_vol)
+       CALL getin_p('mth_emit_vol',mth_emit_vol)
+       CALL getin_p('day_emit_vol',day_emit_vol)
+       CALL getin_p('m_aer_emiss_vol',m_aer_emiss_vol)
+       CALL getin_p('altemiss_vol',altemiss_vol)
+       CALL getin_p('sigma_alt_vol',sigma_alt_vol)
+       CALL getin_p('xlon_min_vol',xlon_min_vol)
+       CALL getin_p('xlon_max_vol',xlon_max_vol)
+       CALL getin_p('xlat_min_vol',xlat_min_vol)
+       CALL getin_p('xlat_max_vol',xlat_max_vol)
     ELSEIF (flag_sulf_emit == 2) THEN ! SAI
        CALL getin_p('m_aer_emiss_sai',m_aer_emiss_sai)
@@ -93,5 +121,4 @@
        CALL getin_p('xlat_sai',xlat_sai)
        CALL getin_p('xlon_sai',xlon_sai)
-       CALL getin_p('flag_sulf_emit_distrib',flag_sulf_emit_distrib)
     ELSEIF (flag_sulf_emit == 3) THEN ! SAI between latitudes
        CALL getin_p('m_aer_emiss_sai',m_aer_emiss_sai)
@@ -101,29 +128,6 @@
        CALL getin_p('xlat_max_sai',xlat_max_sai)
        CALL getin_p('xlat_min_sai',xlat_min_sai)
-       CALL getin_p('flag_sulf_emit_distrib',flag_sulf_emit_distrib)
     ENDIF
 
-    ALLOCATE(year_emit_vol(nErupt),mth_emit_vol(nErupt),day_emit_vol(nErupt))
-    ALLOCATE(m_aer_emiss_vol(nErupt),altemiss_vol(nErupt),sigma_alt_vol(nErupt))
-    ALLOCATE(xlat_min_vol(nErupt),xlon_min_vol(nErupt))
-    ALLOCATE(xlat_max_vol(nErupt),xlon_max_vol(nErupt))
-    
-    IF (nErupt.GT.0) THEN 
-      year_emit_vol=0 ; mth_emit_vol=0 ; day_emit_vol=0
-      m_aer_emiss_vol=0. ; altemiss_vol=0. ; sigma_alt_vol=0.
-      xlon_min_vol=0. ; xlon_max_vol=0.
-      xlat_min_vol=0. ; xlat_max_vol=0.
-    ENDIF
-    
-    CALL getin_p('year_emit_vol',year_emit_vol)
-    CALL getin_p('mth_emit_vol',mth_emit_vol)
-    CALL getin_p('day_emit_vol',day_emit_vol)
-    CALL getin_p('m_aer_emiss_vol',m_aer_emiss_vol)
-    CALL getin_p('altemiss_vol',altemiss_vol)
-    CALL getin_p('sigma_alt_vol',sigma_alt_vol)
-    CALL getin_p('xlon_min_vol',xlon_min_vol)
-    CALL getin_p('xlon_max_vol',xlon_max_vol)
-    CALL getin_p('xlat_min_vol',xlat_min_vol)
-    CALL getin_p('xlat_max_vol',xlat_max_vol)
     !Config Key  = flag_nuc_rate_box
     !Config Desc = define or not a box for nucleation rate
@@ -136,4 +140,7 @@
     !
     flag_nuc_rate_box = .FALSE.
+    nuclat_min=0  ; nuclat_max=0
+    nucpres_min=0 ; nucpres_max=0
+
     CALL getin_p('flag_nuc_rate_box',flag_nuc_rate_box)
     CALL getin_p('nuclat_min',nuclat_min)
@@ -153,5 +160,4 @@
        WRITE(lunout,*) 'IN STRATAER : altemiss_vol',altemiss_vol
        WRITE(lunout,*) 'IN STRATAER : sigma_alt_vol',sigma_alt_vol
-       WRITE(lunout,*) 'IN STRATAER : ponde_lonlat_vol',ponde_lonlat_vol
        WRITE(lunout,*) 'IN STRATAER : xlat_min_vol',xlat_min_vol
        WRITE(lunout,*) 'IN STRATAER : xlat_max_vol',xlat_max_vol
@@ -164,5 +170,4 @@
        WRITE(lunout,*) 'IN STRATAER : xlat_sai',xlat_sai
        WRITE(lunout,*) 'IN STRATAER : xlon_sai',xlon_sai
-       WRITE(lunout,*) 'flag_sulf_emit_distrib = ',flag_sulf_emit_distrib
     ELSEIF (flag_sulf_emit == 3) THEN
        WRITE(lunout,*) 'IN STRATAER : m_aer_emiss_sai',m_aer_emiss_sai
@@ -172,6 +177,6 @@
        WRITE(lunout,*) 'IN STRATAER : xlat_max_sai',xlat_max_sai
        WRITE(lunout,*) 'IN STRATAER : xlon_sai',xlon_sai
-       WRITE(lunout,*) 'flag_sulf_emit_distrib = ',flag_sulf_emit_distrib
     ENDIF
+    WRITE(lunout,*) 'flag_sulf_emit_distrib = ',flag_sulf_emit_distrib
     WRITE(lunout,*) 'IN STRATAER : flag_nuc_rate_box = ',flag_nuc_rate_box
     IF (flag_nuc_rate_box) THEN
@@ -181,6 +186,9 @@
     !ENDIF
 
-    CALL strataer_ponde_init
-    WRITE(lunout,*) 'IN STRATAER INT2 END'
+    IF (flag_sulf_emit == 1) THEN
+       CALL strataer_ponde_init
+       WRITE(lunout,*) 'IN STRATAER INT2 END'
+    END IF
+    WRITE(lunout,*) 'IN STRATAER END'
 
   END SUBROUTINE strataer_init
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/traccoag_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/traccoag_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/StratAer/traccoag_mod.F90	(revision 4482)
@@ -17,5 +17,5 @@
 
     USE dimphy
-    USE infotrac_phy
+    USE infotrac_phy, ONLY : nbtr_bin, nbtr_sulgas, nbtr, id_SO2_strat
     USE aerophys
     USE geometry_mod, ONLY : cell_area, boundslat
@@ -23,5 +23,5 @@
     USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
     USE mod_phys_lmdz_para, only: gather, scatter
-    USE phys_cal_mod
+    USE phys_cal_mod, ONLY : year_len, year_cur,mth_cur, day_cur, hour
     USE sulfate_aer_mod
     USE phys_local_var_mod, ONLY: stratomask
@@ -29,5 +29,4 @@
     USE print_control_mod, ONLY: lunout
     USE strataer_mod
-    USE phys_cal_mod, ONLY : year_len
 
     IMPLICIT NONE
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/atke_exchange_coeff_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/atke_exchange_coeff_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/atke_exchange_coeff_mod.F90	(revision 4482)
@@ -0,0 +1,199 @@
+module atke_exchange_coeff_mod
+
+implicit none
+
+contains 
+
+subroutine atke_compute_km_kh(ngrid,nlay, &
+                        wind_u,wind_v,temp,play,pinterf, &
+                        tke,Km_out,Kh_out)
+
+!========================================================================
+! Routine that computes turbulent Km / Kh coefficients with a
+! 1.5 order closure scheme (TKE) with or without stationarity assumption
+!
+! This parameterization has been constructed in the framework of a
+! collective and collaborative workshop, 
+! the so-called 'Atelier TKE (ATKE)' with
+! K. Arjdal, L. Raillard, C. Dehondt, P. Tiengou, A. Spiga, F. Cheruy, T Dubos, 
+! M. Coulon-Decorzens, S. Fromang, G. Riviere, A. Sima, F. Hourdin, E. Vignon
+!
+! Main assumptions of the model :
+! (1) dry atmosphere
+! (2) horizontal homogeneity (Dx=Dy=0.)
+!=======================================================================
+
+
+
+USE atke_turbulence_ini_mod, ONLY : iflag_atke, kappa, l0, ric, cinf, rpi, rcpd
+USE atke_turbulence_ini_mod, ONLY : cepsilon, pr_slope, pr_asym, pr_neut, rg, rd
+USE atke_turbulence_ini_mod, ONLY : viscom, viscoh
+
+implicit none
+
+
+! Declarations:
+!=============
+
+INTEGER, INTENT(IN) :: ngrid ! number of horizontal index (flat grid)
+INTEGER, INTENT(IN) :: nlay ! number of vertical index  
+
+REAL, DIMENSION(ngrid,nlay), INTENT(IN)       :: wind_u   ! zonal velocity (m/s)
+REAL, DIMENSION(ngrid,nlay), INTENT(IN)       :: wind_v   ! meridional velocity (m/s)
+REAL, DIMENSION(ngrid,nlay), INTENT(IN)       :: temp   ! temperature (K)
+REAL, DIMENSION(ngrid,nlay), INTENT(IN)       :: play   ! pressure (Pa)
+REAL, DIMENSION(ngrid,nlay+1), INTENT(IN)     :: pinterf   ! pressure at interfaces(Pa)
+
+
+REAL, DIMENSION(ngrid,nlay+1), INTENT(INOUT)  :: tke  ! turbulent kinetic energy at interface between layers
+
+REAL, DIMENSION(ngrid,nlay), INTENT(OUT)      :: Km_out   ! output: Exchange coefficient for momentum at interface between layers
+REAL, DIMENSION(ngrid,nlay), INTENT(OUT)      :: Kh_out   ! output: Exchange coefficient for heat flux at interface between layers
+
+! Local variables
+REAL, DIMENSION(ngrid,nlay+1) :: Km          ! Exchange coefficient for momentum at interface between layers
+REAL, DIMENSION(ngrid,nlay+1) :: Kh          ! Exchange coefficient for heat flux at interface between layers
+REAL, DIMENSION(ngrid,nlay)   :: theta       ! Potential temperature
+REAL, DIMENSION(ngrid,nlay+1) :: l_exchange  ! Length of exchange (at interface)
+REAL, DIMENSION(ngrid,nlay+1) :: z_interf    ! Altitude at the interface
+REAL, DIMENSION(ngrid,nlay)   :: z_lay       ! Altitude of layers
+REAL, DIMENSION(ngrid,nlay)   :: dz_interf   ! distance between two consecutive interfaces
+REAL, DIMENSION(ngrid,nlay)   :: dz_lay      ! distance between two layer middles (NB: first and last are half layers)
+REAL, DIMENSION(ngrid,nlay+1) :: Ri          ! Richardson's number (at interface)
+REAL, DIMENSION(ngrid,nlay+1) :: Prandtl     ! Turbulent Prandtl's number (at interface)
+REAL, DIMENSION(ngrid,nlay+1) :: Sm          ! Stability function for momentum (at interface)
+REAL, DIMENSION(ngrid,nlay+1) :: Sh          ! Stability function for heat (at interface)
+
+INTEGER :: igrid,ilay ! horizontal,vertical index (flat grid)
+REAL    :: cn,Ri0,Ri1    ! parameter for Sm stability function and Prandlt
+REAL    :: preff      ! reference pressure for potential temperature calculations
+REAL    :: thetam     ! mean potential temperature at interface
+
+
+! Initializations:
+!================
+
+DO igrid=1,ngrid
+    dz_interf(igrid,1) = 0.0
+    z_interf(igrid,1) = 0.0
+END DO
+
+! Calculation of potential temperature: (if vapor -> todo virtual potential temperature)
+!=====================================
+
+preff=100000.
+! The result should not depend on the choice of preff
+DO ilay=1,nlay
+     DO igrid = 1, ngrid
+        theta(igrid,ilay)=temp(igrid,ilay)*(preff/play(igrid,ilay))**(rd/rcpd)
+     END DO
+END DO
+
+
+
+! Calculation of altitude of layers' middle and bottom interfaces:
+!=================================================================
+
+DO ilay=2,nlay+1
+    DO igrid=1,ngrid
+        dz_interf(igrid,ilay-1) = rd*temp(igrid,ilay-1)/rg/play(igrid,ilay-1)*(pinterf(igrid,ilay-1)-pinterf(igrid,ilay))
+        z_interf(igrid,ilay) = z_interf(igrid,ilay-1) + dz_interf(igrid,ilay-1)
+    ENDDO
+ENDDO
+
+DO ilay=1,nlay
+   DO igrid=1,ngrid 
+      z_lay(igrid,ilay)=0.5*(z_interf(igrid, ilay+1) + z_interf(igrid, ilay))
+   ENDDO
+ENDDO
+
+
+! Computing the mixing length:
+! so far, we have neglected the effect of local stratification
+!==============================================================
+
+
+DO ilay=2,nlay+1
+    DO igrid=1,ngrid
+        l_exchange(igrid,ilay) = kappa*l0*z_interf(igrid,ilay) / (kappa*z_interf(igrid,ilay) + l0)
+    ENDDO
+ENDDO
+
+! Computes the gradient Richardson's number and stability functions:
+!===================================================================
+
+! calculation of cn = Sm value at Ri=0
+! direct dependance on cepsilon to guarantee Fm=1 (first-order like stability function) at Ri=0
+cn=(1./sqrt(cepsilon))**(2/3)
+! calculation of Ri0 such that continuity in slope of Sm at Ri=0
+Ri0=2./rpi*(cinf - cn)*ric/cn
+! calculation of Ri1 to guarantee continuity in slope of Prandlt number at Ri=0
+Ri1 = -2./rpi * (pr_asym - pr_neut) / pr_slope
+
+
+DO ilay=2,nlay
+    DO igrid=1,ngrid
+        dz_lay(igrid,ilay)=z_lay(igrid,ilay)-z_lay(igrid,ilay-1)
+        thetam=0.5*(theta(igrid,ilay) + theta(igrid,ilay-1))
+        Ri(igrid,ilay) = rg * (theta(igrid,ilay) - theta(igrid,ilay-1))/thetam / dz_lay(igrid,ilay) / & 
+        MAX(((wind_u(igrid,ilay) - wind_u(igrid,ilay-1)) / dz_lay(igrid,ilay))**2 + & 
+        ((wind_v(igrid,ilay) - wind_v(igrid,ilay-1)) / dz_lay(igrid,ilay))**2,1E-10) 
+        
+        IF (Ri(igrid,ilay) < 0.) THEN ! unstable cases
+            Sm(igrid,ilay) = 2./rpi * (cinf-cn) * atan(-Ri(igrid,ilay)/Ri0) + cn
+            Prandtl(igrid,ilay) = -2./rpi * (pr_asym - pr_neut) * atan(Ri(igrid,ilay)/Ri1) + pr_neut 
+        ELSE ! stable cases
+            Sm(igrid,ilay) = max(0.,cn*(1.-Ri(igrid,ilay)/Ric))
+            Prandtl(igrid,ilay) = pr_neut + Ri(igrid,ilay) * pr_slope
+            IF (Ri(igrid,ilay) .GE. Prandtl(igrid,ilay)) THEN
+               call abort_physic("atke_compute_km_kh", &
+               'Ri>=Pr in stable conditions -> violates energy conservation principles, change pr_neut or slope', 1)
+            ENDIF
+        END IF
+        
+        Sh(igrid,ilay) = Sm(igrid,ilay) / Prandtl(igrid,ilay)
+
+    ENDDO
+ENDDO
+
+! Computing the TKE:
+!===================
+IF (iflag_atke == 0) THEN
+
+! stationary solution neglecting the vertical transport of TKE by turbulence
+    DO ilay=2,nlay
+        DO igrid=1,ngrid
+            tke(igrid,ilay) = cepsilon * l_exchange(igrid,ilay)**2 * Sm(igrid,ilay) * &
+            (((wind_u(igrid,ilay) - wind_u(igrid,ilay-1)) / dz_lay(igrid,ilay))**2 + & 
+            ((wind_v(igrid,ilay) - wind_v(igrid,ilay-1)) / dz_lay(igrid,ilay))**2 ) * &
+            (1. - Ri(igrid,ilay) / Prandtl(igrid,ilay))
+        ENDDO
+    ENDDO
+
+ELSE ! TO DO
+    
+   call abort_physic("atke_compute_km_kh", &
+        'traitement non-stationnaire de la tke pas encore prevu', 1)
+
+END IF
+
+
+! Computing eddy diffusivity coefficients:
+!========================================
+DO ilay=2,nlay ! TODO: also calculate for nlay+1 ?
+    DO igrid=1,ngrid
+        ! we add the molecular viscosity to Km,h 
+        Km(igrid,ilay) = viscom + l_exchange(igrid,ilay) * Sm(igrid,ilay) * tke(igrid,ilay)**0.5
+        Kh(igrid,ilay) = viscoh + l_exchange(igrid,ilay) * Sh(igrid,ilay) * tke(igrid,ilay)**0.5
+    END DO
+END DO
+
+! for output:
+!===========
+Km_out(1:ngrid,2:nlay)=Km(1:ngrid,2:nlay)
+Kh_out(1:ngrid,2:nlay)=Kh(1:ngrid,2:nlay)
+
+end subroutine atke_compute_km_kh
+
+
+end module atke_exchange_coeff_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/atke_turbulence_ini_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/atke_turbulence_ini_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/atke_turbulence_ini_mod.F90	(revision 4482)
@@ -0,0 +1,80 @@
+MODULE atke_turbulence_ini_mod
+
+implicit none
+
+save
+
+  integer :: iflag_atke
+  !$OMP THREADPRIVATE(iflag_atke)
+  real :: kappa = 0.4 ! Von Karman constant
+  !$OMP THREADPRIVATE(kappa)
+  real :: l0, ric, ri0, cinf, cepsilon, pr_slope, pr_asym, pr_neut
+  !$OMP THREADPRIVATE(l0, ric, cinf, cepsilon, pr_slope, pr_asym, pr_neut)
+  integer :: lunout,prt_level
+  !$OMP THREADPRIVATE(lunout,prt_level)
+  real :: rg, rd, rpi, rcpd
+  !$OMP THREADPRIVATE(rg, rd, rpi, rcpd)
+
+  real :: viscom, viscoh
+  !$OMP THREADPRIVATE(viscom,viscoh)
+
+
+
+CONTAINS
+
+SUBROUTINE atke_ini(prt_level_in, lunout_in, rg_in, rd_in, rpi_in, rcpd_in)
+
+   USE ioipsl_getin_p_mod, ONLY : getin_p
+
+  integer, intent(in) :: lunout_in,prt_level_in
+  real, intent(in) :: rg_in, rd_in, rpi_in, rcpd_in
+
+
+  lunout=lunout_in
+  prt_level=prt_level_in
+  rd=rd_in
+  rg=rg_in
+  rpi=rpi_in
+  rcpd=rcpd_in
+
+  viscom=1.46E-5
+  viscoh=2.06E-5
+
+  ! flag that controls options in atke_compute_km_kh
+  iflag_atke=0
+  CALL getin_p('iflag_atke',iflag_atke)
+
+  ! asymptotic mixing length [m]
+  l0=150.0 
+  CALL getin_p('atke_l0',l0)
+
+  ! critical Richardson number 
+  ric=0.25
+  CALL getin_p('atke_ric',ric)
+
+  ! asymptotic value of Sm for Ri=-Inf
+  cinf=1.5
+  CALL getin_p('atke_cinf',cinf)
+
+  ! constant for tke dissipation calculation
+  cepsilon=16.6 ! default value as in yamada4
+  CALL getin_p('atke_cepsilon',cepsilon)
+
+  ! slope of Pr=f(Ri) for stable conditions
+  pr_slope=5.0 ! default value from Zilitinkevich et al. 2005
+  CALL getin_p('atke_pr_slope',pr_slope)
+
+  ! asymptotic turbulent prandt number value for Ri=-Inf
+  pr_asym=0.4
+  CALL getin_p('atke_pr_asym',pr_asym)
+
+  ! value of turbulent prandtl number in neutral conditions (Ri=0)
+  pr_neut=0.8
+  CALL getin_p('atke_pr_neut',pr_neut)
+
+   
+ RETURN
+
+END SUBROUTINE atke_ini
+
+END MODULE  atke_turbulence_ini_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/carbon_cycle_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/carbon_cycle_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/carbon_cycle_mod.F90	(revision 4482)
@@ -237,44 +237,34 @@
        IF (.NOT.ALLOCATED(fco2_land)) ALLOCATE(fco2_land(klon), stat=ierr)
        IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation fco2_land',1)
-       fco2_land(1:klon) = 0.
 
        IF (.NOT.ALLOCATED(fco2_land_nbp)) ALLOCATE(fco2_land_nbp(klon), stat=ierr)
        IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation fco2_land_nbp',1)
-       fco2_land_nbp(1:klon) = 0.
 
        IF (.NOT.ALLOCATED(fco2_land_nep)) ALLOCATE(fco2_land_nep(klon), stat=ierr)
        IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation fco2_land_nep',1)
-       fco2_land_nep(1:klon) = 0.
 
        IF (.NOT.ALLOCATED(fco2_land_fLuc)) ALLOCATE(fco2_land_fLuc(klon), stat=ierr)
        IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation fco2_land_fLuc',1)
-       fco2_land_fLuc(1:klon) = 0.
 
        IF (.NOT.ALLOCATED(fco2_land_fwoodharvest)) ALLOCATE(fco2_land_fwoodharvest(klon), stat=ierr)
        IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation fco2_land_fwoodharvest',1)
-       fco2_land_fwoodharvest(1:klon) = 0.
 
        IF (.NOT.ALLOCATED(fco2_land_fHarvest)) ALLOCATE(fco2_land_fHarvest(klon), stat=ierr)
        IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation fco2_land_fHarvest',1)
-       fco2_land_fHarvest(1:klon) = 0.
 
        IF (.NOT.ALLOCATED(fco2_ff)) ALLOCATE(fco2_ff(klon), stat=ierr)
        IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation fco2_ff',1)
-       fco2_ff(1:klon) = 0.
 
        IF (.NOT.ALLOCATED(fco2_bb)) ALLOCATE(fco2_bb(klon), stat=ierr)
        IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation fco2_bb',1)
-       fco2_bb(1:klon) = 0.
 
        IF (.NOT.ALLOCATED(fco2_ocean)) ALLOCATE(fco2_ocean(klon), stat=ierr)
        IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation fco2_ocean',1)
-       fco2_ocean(1:klon) = 0.
 
        IF (.NOT.ALLOCATED(fco2_ocean_cor)) ALLOCATE(fco2_ocean_cor(klon), stat=ierr)
        IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation fco2_ocean_cor',1)
-       fco2_ocean_cor(1:klon) = 0.
+
        IF (.NOT.ALLOCATED(fco2_land_cor)) ALLOCATE(fco2_land_cor(klon), stat=ierr)
        IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation fco2_land_cor',1)
-       fco2_land_cor(1:klon) = 0.
 
     ENDIF
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cdrag_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cdrag_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cdrag_mod.F90	(revision 4482)
@@ -16,4 +16,5 @@
      speed, t1,    q1,    zgeop1, &
      psol,  tsurf, qsurf, z0m, z0h,  &
+     ri_in, iri_in, &
      cdm,  cdh,  zri,   pref)
 
@@ -22,4 +23,5 @@
   USE print_control_mod, ONLY: lunout, prt_level
   USE ioipsl_getin_p_mod, ONLY : getin_p
+  USE atke_turbulence_ini_mod, ONLY : ric, cinf, cepsilon, pr_slope, pr_asym, pr_neut
 
   IMPLICIT NONE
@@ -84,4 +86,6 @@
   REAL, DIMENSION(klon), INTENT(IN)        :: qsurf ! Surface humidity (Kg/Kg)
   REAL, DIMENSION(klon), INTENT(IN)        :: z0m, z0h ! Rugosity at surface (m) 
+  REAL, DIMENSION(klon), INTENT(IN)        :: ri_in ! Input Richardson 1st layer for first guess calculations of screen var. 
+  INTEGER, INTENT(IN)                      :: iri_in! iflag to activate cdrag calculation using ri1
   REAL, DIMENSION(klon), INTENT(IN)        :: t1  ! Temperature au premier niveau (K) 
   REAL, DIMENSION(klon), INTENT(IN)        :: q1  ! humidite specifique au premier niveau (kg/kg)
@@ -123,4 +127,6 @@
   REAL, DIMENSION(klon) :: cdmn, cdhn               ! Drag coefficient in neutral conditions
   REAL zzzcd
+  REAL, DIMENSION(klon) :: sm, prandtl              ! Stability function from atke turbulence scheme
+  REAL                  ri0, ri1, cn                ! to have dimensionless term in sm and prandtl
 
   LOGICAL, SAVE :: firstcall = .TRUE.
@@ -162,5 +168,10 @@
 
   ALPHA=5.0
-  
+
+! Consistent with atke scheme
+cn=(1./sqrt(cepsilon))**(2/3)
+ri0=2./rpi*(cinf - cn)*ric/cn
+ri1=-2./rpi * (pr_asym - pr_neut)/pr_slope
+
 
 ! ================================================================= c
@@ -224,4 +235,7 @@
           *(1.+RETV*max(q1(i),0.0))                      ! negative q1 set to zero
      zri(i) = zgeop1(i)*(ztvd-ztsolv)/(zdu2*ztvd)
+     IF (iri_in.EQ.1) THEN
+       zri(i) = ri_in(i)
+     ENDIF
 
 
@@ -236,4 +250,6 @@
 ! Calcul des fonctions de stabilit?? FMs, FHs, FMi, FHi :
 !*******************************************************
+
+
 
 !''''''''''''''
@@ -280,5 +296,10 @@
            FH(i) = MAX(SQRT(1.0-18.0*zri(i)),f_ri_cd_min)
 
-
+         CASE (6) ! Consistent with turbulence scheme (in stationary case) derived in atke (2023)
+         
+           sm(i) = 2./rpi * (cinf - cn) * atan(-zri(i)/ri0) + cn
+           prandtl(i) = -2./rpi * (pr_asym - pr_neut) * atan(zri(i)/ri1) + pr_neut
+           FM(i) = MAX((sm(i)**(3/2) * sqrt(cepsilon) * (1 - zri(i) / prandtl(i))**(1/2)),f_ri_cd_min)
+           FH(i) = MAX((FM(i) / prandtl(i)), f_ri_cd_min)
 
          CASE default ! Louis 1982
@@ -376,7 +397,9 @@
           endif
 
-
-
-
+        CASE (6) ! Consistent with turbulence scheme (in stationary case) derived in atke (2023)
+          sm(i) = MAX(0.,cn*(1.-zri(i)/ric))
+          prandtl(i) = pr_neut + zri(i) * pr_slope
+          FM(i) = MAX((sm(i)**(3/2) * sqrt(cepsilon) * (1 - zri(i) / prandtl(i))**(1/2)),f_ri_cd_min)
+          FH(i) = MAX((FM(i) / prandtl(i)), f_ri_cd_min)
 
         CASE default ! Louis 1982
@@ -414,409 +437,3 @@
 END SUBROUTINE cdrag
 
-!
- SUBROUTINE cdragn_ri1(knon,  nsrf,   &
-     speed, t1,    q1,    zgeop1, &
-     psol,  tsurf, qsurf, z0m, z0h,  &
-     ri1, iri1, &
-     cdm,  cdh,  zri,   pref)
-
-  USE dimphy
-  USE indice_sol_mod
-  USE print_control_mod, ONLY: lunout, prt_level
-  USE ioipsl_getin_p_mod, ONLY : getin_p
-
-  IMPLICIT NONE
-! ================================================================= c
-!
-! Objet : calcul des cdrags pour le moment (pcfm) et 
-!         les flux de chaleur sensible et latente (pcfh) d'apr??s
-!         Louis 1982, Louis 1979, King et al 2001
-!         ou Zilitinkevich et al 2002  pour les cas stables, Louis 1979
-!         et 1982 pour les cas instables 
-!
-! Modified history: 
-!  writting on the 20/05/2016
-!  modified on the 13/12/2016 to be adapted to LMDZ6
-!
-! References:
-!   Louis, J. F., 1979: A parametric model of vertical eddy fluxes in the
-!     atmosphere. Boundary-Layer Meteorology. 01/1979; 17(2):187-202. 
-!   Louis, J. F., Tiedtke, M. and Geleyn, J. F., 1982: `A short history of the
-!     operational PBL parametrization at ECMWF'. Workshop on boundary layer
-!     parametrization, November 1981, ECMWF, Reading, England. 
-!     Page: 19. Equations in Table 1.
-!   Mascart P, Noilhan J, Giordani H 1995.A MODIFIED PARAMETERIZATION OF FLUX-PROFILE RELATIONSHIPS 
-!    IN THE SURFACE LAYER USING DIFFERENT ROUGHNESS LENGTH VALUES FOR HEAT AND MOMENTUM
-!    Boundary-Layer Meteorology 72: 331-344
-!   Anton Beljaars. May 1992. The parametrization of the planetary boundary layer.  
-!     European Centre for Medium-Range Weather Forecasts.
-!     Equations: 110-113. Page 40.
-!   Miller,M.J., A.C.M.Beljaars, T.N.Palmer. 1992. The sensitivity of the ECMWF
-!     model to the parameterization of evaporation from the tropical oceans. J.
-!     Climate, 5:418-434.
-!   King J.C, Connolley, W.M ad Derbyshire S.H. 2001, Sensitivity of Modelled Antarctic climate
-!   to surface and boundary-layer flux parametrizations
-!   QJRMS, 127, pp 779-794
-!
-! ================================================================= c
-! ================================================================= c
-! On choisit le couple de fonctions de correction avec deux flags:
-! Un pour les cas instables, un autre pour les cas stables
-!
-! iflag_corr_insta:
-!                   1: Louis 1979 avec les modifications de Mascart 1995 (z0/= z0h)
-!                   2: Louis 1982 
-!                   3: Laurent Li
-!
-! iflag_corr_sta:
-!                   1: Louis 1979 avec les modifications de Mascart 1995 (z0/= z0h)
-!                   2: Louis 1982 
-!                   3: Laurent Li
-!                   4: King  2001 (SHARP)
-!                   5: MO 1st order theory (allow collapse of turbulence)
-!            
-!
-!*****************************************************************
-! Parametres d'entree
-!***************************************************************** 
-  
-  INTEGER, INTENT(IN)                      :: knon, nsrf ! nombre de points de grille sur l'horizontal + type de surface
-  REAL, DIMENSION(klon), INTENT(IN)        :: speed ! module du vent au 1er niveau du modele
-  REAL, DIMENSION(klon), INTENT(IN)        :: zgeop1! geopotentiel au 1er niveau du modele
-  REAL, DIMENSION(klon), INTENT(IN)        :: tsurf ! Surface temperature (K)
-  REAL, DIMENSION(klon), INTENT(IN)        :: qsurf ! Surface humidity (Kg/Kg)
-  REAL, DIMENSION(klon), INTENT(IN)        :: z0m, z0h ! Rugosity at surface (m) 
-  REAL, DIMENSION(klon), INTENT(IN)        :: ri1   ! Richardson 1ere couche 
-  INTEGER, INTENT(IN)                      :: iri1   !
-  REAL, DIMENSION(klon), INTENT(IN)        :: t1  ! Temperature au premier niveau (K) 
-  REAL, DIMENSION(klon), INTENT(IN)        :: q1  ! humidite specifique au premier niveau (kg/kg)
-  REAL, DIMENSION(klon), INTENT(IN)        :: psol ! pression au sol
-
-
-
-! Parametres de sortie
-!******************************************************************
-  REAL, DIMENSION(klon), INTENT(OUT)       :: cdm  ! Drag coefficient for heat flux
-  REAL, DIMENSION(klon), INTENT(OUT)       :: cdh  ! Drag coefficient for momentum
-  REAL, DIMENSION(klon), INTENT(OUT)       :: zri   ! Richardson number
-  REAL, DIMENSION(klon), INTENT(OUT)       :: pref  ! Pression au niveau zgeop/RG
-! Variables Locales
-!******************************************************************
- 
-
-  INCLUDE "YOMCST.h"
-  INCLUDE "YOETHF.h"
-  INCLUDE "clesphys.h"
-
-
-  REAL, PARAMETER       :: CKAP=0.40, CKAPT=0.42
-  REAL                   CEPDU2
-  REAL                   ALPHA
-  REAL                   CB,CC,CD,C2,C3
-  REAL                   MU, CM, CH, B, CMstar, CHstar
-  REAL                   PM, PH, BPRIME
-  REAL                   C
-  INTEGER                ng_q1                      ! Number of grids that q1 < 0.0
-  INTEGER                ng_qsurf                   ! Number of grids that qsurf < 0.0
-  INTEGER                i
-  REAL                   zdu2, ztsolv
-  REAL                   ztvd, zscf
-  REAL                   zucf, zcr
-  REAL                   friv, frih
-  REAL, DIMENSION(klon) :: FM, FH                   ! stability functions
-  REAL, DIMENSION(klon) :: cdmn, cdhn               ! Drag coefficient in neutral conditions
-  REAL zzzcd
-
-  LOGICAL, SAVE :: firstcall = .TRUE.
-  !$OMP THREADPRIVATE(firstcall)
-  INTEGER, SAVE :: iflag_corr_sta
-  !$OMP THREADPRIVATE(iflag_corr_sta)
-  INTEGER, SAVE :: iflag_corr_insta
-  !$OMP THREADPRIVATE(iflag_corr_insta)
-
-!===================================================================c
-! Valeurs numeriques des constantes
-!===================================================================c
-
-
-! Minimum du carre du vent
-
- CEPDU2 = (0.1)**2
-! Louis 1982
-
-  CB=5.0
-  CC=5.0
-  CD=5.0
-
-
-! King 2001
-
-  C2=0.25
-  C3=0.0625
-
-  
-! Louis 1979
-
-  BPRIME=4.7
-  B=9.4
-  
-
-!MO
-
-  ALPHA=5.0
-  
-
-! ================================================================= c
-! Tests avant de commencer
-! Fuxing WANG, 04/03/2015
-! To check if there are negative q1, qsurf values.
-!====================================================================c
-  ng_q1 = 0     ! Initialization
-  ng_qsurf = 0  ! Initialization
-  DO i = 1, knon
-     IF (q1(i).LT.0.0)     ng_q1 = ng_q1 + 1
-     IF (qsurf(i).LT.0.0)  ng_qsurf = ng_qsurf + 1
-  ENDDO
-  IF (ng_q1.GT.0 .and. prt_level > 5) THEN
-      WRITE(lunout,*)" *** Warning: Negative q1(humidity at 1st level) values in cdrag.F90 !"
-      WRITE(lunout,*)" The total number of the grids is: ", ng_q1
-      WRITE(lunout,*)" The negative q1 is set to zero "
-!      abort_message="voir ci-dessus"
-!      CALL abort_physic(modname,abort_message,1)
-  ENDIF
-  IF (ng_qsurf.GT.0 .and. prt_level > 5) THEN
-      WRITE(lunout,*)" *** Warning: Negative qsurf(humidity at surface) values in cdrag.F90 !"
-      WRITE(lunout,*)" The total number of the grids is: ", ng_qsurf
-      WRITE(lunout,*)" The negative qsurf is set to zero "
-!      abort_message="voir ci-dessus"
-!      CALL abort_physic(modname,abort_message,1)
-  ENDIF
-
-
-
-!=============================================================================c
-! Calcul du cdrag
-!=============================================================================c
-
-! On choisit les fonctions de stabilite utilisees au premier appel
-!**************************************************************************
-  IF (firstcall) THEN
-   iflag_corr_sta=2
-   iflag_corr_insta=2
- 
-   CALL getin_p('iflag_corr_sta',iflag_corr_sta)
-   CALL getin_p('iflag_corr_insta',iflag_corr_insta)
-
-   firstcall = .FALSE.
- ENDIF
-
-!xxxxxxxxxxxxxxxxxxxxxxx
-  DO i = 1, knon        ! Boucle sur l'horizontal
-!xxxxxxxxxxxxxxxxxxxxxxx
-
-
-! calculs preliminaires:
-!***********************
-     
-
-     zdu2 = MAX(CEPDU2, speed(i)**2)
-     pref(i) = EXP(LOG(psol(i)) - zgeop1(i)/(RD*t1(i)* &
-                 (1.+ RETV * max(q1(i),0.0))))           ! negative q1 set to zero 
-     ztsolv = tsurf(i) * (1.0+RETV*max(qsurf(i),0.0))    ! negative qsurf set to zero
-     ztvd = (t1(i)+zgeop1(i)/RCPD/(1.+RVTMP2*max(q1(i),0.0))) &
-          *(1.+RETV*max(q1(i),0.0))                      ! negative q1 set to zero
-     zri(i) = zgeop1(i)*(ztvd-ztsolv)/(zdu2*ztvd)
-
-     IF (iri1.EQ.1) THEN
-       zri(i) = ri1(i)
-     ENDIF
-
-! Coefficients CD neutres : k^2/ln(z/z0) et k^2/(ln(z/z0)*ln(z/z0h)):
-!********************************************************************
-
-     zzzcd=CKAP/LOG(1.+zgeop1(i)/(RG*z0m(i)))
-     cdmn(i) = zzzcd*zzzcd
-     cdhn(i) = zzzcd*(CKAP/LOG(1.+zgeop1(i)/(RG*z0h(i))))
-
-
-! Calcul des fonctions de stabilit?? FMs, FHs, FMi, FHi :
-!*******************************************************
-
-!''''''''''''''
-! Cas instables
-!''''''''''''''
-
- IF (zri(i) .LT. 0.) THEN    
-
-
-        SELECT CASE (iflag_corr_insta)
-    
-        CASE (1) ! Louis 1979 + Mascart 1995
-
-           MU=LOG(MAX(z0m(i)/z0h(i),0.01))
-           CMstar=6.8741+2.6933*MU-0.3601*(MU**2)+0.0154*(MU**3)
-           PM=0.5233-0.0815*MU+0.0135*(MU**2)-0.001*(MU**3)
-           CHstar=3.2165+4.3431*MU+0.536*(MU**2)-0.0781*(MU**3)
-           PH=0.5802-0.1571*MU+0.0327*(MU**2)-0.0026*(MU**3)
-           CH=CHstar*B*CKAP/LOG(z0m(i)+zgeop1(i)/(RG*z0m(i))) &
-            & * CKAPT/LOG(z0h(i)+zgeop1(i)/(RG*z0h(i)))       &
-            & * ((zgeop1(i)/(RG*z0h(i)))**PH)
-           CM=CMstar*B*CKAP/LOG(z0m(i)+zgeop1(i)/(RG*z0m(i))) &
-            & *CKAP/LOG(z0m(i)+zgeop1(i)/(RG*z0m(i)))         &
-            & * ((zgeop1(i)/(RG*z0m(i)))**PM)
-         
-
-
-
-           FM(i)=1.-B*zri(i)/(1.+CM*SQRT(ABS(zri(i))))
-           FH(i)=1.-B*zri(i)/(1.+CH*SQRT(ABS(zri(i))))
-
-        CASE (2) ! Louis 1982
-
-           zucf = 1./(1.+3.0*CB*CC*cdmn(i)*SQRT(ABS(zri(i)) &
-                *(1.0+zgeop1(i)/(RG*z0m(i)))))
-           FM(i) = AMAX1((1.-2.0*CB*zri(i)*zucf),f_ri_cd_min)
-           FH(i) = AMAX1((1.-3.0*CB*zri(i)*zucf),f_ri_cd_min)
-
-
-        CASE (3) ! Laurent Li
-
-           
-           FM(i) = MAX(SQRT(1.0-18.0*zri(i)),f_ri_cd_min)
-           FH(i) = MAX(SQRT(1.0-18.0*zri(i)),f_ri_cd_min)
-
-
-
-         CASE default ! Louis 1982
-
-           zucf = 1./(1.+3.0*CB*CC*cdmn(i)*SQRT(ABS(zri(i)) &
-                *(1.0+zgeop1(i)/(RG*z0m(i)))))
-           FM(i) = AMAX1((1.-2.0*CB*zri(i)*zucf),f_ri_cd_min)
-           FH(i) = AMAX1((1.-3.0*CB*zri(i)*zucf),f_ri_cd_min)
-
-
-         END SELECT
-
-
-
-! Calcul des drags
-
-
-       cdm(i)=cdmn(i)*FM(i)
-       cdh(i)=f_cdrag_ter*cdhn(i)*FH(i)
-
-
-! Traitement particulier des cas oceaniques
-! on applique Miller et al 1992 en l'absence de gustiness 
-
-  IF (nsrf == is_oce) THEN
-!        cdh(i)=f_cdrag_oce*cdhn(i)*FH(i)
-
-        IF(iflag_gusts==0) THEN
-           zcr = (0.0016/(cdmn(i)*SQRT(zdu2)))*ABS(ztvd-ztsolv)**(1./3.)
-           cdh(i) =f_cdrag_oce* cdhn(i)*(1.0+zcr**1.25)**(1./1.25)
-        ENDIF
-
-
-        cdm(i)=MIN(cdm(i),cdmmax)
-        cdh(i)=MIN(cdh(i),cdhmax)
-
-  END IF
-
-
-
- ELSE                          
-
-!'''''''''''''''
-! Cas stables :
-!'''''''''''''''
-        zri(i) = MIN(20.,zri(i))
-
-       SELECT CASE (iflag_corr_sta)
-    
-        CASE (1) ! Louis 1979 + Mascart 1995
-   
-           FM(i)=MAX(1./((1+BPRIME*zri(i))**2),f_ri_cd_min)
-           FH(i)=FM(i)
-
-
-        CASE (2) ! Louis 1982
-           
-           zscf = SQRT(1.+CD*ABS(zri(i)))
-           FM(i)= AMAX1(1. / (1.+2.*CB*zri(i)/zscf), f_ri_cd_min)
-           FH(i)= AMAX1(1./ (1.+3.*CB*zri(i)*zscf), f_ri_cd_min )
-
-
-        CASE (3) ! Laurent Li
-   
-           FM(i)=MAX(1.0 / (1.0+10.0*zri(i)*(1+8.0*zri(i))),f_ri_cd_min)
-           FH(i)=FM(i)
-
-
-        CASE (4)  ! King 2001
-          
-           if (zri(i) .LT. C2/2.) then
-           FM(i)=MAX((1.-zri(i)/C2)**2,f_ri_cd_min)
-           FH(i)=  FM(i)
-
-
-           else
-           FM(i)=MAX(C3*((C2/zri(i))**2),f_ri_cd_min)
-           FH(i)= FM(i)
-           endif
-
-
-        CASE (5) ! MO
-   
-          if (zri(i) .LT. 1./alpha) then
-
-           FM(i)=MAX((1.-alpha*zri(i))**2,f_ri_cd_min)
-           FH(i)=FM(i)
-
-           else 
-
-
-           FM(i)=MAX(1E-7,f_ri_cd_min)
-           FH(i)=FM(i)
-
-          endif
-
-
-
-
-
-        CASE default ! Louis 1982
-
-           zscf = SQRT(1.+CD*ABS(zri(i)))
-           FM(i)= AMAX1(1. / (1.+2.*CB*zri(i)/zscf), f_ri_cd_min)
-           FH(i)= AMAX1(1./ (1.+3.*CB*zri(i)*zscf), f_ri_cd_min )
-
-
-
-   END SELECT
-
-! Calcul des drags
-
-
-       cdm(i)=cdmn(i)*FM(i)
-       cdh(i)=f_cdrag_ter*cdhn(i)*FH(i)
-
-       IF(nsrf.EQ.is_oce) THEN
-
-        cdh(i)=f_cdrag_oce*cdhn(i)*FH(i)
-        cdm(i)=MIN(cdm(i),cdmmax)
-        cdh(i)=MIN(cdh(i),cdhmax)
-
-      ENDIF
-
-
- ENDIF
-
-!xxxxxxxxxxx
-  END DO   !  Fin de la boucle sur l'horizontal
-!xxxxxxxxxxx
-! ================================================================= c
-     
-END SUBROUTINE cdragn_ri1
-
 END MODULE cdrag_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/clesphys.h
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/clesphys.h	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/clesphys.h	(revision 4482)
@@ -7,5 +7,7 @@
 !
 !..include cles_phys.h
-!
+
+       ! threshold on to activate SSO schemes
+       REAL zrel_oro_t, zpmm_orodr_t, zpmm_orolf_t, zstd_orodr_t
        INTEGER iflag_cycle_diurne
        LOGICAL soil_model,new_oliq,ok_orodr,ok_orolf 
@@ -46,5 +48,4 @@
 !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
@@ -54,4 +55,5 @@
        REAL min_wind_speed,f_gust_wk,f_gust_bl,f_qsat_oce,f_z0qh_oce
        REAL z0m_seaice,z0h_seaice
+       REAL z0m_landice, z0h_landice
        INTEGER iflag_gusts,iflag_z0_oce
 
@@ -109,9 +111,9 @@
      &     , 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,pbl_lmixmin_alpha  &
+     &     , cdmmax,cdhmax,ksta,ksta_ter,f_ri_cd_min                    &
      &     , fmagic, pmagic                                             &
      &     , f_cdrag_ter,f_cdrag_oce,f_rugoro,z0min,tau_gl              &
      &     , min_wind_speed,f_gust_wk,f_gust_bl,f_qsat_oce,f_z0qh_oce   &
-     &     , z0m_seaice,z0h_seaice                                      &
+     &     , z0m_seaice,z0h_seaice,z0m_landice,z0h_landice              &
      &     , freq_outNMC, freq_calNMC                                   &
      &     , lonmin_ins, lonmax_ins, latmin_ins, latmax_ins             &
@@ -121,5 +123,5 @@
      &     , co2_ppm0                                                   &
 !FC
-     &     , Cd_frein                                                   &
+     &     , Cd_frein,zrel_oro_t,zpmm_orodr_t,zpmm_orolf_t,zstd_orodr_t &
      &     , ecrit_LES                                                  &
      &     , ecrit_ins, ecrit_hf, ecrit_day                             &
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cloudth_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cloudth_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cloudth_mod.F90	(revision 4482)
@@ -1146,5 +1146,7 @@
 
       ELSE IF (iflag_cloudth_vert == 5) THEN
-      sigma1s=(0.71794+0.000498239*dz(ind1,ind2))*(fraca(ind1,ind2)**0.5)/(1-fraca(ind1,ind2))*(((sth-senv)**2)**0.5)+ratqs(ind1,ind2)*po(ind1) !Environment
+         sigma1s=(0.71794+0.000498239*dz(ind1,ind2))*(fraca(ind1,ind2)**0.5) &
+              /(1-fraca(ind1,ind2))*(((sth-senv)**2)**0.5) &
+              +ratqs(ind1,ind2)*po(ind1) !Environment
       sigma2s=(0.03218+0.000092655*dz(ind1,ind2))/((fraca(ind1,ind2)+0.02)**0.5)*(((sth-senv)**2)**0.5)+0.002*zqta(ind1,ind2)                   !Thermals
       !sigma1s=(1.1**0.5)*(fraca(ind1,ind2)**0.6)/(1-fraca(ind1,ind2))*((sth-senv)**2)**0.5+0.002*po(ind1)
@@ -1414,5 +1416,7 @@
         !--------------------------------------------
       sigma_th=(0.03218+0.000092655*dz(ind1,ind2))/((fraca(ind1,ind2)+0.01)**0.5)*(((sth-senv)**2)**0.5)+0.002*zqta(ind1,ind2)
-      sigma_env=(0.71794+0.000498239*dz(ind1,ind2))*(fraca(ind1,ind2)**0.5)/(1-fraca(ind1,ind2))*(((sth-senv)**2)**0.5)+ratqs(ind1,ind2)*po(ind1)
+      sigma_env=(0.71794+0.000498239*dz(ind1,ind2))*(fraca(ind1,ind2)**0.5) &
+           /(1-fraca(ind1,ind2))*(((sth-senv)**2)**0.5) &
+           +ratqs(ind1,ind2)*po(ind1)
       xth=sth/(sqrt2*sigma_th)
       xenv=senv/(sqrt2*sigma_env)
@@ -1534,5 +1538,5 @@
 
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-SUBROUTINE cloudth_mpc(klon,klev,ind2,mpc_bl_points,                        &
+SUBROUTINE cloudth_mpc(klon,klev,ind2,iflag_mpc_bl,mpc_bl_points,           &
 &           temp,ztv,po,zqta,fraca,zpspsk,paprs,pplay,ztla,zthl,            &
 &           ratqs,zqs,snowflux,qcloud,qincloud,icefrac,ctot,ctot_vol)
@@ -1582,4 +1586,6 @@
       REAL, DIMENSION(klon),      INTENT(IN)      ::  zqs           ! Saturation specific humidity in the mesh [kg/kg]
       REAL, DIMENSION(klon,klev+1), INTENT(IN)    ::  snowflux      ! snow flux at the interface of the layer [kg/m2/s]
+      INTEGER,                      INTENT(IN)    ::  iflag_mpc_bl  ! option flag for mpc boundary layer clouds param.
+
 
       INTEGER, DIMENSION(klon,klev), INTENT(INOUT) :: mpc_bl_points  ! grid points with convective (thermals) mixed phase clouds
@@ -2020,5 +2026,7 @@
                 + (1.-1./(1.+C_mpc*qith(ind1,ind2))) * athl*(qsith(ind1,ind2)-qslth(ind1))  
 
-            sigma2sc=(sigma2s_factor*((MAX((sthlc-senvl),0.)**2)**0.5)/((fraca(ind1,ind2)+0.02)**sigma2s_power))+0.002*zqta(ind1,ind2)
+            sigma2sc=(sigma2s_factor*((MAX((sthlc-senvl),0.)**2)**0.5) &
+                 /((fraca(ind1,ind2)+0.02)**sigma2s_power)) &
+                 +0.002*zqta(ind1,ind2)
             deltasthc=athl*vert_alpha_th*sigma2sc
      
@@ -2166,5 +2174,7 @@
             ctot_vol(ind1,ind2)=fraca(ind1,ind2)*cth_vol(ind1,ind2)+(1.-1.*fraca(ind1,ind2))*cenv_vol(ind1,ind2)
             IF (qcth(ind1,ind2) .GT. 0) THEN
-                icefrac(ind1,ind2)=fraca(ind1,ind2)*qith(ind1,ind2)/(fraca(ind1,ind2)*qcth(ind1,ind2)+(1.-1.*fraca(ind1,ind2))*qcenv(ind1,ind2))
+               icefrac(ind1,ind2)=fraca(ind1,ind2)*qith(ind1,ind2) &
+                    /(fraca(ind1,ind2)*qcth(ind1,ind2) &
+                    +(1.-1.*fraca(ind1,ind2))*qcenv(ind1,ind2))
                 icefrac(ind1,ind2)=MAX(MIN(1.,icefrac(ind1,ind2)),0.)
             ELSE
@@ -2386,5 +2396,7 @@
     AA=RLSTT/Ka/temp(ind2p1)*(RLSTT/RV/temp(ind2p1)-1.)
     BB=1./(rho(ind2p1)*Dv*qsith(ind2p1))
-    unsurtaustardep=C_cap*(Ni**0.66)*(qth(ind2p1)-qsith(ind2p1))/qsith(ind2p1)*4.*RPI/(AA+BB)*(6.*rho(ind2p1)/rhoi/RPI/Gamma(4.))**(0.33)
+    unsurtaustardep=C_cap*(Ni**0.66)*(qth(ind2p1)-qsith(ind2p1)) &
+         /qsith(ind2p1)*4.*RPI/(AA+BB) &
+         *(6.*rho(ind2p1)/rhoi/RPI/Gamma(4.))**(0.33)
     dep_term=rho(ind2p1)*fraca(ind2p1)*(qith(ind2p1)**0.33)*unsurtaustardep
  
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/coef_diff_turb_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/coef_diff_turb_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/coef_diff_turb_mod.F90	(revision 4482)
@@ -162,5 +162,5 @@
      
        IF (prt_level > 9) THEN
-          WRITE(lunout,*) 'USTAR = ',yustar
+          WRITE(lunout,*) 'USTAR = ',(yustar(i),i=1,knon)
        ENDIF
          
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/conf_phys_m.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/conf_phys_m.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/conf_phys_m.F90	(revision 4482)
@@ -133,9 +133,7 @@
     REAL, SAVE          :: f_rugoro_omp   , z0min_omp
     REAL, SAVE          :: z0m_seaice_omp,z0h_seaice_omp
+    REAL, SAVE          :: z0m_landice_omp,z0h_landice_omp
     REAL, SAVE          :: min_wind_speed_omp,f_gust_wk_omp,f_gust_bl_omp,f_qsat_oce_omp, f_z0qh_oce_omp
     INTEGER, SAVE       :: iflag_gusts_omp,iflag_z0_oce_omp
-
-    ! Local
-    REAL                 :: zzz
 
     REAL :: seuil_inversion
@@ -161,7 +159,8 @@
 
     REAL,SAVE :: R_ecc_omp,R_peri_omp,R_incl_omp,solaire_omp
-    REAL,SAVE      :: solaire_omp_init
+    REAL,SAVE :: solaire_omp_init
     LOGICAL,SAVE :: ok_suntime_rrtm_omp
     REAL,SAVE :: co2_ppm_omp, RCO2_omp, co2_ppm_per_omp, RCO2_per_omp
+    REAL,SAVE :: co2_ppm0_omp
     REAL,SAVE :: CH4_ppb_omp, RCH4_omp, CH4_ppb_per_omp, RCH4_per_omp
     REAL,SAVE :: N2O_ppb_omp, RN2O_omp, N2O_ppb_per_omp, RN2O_per_omp
@@ -186,5 +185,5 @@
     REAL,SAVE :: t_glace_min_omp, t_glace_max_omp
     REAL,SAVE :: exposant_glace_omp
-    INTEGER,SAVE :: iflag_gammasat_omp, iflag_mpc_bl_omp
+    INTEGER,SAVE :: iflag_gammasat_omp
     REAL,SAVE :: rei_min_omp, rei_max_omp
     INTEGER,SAVE :: iflag_sic_omp, iflag_inertie_omp
@@ -199,5 +198,4 @@
     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
@@ -227,4 +225,6 @@
     LOGICAL, SAVE :: ok_lic_cond_omp
     !
+    REAL, SAVE    :: zrel_oro_t_omp, zstd_orodr_t_omp
+    REAL, SAVE    :: zpmm_orodr_t_omp, zpmm_orolf_t_omp
     INTEGER, SAVE :: iflag_cycle_diurne_omp
     LOGICAL, SAVE :: soil_model_omp,new_oliq_omp
@@ -255,5 +255,4 @@
     LOGICAL, SAVE :: ok_new_lscp_omp
     LOGICAL, SAVE :: ok_icefra_lscp_omp
-    LOGICAL, SAVE :: ok_radliq_snow_omp
 
 
@@ -745,24 +744,24 @@
     !
     !Config Key  = co2_ppm
-    !Config Desc = concentration du gaz carbonique en ppmv
+    !Config Desc = concentration du CO2 en ppmv
     !Config Def  = 348.
     !Config Help = 
     !               
-    !
     !valeur AMIP II
     co2_ppm_omp = 348.
     CALL getin('co2_ppm', co2_ppm_omp)
     !
-    !Config Key  = RCO2
-    !Config Desc = Concentration du CO2
-    !Config Def  = co2_ppm * 1.0e-06  * 44.011/28.97
-    !Config Def  = 348. * 1.0e-06  * 44.011/28.97
+    !conversion en rapport de mélange massique
+    RCO2_omp = co2_ppm_omp * 1.0e-06 * RMCO2 / RMD
+
+    !
+    !Config Key  = co2_ppm0
+    !Config Desc = concentration initiale du CO2 en ppmv pour la version ESM avec CO2 interactif dans le cas 
+    !              où cette concentration de figure pas dans l'état de redémarrage de la physique
+    !Config Def  = 284.32
     !Config Help = 
     !               
-    ! RCO2 = 5.286789092164308E-04
-    !ancienne valeur
-    RCO2_omp = co2_ppm_omp * 1.0e-06 * RMCO2 / RMD ! pour co2_ppm=348.
-
-    !  CALL getin('RCO2', RCO2)
+    co2_ppm0_omp = 284.32
+    CALL getin('co2_ppm0', co2_ppm0_omp)
     !
     !Config Key  = RCH4
@@ -771,15 +770,7 @@
     !Config Help = 
     !               
-    !
-    !valeur AMIP II
-    !OK  RCH4 = 1.65E-06* 16.043/28.97
-    ! RCH4 = 9.137366240938903E-07
-    !
-    !ancienne valeur
-    ! RCH4 = 1.72E-06* 16.043/28.97
-    !OK CALL getin('RCH4', RCH4)
-    zzz = 1650.
-    CALL getin('CH4_ppb', zzz)
-    CH4_ppb_omp = zzz
+    CH4_ppb_omp = 1650.
+    CALL getin('CH4_ppb', CH4_ppb_omp)
+    !conversion en rapport de mélange massique
     RCH4_omp = CH4_ppb_omp * 1.0E-09 * RMCH4 / RMD
     !
@@ -789,15 +780,7 @@
     !Config Help = 
     !               
-    !
-    !valeur AMIP II
-    !OK  RN2O = 306.E-09* 44.013/28.97
-    ! RN2O = 4.648939592682085E-07
-    !
-    !ancienne valeur
-    ! RN2O = 310.E-09* 44.013/28.97
-    !OK  CALL getin('RN2O', RN2O)
-    zzz=306.
-    CALL getin('N2O_ppb', zzz)
-    N2O_ppb_omp = zzz
+    N2O_ppb_omp = 306.
+    CALL getin('N2O_ppb', N2O_ppb_omp)
+    !conversion en rapport de mélange massique
     RN2O_omp = N2O_ppb_omp * 1.0E-09 * RMN2O / RMD
     !
@@ -807,12 +790,8 @@
     !Config Help = 
     !               
-    !
-    !OK RCFC11 = 280.E-12* 137.3686/28.97
-    zzz = 280.
-    CALL getin('CFC11_ppt',zzz)
-    CFC11_ppt_omp = zzz
+    CFC11_ppt_omp = 280.
+    CALL getin('CFC11_ppt',CFC11_ppt_omp)
+    !conversion en rapport de mélange massique
     RCFC11_omp=CFC11_ppt_omp* 1.0E-12 * RMCFC11 / RMD
-    ! RCFC11 = 1.327690990680013E-09
-    !OK CALL getin('RCFC11', RCFC11)
     !
     !Config Key  = RCFC12
@@ -821,17 +800,12 @@
     !Config Help = 
     !               
-    !
-    !OK RCFC12 = 484.E-12* 120.9140/28.97
-    zzz = 484.
-    CALL getin('CFC12_ppt',zzz)
-    CFC12_ppt_omp = zzz
+    CFC12_ppt_omp = 484.
+    CALL getin('CFC12_ppt',CFC12_ppt_omp)
+    !conversion en rapport de mélange massique
     RCFC12_omp = CFC12_ppt_omp * 1.0E-12 * RMCFC12 / RMD
-    ! RCFC12 = 2.020102726958923E-09
-    !OK CALL getin('RCFC12', RCFC12)
-
-    !ajout CFMIP begin
+
     !
     !Config Key  = co2_ppm_per
-    !Config Desc = concentration du co2_ppm_per
+    !Config Desc = concentration du CO2 perturbé en ppmv (CFMIP)
     !Config Def  = 348.
     !Config Help = 
@@ -839,17 +813,6 @@
     co2_ppm_per_omp = co2_ppm_omp
     CALL getin('co2_ppm_per', co2_ppm_per_omp)
-    !
-    !Config Key  = RCO2_per
-    !Config Desc = Concentration du CO2_per
-    !Config Def  = co2_ppm_per * 1.0e-06  * 44.011/28.97
-    !Config Def  = 348. * 1.0e-06  * 44.011/28.97
-    !Config Help = 
-    !               
+    !conversion en rapport de mélange massique
     RCO2_per_omp = co2_ppm_per_omp * 1.0e-06 * RMCO2 / RMD
-
-    !Config Key  = ok_4xCO2atm
-    !Config Desc = Calcul ou non effet radiatif 4xco2
-    !Config Def  = .FALSE.
-    !Config Help = 
 
     !Config Key  = RCH4_per
@@ -858,7 +821,7 @@
     !Config Help = 
     !               
-    zzz = CH4_ppb_omp
-    CALL getin('CH4_ppb_per', zzz)
-    CH4_ppb_per_omp = zzz
+    CH4_ppb_per_omp = CH4_ppb_omp
+    CALL getin('CH4_ppb_per', CH4_ppb_per_omp)
+    !conversion en rapport de mélange massique
     RCH4_per_omp = CH4_ppb_per_omp * 1.0E-09 * RMCH4 / RMD
     !
@@ -868,7 +831,7 @@
     !Config Help = 
     !               
-    zzz = N2O_ppb_omp
-    CALL getin('N2O_ppb_per', zzz)
-    N2O_ppb_per_omp = zzz
+    N2O_ppb_per_omp = N2O_ppb_omp
+    CALL getin('N2O_ppb_per', N2O_ppb_per_omp)
+    !conversion en rapport de mélange massique
     RN2O_per_omp = N2O_ppb_per_omp * 1.0E-09 * RMN2O / RMD
     !
@@ -878,7 +841,7 @@
     !Config Help = 
     !               
-    zzz = CFC11_ppt_omp
-    CALL getin('CFC11_ppt_per',zzz)
-    CFC11_ppt_per_omp = zzz
+    CFC11_ppt_per_omp = CFC11_ppt_omp
+    CALL getin('CFC11_ppt_per',CFC11_ppt_per_omp)
+    !conversion en rapport de mélange massique
     RCFC11_per_omp=CFC11_ppt_per_omp* 1.0E-12 * RMCFC11 / RMD
     !
@@ -888,9 +851,8 @@
     !Config Help = 
     !               
-    zzz = CFC12_ppt_omp
-    CALL getin('CFC12_ppt_per',zzz)
-    CFC12_ppt_per_omp = zzz
+    CFC12_ppt_per_omp = CFC12_ppt_omp
+    CALL getin('CFC12_ppt_per',CFC12_ppt_per_omp)
+    !conversion en rapport de mélange massique
     RCFC12_per_omp = CFC12_ppt_per_omp * 1.0E-12 * RMCFC12 / RMD
-    !ajout CFMIP end
 
     !
@@ -937,4 +899,35 @@
     ok_orolf_omp = .TRUE.
     CALL getin('ok_orolf', ok_orolf_omp)
+
+
+    !Config  Key  =  zrel_oro_t
+    !Config  Desc = zrel_oro_t
+    !Config  Def  = 9999.
+    !Config  Help = Connais pas !
+    zrel_oro_t_omp = 9999.
+    CALL getin('zrel_oro_t', zrel_oro_t_omp)
+
+    !Config  Key  =  zstd_orodr_t
+    !Config  Desc = zstd_orodr_t
+    !Config  Def  = 0.
+    !Config  Help = Connais pas !
+    zstd_orodr_t_omp = 10.
+    CALL getin('zstd_orodr_t', zstd_orodr_t_omp)
+
+
+    !Config  Key  =  zpmm_orodr_t
+    !Config  Desc = zpmm_orodr_t
+    !Config  Def  = 0.
+    !Config  Help = Connais pas !
+    zpmm_orodr_t_omp = 100.
+    CALL getin('zpmm_orodr_t', zpmm_orodr_t_omp)
+
+
+    !Config  Key  =  zpmm_orolf_t
+    !Config  Desc = zpmm_orolf_t
+    !Config  Def  = 0.
+    !Config  Help = Connais pas !
+    zpmm_orolf_t_omp = 100.
+    CALL getin('zpmm_orolf_t', zpmm_orolf_t_omp)
 
     !Config  Key  = ok_limitvrai
@@ -1457,15 +1450,4 @@
 
     !
-    !Config Key  = iflag_mpc_bl
-    !Config Desc =
-    !Config Def  = 0
-    !Config Help =
-    !
-    iflag_mpc_bl_omp=0
-    CALL getin('iflag_mpc_bl',iflag_mpc_bl_omp)
-
-
-
-    !
     !Config Key  = iflag_t_glace
     !Config Desc =  
@@ -1635,7 +1617,4 @@
     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)
 
     !
@@ -2123,4 +2102,8 @@
     z0m_seaice_omp = 0.002 ; CALL getin('z0m_seaice',z0m_seaice_omp)
     z0h_seaice_omp = 0.002 ; CALL getin('z0h_seaice',z0h_seaice_omp)
+
+
+    z0m_landice_omp = 0.001 ; CALL getin('z0m_landice',z0m_landice_omp)
+    z0h_landice_omp = 0.001 ; CALL getin('z0h_landice',z0h_landice_omp)
 
     f_rugoro_omp = 0.
@@ -2376,12 +2359,4 @@
     !Config Help = ...
 
-
-    ok_radliq_snow_omp = .FALSE.
-    CALL getin('ok_radliq_snow', ok_radliq_snow_omp)
-    !
-    !Config Key  = ok_radliq_snow_omp
-    !Config Desc = take into account snowfall for radiation
-    !Config Def  = .FALSE.
-    !Config Help = ...
 
     ecrit_LES_omp = 1./8.
@@ -2434,4 +2409,5 @@
     ok_suntime_rrtm = ok_suntime_rrtm_omp
     co2_ppm = co2_ppm_omp
+    co2_ppm0 = co2_ppm0_omp
     RCO2 = RCO2_omp
     CH4_ppb = CH4_ppb_omp
@@ -2459,4 +2435,8 @@
     ok_orodr = ok_orodr_omp
     ok_orolf = ok_orolf_omp
+    zrel_oro_t=zrel_oro_t_omp
+    zstd_orodr_t=zstd_orodr_t_omp
+    zpmm_orodr_t=zpmm_orodr_t_omp
+    zpmm_orolf_t=zpmm_orolf_t_omp
     ok_limitvrai = ok_limitvrai_omp
     nbapp_rad = nbapp_rad_omp
@@ -2500,5 +2480,4 @@
     exposant_glace = exposant_glace_omp
     iflag_gammasat=iflag_gammasat_omp
-    iflag_mpc_bl=iflag_mpc_bl_omp
     iflag_t_glace = iflag_t_glace_omp
     iflag_cloudth_vert=iflag_cloudth_vert_omp
@@ -2520,5 +2499,4 @@
     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
@@ -2666,4 +2644,6 @@
     z0m_seaice=z0m_seaice_omp
     z0h_seaice=z0h_seaice_omp
+    z0m_landice=z0m_landice_omp
+    z0h_landice=z0h_landice_omp
 
     f_rugoro=f_rugoro_omp
@@ -2708,5 +2688,4 @@
     ok_new_lscp = ok_new_lscp_omp
     ok_icefra_lscp=ok_icefra_lscp_omp
-    ok_radliq_snow=ok_radliq_snow_omp
     read_fco2_ocean_cor = read_fco2_ocean_cor_omp
     var_fco2_ocean_cor = var_fco2_ocean_cor_omp
@@ -2863,4 +2842,5 @@
     WRITE(lunout,*) ' ok_suntime_rrtm =',ok_suntime_rrtm
     WRITE(lunout,*) ' co2_ppm =',co2_ppm
+    WRITE(lunout,*) ' co2_ppm0 =',co2_ppm0
     WRITE(lunout,*) ' RCO2_act = ',RCO2_act
     WRITE(lunout,*) ' CH4_ppb =',CH4_ppb,' RCH4_act = ',RCH4_act
@@ -2881,4 +2861,8 @@
     WRITE(lunout,*) ' ok_orodr=',ok_orodr
     WRITE(lunout,*) ' ok_orolf=',ok_orolf
+    WRITE(lunout,*) ' zrel_oro_t=',zrel_oro_t
+    WRITE(lunout,*) ' zstd_orodr_t=',zstd_orodr_t
+    WRITE(lunout,*) ' zpmm_orodr_t=',zpmm_orodr_t
+    WRITE(lunout,*) ' zpmm_orolf_t=',zpmm_orolf_t
     WRITE(lunout,*) ' ok_limitvrai=',ok_limitvrai
     WRITE(lunout,*) ' nbapp_rad=',nbapp_rad
@@ -2929,5 +2913,4 @@
     WRITE(lunout,*) ' exposant_glace = ',exposant_glace
     WRITE(lunout,*) ' iflag_gammasat = ',iflag_gammasat
-    WRITE(lunout,*) ' iflag_mpc_bl = ',iflag_mpc_bl
     WRITE(lunout,*) ' iflag_t_glace = ',iflag_t_glace
     WRITE(lunout,*) ' iflag_cloudth_vert = ',iflag_cloudth_vert
@@ -2948,5 +2931,4 @@
     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
@@ -3048,5 +3030,4 @@
     WRITE(lunout,*) ' ok_new_lscp = ', ok_new_lscp
     WRITE(lunout,*) ' ok_icefra_lscp = ', ok_icefra_lscp
-    WRITE(lunout,*) ' ok_radliq_snow = ', ok_radliq_snow
     WRITE(lunout,*) ' read_climoz = ', read_climoz
     WRITE(lunout,*) ' carbon_cycle_tr = ', carbon_cycle_tr
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cpl_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cpl_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cpl_mod.F90	(revision 4482)
@@ -49,6 +49,8 @@
   !$OMP THREADPRIVATE(cpl_snow,cpl_evap,cpl_tsol)
 
-  REAL, ALLOCATABLE, SAVE:: cpl_delta_sst(:), cpl_delta_sal(:)
-  !$OMP THREADPRIVATE(cpl_delta_sst, cpl_delta_sal)
+  REAL, ALLOCATABLE, SAVE:: cpl_delta_sst(:), cpl_delta_sal(:), cpl_dter(:), &
+       cpl_dser(:), cpl_dt_ds(:)
+  !$OMP THREADPRIVATE(cpl_delta_sst, cpl_delta_sal, cpl_dter, cpl_dser)
+  !$OMP THREADPRIVATE(cpl_dt_ds)
   
   REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_fder, cpl_albe, cpl_taux, cpl_tauy
@@ -64,4 +66,6 @@
   REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: cpl_rriv2D, cpl_rcoa2D, cpl_rlic2D
   !$OMP THREADPRIVATE(cpl_rriv2D,cpl_rcoa2D,cpl_rlic2D)
+  REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: rlic_in_frac2D  ! fraction for continental ice
+  !$OMP THREADPRIVATE(rlic_in_frac2D)
 
 ! variables read from coupler :
@@ -94,6 +98,8 @@
   !$OMP THREADPRIVATE(cpl_snow2D, cpl_evap2D, cpl_tsol2D)
 
-  REAL, ALLOCATABLE, SAVE:: cpl_delta_sst_2D(:,:), cpl_delta_sal_2D(:,:)
+  REAL, ALLOCATABLE, SAVE:: cpl_delta_sst_2D(:, :), cpl_delta_sal_2D(:, :), &
+       cpl_dter_2D(:, :), cpl_dser_2D(:, :), cpl_dt_ds_2D(:, :)
   !$OMP THREADPRIVATE(cpl_delta_sst_2D, cpl_delta_sal_2D)
+  !$OMP THREADPRIVATE(cpl_dter_2D, cpl_dser_2D, cpl_dt_ds_2D)
 
   REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cpl_fder2D, cpl_albe2D
@@ -226,4 +232,6 @@
     ALLOCATE(cpl_rlic2D(nbp_lon,jj_nb), stat=error)
     sum_error = sum_error + error
+    ALLOCATE(rlic_in_frac2D(nbp_lon,jj_nb), stat=error)
+    sum_error = sum_error + error
     ALLOCATE(read_sst(nbp_lon, jj_nb), stat = error)
     sum_error = sum_error + error
@@ -238,5 +246,6 @@
     
        if (activate_ocean_skin == 2) then
-          ALLOCATE(cpl_delta_sst(klon), cpl_delta_sal(klon), stat = error)
+          ALLOCATE(cpl_delta_sst(klon), cpl_delta_sal(klon), cpl_dter(klon), &
+               cpl_dser(klon), cpl_dt_ds(klon), stat = error)
           sum_error = sum_error + error
        end if
@@ -650,5 +659,5 @@
        precip_rain, precip_snow, evap, tsurf, fder, albsol, taux, tauy, windsp,&
        sens_prec_liq, sens_prec_sol, lat_prec_liq, lat_prec_sol, delta_sst, &
-       delta_sal)
+       delta_sal, dTer, dSer, dt_ds)
 
     ! This subroutine cumulates some fields for each time-step during
@@ -683,4 +692,16 @@
     real, intent(in):: delta_sal(:) ! (knon)
     ! Ocean-air interface salinity minus bulk salinity, in ppt.
+
+    REAL, intent(in):: dter(:) ! (knon)
+    ! Temperature variation in the diffusive microlayer, that is
+    ! ocean-air interface temperature minus subskin temperature. In
+    ! K.
+
+    REAL, intent(in):: dser(:) ! (knon)
+    ! Salinity variation in the diffusive microlayer, that is
+    ! ocean-air interface salinity minus subskin salinity. In ppt.
+
+    real, intent(in):: dt_ds(:) ! (knon)
+    ! (tks / tkt) * dTer, in K
 
 ! Local variables
@@ -722,4 +743,7 @@
           cpl_delta_sst = 0.
           cpl_delta_sal = 0.
+          cpl_dter = 0.
+          cpl_dser = 0.
+          cpl_dt_ds = 0.
        end if
     ENDIF
@@ -768,4 +792,7 @@
           cpl_delta_sst(ig) = cpl_delta_sst(ig) + delta_sst(ig) / REAL(nexca)
           cpl_delta_sal(ig) = cpl_delta_sal(ig) + delta_sal(ig) / REAL(nexca)
+          cpl_dter(ig) = cpl_dter(ig) + dter(ig) / REAL(nexca)
+          cpl_dser(ig) = cpl_dser(ig) + dser(ig) / REAL(nexca)
+          cpl_dt_ds(ig) = cpl_dt_ds(ig) + dt_ds(ig) / REAL(nexca)
        end if
      ENDDO
@@ -817,5 +844,7 @@
           if (activate_ocean_skin == 2) then
              ALLOCATE(cpl_delta_sst_2D(nbp_lon, jj_nb), &
-                  cpl_delta_sal_2D(nbp_lon, jj_nb), stat = error)
+                  cpl_delta_sal_2D(nbp_lon, jj_nb), &
+                  cpl_dter_2D(nbp_lon, jj_nb), cpl_dser_2D(nbp_lon, jj_nb), &
+                  cpl_dt_ds_2D(nbp_lon, jj_nb), stat = error)
              sum_error = sum_error + error
           end if
@@ -878,4 +907,7 @@
           CALL gath2cpl(cpl_delta_sst, cpl_delta_sst_2D, knon, knindex)
           CALL gath2cpl(cpl_delta_sal, cpl_delta_sal_2D, knon, knindex)
+          CALL gath2cpl(cpl_dter, cpl_dter_2D, knon, knindex)
+          CALL gath2cpl(cpl_dser, cpl_dser_2D, knon, knindex)
+          CALL gath2cpl(cpl_dt_ds, cpl_dt_ds_2D, knon, knindex)
        end if
     ENDIF
@@ -1151,5 +1183,5 @@
 !
 
-  SUBROUTINE cpl_send_landice_fields(itime, knon, knindex, rlic_in)
+  SUBROUTINE cpl_send_landice_fields(itime, knon, knindex, rlic_in, rlic_in_frac)
 ! This subroutine cumulates the field for melting ice for each time-step 
 ! during a coupling period. This routine will not send to coupler. Sending 
@@ -1165,4 +1197,7 @@
     INTEGER, DIMENSION(klon), INTENT(IN)      :: knindex
     REAL, DIMENSION(klon), INTENT(IN)         :: rlic_in
+    REAL, DIMENSION(klon), INTENT(IN)         :: rlic_in_frac  ! Fraction for continental ice, can be equal to 
+                                                               ! pctsrf(:,is_lic) or not, depending on landice_opt
+    
 
 ! Local varibales
@@ -1179,5 +1214,5 @@
 !$OMP END MASTER
     CALL gath2cpl(rlic_in, rlic2D, knon, knindex)
-
+    CALL gath2cpl(rlic_in_frac(:), rlic_in_frac2D(:,:), knon, knindex) 
 !*************************************************************************************
 ! Reset field to zero in the beginning of a new coupling period 
@@ -1276,4 +1311,7 @@
        tab_flds(:, :, ids_delta_sst) = cpl_delta_sst_2D
        tab_flds(:, :, ids_delta_sal) = cpl_delta_sal_2D
+       tab_flds(:, :, ids_dter) = cpl_dter_2D
+       tab_flds(:, :, ids_dser) = cpl_dser_2D
+       tab_flds(:, :, ids_dt_ds) = cpl_dt_ds_2D
     end if
     
@@ -1298,5 +1336,7 @@
     CALL gath2cpl(pctsrf(:,is_oce), pctsrf2D(:,:,is_oce), klon, unity)
     CALL gath2cpl(pctsrf(:,is_sic), pctsrf2D(:,:,is_sic), klon, unity)
-    CALL gath2cpl(pctsrf(:,is_lic), pctsrf2D(:,:,is_lic), klon, unity)
+
+
+
 
 !*************************************************************************************
@@ -1311,5 +1351,5 @@
         DO j = 1, jj_nb
            tmp_calv(:,j) = DOT_PRODUCT (cpl_rlic2D(1:nbp_lon,j), &
-                pctsrf2D(1:nbp_lon,j,is_lic)) / REAL(nbp_lon)
+                rlic_in_frac2D(1:nbp_lon,j)) / REAL(nbp_lon)
         ENDDO
     
@@ -1348,5 +1388,5 @@
             calving(k)=0
             DO j = 1, jj_nb
-               calving(k)= calving(k)+DOT_PRODUCT(cpl_rlic2D(:,j)*area_calving(:,j,k),pctsrf2D(:,j,is_lic))
+               calving(k)= calving(k)+DOT_PRODUCT(cpl_rlic2D(:,j)*area_calving(:,j,k),rlic_in_frac2D(:,j))
             ENDDO
          ENDDO
@@ -1513,5 +1553,6 @@
     ENDIF
 
-    if (activate_ocean_skin == 2) deallocate(cpl_delta_sst_2d, cpl_delta_sal_2d)
+    if (activate_ocean_skin == 2) deallocate(cpl_delta_sst_2d, &
+         cpl_delta_sal_2d, cpl_dter_2d, cpl_dser_2d, cpl_dt_ds_2d)
 
     IF (sum_error /= 0) THEN
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/create_etat0_limit_unstruct.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/create_etat0_limit_unstruct.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/create_etat0_limit_unstruct.F90	(revision 4482)
@@ -89,5 +89,4 @@
                 abort_message='create_etat0_limit_unstruct, Initial state file are created, all is fine' 
                 CALL abort_physic(modname,abort_message,0)
-                STOP 0
               ENDIF
 !$OMP BARRIER
@@ -110,5 +109,4 @@
               abort_message='create_etat0_limit_unstruct, Initial state file are created, all is fine' 
               CALL abort_physic(modname,abort_message,0)
-              STOP 0
           ENDIF
         ENDIF
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/create_etat0_unstruct.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/create_etat0_unstruct.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/create_etat0_unstruct.F90	(revision 4482)
@@ -53,4 +53,5 @@
   USE phys_state_var_mod
   USE indice_sol_mod
+  USE surface_data,      ONLY: landice_opt
   USE mod_phys_lmdz_para
   USE print_control_mod, ONLY: lunout
@@ -83,5 +84,5 @@
       CALL xios_recv_field("qs",qsol_mpi)
       CALL xios_recv_field("mask",zmasq_mpi)
-      CALL xios_recv_field("landice",lic_mpi)
+      IF (landice_opt .LT. 2) CALL xios_recv_field("landice",lic_mpi)
       CALL xios_recv_field("zmea",zmea_mpi)
       CALL xios_recv_field("zstd",zstd_mpi)
@@ -93,5 +94,5 @@
     CALL scatter_omp(qsol_mpi,qsol)
     CALL scatter_omp(zmasq_mpi,zmasq)
-    CALL scatter_omp(lic_mpi,lic)
+    IF (landice_opt .LT. 2) CALL scatter_omp(lic_mpi,lic)
     CALL scatter_omp(zmea_mpi,zmea)
     CALL scatter_omp(zstd_mpi,zstd)
@@ -110,25 +111,35 @@
 
     pctsrf(:,:) = 0
-    pctsrf(:,is_lic)=lic
-    WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0. 
-    WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
-
-    pctsrf(:,is_ter)=zmasq(:)
-
-!--- Adequation with soil/sea mask
-    DO ji=1,klon
-      IF(zmasq(ji)>EPSFRA) THEN 
-        IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
-          pctsrf(ji,is_lic)=zmasq(ji)
-          pctsrf(ji,is_ter)=0.
-        ELSE
-          pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
-          IF(pctsrf(ji,is_ter)<EPSFRA) THEN
-            pctsrf(ji,is_ter)=0.
-            pctsrf(ji,is_lic)=zmasq(ji)
-          END IF 
-        END IF 
-      END IF 
-    END DO 
+    IF (landice_opt .LT. 2) THEN
+       pctsrf(:,is_lic)=lic
+       WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0.
+       WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
+
+       pctsrf(:,is_ter)=zmasq(:)
+       
+       !--- Adequation with soil/sea mask
+       DO ji=1,klon
+          IF(zmasq(ji)>EPSFRA) THEN 
+             IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
+                pctsrf(ji,is_lic)=zmasq(ji)
+                pctsrf(ji,is_ter)=0.
+             ELSE
+                pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
+                IF(pctsrf(ji,is_ter)<EPSFRA) THEN
+                   pctsrf(ji,is_ter)=0.
+                   pctsrf(ji,is_lic)=zmasq(ji)
+                END IF
+             END IF
+          END IF
+       END DO
+   
+    ELSE
+       ! landice_opt=>2 : no land ice
+       pctsrf(:,is_lic)=0.0
+       pctsrf(:,is_ter)=zmasq(:)
+    END IF
+
+
+
 
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/create_limit_unstruct.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/create_limit_unstruct.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/create_limit_unstruct.F90	(revision 4482)
@@ -111,8 +111,8 @@
       WHERE(NINT(zmasq(:))/=1) rugos(:,l)=0.001
     ENDDO
-    CALL time_interpolation(ndays,rugos,'360d',rugos_year)
+    CALL time_interpolation(ndays,rugos,'360_day',rugos_year)
 
 ! albedo    
-    CALL time_interpolation(ndays,albedo,'360d',albedo_year)
+    CALL time_interpolation(ndays,albedo,'360_day',albedo_year)
 
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cv30_routines.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cv30_routines.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/cv30_routines.F90	(revision 4482)
@@ -3349,5 +3349,5 @@
            write(*,*) 'clw(i,k)=',clw(i,k)
            write(*,*) 'cpd,cpv=',cpd,cpv
-           CALL abort_physic(modname,abort_message,0)
+           CALL abort_physic(modname,abort_message,1)
         endif
        enddo !do k=1,nl
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/1DUTILS.h
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/1DUTILS.h	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/1DUTILS.h	(revision 4482)
@@ -1708,9 +1708,9 @@
 
 !
-        print *,'dtime, tau ',dtime,tau
-        print *, 'u_targ',u_targ
-        print *, 'v_targ',v_targ
-        print *,'zonal velocity ',u
-        print *,'meridional velocity ',v
+        !print *,'dtime, tau ',dtime,tau
+        !print *, 'u_targ',u_targ
+        !print *, 'v_targ',v_targ
+        !print *,'zonal velocity ',u
+        !print *,'meridional velocity ',v
         DO k = 1,klev
          DO i = 1,klon
@@ -1721,6 +1721,6 @@
             d_v(i,k) = d_v(i,k) + 1./tau*(v_targ(i,k)-v(i,k))
 !
-            print *,' k,u,d_u,v,d_v ',    &
-                      k,u(i,k),d_u(i,k),v(i,k),d_v(i,k)
+!           print *,' k,u,d_u,v,d_v ',    &
+!                     k,u(i,k),d_u(i,k),v(i,k),d_v(i,k)
 !           ENDIF
 !
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/1D_interp_cases.h
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/1D_interp_cases.h	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/1D_interp_cases.h	(revision 4482)
@@ -10,5 +10,5 @@
 !    &       ,year_ini_cas,day_ju_ini_cas,nt_cas,pdt_cas,nlev_cas                           &
      &       ,nt_cas,nlev_cas                                                               &
-     &       ,ts_cas,ps_cas,plev_cas,t_cas,th_cas,thv_cas,thl_cas,qv_cas,ql_cas,qi_cas      &
+     &       ,ts_cas,tskin_cas,ps_cas,plev_cas,t_cas,th_cas,thv_cas,thl_cas,qv_cas,ql_cas,qi_cas      &
      &       ,u_cas,v_cas,ug_cas,vg_cas                                                     &
      &       ,temp_nudg_cas,qv_nudg_cas,u_nudg_cas,v_nudg_cas                               &
@@ -19,5 +19,5 @@
      &       ,uw_cas,vw_cas,q1_cas,q2_cas,tkes_cas                                           &
 !
-     &       ,ts_prof_cas,ps_prof_cas,plev_prof_cas,t_prof_cas,theta_prof_cas,thv_prof_cas  &
+     &       ,ts_prof_cas,tskin_prof_cas,ps_prof_cas,plev_prof_cas,t_prof_cas,theta_prof_cas,thv_prof_cas  &
      &       ,thl_prof_cas,qv_prof_cas,ql_prof_cas,qi_prof_cas                              &
      &       ,u_prof_cas,v_prof_cas,ug_prof_cas,vg_prof_cas                                 &
@@ -31,5 +31,9 @@
      &       ,sens_prof_cas,ustar_prof_cas,uw_prof_cas,vw_prof_cas,q1_prof_cas,q2_prof_cas,tkes_prof_cas)
 ! EV tg instead of ts_cur
-             tg = ts_prof_cas 
+             tg = ts_prof_cas
+             if ((tg .eq. 0.) .and. (tskin_prof_cas .ne. 0.)) then
+                tg=tskin_prof_cas
+              endif
+
 !            psurf=plev_prof_cas(1)
              psurf=ps_prof_cas
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/1D_read_forc_cases.h
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/1D_read_forc_cases.h	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/1D_read_forc_cases.h	(revision 4482)
@@ -24,5 +24,5 @@
 !    &       ,year_ini_cas,day_ju_ini_cas,nt_cas,pdt_cas,nlev_cas                           &
      &       ,nt_cas,nlev_cas                                                               &
-     &       ,ts_cas,ps_cas,plev_cas,t_cas,th_cas,thv_cas,thl_cas,qv_cas,ql_cas,qi_cas      &
+     &       ,ts_cas,tskin_cas,ps_cas,plev_cas,t_cas,th_cas,thv_cas,thl_cas,qv_cas,ql_cas,qi_cas      &
      &       ,u_cas,v_cas,ug_cas,vg_cas                                                     &
      &       ,temp_nudg_cas,qv_nudg_cas,u_nudg_cas,v_nudg_cas                               &
@@ -33,5 +33,5 @@
      &       ,uw_cas,vw_cas,q1_cas,q2_cas,tkes_cas                                           &
 !
-     &       ,ts_prof_cas,ps_prof_cas,plev_prof_cas,t_prof_cas,theta_prof_cas,thv_prof_cas  &
+     &       ,ts_prof_cas,tskin_prof_cas,ps_prof_cas,plev_prof_cas,t_prof_cas,theta_prof_cas,thv_prof_cas  &
      &       ,thl_prof_cas,qv_prof_cas,ql_prof_cas,qi_prof_cas                              &
      &       ,u_prof_cas,v_prof_cas,ug_prof_cas,vg_prof_cas                                 &
@@ -73,9 +73,15 @@
 
 ! initial and boundary conditions :
-!     tsurf = ts_prof_cas
       psurf = ps_prof_cas
-      !EV tg instead of ts_cur
-      tg = ts_prof_cas 
-      print*, 'tg=', tg
+      if (tskin_prof_cas .NE. 0.) THEN
+          tsurf=tskin_prof_cas
+      endif
+
+      tg = ts_prof_cas
+      if ((tg .eq. 0.) .and. (tskin_prof_cas .NE. 0.)) THEN
+          tg=tskin_prof_cas
+      endif
+
+
 
       do l = 1, llm
@@ -83,4 +89,5 @@
        q(l,1) = qv_mod_cas(l)
        q(l,2) = ql_mod_cas(l)
+       q(l,3) = qi_mod_cas(l)
        u(l) = u_mod_cas(l)
        ug(l)= ug_mod_cas(l)
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/mod_1D_cases_read2.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/mod_1D_cases_read2.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/mod_1D_cases_read2.F90	(revision 4482)
@@ -5,724 +5,712 @@
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!Declarations specifiques au cas standard
-        character*80 :: fich_cas
-! Discr?tisation 
-        integer nlev_cas, nt_cas
-
-
-!profils environnementaux
-        real, allocatable::  plev_cas(:,:),plevh_cas(:)
-        real, allocatable::  ap_cas(:),bp_cas(:)
-
-        real, allocatable::  z_cas(:,:),zh_cas(:)
-        real, allocatable::  t_cas(:,:),q_cas(:,:),qv_cas(:,:),ql_cas(:,:),qi_cas(:,:),rh_cas(:,:)
-        real, allocatable::  th_cas(:,:),thv_cas(:,:),thl_cas(:,:),rv_cas(:,:)
-        real, allocatable::  u_cas(:,:),v_cas(:,:),vitw_cas(:,:),omega_cas(:,:)
-
-!forcing
-        real, allocatable::  ht_cas(:,:),vt_cas(:,:),dt_cas(:,:),dtrad_cas(:,:)
-        real, allocatable::  hth_cas(:,:),vth_cas(:,:),dth_cas(:,:)
-        real, allocatable::  hq_cas(:,:),vq_cas(:,:),dq_cas(:,:)
-        real, allocatable::  hr_cas(:,:),vr_cas(:,:),dr_cas(:,:)
-        real, allocatable::  hu_cas(:,:),vu_cas(:,:),du_cas(:,:)
-        real, allocatable::  hv_cas(:,:),vv_cas(:,:),dv_cas(:,:)
-        real, allocatable::  ug_cas(:,:),vg_cas(:,:)
-        real, allocatable::  lat_cas(:),sens_cas(:),ts_cas(:),ps_cas(:),ustar_cas(:)
-        real, allocatable::  uw_cas(:,:),vw_cas(:,:),q1_cas(:,:),q2_cas(:,:),tke_cas(:)
-
-!champs interpoles
-        real, allocatable::  plev_prof_cas(:)
-        real, allocatable::  t_prof_cas(:)
-        real, allocatable::  theta_prof_cas(:)
-        real, allocatable::  thl_prof_cas(:)
-        real, allocatable::  thv_prof_cas(:)
-        real, allocatable::  q_prof_cas(:)
-        real, allocatable::  qv_prof_cas(:)
-        real, allocatable::  ql_prof_cas(:)
-        real, allocatable::  qi_prof_cas(:)
-        real, allocatable::  rh_prof_cas(:)
-        real, allocatable::  rv_prof_cas(:)
-        real, allocatable::  u_prof_cas(:)
-        real, allocatable::  v_prof_cas(:)        
-        real, allocatable::  vitw_prof_cas(:)
-        real, allocatable::  omega_prof_cas(:)
-        real, allocatable::  ug_prof_cas(:)
-        real, allocatable::  vg_prof_cas(:)
-        real, allocatable::  ht_prof_cas(:)
-        real, allocatable::  hth_prof_cas(:)
-        real, allocatable::  hq_prof_cas(:)
-        real, allocatable::  vt_prof_cas(:)
-        real, allocatable::  vth_prof_cas(:)
-        real, allocatable::  vq_prof_cas(:)
-        real, allocatable::  dt_prof_cas(:)
-        real, allocatable::  dth_prof_cas(:)
-        real, allocatable::  dtrad_prof_cas(:)
-        real, allocatable::  dq_prof_cas(:)
-        real, allocatable::  hu_prof_cas(:)
-        real, allocatable::  hv_prof_cas(:)
-        real, allocatable::  vu_prof_cas(:)
-        real, allocatable::  vv_prof_cas(:)
-        real, allocatable::  du_prof_cas(:)
-        real, allocatable::  dv_prof_cas(:)
-        real, allocatable::  uw_prof_cas(:)
-        real, allocatable::  vw_prof_cas(:)
-        real, allocatable::  q1_prof_cas(:)
-        real, allocatable::  q2_prof_cas(:)
-
-
-        real lat_prof_cas,sens_prof_cas,ts_prof_cas,ps_prof_cas,ustar_prof_cas,tke_prof_cas
-        real o3_cas,orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough,rugos_cas,sand_cas,clay_cas
-      
+  !Declarations specifiques au cas standard
+  character*80 :: fich_cas
+  ! Discr?tisation 
+  integer nlev_cas, nt_cas
+
+
+  !profils environnementaux
+  real, allocatable::  plev_cas(:,:),plevh_cas(:)
+  real, allocatable::  ap_cas(:),bp_cas(:)
+
+  real, allocatable::  z_cas(:,:),zh_cas(:)
+  real, allocatable::  t_cas(:,:),q_cas(:,:),qv_cas(:,:),ql_cas(:,:),qi_cas(:,:),rh_cas(:,:)
+  real, allocatable::  th_cas(:,:),thv_cas(:,:),thl_cas(:,:),rv_cas(:,:)
+  real, allocatable::  u_cas(:,:),v_cas(:,:),vitw_cas(:,:),omega_cas(:,:)
+
+  !forcing
+  real, allocatable::  ht_cas(:,:),vt_cas(:,:),dt_cas(:,:),dtrad_cas(:,:)
+  real, allocatable::  hth_cas(:,:),vth_cas(:,:),dth_cas(:,:)
+  real, allocatable::  hq_cas(:,:),vq_cas(:,:),dq_cas(:,:)
+  real, allocatable::  hr_cas(:,:),vr_cas(:,:),dr_cas(:,:)
+  real, allocatable::  hu_cas(:,:),vu_cas(:,:),du_cas(:,:)
+  real, allocatable::  hv_cas(:,:),vv_cas(:,:),dv_cas(:,:)
+  real, allocatable::  ug_cas(:,:),vg_cas(:,:)
+  real, allocatable::  lat_cas(:),sens_cas(:),ts_cas(:),ps_cas(:),ustar_cas(:)
+  real, allocatable::  uw_cas(:,:),vw_cas(:,:),q1_cas(:,:),q2_cas(:,:),tke_cas(:)
+
+  !champs interpoles
+  real, allocatable::  plev_prof_cas(:)
+  real, allocatable::  t_prof_cas(:)
+  real, allocatable::  theta_prof_cas(:)
+  real, allocatable::  thl_prof_cas(:)
+  real, allocatable::  thv_prof_cas(:)
+  real, allocatable::  q_prof_cas(:)
+  real, allocatable::  qv_prof_cas(:)
+  real, allocatable::  ql_prof_cas(:)
+  real, allocatable::  qi_prof_cas(:)
+  real, allocatable::  rh_prof_cas(:)
+  real, allocatable::  rv_prof_cas(:)
+  real, allocatable::  u_prof_cas(:)
+  real, allocatable::  v_prof_cas(:)        
+  real, allocatable::  vitw_prof_cas(:)
+  real, allocatable::  omega_prof_cas(:)
+  real, allocatable::  ug_prof_cas(:)
+  real, allocatable::  vg_prof_cas(:)
+  real, allocatable::  ht_prof_cas(:)
+  real, allocatable::  hth_prof_cas(:)
+  real, allocatable::  hq_prof_cas(:)
+  real, allocatable::  vt_prof_cas(:)
+  real, allocatable::  vth_prof_cas(:)
+  real, allocatable::  vq_prof_cas(:)
+  real, allocatable::  dt_prof_cas(:)
+  real, allocatable::  dth_prof_cas(:)
+  real, allocatable::  dtrad_prof_cas(:)
+  real, allocatable::  dq_prof_cas(:)
+  real, allocatable::  hu_prof_cas(:)
+  real, allocatable::  hv_prof_cas(:)
+  real, allocatable::  vu_prof_cas(:)
+  real, allocatable::  vv_prof_cas(:)
+  real, allocatable::  du_prof_cas(:)
+  real, allocatable::  dv_prof_cas(:)
+  real, allocatable::  uw_prof_cas(:)
+  real, allocatable::  vw_prof_cas(:)
+  real, allocatable::  q1_prof_cas(:)
+  real, allocatable::  q2_prof_cas(:)
+
+
+  real lat_prof_cas,sens_prof_cas,ts_prof_cas,ps_prof_cas,ustar_prof_cas,tke_prof_cas
+  real o3_cas,orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough,rugos_cas,sand_cas,clay_cas
+
 
 
 CONTAINS
 
-SUBROUTINE read_1D_cas
-      implicit none
+  SUBROUTINE read_1D_cas
+    implicit none
 
 #include "netcdf.inc"
 
-      INTEGER nid,rid,ierr
-      INTEGER ii,jj
-
-      fich_cas='setup/cas.nc'
-      print*,'fich_cas ',fich_cas
-      ierr = NF_OPEN(fich_cas,NF_NOWRITE,nid)
-      print*,'fich_cas,NF_NOWRITE,nid ',fich_cas,NF_NOWRITE,nid
-      if (ierr.NE.NF_NOERR) then
-         write(*,*) 'ERROR: GROS Pb opening forcings nc file '
-         write(*,*) NF_STRERROR(ierr)
-         stop ""
-      endif
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'lat',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension lat'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,ii)
-      print*,'OK1 nid,rid,lat',nid,rid,ii
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'lon',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension lon'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,jj)
-      print*,'OK2 nid,rid,lat',nid,rid,jj
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'lev',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension zz'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,nlev_cas)
-      print*,'OK3 nid,rid,nlev_cas',nid,rid,nlev_cas
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'time',rid)
-      print*,'nid,rid',nid,rid
-      nt_cas=0
-      IF (ierr.NE.NF_NOERR) THEN
-        stop 'probleme lecture dimension sens'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,nt_cas)
-      print*,'OK4 nid,rid,nt_cas',nid,rid,nt_cas
+    INTEGER nid,rid,ierr
+    INTEGER ii,jj
+
+    fich_cas='setup/cas.nc'
+    print*,'fich_cas ',fich_cas
+    ierr = NF_OPEN(fich_cas,NF_NOWRITE,nid)
+    print*,'fich_cas,NF_NOWRITE,nid ',fich_cas,NF_NOWRITE,nid
+    if (ierr.NE.NF_NOERR) then
+       write(*,*) 'ERROR: GROS Pb opening forcings nc file '
+       write(*,*) NF_STRERROR(ierr)
+       stop ""
+    endif
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'lat',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension lat'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,ii)
+    print*,'OK1 nid,rid,lat',nid,rid,ii
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'lon',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension lon'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,jj)
+    print*,'OK2 nid,rid,lat',nid,rid,jj
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'lev',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension zz'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,nlev_cas)
+    print*,'OK3 nid,rid,nlev_cas',nid,rid,nlev_cas
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'time',rid)
+    print*,'nid,rid',nid,rid
+    nt_cas=0
+    IF (ierr.NE.NF_NOERR) THEN
+       stop 'probleme lecture dimension sens'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,nt_cas)
+    print*,'OK4 nid,rid,nt_cas',nid,rid,nt_cas
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!profils moyens:
-        allocate(plev_cas(nlev_cas,nt_cas))        
-        allocate(z_cas(nlev_cas,nt_cas))
-        allocate(t_cas(nlev_cas,nt_cas),q_cas(nlev_cas,nt_cas),rh_cas(nlev_cas,nt_cas))
-        allocate(th_cas(nlev_cas,nt_cas),rv_cas(nlev_cas,nt_cas))
-        allocate(u_cas(nlev_cas,nt_cas))
-        allocate(v_cas(nlev_cas,nt_cas))
-
-!forcing
-        allocate(ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas),dt_cas(nlev_cas,nt_cas),dtrad_cas(nlev_cas,nt_cas))
-        allocate(hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas),dq_cas(nlev_cas,nt_cas))
-        allocate(hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas),dth_cas(nlev_cas,nt_cas))
-        allocate(hr_cas(nlev_cas,nt_cas),vr_cas(nlev_cas,nt_cas),dr_cas(nlev_cas,nt_cas))
-        allocate(hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas),du_cas(nlev_cas,nt_cas))
-        allocate(hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas),dv_cas(nlev_cas,nt_cas))
-        allocate(vitw_cas(nlev_cas,nt_cas))
-        allocate(ug_cas(nlev_cas,nt_cas))
-        allocate(vg_cas(nlev_cas,nt_cas))
-        allocate(lat_cas(nt_cas),sens_cas(nt_cas),ts_cas(nt_cas),ps_cas(nt_cas),ustar_cas(nt_cas))
-        allocate(uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas),q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas))
-
-
-!champs interpoles
-        allocate(plev_prof_cas(nlev_cas))
-        allocate(t_prof_cas(nlev_cas))
-        allocate(q_prof_cas(nlev_cas))
-        allocate(u_prof_cas(nlev_cas))
-        allocate(v_prof_cas(nlev_cas))
-
-        allocate(vitw_prof_cas(nlev_cas))
-        allocate(ug_prof_cas(nlev_cas))
-        allocate(vg_prof_cas(nlev_cas))
-        allocate(ht_prof_cas(nlev_cas))
-        allocate(hq_prof_cas(nlev_cas))
-        allocate(hu_prof_cas(nlev_cas))
-        allocate(hv_prof_cas(nlev_cas))
-        allocate(vt_prof_cas(nlev_cas))
-        allocate(vq_prof_cas(nlev_cas))
-        allocate(vu_prof_cas(nlev_cas))
-        allocate(vv_prof_cas(nlev_cas))
-        allocate(dt_prof_cas(nlev_cas))
-        allocate(dtrad_prof_cas(nlev_cas))
-        allocate(dq_prof_cas(nlev_cas))
-        allocate(du_prof_cas(nlev_cas))
-        allocate(dv_prof_cas(nlev_cas))
-        allocate(uw_prof_cas(nlev_cas))
-        allocate(vw_prof_cas(nlev_cas))
-        allocate(q1_prof_cas(nlev_cas))
-        allocate(q2_prof_cas(nlev_cas))
-
-        print*,'Allocations OK'
-        call read_cas2(nid,nlev_cas,nt_cas                                       &
-     &     ,z_cas,plev_cas,t_cas,q_cas,rh_cas,th_cas,rv_cas,u_cas,v_cas         &
-     &     ,ug_cas,vg_cas,vitw_cas,du_cas,hu_cas,vu_cas,dv_cas,hv_cas,vv_cas    &
-     &     ,dt_cas,dtrad_cas,ht_cas,vt_cas,dq_cas,hq_cas,vq_cas                 &
-     &     ,dth_cas,hth_cas,vth_cas,dr_cas,hr_cas,vr_cas,sens_cas,lat_cas,ts_cas&
-     &     ,ustar_cas,uw_cas,vw_cas,q1_cas,q2_cas)
-        print*,'Read cas OK'
-
-
-END SUBROUTINE read_1D_cas
-!**********************************************************************************************
-SUBROUTINE read2_1D_cas
-      implicit none
+    !profils moyens:
+    allocate(plev_cas(nlev_cas,nt_cas))        
+    allocate(z_cas(nlev_cas,nt_cas))
+    allocate(t_cas(nlev_cas,nt_cas),q_cas(nlev_cas,nt_cas),rh_cas(nlev_cas,nt_cas))
+    allocate(th_cas(nlev_cas,nt_cas),rv_cas(nlev_cas,nt_cas))
+    allocate(u_cas(nlev_cas,nt_cas))
+    allocate(v_cas(nlev_cas,nt_cas))
+
+    !forcing
+    allocate(ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas),dt_cas(nlev_cas,nt_cas),dtrad_cas(nlev_cas,nt_cas))
+    allocate(hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas),dq_cas(nlev_cas,nt_cas))
+    allocate(hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas),dth_cas(nlev_cas,nt_cas))
+    allocate(hr_cas(nlev_cas,nt_cas),vr_cas(nlev_cas,nt_cas),dr_cas(nlev_cas,nt_cas))
+    allocate(hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas),du_cas(nlev_cas,nt_cas))
+    allocate(hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas),dv_cas(nlev_cas,nt_cas))
+    allocate(vitw_cas(nlev_cas,nt_cas))
+    allocate(ug_cas(nlev_cas,nt_cas))
+    allocate(vg_cas(nlev_cas,nt_cas))
+    allocate(lat_cas(nt_cas),sens_cas(nt_cas),ts_cas(nt_cas),ps_cas(nt_cas),ustar_cas(nt_cas))
+    allocate(uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas),q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas))
+
+
+    !champs interpoles
+    allocate(plev_prof_cas(nlev_cas))
+    allocate(t_prof_cas(nlev_cas))
+    allocate(q_prof_cas(nlev_cas))
+    allocate(u_prof_cas(nlev_cas))
+    allocate(v_prof_cas(nlev_cas))
+
+    allocate(vitw_prof_cas(nlev_cas))
+    allocate(ug_prof_cas(nlev_cas))
+    allocate(vg_prof_cas(nlev_cas))
+    allocate(ht_prof_cas(nlev_cas))
+    allocate(hq_prof_cas(nlev_cas))
+    allocate(hu_prof_cas(nlev_cas))
+    allocate(hv_prof_cas(nlev_cas))
+    allocate(vt_prof_cas(nlev_cas))
+    allocate(vq_prof_cas(nlev_cas))
+    allocate(vu_prof_cas(nlev_cas))
+    allocate(vv_prof_cas(nlev_cas))
+    allocate(dt_prof_cas(nlev_cas))
+    allocate(dtrad_prof_cas(nlev_cas))
+    allocate(dq_prof_cas(nlev_cas))
+    allocate(du_prof_cas(nlev_cas))
+    allocate(dv_prof_cas(nlev_cas))
+    allocate(uw_prof_cas(nlev_cas))
+    allocate(vw_prof_cas(nlev_cas))
+    allocate(q1_prof_cas(nlev_cas))
+    allocate(q2_prof_cas(nlev_cas))
+
+    print*,'Allocations OK'
+    call read_cas2(nid,nlev_cas,nt_cas                                       &
+         ,z_cas,plev_cas,t_cas,q_cas,rh_cas,th_cas,rv_cas,u_cas,v_cas         &
+         ,ug_cas,vg_cas,vitw_cas,du_cas,hu_cas,vu_cas,dv_cas,hv_cas,vv_cas    &
+         ,dt_cas,dtrad_cas,ht_cas,vt_cas,dq_cas,hq_cas,vq_cas                 &
+         ,dth_cas,hth_cas,vth_cas,dr_cas,hr_cas,vr_cas,sens_cas,lat_cas,ts_cas&
+         ,ustar_cas,uw_cas,vw_cas,q1_cas,q2_cas)
+    print*,'Read cas OK'
+
+
+  END SUBROUTINE read_1D_cas
+  !**********************************************************************************************
+  SUBROUTINE read2_1D_cas
+    implicit none
 
 #include "netcdf.inc"
 
-      INTEGER nid,rid,ierr
-      INTEGER ii,jj
-
-      fich_cas='setup/cas.nc'
-      print*,'fich_cas ',fich_cas
-      ierr = NF_OPEN(fich_cas,NF_NOWRITE,nid)
-      print*,'fich_cas,NF_NOWRITE,nid ',fich_cas,NF_NOWRITE,nid
-      if (ierr.NE.NF_NOERR) then
-         write(*,*) 'ERROR: GROS Pb opening forcings nc file '
-         write(*,*) NF_STRERROR(ierr)
-         stop ""
-      endif
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'lat',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension lat'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,ii)
-      print*,'OK1 read2: nid,rid,lat',nid,rid,ii
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'lon',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension lon'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,jj)
-      print*,'OK2 read2: nid,rid,lat',nid,rid,jj
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'nlev',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension nlev'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,nlev_cas)
-      print*,'OK3 read2: nid,rid,nlev_cas',nid,rid,nlev_cas
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'time',rid)
-      nt_cas=0
-      IF (ierr.NE.NF_NOERR) THEN
-        stop 'Oh probleme lecture dimension time'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,nt_cas)
-      print*,'OK4 read2: nid,rid,nt_cas',nid,rid,nt_cas
+    INTEGER nid,rid,ierr
+    INTEGER ii,jj
+
+    fich_cas='setup/cas.nc'
+    print*,'fich_cas ',fich_cas
+    ierr = NF_OPEN(fich_cas,NF_NOWRITE,nid)
+    print*,'fich_cas,NF_NOWRITE,nid ',fich_cas,NF_NOWRITE,nid
+    if (ierr.NE.NF_NOERR) then
+       write(*,*) 'ERROR: GROS Pb opening forcings nc file '
+       write(*,*) NF_STRERROR(ierr)
+       stop ""
+    endif
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'lat',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension lat'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,ii)
+    print*,'OK1 read2: nid,rid,lat',nid,rid,ii
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'lon',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension lon'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,jj)
+    print*,'OK2 read2: nid,rid,lat',nid,rid,jj
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'nlev',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension nlev'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,nlev_cas)
+    print*,'OK3 read2: nid,rid,nlev_cas',nid,rid,nlev_cas
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'time',rid)
+    nt_cas=0
+    IF (ierr.NE.NF_NOERR) THEN
+       stop 'Oh probleme lecture dimension time'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,nt_cas)
+    print*,'OK4 read2: nid,rid,nt_cas',nid,rid,nt_cas
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!profils moyens:
-        allocate(plev_cas(nlev_cas,nt_cas),plevh_cas(nlev_cas+1))        
-        allocate(z_cas(nlev_cas,nt_cas),zh_cas(nlev_cas+1))
-        allocate(ap_cas(nlev_cas+1),bp_cas(nt_cas+1))
-        allocate(t_cas(nlev_cas,nt_cas),q_cas(nlev_cas,nt_cas),qv_cas(nlev_cas,nt_cas),ql_cas(nlev_cas,nt_cas), &
-             qi_cas(nlev_cas,nt_cas),rh_cas(nlev_cas,nt_cas))
-        allocate(th_cas(nlev_cas,nt_cas),thl_cas(nlev_cas,nt_cas),thv_cas(nlev_cas,nt_cas),rv_cas(nlev_cas,nt_cas))
-        allocate(u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas),vitw_cas(nlev_cas,nt_cas),omega_cas(nlev_cas,nt_cas))
-
-!forcing
-        allocate(ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas),dt_cas(nlev_cas,nt_cas),dtrad_cas(nlev_cas,nt_cas))
-        allocate(hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas),dq_cas(nlev_cas,nt_cas))
-        allocate(hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas),dth_cas(nlev_cas,nt_cas))
-        allocate(hr_cas(nlev_cas,nt_cas),vr_cas(nlev_cas,nt_cas),dr_cas(nlev_cas,nt_cas))
-        allocate(hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas),du_cas(nlev_cas,nt_cas))
-        allocate(hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas),dv_cas(nlev_cas,nt_cas))
-        allocate(ug_cas(nlev_cas,nt_cas))
-        allocate(vg_cas(nlev_cas,nt_cas))
-        allocate(lat_cas(nt_cas),sens_cas(nt_cas),ts_cas(nt_cas),ps_cas(nt_cas),ustar_cas(nt_cas),tke_cas(nt_cas))
-        allocate(uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas),q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas))
-
-
-
-!champs interpoles
-        allocate(plev_prof_cas(nlev_cas))
-        allocate(t_prof_cas(nlev_cas))
-        allocate(theta_prof_cas(nlev_cas))
-        allocate(thl_prof_cas(nlev_cas))
-        allocate(thv_prof_cas(nlev_cas))
-        allocate(q_prof_cas(nlev_cas))
-        allocate(qv_prof_cas(nlev_cas))
-        allocate(ql_prof_cas(nlev_cas))
-        allocate(qi_prof_cas(nlev_cas))
-        allocate(rh_prof_cas(nlev_cas))
-        allocate(rv_prof_cas(nlev_cas))
-        allocate(u_prof_cas(nlev_cas))
-        allocate(v_prof_cas(nlev_cas))
-        allocate(vitw_prof_cas(nlev_cas))
-        allocate(omega_prof_cas(nlev_cas))
-        allocate(ug_prof_cas(nlev_cas))
-        allocate(vg_prof_cas(nlev_cas))
-        allocate(ht_prof_cas(nlev_cas))
-        allocate(hth_prof_cas(nlev_cas))
-        allocate(hq_prof_cas(nlev_cas))
-        allocate(hu_prof_cas(nlev_cas))
-        allocate(hv_prof_cas(nlev_cas))
-        allocate(vt_prof_cas(nlev_cas))
-        allocate(vth_prof_cas(nlev_cas))
-        allocate(vq_prof_cas(nlev_cas))
-        allocate(vu_prof_cas(nlev_cas))
-        allocate(vv_prof_cas(nlev_cas))
-        allocate(dt_prof_cas(nlev_cas))
-        allocate(dth_prof_cas(nlev_cas))
-        allocate(dtrad_prof_cas(nlev_cas))
-        allocate(dq_prof_cas(nlev_cas))
-        allocate(du_prof_cas(nlev_cas))
-        allocate(dv_prof_cas(nlev_cas))
-        allocate(uw_prof_cas(nlev_cas))
-        allocate(vw_prof_cas(nlev_cas))
-        allocate(q1_prof_cas(nlev_cas))
-        allocate(q2_prof_cas(nlev_cas))
-
-        print*,'Allocations OK'
-        call read2_cas (nid,nlev_cas,nt_cas,                                                                     &
-     &     ap_cas,bp_cas,z_cas,plev_cas,zh_cas,plevh_cas,t_cas,th_cas,thv_cas,thl_cas,qv_cas,                    &
-     &     ql_cas,qi_cas,rh_cas,rv_cas,u_cas,v_cas,vitw_cas,omega_cas,ug_cas,vg_cas,du_cas,hu_cas,vu_cas,        &
-     &     dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dq_cas,hq_cas,vq_cas,dth_cas,hth_cas,vth_cas,               &
-     &     dr_cas,hr_cas,vr_cas,dtrad_cas,sens_cas,lat_cas,ts_cas,ps_cas,ustar_cas,tke_cas,                      &
-     &     uw_cas,vw_cas,q1_cas,q2_cas,orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough, &
-     &     o3_cas,rugos_cas,clay_cas,sand_cas)
-        print*,'Read2 cas OK'
-        do ii=1,nlev_cas
-        print*,'apres read2_cas, plev_cas=',ii,plev_cas(ii,1)
-        enddo
-
-
-END SUBROUTINE read2_1D_cas
-
-!**********************************************************************************************
-SUBROUTINE old_read_SCM_cas
-      implicit none
+    !profils moyens:
+    allocate(plev_cas(nlev_cas,nt_cas),plevh_cas(nlev_cas+1))        
+    allocate(z_cas(nlev_cas,nt_cas),zh_cas(nlev_cas+1))
+    allocate(ap_cas(nlev_cas+1),bp_cas(nt_cas+1))
+    allocate(t_cas(nlev_cas,nt_cas),q_cas(nlev_cas,nt_cas),qv_cas(nlev_cas,nt_cas),ql_cas(nlev_cas,nt_cas), &
+         qi_cas(nlev_cas,nt_cas),rh_cas(nlev_cas,nt_cas))
+    allocate(th_cas(nlev_cas,nt_cas),thl_cas(nlev_cas,nt_cas),thv_cas(nlev_cas,nt_cas),rv_cas(nlev_cas,nt_cas))
+    allocate(u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas),vitw_cas(nlev_cas,nt_cas),omega_cas(nlev_cas,nt_cas))
+
+    !forcing
+    allocate(ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas),dt_cas(nlev_cas,nt_cas),dtrad_cas(nlev_cas,nt_cas))
+    allocate(hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas),dq_cas(nlev_cas,nt_cas))
+    allocate(hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas),dth_cas(nlev_cas,nt_cas))
+    allocate(hr_cas(nlev_cas,nt_cas),vr_cas(nlev_cas,nt_cas),dr_cas(nlev_cas,nt_cas))
+    allocate(hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas),du_cas(nlev_cas,nt_cas))
+    allocate(hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas),dv_cas(nlev_cas,nt_cas))
+    allocate(ug_cas(nlev_cas,nt_cas))
+    allocate(vg_cas(nlev_cas,nt_cas))
+    allocate(lat_cas(nt_cas),sens_cas(nt_cas),ts_cas(nt_cas),ps_cas(nt_cas),ustar_cas(nt_cas),tke_cas(nt_cas))
+    allocate(uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas),q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas))
+
+
+
+    !champs interpoles
+    allocate(plev_prof_cas(nlev_cas))
+    allocate(t_prof_cas(nlev_cas))
+    allocate(theta_prof_cas(nlev_cas))
+    allocate(thl_prof_cas(nlev_cas))
+    allocate(thv_prof_cas(nlev_cas))
+    allocate(q_prof_cas(nlev_cas))
+    allocate(qv_prof_cas(nlev_cas))
+    allocate(ql_prof_cas(nlev_cas))
+    allocate(qi_prof_cas(nlev_cas))
+    allocate(rh_prof_cas(nlev_cas))
+    allocate(rv_prof_cas(nlev_cas))
+    allocate(u_prof_cas(nlev_cas))
+    allocate(v_prof_cas(nlev_cas))
+    allocate(vitw_prof_cas(nlev_cas))
+    allocate(omega_prof_cas(nlev_cas))
+    allocate(ug_prof_cas(nlev_cas))
+    allocate(vg_prof_cas(nlev_cas))
+    allocate(ht_prof_cas(nlev_cas))
+    allocate(hth_prof_cas(nlev_cas))
+    allocate(hq_prof_cas(nlev_cas))
+    allocate(hu_prof_cas(nlev_cas))
+    allocate(hv_prof_cas(nlev_cas))
+    allocate(vt_prof_cas(nlev_cas))
+    allocate(vth_prof_cas(nlev_cas))
+    allocate(vq_prof_cas(nlev_cas))
+    allocate(vu_prof_cas(nlev_cas))
+    allocate(vv_prof_cas(nlev_cas))
+    allocate(dt_prof_cas(nlev_cas))
+    allocate(dth_prof_cas(nlev_cas))
+    allocate(dtrad_prof_cas(nlev_cas))
+    allocate(dq_prof_cas(nlev_cas))
+    allocate(du_prof_cas(nlev_cas))
+    allocate(dv_prof_cas(nlev_cas))
+    allocate(uw_prof_cas(nlev_cas))
+    allocate(vw_prof_cas(nlev_cas))
+    allocate(q1_prof_cas(nlev_cas))
+    allocate(q2_prof_cas(nlev_cas))
+
+    print*,'Allocations OK'
+    call read2_cas (nid,nlev_cas,nt_cas,                                                                     &
+         ap_cas,bp_cas,z_cas,plev_cas,zh_cas,plevh_cas,t_cas,th_cas,thv_cas,thl_cas,qv_cas,                    &
+         ql_cas,qi_cas,rh_cas,rv_cas,u_cas,v_cas,vitw_cas,omega_cas,ug_cas,vg_cas,du_cas,hu_cas,vu_cas,        &
+         dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dq_cas,hq_cas,vq_cas,dth_cas,hth_cas,vth_cas,               &
+         dr_cas,hr_cas,vr_cas,dtrad_cas,sens_cas,lat_cas,ts_cas,ps_cas,ustar_cas,tke_cas,                      &
+         uw_cas,vw_cas,q1_cas,q2_cas,orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough, &
+         o3_cas,rugos_cas,clay_cas,sand_cas)
+    print*,'Read2 cas OK'
+    do ii=1,nlev_cas
+       print*,'apres read2_cas, plev_cas=',ii,plev_cas(ii,1)
+    enddo
+
+
+  END SUBROUTINE read2_1D_cas
+
+  !**********************************************************************************************
+  SUBROUTINE old_read_SCM_cas
+    use netcdf, only: nf90_get_var
+    implicit none
 
 #include "netcdf.inc"
 #include "date_cas.h"
 
-      INTEGER nid,rid,ierr
-      INTEGER ii,jj,timeid
-      REAL, ALLOCATABLE :: time_val(:)
-
-      fich_cas='cas.nc'
-      print*,'fich_cas ',fich_cas
-      ierr = NF_OPEN(fich_cas,NF_NOWRITE,nid)
-      print*,'fich_cas,NF_NOWRITE,nid ',fich_cas,NF_NOWRITE,nid
-      if (ierr.NE.NF_NOERR) then
-         write(*,*) 'ERROR: GROS Pb opening forcings nc file '
-         write(*,*) NF_STRERROR(ierr)
-         stop ""
-      endif
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'lat',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension lat'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,ii)
-      print*,'OK1 read2: nid,rid,lat',nid,rid,ii
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'lon',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension lon'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,jj)
-      print*,'OK2 read2: nid,rid,lat',nid,rid,jj
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'lev',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension nlev'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,nlev_cas)
-      print*,'OK3 read2: nid,rid,nlev_cas',nid,rid,nlev_cas
-      IF ( .NOT. ( nlev_cas > 10 .AND. nlev_cas < 1000 )) THEN
-              print*,'Valeur de nlev_cas peu probable'
-              STOP
-      ENDIF
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'time',rid)
-      nt_cas=0
-      IF (ierr.NE.NF_NOERR) THEN
-        stop 'Oh probleme lecture dimension time'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,nt_cas)
-      print*,'OK4 read2: nid,rid,nt_cas',nid,rid,nt_cas
-! Lecture de l'axe des temps
-      print*,'LECTURE DU TEMPS'
-      ierr=NF_INQ_VARID(nid,'time',timeid)
-         if(ierr/=NF_NOERR) then
-           print *,'Variable time manquante dans cas.nc:'
-           ierr=NF_NOERR
-         else
-                 allocate(time_val(nt_cas))
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,timeid,time_val)
-#else
-           ierr = NF_GET_VAR_REAL(nid,timeid,time_val)
-#endif
-           if(ierr/=NF_NOERR) then
-              print *,'Pb a la lecture de time cas.nc: '
-           endif
-   endif
-   IF (nt_cas>1) THEN
-           pdt_cas=time_val(2)-time_val(1)
-   ELSE
-           pdt_cas=0.
-   ENDIF
+    INTEGER nid,rid,ierr
+    INTEGER ii,jj,timeid
+    REAL, ALLOCATABLE :: time_val(:)
+
+    fich_cas='cas.nc'
+    print*,'fich_cas ',fich_cas
+    ierr = NF_OPEN(fich_cas,NF_NOWRITE,nid)
+    print*,'fich_cas,NF_NOWRITE,nid ',fich_cas,NF_NOWRITE,nid
+    if (ierr.NE.NF_NOERR) then
+       write(*,*) 'ERROR: GROS Pb opening forcings nc file '
+       write(*,*) NF_STRERROR(ierr)
+       stop ""
+    endif
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'lat',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension lat'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,ii)
+    print*,'OK1 read2: nid,rid,lat',nid,rid,ii
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'lon',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension lon'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,jj)
+    print*,'OK2 read2: nid,rid,lat',nid,rid,jj
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'lev',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension nlev'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,nlev_cas)
+    print*,'OK3 read2: nid,rid,nlev_cas',nid,rid,nlev_cas
+    IF ( .NOT. ( nlev_cas > 10 .AND. nlev_cas < 1000 )) THEN
+       print*,'Valeur de nlev_cas peu probable'
+       STOP
+    ENDIF
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'time',rid)
+    nt_cas=0
+    IF (ierr.NE.NF_NOERR) THEN
+       stop 'Oh probleme lecture dimension time'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,nt_cas)
+    print*,'OK4 read2: nid,rid,nt_cas',nid,rid,nt_cas
+    ! Lecture de l'axe des temps
+    print*,'LECTURE DU TEMPS'
+    ierr=NF_INQ_VARID(nid,'time',timeid)
+    if(ierr/=NF_NOERR) then
+       print *,'Variable time manquante dans cas.nc:'
+       ierr=NF_NOERR
+    else
+       allocate(time_val(nt_cas))
+       ierr = NF90_GET_VAR(nid,timeid,time_val)
+       if(ierr/=NF_NOERR) then
+          print *,'Pb a la lecture de time cas.nc: '
+       endif
+    endif
+    IF (nt_cas>1) THEN
+       pdt_cas=time_val(2)-time_val(1)
+    ELSE
+       pdt_cas=0.
+    ENDIF
 
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!profils moyens:
-        allocate(plev_cas(nlev_cas,nt_cas),plevh_cas(nlev_cas+1))        
-        allocate(z_cas(nlev_cas,nt_cas),zh_cas(nlev_cas+1))
-        allocate(ap_cas(nlev_cas+1),bp_cas(nt_cas+1))
-        allocate(t_cas(nlev_cas,nt_cas),q_cas(nlev_cas,nt_cas),qv_cas(nlev_cas,nt_cas),ql_cas(nlev_cas,nt_cas), &
-             qi_cas(nlev_cas,nt_cas),rh_cas(nlev_cas,nt_cas))
-        allocate(th_cas(nlev_cas,nt_cas),thl_cas(nlev_cas,nt_cas),thv_cas(nlev_cas,nt_cas),rv_cas(nlev_cas,nt_cas))
-        allocate(u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas),vitw_cas(nlev_cas,nt_cas),omega_cas(nlev_cas,nt_cas))
-
-!forcing
-        allocate(ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas),dt_cas(nlev_cas,nt_cas),dtrad_cas(nlev_cas,nt_cas))
-        allocate(hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas),dq_cas(nlev_cas,nt_cas))
-        allocate(hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas),dth_cas(nlev_cas,nt_cas))
-        allocate(hr_cas(nlev_cas,nt_cas),vr_cas(nlev_cas,nt_cas),dr_cas(nlev_cas,nt_cas))
-        allocate(hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas),du_cas(nlev_cas,nt_cas))
-        allocate(hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas),dv_cas(nlev_cas,nt_cas))
-        allocate(ug_cas(nlev_cas,nt_cas))
-        allocate(vg_cas(nlev_cas,nt_cas))
-        allocate(lat_cas(nt_cas),sens_cas(nt_cas),ts_cas(nt_cas),ps_cas(nt_cas),ustar_cas(nt_cas),tke_cas(nt_cas))
-        allocate(uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas),q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas))
-
-
-
-!champs interpoles
-        allocate(plev_prof_cas(nlev_cas))
-        allocate(t_prof_cas(nlev_cas))
-        allocate(theta_prof_cas(nlev_cas))
-        allocate(thl_prof_cas(nlev_cas))
-        allocate(thv_prof_cas(nlev_cas))
-        allocate(q_prof_cas(nlev_cas))
-        allocate(qv_prof_cas(nlev_cas))
-        allocate(ql_prof_cas(nlev_cas))
-        allocate(qi_prof_cas(nlev_cas))
-        allocate(rh_prof_cas(nlev_cas))
-        allocate(rv_prof_cas(nlev_cas))
-        allocate(u_prof_cas(nlev_cas))
-        allocate(v_prof_cas(nlev_cas))
-        allocate(vitw_prof_cas(nlev_cas))
-        allocate(omega_prof_cas(nlev_cas))
-        allocate(ug_prof_cas(nlev_cas))
-        allocate(vg_prof_cas(nlev_cas))
-        allocate(ht_prof_cas(nlev_cas))
-        allocate(hth_prof_cas(nlev_cas))
-        allocate(hq_prof_cas(nlev_cas))
-        allocate(hu_prof_cas(nlev_cas))
-        allocate(hv_prof_cas(nlev_cas))
-        allocate(vt_prof_cas(nlev_cas))
-        allocate(vth_prof_cas(nlev_cas))
-        allocate(vq_prof_cas(nlev_cas))
-        allocate(vu_prof_cas(nlev_cas))
-        allocate(vv_prof_cas(nlev_cas))
-        allocate(dt_prof_cas(nlev_cas))
-        allocate(dth_prof_cas(nlev_cas))
-        allocate(dtrad_prof_cas(nlev_cas))
-        allocate(dq_prof_cas(nlev_cas))
-        allocate(du_prof_cas(nlev_cas))
-        allocate(dv_prof_cas(nlev_cas))
-        allocate(uw_prof_cas(nlev_cas))
-        allocate(vw_prof_cas(nlev_cas))
-        allocate(q1_prof_cas(nlev_cas))
-        allocate(q2_prof_cas(nlev_cas))
-
-        print*,'Allocations OK'
-        call old_read_SCM (nid,nlev_cas,nt_cas,                                                                     &
-     &     ap_cas,bp_cas,z_cas,plev_cas,zh_cas,plevh_cas,t_cas,th_cas,thv_cas,thl_cas,qv_cas,                    &
-     &     ql_cas,qi_cas,rh_cas,rv_cas,u_cas,v_cas,vitw_cas,omega_cas,ug_cas,vg_cas,du_cas,hu_cas,vu_cas,        &
-     &     dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dq_cas,hq_cas,vq_cas,dth_cas,hth_cas,vth_cas,               &
-     &     dr_cas,hr_cas,vr_cas,dtrad_cas,sens_cas,lat_cas,ts_cas,ps_cas,ustar_cas,tke_cas,                      &
-     &     uw_cas,vw_cas,q1_cas,q2_cas,orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough, &
-     &     o3_cas,rugos_cas,clay_cas,sand_cas)
-        print*,'Read2 cas OK'
-        do ii=1,nlev_cas
-        print*,'apres read2_cas, plev_cas=',ii,plev_cas(ii,1)
-        enddo
-
-
-END SUBROUTINE old_read_SCM_cas
+    !profils moyens:
+    allocate(plev_cas(nlev_cas,nt_cas),plevh_cas(nlev_cas+1))        
+    allocate(z_cas(nlev_cas,nt_cas),zh_cas(nlev_cas+1))
+    allocate(ap_cas(nlev_cas+1),bp_cas(nt_cas+1))
+    allocate(t_cas(nlev_cas,nt_cas),q_cas(nlev_cas,nt_cas),qv_cas(nlev_cas,nt_cas),ql_cas(nlev_cas,nt_cas), &
+         qi_cas(nlev_cas,nt_cas),rh_cas(nlev_cas,nt_cas))
+    allocate(th_cas(nlev_cas,nt_cas),thl_cas(nlev_cas,nt_cas),thv_cas(nlev_cas,nt_cas),rv_cas(nlev_cas,nt_cas))
+    allocate(u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas),vitw_cas(nlev_cas,nt_cas),omega_cas(nlev_cas,nt_cas))
+
+    !forcing
+    allocate(ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas),dt_cas(nlev_cas,nt_cas),dtrad_cas(nlev_cas,nt_cas))
+    allocate(hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas),dq_cas(nlev_cas,nt_cas))
+    allocate(hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas),dth_cas(nlev_cas,nt_cas))
+    allocate(hr_cas(nlev_cas,nt_cas),vr_cas(nlev_cas,nt_cas),dr_cas(nlev_cas,nt_cas))
+    allocate(hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas),du_cas(nlev_cas,nt_cas))
+    allocate(hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas),dv_cas(nlev_cas,nt_cas))
+    allocate(ug_cas(nlev_cas,nt_cas))
+    allocate(vg_cas(nlev_cas,nt_cas))
+    allocate(lat_cas(nt_cas),sens_cas(nt_cas),ts_cas(nt_cas),ps_cas(nt_cas),ustar_cas(nt_cas),tke_cas(nt_cas))
+    allocate(uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas),q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas))
+
+
+
+    !champs interpoles
+    allocate(plev_prof_cas(nlev_cas))
+    allocate(t_prof_cas(nlev_cas))
+    allocate(theta_prof_cas(nlev_cas))
+    allocate(thl_prof_cas(nlev_cas))
+    allocate(thv_prof_cas(nlev_cas))
+    allocate(q_prof_cas(nlev_cas))
+    allocate(qv_prof_cas(nlev_cas))
+    allocate(ql_prof_cas(nlev_cas))
+    allocate(qi_prof_cas(nlev_cas))
+    allocate(rh_prof_cas(nlev_cas))
+    allocate(rv_prof_cas(nlev_cas))
+    allocate(u_prof_cas(nlev_cas))
+    allocate(v_prof_cas(nlev_cas))
+    allocate(vitw_prof_cas(nlev_cas))
+    allocate(omega_prof_cas(nlev_cas))
+    allocate(ug_prof_cas(nlev_cas))
+    allocate(vg_prof_cas(nlev_cas))
+    allocate(ht_prof_cas(nlev_cas))
+    allocate(hth_prof_cas(nlev_cas))
+    allocate(hq_prof_cas(nlev_cas))
+    allocate(hu_prof_cas(nlev_cas))
+    allocate(hv_prof_cas(nlev_cas))
+    allocate(vt_prof_cas(nlev_cas))
+    allocate(vth_prof_cas(nlev_cas))
+    allocate(vq_prof_cas(nlev_cas))
+    allocate(vu_prof_cas(nlev_cas))
+    allocate(vv_prof_cas(nlev_cas))
+    allocate(dt_prof_cas(nlev_cas))
+    allocate(dth_prof_cas(nlev_cas))
+    allocate(dtrad_prof_cas(nlev_cas))
+    allocate(dq_prof_cas(nlev_cas))
+    allocate(du_prof_cas(nlev_cas))
+    allocate(dv_prof_cas(nlev_cas))
+    allocate(uw_prof_cas(nlev_cas))
+    allocate(vw_prof_cas(nlev_cas))
+    allocate(q1_prof_cas(nlev_cas))
+    allocate(q2_prof_cas(nlev_cas))
+
+    print*,'Allocations OK'
+    call old_read_SCM (nid,nlev_cas,nt_cas,                                                                     &
+         ap_cas,bp_cas,z_cas,plev_cas,zh_cas,plevh_cas,t_cas,th_cas,thv_cas,thl_cas,qv_cas,                    &
+         ql_cas,qi_cas,rh_cas,rv_cas,u_cas,v_cas,vitw_cas,omega_cas,ug_cas,vg_cas,du_cas,hu_cas,vu_cas,        &
+         dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dq_cas,hq_cas,vq_cas,dth_cas,hth_cas,vth_cas,               &
+         dr_cas,hr_cas,vr_cas,dtrad_cas,sens_cas,lat_cas,ts_cas,ps_cas,ustar_cas,tke_cas,                      &
+         uw_cas,vw_cas,q1_cas,q2_cas,orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough, &
+         o3_cas,rugos_cas,clay_cas,sand_cas)
+    print*,'Read2 cas OK'
+    do ii=1,nlev_cas
+       print*,'apres read2_cas, plev_cas=',ii,plev_cas(ii,1)
+    enddo
+
+
+  END SUBROUTINE old_read_SCM_cas
 
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-SUBROUTINE deallocate2_1D_cases
-!profils environnementaux:
-        deallocate(plev_cas,plevh_cas)
-        
-        deallocate(z_cas,zh_cas)
-        deallocate(ap_cas,bp_cas)
-        deallocate(t_cas,q_cas,qv_cas,ql_cas,qi_cas,rh_cas)
-        deallocate(th_cas,thl_cas,thv_cas,rv_cas)
-        deallocate(u_cas,v_cas,vitw_cas,omega_cas)
-        
-!forcing
-        deallocate(ht_cas,vt_cas,dt_cas,dtrad_cas)
-        deallocate(hq_cas,vq_cas,dq_cas)
-        deallocate(hth_cas,vth_cas,dth_cas)
-        deallocate(hr_cas,vr_cas,dr_cas)
-        deallocate(hu_cas,vu_cas,du_cas)
-        deallocate(hv_cas,vv_cas,dv_cas)
-        deallocate(ug_cas)
-        deallocate(vg_cas)
-        deallocate(lat_cas,sens_cas,ts_cas,ps_cas,ustar_cas,tke_cas,uw_cas,vw_cas,q1_cas,q2_cas)
-
-!champs interpoles
-        deallocate(plev_prof_cas)
-        deallocate(t_prof_cas)
-        deallocate(theta_prof_cas)
-        deallocate(thl_prof_cas)
-        deallocate(thv_prof_cas)
-        deallocate(q_prof_cas)
-        deallocate(qv_prof_cas)
-        deallocate(ql_prof_cas)
-        deallocate(qi_prof_cas)
-        deallocate(rh_prof_cas)
-        deallocate(rv_prof_cas)
-        deallocate(u_prof_cas)
-        deallocate(v_prof_cas)
-        deallocate(vitw_prof_cas)
-        deallocate(omega_prof_cas)
-        deallocate(ug_prof_cas)
-        deallocate(vg_prof_cas)
-        deallocate(ht_prof_cas)
-        deallocate(hq_prof_cas)
-        deallocate(hu_prof_cas)
-        deallocate(hv_prof_cas)
-        deallocate(vt_prof_cas)
-        deallocate(vq_prof_cas)
-        deallocate(vu_prof_cas)
-        deallocate(vv_prof_cas)
-        deallocate(dt_prof_cas)
-        deallocate(dtrad_prof_cas)
-        deallocate(dq_prof_cas)
-        deallocate(du_prof_cas)
-        deallocate(dv_prof_cas)
-        deallocate(t_prof_cas)
-        deallocate(u_prof_cas)
-        deallocate(v_prof_cas)
-        deallocate(uw_prof_cas)
-        deallocate(vw_prof_cas)
-        deallocate(q1_prof_cas)
-        deallocate(q2_prof_cas)
-
-END SUBROUTINE deallocate2_1D_cases
+  SUBROUTINE deallocate2_1D_cases
+    !profils environnementaux:
+    deallocate(plev_cas,plevh_cas)
+
+    deallocate(z_cas,zh_cas)
+    deallocate(ap_cas,bp_cas)
+    deallocate(t_cas,q_cas,qv_cas,ql_cas,qi_cas,rh_cas)
+    deallocate(th_cas,thl_cas,thv_cas,rv_cas)
+    deallocate(u_cas,v_cas,vitw_cas,omega_cas)
+
+    !forcing
+    deallocate(ht_cas,vt_cas,dt_cas,dtrad_cas)
+    deallocate(hq_cas,vq_cas,dq_cas)
+    deallocate(hth_cas,vth_cas,dth_cas)
+    deallocate(hr_cas,vr_cas,dr_cas)
+    deallocate(hu_cas,vu_cas,du_cas)
+    deallocate(hv_cas,vv_cas,dv_cas)
+    deallocate(ug_cas)
+    deallocate(vg_cas)
+    deallocate(lat_cas,sens_cas,ts_cas,ps_cas,ustar_cas,tke_cas,uw_cas,vw_cas,q1_cas,q2_cas)
+
+    !champs interpoles
+    deallocate(plev_prof_cas)
+    deallocate(t_prof_cas)
+    deallocate(theta_prof_cas)
+    deallocate(thl_prof_cas)
+    deallocate(thv_prof_cas)
+    deallocate(q_prof_cas)
+    deallocate(qv_prof_cas)
+    deallocate(ql_prof_cas)
+    deallocate(qi_prof_cas)
+    deallocate(rh_prof_cas)
+    deallocate(rv_prof_cas)
+    deallocate(u_prof_cas)
+    deallocate(v_prof_cas)
+    deallocate(vitw_prof_cas)
+    deallocate(omega_prof_cas)
+    deallocate(ug_prof_cas)
+    deallocate(vg_prof_cas)
+    deallocate(ht_prof_cas)
+    deallocate(hq_prof_cas)
+    deallocate(hu_prof_cas)
+    deallocate(hv_prof_cas)
+    deallocate(vt_prof_cas)
+    deallocate(vq_prof_cas)
+    deallocate(vu_prof_cas)
+    deallocate(vv_prof_cas)
+    deallocate(dt_prof_cas)
+    deallocate(dtrad_prof_cas)
+    deallocate(dq_prof_cas)
+    deallocate(du_prof_cas)
+    deallocate(dv_prof_cas)
+    deallocate(t_prof_cas)
+    deallocate(u_prof_cas)
+    deallocate(v_prof_cas)
+    deallocate(uw_prof_cas)
+    deallocate(vw_prof_cas)
+    deallocate(q1_prof_cas)
+    deallocate(q2_prof_cas)
+
+  END SUBROUTINE deallocate2_1D_cases
 
 
 END MODULE mod_1D_cases_read2
 !=====================================================================
-      subroutine read_cas2(nid,nlevel,ntime                          &
-     &     ,zz,pp,temp,qv,rh,theta,rv,u,v,ug,vg,w,                   &
-     &     du,hu,vu,dv,hv,vv,dt,dtrad,ht,vt,dq,hq,vq,                     &
-     &     dth,hth,vth,dr,hr,vr,sens,flat,ts,ustar,uw,vw,q1,q2)
-
-!program reading forcing of the case study
-      implicit none
+subroutine read_cas2(nid,nlevel,ntime                          &
+     ,zz,pp,temp,qv,rh,theta,rv,u,v,ug,vg,w,                   &
+     du,hu,vu,dv,hv,vv,dt,dtrad,ht,vt,dq,hq,vq,                     &
+     dth,hth,vth,dr,hr,vr,sens,flat,ts,ustar,uw,vw,q1,q2)
+
+  !program reading forcing of the case study
+  use netcdf, only: nf90_get_var
+  implicit none
 #include "netcdf.inc"
 
-      integer ntime,nlevel
-
-      real zz(nlevel,ntime)
-      real pp(nlevel,ntime)
-      real temp(nlevel,ntime),qv(nlevel,ntime),rh(nlevel,ntime)
-      real theta(nlevel,ntime),rv(nlevel,ntime)
-      real u(nlevel,ntime)
-      real v(nlevel,ntime)
-      real ug(nlevel,ntime)
-      real vg(nlevel,ntime)
-      real w(nlevel,ntime)
-      real du(nlevel,ntime),hu(nlevel,ntime),vu(nlevel,ntime)
-      real dv(nlevel,ntime),hv(nlevel,ntime),vv(nlevel,ntime)
-      real dt(nlevel,ntime),ht(nlevel,ntime),vt(nlevel,ntime)
-      real dtrad(nlevel,ntime)
-      real dq(nlevel,ntime),hq(nlevel,ntime),vq(nlevel,ntime)
-      real dth(nlevel,ntime),hth(nlevel,ntime),vth(nlevel,ntime)
-      real dr(nlevel,ntime),hr(nlevel,ntime),vr(nlevel,ntime)
-      real flat(ntime),sens(ntime),ts(ntime),ustar(ntime)
-      real uw(nlevel,ntime),vw(nlevel,ntime),q1(nlevel,ntime),q2(nlevel,ntime),resul(nlevel,ntime),resul1(ntime)
-
-
-      integer nid, ierr, ierr1,ierr2,rid,i
-      integer nbvar3d
-      parameter(nbvar3d=39)
-      integer var3didin(nbvar3d)
-      character*5 name_var(1:nbvar3d)
-      data name_var/'zz','pp','temp','qv','rh','theta','rv','u','v','ug','vg','w','advu','hu','vu',&
-     &'advv','hv','vv','advT','hT','vT','advq','hq','vq','advth','hth','vth','advr','hr','vr',&
-     &'radT','uw','vw','q1','q2','sens','flat','ts','ustar'/
-
-       do i=1,nbvar3d
-         print *,'Dans read_cas2, on va lire ',nid,i,name_var(i)
-       enddo
-       do i=1,nbvar3d
-         ierr=NF_INQ_VARID(nid,name_var(i),var3didin(i)) 
-         print *,'ierr=',i,ierr,name_var(i),var3didin(i)
-         if(ierr/=NF_NOERR) then
-           print *,'Variable manquante dans cas.nc:',name_var(i)
-         endif
-       enddo
-       do i=1,nbvar3d
-         print *,'Dans read_cas2, on va lire ',var3didin(i),name_var(i)
-         if(i.LE.35) then
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul)
-#endif
-         print *,'Dans read_cas2, on a lu ',ierr,var3didin(i),name_var(i)
-         if(ierr/=NF_NOERR) then
-            print *,'Pb a la lecture de cas.nc: ',name_var(i)
-            stop "getvarup"
-         endif
-         else
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul1)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul1)
-#endif
-         print *,'Dans read_cas2, on a lu ',ierr,var3didin(i),name_var(i)
-         if(ierr/=NF_NOERR) then
-            print *,'Pb a la lecture de cas.nc: ',name_var(i)
-            stop "getvarup"
-         endif
-         endif
-         select case(i)
-           case(1) ; zz=resul
-           case(2) ; pp=resul
-           case(3) ; temp=resul
-           case(4) ; qv=resul
-           case(5) ; rh=resul
-           case(6) ; theta=resul
-           case(7) ; rv=resul
-           case(8) ; u=resul
-           case(9) ; v=resul
-           case(10) ; ug=resul
-           case(11) ; vg=resul
-           case(12) ; w=resul
-           case(13) ; du=resul
-           case(14) ; hu=resul
-           case(15) ; vu=resul
-           case(16) ; dv=resul
-           case(17) ; hv=resul
-           case(18) ; vv=resul
-           case(19) ; dt=resul
-           case(20) ; ht=resul
-           case(21) ; vt=resul
-           case(22) ; dq=resul
-           case(23) ; hq=resul
-           case(24) ; vq=resul
-           case(25) ; dth=resul
-           case(26) ; hth=resul
-           case(27) ; vth=resul
-           case(28) ; dr=resul
-           case(29) ; hr=resul
-           case(30) ; vr=resul
-           case(31) ; dtrad=resul
-           case(32) ; uw=resul
-           case(33) ; vw=resul
-           case(34) ; q1=resul
-           case(35) ; q2=resul
-           case(36) ; sens=resul1
-           case(37) ; flat=resul1
-           case(38) ; ts=resul1
-           case(39) ; ustar=resul1
-         end select
-       enddo
-
-         return 
-         end subroutine read_cas2
+  integer ntime,nlevel
+
+  real zz(nlevel,ntime)
+  real pp(nlevel,ntime)
+  real temp(nlevel,ntime),qv(nlevel,ntime),rh(nlevel,ntime)
+  real theta(nlevel,ntime),rv(nlevel,ntime)
+  real u(nlevel,ntime)
+  real v(nlevel,ntime)
+  real ug(nlevel,ntime)
+  real vg(nlevel,ntime)
+  real w(nlevel,ntime)
+  real du(nlevel,ntime),hu(nlevel,ntime),vu(nlevel,ntime)
+  real dv(nlevel,ntime),hv(nlevel,ntime),vv(nlevel,ntime)
+  real dt(nlevel,ntime),ht(nlevel,ntime),vt(nlevel,ntime)
+  real dtrad(nlevel,ntime)
+  real dq(nlevel,ntime),hq(nlevel,ntime),vq(nlevel,ntime)
+  real dth(nlevel,ntime),hth(nlevel,ntime),vth(nlevel,ntime)
+  real dr(nlevel,ntime),hr(nlevel,ntime),vr(nlevel,ntime)
+  real flat(ntime),sens(ntime),ts(ntime),ustar(ntime)
+  real uw(nlevel,ntime),vw(nlevel,ntime),q1(nlevel,ntime),q2(nlevel,ntime),resul(nlevel,ntime),resul1(ntime)
+
+
+  integer nid, ierr, ierr1,ierr2,rid,i
+  integer nbvar3d
+  parameter(nbvar3d=39)
+  integer var3didin(nbvar3d)
+  character*5 name_var(1:nbvar3d)
+  data name_var/'zz','pp','temp','qv','rh','theta','rv','u','v','ug','vg','w','advu','hu','vu',&
+       'advv','hv','vv','advT','hT','vT','advq','hq','vq','advth','hth','vth','advr','hr','vr',&
+       'radT','uw','vw','q1','q2','sens','flat','ts','ustar'/
+
+
+  do i=1,nbvar3d
+     print *,'Dans read_cas2, on va lire ',nid,i,name_var(i)
+  enddo
+  do i=1,nbvar3d
+     ierr=NF_INQ_VARID(nid,name_var(i),var3didin(i)) 
+     print *,'ierr=',i,ierr,name_var(i),var3didin(i)
+     if(ierr/=NF_NOERR) then
+        print *,'Variable manquante dans cas.nc:',name_var(i)
+     endif
+  enddo
+  do i=1,nbvar3d
+     print *,'Dans read_cas2, on va lire ',var3didin(i),name_var(i)
+     if(i.LE.35) then
+        ierr = NF90_GET_VAR(nid,var3didin(i),resul, count = [1, 1, nlevel, ntime])
+        print *,'Dans read_cas2, on a lu ',ierr,var3didin(i),name_var(i)
+        if(ierr/=NF_NOERR) then
+           print *,'Pb a la lecture de cas.nc: ',name_var(i)
+           stop "getvarup"
+        endif
+     else
+        print *,'Dans read_cas2, on a lu ',ierr,var3didin(i),name_var(i)
+        ierr = NF90_GET_VAR(nid,var3didin(i),resul1, count = [1, 1, ntime])
+        if(ierr/=NF_NOERR) then
+           print *,'Pb a la lecture de cas.nc: ',name_var(i)
+           stop "getvarup"
+        endif
+     endif
+     select case(i)
+     case(1) ; zz=resul
+     case(2) ; pp=resul
+     case(3) ; temp=resul
+     case(4) ; qv=resul
+     case(5) ; rh=resul
+     case(6) ; theta=resul
+     case(7) ; rv=resul
+     case(8) ; u=resul
+     case(9) ; v=resul
+     case(10) ; ug=resul
+     case(11) ; vg=resul
+     case(12) ; w=resul
+     case(13) ; du=resul
+     case(14) ; hu=resul
+     case(15) ; vu=resul
+     case(16) ; dv=resul
+     case(17) ; hv=resul
+     case(18) ; vv=resul
+     case(19) ; dt=resul
+     case(20) ; ht=resul
+     case(21) ; vt=resul
+     case(22) ; dq=resul
+     case(23) ; hq=resul
+     case(24) ; vq=resul
+     case(25) ; dth=resul
+     case(26) ; hth=resul
+     case(27) ; vth=resul
+     case(28) ; dr=resul
+     case(29) ; hr=resul
+     case(30) ; vr=resul
+     case(31) ; dtrad=resul
+     case(32) ; uw=resul
+     case(33) ; vw=resul
+     case(34) ; q1=resul
+     case(35) ; q2=resul
+     case(36) ; sens=resul1
+     case(37) ; flat=resul1
+     case(38) ; ts=resul1
+     case(39) ; ustar=resul1
+     end select
+  enddo
+
+  return 
+end subroutine read_cas2
 !======================================================================
-      subroutine read2_cas(nid,nlevel,ntime,                                       &
-     &     ap,bp,zz,pp,zzh,pph,temp,theta,thv,thl,qv,ql,qi,rh,rv,u,v,vitw,omega,ug,vg,&
-     &     du,hu,vu,dv,hv,vv,dt,ht,vt,dq,hq,vq,                                    &
-     &     dth,hth,vth,dr,hr,vr,dtrad,sens,flat,ts,ps,ustar,tke,uw,vw,q1,q2,       &
-     &     orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,          &
-     &     heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas)
-
-!program reading forcing of the case study
-      implicit none
+subroutine read2_cas(nid,nlevel,ntime,                                       &
+     ap,bp,zz,pp,zzh,pph,temp,theta,thv,thl,qv,ql,qi,rh,rv,u,v,vitw,omega,ug,vg,&
+     du,hu,vu,dv,hv,vv,dt,ht,vt,dq,hq,vq,                                    &
+     dth,hth,vth,dr,hr,vr,dtrad,sens,flat,ts,ps,ustar,tke,uw,vw,q1,q2,       &
+     orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,          &
+     heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas)
+
+  !program reading forcing of the case study
+  use netcdf, only: nf90_get_var
+  implicit none
 #include "netcdf.inc"
 
-      integer ntime,nlevel
-
-      real ap(nlevel+1),bp(nlevel+1)
-      real zz(nlevel,ntime),zzh(nlevel+1)
-      real pp(nlevel,ntime),pph(nlevel+1)
-      real temp(nlevel,ntime),qv(nlevel,ntime),ql(nlevel,ntime),qi(nlevel,ntime),rh(nlevel,ntime)
-      real theta(nlevel,ntime),thv(nlevel,ntime),thl(nlevel,ntime),rv(nlevel,ntime)
-      real u(nlevel,ntime),v(nlevel,ntime)
-      real ug(nlevel,ntime),vg(nlevel,ntime)
-      real vitw(nlevel,ntime),omega(nlevel,ntime)
-      real du(nlevel,ntime),hu(nlevel,ntime),vu(nlevel,ntime)
-      real dv(nlevel,ntime),hv(nlevel,ntime),vv(nlevel,ntime)
-      real dt(nlevel,ntime),ht(nlevel,ntime),vt(nlevel,ntime)
-      real dtrad(nlevel,ntime)
-      real dq(nlevel,ntime),hq(nlevel,ntime),vq(nlevel,ntime)
-      real dth(nlevel,ntime),hth(nlevel,ntime),vth(nlevel,ntime),hthl(nlevel,ntime)
-      real dr(nlevel,ntime),hr(nlevel,ntime),vr(nlevel,ntime)
-      real flat(ntime),sens(ntime),ustar(ntime)
-      real uw(nlevel,ntime),vw(nlevel,ntime),q1(nlevel,ntime),q2(nlevel,ntime)
-      real ts(ntime),ps(ntime),tke(ntime)
-      real orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas
-      real apbp(nlevel+1),resul(nlevel,ntime),resul1(nlevel),resul2(ntime),resul3
-
-
-      integer nid, ierr,ierr1,ierr2,rid,i
-      integer nbvar3d
-      parameter(nbvar3d=62)
-      integer var3didin(nbvar3d),missing_var(nbvar3d)
-      character*12 name_var(1:nbvar3d)
-      data name_var/'coor_par_a','coor_par_b','height_h','pressure_h',&
-     &'w','omega','ug','vg','uadv','uadvh','uadvv','vadv','vadvh','vadvv','tadv','tadvh','tadvv',&
-     &'qadv','qadvh','qadvv','thadv','thadvh','thadvv','thladvh','radv','radvh','radvv','radcool','q1','q2','ustress','vstress', &
-     'rh',&
-     &'height_f','pressure_f','temp','theta','thv','thl','qv','ql','qi','rv','u','v',&
-     &'sfc_sens_flx','sfc_lat_flx','ts','ps','ustar','tke',&
-     &'orog','albedo','emiss','t_skin','q_skin','mom_rough','heat_rough','o3','rugos','clay','sand'/
-      do i=1,nbvar3d
-        missing_var(i)=0.
-      enddo
-
-!-----------------------------------------------------------------------
-       do i=1,nbvar3d
-         ierr=NF_INQ_VARID(nid,name_var(i),var3didin(i)) 
-         if(ierr/=NF_NOERR) then
-           print *,'Variable manquante dans cas.nc:',i,name_var(i)
-           ierr=NF_NOERR
-           missing_var(i)=1
-         else
-!-----------------------------------------------------------------------
-           if(i.LE.4) then     ! Lecture des coord pression en (nlevelp1,lat,lon)
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),apbp)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),apbp)
-#endif
+  integer ntime,nlevel
+
+  real ap(nlevel+1),bp(nlevel+1)
+  real zz(nlevel,ntime),zzh(nlevel+1)
+  real pp(nlevel,ntime),pph(nlevel+1)
+  real temp(nlevel,ntime),qv(nlevel,ntime),ql(nlevel,ntime),qi(nlevel,ntime),rh(nlevel,ntime)
+  real theta(nlevel,ntime),thv(nlevel,ntime),thl(nlevel,ntime),rv(nlevel,ntime)
+  real u(nlevel,ntime),v(nlevel,ntime)
+  real ug(nlevel,ntime),vg(nlevel,ntime)
+  real vitw(nlevel,ntime),omega(nlevel,ntime)
+  real du(nlevel,ntime),hu(nlevel,ntime),vu(nlevel,ntime)
+  real dv(nlevel,ntime),hv(nlevel,ntime),vv(nlevel,ntime)
+  real dt(nlevel,ntime),ht(nlevel,ntime),vt(nlevel,ntime)
+  real dtrad(nlevel,ntime)
+  real dq(nlevel,ntime),hq(nlevel,ntime),vq(nlevel,ntime)
+  real dth(nlevel,ntime),hth(nlevel,ntime),vth(nlevel,ntime),hthl(nlevel,ntime)
+  real dr(nlevel,ntime),hr(nlevel,ntime),vr(nlevel,ntime)
+  real flat(ntime),sens(ntime),ustar(ntime)
+  real uw(nlevel,ntime),vw(nlevel,ntime),q1(nlevel,ntime),q2(nlevel,ntime)
+  real ts(ntime),ps(ntime),tke(ntime)
+  real orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas
+  real apbp(nlevel+1),resul(nlevel,ntime),resul1(nlevel),resul2(ntime),resul3
+
+
+  integer nid, ierr,ierr1,ierr2,rid,i
+  integer nbvar3d
+  parameter(nbvar3d=62)
+  integer var3didin(nbvar3d),missing_var(nbvar3d)
+  character*12 name_var(1:nbvar3d)
+  data name_var/'coor_par_a','coor_par_b','height_h','pressure_h',&
+       'w','omega','ug','vg','uadv','uadvh','uadvv','vadv','vadvh','vadvv','tadv','tadvh','tadvv',&
+       'qadv','qadvh','qadvv','thadv','thadvh','thadvv','thladvh','radv','radvh','radvv','radcool','q1','q2','ustress','vstress', &
+       'rh',&
+       'height_f','pressure_f','temp','theta','thv','thl','qv','ql','qi','rv','u','v',&
+       'sfc_sens_flx','sfc_lat_flx','ts','ps','ustar','tke',&
+       'orog','albedo','emiss','t_skin','q_skin','mom_rough','heat_rough','o3','rugos','clay','sand'/
+  do i=1,nbvar3d
+     missing_var(i)=0.
+  enddo
+
+  !-----------------------------------------------------------------------
+  do i=1,nbvar3d
+     ierr=NF_INQ_VARID(nid,name_var(i),var3didin(i)) 
+     if(ierr/=NF_NOERR) then
+        print *,'Variable manquante dans cas.nc:',i,name_var(i)
+        ierr=NF_NOERR
+        missing_var(i)=1
+     else
+        !-----------------------------------------------------------------------
+        if(i.LE.4) then     ! Lecture des coord pression en (nlevelp1,lat,lon)
+           ierr = NF90_GET_VAR(nid,var3didin(i),apbp, count = [1, 1, nlevel + 1])
            print *,'read2_cas(apbp), on a lu ',i,name_var(i)
            if(ierr/=NF_NOERR) then
@@ -730,11 +718,7 @@
               stop "getvarup"
            endif
-!-----------------------------------------------------------------------
-           else if(i.gt.4.and.i.LE.45) then   ! Lecture des variables en (time,nlevel,lat,lon)
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul)
-#endif
+           !-----------------------------------------------------------------------
+        else if(i.gt.4.and.i.LE.45) then   ! Lecture des variables en (time,nlevel,lat,lon)
+           ierr = NF90_GET_VAR(nid,var3didin(i),resul, count = [1, 1, nlevel, ntime])
            print *,'read2_cas(resul), on a lu ',i,name_var(i)
            if(ierr/=NF_NOERR) then
@@ -742,11 +726,7 @@
               stop "getvarup"
            endif
-!-----------------------------------------------------------------------
-           else if (i.gt.45.and.i.LE.51) then   ! Lecture des variables en (time,lat,lon)
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul2)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul2)
-#endif
+           !-----------------------------------------------------------------------
+        else if (i.gt.45.and.i.LE.51) then   ! Lecture des variables en (time,lat,lon)
+           ierr = NF90_GET_VAR(nid,var3didin(i),resul2, count = [1, 1, ntime])
            print *,'read2_cas(resul2), on a lu ',i,name_var(i)
            if(ierr/=NF_NOERR) then
@@ -754,11 +734,7 @@
               stop "getvarup"
            endif
-!-----------------------------------------------------------------------
-           else     ! Lecture des constantes (lat,lon)
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul3)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul3)
-#endif
+           !-----------------------------------------------------------------------
+        else     ! Lecture des constantes (lat,lon)
+           ierr = NF90_GET_VAR(nid,var3didin(i),resul3)
            print *,'read2_cas(resul3), on a lu ',i,name_var(i)
            if(ierr/=NF_NOERR) then
@@ -766,155 +742,152 @@
               stop "getvarup"
            endif
-           endif
-         endif
-!-----------------------------------------------------------------------
-         select case(i)
-           case(1) ; ap=apbp       ! donnees indexees en nlevel+1
-           case(2) ; bp=apbp
-           case(3) ; zzh=apbp
-           case(4) ; pph=apbp
-           case(5) ; vitw=resul    ! donnees indexees en nlevel,time
-           case(6) ; omega=resul
-           case(7) ; ug=resul
-           case(8) ; vg=resul
-           case(9) ; du=resul
-           case(10) ; hu=resul
-           case(11) ; vu=resul
-           case(12) ; dv=resul
-           case(13) ; hv=resul
-           case(14) ; vv=resul
-           case(15) ; dt=resul
-           case(16) ; ht=resul
-           case(17) ; vt=resul
-           case(18) ; dq=resul
-           case(19) ; hq=resul
-           case(20) ; vq=resul
-           case(21) ; dth=resul
-           case(22) ; hth=resul
-           case(23) ; vth=resul
-           case(24) ; hthl=resul
-           case(25) ; dr=resul
-           case(26) ; hr=resul
-           case(27) ; vr=resul
-           case(28) ; dtrad=resul
-           case(29) ; q1=resul
-           case(30) ; q2=resul
-           case(31) ; uw=resul
-           case(32) ; vw=resul
-           case(33) ; rh=resul
-           case(34) ; zz=resul      ! donnees en time,nlevel pour profil initial
-           case(35) ; pp=resul
-           case(36) ; temp=resul
-           case(37) ; theta=resul
-           case(38) ; thv=resul
-           case(39) ; thl=resul
-           case(40) ; qv=resul
-           case(41) ; ql=resul
-           case(42) ; qi=resul
-           case(43) ; rv=resul
-           case(44) ; u=resul
-           case(45) ; v=resul
-           case(46) ; sens=resul2   ! donnees indexees en time
-           case(47) ; flat=resul2
-           case(48) ; ts=resul2
-           case(49) ; ps=resul2
-           case(50) ; ustar=resul2
-           case(51) ; tke=resul2
-           case(52) ; orog_cas=resul3      ! constantes
-           case(53) ; albedo_cas=resul3
-           case(54) ; emiss_cas=resul3
-           case(55) ; t_skin_cas=resul3
-           case(56) ; q_skin_cas=resul3
-           case(57) ; mom_rough=resul3
-           case(58) ; heat_rough=resul3
-           case(59) ; o3_cas=resul3        
-           case(60) ; rugos_cas=resul3
-           case(61) ; clay_cas=resul3
-           case(62) ; sand_cas=resul3
-         end select
-         resul=0.
-         resul1=0.
-         resul2=0.
-         resul3=0.
-       enddo
-!-----------------------------------------------------------------------
-
-
-         return 
-         end subroutine read2_cas
+        endif
+     endif
+     !-----------------------------------------------------------------------
+     select case(i)
+     case(1) ; ap=apbp       ! donnees indexees en nlevel+1
+     case(2) ; bp=apbp
+     case(3) ; zzh=apbp
+     case(4) ; pph=apbp
+     case(5) ; vitw=resul    ! donnees indexees en nlevel,time
+     case(6) ; omega=resul
+     case(7) ; ug=resul
+     case(8) ; vg=resul
+     case(9) ; du=resul
+     case(10) ; hu=resul
+     case(11) ; vu=resul
+     case(12) ; dv=resul
+     case(13) ; hv=resul
+     case(14) ; vv=resul
+     case(15) ; dt=resul
+     case(16) ; ht=resul
+     case(17) ; vt=resul
+     case(18) ; dq=resul
+     case(19) ; hq=resul
+     case(20) ; vq=resul
+     case(21) ; dth=resul
+     case(22) ; hth=resul
+     case(23) ; vth=resul
+     case(24) ; hthl=resul
+     case(25) ; dr=resul
+     case(26) ; hr=resul
+     case(27) ; vr=resul
+     case(28) ; dtrad=resul
+     case(29) ; q1=resul
+     case(30) ; q2=resul
+     case(31) ; uw=resul
+     case(32) ; vw=resul
+     case(33) ; rh=resul
+     case(34) ; zz=resul      ! donnees en time,nlevel pour profil initial
+     case(35) ; pp=resul
+     case(36) ; temp=resul
+     case(37) ; theta=resul
+     case(38) ; thv=resul
+     case(39) ; thl=resul
+     case(40) ; qv=resul
+     case(41) ; ql=resul
+     case(42) ; qi=resul
+     case(43) ; rv=resul
+     case(44) ; u=resul
+     case(45) ; v=resul
+     case(46) ; sens=resul2   ! donnees indexees en time
+     case(47) ; flat=resul2
+     case(48) ; ts=resul2
+     case(49) ; ps=resul2
+     case(50) ; ustar=resul2
+     case(51) ; tke=resul2
+     case(52) ; orog_cas=resul3      ! constantes
+     case(53) ; albedo_cas=resul3
+     case(54) ; emiss_cas=resul3
+     case(55) ; t_skin_cas=resul3
+     case(56) ; q_skin_cas=resul3
+     case(57) ; mom_rough=resul3
+     case(58) ; heat_rough=resul3
+     case(59) ; o3_cas=resul3        
+     case(60) ; rugos_cas=resul3
+     case(61) ; clay_cas=resul3
+     case(62) ; sand_cas=resul3
+     end select
+     resul=0.
+     resul1=0.
+     resul2=0.
+     resul3=0.
+  enddo
+  !-----------------------------------------------------------------------
+
+
+  return 
+end subroutine read2_cas
 
 !======================================================================
-      subroutine old_read_SCM(nid,nlevel,ntime,                                       &
-     &     ap,bp,zz,pp,zzh,pph,temp,theta,thv,thl,qv,ql,qi,rh,rv,u,v,vitw,omega,ug,vg,&
-     &     du,hu,vu,dv,hv,vv,dt,ht,vt,dq,hq,vq,                                    &
-     &     dth,hth,vth,dr,hr,vr,dtrad,sens,flat,ts,ps,ustar,tke,uw,vw,q1,q2,       &
-     &     orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,          &
-     &     heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas)
-
-!program reading forcing of the case study
-      implicit none
+subroutine old_read_SCM(nid,nlevel,ntime,                                       &
+     ap,bp,zz,pp,zzh,pph,temp,theta,thv,thl,qv,ql,qi,rh,rv,u,v,vitw,omega,ug,vg,&
+     du,hu,vu,dv,hv,vv,dt,ht,vt,dq,hq,vq,                                    &
+     dth,hth,vth,dr,hr,vr,dtrad,sens,flat,ts,ps,ustar,tke,uw,vw,q1,q2,       &
+     orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,          &
+     heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas)
+
+  !program reading forcing of the case study
+  use netcdf, only: nf90_get_var
+  implicit none
 #include "netcdf.inc"
 
-      integer ntime,nlevel,k,t
-
-      real ap(nlevel+1),bp(nlevel+1)
-      real zz(nlevel,ntime),zzh(nlevel+1)
-      real pp(nlevel,ntime),pph(nlevel+1)
-!profils initiaux
-      real temp0(nlevel),qv0(nlevel),ql0(nlevel),qi0(nlevel),u0(nlevel),v0(nlevel),tke0(nlevel)
-      real pp0(nlevel)    
-      real temp(nlevel,ntime),qv(nlevel,ntime),ql(nlevel,ntime),qi(nlevel,ntime),rh(nlevel,ntime)
-      real theta(nlevel,ntime),thv(nlevel,ntime),thl(nlevel,ntime),rv(nlevel,ntime)
-      real u(nlevel,ntime),v(nlevel,ntime),tke(nlevel,ntime)
-      real ug(nlevel,ntime),vg(nlevel,ntime)
-      real vitw(nlevel,ntime),omega(nlevel,ntime)
-      real du(nlevel,ntime),hu(nlevel,ntime),vu(nlevel,ntime)
-      real dv(nlevel,ntime),hv(nlevel,ntime),vv(nlevel,ntime)
-      real dt(nlevel,ntime),ht(nlevel,ntime),vt(nlevel,ntime)
-      real dtrad(nlevel,ntime)
-      real dq(nlevel,ntime),hq(nlevel,ntime),vq(nlevel,ntime)
-      real dth(nlevel,ntime),hth(nlevel,ntime),vth(nlevel,ntime),hthl(nlevel,ntime)
-      real dr(nlevel,ntime),hr(nlevel,ntime),vr(nlevel,ntime)
-      real flat(ntime),sens(ntime),ustar(ntime)
-      real uw(nlevel,ntime),vw(nlevel,ntime),q1(nlevel,ntime),q2(nlevel,ntime)
-      real ts(ntime),ps(ntime)
-      real orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas
-      real apbp(nlevel+1),resul(nlevel,ntime),resul1(nlevel),resul2(ntime),resul3
-
-
-      integer nid, ierr,ierr1,ierr2,rid,i
-      integer nbvar3d
-      parameter(nbvar3d=70)
-      integer var3didin(nbvar3d),missing_var(nbvar3d)
-      character*13 name_var(1:nbvar3d)
-      data name_var/'coor_par_a','coor_par_b','height_h','pressure_h',&
-     &'temp','qv','ql','qi','u','v','tke','pressure',&
-     &'w','omega','ug','vg','uadv','uadvh','uadvv','vadv','vadvh','vadvv','tadv','tadvh','tadvv',&
-     &'qvadv','qvadvh','qvadvv','thadv','thadvh','thadvv','thladvh','radv','radvh','radvv','radcool','q1','q2','ustress','vstress', &
-     'rh',&
-     &'height_f','pressure_forc','tempt','theta','thv','thl','qvt','qlt','qit','rv','ut','vt','tket',&
-     &'sfc_sens_flx','sfc_lat_flx','ts','ps','ustar',&
-     &'orog','albedo','emiss','t_skin','q_skin','mom_rough','heat_rough','o3','rugos','clay','sand'/
-      do i=1,nbvar3d
-        missing_var(i)=0.
-      enddo
-
-!-----------------------------------------------------------------------
-
-     print*,'ON EST LA'
-       do i=1,nbvar3d
-         ierr=NF_INQ_VARID(nid,name_var(i),var3didin(i)) 
-         if(ierr/=NF_NOERR) then
-           print *,'Variable manquante dans cas.nc:',i,name_var(i)
-           ierr=NF_NOERR
-           missing_var(i)=1
-         else
-!-----------------------------------------------------------------------
-           if(i.LE.4) then     ! Lecture des coord pression en (nlevelp1,lat,lon)
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),apbp)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),apbp)
-#endif
+  integer ntime,nlevel,k,t
+
+  real ap(nlevel+1),bp(nlevel+1)
+  real zz(nlevel,ntime),zzh(nlevel+1)
+  real pp(nlevel,ntime),pph(nlevel+1)
+  !profils initiaux
+  real temp0(nlevel),qv0(nlevel),ql0(nlevel),qi0(nlevel),u0(nlevel),v0(nlevel),tke0(nlevel)
+  real pp0(nlevel)    
+  real temp(nlevel,ntime),qv(nlevel,ntime),ql(nlevel,ntime),qi(nlevel,ntime),rh(nlevel,ntime)
+  real theta(nlevel,ntime),thv(nlevel,ntime),thl(nlevel,ntime),rv(nlevel,ntime)
+  real u(nlevel,ntime),v(nlevel,ntime),tke(nlevel,ntime)
+  real ug(nlevel,ntime),vg(nlevel,ntime)
+  real vitw(nlevel,ntime),omega(nlevel,ntime)
+  real du(nlevel,ntime),hu(nlevel,ntime),vu(nlevel,ntime)
+  real dv(nlevel,ntime),hv(nlevel,ntime),vv(nlevel,ntime)
+  real dt(nlevel,ntime),ht(nlevel,ntime),vt(nlevel,ntime)
+  real dtrad(nlevel,ntime)
+  real dq(nlevel,ntime),hq(nlevel,ntime),vq(nlevel,ntime)
+  real dth(nlevel,ntime),hth(nlevel,ntime),vth(nlevel,ntime),hthl(nlevel,ntime)
+  real dr(nlevel,ntime),hr(nlevel,ntime),vr(nlevel,ntime)
+  real flat(ntime),sens(ntime),ustar(ntime)
+  real uw(nlevel,ntime),vw(nlevel,ntime),q1(nlevel,ntime),q2(nlevel,ntime)
+  real ts(ntime),ps(ntime)
+  real orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas
+  real apbp(nlevel+1),resul(nlevel,ntime),resul1(nlevel),resul2(ntime),resul3
+
+
+  integer nid, ierr,ierr1,ierr2,rid,i
+  integer nbvar3d
+  parameter(nbvar3d=70)
+  integer var3didin(nbvar3d),missing_var(nbvar3d)
+  character*13 name_var(1:nbvar3d)
+  data name_var/'coor_par_a','coor_par_b','height_h','pressure_h',&
+       'temp','qv','ql','qi','u','v','tke','pressure',&
+       'w','omega','ug','vg','uadv','uadvh','uadvv','vadv','vadvh','vadvv','tadv','tadvh','tadvv',&
+       'qvadv','qvadvh','qvadvv','thadv','thadvh','thadvv','thladvh','radv','radvh','radvv','radcool','q1','q2','ustress', &
+       'vstress','rh',&
+       'height_f','pressure_forc','tempt','theta','thv','thl','qvt','qlt','qit','rv','ut','vt','tket',&
+       'sfc_sens_flx','sfc_lat_flx','ts','ps','ustar',&
+       'orog','albedo','emiss','t_skin','q_skin','mom_rough','heat_rough','o3','rugos','clay','sand'/
+  do i=1,nbvar3d
+     missing_var(i)=0.
+  enddo
+
+  !-----------------------------------------------------------------------
+
+  print*,'ON EST LA'
+  do i=1,nbvar3d
+     ierr=NF_INQ_VARID(nid,name_var(i),var3didin(i)) 
+     if(ierr/=NF_NOERR) then
+        print *,'Variable manquante dans cas.nc:',i,name_var(i)
+        ierr=NF_NOERR
+        missing_var(i)=1
+     else
+        !-----------------------------------------------------------------------
+        if(i.LE.4) then     ! Lecture des coord pression en (nlevelp1,lat,lon)
+           ierr = NF90_GET_VAR(nid,var3didin(i),apbp)
            print *,'read2_cas(apbp), on a lu ',i,name_var(i)
            if(ierr/=NF_NOERR) then
@@ -922,11 +895,7 @@
               stop "getvarup"
            endif
-!-----------------------------------------------------------------------
-           else if(i.gt.4.and.i.LE.12) then   ! Lecture des variables en (time,nlevel,lat,lon)
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul1)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul1)
-#endif
+           !-----------------------------------------------------------------------
+        else if(i.gt.4.and.i.LE.12) then   ! Lecture des variables en (time,nlevel,lat,lon)
+           ierr = NF90_GET_VAR(nid,var3didin(i),resul1)
            print *,'read2_cas(resul1), on a lu ',i,name_var(i)
            if(ierr/=NF_NOERR) then
@@ -934,12 +903,8 @@
               stop "getvarup"
            endif
-         print*,'Lecture de la variable #i ',i,name_var(i),minval(resul1),maxval(resul1)
-!-----------------------------------------------------------------------
-           else if(i.gt.12.and.i.LE.54) then   ! Lecture des variables en (time,nlevel,lat,lon)
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul)
-#endif
+           print*,'Lecture de la variable #i ',i,name_var(i),minval(resul1),maxval(resul1)
+           !-----------------------------------------------------------------------
+        else if(i.gt.12.and.i.LE.54) then   ! Lecture des variables en (time,nlevel,lat,lon)
+           ierr = NF90_GET_VAR(nid,var3didin(i),resul)
            print *,'read2_cas(resul), on a lu ',i,name_var(i)
            if(ierr/=NF_NOERR) then
@@ -947,12 +912,8 @@
               stop "getvarup"
            endif
-         print*,'Lecture de la variable #i ',i,name_var(i),minval(resul),maxval(resul)
-!-----------------------------------------------------------------------
-           else if (i.gt.54.and.i.LE.65) then   ! Lecture des variables en (time,lat,lon)
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul2)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul2)
-#endif
+           print*,'Lecture de la variable #i ',i,name_var(i),minval(resul),maxval(resul)
+           !-----------------------------------------------------------------------
+        else if (i.gt.54.and.i.LE.65) then   ! Lecture des variables en (time,lat,lon)
+           ierr = NF90_GET_VAR(nid,var3didin(i),resul2)
            print *,'read2_cas(resul2), on a lu ',i,name_var(i)
            if(ierr/=NF_NOERR) then
@@ -960,12 +921,8 @@
               stop "getvarup"
            endif
-         print*,'Lecture de la variable #i  ',i,name_var(i),minval(resul2),maxval(resul2)
-!-----------------------------------------------------------------------
-           else     ! Lecture des constantes (lat,lon)
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul3)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul3)
-#endif
+           print*,'Lecture de la variable #i  ',i,name_var(i),minval(resul2),maxval(resul2)
+           !-----------------------------------------------------------------------
+        else     ! Lecture des constantes (lat,lon)
+           ierr = NF90_GET_VAR(nid,var3didin(i),resul3)
            print *,'read2_cas(resul3), on a lu ',i,name_var(i)
            if(ierr/=NF_NOERR) then
@@ -973,546 +930,546 @@
               stop "getvarup"
            endif
-         print*,'Lecture de la variable #i ',i,name_var(i),resul3
-           endif
-         endif
-!-----------------------------------------------------------------------
-         select case(i)
-         !case(1) ; ap=apbp       ! donnees indexees en nlevel+1
-         ! case(2) ; bp=apbp
-           case(3) ; zzh=apbp
-           case(4) ; pph=apbp
-           case(5) ; temp0=resul1    ! donnees initiales
-           case(6) ; qv0=resul1
-           case(7) ; ql0=resul1
-           case(8) ; qi0=resul1
-           case(9) ; u0=resul1
-           case(10) ; v0=resul1
-           case(11) ; tke0=resul1
-           case(12) ; pp0=resul1
-           case(13) ; vitw=resul    ! donnees indexees en nlevel,time
-           case(14) ; omega=resul
-           case(15) ; ug=resul
-           case(16) ; vg=resul
-           case(17) ; du=resul
-           case(18) ; hu=resul
-           case(19) ; vu=resul
-           case(20) ; dv=resul
-           case(21) ; hv=resul
-           case(22) ; vv=resul
-           case(23) ; dt=resul
-           case(24) ; ht=resul
-           case(25) ; vt=resul
-           case(26) ; dq=resul
-           case(27) ; hq=resul
-           case(28) ; vq=resul
-           case(29) ; dth=resul
-           case(30) ; hth=resul
-           case(31) ; vth=resul
-           case(32) ; hthl=resul
-           case(33) ; dr=resul
-           case(34) ; hr=resul
-           case(35) ; vr=resul
-           case(36) ; dtrad=resul
-           case(37) ; q1=resul
-           case(38) ; q2=resul
-           case(39) ; uw=resul
-           case(40) ; vw=resul
-           case(41) ; rh=resul
-           case(42) ; zz=resul      ! donnees en time,nlevel pour profil initial
-           case(43) ; pp=resul
-           case(44) ; temp=resul
-           case(45) ; theta=resul
-           case(46) ; thv=resul
-           case(47) ; thl=resul
-           case(48) ; qv=resul
-           case(49) ; ql=resul
-           case(50) ; qi=resul
-           case(51) ; rv=resul
-           case(52) ; u=resul
-           case(53) ; v=resul
-           case(54) ; tke=resul
-           case(55) ; sens=resul2   ! donnees indexees en time
-           case(56) ; flat=resul2
-           case(57) ; ts=resul2
-           case(58) ; ps=resul2
-           case(59) ; ustar=resul2
-           case(60) ; orog_cas=resul3      ! constantes
-           case(61) ; albedo_cas=resul3
-           case(62) ; emiss_cas=resul3
-           case(63) ; t_skin_cas=resul3
-           case(64) ; q_skin_cas=resul3
-           case(65) ; mom_rough=resul3
-           case(66) ; heat_rough=resul3
-           case(67) ; o3_cas=resul3        
-           case(68) ; rugos_cas=resul3
-           case(69) ; clay_cas=resul3
-           case(70) ; sand_cas=resul3
-         end select
-         resul=0.
-         resul1=0.
-         resul2=0.
-         resul3=0.
-       enddo
-         print*,'Lecture de la variable APRES ,sens ',minval(sens),maxval(sens)
-         print*,'Lecture de la variable APRES ,flat ',minval(flat),maxval(flat)
-
-!CR:ATTENTION EN ATTENTE DE REGLER LA QUESTION DU PAS DE TEMPS INITIAL
-       do t=1,ntime
-          do k=1,nlevel
-             temp(k,t)=temp0(k)
-             qv(k,t)=qv0(k)
-             ql(k,t)=ql0(k)
-             qi(k,t)=qi0(k)
-             u(k,t)=u0(k)
-             v(k,t)=v0(k)
-             tke(k,t)=tke0(k)
-          enddo
-       enddo
-!-----------------------------------------------------------------------
-
-         return 
-         end subroutine old_read_SCM
+           print*,'Lecture de la variable #i ',i,name_var(i),resul3
+        endif
+     endif
+     !-----------------------------------------------------------------------
+     select case(i)
+        !case(1) ; ap=apbp       ! donnees indexees en nlevel+1
+        ! case(2) ; bp=apbp
+     case(3) ; zzh=apbp
+     case(4) ; pph=apbp
+     case(5) ; temp0=resul1    ! donnees initiales
+     case(6) ; qv0=resul1
+     case(7) ; ql0=resul1
+     case(8) ; qi0=resul1
+     case(9) ; u0=resul1
+     case(10) ; v0=resul1
+     case(11) ; tke0=resul1
+     case(12) ; pp0=resul1
+     case(13) ; vitw=resul    ! donnees indexees en nlevel,time
+     case(14) ; omega=resul
+     case(15) ; ug=resul
+     case(16) ; vg=resul
+     case(17) ; du=resul
+     case(18) ; hu=resul
+     case(19) ; vu=resul
+     case(20) ; dv=resul
+     case(21) ; hv=resul
+     case(22) ; vv=resul
+     case(23) ; dt=resul
+     case(24) ; ht=resul
+     case(25) ; vt=resul
+     case(26) ; dq=resul
+     case(27) ; hq=resul
+     case(28) ; vq=resul
+     case(29) ; dth=resul
+     case(30) ; hth=resul
+     case(31) ; vth=resul
+     case(32) ; hthl=resul
+     case(33) ; dr=resul
+     case(34) ; hr=resul
+     case(35) ; vr=resul
+     case(36) ; dtrad=resul
+     case(37) ; q1=resul
+     case(38) ; q2=resul
+     case(39) ; uw=resul
+     case(40) ; vw=resul
+     case(41) ; rh=resul
+     case(42) ; zz=resul      ! donnees en time,nlevel pour profil initial
+     case(43) ; pp=resul
+     case(44) ; temp=resul
+     case(45) ; theta=resul
+     case(46) ; thv=resul
+     case(47) ; thl=resul
+     case(48) ; qv=resul
+     case(49) ; ql=resul
+     case(50) ; qi=resul
+     case(51) ; rv=resul
+     case(52) ; u=resul
+     case(53) ; v=resul
+     case(54) ; tke=resul
+     case(55) ; sens=resul2   ! donnees indexees en time
+     case(56) ; flat=resul2
+     case(57) ; ts=resul2
+     case(58) ; ps=resul2
+     case(59) ; ustar=resul2
+     case(60) ; orog_cas=resul3      ! constantes
+     case(61) ; albedo_cas=resul3
+     case(62) ; emiss_cas=resul3
+     case(63) ; t_skin_cas=resul3
+     case(64) ; q_skin_cas=resul3
+     case(65) ; mom_rough=resul3
+     case(66) ; heat_rough=resul3
+     case(67) ; o3_cas=resul3        
+     case(68) ; rugos_cas=resul3
+     case(69) ; clay_cas=resul3
+     case(70) ; sand_cas=resul3
+     end select
+     resul=0.
+     resul1=0.
+     resul2=0.
+     resul3=0.
+  enddo
+  print*,'Lecture de la variable APRES ,sens ',minval(sens),maxval(sens)
+  print*,'Lecture de la variable APRES ,flat ',minval(flat),maxval(flat)
+
+  !CR:ATTENTION EN ATTENTE DE REGLER LA QUESTION DU PAS DE TEMPS INITIAL
+  do t=1,ntime
+     do k=1,nlevel
+        temp(k,t)=temp0(k)
+        qv(k,t)=qv0(k)
+        ql(k,t)=ql0(k)
+        qi(k,t)=qi0(k)
+        u(k,t)=u0(k)
+        v(k,t)=v0(k)
+        tke(k,t)=tke0(k)
+     enddo
+  enddo
+  !-----------------------------------------------------------------------
+
+  return 
+end subroutine old_read_SCM
 !======================================================================
 
 !======================================================================
-        SUBROUTINE interp_case_time2(day,day1,annee_ref                &
-!    &         ,year_cas,day_cas,nt_cas,pdt_forc,nlev_cas      &
-     &         ,nt_cas,nlev_cas                                       &
-     &         ,ts_cas,ps_cas,plev_cas,t_cas,q_cas,u_cas,v_cas               &
-     &         ,ug_cas,vg_cas,vitw_cas,du_cas,hu_cas,vu_cas           &
-     &         ,dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dtrad_cas   &
-     &         ,dq_cas,hq_cas,vq_cas,lat_cas,sens_cas,ustar_cas       &
-     &         ,uw_cas,vw_cas,q1_cas,q2_cas                           &
-     &         ,ts_prof_cas,plev_prof_cas,t_prof_cas,q_prof_cas       &
-     &         ,u_prof_cas,v_prof_cas,ug_prof_cas,vg_prof_cas         &
-     &         ,vitw_prof_cas,du_prof_cas,hu_prof_cas,vu_prof_cas     &
-     &         ,dv_prof_cas,hv_prof_cas,vv_prof_cas,dt_prof_cas       &
-     &         ,ht_prof_cas,vt_prof_cas,dtrad_prof_cas,dq_prof_cas    &
-     &         ,hq_prof_cas,vq_prof_cas,lat_prof_cas,sens_prof_cas    &
-     &         ,ustar_prof_cas,uw_prof_cas,vw_prof_cas,q1_prof_cas,q2_prof_cas)
-          
-
-        implicit none
-
-!---------------------------------------------------------------------------------------
-! Time interpolation of a 2D field to the timestep corresponding to day
-!
-! day: current julian day (e.g. 717538.2)
-! day1: first day of the simulation
-! nt_cas: total nb of data in the forcing 
-! pdt_cas: total time interval (in sec) between 2 forcing data
-!---------------------------------------------------------------------------------------
+SUBROUTINE interp_case_time2(day,day1,annee_ref                &
+     !    &         ,year_cas,day_cas,nt_cas,pdt_forc,nlev_cas      &
+     ,nt_cas,nlev_cas                                       &
+     ,ts_cas,ps_cas,plev_cas,t_cas,q_cas,u_cas,v_cas               &
+     ,ug_cas,vg_cas,vitw_cas,du_cas,hu_cas,vu_cas           &
+     ,dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dtrad_cas   &
+     ,dq_cas,hq_cas,vq_cas,lat_cas,sens_cas,ustar_cas       &
+     ,uw_cas,vw_cas,q1_cas,q2_cas                           &
+     ,ts_prof_cas,plev_prof_cas,t_prof_cas,q_prof_cas       &
+     ,u_prof_cas,v_prof_cas,ug_prof_cas,vg_prof_cas         &
+     ,vitw_prof_cas,du_prof_cas,hu_prof_cas,vu_prof_cas     &
+     ,dv_prof_cas,hv_prof_cas,vv_prof_cas,dt_prof_cas       &
+     ,ht_prof_cas,vt_prof_cas,dtrad_prof_cas,dq_prof_cas    &
+     ,hq_prof_cas,vq_prof_cas,lat_prof_cas,sens_prof_cas    &
+     ,ustar_prof_cas,uw_prof_cas,vw_prof_cas,q1_prof_cas,q2_prof_cas)
+
+
+  implicit none
+
+  !---------------------------------------------------------------------------------------
+  ! Time interpolation of a 2D field to the timestep corresponding to day
+  !
+  ! day: current julian day (e.g. 717538.2)
+  ! day1: first day of the simulation
+  ! nt_cas: total nb of data in the forcing 
+  ! pdt_cas: total time interval (in sec) between 2 forcing data
+  !---------------------------------------------------------------------------------------
 
 #include "compar1d.h"
 #include "date_cas.h"
 
-! inputs:
-        integer annee_ref
-        integer nt_cas,nlev_cas
-        real day, day1,day_cas
-        real ts_cas(nt_cas),ps_cas(nt_cas)
-        real plev_cas(nlev_cas,nt_cas)
-        real t_cas(nlev_cas,nt_cas),q_cas(nlev_cas,nt_cas)
-        real u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas)
-        real ug_cas(nlev_cas,nt_cas),vg_cas(nlev_cas,nt_cas)
-        real vitw_cas(nlev_cas,nt_cas)
-        real du_cas(nlev_cas,nt_cas),hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas)
-        real dv_cas(nlev_cas,nt_cas),hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas)
-        real dt_cas(nlev_cas,nt_cas),ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas)
-        real dtrad_cas(nlev_cas,nt_cas)
-        real dq_cas(nlev_cas,nt_cas),hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas)
-        real lat_cas(nt_cas)
-        real sens_cas(nt_cas)
-        real ustar_cas(nt_cas),uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas)
-        real q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas)
-
-! outputs:
-        real plev_prof_cas(nlev_cas)
-        real t_prof_cas(nlev_cas),q_prof_cas(nlev_cas)
-        real u_prof_cas(nlev_cas),v_prof_cas(nlev_cas)
-        real ug_prof_cas(nlev_cas),vg_prof_cas(nlev_cas)
-        real vitw_prof_cas(nlev_cas)
-        real du_prof_cas(nlev_cas),hu_prof_cas(nlev_cas),vu_prof_cas(nlev_cas)
-        real dv_prof_cas(nlev_cas),hv_prof_cas(nlev_cas),vv_prof_cas(nlev_cas)
-        real dt_prof_cas(nlev_cas),ht_prof_cas(nlev_cas),vt_prof_cas(nlev_cas)
-        real dtrad_prof_cas(nlev_cas)
-        real dq_prof_cas(nlev_cas),hq_prof_cas(nlev_cas),vq_prof_cas(nlev_cas)
-        real lat_prof_cas,sens_prof_cas,ts_prof_cas,ustar_prof_cas
-        real uw_prof_cas(nlev_cas),vw_prof_cas(nlev_cas),q1_prof_cas(nlev_cas),q2_prof_cas(nlev_cas)
-! local:
-        integer it_cas1, it_cas2,k
-        real timeit,time_cas1,time_cas2,frac
-
-
-        print*,'Check time',day1,day_ju_ini_cas,day_deb+1,pdt_cas
-
-! On teste si la date du cas AMMA est correcte.
-! C est pour memoire car en fait les fichiers .def
-! sont censes etre corrects.
-! A supprimer a terme (MPL 20150623)
-!     if ((forcing_type.eq.10).and.(1.eq.0)) then
-! Check that initial day of the simulation consistent with AMMA case:
-!      if (annee_ref.ne.2006) then
-!       print*,'Pour AMMA, annee_ref doit etre 2006'
-!       print*,'Changer annee_ref dans run.def'
-!       stop
-!      endif
-!      if (annee_ref.eq.2006 .and. day1.lt.day_cas) then
-!       print*,'AMMA a debute le 10 juillet 2006',day1,day_cas
-!       print*,'Changer dayref dans run.def'
-!       stop
-!      endif
-!      if (annee_ref.eq.2006 .and. day1.gt.day_cas+1) then
-!       print*,'AMMA a fini le 11 juillet'
-!       print*,'Changer dayref ou nday dans run.def'
-!       stop
-!      endif
-!      endif
-
-! Determine timestep relative to the 1st day:
-!       timeit=(day-day1)*86400.
-!       if (annee_ref.eq.1992) then
-!        timeit=(day-day_cas)*86400.
-!       else
-!        timeit=(day+61.-1.)*86400. ! 61 days between Nov01 and Dec31 1992
-!       endif
-      timeit=(day-day_ju_ini_cas)*86400
-      print *,'day=',day
-      print *,'day_ju_ini_cas=',day_ju_ini_cas
-      print *,'pdt_cas=',pdt_cas
-      print *,'timeit=',timeit
-      print *,'nt_cas=',nt_cas
-
-! Determine the closest observation times:
-!       it_cas1=INT(timeit/pdt_cas)+1
-!       it_cas2=it_cas1 + 1
-!       time_cas1=(it_cas1-1)*pdt_cas
-!       time_cas2=(it_cas2-1)*pdt_cas
-
-       it_cas1=INT(timeit/pdt_cas)+1
-       IF (it_cas1 .EQ. nt_cas) THEN
-       it_cas2=it_cas1 
-       ELSE
-       it_cas2=it_cas1 + 1
-       ENDIF
-       time_cas1=(it_cas1-1)*pdt_cas
-       time_cas2=(it_cas2-1)*pdt_cas
-       print *,'it_cas1,it_cas2,time_cas1,time_cas2=',it_cas1,it_cas2,time_cas1,time_cas2
-
-       if (it_cas1 .gt. nt_cas) then
-        write(*,*) 'PB-stop: day, day_ju_ini_cas,it_cas1, it_cas2, timeit: '            &
-     &        ,day,day_ju_ini_cas,it_cas1,it_cas2,timeit
-        stop
-       endif
-
-! time interpolation:
-       IF (it_cas1 .EQ. it_cas2) THEN
-          frac=0.
-       ELSE
-          frac=(time_cas2-timeit)/(time_cas2-time_cas1)
-          frac=max(frac,0.0)
-       ENDIF
-
-       lat_prof_cas = lat_cas(it_cas2)                                       &
-     &          -frac*(lat_cas(it_cas2)-lat_cas(it_cas1)) 
-       sens_prof_cas = sens_cas(it_cas2)                                     &
-     &          -frac*(sens_cas(it_cas2)-sens_cas(it_cas1))
-       ts_prof_cas = ts_cas(it_cas2)                                         &
-     &          -frac*(ts_cas(it_cas2)-ts_cas(it_cas1))
-       ustar_prof_cas = ustar_cas(it_cas2)                                   &
-     &          -frac*(ustar_cas(it_cas2)-ustar_cas(it_cas1))
-
-       do k=1,nlev_cas
-        plev_prof_cas(k) = plev_cas(k,it_cas2)                               &
-     &          -frac*(plev_cas(k,it_cas2)-plev_cas(k,it_cas1))
-        t_prof_cas(k) = t_cas(k,it_cas2)                               &
-     &          -frac*(t_cas(k,it_cas2)-t_cas(k,it_cas1))
-        q_prof_cas(k) = q_cas(k,it_cas2)                               &
-     &          -frac*(q_cas(k,it_cas2)-q_cas(k,it_cas1))
-        u_prof_cas(k) = u_cas(k,it_cas2)                               &
-     &          -frac*(u_cas(k,it_cas2)-u_cas(k,it_cas1))
-        v_prof_cas(k) = v_cas(k,it_cas2)                               &
-     &          -frac*(v_cas(k,it_cas2)-v_cas(k,it_cas1))
-        ug_prof_cas(k) = ug_cas(k,it_cas2)                               &
-     &          -frac*(ug_cas(k,it_cas2)-ug_cas(k,it_cas1))
-        vg_prof_cas(k) = vg_cas(k,it_cas2)                               &
-     &          -frac*(vg_cas(k,it_cas2)-vg_cas(k,it_cas1))
-        vitw_prof_cas(k) = vitw_cas(k,it_cas2)                               &
-     &          -frac*(vitw_cas(k,it_cas2)-vitw_cas(k,it_cas1))
-        du_prof_cas(k) = du_cas(k,it_cas2)                                   &
-     &          -frac*(du_cas(k,it_cas2)-du_cas(k,it_cas1))
-        hu_prof_cas(k) = hu_cas(k,it_cas2)                                   &
-     &          -frac*(hu_cas(k,it_cas2)-hu_cas(k,it_cas1))
-        vu_prof_cas(k) = vu_cas(k,it_cas2)                                   &
-     &          -frac*(vu_cas(k,it_cas2)-vu_cas(k,it_cas1))
-        dv_prof_cas(k) = dv_cas(k,it_cas2)                                   &
-     &          -frac*(dv_cas(k,it_cas2)-dv_cas(k,it_cas1))
-        hv_prof_cas(k) = hv_cas(k,it_cas2)                                   &
-     &          -frac*(hv_cas(k,it_cas2)-hv_cas(k,it_cas1))
-        vv_prof_cas(k) = vv_cas(k,it_cas2)                                   &
-     &          -frac*(vv_cas(k,it_cas2)-vv_cas(k,it_cas1))
-        dt_prof_cas(k) = dt_cas(k,it_cas2)                                   &
-     &          -frac*(dt_cas(k,it_cas2)-dt_cas(k,it_cas1))
-        ht_prof_cas(k) = ht_cas(k,it_cas2)                                   &
-     &          -frac*(ht_cas(k,it_cas2)-ht_cas(k,it_cas1))
-        vt_prof_cas(k) = vt_cas(k,it_cas2)                                   &
-     &          -frac*(vt_cas(k,it_cas2)-vt_cas(k,it_cas1))
-        dtrad_prof_cas(k) = dtrad_cas(k,it_cas2)                                   &
-     &          -frac*(dtrad_cas(k,it_cas2)-dtrad_cas(k,it_cas1))
-        dq_prof_cas(k) = dq_cas(k,it_cas2)                                   &
-     &          -frac*(dq_cas(k,it_cas2)-dq_cas(k,it_cas1))
-        hq_prof_cas(k) = hq_cas(k,it_cas2)                                   &
-     &          -frac*(hq_cas(k,it_cas2)-hq_cas(k,it_cas1))
-        vq_prof_cas(k) = vq_cas(k,it_cas2)                                   &
-     &          -frac*(vq_cas(k,it_cas2)-vq_cas(k,it_cas1))
-       uw_prof_cas(k) = uw_cas(k,it_cas2)                                   &
-     &          -frac*(uw_cas(k,it_cas2)-uw_cas(k,it_cas1))
-       vw_prof_cas(k) = vw_cas(k,it_cas2)                                   &
-     &          -frac*(vw_cas(k,it_cas2)-vw_cas(k,it_cas1))
-       q1_prof_cas(k) = q1_cas(k,it_cas2)                                   &
-     &          -frac*(q1_cas(k,it_cas2)-q1_cas(k,it_cas1))
-       q2_prof_cas(k) = q2_cas(k,it_cas2)                                   &
-     &          -frac*(q2_cas(k,it_cas2)-q2_cas(k,it_cas1))
-        enddo
-
-        return
-        END SUBROUTINE interp_case_time2
+  ! inputs:
+  integer annee_ref
+  integer nt_cas,nlev_cas
+  real day, day1,day_cas
+  real ts_cas(nt_cas),ps_cas(nt_cas)
+  real plev_cas(nlev_cas,nt_cas)
+  real t_cas(nlev_cas,nt_cas),q_cas(nlev_cas,nt_cas)
+  real u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas)
+  real ug_cas(nlev_cas,nt_cas),vg_cas(nlev_cas,nt_cas)
+  real vitw_cas(nlev_cas,nt_cas)
+  real du_cas(nlev_cas,nt_cas),hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas)
+  real dv_cas(nlev_cas,nt_cas),hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas)
+  real dt_cas(nlev_cas,nt_cas),ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas)
+  real dtrad_cas(nlev_cas,nt_cas)
+  real dq_cas(nlev_cas,nt_cas),hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas)
+  real lat_cas(nt_cas)
+  real sens_cas(nt_cas)
+  real ustar_cas(nt_cas),uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas)
+  real q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas)
+
+  ! outputs:
+  real plev_prof_cas(nlev_cas)
+  real t_prof_cas(nlev_cas),q_prof_cas(nlev_cas)
+  real u_prof_cas(nlev_cas),v_prof_cas(nlev_cas)
+  real ug_prof_cas(nlev_cas),vg_prof_cas(nlev_cas)
+  real vitw_prof_cas(nlev_cas)
+  real du_prof_cas(nlev_cas),hu_prof_cas(nlev_cas),vu_prof_cas(nlev_cas)
+  real dv_prof_cas(nlev_cas),hv_prof_cas(nlev_cas),vv_prof_cas(nlev_cas)
+  real dt_prof_cas(nlev_cas),ht_prof_cas(nlev_cas),vt_prof_cas(nlev_cas)
+  real dtrad_prof_cas(nlev_cas)
+  real dq_prof_cas(nlev_cas),hq_prof_cas(nlev_cas),vq_prof_cas(nlev_cas)
+  real lat_prof_cas,sens_prof_cas,ts_prof_cas,ustar_prof_cas
+  real uw_prof_cas(nlev_cas),vw_prof_cas(nlev_cas),q1_prof_cas(nlev_cas),q2_prof_cas(nlev_cas)
+  ! local:
+  integer it_cas1, it_cas2,k
+  real timeit,time_cas1,time_cas2,frac
+
+
+  print*,'Check time',day1,day_ju_ini_cas,day_deb+1,pdt_cas
+
+  ! On teste si la date du cas AMMA est correcte.
+  ! C est pour memoire car en fait les fichiers .def
+  ! sont censes etre corrects.
+  ! A supprimer a terme (MPL 20150623)
+  !     if ((forcing_type.eq.10).and.(1.eq.0)) then
+  ! Check that initial day of the simulation consistent with AMMA case:
+  !      if (annee_ref.ne.2006) then
+  !       print*,'Pour AMMA, annee_ref doit etre 2006'
+  !       print*,'Changer annee_ref dans run.def'
+  !       stop
+  !      endif
+  !      if (annee_ref.eq.2006 .and. day1.lt.day_cas) then
+  !       print*,'AMMA a debute le 10 juillet 2006',day1,day_cas
+  !       print*,'Changer dayref dans run.def'
+  !       stop
+  !      endif
+  !      if (annee_ref.eq.2006 .and. day1.gt.day_cas+1) then
+  !       print*,'AMMA a fini le 11 juillet'
+  !       print*,'Changer dayref ou nday dans run.def'
+  !       stop
+  !      endif
+  !      endif
+
+  ! Determine timestep relative to the 1st day:
+  !       timeit=(day-day1)*86400.
+  !       if (annee_ref.eq.1992) then
+  !        timeit=(day-day_cas)*86400.
+  !       else
+  !        timeit=(day+61.-1.)*86400. ! 61 days between Nov01 and Dec31 1992
+  !       endif
+  timeit=(day-day_ju_ini_cas)*86400
+  print *,'day=',day
+  print *,'day_ju_ini_cas=',day_ju_ini_cas
+  print *,'pdt_cas=',pdt_cas
+  print *,'timeit=',timeit
+  print *,'nt_cas=',nt_cas
+
+  ! Determine the closest observation times:
+  !       it_cas1=INT(timeit/pdt_cas)+1
+  !       it_cas2=it_cas1 + 1
+  !       time_cas1=(it_cas1-1)*pdt_cas
+  !       time_cas2=(it_cas2-1)*pdt_cas
+
+  it_cas1=INT(timeit/pdt_cas)+1
+  IF (it_cas1 .EQ. nt_cas) THEN
+     it_cas2=it_cas1 
+  ELSE
+     it_cas2=it_cas1 + 1
+  ENDIF
+  time_cas1=(it_cas1-1)*pdt_cas
+  time_cas2=(it_cas2-1)*pdt_cas
+  print *,'it_cas1,it_cas2,time_cas1,time_cas2=',it_cas1,it_cas2,time_cas1,time_cas2
+
+  if (it_cas1 .gt. nt_cas) then
+     write(*,*) 'PB-stop: day, day_ju_ini_cas,it_cas1, it_cas2, timeit: '            &
+          ,day,day_ju_ini_cas,it_cas1,it_cas2,timeit
+     stop
+  endif
+
+  ! time interpolation:
+  IF (it_cas1 .EQ. it_cas2) THEN
+     frac=0.
+  ELSE
+     frac=(time_cas2-timeit)/(time_cas2-time_cas1)
+     frac=max(frac,0.0)
+  ENDIF
+
+  lat_prof_cas = lat_cas(it_cas2)                                       &
+       -frac*(lat_cas(it_cas2)-lat_cas(it_cas1)) 
+  sens_prof_cas = sens_cas(it_cas2)                                     &
+       -frac*(sens_cas(it_cas2)-sens_cas(it_cas1))
+  ts_prof_cas = ts_cas(it_cas2)                                         &
+       -frac*(ts_cas(it_cas2)-ts_cas(it_cas1))
+  ustar_prof_cas = ustar_cas(it_cas2)                                   &
+       -frac*(ustar_cas(it_cas2)-ustar_cas(it_cas1))
+
+  do k=1,nlev_cas
+     plev_prof_cas(k) = plev_cas(k,it_cas2)                               &
+          -frac*(plev_cas(k,it_cas2)-plev_cas(k,it_cas1))
+     t_prof_cas(k) = t_cas(k,it_cas2)                               &
+          -frac*(t_cas(k,it_cas2)-t_cas(k,it_cas1))
+     q_prof_cas(k) = q_cas(k,it_cas2)                               &
+          -frac*(q_cas(k,it_cas2)-q_cas(k,it_cas1))
+     u_prof_cas(k) = u_cas(k,it_cas2)                               &
+          -frac*(u_cas(k,it_cas2)-u_cas(k,it_cas1))
+     v_prof_cas(k) = v_cas(k,it_cas2)                               &
+          -frac*(v_cas(k,it_cas2)-v_cas(k,it_cas1))
+     ug_prof_cas(k) = ug_cas(k,it_cas2)                               &
+          -frac*(ug_cas(k,it_cas2)-ug_cas(k,it_cas1))
+     vg_prof_cas(k) = vg_cas(k,it_cas2)                               &
+          -frac*(vg_cas(k,it_cas2)-vg_cas(k,it_cas1))
+     vitw_prof_cas(k) = vitw_cas(k,it_cas2)                               &
+          -frac*(vitw_cas(k,it_cas2)-vitw_cas(k,it_cas1))
+     du_prof_cas(k) = du_cas(k,it_cas2)                                   &
+          -frac*(du_cas(k,it_cas2)-du_cas(k,it_cas1))
+     hu_prof_cas(k) = hu_cas(k,it_cas2)                                   &
+          -frac*(hu_cas(k,it_cas2)-hu_cas(k,it_cas1))
+     vu_prof_cas(k) = vu_cas(k,it_cas2)                                   &
+          -frac*(vu_cas(k,it_cas2)-vu_cas(k,it_cas1))
+     dv_prof_cas(k) = dv_cas(k,it_cas2)                                   &
+          -frac*(dv_cas(k,it_cas2)-dv_cas(k,it_cas1))
+     hv_prof_cas(k) = hv_cas(k,it_cas2)                                   &
+          -frac*(hv_cas(k,it_cas2)-hv_cas(k,it_cas1))
+     vv_prof_cas(k) = vv_cas(k,it_cas2)                                   &
+          -frac*(vv_cas(k,it_cas2)-vv_cas(k,it_cas1))
+     dt_prof_cas(k) = dt_cas(k,it_cas2)                                   &
+          -frac*(dt_cas(k,it_cas2)-dt_cas(k,it_cas1))
+     ht_prof_cas(k) = ht_cas(k,it_cas2)                                   &
+          -frac*(ht_cas(k,it_cas2)-ht_cas(k,it_cas1))
+     vt_prof_cas(k) = vt_cas(k,it_cas2)                                   &
+          -frac*(vt_cas(k,it_cas2)-vt_cas(k,it_cas1))
+     dtrad_prof_cas(k) = dtrad_cas(k,it_cas2)                                   &
+          -frac*(dtrad_cas(k,it_cas2)-dtrad_cas(k,it_cas1))
+     dq_prof_cas(k) = dq_cas(k,it_cas2)                                   &
+          -frac*(dq_cas(k,it_cas2)-dq_cas(k,it_cas1))
+     hq_prof_cas(k) = hq_cas(k,it_cas2)                                   &
+          -frac*(hq_cas(k,it_cas2)-hq_cas(k,it_cas1))
+     vq_prof_cas(k) = vq_cas(k,it_cas2)                                   &
+          -frac*(vq_cas(k,it_cas2)-vq_cas(k,it_cas1))
+     uw_prof_cas(k) = uw_cas(k,it_cas2)                                   &
+          -frac*(uw_cas(k,it_cas2)-uw_cas(k,it_cas1))
+     vw_prof_cas(k) = vw_cas(k,it_cas2)                                   &
+          -frac*(vw_cas(k,it_cas2)-vw_cas(k,it_cas1))
+     q1_prof_cas(k) = q1_cas(k,it_cas2)                                   &
+          -frac*(q1_cas(k,it_cas2)-q1_cas(k,it_cas1))
+     q2_prof_cas(k) = q2_cas(k,it_cas2)                                   &
+          -frac*(q2_cas(k,it_cas2)-q2_cas(k,it_cas1))
+  enddo
+
+  return
+END SUBROUTINE interp_case_time2
 
 !**********************************************************************************************
-        SUBROUTINE interp2_case_time(day,day1,annee_ref                           &
-!    &         ,year_cas,day_cas,nt_cas,pdt_forc,nlev_cas                         &
-     &         ,nt_cas,nlev_cas                                                   &
-     &         ,ts_cas,ps_cas,plev_cas,t_cas,theta_cas,thv_cas,thl_cas            &
-     &         ,qv_cas,ql_cas,qi_cas,u_cas,v_cas                                  &
-     &         ,ug_cas,vg_cas,vitw_cas,omega_cas,du_cas,hu_cas,vu_cas             &
-     &         ,dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dtrad_cas               &
-     &         ,dq_cas,hq_cas,vq_cas,dth_cas,hth_cas,vth_cas                      &
-     &         ,lat_cas,sens_cas,ustar_cas                                        &
-     &         ,uw_cas,vw_cas,q1_cas,q2_cas,tke_cas                               &
-!
-     &         ,ts_prof_cas,plev_prof_cas,t_prof_cas,theta_prof_cas               &
-     &         ,thv_prof_cas,thl_prof_cas,qv_prof_cas,ql_prof_cas,qi_prof_cas     &
-     &         ,u_prof_cas,v_prof_cas,ug_prof_cas,vg_prof_cas                     &
-     &         ,vitw_prof_cas,omega_prof_cas,du_prof_cas,hu_prof_cas,vu_prof_cas  &
-     &         ,dv_prof_cas,hv_prof_cas,vv_prof_cas,dt_prof_cas                   &
-     &         ,ht_prof_cas,vt_prof_cas,dtrad_prof_cas,dq_prof_cas                &
-     &         ,hq_prof_cas,vq_prof_cas,dth_prof_cas,hth_prof_cas,vth_prof_cas    &
-     &         ,lat_prof_cas,sens_prof_cas                                        &
-     &         ,ustar_prof_cas,uw_prof_cas,vw_prof_cas,q1_prof_cas,q2_prof_cas,tke_prof_cas)
-          
-
-        implicit none
-
-!---------------------------------------------------------------------------------------
-! Time interpolation of a 2D field to the timestep corresponding to day
-!
-! day: current julian day (e.g. 717538.2)
-! day1: first day of the simulation
-! nt_cas: total nb of data in the forcing 
-! pdt_cas: total time interval (in sec) between 2 forcing data
-!---------------------------------------------------------------------------------------
+SUBROUTINE interp2_case_time(day,day1,annee_ref                           &
+     !    &         ,year_cas,day_cas,nt_cas,pdt_forc,nlev_cas                         &
+     ,nt_cas,nlev_cas                                                   &
+     ,ts_cas,ps_cas,plev_cas,t_cas,theta_cas,thv_cas,thl_cas            &
+     ,qv_cas,ql_cas,qi_cas,u_cas,v_cas                                  &
+     ,ug_cas,vg_cas,vitw_cas,omega_cas,du_cas,hu_cas,vu_cas             &
+     ,dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dtrad_cas               &
+     ,dq_cas,hq_cas,vq_cas,dth_cas,hth_cas,vth_cas                      &
+     ,lat_cas,sens_cas,ustar_cas                                        &
+     ,uw_cas,vw_cas,q1_cas,q2_cas,tke_cas                               &
+     !
+     ,ts_prof_cas,plev_prof_cas,t_prof_cas,theta_prof_cas               &
+     ,thv_prof_cas,thl_prof_cas,qv_prof_cas,ql_prof_cas,qi_prof_cas     &
+     ,u_prof_cas,v_prof_cas,ug_prof_cas,vg_prof_cas                     &
+     ,vitw_prof_cas,omega_prof_cas,du_prof_cas,hu_prof_cas,vu_prof_cas  &
+     ,dv_prof_cas,hv_prof_cas,vv_prof_cas,dt_prof_cas                   &
+     ,ht_prof_cas,vt_prof_cas,dtrad_prof_cas,dq_prof_cas                &
+     ,hq_prof_cas,vq_prof_cas,dth_prof_cas,hth_prof_cas,vth_prof_cas    &
+     ,lat_prof_cas,sens_prof_cas                                        &
+     ,ustar_prof_cas,uw_prof_cas,vw_prof_cas,q1_prof_cas,q2_prof_cas,tke_prof_cas)
+
+
+  implicit none
+
+  !---------------------------------------------------------------------------------------
+  ! Time interpolation of a 2D field to the timestep corresponding to day
+  !
+  ! day: current julian day (e.g. 717538.2)
+  ! day1: first day of the simulation
+  ! nt_cas: total nb of data in the forcing 
+  ! pdt_cas: total time interval (in sec) between 2 forcing data
+  !---------------------------------------------------------------------------------------
 
 #include "compar1d.h"
 #include "date_cas.h"
 
-! inputs:
-        integer annee_ref
-        integer nt_cas,nlev_cas
-        real day, day1,day_cas
-        real ts_cas(nt_cas),ps_cas(nt_cas)
-        real plev_cas(nlev_cas,nt_cas)
-        real t_cas(nlev_cas,nt_cas),theta_cas(nlev_cas,nt_cas),thv_cas(nlev_cas,nt_cas),thl_cas(nlev_cas,nt_cas)
-        real qv_cas(nlev_cas,nt_cas),ql_cas(nlev_cas,nt_cas),qi_cas(nlev_cas,nt_cas)
-        real u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas)
-        real ug_cas(nlev_cas,nt_cas),vg_cas(nlev_cas,nt_cas)
-        real vitw_cas(nlev_cas,nt_cas),omega_cas(nlev_cas,nt_cas)
-        real du_cas(nlev_cas,nt_cas),hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas)
-        real dv_cas(nlev_cas,nt_cas),hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas)
-        real dt_cas(nlev_cas,nt_cas),ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas)
-        real dth_cas(nlev_cas,nt_cas),hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas)
-        real dtrad_cas(nlev_cas,nt_cas)
-        real dq_cas(nlev_cas,nt_cas),hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas)
-        real lat_cas(nt_cas),sens_cas(nt_cas),tke_cas(nt_cas)
-        real ustar_cas(nt_cas),uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas)
-        real q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas)
-
-! outputs:
-        real plev_prof_cas(nlev_cas)
-        real t_prof_cas(nlev_cas),theta_prof_cas(nlev_cas),thl_prof_cas(nlev_cas),thv_prof_cas(nlev_cas)
-        real qv_prof_cas(nlev_cas),ql_prof_cas(nlev_cas),qi_prof_cas(nlev_cas)
-        real u_prof_cas(nlev_cas),v_prof_cas(nlev_cas)
-        real ug_prof_cas(nlev_cas),vg_prof_cas(nlev_cas)
-        real vitw_prof_cas(nlev_cas),omega_prof_cas(nlev_cas)
-        real du_prof_cas(nlev_cas),hu_prof_cas(nlev_cas),vu_prof_cas(nlev_cas)
-        real dv_prof_cas(nlev_cas),hv_prof_cas(nlev_cas),vv_prof_cas(nlev_cas)
-        real dt_prof_cas(nlev_cas),ht_prof_cas(nlev_cas),vt_prof_cas(nlev_cas)
-        real dth_prof_cas(nlev_cas),hth_prof_cas(nlev_cas),vth_prof_cas(nlev_cas)
-        real dtrad_prof_cas(nlev_cas)
-        real dq_prof_cas(nlev_cas),hq_prof_cas(nlev_cas),vq_prof_cas(nlev_cas)
-        real lat_prof_cas,sens_prof_cas,tke_prof_cas,ts_prof_cas,ustar_prof_cas
-        real uw_prof_cas(nlev_cas),vw_prof_cas(nlev_cas),q1_prof_cas(nlev_cas),q2_prof_cas(nlev_cas)
-! local:
-        integer it_cas1, it_cas2,k
-        real timeit,time_cas1,time_cas2,frac
-
-
-        print*,'Check time',day1,day_ju_ini_cas,day_deb+1,pdt_cas
-!       do k=1,nlev_cas
-!       print*,'debut de interp2_case_time, plev_cas=',k,plev_cas(k,1)
-!       enddo
-
-! On teste si la date du cas AMMA est correcte.
-! C est pour memoire car en fait les fichiers .def
-! sont censes etre corrects.
-! A supprimer a terme (MPL 20150623)
-!     if ((forcing_type.eq.10).and.(1.eq.0)) then
-! Check that initial day of the simulation consistent with AMMA case:
-!      if (annee_ref.ne.2006) then
-!       print*,'Pour AMMA, annee_ref doit etre 2006'
-!       print*,'Changer annee_ref dans run.def'
-!       stop
-!      endif
-!      if (annee_ref.eq.2006 .and. day1.lt.day_cas) then
-!       print*,'AMMA a debute le 10 juillet 2006',day1,day_cas
-!       print*,'Changer dayref dans run.def'
-!       stop
-!      endif
-!      if (annee_ref.eq.2006 .and. day1.gt.day_cas+1) then
-!       print*,'AMMA a fini le 11 juillet'
-!       print*,'Changer dayref ou nday dans run.def'
-!       stop
-!      endif
-!      endif
-
-! Determine timestep relative to the 1st day:
-!       timeit=(day-day1)*86400.
-!       if (annee_ref.eq.1992) then
-!        timeit=(day-day_cas)*86400.
-!       else
-!        timeit=(day+61.-1.)*86400. ! 61 days between Nov01 and Dec31 1992
-!       endif
-      timeit=(day-day_ju_ini_cas)*86400
-      print *,'day=',day
-      print *,'day_ju_ini_cas=',day_ju_ini_cas
-      print *,'pdt_cas=',pdt_cas
-      print *,'timeit=',timeit
-      print *,'nt_cas=',nt_cas
-
-! Determine the closest observation times:
-!       it_cas1=INT(timeit/pdt_cas)+1
-!       it_cas2=it_cas1 + 1
-!       time_cas1=(it_cas1-1)*pdt_cas
-!       time_cas2=(it_cas2-1)*pdt_cas
-
-       it_cas1=INT(timeit/pdt_cas)+1
-       IF (it_cas1 .EQ. nt_cas) THEN
-       it_cas2=it_cas1 
-       ELSE
-       it_cas2=it_cas1 + 1
-       ENDIF
-       time_cas1=(it_cas1-1)*pdt_cas
-       time_cas2=(it_cas2-1)*pdt_cas
-      print *,'timeit,pdt_cas,nt_cas=',timeit,pdt_cas,nt_cas
-      print *,'it_cas1,it_cas2,time_cas1,time_cas2=',it_cas1,it_cas2,time_cas1,time_cas2
-
-       if (it_cas1 .gt. nt_cas) then 
-        write(*,*) 'PB-stop: day, day_ju_ini_cas,it_cas1, it_cas2, timeit: '            &
-     &        ,day,day_ju_ini_cas,it_cas1,it_cas2,timeit
-        stop
-       endif
-
-! time interpolation:
-       IF (it_cas1 .EQ. it_cas2) THEN
-          frac=0.
-       ELSE
-          frac=(time_cas2-timeit)/(time_cas2-time_cas1)
-          frac=max(frac,0.0)
-       ENDIF
-
-       lat_prof_cas = lat_cas(it_cas2)                                   &
-     &          -frac*(lat_cas(it_cas2)-lat_cas(it_cas1)) 
-       sens_prof_cas = sens_cas(it_cas2)                                 &
-     &          -frac*(sens_cas(it_cas2)-sens_cas(it_cas1))
-       tke_prof_cas = tke_cas(it_cas2)                                   &
-     &          -frac*(tke_cas(it_cas2)-tke_cas(it_cas1))
-       ts_prof_cas = ts_cas(it_cas2)                                     &
-     &          -frac*(ts_cas(it_cas2)-ts_cas(it_cas1))
-       ustar_prof_cas = ustar_cas(it_cas2)                               &
-     &          -frac*(ustar_cas(it_cas2)-ustar_cas(it_cas1))
-
-       do k=1,nlev_cas
-        plev_prof_cas(k) = plev_cas(k,it_cas2)                           &     
-     &          -frac*(plev_cas(k,it_cas2)-plev_cas(k,it_cas1))
-        t_prof_cas(k) = t_cas(k,it_cas2)                                 &        
-     &          -frac*(t_cas(k,it_cas2)-t_cas(k,it_cas1))
-        print *,'k,frac,plev_cas1,plev_cas2=',k,frac,plev_cas(k,it_cas1),plev_cas(k,it_cas2)
-        theta_prof_cas(k) = theta_cas(k,it_cas2)                         &                      
-     &          -frac*(theta_cas(k,it_cas2)-theta_cas(k,it_cas1))
-        thv_prof_cas(k) = thv_cas(k,it_cas2)                             &          
-     &          -frac*(thv_cas(k,it_cas2)-thv_cas(k,it_cas1))
-        thl_prof_cas(k) = thl_cas(k,it_cas2)                             &              
-     &          -frac*(thl_cas(k,it_cas2)-thl_cas(k,it_cas1))
-        qv_prof_cas(k) = qv_cas(k,it_cas2)                               &
-     &          -frac*(qv_cas(k,it_cas2)-qv_cas(k,it_cas1))
-        ql_prof_cas(k) = ql_cas(k,it_cas2)                               &
-     &          -frac*(ql_cas(k,it_cas2)-ql_cas(k,it_cas1))
-        qi_prof_cas(k) = qi_cas(k,it_cas2)                               &
-     &          -frac*(qi_cas(k,it_cas2)-qi_cas(k,it_cas1))
-        u_prof_cas(k) = u_cas(k,it_cas2)                                 &
-     &          -frac*(u_cas(k,it_cas2)-u_cas(k,it_cas1))
-        v_prof_cas(k) = v_cas(k,it_cas2)                                 &
-     &          -frac*(v_cas(k,it_cas2)-v_cas(k,it_cas1))
-        ug_prof_cas(k) = ug_cas(k,it_cas2)                               &
-     &          -frac*(ug_cas(k,it_cas2)-ug_cas(k,it_cas1))
-        vg_prof_cas(k) = vg_cas(k,it_cas2)                               &
-     &          -frac*(vg_cas(k,it_cas2)-vg_cas(k,it_cas1))
-        vitw_prof_cas(k) = vitw_cas(k,it_cas2)                           &
-     &          -frac*(vitw_cas(k,it_cas2)-vitw_cas(k,it_cas1))
-        omega_prof_cas(k) = omega_cas(k,it_cas2)                         &
-     &          -frac*(omega_cas(k,it_cas2)-omega_cas(k,it_cas1))
-        du_prof_cas(k) = du_cas(k,it_cas2)                               &
-     &          -frac*(du_cas(k,it_cas2)-du_cas(k,it_cas1))
-        hu_prof_cas(k) = hu_cas(k,it_cas2)                               &
-     &          -frac*(hu_cas(k,it_cas2)-hu_cas(k,it_cas1))
-        vu_prof_cas(k) = vu_cas(k,it_cas2)                               &
-     &          -frac*(vu_cas(k,it_cas2)-vu_cas(k,it_cas1))
-        dv_prof_cas(k) = dv_cas(k,it_cas2)                               &
-     &          -frac*(dv_cas(k,it_cas2)-dv_cas(k,it_cas1))
-        hv_prof_cas(k) = hv_cas(k,it_cas2)                               &
-     &          -frac*(hv_cas(k,it_cas2)-hv_cas(k,it_cas1))
-        vv_prof_cas(k) = vv_cas(k,it_cas2)                               &
-     &          -frac*(vv_cas(k,it_cas2)-vv_cas(k,it_cas1))
-        dt_prof_cas(k) = dt_cas(k,it_cas2)                               &
-     &          -frac*(dt_cas(k,it_cas2)-dt_cas(k,it_cas1))
-        ht_prof_cas(k) = ht_cas(k,it_cas2)                               &
-     &          -frac*(ht_cas(k,it_cas2)-ht_cas(k,it_cas1))
-        vt_prof_cas(k) = vt_cas(k,it_cas2)                               &
-     &          -frac*(vt_cas(k,it_cas2)-vt_cas(k,it_cas1))
-        dth_prof_cas(k) = dth_cas(k,it_cas2)                             &
-     &          -frac*(dth_cas(k,it_cas2)-dth_cas(k,it_cas1))
-        hth_prof_cas(k) = hth_cas(k,it_cas2)                             &
-     &          -frac*(hth_cas(k,it_cas2)-hth_cas(k,it_cas1))
-        vth_prof_cas(k) = vth_cas(k,it_cas2)                             &
-     &          -frac*(vth_cas(k,it_cas2)-vth_cas(k,it_cas1))
-        dtrad_prof_cas(k) = dtrad_cas(k,it_cas2)                         &
-     &          -frac*(dtrad_cas(k,it_cas2)-dtrad_cas(k,it_cas1))
-        dq_prof_cas(k) = dq_cas(k,it_cas2)                               &
-     &          -frac*(dq_cas(k,it_cas2)-dq_cas(k,it_cas1))
-        hq_prof_cas(k) = hq_cas(k,it_cas2)                               &
-     &          -frac*(hq_cas(k,it_cas2)-hq_cas(k,it_cas1))
-        vq_prof_cas(k) = vq_cas(k,it_cas2)                               &
-     &          -frac*(vq_cas(k,it_cas2)-vq_cas(k,it_cas1))
-       uw_prof_cas(k) = uw_cas(k,it_cas2)                                &
-     &          -frac*(uw_cas(k,it_cas2)-uw_cas(k,it_cas1))
-       vw_prof_cas(k) = vw_cas(k,it_cas2)                                &
-     &          -frac*(vw_cas(k,it_cas2)-vw_cas(k,it_cas1))
-       q1_prof_cas(k) = q1_cas(k,it_cas2)                                &
-     &          -frac*(q1_cas(k,it_cas2)-q1_cas(k,it_cas1))
-       q2_prof_cas(k) = q2_cas(k,it_cas2)                                &
-     &          -frac*(q2_cas(k,it_cas2)-q2_cas(k,it_cas1))
-        enddo
-
-        return
-        END SUBROUTINE interp2_case_time
+  ! inputs:
+  integer annee_ref
+  integer nt_cas,nlev_cas
+  real day, day1,day_cas
+  real ts_cas(nt_cas),ps_cas(nt_cas)
+  real plev_cas(nlev_cas,nt_cas)
+  real t_cas(nlev_cas,nt_cas),theta_cas(nlev_cas,nt_cas),thv_cas(nlev_cas,nt_cas),thl_cas(nlev_cas,nt_cas)
+  real qv_cas(nlev_cas,nt_cas),ql_cas(nlev_cas,nt_cas),qi_cas(nlev_cas,nt_cas)
+  real u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas)
+  real ug_cas(nlev_cas,nt_cas),vg_cas(nlev_cas,nt_cas)
+  real vitw_cas(nlev_cas,nt_cas),omega_cas(nlev_cas,nt_cas)
+  real du_cas(nlev_cas,nt_cas),hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas)
+  real dv_cas(nlev_cas,nt_cas),hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas)
+  real dt_cas(nlev_cas,nt_cas),ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas)
+  real dth_cas(nlev_cas,nt_cas),hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas)
+  real dtrad_cas(nlev_cas,nt_cas)
+  real dq_cas(nlev_cas,nt_cas),hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas)
+  real lat_cas(nt_cas),sens_cas(nt_cas),tke_cas(nt_cas)
+  real ustar_cas(nt_cas),uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas)
+  real q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas)
+
+  ! outputs:
+  real plev_prof_cas(nlev_cas)
+  real t_prof_cas(nlev_cas),theta_prof_cas(nlev_cas),thl_prof_cas(nlev_cas),thv_prof_cas(nlev_cas)
+  real qv_prof_cas(nlev_cas),ql_prof_cas(nlev_cas),qi_prof_cas(nlev_cas)
+  real u_prof_cas(nlev_cas),v_prof_cas(nlev_cas)
+  real ug_prof_cas(nlev_cas),vg_prof_cas(nlev_cas)
+  real vitw_prof_cas(nlev_cas),omega_prof_cas(nlev_cas)
+  real du_prof_cas(nlev_cas),hu_prof_cas(nlev_cas),vu_prof_cas(nlev_cas)
+  real dv_prof_cas(nlev_cas),hv_prof_cas(nlev_cas),vv_prof_cas(nlev_cas)
+  real dt_prof_cas(nlev_cas),ht_prof_cas(nlev_cas),vt_prof_cas(nlev_cas)
+  real dth_prof_cas(nlev_cas),hth_prof_cas(nlev_cas),vth_prof_cas(nlev_cas)
+  real dtrad_prof_cas(nlev_cas)
+  real dq_prof_cas(nlev_cas),hq_prof_cas(nlev_cas),vq_prof_cas(nlev_cas)
+  real lat_prof_cas,sens_prof_cas,tke_prof_cas,ts_prof_cas,ustar_prof_cas
+  real uw_prof_cas(nlev_cas),vw_prof_cas(nlev_cas),q1_prof_cas(nlev_cas),q2_prof_cas(nlev_cas)
+  ! local:
+  integer it_cas1, it_cas2,k
+  real timeit,time_cas1,time_cas2,frac
+
+
+  print*,'Check time',day1,day_ju_ini_cas,day_deb+1,pdt_cas
+  !       do k=1,nlev_cas
+  !       print*,'debut de interp2_case_time, plev_cas=',k,plev_cas(k,1)
+  !       enddo
+
+  ! On teste si la date du cas AMMA est correcte.
+  ! C est pour memoire car en fait les fichiers .def
+  ! sont censes etre corrects.
+  ! A supprimer a terme (MPL 20150623)
+  !     if ((forcing_type.eq.10).and.(1.eq.0)) then
+  ! Check that initial day of the simulation consistent with AMMA case:
+  !      if (annee_ref.ne.2006) then
+  !       print*,'Pour AMMA, annee_ref doit etre 2006'
+  !       print*,'Changer annee_ref dans run.def'
+  !       stop
+  !      endif
+  !      if (annee_ref.eq.2006 .and. day1.lt.day_cas) then
+  !       print*,'AMMA a debute le 10 juillet 2006',day1,day_cas
+  !       print*,'Changer dayref dans run.def'
+  !       stop
+  !      endif
+  !      if (annee_ref.eq.2006 .and. day1.gt.day_cas+1) then
+  !       print*,'AMMA a fini le 11 juillet'
+  !       print*,'Changer dayref ou nday dans run.def'
+  !       stop
+  !      endif
+  !      endif
+
+  ! Determine timestep relative to the 1st day:
+  !       timeit=(day-day1)*86400.
+  !       if (annee_ref.eq.1992) then
+  !        timeit=(day-day_cas)*86400.
+  !       else
+  !        timeit=(day+61.-1.)*86400. ! 61 days between Nov01 and Dec31 1992
+  !       endif
+  timeit=(day-day_ju_ini_cas)*86400
+  print *,'day=',day
+  print *,'day_ju_ini_cas=',day_ju_ini_cas
+  print *,'pdt_cas=',pdt_cas
+  print *,'timeit=',timeit
+  print *,'nt_cas=',nt_cas
+
+  ! Determine the closest observation times:
+  !       it_cas1=INT(timeit/pdt_cas)+1
+  !       it_cas2=it_cas1 + 1
+  !       time_cas1=(it_cas1-1)*pdt_cas
+  !       time_cas2=(it_cas2-1)*pdt_cas
+
+  it_cas1=INT(timeit/pdt_cas)+1
+  IF (it_cas1 .EQ. nt_cas) THEN
+     it_cas2=it_cas1 
+  ELSE
+     it_cas2=it_cas1 + 1
+  ENDIF
+  time_cas1=(it_cas1-1)*pdt_cas
+  time_cas2=(it_cas2-1)*pdt_cas
+  print *,'timeit,pdt_cas,nt_cas=',timeit,pdt_cas,nt_cas
+  print *,'it_cas1,it_cas2,time_cas1,time_cas2=',it_cas1,it_cas2,time_cas1,time_cas2
+
+  if (it_cas1 .gt. nt_cas) then 
+     write(*,*) 'PB-stop: day, day_ju_ini_cas,it_cas1, it_cas2, timeit: '            &
+          ,day,day_ju_ini_cas,it_cas1,it_cas2,timeit
+     stop
+  endif
+
+  ! time interpolation:
+  IF (it_cas1 .EQ. it_cas2) THEN
+     frac=0.
+  ELSE
+     frac=(time_cas2-timeit)/(time_cas2-time_cas1)
+     frac=max(frac,0.0)
+  ENDIF
+
+  lat_prof_cas = lat_cas(it_cas2)                                   &
+       -frac*(lat_cas(it_cas2)-lat_cas(it_cas1)) 
+  sens_prof_cas = sens_cas(it_cas2)                                 &
+       -frac*(sens_cas(it_cas2)-sens_cas(it_cas1))
+  tke_prof_cas = tke_cas(it_cas2)                                   &
+       -frac*(tke_cas(it_cas2)-tke_cas(it_cas1))
+  ts_prof_cas = ts_cas(it_cas2)                                     &
+       -frac*(ts_cas(it_cas2)-ts_cas(it_cas1))
+  ustar_prof_cas = ustar_cas(it_cas2)                               &
+       -frac*(ustar_cas(it_cas2)-ustar_cas(it_cas1))
+
+  do k=1,nlev_cas
+     plev_prof_cas(k) = plev_cas(k,it_cas2)                           &     
+          -frac*(plev_cas(k,it_cas2)-plev_cas(k,it_cas1))
+     t_prof_cas(k) = t_cas(k,it_cas2)                                 &        
+          -frac*(t_cas(k,it_cas2)-t_cas(k,it_cas1))
+     print *,'k,frac,plev_cas1,plev_cas2=',k,frac,plev_cas(k,it_cas1),plev_cas(k,it_cas2)
+     theta_prof_cas(k) = theta_cas(k,it_cas2)                         &                      
+          -frac*(theta_cas(k,it_cas2)-theta_cas(k,it_cas1))
+     thv_prof_cas(k) = thv_cas(k,it_cas2)                             &          
+          -frac*(thv_cas(k,it_cas2)-thv_cas(k,it_cas1))
+     thl_prof_cas(k) = thl_cas(k,it_cas2)                             &              
+          -frac*(thl_cas(k,it_cas2)-thl_cas(k,it_cas1))
+     qv_prof_cas(k) = qv_cas(k,it_cas2)                               &
+          -frac*(qv_cas(k,it_cas2)-qv_cas(k,it_cas1))
+     ql_prof_cas(k) = ql_cas(k,it_cas2)                               &
+          -frac*(ql_cas(k,it_cas2)-ql_cas(k,it_cas1))
+     qi_prof_cas(k) = qi_cas(k,it_cas2)                               &
+          -frac*(qi_cas(k,it_cas2)-qi_cas(k,it_cas1))
+     u_prof_cas(k) = u_cas(k,it_cas2)                                 &
+          -frac*(u_cas(k,it_cas2)-u_cas(k,it_cas1))
+     v_prof_cas(k) = v_cas(k,it_cas2)                                 &
+          -frac*(v_cas(k,it_cas2)-v_cas(k,it_cas1))
+     ug_prof_cas(k) = ug_cas(k,it_cas2)                               &
+          -frac*(ug_cas(k,it_cas2)-ug_cas(k,it_cas1))
+     vg_prof_cas(k) = vg_cas(k,it_cas2)                               &
+          -frac*(vg_cas(k,it_cas2)-vg_cas(k,it_cas1))
+     vitw_prof_cas(k) = vitw_cas(k,it_cas2)                           &
+          -frac*(vitw_cas(k,it_cas2)-vitw_cas(k,it_cas1))
+     omega_prof_cas(k) = omega_cas(k,it_cas2)                         &
+          -frac*(omega_cas(k,it_cas2)-omega_cas(k,it_cas1))
+     du_prof_cas(k) = du_cas(k,it_cas2)                               &
+          -frac*(du_cas(k,it_cas2)-du_cas(k,it_cas1))
+     hu_prof_cas(k) = hu_cas(k,it_cas2)                               &
+          -frac*(hu_cas(k,it_cas2)-hu_cas(k,it_cas1))
+     vu_prof_cas(k) = vu_cas(k,it_cas2)                               &
+          -frac*(vu_cas(k,it_cas2)-vu_cas(k,it_cas1))
+     dv_prof_cas(k) = dv_cas(k,it_cas2)                               &
+          -frac*(dv_cas(k,it_cas2)-dv_cas(k,it_cas1))
+     hv_prof_cas(k) = hv_cas(k,it_cas2)                               &
+          -frac*(hv_cas(k,it_cas2)-hv_cas(k,it_cas1))
+     vv_prof_cas(k) = vv_cas(k,it_cas2)                               &
+          -frac*(vv_cas(k,it_cas2)-vv_cas(k,it_cas1))
+     dt_prof_cas(k) = dt_cas(k,it_cas2)                               &
+          -frac*(dt_cas(k,it_cas2)-dt_cas(k,it_cas1))
+     ht_prof_cas(k) = ht_cas(k,it_cas2)                               &
+          -frac*(ht_cas(k,it_cas2)-ht_cas(k,it_cas1))
+     vt_prof_cas(k) = vt_cas(k,it_cas2)                               &
+          -frac*(vt_cas(k,it_cas2)-vt_cas(k,it_cas1))
+     dth_prof_cas(k) = dth_cas(k,it_cas2)                             &
+          -frac*(dth_cas(k,it_cas2)-dth_cas(k,it_cas1))
+     hth_prof_cas(k) = hth_cas(k,it_cas2)                             &
+          -frac*(hth_cas(k,it_cas2)-hth_cas(k,it_cas1))
+     vth_prof_cas(k) = vth_cas(k,it_cas2)                             &
+          -frac*(vth_cas(k,it_cas2)-vth_cas(k,it_cas1))
+     dtrad_prof_cas(k) = dtrad_cas(k,it_cas2)                         &
+          -frac*(dtrad_cas(k,it_cas2)-dtrad_cas(k,it_cas1))
+     dq_prof_cas(k) = dq_cas(k,it_cas2)                               &
+          -frac*(dq_cas(k,it_cas2)-dq_cas(k,it_cas1))
+     hq_prof_cas(k) = hq_cas(k,it_cas2)                               &
+          -frac*(hq_cas(k,it_cas2)-hq_cas(k,it_cas1))
+     vq_prof_cas(k) = vq_cas(k,it_cas2)                               &
+          -frac*(vq_cas(k,it_cas2)-vq_cas(k,it_cas1))
+     uw_prof_cas(k) = uw_cas(k,it_cas2)                                &
+          -frac*(uw_cas(k,it_cas2)-uw_cas(k,it_cas1))
+     vw_prof_cas(k) = vw_cas(k,it_cas2)                                &
+          -frac*(vw_cas(k,it_cas2)-vw_cas(k,it_cas1))
+     q1_prof_cas(k) = q1_cas(k,it_cas2)                                &
+          -frac*(q1_cas(k,it_cas2)-q1_cas(k,it_cas1))
+     q2_prof_cas(k) = q2_cas(k,it_cas2)                                &
+          -frac*(q2_cas(k,it_cas2)-q2_cas(k,it_cas1))
+  enddo
+
+  return
+END SUBROUTINE interp2_case_time
 
 !**********************************************************************************************
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/mod_1D_cases_read_std.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/mod_1D_cases_read_std.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/mod_1D_cases_read_std.F90	(revision 4482)
@@ -5,79 +5,79 @@
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!Declarations specifiques au cas standard
-        character*80 :: fich_cas
-! Discr?tisation 
-        integer nlev_cas, nt_cas
-
-
-!profils environnementaux
-        real, allocatable::  plev_cas(:,:),plevh_cas(:)
-        real, allocatable::  ap_cas(:),bp_cas(:)
-
-        real, allocatable::  z_cas(:,:),zh_cas(:)
-        real, allocatable::  t_cas(:,:),q_cas(:,:),qv_cas(:,:),ql_cas(:,:),qi_cas(:,:),rh_cas(:,:)
-        real, allocatable::  th_cas(:,:),thv_cas(:,:),thl_cas(:,:),rv_cas(:,:)
-        real, allocatable::  u_cas(:,:),v_cas(:,:),vitw_cas(:,:),omega_cas(:,:),tke_cas(:,:)
-
-!forcing
-        real, allocatable::  ht_cas(:,:),vt_cas(:,:),dt_cas(:,:),dtrad_cas(:,:)
-        real, allocatable::  hth_cas(:,:),vth_cas(:,:),dth_cas(:,:)
-        real, allocatable::  hq_cas(:,:),vq_cas(:,:),dq_cas(:,:)
-        real, allocatable::  hr_cas(:,:),vr_cas(:,:),dr_cas(:,:)
-        real, allocatable::  hu_cas(:,:),vu_cas(:,:),du_cas(:,:)
-        real, allocatable::  hv_cas(:,:),vv_cas(:,:),dv_cas(:,:)
-        real, allocatable::  ug_cas(:,:),vg_cas(:,:)
-        real, allocatable::  temp_nudg_cas(:,:),qv_nudg_cas(:,:),u_nudg_cas(:,:),v_nudg_cas(:,:)
-        real, allocatable::  invtau_temp_nudg_cas(:,:),invtau_qv_nudg_cas(:,:),invtau_u_nudg_cas(:,:),invtau_v_nudg_cas(:,:)
-        real, allocatable::  lat_cas(:),sens_cas(:),ts_cas(:),ps_cas(:),ustar_cas(:)
-        real, allocatable::  uw_cas(:,:),vw_cas(:,:),q1_cas(:,:),q2_cas(:,:),tkes_cas(:)
-
-!champs interpoles
-        real, allocatable::  plev_prof_cas(:)
-        real, allocatable::  t_prof_cas(:)
-        real, allocatable::  theta_prof_cas(:)
-        real, allocatable::  thl_prof_cas(:)
-        real, allocatable::  thv_prof_cas(:)
-        real, allocatable::  q_prof_cas(:)
-        real, allocatable::  qv_prof_cas(:)
-        real, allocatable::  ql_prof_cas(:)
-        real, allocatable::  qi_prof_cas(:)
-        real, allocatable::  rh_prof_cas(:)
-        real, allocatable::  rv_prof_cas(:)
-        real, allocatable::  u_prof_cas(:)
-        real, allocatable::  v_prof_cas(:)        
-        real, allocatable::  vitw_prof_cas(:)
-        real, allocatable::  omega_prof_cas(:)
-        real, allocatable::  tke_prof_cas(:)
-        real, allocatable::  ug_prof_cas(:)
-        real, allocatable::  vg_prof_cas(:)
-        real, allocatable::  temp_nudg_prof_cas(:),qv_nudg_prof_cas(:),u_nudg_prof_cas(:),v_nudg_prof_cas(:)
-        real, allocatable::  invtau_temp_nudg_prof_cas(:),invtau_qv_nudg_prof_cas(:),invtau_u_nudg_prof_cas(:),invtau_v_nudg_prof_cas(:)
-
-        real, allocatable::  ht_prof_cas(:)
-        real, allocatable::  hth_prof_cas(:)
-        real, allocatable::  hq_prof_cas(:)
-        real, allocatable::  vt_prof_cas(:)
-        real, allocatable::  vth_prof_cas(:)
-        real, allocatable::  vq_prof_cas(:)
-        real, allocatable::  dt_prof_cas(:)
-        real, allocatable::  dth_prof_cas(:)
-        real, allocatable::  dtrad_prof_cas(:)
-        real, allocatable::  dq_prof_cas(:)
-        real, allocatable::  hu_prof_cas(:)
-        real, allocatable::  hv_prof_cas(:)
-        real, allocatable::  vu_prof_cas(:)
-        real, allocatable::  vv_prof_cas(:)
-        real, allocatable::  du_prof_cas(:)
-        real, allocatable::  dv_prof_cas(:)
-        real, allocatable::  uw_prof_cas(:)
-        real, allocatable::  vw_prof_cas(:)
-        real, allocatable::  q1_prof_cas(:)
-        real, allocatable::  q2_prof_cas(:)
-
-
-        real o3_cas,lat_prof_cas,sens_prof_cas,ts_prof_cas,ps_prof_cas,ustar_prof_cas,tkes_prof_cas
-        real orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough,rugos_cas,sand_cas,clay_cas
-      
+  !Declarations specifiques au cas standard
+  character*80 :: fich_cas
+  ! Discr?tisation 
+  integer nlev_cas, nt_cas
+
+
+  !profils environnementaux
+  real, allocatable::  plev_cas(:,:),plevh_cas(:)
+  real, allocatable::  ap_cas(:),bp_cas(:)
+
+  real, allocatable::  z_cas(:,:),zh_cas(:)
+  real, allocatable::  t_cas(:,:),q_cas(:,:),qv_cas(:,:),ql_cas(:,:),qi_cas(:,:),rh_cas(:,:)
+  real, allocatable::  th_cas(:,:),thv_cas(:,:),thl_cas(:,:),rv_cas(:,:)
+  real, allocatable::  u_cas(:,:),v_cas(:,:),vitw_cas(:,:),omega_cas(:,:),tke_cas(:,:)
+
+  !forcing
+  real, allocatable::  ht_cas(:,:),vt_cas(:,:),dt_cas(:,:),dtrad_cas(:,:)
+  real, allocatable::  hth_cas(:,:),vth_cas(:,:),dth_cas(:,:)
+  real, allocatable::  hq_cas(:,:),vq_cas(:,:),dq_cas(:,:)
+  real, allocatable::  hr_cas(:,:),vr_cas(:,:),dr_cas(:,:)
+  real, allocatable::  hu_cas(:,:),vu_cas(:,:),du_cas(:,:)
+  real, allocatable::  hv_cas(:,:),vv_cas(:,:),dv_cas(:,:)
+  real, allocatable::  ug_cas(:,:),vg_cas(:,:)
+  real, allocatable::  temp_nudg_cas(:,:),qv_nudg_cas(:,:),u_nudg_cas(:,:),v_nudg_cas(:,:)
+  real, allocatable::  invtau_temp_nudg_cas(:,:),invtau_qv_nudg_cas(:,:),invtau_u_nudg_cas(:,:),invtau_v_nudg_cas(:,:)
+  real, allocatable::  lat_cas(:),sens_cas(:),tskin_cas(:),ts_cas(:),ps_cas(:),ustar_cas(:)
+  real, allocatable::  uw_cas(:,:),vw_cas(:,:),q1_cas(:,:),q2_cas(:,:),tkes_cas(:)
+
+  !champs interpoles
+  real, allocatable::  plev_prof_cas(:)
+  real, allocatable::  t_prof_cas(:)
+  real, allocatable::  theta_prof_cas(:)
+  real, allocatable::  thl_prof_cas(:)
+  real, allocatable::  thv_prof_cas(:)
+  real, allocatable::  q_prof_cas(:)
+  real, allocatable::  qv_prof_cas(:)
+  real, allocatable::  ql_prof_cas(:)
+  real, allocatable::  qi_prof_cas(:)
+  real, allocatable::  rh_prof_cas(:)
+  real, allocatable::  rv_prof_cas(:)
+  real, allocatable::  u_prof_cas(:)
+  real, allocatable::  v_prof_cas(:)        
+  real, allocatable::  vitw_prof_cas(:)
+  real, allocatable::  omega_prof_cas(:)
+  real, allocatable::  tke_prof_cas(:)
+  real, allocatable::  ug_prof_cas(:)
+  real, allocatable::  vg_prof_cas(:)
+  real, allocatable::  temp_nudg_prof_cas(:),qv_nudg_prof_cas(:),u_nudg_prof_cas(:),v_nudg_prof_cas(:)
+  real, allocatable::  invtau_temp_nudg_prof_cas(:),invtau_qv_nudg_prof_cas(:),invtau_u_nudg_prof_cas(:),invtau_v_nudg_prof_cas(:)
+
+  real, allocatable::  ht_prof_cas(:)
+  real, allocatable::  hth_prof_cas(:)
+  real, allocatable::  hq_prof_cas(:)
+  real, allocatable::  vt_prof_cas(:)
+  real, allocatable::  vth_prof_cas(:)
+  real, allocatable::  vq_prof_cas(:)
+  real, allocatable::  dt_prof_cas(:)
+  real, allocatable::  dth_prof_cas(:)
+  real, allocatable::  dtrad_prof_cas(:)
+  real, allocatable::  dq_prof_cas(:)
+  real, allocatable::  hu_prof_cas(:)
+  real, allocatable::  hv_prof_cas(:)
+  real, allocatable::  vu_prof_cas(:)
+  real, allocatable::  vv_prof_cas(:)
+  real, allocatable::  du_prof_cas(:)
+  real, allocatable::  dv_prof_cas(:)
+  real, allocatable::  uw_prof_cas(:)
+  real, allocatable::  vw_prof_cas(:)
+  real, allocatable::  q1_prof_cas(:)
+  real, allocatable::  q2_prof_cas(:)
+
+
+  real o3_cas,lat_prof_cas,sens_prof_cas,ts_prof_cas,tskin_prof_cas,ps_prof_cas,ustar_prof_cas,tkes_prof_cas
+  real orog_cas,albedo_cas,emiss_cas,q_skin_cas,mom_rough,heat_rough,rugos_cas,sand_cas,clay_cas
+
 
 
@@ -85,1148 +85,1131 @@
 
 
-!**********************************************************************************************
-SUBROUTINE read_SCM_cas
-      implicit none
+  !**********************************************************************************************
+  SUBROUTINE read_SCM_cas
+    use netcdf, only: nf90_get_var
+    implicit none
 
 #include "netcdf.inc"
 #include "date_cas.h"
 
-      INTEGER nid,rid,ierr
-      INTEGER ii,jj,timeid
-      REAL, ALLOCATABLE :: time_val(:)
-
-      fich_cas='cas.nc'
-      print*,'fich_cas ',fich_cas
-      ierr = NF_OPEN(fich_cas,NF_NOWRITE,nid)
-      print*,'fich_cas,NF_NOWRITE,nid ',fich_cas,NF_NOWRITE,nid
-      if (ierr.NE.NF_NOERR) then
-         write(*,*) 'ERROR: GROS Pb opening forcings nc file '
-         write(*,*) NF_STRERROR(ierr)
-         stop ""
-      endif
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'lat',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension lat'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,ii)
-      print*,'OK1 read2: nid,rid,lat',nid,rid,ii
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'lon',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension lon'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,jj)
-      print*,'OK2 read2: nid,rid,lat',nid,rid,jj
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'lev',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension nlev'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,nlev_cas)
-      print*,'OK3 read2: nid,rid,nlev_cas',nid,rid,nlev_cas
-      IF ( .NOT. ( nlev_cas > 10 .AND. nlev_cas < 200000 )) THEN
-              print*,'Valeur de nlev_cas peu probable'
-              STOP
-      ENDIF
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'time',rid)
-      nt_cas=0
-      IF (ierr.NE.NF_NOERR) THEN
-        stop 'Oh probleme lecture dimension time'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,nt_cas)
-      print*,'OK4 read2: nid,rid,nt_cas',nid,rid,nt_cas
-! Lecture de l'axe des temps
-      print*,'LECTURE DU TEMPS'
-      ierr=NF_INQ_VARID(nid,'time',timeid)
-         if(ierr/=NF_NOERR) then
-           print *,'Variable time manquante dans cas.nc:'
-           ierr=NF_NOERR
-         else
-                 allocate(time_val(nt_cas))
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,timeid,time_val)
-#else
-           ierr = NF_GET_VAR_REAL(nid,timeid,time_val)
-#endif
-           if(ierr/=NF_NOERR) then
-              print *,'Pb a la lecture de time cas.nc: '
-           endif
-   endif
-   IF (nt_cas>1) THEN
-           pdt_cas=time_val(2)-time_val(1)
-   ELSE
-           pdt_cas=0.
-   ENDIF
+    INTEGER nid,rid,ierr
+    INTEGER ii,jj,timeid
+    REAL, ALLOCATABLE :: time_val(:)
+
+    fich_cas='cas.nc'
+    print*,'fich_cas ',fich_cas
+    ierr = NF_OPEN(fich_cas,NF_NOWRITE,nid)
+    print*,'fich_cas,NF_NOWRITE,nid ',fich_cas,NF_NOWRITE,nid
+    if (ierr.NE.NF_NOERR) then
+       write(*,*) 'ERROR: GROS Pb opening forcings nc file '
+       write(*,*) NF_STRERROR(ierr)
+       stop ""
+    endif
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'lat',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension lat'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,ii)
+    print*,'OK1 read_SCM_cas: nid,rid,lat',nid,rid,ii
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'lon',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension lon'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,jj)
+    print*,'OK2 read_SCM_cas: nid,rid,lat',nid,rid,jj
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'lev',rid)
+    IF (ierr.NE.NF_NOERR) THEN
+       print*, 'Oh probleme lecture dimension nlev'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,nlev_cas)
+    print*,'OK3 read_SCM_cas: nid,rid,nlev_cas',nid,rid,nlev_cas
+    IF ( .NOT. ( nlev_cas > 10 .AND. nlev_cas < 200000 )) THEN
+       print*,'Valeur de nlev_cas peu probable'
+       STOP
+    ENDIF
+    !.......................................................................
+    ierr=NF_INQ_DIMID(nid,'time',rid)
+    nt_cas=0
+    IF (ierr.NE.NF_NOERR) THEN
+       stop 'Oh probleme lecture dimension time'
+    ENDIF
+    ierr=NF_INQ_DIMLEN(nid,rid,nt_cas)
+    print*,'OK4 read_SCM_cas: nid,rid,nt_cas',nid,rid,nt_cas
+    ! Lecture de l'axe des temps
+    print*,'LECTURE DU TEMPS'
+    ierr=NF_INQ_VARID(nid,'time',timeid)
+    if(ierr/=NF_NOERR) then
+       print *,'Variable time manquante dans cas.nc:'
+       ierr=NF_NOERR
+    else
+       allocate(time_val(nt_cas))
+       ierr = NF90_GET_VAR(nid,timeid,time_val)
+       if(ierr/=NF_NOERR) then
+          print *,'A Pb a la lecture de time cas.nc: '
+       endif
+    endif
+    IF (nt_cas>1) THEN
+       pdt_cas=time_val(2)-time_val(1)
+    ELSE
+       pdt_cas=0.
+    ENDIF
 
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!profils moyens:
-        allocate(plev_cas(nlev_cas,nt_cas),plevh_cas(nlev_cas+1))        
-        allocate(z_cas(nlev_cas,nt_cas),zh_cas(nlev_cas+1))
-        allocate(ap_cas(nlev_cas+1),bp_cas(nt_cas+1))
-        allocate(t_cas(nlev_cas,nt_cas),q_cas(nlev_cas,nt_cas),qv_cas(nlev_cas,nt_cas),ql_cas(nlev_cas,nt_cas), &
-             qi_cas(nlev_cas,nt_cas),rh_cas(nlev_cas,nt_cas))
-        allocate(th_cas(nlev_cas,nt_cas),thl_cas(nlev_cas,nt_cas),thv_cas(nlev_cas,nt_cas),rv_cas(nlev_cas,nt_cas))
-        allocate(u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas),vitw_cas(nlev_cas,nt_cas),omega_cas(nlev_cas,nt_cas))
-        allocate(tke_cas(nlev_cas,nt_cas))
-!forcing
-        allocate(ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas),dt_cas(nlev_cas,nt_cas),dtrad_cas(nlev_cas,nt_cas))
-        allocate(hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas),dq_cas(nlev_cas,nt_cas))
-        allocate(hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas),dth_cas(nlev_cas,nt_cas))
-        allocate(hr_cas(nlev_cas,nt_cas),vr_cas(nlev_cas,nt_cas),dr_cas(nlev_cas,nt_cas))
-        allocate(hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas),du_cas(nlev_cas,nt_cas))
-        allocate(hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas),dv_cas(nlev_cas,nt_cas))
-        allocate(ug_cas(nlev_cas,nt_cas),vg_cas(nlev_cas,nt_cas))
-        allocate(temp_nudg_cas(nlev_cas,nt_cas),qv_nudg_cas(nlev_cas,nt_cas))
-        allocate(u_nudg_cas(nlev_cas,nt_cas),v_nudg_cas(nlev_cas,nt_cas))
-        allocate(invtau_temp_nudg_cas(nlev_cas,nt_cas),invtau_qv_nudg_cas(nlev_cas,nt_cas))
-        allocate(invtau_u_nudg_cas(nlev_cas,nt_cas),invtau_v_nudg_cas(nlev_cas,nt_cas))
-        allocate(lat_cas(nt_cas),sens_cas(nt_cas),ts_cas(nt_cas),ps_cas(nt_cas),ustar_cas(nt_cas),tkes_cas(nt_cas))
-        allocate(uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas),q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas))
-
-
-
-!champs interpoles
-        allocate(plev_prof_cas(nlev_cas))
-        allocate(t_prof_cas(nlev_cas))
-        allocate(theta_prof_cas(nlev_cas))
-        allocate(thl_prof_cas(nlev_cas))
-        allocate(thv_prof_cas(nlev_cas))
-        allocate(q_prof_cas(nlev_cas))
-        allocate(qv_prof_cas(nlev_cas))
-        allocate(ql_prof_cas(nlev_cas))
-        allocate(qi_prof_cas(nlev_cas))
-        allocate(rh_prof_cas(nlev_cas))
-        allocate(rv_prof_cas(nlev_cas))
-        allocate(u_prof_cas(nlev_cas))
-        allocate(v_prof_cas(nlev_cas))
-        allocate(vitw_prof_cas(nlev_cas))
-        allocate(omega_prof_cas(nlev_cas))
-        allocate(tke_prof_cas(nlev_cas))
-        allocate(ug_prof_cas(nlev_cas))
-        allocate(vg_prof_cas(nlev_cas))
-        allocate(temp_nudg_prof_cas(nlev_cas),qv_nudg_prof_cas(nlev_cas))
-        allocate(u_nudg_prof_cas(nlev_cas),v_nudg_prof_cas(nlev_cas))
-        allocate(invtau_temp_nudg_prof_cas(nlev_cas),invtau_qv_nudg_prof_cas(nlev_cas))
-        allocate(invtau_u_nudg_prof_cas(nlev_cas),invtau_v_nudg_prof_cas(nlev_cas))
-        allocate(ht_prof_cas(nlev_cas))
-        allocate(hth_prof_cas(nlev_cas))
-        allocate(hq_prof_cas(nlev_cas))
-        allocate(hu_prof_cas(nlev_cas))
-        allocate(hv_prof_cas(nlev_cas))
-        allocate(vt_prof_cas(nlev_cas))
-        allocate(vth_prof_cas(nlev_cas))
-        allocate(vq_prof_cas(nlev_cas))
-        allocate(vu_prof_cas(nlev_cas))
-        allocate(vv_prof_cas(nlev_cas))
-        allocate(dt_prof_cas(nlev_cas))
-        allocate(dth_prof_cas(nlev_cas))
-        allocate(dtrad_prof_cas(nlev_cas))
-        allocate(dq_prof_cas(nlev_cas))
-        allocate(du_prof_cas(nlev_cas))
-        allocate(dv_prof_cas(nlev_cas))
-        allocate(uw_prof_cas(nlev_cas))
-        allocate(vw_prof_cas(nlev_cas))
-        allocate(q1_prof_cas(nlev_cas))
-        allocate(q2_prof_cas(nlev_cas))
-
-        print*,'Allocations OK'
-        CALL read_SCM (nid,nlev_cas,nt_cas,                                                                     &
-     &     ap_cas,bp_cas,z_cas,plev_cas,zh_cas,plevh_cas,t_cas,th_cas,thv_cas,thl_cas,qv_cas,                   &
-     &     ql_cas,qi_cas,rh_cas,rv_cas,u_cas,v_cas,vitw_cas,omega_cas,tke_cas,ug_cas,vg_cas,                            &
-     &     temp_nudg_cas,qv_nudg_cas,u_nudg_cas,v_nudg_cas,                                                     &
-     &     invtau_temp_nudg_cas,invtau_qv_nudg_cas,invtau_u_nudg_cas,invtau_v_nudg_cas,                         &
-     &     du_cas,hu_cas,vu_cas,                                                                                &
-     &     dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dq_cas,hq_cas,vq_cas,dth_cas,hth_cas,vth_cas,               &
-     &     dr_cas,hr_cas,vr_cas,dtrad_cas,sens_cas,lat_cas,ts_cas,ps_cas,ustar_cas,tkes_cas,                      &
-     &     uw_cas,vw_cas,q1_cas,q2_cas,orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough, &
-     &     o3_cas,rugos_cas,clay_cas,sand_cas)
-        print*,'read_SCM cas OK'
-        do ii=1,nlev_cas
-        print*,'apres read2_SCM, plev_cas=',ii,plev_cas(ii,1)
-        !print*,'apres read_SCM, plev_cas=',ii,omega_cas(ii,nt_cas/2+1)
-        enddo
-
-
-END SUBROUTINE read_SCM_cas
+    !profils moyens:
+    allocate(plev_cas(nlev_cas,nt_cas),plevh_cas(nlev_cas+1))        
+    allocate(z_cas(nlev_cas,nt_cas),zh_cas(nlev_cas+1))
+    allocate(ap_cas(nlev_cas+1),bp_cas(nt_cas+1))
+    allocate(t_cas(nlev_cas,nt_cas),q_cas(nlev_cas,nt_cas),qv_cas(nlev_cas,nt_cas),ql_cas(nlev_cas,nt_cas), &
+         qi_cas(nlev_cas,nt_cas),rh_cas(nlev_cas,nt_cas))
+    allocate(th_cas(nlev_cas,nt_cas),thl_cas(nlev_cas,nt_cas),thv_cas(nlev_cas,nt_cas),rv_cas(nlev_cas,nt_cas))
+    allocate(u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas),vitw_cas(nlev_cas,nt_cas),omega_cas(nlev_cas,nt_cas))
+    allocate(tke_cas(nlev_cas,nt_cas))
+    !forcing
+    allocate(ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas),dt_cas(nlev_cas,nt_cas),dtrad_cas(nlev_cas,nt_cas))
+    allocate(hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas),dq_cas(nlev_cas,nt_cas))
+    allocate(hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas),dth_cas(nlev_cas,nt_cas))
+    allocate(hr_cas(nlev_cas,nt_cas),vr_cas(nlev_cas,nt_cas),dr_cas(nlev_cas,nt_cas))
+    allocate(hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas),du_cas(nlev_cas,nt_cas))
+    allocate(hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas),dv_cas(nlev_cas,nt_cas))
+    allocate(ug_cas(nlev_cas,nt_cas),vg_cas(nlev_cas,nt_cas))
+    allocate(temp_nudg_cas(nlev_cas,nt_cas),qv_nudg_cas(nlev_cas,nt_cas))
+    allocate(u_nudg_cas(nlev_cas,nt_cas),v_nudg_cas(nlev_cas,nt_cas))
+    allocate(invtau_temp_nudg_cas(nlev_cas,nt_cas),invtau_qv_nudg_cas(nlev_cas,nt_cas))
+    allocate(invtau_u_nudg_cas(nlev_cas,nt_cas),invtau_v_nudg_cas(nlev_cas,nt_cas))
+    allocate(lat_cas(nt_cas),sens_cas(nt_cas),ts_cas(nt_cas),tskin_cas(nt_cas),ps_cas(nt_cas),ustar_cas(nt_cas),tkes_cas(nt_cas))
+    allocate(uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas),q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas))
+
+
+
+    !champs interpoles
+    allocate(plev_prof_cas(nlev_cas))
+    allocate(t_prof_cas(nlev_cas))
+    allocate(theta_prof_cas(nlev_cas))
+    allocate(thl_prof_cas(nlev_cas))
+    allocate(thv_prof_cas(nlev_cas))
+    allocate(q_prof_cas(nlev_cas))
+    allocate(qv_prof_cas(nlev_cas))
+    allocate(ql_prof_cas(nlev_cas))
+    allocate(qi_prof_cas(nlev_cas))
+    allocate(rh_prof_cas(nlev_cas))
+    allocate(rv_prof_cas(nlev_cas))
+    allocate(u_prof_cas(nlev_cas))
+    allocate(v_prof_cas(nlev_cas))
+    allocate(vitw_prof_cas(nlev_cas))
+    allocate(omega_prof_cas(nlev_cas))
+    allocate(tke_prof_cas(nlev_cas))
+    allocate(ug_prof_cas(nlev_cas))
+    allocate(vg_prof_cas(nlev_cas))
+    allocate(temp_nudg_prof_cas(nlev_cas),qv_nudg_prof_cas(nlev_cas))
+    allocate(u_nudg_prof_cas(nlev_cas),v_nudg_prof_cas(nlev_cas))
+    allocate(invtau_temp_nudg_prof_cas(nlev_cas),invtau_qv_nudg_prof_cas(nlev_cas))
+    allocate(invtau_u_nudg_prof_cas(nlev_cas),invtau_v_nudg_prof_cas(nlev_cas))
+    allocate(ht_prof_cas(nlev_cas))
+    allocate(hth_prof_cas(nlev_cas))
+    allocate(hq_prof_cas(nlev_cas))
+    allocate(hu_prof_cas(nlev_cas))
+    allocate(hv_prof_cas(nlev_cas))
+    allocate(vt_prof_cas(nlev_cas))
+    allocate(vth_prof_cas(nlev_cas))
+    allocate(vq_prof_cas(nlev_cas))
+    allocate(vu_prof_cas(nlev_cas))
+    allocate(vv_prof_cas(nlev_cas))
+    allocate(dt_prof_cas(nlev_cas))
+    allocate(dth_prof_cas(nlev_cas))
+    allocate(dtrad_prof_cas(nlev_cas))
+    allocate(dq_prof_cas(nlev_cas))
+    allocate(du_prof_cas(nlev_cas))
+    allocate(dv_prof_cas(nlev_cas))
+    allocate(uw_prof_cas(nlev_cas))
+    allocate(vw_prof_cas(nlev_cas))
+    allocate(q1_prof_cas(nlev_cas))
+    allocate(q2_prof_cas(nlev_cas))
+
+    print*,'Allocations OK'
+    CALL read_SCM (nid,nlev_cas,nt_cas,                                                                     &
+         ap_cas,bp_cas,z_cas,plev_cas,zh_cas,plevh_cas,t_cas,th_cas,thv_cas,thl_cas,qv_cas,                   &
+         ql_cas,qi_cas,rh_cas,rv_cas,u_cas,v_cas,vitw_cas,omega_cas,tke_cas,ug_cas,vg_cas,                            &
+         temp_nudg_cas,qv_nudg_cas,u_nudg_cas,v_nudg_cas,                                                     &
+         invtau_temp_nudg_cas,invtau_qv_nudg_cas,invtau_u_nudg_cas,invtau_v_nudg_cas,                         &
+         du_cas,hu_cas,vu_cas,                                                                                &
+         dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dq_cas,hq_cas,vq_cas,dth_cas,hth_cas,vth_cas,               &
+         dr_cas,hr_cas,vr_cas,dtrad_cas,sens_cas,lat_cas,ts_cas,tskin_cas,ps_cas,ustar_cas,tkes_cas,            &
+         uw_cas,vw_cas,q1_cas,q2_cas,orog_cas,albedo_cas,emiss_cas,q_skin_cas,mom_rough,heat_rough, &
+         o3_cas,rugos_cas,clay_cas,sand_cas)
+    print*,'read_SCM cas OK'
+    do ii=1,nlev_cas
+       print*,'apres read_SCM_cas, plev_cas=',ii,plev_cas(ii,1)
+       !print*,'apres read_SCM, plev_cas=',ii,omega_cas(ii,nt_cas/2+1)
+    enddo
+
+
+  END SUBROUTINE read_SCM_cas
 
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-SUBROUTINE deallocate2_1D_cases
-!profils environnementaux:
-        deallocate(plev_cas,plevh_cas)
-        
-        deallocate(z_cas,zh_cas)
-        deallocate(ap_cas,bp_cas)
-        deallocate(t_cas,q_cas,qv_cas,ql_cas,qi_cas,rh_cas)
-        deallocate(th_cas,thl_cas,thv_cas,rv_cas)
-        deallocate(u_cas,v_cas,vitw_cas,omega_cas,tke_cas)
-        
-!forcing
-        deallocate(ht_cas,vt_cas,dt_cas,dtrad_cas)
-        deallocate(hq_cas,vq_cas,dq_cas)
-        deallocate(hth_cas,vth_cas,dth_cas)
-        deallocate(hr_cas,vr_cas,dr_cas)
-        deallocate(hu_cas,vu_cas,du_cas)
-        deallocate(hv_cas,vv_cas,dv_cas)
-        deallocate(ug_cas)
-        deallocate(vg_cas)
-        deallocate(lat_cas,sens_cas,ts_cas,ps_cas,ustar_cas,tkes_cas,uw_cas,vw_cas,q1_cas,q2_cas)
-
-!champs interpoles
-        deallocate(plev_prof_cas)
-        deallocate(t_prof_cas)
-        deallocate(theta_prof_cas)
-        deallocate(thl_prof_cas)
-        deallocate(thv_prof_cas)
-        deallocate(q_prof_cas)
-        deallocate(qv_prof_cas)
-        deallocate(ql_prof_cas)
-        deallocate(qi_prof_cas)
-        deallocate(rh_prof_cas)
-        deallocate(rv_prof_cas)
-        deallocate(u_prof_cas)
-        deallocate(v_prof_cas)
-        deallocate(vitw_prof_cas)
-        deallocate(omega_prof_cas)
-        deallocate(tke_prof_cas)
-        deallocate(ug_prof_cas)
-        deallocate(vg_prof_cas)
-        deallocate(temp_nudg_prof_cas,qv_nudg_prof_cas,u_nudg_prof_cas,v_nudg_prof_cas)
-        deallocate(invtau_temp_nudg_prof_cas,invtau_qv_nudg_prof_cas,invtau_u_nudg_prof_cas,invtau_v_nudg_prof_cas)
-        deallocate(ht_prof_cas)
-        deallocate(hq_prof_cas)
-        deallocate(hu_prof_cas)
-        deallocate(hv_prof_cas)
-        deallocate(vt_prof_cas)
-        deallocate(vq_prof_cas)
-        deallocate(vu_prof_cas)
-        deallocate(vv_prof_cas)
-        deallocate(dt_prof_cas)
-        deallocate(dtrad_prof_cas)
-        deallocate(dq_prof_cas)
-        deallocate(du_prof_cas)
-        deallocate(dv_prof_cas)
-        deallocate(t_prof_cas)
-        deallocate(u_prof_cas)
-        deallocate(v_prof_cas)
-        deallocate(uw_prof_cas)
-        deallocate(vw_prof_cas)
-        deallocate(q1_prof_cas)
-        deallocate(q2_prof_cas)
-
-END SUBROUTINE deallocate2_1D_cases
-
-
-!=====================================================================
-      SUBROUTINE read_SCM(nid,nlevel,ntime,                                       &
-     &     ap,bp,zz,pp,zzh,pph,temp,theta,thv,thl,qv,ql,qi,rh,rv,u,v,vitw,omega,tke,ug,vg,&
-     &     temp_nudg,qv_nudg,u_nudg,v_nudg,                                        &
-     &     invtau_temp_nudg,invtau_qv_nudg,invtau_u_nudg,invtau_v_nudg,             &
-     &     du,hu,vu,dv,hv,vv,dt,ht,vt,dq,hq,vq,                                    &
-     &     dth,hth,vth,dr,hr,vr,dtrad,sens,flat,ts,ps,ustar,tkes,uw,vw,q1,q2,       &
-     &     orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,          &
-     &     heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas)
-
-!program reading forcing of the case study
-      implicit none
+  SUBROUTINE deallocate2_1D_cases
+    !profils environnementaux:
+    deallocate(plev_cas,plevh_cas)
+
+    deallocate(z_cas,zh_cas)
+    deallocate(ap_cas,bp_cas)
+    deallocate(t_cas,q_cas,qv_cas,ql_cas,qi_cas,rh_cas)
+    deallocate(th_cas,thl_cas,thv_cas,rv_cas)
+    deallocate(u_cas,v_cas,vitw_cas,omega_cas,tke_cas)
+
+    !forcing
+    deallocate(ht_cas,vt_cas,dt_cas,dtrad_cas)
+    deallocate(hq_cas,vq_cas,dq_cas)
+    deallocate(hth_cas,vth_cas,dth_cas)
+    deallocate(hr_cas,vr_cas,dr_cas)
+    deallocate(hu_cas,vu_cas,du_cas)
+    deallocate(hv_cas,vv_cas,dv_cas)
+    deallocate(ug_cas)
+    deallocate(vg_cas)
+    deallocate(lat_cas,sens_cas,tskin_cas,ts_cas,ps_cas,ustar_cas,tkes_cas,uw_cas,vw_cas,q1_cas,q2_cas)
+
+    !champs interpoles
+    deallocate(plev_prof_cas)
+    deallocate(t_prof_cas)
+    deallocate(theta_prof_cas)
+    deallocate(thl_prof_cas)
+    deallocate(thv_prof_cas)
+    deallocate(q_prof_cas)
+    deallocate(qv_prof_cas)
+    deallocate(ql_prof_cas)
+    deallocate(qi_prof_cas)
+    deallocate(rh_prof_cas)
+    deallocate(rv_prof_cas)
+    deallocate(u_prof_cas)
+    deallocate(v_prof_cas)
+    deallocate(vitw_prof_cas)
+    deallocate(omega_prof_cas)
+    deallocate(tke_prof_cas)
+    deallocate(ug_prof_cas)
+    deallocate(vg_prof_cas)
+    deallocate(temp_nudg_prof_cas,qv_nudg_prof_cas,u_nudg_prof_cas,v_nudg_prof_cas)
+    deallocate(invtau_temp_nudg_prof_cas,invtau_qv_nudg_prof_cas,invtau_u_nudg_prof_cas,invtau_v_nudg_prof_cas)
+    deallocate(ht_prof_cas)
+    deallocate(hq_prof_cas)
+    deallocate(hu_prof_cas)
+    deallocate(hv_prof_cas)
+    deallocate(vt_prof_cas)
+    deallocate(vq_prof_cas)
+    deallocate(vu_prof_cas)
+    deallocate(vv_prof_cas)
+    deallocate(dt_prof_cas)
+    deallocate(dtrad_prof_cas)
+    deallocate(dq_prof_cas)
+    deallocate(du_prof_cas)
+    deallocate(dv_prof_cas)
+    deallocate(t_prof_cas)
+    deallocate(u_prof_cas)
+    deallocate(v_prof_cas)
+    deallocate(uw_prof_cas)
+    deallocate(vw_prof_cas)
+    deallocate(q1_prof_cas)
+    deallocate(q2_prof_cas)
+
+  END SUBROUTINE deallocate2_1D_cases
+
+
+  !=====================================================================
+  SUBROUTINE read_SCM(nid,nlevel,ntime,                                       &
+       ap,bp,zz,pp,zzh,pph,temp,theta,thv,thl,qv,ql,qi,rh,rv,u,v,vitw,omega,tke,ug,vg,&
+       temp_nudg,qv_nudg,u_nudg,v_nudg,                                        &
+       invtau_temp_nudg,invtau_qv_nudg,invtau_u_nudg,invtau_v_nudg,             &
+       du,hu,vu,dv,hv,vv,dt,ht,vt,dq,hq,vq,                                    &
+       dth,hth,vth,dr,hr,vr,dtrad,sens,flat,ts,tskin,ps,ustar,tkes,uw,vw,q1,q2,       &
+       orog_cas,albedo_cas,emiss_cas,q_skin_cas,mom_rough,          &
+       heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas)
+
+    !program reading forcing of the case study
+    use netcdf, only: nf90_get_var
+    implicit none
 #include "netcdf.inc"
 #include "compar1d.h"
 
-      integer ntime,nlevel,k,t
-
-      real ap(nlevel+1),bp(nlevel+1)
-      real zz(nlevel,ntime),zzh(nlevel+1)
-      real pp(nlevel,ntime),pph(nlevel+1)
-!profils initiaux
-      real temp0(nlevel),qv0(nlevel),ql0(nlevel),qi0(nlevel),u0(nlevel),v0(nlevel),tke0(nlevel)
-      real pp0(nlevel)    
-      real temp(nlevel,ntime),qv(nlevel,ntime),ql(nlevel,ntime),qi(nlevel,ntime),rh(nlevel,ntime)
-      real theta(nlevel,ntime),thv(nlevel,ntime),thl(nlevel,ntime),rv(nlevel,ntime)
-      real u(nlevel,ntime),v(nlevel,ntime),tkes(ntime)
-      real temp_nudg(nlevel,ntime),qv_nudg(nlevel,ntime),u_nudg(nlevel,ntime),v_nudg(nlevel,ntime)
-      real invtau_temp_nudg(nlevel,ntime),invtau_qv_nudg(nlevel,ntime),invtau_u_nudg(nlevel,ntime),invtau_v_nudg(nlevel,ntime)
-      real ug(nlevel,ntime),vg(nlevel,ntime)
-      real vitw(nlevel,ntime),omega(nlevel,ntime),tke(nlevel,ntime)
-      real du(nlevel,ntime),hu(nlevel,ntime),vu(nlevel,ntime)
-      real dv(nlevel,ntime),hv(nlevel,ntime),vv(nlevel,ntime)
-      real dt(nlevel,ntime),ht(nlevel,ntime),vt(nlevel,ntime)
-      real dtrad(nlevel,ntime)
-      real dq(nlevel,ntime),hq(nlevel,ntime),vq(nlevel,ntime)
-      real dth(nlevel,ntime),hth(nlevel,ntime),vth(nlevel,ntime),hthl(nlevel,ntime)
-      real dr(nlevel,ntime),hr(nlevel,ntime),vr(nlevel,ntime)
-      real flat(ntime),sens(ntime),ustar(ntime)
-      real uw(nlevel,ntime),vw(nlevel,ntime),q1(nlevel,ntime),q2(nlevel,ntime)
-      real ts(ntime),ps(ntime)
-      real orog_cas,albedo_cas,emiss_cas,t_skin_cas,q_skin_cas,mom_rough,heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas
-      real apbp(nlevel+1),resul(nlevel,ntime),resul1(nlevel),resul2(ntime),resul3
-
-
-      integer nid, ierr,ierr1,ierr2,rid,i,int_test
-      integer nbvar3d
-      parameter(nbvar3d=78)
-      integer var3didin(nbvar3d),missing_var(nbvar3d)
-      character*13 name_var(1:nbvar3d)
-
-
-!      data name_var/ &
-!     ! coordonnees pression (n+1 niveaux) #4
-!     & 'coor_par_a','coor_par_b','height_h','pressure_h',& ! #1-#4
-!     ! coordonnees pression (n niveaux) #8
-!     &'temp','qv','ql','qi','u','v','tke','pressure',& ! #5-#12
-!     ! coordonnees pression + temps #42
-!     &'w','omega','ug','vg','uadv','uadvh','uadvv','vadv','vadvh','vadvv','temp_adv','tadvh','tadvv',& !  #13 - #25
-!     &'qv_adv','qvadvh','qvadvv','thadv','thadvh','thadvv','thladvh',                             & ! #26 - #32
-!     & 'radv','radvh','radvv','radcool','q1','q2','ustress','vstress',                           & ! #33 - #40
-!     & 'rh','temp_nudging','qv_nudging','u_nudging','v_nudging',                                       & ! #41-45
-!     &'height_f','pressure_forc','tempt','theta','thv','thl','qvt','qlt','qit','rv','ut','vt',   & ! #46-58
-!     ! coordonnees temps #12
-!     &'tkes','sfc_sens_flx','sfc_lat_flx','ts','ps','ustar',&
-!     &'orog','albedo','emiss','t_skin','q_skin','mom_rough','heat_rough',&
-!     ! scalaires #4
-!     &'o3','rugos','clay','sand'/
-
-
-
-      data name_var/ &
-     ! coordonnees pression (n+1 niveaux) #4
-     & 'coor_par_a','coor_par_b','zf','pressure_h',& ! #1-#4
-     ! coordonnees pression (n niveaux) #8
-     & 'ta','qv','ql','qi','ua','va','tke','pa',& ! #5-#12
-     ! coordonnees pression + temps #46
-     & 'wa','wap','ug','vg','tnua_adv','tnua_advh','tnua_advv','tnva_adv','tnva_advh','tnva_advv','tnta_adv','tnta_advh','tnta_advv',& !  #13 - #25
-     & 'tnqv_adv','tnqv_advh','tnqv_advv','thadv','thadvh','thadvv','thladvh',                             & ! #26 - #32
-     & 'radv','radvh','radvv','tnta_rad','q1','q2','ustress','vstress',                           & ! #33 - #40
-     & 'rh','ta_nud','qv_nud','ua_nud','va_nud',                                       & ! #41-45
-     & 'zh_forc','pa_forc','tat','thetat','thetavt','thetalt','qvt','qlt','qit','rv','uat','vat',   & ! #46-57
-     & 'nudging_constant_ta', 'nudging_constant_qv', 'nudging_constant_ua', 'nudging_constant_va',           & ! # 58-61
-     ! coordonnees temps #12
-     & 'tkes','hfss','hfls','ts_forc','ps_forc','ustar', &                                        ! 62-67
-     & 'orog','albedo','emiss','t_skin','q_skin','z0','z0h',       &                    ! 68-74
-     ! scalaires #4                               
-     & 'O3','rugos','clay','sand'/                                                      ! 75-78
-
-
-!-----------------------------------------------------------------------
-! First check that we are using a version > v2 of the 1D standard format
-! use the difference between 'temp' (old version) and 'ta' (new version)
-!-----------------------------------------------------------------------
-
-
-         ierr=NF_INQ_VARID(nid,'ta',int_test)
-         if(ierr/=NF_NOERR) then
-           print*, '++++++++++++++++++++++++++++++'
-           print*, 'variable ta missing in cas.nc '
-           print*, 'You are probably using an obsolete version of the 1D cases'
-           print*, 'please dowload the last version of the 1D archive from https://lmdz.lmd.jussieu.fr/pub/'
-           print*, '++++++++++++++++++++++++++++++'
-           CALL abort_gcm ('mod_1D_cases_read_std','bad version of 1D directory',0)
-         endif
-     
-!-----------------------------------------------------------------------
-! Checking availability of variable #i in the cas.nc file
-!     missing_var=1 if the variable is missing
-!-----------------------------------------------------------------------
-
-       do i=1,nbvar3d
-         missing_var(i)=0.
-         ierr=NF_INQ_VARID(nid,name_var(i),var3didin(i)) 
-         print*, 'name_var(i)', name_var(i), var3didin(i)
-         if(ierr/=NF_NOERR) then
-           print *,'Variable manquante dans cas.nc:',i,name_var(i)
-           ierr=NF_NOERR
-           missing_var(i)=1
-         else
-
-!-----------------------------------------------------------------------
-! Activating keys depending on the presence of specific variables in cas.nc
-!-----------------------------------------------------------------------
-if ( 1 == 1 ) THEN
-! A MODIFIER: il faudrait dire nudging_temp mais faut le declarer dans compar1d.h etc...        
-!           if ( name_var(i) == 'temp_nudging' .and. nint(nudging_t)==0) stop 'Nudging inconsistency temp'
-            if ( name_var(i) == 'qv_nud' .and. nint(nudging_qv)==0) stop 'Nudging inconsistency qv'
-            if ( name_var(i) == 'ua_nud' .and. nint(nudging_u)==0) stop 'Nudging inconsistency u'
-            if ( name_var(i) == 'va_nud' .and. nint(nudging_v)==0) stop 'Nudging inconsistency v'
-    ELSE
+    integer ntime,nlevel,k,t
+
+    real ap(nlevel+1),bp(nlevel+1)
+    real zz(nlevel,ntime),zzh(nlevel+1)
+    real pp(nlevel,ntime),pph(nlevel+1)
+    !profils initiaux
+    real temp0(nlevel),qv0(nlevel),ql0(nlevel),qi0(nlevel),u0(nlevel),v0(nlevel),tke0(nlevel)
+    real pp0(nlevel)    
+    real temp(nlevel,ntime),qv(nlevel,ntime),ql(nlevel,ntime),qi(nlevel,ntime),rh(nlevel,ntime)
+    real theta(nlevel,ntime),thv(nlevel,ntime),thl(nlevel,ntime),rv(nlevel,ntime)
+    real u(nlevel,ntime),v(nlevel,ntime),tkes(ntime)
+    real temp_nudg(nlevel,ntime),qv_nudg(nlevel,ntime),u_nudg(nlevel,ntime),v_nudg(nlevel,ntime)
+    real invtau_temp_nudg(nlevel,ntime),invtau_qv_nudg(nlevel,ntime),invtau_u_nudg(nlevel,ntime),invtau_v_nudg(nlevel,ntime)
+    real ug(nlevel,ntime),vg(nlevel,ntime)
+    real vitw(nlevel,ntime),omega(nlevel,ntime),tke(nlevel,ntime)
+    real du(nlevel,ntime),hu(nlevel,ntime),vu(nlevel,ntime)
+    real dv(nlevel,ntime),hv(nlevel,ntime),vv(nlevel,ntime)
+    real dt(nlevel,ntime),ht(nlevel,ntime),vt(nlevel,ntime)
+    real dtrad(nlevel,ntime)
+    real dq(nlevel,ntime),hq(nlevel,ntime),vq(nlevel,ntime)
+    real dth(nlevel,ntime),hth(nlevel,ntime),vth(nlevel,ntime),hthl(nlevel,ntime)
+    real dr(nlevel,ntime),hr(nlevel,ntime),vr(nlevel,ntime)
+    real flat(ntime),sens(ntime),ustar(ntime)
+    real uw(nlevel,ntime),vw(nlevel,ntime),q1(nlevel,ntime),q2(nlevel,ntime)
+    real ts(ntime),tskin(ntime),ps(ntime)
+    real orog_cas,albedo_cas,emiss_cas,q_skin_cas,mom_rough,heat_rough,o3_cas,rugos_cas,clay_cas,sand_cas
+    real apbp(nlevel+1),resul(nlevel,ntime),resul1(nlevel),resul2(ntime),resul3
+
+
+    integer nid, ierr,ierr1,ierr2,rid,i,int_test
+    integer nbvar3d
+    parameter(nbvar3d=78)
+    integer var3didin(nbvar3d),missing_var(nbvar3d)
+    character*13 name_var(1:nbvar3d)
+
+
+    !      data name_var/ &
+    !     ! coordonnees pression (n+1 niveaux) #4
+    !     & 'coor_par_a','coor_par_b','height_h','pressure_h',& ! #1-#4
+    !     ! coordonnees pression (n niveaux) #8
+    !     &'temp','qv','ql','qi','u','v','tke','pressure',& ! #5-#12
+    !     ! coordonnees pression + temps #42
+    !     &'w','omega','ug','vg','uadv','uadvh','uadvv','vadv','vadvh','vadvv','temp_adv','tadvh','tadvv',& !  #13 - #25
+    !     &'qv_adv','qvadvh','qvadvv','thadv','thadvh','thadvv','thladvh',                             & ! #26 - #32
+    !     & 'radv','radvh','radvv','radcool','q1','q2','ustress','vstress',                           & ! #33 - #40
+    !     & 'rh','temp_nudging','qv_nudging','u_nudging','v_nudging',                                       & ! #41-45
+    !     &'height_f','pressure_forc','tempt','theta','thv','thl','qvt','qlt','qit','rv','ut','vt',   & ! #46-58
+    !     ! coordonnees temps #12
+    !     &'tkes','sfc_sens_flx','sfc_lat_flx','ts','ps','ustar',&
+    !     &'orog','albedo','emiss','t_skin','q_skin','mom_rough','heat_rough',&
+    !     ! scalaires #4
+    !     &'o3','rugos','clay','sand'/
+
+
+
+    data name_var/ &
+                                ! coordonnees pression (n+1 niveaux) #4
+         'coor_par_a','coor_par_b','zf','pressure_h',& ! #1-#4
+                                ! coordonnees pression (n niveaux) #8
+         'ta','qv','ql','qi','ua','va','tke','pa',& ! #5-#12
+                                ! coordonnees pression + temps #46
+         'wa','wap','ug','vg','tnua_adv','tnua_advh','tnua_advv','tnva_adv','tnva_advh','tnva_advv','tnta_adv','tnta_advh',& !  #13 - #25
+         'tnta_advv','tnqv_adv','tnqv_advh','tnqv_advv','thadv','thadvh','thadvv','thladvh',                             & ! #26 - #32
+         'radv','radvh','radvv','tnta_rad','q1','q2','ustress','vstress',                           & ! #33 - #40
+         'rh','ta_nud','qv_nud','ua_nud','va_nud',                                       & ! #41-45
+         'zh_forc','pa_forc','tat','thetat','thetavt','thetalt','qvt','qlt','qit','rvt','uat','vat',   & ! #46-57
+         'nudging_constant_ta', 'nudging_constant_qv', 'nudging_constant_ua', 'nudging_constant_va',           & ! # 58-61
+                                ! coordonnees temps #12
+         'tkes','hfss','hfls','ts_forc','tskin','ps_forc','ustar', &                     ! 62-68
+                                  ! scalaires 
+         'orog','albedo','emiss','q_skin','z0','z0h',       &                    ! 69-74
+         'O3','rugos','clay','sand'/                                                      ! 75-78
+
+
+    !-----------------------------------------------------------------------
+    ! First check that we are using a version > v2 of the 1D standard format
+    ! use the difference between 'temp' (old version) and 'ta' (new version)
+    !-----------------------------------------------------------------------
+
+
+    ierr=NF_INQ_VARID(nid,'ta',int_test)
+    if(ierr/=NF_NOERR) then
+       print*, '++++++++++++++++++++++++++++++'
+       print*, 'variable ta missing in cas.nc '
+       print*, 'You are probably using an obsolete version of the 1D cases'
+       print*, 'please dowload the last version of the 1D archive from https://lmdz.lmd.jussieu.fr/pub/'
+       print*, '++++++++++++++++++++++++++++++'
+       CALL abort_gcm ('mod_1D_cases_read_std','bad version of 1D directory',0)
+    endif
+
+    !-----------------------------------------------------------------------
+    ! Checking availability of variable #i in the cas.nc file
+    !     missing_var=1 if the variable is missing
+    !-----------------------------------------------------------------------
+
+    do i=1,nbvar3d
+       missing_var(i)=0.
+       ierr=NF_INQ_VARID(nid,name_var(i),var3didin(i)) 
+       print*, 'name_var(i)', name_var(i), var3didin(i)
+       if(ierr/=NF_NOERR) then
+          print *,'Variable manquante dans cas.nc:',i,name_var(i)
+          ierr=NF_NOERR
+          missing_var(i)=1
+       else
+
+          !-----------------------------------------------------------------------
+          ! Activating keys depending on the presence of specific variables in cas.nc
+          !-----------------------------------------------------------------------
+          if ( 1 == 1 ) THEN
+             ! A MODIFIER: il faudrait dire nudging_temp mais faut le declarer dans compar1d.h etc...        
+             !           if ( name_var(i) == 'temp_nudging' .and. nint(nudging_t)==0) stop 'Nudging inconsistency temp'
+             if ( name_var(i) == 'qv_nud' .and. nint(nudging_qv)==0) stop 'Nudging inconsistency qv'
+             if ( name_var(i) == 'ua_nud' .and. nint(nudging_u)==0) stop 'Nudging inconsistency u'
+             if ( name_var(i) == 'va_nud' .and. nint(nudging_v)==0) stop 'Nudging inconsistency v'
+          ELSE
              print*,'GUIDAGE : CONSISTENCY CHECK DEACTIVATED FOR TESTS of SANDU/REF'
-    ENDIF
-
-!-----------------------------------------------------------------------
-! Reading variables 1D (N+1) vertical variables (nlevelp1,lat,lon)
-!-----------------------------------------------------------------------
-           if(i.LE.4) then
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),apbp)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),apbp)
-#endif
-           print *,'read2_cas(apbp), on a lu ',i,name_var(i)
-           if(ierr/=NF_NOERR) then
-              print *,'Pb a la lecture de cas.nc: ',name_var(i)
-              stop "getvarup"
-           endif
-
-!-----------------------------------------------------------------------
-!  Reading 1D (N) vertical varialbes    (nlevel,lat,lon)   
-!-----------------------------------------------------------------------
-           else if(i.gt.4.and.i.LE.12) then  
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul1)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul1)
-#endif
-           print *,'read2_cas(resul1), on a lu ',i,name_var(i)
-           if(ierr/=NF_NOERR) then
-              print *,'Pb a la lecture de cas.nc: ',name_var(i)
-              stop "getvarup"
-           endif
-         print*,'Lecture de la variable #i ',i,name_var(i),minval(resul1),maxval(resul1)
-
-!-----------------------------------------------------------------------
-!  Reading 2D tim-vertical variables  (time,nlevel,lat,lon)
-!  TBD : seems to be the same as above.
-!-----------------------------------------------------------------------
-           else if(i.gt.12.and.i.LE.61) then
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul)
-#endif
-           print *,'read2_cas(resul), on a lu ',i,name_var(i)
-           if(ierr/=NF_NOERR) then
-              print *,'Pb a la lecture de cas.nc: ',name_var(i)
-              stop "getvarup"
-           endif
-         print*,'Lecture de la variable #i ',i,name_var(i),minval(resul),maxval(resul)
-
-!-----------------------------------------------------------------------
-!  Reading 1D time variables (time,lat,lon)
-!-----------------------------------------------------------------------
-           else if (i.gt.62.and.i.LE.75) then
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul2)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul2)
-#endif
-           print *,'read2_cas(resul2), on a lu ',i,name_var(i)
-           if(ierr/=NF_NOERR) then
-              print *,'Pb a la lecture de cas.nc: ',name_var(i)
-              stop "getvarup"
-           endif
-         print*,'Lecture de la variable #i  ',i,name_var(i),minval(resul2),maxval(resul2)
-
-!-----------------------------------------------------------------------
-! Reading scalar variables (lat,lon)
-!-----------------------------------------------------------------------
-           else
-#ifdef NC_DOUBLE
-           ierr = NF_GET_VAR_DOUBLE(nid,var3didin(i),resul3)
-#else
-           ierr = NF_GET_VAR_REAL(nid,var3didin(i),resul3)
-#endif
-           print *,'read2_cas(resul3), on a lu ',i,name_var(i)
-           if(ierr/=NF_NOERR) then
-              print *,'Pb a la lecture de cas.nc: ',name_var(i)
-              stop "getvarup"
-           endif
-         print*,'Lecture de la variable #i ',i,name_var(i),resul3
-           endif
-         endif
-
-!-----------------------------------------------------------------------
-! Attributing variables
-!-----------------------------------------------------------------------
-         select case(i)
-         !case(1) ; ap=apbp       ! donnees indexees en nlevel+1
-         ! case(2) ; bp=apbp
-           case(3) ; zzh=apbp
-           case(4) ; pph=apbp
-           case(5) ; temp0=resul1    ! donnees initiales
-           case(6) ; qv0=resul1
-           case(7) ; ql0=resul1
-           case(8) ; qi0=resul1
-           case(9) ; u0=resul1
-           case(10) ; v0=resul1
-           case(11) ; tke0=resul1
-           case(12) ; pp0=resul1
-           case(13) ; vitw=resul    ! donnees indexees en nlevel,time
-           case(14) ; omega=resul
-           case(15) ; ug=resul
-           case(16) ; vg=resul
-           case(17) ; du=resul
-           case(18) ; hu=resul
-           case(19) ; vu=resul
-           case(20) ; dv=resul
-           case(21) ; hv=resul
-           case(22) ; vv=resul
-           case(23) ; dt=resul
-           case(24) ; ht=resul
-           case(25) ; vt=resul
-           case(26) ; dq=resul
-           case(27) ; hq=resul
-           case(28) ; vq=resul
-           case(29) ; dth=resul
-           case(30) ; hth=resul
-           case(31) ; vth=resul
-           case(32) ; hthl=resul
-           case(33) ; dr=resul
-           case(34) ; hr=resul
-           case(35) ; vr=resul
-           case(36) ; dtrad=resul
-           case(37) ; q1=resul
-           case(38) ; q2=resul
-           case(39) ; uw=resul
-           case(40) ; vw=resul
-           case(41) ; rh=resul
-           case(42) ; temp_nudg=resul
-           case(43) ; qv_nudg=resul
-           case(44) ; u_nudg=resul
-           case(45) ; v_nudg=resul
-           case(46) ; zz=resul      ! donnees en time,nlevel pour profil initial
-           case(47) ; pp=resul
-           case(48) ; temp=resul
-           case(49) ; theta=resul
-           case(50) ; thv=resul
-           case(51) ; thl=resul
-           case(52) ; qv=resul
-           case(53) ; ql=resul
-           case(54) ; qi=resul
-           case(55) ; rv=resul
-           case(56) ; u=resul
-           case(57) ; v=resul
-           case(58) ; invtau_temp_nudg=resul
-           case(59) ; invtau_qv_nudg=resul
-           case(60) ; invtau_u_nudg=resul
-           case(61) ; invtau_v_nudg=resul
-           case(62) ; tkes=resul2   ! donnees indexees en time
-           case(63) ; sens=resul2
-           case(64) ; flat=resul2
-           case(65) ; ts=resul2
-           case(66) ; ps=resul2
-           case(67) ; ustar=resul2
-           case(68) ; orog_cas=resul3      ! constantes
-           case(69) ; albedo_cas=resul3
-           case(70) ; emiss_cas=resul3
-           case(71) ; t_skin_cas=resul3
-           case(72) ; q_skin_cas=resul3
-           case(73) ; mom_rough=resul3
-           case(74) ; heat_rough=resul3
-           case(75) ; o3_cas=resul3        
-           case(76) ; rugos_cas=resul3
-           case(77) ; clay_cas=resul3
-           case(78) ; sand_cas=resul3
-         end select
-         resul=0.
-         resul1=0.
-         resul2=0.
-         resul3=0.
+          ENDIF
+
+          !-----------------------------------------------------------------------
+          ! Reading variables 1D (N+1) vertical variables (nlevelp1,lat,lon)
+          !-----------------------------------------------------------------------
+          if(i.LE.4) then
+             ierr = NF90_GET_VAR(nid,var3didin(i),apbp)
+             print *,'read_SCM(apbp), on a lu ',i,name_var(i)
+             if(ierr/=NF_NOERR) then
+                print *,'B Pb a la lecture de cas.nc: ',name_var(i)
+                stop "getvarup"
+             endif
+
+             !-----------------------------------------------------------------------
+             !  Reading 1D (N) vertical varialbes    (nlevel,lat,lon)   
+             !-----------------------------------------------------------------------
+          else if(i.gt.4.and.i.LE.12) then  
+             ierr = NF90_GET_VAR(nid,var3didin(i),resul1)
+             print *,'read_SCM(resul1), on a lu ',i,name_var(i)
+             if(ierr/=NF_NOERR) then
+                print *,'C Pb a la lecture de cas.nc: ',name_var(i)
+                stop "getvarup"
+             endif
+             print*,'Lecture de la variable #i ',i,name_var(i),minval(resul1),maxval(resul1)
+
+             !-----------------------------------------------------------------------
+             !  Reading 2D tim-vertical variables  (time,nlevel,lat,lon)
+             !  TBD : seems to be the same as above.
+             !-----------------------------------------------------------------------
+          else if(i.gt.12.and.i.LE.61) then
+             ierr = NF90_GET_VAR(nid,var3didin(i),resul)
+             print *,'read_SCM(resul), on a lu ',i,name_var(i)
+             if(ierr/=NF_NOERR) then
+                print *,'D Pb a la lecture de cas.nc: ',name_var(i)
+                stop "getvarup"
+             endif
+             print*,'Lecture de la variable #i ',i,name_var(i),minval(resul),maxval(resul)
+
+             !-----------------------------------------------------------------------
+             !  Reading 1D time variables (time,lat,lon)
+             !-----------------------------------------------------------------------
+          else if (i.gt.62.and.i.LE.75) then
+             ierr = NF90_GET_VAR(nid,var3didin(i),resul2)
+             print *,'read_SCM(resul2), on a lu ',i,name_var(i)
+             if(ierr/=NF_NOERR) then
+                print *,'E Pb a la lecture de cas.nc: ',name_var(i)
+                stop "getvarup"
+             endif
+             print*,'Lecture de la variable #i  ',i,name_var(i),minval(resul2),maxval(resul2)
+
+             !-----------------------------------------------------------------------
+             ! Reading scalar variables (lat,lon)
+             !-----------------------------------------------------------------------
+          else
+             ierr = NF90_GET_VAR(nid,var3didin(i),resul3)
+             print *,'read_SCM(resul3), on a lu ',i,name_var(i)
+             if(ierr/=NF_NOERR) then
+                print *,'F Pb a la lecture de cas.nc: ',name_var(i)
+                stop "getvarup"
+             endif
+             print*,'Lecture de la variable #i ',i,name_var(i),resul3
+          endif
+       endif
+
+       !-----------------------------------------------------------------------
+       ! Attributing variables
+       !-----------------------------------------------------------------------
+       select case(i)
+          !case(1) ; ap=apbp       ! donnees indexees en nlevel+1
+          ! case(2) ; bp=apbp
+       case(3) ; zzh=apbp
+       case(4) ; pph=apbp
+       case(5) ; temp0=resul1    ! donnees initiales
+       case(6) ; qv0=resul1
+       case(7) ; ql0=resul1
+       case(8) ; qi0=resul1
+       case(9) ; u0=resul1
+       case(10) ; v0=resul1
+       case(11) ; tke0=resul1
+       case(12) ; pp0=resul1
+       case(13) ; vitw=resul    ! donnees indexees en nlevel,time
+       case(14) ; omega=resul
+       case(15) ; ug=resul
+       case(16) ; vg=resul
+       case(17) ; du=resul
+       case(18) ; hu=resul
+       case(19) ; vu=resul
+       case(20) ; dv=resul
+       case(21) ; hv=resul
+       case(22) ; vv=resul
+       case(23) ; dt=resul
+       case(24) ; ht=resul
+       case(25) ; vt=resul
+       case(26) ; dq=resul
+       case(27) ; hq=resul
+       case(28) ; vq=resul
+       case(29) ; dth=resul
+       case(30) ; hth=resul
+       case(31) ; vth=resul
+       case(32) ; hthl=resul
+       case(33) ; dr=resul
+       case(34) ; hr=resul
+       case(35) ; vr=resul
+       case(36) ; dtrad=resul
+       case(37) ; q1=resul
+       case(38) ; q2=resul
+       case(39) ; uw=resul
+       case(40) ; vw=resul
+       case(41) ; rh=resul
+       case(42) ; temp_nudg=resul
+       case(43) ; qv_nudg=resul
+       case(44) ; u_nudg=resul
+       case(45) ; v_nudg=resul
+       case(46) ; zz=resul      ! donnees en time,nlevel pour profil initial
+       case(47) ; pp=resul
+       case(48) ; temp=resul
+       case(49) ; theta=resul
+       case(50) ; thv=resul
+       case(51) ; thl=resul
+       case(52) ; qv=resul
+       case(53) ; ql=resul
+       case(54) ; qi=resul
+       case(55) ; rv=resul
+       case(56) ; u=resul
+       case(57) ; v=resul
+       case(58) ; invtau_temp_nudg=resul
+       case(59) ; invtau_qv_nudg=resul
+       case(60) ; invtau_u_nudg=resul
+       case(61) ; invtau_v_nudg=resul
+       case(62) ; tkes=resul2   ! donnees indexees en time
+       case(63) ; sens=resul2
+       case(64) ; flat=resul2
+       case(65) ; ts=resul2
+       case(66) ; tskin=resul2        
+       case(67) ; ps=resul2
+       case(68) ; ustar=resul2
+       case(69) ; orog_cas=resul3      ! constantes
+       case(70) ; albedo_cas=resul3
+       case(71) ; emiss_cas=resul3
+       case(72) ; q_skin_cas=resul3
+       case(73) ; mom_rough=resul3
+       case(74) ; heat_rough=resul3
+       case(75) ; o3_cas=resul3        
+       case(76) ; rugos_cas=resul3
+       case(77) ; clay_cas=resul3
+       case(78) ; sand_cas=resul3
+       end select
+       resul=0.
+       resul1=0.
+       resul2=0.
+       resul3=0.
+    enddo
+    print*,'Lecture de la variable APRES ,sens ',minval(sens),maxval(sens)
+    print*,'Lecture de la variable APRES ,flat ',minval(flat),maxval(flat)
+
+    !CR:ATTENTION EN ATTENTE DE REGLER LA QUESTION DU PAS DE TEMPS INITIAL
+    do t=1,ntime
+       do k=1,nlevel
+          temp(k,t)=temp0(k)
+          qv(k,t)=qv0(k)
+          ql(k,t)=ql0(k)
+          qi(k,t)=qi0(k)
+          u(k,t)=u0(k)
+          v(k,t)=v0(k)
+          tke(k,t)=tke0(k)
        enddo
-         print*,'Lecture de la variable APRES ,sens ',minval(sens),maxval(sens)
-         print*,'Lecture de la variable APRES ,flat ',minval(flat),maxval(flat)
-
-!CR:ATTENTION EN ATTENTE DE REGLER LA QUESTION DU PAS DE TEMPS INITIAL
-       do t=1,ntime
-          do k=1,nlevel
-             temp(k,t)=temp0(k)
-             qv(k,t)=qv0(k)
-             ql(k,t)=ql0(k)
-             qi(k,t)=qi0(k)
-             u(k,t)=u0(k)
-             v(k,t)=v0(k)
-             tke(k,t)=tke0(k)
-          enddo
-       enddo
-       !!!! TRAVAIL : EN FONCTION DES DECISIONS SUR LA SPECIFICATION DE W
-       !!!omega=-vitw*pres*rg/(rd*temp)
-!-----------------------------------------------------------------------
-
-         return 
-         END SUBROUTINE read_SCM
-!======================================================================
-
-!======================================================================
-
-!**********************************************************************************************
-
-!**********************************************************************************************
-        SUBROUTINE interp_case_time_std(day,day1,annee_ref                           &
-!    &         ,year_cas,day_cas,nt_cas,pdt_forc,nlev_cas                         &
-     &         ,nt_cas,nlev_cas                                                   &
-     &         ,ts_cas,ps_cas,plev_cas,t_cas,theta_cas,thv_cas,thl_cas            &
-     &         ,qv_cas,ql_cas,qi_cas,u_cas,v_cas                                  &
-     &         ,ug_cas,vg_cas,temp_nudg_cas,qv_nudg_cas,u_nudg_cas,v_nudg_cas     &
-     &         ,invtau_temp_nudg_cas,invtau_qv_nudg_cas,invtau_u_nudg_cas,invtau_v_nudg_cas     &
-     &         ,vitw_cas,omega_cas,tke_cas,du_cas,hu_cas,vu_cas             &
-     &         ,dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dtrad_cas               &
-     &         ,dq_cas,hq_cas,vq_cas,dth_cas,hth_cas,vth_cas                      &
-     &         ,lat_cas,sens_cas,ustar_cas                                        &
-     &         ,uw_cas,vw_cas,q1_cas,q2_cas,tkes_cas                               &
-!
-     &         ,ts_prof_cas,ps_prof_cas,plev_prof_cas,t_prof_cas,theta_prof_cas               &
-     &         ,thv_prof_cas,thl_prof_cas,qv_prof_cas,ql_prof_cas,qi_prof_cas     &
-     &         ,u_prof_cas,v_prof_cas,ug_prof_cas,vg_prof_cas                     &
-     &         ,temp_nudg_prof_cas,qv_nudg_prof_cas,u_nudg_prof_cas,v_nudg_prof_cas     &
-     &         ,invtau_temp_nudg_prof_cas,invtau_qv_nudg_prof_cas,invtau_u_nudg_prof_cas,invtau_v_nudg_prof_cas     &     
-     &         ,vitw_prof_cas,omega_prof_cas,tke_prof_cas,du_prof_cas,hu_prof_cas,vu_prof_cas  &
-     &         ,dv_prof_cas,hv_prof_cas,vv_prof_cas,dt_prof_cas                   &
-     &         ,ht_prof_cas,vt_prof_cas,dtrad_prof_cas,dq_prof_cas                &
-     &         ,hq_prof_cas,vq_prof_cas,dth_prof_cas,hth_prof_cas,vth_prof_cas    &
-     &         ,lat_prof_cas,sens_prof_cas                                        &
-     &         ,ustar_prof_cas,uw_prof_cas,vw_prof_cas,q1_prof_cas,q2_prof_cas,tkes_prof_cas)
-
-
-
-
-
-
-       implicit none
-
-!---------------------------------------------------------------------------------------
-! Time interpolation of a 2D field to the timestep corresponding to day
-!
-! day: current julian day (e.g. 717538.2)
-! day1: first day of the simulation
-! nt_cas: total nb of data in the forcing 
-! pdt_cas: total time interval (in sec) between 2 forcing data
-!---------------------------------------------------------------------------------------
+    enddo
+!!!! TRAVAIL : EN FONCTION DES DECISIONS SUR LA SPECIFICATION DE W
+!!!omega=-vitw*pres*rg/(rd*temp)
+    !-----------------------------------------------------------------------
+
+    return 
+  END SUBROUTINE read_SCM
+  !======================================================================
+
+  !======================================================================
+
+  !**********************************************************************************************
+
+  !**********************************************************************************************
+  SUBROUTINE interp_case_time_std(day,day1,annee_ref                           &
+       !    &         ,year_cas,day_cas,nt_cas,pdt_forc,nlev_cas                         &
+       ,nt_cas,nlev_cas                                                   &
+       ,ts_cas,tskin_cas,ps_cas,plev_cas,t_cas,theta_cas,thv_cas,thl_cas            &
+       ,qv_cas,ql_cas,qi_cas,u_cas,v_cas                                  &
+       ,ug_cas,vg_cas,temp_nudg_cas,qv_nudg_cas,u_nudg_cas,v_nudg_cas     &
+       ,invtau_temp_nudg_cas,invtau_qv_nudg_cas,invtau_u_nudg_cas,invtau_v_nudg_cas     &
+       ,vitw_cas,omega_cas,tke_cas,du_cas,hu_cas,vu_cas             &
+       ,dv_cas,hv_cas,vv_cas,dt_cas,ht_cas,vt_cas,dtrad_cas               &
+       ,dq_cas,hq_cas,vq_cas,dth_cas,hth_cas,vth_cas                      &
+       ,lat_cas,sens_cas,ustar_cas                                        &
+       ,uw_cas,vw_cas,q1_cas,q2_cas,tkes_cas                               &
+       !
+       ,ts_prof_cas,tskin_prof_cas,ps_prof_cas,plev_prof_cas,t_prof_cas,theta_prof_cas               &
+       ,thv_prof_cas,thl_prof_cas,qv_prof_cas,ql_prof_cas,qi_prof_cas     &
+       ,u_prof_cas,v_prof_cas,ug_prof_cas,vg_prof_cas                     &
+       ,temp_nudg_prof_cas,qv_nudg_prof_cas,u_nudg_prof_cas,v_nudg_prof_cas     &
+       ,invtau_temp_nudg_prof_cas,invtau_qv_nudg_prof_cas,invtau_u_nudg_prof_cas,invtau_v_nudg_prof_cas     &     
+       ,vitw_prof_cas,omega_prof_cas,tke_prof_cas,du_prof_cas,hu_prof_cas,vu_prof_cas  &
+       ,dv_prof_cas,hv_prof_cas,vv_prof_cas,dt_prof_cas                   &
+       ,ht_prof_cas,vt_prof_cas,dtrad_prof_cas,dq_prof_cas                &
+       ,hq_prof_cas,vq_prof_cas,dth_prof_cas,hth_prof_cas,vth_prof_cas    &
+       ,lat_prof_cas,sens_prof_cas                                        &
+       ,ustar_prof_cas,uw_prof_cas,vw_prof_cas,q1_prof_cas,q2_prof_cas,tkes_prof_cas)
+
+
+
+
+
+
+    implicit none
+
+    !---------------------------------------------------------------------------------------
+    ! Time interpolation of a 2D field to the timestep corresponding to day
+    !
+    ! day: current julian day (e.g. 717538.2)
+    ! day1: first day of the simulation
+    ! nt_cas: total nb of data in the forcing 
+    ! pdt_cas: total time interval (in sec) between 2 forcing data
+    !---------------------------------------------------------------------------------------
 
 #include "compar1d.h"
 #include "date_cas.h"
 
-! inputs:
-        integer annee_ref
-        integer nt_cas,nlev_cas
-        real day, day1,day_cas
-        real ts_cas(nt_cas),ps_cas(nt_cas)
-        real plev_cas(nlev_cas,nt_cas)
-        real t_cas(nlev_cas,nt_cas),theta_cas(nlev_cas,nt_cas)
-        real thv_cas(nlev_cas,nt_cas), thl_cas(nlev_cas,nt_cas)
-        real qv_cas(nlev_cas,nt_cas),ql_cas(nlev_cas,nt_cas),qi_cas(nlev_cas,nt_cas)
-        real u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas)
-        real ug_cas(nlev_cas,nt_cas),vg_cas(nlev_cas,nt_cas)
-        real temp_nudg_cas(nlev_cas,nt_cas),qv_nudg_cas(nlev_cas,nt_cas)
-        real u_nudg_cas(nlev_cas,nt_cas),v_nudg_cas(nlev_cas,nt_cas)
-
-        real invtau_temp_nudg_cas(nlev_cas,nt_cas),invtau_qv_nudg_cas(nlev_cas,nt_cas)
-        real invtau_u_nudg_cas(nlev_cas,nt_cas),invtau_v_nudg_cas(nlev_cas,nt_cas)
-
-        real vitw_cas(nlev_cas,nt_cas),omega_cas(nlev_cas,nt_cas),tke_cas(nlev_cas,nt_cas)
-        real du_cas(nlev_cas,nt_cas),hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas)
-        real dv_cas(nlev_cas,nt_cas),hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas)
-        real dt_cas(nlev_cas,nt_cas),ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas)
-        real dth_cas(nlev_cas,nt_cas),hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas)
-        real dtrad_cas(nlev_cas,nt_cas)
-        real dq_cas(nlev_cas,nt_cas),hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas)
-        real lat_cas(nt_cas),sens_cas(nt_cas),tkes_cas(nt_cas)
-        real ustar_cas(nt_cas),uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas)
-        real q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas)
-
-! outputs:
-        real plev_prof_cas(nlev_cas)
-        real t_prof_cas(nlev_cas),theta_prof_cas(nlev_cas),thl_prof_cas(nlev_cas),thv_prof_cas(nlev_cas)
-        real qv_prof_cas(nlev_cas),ql_prof_cas(nlev_cas),qi_prof_cas(nlev_cas)
-        real u_prof_cas(nlev_cas),v_prof_cas(nlev_cas)
-        real ug_prof_cas(nlev_cas),vg_prof_cas(nlev_cas)
-        real temp_nudg_prof_cas(nlev_cas),qv_nudg_prof_cas(nlev_cas)
-        real u_nudg_prof_cas(nlev_cas),v_nudg_prof_cas(nlev_cas)
-
-        real invtau_temp_nudg_prof_cas(nlev_cas),invtau_qv_nudg_prof_cas(nlev_cas)
-        real invtau_u_nudg_prof_cas(nlev_cas),invtau_v_nudg_prof_cas(nlev_cas)
-
-        real vitw_prof_cas(nlev_cas),omega_prof_cas(nlev_cas),tke_prof_cas(nlev_cas)
-        real du_prof_cas(nlev_cas),hu_prof_cas(nlev_cas),vu_prof_cas(nlev_cas)
-        real dv_prof_cas(nlev_cas),hv_prof_cas(nlev_cas),vv_prof_cas(nlev_cas)
-        real dt_prof_cas(nlev_cas),ht_prof_cas(nlev_cas),vt_prof_cas(nlev_cas)
-        real dth_prof_cas(nlev_cas),hth_prof_cas(nlev_cas),vth_prof_cas(nlev_cas)
-        real dtrad_prof_cas(nlev_cas)
-        real dq_prof_cas(nlev_cas),hq_prof_cas(nlev_cas),vq_prof_cas(nlev_cas)
-        real lat_prof_cas,sens_prof_cas,tkes_prof_cas,ts_prof_cas,ps_prof_cas,ustar_prof_cas
-        real uw_prof_cas(nlev_cas),vw_prof_cas(nlev_cas),q1_prof_cas(nlev_cas),q2_prof_cas(nlev_cas)
-! local:
-        integer it_cas1, it_cas2,k
-        real timeit,time_cas1,time_cas2,frac
-
-
-        print*,'Check time',day1,day_ju_ini_cas,day_deb+1,pdt_cas
-!       do k=1,nlev_cas
-!       print*,'debut de interp2_case_time, plev_cas=',k,plev_cas(k,1)
-!       enddo
-
-! On teste si la date du cas AMMA est correcte.
-! C est pour memoire car en fait les fichiers .def
-! sont censes etre corrects.
-! A supprimer a terme (MPL 20150623)
-!     if ((forcing_type.eq.10).and.(1.eq.0)) then
-! Check that initial day of the simulation consistent with AMMA case:
-!      if (annee_ref.ne.2006) then
-!       print*,'Pour AMMA, annee_ref doit etre 2006'
-!       print*,'Changer annee_ref dans run.def'
-!       stop
-!      endif
-!      if (annee_ref.eq.2006 .and. day1.lt.day_cas) then
-!       print*,'AMMA a debute le 10 juillet 2006',day1,day_cas
-!       print*,'Changer dayref dans run.def'
-!       stop
-!      endif
-!      if (annee_ref.eq.2006 .and. day1.gt.day_cas+1) then
-!       print*,'AMMA a fini le 11 juillet'
-!       print*,'Changer dayref ou nday dans run.def'
-!       stop
-!      endif
-!      endif
-
-! Determine timestep relative to the 1st day:
-!       timeit=(day-day1)*86400.
-!       if (annee_ref.eq.1992) then
-!        timeit=(day-day_cas)*86400.
-!       else
-!        timeit=(day+61.-1.)*86400. ! 61 days between Nov01 and Dec31 1992
-!       endif
-      timeit=(day-day_ju_ini_cas)*86400
-      print *,'day=',day
-      print *,'day_ju_ini_cas=',day_ju_ini_cas
-      print *,'pdt_cas=',pdt_cas
-      print *,'timeit=',timeit
-      print *,'nt_cas=',nt_cas
-
-! Determine the closest observation times:
-!       it_cas1=INT(timeit/pdt_cas)+1
-!       it_cas2=it_cas1 + 1
-!       time_cas1=(it_cas1-1)*pdt_cas
-!       time_cas2=(it_cas2-1)*pdt_cas
-
-       it_cas1=INT(timeit/pdt_cas)+1
-       IF (it_cas1 .EQ. nt_cas) THEN
+    ! inputs:
+    integer annee_ref
+    integer nt_cas,nlev_cas
+    real day, day1,day_cas
+    real ts_cas(nt_cas),tskin_cas(nt_cas),ps_cas(nt_cas)
+    real plev_cas(nlev_cas,nt_cas)
+    real t_cas(nlev_cas,nt_cas),theta_cas(nlev_cas,nt_cas)
+    real thv_cas(nlev_cas,nt_cas), thl_cas(nlev_cas,nt_cas)
+    real qv_cas(nlev_cas,nt_cas),ql_cas(nlev_cas,nt_cas),qi_cas(nlev_cas,nt_cas)
+    real u_cas(nlev_cas,nt_cas),v_cas(nlev_cas,nt_cas)
+    real ug_cas(nlev_cas,nt_cas),vg_cas(nlev_cas,nt_cas)
+    real temp_nudg_cas(nlev_cas,nt_cas),qv_nudg_cas(nlev_cas,nt_cas)
+    real u_nudg_cas(nlev_cas,nt_cas),v_nudg_cas(nlev_cas,nt_cas)
+
+    real invtau_temp_nudg_cas(nlev_cas,nt_cas),invtau_qv_nudg_cas(nlev_cas,nt_cas)
+    real invtau_u_nudg_cas(nlev_cas,nt_cas),invtau_v_nudg_cas(nlev_cas,nt_cas)
+
+    real vitw_cas(nlev_cas,nt_cas),omega_cas(nlev_cas,nt_cas),tke_cas(nlev_cas,nt_cas)
+    real du_cas(nlev_cas,nt_cas),hu_cas(nlev_cas,nt_cas),vu_cas(nlev_cas,nt_cas)
+    real dv_cas(nlev_cas,nt_cas),hv_cas(nlev_cas,nt_cas),vv_cas(nlev_cas,nt_cas)
+    real dt_cas(nlev_cas,nt_cas),ht_cas(nlev_cas,nt_cas),vt_cas(nlev_cas,nt_cas)
+    real dth_cas(nlev_cas,nt_cas),hth_cas(nlev_cas,nt_cas),vth_cas(nlev_cas,nt_cas)
+    real dtrad_cas(nlev_cas,nt_cas)
+    real dq_cas(nlev_cas,nt_cas),hq_cas(nlev_cas,nt_cas),vq_cas(nlev_cas,nt_cas)
+    real lat_cas(nt_cas),sens_cas(nt_cas),tkes_cas(nt_cas)
+    real ustar_cas(nt_cas),uw_cas(nlev_cas,nt_cas),vw_cas(nlev_cas,nt_cas)
+    real q1_cas(nlev_cas,nt_cas),q2_cas(nlev_cas,nt_cas)
+
+    ! outputs:
+    real plev_prof_cas(nlev_cas)
+    real t_prof_cas(nlev_cas),theta_prof_cas(nlev_cas),thl_prof_cas(nlev_cas),thv_prof_cas(nlev_cas)
+    real qv_prof_cas(nlev_cas),ql_prof_cas(nlev_cas),qi_prof_cas(nlev_cas)
+    real u_prof_cas(nlev_cas),v_prof_cas(nlev_cas)
+    real ug_prof_cas(nlev_cas),vg_prof_cas(nlev_cas)
+    real temp_nudg_prof_cas(nlev_cas),qv_nudg_prof_cas(nlev_cas)
+    real u_nudg_prof_cas(nlev_cas),v_nudg_prof_cas(nlev_cas)
+
+    real invtau_temp_nudg_prof_cas(nlev_cas),invtau_qv_nudg_prof_cas(nlev_cas)
+    real invtau_u_nudg_prof_cas(nlev_cas),invtau_v_nudg_prof_cas(nlev_cas)
+
+    real vitw_prof_cas(nlev_cas),omega_prof_cas(nlev_cas),tke_prof_cas(nlev_cas)
+    real du_prof_cas(nlev_cas),hu_prof_cas(nlev_cas),vu_prof_cas(nlev_cas)
+    real dv_prof_cas(nlev_cas),hv_prof_cas(nlev_cas),vv_prof_cas(nlev_cas)
+    real dt_prof_cas(nlev_cas),ht_prof_cas(nlev_cas),vt_prof_cas(nlev_cas)
+    real dth_prof_cas(nlev_cas),hth_prof_cas(nlev_cas),vth_prof_cas(nlev_cas)
+    real dtrad_prof_cas(nlev_cas)
+    real dq_prof_cas(nlev_cas),hq_prof_cas(nlev_cas),vq_prof_cas(nlev_cas)
+    real lat_prof_cas,sens_prof_cas,tkes_prof_cas,ts_prof_cas,tskin_prof_cas,ps_prof_cas,ustar_prof_cas
+    real uw_prof_cas(nlev_cas),vw_prof_cas(nlev_cas),q1_prof_cas(nlev_cas),q2_prof_cas(nlev_cas)
+    ! local:
+    integer it_cas1, it_cas2,k
+    real timeit,time_cas1,time_cas2,frac
+
+
+    print*,'Check time',day1,day_ju_ini_cas,day_deb+1,pdt_cas
+    !       do k=1,nlev_cas
+    !       print*,'debut de interp2_case_time, plev_cas=',k,plev_cas(k,1)
+    !       enddo
+
+    ! On teste si la date du cas AMMA est correcte.
+    ! C est pour memoire car en fait les fichiers .def
+    ! sont censes etre corrects.
+    ! A supprimer a terme (MPL 20150623)
+    !     if ((forcing_type.eq.10).and.(1.eq.0)) then
+    ! Check that initial day of the simulation consistent with AMMA case:
+    !      if (annee_ref.ne.2006) then
+    !       print*,'Pour AMMA, annee_ref doit etre 2006'
+    !       print*,'Changer annee_ref dans run.def'
+    !       stop
+    !      endif
+    !      if (annee_ref.eq.2006 .and. day1.lt.day_cas) then
+    !       print*,'AMMA a debute le 10 juillet 2006',day1,day_cas
+    !       print*,'Changer dayref dans run.def'
+    !       stop
+    !      endif
+    !      if (annee_ref.eq.2006 .and. day1.gt.day_cas+1) then
+    !       print*,'AMMA a fini le 11 juillet'
+    !       print*,'Changer dayref ou nday dans run.def'
+    !       stop
+    !      endif
+    !      endif
+
+    ! Determine timestep relative to the 1st day:
+    !       timeit=(day-day1)*86400.
+    !       if (annee_ref.eq.1992) then
+    !        timeit=(day-day_cas)*86400.
+    !       else
+    !        timeit=(day+61.-1.)*86400. ! 61 days between Nov01 and Dec31 1992
+    !       endif
+    timeit=(day-day_ju_ini_cas)*86400
+    print *,'day=',day
+    print *,'day_ju_ini_cas=',day_ju_ini_cas
+    print *,'pdt_cas=',pdt_cas
+    print *,'timeit=',timeit
+    print *,'nt_cas=',nt_cas
+
+    ! Determine the closest observation times:
+    !       it_cas1=INT(timeit/pdt_cas)+1
+    !       it_cas2=it_cas1 + 1
+    !       time_cas1=(it_cas1-1)*pdt_cas
+    !       time_cas2=(it_cas2-1)*pdt_cas
+
+    it_cas1=INT(timeit/pdt_cas)+1
+    IF (it_cas1 .EQ. nt_cas) THEN
        it_cas2=it_cas1 
-       ELSE
+    ELSE
        it_cas2=it_cas1 + 1
-       ENDIF
-       time_cas1=(it_cas1-1)*pdt_cas
-       time_cas2=(it_cas2-1)*pdt_cas
-!     print *,'timeit,pdt_cas,nt_cas=',timeit,pdt_cas,nt_cas
-!     print *,'it_cas1,it_cas2,time_cas1,time_cas2=',it_cas1,it_cas2,time_cas1,time_cas2
-
-       if (it_cas1 .gt. nt_cas) then 
-        write(*,*) 'PB-stop: day, day_ju_ini_cas,it_cas1, it_cas2, timeit: '            &
-     &        ,day,day_ju_ini_cas,it_cas1,it_cas2,timeit
-        stop
-       endif
-
-! time interpolation:
-       IF (it_cas1 .EQ. it_cas2) THEN
-          frac=0.
-       ELSE
-          frac=(time_cas2-timeit)/(time_cas2-time_cas1)
-          frac=max(frac,0.0)
-       ENDIF
-
-       lat_prof_cas = lat_cas(it_cas2)                                   &
-     &          -frac*(lat_cas(it_cas2)-lat_cas(it_cas1)) 
-       sens_prof_cas = sens_cas(it_cas2)                                 &
-     &          -frac*(sens_cas(it_cas2)-sens_cas(it_cas1))
-       tkes_prof_cas = tkes_cas(it_cas2)                                   &
-     &          -frac*(tkes_cas(it_cas2)-tkes_cas(it_cas1))
-       ts_prof_cas = ts_cas(it_cas2)                                     &
-     &          -frac*(ts_cas(it_cas2)-ts_cas(it_cas1))
-       ps_prof_cas = ps_cas(it_cas2)                                     &
-     &          -frac*(ps_cas(it_cas2)-ps_cas(it_cas1))
-       ustar_prof_cas = ustar_cas(it_cas2)                               &
-     &          -frac*(ustar_cas(it_cas2)-ustar_cas(it_cas1))
-
-       do k=1,nlev_cas
-        plev_prof_cas(k) = plev_cas(k,it_cas2)                           &     
-     &          -frac*(plev_cas(k,it_cas2)-plev_cas(k,it_cas1))
-        t_prof_cas(k) = t_cas(k,it_cas2)                                 &        
-     &          -frac*(t_cas(k,it_cas2)-t_cas(k,it_cas1))
-        !print *,'k,frac,plev_cas1,plev_cas2=',k,frac,plev_cas(k,it_cas1),plev_cas(k,it_cas2)
-        theta_prof_cas(k) = theta_cas(k,it_cas2)                         &                      
-     &          -frac*(theta_cas(k,it_cas2)-theta_cas(k,it_cas1))
-        thv_prof_cas(k) = thv_cas(k,it_cas2)                             &          
-     &          -frac*(thv_cas(k,it_cas2)-thv_cas(k,it_cas1))
-        thl_prof_cas(k) = thl_cas(k,it_cas2)                             &              
-     &          -frac*(thl_cas(k,it_cas2)-thl_cas(k,it_cas1))
-        qv_prof_cas(k) = qv_cas(k,it_cas2)                               &
-     &          -frac*(qv_cas(k,it_cas2)-qv_cas(k,it_cas1))
-        ql_prof_cas(k) = ql_cas(k,it_cas2)                               &
-     &          -frac*(ql_cas(k,it_cas2)-ql_cas(k,it_cas1))
-        qi_prof_cas(k) = qi_cas(k,it_cas2)                               &
-     &          -frac*(qi_cas(k,it_cas2)-qi_cas(k,it_cas1))
-        u_prof_cas(k) = u_cas(k,it_cas2)                                 &
-     &          -frac*(u_cas(k,it_cas2)-u_cas(k,it_cas1))
-        v_prof_cas(k) = v_cas(k,it_cas2)                                 &
-     &          -frac*(v_cas(k,it_cas2)-v_cas(k,it_cas1))
-        ug_prof_cas(k) = ug_cas(k,it_cas2)                               &
-     &          -frac*(ug_cas(k,it_cas2)-ug_cas(k,it_cas1))
-        vg_prof_cas(k) = vg_cas(k,it_cas2)                               &
-     &          -frac*(vg_cas(k,it_cas2)-vg_cas(k,it_cas1))
-        temp_nudg_prof_cas(k) = temp_nudg_cas(k,it_cas2)                    &
-     &          -frac*(temp_nudg_cas(k,it_cas2)-temp_nudg_cas(k,it_cas1))
-        qv_nudg_prof_cas(k) = qv_nudg_cas(k,it_cas2)                        &
-     &          -frac*(qv_nudg_cas(k,it_cas2)-qv_nudg_cas(k,it_cas1))
-        u_nudg_prof_cas(k) = u_nudg_cas(k,it_cas2)                          &
-     &          -frac*(u_nudg_cas(k,it_cas2)-u_nudg_cas(k,it_cas1))
-        v_nudg_prof_cas(k) = v_nudg_cas(k,it_cas2)                          &
-     &          -frac*(v_nudg_cas(k,it_cas2)-v_nudg_cas(k,it_cas1))
-        invtau_temp_nudg_prof_cas(k) = invtau_temp_nudg_cas(k,it_cas2)                    &
-     &          -frac*(invtau_temp_nudg_cas(k,it_cas2)-invtau_temp_nudg_cas(k,it_cas1))
-        invtau_qv_nudg_prof_cas(k) = invtau_qv_nudg_cas(k,it_cas2)                        &
-     &          -frac*(invtau_qv_nudg_cas(k,it_cas2)-invtau_qv_nudg_cas(k,it_cas1))
-        invtau_u_nudg_prof_cas(k) = invtau_u_nudg_cas(k,it_cas2)                          &
-     &          -frac*(invtau_u_nudg_cas(k,it_cas2)-invtau_u_nudg_cas(k,it_cas1))
-        invtau_v_nudg_prof_cas(k) = invtau_v_nudg_cas(k,it_cas2)                          &
-     &          -frac*(invtau_v_nudg_cas(k,it_cas2)-invtau_v_nudg_cas(k,it_cas1))
-        vitw_prof_cas(k) = vitw_cas(k,it_cas2)                           &
-     &          -frac*(vitw_cas(k,it_cas2)-vitw_cas(k,it_cas1))
-        omega_prof_cas(k) = omega_cas(k,it_cas2)                         &
-     &          -frac*(omega_cas(k,it_cas2)-omega_cas(k,it_cas1))
-        tke_prof_cas(k) = tke_cas(k,it_cas2)                         &
-     &          -frac*(tke_cas(k,it_cas2)-tke_cas(k,it_cas1))
-        du_prof_cas(k) = du_cas(k,it_cas2)                               &
-     &          -frac*(du_cas(k,it_cas2)-du_cas(k,it_cas1))
-        hu_prof_cas(k) = hu_cas(k,it_cas2)                               &
-     &          -frac*(hu_cas(k,it_cas2)-hu_cas(k,it_cas1))
-        vu_prof_cas(k) = vu_cas(k,it_cas2)                               &
-     &          -frac*(vu_cas(k,it_cas2)-vu_cas(k,it_cas1))
-        dv_prof_cas(k) = dv_cas(k,it_cas2)                               &
-     &          -frac*(dv_cas(k,it_cas2)-dv_cas(k,it_cas1))
-        hv_prof_cas(k) = hv_cas(k,it_cas2)                               &
-     &          -frac*(hv_cas(k,it_cas2)-hv_cas(k,it_cas1))
-        vv_prof_cas(k) = vv_cas(k,it_cas2)                               &
-     &          -frac*(vv_cas(k,it_cas2)-vv_cas(k,it_cas1))
-        dt_prof_cas(k) = dt_cas(k,it_cas2)                               &
-     &          -frac*(dt_cas(k,it_cas2)-dt_cas(k,it_cas1))
-        ht_prof_cas(k) = ht_cas(k,it_cas2)                               &
-     &          -frac*(ht_cas(k,it_cas2)-ht_cas(k,it_cas1))
-        vt_prof_cas(k) = vt_cas(k,it_cas2)                               &
-     &          -frac*(vt_cas(k,it_cas2)-vt_cas(k,it_cas1))
-        dth_prof_cas(k) = dth_cas(k,it_cas2)                             &
-     &          -frac*(dth_cas(k,it_cas2)-dth_cas(k,it_cas1))
-        hth_prof_cas(k) = hth_cas(k,it_cas2)                             &
-     &          -frac*(hth_cas(k,it_cas2)-hth_cas(k,it_cas1))
-        vth_prof_cas(k) = vth_cas(k,it_cas2)                             &
-     &          -frac*(vth_cas(k,it_cas2)-vth_cas(k,it_cas1))
-        dtrad_prof_cas(k) = dtrad_cas(k,it_cas2)                         &
-     &          -frac*(dtrad_cas(k,it_cas2)-dtrad_cas(k,it_cas1))
-        dq_prof_cas(k) = dq_cas(k,it_cas2)                               &
-     &          -frac*(dq_cas(k,it_cas2)-dq_cas(k,it_cas1))
-        hq_prof_cas(k) = hq_cas(k,it_cas2)                               &
-     &          -frac*(hq_cas(k,it_cas2)-hq_cas(k,it_cas1))
-        vq_prof_cas(k) = vq_cas(k,it_cas2)                               &
-     &          -frac*(vq_cas(k,it_cas2)-vq_cas(k,it_cas1))
+    ENDIF
+    time_cas1=(it_cas1-1)*pdt_cas
+    time_cas2=(it_cas2-1)*pdt_cas
+    !     print *,'timeit,pdt_cas,nt_cas=',timeit,pdt_cas,nt_cas
+    !     print *,'it_cas1,it_cas2,time_cas1,time_cas2=',it_cas1,it_cas2,time_cas1,time_cas2
+
+    if (it_cas1 .gt. nt_cas) then 
+       write(*,*) 'PB-stop: day, day_ju_ini_cas,it_cas1, it_cas2, timeit: '            &
+            ,day,day_ju_ini_cas,it_cas1,it_cas2,timeit
+       stop
+    endif
+
+    ! time interpolation:
+    IF (it_cas1 .EQ. it_cas2) THEN
+       frac=0.
+    ELSE
+       frac=(time_cas2-timeit)/(time_cas2-time_cas1)
+       frac=max(frac,0.0)
+    ENDIF
+
+    lat_prof_cas = lat_cas(it_cas2)                                   &
+         -frac*(lat_cas(it_cas2)-lat_cas(it_cas1)) 
+    sens_prof_cas = sens_cas(it_cas2)                                 &
+         -frac*(sens_cas(it_cas2)-sens_cas(it_cas1))
+    tkes_prof_cas = tkes_cas(it_cas2)                                   &
+         -frac*(tkes_cas(it_cas2)-tkes_cas(it_cas1))
+    ts_prof_cas = ts_cas(it_cas2)                                     &
+         -frac*(ts_cas(it_cas2)-ts_cas(it_cas1))
+    tskin_prof_cas = tskin_cas(it_cas2)                                     &
+         -frac*(tskin_cas(it_cas2)-tskin_cas(it_cas1))
+    ps_prof_cas = ps_cas(it_cas2)                                     &
+         -frac*(ps_cas(it_cas2)-ps_cas(it_cas1))
+    ustar_prof_cas = ustar_cas(it_cas2)                               &
+         -frac*(ustar_cas(it_cas2)-ustar_cas(it_cas1))
+
+    do k=1,nlev_cas
+       plev_prof_cas(k) = plev_cas(k,it_cas2)                           &     
+            -frac*(plev_cas(k,it_cas2)-plev_cas(k,it_cas1))
+       t_prof_cas(k) = t_cas(k,it_cas2)                                 &        
+            -frac*(t_cas(k,it_cas2)-t_cas(k,it_cas1))
+       !print *,'k,frac,plev_cas1,plev_cas2=',k,frac,plev_cas(k,it_cas1),plev_cas(k,it_cas2)
+       theta_prof_cas(k) = theta_cas(k,it_cas2)                         &                      
+            -frac*(theta_cas(k,it_cas2)-theta_cas(k,it_cas1))
+       thv_prof_cas(k) = thv_cas(k,it_cas2)                             &          
+            -frac*(thv_cas(k,it_cas2)-thv_cas(k,it_cas1))
+       thl_prof_cas(k) = thl_cas(k,it_cas2)                             &              
+            -frac*(thl_cas(k,it_cas2)-thl_cas(k,it_cas1))
+       qv_prof_cas(k) = qv_cas(k,it_cas2)                               &
+            -frac*(qv_cas(k,it_cas2)-qv_cas(k,it_cas1))
+       ql_prof_cas(k) = ql_cas(k,it_cas2)                               &
+            -frac*(ql_cas(k,it_cas2)-ql_cas(k,it_cas1))
+       qi_prof_cas(k) = qi_cas(k,it_cas2)                               &
+            -frac*(qi_cas(k,it_cas2)-qi_cas(k,it_cas1))
+       u_prof_cas(k) = u_cas(k,it_cas2)                                 &
+            -frac*(u_cas(k,it_cas2)-u_cas(k,it_cas1))
+       v_prof_cas(k) = v_cas(k,it_cas2)                                 &
+            -frac*(v_cas(k,it_cas2)-v_cas(k,it_cas1))
+       ug_prof_cas(k) = ug_cas(k,it_cas2)                               &
+            -frac*(ug_cas(k,it_cas2)-ug_cas(k,it_cas1))
+       vg_prof_cas(k) = vg_cas(k,it_cas2)                               &
+            -frac*(vg_cas(k,it_cas2)-vg_cas(k,it_cas1))
+       temp_nudg_prof_cas(k) = temp_nudg_cas(k,it_cas2)                    &
+            -frac*(temp_nudg_cas(k,it_cas2)-temp_nudg_cas(k,it_cas1))
+       qv_nudg_prof_cas(k) = qv_nudg_cas(k,it_cas2)                        &
+            -frac*(qv_nudg_cas(k,it_cas2)-qv_nudg_cas(k,it_cas1))
+       u_nudg_prof_cas(k) = u_nudg_cas(k,it_cas2)                          &
+            -frac*(u_nudg_cas(k,it_cas2)-u_nudg_cas(k,it_cas1))
+       v_nudg_prof_cas(k) = v_nudg_cas(k,it_cas2)                          &
+            -frac*(v_nudg_cas(k,it_cas2)-v_nudg_cas(k,it_cas1))
+       invtau_temp_nudg_prof_cas(k) = invtau_temp_nudg_cas(k,it_cas2)                    &
+            -frac*(invtau_temp_nudg_cas(k,it_cas2)-invtau_temp_nudg_cas(k,it_cas1))
+       invtau_qv_nudg_prof_cas(k) = invtau_qv_nudg_cas(k,it_cas2)                        &
+            -frac*(invtau_qv_nudg_cas(k,it_cas2)-invtau_qv_nudg_cas(k,it_cas1))
+       invtau_u_nudg_prof_cas(k) = invtau_u_nudg_cas(k,it_cas2)                          &
+            -frac*(invtau_u_nudg_cas(k,it_cas2)-invtau_u_nudg_cas(k,it_cas1))
+       invtau_v_nudg_prof_cas(k) = invtau_v_nudg_cas(k,it_cas2)                          &
+            -frac*(invtau_v_nudg_cas(k,it_cas2)-invtau_v_nudg_cas(k,it_cas1))
+       vitw_prof_cas(k) = vitw_cas(k,it_cas2)                           &
+            -frac*(vitw_cas(k,it_cas2)-vitw_cas(k,it_cas1))
+       omega_prof_cas(k) = omega_cas(k,it_cas2)                         &
+            -frac*(omega_cas(k,it_cas2)-omega_cas(k,it_cas1))
+       tke_prof_cas(k) = tke_cas(k,it_cas2)                         &
+            -frac*(tke_cas(k,it_cas2)-tke_cas(k,it_cas1))
+       du_prof_cas(k) = du_cas(k,it_cas2)                               &
+            -frac*(du_cas(k,it_cas2)-du_cas(k,it_cas1))
+       hu_prof_cas(k) = hu_cas(k,it_cas2)                               &
+            -frac*(hu_cas(k,it_cas2)-hu_cas(k,it_cas1))
+       vu_prof_cas(k) = vu_cas(k,it_cas2)                               &
+            -frac*(vu_cas(k,it_cas2)-vu_cas(k,it_cas1))
+       dv_prof_cas(k) = dv_cas(k,it_cas2)                               &
+            -frac*(dv_cas(k,it_cas2)-dv_cas(k,it_cas1))
+       hv_prof_cas(k) = hv_cas(k,it_cas2)                               &
+            -frac*(hv_cas(k,it_cas2)-hv_cas(k,it_cas1))
+       vv_prof_cas(k) = vv_cas(k,it_cas2)                               &
+            -frac*(vv_cas(k,it_cas2)-vv_cas(k,it_cas1))
+       dt_prof_cas(k) = dt_cas(k,it_cas2)                               &
+            -frac*(dt_cas(k,it_cas2)-dt_cas(k,it_cas1))
+       ht_prof_cas(k) = ht_cas(k,it_cas2)                               &
+            -frac*(ht_cas(k,it_cas2)-ht_cas(k,it_cas1))
+       vt_prof_cas(k) = vt_cas(k,it_cas2)                               &
+            -frac*(vt_cas(k,it_cas2)-vt_cas(k,it_cas1))
+       dth_prof_cas(k) = dth_cas(k,it_cas2)                             &
+            -frac*(dth_cas(k,it_cas2)-dth_cas(k,it_cas1))
+       hth_prof_cas(k) = hth_cas(k,it_cas2)                             &
+            -frac*(hth_cas(k,it_cas2)-hth_cas(k,it_cas1))
+       vth_prof_cas(k) = vth_cas(k,it_cas2)                             &
+            -frac*(vth_cas(k,it_cas2)-vth_cas(k,it_cas1))
+       dtrad_prof_cas(k) = dtrad_cas(k,it_cas2)                         &
+            -frac*(dtrad_cas(k,it_cas2)-dtrad_cas(k,it_cas1))
+       dq_prof_cas(k) = dq_cas(k,it_cas2)                               &
+            -frac*(dq_cas(k,it_cas2)-dq_cas(k,it_cas1))
+       hq_prof_cas(k) = hq_cas(k,it_cas2)                               &
+            -frac*(hq_cas(k,it_cas2)-hq_cas(k,it_cas1))
+       vq_prof_cas(k) = vq_cas(k,it_cas2)                               &
+            -frac*(vq_cas(k,it_cas2)-vq_cas(k,it_cas1))
        uw_prof_cas(k) = uw_cas(k,it_cas2)                                &
-     &          -frac*(uw_cas(k,it_cas2)-uw_cas(k,it_cas1))
+            -frac*(uw_cas(k,it_cas2)-uw_cas(k,it_cas1))
        vw_prof_cas(k) = vw_cas(k,it_cas2)                                &
-     &          -frac*(vw_cas(k,it_cas2)-vw_cas(k,it_cas1))
+            -frac*(vw_cas(k,it_cas2)-vw_cas(k,it_cas1))
        q1_prof_cas(k) = q1_cas(k,it_cas2)                                &
-     &          -frac*(q1_cas(k,it_cas2)-q1_cas(k,it_cas1))
+            -frac*(q1_cas(k,it_cas2)-q1_cas(k,it_cas1))
        q2_prof_cas(k) = q2_cas(k,it_cas2)                                &
-     &          -frac*(q2_cas(k,it_cas2)-q2_cas(k,it_cas1))
-        enddo
-
-        return
-        END SUBROUTINE interp_case_time_std
-
-!**********************************************************************************************
-!=====================================================================
-       SUBROUTINE interp2_case_vertical_std(play,plev,nlev_cas,plev_prof_cas                           &
-     &         ,t_prof_cas,th_prof_cas,thv_prof_cas,thl_prof_cas                                       &
-     &         ,qv_prof_cas,ql_prof_cas,qi_prof_cas,u_prof_cas,v_prof_cas                              &
-     &         ,ug_prof_cas,vg_prof_cas                                                                &
-     &         ,temp_nudg_prof_cas,qv_nudg_prof_cas,u_nudg_prof_cas,v_nudg_prof_cas                    &
-     &         ,invtau_temp_nudg_prof_cas,invtau_qv_nudg_prof_cas,invtau_u_nudg_prof_cas,invtau_v_nudg_prof_cas &     
-     &         ,vitw_prof_cas,omega_prof_cas,tke_prof_cas                                              &
-     &         ,du_prof_cas,hu_prof_cas,vu_prof_cas,dv_prof_cas,hv_prof_cas,vv_prof_cas                &
-     &         ,dt_prof_cas,ht_prof_cas,vt_prof_cas,dtrad_prof_cas,dq_prof_cas,hq_prof_cas,vq_prof_cas &
-     &         ,dth_prof_cas,hth_prof_cas,vth_prof_cas                                                 &
-!
-     &         ,t_mod_cas,theta_mod_cas,thv_mod_cas,thl_mod_cas                                        &
-     &         ,qv_mod_cas,ql_mod_cas,qi_mod_cas,u_mod_cas,v_mod_cas                                   &
-     &         ,ug_mod_cas,vg_mod_cas                                                                  &
-     &         ,temp_nudg_mod_cas,qv_nudg_mod_cas,u_nudg_mod_cas,v_nudg_mod_cas                        &
-     &         ,invtau_temp_nudg_mod_cas,invtau_qv_nudg_mod_cas,invtau_u_nudg_mod_cas,invtau_v_nudg_mod_cas                        &     
-     &         ,w_mod_cas,omega_mod_cas,tke_mod_cas                                                    &
-     &         ,du_mod_cas,hu_mod_cas,vu_mod_cas,dv_mod_cas,hv_mod_cas,vv_mod_cas                      &
-     &         ,dt_mod_cas,ht_mod_cas,vt_mod_cas,dtrad_mod_cas,dq_mod_cas,hq_mod_cas,vq_mod_cas        &
-     &         ,dth_mod_cas,hth_mod_cas,vth_mod_cas,mxcalc)
- 
-       implicit none
- 
+            -frac*(q2_cas(k,it_cas2)-q2_cas(k,it_cas1))
+    enddo
+
+    return
+  END SUBROUTINE interp_case_time_std
+
+  !**********************************************************************************************
+  !=====================================================================
+  SUBROUTINE interp2_case_vertical_std(play,plev,nlev_cas,plev_prof_cas                           &
+       ,t_prof_cas,th_prof_cas,thv_prof_cas,thl_prof_cas                                       &
+       ,qv_prof_cas,ql_prof_cas,qi_prof_cas,u_prof_cas,v_prof_cas                              &
+       ,ug_prof_cas,vg_prof_cas                                                                &
+       ,temp_nudg_prof_cas,qv_nudg_prof_cas,u_nudg_prof_cas,v_nudg_prof_cas                    &
+       ,invtau_temp_nudg_prof_cas,invtau_qv_nudg_prof_cas,invtau_u_nudg_prof_cas,invtau_v_nudg_prof_cas &     
+       ,vitw_prof_cas,omega_prof_cas,tke_prof_cas                                              &
+       ,du_prof_cas,hu_prof_cas,vu_prof_cas,dv_prof_cas,hv_prof_cas,vv_prof_cas                &
+       ,dt_prof_cas,ht_prof_cas,vt_prof_cas,dtrad_prof_cas,dq_prof_cas,hq_prof_cas,vq_prof_cas &
+       ,dth_prof_cas,hth_prof_cas,vth_prof_cas                                                 &
+       !
+       ,t_mod_cas,theta_mod_cas,thv_mod_cas,thl_mod_cas                                        &
+       ,qv_mod_cas,ql_mod_cas,qi_mod_cas,u_mod_cas,v_mod_cas                                   &
+       ,ug_mod_cas,vg_mod_cas                                                                  &
+       ,temp_nudg_mod_cas,qv_nudg_mod_cas,u_nudg_mod_cas,v_nudg_mod_cas                        &
+       ,invtau_temp_nudg_mod_cas,invtau_qv_nudg_mod_cas,invtau_u_nudg_mod_cas,invtau_v_nudg_mod_cas                        &     
+       ,w_mod_cas,omega_mod_cas,tke_mod_cas                                                    &
+       ,du_mod_cas,hu_mod_cas,vu_mod_cas,dv_mod_cas,hv_mod_cas,vv_mod_cas                      &
+       ,dt_mod_cas,ht_mod_cas,vt_mod_cas,dtrad_mod_cas,dq_mod_cas,hq_mod_cas,vq_mod_cas        &
+       ,dth_mod_cas,hth_mod_cas,vth_mod_cas,mxcalc)
+
+    implicit none
+
 #include "YOMCST.h"
 #include "dimensions.h"
 
-!-------------------------------------------------------------------------
-! Vertical interpolation of generic case forcing data onto mod_casel levels
-!-------------------------------------------------------------------------
- 
-       integer nlevmax
-       parameter (nlevmax=41)
-       integer nlev_cas,mxcalc
-!       real play(llm), plev_prof(nlevmax) 
-!       real t_prof(nlevmax),q_prof(nlevmax)
-!       real u_prof(nlevmax),v_prof(nlevmax), w_prof(nlevmax)
-!       real ht_prof(nlevmax),vt_prof(nlevmax)
-!       real hq_prof(nlevmax),vq_prof(nlevmax)
- 
-       real play(llm), plev(llm+1), plev_prof_cas(nlev_cas) 
-       real t_prof_cas(nlev_cas),th_prof_cas(nlev_cas),thv_prof_cas(nlev_cas),thl_prof_cas(nlev_cas)
-       real qv_prof_cas(nlev_cas),ql_prof_cas(nlev_cas),qi_prof_cas(nlev_cas)
-       real u_prof_cas(nlev_cas),v_prof_cas(nlev_cas)
-       real ug_prof_cas(nlev_cas),vg_prof_cas(nlev_cas), vitw_prof_cas(nlev_cas),omega_prof_cas(nlev_cas),tke_prof_cas(nlev_cas)
-       real temp_nudg_prof_cas(nlev_cas),qv_nudg_prof_cas(nlev_cas)
-       real u_nudg_prof_cas(nlev_cas),v_nudg_prof_cas(nlev_cas)
-       real invtau_temp_nudg_prof_cas(nlev_cas),invtau_qv_nudg_prof_cas(nlev_cas)
-       real invtau_u_nudg_prof_cas(nlev_cas),invtau_v_nudg_prof_cas(nlev_cas)
-
-       real du_prof_cas(nlev_cas),hu_prof_cas(nlev_cas),vu_prof_cas(nlev_cas)
-       real dv_prof_cas(nlev_cas),hv_prof_cas(nlev_cas),vv_prof_cas(nlev_cas)
-       real dt_prof_cas(nlev_cas),ht_prof_cas(nlev_cas),vt_prof_cas(nlev_cas),dtrad_prof_cas(nlev_cas)
-       real dth_prof_cas(nlev_cas),hth_prof_cas(nlev_cas),vth_prof_cas(nlev_cas)
-       real dq_prof_cas(nlev_cas),hq_prof_cas(nlev_cas),vq_prof_cas(nlev_cas)
- 
-       real t_mod_cas(llm),theta_mod_cas(llm),thv_mod_cas(llm),thl_mod_cas(llm)
-       real qv_mod_cas(llm),ql_mod_cas(llm),qi_mod_cas(llm)
-       real u_mod_cas(llm),v_mod_cas(llm)
-       real ug_mod_cas(llm),vg_mod_cas(llm), w_mod_cas(llm),omega_mod_cas(llm),tke_mod_cas(llm+1)
-       real temp_nudg_mod_cas(llm),qv_nudg_mod_cas(llm)
-       real u_nudg_mod_cas(llm),v_nudg_mod_cas(llm)
-       real invtau_temp_nudg_mod_cas(llm),invtau_qv_nudg_mod_cas(llm)
-       real invtau_u_nudg_mod_cas(llm),invtau_v_nudg_mod_cas(llm)
-       real du_mod_cas(llm),hu_mod_cas(llm),vu_mod_cas(llm)
-       real dv_mod_cas(llm),hv_mod_cas(llm),vv_mod_cas(llm)
-       real dt_mod_cas(llm),ht_mod_cas(llm),vt_mod_cas(llm),dtrad_mod_cas(llm)
-       real dth_mod_cas(llm),hth_mod_cas(llm),vth_mod_cas(llm)
-       real dq_mod_cas(llm),hq_mod_cas(llm),vq_mod_cas(llm)
- 
-       integer l,k,k1,k2
-       real frac,frac1,frac2,fact
- 
-
-
-! for variables defined at the middle of layers
-
-       do l = 1, llm
-
-        if (play(l).ge.plev_prof_cas(nlev_cas)) then
- 
-        mxcalc=l
-!        print *,'debut interp2, mxcalc=',mxcalc
-         k1=0
-         k2=0
-
-         if (play(l).le.plev_prof_cas(1)) then
-
-         do k = 1, nlev_cas-1
-          if (play(l).le.plev_prof_cas(k).and. play(l).gt.plev_prof_cas(k+1)) then
-            k1=k
-            k2=k+1
-          endif
-         enddo
-
-         if (k1.eq.0 .or. k2.eq.0) then
-          write(*,*) 'PB! k1, k2 = ',k1,k2
-          write(*,*) 'l,play(l) = ',l,play(l)/100
-         do k = 1, nlev_cas-1
-          write(*,*) 'k,plev_prof_cas(k) = ',k,plev_prof_cas(k)/100
-         enddo
-         endif
-
-
-
-         frac = (plev_prof_cas(k2)-play(l))/(plev_prof_cas(k2)-plev_prof_cas(k1))
-         
-         t_mod_cas(l)= t_prof_cas(k2) - frac*(t_prof_cas(k2)-t_prof_cas(k1))
-         theta_mod_cas(l)= th_prof_cas(k2) - frac*(th_prof_cas(k2)-th_prof_cas(k1))
-         if(theta_mod_cas(l).NE.0) t_mod_cas(l)= theta_mod_cas(l)*(play(l)/100000.)**(RD/RCPD)
-         thv_mod_cas(l)= thv_prof_cas(k2) - frac*(thv_prof_cas(k2)-thv_prof_cas(k1))
-         thl_mod_cas(l)= thl_prof_cas(k2) - frac*(thl_prof_cas(k2)-thl_prof_cas(k1))
-         qv_mod_cas(l)= qv_prof_cas(k2) - frac*(qv_prof_cas(k2)-qv_prof_cas(k1))
-         ql_mod_cas(l)= ql_prof_cas(k2) - frac*(ql_prof_cas(k2)-ql_prof_cas(k1))
-         qi_mod_cas(l)= qi_prof_cas(k2) - frac*(qi_prof_cas(k2)-qi_prof_cas(k1))
-         u_mod_cas(l)= u_prof_cas(k2) - frac*(u_prof_cas(k2)-u_prof_cas(k1))
-         v_mod_cas(l)= v_prof_cas(k2) - frac*(v_prof_cas(k2)-v_prof_cas(k1))
-         ug_mod_cas(l)= ug_prof_cas(k2) - frac*(ug_prof_cas(k2)-ug_prof_cas(k1))
-         vg_mod_cas(l)= vg_prof_cas(k2) - frac*(vg_prof_cas(k2)-vg_prof_cas(k1))
-         temp_nudg_mod_cas(l)= temp_nudg_prof_cas(k2) - frac*(temp_nudg_prof_cas(k2)-temp_nudg_prof_cas(k1))
-         qv_nudg_mod_cas(l)= qv_nudg_prof_cas(k2) - frac*(qv_nudg_prof_cas(k2)-qv_nudg_prof_cas(k1))
-         u_nudg_mod_cas(l)= u_nudg_prof_cas(k2) - frac*(u_nudg_prof_cas(k2)-u_nudg_prof_cas(k1))
-         v_nudg_mod_cas(l)= v_nudg_prof_cas(k2) - frac*(v_nudg_prof_cas(k2)-v_nudg_prof_cas(k1))
-
-         invtau_temp_nudg_mod_cas(l)= invtau_temp_nudg_prof_cas(k2) - frac*(invtau_temp_nudg_prof_cas(k2)-invtau_temp_nudg_prof_cas(k1))
-         invtau_qv_nudg_mod_cas(l)= invtau_qv_nudg_prof_cas(k2) - frac*(invtau_qv_nudg_prof_cas(k2)-invtau_qv_nudg_prof_cas(k1))
-         invtau_u_nudg_mod_cas(l)= invtau_u_nudg_prof_cas(k2) - frac*(invtau_u_nudg_prof_cas(k2)-invtau_u_nudg_prof_cas(k1))
-         invtau_v_nudg_mod_cas(l)= invtau_v_nudg_prof_cas(k2) - frac*(invtau_v_nudg_prof_cas(k2)-invtau_v_nudg_prof_cas(k1))
-
-         w_mod_cas(l)= vitw_prof_cas(k2) - frac*(vitw_prof_cas(k2)-vitw_prof_cas(k1))
-         omega_mod_cas(l)= omega_prof_cas(k2) - frac*(omega_prof_cas(k2)-omega_prof_cas(k1))
-         du_mod_cas(l)= du_prof_cas(k2) - frac*(du_prof_cas(k2)-du_prof_cas(k1))
-         hu_mod_cas(l)= hu_prof_cas(k2) - frac*(hu_prof_cas(k2)-hu_prof_cas(k1))
-         vu_mod_cas(l)= vu_prof_cas(k2) - frac*(vu_prof_cas(k2)-vu_prof_cas(k1))
-         dv_mod_cas(l)= dv_prof_cas(k2) - frac*(dv_prof_cas(k2)-dv_prof_cas(k1))
-         hv_mod_cas(l)= hv_prof_cas(k2) - frac*(hv_prof_cas(k2)-hv_prof_cas(k1))
-         vv_mod_cas(l)= vv_prof_cas(k2) - frac*(vv_prof_cas(k2)-vv_prof_cas(k1))
-         dt_mod_cas(l)= dt_prof_cas(k2) - frac*(dt_prof_cas(k2)-dt_prof_cas(k1))
-         ht_mod_cas(l)= ht_prof_cas(k2) - frac*(ht_prof_cas(k2)-ht_prof_cas(k1))
-         vt_mod_cas(l)= vt_prof_cas(k2) - frac*(vt_prof_cas(k2)-vt_prof_cas(k1))
-         dth_mod_cas(l)= dth_prof_cas(k2) - frac*(dth_prof_cas(k2)-dth_prof_cas(k1))
-         hth_mod_cas(l)= hth_prof_cas(k2) - frac*(hth_prof_cas(k2)-hth_prof_cas(k1))
-         vth_mod_cas(l)= vth_prof_cas(k2) - frac*(vth_prof_cas(k2)-vth_prof_cas(k1))
-         dq_mod_cas(l)= dq_prof_cas(k2) - frac*(dq_prof_cas(k2)-dq_prof_cas(k1))
-         hq_mod_cas(l)= hq_prof_cas(k2) - frac*(hq_prof_cas(k2)-hq_prof_cas(k1))
-         vq_mod_cas(l)= vq_prof_cas(k2) - frac*(vq_prof_cas(k2)-vq_prof_cas(k1))
-         dtrad_mod_cas(l)= dtrad_prof_cas(k2) - frac*(dtrad_prof_cas(k2)-dtrad_prof_cas(k1))
-     
-         else !play>plev_prof_cas(1)
-
-         k1=1
-         k2=2
-         print *,'interp2_vert, k1,k2=',plev_prof_cas(k1),plev_prof_cas(k2)
-         frac1 = (play(l)-plev_prof_cas(k2))/(plev_prof_cas(k1)-plev_prof_cas(k2))
-         frac2 = (play(l)-plev_prof_cas(k1))/(plev_prof_cas(k1)-plev_prof_cas(k2))
-         t_mod_cas(l)= frac1*t_prof_cas(k1) - frac2*t_prof_cas(k2)
-         theta_mod_cas(l)= frac1*th_prof_cas(k1) - frac2*th_prof_cas(k2)
-         if(theta_mod_cas(l).NE.0) t_mod_cas(l)= theta_mod_cas(l)*(play(l)/100000.)**(RD/RCPD)
-         thv_mod_cas(l)= frac1*thv_prof_cas(k1) - frac2*thv_prof_cas(k2)
-         thl_mod_cas(l)= frac1*thl_prof_cas(k1) - frac2*thl_prof_cas(k2)
-         qv_mod_cas(l)= frac1*qv_prof_cas(k1) - frac2*qv_prof_cas(k2)
-         ql_mod_cas(l)= frac1*ql_prof_cas(k1) - frac2*ql_prof_cas(k2)
-         qi_mod_cas(l)= frac1*qi_prof_cas(k1) - frac2*qi_prof_cas(k2)
-         u_mod_cas(l)= frac1*u_prof_cas(k1) - frac2*u_prof_cas(k2)
-         v_mod_cas(l)= frac1*v_prof_cas(k1) - frac2*v_prof_cas(k2)
-         ug_mod_cas(l)= frac1*ug_prof_cas(k1) - frac2*ug_prof_cas(k2)
-         vg_mod_cas(l)= frac1*vg_prof_cas(k1) - frac2*vg_prof_cas(k2)
-         temp_nudg_mod_cas(l)= frac1*temp_nudg_prof_cas(k1) - frac2*temp_nudg_prof_cas(k2)
-         qv_nudg_mod_cas(l)= frac1*qv_nudg_prof_cas(k1) - frac2*qv_nudg_prof_cas(k2)
-         u_nudg_mod_cas(l)= frac1*u_nudg_prof_cas(k1) - frac2*u_nudg_prof_cas(k2)
-         v_nudg_mod_cas(l)= frac1*v_nudg_prof_cas(k1) - frac2*v_nudg_prof_cas(k2)
-
-         invtau_temp_nudg_mod_cas(l)= frac1*invtau_temp_nudg_prof_cas(k1) - frac2*invtau_temp_nudg_prof_cas(k2)
-         invtau_qv_nudg_mod_cas(l)= frac1*invtau_qv_nudg_prof_cas(k1) - frac2*invtau_qv_nudg_prof_cas(k2)
-         invtau_u_nudg_mod_cas(l)= frac1*invtau_u_nudg_prof_cas(k1) - frac2*invtau_u_nudg_prof_cas(k2)
-         invtau_v_nudg_mod_cas(l)= frac1*invtau_v_nudg_prof_cas(k1) - frac2*invtau_v_nudg_prof_cas(k2)
-
-         w_mod_cas(l)= frac1*vitw_prof_cas(k1) - frac2*vitw_prof_cas(k2)
-         omega_mod_cas(l)= frac1*omega_prof_cas(k1) - frac2*omega_prof_cas(k2)
-         du_mod_cas(l)= frac1*du_prof_cas(k1) - frac2*du_prof_cas(k2)
-         hu_mod_cas(l)= frac1*hu_prof_cas(k1) - frac2*hu_prof_cas(k2)
-         vu_mod_cas(l)= frac1*vu_prof_cas(k1) - frac2*vu_prof_cas(k2)
-         dv_mod_cas(l)= frac1*dv_prof_cas(k1) - frac2*dv_prof_cas(k2)
-         hv_mod_cas(l)= frac1*hv_prof_cas(k1) - frac2*hv_prof_cas(k2)
-         vv_mod_cas(l)= frac1*vv_prof_cas(k1) - frac2*vv_prof_cas(k2)
-         dt_mod_cas(l)= frac1*dt_prof_cas(k1) - frac2*dt_prof_cas(k2)
-         ht_mod_cas(l)= frac1*ht_prof_cas(k1) - frac2*ht_prof_cas(k2)
-         vt_mod_cas(l)= frac1*vt_prof_cas(k1) - frac2*vt_prof_cas(k2)
-         dth_mod_cas(l)= frac1*dth_prof_cas(k1) - frac2*dth_prof_cas(k2)
-         hth_mod_cas(l)= frac1*hth_prof_cas(k1) - frac2*hth_prof_cas(k2)
-         vth_mod_cas(l)= frac1*vth_prof_cas(k1) - frac2*vth_prof_cas(k2)
-         dq_mod_cas(l)= frac1*dq_prof_cas(k1) - frac2*dq_prof_cas(k2)
-         hq_mod_cas(l)= frac1*hq_prof_cas(k1) - frac2*hq_prof_cas(k2)
-         vq_mod_cas(l)= frac1*vq_prof_cas(k1) - frac2*vq_prof_cas(k2)
-         dtrad_mod_cas(l)= frac1*dtrad_prof_cas(k1) - frac2*dtrad_prof_cas(k2)
-
-         endif ! play.le.plev_prof_cas(1)
-
-        else ! above max altitude of forcing file
- 
-!jyg
-         fact=20.*(plev_prof_cas(nlev_cas)-play(l))/plev_prof_cas(nlev_cas) !jyg
-         fact = max(fact,0.)                                           !jyg
-         fact = exp(-fact)                                             !jyg
-         t_mod_cas(l)= t_prof_cas(nlev_cas)                            !jyg
-         theta_mod_cas(l)= th_prof_cas(nlev_cas)                       !jyg
-         thv_mod_cas(l)= thv_prof_cas(nlev_cas)                        !jyg
-         thl_mod_cas(l)= thl_prof_cas(nlev_cas)                        !jyg
-         qv_mod_cas(l)= qv_prof_cas(nlev_cas)*fact                     !jyg
-         ql_mod_cas(l)= ql_prof_cas(nlev_cas)*fact                     !jyg
-         qi_mod_cas(l)= qi_prof_cas(nlev_cas)*fact                     !jyg
-         u_mod_cas(l)= u_prof_cas(nlev_cas)*fact                       !jyg
-         v_mod_cas(l)= v_prof_cas(nlev_cas)*fact                       !jyg
-         ug_mod_cas(l)= ug_prof_cas(nlev_cas)                          !jyg
-         vg_mod_cas(l)= vg_prof_cas(nlev_cas)                          !jyg
-         temp_nudg_mod_cas(l)= temp_nudg_prof_cas(nlev_cas)            !jyg
-         qv_nudg_mod_cas(l)= qv_nudg_prof_cas(nlev_cas)                !jyg
-         u_nudg_mod_cas(l)= u_nudg_prof_cas(nlev_cas)                  !jyg
-         v_nudg_mod_cas(l)= v_nudg_prof_cas(nlev_cas)                  !jyg
-
-         invtau_temp_nudg_mod_cas(l)= invtau_temp_nudg_prof_cas(nlev_cas)            !jyg
-         invtau_qv_nudg_mod_cas(l)= invtau_qv_nudg_prof_cas(nlev_cas)                !jyg
-         invtau_u_nudg_mod_cas(l)= invtau_u_nudg_prof_cas(nlev_cas)                  !jyg
-         invtau_v_nudg_mod_cas(l)= invtau_v_nudg_prof_cas(nlev_cas)                  !jyg
-
-         thv_mod_cas(l)= thv_prof_cas(nlev_cas)                        !jyg
-         w_mod_cas(l)= 0.0                                             !jyg
-         omega_mod_cas(l)= 0.0                                         !jyg
-         du_mod_cas(l)= du_prof_cas(nlev_cas)*fact 
-         hu_mod_cas(l)= hu_prof_cas(nlev_cas)*fact                     !jyg
-         vu_mod_cas(l)= vu_prof_cas(nlev_cas)*fact                     !jyg
-         dv_mod_cas(l)= dv_prof_cas(nlev_cas)*fact
-         hv_mod_cas(l)= hv_prof_cas(nlev_cas)*fact                     !jyg
-         vv_mod_cas(l)= vv_prof_cas(nlev_cas)*fact                     !jyg
-         dt_mod_cas(l)= dt_prof_cas(nlev_cas) 
-         ht_mod_cas(l)= ht_prof_cas(nlev_cas)                          !jyg
-         vt_mod_cas(l)= vt_prof_cas(nlev_cas)                          !jyg
-         dth_mod_cas(l)= dth_prof_cas(nlev_cas) 
-         hth_mod_cas(l)= hth_prof_cas(nlev_cas)                        !jyg
-         vth_mod_cas(l)= vth_prof_cas(nlev_cas)                        !jyg
-         dq_mod_cas(l)= dq_prof_cas(nlev_cas)*fact 
-         hq_mod_cas(l)= hq_prof_cas(nlev_cas)*fact                     !jyg
-         vq_mod_cas(l)= vq_prof_cas(nlev_cas)*fact                     !jyg
-         dtrad_mod_cas(l)= dtrad_prof_cas(nlev_cas)*fact               !jyg
- 
-        endif ! play
- 
-       enddo ! l
-
-! for variables defined at layer interfaces (EV):
-
-
-       do l = 1, llm+1
-
-        if (plev(l).ge.plev_prof_cas(nlev_cas)) then
-
-         mxcalc=l
-         k1=0
-         k2=0
-
-         if (plev(l).le.plev_prof_cas(1)) then
-
-         do k = 1, nlev_cas-1
-          if (plev(l).le.plev_prof_cas(k).and. plev(l).gt.plev_prof_cas(k+1)) then
-            k1=k
-            k2=k+1
-          endif
-         enddo
-
-         if (k1.eq.0 .or. k2.eq.0) then
-          write(*,*) 'PB! k1, k2 = ',k1,k2
-          write(*,*) 'l,plev(l) = ',l,plev(l)/100
-         do k = 1, nlev_cas-1
-          write(*,*) 'k,plev_prof_cas(k) = ',k,plev_prof_cas(k)/100
-         enddo
-         endif
-
-         frac = (plev_prof_cas(k2)-plev(l))/(plev_prof_cas(k2)-plev_prof_cas(k1))
-         tke_mod_cas(l)= tke_prof_cas(k2) - frac*(tke_prof_cas(k2)-tke_prof_cas(k1))
-         else !play>plev_prof_cas(1)
-         k1=1
-         k2=2
-         tke_mod_cas(l)= frac1*tke_prof_cas(k1) - frac2*tke_prof_cas(k2)
-
-         endif ! plev.le.plev_prof_cas(1)
-
-        else ! above max altitude of forcing file
-
-         tke_mod_cas(l)=0.0
-
-        endif ! plev
-
-       enddo ! l
-
-
-
-          return
-          end SUBROUTINE interp2_case_vertical_std
-!***************************************************************************** 
+    !-------------------------------------------------------------------------
+    ! Vertical interpolation of generic case forcing data onto mod_casel levels
+    !-------------------------------------------------------------------------
+
+    integer nlevmax
+    parameter (nlevmax=41)
+    integer nlev_cas,mxcalc
+    !       real play(llm), plev_prof(nlevmax) 
+    !       real t_prof(nlevmax),q_prof(nlevmax)
+    !       real u_prof(nlevmax),v_prof(nlevmax), w_prof(nlevmax)
+    !       real ht_prof(nlevmax),vt_prof(nlevmax)
+    !       real hq_prof(nlevmax),vq_prof(nlevmax)
+
+    real play(llm), plev(llm+1), plev_prof_cas(nlev_cas) 
+    real t_prof_cas(nlev_cas),th_prof_cas(nlev_cas),thv_prof_cas(nlev_cas),thl_prof_cas(nlev_cas)
+    real qv_prof_cas(nlev_cas),ql_prof_cas(nlev_cas),qi_prof_cas(nlev_cas)
+    real u_prof_cas(nlev_cas),v_prof_cas(nlev_cas)
+    real ug_prof_cas(nlev_cas),vg_prof_cas(nlev_cas), vitw_prof_cas(nlev_cas),omega_prof_cas(nlev_cas),tke_prof_cas(nlev_cas)
+    real temp_nudg_prof_cas(nlev_cas),qv_nudg_prof_cas(nlev_cas)
+    real u_nudg_prof_cas(nlev_cas),v_nudg_prof_cas(nlev_cas)
+    real invtau_temp_nudg_prof_cas(nlev_cas),invtau_qv_nudg_prof_cas(nlev_cas)
+    real invtau_u_nudg_prof_cas(nlev_cas),invtau_v_nudg_prof_cas(nlev_cas)
+
+    real du_prof_cas(nlev_cas),hu_prof_cas(nlev_cas),vu_prof_cas(nlev_cas)
+    real dv_prof_cas(nlev_cas),hv_prof_cas(nlev_cas),vv_prof_cas(nlev_cas)
+    real dt_prof_cas(nlev_cas),ht_prof_cas(nlev_cas),vt_prof_cas(nlev_cas),dtrad_prof_cas(nlev_cas)
+    real dth_prof_cas(nlev_cas),hth_prof_cas(nlev_cas),vth_prof_cas(nlev_cas)
+    real dq_prof_cas(nlev_cas),hq_prof_cas(nlev_cas),vq_prof_cas(nlev_cas)
+
+    real t_mod_cas(llm),theta_mod_cas(llm),thv_mod_cas(llm),thl_mod_cas(llm)
+    real qv_mod_cas(llm),ql_mod_cas(llm),qi_mod_cas(llm)
+    real u_mod_cas(llm),v_mod_cas(llm)
+    real ug_mod_cas(llm),vg_mod_cas(llm), w_mod_cas(llm),omega_mod_cas(llm),tke_mod_cas(llm+1)
+    real temp_nudg_mod_cas(llm),qv_nudg_mod_cas(llm)
+    real u_nudg_mod_cas(llm),v_nudg_mod_cas(llm)
+    real invtau_temp_nudg_mod_cas(llm),invtau_qv_nudg_mod_cas(llm)
+    real invtau_u_nudg_mod_cas(llm),invtau_v_nudg_mod_cas(llm)
+    real du_mod_cas(llm),hu_mod_cas(llm),vu_mod_cas(llm)
+    real dv_mod_cas(llm),hv_mod_cas(llm),vv_mod_cas(llm)
+    real dt_mod_cas(llm),ht_mod_cas(llm),vt_mod_cas(llm),dtrad_mod_cas(llm)
+    real dth_mod_cas(llm),hth_mod_cas(llm),vth_mod_cas(llm)
+    real dq_mod_cas(llm),hq_mod_cas(llm),vq_mod_cas(llm)
+
+    integer l,k,k1,k2
+    real frac,frac1,frac2,fact
+
+
+
+    ! for variables defined at the middle of layers
+
+    do l = 1, llm
+
+       if (play(l).ge.plev_prof_cas(nlev_cas)) then
+
+          mxcalc=l
+          !        print *,'debut interp2, mxcalc=',mxcalc
+          k1=0
+          k2=0
+
+          if (play(l).le.plev_prof_cas(1)) then
+
+             do k = 1, nlev_cas-1
+                if (play(l).le.plev_prof_cas(k).and. play(l).gt.plev_prof_cas(k+1)) then
+                   k1=k
+                   k2=k+1
+                endif
+             enddo
+
+             if (k1.eq.0 .or. k2.eq.0) then
+                write(*,*) 'PB! k1, k2 = ',k1,k2
+                write(*,*) 'l,play(l) = ',l,play(l)/100
+                do k = 1, nlev_cas-1
+                   write(*,*) 'k,plev_prof_cas(k) = ',k,plev_prof_cas(k)/100
+                enddo
+             endif
+
+
+
+             frac = (plev_prof_cas(k2)-play(l))/(plev_prof_cas(k2)-plev_prof_cas(k1))
+
+             t_mod_cas(l)= t_prof_cas(k2) - frac*(t_prof_cas(k2)-t_prof_cas(k1))
+             theta_mod_cas(l)= th_prof_cas(k2) - frac*(th_prof_cas(k2)-th_prof_cas(k1))
+             if(theta_mod_cas(l).NE.0) t_mod_cas(l)= theta_mod_cas(l)*(play(l)/100000.)**(RD/RCPD)
+             thv_mod_cas(l)= thv_prof_cas(k2) - frac*(thv_prof_cas(k2)-thv_prof_cas(k1))
+             thl_mod_cas(l)= thl_prof_cas(k2) - frac*(thl_prof_cas(k2)-thl_prof_cas(k1))
+             qv_mod_cas(l)= qv_prof_cas(k2) - frac*(qv_prof_cas(k2)-qv_prof_cas(k1))
+             ql_mod_cas(l)= ql_prof_cas(k2) - frac*(ql_prof_cas(k2)-ql_prof_cas(k1))
+             qi_mod_cas(l)= qi_prof_cas(k2) - frac*(qi_prof_cas(k2)-qi_prof_cas(k1))
+             u_mod_cas(l)= u_prof_cas(k2) - frac*(u_prof_cas(k2)-u_prof_cas(k1))
+             v_mod_cas(l)= v_prof_cas(k2) - frac*(v_prof_cas(k2)-v_prof_cas(k1))
+             ug_mod_cas(l)= ug_prof_cas(k2) - frac*(ug_prof_cas(k2)-ug_prof_cas(k1))
+             vg_mod_cas(l)= vg_prof_cas(k2) - frac*(vg_prof_cas(k2)-vg_prof_cas(k1))
+             temp_nudg_mod_cas(l)= temp_nudg_prof_cas(k2) - frac*(temp_nudg_prof_cas(k2)-temp_nudg_prof_cas(k1))
+             qv_nudg_mod_cas(l)= qv_nudg_prof_cas(k2) - frac*(qv_nudg_prof_cas(k2)-qv_nudg_prof_cas(k1))
+             u_nudg_mod_cas(l)= u_nudg_prof_cas(k2) - frac*(u_nudg_prof_cas(k2)-u_nudg_prof_cas(k1))
+             v_nudg_mod_cas(l)= v_nudg_prof_cas(k2) - frac*(v_nudg_prof_cas(k2)-v_nudg_prof_cas(k1))
+
+             invtau_temp_nudg_mod_cas(l)= invtau_temp_nudg_prof_cas(k2) &
+                  - frac*(invtau_temp_nudg_prof_cas(k2)-invtau_temp_nudg_prof_cas(k1))
+             invtau_qv_nudg_mod_cas(l)= invtau_qv_nudg_prof_cas(k2) - frac*(invtau_qv_nudg_prof_cas(k2)-invtau_qv_nudg_prof_cas(k1))
+             invtau_u_nudg_mod_cas(l)= invtau_u_nudg_prof_cas(k2) - frac*(invtau_u_nudg_prof_cas(k2)-invtau_u_nudg_prof_cas(k1))
+             invtau_v_nudg_mod_cas(l)= invtau_v_nudg_prof_cas(k2) - frac*(invtau_v_nudg_prof_cas(k2)-invtau_v_nudg_prof_cas(k1))
+
+             w_mod_cas(l)= vitw_prof_cas(k2) - frac*(vitw_prof_cas(k2)-vitw_prof_cas(k1))
+             omega_mod_cas(l)= omega_prof_cas(k2) - frac*(omega_prof_cas(k2)-omega_prof_cas(k1))
+             du_mod_cas(l)= du_prof_cas(k2) - frac*(du_prof_cas(k2)-du_prof_cas(k1))
+             hu_mod_cas(l)= hu_prof_cas(k2) - frac*(hu_prof_cas(k2)-hu_prof_cas(k1))
+             vu_mod_cas(l)= vu_prof_cas(k2) - frac*(vu_prof_cas(k2)-vu_prof_cas(k1))
+             dv_mod_cas(l)= dv_prof_cas(k2) - frac*(dv_prof_cas(k2)-dv_prof_cas(k1))
+             hv_mod_cas(l)= hv_prof_cas(k2) - frac*(hv_prof_cas(k2)-hv_prof_cas(k1))
+             vv_mod_cas(l)= vv_prof_cas(k2) - frac*(vv_prof_cas(k2)-vv_prof_cas(k1))
+             dt_mod_cas(l)= dt_prof_cas(k2) - frac*(dt_prof_cas(k2)-dt_prof_cas(k1))
+             ht_mod_cas(l)= ht_prof_cas(k2) - frac*(ht_prof_cas(k2)-ht_prof_cas(k1))
+             vt_mod_cas(l)= vt_prof_cas(k2) - frac*(vt_prof_cas(k2)-vt_prof_cas(k1))
+             dth_mod_cas(l)= dth_prof_cas(k2) - frac*(dth_prof_cas(k2)-dth_prof_cas(k1))
+             hth_mod_cas(l)= hth_prof_cas(k2) - frac*(hth_prof_cas(k2)-hth_prof_cas(k1))
+             vth_mod_cas(l)= vth_prof_cas(k2) - frac*(vth_prof_cas(k2)-vth_prof_cas(k1))
+             dq_mod_cas(l)= dq_prof_cas(k2) - frac*(dq_prof_cas(k2)-dq_prof_cas(k1))
+             hq_mod_cas(l)= hq_prof_cas(k2) - frac*(hq_prof_cas(k2)-hq_prof_cas(k1))
+             vq_mod_cas(l)= vq_prof_cas(k2) - frac*(vq_prof_cas(k2)-vq_prof_cas(k1))
+             dtrad_mod_cas(l)= dtrad_prof_cas(k2) - frac*(dtrad_prof_cas(k2)-dtrad_prof_cas(k1))
+
+          else !play>plev_prof_cas(1)
+
+             k1=1
+             k2=2
+             print *,'interp2_vert, k1,k2=',plev_prof_cas(k1),plev_prof_cas(k2)
+             frac1 = (play(l)-plev_prof_cas(k2))/(plev_prof_cas(k1)-plev_prof_cas(k2))
+             frac2 = (play(l)-plev_prof_cas(k1))/(plev_prof_cas(k1)-plev_prof_cas(k2))
+             t_mod_cas(l)= frac1*t_prof_cas(k1) - frac2*t_prof_cas(k2)
+             theta_mod_cas(l)= frac1*th_prof_cas(k1) - frac2*th_prof_cas(k2)
+             if(theta_mod_cas(l).NE.0) t_mod_cas(l)= theta_mod_cas(l)*(play(l)/100000.)**(RD/RCPD)
+             thv_mod_cas(l)= frac1*thv_prof_cas(k1) - frac2*thv_prof_cas(k2)
+             thl_mod_cas(l)= frac1*thl_prof_cas(k1) - frac2*thl_prof_cas(k2)
+             qv_mod_cas(l)= frac1*qv_prof_cas(k1) - frac2*qv_prof_cas(k2)
+             ql_mod_cas(l)= frac1*ql_prof_cas(k1) - frac2*ql_prof_cas(k2)
+             qi_mod_cas(l)= frac1*qi_prof_cas(k1) - frac2*qi_prof_cas(k2)
+             u_mod_cas(l)= frac1*u_prof_cas(k1) - frac2*u_prof_cas(k2)
+             v_mod_cas(l)= frac1*v_prof_cas(k1) - frac2*v_prof_cas(k2)
+             ug_mod_cas(l)= frac1*ug_prof_cas(k1) - frac2*ug_prof_cas(k2)
+             vg_mod_cas(l)= frac1*vg_prof_cas(k1) - frac2*vg_prof_cas(k2)
+             temp_nudg_mod_cas(l)= frac1*temp_nudg_prof_cas(k1) - frac2*temp_nudg_prof_cas(k2)
+             qv_nudg_mod_cas(l)= frac1*qv_nudg_prof_cas(k1) - frac2*qv_nudg_prof_cas(k2)
+             u_nudg_mod_cas(l)= frac1*u_nudg_prof_cas(k1) - frac2*u_nudg_prof_cas(k2)
+             v_nudg_mod_cas(l)= frac1*v_nudg_prof_cas(k1) - frac2*v_nudg_prof_cas(k2)
+
+             invtau_temp_nudg_mod_cas(l)= frac1*invtau_temp_nudg_prof_cas(k1) - frac2*invtau_temp_nudg_prof_cas(k2)
+             invtau_qv_nudg_mod_cas(l)= frac1*invtau_qv_nudg_prof_cas(k1) - frac2*invtau_qv_nudg_prof_cas(k2)
+             invtau_u_nudg_mod_cas(l)= frac1*invtau_u_nudg_prof_cas(k1) - frac2*invtau_u_nudg_prof_cas(k2)
+             invtau_v_nudg_mod_cas(l)= frac1*invtau_v_nudg_prof_cas(k1) - frac2*invtau_v_nudg_prof_cas(k2)
+
+             w_mod_cas(l)= frac1*vitw_prof_cas(k1) - frac2*vitw_prof_cas(k2)
+             omega_mod_cas(l)= frac1*omega_prof_cas(k1) - frac2*omega_prof_cas(k2)
+             du_mod_cas(l)= frac1*du_prof_cas(k1) - frac2*du_prof_cas(k2)
+             hu_mod_cas(l)= frac1*hu_prof_cas(k1) - frac2*hu_prof_cas(k2)
+             vu_mod_cas(l)= frac1*vu_prof_cas(k1) - frac2*vu_prof_cas(k2)
+             dv_mod_cas(l)= frac1*dv_prof_cas(k1) - frac2*dv_prof_cas(k2)
+             hv_mod_cas(l)= frac1*hv_prof_cas(k1) - frac2*hv_prof_cas(k2)
+             vv_mod_cas(l)= frac1*vv_prof_cas(k1) - frac2*vv_prof_cas(k2)
+             dt_mod_cas(l)= frac1*dt_prof_cas(k1) - frac2*dt_prof_cas(k2)
+             ht_mod_cas(l)= frac1*ht_prof_cas(k1) - frac2*ht_prof_cas(k2)
+             vt_mod_cas(l)= frac1*vt_prof_cas(k1) - frac2*vt_prof_cas(k2)
+             dth_mod_cas(l)= frac1*dth_prof_cas(k1) - frac2*dth_prof_cas(k2)
+             hth_mod_cas(l)= frac1*hth_prof_cas(k1) - frac2*hth_prof_cas(k2)
+             vth_mod_cas(l)= frac1*vth_prof_cas(k1) - frac2*vth_prof_cas(k2)
+             dq_mod_cas(l)= frac1*dq_prof_cas(k1) - frac2*dq_prof_cas(k2)
+             hq_mod_cas(l)= frac1*hq_prof_cas(k1) - frac2*hq_prof_cas(k2)
+             vq_mod_cas(l)= frac1*vq_prof_cas(k1) - frac2*vq_prof_cas(k2)
+             dtrad_mod_cas(l)= frac1*dtrad_prof_cas(k1) - frac2*dtrad_prof_cas(k2)
+
+          endif ! play.le.plev_prof_cas(1)
+
+       else ! above max altitude of forcing file
+
+          !jyg
+          fact=20.*(plev_prof_cas(nlev_cas)-play(l))/plev_prof_cas(nlev_cas) !jyg
+          fact = max(fact,0.)                                           !jyg
+          fact = exp(-fact)                                             !jyg
+          t_mod_cas(l)= t_prof_cas(nlev_cas)                            !jyg
+          theta_mod_cas(l)= th_prof_cas(nlev_cas)                       !jyg
+          thv_mod_cas(l)= thv_prof_cas(nlev_cas)                        !jyg
+          thl_mod_cas(l)= thl_prof_cas(nlev_cas)                        !jyg
+          qv_mod_cas(l)= qv_prof_cas(nlev_cas)*fact                     !jyg
+          ql_mod_cas(l)= ql_prof_cas(nlev_cas)*fact                     !jyg
+          qi_mod_cas(l)= qi_prof_cas(nlev_cas)*fact                     !jyg
+          u_mod_cas(l)= u_prof_cas(nlev_cas)*fact                       !jyg
+          v_mod_cas(l)= v_prof_cas(nlev_cas)*fact                       !jyg
+          ug_mod_cas(l)= ug_prof_cas(nlev_cas)                          !jyg
+          vg_mod_cas(l)= vg_prof_cas(nlev_cas)                          !jyg
+          temp_nudg_mod_cas(l)= temp_nudg_prof_cas(nlev_cas)            !jyg
+          qv_nudg_mod_cas(l)= qv_nudg_prof_cas(nlev_cas)                !jyg
+          u_nudg_mod_cas(l)= u_nudg_prof_cas(nlev_cas)                  !jyg
+          v_nudg_mod_cas(l)= v_nudg_prof_cas(nlev_cas)                  !jyg
+
+          invtau_temp_nudg_mod_cas(l)= invtau_temp_nudg_prof_cas(nlev_cas)            !jyg
+          invtau_qv_nudg_mod_cas(l)= invtau_qv_nudg_prof_cas(nlev_cas)                !jyg
+          invtau_u_nudg_mod_cas(l)= invtau_u_nudg_prof_cas(nlev_cas)                  !jyg
+          invtau_v_nudg_mod_cas(l)= invtau_v_nudg_prof_cas(nlev_cas)                  !jyg
+
+          thv_mod_cas(l)= thv_prof_cas(nlev_cas)                        !jyg
+          w_mod_cas(l)= 0.0                                             !jyg
+          omega_mod_cas(l)= 0.0                                         !jyg
+          du_mod_cas(l)= du_prof_cas(nlev_cas)*fact 
+          hu_mod_cas(l)= hu_prof_cas(nlev_cas)*fact                     !jyg
+          vu_mod_cas(l)= vu_prof_cas(nlev_cas)*fact                     !jyg
+          dv_mod_cas(l)= dv_prof_cas(nlev_cas)*fact
+          hv_mod_cas(l)= hv_prof_cas(nlev_cas)*fact                     !jyg
+          vv_mod_cas(l)= vv_prof_cas(nlev_cas)*fact                     !jyg
+          dt_mod_cas(l)= dt_prof_cas(nlev_cas) 
+          ht_mod_cas(l)= ht_prof_cas(nlev_cas)                          !jyg
+          vt_mod_cas(l)= vt_prof_cas(nlev_cas)                          !jyg
+          dth_mod_cas(l)= dth_prof_cas(nlev_cas) 
+          hth_mod_cas(l)= hth_prof_cas(nlev_cas)                        !jyg
+          vth_mod_cas(l)= vth_prof_cas(nlev_cas)                        !jyg
+          dq_mod_cas(l)= dq_prof_cas(nlev_cas)*fact 
+          hq_mod_cas(l)= hq_prof_cas(nlev_cas)*fact                     !jyg
+          vq_mod_cas(l)= vq_prof_cas(nlev_cas)*fact                     !jyg
+          dtrad_mod_cas(l)= dtrad_prof_cas(nlev_cas)*fact               !jyg
+
+       endif ! play
+
+    enddo ! l
+
+    ! for variables defined at layer interfaces (EV):
+
+
+    do l = 1, llm+1
+
+       if (plev(l).ge.plev_prof_cas(nlev_cas)) then
+
+          mxcalc=l
+          k1=0
+          k2=0
+
+          if (plev(l).le.plev_prof_cas(1)) then
+
+             do k = 1, nlev_cas-1
+                if (plev(l).le.plev_prof_cas(k).and. plev(l).gt.plev_prof_cas(k+1)) then
+                   k1=k
+                   k2=k+1
+                endif
+             enddo
+
+             if (k1.eq.0 .or. k2.eq.0) then
+                write(*,*) 'PB! k1, k2 = ',k1,k2
+                write(*,*) 'l,plev(l) = ',l,plev(l)/100
+                do k = 1, nlev_cas-1
+                   write(*,*) 'k,plev_prof_cas(k) = ',k,plev_prof_cas(k)/100
+                enddo
+             endif
+
+             frac = (plev_prof_cas(k2)-plev(l))/(plev_prof_cas(k2)-plev_prof_cas(k1))
+             tke_mod_cas(l)= tke_prof_cas(k2) - frac*(tke_prof_cas(k2)-tke_prof_cas(k1))
+          else !play>plev_prof_cas(1)
+             k1=1
+             k2=2
+             frac1 = (play(l)-plev_prof_cas(k2))/(plev_prof_cas(k1)-plev_prof_cas(k2))
+             frac2 = (play(l)-plev_prof_cas(k1))/(plev_prof_cas(k1)-plev_prof_cas(k2))
+             tke_mod_cas(l)= frac1*tke_prof_cas(k1) - frac2*tke_prof_cas(k2)
+
+          endif ! plev.le.plev_prof_cas(1)
+
+       else ! above max altitude of forcing file
+
+          tke_mod_cas(l)=0.0
+
+       endif ! plev
+
+    enddo ! l
+
+
+
+    return
+  end SUBROUTINE interp2_case_vertical_std
+  !***************************************************************************** 
 
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/old_1DUTILS_read_interp.h
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/old_1DUTILS_read_interp.h	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/old_1DUTILS_read_interp.h	(revision 4482)
@@ -146,5 +146,5 @@
 !program reading forcings of the TWP-ICE experiment
 
-!      use netcdf
+        use netcdf, only: nf90_get_var
 
       implicit none
@@ -314,9 +314,5 @@
        enddo
           
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(1),lat)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(1),lat)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(1),lat)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -325,9 +321,5 @@
 !         write(*,*)'lecture lat ok',lat
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(2),lon)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(2),lon)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(2),lon)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -336,9 +328,5 @@
 !         write(*,*)'lecture lon ok',lon
  
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(3),alt)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(3),alt)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(3),alt)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -347,9 +335,5 @@
 !          write(*,*)'lecture alt ok',alt
  
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(4),phis)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(4),phis)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(4),phis)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -358,9 +342,5 @@
 !          write(*,*)'lecture phis ok',phis
           
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(5),T)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(5),T)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(5),T)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -369,9 +349,5 @@
 !         write(*,*)'lecture T ok'
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(6),q)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(6),q)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(6),q)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -385,9 +361,5 @@
        enddo
        enddo
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(7),u)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(7),u)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(7),u)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -396,9 +368,5 @@
 !         write(*,*)'lecture u ok'
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(8),v)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(8),v)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(8),v)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -407,9 +375,5 @@
 !         write(*,*)'lecture v ok'
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(9),omega)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(9),omega)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(9),omega)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -424,9 +388,5 @@
        enddo
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(10),div)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(10),div)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(10),div)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -435,9 +395,5 @@
 !         write(*,*)'lecture div ok'
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(11),T_adv_h)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(11),T_adv_h)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(11),T_adv_h)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -453,9 +409,5 @@
 
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(12),T_adv_v)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(12),T_adv_v)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(12),T_adv_v)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -470,9 +422,5 @@
        enddo
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(13),q_adv_h)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(13),q_adv_h)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(13),q_adv_h)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -488,9 +436,5 @@
 
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(14),q_adv_v)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(14),q_adv_v)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(14),q_adv_v)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -506,59 +450,35 @@
 
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(15),s)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(15),s)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(16),s_adv_h)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(16),s_adv_h)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(17),s_adv_v)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(17),s_adv_v)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(18),p_srf_aver)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(18),p_srf_aver)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(19),p_srf_center)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(19),p_srf_center)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(20),T_srf)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(20),T_srf)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(15),s)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+
+         ierr = NF90_GET_VAR(nid,var3didin(16),s_adv_h)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+
+         ierr = NF90_GET_VAR(nid,var3didin(17),s_adv_v)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+
+         ierr = NF90_GET_VAR(nid,var3didin(18),p_srf_aver)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+
+         ierr = NF90_GET_VAR(nid,var3didin(19),p_srf_center)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+
+         ierr = NF90_GET_VAR(nid,var3didin(20),T_srf)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -572,5 +492,5 @@
          subroutine catchaxis(nid,ttm,llm,time,lev,ierr)
 
-!         use netcdf
+         use netcdf, only: nf90_get_var
 
          implicit none
@@ -610,11 +530,6 @@
          endif
 
-!#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,timevar,time)
-         ierr = NF_GET_VAR_DOUBLE(nid,levvar,lev)
-!#else
-!        ierr = NF_GET_VAR_REAL(nid,timevar,time)
-!        ierr = NF_GET_VAR_REAL(nid,levvar,lev)
-!#endif
+         ierr = NF90_GET_VAR(nid,timevar,time)
+         ierr = NF90_GET_VAR(nid,levvar,lev)
 
        return
@@ -2255,4 +2170,5 @@
 
 
+      use netcdf, only: nf90_get_var
       implicit none
 
@@ -2364,9 +2280,5 @@
 !      call catchaxis(nid,ntime,nlevel,time,z,ierr)
  
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(1),zz)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(1),zz)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(1),zz)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2375,9 +2287,5 @@
 !          write(*,*)'lecture z ok',zz
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(2),thl)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(2),thl)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(2),thl)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2386,9 +2294,5 @@
 !          write(*,*)'lecture thl ok',thl
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(3),qt)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(3),qt)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(3),qt)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2397,9 +2301,5 @@
 !          write(*,*)'lecture qt ok',qt
  
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(4),u)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(4),u)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(4),u)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2408,9 +2308,5 @@
 !          write(*,*)'lecture u ok',u
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(5),v)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(5),v)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(5),v)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2419,9 +2315,5 @@
 !          write(*,*)'lecture v ok',v
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(6),tke)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(6),tke)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(6),tke)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2430,9 +2322,5 @@
 !          write(*,*)'lecture tke ok',tke
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(7),ug)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(7),ug)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(7),ug)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2441,9 +2329,5 @@
 !          write(*,*)'lecture ug ok',ug
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(8),vg)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(8),vg)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(8),vg)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2452,9 +2336,5 @@
 !          write(*,*)'lecture vg ok',vg
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(9),wls)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(9),wls)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(9),wls)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2463,9 +2343,5 @@
 !          write(*,*)'lecture wls ok',wls
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(10),dqtdx)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(10),dqtdx)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(10),dqtdx)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2474,9 +2350,5 @@
 !          write(*,*)'lecture dqtdx ok',dqtdx
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(11),dqtdy)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(11),dqtdy)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(11),dqtdy)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2485,9 +2357,5 @@
 !          write(*,*)'lecture dqtdy ok',dqtdy
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(12),dqtdt)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(12),dqtdt)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(12),dqtdt)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2496,9 +2364,5 @@
 !          write(*,*)'lecture dqtdt ok',dqtdt
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(13),thl_rad)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(13),thl_rad)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(13),thl_rad)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2517,4 +2381,5 @@
 !program reading initial profils and forcings of the Dice case study
 
+      use netcdf, only: nf90_get_var
 
       implicit none
@@ -2685,9 +2550,5 @@
 !      call catchaxis(nid,ntime,nlevel,time,z,ierr)
  
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(1),zz)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(1),zz)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(1),zz)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2696,9 +2557,5 @@
 !          write(*,*)'lecture zz ok',zz
  
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(11),pres)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(11),pres)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(11),pres)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2707,9 +2564,5 @@
 !          write(*,*)'lecture pres ok',pres
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(12),th)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(12),th)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(12),th)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2721,9 +2574,5 @@
            enddo
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(13),qv)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(13),qv)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(13),qv)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2732,9 +2581,5 @@
 !          write(*,*)'lecture qv ok',qv
  
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(14),u)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(14),u)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(14),u)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2743,9 +2588,5 @@
 !          write(*,*)'lecture u ok',u
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(15),v)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(15),v)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(15),v)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2754,9 +2595,5 @@
 !          write(*,*)'lecture v ok',v
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(16),o3)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(16),o3)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(16),o3)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2765,9 +2602,5 @@
 !          write(*,*)'lecture o3 ok',o3
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(2),shf)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(2),shf)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(2),shf)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2776,9 +2609,5 @@
 !          write(*,*)'lecture shf ok',shf
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(3),lhf)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(3),lhf)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(3),lhf)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2787,9 +2616,5 @@
 !          write(*,*)'lecture lhf ok',lhf
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(4),lwup)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(4),lwup)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(4),lwup)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2798,9 +2623,5 @@
 !          write(*,*)'lecture lwup ok',lwup
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(5),swup)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(5),swup)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(5),swup)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2809,9 +2630,5 @@
 !          write(*,*)'lecture swup ok',swup
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(6),tg)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(6),tg)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(6),tg)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2820,9 +2637,5 @@
 !          write(*,*)'lecture tg ok',tg
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(7),ustar)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(7),ustar)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(7),ustar)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2831,9 +2644,5 @@
 !          write(*,*)'lecture ustar ok',ustar
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(8),psurf)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(8),psurf)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(8),psurf)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2842,9 +2651,5 @@
 !          write(*,*)'lecture psurf ok',psurf
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(9),ug)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(9),ug)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(9),ug)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2853,9 +2658,5 @@
 !          write(*,*)'lecture ug ok',ug
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(10),vg)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(10),vg)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(10),vg)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2864,9 +2665,5 @@
 !          write(*,*)'lecture vg ok',vg
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(17),hadvt)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(17),hadvt)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(17),hadvt)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2875,9 +2672,5 @@
 !          write(*,*)'lecture hadvt ok',hadvt
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(18),hadvq)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(18),hadvq)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(18),hadvq)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2886,9 +2679,5 @@
 !          write(*,*)'lecture hadvq ok',hadvq
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(19),hadvu)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(19),hadvu)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(19),hadvu)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2897,9 +2686,5 @@
 !          write(*,*)'lecture hadvu ok',hadvu
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(20),hadvv)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(20),hadvv)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(20),hadvv)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2908,9 +2693,5 @@
 !          write(*,*)'lecture hadvv ok',hadvv
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(21),w)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(21),w)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(21),w)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2919,9 +2700,5 @@
 !          write(*,*)'lecture w ok',w
 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(22),omega)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(22),omega)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(22),omega)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
@@ -2938,4 +2715,5 @@
 !program reading initial profils and forcings of the Gabls4 case study
 
+      use netcdf, only: nf90_get_var
 
       implicit none
@@ -3068,149 +2846,89 @@
 !      call catchaxis(nid,ntime,nlevel,time,z,ierr)
  
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(1),zz_i)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(1),zz_i)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(2),depth_sn)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(2),depth_sn)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(3),ug_i)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(3),ug_i)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(4),vg_i)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(4),vg_i)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(5),pf_i)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(5),pf_i)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(6),th_i)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(6),th_i)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(7),t_i)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(7),t_i)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(8),qv_i)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(8),qv_i)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(9),u_i)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(9),u_i)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(10),v_i)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(10),v_i)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(11),hadvt_i)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(11),hadvt_i)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(12),hadvq_i)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(12),hadvq_i)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(14),tsnow)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(14),tsnow)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(15),snow_dens)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(15),snow_dens)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(16),tg)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(16),tg)
-#endif
+         ierr = NF90_GET_VAR(nid,var3didin(1),zz_i)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+ 
+         ierr = NF90_GET_VAR(nid,var3didin(2),depth_sn)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+ 
+         ierr = NF90_GET_VAR(nid,var3didin(3),ug_i)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+ 
+         ierr = NF90_GET_VAR(nid,var3didin(4),vg_i)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+ 
+         ierr = NF90_GET_VAR(nid,var3didin(5),pf_i)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+
+         ierr = NF90_GET_VAR(nid,var3didin(6),th_i)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+
+         ierr = NF90_GET_VAR(nid,var3didin(7),t_i)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+
+         ierr = NF90_GET_VAR(nid,var3didin(8),qv_i)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+ 
+         ierr = NF90_GET_VAR(nid,var3didin(9),u_i)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+ 
+         ierr = NF90_GET_VAR(nid,var3didin(10),v_i)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+ 
+         ierr = NF90_GET_VAR(nid,var3didin(11),hadvt_i)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+ 
+         ierr = NF90_GET_VAR(nid,var3didin(12),hadvq_i)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+ 
+         ierr = NF90_GET_VAR(nid,var3didin(14),tsnow)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+ 
+         ierr = NF90_GET_VAR(nid,var3didin(15),snow_dens)
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+
+         ierr = NF90_GET_VAR(nid,var3didin(16),tg)
          if(ierr/=NF_NOERR) then
             write(*,*) NF_STRERROR(ierr)
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/old_1D_read_forc_cases.h
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/old_1D_read_forc_cases.h	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/old_1D_read_forc_cases.h	(revision 4482)
@@ -843,5 +843,5 @@
       if (forcing_case) then
 
-         write(*,*),'avant call read_1D_cas'
+         write(*,*) 'avant call read_1D_cas'
          call read_1D_cas
          write(*,*) 'Forcing read'
@@ -918,5 +918,5 @@
       if (forcing_case2) then
 
-         write(*,*),'avant call read2_1D_cas'
+         write(*,*) 'avant call read2_1D_cas'
          call read2_1D_cas
          write(*,*) 'Forcing read'
@@ -1017,5 +1017,5 @@
       if (forcing_SCM) then
 
-         write(*,*),'avant call old_read_SCM_cas'
+         write(*,*) 'avant call old_read_SCM_cas'
          call old_read_SCM_cas
          write(*,*) 'Forcing read' 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/old_lmdz1d.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/old_lmdz1d.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/old_lmdz1d.F90	(revision 4482)
@@ -494,5 +494,5 @@
 !      calend = 'earth_365d'
       if (calend == 'earth_360d') then
-        call ioconf_calendar('360d')
+        call ioconf_calendar('360_day')
         write(*,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
       else if (calend == 'earth_365d') then
@@ -613,5 +613,5 @@
       call init_dimphy1D(1,llm)
       call suphel
-      call infotrac_init 
+      call init_infotrac
 
       if (nqtot>nqmx) STOP 'Augmenter nqmx dans lmdz1d.F'
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/replay1d.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/replay1d.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/replay1d.F90	(revision 4482)
@@ -1,8 +1,10 @@
 PROGRAM rejouer
 
-  USE mod_const_mpi, ONLY: comm_lmdz
-  USE inigeomphy_mod, ONLY: inigeomphy
- USE comvert_mod, ONLY: presnivs
+USE mod_const_mpi, ONLY: comm_lmdz
+USE inigeomphy_mod, ONLY: inigeomphy
+USE comvert_mod, ONLY: presnivs
 USE comvert_mod, only :  preff, pa
+USE ioipsl, only: getin
+
 
 
@@ -17,7 +19,9 @@
 
 integer ntime
-integer jour0,mois0,an0
-integer it
+integer jour0,mois0,an0,day_step,anneeref,dayref
 integer klev,klon
+CHARACTER (len=10) :: calend
+CHARACTER(len=20) :: calendrier
+
 
 !---------------------------------------------------------------------
@@ -31,6 +35,6 @@
 
 preff=101325.
+!preff=100000.
 pa=50000.
-open(82,file='dump_param.bin',form='unformatted',status='old')
   CALL disvert()
   CALL inigeomphy(1,1,llm, &
@@ -43,26 +47,40 @@
 
 CALL suphel
-ntime=100
-jour0=1
-mois0=1
-an0=2000
+!ntime=4320
+ntime=10000000
+dayref=1
+anneeref=2000
+call getin('dayref',dayref)
+call getin('anneeref',anneeref)
+call getin('calend',calend)
+call getin('day_step',day_step)
+calendrier=calend
+if ( calendrier == "earth_360d" ) calendrier="360_day"
+
+
+jour0=dayref
+mois0=(jour0-1)/30+1
+jour0=jour0-30*((jour0-1)/30)
+an0=anneeref
+
+!print*,"REPLAY1D jour0,mois0,an0",jour0,mois0,an0
+
+
 klon=1
 klev=llm
-call iotd_ini('phys.nc',1,1,klev,0.,0.,presnivs,jour0,mois0,an0,0.,900.,'360d')
+call iotd_ini('phys.nc',1,1,klev,0.,0.,presnivs,jour0,mois0,an0,0.,86400./day_step,calendrier)
+! Consistent with ... CALL iophys_ini(600.)
 
 !---------------------------------------------------------------------
 ! Initialisation de la parametrisation
 !---------------------------------------------------------------------
-      call get_ini_module
+call get_ini_module
 
 !---------------------------------------------------------------------
 ! Boucle en temps sur l'appel à la parametrisation
 !---------------------------------------------------------------------
-      DO it=1,ntime
-         print*,'Pas de temps ',it,klon,klev
-         call call_param_replay(klon,klev)
-      ENDDO
-      END
+call call_param_replay(klon,klev)
 
+end
 
 !---------------------------------------------------------------------
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/scm.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/scm.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/dyn1d/scm.F90	(revision 4482)
@@ -327,5 +327,5 @@
 !      calend = 'earth_365d'
       if (calend == 'earth_360d') then
-        call ioconf_calendar('360d')
+        call ioconf_calendar('360_day')
         write(*,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
       else if (calend == 'earth_365d') then
@@ -393,5 +393,5 @@
       call init_dimphy1D(1,llm)
       call suphel
-      call infotrac_init 
+      call init_infotrac
 
       if (nqtot>nqmx) STOP 'Augmenter nqmx dans lmdz1d.F'
@@ -496,11 +496,4 @@
         stop 'in initialization'
       endif ! forcing_GCM2SCM
-
-      print*,'mxcalc=',mxcalc
-!     print*,'zlay=',zlay(mxcalc)
-!      print*,'play=',play(mxcalc)
-
-!! When surface temperature is forced
-      tg= tsurf ! surface T used in read_tsurf1d
 
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ener_conserv.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ener_conserv.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ener_conserv.F90	(revision 4482)
@@ -1,4 +1,4 @@
 subroutine ener_conserv(klon,klev,pdtphys, &
- &                      puo,pvo,pto,pqo,pql0,pqs0, &
+ &                      puo,pvo,pto,qx,ivap,iliq,isol, &
  &                      pun,pvn,ptn,pqn,pqln,pqsn,dtke,masse,exner,d_t_ec)
 
@@ -28,4 +28,5 @@
 USE phys_output_var_mod, ONLY : bils_ec,bils_ech,bils_tke,bils_kinetic,bils_enthalp,bils_latent,bils_diss
 USE add_phys_tend_mod, ONLY : fl_cor_ebil 
+USE infotrac_phy, ONLY: nqtot
 
 
@@ -39,5 +40,7 @@
 INTEGER, INTENT(IN) :: klon,klev
 REAL, INTENT(IN) :: pdtphys
-REAL, DIMENSION(klon,klev), INTENT(IN)      :: puo,pvo,pto,pqo,pql0,pqs0
+REAL, DIMENSION(klon,klev), INTENT(IN)      :: puo,pvo,pto
+REAL, DIMENSION(klon,klev,nqtot), INTENT(IN):: qx
+INTEGER, INTENT(IN)                         :: ivap, iliq, isol
 REAL, DIMENSION(klon,klev), INTENT(IN)      :: pun,pvn,ptn,pqn,pqln,pqsn
 REAL, DIMENSION(klon,klev), INTENT(IN)      :: masse,exner
@@ -50,5 +53,5 @@
 REAL, DIMENSION(klon,klev+1) :: fluxu,fluxv,fluxt
 REAL, DIMENSION(klon,klev+1) :: dddu,dddv,dddt
-REAL, DIMENSION(klon,klev) :: d_u,d_v,d_t,zv,zu,d_t_ech
+REAL, DIMENSION(klon,klev) :: d_u,d_v,d_t,zv,zu,d_t_ech, pqo, pql0, pqs0
 REAL ZRCPD
 
@@ -59,4 +62,10 @@
 modname='ener_conser'
 d_t_ec(:,:)=0.
+
+IF(ivap == 0) CALL abort_physic (modname,'can''t run without water vapour',1)
+IF(iliq == 0) CALL abort_physic (modname,'can''t run without liquid water',1)
+pqo  = qx(:,:,ivap)
+pql0 = qx(:,:,iliq)
+IF(isol /= 0) pqs0 = qx(:,:,isol)
 
 IF (iflag_ener_conserv==-1) THEN
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/fisrtilp.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/fisrtilp.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/fisrtilp.F90	(revision 4482)
@@ -89,7 +89,7 @@
   ! Coeffients de fraction lessivee : pour OFF-LINE
   !
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: pfrac_nucl
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: pfrac_1nucl
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: pfrac_impa
+  REAL, DIMENSION(klon,klev),      INTENT(INOUT)  :: pfrac_nucl
+  REAL, DIMENSION(klon,klev),      INTENT(INOUT)  :: pfrac_1nucl
+  REAL, DIMENSION(klon,klev),      INTENT(INOUT)  :: pfrac_impa
   !
   ! Fraction d'aerosols lessivee par impaction et par nucleation
@@ -1565,5 +1565,7 @@
         DO i=1, klon
             IF (zrflclr(i) + ziflclr(i) .GT. 0 ) THEN
-                znebprecipclr(i) = min(znebprecipclr(i), max(zrflclr(i)/(znebprecipclr(i)*rain_int_min), ziflclr(i)/(znebprecipclr(i)*rain_int_min)))
+               znebprecipclr(i) = min(znebprecipclr(i), max(zrflclr(i) &
+                    /(znebprecipclr(i)*rain_int_min), &
+                    ziflclr(i)/(znebprecipclr(i)*rain_int_min)))
             ELSE
                 znebprecipclr(i)=0.
@@ -1571,5 +1573,7 @@
 
             IF (zrflcld(i) + ziflcld(i) .GT. 0 ) THEN
-                znebprecipcld(i) = min(znebprecipcld(i), max(zrflcld(i)/(znebprecipcld(i)*rain_int_min), ziflcld(i)/(znebprecipcld(i)*rain_int_min)))
+               znebprecipcld(i) = min(znebprecipcld(i), &
+                    max(zrflcld(i)/(znebprecipcld(i)*rain_int_min), &
+                    ziflcld(i)/(znebprecipcld(i)*rain_int_min)))
             ELSE
                 znebprecipcld(i)=0.
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ice_sursat_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ice_sursat_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ice_sursat_mod.F90	(revision 4482)
@@ -3,19 +3,12 @@
 IMPLICIT NONE
 
+!--flight inventories
+!
 REAL, SAVE, ALLOCATABLE :: flight_m(:,:)    !--flown distance m s-1 per cell
 !$OMP THREADPRIVATE(flight_m)
 REAL, SAVE, ALLOCATABLE :: flight_h2o(:,:)  !--emitted kg H2O s-1 per cell
 !$OMP THREADPRIVATE(flight_h2o)
-
-!--parameters for gamma function
-!--Karcher and Lohmann (2002)
-!--gamma = 2.583 - t / 207.83
-! REAL, SAVE, PARAMETER :: gamma0=2.583, Tgamma=207.83
-!--Ren and MacKenzie (2005) reused by Kärcher
-!--gamma = 2.349 - t / 259.0
-REAL, PARAMETER :: gamma0=2.349, Tgamma=259.0
-!
-!--number of clouds in cell (needs to be parametrized at some point)
-REAL, PARAMETER :: N_cld = 100.
+!
+!--Fixed Parameters
 !
 !--safety parameters for ERF function
@@ -43,11 +36,19 @@
 !  alpha_cld ). Dans le rapport il est appelé beta. Il varie entre 0 et 5
 !  (tun_ratqs = 0 => pas de modification de ratqs).
-
+!
+!--gamma0 and Tgamma: define RHcrit limit above which heterogeneous freezing occurs as a function of T
+!--Karcher and Lohmann (2002)
+!--gamma = 2.583 - t / 207.83
+!--Ren and MacKenzie (2005) reused by Kärcher
+!--gamma = 2.349 - t / 259.0
+!
+!--N_cld: number of clouds in cell (needs to be parametrized at some point)
+!
+!--contrail cross section: typical value found in Freudenthaler et al, GRL, 22, 3501-3504, 1995
+!--in m2, 1000x200 = 200 000 m2 after 15 min
+!
 REAL, SAVE :: chi=1.1, l_turb=50.0, tun_N=1.3, tun_ratqs=3.0
-!$OMP THREADPRIVATE(chi,l_turb,tun_N,tun_ratqs)
-!
-!--contrail cross section, typical value found in Freudenthaler et al, GRL, 22, 3501-3504, 1995
-!--in m2, 1000x200 = 200 000 m2 after 15 min
-REAL, PARAMETER :: contrail_cross_section=200000.0  
+REAL, SAVE :: gamma0=2.349, Tgamma=259.0, N_cld=100, contrail_cross_section=200000.0
+!$OMP THREADPRIVATE(chi,l_turb,tun_N,tun_ratqs,gamma0,Tgamma,N_cld,contrail_cross_section)
 
 CONTAINS
@@ -66,9 +67,18 @@
   CALL getin_p('flag_tun_N',tun_N)
   CALL getin_p('flag_tun_ratqs',tun_ratqs)
-
+  CALL getin_p('gamma0',gamma0)
+  CALL getin_p('Tgamma',Tgamma)
+  CALL getin_p('N_cld',N_cld)
+  CALL getin_p('contrail_cross_section',contrail_cross_section)
+
+  WRITE(lunout,*) 'Parameters for ice_sursat param'
   WRITE(lunout,*) 'flag_chi = ', chi
   WRITE(lunout,*) 'flag_l_turb = ', l_turb
   WRITE(lunout,*) 'flag_tun_N = ', tun_N
   WRITE(lunout,*) 'flag_tun_ratqs = ', tun_ratqs
+  WRITE(lunout,*) 'gamma0 = ', gamma0
+  WRITE(lunout,*) 'Tgamma = ', Tgamma
+  WRITE(lunout,*) 'N_cld = ', N_cld
+  WRITE(lunout,*) 'contrail_cross_section = ', contrail_cross_section
 
 END SUBROUTINE ice_sursat_init
@@ -384,7 +394,7 @@
      !
      !--Estimating gamma 
-     gamma_ss = gamma0 - t_actuel/Tgamma
-     !gamma_prec = gamma0 - t_ancien(i,k)/Tgamma      !--formulation initiale d Audran
-     gamma_prec = gamma0 - t/Tgamma                   !--autre formulation possible basée sur le T du pas de temps
+     gamma_ss = MAX(1.0, gamma0 - t_actuel/Tgamma)
+     !gamma_prec = MAX(1.0, gamma0 - t_ancien(i,k)/Tgamma)      !--formulation initiale d Audran
+     gamma_prec = MAX(1.0, gamma0 - t/Tgamma)                   !--autre formulation possible basée sur le T du pas de temps
      !
      ! Initialisation de qvc : q_sat du pas de temps precedent
@@ -421,5 +431,7 @@
         ! On approxime en serie entiere erf-1(x)
         qvc = 2.*rneb-1.
-        qvc = qvc + PI/12.*qvc**3 + 7.*PI**2/480.*qvc**5 + 127.*PI**3/40320.*qvc**7 + 4369.*PI**4/5806080.*qvc**9 + 34807.*PI**5/182476800.*qvc**11
+        qvc = qvc + PI/12.*qvc**3 + 7.*PI**2/480.*qvc**5 &
+             + 127.*PI**3/40320.*qvc**7 + 4369.*PI**4/5806080.*qvc**9 &
+             + 34807.*PI**5/182476800.*qvc**11
         qvc = sqrt(PI)/2.*qvc
         qvc = (qvc-pdf_b)*pdf_k*sqrt(2.)
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/infotrac_phy.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/infotrac_phy.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/infotrac_phy.F90	(revision 4482)
@@ -1,10 +1,10 @@
-
-! $Id: $
-
+!$Id: infotrac.F90 4301 2022-10-20 11:57:21Z dcugnet $
+!
 MODULE infotrac_phy
 
-   USE       strings_mod, ONLY: msg, maxlen, strStack, strHead, strParse, strIdx, int2str
-   USE readTracFiles_mod, ONLY: trac_type, isot_type, keys_type, delPhase, getKey, tnom_iso => newH2OIso
-
+   USE       strings_mod, ONLY: msg, fmsg, maxlen, cat, dispTable, int2str, bool2str, strStack, strParse, strIdx
+   USE readTracFiles_mod, ONLY: trac_type, nphas, readTracersFiles, tracers, setGeneration, itZonIso, nbIso, tran0, delPhase, &
+                        getKey, isot_type, nzone, readIsotopesFile, isotope, maxTableWidth, iqIsoPha, ntiso, ixIso, addPhase, &
+                   indexUpdate, isoSelect, niso,  testTracersFiles, isoPhas, isoZone, isoName, isoKeys, iH2O, isoCheck, addKey
    IMPLICIT NONE
 
@@ -13,10 +13,14 @@
    !=== FOR TRACERS:
    PUBLIC :: init_infotrac_phy                             !--- Initialization of the tracers
-   PUBLIC :: tracers, type_trac, types_trac                !--- Full tracers database, tracers type keyword
+   PUBLIC :: tracers, type_trac                            !--- Full tracers database, tracers type keyword
    PUBLIC :: nqtot,   nbtr,   nqo,   nqCO2,   nqtottr      !--- Main dimensions
    PUBLIC :: conv_flg, pbl_flg                             !--- Convection & boundary layer activation keys
+#ifdef CPP_StratAer
+   PUBLIC :: nbtr_bin, nbtr_sulgas                         !--- Number of aerosols bins and sulfur gases for StratAer model
+   PUBLIC :: id_OCS_strat, id_SO2_strat, id_H2SO4_strat, id_BIN01_strat, id_TEST_strat
+#endif
 
    !=== FOR ISOTOPES: General
-   PUBLIC :: isotopes,  nbIso                              !--- Derived type, full isotopes families database + nb of families
+   PUBLIC :: isot_type, nbIso                              !--- Derived type, full isotopes families database + nb of families
    PUBLIC :: isoSelect, ixIso                              !--- Isotopes family selection tool + selected family index
    !=== FOR ISOTOPES: Specific to water
@@ -26,11 +30,9 @@
    PUBLIC :: isoName, isoZone, isoPhas                     !--- Isotopes and tagging zones names, phases
    PUBLIC :: niso,    nzone,   nphas,   ntiso              !---  " " numbers + isotopes & tagging tracers number
-   PUBLIC :: itZonIso                                      !--- iq = function(tagging zone idx, isotope idx)
-   PUBLIC :: iqIsoPha                                      !--- idx of tagging tracer in iName = function(isotope idx, phase idx)
+   PUBLIC :: itZonIso                                      !--- idx "it" (in "isoName(1:niso)") = function(tagging idx, isotope idx)
+   PUBLIC :: iqIsoPha                                      !--- idx "iq" (in "qx") = function(isotope idx, phase idx) + aliases
    PUBLIC :: isoCheck                                      !--- Run isotopes checking routines
    !=== FOR BOTH TRACERS AND ISOTOPES
    PUBLIC :: getKey                                        !--- Get a key from "tracers" or "isotope"
-
-   INTERFACE isoSelect; MODULE PROCEDURE isoSelectByIndex, isoSelectByName; END INTERFACE isoSelect
 
 !=== CONVENTIONS FOR TRACERS NUMBERS:
@@ -68,17 +70,15 @@
 !  | phase       | Phases list ("g"as / "l"iquid / "s"olid)             | /           | [g][l][s]              |
 !  | component   | Name(s) of the merged/cumulated section(s)           | /           | coma-separated names   |
-!  | iadv        | Advection scheme number                              | iadv        | 1-20,30 exc. 3-9,15,19 |
 !  | iGeneration | Generation (>=1)                                     | /           |                        |
-!  | isAdvected  | advected tracers flag (.TRUE. if iadv >= 0)          | /           | nqtrue  .TRUE. values  |
 !  | isInPhysics | tracers not extracted from the main table in physics | /           | nqtottr .TRUE. values  |
 !  | iqParent    | Index of the parent tracer                           | iqpere      | 1:nqtot                |
 !  | iqDescen    | Indexes of the childs       (all generations)        | iqfils      | 1:nqtot                |
 !  | nqDescen    | Number of the descendants   (all generations)        | nqdesc      | 1:nqtot                |
-!  | nqChilds    | Number of childs            (1st generation only)    | nqfils      | 1:nqtot                |
+!  | nqChildren  | Number of childs            (1st generation only)    | nqfils      | 1:nqtot                |
+!  | keys        | key/val pairs accessible with "getKey" routine       | /           |                        |
 !  | iso_iGroup  | Isotopes group index in isotopes(:)                  | /           | 1:nbIso                |
 !  | iso_iName   | Isotope  name  index in isotopes(iso_iGroup)%trac(:) | iso_indnum  | 1:niso                 |
 !  | iso_iZone   | Isotope  zone  index in isotopes(iso_iGroup)%zone(:) | zone_num    | 1:nzone                |
 !  | iso_iPhas   | Isotope  phase index in isotopes(iso_iGroup)%phas(:) | phase_num   | 1:nphas                |
-!  | keys        | key/val pairs accessible with "getKey" routine       | /           |                        |
 !  +-------------+------------------------------------------------------+-------------+------------------------+
 !
@@ -98,36 +98,15 @@
 
    !=== DIMENSIONS OF THE TRACERS TABLES AND OTHER SCALAR VARIABLES
-   INTEGER,                 SAVE :: nqtot,  &                   !--- Tracers nb in dynamics (incl. higher moments + H2O)
-                                    nbtr,   &                   !--- Tracers nb in physics  (excl. higher moments + H2O)
-                                    nqo,    &                   !--- Number of water phases
-                                    nbIso,  &                   !--- Number of available isotopes family
-                                    nqtottr, &                  !--- Number of tracers passed to phytrac (TO BE DELETED ?)
-                                    nqCO2                       !--- Number of tracers of CO2  (ThL)
-   CHARACTER(LEN=maxlen),   SAVE :: type_trac                   !--- Keyword for tracers type
-   CHARACTER(LEN=maxlen),   SAVE, ALLOCATABLE :: types_trac(:)  !--- Keyword for tracers type
-!$OMP THREADPRIVATE(nqtot, nbtr, nqo, nbIso, nqtottr, nqCO2, type_trac, types_trac)
-
-   !=== DERIVED TYPES EMBEDDING MOST INFORMATIONS ABOUT TRACERS AND ISOTOPES FAMILIES
-   TYPE(trac_type), TARGET, SAVE, ALLOCATABLE ::  tracers(:)    !=== TRACERS DESCRIPTORS VECTOR
-   TYPE(isot_type), TARGET, SAVE, ALLOCATABLE :: isotopes(:)    !=== ISOTOPES PARAMETERS VECTOR
-!$OMP THREADPRIVATE(tracers, isotopes)
-
-   !=== ALIASES FOR CURRENTLY SELECTED ISOTOPES FAMILY OF VARIABLES EMBEDDED IN THE VECTOR "isotopes"
-   TYPE(isot_type),         SAVE, POINTER :: isotope            !--- CURRENTLY SELECTED ISOTOPES FAMILY DESCRIPTOR
-   INTEGER,                 SAVE          :: ixIso, iH2O        !--- Index of the selected isotopes family and H2O family
-   LOGICAL,                 SAVE          :: isoCheck           !--- Flag to trigger the checking routines
-   TYPE(keys_type),         SAVE, POINTER :: isoKeys(:)         !--- ONE SET OF KEYS FOR EACH ISOTOPE (LISTED IN isoName)
-   CHARACTER(LEN=maxlen),   SAVE, POINTER :: isoName(:),   &    !--- ISOTOPES NAMES FOR THE CURRENTLY SELECTED FAMILY
-                                             isoZone(:),   &    !--- TAGGING ZONES  FOR THE CURRENTLY SELECTED FAMILY
-                                             isoPhas            !--- USED PHASES    FOR THE CURRENTLY SELECTED FAMILY
-   INTEGER,                 SAVE          ::  niso, nzone, &    !--- NUMBER OF ISOTOPES, TAGGING ZONES AND PHASES
-                                             nphas, ntiso       !--- NUMBER OF PHASES AND ISOTOPES + ISOTOPIC TAGGING TRACERS
-   INTEGER,                 SAVE, POINTER ::itZonIso(:,:), &    !--- INDEX IN "isoTrac" AS f(tagging zone idx,  isotope idx)
-                                            iqIsoPha(:,:)       !--- INDEX IN "qx"      AS f(isotopic tracer idx, phase idx)
-!$OMP THREADPRIVATE(isotope, ixIso,iH2O, isoCheck, isoKeys, isoName,isoZone,isoPhas, niso,nzone,nphas,ntiso, itZonIso,iqIsoPha)
-
-   !=== VARIABLES FOR ISOTOPES INITIALIZATION AND FOR INCA
-   INTEGER,          SAVE,    ALLOCATABLE ::conv_flg(:),  &     !--- Convection     activation ; needed for INCA        (nbtr)
-                                             pbl_flg(:)         !--- Boundary layer activation ; needed for INCA        (nbtr)
+   INTEGER,               SAVE :: nqtot,  &                     !--- Tracers nb in dynamics (incl. higher moments + H2O)
+                                  nbtr,   &                     !--- Tracers nb in physics  (excl. higher moments + H2O)
+                                  nqo,    &                     !--- Number of water phases
+                                  nqtottr, &                    !--- Number of tracers passed to phytrac (TO BE DELETED ?)
+                                  nqCO2                         !--- Number of tracers of CO2  (ThL)
+   CHARACTER(LEN=maxlen), SAVE :: type_trac                     !--- Keyword for tracers type(s)
+!$OMP THREADPRIVATE(nqtot, nbtr, nqo, nqtottr, nqCO2, type_trac)
+
+   !=== VARIABLES FOR INCA
+   INTEGER,               SAVE, ALLOCATABLE :: conv_flg(:), &   !--- Convection     activation ; needed for INCA        (nbtr)
+                                                pbl_flg(:)      !--- Boundary layer activation ; needed for INCA        (nbtr)
 !$OMP THREADPRIVATE(conv_flg, pbl_flg)
 
@@ -142,56 +121,315 @@
 CONTAINS
 
-SUBROUTINE init_infotrac_phy(type_trac_, tracers_, isotopes_, nqtottr_, nqCO2_, pbl_flg_, conv_flg_)
-
-   USE print_control_mod, ONLY: prt_level, lunout
-
+SUBROUTINE init_infotrac_phy
+   USE ioipsl_getin_p_mod, ONLY: getin_p
+#ifdef REPROBUS
+   USE CHEM_REP, ONLY: Init_chem_rep_trac
+#endif
    IMPLICIT NONE
-   CHARACTER(LEN=*),INTENT(IN) :: type_trac_
-   TYPE(trac_type), INTENT(IN) ::  tracers_(:)
-   TYPE(isot_type), INTENT(IN) :: isotopes_(:)
-   INTEGER,         INTENT(IN) :: nqtottr_
-   INTEGER,         INTENT(IN) :: nqCO2_
-   INTEGER,         INTENT(IN) :: conv_flg_(:)
-   INTEGER,         INTENT(IN) ::  pbl_flg_(:)
-
-   INTEGER :: iq, ixt
+!==============================================================================================================================
+!
+!   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
+!   -------
+!
+!   Modifications:
+!   --------------
+!   05/94: F.Forget      Modif special traceur
+!   02/02: M-A Filiberti Lecture de traceur.def
+!   01/22: D. Cugnet     Nouveaux tracer.def et tracer_*.def + encapsulation (types trac_type et isot_type)
+!
+!   Objet:
+!   ------
+!   GCM LMD nouvelle grille
+!
+!==============================================================================================================================
+!   ... modification de l'integration de q ( 26/04/94 ) ....
+!------------------------------------------------------------------------------------------------------------------------------
+! Declarations:
+   INCLUDE "dimensions.h"
+   INCLUDE "iniprint.h"
+
+!------------------------------------------------------------------------------------------------------------------------------
+! Local variables
+   INTEGER, ALLOCATABLE :: hadv(:), vadv(:)                          !--- Horizontal/vertical transport scheme number
+#ifdef INCA
+   INTEGER, ALLOCATABLE :: had (:), hadv_inca(:), conv_flg_inca(:), &!--- Variables specific to INCA
+                           vad (:), vadv_inca(:),  pbl_flg_inca(:)
+   CHARACTER(LEN=8), ALLOCATABLE :: solsym_inca(:)                   !--- Tracers names for INCA
+   INTEGER :: nqINCA
+#endif
 #ifdef CPP_StratAer
    CHARACTER(LEN=maxlen), ALLOCATABLE :: tnames(:)
 #endif
-   CHARACTER(LEN=maxlen) :: modname="init_infotrac_phy"
-
-   type_trac = type_trac_
-   IF(strParse(type_trac, '|', types_trac)) CALL abort_physic(modname,'can''t parse "type_trac = '//TRIM(type_trac)//'"',1)
-   tracers   = tracers_
-   isotopes  = isotopes_
-   nqtottr   = nqtottr_
-   nqCO2     = nqCO2_
-   pbl_flg   =  pbl_flg_
-   conv_flg  = conv_flg_
-   nqtot     = SIZE(tracers_)
-   nqo       = COUNT(delPhase(tracers%name)=='H2O' .AND. tracers%iGeneration==0 .AND. tracers%component=='lmdz')
-   nbtr      = SIZE(conv_flg)
-   nbIso     = SIZE(isotopes_)
-
-   !=== Determine selected isotopes class related quantities:
-   !    ixIso, isotope, niso,isoKeys, ntiso,isoName, nzone,isoZone, nphas,isoPhas, itZonIso, iqIsoPha, isoCheck
-   IF(.NOT.isoSelect('H2O')) iH2O = ixIso
-   IF(prt_level > 1) THEN
-      CALL msg('nqtot   = '//TRIM(int2str(nqtot)),   modname)
-      CALL msg('nbtr    = '//TRIM(int2str(nbtr )),   modname)
-      CALL msg('nqo     = '//TRIM(int2str(nqo  )),   modname)
-      CALL msg('niso    = '//TRIM(int2str(niso )),   modname)
-      CALL msg('ntiso   = '//TRIM(int2str(ntiso)),   modname)
-      CALL msg('nqtottr = '//TRIM(int2str(nqtottr)), modname)
-      CALL msg('nqCO2   = '//TRIM(int2str(nqCO2)),   modname)
-   END IF
-
+   CHARACTER(LEN=2)      ::   suff(9)                                !--- Suffixes for schemes of order 3 or 4 (Prather)
+   CHARACTER(LEN=3)      :: descrq(30)                               !--- Advection scheme description tags
+   CHARACTER(LEN=maxlen) :: msg1, texp, ttp                          !--- String for messages and expanded tracers type
+   INTEGER :: fType                                                  !--- Tracers description file type ; 0: none
+                                                                     !--- 1/2/3: "traceur.def"/"tracer.def"/"tracer_*.def"
+   INTEGER :: nqtrue                                                 !--- Tracers nb from tracer.def (no higher order moments)
+   INTEGER :: iad                                                    !--- Advection scheme number
+   INTEGER :: ic, iq, jq, it, nt, im, nm, iz, k                      !--- Indexes and temporary variables
+   LOGICAL :: lerr, ll, lInit
+   CHARACTER(LEN=1) :: p
+   TYPE(trac_type), ALLOCATABLE, TARGET :: ttr(:)
+   TYPE(trac_type), POINTER             :: t1, t(:)
+   INTEGER :: ierr
+
+   CHARACTER(LEN=*), PARAMETER :: modname="init_infotrac_phy"
+!------------------------------------------------------------------------------------------------------------------------------
+! Initialization :
+!------------------------------------------------------------------------------------------------------------------------------
+   suff          = ['x ','y ','z ','xx','xy','xz','yy','yz','zz']
+   descrq( 1:30) =  '   '
+   descrq( 1: 2) = ['LMV','BAK']
+   descrq(10:20) = ['VL1','VLP','FH1','FH2','VLH','   ','PPM','PPS','PPP','   ','SLP']
+   descrq(30)    =  'PRA'
+
+   CALL getin_p('type_trac',type_trac)
+   CALL msg('type_trac = "'//TRIM(type_trac)//'"', modname)
+   lInit = .NOT.ALLOCATED(tracers)
+
+!##############################################################################################################################
+   IF(lInit) THEN                                                    !=== SKIPED IF ALREADY DONE IN dyn3d_common/infotrac  ####
+!##############################################################################################################################
+   !--- MESSAGE ABOUT THE CHOSEN CONFIGURATION
+   msg1 = 'For type_trac = "'//TRIM(type_trac)//'":'
+   SELECT CASE(type_trac)
+      CASE('inca'); CALL msg(TRIM(msg1)//' coupling with INCA chemistry model',        modname)
+      CASE('inco'); CALL msg(TRIM(msg1)//' coupling jointly with INCA and CO2 cycle',  modname)
+      CASE('repr'); CALL msg(TRIM(msg1)//' coupling with REPROBUS chemistry model',    modname)
+      CASE('co2i'); CALL msg(TRIM(msg1)//' you have chosen to run with CO2 cycle',     modname)
+      CASE('coag'); CALL msg(TRIM(msg1)//' tracers are treated for COAGULATION tests', modname)
+      CASE('lmdz'); CALL msg(TRIM(msg1)//' tracers are treated in LMDZ only',          modname)
+      CASE DEFAULT; CALL abort_gcm(modname,'type_trac='//TRIM(type_trac)//' not possible yet.',1)
+   END SELECT
+
+   !--- COHERENCE TEST BETWEEN "type_trac" AND PREPROCESSING KEYS
+   SELECT CASE(type_trac)
+      CASE('inca', 'inco')
+#ifndef INCA
+         CALL abort_gcm(modname, 'You must add cpp key INCA and compile with INCA code', 1)
+#endif
+      CASE('repr')
+#ifndef REPROBUS
+         CALL abort_gcm(modname, 'You must add cpp key REPROBUS and compile with REPROBUS code', 1)
+#endif
+      CASE('coag')
+#ifndef CPP_StratAer
+         CALL abort_gcm(modname, 'You must add cpp key StratAer and compile with StratAer code', 1)
+#endif
+   END SELECT
+!##############################################################################################################################
+   END IF
+!##############################################################################################################################
+
+   nqCO2 = COUNT( [type_trac == 'inco', type_trac == 'co2i'] )
+
+!==============================================================================================================================
+! 1) Get the numbers of: true (first order only) tracers "nqtrue", water tracers "nqo" (vapor/liquid/solid)
+!==============================================================================================================================
+   texp = type_trac                                                  !=== EXPANDED VERSION OF "type_trac", WITH "|" SEPARATOR
+   IF(texp == 'inco') texp = 'co2i|inca'
+   IF(texp /= 'lmdz') texp = 'lmdz|'//TRIM(texp)
+
+   !=== DETERMINE THE TYPE OF THE INPUT TRACERS DESCRIPTION FILE
+   IF(testTracersFiles(modname, texp, fType, lInit)) CALL abort_gcm(modname, 'problem with tracers file(s)',1)
+   ttp = type_trac; IF(fType /= 1) ttp = texp
+
+!##############################################################################################################################
+   IF(lInit) THEN
+      IF(readTracersFiles(ttp, type_trac == 'repr')) CALL abort_gcm(modname, 'problem with tracers file(s)',1)
+   ELSE
+      CALL msg('No tracers description file(s) reading needed: already done in the dynamics', modname)
+   END IF
+!##############################################################################################################################
+
+   !---------------------------------------------------------------------------------------------------------------------------
+   IF(fType == 0) CALL abort_gcm(modname, 'Missing tracers file: "traceur.def", "tracer.def" or "tracer_<keyword>.def file.',1)
+   !---------------------------------------------------------------------------------------------------------------------------
+   IF(fType == 1 .AND. ANY(['inca','inco']==type_trac) .AND. lInit) THEN  !=== OLD STYLE INCA "traceur.def" (single type_trac)
+   !---------------------------------------------------------------------------------------------------------------------------
+#ifdef INCA
+      nqo = SIZE(tracers) - nqCO2
+      CALL Init_chem_inca_trac(nqINCA)                               !--- Get nqINCA from INCA
+      nbtr = nqINCA + nqCO2                                          !--- Number of tracers passed to phytrac
+      nqtrue = nbtr + nqo                                            !--- Total number of "true" tracers
+      IF(ALL([2,3] /= nqo)) CALL abort_gcm(modname, 'Only 2 or 3 water phases allowed ; found nqo='//TRIM(int2str(nqo)), 1)
+      ALLOCATE(hadv(nqtrue), hadv_inca(nqINCA), conv_flg_inca(nqINCA), solsym_inca(nqINCA))
+      ALLOCATE(vadv(nqtrue), vadv_inca(nqINCA),  pbl_flg_inca(nqINCA))
+      CALL init_transport(solsym_inca, conv_flg_inca, pbl_flg_inca, hadv_inca, vadv_inca)
+      ALLOCATE(ttr(nqtrue))
+      ttr(1:nqo+nqCO2)                  = tracers
+      ttr(1    :      nqo   )%component = 'lmdz'
+      ttr(1+nqo:nqCO2+nqo   )%component = 'co2i'
+      ttr(1+nqo+nqCO2:nqtrue)%component = 'inca'
+      ttr(1+nqo      :nqtrue)%name      = [('CO2     ', k=1, nqCO2), solsym_inca]
+      ttr(1+nqo+nqCO2:nqtrue)%parent    = tran0
+      ttr(1+nqo+nqCO2:nqtrue)%phase     = 'g'
+      lerr = getKey('hadv', had, ky=tracers(:)%keys)
+      lerr = getKey('vadv', vad, ky=tracers(:)%keys)
+      hadv(1:nqo+nqCO2) = had(:); hadv(1+nqo+nqCO2:nqtrue) = hadv_inca
+      vadv(1:nqo+nqCO2) = vad(:); vadv(1+nqo+nqCO2:nqtrue) = vadv_inca
+      CALL MOVE_ALLOC(FROM=ttr, TO=tracers)
+      DO iq = 1, nqtrue
+         t1 => tracers(iq)
+         CALL addKey('name',      t1%name,      t1%keys)
+         CALL addKey('component', t1%component, t1%keys)
+         CALL addKey('parent',    t1%parent,    t1%keys)
+         CALL addKey('phase',     t1%phase,     t1%keys)
+      END DO
+      IF(setGeneration(tracers)) CALL abort_gcm(modname,'See below',1) !- SET FIELDS %iGeneration, %gen0Name
+      DEALLOCATE(had, hadv_inca, vad, vadv_inca, conv_flg_inca, pbl_flg_inca, solsym_inca)
+#endif
+   !---------------------------------------------------------------------------------------------------------------------------
+   ELSE                                                              !=== OTHER CASES (OLD OR NEW FORMAT, NO INCA MODULE)
+   !---------------------------------------------------------------------------------------------------------------------------
+      nqo    =        COUNT(delPhase(tracers(:)%name)     == 'H2O' &
+                               .AND. tracers(:)%component == 'lmdz') !--- Number of water phases
+      nqtrue = SIZE(tracers)                                         !--- Total number of "true" tracers
+      nbtr   = nqtrue-COUNT(delPhase(tracers(:)%gen0Name) == 'H2O' &
+                               .AND. tracers(:)%component == 'lmdz') !--- Number of tracers passed to phytrac
+#ifdef INCA
+      nqINCA = COUNT(tracers(:)%component == 'inca')
+#endif
+      lerr = getKey('hadv', hadv, ky=tracers(:)%keys)
+      lerr = getKey('vadv', vadv, ky=tracers(:)%keys)
+   !---------------------------------------------------------------------------------------------------------------------------
+   END IF
+   !---------------------------------------------------------------------------------------------------------------------------
+
+   !--- Transfert the number of tracers to Reprobus
+#ifdef REPROBUS
+   CALL Init_chem_rep_trac(nbtr, nqo, tracers(:)%name)
+#endif
+
+!##############################################################################################################################
+   IF(lInit) THEN                                                    !=== SKIPED IF ALREADY DONE IN dyn3d_common/infotrac  ####
+!##############################################################################################################################
+
+!==============================================================================================================================
+! 2) Calculate nqtot, number of tracers needed (greater if advection schemes 20 or 30 have been chosen).
+!==============================================================================================================================
+   DO iq = 1, nqtrue
+      IF( hadv(iq)<20 .OR. (ANY(hadv(iq)==[20,30]) .AND. hadv(iq)==vadv(iq)) ) CYCLE
+      WRITE(msg1,'("The choice hadv=",i0,", vadv=",i0,a)')hadv(iq),vadv(iq),' for "'//TRIM(tracers(iq)%name)//'" is not available'
+      CALL abort_gcm(modname, TRIM(msg1), 1)
+   END DO
+   nqtot =    COUNT( hadv< 20 .AND. vadv< 20 ) &                     !--- No additional tracer
+         +  4*COUNT( hadv==20 .AND. vadv==20 ) &                     !--- 3  additional tracers
+         + 10*COUNT( hadv==30 .AND. vadv==30 )                       !--- 9  additional tracers
+
+   !--- More tracers due to the choice of advection scheme => assign total number of tracers
+   IF( nqtot /= nqtrue ) THEN
+      CALL msg('The choice of advection scheme for one or more tracers makes it necessary to add tracers')
+      CALL msg('The number of true tracers is '//TRIM(int2str(nqtrue)))
+      CALL msg('The total number of tracers needed is '//TRIM(int2str(nqtot)))
+   END IF
+
+!==============================================================================================================================
+! 3) Determine the advection scheme ; needed to compute the full tracers list, the long names and nqtot.
+!==============================================================================================================================
+   ALLOCATE(ttr(nqtot))
+   jq = nqtrue+1; tracers(:)%iadv = -1
+   DO iq = 1, nqtrue
+      t1 => tracers(iq)
+
+      !--- VERIFY THE CHOICE OF ADVECTION SCHEME
+      iad = -1
+      IF(hadv(iq)     ==    vadv(iq)    ) iad = hadv(iq)
+      IF(hadv(iq)==10 .AND. vadv(iq)==16) iad = 11
+      WRITE(msg1,'("Bad choice of advection scheme for ",a,": hadv = ",i0,", vadv = ",i0)')TRIM(t1%name), hadv(iq), vadv(iq)
+      IF(iad == -1) CALL abort_gcm(modname, msg1, 1)
+
+      !--- SET FIELDS %longName, %isInPhysics
+      t1%longName   = t1%name; IF(iad > 0) t1%longName=TRIM(t1%name)//descrq(iad)
+      t1%isInPhysics= delPhase(t1%gen0Name) /= 'H2O' &
+                          .OR. t1%component /= 'lmdz' !=== OTHER EXCEPTIONS TO BE ADDED: CO2i, SURSATURATED WATER CLOUD...
+      ttr(iq)       = t1
+
+      !--- DEFINE THE HIGHER ORDER TRACERS, IF ANY
+      nm = 0
+      IF(iad == 20) nm = 3                                           !--- 2nd order scheme
+      IF(iad == 30) nm = 9                                           !--- 3rd order scheme
+      IF(nm == 0) CYCLE                                              !--- No higher moments
+      ttr(jq+1:jq+nm)             = t1
+      ttr(jq+1:jq+nm)%name        = [(TRIM(t1%name)    //'-'//TRIM(suff(im)), im=1, nm) ]
+      ttr(jq+1:jq+nm)%parent      = [(TRIM(t1%parent)  //'-'//TRIM(suff(im)), im=1, nm) ]
+      ttr(jq+1:jq+nm)%longName    = [(TRIM(t1%longName)//'-'//TRIM(suff(im)), im=1, nm) ]
+      jq = jq + nm
+   END DO
+   DEALLOCATE(hadv, vadv)
+   CALL MOVE_ALLOC(FROM=ttr, TO=tracers)
+
+   !--- SET FIELDS %iqParent, %nqChildren, %iGeneration, %iqDescen, %nqDescen
+   CALL indexUpdate(tracers)
+
+!##############################################################################################################################
+   END IF
+!##############################################################################################################################
+
+!##############################################################################################################################
+   IF(.NOT.lInit) THEN
+!##############################################################################################################################
+     nqtot = SIZE(tracers)
+!##############################################################################################################################
+   ELSE
+!##############################################################################################################################
+
+   !=== READ PHYSICAL PARAMETERS FOR ISOTOPES
+   niso = 0; nzone = 0; nphas = nqo; ntiso = 0; isoCheck = .FALSE.
+   IF(readIsotopesFile()) CALL abort_gcm(modname, 'Problem when reading isotopes parameters', 1)
+
+!##############################################################################################################################
+   END IF
+!##############################################################################################################################
+   !--- Convection / boundary layer activation for all tracers
+   ALLOCATE(conv_flg(nbtr)); conv_flg(1:nbtr) = 1
+   ALLOCATE( pbl_flg(nbtr));  pbl_flg(1:nbtr) = 1
+
+   !--- Note: nqtottr can differ from nbtr when nmom/=0
+   nqtottr = nqtot - COUNT(delPhase(tracers%gen0Name) == 'H2O' .AND. tracers%component == 'lmdz')
+   IF(COUNT(tracers%iso_iName == 0) - COUNT(delPhase(tracers%name) == 'H2O' .AND. tracers%component == 'lmdz') /= nqtottr) &
+      CALL abort_gcm(modname, 'pb dans le calcul de nqtottr', 1)
+
+   !=== DISPLAY THE RESULTS
+   CALL msg('nqo    = '//TRIM(int2str(nqo)),    modname)
+   CALL msg('nbtr   = '//TRIM(int2str(nbtr)),   modname)
+   CALL msg('nqtrue = '//TRIM(int2str(nqtrue)), modname)
+   CALL msg('nqtot  = '//TRIM(int2str(nqtot)),  modname)
+   CALL msg('niso   = '//TRIM(int2str(niso)),   modname)
+   CALL msg('ntiso  = '//TRIM(int2str(ntiso)),  modname)
+#ifdef INCA
+   CALL msg('nqCO2  = '//TRIM(int2str(nqCO2)),  modname)
+   CALL msg('nqINCA = '//TRIM(int2str(nqINCA)), modname)
+#endif
+   t => tracers
+   CALL msg('Information stored in infotrac_phy :', modname)
+   IF(dispTable('issssssssiiiiiiii', &
+      ['iq    ', 'name  ', 'lName ', 'gen0N ', 'parent', 'type  ', 'phase ', 'compon', 'isPhy ',           &
+                 'iGen  ', 'iqPar ', 'nqDes ', 'nqChld', 'iGroup', 'iName ', 'iZone ', 'iPhase'],          &
+      cat(t%name, t%longName, t%gen0Name, t%parent, t%type, t%phase, t%component, bool2str(t%isInPhysics)),&
+      cat([(iq, iq=1, nqtot)], t%iGeneration, t%iqParent, t%nqDescen, t%nqChildren, t%iso_iGroup,          &
+                  t%iso_iName, t%iso_iZone, t%iso_iPhase), nColMax=maxTableWidth, nHead=2, sub=modname))   &
+      CALL abort_gcm(modname, "problem with the tracers table content", 1)
+   IF(niso > 0) THEN
+      CALL msg('Where, for isotopes family "'//TRIM(isotope%parent)//'":', modname)
+      CALL msg('  isoKeys%name = '//strStack(isoKeys%name), modname)
+      CALL msg('  isoName = '//strStack(isoName),      modname)
+      CALL msg('  isoZone = '//strStack(isoZone),      modname)
+      CALL msg('  isoPhas = '//TRIM(isoPhas),          modname)
+   ELSE
+      CALL msg('No isotopes identified.', modname)
+   END IF
+
+#ifdef ISOVERIF
+   CALL msg('iso_iName = '//strStack(int2str(PACK(tracers(:)%iso_iName, MASK=tracers(:)%iso_iGroup==iH2O))), modname)
+#endif
 #ifdef CPP_StratAer
-   IF (ANY(types_trac == 'coag')) THEN
+   IF (type_trac == 'coag') THEN
       nbtr_bin    = COUNT([(tracers(iq)%name(1:3)=='BIN', iq=1, nqtot)])
       nbtr_sulgas = COUNT([(tracers(iq)%name(1:3)=='GAS', iq=1, nqtot)])
       tnames = PACK(tracers(:)%name, MASK=tracers(:)%isInPhysics)
       id_BIN01_strat = strIdx(tnames, 'BIN01'   )
-      id_OCS_strat   = strIdx(tnames, 'GASOSC'  )
+      id_OCS_strat   = strIdx(tnames, 'GASOCS'  )
       id_SO2_strat   = strIdx(tnames, 'GASSO2'  )
       id_H2SO4_strat = strIdx(tnames, 'GASH2SO4')
@@ -206,55 +444,7 @@
    END IF
 #endif
-#ifdef ISOVERIF
-   CALL msg('iso_iName = '//strStack(int2str(PACK(tracers(:)%iso_iName, MASK=tracers(:)%iso_iGroup==iH2O))), modname)
-#endif
+   CALL msg('end', modname)
 
 END SUBROUTINE init_infotrac_phy
 
-
-!==============================================================================================================================
-!=== THE ROUTINE isoSelect IS USED TO SWITCH FROM AN ISOTOPE FAMILY TO ANOTHER: ISOTOPES DEPENDENT PARAMETERS ARE UPDATED
-!     Single generic "isoSelect" routine, using the predefined index of the parent (fast version) or its name (first call).
-!==============================================================================================================================
-LOGICAL FUNCTION isoSelectByName(iName, lVerbose) RESULT(lerr)
-   IMPLICIT NONE
-   CHARACTER(LEN=*),  INTENT(IN)  :: iName
-   LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
-   INTEGER :: iIso
-   LOGICAL :: lV
-   lV = .FALSE.; IF(PRESENT(lVerbose)) lV = lVerbose
-   iIso = strIdx(isotopes(:)%parent, iName)
-   lerr = iIso == 0
-   IF(lerr) THEN
-      niso = 0; ntiso = 0; nzone=0; nphas=nqo; isoCheck=.FALSE.
-      CALL msg('no isotope family named "'//TRIM(iName)//'"', ll=lV)
-      RETURN
-   END IF
-   lerr = isoSelectByIndex(iIso, lV)
-END FUNCTION isoSelectByName
-!==============================================================================================================================
-LOGICAL FUNCTION isoSelectByIndex(iIso, lVerbose) RESULT(lerr)
-   IMPLICIT NONE
-   INTEGER,           INTENT(IN) :: iIso
-   LOGICAL, OPTIONAL, INTENT(IN) :: lVerbose
-   LOGICAL :: lv
-   lv = .FALSE.; IF(PRESENT(lVerbose)) lv = lVerbose
-   lerr = .FALSE.
-   IF(iIso == ixIso) RETURN                                      !--- Nothing to do if the index is already OK
-   lerr = iIso<=0 .OR. iIso>nbIso
-   CALL msg('Inconsistent isotopes family index '//TRIM(int2str(iIso))//': should be > 0 and <= '//TRIM(int2str(nbIso))//'"',&
-            ll=lerr .AND. lV)
-   IF(lerr) RETURN
-   ixIso = iIso                                                  !--- Update currently selected family index
-   isotope  => isotopes(ixIso)                                   !--- Select corresponding component
-   isoKeys  => isotope%keys;     niso     = isotope%niso
-   isoName  => isotope%trac;     ntiso    = isotope%ntiso
-   isoZone  => isotope%zone;     nzone    = isotope%nzone
-   isoPhas  => isotope%phase;    nphas    = isotope%nphas
-   itZonIso => isotope%itZonIso; isoCheck = isotope%check
-   iqIsoPha => isotope%iqIsoPha
-END FUNCTION isoSelectByIndex
-!==============================================================================================================================
-
-
 END MODULE infotrac_phy
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/iophy.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/iophy.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/iophy.F90	(revision 4482)
@@ -1048,5 +1048,7 @@
 
     !Et sinon on.... écrit
-    IF (SIZE(field)/=klon .AND. SIZE(field)/=klev .AND. SIZE(field)/=klev+1) CALL abort_physic('iophy::histwrite2d_phy','Field first DIMENSION not equal to klon/klev',1)    
+    IF (SIZE(field)/=klon .AND. SIZE(field)/=klev .AND. SIZE(field)/=klev+1) &
+         CALL abort_physic('iophy::histwrite2d_phy',&
+         'Field first DIMENSION not equal to klon/klev',1)
     IF (prt_level >= 10) THEn
       WRITE (lunout,*)"histwrite2d_phy: .not.vars_defined ; time to gather and write ", trim(var%name)
@@ -1246,12 +1248,16 @@
 
     !Et sinon on.... écrit
-    IF (SIZE(field,1)/=klon .AND. SIZE(field,1)/=klev .AND. SIZE(field,1)/=klev+1) CALL abort_physic('iophy::histwrite3d_phy','Field first DIMENSION not equal to klon/klev',1)
+    IF (SIZE(field,1)/=klon .AND. SIZE(field,1)/=klev &
+         .AND. SIZE(field,1)/=klev+1) &
+         CALL abort_physic('iophy::histwrite3d_phy', &
+         'Field first DIMENSION not equal to klon/klev',1)
 
     nlev=SIZE(field,2)
-    IF (nlev.EQ.klev+1) THEN
-        nlevx=klev
-    ELSE
-        nlevx=nlev
-    ENDIF
+    nlevx=nlev
+!    IF (nlev.EQ.klev+1) THEN
+!        nlevx=klev
+!    ELSE
+!        nlevx=nlev
+!    ENDIF
 
     IF (SIZE(field,1) == klon) then
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/iophys.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/iophys.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/iophys.F90	(revision 4482)
@@ -170,8 +170,11 @@
 mois0=day_ref/30+1
 an0=annee_ref
-t0=(day_ini-1)*RDAY
+!FH BIZARE QUAND 1D ...  t0=(day_ini-1)*RDAY
+t0=0.
 calendrier=calend
-
-if ( calendrier == "earth_360d" ) calendrier="360d"
+if ( calendrier == "earth_360d" ) calendrier="360_day"
+
+print*,'iophys_ini annee_ref day_ref',annee_ref,day_ref,day_ini,calend,t0
+
 
 call iotd_ini('phys.nc', &
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/iotd_ecrit.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/iotd_ecrit.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/iotd_ecrit.F90	(revision 4482)
@@ -22,4 +22,5 @@
 !=================================================================
  
+      use netcdf, only: nf90_put_var
       implicit none
 
@@ -108,5 +109,5 @@
 
 
-           ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date)
+           ierr= NF90_PUT_VAR(nid,varid,date,[ntime])
 
 !          print*,'date ',date,ierr,nid
@@ -172,5 +173,5 @@
 
 
-      ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,zx)
+      ierr= NF90_PUT_VAR(nid,varid,zx,corner,edges)
 
       if (ierr.ne.NF_NOERR) then
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/lscp_ini_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/lscp_ini_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/lscp_ini_mod.F90	(revision 4482)
@@ -0,0 +1,90 @@
+module lscp_ini_mod
+
+implicit none
+
+  ! PARAMETERS for lscp:
+  !--------------------
+  
+  REAL, SAVE :: seuil_neb=0.001                 ! cloud fraction threshold: a cloud really exists when exceeded
+  !$OMP THREADPRIVATE(seuil_neb)
+
+  INTEGER, SAVE :: ninter=5                     ! number of iterations to calculate autoconversion to precipitation
+  !$OMP THREADPRIVATE(ninter)
+
+  INTEGER,SAVE :: iflag_evap_prec=1             ! precipitation evaporation flag. 0: nothing, 1: "old way", 
+                                                ! 2: Max cloud fraction above to calculate the max of reevaporation
+                                                ! 4: LTP'method i.e. evaporation in the clear-sky fraction of the mesh only
+  !$OMP THREADPRIVATE(iflag_evap_prec)
+
+  REAL t_coup                                   ! temperature threshold which determines the phase 
+  PARAMETER (t_coup=234.0)                      ! for which the saturation vapor pressure is calculated
+
+  REAL DDT0                                     ! iteration parameter 
+  PARAMETER (DDT0=.01)
+
+  REAL ztfondue                                 ! parameter to calculate melting fraction of precipitation
+  PARAMETER (ztfondue=278.15)
+
+  REAL, SAVE    :: rain_int_min=0.001           ! Minimum local rain intensity [mm/s] before the decrease in associated precipitation fraction 
+  !$OMP THREADPRIVATE(rain_int_min)
+
+  REAL, SAVE :: a_tr_sca(4)                     ! Variables for tracers temporary: alpha parameter for scavenging, 4 possible scavenging processes
+  !$OMP THREADPRIVATE(a_tr_sca)
+  
+  INTEGER, SAVE ::  iflag_mpc_bl=0              ! flag to activate boundary layer mixed phase cloud param
+  !$OMP THREADPRIVATE(iflag_mpc_bl)
+  
+  LOGICAL, SAVE :: ok_radocond_snow=.false.       ! take into account the mass of ice precip in the cloud ice content seen by radiation
+  !$OMP THREADPRIVATE(ok_radocond_snow)
+
+  LOGICAL, SAVE :: ok_debug_autoconversion=.true.   ! removes a bug in the autoconversion process
+  !$OMP THREADPRIVATE(ok_debug_autoconversion)
+
+
+CONTAINS
+
+SUBROUTINE lscp_ini(dtime,ok_ice_sursat)
+
+
+   USE ioipsl_getin_p_mod, ONLY : getin_p
+   USE print_control_mod, ONLY: prt_level, lunout
+   USE ice_sursat_mod, ONLY: ice_sursat_init
+
+   REAL, INTENT(IN)      :: dtime
+   LOGICAL, INTENT(IN)   :: ok_ice_sursat  
+
+    CALL getin_p('ninter',ninter)
+    CALL getin_p('iflag_evap_prec',iflag_evap_prec)
+    CALL getin_p('seuil_neb',seuil_neb)
+    CALL getin_p('rain_int_min',rain_int_min) 
+    CALL getin_p('iflag_mpc_bl',iflag_mpc_bl)
+    CALL getin_p('ok_radocond_snow',ok_radocond_snow) 
+    CALL getin_p('ok_debug_autoconversion',ok_debug_autoconversion)    
+    WRITE(lunout,*) 'lscp, ninter:', ninter
+    WRITE(lunout,*) 'lscp, iflag_evap_prec:', iflag_evap_prec
+    WRITE(lunout,*) 'lscp, seuil_neb:', seuil_neb
+    WRITE(lunout,*) 'lscp, rain_int_min:', rain_int_min
+    WRITE(lunout,*) 'lscp, iflag_mpc_bl:', iflag_mpc_bl
+    WRITE(lunout,*) 'lscp, ok_radocond_snow:', ok_radocond_snow
+    WRITE(lunout,*) 'lscp, ok_debug_autoconversion:', ok_debug_autoconversion
+
+    ! check for precipitation sub-time steps
+    IF (ABS(dtime/REAL(ninter)-360.0).GT.0.001) THEN
+        WRITE(lunout,*) 'lscp: it is not expected, see Z.X.Li', dtime
+        WRITE(lunout,*) 'I would prefer a 6 min sub-timestep'
+    ENDIF
+
+
+    !AA Temporary initialisation
+    a_tr_sca(1) = -0.5
+    a_tr_sca(2) = -0.5
+    a_tr_sca(3) = -0.5
+    a_tr_sca(4) = -0.5
+    
+    IF (ok_ice_sursat) CALL ice_sursat_init()
+
+
+
+end subroutine lscp_ini
+
+end module lscp_ini_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/lscp_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/lscp_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/lscp_mod.F90	(revision 4482)
@@ -1,3 +1,3 @@
-MODULE LSCP_mod
+MODULE lscp_mod
 
 IMPLICIT NONE
@@ -6,13 +6,14 @@
 
 !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-SUBROUTINE LSCP(dtime,missing_val,                      &
+SUBROUTINE lscp(klon,klev,dtime,missing_val,            &
      paprs,pplay,t,q,ptconv,ratqs,                      &
-     d_t, d_q, d_ql, d_qi, rneb, rneb_seri,             &
-     radliq, radicefrac, rain, snow,                    &
-     pfrac_impa, pfrac_nucl, pfrac_1nucl,               &
+     d_t, d_q, d_ql, d_qi, rneb, rneblsvol, rneb_seri,  &
+     radocond, radicefrac, rain, snow,                    &
      frac_impa, frac_nucl, beta,                        &
      prfl, psfl, rhcl, zqta, fraca,                     &
      ztv, zpspsk, ztla, zthl, iflag_cld_th,             &
-     iflag_ice_thermo, ok_ice_sursat)
+     iflag_ice_thermo, ok_ice_sursat, qsatl, qsats,     &
+     qclr, qcld, qss, qvc, rnebclr, rnebss, gamma_ss,   &
+     Tcontr, qcontr, qcontr2, fcontrN, fcontrP)
 
 !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -23,10 +24,10 @@
 !--------------------------------------------------------------------------------
 ! Aim: Large Scale Clouds and Precipitation (LSCP)
-!      
+!
 ! This code is a new version of the fisrtilp.F90 routine, which is itself a 
 ! merge of 'first' (superrsaturation physics, P. LeVan K. Laval)
 ! and 'ilp' (il pleut, L. Li)
 !
-! Compared to fisrtilp, LSCP 
+! Compared to the original fisrtilp code, lscp
 ! -> assumes thermcep = .TRUE. all the time (fisrtilp inconsistent when .FALSE.)
 ! -> consider always precipitation thermalisation (fl_cor_ebil>0)
@@ -40,20 +41,21 @@
 ! References: 
 !
+! - Bony, S., & Emanuel, K. A. 2001, JAS, doi: 10.1175/1520-0469(2001)058<3158:APOTCA>2.0.CO;2
 ! - Hourdin et al. 2013, Clim Dyn, doi:10.1007/s00382-012-1343-y
 ! - Jam et al. 2013, Boundary-Layer Meteorol, doi:10.1007/s10546-012-9789-3
+! - Jouhaud, et al. 2018. JAMES, doi:10.1029/2018MS001379
 ! - Madeleine et al. 2020, JAMES, doi:10.1029/2020MS002046
+! - Touzze-Peifert Ludo, PhD thesis, p117-124
 ! -------------------------------------------------------------------------------
 ! Code structure:
 !
-! P0>     Thermalization of the  precipitation coming from the overlying layer
+! P0>     Thermalization of the precipitation coming from the overlying layer
 ! P1>     Evaporation of the precipitation (falling from the k+1 level)
 ! P2>     Cloud formation (at the k level) 
-! P2.A.0> Cloud properties calculation from a rectangular pdf
-! P2.A.1> With the new PDFs, calculation of cloud properties using the inital
+! P2.A.1> With the PDFs, calculation of cloud properties using the inital
 !         values of T and Q
 ! P2.A.2> Coupling between condensed water and temperature
 ! P2.A.3> Calculation of final quantities associated with cloud formation
-! P2.B>   'All or nothing' cloud
-! P2.C>   Release of Latent heat after cloud formation
+! P2.B>   Release of Latent heat after cloud formation
 ! P3>     Autoconversion to precipitation (k-level)
 ! P4>     Wet scavenging
@@ -64,5 +66,5 @@
 ! water used in the physics and the dynamics 
 ! 
-! During the autoconversion to precipitation (P3 step), radliq (cloud water used
+! During the autoconversion to precipitation (P3 step), radocond (cloud water used
 ! by the radiation scheme) is calculated as an average of the water that remains
 ! in the cloud during the precipitation and not the water remaining at the end
@@ -74,63 +76,56 @@
 ! Radiation:
 ! xflwc(newmicro)+xfiwc(newmicro) =
-!   cldliq(physiq)=radliq(fisrt)=lwcon(nc)+iwcon(nc)
-!
-! Physics/Dynamics:
-! ql_seri(physiq)+qs_seri(physiq)=ocond(nc)
+!   radocond=lwcon(nc)+iwcon(nc)
 !
 ! Notetheless, be aware of:
 !
-! radliq(fisrt) .NE. ocond(nc)
+! radocond .NE. ocond(nc)
 ! i.e.:
 ! lwcon(nc)+iwcon(nc) .NE. ocond(nc)
+! but oliq+(ocond-oliq) .EQ. ocond
 ! (which is not trivial)
 !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-  
-USE dimphy
+!
 USE print_control_mod, ONLY: prt_level, lunout
-USE cloudth_mod 
-USE ioipsl_getin_p_mod, ONLY : getin_p
-USE phys_local_var_mod, ONLY: ql_seri,qs_seri
-USE phys_local_var_mod, ONLY: rneblsvol
-USE lscp_tools_mod, ONLY : CALC_QSAT_ECMWF, ICEFRAC_LSCP, CALC_GAMMASAT, FALLICE_VELOCITY
-USE ice_sursat_mod
-!--ice supersaturation
-USE phys_local_var_mod, ONLY: zqsats, zqsatl
-USE phys_local_var_mod, ONLY: qclr, qcld, qss, qvc, rnebclr, rnebss, gamma_ss
-USE phys_local_var_mod, ONLY: Tcontr, qcontr, qcontr2, fcontrN, fcontrP
+USE cloudth_mod, ONLY : cloudth, cloudth_v3, cloudth_v6, cloudth_mpc 
+USE lscp_tools_mod, ONLY : calc_qsat_ecmwf, icefrac_lscp, calc_gammasat, fallice_velocity
+USE ice_sursat_mod, ONLY : ice_sursat
+
+USE lscp_ini_mod, ONLY : seuil_neb, ninter, iflag_evap_prec, t_coup, DDT0, ztfondue, rain_int_min
+USE lscp_ini_mod, ONLY : iflag_mpc_bl, ok_radocond_snow, a_tr_sca, ok_debug_autoconversion
+
 
 IMPLICIT NONE
 
 !===============================================================================
-! VARIABLE DECLARATION
+! VARIABLES DECLARATION
 !===============================================================================
 
 include "YOMCST.h"
 include "YOETHF.h"
-include "FCTTRE.h"
 include "fisrtilp.h"
 include "nuage.h" 
 
-  
 ! INPUT VARIABLES:
 !-----------------
 
+  INTEGER,                         INTENT(IN)   :: klon,klev       ! number of horizontal grid points and vertical levels
   REAL,                            INTENT(IN)   :: dtime           ! time step [s]
-  REAL, INTENT(IN)                              :: missing_val     ! missing value for output
+  REAL,                            INTENT(IN)   :: missing_val     ! missing value for output
 
   REAL, DIMENSION(klon,klev+1),    INTENT(IN)   :: paprs           ! inter-layer pressure [Pa]
   REAL, DIMENSION(klon,klev),      INTENT(IN)   :: pplay           ! mid-layer pressure [Pa]
   REAL, DIMENSION(klon,klev),      INTENT(IN)   :: t               ! temperature (K)
-  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: q               ! specific humidity [kg/kg]
+  REAL, DIMENSION(klon,klev),      INTENT(IN)   :: q               ! total specific humidity (= vapor phase) [kg/kg] 
   INTEGER,                         INTENT(IN)   :: iflag_cld_th    ! flag that determines the distribution of convective clouds
   INTEGER,                         INTENT(IN)   :: iflag_ice_thermo! flag to activate the ice thermodynamics
-                                                                   ! CR: if iflag_ice_thermo=2, only convection is active    
+                                                                   ! CR: if iflag_ice_thermo=2, only convection is active
   LOGICAL,                         INTENT(IN)   :: ok_ice_sursat   ! flag to determine if ice sursaturation is activated
 
   LOGICAL, DIMENSION(klon,klev),   INTENT(IN)   :: ptconv          ! grid points where deep convection scheme is active
 
-  
+
   !Inputs associated with thermal plumes
-  
+
   REAL, DIMENSION(klon,klev),      INTENT(IN)   :: ztv             ! virtual potential temperature [K]
   REAL, DIMENSION(klon,klev),      INTENT(IN)   :: zqta            ! specific humidity within thermals [kg/kg]
@@ -144,6 +139,6 @@
 
   REAL, DIMENSION(klon,klev),      INTENT(INOUT):: ratqs            ! function of pressure that sets the large-scale
-                                                                    ! cloud PDF (sigma=ratqs*qt)
-  
+  REAL, DIMENSION(klon,klev),      INTENT(INOUT):: beta             ! conversion rate of condensed water
+
 
   ! Input sursaturation en glace
@@ -158,19 +153,15 @@
   REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: d_qi             ! cloud ice mass increment [kg/kg]
   REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: rneb             ! cloud fraction [-]
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: radliq           ! condensed water used in the radiation scheme [kg/kg]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: rneblsvol        ! cloud fraction per unit volume [-]  
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: radocond         ! condensed water used in the radiation scheme [kg/kg]
   REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: radicefrac       ! ice fraction of condensed water for radiation scheme
   REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: rhcl             ! clear-sky relative humidity [-]
-  REAL, DIMENSION(klon),           INTENT(OUT)  :: rain             ! large-scale rainfall [kg/s/m2] 
-  REAL, DIMENSION(klon),           INTENT(OUT)  :: snow             ! large-scale snowfall [kg/s/m2]
+  REAL, DIMENSION(klon),           INTENT(OUT)  :: rain             ! surface large-scale rainfall [kg/s/m2] 
+  REAL, DIMENSION(klon),           INTENT(OUT)  :: snow             ! surface large-scale snowfall [kg/s/m2]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: qsatl            ! saturation specific humidity wrt liquid [kg/kg]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: qsats            ! saturation specific humidity wrt ice [kg/kg]  
   REAL, DIMENSION(klon,klev+1),    INTENT(OUT)  :: prfl             ! large-scale rainfall flux in the column [kg/s/m2]
   REAL, DIMENSION(klon,klev+1),    INTENT(OUT)  :: psfl             ! large-scale snowfall flux in the column [kg/s/m2]
 
- 
-  ! cofficients of scavenging fraction (for off-line)
- 
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: pfrac_nucl       ! scavenging fraction due tu nucleation [-]
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: pfrac_1nucl      ! scavenging fraction due tu nucleation with a -1 factor [-]
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: pfrac_impa       ! scavening fraction due to impaction [-]
-  
   ! fraction of aerosol scavenging through impaction and nucleation (for on-line)
   
@@ -178,39 +169,22 @@
   REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: frac_nucl        ! scavenging fraction due tu nucleation [-]
   
-
-
-
-  ! PROGRAM PARAMETERS:
-  !--------------------
+  ! for supersaturation and contrails parameterisation
   
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: qclr             ! specific total water content in clear sky region [kg/kg]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: qcld             ! specific total water content in cloudy region [kg/kg]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: qss              ! specific total water content in supersat region [kg/kg]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: qvc              ! specific vapor content in clouds [kg/kg] 
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: rnebclr          ! mesh fraction of clear sky [-]   
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: rnebss           ! mesh fraction of ISSR [-]  
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: gamma_ss         ! coefficient governing the ice nucleation RHi threshold [-]      
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: Tcontr           ! threshold temperature for contrail formation [K]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: qcontr           ! threshold humidity for contrail formation [kg/kg]
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: qcontr2          ! // (2nd expression more consistent with LMDZ expression of q)          
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: fcontrN          ! fraction of grid favourable to non-persistent contrails
+  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: fcontrP          ! fraction of grid favourable to persistent contrails
   
-  REAL, SAVE :: seuil_neb=0.001                                     ! cloud fraction threshold: a cloud really exists when exceeded
-  !$OMP THREADPRIVATE(seuil_neb)
-
-  INTEGER, SAVE :: ninter=5                                         ! number of iterations to calculate autoconversion to precipitation
-  !$OMP THREADPRIVATE(ninter)
-
-  INTEGER,SAVE :: iflag_evap_prec=1                                 ! precipitation evap. flag. 0: nothing, 1: "old way", 2: Max cloud fraction above to calculate the max of reevaporation
-                                                                    ! 4: LTP'method i.e. evaporation in the clear-sky fraction of the mesh only
-  !$OMP THREADPRIVATE(iflag_evap_prec)
-                                                                    
-
-  REAL t_coup                                                       ! temperature threshold which determines the phase 
-  PARAMETER (t_coup=234.0)                                          ! for which the saturation vapor pressure is calculated
-
-  REAL DDT0                                                         ! iteration parameter 
-  PARAMETER (DDT0=.01)
-
-  REAL ztfondue                                                     ! parameter to calculate melting fraction of precipitation
-  PARAMETER (ztfondue=278.15)
-
-  REAL, SAVE    :: rain_int_min=0.001                               ! Minimum local rain intensity [mm/s] before the decrease in associated precipitation fraction 
-  !$OMP THREADPRIVATE(rain_int_min)
-
-
 
   ! LOCAL VARIABLES:
   !----------------
-
 
   REAL qsl(klon), qsi(klon)
@@ -218,12 +192,12 @@
   REAL ctot(klon,klev)
   REAL ctot_vol(klon,klev)
-  REAL zqs(klon), zdqs(klon), zdelta, zcor, zcvm5  
+  REAL zqs(klon), zdqs(klon), zdelta, zcor, zcvm5
   REAL zdqsdT_raw(klon)
-  REAL gammasat(klon),dgammasatdt(klon)                                 ! coefficient to make cold condensation at the correct RH and derivative wrt T
+  REAL gammasat(klon),dgammasatdt(klon)                ! coefficient to make cold condensation at the correct RH and derivative wrt T
   REAL Tbef(klon),qlbef(klon),DT(klon),num,denom
   REAL cste
   REAL zpdf_sig(klon),zpdf_k(klon),zpdf_delta(klon)
   REAL Zpdf_a(klon),zpdf_b(klon),zpdf_e1(klon),zpdf_e2(klon)
-  REAL erf   
+  REAL erf
   REAL qcloud(klon), icefrac_mpc(klon,klev), qincloud_mpc(klon)
   REAL zrfl(klon), zrfln(klon), zqev, zqevt 
@@ -245,38 +219,28 @@
   ! Variables precipitation energy conservation
   REAL zmqc(klon)
-  ! Variables for tracers
-  ! temporary: alpha parameter for scavenging
-  ! 4 possible scavenging processes
-  REAL a_tr_sca(4)
-  save a_tr_sca
-  !$OMP THREADPRIVATE(a_tr_sca)  
   REAL zalpha_tr
   REAL zfrac_lessi
   REAL zprec_cond(klon)
-  REAL beta(klon,klev)                   ! conversion rate of condensed water
   REAL zmair(klon), zcpair, zcpeau
   REAL zlh_solid(klon), zm_solid         ! for liquid -> solid conversion
-  REAL zrflclr(klon), zrflcld(klon)                                                                    
-  REAL d_zrfl_clr_cld(klon), d_zifl_clr_cld(klon)                                                   
+  REAL zrflclr(klon), zrflcld(klon)
+  REAL d_zrfl_clr_cld(klon), d_zifl_clr_cld(klon)
   REAL d_zrfl_cld_clr(klon), d_zifl_cld_clr(klon) 
-  REAL ziflclr(klon), ziflcld(klon)                                                                    
-  REAL znebprecipclr(klon), znebprecipcld(klon)                                                        
-  REAL tot_zneb(klon), tot_znebn(klon), d_tot_zneb(klon)                                              
+  REAL ziflclr(klon), ziflcld(klon)
+  REAL znebprecipclr(klon), znebprecipcld(klon)
+  REAL tot_zneb(klon), tot_znebn(klon), d_tot_zneb(klon)
   REAL d_znebprecip_clr_cld(klon), d_znebprecip_cld_clr(klon)
   REAL velo(klon,klev), vr
   REAL qlmpc, qimpc, rnebmpc
-  REAL radliqi(klon,klev), radliql(klon,klev)
+  REAL radocondi(klon,klev), radocondl(klon,klev)
 
   INTEGER i, k, n, kk
   INTEGER n_i(klon), iter
-  INTEGER ncoreczq  
+  INTEGER ncoreczq
   INTEGER mpc_bl_points(klon,klev)
-  INTEGER,SAVE :: itap=0
-  !$OMP THREADPRIVATE(itap)
 
   LOGICAL lognormale(klon)
-  LOGICAL convergence(klon)
-  LOGICAL appel1er
-  SAVE appel1er
+  LOGICAL keepgoing(klon)
+  LOGICAL,SAVE :: appel1er
   !$OMP THREADPRIVATE(appel1er)
 
@@ -290,5 +254,5 @@
 !===============================================================================
 
-! Few initial checksS
+! Few initial checks
 
 IF (iflag_t_glace.EQ.0) THEN
@@ -302,74 +266,30 @@
 ENDIF
 
-IF (.NOT.thermcep) THEN
-     abort_message = 'lscp cannot be used when thermcep=false'
-     CALL abort_physic(modname,abort_message,1)
+IF (iflag_fisrtilp_qsat .LT. 0) THEN
+    abort_message = 'lscp cannot be used with iflag_fisrtilp<0'
+    CALL abort_physic(modname,abort_message,1)
 ENDIF
 
-IF (iflag_fisrtilp_qsat .LT. 0) THEN
-        abort_message = 'lscp cannot be used with iflag_fisrtilp<0'
-     CALL abort_physic(modname,abort_message,1)
-ENDIF
-
-
 ! Few initialisations
 
-itap=itap+1
-znebprecip(:)=0.
+znebprecip(:)=0.0
 ctot_vol(1:klon,1:klev)=0.0
 rneblsvol(1:klon,1:klev)=0.0
-smallestreal=1.e-9                                                                                  
-znebprecipclr(:)=0.    
-znebprecipcld(:)=0.                                                                            
+smallestreal=1.e-9
+znebprecipclr(:)=0.0
+znebprecipcld(:)=0.0
 mpc_bl_points(:,:)=0
 
 IF (prt_level>9) WRITE(lunout,*) 'NUAGES4 A. JAM'
-
-IF (appel1er) THEN
-    CALL getin_p('ninter',ninter)
-    CALL getin_p('iflag_evap_prec',iflag_evap_prec)
-    CALL getin_p('seuil_neb',seuil_neb)
-    CALL getin_p('rain_int_min',rain_int_min) 
-    WRITE(lunout,*) 'lscp, ninter:', ninter
-    WRITE(lunout,*) 'lscp, iflag_evap_prec:', iflag_evap_prec
-    WRITE(lunout,*) 'lscp, seuil_neb:', seuil_neb
-    WRITE(lunout,*) 'lscp, rain_int_min:', rain_int_min
-
-    ! check for precipitation sub-time steps
-    IF (ABS(dtime/REAL(ninter)-360.0).GT.0.001) THEN
-        WRITE(lunout,*) 'lscp: it is not expected, see Z.X.Li', dtime
-        WRITE(lunout,*) 'I would prefer a 6 min sub-timestep'
-    ENDIF
-     
-    !AA Temporary initialisation
-    a_tr_sca(1) = -0.5
-    a_tr_sca(2) = -0.5
-    a_tr_sca(3) = -0.5
-    a_tr_sca(4) = -0.5
-
-    !AA Set scavenged fractions to 1
-    DO k = 1, klev
-        DO i = 1, klon
-            pfrac_nucl(i,k)=1.
-            pfrac_1nucl(i,k)=1.
-            pfrac_impa(i,k)=1.
-            beta(i,k)=0.       
-        ENDDO
-    ENDDO
-
-    IF (ok_ice_sursat) CALL ice_sursat_init()
-
-    appel1er = .FALSE.
-
-ENDIF     !(appel1er)  
 
 ! AA for 'safety' reasons
 zalpha_tr   = 0.
 zfrac_lessi = 0.
-
-! Initialisation of output variables (JYG):
+beta(:,:)= 0.
+
+! Initialisation of variables:
+
 prfl(:,:) = 0.0
 psfl(:,:) = 0.0
-
 d_t(:,:) = 0.0
 d_q(:,:) = 0.0
@@ -377,9 +297,8 @@
 d_qi(:,:) = 0.0
 rneb(:,:) = 0.0
-radliq(:,:) = 0.0
+radocond(:,:) = 0.0
 radicefrac(:,:) = 0.0
-frac_nucl(:,:) = 1. 
-frac_impa(:,:) = 1. 
-
+frac_nucl(:,:) = 1.0 
+frac_impa(:,:) = 1.0 
 rain(:) = 0.0
 snow(:) = 0.0
@@ -393,17 +312,17 @@
 ziflprev(:)=0.0
 zneb(:) = seuil_neb
-zrflclr(:) = 0.0                                                                            
-ziflclr(:) = 0.0                                                                            
-zrflcld(:) = 0.0                                                                               
-ziflcld(:) = 0.0                                                                                  
-tot_zneb(:) = 0.0                                                                                 
-tot_znebn(:) = 0.0                                                                               
-d_tot_zneb(:) = 0.0   
-qzero(:)=0.0
-
-!--ice sursaturation
-gamma_ss(:,:) = 1.
-qss(:,:) = 0.
-rnebss(:,:) = 0.
+zrflclr(:) = 0.0
+ziflclr(:) = 0.0
+zrflcld(:) = 0.0
+ziflcld(:) = 0.0
+tot_zneb(:) = 0.0
+tot_znebn(:) = 0.0
+d_tot_zneb(:) = 0.0
+qzero(:) = 0.0
+
+!--ice supersaturation
+gamma_ss(:,:) = 1.0
+qss(:,:) = 0.0
+rnebss(:,:) = 0.0
 Tcontr(:,:) = missing_val
 qcontr(:,:) = missing_val
@@ -412,4 +331,7 @@
 fcontrP(:,:) = 0.0
 
+!c_iso: variable initialisation for iso 
+
+
 !===============================================================================
 !              BEGINNING OF VERTICAL LOOP FROM TOP TO BOTTOM
@@ -419,5 +341,4 @@
 
 DO k = klev, 1, -1
-
 
     ! Initialisation temperature and specific humidity
@@ -425,4 +346,5 @@
         zt(i)=t(i,k)
         zq(i)=q(i,k)
+        !c_iso init of iso
     ENDDO
     
@@ -430,14 +352,18 @@
     ! P0> Thermalization of precipitation falling from the overlying layer
     ! --------------------------------------------------------------------
-    ! Computes air temperature variation due to latent heat transported by
+    ! Computes air temperature variation due to enthalpy transported by
     ! precipitation. Precipitation is then thermalized with the air in the
     ! layer. 
     ! The precipitation should remain thermalized throughout the different
-    ! thermodynamical transformations. The corresponding water mass should
+    ! thermodynamical transformations. 
+    ! The corresponding water mass should
     ! be added when calculating the layer's enthalpy change with 
     ! temperature
+    ! See lmdzpedia page todoan
+    ! todoan: check consistency with ice phase
+    ! todoan: understand why several steps
     ! ---------------------------------------------------------------------
     
-    IF (k.LE.klevm1) THEN 
+    IF (k.LE.klev-1) THEN 
 
         DO i = 1, klon
@@ -447,6 +373,6 @@
             ! RVTMP2=rcpv/rcpd-1
             zcpair=RCPD*(1.0+RVTMP2*zq(i)) 
-            zcpeau=RCPD*RVTMP2             
-                                          
+            zcpeau=RCPD*RVTMP2
+
             ! zmqc: precipitation mass that has to be thermalized with 
             ! layer's air so that precipitation at the ground has the
@@ -456,8 +382,8 @@
             zt(i) = ( (t(i,k+1)+d_t(i,k+1))*zmqc(i)*zcpeau + zcpair*zt(i) ) &
              / (zcpair + zmqc(i)*zcpeau)
-           
+
         ENDDO
  
-    ELSE  
+    ELSE
  
         DO i = 1, klon 
@@ -474,25 +400,26 @@
     ! --------------------------------------------------------------------
 
-
-    IF (iflag_evap_prec.GE.1) THEN
+    IF (iflag_evap_prec.GE.1) THEN 
 
         ! Calculation of saturation specific humidity
         ! depending on temperature:
-        CALL CALC_QSAT_ECMWF(klon,zt(:),qzero(:),pplay(:,k),RTT,0,.false.,zqs(:),zdqs(:))
+        CALL calc_qsat_ecmwf(klon,zt(:),qzero(:),pplay(:,k),RTT,0,.false.,zqs(:),zdqs(:))
         ! wrt liquid water
-        CALL CALC_QSAT_ECMWF(klon,zt(:),qzero(:),pplay(:,k),RTT,1,.false.,qsl(:),dqsl(:))
+        CALL calc_qsat_ecmwf(klon,zt(:),qzero(:),pplay(:,k),RTT,1,.false.,qsl(:),dqsl(:))
         ! wrt ice
-        CALL CALC_QSAT_ECMWF(klon,zt(:),qzero(:),pplay(:,k),RTT,2,.false.,qsi(:),dqsi(:))
+        CALL calc_qsat_ecmwf(klon,zt(:),qzero(:),pplay(:,k),RTT,2,.false.,qsi(:),dqsi(:))
 
         DO i = 1, klon
-     
+
             ! if precipitation
             IF (zrfl(i)+zifl(i).GT.0.) THEN
-                    
-            ! LTP: we only account for precipitation evaporation in the clear-sky (iflag_evap_prec=4).
-                IF (iflag_evap_prec.EQ.4) THEN                                                          
-                    zrfl(i) = zrflclr(i)                                                          
-                    zifl(i) = ziflclr(i)                                                           
-                ENDIF                      
+
+            ! LudoTP: we only account for precipitation evaporation in the clear-sky (iflag_evap_prec=4).
+            ! c_iso: likely important to distinguish cs from neb isotope precipitation
+
+                IF (iflag_evap_prec.EQ.4) THEN
+                    zrfl(i) = zrflclr(i)
+                    zifl(i) = ziflclr(i)
+                ENDIF
 
                 IF (iflag_evap_prec.EQ.1) THEN
@@ -501,14 +428,12 @@
                     znebprecip(i)=MAX(zneb(i),znebprecip(i))
                 ENDIF
-     
-                                                                                                                                                                                                                  
-                IF (iflag_evap_prec.EQ.4) THEN                                                                 
-                ! Max evaporation not to saturate the whole mesh                                             
-                    zqev0 = MAX(0.0, zqs(i)-zq(i))                                                              
-                ELSE       
-                ! Max evap not to saturate the fraction below the cloud                                                   
-                    zqev0 = MAX(0.0, (zqs(i)-zq(i))*znebprecip(i))                                                                                  
-                ENDIF   
-
+
+                IF (iflag_evap_prec.EQ.4) THEN
+                ! Max evaporation not to saturate the whole mesh
+                    zqev0 = MAX(0.0, zqs(i)-zq(i))
+                ELSE
+                ! Max evap not to saturate the fraction below the cloud
+                    zqev0 = MAX(0.0, (zqs(i)-zq(i))*znebprecip(i))
+                ENDIF
 
                 ! Evaporation of liquid precipitation coming from above
@@ -530,8 +455,7 @@
                 ENDIF
 
-
                 zqevt = MAX(0.0,MIN(zqevt,zrfl(i))) &
-                *RG*dtime/(paprs(i,k)-paprs(i,k+1)) 
-         
+                    *RG*dtime/(paprs(i,k)-paprs(i,k+1)) 
+
                 ! sublimation of the solid precipitation coming from above
                 IF (iflag_evap_prec.EQ.3) THEN
@@ -547,7 +471,7 @@
                     *(paprs(i,k)-paprs(i,k+1))/pplay(i,k)*zt(i)*RD/RG
                 ENDIF
-            
+
                 zqevti = MAX(0.0,MIN(zqevti,zifl(i))) &
-                *RG*dtime/(paprs(i,k)-paprs(i,k+1))   
+                *RG*dtime/(paprs(i,k)-paprs(i,k+1))
 
                 ! A. JAM
@@ -556,5 +480,6 @@
                 ! does not reach saturation. In this case, we 
                 ! redistribute zqev0 conserving the ratio liquid/ice 
-   
+
+                ! todoan: check the consistency of this formula
                 IF (zqevt+zqevti.GT.zqev0) THEN
                     zqev=zqev0*zqevt/(zqevt+zqevti)
@@ -566,5 +491,5 @@
 
 
-                ! New solid and liquid precipitation fluxes
+                ! New solid and liquid precipitation fluxes after evap and sublimation
                 zrfln(i) = Max(0.,zrfl(i) - zqev*(paprs(i,k)-paprs(i,k+1))  &
                          /RG/dtime)
@@ -572,8 +497,8 @@
                          /RG/dtime)
 
+
                 ! vapor, temperature, precip fluxes update
                 zq(i) = zq(i) - (zrfln(i)+zifln(i)-zrfl(i)-zifl(i)) &
                 * (RG/(paprs(i,k)-paprs(i,k+1)))*dtime
-                ! precip thermalization
                 zmqc(i) = zmqc(i) + (zrfln(i)+zifln(i)-zrfl(i)-zifl(i)) &
                 * (RG/(paprs(i,k)-paprs(i,k+1)))*dtime
@@ -589,27 +514,43 @@
                 zifl(i) = zifln(i)
 
-                IF (iflag_evap_prec.EQ.4) THEN                                                                 
-                    zrflclr(i) = zrfl(i)                                                                  
-                    ziflclr(i) = zifl(i)    
-                    IF(zrflclr(i) + ziflclr(i).LE.0) THEN                                                
-                        znebprecipclr(i) = 0.                                                          
-                    ENDIF                                                                                
-                    zrfl(i) = zrflclr(i) + zrflcld(i)                                                      
-                    zifl(i) = ziflclr(i) + ziflcld(i)                                                      
-                ENDIF      
-
-
-                ! CR Be careful: ice melting has been moved
-                zmelt = ((zt(i)-273.15)/(ztfondue-273.15)) ! JYG
+                ! c_iso here call_reevap that updates isotopic zrfl, zifl (in inout)
+                !                         due to evap + sublim                                     
+                                           
+
+                IF (iflag_evap_prec.EQ.4) THEN
+                    zrflclr(i) = zrfl(i)
+                    ziflclr(i) = zifl(i)
+                    IF(zrflclr(i) + ziflclr(i).LE.0) THEN
+                        znebprecipclr(i) = 0.0
+                    ENDIF
+                    zrfl(i) = zrflclr(i) + zrflcld(i)
+                    zifl(i) = ziflclr(i) + ziflcld(i)
+                ENDIF
+
+                ! c_iso duplicate for isotopes or loop on isotopes
+
+                ! Melting:
+                zmelt = ((zt(i)-RTT)/(ztfondue-RTT)) ! JYG
                 ! precip fraction that is melted
                 zmelt = MIN(MAX(zmelt,0.),1.)
-                ! Ice melting
-                IF (iflag_evap_prec.EQ.4) THEN                                                              
-                    zrflclr(i)=zrflclr(i)+zmelt*ziflclr(i)                                            
-                    zrflcld(i)=zrflcld(i)+zmelt*ziflcld(i)                                              
-                    zrfl(i)=zrflclr(i)+zrflcld(i)                                                       
-                ELSE                                                                                        
-                    zrfl(i)=zrfl(i)+zmelt*zifl(i)                                                      
-                ENDIF                  
+
+                ! update of rainfall and snowfall due to melting
+                IF (iflag_evap_prec.EQ.4) THEN
+                    zrflclr(i)=zrflclr(i)+zmelt*ziflclr(i)
+                    zrflcld(i)=zrflcld(i)+zmelt*ziflcld(i)
+                    zrfl(i)=zrflclr(i)+zrflcld(i)
+
+                    ziflclr(i)=ziflclr(i)*(1.-zmelt)
+                    ziflcld(i)=ziflcld(i)*(1.-zmelt)
+                    zifl(i)=ziflclr(i)+ziflcld(i)
+
+                ELSE
+                    zrfl(i)=zrfl(i)+zmelt*zifl(i)
+
+                    zifl(i)=zifl(i)*(1.-zmelt)
+                ENDIF
+
+
+                ! c_iso: melting of isotopic precipi with zmelt (no fractionation)
 
                 ! Latent heat of melting with precipitation thermalization
@@ -617,11 +558,4 @@
                 *RLMLT/RCPD/(1.0+RVTMP2*(zq(i)+zmqc(i)))
                 
-                IF (iflag_evap_prec.EQ.4) THEN                                                             
-                    ziflclr(i)=ziflclr(i)*(1.-zmelt)                                                    
-                    ziflcld(i)=ziflcld(i)*(1.-zmelt)                                                    
-                    zifl(i)=ziflclr(i)+ziflcld(i)                                                       
-                ELSE                                                                                      
-                    zifl(i)=zifl(i)*(1.-zmelt)                                                          
-                ENDIF
 
             ELSE
@@ -632,5 +566,5 @@
 
         ENDDO
-         
+
     ENDIF ! (iflag_evap_prec>=1)
 
@@ -638,13 +572,10 @@
     ! End precip evaporation
     ! --------------------------------------------------------------------
-
-
-
     
     ! Calculation of qsat, L/Cp*dqsat/dT and ncoreczq counter
     !-------------------------------------------------------
-      
+
      qtot(:)=zq(:)+zmqc(:)
-     CALL CALC_QSAT_ECMWF(klon,zt(:),qtot(:),pplay(:,k),RTT,0,.false.,zqs(:),zdqs(:))
+     CALL calc_qsat_ecmwf(klon,zt(:),qtot(:),pplay(:,k),RTT,0,.false.,zqs(:),zdqs(:))
      DO i = 1, klon
             zdelta = MAX(0.,SIGN(1.,RTT-zt(i)))
@@ -654,8 +585,8 @@
                 zq(i)=1.e-15
             ENDIF
+            ! c_iso: do something similar for isotopes
 
      ENDDO
     
-
     ! --------------------------------------------------------------------
     ! P2> Cloud formation
@@ -670,7 +601,6 @@
     ! -------------------------------------------------------------------
 
-           
         ! P2.1> With the PDFs (log-normal, bigaussian) 
-        ! cloud propertues calculation with the initial values of t and q
+        ! cloud properties calculation with the initial values of t and q
         ! ----------------------------------------------------------------
 
@@ -697,8 +627,7 @@
                          ratqs,zqs,t)
 
-
                 !Jean Jouhaud's version, Decembre 2018 
-                !-------------------------------------              
-             
+                !-------------------------------------
+
                 ELSEIF (iflag_cloudth_vert.EQ.6) THEN
 
@@ -714,5 +643,5 @@
                 ! + stationary mixed-phase cloud model
 
-                    CALL cloudth_mpc(klon,klev,k,mpc_bl_points,            &
+                    CALL cloudth_mpc(klon,klev,k,iflag_mpc_bl,mpc_bl_points, &
                          t,ztv,zq,zqta,fraca, zpspsk,                      &
                          paprs,pplay,ztla,zthl,ratqs,zqs,psfl,             &
@@ -740,5 +669,5 @@
 
         ELSE
-                ! When iflag_cld_th=5, we always assume  
+                ! When iflag_cld_th=5, we always assume
                 ! bi-gaussian distribution
             lognormale = .FALSE.
@@ -746,5 +675,4 @@
         ENDIF
 
-
         DT(:) = 0.
         n_i(:)=0
@@ -754,16 +682,18 @@
         ! Treatment of non-boundary layer clouds (lognormale)
         ! condensation with qsat(T) variation (adaptation)
-        ! Iterative Loop to converge towards qsat
-        
-        
+        ! Iterative resolution to converge towards qsat
+        ! with update of temperature, ice fraction and qsat at 
+        ! each iteration
+
+        ! todoan -> sensitivity to iflag_fisrtilp_qsat
         DO iter=1,iflag_fisrtilp_qsat+1
-                
+
                 DO i=1,klon
 
-                    ! convergence = .true. until when convergence is not satisfied
-                    convergence(i)=ABS(DT(i)).GT.DDT0
-                   
-                    IF ((convergence(i) .OR. (n_i(i) .EQ. 0)) .AND. lognormale(i)) THEN
-                          
+                    ! keepgoing = .true. while convergence is not satisfied
+                    keepgoing(i)=ABS(DT(i)).GT.DDT0
+
+                    IF ((keepgoing(i) .OR. (n_i(i) .EQ. 0)) .AND. lognormale(i)) THEN
+
                         ! if not convergence:
 
@@ -776,26 +706,24 @@
                         !---------------------------------------------------------------
 
-                        ! new temperature:
+                        ! new temperature that only serves in the iteration process:
                         Tbef(i)=Tbef(i)+DT(i)
 
                         ! Rneb, qzn and zcond for lognormal PDFs
                         qtot(i)=zq(i)+zmqc(i)
-                    
+
                       ENDIF
 
                   ENDDO
 
-                  ! Calculation of saturation specific humidity and ce fraction
-                  CALL CALC_QSAT_ECMWF(klon,Tbef(:),qtot(:),pplay(:,k),RTT,0,.false.,zqs(:),zdqs(:))
-                  CALL CALC_GAMMASAT(klon,Tbef(:),qtot(:),pplay(:,k),gammasat(:),dgammasatdt(:))
+                  ! Calculation of saturation specific humidity and ice fraction
+                  CALL calc_qsat_ecmwf(klon,Tbef(:),qtot(:),pplay(:,k),RTT,0,.false.,zqs(:),zdqs(:))
+                  CALL calc_gammasat(klon,Tbef(:),qtot(:),pplay(:,k),gammasat(:),dgammasatdt(:))
                   ! saturation may occur at a humidity different from qsat (gamma qsat), so gamma correction for dqs
                   zdqs(:) = gammasat(:)*zdqs(:)+zqs(:)*dgammasatdt(:)
-                  CALL ICEFRAC_LSCP(klon, zt(:),pplay(:,k)/paprs(:,1),zfice(:),dzfice(:))
-
-
-
-                  DO i=1,klon
-
-                      IF ((convergence(i) .OR. (n_i(i) .EQ. 0)) .AND. lognormale(i)) THEN
+                  CALL icefrac_lscp(klon, zt(:),pplay(:,k)/paprs(:,1),zfice(:),dzfice(:))
+
+                  DO i=1,klon !todoan : check if loop in i is needed
+
+                      IF ((keepgoing(i) .OR. (n_i(i) .EQ. 0)) .AND. lognormale(i)) THEN
 
                         zpdf_sig(i)=ratqs(i,k)*zq(i)
@@ -810,6 +738,5 @@
                         zpdf_e2(i)=sign(min(ABS(zpdf_e2(i)),5.),zpdf_e2(i))
                         zpdf_e2(i)=1.-erf(zpdf_e2(i))
-             
-                        !--ice sursaturation by Audran
+
                         IF ((.NOT.ok_ice_sursat).OR.(Tbef(i).GT.t_glace_min)) THEN
 
@@ -826,7 +753,7 @@
                           fcontrP(i,k)=0.0  !--idem
                           qss(i,k)=0.0      !--idem
-                       
-                        ELSE
-               
+
+                       ELSE ! in case of ice supersaturation by Audran
+
                         !------------------------------------
                         ! ICE SUPERSATURATION
@@ -834,6 +761,6 @@
 
                         CALL ice_sursat(pplay(i,k), paprs(i,k)-paprs(i,k+1), dtime, i, k, t(i,k), zq(i), &
-                             gamma_ss(i,k), zqs(i), Tbef(i), rneb_seri(i,k), ratqs(i,k),               &  
-                             rneb(i,k), zqn(i), rnebss(i,k), qss(i,k),                                 & 
+                             gamma_ss(i,k), zqs(i), Tbef(i), rneb_seri(i,k), ratqs(i,k),                 &
+                             rneb(i,k), zqn(i), rnebss(i,k), qss(i,k),                                   & 
                              Tcontr(i,k), qcontr(i,k), qcontr2(i,k), fcontrN(i,k), fcontrP(i,k) )
 
@@ -862,18 +789,18 @@
                         qlbef(i)=max(0.,zqn(i)-zqs(i))
                         num = -Tbef(i)+zt(i)+rneb(i,k)*((1-zfice(i))*RLVTT &
-                        &   +zfice(i)*RLSTT)/RCPD/(1.0+RVTMP2*(zq(i)+zmqc(i)))*qlbef(i)
+                              +zfice(i)*RLSTT)/RCPD/(1.0+RVTMP2*(zq(i)+zmqc(i)))*qlbef(i)
                         denom = 1.+rneb(i,k)*((1-zfice(i))*RLVTT+zfice(i)*RLSTT)/cste*zdqs(i) &
                               -(RLSTT-RLVTT)/RCPD/(1.0+RVTMP2*(zq(i)+zmqc(i)))*rneb(i,k)      &
-                        &     *qlbef(i)*dzfice(i)
+                              *qlbef(i)*dzfice(i)
+                        ! here we update a provisory temperature variable that only serves in the iteration
+                        ! process
                         DT(i)=num/denom
                         n_i(i)=n_i(i)+1
 
-                    ENDIF ! end convergence
+                    ENDIF ! end keepgoing
 
                 ENDDO     ! end loop on i
 
         ENDDO         ! iter=1,iflag_fisrtilp_qsat+1
-
-
 
         ! P2.3> Final quantities calculation 
@@ -886,10 +813,8 @@
         ! ----------------------------------------------------------------
 
-
-
         ! Water vapor update, Phase determination and subsequent latent heat exchange
 
         ! Partition function in stratiform clouds (will be overwritten in boundary-layer MPCs)
-        CALL ICEFRAC_LSCP(klon,zt(:),pplay(:,k)/paprs(:,1),zfice(:), dzfice(:))
+        CALL icefrac_lscp(klon,zt(:),pplay(:,k)/paprs(:,1),zfice(:), dzfice(:))
 
         DO i=1, klon
@@ -923,9 +848,11 @@
                 ENDIF
 
-
                 ! water vapor update 
-                zq(i) = zq(i) - zcond(i)        
-            
+                zq(i) = zq(i) - zcond(i)
+
             ENDIF
+
+            ! c_iso : routine that computes in-cloud supersaturation
+            ! c_iso condensation of isotopes (zcond, zsursat, zfice, zq in input) 
 
             ! temperature update due to phase change
@@ -935,5 +862,4 @@
         ENDDO
 
-
         ! If vertical heterogeneity, change volume fraction 
         IF (iflag_cloudth_vert .GE. 3) THEN
@@ -945,5 +871,5 @@
     ! P3> Precipitation formation 
     ! ----------------------------------------------------------------
-    
+
     ! LTP:
     IF (iflag_evap_prec==4) THEN
@@ -955,6 +881,6 @@
         
         DO i=1, klon
-                tot_znebn(i) = 1 - (1-tot_zneb(i))*(1 - max(rneb(i,k),zneb(i))) &
-                        /(1-min(zneb(i),1-smallestreal))
+                tot_znebn(i) = 1. - (1.-tot_zneb(i))*(1 - max(rneb(i,k),zneb(i))) &
+                        /(1.-min(zneb(i),1.-smallestreal))
                 d_tot_zneb(i) = tot_znebn(i) - tot_zneb(i)
                 tot_zneb(i) = tot_znebn(i)
@@ -963,5 +889,5 @@
                 !1) Cloudy to clear air
                 d_znebprecip_cld_clr(i) = znebprecipcld(i) - min(rneb(i,k),znebprecipcld(i)) 
-                IF (znebprecipcld(i) .GT. 0) THEN
+                IF (znebprecipcld(i) .GT. 0.) THEN
                         d_zrfl_cld_clr(i) = d_znebprecip_cld_clr(i)/znebprecipcld(i)*zrflcld(i) 
                         d_zifl_cld_clr(i) = d_znebprecip_cld_clr(i)/znebprecipcld(i)*ziflcld(i) 
@@ -972,6 +898,5 @@
 
                 !2) Clear to cloudy air
-                d_znebprecip_clr_cld(i) = max(0., min(znebprecipclr(i), rneb(i,k) &
-                        - d_tot_zneb(i) - zneb(i)))
+                d_znebprecip_clr_cld(i) = max(0., min(znebprecipclr(i), rneb(i,k) - d_tot_zneb(i) - zneb(i)))
                 IF (znebprecipclr(i) .GT. 0) THEN
                         d_zrfl_clr_cld(i) = d_znebprecip_clr_cld(i)/znebprecipclr(i)*zrflclr(i) 
@@ -983,5 +908,5 @@
 
                 !Update variables
-                znebprecipcld(i) = znebprecipcld(i) + d_znebprecip_clr_cld(i) - d_znebprecip_cld_clr(i)  
+                znebprecipcld(i) = znebprecipcld(i) + d_znebprecip_clr_cld(i) - d_znebprecip_cld_clr(i)
                 znebprecipclr(i) = znebprecipclr(i) + d_znebprecip_cld_clr(i) - d_znebprecip_clr_cld(i) 
                 zrflcld(i) = zrflcld(i) + d_zrfl_clr_cld(i) - d_zrfl_cld_clr(i) 
@@ -990,8 +915,9 @@
                 ziflclr(i) = ziflclr(i) + d_zifl_cld_clr(i) - d_zifl_clr_cld(i)
 
+                ! c_iso  do the same thing for isotopes precip
         ENDDO
     ENDIF
 
-    ! Initialisation of zoliq and radliq variables
+    ! Initialisation of zoliq and radocond variables
 
     DO i = 1, klon
@@ -999,15 +925,15 @@
             zoliqi(i)= zoliq(i)*zfice(i)
             zoliql(i)= zoliq(i)*(1.-zfice(i))
+            ! c_iso : initialisation of zoliq* also for isotopes
             zrho(i,k)  = pplay(i,k) / zt(i) / RD
             zdz(i)   = (paprs(i,k)-paprs(i,k+1)) / (zrho(i,k)*RG)
             iwc(i)   = 0. 
             zneb(i)  = MAX(rneb(i,k),seuil_neb)
-            radliq(i,k) = zoliq(i)/REAL(ninter+1)
+            radocond(i,k) = zoliq(i)/REAL(ninter+1)
             radicefrac(i,k) = zfice(i)
-            radliqi(i,k)=zoliq(i)*zfice(i)/REAL(ninter+1)
-            radliql(i,k)=zoliq(i)*(1.-zfice(i))/REAL(ninter+1)
+            radocondi(i,k)=zoliq(i)*zfice(i)/REAL(ninter+1)
+            radocondl(i,k)=zoliq(i)*(1.-zfice(i))/REAL(ninter+1)
     ENDDO
 
-    ! -------------------------------------------------------------------------------
     ! Autoconversion
     ! -------------------------------------------------------------------------------
@@ -1021,5 +947,5 @@
         ENDDO
 
-        CALL FALLICE_VELOCITY(klon,iwc(:),zt(:),zrho(:,k),pplay(:,k),ptconv(:,k),velo(:,k))
+        CALL fallice_velocity(klon,iwc(:),zt(:),zrho(:,k),pplay(:,k),ptconv(:,k),velo(:,k))
 
         DO i = 1, klon
@@ -1031,4 +957,5 @@
                 zsnow=0.
                 zprecip=0.
+                ! c_iso same init for isotopes. Externalisation?
 
                 IF (zneb(i).EQ.seuil_neb) THEN
@@ -1037,4 +964,35 @@
                     zrain= 0.0
                 ELSE
+
+                    IF (ok_debug_autoconversion) THEN ! if condition to be removed after test phase
+
+                    ! water quantity to remove: zchau (Sundqvist, 1978)
+                    ! same thing for the ice: zfroi (Zender & Kiehl, 1997)
+                    IF (ptconv(i,k)) THEN ! if convective point
+                        zcl=cld_lc_con
+                        zct=1./cld_tau_con
+                        zfroi = dtime/REAL(ninter)/zdz(i)*zoliqi(i)*velo(i,k)
+                    ELSE
+                        zcl=cld_lc_lsc
+                        zct=1./cld_tau_lsc
+                        zfroi = dtime/REAL(ninter)/zdz(i)*zoliqi(i) &   ! dqice/dt=1/rho*d(rho*wice*qice)/dz
+                            *velo(i,k)
+                    ENDIF
+
+                    ! if vertical heterogeneity is taken into account, we use
+                    ! the "true" volume fraction instead of a modified 
+                    ! surface fraction (which is larger and artificially
+                    ! reduces the in-cloud water).
+
+                    IF ((iflag_cloudth_vert.GE.3).AND.(iflag_rain_incloud_vol.EQ.1)) THEN
+                        zchau = zct   *dtime/REAL(ninter) * zoliql(i) &
+                        *(1.0-EXP(-(zoliql(i)/ctot_vol(i,k)/zcl)**2))
+                    ELSE
+                        zchau = zct   *dtime/REAL(ninter) * zoliql(i) &
+                        *(1.0-EXP(-(zoliql(i)/zneb(i)/zcl)**2))        ! dqliq/dt=-qliq/tau*(1-exp(-qcin/clw)**2)
+                    ENDIF
+
+                    ELSE ! with old bug in autoconversion 
+
                     ! water quantity to remove: zchau (Sundqvist, 1978)
                     ! same thing for the ice: zfroi (Zender & Kiehl, 1997)
@@ -1055,4 +1013,5 @@
                     ! reduces the in-cloud water).
 
+
                     IF ((iflag_cloudth_vert.GE.3).AND.(iflag_rain_incloud_vol.EQ.1)) THEN
                         zchau = zct   *dtime/REAL(ninter) * zoliq(i) &
@@ -1063,18 +1022,22 @@
                     ENDIF
 
-                    zrain   = MIN(MAX(zchau,0.0),zoliq(i)*(1.-zfice(i)))
-                    zsnow   = MIN(MAX(zfroi,0.0),zoliq(i)*zfice(i)) 
+                    ENDIF ! ok_debug_autoconversion
+
+                    zrain   = MIN(MAX(zchau,0.0),zoliql(i))
+                    zsnow   = MIN(MAX(zfroi,0.0),zoliqi(i)) 
                     zprecip = MAX(zrain + zsnow,0.0)
 
                 ENDIF
-            
+
                 zoliql(i) = MAX(zoliq(i)*(1.-zfice(i))-1.*zrain  , 0.0)
                 zoliqi(i) = MAX(zoliq(i)*zfice(i)-1.*zsnow  , 0.0)
                 zoliq(i)  = MAX(zoliq(i)-zprecip , 0.0)
 
-                radliq(i,k) = radliq(i,k) + zoliq(i)/REAL(ninter+1)
-                radliql(i,k) = radliql(i,k) + zoliql(i)/REAL(ninter+1)
-                radliqi(i,k) = radliqi(i,k) + zoliqi(i)/REAL(ninter+1)
-           
+                ! c_iso: call isotope_conversion (for readibility) or duplicate 
+
+                radocond(i,k) = radocond(i,k) + zoliq(i)/REAL(ninter+1)
+                radocondl(i,k) = radocondl(i,k) + zoliql(i)/REAL(ninter+1)
+                radocondi(i,k) = radocondi(i,k) + zoliqi(i)/REAL(ninter+1)
+
             ENDIF ! rneb >0
 
@@ -1083,15 +1046,15 @@
     ENDDO      ! n = 1,niter
 
-    
-
     ! Precipitation flux calculation
 
     DO i = 1, klon
-
-
-            ziflprev(i)=zifl(i)
+            
+            IF (iflag_evap_prec.EQ.4) THEN
+                ziflprev(i)=ziflcld(i)
+            ELSE
+                ziflprev(i)=zifl(i)*zneb(i)
+            ENDIF
 
             IF (rneb(i,k) .GT. 0.0) THEN
-                
 
                ! CR&JYG: We account for the Wegener-Findeisen-Bergeron process in the precipitation flux:
@@ -1126,51 +1089,50 @@
                     ! iced water budget
                     zqpreci(i) = max (zqpreci(i) - Deltaqprecl - Deltaq, 0.)
-           
-                IF (iflag_evap_prec.EQ.4) THEN                                                            
-                    zrflcld(i) = zrflcld(i)+zqprecl(i) &                                                   
-                    *(paprs(i,k)-paprs(i,k+1))/(RG*dtime)                                                
-                    ziflcld(i) = ziflcld(i)+ zqpreci(i) &                                                  
-                        *(paprs(i,k)-paprs(i,k+1))/(RG*dtime)                                            
-                    znebprecipcld(i) = rneb(i,k)                                                          
-                    zrfl(i) = zrflcld(i) + zrflclr(i)                                                      
-                    zifl(i) = ziflcld(i) + ziflclr(i)                                                    
-                ELSE                                 
+
+                    ! c_iso : mv here condensation of isotopes + redispatchage en precip 
+
+                IF (iflag_evap_prec.EQ.4) THEN
+                    zrflcld(i) = zrflcld(i)+zqprecl(i) &
+                    *(paprs(i,k)-paprs(i,k+1))/(RG*dtime)
+                    ziflcld(i) = ziflcld(i)+ zqpreci(i) &
+                        *(paprs(i,k)-paprs(i,k+1))/(RG*dtime)
+                    znebprecipcld(i) = rneb(i,k)
+                    zrfl(i) = zrflcld(i) + zrflclr(i)
+                    zifl(i) = ziflcld(i) + ziflclr(i)
+                ELSE
                     zrfl(i) = zrfl(i)+ zqprecl(i)        &
                     *(paprs(i,k)-paprs(i,k+1))/(RG*dtime) 
                     zifl(i) = zifl(i)+ zqpreci(i)        &
-                   *(paprs(i,k)-paprs(i,k+1))/(RG*dtime)  
-                ENDIF
+                   *(paprs(i,k)-paprs(i,k+1))/(RG*dtime)
+                ENDIF
+                ! c_iso : same for isotopes
  
            ENDIF ! rneb>0
 
-
    ENDDO
 
-
-
-
-    ! LTP: limit of surface cloud fraction covered by precipitation when the local intensity of the flux is below rain_int_min                                                                              
+    ! LTP: limit of surface cloud fraction covered by precipitation when the local intensity of the flux is below rain_int_min
     ! if iflag_evap_pre=4
-    IF (iflag_evap_prec.EQ.4) THEN  
-
-        DO i=1,klon                                        
-                
-            IF ((zrflclr(i) + ziflclr(i)) .GT. 0. ) THEN     
+    IF (iflag_evap_prec.EQ.4) THEN
+
+        DO i=1,klon
+
+            IF ((zrflclr(i) + ziflclr(i)) .GT. 0. ) THEN
                 znebprecipclr(i) = min(znebprecipclr(i),max(zrflclr(i)/ &
                 (MAX(znebprecipclr(i),seuil_neb)*rain_int_min), ziflclr(i)/(MAX(znebprecipclr(i),seuil_neb)*rain_int_min)))
             ELSE
-                znebprecipclr(i)=0.                                                                   
-            ENDIF  
-                                                                                                         
-            IF ((zrflcld(i) + ziflcld(i)) .GT. 0.) THEN                                                  
+                znebprecipclr(i)=0.0
+            ENDIF
+
+            IF ((zrflcld(i) + ziflcld(i)) .GT. 0.) THEN
                 znebprecipcld(i) = min(znebprecipcld(i), max(zrflcld(i)/ &
                 (MAX(znebprecipcld(i),seuil_neb)*rain_int_min), ziflcld(i)/(MAX(znebprecipcld(i),seuil_neb)*rain_int_min)))
-            ELSE                                                                                     
-                znebprecipcld(i)=0.                                                                    
-            ENDIF     
-
-        ENDDO       
-
-    ENDIF  
+            ELSE
+                znebprecipcld(i)=0.0
+            ENDIF
+
+        ENDDO
+
+    ENDIF
 
     ! End of precipitation formation
@@ -1186,16 +1148,16 @@
         d_qi(i,k) = zfice(i)*zoliq(i)
         d_q(i,k) = zq(i) - q(i,k)
+        ! c_iso: same for isotopes
         d_t(i,k) = zt(i) - t(i,k)
     ENDDO
 
     ! Calculation of the concentration of condensates seen by the radiation scheme
-    ! for liquid phase, we take radliql
-    ! for ice phase, we take radliqi if we neglect snowfall, otherwise (ok_radliq_snow=true) 
-    ! we recaulate radliqi to account for contributions from the precipitation flux
-
-
-    IF ((ok_radliq_snow) .AND. (k .LT. klev)) THEN
+    ! for liquid phase, we take radocondl
+    ! for ice phase, we take radocondi if we neglect snowfall, otherwise (ok_radocond_snow=true) 
+    ! we recaulate radocondi to account for contributions from the precipitation flux
+
+    IF ((ok_radocond_snow) .AND. (k .LT. klev)) THEN
         ! for the solid phase (crystals + snowflakes)
-        ! we recalculate radliqi by summing
+        ! we recalculate radocondi by summing
         ! the ice content calculated in the mesh
         ! + the contribution of the non-evaporated snowfall 
@@ -1203,25 +1165,22 @@
         DO i=1,klon
            IF (ziflprev(i) .NE. 0.0) THEN
-              radliqi(i,k)=zoliq(i)*zfice(i)+zqpreci(i)+ziflprev(i)/zrho(i,k+1)/velo(i,k+1)
+              radocondi(i,k)=zoliq(i)*zfice(i)+zqpreci(i)+ziflprev(i)/zrho(i,k+1)/velo(i,k+1)
            ELSE
-              radliqi(i,k)=zoliq(i)*zfice(i)+zqpreci(i)  
+              radocondi(i,k)=zoliq(i)*zfice(i)+zqpreci(i)
            ENDIF
-           radliq(i,k)=radliql(i,k)+radliqi(i,k)
+           radocond(i,k)=radocondl(i,k)+radocondi(i,k)
         ENDDO
     ENDIF
 
-    ! caculate the percentage of ice in "radliq" so cloud+precip seen by the radiation scheme
+    ! caculate the percentage of ice in "radocond" so cloud+precip seen by the radiation scheme
     DO i=1,klon
-        IF (radliq(i,k) .GT. 0.) THEN
-            radicefrac(i,k)=MIN(MAX(radliqi(i,k)/radliq(i,k),0.),1.)
+        IF (radocond(i,k) .GT. 0.) THEN
+            radicefrac(i,k)=MIN(MAX(radocondi(i,k)/radocond(i,k),0.),1.)
         ENDIF
     ENDDO
-
-
 
     ! ----------------------------------------------------------------
     ! P4> Wet scavenging
     ! ----------------------------------------------------------------
-
 
     !Scavenging through nucleation in the layer
@@ -1246,16 +1205,13 @@
 
             zfrac_lessi = 1. - EXP(zalpha_tr*zprec_cond(i)/zneb(i))
-            pfrac_nucl(i,k)=pfrac_nucl(i,k)*(1.-zneb(i)*zfrac_lessi)
             frac_nucl(i,k)= 1.-zneb(i)*zfrac_lessi 
-    
+
             ! Nucleation with a factor of -1 instead of -0.5
             zfrac_lessi = 1. - EXP(-zprec_cond(i)/zneb(i))
-            pfrac_1nucl(i,k)=pfrac_1nucl(i,k)*(1.-zneb(i)*zfrac_lessi)
 
         ENDIF
-        
-    ENDDO      
-
-     
+
+    ENDDO
+
     ! Scavenging through impaction in the underlying layer
 
@@ -1273,5 +1229,4 @@
 
               zfrac_lessi = 1. - EXP(zalpha_tr*zprec_cond(i)/zneb(i))
-              pfrac_impa(i,kk)=pfrac_impa(i,kk)*(1.-zneb(i)*zfrac_lessi)
               frac_impa(i,kk)= 1.-zneb(i)*zfrac_lessi
 
@@ -1281,5 +1236,5 @@
 
     ENDDO
-     
+
     !--save some variables for ice supersaturation
     !
@@ -1294,10 +1249,10 @@
         qclr(i,k) = MAX(1.e-10,zq(i) - qvc(i,k) - qss(i,k))  !--added by OB because of pathologic cases with the lognormal
         qcld(i,k) = qvc(i,k) + zcond(i)
-   END DO
+   ENDDO
    !q_sat
-   CALL CALC_QSAT_ECMWF(klon,Tbef(:),qzero(:),pplay(:,k),RTT,1,.false.,zqsatl(:,k),zdqs(:))
-   CALL CALC_QSAT_ECMWF(klon,Tbef(:),qzero(:),pplay(:,k),RTT,2,.false.,zqsats(:,k),zdqs(:))     
-
-END DO
+   CALL calc_qsat_ecmwf(klon,Tbef(:),qzero(:),pplay(:,k),RTT,1,.false.,qsatl(:,k),zdqs(:))
+   CALL calc_qsat_ecmwf(klon,Tbef(:),qzero(:),pplay(:,k),RTT,2,.false.,qsats(:,k),zdqs(:))
+
+ENDDO
 
 !======================================================================
@@ -1309,4 +1264,5 @@
       snow(i) = zifl(i)
       rain(i) = zrfl(i)
+      ! c_iso final output
   ENDDO
 
@@ -1315,6 +1271,6 @@
   ENDIF
 
-END SUBROUTINE LSCP
+END SUBROUTINE lscp
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
-END MODULE LSCP_MOD
+END MODULE lscp_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/nuage.h
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/nuage.h	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/nuage.h	(revision 4482)
@@ -12,6 +12,6 @@
       INTEGER iflag_rain_incloud_vol
    
-      INTEGER iflag_mpc_bl, iflag_gammasat, iflag_vice, iflag_rei
-      LOGICAL ok_icefra_lscp, ok_radliq_snow
+      INTEGER iflag_gammasat, iflag_vice, iflag_rei
+      LOGICAL ok_icefra_lscp
 
       common /nuagecom/ rad_froid,rad_chau1, rad_chau2,t_glace_max,     &
@@ -21,6 +21,6 @@
      &                  iflag_t_glace,iflag_cloudth_vert,iflag_cld_cv,  &
      &                  iflag_rain_incloud_vol,                         &
-     &                  ok_icefra_lscp,ok_radliq_snow,                  &
-     &                  iflag_mpc_bl, iflag_gammasat, iflag_vice,       &
+     &                  ok_icefra_lscp,                  &
+     &                  iflag_gammasat, iflag_vice,       &
      &                  iflag_rei    
 !$OMP THREADPRIVATE(/nuagecom/)
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/oasis.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/oasis.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/oasis.F90	(revision 4482)
@@ -24,4 +24,7 @@
   USE mod_prism_get_proto
   USE mod_prism_put_proto
+#endif
+#ifdef CPP_CPLOCNINCA
+  USE incaoasis, ONLY : inforcv
 #endif
 #endif
@@ -59,7 +62,8 @@
   INTEGER, PARAMETER :: ids_qraiic = 28
   INTEGER, PARAMETER :: ids_qsnoic = 29
-  INTEGER, PARAMETER :: ids_delta_sst = 30, ids_delta_sal = 31
-  
-  INTEGER, PARAMETER :: maxsend    = 31  ! Maximum number of fields to send
+  INTEGER, PARAMETER :: ids_delta_sst = 30, ids_delta_sal = 31, ids_dter = 32, &
+       ids_dser = 33, ids_dt_ds = 34
+  
+  INTEGER, PARAMETER :: maxsend    = 34  ! Maximum number of fields to send
   
   ! Id for fields received from ocean
@@ -79,4 +83,8 @@
   INTEGER, PARAMETER :: maxrecv    = 9  ! Maximum number of fields to receive
   
+#ifdef CPP_CPLOCNINCA
+  INTEGER, PARAMETER :: idr_ocedms = 1
+  INTEGER, PARAMETER :: maxrcv = 1
+#endif
 
   TYPE, PUBLIC ::   FLD_CPL            ! Type for coupling field information
@@ -194,4 +202,10 @@
        infosend(ids_delta_sal)%action = .TRUE.
        infosend(ids_delta_sal)%name = 'CODELSSS'
+       infosend(ids_dter)%action = .TRUE.
+       infosend(ids_dter)%name = 'CODELTER'
+       infosend(ids_dser)%action = .TRUE.
+       infosend(ids_dser)%name = 'CODELSER'
+       infosend(ids_dt_ds)%action = .TRUE.
+       infosend(ids_dt_ds)%name = 'CODTDS'
     end if
            
@@ -247,4 +261,7 @@
        inforecv(idr_oceco2)%action = .TRUE. ; inforecv(idr_oceco2)%name = 'SICO2FLX'
    ENDIF
+#ifdef CPP_CPLOCNINCA
+       inforcv(idr_ocedms)%action = .TRUE. ; inforcv(idr_ocedms)%name = 'SIDMSFLX'
+#endif
 
 !************************************************************************************
@@ -331,5 +348,22 @@
        ENDIF
     END DO
-    
+
+! Now, if also coupling CPL with INCA, initialize here fields to be exchanged.
+#ifdef CPP_CPLOCNINCA
+    DO jf=1,maxrcv 
+       IF (inforcv(jf)%action) THEN
+          CALL prism_def_var_proto(inforcv(jf)%nid, inforcv(jf)%name, il_part_id, &
+               il_var_nodims, PRISM_In, il_var_actual_shape, il_var_type, &
+               ierror)
+          IF (ierror .NE. PRISM_Ok) THEN
+             WRITE(lunout,*) 'inicma : Problem with prism_def_var_proto for field : ',&
+                  inforcv(jf)%name
+             abort_message=' Problem in call to prism_def_var_proto for fields to receive'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+    END DO
+#endif
+ 
 !************************************************************************************
 ! Atmospheric Fields to send
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ocean_cpl_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ocean_cpl_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ocean_cpl_mod.F90	(revision 4482)
@@ -56,5 +56,5 @@
        qsurf, evap, fluxsens, fluxlat, flux_u1, flux_v1, &
        tsurf_new, dflux_s, dflux_l, sens_prec_liq, sss, delta_sal, rhoa, &
-       delta_sst)
+       delta_sst, dTer, dSer, dt_ds)
 
 !
@@ -103,4 +103,16 @@
     ! only if activate_ocean_skin >= 1.
 
+    REAL, intent(in):: dter(:) ! (knon)
+    ! Temperature variation in the diffusive microlayer, that is
+    ! ocean-air interface temperature minus subskin temperature. In
+    ! K.
+
+    REAL, intent(in):: dser(:) ! (knon)
+    ! Salinity variation in the diffusive microlayer, that is
+    ! ocean-air interface salinity minus subskin salinity. In ppt.
+
+    real, intent(in):: dt_ds(:) ! (knon)
+    ! (tks / tkt) * dTer, in K
+
 ! In/Output arguments
 !****************************************************************************************
@@ -219,5 +231,5 @@
          fluxsens, precip_rain, precip_snow, evap, tsurf_new, fder_new, alb1, &
          flux_u1, flux_v1, windsp, sens_prec_liq, sens_prec_sol, lat_prec_liq, &
-         lat_prec_sol, delta_sst, delta_sal)
+         lat_prec_sol, delta_sst, delta_sal, dTer, dSer, dt_ds)
 
   END SUBROUTINE ocean_cpl_noice
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/pbl_surface_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/pbl_surface_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/pbl_surface_mod.F90	(revision 4482)
@@ -14,5 +14,5 @@
   USE mod_grid_phy_lmdz,   ONLY : klon_glo
   USE ioipsl
-  USE surface_data,        ONLY : type_ocean, ok_veget
+  USE surface_data,        ONLY : type_ocean, ok_veget, landice_opt
   USE surf_land_mod,       ONLY : surf_land
   USE surf_landice_mod,    ONLY : surf_landice
@@ -23,4 +23,5 @@
   USE climb_wind_mod,      ONLY : climb_wind_down, climb_wind_up
   USE coef_diff_turb_mod,  ONLY : coef_diff_turb
+  USE atke_exchange_coeff_mod, ONLY :  atke_compute_km_kh
   USE ioipsl_getin_p_mod,  ONLY : getin_p
   USE cdrag_mod
@@ -313,6 +314,7 @@
     USE print_control_mod,  ONLY : prt_level,lunout
     USE ioipsl_getin_p_mod, ONLY : getin_p
-    use phys_state_var_mod, only: ds_ns, dt_ns, delta_sst, delta_sal, zsig, zmea
-    use phys_output_var_mod, only: dter, dser, tkt, tks, taur, sss
+    use phys_state_var_mod, only: ds_ns, dt_ns, delta_sst, delta_sal, dter, &
+         dser, dt_ds, zsig, zmea
+    use phys_output_var_mod, only: tkt, tks, taur, sss
 #ifdef CPP_XIOS
     USE wxios, ONLY: missing_val
@@ -874,9 +876,10 @@
     REAL, DIMENSION(klon)              :: yrmu0
     ! Martin
-
-    REAL, DIMENSION(klon):: ydelta_sst, ydelta_sal, yds_ns, ydt_ns, ydter, ydser, &
-         ytkt, ytks, ytaur, ysss
-    ! compression of delta_sst, delta_sal, ds_ns, dt_ns, dter, dser, tkt, tks,
-    ! taur, sss on ocean points
+    REAL, DIMENSIOn(klon)              :: yri0
+
+    REAL, DIMENSION(klon):: ydelta_sst, ydelta_sal, yds_ns, ydt_ns, ydter, &
+         ydser, ydt_ds, ytkt, ytks, ytaur, ysss
+    ! compression of delta_sst, delta_sal, ds_ns, dt_ns, dter, dser,
+    ! dt_ds, tkt, tks, taur, sss on ocean points
 
 !****************************************************************************************
@@ -1058,4 +1061,5 @@
 
     ytke=0.
+    yri0(:)=0.
 !FC 
     y_treedrg=0.
@@ -1533,4 +1537,7 @@
              ydelta_sal(:knon) = delta_sal(ni(:knon))
              ydelta_sst(:knon) = delta_sst(ni(:knon))
+             ydter(:knon) = dter(ni(:knon))
+             ydser(:knon) = dser(ni(:knon))
+             ydt_ds(:knon) = dt_ds(ni(:knon))
           end if
           
@@ -1564,5 +1571,5 @@
         CALL cdrag(knon, nsrf, &
             speed, yt(:,1), yq(:,1), zgeo1, ypaprs(:,1),&
-            yts, yqsurf, yz0m, yz0h, &
+            yts, yqsurf, yz0m, yz0h, yri0, 0, &
             ycdragm, ycdragh, zri1, pref )
 
@@ -1598,5 +1605,5 @@
             CALL cdrag(knon, nsrf, &
             speed_x, yt_x(:,1), yq_x(:,1), zgeo1_x, ypaprs(:,1),&
-            yts_x, yqsurf_x, yz0m, yz0h, &
+            yts_x, yqsurf_x, yz0m, yz0h, yri0, 0, &
             ycdragm_x, ycdragh_x, zri1_x, pref_x )
 
@@ -1625,5 +1632,5 @@
         CALL cdrag(knon, nsrf, &
             speed_w, yt_w(:,1), yq_w(:,1), zgeo1_w, ypaprs(:,1),&
-            yts_w, yqsurf_w, yz0m, yz0h, &
+            yts_w, yqsurf_w, yz0m, yz0h, yri0, 0, &
             ycdragm_w, ycdragh_w, zri1_w, pref_w )
 !
@@ -1652,5 +1659,4 @@
 !!! jyg le 07/02/2012
        IF (iflag_split .eq.0) THEN
-!!!
 !!! nrlmd & jyg les 02/05/2011, 13/06/2011, 05/02/2012
       IF (prt_level >=10) THEN
@@ -1665,6 +1671,13 @@
       print *,' args coef_diff_turb: ycdragh ', ycdragh
       print *,' args coef_diff_turb: ytke ', ytke
-
        ENDIF
+
+        IF (iflag_pbl>=50) THEN
+
+        CALL atke_compute_km_kh(knon,klev,yu,yv,yt, &
+             ypplay,ypaprs,ytke,ycoefm, ycoefh)
+
+        ELSE
+
         CALL coef_diff_turb(dtime, nsrf, knon, ni,  &
             ypaprs, ypplay, yu, yv, yq, yt, yts, yqsurf, ycdragm, &
@@ -1682,7 +1695,13 @@
        ENDDO
        ENDIF
+
+       ENDIF ! iflag_pbl >= 50
+
         IF (prt_level >=10) print *,'coef_diff_turb -> ycoefh ',ycoefh
-!
+
+
        ELSE  !(iflag_split .eq.0)
+
+      
       IF (prt_level >=10) THEN
       print *,' args coef_diff_turb: yu_x ',  yu_x  
@@ -1695,6 +1714,14 @@
       print *,' args coef_diff_turb: ycdragh_x ', ycdragh_x
       print *,' args coef_diff_turb: ytke_x ', ytke_x
-
-       ENDIF
+      ENDIF
+
+
+        IF (iflag_pbl>=50) THEN
+     
+        CALL atke_compute_km_kh(knon,klev,yu_x,yv_x,yt_x, &
+             ypplay,ypaprs,ytke_x,ycoefm_x, ycoefh_x)
+
+        ELSE
+
         CALL coef_diff_turb(dtime, nsrf, knon, ni,  &
             ypaprs, ypplay, yu_x, yv_x, yq_x, yt_x, yts_x, yqsurf_x, ycdragm_x, &
@@ -1712,4 +1739,7 @@
        ENDDO
        ENDIF
+
+        ENDIF ! iflag_pbl >= 50
+
         IF (prt_level >=10) print *,'coef_diff_turb -> ycoefh_x ',ycoefh_x
 !
@@ -1724,5 +1754,13 @@
       print *,' args coef_diff_turb: ycdragh_w ', ycdragh_w
       print *,' args coef_diff_turb: ytke_w ', ytke_w
-       ENDIF
+      ENDIF
+      
+        IF (iflag_pbl>=50) THEN
+        
+        CALL atke_compute_km_kh(knon,klev,yu_w,yv_w,yt_w, &
+             ypplay,ypaprs,ytke_w,ycoefm_w, ycoefh_w)
+
+        ELSE
+
         CALL coef_diff_turb(dtime, nsrf, knon, ni,  &
             ypaprs, ypplay, yu_w, yv_w, yq_w, yt_w, yts_w, yqsurf_w, ycdragm_w, &
@@ -1739,6 +1777,10 @@
        ENDDO
        ENDIF
+
+       ENDIF ! iflag_pbl >= 50
+
+
         IF (prt_level >=10) print *,'coef_diff_turb -> ycoefh_w ',ycoefh_w
-!
+
 !!!jyg le 10/04/2013
 !!   En attendant de traiter le transport des traceurs dans les poches froides, formule
@@ -1750,7 +1792,8 @@
         ENDDO
       ENDDO
-!!!
+
+
        ENDIF  ! (iflag_split .eq.0)
-!!!
+
        
 !****************************************************************************************
@@ -2056,41 +2099,46 @@
        CASE(is_lic)
           ! Martin
-          CALL surf_landice(itap, dtime, knon, ni, &
-               rlon, rlat, debut, lafin, &
-               yrmu0, ylwdown, yalb, zgeo1, &
-               ysolsw, ysollw, yts, ypplay(:,1), &
-!!jyg               ycdragh, ycdragm, yrain_f, ysnow_f, yt(:,1), yq(:,1),&
-               ycdragh, ycdragm, yrain_f, ysnow_f, yt1, yq1,&
-               AcoefH, AcoefQ, BcoefH, BcoefQ, &
-               AcoefU, AcoefV, BcoefU, BcoefV, &
-               ypsref, yu1, yv1, ygustiness, yrugoro, pctsrf, &
-               ysnow, yqsurf, yqsol, yagesno, &
-               ytsoil, yz0m, yz0h, SFRWL, yalb_dir_new, yalb_dif_new, yevap,yfluxsens,yfluxlat, &
-               ytsurf_new, y_dflux_t, y_dflux_q, &
-               yzmea, yzsig, ycldt, &
-               ysnowhgt, yqsnow, ytoice, ysissnow, &
-               yalb3_new, yrunoff, &
-               y_flux_u1, y_flux_v1)
-
-!jyg<
-!!          alb3_lic(:)=0.
-!>jyg
-          DO j = 1, knon
-             i = ni(j)
-             alb3_lic(i) = yalb3_new(j)
-             snowhgt(i)   = ysnowhgt(j)
-             qsnow(i)     = yqsnow(j)
-             to_ice(i)    = ytoice(j)
-             sissnow(i)   = ysissnow(j)
-             runoff(i)    = yrunoff(j)
-          ENDDO
-          ! Martin
-! Special DICE MPL 05082013 puis BOMEX MPL 20150410
-       IF (ok_prescr_ust) THEN
-          DO j=1,knon
-          y_flux_u1(j)=ycdragm(j)*(1.+sqrt(yu(j,1)*yu(j,1)+yv(j,1)*yv(j,1)))*yu(j,1)*ypplay(j,1)/RD/yt(j,1)
-          y_flux_v1(j)=ycdragm(j)*(1.+sqrt(yu(j,1)*yu(j,1)+yv(j,1)*yv(j,1)))*yv(j,1)*ypplay(j,1)/RD/yt(j,1)
-          ENDDO
-      ENDIF
+
+          IF (landice_opt .LT. 2) THEN
+             ! Land ice is treated by LMDZ and not by ORCHIDEE
+             CALL surf_landice(itap, dtime, knon, ni, &
+                  rlon, rlat, debut, lafin, &
+                  yrmu0, ylwdown, yalb, zgeo1, &
+                  ysolsw, ysollw, yts, ypplay(:,1), &
+                  !!jyg               ycdragh, ycdragm, yrain_f, ysnow_f, yt(:,1), yq(:,1),&
+                  ycdragh, ycdragm, yrain_f, ysnow_f, yt1, yq1,&
+                  AcoefH, AcoefQ, BcoefH, BcoefQ, &
+                  AcoefU, AcoefV, BcoefU, BcoefV, &
+                  ypsref, yu1, yv1, ygustiness, yrugoro, pctsrf, &
+                  ysnow, yqsurf, yqsol, yagesno, &
+                  ytsoil, yz0m, yz0h, SFRWL, yalb_dir_new, yalb_dif_new, yevap,yfluxsens,yfluxlat, &
+                  ytsurf_new, y_dflux_t, y_dflux_q, &
+                  yzmea, yzsig, ycldt, &
+                  ysnowhgt, yqsnow, ytoice, ysissnow, &
+                  yalb3_new, yrunoff, &
+                  y_flux_u1, y_flux_v1)
+             
+             !jyg<
+             !!          alb3_lic(:)=0.
+             !>jyg
+             DO j = 1, knon
+                i = ni(j)
+                alb3_lic(i) = yalb3_new(j)
+                snowhgt(i)   = ysnowhgt(j)
+                qsnow(i)     = yqsnow(j)
+                to_ice(i)    = ytoice(j)
+                sissnow(i)   = ysissnow(j)
+                runoff(i)    = yrunoff(j)
+             ENDDO
+             ! Martin
+             ! Special DICE MPL 05082013 puis BOMEX MPL 20150410
+             IF (ok_prescr_ust) THEN
+                DO j=1,knon
+                   y_flux_u1(j)=ycdragm(j)*(1.+sqrt(yu(j,1)*yu(j,1)+yv(j,1)*yv(j,1)))*yu(j,1)*ypplay(j,1)/RD/yt(j,1)
+                   y_flux_v1(j)=ycdragm(j)*(1.+sqrt(yu(j,1)*yu(j,1)+yv(j,1)*yv(j,1)))*yv(j,1)*ypplay(j,1)/RD/yt(j,1)
+                ENDDO
+             ENDIF
+             
+          END IF
           
        CASE(is_oce)
@@ -2108,5 +2156,5 @@
                y_flux_u1, y_flux_v1, ydelta_sst(:knon), ydelta_sal(:knon), &
                yds_ns(:knon), ydt_ns(:knon), ydter(:knon), ydser(:knon), &
-               ytkt(:knon), ytks(:knon), ytaur(:knon), ysss)
+               ydt_ds(:knon), ytkt(:knon), ytks(:knon), ytaur(:knon), ysss)
       IF (prt_level >=10) THEN
           print *,'arg de surf_ocean: ycdragh ',ycdragh
@@ -2855,4 +2903,9 @@
           taur(ni(:knon)) = ytaur(:knon)
           sss(ni(:knon)) = ysss(:knon)
+
+          if (activate_ocean_skin == 2 .and. type_ocean == "couple") then
+             dt_ds = missing_val
+             dt_ds(ni(:knon)) = ydt_ds(:knon)
+          end if
        end if
 
@@ -3522,5 +3575,6 @@
 
     USE indice_sol_mod
-    use phys_state_var_mod, only: delta_sal, ds_ns, dt_ns, delta_sst
+    use phys_state_var_mod, only: delta_sal, ds_ns, dt_ns, delta_sst, dter, &
+         dser, dt_ds
     use config_ocean_skin_m, only: activate_ocean_skin
 
@@ -3615,4 +3669,7 @@
                          delta_sal(i) = 0.
                          delta_sst(i) = 0.
+                         dter(i) = 0.
+                         dser(i) = 0.
+                         dt_ds(i) = 0.
                       end if
                       
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyaqua_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyaqua_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyaqua_mod.F90	(revision 4482)
@@ -135,6 +135,5 @@
     if (year_len.ne.360) then
       write (*,*) year_len
-      write (*,*) 'iniaqua: 360 day calendar is required !'
-      stop
+      call abort_physic("iniaqua", 'iniaqua: 360 day calendar is required !', 1)
     endif
 
@@ -573,4 +572,5 @@
     USE mod_phys_lmdz_transfert_para, ONLY: gather
     USE phys_cal_mod, ONLY: year_len
+    use netcdf, only: nf90_def_var, nf90_double, nf90_float
     IMPLICIT NONE
     include "netcdf.inc"
@@ -617,14 +617,14 @@
 
 #ifdef NC_DOUBLE
-      ierr = nf_def_var(nid, 'TEMPS', nf_double, 1, ntim, id_tim)
-#else
-      ierr = nf_def_var(nid, 'TEMPS', nf_float, 1, ntim, id_tim)
+      ierr = nf90_def_var(nid, 'TEMPS', nf90_double, [ntim], id_tim)
+#else
+      ierr = nf90_def_var(nid, 'TEMPS', nf90_float, [ntim], id_tim)
 #endif
       ierr = nf_put_att_text(nid, id_tim, 'title', 17, 'Jour dans l annee')
 
 #ifdef NC_DOUBLE
-      ierr = nf_def_var(nid, 'NAT', nf_double, 2, dims, id_nat)
-#else
-      ierr = nf_def_var(nid, 'NAT', nf_float, 2, dims, id_nat)
+      ierr = nf90_def_var(nid, 'NAT', nf90_double, dims, id_nat)
+#else
+      ierr = nf90_def_var(nid, 'NAT', nf90_float, dims, id_nat)
 #endif
       ierr = nf_put_att_text(nid, id_nat, 'title', 23, &
@@ -632,7 +632,7 @@
 
 #ifdef NC_DOUBLE
-      ierr = nf_def_var(nid, 'SST', nf_double, 2, dims, id_sst)
-#else
-      ierr = nf_def_var(nid, 'SST', nf_float, 2, dims, id_sst)
+      ierr = nf90_def_var(nid, 'SST', nf90_double, dims, id_sst)
+#else
+      ierr = nf90_def_var(nid, 'SST', nf90_float, dims, id_sst)
 #endif
       ierr = nf_put_att_text(nid, id_sst, 'title', 35, &
@@ -640,7 +640,7 @@
 
 #ifdef NC_DOUBLE
-      ierr = nf_def_var(nid, 'BILS', nf_double, 2, dims, id_bils)
-#else
-      ierr = nf_def_var(nid, 'BILS', nf_float, 2, dims, id_bils)
+      ierr = nf90_def_var(nid, 'BILS', nf90_double, dims, id_bils)
+#else
+      ierr = nf90_def_var(nid, 'BILS', nf90_float, dims, id_bils)
 #endif
       ierr = nf_put_att_text(nid, id_bils, 'title', 32, &
@@ -648,39 +648,39 @@
 
 #ifdef NC_DOUBLE
-      ierr = nf_def_var(nid, 'ALB', nf_double, 2, dims, id_alb)
-#else
-      ierr = nf_def_var(nid, 'ALB', nf_float, 2, dims, id_alb)
+      ierr = nf90_def_var(nid, 'ALB', nf90_double, dims, id_alb)
+#else
+      ierr = nf90_def_var(nid, 'ALB', nf90_float, dims, id_alb)
 #endif
       ierr = nf_put_att_text(nid, id_alb, 'title', 19, 'Albedo a la surface')
 
 #ifdef NC_DOUBLE
-      ierr = nf_def_var(nid, 'RUG', nf_double, 2, dims, id_rug)
-#else
-      ierr = nf_def_var(nid, 'RUG', nf_float, 2, dims, id_rug)
+      ierr = nf90_def_var(nid, 'RUG', nf90_double, dims, id_rug)
+#else
+      ierr = nf90_def_var(nid, 'RUG', nf90_float, dims, id_rug)
 #endif
       ierr = nf_put_att_text(nid, id_rug, 'title', 8, 'Rugosite')
 
 #ifdef NC_DOUBLE
-      ierr = nf_def_var(nid, 'FTER', nf_double, 2, dims, id_fter)
-#else
-      ierr = nf_def_var(nid, 'FTER', nf_float, 2, dims, id_fter)
+      ierr = nf90_def_var(nid, 'FTER', nf90_double, dims, id_fter)
+#else
+      ierr = nf90_def_var(nid, 'FTER', nf90_float, dims, id_fter)
 #endif
       ierr = nf_put_att_text(nid, id_fter, 'title',10,'Frac. Land')
 #ifdef NC_DOUBLE
-      ierr = nf_def_var(nid, 'FOCE', nf_double, 2, dims, id_foce)
-#else
-      ierr = nf_def_var(nid, 'FOCE', nf_float, 2, dims, id_foce)
+      ierr = nf90_def_var(nid, 'FOCE', nf90_double, dims, id_foce)
+#else
+      ierr = nf90_def_var(nid, 'FOCE', nf90_float, dims, id_foce)
 #endif
       ierr = nf_put_att_text(nid, id_foce, 'title',11,'Frac. Ocean')
 #ifdef NC_DOUBLE
-      ierr = nf_def_var(nid, 'FSIC', nf_double, 2, dims, id_fsic)
-#else
-      ierr = nf_def_var(nid, 'FSIC', nf_float, 2, dims, id_fsic)
+      ierr = nf90_def_var(nid, 'FSIC', nf90_double, dims, id_fsic)
+#else
+      ierr = nf90_def_var(nid, 'FSIC', nf90_float, dims, id_fsic)
 #endif
       ierr = nf_put_att_text(nid, id_fsic, 'title',13,'Frac. Sea Ice')
 #ifdef NC_DOUBLE
-      ierr = nf_def_var(nid, 'FLIC', nf_double, 2, dims, id_flic)
-#else
-      ierr = nf_def_var(nid, 'FLIC', nf_float, 2, dims, id_flic)
+      ierr = nf90_def_var(nid, 'FLIC', nf90_double, dims, id_flic)
+#else
+      ierr = nf90_def_var(nid, 'FLIC', nf90_float, dims, id_flic)
 #endif
       ierr = nf_put_att_text(nid, id_flic, 'title',14,'Frac. Land Ice')
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyetat0.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyetat0.F90	(revision 4444)
+++ 	(revision )
@@ -1,656 +1,0 @@
-! $Id$
-
-SUBROUTINE phyetat0 (fichnom, clesphy0, tabcntr0)
-
-  USE dimphy, only: klon, zmasq, klev
-  USE iophy, ONLY : init_iophy_new
-  USE ocean_cpl_mod,    ONLY : ocean_cpl_init
-  USE fonte_neige_mod,  ONLY : fonte_neige_init
-  USE pbl_surface_mod,  ONLY : pbl_surface_init
-  USE surface_data,     ONLY : type_ocean, version_ocean
-  USE phys_state_var_mod, ONLY : ancien_ok, clwcon, detr_therm, phys_tstep, &
-       qsol, fevap, z0m, z0h, agesno, &
-       du_gwd_rando, du_gwd_front, entr_therm, f0, fm_therm, &
-       falb_dir, falb_dif, prw_ancien, prlw_ancien, prsw_ancien, &
-       ftsol, pbl_tke, pctsrf, q_ancien, ql_ancien, qs_ancien, rneb_ancien, radpas, radsol, rain_fall, ratqs, &
-       rnebcon, rugoro, sig1, snow_fall, solaire_etat0, sollw, sollwdown, &
-       solsw, solswfdiff, t_ancien, u_ancien, v_ancien, w01, wake_cstar, wake_deltaq, &
-       wake_deltat, wake_delta_pbl_TKE, delta_tsurf, beta_aridity, wake_fip, wake_pe, &
-       wake_s, wake_dens, awake_dens, cv_gen, zgam, zmax0, zmea, zpic, zsig, &
-       zstd, zthe, zval, ale_bl, ale_bl_trig, alp_bl, u10m, v10m, treedrg, &
-       ale_wake, ale_bl_stat, ds_ns, dt_ns, delta_sst, delta_sal, ratqs_inter
-!FC
-  USE geometry_mod,     ONLY: longitude_deg, latitude_deg
-  USE iostart,          ONLY: close_startphy, get_field, get_var, open_startphy
-  USE infotrac_phy,     ONLY: nqtot, nbtr, types_trac, tracers
-  USE traclmdz_mod,     ONLY: traclmdz_from_restart
-  USE carbon_cycle_mod, ONLY: carbon_cycle_tr, carbon_cycle_cpl, co2_send
-  USE indice_sol_mod,   ONLY: nbsrf, is_ter, epsfra, is_lic, is_oce, is_sic
-  USE ocean_slab_mod,   ONLY: nslay, tslab, seaice, tice, ocean_slab_init
-  USE time_phylmdz_mod, ONLY: init_iteration, pdtphys, itau_phy
-#ifdef CPP_XIOS
-  USE wxios, ONLY: missing_val
-#else
-  use netcdf, only: missing_val => nf90_fill_real
-#endif
-  use config_ocean_skin_m, only: activate_ocean_skin
-
-  IMPLICIT none
-  !======================================================================
-  ! Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
-  ! Objet: Lecture de l'etat initial pour la physique
-  !======================================================================
-  include "dimsoil.h"
-  include "clesphys.h"
-  include "alpale.h"
-  include "compbl.h"
-  include "YOMCST.h"
-  !======================================================================
-  CHARACTER*(*) fichnom
-
-  ! les variables globales lues dans le fichier restart
-
-  REAL tsoil(klon, nsoilmx, nbsrf)
-  REAL qsurf(klon, nbsrf)
-  REAL snow(klon, nbsrf)
-  real fder(klon)
-  REAL run_off_lic_0(klon)
-  REAL fractint(klon)
-  REAL trs(klon, nbtr)
-  REAL zts(klon)
-  ! pour drag arbres FC
-  REAL drg_ter(klon,klev)
-
-  CHARACTER*6 ocean_in
-  LOGICAL ok_veget_in
-
-  INTEGER        longcles
-  PARAMETER    ( longcles = 20 )
-  REAL clesphy0( longcles )
-
-  REAL xmin, xmax
-
-  INTEGER nid, nvarid
-  INTEGER ierr, i, nsrf, isoil , k
-  INTEGER length
-  PARAMETER (length=100)
-  INTEGER it, iq, isw
-  REAL tab_cntrl(length), tabcntr0(length)
-  CHARACTER*7 str7
-  CHARACTER*2 str2
-  LOGICAL :: found,phyetat0_get,phyetat0_srf
-  REAL :: lon_startphy(klon), lat_startphy(klon)
-
-  ! FH1D
-  !     real iolat(jjm+1)
-  !real iolat(jjm+1-1/(iim*jjm))
-
-  ! Ouvrir le fichier contenant l'etat initial:
-
-  CALL open_startphy(fichnom)
-
-  ! Lecture des parametres de controle:
-
-  CALL get_var("controle", tab_cntrl)
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-  ! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
-  ! Les constantes de la physiques sont lues dans la physique seulement.
-  ! Les egalites du type
-  !             tab_cntrl( 5 )=clesphy0(1)
-  ! sont remplacees par
-  !             clesphy0(1)=tab_cntrl( 5 )
-  ! On inverse aussi la logique.
-  ! On remplit les tab_cntrl avec les parametres lus dans les .def
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  DO i = 1, length
-     tabcntr0( i ) = tab_cntrl( i )
-  ENDDO
-
-  tab_cntrl(1)=pdtphys
-  tab_cntrl(2)=radpas
-
-  ! co2_ppm : value from the previous time step
-  IF (carbon_cycle_tr .OR. carbon_cycle_cpl) THEN
-     co2_ppm = tab_cntrl(3)
-     RCO2    = co2_ppm * 1.0e-06 * RMCO2 / RMD
-     ! ELSE : keep value from .def
-  ENDIF
-
-! co2_ppm0 : initial value of atmospheric CO2 (from create_etat0_limit.e .def)
-! co2_ppm0   = tab_cntrl(16)
-! initial value for interactive CO2 run when there is no tracer field for CO2 in restart
-  co2_ppm0=284.32
-
-  solaire_etat0      = tab_cntrl(4)
-  tab_cntrl(5)=iflag_con
-  tab_cntrl(6)=nbapp_rad
-
-  IF (iflag_cycle_diurne.GE.1) tab_cntrl( 7) = iflag_cycle_diurne
-  IF (soil_model) tab_cntrl( 8) =1.
-  IF (new_oliq) tab_cntrl( 9) =1.
-  IF (ok_orodr) tab_cntrl(10) =1.
-  IF (ok_orolf) tab_cntrl(11) =1.
-  IF (ok_limitvrai) tab_cntrl(12) =1.
-
-  itau_phy = tab_cntrl(15)
-
-  clesphy0(1)=tab_cntrl( 5 )
-  clesphy0(2)=tab_cntrl( 6 )
-  clesphy0(3)=tab_cntrl( 7 )
-  clesphy0(4)=tab_cntrl( 8 )
-  clesphy0(5)=tab_cntrl( 9 )
-  clesphy0(6)=tab_cntrl( 10 )
-  clesphy0(7)=tab_cntrl( 11 )
-  clesphy0(8)=tab_cntrl( 12 )
-
-  ! set time iteration
-   CALL init_iteration(itau_phy)
-
-  ! read latitudes and make a sanity check (because already known from dyn)
-  CALL get_field("latitude",lat_startphy)
-  DO i=1,klon
-    IF (ABS(lat_startphy(i)-latitude_deg(i))>=1) THEN
-      WRITE(*,*) "phyetat0: Error! Latitude discrepancy wrt startphy file:",&
-                 " i=",i," lat_startphy(i)=",lat_startphy(i),&
-                 " latitude_deg(i)=",latitude_deg(i)
-      ! This is presumably serious enough to abort run
-      CALL abort_physic("phyetat0","discrepancy in latitudes!",1)
-    ENDIF
-    IF (ABS(lat_startphy(i)-latitude_deg(i))>=0.0001) THEN
-      WRITE(*,*) "phyetat0: Warning! Latitude discrepancy wrt startphy file:",&
-                 " i=",i," lat_startphy(i)=",lat_startphy(i),&
-                 " latitude_deg(i)=",latitude_deg(i)
-    ENDIF
-  ENDDO
-
-  ! read longitudes and make a sanity check (because already known from dyn)
-  CALL get_field("longitude",lon_startphy)
-  DO i=1,klon
-    IF (ABS(lon_startphy(i)-longitude_deg(i))>=1) THEN
-      IF (ABS(360-ABS(lon_startphy(i)-longitude_deg(i)))>=1) THEN
-        WRITE(*,*) "phyetat0: Error! Longitude discrepancy wrt startphy file:",&
-                   " i=",i," lon_startphy(i)=",lon_startphy(i),&
-                   " longitude_deg(i)=",longitude_deg(i)
-        ! This is presumably serious enough to abort run
-        CALL abort_physic("phyetat0","discrepancy in longitudes!",1)
-      ENDIF
-    ENDIF
-    IF (ABS(lon_startphy(i)-longitude_deg(i))>=1) THEN
-      IF (ABS(360-ABS(lon_startphy(i)-longitude_deg(i))) > 0.0001) THEN
-        WRITE(*,*) "phyetat0: Warning! Longitude discrepancy wrt startphy file:",&
-                   " i=",i," lon_startphy(i)=",lon_startphy(i),&
-                   " longitude_deg(i)=",longitude_deg(i)
-      ENDIF 
-    ENDIF
-  ENDDO
-
-  ! Lecture du masque terre mer
-
-  CALL get_field("masque", zmasq, found)
-  IF (.NOT. found) THEN
-     PRINT*, 'phyetat0: Le champ <masque> est absent'
-     PRINT *, 'fichier startphy non compatible avec phyetat0'
-  ENDIF
-
-  ! Lecture des fractions pour chaque sous-surface
-
-  ! initialisation des sous-surfaces
-
-  pctsrf = 0.
-
-  ! fraction de terre
-
-  CALL get_field("FTER", pctsrf(:, is_ter), found)
-  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FTER> est absent'
-
-  ! fraction de glace de terre
-
-  CALL get_field("FLIC", pctsrf(:, is_lic), found)
-  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FLIC> est absent'
-
-  ! fraction d'ocean
-
-  CALL get_field("FOCE", pctsrf(:, is_oce), found)
-  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FOCE> est absent'
-
-  ! fraction glace de mer
-
-  CALL get_field("FSIC", pctsrf(:, is_sic), found)
-  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FSIC> est absent'
-
-  !  Verification de l'adequation entre le masque et les sous-surfaces
-
-  fractint( 1 : klon) = pctsrf(1 : klon, is_ter)  &
-       + pctsrf(1 : klon, is_lic)
-  DO i = 1 , klon
-     IF ( abs(fractint(i) - zmasq(i) ) .GT. EPSFRA ) THEN
-        WRITE(*, *) 'phyetat0: attention fraction terre pas ',  &
-             'coherente ', i, zmasq(i), pctsrf(i, is_ter) &
-             , pctsrf(i, is_lic)
-        WRITE(*, *) 'Je force la coherence zmasq=fractint'
-        zmasq(i) = fractint(i)
-     ENDIF
-  ENDDO
-  fractint (1 : klon) =  pctsrf(1 : klon, is_oce)  &
-       + pctsrf(1 : klon, is_sic)
-  DO i = 1 , klon
-     IF ( abs( fractint(i) - (1. - zmasq(i))) .GT. EPSFRA ) THEN
-        WRITE(*, *) 'phyetat0 attention fraction ocean pas ',  &
-             'coherente ', i, zmasq(i) , pctsrf(i, is_oce) &
-             , pctsrf(i, is_sic)
-        WRITE(*, *) 'Je force la coherence zmasq=1.-fractint'
-        zmasq(i) = 1. - fractint(i)
-     ENDIF
-  ENDDO
-
-!===================================================================
-! Lecture des temperatures du sol:
-!===================================================================
-
-  found=phyetat0_get(1,ftsol(:,1),"TS","Surface temperature",283.)
-  IF (found) THEN
-     DO nsrf=2,nbsrf
-        ftsol(:,nsrf)=ftsol(:,1)
-     ENDDO
-  ELSE
-     found=phyetat0_srf(1,ftsol,"TS","Surface temperature",283.)
-  ENDIF
-
-!===================================================================
-  ! Lecture des albedo difus et direct
-!===================================================================
-
-  DO nsrf = 1, nbsrf
-     DO isw=1, nsw
-        IF (isw.GT.99) THEN
-           PRINT*, "Trop de bandes SW"
-           call abort_physic("phyetat0", "", 1)
-        ENDIF
-        WRITE(str2, '(i2.2)') isw
-        found=phyetat0_srf(1,falb_dir(:, isw,:),"A_dir_SW"//str2//"srf","Direct Albedo",0.2)
-        found=phyetat0_srf(1,falb_dif(:, isw,:),"A_dif_SW"//str2//"srf","Direct Albedo",0.2)
-     ENDDO
-  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:
-!===================================================================
-
-   DO isoil=1, nsoilmx
-        IF (isoil.GT.99) THEN
-           PRINT*, "Trop de couches "
-           call abort_physic("phyetat0", "", 1)
-        ENDIF
-        WRITE(str2,'(i2.2)') isoil
-        found=phyetat0_srf(1,tsoil(:, isoil,:),"Tsoil"//str2//"srf","Temp soil",0.)
-        IF (.NOT. found) THEN
-           PRINT*, "phyetat0: Le champ <Tsoil"//str7//"> est absent"
-           PRINT*, "          Il prend donc la valeur de surface"
-           tsoil(:, isoil, :)=ftsol(:, :)
-        ENDIF
-   ENDDO
-
-!=======================================================================
-! Lecture precipitation/evaporation
-!=======================================================================
-
-  found=phyetat0_srf(1,qsurf,"QS","Near surface hmidity",0.)
-  found=phyetat0_get(1,qsol,"QSOL","Surface hmidity / bucket",0.)
-  found=phyetat0_srf(1,snow,"SNOW","Surface snow",0.)
-  found=phyetat0_srf(1,fevap,"EVAP","evaporation",0.)
-  found=phyetat0_get(1,snow_fall,"snow_f","snow fall",0.)
-  found=phyetat0_get(1,rain_fall,"rain_f","rain fall",0.)
-
-!=======================================================================
-! Radiation
-!=======================================================================
-
-  found=phyetat0_get(1,solsw,"solsw","net SW radiation surf",0.)
-  found=phyetat0_get(1,solswfdiff,"solswfdiff","fraction of SW radiation surf that is diffuse",1.)
-  found=phyetat0_get(1,sollw,"sollw","net LW radiation surf",0.)
-  found=phyetat0_get(1,sollwdown,"sollwdown","down LW radiation surf",0.)
-  IF (.NOT. found) THEN
-     sollwdown(:) = 0. ;  zts(:)=0.
-     DO nsrf=1,nbsrf
-        zts(:)=zts(:)+ftsol(:,nsrf)*pctsrf(:,nsrf)
-     ENDDO
-     sollwdown(:)=sollw(:)+RSIGMA*zts(:)**4
-  ENDIF
-
-  found=phyetat0_get(1,radsol,"RADS","Solar radiation",0.)
-  found=phyetat0_get(1,fder,"fder","Flux derivative",0.) 
-
-
-  ! Lecture de la longueur de rugosite 
-  found=phyetat0_srf(1,z0m,"RUG","Z0m ancien",0.001)
-  IF (found) THEN
-     z0h(:,1:nbsrf)=z0m(:,1:nbsrf)
-  ELSE
-     found=phyetat0_srf(1,z0m,"Z0m","Roughness length, momentum ",0.001)
-     found=phyetat0_srf(1,z0h,"Z0h","Roughness length, enthalpy ",0.001)
-  ENDIF
-!FC
-  IF (ifl_pbltree>0) THEN
-!CALL get_field("FTER", pctsrf(:, is_ter), found)
-    treedrg(:,1:klev,1:nbsrf)= 0.0
-    CALL get_field("treedrg_ter", drg_ter(:,:), found)
-!  found=phyetat0_srf(1,treedrg,"treedrg","drag from vegetation" , 0.)
-    !lecture du profile de freinage des arbres
-    IF (.not. found ) THEN
-      treedrg(:,1:klev,1:nbsrf)= 0.0
-    ELSE
-      treedrg(:,1:klev,is_ter)= drg_ter(:,:)
-!     found=phyetat0_srf(klev,treedrg,"treedrg","freinage arbres",0.)
-    ENDIF
-  ELSE
-    ! initialize treedrg(), because it will be written in restartphy.nc
-    treedrg(:,:,:) = 0.0 
-  ENDIF
-
-  ! Lecture de l'age de la neige:
-  found=phyetat0_srf(1,agesno,"AGESNO","SNOW AGE",0.001)
-
-  ancien_ok=.true.
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,t_ancien,"TANCIEN","TANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,q_ancien,"QANCIEN","QANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,ql_ancien,"QLANCIEN","QLANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,qs_ancien,"QSANCIEN","QSANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,rneb_ancien,"RNEBANCIEN","RNEBANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,u_ancien,"UANCIEN","UANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,v_ancien,"VANCIEN","VANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(1,prw_ancien,"PRWANCIEN","PRWANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(1,prlw_ancien,"PRLWANCIEN","PRLWANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(1,prsw_ancien,"PRSWANCIEN","PRSWANCIEN",0.)
-
-  ! Ehouarn: addtional tests to check if t_ancien, q_ancien contain
-  !          dummy values (as is the case when generated by ce0l,
-  !          or by iniaqua)
-  IF ( (maxval(q_ancien).EQ.minval(q_ancien))       .OR. &
-       (maxval(ql_ancien).EQ.minval(ql_ancien))     .OR. &
-       (maxval(qs_ancien).EQ.minval(qs_ancien))     .OR. &
-       (maxval(rneb_ancien).EQ.minval(rneb_ancien)) .OR. &
-       (maxval(prw_ancien).EQ.minval(prw_ancien))   .OR. &
-       (maxval(prlw_ancien).EQ.minval(prlw_ancien)) .OR. &
-       (maxval(prsw_ancien).EQ.minval(prsw_ancien)) .OR. &
-       (maxval(t_ancien).EQ.minval(t_ancien)) ) THEN
-    ancien_ok=.false.
-  ENDIF
-
-  found=phyetat0_get(klev,clwcon,"CLWCON","CLWCON",0.)
-  found=phyetat0_get(klev,rnebcon,"RNEBCON","RNEBCON",0.)
-  found=phyetat0_get(klev,ratqs,"RATQS","RATQS",0.)
-
-  found=phyetat0_get(1,run_off_lic_0,"RUNOFFLIC0","RUNOFFLIC0",0.)
-
-!==================================
-!  TKE
-!==================================
-!
-  IF (iflag_pbl>1) then
-     found=phyetat0_srf(klev+1,pbl_tke,"TKE","Turb. Kinetic. Energ. ",1.e-8)
-  ENDIF
-
-  IF (iflag_pbl>1 .AND. iflag_wake>=1  .AND. iflag_pbl_split >=1 ) then
-    found=phyetat0_srf(klev+1,wake_delta_pbl_tke,"DELTATKE","Del TKE wk/env",0.)
-!!    found=phyetat0_srf(1,delta_tsurf,"DELTA_TSURF","Delta Ts wk/env ",0.)
-    found=phyetat0_srf(1,delta_tsurf,"DELTATS","Delta Ts wk/env ",0.)
-!!    found=phyetat0_srf(1,beta_aridity,"BETA_S","Aridity factor ",1.)
-    found=phyetat0_srf(1,beta_aridity,"BETAS","Aridity factor ",1.)
-  ENDIF   !(iflag_pbl>1 .AND. iflag_wake>=1 .AND. iflag_pbl_split >=1 )
-
-!==================================
-!  thermiques, poches, convection
-!==================================
-
-! Emanuel
-  found=phyetat0_get(klev,sig1,"sig1","sig1",0.)
-  found=phyetat0_get(klev,w01,"w01","w01",0.)
-
-! Wake
-  found=phyetat0_get(klev,wake_deltat,"WAKE_DELTAT","Delta T wake/env",0.)
-  found=phyetat0_get(klev,wake_deltaq,"WAKE_DELTAQ","Delta hum. wake/env",0.)
-  found=phyetat0_get(1,wake_s,"WAKE_S","Wake frac. area",0.)
-!jyg<
-!  Set wake_dens to -1000. when there is no restart so that the actual
-!  initialization is made in calwake.
-!!  found=phyetat0_get(1,wake_dens,"WAKE_DENS","Wake num. /unit area",0.)
-  found=phyetat0_get(1,wake_dens,"WAKE_DENS","Wake num. /unit area",-1000.)
-  found=phyetat0_get(1,awake_dens,"AWAKE_DENS","Active Wake num. /unit area",0.)
-  found=phyetat0_get(1,cv_gen,"CV_GEN","CB birth rate",0.)
-!>jyg
-  found=phyetat0_get(1,wake_cstar,"WAKE_CSTAR","WAKE_CSTAR",0.)
-  found=phyetat0_get(1,wake_pe,"WAKE_PE","WAKE_PE",0.)
-  found=phyetat0_get(1,wake_fip,"WAKE_FIP","WAKE_FIP",0.)
-
-! Thermiques
-  found=phyetat0_get(1,zmax0,"ZMAX0","ZMAX0",40.)
-  found=phyetat0_get(1,f0,"F0","F0",1.e-5)
-  found=phyetat0_get(klev+1,fm_therm,"FM_THERM","Thermals mass flux",0.)
-  found=phyetat0_get(klev,entr_therm,"ENTR_THERM","Thermals Entrain.",0.)
-  found=phyetat0_get(klev,detr_therm,"DETR_THERM","Thermals Detrain.",0.)
-
-! ALE/ALP
-  found=phyetat0_get(1,ale_bl,"ALE_BL","ALE BL",0.)
-  found=phyetat0_get(1,ale_bl_trig,"ALE_BL_TRIG","ALE BL_TRIG",0.)
-  found=phyetat0_get(1,alp_bl,"ALP_BL","ALP BL",0.)
-  found=phyetat0_get(1,ale_wake,"ALE_WAKE","ALE_WAKE",0.)
-  found=phyetat0_get(1,ale_bl_stat,"ALE_BL_STAT","ALE_BL_STAT",0.)
-
-! fisrtilp/Clouds 0.002 could be ratqsbas. But can stay like this as well
-  found=phyetat0_get(klev,ratqs_inter,"RATQS_INTER","Relative width of the lsc sugrid scale water",0.002)
-
-!===========================================
-  ! Read and send field trs to traclmdz
-!===========================================
-
-!--OB now this is for co2i - ThL: and therefore also for inco
-  IF (ANY(types_trac == 'co2i') .OR. ANY(types_trac == 'inco')) THEN
-     IF (carbon_cycle_cpl) THEN
-        ALLOCATE(co2_send(klon), stat=ierr)
-        IF (ierr /= 0) CALL abort_physic('phyetat0', 'pb allocation co2_send', 1)
-        found=phyetat0_get(1,co2_send,"co2_send","co2 send",co2_ppm)
-     ENDIF
-  ELSE IF (ANY(types_trac == 'lmdz')) THEN
-     it = 0
-     DO iq = 1, nqtot
-        IF(.NOT.(tracers(iq)%isAdvected .AND. tracers(iq)%isInPhysics)) CYCLE
-        it = it+1
-        found=phyetat0_get(1,trs(:,it),"trs_"//TRIM(tracers(iq)%name), &
-                                  "Surf trac"//TRIM(tracers(iq)%name),0.)
-     END DO
-     CALL traclmdz_from_restart(trs)
-  ENDIF
-
-
-!===========================================
-!  ondes de gravite / relief
-!===========================================
-
-!  ondes de gravite non orographiques
-  IF (ok_gwd_rando) found = &
-       phyetat0_get(klev,du_gwd_rando,"du_gwd_rando","du_gwd_rando",0.)
-  IF (.NOT. ok_hines .AND. ok_gwd_rando) found &
-       = phyetat0_get(klev,du_gwd_front,"du_gwd_front","du_gwd_front",0.)
-
-!  prise en compte du relief sous-maille
-  found=phyetat0_get(1,zmea,"ZMEA","sub grid orography",0.)
-  found=phyetat0_get(1,zstd,"ZSTD","sub grid orography",0.)
-  found=phyetat0_get(1,zsig,"ZSIG","sub grid orography",0.)
-  found=phyetat0_get(1,zgam,"ZGAM","sub grid orography",0.)
-  found=phyetat0_get(1,zthe,"ZTHE","sub grid orography",0.)
-  found=phyetat0_get(1,zpic,"ZPIC","sub grid orography",0.)
-  found=phyetat0_get(1,zval,"ZVAL","sub grid orography",0.)
-  found=phyetat0_get(1,zmea,"ZMEA","sub grid orography",0.)
-  found=phyetat0_get(1,rugoro,"RUGSREL","sub grid orography",0.)
-
-!===========================================
-! Initialize ocean
-!===========================================
-
-  IF ( type_ocean == 'slab' ) THEN
-      CALL ocean_slab_init(phys_tstep, pctsrf)
-      IF (nslay.EQ.1) THEN
-        found=phyetat0_get(1,tslab,"tslab01","tslab",0.)
-        IF (.NOT. found) THEN
-            found=phyetat0_get(1,tslab,"tslab","tslab",0.)
-        ENDIF
-      ELSE
-          DO i=1,nslay
-            WRITE(str2,'(i2.2)') i
-            found=phyetat0_get(1,tslab(:,i),"tslab"//str2,"tslab",0.)  
-          ENDDO
-      ENDIF
-      IF (.NOT. found) THEN 
-          PRINT*, "phyetat0: Le champ <tslab> est absent"
-          PRINT*, "Initialisation a tsol_oce"
-          DO i=1,nslay
-              tslab(:,i)=MAX(ftsol(:,is_oce),271.35)
-          ENDDO
-      ENDIF 
-
-      ! Sea ice variables
-      IF (version_ocean == 'sicINT') THEN
-          found=phyetat0_get(1,tice,"slab_tice","slab_tice",0.)
-          IF (.NOT. found) THEN 
-              PRINT*, "phyetat0: Le champ <tice> est absent"
-              PRINT*, "Initialisation a tsol_sic"
-                  tice(:)=ftsol(:,is_sic)
-          ENDIF 
-          found=phyetat0_get(1,seaice,"seaice","seaice",0.)
-          IF (.NOT. found) THEN
-              PRINT*, "phyetat0: Le champ <seaice> est absent"
-              PRINT*, "Initialisation a 0/1m suivant fraction glace"
-              seaice(:)=0.
-              WHERE (pctsrf(:,is_sic).GT.EPSFRA)
-                  seaice=917.
-              ENDWHERE
-          ENDIF
-      ENDIF !sea ice INT
-  ENDIF ! Slab        
-
-  if (activate_ocean_skin >= 1) then
-     if (activate_ocean_skin == 2 .and. type_ocean == 'couple') then
-        found = phyetat0_get(1, delta_sal, "delta_sal", &
-             "ocean-air interface salinity minus bulk salinity", 0.)
-        found = phyetat0_get(1, delta_sst, "delta_SST", &
-             "ocean-air interface temperature minus bulk SST", 0.)
-     end if
-     
-     found = phyetat0_get(1, ds_ns, "dS_ns", "delta salinity near surface", 0.)
-     found = phyetat0_get(1, dt_ns, "dT_ns", "delta temperature near surface", &
-          0.)
-
-     where (pctsrf(:, is_oce) == 0.)
-        ds_ns = missing_val
-        dt_ns = missing_val
-        delta_sst = missing_val
-        delta_sal = missing_val
-     end where
-  end if
-
-  ! on ferme le fichier
-  CALL close_startphy
-
-  ! Initialize module pbl_surface_mod 
-
-  CALL pbl_surface_init(fder, snow, qsurf, tsoil)
-
-  ! Initialize module ocean_cpl_mod for the case of coupled ocean
-  IF ( type_ocean == 'couple' ) THEN
-     CALL ocean_cpl_init(phys_tstep, longitude_deg, latitude_deg)
-  ENDIF
-
-!  CALL init_iophy_new(latitude_deg, longitude_deg)
-
-  ! Initilialize module fonte_neige_mod      
-  CALL fonte_neige_init(run_off_lic_0)
-
-END SUBROUTINE phyetat0
-
-!===================================================================
-FUNCTION phyetat0_get(nlev,field,name,descr,default)
-!===================================================================
-! Lecture d'un champ avec contrôle
-! Function logique dont le resultat indique si la lecture
-! s'est bien passée
-! On donne une valeur par defaut dans le cas contraire
-!===================================================================
-
-USE iostart, ONLY : get_field
-USE dimphy, only: klon 
-USE print_control_mod, ONLY: lunout
-
-IMPLICIT NONE
-
-LOGICAL phyetat0_get
-
-! arguments
-INTEGER,INTENT(IN) :: nlev
-CHARACTER*(*),INTENT(IN) :: name,descr
-REAL,INTENT(IN) :: default
-REAL,DIMENSION(klon,nlev),INTENT(INOUT) :: field
-
-! Local variables
-LOGICAL found
-
-   CALL get_field(name, field, found)
-   IF (.NOT. found) THEN
-     WRITE(lunout,*) "phyetat0: Le champ <",TRIM(name),"> est absent"
-     WRITE(lunout,*) "Depart legerement fausse. Mais je continue"
-     field(:,:)=default
-   ENDIF
-   WRITE(lunout,*) name, descr, MINval(field),MAXval(field)
-   phyetat0_get=found
-
-RETURN
-END FUNCTION phyetat0_get
-
-!================================================================
-FUNCTION phyetat0_srf(nlev,field,name,descr,default)
-!===================================================================
-! Lecture d'un champ par sous-surface avec contrôle
-! Function logique dont le resultat indique si la lecture
-! s'est bien passée
-! On donne une valeur par defaut dans le cas contraire
-!===================================================================
-
-USE iostart, ONLY : get_field
-USE dimphy, only: klon 
-USE indice_sol_mod, only: nbsrf
-USE print_control_mod, ONLY: lunout
-
-IMPLICIT NONE
-
-LOGICAL phyetat0_srf
-! arguments
-INTEGER,INTENT(IN) :: nlev
-CHARACTER*(*),INTENT(IN) :: name,descr
-REAL,INTENT(IN) :: default
-REAL,DIMENSION(klon,nlev,nbsrf),INTENT(INOUT) :: field
-
-! Local variables
-LOGICAL found,phyetat0_get
-INTEGER nsrf
-CHARACTER*2 str2
-  
-     IF (nbsrf.GT.99) THEN
-        WRITE(lunout,*) "Trop de sous-mailles"
-        call abort_physic("phyetat0", "", 1)
-     ENDIF
-
-     DO nsrf = 1, nbsrf
-        WRITE(str2, '(i2.2)') nsrf
-        found= phyetat0_get(nlev,field(:,:, nsrf), &
-        name//str2,descr//" srf:"//str2,default)
-     ENDDO
-
-     phyetat0_srf=found
-
-RETURN
-END FUNCTION phyetat0_srf
-
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyetat0_get_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyetat0_get_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyetat0_get_mod.F90	(revision 4482)
@@ -0,0 +1,143 @@
+MODULE phyetat0_get_mod
+
+  PRIVATE
+  PUBLIC :: phyetat0_get, phyetat0_srf
+
+  INTERFACE phyetat0_get
+    MODULE PROCEDURE phyetat0_get10, phyetat0_get20, phyetat0_get11, phyetat0_get21
+  END INTERFACE phyetat0_get
+  INTERFACE phyetat0_srf
+    MODULE PROCEDURE phyetat0_srf20, phyetat0_srf30, phyetat0_srf21, phyetat0_srf31
+  END INTERFACE phyetat0_srf
+
+CONTAINS
+
+!==============================================================================
+LOGICAL FUNCTION phyetat0_get10(field, name, descr, default) RESULT(lFound)
+! Read a field. Check whether reading succeded and use default value if not.
+  IMPLICIT NONE
+  REAL,             INTENT(INOUT) :: field(:) ! klon
+  CHARACTER(LEN=*), INTENT(IN)    :: name
+  CHARACTER(LEN=*), INTENT(IN)    :: descr
+  REAL,             INTENT(IN)    :: default
+!------------------------------------------------------------------------------
+  REAL :: fld(SIZE(field),1)
+  lFound = phyetat0_get21(fld, [name], descr, default); field = fld(:,1)
+END FUNCTION phyetat0_get10
+!==============================================================================
+LOGICAL FUNCTION phyetat0_get20(field, name, descr, default) RESULT(lFound)
+! Same as phyetat0_get11, field on multiple levels.
+  IMPLICIT NONE
+  REAL,             INTENT(INOUT) :: field(:,:) ! klon, nlev
+  CHARACTER(LEN=*), INTENT(IN)    :: name
+  CHARACTER(LEN=*), INTENT(IN)    :: descr
+  REAL,             INTENT(IN)    :: default
+!-----------------------------------------------------------------------------
+  lFound = phyetat0_get21(field, [name], descr, default)
+END FUNCTION phyetat0_get20
+!==============================================================================
+LOGICAL FUNCTION phyetat0_get11(field, name, descr, default) RESULT(lFound)
+! Same as phyetat0_get11, multiple names.
+  IMPLICIT NONE
+  REAL,             INTENT(INOUT) :: field(:) ! klon
+  CHARACTER(LEN=*), INTENT(IN)    :: name(:)
+  CHARACTER(LEN=*), INTENT(IN)    :: descr
+  REAL,             INTENT(IN)    :: default
+!-----------------------------------------------------------------------------
+  REAL :: fld(SIZE(field),1)
+  lFound = phyetat0_get21(fld, name, descr, default); field = fld(:,1)
+END FUNCTION phyetat0_get11
+!==============================================================================
+LOGICAL FUNCTION phyetat0_get21(field, name, descr, default, tname) RESULT(lFound)
+! Same as phyetat0_get11, field on multiple levels, multiple names.
+  USE iostart,           ONLY: get_field
+  USE print_control_mod, ONLY: lunout
+  IMPLICIT NONE
+  REAL,             INTENT(INOUT) :: field(:,:) ! klon, nlev
+  CHARACTER(LEN=*), INTENT(IN)    :: name(:)
+  CHARACTER(LEN=*), INTENT(IN)    :: descr
+  REAL,             INTENT(IN)    :: default
+  CHARACTER(LEN=*), OPTIONAL, INTENT(OUT) :: tname
+!-----------------------------------------------------------------------------
+  CHARACTER(LEN=LEN(name)) :: tnam
+  INTEGER :: i
+  DO i = 1, SIZE(name)
+    CALL get_field(TRIM(name(i)), field, lFound)
+    IF(lFound) EXIT
+    WRITE(lunout,*) "phyetat0: Missing field <",TRIM(name(i)),"> "
+  END DO
+  IF(.NOT.lFound) THEN
+    WRITE(lunout,*) "Slightly distorted start ; continuing."
+    field(:,:) = default
+    tnam = name(1)
+  ELSE
+    tnam = name(i)
+  END IF
+  WRITE(lunout,'(2(a,ES14.7))') 'phyetat0: '//TRIM(tnam)//' ('//TRIM(descr)//') min/max=', &
+    MINval(field),' ',MAXval(field)
+  IF(PRESENT(tname)) tname = tnam
+END FUNCTION phyetat0_get21
+!==============================================================================
+LOGICAL FUNCTION phyetat0_srf20(field, name, descr, default) RESULT(lFound)
+! Read a field per sub-surface.
+! Check whether reading succeded and use default value if not.
+  IMPLICIT NONE
+  REAL,             INTENT(INOUT) :: field(:,:)
+  CHARACTER(LEN=*), INTENT(IN)    :: name
+  CHARACTER(LEN=*), INTENT(IN)    :: descr
+  REAL,             INTENT(IN)    :: default
+!-----------------------------------------------------------------------------
+  REAL :: fld(SIZE(field,1),1,SIZE(field,2))
+  lFound = phyetat0_srf31(fld, [name], descr, default); field = fld(:,1,:)
+END FUNCTION phyetat0_srf20
+
+!==============================================================================
+LOGICAL FUNCTION phyetat0_srf30(field, name, descr, default) RESULT(lFound)
+! Same as phyetat0_sfr11, multiple names tested one after the other.
+  IMPLICIT NONE
+  REAL,             INTENT(INOUT) :: field(:,:,:)
+  CHARACTER(LEN=*), INTENT(IN)    :: name
+  CHARACTER(LEN=*), INTENT(IN)    :: descr
+  REAL,             INTENT(IN)    :: default
+!-----------------------------------------------------------------------------
+  lFound = phyetat0_srf31(field, [name], descr, default)
+END FUNCTION phyetat0_srf30
+
+!==============================================================================
+LOGICAL FUNCTION phyetat0_srf21(field, name, descr, default) RESULT(lFound)
+! Same as phyetat0_sfr11, field on multiple levels.
+  IMPLICIT NONE
+  REAL,             INTENT(INOUT) :: field(:,:)
+  CHARACTER(LEN=*), INTENT(IN)    :: name(:)
+  CHARACTER(LEN=*), INTENT(IN)    :: descr
+  REAL,             INTENT(IN)    :: default
+!-----------------------------------------------------------------------------
+  REAL :: fld(SIZE(field,1),1,SIZE(field,2))
+  lFound = phyetat0_srf31(fld, name, descr, default); field = fld(:,1,:)
+END FUNCTION phyetat0_srf21
+
+!==============================================================================
+LOGICAL FUNCTION phyetat0_srf31(field, name, descr, default) RESULT(lFound)
+! Same as phyetat0_sfr11, field on multiple levels, multiple names tested one after the other.
+  USE iostart,           ONLY: get_field
+  USE print_control_mod, ONLY: lunout
+  USE strings_mod,       ONLY: int2str, maxlen
+  IMPLICIT NONE
+  REAL,             INTENT(INOUT) :: field(:,:,:)
+  CHARACTER(LEN=*), INTENT(IN)    :: name(:)
+  CHARACTER(LEN=*), INTENT(IN)    :: descr
+  REAL,             INTENT(IN)    :: default
+!-----------------------------------------------------------------------------
+  INTEGER :: nsrf, i
+  CHARACTER(LEN=maxlen) :: nam(SIZE(name)), tname, des
+  IF(SIZE(field,3)>99) CALL abort_physic("phyetat0", "Too much sub-cells", 1)
+  DO nsrf = 1, SIZE(field,3)
+    DO i = 1, SIZE(name); nam(i) = TRIM(name(i))//TRIM(int2str(nsrf,2)); END DO
+    des = TRIM(descr)//" srf:"//int2str(nsrf,2)
+    lFound = phyetat0_get21(field(:,:,nsrf), nam, TRIM(des), default, tname)
+  END DO
+  WRITE(lunout,'(2(a,ES14.7))') 'phyetat0: '//TRIM(tname)//' ('//TRIM(descr)//') min/max=', &
+    MINval(field),' ',MAXval(field)
+END FUNCTION phyetat0_srf31
+
+END MODULE phyetat0_get_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyetat0_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyetat0_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyetat0_mod.F90	(revision 4482)
@@ -0,0 +1,608 @@
+! $Id$
+
+MODULE phyetat0_mod
+
+  PRIVATE
+  PUBLIC :: phyetat0
+
+CONTAINS
+
+SUBROUTINE phyetat0 (fichnom, clesphy0, tabcntr0)
+
+  USE dimphy, only: klon, zmasq, klev
+  USE iophy, ONLY : init_iophy_new
+  USE ocean_cpl_mod,    ONLY : ocean_cpl_init
+  USE fonte_neige_mod,  ONLY : fonte_neige_init
+  USE pbl_surface_mod,  ONLY : pbl_surface_init
+  USE surface_data,     ONLY : type_ocean, version_ocean
+  USE phyetat0_get_mod, ONLY : phyetat0_get, phyetat0_srf
+  USE phys_state_var_mod, ONLY : ancien_ok, clwcon, detr_therm, phys_tstep, &
+       qsol, fevap, z0m, z0h, agesno, &
+       du_gwd_rando, du_gwd_front, entr_therm, f0, fm_therm, &
+       falb_dir, falb_dif, prw_ancien, prlw_ancien, prsw_ancien, &
+       ftsol, pbl_tke, pctsrf, q_ancien, ql_ancien, qs_ancien, rneb_ancien, radpas, radsol, rain_fall, ratqs, &
+       rnebcon, rugoro, sig1, snow_fall, solaire_etat0, sollw, sollwdown, &
+       solsw, solswfdiff, t_ancien, u_ancien, v_ancien, w01, wake_cstar, wake_deltaq, &
+       wake_deltat, wake_delta_pbl_TKE, delta_tsurf, beta_aridity, wake_fip, wake_pe, &
+       wake_s, wake_dens, awake_dens, cv_gen, zgam, zmax0, zmea, zpic, zsig, &
+       zstd, zthe, zval, ale_bl, ale_bl_trig, alp_bl, u10m, v10m, treedrg, &
+       ale_wake, ale_bl_stat, ds_ns, dt_ns, delta_sst, delta_sal, dter, dser, &
+       dt_ds, ratqs_inter
+!FC
+  USE geometry_mod,     ONLY: longitude_deg, latitude_deg
+  USE iostart,          ONLY: close_startphy, get_field, get_var, open_startphy
+  USE infotrac_phy,     ONLY: nqtot, nbtr, type_trac, tracers
+  USE readTracFiles_mod,ONLY: maxlen, new2oldH2O
+  USE traclmdz_mod,     ONLY: traclmdz_from_restart
+  USE carbon_cycle_mod, ONLY: carbon_cycle_init, carbon_cycle_cpl, carbon_cycle_tr, carbon_cycle_rad, co2_send, RCO2_glo
+  USE indice_sol_mod,   ONLY: nbsrf, is_ter, epsfra, is_lic, is_oce, is_sic
+  USE ocean_slab_mod,   ONLY: nslay, tslab, seaice, tice, ocean_slab_init
+  USE time_phylmdz_mod, ONLY: init_iteration, pdtphys, itau_phy
+#ifdef CPP_XIOS
+  USE wxios, ONLY: missing_val
+#else
+  use netcdf, only: missing_val => nf90_fill_real
+#endif
+  use config_ocean_skin_m, only: activate_ocean_skin
+
+  IMPLICIT none
+  !======================================================================
+  ! Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
+  ! Objet: Lecture de l'etat initial pour la physique
+  !======================================================================
+  include "dimsoil.h"
+  include "clesphys.h"
+  include "alpale.h"
+  include "compbl.h"
+  include "YOMCST.h"
+  !======================================================================
+  CHARACTER*(*) fichnom
+
+  ! les variables globales lues dans le fichier restart
+
+  REAL tsoil(klon, nsoilmx, nbsrf)
+  REAL qsurf(klon, nbsrf)
+  REAL snow(klon, nbsrf)
+  real fder(klon)
+  REAL run_off_lic_0(klon)
+  REAL fractint(klon)
+  REAL trs(klon, nbtr)
+  REAL zts(klon)
+  ! pour drag arbres FC
+  REAL drg_ter(klon,klev)
+
+  CHARACTER*6 ocean_in
+  LOGICAL ok_veget_in
+
+  INTEGER        longcles
+  PARAMETER    ( longcles = 20 )
+  REAL clesphy0( longcles )
+
+  REAL xmin, xmax
+
+  INTEGER nid, nvarid
+  INTEGER ierr, i, nsrf, isoil , k
+  INTEGER length
+  PARAMETER (length=100)
+  INTEGER it, iq, isw
+  REAL tab_cntrl(length), tabcntr0(length)
+  CHARACTER*7 str7
+  CHARACTER*2 str2
+  LOGICAL :: found
+  REAL :: lon_startphy(klon), lat_startphy(klon)
+  CHARACTER(LEN=maxlen) :: tname, t(2)
+
+  ! FH1D
+  !     real iolat(jjm+1)
+  !real iolat(jjm+1-1/(iim*jjm))
+
+  ! Ouvrir le fichier contenant l'etat initial:
+
+  CALL open_startphy(fichnom)
+
+  ! Lecture des parametres de controle:
+
+  CALL get_var("controle", tab_cntrl)
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  ! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
+  ! Les constantes de la physiques sont lues dans la physique seulement.
+  ! Les egalites du type
+  !             tab_cntrl( 5 )=clesphy0(1)
+  ! sont remplacees par
+  !             clesphy0(1)=tab_cntrl( 5 )
+  ! On inverse aussi la logique.
+  ! On remplit les tab_cntrl avec les parametres lus dans les .def
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  DO i = 1, length
+     tabcntr0( i ) = tab_cntrl( i )
+  ENDDO
+
+  tab_cntrl(1)=pdtphys
+  tab_cntrl(2)=radpas
+
+  ! co2_ppm : value from the previous time step
+
+  ! co2_ppm0 : initial value of atmospheric CO2 (from create_etat0_limit.e .def)
+  co2_ppm0 = 284.32
+  ! when no initial value is available e.g., from a restart 
+  ! this variable must be set  in a .def file which will then be 
+  ! used by the conf_phys_m.F90 routine.
+  ! co2_ppm0 = 284.32 (illustrative example on how to set the variable in .def
+  ! file, for a pre-industrial CO2 concentration value)
+
+  IF (carbon_cycle_tr .OR. carbon_cycle_cpl) THEN
+     co2_ppm = tab_cntrl(3)
+     RCO2    = co2_ppm * 1.0e-06 * RMCO2 / RMD
+     IF (tab_cntrl(17) > 0. .AND. carbon_cycle_rad) THEN
+           RCO2_glo = tab_cntrl(17)
+       ELSE
+           RCO2_glo    = co2_ppm0 * 1.0e-06 * RMCO2 / RMD
+     ENDIF
+     ! ELSE : keep value from .def
+  ENDIF
+
+  solaire_etat0      = tab_cntrl(4)
+  tab_cntrl(5)=iflag_con
+  tab_cntrl(6)=nbapp_rad
+
+  IF (iflag_cycle_diurne.GE.1) tab_cntrl( 7) = iflag_cycle_diurne
+  IF (soil_model) tab_cntrl( 8) =1.
+  IF (new_oliq) tab_cntrl( 9) =1.
+  IF (ok_orodr) tab_cntrl(10) =1.
+  IF (ok_orolf) tab_cntrl(11) =1.
+  IF (ok_limitvrai) tab_cntrl(12) =1.
+
+  itau_phy = tab_cntrl(15)
+
+  clesphy0(1)=tab_cntrl( 5 )
+  clesphy0(2)=tab_cntrl( 6 )
+  clesphy0(3)=tab_cntrl( 7 )
+  clesphy0(4)=tab_cntrl( 8 )
+  clesphy0(5)=tab_cntrl( 9 )
+  clesphy0(6)=tab_cntrl( 10 )
+  clesphy0(7)=tab_cntrl( 11 )
+  clesphy0(8)=tab_cntrl( 12 )
+  clesphy0(9)=tab_cntrl( 17 )
+
+  ! set time iteration
+   CALL init_iteration(itau_phy)
+
+  ! read latitudes and make a sanity check (because already known from dyn)
+  CALL get_field("latitude",lat_startphy)
+  DO i=1,klon
+    IF (ABS(lat_startphy(i)-latitude_deg(i))>=1) THEN
+      WRITE(*,*) "phyetat0: Error! Latitude discrepancy wrt startphy file:",&
+                 " i=",i," lat_startphy(i)=",lat_startphy(i),&
+                 " latitude_deg(i)=",latitude_deg(i)
+      ! This is presumably serious enough to abort run
+      CALL abort_physic("phyetat0","discrepancy in latitudes!",1)
+    ENDIF
+    IF (ABS(lat_startphy(i)-latitude_deg(i))>=0.0001) THEN
+      WRITE(*,*) "phyetat0: Warning! Latitude discrepancy wrt startphy file:",&
+                 " i=",i," lat_startphy(i)=",lat_startphy(i),&
+                 " latitude_deg(i)=",latitude_deg(i)
+    ENDIF
+  ENDDO
+
+  ! read longitudes and make a sanity check (because already known from dyn)
+  CALL get_field("longitude",lon_startphy)
+  DO i=1,klon
+    IF (ABS(lon_startphy(i)-longitude_deg(i))>=1) THEN
+      IF (ABS(360-ABS(lon_startphy(i)-longitude_deg(i)))>=1) THEN
+        WRITE(*,*) "phyetat0: Error! Longitude discrepancy wrt startphy file:",&
+                   " i=",i," lon_startphy(i)=",lon_startphy(i),&
+                   " longitude_deg(i)=",longitude_deg(i)
+        ! This is presumably serious enough to abort run
+        CALL abort_physic("phyetat0","discrepancy in longitudes!",1)
+      ENDIF
+    ENDIF
+    IF (ABS(lon_startphy(i)-longitude_deg(i))>=1) THEN
+      IF (ABS(360-ABS(lon_startphy(i)-longitude_deg(i))) > 0.0001) THEN
+        WRITE(*,*) "phyetat0: Warning! Longitude discrepancy wrt startphy file:",&
+                   " i=",i," lon_startphy(i)=",lon_startphy(i),&
+                   " longitude_deg(i)=",longitude_deg(i)
+      ENDIF 
+    ENDIF
+  ENDDO
+
+  ! Lecture du masque terre mer
+
+  CALL get_field("masque", zmasq, found)
+  IF (.NOT. found) THEN
+     PRINT*, 'phyetat0: Le champ <masque> est absent'
+     PRINT *, 'fichier startphy non compatible avec phyetat0'
+  ENDIF
+
+  ! Lecture des fractions pour chaque sous-surface
+
+  ! initialisation des sous-surfaces
+
+  pctsrf = 0.
+
+  ! fraction de terre
+
+  CALL get_field("FTER", pctsrf(:, is_ter), found)
+  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FTER> est absent'
+
+  ! fraction de glace de terre
+
+  CALL get_field("FLIC", pctsrf(:, is_lic), found)
+  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FLIC> est absent'
+
+  ! fraction d'ocean
+
+  CALL get_field("FOCE", pctsrf(:, is_oce), found)
+  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FOCE> est absent'
+
+  ! fraction glace de mer
+
+  CALL get_field("FSIC", pctsrf(:, is_sic), found)
+  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FSIC> est absent'
+
+  !  Verification de l'adequation entre le masque et les sous-surfaces
+
+  fractint( 1 : klon) = pctsrf(1 : klon, is_ter)  &
+       + pctsrf(1 : klon, is_lic)
+  DO i = 1 , klon
+     IF ( abs(fractint(i) - zmasq(i) ) .GT. EPSFRA ) THEN
+        WRITE(*, *) 'phyetat0: attention fraction terre pas ',  &
+             'coherente ', i, zmasq(i), pctsrf(i, is_ter) &
+             , pctsrf(i, is_lic)
+        WRITE(*, *) 'Je force la coherence zmasq=fractint'
+        zmasq(i) = fractint(i)
+     ENDIF
+  ENDDO
+  fractint (1 : klon) =  pctsrf(1 : klon, is_oce)  &
+       + pctsrf(1 : klon, is_sic)
+  DO i = 1 , klon
+     IF ( abs( fractint(i) - (1. - zmasq(i))) .GT. EPSFRA ) THEN
+        WRITE(*, *) 'phyetat0 attention fraction ocean pas ',  &
+             'coherente ', i, zmasq(i) , pctsrf(i, is_oce) &
+             , pctsrf(i, is_sic)
+        WRITE(*, *) 'Je force la coherence zmasq=1.-fractint'
+        zmasq(i) = 1. - fractint(i)
+     ENDIF
+  ENDDO
+
+!===================================================================
+! Lecture des temperatures du sol:
+!===================================================================
+
+  found=phyetat0_get(ftsol(:,1),"TS","Surface temperature",283.)
+  IF (found) THEN
+     DO nsrf=2,nbsrf
+        ftsol(:,nsrf)=ftsol(:,1)
+     ENDDO
+  ELSE
+     found=phyetat0_srf(ftsol,"TS","Surface temperature",283.)
+  ENDIF
+
+!===================================================================
+  ! Lecture des albedo difus et direct
+!===================================================================
+
+  DO nsrf = 1, nbsrf
+     DO isw=1, nsw
+        IF (isw.GT.99) THEN
+           PRINT*, "Trop de bandes SW"
+           call abort_physic("phyetat0", "", 1)
+        ENDIF
+        WRITE(str2, '(i2.2)') isw
+        found=phyetat0_srf(falb_dir(:, isw,:),"A_dir_SW"//str2//"srf","Direct Albedo",0.2)
+        found=phyetat0_srf(falb_dif(:, isw,:),"A_dif_SW"//str2//"srf","Direct Albedo",0.2)
+     ENDDO
+  ENDDO
+
+  found=phyetat0_srf(u10m,"U10M","u a 10m",0.)
+  found=phyetat0_srf(v10m,"V10M","v a 10m",0.)
+
+!===================================================================
+  ! Lecture des temperatures du sol profond:
+!===================================================================
+
+   DO isoil=1, nsoilmx
+        IF (isoil.GT.99) THEN
+           PRINT*, "Trop de couches "
+           call abort_physic("phyetat0", "", 1)
+        ENDIF
+        WRITE(str2,'(i2.2)') isoil
+        found=phyetat0_srf(tsoil(:, isoil,:),"Tsoil"//str2//"srf","Temp soil",0.)
+        IF (.NOT. found) THEN
+           PRINT*, "phyetat0: Le champ <Tsoil"//str7//"> est absent"
+           PRINT*, "          Il prend donc la valeur de surface"
+           tsoil(:, isoil, :)=ftsol(:, :)
+        ENDIF
+   ENDDO
+
+!=======================================================================
+! Lecture precipitation/evaporation
+!=======================================================================
+
+  found=phyetat0_srf(qsurf,"QS","Near surface hmidity",0.)
+  found=phyetat0_get(qsol,"QSOL","Surface hmidity / bucket",0.)
+  found=phyetat0_srf(snow,"SNOW","Surface snow",0.)
+  found=phyetat0_srf(fevap,"EVAP","evaporation",0.)
+  found=phyetat0_get(snow_fall,"snow_f","snow fall",0.)
+  found=phyetat0_get(rain_fall,"rain_f","rain fall",0.)
+
+!=======================================================================
+! Radiation
+!=======================================================================
+
+  found=phyetat0_get(solsw,"solsw","net SW radiation surf",0.)
+  found=phyetat0_get(solswfdiff,"solswfdiff","fraction of SW radiation surf that is diffuse",1.)
+  found=phyetat0_get(sollw,"sollw","net LW radiation surf",0.)
+  found=phyetat0_get(sollwdown,"sollwdown","down LW radiation surf",0.)
+  IF (.NOT. found) THEN
+     sollwdown(:) = 0. ;  zts(:)=0.
+     DO nsrf=1,nbsrf
+        zts(:)=zts(:)+ftsol(:,nsrf)*pctsrf(:,nsrf)
+     ENDDO
+     sollwdown(:)=sollw(:)+RSIGMA*zts(:)**4
+  ENDIF
+
+  found=phyetat0_get(radsol,"RADS","Solar radiation",0.)
+  found=phyetat0_get(fder,"fder","Flux derivative",0.) 
+
+
+  ! Lecture de la longueur de rugosite 
+  found=phyetat0_srf(z0m,"RUG","Z0m ancien",0.001)
+  IF (found) THEN
+     z0h(:,1:nbsrf)=z0m(:,1:nbsrf)
+  ELSE
+     found=phyetat0_srf(z0m,"Z0m","Roughness length, momentum ",0.001)
+     found=phyetat0_srf(z0h,"Z0h","Roughness length, enthalpy ",0.001)
+  ENDIF
+!FC
+  IF (ifl_pbltree>0) THEN
+!CALL get_field("FTER", pctsrf(:, is_ter), found)
+    treedrg(:,1:klev,1:nbsrf)= 0.0
+    CALL get_field("treedrg_ter", drg_ter(:,:), found)
+!  found=phyetat0_srf(treedrg,"treedrg","drag from vegetation" , 0.)
+    !lecture du profile de freinage des arbres
+    IF (.not. found ) THEN
+      treedrg(:,1:klev,1:nbsrf)= 0.0
+    ELSE
+      treedrg(:,1:klev,is_ter)= drg_ter(:,:)
+!     found=phyetat0_get(treedrg,"treedrg","freinage arbres",0.)
+    ENDIF
+  ELSE
+    ! initialize treedrg(), because it will be written in restartphy.nc
+    treedrg(:,:,:) = 0.0 
+  ENDIF
+
+  ! Lecture de l'age de la neige:
+  found=phyetat0_srf(agesno,"AGESNO","SNOW AGE",0.001)
+
+  ancien_ok=.true.
+  ancien_ok=ancien_ok.AND.phyetat0_get(t_ancien,"TANCIEN","TANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(q_ancien,"QANCIEN","QANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(ql_ancien,"QLANCIEN","QLANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(qs_ancien,"QSANCIEN","QSANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(rneb_ancien,"RNEBANCIEN","RNEBANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(u_ancien,"UANCIEN","UANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(v_ancien,"VANCIEN","VANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(prw_ancien,"PRWANCIEN","PRWANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(prlw_ancien,"PRLWANCIEN","PRLWANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(prsw_ancien,"PRSWANCIEN","PRSWANCIEN",0.)
+
+  ! Ehouarn: addtional tests to check if t_ancien, q_ancien contain
+  !          dummy values (as is the case when generated by ce0l,
+  !          or by iniaqua)
+  IF ( (maxval(q_ancien).EQ.minval(q_ancien))       .OR. &
+       (maxval(ql_ancien).EQ.minval(ql_ancien))     .OR. &
+       (maxval(qs_ancien).EQ.minval(qs_ancien))     .OR. &
+       (maxval(rneb_ancien).EQ.minval(rneb_ancien)) .OR. &
+       (maxval(prw_ancien).EQ.minval(prw_ancien))   .OR. &
+       (maxval(prlw_ancien).EQ.minval(prlw_ancien)) .OR. &
+       (maxval(prsw_ancien).EQ.minval(prsw_ancien)) .OR. &
+       (maxval(t_ancien).EQ.minval(t_ancien)) ) THEN
+    ancien_ok=.false.
+  ENDIF
+
+  found=phyetat0_get(clwcon,"CLWCON","CLWCON",0.)
+  found=phyetat0_get(rnebcon,"RNEBCON","RNEBCON",0.)
+  found=phyetat0_get(ratqs,"RATQS","RATQS",0.)
+
+  found=phyetat0_get(run_off_lic_0,"RUNOFFLIC0","RUNOFFLIC0",0.)
+
+!==================================
+!  TKE
+!==================================
+!
+  IF (iflag_pbl>1) then
+     found=phyetat0_srf(pbl_tke,"TKE","Turb. Kinetic. Energ. ",1.e-8)
+  ENDIF
+
+  IF (iflag_pbl>1 .AND. iflag_wake>=1  .AND. iflag_pbl_split >=1 ) then
+    found=phyetat0_srf(wake_delta_pbl_tke,"DELTATKE","Del TKE wk/env",0.)
+!!    found=phyetat0_srf(delta_tsurf,"DELTA_TSURF","Delta Ts wk/env ",0.)
+    found=phyetat0_srf(delta_tsurf,"DELTATS","Delta Ts wk/env ",0.)
+!!    found=phyetat0_srf(beta_aridity,"BETA_S","Aridity factor ",1.)
+    found=phyetat0_srf(beta_aridity,"BETAS","Aridity factor ",1.)
+  ENDIF   !(iflag_pbl>1 .AND. iflag_wake>=1 .AND. iflag_pbl_split >=1 )
+
+!==================================
+!  thermiques, poches, convection
+!==================================
+
+! Emanuel
+  found=phyetat0_get(sig1,"sig1","sig1",0.)
+  found=phyetat0_get(w01,"w01","w01",0.)
+
+! Wake
+  found=phyetat0_get(wake_deltat,"WAKE_DELTAT","Delta T wake/env",0.)
+  found=phyetat0_get(wake_deltaq,"WAKE_DELTAQ","Delta hum. wake/env",0.)
+  found=phyetat0_get(wake_s,"WAKE_S","Wake frac. area",0.)
+!jyg<
+!  Set wake_dens to -1000. when there is no restart so that the actual
+!  initialization is made in calwake.
+!!  found=phyetat0_get(1,wake_dens,"WAKE_DENS","Wake num. /unit area",0.)
+  found=phyetat0_get(wake_dens,"WAKE_DENS","Wake num. /unit area",-1000.)
+  found=phyetat0_get(awake_dens,"AWAKE_DENS","Active Wake num. /unit area",0.)
+  found=phyetat0_get(cv_gen,"CV_GEN","CB birth rate",0.)
+!>jyg
+  found=phyetat0_get(wake_cstar,"WAKE_CSTAR","WAKE_CSTAR",0.)
+  found=phyetat0_get(wake_pe,"WAKE_PE","WAKE_PE",0.)
+  found=phyetat0_get(wake_fip,"WAKE_FIP","WAKE_FIP",0.)
+
+! Thermiques
+  found=phyetat0_get(zmax0,"ZMAX0","ZMAX0",40.)
+  found=phyetat0_get(f0,"F0","F0",1.e-5)
+  found=phyetat0_get(fm_therm,"FM_THERM","Thermals mass flux",0.)
+  found=phyetat0_get(entr_therm,"ENTR_THERM","Thermals Entrain.",0.)
+  found=phyetat0_get(detr_therm,"DETR_THERM","Thermals Detrain.",0.)
+
+! ALE/ALP
+  found=phyetat0_get(ale_bl,"ALE_BL","ALE BL",0.)
+  found=phyetat0_get(ale_bl_trig,"ALE_BL_TRIG","ALE BL_TRIG",0.)
+  found=phyetat0_get(alp_bl,"ALP_BL","ALP BL",0.)
+  found=phyetat0_get(ale_wake,"ALE_WAKE","ALE_WAKE",0.)
+  found=phyetat0_get(ale_bl_stat,"ALE_BL_STAT","ALE_BL_STAT",0.)
+
+! fisrtilp/Clouds 0.002 could be ratqsbas. But can stay like this as well
+  found=phyetat0_get(ratqs_inter,"RATQS_INTER","Relative width of the lsc sugrid scale water",0.002)
+
+!===========================================
+  ! Read and send field trs to traclmdz
+!===========================================
+
+!--OB now this is for co2i - ThL: and therefore also for inco
+  IF (ANY(type_trac == ['co2i','inco'])) THEN
+     IF (carbon_cycle_cpl) THEN
+        ALLOCATE(co2_send(klon), stat=ierr)
+        IF (ierr /= 0) CALL abort_physic('phyetat0', 'pb allocation co2_send', 1)
+        found=phyetat0_get(co2_send,"co2_send","co2 send",co2_ppm0)
+     ENDIF
+  ELSE IF (type_trac == 'lmdz') THEN
+     it = 0
+     DO iq = 1, nqtot
+        IF(.NOT.(tracers(iq)%isAdvected .AND. tracers(iq)%isInPhysics)) CYCLE
+        it = it+1
+        tname = tracers(iq)%name
+        t(1) = 'trs_'//TRIM(tname); t(2) = 'trs_'//TRIM(new2oldH2O(tname))
+        found = phyetat0_get(trs(:,it), t(:), "Surf trac"//TRIM(tname), 0.)
+     END DO
+     CALL traclmdz_from_restart(trs)
+  ENDIF
+
+
+!===========================================
+!  ondes de gravite / relief
+!===========================================
+
+!  ondes de gravite non orographiques
+  IF (ok_gwd_rando) found = &
+       phyetat0_get(du_gwd_rando,"du_gwd_rando","du_gwd_rando",0.)
+  IF (.NOT. ok_hines .AND. ok_gwd_rando) found &
+       = phyetat0_get(du_gwd_front,"du_gwd_front","du_gwd_front",0.)
+
+!  prise en compte du relief sous-maille
+  found=phyetat0_get(zmea,"ZMEA","sub grid orography",0.)
+  found=phyetat0_get(zstd,"ZSTD","sub grid orography",0.)
+  found=phyetat0_get(zsig,"ZSIG","sub grid orography",0.)
+  found=phyetat0_get(zgam,"ZGAM","sub grid orography",0.)
+  found=phyetat0_get(zthe,"ZTHE","sub grid orography",0.)
+  found=phyetat0_get(zpic,"ZPIC","sub grid orography",0.)
+  found=phyetat0_get(zval,"ZVAL","sub grid orography",0.)
+  found=phyetat0_get(zmea,"ZMEA","sub grid orography",0.)
+  found=phyetat0_get(rugoro,"RUGSREL","sub grid orography",0.)
+
+!===========================================
+! Initialize ocean
+!===========================================
+
+  IF ( type_ocean == 'slab' ) THEN
+      CALL ocean_slab_init(phys_tstep, pctsrf)
+      IF (nslay.EQ.1) THEN
+        found=phyetat0_get(tslab,["tslab01","tslab  "],"tslab",0.)
+      ELSE
+          DO i=1,nslay
+            WRITE(str2,'(i2.2)') i
+            found=phyetat0_get(tslab(:,i),"tslab"//str2,"tslab",0.)  
+          ENDDO
+      ENDIF
+      IF (.NOT. found) THEN 
+          PRINT*, "phyetat0: Le champ <tslab> est absent"
+          PRINT*, "Initialisation a tsol_oce"
+          DO i=1,nslay
+              tslab(:,i)=MAX(ftsol(:,is_oce),271.35)
+          ENDDO
+      ENDIF 
+
+      ! Sea ice variables
+      IF (version_ocean == 'sicINT') THEN
+          found=phyetat0_get(tice,"slab_tice","slab_tice",0.)
+          IF (.NOT. found) THEN 
+              PRINT*, "phyetat0: Le champ <tice> est absent"
+              PRINT*, "Initialisation a tsol_sic"
+                  tice(:)=ftsol(:,is_sic)
+          ENDIF 
+          found=phyetat0_get(seaice,"seaice","seaice",0.)
+          IF (.NOT. found) THEN
+              PRINT*, "phyetat0: Le champ <seaice> est absent"
+              PRINT*, "Initialisation a 0/1m suivant fraction glace"
+              seaice(:)=0.
+              WHERE (pctsrf(:,is_sic).GT.EPSFRA)
+                  seaice=917.
+              ENDWHERE
+          ENDIF
+      ENDIF !sea ice INT
+  ENDIF ! Slab        
+
+  if (activate_ocean_skin >= 1) then
+     if (activate_ocean_skin == 2 .and. type_ocean == 'couple') then
+        found = phyetat0_get(delta_sal, "delta_sal", &
+             "ocean-air interface salinity minus bulk salinity", 0.)
+        found = phyetat0_get(delta_sst, "delta_SST", &
+             "ocean-air interface temperature minus bulk SST", 0.)
+        found = phyetat0_get(dter, "dter", &
+             "ocean-air interface temperature minus subskin temperature", 0.)
+        found = phyetat0_get(dser, "dser", &
+             "ocean-air interface salinity minus subskin salinity", 0.)
+        found = phyetat0_get(dt_ds, "dt_ds", "(tks / tkt) * dTer", 0.)
+
+        where (pctsrf(:, is_oce) == 0.)
+           delta_sst = missing_val
+           delta_sal = missing_val
+           dter = missing_val
+           dser = missing_val
+           dt_ds = missing_val
+        end where
+     end if
+     
+     found = phyetat0_get(ds_ns, "dS_ns", "delta salinity near surface", 0.)
+     found = phyetat0_get(dt_ns, "dT_ns", "delta temperature near surface", &
+          0.)
+
+     where (pctsrf(:, is_oce) == 0.)
+        ds_ns = missing_val
+        dt_ns = missing_val
+        delta_sst = missing_val
+        delta_sal = missing_val
+     end where
+  end if
+
+  ! on ferme le fichier
+  CALL close_startphy
+
+  ! Initialize module pbl_surface_mod 
+
+  CALL pbl_surface_init(fder, snow, qsurf, tsoil)
+
+  ! Initialize module ocean_cpl_mod for the case of coupled ocean
+  IF ( type_ocean == 'couple' ) THEN
+     CALL ocean_cpl_init(phys_tstep, longitude_deg, latitude_deg)
+  ENDIF
+
+!  CALL init_iophy_new(latitude_deg, longitude_deg)
+
+  ! Initilialize module fonte_neige_mod      
+  CALL fonte_neige_init(run_off_lic_0)
+
+END SUBROUTINE phyetat0
+
+END MODULE phyetat0_mod
+
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyredem.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyredem.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phyredem.F90	(revision 4482)
@@ -30,11 +30,11 @@
                                 du_gwd_rando, du_gwd_front, u10m, v10m, &
                                 treedrg, solswfdiff, delta_sal, ds_ns, dt_ns, &
-                                delta_sst, ratqs_inter
+                                delta_sst, ratqs_inter, dter, dser, dt_ds
 
   USE geometry_mod, ONLY : longitude_deg, latitude_deg
   USE iostart, ONLY: open_restartphy, close_restartphy, enddef_restartphy, put_field, put_var
   USE traclmdz_mod, ONLY : traclmdz_to_restart
-  USE infotrac_phy, ONLY: types_trac, nqtot, tracers, nbtr
-  USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send
+  USE infotrac_phy, ONLY: type_trac, nqtot, tracers, nbtr
+  USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send, carbon_cycle_rad, RCO2_glo
   USE indice_sol_mod, ONLY: nbsrf, is_oce, is_sic, is_ter, is_lic, epsfra
   USE surface_data, ONLY: type_ocean, version_ocean
@@ -108,5 +108,10 @@
 
   ! co2_ppm0 : initial value of atmospheric CO2
-  tab_cntrl(16) = co2_ppm0
+  ! tab_cntrl(16) = co2_ppm0
+
+  !  PC -- initial value of RCO2 for the radiation scheme
+  !  tab_cntrl(17) = co2_ppm * 1.0e-06 * RMCO2 / RMD
+  IF (carbon_cycle_rad) tab_cntrl(17) = RCO2_glo
+  !PRINT*, "PC : phyredem RCO2_glo =",RCO2_glo
 
   DO pass=1,2   ! pass=1 netcdf definition ; pass=2 netcdf write
@@ -140,5 +145,4 @@
 
     CALL put_field(pass,"FLIC", "fraction glace de terre", pctsrf(:, is_lic))
-
     ! 3. fraction ocean
 
@@ -325,5 +329,5 @@
 
 
-    IF (ANY(types_trac == 'co2i') .OR. ANY(types_trac == 'inco')) THEN
+    IF (ANY(type_trac == ['co2i','inco'])) THEN
        IF (carbon_cycle_cpl) THEN
           IF (.NOT. ALLOCATED(co2_send)) THEN
@@ -336,5 +340,5 @@
 
     ! trs from traclmdz_mod
-    ELSE IF (ANY(types_trac == 'lmdz')) THEN
+    ELSE IF (type_trac == 'lmdz') THEN
        CALL traclmdz_to_restart(trs)
        it = 0
@@ -374,4 +378,11 @@
           CALL put_field(pass, "delta_SST", &
                "ocean-air interface temperature minus bulk SST", delta_sst)
+          CALL put_field(pass, "dter", &
+               "ocean-air interface temperature minus subskin temperature", &
+               dter)
+          CALL put_field(pass, "dser", &
+               "ocean-air interface salinity minus subskin salinity", dser)
+          CALL put_field(pass, "dt_ds", &
+               "(tks / tkt) * dTer", dt_ds)
        end if
        
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_cal_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_cal_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_cal_mod.F90	(revision 4482)
@@ -51,5 +51,5 @@
     IF (is_omp_master) THEN
       IF (calend == 'earth_360d') THEN
-        CALL ioconf_calendar('360d')
+        CALL ioconf_calendar('360_day')
       ELSE IF (calend == 'earth_365d') THEN
         CALL ioconf_calendar('noleap')
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4482)
@@ -1413,7 +1413,7 @@
     'ec550aer', 'Extinction at 550nm', 'm^-1', (/ ('', i=1, 10) /))
   TYPE(ctrl_out), SAVE :: o_lwcon = ctrl_out((/ 2, 5, 10, 10, 10, 10, 11, 11, 11, 11/), &
-    'lwcon', 'Cloud liquid water content', 'kg/kg', (/ ('', i=1, 10) /))
+    'lwcon', 'Cloud liquid water content seen by radiation', 'kg/kg', (/ ('', i=1, 10) /))
   TYPE(ctrl_out), SAVE :: o_iwcon = ctrl_out((/ 2, 5, 10, 10, 10, 10, 11, 11, 11, 11/), &
-    'iwcon', 'Cloud ice water content', 'kg/kg', (/ ('', i=1, 10) /))
+    'iwcon', 'Cloud ice water content seen by radiation', 'kg/kg', (/ ('', i=1, 10) /))
   TYPE(ctrl_out), SAVE :: o_temp = ctrl_out((/ 2, 3, 4, 10, 10, 10, 11, 11, 11, 11/), &
     'temp', 'Air temperature', 'K', (/ ('', i=1, 10) /))
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_mod.F90	(revision 4482)
@@ -45,5 +45,5 @@
     USE mod_grid_phy_lmdz, only: klon_glo,nbp_lon,nbp_lat
     USE print_control_mod, ONLY: prt_level,lunout
-    USE vertical_layers_mod, ONLY: ap,bp,preff,presnivs, aps, bps, pseudoalt
+    USE vertical_layers_mod, ONLY: ap,bp,preff,presnivs, aps, bps, pseudoalt, presinter
     USE time_phylmdz_mod, ONLY: day_ini, itau_phy, start_time, annee_ref, day_ref
 #ifdef CPP_XIOS
@@ -347,4 +347,6 @@
     CALL wxios_add_vaxis("presnivs", &
             levmax(iff) - levmin(iff) + 1, presnivs(levmin(iff):levmax(iff)))
+    CALL wxios_add_vaxis("presinter", &
+            klev + 1, presinter(1:klev+1))
     CALL wxios_add_vaxis("Ahyb", &
             levmax(iff) - levmin(iff) + 1, aps(levmin(iff):levmax(iff)), positif='down', &
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_var_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_var_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_var_mod.F90	(revision 4482)
@@ -135,25 +135,17 @@
   ! Ocean-atmosphere interface, subskin ocean and near-surface ocean:
   
-  REAL, ALLOCATABLE, SAVE:: dter(:)
-  ! Temperature variation in the diffusive microlayer, that is
-  ! ocean-air interface temperature minus subskin temperature. In K.
-      
-  REAL, SAVE, ALLOCATABLE:: dser(:)
-  ! Temperature variation in the diffusive microlayer, that is
-  ! subskin temperature minus ocean-air interface temperature. In K.
-
-  REAL, SAVE, ALLOCATABLE:: tkt(:)
+  REAL, SAVE, ALLOCATABLE:: tkt(:) ! (klon)
   ! épaisseur (m) de la couche de diffusion thermique (microlayer)
   ! cool skin thickness
 
-  REAL, SAVE, ALLOCATABLE:: tks(:)
+  REAL, SAVE, ALLOCATABLE:: tks(:) ! (klon)
   ! épaisseur (m) de la couche de diffusion de masse (microlayer)
   
-  REAL, SAVE, ALLOCATABLE:: taur(:) ! momentum flux due to rain, in Pa
-
-  REAL, SAVE, ALLOCATABLE:: sss(:)
+  REAL, SAVE, ALLOCATABLE:: taur(:) ! (klon) momentum flux due to rain, in Pa
+
+  REAL, SAVE, ALLOCATABLE:: sss(:) ! (klon)
   ! bulk salinity of the surface layer of the ocean, in ppt
   
-  !$OMP THREADPRIVATE(dter, dser, tkt, tks, taur, sss)
+  !$OMP THREADPRIVATE(tkt, tks, taur, sss)
 
 CONTAINS
@@ -216,6 +208,6 @@
     IF (ok_gwd_rando) allocate(zustr_gwd_rando(klon), zvstr_gwd_rando(klon))
 
-    if (activate_ocean_skin >= 1) allocate(dter(klon), dser(klon), tkt(klon), &
-         tks(klon), taur(klon), sss(klon))
+    if (activate_ocean_skin >= 1) allocate(tkt(klon), tks(klon), taur(klon), &
+         sss(klon))
 
   END SUBROUTINE phys_output_var_init
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_write_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_write_mod.F90	(revision 4482)
@@ -25,5 +25,5 @@
 
     USE dimphy, ONLY: klon, klev, klevp1
-    USE infotrac_phy, ONLY: nbtr, nqtot, nqo, types_trac, tracers, niso, ntiso
+    USE infotrac_phy, ONLY: nbtr, nqtot, nqo, type_trac, tracers, niso, ntiso
     USE strings_mod,  ONLY: maxlen
     USE mod_phys_lmdz_para, ONLY: is_north_pole_phy,is_south_pole_phy
@@ -271,5 +271,5 @@
         xtrain_con, xtsnow_con, xtrain_fall, xtsnow_fall, &
 #endif
-         dt_ns, delta_sst
+         dt_ns, delta_sst, dter, dser
 
     USE phys_local_var_mod, ONLY: zxfluxlat, slp, ptstar, pt0, zxtsol, zt2m, &
@@ -390,5 +390,5 @@
          alt_tropo, &
 !Ionela
-         ok_4xCO2atm, dter, dser, tkt, tks, taur, sss
+         ok_4xCO2atm, tkt, tks, taur, sss
 
     USE ocean_slab_mod, ONLY: nslay, tslab, slab_bilg, tice, seaice, &
@@ -481,4 +481,5 @@
 #ifdef CPP_StratAer 
     LOGICAL, PARAMETER :: debug_strataer=.FALSE.
+    CHARACTER(LEN=maxlen) :: unt
 #endif
     REAL,DIMENSION(klon,klev) :: z, dz
@@ -942,5 +943,5 @@
        CALL histwrite_phy(o_SWupTOAclr, zx_tmp_fi2d)
 
-       IF (ALL(types_trac/='inca') .OR. config_inca=='aeNP') THEN 
+       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN 
           IF (vars_defined) THEN
              zx_tmp_fi2d(:) = swupc0(:,klevp1)*swradcorr(:)
@@ -1014,5 +1015,5 @@
        CALL histwrite_phy(o_SWupSFCclr, zx_tmp_fi2d)
 
-       IF (ALL(types_trac/='inca') .OR. config_inca=='aeNP') THEN 
+       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN 
           IF (vars_defined) THEN
              zx_tmp_fi2d(:) = swupc0(:,1)*swradcorr(:)
@@ -1031,5 +1032,5 @@
        CALL histwrite_phy(o_SWdnSFCclr, zx_tmp_fi2d)
 
-       IF (ALL(types_trac/='inca') .OR. config_inca=='aeNP') THEN 
+       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN 
           IF (vars_defined) THEN
              zx_tmp_fi2d(:) = swdnc0(:,1)*swradcorr(:)
@@ -1053,5 +1054,5 @@
        CALL histwrite_phy(o_LWdnSFCclr, sollwdownclr)
 
-       IF (ALL(types_trac/='inca') .OR. config_inca=='aeNP') THEN 
+       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN 
           IF (vars_defined) THEN
              zx_tmp_fi2d(:) = lwupc0(:,klevp1)
@@ -1060,5 +1061,5 @@
        ENDIF
 
-       IF (ALL(types_trac/='inca') .OR. config_inca=='aeNP') THEN 
+       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN 
           IF (vars_defined) THEN
              zx_tmp_fi2d(:) = -1.*lwdnc0(:,1)
@@ -1570,5 +1571,5 @@
 #ifndef CPP_ECRAD
        IF (flag_aerosol.GT.0) THEN
-          IF (ALL(types_trac/='inca') .OR. config_inca=='aeNP') THEN 
+          IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN 
 
              CALL histwrite_phy(o_od443aer, od443aer)
@@ -1634,5 +1635,5 @@
 
 #ifdef CPP_StratAer
-       IF (ANY(types_trac=='coag')) THEN
+       IF (type_trac=='coag') THEN
           CALL histwrite_phy(o_R2SO4, R2SO4)
           CALL histwrite_phy(o_OCS_lifetime, OCS_lifetime)
@@ -1693,5 +1694,5 @@
           CALL histwrite_phy(o_solswad0, zx_tmp_fi2d)
           
-          IF (ALL(types_trac/='inca') .OR. config_inca=='aeNP') THEN 
+          IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN 
 
              CALL histwrite_phy(o_toplwad, toplwad_aero)
@@ -1770,5 +1771,5 @@
        ! Champs 3D:
        IF (ok_ade .OR. ok_aie) then
-          IF (ALL(types_trac/='inca') .OR. config_inca=='aeNP') THEN 
+          IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN 
              CALL histwrite_phy(o_ec550aer, ec550aer)
           ENDIF
@@ -2231,5 +2232,5 @@
        CALL histwrite_phy(o_rsucs, zx_tmp_fi3d1)
 
-       IF (ALL(types_trac/='inca') .OR. config_inca=='aeNP') THEN 
+       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN 
           IF (vars_defined) THEN
              DO k=1, klevp1
@@ -2247,5 +2248,5 @@
        CALL histwrite_phy(o_rsdcs, zx_tmp_fi3d1)
 
-       IF (ALL(types_trac/='inca') .OR. config_inca=='aeNP') THEN 
+       IF (type_trac/='inca' .OR. config_inca=='aeNP') THEN 
           IF (vars_defined) THEN
              DO k=1, klevp1
@@ -2493,5 +2494,5 @@
        IF (iflag_phytrac == 1 ) then
 !
-         IF (ANY(types_trac == 'co2i')) THEN
+         IF (type_trac == 'co2i') THEN
            itr = 0
            DO iq = 1, nqtot
@@ -2522,5 +2523,5 @@
            CALL histwrite_phy(o_flx_co2_bb,    fco2_bb)
 
-         ELSE IF (ANY(types_trac == 'inco')) THEN
+         ELSE IF (type_trac == 'inco') THEN
            itr = 0
            DO iq = 1, nqtot
@@ -2551,5 +2552,5 @@
            CALL histwrite_phy(o_flx_co2_bb,    fco2_bb)
 
-         ELSE IF ((ANY(types_trac=='lmdz') .OR. ANY(types_trac=='coag')) .AND. ALL(types_trac /= 'inca')) THEN
+         ELSE IF (ANY(type_trac==['lmdz','coag'])) THEN
            itr = 0
            DO iq = 1, nqtot
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_state_var_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_state_var_mod.F90	(revision 4482)
@@ -489,5 +489,16 @@
       ! Ocean-air interface salinity minus bulk salinity, in ppt
       
-      !$OMP THREADPRIVATE(delta_sal, ds_ns, dt_ns, delta_sst)
+      REAL, ALLOCATABLE, SAVE:: dter(:) ! (klon)
+      ! Temperature variation in the diffusive microlayer, that is
+      ! ocean-air interface temperature minus subskin temperature. In K.
+
+      REAL, SAVE, ALLOCATABLE:: dser(:) ! (klon)
+      ! Salinity variation in the diffusive microlayer, that is
+      ! ocean-air interface salinity minus subskin salinity. In ppt.
+
+      real, SAVE, ALLOCATABLE:: dt_ds(:) ! (klon)
+      ! (tks / tkt) * dTer, in K
+
+      !$OMP THREADPRIVATE(delta_sal, ds_ns, dt_ns, delta_sst, dter, dser, dt_ds)
 
     CONTAINS
@@ -503,4 +514,5 @@
 USE indice_sol_mod
 use config_ocean_skin_m, only: activate_ocean_skin
+use surface_data, only: type_ocean
 IMPLICIT NONE
 
@@ -560,4 +572,8 @@
       ALLOCATE(coefh(klon,klev+1,nbsrf+1))
       ALLOCATE(coefm(klon,klev+1,nbsrf+1))
+      ! initialize cleanly coefh,coefm
+      ! (most of the time in the code these are assumed to be on klev levels)
+      coefh(:,:,:)=0
+      coefm(:,:,:)=0
       ALLOCATE(zmax0(klon), f0(klon))
       ALLOCATE(sig1(klon,klev), w01(klon,klev))
@@ -722,6 +738,11 @@
         du_gwd_front(:,:) = 0 !ym missing init   
       ENDIF
-      if (activate_ocean_skin >= 1) ALLOCATE(delta_sal(klon), ds_ns(klon), &
-           dt_ns(klon), delta_sst(klon))
+
+      if (activate_ocean_skin >= 1) then
+         ALLOCATE(delta_sal(klon), ds_ns(klon), dt_ns(klon), delta_sst(klon), &
+              dter(klon), dser(klon))
+         if (activate_ocean_skin == 2 .and. type_ocean == "couple") &
+              allocate(dt_ds(klon))
+      end if
 
     END SUBROUTINE phys_state_var_init
@@ -733,4 +754,5 @@
 USE indice_sol_mod
 use config_ocean_skin_m, only: activate_ocean_skin
+use surface_data, only: type_ocean
 IMPLICIT NONE
 include "clesphys.h"
@@ -861,6 +883,9 @@
       DEALLOCATE(ratqs_inter)
 
-      if (activate_ocean_skin >= 1) deALLOCATE(delta_sal, ds_ns, dt_ns, &
-           delta_sst)
+      if (activate_ocean_skin >= 1) then
+         deALLOCATE(delta_sal, ds_ns, dt_ns, delta_sst, dter, dser)
+         if (activate_ocean_skin == 2 .and. type_ocean == "couple") &
+              deALLOCATE(dt_ds)
+      end if
 
 #ifdef ISO    
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/physiq_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/physiq_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/physiq_mod.F90	(revision 4482)
@@ -34,11 +34,10 @@
     USE FLOTT_GWD_rando_m, only: FLOTT_GWD_rando
     USE fonte_neige_mod, ONLY  : fonte_neige_get_vars
-    USE geometry_mod, ONLY: cell_area, latitude_deg, longitude_deg, longitude,latitude, &
-         boundslon,boundslat, dx, dy, ind_cell_glo
+    USE geometry_mod, ONLY: cell_area, latitude_deg, longitude_deg
     USE ioipsl, only: histbeg, histvert, histdef, histend, histsync, &
          histwrite, ju2ymds, ymds2ju, getin
     USE ioipsl_getin_p_mod, ONLY : getin_p
     USE indice_sol_mod
-    USE infotrac_phy, ONLY: nqtot, nbtr, nqo, tracers, types_trac, nqCO2
+    USE infotrac_phy, ONLY: nqtot, nbtr, nqo, tracers, type_trac
     USE readTracFiles_mod, ONLY: addPhase
     USE strings_mod,  ONLY: strIdx
@@ -54,4 +53,5 @@
     USE pbl_surface_mod, ONLY : pbl_surface
     USE phyaqua_mod, only: zenang_an
+    USE phyetat0_mod, only: phyetat0
     USE phystokenc_mod, ONLY: offline, phystokenc
     USE phys_cal_mod, only: year_len, mth_len, days_elapsed, jh_1jan, &
@@ -69,16 +69,20 @@
     USE regr_horiz_time_climoz_m, ONLY: regr_horiz_time_climoz
     USE regr_pr_time_av_m, only: regr_pr_time_av
-    USE surface_data,     ONLY : type_ocean, ok_veget, landice_opt
-    USE time_phylmdz_mod, only: annee_ref, current_time, day_ini, day_ref, &
-          day_step_phy, itau_phy, pdtphys, raz_date, start_time, update_time, ndays
+    USE surface_data,     ONLY : type_ocean, ok_veget
+    USE time_phylmdz_mod, only: current_time, itau_phy, pdtphys, raz_date, update_time
     USE tracinca_mod, ONLY: config_inca
     USE tropopause_m,     ONLY: dyn_tropopause
     USE ice_sursat_mod,  ONLY: flight_init, airplane
     USE vampir
-    USE VERTICAL_LAYERS_MOD, ONLY: aps,bps, ap, bp
     USE write_field_phy
+#ifdef CPP_XIOS
+    USE wxios, ONLY: g_ctx, wxios_set_context
+#endif
     USE lscp_mod, ONLY : lscp
     USE wake_ini_mod, ONLY : wake_ini
+    USE yamada_ini_mod, ONLY : yamada_ini
+    USE atke_turbulence_ini_mod, ONLY : atke_ini
     USE thermcell_ini_mod, ONLY : thermcell_ini
+    USE lscp_ini_mod, ONLY : lscp_ini
 
     !USE cmp_seri_mod
@@ -98,8 +102,16 @@
 
 
+#ifdef INCA
+    USE geometry_mod,      ONLY: longitude, latitude, boundslon, boundslat, ind_cell_glo
+    USE time_phylmdz_mod,  ONLY: ndays
+    USE infotrac_phy,      ONLY: nqCO2
+#endif
 #ifdef REPROBUS
-    USE CHEM_REP, ONLY : Init_chem_rep_xjour, &
-         d_q_rep,d_ql_rep,d_qi_rep,ptrop,ttrop, &
-         ztrop, gravit,itroprep, Z1,Z2,fac,B
+    USE chem_rep, ONLY: Init_chem_rep_xjour, d_q_rep, d_ql_rep, d_qi_rep, &
+                        ptrop, ttrop, ztrop, gravit, itroprep, Z1, Z2, fac, B
+#endif
+#if defined INCA || defined REPROBUS
+    USE time_phylmdz_mod,    ONLY: annee_ref, day_ini, day_ref, start_time
+    USE vertical_layers_mod, ONLY: aps, bps, ap, bp
 #endif
 
@@ -107,5 +119,5 @@
 #ifdef CPP_RRTM
     USE YOERAD, ONLY : NRADLP
-    USE YOESW, ONLY : RSUN
+!    USE YOESW, ONLY : RSUN
 #endif
 
@@ -117,6 +129,7 @@
 
 #ifdef CPP_XIOS
-    USE xios, ONLY: xios_update_calendar, xios_context_finalize, &
-            xios_get_field_attr, xios_field_is_active
+    USE xios, ONLY: xios_update_calendar, xios_context_finalize
+    USE xios, ONLY: xios_get_field_attr, xios_field_is_active, xios_context
+    USE xios, ONLY: xios_set_current_context
     USE wxios, ONLY: missing_val, missing_val_omp
 #endif
@@ -143,6 +156,6 @@
        d_t_ajsb,d_q_ajsb, &
        d_t_ajs,d_q_ajs,d_u_ajs,d_v_ajs, &
-       d_t_ajs_w,d_q_ajs_w, &
-       d_t_ajs_x,d_q_ajs_x, &
+!       d_t_ajs_w,d_q_ajs_w, &
+!       d_t_ajs_x,d_q_ajs_x, &
        !
        d_t_eva,d_q_eva,d_ql_eva,d_qi_eva, &
@@ -157,5 +170,5 @@
        d_ts, &
        !
-       d_t_oli,d_u_oli,d_v_oli, &
+!       d_t_oli,d_u_oli,d_v_oli, &
        d_t_oro,d_u_oro,d_v_oro, &
        d_t_oro_gw,d_u_oro_gw,d_v_oro_gw, &
@@ -276,4 +289,8 @@
        sij, &
        !
+       rneblsvol, &
+       zqsatl, zqsats, &
+       qclr, qcld, qss, qvc, rnebclr, rnebss, gamma_ss, &
+       Tcontr, qcontr, qcontr2, fcontrN, fcontrP, &
        cldemi,  &
        cldfra, cldtau, fiwc,  &
@@ -302,5 +319,4 @@
        zxsnow,snowhgt,qsnow,to_ice,sissnow,runoff,albsol3_lic
        !
-
 
     IMPLICIT NONE
@@ -515,5 +531,4 @@
     !
     !
-    INTEGER debug
     INTEGER n
     !ym      INTEGER npoints
@@ -572,5 +587,5 @@
     ! Upmost level reached by deep convection and related variable (jyg)
     !
-    INTEGER izero
+!    INTEGER izero
     INTEGER k_upper_cv
     !------------------------------------------------------------------
@@ -742,5 +757,4 @@
     REAL beta_prec_fisrt(klon,klev) ! taux de conv de l'eau cond (fisrt)
     ! RomP <<<
-    REAL          :: calday
 
     !IM cf FH pour Tiedtke 080604
@@ -796,5 +810,4 @@
     !C      EXTERNAL o3cm      ! initialiser l'ozone
     EXTERNAL orbite    ! calculer l'orbite terrestre
-    EXTERNAL phyetat0  ! lire l'etat initial de la physique
     EXTERNAL phyredem  ! ecrire l'etat de redemarrage de la physique
     EXTERNAL suphel    ! initialiser certaines constantes
@@ -817,5 +830,5 @@
     REAL dialiq(klon,klev)  ! eau liquide nuageuse
     REAL diafra(klon,klev)  ! fraction nuageuse
-    REAL cldliq(klon,klev)  ! eau liquide nuageuse
+    REAL radocond(klon,klev)  ! eau condensee nuageuse
     !
     !XXX PB 
@@ -840,7 +853,4 @@
     REAL conv_t(klon,klev) ! convergence de la temperature(K/s)
     !
-#ifdef INCA
-    REAL zxsnow_dummy(klon)
-#endif
     REAL zsav_tsol(klon)
     !
@@ -857,5 +867,5 @@
     real zqsat(klon,klev)
     !
-    INTEGER i, k, iq, j, nsrf, ll, l, itr
+    INTEGER i, k, iq, nsrf, l, itr
     !
     REAL t_coup
@@ -966,4 +976,5 @@
 
     REAL picefra(klon,klev)
+    REAL zrel_oro(klon)
     !IM cf. AM 081204 END
     !
@@ -1172,4 +1183,5 @@
 
 #ifdef INCA
+    REAL :: calday, zxsnow_dummy(klon)
     ! set de variables utilisees pour l'initialisation des valeurs provenant de INCA
     REAL, DIMENSION(klon,klev,naero_grp,nbands) :: init_tauinca
@@ -1217,5 +1229,9 @@
     phys_tstep=NINT(pdtphys)
 #ifdef CPP_XIOS
-    IF (.NOT. debut .AND. is_omp_master) CALL xios_update_calendar(itap+1)
+! switch to XIOS LMDZ physics context 
+    IF (.NOT. debut .AND. is_omp_master) THEN
+       CALL wxios_set_context()
+       CALL xios_update_calendar(itap+1)
+    ENDIF
 #endif
 
@@ -1287,6 +1303,4 @@
        CALL strataer_init
 #endif
-
-       !!CALL flight_init
 
        print*, '================================================='
@@ -1455,5 +1469,5 @@
        tau_overturning_th(:)=0.
 
-       IF (ANY(types_trac == 'inca') .OR. ANY(types_trac == 'inco')) THEN
+       IF (ANY(type_trac == ['inca','inco'])) THEN
           ! jg : initialisation jusqu'au ces variables sont dans restart
           ccm(:,:,:) = 0.
@@ -1734,7 +1748,11 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        CALL wake_ini(rg,rd,rv,prt_level)
+       CALL yamada_ini(klon,lunout,prt_level)
+       CALL atke_ini(prt_level, lunout, RG, RD, RPI, RCPD)
        CALL thermcell_ini(iflag_thermals,prt_level,tau_thermals,lunout, &
    &    RG,RD,RCPD,RKAPPA,RLVTT,RETV)
-
+       IF (ok_new_lscp) then
+           CALL lscp_ini(pdtphys,ok_ice_sursat)
+       endif
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -2022,5 +2040,5 @@
        !c         ENDDO
        !
-       IF (ANY(types_trac == 'inca') .OR. ANY(types_trac == 'inco')) THEN ! ModThL
+       IF (ANY(type_trac == ['inca','inco'])) THEN ! ModThL
 #ifdef INCA
           CALL VTe(VTphysiq)
@@ -2036,32 +2054,57 @@
                longitude, latitude, &
                boundslon, boundslat, &
-               dx, dy, cell_area, ind_cell_glo) 
-
-
-          CALL chemini(  pplay, &
-               nbp_lon, nbp_lat, &
-               latitude_deg, &
-               longitude_deg, &
-               presnivs, &
-               calday, &
-               klon, &
-               nqtot, &
-               nqo+nqCO2, &
-               pdtphys, &
-               annee_ref, &
-               year_cur, &
-               day_ref,  &
-               day_ini, &
-               start_time, &
-               itau_phy, &
-               date0, &
-               io_lon, &
-               io_lat, &
-               chemistry_couple, &
-               init_source, &
-               init_tauinca, &
-               init_pizinca, &
-               init_cginca, &
-               init_ccminca)
+               cell_area, ind_cell_glo) 
+
+          if (grid_type==unstructured) THEN 
+             CALL chemini(  pplay, &
+                  nbp_lon, nbp_lat, &
+                  latitude_deg, &
+                  longitude_deg, &
+                  presnivs, &
+                  calday, &
+                  klon, &
+                  nqtot, &
+                  nqo+nqCO2, &
+                  pdtphys, &
+                  annee_ref, &
+                  year_cur, &
+                  day_ref,  &
+                  day_ini, &
+                  start_time, &
+                  itau_phy, &
+                  date0, &
+                  chemistry_couple, &
+                  init_source, &
+                  init_tauinca, &
+                  init_pizinca, &
+                  init_cginca, &
+                  init_ccminca)
+          ELSE
+             CALL chemini(  pplay, &
+                  nbp_lon, nbp_lat, &
+                  latitude_deg, &
+                  longitude_deg, &
+                  presnivs, &
+                  calday, &
+                  klon, &
+                  nqtot, &
+                  nqo+nqCO2, &
+                  pdtphys, &
+                  annee_ref, &
+                  year_cur, &
+                  day_ref,  &
+                  day_ini, &
+                  start_time, &
+                  itau_phy, &
+                  date0, &
+                  chemistry_couple, &
+                  init_source, &
+                  init_tauinca, &
+                  init_pizinca, &
+                  init_cginca, &
+                  init_ccminca, &
+                  io_lon, &
+                  io_lat)
+          ENDIF
 
 
@@ -2079,5 +2122,5 @@
        ENDIF
        !
-       IF (ANY(types_trac == 'repr')) THEN
+       IF (type_trac == 'repr') THEN
 #ifdef REPROBUS
           CALL chemini_rep(  &
@@ -2192,5 +2235,5 @@
 
     ! Update time and other variables in Reprobus
-    IF (ANY(types_trac == 'repr')) THEN
+    IF (type_trac == 'repr') THEN
 #ifdef REPROBUS
        CALL Init_chem_rep_xjour(jD_cur-jD_ref+day_ref)
@@ -2983,5 +3026,5 @@
           !
           !>jyg
-          IF (ANY(types_trac == 'repr')) THEN
+          IF (type_trac == 'repr') THEN
              nbtr_tmp=ntra
           ELSE
@@ -3596,13 +3639,14 @@
     ENDIF
 
-    CALL lscp(phys_tstep,missing_val,paprs,pplay, &
+    CALL lscp(klon,klev,phys_tstep,missing_val,paprs,pplay, &
          t_seri, q_seri,ptconv,ratqs, &
-         d_t_lsc, d_q_lsc, d_ql_lsc, d_qi_lsc, rneb, rneb_seri, & 
-         cldliq, picefra, rain_lsc, snow_lsc, &
-         pfrac_impa, pfrac_nucl, pfrac_1nucl, &
+         d_t_lsc, d_q_lsc, d_ql_lsc, d_qi_lsc, rneb, rneblsvol, rneb_seri, & 
+         radocond, picefra, rain_lsc, snow_lsc, &
          frac_impa, frac_nucl, beta_prec_fisrt, &
          prfl, psfl, rhcl,  &
          zqasc, fraca,ztv,zpspsk,ztla,zthl,iflag_cld_th, &
-         iflag_ice_thermo, ok_ice_sursat)
+         iflag_ice_thermo, ok_ice_sursat, zqsatl, zqsats, &
+         qclr, qcld, qss, qvc, rnebclr, rnebss, gamma_ss, &
+         Tcontr, qcontr, qcontr2, fcontrN, fcontrP )
 
     ELSE
@@ -3610,5 +3654,5 @@
     CALL fisrtilp(phys_tstep,paprs,pplay, &
          t_seri, q_seri,ptconv,ratqs, &
-         d_t_lsc, d_q_lsc, d_ql_lsc, d_qi_lsc, rneb, cldliq, &
+         d_t_lsc, d_q_lsc, d_ql_lsc, d_qi_lsc, rneb, radocond, &
          rain_lsc, snow_lsc, &
          pfrac_impa, pfrac_nucl, pfrac_1nucl, &
@@ -3657,5 +3701,5 @@
           cldfra(i,k) = rneb(i,k)
           !CR: a quoi ca sert? Faut-il ajouter qs_seri?
-          IF (.NOT.new_oliq) cldliq(i,k) = ql_seri(i,k)
+          IF (.NOT.new_oliq) radocond(i,k) = ql_seri(i,k)
        ENDDO
     ENDDO
@@ -3721,5 +3765,5 @@
           DO i = 1, klon
              IF (diafra(i,k).GT.cldfra(i,k)) THEN
-                cldliq(i,k) = dialiq(i,k)
+                radocond(i,k) = dialiq(i,k)
                 cldfra(i,k) = diafra(i,k)
              ENDIF
@@ -3758,9 +3802,9 @@
                 DO i=1,klon
                    IF (ptconv(i,k).AND.ptconvth(i,k)) THEN
-                      cldliq(i,k)=cldliq(i,k)+rnebcon(i,k)*clwcon(i,k)
+                      radocond(i,k)=radocond(i,k)+rnebcon(i,k)*clwcon(i,k)
                       cldfra(i,k)=min(cldfra(i,k)+rnebcon(i,k),1.)
                    ELSE IF (ptconv(i,k)) THEN
                       cldfra(i,k)=rnebcon(i,k)
-                      cldliq(i,k)=rnebcon(i,k)*clwcon(i,k)
+                      radocond(i,k)=rnebcon(i,k)*clwcon(i,k)
                    ENDIF
                 ENDDO
@@ -3771,5 +3815,5 @@
                 DO i=1,klon
                    cldfra(i,k)=min(cldfra(i,k)+rnebcon(i,k),1.)
-                   cldliq(i,k)=cldliq(i,k)+rnebcon(i,k)*clwcon(i,k)
+                   radocond(i,k)=radocond(i,k)+rnebcon(i,k)*clwcon(i,k)
                 ENDDO
              ENDDO
@@ -3789,5 +3833,5 @@
                    IF (ptconv(i,k).AND. .NOT.ptconvth(i,k)) THEN
                       cldfra(i,k)=rnebcon(i,k)
-                      cldliq(i,k)=rnebcon(i,k)*clwcon(i,k)
+                      radocond(i,k)=rnebcon(i,k)*clwcon(i,k)
                    ENDIF
                 ENDDO
@@ -3800,5 +3844,5 @@
           ! Ancienne version
           cldfra(:,:)=min(max(cldfra(:,:),rnebcon(:,:)),1.)
-          cldliq(:,:)=cldliq(:,:)+rnebcon(:,:)*clwcon(:,:)
+          radocond(:,:)=radocond(:,:)+rnebcon(:,:)*clwcon(:,:)
        ENDIF
 
@@ -3820,5 +3864,5 @@
           DO i = 1, klon
              IF (diafra(i,k).GT.cldfra(i,k)) THEN
-                cldliq(i,k) = dialiq(i,k)
+                radocond(i,k) = dialiq(i,k)
                 cldfra(i,k) = diafra(i,k)
              ENDIF
@@ -3888,5 +3932,5 @@
     ENDDO
 
-    IF (ANY(types_trac == 'inca') .OR. ANY(types_trac == 'inco')) THEN ! ModThL
+    IF (ANY(type_trac == ['inca','inco'])) THEN ! ModThL
 #ifdef INCA
        CALL VTe(VTphysiq)
@@ -3944,5 +3988,5 @@
 #endif
     ENDIF !type_trac = inca or inco
-    IF (ANY(types_trac == 'repr')) THEN
+    IF (type_trac == 'repr') THEN
 #ifdef REPROBUS
     !CALL chemtime_rep(itap+itau_phy-1, date0, dtime, itap)
@@ -4143,5 +4187,5 @@
           ENDIF
           CALL newmicro (flag_aerosol, ok_cdnc, bl95_b0, bl95_b1, &
-               paprs, pplay, t_seri, cldliq, picefra, cldfra, &
+               paprs, pplay, t_seri, radocond, picefra, cldfra, &
                cldtau, cldemi, cldh, cldl, cldm, cldt, cldq, &
                flwp, fiwp, flwc, fiwc, &
@@ -4151,5 +4195,5 @@
        ELSE
           CALL nuage (paprs, pplay, &
-               t_seri, cldliq, picefra, cldfra, cldtau, cldemi, &
+               t_seri, radocond, picefra, cldfra, cldtau, cldemi, &
                cldh, cldl, cldm, cldt, cldq, &
                ok_aie, &
@@ -4287,7 +4331,5 @@
           ! 
           !--interactive CO2 in ppm from carbon cycle
-          IF (carbon_cycle_rad.AND..NOT.debut) THEN
-            RCO2=RCO2_glo
-          ENDIF
+          IF (carbon_cycle_rad) RCO2=RCO2_glo
           !
           IF (prt_level .GE.10) THEN
@@ -4345,16 +4387,4 @@
  
 #ifndef CPP_XIOS
-          !--OB 30/05/2016 modified 21/10/2016
-          !--here we return swaero_diag and dryaod_diag to FALSE
-          !--and histdef will switch it back to TRUE if necessary
-          !--this is necessary to get the right swaero at first step
-          !--but only in the case of no XIOS as XIOS is covered elsewhere 
-          IF (debut) swaerofree_diag = .FALSE.
-          IF (debut) swaero_diag = .FALSE.
-          IF (debut) dryaod_diag = .FALSE.
-          !--IM 15/09/2017 here we return ok_4xCO2atm to FALSE
-          !--as for swaero_diag, see above
-          IF (debut) ok_4xCO2atm = .FALSE.
-
           !
           !IM 2eme calcul radiatif pour le cas perturbe ou au moins un
@@ -4516,6 +4546,11 @@
        DO i=1,klon
           itest(i)=0
-          !        IF ((zstd(i).gt.10.0)) THEN
-          IF (((zpic(i)-zmea(i)).GT.100.).AND.(zstd(i).GT.10.0)) THEN
+          zrel_oro(i)=zstd(i)/(max(zsig(i),1.E-8)*sqrt(cell_area(i)))
+          !zrel_oro: relative mountain height wrt relief explained by mean slope
+          ! -> condition on zrel_oro can deactivate the drag on tilted planar terrains
+          !    such as ice sheets (work by V. Wiener)
+          ! zpmm_orodr_t and zstd_orodr_t are activation thresholds set by F. Lott to
+          ! earn computation time but they are not physical.
+          IF (((zpic(i)-zmea(i)).GT.zpmm_orodr_t).AND.(zstd(i).GT.zstd_orodr_t).AND.(zrel_oro(i).LE.zrel_oro_t)) THEN
              itest(i)=1
              igwd=igwd+1
@@ -4566,5 +4601,9 @@
        DO i=1,klon
           itest(i)=0
-          IF ((zpic(i)-zmea(i)).GT.100.) THEN
+          !zrel_oro: relative mountain height wrt relief explained by mean slope
+          ! -> condition on zrel_oro can deactivate the lifting on tilted planar terrains
+          !    such as ice sheets (work by V. Wiener)
+          zrel_oro(i)=zstd(i)/(max(zsig(i),1.E-8)*sqrt(cell_area(i)))
+          IF (((zpic(i)-zmea(i)).GT.zpmm_orolf_t).AND.(zrel_oro(i).LE.zrel_oro_t)) THEN
              itest(i)=1
              igwd=igwd+1
@@ -4756,5 +4795,5 @@
 ! car on peut s'attendre a ce que les petites echelles produisent aussi de la TKE
 ! Mais attention, cela ne va pas dans le sens de la conservation de l'energie! 
-          IF (zstd(i).GT.1.0) THEN
+          IF ((zstd(i).GT.1.0) .AND.(zrel_oro(i).LE.zrel_oro_t)) THEN
              itest(i)=1
              igwd=igwd+1
@@ -4768,5 +4807,5 @@
        DO i=1,klon
           itest(i)=0
-        IF (((zpic(i)-zmea(i)).GT.100.).AND.(zstd(i).GT.10.0)) THEN
+        IF (((zpic(i)-zmea(i)).GT.zpmm_orodr_t).AND.(zstd(i).GT.zstd_orodr_t).AND.(zrel_oro(i).LE.zrel_oro_t)) THEN
              itest(i)=1
              igwd=igwd+1
@@ -4935,5 +4974,5 @@
     !
 
-    IF (ANY(types_trac=='repr')) THEN
+    IF (type_trac == 'repr') THEN
 !MM pas d'impact, car on recupere q_seri,tr_seri,t_seri via phys_local_var_mod
 !MM                               dans Reprobus
@@ -4985,5 +5024,5 @@
          presnivs, pphis,     pphi,     albsol1, &
          sh_in,   ch_in,    rhcl,      cldfra,   rneb, &
-         diafra,   cldliq,    itop_con, ibas_con, &
+         diafra,   radocond,    itop_con, ibas_con, &
          pmflxr,   pmflxs,    prfl,     psfl, &
          da,       phi,       mp,       upwd, &
@@ -5033,17 +5072,16 @@
     ! Calculer le transport de l'eau et de l'energie (diagnostique)
     !
-    CALL transp (paprs,zxtsol, &
-         t_seri, q_seri, ql_seri, qs_seri, u_seri, v_seri, zphi, &
-         ve, vq, ue, uq, vwat, uwat)
+    CALL transp (paprs,zxtsol, t_seri, q_seri, ql_seri, qs_seri, u_seri, v_seri, zphi, &
+                 ue, ve, uq, vq, uwat, vwat)
     !
     !IM global posePB BEG
     IF(1.EQ.0) THEN
        !
-       CALL transp_lay (paprs,zxtsol, &
-            t_seri, q_seri, u_seri, v_seri, zphi, &
+       CALL transp_lay (paprs,zxtsol, t_seri, q_seri, u_seri, v_seri, zphi, &
             ve_lay, vq_lay, ue_lay, uq_lay)
        !
     ENDIF !(1.EQ.0) THEN
     !IM global posePB END
+    !
     ! Accumuler les variables a stocker dans les fichiers histoire:
     !
@@ -5056,5 +5094,5 @@
     d_t_ec(:,:)=0.
     forall (k=1: nbp_lev) exner(:, k) = (pplay(:, k)/paprs(:,1))**RKAPPA
-    CALL ener_conserv(klon,klev,pdtphys,u,v,t,qx(:,:,ivap),qx(:,:,iliq),qx(:,:,isol), &
+    CALL ener_conserv(klon,klev,pdtphys,u,v,t,qx,ivap,iliq,isol, &
          u_seri,v_seri,t_seri,q_seri,ql_seri,qs_seri,pbl_tke(:,:,is_ave)-tke0(:,:), &
          zmasse,exner,d_t_ec)
@@ -5089,5 +5127,5 @@
     ENDDO
     !
-    IF (ANY(types_trac == 'inca') .OR. ANY(types_trac == 'inco')) THEN
+    IF (ANY(type_trac == ['inca','inco'])) THEN
 #ifdef INCA
        CALL VTe(VTphysiq)
@@ -5113,5 +5151,5 @@
     ENDIF
 
-    IF (ANY(types_trac == 'repr')) THEN
+    IF (type_trac == 'repr') THEN
 #ifdef REPROBUS
         CALL coord_hyb_rep(paprs, pplay, aps, bps, ap, bp, cell_area)
@@ -5151,16 +5189,15 @@
     ENDDO
     !
-    IF (nqtot > nqo) THEN
-       itr = 0
-       DO iq = 1, nqtot
-          IF(.NOT.tracers(iq)%isInPhysics) CYCLE
-          itr = itr+1
-          DO  k = 1, klev
-             DO  i = 1, klon
-                d_qx(i,k,iq) = ( tr_seri(i,k,itr) - qx(i,k,iq) ) / phys_tstep
-             ENDDO
+    ! DC: All iterations are cycled if nqtot==nqo, so no nqtot>nqo condition required
+    itr = 0
+    DO iq = 1, nqtot
+       IF(.NOT.tracers(iq)%isInPhysics) CYCLE
+       itr = itr+1
+       DO  k = 1, klev
+          DO  i = 1, klon
+             d_qx(i,k,iq) = ( tr_seri(i,k,itr) - qx(i,k,iq) ) / phys_tstep
           ENDDO
        ENDDO
-    ENDIF
+    ENDDO
     !
     !IM rajout diagnostiques bilan KP pour analyse MJO par Jun-Ichi Yano
@@ -5375,5 +5412,5 @@
 
 #ifdef INCA
-       if (ANY(types_trac == 'inca' )) then 
+       if (type_trac == 'inca') then 
           IF (is_omp_master .and. grid_type==unstructured) THEN 
              CALL finalize_inca
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phytrac_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phytrac_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phytrac_mod.F90	(revision 4482)
@@ -56,5 +56,5 @@
   SUBROUTINE phytrac_init()
     USE dimphy
-    USE infotrac_phy, ONLY: nbtr, types_trac
+    USE infotrac_phy, ONLY: nbtr, type_trac
     USE tracco2i_mod, ONLY: tracco2i_init
     IMPLICIT NONE
@@ -79,6 +79,11 @@
     !===============================================================================
     !   -- CO2 interactif --
-    IF(ANY(types_trac == 'co2i') .OR. ANY(types_trac == 'inco')) CALL tracco2i_init()
-
+    IF(ANY(type_trac == ['co2i','inco'])) CALL tracco2i_init()
+
+       !   -- type_trac == 'co2i' ! PC 
+       !   -- CO2 interactif --
+       !   -- source is updated with FF and BB emissions 
+       !   -- and net fluxes from ocean and orchidee 
+       !   -- sign convention : positive into the atmosphere
 
   END SUBROUTINE phytrac_init
@@ -119,5 +124,5 @@
     USE phys_cal_mod, only : hour
     USE dimphy
-    USE infotrac_phy, ONLY: nbtr, nqCO2, types_trac, type_trac, conv_flg, pbl_flg
+    USE infotrac_phy, ONLY: nbtr, nqCO2, type_trac, conv_flg, pbl_flg
     USE strings_mod,  ONLY: int2str
     USE mod_grid_phy_lmdz
@@ -179,5 +184,5 @@
     REAL,DIMENSION(klon),INTENT(IN)        :: pphis
     REAL,DIMENSION(klev),INTENT(IN)        :: presnivs 
-    REAL,DIMENSION(klon,klev),INTENT(IN)   :: cldliq  ! eau liquide nuageuse
+    REAL,DIMENSION(klon,klev),INTENT(IN)   :: cldliq  ! eau condensee totale
     REAL,DIMENSION(klon,klev),INTENT(IN)   :: cldfra  ! fraction nuageuse (tous les nuages)
     REAL,DIMENSION(klon,klev),INTENT(IN)   :: diafra  ! fraction nuageuse (convection ou stratus artificiels)
@@ -486,10 +491,10 @@
 
        ! Initialize module for specific tracers
-       IF(ANY(types_trac == 'inca')) THEN
+       IF(type_trac == 'inca') THEN
           source(:,:)=init_source(:,:)
           CALL tracinca_init(aerosol,lessivage)
-       ELSE IF(ANY(types_trac == 'repr')) THEN
+       ELSE IF(type_trac == 'repr') THEN
           source(:,:)=0.
-       ELSE IF(ANY(types_trac == 'co2i')) THEN
+       ELSE IF(type_trac == 'co2i') THEN
           source(:,:)=0.
           lessivage  = .FALSE.
@@ -499,5 +504,5 @@
           iflag_vdf_trac= 1
           iflag_con_trac= 1
-       ELSE IF(ANY(types_trac == 'inco')) THEN
+       ELSE IF(type_trac == 'inco') THEN
           source(:,1:nqCO2) = 0.                          ! from CO2i ModThL
           source(:,nqCO2+1:nbtr)=init_source(:,:)         ! from INCA ModThL
@@ -509,5 +514,5 @@
           iflag_con_trac = 1                              ! From CO2i
 #ifdef CPP_StratAer
-       ELSE IF(ANY(types_trac == 'coag')) THEN
+       ELSE IF(type_trac == 'coag') THEN
           source(:,:)=0.
           DO it= 1, nbtr_sulgas
@@ -519,5 +524,5 @@
           ENDDO
 #endif
-       ELSE IF(ANY(types_trac == 'lmdz')) THEN
+       ELSE IF(type_trac == 'lmdz') THEN
           CALL traclmdz_init(pctsrf,xlat,xlon,ftsol,tr_seri,t_seri,pplay,sh,pdtphys,aerosol,lessivage)
        END IF
@@ -534,7 +539,7 @@
           !
           DO it=1, nbtr
-             IF(ANY(types_trac == 'repr')) THEN
+             IF(type_trac == 'repr') THEN
                  flag_cvltr(it)=.FALSE.
-             ELSE IF(ANY(types_trac == 'inca')) THEN
+             ELSE IF(type_trac == 'inca') THEN
 !                IF ((it.EQ.id_Rn222) .OR. ((it.GE.id_SO2) .AND. (it.LE.id_NH3)) ) THEN 
 !                   !--gas-phase species
@@ -560,11 +565,11 @@
                 !--for now we do not scavenge in cvltr
                 flag_cvltr(it)=.FALSE.
-             ELSE IF(ANY(types_trac == 'co2i')) THEN
+             ELSE IF(type_trac == 'co2i') THEN
                 !--co2 tracers are not scavenged
                 flag_cvltr(it)=.FALSE.
-             ELSE IF(ANY(types_trac == 'inco')) THEN     ! Add ThL
+             ELSE IF(type_trac == 'inco') THEN     ! Add ThL
                 flag_cvltr(it)=.FALSE.
 #ifdef CPP_StratAer
-             ELSE IF(ANY(types_trac == 'coag')) THEN
+             ELSE IF(type_trac == 'coag') THEN
                 IF (convscav.and.aerosol(it)) THEN
                    flag_cvltr(it)=.TRUE.
@@ -576,5 +581,5 @@
                 ENDIF
 #endif
-             ELSE IF(ANY(types_trac == 'lmdz')) THEN
+             ELSE IF(type_trac == 'lmdz') THEN
                 IF (convscav.and.aerosol(it)) THEN
                    flag_cvltr(it)=.TRUE.
@@ -609,8 +614,6 @@
        write(lunout,*)  'flag_cvltr    = ', flag_cvltr
 
-       IF (lessivage .AND. (ANY(types_trac == 'inca') .OR. ANY(types_trac=='inco'))) THEN     ! Mod ThL
+       IF (lessivage .AND. ANY(type_trac == ['inca','inco'])) &
           CALL abort_physic('phytrac', 'lessivage=T config_inca=inca impossible',1)
-!          STOP
-       ENDIF
        !
     ENDIF ! of IF (debutphy)
@@ -635,10 +638,10 @@
     !      
     !===============================================================================
-    IF(ANY(types_trac == 'inca')) THEN
+    IF(type_trac == 'inca') THEN
        !    -- CHIMIE INCA  config_inca = aero or chem --
        ! Appel fait en fin de phytrac pour avoir les emissions modifiees par 
        ! la couche limite et la convection avant le calcul de la chimie 
 
-    ELSE IF(ANY(types_trac == 'repr')) THEN
+    ELSE IF(type_trac == 'repr') THEN
        !   -- CHIMIE REPROBUS --
        CALL tracreprobus(pdtphys, gmtime, debutphy, julien, &
@@ -647,5 +650,5 @@
             tr_seri)
 
-    ELSE IF(ANY(types_trac == 'co2i')) THEN
+    ELSE IF(type_trac == 'co2i') THEN
        !   -- CO2 interactif --
        !   -- source is updated with FF and BB emissions 
@@ -656,5 +659,5 @@
             xlat, xlon, pphis, pphi, &
             t_seri, pplay, paprs, tr_seri, source)
-    ELSE IF(ANY(types_trac == 'inco')) THEN      ! Add ThL
+    ELSE IF(type_trac == 'inco') THEN      ! Add ThL
        CALL tracco2i(pdtphys, debutphy, &
             xlat, xlon, pphis, pphi, &
@@ -662,5 +665,5 @@
 
 #ifdef CPP_StratAer
-    ELSE IF(ANY(types_trac == 'coag')) THEN
+    ELSE IF(type_trac == 'coag') THEN
        !   --STRATOSPHERIC AER IN THE STRAT --
        CALL traccoag(pdtphys, gmtime, debutphy, julien, &
@@ -669,5 +672,5 @@
             tr_seri)
 #endif
-    ELSE IF(ANY(types_trac == 'lmdz')) THEN
+    ELSE IF(type_trac == 'lmdz') THEN
        !    -- Traitement des traceurs avec traclmdz
        CALL traclmdz(nstep, julien, gmtime, pdtphys, t_seri, paprs, pplay, &
@@ -707,6 +710,4 @@
                 !--with the full array tr_seri even if only item it is processed
 
-                print*,'CV SCAV ',it,ccntrAA(it),ccntrENV(it)
-
                 CALL cvltr_scav(pdtphys, da, phi,phi2,d1a,dam, mp,ep,         &
                      sigd,sij,wght_cvfd,clw,elij,epmlmMm,eplaMm,              &     
@@ -745,5 +746,5 @@
 
 #ifdef CPP_StratAer
-       IF (ANY(types_trac=='coag')) THEN
+       IF (type_trac=='coag') THEN
          ! initialize wet deposition flux of sulfur
          budg_dep_wet_ocs(:)=0.0
@@ -826,5 +827,5 @@
        !
 #ifdef CPP_StratAer
-       IF (ANY(types_trac=='coag')) THEN
+       IF (type_trac=='coag') THEN
 
          ! initialize dry deposition flux of sulfur
@@ -863,5 +864,5 @@
              !
 #ifdef CPP_StratAer
-             IF (ANY(types_trac=='coag')) THEN
+             IF (type_trac=='coag') THEN
                ! compute dry deposition flux of sulfur (sum over gases and particles)
                IF (it==id_OCS_strat) THEN
@@ -948,5 +949,5 @@
 
 #ifdef CPP_StratAer
-         IF (ANY(types_trac=='coag')) THEN
+         IF (type_trac=='coag') THEN
            ! compute wet deposition flux of sulfur (sum over gases and
            ! particles) and convert to kg(S)/m2/s
@@ -1088,5 +1089,5 @@
 
     !    -- CHIMIE INCA  config_inca = aero or chem --
-    IF (ANY(types_trac == 'inca') .OR. ANY(types_trac == 'inco')) THEN  ! ModThL
+    IF (ANY(type_trac == ['inca','inco'])) THEN  ! ModThL
 
        CALL tracinca(&
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radiation_AR4.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radiation_AR4.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radiation_AR4.F90	(revision 4482)
@@ -479,5 +479,5 @@
   USE dimphy
   USE radiation_ar4_param, ONLY: rsun, rray
-  USE infotrac_phy, ONLY: types_trac
+  USE infotrac_phy, ONLY: type_trac
 #ifdef REPROBUS
   USE chem_rep, ONLY: rsuntime, ok_suntime
@@ -571,5 +571,5 @@
   ! If running with Reporbus, overwrite default values of RSUN.
   ! Otherwise keep default values from radiation_AR4_param module.
-  IF (ANY(types_trac=='repr')) THEN
+  IF (type_trac=='repr') THEN
 #ifdef REPROBUS
     IF (ok_suntime) THEN
@@ -701,5 +701,5 @@
   USE dimphy
   USE radiation_ar4_param, ONLY: rsun, rray
-  USE infotrac_phy, ONLY: types_trac
+  USE infotrac_phy, ONLY: type_trac
 #ifdef REPROBUS
   USE chem_rep, ONLY: rsuntime, ok_suntime
@@ -825,5 +825,5 @@
   ! If running with Reporbus, overwrite default values of RSUN.
   ! Otherwise keep default values from radiation_AR4_param module.
-  IF (ANY(types_trac=='repr')) THEN
+  IF (type_trac=='repr') THEN
 #ifdef REPROBUS
     IF (ok_suntime) THEN
@@ -2313,5 +2313,5 @@
   USE dimphy
   USE radiation_ar4_param, ONLY: tref, rt1, raer, at, bt, oct
-  USE infotrac_phy, ONLY: types_trac
+  USE infotrac_phy, ONLY: type_trac
 #ifdef REPROBUS
   USE chem_rep, ONLY: rch42d, rn2o2d, rcfc112d, rcfc122d, ok_rtime2d
@@ -2621,5 +2621,5 @@
 
 
-        IF (ANY(types_trac=='repr')) THEN
+        IF (type_trac=='repr') THEN
 #ifdef REPROBUS
           IF (ok_rtime2d) THEN
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radlwsw_m.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radlwsw_m.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radlwsw_m.F90	(revision 4482)
@@ -48,5 +48,5 @@
   USE DIMPHY
   USE assert_m, ONLY : assert
-  USE infotrac_phy, ONLY : types_trac
+  USE infotrac_phy, ONLY : type_trac
   USE write_field_phy
 
@@ -551,5 +551,5 @@
   PSCT = solaire/zdist/zdist
 
-  IF (ANY(types_trac == 'repr')) THEN
+  IF (type_trac == 'repr') THEN
 #ifdef REPROBUS
     IF (iflag_rrtm==0) THEN
@@ -635,5 +635,5 @@
     ENDDO
 
-    IF (ANY(types_trac == 'repr')) THEN
+    IF (type_trac == 'repr') THEN
 #ifdef REPROBUS
        ndimozon = size(wo, 3)
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/read_pstoke.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/read_pstoke.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/read_pstoke.F90	(revision 4482)
@@ -252,9 +252,5 @@
 
     ! niveaux de pression
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidpl, 1, zklevo, pl)
-#else
-    status = nf_get_vara_real(ncidp, varidpl, 1, zklevo, pl)
-#endif
+    status = nf90_get_var(ncidp, varidpl, pl, [1], [ncklevo])
 
     ! lecture de aire et phis
@@ -271,17 +267,9 @@
 
     ! phis
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidps, start, count, phisfi2)
-#else
-    status = nf_get_vara_real(ncidp, varidps, start, count, phisfi2)
-#endif
+    status = nf90_get_var(ncidp, varidps, phisfi2, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, phisfi2, phisfi)
 
     ! aire
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidai, start, count, airefi2)
-#else
-    status = nf_get_vara_real(ncidp, varidai, start, count, airefi2)
-#endif
+    status = nf90_get_var(ncidp, varidai, airefi2, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, airefi2, airefi)
   ELSE
@@ -309,75 +297,39 @@
     ! *** Lessivage******************************************************
     ! frac_impa
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidfi, start, count, frac_impa2)
-#else
-    status = nf_get_vara_real(ncidp, varidfi, start, count, frac_impa2)
-#endif
+    status = nf90_get_var(ncidp, varidfi, frac_impa2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, frac_impa2, frac_impa)
 
     ! frac_nucl
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidfn, start, count, frac_nucl2)
-#else
-    status = nf_get_vara_real(ncidp, varidfn, start, count, frac_nucl2)
-#endif
+    status = nf90_get_var(ncidp, varidfn, frac_nucl2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, frac_nucl2, frac_nucl)
 
     ! *** Temperature ******************************************************
     ! abder t
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidt, start, count, t2)
-#else
-    status = nf_get_vara_real(ncidp, varidt, start, count, t2)
-#endif
+    status = nf90_get_var(ncidp, varidt, t2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, t2, t)
 
     ! *** Flux pour le calcul de la convection TIEDTK ***********************
     ! mfu
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidmfu, start, count, mfu2)
-#else
-    status = nf_get_vara_real(ncidp, varidmfu, start, count, mfu2)
-#endif
+    status = nf90_get_var(ncidp, varidmfu, mfu2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, mfu2, mfu)
 
     ! mfd
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidmfd, start, count, mfd2)
-#else
-    status = nf_get_vara_real(ncidp, varidmfd, start, count, mfd2)
-#endif
+    status = nf90_get_var(ncidp, varidmfd, mfd2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, mfd2, mfd)
 
     ! en_u
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidenu, start, count, en_u2)
-#else
-    status = nf_get_vara_real(ncidp, varidenu, start, count, en_u2)
-#endif
+    status = nf90_get_var(ncidp, varidenu, en_u2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, en_u2, en_u)
 
     ! de_u
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, variddeu, start, count, de_u2)
-#else
-    status = nf_get_vara_real(ncidp, variddeu, start, count, de_u2)
-#endif
+    status = nf90_get_var(ncidp, variddeu, de_u2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, de_u2, de_u)
 
     ! en_d
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidend, start, count, en_d2)
-#else
-    status = nf_get_vara_real(ncidp, varidend, start, count, en_d2)
-#endif
+    status = nf90_get_var(ncidp, varidend, en_d2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, en_d2, en_d)
 
     ! de_d
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidded, start, count, de_d2)
-#else
-    status = nf_get_vara_real(ncidp, varidded, start, count, de_d2)
-#endif
+    status = nf90_get_var(ncidp, varidded, de_d2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, de_d2, de_d)
 
@@ -385,9 +337,5 @@
     ! turbulent**********************************
     ! coefh
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidch, start, count, coefh2)
-#else
-    status = nf_get_vara_real(ncidp, varidch, start, count, coefh2)
-#endif
+    status = nf90_get_var(ncidp, varidch, coefh2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, coefh2, coefh)
 
@@ -395,16 +343,8 @@
     ! Thermiques************************
     ! abder thermiques
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidfmth, start, count, fm_therm2)
-#else
-    status = nf_get_vara_real(ncidp, varidfmth, start, count, fm_therm2)
-#endif
+    status = nf90_get_var(ncidp, varidfmth, fm_therm2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, fm_therm2, fm_therm)
 
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidenth, start, count, en_therm2)
-#else
-    status = nf_get_vara_real(ncidp, varidenth, start, count, en_therm2)
-#endif
+    status = nf90_get_var(ncidp, varidenth, en_therm2, start, count)
     CALL gr_ecrit_fi(klevo, klono, imo, jmo+1, en_therm2, en_therm)
 
@@ -416,83 +356,43 @@
     count(4) = 0
     ! pyu1
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidyu1, start, count, pyu12)
-#else
-    status = nf_get_vara_real(ncidp, varidyu1, start, count, pyu12)
-#endif
+    status = nf90_get_var(ncidp, varidyu1, pyu12, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, pyu12, pyu1)
 
     ! pyv1
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidyv1, start, count, pyv12)
-#else
-    status = nf_get_vara_real(ncidp, varidyv1, start, count, pyv12)
-#endif
+    status = nf90_get_var(ncidp, varidyv1, pyv12, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, pyv12, pyv1)
 
     ! *** Temperature au sol ********************************************
     ! ftsol1
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidfts1, start, count, ftsol12)
-#else
-    status = nf_get_vara_real(ncidp, varidfts1, start, count, ftsol12)
-#endif
+    status = nf90_get_var(ncidp, varidfts1, ftsol12, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, ftsol12, ftsol1)
 
     ! ftsol2
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidfts2, start, count, ftsol22)
-#else
-    status = nf_get_vara_real(ncidp, varidfts2, start, count, ftsol22)
-#endif
+    status = nf90_get_var(ncidp, varidfts2, ftsol22, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, ftsol22, ftsol2)
 
     ! ftsol3
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidfts3, start, count, ftsol32)
-#else
-    status = nf_get_vara_real(ncidp, varidfts3, start, count, ftsol32)
-#endif
+    status = nf90_get_var(ncidp, varidfts3, ftsol32, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, ftsol32, ftsol3)
 
     ! ftsol4
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidfts4, start, count, ftsol42)
-#else
-    status = nf_get_vara_real(ncidp, varidfts4, start, count, ftsol42)
-#endif
+    status = nf90_get_var(ncidp, varidfts4, ftsol42, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, ftsol42, ftsol4)
 
     ! *** Nature du sol **************************************************
     ! psrf1
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidpsr1, start, count, psrf12)
-#else
-    status = nf_get_vara_real(ncidp, varidpsr1, start, count, psrf12)
-#endif
+    status = nf90_get_var(ncidp, varidpsr1, psrf12, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, psrf12, psrf1)
 
     ! psrf2
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidpsr2, start, count, psrf22)
-#else
-    status = nf_get_vara_real(ncidp, varidpsr2, start, count, psrf22)
-#endif
+    status = nf90_get_var(ncidp, varidpsr2, psrf22, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, psrf22, psrf2)
 
     ! psrf3
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidpsr3, start, count, psrf32)
-#else
-    status = nf_get_vara_real(ncidp, varidpsr3, start, count, psrf32)
-#endif
+    status = nf90_get_var(ncidp, varidpsr3, psrf32, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, psrf32, psrf3)
 
     ! psrf4
-#ifdef NC_DOUBLE
-    status = nf_get_vara_double(ncidp, varidpsr4, start, count, psrf42)
-#else
-    status = nf_get_vara_real(ncidp, varidpsr4, start, count, psrf42)
-#endif
+    status = nf90_get_var(ncidp, varidpsr4, psrf42, start, count)
     CALL gr_ecrit_fi(1, klono, imo, jmo+1, psrf42, psrf4)
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/rrtm/rrtm_taumol2.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/rrtm/rrtm_taumol2.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/rrtm/rrtm_taumol2.F90	(revision 4482)
@@ -125,6 +125,6 @@
       CALL prt_alerte(message,modname,1)
       PRINT*,'WARNING IFP=',IFP,' 2.E2_JPRB*Z_FP+0.5_JPRB avec Z_FP=',Z_FP
-      IFP=200
    ENDIF
+   IFP=200
   ENDIF
 
@@ -170,6 +170,6 @@
       CALL prt_alerte(message,modname,1)
       PRINT*,'WARNING IFP=',IFP,' 2.E2_JPRB*Z_FP+0.5_JPRB avec Z_FP=',Z_FP
-      IFP=200
    ENDIF
+   IFP=200
   ENDIF
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/rrtm/suecrad.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/rrtm/suecrad.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/rrtm/suecrad.F90	(revision 4482)
@@ -243,8 +243,8 @@
 !      ----------------------------------------------------------------
 
+#include "clesphys.h"
 #include "naerad.h"
 #include "namrgri.h"
 !MPL/IM 20160915 on prend GES de phylmd
-#include "clesphys.h"
 
 !*         1.       INITIALIZE NEUROFLUX LONGWAVE RADIATION
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/screenc_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/screenc_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/screenc_mod.F90	(revision 4482)
@@ -70,5 +70,5 @@
 ! Variables locales  
       INTEGER :: i 
-      REAL, dimension(klon) :: cdram, cdrah, cdran, zri1, gref,ycdragm
+      REAL, dimension(klon) :: cdram, cdrah, cdran, zri1, gref,ycdragm,zri_zero
 !
 !------------------------------------------------------------------------- 
@@ -89,4 +89,5 @@
                     speed, temp, q_zref, gref, &
                     psol, ts, qsurf, z0m, z0h, &
+                    zri_zero,0,                &
                     cdram, cdrah, zri1, pref)
       DO i = 1, knon
@@ -177,5 +178,5 @@
 ! Richardson at reference level 
 !
-      CALL cdragn_ri1 (knon, nsrf, &
+      CALL cdrag(knon, nsrf, &
                     speed, temp, q_zref, gref, &
                     psol, ts, qsurf, z0m, z0h, &
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/stdlevvar_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/stdlevvar_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/stdlevvar_mod.F90	(revision 4482)
@@ -103,5 +103,5 @@
       REAL, dimension(klon) :: te_zref_con, q_zref_con
       REAL, dimension(klon) :: u_zref_c, te_zref_c, temp_c, q_zref_c
-      REAL, dimension(klon) :: ok_pred, ok_corr
+      REAL, dimension(klon) :: ok_pred, ok_corr, zri_zero
 !     REAL, dimension(klon) :: conv_te, conv_q
 !------------------------------------------------------------------------- 
@@ -121,4 +121,5 @@
  &                   speed, t1, q1, z1, &
  &                   psol, ts1, qsurf, z0m, z0h, &
+ &                   zri_zero, 0, &
  &                   cdram, cdrah, zri1, pref)
 
@@ -413,5 +414,5 @@
       REAL, dimension(klon) :: cdrm10m, cdrh10m, ri10m
       REAL, dimension(klon) :: cdmn10m, cdhn10m, fm10m, fh10m
-      REAL, dimension(klon) :: cdn2m, cdn1
+      REAL, dimension(klon) :: cdn2m, cdn1, zri_zero
       REAL :: CEPDUE,zdu2 
       INTEGER :: nzref, nz1
@@ -444,4 +445,5 @@
  &                   speed, t1, q1, z1, &
  &                   psol, ts1, qsurf, z0m, z0h, &
+ &                   zri_zero, 0, &
  &                   cdram, cdrah, zri1, pref)
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_land_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_land_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_land_mod.F90	(revision 4482)
@@ -24,7 +24,6 @@
     USE dimphy
     USE surface_data, ONLY    : ok_veget
-! >> PC
-    USE carbon_cycle_mod 
-! << PC
+    USE carbon_cycle_mod
+
 
     ! See comments in each module surf_land_orchidee_xxx for compatiblity with ORCHIDEE
@@ -45,4 +44,9 @@
     USE surf_land_orchidee_nounstruct_mod
 #else
+#if ORCHIDEE_NOLIC
+    ! Compilation with cpp key ORCHIDEE_NOLIC
+    USE surf_land_orchidee_nolic_mod
+#else
+    ! Default version
     USE surf_land_orchidee_mod
 #endif
@@ -50,12 +54,10 @@
 #endif
 #endif
-
+#endif
+    
     USE surf_land_bucket_mod
     USE calcul_fluxs_mod
     USE indice_sol_mod
-
-! >> PC
     USE print_control_mod, ONLY: lunout
-! << PC
 
     INCLUDE "dimsoil.h"
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_land_orchidee_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_land_orchidee_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_land_orchidee_mod.F90	(revision 4482)
@@ -5,11 +5,12 @@
 #ifndef ORCHIDEE_NOFREIN
 #ifndef ORCHIDEE_NOUNSTRUCT
+#ifndef ORCHIDEE_NOLIC
 !
 ! This module controles the interface towards the model ORCHIDEE.
 !
 ! Compatibility with ORCHIDIEE :
-! The current version can be used with ORCHIDEE/trunk from revision 4465.
+! The current version can be used with ORCHIDEE/trunk from revision 7757. 
 ! This interface is used if none of the cpp keys ORCHIDEE_NOOPENMP, 
-! ORCHIDEE_NOZ0H or ORCHIDEE_NOFREIN is set.
+! ORCHIDEE_NOZ0H, ORCHIDEE_NOFREIN or ORCHIDEE_NOLIC is set.
 !
 ! Subroutines in this module : surf_land_orchidee
@@ -20,8 +21,8 @@
   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 intersurf     ! module in ORCHIDEE
+#endif
+  USE cpl_mod,      ONLY : cpl_send_land_fields, cpl_send_landice_fields
+  USE surface_data, ONLY : type_ocean, landice_opt
   USE geometry_mod, ONLY : dx, dy, boundslon, boundslat,longitude, latitude, cell_area,  ind_cell_glo
   USE mod_grid_phy_lmdz
@@ -152,4 +153,7 @@
     INTEGER                                   :: error
     REAL, DIMENSION(klon)                     :: swdown_vrai
+    REAL, DIMENSION(klon)                     :: run_off_lic        !! run off from land ice defined in ORCHIDEE, contains calving, melting and liquid precipitation
+    REAL, DIMENSION(klon)                     :: run_off_lic_frac   !! cell fraction corresponding to run_off_lic
+    REAL, DIMENSION(klon)                     :: blowingsnow_flux   !! blowing snow flux
     CHARACTER (len = 20)                      :: modname = 'surf_land_orchidee'
     CHARACTER (len = 80)                      :: abort_message
@@ -570,5 +574,6 @@
                lon_scat, lat_scat, q2m(1:knon), t2m(1:knon), z0h_new(1:knon), nvm_orch, &
                grid=grid_type, bounds_latlon=bounds_lalo, cell_area=area, ind_cell_glo=ind_cell, &
-               field_out_names=cfname_out, field_in_names=cfname_in(1:nbcf_in_orc))
+               field_out_names=cfname_out, field_in_names=cfname_in(1:nbcf_in_orc), &
+               coszang=yrmu0(1:knon))
 #endif         
        ENDIF
@@ -603,5 +608,5 @@
             fields_out=yfields_out(1:knon,1:nbcf_out),  &
             fields_in=yfields_in(1:knon,1:nbcf_in_orc), &
-            coszang=yrmu0(1:knon))
+            coszang=yrmu0(1:knon), run_off_lic=run_off_lic(1:knon), run_off_lic_frac=run_off_lic_frac(1:knon), blowingsnow_flux=blowingsnow_flux(1:knon))
 #endif       
     ENDIF
@@ -616,4 +621,7 @@
        CALL cpl_send_land_fields(itime, knon, knindex, &
             riverflow, coastalflow)
+       IF (landice_opt .GE. 2) THEN
+          CALL cpl_send_landice_fields(itime, knon, knindex, run_off_lic, run_off_lic_frac)
+       END IF
     ENDIF
 
@@ -850,3 +858,4 @@
 #endif
 #endif
+#endif
 END MODULE surf_land_orchidee_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_land_orchidee_nolic_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_land_orchidee_nolic_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_land_orchidee_nolic_mod.F90	(revision 4482)
@@ -0,0 +1,846 @@
+!
+MODULE surf_land_orchidee_nolic_mod
+#ifdef ORCHIDEE_NOLIC
+!
+! This module controles the interface towards the model ORCHIDEE.
+!
+! Compatibility with ORCHIDIEE :
+! This module is compiled only if cpp key ORCHIDEE_NOLIC is defined. 
+! The current version can be used with ORCHIDEE/trunk from revision 4465-7757. 
+! (it can be used for later revisions also but it is not needed.)
+! 
+! 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, boundslon, boundslat,longitude, latitude, cell_area,  ind_cell_glo
+  USE mod_grid_phy_lmdz
+  USE mod_phys_lmdz_para, mpi_root_rank=>mpi_master
+  USE carbon_cycle_mod, ONLY : nbcf_in_orc, nbcf_out, fields_in, yfields_in, yfields_out, cfname_in, cfname_out
+  USE nrtype, ONLY : PI
+  
+  IMPLICIT NONE
+
+  PRIVATE
+  PUBLIC  :: surf_land_orchidee
+
+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, z0m_new, z0h_new, qsurf, &
+       veget, lai, height )
+
+    USE mod_surf_para
+    USE mod_synchro_omp
+    USE carbon_cycle_mod
+    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
+!   z0m_new      surface roughness for momentum
+!   z0h_new      surface roughness for heat
+!   qsurf        air moisture at surface
+!
+    INCLUDE "YOMCST.h"
+    INCLUDE "dimpft.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, z0m_new, z0h_new
+    REAL, DIMENSION(klon,nvm_lmdz), INTENT(OUT) :: veget
+    REAL, DIMENSION(klon,nvm_lmdz), INTENT(OUT) :: lai
+    REAL, DIMENSION(klon,nvm_lmdz), INTENT(OUT) :: height
+
+! Local
+!****************************************************************************************
+    INTEGER                                   :: ij, jj, igrid, ireal, index, nb
+    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)
+! boundaries of cells
+    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE   :: bounds_lalo
+    !$OMP THREADPRIVATE(bounds_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)
+
+! area of cells
+    REAL, ALLOCATABLE, DIMENSION (:), SAVE  :: area  
+    !$OMP THREADPRIVATE(area)
+
+    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_mpi_rank
+    INTEGER :: orch_mpi_size
+    INTEGER :: orch_omp_rank
+    INTEGER :: orch_omp_size
+
+    REAL, ALLOCATABLE, DIMENSION(:)         :: longitude_glo
+    REAL, ALLOCATABLE, DIMENSION(:)         :: latitude_glo
+    REAL, ALLOCATABLE, DIMENSION(:,:)       :: boundslon_glo
+    REAL, ALLOCATABLE, DIMENSION(:,:)       :: boundslat_glo
+    INTEGER, ALLOCATABLE, DIMENSION(:)      :: ind_cell_glo_glo
+    INTEGER, ALLOCATABLE, SAVE,DIMENSION(:) :: ind_cell
+    !$OMP THREADPRIVATE(ind_cell)
+    INTEGER :: begin, end
+!
+! 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(area))) THEN
+          ALLOCATE(area(knon), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation area'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       DO igrid = 1, knon
+          area(igrid) = cell_area(knindex(igrid))
+       ENDDO
+       
+       IF (grid_type==unstructured) THEN
+
+
+         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
+         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)
+                
+       ELSE IF (grid_type==regular_lonlat) THEN
+
+         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(bounds_lalo))) THEN
+           ALLOCATE(bounds_lalo(knon,nvertex,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)
+            bounds_lalo(igrid,:,2)=boundslon(index,:)*180./PI
+            bounds_lalo(igrid,:,1)=boundslat(index,:)*180./PI
+         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)
+       
+       ENDIF
+!
+! Allouer et initialiser le tableau des voisins et des fraction de continents
+!
+       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
+
+
+       IF (grid_type==regular_lonlat) THEN
+ 
+         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.
+         CALL Init_neighbours(knon,neighbours,knindex,pctsrf(:,is_ter))
+
+       ELSE IF (grid_type==unstructured) THEN
+ 
+         IF ( (.NOT.ALLOCATED(neighbours))) THEN
+          ALLOCATE(neighbours(knon,12), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation neighbours'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+         ENDIF
+         neighbours = -1.
+ 
+       ENDIF
+         
+
+!
+!  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
+       
+       IF (grid_type==regular_lonlat) THEN
+         DO igrid = 1, knon
+            ij = knindex(igrid)
+            resolution(igrid,1) = dx(ij)
+           resolution(igrid,2) = dy(ij)
+         ENDDO
+       ENDIF
+        
+       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
+!
+! >> PC
+!       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
+! << PC
+       
+    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_mpi_size,orch_mpi_rank, orch_omp_size,orch_omp_rank)
+
+       IF (grid_type==unstructured) THEN
+         IF (knon==0) THEN
+           begin=1
+           end=0
+         ELSE
+           begin=offset+1
+           end=offset+ktindex(knon)
+         ENDIF
+        
+         IF (orch_mpi_rank==orch_mpi_size-1 .AND. orch_omp_rank==orch_omp_size-1) end=nbp_lon*nbp_lat 
+          
+         ALLOCATE(lalo(end-begin+1,2))
+         ALLOCATE(bounds_lalo(end-begin+1,nvertex,2))
+         ALLOCATE(ind_cell(end-begin+1))
+         
+         ALLOCATE(longitude_glo(klon_glo))
+         CALL gather(longitude,longitude_glo)
+         CALL bcast(longitude_glo)
+         lalo(:,2)=longitude_glo(begin:end)*180./PI
+ 
+         ALLOCATE(latitude_glo(klon_glo))
+         CALL gather(latitude,latitude_glo)
+         CALL bcast(latitude_glo)
+         lalo(:,1)=latitude_glo(begin:end)*180./PI
+
+         ALLOCATE(boundslon_glo(klon_glo,nvertex))
+         CALL gather(boundslon,boundslon_glo)
+         CALL bcast(boundslon_glo)
+         bounds_lalo(:,:,2)=boundslon_glo(begin:end,:)*180./PI
+ 
+         ALLOCATE(boundslat_glo(klon_glo,nvertex))
+         CALL gather(boundslat,boundslat_glo)
+         CALL bcast(boundslat_glo)
+         bounds_lalo(:,:,1)=boundslat_glo(begin:end,:)*180./PI
+         
+         ALLOCATE(ind_cell_glo_glo(klon_glo))
+         CALL gather(ind_cell_glo,ind_cell_glo_glo)
+         CALL bcast(ind_cell_glo_glo)
+         ind_cell(:)=ind_cell_glo_glo(begin:end)
+         
+       ENDIF
+       CALL Init_synchro_omp
+
+!$OMP BARRIER
+       
+       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,grid=grid_type)
+#endif
+       ENDIF
+
+       CALL Synchro_omp
+
+       
+       IF (knon > 0) THEN 
+
+#ifdef CPP_VEGET
+
+         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, z0m_new, &    
+               lon_scat, lat_scat, q2m(1:knon), t2m(1:knon), z0h_new(1:knon), nvm_orch, &
+               grid=grid_type, bounds_latlon=bounds_lalo, cell_area=area, ind_cell_glo=ind_cell, &
+               field_out_names=cfname_out, field_in_names=cfname_in(1:nbcf_in_orc))
+#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)
+!$OMP BARRIER
+
+    IF (knon > 0) THEN
+#ifdef CPP_VEGET    
+       IF (nvm_orch .NE. nvm_lmdz ) THEN
+          abort_message='Pb de dimensiosn PFT: nvm_orch et nvm_lmdz differents.'
+          CALL abort_physic(modname,abort_message,1)
+       ENDIF
+
+       CALL intersurf_main_gathered (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), z0m_new(1:knon), &
+            lon_scat, lat_scat, q2m(1:knon), t2m(1:knon), z0h_new(1:knon),&
+            veget(1:knon,:),lai(1:knon,:),height(1:knon,:),&
+            fields_out=yfields_out(1:knon,1:nbcf_out),  &
+            fields_in=yfields_in(1:knon,1:nbcf_in_orc), &
+            coszang=yrmu0(1:knon))
+#endif       
+    ENDIF
+
+    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
+
+! >> PC
+! Decompressing variables into LMDz for the module carbon_cycle_mod
+! nbcf_in can be zero, in which case the loop does not operate
+! fields_in can then used elsewhere in the model
+     
+     fields_in(:,:)=0.0
+
+     DO nb=1, nbcf_in_orc
+       DO igrid = 1, knon
+        ireal = knindex(igrid)
+        fields_in(ireal,nb)=yfields_in(igrid,nb)
+       ENDDO
+       WRITE(*,*) 'surf_land_orchidee_mod --- yfields_in :',cfname_in(nb)
+     ENDDO
+! >> PC
+    
+  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_mpi_size, orch_mpi_rank, 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_mpi_size
+    INTEGER,INTENT(OUT) :: orch_mpi_rank
+    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)
+      CALL MPI_COMM_SIZE(orch_comm,orch_mpi_size,ierr)
+      CALL MPI_COMM_RANK(orch_comm,orch_mpi_rank,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
+       
+       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_nolic_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_landice_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_landice_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_landice_mod.F90	(revision 4482)
@@ -30,5 +30,5 @@
     USE cpl_mod,          ONLY : cpl_send_landice_fields
     USE calcul_fluxs_mod
-    USE phys_output_var_mod
+    USE phys_output_var_mod, ONLY : snow_o,zfra_o
 !FC
     USE ioipsl_getin_p_mod, ONLY : getin_p
@@ -115,4 +115,5 @@
     INTEGER                  :: i,j,nt
     REAL, DIMENSION(klon)    :: fqfonte,ffonte
+    REAL, DIMENSION(klon)    :: run_off_lic_frac
     REAL, DIMENSION(klon)    :: emis_new                  !Emissivity
     REAL, DIMENSION(klon)    :: swdown,lwdown
@@ -156,6 +157,4 @@
            PRINT*, 'alb_nir_sno_lic',alb_nir_sno_lic
   
-!  z0m=1.e-3
-!  z0h = z0m
   firstcall=.false.
   ENDIF
@@ -351,7 +350,7 @@
 !
 !****************************************************************************************
-    z0m=1.e-3
-    z0h = z0m
-    z0m = SQRT(z0m**2+rugoro**2)
+    z0m = z0m_landice
+    z0h = z0h_landice
+    !z0m = SQRT(z0m**2+rugoro**2)
 
 
@@ -363,8 +362,15 @@
 ! Send run-off on land-ice to coupler if coupled ocean.
 ! run_off_lic has been calculated in fonte_neige or surf_inlandsis
-!
-!****************************************************************************************
-    IF (type_ocean=='couple') THEN
-       CALL cpl_send_landice_fields(itime, knon, knindex, run_off_lic)
+! If landice_opt>=2, corresponding call is done from surf_land_orchidee
+!****************************************************************************************
+    IF (type_ocean=='couple' .AND. landice_opt .LT. 2) THEN
+       ! Compress fraction where run_off_lic is active (here all pctsrf(is_lic))
+       run_off_lic_frac(:)=0.0
+       DO j = 1, knon
+          i = knindex(j)
+          run_off_lic_frac(j) = pctsrf(i,is_lic)
+       ENDDO
+
+       CALL cpl_send_landice_fields(itime, knon, knindex, run_off_lic, run_off_lic_frac)
     ENDIF
 
@@ -373,14 +379,4 @@
 
   
-!****************************************************************************************
-! Etienne: comment these lines because of duplication just below
-!       snow_o=0.
-!       zfra_o = 0.
-!       DO j = 1, knon
-!           i = knindex(j)
-!           snow_o(i) = snow(j) 
-!           zfra_o(i) = zfra(j)
-!       ENDDO
-!
 !****************************************************************************************
        snow_o=0.
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_ocean_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_ocean_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/surf_ocean_mod.F90	(revision 4482)
@@ -20,6 +20,6 @@
        z0m, z0h, SFRWL, alb_dir_new, alb_dif_new, evap, fluxsens, fluxlat, & 
        tsurf_new, dflux_s, dflux_l, lmt_bils, &
-       flux_u1, flux_v1, delta_sst, delta_sal, ds_ns, dt_ns, dter, dser, tkt, tks, &
-       taur, sss)
+       flux_u1, flux_v1, delta_sst, delta_sal, ds_ns, dt_ns, dter, dser, &
+       dt_ds, tkt, tks, taur, sss)
 
     use albedo, only: alboc, alboc_cd
@@ -94,4 +94,16 @@
     ! minus foundation temperature. (Can be negative.) In K.
 
+    REAL, intent(inout):: dter(:) ! (knon)
+    ! Temperature variation in the diffusive microlayer, that is
+    ! ocean-air interface temperature minus subskin temperature. In
+    ! K.
+
+    REAL, intent(inout):: dser(:) ! (knon)
+    ! Salinity variation in the diffusive microlayer, that is
+    ! ocean-air interface salinity minus subskin salinity. In ppt.
+
+    real, intent(inout):: dt_ds(:) ! (knon)
+    ! (tks / tkt) * dTer, in K
+
     ! Output variables
     !**************************************************************************
@@ -109,13 +121,4 @@
     REAL, DIMENSION(klon), INTENT(OUT)       :: flux_u1, flux_v1
 
-    REAL, intent(out):: dter(:) ! (knon)
-    ! Temperature variation in the diffusive microlayer, that is
-    ! ocean-air interface temperature minus subskin temperature. In
-    ! K.
-
-    REAL, intent(out):: dser(:) ! (knon)
-    ! Salinity variation in the diffusive microlayer, that is
-    ! ocean-air interface salinity minus subskin salinity. In ppt.
-
     REAL, intent(out):: tkt(:) ! (knon)
     ! épaisseur (m) de la couche de diffusion thermique (microlayer)
@@ -192,5 +195,5 @@
             qsurf, evap, fluxsens, fluxlat, flux_u1, flux_v1, &
             tsurf_new, dflux_s, dflux_l, sens_prec_liq, sss, delta_sal, rhoa, &
-            delta_sst)
+            delta_sst, dTer, dSer, dt_ds)
 
     CASE('slab')
@@ -331,5 +334,9 @@
        delta_sst = t_int - tsurf_new(:knon)
        delta_sal = s_int - sss(:knon)
-       if (activate_ocean_skin >= 2) tsurf_new(:knon) = t_int
+
+       if (activate_ocean_skin == 2) then
+          tsurf_new(:knon) = t_int
+          if (type_ocean == 'couple') dt_ds = (tks / tkt) * dter
+       end if
     end if
     
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_down.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_down.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_down.F90	(revision 4482)
@@ -0,0 +1,300 @@
+SUBROUTINE thermcell_updown_dq(ngrid,nlay,ptimestep,lmax,eup,dup,edn,ddn,masse,trac,dtrac)
+
+USE thermcell_ini_mod, ONLY: iflag_thermals_down
+
+
+!-----------------------------------------------------------------
+! thermcell_updown_dq: computes the tendency of tracers associated
+! with the presence of convective up/down drafts
+! This routine that has been collectively written during the 
+! "ateliers downdrafts" in 2022/2023
+! Maelle, Frédéric, Catherine, Fleur, Florent, Etienne
+!------------------------------------------------------------------
+
+
+   IMPLICIT NONE
+
+! declarations
+!==============================================================
+
+! input/output
+
+   integer,intent(in)  :: ngrid ! number of horizontal grid points
+   integer, intent(in) :: nlay  ! number of vertical layers
+   real,intent(in) :: ptimestep ! time step of the physics [s]
+   real,intent(in), dimension(ngrid,nlay) :: eup ! entrainment to updrafts * dz [same unit as flux]
+   real,intent(in), dimension(ngrid,nlay) :: dup ! detrainment from updrafts * dz [same unit as flux]
+   real,intent(in), dimension(ngrid,nlay) :: edn ! entrainment to downdrafts * dz [same unit as flux]
+   real,intent(in), dimension(ngrid,nlay) :: ddn ! detrainment from downdrafts * dz [same unit as flux]
+   real,intent(in), dimension(ngrid,nlay) :: masse ! mass of layers = rho dz 
+   real,intent(in), dimension(ngrid,nlay) :: trac ! tracer 
+   integer, intent(in), dimension(ngrid) :: lmax ! max level index at which downdraft are present
+   real,intent(out),dimension(ngrid,nlay) ::dtrac ! tendance du traceur
+
+   
+! Local
+
+   real, dimension(ngrid,nlay+1) :: fup,fdn,fc,fthu,fthd,fthe,fthtot
+   real, dimension(ngrid,nlay) :: tracu,tracd,traci,tracold
+   real :: www, mstar_inv
+   integer ig,ilay
+   real, dimension(ngrid,nlay):: s1,s2,num !coefficients pour la resolution implicite
+   integer :: iflag_impl=1 ! 0 pour explicite, 1 pour implicite "classique", 2 pour implicite avec entrainement et detrainement
+   
+   fdn(:,:)=0.
+   fup(:,:)=0.
+   fc(:,:)=0.
+   fthu(:,:)=0.
+   fthd(:,:)=0.
+   fthe(:,:)=0.
+   fthtot(:,:)=0.
+   tracd(:,:)=0.
+   tracu(:,:)=0.
+   traci(:,:)=trac(:,:)
+   tracold(:,:)=trac(:,:)
+   s1(:,:)=0.
+   s2(:,:)=0.
+   num(:,:)=1.
+
+   if ( iflag_thermals_down < 10 ) then
+      call abort_physic("thermcell_updown_dq", &
+           'thermcell_down_dq = 0 or >= 10', 1)
+   else
+        iflag_impl=iflag_thermals_down-10
+   endif
+      
+
+   ! lmax : indice tel que fu(kmax+1)=0
+   ! Dans ce cas, pas besoin d'initialiser tracd(lmax) ( =trac(lmax) )
+   ! Boucle pour le downdraft
+   do ilay=nlay,1,-1
+      do ig=1,ngrid
+         !if ( lmax(ig) > nlay - 2 ) stop "les thermiques montent trop haut"
+         if (ilay.le.lmax(ig) .and. lmax(ig)>1 ) then
+            fdn(ig,ilay)=fdn(ig,ilay+1)+edn(ig,ilay)-ddn(ig,ilay)
+            if ( fdn(ig,ilay)+ddn(ig,ilay) > 0. ) then
+               www=fdn(ig,ilay+1)/ (fdn(ig,ilay)+ddn(ig,ilay))
+            else
+               www=0.
+            endif
+            tracd(ig,ilay)=www*tracd(ig,ilay+1) + (1.-www)*trac(ig,ilay)
+         endif
+      enddo 
+   enddo !Fin boucle sur l'updraft
+   fdn(:,1)=0.
+
+   !Boucle pour l'updraft
+   do ilay=1,nlay,1
+      do ig=1,ngrid
+         if (ilay.lt.lmax(ig) .and. lmax(ig)>1) then
+            fup(ig,ilay+1)=fup(ig,ilay)+eup(ig,ilay)-dup(ig,ilay)
+            if (fup(ig,ilay+1)+dup(ig,ilay) > 0.) then
+               www=fup(ig,ilay)/(fup(ig,ilay+1)+dup(ig,ilay))
+            else
+               www=0.
+            endif
+            if (ilay == 1 ) then
+               tracu(ig,ilay)=trac(ig,ilay)
+            else
+               tracu(ig,ilay)=www*tracu(ig,ilay-1)+(1.-www)*trac(ig,ilay)
+            endif
+         endif
+      enddo 
+      enddo !fin boucle sur le downdraft
+
+   ! Calcul des flux des traceurs dans les updraft et les downdrfat 
+   ! et du flux de masse compensateur
+   ! en ilay=1 et nlay+1, fthu=0 et fthd=0
+   fthu(:,1)=0.
+   fthu(:,nlay+1)=0.
+   fthd(:,1)=0.
+   fthd(:,nlay+1)=0.
+   fc(:,1)=0.
+   fc(:,nlay+1)=0.
+   do ilay=2,nlay,1 !boucle sur les interfaces
+     do ig=1,ngrid
+       fthu(ig,ilay)=fup(ig,ilay)*tracu(ig,ilay-1)
+       fthd(ig,ilay)=-fdn(ig,ilay)*tracd(ig,ilay)
+       fc(ig,ilay)=fup(ig,ilay)-fdn(ig,ilay)
+     enddo
+   enddo
+   
+
+   !Boucle pour calculer le flux du traceur flux updraft, flux downdraft, flux compensatoire
+   !Methode explicite : 
+   if(iflag_impl==0) then
+     do ilay=2,nlay,1
+       do ig=1,ngrid
+         !!!!ATTENTION HYPOTHESE de FLUX COMPENSATOIRE DESCENDANT ET DONC comme schema amont on va chercher trac au dessus!!!!!
+         !!!! tentative de prise en compte d'un flux compensatoire montant  !!!!
+         if (fup(ig,ilay)-fdn(ig,ilay) .lt. 0.) then
+            call abort_physic("thermcell_updown_dq", 'flux compensatoire '&
+                 // 'montant, cas non traite par thermcell_updown_dq', 1)
+            !fthe(ig,ilay)=(fup(ig,ilay)-fdn(ig,ilay))*trac(ig,ilay-1)
+         else
+            fthe(ig,ilay)=-(fup(ig,ilay)-fdn(ig,ilay))*trac(ig,ilay)
+         endif
+         !! si on voulait le prendre en compte on
+         !fthe(ig,ilay)=-(fup(ig,ilay)-fdn(ig,ilay))*trac(ig,ilay-1)
+         fthtot(ig,ilay)=fthu(ig,ilay)+fthd(ig,ilay)+fthe(ig,ilay)
+       enddo
+     enddo
+     !Boucle pour calculer trac
+     do ilay=1,nlay
+       do ig=1,ngrid
+         dtrac(ig,ilay)=(fthtot(ig,ilay)-fthtot(ig,ilay+1))/masse(ig,ilay)
+!         trac(ig,ilay)=trac(ig,ilay) + (fthtot(ig,ilay)-fthtot(ig,ilay+1))*(ptimestep/masse(ig,ilay))
+       enddo
+     enddo !fin du calculer de la tendance du traceur avec la methode explicite
+
+   !!! Reecriture du schéma explicite avec les notations du schéma implicite
+   else if(iflag_impl==-1) then
+     write(*,*) 'nouveau schéma explicite !!!'
+     !!! Calcul de s1
+     do ilay=1,nlay
+       do ig=1,ngrid
+         s1(ig,ilay)=fthu(ig,ilay)-fthu(ig,ilay+1)+fthd(ig,ilay)-fthd(ig,ilay+1)
+         s2(ig,ilay)=s1(ig,ilay)+fthe(ig,ilay)-fthe(ig,ilay+1)
+       enddo
+     enddo
+
+     do ilay=2,nlay,1
+       do ig=1,ngrid
+         if (fup(ig,ilay)-fdn(ig,ilay) .lt. 0.) then
+            call abort_physic("thermcell_updown_dq", 'flux compensatoire ' &
+                 // 'montant, cas non traite par thermcell_updown_dq', 1)
+         else
+            fthe(ig,ilay)=-(fup(ig,ilay)-fdn(ig,ilay))*trac(ig,ilay)
+         endif
+         fthtot(ig,ilay)=fthu(ig,ilay)+fthd(ig,ilay)+fthe(ig,ilay)
+       enddo
+     enddo
+     !Boucle pour calculer trac
+     do ilay=1,nlay
+       do ig=1,ngrid
+         ! dtrac(ig,ilay)=(fthtot(ig,ilay)-fthtot(ig,ilay+1))/masse(ig,ilay)
+         dtrac(ig,ilay)=(s1(ig,ilay)+fthe(ig,ilay)-fthe(ig,ilay+1))/masse(ig,ilay)
+!         trac(ig,ilay)=trac(ig,ilay) + (fthtot(ig,ilay)-fthtot(ig,ilay+1))*(ptimestep/masse(ig,ilay))
+!         trac(ig,ilay)=trac(ig,ilay) + (s1(ig,ilay)+fthe(ig,ilay)-fthe(ig,ilay+1))*(ptimestep/masse(ig,ilay))
+       enddo
+     enddo !fin du calculer de la tendance du traceur avec la methode explicite
+
+   else if (iflag_impl==1) then
+     do ilay=1,nlay
+       do ig=1,ngrid
+         s1(ig,ilay)=fthu(ig,ilay)-fthu(ig,ilay+1)+fthd(ig,ilay)-fthd(ig,ilay+1)
+       enddo
+     enddo
+     
+     !Boucle pour calculer traci = trac((t+dt)
+     do ilay=nlay-1,1,-1
+       do ig=1,ngrid
+         if((fup(ig,ilay)-fdn(ig,ilay)) .lt. 0) then
+            write(*,*) 'flux compensatoire montant, cas non traite par thermcell_updown_dq dans le cas d une resolution implicite, ilay : ', ilay
+            call abort_physic("thermcell_updown_dq", "", 1)
+         else
+           mstar_inv=ptimestep/masse(ig,ilay)
+           traci(ig,ilay)=((traci(ig,ilay+1)*fc(ig,ilay+1)+s1(ig,ilay))*mstar_inv+tracold(ig,ilay))/(1.+fc(ig,ilay)*mstar_inv)
+         endif
+       enddo
+     enddo
+     do ilay=1,nlay
+       do ig=1,ngrid
+         dtrac(ig,ilay)=(traci(ig,ilay)-tracold(ig,ilay))/ptimestep
+       enddo
+     enddo
+
+   else
+      call abort_physic("thermcell_updown_dq", &
+           'valeur de iflag_impl non prevue', 1)
+   endif
+
+ RETURN
+   END
+
+!=========================================================================
+
+   SUBROUTINE thermcell_down(ngrid,nlay,po,pt,pu,pv,pplay,pplev,  &
+     &           lmax,fup,eup,dup,theta)
+
+!--------------------------------------------------------------
+!thermcell_down: calcul des propri??t??s du panache descendant.
+!--------------------------------------------------------------
+
+
+   USE thermcell_ini_mod, ONLY : prt_level,RLvCp,RKAPPA,RETV,fact_thermals_down
+   IMPLICIT NONE
+
+! arguments
+
+   integer,intent(in) :: ngrid,nlay
+   real,intent(in), dimension(ngrid,nlay) :: po,pt,pu,pv,pplay,eup,dup
+   real,intent(in), dimension(ngrid,nlay) :: theta
+   real,intent(in), dimension(ngrid,nlay+1) :: pplev,fup
+   integer, intent(in), dimension(ngrid) :: lmax
+
+
+   
+! Local
+
+   real, dimension(ngrid,nlay) :: edn,ddn,thetad
+   real, dimension(ngrid,nlay+1) :: fdn
+
+   integer ig,ilay
+   real dqsat_dT
+   logical mask(ngrid,nlay)
+
+   edn(:,:)=0.
+   ddn(:,:)=0.
+   fdn(:,:)=0.
+   thetad(:,:)=0.
+
+   ! lmax : indice tel que fu(kmax+1)=0
+   
+   ! Dans ce cas, pas besoin d'initialiser thetad(lmax) ( =theta(lmax) )
+
+! FH MODIFS APRES REUNIONS POUR COMMISSIONS
+! quelques erreurs de declaration
+! probleme si lmax=1 ce qui a l'air d'??tre le cas en d??but de simu. Devrait ??tre 0 ?
+! Remarques :
+! on pourrait ??crire la formule de thetad
+!    www=fdn(ig,ilay+1)/ (fdn(ig,ilay)+ddn(ig,ilay))
+!    thetad(ig,ilay)= www * thetad(ig,ilay+1) + (1.-www) * theta(ig,ilay) 
+! Elle a l'avantage de bien montr?? la conservation, l'id??e fondamentale dans le 
+!   transport qu'on ne fait que sommer des "sources" au travers d'un "propagateur"
+!   (Green)
+! Elle montre aussi beaucoup plus clairement pourquoi on n'a pas ?? se souccier (trop)
+!   de la possible nulit?? du d??nominateur
+
+
+   do ilay=nlay,1,-1
+      do ig=1,ngrid
+         if (ilay.le.lmax(ig).and.lmax(ig)>1) then
+            edn(ig,ilay)=fact_thermals_down*dup(ig,ilay)
+            ddn(ig,ilay)=fact_thermals_down*eup(ig,ilay)
+            fdn(ig,ilay)=fdn(ig,ilay+1)+edn(ig,ilay)-ddn(ig,ilay)
+            thetad(ig,ilay)=( fdn(ig,ilay+1)*thetad(ig,ilay+1) + edn(ig,ilay)*theta(ig,ilay) ) / (fdn(ig,ilay)+ddn(ig,ilay))
+         endif
+      enddo 
+   enddo
+
+   ! Suite du travail :
+   ! Ecrire la conservervation de theta_l dans le panache descendant
+   ! Eventuellement faire la transformation theta_l -> theta_v
+   ! Si l'air est sec (et qu'on oublie le c??t?? theta_v) on peut
+   ! se contenter de conserver theta.
+   !
+   ! Connaissant thetadn, on peut calculer la flotabilit??.
+   ! Connaissant la flotabilit??, on peut calculer w de proche en proche
+   ! On peut calculer le detrainement de facon ?? garder alpha*rho = cste
+   ! On en d??duit l'entrainement lat??ral
+   ! C'est le mod??le des mini-projets.
+
+!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+! Initialisations :
+!------------------
+
+
+!
+ RETURN
+   END
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_ini_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_ini_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_ini_mod.F90	(revision 4482)
@@ -3,9 +3,11 @@
 
 save
+
    integer :: dvdq=1,dqimpl=-1,prt_level=0,lunout
    real RG,RD,RCPD,RKAPPA,RLVTT,RLvCp,RETV
    real           :: r_aspect_thermals,tau_thermals,fact_thermals_ed_dz
    integer        :: iflag_thermals_ed,iflag_thermals_optflux,iflag_thermals_closure
-
+   integer        :: iflag_thermals_down
+   real           :: fact_thermals_down
 
 !$OMP THREADPRIVATE(dvdq,dqimpl,prt_level,lunout)
@@ -13,4 +15,7 @@
 !$OMP THREADPRIVATE(r_aspect_thermals,tau_thermals,fact_thermals_ed_dz)
 !$OMP THREADPRIVATE(iflag_thermals_ed,iflag_thermals_optflux,iflag_thermals_closure)
+!$OMP THREADPRIVATE(iflag_thermals_down)
+!$OMP THREADPRIVATE(fact_thermals_down)
+
 
    REAL, SAVE :: fact_epsilon=0.002
@@ -85,4 +90,10 @@
    CALL getin_p('iflag_thermals_closure',iflag_thermals_closure)
 
+   iflag_thermals_down = 0
+   CALL getin_p('iflag_thermals_down',iflag_thermals_down)
+
+   fact_thermals_down = 0.5
+   CALL getin_p('fact_thermals_down',fact_thermals_down)
+
      CALL getin_p('thermals_fact_epsilon',fact_epsilon)
      CALL getin_p('thermals_betalpha',betalpha)
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_main.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_main.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_main.F90	(revision 4482)
@@ -1,3 +1,2 @@
-
 ! $Id$
 !
@@ -19,4 +18,5 @@
       USE thermcell_ini_mod, ONLY: thermcell_ini,dqimpl,dvdq,prt_level,lunout,prt_level
       USE thermcell_ini_mod, ONLY: iflag_thermals_closure,iflag_thermals_ed,tau_thermals,r_aspect_thermals
+      USE thermcell_ini_mod, ONLY: iflag_thermals_down, fact_thermals_down
       USE thermcell_ini_mod, ONLY: RD,RG
 
@@ -134,4 +134,5 @@
       real, dimension(ngrid,nlay) :: zqsat,csc
       real, dimension(ngrid) :: zcon,zcon2,alim_star_tot,f
+      real, dimension(ngrid,nlay) :: entrdn,detrdn
 
       character (len=20) :: modname='thermcell_main'
@@ -455,4 +456,5 @@
      &       entr_star,detr_star,f,rhobarz,zlev,zw2,fm,entr,  &
      &       detr,zqla,lev_out,lunout1,igout)
+
 !IM 060508    &       detr,zqla,zmax,lev_out,lunout,igout)
 
@@ -478,12 +480,40 @@
       endif
 
+!------------------------------------------------------------------
+! Calcul de la fraction de l'ascendance
+!------------------------------------------------------------------
+      do ig=1,ngrid
+         fraca(ig,1)=0.
+         fraca(ig,nlay+1)=0.
+      enddo
+      do l=2,nlay
+         do ig=1,ngrid
+            if (zw2(ig,l).gt.1.e-10) then
+            fraca(ig,l)=fm(ig,l)/(rhobarz(ig,l)*zw2(ig,l))
+            else
+            fraca(ig,l)=0.
+            endif
+         enddo
+      enddo
+     
 !c------------------------------------------------------------------
 !   calcul du transport vertical
 !------------------------------------------------------------------
-
-      call thermcell_dq(ngrid,nlay,dqimpl,ptimestep,fm0,entr0,masse,  &
-     &                    zthl,zdthladj,zta,lev_out)
-      call thermcell_dq(ngrid,nlay,dqimpl,ptimestep,fm0,entr0,masse,  &
-     &                   po,pdoadj,zoa,lev_out)
+      IF (iflag_thermals_down .GT. 0) THEN
+        if (debut) print*,'WARNING !!! routine thermcell_down en cours de developpement'
+        entrdn=fact_thermals_down*detr0
+        detrdn=fact_thermals_down*entr0 
+        ! we want to transport potential temperature, total water and momentum
+        CALL thermcell_updown_dq(ngrid,nlay,ptimestep,lmax,entr0,detr0,entrdn,detrdn,masse,zthl,zdthladj)
+        CALL thermcell_updown_dq(ngrid,nlay,ptimestep,lmax,entr0,detr0,entrdn,detrdn,masse,po,pdoadj)
+        CALL thermcell_updown_dq(ngrid,nlay,ptimestep,lmax,entr0,detr0,entrdn,detrdn,masse,zu,pduadj)
+        CALL thermcell_updown_dq(ngrid,nlay,ptimestep,lmax,entr0,detr0,entrdn,detrdn,masse,zv,pdvadj)
+      ELSE
+      !--------------------------------------------------------------
+
+        call thermcell_dq(ngrid,nlay,dqimpl,ptimestep,fm0,entr0,masse,  &
+        &                    zthl,zdthladj,zta,lev_out)
+        call thermcell_dq(ngrid,nlay,dqimpl,ptimestep,fm0,entr0,masse,  &
+        &                   po,pdoadj,zoa,lev_out)
 
 #ifdef ISO
@@ -527,22 +557,4 @@
 
 
-
-!------------------------------------------------------------------
-! Calcul de la fraction de l'ascendance
-!------------------------------------------------------------------
-      do ig=1,ngrid
-         fraca(ig,1)=0.
-         fraca(ig,nlay+1)=0.
-      enddo
-      do l=2,nlay
-         do ig=1,ngrid
-            if (zw2(ig,l).gt.1.e-10) then
-            fraca(ig,l)=fm(ig,l)/(rhobarz(ig,l)*zw2(ig,l))
-            else
-            fraca(ig,l)=0.
-            endif
-         enddo
-      enddo
-     
 !------------------------------------------------------------------
 !  calcul du transport vertical du moment horizontal
@@ -569,4 +581,5 @@
 
       endif
+    ENDIF
 
 !     print*,'13 OK convect8'
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_plume_6A.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_plume_6A.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/thermcell_plume_6A.F90	(revision 4482)
@@ -138,4 +138,11 @@
       lmix_bis(:)=2
       wmaxa(:)=0.
+
+! Initialisation a 0  en cas de sortie dans replay
+      zqsat(:)=0.
+      zta_est(:,:)=0.
+      zdqt(:,:)=0.
+      zdqtjam(:,:)=0.
+      c2(:,:)=0.
 
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/tracco2i_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/tracco2i_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/tracco2i_mod.F90	(revision 4482)
@@ -103,5 +103,5 @@
     IF (debutphy) THEN
 
-! Initialisation de tr_seri(id_CO2) si pas initialise
+! Initialization of tr_seri(id_CO2) If it is not initialized
       IF (MAXVAL(tr_seri(:,:,id_CO2)).LT.1.e-15) THEN 
         tr_seri(:,:,id_CO2)=co2_ppm0*1.e-6/RMD*RMCO2 !--initialised from co2_ppm0 in rdem
@@ -226,5 +226,7 @@
 
       DO i=1, klon  
-          fco2_ocean_cor(i)=(var_fco2_ocean_cor*(RMCO2/RMC)*(pctsrf(i,is_oce)+pctsrf(i,is_sic))/ocean_area_tot/(secinday*year_len))*1.e12
+         fco2_ocean_cor(i)=(var_fco2_ocean_cor*(RMCO2/RMC) &
+              *(pctsrf(i,is_oce)+pctsrf(i,is_sic))/ocean_area_tot &
+              /(secinday*year_len))*1.e12
       ENDDO
 
@@ -305,7 +307,11 @@
 
 !--compute a global mean CO2 value and print its value in ppm
-       IF (is_mpi_root) THEN
+       IF (is_mpi_root .AND. is_omp_root) THEN
          RCO2_tot=SUM(co2_glo*m_air_glo)  !--unit kg CO2
          RCO2_glo=RCO2_tot/SUM(m_air_glo) !--unit kg CO2 / kg air
+         ! the following operation is only to maintain precision consistency
+         ! of RCO2_glo which differs whether it is directly computed or read from
+         ! a restart file (after having been computed)
+         RCO2_glo = FLOAT(INT(RCO2_glo * 1e8))/1e8
          PRINT *,'tracco2i: global CO2 in ppm =', RCO2_glo*1.e6*RMD/RMCO2
          PRINT *,'tracco2i: total CO2 in kg =', RCO2_tot
@@ -314,4 +320,5 @@
        CALL bcast(RCO2_glo)
        day_pre=day_cur
+
 !--if not carbon_cycle_tr, then we reinitialize the CO2 each day to its global mean value
        IF (.NOT.carbon_cycle_tr) THEN 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/tracinca_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/tracinca_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/tracinca_mod.F90	(revision 4482)
@@ -12,4 +12,5 @@
                      ! config_inca='chem' => INCA with chemistry
                      ! config_inca='aero' => INCA with aerosols
+                     ! config_inca='aeNP' => INCA with aerosols NP (?)
 CONTAINS
 
@@ -17,6 +18,5 @@
     ! This subroutine initialize some control varaibles. 
 
-    USE infotrac_phy, ONLY: nbtr
-    USE ioipsl_getin_p_mod, ONLY: getin_p
+    USE infotrac_phy, ONLY: nbtr, type_trac
     IMPLICIT NONE
     
@@ -25,8 +25,15 @@
     LOGICAL,INTENT(OUT) :: lessivage
     
-    
     ! Initialization
     lessivage  =.FALSE.
     aerosol(:) = .FALSE.
+
+    !--- COHERENCE TEST BETWEEN "type_trac" AND "config_inca"
+    IF(ANY(type_trac == ['inca','inco']) .AND. ALL(config_inca /= ['aero','aeNP','chem'])) CALL abort_gcm('tracinca_init', &
+       'INCA enabled, but unknown config_inca = "'//TRIM(config_inca)//'". Please modify "run.def"', 1)
+
+    !--- PROBLEM IF "config_inca" DIFFERS FROM "none" AND INCA HAS NOT BEEN ACTIVATED
+    IF(ALL(type_trac /= ['inca','inco'])  .AND.    config_inca /= 'none')                  CALL abort_gcm('tracinca_init', &
+       'INCA disabled, but config_inca = "'//TRIM(config_inca)//'" should be "none". Please modify "run.def"', 1)
 
   END SUBROUTINE tracinca_init
@@ -82,5 +89,5 @@
     REAL,DIMENSION(klon,klev),INTENT(IN)   :: pphi    ! geopotentiel
     REAL,DIMENSION(klon),INTENT(IN)        :: pphis
-    REAL,DIMENSION(klon,klev),INTENT(IN)   :: cldliq  ! eau liquide nuageuse
+    REAL,DIMENSION(klon,klev),INTENT(IN)   :: cldliq  ! eau condensee pour le radiatif
     REAL,DIMENSION(klon,klev),INTENT(IN)   :: cldfra  ! fraction nuageuse (tous les nuages)
     REAL,DIMENSION(klon,klev),INTENT(IN)   :: diafra  ! fraction nuageuse (convection ou stratus artificiels)
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/traclmdz_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/traclmdz_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/traclmdz_mod.F90	(revision 4482)
@@ -96,5 +96,4 @@
     USE indice_sol_mod
     USE print_control_mod, ONLY: lunout
-    USE strings_mod, ONLY: strLower
 
 ! Input variables
@@ -175,24 +174,24 @@
     it = 0
     DO iq = 1, nqtot
-       IF(.NOT.(tracers(iq)%isAdvected .AND. tracers(iq)%isInPhysics)) CYCLE
+       IF(.NOT.(tracers(iq)%isInPhysics)) CYCLE
        it = it+1
-       SELECT CASE(strLower(tracers(iq)%name))
-         CASE("rn");      id_rn     = it ! radon
-         CASE("pb");      id_pb     = it ! plomb
-         CASE("aga");     id_aga    = it ! Age of stratospheric air
-         CASE("be","be7");id_be     = it ! Recherche du Beryllium 7
-         CASE("o3");      id_o3     = it ! Recherche de l'ozone
-         CASE("pcsat");   id_pcsat  = it
-         CASE("pcocsat"); id_pcocsat= it
-         CASE("pcq");     id_pcq    = it
-         CASE("pcs0");    id_pcs0   = it
-         CASE("pcos0");   id_pcos0  = it
-         CASE("pcq0");    id_pcq0   = it
+       SELECT CASE(tracers(iq)%name)
+         CASE("RN");                  id_rn     = it ! radon
+         CASE("PB");                  id_pb     = it ! plomb
+         CASE("Aga","AGA");           id_aga    = it ! Age of stratospheric air
+         CASE("Be","BE","Be7","BE7"); id_be     = it ! Recherche du Beryllium 7
+         CASE("o3","O3");             id_o3     = it ! Recherche de l'ozone
+         CASE("pcsat",  "Pcsat");     id_pcsat  = it
+         CASE("pcocsat","Pcocsat");   id_pcocsat= it
+         CASE("pcq",    "Pcq");       id_pcq    = it
+         CASE("pcs0",   "Pcs0");      id_pcs0   = it
+         CASE("pcos0",  "Pcos0");     id_pcos0  = it
+         CASE("pcq0",   "Pcq0");      id_pcq0   = it
          CASE DEFAULT
            WRITE(lunout,*) 'This is an unknown tracer in LMDZ : ', trim(tracers(iq)%name)
        END SELECT
 
-       SELECT CASE(strLower(tracers(iq)%name))
-         CASE("pb")                        !--- RomP >>> profil initial de PB210 
+       SELECT CASE(tracers(iq)%name)
+         CASE("PB")                        !--- RomP >>> profil initial de PB210 
            OPEN(ilesfil2,file='prof.pb210',status='old',iostat=irr2)
            IF(irr2 == 0) THEN 
@@ -203,7 +202,7 @@
              tr_seri(:,:,id_pb) = plomb(:,:)
            ELSE
-             WRITE(lunout,*)'Prof. Pb210 does not exist: use restart values'
+             WRITE(lunout,*)'prof.pb210 does not exist: use restart values'
            END IF
-         CASE("aga")
+         CASE("Aga","AGA")
            radio(id_aga) = .FALSE.
            aerosol(id_aga) = .FALSE.
@@ -217,5 +216,5 @@
               lev_1p5km=klev/2
            END IF
-         CASE("be","be7")
+         CASE("Be","BE","Be7","BE7")
            ALLOCATE( srcbe(klon,klev) )
            radio(id_be) = .TRUE.
@@ -234,8 +233,8 @@
              WRITE(lunout,*)'Prof. Be7 does not exist: use restart values'
            END IF
-         CASE("o3")                         !--- Parametrisation par la chimie de Cariolle
+         CASE("o3","O3")                    !--- Parametrisation par la chimie de Cariolle
            CALL alloc_coefoz                !--- Allocate ozone coefficients
            CALL press_coefoz                !--- Read input pressure levels
-         CASE("pcs0","pcos0","pcq0")
+         CASE("pcs0","Pcs0", "pcos0","Pcos0", "pcq0","Pcq0")
            conv_flg(it)=0                   !--- No transport by convection for this tracer
        END SELECT
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/transp.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/transp.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/transp.F90	(revision 4482)
@@ -2,6 +2,6 @@
 ! $Id$
 
-SUBROUTINE transp(paprs, tsol, t, q, ql, qs, u, v, geom, vtran_e, vtran_q, utran_e, &
-    utran_q, vtran_w, utran_w)
+SUBROUTINE transp(paprs, tsol, t, q, ql, qs, u, v, geom, & 
+                  utran_e, vtran_e, utran_q, vtran_q, utran_w, vtran_w)
 
   USE dimphy
@@ -15,37 +15,43 @@
   include "YOMCST.h"
 
-  REAL paprs(klon, klev+1), tsol(klon)
-  REAL t(klon, klev), q(klon, klev), ql(klon, klev), qs(klon, klev)
-  REAL u(klon, klev), v(klon, klev)
-  REAL utran_e(klon), utran_q(klon), vtran_e(klon), vtran_q(klon)
-  REAL utran_w(klon), vtran_w(klon)
+  !--inputs
+  REAL, INTENT(IN)  :: paprs(klon, klev+1), tsol(klon), geom(klon, klev)
+  REAL, INTENT(IN)  :: t(klon, klev), q(klon, klev), ql(klon, klev), qs(klon, klev)
+  REAL, INTENT(IN)  :: u(klon, klev), v(klon, klev)
+  !--outputs
+  REAL, INTENT(OUT) :: utran_e(klon), vtran_e(klon) !--lateral flux of dry static energy (J m-1 s-1)
+  REAL, INTENT(OUT) :: utran_q(klon), vtran_q(klon) !--lateral flux of water vapour (kg m-1 s-1)
+  REAL, INTENT(OUT) :: utran_w(klon), vtran_w(klon) !--lateral flux of total water (kg m-1 s-1)
+  !--local variables
+  INTEGER i, l
+  REAL e, dm
+  ! ------------------------------------------------------------------
 
-  INTEGER i, l
-  ! ------------------------------------------------------------------
-  REAL geom(klon, klev), e
-  ! ------------------------------------------------------------------
-  DO i = 1, klon
-    utran_e(i) = 0.0
-    utran_q(i) = 0.0
-    vtran_e(i) = 0.0
-    vtran_q(i) = 0.0
-    utran_w(i) = 0.0
-    vtran_w(i) = 0.0
-  END DO
+  !--initialisations
+  utran_e(:) = 0.0
+  utran_q(:) = 0.0
+  vtran_e(:) = 0.0
+  vtran_q(:) = 0.0
+  utran_w(:) = 0.0
+  vtran_w(:) = 0.0
 
+  !--vertical integration of diagnostics
   DO l = 1, klev
     DO i = 1, klon
+      dm= (paprs(i,l)-paprs(i,l+1))/RG  !--mass of layer kg m-2
+      !--moist static energy
 !      e = rcpd*t(i, l) + rlvtt*q(i, l) + geom(i, l)
+      !--dry static energy
       e = rcpd*t(i, l) + geom(i, l)
-      utran_e(i) = utran_e(i) + u(i, l)*e*(paprs(i,l)-paprs(i,l+1))/rg
-      utran_q(i) = utran_q(i) + u(i, l)*q(i, l)*(paprs(i,l)-paprs(i,l+1))/rg
-      utran_w(i) = utran_w(i) + u(i, l)*(q(i, l)+ql(i, l)+qs(i, l))           &
-                                       *(paprs(i,l)-paprs(i,l+1))/rg
-      vtran_e(i) = vtran_e(i) + v(i, l)*e*(paprs(i,l)-paprs(i,l+1))/rg
-      vtran_q(i) = vtran_q(i) + v(i, l)*q(i, l)*(paprs(i,l)-paprs(i,l+1))/rg
-      vtran_w(i) = vtran_w(i) + v(i, l)*(q(i, l)+ql(i, l)+qs(i, l))           &
-                                       *(paprs(i,l)-paprs(i,l+1))/rg
-    END DO
-  END DO
+      utran_e(i) = utran_e(i) + u(i, l)*e*dm
+      vtran_e(i) = vtran_e(i) + v(i, l)*e*dm
+      !--water vapour
+      utran_q(i) = utran_q(i) + u(i, l)*q(i,l)*dm 
+      vtran_q(i) = vtran_q(i) + v(i, l)*q(i,l)*dm
+      !--total water
+      utran_w(i) = utran_w(i) + u(i, l)*(q(i,l)+ql(i,l)+qs(i,l))*dm 
+      vtran_w(i) = vtran_w(i) + v(i, l)*(q(i,l)+ql(i,l)+qs(i,l))*dm
+    ENDDO
+  ENDDO
 
   RETURN
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/wake.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/wake.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/wake.F90	(revision 4482)
@@ -7,10 +7,10 @@
                 dtdwn, dqdwn, amdwn, amup, dta, dqa, wgen, &
                 sigd_con, Cin, &
-                deltatw, deltaqw, sigmaw, awdens, wdens, &                  ! state variables
+                deltatw, deltaqw, sigmaw, awdens, wdens, &                  ! state variables           
                 dth, hw, wape, fip, gfl, &
                 dtls, dqls, ktopw, omgbdth, dp_omgb, tu, qu, &
                 dtke, dqke, omg, dp_deltomg, wkspread, cstar, &
-                d_deltat_gw, &
-                d_deltatw2, d_deltaqw2, d_sigmaw2, d_awdens2, d_wdens2)     ! tendencies
+                d_deltat_gw, &                                                      ! tendencies
+                d_deltatw2, d_deltaqw2, d_sigmaw2, d_awdens2, d_wdens2)             ! tendencies
 
 
@@ -27,8 +27,9 @@
   USE wake_ini_mod , ONLY : wake_ini
   USE wake_ini_mod , ONLY : prt_level,epsim1,RG,RD
-  USE wake_ini_mod , ONLY : stark, wdens_ref, coefgw, alpk, wdens_ref, stark, coefgw, alpk
+  USE wake_ini_mod , ONLY : stark, wdens_ref, coefgw, alpk, wk_pupper
   USE wake_ini_mod , ONLY : crep_upper, crep_sol, tau_cv, rzero, aa0, flag_wk_check_trgl
   USE wake_ini_mod , ONLY : iflag_wk_act, iflag_wk_check_trgl, iflag_wk_pop_dyn, wdensmin
   USE wake_ini_mod , ONLY : sigmad, hwmin, wapecut, cstart, sigmaw_max, dens_rate, epsilon_loc
+  USE wake_ini_mod , ONLY : iflag_wk_profile
 
 
@@ -119,10 +120,10 @@
   ! wdens_ref: initial number of wakes per unit area (3D) or per
   ! unit length (2D), at the beginning of each time step
-  ! Tgw    : 1 sur la période de onde de gravité
-  ! Cgw    : vitesse de propagation de onde de gravité
+  ! Tgw    : 1 sur la periode de onde de gravite
+  ! Cgw    : vitesse de propagation de onde de gravite
   ! LL     : distance entre 2 poches
 
   ! -------------------------------------------------------------------------
-  ! Déclaration de variables
+  ! Declaration de variables
   ! -------------------------------------------------------------------------
 
@@ -163,8 +164,9 @@
   REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: omgbdth, omg
   REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: dp_omgb, dp_deltomg
-  REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: d_deltat_gw
   REAL, DIMENSION (klon),           INTENT(OUT)         :: hw, wape, fip, gfl, cstar
   INTEGER, DIMENSION (klon),        INTENT(OUT)         :: ktopw
-  ! Tendencies of state variables
+  ! Tendencies of state variables (2 is appended to the names of fields which are the cumul of fields 
+  !                                 computed at each sub-timestep; e.g. d_wdens2 is the cumul of d_wdens)
+  REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: d_deltat_gw
   REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: d_deltatw2, d_deltaqw2
   REAL, DIMENSION (klon),           INTENT(OUT)         :: d_sigmaw2, d_awdens2, d_wdens2
@@ -173,5 +175,5 @@
   ! -------------------
 
-  ! Variables à fixer
+  ! Variables a fixer
 
   REAL                                                  :: delta_t_min
@@ -188,14 +190,22 @@
 !!  REAL, DIMENSION (klon)                                :: sigmaw1
 
-  ! Variables liees a la dynamique de population
+  ! Variables liees a la dynamique de population 1
   REAL, DIMENSION(klon)                                 :: act
   REAL, DIMENSION(klon)                                 :: rad_wk, tau_wk_inv
   REAL, DIMENSION(klon)                                 :: f_shear
   REAL, DIMENSION(klon)                                 :: drdt
-  REAL, DIMENSION(klon)                                 :: d_sig_gen, d_sig_death, d_sig_col
+  
+  ! Variables liees a la dynamique de population 2
+  REAL, DIMENSION(klon)                                 :: cont_fact  
+  
+!!  REAL, DIMENSION(klon)                                 :: d_sig_gen, d_sig_death, d_sig_col
   REAL, DIMENSION(klon)                                 :: wape1_act, wape2_act
   LOGICAL, DIMENSION (klon)                             :: kill_wake
   REAL                                                  :: drdt_pos
   REAL                                                  :: tau_wk_inv_min
+  ! Some components of the tendencies of state variables  
+  REAL, DIMENSION (klon)                                :: d_sig_gen2, d_sig_death2, d_sig_col2, d_sig_spread2, d_sig_bnd2
+  REAL, DIMENSION (klon)                                :: d_dens_gen2, d_dens_death2, d_dens_col2, d_dens_bnd2
+  REAL, DIMENSION (klon)                                :: d_adens_death2, d_adens_icol2, d_adens_acol2, d_adens_bnd2
 
   ! Variables pour les GW
@@ -219,6 +229,9 @@
   REAL, DIMENSION (klon, klev)                          :: d_deltatw, d_deltaqw
   REAL, DIMENSION (klon, klev)                          :: d_tenv, d_qe
-  REAL, DIMENSION (klon)                                :: d_awdens, d_wdens
-  REAL, DIMENSION (klon)                                :: d_sigmaw, alpha
+  REAL, DIMENSION (klon)                                :: d_awdens, d_wdens, d_sigmaw 
+  REAL, DIMENSION (klon)                                :: d_sig_gen, d_sig_death, d_sig_col, d_sig_spread, d_sig_bnd
+  REAL, DIMENSION (klon)                                :: d_dens_gen, d_dens_death, d_dens_col, d_dens_bnd
+  REAL, DIMENSION (klon)                                :: d_adens_death, d_adens_icol, d_adens_acol, d_adens_bnd
+  REAL, DIMENSION (klon)                                :: alpha, alpha_tot
   REAL, DIMENSION (klon)                                :: q0_min, q1_min
   LOGICAL, DIMENSION (klon)                             :: wk_adv, ok_qx_qw
@@ -227,6 +240,8 @@
   INTEGER                                               ::isubstep, k, i, igout
 
+  REAL                                                  :: sigmaw_targ
   REAL                                                  :: wdens_targ
-  REAL                                                  :: sigmaw_targ
+  REAL                                                  :: d_sigmaw_targ
+  REAL                                                  :: d_wdens_targ
 
   REAL, DIMENSION (klon)                                :: sum_thu, sum_tu, sum_qu, sum_thvu
@@ -276,5 +291,4 @@
   REAL, DIMENSION(klon)                                 :: awdens_in, wdens_in   ! pour les prints
 
-
   ! -------------------------------------------------------------------------
   ! Initialisations
@@ -289,7 +303,7 @@
   ! Configuration de coefgw,stark,wdens (22/02/06 by YU Jingmei)
 
-  ! coefgw : Coefficient pour les ondes de gravité
+  ! coefgw : Coefficient pour les ondes de gravite
   ! stark : Coefficient k dans Cstar=k*sqrt(2*WAPE)
-  ! wdens : Densité surfacique de poche froide
+  ! wdens : Densite surfacique de poche froide
   ! -------------------------------------------------------------------------
 
@@ -304,6 +318,5 @@
   ! alpk = 0.5
   ! alpk = 0.05
-
-
+!print *,'XXXX dtime input ', dtime
  igout = klon/2+1/klon
 
@@ -380,33 +393,4 @@
    sigmaw_in(:) = sigmaw(:)
 !>jyg
-
-  ! sigmaw1=sigmaw
-  ! IF (sigd_con.GT.sigmaw1) THEN
-  ! print*, 'sigmaw,sigd_con', sigmaw, sigd_con
-  ! ENDIF
-  IF (iflag_wk_pop_dyn >=1) THEN
-    DO i = 1, klon
-      wdens_targ = max(wdens(i),wdensmin)
-      d_wdens2(i) = wdens_targ - wdens(i)
-      wdens(i) = wdens_targ
-    END DO
-  ELSE
-    DO i = 1, klon
-      d_awdens2(i) = 0.
-      d_wdens2(i) = 0.
-    END DO
-  ENDIF  ! (iflag_wk_pop_dyn >=1)
-!
-  DO i = 1, klon
-    ! c      sigmaw(i) = amax1(sigmaw(i),sigd_con(i))
-!jyg<
-!!    sigmaw(i) = amax1(sigmaw(i), sigmad)
-!!    sigmaw(i) = amin1(sigmaw(i), 0.99)
-    sigmaw_targ = min(max(sigmaw(i), sigmad),0.99)
-    d_sigmaw2(i) = sigmaw_targ - sigmaw(i)
-    sigmaw(i) = sigmaw_targ
-!>jyg
-  END DO
-
 !
   IF (iflag_wk_pop_dyn >= 1) THEN
@@ -417,4 +401,57 @@
 !!  ELSE
   ENDIF  ! (iflag_wk_pop_dyn >= 1)
+
+
+  ! sigmaw1=sigmaw
+  ! IF (sigd_con.GT.sigmaw1) THEN
+  ! print*, 'sigmaw,sigd_con', sigmaw, sigd_con
+  ! ENDIF
+  IF (iflag_wk_pop_dyn >= 1) THEN
+    DO i = 1, klon
+      d_dens_gen2(i)   = 0.
+      d_dens_death2(i) = 0.
+      d_dens_col2(i)   = 0.
+      d_awdens2(i) = 0.
+!
+      wdens_targ = max(wdens(i),wdensmin)
+      d_dens_bnd2(i) = wdens_targ - wdens(i)
+      d_wdens2(i) = wdens_targ - wdens(i)
+      wdens(i) = wdens_targ
+    END DO
+    IF (iflag_wk_pop_dyn == 2) THEN
+       DO i = 1, klon  
+          d_adens_death2(i) = 0.
+          d_adens_icol2(i) = 0.
+          d_adens_acol2(i) = 0.
+!      
+          wdens_targ = min(max(awdens(i),0.),wdens(i))
+          d_adens_bnd2(i) = wdens_targ - awdens(i)
+          d_awdens2(i) = wdens_targ - awdens(i)
+          awdens(i) = wdens_targ
+       END DO
+    ENDIF ! (iflag_wk_pop_dyn == 2)
+  ELSE  
+    DO i = 1, klon
+      d_awdens2(i) = 0.
+      d_wdens2(i) = 0.
+    END DO
+  ENDIF  ! (iflag_wk_pop_dyn >= 1)
+!
+  DO i = 1, klon
+    ! c      sigmaw(i) = amax1(sigmaw(i),sigd_con(i))
+!jyg<
+!!    sigmaw(i) = amax1(sigmaw(i), sigmad)
+!!    sigmaw(i) = amin1(sigmaw(i), 0.99)
+    d_sig_gen2(i)   = 0.
+    d_sig_death2(i) = 0.
+    d_sig_col2(i)   = 0.
+    d_sig_spread2(i)= 0.
+    sigmaw_targ = min(max(sigmaw(i), sigmad),0.99)
+    d_sig_bnd2(i) = sigmaw_targ - sigmaw(i)
+    d_sigmaw2(i) = sigmaw_targ - sigmaw(i)
+!  print *,'XXXX1 d_sigmaw2(i), sigmaw(i) ', d_sigmaw2(i), sigmaw(i)
+    sigmaw(i) = sigmaw_targ
+!>jyg
+  END DO
 
   wape(:) = 0.
@@ -446,4 +483,5 @@
 dp_omgbw(:,:) = 0.
 omgbdq(:,:) = 0.
+
 !>jyg
 !
@@ -572,17 +610,7 @@
   END DO
 
-
+  
   ! Choose an integration bound well above wake top
   ! -----------------------------------------------------------------
-
-  ! Pupper = 50000.  ! melting level
-  ! Pupper = 60000.
-  ! Pupper = 80000.  ! essais pour case_e
-  DO i = 1, klon
-    pupper(i) = 0.6*ph(i, 1)
-    pupper(i) = max(pupper(i), 45000.)
-    ! cc        Pupper(i) = 60000.
-  END DO
-
 
   ! Determine Wake top pressure (Ptop) from buoyancy integral
@@ -657,16 +685,13 @@
   ! -5/ Determination de ktop et kupper
 
+  CALL pkupper (klon, klev, ptop, ph, pupper, kupper)
+  
   DO k = klev, 1, -1
     DO i = 1, klon
       IF (ph(i,k+1)<ptop(i)) ktop(i) = k
-      IF (ph(i,k+1)<pupper(i)) kupper(i) = k
-    END DO
-  END DO
-
-  ! On evite kupper = 1 et kupper = klev
-  DO i = 1, klon
-    kupper(i) = max(kupper(i), 2)
-    kupper(i) = min(kupper(i), klev-1)
-  END DO
+    END DO
+  END DO
+  !print*, 'ptop, pupper, ktop, kupper', ptop, pupper, ktop, kupper
+ 
 
 
@@ -808,5 +833,7 @@
 !!      sigmaw(i) = amax1(sigmad, sigd_con(i))
       sigmaw_targ = max(sigmad, sigd_con(i))
+      d_sig_bnd2(i) = d_sig_bnd2(i) + sigmaw_targ - sigmaw(i)
       d_sigmaw2(i) = d_sigmaw2(i) + sigmaw_targ - sigmaw(i)
+!  print *,'XXXX2 d_sigmaw2(i), sigmaw(i) ', d_sigmaw2(i), sigmaw(i)
       sigmaw(i) = sigmaw_targ
 !>jyg
@@ -840,4 +867,5 @@
     ok_qx_qw(i) = q0_min(i) >= 0.
     alpha(i) = 1.
+    alpha_tot(i) = 1.
   END DO
 
@@ -855,7 +883,12 @@
   dtimesub = dtime/nsub
 
+
+  
   ! ------------------------------------------------------------
   DO isubstep = 1, nsub
     ! ------------------------------------------------------------
+  CALL pkupper (klon, klev, ptop, ph, pupper, kupper)
+ 
+    !print*, 'ptop, pupper, ktop, kupper', ptop, pupper, ktop, kupper
 
     ! wk_adv is the logical flag enabling wake evolution in the time advance
@@ -867,9 +900,10 @@
       PRINT *, 'wake-4.1, isubstep,wk_adv(igout),cstar(igout),wape(igout), ptop(igout) ', &
                           isubstep,wk_adv(igout),cstar(igout),wape(igout), ptop(igout)
+     
     ENDIF
 
     ! cc nrlmd   Ajout d'un recalcul de wdens dans le cas d'un entrainement
-    ! négatif de ktop à kupper --------
-    ! cc           On calcule pour cela une densité wdens0 pour laquelle on
+    ! negatif de ktop a kupper --------
+    ! cc           On calcule pour cela une densite wdens0 pour laquelle on
     ! aurait un entrainement nul ---
     !jyg<
@@ -878,5 +912,5 @@
     ! des descentes unsaturees. Nous faisons alors l'hypothese que la 
     ! convection profonde cree directement de nouvelles poches, sans passer 
-    ! par les thermiques. La nouvelle valeur de wdens est alors imposée.
+    ! par les thermiques. La nouvelle valeur de wdens est alors imposee.
 
     DO i = 1, klon
@@ -884,6 +918,10 @@
       ! c     $           isubstep,wk_adv(i),cstar(i),wape(i)
       IF (wk_adv(i) .AND. cstar(i)>0.01) THEN
-        omg(i, kupper(i)+1) = -RG*amdwn(i, kupper(i)+1)/sigmaw(i) + &
+        IF ( iflag_wk_profile == 0 ) THEN
+           omg(i, kupper(i)+1)=-RG*amdwn(i, kupper(i)+1)/sigmaw(i) + &
                                RG*amup(i, kupper(i)+1)/(1.-sigmaw(i))
+        ELSE
+           omg(i, kupper(i)+1)=0.
+        ENDIF
         wdens0 = (sigmaw(i)/(4.*3.14))* &
           ((1.-sigmaw(i))*omg(i,kupper(i)+1)/((ph(i,1)-pupper(i))*cstar(i)))**(2)
@@ -894,4 +932,5 @@
         IF (wdens(i)<=wdens0*1.1) THEN
           IF (iflag_wk_pop_dyn >= 1) THEN
+             d_dens_bnd2(i) = d_dens_bnd2(i) + wdens0 - wdens(i)
              d_wdens2(i) = d_wdens2(i) + wdens0 - wdens(i)
           ENDIF
@@ -908,5 +947,7 @@
 !!        sigmaw(i) = amin1(sigmaw(i), sigmaw_max)
         sigmaw_targ = min(sigmaw(i), sigmaw_max)
+        d_sig_bnd2(i) = d_sig_bnd2(i) + sigmaw_targ - sigmaw(i)
         d_sigmaw2(i) = d_sigmaw2(i) + sigmaw_targ - sigmaw(i)
+!  print *,'XXXX3 d_sigmaw2(i), sigmaw(i) ', d_sigmaw2(i), sigmaw(i)
         sigmaw(i) = sigmaw_targ
 !>jyg
@@ -914,68 +955,40 @@
     END DO
 
-    IF (iflag_wk_pop_dyn >= 1) THEN
+    IF (iflag_wk_pop_dyn == 1) THEN
+  
+     CALL wake_popdyn_1 (klon, klev, dtime, cstar, tau_wk_inv, wgen, wdens, awdens, sigmaw, &
+                  dtimesub, gfl, rad_wk, f_shear, drdt_pos, &
+                  d_awdens, d_wdens, d_sigmaw, &
+                  iflag_wk_act, wk_adv, cin, wape, &
+                  drdt, &
+                  d_dens_gen, d_dens_death, d_dens_col, d_dens_bnd, &
+                  d_sig_gen, d_sig_death, d_sig_col, d_sig_spread, d_sig_bnd, &
+                  d_wdens_targ, d_sigmaw_targ)
+                      
 !    The variable "death_rate" is significant only when iflag_wk_pop_dyn = 0.
 !    Here, it has to be set to zero.
       death_rate(:) = 0.
-
-      IF (iflag_wk_act ==2) THEN
+    
+    ELSEIF (iflag_wk_pop_dyn == 2) THEN
+     CALL wake_popdyn_2 ( klon, klev, wk_adv, dtimesub, wgen, &
+                             sigmaw, wdens, awdens, &   !! states variables
+                             gfl, cstar, cin, wape, rad_wk, &
+                             d_sigmaw, d_wdens, d_awdens, &  !! tendences                              
+                             cont_fact, &
+                             d_sig_gen, d_sig_death, d_sig_col, d_sig_spread, d_sig_bnd, &
+                             d_dens_gen, d_dens_death, d_dens_col, d_dens_bnd, &
+                             d_adens_death, d_adens_icol, d_adens_acol, d_adens_bnd )
+     death_rate(:) = 0.
+sigmaw=sigmaw-d_sigmaw
+wdens=wdens-d_wdens
+awdens=awdens-d_awdens
+   
+    ELSEIF (iflag_wk_pop_dyn == 0) THEN
+    
+    ! cc nrlmd
+
       DO i = 1, klon
         IF (wk_adv(i)) THEN
-          wape1_act(i) = abs(cin(i))
-          wape2_act(i) = 2.*wape1_act(i) + 1.
-          act(i) = min(1., max(0., (wape(i)-wape1_act(i)) / (wape2_act(i)-wape1_act(i)) ))
-        ENDIF  ! (wk_adv(i))
-      ENDDO
-      ENDIF  ! (iflag_wk_act ==2)
-
-
-      DO i = 1, klon
-        IF (wk_adv(i)) THEN
-!!          tau_wk(i) = max(rad_wk(i)/(3.*cstar(i))*((cstar(i)/cstart)**1.5 - 1), 100.)
-          tau_wk_inv(i) = max( (3.*cstar(i))/(rad_wk(i)*((cstar(i)/cstart)**1.5 - 1)), 0.)
-          tau_wk_inv_min = min(tau_wk_inv(i), 1./dtimesub)
-          drdt(i) = (cstar(i) - wgen(i)*(sigmaw(i)/wdens(i)-aa0)/gfl(i)) / &
-                    (1 + 2*f_shear(i)*(2.*sigmaw(i)-aa0*wdens(i)) - 2.*sigmaw(i))
-!!                    (1 - 2*sigmaw(i)*(1.-f_shear(i)))
-          drdt_pos=max(drdt(i),0.)
-
-!!          d_wdens(i) = ( wgen(i)*(1.+2.*(sigmaw(i)-sigmad)) &
-!!                     - wdens(i)*tau_wk_inv_min &
-!!                     - 2.*gfl(i)*wdens(i)*Cstar(i) )*dtimesub
-          d_awdens(i) = ( wgen(i) - (1./tau_cv)*(awdens(i) - act(i)*wdens(i)) )*dtimesub
-          d_wdens(i) = ( wgen(i) - (wdens(i)-awdens(i))*tau_wk_inv_min -  &
-                         2.*wdens(i)*gfl(i)*drdt_pos )*dtimesub
-          d_wdens(i) = max(d_wdens(i), wdensmin-wdens(i))
-
-!!          d_sigmaw(i) = ( (1.-2*f_shear(i)*sigmaw(i))*(gfl(i)*Cstar(i)+wgen(i)*sigmad/wdens(i)) &
-!!                      + 2.*f_shear(i)*wgen(i)*sigmaw(i)**2/wdens(i) &
-!!                      - sigmaw(i)*tau_wk_inv_min )*dtimesub
-          d_sig_gen(i) = wgen(i)*aa0
-          d_sig_death(i) = - sigmaw(i)*(1.-awdens(i)/wdens(i))*tau_wk_inv_min
-!!          d_sig_col(i) = - 2*f_shear(i)*sigmaw(i)*gfl(i)*drdt_pos
-          d_sig_col(i) = - 2*f_shear(i)*(2.*sigmaw(i)-wdens(i)*aa0)*gfl(i)*drdt_pos
-          d_sigmaw(i) = ( d_sig_gen(i) + d_sig_death(i) + d_sig_col(i) + gfl(i)*cstar(i) )*dtimesub
-          d_sigmaw(i) = max(d_sigmaw(i), sigmad-sigmaw(i))
-        ENDIF
-      ENDDO
-
-      IF (prt_level >= 10) THEN
-        print *,'wake, cstar(1), cstar(1)/cstart, rad_wk(1), tau_wk_inv(1), drdt(1) ', &
-                       cstar(1), cstar(1)/cstart, rad_wk(1), tau_wk_inv(1), drdt(1)
-        print *,'wake, wdens(1), awdens(1), act(1), d_awdens(1) ', &
-                       wdens(1), awdens(1), act(1), d_awdens(1)
-        print *,'wake, wgen, -(wdens-awdens)*tau_wk_inv, -2.*wdens*gfl*drdt_pos, d_wdens ', &
-                       wgen(1), -(wdens(1)-awdens(1))*tau_wk_inv(1), -2.*wdens(1)*gfl(1)*drdt_pos, d_wdens(1)
-        print *,'wake, d_sig_gen(1), d_sig_death(1), d_sig_col(1), d_sigmaw(1) ', &
-                       d_sig_gen(1), d_sig_death(1), d_sig_col(1), d_sigmaw(1)
-      ENDIF
-    
-    ELSE  !  (iflag_wk_pop_dyn >= 1)
-
-    ! cc nrlmd
-
-      DO i = 1, klon
-        IF (wk_adv(i)) THEN
-          ! cc nrlmd          Introduction du taux de mortalité des poches et
+          ! cc nrlmd          Introduction du taux de mortalite des poches et
           ! test sur sigmaw_max=0.4
           ! cc         d_sigmaw(i) = gfl(i)*Cstar(i)*dtimesub
@@ -1008,5 +1021,5 @@
     ! IM 060208 differences par rapport au code initial; init. a 0 dp_deltomg
     ! IM 060208 et omg sur les niveaux de 1 a klev+1, alors que avant l'on definit
-    ! IM 060208 au niveau k=1..?
+    ! IM 060208 au niveau k=1...
     !JYG 161013 Correction : maintenant omg est dimensionne a klev.
     DO k = 1, klev
@@ -1082,6 +1095,10 @@
     DO i = 1, klon
       IF (wk_adv(i) .AND. kupper(i)>ktop(i)) THEN
-        omg(i, kupper(i)+1) = -RG*amdwn(i, kupper(i)+1)/sigmaw(i) + &
+        IF ( iflag_wk_profile == 0 ) THEN
+           omg(i, kupper(i)+1) =-RG*amdwn(i, kupper(i)+1)/sigmaw(i) + &
           RG*amup(i, kupper(i)+1)/(1.-sigmaw(i))
+        ELSE
+           omg(i, kupper(i)+1) = 0.
+        ENDIF
         dp_deltomg(i, kupper(i)) = (omgtop(i)-omg(i,kupper(i)+1))/ &
           (ptop(i)-pupper(i))
@@ -1090,5 +1107,5 @@
 
     ! c      DO i=1,klon
-    ! c        print*,'Pente entre 0 et kupper (référence)'
+    ! c        print*,'Pente entre 0 et kupper (reference)'
     ! c     $   	,omg(i,kupper(i)+1)/(pupper(i)-ph(i,1))
     ! c        print*,'Pente entre ktop et kupper'
@@ -1166,4 +1183,5 @@
         IF (wk_adv(i) .AND. k<=kupper(i)+1) THEN
           dth(i, k) = deltatw(i, k)/ppi(i, k)
+! print *, 'VVVVwake k, the(i,k), dth(i,k), sigmaw(i) ', k, the(i,k), dth(i,k), sigmaw(i)
           th1(i, k) = the(i, k) - sigmaw(i)*dth(i, k) ! undisturbed area
           th2(i, k) = the(i, k) + (1.-sigmaw(i))*dth(i, k) ! wake
@@ -1214,9 +1232,10 @@
     END DO
 
-    IF (prt_level>=10) THEN
-      PRINT *, 'wake-4.3, th1(igout,k) ', (k,th1(igout,k), k=1,klev)
-      PRINT *, 'wake-4.3, th2(igout,k) ', (k,th2(igout,k), k=1,klev)
-      PRINT *, 'wake-4.3, dth(igout,k) ', (k,dth(igout,k), k=1,klev)
-      PRINT *, 'wake-4.3, omgbdth(igout,k) ', (k,omgbdth(igout,k), k=1,klev)
+!!    IF (prt_level>=10) THEN
+    IF (prt_level>=10 .and. wk_adv(igout)) THEN
+      PRINT *, 'wake-4.3, th1(igout,k) ', (k,th1(igout,k), k=1,kupper(igout))
+      PRINT *, 'wake-4.3, th2(igout,k) ', (k,th2(igout,k), k=1,kupper(igout))
+      PRINT *, 'wake-4.3, dth(igout,k) ', (k,dth(igout,k), k=1,kupper(igout))
+      PRINT *, 'wake-4.3, omgbdth(igout,k) ', (k,omgbdth(igout,k), k=1,kupper(igout))
     ENDIF
 
@@ -1310,5 +1329,5 @@
 
 
-          ! Coefficient de répartition
+          ! Coefficient de repartition
 
           crep(i, k) = crep_sol*(ph(i,kupper(i))-ph(i,k))/ &
@@ -1340,6 +1359,6 @@
 !
 
-          ! cc nrlmd          Prise en compte du taux de mortalité
-          ! cc               Définitions de entr, detr
+          ! cc nrlmd          Prise en compte du taux de mortalite
+          ! cc               Definitions de entr, detr
 !jyg<
 !!            detr(i, k) = 0.
@@ -1358,5 +1377,5 @@
 
 
-          ! ajout d'un effet onde de gravité -Tgw(k)*deltatw(k) 03/02/06 YU
+          ! ajout d'un effet onde de gravite -Tgw(k)*deltatw(k) 03/02/06 YU
           ! Jingmei
 
@@ -1414,4 +1433,11 @@
     CALL wake_vec_modulation(klon, klev, wk_adv, epsilon_loc, qe, d_qe, deltaqw, &
       d_deltaqw, sigmaw, d_sigmaw, alpha)
+    !
+    ! Alpha_tot = Product of all the alpha's
+    DO i = 1, klon
+      IF (wk_adv(i)) THEN
+        alpha_tot(i) = alpha_tot(i)*alpha(i)    
+      END IF
+    END DO
 
     ! cc nrlmd
@@ -1472,22 +1498,62 @@
         sigmaw(i) = sigmaw(i) + d_sigmaw(i)
         d_sigmaw2(i) = d_sigmaw2(i) + d_sigmaw(i)
+!  print *,'XXXX4 d_sigmaw2(i), sigmaw(i) ', d_sigmaw2(i), sigmaw(i)
       END IF
     END DO
 !jyg<
     IF (iflag_wk_pop_dyn >= 1) THEN
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sigmaw !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!  Cumulatives
+      DO i = 1, klon
+        IF (wk_adv(i)) THEN
+          d_sig_gen2(i)   = d_sig_gen2(i)   + d_sig_gen(i)
+          d_sig_death2(i) = d_sig_death2(i) + d_sig_death(i)
+          d_sig_col2(i)   = d_sig_col2(i)   + d_sig_col(i)
+          d_sig_spread2(i)= d_sig_spread2(i)+ d_sig_spread(i)
+          d_sig_bnd2(i)   = d_sig_bnd2(i)   + d_sig_bnd(i)
+        END IF
+      END DO
+!  Bounds
+      DO i = 1, klon
+        IF (wk_adv(i)) THEN
+          sigmaw_targ = max(sigmaw(i),sigmad)
+          d_sig_bnd2(i) = d_sig_bnd2(i) + sigmaw_targ - sigmaw(i)
+          d_sigmaw2(i) = d_sigmaw2(i) + sigmaw_targ - sigmaw(i)
+!  print *,'XXXX5 d_sigmaw2(i), sigmaw(i) ', d_sigmaw2(i), sigmaw(i)
+          sigmaw(i) = sigmaw_targ
+        END IF
+      END DO
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! wdens  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!  Cumulatives
+      DO i = 1, klon
+        IF (wk_adv(i)) THEN
+          wdens(i) = wdens(i) + d_wdens(i)
+          d_wdens2(i) = d_wdens2(i) + d_wdens(i)
+          d_dens_gen2(i)   = d_dens_gen2(i)   + d_dens_gen(i)
+          d_dens_death2(i) = d_dens_death2(i) + d_dens_death(i)
+          d_dens_col2(i)   = d_dens_col2(i)   + d_dens_col(i)
+          d_dens_bnd2(i)   = d_dens_bnd2(i)   + d_dens_bnd(i)
+        END IF
+      END DO
+!  Bounds
+      DO i = 1, klon
+        IF (wk_adv(i)) THEN
+          wdens_targ = max(wdens(i),wdensmin)
+          d_dens_bnd2(i) = d_dens_bnd2(i) + wdens_targ - wdens(i)
+          d_wdens2(i) = d_wdens2(i) + wdens_targ - wdens(i)
+          wdens(i) = wdens_targ
+        END IF
+      END DO
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! awdens !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!  Cumulatives
       DO i = 1, klon
         IF (wk_adv(i)) THEN
           awdens(i) = awdens(i) + d_awdens(i)
-          wdens(i) = wdens(i) + d_wdens(i)
           d_awdens2(i) = d_awdens2(i) + d_awdens(i)
-          d_wdens2(i) = d_wdens2(i) + d_wdens(i)
-        END IF
-      END DO
+        END IF
+      END DO
+!  Bounds
       DO i = 1, klon
         IF (wk_adv(i)) THEN
-          wdens_targ = max(wdens(i),wdensmin)
-          d_wdens2(i) = d_wdens2(i) + wdens_targ - wdens(i)
-          wdens(i) = wdens_targ
-!
           wdens_targ = min( max(awdens(i),0.), wdens(i) )
           d_awdens2(i) = d_awdens2(i) + wdens_targ - awdens(i)
@@ -1495,13 +1561,25 @@
         END IF
       END DO
-      DO i = 1, klon
-        IF (wk_adv(i)) THEN
-          sigmaw_targ = max(sigmaw(i),sigmad)
-          d_sigmaw2(i) = d_sigmaw2(i) + sigmaw_targ - sigmaw(i)
-          sigmaw(i) = sigmaw_targ
-        END IF
-      END DO
+!
+      IF (iflag_wk_pop_dyn == 2) THEN
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! awdens again for iflag_wk_pop_dyn = 2!!!!!!
+!  Cumulatives
+          DO i = 1, klon
+             IF (wk_adv(i)) THEN
+                 d_adens_death2(i)   = d_adens_death2(i)   + d_adens_death(i)
+                 d_adens_icol2(i)   = d_adens_icol2(i)   + d_adens_icol(i)
+                 d_adens_acol2(i)   = d_adens_acol2(i)   + d_adens_acol(i)
+                 d_adens_bnd2(i)   = d_adens_bnd2(i)   + d_adens_bnd(i)          
+             END IF
+          END DO
+!  Bounds
+          DO i = 1, klon
+             IF (wk_adv(i)) THEN
+                 wdens_targ = min( max(awdens(i),0.), wdens(i) )
+                 d_adens_bnd2(i) = d_adens_bnd2(i) + wdens_targ - awdens(i)
+             END IF
+          END DO
+      ENDIF ! (iflag_wk_pop_dyn == 2)
     ENDIF  ! (iflag_wk_pop_dyn >= 1)
-!>jyg
 
 
@@ -1744,5 +1822,7 @@
 !!          sigmaw(i) = max(sigmad, sigd_con(i))
           sigmaw_targ = max(sigmad, sigd_con(i))
+          d_sig_bnd2(i) = d_sig_bnd2(i) + sigmaw_targ - sigmaw(i)
           d_sigmaw2(i) = d_sigmaw2(i) + sigmaw_targ - sigmaw(i)
+!  print *,'XXXX6 d_sigmaw2(i), sigmaw(i) ', d_sigmaw2(i), sigmaw(i)
           sigmaw(i) = sigmaw_targ
 !>jyg
@@ -1961,5 +2041,7 @@
 !!      sigmaw(i) = amax1(sigmad, sigd_con(i))
       sigmaw_targ = max(sigmad, sigd_con(i))
+      d_sig_bnd2(i) = d_sig_bnd2(i) + sigmaw_targ - sigmaw(i)
       d_sigmaw2(i) = d_sigmaw2(i) + sigmaw_targ - sigmaw(i)
+!  print *,'XXXX7 d_sigmaw2(i), sigmaw(i) ', d_sigmaw2(i), sigmaw(i)
       sigmaw(i) = sigmaw_targ
 !>jyg
@@ -2058,5 +2140,8 @@
 !!      sigmaw(i) = 0.                        !jyg
       sigmaw_targ = 0.
-      d_sigmaw2(i) = d_sigmaw2(i) + sigmaw_targ - sigmaw(i)
+      d_sig_bnd2(i) = d_sig_bnd2(i) + sigmaw_targ - sigmaw(i)
+!!      d_sigmaw2(i) = d_sigmaw2(i) + sigmaw_targ - sigmaw(i)
+      d_sigmaw2(i) = sigmaw_targ - sigmaw_in(i)      ! _in = correction jyg 20220124
+!  print *,'XXXX8 d_sigmaw2(i), sigmaw(i) ', d_sigmaw2(i), sigmaw(i)
       sigmaw(i) = sigmaw_targ
       IF (iflag_wk_pop_dyn >= 1) THEN
@@ -2064,9 +2149,19 @@
 !!        wdens(i) = 0.
         wdens_targ = 0.
-        d_wdens2(i) = wdens_targ - wdens(i)
+        d_dens_bnd2(i) = d_dens_bnd2(i) + wdens_targ - wdens(i)
+!!        d_wdens2(i) = wdens_targ - wdens(i)
+        d_wdens2(i) = wdens_targ - wdens_in(i)      ! jyg 20220916
         wdens(i) = wdens_targ
         wdens_targ = 0.
-        d_awdens2(i) = wdens_targ - awdens(i)
+!!jyg: bug fix : the d_adens_bnd2 computation must be before the update of awdens.
+        IF (iflag_wk_pop_dyn == 2) THEN
+            d_adens_bnd2(i) = d_adens_bnd2(i) + wdens_targ - awdens(i)
+        ENDIF ! (iflag_wk_pop_dyn == 2)
+!!        d_awdens2(i) = wdens_targ - awdens(i)
+        d_awdens2(i) = wdens_targ - awdens_in(i)    ! jyg 20220916
         awdens(i) = wdens_targ
+!!        IF (iflag_wk_pop_dyn == 2) THEN
+!!            d_adens_bnd2(i) = d_adens_bnd2(i) + wdens_targ - awdens(i)
+!!        ENDIF ! (iflag_wk_pop_dyn == 2)
       ENDIF  ! (iflag_wk_pop_dyn >= 1)
     ELSE  ! (kill_wake(i))
@@ -2106,10 +2201,37 @@
     END DO
   END DO
-
-  DO i = 1, klon
+!jyg<
+  IF (iflag_wk_pop_dyn >= 1) THEN
+  DO i = 1, klon
+      IF (ok_qx_qw(i)) THEN
+    d_sig_gen2(i) = d_sig_gen2(i)/dtime
+    d_sig_death2(i) = d_sig_death2(i)/dtime
+    d_sig_col2(i) = d_sig_col2(i)/dtime
+    d_sig_spread2(i) = d_sig_spread2(i)/dtime
+    d_sig_bnd2(i) = d_sig_bnd2(i)/dtime
     d_sigmaw2(i) = d_sigmaw2(i)/dtime
+!  print *,'XXXX9 d_sigmaw2(i), sigmaw(i), dtime ', d_sigmaw2(i), sigmaw(i), dtime
+!
+    d_dens_gen2(i) = d_dens_gen2(i)/dtime
+    d_dens_death2(i) = d_dens_death2(i)/dtime
+    d_dens_col2(i) = d_dens_col2(i)/dtime
+    d_dens_bnd2(i) = d_dens_bnd2(i)/dtime
     d_awdens2(i) = d_awdens2(i)/dtime
     d_wdens2(i) = d_wdens2(i)/dtime
+      ENDIF
   ENDDO
+  IF (iflag_wk_pop_dyn == 2) THEN
+    DO i = 1, klon
+      IF (ok_qx_qw(i)) THEN
+    d_adens_death2(i) = d_adens_death2(i)/dtime
+    d_adens_icol2(i) = d_adens_icol2(i)/dtime
+    d_adens_acol2(i) = d_adens_acol2(i)/dtime
+    d_adens_bnd2(i) = d_adens_bnd2(i)/dtime
+      ENDIF
+    ENDDO
+   ENDIF ! (iflag_wk_pop_dyn == 2)  
+  ENDIF  ! (iflag_wk_pop_dyn >= 1)
+ 
+!>jyg
 
  RETURN
@@ -2161,5 +2283,5 @@
         discrim = b*b - 4.*a*c
         ! print*, 'x, a, b, c, discrim', x, a, b, c, discrim
-        IF (a+b>=0.) THEN !! Condition suffisante pour la positivité de ovap
+        IF (a+b>=0.) THEN !! Condition suffisante pour la positivite de ovap
           alpha1(i) = 1.
         ELSE
@@ -2186,2 +2308,360 @@
   RETURN
 END SUBROUTINE wake_vec_modulation
+
+
+
+SUBROUTINE pkupper (klon, klev, ptop, ph, pupper, kupper)
+
+USE wake_ini_mod , ONLY : wk_pupper
+IMPLICIT NONE
+
+INTEGER,  INTENT(IN)                              :: klon,klev
+REAL,     INTENT(IN),   DIMENSION (klon,klev+1)   :: ph
+REAL,     INTENT(IN),   DIMENSION (klon)          :: ptop
+REAL,     INTENT(OUT),  DIMENSION (klon)          :: pupper
+INTEGER,  INTENT(OUT),  DIMENSION (klon)          :: kupper
+INTEGER                                           :: i,k
+
+
+ kupper = 0
+ 
+IF (wk_pupper<1.) THEN
+ ! Choose an integration bound well above wake top
+  ! -----------------------------------------------------------------
+
+  ! Pupper = 50000.  ! melting level
+  ! Pupper = 60000.
+  ! Pupper = 80000.  ! essais pour case_e
+  DO i = 1, klon
+  !  pupper(i) = 0.6*ph(i, 1)
+    pupper(i) = wk_pupper*ph(i, 1)
+    pupper(i) = max(pupper(i), 45000.)
+    ! cc        Pupper(i) = 60000.
+  END DO
+
+ELSE
+  
+  DO i=1, klon
+     ! pupper(i) = wk_pupper*ptop(i)+(1.-wk_pupper)*ph(i, 1) 
+     pupper(i) = min( wk_pupper*ptop(i)+(1.-wk_pupper)*ph(i, 1) , ptop(i)-5000.) 
+  END DO
+END IF
+ 
+  ! -5/ Determination de kupper
+
+  DO k = klev, 1, -1
+    DO i = 1, klon
+      IF (ph(i,k+1)<pupper(i)) kupper(i) = k
+    END DO
+  END DO
+
+  ! On evite kupper = 1 et kupper = klev
+  DO i = 1, klon
+    kupper(i) = max(kupper(i), 2)
+    kupper(i) = min(kupper(i), klev-1)
+  END DO 
+    RETURN
+END SUBROUTINE pkupper
+
+
+SUBROUTINE wake_popdyn_1(klon, klev, dtime, cstar, tau_wk_inv, wgen, wdens, awdens, sigmaw, &
+                  dtimesub, gfl, rad_wk, f_shear, drdt_pos, &
+                  d_awdens, d_wdens, d_sigmaw, &
+                  iflag_wk_act, wk_adv, cin, wape, &
+                  drdt, &
+                  d_dens_gen, d_dens_death, d_dens_col, d_dens_bnd, &
+                  d_sig_gen, d_sig_death, d_sig_col, d_sig_spread, d_sig_bnd, &
+                  d_wdens_targ, d_sigmaw_targ)
+                
+
+  USE wake_ini_mod , ONLY : wake_ini
+  USE wake_ini_mod , ONLY : prt_level,RG
+  USE wake_ini_mod , ONLY : stark, wdens_ref
+  USE wake_ini_mod , ONLY : tau_cv, rzero, aa0
+  USE wake_ini_mod , ONLY : iflag_wk_pop_dyn, wdensmin
+  USE wake_ini_mod , ONLY : sigmad, cstart, sigmaw_max
+  
+IMPLICIT NONE
+
+  INTEGER, INTENT(IN)                                   :: klon,klev
+  LOGICAL, DIMENSION (klon),        INTENT(IN)          :: wk_adv
+  REAL,                             INTENT(IN)          :: dtime
+  REAL,                             INTENT(IN)          :: dtimesub
+  REAL, DIMENSION (klon),           INTENT(IN)          :: wgen
+  REAL, DIMENSION (klon),           INTENT(IN)          :: wdens
+  REAL, DIMENSION (klon),           INTENT(IN)          :: awdens
+  REAL, DIMENSION (klon),           INTENT(IN)          :: sigmaw
+  REAL, DIMENSION (klon),           INTENT(IN)          :: gfl, cstar
+  REAL, DIMENSION (klon),           INTENT(IN)          :: cin, wape
+  REAL, DIMENSION (klon),           INTENT(IN)          :: rad_wk
+  REAL, DIMENSION (klon),           INTENT(IN)          :: f_shear
+  INTEGER,                          INTENT(IN)          :: iflag_wk_act
+
+  
+  !
+ 
+  ! Tendencies of state variables (2 is appended to the names of fields which are the cumul of fields 
+  !                                 computed at each sub-timestep; e.g. d_wdens2 is the cumul of d_wdens)
+  REAL, DIMENSION (klon),           INTENT(OUT)         :: d_sigmaw, d_awdens, d_wdens
+  REAL, DIMENSION (klon),           INTENT(OUT)         :: drdt
+  ! Some components of the tendencies of state variables  
+  REAL, DIMENSION (klon),           INTENT(OUT)         :: d_sig_gen, d_sig_death, d_sig_col, d_sig_bnd
+  REAL, DIMENSION (klon),           INTENT(OUT)         :: d_sig_spread
+  REAL, DIMENSION (klon),           INTENT(OUT)         :: d_dens_gen, d_dens_death, d_dens_col, d_dens_bnd
+  REAL,                             INTENT(OUT)         :: d_wdens_targ, d_sigmaw_targ
+ 
+  
+  REAL                                                  :: delta_t_min
+  INTEGER                                               :: nsub
+  INTEGER                                               :: i, k
+  REAL                                                  :: wdens0
+  ! IM 080208
+  LOGICAL, DIMENSION (klon)                             :: gwake
+  
+   ! Variables liees a la dynamique de population
+  REAL, DIMENSION(klon)                                 :: act
+  REAL, DIMENSION(klon)                                 :: tau_wk_inv
+  REAL, DIMENSION(klon)                                 :: wape1_act, wape2_act
+  LOGICAL, DIMENSION (klon)                             :: kill_wake
+  REAL                                                  :: drdt_pos
+  REAL                                                  :: tau_wk_inv_min
+  
+     
+
+      IF (iflag_wk_act == 0) THEN
+        act(:) = 0.
+      ELSEIF (iflag_wk_act == 1) THEN
+        act(:) = 1.
+      ELSEIF (iflag_wk_act ==2) THEN
+      DO i = 1, klon
+        IF (wk_adv(i)) THEN
+          wape1_act(i) = abs(cin(i))
+          wape2_act(i) = 2.*wape1_act(i) + 1.
+          act(i) = min(1., max(0., (wape(i)-wape1_act(i)) / (wape2_act(i)-wape1_act(i)) ))
+        ENDIF  ! (wk_adv(i))
+      ENDDO
+      ENDIF  ! (iflag_wk_act ==2)
+
+
+      DO i = 1, klon
+       ! print*, 'XXX wk_adv(i)', wk_adv(i)
+        IF (wk_adv(i)) THEN
+!!          tau_wk(i) = max(rad_wk(i)/(3.*cstar(i))*((cstar(i)/cstart)**1.5 - 1), 100.)
+          tau_wk_inv(i) = max( (3.*cstar(i))/(rad_wk(i)*((cstar(i)/cstart)**1.5 - 1)), 0.)
+          tau_wk_inv_min = min(tau_wk_inv(i), 1./dtimesub)
+          drdt(i) = (cstar(i) - wgen(i)*(sigmaw(i)/wdens(i)-aa0)/gfl(i)) / &
+                    (1 + 2*f_shear(i)*(2.*sigmaw(i)-aa0*wdens(i)) - 2.*sigmaw(i))
+!!                    (1 - 2*sigmaw(i)*(1.-f_shear(i)))
+          drdt_pos=max(drdt(i),0.)
+
+!!          d_wdens(i) = ( wgen(i)*(1.+2.*(sigmaw(i)-sigmad)) &
+!!                     - wdens(i)*tau_wk_inv_min &
+!!                     - 2.*gfl(i)*wdens(i)*Cstar(i) )*dtimesub
+!jyg+mlt<
+          d_awdens(i) = ( wgen(i) - (1./tau_cv)*(awdens(i) - act(i)*wdens(i)) )*dtimesub
+          d_dens_gen(i) = wgen(i)
+          d_dens_death(i) = - (wdens(i)-awdens(i))*tau_wk_inv_min 
+          d_dens_col(i) =  -2.*wdens(i)*gfl(i)*drdt_pos 
+          d_dens_gen(i) =  d_dens_gen(i)*dtimesub
+          d_dens_death(i) = d_dens_death(i)*dtimesub
+          d_dens_col(i) =  d_dens_col(i)*dtimesub 
+
+          d_wdens(i) = d_dens_gen(i)+d_dens_death(i)+d_dens_col(i)
+!!          d_wdens(i) = ( wgen(i) - (wdens(i)-awdens(i))*tau_wk_inv_min -  &
+!!                         2.*wdens(i)*gfl(i)*drdt_pos )*dtimesub
+!>jyg+mlt
+!
+!jyg<
+          d_wdens_targ = max(d_wdens(i), wdensmin-wdens(i))
+!!          d_dens_bnd(i) = d_dens_bnd(i) + d_wdens_targ - d_wdens(i)
+          d_dens_bnd(i) = d_wdens_targ - d_wdens(i)
+          d_wdens(i) = d_wdens_targ
+!!          d_wdens(i) = max(d_wdens(i), wdensmin-wdens(i))
+!>jyg
+
+!jyg+mlt<
+!!          d_sigmaw(i) = ( (1.-2*f_shear(i)*sigmaw(i))*(gfl(i)*Cstar(i)+wgen(i)*sigmad/wdens(i)) &
+!!                      + 2.*f_shear(i)*wgen(i)*sigmaw(i)**2/wdens(i) &
+!!                      - sigmaw(i)*tau_wk_inv_min )*dtimesub
+          d_sig_gen(i) = wgen(i)*aa0
+!!          print*, 'XXX sigmaw(i), awdens(i), wdens(i), tau_wk_inv_min', &
+!!                  sigmaw(i), awdens(i), wdens(i), tau_wk_inv_min
+          d_sig_death(i) = - sigmaw(i)*(1.-awdens(i)/wdens(i))*tau_wk_inv_min
+!!        
+          
+          d_sig_col(i) = - 2*f_shear(i)*sigmaw(i)*gfl(i)*drdt_pos
+          d_sig_col(i) = - 2*f_shear(i)*(2.*sigmaw(i)-wdens(i)*aa0)*gfl(i)*drdt_pos
+          d_sig_spread(i) = gfl(i)*cstar(i)
+          d_sig_gen(i) =  d_sig_gen(i)*dtimesub
+          d_sig_death(i) = d_sig_death(i)*dtimesub
+          d_sig_col(i) =  d_sig_col(i)*dtimesub 
+          d_sig_spread(i) =  d_sig_spread(i)*dtimesub 
+          d_sigmaw(i) =  d_sig_gen(i) + d_sig_death(i) + d_sig_col(i) + d_sig_spread(i)
+!>jyg+mlt
+!
+!jyg<
+          d_sigmaw_targ = max(d_sigmaw(i), sigmad-sigmaw(i))
+!!          d_sig_bnd(i) = d_sig_bnd(i) + d_sigmaw_targ - d_sigmaw(i)
+!!          d_sig_bnd_provis(i) = d_sigmaw_targ - d_sigmaw(i)
+          d_sig_bnd(i) = d_sigmaw_targ - d_sigmaw(i)
+          d_sigmaw(i) = d_sigmaw_targ
+!!          d_sigmaw(i) = max(d_sigmaw(i), sigmad-sigmaw(i))
+!>jyg
+        ENDIF
+      ENDDO
+
+      IF (prt_level >= 10) THEN
+        print *,'wake, cstar(1), cstar(1)/cstart, rad_wk(1), tau_wk_inv(1), drdt(1) ', &
+                       cstar(1), cstar(1)/cstart, rad_wk(1), tau_wk_inv(1), drdt(1)
+        print *,'wake, wdens(1), awdens(1), act(1), d_awdens(1) ', &
+                       wdens(1), awdens(1), act(1), d_awdens(1)
+        print *,'wake, wgen, -(wdens-awdens)*tau_wk_inv, -2.*wdens*gfl*drdt_pos, d_wdens ', &
+                       wgen(1), -(wdens(1)-awdens(1))*tau_wk_inv(1), -2.*wdens(1)*gfl(1)*drdt_pos, d_wdens(1)
+        print *,'wake, d_sig_gen(1), d_sig_death(1), d_sig_col(1), d_sigmaw(1) ', &
+                       d_sig_gen(1), d_sig_death(1), d_sig_col(1), d_sigmaw(1)
+      ENDIF
+    
+    RETURN 
+    END SUBROUTINE wake_popdyn_1
+    
+    SUBROUTINE wake_popdyn_2 ( klon, klev, wk_adv, dtimesub, wgen, &
+                             sigmaw, wdens, awdens, &   !! states variables
+                             gfl, cstar, cin, wape, rad_wk, &
+                             d_sigmaw, d_wdens, d_awdens, &  !! tendences 
+                             cont_fact, &
+                             d_sig_gen, d_sig_death, d_sig_col, d_sig_spread, d_sig_bnd, &
+                             d_dens_gen, d_dens_death, d_dens_col, d_dens_bnd, &
+                             d_adens_death, d_adens_icol, d_adens_acol, d_adens_bnd )
+                             
+                                             
+
+  USE wake_ini_mod , ONLY : wake_ini
+  USE wake_ini_mod , ONLY : prt_level,RG
+  USE wake_ini_mod , ONLY : stark, wdens_ref
+  USE wake_ini_mod , ONLY : tau_cv, rzero, aa0
+  USE wake_ini_mod , ONLY : iflag_wk_pop_dyn, wdensmin
+  USE wake_ini_mod , ONLY : sigmad, cstart, sigmaw_max
+  
+IMPLICIT NONE
+
+  INTEGER, INTENT(IN)                                   :: klon,klev
+  LOGICAL, DIMENSION (klon),        INTENT(IN)          :: wk_adv
+  REAL,                             INTENT(IN)          :: dtimesub
+  REAL, DIMENSION (klon),           INTENT(IN)          :: wgen      !! B = birth rate of wakes
+  REAL, DIMENSION (klon),           INTENT(INOUT)       :: sigmaw    !! sigma = fractional area of wakes 
+  REAL, DIMENSION (klon),           INTENT(INOUT)       :: wdens     !! D = number of wakes per unit area 
+  REAL, DIMENSION (klon),           INTENT(INOUT)       :: awdens    !! A = number of active wakes per unit area
+  REAL, DIMENSION (klon),           INTENT(IN)          :: gfl       !! Lg = gust front lenght per unit area
+  REAL, DIMENSION (klon),           INTENT(IN)          :: cstar     !! C* = spreading velocity of wakes
+  REAL, DIMENSION (klon),           INTENT(IN)          :: cin, wape  ! RM : A Faire disparaitre
+  REAL, DIMENSION (klon),           INTENT(IN)          :: rad_wk    !! r = wake radius
+
+!  
+  REAL, DIMENSION (klon),           INTENT(OUT)         :: d_sigmaw, d_wdens, d_awdens
+  REAL, DIMENSION (klon),           INTENT(OUT)         :: cont_fact  !! RM facteur de contact = 2 pi * rad * C*
+  ! Some components of the tendencies of state variables  
+  REAL, DIMENSION (klon),           INTENT(OUT)         :: d_sig_gen, d_sig_death, d_sig_col, d_sig_spread, d_sig_bnd
+  REAL, DIMENSION (klon),           INTENT(OUT)         :: d_dens_gen, d_dens_death, d_dens_col, d_dens_bnd
+  REAL, DIMENSION (klon),           INTENT(OUT)         :: d_adens_death, d_adens_icol, d_adens_acol, d_adens_bnd
+
+
+!! internal variables
+  
+  INTEGER                                               :: i, k
+  REAL, DIMENSION (klon)                                :: tau_wk_inv      !! tau = life time of wakes
+  REAL                                                  :: tau_wk_inv_min
+  REAL, DIMENSION (klon)                                :: tau_prime       !! tau_prime = life time of actives wakes
+  REAL                                                  :: d_wdens_targ, d_sigmaw_targ
+  
+
+!! Equations
+!! dD/dt = B - (D-A)/tau - f D^2
+!! dA/dt = B - A/tau_prime + f (D-A)^2 - f A^2
+!! dsigma/dt = B a0 - sigma/D (D-A)/tau + Lg C* - f (D-A)^2 (sigma/D-a0)
+!!
+!! f = 2 (B (a0-sigma/D) + Lg C*) / (2 (D-A)^2 (2 sigma/D-a0) + D (1-2 sigma))
+
+
+      DO i = 1, klon
+       ! print*, 'XXX wk_adv(i)', wk_adv(i)
+        IF (wk_adv(i)) THEN
+!!          tau_wk(i) = max(rad_wk(i)/(3.*cstar(i))*((cstar(i)/cstart)**1.5 - 1), 100.)
+          tau_wk_inv(i) = max( (3.*cstar(i))/(rad_wk(i)*((cstar(i)/cstart)**1.5 - 1)), 0.)
+          tau_wk_inv_min = min(tau_wk_inv(i), 1./dtimesub)
+          tau_prime(i) = tau_cv
+!!          cont_fact(i) = 2.*(wgen(i)*(aa0-sigmaw(i)/wdens(i)) + gfl(i)*cstar(i)) / &
+!!                             (2.*(wdens(i)-awdens(i))**2*(2.*sigmaw(i)/wdens(i) - aa0) + wdens(i)*(1.-2.*sigmaw(i)))
+!!          cont_fact(i) = 2.*3.14*rad_wk(i)*cstar(i)     ! bug
+!!          cont_fact(i) = 4.*3.14*rad_wk(i)*cstar(i)
+          cont_fact(i) = 2.*gfl(i)*cstar(i)/wdens(i)
+
+          d_sig_gen(i) = wgen(i)*aa0
+          d_sig_death(i) = - sigmaw(i)*(1.-awdens(i)/wdens(i))*tau_wk_inv_min
+          d_sig_col(i) = - cont_fact(i)*(wdens(i)-awdens(i))**2*(2.*sigmaw(i)/wdens(i)-aa0)
+          d_sig_spread(i) = gfl(i)*cstar(i)
+!
+          d_sig_gen(i) =  d_sig_gen(i)*dtimesub
+          d_sig_death(i) = d_sig_death(i)*dtimesub
+          d_sig_col(i) =  d_sig_col(i)*dtimesub 
+          d_sig_spread(i) =  d_sig_spread(i)*dtimesub 
+          d_sigmaw(i) =  d_sig_gen(i) + d_sig_death(i) + d_sig_col(i) + d_sig_spread(i)
+
+         
+          d_sigmaw_targ = max(d_sigmaw(i), sigmad-sigmaw(i))
+!!          d_sig_bnd(i) = d_sig_bnd(i) + d_sigmaw_targ - d_sigmaw(i)
+!!          d_sig_bnd_provis(i) = d_sigmaw_targ - d_sigmaw(i)
+          d_sig_bnd(i) = d_sigmaw_targ - d_sigmaw(i)
+          d_sigmaw(i) = d_sigmaw_targ
+!!          d_sigmaw(i) = max(d_sigmaw(i), sigmad-sigmaw(i))
+         
+         
+          d_dens_gen(i) = wgen(i)
+          d_dens_death(i) = - (wdens(i)-awdens(i))*tau_wk_inv_min 
+          d_dens_col(i) =  - cont_fact(i)*wdens(i)**2
+! 
+          d_dens_gen(i) =  d_dens_gen(i)*dtimesub
+          d_dens_death(i) = d_dens_death(i)*dtimesub
+          d_dens_col(i) =  d_dens_col(i)*dtimesub 
+          d_wdens(i) = d_dens_gen(i) + d_dens_death(i) + d_dens_col(i)
+
+
+          d_adens_death(i) = -awdens(i)/tau_prime(i)
+          d_adens_icol(i) = cont_fact(i)*(wdens(i)-awdens(i))**2
+          d_adens_acol(i) = - cont_fact(i)*awdens(i)**2
+!
+          d_adens_death(i) =  d_adens_death(i)*dtimesub
+          d_adens_icol(i) =   d_adens_icol(i)*dtimesub
+          d_adens_acol(i) =   d_adens_acol(i)*dtimesub
+          d_awdens(i) =   d_dens_gen(i) + d_adens_death(i) + d_adens_icol(i) + d_adens_acol(i)     
+            
+!!
+          d_wdens_targ = max(d_wdens(i), wdensmin-wdens(i))
+!!          d_dens_bnd(i) = d_dens_bnd(i) + d_wdens_targ - d_wdens(i)
+          d_dens_bnd(i) = d_wdens_targ - d_wdens(i)
+          d_wdens(i) = d_wdens_targ
+          
+          d_wdens_targ = min(max(d_awdens(i),-awdens(i)), wdens(i)-awdens(i))
+!!          d_dens_bnd(i) = d_dens_bnd(i) + d_wdens_targ - d_wdens(i)
+          d_adens_bnd(i) = d_wdens_targ - d_awdens(i)
+          d_awdens(i) = d_wdens_targ
+
+
+
+        ENDIF
+      ENDDO
+
+      IF (prt_level >= 10) THEN
+        print *,'wake, cstar(1), cstar(1)/cstart, rad_wk(1), tau_wk_inv(1), cont_fact(1) ', &
+                       cstar(1), cstar(1)/cstart, rad_wk(1), tau_wk_inv(1), cont_fact(1)
+        print *,'wake, wdens(1), awdens(1), d_awdens(1) ', &
+                       wdens(1), awdens(1), d_awdens(1)
+        print *,'wake, d_sig_gen(1), d_sig_death(1), d_sig_col(1), d_sigmaw(1) ', &
+                       d_sig_gen(1), d_sig_death(1), d_sig_col(1), d_sigmaw(1)
+      ENDIF
+sigmaw=sigmaw+d_sigmaw
+wdens=wdens+d_wdens
+awdens=awdens+d_awdens
+
+    RETURN 
+    END SUBROUTINE wake_popdyn_2  
+  
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/wake_ini_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/wake_ini_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/wake_ini_mod.F90	(revision 4482)
@@ -17,16 +17,16 @@
 
   ! -------------------------------------------------------------------------
-  ! Déclaration de variables
-  ! -------------------------------------------------------------------------
-
-  ! Variables à fixer
+  ! Declaration de variables
+  ! -------------------------------------------------------------------------
+
+  ! Variables a fixer
 !jyg<
 !!  REAL, SAVE                                            :: stark, wdens_ref, coefgw, alpk
   INTEGER, SAVE, PROTECTED                                         :: prt_level
   REAL, SAVE, PROTECTED, DIMENSION(2)                              :: wdens_ref
-  REAL, SAVE, PROTECTED                                            :: stark, coefgw, alpk
+  REAL, SAVE, PROTECTED                                            :: stark, coefgw, alpk, wk_pupper
 !>jyg
   REAL, SAVE, PROTECTED                                            :: crep_upper, crep_sol  
-  !$OMP THREADPRIVATE(stark, wdens_ref, coefgw, alpk, crep_upper, crep_sol)
+  !$OMP THREADPRIVATE(stark, wdens_ref, coefgw, alpk, wk_pupper, crep_upper, crep_sol)
 
   REAL, SAVE, PROTECTED                                            :: tau_cv
@@ -44,4 +44,7 @@
   INTEGER, SAVE, PROTECTED                                         :: iflag_wk_pop_dyn
   !$OMP THREADPRIVATE(iflag_wk_pop_dyn)
+
+  INTEGER, SAVE, PROTECTED                                         :: iflag_wk_profile
+  !$OMP THREADPRIVATE(iflag_wk_profile)
 
   REAL, SAVE, PROTECTED                                            :: wdensmin
@@ -111,7 +114,7 @@
   ! Configuration de coefgw,stark,wdens (22/02/06 by YU Jingmei)
 
-  ! coefgw : Coefficient pour les ondes de gravité
+  ! coefgw : Coefficient pour les ondes de gravite
   ! stark : Coefficient k dans Cstar=k*sqrt(2*WAPE)
-  ! wdens : Densité surfacique de poche froide
+  ! wdens : Densite surfacique de poche froide
   ! -------------------------------------------------------------------------
 
@@ -149,4 +152,9 @@
   alpk=0.25
   CALL getin_p('alpk',alpk)
+  
+  wk_pupper=0.6
+  CALL getin_p('wk_pupper',wk_pupper)
+
+
 !jyg<
 !!  wdens_ref=8.E-12
@@ -170,4 +178,7 @@
                                             ! 2: act(:)=f(Wape)
 
+  iflag_wk_profile = 0
+  CALL getin_p('iflag_wk_profile',iflag_wk_profile) ! switch between wdens prescribed 
+                                                    ! and wdens prognostic
   rzero = 5000.
   CALL getin_p('rzero_wk', rzero)
@@ -184,4 +195,5 @@
   WRITE(*,*) 'stark=', stark
   WRITE(*,*) 'alpk=', alpk
+  WRITE(*,*) 'wk_pupper=', wk_pupper
 !jyg<
 !!  WRITE(*,*) 'wdens_ref=', wdens_ref
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/write_bilKP_ave.h
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/write_bilKP_ave.h	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/write_bilKP_ave.h	(revision 4482)
@@ -49,5 +49,5 @@
       CALL histwrite_phy(nid_bilKPave,"play",itau_w,paprs)
 c
-cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldliq, zx_tmp_3d)
+cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, radocond, zx_tmp_3d)
       CALL histwrite_phy(nid_bilKPave,"oliq",itau_w,cldliq)
 c
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/write_bilKP_ins.h
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/write_bilKP_ins.h	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/write_bilKP_ins.h	(revision 4482)
@@ -49,5 +49,5 @@
       CALL histwrite_phy(nid_bilKPins,"play",itau_w,paprs)
 c
-cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldliq, zx_tmp_3d)
+cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, radocond, zx_tmp_3d)
       CALL histwrite_phy(nid_bilKPins,"oliq",itau_w,cldliq)
 c
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/yamada4.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/yamada4.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/yamada4.F90	(revision 4482)
@@ -4,13 +4,11 @@
     cd, tke, km, kn, kq, ustar, iflag_pbl, drgpro)
 
-  USE dimphy
-  USE ioipsl_getin_p_mod, ONLY : getin_p
+  USE dimphy, only : klev,klon
   USE phys_local_var_mod, only: tke_dissip,wprime
+  USE yamada_ini_mod, only : new_yamada4,yamada4_num,hboville
+  USE yamada_ini_mod, only : prt_level, lunout,pbl_lmixmin_alpha,b1,kap,viscom,viscoh
+  USE yamada_ini_mod, only : ric, yun,ydeux,lmixmin
   
   IMPLICIT NONE
-  include "iniprint.h"
-  ! .......................................................................
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   ! ************************************************************************************************
   !
@@ -111,6 +109,4 @@
   !-------
 
-  INCLUDE "clesphys.h"
-
   REAL q2(klon, klev+1)
   REAL kmpre(klon, klev+1), tmp2, qpre
@@ -121,7 +117,4 @@
   INTEGER nlay, nlev
 
-  LOGICAL,SAVE :: hboville=.TRUE.
-  REAL,SAVE :: viscom,viscoh
-  !$OMP THREADPRIVATE( hboville,viscom,viscoh)
   INTEGER ig, jg, k
   REAL ri, zrif, zalpha, zsm, zsn
@@ -136,22 +129,12 @@
   REAL :: disseff
 
-  REAL,SAVE :: ric0,ric,rifc, b1, kap
-  !$OMP THREADPRIVATE(ric0,ric,rifc,b1,kap)
-  DATA b1, kap/16.6, 0.4/
+  REAL,SAVE :: rifc
+  !$OMP THREADPRIVATE(rifc)
   REAL,SAVE :: seuilsm, seuilalpha
   !$OMP THREADPRIVATE(seuilsm, seuilalpha)
-  REAL,SAVE :: lmixmin
-  !$OMP THREADPRIVATE(lmixmin)
-  LOGICAL, SAVE :: new_yamada4
-  INTEGER, SAVE :: yamada4_num
-  !$OMP THREADPRIVATE(new_yamada4,yamada4_num)
-  REAL, SAVE :: yun,ydeux
-  !$OMP THREADPRIVATE(yun,ydeux)
 
   REAL frif, falpha, fsm
   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)
 
   CHARACTER (len = 20) :: modname = 'yamada4'
@@ -168,50 +151,15 @@
   
 
-  IF (firstcall) THEN
-! Seuil dans le code de turbulence 
-    new_yamada4=.false.
-    CALL getin_p('new_yamada4',new_yamada4)
 
     IF (new_yamada4) THEN
 ! Corrections et reglages issus du travail de these d'Etienne Vignon.
-       ric=0.143 ! qui donne des valeurs proches des seuils proposes
-                 ! dans YAMADA 1983 : sm=0.0845 (0.085 dans Y83)
-                 !                    sm=1.1213 (1.12  dans Y83)
-       CALL getin_p('yamada4_ric',ric)
-       ric0=0.19489      ! ric=0.195 originalement, mais produisait sm<0
-       ric=min(ric,ric0) ! Au dela de ric0, sm devient n??gatif
        rifc=frif(ric)
        seuilsm=fsm(frif(ric))
        seuilalpha=falpha(frif(ric))
-       yun=1.
-       ydeux=2.
-       hboville=.FALSE.
-       viscom=1.46E-5
-       viscoh=2.06E-5
-       !lmixmin=1.0E-3
-       lmixmin=0.
-       yamada4_num=5
     ELSE
-       ric=0.195
        rifc=0.191
        seuilalpha=1.12
        seuilsm=0.085
-       yun=2.
-       ydeux=1.
-       hboville=.TRUE.
-       viscom=0.
-       viscoh=0.
-       lmixmin=1.
-       yamada4_num=0
     ENDIF
-
-    WRITE(lunout,*)'YAMADA4 RIc, RIfc, Sm_min, Alpha_min',ric,rifc,seuilsm,seuilalpha
-    firstcall = .FALSE.
-    CALL getin_p('lmixmin',lmixmin)
-    CALL getin_p('yamada4_hboville',hboville)
-    CALL getin_p('yamada4_num',yamada4_num)
-  END IF
-
-
 
 !===============================================================================
@@ -444,5 +392,5 @@
          tkeprov= tkeprov*                           &
            &  (tkeprov+dt*(shear(ig,k)+max(0.,buoy(ig,k))))/ &
-           &  (tkeprov+dt*((-1.)*min(0.,buoy(ig,k))+dissip(ig,k)))
+           &  (tkeprov+dt*((-1.)*min(0.,buoy(ig,k))+dissip(ig,k)+drgpro(ig,k)*tkeprov))
          q2(ig,k)=tkeprov*ydeux
         ENDDO
@@ -497,10 +445,4 @@
          DO ig=1,ngrid
          tkeprov=q2(ig,k)/ydeux
-
-!             if(ifl_pbltree .eq. 0) then
-!         disseff=dissip(ig,k)-min(0.,buoy(ig,k))
-!         tkeexp=exp(-dt*disseff/tkeprov)
-!         tkeprov= shear(ig,k)*tkeprov/disseff*(1.-tkeexp)+tkeprov*tkeexp
-!           else
 !FC on ajoute la dissipation due aux arbres
          disseff=dissip(ig,k)-min(0.,buoy(ig,k)) + drgpro(ig,k)*tkeprov
@@ -510,8 +452,5 @@
          tkeprov= (shear(ig,k)+ &
           & drgpro(ig,k)*(winds(ig,k))**3)*tkeprov/disseff*(1.-tkeexp)+tkeprov*tkeexp
-!               endif
-
          q2(ig,k)=tkeprov*ydeux
-
          ! En cas stable, on traite la flotabilite comme la
          ! dissipation, en supposant que buoy/q2^3 est constant.
@@ -522,14 +461,7 @@
        DO k = 2, klev - 1
          DO ig=1,ngrid
-         !tkeprov=q2(ig,k)/ydeux
-         !tkeprov=tkeprov+max(buoy(ig,k)+shear(ig,k),0.)*dt
-         !disseff=dissip(ig,k)-min(0.,buoy(ig,k)+shear(ig,k)) 
-         !tkeexp=exp(-dt*disseff/tkeprov)
-         !tkeprov= tkeprov*tkeexp
-         !q2(ig,k)=tkeprov*ydeux
          ! En cas stable, on traite la flotabilite comme la
          ! dissipation, en supposant que dissipeff/TKE est constant.
          ! Puis on prend la solution exacte
-         ! 
          ! With drag and dissipation from high vegetation (EV & FC, 05/10/2020)
          winds(ig,k)=sqrt(u(ig,k)**2+v(ig,k)**2)
@@ -776,5 +708,5 @@
 SUBROUTINE vdif_q2(timestep, gravity, rconst, ngrid, plev, temp, kmy, q2)
 
-  USE dimphy
+  USE dimphy, only : klev,klon
   IMPLICIT NONE
  
@@ -865,5 +797,5 @@
  SUBROUTINE vdif_q2e(timestep, gravity, rconst, ngrid, plev, temp, kmy, q2)
   
-   USE dimphy
+   USE dimphy, only : klev,klon
   IMPLICIT NONE
 
@@ -936,7 +868,9 @@
 
 
-  USE dimphy
+  USE dimphy, only : klev,klon
+  USE yamada_ini_mod, only : l0
   USE phys_state_var_mod, only: zstd, zsig, zmea
   USE phys_local_var_mod, only: l_mixmin, l_mix
+  USE yamada_ini_mod, only : kap, kapb
 
  ! zstd: ecart type de la'altitud e sous-maille
@@ -998,7 +932,4 @@
 !-------
 
-  LOGICAL, SAVE :: firstcall = .TRUE.
-  !$OMP THREADPRIVATE(firstcall)
-
 ! Outputs
 !---------
@@ -1013,10 +944,6 @@
  REAL     h_oro(klon)
  REAL     hlim(klon)
- REAL, SAVE :: kap=0.4,kapb=0.4
-  !$OMP THREADPRIVATE(kap,kapb)
  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
@@ -1046,9 +973,4 @@
 
   IF (ngrid==0) RETURN
-
-  IF (firstcall) THEN
-    ALLOCATE (l0(klon))
-    firstcall = .FALSE.
-  END IF
 
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/yamada_ini_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/yamada_ini_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/yamada_ini_mod.F90	(revision 4482)
@@ -0,0 +1,91 @@
+MODULE yamada_ini_mod
+
+! AFAIRE : frif defini deux fois.
+! peut on passer une fonction du module au code.
+
+implicit none
+
+save
+
+  LOGICAL :: new_yamada4
+  INTEGER :: yamada4_num
+  !$OMP THREADPRIVATE(new_yamada4,yamada4_num)
+  LOGICAL :: hboville=.TRUE.
+  REAL :: viscom,viscoh,pbl_lmixmin_alpha
+  !$OMP THREADPRIVATE( hboville,viscom,viscoh,pbl_lmixmin_alpha)
+  real :: ric, yun,ydeux,lmixmin,b1,kap,kapb
+  !$OMP THREADPRIVATE(ric, yun,ydeux,lmixmin,b1,kap,kapb)
+
+  real, dimension(:), allocatable, save :: l0
+  !$OMP THREADPRIVATE(l0)
+  integer :: lunout,prt_level
+  !$OMP THREADPRIVATE(lunout,prt_level)
+
+
+CONTAINS
+
+SUBROUTINE yamada_ini(klon,lunout_in,prt_level_in)
+
+   USE ioipsl_getin_p_mod, ONLY : getin_p
+
+! local
+  integer, intent(in) :: klon,lunout_in,prt_level_in
+  real :: ric0
+  real frif,falpha,fsm,ri
+
+  lunout=lunout_in
+  prt_level=prt_level_in
+
+  b1=16.6
+  kap=0.4
+  kapb=0.4
+
+    ALLOCATE (l0(klon))
+
+   new_yamada4=.false.
+   CALL getin_p('new_yamada4',new_yamada4)
+
+
+    IF (new_yamada4) THEN
+! Corrections et reglages issus du travail de these d'Etienne Vignon.
+       ric=0.143 ! qui donne des valeurs proches des seuils proposes
+                 ! dans YAMADA 1983 : sm=0.0845 (0.085 dans Y83)
+                 !                    sm=1.1213 (1.12  dans Y83)
+
+       CALL getin_p('yamada4_ric',ric)
+       ric0=0.19489      ! ric=0.195 originalement, mais produisait sm<0
+       ric=min(ric,ric0) ! Au dela de ric0, sm devient n??gatif
+       yun=1.
+       ydeux=2.
+       hboville=.FALSE.
+       viscom=1.46E-5
+       viscoh=2.06E-5
+       !lmixmin=1.0E-3
+       lmixmin=0.
+       yamada4_num=5
+    ELSE
+       ric=0.195
+       yun=2.
+       ydeux=1.
+       hboville=.TRUE.
+       viscom=0.
+       viscoh=0.
+       lmixmin=1.
+       yamada4_num=0
+    ENDIF
+
+
+!    WRITE(lunout,*)'YAMADA4 RIc, RIfc, Sm_min, Alpha_min',ric,rifc,seuilsm,seuilalpha
+    CALL getin_p('lmixmin',lmixmin)
+    CALL getin_p('yamada4_hboville',hboville)
+    CALL getin_p('yamada4_num',yamada4_num)
+    pbl_lmixmin_alpha=0.0
+    CALL getin_p('pbl_lmixmin_alpha',pbl_lmixmin_alpha)
+
+
+   
+ RETURN
+
+END SUBROUTINE yamada_ini
+
+END MODULE yamada_ini_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/atke_exchange_coeff_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/atke_exchange_coeff_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/atke_exchange_coeff_mod.F90	(revision 4482)
@@ -0,0 +1,1 @@
+link ../phylmd/atke_exchange_coeff_mod.F90
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/atke_turbulence_ini_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/atke_turbulence_ini_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/atke_turbulence_ini_mod.F90	(revision 4482)
@@ -0,0 +1,1 @@
+link ../phylmd/atke_turbulence_ini_mod.F90
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/fisrtilp.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/fisrtilp.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/fisrtilp.F90	(revision 4482)
@@ -143,7 +143,7 @@
   ! Coeffients de fraction lessivee : pour OFF-LINE
   !
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: pfrac_nucl
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: pfrac_1nucl
-  REAL, DIMENSION(klon,klev),      INTENT(OUT)  :: pfrac_impa
+  REAL, DIMENSION(klon,klev),      INTENT(INOUT)  :: pfrac_nucl
+  REAL, DIMENSION(klon,klev),      INTENT(INOUT)  :: pfrac_1nucl
+  REAL, DIMENSION(klon,klev),      INTENT(INOUT)  :: pfrac_impa
   !
   ! Fraction d'aerosols lessivee par impaction et par nucleation
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotopes_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotopes_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotopes_mod.F90	(revision 4482)
@@ -133,5 +133,4 @@
 
 SUBROUTINE iso_init()
-   USE ioipsl_getin_p_mod, ONLY: getin_p
    USE infotrac_phy,       ONLY: ntiso, niso, getKey
     USE strings_mod,       ONLY: maxlen
@@ -175,16 +174,11 @@
 
    !--- Type of water isotopes:
-   iso_eau = strIdx(isoName, 'H2[16]O'); CALL msg('iso_eau='//int2str(iso_eau), modname)
-   iso_HDO = strIdx(isoName, 'H[2]HO');  CALL msg('iso_HDO='//int2str(iso_HDO), modname)
-   iso_O18 = strIdx(isoName, 'H2[18]O'); CALL msg('iso_O18='//int2str(iso_O18), modname)
-   iso_O17 = strIdx(isoName, 'H2[17]O'); CALL msg('iso_O17='//int2str(iso_O17), modname)
-   iso_HTO = strIdx(isoName, 'H[3]HO');  CALL msg('iso_HTO='//int2str(iso_HTO), modname)
-
-   ! initialisation
-   ! lecture des parametres isotopiques:
-   ! pour que ca marche en openMP, il faut utiliser getin_p. Car le getin ne peut
-   ! etre appele que par un thread a la fois, et ca pose tout un tas de problemes,
-   ! d'ou tout un tas de magouilles comme dans conf_phys_m. A terme, tout le monde
-   ! lira par getin_p.
+   iso_eau = strIdx(isoName, 'H216O'); CALL msg('iso_eau='//int2str(iso_eau), modname)
+   iso_HDO = strIdx(isoName, 'HDO');   CALL msg('iso_HDO='//int2str(iso_HDO), modname)
+   iso_O18 = strIdx(isoName, 'H218O'); CALL msg('iso_O18='//int2str(iso_O18), modname)
+   iso_O17 = strIdx(isoName, 'H217O'); CALL msg('iso_O17='//int2str(iso_O17), modname)
+   iso_HTO = strIdx(isoName, 'HTO');   CALL msg('iso_HTO='//int2str(iso_HTO), modname)
+
+   !--- Initialiaation: reading the isotopic parameters.
    CALL get_in('lambda',     lambda_sursat, 0.004)
    CALL get_in('thumxt1',    thumxt1,       0.75*1.2)
@@ -252,5 +246,5 @@
    ! bugs quand temperature dans ascendances convs est mal calculee
    CALL get_in('cond_temp_env',        cond_temp_env,        .FALSE.)
-   IF(ANY(isoName == 'H[3]HO')) &
+   IF(ANY(isoName == 'HTO')) &
    CALL get_in('ok_prod_nucl_tritium', ok_prod_nucl_tritium, .FALSE., .FALSE.)
 
@@ -339,14 +333,16 @@
    USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
    USE mod_phys_lmdz_transfert_para, ONLY : bcast
-   CHARACTER(LEN=*),  INTENT(IN)    :: nam
-   CHARACTER(LEN=*),  INTENT(INOUT) :: val
-   CHARACTER(LEN=*),  INTENT(IN)    :: def
-   LOGICAL, OPTIONAL, INTENT(IN)    :: lDisp
+   CHARACTER(LEN=*),           INTENT(IN)    :: nam
+   CHARACTER(LEN=*),           INTENT(INOUT) :: val
+   CHARACTER(LEN=*), OPTIONAL, INTENT(IN)    :: def
+   LOGICAL,          OPTIONAL, INTENT(IN)    :: lDisp
    LOGICAL :: lD
 !$OMP BARRIER
-   IF(.NOT.(is_mpi_root.AND.is_omp_root)) RETURN
-   val=def; CALL getin(nam,val); CALL bcast(val)
-   lD=.TRUE.; IF(PRESENT(lDisp)) lD=lDisp
-   IF(lD) CALL msg(TRIM(nam)//' = '//TRIM(val))
+   IF(is_mpi_root.AND.is_omp_root) THEN
+      IF(PRESENT(def)) val=def; CALL getin(nam,val)
+      lD=.TRUE.; IF(PRESENT(lDisp)) lD=lDisp
+      IF(lD) CALL msg(TRIM(nam)//' = '//TRIM(val))
+  END IF
+  CALL bcast(val)
 END SUBROUTINE getinp_s
 
@@ -358,12 +354,14 @@
    CHARACTER(LEN=*),  INTENT(IN)    :: nam
    INTEGER,           INTENT(INOUT) :: val
-   INTEGER,           INTENT(IN)    :: def
+   INTEGER, OPTIONAL, INTENT(IN)    :: def
    LOGICAL, OPTIONAL, INTENT(IN)    :: lDisp
    LOGICAL :: lD
 !$OMP BARRIER
-   IF(.NOT.(is_mpi_root.AND.is_omp_root)) RETURN
-   val=def; CALL getin(nam,val); CALL bcast(val)
-   lD=.TRUE.; IF(PRESENT(lDisp)) lD=lDisp
-   IF(lD) CALL msg(TRIM(nam)//' = '//TRIM(int2str(val)))
+   IF(is_mpi_root.AND.is_omp_root) THEN
+      IF(PRESENT(def)) val=def; CALL getin(nam,val)
+      lD=.TRUE.; IF(PRESENT(lDisp)) lD=lDisp
+      IF(lD) CALL msg(TRIM(nam)//' = '//TRIM(int2str(val)))
+  END IF
+  CALL bcast(val)
 END SUBROUTINE getinp_i
 
@@ -375,12 +373,14 @@
    CHARACTER(LEN=*),  INTENT(IN)    :: nam
    REAL,              INTENT(INOUT) :: val
-   REAL,              INTENT(IN)    :: def
+   REAL,    OPTIONAL, INTENT(IN)    :: def
    LOGICAL, OPTIONAL, INTENT(IN)    :: lDisp
    LOGICAL :: lD
 !$OMP BARRIER
-   IF(.NOT.(is_mpi_root.AND.is_omp_root)) RETURN
-   val=def; CALL getin(nam,val); CALL bcast(val)
-   lD=.TRUE.; IF(PRESENT(lDisp)) lD=lDisp
-   IF(lD) CALL msg(TRIM(nam)//' = '//TRIM(real2str(val)))
+   IF(is_mpi_root.AND.is_omp_root) THEN
+      IF(PRESENT(def)) val=def; CALL getin(nam,val)
+      lD=.TRUE.; IF(PRESENT(lDisp)) lD=lDisp
+      IF(lD) CALL msg(TRIM(nam)//' = '//TRIM(real2str(val)))
+  END IF
+  CALL bcast(val)
 END SUBROUTINE getinp_r
 
@@ -392,12 +392,14 @@
    CHARACTER(LEN=*),  INTENT(IN)    :: nam
    LOGICAL,           INTENT(INOUT) :: val
-   LOGICAL,           INTENT(IN)    :: def
+   LOGICAL, OPTIONAL, INTENT(IN)    :: def
    LOGICAL, OPTIONAL, INTENT(IN)    :: lDisp
    LOGICAL :: lD
 !$OMP BARRIER
-   IF(.NOT.(is_mpi_root.AND.is_omp_root)) RETURN
-   val=def; CALL getin(nam,val); CALL bcast(val)
-   lD=.TRUE.; IF(PRESENT(lDisp)) lD=lDisp
-   IF(lD) CALL msg(TRIM(nam)//' = '//TRIM(bool2str(val)))
+   IF(is_mpi_root.AND.is_omp_root) THEN
+      IF(PRESENT(def)) val=def; CALL getin(nam,val)
+      lD=.TRUE.; IF(PRESENT(lDisp)) lD=lDisp
+      IF(lD) CALL msg(TRIM(nam)//' = '//TRIM(bool2str(val)))
+  END IF
+  CALL bcast(val)
 END SUBROUTINE getinp_l
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotopes_routines_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotopes_routines_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotopes_routines_mod.F90	(revision 4482)
@@ -1731,7 +1731,7 @@
        else
            write(*,*) 'iso_fractcal 1734: non prévu: ixt=',ixt
-#ifdef ISOVERIF
-           stop
-#endif
+!#ifdef ISOVERIF
+           CALL abort_physic('isotopes_routines_mod', 'iso_fractcal 1734', 1)
+!#endif
        endif
 
@@ -1949,7 +1949,7 @@
        else
            write(*,*) 'iso_fractcal 1954: non prévu: ixt=',ixt
-#ifdef ISOVERIF
-           stop
-#endif
+!#ifdef ISOVERIF
+          CALL abort_physic('isotopes_routines_mod', 'iso_fractcal 1954', 1)
+!#endif
        endif
 
@@ -2185,5 +2185,5 @@
         write(*,*) 'qsol(i)=',qsol(i),' mais evap(i)=',evap(i)
         write(*,*) 'q1lay(i)=',q1lay(i)
-        stop
+        CALL abort_physic('isotopes_routines_mod', 'iso_surf 2187', 1)
  endif !if (q1lay(i).gt.ridicule) then
 endif !if (qsol(i).gt.ridicule_rain) then
@@ -2414,5 +2414,5 @@
     write(*,*) 'iso_surf>iso_rosee_givre 3189: evap=',evap(i)
     write(*,*) 'q1lay(i)=',q1lay(i)
-    stop
+    CALL abort_physic('isotopes_routines_mod', 'iso_surf 2416', 1)
 endif !if (q1lay(i).gt.0) then
 
@@ -2552,5 +2552,5 @@
   write(*,*) 'il,Pqisup(il),Eqi(il),Pqiinf(il)=', &
 &          il,Pqisup(il),Eqi(il),Pqiinf(il) 
-  stop
+  CALL abort_physic('isotopes_routines_mod', 'stewart 2554', 1)
 endif !if (iso_verif_egalite
 enddo !do il=1,ncas 
@@ -16508,246 +16508,162 @@
       end subroutine phyiso_etat0_dur
 
-      subroutine phyiso_etat0_fichier( &
-     &           snow,run_off_lic_0, &
-     &           xtsnow,xtrun_off_lic_0, &
-     &           Rland_ice)
-      USE dimphy, only: klon,klev
-      !USE mod_grid_phy_lmdz
-      !USE mod_phys_lmdz_para
-      USE iophy
-      USE phys_state_var_mod, ONLY: q_ancien,xt_ancien,wake_deltaq,wake_deltaxt, &
-#ifdef ISOVERIF
-        rain_fall,snow_fall,fevap,qsol, &
-#endif
-        xtrain_fall,xtsnow_fall,ql_ancien,xtl_ancien,qs_ancien,xts_ancien, &
-        fxtevap,xtsol
-      !USE iostart
-      !USE write_field_phy
-      USE indice_sol_mod, only: nbsrf  
-  USE isotopes_mod, ONLY: isoName,iso_HDO,iso_eau
-#ifdef ISOVERIF
-  USE isotopes_verif_mod
+SUBROUTINE phyiso_etat0_fichier(snow, run_off_lic_0, xtsnow, xtrun_off_lic_0, Rland_ice)
+   USE dimphy,             ONLY: klon,klev
+   USE iophy
+   USE phys_state_var_mod, ONLY: q_ancien, xt_ancien, wake_deltaq, wake_deltaxt, &
+#ifdef ISOVERIF
+     rain_fall, snow_fall, fevap,qsol, &
+#endif
+     xtrain_fall, xtsnow_fall, ql_ancien, xtl_ancien, qs_ancien, xts_ancien, fxtevap, xtsol
+   USE indice_sol_mod,    ONLY: nbsrf
+   USE isotopes_mod,      ONLY: isoName,iso_HDO,iso_eau
+   USE phyetat0_get_mod,  ONLY: phyetat0_get, phyetat0_srf
+   USE readTracFiles_mod, ONLY: new2oldH2O
+   USE strings_mod,       ONLY: strIdx, strTail, maxlen, msg, int2str
+#ifdef ISOVERIF
+   USE isotopes_verif_mod
 #endif
 #ifdef ISOTRAC
- USE isotrac_mod, ONLY: strtrac,initialisation_isotrac,index_iso, &
-&       index_zone,izone_init
-#endif
-        implicit none
+   USE isotrac_mod, ONLY: strtrac, initialisation_isotrac, index_iso, index_zone, izone_init
+#endif
+   IMPLICIT NONE
 
 #include "netcdf.inc"
 #include "dimsoil.h"
 #include "clesphys.h"
-! #include "thermcell.h"
 #include "compbl.h"    
 
-        ! inputs 
-        !REAL qsol(klon)
-        REAL snow(klon,nbsrf)
-        !REAL evap(klon,nbsrf)
-        REAL run_off_lic_0(klon)
-        ! outputs   
-        !REAL xtsol(niso,klon)
-        REAL xtsnow(niso,klon,nbsrf) 
-        !REAL xtevap(ntraciso,klon,nbsrf)     
-        REAL xtrun_off_lic_0(niso,klon)
-        REAL Rland_ice(niso,klon)
-
-        ! locals
-        real iso_tmp(klon)
-        real iso_tmp_lonlev(klon,klev)
-        real iso_tmp_lonsrf(klon,nbsrf)
-        INTEGER ierr
-        integer i,ixt,k,nsrf
-        INTEGER nid, nvarid
-        CHARACTER*2 str2
-        CHARACTER*5 str5
-        real xmin,xmax    
-        CHARACTER*50 outiso  
-        integer lnblnk
-        LOGICAL :: found,phyetat0_get,phyetat0_srf
-
-!#ifdef ISOVERIF
-!      integer iso_verif_egalite_nostop
-!#endif
-!#ifdef ISOVERIF
-!        real deltaD
-!        integer iso_verif_noNaN_nostop
-!#endif
+   REAL, INTENT(IN) ::             snow     (klon,nbsrf)
+   REAL, INTENT(IN) ::    run_off_lic_0     (klon)
+   REAL, INTENT(OUT) ::          xtsnow(niso,klon,nbsrf) 
+   REAL, INTENT(OUT) :: xtrun_off_lic_0(niso,klon)
+   REAL, INTENT(OUT) ::       Rland_ice(niso,klon)
+
+   INTEGER :: ierr, i, ixt, k, nsrf, nid, nvarid, lnblnk
+   CHARACTER(LEN=2) :: str2
+   CHARACTER(LEN=5) :: str5
+   CHARACTER(LEN=maxlen) :: outiso, oldIso, modname, nam(2)
+   REAL :: xmin, xmax
+   LOGICAL :: found
 #ifdef ISOTRAC
-        integer iiso,izone
-#endif
-
-
-   write(*,*) 'phyiso_etat0_fichier 3'
-   write(*,*) 'niso=',niso
-   write(*,*) 'isoName(1)='//TRIM(isoName(1))
-
-   do ixt=1,ntraciso
-
-      outiso=TRIM(isoName(ixt))
-      i = INDEX(outiso, '_', .TRUE.)
-      outiso = outiso(1:i-1)//outiso(i+1:LEN_TRIM(outiso))
-      write(*,*) 'phyiso_etat0_fichier 16621: ixt,outiso=',ixt,TRIM(outiso)
-
-           
-      ! on lit seulement si ixt<=niso ou si on initialise les traceurs d'après
-      ! fichier:
+   INTEGER :: iiso, izone
+#endif
+
+   modname = 'phyiso_etat0_fichier'
+   CALL msg('3', modname)
+   CALL msg('niso = '//TRIM(int2str(niso)), modname)
+   CALL msg('isoName(1) = '//TRIM(isoName(1)), modname)
+
+   DO ixt = 1, ntraciso
+
+      outiso = isoName(ixt)
+      oldIso = strTail(new2oldH2O(outiso), '_')            !--- Remove "H2O_" from "H2O_<iso>[_<tag>]"
+      ! on lit seulement si ixt<=niso ou si on initialise les traceurs d'après fichier:
 #ifdef ISOTRAC
-      if ((ixt.le.niso).or.(initialisation_isotrac.eq.0)) then
-#endif
-
-      found=phyetat0_srf(1,iso_tmp_lonsrf,"XTSNOW"//TRIM(outiso),"Surface snow",0.)
-      if (.NOT.found) CALL abort_physic('isotopes_routines_mod', &
-                            'phyiso_etat0_fichier 16581: variable isotopique not found',1)
-      xtsnow(ixt,:,:)=iso_tmp_lonsrf(:,:)
-      
-      found=phyetat0_srf(1,iso_tmp_lonsrf,"XTEVAP"//TRIM(outiso),"evaporation",0.)
-      fxtevap(ixt,:,:)=iso_tmp_lonsrf(:,:)
-
-      found=phyetat0_get(1,iso_tmp,"xtrain_f"//TRIM(outiso),"xrain fall",0.)
-      xtrain_fall(ixt,:)=iso_tmp(:)
-
-      found=phyetat0_get(1,iso_tmp,"xtsnow_f"//TRIM(outiso),"snow fall",0.)
-      xtsnow_fall(ixt,:)=iso_tmp(:)
-
-      found=phyetat0_get(klev,iso_tmp_lonlev,"XTANCIEN"//TRIM(outiso),"QANCIEN",0.)
-      xt_ancien(ixt,:,:)=iso_tmp_lonlev(:,:)
-
-      found=phyetat0_get(klev,iso_tmp_lonlev,"XTLANCIEN"//TRIM(outiso),"QLANCIEN",0.)
-      xtl_ancien(ixt,:,:)=iso_tmp_lonlev(:,:)
-
-      found=phyetat0_get(klev,iso_tmp_lonlev,"XTSANCIEN"//TRIM(outiso),"QSANCIEN",0.)
-      xts_ancien(ixt,:,:)=iso_tmp_lonlev(:,:)
-
-      found=phyetat0_get(1,iso_tmp,"XTRUNOFFLIC0"//TRIM(outiso),"RUNOFFLIC0",0.)  
-      xtrun_off_lic_0(ixt,:)=iso_tmp(:)
-
-      found=phyetat0_get(klev,iso_tmp_lonlev,"WAKE_DELTAXT"//TRIM(outiso),"Delta hum. wake/env",0.)  
-      wake_deltaxt(ixt,:,:)=iso_tmp_lonlev(:,:)
-
-#ifdef ISOVERIF           
-      if ((ixt.eq.iso_eau).and.(iso_eau.gt.0)) then
-        do i=1,klon
-         call iso_verif_egalite(xtrain_fall(iso_eau,i),rain_fall(i), &
-     &           'phyisoetat0_fichier 231a')
-         call iso_verif_egalite(xtsnow_fall(iso_eau,i),snow_fall(i), &
-     &           'phyisoetat0_fichier 231b')
-         DO nsrf = 1, nbsrf
-         call iso_verif_egalite(fxtevap(iso_eau,i,nsrf),fevap(i,nsrf), &
-     &           'phyisoetat0_fichier 231c')
-         call iso_verif_egalite(xtsnow(iso_eau,i,nsrf),snow(i,nsrf), &
-     &           'phyisoetat0_fichier 231d')
-         enddo !DO nsrf = 1, nbsrf
-        enddo !do i=1,klon        
-      endif !if (iso_eau.gt.0) then  
-        if ((iso_HDO.gt.0).and.(ixt.eq.iso_HDO)) then
-              do k=1,klev
-               do i=1,klon
-                if (q_ancien(i,k).gt.2e-3) then
-                call iso_verif_aberrant(xt_ancien(iso_hdo,i,k) &
-     &           /q_ancien(i,k),'phyisoetat0_fichier 312')
-                endif !if (q_ancien(i,k).gt.2e-3) then
-               enddo !do i=1,klon
-              enddo !do k=1,klev
-      endif !if ((iso_HDO.gt.0).and.(ixt.eq.iso_HDO)) then 
-      if (iso_eau.gt.0) then   
-        do i=1,klon
-          if (iso_verif_egalite_nostop(run_off_lic_0(i), &
-     &           xtrun_off_lic_0(iso_eau,i), &
-     &          'phyiso_etat0_fichier 326').eq.1) then
-            write(*,*) 'i=',i
-            stop
-          endif !if (iso_verif_egalite_nostop(run_off_lic_0(i),
-        enddo !do i=1,klon
-      endif !if (iso_eau.gt.0) then 
-#endif
-
-       ! ces variables n'ont pas de traceurs:
-       if (ixt.le.niso) then
-        found=phyetat0_get(1,iso_tmp,"XTSOL"//TRIM(outiso),"Surface hmidity / bucket",0.)  
-        xtsol(ixt,:)=iso_tmp(:)
-
-        found=phyetat0_get(1,iso_tmp,"Rland_ice"//TRIM(outiso),"R land ice",0.)
-        Rland_ice(ixt,:)=iso_tmp(:)
-
-#ifdef ISOVERIF
-      do i=1,klon
-          if (iso_verif_noNaN_nostop(xtsol(ixt,i), &
-     &          'phyiso_etat0_fichier 95').eq.1) then
-            write(*,*) 'ixt,i=',ixt,i
-            stop
-          endif       
-      enddo !do i=1,klon
-#endif
-
-       endif
-
+      IF(ixt <= niso .OR. initialisation_isotrac == 0) THEN
+#endif
+      found = phyetat0iso_srf3(xtsnow,      "XTSNOW", "Surface snow", 0.)
+      if (.NOT.found) CALL abort_physic('isotopes_routines_mod', 'phyiso_etat0_fichier 16581: unfound isotopic variable',1)
+      found = phyetat0iso_srf3(fxtevap,     "XTEVAP", "evaporation",  0.)
+      found = phyetat0iso_get2(xtrain_fall, "xtrain_f", "xrain fall", 0.)
+      found = phyetat0iso_get2(xtsnow_fall, "xtsnow_f", "xsnow fall", 0.)
+      found = phyetat0iso_get3(xt_ancien,   "XTANCIEN",  "QANCIEN",   0.)
+      found = phyetat0iso_get3(xtl_ancien,  "XTLANCIEN", "QLANCIEN",  0.)
+      found = phyetat0iso_get3(xts_ancien,  "XTSANCIEN", "QSANCIEN",  0.)
+      found = phyetat0iso_get2(xtrun_off_lic_0, "XTRUNOFFLIC0", "RUNOFFLIC0", 0.)
+      found = phyetat0iso_get3(wake_deltaxt,  "WAKE_DELTAXT", "Delta hum. wake/env",  0.)
+#ifdef ISOVERIF
+      IF(ixt == iso_eau .AND. iso_eau > 0) THEN
+         DO i=1,klon
+            CALL iso_verif_egalite(xtrain_fall(iso_eau,i),rain_fall(i),TRIM(modname)//' 231a')
+            CALL iso_verif_egalite(xtsnow_fall(iso_eau,i),snow_fall(i),TRIM(modname)//' 231b')
+            DO nsrf = 1, nbsrf
+               CALL iso_verif_egalite(fxtevap(iso_eau,i,nsrf),fevap(i,nsrf),TRIM(modname)//' 231c')
+               CALL iso_verif_egalite( xtsnow(iso_eau,i,nsrf), snow(i,nsrf),TRIM(modname)//' 231d')
+            END DO
+         END DO
+      END IF
+      IF(ixt == iso_HDO .AND. iso_HDO > 0) THEN
+         DO k=1,klev
+            DO i=1,klon
+               IF(q_ancien(i,k) > 2e-3) &
+                  CALL iso_verif_aberrant(xt_ancien(iso_hdo,i,k)/q_ancien(i,k),TRIM(modname)//' 312')
+            END DO
+         END DO
+      END IF
+      IF(iso_eau > 0 .AND. ixt == iso_eau) THEN
+         DO i=1,klon
+            IF(iso_verif_egalite_nostop(run_off_lic_0(i),xtrun_off_lic_0(iso_eau,i),TRIM(modname)//' 326') == 1) THEN
+               WRITE(*,*) 'i=',i
+               STOP
+            END IF
+         END DO
+      END IF
+#endif
+      ! ces variables n'ont pas de traceurs:
+      IF(ixt <= niso) THEN
+         found = phyetat0iso_get2(xtsol, "XTSOL", "Surface humidity / bucket", 0.)
+         found = phyetat0iso_get2(Rland_ice, "Rland_ice", "SR land ice", 0.)
+#ifdef ISOVERIF
+
+         DO i=1,klon
+            IF(iso_verif_noNaN_nostop(xtsol(ixt,i),TRIM(modname)//' 95') == 1) THEN
+               WRITE(*,*) 'ixt,i=',ixt,i
+               STOP
+            END IF
+         END DO
+#endif
+      END IF
 #ifdef ISOTRAC
-     endif !if ((ixt.le.niso).or.(initialisation_isotrac.eq.0)) then
-#endif
-
-  enddo !do ixt=1,ntraciso
+      END IF ! IF(ixt > niso .OR. initialisation_isotrac == 0))
+#endif
+
+   END DO
 
 #ifdef ISOTRAC
-        if (initialisation_isotrac.ne.0) then
-        ! on n'initialise pas d'après le fichier
-        ! l'eau normale est mise dans la zone izone_init
-
-        do ixt=niso+1,ntraciso
-
-             iiso=index_iso(ixt)
-
-             if (index_zone(ixt).eq.izone_init) then
-                do i=1,klon
-                 do nsrf = 1, nbsrf
-                  fxtevap(ixt,i,nsrf)=fxtevap(iiso,i,nsrf)
-                 enddo !do nsrf = 1, nbsrf
-                 xtsnow_fall(ixt,i)=xtsnow_fall(iiso,i)
-                 xtrain_fall(ixt,i)=xtrain_fall(iiso,i)
-                 do k=1,klev
-                   xt_ancien(ixt,i,k)=xt_ancien(iiso,i,k)
-                   xtl_ancien(ixt,i,k)=xtl_ancien(iiso,i,k)
-                   xts_ancien(ixt,i,k)=xts_ancien(iiso,i,k)
-                   wake_deltaxt(ixt,i,k)= wake_deltaxt(iiso,i,k)    
-                 enddo
-                enddo !do i=1,klon
-             else !if (index_zone(ixt).eq.izone_init) then
-                do i=1,klon
-                 do nsrf = 1, nbsrf
-                  fxtevap(ixt,i,nsrf)=0.0
-                 enddo !do nsrf = 1, nbsrf
-                 xtsnow_fall(ixt,i)=0.0
-                 xtrain_fall(ixt,i)=0.0
-                 do k=1,klev
-                   xt_ancien(ixt,i,k)=0.0
-                   xtl_ancien(ixt,i,k)=0.0
-                   xts_ancien(ixt,i,k)=0.0
-                 enddo
-                enddo !do i=1,klon
-             endif !if (index_zone(ixt).eq.izone_init) then
-
-         enddo  !do ixt=1,niso
-      endif !if (initialisation_isotrac.eq.0) then
-
-
-#ifdef ISOVERIF
-        DO nsrf = 1, nbsrf
-         do i=1,klon
-               call iso_verif_traceur(fxtevap(1,i,nsrf), &
-     &                   'phyiso_etat0_fichier 426')
-         enddo !do i=1,klon 
-        enddo !DO nsrf = 1, nbsrf
-        do i=1,klon
-           call iso_verif_traceur(xtrain_fall(1,i), &
-     &                   'phyiso_etat0_fichier 466')
-           call iso_verif_traceur(xtsnow_fall(1,i), &
-     &                   'phyiso_etat0_fichier 468')
-        enddo !do i=1,klon 
-        do k=1,klev
-          do i=1,klon
-               call iso_verif_traceur(xt_ancien(1,i,k), &
-     &                   'phyiso_etat0_fichier 591')
-          enddo !do i=1,klon
-        enddo !do k=1,klev             
+   IF(initialisation_isotrac /= 0) THEN
+      ! On n'initialise pas d'apres le fichier. L'eau normale est mise dans la zone izone_init
+      DO ixt=niso+1,ntraciso
+         iiso=index_iso(ixt)
+         IF(index_zone(ixt) == izone_init) THEN
+            DO i = 1, klon
+               fxtevap(ixt,i,1:nbsrf) = fxtevap(iiso,i,1:nbsrf)
+               xtsnow_fall(ixt,i) = xtsnow_fall(iiso,i)
+               xtrain_fall(ixt,i) = xtrain_fall(iiso,i)
+               DO k = 1, klev
+                  xt_ancien   (ixt,i,k) = xt_ancien   (iiso,i,k)
+                  xtl_ancien  (ixt,i,k) = xtl_ancien  (iiso,i,k)
+                  xts_ancien  (ixt,i,k) = xts_ancien  (iiso,i,k)
+                  wake_deltaxt(ixt,i,k) = wake_deltaxt(iiso,i,k)    
+               END DO
+            END DO
+         ELSE
+            DO i = 1, klon
+               fxtevap(ixt,i,1:nbsrf)=0.0
+               xtsnow_fall(ixt,i)=0.0
+               xtrain_fall(ixt,i)=0.0
+               xt_ancien (ixt,i,1:klev) = 0.0
+               xtl_ancien(ixt,i,1:klev) = 0.0
+               xts_ancien(ixt,i,1:klev) = 0.0
+            END DO
+         END IF
+      END DO
+   END IF
+
+#ifdef ISOVERIF
+   DO nsrf = 1, nbsrf
+      DO i = 1, klon
+         CALL iso_verif_traceur(fxtevap(1,i,nsrf), 'phyiso_etat0_fichier 426')
+      END DO
+   END DO
+   DO i=1,klon
+      CALL iso_verif_traceur(xtrain_fall(1,i), 'phyiso_etat0_fichier 466')
+      CALL iso_verif_traceur(xtsnow_fall(1,i), 'phyiso_etat0_fichier 468')
+   END DO
+   DO k = 1, klev
+      DO i = 1, klon
+         CALL iso_verif_traceur(xt_ancien(1,i,k), 'phyiso_etat0_fichier 591')
+      END DO
+   END DO
 #endif 
         ! endif ISOVERIF       
@@ -16755,9 +16671,43 @@
         ! endif ISOTRAC      
 
-! on ferme le fichier
-!      CALL close_startphy
-! déjà fermé dans phyetat0
+CONTAINS
+
+LOGICAL FUNCTION phyetat0iso_get2(field, pref, descr, default) RESULT(lFound)
+  REAL,             INTENT(INOUT) :: field(:,:)
+  CHARACTER(LEN=*), INTENT(IN)    :: pref, descr
+  REAL,             INTENT(IN)    :: default
+  REAL :: iso_tmp(klon)
+  nam(1) = TRIM(pref)//TRIM(outiso)
+  nam(2) = TRIM(pref)//TRIM(oldIso)
+  lFound = phyetat0_get(iso_tmp, nam, descr, default)
+  field(ixt,:) = iso_tmp
+END FUNCTION phyetat0iso_get2
+
+
+LOGICAL FUNCTION phyetat0iso_get3(field, pref, descr, default) RESULT(lFound)
+  REAL,             INTENT(INOUT) :: field(:,:,:)
+  CHARACTER(LEN=*), INTENT(IN)    :: pref, descr
+  REAL,             INTENT(IN)    :: default
+  REAL :: iso_tmp_lonlev(klon,klev)
+  nam(1) = TRIM(pref)//TRIM(outiso)
+  nam(2) = TRIM(pref)//TRIM(oldIso)
+  lFound = phyetat0_get(iso_tmp_lonlev, nam, descr, default)
+  field(ixt,:,:) = iso_tmp_lonlev(:,:)
+END FUNCTION phyetat0iso_get3
+
+LOGICAL FUNCTION phyetat0iso_srf3(field, pref, descr, default) RESULT(lFound)
+  REAL,             INTENT(INOUT) :: field(:,:,:)
+  CHARACTER(LEN=*), INTENT(IN)    :: pref, descr
+  REAL,             INTENT(IN)    :: default
+  REAL :: iso_tmp_lonsrf(klon,nbsrf)
+  nam(1) = TRIM(pref)//TRIM(outiso)
+  nam(2) = TRIM(pref)//TRIM(oldIso)
+  lFound = phyetat0_srf(iso_tmp_lonsrf, nam, descr, default)
+  field(ixt,:,:) = iso_tmp_lonsrf
+END FUNCTION phyetat0iso_srf3
 
         end subroutine phyiso_etat0_fichier
+
+
 
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotopes_verif_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotopes_verif_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotopes_verif_mod.F90	(revision 4482)
@@ -5,8 +5,8 @@
 MODULE isotopes_verif_mod
 !use isotopes_mod, ONLY: 
-#ifdef ISOTRAC
-   USE isotrac_mod, ONLY: nzone
-#endif
-USE infotrac_phy, ONLY: ntraciso=>ntiso, niso, itZonIso
+!#ifdef ISOTRAC
+!   USE isotrac_mod, ONLY: nzone
+!#endif
+USE infotrac_phy, ONLY: ntraciso=>ntiso, niso, itZonIso, nzone
 implicit none
 save
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotrac_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotrac_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotrac_mod.F90	(revision 4482)
@@ -1,104 +1,27 @@
 #ifdef ISO
 #ifdef ISOTRAC
-! $Id: $
 
 MODULE isotrac_mod
-use infotrac_phy, ONLY: niso,ntiso,ntraceurs_zone=>nzone
-use isotopes_mod, only: ridicule
-
-IMPLICIT NONE
-SAVE
-
-! contient toutes les variables traceurs isotopiques + les routines specifiquement
-! traceurs isotopiques
-
-      real ridicule_trac
-      parameter (ridicule_trac=ridicule*1e4)
-
-integer, save ::  option_traceurs 
-integer, save ::  ntraceurs_zone_opt ! ntraceurs_zone propre à l'option
-! on vérifie que ça correspond bien à ntraceurs_zone d'infotrac
-integer, save ::  ntraceurs_zoneOR
-!$OMP THREADPRIVATE(option_traceurs,ntraceurs_zone_opt,ntraceurs_zoneOR)
-integer, save ::  initialisation_isotrac
-                ! 1 pour idéalisé
-                ! 0 pour lecture dans fichier
-!$OMP THREADPRIVATE(initialisation_isotrac)
-
-! variables spécifiques aux différentes options, mais necessaires au
-! calcul du nombre de zones de traceurs
-! si option=3
-integer, save :: use_bassin_atlantic
-!$OMP THREADPRIVATE(use_bassin_atlantic)
-integer, save :: use_bassin_medit
-!$OMP THREADPRIVATE(use_bassin_medit)
-integer, save :: use_bassin_indian
-!$OMP THREADPRIVATE(use_bassin_indian)
-integer, save :: use_bassin_austral
-!$OMP THREADPRIVATE(use_bassin_austral)
-integer, save :: use_bassin_pacific
-!$OMP THREADPRIVATE(use_bassin_pacific)
-integer, save :: use_bassin_merarabie
-!$OMP THREADPRIVATE(use_bassin_merarabie)
-integer, save :: use_bassin_golfebengale
-!$OMP THREADPRIVATE(use_bassin_golfebengale)
-integer, save :: use_bassin_indiansud
-!$OMP THREADPRIVATE(use_bassin_indiansud)
-integer, save :: use_bassin_tropics
-!$OMP THREADPRIVATE(use_bassin_tropics)
-integer, save :: use_bassin_midlats
-!$OMP THREADPRIVATE(use_bassin_midlats)
-integer, save :: use_bassin_hauteslats
-!$OMP THREADPRIVATE(use_bassin_hauteslats)
-integer, save :: bassin_atlantic
-!$OMP THREADPRIVATE(bassin_atlantic)
-integer, save :: bassin_medit
-!$OMP THREADPRIVATE(bassin_medit)
-integer, save :: bassin_indian
-!$OMP THREADPRIVATE(bassin_indian)
-integer, save :: bassin_austral
-!$OMP THREADPRIVATE(bassin_austral)
-integer, save :: bassin_pacific
-!$OMP THREADPRIVATE(bassin_pacific)
-integer, save :: bassin_merarabie
-!$OMP THREADPRIVATE(bassin_merarabie)
-integer, save :: bassin_golfebengale
-!$OMP THREADPRIVATE(bassin_golfebengale)
-integer, save :: bassin_indiansud
-!$OMP THREADPRIVATE(bassin_indiansud)
-integer, save :: bassin_tropics
-!$OMP THREADPRIVATE(bassin_tropics)
-integer, save :: bassin_midlats
-!$OMP THREADPRIVATE(bassin_midlats)
-integer, save :: bassin_hauteslats
-!$OMP THREADPRIVATE(bassin_hauteslats)
-! si option=4
-integer nzone_temp
-parameter (nzone_temp=1)
-real, save :: zone_temp1,zone_tempf,zone_tempa  
-!$OMP THREADPRIVATE(zone_temp1,zone_tempf,zone_tempa)
-! si option 14
-integer nzone_lat
-parameter (nzone_lat=4)
-integer nzone_pres
-parameter (nzone_pres=3)
-real, save :: zone_pres1,zone_presf,zone_presa 
-!$OMP THREADPRIVATE(zone_pres1,zone_presf,zone_presa) 
-real, save :: dlattag,lattag_min
-!$OMP THREADPRIVATE(dlattag,lattag_min)
-
-
-! option 1: on trace evap ocean et continent séparement  
+  USE infotrac_phy,      ONLY: niso, ntiso, nzone
+  USE readTracFiles_mod, ONLY: delPhase
+  USE isotopes_mod,      ONLY: ridicule, get_in
+
+  IMPLICIT NONE
+  SAVE
+
+!=== CONTENT: ALL THE ISOTOPIC TRACERS RELATED VARIABLES ===
+!
+! option 1: on trace evap ocean et continent separement  
 ! option 2: on trace evap ocean, continent et evap precip
-! option 3: on trace evap différents bassins océaniques 
-!       + continents + résidu
-!       attention, choisir dans ce cas les bassins océaniques
+! option 3: on trace evap differents bassins oceaniques 
+!       + continents + residu
+!       attention, choisir dans ce cas les bassins oceaniques
 !       dans iso_traceurs_opt3F90.h 
-! option 4: tracage par température minimale
-!       dans ce cas, on définit des bins dans iso_traceurs_opt4.h
-! option 5: pour AMMA: on taggue résidu/AEJ/flux mousson/Harmattan
+! option 4: tracage par temperature minimale
+!       dans ce cas, on definit des bins dans iso_traceurs_opt4.h
+! option 5: pour AMMA: on taggue residu/AEJ/flux mousson/Harmattan
 ! option 6: taggage des ddfts
-! option 7: pour Sandrine: taggage de la vapeur à 700hPa pour omega500<-20 TODO
-! option 8: pour Sandrine: taggage de la vapeur entre 950 et 800hPa, omega de 0 à 25 hPa et de l'évaoration en omega<-20. TODO
+! option 7: pour Sandrine: taggage de la vapeur a 700hPa pour omega500<-20 TODO
+! option 8: pour Sandrine: taggage de la vapeur entre 950 et 800hPa, omega de 0 a 25 hPa et de l'evaoration en omega<-20. TODO
 ! option 9: taggage du condensat et de la revap precip
 ! option 10: taggage evap oce, transpiration et evaporation
@@ -107,910 +30,645 @@
 ! option 12: taggage evap oce, sol nu, canop et reste evap cont. 
 ! A utiliser quand on couple avec ORCHIDEE
-! option 13: taggage température minimale + revap precip
-! option 14: taggage lat et altitude de dernière saturation (niveaux de pression) + evap surf
+! option 13: taggage temperature minimale + revap precip
+! option 14: taggage lat et altitude de derniere saturation (niveaux de pression) + evap surf
 ! otion 15: taggage irrigation
 ! option 16: taggage precip selon saisons et fonte neige: seulement pour ORCHIDEE
-! option 17: taggage température minimum de condensation directement dans la convection et la cond LS, + evap sfc, condensat et precipitation
+! option 17: taggage temperature minimum de condensation directement dans la convection et la cond LS, + evap sfc, condensat et precipitation
 ! option 18: idem 17 mais on tague qsmin au lieu de Tmin
 ! option 19: on tag vap residuelle, vap residuelle dans ddfts, sfc, cond, rev
 ! option 20: on taggue vapeur tropicale vs vapeur extratropicale
 ! option 21: taggage de 2 boites 3D: extratropiques (>35°) et UT tropicale (15-15°, > 500hPa)
-! option 22: tagage de la vapeur proccessée dans les zones très convectives
+! option 22: tagage de la vapeur proccessee dans les zones tres convectives
                 
-        ! ces variables sont initialisées dans traceurs_init
+   !--- nzone_opt (value of nzone for the selected option) must be equal to nzone as defined in onfotrac
+   REAL, PARAMETER :: ridicule_trac = ridicule * 1e4
+   INTEGER, SAVE :: option_traceurs, nzone_opt, nzoneOR
+!$OMP THREADPRIVATE(option_traceurs,nzone_opt,nzoneOR)
+   INTEGER, SAVE :: initialisation_isotrac
+!$OMP THREADPRIVATE(initialisation_isotrac)      
+                ! 1 pour idealise
+                ! 0 pour lecture dans fichier
+
+   !=== VARIABLES SPECIFIC TO THE SELECTED OPTION, BUT NEEDED FOR THE COMPUTATION OF THE NUMBER OF ZONES ; TO BE INITIALIZED IN traceurs_init
+
+   !--- option 3
+   LOGICAL, SAVE :: use_bassin_Austral, use_bassin_Atlantic, use_bassin_MidLats, use_bassin_SouthIndian, use_bassin_MerArabie
+!$OMP THREADPRIVATE(use_bassin_Austral, use_bassin_Atlantic, use_bassin_MidLats, use_bassin_SouthIndian, use_bassin_MerArabie)
+   INTEGER, SAVE ::     bassin_Austral,     bassin_Atlantic,     bassin_MidLats,     bassin_SouthIndian,     bassin_MerArabie
+!$OMP THREADPRIVATE(    bassin_Austral,     bassin_Atlantic,     bassin_MidLats,     bassin_SouthIndian,     bassin_MerArabie)
+   LOGICAL, SAVE :: use_bassin_Pacific, use_bassin_Indian,   use_bassin_Tropics, use_bassin_BengalGolf,  use_bassin_HighLats, use_bassin_Medit
+!$OMP THREADPRIVATE(use_bassin_Pacific, use_bassin_Indian,   use_bassin_Tropics, use_bassin_BengalGolf,  use_bassin_HighLats, use_bassin_Medit)
+   INTEGER, SAVE ::     bassin_Pacific,     bassin_Indian,       bassin_Tropics,     bassin_BengalGolf,      bassin_HighLats,     bassin_Medit
+!$OMP THREADPRIVATE(    bassin_Pacific,     bassin_Indian,       bassin_Tropics,     bassin_BengalGolf,      bassin_HighLats,     bassin_Medit)
+
+   !--- option 4
+   INTEGER, PARAMETER :: nzone_temp = 1
+   REAL,   SAVE ::  zone_temp1, zone_tempf, zone_tempa  
+!$OMP THREADPRIVATE(zone_temp1, zone_tempf, zone_tempa)
+   REAL,   SAVE ::  zone_temp(nzone_temp-1)
+!$OMP THREADPRIVATE(zone_temp)
+
+   !--- option 5
+   INTEGER, SAVE :: izone_aej, izone_harmattan, izone_mousson
+!$OMP THREADPRIVATE(izone_aej, izone_harmattan, izone_mousson)
+
+   !--- option 6
+   INTEGER, SAVE :: izone_ddft
+!$OMP THREADPRIVATE(izone_ddft)
+
+   !--- option 10
+   INTEGER, SAVE :: izone_contfrac
+!$OMP THREADPRIVATE(izone_contfrac)
+
+   !--- option 12	
+   INTEGER, SAVE :: izone_contcanop
+!$OMP THREADPRIVATE(izone_contcanop)
+
+   !--- option 13
+   INTEGER, PARAMETER :: nzone_pres = 3
+   REAL, SAVE ::  zone_pres(nzone_pres-1)
+!$OMP THREADPRIVATE(zone_pres)
+
+   !--- option 14
+   INTEGER, PARAMETER :: nzone_lat = 4
+   REAL,    SAVE :: zone_pres1, zone_presf, zone_presa 
+!$OMP THREADPRIVATE(zone_pres1, zone_presf, zone_presa) 
+   REAL,    SAVE :: dlattag, lattag_min, zone_lat(nzone_lat-1)
+!$OMP THREADPRIVATE(dlattag, lattag_min, zone_lat)
+
+   !--- option 15
+   INTEGER, SAVE :: izone_irrig
+!$OMP THREADPRIVATE(izone_irrig)
+
+   !--- option 17
+   REAL,    SAVE :: seuil_tag_tmin, seuil_tag_tmin_ls
+!$OMP THREADPRIVATE(seuil_tag_tmin, seuil_tag_tmin_ls)
+  INTEGER,  SAVE :: option_seuil_tag_tmin
+!$OMP THREADPRIVATE(option_seuil_tag_tmin)
+
+   !--- option 20
+   INTEGER, SAVE :: izone_trop, izone_extra
+!$OMP THREADPRIVATE(izone_trop, izone_extra)
+   REAL,    SAVE :: lim_tag20 
+!$OMP THREADPRIVATE(lim_tag20)
+
+   !--- option 21: on garde izone_trop, izone_extra  
+
+   !--- option 22
+   INTEGER, SAVE :: izone_conv_BT, izone_conv_UT
+!$OMP THREADPRIVATE(izone_conv_BT, izone_conv_UT)
+   REAL,    SAVE :: lim_precip_tag22 
+!$OMP THREADPRIVATE(lim_precip_tag22)
+
         
-integer, ALLOCATABLE, DIMENSION(:), save :: index_iso
-!$OMP THREADPRIVATE(index_iso)
-integer, ALLOCATABLE, DIMENSION(:), save ::  index_zone
-!$OMP THREADPRIVATE(index_zone)
-integer, ALLOCATABLE, DIMENSION(:,:), save ::  itZonIso_loc ! il y a déjà un itZonIso dans infotrac: vérifier que c'est le même
-!$OMP THREADPRIVATE(itZonIso_loc)
-character*3, ALLOCATABLE, DIMENSION(:), save :: strtrac
-!$OMP THREADPRIVATE(strtrac)
-! -> tout ça passe maintenant par infotrac
-
-integer, ALLOCATABLE, DIMENSION(:), save :: bassin_map
-integer, ALLOCATABLE, DIMENSION(:,:), save :: boite_map
-!$OMP THREADPRIVATE(bassin_map,boite_map)
-
-
-        ! traitement recyclage et evap
-integer, save :: izone_cont ! pour le recyclage continental
-!$OMP THREADPRIVATE(izone_cont)
-integer, save :: izone_oce ! pour l'océan
-!$OMP THREADPRIVATE(izone_oce)
-integer, save :: izone_poubelle ! pour les petits résidus numériques
+  INTEGER, ALLOCATABLE, SAVE :: index_iso(:), index_zone(:), itZonIso_loc(:,:)
+!$OMP THREADPRIVATE(            index_iso,    index_zone,    itZonIso_loc)
+  CHARACTER(LEN=3), ALLOCATABLE :: strtrac(:)
+!$OMP THREADPRIVATE(               strtrac)
+  INTEGER, ALLOCATABLE, SAVE :: bassin_map(:), boite_map(:,:)
+!$OMP THREADPRIVATE(            bassin_map,    boite_map)
+
+   !=== RECYCLING AND EVAPORATION TREATMENT
+   INTEGER, SAVE :: izone_cont, izone_oce        !--- For land and ocean recycling
+!$OMP THREADPRIVATE(izone_cont, izone_oce)
+   INTEGER, SAVE :: izone_poubelle               !--- For small numerical residues
 !$OMP THREADPRIVATE(izone_poubelle)
-integer, save :: izone_init ! pour l'initialisation par défaut
+   INTEGER, SAVE :: izone_init                   !--- For default initialization
 !$OMP THREADPRIVATE(izone_init)
-integer, save :: izone_revap ! pour l'évap des gouttes
+   INTEGER, SAVE :: izone_revap                  !--- For droplets evaporation
 !$OMP THREADPRIVATE(izone_revap)
-integer, save :: option_revap
-!$OMP THREADPRIVATE(option_revap)
-integer, save :: option_tmin
-!$OMP THREADPRIVATE(option_tmin)
-integer, save :: option_cond
-!$OMP THREADPRIVATE(option_cond)
-integer, save :: izone_cond
-!$OMP THREADPRIVATE(izone_cond)
-real evap_franche
-parameter (evap_franche=1e-6) ! en kg/m2/s
-
-! specifique à option 4:
-real, save ::  zone_temp(nzone_temp-1)
-!$OMP THREADPRIVATE(zone_temp)
-! si option 5
-integer, save :: izone_aej
-!$OMP THREADPRIVATE(izone_aej)
-integer, save :: izone_harmattan
-!$OMP THREADPRIVATE(izone_harmattan)
-integer, save :: izone_mousson
-!$OMP THREADPRIVATE(izone_mousson)
-! si option 6
-integer, save :: izone_ddft
-!$OMP THREADPRIVATE(izone_ddft)
-! si option 10
-integer, save :: izone_contfrac
-!$OMP THREADPRIVATE(izone_contfrac)
-! si option 12	
-integer, save :: izone_contcanop
-!$OMP THREADPRIVATE(izone_contcanop)
-! specifique à option 13:
-real, save ::  zone_pres(nzone_pres-1)
-!$OMP THREADPRIVATE(zone_pres)
-! si option 14
-real, save ::  zone_lat(nzone_lat-1)
-!$OMP THREADPRIVATE(zone_lat)
-! si option 15
-integer, save :: izone_irrig
-!$OMP THREADPRIVATE(izone_irrig)
-! si option 17
-real, save ::  seuil_tag_tmin
-!$OMP THREADPRIVATE(seuil_tag_tmin)
-real, save ::  seuil_tag_tmin_ls
-!$OMP THREADPRIVATE(seuil_tag_tmin_ls)
-integer, save :: option_seuil_tag_tmin
-!$OMP THREADPRIVATE(option_seuil_tag_tmin)
-! si option 20
-integer, save :: izone_trop,izone_extra
-real, save ::  lim_tag20 
-!$OMP THREADPRIVATE(izone_trop,izone_extra,lim_tag20)
-! si option 21: on garde izone_trop,izone_extra  
-! si opt 22
-integer, save :: izone_conv_BT,izone_conv_UT
-real, save ::  lim_precip_tag22 
-!$OMP THREADPRIVATE(izone_conv_BT,izone_conv_UT,lim_precip_tag22)
-
+   INTEGER, SAVE :: option_revap, option_tmin, option_cond, izone_cond
+!$OMP THREADPRIVATE(option_revap, option_tmin, option_cond, izone_cond)
+   REAL, PARAMETER :: evap_franche = 1e-6        !--- In kg/m2/s
 
 CONTAINS
 
-      subroutine iso_traceurs_init()
-
-      use IOIPSL ! getin
-      USE infotrac_phy, ONLY: itZonIso
-      USE isotopes_mod, ONLY: iso_eau,ntracisoOR,initialisation_iso
-      USE dimphy, only: klon,klev
-
-        implicit none
-
-
-        ! définition de quelles zones et quelles isotopes représentent
-        ! les traceurs
-
-        ! inputs, outputs
-        ! ! c'est les variables dans traceurs.h qui sont modifiées
-
-        ! locals
-        integer itrac,izone,ixt,k
-        integer izone_pres,izone_lat
-        character*2 strz,strz_preslat
-        character*1 strz_pres,strz_lat
-        integer ntraceurs_zone_opt
-
-        ! vérifier que on a bien l'eau comme traceurs
-        if (iso_eau.eq.0) then
-            write(*,*) 'traceurs_init 18: isotrac ne marche que si ', &
-     &            'on met l''eau comme isotope'
-            stop
-        endif
-
-        ! initialiser
-        option_traceurs=0
-        initialisation_isotrac=0
-
-        ! allouer
-        allocate (index_iso(ntiso))
-        allocate (index_zone(ntiso))
-        allocate (itZonIso_loc(ntraceurs_zone,niso))
-        allocate (strtrac(ntraceurs_zone))
-        allocate (bassin_map(klon))
-        allocate (boite_map(klon,klev))
-
-        if (initialisation_iso.eq.0) then
-          call getin('initialisation_isotrac',initialisation_isotrac)
-          write(*,*) 'initialisation_isotrac=',initialisation_isotrac
-        endif !if (initialisation_iso.eq.0) then
-
-        ! lire l'option de traçage
-        call getin('option_traceurs',option_traceurs)
-        write(*,*) 'option_traceurs=',option_traceurs
-
-        ! cas général: pas de traceurs dans ORCHIDEE
-        ntracisoOR=niso
-
-        ! partie à éditer ! pour définir les différentes zones
-        if (option_traceurs.eq.1) then
-          ! on trace continents/ocean  
-
-          ntraceurs_zone_opt=2
-          izone_cont=1
-          izone_oce=2          
-          izone_poubelle=2 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=2 ! zone d'initialisation par défaut          
-          option_revap=0
-          option_tmin=0
-          izone_revap=0
-          option_cond=0
-
-          strtrac(izone_cont)='con'
-          strtrac(izone_oce)='oce'
-
-        elseif (option_traceurs.eq.2) then
-          ! on trace continent/ ocean/reevap des gouttes
-
-          ntraceurs_zone_opt=3
-          izone_cont=1
-          izone_oce=2
-          izone_poubelle=2 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=2 ! zone d'initialisation par défaut
-          option_revap=1
-          option_tmin=0
-          izone_revap=3
-          option_cond=0
-
-          strtrac(izone_cont)='con'
-          strtrac(izone_oce)='oce'
-          strtrac(izone_revap)='rev'
-          
-
-        else if (option_traceurs.eq.3) then
-            ! on trace des bassins océaniques + un résidu. On ne trace
-            ! pas l'évap des gouttes à part
-            ! le résidu est la dernère dimension
-            
-          ! lire les use_bassin
-          call getin('use_bassin_atlantic',use_bassin_atlantic)     
-          call getin('use_bassin_medit',use_bassin_medit)      
-          call getin('use_bassin_indian',use_bassin_indian)     
-          call getin('use_bassin_austral',use_bassin_austral)     
-          call getin('use_bassin_pacific',use_bassin_pacific)     
-          call getin('use_bassin_merarabie',use_bassin_merarabie)     
-          call getin('use_bassin_golfebengale',use_bassin_golfebengale)     
-          call getin('use_bassin_indiansud',use_bassin_indiansud)     
-          call getin('use_bassin_tropics',use_bassin_tropics)     
-          call getin('use_bassin_midlats',use_bassin_midlats)     
-          call getin('use_bassin_hauteslats',use_bassin_hauteslats)
-
-          write(*,*) 'use_bassin_atlantic=' ,use_bassin_atlantic  
-          write(*,*) 'use_bassin_medit=' ,use_bassin_medit
-          write(*,*) 'use_bassin_indian=' ,use_bassin_indian
-          write(*,*) 'use_bassin_austral=' ,use_bassin_austral
-          write(*,*) 'use_bassin_merarabie=' ,use_bassin_merarabie
-          write(*,*) 'use_bassin_golfebengale=' ,use_bassin_golfebengale
-          write(*,*) 'use_bassin_indiansud=' ,use_bassin_indiansud
-          write(*,*) 'use_bassin_tropics=' ,use_bassin_tropics
-          write(*,*) 'use_bassin_midlats=' ,use_bassin_midlats
-          write(*,*) 'use_bassin_hauteslats=' ,use_bassin_hauteslats
-
-        
-          ntraceurs_zone_opt=2 &
-     &                   +use_bassin_atlantic &
-     &                   +use_bassin_medit &
-     &                   +use_bassin_indian &
-     &                   +use_bassin_austral &
-     &                   +use_bassin_pacific &
-     &                   +use_bassin_merarabie &
-     &                   +use_bassin_golfebengale &
-     &                   +use_bassin_indiansud &
-     &                   +use_bassin_tropics &
-     &                   +use_bassin_midlats &
-     &                   +use_bassin_hauteslats
-
-          izone_cont=ntraceurs_zone
-          izone_oce=0 ! pas de sens car séparée en bassins          
-          izone_poubelle=ntraceurs_zone-1 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=ntraceurs_zone-1 ! zone d'initialisation par défaut
-          option_revap=0 ! on ne trace pas les gouttes 
-          option_tmin=0
-          izone_revap=0 ! pas de sens car on taggue pas les gouttes séparemment  
-          option_cond=0
-
-          ! si on a use_bassin_indian, on n'a pas le découpage détaillé
-          ! de l'indian:
+   SUBROUTINE iso_traceurs_init()
+
+   USE infotrac_phy, ONLY: itZonIso, isoName, isoZone
+   USE isotopes_mod, ONLY: iso_eau, ntracisoOR, initialisation_iso
+   USE dimphy,       ONLY: klon, klev
+   USE  strings_mod, ONLY: int2str, strStack, strTail, strHead, strIdx, fmsg
+
+   IMPLICIT NONE
+   ! Define which zones and isotopes correspond to isotopic tagging tracers
+   ! Modify traceurs.h variables
+   INTEGER :: izone, ixt, k
+   INTEGER :: izone_pres, izone_lat
+   INTEGER :: nzone_opt
+
+   IF(fmsg("traceurs_init 18: isotrac ne marche que si on met l'eau comme isotope", 'iso_traceurs_init', iso_eau==0)) STOP
+
+   !--- Initialize
+   option_traceurs = 0
+   initialisation_isotrac = 0
+
+   !--- Allocate
+   ALLOCATE(index_iso (ntiso))
+   ALLOCATE(index_zone(ntiso))
+   ALLOCATE(itZonIso_loc(nzone,niso))
+   ALLOCATE(strtrac(nzone))
+   ALLOCATE(bassin_map(klon))
+   ALLOCATE( boite_map(klon,klev))
+
+   IF(initialisation_iso == 0) CALL get_in('initialisation_isotrac', initialisation_isotrac)
+
+   !--- Read tracing option
+   CALL get_in('option_traceurs', option_traceurs)
+
+   !--- Genral case: no traceurs in ORCHIDEE
+   ntracisoOR=niso
+
+   ! partie a editer ! pour definir les differentes zones
+   SELECT CASE(option_traceurs)
+      !========================================================================================================================
+      CASE(1)      !=== TRACING LAND/OCEAN
+      !========================================================================================================================
+         nzone_opt=2
+         izone_cont=1
+         izone_oce=2
+         izone_poubelle=2    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=2        ! zone d'initialisation par defaut          
+         option_revap=0
+         option_tmin=0
+         izone_revap=0
+         option_cond=0
+         strtrac(izone_cont) = 'con'
+         strtrac(izone_oce)  = 'oce'
+      !========================================================================================================================
+      CASE(2)      !=== TRACING LAND/OCEAN/DROPLETS REEVAPORATION
+      !========================================================================================================================
+         nzone_opt=3
+         izone_cont=1
+         izone_oce=2
+         izone_poubelle=2    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=2        ! zone d'initialisation par defaut          
+         option_revap=1
+         option_tmin=0
+         izone_revap=3
+         option_cond=0
+         strtrac(izone_cont) = 'con'
+         strtrac(izone_oce)  = 'oce'
+         strtrac(izone_revap)= 'rev'
+      !========================================================================================================================
+      CASE(3)      !=== TRACING OCEANS BASINS + RESIDUE (LAST DIMENSION). NO DROPLETS EVAPORATION TRACING.
+      !========================================================================================================================
+         ! lire les use_bassin
+         CALL get_in('use_bassin_Atlantic',   use_bassin_Atlantic)
+         CALL get_in('use_bassin_Medit',      use_bassin_Medit)
+         CALL get_in('use_bassin_Indian',     use_bassin_Indian)
+         CALL get_in('use_bassin_Austral',    use_bassin_Austral)
+         CALL get_in('use_bassin_Pacific',    use_bassin_Pacific)
+         CALL get_in('use_bassin_MerArabie',  use_bassin_MerArabie)
+         CALL get_in('use_bassin_BengalGolf', use_bassin_BengalGolf)
+         CALL get_in('use_bassin_SouthIndian',use_bassin_SouthIndian)
+         CALL get_in('use_bassin_Tropics',    use_bassin_Tropics)
+         CALL get_in('use_bassin_Midlats',    use_bassin_Midlats)
+         CALL get_in('use_bassin_HighLats',   use_bassin_HighLats)
+         nzone_opt  =  2  +  COUNT([use_bassin_Atlantic, use_bassin_Medit,     use_bassin_Indian,     &
+            use_bassin_Austral,     use_bassin_Pacific,  use_bassin_MerArabie, use_bassin_BengalGolf, &
+            use_bassin_SouthIndian, use_bassin_Tropics,  use_bassin_Midlats,   use_bassin_HighLats])
+         izone_cont=nzone
+         izone_oce=0             ! pas de sens car separee en bassins          
+         izone_poubelle=nzone-1  ! zone ou on met les flux non physiques, de reajustement
+         izone_init=nzone-1      ! zone d'initialisation par defaut
+         option_revap=0          ! on ne trace pas les gouttes 
+         option_tmin=0
+         izone_revap=0           ! pas de sens car on taggue pas les gouttes separemment  
+         option_cond=0
 #ifdef ISOVERIF
-          if (use_bassin_indian.eq.1) then
-!              call iso_verif_egalite(float(use_bassin_merarabie), &
-!     &            0.0,'iso_traceurs_init 73: revoir def des bassins')
-               if ((use_bassin_merarabie.ne.0).or. &
-      &            (use_bassin_indiansud.ne.0).or. &
-      &            (use_bassin_golfebengale.ne.0)) then
-                write(*,*) 'traceurs_init 73'
-                stop
-               endif 
-!              call iso_verif_egalite(float(use_bassin_golfebengale), &
-!     &            0.0,'iso_traceurs_init 73: revoir def des bassins')
-!              call iso_verif_egalite(float(use_bassin_indiansud), &
-!     &            0.0,'iso_traceurs_init 73: revoir def des bassins')
-          endif
+         IF(use_bassin_Indian) THEN   !=== NON COMPATIBLE WITH A DETAILED INDIAN CUTTING
+            IF(use_bassin_MerArabie .OR. use_bassin_SouthIndian .OR. use_bassin_BengalGolf) THEN
+               WRITE(*,*) 'traceurs_init 73'; STOP
+            END IF
+!           CALL iso_verif_egalite(float(use_bassin_MerArabie),   0.0, 'iso_traceurs_init 73: revoir def des bassins')
+!           CALL iso_verif_egalite(float(use_bassin_BengalGolf),  0.0, 'iso_traceurs_init 73: revoir def des bassins')
+!           CALL iso_verif_egalite(float(use_bassin_SouthIndian), 0.0, 'iso_traceurs_init 73: revoir def des bassins')
+         END IF
 #endif    
-          
-          bassin_atlantic= max(use_bassin_atlantic,1)
-          bassin_medit=max(use_bassin_atlantic &
-     &           +use_bassin_medit,1)
-          bassin_indian=max(use_bassin_atlantic &
-     &           +use_bassin_medit &
-     &           +use_bassin_indian,1)
-          bassin_austral=max(use_bassin_atlantic &
-     &           +use_bassin_medit &
-     &           +use_bassin_indian &
-     &           +use_bassin_austral,1)
-          bassin_pacific=max(use_bassin_atlantic &
-     &           +use_bassin_medit &
-     &           +use_bassin_indian &
-     &           +use_bassin_austral &
-     &           +use_bassin_pacific,1)
-          bassin_merarabie=max(use_bassin_atlantic &
-     &           +use_bassin_medit &
-     &           +use_bassin_indian &
-     &           +use_bassin_austral &
-     &           +use_bassin_pacific &
-     &           +use_bassin_merarabie,1)
-          bassin_golfebengale=max(use_bassin_atlantic& 
-     &           +use_bassin_medit &
-     &           +use_bassin_indian & 
-     &           +use_bassin_austral &
-     &           +use_bassin_pacific &
-     &           +use_bassin_merarabie &
-     &           +use_bassin_golfebengale,1)
-          bassin_indiansud=max(use_bassin_atlantic &
-     &           +use_bassin_medit &
-     &           +use_bassin_indian &
-     &           +use_bassin_austral &
-     &           +use_bassin_pacific &
-     &           +use_bassin_merarabie &
-     &           +use_bassin_golfebengale &
-     &           +use_bassin_indiansud,1) 
-          bassin_tropics=max(use_bassin_atlantic &
-     &                       +use_bassin_medit &
-     &                       +use_bassin_indian &
-     &                       +use_bassin_austral &
-     &                       +use_bassin_pacific &
-     &                       +use_bassin_merarabie &
-     &                       +use_bassin_golfebengale &
-     &                       +use_bassin_indiansud, &
-     &                       +use_bassin_tropics,1) 
-          bassin_midlats=max(use_bassin_atlantic &
-     &                       +use_bassin_medit &
-     &                       +use_bassin_indian &
-     &                       +use_bassin_austral &
-     &                       +use_bassin_pacific &
-     &                       +use_bassin_merarabie &
-     &                       +use_bassin_golfebengale &
-     &                       +use_bassin_indiansud &
-     &                       +use_bassin_tropics &
-     &                       +use_bassin_midlats,1) 
-          bassin_hauteslats=max(use_bassin_atlantic & 
-     &                       +use_bassin_medit &
-     &                       +use_bassin_indian &
-     &                       +use_bassin_austral &
-     &                       +use_bassin_pacific &
-     &                       +use_bassin_merarabie &
-     &                       +use_bassin_golfebengale &
-     &                       +use_bassin_indiansud &
-     &                       +use_bassin_tropics &
-     &                       +use_bassin_midlats &
-     &                       +use_bassin_hauteslats,1) 
-
-          write(*,*) 'bassin_atlantic=' ,bassin_atlantic  
-          write(*,*) 'bassin_medit=' ,bassin_medit
-          write(*,*) 'bassin_indian=' ,bassin_indian
-          write(*,*) 'bassin_austral=' ,bassin_austral
-          write(*,*) 'bassin_merarabie=' ,bassin_merarabie
-          write(*,*) 'bassin_golfebengale=' ,bassin_golfebengale
-          write(*,*) 'bassin_indiansud=' ,bassin_indiansud
-          write(*,*) 'bassin_tropics=' ,bassin_tropics
-          write(*,*) 'bassin_midlats=' ,bassin_midlats
-          write(*,*) 'bassin_hauteslats=' ,bassin_hauteslats
-
-          if (use_bassin_atlantic.eq.1) then
-            strtrac(bassin_atlantic)='atl'
-          endif
-          if (use_bassin_medit.eq.1) then
-            strtrac(bassin_medit)='med'
-          endif
-          if (use_bassin_indian.eq.1) then
-            strtrac(bassin_indian)='ind'
-          endif
-          if (use_bassin_austral.eq.1) then
-            strtrac(bassin_austral)='aus'
-          endif
-          if (use_bassin_pacific.eq.1) then
-            strtrac(bassin_pacific)='pac'
-          endif
-          if (use_bassin_merarabie.eq.1) then
-            strtrac(bassin_merarabie)='ara'
-          endif
-          if (use_bassin_golfebengale.eq.1) then
-            strtrac(bassin_golfebengale)='ben'
-          endif
-          if (use_bassin_indiansud.eq.1) then
-            strtrac(bassin_indiansud)='ins'
-          endif
-          if (use_bassin_tropics.eq.1) then
-            strtrac(bassin_tropics)='tro'
-          endif
-          if (use_bassin_midlats.eq.1) then
-            strtrac(bassin_midlats)='mid'
-          endif
-          if (use_bassin_hauteslats.eq.1) then
-            strtrac(bassin_hauteslats)='hau'
-          endif
-          strtrac(ntraceurs_zone-1)='res'
-          strtrac(ntraceurs_zone)='con'
-
-        else if (option_traceurs.eq.4) then
-          ! on trace les température minimales vécues
-          ! comme dans article sur LdG sauf pas de revap
-            
-          zone_temp1=293.0 ! en K
-!          zone_tempf=223.0 ! en K
-          zone_tempf=243.0 ! en K
- ! courbure de la relation entre l'indice et la température: 0 pour linéaire, <0 pour plus de détal en bas
-
+         bassin_Atlantic   = 1
+         bassin_Medit      = bassin_Atlantic    + COUNT([use_bassin_Medit]);       WRITE(*,*) 'bassin_Atlantic    =' ,bassin_Atlantic
+         bassin_Indian     = bassin_Medit       + COUNT([use_bassin_Indian]);      WRITE(*,*) 'bassin_Medit       =' ,bassin_Medit
+         bassin_Austral    = bassin_Indian      + COUNT([use_bassin_Austral]);     WRITE(*,*) 'bassin_Indian      =' ,bassin_Indian
+         bassin_Pacific    = bassin_Austral     + COUNT([use_bassin_Pacific]);     WRITE(*,*) 'bassin_Austral     =' ,bassin_Austral
+         bassin_MerArabie  = bassin_Pacific     + COUNT([use_bassin_MerArabie]);   WRITE(*,*) 'bassin_MerArabie   =' ,bassin_MerArabie
+         bassin_BengalGolf = bassin_MerArabie   + COUNT([use_bassin_BengalGolf]);  WRITE(*,*) 'bassin_BengalGolf  =' ,bassin_BengalGolf
+         bassin_SouthIndian= bassin_BengalGolf  + COUNT([use_bassin_SouthIndian]); WRITE(*,*) 'bassin_SouthIndian =' ,bassin_SouthIndian
+         bassin_Tropics    = bassin_SouthIndian + COUNT([use_bassin_Tropics]);     WRITE(*,*) 'bassin_Tropics     =' ,bassin_Tropics
+         bassin_MidLats    = bassin_Tropics     + COUNT([use_bassin_MidLats]);     WRITE(*,*) 'bassin_MidLats     =' ,bassin_MidLats
+         bassin_HighLats   = bassin_MidLats     + COUNT([use_bassin_HighLats]);    WRITE(*,*) 'bassin_HighLats    =' ,bassin_HighLats
+         IF(use_bassin_atlantic   ) strtrac(bassin_atlantic)   = 'atl'
+         IF(use_bassin_medit      ) strtrac(bassin_medit)      = 'med'
+         IF(use_bassin_indian     ) strtrac(bassin_indian)     = 'ind'
+         IF(use_bassin_austral    ) strtrac(bassin_austral)    = 'aus'
+         IF(use_bassin_pacific    ) strtrac(bassin_pacific)    = 'pac'
+         IF(use_bassin_merarabie  ) strtrac(bassin_merarabie)  = 'ara'
+         IF(use_bassin_BengalGolf ) strtrac(bassin_BengalGolf) = 'ben'
+         IF(use_bassin_SouthIndian) strtrac(bassin_SouthIndian)= 'ins'
+         IF(use_bassin_tropics    ) strtrac(bassin_tropics)    = 'tro'
+         IF(use_bassin_midlats    ) strtrac(bassin_midlats)    = 'mid'
+         IF(use_bassin_HighLats   ) strtrac(bassin_HighLats)   = 'hau'
+         strtrac(nzone-1)='res'
+         strtrac(nzone)='con'
+      !========================================================================================================================
+      CASE(4)      !=== TRACING MINIMAL EXPERIENCED TEMPERATURE AS IN THE ARTICLE ON LfG, EXCEPT NO REVAPORATION
+      !========================================================================================================================
+         zone_temp1 = 293.0  ! en K
+!        zone_tempf = 223.0  ! en K
+         zone_tempf = 243.0  ! en K
+        ! courbure de la relation entre l'indice et la temperature: 0 pour lineaire, <0 pour plus de detal en bas
         ! zone 1: >= zone_temp1
-        ! zone 2 à 4: intermédiaire, 
+        ! zone 2 a 4: intermediaire, 
         ! zone 5: <zone_tempf
-        
-          ntraceurs_zone_opt=nzone_temp+1
-
-          zone_tempa=-4.0 ! en K
-          izone_cont=ntraceurs_zone
-          izone_oce=ntraceurs_zone  
-          izone_poubelle=ntraceurs_zone
-          izone_init=ntraceurs_zone ! zone d'initialisation par défaut
-          option_revap=0 
-          option_tmin=0  
-          izone_revap=0
-          option_cond=0
-          do izone=1,nzone_temp
-            write(strz,'(i2.2)') izone
-            strtrac(izone)='t'//strz
-            write(*,*) 'izone,strz,strtrac=',izone,strz,strtrac(izone)
-          enddo
-          strtrac(izone_poubelle)='pou'
-
-          ! initialisation des zones de tempéarture
-          do izone=1,nzone_temp-1
-            zone_temp(izone)=zone_temp1+float(izone-1) &
-     &                      *(zone_tempa*float(izone-nzone_temp+1) &
-     &                      +(zone_tempf-zone_temp1)/float(nzone_temp-2))
-          enddo
-          write(*,*) 'iso_trac_init 183: zone_temp=',zone_temp          
-
-        elseif (option_traceurs.eq.5) then
-          ! on trace AEJ/flux de mousson/Harmattan
-!          write(*,*) 'iso_traceurs_init 129'
-
-          ntraceurs_zone_opt=4
-          izone_cont=1
-          izone_oce=1
-          izone_poubelle=1 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=1 ! zone d'initialisation par défaut
-          option_revap=0
-          option_tmin=0
-          izone_revap=0
-          izone_aej=2
-          izone_mousson=3
-          izone_harmattan=4 
-          option_cond=0
-
-          strtrac(izone_poubelle)='res'
-          strtrac(izone_aej)='aej'
-          strtrac(izone_mousson)='mou'
-          strtrac(izone_harmattan)='sah'
-
-        elseif (option_traceurs.eq.6) then
-          ! on trace les ddfts
-
-          ntraceurs_zone_opt=2
-          izone_cont=1
-          izone_oce=1
-          izone_poubelle=1 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=1 ! zone d'initialisation par défaut
-          option_revap=0
-          option_tmin=0
-          izone_revap=0
-          izone_ddft=2
-          option_cond=0
-
-          strtrac(izone_poubelle)='res'
-          strtrac(izone_ddft)='dft'
-
-        elseif (option_traceurs.eq.9) then
-          ! on trace le condensat
-
-          ntraceurs_zone_opt=3
-          izone_cont=1
-          izone_oce=1
-          izone_poubelle=1 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=1 ! zone d'initialisation par défaut
-          option_revap=1
-          option_tmin=0
-          izone_revap=2
-          izone_cond=3
-          option_cond=1
-
-          ! 1 par défaut pour colorier à la fois condensat LS et
-          ! condensat convectif. Mais on peut mettre 2 si on ne veut que
-          ! collorier que le condensat convectif.
-          call getin('option_cond',option_cond)
-          write(*,*) 'option_cond=',option_cond
-
-          strtrac(izone_poubelle)='res'
-          strtrac(izone_cond)='con'
-          strtrac(izone_revap)='rev'
-
-        elseif (option_traceurs.eq.10) then
-          ! on trace l'évap venant de ocean/continent no frac/continent frac
-          !  utilse seulement si couplé avec ORCHIDEE
-#ifdef CPP_VEGET
-#else
-          write(*,*) 'iso_traceurs_init 219: option_traceurs=10 ', &
-     &                      'inutile si on ne couple pas avec ORCHIDEE'
-          stop
+         nzone_opt=nzone_temp+1
+         zone_tempa=-4.0     ! en K
+         izone_cont=nzone
+         izone_oce=nzone  
+         izone_poubelle=nzone
+         izone_init=nzone    ! zone d'initialisation par defaut
+         option_revap=0 
+         option_tmin=0  
+         izone_revap=0
+         option_cond=0
+         DO izone=1,nzone_temp
+            strtrac(izone) = 't'//TRIM(int2str(izone))
+            WRITE(*,*) 'izone, strtrac=', izone, strtrac(izone)
+         END DO
+         strtrac(izone_poubelle)='pou'
+         ! Initialization of temperatures zones
+         DO izone=1,nzone_temp-1
+            zone_temp(izone) = zone_temp1+float(izone-1)            &
+                            * (zone_tempa*float(izone-nzone_temp+1) &
+                            + (zone_tempf-zone_temp1)/float(nzone_temp-2))
+         END DO
+         WRITE(*,*) 'iso_trac_init 183: zone_temp=', zone_temp
+      !========================================================================================================================
+      CASE(5)      !=== TRACING AEJ/MOONSOON FLUX/Harmattan
+      !========================================================================================================================
+!        WRITE*,*) 'iso_traceurs_init 129'
+         nzone_opt=4
+         izone_cont=1
+         izone_oce=1
+         izone_poubelle=1    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=1        ! zone d'initialisation par defaut          
+         option_revap=0
+         option_tmin=0
+         izone_revap=0
+         izone_aej=2
+         izone_mousson=3
+         izone_harmattan=4 
+         option_cond=0
+         strtrac(izone_poubelle) = 'res'
+         strtrac(izone_aej)      = 'aej'
+         strtrac(izone_mousson)  = 'mou'
+         strtrac(izone_harmattan)= 'sah'
+      !========================================================================================================================
+      CASE(6)      !=== TRACING DDFTS
+      !========================================================================================================================
+         nzone_opt=2
+         izone_cont=1
+         izone_oce=1
+         izone_poubelle=1    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=1        ! zone d'initialisation par defaut          
+         option_revap=0
+         option_tmin=0
+         izone_revap=0
+         izone_ddft=2
+         option_cond=0
+         strtrac(izone_poubelle)='res'
+         strtrac(izone_ddft)='dft'
+      !========================================================================================================================
+      CASE(9)      !=== TRACING CONDENSATION
+      !========================================================================================================================
+         nzone_opt=3
+         izone_cont=1
+         izone_oce=1
+         izone_poubelle=1    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=1        ! zone d'initialisation par defaut          
+         option_revap=1
+         option_tmin=0
+         izone_revap=2
+         izone_cond=3
+         option_cond=1
+         ! 1 par defaut pour colorier a la fois condensat LS et condensat convectif.
+         ! Mais on peut mettre 2 si on ne veut que colorier que le condensat convectif.
+         CALL get_in('option_cond',option_cond)
+         strtrac(izone_poubelle)='res'
+         strtrac(izone_cond)='con'
+         strtrac(izone_revap)='rev'
+      !========================================================================================================================
+      CASE(10)     !=== TRACING EVAPORATION FROM OCEAN/LAND, NON FRAC/LAND FRAC ; ONLY WHEN COUPLED WITH ORCHIDEE
+      !========================================================================================================================
+#ifndef CPP_VEGET
+         WRITE(*,*) 'iso_traceurs_init 219: option_traceurs=10 inutile si on ne couple pas avec ORCHIDEE'; STOP
 #endif          
-
-          ntraceurs_zone_opt=3
-          izone_cont=1 ! sous-entendu non fractionnant
-          izone_oce=2
-          izone_poubelle=2 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=2 ! zone d'initialisation par défaut
-          option_revap=0
-          option_tmin=0
-          izone_revap=0
-          izone_contfrac=3
-          izone_contcanop=3
-          izone_irrig=0
-          option_cond=0
-
-          strtrac(izone_oce)='oce'
-          strtrac(izone_cont)='con'  
-          strtrac(izone_contfrac)='enu'  ! evap sol nu
-
-        elseif (option_traceurs.eq.11) then
-          ! on trace reevap des gouttes et le reste
-
-          ntraceurs_zone_opt=2
-          izone_cont=1
-          izone_oce=1
-          izone_poubelle=1 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=1 ! zone d'initialisation par défaut
-          option_revap=1
-          option_tmin=0
-          izone_revap=2
-          izone_irrig=0
-          option_cond=0
-
-          strtrac(izone_poubelle)='res'
-          strtrac(izone_revap)='rev'
-
-        elseif (option_traceurs.eq.12) then
-          ! on trace evap du sol nu, evap de la canopée, reste de l'evap cont et
-          ! evap oce
-#ifdef CPP_VEGET
-#else
-          write(*,*) 'iso_traceurs_init 257: option_traceurs=10 ', &
-     &                      'inutile si on ne couple pas avec ORCHIDEE'
-          stop
+         nzone_opt=3
+         izone_cont=1        ! sous-entendu non fractionnant
+         izone_oce=2
+         izone_poubelle=2    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=2        ! zone d'initialisation par defaut
+         option_revap=0
+         option_tmin=0
+         izone_revap=0
+         izone_contfrac=3
+         izone_contcanop=3
+         izone_irrig=0
+         option_cond=0
+         strtrac(izone_oce)='oce'
+         strtrac(izone_cont)='con'  
+         strtrac(izone_contfrac)='enu'  ! evap sol nu
+      !========================================================================================================================
+      CASE(11)     !=== TRACING DROPLETS REEVAPORATION + REST
+      !========================================================================================================================
+         nzone_opt=2
+         izone_cont=1
+         izone_oce=1
+         izone_poubelle=1    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=1        ! zone d'initialisation par defaut
+         option_revap=1
+         option_tmin=0
+         izone_revap=2
+         izone_irrig=0
+         option_cond=0
+         strtrac(izone_poubelle)='res'
+         strtrac(izone_revap)='rev'
+      !========================================================================================================================
+      CASE(12)     !=== TRACING NAKED GROUND EVAPORATION, CANOPY EVAPORATION, REST OF LAND EVAPORATION AND OCEAN EVAPORATION
+      !========================================================================================================================
+#ifndef CPP_VEGET
+         WRITE(*,*) 'iso_traceurs_init 257: option_traceurs=10 inutile si on ne couple pas avec ORCHIDEE'; STOP
 #endif           
-
-          ntraceurs_zone_opt=2
-          izone_cont=1
-          izone_oce=2
-          izone_poubelle=2 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=2 ! zone d'initialisation par défaut
-          option_revap=0
-          option_tmin=0
-          izone_revap=0
-          izone_contfrac=3
-          izone_contcanop=4
-          izone_irrig=0   
-          option_cond=0
-
-          strtrac(izone_oce)='oce'
-          strtrac(izone_cont)='con'
-          strtrac(izone_contfrac)='enu'  ! evap sol nu
-          strtrac(izone_contcanop)='eca'  ! evap canop
-
-       else if (option_traceurs.eq.13) then
-          ! on trace les température minimales vécues + la revap
-          ! comme dans article sur LdG
-            
-        zone_temp1=293.0         ! en K        
-!        parameter (zone_tempf=223.0) ! en K
-        zone_tempf=243.0 ! en K
-        zone_tempa=-4.0 ! courbure de la relation entre l'indice et la température: 0 pour linéaire, <0 pour plus de détal en bas
-
-        ! zone 1: >= zone_temp1
-        ! zone 2 à 4: intermédiaire, 
-        ! zone 5: <zone_tempf
-        
-          ntraceurs_zone_opt=nzone_temp+1
-          
-          izone_cont=1
-          izone_oce=1  
-          izone_poubelle=1
-          izone_init=1 ! zone d'initialisation par défaut
-          option_revap=1   
-          option_tmin=0
-          izone_revap=ntraceurs_zone
-          izone_irrig=0
-          option_cond=0
-          do izone=1,nzone_temp
-            write(strz,'(i2.2)') izone
-            strtrac(izone)='t'//strz
-            write(*,*) 'izone,strz,strtrac=',izone,strz,strtrac(izone)
-          enddo
-          strtrac(izone_revap)='rev'
-
-          ! initialisation des zones de tempéarture
-          do izone=1,nzone_temp-1
-            zone_temp(izone)=zone_temp1+float(izone-1) &
-     &                      *(zone_tempa*float(izone-nzone_temp+1) &
-     &                      +(zone_tempf-zone_temp1)/float(nzone_temp-2))
-          enddo
-          write(*,*) 'zone_temp=',zone_temp
-
-       else if (option_traceurs.eq.14) then
-          ! on trace les pres et lat de dernière saturation définies
-          ! comme rh>90%
-            
-        zone_pres1=600.0*100.0 ! en Pa       
-        zone_presf=300.0*100.0 ! en Pa
-        zone_presa=0.0 ! courbure de la relation entre l'indice et la température: 0 pour linéaire, <0 pour plus de détal en bas
-
-        lattag_min=10.0 ! en degrès
-        dlattag=15.0
-
-        ! zone 1: >= zone_pres1
-        ! zone 2 à 4: intermédiaire, 
-        ! zone 5: <zone_presf
-        
-         ntraceurs_zone_opt=nzone_pres*nzone_lat+1          
-          izone_cont=ntraceurs_zone
-          izone_oce=ntraceurs_zone
-          izone_poubelle=ntraceurs_zone
-          izone_init=ntraceurs_zone ! zone d'initialisation par défaut
-          option_revap=0  
-          option_tmin=0 
-          izone_revap=0
-          izone_irrig=0
-          option_cond=0
-          do izone_pres=1,nzone_pres
-           do izone_lat=1,nzone_lat
-            write(strz_pres,'(i1.1)') izone_pres
-            write(strz_lat,'(i1.1)') izone_lat
-            strz_preslat=strz_pres//strz_lat
-            izone=izone_lat+(izone_pres-1)*nzone_lat
-            strtrac(izone)='t'//strz_preslat
-            write(*,*) 'izone_pres,izone_lat,strtrac=', &
-     &                        izone_pres,izone_lat,izone,strtrac(izone)
-           enddo !do izone_lat=1,nzone_lat
-          enddo !do izone_pres=1,nzone_pres
-          strtrac(ntraceurs_zone)='sfc'
-
-          ! initialisation des zones de tempéarture
-          do izone=1,nzone_pres-1
-            zone_pres(izone)=zone_pres1+float(izone-1) &
-     &                      *(zone_presa*float(izone-nzone_pres+1) &
-     &                      +(zone_presf-zone_pres1)/float(nzone_pres-2))
-          enddo !do izone=1,nzone_pres-1
-          write(*,*) 'traceurs_init 332: zone_pres=',zone_pres
-!          stop
-!
-       elseif (option_traceurs.eq.15) then
-          ! on trace l'irrigation dans ORCHIDEE
-#ifdef CPP_VEGET
-#else
-          write(*,*) 'iso_traceurs_init 257: option_traceurs=15 ', &
-     &                      'inutile si on ne couple pas avec ORCHIDEE'
-          stop
+         nzone_opt=2
+         izone_cont=1
+         izone_oce=2
+         izone_poubelle=2    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=2        ! zone d'initialisation par defaut
+         option_revap=0
+         option_tmin=0
+         izone_revap=0
+         izone_contfrac=3
+         izone_contcanop=4
+         izone_irrig=0   
+         option_cond=0
+         strtrac(izone_oce)='oce'
+         strtrac(izone_cont)='con'
+         strtrac(izone_contfrac)='enu' ! evap sol nu
+         strtrac(izone_contcanop)='eca'! evap canop
+      !========================================================================================================================
+      CASE(13)     !=== TRACING MINIMUM EXPERIENCED TEMPERATIRES + REEVAPORATION AS IN THE ARTICLE ON LdG
+      !========================================================================================================================
+         zone_temp1=293.0    ! en K        
+!        zone_tempf=223.0    ! en K
+         zone_tempf=243.0    ! en K
+         zone_tempa=-4.0     ! courbure de la relation entre l'indice et la temperature: 0 pour lineaire, <0 pour plus de detal en bas
+         ! zone 1: >= zone_temp1
+         ! zone 2 a 4: intermediaire, 
+         ! zone 5: <zone_tempf
+         nzone_opt=nzone_temp+1
+         izone_cont=1
+         izone_oce=1  
+         izone_poubelle=1
+         izone_init=1        ! zone d'initialisation par defaut
+         option_revap=1   
+         option_tmin=0
+         izone_revap=nzone
+         izone_irrig=0
+         option_cond=0
+         DO izone=1,nzone_temp
+            strtrac(izone) = 't'//TRIM(int2str(izone))
+            WRITE(*,*) 'izone, strtrac = ', izone, strtrac(izone)
+         END DO
+         strtrac(izone_revap)='rev'
+         ! initialisation des zones de tempearture
+         DO izone=1,nzone_temp-1
+            zone_temp(izone) = zone_temp1+float(izone-1) &
+                             *(zone_tempa*float(izone-nzone_temp+1) &
+                             +(zone_tempf-zone_temp1)/float(nzone_temp-2))
+         END DO
+         WRITE(*,*) 'zone_temp=',zone_temp
+      !========================================================================================================================
+      CASE(14)     !=== TRACING PRES AND LAT OF LAST SATURATION DEFINED AS rh>90%
+      !========================================================================================================================
+         zone_pres1=600.0*100.0   ! en Pa       
+         zone_presf=300.0*100.0   ! en Pa
+         zone_presa=0.0           ! courbure de la relation entre l'indice et la temperature: 0 pour lineaire
+         lattag_min=10.0          ! en degres
+         dlattag=15.0
+         ! zone 1: >= zone_pres1
+         ! zone 2 a 4: intermediaire, 
+         ! zone 5: <zone_presf
+         nzone_opt=nzone_pres*nzone_lat+1          
+         izone_cont=nzone
+         izone_oce=nzone
+         izone_poubelle=nzone
+         izone_init=nzone         ! zone d'initialisation par defaut
+         option_revap=0  
+         option_tmin=0 
+         izone_revap=0
+         izone_irrig=0
+         option_cond=0
+         DO izone_pres=1,nzone_pres
+            DO izone_lat=1,nzone_lat
+               izone=izone_lat+(izone_pres-1)*nzone_lat
+               strtrac(izone) = 't'//TRIM(int2str(izone_pres))//TRIM(int2str(izone_lat))
+               write(*,*) 'izone_pres, izone_lat, izone, strtrac = ',izone_pres, izone_lat, izone, strtrac(izone)
+            END DO
+         END DO
+         strtrac(nzone)='sfc'
+         ! initialisation des zones de temperature
+         DO izone=1,nzone_pres-1
+            zone_pres(izone) = zone_pres1+float(izone-1) &
+                             *(zone_presa*float(izone-nzone_pres+1) &
+                             +(zone_presf-zone_pres1)/float(nzone_pres-2))
+         END DO
+         WRITE(*,*) 'traceurs_init 332: zone_pres=',zone_pres
+      !========================================================================================================================
+      CASE(15)     !=== TRACING IRRIGATION IN ORCHIDEE
+      !========================================================================================================================
+#ifndef CPP_VEGET
+         WRITE(*,*) 'iso_traceurs_init 257: option_traceurs=15 inutile si on ne couple pas avec ORCHIDEE'; STOP
 #endif
-
-          ntraceurs_zone_opt=1
-          izone_cont=1
-          izone_oce=1
-          izone_poubelle=1 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=1 ! zone d'initialisation par défaut
-          option_revap=0
-          option_tmin=0
-          izone_revap=0
-          izone_contfrac=0
-          izone_contcanop=0 
-          izone_irrig=2 
-          option_cond=0
-          
-          strtrac(izone_poubelle)='res'
-          strtrac(izone_irrig)='irrig'
-
-          ! dans ce cas particulier, il y a des traceurs dans ORCHIDEE
-          ntracisoOR=ntiso
-
-        else if ((option_traceurs.eq.17).or. &
-     &           (option_traceurs.eq.18)) then
-          ! on trace les température minimales vécues
-          ! comme dans article sur LdG sauf pas de revap
-            
-        zone_temp1=12.0e-3 ! en kg/kg        
-        zone_tempf=0.2e-3 ! en kg/kg
-        zone_tempa=1.2e-3 ! courbure de la relation entre l'indice et la température: 0 pour linéaire, <0 pour plus de détail en bas
-
-!	parameter (zone_temp1=14.0e-3) ! en kg/kg        
-!   	parameter (zone_tempf=0.2e-3) ! en kg/kg
-!	parameter (zone_tempa=0.5e-3)       
-
-!        parameter (zone_temp1=10.0e-3) ! en kg/kg
-!   	parameter (zone_tempf=0.5e-3) ! en kg/kg
-!	parameter (zone_tempa=0.5e-3)
-
-        ! zone 1: >= zone_temp1
-        ! zone 2 à 4: intermédiaire, 
-        ! zone 5: <zone_tempf
-        
-        ntraceurs_zone_opt=nzone_temp+3
-        
-          izone_cont=nzone_temp+1
-          izone_oce=nzone_temp+1 
-          izone_poubelle=nzone_temp+1
-          izone_init=nzone_temp+1 ! zone d'initialisation par défaut
-          option_revap=1  
-          option_tmin=1 
-          option_cond=1
-
-          izone_revap=nzone_temp+3
-          izone_cond=nzone_temp+2
-          do izone=1,nzone_temp
-            write(strz,'(i2.2)') izone
-            strtrac(izone)='t'//strz
-            write(*,*) 'izone,strz,strtrac=',izone,strz,strtrac(izone)
-          enddo !do izone=1,nzone_temp
-          strtrac(izone_poubelle)='sfc'
-          strtrac(izone_cond)='con'
-          strtrac(izone_revap)='rev'
-
-          ! initialisation des zones de tempéarture
-          do izone=1,nzone_temp-1
-            zone_temp(izone)=zone_temp1+float(izone-1) &
-     &                      *(zone_tempa*float(izone-nzone_temp+1) &
-     &             +(zone_tempf-zone_temp1)/float(nzone_temp-2))
-          enddo
-         write(*,*) 'zone_temp1,zone_tempf,zone_tempa=', &
-     &              zone_temp1,zone_tempf,zone_tempa
-          write(*,*) 'zone_temp=',zone_temp
-!          stop          
-
-        else if (option_traceurs.eq.19) then
-
-        zone_temp1=12.0e-3 ! en kg/kg        
-        zone_tempf=0.2e-3 ! en kg/kg
-        zone_tempa=1.2e-3 ! courbure de la relation entre l'indice et la température: 0 pour linéaire, <0 pour plus de détail en bas
-
-!	parameter (zone_temp1=14.0e-3) ! en kg/kg        
-!   	parameter (zone_tempf=0.2e-3) ! en kg/kg
-!	parameter (zone_tempa=0.5e-3)       
-
-!        parameter (zone_temp1=10.0e-3) ! en kg/kg
-!   	parameter (zone_tempf=0.5e-3) ! en kg/kg
-!	parameter (zone_tempa=0.5e-3)
-
-        ! zone 1: >= zone_temp1
-        ! zone 2 à 4: intermédiaire, 
-        ! zone 5: <zone_tempf
-        
-        ntraceurs_zone_opt=nzone_temp+4
-        
-          izone_cont=nzone_temp+1
-          izone_oce=nzone_temp+1 
-          izone_poubelle=nzone_temp+1
-          if (option_seuil_tag_tmin.eq.1) then
-            izone_init=nzone_temp+1 ! zone d'initialisation par défaut
-          else
+         nzone_opt=1
+         izone_cont=1
+         izone_oce=1
+         izone_poubelle=1    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=1        ! zone d'initialisation par defaut
+         option_revap=0
+         option_tmin=0
+         izone_revap=0
+         izone_contfrac=0
+         izone_contcanop=0 
+         izone_irrig=2 
+         option_cond=0
+         strtrac(izone_poubelle)='res'
+         strtrac(izone_irrig)='irrig'
+         ! dans ce cas particulier, il y a des traceurs dans ORCHIDEE
+         ntracisoOR=ntiso
+      !========================================================================================================================
+      CASE(17,18)  !=== TRACING MINIMAL EXPERIENCES TEMPERATURES AS IN THE ARTICLE ABOUT LdG, BUT NO EVAPORATION
+      !========================================================================================================================
+         zone_temp1=12.0e-3  ! en kg/kg        
+         zone_tempf=0.2e-3   ! en kg/kg
+         zone_tempa=1.2e-3   ! courbure de la relation entre l'indice et la temperature: 0 pour lineaire
+!	 zone_temp1=14.0e-3  ! en kg/kg        
+!   	 zone_tempf=0.2e-3   ! en kg/kg
+!	 zone_tempa=0.5e-3       
+!        zone_temp1=10.0e-3  ! en kg/kg
+!   	 zone_tempf=0.5e-3   ! en kg/kg
+!	 zone_tempa=0.5e-3
+         ! zone 1: >= zone_temp1
+         ! zone 2 a 4: intermediaire, 
+         ! zone 5: <zone_tempf
+         nzone_opt=nzone_temp+3
+         izone_cont=nzone_temp+1
+         izone_oce=nzone_temp+1 
+         izone_poubelle=nzone_temp+1
+         izone_init=nzone_temp+1 ! zone d'initialisation par defaut
+         option_revap=1  
+         option_tmin=1 
+         option_cond=1
+         izone_revap=nzone_temp+3
+         izone_cond=nzone_temp+2
+         DO izone=1,nzone_temp
+            strtrac(izone) = 't'//TRIM(int2str(izone))
+            WRITE(*,*) 'izone, strtrac = ', izone, strtrac(izone)
+         END DO !do izone=1,nzone_temp
+         strtrac(izone_poubelle)='sfc'
+         strtrac(izone_cond)='con'
+         strtrac(izone_revap)='rev'
+         ! initialisation des zones de tempearture
+         DO izone=1,nzone_temp-1
+            zone_temp(izone) = zone_temp1+float(izone-1) &
+                             *(zone_tempa*float(izone-nzone_temp+1) &
+                             +(zone_tempf-zone_temp1)/float(nzone_temp-2))
+         END DO
+         WRITE(*,*) 'zone_temp1,zone_tempf,zone_tempa=',zone_temp1,zone_tempf,zone_tempa
+         WRITE(*,*) 'zone_temp=',zone_temp
+!        STOP          
+      !========================================================================================================================
+      CASE(19)     !=== TRACING TROPICAL AND EXTRATROPICAL VAPOUR
+      !========================================================================================================================
+         zone_temp1=12.0e-3  ! en kg/kg        
+         zone_tempf=0.2e-3   ! en kg/kg
+         zone_tempa=1.2e-3   ! courbure de la relation entre l'indice et la temperature: 0 pour lineaire, <0 pour plus de detail en bas
+!        zone_temp1=14.0e-3  ! en kg/kg        
+!        zone_tempf=0.2e-3   ! en kg/kg
+!        zone_tempa=0.5e-3
+!        zone_temp1=10.0e-3  ! en kg/kg        
+!        zone_tempf=0.5e-3   ! en kg/kg
+!        zone_tempa=0.5e-3
+         ! zone 1: >= zone_temp1
+         ! zone 2 a 4: intermediaire, 
+         ! zone 5: <zone_tempf
+         nzone_opt=nzone_temp+4
+         izone_cont=nzone_temp+1
+         izone_oce=nzone_temp+1 
+         izone_poubelle=nzone_temp+1
+         IF(option_seuil_tag_tmin == 1) THEN
+            izone_init=nzone_temp+1 ! zone d'initialisation par defaut
+         ELSE
             izone_init=nzone_temp
-          endif
-          option_revap=1   
-          izone_revap=nzone_temp+3
-          izone_cond=nzone_temp+2
-          izone_ddft=nzone_temp+4
-          option_tmin=1          
-          option_cond=1
-          do izone=1,nzone_temp
-            write(strz,'(i2.2)') izone
-            strtrac(izone)='t'//strz
-            write(*,*) 'izone,strz,strtrac=',izone,strz,strtrac(izone)
-          enddo !do izone=1,nzone_temp
-          strtrac(izone_poubelle)='sfc'
-          strtrac(izone_cond)='con'
-          strtrac(izone_revap)='rev'
-          strtrac(izone_ddft)='dft'
-
-        elseif (option_traceurs.eq.20) then
-          ! on vapeur tropical/extractropicale/recyclage extractropical
-          ! pour comprendre controles humidité et isotopes subtropicaux.        
-          
-          lim_tag20=35.0
-          call getin('lim_tag20',lim_tag20)
-          write(*,*) 'lim_tag20=',lim_tag20
-
-          ntraceurs_zone_opt=3
-          izone_cont=1
-          izone_oce=1
-          izone_poubelle=2 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=2 ! zone d'initialisation par défaut
-          option_revap=0
-          option_tmin=0
-          izone_revap=0
-          izone_trop=2
-          izone_extra=3
-
-          strtrac(izone_trop)='tro' ! vapeur tropicale
-          strtrac(izone_extra)='ext' ! vapeur extractropicale evaporée 
-                ! dans les tropiques
-          strtrac(izone_cont)='rec' ! recyclage
-
-        elseif (option_traceurs.eq.21) then
-          ! on trace 2 boites 3D: UT tropicale et extratropiques 
-          ! fonctionnement similaire à option 5 pour taggage des zones
-          ! AMMA
-!          write(*,*) 'iso_traceurs_init 129'
-
-          ntraceurs_zone_opt=3
-          izone_cont=1
-          izone_oce=1
-          izone_poubelle=1 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=1 ! zone d'initialisation par défaut
-          option_revap=0
-          option_tmin=0
-          izone_revap=0
-          izone_trop=2
-          izone_extra=3
-          option_cond=0
-
-          strtrac(izone_poubelle)='res'
-          strtrac(izone_trop)='tro'
-          strtrac(izone_extra)='ext'
-
-        elseif (option_traceurs.eq.22) then
-          ! on trace la vapeur qui a été processée dans zones de
-          ! convections à 3 niveaux: BT, MT et UT
-
-          lim_precip_tag22=20.0
-          call getin('lim_precip_tag22',lim_precip_tag22)
-          write(*,*) 'lim_precip_tag22=',lim_precip_tag22
-
-          ntraceurs_zone_opt=3
-          izone_cont=1
-          izone_oce=1
-          izone_poubelle=1 ! zone où on met les flux non physiques, de
-                ! réajustement
-          izone_init=1 ! zone d'initialisation par défaut
-          option_revap=0
-          option_tmin=0
-          izone_revap=0
-          izone_conv_BT=2
-          izone_conv_UT=3
-          option_cond=0
-
-          strtrac(izone_poubelle)='res'
-          strtrac(izone_conv_BT)='cbt'
-          strtrac(izone_conv_UT)='cut'
-
-        else
-            write(*,*) 'traceurs_init 36: option pas encore prévue'
-            stop
-        endif
-
-        
-          if (ntraceurs_zone_opt.ne.ntraceurs_zone) then
-                write(*,*) 'ntraceurs_zone_opt,ntraceurs_zone=', &
-                        & ntraceurs_zone_opt,ntraceurs_zone
-                call abort_physic ('isotrac_mod','ntraceurs_zone incoherent',1)
-          endif
-
-       
-        ! seuil sur le taux de condensation
-        if (option_tmin.eq.1) then
-          seuil_tag_tmin=0.01
-          call getin('seuil_tag_tmin',seuil_tag_tmin)
-          write(*,*) 'seuil_tag_tmin=',seuil_tag_tmin
-
-          seuil_tag_tmin_ls=seuil_tag_tmin
-          call getin('seuil_tag_tmin_ls',seuil_tag_tmin_ls)
-          write(*,*) 'seuil_tag_tmin_ls=',seuil_tag_tmin_ls
-
-          option_seuil_tag_tmin=1
-          call getin('option_seuil_tag_tmin',option_seuil_tag_tmin)
-          write(*,*) 'option_seuil_tag_tmin=',option_seuil_tag_tmin
-        endif
-
-
-        do ixt=1,niso
-           index_zone(ixt)=0
-           index_iso(ixt)=ixt
-        enddo
-        itrac=niso        
-        do izone=1,ntraceurs_zone
-          do ixt=1,niso
-            itrac=itrac+1
-            index_zone(itrac)=izone
-            index_iso(itrac)=ixt
-            itZonIso_loc(izone,ixt)=itrac
-            if (itZonIso(izone,ixt).ne.itZonIso_loc(izone,ixt)) then
-                write(*,*) 'isotrac 989: izone,ixt,itrac=',izone,ixt,itrac
-                CALL abort_physic ('isotrac','isotrac 989',1)
-            endif
-          enddo
-        enddo
+         END IF
+         option_revap=1   
+         izone_revap=nzone_temp+3
+         izone_cond=nzone_temp+2
+         izone_ddft=nzone_temp+4
+         option_tmin=1          
+         option_cond=1
+         DO izone=1,nzone_temp
+            strtrac(izone) = 't'//TRIM(int2str(izone))
+            WRITE(*,*) 'izone, strtrac = ', izone, strtrac(izone)
+         END DO
+         strtrac(izone_poubelle)='sfc'
+         strtrac(izone_cond)='con'
+         strtrac(izone_revap)='rev'
+         strtrac(izone_ddft)='dft'
+      !========================================================================================================================
+      CASE(20)     !=== TRACING TROPICAL/EXTRATROPICAL/EXTRATROPICAL RECYCLING TO STUDY HUMIDITY AND SUBTROPICAL ISOTOPES CONTROL
+      !========================================================================================================================
+         CALL get_in('lim_tag20', lim_tag20, 35.0)
+         nzone_opt=3
+         izone_cont=1
+         izone_oce=1
+         izone_poubelle=2    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=2        ! zone d'initialisation par defaut
+         option_revap=0
+         option_tmin=0
+         izone_revap=0
+         izone_trop=2
+         izone_extra=3
+         strtrac(izone_trop)='tro'     ! tropical vapour
+         strtrac(izone_extra)='ext'    ! extratropical vapour evaporated in the tropics
+         strtrac(izone_cont)='rec'     ! recycling
+      !========================================================================================================================
+      CASE(21)     !=== TRACING TWO 3D BOXES: TROPICAL UT AND EXTRATROPICS ; SIMILAR TO 5 FOR AMMA ZONES TAGGING
+      !========================================================================================================================
+!        WRITE(*,*) 'iso_traceurs_init 129'
+         nzone_opt=3
+         izone_cont=1
+         izone_oce=1
+         izone_poubelle=1    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=1        ! zone d'initialisation par defaut
+         option_revap=0
+         option_tmin=0
+         izone_revap=0
+         izone_trop=2
+         izone_extra=3
+         option_cond=0
+         strtrac(izone_poubelle)='res'
+         strtrac(izone_trop)='tro'
+         strtrac(izone_extra)='ext'
+      !========================================================================================================================
+      CASE(22)     !=== TRACING WATER VAPOUR PROCESSED IN THE 3-LEVELS SCONVECTION ZONES BT, MT AND UT
+      !========================================================================================================================
+         CALL get_in('lim_precip_tag22', lim_precip_tag22, 20.0)
+         nzone_opt=3
+         izone_cont=1
+         izone_oce=1
+         izone_poubelle=1    ! zone ou on met les flux non physiques, de reajustement
+         izone_init=1        ! zone d'initialisation par defaut
+         option_revap=0
+         option_tmin=0
+         izone_revap=0
+         izone_conv_BT=2
+         izone_conv_UT=3
+         option_cond=0
+         strtrac(izone_poubelle)='res'
+         strtrac(izone_conv_BT)='cbt'
+         strtrac(izone_conv_UT)='cut'
+      CASE DEFAULT
+         WRITE(*,*) 'traceurs_init 36: option pas encore prevue' ; STOP
+   END SELECT
+
+   IF(nzone_opt /= nzone) THEN
+      WRITE(*,*) 'nzone_opt, nzone=', nzone_opt, nzone
+      CALL abort_physic ('isotrac_mod','nzone incoherent',1)
+   END IF
+
+   !--- Condensation rate threshold
+   IF(option_tmin == 1) THEN
+      seuil_tag_tmin = 0.01
+      CALL get_in('seuil_tag_tmin',        seuil_tag_tmin,        0.01)
+      CALL get_in('seuil_tag_tmin_ls',     seuil_tag_tmin_ls,     seuil_tag_tmin)
+      CALL get_in('option_seuil_tag_tmin', option_seuil_tag_tmin, 1)
+   END IF
+
+   index_zone = [(strIdx(isoZone, strTail(isoName(ixt) ,'_',.TRUE.)), ixt=1, ntiso)]
+   index_iso  = [(strIdx(isoName, strHead(isoName(ixt) ,'_',.TRUE.)), ixt=1, ntiso)]
+   itZonIso_loc = itZonIso(:,:)
 #ifdef ISOVERIF
-!        call iso_verif_egalite(float(itrac),float(ntiso), &
-!     &           'traceurs_init 50')
-        if (itrac.ne.ntiso) then
-          write(*,*) 'traceurs_init 50'
-          stop
-        endif
-     
-        write(*,*) 'traceurs_init 65: bilan de l''init:'
-        write(*,*) 'index_zone=',index_zone(1:ntiso)
-        write(*,*) 'index_iso=',index_iso(1:ntiso)
-        write(*,*) 'itZonIso=',itZonIso(1:ntraceurs_zone,1:niso)
-        do izone=1,ntraceurs_zone
-          write(*,*) 'strtrac(',izone,')=',strtrac(izone)
-        enddo !do izone=1,ntraceurs_zone
-        write(*,*) 'ntracisoOR=',ntracisoOR
+   WRITE(*,*) 'traceurs_init 65: bilan de l''init:'
+   WRITE(*,*) 'index_zone = '//TRIM(strStack(int2str(index_zone(1:ntiso))))
+   WRITE(*,*) 'index_iso  = '//TRIM(strStack(int2str(index_iso (1:ntiso))))
+   DO izone=1,nzone
+      WRITE(*,*)'itZonIso('//TRIM(int2str(izone))//',:) = '//strStack(int2str(itZonIso(izone,:)))
+   END DO
+   DO izone=1,nzone
+      WRITE(*,*)'strtrac('//TRIM(int2str(izone))//',:) = '//TRIM(strtrac(izone))
+   END DO
+   WRITE(*,*) 'ntracisoOR=',ntracisoOR
 #endif  
 
-        end subroutine iso_traceurs_init
-
+END SUBROUTINE iso_traceurs_init
 
 END MODULE isotrac_mod
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotrac_routines_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotrac_routines_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/isotrac_routines_mod.F90	(revision 4482)
@@ -1113,10 +1113,10 @@
       USE isotrac_mod, only: use_bassin_atlantic,use_bassin_medit, &
 &       use_bassin_indian,use_bassin_austral,use_bassin_pacific, &
-&       use_bassin_merarabie,use_bassin_golfebengale,use_bassin_indiansud, &
-&       use_bassin_tropics,use_bassin_midlats,use_bassin_hauteslats, &
+&       use_bassin_MerArabie,use_bassin_BengalGolf,use_bassin_SouthIndian, &
+&       use_bassin_tropics,use_bassin_midlats,use_bassin_HighLats, &
 &       bassin_atlantic,bassin_medit, &
 &       bassin_indian,bassin_austral,bassin_pacific, &
-&       bassin_merarabie,bassin_golfebengale,bassin_indiansud, &
-&       bassin_tropics,bassin_midlats,bassin_hauteslats
+&       bassin_MerArabie,bassin_BengalGolf,bassin_SouthIndian, &
+&       bassin_tropics,bassin_midlats,bassin_HighLats
       implicit none
       ! répond true si lat,lon se trouve dans le bassin numéroté bassin
@@ -1137,6 +1137,5 @@
       write(*,*) 'is_in_basin 84: entree,bassin=',bassin
 #endif
-      if ((use_bassin_atlantic.eq.1).and. &
-     &           (bassin.eq.bassin_atlantic)) then
+      if (use_bassin_atlantic .and. bassin==bassin_atlantic) then
 #ifdef ISOVERIF           
           write(*,*) 'bassin Atlantique?'
@@ -1169,6 +1168,5 @@
           endif
 
-      else if ((use_bassin_medit.eq.1).and. &
-     &           (bassin.eq.bassin_medit)) then
+      else if (use_bassin_medit .and. bassin==bassin_medit) then
 #ifdef ISOVERIF           
           write(*,*) 'bassin Medit?'
@@ -1183,6 +1181,5 @@
           endif
 
-      else if ((use_bassin_indian.eq.1).and. &
-     &           (bassin.eq.bassin_indian)) then
+      else if (use_bassin_indian .and. bassin==bassin_indian) then
 #ifdef ISOVERIF           
           write(*,*) 'bassin indian?'
@@ -1199,6 +1196,5 @@
           endif   
 
-      else if ((use_bassin_indiansud.eq.1).and. &
-     &           (bassin.eq.bassin_indiansud)) then
+      else if (use_bassin_SouthIndian .and. bassin==bassin_SouthIndian) then
 #ifdef ISOVERIF           
           write(*,*) 'bassin indian hemisphere Sud?'
@@ -1209,6 +1205,5 @@
           endif
           
-      else if ((use_bassin_merarabie.eq.1).and. &
-     &           (bassin.eq.bassin_merarabie)) then
+      else if (use_bassin_MerArabie .and. bassin==bassin_MerArabie) then
 #ifdef ISOVERIF           
           write(*,*) 'bassin Mer d''Arabie?'
@@ -1219,6 +1214,5 @@
           endif 
 
-      else if ((use_bassin_golfebengale.eq.1).and. &
-     &           (bassin.eq.bassin_golfebengale)) then
+      else if (use_bassin_BengalGolf .and. bassin==bassin_BengalGolf) then
 #ifdef ISOVERIF           
           write(*,*) 'bassin Golfe du Bengale?'
@@ -1229,6 +1223,5 @@
           endif         
 
-      else if ((use_bassin_pacific.eq.1).and. &
-     &           (bassin.eq.bassin_pacific)) then
+      else if (use_bassin_pacific .and. bassin==bassin_pacific) then
 #ifdef ISOVERIF           
           write(*,*) 'bassin Pacific?'
@@ -1267,6 +1260,5 @@
           endif
 
-      else if ((use_bassin_austral.eq.1).and. &
-     &           (bassin.eq.bassin_austral)) then  
+      else if (use_bassin_austral .and. bassin==bassin_austral) then  
 #ifdef ISOVERIF           
           write(*,*) 'bassin austral?'
@@ -1277,6 +1269,5 @@
           endif  
 
-      else if ((use_bassin_hauteslats.eq.1).and. &
-     &           (bassin.eq.bassin_hauteslats)) then  
+      else if (use_bassin_HighLats .and. bassin==bassin_HighLats) then  
 #ifdef ISOVERIF           
           write(*,*) 'bassin hautes lats?'
@@ -1287,6 +1278,5 @@
           endif
 
-      else if ((use_bassin_tropics.eq.1).and. &
-     &           (bassin.eq.bassin_tropics)) then  
+      else if (use_bassin_tropics .and. bassin==bassin_tropics) then  
 #ifdef ISOVERIF           
           write(*,*) 'bassin tropics?'
@@ -1297,6 +1287,5 @@
           endif
 
-       else if ((use_bassin_midlats.eq.1).and. &
-     &           (bassin.eq.bassin_midlats)) then  
+       else if (use_bassin_midlats .and. bassin==bassin_midlats) then  
 #ifdef ISOVERIF           
           write(*,*) 'bassin mid lats?'
@@ -1314,14 +1303,14 @@
           write(*,*) 'bassin_indian=' ,bassin_indian
           write(*,*) 'bassin_austral=' ,bassin_austral
-          write(*,*) 'bassin_merarabie=' ,bassin_merarabie
-          write(*,*) 'bassin_golfebengale=' ,bassin_golfebengale
-          write(*,*) 'bassin_indiansud=' ,bassin_indiansud
+          write(*,*) 'bassin_MerArabie=' ,bassin_MerArabie
+          write(*,*) 'bassin_BengalGolf=' ,bassin_BengalGolf
+          write(*,*) 'bassin_SouthIndian=' ,bassin_SouthIndian
           write(*,*) 'use_bassin_atlantic=' ,use_bassin_atlantic  
           write(*,*) 'use_bassin_medit=' ,use_bassin_medit
           write(*,*) 'use_bassin_indian=' ,use_bassin_indian
           write(*,*) 'use_bassin_austral=' ,use_bassin_austral
-          write(*,*) 'use_bassin_merarabie=' ,use_bassin_merarabie
-          write(*,*) 'use_bassin_golfebengale=' ,use_bassin_golfebengale
-          write(*,*) 'use_bassin_indiansud=' ,use_bassin_indiansud
+          write(*,*) 'use_bassin_MerArabie=' ,use_bassin_MerArabie
+          write(*,*) 'use_bassin_BengalGolf=' ,use_bassin_BengalGolf
+          write(*,*) 'use_bassin_SouthIndian=' ,use_bassin_SouthIndian
           stop
       endif
@@ -2333,5 +2322,6 @@
         subroutine iso_verif_traceur_jbid_vect(x,n,m)
         USE isotopes_mod, ONLY: bidouille_anti_divergence,iso_eau,ridicule
-        use isotrac_mod, only: ntraceurs_zone=>nzone
+        !use isotrac_mod, only: ntraceurs_zone=>nzone
+        USE infotrac_phy, ONLY: ntraceurs_zone=>nzone
         implicit none
         
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/lscp_ini_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/lscp_ini_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/lscp_ini_mod.F90	(revision 4482)
@@ -0,0 +1,1 @@
+link ../phylmd/lscp_ini_mod.F90
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/pbl_surface_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/pbl_surface_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/pbl_surface_mod.F90	(revision 4482)
@@ -14,5 +14,5 @@
   USE mod_grid_phy_lmdz,   ONLY : klon_glo
   USE ioipsl
-  USE surface_data,        ONLY : type_ocean, ok_veget
+  USE surface_data,        ONLY : type_ocean, ok_veget, landice_opt
   USE surf_land_mod,       ONLY : surf_land
   USE surf_landice_mod,    ONLY : surf_landice
@@ -23,4 +23,5 @@
   USE climb_wind_mod,      ONLY : climb_wind_down, climb_wind_up
   USE coef_diff_turb_mod,  ONLY : coef_diff_turb
+  USE atke_exchange_coeff_mod, ONLY :  atke_compute_km_kh
   USE ioipsl_getin_p_mod,  ONLY : getin_p
   USE cdrag_mod
@@ -406,6 +407,7 @@
 #endif
     USE ioipsl_getin_p_mod, ONLY : getin_p
-    use phys_state_var_mod, only: ds_ns, dt_ns, delta_sst, delta_sal, zsig, zmea
-    use phys_output_var_mod, only: dter, dser, tkt, tks, taur, sss
+    use phys_state_var_mod, only: ds_ns, dt_ns, delta_sst, delta_sal, dter, &
+         dser, dt_ds, zsig, zmea
+    use phys_output_var_mod, only: tkt, tks, taur, sss
 #ifdef CPP_XIOS
     USE wxios, ONLY: missing_val
@@ -1028,9 +1030,9 @@
     REAL, DIMENSION(klon)              :: yrmu0
     ! Martin
-
-    REAL, DIMENSION(klon):: ydelta_sst, ydelta_sal, yds_ns, ydt_ns, ydter, ydser, &
-         ytkt, ytks, ytaur, ysss
-    ! compression of delta_sst, delta_sal, ds_ns, dt_ns, dter, dser, tkt, tks,
-    ! taur, sss on ocean points
+    REAL, DIMENSION(klon)              :: yri0
+    REAL, DIMENSION(klon):: ydelta_sst, ydelta_sal, yds_ns, ydt_ns, ydter, &
+         ydser, ydt_ds, ytkt, ytks, ytaur, ysss
+    ! compression of delta_sst, delta_sal, ds_ns, dt_ns, dter, dser,
+    ! dt_ds, tkt, tks, taur, sss on ocean points
 
 #ifdef ISO
@@ -1277,4 +1279,5 @@
 
     ytke=0.
+    yri0(:)=0.
 !FC 
     y_treedrg=0.
@@ -1813,4 +1816,7 @@
              ydelta_sal(:knon) = delta_sal(ni(:knon))
              ydelta_sst(:knon) = delta_sst(ni(:knon))
+             ydter(:knon) = dter(ni(:knon))
+             ydser(:knon) = dser(ni(:knon))
+             ydt_ds(:knon) = dt_ds(ni(:knon))
           end if
           
@@ -1844,5 +1850,5 @@
         CALL cdrag(knon, nsrf, &
             speed, yt(:,1), yq(:,1), zgeo1, ypaprs(:,1),&
-            yts, yqsurf, yz0m, yz0h, &
+            yts, yqsurf, yz0m, yz0h, yri0, 0, &
             ycdragm, ycdragh, zri1, pref )
 
@@ -1878,5 +1884,5 @@
             CALL cdrag(knon, nsrf, &
             speed_x, yt_x(:,1), yq_x(:,1), zgeo1_x, ypaprs(:,1),&
-            yts_x, yqsurf_x, yz0m, yz0h, &
+            yts_x, yqsurf_x, yz0m, yz0h, yri0, 0, &
             ycdragm_x, ycdragh_x, zri1_x, pref_x )
 
@@ -1905,5 +1911,5 @@
         CALL cdrag(knon, nsrf, &
             speed_w, yt_w(:,1), yq_w(:,1), zgeo1_w, ypaprs(:,1),&
-            yts_w, yqsurf_w, yz0m, yz0h, &
+            yts_w, yqsurf_w, yz0m, yz0h, yri0, 0, &
             ycdragm_w, ycdragh_w, zri1_w, pref_w )
 !
@@ -1947,4 +1953,13 @@
 
        ENDIF
+
+        IF (iflag_pbl>=50) THEN
+
+        CALL atke_compute_km_kh(knon,klev,yu,yv,yt, &
+             ypplay,ypaprs,ytke,ycoefm, ycoefh)
+
+        ELSE
+
+
         CALL coef_diff_turb(dtime, nsrf, knon, ni,  &
             ypaprs, ypplay, yu, yv, yq, yt, yts, yqsurf, ycdragm, &
@@ -1962,4 +1977,7 @@
        ENDDO
        ENDIF
+
+       ENDIF ! iflag_pbl >= 50
+
         IF (prt_level >=10) print *,'coef_diff_turb -> ycoefh ',ycoefh
 !
@@ -1977,4 +1995,13 @@
 
        ENDIF
+
+        IF (iflag_pbl>=50) THEN
+
+        CALL atke_compute_km_kh(knon,klev,yu_x,yv_x,yt_x, &
+             ypplay,ypaprs,ytke_x,ycoefm_x, ycoefh_x)
+
+        ELSE
+
+
         CALL coef_diff_turb(dtime, nsrf, knon, ni,  &
             ypaprs, ypplay, yu_x, yv_x, yq_x, yt_x, yts_x, yqsurf_x, ycdragm_x, &
@@ -1992,4 +2019,7 @@
        ENDDO
        ENDIF
+
+       ENDIF ! iflag_pbl >= 50
+
         IF (prt_level >=10) print *,'coef_diff_turb -> ycoefh_x ',ycoefh_x
 !
@@ -2005,4 +2035,13 @@
       print *,' args coef_diff_turb: ytke_w ', ytke_w
        ENDIF
+
+        IF (iflag_pbl>=50) THEN
+
+        CALL atke_compute_km_kh(knon,klev,yu_w,yv_w,yt_w, &
+             ypplay,ypaprs,ytke_w,ycoefm_w, ycoefh_w)
+
+        ELSE
+
+
         CALL coef_diff_turb(dtime, nsrf, knon, ni,  &
             ypaprs, ypplay, yu_w, yv_w, yq_w, yt_w, yts_w, yqsurf_w, ycdragm_w, &
@@ -2019,4 +2058,7 @@
        ENDDO
        ENDIF
+
+       ENDIF ! iflag_pbl >= 50
+
         IF (prt_level >=10) print *,'coef_diff_turb -> ycoefh_w ',ycoefh_w
 !
@@ -2382,67 +2424,70 @@
        CASE(is_lic)
           ! Martin
-          CALL surf_landice(itap, dtime, knon, ni, &
-               rlon, rlat, debut, lafin, &
-               yrmu0, ylwdown, yalb, zgeo1, &
-               ysolsw, ysollw, yts, ypplay(:,1), &
-!!jyg               ycdragh, ycdragm, yrain_f, ysnow_f, yt(:,1), yq(:,1),&
-               ycdragh, ycdragm, yrain_f, ysnow_f, yt1, yq1,&
-               AcoefH, AcoefQ, BcoefH, BcoefQ, &
-               AcoefU, AcoefV, BcoefU, BcoefV, &
-               ypsref, yu1, yv1, ygustiness, yrugoro, pctsrf, &
-               ysnow, yqsurf, yqsol, yagesno, &
-               ytsoil, yz0m, yz0h, SFRWL, yalb_dir_new, yalb_dif_new, yevap,yfluxsens,yfluxlat, &
-               ytsurf_new, y_dflux_t, y_dflux_q, &
-               yzmea, yzsig, ycldt, &
-               ysnowhgt, yqsnow, ytoice, ysissnow, &
-               yalb3_new, yrunoff, &
-               y_flux_u1, y_flux_v1 &
-#ifdef ISO
-           &    ,yxtrain_f, yxtsnow_f,yxt1,yRland_ice &
-           &    ,yxtsnow,yxtsol,yxtevap &
+          IF (landice_opt .LT. 2) THEN
+             ! Land ice is treated by LMDZ and not by ORCHIDEE
+             
+             CALL surf_landice(itap, dtime, knon, ni, &
+                  rlon, rlat, debut, lafin, &
+                  yrmu0, ylwdown, yalb, zgeo1, &
+                  ysolsw, ysollw, yts, ypplay(:,1), &
+                  !!jyg               ycdragh, ycdragm, yrain_f, ysnow_f, yt(:,1), yq(:,1),&
+                  ycdragh, ycdragm, yrain_f, ysnow_f, yt1, yq1,&
+                  AcoefH, AcoefQ, BcoefH, BcoefQ, &
+                  AcoefU, AcoefV, BcoefU, BcoefV, &
+                  ypsref, yu1, yv1, ygustiness, yrugoro, pctsrf, &
+                  ysnow, yqsurf, yqsol, yagesno, &
+                  ytsoil, yz0m, yz0h, SFRWL, yalb_dir_new, yalb_dif_new, yevap,yfluxsens,yfluxlat, &
+                  ytsurf_new, y_dflux_t, y_dflux_q, &
+                  yzmea, yzsig, ycldt, &
+                  ysnowhgt, yqsnow, ytoice, ysissnow, &
+                  yalb3_new, yrunoff, &
+                  y_flux_u1, y_flux_v1 &
+#ifdef ISO
+                  &    ,yxtrain_f, yxtsnow_f,yxt1,yRland_ice &
+                  &    ,yxtsnow,yxtsol,yxtevap &
 #endif              
-           &    )
-
-!jyg<
-!!          alb3_lic(:)=0.
-!>jyg
-          DO j = 1, knon
-             i = ni(j)
-             alb3_lic(i) = yalb3_new(j)
-             snowhgt(i)   = ysnowhgt(j)
-             qsnow(i)     = yqsnow(j)
-             to_ice(i)    = ytoice(j)
-             sissnow(i)   = ysissnow(j)
-             runoff(i)    = yrunoff(j)
-          ENDDO
-          ! Martin
-! Special DICE MPL 05082013 puis BOMEX MPL 20150410
-       IF (ok_prescr_ust) THEN
-          DO j=1,knon
-          y_flux_u1(j)=ycdragm(j)*(1.+sqrt(yu(j,1)*yu(j,1)+yv(j,1)*yv(j,1)))*yu(j,1)*ypplay(j,1)/RD/yt(j,1)
-          y_flux_v1(j)=ycdragm(j)*(1.+sqrt(yu(j,1)*yu(j,1)+yv(j,1)*yv(j,1)))*yv(j,1)*ypplay(j,1)/RD/yt(j,1)
-          ENDDO
-      ENDIF
-
+                  &    )
+             
+             !jyg<
+             !!          alb3_lic(:)=0.
+             !>jyg
+             DO j = 1, knon
+                i = ni(j)
+                alb3_lic(i) = yalb3_new(j)
+                snowhgt(i)   = ysnowhgt(j)
+                qsnow(i)     = yqsnow(j)
+                to_ice(i)    = ytoice(j)
+                sissnow(i)   = ysissnow(j)
+                runoff(i)    = yrunoff(j)
+             ENDDO
+             ! Martin
+             ! Special DICE MPL 05082013 puis BOMEX MPL 20150410
+             IF (ok_prescr_ust) THEN
+                DO j=1,knon
+                   y_flux_u1(j)=ycdragm(j)*(1.+sqrt(yu(j,1)*yu(j,1)+yv(j,1)*yv(j,1)))*yu(j,1)*ypplay(j,1)/RD/yt(j,1)
+                   y_flux_v1(j)=ycdragm(j)*(1.+sqrt(yu(j,1)*yu(j,1)+yv(j,1)*yv(j,1)))*yv(j,1)*ypplay(j,1)/RD/yt(j,1)
+                ENDDO
+             ENDIF
+             
 #ifdef ISOVERIF
-        do j=1,knon
-          do ixt=1,ntraciso
-            call iso_verif_noNaN(yxtevap(ixt,j), &
-         &      'pbl_surface 1095a: apres surf_landice')
-            call iso_verif_noNaN(yxtsol(ixt,j), &
-         &      'pbl_surface 1095b: apres surf_landice')
-          enddo
-        enddo
+             do j=1,knon
+                do ixt=1,ntraciso
+                   call iso_verif_noNaN(yxtevap(ixt,j), &
+                        &      'pbl_surface 1095a: apres surf_landice')
+                   call iso_verif_noNaN(yxtsol(ixt,j), &
+                        &      'pbl_surface 1095b: apres surf_landice')
+                enddo
+             enddo
 #endif
 #ifdef ISOVERIF
-        !write(*,*) 'pbl_surface_mod 1060: sortie surf_landice'
-        do j=1,knon
-          if (iso_eau.gt.0) then     
-                 call iso_verif_egalite(yxtsnow(iso_eau,j), &
-     &                  ysnow(j),'pbl_surf_mod 1064')
-           endif !if (iso_eau.gt.0) then
-        enddo !do i=1,klon
-#endif
-          
+             !write(*,*) 'pbl_surface_mod 1060: sortie surf_landice'
+             do j=1,knon
+                if (iso_eau.gt.0) then     
+                   call iso_verif_egalite(yxtsnow(iso_eau,j), &
+                        &                  ysnow(j),'pbl_surf_mod 1064')
+                endif !if (iso_eau.gt.0) then
+             enddo !do i=1,klon
+#endif
+          END IF
        CASE(is_oce)
            CALL surf_ocean(rlon, rlat, ysolsw, ysollw, yalb_vis, &
@@ -2459,5 +2504,5 @@
                y_flux_u1, y_flux_v1, ydelta_sst(:knon), ydelta_sal(:knon), &
                yds_ns(:knon), ydt_ns(:knon), ydter(:knon), ydser(:knon), &
-               ytkt(:knon), ytks(:knon), ytaur(:knon), ysss &
+               ydt_ds(:knon), ytkt(:knon), ytks(:knon), ytaur(:knon), ysss &
 #ifdef ISO
          &      ,yxtrain_f, yxtsnow_f,yxt1,Roce, &
@@ -3391,4 +3436,9 @@
           taur(ni(:knon)) = ytaur(:knon)
           sss(ni(:knon)) = ysss(:knon)
+
+          if (activate_ocean_skin == 2 .and. type_ocean == "couple") then
+             dt_ds = missing_val
+             dt_ds(ni(:knon)) = ydt_ds(:knon)
+          end if
        end if
 
@@ -4128,5 +4178,6 @@
 
     USE indice_sol_mod
-    use phys_state_var_mod, only: delta_sal, ds_ns, dt_ns, delta_sst
+    use phys_state_var_mod, only: delta_sal, ds_ns, dt_ns, delta_sst, dter, &
+         dser, dt_ds
     use config_ocean_skin_m, only: activate_ocean_skin
 
@@ -4234,4 +4285,7 @@
                          delta_sal(i) = 0.
                          delta_sst(i) = 0.
+                         dter(i) = 0.
+                         dser(i) = 0.
+                         dt_ds(i) = 0.
                       end if
                       
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phyetat0.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phyetat0.F90	(revision 4444)
+++ 	(revision )
@@ -1,706 +1,0 @@
-! $Id: phyetat0.F90 3890 2021-05-05 15:15:06Z jyg $
-
-SUBROUTINE phyetat0 (fichnom, clesphy0, tabcntr0)
-
-  USE dimphy, only: klon, zmasq, klev
-  USE iophy, ONLY : init_iophy_new
-  USE ocean_cpl_mod,    ONLY : ocean_cpl_init
-  USE fonte_neige_mod,  ONLY : fonte_neige_init
-  USE pbl_surface_mod,  ONLY : pbl_surface_init
-#ifdef ISO
-  USE fonte_neige_mod,  ONLY : fonte_neige_init_iso
-  USE pbl_surface_mod,  ONLY : pbl_surface_init_iso
-#endif
-  USE surface_data,     ONLY : type_ocean, version_ocean
-  USE phys_state_var_mod, ONLY : ancien_ok, clwcon, detr_therm, phys_tstep, &
-       qsol, fevap, z0m, z0h, agesno, &
-       du_gwd_rando, du_gwd_front, entr_therm, f0, fm_therm, &
-       falb_dir, falb_dif, prw_ancien, prlw_ancien, prsw_ancien, &
-       ftsol, pbl_tke, pctsrf, q_ancien, ql_ancien, qs_ancien, radpas, radsol, rain_fall, ratqs, &
-       rnebcon, rugoro, sig1, snow_fall, solaire_etat0, sollw, sollwdown, &
-       solsw, solswfdiff, t_ancien, u_ancien, v_ancien, w01, wake_cstar, wake_deltaq, &
-       wake_deltat, wake_delta_pbl_TKE, delta_tsurf, beta_aridity, wake_fip, wake_pe, &
-       wake_s, wake_dens, awake_dens, cv_gen, zgam, zmax0, zmea, zpic, zsig, &
-#ifdef ISO
-       fxtevap, xtsol, xt_ancien, xtl_ancien, xts_ancien, wake_deltaxt, &
-       xtrain_fall,xtsnow_fall, &
-#endif
-       zstd, zthe, zval, ale_bl, ale_bl_trig, alp_bl, u10m, v10m, treedrg, &
-       ale_wake, ale_bl_stat, ds_ns, dt_ns, delta_sst, delta_sal, ratqs_inter
-!FC
-  USE geometry_mod,     ONLY: longitude_deg, latitude_deg
-  USE iostart,          ONLY: close_startphy, get_field, get_var, open_startphy
-  USE infotrac_phy,     ONLY: nqtot, nbtr, types_trac, tracers
-  USE traclmdz_mod,     ONLY: traclmdz_from_restart
-  USE carbon_cycle_mod, ONLY: carbon_cycle_tr, carbon_cycle_cpl, co2_send
-  USE indice_sol_mod,   ONLY: nbsrf, is_ter, epsfra, is_lic, is_oce, is_sic
-  USE ocean_slab_mod,   ONLY: nslay, tslab, seaice, tice, ocean_slab_init
-  USE time_phylmdz_mod, ONLY: init_iteration, pdtphys, itau_phy
-#ifdef CPP_XIOS
-  USE wxios, ONLY: missing_val
-#else
-  use netcdf, only: missing_val => nf90_fill_real
-#endif
-  use config_ocean_skin_m, only: activate_ocean_skin
-#ifdef ISO
-  USE infotrac_phy, ONLY: niso
-  USE isotopes_routines_mod, ONLY: phyisoetat0
-  USE isotopes_mod, ONLY: iso_eau
-#ifdef ISOVERIF
-  USE isotopes_verif_mod, ONLY: iso_verif_egalite_vect2D,iso_verif_egalite
-#endif
-#endif
-
-  IMPLICIT none
-  !======================================================================
-  ! Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
-  ! Objet: Lecture de l'etat initial pour la physique
-  !======================================================================
-  include "dimsoil.h"
-  include "clesphys.h"
-  include "alpale.h"
-  include "compbl.h"
-  include "YOMCST.h"
-  !======================================================================
-  CHARACTER*(*) fichnom
-
-  ! les variables globales lues dans le fichier restart
-
-  REAL tsoil(klon, nsoilmx, nbsrf)
-  REAL qsurf(klon, nbsrf)
-  REAL snow(klon, nbsrf)
-  real fder(klon)
-  REAL run_off_lic_0(klon)
-  REAL fractint(klon)
-  REAL trs(klon, nbtr)
-  REAL zts(klon)
-  ! pour drag arbres FC
-  REAL drg_ter(klon,klev)
-
-  CHARACTER*6 ocean_in
-  LOGICAL ok_veget_in
-
-  INTEGER        longcles
-  PARAMETER    ( longcles = 20 )
-  REAL clesphy0( longcles )
-
-  REAL xmin, xmax
-
-  INTEGER nid, nvarid
-  INTEGER ierr, i, nsrf, isoil , k
-  INTEGER length
-  PARAMETER (length=100)
-  INTEGER it, iq, isw
-  REAL tab_cntrl(length), tabcntr0(length)
-  CHARACTER*7 str7
-  CHARACTER*2 str2
-  LOGICAL :: found,phyetat0_get,phyetat0_srf
-  REAL :: lon_startphy(klon), lat_startphy(klon)
-
-#ifdef ISO
-  REAL xtsnow(niso,klon, nbsrf)
-  REAL xtrun_off_lic_0(niso,klon)
-  REAL Rland_ice(niso,klon)
-#endif
-  ! FH1D
-  !     real iolat(jjm+1)
-  !real iolat(jjm+1-1/(iim*jjm))
-
-  ! Ouvrir le fichier contenant l'etat initial:
-
-  CALL open_startphy(fichnom)
-
-  ! Lecture des parametres de controle:
-
-  CALL get_var("controle", tab_cntrl)
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-  ! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
-  ! Les constantes de la physiques sont lues dans la physique seulement.
-  ! Les egalites du type
-  !             tab_cntrl( 5 )=clesphy0(1)
-  ! sont remplacees par
-  !             clesphy0(1)=tab_cntrl( 5 )
-  ! On inverse aussi la logique.
-  ! On remplit les tab_cntrl avec les parametres lus dans les .def
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  DO i = 1, length
-     tabcntr0( i ) = tab_cntrl( i )
-  ENDDO
-
-  tab_cntrl(1)=pdtphys
-  tab_cntrl(2)=radpas
-
-  ! co2_ppm : value from the previous time step
-  IF (carbon_cycle_tr .OR. carbon_cycle_cpl) THEN
-     co2_ppm = tab_cntrl(3)
-     RCO2    = co2_ppm * 1.0e-06 * RMCO2 / RMD
-     ! ELSE : keep value from .def
-  ENDIF
-
-! co2_ppm0 : initial value of atmospheric CO2 (from create_etat0_limit.e .def)
-! co2_ppm0   = tab_cntrl(16)
-! initial value for interactive CO2 run when there is no tracer field for CO2 in restart
-  co2_ppm0=284.32
-
-  solaire_etat0      = tab_cntrl(4)
-  tab_cntrl(5)=iflag_con
-  tab_cntrl(6)=nbapp_rad
-
-  IF (iflag_cycle_diurne.GE.1) tab_cntrl( 7) = iflag_cycle_diurne
-  IF (soil_model) tab_cntrl( 8) =1.
-  IF (new_oliq) tab_cntrl( 9) =1.
-  IF (ok_orodr) tab_cntrl(10) =1.
-  IF (ok_orolf) tab_cntrl(11) =1.
-  IF (ok_limitvrai) tab_cntrl(12) =1.
-
-  itau_phy = tab_cntrl(15)
-
-  clesphy0(1)=tab_cntrl( 5 )
-  clesphy0(2)=tab_cntrl( 6 )
-  clesphy0(3)=tab_cntrl( 7 )
-  clesphy0(4)=tab_cntrl( 8 )
-  clesphy0(5)=tab_cntrl( 9 )
-  clesphy0(6)=tab_cntrl( 10 )
-  clesphy0(7)=tab_cntrl( 11 )
-  clesphy0(8)=tab_cntrl( 12 )
-
-  ! set time iteration
-   CALL init_iteration(itau_phy)
-
-  ! read latitudes and make a sanity check (because already known from dyn)
-  CALL get_field("latitude",lat_startphy)
-  DO i=1,klon
-    IF (ABS(lat_startphy(i)-latitude_deg(i))>=1) THEN
-      WRITE(*,*) "phyetat0: Error! Latitude discrepancy wrt startphy file:",&
-                 " i=",i," lat_startphy(i)=",lat_startphy(i),&
-                 " latitude_deg(i)=",latitude_deg(i)
-      ! This is presumably serious enough to abort run
-      CALL abort_physic("phyetat0","discrepancy in latitudes!",1)
-    ENDIF
-    IF (ABS(lat_startphy(i)-latitude_deg(i))>=0.0001) THEN
-      WRITE(*,*) "phyetat0: Warning! Latitude discrepancy wrt startphy file:",&
-                 " i=",i," lat_startphy(i)=",lat_startphy(i),&
-                 " latitude_deg(i)=",latitude_deg(i)
-    ENDIF
-  ENDDO
-
-  ! read longitudes and make a sanity check (because already known from dyn)
-  CALL get_field("longitude",lon_startphy)
-  DO i=1,klon
-    IF (ABS(lon_startphy(i)-longitude_deg(i))>=1) THEN
-      IF (ABS(360-ABS(lon_startphy(i)-longitude_deg(i)))>=1) THEN
-        WRITE(*,*) "phyetat0: Error! Longitude discrepancy wrt startphy file:",&
-                   " i=",i," lon_startphy(i)=",lon_startphy(i),&
-                   " longitude_deg(i)=",longitude_deg(i)
-        ! This is presumably serious enough to abort run
-        CALL abort_physic("phyetat0","discrepancy in longitudes!",1)
-      ENDIF
-    ENDIF
-    IF (ABS(lon_startphy(i)-longitude_deg(i))>=1) THEN
-      IF (ABS(360-ABS(lon_startphy(i)-longitude_deg(i))) > 0.0001) THEN
-        WRITE(*,*) "phyetat0: Warning! Longitude discrepancy wrt startphy file:",&
-                   " i=",i," lon_startphy(i)=",lon_startphy(i),&
-                   " longitude_deg(i)=",longitude_deg(i)
-      ENDIF 
-    ENDIF
-  ENDDO
-
-  ! Lecture du masque terre mer
-
-  CALL get_field("masque", zmasq, found)
-  IF (.NOT. found) THEN
-     PRINT*, 'phyetat0: Le champ <masque> est absent'
-     PRINT *, 'fichier startphy non compatible avec phyetat0'
-  ENDIF
-
-  ! Lecture des fractions pour chaque sous-surface
-
-  ! initialisation des sous-surfaces
-
-  pctsrf = 0.
-
-  ! fraction de terre
-
-  CALL get_field("FTER", pctsrf(:, is_ter), found)
-  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FTER> est absent'
-
-  ! fraction de glace de terre
-
-  CALL get_field("FLIC", pctsrf(:, is_lic), found)
-  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FLIC> est absent'
-
-  ! fraction d'ocean
-
-  CALL get_field("FOCE", pctsrf(:, is_oce), found)
-  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FOCE> est absent'
-
-  ! fraction glace de mer
-
-  CALL get_field("FSIC", pctsrf(:, is_sic), found)
-  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FSIC> est absent'
-
-  !  Verification de l'adequation entre le masque et les sous-surfaces
-
-  fractint( 1 : klon) = pctsrf(1 : klon, is_ter)  &
-       + pctsrf(1 : klon, is_lic)
-  DO i = 1 , klon
-     IF ( abs(fractint(i) - zmasq(i) ) .GT. EPSFRA ) THEN
-        WRITE(*, *) 'phyetat0: attention fraction terre pas ',  &
-             'coherente ', i, zmasq(i), pctsrf(i, is_ter) &
-             , pctsrf(i, is_lic)
-        WRITE(*, *) 'Je force la coherence zmasq=fractint'
-        zmasq(i) = fractint(i)
-     ENDIF
-  ENDDO
-  fractint (1 : klon) =  pctsrf(1 : klon, is_oce)  &
-       + pctsrf(1 : klon, is_sic)
-  DO i = 1 , klon
-     IF ( abs( fractint(i) - (1. - zmasq(i))) .GT. EPSFRA ) THEN
-        WRITE(*, *) 'phyetat0 attention fraction ocean pas ',  &
-             'coherente ', i, zmasq(i) , pctsrf(i, is_oce) &
-             , pctsrf(i, is_sic)
-        WRITE(*, *) 'Je force la coherence zmasq=1.-fractint'
-        zmasq(i) = 1. - fractint(i)
-     ENDIF
-  ENDDO
-
-!===================================================================
-! Lecture des temperatures du sol:
-!===================================================================
-
-  found=phyetat0_get(1,ftsol(:,1),"TS","Surface temperature",283.)
-  IF (found) THEN
-     DO nsrf=2,nbsrf
-        ftsol(:,nsrf)=ftsol(:,1)
-     ENDDO
-  ELSE
-     found=phyetat0_srf(1,ftsol,"TS","Surface temperature",283.)
-  ENDIF
-
-!===================================================================
-  ! Lecture des albedo difus et direct
-!===================================================================
-
-  DO nsrf = 1, nbsrf
-     DO isw=1, nsw
-        IF (isw.GT.99) THEN
-           PRINT*, "Trop de bandes SW"
-           call abort_physic("phyetat0", "", 1)
-        ENDIF
-        WRITE(str2, '(i2.2)') isw
-        found=phyetat0_srf(1,falb_dir(:, isw,:),"A_dir_SW"//str2//"srf","Direct Albedo",0.2)
-        found=phyetat0_srf(1,falb_dif(:, isw,:),"A_dif_SW"//str2//"srf","Direct Albedo",0.2)
-     ENDDO
-  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:
-!===================================================================
-
-   DO isoil=1, nsoilmx
-        IF (isoil.GT.99) THEN
-           PRINT*, "Trop de couches "
-           call abort_physic("phyetat0", "", 1)
-        ENDIF
-        WRITE(str2,'(i2.2)') isoil
-        found=phyetat0_srf(1,tsoil(:, isoil,:),"Tsoil"//str2//"srf","Temp soil",0.)
-        IF (.NOT. found) THEN
-           PRINT*, "phyetat0: Le champ <Tsoil"//str7//"> est absent"
-           PRINT*, "          Il prend donc la valeur de surface"
-           tsoil(:, isoil, :)=ftsol(:, :)
-        ENDIF
-   ENDDO
-
-!=======================================================================
-! Lecture precipitation/evaporation
-!=======================================================================
-
-  found=phyetat0_srf(1,qsurf,"QS","Near surface hmidity",0.)
-  found=phyetat0_get(1,qsol,"QSOL","Surface hmidity / bucket",0.)
-  found=phyetat0_srf(1,snow,"SNOW","Surface snow",0.)
-  found=phyetat0_srf(1,fevap,"EVAP","evaporation",0.)
-  found=phyetat0_get(1,snow_fall,"snow_f","snow fall",0.)
-  found=phyetat0_get(1,rain_fall,"rain_f","rain fall",0.)
-
-!=======================================================================
-! Radiation
-!=======================================================================
-
-  found=phyetat0_get(1,solsw,"solsw","net SW radiation surf",0.)
-  found=phyetat0_get(1,solswfdiff,"solswfdiff","fraction of SW radiation surf that is diffuse",1.)
-  found=phyetat0_get(1,sollw,"sollw","net LW radiation surf",0.)
-  found=phyetat0_get(1,sollwdown,"sollwdown","down LW radiation surf",0.)
-  IF (.NOT. found) THEN
-     sollwdown(:) = 0. ;  zts(:)=0.
-     DO nsrf=1,nbsrf
-        zts(:)=zts(:)+ftsol(:,nsrf)*pctsrf(:,nsrf)
-     ENDDO
-     sollwdown(:)=sollw(:)+RSIGMA*zts(:)**4
-  ENDIF
-
-  found=phyetat0_get(1,radsol,"RADS","Solar radiation",0.)
-  found=phyetat0_get(1,fder,"fder","Flux derivative",0.) 
-
-
-  ! Lecture de la longueur de rugosite 
-  found=phyetat0_srf(1,z0m,"RUG","Z0m ancien",0.001)
-  IF (found) THEN
-     z0h(:,1:nbsrf)=z0m(:,1:nbsrf)
-  ELSE
-     found=phyetat0_srf(1,z0m,"Z0m","Roughness length, momentum ",0.001)
-     found=phyetat0_srf(1,z0h,"Z0h","Roughness length, enthalpy ",0.001)
-  ENDIF
-!FC
-  IF (ifl_pbltree>0) THEN
-!CALL get_field("FTER", pctsrf(:, is_ter), found)
-    treedrg(:,1:klev,1:nbsrf)= 0.0
-    CALL get_field("treedrg_ter", drg_ter(:,:), found)
-!  found=phyetat0_srf(1,treedrg,"treedrg","drag from vegetation" , 0.)
-    !lecture du profile de freinage des arbres
-    IF (.not. found ) THEN
-      treedrg(:,1:klev,1:nbsrf)= 0.0
-    ELSE
-      treedrg(:,1:klev,is_ter)= drg_ter(:,:)
-!     found=phyetat0_srf(klev,treedrg,"treedrg","freinage arbres",0.)
-    ENDIF
-  ELSE
-    ! initialize treedrg(), because it will be written in restartphy.nc
-    treedrg(:,:,:) = 0.0 
-  ENDIF
-
-  ! Lecture de l'age de la neige:
-  found=phyetat0_srf(1,agesno,"AGESNO","SNOW AGE",0.001)
-
-  ancien_ok=.true.
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,t_ancien,"TANCIEN","TANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,q_ancien,"QANCIEN","QANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,ql_ancien,"QLANCIEN","QLANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,qs_ancien,"QSANCIEN","QSANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,u_ancien,"UANCIEN","UANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(klev,v_ancien,"VANCIEN","VANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(1,prw_ancien,"PRWANCIEN","PRWANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(1,prlw_ancien,"PRLWANCIEN","PRLWANCIEN",0.)
-  ancien_ok=ancien_ok.AND.phyetat0_get(1,prsw_ancien,"PRSWANCIEN","PRSWANCIEN",0.)
-
-  ! Ehouarn: addtional tests to check if t_ancien, q_ancien contain
-  !          dummy values (as is the case when generated by ce0l,
-  !          or by iniaqua)
-  IF ( (maxval(q_ancien).EQ.minval(q_ancien))       .OR. &
-       (maxval(ql_ancien).EQ.minval(ql_ancien))     .OR. &
-       (maxval(qs_ancien).EQ.minval(qs_ancien))     .OR. &
-       (maxval(prw_ancien).EQ.minval(prw_ancien))   .OR. &
-       (maxval(prlw_ancien).EQ.minval(prlw_ancien)) .OR. &
-       (maxval(prsw_ancien).EQ.minval(prsw_ancien)) .OR. &
-       (maxval(t_ancien).EQ.minval(t_ancien)) ) THEN
-    ancien_ok=.false.
-  ENDIF
-
-  found=phyetat0_get(klev,clwcon,"CLWCON","CLWCON",0.)
-  found=phyetat0_get(klev,rnebcon,"RNEBCON","RNEBCON",0.)
-  found=phyetat0_get(klev,ratqs,"RATQS","RATQS",0.)
-
-  found=phyetat0_get(1,run_off_lic_0,"RUNOFFLIC0","RUNOFFLIC0",0.)
-
-!==================================
-!  TKE
-!==================================
-!
-  IF (iflag_pbl>1) then
-     found=phyetat0_srf(klev+1,pbl_tke,"TKE","Turb. Kinetic. Energ. ",1.e-8)
-  ENDIF
-
-  IF (iflag_pbl>1 .AND. iflag_wake>=1  .AND. iflag_pbl_split >=1 ) then
-    found=phyetat0_srf(klev+1,wake_delta_pbl_tke,"DELTATKE","Del TKE wk/env",0.)
-!!    found=phyetat0_srf(1,delta_tsurf,"DELTA_TSURF","Delta Ts wk/env ",0.)
-    found=phyetat0_srf(1,delta_tsurf,"DELTATS","Delta Ts wk/env ",0.)
-!!    found=phyetat0_srf(1,beta_aridity,"BETA_S","Aridity factor ",1.)
-    found=phyetat0_srf(1,beta_aridity,"BETAS","Aridity factor ",1.)
-  ENDIF   !(iflag_pbl>1 .AND. iflag_wake>=1 .AND. iflag_pbl_split >=1 )
-
-!==================================
-!  thermiques, poches, convection
-!==================================
-
-! Emanuel
-  found=phyetat0_get(klev,sig1,"sig1","sig1",0.)
-  found=phyetat0_get(klev,w01,"w01","w01",0.)
-
-! Wake
-  found=phyetat0_get(klev,wake_deltat,"WAKE_DELTAT","Delta T wake/env",0.)
-  found=phyetat0_get(klev,wake_deltaq,"WAKE_DELTAQ","Delta hum. wake/env",0.)
-  found=phyetat0_get(1,wake_s,"WAKE_S","Wake frac. area",0.)
-!jyg<
-!  Set wake_dens to -1000. when there is no restart so that the actual
-!  initialization is made in calwake.
-!!  found=phyetat0_get(1,wake_dens,"WAKE_DENS","Wake num. /unit area",0.)
-  found=phyetat0_get(1,wake_dens,"WAKE_DENS","Wake num. /unit area",-1000.)
-  found=phyetat0_get(1,awake_dens,"AWAKE_DENS","Active Wake num. /unit area",0.)
-  found=phyetat0_get(1,cv_gen,"CV_GEN","CB birth rate",0.)
-!>jyg
-  found=phyetat0_get(1,wake_cstar,"WAKE_CSTAR","WAKE_CSTAR",0.)
-  found=phyetat0_get(1,wake_pe,"WAKE_PE","WAKE_PE",0.)
-  found=phyetat0_get(1,wake_fip,"WAKE_FIP","WAKE_FIP",0.)
-
-! Thermiques
-  found=phyetat0_get(1,zmax0,"ZMAX0","ZMAX0",40.)
-  found=phyetat0_get(1,f0,"F0","F0",1.e-5)
-  found=phyetat0_get(klev+1,fm_therm,"FM_THERM","Thermals mass flux",0.)
-  found=phyetat0_get(klev,entr_therm,"ENTR_THERM","Thermals Entrain.",0.)
-  found=phyetat0_get(klev,detr_therm,"DETR_THERM","Thermals Detrain.",0.)
-
-! ALE/ALP
-  found=phyetat0_get(1,ale_bl,"ALE_BL","ALE BL",0.)
-  found=phyetat0_get(1,ale_bl_trig,"ALE_BL_TRIG","ALE BL_TRIG",0.)
-  found=phyetat0_get(1,alp_bl,"ALP_BL","ALP BL",0.)
-  found=phyetat0_get(1,ale_wake,"ALE_WAKE","ALE_WAKE",0.)
-  found=phyetat0_get(1,ale_bl_stat,"ALE_BL_STAT","ALE_BL_STAT",0.)
-
-! fisrtilp/Clouds 0.002 could be ratqsbas. But can stay like this as well
-  found=phyetat0_get(klev,ratqs_inter,"RATQS_INTER","Relative width of the lsc sugrid scale water",0.002)
-
-!===========================================
-  ! Read and send field trs to traclmdz
-!===========================================
-
-!--OB now this is for co2i - ThL: and therefore also for inco
-  IF (ANY(types_trac == 'co2i') .OR. ANY(types_trac == 'inco')) THEN
-     IF (carbon_cycle_cpl) THEN
-        ALLOCATE(co2_send(klon), stat=ierr)
-        IF (ierr /= 0) CALL abort_physic('phyetat0', 'pb allocation co2_send', 1)
-        found=phyetat0_get(1,co2_send,"co2_send","co2 send",co2_ppm)
-     ENDIF
-  ELSE IF (ANY(types_trac == 'lmdz')) THEN
-     it = 0
-     DO iq = 1, nqtot
-        IF(.NOT.(tracers(iq)%isAdvected .AND. tracers(iq)%isInPhysics)) CYCLE
-        it = it+1
-        found=phyetat0_get(1,trs(:,it),"trs_"//TRIM(tracers(iq)%name), &
-                                  "Surf trac"//TRIM(tracers(iq)%name),0.)
-     END DO
-     CALL traclmdz_from_restart(trs)
-  ENDIF
-
-#ifdef ISO
-        ! initialise les isotopes       
-        write(*,*) 'phyetat0 1069' 
-         CALL phyisoetat0 (snow,run_off_lic_0, &
-     &           xtsnow,xtrun_off_lic_0, &
-     &           Rland_ice)
-#ifdef ISOVERIF 
-      write(*,*) 'phyetat0 1074'
-      if (iso_eau.gt.0) then
-      call iso_verif_egalite_vect2D(  &
-     &           xtsnow,snow, &
-     &           'phyetat0 1101a',niso,klon,nbsrf)
-        do i=1,klon  
-              call iso_verif_egalite(Rland_ice(iso_eau,i),1.0, &
-     &         'phyetat0 1101b')
-         enddo
-      endif
-      write(*,*) 'phyetat0 1102'
-#endif
-#endif
-
-!===========================================
-!  ondes de gravite / relief
-!===========================================
-
-!  ondes de gravite non orographiques
-  IF (ok_gwd_rando) found = &
-       phyetat0_get(klev,du_gwd_rando,"du_gwd_rando","du_gwd_rando",0.)
-  IF (.NOT. ok_hines .AND. ok_gwd_rando) found &
-       = phyetat0_get(klev,du_gwd_front,"du_gwd_front","du_gwd_front",0.)
-
-!  prise en compte du relief sous-maille
-  found=phyetat0_get(1,zmea,"ZMEA","sub grid orography",0.)
-  found=phyetat0_get(1,zstd,"ZSTD","sub grid orography",0.)
-  found=phyetat0_get(1,zsig,"ZSIG","sub grid orography",0.)
-  found=phyetat0_get(1,zgam,"ZGAM","sub grid orography",0.)
-  found=phyetat0_get(1,zthe,"ZTHE","sub grid orography",0.)
-  found=phyetat0_get(1,zpic,"ZPIC","sub grid orography",0.)
-  found=phyetat0_get(1,zval,"ZVAL","sub grid orography",0.)
-  found=phyetat0_get(1,zmea,"ZMEA","sub grid orography",0.)
-  found=phyetat0_get(1,rugoro,"RUGSREL","sub grid orography",0.)
-
-!===========================================
-! Initialize ocean
-!===========================================
-
-  IF ( type_ocean == 'slab' ) THEN
-      CALL ocean_slab_init(phys_tstep, pctsrf)
-      IF (nslay.EQ.1) THEN
-        found=phyetat0_get(1,tslab,"tslab01","tslab",0.)
-        IF (.NOT. found) THEN
-            found=phyetat0_get(1,tslab,"tslab","tslab",0.)
-        ENDIF
-      ELSE
-          DO i=1,nslay
-            WRITE(str2,'(i2.2)') i
-            found=phyetat0_get(1,tslab(:,i),"tslab"//str2,"tslab",0.)  
-          ENDDO
-      ENDIF
-      IF (.NOT. found) THEN 
-          PRINT*, "phyetat0: Le champ <tslab> est absent"
-          PRINT*, "Initialisation a tsol_oce"
-          DO i=1,nslay
-              tslab(:,i)=MAX(ftsol(:,is_oce),271.35)
-          ENDDO
-      ENDIF 
-
-      ! Sea ice variables
-      IF (version_ocean == 'sicINT') THEN
-          found=phyetat0_get(1,tice,"slab_tice","slab_tice",0.)
-          IF (.NOT. found) THEN 
-              PRINT*, "phyetat0: Le champ <tice> est absent"
-              PRINT*, "Initialisation a tsol_sic"
-                  tice(:)=ftsol(:,is_sic)
-          ENDIF 
-          found=phyetat0_get(1,seaice,"seaice","seaice",0.)
-          IF (.NOT. found) THEN
-              PRINT*, "phyetat0: Le champ <seaice> est absent"
-              PRINT*, "Initialisation a 0/1m suivant fraction glace"
-              seaice(:)=0.
-              WHERE (pctsrf(:,is_sic).GT.EPSFRA)
-                  seaice=917.
-              ENDWHERE
-          ENDIF
-      ENDIF !sea ice INT
-  ENDIF ! Slab        
-
-  if (activate_ocean_skin >= 1) then
-     if (activate_ocean_skin == 2 .and. type_ocean == 'couple') then
-        found = phyetat0_get(1, delta_sal, "delta_sal", &
-             "ocean-air interface salinity minus bulk salinity", 0.)
-        found = phyetat0_get(1, delta_sst, "delta_SST", &
-             "ocean-air interface temperature minus bulk SST", 0.)
-     end if
-     
-     found = phyetat0_get(1, ds_ns, "dS_ns", "delta salinity near surface", 0.)
-     found = phyetat0_get(1, dt_ns, "dT_ns", "delta temperature near surface", &
-          0.)
-
-     where (pctsrf(:, is_oce) == 0.)
-        ds_ns = missing_val
-        dt_ns = missing_val
-        delta_sst = missing_val
-        delta_sal = missing_val
-     end where
-  end if
-
-  ! on ferme le fichier
-  CALL close_startphy
-
-  ! Initialize module pbl_surface_mod 
-
-#ifdef ISOVERIF
-        write(*,*) 'phyetat0 572: snow(994,:)=',snow(994,2)
-        write(*,*) 'xtsnow(:,994,2)=',xtsnow(:,994,2)
-#endif
-
-  CALL pbl_surface_init(fder, snow, qsurf, tsoil)
-#ifdef ISO
-  CALL pbl_surface_init_iso(xtsnow,Rland_ice)
-#endif
-
-  ! Initialize module ocean_cpl_mod for the case of coupled ocean
-  IF ( type_ocean == 'couple' ) THEN
-     CALL ocean_cpl_init(phys_tstep, longitude_deg, latitude_deg)
-  ENDIF
-
-!  CALL init_iophy_new(latitude_deg, longitude_deg)
-
-  ! Initilialize module fonte_neige_mod      
-  CALL fonte_neige_init(run_off_lic_0)
-#ifdef ISO
-   CALL fonte_neige_init_iso(xtrun_off_lic_0)
-#endif
-
-END SUBROUTINE phyetat0
-
-!===================================================================
-FUNCTION phyetat0_get(nlev,field,name,descr,default)
-!===================================================================
-! Lecture d'un champ avec contrôle
-! Function logique dont le resultat indique si la lecture
-! s'est bien passée
-! On donne une valeur par defaut dans le cas contraire
-!===================================================================
-
-USE iostart, ONLY : get_field
-USE dimphy, only: klon 
-USE print_control_mod, ONLY: lunout
-
-IMPLICIT NONE
-
-LOGICAL phyetat0_get
-
-! arguments
-INTEGER,INTENT(IN) :: nlev
-CHARACTER*(*),INTENT(IN) :: name,descr
-REAL,INTENT(IN) :: default
-REAL,DIMENSION(klon,nlev),INTENT(INOUT) :: field
-
-! Local variables
-LOGICAL found
-
-   CALL get_field(name, field, found)
-   IF (.NOT. found) THEN
-     WRITE(lunout,*) "phyetat0: Le champ <",TRIM(name),"> est absent"
-     WRITE(lunout,*) "Depart legerement fausse. Mais je continue"
-     field(:,:)=default
-   ENDIF
-   WRITE(lunout,*) name, descr, MINval(field),MAXval(field)
-   phyetat0_get=found
-
-RETURN
-END FUNCTION phyetat0_get
-
-!================================================================
-FUNCTION phyetat0_srf(nlev,field,name,descr,default)
-!===================================================================
-! Lecture d'un champ par sous-surface avec contrôle
-! Function logique dont le resultat indique si la lecture
-! s'est bien passée
-! On donne une valeur par defaut dans le cas contraire
-!===================================================================
-
-USE iostart, ONLY : get_field
-USE dimphy, only: klon 
-USE indice_sol_mod, only: nbsrf
-USE print_control_mod, ONLY: lunout
-
-IMPLICIT NONE
-
-LOGICAL phyetat0_srf
-! arguments
-INTEGER,INTENT(IN) :: nlev
-CHARACTER*(*),INTENT(IN) :: name,descr
-REAL,INTENT(IN) :: default
-REAL,DIMENSION(klon,nlev,nbsrf),INTENT(INOUT) :: field
-
-! Local variables
-LOGICAL found,phyetat0_get
-INTEGER nsrf
-CHARACTER*2 str2
-  
-     IF (nbsrf.GT.99) THEN
-        WRITE(lunout,*) "Trop de sous-mailles"
-        call abort_physic("phyetat0", "", 1)
-     ENDIF
-
-     DO nsrf = 1, nbsrf
-        WRITE(str2, '(i2.2)') nsrf
-        found= phyetat0_get(nlev,field(:,:, nsrf), &
-        name//str2,descr//" srf:"//str2,default)
-     ENDDO
-
-     phyetat0_srf=found
-
-RETURN
-END FUNCTION phyetat0_srf
-
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phyetat0_get_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phyetat0_get_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phyetat0_get_mod.F90	(revision 4482)
@@ -0,0 +1,1 @@
+link ../phylmd/phyetat0_get_mod.F90
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phyetat0_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phyetat0_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phyetat0_mod.F90	(revision 4482)
@@ -0,0 +1,661 @@
+! $Id: phyetat0.F90 3890 2021-05-05 15:15:06Z jyg $
+
+MODULE phyetat0_mod
+
+  PRIVATE
+  PUBLIC :: phyetat0
+
+CONTAINS
+
+SUBROUTINE phyetat0 (fichnom, clesphy0, tabcntr0)
+
+  USE dimphy, only: klon, zmasq, klev
+  USE iophy, ONLY : init_iophy_new
+  USE ocean_cpl_mod,    ONLY : ocean_cpl_init
+  USE fonte_neige_mod,  ONLY : fonte_neige_init
+  USE pbl_surface_mod,  ONLY : pbl_surface_init
+#ifdef ISO
+  USE fonte_neige_mod,  ONLY : fonte_neige_init_iso
+  USE pbl_surface_mod,  ONLY : pbl_surface_init_iso
+#endif
+  USE phyetat0_get_mod, ONLY : phyetat0_get, phyetat0_srf
+  USE surface_data,     ONLY : type_ocean, version_ocean
+  USE phys_state_var_mod, ONLY : ancien_ok, clwcon, detr_therm, phys_tstep, &
+       qsol, fevap, z0m, z0h, agesno, &
+       du_gwd_rando, du_gwd_front, entr_therm, f0, fm_therm, &
+       falb_dir, falb_dif, prw_ancien, prlw_ancien, prsw_ancien, &
+       ftsol, pbl_tke, pctsrf, q_ancien, ql_ancien, qs_ancien, rneb_ancien, radpas, radsol, rain_fall, ratqs, &
+       rnebcon, rugoro, sig1, snow_fall, solaire_etat0, sollw, sollwdown, &
+       solsw, solswfdiff, t_ancien, u_ancien, v_ancien, w01, wake_cstar, wake_deltaq, &
+       wake_deltat, wake_delta_pbl_TKE, delta_tsurf, beta_aridity, wake_fip, wake_pe, &
+       wake_s, wake_dens, awake_dens, cv_gen, zgam, zmax0, zmea, zpic, zsig, &
+#ifdef ISO
+       fxtevap, xtsol, xt_ancien, xtl_ancien, xts_ancien, wake_deltaxt, &
+       xtrain_fall,xtsnow_fall, &
+#endif
+       zstd, zthe, zval, ale_bl, ale_bl_trig, alp_bl, u10m, v10m, treedrg, &
+       ale_wake, ale_bl_stat, ds_ns, dt_ns, delta_sst, delta_sal, dter, dser, &
+       dt_ds, ratqs_inter
+!FC
+  USE geometry_mod,     ONLY: longitude_deg, latitude_deg
+  USE iostart,          ONLY: close_startphy, get_field, get_var, open_startphy
+  USE infotrac_phy,     ONLY: nqtot, nbtr, type_trac, tracers
+  USE readTracFiles_mod,ONLY: maxlen, new2oldH2O
+  USE traclmdz_mod,     ONLY: traclmdz_from_restart
+  USE carbon_cycle_mod, ONLY: carbon_cycle_init, carbon_cycle_cpl, carbon_cycle_tr, carbon_cycle_rad, co2_send, RCO2_glo
+  USE indice_sol_mod,   ONLY: nbsrf, is_ter, epsfra, is_lic, is_oce, is_sic
+  USE ocean_slab_mod,   ONLY: nslay, tslab, seaice, tice, ocean_slab_init
+  USE time_phylmdz_mod, ONLY: init_iteration, pdtphys, itau_phy
+#ifdef CPP_XIOS
+  USE wxios, ONLY: missing_val
+#else
+  use netcdf, only: missing_val => nf90_fill_real
+#endif
+  use config_ocean_skin_m, only: activate_ocean_skin
+#ifdef ISO
+  USE infotrac_phy, ONLY: niso
+  USE isotopes_routines_mod, ONLY: phyisoetat0
+  USE isotopes_mod, ONLY: iso_eau
+#ifdef ISOVERIF
+  USE isotopes_verif_mod, ONLY: iso_verif_egalite_vect2D,iso_verif_egalite
+#endif
+#endif
+
+  IMPLICIT none
+  !======================================================================
+  ! Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
+  ! Objet: Lecture de l'etat initial pour la physique
+  !======================================================================
+  include "dimsoil.h"
+  include "clesphys.h"
+  include "alpale.h"
+  include "compbl.h"
+  include "YOMCST.h"
+  !======================================================================
+  CHARACTER*(*) fichnom
+
+  ! les variables globales lues dans le fichier restart
+
+  REAL tsoil(klon, nsoilmx, nbsrf)
+  REAL qsurf(klon, nbsrf)
+  REAL snow(klon, nbsrf)
+  real fder(klon)
+  REAL run_off_lic_0(klon)
+  REAL fractint(klon)
+  REAL trs(klon, nbtr)
+  REAL zts(klon)
+  ! pour drag arbres FC
+  REAL drg_ter(klon,klev)
+
+  CHARACTER*6 ocean_in
+  LOGICAL ok_veget_in
+
+  INTEGER        longcles
+  PARAMETER    ( longcles = 20 )
+  REAL clesphy0( longcles )
+
+  REAL xmin, xmax
+
+  INTEGER nid, nvarid
+  INTEGER ierr, i, nsrf, isoil , k
+  INTEGER length
+  PARAMETER (length=100)
+  INTEGER it, iq, isw
+  REAL tab_cntrl(length), tabcntr0(length)
+  CHARACTER*7 str7
+  CHARACTER*2 str2
+  LOGICAL :: found
+  REAL :: lon_startphy(klon), lat_startphy(klon)
+  CHARACTER(LEN=maxlen) :: tname, t(2)
+
+#ifdef ISO
+  REAL xtsnow(niso,klon, nbsrf)
+  REAL xtrun_off_lic_0(niso,klon)
+  REAL Rland_ice(niso,klon)
+#endif
+  ! FH1D
+  !     real iolat(jjm+1)
+  !real iolat(jjm+1-1/(iim*jjm))
+
+  ! Ouvrir le fichier contenant l'etat initial:
+
+  CALL open_startphy(fichnom)
+
+  ! Lecture des parametres de controle:
+
+  CALL get_var("controle", tab_cntrl)
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  ! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
+  ! Les constantes de la physiques sont lues dans la physique seulement.
+  ! Les egalites du type
+  !             tab_cntrl( 5 )=clesphy0(1)
+  ! sont remplacees par
+  !             clesphy0(1)=tab_cntrl( 5 )
+  ! On inverse aussi la logique.
+  ! On remplit les tab_cntrl avec les parametres lus dans les .def
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  DO i = 1, length
+     tabcntr0( i ) = tab_cntrl( i )
+  ENDDO
+
+  tab_cntrl(1)=pdtphys
+  tab_cntrl(2)=radpas
+
+  ! co2_ppm : value from the previous time step
+
+  ! co2_ppm0 : initial value of atmospheric CO2 (from create_etat0_limit.e .def)
+  co2_ppm0 = 284.32
+  ! when no initial value is available e.g., from a restart 
+  ! this variable must be set  in a .def file which will then be 
+  ! used by the conf_phys_m.F90 routine.
+  ! co2_ppm0 = 284.32 (illustrative example on how to set the variable in .def
+  ! file, for a pre-industrial CO2 concentration value)
+
+  IF (carbon_cycle_tr .OR. carbon_cycle_cpl) THEN
+     co2_ppm = tab_cntrl(3)
+     RCO2    = co2_ppm * 1.0e-06 * RMCO2 / RMD
+     IF (tab_cntrl(17) > 0. .AND. carbon_cycle_rad) THEN
+           RCO2_glo = tab_cntrl(17)
+       ELSE
+           RCO2_glo    = co2_ppm0 * 1.0e-06 * RMCO2 / RMD
+     ENDIF
+     ! ELSE : keep value from .def
+  ENDIF
+
+  solaire_etat0      = tab_cntrl(4)
+  tab_cntrl(5)=iflag_con
+  tab_cntrl(6)=nbapp_rad
+
+  IF (iflag_cycle_diurne.GE.1) tab_cntrl( 7) = iflag_cycle_diurne
+  IF (soil_model) tab_cntrl( 8) =1.
+  IF (new_oliq) tab_cntrl( 9) =1.
+  IF (ok_orodr) tab_cntrl(10) =1.
+  IF (ok_orolf) tab_cntrl(11) =1.
+  IF (ok_limitvrai) tab_cntrl(12) =1.
+
+  itau_phy = tab_cntrl(15)
+
+  clesphy0(1)=tab_cntrl( 5 )
+  clesphy0(2)=tab_cntrl( 6 )
+  clesphy0(3)=tab_cntrl( 7 )
+  clesphy0(4)=tab_cntrl( 8 )
+  clesphy0(5)=tab_cntrl( 9 )
+  clesphy0(6)=tab_cntrl( 10 )
+  clesphy0(7)=tab_cntrl( 11 )
+  clesphy0(8)=tab_cntrl( 12 )
+  clesphy0(9)=tab_cntrl( 17 )
+
+  ! set time iteration
+   CALL init_iteration(itau_phy)
+
+  ! read latitudes and make a sanity check (because already known from dyn)
+  CALL get_field("latitude",lat_startphy)
+  DO i=1,klon
+    IF (ABS(lat_startphy(i)-latitude_deg(i))>=1) THEN
+      WRITE(*,*) "phyetat0: Error! Latitude discrepancy wrt startphy file:",&
+                 " i=",i," lat_startphy(i)=",lat_startphy(i),&
+                 " latitude_deg(i)=",latitude_deg(i)
+      ! This is presumably serious enough to abort run
+      CALL abort_physic("phyetat0","discrepancy in latitudes!",1)
+    ENDIF
+    IF (ABS(lat_startphy(i)-latitude_deg(i))>=0.0001) THEN
+      WRITE(*,*) "phyetat0: Warning! Latitude discrepancy wrt startphy file:",&
+                 " i=",i," lat_startphy(i)=",lat_startphy(i),&
+                 " latitude_deg(i)=",latitude_deg(i)
+    ENDIF
+  ENDDO
+
+  ! read longitudes and make a sanity check (because already known from dyn)
+  CALL get_field("longitude",lon_startphy)
+  DO i=1,klon
+    IF (ABS(lon_startphy(i)-longitude_deg(i))>=1) THEN
+      IF (ABS(360-ABS(lon_startphy(i)-longitude_deg(i)))>=1) THEN
+        WRITE(*,*) "phyetat0: Error! Longitude discrepancy wrt startphy file:",&
+                   " i=",i," lon_startphy(i)=",lon_startphy(i),&
+                   " longitude_deg(i)=",longitude_deg(i)
+        ! This is presumably serious enough to abort run
+        CALL abort_physic("phyetat0","discrepancy in longitudes!",1)
+      ENDIF
+    ENDIF
+    IF (ABS(lon_startphy(i)-longitude_deg(i))>=1) THEN
+      IF (ABS(360-ABS(lon_startphy(i)-longitude_deg(i))) > 0.0001) THEN
+        WRITE(*,*) "phyetat0: Warning! Longitude discrepancy wrt startphy file:",&
+                   " i=",i," lon_startphy(i)=",lon_startphy(i),&
+                   " longitude_deg(i)=",longitude_deg(i)
+      ENDIF 
+    ENDIF
+  ENDDO
+
+  ! Lecture du masque terre mer
+
+  CALL get_field("masque", zmasq, found)
+  IF (.NOT. found) THEN
+     PRINT*, 'phyetat0: Le champ <masque> est absent'
+     PRINT *, 'fichier startphy non compatible avec phyetat0'
+  ENDIF
+
+  ! Lecture des fractions pour chaque sous-surface
+
+  ! initialisation des sous-surfaces
+
+  pctsrf = 0.
+
+  ! fraction de terre
+
+  CALL get_field("FTER", pctsrf(:, is_ter), found)
+  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FTER> est absent'
+
+  ! fraction de glace de terre
+
+  CALL get_field("FLIC", pctsrf(:, is_lic), found)
+  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FLIC> est absent'
+
+  ! fraction d'ocean
+
+  CALL get_field("FOCE", pctsrf(:, is_oce), found)
+  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FOCE> est absent'
+
+  ! fraction glace de mer
+
+  CALL get_field("FSIC", pctsrf(:, is_sic), found)
+  IF (.NOT. found) PRINT*, 'phyetat0: Le champ <FSIC> est absent'
+
+  !  Verification de l'adequation entre le masque et les sous-surfaces
+
+  fractint( 1 : klon) = pctsrf(1 : klon, is_ter)  &
+       + pctsrf(1 : klon, is_lic)
+  DO i = 1 , klon
+     IF ( abs(fractint(i) - zmasq(i) ) .GT. EPSFRA ) THEN
+        WRITE(*, *) 'phyetat0: attention fraction terre pas ',  &
+             'coherente ', i, zmasq(i), pctsrf(i, is_ter) &
+             , pctsrf(i, is_lic)
+        WRITE(*, *) 'Je force la coherence zmasq=fractint'
+        zmasq(i) = fractint(i)
+     ENDIF
+  ENDDO
+  fractint (1 : klon) =  pctsrf(1 : klon, is_oce)  &
+       + pctsrf(1 : klon, is_sic)
+  DO i = 1 , klon
+     IF ( abs( fractint(i) - (1. - zmasq(i))) .GT. EPSFRA ) THEN
+        WRITE(*, *) 'phyetat0 attention fraction ocean pas ',  &
+             'coherente ', i, zmasq(i) , pctsrf(i, is_oce) &
+             , pctsrf(i, is_sic)
+        WRITE(*, *) 'Je force la coherence zmasq=1.-fractint'
+        zmasq(i) = 1. - fractint(i)
+     ENDIF
+  ENDDO
+
+!===================================================================
+! Lecture des temperatures du sol:
+!===================================================================
+
+  found=phyetat0_get(ftsol(:,1),"TS","Surface temperature",283.)
+  IF (found) THEN
+     DO nsrf=2,nbsrf
+        ftsol(:,nsrf)=ftsol(:,1)
+     ENDDO
+  ELSE
+     found=phyetat0_srf(ftsol,"TS","Surface temperature",283.)
+  ENDIF
+
+!===================================================================
+  ! Lecture des albedo difus et direct
+!===================================================================
+
+  DO nsrf = 1, nbsrf
+     DO isw=1, nsw
+        IF (isw.GT.99) THEN
+           PRINT*, "Trop de bandes SW"
+           call abort_physic("phyetat0", "", 1)
+        ENDIF
+        WRITE(str2, '(i2.2)') isw
+        found=phyetat0_srf(falb_dir(:, isw,:),"A_dir_SW"//str2//"srf","Direct Albedo",0.2)
+        found=phyetat0_srf(falb_dif(:, isw,:),"A_dif_SW"//str2//"srf","Direct Albedo",0.2)
+     ENDDO
+  ENDDO
+
+  found=phyetat0_srf(u10m,"U10M","u a 10m",0.)
+  found=phyetat0_srf(v10m,"V10M","v a 10m",0.)
+
+!===================================================================
+  ! Lecture des temperatures du sol profond:
+!===================================================================
+
+   DO isoil=1, nsoilmx
+        IF (isoil.GT.99) THEN
+           PRINT*, "Trop de couches "
+           call abort_physic("phyetat0", "", 1)
+        ENDIF
+        WRITE(str2,'(i2.2)') isoil
+        found=phyetat0_srf(tsoil(:, isoil,:),"Tsoil"//str2//"srf","Temp soil",0.)
+        IF (.NOT. found) THEN
+           PRINT*, "phyetat0: Le champ <Tsoil"//str7//"> est absent"
+           PRINT*, "          Il prend donc la valeur de surface"
+           tsoil(:, isoil, :)=ftsol(:, :)
+        ENDIF
+   ENDDO
+
+!=======================================================================
+! Lecture precipitation/evaporation
+!=======================================================================
+
+  found=phyetat0_srf(qsurf,"QS","Near surface hmidity",0.)
+  found=phyetat0_get(qsol,"QSOL","Surface hmidity / bucket",0.)
+  found=phyetat0_srf(snow,"SNOW","Surface snow",0.)
+  found=phyetat0_srf(fevap,"EVAP","evaporation",0.)
+  found=phyetat0_get(snow_fall,"snow_f","snow fall",0.)
+  found=phyetat0_get(rain_fall,"rain_f","rain fall",0.)
+
+!=======================================================================
+! Radiation
+!=======================================================================
+
+  found=phyetat0_get(solsw,"solsw","net SW radiation surf",0.)
+  found=phyetat0_get(solswfdiff,"solswfdiff","fraction of SW radiation surf that is diffuse",1.)
+  found=phyetat0_get(sollw,"sollw","net LW radiation surf",0.)
+  found=phyetat0_get(sollwdown,"sollwdown","down LW radiation surf",0.)
+  IF (.NOT. found) THEN
+     sollwdown(:) = 0. ;  zts(:)=0.
+     DO nsrf=1,nbsrf
+        zts(:)=zts(:)+ftsol(:,nsrf)*pctsrf(:,nsrf)
+     ENDDO
+     sollwdown(:)=sollw(:)+RSIGMA*zts(:)**4
+  ENDIF
+
+  found=phyetat0_get(radsol,"RADS","Solar radiation",0.)
+  found=phyetat0_get(fder,"fder","Flux derivative",0.) 
+
+
+  ! Lecture de la longueur de rugosite 
+  found=phyetat0_srf(z0m,"RUG","Z0m ancien",0.001)
+  IF (found) THEN
+     z0h(:,1:nbsrf)=z0m(:,1:nbsrf)
+  ELSE
+     found=phyetat0_srf(z0m,"Z0m","Roughness length, momentum ",0.001)
+     found=phyetat0_srf(z0h,"Z0h","Roughness length, enthalpy ",0.001)
+  ENDIF
+!FC
+  IF (ifl_pbltree>0) THEN
+!CALL get_field("FTER", pctsrf(:, is_ter), found)
+    treedrg(:,1:klev,1:nbsrf)= 0.0
+    CALL get_field("treedrg_ter", drg_ter(:,:), found)
+!  found=phyetat0_srf(treedrg,"treedrg","drag from vegetation" , 0.)
+    !lecture du profile de freinage des arbres
+    IF (.not. found ) THEN
+      treedrg(:,1:klev,1:nbsrf)= 0.0
+    ELSE
+      treedrg(:,1:klev,is_ter)= drg_ter(:,:)
+!     found=phyetat0_get(treedrg,"treedrg","freinage arbres",0.)
+    ENDIF
+  ELSE
+    ! initialize treedrg(), because it will be written in restartphy.nc
+    treedrg(:,:,:) = 0.0 
+  ENDIF
+
+  ! Lecture de l'age de la neige:
+  found=phyetat0_srf(agesno,"AGESNO","SNOW AGE",0.001)
+
+  ancien_ok=.true.
+  ancien_ok=ancien_ok.AND.phyetat0_get(t_ancien,"TANCIEN","TANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(q_ancien,"QANCIEN","QANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(ql_ancien,"QLANCIEN","QLANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(qs_ancien,"QSANCIEN","QSANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(rneb_ancien,"RNEBANCIEN","RNEBANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(u_ancien,"UANCIEN","UANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(v_ancien,"VANCIEN","VANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(prw_ancien,"PRWANCIEN","PRWANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(prlw_ancien,"PRLWANCIEN","PRLWANCIEN",0.)
+  ancien_ok=ancien_ok.AND.phyetat0_get(prsw_ancien,"PRSWANCIEN","PRSWANCIEN",0.)
+
+  ! Ehouarn: addtional tests to check if t_ancien, q_ancien contain
+  !          dummy values (as is the case when generated by ce0l,
+  !          or by iniaqua)
+  IF ( (maxval(q_ancien).EQ.minval(q_ancien))       .OR. &
+       (maxval(ql_ancien).EQ.minval(ql_ancien))     .OR. &
+       (maxval(qs_ancien).EQ.minval(qs_ancien))     .OR. &
+       (maxval(rneb_ancien).EQ.minval(rneb_ancien)) .OR. &
+       (maxval(prw_ancien).EQ.minval(prw_ancien))   .OR. &
+       (maxval(prlw_ancien).EQ.minval(prlw_ancien)) .OR. &
+       (maxval(prsw_ancien).EQ.minval(prsw_ancien)) .OR. &
+       (maxval(t_ancien).EQ.minval(t_ancien)) ) THEN
+    ancien_ok=.false.
+  ENDIF
+
+  found=phyetat0_get(clwcon,"CLWCON","CLWCON",0.)
+  found=phyetat0_get(rnebcon,"RNEBCON","RNEBCON",0.)
+  found=phyetat0_get(ratqs,"RATQS","RATQS",0.)
+
+  found=phyetat0_get(run_off_lic_0,"RUNOFFLIC0","RUNOFFLIC0",0.)
+
+!==================================
+!  TKE
+!==================================
+!
+  IF (iflag_pbl>1) then
+     found=phyetat0_srf(pbl_tke,"TKE","Turb. Kinetic. Energ. ",1.e-8)
+  ENDIF
+
+  IF (iflag_pbl>1 .AND. iflag_wake>=1  .AND. iflag_pbl_split >=1 ) then
+    found=phyetat0_srf(wake_delta_pbl_tke,"DELTATKE","Del TKE wk/env",0.)
+!!    found=phyetat0_srf(delta_tsurf,"DELTA_TSURF","Delta Ts wk/env ",0.)
+    found=phyetat0_srf(delta_tsurf,"DELTATS","Delta Ts wk/env ",0.)
+!!    found=phyetat0_srf(beta_aridity,"BETA_S","Aridity factor ",1.)
+    found=phyetat0_srf(beta_aridity,"BETAS","Aridity factor ",1.)
+  ENDIF   !(iflag_pbl>1 .AND. iflag_wake>=1 .AND. iflag_pbl_split >=1 )
+
+!==================================
+!  thermiques, poches, convection
+!==================================
+
+! Emanuel
+  found=phyetat0_get(sig1,"sig1","sig1",0.)
+  found=phyetat0_get(w01,"w01","w01",0.)
+
+! Wake
+  found=phyetat0_get(wake_deltat,"WAKE_DELTAT","Delta T wake/env",0.)
+  found=phyetat0_get(wake_deltaq,"WAKE_DELTAQ","Delta hum. wake/env",0.)
+  found=phyetat0_get(wake_s,"WAKE_S","Wake frac. area",0.)
+!jyg<
+!  Set wake_dens to -1000. when there is no restart so that the actual
+!  initialization is made in calwake.
+!!  found=phyetat0_get(1,wake_dens,"WAKE_DENS","Wake num. /unit area",0.)
+  found=phyetat0_get(wake_dens,"WAKE_DENS","Wake num. /unit area",-1000.)
+  found=phyetat0_get(awake_dens,"AWAKE_DENS","Active Wake num. /unit area",0.)
+  found=phyetat0_get(cv_gen,"CV_GEN","CB birth rate",0.)
+!>jyg
+  found=phyetat0_get(wake_cstar,"WAKE_CSTAR","WAKE_CSTAR",0.)
+  found=phyetat0_get(wake_pe,"WAKE_PE","WAKE_PE",0.)
+  found=phyetat0_get(wake_fip,"WAKE_FIP","WAKE_FIP",0.)
+
+! Thermiques
+  found=phyetat0_get(zmax0,"ZMAX0","ZMAX0",40.)
+  found=phyetat0_get(f0,"F0","F0",1.e-5)
+  found=phyetat0_get(fm_therm,"FM_THERM","Thermals mass flux",0.)
+  found=phyetat0_get(entr_therm,"ENTR_THERM","Thermals Entrain.",0.)
+  found=phyetat0_get(detr_therm,"DETR_THERM","Thermals Detrain.",0.)
+
+! ALE/ALP
+  found=phyetat0_get(ale_bl,"ALE_BL","ALE BL",0.)
+  found=phyetat0_get(ale_bl_trig,"ALE_BL_TRIG","ALE BL_TRIG",0.)
+  found=phyetat0_get(alp_bl,"ALP_BL","ALP BL",0.)
+  found=phyetat0_get(ale_wake,"ALE_WAKE","ALE_WAKE",0.)
+  found=phyetat0_get(ale_bl_stat,"ALE_BL_STAT","ALE_BL_STAT",0.)
+
+! fisrtilp/Clouds 0.002 could be ratqsbas. But can stay like this as well
+  found=phyetat0_get(ratqs_inter,"RATQS_INTER","Relative width of the lsc sugrid scale water",0.002)
+
+!===========================================
+  ! Read and send field trs to traclmdz
+!===========================================
+
+!--OB now this is for co2i - ThL: and therefore also for inco
+  IF (ANY(type_trac == ['co2i','inco'])) THEN
+     IF (carbon_cycle_cpl) THEN
+        ALLOCATE(co2_send(klon), stat=ierr)
+        IF (ierr /= 0) CALL abort_physic('phyetat0', 'pb allocation co2_send', 1)
+        found=phyetat0_get(co2_send,"co2_send","co2 send",co2_ppm0)
+     ENDIF
+  ELSE IF (type_trac == 'lmdz') THEN
+     it = 0
+     DO iq = 1, nqtot
+        IF(.NOT.(tracers(iq)%isAdvected .AND. tracers(iq)%isInPhysics)) CYCLE
+        it = it+1
+        tname = tracers(iq)%name
+        t(1) = 'trs_'//TRIM(tname); t(2) = 'trs_'//TRIM(new2oldH2O(tname))
+        found = phyetat0_get(trs(:,it), t(:), "Surf trac"//TRIM(tname), 0.)
+     END DO
+     CALL traclmdz_from_restart(trs)
+  ENDIF
+
+#ifdef ISO
+        ! initialise les isotopes       
+        write(*,*) 'phyetat0 1069' 
+         CALL phyisoetat0 (snow,run_off_lic_0, &
+     &           xtsnow,xtrun_off_lic_0, &
+     &           Rland_ice)
+#ifdef ISOVERIF 
+      write(*,*) 'phyetat0 1074'
+      if (iso_eau.gt.0) then
+      call iso_verif_egalite_vect2D(  &
+     &           xtsnow,snow, &
+     &           'phyetat0 1101a',niso,klon,nbsrf)
+        do i=1,klon  
+              call iso_verif_egalite(Rland_ice(iso_eau,i),1.0, &
+     &         'phyetat0 1101b')
+         enddo
+      endif
+      write(*,*) 'phyetat0 1102'
+#endif
+#endif
+
+!===========================================
+!  ondes de gravite / relief
+!===========================================
+
+!  ondes de gravite non orographiques
+  IF (ok_gwd_rando) found = &
+       phyetat0_get(du_gwd_rando,"du_gwd_rando","du_gwd_rando",0.)
+  IF (.NOT. ok_hines .AND. ok_gwd_rando) found &
+       = phyetat0_get(du_gwd_front,"du_gwd_front","du_gwd_front",0.)
+
+!  prise en compte du relief sous-maille
+  found=phyetat0_get(zmea,"ZMEA","sub grid orography",0.)
+  found=phyetat0_get(zstd,"ZSTD","sub grid orography",0.)
+  found=phyetat0_get(zsig,"ZSIG","sub grid orography",0.)
+  found=phyetat0_get(zgam,"ZGAM","sub grid orography",0.)
+  found=phyetat0_get(zthe,"ZTHE","sub grid orography",0.)
+  found=phyetat0_get(zpic,"ZPIC","sub grid orography",0.)
+  found=phyetat0_get(zval,"ZVAL","sub grid orography",0.)
+  found=phyetat0_get(zmea,"ZMEA","sub grid orography",0.)
+  found=phyetat0_get(rugoro,"RUGSREL","sub grid orography",0.)
+
+!===========================================
+! Initialize ocean
+!===========================================
+
+  IF ( type_ocean == 'slab' ) THEN
+      CALL ocean_slab_init(phys_tstep, pctsrf)
+      IF (nslay.EQ.1) THEN
+        found=phyetat0_get(tslab,["tslab01","tslab  "],"tslab",0.)
+      ELSE
+          DO i=1,nslay
+            WRITE(str2,'(i2.2)') i
+            found=phyetat0_get(tslab(:,i),"tslab"//str2,"tslab",0.)  
+          ENDDO
+      ENDIF
+      IF (.NOT. found) THEN 
+          PRINT*, "phyetat0: Le champ <tslab> est absent"
+          PRINT*, "Initialisation a tsol_oce"
+          DO i=1,nslay
+              tslab(:,i)=MAX(ftsol(:,is_oce),271.35)
+          ENDDO
+      ENDIF 
+
+      ! Sea ice variables
+      IF (version_ocean == 'sicINT') THEN
+          found=phyetat0_get(tice,"slab_tice","slab_tice",0.)
+          IF (.NOT. found) THEN 
+              PRINT*, "phyetat0: Le champ <tice> est absent"
+              PRINT*, "Initialisation a tsol_sic"
+                  tice(:)=ftsol(:,is_sic)
+          ENDIF 
+          found=phyetat0_get(seaice,"seaice","seaice",0.)
+          IF (.NOT. found) THEN
+              PRINT*, "phyetat0: Le champ <seaice> est absent"
+              PRINT*, "Initialisation a 0/1m suivant fraction glace"
+              seaice(:)=0.
+              WHERE (pctsrf(:,is_sic).GT.EPSFRA)
+                  seaice=917.
+              ENDWHERE
+          ENDIF
+      ENDIF !sea ice INT
+  ENDIF ! Slab        
+
+  if (activate_ocean_skin >= 1) then
+     if (activate_ocean_skin == 2 .and. type_ocean == 'couple') then
+        found = phyetat0_get(delta_sal, "delta_sal", &
+             "ocean-air interface salinity minus bulk salinity", 0.)
+        found = phyetat0_get(delta_sst, "delta_SST", &
+             "ocean-air interface temperature minus bulk SST", 0.)
+        found = phyetat0_get(dter, "dter", &
+             "ocean-air interface temperature minus subskin temperature", 0.)
+        found = phyetat0_get(dser, "dser", &
+             "ocean-air interface salinity minus subskin salinity", 0.)
+        found = phyetat0_get(dt_ds, "dt_ds", "(tks / tkt) * dTer", 0.)
+
+        where (pctsrf(:, is_oce) == 0.)
+           delta_sst = missing_val
+           delta_sal = missing_val
+           dter = missing_val
+           dser = missing_val
+           dt_ds = missing_val
+        end where
+     end if
+     
+     found = phyetat0_get(ds_ns, "dS_ns", "delta salinity near surface", 0.)
+     found = phyetat0_get(dt_ns, "dT_ns", "delta temperature near surface", &
+          0.)
+
+     where (pctsrf(:, is_oce) == 0.)
+        ds_ns = missing_val
+        dt_ns = missing_val
+        delta_sst = missing_val
+        delta_sal = missing_val
+     end where
+  end if
+
+  ! on ferme le fichier
+  CALL close_startphy
+
+  ! Initialize module pbl_surface_mod 
+
+! 994 est trop grand quand OpenMP est activé : on sort du tableau
+!#ifdef ISOVERIF
+!        write(*,*) 'phyetat0 572: snow(994,:)=',snow(994,2)
+!        write(*,*) 'xtsnow(:,994,2)=',xtsnow(:,994,2)
+!#endif
+
+  CALL pbl_surface_init(fder, snow, qsurf, tsoil)
+#ifdef ISO
+  CALL pbl_surface_init_iso(xtsnow,Rland_ice)
+#endif
+
+  ! Initialize module ocean_cpl_mod for the case of coupled ocean
+  IF ( type_ocean == 'couple' ) THEN
+     CALL ocean_cpl_init(phys_tstep, longitude_deg, latitude_deg)
+  ENDIF
+
+!  CALL init_iophy_new(latitude_deg, longitude_deg)
+
+  ! Initilialize module fonte_neige_mod      
+  CALL fonte_neige_init(run_off_lic_0)
+#ifdef ISO
+   CALL fonte_neige_init_iso(xtrun_off_lic_0)
+#endif
+
+END SUBROUTINE phyetat0
+
+END MODULE phyetat0_mod
+
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phyredem.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phyredem.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phyredem.F90	(revision 4482)
@@ -30,5 +30,5 @@
                                 du_gwd_rando, du_gwd_front, u10m, v10m, &
                                 treedrg, solswfdiff, delta_sal, ds_ns, dt_ns, &
-                                delta_sst, ratqs_inter
+                                delta_sst, ratqs_inter, dter, dser, dt_ds
 #ifdef ISO
   USE phys_state_var_mod, ONLY: xtsol, fxtevap,xtrain_fall, xtsnow_fall,     &
@@ -39,5 +39,5 @@
   USE iostart, ONLY: open_restartphy, close_restartphy, enddef_restartphy, put_field, put_var
   USE traclmdz_mod, ONLY : traclmdz_to_restart
-  USE infotrac_phy, ONLY: types_trac, nqtot, tracers, nbtr, niso
+  USE infotrac_phy, ONLY: type_trac, nqtot, tracers, nbtr, niso
 #ifdef ISO
 #ifdef ISOVERIF
@@ -45,5 +45,5 @@
 #endif
 #endif
-  USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send
+  USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send, carbon_cycle_rad, RCO2_glo
   USE indice_sol_mod, ONLY: nbsrf, is_oce, is_sic, is_ter, is_lic, epsfra
   USE surface_data, ONLY: type_ocean, version_ocean
@@ -130,5 +130,10 @@
 
   ! co2_ppm0 : initial value of atmospheric CO2
-  tab_cntrl(16) = co2_ppm0
+  ! tab_cntrl(16) = co2_ppm0
+
+  !  PC -- initial value of RCO2 for the radiation scheme
+  !  tab_cntrl(17) = co2_ppm * 1.0e-06 * RMCO2 / RMD
+  IF (carbon_cycle_rad) tab_cntrl(17) = RCO2_glo
+  !PRINT*, "PC : phyredem RCO2_glo =",RCO2_glo
 
   DO pass=1,2   ! pass=1 netcdf definition ; pass=2 netcdf write
@@ -171,13 +176,7 @@
     CALL put_field(pass,"FSIC", "fraction glace mer", pctsrf(:, is_sic))
 
-    IF(nbsrf>99) THEN
-      PRINT*, "Trop de sous-mailles";  CALL abort_physic("phyredem", "", 1)
-    END IF
-    IF(nsoilmx>99) THEN
-      PRINT*, "Trop de sous-surfaces"; CALL abort_physic("phyredem", "", 1)
-    END IF
-    IF(nsw>99) THEN
-      PRINT*, "Trop de bandes"; CALL abort_physic("phyredem", "", 1)
-    END IF
+    IF(nbsrf  >99) CALL abort_physic("phyredem", "Trop de sous-mailles", 1)
+    IF(nsoilmx>99) CALL abort_physic("phyredem", "Trop de sous-mailles", 1)
+    IF(nsw    >99) CALL abort_physic("phyredem", "Trop de bandes", 1)
 
 !    Surface variables 
@@ -345,5 +344,5 @@
 
 
-    IF (ANY(types_trac == 'co2i') .OR. ANY(types_trac == 'inco')) THEN
+    IF (ANY(type_trac == ['co2i','inco'])) THEN
        IF (carbon_cycle_cpl) THEN
           IF (.NOT. ALLOCATED(co2_send)) THEN
@@ -356,5 +355,5 @@
 
     ! trs from traclmdz_mod
-    ELSE IF (ANY(types_trac == 'lmdz')) THEN
+    ELSE IF (type_trac == 'lmdz') THEN
        CALL traclmdz_to_restart(trs)
        it = 0
@@ -394,4 +393,11 @@
           CALL put_field(pass, "delta_SST", &
                "ocean-air interface temperature minus bulk SST", delta_sst)
+          CALL put_field(pass, "dter", &
+               "ocean-air interface temperature minus subskin temperature", &
+               dter)
+          CALL put_field(pass, "dser", &
+               "ocean-air interface salinity minus subskin salinity", dser)
+          CALL put_field(pass, "dt_ds", &
+               "(tks / tkt) * dTer", dt_ds)
        end if
        
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phys_output_var_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phys_output_var_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/phys_output_var_mod.F90	(revision 4482)
@@ -135,25 +135,17 @@
   ! Ocean-atmosphere interface, subskin ocean and near-surface ocean:
   
-  REAL, ALLOCATABLE, SAVE:: dter(:)
-  ! Temperature variation in the diffusive microlayer, that is
-  ! ocean-air interface temperature minus subskin temperature. In K.
-      
-  REAL, SAVE, ALLOCATABLE:: dser(:)
-  ! Temperature variation in the diffusive microlayer, that is
-  ! subskin temperature minus ocean-air interface temperature. In K.
-
-  REAL, SAVE, ALLOCATABLE:: tkt(:)
+  REAL, SAVE, ALLOCATABLE:: tkt(:) ! (klon)
   ! épaisseur (m) de la couche de diffusion thermique (microlayer)
   ! cool skin thickness
 
-  REAL, SAVE, ALLOCATABLE:: tks(:)
+  REAL, SAVE, ALLOCATABLE:: tks(:) ! (klon)
   ! épaisseur (m) de la couche de diffusion de masse (microlayer)
   
-  REAL, SAVE, ALLOCATABLE:: taur(:) ! momentum flux due to rain, in Pa
-
-  REAL, SAVE, ALLOCATABLE:: sss(:)
+  REAL, SAVE, ALLOCATABLE:: taur(:) ! (klon) momentum flux due to rain, in Pa
+
+  REAL, SAVE, ALLOCATABLE:: sss(:) ! (klon)
   ! bulk salinity of the surface layer of the ocean, in ppt
   
-  !$OMP THREADPRIVATE(dter, dser, tkt, tks, taur, sss)
+  !$OMP THREADPRIVATE(tkt, tks, taur, sss)
 
 CONTAINS
@@ -216,6 +208,6 @@
     IF (ok_gwd_rando) allocate(zustr_gwd_rando(klon), zvstr_gwd_rando(klon))
 
-    if (activate_ocean_skin >= 1) allocate(dter(klon), dser(klon), tkt(klon), &
-         tks(klon), taur(klon), sss(klon))
+    if (activate_ocean_skin >= 1) allocate(tkt(klon), tks(klon), taur(klon), &
+         sss(klon))
 
   END SUBROUTINE phys_output_var_init
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/physiq_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/physiq_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/physiq_mod.F90	(revision 4482)
@@ -39,7 +39,7 @@
     USE ioipsl_getin_p_mod, ONLY : getin_p
     USE indice_sol_mod
-    USE infotrac_phy, ONLY: nqtot, nbtr, nqo, tracers, types_trac, nqCO2
+    USE infotrac_phy, ONLY: nqtot, nbtr, nqo, tracers, type_trac
     USE readTracFiles_mod, ONLY: addPhase
-    USE strings_mod,  ONLY: strIdx, strStack, int2str
+    USE strings_mod,  ONLY: strIdx
     USE iophy
     USE limit_read_mod, ONLY : init_limit_read
@@ -53,7 +53,8 @@
     USE pbl_surface_mod, ONLY : pbl_surface
     USE phyaqua_mod, only: zenang_an
+    USE phyetat0_mod, only: phyetat0
     USE phystokenc_mod, ONLY: offline, phystokenc
     USE phys_cal_mod, only: year_len, mth_len, days_elapsed, jh_1jan, &
-         year_cur, mth_cur,jD_cur, jH_cur, jD_ref, day_cur, hour
+         year_cur, mth_cur,jD_cur, jH_cur, jD_ref, day_cur, hour, calend
 !!  USE phys_local_var_mod, ONLY : a long list of variables
 !!              ==> see below, after "CPP Keys" section
@@ -68,14 +69,19 @@
     USE regr_horiz_time_climoz_m, ONLY: regr_horiz_time_climoz
     USE regr_pr_time_av_m, only: regr_pr_time_av
-    USE surface_data,     ONLY : type_ocean, ok_veget, landice_opt
-    USE time_phylmdz_mod, only: annee_ref, current_time, day_ini, day_ref, &
-          day_step_phy, itau_phy, pdtphys, raz_date, start_time, update_time
+    USE surface_data,     ONLY : type_ocean, ok_veget
+    USE time_phylmdz_mod, only: current_time, itau_phy, pdtphys, raz_date, update_time
     USE tracinca_mod, ONLY: config_inca
     USE tropopause_m,     ONLY: dyn_tropopause
     USE ice_sursat_mod,  ONLY: flight_init, airplane
     USE vampir
-    USE VERTICAL_LAYERS_MOD, ONLY: aps,bps, ap, bp
     USE write_field_phy
+#ifdef CPP_XIOS
+    USE wxios, ONLY: g_ctx, wxios_set_context
+#endif
+    USE atke_turbulence_ini_mod, ONLY : atke_ini
+    USE lscp_ini_mod, ONLY : lscp_ini
     USE lscp_mod, ONLY : lscp
+    USE wake_ini_mod, ONLY : wake_ini
+    USE yamada_ini_mod, ONLY : yamada_ini
     USE thermcell_ini_mod, ONLY : thermcell_ini
 
@@ -96,8 +102,16 @@
 
 
+#ifdef INCA
+    USE geometry_mod,      ONLY: longitude, latitude, boundslon, boundslat, ind_cell_glo
+    USE time_phylmdz_mod,  ONLY: ndays
+    USE infotrac_phy,      ONLY: nqCO2
+#endif
 #ifdef REPROBUS
-    USE CHEM_REP, ONLY : Init_chem_rep_xjour, &
-         d_q_rep,d_ql_rep,d_qi_rep,ptrop,ttrop, &
-         ztrop, gravit,itroprep, Z1,Z2,fac,B
+    USE chem_rep, ONLY: Init_chem_rep_xjour, d_q_rep, d_ql_rep, d_qi_rep, &
+                        ptrop, ttrop, ztrop, gravit, itroprep, Z1, Z2, fac, B
+#endif
+#if defined INCA || defined REPROBUS
+    USE time_phylmdz_mod,    ONLY: annee_ref, day_ini, day_ref, start_time
+    USE vertical_layers_mod, ONLY: aps, bps, ap, bp
 #endif
 
@@ -105,5 +119,5 @@
 #ifdef CPP_RRTM
     USE YOERAD, ONLY : NRADLP
-    USE YOESW, ONLY : RSUN
+!    USE YOESW, ONLY : RSUN
 #endif
 
@@ -115,6 +129,7 @@
 
 #ifdef CPP_XIOS
-    USE xios, ONLY: xios_update_calendar, xios_context_finalize, &
-            xios_get_field_attr, xios_field_is_active
+    USE xios, ONLY: xios_update_calendar, xios_context_finalize
+    USE xios, ONLY: xios_get_field_attr, xios_field_is_active, xios_context
+    USE xios, ONLY: xios_set_current_context
     USE wxios, ONLY: missing_val, missing_val_omp
 #endif
@@ -179,6 +194,6 @@
        d_t_ajsb,d_q_ajsb, &
        d_t_ajs,d_q_ajs,d_u_ajs,d_v_ajs, &
-       d_t_ajs_w,d_q_ajs_w, &
-       d_t_ajs_x,d_q_ajs_x, &
+!       d_t_ajs_w,d_q_ajs_w, &
+!       d_t_ajs_x,d_q_ajs_x, &
        !
        d_t_eva,d_q_eva,d_ql_eva,d_qi_eva, &
@@ -193,5 +208,5 @@
        d_ts, &
        !
-       d_t_oli,d_u_oli,d_v_oli, &
+!       d_t_oli,d_u_oli,d_v_oli, &
        d_t_oro,d_u_oro,d_v_oro, &
        d_t_oro_gw,d_u_oro_gw,d_v_oro_gw, &
@@ -312,4 +327,8 @@
        sij, &
        !
+       rneblsvol, &
+       zqsatl, zqsats, &
+       qclr, qcld, qss, qvc, rnebclr, rnebss, gamma_ss, &
+       Tcontr, qcontr, qcontr2, fcontrN, fcontrP, &
        cldemi,  &
        cldfra, cldtau, fiwc,  &
@@ -365,5 +384,4 @@
 #endif
        !
-
 
     IMPLICIT NONE
@@ -578,5 +596,4 @@
     !
     !
-    INTEGER debug
     INTEGER n
     !ym      INTEGER npoints
@@ -635,5 +652,5 @@
     ! Upmost level reached by deep convection and related variable (jyg)
     !
-    INTEGER izero
+!    INTEGER izero
     INTEGER k_upper_cv
     !------------------------------------------------------------------
@@ -813,5 +830,4 @@
     REAL beta_prec_fisrt(klon,klev) ! taux de conv de l'eau cond (fisrt)
     ! RomP <<<
-    REAL          :: calday
 
     !IM cf FH pour Tiedtke 080604
@@ -869,5 +885,4 @@
     !C      EXTERNAL o3cm      ! initialiser l'ozone
     EXTERNAL orbite    ! calculer l'orbite terrestre
-    EXTERNAL phyetat0  ! lire l'etat initial de la physique
     EXTERNAL phyredem  ! ecrire l'etat de redemarrage de la physique
     EXTERNAL suphel    ! initialiser certaines constantes
@@ -934,5 +949,5 @@
     real zqsat(klon,klev)
     !
-    INTEGER i, k, iq, j, nsrf, ll, l, itr
+    INTEGER i, k, iq, nsrf, l, itr
 #ifdef ISO
     real zxt_apres(ntraciso,klon)
@@ -1056,4 +1071,5 @@
 
     REAL picefra(klon,klev)
+    REAL zrel_oro(klon)
     !IM cf. AM 081204 END
     !
@@ -1265,4 +1281,5 @@
 
 #ifdef INCA
+    REAL :: calday, zxsnow_dummy(klon)
     ! set de variables utilisees pour l'initialisation des valeurs provenant de INCA
     REAL, DIMENSION(klon,klev,naero_grp,nbands) :: init_tauinca
@@ -1313,5 +1330,9 @@
     phys_tstep=NINT(pdtphys)
 #ifdef CPP_XIOS
-    IF (.NOT. debut .AND. is_omp_master) CALL xios_update_calendar(itap+1)
+! switch to XIOS LMDZ physics context 
+    IF (.NOT. debut .AND. is_omp_master) THEN
+       CALL wxios_set_context()
+       CALL xios_update_calendar(itap+1)
+    ENDIF
 #endif
 
@@ -1403,4 +1424,16 @@
           WRITE (lunout, *) ' ok_ice_sursat=y requires 4 H2O tracers ', &
                '(H2O_g, H2O_l, H2O_s, H2O_r) but nqo=', nqo, '. Might as well stop here.'
+          abort_message='see above'
+          CALL abort_physic(modname,abort_message,1)
+       ENDIF
+
+       IF (ok_plane_h2o.AND..NOT.ok_ice_sursat) THEN
+          WRITE (lunout, *) ' ok_plane_h2o=y requires ok_ice_sursat=y '
+          abort_message='see above'
+          CALL abort_physic(modname,abort_message,1)
+       ENDIF
+
+       IF (ok_plane_contrail.AND..NOT.ok_ice_sursat) THEN
+          WRITE (lunout, *) ' ok_plane_contrail=y requires ok_ice_sursat=y '
           abort_message='see above'
           CALL abort_physic(modname,abort_message,1)
@@ -1539,5 +1572,5 @@
        tau_overturning_th(:)=0.
 
-       IF (ANY(types_trac == 'inca') .OR. ANY(types_trac == 'inco')) THEN
+       IF (ANY(type_trac == ['inca','inco'])) THEN
           ! jg : initialisation jusqu'au ces variables sont dans restart
           ccm(:,:,:) = 0.
@@ -1847,13 +1880,20 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        ! Nouvelle initialisation pour le rayonnement RRTM
-       !
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
        CALL iniradia(klon,klev,paprs(1,1:klev+1))
 
-
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+       CALL wake_ini(rg,rd,rv,prt_level)
+       CALL yamada_ini(klon,lunout,prt_level)
+       CALL atke_ini(prt_level, lunout, RG, RD, RPI, RCPD)
        CALL thermcell_ini(iflag_thermals,prt_level,tau_thermals,lunout, &
    &    RG,RD,RCPD,RKAPPA,RLVTT,RETV)
+       IF (ok_new_lscp) then
+           CALL lscp_ini(pdtphys,ok_ice_sursat)
+       endif
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
        !
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -2151,5 +2191,5 @@
        !c         ENDDO
        !
-       IF (ANY(types_trac == 'inca') .OR. ANY(types_trac == 'inco')) THEN  ! ModThL
+       IF (ANY(type_trac == ['inca','inco'])) THEN ! ModThL
 #ifdef INCA
           CALL VTe(VTphysiq)
@@ -2158,31 +2198,64 @@
           WRITE(lunout,*) 'initial time chemini', days_elapsed, calday
 
-          CALL chemini(  &
-               rg, &
-               ra, &
-               cell_area, &
-               latitude_deg, &
-               longitude_deg, &
-               presnivs, &
-               calday, &
-               klon, &
-               nqtot, &
-               nqo+nqCO2, &
-               pdtphys, &
-               annee_ref, &
-               year_cur, &
-               day_ref,  &
-               day_ini, &
-               start_time, &
-               itau_phy, &
-               date0, &
-               io_lon, &
-               io_lat, &
-               chemistry_couple, &
-               init_source, &
-               init_tauinca, &
-               init_pizinca, &
-               init_cginca, &
-               init_ccminca)
+          call init_const_lmdz( &
+          ndays, nbsrf, is_oce,is_sic, is_ter,is_lic, calend, &
+          config_inca)
+
+          CALL init_inca_geometry( & 
+               longitude, latitude, &
+               boundslon, boundslat, &
+               cell_area, ind_cell_glo) 
+
+          if (grid_type==unstructured) THEN 
+             CALL chemini(  pplay, &
+                  nbp_lon, nbp_lat, &
+                  latitude_deg, &
+                  longitude_deg, &
+                  presnivs, &
+                  calday, &
+                  klon, &
+                  nqtot, &
+                  nqo+nqCO2, &
+                  pdtphys, &
+                  annee_ref, &
+                  year_cur, &
+                  day_ref,  &
+                  day_ini, &
+                  start_time, &
+                  itau_phy, &
+                  date0, &
+                  chemistry_couple, &
+                  init_source, &
+                  init_tauinca, &
+                  init_pizinca, &
+                  init_cginca, &
+                  init_ccminca)
+          ELSE
+             CALL chemini(  pplay, &
+                  nbp_lon, nbp_lat, &
+                  latitude_deg, &
+                  longitude_deg, &
+                  presnivs, &
+                  calday, &
+                  klon, &
+                  nqtot, &
+                  nqo+nqCO2, &
+                  pdtphys, &
+                  annee_ref, &
+                  year_cur, &
+                  day_ref,  &
+                  day_ini, &
+                  start_time, &
+                  itau_phy, &
+                  date0, &
+                  chemistry_couple, &
+                  init_source, &
+                  init_tauinca, &
+                  init_pizinca, &
+                  init_cginca, &
+                  init_ccminca, &
+                  io_lon, &
+                  io_lat)
+          ENDIF
 
 
@@ -2200,5 +2273,5 @@
        ENDIF
        !
-       IF (ANY(types_trac == 'repr')) THEN
+       IF (type_trac == 'repr') THEN
 #ifdef REPROBUS
           CALL chemini_rep(  &
@@ -2286,4 +2359,5 @@
 
 
+
     ENDIF
     !
@@ -2316,5 +2390,5 @@
 
     ! Update time and other variables in Reprobus
-    IF (ANY(types_trac == 'repr')) THEN
+    IF (type_trac == 'repr') THEN
 #ifdef REPROBUS
        CALL Init_chem_rep_xjour(jD_cur-jD_ref+day_ref)
@@ -2390,9 +2464,11 @@
           ql_seri(i,k) = qx(i,k,iliq)
           !CR: ATTENTION, on rajoute la variable glace
-          IF (nqo.eq.2) THEN
+          IF (nqo.EQ.2) THEN             !--vapour and liquid only
              qs_seri(i,k) = 0.
-          ELSE IF (nqo.eq.3) THEN
+             rneb_seri(i,k) = 0.
+          ELSE IF (nqo.EQ.3) THEN        !--vapour, liquid and ice
              qs_seri(i,k) = qx(i,k,isol)
-          ELSE IF (nqo.eq.4) THEN
+             rneb_seri(i,k) = 0.
+          ELSE IF (nqo.EQ.4) THEN        !--vapour, liquid, ice and rneb
              qs_seri(i,k) = qx(i,k,isol)
              rneb_seri(i,k) = qx(i,k,irneb)
@@ -2606,7 +2682,7 @@
              DO i = 1, klon
               if (q_seri(i,k).gt.3e-3) then
-              call iso_verif_positif(deltaD(xt_seri(iso_eau,i,k) &
+              call iso_verif_positif(deltaD(xt_seri(iso_HDO,i,k) &
      &           /q_seri(i,k))+400.0,'physiq 2045a')
-              call iso_verif_positif(deltaD(xt_ancien(iso_eau,i,k) &
+              call iso_verif_positif(deltaD(xt_ancien(iso_HDO,i,k) &
      &            /q_ancien(i,k))+400.0,'physiq 2045b')
 !              call iso_verif_egalite_choix(d_xt_dyn(iso_hdo,i,k) &
@@ -2658,6 +2734,6 @@
        ! !! RomP >>>   td dyn traceur
        IF (nqtot > nqo) d_tr_dyn(:,:,:)= 0.0
+       ! !! RomP <<<
        d_rneb_dyn(:,:)=0.0
-       ! !! RomP <<<
        ancien_ok = .TRUE.
     ENDIF
@@ -3526,5 +3602,5 @@
            endif ! if ((iso_HDO.gt.0).and.(iso_O18.gt.0)) then
            if ((iso_O17.gt.0).and.(iso_O18.gt.0)) then
-             if ((q_seri(i,k).gt.ridicule).and.(l.lt.nlevmaxO17)) then
+             if ((q_seri(i,k).gt.ridicule).and.(k.lt.nlevmaxO17)) then
               call iso_verif_aberrant_o17(xt_seri(iso_o17,i,k) &
      &           /q_seri(i,k),xt_seri(iso_o18,i,k) &
@@ -3582,5 +3658,5 @@
           !
           !>jyg
-          IF (ANY(types_trac == 'repr')) THEN
+          IF (type_trac == 'repr') THEN
              nbtr_tmp=ntra
           ELSE
@@ -4608,15 +4684,22 @@
     IF (ok_new_lscp) THEN
 
-    CALL lscp(phys_tstep,missing_val,paprs,pplay, &
+    !--mise à jour de flight_m et flight_h2o dans leur module
+    IF (ok_plane_h2o .OR. ok_plane_contrail) THEN
+      CALL airplane(debut,pphis,pplay,paprs,t_seri)
+    ENDIF
+
+    CALL lscp(klon,klev,phys_tstep,missing_val,paprs,pplay, &
          t_seri, q_seri,ptconv,ratqs, &
-         d_t_lsc, d_q_lsc, d_ql_lsc, d_qi_lsc, rneb, rneb_seri, & 
+         d_t_lsc, d_q_lsc, d_ql_lsc, d_qi_lsc, rneb, rneblsvol, rneb_seri, &
          cldliq, picefra, rain_lsc, snow_lsc, &
-         pfrac_impa, pfrac_nucl, pfrac_1nucl, &
          frac_impa, frac_nucl, beta_prec_fisrt, &
          prfl, psfl, rhcl,  &
          zqasc, fraca,ztv,zpspsk,ztla,zthl,iflag_cld_th, &
-         iflag_ice_thermo, ok_ice_sursat)
+         iflag_ice_thermo, ok_ice_sursat, zqsatl, zqsats, &
+         qclr, qcld, qss, qvc, rnebclr, rnebss, gamma_ss, &
+         Tcontr, qcontr, qcontr2, fcontrN, fcontrP )
 
     ELSE
+
     CALL fisrtilp(phys_tstep,paprs,pplay, &
          t_seri, q_seri,ptconv,ratqs, &
@@ -4690,5 +4773,5 @@
        ENDDO
     ENDDO
-    IF (nqo==3) THEN
+    IF (nqo >= 3) THEN
     DO k = 1, klev
        DO i = 1, klon
@@ -5112,5 +5195,5 @@
     ENDDO
 
-    IF (ANY(types_trac == 'inca') .OR. ANY(types_trac == 'inco')) THEN ! ModThL
+    IF (ANY(type_trac == ['inca','inco'])) THEN ! ModThL
 #ifdef INCA
        CALL VTe(VTphysiq)
@@ -5168,5 +5251,5 @@
 #endif
     ENDIF !type_trac = inca or inco
-    IF (ANY(types_trac == 'repr')) THEN
+    IF (type_trac == 'repr') THEN
 #ifdef REPROBUS
     !CALL chemtime_rep(itap+itau_phy-1, date0, dtime, itap)
@@ -5497,7 +5580,5 @@
           ! 
           !--interactive CO2 in ppm from carbon cycle
-          IF (carbon_cycle_rad.AND..NOT.debut) THEN
-            RCO2=RCO2_glo
-          ENDIF
+          IF (carbon_cycle_rad) RCO2=RCO2_glo
           !
           IF (prt_level .GE.10) THEN
@@ -5555,16 +5636,4 @@
  
 #ifndef CPP_XIOS
-          !--OB 30/05/2016 modified 21/10/2016
-          !--here we return swaero_diag and dryaod_diag to FALSE
-          !--and histdef will switch it back to TRUE if necessary
-          !--this is necessary to get the right swaero at first step
-          !--but only in the case of no XIOS as XIOS is covered elsewhere 
-          IF (debut) swaerofree_diag = .FALSE.
-          IF (debut) swaero_diag = .FALSE.
-          IF (debut) dryaod_diag = .FALSE.
-          !--IM 15/09/2017 here we return ok_4xCO2atm to FALSE
-          !--as for swaero_diag, see above
-          IF (debut) ok_4xCO2atm = .FALSE.
-
           !
           !IM 2eme calcul radiatif pour le cas perturbe ou au moins un
@@ -5734,6 +5803,11 @@
        DO i=1,klon
           itest(i)=0
-          !        IF ((zstd(i).gt.10.0)) THEN
-          IF (((zpic(i)-zmea(i)).GT.100.).AND.(zstd(i).GT.10.0)) THEN
+          zrel_oro(i)=zstd(i)/(max(zsig(i),1.E-8)*sqrt(cell_area(i)))
+          !zrel_oro: relative mountain height wrt relief explained by mean slope
+          ! -> condition on zrel_oro can deactivate the drag on tilted planar terrains
+          !    such as ice sheets (work by V. Wiener)
+          ! zpmm_orodr_t and zstd_orodr_t are activation thresholds set by F. Lott to 
+          ! earn computation time but they are not physical.
+          IF (((zpic(i)-zmea(i)).GT.zpmm_orodr_t).AND.(zstd(i).GT.zstd_orodr_t).AND.(zrel_oro(i).LE.zrel_oro_t)) THEN
              itest(i)=1
              igwd=igwd+1
@@ -5788,5 +5862,9 @@
        DO i=1,klon
           itest(i)=0
-          IF ((zpic(i)-zmea(i)).GT.100.) THEN
+          !zrel_oro: relative mountain height wrt relief explained by mean slope
+          ! -> condition on zrel_oro can deactivate the lifting on tilted planar terrains
+          !    such as ice sheets (work by V. Wiener)
+          zrel_oro(i)=zstd(i)/(max(zsig(i),1.E-8)*sqrt(cell_area(i)))
+          IF (((zpic(i)-zmea(i)).GT.zpmm_orolf_t).AND.(zrel_oro(i).LE.zrel_oro_t)) THEN
              itest(i)=1
              igwd=igwd+1
@@ -6004,5 +6082,5 @@
 ! car on peut s'attendre a ce que les petites echelles produisent aussi de la TKE
 ! Mais attention, cela ne va pas dans le sens de la conservation de l'energie! 
-          IF (zstd(i).GT.1.0) THEN
+          IF ((zstd(i).GT.1.0).AND.(zrel_oro(i).LE.zrel_oro_t)) THEN
              itest(i)=1
              igwd=igwd+1
@@ -6016,5 +6094,5 @@
        DO i=1,klon
           itest(i)=0
-        IF (((zpic(i)-zmea(i)).GT.100.).AND.(zstd(i).GT.10.0)) THEN
+        IF (((zpic(i)-zmea(i)).GT.zpmm_orodr_t).AND.(zstd(i).GT.zstd_orodr_t).AND.(zrel_oro(i).LE.zrel_oro_t)) THEN
              itest(i)=1
              igwd=igwd+1
@@ -6264,5 +6342,5 @@
     !
 
-    IF (ANY(types_trac=='repr')) THEN
+    IF (type_trac=='repr') THEN
 !MM pas d'impact, car on recupere q_seri,tr_seri,t_seri via phys_local_var_mod
 !MM                               dans Reprobus
@@ -6275,5 +6353,5 @@
     ELSE
        sh_in(:,:) = qx(:,:,ivap)
-       IF (nqo .EQ. 3) THEN 
+       IF (nqo >= 3) THEN 
           ch_in(:,:) = qx(:,:,iliq) + qx(:,:,isol)
        ELSE 
@@ -6362,17 +6440,16 @@
     ! Calculer le transport de l'eau et de l'energie (diagnostique)
     !
-    CALL transp (paprs,zxtsol, &
-         t_seri, q_seri, ql_seri, qs_seri, u_seri, v_seri, zphi, &
-         ve, vq, ue, uq, vwat, uwat)
+    CALL transp (paprs,zxtsol, t_seri, q_seri, ql_seri, qs_seri, u_seri, v_seri, zphi, &
+                 ue, ve, uq, vq, uwat, vwat)
     !
     !IM global posePB BEG
     IF(1.EQ.0) THEN
        !
-       CALL transp_lay (paprs,zxtsol, &
-            t_seri, q_seri, u_seri, v_seri, zphi, &
+       CALL transp_lay (paprs,zxtsol, t_seri, q_seri, u_seri, v_seri, zphi, &
             ve_lay, vq_lay, ue_lay, uq_lay)
        !
     ENDIF !(1.EQ.0) THEN
     !IM global posePB END
+    !
     ! Accumuler les variables a stocker dans les fichiers histoire:
     !
@@ -6385,5 +6462,5 @@
     d_t_ec(:,:)=0.
     forall (k=1: nbp_lev) exner(:, k) = (pplay(:, k)/paprs(:,1))**RKAPPA
-    CALL ener_conserv(klon,klev,pdtphys,u,v,t,qx(:,:,ivap),qx(:,:,iliq),qx(:,:,isol), &
+    CALL ener_conserv(klon,klev,pdtphys,u,v,t,qx,ivap,iliq,isol, &
          u_seri,v_seri,t_seri,q_seri,ql_seri,qs_seri,pbl_tke(:,:,is_ave)-tke0(:,:), &
          zmasse,exner,d_t_ec)
@@ -6430,5 +6507,5 @@
 #endif
     !
-    IF (ANY(types_trac == 'inca') .OR. ANY(types_trac == 'inco')) THEN
+    IF (ANY(type_trac == ['inca','inco'])) THEN
 #ifdef INCA
        CALL VTe(VTphysiq)
@@ -6447,5 +6524,5 @@
             pphis, &
             zx_rh, &
-            aps, bps, ap, bp)
+            aps, bps, ap, bp, lafin)
 
        CALL VTe(VTinca)
@@ -6454,4 +6531,9 @@
     ENDIF
 
+    IF (type_trac == 'repr') THEN
+#ifdef REPROBUS
+        CALL coord_hyb_rep(paprs, pplay, aps, bps, ap, bp, cell_area)
+#endif
+    ENDIF
 
     !
@@ -6477,9 +6559,9 @@
           d_qx(i,k,iliq) = ( ql_seri(i,k) - qx(i,k,iliq) ) / phys_tstep
           !CR: on ajoute le contenu en glace
-          IF (nqo.ge.3) THEN
+          IF (nqo >= 3) THEN
              d_qx(i,k,isol) = ( qs_seri(i,k) - qx(i,k,isol) ) / phys_tstep
           ENDIF
           !--ice_sursat: nqo=4, on ajoute rneb
-          IF (nqo.eq.4) THEN
+          IF (nqo == 4) THEN
              d_qx(i,k,irneb) = ( rneb_seri(i,k) - qx(i,k,irneb) ) / phys_tstep
           ENDIF
@@ -6503,11 +6585,5 @@
       enddo ! DO k = 1, klev
     enddo !do ixt=1,ntraciso
-!#ifdef ISOVERIF
-!        write(*,*) 'physiq 6120: d_qx(1,1,:)=',d_qx(1,1,:)
-!        write(*,*) 'qx(1,1,:)=',qx(1,1,:)
-!        write(*,*) 'xt_seri(:,1,1)=',xt_seri(:,1,1)
-!#endif
-#endif
-! #ifdef ISO
+#endif
     ! DC: All iterations are cycled if nqtot==nqo, so no nqtot>nqo condition required
     itr = 0
@@ -6569,4 +6645,5 @@
     ql_ancien(:,:) = ql_seri(:,:)
     qs_ancien(:,:) = qs_seri(:,:)
+    rneb_ancien(:,:) = rneb_seri(:,:)
 #ifdef ISO
     xt_ancien(:,:,:)=xt_seri(:,:,:)
@@ -6828,4 +6905,13 @@
 #ifdef CPP_XIOS
        IF (is_omp_master) CALL xios_context_finalize
+
+#ifdef INCA
+       if (type_trac == 'inca') then 
+          IF (is_omp_master .and. grid_type==unstructured) THEN 
+             CALL finalize_inca
+          ENDIF
+       endif
+#endif
+
 #endif
        WRITE(lunout,*) ' physiq fin, nombre de steps ou cvpas = 1 : ', Ncvpaseq1
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_land_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_land_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_land_mod.F90	(revision 4482)
@@ -30,7 +30,5 @@
     USE dimphy
     USE surface_data, ONLY    : ok_veget
-! >> PC
     USE carbon_cycle_mod 
-! << PC
 
     ! See comments in each module surf_land_orchidee_xxx for compatiblity with ORCHIDEE
@@ -51,5 +49,11 @@
     USE surf_land_orchidee_nounstruct_mod
 #else
+#if ORCHIDEE_NOLIC
+    ! Compilation with cpp key ORCHIDEE_NOLIC
+    USE surf_land_orchidee_nolic_mod
+#else
+    ! Default version#else
     USE surf_land_orchidee_mod
+#endif
 #endif
 #endif
@@ -67,8 +71,6 @@
 #endif
 #endif
-
-! >> PC
+    
     USE print_control_mod, ONLY: lunout
-! << PC
 
     INCLUDE "dimsoil.h"
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_land_orchidee_nolic_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_land_orchidee_nolic_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_land_orchidee_nolic_mod.F90	(revision 4482)
@@ -0,0 +1,1 @@
+link ../phylmd/surf_land_orchidee_nolic_mod.F90
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_landice_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_landice_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_landice_mod.F90	(revision 4482)
@@ -144,4 +144,5 @@
     INTEGER                  :: i,j,nt
     REAL, DIMENSION(klon)    :: fqfonte,ffonte
+    REAL, DIMENSION(klon)    :: run_off_lic_frac
 #ifdef ISO       
       real, parameter :: t_coup = 273.15
@@ -484,8 +485,15 @@
 ! Send run-off on land-ice to coupler if coupled ocean.
 ! run_off_lic has been calculated in fonte_neige or surf_inlandsis
-!
-!****************************************************************************************
-    IF (type_ocean=='couple') THEN
-       CALL cpl_send_landice_fields(itime, knon, knindex, run_off_lic)
+! If landice_opt>=2, corresponding call is done from surf_land_orchidee
+!****************************************************************************************
+    IF (type_ocean=='couple' .AND. landice_opt .LT. 2) THEN
+       ! Compress fraction where run_off_lic is active (here all pctsrf(is_lic))
+       run_off_lic_frac(:)=0.0
+       DO j = 1, knon
+          i = knindex(j)
+          run_off_lic_frac(j) = pctsrf(i,is_lic)
+       ENDDO
+       
+       CALL cpl_send_landice_fields(itime, knon, knindex, run_off_lic, run_off_lic_frac)
     ENDIF
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_ocean_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_ocean_mod.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/surf_ocean_mod.F90	(revision 4482)
@@ -20,6 +20,6 @@
        z0m, z0h, SFRWL, alb_dir_new, alb_dif_new, evap, fluxsens, fluxlat, & 
        tsurf_new, dflux_s, dflux_l, lmt_bils, &
-       flux_u1, flux_v1, delta_sst, delta_sal, ds_ns, dt_ns, dter, dser, tkt, tks, &
-       taur, sss &
+       flux_u1, flux_v1, delta_sst, delta_sal, ds_ns, dt_ns, dter, dser, &
+       dt_ds, tkt, tks, taur, sss &
 #ifdef ISO
         &       ,xtprecip_rain, xtprecip_snow,xtspechum,Roce, &
@@ -114,4 +114,16 @@
     ! minus foundation temperature. (Can be negative.) In K.
 
+    REAL, intent(inout):: dter(:) ! (knon)
+    ! Temperature variation in the diffusive microlayer, that is
+    ! ocean-air interface temperature minus subskin temperature. In
+    ! K.
+
+    REAL, intent(inout):: dser(:) ! (knon)
+    ! Salinity variation in the diffusive microlayer, that is
+    ! ocean-air interface salinity minus subskin salinity. In ppt.
+
+    real, intent(inout):: dt_ds(:) ! (knon)
+    ! (tks / tkt) * dTer, in K
+
     ! Output variables
     !**************************************************************************
@@ -129,13 +141,4 @@
     REAL, DIMENSION(klon), INTENT(OUT)       :: flux_u1, flux_v1
 
-    REAL, intent(out):: dter(:) ! (knon)
-    ! Temperature variation in the diffusive microlayer, that is
-    ! ocean-air interface temperature minus subskin temperature. In
-    ! K.
-
-    REAL, intent(out):: dser(:) ! (knon)
-    ! Salinity variation in the diffusive microlayer, that is
-    ! ocean-air interface salinity minus subskin salinity. In ppt.
-
     REAL, intent(out):: tkt(:) ! (knon)
     ! épaisseur (m) de la couche de diffusion thermique (microlayer)
@@ -152,4 +155,5 @@
     ! defined for subscripts 1:knon, but we have to declare it with
     ! size klon because of the coupling machinery.)
+
 #ifdef ISO
     REAL, DIMENSION(ntraciso,klon), INTENT(out)        :: xtevap ! isotopes in surface evaporation flux 
@@ -172,5 +176,5 @@
     real s_int(knon) ! ocean-air interface salinity, in ppt
 
-    !******************************************************************************
+    !**************************************************************************
 
 #ifdef ISO
@@ -213,7 +217,5 @@
     ENDIF
 
-
     rhoa = PS(:KNON) / (Rd * temp_air(:knon) * (1. + retv * spechum(:knon)))
-
     !******************************************************************************
     ! Switch according to type of ocean (couple, slab or forced)
@@ -232,5 +234,5 @@
             qsurf, evap, fluxsens, fluxlat, flux_u1, flux_v1, &
             tsurf_new, dflux_s, dflux_l, sens_prec_liq, sss, delta_sal, rhoa, &
-            delta_sst)
+            delta_sst, dTer, dSer, dt_ds)
 
     CASE('slab')
@@ -376,7 +378,11 @@
        delta_sst = t_int - tsurf_new(:knon)
        delta_sal = s_int - sss(:knon)
-       if (activate_ocean_skin >= 2) tsurf_new(:knon) = t_int
+
+       if (activate_ocean_skin == 2) then
+          tsurf_new(:knon) = t_int
+          if (type_ocean == 'couple') dt_ds = (tks / tkt) * dter
+       end if
     end if
-
+    
   END SUBROUTINE surf_ocean
   !****************************************************************************
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/thermcell_down.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/thermcell_down.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/thermcell_down.F90	(revision 4482)
@@ -0,0 +1,1 @@
+link ../phylmd/thermcell_down.F90
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/wake.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/wake.F90	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/wake.F90	(revision 4482)
@@ -2550,5 +2550,5 @@
     d_deltaqw, sigmaw, d_sigmaw, alpha)
   ! ------------------------------------------------------
-  ! Dtermination du coefficient alpha tel que les tendances
+  ! D\'etermination du coefficient alpha tel que les tendances
   ! corriges alpha*d_G, pour toutes les grandeurs G, correspondent
   ! a une humidite positive dans la zone (x) et dans la zone (w).
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/wake_ini_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/wake_ini_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/wake_ini_mod.F90	(revision 4482)
@@ -0,0 +1,1 @@
+link ../phylmd/wake_ini_mod.F90
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/yamada_ini_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/yamada_ini_mod.F90	(revision 4482)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmdiso/yamada_ini_mod.F90	(revision 4482)
@@ -0,0 +1,1 @@
+link ../phylmd/yamada_ini_mod.F90
Index: LMDZ6/branches/LMDZ_ECRad/makelmdz
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/makelmdz	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/makelmdz	(revision 4482)
@@ -111,7 +111,8 @@
 [-prod / -dev / -debug]    : compilation mode production (default) / developement / debug
 [-c false/MPI1/MPI2]       : coupling with ocean model : MPI1/MPI2/false (default: false)
-[-v false/orchidee2.0/orchidee1.9/true] : version of the vegetation model to include (default: false)
+[-v false/orchideetrunk/orchidee2.1/orchidee2.0/orchidee1.9] : version of the vegetation model to include (default: false)
           false       : no vegetation model
-          orchidee2.1 : compile using ORCHIDEE 2.1 (or more recent version)
+          orchideetrunk : compile using ORCHIDEE trunk from revision 7757 or higher
+          orchidee2.1 : compile using ORCHIDEE 2.1 until 4.1 included or until revision 7757 on the trunk
           orchidee2.0 : compile using ORCHIDEE 2.0 (or more recent version)
           orchidee1.9 : compile using ORCHIDEE up to the version including OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6
@@ -123,5 +124,5 @@
 [-inlandsis true/false]  : compile with/without inlandsis package (default: false)
 [-rrtm true/false]    : compile with/without rrtm package (default: false)
-[-rad old/rrtm/ecrad]    : compile with old/rrtm/ecrad radiatif code (default: old)
+[-rad oldrad/rrtm/ecrad]    : compile with oldrad/rrtm/ecrad radiatif code (default: oldrad)
 [-dust true/false]    : compile with/without the dust package from Boucher et al. (default: false)
 [-strataer true/false]    : compile with/without the strat aer package from Boucher et al. (default: false)
@@ -195,5 +196,5 @@
 
       "-rrtm")
-          rrtm="$2" ; if [ "$2" = "false" ] ; then rad="old" ; else rad="rrtm" ; fi ; shift ; shift ;;
+          rrtm="$2" ; if [ "$2" = "false" ] ; then rad="oldrad" ; else rad="rrtm" ; fi ; shift ; shift ;;
 
       "-rad")
@@ -373,7 +374,7 @@
 then
    CPP_KEY="$CPP_KEY INCA"
-   INCLUDE="$INCLUDE -I${INCA_INCDIR}"
-   LIB="$LIB -L${INCA_LIBDIR} -lchimie"
-   libchimie=" -L${INCA_LIBDIR} -lchimie"
+   INCLUDE="$INCLUDE ${INCA_INCDIR}"
+   LIB="$LIB ${INCA_LIBDIR} ${INCA_LIB}"
+   libchimie=" ${INCA_LIBDIR} ${INCA_LIB}"
 fi
 
@@ -381,6 +382,6 @@
 then
    CPP_KEY="$CPP_KEY CPP_COUPLE"
-   INCLUDE="$INCLUDE -I${OASIS_INCDIR}"
-   LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.${couple} -lmpp_io"
+   INCLUDE="$INCLUDE ${OASIS_INCDIR}"
+   LIB="$LIB ${OASIS_LIBDIR} ${OASIS_LIB}"
 fi
 
@@ -442,8 +443,8 @@
 
 #==============================================================================
-if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" -o "$veget" = "orchidee2.1" ]
-then
-
-   INCLUDE="${INCLUDE} -I${ORCH_INCDIR}"
+if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" -o "$veget" = "orchidee2.1" -o "$veget" = "orchideetrunk" ]
+then
+
+   INCLUDE="${INCLUDE} ${ORCH_INCDIR}"
    CPP_KEY="$CPP_KEY CPP_VEGET"
 # temporary, for Orchidee versions 1.9.* (before openmp activation)
@@ -452,17 +453,20 @@
    fi
    if [[ "$veget" == "orchidee2.0" ]] ; then
-      orch_libs="sechiba parameters stomate parallel orglob orchidee"
+      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob -lorchidee"
       CPP_KEY="$CPP_KEY ORCHIDEE_NOUNSTRUCT"
    elif [[ "$veget" == "orchidee2.1" ]] ; then
-      orch_libs="sechiba parameters stomate parallel orglob orchidee"
+      CPP_KEY="$CPP_KEY ORCHIDEE_NOLIC"
+      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob -lorchidee"
+   elif [[ "$veget" == "orchideetrunk" ]] ; then
+      orch_libs="-lorchidee"
    else
-      orch_libs="sechiba parameters stomate parallel orglob"
+      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob"
    fi
-   LIB="${LIB} -L${ORCH_LIBDIR}"
-   for lib in ${orch_libs} ; do
-      if [ -f ${ORCH_LIBDIR}/lib${LIBPREFIX}$lib.a ] ; then
-         LIB="${LIB} -l${LIBPREFIX}$lib "
-      fi
-   done
+   LIB="${LIB} ${ORCH_LIBDIR} ${orch_libs}"
+#   for lib in ${orch_libs} ; do
+#      if [ -f ${ORCH_LIBDIR}/lib${LIBPREFIX}$lib.a ] ; then
+#         LIB="${LIB} -l${LIBPREFIX}$lib "
+#      fi
+#   done
 elif [[ "$veget" != "false" ]] ; then
    echo "Option -v $veget does not exist"
@@ -478,18 +482,18 @@
 then
    CPP_KEY="$CPP_KEY CPP_IOIPSL"
-   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}"
-   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl"
+   INCLUDE="$INCLUDE ${IOIPSL_INCDIR}"
+   LIB="$LIB ${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl"
 elif [[ $io == mix ]]
 then
    # For now, xios implies also using ioipsl
    CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS"
-   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}"
-   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios -l${LIBPREFIX}stdc++"
+   INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
+   LIB="$LIB ${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl ${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios -l${LIBPREFIX}stdc++"
 elif [[ $io == xios ]]
 then
    # For now, xios implies also using ioipsl
    CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS CPP_IOIPSL_NO_OUTPUT"
-   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}"
-   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios -l${LIBPREFIX}stdc++"
+   INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
+   LIB="$LIB ${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl ${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios -l${LIBPREFIX}stdc++"
 fi
 
@@ -556,5 +560,5 @@
 
 INCLUDE="$INCLUDE ${NETCDF_INCDIR}"
-LIB="$LIB ${NETCDF_LIBDIR}"
+LIB="$LIB ${NETCDF_LIBDIR} ${NETCDF_LIB}"
 
 ########################################################################
@@ -707,7 +711,8 @@
    # On enleve tout apres ONLy et on met un "uniq" pour que ca ne recrée pas
    # le makefile si on se contente d'ajouter des lignes dans le ONLY
+   exclude="replay automatic include"
    for str in subroutine "use " "include " ; do
-      grep -i "$str" libf/$dir/*.[Fh] | cut -d\( -f1 | sed -e 's/[Oo][Nn][Ll][Yy].*.$//' | uniq >> tmp77
-      grep -i "$str" libf/$dir/*.F90  | cut -d\( -f1 | sed -e 's/[Oo][Nn][Ll][Yy].*.$//' | uniq >> tmp90
+      grep -i "$str" libf/$dir/*.[Fh] | sed -e "/$exclude/d" | cut -d\( -f1 | sed -e 's/[Oo][Nn][Ll][Yy].*.$//' | uniq >> tmp77
+      grep -i "$str" libf/$dir/*.F90  | sed -e "/$exclude/d" | cut -d\( -f1 | sed -e 's/[Oo][Nn][Ll][Yy].*.$//' | uniq >> tmp90
    done
 done
Index: LMDZ6/branches/LMDZ_ECRad/makelmdz_fcm
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/makelmdz_fcm	(revision 4444)
+++ LMDZ6/branches/LMDZ_ECRad/makelmdz_fcm	(revision 4482)
@@ -45,4 +45,5 @@
 isotrac=false
 force_compile=false
+cplocninca=false
 
 arch_defined="FALSE"
@@ -94,11 +95,13 @@
 [-prod / -dev / -debug]    : compilation mode production (default) / developement / debug
 [-c false/MPI1/OMCT]       : coupling with ocean model : MPI1/OMCT/false (default: false)
-[-v false/orchidee2.0/orchidee1.9/true] : version of the vegetation model to include (default: false)
+[-v false/orchideetrunk/orchidee2.1/orchidee2.0/orchidee1.9] : version of the vegetation model to include (default: false)
           false       : no vegetation model
-          orchidee2.1 : compile using ORCHIDEE 2.1 (or more recent version)
+          orchideetrunk : compile using ORCHIDEE trunk from revision 7757 or higher
+          orchidee2.1 : compile using ORCHIDEE 2.1 until 4.1 included or until revision 7757 on the trunk
           orchidee2.0 : compile using ORCHIDEE 2.0
           orchidee1.9 : compile using ORCHIDEE up to the version including OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6
           true        : (obsolete; for backward compatibility) use ORCHIDEE tag 1.9-1.9.6
 [-chimie INCA/false]       : with INCA chemistry model or without (default: false)
+[-cplocninca ]        : allow transfer of species from PISCES to INCA (default: false)
 [-cosp true/false]    : compile with/without cosp package (default: false)
 [-cosp2 true/false]    : compile with/without cosp2 package (default: false)
@@ -179,4 +182,7 @@
 	  chimie="$2" ; shift ; shift ;;
 
+     "-cplocninca")
+          cplocninca=TRUE ; shift ;;
+
       "-isotopes")
 	  isotopes="$2" ; shift ; shift ;;
@@ -364,6 +370,6 @@
 then
    CPP_KEY="$CPP_KEY INCA"
-   INCLUDE="$INCLUDE -I${INCA_INCDIR}"
-   LIB="$LIB -L${INCA_LIBDIR} -lchimie"
+   INCLUDE="$INCLUDE ${INCA_INCDIR}"
+   LIB="$LIB ${INCA_LIBDIR} ${INCA_LIB}"
 fi
 
@@ -399,6 +405,6 @@
     else
 	CPP_KEY="$CPP_KEY CPP_COUPLE CPP_OMCT"
-	INCLUDE="$INCLUDE -I${OASIS_INCDIR}"
-	LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.MPI1 -lscrip -lmct -lmpeu"
+	INCLUDE="$INCLUDE ${OASIS_INCDIR}"
+	LIB="$LIB ${OASIS_LIBDIR} -lpsmile.MPI1 -lscrip -lmct -lmpeu"
     fi
 fi
@@ -428,10 +434,11 @@
 fi
 
-if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" -o "$veget" = "orchidee2.1" ]
-then
+if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" -o "$veget" = "orchidee2.1" -o "$veget" = "orchideetrunk" ]
+then
+	echo "doing orchidee"
 #NB: option 'true': for backward compatibility. To be used with ORCHIDEE tag 1.9-1.9.6
 #    For this case, cpp flag ORCHIDEE_NOOPENMP must be added to the makelmdz_fcm arguments
 #    option orchidee1.9 : Compile with ORCHIDEE version up to the inclusion of OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6
-   INCLUDE="${INCLUDE} -I${ORCH_INCDIR}"
+   INCLUDE="${INCLUDE} ${ORCH_INCDIR}"
    CPP_KEY="$CPP_KEY CPP_VEGET"
 # temporary, for Orchidee versions 1.9.* (before openmp activation)
@@ -440,17 +447,22 @@
    fi
    if [[ "$veget" == "orchidee2.0" ]] ; then
-      orch_libs="sechiba parameters stomate parallel orglob orchidee"
+      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob -lorchidee"
       CPP_KEY="$CPP_KEY ORCHIDEE_NOUNSTRUCT"
    elif [[ "$veget" == "orchidee2.1" ]] ; then
-      orch_libs="sechiba parameters stomate parallel orglob orchidee"
+      CPP_KEY="$CPP_KEY ORCHIDEE_NOLIC"
+      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob -lorchidee"
+   elif [[ "$veget" == "orchideetrunk" ]] ; then
+      orch_libs="-lorchidee"
    else
-      orch_libs="sechiba parameters stomate parallel orglob"
+      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob"
    fi
-   LIB="${LIB} -L${ORCH_LIBDIR}"
-   for lib in ${orch_libs} ; do
-      if [ -f ${ORCH_LIBDIR}/lib${LIBPREFIX}$lib.a ] ; then
-         LIB="${LIB} -l${LIBPREFIX}$lib "
-      fi
-   done
+   LIB="${LIB} ${ORCH_LIBDIR} ${orch_libs}"
+#   for lib in ${orch_libs} ; do
+#      if [ -f ${ORCH_LIBDIR#-L}/lib${LIBPREFIX}$lib.a ] ; then
+#         LIB="${LIB} -l${LIBPREFIX}$lib "
+#      fi
+#   done
+   echo "orchidee lib" 
+   echo ${LIB}
 elif [[ "$veget" != "false" ]] ; then
    echo "Option -v $veget does not exist"
@@ -495,18 +507,18 @@
 then
    CPP_KEY="$CPP_KEY CPP_IOIPSL"
-   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}"
-   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl"
+   INCLUDE="$INCLUDE ${IOIPSL_INCDIR}"
+   LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB}"
 elif [[ $io == mix ]]
 then
    # For now, xios implies also using ioipsl
    CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS"
-   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}"
-   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios -l${LIBPREFIX}stdc++"
+   INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
+   LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}"
 elif [[ $io == xios ]]
 then
    # For now, xios implies also using ioipsl
    CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS CPP_IOIPSL_NO_OUTPUT"
-   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}"
-   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios -l${LIBPREFIX}stdc++"
+   INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
+   LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}"
 fi
 
@@ -532,8 +544,12 @@
 fi
 
+if [[ "$cplocninca" == "TRUE" ]]
+then
+    CPP_KEY="${CPP_KEY} CPP_CPLOCNINCA"
+fi
 
 
 INCLUDE="$INCLUDE ${NETCDF_INCDIR}"
-LIB="$LIB ${NETCDF_LIBDIR}"
+LIB="$LIB ${NETCDF_LIBDIR} ${NETCDF_LIB}"
 
 ########################################################################
@@ -598,6 +614,4 @@
 then
   CPP_KEY="$CPP_KEY CPP_1D"
-##in 1D, add dyn3d to include path (because main prog is in physics)
-  INCLUDE="$INCLUDE -Ilibf/dyn3d -Ilibf/dyn3d_common"
 ## no filtre in 1d:
   FILTRE_PATH=$LMDGCM/.void_dir
