Index: /LMDZ5/branches/testing/DefLists/field_def_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/field_def_lmdz.xml	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/field_def_lmdz.xml	(revision 2408)
@@ -15,4 +15,6 @@
         <field id="flat"    long_name="Latent heat flux"        unit="W/m2" />
         <field id="slp"     long_name="Sea Level Pressure"      unit="Pa" />
+        <field id="ptstar"  long_name="Air Surface Temperature" unit="K" />
+        <field id="pt0"     long_name="Standard Air Surface Temperature"      unit="K" />
         <field id="tsol"    long_name="Surface Temperature"     unit="K" />
         <field id="t2m"        long_name="Temperature 2m" unit="K" />
@@ -111,5 +113,10 @@
 	<field id="du_gwd_rando"    long_name="peu importe"    unit="W/m2" />
 	<field id="dv_gwd_rando"    long_name="peu importe"    unit="W/m2" />
-	<field id="vstr_gwd_rando"    long_name="peu importe"    unit="W/m2" />
+	<field id="ustr_gwd_hines"    long_name="zonal wind stress Hines gravity waves"    unit="Pa" />
+	<field id="vstr_gwd_hines"    long_name="meridional wind stress Hines gravity waves"    unit="Pa" />
+	<field id="ustr_gwd_front"    long_name="zonal wind stress fronts gravity waves"    unit="Pa" />
+	<field id="vstr_gwd_front"    long_name="meridional wind stress fronts gravity waves"    unit="Pa" />
+	<field id="ustr_gwd_rando"    long_name="zonal wind stress random gravity waves"    unit="Pa" />
+	<field id="vstr_gwd_rando"    long_name="meridinal wind stress random gravity waves"    unit="Pa" />
         <field id="sens"    long_name="Sensible heat flux"    unit="W/m2" />
         <field id="fder"    long_name="Heat flux derivation"    unit="W/m2" />
@@ -510,6 +517,10 @@
         <field id="dulif"    long_name="Orography dU"    unit="m/s2" />
         <field id="dvlif"    long_name="Orography dV"    unit="m/s2" />
-        <field id="duhin"    long_name="Hines GWD dU"    unit="m/s2" />
-        <field id="dvhin"    long_name="Hines GWD dV"    unit="m/s2" />
+	<field id="du_gwd_hines" long_name="Hines GWD dU" unit="m/s2" />
+	<field id="dv_gwd_hines" long_name="Hines GWD dV" unit="m/s2" />
+	<field id="du_gwd_front" long_name="Fronts GWD dU" unit="m/s2" />
+	<field id="dv_gwd_front" long_name="Fronts GWD dV" unit="m/s2" />
+	<field id="east_gwstress" long_name="Eastward GW Stress" unit="Pa" />
+	<field id="west_gwstress" long_name="Westward GW Stress" unit="Pa" />
         <field id="dtoro"    long_name="Orography dT"    unit="K/s" />
         <field id="dtlif"    long_name="Orography dT"    unit="K/s" />
@@ -693,2 +704,3 @@
 
 </field_definition>
+
Index: /LMDZ5/branches/testing/DefLists/file_def_histLES_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histLES_lmdz.xml	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/file_def_histLES_lmdz.xml	(revision 2408)
@@ -19,4 +19,6 @@
                 <field field_ref="flat" level="5" />
                 <field field_ref="slp" level="10" />
+                <field field_ref="ptstar" level="10" />
+                <field field_ref="pt0" level="10" />
                 <field field_ref="tsol" level="10" />
                 <field field_ref="t2m" level="10" />
@@ -491,6 +493,10 @@
                 <field field_ref="dulif" level="10" />
                 <field field_ref="dvlif" level="10" />
-                <field field_ref="duhin" level="10" />
-                <field field_ref="dvhin" level="10" />
+                <field field_ref="du_gwd_hines" level="10" />
+                <field field_ref="dv_gwd_hines" level="10" />
+                <field field_ref="du_gwd_front" level="10" />
+                <field field_ref="dv_gwd_front" level="10" />
+                <field field_ref="east_gwstress" level="10" />
+                <field field_ref="west_gwstress" level="10" />
                 <field field_ref="dtoro" level="10" />
                 <field field_ref="dtlif" level="10" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histday_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histday_lmdz.xml	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/file_def_histday_lmdz.xml	(revision 2408)
@@ -19,4 +19,6 @@
                 <field field_ref="flat" level="1" />
                 <field field_ref="slp" level="1" />
+                <field field_ref="ptstar" level="1" />
+                <field field_ref="pt0" level="1" />
                 <field field_ref="tsol" level="1" />
                 <field field_ref="t2m" level="1" />
@@ -491,6 +493,10 @@
                 <field field_ref="dulif" level="10" />
                 <field field_ref="dvlif" level="10" />
-                <field field_ref="duhin" level="10" />
-                <field field_ref="dvhin" level="10" />
+                <field field_ref="du_gwd_hines" level="10" />
+                <field field_ref="dv_gwd_hines" level="10" />
+                <field field_ref="du_gwd_front" level="10" />
+                <field field_ref="dv_gwd_front" level="10" />
+                <field field_ref="east_gwstress" level="10" />
+                <field field_ref="west_gwstress" level="10" />
                 <field field_ref="dtoro" level="10" />
                 <field field_ref="dtlif" level="10" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histhf_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histhf_lmdz.xml	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/file_def_histhf_lmdz.xml	(revision 2408)
@@ -19,4 +19,6 @@
                 <field field_ref="flat" level="10" />
                 <field field_ref="slp" level="10" />
+                <field field_ref="ptstar" level="10" />
+                <field field_ref="pt0" level="10" />
                 <field field_ref="tsol" level="5" />
                 <field field_ref="t2m" level="5" />
@@ -491,6 +493,10 @@
                 <field field_ref="dulif" level="10" />
                 <field field_ref="dvlif" level="10" />
-                <field field_ref="duhin" level="10" />
-                <field field_ref="dvhin" level="10" />
+                <field field_ref="du_gwd_hines" level="10" />
+                <field field_ref="dv_gwd_hines" level="10" />
+                <field field_ref="du_gwd_front" level="10" />
+                <field field_ref="dv_gwd_front" level="10" />
+                <field field_ref="east_gwstress" level="10" />
+                <field field_ref="west_gwstress" level="10" />
                 <field field_ref="dtoro" level="10" />
                 <field field_ref="dtlif" level="10" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histins_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histins_lmdz.xml	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/file_def_histins_lmdz.xml	(revision 2408)
@@ -19,4 +19,6 @@
                 <field field_ref="flat" level="10" />
                 <field field_ref="slp" level="1" />
+                <field field_ref="ptstar" level="1" />
+                <field field_ref="pt0" level="1" />
                 <field field_ref="tsol" level="1" />
                 <field field_ref="t2m" level="1" />
@@ -491,6 +493,10 @@
                 <field field_ref="dulif" level="10" />
                 <field field_ref="dvlif" level="10" />
-                <field field_ref="duhin" level="10" />
-                <field field_ref="dvhin" level="10" />
+                <field field_ref="du_gwd_hines" level="10" />
+                <field field_ref="dv_gwd_hines" level="10" />
+                <field field_ref="du_gwd_front" level="10" />
+                <field field_ref="dv_gwd_front" level="10" />
+                <field field_ref="east_gwstress" level="10" />
+                <field field_ref="west_gwstress" level="10" />
                 <field field_ref="dtoro" level="10" />
                 <field field_ref="dtlif" level="10" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histmth_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histmth_lmdz.xml	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/file_def_histmth_lmdz.xml	(revision 2408)
@@ -19,4 +19,6 @@
                 <field field_ref="flat"         level="5" />
                 <field field_ref="slp"          level="1" />
+                <field field_ref="ptstar"       level="1" />
+                <field field_ref="pt0"          level="1" />
                 <field field_ref="tsol"         level="1" />
                 <field field_ref="t2m"          level="1" />
@@ -491,6 +493,10 @@
                 <field field_ref="dulif" level="4" />
                 <field field_ref="dvlif" level="4" />
-                <field field_ref="duhin" level="4" />
-                <field field_ref="dvhin" level="4" />
+                <field field_ref="du_gwd_hines" level="4" />
+                <field field_ref="dv_gwd_hines" level="4" />
+                <field field_ref="du_gwd_front" level="4" />
+                <field field_ref="dv_gwd_front" level="4" />
+                <field field_ref="east_gwstress" level="4" />
+                <field field_ref="west_gwstress" level="4" />
                 <field field_ref="dtoro" level="4" />
                 <field field_ref="dtlif" level="4" />
Index: /LMDZ5/branches/testing/DefLists/file_def_histstn_lmdz.xml
===================================================================
--- /LMDZ5/branches/testing/DefLists/file_def_histstn_lmdz.xml	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/file_def_histstn_lmdz.xml	(revision 2408)
@@ -19,4 +19,6 @@
                 <field field_ref="flat" level="10" />
                 <field field_ref="slp" level="10" />
+                <field field_ref="ptstar" level="10" />
+                <field field_ref="pt0" level="10" />
                 <field field_ref="tsol" level="10" />
                 <field field_ref="t2m" level="10" />
@@ -491,6 +493,10 @@
                 <field field_ref="dulif" level="10" />
                 <field field_ref="dvlif" level="10" />
-                <field field_ref="duhin" level="10" />
-                <field field_ref="dvhin" level="10" />
+                <field field_ref="du_gwd_hines" level="10" />
+                <field field_ref="dv_gwd_hines" level="10" />
+                <field field_ref="du_gwd_front" level="10" />
+                <field field_ref="dv_gwd_front" level="10" />
+                <field field_ref="east_gwstress" level="10" />
+                <field field_ref="west_gwstress" level="10" />
                 <field field_ref="dtoro" level="10" />
                 <field field_ref="dtlif" level="10" />
Index: /LMDZ5/branches/testing/DefLists/physiq.def_L39_AR40.0
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_L39_AR40.0	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_L39_AR40.0	(revision 2408)
@@ -1,3 +1,6 @@
-##############################################################################
+#
+# $Id$
+#
+###############################################################################
 # PARAMETRES ET CLES DE LA PHYSIQUE LMDZ
 ##############################################################################
Index: /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv0.0
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv0.0	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv0.0	(revision 2408)
@@ -1,3 +1,6 @@
-##############################################################################
+#
+# $Id$
+#
+###############################################################################
 # PARAMETRES ET CLES DE LA PHYSIQUE LMDZ
 ##############################################################################
Index: /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv1.0
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv1.0	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv1.0	(revision 2408)
@@ -1,3 +1,6 @@
-##############################################################################
+#
+# $Id$
+#
+###############################################################################
 # PARAMETRES ET CLES DE LA PHYSIQUE LMDZ
 ##############################################################################
Index: /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv2.0
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv2.0	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv2.0	(revision 2408)
@@ -1,2 +1,5 @@
+#
+# $Id$
+#
 ##############################################################################
 # PARAMETRES ET CLES DE LA PHYSIQUE LMDZ
Index: /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv3.0
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv3.0	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv3.0	(revision 2408)
@@ -1,3 +1,6 @@
-##############################################################################
+#
+# $Id$
+#
+###############################################################################
 # PARAMETRES ET CLES DE LA PHYSIQUE LMDZ
 ##############################################################################
Index: /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv3.1
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv3.1	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv3.1	(revision 2408)
@@ -1,3 +1,6 @@
-##############################################################################
+#
+# $Id$
+#
+###############################################################################
 # PARAMETRES ET CLES DE LA PHYSIQUE LMDZ
 ##############################################################################
Index: /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv3.2
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv3.2	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_L39_NPv3.2	(revision 2408)
@@ -1,3 +1,6 @@
-##############################################################################
+#
+# $Id$
+#
+###############################################################################
 # PARAMETRES ET CLES DE LA PHYSIQUE LMDZ
 ##############################################################################
Index: /LMDZ5/branches/testing/DefLists/physiq.def_L59_NPv4.12
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_L59_NPv4.12	(revision 2407)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_L59_NPv4.12	(revision 2408)
@@ -1,3 +1,6 @@
-##############################################################################
+#
+# $Id$
+#
+###############################################################################
 # PARAMETRES ET CLES DE LA PHYSIQUE LMDZ
 ##############################################################################
Index: /LMDZ5/branches/testing/DefLists/physiq.def_L79_NPv5.17h
===================================================================
--- /LMDZ5/branches/testing/DefLists/physiq.def_L79_NPv5.17h	(revision 2408)
+++ /LMDZ5/branches/testing/DefLists/physiq.def_L79_NPv5.17h	(revision 2408)
@@ -0,0 +1,181 @@
+#
+# $Id$
+#
+###############################################################################
+# PARAMETRES ET CLES DE LA PHYSIQUE LMDZ
+##############################################################################
+# D: Valeur par default
+#
+#Parametres Orographiques et cdrags
+#**********************************
+##   Si=.T. ,  lecture du fichier limit avec la bonne annee 
+ok_limitvrai=n
+iflag_albedo=1
+#Cdrags 
+f_cdrag_stable=1.
+f_cdrag_ter=1.
+f_cdrag_oce=0.7
+f_ri_cd_min=0.6
+#cdmmax
+cdmmax=2.5E-3
+#cdhmax
+cdhmax=2.0E-3
+##  Orodr  ou  non   pour l orographie
+ok_orodr=y
+##  Orolf  ou  non   pour l orographie              
+ok_orolf=y
+#Rugoro
+f_rugoro=0.
+#
+### Random gravity waves
+#Activitate the stochastic parameterization of convective GWs (should be equal to ok_strato)
+ok_gwd_rando=y
+# Scale the momentum fluxes due to convective GWs
+gwd_rando_ruwmax=2.5
+#Scale the saturated momentum flux of  convective GWs 
+gwd_rando_sat=0.2
+
+#
+# Rayonnement
+#*********************
+# activation du nouveau code de rayonnement RRTM
+# 0 : Ancien code et 1 : RRTM (D=0)
+iflag_rrtm=0
+#NSW=2
+#
+# Parametres nuages
+#******************
+#seuils de la precipitation des nuages strateformes (D: 2.6e-4 2.6e-4)
+cld_lc_lsc=0.0003
+cld_lc_con=0.0003
+#constante de temps pour eleminer eau lsc et convective (D: 3600. 3600.)
+cld_tau_lsc=1800.
+cld_tau_con=1800.
+#facteurs correctifs sur la vitesse de chute des cristaux de glace (D: 1 1)
+ffallv_lsc=0.66528
+ffallv_con=0.66528
+#coefficient sur la reevaporation de la pluie (D: 2.e-5 n)
+coef_eva=2e-5
+reevap_ice=y
+#calcul des proprietes des nuages convectifs (D:1 0.375 1.e-4) 
+iflag_cldcon=6
+fact_cldcon=1.
+facttemps=0.
+#calcul eau condensee et fraction nuageuse a partir des PDF (D:0, 0:version avec ratqs sinon nouvelles PDFs)  
+iflag_pdf=1
+#calcul epaisseur optique et emmissivite des nuages (D: y 1 0.01 0.3)
+ok_newmicro=y
+iflag_ratqs=4
+ratqsbas=0.002
+ratqshaut=0.312
+#rayon effectif pour les nuages de glace (D:35)
+rad_froid=35
+#rayons effectifs pour les nuages eau liq (tailles des gouttes d eau nuageuse, D: 13 9)
+rad_chau1=12
+rad_chau2=11
+##  Choix ou non  de  New oliq               
+new_oliq=y
+#Rayons min et max effectifs des particules des nuages
+rei_min=16.
+rei_max=61.29
+#
+# Flags Convection 
+#*****************
+#Convection scheme switch (D:2, 1:LMD, 2:Tiedtke, 3:KE New Physics, 30:KE AR4)
+iflag_con=3
+#output level of energy conservation diagnostics
+if_ebil=0
+#maximum efficiency of cld water->precipitation conversion (D: 0.993)
+epmax=0.998
+#dry convective adjustment at beginning of Emanuel convective scheme (D: n 0)
+ok_adj_ema=n
+iflag_clw=0
+#Convective closure (D:1, 0:AR4, 2:ALE and ALP)
+iflag_clos=2
+#Convective entrainment mixing law (D:1, 0:AR4=flat PDF, 1=PDF)
+iflag_mix=0
+#weights of the bell shaped and flat PDF (used only if iflag_mix=1) (D: 1 0)
+qqa1=1.
+qqa2=0.
+#Parameters of the bell shaped PDF; Fmax=center (D= 0.65), Gammas=width (D=0.05)
+cvl_corr=1.0
+#Multiplicative factor of Emanuel convective scheme precipitation (D: 1.)
+Fmax=0.65
+#
+# Flags Couche limite
+#********************
+#shema de CL des thermiques (D:0, 0:ajustement sec,=>1:versions thermiques) 
+iflag_thermals=18
+#pas de temps du spliting pour les thermiques
+nsplit_thermals=1
+tau_thermals=0.
+iflag_thermals_ed=8
+fact_thermals_ed_dz=0.1
+iflag_thermals_optflux=0
+#shema de la couche de surface (D:1, 1:LMD, 8:Mellor-Yamada) 
+iflag_pbl=11
+#diffusion turbulente
+ksta_ter=1.e-7
+ksta=1.e-10
+#ok_kzmin : calcul Kzmin dans la CL de surface
+ok_kzmin=y
+#couplage ou non avec la convection
+iflag_coupl=5 (0:AR4 et 1:nouvelle physique)
+seuil_inversion=-0.08
+#rendement sur la puissance fournie par les thermiques a la convection
+alp_bl_k=0.5
+#
+## temperature dependency of qsat for iterative procedure
+## temporary flag to switch between the old (CMIP5, D=0) and new versions (=1) versions 
+iflag_fisrtilp_qsat=4 
+## Reactivation du calcul d'un zmax continu pour les thermiques
+## reactivation d'une fermeture humide des thermiques  iflag_thermals_closure=2 (D=1)
+iflag_thermals_closure=1
+#
+# Flags wakes
+#************
+#Wake scheme switch (D:0, 0:AR4, 1:New Physics)
+iflag_wake=1
+#Constant value to be added to Alp (D: 0.)
+alp_offset=0.
+
+### nrlmd le 10/04/2012: Declenchement ###
+#Déclelenchement par couche-limite (0: deterministe, 1: stochastique)
+iflag_trig_bl=1
+#Surface critique au LCL
+s_trig=1.2e7
+#Temps de decorrelation entre scenes de cumulus
+tau_trig_shallow=1200
+#Temps de decorrelation entre scenes de cumulonimbus
+tau_trig_deep=1200
+# Pour la stabilisation
+random_notrig_max=0.99
+ok_adjwk=y
+tmax_fonte_cv=288.15
+
+
+### nrlmd le 10/04/2012: Fermeture ###
+#Fermeture par couche-limite (0: deterministe, 1: statistique, 2: statistique+convergence grande échelle)
+iflag_clos_bl=1
+### fin nrlmd le 10/04/2012
+
+## Modification de la plage de temperature pour la phase mixte liquide/glace des nuages
+## Controle par les t_glace_min/max, exposant_glace, iflag_t_glace (D=0)
+t_glace_min=233.13
+t_glace_max=273.13
+exposant_glace=1.
+iflag_t_glace=1
+iflag_ice_thermo=1
+
+#
+## The source terms of the TKE prognostic equation are diagnosed from tendencies (du, dv, dT) 
+## associated with subrgrid scaleamotions and treated as an additional heat source.
+## Controled by a key, iflag_ener_conserv (D=-1):
+## 0 : no conservation, -1 : old adhoc correction for kinetic E only (used for CMIP5) 
+## 1 : conservation, 101 : conversion from kinetic to heat only, 110 conversion from potential to heat only
+iflag_ener_conserv=1
+
+#Activation of corrections for water conservation (D: n). 
+##The default is n for compatibility with earlier versions.
+##generally it should be y.
+ok_conserv_q=y 
Index: /LMDZ5/branches/testing/arch/arch-X64_OCCIGEN.fcm
===================================================================
--- /LMDZ5/branches/testing/arch/arch-X64_OCCIGEN.fcm	(revision 2408)
+++ /LMDZ5/branches/testing/arch/arch-X64_OCCIGEN.fcm	(revision 2408)
@@ -0,0 +1,15 @@
+%COMPILER            mpif90
+%LINK                mpif90
+%AR                  ar
+%MAKE                gmake
+%FPP_FLAGS           -P -traditional
+%FPP_DEF             NC_DOUBLE FFT_MKL
+%BASE_FFLAGS         -i4 -r8 -auto -recursive -mcmodel=medium -align all -fp-model strict -xCORE-AVX2
+%PROD_FFLAGS         -O2 -ip
+%DEV_FFLAGS          -p -g -O1 -fpe0 -traceback
+%DEBUG_FFLAGS        -p -g -O0 -fpe-all=0 -ftz -ftrapuv -fp-stack-check -check all -debug -traceback
+%MPI_FFLAGS
+%OMP_FFLAGS          -openmp -openmp-threadprivate compat
+%BASE_LD             -i4 -r8 -auto -shared-intel -Wl,-rpath=/opt/software/libraries/netcdf/bullxmpi/netcdf-4.3.3-rc2/lib:/opt/software/libraries/netcdf/bullxmpi/netcdf-fortran-4.4.1-4.3.3-rc2/lib:/opt/software/libraries/hdf5/hdf5_with_bullxmpi/1.8.14/lib $MKL_LIBS
+%MPI_LD
+%OMP_LD              -openmp
Index: /LMDZ5/branches/testing/arch/arch-X64_OCCIGEN.path
===================================================================
--- /LMDZ5/branches/testing/arch/arch-X64_OCCIGEN.path	(revision 2408)
+++ /LMDZ5/branches/testing/arch/arch-X64_OCCIGEN.path	(revision 2408)
@@ -0,0 +1,13 @@
+NETCDF_LIBDIR="-L/opt/software/libraries/netcdf/bullxmpi/netcdf-fortran-4.4.1-4.3.3-rc2/lib -lnetcdff -L/opt/software/libraries/netcdf/bullxmpi/netcdf-4.3.3-rc2/lib -lnetcdf -L/opt/software/libraries/hdf5/hdf5_with_bullxmpi/1.8.14/lib -lhdf5_hl -lhdf5 -lz"
+NETCDF_INCDIR="-I/opt/software/libraries/hdf5/hdf5_with_bullxmpi/1.8.14/include -I/opt/software/libraries/netcdf/bullxmpi/netcdf-fortran-4.4.1-4.3.3-rc2/include"
+IOIPSL_INCDIR=$LMDGCM/../../lib
+IOIPSL_LIBDIR=$LMDGCM/../../lib
+XIOS_INCDIR=$LMDGCM/../XIOS/inc
+XIOS_LIBDIR=$LMDGCM/../XIOS/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/config/lib
+INCA_INCDIR=$LMDGCM/../INCA/config/inc
+
Index: /LMDZ5/branches/testing/bld.cfg
===================================================================
--- /LMDZ5/branches/testing/bld.cfg	(revision 2407)
+++ /LMDZ5/branches/testing/bld.cfg	(revision 2408)
@@ -32,4 +32,5 @@
 src::misc    %SRC_PATH/misc
 src::dyn3d_common   %DYN_COMMON 
+src::phy_common %PHY_COMMON
 src::cosp    %COSP
 src::ext_src %EXT_SRC
@@ -37,12 +38,11 @@
 bld::lib            lmdz
 
-bld::outfile_ext::exe    %SUFF_NAME.e
-bld::target              liblmdz.a 
-bld::target              %EXEC%SUFF_NAME.e
+bld::outfile_ext::exe    %SUFF_NAME
+bld::target              liblmdz.a %EXEC%SUFF_NAME
 bld::exe_dep             
 
 
 dir::root            %CONFIG_PATH
-dir::lib             %BASE_CONFIG_PATH
+#dir::lib             %BASE_CONFIG_PATH
 dir::bin             %ROOT_PATH/bin
 
Index: /LMDZ5/branches/testing/create_make_gcm
===================================================================
--- /LMDZ5/branches/testing/create_make_gcm	(revision 2407)
+++ /LMDZ5/branches/testing/create_make_gcm	(revision 2408)
@@ -54,4 +54,5 @@
 echo "PHYS  = "
 echo 'LIBPHY = $(LIBO)/libphy$(PHYS).a'
+echo 'LIBPHY_COMMON= $(LIBO)/libphy_common.a'
 echo 'LIBDYN_PHY = $(LIBO)/libdynlmdz_phy$(PHYS).a'
 echo 'DIRMAIN=dyn$(DIM)d$(FLAG_PARA)'
@@ -64,5 +65,5 @@
 echo 'L_FILTRE   = -l$(FILTRE)'
 echo 'L_DYN_PHY = -ldynlmdz_phy$(PHYS) '
-echo 'L_PHY = -lphy$(PHYS) '
+echo 'L_PHY = -lphy$(PHYS) -lphy_common'
 echo 'L_MISC    = -lmisc'
 echo 'L_ADJNT    ='
@@ -92,5 +93,5 @@
 echo
 #echo 'main : chimie $(DYN) misc phys $(OPTION_DEP) '
-echo 'main : $(DYN) misc phys dyn_phy $(OPTION_DEP) '
+echo 'main : $(DYN) misc phys phy_common dyn_phy $(OPTION_DEP) '
 echo '	cd $(LIBO) ; $(RANLIB) lib*.a ; cd $(GCM) ;\'
 echo '	cd $(LOCAL_DIR); \'
@@ -99,4 +100,5 @@
 echo
 echo 'phys : $(LIBPHY)'
+echo 'phy_common : $(LIBPHY_COMMON)'
 echo 'dyn3d : $(LIBO)/libdyn$(DIM)d$(FLAG_PARA).a $(LIBO)/lib$(FILTRE).a $(LIBO)/libdyn3d_common.a'
 echo 'dyn2d : $(LIBO)/libdyn2d.a'
Index: DZ5/branches/testing/libf/dyn3d/dynetat0.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d/dynetat0.F	(revision 2407)
+++ 	(revision )
@@ -1,361 +1,0 @@
-!
-! $Id $
-!
-      SUBROUTINE dynetat0(fichnom,vcov,ucov,
-     .                    teta,q,masse,ps,phis,time)
-
-      USE infotrac
-      use netcdf, only: nf90_get_var
-
-      use control_mod, only : planet_type
-
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteur:  P. Le Van / L.Fairhead
-c   -------
-c
-c   objet:
-c   ------
-c
-c   Lecture de l'etat initial
-c
-c=======================================================================
-c-----------------------------------------------------------------------
-c   Declarations:
-c   -------------
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "temps.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom2.h"
-#include "ener.h"
-#include "netcdf.inc"
-#include "description.h"
-#include "serre.h"
-#include "logic.h"
-#include "iniprint.h"
-
-c   Arguments:
-c   ----------
-
-      CHARACTER*(*) fichnom
-      REAL vcov(iip1, jjm,llm),ucov(iip1, jjp1,llm),teta(iip1, jjp1,llm)
-      REAL q(iip1,jjp1,llm,nqtot),masse(iip1, jjp1,llm)
-      REAL ps(iip1, jjp1),phis(iip1, jjp1)
-
-      REAL time
-
-c   Variables 
-c
-      INTEGER length,iq
-      PARAMETER (length = 100)
-      REAL tab_cntrl(length) ! tableau des parametres du run
-      INTEGER ierr, nid, nvarid
-
-      INTEGER idecal
-
-c-----------------------------------------------------------------------
-
-c  Ouverture NetCDF du fichier etat initial
-
-      ierr = NF_OPEN (fichnom, NF_NOWRITE,nid)
-      IF (ierr.NE.NF_NOERR) THEN
-        write(lunout,*)'dynetat0: Pb d''ouverture du fichier start.nc'
-        write(lunout,*)' ierr = ', ierr
-        CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-c
-      ierr = NF_INQ_VARID (nid, "controle", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <controle> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, tab_cntrl)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echoue pour <controle>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      !!! AS: idecal is a hack to be able to read planeto starts...
-      !!!     .... while keeping everything OK for LMDZ EARTH
-      if (planet_type.eq."generic") then
-          print*,'NOTE NOTE NOTE : Planeto-like start files'
-          idecal = 4
-          annee_ref  = 2000
-      else
-          print*,'NOTE NOTE NOTE : Earth-like start files'
-          idecal = 5
-          annee_ref  = tab_cntrl(5)
-      endif
-
-
-      im         = tab_cntrl(1)
-      jm         = tab_cntrl(2)
-      lllm       = tab_cntrl(3)
-      day_ref    = tab_cntrl(4)
-      rad        = tab_cntrl(idecal+1)
-      omeg       = tab_cntrl(idecal+2)
-      g          = tab_cntrl(idecal+3)
-      cpp        = tab_cntrl(idecal+4)
-      kappa      = tab_cntrl(idecal+5)
-      daysec     = tab_cntrl(idecal+6)
-      dtvr       = tab_cntrl(idecal+7)
-      etot0      = tab_cntrl(idecal+8)
-      ptot0      = tab_cntrl(idecal+9)
-      ztot0      = tab_cntrl(idecal+10)
-      stot0      = tab_cntrl(idecal+11)
-      ang0       = tab_cntrl(idecal+12)
-      pa         = tab_cntrl(idecal+13)
-      preff      = tab_cntrl(idecal+14)
-c
-      clon       = tab_cntrl(idecal+15)
-      clat       = tab_cntrl(idecal+16)
-      grossismx  = tab_cntrl(idecal+17)
-      grossismy  = tab_cntrl(idecal+18)
-c
-      IF ( tab_cntrl(idecal+19).EQ.1. )  THEN
-        fxyhypb  = . TRUE .
-c        dzoomx   = tab_cntrl(25)
-c        dzoomy   = tab_cntrl(26)
-c        taux     = tab_cntrl(28)
-c        tauy     = tab_cntrl(29)
-      ELSE
-        fxyhypb = . FALSE .
-        ysinus  = . FALSE .
-        IF( tab_cntrl(idecal+22).EQ.1. ) ysinus = . TRUE. 
-      ENDIF
-
-      day_ini = tab_cntrl(30)
-      itau_dyn = tab_cntrl(31)
-      start_time = tab_cntrl(32)
-c   .................................................................
-c
-c
-      write(lunout,*)'dynetat0: rad,omeg,g,cpp,kappa',
-     &               rad,omeg,g,cpp,kappa
-
-      IF(   im.ne.iim           )  THEN
-          PRINT 1,im,iim
-          STOP
-      ELSE  IF( jm.ne.jjm       )  THEN
-          PRINT 2,jm,jjm
-          STOP
-      ELSE  IF( lllm.ne.llm     )  THEN
-          PRINT 3,lllm,llm
-          STOP
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlonu", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <rlonu> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, rlonu)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <rlonu>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlatu", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <rlatu> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, rlatu)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <rlatu>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlonv", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <rlonv> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, rlonv)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <rlonv>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlatv", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <rlatv> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, rlatv)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour rlatv"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "cu", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <cu> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, cu)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <cu>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "cv", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <cv> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, cv)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <cv>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "aire", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <aire> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, aire)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <aire>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "phisinit", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <phisinit> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, phis)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <phisinit>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "temps", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <temps> est absent"
-         write(lunout,*)"dynetat0: J essaie <Time>"
-         ierr = NF_INQ_VARID (nid, "Time", nvarid)
-         IF (ierr .NE. NF_NOERR) THEN
-            write(lunout,*)"dynetat0: Le champ <Time> est absent"
-            CALL ABORT_gcm("dynetat0", "", 1)
-         ENDIF
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, time)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee <temps>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "ucov", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <ucov> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, ucov)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <ucov>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
- 
-      ierr = NF_INQ_VARID (nid, "vcov", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <vcov> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, vcov)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <vcov>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "teta", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <teta> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, teta)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <teta>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-
-      IF(nqtot.GE.1) THEN
-      DO iq=1,nqtot
-        ierr =  NF_INQ_VARID (nid, tname(iq), nvarid)
-        IF (ierr .NE. NF_NOERR) THEN
-           write(lunout,*)"dynetat0: Le traceur <"//trim(tname(iq))//
-     &                    "> est absent"
-           write(lunout,*)"          Il est donc initialise a zero"
-           q(:,:,:,iq)=0.
-
-           ! CRisi: pour les isotopes, on peut faire init théorique
-           ! distill de Rayleigh très simplifiée
-           if (ok_isotopes) then
-              if ((iso_num(iq).gt.0).and.(zone_num(iq).eq.0)) then
-                q(:,:,:,iq)=q(:,:,:,iqpere(iq))                         
-     &                   *tnat(iso_num(iq))                             
-     &                   *(q(:,:,:,iqpere(iq))/30.e-3)                  
-     &                   **(alpha_ideal(iso_num(iq))-1)
-              endif
-              if ((iso_num(iq).gt.0).and.(zone_num(iq).eq.1)) then
-                  q(:,:,:,iq)=q(:,:,:,iqiso(iso_indnum(iq),
-     &                   phase_num(iq)))
-              endif  
-           endif !if (ok_isotopes) then 
-        ELSE
-           ierr = NF90_GET_VAR(nid, nvarid, q(:,:,:,iq))
-          IF (ierr .NE. NF_NOERR) THEN
-            write(lunout,*)"dynetat0: Lecture echouee pour "//tname(iq)
-            CALL ABORT_gcm("dynetat0", "", 1)
-          ENDIF
-        ENDIF
-      ENDDO
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "masse", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <masse> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, masse)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <masse>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "ps", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <ps> est absent"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-      ierr = nf90_get_var(nid, nvarid, ps)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Lecture echouee pour <ps>"
-         CALL ABORT_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_CLOSE(nid)
-
-       day_ini=day_ini+INT(time)
-       time=time-INT(time)
-
-  1   FORMAT(//10x,'la valeur de im =',i4,2x,'lue sur le fichier de dem
-     *arrage est differente de la valeur parametree iim =',i4//)
-   2  FORMAT(//10x,'la valeur de jm =',i4,2x,'lue sur le fichier de dem
-     *arrage est differente de la valeur parametree jjm =',i4//)
-   3  FORMAT(//10x,'la valeur de lmax =',i4,2x,'lue sur le fichier dema
-     *rrage est differente de la valeur parametree llm =',i4//)
-   4  FORMAT(//10x,'la valeur de dtrv =',i4,2x,'lue sur le fichier dema
-     *rrage est differente de la valeur  dtinteg =',i4//)
-
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d/dynetat0.f90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d/dynetat0.f90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d/dynetat0.f90	(revision 2408)
@@ -0,0 +1,202 @@
+SUBROUTINE dynetat0(fichnom,vcov,ucov,teta,q,masse,ps,phis,time)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , L.Fairhead
+!-------------------------------------------------------------------------------
+! Purpose: Initial state reading.
+!-------------------------------------------------------------------------------
+  USE infotrac
+  USE netcdf,      ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_INQ_VARID, NF90_NoErr, &
+                         NF90_CLOSE, NF90_GET_VAR
+  USE control_mod, ONLY: planet_type
+  USE assert_eq_m, ONLY: assert_eq
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "temps.h"
+  include "comconst.h"
+  include "comvert.h"
+  include "comgeom2.h"
+  include "ener.h"
+  include "description.h"
+  include "serre.h"
+  include "logic.h"
+  include "iniprint.h"
+!===============================================================================
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN) :: fichnom          !--- FILE NAME
+  REAL, INTENT(OUT) ::  vcov(iip1,jjm, llm)        !--- V COVARIANT WIND
+  REAL, INTENT(OUT) ::  ucov(iip1,jjp1,llm)        !--- U COVARIANT WIND
+  REAL, INTENT(OUT) ::  teta(iip1,jjp1,llm)        !--- POTENTIAL TEMP.
+  REAL, INTENT(OUT) ::     q(iip1,jjp1,llm,nqtot)  !--- TRACERS
+  REAL, INTENT(OUT) :: masse(iip1,jjp1,llm)        !--- MASS PER CELL
+  REAL, INTENT(OUT) ::    ps(iip1,jjp1)            !--- GROUND PRESSURE
+  REAL, INTENT(OUT) ::  phis(iip1,jjp1)            !--- GEOPOTENTIAL
+!===============================================================================
+! Local variables:
+  CHARACTER(LEN=256) :: msg, var, modname
+  INTEGER, PARAMETER :: length=100
+  INTEGER :: iq, fID, vID, idecal!, iml, jml, lml, nqt
+  REAL    :: time, tab_cntrl(length)               !--- RUN PARAMS TABLE
+!-------------------------------------------------------------------------------
+  modname="dynetat0"
+
+!--- Initial state file opening
+  var=fichnom
+  CALL err(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var)
+  CALL get_var1("controle",tab_cntrl)
+
+!!! AS: idecal is a hack to be able to read planeto starts...
+!!!     .... while keeping everything OK for LMDZ EARTH
+  IF(planet_type=="generic") THEN
+    WRITE(lunout,*)'NOTE NOTE NOTE : Planeto-like start files'
+    idecal = 4
+    annee_ref  = 2000
+  ELSE
+    WRITE(lunout,*)'NOTE NOTE NOTE : Earth-like start files'
+    idecal = 5
+    annee_ref  = tab_cntrl(5)
+  END IF
+  im         = tab_cntrl(1)
+  jm         = tab_cntrl(2)
+  lllm       = tab_cntrl(3)
+  day_ref    = tab_cntrl(4)
+  rad        = tab_cntrl(idecal+1)
+  omeg       = tab_cntrl(idecal+2)
+  g          = tab_cntrl(idecal+3)
+  cpp        = tab_cntrl(idecal+4)
+  kappa      = tab_cntrl(idecal+5)
+  daysec     = tab_cntrl(idecal+6)
+  dtvr       = tab_cntrl(idecal+7)
+  etot0      = tab_cntrl(idecal+8)
+  ptot0      = tab_cntrl(idecal+9)
+  ztot0      = tab_cntrl(idecal+10)
+  stot0      = tab_cntrl(idecal+11)
+  ang0       = tab_cntrl(idecal+12)
+  pa         = tab_cntrl(idecal+13)
+  preff      = tab_cntrl(idecal+14)
+!
+  clon       = tab_cntrl(idecal+15)
+  clat       = tab_cntrl(idecal+16)
+  grossismx  = tab_cntrl(idecal+17)
+  grossismy  = tab_cntrl(idecal+18)
+!
+  IF ( tab_cntrl(idecal+19)==1. )  THEN
+    fxyhypb  = .TRUE.
+!   dzoomx   = tab_cntrl(25)
+!   dzoomy   = tab_cntrl(26)
+!   taux     = tab_cntrl(28)
+!   tauy     = tab_cntrl(29)
+  ELSE
+    fxyhypb = .FALSE.
+    ysinus  = tab_cntrl(idecal+22)==1.
+  END IF
+
+  day_ini    = tab_cntrl(30)
+  itau_dyn   = tab_cntrl(31)
+  start_time = tab_cntrl(32)
+
+!-------------------------------------------------------------------------------
+  WRITE(lunout,*)TRIM(modname)//': rad,omeg,g,cpp,kappa',rad,omeg,g,cpp,kappa
+  CALL check_dim(im,iim,'im','im')
+  CALL check_dim(jm,jjm,'jm','jm')
+  CALL check_dim(lllm,llm,'lm','lllm')
+  CALL get_var1("rlonu",rlonu)
+  CALL get_var1("rlatu",rlatu)
+  CALL get_var1("rlonv",rlonv)
+  CALL get_var1("rlatv",rlatv)
+  CALL get_var2("cu"   ,cu)
+  CALL get_var2("cv"   ,cv)
+  CALL get_var2("aire" ,aire)
+  var="temps"
+  IF(NF90_INQ_VARID(fID,var,vID)/=NF90_NoErr) THEN
+    WRITE(lunout,*)TRIM(modname)//": missing field <temps>"
+    WRITE(lunout,*)TRIM(modname)//": trying with <Time>"; var="Time"
+    CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
+  END IF
+  CALL err(NF90_GET_VAR(fID,vID,time),"get",var)
+  CALL get_var2("phisinit",phis)
+  CALL get_var3("ucov",ucov)
+  CALL get_var3("vcov",vcov)
+  CALL get_var3("teta",teta)
+  CALL get_var3("masse",masse)
+  CALL get_var2("ps",ps)
+
+!--- Tracers
+  DO iq=1,nqtot
+    var=tname(iq)
+    IF(NF90_INQ_VARID(fID,var,vID)==NF90_NoErr) THEN
+      CALL err(NF90_GET_VAR(fID,vID,q(:,:,:,iq)),"get",var); CYCLE
+    END IF
+    WRITE(lunout,*)TRIM(modname)//": Tracer <"//TRIM(var)//"> is missing"
+    WRITE(lunout,*)"         It is hence initialized to zero"
+    q(:,:,:,iq)=0.
+   !--- CRisi: for isotops, theoretical initialization using very simplified
+   !           Rayleigh distillation las.
+    IF(ok_isotopes.AND.iso_num(iq)>0) THEN
+      IF(zone_num(iq)==0) q(:,:,:,iq)=q(:,:,:,iqpere(iq))*tnat(iso_num(iq))    &
+     &             *(q(:,:,:,iqpere(iq))/30.e-3)**(alpha_ideal(iso_num(iq))-1)
+      IF(zone_num(iq)==1) q(:,:,:,iq)=q(:,:,:,iqiso(iso_indnum(iq),phase_num(iq)))
+    END IF
+  END DO
+
+  CALL err(NF90_CLOSE(fID),"close",fichnom)
+  day_ini=day_ini+INT(time)
+  time=time-INT(time)
+
+
+  CONTAINS
+
+
+SUBROUTINE check_dim(n1,n2,str1,str2)
+  INTEGER,          INTENT(IN) :: n1, n2
+  CHARACTER(LEN=*), INTENT(IN) :: str1, str2
+  CHARACTER(LEN=256) :: s1, s2
+  IF(n1/=n2) THEN
+    s1='value of '//TRIM(str1)//' ='
+    s2=' read in starting file differs from parametrized '//TRIM(str2)//' ='
+    WRITE(msg,'(10x,a,i4,2x,a,i4)'),s1,n1,s2,n2
+    CALL ABORT_gcm(TRIM(modname),TRIM(msg),1)
+  END IF
+END SUBROUTINE check_dim
+
+
+SUBROUTINE get_var1(var,v)
+  CHARACTER(LEN=*), INTENT(IN)  :: var
+  REAL,             INTENT(OUT) :: v(:)
+  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
+  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
+END SUBROUTINE get_var1
+
+
+SUBROUTINE get_var2(var,v)
+  CHARACTER(LEN=*), INTENT(IN)  :: var
+  REAL,             INTENT(OUT) :: v(:,:)
+  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
+  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
+END SUBROUTINE get_var2
+
+
+SUBROUTINE get_var3(var,v)
+  CHARACTER(LEN=*), INTENT(IN)  :: var
+  REAL,             INTENT(OUT) :: v(:,:,:)
+  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
+  CALL err(NF90_GET_VAR(fID,vID,v),"get",var)
+END SUBROUTINE get_var3
+
+
+SUBROUTINE err(ierr,typ,nam)
+  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
+  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
+  CHARACTER(LEN=*), INTENT(IN) :: nam    !--- FIELD/FILE NAME
+  IF(ierr==NF90_NoERR) RETURN
+  SELECT CASE(typ)
+    CASE('inq');   msg="Field <"//TRIM(nam)//"> is missing"
+    CASE('get');   msg="Reading failed for <"//TRIM(nam)//">"
+    CASE('open');  msg="File opening failed for <"//TRIM(nam)//">"
+    CASE('close'); msg="File closing failed for <"//TRIM(nam)//">"
+  END SELECT
+  CALL ABORT_gcm(TRIM(modname),TRIM(msg),ierr)
+END SUBROUTINE err
+
+END SUBROUTINE dynetat0
Index: DZ5/branches/testing/libf/dyn3d/dynredem.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d/dynredem.F	(revision 2407)
+++ 	(revision )
@@ -1,662 +1,0 @@
-!
-! $Id$
-!
-c
-      SUBROUTINE dynredem0(fichnom,iday_end,phis)
-#ifdef CPP_IOIPSL
-      USE IOIPSL
-#endif
-      USE infotrac
-      use netcdf95, only: NF95_PUT_VAR
- 
-      IMPLICIT NONE
-c=======================================================================
-c Ecriture du fichier de redemarrage sous format NetCDF (initialisation)
-c=======================================================================
-c   Declarations:
-c   -------------
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom2.h"
-#include "temps.h"
-#include "ener.h"
-#include "logic.h"
-#include "netcdf.inc"
-#include "description.h"
-#include "serre.h"
-#include "iniprint.h"
-
-c   Arguments:
-c   ----------
-      INTEGER iday_end
-      REAL phis(iip1, jjp1)
-      CHARACTER*(*) fichnom
-
-c   Local:
-c   ------
-      INTEGER iq,l
-      INTEGER length
-      PARAMETER (length = 100)
-      REAL tab_cntrl(length) ! tableau des parametres du run
-      INTEGER ierr
-      character*20 modname
-      character*80 abort_message
-
-c   Variables locales pour NetCDF:
-c
-      INTEGER dims2(2), dims3(3), dims4(4)
-      INTEGER idim_index
-      INTEGER idim_rlonu, idim_rlonv, idim_rlatu, idim_rlatv
-      INTEGER idim_s, idim_sig
-      INTEGER idim_tim
-      INTEGER nid,nvarid
-
-      REAL zan0,zjulian,hours
-      INTEGER yyears0,jjour0, mmois0
-      character*30 unites
-
-
-c-----------------------------------------------------------------------
-      modname='dynredem0'
-
-#ifdef CPP_IOIPSL
-      call ymds2ju(annee_ref, 1, iday_end, 0.0, zjulian)
-      call ju2ymds(zjulian, yyears0, mmois0, jjour0, hours)
-#else
-! set yyears0, mmois0, jjour0 to 0,1,1 (hours is not used)
-      yyears0=0
-      mmois0=1
-      jjour0=1
-#endif        
-
-      DO l=1,length
-       tab_cntrl(l) = 0.
-      ENDDO
-       tab_cntrl(1)  = REAL(iim)
-       tab_cntrl(2)  = REAL(jjm)
-       tab_cntrl(3)  = REAL(llm)
-       tab_cntrl(4)  = REAL(day_ref)
-       tab_cntrl(5)  = REAL(annee_ref)
-       tab_cntrl(6)  = rad
-       tab_cntrl(7)  = omeg
-       tab_cntrl(8)  = g
-       tab_cntrl(9)  = cpp
-       tab_cntrl(10) = kappa
-       tab_cntrl(11) = daysec
-       tab_cntrl(12) = dtvr
-       tab_cntrl(13) = etot0
-       tab_cntrl(14) = ptot0
-       tab_cntrl(15) = ztot0
-       tab_cntrl(16) = stot0
-       tab_cntrl(17) = ang0
-       tab_cntrl(18) = pa
-       tab_cntrl(19) = preff
-c
-c    .....    parametres  pour le zoom      ......   
-
-       tab_cntrl(20)  = clon
-       tab_cntrl(21)  = clat
-       tab_cntrl(22)  = grossismx
-       tab_cntrl(23)  = grossismy
-c
-      IF ( fxyhypb )   THEN
-       tab_cntrl(24) = 1.
-       tab_cntrl(25) = dzoomx
-       tab_cntrl(26) = dzoomy
-       tab_cntrl(27) = 0.
-       tab_cntrl(28) = taux
-       tab_cntrl(29) = tauy
-      ELSE
-       tab_cntrl(24) = 0.
-       tab_cntrl(25) = dzoomx
-       tab_cntrl(26) = dzoomy
-       tab_cntrl(27) = 0.
-       tab_cntrl(28) = 0.
-       tab_cntrl(29) = 0.
-       IF( ysinus )  tab_cntrl(27) = 1.
-      ENDIF
-
-       tab_cntrl(30) = REAL(iday_end)
-       tab_cntrl(31) = REAL(itau_dyn + itaufin)
-c start_time: start_time of simulation (not necessarily 0.)
-       tab_cntrl(32) = start_time
-c
-c    .........................................................
-c
-c Creation du fichier:
-c
-      ierr = NF_CREATE(fichnom, NF_CLOBBER, nid)
-      IF (ierr.NE.NF_NOERR) THEN
-         write(lunout,*)"dynredem0: Pb d ouverture du fichier "
-     &                  //trim(fichnom)
-         write(lunout,*)' ierr = ', ierr
-         CALL ABORT_GCM("DYNREDEM0", "", 1)
-      ENDIF
-c
-c Preciser quelques attributs globaux:
-c
-      ierr = NF_PUT_ATT_TEXT (nid, NF_GLOBAL, "title", 27,
-     .                       "Fichier demmarage dynamique")
-c
-c Definir les dimensions du fichiers:
-c
-      ierr = NF_DEF_DIM (nid, "index", length, idim_index)
-      ierr = NF_DEF_DIM (nid, "rlonu", iip1, idim_rlonu)
-      ierr = NF_DEF_DIM (nid, "rlatu", jjp1, idim_rlatu)
-      ierr = NF_DEF_DIM (nid, "rlonv", iip1, idim_rlonv)
-      ierr = NF_DEF_DIM (nid, "rlatv", jjm, idim_rlatv)
-      ierr = NF_DEF_DIM (nid, "sigs", llm, idim_s)
-      ierr = NF_DEF_DIM (nid, "sig", llmp1, idim_sig)
-      ierr = NF_DEF_DIM (nid, "temps", NF_UNLIMITED, idim_tim)
-c
-      ierr = NF_ENDDEF(nid) ! sortir du mode de definition
-c
-c Definir et enregistrer certains champs invariants:
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"controle",NF_DOUBLE,1,idim_index,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"controle",NF_FLOAT,1,idim_index,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 22,
-     .                       "Parametres de controle")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,tab_cntrl)
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"rlonu",NF_DOUBLE,1,idim_rlonu,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"rlonu",NF_FLOAT,1,idim_rlonu,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 23,
-     .                       "Longitudes des points U")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,rlonu)
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"rlatu",NF_DOUBLE,1,idim_rlatu,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"rlatu",NF_FLOAT,1,idim_rlatu,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 22,
-     .                       "Latitudes des points U")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR (nid,nvarid,rlatu)
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"rlonv",NF_DOUBLE,1,idim_rlonv,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"rlonv",NF_FLOAT,1,idim_rlonv,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 23,
-     .                       "Longitudes des points V")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,rlonv)
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"rlatv",NF_DOUBLE,1,idim_rlatv,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"rlatv",NF_FLOAT,1,idim_rlatv,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 22,
-     .                       "Latitudes des points V")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,rlatv)
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"nivsigs",NF_DOUBLE,1,idim_s,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"nivsigs",NF_FLOAT,1,idim_s,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 28,
-     .                       "Numero naturel des couches s")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,nivsigs)
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"nivsig",NF_DOUBLE,1,idim_sig,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"nivsig",NF_FLOAT,1,idim_sig,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 32,
-     .                       "Numero naturel des couches sigma")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,nivsig)
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"ap",NF_DOUBLE,1,idim_sig,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"ap",NF_FLOAT,1,idim_sig,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 26,
-     .                       "Coefficient A pour hybride")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,ap)
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"bp",NF_DOUBLE,1,idim_sig,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"bp",NF_FLOAT,1,idim_sig,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 26,
-     .                       "Coefficient B pour hybride")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,bp)
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"presnivs",NF_DOUBLE,1,idim_s,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"presnivs",NF_FLOAT,1,idim_s,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,presnivs)
-c
-c Coefficients de passage cov. <-> contra. <--> naturel
-c
-      ierr = NF_REDEF (nid)
-      dims2(1) = idim_rlonu
-      dims2(2) = idim_rlatu
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"cu",NF_DOUBLE,2,dims2,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"cu",NF_FLOAT,2,dims2,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 29,
-     .                       "Coefficient de passage pour U")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,cu)
-c
-      ierr = NF_REDEF (nid)
-      dims2(1) = idim_rlonv
-      dims2(2) = idim_rlatv
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"cv",NF_DOUBLE,2,dims2,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"cv",NF_FLOAT,2,dims2,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 29,
-     .                       "Coefficient de passage pour V")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,cv)
-c
-c Aire de chaque maille:
-c
-      ierr = NF_REDEF (nid)
-      dims2(1) = idim_rlonv
-      dims2(2) = idim_rlatu
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"aire",NF_DOUBLE,2,dims2,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"aire",NF_FLOAT,2,dims2,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 22,
-     .                       "Aires de chaque maille")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,aire)
-c
-c Geopentiel au sol:
-c
-      ierr = NF_REDEF (nid)
-      dims2(1) = idim_rlonv
-      dims2(2) = idim_rlatu
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"phisinit",NF_DOUBLE,2,dims2,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"phisinit",NF_FLOAT,2,dims2,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 19,
-     .                       "Geopotentiel au sol")
-      ierr = NF_ENDDEF(nid)
-      call NF95_PUT_VAR(nid,nvarid,phis)
-c
-c Definir les variables pour pouvoir les enregistrer plus tard:
-c
-      ierr = NF_REDEF (nid) ! entrer dans le mode de definition
-c
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"temps",NF_DOUBLE,1,idim_tim,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"temps",NF_FLOAT,1,idim_tim,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 19,
-     .                       "Temps de simulation")
-      write(unites,200)yyears0,mmois0,jjour0
-200   format('days since ',i4,'-',i2.2,'-',i2.2,' 00:00:00')
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "units", 30,
-     .                         unites)
-
-c
-      dims4(1) = idim_rlonu
-      dims4(2) = idim_rlatu
-      dims4(3) = idim_s
-      dims4(4) = idim_tim
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"ucov",NF_DOUBLE,4,dims4,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"ucov",NF_FLOAT,4,dims4,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 9,
-     .                       "Vitesse U")
-c
-      dims4(1) = idim_rlonv
-      dims4(2) = idim_rlatv
-      dims4(3) = idim_s
-      dims4(4) = idim_tim
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"vcov",NF_DOUBLE,4,dims4,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"vcov",NF_FLOAT,4,dims4,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 9,
-     .                       "Vitesse V")
-c
-      dims4(1) = idim_rlonv
-      dims4(2) = idim_rlatu
-      dims4(3) = idim_s
-      dims4(4) = idim_tim
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"teta",NF_DOUBLE,4,dims4,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"teta",NF_FLOAT,4,dims4,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 11,
-     .                       "Temperature")
-c
-      dims4(1) = idim_rlonv
-      dims4(2) = idim_rlatu
-      dims4(3) = idim_s
-      dims4(4) = idim_tim
-      IF(nqtot.GE.1) THEN
-      DO iq=1,nqtot
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,tname(iq),NF_DOUBLE,4,dims4,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,tname(iq),NF_FLOAT,4,dims4,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 12,ttext(iq))
-      ENDDO
-      ENDIF
-c
-      dims4(1) = idim_rlonv
-      dims4(2) = idim_rlatu
-      dims4(3) = idim_s
-      dims4(4) = idim_tim
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"masse",NF_DOUBLE,4,dims4,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"masse",NF_FLOAT,4,dims4,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 12,
-     .                       "C est quoi ?")
-c
-      dims3(1) = idim_rlonv
-      dims3(2) = idim_rlatu
-      dims3(3) = idim_tim
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"ps",NF_DOUBLE,3,dims3,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"ps",NF_FLOAT,3,dims3,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 15,
-     .                       "Pression au sol")
-c
-      ierr = NF_ENDDEF(nid) ! sortir du mode de definition
-      ierr = NF_CLOSE(nid) ! fermer le fichier
-
-      write(lunout,*)'dynredem0: iim,jjm,llm,iday_end',
-     &               iim,jjm,llm,iday_end
-      write(lunout,*)'dynredem0: rad,omeg,g,cpp,kappa',
-     &        rad,omeg,g,cpp,kappa
-
-      RETURN
-      END
-      SUBROUTINE dynredem1(fichnom,time,
-     .                     vcov,ucov,teta,q,masse,ps)
-      USE infotrac
-      USE control_mod
-      use netcdf, only: NF90_get_VAR
-      use netcdf95, only: NF95_PUT_VAR
- 
-      IMPLICIT NONE
-c=================================================================
-c  Ecriture du fichier de redemarrage sous format NetCDF
-c=================================================================
-#include "dimensions.h"
-#include "paramet.h"
-#include "description.h"
-#include "netcdf.inc"
-#include "comvert.h"
-#include "comgeom.h"
-#include "temps.h"
-#include "iniprint.h"
-
-
-      INTEGER l
-      REAL vcov(iip1,jjm,llm),ucov(iip1, jjp1,llm) 
-      REAL teta(iip1, jjp1,llm)                   
-      REAL ps(iip1, jjp1),masse(iip1, jjp1,llm)                   
-      REAL q(iip1, jjp1, llm, nqtot)
-      CHARACTER*(*) fichnom
-     
-      REAL time
-      INTEGER nid, nvarid, nid_trac, nvarid_trac
-      REAL trac_tmp(ip1jmp1,llm)      
-      INTEGER ierr, ierr_file 
-      INTEGER iq
-      INTEGER length
-      PARAMETER (length = 100)
-      REAL tab_cntrl(length) ! tableau des parametres du run
-      character*20 modname
-      character*80 abort_message
-c
-      INTEGER nb
-      SAVE nb
-      DATA nb / 0 /
-
-      modname = 'dynredem1'
-      ierr = NF_OPEN(fichnom, NF_WRITE, nid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynredem1: Pb. d ouverture "//trim(fichnom)
-         call abort_gcm("dynredem1", "", 1)
-      ENDIF
-
-c  Ecriture/extension de la coordonnee temps
-
-      nb = nb + 1
-      ierr = NF_INQ_VARID(nid, "temps", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*) NF_STRERROR(ierr)
-         abort_message='Variable temps n est pas definie'
-         CALL abort_gcm(modname,abort_message,ierr)
-      ENDIF
-      call NF95_PUT_VAR(nid,nvarid,time,start=(/nb/))
-      write(lunout,*) "dynredem1: Enregistrement pour ", nb, time
-
-c
-c  Re-ecriture du tableau de controle, itaufin n'est plus defini quand
-c  on passe dans dynredem0
-      ierr = NF_INQ_VARID (nid, "controle", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         abort_message="dynredem1: Le champ <controle> est absent"
-         ierr = 1
-         CALL abort_gcm(modname,abort_message,ierr)
-      ENDIF
-      ierr = NF90_GET_VAR(nid, nvarid, tab_cntrl)
-       tab_cntrl(31) = REAL(itau_dyn + itaufin)
-      call NF95_PUT_VAR(nid,nvarid,tab_cntrl)
-
-c  Ecriture des champs
-c
-      ierr = NF_INQ_VARID(nid, "ucov", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         abort_message="Variable ucov n est pas definie"
-         ierr=1
-         CALL abort_gcm(modname,abort_message,ierr)
-      ENDIF
-      call NF95_PUT_VAR(nid,nvarid,ucov)
-
-      ierr = NF_INQ_VARID(nid, "vcov", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         abort_message="Variable vcov n est pas definie"
-         ierr=1
-         CALL abort_gcm(modname,abort_message,ierr)
-      ENDIF
-      call NF95_PUT_VAR(nid,nvarid,vcov)
-
-      ierr = NF_INQ_VARID(nid, "teta", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         abort_message="Variable teta n est pas definie"
-         ierr=1
-         CALL abort_gcm(modname,abort_message,ierr)
-      ENDIF
-      call NF95_PUT_VAR(nid,nvarid,teta)
-
-      IF (type_trac == 'inca') THEN
-! Ajout Anne pour lecture valeurs traceurs dans un fichier start_trac.nc
-         ierr_file = NF_OPEN ("start_trac.nc", NF_NOWRITE,nid_trac)
-         IF (ierr_file .NE.NF_NOERR) THEN
-            write(lunout,*)'dynredem1: Pb d''ouverture du fichier',
-     &                     ' start_trac.nc'
-            write(lunout,*)' ierr = ', ierr_file 
-         ENDIF
-      END IF
-
-      IF(nqtot.GE.1) THEN
-      do iq=1,nqtot 
-
-         IF (type_trac /= 'inca') THEN
-            ierr = NF_INQ_VARID(nid, tname(iq), nvarid)
-            IF (ierr .NE. NF_NOERR) THEN
-               abort_message="Variable  tname(iq) n est pas definie"
-               ierr=1
-               CALL abort_gcm(modname,abort_message,ierr)
-            ENDIF
-            call NF95_PUT_VAR(nid,nvarid,q(:,:,:,iq))
-        ELSE ! type_trac = inca
-! lecture de la valeur du traceur dans start_trac.nc
-           IF (ierr_file .ne. 2) THEN
-             ierr = NF_INQ_VARID (nid_trac, tname(iq), nvarid_trac)
-             IF (ierr .NE. NF_NOERR) THEN
-                write(lunout,*) "dynredem1: ",trim(tname(iq)),
-     &                          " est absent de start_trac.nc"
-                ierr = NF_INQ_VARID(nid, tname(iq), nvarid)
-                IF (ierr .NE. NF_NOERR) THEN
-                   abort_message="dynredem1: Variable "//
-     &                     trim(tname(iq))//" n est pas definie"
-                   ierr=1
-                   CALL abort_gcm(modname,abort_message,ierr)
-                ENDIF
-                call NF95_PUT_VAR(nid,nvarid,q(:,:,:,iq))
-                
-             ELSE
-                write(lunout,*) "dynredem1: ",trim(tname(iq)),
-     &              " est present dans start_trac.nc"
-               ierr = NF90_GET_VAR(nid_trac, nvarid_trac, trac_tmp)
-                IF (ierr .NE. NF_NOERR) THEN
-                   abort_message="dynredem1: Lecture echouee pour"//
-     &                    trim(tname(iq))
-                   ierr=1
-                   CALL abort_gcm(modname,abort_message,ierr)
-                ENDIF
-                ierr = NF_INQ_VARID(nid, tname(iq), nvarid)
-                IF (ierr .NE. NF_NOERR) THEN
-                   abort_message="dynredem1: Variable "//
-     &                trim(tname(iq))//" n est pas definie"
-                   ierr=1
-                   CALL abort_gcm(modname,abort_message,ierr)
-                ENDIF
-                call NF95_PUT_VAR(nid, nvarid, trac_tmp)
-               
-             ENDIF ! IF (ierr .NE. NF_NOERR)
-! fin lecture du traceur
-          ELSE                  ! si il n'y a pas de fichier start_trac.nc
-!             print *, 'il n y a pas de fichier start_trac'
-             ierr = NF_INQ_VARID(nid, tname(iq), nvarid)
-             IF (ierr .NE. NF_NOERR) THEN
-                abort_message="dynredem1: Variable "//
-     &                trim(tname(iq))//" n est pas definie"
-                   ierr=1
-                   CALL abort_gcm(modname,abort_message,ierr)
-             ENDIF
-             call NF95_PUT_VAR(nid,nvarid,q(:,:,:,iq))
-          ENDIF ! (ierr_file .ne. 2)
-       END IF   !type_trac
-      
-      ENDDO
-      ENDIF
-c
-      ierr = NF_INQ_VARID(nid, "masse", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         abort_message="dynredem1: Variable masse n est pas definie"
-         ierr=1
-         CALL abort_gcm(modname,abort_message,ierr)
-      ENDIF
-      call NF95_PUT_VAR(nid,nvarid,masse)
-c
-      ierr = NF_INQ_VARID(nid, "ps", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         abort_message="dynredem1: Variable ps n est pas definie"
-         ierr=1
-         CALL abort_gcm(modname,abort_message,ierr)
-      ENDIF
-      call NF95_PUT_VAR(nid,nvarid,ps)
-
-      ierr = NF_CLOSE(nid)
-c
-      RETURN
-      END
-
Index: /LMDZ5/branches/testing/libf/dyn3d/dynredem.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d/dynredem.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d/dynredem.F90	(revision 2408)
@@ -0,0 +1,247 @@
+SUBROUTINE dynredem0(fichnom,iday_end,phis)
+!
+!-------------------------------------------------------------------------------
+! Write the NetCDF restart file (initialization).
+!-------------------------------------------------------------------------------
+#ifdef CPP_IOIPSL
+  USE IOIPSL
+#endif
+  USE infotrac
+  USE netcdf, ONLY: NF90_CREATE, NF90_DEF_DIM, NF90_INQ_VARID, NF90_GLOBAL,    &
+                    NF90_CLOSE,  NF90_PUT_ATT, NF90_UNLIMITED, NF90_CLOBBER
+  USE dynredem_mod, ONLY: cre_var, put_var1, put_var2, err, modname, fil
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comconst.h"
+  include "comvert.h"
+  include "comgeom2.h"
+  include "temps.h"
+  include "ener.h"
+  include "logic.h"
+  include "description.h"
+  include "serre.h"
+  include "iniprint.h"
+!===============================================================================
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN) :: fichnom          !--- FILE NAME
+  INTEGER,          INTENT(IN) :: iday_end         !--- 
+  REAL,             INTENT(IN) :: phis(iip1, jjp1) !--- GROUND GEOPOTENTIAL
+!===============================================================================
+! Local variables:
+  INTEGER :: iq, l
+  INTEGER, PARAMETER :: length=100
+  REAL    :: tab_cntrl(length)                     !--- RUN PARAMETERS TABLE
+!   For NetCDF:
+  CHARACTER(LEN=30) :: unites
+  INTEGER :: indexID
+  INTEGER :: rlonuID, rlonvID, rlatuID, rlatvID
+  INTEGER :: sID, sigID, nID, vID, timID
+  INTEGER :: yyears0, jjour0, mmois0
+  REAL    :: zan0, zjulian, hours
+!===============================================================================
+  modname='dynredem0'; fil=fichnom
+#ifdef CPP_IOIPSL
+  CALL ymds2ju(annee_ref, 1, iday_end, 0.0, zjulian)
+  CALL ju2ymds(zjulian, yyears0, mmois0, jjour0, hours)
+#else
+! set yyears0, mmois0, jjour0 to 0,1,1 (hours is not used)
+  yyears0=0
+  mmois0=1
+  jjour0=1
+#endif        
+
+  tab_cntrl(:)  = 0.
+  tab_cntrl(1)  = REAL(iim)
+  tab_cntrl(2)  = REAL(jjm)
+  tab_cntrl(3)  = REAL(llm)
+  tab_cntrl(4)  = REAL(day_ref)
+  tab_cntrl(5)  = REAL(annee_ref)
+  tab_cntrl(6)  = rad
+  tab_cntrl(7)  = omeg
+  tab_cntrl(8)  = g
+  tab_cntrl(9)  = cpp
+  tab_cntrl(10) = kappa
+  tab_cntrl(11) = daysec
+  tab_cntrl(12) = dtvr
+  tab_cntrl(13) = etot0
+  tab_cntrl(14) = ptot0
+  tab_cntrl(15) = ztot0
+  tab_cntrl(16) = stot0
+  tab_cntrl(17) = ang0
+  tab_cntrl(18) = pa
+  tab_cntrl(19) = preff
+
+!    .....    parameters for zoom    ......   
+  tab_cntrl(20) = clon
+  tab_cntrl(21) = clat
+  tab_cntrl(22) = grossismx
+  tab_cntrl(23) = grossismy
+!
+  IF ( fxyhypb )   THEN
+    tab_cntrl(24) = 1.
+    tab_cntrl(25) = dzoomx
+    tab_cntrl(26) = dzoomy
+    tab_cntrl(27) = 0.
+    tab_cntrl(28) = taux
+    tab_cntrl(29) = tauy
+  ELSE
+    tab_cntrl(24) = 0.
+    tab_cntrl(25) = dzoomx
+    tab_cntrl(26) = dzoomy
+    tab_cntrl(27) = 0.
+    tab_cntrl(28) = 0.
+    tab_cntrl(29) = 0.
+    IF( ysinus )  tab_cntrl(27) = 1.
+  END IF
+  tab_cntrl(30) = REAL(iday_end)
+  tab_cntrl(31) = REAL(itau_dyn + itaufin)
+! start_time: start_time of simulation (not necessarily 0.)
+  tab_cntrl(32) = start_time
+
+!--- File creation
+  CALL err(NF90_CREATE(fichnom,NF90_CLOBBER,nid))
+
+!--- Some global attributes
+  CALL err(NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier demarrage dynamique"))
+
+!--- Dimensions
+  CALL err(NF90_DEF_DIM(nid,"index", length, indexID))
+  CALL err(NF90_DEF_DIM(nid,"rlonu", iip1,   rlonuID))
+  CALL err(NF90_DEF_DIM(nid,"rlatu", jjp1,   rlatuID))
+  CALL err(NF90_DEF_DIM(nid,"rlonv", iip1,   rlonvID))
+  CALL err(NF90_DEF_DIM(nid,"rlatv", jjm,    rlatvID))
+  CALL err(NF90_DEF_DIM(nid,"sigs",  llm,        sID))
+  CALL err(NF90_DEF_DIM(nid,"sig",   llmp1,    sigID))
+  CALL err(NF90_DEF_DIM(nid,"temps", NF90_UNLIMITED, timID))
+
+!--- Define and save invariant fields
+  CALL put_var1(nid,"controle","Parametres de controle" ,[indexID],tab_cntrl)
+  CALL put_var1(nid,"rlonu"   ,"Longitudes des points U",[rlonuID],rlonu)
+  CALL put_var1(nid,"rlatu"   ,"Latitudes des points U" ,[rlatuID],rlatu)
+  CALL put_var1(nid,"rlonv"   ,"Longitudes des points V",[rlonvID],rlonv)
+  CALL put_var1(nid,"rlatv"   ,"Latitudes des points V" ,[rlatvID],rlatv)
+  CALL put_var1(nid,"nivsigs" ,"Numero naturel des couches s"    ,[sID]  ,nivsigs)
+  CALL put_var1(nid,"nivsig"  ,"Numero naturel des couches sigma",[sigID],nivsig)
+  CALL put_var1(nid,"ap"      ,"Coefficient A pour hybride"      ,[sigID],ap)
+  CALL put_var1(nid,"bp"      ,"Coefficient B pour hybride"      ,[sigID],bp)
+  CALL put_var1(nid,"presnivs",""                                ,[sID]  ,presnivs)
+! covariant <-> contravariant <-> natural conversion coefficients
+  CALL put_var2(nid,"cu","Coefficient de passage pour U",[rlonuID,rlatuID],cu)
+  CALL put_var2(nid,"cv","Coefficient de passage pour V",[rlonvID,rlatvID],cv)
+  CALL put_var2(nid,"aire","Aires de chaque maille"     ,[rlonvID,rlatuID],aire)
+  CALL put_var2(nid,"phisinit","Geopotentiel au sol"    ,[rlonvID,rlatuID],phis)
+
+!--- Define fields saved later
+  WRITE(unites,"('days since ',i4,'-',i2.2,'-',i2.2,' 00:00:00')"),&
+               yyears0,mmois0,jjour0
+  CALL cre_var(nid,"temps","Temps de simulation",[timID],unites)
+  CALL cre_var(nid,"ucov" ,"Vitesse U"  ,[rlonuID,rlatuID,sID,timID])
+  CALL cre_var(nid,"vcov" ,"Vitesse V"  ,[rlonvID,rlatvID,sID,timID])
+  CALL cre_var(nid,"teta" ,"Temperature",[rlonvID,rlatuID,sID,timID])
+  DO iq=1,nqtot
+    CALL cre_var(nid,tname(iq),ttext(iq),[rlonvID,rlatuID,sID,timID])
+  END DO
+  CALL cre_var(nid,"masse","Masse d air"    ,[rlonvID,rlatuID,sID,timID])
+  CALL cre_var(nid,"ps"   ,"Pression au sol",[rlonvID,rlatuID    ,timID])
+  CALL err(NF90_CLOSE (nid))
+
+  WRITE(lunout,*)TRIM(modname)//': iim,jjm,llm,iday_end',iim,jjm,llm,iday_end
+  WRITE(lunout,*)TRIM(modname)//': rad,omeg,g,cpp,kappa',rad,omeg,g,cpp,kappa
+
+END SUBROUTINE dynredem0
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE dynredem1(fichnom,time,vcov,ucov,teta,q,masse,ps)
+!
+!-------------------------------------------------------------------------------
+! Purpose: Write the NetCDF restart file (append).
+!-------------------------------------------------------------------------------
+  USE infotrac
+  USE control_mod
+  USE netcdf,   ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_GET_VAR, NF90_INQ_VARID,  &
+                      NF90_CLOSE, NF90_WRITE,   NF90_PUT_VAR, NF90_NoErr
+  USE dynredem_mod, ONLY: dynredem_write_u, dynredem_write_v, dynredem_read_u, &
+                          err, modname, fil, msg
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "description.h"
+  include "comvert.h"
+  include "comgeom.h"
+  include "temps.h"
+  include "iniprint.h"
+!===============================================================================
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN) :: fichnom              !-- FILE NAME
+  REAL, INTENT(IN)    ::  time                         !-- TIME
+  REAL, INTENT(IN)    ::  vcov(iip1,jjm, llm)          !-- V COVARIANT WIND
+  REAL, INTENT(IN)    ::  ucov(iip1,jjp1,llm)          !-- U COVARIANT WIND
+  REAL, INTENT(IN)    ::  teta(iip1,jjp1,llm)          !-- POTENTIAL TEMPERATURE
+  REAL, INTENT(INOUT) ::     q(iip1,jjp1,llm,nqtot)    !-- TRACERS
+  REAL, INTENT(IN)    :: masse(iip1,jjp1,llm)          !-- MASS PER CELL
+  REAL, INTENT(IN)    ::    ps(iip1,jjp1)              !-- GROUND PRESSURE
+!===============================================================================
+! Local variables:
+  INTEGER :: l, iq, nid, vID, ierr, nid_trac, vID_trac
+  INTEGER, SAVE :: nb=0
+  INTEGER, PARAMETER :: length=100
+  REAL               :: tab_cntrl(length) ! tableau des parametres du run
+  CHARACTER(LEN=256) :: var, dum
+  LOGICAL            :: lread_inca
+!===============================================================================
+
+  modname='dynredem1'; fil=fichnom
+  CALL err(NF90_OPEN(fil,NF90_WRITE,nid),"open",fil)
+
+!--- Write/extend time coordinate
+  nb = nb + 1
+  var="temps"
+  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
+  CALL err(NF90_PUT_VAR(nid,vID,[time]),"put",var)
+  WRITE(lunout,*)TRIM(modname)//": Saving for ", nb, time
+
+!--- Rewrite control table (itaufin undefined in dynredem0)
+  var="controle"
+  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
+  CALL err(NF90_GET_VAR(nid,vID,tab_cntrl),"get",var)
+  tab_cntrl(31)=DBLE(itau_dyn + itaufin)
+  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
+  CALL err(NF90_PUT_VAR(nid,vID,tab_cntrl),"put",var)
+
+!--- Save fields
+  CALL dynredem_write_u(nid,"ucov" ,ucov ,llm)
+  CALL dynredem_write_v(nid,"vcov" ,vcov ,llm)
+  CALL dynredem_write_u(nid,"teta" ,teta ,llm)
+  CALL dynredem_write_u(nid,"masse",masse,llm)
+  CALL dynredem_write_u(nid,"ps"   ,ps   ,1)
+
+!--- Tracers in file "start_trac.nc" (added by Anne)
+  lread_inca=.FALSE.; fil="start_trac.nc"
+  IF(type_trac=='inca') INQUIRE(FILE=fil,EXIST=lread_inca)
+  IF(lread_inca) CALL err(NF90_OPEN(fil,NF90_NOWRITE,nid_trac),"open")
+
+!--- Save tracers
+  DO iq=1,nqtot; var=tname(iq); ierr=-1
+    IF(lread_inca) THEN                  !--- Possibly read from "start_trac.nc"
+      fil="start_trac.nc"
+      ierr=NF90_INQ_VARID(nid_trac,var,vID_trac)
+      dum='inq'; IF(ierr==NF90_NoErr) dum='fnd'
+      WRITE(lunout,*)msg(dum,var)
+
+
+      IF(ierr==NF90_NoErr) CALL dynredem_read_u(nid_trac,var,q(:,:,:,iq),llm)
+    END IF
+    fil=fichnom
+    CALL dynredem_write_u(nid,var,q(:,:,:,iq),llm)
+  END DO
+  CALL err(NF90_CLOSE(nid),"close")
+  fil="start_trac.nc"
+  IF(lread_inca) CALL err(NF90_CLOSE(nid_trac),"close")
+
+END SUBROUTINE dynredem1
+
Index: /LMDZ5/branches/testing/libf/dyn3d/dynredem_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d/dynredem_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d/dynredem_mod.F90	(revision 2408)
@@ -0,0 +1,219 @@
+MODULE dynredem_mod
+
+  USE netcdf
+  PRIVATE
+  PUBLIC :: dynredem_write_u, dynredem_write_v, dynredem_read_u, err
+  PUBLIC :: cre_var, get_var1, put_var1, put_var2, fil, modname, msg
+  include "dimensions.h"
+  include "paramet.h"
+  CHARACTER(LEN=256), SAVE :: fil, modname
+  INTEGER,            SAVE :: nvarid
+
+
+CONTAINS
+
+
+!===============================================================================
+!
+SUBROUTINE dynredem_write_u(ncid,id,var,ll)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,          INTENT(IN) :: ncid
+  CHARACTER(LEN=*), INTENT(IN) :: id
+  REAL,             INTENT(IN) :: var(iip1,jjp1,ll)
+  INTEGER,          INTENT(IN) :: ll
+!===============================================================================
+! Local variables:
+  INTEGER :: start(4), count(4)
+!===============================================================================
+  start(:)=[1,1,1,1]; count(:)=[iip1,jjp1,ll,1]
+  CALL err(NF90_INQ_VARID(ncid,id,nvarid),"inq",id)
+  CALL err(NF90_PUT_VAR(ncid,nvarid,var,start,count),"put",id)
+  
+END SUBROUTINE dynredem_write_u
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+SUBROUTINE dynredem_write_v(ncid,id,var,ll)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,          INTENT(IN) :: ncid
+  CHARACTER(LEN=*), INTENT(IN) :: id
+  REAL,             INTENT(IN) :: var(iip1,jjm,ll)
+  INTEGER,          INTENT(IN) :: ll
+!===============================================================================
+! Local variables:
+  INTEGER :: start(4), count(4)
+!===============================================================================
+  start(:)=[1,1,1,1]; count(:)=[iip1,jjm,ll,1]
+  CALL err(NF90_INQ_VARID(ncid,id,nvarid),"inq",id)
+  CALL err(NF90_PUT_VAR(ncid,nvarid,var,start,count),"put",id)
+  
+END SUBROUTINE dynredem_write_v
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+SUBROUTINE dynredem_read_u(ncid,id,var,ll)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,          INTENT(IN)  :: ncid
+  CHARACTER(LEN=*), INTENT(IN)  :: id
+  REAL,             INTENT(OUT) :: var(iip1,jjp1,ll)
+  INTEGER,          INTENT(IN)  :: ll
+!===============================================================================
+! Local variables:
+  INTEGER :: start(4), count(4)
+!===============================================================================
+  start(:)=[1,1,1,1]; count(:)=[iip1,jjp1,ll,1]
+  CALL err(NF90_INQ_VARID(ncid,id,nvarid),"inq",id)
+  CALL err(NF90_GET_VAR(ncid,nvarid,var,start,count),"get",id)
+  
+END SUBROUTINE dynredem_read_u    
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+SUBROUTINE cre_var(ncid,var,title,did,units)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,                    INTENT(IN) :: ncid
+  CHARACTER(LEN=*),           INTENT(IN) :: var, title
+  INTEGER,                    INTENT(IN) :: did(:)
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: units
+!===============================================================================
+#ifdef NC_DOUBLE
+  CALL err(NF90_DEF_VAR(ncid,var,NF90_DOUBLE,did,nvarid),"inq",var)
+#else
+  CALL err(NF90_DEF_VAR(ncid,var,NF90_FLOAT ,did,nvarid),"inq",var)
+#endif
+  IF(title/="")      CALL err(NF90_PUT_ATT(ncid,nvarid,"title",title),var)
+  IF(PRESENT(units)) CALL err(NF90_PUT_ATT(ncid,nvarid,"units",units),var)
+
+END SUBROUTINE cre_var
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+SUBROUTINE put_var1(ncid,var,title,did,v,units)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,                    INTENT(IN) :: ncid
+  CHARACTER(LEN=*),           INTENT(IN) :: var, title
+  INTEGER,                    INTENT(IN) :: did(1)
+  REAL,                       INTENT(IN) :: v(:)
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: units
+!===============================================================================
+  IF(     PRESENT(units)) CALL cre_var(ncid,var,title,did,units)
+  IF(.NOT.PRESENT(units)) CALL cre_var(ncid,var,title,did)
+  CALL err(NF90_ENDDEF(ncid))
+  CALL err(NF90_PUT_VAR(ncid,nvarid,v),"put",var)
+  CALL err(NF90_REDEF(ncid))
+
+END SUBROUTINE put_var1
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+SUBROUTINE put_var2(ncid,var,title,did,v,units)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,                    INTENT(IN) :: ncid
+  CHARACTER(LEN=*),           INTENT(IN) :: var, title
+  INTEGER,                    INTENT(IN) :: did(2)
+  REAL,                       INTENT(IN) :: v(:,:)
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: units
+!===============================================================================
+  IF(     PRESENT(units)) CALL cre_var(ncid,var,title,did,units)
+  IF(.NOT.PRESENT(units)) CALL cre_var(ncid,var,title,did)
+  CALL err(NF90_ENDDEF(ncid))
+  CALL err(NF90_PUT_VAR(ncid,nvarid,v),"put",var)
+  CALL err(NF90_REDEF(ncid))
+
+END SUBROUTINE put_var2
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+FUNCTION msg(typ,nam)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  CHARACTER(LEN=256)                     :: msg    !--- STANDARDIZED MESSAGE
+  CHARACTER(LEN=*),           INTENT(IN) :: typ    !--- TYPE OF OPERATION
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: nam    !--- FIELD NAME
+!===============================================================================
+  SELECT CASE(typ)
+    CASE('open');  msg="Opening failed for <"//TRIM(fil)//">"
+    CASE('close'); msg="Closing failed for <"//TRIM(fil)//">"
+    CASE('get');   msg="Reading failed for <"//TRIM(nam)//">"
+    CASE('put');   msg="Writting failed for <"//TRIM(nam)//">"
+    CASE('inq');   msg="Missing field <"//TRIM(nam)//">"
+    CASE('fnd');   msg="Found field <"//TRIM(nam)//">"
+  END SELECT
+  msg=TRIM(msg)//" in file <"//TRIM(fil)//">"
+
+END FUNCTION msg
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+SUBROUTINE err(ierr,typ,nam)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,                    INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: typ    !--- TYPE OF OPERATION
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: nam    !--- FIELD NAME
+!===============================================================================
+  IF(ierr==NF90_NoERR) RETURN
+  IF(.NOT.PRESENT(typ)) THEN
+    CALL ABORT_gcm(modname,NF90_STRERROR(ierr),ierr)
+  ELSE
+    CALL ABORT_gcm(modname,msg(typ,nam),ierr)
+  END IF
+
+END SUBROUTINE err
+!
+!===============================================================================
+
+END MODULE dynredem_mod   
+    
+    
Index: /LMDZ5/branches/testing/libf/dyn3d/gcm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d/gcm.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dyn3d/gcm.F90	(revision 2408)
@@ -22,10 +22,6 @@
   USE infotrac
   USE control_mod
-
-#ifdef INCA
-  ! Only INCA needs these informations (from the Earth's physics)
-  USE indice_sol_mod
-  USE mod_phys_lmdz_para, ONLY : klon_mpi_para_nb
-#endif
+  USE mod_const_mpi, ONLY: COMM_LMDZ
+
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -34,6 +30,5 @@
   ! dynamique -> physique pour l'initialisation
 #ifdef CPP_PHYS
-  !      USE dimphy
-  !      USE comgeomphy
+  USE iniphysiq_mod, ONLY: iniphysiq
 #endif
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -86,8 +81,4 @@
   include "iniprint.h"
   include "tracstoke.h"
-#ifdef INCA
-  ! Only INCA needs these informations (from the Earth's physics)
-  !include "indicesol.h"
-#endif
 
   REAL zdtvr
@@ -182,8 +173,8 @@
   ! A nettoyer. On ne veut qu'une ou deux routines d'interface 
   ! dynamique -> physique pour l'initialisation
-#ifdef CPP_PHYS
-  CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
-  !      call InitComgeomphy ! now done in iniphysiq
-#endif
+!#ifdef CPP_PHYS
+!  CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
+!  !      call InitComgeomphy ! now done in iniphysiq
+!#endif
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !-----------------------------------------------------------------------
@@ -209,12 +200,4 @@
 #endif
   !-----------------------------------------------------------------------
-
-  IF (type_trac == 'inca') THEN
-#ifdef INCA
-     call init_const_lmdz(nbtr,anneeref,dayref,iphysiq,day_step,nday,  &
-          nbsrf, is_oce,is_sic,is_ter,is_lic)
-     call init_inca_para(iim,jjm+1,klon,1,klon_mpi_para_nb,0)
-#endif
-  END IF
   !
   !
@@ -260,11 +243,4 @@
 
   endif ! of if (read_start)
-
-  IF (type_trac == 'inca') THEN
-#ifdef INCA
-     call init_inca_dim(klon,llm,iim,jjm, &
-          rlonu,rlatu,rlonv,rlatv)
-#endif
-  END IF
 
 
@@ -416,6 +392,8 @@
      ! Physics:
 #ifdef CPP_PHYS
-     CALL iniphysiq(iim,jjm,llm,daysec,day_ini,dtphys/nsplit_phys, &
-          rlatu,rlonv,aire,cu,cv,rad,g,r,cpp, &
+     CALL iniphysiq(iim,jjm,llm, &
+          (jjm-1)*iim+2,comm_lmdz, &
+          daysec,day_ini,dtphys/nsplit_phys, &
+          rlatu,rlatv,rlonu,rlonv,aire,cu,cv,rad,g,r,cpp, &
           iflag_phys)
 #endif
Index: /LMDZ5/branches/testing/libf/dyn3d/leapfrog.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d/leapfrog.F	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dyn3d/leapfrog.F	(revision 2408)
@@ -228,8 +228,11 @@
    1  CONTINUE ! Matsuno Forward step begins here
 
+c   date: (NB: date remains unchanged for Backward step)
+c   -----
+
       jD_cur = jD_ref + day_ini - day_ref +                             &
-     &          itau/day_step
+     &          (itau+1)/day_step
       jH_cur = jH_ref + start_time +                                    &
-     &          mod(itau,day_step)/float(day_step) 
+     &          mod(itau+1,day_step)/float(day_step) 
       jD_cur = jD_cur + int(jH_cur)
       jH_cur = jH_cur - int(jH_cur)
@@ -277,6 +280,15 @@
 c-----------------------------------------------------------------------
 
-c   date:
+c   date: (NB: only leapfrog step requires recomputing date)
 c   -----
+
+      IF (leapf) THEN
+        jD_cur = jD_ref + day_ini - day_ref +
+     &            (itau+1)/day_step
+        jH_cur = jH_ref + start_time +
+     &            mod(itau+1,day_step)/float(day_step) 
+        jD_cur = jD_cur + int(jH_cur)
+        jH_cur = jH_cur - int(jH_cur)
+      ENDIF
 
 
@@ -416,5 +428,5 @@
 !     &              (itau * dtvr / daysec - int(itau * dtvr / daysec)) 
            jD_cur = jD_ref + day_ini - day_ref +                        &
-     &          itau/day_step
+     &          (itau+1)/day_step
 
            IF (planet_type .eq."generic") THEN
@@ -424,5 +436,5 @@
 
            jH_cur = jH_ref + start_time +                               &
-     &              mod(itau,day_step)/float(day_step) 
+     &              mod(itau+1,day_step)/float(day_step) 
            jD_cur = jD_cur + int(jH_cur)
            jH_cur = jH_cur - int(jH_cur)
@@ -443,10 +455,8 @@
          IF (ip_ebil_dyn.ge.1 ) THEN 
           ztit='bil dyn'
-! Ehouarn: be careful, diagedyn is Earth-specific (includes ../phylmd/..)!
+! Ehouarn: be careful, diagedyn is Earth-specific!
            IF (planet_type.eq."earth") THEN
-#ifdef CPP_EARTH
             CALL diagedyn(ztit,2,1,1,dtphys
      &    , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
-#endif
            ENDIF
          ENDIF ! of IF (ip_ebil_dyn.ge.1 )
Index: DZ5/branches/testing/libf/dyn3d_common/caldyn0.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/caldyn0.F	(revision 2407)
+++ 	(revision )
@@ -1,91 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE caldyn0
-     $ (itau,ucov,vcov,teta,ps,masse,pk,phis ,
-     $  phi,w,pbaru,pbarv,time )
-
-      USE control_mod, ONLY: resetvarc 
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c  Auteur :  P. Le Van
-c
-c   Objet:
-c   ------
-c
-c   Calcul des tendances dynamiques.
-c
-c Modif 04/93 F.Forget
-c=======================================================================
-
-c-----------------------------------------------------------------------
-c   0. Declarations:
-c   ----------------
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
-
-c   Arguments:
-c   ----------
-
-      INTEGER itau
-      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm),teta(ip1jmp1,llm)
-      REAL ps(ip1jmp1),phis(ip1jmp1)
-      REAL pk(iip1,jjp1,llm)
-      REAL vcont(ip1jm,llm),ucont(ip1jmp1,llm)
-      REAL phi(ip1jmp1,llm),masse(ip1jmp1,llm)
-      REAL pbaru(ip1jmp1,llm),pbarv(ip1jm,llm)
-      REAL time
-
-c   Local:
-c   ------
-
-      REAL ang(ip1jmp1,llm),p(ip1jmp1,llmp1)
-      REAL massebx(ip1jmp1,llm),masseby(ip1jm,llm),psexbarxy(ip1jm)
-      REAL vorpot(ip1jm,llm)
-      REAL w(ip1jmp1,llm),ecin(ip1jmp1,llm),convm(ip1jmp1,llm)
-      REAL bern(ip1jmp1,llm)
-      REAL massebxy(ip1jm,llm), dp(ip1jmp1)
-    
-
-      INTEGER   ij,l
-
-c-----------------------------------------------------------------------
-c   Calcul des tendances dynamiques:
-c   --------------------------------
-
-      CALL covcont  ( llm    , ucov    , vcov , ucont, vcont        )
-      CALL pression ( ip1jmp1, ap      , bp   ,  ps  , p            )
-      CALL psextbar (   ps   , psexbarxy                            )
-      CALL massdair (    p   , masse                                )
-      CALL massbar  (   masse, massebx , masseby                    )
-      CALL massbarxy(   masse, massebxy                             )
-      CALL flumass  ( massebx, masseby , vcont, ucont ,pbaru, pbarv )
-      CALL convmas  (   pbaru, pbarv   , convm                      )
-
-      DO ij =1, ip1jmp1
-         dp( ij ) = convm( ij,1 ) / airesurg( ij )
-      ENDDO
-
-      CALL vitvert ( convm  , w                                  )
-      CALL tourpot ( vcov   , ucov  , massebxy  , vorpot         )
-      CALL enercin ( vcov   , ucov  , vcont     , ucont  , ecin  )
-      CALL bernoui ( ip1jmp1, llm   , phi       , ecin   , bern  )
-
-      DO l=1,llm
-         DO ij=1,ip1jmp1
-            ang(ij,l) = ucov(ij,l) + constang(ij)
-         ENDDO
-      ENDDO
-
-      resetvarc=.true. ! force a recomputation of initial values in sortvarc
-      CALL sortvarc
-     $ ( itau,ucov,teta,ps,masse,pk,phis,vorpot,phi,bern,dp,time,vcov )
-
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d_common/caldyn0.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/caldyn0.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/caldyn0.F90	(revision 2408)
@@ -0,0 +1,56 @@
+SUBROUTINE caldyn0(itau,ucov,vcov,teta,ps,masse,pk,phis,phi,w,pbaru,pbarv,time)
+!
+!-------------------------------------------------------------------------------
+! Author: P. Le Van ; modif. 04/93: F.Forget.
+!-------------------------------------------------------------------------------
+! Purpose: Compute dynamic tendencies.
+!-------------------------------------------------------------------------------
+  USE control_mod, ONLY: resetvarc 
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comconst.h"
+  include "comvert.h"
+  include "comgeom.h"
+!===============================================================================
+! Arguments:
+  INTEGER, INTENT(IN)  :: itau                      !--- TIME STEP INDEX
+  REAL,    INTENT(IN)  :: vcov (ip1jm    ,llm)      !--- V COVARIANT WIND
+  REAL,    INTENT(IN)  :: ucov (ip1jmp1  ,llm)      !--- U COVARIANT WIND
+  REAL,    INTENT(IN)  :: teta (ip1jmp1  ,llm)      !--- POTENTIAL TEMPERATURE
+  REAL,    INTENT(IN)  :: ps   (ip1jmp1)            !--- GROUND PRESSURE
+  REAL,    INTENT(OUT) :: masse(ip1jmp1  ,llm)      !--- MASS IN EACH CELL
+  REAL,    INTENT(IN)  :: pk   (iip1,jjp1,llm)      !--- PRESSURE
+  REAL,    INTENT(IN)  :: phis (ip1jmp1)            !--- GROUND GEOPOTENTIAL
+  REAL,    INTENT(IN)  :: phi  (ip1jmp1  ,llm)      !--- 3D GEOPOTENTIAL
+  REAL,    INTENT(OUT) :: w    (ip1jmp1  ,llm)      !--- VERTICAL WIND
+  REAL,    INTENT(OUT) :: pbaru(ip1jmp1  ,llm)      !--- U MASS FLUX
+  REAL,    INTENT(OUT) :: pbarv(ip1jm    ,llm)      !--- V MASS FLUX
+  REAL,    INTENT(IN)  :: time                      !--- TIME
+!===============================================================================
+! Local variables:
+  REAL, DIMENSION(ip1jmp1,llmp1) :: p
+  REAL, DIMENSION(ip1jmp1,llm)   :: ucont, massebx, ang, ecin, convm, bern
+  REAL, DIMENSION(ip1jmp1)       :: dp
+  REAL, DIMENSION(ip1jm  ,llm)   :: vcont, masseby, massebxy, vorpot
+  REAL, DIMENSION(ip1jm)         :: psexbarxy
+  INTEGER                        :: ij, l
+!===============================================================================
+  CALL covcont  ( llm    , ucov    , vcov , ucont, vcont        )
+  CALL pression ( ip1jmp1, ap      , bp   ,  ps  , p            )
+  CALL psextbar (   ps   , psexbarxy                            )
+  CALL massdair (    p   , masse                                )
+  CALL massbar  (   masse, massebx , masseby                    )
+  CALL massbarxy(   masse, massebxy                             )
+  CALL flumass  ( massebx, masseby , vcont, ucont ,pbaru, pbarv )
+  CALL convmas  (   pbaru, pbarv   , convm                      )
+  CALL vitvert  ( convm  , w                                    )
+  CALL tourpot  ( vcov   , ucov    , massebxy  , vorpot         )
+  CALL enercin  ( vcov   , ucov    , vcont     , ucont  , ecin  )
+  CALL bernoui  ( ip1jmp1, llm     , phi       , ecin   , bern  )
+  DO l=1,llm; ang(:,l) = ucov(:,l) + constang(:); END DO
+  resetvarc=.true. ! force a recomputation of initial values in sortvarc
+  dp(:)=convm(:,1)/airesurg(:)
+  CALL sortvarc( itau,ucov,teta,ps,masse,pk,phis,vorpot,phi,bern,dp,time,vcov )
+
+END SUBROUTINE caldyn0
Index: DZ5/branches/testing/libf/dyn3d_common/conf_dat2d.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/conf_dat2d.F	(revision 2407)
+++ 	(revision )
@@ -1,221 +1,0 @@
-!
-! $Header$
-!
-C
-C
-      SUBROUTINE conf_dat2d( title,lons,lats,xd,yd,xf,yf,champd ,
-     ,                           interbar                        )
-c
-c     Auteur :  P. Le Van
-
-c    Ce s-pr. configure le champ de donnees 2D 'champd' de telle facon que
-c       qu'on ait     - pi    a    pi    en longitude
-c       et qu'on ait   pi/2.  a - pi/2.  en latitude
-c
-c      xd et yd  sont les longitudes et latitudes initiales
-c      xf et yf  sont les longitudes et latitudes en sortie , eventuellement
-c      modifiees pour etre configurees comme ci-dessus .
-
-      IMPLICIT NONE
- 
-c    ***       Arguments en  entree      ***
-      INTEGER lons,lats
-      CHARACTER*25 title
-      REAL xd(lons),yd(lats)
-      LOGICAL interbar
-c
-c    ***       Arguments en  sortie      ***
-      REAL xf(lons),yf(lats)
-c
-c    ***  Arguments en entree et  sortie ***
-      REAL champd(lons,lats)
-
-c   ***     Variables  locales  ***
-c
-      REAL pi,pis2,depi
-      LOGICAL radianlon, invlon ,radianlat, invlat, alloc
-      REAL rlatmin,rlatmax,oldxd1
-      INTEGER i,j,ip180,ind
-
-      REAL, ALLOCATABLE :: xtemp(:) 
-      REAL, ALLOCATABLE :: ytemp(:) 
-      REAL, ALLOCATABLE :: champf(:,:)
-     
-c
-c      WRITE(6,*) ' conf_dat2d  pour la variable ', title
-
-      ALLOCATE( xtemp(lons) )
-      ALLOCATE( ytemp(lats) )
-      ALLOCATE( champf(lons,lats) )
-
-      DO i = 1, lons
-       xtemp(i) = xd(i)
-      ENDDO
-      DO j = 1, lats
-       ytemp(j) = yd(j)
-      ENDDO
-
-      pi   = 2. * ASIN(1.) 
-      pis2 = pi/2.
-      depi = 2. * pi
-
-            radianlon = .FALSE.
-      IF( xtemp(1).GE.-pi-0.5.AND. xtemp(lons).LE.pi+0.5 )  THEN
-            radianlon = .TRUE.
-            invlon    = .FALSE.
-      ELSE IF (xtemp(1).GE.-0.5.AND.xtemp(lons).LE.depi+0.5 ) THEN
-            radianlon = .TRUE.
-            invlon    = .TRUE.
-      ELSE IF ( xtemp(1).GE.-180.5.AND. xtemp(lons).LE.180.5 )   THEN
-            radianlon = .FALSE.
-            invlon    = .FALSE.
-      ELSE IF ( xtemp(1).GE.-0.5.AND.xtemp(lons).LE.360.5 )   THEN
-            radianlon = .FALSE.
-            invlon    = .TRUE.
-      ELSE
-        WRITE(6,*) 'Pbs. sur les longitudes des donnees pour le fichier'
-     ,  , title
-      ENDIF
-
-      invlat = .FALSE.
-      
-      IF( ytemp(1).LT.ytemp(lats) ) THEN
-        invlat = .TRUE.
-      ENDIF
-
-      rlatmin = MIN( ytemp(1), ytemp(lats) )
-      rlatmax = MAX( ytemp(1), ytemp(lats) )
-      
-      IF( rlatmin.GE.-pis2-0.5.AND.rlatmax.LE.pis2+0.5)THEN
-             radianlat = .TRUE.
-      ELSE IF ( rlatmin.GE.-90.-0.5.AND.rlatmax.LE.90.+0.5 ) THEN
-             radianlat = .FALSE.
-      ELSE
-        WRITE(6,*) ' Pbs. sur les latitudes des donnees pour le fichier'
-     ,  , title
-      ENDIF
-
-       IF( .NOT. radianlon )  THEN
-         DO i = 1, lons
-          xtemp(i) = xtemp(i) * pi/180.
-         ENDDO
-       ENDIF
-
-       IF( .NOT. radianlat )  THEN
-         DO j = 1, lats
-          ytemp(j) = ytemp(j) * pi/180.
-         ENDDO   
-       ENDIF
-
-
-        IF ( invlon )   THEN
-
-           DO j = 1, lats
-            DO i = 1,lons
-             champf(i,j) = champd(i,j)
-            ENDDO
-           ENDDO
-
-           DO i = 1 ,lons
-            xf(i) = xtemp(i)
-           ENDDO
-c
-c    ***  On tourne les longit.  pour avoir  - pi  a  +  pi  ****
-c
-           DO i=1,lons
-            IF( xf(i).GT. pi )  THEN
-            GO TO 88
-            ENDIF
-           ENDDO
-
-88         CONTINUE
-c
-           ip180 = i
-
-           DO i = 1,lons
-            IF (xf(i).GT. pi)  THEN
-             xf(i) = xf(i) - depi
-            ENDIF
-           ENDDO
-
-           DO i= ip180,lons
-            ind = i-ip180 +1
-            xtemp(ind) = xf(i)
-           ENDDO
-
-           DO i= ind +1,lons
-            xtemp(i) = xf(i-ind)
-           ENDDO
-
-c   .....    on tourne les longitudes  pour  champf ....
-c
-           DO j = 1,lats
-
-             DO i = ip180,lons
-              ind  = i-ip180 +1
-              champd (ind,j) = champf (i,j)
-             ENDDO
-   
-             DO i= ind +1,lons
-              champd (i,j)  = champf (i-ind,j)
-             ENDDO
-
-           ENDDO
-
-
-        ENDIF
-c
-c    *****   fin  de   IF(invlon)   ****
-
-         IF ( invlat )    THEN
-
-           DO j = 1,lats
-            yf(j) = ytemp(j)
-           ENDDO
-
-           DO j = 1, lats
-             DO i = 1,lons
-              champf(i,j) = champd(i,j)
-             ENDDO
-           ENDDO
-
-           DO j = 1, lats
-              ytemp( lats-j+1 ) = yf(j)
-              DO i = 1, lons
-               champd (i,lats-j+1) = champf (i,j)
-              ENDDO
-           ENDDO
-
-
-         ENDIF
-
-c    *****  fin  de  IF(invlat)   ****
-
-c        
-      IF( interbar )  THEN
-        oldxd1 = xtemp(1)
-        DO i = 1, lons -1
-          xtemp(i) = 0.5 * ( xtemp(i) + xtemp(i+1) )
-        ENDDO
-          xtemp(lons) = 0.5 * ( xtemp(lons) + oldxd1 + depi )
-
-        DO j = 1, lats -1
-          ytemp(j) = 0.5 * ( ytemp(j) + ytemp(j+1) )
-        ENDDO
-
-      ENDIF
-c
-        DEALLOCATE(champf)
-
-       DO i = 1, lons
-        xf(i) = xtemp(i)
-       ENDDO
-       DO j = 1, lats
-        yf(j) = ytemp(j)
-       ENDDO
-
-      deallocate(xtemp)
-      deallocate(ytemp)
-
-      RETURN
-      END
Index: DZ5/branches/testing/libf/dyn3d_common/conf_dat3d.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/conf_dat3d.F	(revision 2407)
+++ 	(revision )
@@ -1,296 +1,0 @@
-!
-! $Header$
-!
-C
-C
-      SUBROUTINE conf_dat3d( title, lons,lats,levs,xd,yd,zd,xf,yf,zf,
-     ,                                 champd , interbar             )
-c
-c     Auteur : P. Le Van
-c
-c    Ce s-pr. configure le champ de donnees 3D 'champd' de telle facon 
-c       qu'on ait     - pi    a    pi    en longitude
-c       qu'on ait      pi/2.  a - pi/2.  en latitude
-c      et qu'on ait les niveaux verticaux variant du sol vers le ht de l'atmos.
-c           (     en Pascals   ) .
-c
-c      xd et yd  sont les longitudes et latitudes initiales
-c      zd  les pressions initiales
-c
-c      xf et yf  sont les longitudes et latitudes en sortie , eventuellement
-c       modifiees pour etre configurees comme ci-dessus .
-c      zf  les pressions en sortie
-c
-c      champd   en meme temps le champ initial et  final
-c
-c      interbar = .TRUE.  si on appelle l'interpo. barycentrique inter_barxy
-c          sinon , l'interpolation   grille_m  ( grid_atob ) .
-c
-
-      IMPLICIT NONE
- 
-c    ***       Arguments en  entree      ***
-      CHARACTER*(*) :: title
-      INTEGER lons, lats, levs
-      REAL xd(lons), yd(lats), zd(levs)
-      LOGICAL interbar
-c
-c    ***       Arguments en  sortie      ***
-      REAL xf(lons), yf(lats), zf(levs)
-
-c    ***  Arguments en entree et  sortie ***
-      REAL  champd(lons,lats,levs)
-
-c    ***  Variables locales  ***
-c
-      REAL pi,pis2,depi,presmax
-      LOGICAL radianlon, invlon ,radianlat, invlat, invlev, alloc
-      REAL rlatmin,rlatmax,oldxd1
-      INTEGER i,j,ip180,ind,l
-
-      REAL, ALLOCATABLE :: xtemp(:)
-      REAL, ALLOCATABLE :: ytemp(:)
-      REAL, ALLOCATABLE :: ztemp(:)
-      REAL, ALLOCATABLE :: champf(:,:,:)
-     
-
-c      WRITE(6,*) '  Conf_dat3d  pour  ',title
-
-      ALLOCATE(xtemp(lons))
-      ALLOCATE(ytemp(lats))
-      ALLOCATE(ztemp(levs))
-
-      DO i = 1, lons
-       xtemp(i) = xd(i)
-      ENDDO
-      DO j = 1, lats
-       ytemp(j) = yd(j)
-      ENDDO
-      DO l = 1, levs
-       ztemp(l) = zd(l)
-      ENDDO
-
-      pi   = 2. * ASIN(1.) 
-      pis2 = pi/2.
-      depi = 2. * pi
-
-      IF( xtemp(1).GE.-pi-0.5.AND. xtemp(lons).LE.pi+0.5 )  THEN
-            radianlon = .TRUE.
-            invlon    = .FALSE.
-      ELSE IF (xtemp(1).GE.-0.5.AND.xtemp(lons).LE.depi+0.5 ) THEN
-            radianlon = .TRUE.
-            invlon    = .TRUE.
-      ELSE IF ( xtemp(1).GE.-180.5.AND. xtemp(lons).LE.180.5 )   THEN
-            radianlon = .FALSE.
-            invlon    = .FALSE.
-      ELSE IF ( xtemp(1).GE.-0.5.AND.xtemp(lons).LE.360.5 )   THEN
-            radianlon = .FALSE.
-            invlon    = .TRUE.
-      ELSE
-        WRITE(6,*) 'Pbs. sur les longitudes des donnees pour le fichier'
-     ,  , title
-      ENDIF
-
-      invlat = .FALSE.
-      
-      IF( ytemp(1).LT.ytemp(lats) ) THEN
-        invlat = .TRUE.
-      ENDIF
-
-      rlatmin = MIN( ytemp(1), ytemp(lats) )
-      rlatmax = MAX( ytemp(1), ytemp(lats) )
-      
-      IF( rlatmin.GE.-pis2-0.5.AND.rlatmax.LE.pis2+0.5)THEN
-             radianlat = .TRUE.
-      ELSE IF ( rlatmin.GE.-90.-0.5.AND.rlatmax.LE.90.+0.5 ) THEN
-             radianlat = .FALSE.
-      ELSE
-        WRITE(6,*) ' Pbs. sur les latitudes des donnees pour le fichier'
-     ,  , title
-      ENDIF
-
-       IF( .NOT. radianlon )  THEN
-         DO i = 1, lons
-          xtemp(i) = xtemp(i) * pi/180.
-         ENDDO
-       ENDIF
-
-       IF( .NOT. radianlat )  THEN
-         DO j = 1, lats
-          ytemp(j) = ytemp(j) * pi/180.
-         ENDDO   
-       ENDIF
-
-
-        alloc =.FALSE.
-
-        IF ( invlon )   THEN
-
-            ALLOCATE(champf(lons,lats,levs))
-            alloc = .TRUE.
-
-            DO i = 1 ,lons
-             xf(i) = xtemp(i)
-            ENDDO
-
-            DO l = 1, levs
-             DO j = 1, lats
-              DO i= 1, lons
-               champf (i,j,l)  = champd (i,j,l)
-              ENDDO
-             ENDDO
-            ENDDO
-c
-c    ***  On tourne les longit.  pour avoir  - pi  a  +  pi  ****
-c
-            DO i=1,lons
-             IF( xf(i).GT. pi )  THEN
-              GO TO 88
-             ENDIF
-            ENDDO
-
-88          CONTINUE
-c
-            ip180 = i
-
-            DO i = 1,lons
-             IF (xf(i).GT. pi)  THEN
-              xf(i) = xf(i) - depi
-             ENDIF
-            ENDDO
-
-            DO i= ip180,lons
-             ind = i-ip180 +1
-             xtemp(ind) = xf(i)
-            ENDDO
-
-            DO i= ind +1,lons
-             xtemp(i) = xf(i-ind)
-            ENDDO
-
-c   .....    on tourne les longitudes  pour champf  ....
-c
-            DO l = 1,levs
-              DO j = 1,lats
-               DO i = ip180,lons
-                ind  = i-ip180 +1
-                champd (ind,j,l) = champf (i,j,l)
-               ENDDO
-   
-               DO i= ind +1,lons
-                champd (i,j,l)  = champf (i-ind,j,l)
-               ENDDO
-              ENDDO
-            ENDDO
-
-        ENDIF
-c
-c    *****   fin  de   IF(invlon)   ****
-         
-         IF ( invlat )    THEN
-
-           IF(.NOT.alloc)  THEN 
-            ALLOCATE(champf(lons,lats,levs))
-            alloc = .TRUE.
-           ENDIF
-
-           DO j = 1, lats
-            yf(j) = ytemp(j)
-           ENDDO
-         
-           DO l = 1,levs
-            DO j = 1, lats
-             DO i = 1,lons
-              champf(i,j,l) = champd(i,j,l)
-             ENDDO
-            ENDDO
-
-            DO j = 1, lats
-              ytemp( lats-j+1 ) = yf(j)
-              DO i = 1, lons
-               champd (i,lats-j+1,l) = champf (i,j,l)
-              ENDDO
-            ENDDO
-          ENDDO
-
-
-         ENDIF
-
-c    *****  fin  de  IF(invlat)   ****
-c
-c
-      IF( interbar )  THEN
-        oldxd1 = xtemp(1)
-        DO i = 1, lons -1
-          xtemp(i) = 0.5 * ( xtemp(i) + xtemp(i+1) )
-        ENDDO
-          xtemp(lons) = 0.5 * ( xtemp(lons) + oldxd1 + depi )
-
-        DO j = 1, lats -1
-          ytemp(j) = 0.5 * ( ytemp(j) + ytemp(j+1) )
-        ENDDO
-      ENDIF
-c
-
-      invlev = .FALSE.
-      IF( ztemp(1).LT.ztemp(levs) )  invlev = .TRUE.
-
-      presmax = MAX( ztemp(1), ztemp(levs) )
-      IF( presmax.LT.1200. ) THEN
-         DO l = 1,levs
-           ztemp(l) = ztemp(l) * 100.
-         ENDDO
-      ENDIF
-
-      IF( invlev )  THEN
-
-          IF(.NOT.alloc)  THEN
-            ALLOCATE(champf(lons,lats,levs))
-            alloc = .TRUE.
-          ENDIF
-
-          DO l = 1,levs
-            zf(l) = ztemp(l)
-          ENDDO
-
-          DO l = 1,levs
-            DO j = 1, lats
-             DO i = 1,lons
-              champf(i,j,l) = champd(i,j,l)
-             ENDDO
-            ENDDO
-          ENDDO
-
-          DO l = 1,levs
-            ztemp(levs+1-l) = zf(l)
-          ENDDO
-
-          DO l = 1,levs
-            DO j = 1, lats
-             DO i = 1,lons
-              champd(i,j,levs+1-l) = champf(i,j,l)
-             ENDDO
-            ENDDO
-          ENDDO
-
-
-      ENDIF
-
-         IF(alloc)  DEALLOCATE(champf)
-
-         DO i = 1, lons
-           xf(i) = xtemp(i)
-         ENDDO
-         DO j = 1, lats
-           yf(j) = ytemp(j)
-         ENDDO
-         DO l = 1, levs
-           zf(l) = ztemp(l)
-         ENDDO
-
-      DEALLOCATE(xtemp)
-      DEALLOCATE(ytemp)
-      DEALLOCATE(ztemp)
-
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d_common/conf_dat_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/conf_dat_m.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/conf_dat_m.F90	(revision 2408)
@@ -0,0 +1,235 @@
+MODULE conf_dat_m
+!
+!*******************************************************************************
+
+  PRIVATE
+  PUBLIC :: conf_dat2d, conf_dat3d
+
+
+CONTAINS
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE conf_dat2d(title, xd, yd, xf, yf, champd, interbar)
+!
+!-------------------------------------------------------------------------------
+! Author: P. Le Van
+!-------------------------------------------------------------------------------
+! Purpose: Configure the 2D data field "champd" so that:
+!     - Longitudes are in [ -pi     pi   ]
+!     - Latitudes  are in [  pi/2. -pi/2 ]
+!  * xd / yd are initial lon / lats.
+!  * xf / yf are output  lon / lats, possibly modified to satisfy configuration.
+!  * interbar is TRUE for barycentric interpolation.
+!-------------------------------------------------------------------------------
+  USE assert_eq_m, ONLY: assert_eq
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN)    :: title
+  REAL,             INTENT(IN)    :: xd(:), yd(:)  ! dim (lons) (lats)
+  REAL,             INTENT(INOUT) :: xf(:), yf(:)  ! dim (lons) (lats)
+  REAL,             INTENT(INOUT) :: champd(:,:)   ! dim (lons,lats)
+  LOGICAL,          INTENT(IN)    :: interbar
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname="conf_dat2d"
+  INTEGER :: i, j, ip180, ind, lons, lats
+  LOGICAL :: radlon, invlon ,radlat, invlat
+  REAL    :: pi, pis2, depi, rlatmin, rlatmax, oldxd1
+  REAL, ALLOCATABLE :: xtemp(:) , ytemp(:), champf(:,:)
+!-------------------------------------------------------------------------------
+  lons=assert_eq(SIZE(xd),SIZE(xf),SIZE(champd,1),TRIM(modname)//" lons")
+  lats=assert_eq(SIZE(yd),SIZE(yf),SIZE(champd,2),TRIM(modname)//" lats")
+  ALLOCATE(xtemp(lons),ytemp(lats)); xtemp(:)=xd(:); ytemp(:)=yd(:)
+  ALLOCATE(champf(lons,lats))
+  pi = 2. * ASIN(1.) 
+  pis2 = pi/2.
+  depi = 2. * pi
+  radlon=.FALSE.; invlon=.FALSE.
+  IF     (xtemp(1)>=-pi-0.5.AND.xtemp(lons)<=  pi+0.5) THEN
+    radlon = .TRUE.;  invlon = .FALSE.
+  ELSE IF(xtemp(1)>=   -0.5.AND.xtemp(lons)<=depi+0.5) THEN
+    radlon = .TRUE.;  invlon = .TRUE.
+  ELSE IF(xtemp(1)>= -180.5.AND.xtemp(lons)<=   180.5) THEN
+    radlon = .FALSE.; invlon = .FALSE.
+  ELSE IF(xtemp(1)>=   -0.5.AND.xtemp(lons)<=   360.5) THEN
+    radlon = .FALSE.; invlon = .TRUE.
+  ELSE; WRITE(6,*) 'Problems with data longitudes for file '//TRIM(title)
+  END IF
+  invlat = ytemp(1)<ytemp(lats)
+  rlatmin = MIN( ytemp(1), ytemp(lats) )
+  rlatmax = MAX( ytemp(1), ytemp(lats) )
+      
+  IF     (rlatmin>=-pis2-0.5.AND.rlatmax<=pis2+0.5) THEN; radlat = .TRUE.
+  ELSE IF(rlatmin>= -90.-0.5.AND.rlatmax<= 90.+0.5) THEN; radlat = .FALSE.
+  ELSE; WRITE(6,*) 'Problems with data latitudes for file '//TRIM(title)
+  END IF
+
+  IF(.NOT.radlon) xtemp(:)=xtemp(:)*pi/180.
+  IF(.NOT.radlat) ytemp(:)=ytemp(:)*pi/180.
+
+!--- FLIPPED LONGITUDES
+  IF(invlon) THEN
+    champf(:,:)=champd(:,:); xf(:)=xtemp(:)
+
+  !--- Longitudes rotated to get them in [ -pi pi] interval.
+    DO i=1,lons;      IF(xf(i)>pi) EXIT;                   END DO; ip180 = i
+    DO i=1,lons;      IF(xf(i)>pi) xf(i)=xf(i)-depi;       END DO
+    DO i= ip180,lons; ind=i-ip180+1; xtemp(ind)=xf(i);     END DO
+    DO i= ind+1,lons;                xtemp(i  )=xf(i-ind); END DO
+
+  !--- Longitudes rotated in champf
+    DO j=1,lats
+      DO i=ip180,lons; ind=i-ip180+1; champd(ind,j)=champf(i    ,j); END DO
+      DO i=ind+1,lons;                champd(i  ,j)=champf(i-ind,j); END DO
+    END DO
+  END IF
+
+!--- FLIPPED LATITUDES
+  IF(invlat) THEN
+    yf(:)=ytemp(:)
+    champf(:,:)=champd(:,:)
+    ytemp(lats:1:-1)=yf(:)
+    DO j=1,lats; champd(:,lats-j+1)=champf(:,j); END DO
+  END IF
+
+!--- FOR BARYCENTRIC INTERPOLATION
+  IF(interbar) THEN
+    oldxd1 = xtemp(1)
+    xtemp(1:lons-1)=0.5*(xtemp(1:lons-1)+xtemp(2:lons))
+    xtemp(  lons  )=0.5*(xtemp(  lons  )+oldxd1+depi)
+    ytemp(1:lats-1)=0.5*(ytemp(1:lats-1)+ytemp(2:lats))
+  END IF
+  DEALLOCATE(champf)
+  xf(:)=xtemp(:); DEALLOCATE(xtemp)
+  yf(:)=ytemp(:); DEALLOCATE(ytemp)
+
+END SUBROUTINE conf_dat2d
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE conf_dat3d(title, xd, yd, zd, xf, yf, zf, champd, interbar)
+!
+!-------------------------------------------------------------------------------
+! Author: P. Le Van
+!-------------------------------------------------------------------------------
+! Purpose: Configure the 3D data field "champd" so that:
+!     - Longitudes are in [ -pi     pi   ]
+!     - Latitudes  are in [  pi/2. -pi/2 ]
+!     - Vertical levels from ground to model top (in Pascals)
+!  * xd / yd are initial lon / lats.
+!  * xf / yf are output  lon / lats, possibly modified to satisfy configuration.
+!  * zf      are output pressures
+!  * interbar is TRUE for barycentric interpolation.
+!-------------------------------------------------------------------------------
+  USE assert_eq_m, ONLY: assert_eq
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN)    :: title
+  REAL,             INTENT(IN)    :: xd(:), yd(:), zd(:) ! (lons) (lats) (levs)
+  REAL,             INTENT(INOUT) :: xf(:), yf(:), zf(:) ! (lons) (lats) (levs)
+  REAL,             INTENT(INOUT) :: champd(:,:,:)       ! (lons,lats,levs)
+  LOGICAL,          INTENT(IN)    :: interbar
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname="conf_dat3d"
+  INTEGER :: i, j, l, ip180, ind, lons, lats, levs
+  LOGICAL :: radlon, invlon ,radlat, invlat, invlev
+  REAL    :: pi, pis2, depi, presmax, rlatmin, rlatmax, oldxd1
+  REAL, ALLOCATABLE :: xtemp(:) , ytemp(:), ztemp(:), champf(:,:,:)
+!-------------------------------------------------------------------------------
+  lons=assert_eq(SIZE(xd),SIZE(xf),SIZE(champd,1),TRIM(modname)//" lons")
+  lats=assert_eq(SIZE(yd),SIZE(yf),SIZE(champd,2),TRIM(modname)//" lats")
+  levs=assert_eq(SIZE(zd),SIZE(zf),SIZE(champd,3),TRIM(modname)//" levs")
+  ALLOCATE(xtemp(lons),ytemp(lats),ztemp(levs),champf(lons,lats,levs))
+  xtemp(:)=xd(:); ytemp(:)=yd(:); ztemp(:)=zd(:)
+  pi = 2. * ASIN(1.) 
+  pis2 = pi/2.
+  depi = 2. * pi
+  radlon=.FALSE.; invlon=.FALSE.
+  IF     (xtemp(1)>=-pi-0.5.AND.xtemp(lons)<=  pi+0.5) THEN
+    radlon = .TRUE.;  invlon = .FALSE.
+  ELSE IF(xtemp(1)>=   -0.5.AND.xtemp(lons)<=depi+0.5) THEN
+    radlon = .TRUE.;  invlon = .TRUE.
+  ELSE IF(xtemp(1)>= -180.5.AND.xtemp(lons)<=   180.5) THEN
+    radlon = .FALSE.; invlon = .FALSE.
+  ELSE IF(xtemp(1)>=   -0.5.AND.xtemp(lons)<=   360.5) THEN
+    radlon = .FALSE.; invlon = .TRUE.
+  ELSE; WRITE(6,*) 'Problems with data longitudes for file '//TRIM(title)
+  END IF
+  invlat = ytemp(1)<ytemp(lats)
+  rlatmin = MIN( ytemp(1), ytemp(lats) )
+  rlatmax = MAX( ytemp(1), ytemp(lats) )
+      
+  IF     (rlatmin>=-pis2-0.5.AND.rlatmax<=pis2+0.5) THEN; radlat = .TRUE.
+  ELSE IF(rlatmin>= -90.-0.5.AND.rlatmax<= 90.+0.5) THEN; radlat = .FALSE.
+  ELSE; WRITE(6,*) 'Problems with data latitudes for file '//TRIM(title)
+  END IF
+
+  IF(.NOT.radlon) xtemp(:)=xtemp(:)*pi/180.
+  IF(.NOT.radlat) ytemp(:)=ytemp(:)*pi/180.
+
+!--- FLIPPED LONGITUDES
+  IF(invlon) THEN
+    champf(:,:,:)=champd(:,:,:); xf(:)=xtemp(:)
+
+  !--- Longitudes rotated to get them in [ -pi pi] interval.
+    DO i=1,lons;      IF(xf(i)>pi) EXIT;                   END DO; ip180 = i
+    DO i=1,lons;      IF(xf(i)>pi) xf(i)=xf(i)-depi;       END DO
+    DO i= ip180,lons; ind=i-ip180+1; xtemp(ind)=xf(i);     END DO
+    DO i= ind+1,lons;                xtemp(i  )=xf(i-ind); END DO
+
+  !--- Longitudes rotated in champf
+    DO l=1,levs
+    DO j=1,lats
+      DO i=ip180,lons; ind=i-ip180+1; champd(ind,j,l)=champf(i    ,j,l); END DO
+      DO i=ind+1,lons;                champd(i  ,j,l)=champf(i-ind,j,l); END DO
+    END DO
+    END DO
+  END IF
+
+!--- FLIPPED LATITUDES
+  IF(invlat) THEN
+    yf(:)=ytemp(:)
+    champf(:,:,:)=champd(:,:,:)
+    ytemp(lats:1:-1)=yf(:)
+    DO l=1,levs
+      DO j=1,lats; champd(:,lats-j+1,l)=champf(:,j,l); END DO
+    END DO
+  END IF
+
+!--- FOR BARYCENTRIC INTERPOLATION
+  IF(interbar) THEN
+    oldxd1 = xtemp(1)
+    xtemp(1:lons-1)=0.5*(xtemp(1:lons-1)+xtemp(2:lons))
+    xtemp(  lons  )=0.5*(xtemp(  lons  )+oldxd1+depi)
+    ytemp(1:lats-1)=0.5*(ytemp(1:lats-1)+ytemp(2:lats))
+  END IF
+
+!--- FLIPPED LEVELS
+  invlev=ztemp(1)<ztemp(levs)
+  IF(MAX(ztemp(1),ztemp(levs))<1200.) ztemp(:)=ztemp(:)*100.
+  IF(invlev) THEN
+    zf(:)=ztemp(:)
+    champf(:,:,:)=champd(:,:,:)
+    ztemp(levs:1:-1)=zf(:)
+    DO l=1,levs; champd(:,:,levs+1-l)=champf(:,:,l); END DO
+  END IF
+
+  DEALLOCATE(champf)
+  xf(:)=xtemp(:); DEALLOCATE(xtemp)
+  yf(:)=ytemp(:); DEALLOCATE(ytemp)
+  zf(:)=ztemp(:); DEALLOCATE(ztemp)
+
+END SUBROUTINE conf_dat3d
+!
+!-------------------------------------------------------------------------------
+
+END MODULE conf_dat_m
+
Index: DZ5/branches/testing/libf/dyn3d_common/convmas.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/convmas.F	(revision 2407)
+++ 	(revision )
@@ -1,63 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE convmas (pbaru, pbarv, convm )
-c
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteurs:  P. Le Van , F. Hourdin  .
-c   -------
-c
-c   Objet:
-c   ------
-c
-c   ********************************************************************
-c   .... calcul de la convergence du flux de masse aux niveaux p ...
-c   ********************************************************************
-c
-c
-c     pbaru  et  pbarv  sont des arguments d'entree pour le s-pg  ....
-c      .....  convm      est  un argument de sortie pour le s-pg  ....
-c
-c    le calcul se fait de haut en bas, 
-c    la convergence de masse au niveau p(llm+1) est egale a 0. et
-c    n'est pas stockee dans le tableau convm .
-c
-c
-c=======================================================================
-c
-c   Declarations:
-c   -------------
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
-#include "logic.h"
-
-      REAL pbaru( ip1jmp1,llm ),pbarv( ip1jm,llm ),convm(  ip1jmp1,llm )
-      INTEGER   l,ij
-
-
-c-----------------------------------------------------------------------
-c    ....  calcul de - (d(pbaru)/dx + d(pbarv)/dy ) ......
-
-      CALL  convflu( pbaru, pbarv, llm, convm )
-
-c-----------------------------------------------------------------------
-c   filtrage:
-c   ---------
-
-       CALL filtreg( convm, jjp1, llm, 2, 2, .true., 1 )
-
-c    integration de la convergence de masse de haut  en bas ......
-
-      DO      l      = llmm1, 1, -1
-        DO    ij     = 1, ip1jmp1
-         convm(ij,l) = convm(ij,l) + convm(ij,l+1)
-        ENDDO
-      ENDDO
-c
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d_common/convmas.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/convmas.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/convmas.F90	(revision 2408)
@@ -0,0 +1,36 @@
+SUBROUTINE convmas (pbaru, pbarv, convm)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute mass flux convergence at p levels.
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+  include "logic.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: pbaru(ip1jmp1,llm)
+  REAL, INTENT(IN)  :: pbarv(ip1jm  ,llm)
+  REAL, INTENT(OUT) :: convm(ip1jmp1,llm)
+!===============================================================================
+! Method used:   Computation from top to bottom.
+!   Mass convergence at level llm is equal to zero and is not stored in convm.
+!===============================================================================
+! Local variables:
+  INTEGER :: l
+!===============================================================================
+
+!--- Computation of - (d(pbaru)/dx + d(pbarv)/dy )
+  CALL convflu( pbaru, pbarv, llm, convm )
+
+!--- Filter
+  CALL filtreg( convm, jjp1, llm, 2, 2, .TRUE., 1 )
+
+!--- Mass convergence is integrated from top to bottom
+  DO l=llmm1,1,-1
+    convm(:,l) = convm(:,l) + convm(:,l+1)
+  END DO
+
+END SUBROUTINE convmas
Index: DZ5/branches/testing/libf/dyn3d_common/covcont.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/covcont.F	(revision 2407)
+++ 	(revision )
@@ -1,43 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE covcont (klevel,ucov, vcov, ucont, vcont )
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteur:  P. Le Van
-c   -------
-c
-c   Objet:
-c   ------
-c
-c  *********************************************************************
-c    calcul des compos. contravariantes a partir des comp.covariantes
-c  ********************************************************************
-c
-c=======================================================================
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom.h"
-
-      INTEGER klevel
-      REAL ucov( ip1jmp1,klevel ),  vcov( ip1jm,klevel )
-      REAL ucont( ip1jmp1,klevel ), vcont( ip1jm,klevel )
-      INTEGER   l,ij
-
-
-      DO 10 l = 1,klevel
-
-      DO 2  ij = iip2, ip1jm
-      ucont( ij,l ) = ucov( ij,l ) * unscu2( ij )
-   2  CONTINUE
-
-      DO 4 ij = 1,ip1jm
-      vcont( ij,l ) = vcov( ij,l ) * unscv2( ij )
-   4  CONTINUE
-
-  10  CONTINUE
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d_common/covcont.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/covcont.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/covcont.F90	(revision 2408)
@@ -0,0 +1,29 @@
+SUBROUTINE covcont (klevel,ucov, vcov, ucont, vcont )
+!
+!-------------------------------------------------------------------------------
+! Author: P. Le Van
+!-------------------------------------------------------------------------------
+! Purpose: Compute contravariant components from covariant components.
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+!===============================================================================
+! Arguments:
+  INTEGER, INTENT(IN)  :: klevel                    !--- VERTICAL LEVELS NUMBER
+  REAL,    INTENT(IN)  :: ucov ( ip1jmp1,klevel )   !--- U COVARIANT WIND
+  REAL,    INTENT(IN)  :: vcov ( ip1jm  ,klevel )   !--- V COVARIANT WIND
+  REAL,    INTENT(OUT) :: ucont( ip1jmp1,klevel )   !--- U CONTRAVAR WIND
+  REAL,    INTENT(OUT) :: vcont( ip1jm  ,klevel )   !--- V CONTRAVAR WIND
+!===============================================================================
+!   Local variables:
+  INTEGER :: l
+!===============================================================================
+  DO l=1,klevel
+    ucont(iip2:ip1jm,l)=ucov(iip2:ip1jm,l) * unscu2(iip2:ip1jm)
+    vcont(   1:ip1jm,l)=vcov(   1:ip1jm,l) * unscv2(   1:ip1jm)
+  END DO
+
+END SUBROUTINE covcont
+
Index: DZ5/branches/testing/libf/dyn3d_common/enercin.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/enercin.F	(revision 2407)
+++ 	(revision )
@@ -1,98 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE enercin ( vcov, ucov, vcont, ucont, ecin )
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteur: P. Le Van
-c   -------
-c
-c   Objet:
-c   ------
-c
-c *********************************************************************
-c .. calcul de l'energie cinetique aux niveaux s  ......
-c *********************************************************************
-c  vcov, vcont, ucov et ucont sont des arguments d'entree pour le s-pg .
-c  ecin         est  un  argument de sortie pour le s-pg
-c
-c=======================================================================
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom.h"
-
-      REAL vcov( ip1jm,llm ),vcont( ip1jm,llm ),
-     * ucov( ip1jmp1,llm ),ucont( ip1jmp1,llm ),ecin( ip1jmp1,llm )
-
-      REAL ecinni( iip1 ),ecinsi( iip1 )
-
-      REAL ecinpn, ecinps
-      INTEGER     l,ij,i
-
-      REAL        SSUM
-
-
-
-c                 . V
-c                i,j-1
-
-c      alpha4 .       . alpha1
-
-
-c        U .      . P     . U
-c       i-1,j    i,j      i,j
-
-c      alpha3 .       . alpha2
-
-
-c                 . V
-c                i,j
-
-c    
-c  L'energie cinetique au point scalaire P(i,j) ,autre que les poles, est :
-c       Ecin = 0.5 * U(i-1,j)**2 *( alpha3 + alpha4 )  +
-c              0.5 * U(i  ,j)**2 *( alpha1 + alpha2 )  +
-c              0.5 * V(i,j-1)**2 *( alpha1 + alpha4 )  +
-c              0.5 * V(i,  j)**2 *( alpha2 + alpha3 )
-
-
-      DO 5 l = 1,llm
-
-      DO 1  ij = iip2, ip1jm -1
-      ecin( ij+1, l )  =    0.5  *
-     * (   ucov( ij   ,l ) * ucont( ij   ,l ) * alpha3p4( ij +1 )   +
-     *     ucov( ij+1 ,l ) * ucont( ij+1 ,l ) * alpha1p2( ij +1 )   +
-     *     vcov(ij-iim,l ) * vcont(ij-iim,l ) * alpha1p4( ij +1 )   +
-     *     vcov( ij+ 1,l ) * vcont( ij+ 1,l ) * alpha2p3( ij +1 )   )
-   1  CONTINUE
-
-c    ... correction pour  ecin(1,j,l)  ....
-c    ...   ecin(1,j,l)= ecin(iip1,j,l) ...
-
-CDIR$ IVDEP
-      DO 2 ij = iip2, ip1jm, iip1
-      ecin( ij,l ) = ecin( ij + iim, l )
-   2  CONTINUE
-
-c     calcul aux poles  .......
-
-
-      DO 3 i = 1, iim
-      ecinni(i) = vcov(    i  ,  l) * vcont(    i    ,l) * aire(   i   )
-      ecinsi(i) = vcov(i+ip1jmi1,l) * vcont(i+ip1jmi1,l) * aire(i+ip1jm)
-   3  CONTINUE
-
-      ecinpn = 0.5 * SSUM( iim,ecinni,1 ) / apoln
-      ecinps = 0.5 * SSUM( iim,ecinsi,1 ) / apols
-
-      DO 4 ij = 1,iip1
-      ecin(   ij     , l ) = ecinpn
-      ecin( ij+ ip1jm, l ) = ecinps
-   4  CONTINUE
-
-   5  CONTINUE
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d_common/enercin.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/enercin.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/enercin.F90	(revision 2408)
@@ -0,0 +1,71 @@
+SUBROUTINE enercin ( vcov, ucov, vcont, ucont, ecin )
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van.
+!-------------------------------------------------------------------------------
+! Purpose: Compute kinetic energy at sigma levels.
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: vcov    (ip1jm,  llm)
+  REAL, INTENT(IN)  :: ucov    (ip1jmp1,llm)
+  REAL, INTENT(IN)  :: vcont   (ip1jm,  llm)
+  REAL, INTENT(IN)  :: ucont   (ip1jmp1,llm)
+  REAL, INTENT(OUT) :: ecin    (ip1jmp1,llm)
+!===============================================================================
+! Notes:
+!                 . V
+!                i,j-1
+!
+!      alpha4 .       . alpha1
+!
+!
+!        U .      . P     . U
+!       i-1,j    i,j      i,j
+!
+!      alpha3 .       . alpha2
+!
+!
+!                 . V
+!                i,j
+!
+! Kinetic energy at scalar point P(i,j) (excluding poles) is:
+!       Ecin = 0.5 * U(i-1,j)**2 *( alpha3 + alpha4 )  +
+!              0.5 * U(i  ,j)**2 *( alpha1 + alpha2 )  +
+!              0.5 * V(i,j-1)**2 *( alpha1 + alpha4 )  +
+!              0.5 * V(i,  j)**2 *( alpha2 + alpha3 )
+!===============================================================================
+! Local variables:
+  INTEGER :: l, ij, i
+  REAL    :: ecinni(iip1), ecinsi(iip1), ecinpn, ecinps
+!===============================================================================
+  DO l=1,llm
+    DO ij = iip2, ip1jm -1
+      ecin(ij+1,l)=0.5*(ucov(ij    ,l)*ucont(ij    ,l)*alpha3p4(ij +1)          &
+                      + ucov(ij+1  ,l)*ucont(ij+1  ,l)*alpha1p2(ij +1)          &
+                      + vcov(ij-iim,l)*vcont(ij-iim,l)*alpha1p4(ij +1)          &
+                      + vcov(ij+1  ,l)*vcont(ij+1  ,l)*alpha2p3(ij +1) )
+    END DO
+    !--- Correction: ecin(1,j,l)= ecin(iip1,j,l)
+    DO ij=iip2,ip1jm,iip1; ecin(ij,l) = ecin(ij+iim,l); END DO
+
+    !--- North pole
+    DO i=1,iim
+      ecinni(i) = vcov(i,l)*vcont(i,l)*aire(i)
+    END DO
+    ecinpn = 0.5*SUM(ecinni(1:iim))/apoln
+    DO ij=1,iip1; ecin(ij,l)=ecinpn; END DO
+
+    !--- South pole
+    DO i=1,iim
+      ecinsi(i) = vcov(i+ip1jmi1,l)*vcont(i+ip1jmi1,l)*aire(i+ip1jm)
+    END DO
+    ecinps = 0.5*SUM(ecinsi(1:iim))/apols
+    DO ij=1,iip1; ecin(ij+ip1jm,l)=ecinps; END DO
+  END DO
+
+END SUBROUTINE enercin
+
Index: DZ5/branches/testing/libf/dyn3d_common/flumass.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/flumass.F	(revision 2407)
+++ 	(revision )
@@ -1,109 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE flumass (massebx,masseby, vcont, ucont, pbaru, pbarv )
-
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteurs:  P. Le Van, F. Hourdin  .
-c   -------
-c
-c   Objet:
-c   ------
-c
-c *********************************************************************
-c     .... calcul du flux de masse  aux niveaux s ......
-c *********************************************************************
-c   massebx,masseby,vcont et ucont sont des argum. d'entree pour le s-pg .
-c       pbaru  et pbarv            sont des argum.de sortie pour le s-pg .
-c
-c=======================================================================
-
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom.h"
-
-      REAL massebx( ip1jmp1,llm ),masseby( ip1jm,llm ) ,
-     * vcont( ip1jm,llm ),ucont( ip1jmp1,llm ),pbaru( ip1jmp1,llm ),
-     * pbarv( ip1jm,llm )
-
-      REAL apbarun( iip1 ),apbarus( iip1 )
-
-      REAL sairen,saireun,saires,saireus,ctn,cts,ctn0,cts0
-      INTEGER  l,ij,i
-
-      REAL       SSUM
-
-
-      DO  5 l = 1,llm
-
-      DO  1 ij = iip2,ip1jm
-      pbaru( ij,l ) = massebx( ij,l ) * ucont( ij,l )
-   1  CONTINUE
-
-      DO 3 ij = 1,ip1jm
-      pbarv( ij,l ) = masseby( ij,l ) * vcont( ij,l )
-   3  CONTINUE
-
-   5  CONTINUE
-
-c    ................................................................
-c     calcul de la composante du flux de masse en x aux poles .......
-c    ................................................................
-c     par la resolution d'1 systeme de 2 equations .
-
-c     la premiere equat.decrivant le calcul de la divergence en 1 point i
-c     du pole,ce calcul etant itere de i=1 a i=im .
-c                 c.a.d   ,
-c     ( ( 0.5*pbaru(i)-0.5*pbaru(i-1) - pbarv(i))/aire(i)   =
-c                                           - somme de ( pbarv(n) )/aire pole
-
-c     l'autre equat.specifiant que la moyenne du flux de masse au pole est =0.
-c     c.a.d    somme de pbaru(n)*aire locale(n) = 0.
-
-c     on en revient ainsi a determiner la constante additive commune aux pbaru
-c     qui representait pbaru(0,j,l) dans l'equat.du calcul de la diverg.au pt
-c     i=1 .
-c     i variant de 1 a im
-c     n variant de 1 a im
-
-      sairen = SSUM( iim,  aire(   1     ), 1 )
-      saireun= SSUM( iim, aireu(   1     ), 1 )
-      saires = SSUM( iim,  aire( ip1jm+1 ), 1 )
-      saireus= SSUM( iim, aireu( ip1jm+1 ), 1 )
-
-      DO 20 l = 1,llm
-
-      ctn =  SSUM( iim, pbarv(    1     ,l),  1 )/ sairen
-      cts =  SSUM( iim, pbarv(ip1jmi1+ 1,l),  1 )/ saires
-
-      pbaru(    1   ,l )=   pbarv(    1     ,l ) - ctn * aire(    1    )
-      pbaru( ip1jm+1,l )= - pbarv( ip1jmi1+1,l ) + cts * aire( ip1jm+1 )
-
-      DO 11 i = 2,iim
-      pbaru(    i    ,l ) = pbaru(   i - 1   ,l )    +
-     *                      pbarv(    i      ,l ) - ctn * aire(   i    )
-
-      pbaru( i+ ip1jm,l ) = pbaru( i+ ip1jm-1,l )    -
-     *                      pbarv( i+ ip1jmi1,l ) + cts * aire(i+ ip1jm)
-  11  CONTINUE
-      DO 12 i = 1,iim
-      apbarun(i) = aireu(    i   ) * pbaru(   i    , l)
-      apbarus(i) = aireu(i +ip1jm) * pbaru(i +ip1jm, l)
-  12  CONTINUE
-      ctn0 = -SSUM( iim,apbarun,1 )/saireun
-      cts0 = -SSUM( iim,apbarus,1 )/saireus
-      DO 14 i = 1,iim
-      pbaru(   i    , l) = 2. * ( pbaru(   i    , l) + ctn0 )
-      pbaru(i+ ip1jm, l) = 2. * ( pbaru(i +ip1jm, l) + cts0 )
-  14  CONTINUE
-
-      pbaru(   iip1 ,l ) = pbaru(    1    ,l )
-      pbaru( ip1jmp1,l ) = pbaru( ip1jm +1,l )
-  20  CONTINUE
-
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d_common/flumass.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/flumass.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/flumass.F90	(revision 2408)
@@ -0,0 +1,76 @@
+SUBROUTINE flumass (massebx,masseby, vcont, ucont, pbaru, pbarv )
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute mass flux at s levels.
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: massebx(ip1jmp1,llm)
+  REAL, INTENT(IN)  :: masseby(ip1jm  ,llm)
+  REAL, INTENT(IN)  :: vcont  (ip1jm  ,llm)
+  REAL, INTENT(IN)  :: ucont  (ip1jmp1,llm)
+  REAL, INTENT(OUT) :: pbaru  (ip1jmp1,llm)
+  REAL, INTENT(OUT) :: pbarv  (ip1jm  ,llm)
+!===============================================================================
+! Method used:   A 2 equations system is solved.
+!   * 1st one describes divergence computation at pole point nr. i (i=1 to im):
+!     (0.5*(pbaru(i)-pbaru(i-1))-pbarv(i))/aire(i) = - SUM(pbarv(n))/aire pole
+!   * 2nd one specifies that mean mass flux at pole is equal to 0:
+!     SUM(pbaru(n)*local_area(n))=0
+! This way, we determine additive constant common to pbary elements representing
+!   pbaru(0,j,l) in divergence computation equation for point i=1. (i=1 to im)
+!===============================================================================
+! Local variables:
+  REAL    :: sairen, saireun, ctn, ctn0, apbarun(iip1)
+  REAL    :: saires, saireus, cts, cts0, apbarus(iip1)
+  INTEGER :: l, i
+!===============================================================================
+  DO l=1,llm
+    pbaru(iip2:ip1jm,l)=massebx(iip2:ip1jm,l)*ucont(iip2:ip1jm,l)
+    pbarv(   1:ip1jm,l)=masseby(   1:ip1jm,l)*vcont(   1:ip1jm,l)
+  END DO
+
+  !--- NORTH POLE
+  sairen =SUM(aire (1:iim))
+  saireun=SUM(aireu(1:iim))
+  DO l = 1,llm
+    ctn=SUM(pbarv(1:iim,l))/sairen
+    pbaru(1,l)= pbarv(1,l)-ctn*aire(1)
+    DO i=2,iim
+      pbaru(i,l)=pbaru(i-1,l)+pbarv(i,l)-ctn*aire(i)
+    END DO
+    DO i=1,iim
+      apbarun(i)=aireu(i)*pbaru(i,l)
+    END DO
+    ctn0 = -SUM(apbarun(1:iim))/saireun
+    DO i = 1,iim
+      pbaru(i,l)=2.*(pbaru(i,l)+ctn0)
+    END DO
+    pbaru(iip1,l)=pbaru(1,l)
+  END DO
+
+  !--- SOUTH POLE
+  saires =SUM(aire (ip1jm+1:ip1jmp1-1))
+  saireus=SUM(aireu(ip1jm+1:ip1jmp1-1))
+  DO l = 1,llm
+    cts=SUM(pbarv(ip1jmi1+1:ip1jm-1,l))/saires
+    pbaru(1+ip1jm,l)=-pbarv(1+ip1jmi1,l)+cts*aire(1+ip1jm)
+    DO i=2,iim
+      pbaru(i+ip1jm,l)=pbaru(i-1+ip1jm,l)-pbarv(i+ip1jmi1,l)+cts*aire(i+ip1jm)
+    END DO
+    DO i=1,iim
+      apbarus(i)=aireu(i+ip1jm)*pbaru(i+ip1jm,l)
+    END DO
+    cts0 = -SUM(apbarus(1:iim))/saireus
+    DO i = 1,iim
+      pbaru(i+ip1jm,l)=2.*(pbaru(i+ip1jm,l)+cts0)
+    END DO
+    pbaru(ip1jmp1,l)=pbaru(1+ip1jm,l)
+  END DO
+
+END SUBROUTINE flumass
Index: DZ5/branches/testing/libf/dyn3d_common/grid_atob.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/grid_atob.F	(revision 2407)
+++ 	(revision )
@@ -1,982 +1,0 @@
-!
-! $Id$
-!
-      SUBROUTINE grille_m(imdep, jmdep, xdata, ydata, entree,
-     .                    imar, jmar, x, y, sortie)
-c=======================================================================
-c z.x.li (le 1 avril 1994) (voir aussi A. Harzallah et L. Fairhead)
-c
-c Methode naive pour transformer un champ d'une grille fine a une
-c grille grossiere. Je considere que les nouveaux points occupent
-c une zone adjacente qui comprend un ou plusieurs anciens points
-c
-c Aucune ponderation est consideree (voir grille_p)
-c
-c           (c)
-c        ----d-----
-c        | . . . .|
-c        |        |
-c     (b)a . * . .b(a)
-c        |        |
-c        | . . . .|
-c        ----c-----
-c           (d)
-C=======================================================================
-c INPUT:
-c        imdep, jmdep: dimensions X et Y pour depart
-c        xdata, ydata: coordonnees X et Y pour depart
-c        entree: champ d'entree a transformer
-c OUTPUT:
-c        imar, jmar: dimensions X et Y d'arrivee
-c        x, y: coordonnees X et Y d'arrivee
-c        sortie: champ de sortie deja transforme
-C=======================================================================
-      IMPLICIT none
-
-      INTEGER imdep, jmdep
-      REAL xdata(imdep),ydata(jmdep) 
-      REAL entree(imdep,jmdep)
-c
-      INTEGER imar, jmar
-      REAL x(imar),y(jmar)
-      REAL sortie(imar,jmar)
-c
-      INTEGER i, j, ii, jj
-      REAL a(2200),b(2200),c(1100),d(1100)
-      REAL number(2200,1100)
-      REAL distans(2200*1100)
-      INTEGER i_proche, j_proche, ij_proche
-#ifdef CRAY
-      INTEGER ISMIN
-#else
-      REAL zzmin
-#endif
-      include "iniprint.h"
-c
-      IF (imar.GT.2200 .OR. jmar.GT.1100) THEN
-         PRINT*, 'imar ou jmar trop grand', imar, jmar
-         CALL ABORT_GCM("", "", 1)
-      ENDIF
-c
-c Calculer les limites des zones des nouveaux points
-c
-
-      a(1) = x(1) - (x(2)-x(1))/2.0
-      b(1) = (x(1)+x(2))/2.0
-      DO i = 2, imar-1
-         a(i) = b(i-1)
-         b(i) = (x(i)+x(i+1))/2.0
-      ENDDO
-      a(imar) = b(imar-1)
-      b(imar) = x(imar) + (x(imar)-x(imar-1))/2.0
-
-      c(1) = y(1) - (y(2)-y(1))/2.0
-      d(1) = (y(1)+y(2))/2.0
-      DO j = 2, jmar-1
-         c(j) = d(j-1)
-         d(j) = (y(j)+y(j+1))/2.0
-      ENDDO
-      c(jmar) = d(jmar-1)
-      d(jmar) = y(jmar) + (y(jmar)-y(jmar-1))/2.0
-
-      DO i = 1, imar
-      DO j = 1, jmar
-         number(i,j) = 0.0
-         sortie(i,j) = 0.0
-      ENDDO
-      ENDDO
-c
-c Determiner la zone sur laquelle chaque ancien point se trouve
-c
-c
-c  .....  Modif  P. Le Van ( 23/08/95 )  ....
-
-      DO ii = 1, imar
-      DO jj = 1, jmar
-        DO i = 1, imdep
-         IF( ( xdata(i)-a(ii).GE.1.e-5.AND.xdata(i)-b(ii).LE.1.e-5 ).OR.
-     .     (   xdata(i)-a(ii).LE.1.e-5.AND.xdata(i)-b(ii).GE.1.e-5 )   )
-     .           THEN
-          DO j = 1, jmdep
-          IF( (ydata(j)-c(jj).GE.1.e-5.AND.ydata(j)-d(jj).LE.1.e-5 ).OR.
-     .      (  ydata(j)-c(jj).LE.1.e-5.AND.ydata(j)-d(jj).GE.1.e-5 )   )
-     .           THEN
-               number(ii,jj) = number(ii,jj) + 1.0
-               sortie(ii,jj) = sortie(ii,jj) + entree(i,j)
-          ENDIF
-          ENDDO
-         ENDIF
-        ENDDO
-      ENDDO
-      ENDDO
-c
-c Si aucun ancien point tombe sur une zone, c'est un probleme
-c
-
-      DO i = 1, imar
-      DO j = 1, jmar
-         IF (number(i,j) .GT. 0.001) THEN
-         sortie(i,j) = sortie(i,j) / number(i,j)
-         ELSE
-         if (prt_level >= 1) PRINT*, 'probleme,i,j=', i,j
-ccc         CALL ABORT_GCM("", "", 1)
-         CALL dist_sphe(x(i),y(j),xdata,ydata,imdep,jmdep,distans)
-#ifdef CRAY
-         ij_proche = ISMIN(imdep*jmdep,distans,1)
-#else
-         ij_proche = 1
-         zzmin = distans(ij_proche)
-         DO ii = 2, imdep*jmdep
-            IF (distans(ii).LT.zzmin) THEN
-               zzmin = distans(ii)
-               ij_proche = ii
-            ENDIF
-         ENDDO
-#endif
-         j_proche = (ij_proche-1)/imdep + 1
-         i_proche = ij_proche - (j_proche-1)*imdep
-         if (prt_level >= 1) PRINT*, "solution:", ij_proche, i_proche,
-     $        j_proche
-         sortie(i,j) = entree(i_proche,j_proche)
-         ENDIF
-      ENDDO
-      ENDDO
-
-      RETURN
-      END
-
-
-      SUBROUTINE grille_p(imdep, jmdep, xdata, ydata, entree,
-     .                    imar, jmar, x, y, sortie)
-c=======================================================================
-c z.x.li (le 1 avril 1994) (voir aussi A. Harzallah et L. Fairhead)
-c
-c Methode naive pour transformer un champ d'une grille fine a une
-c grille grossiere. Je considere que les nouveaux points occupent
-c une zone adjacente qui comprend un ou plusieurs anciens points
-c
-c Consideration de la distance des points (voir grille_m)
-c
-c           (c)
-c        ----d-----
-c        | . . . .|
-c        |        |
-c     (b)a . * . .b(a)
-c        |        |
-c        | . . . .|
-c        ----c-----
-c           (d)
-C=======================================================================
-c INPUT:
-c        imdep, jmdep: dimensions X et Y pour depart
-c        xdata, ydata: coordonnees X et Y pour depart
-c        entree: champ d'entree a transformer
-c OUTPUT:
-c        imar, jmar: dimensions X et Y d'arrivee
-c        x, y: coordonnees X et Y d'arrivee
-c        sortie: champ de sortie deja transforme
-C=======================================================================
-      IMPLICIT none
-
-      INTEGER imdep, jmdep
-      REAL xdata(imdep),ydata(jmdep) 
-      REAL entree(imdep,jmdep)
-c
-      INTEGER imar, jmar
-      REAL x(imar),y(jmar)
-      REAL sortie(imar,jmar)
-c
-      INTEGER i, j, ii, jj
-      REAL a(400),b(400),c(200),d(200)
-      REAL number(400,200)
-      INTEGER indx(400,200), indy(400,200)
-      REAL dist(400,200), distsom(400,200)
-c
-      IF (imar.GT.400 .OR. jmar.GT.200) THEN
-         PRINT*, 'imar ou jmar trop grand', imar, jmar
-         CALL ABORT_GCM("", "", 1)
-      ENDIF
-c
-      IF (imdep.GT.400 .OR. jmdep.GT.200) THEN
-         PRINT*, 'imdep ou jmdep trop grand', imdep, jmdep
-         CALL ABORT_GCM("", "", 1)
-      ENDIF
-c
-c calculer les bords a et b de la nouvelle grille
-c
-      a(1) = x(1) - (x(2)-x(1))/2.0
-      b(1) = (x(1)+x(2))/2.0
-      DO i = 2, imar-1
-         a(i) = b(i-1)
-         b(i) = (x(i)+x(i+1))/2.0
-      ENDDO
-      a(imar) = b(imar-1)
-      b(imar) = x(imar) + (x(imar)-x(imar-1))/2.0
-
-c
-c calculer les bords c et d de la nouvelle grille
-c
-      c(1) = y(1) - (y(2)-y(1))/2.0
-      d(1) = (y(1)+y(2))/2.0
-      DO j = 2, jmar-1
-         c(j) = d(j-1)
-         d(j) = (y(j)+y(j+1))/2.0
-      ENDDO
-      c(jmar) = d(jmar-1)
-      d(jmar) = y(jmar) + (y(jmar)-y(jmar-1))/2.0
-
-c
-c trouver les indices (indx,indy) de la nouvelle grille sur laquelle
-c un point de l'ancienne grille est tombe.
-c
-c
-c  .....  Modif  P. Le Van ( 23/08/95 )  ....
-
-      DO ii = 1, imar
-      DO jj = 1, jmar
-        DO i = 1, imdep
-         IF( ( xdata(i)-a(ii).GE.1.e-5.AND.xdata(i)-b(ii).LE.1.e-5 ).OR.
-     .     (   xdata(i)-a(ii).LE.1.e-5.AND.xdata(i)-b(ii).GE.1.e-5 )   )
-     .           THEN
-          DO j = 1, jmdep
-          IF( (ydata(j)-c(jj).GE.1.e-5.AND.ydata(j)-d(jj).LE.1.e-5 ).OR.
-     .      (  ydata(j)-c(jj).LE.1.e-5.AND.ydata(j)-d(jj).GE.1.e-5 )   )
-     .           THEN
-               indx(i,j) = ii
-               indy(i,j) = jj
-          ENDIF
-          ENDDO
-         ENDIF
-        ENDDO
-      ENDDO
-      ENDDO
-c
-c faire une verification
-c
-
-      DO i = 1, imdep
-      DO j = 1, jmdep
-         IF (indx(i,j).GT.imar .OR. indy(i,j).GT.jmar) THEN
-            PRINT*, 'Probleme grave,i,j,indx,indy=',
-     .              i,j,indx(i,j),indy(i,j)
-            call abort_gcm("", "", 1)
-         ENDIF
-      ENDDO
-      ENDDO
-
-c
-c calculer la distance des anciens points avec le nouveau point,
-c on prend ensuite une sorte d'inverse pour ponderation.
-c
-
-      DO i = 1, imar
-      DO j = 1, jmar
-         number(i,j) = 0.0
-         distsom(i,j) = 0.0
-      ENDDO
-      ENDDO
-      DO i = 1, imdep
-      DO j = 1, jmdep
-         dist(i,j) = SQRT ( (xdata(i)-x(indx(i,j)))**2
-     .                     +(ydata(j)-y(indy(i,j)))**2 )
-         distsom(indx(i,j),indy(i,j)) = distsom(indx(i,j),indy(i,j))
-     .                                  + dist(i,j)
-         number(indx(i,j),indy(i,j)) = number(indx(i,j),indy(i,j)) +1.
-      ENDDO
-      ENDDO
-      DO i = 1, imdep
-      DO j = 1, jmdep
-         dist(i,j) = 1.0 - dist(i,j)/distsom(indx(i,j),indy(i,j))
-      ENDDO
-      ENDDO
-
-      DO i = 1, imar
-      DO j = 1, jmar
-         number(i,j) = 0.0
-         sortie(i,j) = 0.0
-      ENDDO
-      ENDDO
-      DO i = 1, imdep
-      DO j = 1, jmdep
-         sortie(indx(i,j),indy(i,j)) = sortie(indx(i,j),indy(i,j))
-     .                                 + entree(i,j) * dist(i,j)
-         number(indx(i,j),indy(i,j)) = number(indx(i,j),indy(i,j))
-     .                                 + dist(i,j)
-      ENDDO
-      ENDDO
-      DO i = 1, imar
-      DO j = 1, jmar
-         IF (number(i,j) .GT. 0.001) THEN
-         sortie(i,j) = sortie(i,j) / number(i,j)
-         ELSE
-         PRINT*, 'probleme,i,j=', i,j
-         CALL ABORT_GCM("", "", 1)
-         ENDIF
-      ENDDO
-      ENDDO
-
-      RETURN
-      END
-
-
-
-
-      SUBROUTINE mask_c_o(imdep, jmdep, xdata, ydata, relief,
-     .                    imar, jmar, x, y, mask)
-c=======================================================================
-c z.x.li (le 1 avril 1994): A partir du champ de relief, on fabrique
-c                           un champ indicateur (masque) terre/ocean
-c                           terre:1; ocean:0
-c
-c Methode naive (voir grille_m)
-C=======================================================================
-      IMPLICIT none
-
-      INTEGER imdep, jmdep
-      REAL xdata(imdep),ydata(jmdep) 
-      REAL relief(imdep,jmdep)
-c
-      INTEGER imar, jmar
-      REAL x(imar),y(jmar)
-      REAL mask(imar,jmar)
-c
-      INTEGER i, j, ii, jj
-      REAL a(2200),b(2200),c(1100),d(1100)
-      REAL num_tot(2200,1100), num_oce(2200,1100)
-c
-      IF (imar.GT.2200 .OR. jmar.GT.1100) THEN
-         PRINT*, 'imar ou jmar trop grand', imar, jmar
-         CALL ABORT_GCM("", "", 1)
-      ENDIF
-c
-
-      a(1) = x(1) - (x(2)-x(1))/2.0
-      b(1) = (x(1)+x(2))/2.0
-      DO i = 2, imar-1
-         a(i) = b(i-1)
-         b(i) = (x(i)+x(i+1))/2.0
-      ENDDO
-      a(imar) = b(imar-1)
-      b(imar) = x(imar) + (x(imar)-x(imar-1))/2.0
-
-      c(1) = y(1) - (y(2)-y(1))/2.0
-      d(1) = (y(1)+y(2))/2.0
-      DO j = 2, jmar-1
-         c(j) = d(j-1)
-         d(j) = (y(j)+y(j+1))/2.0
-      ENDDO
-      c(jmar) = d(jmar-1)
-      d(jmar) = y(jmar) + (y(jmar)-y(jmar-1))/2.0
-
-      DO i = 1, imar
-      DO j = 1, jmar
-         num_oce(i,j) = 0.0
-         num_tot(i,j) = 0.0
-      ENDDO
-      ENDDO
-
-c
-c  .....  Modif  P. Le Van ( 23/08/95 )  ....
-
-      DO ii = 1, imar
-      DO jj = 1, jmar
-        DO i = 1, imdep
-         IF( ( xdata(i)-a(ii).GE.1.e-5.AND.xdata(i)-b(ii).LE.1.e-5 ).OR.
-     .     (   xdata(i)-a(ii).LE.1.e-5.AND.xdata(i)-b(ii).GE.1.e-5 )   )
-     .           THEN
-          DO j = 1, jmdep
-          IF( (ydata(j)-c(jj).GE.1.e-5.AND.ydata(j)-d(jj).LE.1.e-5 ).OR.
-     .      (  ydata(j)-c(jj).LE.1.e-5.AND.ydata(j)-d(jj).GE.1.e-5 )   )
-     .           THEN
-               num_tot(ii,jj) = num_tot(ii,jj) + 1.0
-               IF (.NOT. ( relief(i,j) - 0.9. GE. 1.e-5 ) )
-     .             num_oce(ii,jj) = num_oce(ii,jj) + 1.0
-          ENDIF
-          ENDDO
-         ENDIF
-        ENDDO
-      ENDDO
-      ENDDO
-c
-c
-c
-      DO i = 1, imar
-      DO j = 1, jmar
-         IF (num_tot(i,j) .GT. 0.001) THEN
-           IF ( num_oce(i,j)/num_tot(i,j) - 0.5 .GE. 1.e-5 ) THEN
-              mask(i,j) = 0.
-           ELSE
-              mask(i,j) = 1.
-           ENDIF
-         ELSE
-         PRINT*, 'probleme,i,j=', i,j
-         CALL ABORT_GCM("", "", 1)
-         ENDIF
-      ENDDO
-      ENDDO
-
-      RETURN
-      END
-c
-c
-
-
-      SUBROUTINE rugosite(imdep, jmdep, xdata, ydata, entree,
-     .                    imar, jmar, x, y, sortie, mask)
-c=======================================================================
-c z.x.li (le 1 avril 1994): Transformer la longueur de rugosite d'une
-c grille fine a une grille grossiere. Sur l'ocean, on impose une valeur
-c fixe (0.001m).
-c
-c Methode naive (voir grille_m)
-C=======================================================================
-      IMPLICIT none
-
-      INTEGER imdep, jmdep
-      REAL xdata(imdep),ydata(jmdep) 
-      REAL entree(imdep,jmdep)
-c
-      INTEGER imar, jmar
-      REAL x(imar),y(jmar)
-      REAL sortie(imar,jmar), mask(imar,jmar)
-c
-      INTEGER i, j, ii, jj
-      REAL a(400),b(400),c(400),d(400)
-      REAL num_tot(400,400)
-      REAL distans(400*400)
-      INTEGER i_proche, j_proche, ij_proche
-#ifdef CRAY
-      INTEGER ISMIN
-#else
-      REAL zzmin
-#endif
-      include "iniprint.h"
-c
-      IF (imar.GT.400 .OR. jmar.GT.400) THEN
-         PRINT*, 'imar ou jmar trop grand', imar, jmar
-         CALL ABORT_GCM("", "", 1)
-      ENDIF
-c
-
-      a(1) = x(1) - (x(2)-x(1))/2.0
-      b(1) = (x(1)+x(2))/2.0
-      DO i = 2, imar-1
-         a(i) = b(i-1)
-         b(i) = (x(i)+x(i+1))/2.0
-      ENDDO
-      a(imar) = b(imar-1)
-      b(imar) = x(imar) + (x(imar)-x(imar-1))/2.0
-
-      c(1) = y(1) - (y(2)-y(1))/2.0
-      d(1) = (y(1)+y(2))/2.0
-      DO j = 2, jmar-1
-         c(j) = d(j-1)
-         d(j) = (y(j)+y(j+1))/2.0
-      ENDDO
-      c(jmar) = d(jmar-1)
-      d(jmar) = y(jmar) + (y(jmar)-y(jmar-1))/2.0
-
-      DO i = 1, imar
-      DO j = 1, jmar
-         num_tot(i,j) = 0.0
-         sortie(i,j) = 0.0
-      ENDDO
-      ENDDO
-
-c
-c
-c  .....  Modif  P. Le Van ( 23/08/95 )  ....
-
-      DO ii = 1, imar
-      DO jj = 1, jmar
-        DO i = 1, imdep
-         IF( ( xdata(i)-a(ii).GE.1.e-5.AND.xdata(i)-b(ii).LE.1.e-5 ).OR.
-     .     (   xdata(i)-a(ii).LE.1.e-5.AND.xdata(i)-b(ii).GE.1.e-5 )   )
-     .           THEN
-          DO j = 1, jmdep
-          IF( (ydata(j)-c(jj).GE.1.e-5.AND.ydata(j)-d(jj).LE.1.e-5 ).OR.
-     .      (  ydata(j)-c(jj).LE.1.e-5.AND.ydata(j)-d(jj).GE.1.e-5 )   )
-     .           THEN
-              sortie(ii,jj)  = sortie(ii,jj) + LOG(entree(i,j))
-              num_tot(ii,jj) = num_tot(ii,jj) + 1.0
-          ENDIF
-          ENDDO
-         ENDIF
-        ENDDO
-      ENDDO
-      ENDDO
-c
-
-      DO i = 1, imar
-      DO j = 1, jmar
-       IF (NINT(mask(i,j)).EQ.1) THEN
-         IF (num_tot(i,j) .GT. 0.0) THEN
-            sortie(i,j) = sortie(i,j) / num_tot(i,j)
-            sortie(i,j) = EXP(sortie(i,j))
-         ELSE
-            if (prt_level >= 1) PRINT*, 'probleme,i,j=', i,j
-ccc            CALL ABORT_GCM("", "", 1)
-         CALL dist_sphe(x(i),y(j),xdata,ydata,imdep,jmdep,distans)
-#ifdef CRAY
-         ij_proche = ISMIN(imdep*jmdep,distans,1)
-#else
-         ij_proche = 1
-         zzmin = distans(ij_proche)
-         DO ii = 2, imdep*jmdep
-            IF (distans(ii).LT.zzmin) THEN
-               zzmin = distans(ii)
-               ij_proche = ii
-            ENDIF
-         ENDDO
-#endif
-         j_proche = (ij_proche-1)/imdep + 1
-         i_proche = ij_proche - (j_proche-1)*imdep
-         if (prt_level >= 1) PRINT*, "solution:", ij_proche, i_proche,
-     $        j_proche
-         sortie(i,j) = entree(i_proche,j_proche)
-         ENDIF
-       ELSE
-         sortie(i,j) = 0.001
-       ENDIF
-      ENDDO
-      ENDDO
-
-      RETURN
-      END
-
-
-
-
-
-      SUBROUTINE sea_ice(imdep, jmdep, xdata, ydata, glace01,
-     .                    imar, jmar, x, y, frac_ice)
-c=======================================================================
-c z.x.li (le 1 avril 1994): Transformer un champ d'indicateur de la
-c glace (1, sinon 0) d'une grille fine a un champ de fraction de glace
-c (entre 0 et 1) dans une grille plus grossiere.
-c
-c Methode naive (voir grille_m)
-C=======================================================================
-      IMPLICIT none
-
-      INTEGER imdep, jmdep
-      REAL xdata(imdep),ydata(jmdep) 
-      REAL glace01(imdep,jmdep)
-c
-      INTEGER imar, jmar
-      REAL x(imar),y(jmar)
-      REAL frac_ice(imar,jmar)
-c
-      INTEGER i, j, ii, jj
-      REAL a(400),b(400),c(400),d(400)
-      REAL num_tot(400,400), num_ice(400,400)
-      REAL distans(400*400)
-      INTEGER i_proche, j_proche, ij_proche
-#ifdef CRAY
-      INTEGER ISMIN
-#else
-      REAL zzmin
-#endif
-      include "iniprint.h"
-c
-      IF (imar.GT.400 .OR. jmar.GT.400) THEN
-         PRINT*, 'imar ou jmar trop grand', imar, jmar
-         CALL ABORT_GCM("", "", 1)
-      ENDIF
-c
-
-      a(1) = x(1) - (x(2)-x(1))/2.0
-      b(1) = (x(1)+x(2))/2.0
-      DO i = 2, imar-1
-         a(i) = b(i-1)
-         b(i) = (x(i)+x(i+1))/2.0
-      ENDDO
-      a(imar) = b(imar-1)
-      b(imar) = x(imar) + (x(imar)-x(imar-1))/2.0
-
-      c(1) = y(1) - (y(2)-y(1))/2.0
-      d(1) = (y(1)+y(2))/2.0
-      DO j = 2, jmar-1
-         c(j) = d(j-1)
-         d(j) = (y(j)+y(j+1))/2.0
-      ENDDO
-      c(jmar) = d(jmar-1)
-      d(jmar) = y(jmar) + (y(jmar)-y(jmar-1))/2.0
-
-      DO i = 1, imar
-      DO j = 1, jmar
-         num_ice(i,j) = 0.0
-         num_tot(i,j) = 0.0
-      ENDDO
-      ENDDO
-
-c
-c
-c  .....  Modif  P. Le Van ( 23/08/95 )  ....
-
-      DO ii = 1, imar
-      DO jj = 1, jmar
-        DO i = 1, imdep
-         IF( ( xdata(i)-a(ii).GE.1.e-5.AND.xdata(i)-b(ii).LE.1.e-5 ).OR.
-     .     (   xdata(i)-a(ii).LE.1.e-5.AND.xdata(i)-b(ii).GE.1.e-5 )   )
-     .           THEN
-          DO j = 1, jmdep
-          IF( (ydata(j)-c(jj).GE.1.e-5.AND.ydata(j)-d(jj).LE.1.e-5 ).OR.
-     .      (  ydata(j)-c(jj).LE.1.e-5.AND.ydata(j)-d(jj).GE.1.e-5 )   )
-     .           THEN
-             num_tot(ii,jj) = num_tot(ii,jj) + 1.0
-              IF (NINT(glace01(i,j)).EQ.1 ) 
-     .       num_ice(ii,jj) = num_ice(ii,jj) + 1.0
-          ENDIF
-          ENDDO
-         ENDIF
-        ENDDO
-      ENDDO
-      ENDDO
-c
-c
-
-      DO i = 1, imar
-      DO j = 1, jmar
-         IF (num_tot(i,j) .GT. 0.001) THEN
-           IF (num_ice(i,j).GT.0.001) THEN
-            frac_ice(i,j) = num_ice(i,j) / num_tot(i,j)
-           ELSE
-              frac_ice(i,j) = 0.0
-           ENDIF
-         ELSE
-           if (prt_level >= 1) PRINT*, 'probleme,i,j=', i,j
-ccc           CALL ABORT_GCM("", "", 1)
-         CALL dist_sphe(x(i),y(j),xdata,ydata,imdep,jmdep,distans)
-#ifdef CRAY
-         ij_proche = ISMIN(imdep*jmdep,distans,1)
-#else
-         ij_proche = 1
-         zzmin = distans(ij_proche)
-         DO ii = 2, imdep*jmdep
-            IF (distans(ii).LT.zzmin) THEN
-               zzmin = distans(ii)
-               ij_proche = ii
-            ENDIF
-         ENDDO
-#endif
-         j_proche = (ij_proche-1)/imdep + 1
-         i_proche = ij_proche - (j_proche-1)*imdep
-         if (prt_level >= 1) PRINT*, "solution:", ij_proche, i_proche,
-     $        j_proche
-         IF (NINT(glace01(i_proche,j_proche)).EQ.1 ) THEN
-            frac_ice(i,j) = 1.0
-         ELSE
-            frac_ice(i,j) = 0.0
-         ENDIF
-         ENDIF
-      ENDDO
-      ENDDO
-
-      RETURN
-      END
-
-
-
-      SUBROUTINE rugsoro(imrel, jmrel, xrel, yrel, relief,
-     .                    immod, jmmod, xmod, ymod, rugs)
-c=======================================================================
-c Calculer la longueur de rugosite liee au relief en utilisant
-c l'ecart-type dans une maille de 1x1
-C=======================================================================
-      IMPLICIT none
-c
-#ifdef CRAY
-      INTEGER ISMIN
-#else
-      REAL zzmin
-#endif
-c
-      REAL amin, AMAX
-c
-      INTEGER imrel, jmrel
-      REAL xrel(imrel),yrel(jmrel)
-      REAL relief(imrel,jmrel)
-c
-      INTEGER immod, jmmod
-      REAL xmod(immod),ymod(jmmod)
-      REAL rugs(immod,jmmod)
-c
-      INTEGER imtmp, jmtmp
-      PARAMETER (imtmp=360,jmtmp=180)
-      REAL xtmp(imtmp), ytmp(jmtmp)
-      REAL(KIND=8) cham1tmp(imtmp,jmtmp), cham2tmp(imtmp,jmtmp)
-      REAL zzzz
-c
-      INTEGER i, j, ii, jj
-      REAL a(2200),b(2200),c(1100),d(1100)
-      REAL number(2200,1100)
-c
-      REAL distans(400*400)
-      INTEGER i_proche, j_proche, ij_proche
-c
-      include "iniprint.h"
-
-      IF (immod.GT.2200 .OR. jmmod.GT.1100) THEN
-         PRINT*, 'immod ou jmmod trop grand', immod, jmmod
-         CALL ABORT_GCM("", "", 1)
-      ENDIF
-c
-c Calculs intermediares:
-c
-      xtmp(1) = -180.0 + 360.0/REAL(imtmp) / 2.0
-      DO i = 2, imtmp
-         xtmp(i) = xtmp(i-1) + 360.0/REAL(imtmp)
-      ENDDO
-      DO i = 1, imtmp
-         xtmp(i) = xtmp(i) /180.0 * 4.0*ATAN(1.0)
-      ENDDO
-      ytmp(1) = -90.0 + 180.0/REAL(jmtmp) / 2.0
-      DO j = 2, jmtmp
-         ytmp(j) = ytmp(j-1) + 180.0/REAL(jmtmp)
-      ENDDO
-      DO j = 1, jmtmp
-         ytmp(j) = ytmp(j) /180.0 * 4.0*ATAN(1.0)
-      ENDDO
-c
-      a(1) = xtmp(1) - (xtmp(2)-xtmp(1))/2.0
-      b(1) = (xtmp(1)+xtmp(2))/2.0
-      DO i = 2, imtmp-1
-         a(i) = b(i-1)
-         b(i) = (xtmp(i)+xtmp(i+1))/2.0
-      ENDDO
-      a(imtmp) = b(imtmp-1)
-      b(imtmp) = xtmp(imtmp) + (xtmp(imtmp)-xtmp(imtmp-1))/2.0
-
-      c(1) = ytmp(1) - (ytmp(2)-ytmp(1))/2.0
-      d(1) = (ytmp(1)+ytmp(2))/2.0
-      DO j = 2, jmtmp-1
-         c(j) = d(j-1)
-         d(j) = (ytmp(j)+ytmp(j+1))/2.0
-      ENDDO
-      c(jmtmp) = d(jmtmp-1)
-      d(jmtmp) = ytmp(jmtmp) + (ytmp(jmtmp)-ytmp(jmtmp-1))/2.0
-
-      DO i = 1, imtmp
-      DO j = 1, jmtmp
-         number(i,j) = 0.0
-         cham1tmp(i,j) = 0.0
-         cham2tmp(i,j) = 0.0
-      ENDDO
-      ENDDO
-c
-c
-c
-c  .....  Modif  P. Le Van ( 23/08/95 )  ....
-
-      DO ii = 1, imtmp
-      DO jj = 1, jmtmp
-        DO i = 1, imrel
-         IF( ( xrel(i)-a(ii).GE.1.e-5.AND.xrel(i)-b(ii).LE.1.e-5 ).OR.
-     .     (   xrel(i)-a(ii).LE.1.e-5.AND.xrel(i)-b(ii).GE.1.e-5 )   )
-     .           THEN
-          DO j = 1, jmrel
-          IF( (yrel(j)-c(jj).GE.1.e-5.AND.yrel(j)-d(jj).LE.1.e-5 ).OR.
-     .      (  yrel(j)-c(jj).LE.1.e-5.AND.yrel(j)-d(jj).GE.1.e-5 )   )
-     .           THEN
-              number(ii,jj) = number(ii,jj) + 1.0
-              cham1tmp(ii,jj) = cham1tmp(ii,jj) + relief(i,j)
-              cham2tmp(ii,jj) = cham2tmp(ii,jj) 
-     .                              + relief(i,j)*relief(i,j)
-          ENDIF
-          ENDDO
-         ENDIF
-        ENDDO
-      ENDDO
-      ENDDO
-c
-c
-      DO i = 1, imtmp
-      DO j = 1, jmtmp
-         IF (number(i,j) .GT. 0.001) THEN
-         cham1tmp(i,j) = cham1tmp(i,j) / number(i,j)
-         cham2tmp(i,j) = cham2tmp(i,j) / number(i,j)
-         zzzz=cham2tmp(i,j)-cham1tmp(i,j)**2
-         if (zzzz .lt. 0.0) then
-           if (zzzz .gt. -7.5) then
-             zzzz = 0.0
-             print*,'Pb rugsoro, -7.5 < zzzz < 0, => zzz = 0.0'
-           else
-              stop 'Pb rugsoro, zzzz <-7.5'
-           endif
-         endif
-         cham2tmp(i,j) = SQRT(zzzz)
-         ELSE
-         PRINT*, 'probleme,i,j=', i,j
-         CALL ABORT_GCM("", "", 1)
-         ENDIF
-      ENDDO
-      ENDDO
-c
-      amin = cham2tmp(1,1)
-      AMAX = cham2tmp(1,1)
-      DO j = 1, jmtmp
-      DO i = 1, imtmp
-         IF (cham2tmp(i,j).GT.AMAX) AMAX = cham2tmp(i,j)
-         IF (cham2tmp(i,j).LT.amin) amin = cham2tmp(i,j)
-      ENDDO
-      ENDDO
-      PRINT*, 'Ecart-type 1x1:', amin, AMAX
-c
-c
-c
-      a(1) = xmod(1) - (xmod(2)-xmod(1))/2.0
-      b(1) = (xmod(1)+xmod(2))/2.0
-      DO i = 2, immod-1
-         a(i) = b(i-1)
-         b(i) = (xmod(i)+xmod(i+1))/2.0
-      ENDDO
-      a(immod) = b(immod-1)
-      b(immod) = xmod(immod) + (xmod(immod)-xmod(immod-1))/2.0
-
-      c(1) = ymod(1) - (ymod(2)-ymod(1))/2.0
-      d(1) = (ymod(1)+ymod(2))/2.0
-      DO j = 2, jmmod-1
-         c(j) = d(j-1)
-         d(j) = (ymod(j)+ymod(j+1))/2.0
-      ENDDO
-      c(jmmod) = d(jmmod-1)
-      d(jmmod) = ymod(jmmod) + (ymod(jmmod)-ymod(jmmod-1))/2.0
-c
-      DO i = 1, immod
-      DO j = 1, jmmod
-         number(i,j) = 0.0
-         rugs(i,j) = 0.0
-      ENDDO
-      ENDDO
-c
-c
-c
-c  .....  Modif  P. Le Van ( 23/08/95 )  ....
-
-      DO ii = 1, immod
-      DO jj = 1, jmmod
-        DO i = 1, imtmp
-         IF( ( xtmp(i)-a(ii).GE.1.e-5.AND.xtmp(i)-b(ii).LE.1.e-5 ).OR.
-     .     (   xtmp(i)-a(ii).LE.1.e-5.AND.xtmp(i)-b(ii).GE.1.e-5 )   )
-     .           THEN
-          DO j = 1, jmtmp
-          IF( (ytmp(j)-c(jj).GE.1.e-5.AND.ytmp(j)-d(jj).LE.1.e-5 ).OR.
-     .      (  ytmp(j)-c(jj).LE.1.e-5.AND.ytmp(j)-d(jj).GE.1.e-5 )   )
-     .           THEN
-              number(ii,jj) = number(ii,jj) + 1.0
-              rugs(ii,jj) = rugs(ii,jj)
-     .                       + LOG(MAX(0.001_8,cham2tmp(i,j)))
-          ENDIF
-          ENDDO
-         ENDIF
-        ENDDO
-      ENDDO
-      ENDDO
-c
-c
-      DO i = 1, immod
-      DO j = 1, jmmod
-         IF (number(i,j) .GT. 0.001) THEN
-         rugs(i,j) = rugs(i,j) / number(i,j)
-         rugs(i,j) = EXP(rugs(i,j))
-         ELSE
-         if (prt_level >= 1) PRINT*, 'probleme,i,j=', i,j
-ccc         CALL ABORT_GCM("", "", 1)
-         CALL dist_sphe(xmod(i),ymod(j),xtmp,ytmp,imtmp,jmtmp,distans)
-#ifdef CRAY
-         ij_proche = ISMIN(imtmp*jmtmp,distans,1)
-#else
-         ij_proche = 1
-         zzmin = distans(ij_proche)
-         DO ii = 2, imtmp*jmtmp
-            IF (distans(ii).LT.zzmin) THEN
-               zzmin = distans(ii)
-               ij_proche = ii
-            ENDIF
-         ENDDO
-#endif
-         j_proche = (ij_proche-1)/imtmp + 1
-         i_proche = ij_proche - (j_proche-1)*imtmp
-         if (prt_level >= 1) PRINT*, "solution:", ij_proche, i_proche,
-     $        j_proche
-         rugs(i,j) = LOG(MAX(0.001_8,cham2tmp(i_proche,j_proche)))
-         ENDIF
-      ENDDO
-      ENDDO
-c
-      amin = rugs(1,1)
-      AMAX = rugs(1,1)
-      DO j = 1, jmmod
-      DO i = 1, immod
-         IF (rugs(i,j).GT.AMAX) AMAX = rugs(i,j)
-         IF (rugs(i,j).LT.amin) amin = rugs(i,j)
-      ENDDO
-      ENDDO
-      PRINT*, 'Ecart-type du modele:', amin, AMAX
-c
-      DO j = 1, jmmod
-      DO i = 1, immod
-         rugs(i,j) = rugs(i,j) / AMAX * 20.0
-      ENDDO
-      ENDDO
-c
-      amin = rugs(1,1)
-      AMAX = rugs(1,1)
-      DO j = 1, jmmod
-      DO i = 1, immod
-         IF (rugs(i,j).GT.AMAX) AMAX = rugs(i,j)
-         IF (rugs(i,j).LT.amin) amin = rugs(i,j)
-      ENDDO
-      ENDDO
-      PRINT*, 'Longueur de rugosite du modele:', amin, AMAX
-c
-      RETURN
-      END
-c
-      SUBROUTINE dist_sphe(rf_lon,rf_lat,rlon,rlat,im,jm,distance)
-      IMPLICIT NONE
-c
-c Auteur: Laurent Li (le 30 decembre 1996)
-c
-c Ce programme calcule la distance minimale (selon le grand cercle)
-c entre deux points sur la terre
-c
-c Input:
-      INTEGER im, jm ! dimensions
-      REAL rf_lon ! longitude du point de reference (degres)
-      REAL rf_lat ! latitude du point de reference (degres)
-      REAL rlon(im), rlat(jm) ! longitude et latitude des points
-c
-c Output:
-      REAL distance(im,jm) ! distances en metre
-c
-      REAL rlon1, rlat1
-      REAL rlon2, rlat2
-      REAL dist
-      REAL pa, pb, p, pi
-c
-      REAL radius
-      PARAMETER (radius=6371229.)
-      INTEGER i,j
-c
-      pi = 4.0 * ATAN(1.0)
-c
-      DO 9999 j = 1, jm
-      DO 9999 i = 1, im
-c
-      rlon1=rf_lon
-      rlat1=rf_lat
-      rlon2=rlon(i)
-      rlat2=rlat(j)
-      pa = pi/2.0 - rlat1*pi/180.0 ! dist. entre pole n et point a
-      pb = pi/2.0 - rlat2*pi/180.0 ! dist. entre pole n et point b
-      p = (rlon1-rlon2)*pi/180.0 ! angle entre a et b (leurs meridiens)
-c
-      dist = ACOS( COS(pa)*COS(pb) + SIN(pa)*SIN(pb)*COS(p))
-      dist = radius * dist
-      distance(i,j) = dist
-c
- 9999 CONTINUE
-c
-      END
Index: DZ5/branches/testing/libf/dyn3d_common/grid_noro.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/grid_noro.F	(revision 2407)
+++ 	(revision )
@@ -1,532 +1,0 @@
-!
-! $Id$
-!
-c
-c
-      SUBROUTINE grid_noro(imdep, jmdep, xdata, ydata, zdata,
-     .             imar, jmar, x, y,
-     .             zphi,zmea,zstd,zsig,zgam,zthe,
-     .             zpic,zval,mask)
-c=======================================================================
-c (F. Lott) (voir aussi z.x. Li, A. Harzallah et L. Fairhead)
-c
-c      Compute the Parameters of the SSO scheme as described in
-c      LOTT & MILLER (1997) and LOTT(1999).
-c      Target points are on a rectangular grid:
-c      iim+1 latitudes including North and South Poles;
-c      jjm+1 longitudes, with periodicity jjm+1=1.
-c      aux poles.  At the poles the fields value is repeated
-c      jjm+1 time.
-c      The parameters a,b,c,d represent the limite of the target
-c      gridpoint region. The means over this region are calculated
-c      from USN data, ponderated by a weight proportional to the 
-c      surface occupated by the data inside the model gridpoint area.
-c      In most circumstances, this weight is the ratio between the
-c      surface of the USN gridpoint area and the surface of the
-c      model gridpoint area. 
-c
-c           (c)
-c        ----d-----
-c        | . . . .|
-c        |        |
-c     (b)a . * . .b(a)
-c        |        |
-c        | . . . .|
-c        ----c-----
-c           (d)
-C=======================================================================
-c INPUT:
-c        imdep, jmdep: dimensions X and Y input field
-c        xdata, ydata: coordinates X and Y input field
-c        zdata: Input field
-c        In this version it is assumed that the entry data come from
-c        the USNavy dataset: imdep=iusn=2160, jmdep=jusn=1080.
-c OUTPUT:
-c        imar, jmar: dimensions X and Y Output field
-c        x, y: ccordinates  X and Y Output field.
-c             zmea:  Mean orographie   
-c             zstd:  Standard deviation
-c             zsig:  Slope
-c             zgam:  Anisotropy
-c             zthe:  Orientation of the small axis
-c             zpic:  Maximum altitude
-c             zval:  Minimum altitude
-C=======================================================================
-
-      IMPLICIT NONE 
-      
-      INTEGER,PARAMETER :: iusn=2160,jusn=1080,iext=216
-      REAL,PARAMETER :: epsfra = 1.e-5
-#include "dimensions.h"
-	  REAL xusn(iusn+2*iext),yusn(jusn+2)	
-      REAL zusn(iusn+2*iext,jusn+2)
-
-      INTEGER imdep, jmdep
-      REAL xdata(imdep),ydata(jmdep) 
-      REAL zdata(imdep,jmdep)
-c
-      INTEGER imar, jmar
-  
-C INTERMEDIATE FIELDS  (CORRELATIONS OF OROGRAPHY GRADIENT)
-
-      REAL ztz(iim+1,jjm+1),zxtzx(iim+1,jjm+1)
-      REAL zytzy(iim+1,jjm+1),zxtzy(iim+1,jjm+1)
-      REAL weight(iim+1,jjm+1)
-
-C CORRELATIONS OF USN OROGRAPHY GRADIENTS
-
-      REAL zxtzxusn(iusn+2*iext,jusn+2),zytzyusn(iusn+2*iext,jusn+2)
-      REAL zxtzyusn(iusn+2*iext,jusn+2)
-      REAL x(imar+1),y(jmar),zphi(imar+1,jmar)
-      REAL zmea(imar+1,jmar),zstd(imar+1,jmar)
-      REAL zmea0(imar+1,jmar) ! GK211005 (CG)
-      REAL zsig(imar+1,jmar),zgam(imar+1,jmar),zthe(imar+1,jmar)
-      REAL zpic(imar+1,jmar),zval(imar+1,jmar)
-cxxx PB     integer mask(imar+1,jmar)
-      real mask(imar+1,jmar), mask_tmp(imar+1,jmar)
-      real num_tot(2200,1100),num_lan(2200,1100)
-c
-      REAL a(2200),b(2200),c(1100),d(1100)
-      logical masque_lu
-      INTEGER i,j,ii,jj
-      REAL xpi, rad, zdeltay, masque
-      REAL zdeltax, zlenx, zleny, xincr
-      REAL zbordnor, zbordsud, weighy, zbordest, zbordoue, weighx
-      REAL zllmmea, zllmstd, zllmsig, zllmgam, zllmpic, zllmval
-      REAL zllmthe, zminthe
-      REAL xk, xl, xm, xp, xq, xw
-      REAL zmeanor, zmeasud, zstdnor, zstdsud, zsignor, zsigsud
-      REAL zweinor, zweisud, zpicnor, zpicsud, zvalnor, zvalsud
-c
-      print *,' parametres de l orographie a l echelle sous maille' 
-      xpi=acos(-1.)
-      rad    = 6 371 229.
-      zdeltay=2.*xpi/REAL(jusn)*rad
-c
-c utilise-t'on un masque lu?
-c
-      masque_lu = .true.
-      if (maxval(mask) == -99999 .and. minval(mask) == -99999) then
-        masque_lu= .false.
-        masque = 0.0
-      endif
-      write(*,*)'Masque lu', masque_lu
-c
-c  quelques tests de dimensions:
-c    
-c
-      if(iim.ne.imar) STOP 'Problem dim. x'
-      if(jjm.ne.jmar-1) STOP 'Problem dim. y'
-      IF (imar.GT.2200 .OR. jmar.GT.1100) THEN
-         PRINT*, 'imar or jmar too big', imar, jmar
-         CALL ABORT_GCM("GRID_NORO", "", 1)
-      ENDIF
-
-      IF(imdep.ne.iusn.or.jmdep.ne.jusn)then
-         print *,' imdep or jmdep bad dimensions:',imdep,jmdep
-         call abort_gcm("grid_noro", "", 1)
-      ENDIF
-
-      IF(imar+1.ne.iim+1.or.jmar.ne.jjm+1)THEN
-        print *,' imar or jmar bad dimensions:',imar,jmar
-        call abort_gcm("grid_noro", "", 1)
-      ENDIF
-
-
-c      print *,'xdata:',xdata
-c      print *,'ydata:',ydata
-c      print *,'x:',x
-c      print *,'y:',y
-c
-C  EXTENSION OF THE USN DATABASE TO POCEED COMPUTATIONS AT
-C  BOUNDARIES:
-c
-      DO j=1,jusn
-        yusn(j+1)=ydata(j)
-      DO i=1,iusn
-        zusn(i+iext,j+1)=zdata(i,j)
-        xusn(i+iext)=xdata(i)
-      ENDDO
-      DO i=1,iext
-        zusn(i,j+1)=zdata(iusn-iext+i,j)
-        xusn(i)=xdata(iusn-iext+i)-2.*xpi
-        zusn(iusn+iext+i,j+1)=zdata(i,j)
-        xusn(iusn+iext+i)=xdata(i)+2.*xpi
-      ENDDO
-      ENDDO
-
-        yusn(1)=ydata(1)+(ydata(1)-ydata(2))
-        yusn(jusn+2)=ydata(jusn)+(ydata(jusn)-ydata(jusn-1))
-       DO i=1,iusn/2+iext
-        zusn(i,1)=zusn(i+iusn/2,2)
-        zusn(i+iusn/2+iext,1)=zusn(i,2)
-        zusn(i,jusn+2)=zusn(i+iusn/2,jusn+1)
-        zusn(i+iusn/2+iext,jusn+2)=zusn(i,jusn+1)
-       ENDDO
-c  
-c COMPUTE LIMITS OF MODEL GRIDPOINT AREA
-C     ( REGULAR GRID)
-c
-      a(1) = x(1) - (x(2)-x(1))/2.0
-      b(1) = (x(1)+x(2))/2.0
-      DO i = 2, imar
-         a(i) = b(i-1)
-         b(i) = (x(i)+x(i+1))/2.0
-      ENDDO
-      a(imar+1) = b(imar)
-      b(imar+1) = x(imar+1) + (x(imar+1)-x(imar))/2.0
-
-      c(1) = y(1) - (y(2)-y(1))/2.0
-      d(1) = (y(1)+y(2))/2.0
-      DO j = 2, jmar-1
-         c(j) = d(j-1)
-         d(j) = (y(j)+y(j+1))/2.0
-      ENDDO
-      c(jmar) = d(jmar-1)
-      d(jmar) = y(jmar) + (y(jmar)-y(jmar-1))/2.0
-c
-c  initialisations:
-c
-      DO i = 1, imar+1
-      DO j = 1, jmar
-         weight(i,j) = 0.0
-         zxtzx(i,j)  = 0.0
-         zytzy(i,j)  = 0.0
-         zxtzy(i,j)  = 0.0
-         ztz(i,j)    = 0.0
-         zmea(i,j)   = 0.0
-         zpic(i,j)  =-1.E+10
-         zval(i,j)  = 1.E+10
-      ENDDO
-      ENDDO
-c
-c  COMPUTE SLOPES CORRELATIONS ON USN GRID
-c
-         DO j = 1,jusn+2 
-         DO i = 1, iusn+2*iext
-            zytzyusn(i,j)=0.0
-            zxtzxusn(i,j)=0.0
-            zxtzyusn(i,j)=0.0
-         ENDDO
-         ENDDO
-
-
-         DO j = 2,jusn+1 
-            zdeltax=zdeltay*cos(yusn(j))
-         DO i = 2, iusn+2*iext-1
-            zytzyusn(i,j)=(zusn(i,j+1)-zusn(i,j-1))**2/zdeltay**2
-            zxtzxusn(i,j)=(zusn(i+1,j)-zusn(i-1,j))**2/zdeltax**2
-            zxtzyusn(i,j)=(zusn(i,j+1)-zusn(i,j-1))/zdeltay
-     *                   *(zusn(i+1,j)-zusn(i-1,j))/zdeltax
-         ENDDO
-         ENDDO
-c
-c  SUMMATION OVER GRIDPOINT AREA
-c 
-      zleny=xpi/REAL(jusn)*rad
-      xincr=xpi/2./REAL(jusn)
-       DO ii = 1, imar+1
-       DO jj = 1, jmar
-       num_tot(ii,jj)=0.
-       num_lan(ii,jj)=0.
-c        PRINT *,' iteration ii jj:',ii,jj
-         DO j = 2,jusn+1 
-c         DO j = 3,jusn 
-            zlenx=zleny*cos(yusn(j))
-            zdeltax=zdeltay*cos(yusn(j))
-            zbordnor=(c(jj)-yusn(j)+xincr)*rad
-            zbordsud=(yusn(j)-d(jj)+xincr)*rad
-            weighy=AMAX1(0.,
-     *             amin1(zbordnor,zbordsud,zleny))
-         IF(weighy.ne.0)THEN
-         DO i = 2, iusn+2*iext-1
-            zbordest=(xusn(i)-a(ii)+xincr)*rad*cos(yusn(j))
-            zbordoue=(b(ii)+xincr-xusn(i))*rad*cos(yusn(j))
-            weighx=AMAX1(0.,
-     *             amin1(zbordest,zbordoue,zlenx))
-            IF(weighx.ne.0)THEN
-            num_tot(ii,jj)=num_tot(ii,jj)+1.0
-            if(zusn(i,j).ge.1.)num_lan(ii,jj)=num_lan(ii,jj)+1.0
-            weight(ii,jj)=weight(ii,jj)+weighx*weighy
-            zxtzx(ii,jj)=zxtzx(ii,jj)+zxtzxusn(i,j)*weighx*weighy
-            zytzy(ii,jj)=zytzy(ii,jj)+zytzyusn(i,j)*weighx*weighy
-            zxtzy(ii,jj)=zxtzy(ii,jj)+zxtzyusn(i,j)*weighx*weighy
-            ztz(ii,jj)  =ztz(ii,jj)  +zusn(i,j)*zusn(i,j)*weighx*weighy
-c mean
-            zmea(ii,jj) =zmea(ii,jj)+zusn(i,j)*weighx*weighy
-c peacks
-            zpic(ii,jj)=amax1(zpic(ii,jj),zusn(i,j))
-c valleys
-            zval(ii,jj)=amin1(zval(ii,jj),zusn(i,j))
-            ENDIF
-         ENDDO
-         ENDIF
-         ENDDO
-       ENDDO
-       ENDDO
-c
-c  COMPUTE PARAMETERS NEEDED BY THE LOTT & MILLER (1997) AND
-C  LOTT (1999) SSO SCHEME.
-c
-      zllmmea=0.
-      zllmstd=0.
-      zllmsig=0.
-      zllmgam=0.
-      zllmpic=0.
-      zllmval=0.
-      zllmthe=0.
-      zminthe=0.
-c     print 100,' '
-c100  format(1X,A1,'II JJ',4X,'H',8X,'SD',8X,'SI',3X,'GA',3X,'TH') 
-       DO ii = 1, imar+1
-       DO jj = 1, jmar
-         IF (weight(ii,jj) .NE. 0.0) THEN
-c  Mask
-cXXX           if(num_lan(ii,jj)/num_tot(ii,jj).ge.0.5)then
-cXXX             mask(ii,jj)=1
-cXXX           else
-cXXX             mask(ii,jj)=0
-cXXX           ENDIF
-             if (.not. masque_lu) then
-               mask(ii,jj) = num_lan(ii,jj)/num_tot(ii,jj)
-             endif
-c  Mean Orography:
-           zmea (ii,jj)=zmea (ii,jj)/weight(ii,jj)
-           zxtzx(ii,jj)=zxtzx(ii,jj)/weight(ii,jj)
-           zytzy(ii,jj)=zytzy(ii,jj)/weight(ii,jj)
-           zxtzy(ii,jj)=zxtzy(ii,jj)/weight(ii,jj)
-           ztz(ii,jj)  =ztz(ii,jj)/weight(ii,jj)
-c  Standard deviation:
-           zstd(ii,jj)=sqrt(AMAX1(0.,ztz(ii,jj)-zmea(ii,jj)**2))
-         ELSE
-            PRINT*, 'probleme,ii,jj=', ii,jj
-         ENDIF
-       ENDDO
-       ENDDO
-
-C CORRECT VALUES OF HORIZONTAL SLOPE NEAR THE POLES:
-
-       DO ii = 1, imar+1
-         zxtzx(ii,1)=zxtzx(ii,2)
-         zxtzx(ii,jmar)=zxtzx(ii,jmar-1)
-         zxtzy(ii,1)=zxtzy(ii,2)
-         zxtzy(ii,jmar)=zxtzy(ii,jmar-1)
-         zytzy(ii,1)=zytzy(ii,2)
-         zytzy(ii,jmar)=zytzy(ii,jmar-1)
-       ENDDO
-
-C  FILTERS TO SMOOTH OUT FIELDS FOR INPUT INTO SSO SCHEME.
-
-C  FIRST FILTER, MOVING AVERAGE OVER 9 POINTS.
-
-       zmea0(:,:) = zmea(:,:) ! GK211005 (CG) on sauvegarde la topo non lissee
-       CALL MVA9(zmea,iim+1,jjm+1)
-       CALL MVA9(zstd,iim+1,jjm+1)
-       CALL MVA9(zpic,iim+1,jjm+1)
-       CALL MVA9(zval,iim+1,jjm+1)
-       CALL MVA9(zxtzx,iim+1,jjm+1)
-       CALL MVA9(zxtzy,iim+1,jjm+1) 
-       CALL MVA9(zytzy,iim+1,jjm+1)
-CXXX   Masque prenant en compte maximum de terre
-CXXX  On seuil a 10% de terre de terre car en dessous les parametres de surface n'on
-CXXX pas de sens (PB)
-       mask_tmp= 0.0
-       WHERE(mask .GE. 0.1) mask_tmp = 1.
-
-       DO ii = 1, imar
-       DO jj = 1, jmar
-         IF (weight(ii,jj) .NE. 0.0) THEN
-c  Coefficients K, L et M:
-           xk=(zxtzx(ii,jj)+zytzy(ii,jj))/2.
-           xl=(zxtzx(ii,jj)-zytzy(ii,jj))/2.
-           xm=zxtzy(ii,jj)
-           xp=xk-sqrt(xl**2+xm**2)
-           xq=xk+sqrt(xl**2+xm**2)
-           xw=1.e-8
-           if(xp.le.xw) xp=0.
-           if(xq.le.xw) xq=xw
-           if(abs(xm).le.xw) xm=xw*sign(1.,xm)
-c slope: 
-cXXX           zsig(ii,jj)=sqrt(xq)*mask(ii,jj)
-cXXXc isotropy:
-cXXX           zgam(ii,jj)=xp/xq*mask(ii,jj)
-cXXXc angle theta:
-cXXX           zthe(ii,jj)=57.29577951*atan2(xm,xl)/2.*mask(ii,jj)
-cXXX           zphi(ii,jj)=zmea(ii,jj)*mask(ii,jj)
-cXXX           zmea(ii,jj)=zmea(ii,jj)*mask(ii,jj)
-cXXX           zpic(ii,jj)=zpic(ii,jj)*mask(ii,jj)
-cXXX           zval(ii,jj)=zval(ii,jj)*mask(ii,jj)
-cXXX           zstd(ii,jj)=zstd(ii,jj)*mask(ii,jj)
-CXX* PB modif pour maque de terre fractionnaire
-c slope: 
-           zsig(ii,jj)=sqrt(xq)*mask_tmp(ii,jj)
-c isotropy:
-           zgam(ii,jj)=xp/xq*mask_tmp(ii,jj)
-c angle theta:
-           zthe(ii,jj)=57.29577951*atan2(xm,xl)/2.*mask_tmp(ii,jj)
-           ! GK211005 (CG) ne pas forcement lisser la topo
-           ! zphi(ii,jj)=zmea(ii,jj)*mask_tmp(ii,jj)
-           zphi(ii,jj)=zmea0(ii,jj)*mask_tmp(ii,jj)
-           !
-           zmea(ii,jj)=zmea(ii,jj)*mask_tmp(ii,jj)
-           zpic(ii,jj)=zpic(ii,jj)*mask_tmp(ii,jj)
-           zval(ii,jj)=zval(ii,jj)*mask_tmp(ii,jj)
-           zstd(ii,jj)=zstd(ii,jj)*mask_tmp(ii,jj)
-c          print 101,ii,jj,
-c    *           zmea(ii,jj),zstd(ii,jj),zsig(ii,jj),zgam(ii,jj),
-c    *           zthe(ii,jj)
-c101  format(1x,2(1x,i2),2(1x,f7.1),1x,f7.4,2x,f4.2,1x,f5.1)     
-         ELSE
-c           PRINT*, 'probleme,ii,jj=', ii,jj
-         ENDIF
-      zllmmea=AMAX1(zmea(ii,jj),zllmmea)
-      zllmstd=AMAX1(zstd(ii,jj),zllmstd)
-      zllmsig=AMAX1(zsig(ii,jj),zllmsig)
-      zllmgam=AMAX1(zgam(ii,jj),zllmgam)
-      zllmthe=AMAX1(zthe(ii,jj),zllmthe)
-      zminthe=amin1(zthe(ii,jj),zminthe)
-      zllmpic=AMAX1(zpic(ii,jj),zllmpic)
-      zllmval=AMAX1(zval(ii,jj),zllmval)
-       ENDDO
-       ENDDO
-      print *,'  MEAN ORO:',zllmmea
-      print *,'  ST. DEV.:',zllmstd
-      print *,'  PENTE:',zllmsig
-      print *,' ANISOTROP:',zllmgam
-      print *,'  ANGLE:',zminthe,zllmthe	
-      print *,'  pic:',zllmpic
-      print *,'  val:',zllmval
-      
-C
-c gamma and theta a 1. and 0. at poles
-c
-      DO jj=1,jmar
-      zmea(imar+1,jj)=zmea(1,jj)
-      zphi(imar+1,jj)=zphi(1,jj)
-      zpic(imar+1,jj)=zpic(1,jj)
-      zval(imar+1,jj)=zval(1,jj)
-      zstd(imar+1,jj)=zstd(1,jj)
-      zsig(imar+1,jj)=zsig(1,jj)
-      zgam(imar+1,jj)=zgam(1,jj)
-      zthe(imar+1,jj)=zthe(1,jj)
-      ENDDO
-
-
-      zmeanor=0.0
-      zmeasud=0.0
-      zstdnor=0.0
-      zstdsud=0.0
-      zsignor=0.0
-      zsigsud=0.0
-      zweinor=0.0
-      zweisud=0.0
-      zpicnor=0.0
-      zpicsud=0.0                                   
-      zvalnor=0.0
-      zvalsud=0.0 
-
-      DO ii=1,imar
-      zweinor=zweinor+              weight(ii,   1)
-      zweisud=zweisud+              weight(ii,jmar)
-      zmeanor=zmeanor+zmea(ii,   1)*weight(ii,   1)
-      zmeasud=zmeasud+zmea(ii,jmar)*weight(ii,jmar)
-      zstdnor=zstdnor+zstd(ii,   1)*weight(ii,   1)
-      zstdsud=zstdsud+zstd(ii,jmar)*weight(ii,jmar)
-      zsignor=zsignor+zsig(ii,   1)*weight(ii,   1)
-      zsigsud=zsigsud+zsig(ii,jmar)*weight(ii,jmar)
-      zpicnor=zpicnor+zpic(ii,   1)*weight(ii,   1)
-      zpicsud=zpicsud+zpic(ii,jmar)*weight(ii,jmar)
-      zvalnor=zvalnor+zval(ii,   1)*weight(ii,   1)
-      zvalsud=zvalsud+zval(ii,jmar)*weight(ii,jmar)
-      ENDDO
-
-      DO ii=1,imar+1
-      zmea(ii,   1)=zmeanor/zweinor
-      zmea(ii,jmar)=zmeasud/zweisud
-      zphi(ii,   1)=zmeanor/zweinor
-      zphi(ii,jmar)=zmeasud/zweisud
-      zpic(ii,   1)=zpicnor/zweinor
-      zpic(ii,jmar)=zpicsud/zweisud
-      zval(ii,   1)=zvalnor/zweinor
-      zval(ii,jmar)=zvalsud/zweisud
-      zstd(ii,   1)=zstdnor/zweinor
-      zstd(ii,jmar)=zstdsud/zweisud
-      zsig(ii,   1)=zsignor/zweinor
-      zsig(ii,jmar)=zsigsud/zweisud
-      zgam(ii,   1)=1.
-      zgam(ii,jmar)=1.
-      zthe(ii,   1)=0.
-      zthe(ii,jmar)=0.
-      ENDDO
-
-      RETURN
-      END
-
-      SUBROUTINE MVA9(X,IMAR,JMAR)
-      IMPLICIT NONE
-C MAKE A MOVING AVERAGE OVER 9 GRIDPOINTS OF THE X FIELDS
-      INTEGER IMAR,JMAR
-      REAL X(IMAR,JMAR),XF(IMAR,JMAR)
-      real WEIGHTpb(-1:1,-1:1)
-      INTEGER I,J,IS,JS
-      REAL SUM
-
-
-      SUM=0.
-      DO IS=-1,1
-        DO JS=-1,1
-          WEIGHTpb(IS,JS)=1./REAL((1+IS**2)*(1+JS**2))
-          SUM=SUM+WEIGHTpb(IS,JS)
-        ENDDO
-      ENDDO
-      
-c     WRITE(*,*) 'MVA9 ', IMAR, JMAR
-c     WRITE(*,*) 'MVA9 ', WEIGHTpb
-c     WRITE(*,*) 'MVA9 SUM ', SUM
-      DO IS=-1,1
-        DO JS=-1,1
-          WEIGHTpb(IS,JS)=WEIGHTpb(IS,JS)/SUM
-        ENDDO
-      ENDDO
-
-      DO J=2,JMAR-1
-        DO I=2,IMAR-1
-          XF(I,J)=0.
-          DO IS=-1,1
-            DO JS=-1,1
-              XF(I,J)=XF(I,J)+X(I+IS,J+JS)*WEIGHTpb(IS,JS)
-            ENDDO
-          ENDDO
-        ENDDO
-      ENDDO
-
-      DO J=2,JMAR-1
-        XF(1,J)=0.
-        IS=IMAR-1
-        DO JS=-1,1 
-          XF(1,J)=XF(1,J)+X(IS,J+JS)*WEIGHTpb(-1,JS)
-        ENDDO
-        DO IS=0,1 
-          DO JS=-1,1 
-            XF(1,J)=XF(1,J)+X(1+IS,J+JS)*WEIGHTpb(IS,JS)
-          ENDDO
-        ENDDO
-        XF(IMAR,J)=XF(1,J)
-      ENDDO
-
-      DO I=1,IMAR
-        XF(I,1)=XF(I,2)
-        XF(I,JMAR)=XF(I,JMAR-1)
-      ENDDO
-
-      DO I=1,IMAR
-        DO J=1,JMAR
-          X(I,J)=XF(I,J)
-        ENDDO
-      ENDDO
-
-      RETURN
-      END
-
-
-
Index: /LMDZ5/branches/testing/libf/dyn3d_common/infotrac.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/infotrac.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/infotrac.F90	(revision 2408)
@@ -59,5 +59,5 @@
 
   SUBROUTINE infotrac_init
-    USE control_mod
+    USE control_mod, ONLY: planet_type, config_inca
 #ifdef REPROBUS
     USE CHEM_REP, ONLY : Init_chem_rep_trac
@@ -196,11 +196,13 @@
           nqo=2
        ENDIF
-       IF (nqo /= 2 .OR. nqo /= 3 ) THEN
+       IF (nqo /= 2 .AND. nqo /= 3 ) THEN
           WRITE(lunout,*) trim(modname),': nqo=',nqo, ' is not allowded. Only 2 or 3 water phases allowed'
           CALL abort_gcm('infotrac_init','Bad number of water phases',1)
        END IF
        ! nbtr has been read from INCA by init_const_lmdz() in gcm.F 
+#ifdef INCA
+       CALL Init_chem_inca_trac(nbtr) 
+#endif       
        nqtrue=nbtr+nqo
-!!       nqtrue=nbtr+2
     END IF   ! type_trac
 !>jyg
@@ -274,15 +276,15 @@
              ! Y-a-t-il 1 ou 2 noms de traceurs? -> On regarde s'il y a un
              ! espace ou pas au milieu de la chaine.
-             continu=1
-             nouveau_traceurdef=0
+             continu=.true.
+             nouveau_traceurdef=.false.
              iiq=1
              do while (continu)
                 if (tchaine(iiq:iiq).eq.' ') then
-                  nouveau_traceurdef=1
-                  continu=0
+                  nouveau_traceurdef=.true.
+                  continu=.false.
                 else if (iiq.lt.LEN_TRIM(tchaine)) then
                   iiq=iiq+1
                 else
-                  continu=0      
+                  continu=.false.
                 endif
              enddo
@@ -384,10 +386,16 @@
 #endif
        tnom_0(1)='H2Ov'
+       tnom_transp(1) = 'air'
        tnom_0(2)='H2Ol'
-       IF (nqo == 3) tnom_0(3)='H2Oi'     !! jyg
+       tnom_transp(2) = 'air'
+       IF (nqo == 3) then 
+          tnom_0(3)='H2Oi'     !! jyg
+          tnom_transp(3) = 'air'
+       endif
 
 !jyg<
        DO iq = nqo+1, nqtrue
           tnom_0(iq)=solsym(iq-nqo)
+          tnom_transp(iq) = 'air'
        END DO
 !!       DO iq =3,nqtrue
@@ -672,12 +680,12 @@
 
     do iq=nqo+1,nqtot
-       write(lunout,*) 'infotrac 569: iq,tnom_0(iq)=',iq,tnom_0(iq)
+!       write(lunout,*) 'infotrac 569: iq,tnom_0(iq)=',iq,tnom_0(iq)
        do phase=1,nqo    
         do ixt= 1,niso_possibles   
          tnom_trac=trim(tnom_0(phase))//'_'
          tnom_trac=trim(tnom_trac)//trim(tnom_iso(ixt))
-         write(*,*) 'phase,ixt,tnom_trac=',phase,ixt,tnom_trac      
+!         write(*,*) 'phase,ixt,tnom_trac=',phase,ixt,tnom_trac      
          IF (tnom_0(iq) == tnom_trac) then
-          write(lunout,*) 'Ce traceur est un isotope'
+!          write(lunout,*) 'Ce traceur est un isotope'
           nb_iso(ixt,phase)=nb_iso(ixt,phase)+1   
           nb_isoind(phase)=nb_isoind(phase)+1   
@@ -686,12 +694,12 @@
           indnum_fn_num(ixt)=iso_indnum(iq)
           phase_num(iq)=phase
-          write(lunout,*) 'iso_num(iq)=',iso_num(iq)
-          write(lunout,*) 'iso_indnum(iq)=',iso_indnum(iq)
-          write(lunout,*) 'indnum_fn_num(ixt)=',indnum_fn_num(ixt)
-          write(lunout,*) 'phase_num(iq)=',phase_num(iq)
+!          write(lunout,*) 'iso_num(iq)=',iso_num(iq)
+!          write(lunout,*) 'iso_indnum(iq)=',iso_indnum(iq)
+!          write(lunout,*) 'indnum_fn_num(ixt)=',indnum_fn_num(ixt)
+!          write(lunout,*) 'phase_num(iq)=',phase_num(iq)
           goto 20
          else if (iqpere(iq).gt.0) then          
           if (tnom_0(iqpere(iq)) == tnom_trac) then
-           write(lunout,*) 'Ce traceur est le fils d''un isotope'
+!           write(lunout,*) 'Ce traceur est le fils d''un isotope'
            ! c'est un traceur d'isotope
            nb_traciso(ixt,phase)=nb_traciso(ixt,phase)+1
@@ -700,7 +708,7 @@
            zone_num(iq)=nb_traciso(ixt,phase)
            phase_num(iq)=phase
-           write(lunout,*) 'iso_num(iq)=',iso_num(iq)
-           write(lunout,*) 'phase_num(iq)=',phase_num(iq)
-           write(lunout,*) 'zone_num(iq)=',zone_num(iq)
+!           write(lunout,*) 'iso_num(iq)=',iso_num(iq)
+!           write(lunout,*) 'phase_num(iq)=',phase_num(iq)
+!           write(lunout,*) 'zone_num(iq)=',zone_num(iq)
            goto 20
           endif !if (tnom_0(iqpere(iq)) == trim(tnom_0(phase))//trim(tnom_iso(ixt))) then
@@ -711,9 +719,9 @@
       enddo !do iq=1,nqtot
 
-      write(lunout,*) 'iso_num=',iso_num
-      write(lunout,*) 'iso_indnum=',iso_indnum
-      write(lunout,*) 'zone_num=',zone_num  
-      write(lunout,*) 'phase_num=',phase_num
-      write(lunout,*) 'indnum_fn_num=',indnum_fn_num
+!      write(lunout,*) 'iso_num=',iso_num
+!      write(lunout,*) 'iso_indnum=',iso_indnum
+!      write(lunout,*) 'zone_num=',zone_num  
+!      write(lunout,*) 'phase_num=',phase_num
+!      write(lunout,*) 'indnum_fn_num=',indnum_fn_num
 
       do ixt= 1,niso_possibles  
@@ -724,5 +732,5 @@
           do phase=2,nqo
             if (nb_iso(ixt,phase).ne.nb_iso(ixt,1)) then
-              write(lunout,*) 'ixt,phase,nb_iso=',ixt,phase,nb_iso(ixt,phase)
+!              write(lunout,*) 'ixt,phase,nb_iso=',ixt,phase,nb_iso(ixt,phase)
               CALL abort_gcm('infotrac_init','Phases must have same number of isotopes',1)
             endif
@@ -763,6 +771,6 @@
     ! dimensions isotopique:
     ntraciso=niso*(ntraceurs_zone+1)
-    WRITE(lunout,*) 'niso=',niso
-    WRITE(lunout,*) 'ntraceurs_zone,ntraciso=',ntraceurs_zone,ntraciso    
+!    WRITE(lunout,*) 'niso=',niso
+!    WRITE(lunout,*) 'ntraceurs_zone,ntraciso=',ntraceurs_zone,ntraciso    
  
     ! flags isotopiques:
@@ -772,5 +780,5 @@
         ok_isotopes=.false.
     endif 
-    WRITE(lunout,*) 'ok_isotopes=',ok_isotopes
+!    WRITE(lunout,*) 'ok_isotopes=',ok_isotopes
  
     if (ok_isotopes) then
@@ -782,6 +790,6 @@
         alpha_ideal=(/1.0,1.01,1.006,1.003,1.0/)
     endif !if (ok_isotopes) then  
-    WRITE(lunout,*) 'ok_iso_verif=',ok_iso_verif
-    WRITE(lunout,*) 'ok_init_iso=',ok_init_iso
+!    WRITE(lunout,*) 'ok_iso_verif=',ok_iso_verif
+!    WRITE(lunout,*) 'ok_init_iso=',ok_init_iso
 
     if (ntraceurs_zone.gt.0) then
@@ -790,5 +798,5 @@
         ok_isotrac=.false.
     endif   
-    WRITE(lunout,*) 'ok_isotrac=',ok_isotrac
+!    WRITE(lunout,*) 'ok_isotrac=',ok_isotrac
 
     ! remplissage du tableau iqiso(ntraciso,phase)
@@ -801,5 +809,5 @@
         endif
     enddo
-    WRITE(lunout,*) 'iqiso=',iqiso
+!    WRITE(lunout,*) 'iqiso=',iqiso
 
     ! replissage du tableau index_trac(ntraceurs_zone,niso)
@@ -814,5 +822,5 @@
         index_trac(:,:)=0.0
     endif !if (ok_isotrac) then
-    write(lunout,*) 'index_trac=',index_trac    
+!    write(lunout,*) 'index_trac=',index_trac    
 
 ! Finalize :
Index: DZ5/branches/testing/libf/dyn3d_common/massbar.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/massbar.F	(revision 2407)
+++ 	(revision )
@@ -1,102 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE massbar(  masse, massebx, masseby )
-      IMPLICIT NONE
-c
-c **********************************************************************
-c
-c  Calcule les moyennes en x et  y de la masse d'air dans chaque maille.
-c **********************************************************************
-c    Auteurs : P. Le Van , Fr. Hourdin  .
-c   ..........
-c
-c  ..  masse                 est  un argum. d'entree  pour le s-pg ...
-c  ..  massebx,masseby      sont des argum. de sortie pour le s-pg ...
-c     
-c
-c     IMPLICIT NONE
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom.h"
-c
-      REAL    masse( ip1jmp1,llm ), massebx( ip1jmp1,llm )  ,
-     *      masseby(   ip1jm,llm )
-      INTEGER ij,l
-c
-c
-c   Methode pour calculer massebx et masseby .
-c   ----------------------------------------
-c
-c    A chaque point scalaire P (i,j) est affecte 4 coefficients d'aires
-c       alpha1(i,j)  calcule  au point ( i+1/4,j-1/4 )
-c       alpha2(i,j)  calcule  au point ( i+1/4,j+1/4 )
-c       alpha3(i,j)  calcule  au point ( i-1/4,j+1/4 )
-c       alpha4(i,j)  calcule  au point ( i-1/4,j-1/4 )
-c
-c    Avec  alpha1(i,j) = aire(i+1/4,j-1/4)/ aire(i,j)        
-c
-c    N.B .  Pour plus de details, voir s-pg  ...  iniconst ...
-c
-c
-c
-c   alpha4 .         . alpha1    . alpha4
-c    (i,j)             (i,j)       (i+1,j)
-c
-c             P .        U .          . P
-c           (i,j)       (i,j)         (i+1,j)
-c
-c   alpha3 .         . alpha2    .alpha3 
-c    (i,j)              (i,j)     (i+1,j)
-c
-c             V .        Z .          . V
-c           (i,j)
-c
-c   alpha4 .         . alpha1    .alpha4
-c   (i,j+1)            (i,j+1)   (i+1,j+1) 
-c
-c             P .        U .          . P
-c          (i,j+1)                    (i+1,j+1)
-c
-c
-c
-c                       On  a :
-c
-c    massebx(i,j) = masse(i  ,j) * ( alpha1(i  ,j) + alpha2(i,j))   +
-c                   masse(i+1,j) * ( alpha3(i+1,j) + alpha4(i+1,j) )
-c     localise  au point  ... U (i,j) ...
-c
-c    masseby(i,j) = masse(i,j  ) * ( alpha2(i,j  ) + alpha3(i,j  )  +
-c                   masse(i,j+1) * ( alpha1(i,j+1) + alpha4(i,j+1)  
-c     localise  au point  ... V (i,j) ...
-c
-c
-c=======================================================================
-
-      DO   100    l = 1 , llm
-c
-        DO  ij = 1, ip1jmp1 - 1
-         massebx(ij,l) =  masse( ij, l) * alpha1p2( ij  )     + 
-     *                   masse(ij+1, l) * alpha3p4(ij+1 )
-        ENDDO
-
-c    .... correction pour massebx( iip1,j) .....
-c    ...    massebx(iip1,j)= massebx(1,j) ...
-c
-CDIR$ IVDEP
-        DO  ij = iip1, ip1jmp1, iip1
-         massebx( ij,l ) = massebx( ij - iim,l )
-        ENDDO
-
-
-         DO  ij = 1,ip1jm
-         masseby( ij,l ) = masse(  ij   , l ) * alpha2p3(   ij    )  +
-     *                     masse(ij+iip1, l ) * alpha1p4( ij+iip1 )
-         ENDDO
-
-100   CONTINUE
-c
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d_common/massbar.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/massbar.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/massbar.F90	(revision 2408)
@@ -0,0 +1,66 @@
+SUBROUTINE massbar(masse,massebx,masseby)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute air mass mean along X and Y in each cell.
+! See iniconst for more details.
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: masse  (ip1jmp1,llm)
+  REAL, INTENT(OUT) :: massebx(ip1jmp1,llm)
+  REAL, INTENT(OUT) :: masseby(ip1jm  ,llm)
+!-------------------------------------------------------------------------------
+! Method used. Each scalar point is associated to 4 area coefficients:
+!    * alpha1(i,j) at point ( i+1/4,j-1/4 )
+!    * alpha2(i,j) at point ( i+1/4,j+1/4 )
+!    * alpha3(i,j) at point ( i-1/4,j+1/4 )
+!    * alpha4(i,j) at point ( i-1/4,j-1/4 )
+! where alpha1(i,j) = aire(i+1/4,j-1/4)/ aire(i,j)
+!
+!   alpha4 .         . alpha1    . alpha4
+!    (i,j)             (i,j)       (i+1,j)
+!
+!             P .        U .          . P
+!           (i,j)       (i,j)         (i+1,j)
+!
+!   alpha3 .         . alpha2    .alpha3 
+!    (i,j)              (i,j)     (i+1,j)
+!
+!             V .        Z .          . V
+!           (i,j)
+!
+!   alpha4 .         . alpha1    .alpha4
+!   (i,j+1)            (i,j+1)   (i+1,j+1) 
+!
+!             P .        U .          . P
+!          (i,j+1)                    (i+1,j+1)
+!
+!
+!    massebx(i,j) = masse(i  ,j) * ( alpha1(i  ,j) + alpha2(i,j))   +
+!                   masse(i+1,j) * ( alpha3(i+1,j) + alpha4(i+1,j) )
+!     localized at point  ... U (i,j) ...
+!
+!    masseby(i,j) = masse(i,j  ) * ( alpha2(i,j  ) + alpha3(i,j  )  +
+!                   masse(i,j+1) * ( alpha1(i,j+1) + alpha4(i,j+1)  
+!     localized at point  ... V (i,j) ...
+!===============================================================================
+! Local variables:
+  INTEGER :: ij, l
+!===============================================================================
+  DO l=1,llm
+    DO ij=1,ip1jmp1-1
+      massebx(ij,l)=masse(ij,l)*alpha1p2(ij)+masse(ij+1   ,l)*alpha3p4(ij+1)
+    END DO
+    DO ij=iip1,ip1jmp1,iip1; massebx(ij,l)=massebx(ij-iim,l); END DO
+    DO ij=1,ip1jm
+      masseby(ij,l)=masse(ij,l)*alpha2p3(ij)+masse(ij+iip1,l)*alpha1p4(ij+iip1)
+    END DO
+  END DO
+
+END SUBROUTINE massbar
+
Index: DZ5/branches/testing/libf/dyn3d_common/massbarxy.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/massbarxy.F	(revision 2407)
+++ 	(revision )
@@ -1,49 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE massbarxy(  masse, massebxy )
-      IMPLICIT NONE
-c
-c **********************************************************************
-c
-c  Calcule les moyennes en x et  y de la masse d'air dans chaque maille.
-c **********************************************************************
-c    Auteurs : P. Le Van , Fr. Hourdin  .
-c   ..........
-c
-c  ..  masse          est  un  argum. d'entree  pour le s-pg ...
-c  ..  massebxy       est  un  argum. de sortie pour le s-pg ...
-c     
-c
-c     IMPLICIT NONE
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom.h"
-c
-       REAL  masse( ip1jmp1,llm ), massebxy( ip1jm,llm )
-       INTEGER ij,l
-c
-
-      DO   100    l = 1 , llm
-c
-      DO 5 ij = 1, ip1jm - 1
-      massebxy( ij,l ) = masse(    ij  ,l ) * alpha2(   ij    )   +
-     +                   masse(   ij+1 ,l ) * alpha3(  ij+1   )   +
-     +                   masse( ij+iip1,l ) * alpha1( ij+iip1 )   +
-     +                   masse( ij+iip2,l ) * alpha4( ij+iip2 )
-   5  CONTINUE
-
-c    ....  correction pour     massebxy( iip1,j )  ........
-
-CDIR$ IVDEP
-
-      DO 7 ij = iip1, ip1jm, iip1
-      massebxy( ij,l ) = massebxy( ij - iim,l )
-   7  CONTINUE
-
-100   CONTINUE
-c
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d_common/massbarxy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/massbarxy.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/massbarxy.F90	(revision 2408)
@@ -0,0 +1,31 @@
+SUBROUTINE massbarxy(masse,massebxy)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute air mass mean along X and Y in each cell.
+! See iniconst for more details.
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comconst.h"
+  include "comgeom.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: masse   (ip1jmp1,llm)
+  REAL, INTENT(OUT) :: massebxy(ip1jm  ,llm)
+!===============================================================================
+! Local variables:
+  INTEGER :: ij, l
+!===============================================================================
+  DO l=1,llm
+    DO ij=1,ip1jm-1
+      massebxy(ij,l)=masse(ij     ,l)*alpha2(ij     ) + &
+     +               masse(ij+1   ,l)*alpha3(ij+1   ) + &
+     +               masse(ij+iip1,l)*alpha1(ij+iip1) + &
+     +               masse(ij+iip2,l)*alpha4(ij+iip2)
+    END DO
+    DO ij=iip1,ip1jm,iip1; massebxy(ij,l)=massebxy(ij-iim,l); END DO
+  END DO
+
+END SUBROUTINE massbarxy
Index: /LMDZ5/branches/testing/libf/dyn3d_common/misc_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/misc_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/misc_mod.F90	(revision 2408)
@@ -0,0 +1,6 @@
+module misc_mod
+  integer,save :: itaumax
+  logical,save :: adjust
+  integer,save :: ItCount
+  logical,save :: debug
+end module misc_mod 
Index: DZ5/branches/testing/libf/dyn3d_common/pression.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/pression.F	(revision 2407)
+++ 	(revision )
@@ -1,32 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE pression( ngrid, ap, bp, ps, p )
-c
-
-c      Auteurs : P. Le Van , Fr.Hourdin  .
-
-c  ************************************************************************
-c     Calcule la pression p(l) aux differents niveaux l = 1 ( niveau du
-c     sol) a l = llm +1 ,ces niveaux correspondant aux interfaces des (llm) 
-c     couches , avec  p(ij,llm +1) = 0.  et p(ij,1) = ps(ij)  .      
-c  ************************************************************************
-c
-      IMPLICIT NONE
-c
-#include "dimensions.h"
-#include "paramet.h"
-c
-      INTEGER ngrid
-      INTEGER l,ij
- 
-      REAL ap( llmp1 ), bp( llmp1 ), ps( ngrid ), p( ngrid,llmp1 ) 
-      
-      DO    l    = 1, llmp1
-        DO  ij   = 1, ngrid
-         p(ij,l) = ap(l) + bp(l) * ps(ij)
-        ENDDO
-      ENDDO
-   
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d_common/pression.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/pression.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/pression.F90	(revision 2408)
@@ -0,0 +1,27 @@
+SUBROUTINE pression( ngrid, ap, bp, ps, p )
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr.Hourdin 
+!-------------------------------------------------------------------------------
+! Purpose: Compute pressure p(l) at different levels from l = 1 (ground level)
+!          to l = llm +1. Those levels correspond to the llm layers interfaces,
+!          with p(ij,llm+1) = 0. and  p(ij,1) = ps(ij)  .   
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+!===============================================================================
+! Arguments:
+  INTEGER, INTENT(IN)  :: ngrid                 !--- NUMBER OF GRID POINTS
+  REAL,    INTENT(IN)  :: ap(llmp1), bp(llmp1)  !--- HYBRID COEFFICIENTS
+  REAL,    INTENT(IN)  :: ps(ngrid)             !--- SURFACE PRESSURE
+  REAL,    INTENT(OUT) :: p(ngrid,llmp1)        !--- 3D PRESSURE FIELD 
+!===============================================================================
+! Local variables:
+  INTEGER :: l
+!===============================================================================
+  DO l=1,llmp1;  p(:,l) = ap(l) + bp(l) * ps(:);  END DO
+
+END SUBROUTINE pression
+
+
Index: DZ5/branches/testing/libf/dyn3d_common/q_sat.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/q_sat.F	(revision 2407)
+++ 	(revision )
@@ -1,72 +1,0 @@
-!
-! $Header$
-!
-!
-!
-
-      subroutine q_sat(np,temp,pres,qsat)
-!
-      IMPLICIT none
-!======================================================================
-! Autheur(s): Z.X. Li (LMD/CNRS)
-!  reecriture vectorisee par F. Hourdin.
-! Objet: calculer la vapeur d'eau saturante (formule Centre Euro.)
-!======================================================================
-! Arguments:
-! kelvin---input-R: temperature en Kelvin
-! millibar--input-R: pression en mb
-!
-! q_sat----output-R: vapeur d'eau saturante en kg/kg
-!======================================================================
-!
-      integer np
-      REAL temp(np),pres(np),qsat(np)
-!
-      REAL r2es
-      PARAMETER (r2es=611.14 *18.0153/28.9644)
-!
-      REAL r3les, r3ies, r3es
-      PARAMETER (R3LES=17.269)
-      PARAMETER (R3IES=21.875)
-!
-      REAL r4les, r4ies, r4es
-      PARAMETER (R4LES=35.86)
-      PARAMETER (R4IES=7.66)
-!
-      REAL rtt
-      PARAMETER (rtt=273.16)
-!
-      REAL retv
-      PARAMETER (retv=28.9644/18.0153 - 1.0)
-
-      real zqsat
-      integer ip
-!
-!     ------------------------------------------------------------------
-!
-!
-
-      do ip=1,np
-
-!      write(*,*)'kelvin,millibar=',kelvin,millibar
-!       write(*,*)'temp,pres=',temp(ip),pres(ip)
-!
-         IF (temp(ip) .LE. rtt) THEN
-            r3es = r3ies
-            r4es = r4ies
-         ELSE
-            r3es = r3les
-            r4es = r4les
-         ENDIF
-!
-         zqsat=r2es/pres(ip)*EXP(r3es*(temp(ip)-rtt)/(temp(ip)-r4es))
-         zqsat=MIN(0.5,ZQSAT)
-         zqsat=zqsat/(1.-retv *zqsat)
-!
-         qsat(ip)= zqsat
-!      write(*,*)'qsat=',qsat(ip)
-
-      enddo
-!
-      RETURN
-      END
Index: DZ5/branches/testing/libf/dyn3d_common/startvar.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/startvar.F90	(revision 2407)
+++ 	(revision )
@@ -1,783 +1,0 @@
-!
-! $Id$
-!
-!*******************************************************************************
-!
-MODULE startvar
-!
-!*******************************************************************************
-!
-!-------------------------------------------------------------------------------
-! Purpose: Access data from the database of atmospheric to initialize the model.
-!-------------------------------------------------------------------------------
-! Comments:
-!
-!    *  This module is designed to work for Earth (and with ioipsl)
-!
-!    *  There are three ways to acces data, depending on the type of field
-!  which needs to be extracted. In any case the call should come after a restget
-!  and should be of the type :                     CALL startget(...)
-!
-!  - A 1D variable on the physical grid :
-!    CALL startget_phys1d((varname, iml, jml,  lon_in,  lat_in,  nbindex,              &
-!           champ, val_exp,      jml2, lon_in2, lat_in2, ibar )
-!
-!  - A 2D variable on the dynamical grid :
-!    CALL startget_phys2d(varname, iml, jml,  lon_in,  lat_in,                        &
-!           champ, val_exp,      jml2, lon_in2, lat_in2, ibar )             
-!
-!  - A 3D variable on the dynamical grid :
-!    CALL startget_dyn((varname, iml, jml,  lon_in,  lat_in,  lml, pls, workvar,    &
-!           champ, val_exp,      jml2, lon_in2, lat_in2, ibar )
-!
-!    *  Data needs to be in NetCDF format
-!
-!    *  Variables should have the following names in the files:
-!            'RELIEF' : High resolution orography 
-!            'ST'     : Surface temperature
-!            'CDSW'   : Soil moisture
-!            'Z'      : Surface geopotential
-!            'SP'     : Surface pressure
-!            'U'      : East ward wind
-!            'V'      : Northward wind
-!            'TEMP'   : Temperature
-!            'R'      : Relative humidity
-!
-!   *   There is a big mess with the longitude size. Should it be iml or iml+1 ?
-!  I have chosen to use the iml+1 as an argument to this routine and we declare
-!  internaly smaller fields when needed. This needs to be cleared once and for
-!  all in LMDZ. A convention is required.
-!-------------------------------------------------------------------------------
-#ifdef CPP_EARTH
-  USE ioipsl
-  IMPLICIT NONE
-
-  PRIVATE
-  PUBLIC startget_phys2d, startget_phys1d, startget_dyn
-!  INTERFACE startget
-!    MODULE PROCEDURE startget_phys1d, startget_phys2d, startget_dyn
-!  END INTERFACE
-
-  REAL,    SAVE :: deg2rad,  pi
-  INTEGER, SAVE ::           iml_rel,  jml_rel
-  INTEGER, SAVE :: fid_phys, iml_phys, jml_phys
-  INTEGER, SAVE :: fid_dyn,  iml_dyn,  jml_dyn,  llm_dyn,  ttm_dyn
-  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lon_phys, lon_dyn
-  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lat_phys, lat_dyn
-  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lon_rug, lon_alb, lon_rel
-  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lat_rug, lat_alb, lat_rel
-  REAL, DIMENSION(:),     ALLOCATABLE, TARGET, SAVE :: levdyn_ini
-  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: relief, zstd, zsig, zgam
-  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: masque, zthe, zpic, zval
-  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: rugo, phis, tsol, qsol
-  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: psol_dyn
-  REAL, DIMENSION(:,:,:), ALLOCATABLE, TARGET, SAVE :: var_ana3d
-
-   CONTAINS
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE startget_phys1d(varname, iml, jml, lon_in, lat_in, nbindex, champ,  &
-                           val_exp ,jml2, lon_in2, lat_in2, ibar)
-!
-!-------------------------------------------------------------------------------
-! Comment:
-!   This routine only works if the variable does not exist or is constant.
-!-------------------------------------------------------------------------------
-! Arguments:
-  CHARACTER(LEN=*),         INTENT(IN)    :: varname
-  INTEGER,                  INTENT(IN)    :: iml, jml
-  REAL, DIMENSION(iml),     INTENT(IN)    :: lon_in
-  REAL, DIMENSION(jml),     INTENT(IN)    :: lat_in
-  INTEGER,                  INTENT(IN)    :: nbindex
-  REAL, DIMENSION(nbindex), INTENT(INOUT) :: champ
-  REAL,                     INTENT(IN)    :: val_exp
-  INTEGER,                  INTENT(IN)    :: jml2
-  REAL, DIMENSION(iml),     INTENT(IN)    :: lon_in2
-  REAL, DIMENSION(jml2),    INTENT(IN)    :: lat_in2
-  LOGICAL,                  INTENT(IN)    :: ibar
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "iniprint.h"
-  REAL, DIMENSION(:,:), POINTER :: v2d
-!-------------------------------------------------------------------------------
-  v2d=>NULL()
-  IF(MINVAL(champ)==MAXVAL(champ).AND.MINVAL(champ)==val_exp) THEN
-
-!--- CHECKING IF THE FIELD IS KNOWN ; READING UNALLOCATED FILES
-    SELECT CASE(varname)
-      CASE('tsol')
-        IF(.NOT.ALLOCATED(tsol))                                               &
-         CALL start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
-      CASE('qsol')
-        IF(.NOT.ALLOCATED(qsol))                                               &
-         CALL start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
-      CASE('psol')
-        IF(.NOT.ALLOCATED(psol_dyn))                                           &
-         CALL start_init_dyn (iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
-      CASE('zmea','zstd','zsig','zgam','zthe','zpic','zval')
-        IF(.NOT.ALLOCATED(relief))                                             &
-         CALL start_init_orog(iml,jml,lon_in,lat_in)
-      CASE('rads','snow','tslab','seaice','rugmer','agsno')
-      CASE DEFAULT
-        WRITE(lunout,*)'startget_phys1d'
-        WRITE(lunout,*)'No rule is present to extract variable '//TRIM(varname)&
-                     //' from any data set'; STOP
-    END SELECT
-
-!--- SELECTING v2d FOR WANTED VARIABLE AND CHEKING ITS SIZE
-    SELECT CASE(varname)
-      CASE('rads','snow','tslab','seaice');  champ=0.0
-      CASE('rugmer');                        champ(:)=0.001
-      CASE('agsno');                         champ(:)=50.0
-      CASE DEFAULT
-        SELECT CASE(varname)
-          CASE('tsol'); v2d=>tsol
-          CASE('qsol'); v2d=>qsol
-          CASE('psol'); v2d=>psol_dyn
-          CASE('zmea'); v2d=>relief
-          CASE('zstd'); v2d=>zstd
-          CASE('zsig'); v2d=>zsig
-          CASE('zgam'); v2d=>zgam
-          CASE('zthe'); v2d=>zthe
-          CASE('zpic'); v2d=>zpic
-          CASE('zval'); v2d=>zval
-        END SELECT
-        IF(SIZE(v2d)/=SIZE(lon_in)*SIZE(lat_in)) THEN
-         WRITE(lunout,*)'STARTVAR module has been initialized to the wrong size'
-         STOP
-        END IF
-        CALL gr_dyn_fi(1,iml,jml,nbindex,v2d,champ)
-    END SELECT
-
-  ELSE
-
-!--- SOME FIELDS ARE CAUGHT: MAY BE NEEDED FOR A 3D INTEPROLATION
-    SELECT CASE(varname)
-      CASE('tsol')
-        IF(.NOT.ALLOCATED(tsol)) ALLOCATE(tsol(iml,jml))
-        CALL gr_fi_dyn(1,iml,jml,nbindex,champ,tsol)
-    END SELECT
-
-  END IF
-
-END SUBROUTINE  startget_phys1d
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE startget_phys2d(varname, iml, jml, lon_in, lat_in, champ, val_exp,  &
-                           jml2, lon_in2, lat_in2 , ibar, msk)
-!
-!-------------------------------------------------------------------------------
-! Comment:
-!   This routine only works if the variable does not exist or is constant.
-!-------------------------------------------------------------------------------
-! Arguments:
-  CHARACTER(LEN=*),         INTENT(IN)           :: varname
-  INTEGER,                  INTENT(IN)           :: iml, jml
-  REAL, DIMENSION(iml),     INTENT(IN)           :: lon_in
-  REAL, DIMENSION(jml),     INTENT(IN)           :: lat_in
-  REAL, DIMENSION(iml,jml), INTENT(INOUT)        :: champ
-  REAL,                     INTENT(IN)           :: val_exp
-  INTEGER,                  INTENT(IN)           :: jml2
-  REAL, DIMENSION(iml),     INTENT(IN)           :: lon_in2
-  REAL, DIMENSION(jml2),    INTENT(IN)           :: lat_in2
-  LOGICAL,                  INTENT(IN)           :: ibar
-  REAL, DIMENSION(iml,jml), INTENT(IN), OPTIONAL :: msk
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "iniprint.h"
-  REAL, DIMENSION(:,:), POINTER :: v2d=>NULL()
-  LOGICAL                       :: lrelief1, lrelief2
-!-------------------------------------------------------------------------------
-  v2d=>NULL()
-  lrelief1=(.NOT.ALLOCATED(relief).AND.     PRESENT(msk))
-  lrelief2=(.NOT.ALLOCATED(relief).AND..NOT.PRESENT(msk))
-  IF(MINVAL(champ)==MAXVAL(champ).AND.MINVAL(champ)==val_exp) THEN
-
-!--- CHECKING IF THE FIELD IS KNOWN ; READING UNALLOCATED FILES
-    SELECT CASE(varname)
-      CASE('psol')
-        IF(.NOT.ALLOCATED(psol_dyn))                                           &
-          CALL start_init_dyn (iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
-      CASE('relief')
-        IF(lrelief1)             CALL start_init_orog(iml,jml,lon_in,lat_in,msk)
-        IF(lrelief2)             CALL start_init_orog(iml,jml,lon_in,lat_in)
-      CASE('surfgeo')
-        IF(.NOT.ALLOCATED(phis)) CALL start_init_orog(iml,jml,lon_in,lat_in)
-      CASE('rugosite','masque')
-        IF(.NOT.ALLOCATED(rugo)) CALL start_init_orog(iml,jml,lon_in,lat_in)
-      CASE DEFAULT
-        WRITE(lunout,*)'startget_phys2d'
-        WRITE(lunout,*)'No rule is present to extract variable '//TRIM(varname)&
-                     //' from any data set'; STOP
-    END SELECT
-
-!--- SELECTING v2d FOR WANTED VARIABLE AND CHEKING ITS SIZE
-    SELECT CASE(varname)
-      CASE('psol');     v2d=>psol_dyn
-      CASE('relief');   v2d=>relief
-      CASE('rugosite'); v2d=>rugo
-      CASE('masque');   v2d=>masque
-      CASE('surfgeo');  v2d=>phis
-    END SELECT
-    IF(SIZE(champ)/=SIZE(v2d)) THEN
-      WRITE(lunout,*) 'STARTVAR module has been initialized to the wrong size'
-      STOP
-    END IF
-
-    champ(:,:)=v2d(:,:)
-
-  ELSE
-
-!--- SOME FIELDS ARE CAUGHT: MAY BE NEEDED FOR A 3D INTEPROLATION
-    SELECT CASE(varname)
-      CASE ('surfgeo')
-        IF(.NOT.ALLOCATED(phis)) ALLOCATE(phis(iml,jml))
-        IF(SIZE(phis)/=SIZE(champ)) THEN
-         WRITE(lunout,*)'STARTVAR module has been initialized to the wrong size'
-         STOP
-        END IF
-        phis(:,:)=champ(:,:)
-    END SELECT
-
-  END IF
-
-END SUBROUTINE startget_phys2d
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE startget_dyn(varname,  lon_in,  lat_in, pls,workvar,&
-                     champ, val_exp, lon_in2, lat_in2, ibar)
-
-      use assert_eq_m, only: assert_eq
-
-
-!-------------------------------------------------------------------------------
-! Comment:
-!   This routine only works if the variable does not exist or is constant.
-!-------------------------------------------------------------------------------
-! Arguments:
-  CHARACTER(LEN=*), INTENT(IN)    :: varname
-  REAL, INTENT(IN)    :: lon_in(:) ! dim(iml)
-  REAL, INTENT(IN)    :: lat_in(:) ! dim(jml)
-  REAL, INTENT(IN)    :: pls(:, :, :) ! dim(iml, jml, lml)
-  REAL, INTENT(IN)    :: workvar(:, :, :) ! dim(iml, jml, lml)
-  REAL, INTENT(INOUT) :: champ(:, :, :) ! dim(iml, jml, lml)
-  REAL, INTENT(IN)    :: val_exp
-  REAL, INTENT(IN)    :: lon_in2(:) ! dim(iml)
-  REAL, INTENT(IN)    :: lat_in2(:) ! dim(jml2)
-  LOGICAL,                      INTENT(IN)    :: ibar
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "iniprint.h"
-#include "dimensions.h"
-#include "comconst.h"
-#include "paramet.h"
-#include "comgeom2.h"
-  INTEGER    :: iml, jml
-  INTEGER    :: lml
-  INTEGER    :: jml2
-  REAL, DIMENSION(:,:,:), POINTER :: v3d=>NULL()
-  CHARACTER(LEN=10) :: vname
-  INTEGER :: il
-  REAL    :: xppn, xpps
-!-------------------------------------------------------------------------------
-  NULLIFY(v3d)
-  IF(MINVAL(champ)==MAXVAL(champ).AND.MINVAL(champ)==val_exp) THEN
-
-      iml = assert_eq((/size(lon_in), size(pls, 1), size(workvar, 1), &
-     &     size(champ, 1), size(lon_in2)/), "startget_dyn iml")
-      jml = assert_eq(size(lat_in), size(pls, 2), size(workvar, 2),   &
-     &     size(champ, 2), "startget_dyn jml")
-      lml = assert_eq(size(pls, 3), size(workvar, 3), size(champ, 3), &
-     &     "startget_dyn lml")
-      jml2 = size(lat_in2)
-
-!--- READING UNALLOCATED FILES
-    IF(.NOT.ALLOCATED(psol_dyn))                                               &
-      CALL start_init_dyn(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
-
-!--- CHECKING IF THE FIELD IS KNOWN AND INTERPOLATING 3D FIELDS
-    SELECT CASE(varname)
-      CASE('u');        vname='U'
-      CASE('v');        vname='V'
-      CASE('t','tpot'); vname='TEMP'
-      CASE('q');        vname='R'
-      CASE DEFAULT
-        WRITE(lunout,*)'startget_dyn'
-        WRITE(lunout,*)'No rule is present to extract variable '//TRIM(varname)&
-                //' from any data set'; STOP
-    END SELECT
-    CALL start_inter_3d(TRIM(vname), iml, jml, lml, lon_in, lat_in, jml2,      &
-                        lon_in2, lat_in2,  pls, champ,ibar )
-
-!--- COMPUTING THE REQUIRED FILED
-    SELECT CASE(varname)
-      CASE('u')                                            !--- Eastward wind
-        DO il=1,lml; champ(:,:,il)=champ(:,:,il)*cu(:,1:jml); END DO
-        champ(iml,:,:)=champ(1,:,:)
-
-      CASE('v')                                            !--- Northward wind
-        DO il=1,lml; champ(:,:,il)=champ(:,:,il)*cv(:,1:jml); END DO
-        champ(iml,:,:)=champ(1,:,:)
-
-      CASE('tpot')                                         !--- Temperature
-        IF(MINVAL(workvar)/=MAXVAL(workvar)) THEN
-          champ=champ*cpp/workvar
-          DO il=1,lml
-            xppn = SUM(aire(:,1  )*champ(:,1  ,il))/apoln
-            xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
-            champ(:,1  ,il) = xppn
-            champ(:,jml,il) = xpps
-          END DO
-        ELSE
-          WRITE(lunout,*)'Could not compute potential temperature as the'
-          WRITE(lunout,*)'Exner function is missing or constant.'; STOP
-        END IF
-
-      CASE('q')                                            !--- Relat. humidity
-        IF(MINVAL(workvar)/=MAXVAL(workvar)) THEN
-          champ=0.01*champ*workvar
-          WHERE(champ<0.) champ=1.0E-10
-          DO il=1,lml
-            xppn = SUM(aire(:,1  )*champ(:,1  ,il))/apoln
-            xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
-            champ(:,1  ,il) = xppn
-            champ(:,jml,il) = xpps
-          END DO
-        ELSE
-          WRITE(lunout,*)'Could not compute specific humidity as the'
-          WRITE(lunout,*)'saturated humidity is missing or constant.'; STOP
-        END IF
-
-    END SELECT
-
-  END IF
-
-END SUBROUTINE startget_dyn
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE start_init_orog(iml,jml,lon_in,lat_in,masque_lu)
-!
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER,                  INTENT(IN)           :: iml, jml
-  REAL, DIMENSION(iml),     INTENT(IN)           :: lon_in
-  REAL, DIMENSION(jml),     INTENT(IN)           :: lat_in
-  REAL, DIMENSION(iml,jml), INTENT(IN), OPTIONAL :: masque_lu
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "iniprint.h"
-  CHARACTER(LEN=25)     :: title
-  CHARACTER(LEN=120)    :: orofname
-  LOGICAL               :: check=.TRUE.
-  REAL,    DIMENSION(1) :: lev
-  REAL                  :: date, dt
-  INTEGER, DIMENSION(1) :: itau
-  INTEGER               :: fid, llm_tmp, ttm_tmp
-  REAL,    DIMENSION(:,:), ALLOCATABLE :: relief_hi, tmp_var
-  REAL,    DIMENSION(:),   ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
-!-------------------------------------------------------------------------------
-  pi=2.0*ASIN(1.0); deg2rad=pi/180.0
-
-  orofname = 'Relief.nc'; title='RELIEF'
-  IF(check) WRITE(lunout,*)'Reading the high resolution orography'
-  CALL flininfo(orofname, iml_rel, jml_rel, llm_tmp, ttm_tmp, fid)
-
-  ALLOCATE(lat_rel(iml_rel,jml_rel),lon_rel(iml_rel,jml_rel))
-  CALL flinopen(orofname, .FALSE., iml_rel, jml_rel, llm_tmp, lon_rel, lat_rel,&
-                lev, ttm_tmp, itau, date, dt, fid)
-  ALLOCATE(relief_hi(iml_rel,jml_rel))
-  CALL flinget(fid, title, iml_rel, jml_rel, llm_tmp, ttm_tmp, 1, 1, relief_hi)
-  CALL flinclo(fid)
-
-!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
-  ALLOCATE(lon_ini(iml_rel),lat_ini(jml_rel))
-  lon_ini(:)=lon_rel(:,1); IF(MAXVAL(lon_rel)>pi) lon_ini=lon_ini*deg2rad
-  lat_ini(:)=lat_rel(1,:); IF(MAXVAL(lat_rel)>pi) lat_ini=lat_ini*deg2rad
-
-!--- FIELDS ARE PROCESSED TO BE ON STANDARD ANGULAR DOMAINS
-  ALLOCATE(lon_rad(iml_rel),lat_rad(jml_rel))
-  CALL conf_dat2d(title, iml_rel, jml_rel, lon_ini, lat_ini, lon_rad, lat_rad, &
-                  relief_hi, .FALSE.)
-  DEALLOCATE(lon_ini,lat_ini)
-
-!--- COMPUTING THE REQUIRED FIELDS USING ROUTINE grid_noro
-  IF(check) WRITE(lunout,*)'Computes all parameters needed for gravity wave dra&
-     &g code'
-
-  ALLOCATE(phis(iml,jml))      ! Geopotentiel au sol
-  ALLOCATE(zstd(iml,jml))      ! Deviation standard de l'orographie sous-maille
-  ALLOCATE(zsig(iml,jml))      ! Pente de l'orographie sous-maille 
-  ALLOCATE(zgam(iml,jml))      ! Anisotropie de l'orographie sous maille
-  ALLOCATE(zthe(iml,jml))      ! Orientation axe +grande pente d'oro sous maille
-  ALLOCATE(zpic(iml,jml))      ! Hauteur pics de la SSO
-  ALLOCATE(zval(iml,jml))      ! Hauteur vallees de la SSO
-  ALLOCATE(relief(iml,jml))    ! Orographie moyenne
-  ALLOCATE(masque(iml,jml))    ! Masque terre ocean
-  masque = -99999.
-  IF(PRESENT(masque_lu)) masque=masque_lu
-
-  CALL grid_noro(iml_rel, jml_rel, lon_rad, lat_rad, relief_hi, iml-1, jml,    &
-       lon_in, lat_in, phis, relief, zstd, zsig, zgam, zthe, zpic, zval, masque)
-  phis = phis * 9.81
-
-!--- SURFACE ROUGHNESS COMPUTATION (UNUSED FOR THE MOMENT !!! )
-  IF(check) WRITE(lunout,*)'Compute surface roughness induced by the orography'
-  ALLOCATE(rugo   (iml  ,jml))
-  ALLOCATE(tmp_var(iml-1,jml))
-  CALL rugsoro(iml_rel, jml_rel, lon_rad, lat_rad, relief_hi, iml-1, jml,      &
-       lon_in, lat_in, tmp_var)
-  rugo(1:iml-1,:)=tmp_var; rugo(iml,:)=tmp_var(1,:)
-  DEALLOCATE(relief_hi,tmp_var,lon_rad,lat_rad)
-  RETURN
-
-END SUBROUTINE start_init_orog
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
-!
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER,               INTENT(IN) :: iml, jml
-  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in
-  REAL, DIMENSION(jml),  INTENT(IN) :: lat_in
-  INTEGER,               INTENT(IN) :: jml2
-  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in2
-  REAL, DIMENSION(jml2), INTENT(IN) :: lat_in2
-  LOGICAL,               INTENT(IN) :: ibar
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "iniprint.h"
-  CHARACTER(LEN=25)     :: title
-  CHARACTER(LEN=120)    :: physfname
-  LOGICAL               :: check=.TRUE.
-  REAL                  :: date, dt
-  INTEGER, DIMENSION(1) :: itau
-  INTEGER               :: llm_tmp, ttm_tmp
-  REAL,    DIMENSION(:,:), ALLOCATABLE :: var_ana
-  REAL,    DIMENSION(:),   ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
-  REAL,    DIMENSION(:),   ALLOCATABLE :: levphys_ini
-!-------------------------------------------------------------------------------
-  physfname = 'ECPHY.nc'; pi=2.0*ASIN(1.0); deg2rad=pi/180.0
-  IF(check) WRITE(lunout,*)'Opening the surface analysis'
-  CALL flininfo(physfname, iml_phys, jml_phys, llm_tmp, ttm_tmp, fid_phys)
-
-  ALLOCATE(lat_phys(iml_phys,jml_phys))
-  ALLOCATE(lon_phys(iml_phys,jml_phys))
-  ALLOCATE(levphys_ini(llm_tmp))
-  CALL flinopen(physfname, .FALSE., iml_phys, jml_phys, llm_tmp, lon_phys,     &
-                lat_phys, levphys_ini, ttm_tmp, itau, date, dt, fid_phys)
-  DEALLOCATE(levphys_ini)
-
-!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
-  ALLOCATE(lon_ini(iml_phys),lat_ini(jml_phys))
-  lon_ini(:)=lon_phys(:,1); IF(MAXVAL(lon_phys)>pi) lon_ini=lon_ini*deg2rad
-  lat_ini(:)=lat_phys(1,:); IF(MAXVAL(lat_phys)>pi) lat_ini=lat_ini*deg2rad
-
-  ALLOCATE(var_ana(iml_phys,jml_phys),lon_rad(iml_phys),lat_rad(jml_phys))
-
-!--- SURFACE TEMPERATURE
-  title='ST'
-  ALLOCATE(tsol(iml,jml))
-  CALL flinget(fid_phys,title,iml_phys,jml_phys,llm_tmp,ttm_tmp,1,1,var_ana)
-  CALL conf_dat2d(title,iml_phys, jml_phys, lon_ini, lat_ini, lon_rad, lat_rad,&
-                  var_ana , ibar  )
-  CALL interp_startvar(title, ibar, .TRUE.,                                    &
-      iml_phys, jml_phys, lon_rad, lat_rad, var_ana, iml, jml, jml-1,          &
-      lon_in,   lat_in,   lon_in2, lat_in2, tsol)
-
-!--- SOIL MOISTURE
-  title='CDSW'
-  ALLOCATE(qsol(iml,jml))
-  CALL flinget(fid_phys,title,iml_phys,jml_phys,llm_tmp,ttm_tmp,1,1,var_ana)
-  CALL conf_dat2d(title,iml_phys, jml_phys, lon_ini, lat_ini, lon_rad, lat_rad,&
-                  var_ana, ibar  )
-  CALL interp_startvar(title, ibar, .TRUE.,                                    &
-      iml_phys, jml_phys, lon_rad, lat_rad, var_ana, iml, jml, jml-1,          &
-      lon_in,   lat_in,   lon_in2, lat_in2, qsol)
-
-  CALL flinclo(fid_phys)
-
-  DEALLOCATE(var_ana,lon_rad,lat_rad,lon_ini,lat_ini)
-
-END SUBROUTINE start_init_phys
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE start_init_dyn(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
-!
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER,               INTENT(IN) :: iml, jml
-  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in
-  REAL, DIMENSION(jml),  INTENT(IN) :: lat_in
-  INTEGER,               INTENT(IN) :: jml2
-  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in2
-  REAL, DIMENSION(jml2), INTENT(IN) :: lat_in2
-  LOGICAL,               INTENT(IN) :: ibar
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "iniprint.h"
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom2.h"
-  CHARACTER(LEN=25)     :: title
-  CHARACTER(LEN=120)    :: physfname
-  LOGICAL               :: check=.TRUE.
-  REAL                  :: date, dt
-  INTEGER, DIMENSION(1) :: itau
-  INTEGER               :: i, j
-  REAL,    DIMENSION(:,:), ALLOCATABLE :: var_ana, z
-  REAL,    DIMENSION(:),   ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
-  REAL,    DIMENSION(:),   ALLOCATABLE :: xppn, xpps
-!-------------------------------------------------------------------------------
-
-!--- KINETIC ENERGY
-  physfname = 'ECDYN.nc'; pi=2.0*ASIN(1.0); deg2rad=pi/180.0
-  IF(check) WRITE(lunout,*) 'Opening the surface analysis'
-  CALL flininfo(physfname, iml_dyn, jml_dyn, llm_dyn, ttm_dyn, fid_dyn)
-  IF(check) WRITE(lunout,*) 'Values read: ', iml_dyn, jml_dyn, llm_dyn, ttm_dyn
-
-  ALLOCATE(lat_dyn(iml_dyn,jml_dyn))
-  ALLOCATE(lon_dyn(iml_dyn,jml_dyn))
-  ALLOCATE(levdyn_ini(llm_dyn))
-  CALL flinopen(physfname, .FALSE., iml_dyn, jml_dyn, llm_dyn, lon_dyn,lat_dyn,&
-                levdyn_ini, ttm_dyn, itau, date, dt, fid_dyn)
-
-!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
-  ALLOCATE(lon_ini(iml_dyn),lat_ini(jml_dyn))
-  lon_ini(:)=lon_dyn(:,1); IF(MAXVAL(lon_dyn)>pi) lon_ini=lon_ini*deg2rad
-  lat_ini(:)=lat_dyn(1,:); IF(MAXVAL(lat_dyn)>pi) lat_ini=lat_ini*deg2rad
-
-  ALLOCATE(var_ana(iml_dyn,jml_dyn),lon_rad(iml_dyn),lat_rad(jml_dyn))
-
-!--- SURFACE GEOPOTENTIAL
-  title='Z'
-  ALLOCATE(z(iml,jml))
-  CALL flinget(fid_dyn, title, iml_dyn, jml_dyn, 0, ttm_dyn, 1, 1, var_ana)
-  CALL conf_dat2d(title, iml_dyn, jml_dyn, lon_ini, lat_ini, lon_rad, lat_rad, &
-                  var_ana, ibar)
-  CALL interp_startvar(title, ibar, .TRUE.,                                    &
-      iml_dyn, jml_dyn, lon_rad, lat_rad, var_ana, iml, jml, jml-1,            &
-      lon_in,  lat_in,  lon_in2, lat_in2, z)
-
-!--- SURFACE PRESSURE
-  title='SP'
-  ALLOCATE(psol_dyn(iml,jml))
-  CALL flinget(fid_dyn, title, iml_dyn, jml_dyn, 0, ttm_dyn, 1, 1, var_ana)
-  CALL conf_dat2d(title, iml_dyn, jml_dyn, lon_ini, lat_ini, lon_rad, lat_rad, &
-                  var_ana, ibar)
-  CALL interp_startvar(title, ibar, .TRUE.,                                    &
-      iml_dyn, jml_dyn, lon_rad, lat_rad, var_ana, iml, jml, jml-1,            &
-      lon_in,  lat_in,  lon_in2, lat_in2, psol_dyn)
-
-  DEALLOCATE(var_ana,lon_rad,lat_rad,lon_ini,lat_ini)
-
-!--- ALLOCATION OF VARIABLES CREATED IN OR COMING FROM RESTART FILE
-  IF(.NOT.ALLOCATED(tsol)) THEN
-    CALL start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
-  ELSE
-    IF(SIZE(tsol)/=SIZE(psol_dyn)) THEN
-      WRITE(lunout,*)'start_init_dyn :'
-      WRITE(lunout,*)'The temperature field we have does not have the right size'
-      STOP
-    END IF
-  END IF
-
-  IF(.NOT.ALLOCATED(phis)) THEN
-    CALL start_init_orog(iml,jml,lon_in,lat_in)
-  ELSE
-    IF(SIZE(phis)/=SIZE(psol_dyn)) THEN
-      WRITE(lunout,*)'start_init_dyn :'
-      WRITE(lunout,*)'The orography field we have does not have the right size'
-      STOP
-    END IF
-  END IF
-
-!--- PSOL IS COMPUTED IN PASCALS
-  DO j = 1, jml
-    DO i = 1, iml-1
-      psol_dyn(i,j) = psol_dyn(i,j)*(1.0+(z(i,j)-phis(i,j))/287.0/tsol(i,j))
-    END DO
-    psol_dyn(iml,j) = psol_dyn(1,j)
-  END DO
-  DEALLOCATE(z)
-
-  ALLOCATE(xppn(iml-1),xpps(iml-1)) 
-  DO i = 1, iml-1
-    xppn(i) = aire( i,1) * psol_dyn( i,1)
-    xpps(i) = aire( i,jml) * psol_dyn( i,jml)
-  END DO
-  DO i = 1, iml
-    psol_dyn(i,1  ) = SUM(xppn)/apoln
-    psol_dyn(i,jml) = SUM(xpps)/apols
-  END DO
-  DEALLOCATE(xppn,xpps) 
-
-  RETURN
-
-END SUBROUTINE start_init_dyn
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE start_inter_3d(varname, iml, jml, lml, lon_in, lat_in, jml2, &
-     lon_in2, lat_in2, pls_in, var3d, ibar)
-
-  use pchsp_95_m, only: pchsp_95
-  use pchfe_95_m, only: pchfe_95
-
-! Arguments:
-  CHARACTER(LEN=*),             INTENT(IN)    :: varname
-  INTEGER,                      INTENT(IN)    :: iml, jml, lml
-  REAL, DIMENSION(iml),         INTENT(IN)    :: lon_in
-  REAL, DIMENSION(jml),         INTENT(IN)    :: lat_in
-  INTEGER,                      INTENT(IN)    :: jml2
-  REAL, DIMENSION(iml),         INTENT(IN)    :: lon_in2
-  REAL, DIMENSION(jml2),        INTENT(IN)    :: lat_in2
-  REAL, DIMENSION(iml, jml, lml), INTENT(IN)    :: pls_in
-  REAL, DIMENSION(iml, jml, lml), INTENT(OUT)   :: var3d
-  LOGICAL,                      INTENT(IN)    :: ibar
-!----------------------------------------------------------------------------
-! Local variables:
-#include "iniprint.h"
-  LOGICAL:: check=.TRUE., skip
-  REAL                  chmin, chmax
-  INTEGER ii, ij, il, ierr
-  integer n_extrap ! number of extrapolated points
-  REAL, DIMENSION(iml, jml, llm_dyn):: var_tmp3d
-  REAL,    DIMENSION(:),     ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
-  REAL, DIMENSION(llm_dyn):: lev_dyn, ax, ay, yder
-
-!---------------------------------------------------------------------------
-  IF(check) WRITE(lunout, *)'Going into flinget to extract the 3D  field.'
-  IF(check) WRITE(lunout, *) fid_dyn, varname, iml_dyn, jml_dyn, llm_dyn, &
-       ttm_dyn
-  IF(check) WRITE(lunout, *) 'Allocating space for interpolation', iml, jml, &
-       llm_dyn
-
-  IF(.NOT.ALLOCATED(var_ana3d)) ALLOCATE(var_ana3d(iml_dyn, jml_dyn, llm_dyn))
-  CALL flinget(fid_dyn, varname, iml_dyn, jml_dyn, llm_dyn, ttm_dyn, 1, 1, &
-       var_ana3d)
-
-!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
-  ALLOCATE(lon_ini(iml_dyn), lat_ini(jml_dyn))
-  lon_ini(:)=lon_dyn(:, 1); IF(MAXVAL(lon_dyn)>pi) lon_ini=lon_ini*deg2rad
-  lat_ini(:)=lat_dyn(1, :); IF(MAXVAL(lat_dyn)>pi) lat_ini=lat_ini*deg2rad
-
-!--- FIELDS ARE PROCESSED TO BE ON STANDARD ANGULAR DOMAINS
-  ALLOCATE(lon_rad(iml_dyn), lat_rad(jml_dyn))
-  CALL conf_dat3d (varname, iml_dyn, jml_dyn, llm_dyn, lon_ini, lat_ini,      &
-                   levdyn_ini, lon_rad, lat_rad, lev_dyn, var_ana3d, ibar)
-  DEALLOCATE(lon_ini, lat_ini)
-
-!--- COMPUTING THE REQUIRED FIELDS USING ROUTINE grid_noro
-  DO il=1, llm_dyn
-    CALL interp_startvar(varname, ibar, il==1, iml_dyn, jml_dyn, lon_rad, &
-         lat_rad, var_ana3d(:, :, il), iml, jml, jml2, lon_in, lat_in, &
-         lon_in2, lat_in2, var_tmp3d(:, :, il))
-  END DO
-  DEALLOCATE(lon_rad, lat_rad)
-
-!--- VERTICAL INTERPOLATION IS PERFORMED FROM TOP OF ATMOSPHERE TO GROUND
-  ax = lev_dyn(llm_dyn:1:-1) 
-  skip = .false.
-  n_extrap = 0
-  DO ij=1, jml
-    DO ii=1, iml-1
-      ay = var_tmp3d(ii, ij, llm_dyn:1:-1)
-      yder = pchsp_95(ax, ay, ibeg=2, iend=2, vc_beg=0., vc_end=0.)
-      CALL pchfe_95(ax, ay, yder, skip, pls_in(ii, ij, lml:1:-1), &
-           var3d(ii, ij, lml:1:-1), ierr)
-      if (ierr < 0) stop 1
-      n_extrap = n_extrap + ierr
-    END DO
-  END DO
-  if (n_extrap /= 0) then
-     print *, "start_inter_3d pchfe_95: n_extrap = ", n_extrap
-  end if
-  var3d(iml, :, :) = var3d(1, :, :) 
-
-  DO il=1, lml
-    CALL minmax(iml*jml, var3d(1, 1, il), chmin, chmax)
-    WRITE(lunout, *)' '//TRIM(varname)//'  min max l ', il, chmin, chmax
-  END DO
-
-END SUBROUTINE start_inter_3d
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE interp_startvar(vname, ibar, ibeg, ii, jj,    lon,  lat,  vari,     &
-                                 i1, j1, j2, lon1, lat1, lon2, lat2, varo)
-!
-!-------------------------------------------------------------------------------
-
-  USE inter_barxy_m, only: inter_barxy
-
-! Arguments:
-  CHARACTER(LEN=*),       INTENT(IN)  :: vname
-  LOGICAL,                INTENT(IN)  :: ibar, ibeg
-  INTEGER,                INTENT(IN)  :: ii, jj
-  REAL, DIMENSION(ii),    INTENT(IN)  :: lon
-  REAL, DIMENSION(jj),    INTENT(IN)  :: lat
-  REAL, DIMENSION(ii,jj), INTENT(IN)  :: vari
-  INTEGER,                INTENT(IN)  :: i1, j1, j2
-  REAL, DIMENSION(i1),    INTENT(IN)  :: lon1
-  REAL, DIMENSION(j1),    INTENT(IN)  :: lat1
-  REAL, DIMENSION(i1),    INTENT(IN)  :: lon2
-  REAL, DIMENSION(j2),    INTENT(IN)  :: lat2
-  REAL, DIMENSION(i1,j1), INTENT(OUT) :: varo
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "iniprint.h"
-  REAL, DIMENSION(i1-1,j1) :: vtmp
-!-------------------------------------------------------------------------------
-  IF(ibar) THEN
-    IF(ibeg) THEN
-      WRITE(lunout,*)                                                          &
-               '---------------------------------------------------------------'
-      WRITE(lunout,*)                                                          &
- '$$$ Utilisation de l interpolation barycentrique  pour  '//TRIM(vname)//' $$$'
-      WRITE(lunout,*)                                                          &
-               '---------------------------------------------------------------'
-    END IF
-    CALL inter_barxy(lon, lat(:jj-1), vari, lon2(:i1-1), lat2(:j2), vtmp)
-  ELSE
-    CALL grille_m   (ii, jj,   lon, lat, vari, i1-1, j1, lon1, lat1,     vtmp)
-  END IF
-  CALL gr_int_dyn(vtmp, varo, i1-1, j1)
-
-END SUBROUTINE interp_startvar
-!
-!-------------------------------------------------------------------------------
-
-#endif
-! of #ifdef CPP_EARTH
-
-END MODULE startvar
-!
-!*******************************************************************************
Index: DZ5/branches/testing/libf/dyn3d_common/tourpot.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/tourpot.F	(revision 2407)
+++ 	(revision )
@@ -1,81 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE tourpot ( vcov, ucov, massebxy, vorpot )
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteur:  P. Le Van
-c   -------
-c
-c   Objet:
-c   ------
-c
-c    *******************************************************************
-c    .........      calcul du tourbillon potentiel             .........
-c    *******************************************************************
-c
-c     vcov,ucov,fext et pbarxyfl sont des argum. d'entree pour le s-pg .
-c             vorpot            est  un argum.de sortie pour le s-pg .
-c
-c=======================================================================
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom.h"
-#include "logic.h"
-
-      REAL  rot( ip1jm,llm )
-      REAL vcov( ip1jm,llm ),ucov( ip1jmp1,llm )
-      REAL massebxy( ip1jm,llm ),vorpot( ip1jm,llm )
-
-      INTEGER l, ij
-
-
-
-
-c  ... vorpot = ( Filtre( d(vcov)/dx - d(ucov)/dy ) + fext ) /psbarxy ..
-
-
-
-c    ........  Calcul du rotationnel du vent V  puis filtrage  ........
-
-      DO 5 l = 1,llm
-
-      DO 2 ij = 1, ip1jm - 1
-      rot( ij,l ) = vcov(ij+1,l)-vcov(ij,l)+ucov(ij+iip1,l)-ucov(ij,l)
-   2  CONTINUE
-
-c    ....  correction pour  rot( iip1,j,l )  .....
-c    ....     rot(iip1,j,l) = rot(1,j,l)    .....
-
-CDIR$ IVDEP
-
-      DO 3 ij = iip1, ip1jm, iip1
-      rot( ij,l ) = rot( ij -iim, l )
-   3  CONTINUE
-
-   5  CONTINUE
-
-
-      CALL  filtreg( rot, jjm, llm, 2, 1, .FALSE., 1 )
-
-
-      DO 10 l = 1, llm
-
-      DO 6 ij = 1, ip1jm - 1
-      vorpot( ij,l ) = ( rot(ij,l) + fext(ij) ) / massebxy(ij,l)
-   6  CONTINUE
-
-c    ..... correction pour  vorpot( iip1,j,l)  .....
-c    ....   vorpot(iip1,j,l)= vorpot(1,j,l) ....
-CDIR$ IVDEP
-      DO 8 ij = iip1, ip1jm, iip1
-      vorpot( ij,l ) = vorpot( ij -iim,l )
-   8  CONTINUE
-
-  10  CONTINUE
-
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d_common/tourpot.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/tourpot.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/tourpot.F90	(revision 2408)
@@ -0,0 +1,46 @@
+SUBROUTINE tourpot ( vcov, ucov, massebxy, vorpot )
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van.
+!-------------------------------------------------------------------------------
+! Purpose: Compute potential vorticity.
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+  include "logic.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: vcov    (ip1jm,  llm)
+  REAL, INTENT(IN)  :: ucov    (ip1jmp1,llm)
+  REAL, INTENT(IN)  :: massebxy(ip1jm,  llm)
+  REAL, INTENT(OUT) :: vorpot  (ip1jm,  llm)
+!===============================================================================
+! Method used:
+!   vorpot = ( Filtre( d(vcov)/dx - d(ucov)/dy ) + fext ) /psbarxy
+!===============================================================================
+! Local variables:
+  INTEGER :: l, ij
+  REAL    :: rot(ip1jm,llm)
+!===============================================================================
+
+!--- Wind vorticity ; correction: rot(iip1,j,l) = rot(1,j,l)
+  DO l=1,llm
+    DO ij=1,ip1jm-1
+      rot(ij,l)=vcov(ij+1,l)-vcov(ij,l)+ucov(ij+iip1,l)-ucov(ij,l)
+    END DO
+    DO ij=iip1,ip1jm,iip1; rot(ij,l)=rot(ij-iim,l); END DO
+  END DO
+
+!--- Filter
+  CALL  filtreg(rot,jjm,llm,2,1,.FALSE.,1)
+
+!--- Potential vorticity ; correction: rot(iip1,j,l) = rot(1,j,l)
+  DO l=1,llm
+    DO ij=1,ip1jm-1
+      vorpot(ij,l)=(rot(ij,l)+fext(ij))/massebxy(ij,l)
+    END DO
+    DO ij=iip1,ip1jm,iip1; vorpot(ij,l)=vorpot(ij-iim,l); END DO
+  END DO
+
+END SUBROUTINE tourpot
Index: DZ5/branches/testing/libf/dyn3d_common/vitvert.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/vitvert.F	(revision 2407)
+++ 	(revision )
@@ -1,52 +1,0 @@
-!
-! $Header$
-!
-      SUBROUTINE vitvert ( convm , w )
-c
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteurs:  P. Le Van , F. Hourdin .
-c   -------
-c
-c   Objet:
-c   ------
-c
-c    *******************************************************************
-c  .... calcul de la vitesse verticale aux niveaux sigma  ....
-c    *******************************************************************
-c     convm   est un argument  d'entree pour le s-pg  ......
-c       w     est un argument de sortie pour le s-pg  ......
-c
-c    la vitesse verticale est orientee de  haut en bas .
-c    au sol, au niveau sigma(1),   w(i,j,1) = 0.
-c    au sommet, au niveau sigma(llm+1) , la vit.verticale est aussi
-c    egale a 0. et n'est pas stockee dans le tableau w  .
-c
-c
-c=======================================================================
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
-
-      REAL w(ip1jmp1,llm),convm(ip1jmp1,llm)
-      INTEGER   l, ij
-
-
-
-      DO 2  l = 1,llmm1
-
-      DO 1 ij = 1,ip1jmp1
-      w( ij, l+1 ) = convm( ij, l+1 ) - bp(l+1) * convm( ij, 1 )
-   1  CONTINUE
-
-   2  CONTINUE
-
-      DO 5 ij  = 1,ip1jmp1
-      w(ij,1)  = 0.
-5     CONTINUE
-
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3d_common/vitvert.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/vitvert.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3d_common/vitvert.F90	(revision 2408)
@@ -0,0 +1,27 @@
+SUBROUTINE vitvert (convm, w)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute vertical speed at sigma levels.
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comvert.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: convm(ip1jmp1,llm)
+  REAL, INTENT(OUT) :: w    (ip1jmp1,llm)
+!===============================================================================
+! Notes: Vertical speed is oriented from bottom to top.
+!   * At ground - level sigma(1):     w(i,j,1) = 0.
+!   * At top    - level sigma(llm+1): w(i,j,l) = 0. (not stored in w)
+!===============================================================================
+! Local variables:
+  INTEGER :: l
+!===============================================================================
+  DO l=1,llmm1; w(:,l+1)=convm(:,l+1)-bp(l+1)*convm(:,1); END DO
+  w(:,1)=0.
+
+END SUBROUTINE vitvert
+
Index: DZ5/branches/testing/libf/dyn3d_common/write_field.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d_common/write_field.F90	(revision 2407)
+++ 	(revision )
@@ -1,326 +1,0 @@
-!
-! $Id$
-!
-module write_field
-implicit none
-
-  integer, parameter :: MaxWriteField = 100
-  integer, dimension(MaxWriteField),save :: FieldId
-  integer, dimension(MaxWriteField),save :: FieldVarId
-  integer, dimension(MaxWriteField),save :: FieldIndex
-  character(len=255), dimension(MaxWriteField) ::  FieldName 
-   
-  integer,save :: NbField = 0
-  
-  interface WriteField
-    module procedure WriteField3d,WriteField2d,WriteField1d
-  end interface WriteField
-  contains
-  
-    function GetFieldIndex(name)
-    implicit none
-      integer          :: GetFieldindex
-      character(len=*) :: name
-    
-      character(len=255) :: TrueName
-      integer            :: i
-       
-      
-      TrueName=TRIM(ADJUSTL(name))
-    
-      GetFieldIndex=-1
-      do i=1,NbField
-        if (TrueName==FieldName(i)) then
-          GetFieldIndex=i
-          exit
-        endif
-      enddo
-    end function GetFieldIndex
- 
-    subroutine WriteField3d(name,Field)
-    implicit none
-      character(len=*) :: name
-      real, dimension(:,:,:) :: Field 
-      integer, dimension(3) :: Dim
-      
-      Dim=shape(Field)
-      call WriteField_gen(name,Field,Dim(1),Dim(2),Dim(3))  
-  
-    end subroutine WriteField3d
-    
-    subroutine WriteField2d(name,Field)
-    implicit none
-      character(len=*) :: name
-      real, dimension(:,:) :: Field 
-      integer, dimension(2) :: Dim
-      
-      Dim=shape(Field)
-      call WriteField_gen(name,Field,Dim(1),Dim(2),1)  
-  
-    end subroutine WriteField2d
-    
-    subroutine WriteField1d(name,Field)
-    implicit none
-      character(len=*) :: name
-      real, dimension(:) :: Field 
-      integer, dimension(1) :: Dim
-      
-      Dim=shape(Field)
-      call WriteField_gen(name,Field,Dim(1),1,1)  
-  
-    end subroutine WriteField1d
-        
-    subroutine WriteField_gen(name,Field,dimx,dimy,dimz)
-    implicit none
-    include 'netcdf.inc'
-      character(len=*) :: name
-      integer :: dimx,dimy,dimz
-      real,dimension(dimx,dimy,dimz) :: Field
-      integer,dimension(dimx*dimy*dimz) :: ndex
-      integer :: status
-      integer :: index
-      integer :: start(4)
-      integer :: count(4)
-      
-           
-      Index=GetFieldIndex(name)
-      if (Index==-1) then
-        call CreateNewField(name,dimx,dimy,dimz)
-	Index=GetFieldIndex(name)
-      else
-        FieldIndex(Index)=FieldIndex(Index)+1.
-      endif
-      
-      start(1)=1
-      start(2)=1
-      start(3)=1
-      start(4)=FieldIndex(Index)
-
-      count(1)=dimx
-      count(2)=dimy
-      count(3)=dimz
-      count(4)=1
-
-      status = NF_PUT_VARA_DOUBLE(FieldId(Index),FieldVarId(Index),start,count,Field)
-      status = NF_SYNC(FieldId(Index))
-      
-    end subroutine WriteField_gen
-       
-    subroutine CreateNewField(name,dimx,dimy,dimz)
-    implicit none
-    include 'netcdf.inc'  
-      character(len=*) :: name
-      integer :: dimx,dimy,dimz
-      integer :: TabDim(4)
-      integer :: status
-      
-      
-      NbField=NbField+1
-      FieldName(NbField)=TRIM(ADJUSTL(name))
-      FieldIndex(NbField)=1
-      
-      
-      status = NF_CREATE(TRIM(ADJUSTL(name))//'.nc', NF_CLOBBER, FieldId(NbField))
-      status = NF_DEF_DIM(FieldId(NbField),'X',dimx,TabDim(1))
-      status = NF_DEF_DIM(FieldId(NbField),'Y',dimy,TabDim(2))
-      status = NF_DEF_DIM(FieldId(NbField),'Z',dimz,TabDim(3))
-      status = NF_DEF_DIM(FieldId(NbField),'iter',NF_UNLIMITED,TabDim(4))
-      status = NF_DEF_VAR(FieldId(NbField),FieldName(NbField),NF_DOUBLE,4,TabDim,FieldVarId(NbField))
-      status = NF_ENDDEF(FieldId(NbField))
-
-    end subroutine CreateNewField
-    
-    
-    
-  subroutine write_field1D(name,Field)
-    implicit none
-  
-    integer, parameter :: MaxDim=1
-    character(len=*)   :: name
-    real, dimension(:) :: Field
-    real, dimension(:),allocatable :: New_Field
-    character(len=20) :: str
-    integer, dimension(MaxDim) :: Dim
-    integer :: i,nb
-    integer, parameter :: id=10
-    integer, parameter :: NbCol=4
-    integer :: ColumnSize 
-    integer :: pos
-    character(len=255) :: form
-    character(len=255) :: MaxLen
-    
-    
-    open(unit=id,file=name//'.field',form='formatted',status='replace')
-    write (id,'("----- Field '//name//'",//)')
-    Dim=shape(Field)
-    MaxLen=int2str(len(trim(int2str(Dim(1)))))
-    ColumnSize=20+6+3+len(trim(int2str(Dim(1))))
-    Nb=0
-    Pos=2
-    do i=1,Dim(1)
-      nb=nb+1
-      
-      if (MOD(nb,NbCol)==0) then
-        form='(t'//trim(int2str(pos))// ',i'//trim(MaxLen) //'," ---> ",g22.16,/)'
-        Pos=2
-      else
-        form='(t'//trim(int2str(pos))// ',i'//trim(MaxLen) //'," ---> ",g22.16," | ",)'
-        Pos=Pos+ColumnSize
-      endif
-      write (id,form,advance='no') i,Field(i)
-    enddo
-     
-    close(id)
-
-  end subroutine write_field1D
-
-  subroutine write_field2D(name,Field)
-    implicit none
-  
-    integer, parameter :: MaxDim=2
-    character(len=*)   :: name
-    real, dimension(:,:) :: Field
-    real, dimension(:,:),allocatable :: New_Field
-    character(len=20) :: str
-    integer, dimension(MaxDim) :: Dim
-    integer :: i,j,nb
-    integer, parameter :: id=10
-    integer, parameter :: NbCol=4
-    integer :: ColumnSize 
-    integer :: pos,offset
-    character(len=255) :: form
-    character(len=255) :: spacing
-    
-    open(unit=id,file=name//'.field',form='formatted',status='replace')
-    write (id,'("----- Field '//name//'",//)')
-    
-    Dim=shape(Field)
-    offset=len(trim(int2str(Dim(1))))+len(trim(int2str(Dim(2))))+3
-    ColumnSize=20+6+3+offset
-
-    spacing='(t2,"'//repeat('-',ColumnSize*NbCol)//'")'
-    
-    do i=1,Dim(2)
-      nb=0
-      Pos=2
-      do j=1,Dim(1)
-        nb=nb+1
-      
-        if (MOD(nb,NbCol)==0) then
-          form='(t'//trim(int2str(pos))//            &
-               ',"('//trim(int2str(j))//','          &
-                    //trim(int2str(i))//')",t'       & 
-                    //trim(int2str(pos+offset))     &    
-                    //'," ---> ",g22.16,/)'
-          Pos=2
-        else
-          form='(t'//trim(int2str(pos))//            &
-               ',"('//trim(int2str(j))//','          &
-                    //trim(int2str(i))//')",t'       & 
-                    //trim(int2str(pos+offset))     &    
-                    //'," ---> ",g22.16," | ")'
-          Pos=Pos+ColumnSize
-        endif
-        write (id,form,advance='no') Field(j,i)
-      enddo
-      if (MOD(nb,NbCol)==0) then
-        write (id,spacing)
-      else
-        write (id,'("")')
-        write (id,spacing)
-      endif
-    enddo
-     
-  end subroutine write_field2D
-  
-  subroutine write_field3D(name,Field)
-    implicit none
-  
-    integer, parameter :: MaxDim=3
-    character(len=*)   :: name
-    real, dimension(:,:,:) :: Field
-    real, dimension(:,:,:),allocatable :: New_Field
-    integer, dimension(MaxDim) :: Dim
-    integer :: i,j,k,nb
-    integer, parameter :: id=10
-    integer, parameter :: NbCol=4
-    integer :: ColumnSize 
-    integer :: pos,offset
-    character(len=255) :: form
-    character(len=255) :: spacing
-
-    open(unit=id,file=name//'.field',form='formatted',status='replace')
-    write (id,'("----- Field '//name//'"//)')
-    
-    Dim=shape(Field)
-    offset=len(trim(int2str(Dim(1))))+len(trim(int2str(Dim(2))))+len(trim(int2str(Dim(3))))+4
-    ColumnSize=22+6+3+offset
-
-!    open(unit=id,file=name,form=formatted
-   
-    spacing='(t2,"'//repeat('-',ColumnSize*NbCol)//'")'
-    
-    do i=1,Dim(3)
-    
-      do j=1,Dim(2)
-        nb=0
-        Pos=2
-        
-        do k=1,Dim(1)
-        nb=nb+1
-      
-          if (MOD(nb,NbCol)==0) then
-            form='(t'//trim(int2str(pos))//            &
-                 ',"('//trim(int2str(k))//','          &
-                      //trim(int2str(j))//','          &
-                      //trim(int2str(i))//')",t'       & 
-                      //trim(int2str(pos+offset))      &    
-                      //'," ---> ",g22.16,/)'
-           Pos=2
-          else
-            form='(t'//trim(int2str(pos))//            &
-                 ',"('//trim(int2str(k))//','          &
-                      //trim(int2str(j))//','          &
-                      //trim(int2str(i))//')",t'       & 
-                      //trim(int2str(pos+offset))      &    
-                      //'," ---> ",g22.16," | ")'
-! dépent de l'implémention, sur compaq, c'est necessaire
-!            Pos=Pos+ColumnSize
-          endif
-          write (id,form,advance='no') Field(k,j,i)
-        enddo
-        if (MOD(nb,NbCol)==0) then
-          write (id,spacing)
-        else
-          write (id,'("")')
-          write (id,spacing)
-        endif
-      enddo
-      write (id,spacing)
-    enddo
-    
-    close(id)
-  
-  end subroutine write_field3D  
-  
-  function int2str(int)
-    implicit none
-    integer, parameter :: MaxLen=10
-    integer,intent(in) :: int
-    character(len=MaxLen) :: int2str
-    logical :: flag
-    integer :: i
-    flag=.true.
-    
-    i=int
-    
-    int2str=''
-    do while (flag)
-      int2str=CHAR(MOD(i,10)+48)//int2str
-      i=i/10
-      if (i==0) flag=.false.
-    enddo
-  end function int2str
-
-end module write_field
-  
Index: /LMDZ5/branches/testing/libf/dyn3dmem/bands.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/bands.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/bands.F90	(revision 2408)
@@ -105,11 +105,9 @@
    SUBROUTINE  Set_Bands 
      USE parallel_lmdz
-#ifdef CPP_PHYS
-! Ehouarn: what follows is only related to // physics
-     USE mod_phys_lmdz_para, ONLY : jj_para_begin,jj_para_end
-#endif
      IMPLICIT NONE
      INCLUDE 'dimensions.h'    
-     INTEGER :: i
+     INTEGER :: i, ij
+     INTEGER :: jj_para_begin(0:mpi_size-1)
+     INTEGER :: jj_para_end(0:mpi_size-1)
         
       do i=0,mpi_size-1
@@ -118,6 +116,16 @@
       enddo
           
-#ifdef CPP_PHYS
-      do i=0,MPI_Size-1
+      jj_para_begin(0)=1
+      ij=distrib_phys(0)+iim-1
+      jj_para_end(0)=((ij-1)/iim)+1
+      
+      DO i=1,mpi_Size-1
+        ij=ij+1
+        jj_para_begin(i)=((ij-1)/iim)+1
+        ij=ij+distrib_phys(i)-1
+        jj_para_end(i)=((ij-1)/iim)+1
+      ENDDO
+ 
+       do i=0,MPI_Size-1
         jj_Nb_physic(i)=jj_para_end(i)-jj_para_begin(i)+1
         if (i/=0) then
@@ -139,5 +147,5 @@
         endif
       enddo
-#endif      
+
       CALL create_distrib(jj_Nb_Caldyn,distrib_caldyn)
       CALL create_distrib(jj_Nb_vanleer,distrib_vanleer)
@@ -479,2 +487,3 @@
   
   
+
Index: /LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90	(revision 2408)
@@ -137,5 +137,5 @@
    
            jD_cur = jD_ref + day_ini - day_ref                           &
-     &        + itau/day_step
+     &        + (itau+1)/day_step
 
            IF (planet_type .eq."generic") THEN
@@ -145,5 +145,5 @@
 
            jH_cur = jH_ref + start_time +                                &
-     &              mod(itau,day_step)/float(day_step) 
+     &              mod(itau+1,day_step)/float(day_step) 
     if (jH_cur > 1.0 ) then
       jD_cur = jD_cur +1.
Index: DZ5/branches/testing/libf/dyn3dmem/ce0l.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/ce0l.F90	(revision 2407)
+++ 	(revision )
@@ -1,134 +1,0 @@
-!
-! $Id$
-!
-!-------------------------------------------------------------------------------
-!
-PROGRAM ce0l
-!-------------------------------------------------------------------------------
-! Purpose: Calls etat0, creates initial states and limit_netcdf
-!
-!     interbar=.T. for barycentric interpolation inter_barxy
-!     extrap  =.T. for data extrapolation, like for the SSTs when file does not
-!                  contain ocean points only.
-!     oldice  =.T. for old-style ice, obtained using grille_m (grid_atob).
-!     masque is created in etat0, passed to limit to ensure consistancy.
-!-------------------------------------------------------------------------------
-  USE control_mod
-#ifdef CPP_EARTH
-! This prog. is designed to work for Earth
-  USE dimphy
-  USE comgeomphy
-  USE mod_phys_lmdz_para, mpi_root_xx=>mpi_root
-  USE mod_const_mpi
-  USE infotrac
-  USE parallel_lmdz, ONLY: finalize_parallel  
-  USE indice_sol_mod
-
-#ifdef CPP_IOIPSL
-  USE ioipsl, ONLY: ioconf_calendar
-#endif
-
-#endif
-  IMPLICIT NONE
-#ifndef CPP_EARTH
-#include "iniprint.h"
-  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
-#else
-!-------------------------------------------------------------------------------
-! Local variables:
-  LOGICAL, PARAMETER :: interbar=.TRUE., extrap=.FALSE., oldice=.FALSE.
-#include "dimensions.h"
-#include "paramet.h"
-!#include "indicesol.h"
-#include "iniprint.h"
-#include "temps.h"
-#include "logic.h"
-#ifdef CPP_MPI
-      include 'mpif.h'
-#endif
-
-  INTEGER                       :: ierr
-  REAL,    DIMENSION(iip1,jjp1) :: masque
-  CHARACTER(LEN=15)             :: calnd
-  REAL,    DIMENSION(iip1,jjp1) :: phis ! geopotentiel au sol
-!-------------------------------------------------------------------------------
-  CALL conf_gcm( 99, .TRUE. )
-
-#ifdef CPP_MPI
-  CALL init_mpi
-#endif
-
-  CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
-  WRITE(lunout,*)'---> klon=',klon
-  IF (mpi_size>1 .OR. omp_size>1) THEN
-       CALL abort_gcm('ce0l','In parallel mode,                         &
- &                 ce0l must be called only                             &
- &                 for 1 process and 1 task',1)
-  ENDIF
-
-  CALL InitComgeomphy
-
-#ifdef CPP_IOIPSL
-  SELECT CASE(calend)
-    CASE('earth_360d');CALL ioconf_calendar('360d');      calnd='a 360 jours/an'
-    CASE('earth_365d');CALL ioconf_calendar('noleap');    calnd='a 365 jours/an'
-    CASE('earth_366d');CALL ioconf_calendar('366d');      calnd='bissextile'
-    CASE('gregorian'); CALL ioconf_calendar('gregorian'); calnd='gregorien'
-    CASE('standard');  CALL ioconf_calendar('gregorian'); calnd='gregorien'
-    CASE('julian');    CALL ioconf_calendar('julian');    calnd='julien'
-    CASE('proleptic_gregorian'); CALL ioconf_calendar('gregorian')
-  !--- DC Bof...  => IOIPSL a mettre a jour: proleptic_gregorian /= gregorian
-    CASE DEFAULT
-      CALL abort_gcm('ce0l','Mauvais choix de calendrier',1)
-  END SELECT
-  WRITE(lunout,*)'CALENDRIER CHOISI: Terrestre '//TRIM(calnd)
-#endif
-
-  IF (type_trac == 'inca') THEN
-#ifdef INCA
-      CALL init_const_lmdz( &
-         nbtr,anneeref,dayref,&
-         iphysiq,day_step,nday,& 
-         nbsrf, is_oce,is_sic,&
-         is_ter,is_lic)
-      
-#endif
-  END IF
-
-  WRITE(lunout,'(//)')
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,*) '  ***  etat0_netcdf ***  '
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,'(//)')
-  WRITE(lunout,*) ' interbar = ',interbar
-  CALL etat0_netcdf(interbar,masque,phis,ok_etat0)
-
-  IF(ok_limit) THEN
-  WRITE(lunout,'(//)')
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,*) '  ***  Limit_netcdf ***  '
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,'(//)')
-  CALL limit_netcdf(interbar,extrap,oldice,masque)
-  END IF
-
-  WRITE(lunout,'(//)')
-  WRITE(lunout,*) '  ***************************  '
-  WRITE(lunout,*) '  ***  grilles_gcm_netcdf ***  '
-  WRITE(lunout,*) '  ***************************  '
-  WRITE(lunout,'(//)')
-  CALL grilles_gcm_netcdf_sub(masque,phis)
-  
-#ifdef CPP_MPI
-!$OMP MASTER
-  CALL MPI_FINALIZE(ierr)
-  IF (ierr /= 0) CALL abort_gcm('ce0l','Error in MPI_FINALIZE',1)
-!$OMP END MASTER
-#endif
-
-#endif
-! of #ifndef CPP_EARTH #else
-
-END PROGRAM ce0l
-!
-!-------------------------------------------------------------------------------
Index: DZ5/branches/testing/libf/dyn3dmem/convmas1_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/convmas1_loc.F	(revision 2407)
+++ 	(revision )
@@ -1,64 +1,0 @@
-      SUBROUTINE convmas1_loc (pbaru, pbarv, convm )
-c
-      USE parallel_lmdz
-      USE mod_filtreg_p
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteurs:  P. Le Van , F. Hourdin  .
-c   -------
-c
-c   Objet:
-c   ------
-c
-c   ********************************************************************
-c   .... calcul de la convergence du flux de masse aux niveaux p ...
-c   ********************************************************************
-c
-c
-c     pbaru  et  pbarv  sont des arguments d'entree pour le s-pg  ....
-c      .....  convm      est  un argument de sortie pour le s-pg  ....
-c
-c    le calcul se fait de haut en bas, 
-c    la convergence de masse au niveau p(llm+1) est egale a 0. et
-c    n'est pas stockee dans le tableau convm .
-c
-c
-c=======================================================================
-c
-c   Declarations:
-c   -------------
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
-#include "logic.h"
-
-      REAL pbaru( ijb_u:ije_u,llm ),pbarv( ijb_v:ije_v,llm )
-      REAL, target :: convm(  ijb_u:ije_u,llm )
-      INTEGER   l,ij
-
-      INTEGER ijb,ije,jjb,jje
- 
-      
-c-----------------------------------------------------------------------
-c    ....  calcul de - (d(pbaru)/dx + d(pbarv)/dy ) ......
-
-      CALL  convflu_loc( pbaru, pbarv, llm, convm )
-
-c-----------------------------------------------------------------------
-c   filtrage:
-c   ---------
-       
-       jjb=jj_begin
-       jje=jj_end+1
-       if (pole_sud) jje=jj_end
- 
-       CALL filtreg_p( convm, jjb_u,jje_u,jjb, jje, jjp1, llm,
-     &                 2, 2, .true., 1 )
-
-c    integration de la convergence de masse de haut  en bas ......
-c
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3dmem/convmas1_loc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/convmas1_loc.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/convmas1_loc.F90	(revision 2408)
@@ -0,0 +1,38 @@
+SUBROUTINE convmas1_loc (pbaru, pbarv, convm)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute mass flux convergence at p levels.
+!          Equivalent to convmas_loc if convmas2_loc is called after.
+  USE parallel_lmdz
+  USE mod_filtreg_p
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+  include "logic.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: pbaru(ijb_u:ije_u,llm)
+  REAL, INTENT(IN)  :: pbarv(ijb_v:ije_v,llm)
+  REAL, TARGET, INTENT(OUT) :: convm(ijb_u:ije_u,llm)
+!===============================================================================
+! Method used:   Computation from top to bottom.
+!   Mass convergence at level llm is equal to zero and is not stored in convm.
+!===============================================================================
+! Local variables:
+  INTEGER :: l, jjb, jje
+!===============================================================================
+
+!--- Computation of - (d(pbaru)/dx + d(pbarv)/dy )
+  CALL convflu_loc( pbaru, pbarv, llm, convm )
+
+!--- Filter
+  jjb=jj_begin
+  jje=jj_end+1
+  IF(pole_sud) jje=jj_end
+  CALL filtreg_p(convm,jjb_u,jje_u,jjb,jje,jjp1,llm,2,2,.TRUE.,1)
+
+END SUBROUTINE convmas1_loc
+
Index: DZ5/branches/testing/libf/dyn3dmem/convmas2_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/convmas2_loc.F	(revision 2407)
+++ 	(revision )
@@ -1,56 +1,0 @@
-      SUBROUTINE convmas2_loc ( convm )
-c
-      USE parallel_lmdz
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteurs:  P. Le Van , F. Hourdin  .
-c   -------
-c
-c   Objet:
-c   ------
-c
-c   ********************************************************************
-c   .... calcul de la convergence du flux de masse aux niveaux p ...
-c   ********************************************************************
-c
-c
-c     pbaru  et  pbarv  sont des arguments d'entree pour le s-pg  ....
-c      .....  convm      est  un argument de sortie pour le s-pg  ....
-c
-c    le calcul se fait de haut en bas, 
-c    la convergence de masse au niveau p(llm+1) est egale a 0. et
-c    n'est pas stockee dans le tableau convm .
-c
-c
-c=======================================================================
-c
-c   Declarations:
-c   -------------
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
-#include "logic.h"
-
-      REAL pbaru( ijb_u:ije_u,llm ),pbarv( ijb_v:ije_v,llm )
-      REAL :: convm(  ijb_u:ije_u,llm )
-      INTEGER   l,ij
-      INTEGER ijb,ije,jjb,jje
- 
-c$OMP MASTER
-c    integration de la convergence de masse de haut  en bas ......
-       ijb=ij_begin
-       ije=ij_end+iip1
-       if (pole_sud) ije=ij_end
-            
-      DO      l      = llmm1, 1, -1
-        DO    ij     = ijb, ije
-         convm(ij,l) = convm(ij,l) + convm(ij,l+1)
-        ENDDO
-      ENDDO
-c
-c$OMP END MASTER
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3dmem/convmas2_loc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/convmas2_loc.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/convmas2_loc.F90	(revision 2408)
@@ -0,0 +1,36 @@
+SUBROUTINE convmas2_loc (convm)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute mass flux convergence at p levels.
+!          Equivalent to convmas_loc if convmas1_loc is called before.
+  USE parallel_lmdz
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+  include "logic.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(INOUT) :: convm(ijb_u:ije_u,llm)
+!===============================================================================
+! Method used:   Computation from top to bottom.
+!   Mass convergence at level llm is equal to zero and is not stored in convm.
+!===============================================================================
+! Local variables:
+  INTEGER :: l, ijb, ije
+!===============================================================================
+
+!$OMP MASTER
+!--- Mass convergence is integrated from top to bottom
+  ijb=ij_begin
+  ije=ij_end+iip1
+  IF(pole_sud) ije=ij_end
+  DO l=llmm1,1,-1
+    convm(ijb:ije,l) = convm(ijb:ije,l) + convm(ijb:ije,l+1)
+  END DO
+!$OMP END MASTER
+
+END SUBROUTINE convmas2_loc
+
Index: DZ5/branches/testing/libf/dyn3dmem/convmas_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/convmas_loc.F	(revision 2407)
+++ 	(revision )
@@ -1,77 +1,0 @@
-      SUBROUTINE convmas_loc (pbaru, pbarv, convm )
-c
-      USE parallel_lmdz
-      USE mod_filtreg_p
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteurs:  P. Le Van , F. Hourdin  .
-c   -------
-c
-c   Objet:
-c   ------
-c
-c   ********************************************************************
-c   .... calcul de la convergence du flux de masse aux niveaux p ...
-c   ********************************************************************
-c
-c
-c     pbaru  et  pbarv  sont des arguments d'entree pour le s-pg  ....
-c      .....  convm      est  un argument de sortie pour le s-pg  ....
-c
-c    le calcul se fait de haut en bas, 
-c    la convergence de masse au niveau p(llm+1) est egale a 0. et
-c    n'est pas stockee dans le tableau convm .
-c
-c
-c=======================================================================
-c
-c   Declarations:
-c   -------------
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
-#include "logic.h"
-
-      REAL pbaru( ijb_u:ije_u,llm ),pbarv( ijb_v:ije_v,llm )
-      REAL, target :: convm(  ijb_u:ije_u,llm )
-      INTEGER   l,ij
-
-      INTEGER ijb,ije,jjb,jje
- 
-      
-c-----------------------------------------------------------------------
-c    ....  calcul de - (d(pbaru)/dx + d(pbarv)/dy ) ......
-
-      CALL  convflu_loc( pbaru, pbarv, llm, convm )
-
-c-----------------------------------------------------------------------
-c   filtrage:
-c   ---------
-       
-       jjb=jj_begin
-       jje=jj_end+1
-       if (pole_sud) jje=jj_end
- 
-       CALL filtreg_p(convm, jjb_u, jje_u,jjb, jje, jjp1, llm,
-     &                 2, 2, .true., 1 )
-
-c    integration de la convergence de masse de haut  en bas ......
-!$OMP BARRIER
-!$OMP MASTER
-       ijb=ij_begin
-       ije=ij_end+iip1
-       if (pole_sud) ije=ij_end
-            
-      DO      l      = llmm1, 1, -1
-        DO    ij     = ijb, ije
-         convm(ij,l) = convm(ij,l) + convm(ij,l+1)
-        ENDDO
-      ENDDO
-c
-!$OMP END MASTER
-!$OMP BARRIER
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3dmem/convmas_loc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/convmas_loc.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/convmas_loc.F90	(revision 2408)
@@ -0,0 +1,49 @@
+SUBROUTINE convmas_loc (pbaru, pbarv, convm)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute mass flux convergence at p levels.
+  USE parallel_lmdz
+  USE mod_filtreg_p
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+  include "logic.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: pbaru(ijb_u:ije_u,llm)
+  REAL, INTENT(IN)  :: pbarv(ijb_v:ije_v,llm)
+  REAL, INTENT(OUT) :: convm(ijb_u:ije_u,llm)
+!===============================================================================
+! Method used:   Computation from top to bottom.
+!   Mass convergence at level llm is equal to zero and is not stored in convm.
+!===============================================================================
+! Local variables:
+  INTEGER :: l, ijb, ije, jjb, jje
+!===============================================================================
+
+!--- Computation of - (d(pbaru)/dx + d(pbarv)/dy )
+  CALL convflu_loc( pbaru, pbarv, llm, convm )
+
+!--- Filter
+  jjb=jj_begin
+  jje=jj_end+1
+  IF(pole_sud) jje=jj_end
+  CALL filtreg_p(convm,jjb_u,jje_u,jjb,jje,jjp1,llm,2,2,.TRUE.,1)
+
+!--- Mass convergence is integrated from top to bottom
+!$OMP BARRIER
+!$OMP MASTER
+  ijb=ij_begin
+  ije=ij_end+iip1
+  IF(pole_sud) ije=ij_end
+  DO l=llmm1,1,-1
+    convm(ijb:ije,l) = convm(ijb:ije,l) + convm(ijb:ije,l+1)
+  END DO
+!$OMP END MASTER
+!$OMP BARRIER
+
+END SUBROUTINE convmas_loc
+
Index: DZ5/branches/testing/libf/dyn3dmem/dynetat0_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/dynetat0_loc.F	(revision 2407)
+++ 	(revision )
@@ -1,457 +1,0 @@
-!
-! $Id$
-!
-      SUBROUTINE dynetat0_loc(fichnom,vcov,ucov,
-     .                    teta,q,masse,ps,phis,time)
-      USE infotrac
-      use control_mod, only : planet_type
-      USE parallel_lmdz
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteur:  P. Le Van / L.Fairhead
-c   -------
-c
-c   objet:
-c   ------
-c
-c   Lecture de l'etat initial
-c
-c=======================================================================
-c-----------------------------------------------------------------------
-c   Declarations:
-c   -------------
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "temps.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
-#include "ener.h"
-#include "netcdf.inc"
-#include "description.h"
-#include "serre.h"
-#include "logic.h"
-#include "iniprint.h"
-
-c   Arguments:
-c   ----------
-
-      CHARACTER*(*) fichnom
-      REAL vcov(ijb_v:ije_v,llm),ucov(ijb_u:ije_u,llm)
-      REAL teta(ijb_u:ije_u,llm)
-      REAL q(ijb_u:ije_u,llm,nqtot),masse(ijb_u:ije_u,llm)
-      REAL ps(ijb_u:ije_u),phis(ijb_u:ije_u)
-
-      REAL time
-
-c   Variables 
-c
-      INTEGER length,iq
-      PARAMETER (length = 100)
-      REAL tab_cntrl(length) ! tableau des parametres du run
-      INTEGER ierr, nid, nvarid
-      REAL,ALLOCATABLE :: vcov_glo(:,:),ucov_glo(:,:),teta_glo(:,:)
-      REAL,ALLOCATABLE :: q_glo(:,:),masse_glo(:,:),ps_glo(:)
-      REAL,ALLOCATABLE :: phis_glo(:)
-
-      INTEGER idecal
-
-c-----------------------------------------------------------------------
-c  Ouverture NetCDF du fichier etat initial
-
-      ierr = NF_OPEN (fichnom, NF_NOWRITE,nid)
-      IF (ierr.NE.NF_NOERR) THEN
-        write(lunout,*)
-     &  'dynetat0_loc: Pb d''ouverture du fichier start.nc'
-        write(lunout,*)' ierr = ', ierr
-        CALL ABORT_GCM("DYNETAT0", "", 1)
-      ENDIF
-
-c
-      ierr = NF_INQ_VARID (nid, "controle", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <controle> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tab_cntrl)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, tab_cntrl)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echoue pour <controle>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-
-      !!! AS: idecal is a hack to be able to read planeto starts...
-      !!!     .... while keeping everything OK for LMDZ EARTH
-      if (planet_type.eq."generic") then
-          print*,'NOTE NOTE NOTE : Planeto-like start files'
-          idecal = 4
-          annee_ref  = 2000
-      else
-          print*,'NOTE NOTE NOTE : Earth-like start files'
-          idecal = 5
-          annee_ref  = tab_cntrl(5)
-      endif
-
-
-      im         = tab_cntrl(1)
-      jm         = tab_cntrl(2)
-      lllm       = tab_cntrl(3)
-      day_ref    = tab_cntrl(4)
-      rad        = tab_cntrl(idecal+1)
-      omeg       = tab_cntrl(idecal+2)
-      g          = tab_cntrl(idecal+3)
-      cpp        = tab_cntrl(idecal+4)
-      kappa      = tab_cntrl(idecal+5)
-      daysec     = tab_cntrl(idecal+6)
-      dtvr       = tab_cntrl(idecal+7)
-      etot0      = tab_cntrl(idecal+8)
-      ptot0      = tab_cntrl(idecal+9)
-      ztot0      = tab_cntrl(idecal+10)
-      stot0      = tab_cntrl(idecal+11)
-      ang0       = tab_cntrl(idecal+12)
-      pa         = tab_cntrl(idecal+13)
-      preff      = tab_cntrl(idecal+14)
-c
-      clon       = tab_cntrl(idecal+15)
-      clat       = tab_cntrl(idecal+16)
-      grossismx  = tab_cntrl(idecal+17)
-      grossismy  = tab_cntrl(idecal+18)
-c
-      IF ( tab_cntrl(idecal+19).EQ.1. )  THEN
-        fxyhypb  = . TRUE .
-c        dzoomx   = tab_cntrl(25)
-c        dzoomy   = tab_cntrl(26)
-c        taux     = tab_cntrl(28)
-c        tauy     = tab_cntrl(29)
-      ELSE
-        fxyhypb = . FALSE .
-        ysinus  = . FALSE .
-        IF( tab_cntrl(idecal+22).EQ.1. ) ysinus = . TRUE. 
-      ENDIF
-
-      day_ini = tab_cntrl(30)
-      itau_dyn = tab_cntrl(31)
-c   .................................................................
-c
-c
-      write(lunout,*)'dynetat0_loc: rad,omeg,g,cpp,kappa',
-     &               rad,omeg,g,cpp,kappa
-
-      IF(   im.ne.iim           )  THEN
-          PRINT 1,im,iim
-          STOP
-      ELSE  IF( jm.ne.jjm       )  THEN
-          PRINT 2,jm,jjm
-          STOP
-      ELSE  IF( lllm.ne.llm     )  THEN
-          PRINT 3,lllm,llm
-          STOP
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlonu", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <rlonu> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, rlonu)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, rlonu)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <rlonu>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlatu", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <rlatu> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, rlatu)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, rlatu)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <rlatu>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlonv", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <rlonv> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, rlonv)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, rlonv)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <rlonv>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "rlatv", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <rlatv> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, rlatv)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, rlatv)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour rlatv"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "cu", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <cu> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, cu)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, cu)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <cu>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "cv", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <cv> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, cv)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, cv)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <cv>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "aire", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <aire> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, aire)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, aire)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <aire>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-      
-      ALLOCATE(phis_glo(ip1jmp1))
-      
-      ierr = NF_INQ_VARID (nid, "phisinit", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <phisinit> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, phis_glo)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, phis_glo)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <phisinit>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-      phis(ijb_u:ije_u)=phis_glo(ijb_u:ije_u)
-      DEALLOCATE(phis_glo)
-
-      ierr = NF_INQ_VARID (nid, "temps", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0: Le champ <temps> est absent"
-         write(lunout,*)"dynetat0: J essaie <Time>"
-         ierr = NF_INQ_VARID (nid, "Time", nvarid)
-         IF (ierr .NE. NF_NOERR) THEN
-            write(lunout,*)"dynetat0: Le champ <Time> est absent"
-            CALL abort_gcm("dynetat0", "", 1)
-         ENDIF
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, time)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, time)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee <temps>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ierr = NF_INQ_VARID (nid, "ucov", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <ucov> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-      
-      ALLOCATE(ucov_glo(ip1jmp1,llm))
-      
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, ucov_glo)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, ucov_glo)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <ucov>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ucov(ijb_u:ije_u,:)=ucov_glo(ijb_u:ije_u,:)
-      DEALLOCATE(ucov_glo)
-      ALLOCATE(vcov_glo(ip1jm,llm))
-      
-      ierr = NF_INQ_VARID (nid, "vcov", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <vcov> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, vcov_glo)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, vcov_glo)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <vcov>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-      vcov(ijb_v:ije_v,:)=vcov_glo(ijb_v:ije_v,:)
-      DEALLOCATE(vcov_glo)
-      ALLOCATE(teta_glo(ip1jmp1,llm))
-
-      ierr = NF_INQ_VARID (nid, "teta", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <teta> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, teta_glo)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, teta_glo)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <teta>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-
-      teta(ijb_u:ije_u,:)=teta_glo(ijb_u:ije_u,:)
-      DEALLOCATE(teta_glo)
-      ALLOCATE(q_glo(ip1jmp1,llm))
-
-
-      DO iq=1,nqtot
-        ierr =  NF_INQ_VARID (nid, tname(iq), nvarid)
-        IF (ierr .NE. NF_NOERR) THEN
-           write(lunout,*)"dynetat0_loc: Le traceur <"                  &
-     &     //trim(tname(iq))//"> est absent"
-           write(lunout,*)"Il est donc initialise a zero"
-           q(:,:,iq)=0.
-
-           ! CRisi: pour les isotopes, on peut faire init théorique
-           ! distill de Rayleigh très simplifiée
-           if (ok_isotopes) then
-              if ((iso_num(iq).gt.0).and.(zone_num(iq).eq.0)) then
-                q(:,:,iq)=q(:,:,iqpere(iq))                             &
-     &                   *tnat(iso_num(iq))                             &
-     &                   *(q(:,:,iqpere(iq))/30.e-3)                    &
-     &                   **(alpha_ideal(iso_num(iq))-1)
-              endif
-              if ((iso_num(iq).gt.0).and.(zone_num(iq).eq.1)) then
-                  q(:,:,iq)=q(:,:,iqiso(iso_indnum(iq),phase_num(iq)))
-              endif  
-           endif !if (ok_isotopes) then        
-
-        ELSE
-#ifdef NC_DOUBLE
-          ierr = NF_GET_VAR_DOUBLE(nid, nvarid, q_glo)
-#else
-          ierr = NF_GET_VAR_REAL(nid, nvarid, q_glo)
-#endif
-          IF (ierr .NE. NF_NOERR) THEN
-            write(lunout,*)
-     &      "dynetat0_loc: Lecture echouee pour "//tname(iq)
-            CALL abort_gcm("dynetat0", "", 1)
-          ENDIF
-        q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:)
-
-        ENDIF
-      ENDDO !DO iq=1,nqtot
-
-      if (ok_iso_verif) then
-         call check_isotopes(q,ijb_u,ije_u,'dynetat0_loc')
-      endif !if (ok_iso_verif) then
-
-      DEALLOCATE(q_glo)
-      ALLOCATE(masse_glo(ip1jmp1,llm))
-
-      ierr = NF_INQ_VARID (nid, "masse", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <masse> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, masse_glo)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, masse_glo)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <masse>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-      masse(ijb_u:ije_u,:)=masse_glo(ijb_u:ije_u,:)
-      DEALLOCATE(masse_glo)
-      ALLOCATE(ps_glo(ip1jmp1))
-
-      ierr = NF_INQ_VARID (nid, "ps", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Le champ <ps> est absent"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, ps_glo)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, ps_glo)
-#endif
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynetat0_loc: Lecture echouee pour <ps>"
-         CALL abort_gcm("dynetat0", "", 1)
-      ENDIF
-
-      ps(ijb_u:ije_u)=ps_glo(ijb_u:ije_u)
-      DEALLOCATE(ps_glo)
-
-      ierr = NF_CLOSE(nid)
-
-       day_ini=day_ini+INT(time)
-       time=time-INT(time)
-
-  1   FORMAT(//10x,'la valeur de im =',i4,2x,'lue sur le fichier de dem
-     *arrage est differente de la valeur parametree iim =',i4//)
-   2  FORMAT(//10x,'la valeur de jm =',i4,2x,'lue sur le fichier de dem
-     *arrage est differente de la valeur parametree jjm =',i4//)
-   3  FORMAT(//10x,'la valeur de lmax =',i4,2x,'lue sur le fichier dema
-     *rrage est differente de la valeur parametree llm =',i4//)
-   4  FORMAT(//10x,'la valeur de dtrv =',i4,2x,'lue sur le fichier dema
-     *rrage est differente de la valeur  dtinteg =',i4//)
-
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3dmem/dynetat0_loc.f90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/dynetat0_loc.f90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/dynetat0_loc.f90	(revision 2408)
@@ -0,0 +1,241 @@
+SUBROUTINE dynetat0_loc(fichnom,vcov,ucov,teta,q,masse,ps,phis,time)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , L.Fairhead
+!-------------------------------------------------------------------------------
+! Purpose: Initial state reading.
+!-------------------------------------------------------------------------------
+  USE parallel_lmdz
+  USE infotrac
+  USE netcdf, ONLY: NF90_OPEN,  NF90_INQUIRE_DIMENSION, NF90_INQ_VARID,        &
+      NF90_NOWRITE, NF90_CLOSE, NF90_INQUIRE_VARIABLE,  NF90_GET_VAR, NF90_NoErr
+  USE control_mod, ONLY: planet_type
+  USE assert_eq_m, ONLY: assert_eq
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "temps.h"
+  include "comconst.h"
+  include "comvert.h"
+  include "comgeom.h"
+  include "ener.h"
+  include "description.h"
+  include "serre.h"
+  include "logic.h"
+  include "iniprint.h"
+!===============================================================================
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN) :: fichnom          !--- FILE NAME
+  REAL, INTENT(OUT) ::  vcov(ijb_v:ije_v,llm)      !--- V COVARIANT WIND
+  REAL, INTENT(OUT) ::  ucov(ijb_u:ije_u,llm)      !--- U COVARIANT WIND
+  REAL, INTENT(OUT) ::  teta(ijb_u:ije_u,llm)      !--- POTENTIAL TEMP.
+  REAL, INTENT(OUT) ::     q(ijb_u:ije_u,llm,nqtot)!--- TRACERS
+  REAL, INTENT(OUT) :: masse(ijb_u:ije_u,llm)      !--- MASS PER CELL
+  REAL, INTENT(OUT) ::    ps(ijb_u:ije_u)          !--- GROUND PRESSURE
+  REAL, INTENT(OUT) ::  phis(ijb_u:ije_u)          !--- GEOPOTENTIAL
+!===============================================================================
+! Local variables:
+  CHARACTER(LEN=256) :: msg, var, modname
+  INTEGER, PARAMETER :: length=100
+  INTEGER :: iq, fID, vID, idecal, ierr
+  REAL    :: time, 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(:,:)
+!-------------------------------------------------------------------------------
+  modname="dynetat0_loc"
+
+!--- Initial state file opening
+  var=fichnom
+  CALL err(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var)
+  CALL get_var1("controle",tab_cntrl)
+
+!!! AS: idecal is a hack to be able to read planeto starts...
+!!!     .... while keeping everything OK for LMDZ EARTH
+  IF(planet_type=="generic") THEN
+    WRITE(lunout,*)'NOTE NOTE NOTE : Planeto-like start files'
+    idecal = 4
+    annee_ref  = 2000
+  ELSE
+    WRITE(lunout,*)'NOTE NOTE NOTE : Earth-like start files'
+    idecal = 5
+    annee_ref  = tab_cntrl(5)
+  END IF
+  im         = tab_cntrl(1)
+  jm         = tab_cntrl(2)
+  lllm       = tab_cntrl(3)
+  day_ref    = tab_cntrl(4)
+  rad        = tab_cntrl(idecal+1)
+  omeg       = tab_cntrl(idecal+2)
+  g          = tab_cntrl(idecal+3)
+  cpp        = tab_cntrl(idecal+4)
+  kappa      = tab_cntrl(idecal+5)
+  daysec     = tab_cntrl(idecal+6)
+  dtvr       = tab_cntrl(idecal+7)
+  etot0      = tab_cntrl(idecal+8)
+  ptot0      = tab_cntrl(idecal+9)
+  ztot0      = tab_cntrl(idecal+10)
+  stot0      = tab_cntrl(idecal+11)
+  ang0       = tab_cntrl(idecal+12)
+  pa         = tab_cntrl(idecal+13)
+  preff      = tab_cntrl(idecal+14)
+!
+  clon       = tab_cntrl(idecal+15)
+  clat       = tab_cntrl(idecal+16)
+  grossismx  = tab_cntrl(idecal+17)
+  grossismy  = tab_cntrl(idecal+18)
+!
+  IF ( tab_cntrl(idecal+19)==1. )  THEN
+    fxyhypb  = .TRUE.
+!   dzoomx   = tab_cntrl(25)
+!   dzoomy   = tab_cntrl(26)
+!   taux     = tab_cntrl(28)
+!   tauy     = tab_cntrl(29)
+  ELSE
+    fxyhypb = .FALSE.
+    ysinus  = tab_cntrl(idecal+22)==1.
+  END IF
+
+  day_ini    = tab_cntrl(30)
+  itau_dyn   = tab_cntrl(31)
+!  start_time = tab_cntrl(32)   ????
+
+!-------------------------------------------------------------------------------
+  WRITE(lunout,*)TRIM(modname)//': rad,omeg,g,cpp,kappa',rad,omeg,g,cpp,kappa
+  CALL check_dim(im,iim,'im','im')
+  CALL check_dim(jm,jjm,'jm','jm')
+  CALL check_dim(lllm,llm,'lm','lllm')
+  CALL get_var1("rlonu",rlonu)
+  CALL get_var1("rlatu",rlatu)
+  CALL get_var1("rlonv",rlonv)
+  CALL get_var1("rlatv",rlatv)
+  CALL get_var1("cu"  ,cu)
+  CALL get_var1("cv"  ,cv)
+  CALL get_var1("aire",aire)
+
+  var="temps"
+  IF(NF90_INQ_VARID(fID,var,vID)/=NF90_NoErr) THEN
+    WRITE(lunout,*)TRIM(modname)//": missing field <temps>"
+    WRITE(lunout,*)TRIM(modname)//": trying with <Time>"; var="Time"
+    CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
+  END IF
+  CALL err(NF90_GET_VAR(fID,vID,time),"get",var)
+
+  ALLOCATE(phis_glo(ip1jmp1))
+  CALL get_var1("phisinit",phis_glo)
+  phis (ijb_u:ije_u)  =phis_glo(ijb_u:ije_u);    DEALLOCATE(phis_glo)
+
+  ALLOCATE(ucov_glo(ip1jmp1,llm))
+  CALL get_var2("ucov",ucov_glo)
+  ucov (ijb_u:ije_u,:)=ucov_glo(ijb_u:ije_u,:);  DEALLOCATE(ucov_glo)
+
+  ALLOCATE(vcov_glo(ip1jm,llm))
+  CALL get_var2("vcov",vcov_glo)
+  vcov (ijb_v:ije_v,:)=vcov_glo(ijb_v:ije_v,:);  DEALLOCATE(vcov_glo)
+
+  ALLOCATE(teta_glo(ip1jmp1,llm))
+  CALL get_var2("teta",teta_glo)
+  teta (ijb_u:ije_u,:)=teta_glo(ijb_u:ije_u,:);  DEALLOCATE(teta_glo)
+
+  ALLOCATE(masse_glo(ip1jmp1,llm))
+  CALL get_var2("masse",masse_glo)
+  masse(ijb_u:ije_u,:)=masse_glo(ijb_u:ije_u,:); DEALLOCATE(masse_glo)
+  
+  ALLOCATE(ps_glo(ip1jmp1))
+  CALL get_var1("ps",ps_glo)
+  ps   (ijb_u:ije_u)  =   ps_glo(ijb_u:ije_u);   DEALLOCATE(ps_glo)
+
+!--- Tracers
+  ALLOCATE(q_glo(ip1jmp1,llm))
+  DO iq=1,nqtot
+    var=tname(iq)
+    IF(NF90_INQ_VARID(fID,var,vID)==NF90_NoErr) THEN
+      CALL get_var2(var,q_glo); q(ijb_u:ije_u,:,iq)=q_glo(ijb_u:ije_u,:); CYCLE
+    END IF
+    WRITE(lunout,*)TRIM(modname)//": Tracer <"//TRIM(var)//"> is missing"
+    WRITE(lunout,*)"         It is hence initialized to zero"
+    q(ijb_u:ije_u,:,iq)=0.
+   !--- CRisi: for isotops, theoretical initialization using very simplified
+   !           Rayleigh distillation las.
+    IF(ok_isotopes.AND.iso_num(iq)>0) THEN
+      IF(zone_num(iq)==0) q(:,:,iq)=q(:,:,iqpere(iq))*tnat(iso_num(iq))        &
+     &           *(q(:,:,iqpere(iq))/30.e-3)**(alpha_ideal(iso_num(iq))-1)
+      IF(zone_num(iq)==1) q(:,:,iq)=q(:,:,iqiso(iso_indnum(iq),phase_num(iq)))
+    END IF
+  END DO
+  DEALLOCATE(q_glo)
+  CALL err(NF90_CLOSE(fID),"close",fichnom)
+  day_ini=day_ini+INT(time)
+  time=time-INT(time)
+
+
+  CONTAINS
+
+
+SUBROUTINE check_dim(n1,n2,str1,str2)
+  INTEGER,          INTENT(IN) :: n1, n2
+  CHARACTER(LEN=*), INTENT(IN) :: str1, str2
+  CHARACTER(LEN=256) :: s1, s2
+  IF(n1/=n2) THEN
+    s1='value of '//TRIM(str1)//' ='
+    s2=' read in starting file differs from parametrized '//TRIM(str2)//' ='
+    WRITE(msg,'(10x,a,i4,2x,a,i4)'),s1,n1,s2,n2
+    CALL ABORT_gcm(TRIM(modname),TRIM(msg),1)
+  END IF
+END SUBROUTINE check_dim
+
+
+SUBROUTINE get_var1(var,v)
+  CHARACTER(LEN=*), INTENT(IN)  :: var
+  REAL,             INTENT(OUT) :: v(:)
+  REAL,             ALLOCATABLE :: w2(:,:), w3(:,:,:)
+  INTEGER :: nn(3), dids(3), k, nd, ntot
+
+  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
+  ierr=NF90_INQUIRE_VARIABLE(fID,vID,ndims=nd)
+  IF(nd==1) THEN
+    CALL err(NF90_GET_VAR(fID,vID,v),"get",var); RETURN
+  END IF
+  ierr=NF90_INQUIRE_VARIABLE(fID,vID,dimids=dids)
+  DO k=1,nd; ierr=NF90_INQUIRE_DIMENSION(fID,dids(k),len=nn(k)); END DO
+  ntot=PRODUCT(nn(1:nd))
+  SELECT CASE(nd)
+    CASE(2); ALLOCATE(w2(nn(1),nn(2)))
+      CALL err(NF90_GET_VAR(fID,vID,w2),"get",var)
+      v=RESHAPE(w2,[ntot]); DEALLOCATE(w2)
+    CASE(3); ALLOCATE(w3(nn(1),nn(2),nn(3)))
+      CALL err(NF90_GET_VAR(fID,vID,w3),"get",var)
+      v=RESHAPE(w3,[ntot]); DEALLOCATE(w3)
+  END SELECT
+END SUBROUTINE get_var1
+
+
+SUBROUTINE get_var2(var,v)
+  CHARACTER(LEN=*), INTENT(IN)  :: var
+  REAL,             INTENT(OUT) :: v(:,:)
+  REAL,             ALLOCATABLE :: w4(:,:,:,:)
+  INTEGER :: nn(4), dids(4), k, nd
+  CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var)
+  ierr=NF90_INQUIRE_VARIABLE(fID,vID,dimids=dids,ndims=nd)
+  DO k=1,nd; ierr=NF90_INQUIRE_DIMENSION(fID,dids(k),len=nn(k)); END DO
+  ALLOCATE(w4(nn(1),nn(2),nn(3),nn(4)))
+  CALL err(NF90_GET_VAR(fID,vID,w4),"get",var)
+  v=RESHAPE(w4,[nn(1)*nn(2),nn(3)]); DEALLOCATE(w4)
+END SUBROUTINE get_var2
+
+
+SUBROUTINE err(ierr,typ,nam)
+  INTEGER,          INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
+  CHARACTER(LEN=*), INTENT(IN) :: typ    !--- TYPE OF OPERATION
+  CHARACTER(LEN=*), INTENT(IN) :: nam    !--- FIELD/FILE NAME
+  IF(ierr==NF90_NoERR) RETURN
+  SELECT CASE(typ)
+    CASE('inq');   msg="Field <"//TRIM(nam)//"> is missing"
+    CASE('get');   msg="Reading failed for <"//TRIM(nam)//">"
+    CASE('open');  msg="File opening failed for <"//TRIM(nam)//">"
+    CASE('close'); msg="File closing failed for <"//TRIM(nam)//">"
+  END SELECT
+  CALL ABORT_gcm(TRIM(modname),TRIM(msg),ierr)
+END SUBROUTINE err
+
+END SUBROUTINE dynetat0_loc
Index: DZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F	(revision 2407)
+++ 	(revision )
@@ -1,688 +1,0 @@
-!
-! $Id$
-!
-c
-      SUBROUTINE dynredem0_loc(fichnom,iday_end,phis)
-#ifdef CPP_IOIPSL
-      USE IOIPSL
-#endif
-      USE parallel_lmdz
-      USE mod_hallo
-      USE infotrac
-      IMPLICIT NONE
-c=======================================================================
-c Ecriture du fichier de redemarrage sous format NetCDF (initialisation)
-c=======================================================================
-c   Declarations:
-c   -------------
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comvert.h"
-#include "comgeom.h"
-#include "temps.h"
-#include "ener.h"
-#include "logic.h"
-#include "netcdf.inc"
-#include "description.h"
-#include "serre.h"
-#include "iniprint.h"
-
-c   Arguments:
-c   ----------
-      INTEGER iday_end
-      REAL phis(ijb_u:ije_u)
-      CHARACTER*(*) fichnom
-
-c   Local:
-c   ------
-      INTEGER iq,l
-      INTEGER length
-      PARAMETER (length = 100)
-      REAL tab_cntrl(length) ! tableau des parametres du run
-      INTEGER ierr
-      character*20 modname
-      character*80 abort_message
-
-c   Variables locales pour NetCDF:
-c
-      INTEGER dims2(2), dims3(3), dims4(4)
-      INTEGER idim_index
-      INTEGER idim_rlonu, idim_rlonv, idim_rlatu, idim_rlatv
-      INTEGER idim_s, idim_sig
-      INTEGER idim_tim
-      INTEGER nid,nvarid
-
-      REAL zan0,zjulian,hours
-      INTEGER yyears0,jjour0, mmois0
-      character*30 unites
-      REAL :: phis_glo(ip1jmp1)
-      
-      CALL Gather_field_u(phis,phis_glo,1)
-      
-      
-c-----------------------------------------------------------------------
-      if (mpi_rank==0) then
-      
-      modname='dynredem0_loc'
-
-#ifdef CPP_IOIPSL
-      call ymds2ju(annee_ref, 1, iday_end, 0.0, zjulian)
-      call ju2ymds(zjulian, yyears0, mmois0, jjour0, hours)
-#else
-! set yyears0, mmois0, jjour0 to 0,1,1 (hours is not used)
-      yyears0=0
-      mmois0=1
-      jjour0=1
-#endif                
-
-      DO l=1,length
-       tab_cntrl(l) = 0.
-      ENDDO
-       tab_cntrl(1)  =  REAL(iim)
-       tab_cntrl(2)  =  REAL(jjm)
-       tab_cntrl(3)  =  REAL(llm)
-       tab_cntrl(4)  =  REAL(day_ref)
-       tab_cntrl(5)  =  REAL(annee_ref)
-       tab_cntrl(6)  = rad
-       tab_cntrl(7)  = omeg
-       tab_cntrl(8)  = g
-       tab_cntrl(9)  = cpp
-       tab_cntrl(10) = kappa
-       tab_cntrl(11) = daysec
-       tab_cntrl(12) = dtvr
-       tab_cntrl(13) = etot0
-       tab_cntrl(14) = ptot0
-       tab_cntrl(15) = ztot0
-       tab_cntrl(16) = stot0
-       tab_cntrl(17) = ang0
-       tab_cntrl(18) = pa
-       tab_cntrl(19) = preff
-c
-c    .....    parametres  pour le zoom      ......   
-
-       tab_cntrl(20)  = clon
-       tab_cntrl(21)  = clat
-       tab_cntrl(22)  = grossismx
-       tab_cntrl(23)  = grossismy
-c
-      IF ( fxyhypb )   THEN
-       tab_cntrl(24) = 1.
-       tab_cntrl(25) = dzoomx
-       tab_cntrl(26) = dzoomy
-       tab_cntrl(27) = 0.
-       tab_cntrl(28) = taux
-       tab_cntrl(29) = tauy
-      ELSE
-       tab_cntrl(24) = 0.
-       tab_cntrl(25) = dzoomx
-       tab_cntrl(26) = dzoomy
-       tab_cntrl(27) = 0.
-       tab_cntrl(28) = 0.
-       tab_cntrl(29) = 0.
-       IF( ysinus )  tab_cntrl(27) = 1.
-      ENDIF
-
-       tab_cntrl(30) =  REAL(iday_end)
-       tab_cntrl(31) =  REAL(itau_dyn + itaufin)
-c start_time: start_time of simulation (not necessarily 0.)
-       tab_cntrl(32) = start_time
-c
-c    .........................................................
-c
-c Creation du fichier:
-c
-      ierr = NF_CREATE(fichnom, NF_CLOBBER, nid)
-      IF (ierr.NE.NF_NOERR) THEN
-         write(lunout,*)"dynredem0: Pb d ouverture du fichier "
-     &                  //trim(fichnom)
-         write(lunout,*)' ierr = ', ierr
-         CALL ABORT_GCM("DYNREDEM0", "", 1)
-      ENDIF
-c
-c Preciser quelques attributs globaux:
-c
-      ierr = NF_PUT_ATT_TEXT (nid, NF_GLOBAL, "title", 27,
-     .                       "Fichier demmarage dynamique")
-c
-c Definir les dimensions du fichiers:
-c
-      ierr = NF_DEF_DIM (nid, "index", length, idim_index)
-      ierr = NF_DEF_DIM (nid, "rlonu", iip1, idim_rlonu)
-      ierr = NF_DEF_DIM (nid, "rlatu", jjp1, idim_rlatu)
-      ierr = NF_DEF_DIM (nid, "rlonv", iip1, idim_rlonv)
-      ierr = NF_DEF_DIM (nid, "rlatv", jjm, idim_rlatv)
-      ierr = NF_DEF_DIM (nid, "sigs", llm, idim_s)
-      ierr = NF_DEF_DIM (nid, "sig", llmp1, idim_sig)
-      ierr = NF_DEF_DIM (nid, "temps", NF_UNLIMITED, idim_tim)
-c
-      ierr = NF_ENDDEF(nid) ! sortir du mode de definition
-c
-c Definir et enregistrer certains champs invariants:
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"controle",NF_DOUBLE,1,idim_index,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"controle",NF_FLOAT,1,idim_index,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 22,
-     .                       "Parametres de controle")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,tab_cntrl)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,tab_cntrl)
-#endif
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"rlonu",NF_DOUBLE,1,idim_rlonu,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"rlonu",NF_FLOAT,1,idim_rlonu,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 23,
-     .                       "Longitudes des points U")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlonu)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlonu)
-#endif
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"rlatu",NF_DOUBLE,1,idim_rlatu,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"rlatu",NF_FLOAT,1,idim_rlatu,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 22,
-     .                       "Latitudes des points U")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlatu)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlatu)
-#endif
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"rlonv",NF_DOUBLE,1,idim_rlonv,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"rlonv",NF_FLOAT,1,idim_rlonv,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 23,
-     .                       "Longitudes des points V")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlonv)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlonv)
-#endif
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"rlatv",NF_DOUBLE,1,idim_rlatv,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"rlatv",NF_FLOAT,1,idim_rlatv,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 22,
-     .                       "Latitudes des points V")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,rlatv)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,rlatv)
-#endif
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"nivsigs",NF_DOUBLE,1,idim_s,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"nivsigs",NF_FLOAT,1,idim_s,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 28,
-     .                       "Numero naturel des couches s")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,nivsigs)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,nivsigs)
-#endif
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"nivsig",NF_DOUBLE,1,idim_sig,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"nivsig",NF_FLOAT,1,idim_sig,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 32,
-     .                       "Numero naturel des couches sigma")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,nivsig)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,nivsig)
-#endif
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"ap",NF_DOUBLE,1,idim_sig,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"ap",NF_FLOAT,1,idim_sig,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 26,
-     .                       "Coefficient A pour hybride")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,ap)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,ap)
-#endif
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"bp",NF_DOUBLE,1,idim_sig,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"bp",NF_FLOAT,1,idim_sig,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 26,
-     .                       "Coefficient B pour hybride")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,bp)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,bp)
-#endif
-c
-      ierr = NF_REDEF (nid)
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"presnivs",NF_DOUBLE,1,idim_s,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"presnivs",NF_FLOAT,1,idim_s,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,presnivs)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,presnivs)
-#endif
-c
-c Coefficients de passage cov. <-> contra. <--> naturel
-c
-      ierr = NF_REDEF (nid)
-      dims2(1) = idim_rlonu
-      dims2(2) = idim_rlatu
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"cu",NF_DOUBLE,2,dims2,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"cu",NF_FLOAT,2,dims2,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 29,
-     .                       "Coefficient de passage pour U")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,cu)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,cu)
-#endif
-c
-      ierr = NF_REDEF (nid)
-      dims2(1) = idim_rlonv
-      dims2(2) = idim_rlatv
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"cv",NF_DOUBLE,2,dims2,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"cv",NF_FLOAT,2,dims2,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 29,
-     .                       "Coefficient de passage pour V")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,cv)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,cv)
-#endif
-c
-c Aire de chaque maille:
-c
-      ierr = NF_REDEF (nid)
-      dims2(1) = idim_rlonv
-      dims2(2) = idim_rlatu
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"aire",NF_DOUBLE,2,dims2,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"aire",NF_FLOAT,2,dims2,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 22,
-     .                       "Aires de chaque maille")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,aire)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,aire)
-#endif
-c
-c Geopentiel au sol:
-c
-      ierr = NF_REDEF (nid)
-      dims2(1) = idim_rlonv
-      dims2(2) = idim_rlatu
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"phisinit",NF_DOUBLE,2,dims2,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"phisinit",NF_FLOAT,2,dims2,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 19,
-     .                       "Geopotentiel au sol")
-      ierr = NF_ENDDEF(nid)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,phis_glo)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,phis_glo)
-#endif
-c
-c Definir les variables pour pouvoir les enregistrer plus tard:
-c
-      ierr = NF_REDEF (nid) ! entrer dans le mode de definition
-c
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"temps",NF_DOUBLE,1,idim_tim,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"temps",NF_FLOAT,1,idim_tim,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 19,
-     .                       "Temps de simulation")
-      write(unites,200)yyears0,mmois0,jjour0
-200   format('days since ',i4,'-',i2.2,'-',i2.2,' 00:00:00')
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "units", 30,
-     .                         unites)
-
-c
-      dims4(1) = idim_rlonu
-      dims4(2) = idim_rlatu
-      dims4(3) = idim_s
-      dims4(4) = idim_tim
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"ucov",NF_DOUBLE,4,dims4,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"ucov",NF_FLOAT,4,dims4,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 9,
-     .                       "Vitesse U")
-c
-      dims4(1) = idim_rlonv
-      dims4(2) = idim_rlatv
-      dims4(3) = idim_s
-      dims4(4) = idim_tim
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"vcov",NF_DOUBLE,4,dims4,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"vcov",NF_FLOAT,4,dims4,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 9,
-     .                       "Vitesse V")
-c
-      dims4(1) = idim_rlonv
-      dims4(2) = idim_rlatu
-      dims4(3) = idim_s
-      dims4(4) = idim_tim
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"teta",NF_DOUBLE,4,dims4,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"teta",NF_FLOAT,4,dims4,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 11,
-     .                       "Temperature")
-c
-      dims4(1) = idim_rlonv
-      dims4(2) = idim_rlatu
-      dims4(3) = idim_s
-      dims4(4) = idim_tim
-
-      DO iq=1,nqtot
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,tname(iq),NF_DOUBLE,4,dims4,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,tname(iq),NF_FLOAT,4,dims4,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 12,ttext(iq))
-      ENDDO
-c
-      dims4(1) = idim_rlonv
-      dims4(2) = idim_rlatu
-      dims4(3) = idim_s
-      dims4(4) = idim_tim
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"masse",NF_DOUBLE,4,dims4,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"masse",NF_FLOAT,4,dims4,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 12,
-     .                       "C est quoi ?")
-c
-      dims3(1) = idim_rlonv
-      dims3(2) = idim_rlatu
-      dims3(3) = idim_tim
-cIM 220306 BEG
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid,"ps",NF_DOUBLE,3,dims3,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid,"ps",NF_FLOAT,3,dims3,nvarid)
-#endif
-cIM 220306 END
-      ierr = NF_PUT_ATT_TEXT (nid, nvarid, "title", 15,
-     .                       "Pression au sol")
-c
-      ierr = NF_ENDDEF(nid) ! sortir du mode de definition
-      ierr = NF_CLOSE(nid) ! fermer le fichier
-
-      write(lunout,*)'dynredem_loc: iim,jjm,llm,iday_end',
-     &               iim,jjm,llm,iday_end
-      write(lunout,*)'dynredem_loc: rad,omeg,g,cpp,kappa',
-     &        rad,omeg,g,cpp,kappa
-
-      endif  ! mpi_rank==0
-      RETURN
-      END
-      SUBROUTINE dynredem1_loc(fichnom,time,
-     .                     vcov,ucov,teta,q,masse,ps)
-      USE parallel_lmdz
-      USE mod_hallo
-      USE infotrac
-      USE control_mod
-      USE dynredem_mod
-      IMPLICIT NONE
-c=================================================================
-c  Ecriture du fichier de redemarrage sous format NetCDF
-c=================================================================
-#include "dimensions.h"
-#include "paramet.h"
-#include "description.h"
-#include "netcdf.inc"
-#include "comvert.h"
-#include "comgeom.h"
-#include "temps.h"
-#include "iniprint.h"
-
-      INTEGER l
-      REAL vcov(ijb_v:ije_v,llm),ucov(ijb_u:ije_u,llm) 
-      REAL teta(ijb_u:ije_u,llm)                   
-      REAL ps(ijb_u:ije_u),masse(ijb_u:ije_u,llm)                   
-      REAL q(ijb_u:ije_u,llm,nqtot)
-      CHARACTER*(*) fichnom
-     
-      REAL time
-      INTEGER nid, nvarid, nid_trac, nvarid_trac
-      REAL trac_tmp(ijb_u:ije_u,llm)      
-      INTEGER ierr, ierr_file
-      INTEGER iq
-      INTEGER length
-      PARAMETER (length = 100)
-      REAL tab_cntrl(length) ! tableau des parametres du run
-      character*20 modname
-      character*80 abort_message
-c
-      INTEGER nb
-      SAVE nb
-      DATA nb / 0 /
-      REAL,SAVE,ALLOCATABLE :: ucov_glo(:,:),vcov_glo(:,:),teta_glo(:,:)
-      REAL,SAVE,ALLOCATABLE :: masse_glo(:,:),ps_glo(:),q_glo(:,:)
-      LOGICAL,SAVE :: exist_file
-      INTEGER,SAVE :: ierr_var
-      
-!      call Gather_Field(ucov,ip1jmp1,llm,0)
-!      call Gather_Field(vcov,ip1jm,llm,0)
-!      call Gather_Field(teta,ip1jmp1,llm,0)
-!      call Gather_Field(masse,ip1jmp1,llm,0)
-!      call Gather_Field(ps,ip1jmp1,1,0)
-      
-!      do iq=1,nqtot
-!        call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
- !     enddo
-      
-!$OMP MASTER      
-      if (mpi_rank==0) then
-      modname = 'dynredem1_loc'
-      ierr = NF_OPEN(fichnom, NF_WRITE, nid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*)"dynredem1: Pb. d ouverture "//trim(fichnom)
-         CALL abort_gcm("dynredem1", "", 1)
-      ENDIF
-
-c  Ecriture/extension de la coordonnee temps
-
-      nb = nb + 1
-      ierr = NF_INQ_VARID(nid, "temps", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         write(lunout,*) NF_STRERROR(ierr)
-         abort_message='Variable temps n est pas definie'
-         CALL abort_gcm(modname,abort_message,ierr)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR1_DOUBLE (nid,nvarid,nb,time)
-#else
-      ierr = NF_PUT_VAR1_REAL (nid,nvarid,nb,time)
-#endif
-      write(lunout,*) "dynredem1_loc: Enregistrement pour ", nb, time
-
-c
-c  Re-ecriture du tableau de controle, itaufin n'est plus defini quand
-c  on passe dans dynredem0
-      ierr = NF_INQ_VARID (nid, "controle", nvarid)
-      IF (ierr .NE. NF_NOERR) THEN
-         abort_message="dynredem1: Le champ <controle> est absent"
-         ierr = 1
-         CALL abort_gcm(modname,abort_message,ierr)
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tab_cntrl)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, tab_cntrl)
-#endif
-       tab_cntrl(31) =  REAL(itau_dyn + itaufin)
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,tab_cntrl)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,tab_cntrl)
-#endif
-      endif
-!$OMP END MASTER
-
-!     
-      CALL dynredem_write_u(nid,"ucov",ucov,llm)
-      CALL dynredem_write_v(nid,"vcov",vcov,llm)
-      CALL dynredem_write_u(nid,"teta",teta,llm)
-      CALL dynredem_write_u(nid,"masse",masse,llm)
-      CALL dynredem_write_u(nid,"ps",ps,1)
-
-      IF (type_trac /= 'inca') THEN
-        DO iq=1,nqtot
-          CALL dynredem_write_u(nid,tname(iq),q(:,:,iq),llm)
-        ENDDO
-      ELSE
-        
-!$OMP MASTER
-        INQUIRE(FILE="start_trac.nc", EXIST=exist_file) 
-        PRINT *, "EXIST", exist_file
-!$OMP END MASTER
-!$OMP BARRIER
-      
-        IF (exist_file) THEN
-!$OMP MASTER
-          ierr_file = NF_OPEN ("start_trac.nc", NF_NOWRITE,nid_trac)
-          IF (ierr_file .NE.NF_NOERR) THEN
-            WRITE(6,*)' Pb d''ouverture du fichier start_trac.nc'
-            WRITE(6,*)' ierr = ', ierr_file 
-          ENDIF
-!$OMP END MASTER
-
-          DO iq=1,nqtot
-
-!$OMP MASTER      
-            ierr_var = NF_INQ_VARID (nid_trac, tname(iq), nvarid_trac)
-!$OMP END MASTER
-!$OMP BARRIER
-            IF (ierr == NF_NOERR) THEN
-              CALL dynredem_read_u(nid_trac,tname(iq),q(:,:,iq),llm) 
-            ENDIF
-            CALL dynredem_write_u(nid,tname(iq),q(:,:,iq),llm)  
-          ENDDO          
-          
-        ELSE ! pas de fichier start_tract
-          DO iq=1,nqtot
-            CALL dynredem_write_u(nid,tname(iq),q(:,:,iq),llm)
-          ENDDO
-        ENDIF 
-      ENDIF
-
-
-!$OMP MASTER
-      IF (mpi_rank==0) THEN
-        ierr = NF_CLOSE(nid)
-      ENDIF ! mpi_rank==0
-!$OMP END MASTER
-      
-      RETURN
-      END
-
Index: /LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/dynredem_loc.F90	(revision 2408)
@@ -0,0 +1,269 @@
+SUBROUTINE dynredem0_loc(fichnom,iday_end,phis)
+!
+!-------------------------------------------------------------------------------
+! Write the NetCDF restart file (initialization).
+!-------------------------------------------------------------------------------
+#ifdef CPP_IOIPSL
+  USE IOIPSL
+#endif
+  USE parallel_lmdz
+  USE mod_hallo
+  USE infotrac
+  USE netcdf, ONLY: NF90_CREATE, NF90_DEF_DIM, NF90_INQ_VARID, NF90_GLOBAL,    &
+                    NF90_CLOSE,  NF90_PUT_ATT, NF90_UNLIMITED, NF90_CLOBBER
+  USE dynredem_mod, ONLY: cre_var, put_var, err, modname, fil
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comconst.h"
+  include "comvert.h"
+  include "comgeom.h"
+  include "temps.h"
+  include "ener.h"
+  include "logic.h"
+  include "description.h"
+  include "serre.h"
+  include "iniprint.h"
+!===============================================================================
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN) :: fichnom          !--- FILE NAME
+  INTEGER,          INTENT(IN) :: iday_end         !--- 
+  REAL,             INTENT(IN) :: phis(ijb_u:ije_u)!--- GROUND GEOPOTENTIAL
+!===============================================================================
+! Local variables:
+  INTEGER :: iq, l
+  INTEGER, PARAMETER :: length=100
+  REAL    :: tab_cntrl(length)                     !--- RUN PARAMETERS TABLE
+  REAL    :: phis_glo(ip1jmp1)
+!   For NetCDF:
+  CHARACTER(LEN=30) :: unites
+  INTEGER :: indexID
+  INTEGER :: rlonuID, rlonvID, rlatuID, rlatvID
+  INTEGER :: sID, sigID, nID, vID, timID
+  INTEGER :: yyears0, jjour0, mmois0
+  REAL    :: zan0, zjulian, hours
+!===============================================================================
+  modname='dynredem0'; fil=fichnom
+  CALL Gather_field_u(phis,phis_glo,1)
+  IF(mpi_rank/=0) RETURN
+
+#ifdef CPP_IOIPSL
+  CALL ymds2ju(annee_ref, 1, iday_end, 0.0, zjulian)
+  CALL ju2ymds(zjulian, yyears0, mmois0, jjour0, hours)
+#else
+! set yyears0, mmois0, jjour0 to 0,1,1 (hours is not used)
+  yyears0=0
+  mmois0=1
+  jjour0=1
+#endif        
+
+  tab_cntrl(:)  = 0.
+  tab_cntrl(1)  = REAL(iim)
+  tab_cntrl(2)  = REAL(jjm)
+  tab_cntrl(3)  = REAL(llm)
+  tab_cntrl(4)  = REAL(day_ref)
+  tab_cntrl(5)  = REAL(annee_ref)
+  tab_cntrl(6)  = rad
+  tab_cntrl(7)  = omeg
+  tab_cntrl(8)  = g
+  tab_cntrl(9)  = cpp
+  tab_cntrl(10) = kappa
+  tab_cntrl(11) = daysec
+  tab_cntrl(12) = dtvr
+  tab_cntrl(13) = etot0
+  tab_cntrl(14) = ptot0
+  tab_cntrl(15) = ztot0
+  tab_cntrl(16) = stot0
+  tab_cntrl(17) = ang0
+  tab_cntrl(18) = pa
+  tab_cntrl(19) = preff
+
+!    .....    parameters for zoom    ......   
+  tab_cntrl(20) = clon
+  tab_cntrl(21) = clat
+  tab_cntrl(22) = grossismx
+  tab_cntrl(23) = grossismy
+!
+  IF ( fxyhypb )   THEN
+    tab_cntrl(24) = 1.
+    tab_cntrl(25) = dzoomx
+    tab_cntrl(26) = dzoomy
+    tab_cntrl(27) = 0.
+    tab_cntrl(28) = taux
+    tab_cntrl(29) = tauy
+  ELSE
+    tab_cntrl(24) = 0.
+    tab_cntrl(25) = dzoomx
+    tab_cntrl(26) = dzoomy
+    tab_cntrl(27) = 0.
+    tab_cntrl(28) = 0.
+    tab_cntrl(29) = 0.
+    IF( ysinus )  tab_cntrl(27) = 1.
+  END IF
+  tab_cntrl(30) = REAL(iday_end)
+  tab_cntrl(31) = REAL(itau_dyn + itaufin)
+! start_time: start_time of simulation (not necessarily 0.)
+  tab_cntrl(32) = start_time
+
+!--- File creation
+  CALL err(NF90_CREATE(fichnom,NF90_CLOBBER,nid))
+
+!--- Some global attributes
+  CALL err(NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier demarrage dynamique"))
+
+!--- Dimensions
+  CALL err(NF90_DEF_DIM(nid,"index", length, indexID))
+  CALL err(NF90_DEF_DIM(nid,"rlonu", iip1,   rlonuID))
+  CALL err(NF90_DEF_DIM(nid,"rlatu", jjp1,   rlatuID))
+  CALL err(NF90_DEF_DIM(nid,"rlonv", iip1,   rlonvID))
+  CALL err(NF90_DEF_DIM(nid,"rlatv", jjm,    rlatvID))
+  CALL err(NF90_DEF_DIM(nid,"sigs",  llm,        sID))
+  CALL err(NF90_DEF_DIM(nid,"sig",   llmp1,    sigID))
+  CALL err(NF90_DEF_DIM(nid,"temps", NF90_UNLIMITED, timID))
+
+!--- Define and save invariant fields
+  CALL put_var(nid,"controle","Parametres de controle" ,[indexID],tab_cntrl)
+  CALL put_var(nid,"rlonu"   ,"Longitudes des points U",[rlonuID],rlonu)
+  CALL put_var(nid,"rlatu"   ,"Latitudes des points U" ,[rlatuID],rlatu)
+  CALL put_var(nid,"rlonv"   ,"Longitudes des points V",[rlonvID],rlonv)
+  CALL put_var(nid,"rlatv"   ,"Latitudes des points V" ,[rlatvID],rlatv)
+  CALL put_var(nid,"nivsigs" ,"Numero naturel des couches s"    ,[sID]  ,nivsigs)
+  CALL put_var(nid,"nivsig"  ,"Numero naturel des couches sigma",[sigID],nivsig)
+  CALL put_var(nid,"ap"      ,"Coefficient A pour hybride"      ,[sigID],ap)
+  CALL put_var(nid,"bp"      ,"Coefficient B pour hybride"      ,[sigID],bp)
+  CALL put_var(nid,"presnivs",""                                ,[sID]  ,presnivs)
+! covariant <-> contravariant <-> natural conversion coefficients
+  CALL put_var(nid,"cu","Coefficient de passage pour U",[rlonuID,rlatuID],cu)
+  CALL put_var(nid,"cv","Coefficient de passage pour V",[rlonvID,rlatvID],cv)
+  CALL put_var(nid,"aire","Aires de chaque maille"     ,[rlonvID,rlatuID],aire)
+  CALL put_var(nid,"phisinit","Geopotentiel au sol"    ,[rlonvID,rlatuID],phis_glo)
+
+!--- Define fields saved later
+  WRITE(unites,"('days since ',i4,'-',i2.2,'-',i2.2,' 00:00:00')"),&
+               yyears0,mmois0,jjour0
+  CALL cre_var(nid,"temps","Temps de simulation",[timID],unites)
+  CALL cre_var(nid,"ucov" ,"Vitesse U"  ,[rlonuID,rlatuID,sID,timID])
+  CALL cre_var(nid,"vcov" ,"Vitesse V"  ,[rlonvID,rlatvID,sID,timID])
+  CALL cre_var(nid,"teta" ,"Temperature",[rlonvID,rlatuID,sID,timID])
+  DO iq=1,nqtot
+    CALL cre_var(nid,tname(iq),ttext(iq),[rlonvID,rlatuID,sID,timID])
+  END DO
+  CALL cre_var(nid,"masse","Masse d air"    ,[rlonvID,rlatuID,sID,timID])
+  CALL cre_var(nid,"ps"   ,"Pression au sol",[rlonvID,rlatuID    ,timID])
+  CALL err(NF90_CLOSE (nid))
+
+  WRITE(lunout,*)TRIM(modname)//': iim,jjm,llm,iday_end',iim,jjm,llm,iday_end
+  WRITE(lunout,*)TRIM(modname)//': rad,omeg,g,cpp,kappa',rad,omeg,g,cpp,kappa
+
+END SUBROUTINE dynredem0_loc
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE dynredem1_loc(fichnom,time,vcov,ucov,teta,q,masse,ps)
+!
+!-------------------------------------------------------------------------------
+! Purpose: Write the NetCDF restart file (append).
+!-------------------------------------------------------------------------------
+  USE parallel_lmdz
+  USE mod_hallo
+  USE infotrac
+  USE control_mod
+  USE netcdf,   ONLY: NF90_OPEN,  NF90_NOWRITE, NF90_GET_VAR, NF90_INQ_VARID,  &
+                      NF90_CLOSE, NF90_WRITE,   NF90_PUT_VAR, NF90_NoErr
+  USE dynredem_mod, ONLY: dynredem_write_u, dynredem_write_v, dynredem_read_u, &
+                          err, modname, fil, msg
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "description.h"
+  include "comvert.h"
+  include "comgeom.h"
+  include "temps.h"
+  include "iniprint.h"
+!===============================================================================
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN) :: fichnom              !-- FILE NAME
+  REAL, INTENT(IN)    ::  time                         !-- TIME
+  REAL, INTENT(IN)    ::  vcov(ijb_v:ije_v,llm)        !-- V COVARIANT WIND
+  REAL, INTENT(IN)    ::  ucov(ijb_u:ije_u,llm)        !-- U COVARIANT WIND
+  REAL, INTENT(IN)    ::  teta(ijb_u:ije_u,llm)        !-- POTENTIAL TEMPERATURE
+  REAL, INTENT(INOUT) ::     q(ijb_u:ije_u,llm,nqtot)  !-- TRACERS
+  REAL, INTENT(IN)    :: masse(ijb_u:ije_u,llm)        !-- MASS PER CELL
+  REAL, INTENT(IN)    ::    ps(ijb_u:ije_u)            !-- GROUND PRESSURE
+!===============================================================================
+! Local variables:
+  INTEGER :: l, iq, nid, vID, ierr, nid_trac, vID_trac
+  INTEGER, SAVE :: nb=0
+  INTEGER, PARAMETER :: length=100
+  REAL               :: tab_cntrl(length) ! tableau des parametres du run
+  CHARACTER(LEN=256) :: var, dum
+  LOGICAL            :: lread_inca
+!===============================================================================
+
+!$OMP MASTER
+  IF(mpi_rank==0) THEN !++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  modname='dynredem1_loc'; fil=fichnom
+  fil=fichnom
+  CALL err(NF90_OPEN(fil,NF90_WRITE,nid),"open",fil)
+
+!--- Write/extend time coordinate
+  nb = nb + 1
+  var="temps"
+  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
+  CALL err(NF90_PUT_VAR(nid,vID,[time]),"put",var)
+  WRITE(lunout,*)TRIM(modname)//": Saving for ", nb, time
+
+!--- Rewrite control table (itaufin undefined in dynredem0)
+  var="controle"
+  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
+  CALL err(NF90_GET_VAR(nid,vID,tab_cntrl),"get",var)
+  tab_cntrl(31)=DBLE(itau_dyn + itaufin)
+  CALL err(NF90_INQ_VARID(nid,var,vID),"inq",var)
+  CALL err(NF90_PUT_VAR(nid,vID,tab_cntrl),"put",var)
+  END IF               !++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+!$OMP END MASTER
+
+!--- Save fields
+  CALL dynredem_write_u(nid,"ucov" ,ucov ,llm)
+  CALL dynredem_write_v(nid,"vcov" ,vcov ,llm)
+  CALL dynredem_write_u(nid,"teta" ,teta ,llm)
+  CALL dynredem_write_u(nid,"masse",masse,llm)
+  CALL dynredem_write_u(nid,"ps"   ,ps   ,1)
+
+!--- Tracers in file "start_trac.nc" (added by Anne)
+!$OMP MASTER
+  lread_inca=.FALSE.; fil="start_trac.nc"
+  IF(type_trac=='inca') INQUIRE(FILE=fil,EXIST=lread_inca)
+  IF(lread_inca) CALL err(NF90_OPEN(fil,NF90_NOWRITE,nid_trac),"open")
+!$OMP END MASTER
+!$OMP BARRIER
+
+!--- Save tracers
+  DO iq=1,nqtot; var=tname(iq); ierr=-1
+    IF(lread_inca) THEN                  !--- Possibly read from "start_trac.nc"
+!$OMP MASTER      
+      fil="start_trac.nc"
+      ierr=NF90_INQ_VARID(nid_trac,var,vID_trac)
+      dum='inq'; IF(ierr==NF90_NoErr) dum='fnd'
+      WRITE(lunout,*)msg(dum,var)
+!$OMP END MASTER
+!$OMP BARRIER
+      IF(ierr==NF90_NoErr) CALL dynredem_read_u(nid_trac,var,q(:,:,iq),llm)
+    END IF
+    fil=fichnom
+    CALL dynredem_write_u(nid,var,q(:,:,iq),llm)
+  END DO
+
+!$OMP MASTER
+  IF(mpi_rank==0) THEN !++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  CALL err(NF90_CLOSE(nid),"close")
+  fil="start_trac.nc"
+  IF(lread_inca) CALL err(NF90_CLOSE(nid_trac),"close")
+  END IF               !++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+!$OMP END MASTER
+
+END SUBROUTINE dynredem1_loc
+
Index: /LMDZ5/branches/testing/libf/dyn3dmem/dynredem_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/dynredem_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/dynredem_mod.F90	(revision 2408)
@@ -1,206 +1,276 @@
-!
-! $Id$
-!
 MODULE dynredem_mod
 
-CONTAINS
-
-  SUBROUTINE dynredem_write_u(ncid,id,var,ll)
   USE dimensions_mod
   USE parallel_lmdz
   USE mod_hallo
-  IMPLICIT NONE
-    INTEGER          :: ncid
-    CHARACTER(LEN=*) :: id
-    REAL             :: var(ijb_u:ije_u,ll)
-    REAL,ALLOCATABLE,SAVE  :: var_tmp(:,:)
-    REAL,ALLOCATABLE,SAVE  :: var_glo(:)
-    INTEGER          :: ll
-    INTEGER          :: count(4)
-    INTEGER          :: start(4)
-    INTEGER          :: l
-    INTEGER          :: nvarid
-    INTEGER          :: ierr
-    INCLUDE 'netcdf.inc'    
+  USE netcdf
+  PRIVATE
+  PUBLIC :: dynredem_write_u, dynredem_write_v, dynredem_read_u, err
+  PUBLIC :: cre_var, get_var1, put_var, fil, modname, msg
+  CHARACTER(LEN=256), SAVE :: fil, modname
+  INTEGER,            SAVE :: nvarid
+
+
+CONTAINS
+
+
+!===============================================================================
+!
+SUBROUTINE dynredem_write_u(ncid,id,var,ll)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,          INTENT(IN) :: ncid
+  CHARACTER(LEN=*), INTENT(IN) :: id
+  REAL,             INTENT(IN) :: var(ijb_u:ije_u,ll)
+  INTEGER,          INTENT(IN) :: ll
+!===============================================================================
+! Local variables:
+  REAL, ALLOCATABLE, SAVE :: var_tmp(:,:), var_glo(:)
+  INTEGER :: start(4), count(4), l, ierr
+!===============================================================================
+  start(:)=[1,1,1,1]; count(:)=[iip1,jjp1,1,1]
+
+!$OMP MASTER
+  IF(mpi_rank==0) CALL err(NF90_INQ_VARID(ncid,id,nvarid),"inq",id)
+!$OMP END MASTER
+
+!$OMP MASTER
+  ALLOCATE(var_tmp(ijb_u:ije_u,ll),var_glo(ip1jmp1))
+!$OMP END MASTER
+!$OMP BARRIER
+
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+  DO l=1,ll; var_tmp(:,l)=var(:,l); END DO
+  DO l=1,ll
+    CALL gather_field_u(var_tmp(:,l),var_glo,1)
+    IF(mpi_rank==0) THEN
+    !$OMP MASTER
+      start(3)=l
+      CALL err(NF90_PUT_VAR(ncid,nvarid,var_glo,start,count),"put",id)
+    !$OMP END MASTER
+    END IF
+  END DO
+!$OMP BARRIER
+!$OMP MASTER
+  DEALLOCATE(var_glo,var_tmp)
+!$OMP END MASTER
+!$OMP BARRIER
+  
+END SUBROUTINE dynredem_write_u
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+SUBROUTINE dynredem_write_v(ncid,id,var,ll)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,          INTENT(IN) :: ncid
+  CHARACTER(LEN=*), INTENT(IN) :: id
+  REAL,             INTENT(IN) :: var(ijb_v:ije_v,ll)
+  INTEGER,          INTENT(IN) :: ll
+!===============================================================================
+! Local variables:
+  REAL, ALLOCATABLE, SAVE :: var_tmp(:,:), var_glo(:)
+  INTEGER :: start(4), count(4), l, ierr
+!===============================================================================
+  start(:)=[1,1,1,1]; count(:)=[iip1,jjm,1,1]
+
+!$OMP MASTER
+  IF(mpi_rank==0) CALL err(NF90_INQ_VARID(ncid,id,nvarid),"inq",id)
+!$OMP END MASTER
+
+!$OMP MASTER
+  ALLOCATE(var_tmp(ijb_v:ije_v,ll),var_glo(ip1jm))
+!$OMP END MASTER
+!$OMP BARRIER
+
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+  DO l=1,ll; var_tmp(:,l)=var(:,l); END DO
+  DO l=1,ll
+    CALL gather_field_v(var_tmp(:,l),var_glo,1)
+    IF(mpi_rank==0) THEN
+    !$OMP MASTER
+      start(3)=l
+      CALL err(NF90_PUT_VAR(ncid,nvarid,var_glo,start,count),"put",id)
+    !$OMP END MASTER
+    END IF
+  END DO
+!$OMP BARRIER
+!$OMP MASTER
+  DEALLOCATE(var_glo,var_tmp)
+!$OMP END MASTER
+!$OMP BARRIER
+  
+END SUBROUTINE dynredem_write_v
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+SUBROUTINE dynredem_read_u(ncid,id,var,ll)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,          INTENT(IN)  :: ncid
+  CHARACTER(LEN=*), INTENT(IN)  :: id
+  REAL,             INTENT(OUT) :: var(ijb_u:ije_u,ll)
+  INTEGER,          INTENT(IN)  :: ll
+!===============================================================================
+! Local variables:
+  REAL, ALLOCATABLE, SAVE :: var_tmp(:,:), var_glo(:)
+  INTEGER :: start(4), count(4), l, ierr
+!===============================================================================
+  start(:)=[1,1,1,1]; count(:)=[iip1,jjp1,1,1]
+
+!$OMP MASTER
+  IF(mpi_rank==0) CALL err(NF90_INQ_VARID(ncid,id,nvarid),'inq',id)
+!$OMP END MASTER
+
+!$OMP MASTER
+  ALLOCATE(var_tmp(ijb_u:ije_u,ll),var_glo(ip1jmp1))
+!$OMP END MASTER
+!$OMP BARRIER
+
+  DO l=1,ll
+    IF(mpi_rank==0) THEN
+    !$OMP MASTER
+      start(3)=l
+      CALL err(NF90_GET_VAR(ncid,nvarid,var_glo,start,count),"get",id)
+    !$OMP END MASTER
+    END IF
+    CALL scatter_field_u(var_glo,var_tmp(:,l),1)
+  END DO
+
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+  DO l=1,ll; var(:,l)=var_tmp(:,l); END DO
     
-    count(:)=(/ iip1,jjp1,1,1 /)
-    start(:)=(/ 1,1,1,1 /)
-    
-!$OMP MASTER    
-   IF (mpi_rank==0) THEN
-     ierr = NF_INQ_VARID(ncid, id, nvarid)
-     IF (ierr .NE. NF_NOERR) THEN
-       PRINT*, "Variable "//id//" n est pas definie"
-       CALL abort
-     ENDIF
-   ENDIF
-!$OMP END MASTER
-
-!$OMP MASTER
-    ALLOCATE(var_tmp(ijb_u:ije_u,ll))
-    ALLOCATE(var_glo(ip1jmp1))
-!$OMP END MASTER
-!$OMP BARRIER
-
-!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-    DO l=1,ll
-      var_tmp(:,l)=var(:,l)
-    ENDDO
-
-    DO l=1,ll
-      CALL gather_field_u(var_tmp(:,l),var_glo,1)
-       IF (mpi_rank==0) THEN
-   !$OMP MASTER
-        start(3)=l
+!$OMP BARRIER
+!$OMP MASTER
+  DEALLOCATE(var_glo,var_tmp)
+!$OMP END MASTER
+!$OMP BARRIER
+  
+END SUBROUTINE dynredem_read_u    
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+SUBROUTINE cre_var(ncid,var,title,did,units)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,                    INTENT(IN) :: ncid
+  CHARACTER(LEN=*),           INTENT(IN) :: var, title
+  INTEGER,                    INTENT(IN) :: did(:)
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: units
+!===============================================================================
 #ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE (ncid,nvarid,start,count,var_glo)
+  CALL err(NF90_DEF_VAR(ncid,var,NF90_DOUBLE,did,nvarid),"inq",var)
 #else
-        ierr = NF_PUT_VARA_REAL (ncid,nvarid,start,count,var_glo)
+  CALL err(NF90_DEF_VAR(ncid,var,NF90_FLOAT ,did,nvarid),"inq",var)
 #endif
-   !$OMP END MASTER
-       ENDIF
-    ENDDO
-    
-  !$OMP BARRIER
-  !$OMP MASTER
-    DEALLOCATE(var_tmp)
-    DEALLOCATE(var_glo)
-  !$OMP END MASTER
-  !$OMP BARRIER
-  
-  END SUBROUTINE dynredem_write_u
-      
-  SUBROUTINE dynredem_write_v(ncid,id,var,ll)
-  USE dimensions_mod
-  USE parallel_lmdz
-  USE mod_hallo
-  IMPLICIT NONE
-    INTEGER          :: ncid
-    CHARACTER(LEN=*) :: id
-    REAL             :: var(ijb_v:ije_v,ll)
-    REAL,ALLOCATABLE,SAVE  :: var_tmp(:,:)
-    REAL,ALLOCATABLE,SAVE  :: var_glo(:)
-    INTEGER          :: ll
-    INTEGER          :: count(4)
-    INTEGER          :: start(4)
-    INTEGER          :: l
-    INTEGER          :: nvarid
-    INTEGER          :: ierr
-    INCLUDE 'netcdf.inc'    
-    
-    count(:)=(/ iip1,jjm,1,1 /)
-    start(:)=(/ 1,1,1,1 /)
-    
-!$OMP MASTER    
-   IF (mpi_rank==0) THEN
-     ierr = NF_INQ_VARID(ncid, id, nvarid)
-     IF (ierr .NE. NF_NOERR) THEN
-       PRINT*, "Variable "//id//" n est pas definie"
-       CALL abort
-     ENDIF
-   ENDIF
-!$OMP END MASTER
- 
-!$OMP MASTER
-    ALLOCATE(var_tmp(ijb_v:ije_v,ll))
-    ALLOCATE(var_glo(ip1jm))
-!$OMP END MASTER
-!$OMP BARRIER
-
-!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-    DO l=1,ll
-      var_tmp(:,l)=var(:,l)
-    ENDDO
-
-    DO l=1,ll
-      CALL gather_field_v(var_tmp(:,l),var_glo,1)
-       IF (mpi_rank==0) THEN
-   !$OMP MASTER
-        start(3)=l
-#ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE (ncid,nvarid,start,count,var_glo)
-#else
-        ierr = NF_PUT_VARA_REAL (ncid,nvarid,start,count,var_glo)
-#endif
-   !$OMP END MASTER
-       ENDIF
-    ENDDO
-    
-  !$OMP BARRIER
-  !$OMP MASTER
-    DEALLOCATE(var_tmp)
-    DEALLOCATE(var_glo)
-  !$OMP END MASTER
-  !$OMP BARRIER
-  
-  END SUBROUTINE dynredem_write_v
-
-  SUBROUTINE dynredem_read_u(ncid,id,var,ll)
-  USE dimensions_mod
-  USE parallel_lmdz
-  USE mod_hallo
-  IMPLICIT NONE
-    INTEGER          :: ncid
-    CHARACTER(LEN=*) :: id
-    REAL             :: var(ijb_u:ije_u,ll)
-    REAL,ALLOCATABLE,SAVE  :: var_tmp(:,:)
-    REAL,ALLOCATABLE,SAVE  :: var_glo(:)
-    INTEGER          :: ll
-    INTEGER          :: count(4)
-    INTEGER          :: start(4)
-    INTEGER          :: l
-    INTEGER          :: nvarid
-    INTEGER          :: ierr
-    INCLUDE 'netcdf.inc'    
-    
-    count(:)=(/ iip1,jjp1,1,1 /)
-    start(:)=(/ 1,1,1,1 /)
-    
-!$OMP MASTER    
-   IF (mpi_rank==0) THEN
-     ierr = NF_INQ_VARID(ncid, id, nvarid)
-     IF (ierr .NE. NF_NOERR) THEN
-       PRINT*, "Variable "//id//" n est pas definie"
-       CALL abort
-     ENDIF
-   ENDIF
-!$OMP END MASTER
- 
-!$OMP MASTER
-    ALLOCATE(var_tmp(ijb_u:ije_u,ll))
-    ALLOCATE(var_glo(ip1jmp1))
-!$OMP END MASTER
-!$OMP BARRIER
-
-
-    DO l=1,ll
-       IF (mpi_rank==0) THEN
-   !$OMP MASTER
-        start(3)=l
-#ifdef NC_DOUBLE
-        ierr = NF_GET_VARA_DOUBLE (ncid,nvarid,start,count,var_glo)
-#else
-        ierr = NF_GET_VARA_REAL (ncid,nvarid,start,count,var_glo)
-#endif
-   !$OMP END MASTER
-       ENDIF
-       CALL scatter_field_u(var_glo,var_tmp(:,l),1)
-    ENDDO
-
-!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-    DO l=1,ll
-      var(:,l)=var_tmp(:,l)
-    ENDDO
-    
-  !$OMP BARRIER
-  !$OMP MASTER
-    DEALLOCATE(var_tmp)
-    DEALLOCATE(var_glo)
-  !$OMP END MASTER
-  !$OMP BARRIER
-  
-  END SUBROUTINE dynredem_read_u    
-  
+  IF(title/="")      CALL err(NF90_PUT_ATT(ncid,nvarid,"title",title),var)
+  IF(PRESENT(units)) CALL err(NF90_PUT_ATT(ncid,nvarid,"units",units),var)
+
+END SUBROUTINE cre_var
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+SUBROUTINE put_var(ncid,var,title,did,v,units)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,                    INTENT(IN) :: ncid
+  CHARACTER(LEN=*),           INTENT(IN) :: var, title
+  INTEGER,                    INTENT(IN) :: did(:)
+  REAL,                       INTENT(IN) :: v(:)
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: units
+!===============================================================================
+  INTEGER :: nd, k, nn(2)
+  IF(     PRESENT(units)) CALL cre_var(ncid,var,title,did,units)
+  IF(.NOT.PRESENT(units)) CALL cre_var(ncid,var,title,did)
+  CALL err(NF90_ENDDEF(ncid))
+  nd=SIZE(did)
+  DO k=1,nd; CALL err(NF90_INQUIRE_DIMENSION(ncid,did(k),len=nn(k))); END DO
+  IF(nd==1) CALL err(NF90_PUT_VAR(ncid,nvarid,RESHAPE(v,nn(1:1))),var)
+  IF(nd==2) CALL err(NF90_PUT_VAR(ncid,nvarid,RESHAPE(v,nn(1:2))),var)
+  CALL err(NF90_REDEF(ncid))
+END SUBROUTINE put_var
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+FUNCTION msg(typ,nam)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  CHARACTER(LEN=256)                     :: msg    !--- STANDARDIZED MESSAGE
+  CHARACTER(LEN=*),           INTENT(IN) :: typ    !--- TYPE OF OPERATION
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: nam    !--- FIELD NAME
+!===============================================================================
+  SELECT CASE(typ)
+    CASE('open');  msg="Opening failed for <"//TRIM(fil)//">"
+    CASE('close'); msg="Closing failed for <"//TRIM(fil)//">"
+    CASE('get');   msg="Reading failed for <"//TRIM(nam)//">"
+    CASE('put');   msg="Writting failed for <"//TRIM(nam)//">"
+    CASE('inq');   msg="Missing field <"//TRIM(nam)//">"
+    CASE('fnd');   msg="Found field <"//TRIM(nam)//">"
+  END SELECT
+  msg=TRIM(msg)//" in file <"//TRIM(fil)//">"
+
+END FUNCTION msg
+!
+!===============================================================================
+
+
+!===============================================================================
+!
+SUBROUTINE err(ierr,typ,nam)
+!
+!===============================================================================
+  IMPLICIT NONE
+!===============================================================================
+! Arguments:
+  INTEGER,                    INTENT(IN) :: ierr   !--- NetCDF ERROR CODE
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: typ    !--- TYPE OF OPERATION
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: nam    !--- FIELD NAME
+!===============================================================================
+  IF(ierr==NF90_NoERR) RETURN
+  IF(.NOT.PRESENT(typ)) THEN
+    CALL ABORT_gcm(modname,NF90_STRERROR(ierr),ierr)
+  ELSE
+    CALL ABORT_gcm(modname,msg(typ,nam),ierr)
+  END IF
+
+END SUBROUTINE err
+!
+!===============================================================================
+
 END MODULE dynredem_mod   
+
     
     
Index: DZ5/branches/testing/libf/dyn3dmem/enercin_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/enercin_loc.F	(revision 2407)
+++ 	(revision )
@@ -1,122 +1,0 @@
-      SUBROUTINE enercin_loc ( vcov, ucov, vcont, ucont, ecin )
-      USE parallel_lmdz
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteur: P. Le Van
-c   -------
-c
-c   Objet:
-c   ------
-c
-c *********************************************************************
-c .. calcul de l'energie cinetique aux niveaux s  ......
-c *********************************************************************
-c  vcov, vcont, ucov et ucont sont des arguments d'entree pour le s-pg .
-c  ecin         est  un  argument de sortie pour le s-pg
-c
-c=======================================================================
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom.h"
-
-      REAL vcov( ijb_v:ije_v,llm ),vcont( ijb_v:ije_v,llm )
-      REAL ucov( ijb_u:ije_u,llm ),ucont( ijb_u:ije_u,llm )
-      REAL ecin( ijb_u:ije_u,llm )
-
-      REAL ecinni( iip1 ),ecinsi( iip1 )
-
-      REAL ecinpn, ecinps
-      INTEGER     l,ij,i,ijb,ije
-
-      EXTERNAL    SSUM
-      REAL        SSUM
-
-
-
-c                 . V
-c                i,j-1
-
-c      alpha4 .       . alpha1
-
-
-c        U .      . P     . U
-c       i-1,j    i,j      i,j
-
-c      alpha3 .       . alpha2
-
-
-c                 . V
-c                i,j
-
-c    
-c  L'energie cinetique au point scalaire P(i,j) ,autre que les poles, est :
-c       Ecin = 0.5 * U(i-1,j)**2 *( alpha3 + alpha4 )  +
-c              0.5 * U(i  ,j)**2 *( alpha1 + alpha2 )  +
-c              0.5 * V(i,j-1)**2 *( alpha1 + alpha4 )  +
-c              0.5 * V(i,  j)**2 *( alpha2 + alpha3 )
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-      DO 5 l = 1,llm
-      
-      ijb=ij_begin
-      ije=ij_end+iip1
-      
-      IF (pole_nord) ijb=ij_begin+iip1
-      IF (pole_sud)  ije=ij_end-iip1
-      
-      DO 1  ij = ijb, ije -1
-      ecin( ij+1, l )  =    0.5  *
-     * (   ucov( ij   ,l ) * ucont( ij   ,l ) * alpha3p4( ij +1 )   +
-     *     ucov( ij+1 ,l ) * ucont( ij+1 ,l ) * alpha1p2( ij +1 )   +
-     *     vcov(ij-iim,l ) * vcont(ij-iim,l ) * alpha1p4( ij +1 )   +
-     *     vcov( ij+ 1,l ) * vcont( ij+ 1,l ) * alpha2p3( ij +1 )   )
-   1  CONTINUE
-
-c    ... correction pour  ecin(1,j,l)  ....
-c    ...   ecin(1,j,l)= ecin(iip1,j,l) ...
-
-CDIR$ IVDEP
-      DO 2 ij = ijb, ije, iip1
-      ecin( ij,l ) = ecin( ij + iim, l )
-   2  CONTINUE
-
-c     calcul aux poles  .......
-
-      IF (pole_nord) THEN
-    
-        DO  i = 1, iim
-         ecinni(i) = vcov(    i  ,  l) * 
-     *               vcont(    i    ,l) * aire(   i   )
-        ENDDO
-
-        ecinpn = 0.5 * SSUM( iim,ecinni,1 ) / apoln
-
-        DO ij = 1,iip1
-          ecin(   ij     , l ) = ecinpn
-        ENDDO
-   
-      ENDIF
-
-      IF (pole_sud) THEN
-    
-        DO  i = 1, iim
-         ecinsi(i) = vcov(i+ip1jmi1,l)* 
-     *               vcont(i+ip1jmi1,l) * aire(i+ip1jm)
-        ENDDO
-
-        ecinps = 0.5 * SSUM( iim,ecinsi,1 ) / apols
-
-        DO ij = 1,iip1
-          ecin( ij+ ip1jm, l ) = ecinps
-        ENDDO
-   
-      ENDIF
-
-      
-   5  CONTINUE
-c$OMP END DO NOWAIT
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3dmem/enercin_loc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/enercin_loc.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/enercin_loc.F90	(revision 2408)
@@ -0,0 +1,84 @@
+SUBROUTINE enercin_loc ( vcov, ucov, vcont, ucont, ecin )
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van.
+!-------------------------------------------------------------------------------
+! Purpose: Compute kinetic energy at sigma levels.
+  USE parallel_lmdz
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: vcov    (ijb_v:ije_v,llm)
+  REAL, INTENT(IN)  :: ucov    (ijb_u:ije_u,llm)
+  REAL, INTENT(IN)  :: vcont   (ijb_v:ije_v,llm)
+  REAL, INTENT(IN)  :: ucont   (ijb_u:ije_u,llm)
+  REAL, INTENT(OUT) :: ecin    (ijb_u:ije_u,llm)
+!===============================================================================
+! Notes:
+!                 . V
+!                i,j-1
+!
+!      alpha4 .       . alpha1
+!
+!
+!        U .      . P     . U
+!       i-1,j    i,j      i,j
+!
+!      alpha3 .       . alpha2
+!
+!
+!                 . V
+!                i,j
+!
+! Kinetic energy at scalar point P(i,j) (excluding poles) is:
+!       Ecin = 0.5 * U(i-1,j)**2 *( alpha3 + alpha4 )  +
+!              0.5 * U(i  ,j)**2 *( alpha1 + alpha2 )  +
+!              0.5 * V(i,j-1)**2 *( alpha1 + alpha4 )  +
+!              0.5 * V(i,  j)**2 *( alpha2 + alpha3 )
+!===============================================================================
+! Local variables:
+  INTEGER :: l, ij, i, ijb, ije
+  REAL    :: ecinni(iim), ecinsi(iim), ecinpn, ecinps
+!===============================================================================
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+  DO l=1,llm
+
+    ijb=ij_begin
+    ije=ij_end+iip1
+
+    IF(pole_nord) ijb=ij_begin+iip1
+    IF(pole_sud)  ije=ij_end-iip1
+
+    DO ij = ijb,ije-1
+      ecin(ij+1,l)=0.5*(ucov(ij    ,l)*ucont(ij    ,l)*alpha3p4(ij +1)          &
+                      + ucov(ij+1  ,l)*ucont(ij+1  ,l)*alpha1p2(ij +1)          &
+                      + vcov(ij-iim,l)*vcont(ij-iim,l)*alpha1p4(ij +1)          &
+                      + vcov(ij+1  ,l)*vcont(ij+1  ,l)*alpha2p3(ij +1) )
+    END DO
+
+    !--- Correction: ecin(1,j,l)= ecin(iip1,j,l)
+    DO ij=ijb,ije,iip1; ecin(ij,l) = ecin(ij+iim,l); END DO
+
+    !--- North pole
+    IF(pole_nord) THEN
+      ecinni(:) = vcov(1:iim,l)*vcont(1:iim,l)*aire(1:iim)
+      ecinpn = 0.5*SUM(ecinni)/apoln
+      ecin(1:iip1,l)=ecinpn
+    END IF
+
+    !--- South pole
+    IF(pole_sud) THEN
+      DO i=1,iim
+        ecinsi(i) = vcov(i+ip1jmi1,l)*vcont(i+ip1jmi1,l)*aire(i+ip1jm)
+      END DO
+      ecinps = 0.5*SUM(ecinsi)/apols
+      ecin(1+ip1jm:ip1jmp1,l)=ecinps
+    END IF
+  END DO
+!$OMP END DO NOWAIT
+
+END SUBROUTINE enercin_loc
+
Index: DZ5/branches/testing/libf/dyn3dmem/flumass_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/flumass_loc.F	(revision 2407)
+++ 	(revision )
@@ -1,152 +1,0 @@
-      SUBROUTINE flumass_loc(massebx,masseby,vcont,ucont,pbaru,pbarv)
-      USE parallel_lmdz
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteurs:  P. Le Van, F. Hourdin  .
-c   -------
-c
-c   Objet:
-c   ------
-c
-c *********************************************************************
-c     .... calcul du flux de masse  aux niveaux s ......
-c *********************************************************************
-c   massebx,masseby,vcont et ucont sont des argum. d'entree pour le s-pg .
-c       pbaru  et pbarv            sont des argum.de sortie pour le s-pg .
-c
-c=======================================================================
-
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom.h"
-
-      REAL massebx( ijb_u:ije_u,llm ),masseby( ijb_v:ije_v,llm ) ,
-     * vcont( ijb_v:ije_v,llm ),ucont( ijb_u:ije_u,llm ),
-     * pbaru( ijb_u:ije_u,llm ),pbarv( ijb_v:ije_v,llm )
-
-      REAL apbarun( iip1 ),apbarus( iip1 )
-
-      REAL sairen,saireun,saires,saireus,ctn,cts,ctn0,cts0
-      INTEGER  l,ij,i
-      INTEGER ijb,ije
-      
-      EXTERNAL   SSUM
-      REAL       SSUM
-      
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)    
-      DO  5 l = 1,llm
-
-        ijb=ij_begin
-        ije=ij_end+iip1
-      
-        if (pole_nord) ijb=ij_begin+iip1
-        if (pole_sud)  ije=ij_end-iip1
-        
-        DO  1 ij = ijb,ije
-          pbaru( ij,l ) = massebx( ij,l ) * ucont( ij,l )
-   1    CONTINUE
-
-        ijb=ij_begin-iip1
-        ije=ij_end+iip1
-      
-        if (pole_nord) ijb=ij_begin
-        if (pole_sud)  ije=ij_end-iip1
-        
-        DO 3 ij = ijb,ije
-          pbarv( ij,l ) = masseby( ij,l ) * vcont( ij,l )
-   3    CONTINUE
-
-   5  CONTINUE
-c$OMP END DO NOWAIT
-c    ................................................................
-c     calcul de la composante du flux de masse en x aux poles .......
-c    ................................................................
-c     par la resolution d'1 systeme de 2 equations .
-
-c     la premiere equat.decrivant le calcul de la divergence en 1 point i
-c     du pole,ce calcul etant itere de i=1 a i=im .
-c                 c.a.d   ,
-c     ( ( 0.5*pbaru(i)-0.5*pbaru(i-1) - pbarv(i))/aire(i)   =
-c                                           - somme de ( pbarv(n) )/aire pole
-
-c     l'autre equat.specifiant que la moyenne du flux de masse au pole est =0.
-c     c.a.d    somme de pbaru(n)*aire locale(n) = 0.
-
-c     on en revient ainsi a determiner la constante additive commune aux pbaru
-c     qui representait pbaru(0,j,l) dans l'equat.du calcul de la diverg.au pt
-c     i=1 .
-c     i variant de 1 a im
-c     n variant de 1 a im
-
-      IF (pole_nord) THEN
-     
-        sairen = SSUM( iim,  aire(   1     ), 1 )
-        saireun= SSUM( iim, aireu(   1     ), 1 )
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)    
-        DO l = 1,llm
- 
-          ctn =  SSUM( iim, pbarv(    1     ,l),  1 )/ sairen
-      
-          pbaru(1,l)=pbarv(1,l) - ctn * aire(1)
-        
-          DO i = 2,iim
-            pbaru(i,l) = pbaru(i- 1,l )    +
-     *                   pbarv(i,l) - ctn * aire(i )
-          ENDDO
-        
-          DO i = 1,iim
-            apbarun(i) = aireu(    i   ) * pbaru(   i    , l)
-          ENDDO
-      
-          ctn0 = -SSUM( iim,apbarun,1 )/saireun
-        
-          DO i = 1,iim
-            pbaru(   i    , l) = 2. * ( pbaru(   i    , l) + ctn0 )
-          ENDDO
-       
-          pbaru(   iip1 ,l ) = pbaru(    1    ,l )
-        
-        ENDDO
-c$OMP END DO NOWAIT              
-
-      ENDIF
-
-      
-      IF (pole_sud) THEN
-  
-        saires = SSUM( iim,  aire( ip1jm+1 ), 1 )
-        saireus= SSUM( iim, aireu( ip1jm+1 ), 1 )
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)    
-        DO  l = 1,llm
- 
-          cts =  SSUM( iim, pbarv(ip1jmi1+ 1,l),  1 )/ saires
-          pbaru(ip1jm+1,l)= - pbarv(ip1jmi1+1,l) + cts * aire(ip1jm+1)
-   
-          DO i = 2,iim
-            pbaru(i+ ip1jm,l) = pbaru(i+ip1jm-1,l)    -
-     *                          pbarv(i+ip1jmi1,l)+cts*aire(i+ip1jm)
-          ENDDO
-        
-          DO i = 1,iim
-            apbarus(i) = aireu(i +ip1jm) * pbaru(i +ip1jm, l)
-          ENDDO
-
-          cts0 = -SSUM( iim,apbarus,1 )/saireus
-
-          DO i = 1,iim
-            pbaru(i+ ip1jm, l) = 2. * ( pbaru(i +ip1jm, l) + cts0 )
-          ENDDO
-
-          pbaru( ip1jmp1,l ) = pbaru( ip1jm +1,l )
-       
-        ENDDO
-c$OMP END DO NOWAIT         
-      ENDIF
-      
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3dmem/flumass_loc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/flumass_loc.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/flumass_loc.F90	(revision 2408)
@@ -0,0 +1,91 @@
+SUBROUTINE flumass_loc(massebx,masseby, vcont, ucont, pbaru, pbarv )
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute mass flux at s levels.
+  USE parallel_lmdz
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: massebx(ijb_u:ije_u,llm)
+  REAL, INTENT(IN)  :: masseby(ijb_v:ije_v,llm)
+  REAL, INTENT(IN)  :: vcont  (ijb_v:ije_v,llm)
+  REAL, INTENT(IN)  :: ucont  (ijb_u:ije_u,llm)
+  REAL, INTENT(OUT) :: pbaru  (ijb_u:ije_u,llm)
+  REAL, INTENT(OUT) :: pbarv  (ijb_v:ije_v,llm)
+!===============================================================================
+! Method used:   A 2 equations system is solved.
+!   * 1st one describes divergence computation at pole point nr. i (i=1 to im):
+!     (0.5*(pbaru(i)-pbaru(i-1))-pbarv(i))/aire(i) = - SUM(pbarv(n))/aire pole
+!   * 2nd one specifies that mean mass flux at pole is equal to 0:
+!     SUM(pbaru(n)*local_area(n))=0
+! This way, we determine additive constant common to pbary elements representing
+!   pbaru(0,j,l) in divergence computation equation for point i=1. (i=1 to im)
+!===============================================================================
+! Local variables:
+  REAL    :: sairen, saireun, ctn, ctn0, apbarun(iim)
+  REAL    :: saires, saireus, cts, cts0, apbarus(iim)
+  INTEGER :: l, i, ij, ijb, ije
+!===============================================================================
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)    
+  DO l=1,llm
+
+    ijb=ij_begin
+    ije=ij_end+iip1
+    IF(pole_nord) ijb=ij_begin+iip1
+    IF(pole_sud)  ije=ij_end-iip1
+    pbaru(ijb:ije,l)=massebx(ijb:ije,l)*ucont(ijb:ije,l)
+
+    ijb=ij_begin-iip1
+    ije=ij_end+iip1
+    IF(pole_nord) ijb=ij_begin
+    IF(pole_sud)  ije=ij_end-iip1
+    pbarv(ijb:ije,l)=masseby(ijb:ije,l)*vcont(ijb:ije,l)
+
+  END DO
+!$OMP END DO NOWAIT
+
+  !--- North pole
+  IF(pole_nord) THEN
+    sairen =SUM(aire (1:iim))
+    saireun=SUM(aireu(1:iim))
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)    
+    DO l=1,llm
+      ctn=SUM(pbarv(1:iim,l))/sairen
+      pbaru(1,l)= pbarv(1,l)-ctn*aire(1)
+      DO i=2,iim
+        pbaru(i,l)=pbaru(i-1,l)+pbarv(i,l)-ctn*aire(i)
+      END DO
+      apbarun(:)=aireu(1:iim)*pbaru(1:iim,l)
+      ctn0 = -SUM(apbarun)/saireun
+      pbaru(1:iim,l)=2.*(pbaru(1:iim,l)+ctn0)
+      pbaru(iip1,l)=pbaru(1,l)
+    END DO
+!$OMP END DO NOWAIT              
+  END IF
+
+  !--- South pole
+  IF(pole_sud) THEN
+    saires =SUM(aire (ip1jm+1:ip1jmp1-1))
+    saireus=SUM(aireu(ip1jm+1:ip1jmp1-1))
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)    
+    DO l=1,llm
+      cts=SUM(pbarv(1+ip1jmi1:ip1jm-1,l))/saires
+      pbaru(1+ip1jm,l)=-pbarv(1+ip1jmi1,l)+cts*aire(1+ip1jm)
+      DO i=2,iim
+        pbaru(i+ip1jm,l)=pbaru(i-1+ip1jm,l)-pbarv(i+ip1jmi1,l)+cts*aire(i+ip1jm)
+      END DO
+      apbarus(:)=aireu(1+ip1jm:ip1jmp1-1)*pbaru(1+ip1jm:ip1jmp1-1,l)
+      cts0 = -SUM(apbarus)/saireus
+      pbaru(1+ip1jm:ip1jmp1-1,l)=2.*(pbaru(1+ip1jm:ip1jmp1-1,l)+cts0)
+      pbaru(ip1jmp1,l)=pbaru(1+ip1jm,l)
+    END DO
+!$OMP END DO NOWAIT         
+  END IF
+
+END SUBROUTINE flumass_loc
+
Index: /LMDZ5/branches/testing/libf/dyn3dmem/gcm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/gcm.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/gcm.F90	(revision 2408)
@@ -10,7 +10,7 @@
   USE parallel_lmdz
   USE infotrac
-#ifdef CPP_PHYS
-  USE mod_interface_dyn_phys, ONLY: init_interface_dyn_phys
-#endif
+!#ifdef CPP_PHYS
+!  USE mod_interface_dyn_phys, ONLY: init_interface_dyn_phys
+!#endif
   USE mod_hallo
   USE Bands
@@ -18,15 +18,6 @@
   USE control_mod
 
-#ifdef INCA
-  ! Only INCA needs these informations (from the Earth's physics)
-  USE indice_sol_mod
-  USE mod_phys_lmdz_omp_data, ONLY: klon_omp 
-#endif
-
 #ifdef CPP_PHYS
-  !      USE mod_grid_phy_lmdz
-  !      USE mod_phys_lmdz_para, ONLY : klon_mpi_para_nb
-  !      USE dimphy
-  !      USE comgeomphy
+  USE iniphysiq_mod, ONLY: iniphysiq
 #endif
   IMPLICIT NONE
@@ -76,8 +67,4 @@
   include "tracstoke.h"
 
-#ifdef INCA
-  ! Only INCA needs these informations (from the Earth's physics)
-  !include "indicesol.h"
-#endif
 
   REAL zdtvr
@@ -155,11 +142,11 @@
   call Read_Distrib
 
-#ifdef CPP_PHYS
-  CALL Init_Phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
+!#ifdef CPP_PHYS
+!  CALL Init_Phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
   !#endif
   !      CALL set_bands
   !#ifdef CPP_PHYS
-  CALL Init_interface_dyn_phys
-#endif
+!  CALL Init_interface_dyn_phys
+!#endif
   CALL barrier
 
@@ -200,17 +187,4 @@
 #endif
 
-  IF (type_trac == 'inca') THEN
-#ifdef INCA
-     call init_const_lmdz( &
-          nbtr,anneeref,dayref, &
-          iphysiq,day_step,nday,  &
-          nbsrf, is_oce,is_sic, &
-          is_ter,is_lic, calend)
-
-     call init_inca_para( &
-          iim,jjm+1,llm,klon_glo,mpi_size, &
-          distrib_phys,COMM_LMDZ)
-#endif
-  END IF
 
   !-----------------------------------------------------------------------
@@ -400,22 +374,12 @@
      ! Physics:
 #ifdef CPP_PHYS
-     CALL iniphysiq(iim,jjm,llm,daysec,day_ini,dtphys/nsplit_phys, &
-          rlatu,rlonv,aire,cu,cv,rad,g,r,cpp, &
+     CALL iniphysiq(iim,jjm,llm, &
+          distrib_phys(mpi_rank),comm_lmdz, &
+          daysec,day_ini,dtphys/nsplit_phys, &
+          rlatu,rlatv,rlonu,rlonv,aire,cu,cv,rad,g,r,cpp, &
           iflag_phys)
 #endif
   ENDIF ! of IF ((iflag_phys==1).or.(iflag_phys>=100))
 
-
-  !-----------------------------------------------------------------------
-  !   Initialisation des dimensions d'INCA :
-  !   --------------------------------------
-  IF (type_trac == 'inca') THEN
-     !$OMP PARALLEL
-#ifdef INCA
-     CALL init_inca_dim(klon_omp,llm,iim,jjm, &
-          rlonu,rlatu,rlonv,rlatv)
-#endif
-     !$OMP END PARALLEL
-  END IF
 
   !-----------------------------------------------------------------------
Index: /LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F	(revision 2408)
@@ -308,9 +308,12 @@
 
    1  CONTINUE ! Matsuno Forward step begins here
-      !write(*,*) 'leapfrog 298: itau=',itau
+
+c   date: (NB: date remains unchanged for Backward step)
+c   -----
+
       jD_cur = jD_ref + day_ini - day_ref +                             &
-     &          itau/day_step
+     &          (itau+1)/day_step
       jH_cur = jH_ref + start_time +                                    &
-     &         mod(itau,day_step)/float(day_step) 
+     &         mod(itau+1,day_step)/float(day_step) 
       if (jH_cur > 1.0 ) then
         jD_cur = jD_cur +1.
@@ -421,7 +424,17 @@
 c-----------------------------------------------------------------------
 
-c   date:
+c   date: (NB: only leapfrog step requires recomputing date)
 c   -----
 
+      IF (leapf) THEN
+        jD_cur = jD_ref + day_ini - day_ref +
+     &          (itau+1)/day_step
+        jH_cur = jH_ref + start_time +
+     &         mod(itau+1,day_step)/float(day_step) 
+        if (jH_cur > 1.0 ) then
+          jD_cur = jD_cur +1.
+          jH_cur = jH_cur -1.
+        endif
+      ENDIF
 
 c   gestion des appels de la physique et des dissipations:
Index: DZ5/branches/testing/libf/dyn3dmem/massbar_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/massbar_loc.F	(revision 2407)
+++ 	(revision )
@@ -1,117 +1,0 @@
-      SUBROUTINE massbar_loc(  masse, massebx, masseby )
-     
-c
-c **********************************************************************
-c
-c  Calcule les moyennes en x et  y de la masse d'air dans chaque maille.
-c **********************************************************************
-c    Auteurs : P. Le Van , Fr. Hourdin  .
-c   ..........
-c
-c  ..  masse                 est  un argum. d'entree  pour le s-pg ...
-c  ..  massebx,masseby      sont des argum. de sortie pour le s-pg ...
-c     
-c
-      USE parallel_lmdz
-      IMPLICIT NONE
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom.h"
-c
-      REAL    masse( ijb_u:ije_u,llm ), massebx( ijb_u:ije_u,llm )  ,
-     *      masseby(   ijb_v:ije_v,llm )
-      INTEGER ij,l,ijb,ije
-c
-c
-c   Methode pour calculer massebx et masseby .
-c   ----------------------------------------
-c
-c    A chaque point scalaire P (i,j) est affecte 4 coefficients d'aires
-c       alpha1(i,j)  calcule  au point ( i+1/4,j-1/4 )
-c       alpha2(i,j)  calcule  au point ( i+1/4,j+1/4 )
-c       alpha3(i,j)  calcule  au point ( i-1/4,j+1/4 )
-c       alpha4(i,j)  calcule  au point ( i-1/4,j-1/4 )
-c
-c    Avec  alpha1(i,j) = aire(i+1/4,j-1/4)/ aire(i,j)        
-c
-c    N.B .  Pour plus de details, voir s-pg  ...  iniconst ...
-c
-c
-c
-c   alpha4 .         . alpha1    . alpha4
-c    (i,j)             (i,j)       (i+1,j)
-c
-c             P .        U .          . P
-c           (i,j)       (i,j)         (i+1,j)
-c
-c   alpha3 .         . alpha2    .alpha3 
-c    (i,j)              (i,j)     (i+1,j)
-c
-c             V .        Z .          . V
-c           (i,j)
-c
-c   alpha4 .         . alpha1    .alpha4
-c   (i,j+1)            (i,j+1)   (i+1,j+1) 
-c
-c             P .        U .          . P
-c          (i,j+1)                    (i+1,j+1)
-c
-c
-c
-c                       On  a :
-c
-c    massebx(i,j) = masse(i  ,j) * ( alpha1(i  ,j) + alpha2(i,j))   +
-c                   masse(i+1,j) * ( alpha3(i+1,j) + alpha4(i+1,j) )
-c     localise  au point  ... U (i,j) ...
-c
-c    masseby(i,j) = masse(i,j  ) * ( alpha2(i,j  ) + alpha3(i,j  )  +
-c                   masse(i,j+1) * ( alpha1(i,j+1) + alpha4(i,j+1)  
-c     localise  au point  ... V (i,j) ...
-c
-c
-c=======================================================================
-      
-      
-      
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)  
-      DO   100    l = 1 , llm
-c
-        ijb=ij_begin
-        ije=ij_end+iip1
-        if (pole_sud) ije=ije-iip1
-        
-        DO  ij = ijb, ije - 1
-         massebx(ij,l) =  masse( ij, l) * alpha1p2( ij  )     + 
-     *                   masse(ij+1, l) * alpha3p4(ij+1 )
-        ENDDO
-
-c    .... correction pour massebx( iip1,j) .....
-c    ...    massebx(iip1,j)= massebx(1,j) ...
-c
-CDIR$ IVDEP
-
-        
-
-        DO  ij = ijb+iim, ije+iim, iip1
-         massebx( ij,l ) = massebx( ij - iim,l )
-        ENDDO
-
-
-      
-        ijb=ij_begin-iip1
-        ije=ij_end+iip1
-        if (pole_nord) ijb=ij_begin
-        if (pole_sud) ije=ij_end-iip1
-
-         DO  ij = ijb,ije
-         masseby( ij,l ) = masse(  ij   , l ) * alpha2p3(   ij    )  +
-     *                     masse(ij+iip1, l ) * alpha1p4( ij+iip1 )
-         ENDDO
-
-100   CONTINUE
-c$OMP END DO NOWAIT
-c
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3dmem/massbar_loc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/massbar_loc.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/massbar_loc.F90	(revision 2408)
@@ -0,0 +1,76 @@
+SUBROUTINE massbar_loc(masse,massebx,masseby)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute air mass mean along X and Y in each cell.
+! See iniconst for more details.
+  USE parallel_lmdz
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: masse  (ijb_u:ije_u,llm)
+  REAL, INTENT(OUT) :: massebx(ijb_u:ije_u,llm)
+  REAL, INTENT(OUT) :: masseby(ijb_v:ije_v,llm)
+!-------------------------------------------------------------------------------
+! Method used. Each scalar point is associated to 4 area coefficients:
+!    * alpha1(i,j) at point ( i+1/4,j-1/4 )
+!    * alpha2(i,j) at point ( i+1/4,j+1/4 )
+!    * alpha3(i,j) at point ( i-1/4,j+1/4 )
+!    * alpha4(i,j) at point ( i-1/4,j-1/4 )
+! where alpha1(i,j) = aire(i+1/4,j-1/4)/ aire(i,j)
+!
+!   alpha4 .         . alpha1    . alpha4
+!    (i,j)             (i,j)       (i+1,j)
+!
+!             P .        U .          . P
+!           (i,j)       (i,j)         (i+1,j)
+!
+!   alpha3 .         . alpha2    .alpha3 
+!    (i,j)              (i,j)     (i+1,j)
+!
+!             V .        Z .          . V
+!           (i,j)
+!
+!   alpha4 .         . alpha1    .alpha4
+!   (i,j+1)            (i,j+1)   (i+1,j+1) 
+!
+!             P .        U .          . P
+!          (i,j+1)                    (i+1,j+1)
+!
+!
+!    massebx(i,j) = masse(i  ,j) * ( alpha1(i  ,j) + alpha2(i,j))   +
+!                   masse(i+1,j) * ( alpha3(i+1,j) + alpha4(i+1,j) )
+!     localized at point  ... U (i,j) ...
+!
+!    masseby(i,j) = masse(i,j  ) * ( alpha2(i,j  ) + alpha3(i,j  )  +
+!                   masse(i,j+1) * ( alpha1(i,j+1) + alpha4(i,j+1)  
+!     localized at point  ... V (i,j) ...
+!===============================================================================
+! Local variables:
+  INTEGER :: ij, l, ijb, ije
+!===============================================================================
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)  
+  DO l=1,llm
+    ijb=ij_begin
+    ije=ij_end+iip1
+    IF(pole_sud) ije=ije-iip1
+    DO ij=ijb,ije-1
+      massebx(ij,l)=masse(ij,l)*alpha1p2(ij)+masse(ij+1   ,l)*alpha3p4(ij+1)
+    END DO
+    DO ij=ijb+iim,ije+iim,iip1; massebx(ij,l)=massebx(ij-iim,l); END DO
+    ijb=ij_begin-iip1
+    ije=ij_end+iip1
+    IF(pole_nord) ijb=ij_begin
+    IF(pole_sud) ije=ij_end-iip1
+    DO ij=ijb,ije
+      masseby(ij,l)=masse(ij,l)*alpha2p3(ij)+masse(ij+iip1,l)*alpha1p4(ij+iip1)
+    END DO
+  END DO
+!$OMP END DO NOWAIT
+
+END SUBROUTINE massbar_loc
+
Index: DZ5/branches/testing/libf/dyn3dmem/massbarxy_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/massbarxy_loc.F	(revision 2407)
+++ 	(revision )
@@ -1,55 +1,0 @@
-      SUBROUTINE massbarxy_loc(  masse, massebxy )
-      USE parallel_lmdz
-      implicit none
-c **********************************************************************
-c
-c  Calcule les moyennes en x et  y de la masse d'air dans chaque maille.
-c **********************************************************************
-c    Auteurs : P. Le Van , Fr. Hourdin  .
-c   ..........
-c
-c  ..  masse          est  un  argum. d'entree  pour le s-pg ...
-c  ..  massebxy       est  un  argum. de sortie pour le s-pg ...
-c     
-c
-c     IMPLICIT NONE
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comconst.h"
-#include "comgeom.h"
-c
-       REAL  masse( ijb_u:ije_u,llm ), massebxy( ijb_v:ije_v,llm )
-c
-      INTEGER ij,l,ijb,ije
-
-      
-      ijb=ij_begin-iip1
-      ije=ij_end
-      
-      if (pole_nord) ijb=ijb+iip1
-      if (pole_sud)  ije=ije-iip1
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)    
-      DO   100    l = 1 , llm
-c
-      DO 5 ij = ijb, ije - 1
-      massebxy( ij,l ) = masse(    ij  ,l ) * alpha2(   ij    )   +
-     +                   masse(   ij+1 ,l ) * alpha3(  ij+1   )   +
-     +                   masse( ij+iip1,l ) * alpha1( ij+iip1 )   +
-     +                   masse( ij+iip2,l ) * alpha4( ij+iip2 )
-   5  CONTINUE
-
-c    ....  correction pour     massebxy( iip1,j )  ........
-
-CDIR$ IVDEP
-
-      DO 7 ij = ijb+iip1-1, ije+iip1-1, iip1
-      massebxy( ij,l ) = massebxy( ij - iim,l )
-   7  CONTINUE
-
-100   CONTINUE
-c$OMP END DO NOWAIT
-c
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3dmem/massbarxy_loc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/massbarxy_loc.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/massbarxy_loc.F90	(revision 2408)
@@ -0,0 +1,39 @@
+SUBROUTINE massbarxy_loc(masse,massebxy)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute air mass mean along X and Y in each cell.
+! See iniconst for more details.
+  USE parallel_lmdz
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comconst.h"
+  include "comgeom.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: masse   (ijb_u:ije_u,llm)
+  REAL, INTENT(OUT) :: massebxy(ijb_v:ije_v,llm)
+!===============================================================================
+! Local variables:
+  INTEGER :: ij, l, ijb, ije
+!===============================================================================
+  ijb=ij_begin-iip1
+  ije=ij_end
+  IF(pole_nord) ijb=ijb+iip1
+  IF(pole_sud)  ije=ije-iip1
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)    
+  DO l=1,llm
+    DO ij=ijb,ije-1
+      massebxy(ij,l)=masse(ij     ,l)*alpha2(ij     ) + &
+     +               masse(ij+1   ,l)*alpha3(ij+1   ) + &
+     +               masse(ij+iip1,l)*alpha1(ij+iip1) + &
+     +               masse(ij+iip2,l)*alpha4(ij+iip2)
+    END DO
+    DO ij=ijb+iip1-1,ije+iip1-1,iip1; massebxy(ij,l)=massebxy(ij-iim,l); END DO
+  END DO
+!$OMP END DO NOWAIT
+
+END SUBROUTINE massbarxy_loc
+
Index: DZ5/branches/testing/libf/dyn3dmem/tourpot_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/tourpot_loc.F	(revision 2407)
+++ 	(revision )
@@ -1,95 +1,0 @@
-      SUBROUTINE tourpot_loc ( vcov, ucov, massebxy, vorpot )
-      USE parallel_lmdz
-      USE mod_filtreg_p
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteur:  P. Le Van
-c   -------
-c
-c   Objet:
-c   ------
-c
-c    *******************************************************************
-c    .........      calcul du tourbillon potentiel             .........
-c    *******************************************************************
-c
-c     vcov,ucov,fext et pbarxyfl sont des argum. d'entree pour le s-pg .
-c             vorpot            est  un argum.de sortie pour le s-pg .
-c
-c=======================================================================
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom.h"
-#include "logic.h"
-
-      REAL  rot( ijb_v:ije_v,llm )
-      REAL vcov( ijb_v:ije_v,llm ),ucov( ijb_u:ije_u,llm )
-      REAL massebxy( ijb_v:ije_v,llm ),vorpot( ijb_v:ije_v,llm )
-
-      INTEGER l, ij ,ije,ijb,jje,jjb
-
-
-      ijb=ij_begin-iip1
-      ije=ij_end
-      
-      if (pole_nord) ijb=ij_begin
-      
-      
-c  ... vorpot = ( Filtre( d(vcov)/dx - d(ucov)/dy ) + fext ) /psbarxy ..
-
-
-
-c    ........  Calcul du rotationnel du vent V  puis filtrage  ........
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-      DO 5 l = 1,llm
-
-      if (pole_sud)  ije=ij_end-iip1-1
-      DO 2 ij = ijb, ije 
-      rot( ij,l ) = vcov(ij+1,l)-vcov(ij,l)+ucov(ij+iip1,l)-ucov(ij,l)
-   2  CONTINUE
-
-c    ....  correction pour  rot( iip1,j,l )  .....
-c    ....     rot(iip1,j,l) = rot(1,j,l)    .....
-
-CDIR$ IVDEP
-
-      if (pole_sud)  ije=ij_end-iip1
-     
-      DO 3 ij = ijb+iip1-1, ije, iip1
-      rot( ij,l ) = rot( ij -iim, l )
-   3  CONTINUE
-
-   5  CONTINUE
-c$OMP END DO NOWAIT
-      jjb=jj_begin-1
-      jje=jj_end
-      
-      if (pole_nord) jjb=jjb+1
-      if (pole_sud)  jje=jje-1
-      CALL  filtreg_p( rot, jjb_v,jje_v,jjb,jje,jjm, llm, 
-     &                 2, 1, .FALSE., 1 )
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)     
-      DO 10 l = 1, llm
-      
-      if (pole_sud)  ije=ij_end-iip1-1  
-      
-      DO 6 ij = ijb, ije
-      vorpot( ij,l ) = ( rot(ij,l) + fext(ij) ) / massebxy(ij,l)
-   6  CONTINUE
-
-c    ..... correction pour  vorpot( iip1,j,l)  .....
-c    ....   vorpot(iip1,j,l)= vorpot(1,j,l) ....
-CDIR$ IVDEP
-      if (pole_sud)  ije=ij_end-iip1
-      DO 8 ij = ijb+iip1-1, ije, iip1
-      vorpot( ij,l ) = vorpot( ij -iim,l )
-   8  CONTINUE
-
-  10  CONTINUE
-c$OMP END DO NOWAIT
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3dmem/tourpot_loc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/tourpot_loc.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/tourpot_loc.F90	(revision 2408)
@@ -0,0 +1,65 @@
+SUBROUTINE tourpot_loc ( vcov, ucov, massebxy, vorpot )
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van.
+!-------------------------------------------------------------------------------
+! Purpose: Compute potential vorticity.
+  USE parallel_lmdz
+  USE mod_filtreg_p
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+  include "logic.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: vcov    (ijb_v:ije_v,llm)
+  REAL, INTENT(IN)  :: ucov    (ijb_u:ije_u,llm)
+  REAL, INTENT(IN)  :: massebxy(ijb_v:ije_v,llm)
+  REAL, INTENT(OUT) :: vorpot  (ijb_v:ije_v,llm)
+!===============================================================================
+! Method used:
+!   vorpot = ( Filtre( d(vcov)/dx - d(ucov)/dy ) + fext ) /psbarxy
+!===============================================================================
+! Local variables:
+  INTEGER :: l, ij, ije, ijb, jje, jjb
+  REAL    :: rot(ijb_v:ije_v,llm)
+!===============================================================================
+
+  ijb=ij_begin-iip1
+  ije=ij_end
+  IF(pole_nord) ijb=ij_begin
+
+!--- Wind vorticity ; correction: rot(iip1,j,l) = rot(1,j,l)
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+  DO l=1,llm
+    IF(pole_sud) ije=ij_end-iip1-1
+    DO ij=ijb,ije
+      rot(ij,l)=vcov(ij+1,l)-vcov(ij,l)+ucov(ij+iip1,l)-ucov(ij,l)
+    END DO
+    IF(pole_sud) ije=ij_end-iip1
+    DO ij=ijb+iip1-1,ije,iip1; rot(ij,l)=rot(ij-iim,l); END DO
+  END DO
+!$OMP END DO NOWAIT
+
+!--- Filter
+  jjb=jj_begin-1
+  jje=jj_end
+  IF(pole_nord) jjb=jjb+1
+  IF(pole_sud)  jje=jje-1
+  CALL filtreg_p(rot,jjb_v,jje_v,jjb,jje,jjm,llm,2,1,.FALSE.,1)
+
+!--- Potential vorticity ; correction: rot(iip1,j,l) = rot(1,j,l)
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+  DO l=1,llm
+    IF(pole_sud) ije=ij_end-iip1-1
+    DO ij=ijb,ije
+      vorpot(ij,l)=(rot(ij,l)+fext(ij))/massebxy(ij,l)
+    END DO
+    IF(pole_sud) ije=ij_end-iip1
+    DO ij=ijb+iip1-1,ije,iip1; vorpot(ij,l)=vorpot(ij-iim,l); END DO
+  END DO
+!$OMP END DO NOWAIT
+
+END SUBROUTINE tourpot_loc
+
Index: DZ5/branches/testing/libf/dyn3dmem/vitvert_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/vitvert_loc.F	(revision 2407)
+++ 	(revision )
@@ -1,56 +1,0 @@
-      SUBROUTINE vitvert_loc ( convm , w )
-c
-      USE parallel_lmdz
-      IMPLICIT NONE
-
-c=======================================================================
-c
-c   Auteurs:  P. Le Van , F. Hourdin .
-c   -------
-c
-c   Objet:
-c   ------
-c
-c    *******************************************************************
-c  .... calcul de la vitesse verticale aux niveaux sigma  ....
-c    *******************************************************************
-c     convm   est un argument  d'entree pour le s-pg  ......
-c       w     est un argument de sortie pour le s-pg  ......
-c
-c    la vitesse verticale est orientee de  haut en bas .
-c    au sol, au niveau sigma(1),   w(i,j,1) = 0.
-c    au sommet, au niveau sigma(llm+1) , la vit.verticale est aussi
-c    egale a 0. et n'est pas stockee dans le tableau w  .
-c
-c
-c=======================================================================
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
-
-      REAL w(ijb_u:ije_u,llm),convm(ijb_u:ije_u,llm)
-      INTEGER   l, ij,ijb,ije
-
-
-      ijb=ij_begin
-      ije=ij_end+iip1
-      
-      if (pole_sud) ije=ij_end
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      DO 2  l = 1,llmm1
-
-      DO 1 ij = ijb,ije
-      w( ij, l+1 ) = convm( ij, l+1 ) - bp(l+1) * convm( ij, 1 )
-   1  CONTINUE
-
-   2  CONTINUE
-c$OMP END DO
-c$OMP MASTER
-      DO 5 ij  = ijb,ije
-      w(ij,1)  = 0.
-5     CONTINUE
-c$OMP END MASTER
-c$OMP BARRIER
-      RETURN
-      END
Index: /LMDZ5/branches/testing/libf/dyn3dmem/vitvert_loc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dmem/vitvert_loc.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dyn3dmem/vitvert_loc.F90	(revision 2408)
@@ -0,0 +1,38 @@
+SUBROUTINE vitvert_loc(convm, w)
+!
+!-------------------------------------------------------------------------------
+! Authors: P. Le Van , Fr. Hourdin.
+!-------------------------------------------------------------------------------
+! Purpose: Compute vertical speed at sigma levels.
+  USE parallel_lmdz
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comvert.h"
+!===============================================================================
+! Arguments:
+  REAL, INTENT(IN)  :: convm(ijb_u:ije_u,llm)
+  REAL, INTENT(OUT) :: w    (ijb_u:ije_u,llm)
+!===============================================================================
+! Notes: Vertical speed is oriented from bottom to top.
+!   * At ground - level sigma(1):     w(i,j,1) = 0.
+!   * At top    - level sigma(llm+1): w(i,j,l) = 0. (not stored in w)
+!===============================================================================
+! Local variables:
+  INTEGER :: l, ijb, ije
+!===============================================================================
+  ijb=ij_begin
+  ije=ij_end+iip1
+  IF(pole_sud) ije=ij_end
+!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+  DO l=1,llmm1
+    w(ijb:ije,l+1)=convm(ijb:ije,l+1)-bp(l+1)*convm(ijb:ije,1)
+  END DO
+!$OMP END DO
+!$OMP MASTER
+  w(ijb:ije,1)=0.
+!$OMP END MASTER
+!$OMP BARRIER
+
+END SUBROUTINE vitvert_loc
+
Index: /LMDZ5/branches/testing/libf/dyn3dpar/bands.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dpar/bands.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dyn3dpar/bands.F90	(revision 2408)
@@ -93,12 +93,10 @@
    SUBROUTINE  Set_Bands 
      USE parallel_lmdz
-#ifdef CPP_PHYS
-! Ehouarn: what follows is only related to // physics
-     USE mod_phys_lmdz_para, ONLY : jj_para_begin,jj_para_end
-#endif
      IMPLICIT NONE
      INCLUDE 'dimensions.h'    
-     INTEGER :: i
-        
+     INTEGER :: i, ij
+     INTEGER :: jj_para_begin(0:mpi_size-1)
+     INTEGER :: jj_para_end(0:mpi_size-1)
+       
       do i=0,mpi_size-1
          jj_nb_vanleer2(i)=(jjm+1)/mpi_size
@@ -106,5 +104,15 @@
       enddo
           
-#ifdef CPP_PHYS
+      jj_para_begin(0)=1
+      ij=distrib_phys(0)+iim-1
+      jj_para_end(0)=((ij-1)/iim)+1
+      
+      DO i=1,mpi_Size-1
+        ij=ij+1
+        jj_para_begin(i)=((ij-1)/iim)+1
+        ij=ij+distrib_phys(i)-1
+        jj_para_end(i)=((ij-1)/iim)+1
+      ENDDO
+ 
       do i=0,MPI_Size-1
         jj_Nb_physic(i)=jj_para_end(i)-jj_para_begin(i)+1
@@ -127,5 +135,4 @@
         endif
       enddo
-#endif      
       
     end subroutine Set_Bands
Index: DZ5/branches/testing/libf/dyn3dpar/ce0l.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dpar/ce0l.F90	(revision 2407)
+++ 	(revision )
@@ -1,134 +1,0 @@
-!
-! $Id$
-!
-!-------------------------------------------------------------------------------
-!
-PROGRAM ce0l
-!-------------------------------------------------------------------------------
-! Purpose: Calls etat0, creates initial states and limit_netcdf
-!
-!     interbar=.T. for barycentric interpolation inter_barxy
-!     extrap  =.T. for data extrapolation, like for the SSTs when file does not
-!                  contain ocean points only.
-!     oldice  =.T. for old-style ice, obtained using grille_m (grid_atob).
-!     masque is created in etat0, passed to limit to ensure consistancy.
-!-------------------------------------------------------------------------------
-  USE control_mod
-#ifdef CPP_EARTH
-! This prog. is designed to work for Earth
-  USE dimphy
-  USE comgeomphy
-  USE mod_phys_lmdz_para, mpi_root_xx=>mpi_root
-  USE mod_const_mpi
-  USE infotrac
-  USE parallel_lmdz, ONLY: finalize_parallel
-  USE indice_sol_mod
-
-#ifdef CPP_IOIPSL
-  USE ioipsl, ONLY: ioconf_calendar
-#endif
-
-#endif
-  IMPLICIT NONE
-#ifndef CPP_EARTH
-#include "iniprint.h"
-  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
-#else
-!-------------------------------------------------------------------------------
-! Local variables:
-  LOGICAL, PARAMETER :: interbar=.TRUE., extrap=.FALSE., oldice=.FALSE.
-#include "dimensions.h"
-#include "paramet.h"
-!#include "indicesol.h"
-#include "iniprint.h"
-#include "temps.h"
-#include "logic.h"
-#ifdef CPP_MPI
-      include 'mpif.h'
-#endif
-
-  INTEGER                       :: ierr
-  REAL,    DIMENSION(iip1,jjp1) :: masque
-  CHARACTER(LEN=15)             :: calnd
-  REAL,    DIMENSION(iip1,jjp1) :: phis ! geopotentiel au sol
-!-------------------------------------------------------------------------------
-  CALL conf_gcm( 99, .TRUE. )
-
-#ifdef CPP_MPI
-  CALL init_mpi
-#endif
-
-  CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
-  WRITE(lunout,*)'---> klon=',klon
-  IF (mpi_size>1 .OR. omp_size>1) THEN
-       CALL abort_gcm('ce0l','In parallel mode,                         &
- &                 ce0l must be called only                             &
- &                 for 1 process and 1 task',1)
-  ENDIF
-
-  CALL InitComgeomphy
-
-#ifdef CPP_IOIPSL
-  SELECT CASE(calend)
-    CASE('earth_360d');CALL ioconf_calendar('360d');      calnd='a 360 jours/an'
-    CASE('earth_365d');CALL ioconf_calendar('noleap');    calnd='a 365 jours/an'
-    CASE('earth_366d');CALL ioconf_calendar('366d');      calnd='bissextile'
-    CASE('gregorian'); CALL ioconf_calendar('gregorian'); calnd='gregorien'
-    CASE('standard');  CALL ioconf_calendar('gregorian'); calnd='gregorien'
-    CASE('julian');    CALL ioconf_calendar('julian');    calnd='julien'
-    CASE('proleptic_gregorian'); CALL ioconf_calendar('gregorian')
-  !--- DC Bof...  => IOIPSL a mettre a jour: proleptic_gregorian /= gregorian
-    CASE DEFAULT
-      CALL abort_gcm('ce0l','Mauvais choix de calendrier',1)
-  END SELECT
-  WRITE(lunout,*)'CALENDRIER CHOISI: Terrestre '//TRIM(calnd)
-#endif
-
-  IF (type_trac == 'inca') THEN
-#ifdef INCA
-      CALL init_const_lmdz( &
-         nbtr,anneeref,dayref,&
-         iphysiq,day_step,nday,& 
-         nbsrf, is_oce,is_sic,&
-         is_ter,is_lic)
-      
-#endif
-  END IF
-
-  WRITE(lunout,'(//)')
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,*) '  ***  etat0_netcdf ***  '
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,'(//)')
-  WRITE(lunout,*) ' interbar = ',interbar
-  CALL etat0_netcdf(interbar,masque,phis,ok_etat0)
-
-  IF(ok_limit) THEN
-  WRITE(lunout,'(//)')
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,*) '  ***  Limit_netcdf ***  '
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,'(//)')
-  CALL limit_netcdf(interbar,extrap,oldice,masque)
-  END IF
-
-  WRITE(lunout,'(//)')
-  WRITE(lunout,*) '  ***************************  '
-  WRITE(lunout,*) '  ***  grilles_gcm_netcdf ***  '
-  WRITE(lunout,*) '  ***************************  '
-  WRITE(lunout,'(//)')
-  CALL grilles_gcm_netcdf_sub(masque,phis)
-  
-#ifdef CPP_MPI
-!$OMP MASTER
-  CALL MPI_FINALIZE(ierr)
-  IF (ierr /= 0) CALL abort_gcm('ce0l','Error in MPI_FINALIZE',1)
-!$OMP END MASTER
-#endif
-
-#endif
-! of #ifndef CPP_EARTH #else
-
-END PROGRAM ce0l
-!
-!-------------------------------------------------------------------------------
Index: /LMDZ5/branches/testing/libf/dyn3dpar/gcm.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dpar/gcm.F	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dyn3dpar/gcm.F	(revision 2408)
@@ -14,7 +14,7 @@
       USE parallel_lmdz
       USE infotrac
-#ifdef CPP_PHYS
-      USE mod_interface_dyn_phys, ONLY: init_interface_dyn_phys
-#endif
+!#ifdef CPP_PHYS
+!      USE mod_interface_dyn_phys, ONLY: init_interface_dyn_phys
+!#endif
       USE mod_hallo
       USE Bands
@@ -30,8 +30,5 @@
 
 #ifdef CPP_PHYS
-!      USE mod_grid_phy_lmdz
-!      USE mod_phys_lmdz_para, ONLY : klon_mpi_para_nb
-!      USE dimphy
-!      USE comgeomphy
+  USE iniphysiq_mod, ONLY: iniphysiq
 #endif
       IMPLICIT NONE
@@ -162,11 +159,11 @@
       call Read_Distrib
 
-#ifdef CPP_PHYS
-        CALL Init_Phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
+!#ifdef CPP_PHYS
+!        CALL Init_Phys_lmdz(iim,jjp1,llm,mpi_size,distrib_phys)
 !#endif
 !      CALL set_bands
 !#ifdef CPP_PHYS
-      CALL Init_interface_dyn_phys
-#endif
+!      CALL Init_interface_dyn_phys
+!#endif
       CALL barrier
 
@@ -406,6 +403,8 @@
 ! Physics:
 #ifdef CPP_PHYS
-         CALL iniphysiq(iim,jjm,llm,daysec,day_ini,dtphys/nsplit_phys,
-     &                rlatu,rlonv,aire,cu,cv,rad,g,r,cpp,
+         CALL iniphysiq(iim,jjm,llm,
+     &                distrib_phys(mpi_rank),comm_lmdz,
+     &                daysec,day_ini,dtphys/nsplit_phys,
+     &                rlatu,rlatv,rlonu,rlonv,aire,cu,cv,rad,g,r,cpp,
      &                iflag_phys)
 #endif
Index: /LMDZ5/branches/testing/libf/dyn3dpar/leapfrog_p.F
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dpar/leapfrog_p.F	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dyn3dpar/leapfrog_p.F	(revision 2408)
@@ -258,8 +258,11 @@
    1  CONTINUE ! Matsuno Forward step begins here
 
+c   date: (NB: date remains unchanged for Backward step)
+c   -----
+
       jD_cur = jD_ref + day_ini - day_ref +                             &
-     &          itau/day_step
+     &          (itau+1)/day_step
       jH_cur = jH_ref + start_time +                                    &
-     &         mod(itau,day_step)/float(day_step) 
+     &         mod(itau+1,day_step)/float(day_step) 
       if (jH_cur > 1.0 ) then
         jD_cur = jD_cur +1.
@@ -356,7 +359,17 @@
 c-----------------------------------------------------------------------
 
-c   date:
+c   date: (NB: only leapfrog step requires recomputing date)
 c   -----
 
+      IF (leapf) THEN
+        jD_cur = jD_ref + day_ini - day_ref +
+     &            (itau+1)/day_step
+        jH_cur = jH_ref + start_time +
+     &           mod(itau+1,day_step)/float(day_step) 
+        if (jH_cur > 1.0 ) then
+          jD_cur = jD_cur +1.
+          jH_cur = jH_cur -1.
+        endif
+      ENDIF
 
 c   gestion des appels de la physique et des dissipations:
@@ -720,5 +733,5 @@
 
            jD_cur = jD_ref + day_ini - day_ref
-     $        + itau/day_step
+     $        + (itau+1)/day_step
 
            IF (planet_type .eq."generic") THEN
@@ -728,5 +741,5 @@
 
            jH_cur = jH_ref + start_time +                                &
-     &              mod(itau,day_step)/float(day_step) 
+     &              mod(itau+1,day_step)/float(day_step) 
 !         call ju2ymds(jD_cur+jH_cur, an, mois, jour, secondes)
            if (jH_cur > 1.0 ) then
@@ -747,10 +760,8 @@
       IF (ip_ebil_dyn.ge.1 ) THEN 
           ztit='bil dyn'
-! Ehouarn: be careful, diagedyn is Earth-specific (includes ../phylmd/..)!
+! Ehouarn: be careful, diagedyn is Earth-specific!
            IF (planet_type.eq."earth") THEN
-#ifdef CPP_EARTH
             CALL diagedyn(ztit,2,1,1,dtphys
      &    , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
-#endif
            ENDIF
       ENDIF 
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/calfis.F
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/calfis.F	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/calfis.F	(revision 2408)
@@ -139,5 +139,6 @@
       REAL zphi(ngridmx,llm),zphis(ngridmx)
 c
-      REAL zufi(ngridmx,llm), zvfi(ngridmx,llm)
+      REAL zrot(iip1,jjm,llm) ! AdlC May 2014
+      REAL zufi(ngridmx,llm), zvfi(ngridmx,llm), zrfi(ngridmx,llm)
       REAL ztfi(ngridmx,llm),zqfi(ngridmx,llm,nqtot)
 c
@@ -350,4 +351,18 @@
 
 
+C  Alvaro de la Camara (May 2014)
+C  46.1 Calcul de la vorticite et passage sur la grille physique
+C  --------------------------------------------------------------
+      DO l=1,llm
+        do i=1,iim
+          do j=1,jjm
+            zrot(i,j,l) = (pvcov(i+1,j,l) - pvcov(i,j,l)
+     $                   + pucov(i,j+1,l) - pucov(i,j,l)) 
+     $                   / (cu(i,j)+cu(i,j+1)) 
+     $                   / (cv(i+1,j)+cv(i,j)) *4
+          enddo
+        enddo
+      ENDDO
+
 c   46.champ v:
 c   -----------
@@ -362,4 +377,10 @@
      $         ( pdvcov(i,j-1,l)/cv(i,j-1) + pdvcov(i,j,l)/cv(i,j) )
             ENDDO
+               zrfi(ig0 + 1,l)= 0.25 *(zrot(iim,j-1,l)+zrot(iim,j,l)
+     &                                +zrot(1,j-1,l)+zrot(1,j,l))
+            DO i=2,iim
+               zrfi(ig0 + i,l)= 0.25 *(zrot(i-1,j-1,l)+zrot(i-1,j,l)
+     $                   +zrot(i,j-1,l)+zrot(i,j,l))   !  AdlC MAY 2014
+            ENDDO
          ENDDO
       ENDDO
@@ -391,5 +412,5 @@
          zvfi(1,l)  = SSUM(iim,zsin,1)/pi
          pcvgv(1,l) = SSUM(iim,zsinbis,1)/pi
-
+         zrfi(1, l) = 0.
       ENDDO
 
@@ -420,5 +441,5 @@
          zvfi(ngridmx,l)  = SSUM(iim,zsin,1)/pi
          pcvgv(ngridmx,l) = SSUM(iim,zsinbis,1)/pi
-
+         zrfi(ngridmx, l) = 0.
       ENDDO
 c
@@ -462,5 +483,5 @@
      .             presnivs,
      .             zufi,
-     .             zvfi,
+     .             zvfi, zrfi,
      .             ztfi,
      .             zqfi,
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/calfis_loc.F
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/calfis_loc.F	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/calfis_loc.F	(revision 2408)
@@ -32,5 +32,7 @@
 c   .........
       USE dimphy
-      USE mod_phys_lmdz_para, mpi_root_xx=>mpi_root 
+      USE mod_phys_lmdz_mpi_data, mpi_root_xx=>mpi_master
+      USE mod_phys_lmdz_omp_data, ONLY: klon_omp, klon_omp_begin
+      USE mod_const_mpi, ONLY: COMM_LMDZ
       USE mod_interface_dyn_phys
       USE IOPHY
@@ -38,4 +40,5 @@
 #ifdef CPP_PARA
       USE parallel_lmdz,ONLY:omp_chunk,using_mpi,jjb_u,jje_u,jjb_v,jje_v
+     $                        ,jj_begin_dyn=>jj_begin,jj_end_dyn=>jj_end
       USE Write_Field
       Use Write_field_p
@@ -154,5 +157,6 @@
       REAL,ALLOCATABLE,SAVE :: zphi(:,:),zphis(:)
 c
-      REAL,ALLOCATABLE,SAVE :: zufi(:,:), zvfi(:,:)
+      REAL zrot(iip1,jjb_v:jje_v,llm) ! AdlC May 2014
+      REAL,ALLOCATABLE,SAVE :: zufi(:,:), zvfi(:,:), zrfi(:,:)
       REAL,ALLOCATABLE,SAVE :: ztfi(:,:),zqfi(:,:,:)
 c
@@ -173,4 +177,5 @@
       REAL,ALLOCATABLE,SAVE :: zufi_omp(:,:) 
       REAL,ALLOCATABLE,SAVE :: zvfi_omp(:,:)
+      REAL,ALLOCATABLE,SAVE :: zrfi_omp(:,:)
       REAL,ALLOCATABLE,SAVE :: ztfi_omp(:,:)
       REAL,ALLOCATABLE,SAVE :: zqfi_omp(:,:,:)
@@ -206,5 +211,5 @@
 c$OMP THREADPRIVATE(zplev_omp,zplay_omp,zphi_omp,zphis_omp,
 c$OMP+                 presnivs_omp,zufi_omp,zvfi_omp,ztfi_omp,
-c$OMP+                 zqfi_omp,zdufi_omp,zdvfi_omp,
+c$OMP+                 zrfi_omp,zqfi_omp,zdufi_omp,zdvfi_omp,
 c$OMP+                 zdtfi_omp,zdqfi_omp,zdpsrf_omp,flxwfi_omp,
 c$OMP+                 zdufic_omp,zdvfic_omp,zdtfic_omp,zdqfic_omp)       
@@ -233,4 +238,5 @@
       integer :: k,kstart,kend
       INTEGER :: offset
+      INTEGER :: jjb,jje
 
       LOGICAL tracerdyn  
@@ -259,5 +265,5 @@
       ALLOCATE(zplev(klon,llm+1),zplay(klon,llm))
       ALLOCATE(zphi(klon,llm),zphis(klon))
-      ALLOCATE(zufi(klon,llm), zvfi(klon,llm))
+      ALLOCATE(zufi(klon,llm), zvfi(klon,llm),zrfi(klon,llm))
       ALLOCATE(ztfi(klon,llm),zqfi(klon,llm,nqtot))
       ALLOCATE(pcvgu(klon,llm), pcvgv(klon,llm))
@@ -431,5 +437,29 @@
 c$OMP END DO NOWAIT
 
-c   46.champ v:
+c
+C  Alvaro de la Camara (May 2014)
+C  46.1 Calcul de la vorticite et passage sur la grille physique
+C  --------------------------------------------------------------
+
+      jjb=jj_begin_dyn-1
+      jje=jj_end_dyn+1
+      if (is_north_pole) jjb=1
+      if (is_south_pole) jje=jjm
+
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
+
+      DO l=1,llm
+        do i=1,iim
+          do j=jjb,jje
+            zrot(i,j,l) = (pvcov(i+1,j,l) - pvcov(i,j,l)
+     $                   + pucov(i,j+1,l) - pucov(i,j,l))
+     $                   / (cu(i,j)+cu(i,j+1))
+     $                   / (cv(i+1,j)+cv(i,j)) *4
+          enddo
+        enddo
+      ENDDO
+
+
+c   46.2champ v:
 c   -----------
 
@@ -443,4 +473,16 @@
           zvfi(ig0,l)= 0.5 *(  pvcov(i,j-1,l)/cv(i,j-1) 
      $                       + pvcov(i,j,l)/cv(i,j) )
+          if (j==1 .OR. j==jjp1) then !  AdlC MAY 2014
+            zrfi(ig0,l) = 0 !  AdlC MAY 2014
+          else
+            if(i==1)then
+            zrfi(ig0,l)= 0.25 *(zrot(iim,j-1,l)+zrot(iim,j,l)
+     $                   +zrot(1,j-1,l)+zrot(1,j,l))   !  AdlC MAY 2014
+            else
+            zrfi(ig0,l)= 0.25 *(zrot(i-1,j-1,l)+zrot(i-1,j,l)
+     $                   +zrot(i,j-1,l)+zrot(i,j,l))   !  AdlC MAY 2014
+            endif
+          endif
+
     
          ENDDO
@@ -469,4 +511,5 @@
            zufi(1,l)  = SSUM(iim,zcos,1)/pi
            zvfi(1,l)  = SSUM(iim,zsin,1)/pi
+           zrfi(1,l)  = 0.
   
         ENDDO
@@ -496,4 +539,5 @@
            zufi(klon,l)  = SSUM(iim,zcos,1)/pi
            zvfi(klon,l)  = SSUM(iim,zsin,1)/pi
+           zrfi(klon,l)  = 0.
         ENDDO
 c$OMP END DO NOWAIT       
@@ -531,4 +575,5 @@
         allocate(zufi_omp(klon,llm))
         allocate(zvfi_omp(klon,llm))
+        allocate(zrfi_omp(klon,llm))  ! LG Ari 2014
         allocate(ztfi_omp(klon,llm))
         allocate(zqfi_omp(klon,llm,nqtot))
@@ -591,4 +636,10 @@
       do l=1,llm
         do i=1,klon
+	  zrfi_omp(i,l)=zrfi(offset+i,l)
+	enddo 
+      enddo
+	
+      do l=1,llm
+        do i=1,klon
 	  ztfi_omp(i,l)=ztfi(offset+i,l)
 	enddo 
@@ -674,4 +725,5 @@
      .             zufi_omp,
      .             zvfi_omp,
+     .             zrfi_omp,
      .             ztfi_omp,
      .             zqfi_omp,
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/calfis_p.F
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/calfis_p.F	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/calfis_p.F	(revision 2408)
@@ -29,5 +29,7 @@
 ! If using physics
       USE dimphy
-      USE mod_phys_lmdz_para, mpi_root_xx=>mpi_root 
+      USE mod_phys_lmdz_mpi_data, mpi_root_xx=>mpi_master
+      USE mod_phys_lmdz_omp_data, ONLY: klon_omp, klon_omp_begin
+      USE mod_const_mpi, ONLY: COMM_LMDZ
       USE mod_interface_dyn_phys
       USE IOPHY
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/grid_atob_m.f90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/grid_atob_m.f90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/grid_atob_m.f90	(revision 2408)
@@ -0,0 +1,292 @@
+!*******************************************************************************
+!
+MODULE grid_atob_m
+!
+!*******************************************************************************
+
+  USE assert_eq_m, ONLY: assert_eq
+
+  PRIVATE
+  PUBLIC :: grille_m, rugosite, sea_ice, rugsoro
+
+CONTAINS
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE fine2coarse(x_i, y_i, x_o, y_o, d_o1, d_i, msk, d_o2)
+!
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL,              INTENT(IN)  :: x_i(:), y_i(:) !-- INPUT  X&Y COOR. (mi)(ni)
+  REAL,              INTENT(IN)  :: x_o(:), y_o(:) !-- OUTPUT X&Y COOR. (mo)(no)
+  REAL,              INTENT(OUT) :: d_o1(:,:)      !-- OUTPUT FIELD     (mo,no)
+  REAL,    OPTIONAL, INTENT(IN)  :: d_i (:,:)      !-- INPUT FIELD      (mi,ni)
+  LOGICAL, OPTIONAL, INTENT(IN)  :: msk (:,:)      !-- MASK             (mo,no)
+  REAL,    OPTIONAL, INTENT(OUT) :: d_o2(:,:)      !-- OUTPUT FOR d_i^2 (mo,no)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname="fine2coarse"
+  INTEGER :: mi, ni, ii, ji, mo, no, io, jo, nr(2), m1, n1, m2, n2, mx, my, nn
+  LOGICAL :: li, lo
+  REAL    :: inc
+  INTEGER, DIMENSION(SIZE(x_o),SIZE(y_o)) :: num_tot
+  LOGICAL, DIMENSION(SIZE(x_o),SIZE(y_o)) :: found, mask
+  REAL,    DIMENSION(SIZE(x_o),SIZE(y_o)) :: dist
+  REAL,    DIMENSION(SIZE(x_o))           :: a, b
+  REAL,    DIMENSION(SIZE(y_o))           :: c, d
+  REAL,    PARAMETER :: thresh=1.E-5
+!-------------------------------------------------------------------------------
+  mi=SIZE(x_i); ni=SIZE(y_i); mo=SIZE(x_o); no=SIZE(y_o)
+  m1=m1; m2=mo; mx=mo; IF(PRESENT(msk)) mx=SIZE(msk,1)
+  n1=ni; n2=no; my=no; IF(PRESENT(msk)) my=SIZE(msk,2)
+  li=PRESENT(d_i ); IF(li) THEN; m1=SIZE(d_i ,1); n1=SIZE(d_i ,2); END IF
+  lo=PRESENT(d_o2); IF(lo) THEN; m2=SIZE(d_o2,1); n2=SIZE(d_o2,2); END IF
+  mi=assert_eq(mi,m1,TRIM(modname)//" mi")
+  ni=assert_eq(ni,n1,TRIM(modname)//" ni")
+  mo=assert_eq(mo,m2,mx,SIZE(d_o1,1),TRIM(modname)//" mo")
+  no=assert_eq(no,n2,my,SIZE(d_o1,2),TRIM(modname)//" no")
+  mask(:,:)=.TRUE.; IF(PRESENT(msk)) mask(:,:)=msk(:,:)
+
+!--- COMPUTE CELLS INTERFACES COORDINATES OF OUTPUT GRID
+  b(mo)=x_o(mo)+(x_o(mo)-x_o(mo-1))/2.0; b(1:mo-1)=(x_o(1:mo-1)+x_o(2:mo))/2.0
+  d(no)=y_o(no)+(y_o(no)-y_o(no-1))/2.0; d(1:no-1)=(y_o(1:no-1)+y_o(2:no))/2.0
+  a(1 )=x_o(1 )-(x_o(2 )-x_o(1   ))/2.0; a(2:mo  )=   b(1:mo-1)
+  c(1 )=y_o(1 )-(y_o(2 )-y_o(1   ))/2.0; c(2:no  )=   d(1:no-1)
+
+!--- ACCUMULATE INPUT POINTS ON OUTPUT GRID
+  d_o1(:,:)=0.; num_tot(:,:)=0; inc=1.0
+  IF(lo) d_o2(:,:)=0.
+  DO ji = 1, ni
+    DO ii = 1, mi
+      IF(li) inc=d_i(ii,ji)
+      DO jo = 1, no
+        IF((y_i(ji)-c(jo)<thresh.OR.y_i(ji)-d(jo)>thresh).AND.   &
+           (y_i(ji)-c(jo)>thresh.OR.y_i(ji)-d(jo)<thresh)) CYCLE
+        DO io = 1, mo
+          IF((x_i(ii)-a(io)<thresh.OR.x_i(ii)-b(io)>thresh).AND. &
+             (x_i(ii)-a(io)>thresh.OR.x_i(ii)-b(io)<thresh)) CYCLE
+          num_tot(io,jo)=num_tot(io,jo)+1
+          IF(mask(io,jo)) d_o1(io,jo)=d_o1(io,jo)+inc
+          IF(.NOT.lo) CYCLE
+          IF(mask(io,jo)) d_o2(io,jo)=d_o2(io,jo)+inc*inc
+        END DO
+      END DO
+    END DO
+  END DO
+
+!--- CHECK INPUT POINTS HAVE BEEN FOUND IN EACH OUTPUT CELL
+  found(:,:)=num_tot(:,:)/=0
+  WHERE(found.AND.mask) d_o1(:,:)=d_o1(:,:)/REAL(num_tot(:,:))
+  IF(PRESENT(d_o2)) THEN
+    WHERE(found.AND.mask) d_o2(:,:)=d_o2(:,:)/REAL(num_tot(:,:))
+    RETURN
+  END IF
+  nn=COUNT(found); IF(nn==0) RETURN
+
+!--- MISSING POINTS ; USE DISTANCE ON THE SPHERE TO FIND NEAREST POINT nr(2)
+  DO io = 1, mo
+    DO jo = 1, no
+      IF(found(io,jo)) CYCLE
+!      IF(prt_level>=1) PRINT*, "Problem: point out of domain (i,j)=", io,jo
+      CALL dist_sphe(x_o(io),y_o(jo),x_i,y_i,dist(:,:))
+      nr=MINLOC(dist(:,:))!; IF(prt_level>=1) PRINT*, "Solution: ", nr
+      inc=1.0; IF(li) inc=d_i(nr(1),nr(2))
+      IF(mask(io,jo)) d_o1(io,jo)=inc
+    END DO
+  END DO
+
+END SUBROUTINE fine2coarse
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE grille_m(xdata, ydata, entree, x, y, sortie)
+!
+!-------------------------------------------------------------------------------
+! Author:  Z.X. Li (april 1st 1994) (see also A. Harzallah and L. Fairhead)
+!-------------------------------------------------------------------------------
+! Purpose: Naive method to regrid on a coarser grid.
+!   Value at a new point is an average of the old points lcoated in a zone
+!   surrounding the considered new point.
+!   No ponderation is used (see grille_p)
+!
+!           (c)
+!        ----d-----
+!        | . . . .|
+!        |        |
+!     (b)a . * . .b(a)
+!        |        |
+!        | . . . .|
+!        ----c-----
+!           (d)
+!
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL, INTENT(IN)  :: xdata(:), ydata(:)       !--- INPUT  FIELD X AND Y COORD.
+  REAL, INTENT(IN)  :: entree(SIZE(xdata),SIZE(ydata)) !--- INPUT  FIELD
+  REAL, INTENT(IN)  :: x(:), y(:)               !--- OUTPUT FIELD X AND Y COORD.
+  REAL, INTENT(OUT) :: sortie(SIZE(x),SIZE(y))  !--- OUTPUT FIELD 
+!-------------------------------------------------------------------------------
+  CALL fine2coarse(xdata,ydata,x,y,sortie,entree)
+
+END SUBROUTINE grille_m
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE rugosite(xdata, ydata, entree, x, y, sortie, mask)
+!
+!-------------------------------------------------------------------------------
+! Author:  Z.X. Li (april 1st 1994)
+!-------------------------------------------------------------------------------
+! Purpose: Remap rugosity length ; constant value (0.001) on oceans.
+! Naive method  (see grille_m)
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL, INTENT(IN)  :: xdata(:), ydata(:)      !--- INPUT  FIELD X AND Y COORD.
+  REAL, INTENT(IN)  :: entree(SIZE(xdata),SIZE(ydata)) !--- INPUT  FIELD
+  REAL, INTENT(IN)  :: x(:), y(:)              !--- OUTPUT FIELD X AND Y COORD.
+  REAL, INTENT(OUT) :: sortie(SIZE(x),SIZE(y)) !--- OUTPUT FIELD 
+  REAL, INTENT(IN)  :: mask  (SIZE(x),SIZE(y)) !--- MASK
+!-------------------------------------------------------------------------------
+  CALL fine2coarse(xdata,ydata,x,y,sortie,LOG(entree))
+  WHERE(NINT(mask)==1)
+    sortie(:,:)=EXP(sortie(:,:))
+  ELSE WHERE
+    sortie(:,:)=0.001
+  END WHERE
+
+END SUBROUTINE rugosite
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE sea_ice(xdata, ydata, glace01, x, y, frac_ice)
+!
+!-------------------------------------------------------------------------------
+! Author:  Z.X. Li (april 1st 1994)
+! Purpose: Regrid ice indicator (0 or 1) on a coarser grid to get an ice fract.
+! field (between 0 and 1).
+! Naive method  (see grille_m)
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL, INTENT(IN)  :: xdata(:), ydata(:)      !--- INPUT  FIELD X AND Y COORD.
+  REAL, INTENT(IN)  :: glace01(:,:)            !--- INPUT  FIELD
+  REAL, INTENT(IN)  :: x(:), y(:)              !--- OUTPUT FIELD X AND Y COORD.
+  REAL, INTENT(OUT) :: frac_ice(SIZE(x),SIZE(y)) !--- OUTPUT FIELD 
+!-------------------------------------------------------------------------------
+  CALL fine2coarse(xdata,ydata,x,y,frac_ice,msk=NINT(glace01)==1)
+
+END SUBROUTINE sea_ice
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE rugsoro(xrel, yrel, relief, xmod, ymod, rugs)
+!
+!-------------------------------------------------------------------------------
+! Author:  Z.X. Li (april 1st 1994) ; Modifications: august 23rd 1995.
+! Purpose: Compute rugosity due to orography by using standard dev in a 1x1 cell
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL, INTENT(IN)  :: xrel(:), yrel(:)        !--- INPUT  FIELD X AND Y COORD.
+  REAL, INTENT(IN)  :: relief(:,:)             !--- INPUT  FIELD
+  REAL, INTENT(IN)  :: xmod(:), ymod(:)        !--- OUTPUT FIELD X AND Y COORD.
+  REAL, INTENT(OUT) :: rugs(SIZE(xmod),SIZE(ymod)) !--- OUTPUT FIELD 
+!-------------------------------------------------------------------------------
+! Local variable:
+  INTEGER           :: k, nn
+  INTEGER, PARAMETER:: itmp=360, jtmp=180
+  REAL  :: out(SIZE(xmod),SIZE(xmod)), amin, amax
+  REAL  :: cham1tmp(itmp,jtmp), cham2tmp(itmp,jtmp), xtmp(itmp), ytmp(jtmp)
+!-------------------------------------------------------------------------------
+
+!--- TEST INPUT FILE FITS FOR ONE DEGREE RESOLUTION
+  xtmp(:)=4.0*ATAN(1.0)*[(-1.0+REAL(2*k-1)/REAL(itmp),k=1,itmp)]
+  ytmp(:)=2.0*ATAN(1.0)*[(-1.0+REAL(2*k-1)/REAL(jtmp),k=1,jtmp)]
+  CALL fine2coarse(xrel,yrel,xtmp,ytmp,cham1tmp,relief,d_o2=cham2tmp)
+  cham2tmp(:,:)=cham2tmp(:,:)-cham1tmp(:,:)**2
+  nn=COUNT(cham2tmp<=-7.5)
+  IF(nn/=0) THEN
+    PRINT*,'Problem for rugsoro ; std**2 < -7.5 for several points: ',nn
+    CALL ABORT_GCM("", "", 1)
+  END IF
+  nn=COUNT(cham2tmp<0)
+  IF(nn/=0) PRINT*,'Problem for rugsoro ; std**2 < 0. for several points: ',nn
+  WHERE(cham2tmp<0.0) cham2tmp=0.0
+  cham2tmp(:,:)=SQRT(cham2tmp(:,:))
+  amin=MINVAL(cham2tmp); amax=MAXVAL(cham2tmp)
+  PRINT*, 'Ecart-type 1x1:', amin, amax
+
+!--- COMPUTE RUGOSITY AT REQUIRED SCALE
+  WHERE(cham2tmp<0.001) cham2tmp=0.001
+  CALL fine2coarse(xtmp,ytmp,xmod,ymod,out,REAL(LOG(cham2tmp)))
+  out=EXP(out)
+  amin=MINVAL(out); amax=MAXVAL(out)
+  PRINT*, 'Ecart-type du modele:', amin, amax
+  out=out/amax*20.0
+  amin=MINVAL(out); amax=MAXVAL(out)
+  PRINT*, 'Longueur de rugosite du modele:', amin, amax
+  rugs=REAL(out)
+
+END SUBROUTINE rugsoro
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE dist_sphe(rf_lon,rf_lat,rlon,rlat,distance)
+!
+!-------------------------------------------------------------------------------
+! Author:  Laurent Li (december 30th 1996).
+! Purpose: Compute min. distance (along big circle) between 2 points in radians.
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL, INTENT(IN) :: rf_lon, rf_lat  !--- Reference point coordinates (radians)
+  REAL, INTENT(IN) :: rlon(:), rlat(:)!--- Points longitudes/latitudes (radians)
+  REAL, INTENT(OUT):: distance(SIZE(rlon),SIZE(rlat)) !--- Distance    (radians)
+!-------------------------------------------------------------------------------
+! Local variables:
+  LOGICAL, SAVE :: first=.TRUE.
+  REAL,    SAVE :: pi, hpi
+  REAL    :: pa, pb, cpa, spa, crlo(SIZE(rlon))
+  INTEGER :: i, j
+!-------------------------------------------------------------------------------
+  IF(first) THEN; pi=4.0*ATAN(1.0); hpi=pi/2.0; first=.FALSE.; END IF
+  crlo(:)=COS(rf_lon-rlon(:))         !--- COS of points 1 and 2 angle
+  pa=hpi-rf_lat                       !--- North Pole - Point 1 distance
+  cpa=COS(pa); spa=SIN(pa)
+  DO j=1,SIZE(rlat)
+    pb=hpi-rlat(j)                    !--- North Pole - Point 2 distance
+    distance(:,j)=ACOS(cpa*COS(pb)+spa*SIN(pb)*crlo(:))
+  END DO
+
+END SUBROUTINE dist_sphe
+!
+!-------------------------------------------------------------------------------
+
+END MODULE grid_atob_m
+!
+!*******************************************************************************
+
Index: DZ5/branches/testing/libf/dynlonlat_phylonlat/ioipsl_getin_p_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/ioipsl_getin_p_mod.F90	(revision 2407)
+++ 	(revision )
@@ -1,169 +1,0 @@
-!
-! $Id$
-!
-MODULE ioipsl_getin_p_mod
-! To use getin in a parallel context
-!---------------------------------------------------------------------
-#ifdef CPP_IOIPSL
-USE ioipsl, ONLY: getin
-#else
-USE ioipsl_getincom, ONLY: getin
-#endif
-USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
-use mod_phys_lmdz_para, only : bcast
-!-
-IMPLICIT NONE
-!-
-PRIVATE
-PUBLIC :: getin_p
-!-
-INTERFACE getin_p
-
-  MODULE PROCEDURE getinrs_p, getinr1d_p, getinr2d_p, &
- &                 getinis_p, getini1d_p, getini2d_p, &
- &                 getincs_p, 		              &
- &                 getinls_p, getinl1d_p, getinl2d_p
-END INTERFACE
-!-
-CONTAINS
-
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!!   Definition des getin -> bcast      !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-!! -- Les chaines de caracteres -- !!
-  
-  SUBROUTINE getincs_p(VarIn,VarOut)
-    IMPLICIT NONE    
-    CHARACTER(LEN=*),INTENT(IN) :: VarIn
-    CHARACTER(LEN=*),INTENT(INOUT) :: VarOut    
-
-!$OMP BARRIER
-    IF (is_mpi_root .AND. is_omp_root) THEN
-    	CALL getin(VarIn,VarOut)
-    ENDIF
-    CALL bcast(VarOut)
-  END SUBROUTINE getincs_p
-
-!! -- Les entiers -- !!
-  
-  SUBROUTINE getinis_p(VarIn,VarOut)
-    IMPLICIT NONE    
-    CHARACTER(LEN=*),INTENT(IN) :: VarIn
-    INTEGER,INTENT(INOUT) :: VarOut    
-
-!$OMP BARRIER
-    IF (is_mpi_root .AND. is_omp_root) THEN
-    	CALL getin(VarIn,VarOut)
-    ENDIF
-    CALL bcast(VarOut)
-  END SUBROUTINE getinis_p
-
-  SUBROUTINE getini1d_p(VarIn,VarOut)
-    IMPLICIT NONE    
-    CHARACTER(LEN=*),INTENT(IN) :: VarIn
-    INTEGER,INTENT(INOUT) :: VarOut(:)
-
-!$OMP BARRIER
-    IF (is_mpi_root .AND. is_omp_root) THEN
-    	CALL getin(VarIn,VarOut)
-    ENDIF
-    CALL bcast(VarOut)
-  END SUBROUTINE getini1d_p
-
-  SUBROUTINE getini2d_p(VarIn,VarOut)
-    IMPLICIT NONE    
-    CHARACTER(LEN=*),INTENT(IN) :: VarIn
-    INTEGER,INTENT(INOUT) :: VarOut(:,:)
-
-!$OMP BARRIER
-    IF (is_mpi_root .AND. is_omp_root) THEN
-    	CALL getin(VarIn,VarOut)
-    ENDIF
-    CALL bcast(VarOut)
-  END SUBROUTINE getini2d_p
-
-!! -- Les flottants -- !!
-  
-  SUBROUTINE getinrs_p(VarIn,VarOut)
-    IMPLICIT NONE    
-    CHARACTER(LEN=*),INTENT(IN) :: VarIn
-    REAL,INTENT(INOUT) :: VarOut
-
-!$OMP BARRIER
-    IF (is_mpi_root .AND. is_omp_root) THEN
-    	CALL getin(VarIn,VarOut)
-    ENDIF
-    CALL bcast(VarOut)
-  END SUBROUTINE getinrs_p
-
-  SUBROUTINE getinr1d_p(VarIn,VarOut)
-    IMPLICIT NONE    
-    CHARACTER(LEN=*),INTENT(IN) :: VarIn
-    REAL,INTENT(INOUT) :: VarOut(:)
-
-!$OMP BARRIER
-    IF (is_mpi_root .AND. is_omp_root) THEN
-    	CALL getin(VarIn,VarOut)
-    ENDIF
-    CALL bcast(VarOut)
-  END SUBROUTINE getinr1d_p
-
-  SUBROUTINE getinr2d_p(VarIn,VarOut)
-    IMPLICIT NONE    
-    CHARACTER(LEN=*),INTENT(IN) :: VarIn
-    REAL,INTENT(INOUT) :: VarOut(:,:)
-
-!$OMP BARRIER
-    IF (is_mpi_root .AND. is_omp_root) THEN
-    	CALL getin(VarIn,VarOut)
-    ENDIF
-    CALL bcast(VarOut)
-  END SUBROUTINE getinr2d_p
-
-!! -- Les Booleens -- !!
-  
-  SUBROUTINE getinls_p(VarIn,VarOut)
-    IMPLICIT NONE    
-    CHARACTER(LEN=*),INTENT(IN) :: VarIn
-    LOGICAL,INTENT(INOUT) :: VarOut
-
-!$OMP BARRIER
-    IF (is_mpi_root .AND. is_omp_root) THEN
-    	CALL getin(VarIn,VarOut)
-    ENDIF
-    CALL bcast(VarOut)
-  END SUBROUTINE getinls_p
-
-  SUBROUTINE getinl1d_p(VarIn,VarOut)
-    IMPLICIT NONE    
-    CHARACTER(LEN=*),INTENT(IN) :: VarIn
-    LOGICAL,INTENT(INOUT) :: VarOut(:)
-
-!$OMP BARRIER
-    IF (is_mpi_root .AND. is_omp_root) THEN
-    	CALL getin(VarIn,VarOut)
-    ENDIF
-    CALL bcast(VarOut)
-  END SUBROUTINE getinl1d_p
-
-  SUBROUTINE getinl2d_p(VarIn,VarOut)
-    IMPLICIT NONE    
-    CHARACTER(LEN=*),INTENT(IN) :: VarIn
-    LOGICAL,INTENT(INOUT) :: VarOut(:,:)
-
-!$OMP BARRIER
-    IF (is_mpi_root .AND. is_omp_root) THEN
-    	CALL getin(VarIn,VarOut)
-    ENDIF
-    CALL bcast(VarOut)
-  END SUBROUTINE getinl2d_p
-!-
-!-----------------------------
-!-----------------------------
-!-----------------------------
-
-END MODULE ioipsl_getin_p_mod
-
Index: DZ5/branches/testing/libf/dynlonlat_phylonlat/mod_grid_phy_lmdz.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/mod_grid_phy_lmdz.F90	(revision 2407)
+++ 	(revision )
@@ -1,454 +1,0 @@
-!
-!$Id $
-!
-MODULE mod_grid_phy_lmdz
-
-  PUBLIC
-  PRIVATE :: grid1dTo2d_glo_igen, grid1dTo2d_glo_rgen, grid1dTo2d_glo_lgen, &
-             grid2dTo1d_glo_igen, grid2dTo1d_glo_rgen, grid2dTo1d_glo_lgen
-  
-  INTEGER,SAVE :: nbp_lon  ! == iim
-  INTEGER,SAVE :: nbp_lat  ! == jjmp1
-  INTEGER,SAVE :: nbp_lev  ! == llm
-  INTEGER,SAVE :: klon_glo
-
-  INTERFACE grid1dTo2d_glo
-    MODULE PROCEDURE grid1dTo2d_glo_i,grid1dTo2d_glo_i1,grid1dTo2d_glo_i2,grid1dTo2d_glo_i3, &
-                     grid1dTo2d_glo_r,grid1dTo2d_glo_r1,grid1dTo2d_glo_r2,grid1dTo2d_glo_r3, &
-		     grid1dTo2d_glo_l,grid1dTo2d_glo_l1,grid1dTo2d_glo_l2,grid1dTo2d_glo_l3
-   END INTERFACE 
-
-   INTERFACE grid2dTo1d_glo
-    MODULE PROCEDURE grid2dTo1d_glo_i,grid2dTo1d_glo_i1,grid2dTo1d_glo_i2,grid2dTo1d_glo_i3, &
-                     grid2dTo1d_glo_r,grid2dTo1d_glo_r1,grid2dTo1d_glo_r2,grid2dTo1d_glo_r3, &
-		     grid2dTo1d_glo_l,grid2dTo1d_glo_l1,grid2dTo1d_glo_l2,grid2dTo1d_glo_l3
-   END INTERFACE 
- 
-CONTAINS
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! SUBROUTINE grid1dTo2d  !!  
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-
-  SUBROUTINE Init_grid_phy_lmdz(iim,jjp1,llm)
-  IMPLICIT NONE
-  INTEGER, INTENT(in) :: iim
-  INTEGER, INTENT(in) :: jjp1
-  INTEGER, INTENT(in) :: llm
-  
-    nbp_lon=iim
-    nbp_lat=jjp1
-    nbp_lev=llm
-    klon_glo=(iim*jjp1)-2*(iim-1)
-  
-  END SUBROUTINE Init_grid_phy_lmdz
-  
-  
-  SUBROUTINE grid1dTo2d_glo_i(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:)     :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_igen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid1dTo2d_glo_i
-  
-
-  SUBROUTINE grid1dTo2d_glo_i1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:)     :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_igen(VarIn,VarOut,size(VarIn,2))
-  
-  END SUBROUTINE grid1dTo2d_glo_i1
-
-  SUBROUTINE grid1dTo2d_glo_i2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_igen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
-  
-  END SUBROUTINE grid1dTo2d_glo_i2
-  
-  SUBROUTINE grid1dTo2d_glo_i3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_igen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid1dTo2d_glo_i3
-
-
-  SUBROUTINE grid1dTo2d_glo_r(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:)     :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_rgen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid1dTo2d_glo_r
-  
-
-  SUBROUTINE grid1dTo2d_glo_r1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:)     :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_rgen(VarIn,VarOut,size(VarIn,2))
-  
-  END SUBROUTINE grid1dTo2d_glo_r1
-
-  SUBROUTINE grid1dTo2d_glo_r2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_rgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
-  
-  END SUBROUTINE grid1dTo2d_glo_r2
-  
-  SUBROUTINE grid1dTo2d_glo_r3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_rgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid1dTo2d_glo_r3
-  
-  
-  
-  SUBROUTINE grid1dTo2d_glo_l(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:)     :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_lgen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid1dTo2d_glo_l
-  
-
-  SUBROUTINE grid1dTo2d_glo_l1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:)     :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_lgen(VarIn,VarOut,size(VarIn,2))
-  
-  END SUBROUTINE grid1dTo2d_glo_l1
-
-  SUBROUTINE grid1dTo2d_glo_l2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_lgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
-  
-  END SUBROUTINE grid1dTo2d_glo_l2
-  
-  SUBROUTINE grid1dTo2d_glo_l3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_glo_lgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid1dTo2d_glo_l3  
-  
-    SUBROUTINE grid2dTo1d_glo_i(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_igen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid2dTo1d_glo_i
-  
-
-  SUBROUTINE grid2dTo1d_glo_i1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_igen(VarIn,VarOut,size(VarIn,3))
-  
-  END SUBROUTINE grid2dTo1d_glo_i1
-
-  SUBROUTINE grid2dTo1d_glo_i2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_igen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid2dTo1d_glo_i2
-  
-  SUBROUTINE grid2dTo1d_glo_i3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_igen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
-  
-  END SUBROUTINE grid2dTo1d_glo_i3
- 
-
-
-
-  SUBROUTINE grid2dTo1d_glo_r(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_rgen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid2dTo1d_glo_r
-  
-
-  SUBROUTINE grid2dTo1d_glo_r1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_rgen(VarIn,VarOut,size(VarIn,3))
-  
-  END SUBROUTINE grid2dTo1d_glo_r1
-
-  SUBROUTINE grid2dTo1d_glo_r2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_rgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid2dTo1d_glo_r2
-  
-  SUBROUTINE grid2dTo1d_glo_r3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_rgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
-  
-  END SUBROUTINE grid2dTo1d_glo_r3
-
-
-
-  SUBROUTINE grid2dTo1d_glo_l(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_lgen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid2dTo1d_glo_l
-  
-
-  SUBROUTINE grid2dTo1d_glo_l1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_lgen(VarIn,VarOut,size(VarIn,3))
-  
-  END SUBROUTINE grid2dTo1d_glo_l1
-
-  SUBROUTINE grid2dTo1d_glo_l2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_lgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid2dTo1d_glo_l2
-  
-  SUBROUTINE grid2dTo1d_glo_l3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_glo_lgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
-  
-  END SUBROUTINE grid2dTo1d_glo_l3
-
-!---------------------------------------------------------------- 
-!  Generic (private) fonctions
-!---------------------------------------------------------------- 
-  
-  SUBROUTINE grid1dTo2d_glo_igen(VarIn,VarOut,dimsize)
-
-    IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    INTEGER,INTENT(IN) ,DIMENSION(klon_glo,dimsize)       :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(nbp_lon*nbp_lat,dimsize)  :: VarOut
-    INTEGER :: i,ij,Offset
-
-    
-    Offset=nbp_lon
-        
-    DO i=1,dimsize
-      DO ij=1,klon_glo
-        VarOut(ij+offset-1,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO
-    
-    
-    DO i=1,dimsize
-      DO ij=1,nbp_lon
-       VarOut(ij,i)=VarIn(1,i)
-      ENDDO
-    ENDDO
-    
-    
-    DO i=1,dimsize
-      DO ij=nbp_lon*(nbp_lat-1)+1,nbp_lat*nbp_lon
-       VarOut(ij,i)=VarIn(klon_glo,i)
-      ENDDO
-    ENDDO
-
-  END SUBROUTINE grid1dTo2d_glo_igen   
-
-
-  SUBROUTINE grid1dTo2d_glo_rgen(VarIn,VarOut,dimsize)
-
-    IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    REAL,INTENT(IN) ,DIMENSION(klon_glo,dimsize)       :: VarIn
-    REAL,INTENT(OUT),DIMENSION(nbp_lon*nbp_lat,dimsize)  :: VarOut
-    INTEGER :: i,ij,Offset
-
-   
-    Offset=nbp_lon
-        
-    DO i=1,dimsize
-      DO ij=1,klon_glo
-        VarOut(ij+offset-1,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO
-    
-    
-    DO i=1,dimsize
-      DO ij=1,nbp_lon
-       VarOut(ij,i)=VarIn(1,i)
-      ENDDO
-    ENDDO
-    
-    
-    DO i=1,dimsize
-      DO ij=nbp_lon*(nbp_lat-1)+1,nbp_lat*nbp_lon
-       VarOut(ij,i)=VarIn(klon_glo,i)
-      ENDDO
-    ENDDO
-
-  END SUBROUTINE grid1dTo2d_glo_rgen   
-
-  SUBROUTINE grid1dTo2d_glo_lgen(VarIn,VarOut,dimsize)
-
-    IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: dimsize
-    LOGICAL,INTENT(IN) ,DIMENSION(klon_glo,dimsize)       :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(nbp_lon*nbp_lat,dimsize)  :: VarOut
-    INTEGER :: i,ij,Offset
-
-    Offset=nbp_lon
-        
-    DO i=1,dimsize
-      DO ij=1,klon_glo
-        VarOut(ij+offset-1,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO
-    
-    
-    DO i=1,dimsize
-      DO ij=1,nbp_lon
-       VarOut(ij,i)=VarIn(1,i)
-      ENDDO
-    ENDDO
-    
-    
-    DO i=1,dimsize
-      DO ij=nbp_lon*(nbp_lat-1)+1,nbp_lat*nbp_lon
-       VarOut(ij,i)=VarIn(klon_glo,i)
-      ENDDO
-    ENDDO
-
-  END SUBROUTINE grid1dTo2d_glo_lgen     
-  
-  
-  SUBROUTINE grid2dTo1d_glo_igen(VarIn,VarOut,dimsize)
-
-    IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    INTEGER,INTENT(IN) ,DIMENSION(nbp_lon*nbp_lat,dimsize) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(klon_glo,dimsize)      :: VarOut
-    INTEGER :: i,ij,offset
-
-    offset=nbp_lon
-
-    DO i=1,dimsize
-      DO ij=1,klon_glo
-        VarOut(ij,i)=VarIn(ij+offset-1,i)
-      ENDDO
-    ENDDO
-
-    DO i=1,dimsize
-      VarOut(1,i)=VarIn(1,i)
-    ENDDO
-    
-  END SUBROUTINE grid2dTo1d_glo_igen   
-  
-  SUBROUTINE grid2dTo1d_glo_rgen(VarIn,VarOut,dimsize)
-
-    IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    REAL,INTENT(IN) ,DIMENSION(nbp_lon*nbp_lat,dimsize) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(klon_glo,dimsize)      :: VarOut
-    INTEGER :: i,ij,offset
-
-    offset=nbp_lon
-
-    DO i=1,dimsize
-      DO ij=1,klon_glo
-        VarOut(ij,i)=VarIn(ij+offset-1,i)
-      ENDDO
-    ENDDO
-
-    DO i=1,dimsize
-      VarOut(1,i)=VarIn(1,i)
-    ENDDO
-    
-  END SUBROUTINE grid2dTo1d_glo_rgen 
-    
-  SUBROUTINE grid2dTo1d_glo_lgen(VarIn,VarOut,dimsize)
-
-    IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    LOGICAL,INTENT(IN) ,DIMENSION(nbp_lon*nbp_lat,dimsize) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(klon_glo,dimsize)      :: VarOut
-    INTEGER :: i,ij,offset
-
-    offset=nbp_lon
-
-    DO i=1,dimsize
-      DO ij=1,klon_glo
-        VarOut(ij,i)=VarIn(ij+offset-1,i)
-      ENDDO
-    ENDDO
-
-    DO i=1,dimsize
-      VarOut(1,i)=VarIn(1,i)
-    ENDDO
-    
-  END SUBROUTINE grid2dTo1d_glo_lgen   
-
-END MODULE mod_grid_phy_lmdz
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/mod_interface_dyn_phys.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/mod_interface_dyn_phys.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/mod_interface_dyn_phys.F90	(revision 2408)
@@ -7,8 +7,8 @@
   
   
+CONTAINS
+  
 #ifdef CPP_PARA
 ! Interface with parallel physics,
-CONTAINS
-  
   SUBROUTINE Init_interface_dyn_phys
     USE mod_phys_lmdz_mpi_data
@@ -54,4 +54,8 @@
   
   END SUBROUTINE Init_interface_dyn_phys 
+#else
+  SUBROUTINE Init_interface_dyn_phys
+  ! dummy routine for seq case
+  END SUBROUTINE Init_interface_dyn_phys 
 #endif
 ! of #ifdef CPP_PARA
Index: DZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_mpi_data.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_mpi_data.F90	(revision 2407)
+++ 	(revision )
@@ -1,203 +1,0 @@
-!
-!$Header$
-!
-MODULE mod_phys_lmdz_mpi_data
-  USE mod_const_mpi
-  
-  INTEGER,SAVE :: ii_begin
-  INTEGER,SAVE :: ii_end
-  INTEGER,SAVE :: jj_begin
-  INTEGER,SAVE :: jj_end
-  INTEGER,SAVE :: jj_nb
-  INTEGER,SAVE :: ij_begin
-  INTEGER,SAVE :: ij_end
-  INTEGER,SAVE :: ij_nb
-  INTEGER,SAVE :: klon_mpi_begin
-  INTEGER,SAVE :: klon_mpi_end
-  INTEGER,SAVE :: klon_mpi
-  
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: jj_para_nb
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: jj_para_begin
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: jj_para_end
-
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ii_para_begin
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ii_para_end
-
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ij_para_nb
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ij_para_begin
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ij_para_end
-
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: klon_mpi_para_nb
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: klon_mpi_para_begin
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: klon_mpi_para_end 
-
-  
-  INTEGER,SAVE :: mpi_rank
-  INTEGER,SAVE :: mpi_size
-  INTEGER,SAVE :: mpi_root
-  LOGICAL,SAVE :: is_mpi_root
-  LOGICAL,SAVE :: is_using_mpi
-  
-  
-  LOGICAL,SAVE :: is_north_pole
-  LOGICAL,SAVE :: is_south_pole
-  INTEGER,SAVE :: COMM_LMDZ_PHY
-
-CONTAINS
-  
-  SUBROUTINE Init_phys_lmdz_mpi_data(iim,jjp1,nb_proc,distrib)
-  USE mod_const_mpi, ONLY : COMM_LMDZ
-  IMPLICIT NONE
-    INTEGER,INTENT(in) :: iim
-    INTEGER,INTENT(in) :: jjp1
-    INTEGER,INTENT(in) :: nb_proc
-    INTEGER,INTENT(in) :: distrib(0:nb_proc-1)
-    
-    INTEGER :: ierr
-    INTEGER :: klon_glo
-    INTEGER :: i
-    
-#ifdef CPP_MPI
-    is_using_mpi=.TRUE.
-#else
-    is_using_mpi=.FALSE.
-#endif
-    
-    if (iim.eq.1) then
-       klon_glo=1
-    else
-       klon_glo=iim*(jjp1-2)+2
-    endif
-    
-    COMM_LMDZ_PHY=COMM_LMDZ
-
-    IF (is_using_mpi) THEN    
-#ifdef CPP_MPI
-      CALL MPI_COMM_SIZE(COMM_LMDZ_PHY,mpi_size,ierr)    
-      CALL MPI_COMM_RANK(COMM_LMDZ_PHY,mpi_rank,ierr)
-#endif
-    ELSE
-      mpi_size=1
-      mpi_rank=0
-    ENDIF
-    
-    IF (mpi_rank == 0) THEN
-      mpi_root = 0
-      is_mpi_root = .true.
-    ENDIF
-    
-    IF (mpi_rank == 0) THEN 
-      is_north_pole = .TRUE.
-    ELSE
-      is_north_pole = .FALSE.
-    ENDIF
-    
-    IF (mpi_rank == mpi_size-1) THEN
-      is_south_pole = .TRUE.
-    ELSE
-      is_south_pole = .FALSE.
-    ENDIF
-    
-    ALLOCATE(jj_para_nb(0:mpi_size-1))
-    ALLOCATE(jj_para_begin(0:mpi_size-1))
-    ALLOCATE(jj_para_end(0:mpi_size-1))
-    
-    ALLOCATE(ij_para_nb(0:mpi_size-1))
-    ALLOCATE(ij_para_begin(0:mpi_size-1))
-    ALLOCATE(ij_para_end(0:mpi_size-1))
-    
-    ALLOCATE(ii_para_begin(0:mpi_size-1))
-    ALLOCATE(ii_para_end(0:mpi_size-1))
-
-    ALLOCATE(klon_mpi_para_nb(0:mpi_size-1))
-    ALLOCATE(klon_mpi_para_begin(0:mpi_size-1))
-    ALLOCATE(klon_mpi_para_end(0:mpi_size-1))
-  
-      
-    klon_mpi_para_nb(0:mpi_size-1)=distrib(0:nb_proc-1)
-
-    DO i=0,mpi_size-1
-      IF (i==0) THEN 
-        klon_mpi_para_begin(i)=1
-      ELSE 
-        klon_mpi_para_begin(i)=klon_mpi_para_end(i-1)+1
-      ENDIF
-        klon_mpi_para_end(i)=klon_mpi_para_begin(i)+klon_mpi_para_nb(i)-1
-    ENDDO
-
-
-    DO i=0,mpi_size-1
-      
-      IF (i==0) THEN
-        ij_para_begin(i) = 1
-      ELSE
-        ij_para_begin(i) = klon_mpi_para_begin(i)+iim-1
-      ENDIF
-
-      jj_para_begin(i) = (ij_para_begin(i)-1)/iim + 1
-      ii_para_begin(i) = MOD(ij_para_begin(i)-1,iim) + 1
-
-      
-      ij_para_end(i) = klon_mpi_para_end(i)+iim-1
-      jj_para_end(i) = (ij_para_end(i)-1)/iim + 1
-      ii_para_end(i) = MOD(ij_para_end(i)-1,iim) + 1
-
-
-      ij_para_nb(i) = ij_para_end(i)-ij_para_begin(i)+1
-      jj_para_nb(i) = jj_para_end(i)-jj_para_begin(i)+1
-         
-    ENDDO
-  
-    ii_begin = ii_para_begin(mpi_rank)
-    ii_end   = ii_para_end(mpi_rank)
-    jj_begin = jj_para_begin(mpi_rank)
-    jj_end   = jj_para_end(mpi_rank)
-    jj_nb    = jj_para_nb(mpi_rank)
-    ij_begin = ij_para_begin(mpi_rank)
-    ij_end   = ij_para_end(mpi_rank)
-    ij_nb    = ij_para_nb(mpi_rank)
-    klon_mpi_begin = klon_mpi_para_begin(mpi_rank)
-    klon_mpi_end   = klon_mpi_para_end(mpi_rank)
-    klon_mpi       = klon_mpi_para_nb(mpi_rank)
-   
-    CALL Print_module_data
-    
-  END SUBROUTINE Init_phys_lmdz_mpi_data
-
-  SUBROUTINE print_module_data
-  IMPLICIT NONE
-  INCLUDE "iniprint.h" 
-  
-    WRITE(lunout,*) 'ii_begin =', ii_begin
-    WRITE(lunout,*) 'ii_end =', ii_end
-    WRITE(lunout,*) 'jj_begin =',jj_begin
-    WRITE(lunout,*) 'jj_end =', jj_end
-    WRITE(lunout,*) 'jj_nb =', jj_nb
-    WRITE(lunout,*) 'ij_begin =', ij_begin
-    WRITE(lunout,*) 'ij_end =', ij_end
-    WRITE(lunout,*) 'ij_nb =', ij_nb
-    WRITE(lunout,*) 'klon_mpi_begin =', klon_mpi_begin
-    WRITE(lunout,*) 'klon_mpi_end =', klon_mpi_end
-    WRITE(lunout,*) 'klon_mpi =', klon_mpi
-    WRITE(lunout,*) 'jj_para_nb =', jj_para_nb
-    WRITE(lunout,*) 'jj_para_begin =', jj_para_begin
-    WRITE(lunout,*) 'jj_para_end =', jj_para_end
-    WRITE(lunout,*) 'ii_para_begin =', ii_para_begin
-    WRITE(lunout,*) 'ii_para_end =', ii_para_end
-    WRITE(lunout,*) 'ij_para_nb =', ij_para_nb
-    WRITE(lunout,*) 'ij_para_begin =', ij_para_begin
-    WRITE(lunout,*) 'ij_para_end =', ij_para_end
-    WRITE(lunout,*) 'klon_mpi_para_nb =', klon_mpi_para_nb
-    WRITE(lunout,*) 'klon_mpi_para_begin =', klon_mpi_para_begin
-    WRITE(lunout,*) 'klon_mpi_para_end  =', klon_mpi_para_end 
-    WRITE(lunout,*) 'mpi_rank =', mpi_rank
-    WRITE(lunout,*) 'mpi_size =', mpi_size
-    WRITE(lunout,*) 'mpi_root =', mpi_root
-    WRITE(lunout,*) 'is_mpi_root =', is_mpi_root
-    WRITE(lunout,*) 'is_north_pole =', is_north_pole
-    WRITE(lunout,*) 'is_south_pole =', is_south_pole
-    WRITE(lunout,*) 'COMM_LMDZ_PHY =', COMM_LMDZ_PHY
-  
-  END SUBROUTINE print_module_data
-  
-END MODULE mod_phys_lmdz_mpi_data
Index: DZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_mpi_transfert.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_mpi_transfert.F90	(revision 2407)
+++ 	(revision )
@@ -1,1902 +1,0 @@
-!
-!$Header$
-!
-MODULE mod_phys_lmdz_mpi_transfert
-
-
-  INTERFACE bcast_mpi
-    MODULE PROCEDURE bcast_mpi_c,                                                     &
-                     bcast_mpi_i,bcast_mpi_i1,bcast_mpi_i2,bcast_mpi_i3,bcast_mpi_i4, &
-                     bcast_mpi_r,bcast_mpi_r1,bcast_mpi_r2,bcast_mpi_r3,bcast_mpi_r4, &
-                     bcast_mpi_l,bcast_mpi_l1,bcast_mpi_l2,bcast_mpi_l3,bcast_mpi_l4
-  END INTERFACE
-
-  INTERFACE scatter_mpi
-    MODULE PROCEDURE scatter_mpi_i,scatter_mpi_i1,scatter_mpi_i2,scatter_mpi_i3, &
-                     scatter_mpi_r,scatter_mpi_r1,scatter_mpi_r2,scatter_mpi_r3, &
-                     scatter_mpi_l,scatter_mpi_l1,scatter_mpi_l2,scatter_mpi_l3
-  END INTERFACE
-
-  
-  INTERFACE gather_mpi
-    MODULE PROCEDURE gather_mpi_i,gather_mpi_i1,gather_mpi_i2,gather_mpi_i3, &
-                     gather_mpi_r,gather_mpi_r1,gather_mpi_r2,gather_mpi_r3, &
-                     gather_mpi_l,gather_mpi_l1,gather_mpi_l2,gather_mpi_l3  
-  END INTERFACE
-  
-  INTERFACE scatter2D_mpi
-    MODULE PROCEDURE scatter2D_mpi_i,scatter2D_mpi_i1,scatter2D_mpi_i2,scatter2D_mpi_i3, &
-                     scatter2D_mpi_r,scatter2D_mpi_r1,scatter2D_mpi_r2,scatter2D_mpi_r3, &
-                     scatter2D_mpi_l,scatter2D_mpi_l1,scatter2D_mpi_l2,scatter2D_mpi_l3
-  END INTERFACE
-
-  INTERFACE gather2D_mpi
-    MODULE PROCEDURE gather2D_mpi_i,gather2D_mpi_i1,gather2D_mpi_i2,gather2D_mpi_i3, &
-                     gather2D_mpi_r,gather2D_mpi_r1,gather2D_mpi_r2,gather2D_mpi_r3, &
-                     gather2D_mpi_l,gather2D_mpi_l1,gather2D_mpi_l2,gather2D_mpi_l3
-  END INTERFACE 
-  
-  INTERFACE reduce_sum_mpi
-    MODULE PROCEDURE reduce_sum_mpi_i,reduce_sum_mpi_i1,reduce_sum_mpi_i2,reduce_sum_mpi_i3,reduce_sum_mpi_i4, &
-                     reduce_sum_mpi_r,reduce_sum_mpi_r1,reduce_sum_mpi_r2,reduce_sum_mpi_r3,reduce_sum_mpi_r4
-  END INTERFACE 
-
- INTERFACE grid1dTo2d_mpi
-    MODULE PROCEDURE grid1dTo2d_mpi_i,grid1dTo2d_mpi_i1,grid1dTo2d_mpi_i2,grid1dTo2d_mpi_i3, &
-                     grid1dTo2d_mpi_r,grid1dTo2d_mpi_r1,grid1dTo2d_mpi_r2,grid1dTo2d_mpi_r3, &
-                     grid1dTo2d_mpi_l,grid1dTo2d_mpi_l1,grid1dTo2d_mpi_l2,grid1dTo2d_mpi_l3
- END INTERFACE 
-
- INTERFACE grid2dTo1d_mpi
-    MODULE PROCEDURE grid2dTo1d_mpi_i,grid2dTo1d_mpi_i1,grid2dTo1d_mpi_i2,grid2dTo1d_mpi_i3, &
-                     grid2dTo1d_mpi_r,grid2dTo1d_mpi_r1,grid2dTo1d_mpi_r2,grid2dTo1d_mpi_r3, &
-                     grid2dTo1d_mpi_l,grid2dTo1d_mpi_l1,grid2dTo1d_mpi_l2,grid2dTo1d_mpi_l3
- END INTERFACE 
-    
-CONTAINS
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Broadcast --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-!! -- Les chaine de charactère -- !!
-
-  SUBROUTINE bcast_mpi_c(var1)
-  IMPLICIT NONE
-    CHARACTER(LEN=*),INTENT(INOUT) :: Var1
-   
-    CALL bcast_mpi_cgen(Var1,len(Var1))
-
-  END SUBROUTINE bcast_mpi_c
-
-!! -- Les entiers -- !!
-  
-  SUBROUTINE bcast_mpi_i(var)
-  USE mod_phys_lmdz_mpi_data, ONLY : is_mpi_root
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var
-    
-    INTEGER               :: var_tmp(1)
-    
-    IF (is_mpi_root) var_tmp(1)=var
-    CALL bcast_mpi_igen(Var_tmp,1)
-    var=var_tmp(1)
-    
-  END SUBROUTINE bcast_mpi_i
-
-  SUBROUTINE bcast_mpi_i1(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:)
-
-    CALL bcast_mpi_igen(Var,size(Var))
-    
-  END SUBROUTINE bcast_mpi_i1
-
-  SUBROUTINE bcast_mpi_i2(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:)
-   
-    CALL bcast_mpi_igen(Var,size(Var))
-  
-  END SUBROUTINE bcast_mpi_i2
-
-  SUBROUTINE bcast_mpi_i3(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:,:)
-   
-    CALL bcast_mpi_igen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_i3
-
-  SUBROUTINE bcast_mpi_i4(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:,:,:)
-   
-    CALL bcast_mpi_igen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_i4
-
-
-!! -- Les reels -- !!
-
-  SUBROUTINE bcast_mpi_r(var)
-  USE mod_phys_lmdz_mpi_data, ONLY : is_mpi_root
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var
-    REAL               :: var_tmp(1)
-    
-    IF (is_mpi_root) var_tmp(1)=var
-    CALL bcast_mpi_rgen(Var_tmp,1)
-    var=var_tmp(1)   
-
-  END SUBROUTINE bcast_mpi_r
-
-  SUBROUTINE bcast_mpi_r1(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:)
-   
-    CALL bcast_mpi_rgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_r1
-
-  SUBROUTINE bcast_mpi_r2(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:)
-   
-    CALL bcast_mpi_rgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_r2
-
-  SUBROUTINE bcast_mpi_r3(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:,:)
-   
-    CALL bcast_mpi_rgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_r3
-
-  SUBROUTINE bcast_mpi_r4(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:,:,:)
-   
-    CALL bcast_mpi_rgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_r4
-  
-!! -- Les booleans -- !!
-
-  SUBROUTINE bcast_mpi_l(var)
-  USE mod_phys_lmdz_mpi_data, ONLY : is_mpi_root
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var
-    LOGICAL               :: var_tmp(1)
-    
-    IF (is_mpi_root) var_tmp(1)=var
-    CALL bcast_mpi_lgen(Var_tmp,1)
-    var=var_tmp(1)   
-
-  END SUBROUTINE bcast_mpi_l
-
-  SUBROUTINE bcast_mpi_l1(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:)
-   
-    CALL bcast_mpi_lgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_l1
-
-  SUBROUTINE bcast_mpi_l2(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:)
-   
-    CALL bcast_mpi_lgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_l2
-
-  SUBROUTINE bcast_mpi_l3(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:,:)
-   
-    CALL bcast_mpi_lgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_l3
-
-  SUBROUTINE bcast_mpi_l4(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:,:,:)
-   
-    CALL bcast_mpi_lgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_l4
-  
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Scatter   --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  SUBROUTINE scatter_mpi_i(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    CALL scatter_mpi_igen(VarIn,Varout,1)
-    
-  END SUBROUTINE scatter_mpi_i
-
-  SUBROUTINE scatter_mpi_i1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    CALL scatter_mpi_igen(VarIn,Varout,Size(VarOut,2))
-    
-  END SUBROUTINE scatter_mpi_i1
-  
-  SUBROUTINE scatter_mpi_i2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL scatter_mpi_igen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3))
-
-  END SUBROUTINE scatter_mpi_i2
-
-  SUBROUTINE scatter_mpi_i3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    CALL scatter_mpi_igen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4))
-  
-  END SUBROUTINE scatter_mpi_i3
-
-
-  SUBROUTINE scatter_mpi_r(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-      CALL scatter_mpi_rgen(VarIn,Varout,1)
-  
-  END SUBROUTINE scatter_mpi_r
-
-  SUBROUTINE scatter_mpi_r1(VarIn, VarOut)
-  USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-  IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-      CALL scatter_mpi_rgen(VarIn,Varout,Size(VarOut,2))
-  
-  END SUBROUTINE scatter_mpi_r1
-  
-  SUBROUTINE scatter_mpi_r2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-      CALL scatter_mpi_rgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3))
-  
-  END SUBROUTINE scatter_mpi_r2
-
-  SUBROUTINE scatter_mpi_r3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-      CALL scatter_mpi_rgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4))
-  
-  END SUBROUTINE scatter_mpi_r3
-
-
-  SUBROUTINE scatter_mpi_l(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-      CALL scatter_mpi_lgen(VarIn,Varout,1)
-    
-  END SUBROUTINE scatter_mpi_l
-
-  SUBROUTINE scatter_mpi_l1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-      CALL scatter_mpi_lgen(VarIn,Varout,Size(VarOut,2))
-  
-  END SUBROUTINE scatter_mpi_l1
-  
-  SUBROUTINE scatter_mpi_l2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-      CALL scatter_mpi_lgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3))
-  
-  END SUBROUTINE scatter_mpi_l2
-
-  SUBROUTINE scatter_mpi_l3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-      CALL scatter_mpi_lgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4))
-  
-  END SUBROUTINE scatter_mpi_l3  
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Gather   --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 
-!!!!! --> Les entiers
-
-  SUBROUTINE gather_mpi_i(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-      CALL gather_mpi_igen(VarIn,VarOut,1)
-  
-  END SUBROUTINE gather_mpi_i
-  
-
-!!!!!
-
-  SUBROUTINE gather_mpi_i1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-      CALL gather_mpi_igen(VarIn,VarOut,Size(VarIn,2))
-  
-  END SUBROUTINE gather_mpi_i1
-
-!!!!!
-  
-  SUBROUTINE gather_mpi_i2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-      CALL gather_mpi_igen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3))
-  
-  END SUBROUTINE gather_mpi_i2
-
-!!!!!
-
-  SUBROUTINE gather_mpi_i3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-      CALL gather_mpi_igen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4))
-  
-  END SUBROUTINE gather_mpi_i3
-
-!!!!! --> Les reels
-
-  SUBROUTINE gather_mpi_r(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-      CALL gather_mpi_rgen(VarIn,VarOut,1)
-  
-  END SUBROUTINE gather_mpi_r
-
-!!!!!
-
-  SUBROUTINE gather_mpi_r1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-      CALL gather_mpi_rgen(VarIn,VarOut,Size(VarIn,2))
-  
-  END SUBROUTINE gather_mpi_r1
-
-!!!!!
-  
-  SUBROUTINE gather_mpi_r2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-      CALL gather_mpi_rgen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3))
-  
-  END SUBROUTINE gather_mpi_r2
-
-!!!!!
-
-  SUBROUTINE gather_mpi_r3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-      CALL gather_mpi_rgen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4))
-  
-  END SUBROUTINE gather_mpi_r3
-
-!!!!! --> Les booleen
-
-  SUBROUTINE gather_mpi_l(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-      CALL gather_mpi_lgen(VarIn,VarOut,1)
-  
-  END SUBROUTINE gather_mpi_l
-
-!!!!!
-
-  SUBROUTINE gather_mpi_l1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-      CALL gather_mpi_lgen(VarIn,VarOut,Size(VarIn,2))
-  
-  END SUBROUTINE gather_mpi_l1
-
-!!!!!
-  
-  SUBROUTINE gather_mpi_l2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-      CALL gather_mpi_lgen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3))
-  
-  END SUBROUTINE gather_mpi_l2
-
-!!!!!
-
-  SUBROUTINE gather_mpi_l3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    CALL gather_mpi_lgen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4))
-  
-  END SUBROUTINE gather_mpi_l3
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Scatter2D   --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  SUBROUTINE scatter2D_mpi_i(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    INTEGER,DIMENSION(klon_glo) :: Var_tmp    
-    
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_mpi_i
-
-  SUBROUTINE scatter2D_mpi_i1(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    INTEGER,DIMENSION(klon_glo,size(VarOut,2)) :: Var_tmp
-
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_mpi_i1
-
-  SUBROUTINE scatter2D_mpi_i2(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-
-    INTEGER,DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3)) :: Var_tmp
-
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_mpi_i2
-  
-  SUBROUTINE scatter2D_mpi_i3(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    INTEGER,DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3),size(VarOut,4)) :: Var_tmp
-
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
-    
-  END SUBROUTINE scatter2D_mpi_i3
-
-
-
-  SUBROUTINE scatter2D_mpi_r(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    REAL,DIMENSION(klon_glo) :: Var_tmp    
-    
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_mpi_R
-
-
-  SUBROUTINE scatter2D_mpi_r1(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    REAL,DIMENSION(klon_glo,size(VarOut,2)) :: Var_tmp
-    
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_mpi_r1
-
-
-  SUBROUTINE scatter2D_mpi_r2(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-
-    REAL,DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3)) :: Var_tmp
-    
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_mpi_r2
-  
-  SUBROUTINE scatter2D_mpi_r3(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    REAL,DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3),size(VarOut,4)) :: Var_tmp
-
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
- 
-  END SUBROUTINE scatter2D_mpi_r3
-  
-  
-  SUBROUTINE scatter2D_mpi_l(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    LOGICAL,DIMENSION(klon_glo) :: Var_tmp    
-    
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_mpi_l
-
-
-  SUBROUTINE scatter2D_mpi_l1(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    LOGICAL,DIMENSION(klon_glo,size(VarOut,2)) :: Var_tmp
-
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
-  
-  END SUBROUTINE scatter2D_mpi_l1
-
-
-  SUBROUTINE scatter2D_mpi_l2(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    LOGICAL, DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3)) :: Var_tmp
-  
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_mpi_l2
-  
-  SUBROUTINE scatter2D_mpi_l3(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    LOGICAL,DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3),size(VarOut,4)) :: Var_tmp
-
-    CALL grid2dTo1d_glo(VarIn,Var_tmp)
-    CALL scatter_mpi(Var_tmp,VarOut)
- 
-  END SUBROUTINE scatter2D_mpi_l3
-  
-  
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Gather2D   --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  SUBROUTINE gather2D_mpi_i(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    INTEGER,DIMENSION(klon_glo) :: Var_tmp
-    
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_i
-
-  SUBROUTINE gather2D_mpi_i1(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-
-    INTEGER,DIMENSION(klon_glo,size(VarOut,3)) :: Var_tmp
-
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_i1
-
-  SUBROUTINE gather2D_mpi_i2(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-
-    INTEGER,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4)) :: Var_tmp
-    
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_i2
-  
-  SUBROUTINE gather2D_mpi_i3(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
- 
-    INTEGER,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4),SIZE(VarOut,5)) :: Var_tmp
-    
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_i3
-
-
-
-  SUBROUTINE gather2D_mpi_r(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    REAL,DIMENSION(klon_glo) :: Var_tmp
-    
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_r
-
-  SUBROUTINE gather2D_mpi_r1(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    REAL,DIMENSION(klon_glo,size(VarOut,3)) :: Var_tmp
-
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_r1
-
-  SUBROUTINE gather2D_mpi_r2(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    REAL,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4)) :: Var_tmp
-
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_r2
-  
-  SUBROUTINE gather2D_mpi_r3(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
-    
-    REAL,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4),SIZE(VarOut,5)) :: Var_tmp
-    
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_r3
-
-  
-  
-  SUBROUTINE gather2D_mpi_l(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    LOGICAL,DIMENSION(klon_glo) :: Var_tmp
-    
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_l
-
-  SUBROUTINE gather2D_mpi_l1(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    LOGICAL,DIMENSION(klon_glo,size(VarOut,3)) :: Var_tmp
-
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_l1
-
-  SUBROUTINE gather2D_mpi_l2(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    LOGICAL,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4)) :: Var_tmp
-
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_l2
-  
-  SUBROUTINE gather2D_mpi_l3(VarIn, VarOut)
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
-    
-    LOGICAL,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4),SIZE(VarOut,5)) :: Var_tmp
-    
-    CALL gather_mpi(VarIn,Var_tmp)
-    CALL grid1dTo2d_glo(Var_tmp,VarOut)
-
-  END SUBROUTINE gather2D_mpi_l3
-  
-  
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des reduce_sum   --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  SUBROUTINE reduce_sum_mpi_i(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN)  :: VarIn
-    INTEGER,INTENT(OUT) :: VarOut
-    INTEGER             :: VarIn_tmp(1)
-    INTEGER             :: VarOut_tmp(1)
-    
-    VarIn_tmp(1)=VarIn    
-    CALL reduce_sum_mpi_igen(VarIn_tmp,Varout_tmp,1)
-    VarOut=VarOut_tmp(1)
-    
-  END SUBROUTINE reduce_sum_mpi_i
-
-  SUBROUTINE reduce_sum_mpi_i1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-    CALL reduce_sum_mpi_igen(VarIn,Varout,SIZE(VarIn))
-  
-  END SUBROUTINE reduce_sum_mpi_i1
-
-  SUBROUTINE reduce_sum_mpi_i2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    CALL reduce_sum_mpi_igen(VarIn,Varout,SIZE(VarIn))
-  
-  END SUBROUTINE reduce_sum_mpi_i2
-
-  SUBROUTINE reduce_sum_mpi_i3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL reduce_sum_mpi_igen(VarIn,Varout,SIZE(VarIn))
-  
-  END SUBROUTINE reduce_sum_mpi_i3
-
-  SUBROUTINE reduce_sum_mpi_i4(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    CALL reduce_sum_mpi_igen(VarIn,Varout,SIZE(VarIn))
-  
-  END SUBROUTINE reduce_sum_mpi_i4                  
-  
-  
-  SUBROUTINE reduce_sum_mpi_r(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN)  :: VarIn
-    REAL,INTENT(OUT) :: VarOut
-    REAL             :: VarIn_tmp(1)
-    REAL             :: VarOut_tmp(1)
-    
-    VarIn_tmp(1)=VarIn    
-    CALL reduce_sum_mpi_rgen(VarIn_tmp,Varout_tmp,1)
-    VarOut=VarOut_tmp(1)
-  
-  END SUBROUTINE reduce_sum_mpi_r
-
-  SUBROUTINE reduce_sum_mpi_r1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-    CALL reduce_sum_mpi_rgen(VarIn,Varout,SIZE(VarIn))
-     
-  END SUBROUTINE reduce_sum_mpi_r1
-
-  SUBROUTINE reduce_sum_mpi_r2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    CALL reduce_sum_mpi_rgen(VarIn,Varout,SIZE(VarIn))
-  
-  END SUBROUTINE reduce_sum_mpi_r2
-
-  SUBROUTINE reduce_sum_mpi_r3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL reduce_sum_mpi_rgen(VarIn,Varout,SIZE(VarIn))
-  
-  END SUBROUTINE reduce_sum_mpi_r3
-
-  SUBROUTINE reduce_sum_mpi_r4(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    CALL reduce_sum_mpi_rgen(VarIn,Varout,SIZE(VarIn))
-  
-  END SUBROUTINE reduce_sum_mpi_r4 
-  
-
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! SUBROUTINE grid1dTo2d  !!  
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-
-  SUBROUTINE grid1dTo2d_mpi_i(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:)     :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_igen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid1dTo2d_mpi_i
-  
-
-  SUBROUTINE grid1dTo2d_mpi_i1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:)     :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_igen(VarIn,VarOut,size(VarIn,2))
-  
-  END SUBROUTINE grid1dTo2d_mpi_i1
-
-  SUBROUTINE grid1dTo2d_mpi_i2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_igen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
-  
-  END SUBROUTINE grid1dTo2d_mpi_i2
-  
-  SUBROUTINE grid1dTo2d_mpi_i3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_igen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid1dTo2d_mpi_i3
-
-
-  SUBROUTINE grid1dTo2d_mpi_r(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:)     :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_rgen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid1dTo2d_mpi_r
-  
-
-  SUBROUTINE grid1dTo2d_mpi_r1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:)     :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_rgen(VarIn,VarOut,size(VarIn,2))
-  
-  END SUBROUTINE grid1dTo2d_mpi_r1
-
-  SUBROUTINE grid1dTo2d_mpi_r2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_rgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
-  
-  END SUBROUTINE grid1dTo2d_mpi_r2
-  
-  SUBROUTINE grid1dTo2d_mpi_r3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_rgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid1dTo2d_mpi_r3
-  
-  
-  
-  SUBROUTINE grid1dTo2d_mpi_l(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:)     :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_lgen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid1dTo2d_mpi_l
-  
-
-  SUBROUTINE grid1dTo2d_mpi_l1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:)     :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_lgen(VarIn,VarOut,size(VarIn,2))
-  
-  END SUBROUTINE grid1dTo2d_mpi_l1
-
-  SUBROUTINE grid1dTo2d_mpi_l2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_lgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
-  
-  END SUBROUTINE grid1dTo2d_mpi_l2
-  
-  SUBROUTINE grid1dTo2d_mpi_l3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
-    
-    CALL grid1dTo2d_mpi_lgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid1dTo2d_mpi_l3
-
-
-  SUBROUTINE grid2dTo1d_mpi_i(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_igen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid2dTo1d_mpi_i
-  
-
-  SUBROUTINE grid2dTo1d_mpi_i1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_igen(VarIn,VarOut,size(VarIn,3))
-  
-  END SUBROUTINE grid2dTo1d_mpi_i1
-
-  SUBROUTINE grid2dTo1d_mpi_i2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_igen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid2dTo1d_mpi_i2
-  
-  SUBROUTINE grid2dTo1d_mpi_i3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_igen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
-  
-  END SUBROUTINE grid2dTo1d_mpi_i3
- 
-
-
-
-  SUBROUTINE grid2dTo1d_mpi_r(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_rgen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid2dTo1d_mpi_r
-  
-
-  SUBROUTINE grid2dTo1d_mpi_r1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_rgen(VarIn,VarOut,size(VarIn,3))
-  
-  END SUBROUTINE grid2dTo1d_mpi_r1
-
-  SUBROUTINE grid2dTo1d_mpi_r2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_rgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid2dTo1d_mpi_r2
-  
-  SUBROUTINE grid2dTo1d_mpi_r3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_rgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
-  
-  END SUBROUTINE grid2dTo1d_mpi_r3
-
-
-
-  SUBROUTINE grid2dTo1d_mpi_l(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_lgen(VarIn,VarOut,1)
-  
-  END SUBROUTINE grid2dTo1d_mpi_l
-  
-
-  SUBROUTINE grid2dTo1d_mpi_l1(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_lgen(VarIn,VarOut,size(VarIn,3))
-  
-  END SUBROUTINE grid2dTo1d_mpi_l1
-
-
-
-  SUBROUTINE grid2dTo1d_mpi_l2(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_lgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
-  
-  END SUBROUTINE grid2dTo1d_mpi_l2
-
-  
-  SUBROUTINE grid2dTo1d_mpi_l3(VarIn,VarOut)  
-  IMPLICIT NONE  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
-    
-    CALL grid2dTo1d_mpi_lgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
-  
-  END SUBROUTINE grid2dTo1d_mpi_l3
-
-               
-
-
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! DEFINITION DES FONCTIONS DE TRANSFERT GENERIQUES !
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  SUBROUTINE bcast_mpi_cgen(var,nb)
-    USE mod_phys_lmdz_mpi_data , mpi_root_x=>mpi_root
-    IMPLICIT NONE
-    
-    CHARACTER(LEN=*),INTENT(INOUT) :: Var
-    INTEGER,INTENT(IN) :: nb
-    
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-    INTEGER :: ierr
-
-    IF (.not.is_using_mpi) RETURN
-    
-#ifdef CPP_MPI
-    CALL MPI_BCAST(Var,nb,MPI_CHARACTER,mpi_root_x,COMM_LMDZ_PHY,ierr)
-#endif
-        
-  END SUBROUTINE bcast_mpi_cgen
-
-
-      
-  SUBROUTINE bcast_mpi_igen(var,nb)
-    USE mod_phys_lmdz_mpi_data , mpi_root_x=>mpi_root
-    IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: nb
-    INTEGER,DIMENSION(nb),INTENT(INOUT) :: Var
-    
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-    INTEGER :: ierr
-
-    IF (.not.is_using_mpi) RETURN
-
-#ifdef CPP_MPI
-    CALL MPI_BCAST(Var,nb,MPI_INTEGER,mpi_root_x,COMM_LMDZ_PHY,ierr)
-#endif
-        
-  END SUBROUTINE bcast_mpi_igen
-
-
-
-  
-  SUBROUTINE bcast_mpi_rgen(var,nb)
-    USE mod_phys_lmdz_mpi_data , mpi_root_x=>mpi_root
-    IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: nb
-    REAL,DIMENSION(nb),INTENT(INOUT) :: Var
-    
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-    INTEGER :: ierr
-
-    IF (.not.is_using_mpi) RETURN
-
-#ifdef CPP_MPI
-    CALL MPI_BCAST(Var,nb,MPI_REAL_LMDZ,mpi_root_x,COMM_LMDZ_PHY,ierr)
-#endif
-    
-  END SUBROUTINE bcast_mpi_rgen
-  
-
-
-
-  SUBROUTINE bcast_mpi_lgen(var,nb)
-    USE mod_phys_lmdz_mpi_data ,  mpi_root_x=>mpi_root
-    IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: nb
-    LOGICAL,DIMENSION(nb),INTENT(INOUT) :: Var
-    
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-    INTEGER :: ierr
-
-    IF (.not.is_using_mpi) RETURN
-
-#ifdef CPP_MPI
-    CALL MPI_BCAST(Var,nb,MPI_LOGICAL,mpi_root_x,COMM_LMDZ_PHY,ierr)
-#endif
-
-  END SUBROUTINE bcast_mpi_lgen
-
-  
-
-  SUBROUTINE scatter_mpi_igen(VarIn, VarOut, dimsize)
-    USE mod_phys_lmdz_mpi_data , mpi_root_x=>mpi_root
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN) :: dimsize
-    INTEGER,INTENT(IN),DIMENSION(klon_glo,dimsize) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
-  
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-    INTEGER,DIMENSION(0:mpi_size-1) :: displs
-    INTEGER,DIMENSION(0:mpi_size-1) :: counts
-    INTEGER,DIMENSION(dimsize*klon_glo) :: VarTmp
-    INTEGER :: nb,i,index,rank
-    INTEGER :: ierr
-
-
-    IF (.not.is_using_mpi) THEN
-      VarOut(:,:)=VarIn(:,:)
-      RETURN
-    ENDIF
-
-    
-    IF (is_mpi_root) THEN
-      Index=1
-      DO rank=0,mpi_size-1
-        nb=klon_mpi_para_nb(rank)
-        displs(rank)=Index-1
-        counts(rank)=nb*dimsize
-        DO i=1,dimsize
-          VarTmp(Index:Index+nb-1)=VarIn(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)
-          Index=Index+nb
-        ENDDO
-      ENDDO
-    ENDIF
-      
-#ifdef CPP_MPI 
-    CALL MPI_SCATTERV(VarTmp,counts,displs,MPI_INTEGER,VarOut,klon_mpi*dimsize,   &
-                      MPI_INTEGER,mpi_root_x, COMM_LMDZ_PHY,ierr)
-#endif
-
-  END SUBROUTINE scatter_mpi_igen
-
-  SUBROUTINE scatter_mpi_rgen(VarIn, VarOut, dimsize)
-    USE mod_phys_lmdz_mpi_data , mpi_root_x=>mpi_root
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN) :: dimsize
-    REAL,INTENT(IN),DIMENSION(klon_glo,dimsize) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
-  
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-
-    INTEGER,DIMENSION(0:mpi_size-1) :: displs
-    INTEGER,DIMENSION(0:mpi_size-1) :: counts
-    REAL,DIMENSION(dimsize*klon_glo) :: VarTmp
-    INTEGER :: nb,i,index,rank
-    INTEGER :: ierr
-
-    IF (.not.is_using_mpi) THEN
-      VarOut(:,:)=VarIn(:,:)
-      RETURN
-    ENDIF
-    
-    IF (is_mpi_root) THEN
-      Index=1
-      DO rank=0,mpi_size-1
-        nb=klon_mpi_para_nb(rank)
-        displs(rank)=Index-1
-        counts(rank)=nb*dimsize
-        DO i=1,dimsize
-          VarTmp(Index:Index+nb-1)=VarIn(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)
-          Index=Index+nb
-        ENDDO
-      ENDDO
-    ENDIF
-      
-#ifdef CPP_MPI 
-    CALL MPI_SCATTERV(VarTmp,counts,displs,MPI_REAL_LMDZ,VarOut,klon_mpi*dimsize,   &
-                      MPI_REAL_LMDZ,mpi_root_x, COMM_LMDZ_PHY,ierr)
-
-#endif
-
-  END SUBROUTINE scatter_mpi_rgen
-
-  
-  SUBROUTINE scatter_mpi_lgen(VarIn, VarOut, dimsize)
-    USE mod_phys_lmdz_mpi_data , mpi_root_x=>mpi_root
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN) :: dimsize
-    LOGICAL,INTENT(IN),DIMENSION(klon_glo,dimsize) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
-  
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-
-    INTEGER,DIMENSION(0:mpi_size-1) :: displs
-    INTEGER,DIMENSION(0:mpi_size-1) :: counts
-    LOGICAL,DIMENSION(dimsize*klon_glo) :: VarTmp
-    INTEGER :: nb,i,index,rank
-    INTEGER :: ierr
-
-    IF (.not.is_using_mpi) THEN
-      VarOut(:,:)=VarIn(:,:)
-      RETURN
-    ENDIF
-    
-    IF (is_mpi_root) THEN
-      Index=1
-      DO rank=0,mpi_size-1
-        nb=klon_mpi_para_nb(rank)
-        displs(rank)=Index-1
-        counts(rank)=nb*dimsize
-        DO i=1,dimsize
-          VarTmp(Index:Index+nb-1)=VarIn(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)
-          Index=Index+nb
-        ENDDO
-      ENDDO
-    ENDIF
-      
-#ifdef CPP_MPI
-    CALL MPI_SCATTERV(VarTmp,counts,displs,MPI_LOGICAL,VarOut,klon_mpi*dimsize,   &
-                      MPI_LOGICAL,mpi_root_x, COMM_LMDZ_PHY,ierr)
-#endif
-
-  END SUBROUTINE scatter_mpi_lgen  
-
-
-
-
-  SUBROUTINE gather_mpi_igen(VarIn, VarOut, dimsize)
-    USE mod_phys_lmdz_mpi_data , mpi_root_x=>mpi_root
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-    
-    INTEGER,INTENT(IN) :: dimsize
-    INTEGER,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(klon_glo,dimsize) :: VarOut
-  
-    INTEGER,DIMENSION(0:mpi_size-1) :: displs
-    INTEGER,DIMENSION(0:mpi_size-1) :: counts
-    INTEGER,DIMENSION(dimsize*klon_glo) :: VarTmp
-    INTEGER :: nb,i,index,rank
-    INTEGER :: ierr
-
-    IF (.not.is_using_mpi) THEN
-      VarOut(:,:)=VarIn(:,:)
-      RETURN
-    ENDIF
-
-    IF (is_mpi_root) THEN
-      Index=1
-      DO rank=0,mpi_size-1
-        nb=klon_mpi_para_nb(rank)
-        displs(rank)=Index-1
-        counts(rank)=nb*dimsize
-        Index=Index+nb*dimsize
-      ENDDO
-     
-    ENDIF
-    
-#ifdef CPP_MPI
-    CALL MPI_GATHERV(VarIn,klon_mpi*dimsize,MPI_INTEGER,VarTmp,counts,displs,   &
-                     MPI_INTEGER,mpi_root_x, COMM_LMDZ_PHY,ierr)
-#endif
-
-                          
-    IF (is_mpi_root) THEN
-      Index=1
-      DO rank=0,mpi_size-1
-        nb=klon_mpi_para_nb(rank)
-        DO i=1,dimsize
-          VarOut(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)=VarTmp(Index:Index+nb-1)
-          Index=Index+nb
-        ENDDO
-      ENDDO
-    ENDIF
-
-  END SUBROUTINE gather_mpi_igen  
-
-  SUBROUTINE gather_mpi_rgen(VarIn, VarOut, dimsize)
-    USE mod_phys_lmdz_mpi_data , mpi_root_x=>mpi_root
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-    
-    INTEGER,INTENT(IN) :: dimsize
-    REAL,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(klon_glo,dimsize) :: VarOut
-  
-    INTEGER,DIMENSION(0:mpi_size-1) :: displs
-    INTEGER,DIMENSION(0:mpi_size-1) :: counts
-    REAL,DIMENSION(dimsize*klon_glo) :: VarTmp
-    INTEGER :: nb,i,index,rank
-    INTEGER :: ierr
-
-    IF (is_mpi_root) THEN
-      Index=1
-      DO rank=0,mpi_size-1
-        nb=klon_mpi_para_nb(rank)
-        displs(rank)=Index-1
-        counts(rank)=nb*dimsize
-        Index=Index+nb*dimsize
-      ENDDO
-    ENDIF
-    
-    IF (.not.is_using_mpi) THEN
-      VarOut(:,:)=VarIn(:,:)
-      RETURN
-    ENDIF
-
-#ifdef CPP_MPI
-    CALL MPI_GATHERV(VarIn,klon_mpi*dimsize,MPI_REAL_LMDZ,VarTmp,counts,displs,   &
-                      MPI_REAL_LMDZ,mpi_root_x, COMM_LMDZ_PHY,ierr)
-#endif
-                          
-    IF (is_mpi_root) THEN
-      Index=1
-      DO rank=0,mpi_size-1
-        nb=klon_mpi_para_nb(rank)
-        DO i=1,dimsize
-          VarOut(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)=VarTmp(Index:Index+nb-1)
-          Index=Index+nb
-        ENDDO
-      ENDDO
-    ENDIF
-
-  END SUBROUTINE gather_mpi_rgen  
-
-  SUBROUTINE gather_mpi_lgen(VarIn, VarOut, dimsize)
-    USE mod_phys_lmdz_mpi_data , mpi_root_x=>mpi_root
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN) :: dimsize
-    LOGICAL,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(klon_glo,dimsize) :: VarOut
-  
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-
-    INTEGER,DIMENSION(0:mpi_size-1) :: displs
-    INTEGER,DIMENSION(0:mpi_size-1) :: counts
-    LOGICAL,DIMENSION(dimsize*klon_glo) :: VarTmp
-    INTEGER :: nb,i,index,rank
-    INTEGER :: ierr
-    
-    IF (.not.is_using_mpi) THEN
-      VarOut(:,:)=VarIn(:,:)
-      RETURN
-    ENDIF
-
-    IF (is_mpi_root) THEN
-      Index=1
-      DO rank=0,mpi_size-1
-        nb=klon_mpi_para_nb(rank)
-        displs(rank)=Index-1
-        counts(rank)=nb*dimsize
-        Index=Index+nb*dimsize
-      ENDDO
-    ENDIF
-    
-
-#ifdef CPP_MPI
-    CALL MPI_GATHERV(VarIn,klon_mpi*dimsize,MPI_LOGICAL,VarTmp,counts,displs,   &
-                      MPI_LOGICAL,mpi_root_x, COMM_LMDZ_PHY,ierr)
-#endif
-                          
-    IF (is_mpi_root) THEN
-      Index=1
-      DO rank=0,mpi_size-1
-        nb=klon_mpi_para_nb(rank)
-        DO i=1,dimsize
-          VarOut(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)=VarTmp(Index:Index+nb-1)
-          Index=Index+nb
-        ENDDO
-      ENDDO
-    ENDIF
-
-  END SUBROUTINE gather_mpi_lgen
-  
-
-
-  SUBROUTINE reduce_sum_mpi_igen(VarIn,VarOut,nb)
-    USE mod_phys_lmdz_mpi_data , mpi_root_x=>mpi_root
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-    
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-   
-    INTEGER,INTENT(IN) :: nb
-    INTEGER,DIMENSION(nb),INTENT(IN) :: VarIn
-    INTEGER,DIMENSION(nb),INTENT(OUT) :: VarOut    
-    INTEGER :: ierr
-   
-    IF (.not.is_using_mpi) THEN
-      VarOut(:)=VarIn(:)
-      RETURN
-    ENDIF
-
-
-#ifdef CPP_MPI
-    CALL MPI_REDUCE(VarIn,VarOut,nb,MPI_INTEGER,MPI_SUM,mpi_root_x,COMM_LMDZ_PHY,ierr)
-#endif
-            
-  END SUBROUTINE reduce_sum_mpi_igen
-  
-  SUBROUTINE reduce_sum_mpi_rgen(VarIn,VarOut,nb)
-    USE mod_phys_lmdz_mpi_data , mpi_root_x=>mpi_root
-    USE mod_grid_phy_lmdz
-
-    IMPLICIT NONE
-
-#ifdef CPP_MPI
-    INCLUDE 'mpif.h'
-#endif
-    
-    INTEGER,INTENT(IN) :: nb
-    REAL,DIMENSION(nb),INTENT(IN) :: VarIn
-    REAL,DIMENSION(nb),INTENT(OUT) :: VarOut    
-    INTEGER :: ierr
- 
-    IF (.not.is_using_mpi) THEN
-      VarOut(:)=VarIn(:)
-      RETURN
-    ENDIF
-   
-#ifdef CPP_MPI
-    CALL MPI_REDUCE(VarIn,VarOut,nb,MPI_REAL_LMDZ,MPI_SUM,mpi_root_x,COMM_LMDZ_PHY,ierr)
-#endif
-        
-  END SUBROUTINE reduce_sum_mpi_rgen
-
-
-
-  SUBROUTINE grid1dTo2d_mpi_igen(VarIn,VarOut,dimsize)
-    USE mod_phys_lmdz_mpi_data
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: dimsize
-    INTEGER,INTENT(IN) ,DIMENSION(klon_mpi,dimsize)       :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(nbp_lon*jj_nb,dimsize)  :: VarOut
-    INTEGER :: i,ij,Offset
-
-    
-    VarOut(1:nbp_lon,:)=0
-    VarOut(nbp_lon*(jj_nb-1)+1:nbp_lon*jj_nb,:)=0
-    
-    offset=ii_begin
-    IF (is_north_pole) Offset=nbp_lon
-    
-    
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        VarOut(ij+offset-1,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO
-    
-    
-    IF (is_north_pole) THEN 
-      DO i=1,dimsize
-        DO ij=1,nbp_lon
-         VarOut(ij,i)=VarIn(1,i)
-        ENDDO
-      ENDDO
-    ENDIF
-    
-    IF (is_south_pole) THEN 
-      DO i=1,dimsize
-        DO ij=nbp_lon*(jj_nb-1)+1,nbp_lon*jj_nb
-         VarOut(ij,i)=VarIn(klon_mpi,i)
-        ENDDO
-      ENDDO
-    ENDIF
-
-  END SUBROUTINE grid1dTo2d_mpi_igen   
-
-
-  SUBROUTINE grid1dTo2d_mpi_rgen(VarIn,VarOut,dimsize)
-    USE mod_phys_lmdz_mpi_data
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: dimsize
-    REAL,INTENT(IN) ,DIMENSION(klon_mpi,dimsize)       :: VarIn
-    REAL,INTENT(OUT),DIMENSION(nbp_lon*jj_nb,dimsize)  :: VarOut
-    INTEGER :: i,ij,Offset
-
-    
-    VarOut(1:nbp_lon,:)=0
-    VarOut(nbp_lon*(jj_nb-1)+1:nbp_lon*jj_nb,:)=0
-    
-    offset=ii_begin
-    IF (is_north_pole) Offset=nbp_lon
-    
-    
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        VarOut(ij+offset-1,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO
-    
-    
-    IF (is_north_pole) THEN 
-      DO i=1,dimsize
-        DO ij=1,nbp_lon
-         VarOut(ij,i)=VarIn(1,i)
-        ENDDO
-      ENDDO
-    ENDIF
-    
-    IF (is_south_pole) THEN 
-      DO i=1,dimsize
-        DO ij=nbp_lon*(jj_nb-1)+1,nbp_lon*jj_nb
-         VarOut(ij,i)=VarIn(klon_mpi,i)
-        ENDDO
-      ENDDO
-    ENDIF
-
-   END SUBROUTINE grid1dTo2d_mpi_rgen   
-
-
-
-  SUBROUTINE grid1dTo2d_mpi_lgen(VarIn,VarOut,dimsize)
-    USE mod_phys_lmdz_mpi_data
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: dimsize
-    LOGICAL,INTENT(IN) ,DIMENSION(klon_mpi,dimsize)       :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(nbp_lon*jj_nb,dimsize)  :: VarOut
-    INTEGER :: i,ij,Offset
-
-    
-    VarOut(1:nbp_lon,:)=.FALSE.
-    VarOut(nbp_lon*(jj_nb-1)+1:nbp_lon*jj_nb,:)=.FALSE.
-    
-    offset=ii_begin
-    IF (is_north_pole) Offset=nbp_lon
-    
-    
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        VarOut(ij+offset-1,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO
-    
-    
-    IF (is_north_pole) THEN 
-      DO i=1,dimsize
-        DO ij=1,nbp_lon
-         VarOut(ij,i)=VarIn(1,i)
-        ENDDO
-      ENDDO
-    ENDIF
-    
-    IF (is_south_pole) THEN 
-      DO i=1,dimsize
-        DO ij=nbp_lon*(jj_nb-1)+1,nbp_lon*jj_nb
-         VarOut(ij,i)=VarIn(klon_mpi,i)
-        ENDDO
-      ENDDO
-    ENDIF
-
-   END SUBROUTINE grid1dTo2d_mpi_lgen   
-
-  
-
-
-  SUBROUTINE grid2dTo1d_mpi_igen(VarIn,VarOut,dimsize)
-    USE mod_phys_lmdz_mpi_data
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: dimsize
-    INTEGER,INTENT(IN) ,DIMENSION(nbp_lon*jj_nb,dimsize) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(klon_mpi,dimsize)      :: VarOut
-    INTEGER :: i,ij,offset
-
-    offset=ii_begin
-    IF (is_north_pole) offset=nbp_lon
-
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        VarOut(ij,i)=VarIn(ij+offset-1,i)
-      ENDDO
-    ENDDO
-
-    IF (is_north_pole) THEN 
-      DO i=1,dimsize
-        VarOut(1,i)=VarIn(1,i)
-      ENDDO
-    ENDIF
-    
-    
-  END SUBROUTINE grid2dTo1d_mpi_igen   
-
-
-
-  SUBROUTINE grid2dTo1d_mpi_rgen(VarIn,VarOut,dimsize)
-    USE mod_phys_lmdz_mpi_data
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: dimsize
-    REAL,INTENT(IN) ,DIMENSION(nbp_lon*jj_nb,dimsize) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize)      :: VarOut
-    INTEGER :: i,ij,offset
-
-    offset=ii_begin
-    IF (is_north_pole) offset=nbp_lon
-
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        VarOut(ij,i)=VarIn(ij+offset-1,i)
-      ENDDO
-    ENDDO
-
-    IF (is_north_pole) THEN 
-      DO i=1,dimsize
-         VarOut(1,i)=VarIn(1,i)
-      ENDDO
-    ENDIF
-    
-    
-  END SUBROUTINE grid2dTo1d_mpi_rgen   
-  
-
-  SUBROUTINE grid2dTo1d_mpi_lgen(VarIn,VarOut,dimsize)
-    USE mod_phys_lmdz_mpi_data
-    USE mod_grid_phy_lmdz
-    IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: dimsize
-    LOGICAL,INTENT(IN) ,DIMENSION(nbp_lon*jj_nb,dimsize) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize)      :: VarOut
-    INTEGER :: i,ij,offset
-
-    offset=ii_begin
-    IF (is_north_pole) offset=nbp_lon
-
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        VarOut(ij,i)=VarIn(ij+offset-1,i)
-      ENDDO
-    ENDDO
-
-    IF (is_north_pole) THEN 
-      DO i=1,dimsize
-        VarOut(1,i)=VarIn(1,i)
-      ENDDO
-    ENDIF
-    
-    
-  END SUBROUTINE grid2dTo1d_mpi_lgen   
-
-END MODULE mod_phys_lmdz_mpi_transfert
Index: DZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_omp_data.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_omp_data.F90	(revision 2407)
+++ 	(revision )
@@ -1,109 +1,0 @@
-!
-!$Id$
-!
-MODULE mod_phys_lmdz_omp_data
-
-  INTEGER,SAVE :: omp_size
-  INTEGER,SAVE :: omp_rank
-  LOGICAL,SAVE :: is_omp_root
-  LOGICAL,SAVE :: is_using_omp
-  
-  INTEGER,SAVE,DIMENSION(:),ALLOCATABLE :: klon_omp_para_nb
-  INTEGER,SAVE,DIMENSION(:),ALLOCATABLE :: klon_omp_para_begin
-  INTEGER,SAVE,DIMENSION(:),ALLOCATABLE :: klon_omp_para_end    
-  
-  INTEGER,SAVE :: klon_omp
-  INTEGER,SAVE :: klon_omp_begin
-  INTEGER,SAVE :: klon_omp_end
-!$OMP  THREADPRIVATE(omp_rank,klon_omp,is_omp_root,klon_omp_begin,klon_omp_end)
-
-CONTAINS
-  
-  SUBROUTINE Init_phys_lmdz_omp_data(klon_mpi)
-    USE dimphy
-    IMPLICIT NONE
-    INTEGER, INTENT(in) :: klon_mpi
-
-    INTEGER :: i
-
-    CHARACTER (LEN=20) :: modname='Init_phys_lmdz_omp_data'
-    CHARACTER (LEN=80) :: abort_message
-
-
-#ifdef CPP_OMP    
-    INTEGER :: OMP_GET_NUM_THREADS
-    EXTERNAL OMP_GET_NUM_THREADS
-    INTEGER :: OMP_GET_THREAD_NUM
-    EXTERNAL OMP_GET_THREAD_NUM
-#endif  
-
-#ifdef CPP_OMP
-!$OMP MASTER
-        is_using_omp=.TRUE.
-        omp_size=OMP_GET_NUM_THREADS()
-!$OMP END MASTER
-        omp_rank=OMP_GET_THREAD_NUM()    
-#else    
-    is_using_omp=.FALSE.
-    omp_size=1
-    omp_rank=0
-#endif
-
-   is_omp_root=.FALSE.
-!$OMP MASTER
-   IF (omp_rank==0) THEN
-     is_omp_root=.TRUE.
-   ELSE
-     abort_message = 'ANORMAL : OMP_MASTER /= 0'
-     CALL abort_gcm (modname,abort_message,1)
-   ENDIF
-!$OMP END MASTER
-
-
-!$OMP MASTER 
-    ALLOCATE(klon_omp_para_nb(0:omp_size-1))
-    ALLOCATE(klon_omp_para_begin(0:omp_size-1))
-    ALLOCATE(klon_omp_para_end(0:omp_size-1))
-    
-    DO i=0,omp_size-1
-      klon_omp_para_nb(i)=klon_mpi/omp_size
-      IF (i<MOD(klon_mpi,omp_size)) klon_omp_para_nb(i)=klon_omp_para_nb(i)+1
-    ENDDO
-    
-    klon_omp_para_begin(0) = 1
-    klon_omp_para_end(0) = klon_omp_para_nb(0)
-    
-    DO i=1,omp_size-1
-      klon_omp_para_begin(i)=klon_omp_para_end(i-1)+1
-      klon_omp_para_end(i)=klon_omp_para_begin(i)+klon_omp_para_nb(i)-1
-    ENDDO
-!$OMP END MASTER
-!$OMP BARRIER
-   
-    klon_omp=klon_omp_para_nb(omp_rank)
-    klon_omp_begin=klon_omp_para_begin(omp_rank)
-    klon_omp_end=klon_omp_para_end(omp_rank)
-    
-    CALL Print_module_data
-    
-  END SUBROUTINE Init_phys_lmdz_omp_data
-
-  SUBROUTINE Print_module_data
-  IMPLICIT NONE
-  INCLUDE "iniprint.h"
-
-!$OMP CRITICAL  
-  WRITE(lunout,*)'--------> TASK ',omp_rank
-  WRITE(lunout,*)'omp_size =',omp_size
-  WRITE(lunout,*)'omp_rank =',omp_rank
-  WRITE(lunout,*)'is_omp_root =',is_omp_root
-  WRITE(lunout,*)'klon_omp_para_nb =',klon_omp_para_nb
-  WRITE(lunout,*)'klon_omp_para_begin =',klon_omp_para_begin
-  WRITE(lunout,*)'klon_omp_para_end =',klon_omp_para_end    
-  WRITE(lunout,*)'klon_omp =',klon_omp
-  WRITE(lunout,*)'klon_omp_begin =',klon_omp_begin
-  WRITE(lunout,*)'klon_omp_end =',klon_omp_end    
-!$OMP END CRITICAL
-
-  END SUBROUTINE Print_module_data
-END MODULE mod_phys_lmdz_omp_data
Index: DZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_omp_transfert.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_omp_transfert.F90	(revision 2407)
+++ 	(revision )
@@ -1,1064 +1,0 @@
-!
-!$Header$
-!
-MODULE mod_phys_lmdz_omp_transfert
-
-  PRIVATE
-  
-  INTEGER,PARAMETER :: grow_factor=1.5
-  INTEGER,PARAMETER :: size_min=1024
-  
-  CHARACTER(LEN=size_min),SAVE            :: buffer_c
-!  INTEGER,SAVE                            :: size_c=0
-  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:)   :: buffer_i
-  INTEGER,SAVE                            :: size_i=0
-  REAL,SAVE,ALLOCATABLE,DIMENSION(:)      :: buffer_r
-  INTEGER,SAVE                            :: size_r=0
-  LOGICAL,SAVE,ALLOCATABLE,DIMENSION(:)   :: buffer_l
-  INTEGER,SAVE                            :: size_l=0
-
-
-  
-  
-  INTERFACE bcast_omp
-    MODULE PROCEDURE bcast_omp_c,                                                     &
-                     bcast_omp_i,bcast_omp_i1,bcast_omp_i2,bcast_omp_i3,bcast_omp_i4, &
-                     bcast_omp_r,bcast_omp_r1,bcast_omp_r2,bcast_omp_r3,bcast_omp_r4, &
-                     bcast_omp_l,bcast_omp_l1,bcast_omp_l2,bcast_omp_l3,bcast_omp_l4
-  END INTERFACE
-
-  INTERFACE scatter_omp
-    MODULE PROCEDURE scatter_omp_i,scatter_omp_i1,scatter_omp_i2,scatter_omp_i3, &
-                     scatter_omp_r,scatter_omp_r1,scatter_omp_r2,scatter_omp_r3, &
-                     scatter_omp_l,scatter_omp_l1,scatter_omp_l2,scatter_omp_l3
-  END INTERFACE
-
-  
-  INTERFACE gather_omp
-    MODULE PROCEDURE gather_omp_i,gather_omp_i1,gather_omp_i2,gather_omp_i3, &
-                     gather_omp_r,gather_omp_r1,gather_omp_r2,gather_omp_r3, &
-                     gather_omp_l,gather_omp_l1,gather_omp_l2,gather_omp_l3  
-  END INTERFACE
-  
-  
-  INTERFACE reduce_sum_omp
-    MODULE PROCEDURE reduce_sum_omp_i,reduce_sum_omp_i1,reduce_sum_omp_i2,reduce_sum_omp_i3,reduce_sum_omp_i4, &
-                     reduce_sum_omp_r,reduce_sum_omp_r1,reduce_sum_omp_r2,reduce_sum_omp_r3,reduce_sum_omp_r4
-  END INTERFACE 
-
-
-  PUBLIC bcast_omp,scatter_omp,gather_omp,reduce_sum_omp, omp_barrier
-
-CONTAINS
-
-  SUBROUTINE omp_barrier
-  IMPLICIT NONE
-
-!$OMP BARRIER
-
-  END SUBROUTINE omp_barrier
-  
-  SUBROUTINE check_buffer_i(buff_size)
-  IMPLICIT NONE
-  INTEGER :: buff_size
-
-!$OMP BARRIER
-!$OMP MASTER
-    IF (buff_size>size_i) THEN
-      IF (ALLOCATED(buffer_i)) DEALLOCATE(buffer_i)
-      size_i=MAX(size_min,INT(grow_factor*buff_size))
-      ALLOCATE(buffer_i(size_i))
-    ENDIF
-!$OMP END MASTER
-!$OMP BARRIER
-  
-  END SUBROUTINE check_buffer_i
-  
-  SUBROUTINE check_buffer_r(buff_size)
-  IMPLICIT NONE
-  INTEGER :: buff_size
-
-!$OMP BARRIER
-!$OMP MASTER
-    IF (buff_size>size_r) THEN
-      IF (ALLOCATED(buffer_r)) DEALLOCATE(buffer_r)
-      size_r=MAX(size_min,INT(grow_factor*buff_size))
-      ALLOCATE(buffer_r(size_r))
-    ENDIF
-!$OMP END MASTER
-!$OMP BARRIER
-  
-  END SUBROUTINE check_buffer_r
-  
-  SUBROUTINE check_buffer_l(buff_size)
-  IMPLICIT NONE
-  INTEGER :: buff_size
-
-!$OMP BARRIER
-!$OMP MASTER
-    IF (buff_size>size_l) THEN
-      IF (ALLOCATED(buffer_l)) DEALLOCATE(buffer_l)
-      size_l=MAX(size_min,INT(grow_factor*buff_size))
-      ALLOCATE(buffer_l(size_l))
-    ENDIF
-!$OMP END MASTER
-!$OMP BARRIER
-  
-  END SUBROUTINE check_buffer_l
-    
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Broadcast --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-!! -- Les chaine de charactère -- !!
-
-  SUBROUTINE bcast_omp_c(var)
-  IMPLICIT NONE
-    CHARACTER(LEN=*),INTENT(INOUT) :: Var
-    
-    CALL bcast_omp_cgen(Var,len(Var),buffer_c)
-    
-  END SUBROUTINE bcast_omp_c
-
-!! -- Les entiers -- !!
-  
-  SUBROUTINE bcast_omp_i(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var
-    INTEGER :: Var_tmp(1)
-    
-    Var_tmp(1)=Var
-    CALL check_buffer_i(1)
-    CALL bcast_omp_igen(Var_tmp,1,buffer_i)
-    Var=Var_tmp(1)
-
-  END SUBROUTINE bcast_omp_i
-
-
-  SUBROUTINE bcast_omp_i1(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:)
-   
-    CALL check_buffer_i(size(Var))
-    CALL bcast_omp_igen(Var,size(Var),buffer_i)
-
-  END SUBROUTINE bcast_omp_i1
-
-
-  SUBROUTINE bcast_omp_i2(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:)
-   
-    CALL check_buffer_i(size(Var))
-    CALL bcast_omp_igen(Var,size(Var),buffer_i)
-
-  END SUBROUTINE bcast_omp_i2
-
-
-  SUBROUTINE bcast_omp_i3(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:,:)
-
-    CALL check_buffer_i(size(Var))
-    CALL bcast_omp_igen(Var,size(Var),buffer_i)
-
-  END SUBROUTINE bcast_omp_i3
-
-
-  SUBROUTINE bcast_omp_i4(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:,:,:)
-   
-    CALL check_buffer_i(size(Var))
-    CALL bcast_omp_igen(Var,size(Var),buffer_i)
-
-  END SUBROUTINE bcast_omp_i4
-
-
-!! -- Les reels -- !!
-
-  SUBROUTINE bcast_omp_r(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var
-    REAL :: Var_tmp(1)
-    
-    Var_tmp(1)=Var
-    CALL check_buffer_r(1)
-    CALL bcast_omp_rgen(Var_tmp,1,buffer_r)
-    Var=Var_tmp(1)
-
-  END SUBROUTINE bcast_omp_r
-
-
-  SUBROUTINE bcast_omp_r1(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:)
-   
-    CALL check_buffer_r(size(Var))
-    CALL bcast_omp_rgen(Var,size(Var),buffer_r)
-
-  END SUBROUTINE bcast_omp_r1
-
-
-  SUBROUTINE bcast_omp_r2(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:)
-   
-    CALL check_buffer_r(size(Var))
-    CALL bcast_omp_rgen(Var,size(Var),buffer_r)
-
-  END SUBROUTINE bcast_omp_r2
-
-
-  SUBROUTINE bcast_omp_r3(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:,:)
-
-    CALL check_buffer_r(size(Var))
-    CALL bcast_omp_rgen(Var,size(Var),buffer_r)
-
-  END SUBROUTINE bcast_omp_r3
-
-
-  SUBROUTINE bcast_omp_r4(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:,:,:)
-   
-    CALL check_buffer_r(size(Var))
-    CALL bcast_omp_rgen(Var,size(Var),buffer_r)
-
-  END SUBROUTINE bcast_omp_r4
-
-  
-!! -- Les booleans -- !!
-
-  SUBROUTINE bcast_omp_l(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var
-    LOGICAL :: Var_tmp(1)
-    
-    Var_tmp(1)=Var
-    CALL check_buffer_l(1)
-    CALL bcast_omp_lgen(Var_tmp,1,buffer_l)
-    Var=Var_tmp(1)
-
-  END SUBROUTINE bcast_omp_l
-
-
-  SUBROUTINE bcast_omp_l1(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:)
-   
-    CALL check_buffer_l(size(Var))
-    CALL bcast_omp_lgen(Var,size(Var),buffer_l)
-
-  END SUBROUTINE bcast_omp_l1
-
-
-  SUBROUTINE bcast_omp_l2(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:)
-   
-    CALL check_buffer_l(size(Var))
-    CALL bcast_omp_lgen(Var,size(Var),buffer_l)
-
-  END SUBROUTINE bcast_omp_l2
-
-
-  SUBROUTINE bcast_omp_l3(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:,:)
-
-    CALL check_buffer_l(size(Var))
-    CALL bcast_omp_lgen(Var,size(Var),buffer_l)
-
-  END SUBROUTINE bcast_omp_l3
-
-
-  SUBROUTINE bcast_omp_l4(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:,:,:)
-   
-    CALL check_buffer_l(size(Var))
-    CALL bcast_omp_lgen(Var,size(Var),buffer_l)
-
-  END SUBROUTINE bcast_omp_l4
-
-
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Scatter   --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  SUBROUTINE scatter_omp_i(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    CALL Check_buffer_i(size(VarIn))   
-    CALL scatter_omp_igen(VarIn,Varout,1,buffer_i)
-    
-  END SUBROUTINE scatter_omp_i
-
-
-  SUBROUTINE scatter_omp_i1(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-
-    CALL Check_buffer_i(size(VarIn))   
-    CALL scatter_omp_igen(VarIn,Varout,Size(VarOut,2),buffer_i)
-    
-  END SUBROUTINE scatter_omp_i1
-  
-  
-  SUBROUTINE scatter_omp_i2(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL Check_buffer_i(size(VarIn))   
-    CALL scatter_omp_igen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3),buffer_i)
-
-  END SUBROUTINE scatter_omp_i2
-
-
-  SUBROUTINE scatter_omp_i3(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    CALL Check_buffer_i(size(VarIn))   
-    CALL scatter_omp_igen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4),buffer_i)
-  
-  END SUBROUTINE scatter_omp_i3
-
-
-
-
-  SUBROUTINE scatter_omp_r(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    CALL Check_buffer_r(size(VarIn))   
-    CALL scatter_omp_rgen(VarIn,Varout,1,buffer_r)
-    
-  END SUBROUTINE scatter_omp_r
-
-
-  SUBROUTINE scatter_omp_r1(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    CALL Check_buffer_r(size(VarIn))   
-    CALL scatter_omp_rgen(VarIn,Varout,Size(VarOut,2),buffer_r)
-        
-  END SUBROUTINE scatter_omp_r1
-  
-  
-  SUBROUTINE scatter_omp_r2(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL Check_buffer_r(size(VarIn))   
-    CALL scatter_omp_rgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3),buffer_r)
-
-  END SUBROUTINE scatter_omp_r2
-
-
-  SUBROUTINE scatter_omp_r3(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    CALL Check_buffer_r(size(VarIn))   
-    CALL scatter_omp_rgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4),buffer_r)
-  
-  END SUBROUTINE scatter_omp_r3
-  
-
-
-  SUBROUTINE scatter_omp_l(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    CALL Check_buffer_l(size(VarIn))   
-    CALL scatter_omp_lgen(VarIn,Varout,1,buffer_l)
-    
-  END SUBROUTINE scatter_omp_l
-
-
-  SUBROUTINE scatter_omp_l1(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    CALL Check_buffer_l(size(VarIn))   
-    CALL scatter_omp_lgen(VarIn,Varout,Size(VarOut,2),buffer_l)
-    
-  END SUBROUTINE scatter_omp_l1
-  
-  
-  SUBROUTINE scatter_omp_l2(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL Check_buffer_l(size(VarIn))   
-    CALL scatter_omp_lgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3),buffer_l)
-
-  END SUBROUTINE scatter_omp_l2
-
-
-  SUBROUTINE scatter_omp_l3(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    CALL Check_buffer_l(size(VarIn))   
-    CALL scatter_omp_lgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4),buffer_l)
-  
-  END SUBROUTINE scatter_omp_l3  
-  
-
-  SUBROUTINE gather_omp_i(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    CALL Check_buffer_i(size(VarOut))   
-    CALL gather_omp_igen(VarIn,Varout,1,buffer_i)
-    
-  END SUBROUTINE gather_omp_i
-
-
-  SUBROUTINE gather_omp_i1(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    CALL Check_buffer_i(size(VarOut))   
-    CALL gather_omp_igen(VarIn,Varout,Size(VarIn,2),buffer_i)
-    
-  END SUBROUTINE gather_omp_i1
-
-
-  SUBROUTINE gather_omp_i2(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL Check_buffer_i(size(VarOut))   
-    CALL gather_omp_igen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3),buffer_i)
-          
-  END SUBROUTINE gather_omp_i2
-  
-
-  SUBROUTINE gather_omp_i3(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    CALL Check_buffer_i(size(VarOut))   
-    CALL gather_omp_igen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4),buffer_i)
-    
-  END SUBROUTINE gather_omp_i3
-
-
-
-  SUBROUTINE gather_omp_r(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    CALL Check_buffer_r(size(VarOut))   
-    CALL gather_omp_rgen(VarIn,Varout,1,buffer_r)
-    
-  END SUBROUTINE gather_omp_r
-
-
-  SUBROUTINE gather_omp_r1(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-
-    CALL Check_buffer_r(size(VarOut))   
-    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2),buffer_r)
-        
-  END SUBROUTINE gather_omp_r1
-
-
-  SUBROUTINE gather_omp_r2(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL Check_buffer_r(size(VarOut))   
-    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3),buffer_r)
-    
-  END SUBROUTINE gather_omp_r2
-  
-
-  SUBROUTINE gather_omp_r3(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-
-    CALL Check_buffer_r(size(VarOut))       
-    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4),buffer_r)
-    
-  END SUBROUTINE gather_omp_r3
-
-
-  SUBROUTINE gather_omp_l(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    CALL Check_buffer_l(size(VarOut))   
-    CALL gather_omp_lgen(VarIn,Varout,1,buffer_l)
-    
-  END SUBROUTINE gather_omp_l
-
-
-  SUBROUTINE gather_omp_l1(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    CALL Check_buffer_l(size(VarOut))   
-    CALL gather_omp_lgen(VarIn,Varout,Size(VarIn,2),buffer_l)
-    
-  END SUBROUTINE gather_omp_l1
-
-
-  SUBROUTINE gather_omp_l2(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL Check_buffer_l(size(VarOut))   
-    CALL gather_omp_lgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3),buffer_l)
-    
-  END SUBROUTINE gather_omp_l2
-  
-
-  SUBROUTINE gather_omp_l3(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    CALL Check_buffer_l(size(VarOut))   
-    CALL gather_omp_lgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4),buffer_l)
-    
-  END SUBROUTINE gather_omp_l3
-
-
-
-
-  SUBROUTINE reduce_sum_omp_i(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN)  :: VarIn
-    INTEGER,INTENT(OUT) :: VarOut
-    INTEGER             :: VarIn_tmp(1)
-    INTEGER             :: VarOut_tmp(1)
-    
-    VarIn_tmp(1)=VarIn
-    CALL Check_buffer_i(1)   
-    CALL reduce_sum_omp_igen(VarIn_tmp,Varout_tmp,1,buffer_i)
-    VarOut=VarOut_tmp(1)
-    
-  END SUBROUTINE reduce_sum_omp_i
-
-  SUBROUTINE reduce_sum_omp_i1(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-    CALL Check_buffer_i(size(VarIn))   
-    CALL reduce_sum_omp_igen(VarIn,Varout,Size(VarIn),buffer_i)
-   
-  END SUBROUTINE reduce_sum_omp_i1
-  
-  
-  SUBROUTINE reduce_sum_omp_i2(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-
-    CALL Check_buffer_i(size(VarIn))   
-    CALL reduce_sum_omp_igen(VarIn,Varout,Size(VarIn),buffer_i)
-  
-  END SUBROUTINE reduce_sum_omp_i2
-
-
-  SUBROUTINE reduce_sum_omp_i3(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL Check_buffer_i(size(VarIn))   
-    CALL reduce_sum_omp_igen(VarIn,Varout,Size(VarIn),buffer_i)
-  
-  END SUBROUTINE reduce_sum_omp_i3
-
-
-  SUBROUTINE reduce_sum_omp_i4(VarIn, VarOut)
-    IMPLICIT NONE
-
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-  
-    CALL Check_buffer_i(size(VarIn))   
-    CALL reduce_sum_omp_igen(VarIn,Varout,Size(VarIn),buffer_i)
-  
-  END SUBROUTINE reduce_sum_omp_i4
-
-
-  SUBROUTINE reduce_sum_omp_r(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN)  :: VarIn
-    REAL,INTENT(OUT) :: VarOut
-    REAL             :: VarIn_tmp(1)
-    REAL             :: VarOut_tmp(1)
-    
-    VarIn_tmp(1)=VarIn
-    CALL Check_buffer_r(1)   
-    CALL reduce_sum_omp_rgen(VarIn_tmp,Varout_tmp,1,buffer_r)
-    VarOut=VarOut_tmp(1)
-  
-  END SUBROUTINE reduce_sum_omp_r
-
-  SUBROUTINE reduce_sum_omp_r1(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-    CALL Check_buffer_r(size(VarIn))   
-    CALL reduce_sum_omp_rgen(VarIn,Varout,Size(VarIn),buffer_r)
-   
-  END SUBROUTINE reduce_sum_omp_r1
-  
-  
-  SUBROUTINE reduce_sum_omp_r2(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    CALL Check_buffer_r(size(VarIn))   
-    CALL reduce_sum_omp_rgen(VarIn,Varout,Size(VarIn),buffer_r)
-  
-  END SUBROUTINE reduce_sum_omp_r2
-
-
-  SUBROUTINE reduce_sum_omp_r3(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    CALL Check_buffer_r(size(VarIn))   
-    CALL reduce_sum_omp_rgen(VarIn,Varout,Size(VarIn),buffer_r)
-  
-  END SUBROUTINE reduce_sum_omp_r3
-
-
-  SUBROUTINE reduce_sum_omp_r4(VarIn, VarOut)
-    IMPLICIT NONE
-
-    REAL,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-  
-    CALL Check_buffer_r(size(VarIn))   
-    CALL reduce_sum_omp_rgen(VarIn,Varout,Size(VarIn),buffer_r)
-  
-  END SUBROUTINE reduce_sum_omp_r4
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!    LES ROUTINES GENERIQUES    !
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  SUBROUTINE bcast_omp_cgen(Var,Nb,Buff)
-  IMPLICIT NONE
-    
-    CHARACTER(LEN=*),INTENT(INOUT) :: Var
-    CHARACTER(LEN=*),INTENT(INOUT) :: Buff
-    INTEGER,INTENT(IN) :: Nb
-    
-    INTEGER :: i
-  
-  !$OMP MASTER
-      Buff=Var
-  !$OMP END MASTER
-  !$OMP BARRIER
-
-    DO i=1,Nb
-      Var=Buff
-    ENDDO
-  !$OMP BARRIER      
-  
-  END SUBROUTINE bcast_omp_cgen
-
-
-      
-  SUBROUTINE bcast_omp_igen(Var,Nb,Buff)
-  IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: Nb
-    INTEGER,DIMENSION(Nb),INTENT(INOUT) :: Var
-    INTEGER,DIMENSION(Nb),INTENT(INOUT) :: Buff
-
-    INTEGER :: i
-    
-  !$OMP MASTER
-    DO i=1,Nb
-      Buff(i)=Var(i)
-    ENDDO
-  !$OMP END MASTER
-  !$OMP BARRIER
-
-    DO i=1,Nb
-      Var(i)=Buff(i)
-    ENDDO
-  !$OMP BARRIER        
-
-  END SUBROUTINE bcast_omp_igen
-
-
-  SUBROUTINE bcast_omp_rgen(Var,Nb,Buff)
-  IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: Nb
-    REAL,DIMENSION(Nb),INTENT(INOUT) :: Var
-    REAL,DIMENSION(Nb),INTENT(INOUT) :: Buff
-
-    INTEGER :: i
-    
-  !$OMP MASTER
-    DO i=1,Nb
-      Buff(i)=Var(i)
-    ENDDO
-  !$OMP END MASTER
-  !$OMP BARRIER
-
-    DO i=1,Nb
-      Var(i)=Buff(i)
-    ENDDO
-  !$OMP BARRIER        
-
-  END SUBROUTINE bcast_omp_rgen
-
-  SUBROUTINE bcast_omp_lgen(Var,Nb,Buff)
-  IMPLICIT NONE
-    
-    INTEGER,INTENT(IN) :: Nb
-    LOGICAL,DIMENSION(Nb),INTENT(INOUT) :: Var
-    LOGICAL,DIMENSION(Nb),INTENT(INOUT) :: Buff
-  
-    INTEGER :: i
-    
-  !$OMP MASTER
-    DO i=1,Nb
-      Buff(i)=Var(i)
-    ENDDO
-  !$OMP END MASTER
-  !$OMP BARRIER
-
-    DO i=1,Nb
-      Var(i)=Buff(i)
-    ENDDO
-  !$OMP BARRIER        
-
-  END SUBROUTINE bcast_omp_lgen
-
-
-  SUBROUTINE scatter_omp_igen(VarIn,VarOut,dimsize,Buff)
-    USE mod_phys_lmdz_omp_data
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
-    IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    INTEGER,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(klon_omp,dimsize) :: VarOut
-    INTEGER,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
-
-    INTEGER :: i,ij
-    
-  !$OMP MASTER
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        Buff(ij,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO  
-  !$OMP END MASTER
-  !$OMP BARRIER
- 
-    DO i=1,dimsize
-      DO ij=1,klon_omp
-        VarOut(ij,i)=Buff(klon_omp_begin-1+ij,i)
-      ENDDO
-    ENDDO
-  !$OMP BARRIER  
- 
-  END SUBROUTINE scatter_omp_igen
-
-
-  SUBROUTINE scatter_omp_rgen(VarIn,VarOut,dimsize,Buff)
-  USE mod_phys_lmdz_omp_data
-  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
-  IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    REAL,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(klon_omp,dimsize) :: VarOut
-    REAL,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
-
-    INTEGER :: i,ij
-    
-  !$OMP MASTER
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        Buff(ij,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO  
-  !$OMP END MASTER
-  !$OMP BARRIER
-
-    DO i=1,dimsize
-      DO ij=1,klon_omp
-        VarOut(ij,i)=Buff(klon_omp_begin-1+ij,i)
-      ENDDO
-    ENDDO
-  !$OMP BARRIER  
-
-  END SUBROUTINE scatter_omp_rgen
-
-
-  SUBROUTINE scatter_omp_lgen(VarIn,VarOut,dimsize,Buff)
-  USE mod_phys_lmdz_omp_data
-  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
-  IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    LOGICAL,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(klon_omp,dimsize) :: VarOut
-    LOGICAL,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
-
-    INTEGER :: i,ij
-    
- !$OMP MASTER 
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        Buff(ij,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO  
-  !$OMP END MASTER
-  !$OMP BARRIER
-
-    DO i=1,dimsize
-      DO ij=1,klon_omp
-        VarOut(ij,i)=Buff(klon_omp_begin-1+ij,i)
-      ENDDO
-    ENDDO
-  !$OMP BARRIER  
-
-  END SUBROUTINE scatter_omp_lgen
-
-
-
-
-
-  SUBROUTINE gather_omp_igen(VarIn,VarOut,dimsize,Buff)
-  USE mod_phys_lmdz_omp_data
-  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
-  IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    INTEGER,INTENT(IN),DIMENSION(klon_omp,dimsize) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
-    INTEGER,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
-
-    INTEGER :: i,ij
-    
-    DO i=1,dimsize
-      DO ij=1,klon_omp
-        Buff(klon_omp_begin-1+ij,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO
-  !$OMP BARRIER  
-  
-  
-  !$OMP MASTER
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        VarOut(ij,i)=Buff(ij,i)
-      ENDDO
-    ENDDO  
-  !$OMP END MASTER
-  !$OMP BARRIER
-
-  END SUBROUTINE gather_omp_igen
-
-
-  SUBROUTINE gather_omp_rgen(VarIn,VarOut,dimsize,Buff)
-  USE mod_phys_lmdz_omp_data
-  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
-  IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    REAL,INTENT(IN),DIMENSION(klon_omp,dimsize) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
-    REAL,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
-
-    INTEGER :: i,ij
-    
-    DO i=1,dimsize
-      DO ij=1,klon_omp
-        Buff(klon_omp_begin-1+ij,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO
-  !$OMP BARRIER  
-
-
-  !$OMP MASTER
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        VarOut(ij,i)=Buff(ij,i)
-      ENDDO
-    ENDDO  
-  !$OMP END MASTER
-  !$OMP BARRIER
-
-  END SUBROUTINE gather_omp_rgen
-
-
-  SUBROUTINE gather_omp_lgen(VarIn,VarOut,dimsize,Buff)
-  USE mod_phys_lmdz_omp_data
-  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
-  IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    LOGICAL,INTENT(IN),DIMENSION(klon_omp,dimsize) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
-    LOGICAL,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
-
-    INTEGER :: i,ij
-    
-    DO i=1,dimsize
-      DO ij=1,klon_omp
-        Buff(klon_omp_begin-1+ij,i)=VarIn(ij,i)
-      ENDDO
-    ENDDO
-  !$OMP BARRIER  
-
-
-  !$OMP MASTER
-    DO i=1,dimsize
-      DO ij=1,klon_mpi
-        VarOut(ij,i)=Buff(ij,i)
-      ENDDO
-    ENDDO  
-  !$OMP END MASTER
-  !$OMP BARRIER
-
-  END SUBROUTINE gather_omp_lgen
-
-
-  SUBROUTINE reduce_sum_omp_igen(VarIn,VarOut,dimsize,Buff)
-  IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    INTEGER,INTENT(IN),DIMENSION(dimsize) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(dimsize) :: VarOut
-    INTEGER,INTENT(INOUT),DIMENSION(dimsize) :: Buff
-
-    INTEGER :: i
-
-  !$OMP MASTER
-    Buff(:)=0
-  !$OMP END MASTER
-  !$OMP BARRIER
-  
-  !$OMP CRITICAL     
-    DO i=1,dimsize
-      Buff(i)=Buff(i)+VarIn(i)
-    ENDDO
-  !$OMP END CRITICAL
-  !$OMP BARRIER  
-  
-  !$OMP MASTER
-    DO i=1,dimsize
-      VarOut(i)=Buff(i)
-    ENDDO
-  !$OMP END MASTER
-  !$OMP BARRIER
-  
-  END SUBROUTINE reduce_sum_omp_igen
-
-  SUBROUTINE reduce_sum_omp_rgen(VarIn,VarOut,dimsize,Buff)
-  IMPLICIT NONE
-
-    INTEGER,INTENT(IN) :: dimsize
-    REAL,INTENT(IN),DIMENSION(dimsize) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(dimsize) :: VarOut
-    REAL,INTENT(INOUT),DIMENSION(dimsize) :: Buff
-
-    INTEGER :: i
-
-  !$OMP MASTER
-    Buff(:)=0
-  !$OMP END MASTER
-  !$OMP BARRIER
-  
-  !$OMP CRITICAL     
-    DO i=1,dimsize
-      Buff(i)=Buff(i)+VarIn(i)
-    ENDDO
-  !$OMP END CRITICAL
-  !$OMP BARRIER  
-  
-  !$OMP MASTER
-    DO i=1,dimsize
-      VarOut(i)=Buff(i)
-    ENDDO
-  !$OMP END MASTER
-  !$OMP BARRIER
-  
-  END SUBROUTINE reduce_sum_omp_rgen
-
-END MODULE mod_phys_lmdz_omp_transfert
Index: DZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_para.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_para.F90	(revision 2407)
+++ 	(revision )
@@ -1,113 +1,0 @@
-!
-!$Header$
-!
-MODULE mod_phys_lmdz_para
-  USE mod_phys_lmdz_transfert_para
-  USE mod_phys_lmdz_mpi_data
-  USE mod_phys_lmdz_omp_data
-    
-  INTEGER,SAVE :: klon_loc
-  LOGICAL,SAVE :: is_sequential
-  LOGICAL,SAVE :: is_parallel
-  LOGICAL,SAVE :: is_master
-  
-!$OMP THREADPRIVATE(klon_loc,is_master)
-  
-CONTAINS
-
-  SUBROUTINE Init_phys_lmdz_para(iim,jjp1,nb_proc,distrib)
-  IMPLICIT NONE
-    INTEGER,INTENT(in) :: iim
-    INTEGER,INTENT(in) :: jjp1
-    INTEGER,INTENT(in) :: nb_proc
-    INTEGER,INTENT(in) :: distrib(0:nb_proc-1)
-
-    CALL Init_phys_lmdz_mpi_data(iim,jjp1,nb_proc,distrib)
-!$OMP PARALLEL
-    CALL Init_phys_lmdz_omp_data(klon_mpi)
-    klon_loc=klon_omp
-    IF (is_mpi_root .AND. is_omp_root) THEN 
-       is_master=.TRUE.
-     ELSE
-       is_master=.FALSE.
-     ENDIF
-     CALL Test_transfert
-!$OMP END PARALLEL    
-     IF (is_using_mpi .OR. is_using_omp) THEN
-       is_sequential=.FALSE.
-       is_parallel=.TRUE.
-     ELSE
-       is_sequential=.TRUE.
-       is_parallel=.FALSE.
-     ENDIF
-      
-  END SUBROUTINE Init_phys_lmdz_para
-
-  SUBROUTINE Test_transfert
-  USE mod_grid_phy_lmdz
-  IMPLICIT NONE
-    INCLUDE "iniprint.h"
- 
-    REAL :: Test_Field1d_glo(klon_glo,nbp_lev)
-    REAL :: tmp1d_glo(klon_glo,nbp_lev)
-    REAL :: Test_Field2d_glo(nbp_lon,nbp_lat,nbp_lev)
-    REAL :: tmp2d_glo(nbp_lon,nbp_lat,nbp_lev)
-    REAL :: Test_Field1d_loc(klon_loc,nbp_lev)
-    REAL :: Test_Field2d_loc(nbp_lon,jj_nb,nbp_lev)
-    REAL :: CheckSum
-    
-    INTEGER :: i,l
-  
-    Test_Field1d_glo = 0.
-    Test_Field2d_glo = 0.
-    Test_Field1d_loc = 0.
-    Test_Field2d_loc = 0.
-  
-    IF (is_mpi_root) THEN
-!$OMP MASTER
-      DO l=1,nbp_lev
-        DO i=1,klon_glo
-!          Test_Field1d_glo(i,l)=MOD(i,10)+10*(l-1)
-           Test_Field1d_glo(i,l)=1
-        ENDDO
-      ENDDO
-!$OMP END MASTER  
-    ENDIF
-  
-    CALL Scatter(Test_Field1d_glo,Test_Field1d_loc)
-    CALL Gather(Test_Field1d_loc,tmp1d_glo)
-  
-    IF (is_mpi_root) THEN
-!$OMP MASTER  
-      Checksum=sum(Test_Field1d_glo-tmp1d_glo)
-      WRITE(lunout,*) "------> Checksum =",Checksum," MUST BE 0"
-!$OMP END MASTER
-    ENDIF
-    
-    CALL grid1dTo2d_glo(Test_Field1d_glo,Test_Field2d_glo)
-    CALL scatter2D(Test_Field2d_glo,Test_Field1d_loc)
-    CALL gather2d(Test_Field1d_loc,Test_Field2d_glo)
-    CALL grid2dTo1d_glo(Test_Field2d_glo,tmp1d_glo)
-
-    IF (is_mpi_root) THEN
-!$OMP MASTER  
-      Checksum=sum(Test_Field1d_glo-tmp1d_glo)
-      WRITE(lunout,*) "------> Checksum =",Checksum," MUST BE 0"
-!$OMP END MASTER
-    ENDIF
-
-    CALL bcast(Test_Field1d_glo)
-    CALL reduce_sum(Test_Field1d_glo,tmp1d_glo)
-
-    IF (is_mpi_root) THEN
-!$OMP MASTER  
-      Checksum=sum(Test_Field1d_glo*omp_size*mpi_size-tmp1d_glo)
-      WRITE(lunout,*) "------> Checksum =",Checksum," MUST BE 0"
-!$OMP END MASTER
-    ENDIF
-    
-     
-   END SUBROUTINE Test_transfert
-  
-END MODULE mod_phys_lmdz_para
-    
Index: DZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_transfert_para.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/mod_phys_lmdz_transfert_para.F90	(revision 2407)
+++ 	(revision )
@@ -1,1275 +1,0 @@
-!
-!$Header$
-!
-MODULE mod_phys_lmdz_transfert_para
-
-  USE mod_phys_lmdz_mpi_transfert
-  USE mod_phys_lmdz_omp_transfert 
-
-
-
-  INTERFACE bcast
-    MODULE PROCEDURE bcast_c,                                     &
-                     bcast_i,bcast_i1,bcast_i2,bcast_i3,bcast_i4, &
-                     bcast_r,bcast_r1,bcast_r2,bcast_r3,bcast_r4, &
-		     bcast_l,bcast_l1,bcast_l2,bcast_l3,bcast_l4
-  END INTERFACE
-
-  INTERFACE scatter
-    MODULE PROCEDURE scatter_i,scatter_i1,scatter_i2,scatter_i3, &
-                     scatter_r,scatter_r1,scatter_r2,scatter_r3, &
-		     scatter_l,scatter_l1,scatter_l2,scatter_l3
-  END INTERFACE
-
-  
-  INTERFACE gather
-    MODULE PROCEDURE gather_i,gather_i1,gather_i2,gather_i3, &
-                     gather_r,gather_r1,gather_r2,gather_r3, &
-		     gather_l,gather_l1,gather_l2,gather_l3  
-  END INTERFACE
-  
-  INTERFACE scatter2D
-    MODULE PROCEDURE scatter2D_i,scatter2D_i1,scatter2D_i2,scatter2D_i3, &
-                     scatter2D_r,scatter2D_r1,scatter2D_r2,scatter2D_r3, &
-		     scatter2D_l,scatter2D_l1,scatter2D_l2,scatter2D_l3
-  END INTERFACE
-
-  INTERFACE gather2D
-    MODULE PROCEDURE gather2D_i,gather2D_i1,gather2D_i2,gather2D_i3, &
-                     gather2D_r,gather2D_r1,gather2D_r2,gather2D_r3, &
-		     gather2D_l,gather2D_l1,gather2D_l2,gather2D_l3
-  END INTERFACE 
-  
-  INTERFACE reduce_sum
-    MODULE PROCEDURE reduce_sum_i,reduce_sum_i1,reduce_sum_i2,reduce_sum_i3,reduce_sum_i4, &
-                     reduce_sum_r,reduce_sum_r1,reduce_sum_r2,reduce_sum_r3,reduce_sum_r4
-  END INTERFACE 
-
-   
-CONTAINS
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Broadcast --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-!! -- Les chaine de charactère -- !!
-
-  SUBROUTINE bcast_c(var)
-  IMPLICIT NONE
-    CHARACTER(LEN=*),INTENT(INOUT) :: Var
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_c
-
-!! -- Les entiers -- !!
-  
-  SUBROUTINE bcast_i(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_i
-
-  SUBROUTINE bcast_i1(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_i1
-
-
-  SUBROUTINE bcast_i2(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_i2
-
-
-  SUBROUTINE bcast_i3(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:,:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_i3
-
-
-  SUBROUTINE bcast_i4(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:,:,:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_i4
-
- 
-!! -- Les reels -- !!
-  
-  SUBROUTINE bcast_r(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var
-
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_r
-
-  SUBROUTINE bcast_r1(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_r1
-
-
-  SUBROUTINE bcast_r2(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_r2
-
-
-  SUBROUTINE bcast_r3(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:,:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_r3
-
-
-  SUBROUTINE bcast_r4(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:,:,:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_r4 
-
-
-!! -- Les booleens -- !!
-  
-  SUBROUTINE bcast_l(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_l
-
-  SUBROUTINE bcast_l1(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_l1
-
-
-  SUBROUTINE bcast_l2(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_l2
-
-
-  SUBROUTINE bcast_l3(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:,:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_l3
-
-
-  SUBROUTINE bcast_l4(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:,:,:)
-   
-!$OMP MASTER
-    CALL bcast_mpi(Var)
-!$OMP END MASTER
-    CALL bcast_omp(Var)
-    
-  END SUBROUTINE bcast_l4
-
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Scatter   --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  SUBROUTINE scatter_i(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    INTEGER,DIMENSION(klon_mpi) :: Var_tmp
-    
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-
-      CALL scatter_omp(Var_tmp,Varout)
-    
-  END SUBROUTINE scatter_i
-
-
-  SUBROUTINE scatter_i1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-
-    INTEGER,DIMENSION(klon_mpi,SIZE(Varout,2)) :: Var_tmp
-
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-      CALL scatter_omp(Var_tmp,Varout)
-    
-  END SUBROUTINE scatter_i1
-
-
-  SUBROUTINE scatter_i2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    INTEGER,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3)) :: Var_tmp
-
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-      CALL scatter_omp(Var_tmp,Varout)
-    
-  END SUBROUTINE scatter_i2
-
-
-  SUBROUTINE scatter_i3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-
-    INTEGER,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3),SIZE(Varout,4)) :: Var_tmp
-
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-      CALL scatter_omp(Var_tmp,VarOut)
-    
-  END SUBROUTINE scatter_i3
-
-
-  SUBROUTINE scatter_r(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    REAL,DIMENSION(klon_mpi) :: Var_tmp
-    
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-
-      CALL scatter_omp(Var_tmp,Varout)
-    
-  END SUBROUTINE scatter_r
-
-
-  SUBROUTINE scatter_r1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-
-    REAL,DIMENSION(klon_mpi,SIZE(Varout,2)) :: Var_tmp
-
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-      CALL scatter_omp(Var_tmp,Varout)
-    
-  END SUBROUTINE scatter_r1
-
-
-  SUBROUTINE scatter_r2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    REAL,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3)) :: Var_tmp
-
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-      CALL scatter_omp(Var_tmp,Varout)
-    
-  END SUBROUTINE scatter_r2
-
-
-  SUBROUTINE scatter_r3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-
-    REAL,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3),SIZE(Varout,4)) :: Var_tmp
-
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-      CALL scatter_omp(Var_tmp,VarOut)
-    
-  END SUBROUTINE scatter_r3
-  
-  
-
-  SUBROUTINE scatter_l(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    LOGICAL,DIMENSION(klon_mpi) :: Var_tmp
-    
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-
-      CALL scatter_omp(Var_tmp,Varout)
-    
-  END SUBROUTINE scatter_l
-
-
-  SUBROUTINE scatter_l1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-
-    LOGICAL,DIMENSION(klon_mpi,SIZE(Varout,2)) :: Var_tmp
-
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-      CALL scatter_omp(Var_tmp,Varout)
-    
-  END SUBROUTINE scatter_l1
-
-
-  SUBROUTINE scatter_l2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    LOGICAL,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3)) :: Var_tmp
-
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-      CALL scatter_omp(Var_tmp,Varout)
-    
-  END SUBROUTINE scatter_l2
-
-
-  SUBROUTINE scatter_l3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-
-    LOGICAL,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3),SIZE(Varout,4)) :: Var_tmp
-
-!$OMP MASTER
-      CALL scatter_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-      CALL scatter_omp(Var_tmp,VarOut)
-    
-  END SUBROUTINE scatter_l3
-
-
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Gather   --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 
-!!!!! --> Les entiers
-
-  SUBROUTINE gather_i(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-    INTEGER, DIMENSION(klon_mpi) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,Varout)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_i
-
-
-  SUBROUTINE gather_i1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    INTEGER, DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,Varout)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_i1
-
-
-  SUBROUTINE gather_i2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    INTEGER, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_i2
-
-
-  SUBROUTINE gather_i3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    INTEGER, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_i3
-
-
-!!!!! --> Les reels
-
-  SUBROUTINE gather_r(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-    REAL, DIMENSION(klon_mpi) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_r
-
-
-  SUBROUTINE gather_r1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    REAL, DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_r1
-
-
-  SUBROUTINE gather_r2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    REAL, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_r2
-
-
-  SUBROUTINE gather_r3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    REAL, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_r3
-
-
-!!!!! --> Les booleens
-
-  SUBROUTINE gather_l(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-    LOGICAL, DIMENSION(klon_mpi) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_l
-
-
-  SUBROUTINE gather_l1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    LOGICAL, DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_l1
-
-
-  SUBROUTINE gather_l2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    LOGICAL, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_l2
-
-
-  SUBROUTINE gather_l3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    LOGICAL, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
-    
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE gather_l3
-
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Scatter2D   --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-
-!!!!! --> Les entiers
-
-  SUBROUTINE scatter2D_i(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    INTEGER,DIMENSION(klon_mpi) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_i
-
-
-  SUBROUTINE scatter2D_i1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-
-    INTEGER,DIMENSION(klon_mpi,SIZE(VarOut,2)) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_i1
-  
-
-  SUBROUTINE scatter2D_i2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-
-    INTEGER,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3)) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_i2  
-
-
-  SUBROUTINE scatter2D_i3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-
-    INTEGER,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3),SIZE(VarOut,4)) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_i3
-  
-
-!!!!! --> Les reels
-
-  SUBROUTINE scatter2D_r(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    REAL,DIMENSION(klon_mpi) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_r
-
-
-  SUBROUTINE scatter2D_r1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-
-    REAL,DIMENSION(klon_mpi,SIZE(VarOut,2)) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_r1
-  
-
-  SUBROUTINE scatter2D_r2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-
-    REAL,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3)) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_r2  
-
-
-  SUBROUTINE scatter2D_r3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-
-    REAL,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3),SIZE(VarOut,4)) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_r3
-    
-    
-!!!!! --> Les booleens
-
-
-  SUBROUTINE scatter2D_l(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
-
-    LOGICAL,DIMENSION(klon_mpi) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_l
-
-
-  SUBROUTINE scatter2D_l1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-
-    LOGICAL,DIMENSION(klon_mpi,SIZE(VarOut,2)) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_l1
-  
-
-  SUBROUTINE scatter2D_l2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-
-    LOGICAL,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3)) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_l2  
-
-
-  SUBROUTINE scatter2D_l3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-
-    LOGICAL,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3),SIZE(VarOut,4)) :: Var_tmp    
-
-!$OMP MASTER    
-    CALL scatter2D_mpi(VarIn,Var_tmp)
-!$OMP END MASTER
-    CALL scatter_omp(Var_tmp,VarOut)
-
-  END SUBROUTINE scatter2D_l3
-
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Gather2D   --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-!!!!! --> Les entiers
-
-  SUBROUTINE gather2D_i(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    INTEGER,DIMENSION(klon_mpi) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_i
-  
-
-  SUBROUTINE gather2D_i1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    INTEGER,DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_i1
-
-  
-  SUBROUTINE gather2D_i2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    INTEGER,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_i2
-
-
-  SUBROUTINE gather2D_i3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
-    
-    INTEGER,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_i3
-
-
-!!!!! --> Les reels
-
-  SUBROUTINE gather2D_r(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    REAL,DIMENSION(klon_mpi) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_r
-  
-
-  SUBROUTINE gather2D_r1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    REAL,DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_r1
-
-  
-  SUBROUTINE gather2D_r2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    REAL,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_r2
-
-
-  SUBROUTINE gather2D_r3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
-    
-    REAL,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_r3
-  
-
-!!!!! --> Les booleens
-
-  SUBROUTINE gather2D_l(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    LOGICAL,DIMENSION(klon_mpi) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_l
-  
-
-  SUBROUTINE gather2D_l1(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    LOGICAL,DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_l1
-
-  
-  SUBROUTINE gather2D_l2(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    LOGICAL,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_l2
-
-
-  SUBROUTINE gather2D_l3(VarIn, VarOut)
-    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
-    IMPLICIT NONE
-  
-    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
-    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
-    
-    LOGICAL,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
-
-    CALL gather_omp(VarIn,Var_tmp)
-!$OMP MASTER
-    CALL gather2D_mpi(Var_tmp,VarOut)
-!$OMP END MASTER    
-
-  END SUBROUTINE gather2D_l3
-  
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des reduce_sum   --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-! Les entiers
-
-  SUBROUTINE reduce_sum_i(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN)  :: VarIn
-    INTEGER,INTENT(OUT) :: VarOut
-    
-    INTEGER             :: Var_tmp
-           
-    CALL reduce_sum_omp(VarIn,Var_tmp)
-!$OMP MASTER      
-    CALL reduce_sum_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE reduce_sum_i  
-
-
-  SUBROUTINE reduce_sum_i1(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-    INTEGER,DIMENSION(SIZE(VarIn))   :: Var_tmp
-           
-    CALL reduce_sum_omp(VarIn,Var_tmp)
-!$OMP MASTER      
-    CALL reduce_sum_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE reduce_sum_i1  
-
-
-  SUBROUTINE reduce_sum_i2(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    INTEGER,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2)) :: Var_tmp
-           
-    CALL reduce_sum_omp(VarIn,Var_tmp)
-!$OMP MASTER      
-    CALL reduce_sum_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE reduce_sum_i2  
-  
-
-  SUBROUTINE reduce_sum_i3(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    INTEGER,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2),SIZE(VarIn,3))  :: Var_tmp
-           
-    CALL reduce_sum_omp(VarIn,Var_tmp)
-!$OMP MASTER      
-    CALL reduce_sum_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE reduce_sum_i3  
-
-
-  SUBROUTINE reduce_sum_i4(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    INTEGER,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
-    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    INTEGER,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4))  :: Var_tmp
-           
-    CALL reduce_sum_omp(VarIn,Var_tmp)
-!$OMP MASTER      
-    CALL reduce_sum_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE reduce_sum_i4  
-
-
-! Les reels
-
-  SUBROUTINE reduce_sum_r(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN)  :: VarIn
-    REAL,INTENT(OUT) :: VarOut
-    
-    REAL             :: Var_tmp
-           
-    CALL reduce_sum_omp(VarIn,Var_tmp)
-!$OMP MASTER      
-    CALL reduce_sum_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE reduce_sum_r  
-
-
-  SUBROUTINE reduce_sum_r1(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
-    
-    REAL,DIMENSION(SIZE(VarIn))   :: Var_tmp
-           
-    CALL reduce_sum_omp(VarIn,Var_tmp)
-!$OMP MASTER      
-    CALL reduce_sum_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE reduce_sum_r1  
-
-
-  SUBROUTINE reduce_sum_r2(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
-    
-    REAL,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2)) :: Var_tmp
-           
-    CALL reduce_sum_omp(VarIn,Var_tmp)
-!$OMP MASTER      
-    CALL reduce_sum_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE reduce_sum_r2  
-  
-
-  SUBROUTINE reduce_sum_r3(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
-    
-    REAL,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2),SIZE(VarIn,3))  :: Var_tmp
-           
-    CALL reduce_sum_omp(VarIn,Var_tmp)
-!$OMP MASTER      
-    CALL reduce_sum_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE reduce_sum_r3  
-
-
-  SUBROUTINE reduce_sum_r4(VarIn, VarOut)
-    IMPLICIT NONE
-  
-    REAL,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
-    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
-    
-    REAL,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4))  :: Var_tmp
-           
-    CALL reduce_sum_omp(VarIn,Var_tmp)
-!$OMP MASTER      
-    CALL reduce_sum_mpi(Var_tmp,VarOut)
-!$OMP END MASTER
-  
-  END SUBROUTINE reduce_sum_r4  
-
-   
-END MODULE mod_phys_lmdz_transfert_para
-
Index: DZ5/branches/testing/libf/dynlonlat_phylonlat/phydev/iniphysiq.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phydev/iniphysiq.F90	(revision 2407)
+++ 	(revision )
@@ -1,146 +1,0 @@
-!
-! $Id: iniphysiq.F 1403 2010-07-01 09:02:53Z fairhead $
-!
-SUBROUTINE iniphysiq(iim,jjm,nlayer,punjours, pdayref,ptimestep,         &
-                     rlatu,rlonv,aire,cu,cv,                             &
-                     prad,pg,pr,pcpp,iflag_phys)
-  USE dimphy, ONLY: klev ! number of atmospheric levels
-  USE mod_grid_phy_lmdz, ONLY: klon_glo ! number of atmospheric columns
-                                        ! (on full grid)
-  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
-                                klon_omp_begin, & ! start index of local omp subgrid
-                                klon_omp_end, & ! end index of local omp subgrid
-                                klon_mpi_begin ! start indes of columns (on local mpi grid)
-  USE comgeomphy, ONLY: initcomgeomphy, &
-                        airephy, & ! physics grid area (m2)
-                        cuphy, & ! cu coeff. (u_covariant = cu * u)
-                        cvphy, & ! cv coeff. (v_covariant = cv * v)
-                        rlond, & ! longitudes
-                        rlatd ! latitudes
-  USE comcstphy, ONLY: rradius, & ! planet radius (m)
-                       rr, & ! recuced gas constant: R/molar mass of atm
-                       rg, & ! gravity
-                       rcpp  ! specific heat of the atmosphere
-  USE phyaqua_mod, ONLY: iniaqua
-  IMPLICIT NONE
-  !
-  !=======================================================================
-  !   Initialisation of the physical constants and some positional and 
-  !   geometrical arrays for the physics
-  !=======================================================================
- 
- 
-  include "iniprint.h"
-
-  REAL,INTENT(IN) :: prad ! radius of the planet (m)
-  REAL,INTENT(IN) :: pg ! gravitational acceleration (m/s2)
-  REAL,INTENT(IN) :: pr ! ! reduced gas constant R/mu
-  REAL,INTENT(IN) :: pcpp ! specific heat Cp
-  REAL,INTENT(IN) :: punjours ! length (in s) of a standard day
-  INTEGER, INTENT (IN) :: nlayer ! number of atmospheric layers
-  INTEGER, INTENT (IN) :: iim ! number of atmospheric coulumns along longitudes
-  INTEGER, INTENT (IN) :: jjm  ! number of atompsheric columns along latitudes
-  REAL, INTENT (IN) :: rlatu(jjm+1) ! latitudes of the physics grid
-  REAL, INTENT (IN) :: rlonv(iim+1) ! longitudes of the physics grid
-  REAL, INTENT (IN) :: aire(iim+1,jjm+1) ! area of the dynamics grid (m2)
-  REAL, INTENT (IN) :: cu((iim+1)*(jjm+1)) ! cu coeff. (u_covariant = cu * u)
-  REAL, INTENT (IN) :: cv((iim+1)*jjm) ! cv coeff. (v_covariant = cv * v)
-  INTEGER, INTENT (IN) :: pdayref ! reference day of for the simulation
-  REAL,INTENT(IN) :: ptimestep !physics time step (s)
-  INTEGER,INTENT(IN) :: iflag_phys ! type of physics to be called
-
-  INTEGER :: ibegin,iend,offset
-  INTEGER :: i,j
-  CHARACTER (LEN=20) :: modname='iniphysiq'
-  CHARACTER (LEN=80) :: abort_message
-  REAL :: total_area_phy, total_area_dyn
-
-
-  ! global array, on full physics grid:
-  REAL,ALLOCATABLE :: latfi(:)
-  REAL,ALLOCATABLE :: lonfi(:)
-  REAL,ALLOCATABLE :: cufi(:)
-  REAL,ALLOCATABLE :: cvfi(:)
-  REAL,ALLOCATABLE :: airefi(:)
-
-  IF (nlayer.NE.klev) THEN
-    WRITE(lunout,*) 'STOP in ',trim(modname)
-    WRITE(lunout,*) 'Problem with dimensions :'
-    WRITE(lunout,*) 'nlayer     = ',nlayer
-    WRITE(lunout,*) 'klev   = ',klev
-    abort_message = ''
-    CALL abort_gcm (modname,abort_message,1)
-  ENDIF
-
-  !call init_phys_lmdz(iim,jjm+1,llm,1,(/(jjm-1)*iim+2/))
-  
-  ! Generate global arrays on full physics grid
-  ALLOCATE(latfi(klon_glo),lonfi(klon_glo),cufi(klon_glo),cvfi(klon_glo))
-  ALLOCATE(airefi(klon_glo))
-
-    ! North pole
-    latfi(1)=rlatu(1)
-    lonfi(1)=0.
-    cufi(1) = cu(1)
-    cvfi(1) = cv(1)
-    DO j=2,jjm
-      DO i=1,iim
-        latfi((j-2)*iim+1+i)= rlatu(j)
-        lonfi((j-2)*iim+1+i)= rlonv(i)
-        cufi((j-2)*iim+1+i) = cu((j-1)*iim+1+i)
-        cvfi((j-2)*iim+1+i) = cv((j-1)*iim+1+i)
-      ENDDO
-    ENDDO
-    ! South pole
-    latfi(klon_glo)= rlatu(jjm+1)
-    lonfi(klon_glo)= 0.
-    cufi(klon_glo) = cu((iim+1)*jjm+1)
-    cvfi(klon_glo) = cv((iim+1)*jjm-iim)
-
-    ! build airefi(), mesh area on physics grid
-    CALL gr_dyn_fi(1,iim+1,jjm+1,klon_glo,aire,airefi)
-    ! Poles are single points on physics grid
-    airefi(1)=sum(aire(1:iim,1))
-    airefi(klon_glo)=sum(aire(1:iim,jjm+1))
-
-    ! Sanity check: do total planet area match between physics and dynamics?
-    total_area_dyn=sum(aire(1:iim,1:jjm+1))
-    total_area_phy=sum(airefi(1:klon_glo))
-    IF (total_area_dyn/=total_area_phy) THEN
-      WRITE (lunout, *) 'iniphysiq: planet total surface discrepancy !!!'
-      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
-      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
-      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
-        ! stop here if the relative difference is more than 0.001%
-        abort_message = 'planet total surface discrepancy'
-        CALL abort_gcm(modname, abort_message, 1)
-      ENDIF
-    ENDIF
-
-!$OMP PARALLEL 
-  ! Now generate local lon/lat/cu/cv/area arrays
-  CALL initcomgeomphy
-
-  offset = klon_mpi_begin - 1
-  airephy(1:klon_omp) = airefi(offset+klon_omp_begin:offset+klon_omp_end)
-  cuphy(1:klon_omp) = cufi(offset+klon_omp_begin:offset+klon_omp_end)
-  cvphy(1:klon_omp) = cvfi(offset+klon_omp_begin:offset+klon_omp_end)
-  rlond(1:klon_omp) = lonfi(offset+klon_omp_begin:offset+klon_omp_end)
-  rlatd(1:klon_omp) = latfi(offset+klon_omp_begin:offset+klon_omp_end)
-
-  ! copy some fundamental parameters to physics
-  rradius=prad
-  rg=pg
-  rr=pr
-  rcpp=pcpp
-
-!$OMP END PARALLEL
-
-  ! Additional initializations for aquaplanets 
-!$OMP PARALLEL
-  IF (iflag_phys>=100) THEN
-    CALL iniaqua(klon_omp,rlatd,rlond,iflag_phys)
-  ENDIF
-!$OMP END PARALLEL
-
-END SUBROUTINE iniphysiq
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phydev/iniphysiq_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phydev/iniphysiq_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phydev/iniphysiq_mod.F90	(revision 2408)
@@ -0,0 +1,232 @@
+!
+! $Id: iniphysiq.F 1403 2010-07-01 09:02:53Z fairhead $
+!
+MODULE iniphysiq_mod
+
+CONTAINS
+
+SUBROUTINE iniphysiq(iim,jjm,nlayer, &
+                     nbp, communicator, &
+                     punjours, pdayref,ptimestep, &
+                     rlatu,rlatv,rlonu,rlonv,aire,cu,cv, &
+                     prad,pg,pr,pcpp,iflag_phys)
+  USE dimphy, ONLY: init_dimphy
+  USE mod_grid_phy_lmdz, ONLY: klon_glo,  & ! number of atmospheric columns (on full grid)
+                               regular_lonlat  ! regular longitude-latitude grid type
+  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
+                                klon_omp_begin, & ! start index of local omp subgrid
+                                klon_omp_end, & ! end index of local omp subgrid
+                                klon_mpi_begin ! start indes of columns (on local mpi grid)
+  USE geometry_mod, ONLY : init_geometry
+  USE infotrac, ONLY: nqtot, type_trac
+  USE infotrac_phy, ONLY: init_infotrac_phy
+!  USE comcstphy, ONLY: rradius, & ! planet radius (m)
+!                       rr, & ! recuced gas constant: R/molar mass of atm
+!                       rg, & ! gravity
+!                       rcpp  ! specific heat of the atmosphere
+  USE inifis_mod, ONLY: inifis
+  USE phyaqua_mod, ONLY: iniaqua
+  USE physics_distribution_mod, ONLY : init_physics_distribution
+  USE regular_lonlat_mod, ONLY : init_regular_lonlat, &
+                                 east, west, north, south, &
+                                 north_east, north_west, &
+                                 south_west, south_east
+  USE mod_interface_dyn_phys, ONLY :  init_interface_dyn_phys
+  USE nrtype, ONLY: pi
+  IMPLICIT NONE
+  !
+  !=======================================================================
+  !   Initialisation of the physical constants and some positional and 
+  !   geometrical arrays for the physics
+  !=======================================================================
+ 
+ 
+  include "iniprint.h"
+
+  REAL,INTENT(IN) :: prad ! radius of the planet (m)
+  REAL,INTENT(IN) :: pg ! gravitational acceleration (m/s2)
+  REAL,INTENT(IN) :: pr ! ! reduced gas constant R/mu
+  REAL,INTENT(IN) :: pcpp ! specific heat Cp
+  REAL,INTENT(IN) :: punjours ! length (in s) of a standard day
+  INTEGER, INTENT (IN) :: nlayer ! number of atmospheric layers
+  INTEGER, INTENT (IN) :: iim ! number of atmospheric coulumns along longitudes
+  INTEGER, INTENT (IN) :: jjm  ! number of atompsheric columns along latitudes
+  INTEGER, INTENT(IN) :: nbp ! number of physics columns for this MPI process
+  INTEGER, INTENT(IN) :: communicator ! MPI communicator
+  REAL, INTENT (IN) :: rlatu(jjm+1) ! latitudes of the physics grid
+  REAL, INTENT (IN) :: rlatv(jjm) ! latitude boundaries of the physics grid
+  REAL, INTENT (IN) :: rlonv(iim+1) ! longitudes of the physics grid
+  REAL, INTENT (IN) :: rlonu(iim+1) ! longitude boundaries of the physics grid
+  REAL, INTENT (IN) :: aire(iim+1,jjm+1) ! area of the dynamics grid (m2)
+  REAL, INTENT (IN) :: cu((iim+1)*(jjm+1)) ! cu coeff. (u_covariant = cu * u)
+  REAL, INTENT (IN) :: cv((iim+1)*jjm) ! cv coeff. (v_covariant = cv * v)
+  INTEGER, INTENT (IN) :: pdayref ! reference day of for the simulation
+  REAL,INTENT(IN) :: ptimestep !physics time step (s)
+  INTEGER,INTENT(IN) :: iflag_phys ! type of physics to be called
+
+  INTEGER :: ibegin,iend,offset
+  INTEGER :: i,j,k
+  CHARACTER (LEN=20) :: modname='iniphysiq'
+  CHARACTER (LEN=80) :: abort_message
+  REAL :: total_area_phy, total_area_dyn
+
+  ! boundaries, on global grid
+  REAL,ALLOCATABLE :: boundslon_reg(:,:)
+  REAL,ALLOCATABLE :: boundslat_reg(:,:)
+
+  ! global array, on full physics grid:
+  REAL,ALLOCATABLE :: latfi_glo(:)
+  REAL,ALLOCATABLE :: lonfi_glo(:)
+  REAL,ALLOCATABLE :: cufi_glo(:)
+  REAL,ALLOCATABLE :: cvfi_glo(:)
+  REAL,ALLOCATABLE :: airefi_glo(:)
+  REAL,ALLOCATABLE :: boundslonfi_glo(:,:)
+  REAL,ALLOCATABLE :: boundslatfi_glo(:,:)
+
+  ! local arrays, on given MPI/OpenMP domain:
+  REAL,ALLOCATABLE,SAVE :: latfi(:)
+  REAL,ALLOCATABLE,SAVE :: lonfi(:)
+  REAL,ALLOCATABLE,SAVE :: cufi(:)
+  REAL,ALLOCATABLE,SAVE :: cvfi(:)
+  REAL,ALLOCATABLE,SAVE :: airefi(:)
+  REAL,ALLOCATABLE,SAVE :: boundslonfi(:,:)
+  REAL,ALLOCATABLE,SAVE :: boundslatfi(:,:)
+!$OMP THREADPRIVATE (latfi,lonfi,cufi,cvfi,airefi,boundslonfi,boundslatfi)
+
+  ! Initialize Physics distibution and parameters and interface with dynamics
+  CALL init_physics_distribution(regular_lonlat,4, &
+                                 nbp,iim,jjm+1,nlayer,communicator)
+  CALL init_interface_dyn_phys
+  
+  ! init regular global longitude-latitude grid points and boundaries
+  ALLOCATE(boundslon_reg(iim,2))
+  ALLOCATE(boundslat_reg(jjm+1,2))
+  
+  DO i=1,iim
+   boundslon_reg(i,east)=rlonu(i) 
+   boundslon_reg(i,west)=rlonu(i+1) 
+  ENDDO
+
+  boundslat_reg(1,north)= PI/2 
+  boundslat_reg(1,south)= rlatv(1)
+  DO j=2,jjm
+   boundslat_reg(j,north)=rlatv(j-1) 
+   boundslat_reg(j,south)=rlatv(j) 
+  ENDDO
+  boundslat_reg(jjm+1,north)= rlatv(jjm) 
+  boundslat_reg(jjm+1,south)= -PI/2
+
+  ! Write values in module regular_lonlat_mod
+  CALL init_regular_lonlat(iim,jjm+1, rlonv(1:iim), rlatu, &
+                           boundslon_reg, boundslat_reg)
+
+  ! Generate global arrays on full physics grid
+  ALLOCATE(latfi_glo(klon_glo),lonfi_glo(klon_glo))
+  ALLOCATE(cufi_glo(klon_glo),cvfi_glo(klon_glo))
+  ALLOCATE(airefi_glo(klon_glo))
+  ALLOCATE(boundslonfi_glo(klon_glo,4))
+  ALLOCATE(boundslatfi_glo(klon_glo,4))
+
+    ! North pole
+    latfi_glo(1)=rlatu(1)
+    lonfi_glo(1)=0.
+    cufi_glo(1) = cu(1)
+    cvfi_glo(1) = cv(1)
+    boundslonfi_glo(1,north_east)=0
+    boundslatfi_glo(1,north_east)=PI/2
+    boundslonfi_glo(1,north_west)=2*PI
+    boundslatfi_glo(1,north_west)=PI/2
+    boundslonfi_glo(1,south_west)=2*PI
+    boundslatfi_glo(1,south_west)=rlatv(1)
+    boundslonfi_glo(1,south_east)=0
+    boundslatfi_glo(1,south_east)=rlatv(1)
+    DO j=2,jjm
+      DO i=1,iim
+        k=(j-2)*iim+1+i
+        latfi_glo(k)= rlatu(j)
+        lonfi_glo(k)= rlonv(i)
+        cufi_glo(k) = cu((j-1)*(iim+1)+i)
+        cvfi_glo(k) = cv((j-1)*(iim+1)+i)
+        boundslonfi_glo(k,north_east)=rlonu(i)
+        boundslatfi_glo(k,north_east)=rlatv(j-1)
+        boundslonfi_glo(k,north_west)=rlonu(i+1)
+        boundslatfi_glo(k,north_west)=rlatv(j-1)
+        boundslonfi_glo(k,south_west)=rlonu(i+1)
+        boundslatfi_glo(k,south_west)=rlatv(j)
+        boundslonfi_glo(k,south_east)=rlonu(i)
+        boundslatfi_glo(k,south_east)=rlatv(j)
+      ENDDO
+    ENDDO
+    ! South pole
+    latfi_glo(klon_glo)= rlatu(jjm+1)
+    lonfi_glo(klon_glo)= 0.
+    cufi_glo(klon_glo) = cu((iim+1)*jjm+1)
+    cvfi_glo(klon_glo) = cv((iim+1)*jjm-iim)
+    boundslonfi_glo(klon_glo,north_east)= 0
+    boundslatfi_glo(klon_glo,north_east)= rlatv(jjm)
+    boundslonfi_glo(klon_glo,north_west)= 2*PI
+    boundslatfi_glo(klon_glo,north_west)= rlatv(jjm)
+    boundslonfi_glo(klon_glo,south_west)= 2*PI
+    boundslatfi_glo(klon_glo,south_west)= -PI/2
+    boundslonfi_glo(klon_glo,south_east)= 0
+    boundslatfi_glo(klon_glo,south_east)= -Pi/2
+
+    ! build airefi(), mesh area on physics grid
+    CALL gr_dyn_fi(1,iim+1,jjm+1,klon_glo,aire,airefi_glo)
+    ! Poles are single points on physics grid
+    airefi_glo(1)=sum(aire(1:iim,1))
+    airefi_glo(klon_glo)=sum(aire(1:iim,jjm+1))
+
+    ! Sanity check: do total planet area match between physics and dynamics?
+    total_area_dyn=sum(aire(1:iim,1:jjm+1))
+    total_area_phy=sum(airefi_glo(1:klon_glo))
+    IF (total_area_dyn/=total_area_phy) THEN
+      WRITE (lunout, *) 'iniphysiq: planet total surface discrepancy !!!'
+      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
+      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
+      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
+        ! stop here if the relative difference is more than 0.001%
+        abort_message = 'planet total surface discrepancy'
+        CALL abort_gcm(modname, abort_message, 1)
+      ENDIF
+    ENDIF
+
+!$OMP PARALLEL 
+  ! Now generate local lon/lat/cu/cv/area/bounds arrays
+  ALLOCATE(latfi(klon_omp),lonfi(klon_omp),cufi(klon_omp),cvfi(klon_omp))
+  ALLOCATE(airefi(klon_omp))
+  ALLOCATE(boundslonfi(klon_omp,4))
+  ALLOCATE(boundslatfi(klon_omp,4))
+
+
+  offset = klon_mpi_begin - 1
+  airefi(1:klon_omp) = airefi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  cufi(1:klon_omp) = cufi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  cvfi(1:klon_omp) = cvfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  lonfi(1:klon_omp) = lonfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  latfi(1:klon_omp) = latfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  boundslonfi(1:klon_omp,:) = boundslonfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
+  boundslatfi(1:klon_omp,:) = boundslatfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
+
+  ! copy over local grid longitudes and latitudes
+  CALL init_geometry(klon_omp,lonfi,latfi,boundslonfi,boundslatfi, &
+                     airefi,cufi,cvfi)
+
+  ! Initialize physical constants in physics:
+  CALL inifis(prad,pg,pr,pcpp)
+  
+  ! Initialize dimphy module
+  CALL Init_dimphy(klon_omp,nlayer)
+
+  ! Initialize tracer names, numbers, etc. for physics
+  CALL init_infotrac_phy(nqtot,type_trac)
+
+  ! Additional initializations for aquaplanets 
+  IF (iflag_phys>=100) THEN
+    CALL iniaqua(klon_omp,iflag_phys)
+  ENDIF
+!$OMP END PARALLEL
+
+END SUBROUTINE iniphysiq
+
+END MODULE iniphysiq_mod
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/ce0l.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/ce0l.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/ce0l.F90	(revision 2408)
@@ -1,109 +1,214 @@
+PROGRAM ce0l
 !
-! $Id$
-!
-!-------------------------------------------------------------------------------
-!
-PROGRAM ce0l
-!-------------------------------------------------------------------------------
-! Purpose: Calls etat0, creates initial states and limit_netcdf
-!
-!     interbar=.T. for barycentric interpolation inter_barxy
-!     extrap  =.T. for data extrapolation, like for the SSTs when file does not
-!                  contain ocean points only.
-!     oldice  =.T. for old-style ice, obtained using grille_m (grid_atob).
-!     masque is created in etat0, passed to limit to ensure consistancy.
-!-------------------------------------------------------------------------------
-  USE control_mod
-#ifdef CPP_EARTH
-! This prog. is designed to work for Earth
-  USE dimphy
-  USE comgeomphy
-  USE infotrac
-  USE indice_sol_mod
-
+!-------------------------------------------------------------------------------
+! Purpose: Initial states and boundary conditions files creation:
+!     * start.nc    for dynamics    (using etat0dyn     routine)
+!     * startphy.nc for physics     (using etat0phys    routine)
+!     * limit.nc    for forced runs (using limit_netcdf routine)
+!-------------------------------------------------------------------------------
+! Notes:
+!     * extrap=.T. (default) for data extrapolation, like for the SSTs when file
+!                   does contain ocean points only.
+!     * "masque" can be:
+!       - read from file "o2a.nc"          (for coupled runs).
+!       - created in etat0phys or etat0dyn (for forced  runs).
+!     It is then passed to limit_netcdf to ensure consistancy.
+!-------------------------------------------------------------------------------
+  USE ioipsl, ONLY: ioconf_calendar, getin, flininfo, flinopen, flinget, flinclo
+  USE control_mod,    ONLY: day_step, dayref, nsplit_phys
+  USE etat0dyn,       ONLY: etat0dyn_netcdf
+  USE etat0phys,      ONLY: etat0phys_netcdf
+  USE limit,          ONLY: limit_netcdf
+  USE netcdf,         ONLY: NF90_OPEN, NF90_NOWRITE, NF90_CLOSE, NF90_NOERR
+  USE infotrac,       ONLY: type_trac, infotrac_init
+  USE dimphy,         ONLY: klon
+  USE test_disvert_m, ONLY: test_disvert
+  USE filtreg_mod,    ONLY: inifilr
+  USE iniphysiq_mod,  ONLY: iniphysiq
+  USE mod_const_mpi,  ONLY: comm_lmdz
+#ifdef inca
+  USE indice_sol_mod, ONLY: nbsrf, is_oce, is_sic, is_ter, is_lic
+#endif
+#ifdef CPP_PARA
+  USE mod_const_mpi,  ONLY: init_const_mpi
+  USE parallel_lmdz,  ONLY: init_parallel, mpi_rank, omp_rank, mpi_size
+  USE bands,          ONLY: read_distrib, distrib_phys
+  USE mod_hallo,      ONLY: init_mod_hallo
+  USE mod_interface_dyn_phys, ONLY: init_interface_dyn_phys
+#endif
+
+  IMPLICIT NONE
+
+!-------------------------------------------------------------------------------
+! Local variables:
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom2.h"
+  include "comconst.h"
+  include "comvert.h"
+  include "iniprint.h"
+  include "temps.h"
+  include "logic.h"
+  REAL               :: masque(iip1,jjp1)             !--- CONTINENTAL MASK
+  REAL               :: phis  (iip1,jjp1)             !--- GROUND GEOPOTENTIAL
+  CHARACTER(LEN=256) :: modname, fmt, calnd           !--- CALENDAR TYPE
+  LOGICAL            :: use_filtre_fft
+  LOGICAL, PARAMETER :: extrap=.FALSE.
+
+!--- Local variables for ocean mask reading:
+  INTEGER            :: nid_o2a, iml_omask, jml_omask, j
+  INTEGER            :: fid, iret, llm_tmp, ttm_tmp, itaul(1)
+  REAL, ALLOCATABLE  :: lon_omask(:,:), dlon_omask(:), ocemask(:,:)
+  REAL, ALLOCATABLE  :: lat_omask(:,:), dlat_omask(:), ocetmp (:,:)
+  REAL               :: date, lev(1)
+#ifndef CPP_PARA
+! for iniphysiq in serial mode
+  INTEGER,PARAMETER :: mpi_rank=0
+  INTEGER :: distrib_phys(mpi_rank:mpi_rank)=(jjm-1)*iim+2
+#endif
+!-------------------------------------------------------------------------------
+  modname="ce0l"
+
+!--- Constants
+  pi     = 4. * ATAN(1.)
+  rad    = 6371229.
+  daysec = 86400.
+  omeg   = 2.*pi/daysec
+  g      = 9.8
+  kappa  = 0.2857143
+  cpp    = 1004.70885
+  jmp1   = jjm + 1
+  preff   = 101325.
+  pa      = 50000.
+
+  CALL conf_gcm( 99, .TRUE. )
+  dtvr = daysec/REAL(day_step)
+  WRITE(lunout,*)'dtvr',dtvr
+  CALL iniconst()
+  CALL inigeom()
+
+!--- Calendar choice
 #ifdef CPP_IOIPSL
-  USE ioipsl, ONLY: ioconf_calendar, getin
-#else
-  ! if not using IOIPSL, we still need to use (a local version of) getin
-  use ioipsl_getincom, only: getin
-#endif
-
-#endif
-  IMPLICIT NONE
-#ifndef CPP_EARTH
-#include "iniprint.h"
-  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
-#else
-!-------------------------------------------------------------------------------
-! Local variables:
-  LOGICAL, PARAMETER :: interbar=.TRUE., extrap=.FALSE., oldice=.FALSE.
-#include "dimensions.h"
-#include "paramet.h"
-!#include "indicesol.h"
-#include "iniprint.h"
-#include "temps.h"
-#include "logic.h"
-  REAL,    DIMENSION(iip1,jjp1) :: masque
-  CHARACTER(LEN=15)             :: calnd
-  REAL,    DIMENSION(iip1,jjp1) :: phis ! geopotentiel au sol
-  logical use_filtre_fft
-!-------------------------------------------------------------------------------
-  CALL conf_gcm( 99, .TRUE. )
-
-  use_filtre_fft=.FALSE.
-  CALL getin('use_filtre_fft',use_filtre_fft)
-  IF (use_filtre_fft) THEN
-     write(lunout, fmt = *) 'FFT filter is not available in the ' &
-          // 'sequential version of the dynamics.'
-     write(lunout, fmt = *) &
-          "Your setting of variable use_filtre_fft is not used."
-  ENDIF
-
-  CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
-  WRITE(lunout,*)'---> klon=',klon
-  CALL InitComgeomphy
-
-#ifdef CPP_IOIPSL
+  calnd='gregorian'
   SELECT CASE(calend)
-    CASE('earth_360d');CALL ioconf_calendar('360d');      calnd='a 360 jours/an'
-    CASE('earth_365d');CALL ioconf_calendar('noleap');    calnd='a 365 jours/an'
-    CASE('earth_366d');CALL ioconf_calendar('366d');      calnd='bissextile'
-    CASE('gregorian'); CALL ioconf_calendar('gregorian'); calnd='gregorien'
-    CASE('standard');  CALL ioconf_calendar('gregorian'); calnd='gregorien'
-    CASE('julian');    CALL ioconf_calendar('julian');    calnd='julien'
+    CASE('earth_360d');CALL ioconf_calendar('360d');   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'
+    CASE('gregorian'); CALL ioconf_calendar('gregorian')
+    CASE('standard');  CALL ioconf_calendar('gregorian')
+    CASE('julian');    CALL ioconf_calendar('julian'); calnd='julian'
     CASE('proleptic_gregorian'); CALL ioconf_calendar('gregorian')
   !--- DC Bof...  => IOIPSL a mettre a jour: proleptic_gregorian /= gregorian
     CASE DEFAULT
-      CALL abort_gcm('ce0l','Mauvais choix de calendrier',1)
+      CALL abort_gcm('ce0l','Bad choice for calendar',1)
   END SELECT
-  WRITE(lunout,*)'CALENDRIER CHOISI: Terrestre '//TRIM(calnd)
-#endif
-
+  WRITE(lunout,*)'CHOSEN CALENDAR: Earth '//TRIM(calnd)
+#endif
+
+#ifdef CPP_PARA
+!--- Physical grid + parallel initializations
+  CALL init_const_mpi()
+  CALL init_parallel()
+  CALL read_distrib()
+  CALL init_mod_hallo()
+#endif
+  WRITE(lunout,*)'---> klon=',klon
+
+!--- Tracers initializations
   IF (type_trac == 'inca') THEN
 #ifdef INCA
-    CALL init_const_lmdz(nbtr,anneeref,dayref,iphysiq,day_step,nday)
-    CALL init_inca_para(iim,jjm+1,klon,1,klon_mpi_para_nb,0)
+    CALL init_const_lmdz(nbtr,anneeref,dayref,iphysiq,day_step,nday,&
+                         nbsrf,is_oce,is_sic,is_ter,is_lic,calend)
+    CALL init_inca_para(iim,jjp1,llm,klon_glo,mpi_size,distrib_phys,&
+                        COMM_LMDZ)
     WRITE(lunout,*)'nbtr =' , nbtr 
 #endif
   END IF
-
-  WRITE(lunout,'(//)')
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,*) '  ***  etat0_netcdf ***  '
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,'(//)')
-  WRITE(lunout,*) ' interbar = ',interbar
-  CALL etat0_netcdf(interbar,masque,phis,ok_etat0)
+  CALL infotrac_init()
+
+  CALL inifilr()
+  CALL iniphysiq(iim,jjm,llm, &
+                 distrib_phys(mpi_rank),comm_lmdz, &
+                 daysec,day_ini,dtphys/nsplit_phys, &
+                 rlatu,rlatv,rlonu,rlonv,aire,cu,cv,rad,g,r,cpp,iflag_phys)
+  IF(pressure_exner) CALL test_disvert
+
+#ifdef CPP_PARA
+  IF (mpi_rank==0.AND.omp_rank==0) THEN
+#endif
+  use_filtre_fft=.FALSE.
+  CALL getin('use_filtre_fft',use_filtre_fft)
+  IF(use_filtre_fft) THEN
+     WRITE(lunout,*)"FFT filter not available for sequential dynamics."
+     WRITE(lunout,*)"Your setting of variable use_filtre_fft is not used."
+  ENDIF
+
+!--- LAND MASK. TWO CASES:
+!   1) read from ocean model    file "o2a.nc"    (coupled runs)
+!   2) computed from topography file "Relief.nc" (masque(:,:)=-99999.)
+! Coupled simulations (case 1) use the ocean model mask to compute the
+! weights to ensure ocean fractions are the same for atmosphere and ocean.
+!*******************************************************************************
+  IF(NF90_OPEN("o2a.nc", NF90_NOWRITE, nid_o2a)/=NF90_NOERR) THEN
+    WRITE(lunout,*)'BEWARE !! No ocean mask "o2a.nc" file found'
+    WRITE(lunout,*)'Forced run.'
+    masque(:,:)=-99999.
+  ELSE
+    iret=NF90_CLOSE(nid_o2a)
+    WRITE(lunout,*)'BEWARE !! Ocean mask "o2a.nc" file found'
+    WRITE(lunout,*)'Coupled run.'
+    CALL flininfo("o2a.nc", iml_omask, jml_omask, llm_tmp, ttm_tmp, nid_o2a)
+    IF(iml_omask/=iim .OR.jml_omask/=jjp1) THEN
+      WRITE(lunout,*)'Mismatching dimensions for ocean mask'
+      WRITE(lunout,*)'iim  = ',iim ,' iml_omask = ',iml_omask
+      WRITE(lunout,*)'jjp1 = ',jjp1,' jml_omask = ',jml_omask
+      CALL abort_gcm(modname,'',1)
+    END IF
+    ALLOCATE(ocemask(iim,jjp1),lon_omask(iim,jjp1),dlon_omask(iim ))
+    ALLOCATE(ocetmp (iim,jjp1),lat_omask(iim,jjp1),dlat_omask(jjp1))
+    CALL flinopen("o2a.nc", .FALSE.,iml_omask,jml_omask,llm_tmp,               &
+                  lon_omask,lat_omask,lev,ttm_tmp,itaul,date,dt,fid)
+    CALL flinget(fid, "OceMask",    iim,jjp1,llm_tmp,ttm_tmp,1,1,ocetmp)
+    CALL flinclo(fid)
+    dlon_omask(1:iim ) = lon_omask(1:iim,1)
+    dlat_omask(1:jjp1) = lat_omask(1,1:jjp1)
+    ocemask = ocetmp
+    IF(dlat_omask(1)<dlat_omask(jml_omask)) THEN
+      DO j=1,jjp1; ocemask(:,j) = ocetmp(:,jjp1-j+1); END DO
+    END IF
+    DEALLOCATE(ocetmp,lon_omask,lat_omask,dlon_omask,dlat_omask)
+    IF(prt_level>=1) THEN
+      WRITE(fmt,"(i4,'i1)')")iim ; fmt='('//ADJUSTL(fmt)
+      WRITE(lunout,*)'OCEAN MASK :'
+      WRITE(lunout,fmt) NINT(ocemask)
+    END IF
+    masque(1:iim,:)=1.-ocemask(:,:)
+    masque(iip1 ,:)=masque(1,:)
+    DEALLOCATE(ocemask)
+  END IF
+  phis(:,:)=-99999.
+
+  IF(ok_etat0) THEN
+    WRITE(lunout,'(//)')
+    WRITE(lunout,*) '  ************************  '
+    WRITE(lunout,*) '  ***  etat0phy_netcdf ***  '
+    WRITE(lunout,*) '  ************************  '
+    CALL etat0phys_netcdf(masque,phis)
+    WRITE(lunout,'(//)')
+    WRITE(lunout,*) '  ************************  '
+    WRITE(lunout,*) '  ***  etat0dyn_netcdf ***  '
+    WRITE(lunout,*) '  ************************  '
+    CALL etat0dyn_netcdf(masque,phis)
+  END IF
 
   IF(ok_limit) THEN
-  WRITE(lunout,'(//)')
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,*) '  ***  Limit_netcdf ***  '
-  WRITE(lunout,*) '  *********************  '
-  WRITE(lunout,'(//)')
-  CALL limit_netcdf(interbar,extrap,oldice,masque)
-  END IF
-
-  
+    WRITE(lunout,'(//)')
+    WRITE(lunout,*) '  *********************  '
+    WRITE(lunout,*) '  ***  Limit_netcdf ***  '
+    WRITE(lunout,*) '  *********************  '
+    WRITE(lunout,'(//)')
+    CALL limit_netcdf(masque,phis,extrap)
+  END IF
+
   WRITE(lunout,'(//)')
   WRITE(lunout,*) '  ***************************  '
@@ -113,6 +218,7 @@
   CALL grilles_gcm_netcdf_sub(masque,phis)
 
-#endif
-! of #ifndef CPP_EARTH #else
+#ifdef CPP_PARA
+  END IF
+#endif
 
 END PROGRAM ce0l
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/etat0dyn_netcdf.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/etat0dyn_netcdf.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/etat0dyn_netcdf.F90	(revision 2408)
@@ -0,0 +1,503 @@
+MODULE etat0dyn
+!
+!*******************************************************************************
+! Purpose: Create dynamical initial state using atmospheric fields from a
+!          database of atmospheric to initialize the model.
+!-------------------------------------------------------------------------------
+! Comments:
+!
+!    *  This module is designed to work for Earth (and with ioipsl)
+!
+!    *  etat0dyn_netcdf routine can access to NetCDF data through the following
+!  routine (to be called after restget):
+!    CALL startget_dyn3d(varname, lon_in,  lat_in, pls, workvar,&
+!                          champ, lon_in2, lat_in2)
+!
+!    *  Variables should have the following names in the NetCDF files:
+!            'U'      : East ward wind              (in "ECDYN.nc")
+!            'V'      : Northward wind              (in "ECDYN.nc")
+!            'TEMP'   : Temperature                 (in "ECDYN.nc")
+!            'R'      : Relative humidity           (in "ECDYN.nc")
+!            'RELIEF' : High resolution orography   (in "Relief.nc") 
+!
+!    * The land mask and corresponding weights can be:
+!      1) already known (in particular if etat0dyn has been called before) ;
+!         in this case, ANY(masque(:,:)/=-99999.) = .TRUE.
+!      2) computed using the ocean mask from the ocean model (to ensure ocean
+!         fractions are the same for atmosphere and ocean) for coupled runs.
+!         File name: "o2a.nc"  ;  variable name: "OceMask"
+!      3) computed from topography file "Relief.nc" for forced runs.
+!
+!   *   There is a big mess with the longitude size. Should it be iml or iml+1 ?
+!  I have chosen to use the iml+1 as an argument to this routine and we declare
+!  internaly smaller fields when needed. This needs to be cleared once and for
+!  all in LMDZ. A convention is required.
+!-------------------------------------------------------------------------------
+  USE ioipsl,         ONLY: flininfo, flinopen, flinget, flinclo, histclo
+  USE assert_eq_m,    ONLY: assert_eq
+  IMPLICIT NONE
+
+  PRIVATE
+  PUBLIC :: etat0dyn_netcdf
+
+  include "iniprint.h"
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom2.h"
+  include "comvert.h"
+  include "comconst.h"
+  include "temps.h"
+  include "comdissnew.h"
+  include "serre.h"
+  REAL, SAVE :: deg2rad
+  INTEGER,            SAVE      :: iml_dyn, jml_dyn, llm_dyn, ttm_dyn, fid_dyn
+  REAL, ALLOCATABLE,  SAVE      :: lon_dyn(:,:), lat_dyn(:,:), levdyn_ini(:)
+  CHARACTER(LEN=120), PARAMETER :: dynfname='ECDYN.nc'
+
+CONTAINS
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE etat0dyn_netcdf(masque, phis)
+!
+!-------------------------------------------------------------------------------
+! Purpose: Create dynamical initial states.
+!-------------------------------------------------------------------------------
+! Notes:  1) This routine is designed to work for Earth
+!         2) If masque(:,:)/=-99999., masque and phis are already known.
+!         Otherwise: compute it.
+!-------------------------------------------------------------------------------
+  USE control_mod
+  USE regr_lat_time_coefoz_m, ONLY: regr_lat_time_coefoz
+  USE regr_pr_o3_m,   ONLY: regr_pr_o3
+  USE press_coefoz_m, ONLY: press_coefoz
+  USE exner_hyb_m,    ONLY: exner_hyb
+  USE exner_milieu_m, ONLY: exner_milieu
+  USE infotrac,       ONLY: nqtot, tname
+  USE filtreg_mod
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL,    INTENT(INOUT) :: masque(iip1,jjp1)   !--- Land-ocean mask
+  REAL,    INTENT(INOUT) :: phis  (iip1,jjp1)   !--- Ground geopotential
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname, fmt
+  INTEGER            :: i, j, l, ji, itau, iday
+  REAL               :: xpn, xps, time, phystep
+  REAL, DIMENSION(iip1,jjp1)       :: psol
+  REAL, DIMENSION(iip1,jjp1,llm+1) :: p3d
+  REAL, DIMENSION(iip1,jjp1,llm)   :: uvent, t3d, tpot, qsat, qd
+  REAL, DIMENSION(iip1,jjp1,llm)   :: pk, pls, y, masse
+  REAL, DIMENSION(iip1,jjm ,llm)   :: vvent
+  REAL, DIMENSION(ip1jm    ,llm)   :: pbarv
+  REAL, DIMENSION(ip1jmp1  ,llm)   :: pbaru, phi, w
+  REAL, DIMENSION(ip1jmp1)         :: pks
+  REAL, DIMENSION(iim)             :: xppn, xpps
+  REAL, ALLOCATABLE                :: q3d(:,:,:,:)
+!-------------------------------------------------------------------------------
+  modname='etat0dyn_netcdf'
+
+  deg2rad = pi/180.0
+
+! Compute psol AND tsol, knowing phis.
+!*******************************************************************************
+  CALL start_init_dyn(rlonv, rlatu, rlonu, rlatv, phis, psol)
+
+! Mid-levels pressure computation
+!*******************************************************************************
+  CALL pression(ip1jmp1, ap, bp, psol, p3d)             !--- Update p3d
+  IF(pressure_exner) THEN                               !--- Update pk, pks
+    CALL exner_hyb   (ip1jmp1,psol,p3d,pks,pk)
+  ELSE
+    CALL exner_milieu(ip1jmp1,psol,p3d,pks,pk)
+  END IF
+  pls(:,:,:)=preff*(pk(:,:,:)/cpp)**(1./kappa)          !--- Update pls
+
+! Update uvent, vvent, t3d and tpot
+!*******************************************************************************
+  uvent(:,:,:) = 0.0 ; vvent(:,:,:) = 0.0 ; t3d (:,:,:) = 0.0
+  CALL startget_dyn3d('u'   ,rlonu,rlatu,pls,y ,uvent,rlonv,rlatv)
+  CALL startget_dyn3d('v'   ,rlonv,rlatv,pls(:,:jjm,:),y(:,:jjm,:),vvent,      &
+ &                           rlonu,rlatu(:jjm))
+  CALL startget_dyn3d('t'   ,rlonv,rlatu,pls,y ,t3d ,rlonu,rlatv)
+  tpot(:,:,:)=t3d(:,:,:)
+  CALL startget_dyn3d('tpot',rlonv,rlatu,pls,pk,tpot,rlonu,rlatv)
+
+  WRITE(lunout,*) 'T3D min,max:',MINVAL(t3d(:,:,:)),MAXVAL(t3d(:,:,:))
+  WRITE(lunout,*) 'PLS min,max:',MINVAL(pls(:,:,:)),MAXVAL(pls(:,:,:))
+
+! Humidity at saturation computation
+!*******************************************************************************
+  WRITE(lunout,*) 'avant q_sat'
+  CALL q_sat(llm*jjp1*iip1, t3d, pls, qsat)
+  WRITE(lunout,*) 'apres q_sat'
+  WRITE(lunout,*) 'QSAT min,max:',MINVAL(qsat(:,:,:)),MAXVAL(qsat(:,:,:))
+!  WRITE(lunout,*) 'QSAT :',qsat(10,20,:)
+  qd (:,:,:) = 0.0
+  CALL startget_dyn3d('q',rlonv,rlatu,pls,qsat,qd,rlonu,rlatv)
+  ALLOCATE(q3d(iip1,jjp1,llm,nqtot)); q3d(:,:,:,:)=0.0 ; q3d(:,:,:,1)=qd(:,:,:)
+  CALL flinclo(fid_dyn)
+
+! Parameterization of ozone chemistry:
+!*******************************************************************************
+! Look for ozone tracer:
+  DO i=1,nqtot; IF(ANY(["O3","o3"]==tname(i))) EXIT; END DO
+  IF(i/=nqtot+1) THEN
+    CALL regr_lat_time_coefoz
+    CALL press_coefoz
+    CALL regr_pr_o3(p3d, q3d(:,:,:,i))
+    q3d(:,:,:,i)=q3d(:,:,:,i)*48./ 29.                  !--- Mole->mass fraction         
+  END IF
+  q3d(iip1,:,:,:)=q3d(1,:,:,:)
+
+! Writing
+!*******************************************************************************
+  CALL inidissip(lstardis, nitergdiv, nitergrot, niterh, tetagdiv, tetagrot,   &
+       tetatemp, vert_prof_dissip)
+  WRITE(lunout,*)'sortie inidissip'
+  itau=0
+  itau_dyn=0
+  itau_phy=0
+  iday=dayref+itau/day_step
+  time=FLOAT(itau-(iday-dayref)*day_step)/day_step
+  IF(time>1.) THEN
+   time=time-1
+   iday=iday+1
+  END IF
+  day_ref=dayref
+  annee_ref=anneeref
+  CALL geopot( ip1jmp1, tpot, pk, pks, phis, phi )
+  WRITE(lunout,*)'sortie geopot'
+  CALL caldyn0( itau, uvent, vvent, tpot, psol, masse, pk, phis,               &
+                phi,  w, pbaru, pbarv, time+iday-dayref)
+  WRITE(lunout,*)'sortie caldyn0'     
+#ifdef CPP_PARA
+  CALL dynredem0_loc( "start.nc", dayref, phis)
+#else
+  CALL dynredem0( "start.nc", dayref, phis)
+#endif
+  WRITE(lunout,*)'sortie dynredem0'
+#ifdef CPP_PARA
+  CALL dynredem1_loc( "start.nc", 0.0, vvent, uvent, tpot, q3d, masse, psol)
+#else
+  CALL dynredem1( "start.nc", 0.0, vvent, uvent, tpot, q3d, masse, psol)
+#endif
+  WRITE(lunout,*)'sortie dynredem1' 
+  CALL histclo()
+
+END SUBROUTINE etat0dyn_netcdf
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE startget_dyn3d(var, lon_in,  lat_in,  pls,  workvar,&
+                        champ, lon_in2, lat_in2)
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!===============================================================================
+! Purpose: Compute some quantities (u,v,t,q,tpot) using variables U,V,TEMP and R
+!     (3D fields) of file dynfname.
+!-------------------------------------------------------------------------------
+! Note: An input auxilliary field "workvar" has to be specified in two cases:
+!     * for "q":    the saturated humidity.
+!     * for "tpot": the Exner function.
+!===============================================================================
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN)    :: var
+  REAL,             INTENT(IN)    :: lon_in(:)        ! dim (iml)
+  REAL,             INTENT(IN)    :: lat_in(:)        ! dim (jml)
+  REAL,             INTENT(IN)    :: pls    (:, :, :) ! dim (iml, jml, lml)
+  REAL,             INTENT(IN)    :: workvar(:, :, :) ! dim (iml, jml, lml)
+  REAL,             INTENT(INOUT) :: champ  (:, :, :) ! dim (iml, jml, lml)
+  REAL,             INTENT(IN)    :: lon_in2(:)       ! dim (iml)
+  REAL,             INTENT(IN)    :: lat_in2(:)       ! dim (jml2)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=10)  :: vname
+  CHARACTER(LEN=256) :: msg, modname="startget_dyn3d"
+  INTEGER            :: iml, jml, jml2, lml, il
+  REAL               :: xppn, xpps
+!-------------------------------------------------------------------------------
+  iml=assert_eq([SIZE(lon_in),SIZE(pls,1),SIZE(workvar,1),SIZE(champ,1),       &
+     &                                    SIZE(lon_in2)], TRIM(modname)//" iml")
+  jml=assert_eq( SIZE(lat_in),SIZE(pls,2),SIZE(workvar,2),SIZE(champ,2),       &
+     &                                                    TRIM(modname)//" jml")
+  lml=assert_eq(              SIZE(pls,3),SIZE(workvar,3),SIZE(champ,3),       &
+     &                                                    TRIM(modname)//" lml")
+  jml2=SIZE(lat_in2)
+
+!--- CHECK IF THE FIELD IS KNOWN
+   SELECT CASE(var)
+    CASE('u');    vname='U'
+    CASE('v');    vname='V'
+    CASE('t');    vname='TEMP'
+    CASE('q');    vname='R';    msg='humidity as the saturated humidity'
+    CASE('tpot'); msg='potential temperature as the Exner function'
+    CASE DEFAULT; msg='No rule to extract variable '//TRIM(var)
+      CALL abort_gcm(modname,TRIM(msg)//' from any data set',1)
+  END SELECT
+
+!--- CHECK IF SOMETHING IS MISSING
+  IF((var=='tpot'.OR.var=='q').AND.MINVAL(workvar)==MAXVAL(workvar)) THEN
+    msg='Could not compute '//TRIM(msg)//' is missing or constant.'
+    CALL abort_gcm(modname,TRIM(msg),1)
+  END IF
+
+!--- INTERPOLATE 3D FIELD IF NEEDED
+  IF(var/='tpot') CALL start_inter_3d(TRIM(vname),lon_in,lat_in,lon_in2,      &
+                                                  lat_in2,pls,champ)
+
+!--- COMPUTE THE REQUIRED FILED
+  SELECT CASE(var)
+    CASE('u'); DO il=1,lml; champ(:,:,il)=champ(:,:,il)*cu(:,1:jml); END DO
+      champ(iml,:,:)=champ(1,:,:)                   !--- Eastward wind
+
+    CASE('v'); DO il=1,lml; champ(:,:,il)=champ(:,:,il)*cv(:,1:jml); END DO
+      champ(iml,:,:)=champ(1,:,:)                   !--- Northward wind
+
+    CASE('tpot','q')
+      IF(var=='tpot') THEN; champ=champ*cpp/workvar !--- Potential temperature
+      ELSE;                 champ=champ*.01*workvar !--- Relative humidity
+        WHERE(champ<0.) champ=1.0E-10
+      END IF
+      DO il=1,lml
+        xppn = SUM(aire(:,1  )*champ(:,1  ,il))/apoln
+        xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
+        champ(:,1  ,il) = xppn
+        champ(:,jml,il) = xpps
+      END DO
+  END SELECT
+
+END SUBROUTINE startget_dyn3d
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_init_dyn(lon_in,lat_in,lon_in2,lat_in2,zs,psol)
+!
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!===============================================================================
+! Purpose:   Compute psol, knowing phis.
+!===============================================================================
+! Arguments:
+  REAL,    INTENT(IN)  :: lon_in (:),  lat_in (:)    ! dim (iml) (jml)
+  REAL,    INTENT(IN)  :: lon_in2(:),  lat_in2(:)    ! dim (iml) (jml2)
+  REAL,    INTENT(IN)  :: zs  (:,:)                  ! dim (iml,jml)
+  REAL,    INTENT(OUT) :: psol(:,:)                  ! dim (iml,jml)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname='start_init_dyn'
+  REAL               :: date, dt
+  INTEGER            :: iml, jml, jml2, itau(1)
+  REAL, ALLOCATABLE  :: lon_rad(:), lon_ini(:), var_ana(:,:)
+  REAL, ALLOCATABLE  :: lat_rad(:), lat_ini(:)
+  REAL, ALLOCATABLE  :: z(:,:), ps(:,:), ts(:,:)
+!-------------------------------------------------------------------------------
+  iml=assert_eq(SIZE(lon_in),SIZE(zs,1),SIZE(psol,1),SIZE(lon_in2),            &
+      &                                              TRIM(modname)//" iml")
+  jml=assert_eq(SIZE(lat_in),SIZE(zs,2),SIZE(psol,2),TRIM(modname)//" jml")
+  jml2=SIZE(lat_in2)
+
+  WRITE(lunout,*) 'Opening the surface analysis'
+  CALL flininfo(dynfname, iml_dyn, jml_dyn, llm_dyn, ttm_dyn, fid_dyn)
+  WRITE(lunout,*) 'Values read: ', iml_dyn, jml_dyn, llm_dyn, ttm_dyn
+
+  ALLOCATE(lon_dyn(iml_dyn,jml_dyn), lat_dyn(iml_dyn,jml_dyn))
+  ALLOCATE(levdyn_ini(llm_dyn))
+  CALL flinopen(dynfname, .FALSE., iml_dyn, jml_dyn, llm_dyn,                  &
+                lon_dyn,lat_dyn,levdyn_ini,ttm_dyn,itau,date,dt,fid_dyn)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_dyn),lat_ini(jml_dyn))
+  lon_ini(:)=lon_dyn(:,1); IF(MAXVAL(lon_dyn)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_dyn(1,:); IF(MAXVAL(lat_dyn)>pi) lat_ini=lat_ini*deg2rad
+
+  ALLOCATE(var_ana(iml_dyn,jml_dyn),lon_rad(iml_dyn),lat_rad(jml_dyn))
+  CALL get_var_dyn('Z',z)                        !--- SURFACE GEOPOTENTIAL
+  CALL get_var_dyn('SP',ps)                      !--- SURFACE PRESSURE
+  CALL get_var_dyn('ST',ts)                      !--- SURFACE TEMPERATURE
+!  CALL flinclo(fid_dyn)
+  DEALLOCATE(var_ana,lon_rad,lat_rad,lon_ini,lat_ini)
+
+!--- PSOL IS COMPUTED IN PASCALS
+  psol(:iml-1,:) = ps(:iml-1,:)*(1.0+(z(:iml-1,:)-zs(:iml-1,:))/287.0          &
+     &            /ts(:iml-1,:))
+  psol(iml,:)=psol(1,:)
+  DEALLOCATE(z,ps,ts)
+  psol(:,1  )=SUM(aire(1:iml-1,1  )*psol(1:iml-1,1  ))/apoln  !--- NORTH POLE
+  psol(:,jml)=SUM(aire(1:iml-1,jml)*psol(1:iml-1,jml))/apols  !--- SOUTH POLE
+
+CONTAINS
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE get_var_dyn(title,field)
+!
+!-------------------------------------------------------------------------------
+  USE conf_dat_m, ONLY: conf_dat2d
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),  INTENT(IN)    :: title
+  REAL, ALLOCATABLE, INTENT(INOUT) :: field(:,:)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: msg
+  INTEGER :: tllm
+!-------------------------------------------------------------------------------
+  SELECT CASE(title)
+    CASE('Z');     tllm=0;       msg='geopotential'
+    CASE('SP');    tllm=0;       msg='surface pressure'
+    CASE('ST');    tllm=llm_dyn; msg='temperature'
+  END SELECT
+  IF(.NOT.ALLOCATED(field)) THEN
+    ALLOCATE(field(iml,jml))
+    CALL flinget(fid_dyn, title, iml_dyn,jml_dyn, tllm, ttm_dyn, 1, 1, var_ana)
+    CALL conf_dat2d(title, lon_ini, lat_ini, lon_rad, lat_rad, var_ana, .TRUE.)
+    CALL interp_startvar(title, .TRUE., lon_rad,lat_rad, var_ana,              &
+                                        lon_in, lat_in, lon_in2, lat_in2, field)
+  ELSE IF(SIZE(field)/=SIZE(z)) THEN
+    msg='The '//TRIM(msg)//' field we have does not have the right size'
+    CALL abort_gcm(TRIM(modname),msg,1)
+  END IF
+
+END SUBROUTINE get_var_dyn
+!
+!-------------------------------------------------------------------------------
+
+END SUBROUTINE start_init_dyn
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_inter_3d(var,lon_in,lat_in,lon_in2,lat_in2,pls_in,var3d)
+!
+!-------------------------------------------------------------------------------
+  USE conf_dat_m, ONLY: conf_dat3d
+  USE pchsp_95_m, ONLY: pchsp_95
+  USE pchfe_95_m, ONLY: pchfe_95
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN) :: var
+  REAL,    INTENT(IN)  :: lon_in(:),  lat_in(:)   ! dim (iml) (jml)
+  REAL,    INTENT(IN)  :: lon_in2(:), lat_in2(:)  ! dim (iml) (jml2)
+  REAL,    INTENT(IN)  :: pls_in(:,:,:)           ! dim (iml,jml,lml)
+  REAL,    INTENT(OUT) :: var3d (:,:,:)           ! dim (iml,jml,lml)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname='start_inter_3d'
+  LOGICAL :: skip
+  REAL    :: chmin, chmax
+  INTEGER :: iml, jml, lml, jml2, ii, ij, il, ierr
+  INTEGER :: n_extrap                             ! Extrapolated points number
+  REAL, ALLOCATABLE :: ax(:), lon_rad(:), lon_ini(:), lev_dyn(:), yder(:)
+  REAL, ALLOCATABLE :: ay(:), lat_rad(:), lat_ini(:), var_tmp3d(:,:,:)
+  REAL, ALLOCATABLE, SAVE :: var_ana3d(:,:,:)
+!-------------------------------------------------------------------------------
+  iml=assert_eq(SIZE(lon_in),SIZE(lon_in2),SIZE(pls_in,1),SIZE(var3d,1),TRIM(modname)//" iml")
+  jml=assert_eq(SIZE(lat_in),              SIZE(pls_in,2),SIZE(var3d,2),TRIM(modname)//" jml")
+  lml=assert_eq(SIZE(pls_in,3),SIZE(var3d,3),TRIM(modname)//" lml"); jml2=SIZE(lat_in2)
+
+  WRITE(lunout, *)'Going into flinget to extract the 3D field.'
+  IF(.NOT.ALLOCATED(var_ana3d)) ALLOCATE(var_ana3d(iml_dyn, jml_dyn, llm_dyn))
+  CALL flinget(fid_dyn,var,iml_dyn,jml_dyn,llm_dyn,ttm_dyn,1,1,var_ana3d)
+
+!--- ANGLES IN DEGREES ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_dyn), lat_ini(jml_dyn))
+  lon_ini(:)=lon_dyn(:,1); IF(MAXVAL(lon_dyn)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_dyn(1,:); IF(MAXVAL(lat_dyn)>pi) lat_ini=lat_ini*deg2rad
+
+!--- FIELDS ARE PROCESSED TO BE ON STANDARD ANGULAR DOMAINS
+  ALLOCATE(lon_rad(iml_dyn), lat_rad(jml_dyn), lev_dyn(llm_dyn))
+  CALL conf_dat3d(var, lon_ini, lat_ini, levdyn_ini,                           &
+                       lon_rad, lat_rad, lev_dyn, var_ana3d, .TRUE.)
+  DEALLOCATE(lon_ini, lat_ini)
+
+!--- COMPUTE THE REQUIRED FIELDS USING ROUTINE grid_noro
+  ALLOCATE(var_tmp3d(iml,jml,llm_dyn))
+  DO il = 1,llm_dyn
+    CALL interp_startvar(var,il==1,lon_rad,lat_rad,var_ana3d(:,:,il),          &
+                          lon_in,lat_in,lon_in2,lat_in2,var_tmp3d(:,:,il))
+  END DO
+  DEALLOCATE(lon_rad, lat_rad)
+
+!--- VERTICAL INTERPOLATION FROM TOP OF ATMOSPHERE TO GROUND
+  ALLOCATE(ax(llm_dyn),ay(llm_dyn),yder(llm_dyn))
+  ax = lev_dyn(llm_dyn:1:-1) 
+  skip = .FALSE.
+  n_extrap = 0
+  DO ij=1, jml
+    DO ii=1, iml-1
+      ay = var_tmp3d(ii, ij, llm_dyn:1:-1)
+      yder = pchsp_95(ax, ay, ibeg=2, iend=2, vc_beg=0., vc_end=0.)
+      CALL pchfe_95(ax, ay, yder, skip, pls_in(ii, ij, lml:1:-1),              &
+           var3d(ii, ij, lml:1:-1), ierr)
+      IF(ierr<0) CALL abort_gcm(TRIM(modname),'error in pchfe_95',1)
+      n_extrap = n_extrap + ierr
+    END DO
+  END DO
+  IF(n_extrap/=0) WRITE(lunout,*)TRIM(modname)//" pchfe_95: n_extrap=", n_extrap
+  var3d(iml, :, :) = var3d(1, :, :) 
+
+  DO il=1, lml
+    CALL minmax(iml*jml, var3d(1, 1, il), chmin, chmax)
+    WRITE(lunout, *)' '//TRIM(var)//'  min max l ', il, chmin, chmax
+  END DO
+
+END SUBROUTINE start_inter_3d
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE interp_startvar(nam,ibeg,lon,lat,vari,lon1,lat1,lon2,lat2,varo)
+!
+!-------------------------------------------------------------------------------
+  USE inter_barxy_m, ONLY: inter_barxy
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN)  :: nam
+  LOGICAL,          INTENT(IN)  :: ibeg
+  REAL,             INTENT(IN)  :: lon(:), lat(:)   ! dim (ii) (jj)
+  REAL,             INTENT(IN)  :: vari(:,:)        ! dim (ii,jj)
+  REAL,             INTENT(IN)  :: lon1(:), lat1(:) ! dim (i1) (j1)
+  REAL,             INTENT(IN)  :: lon2(:), lat2(:) ! dim (i1) (j2)
+  REAL,             INTENT(OUT) :: varo(:,:)        ! dim (i1) (j1)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname="interp_startvar"
+  INTEGER            :: ii, jj, i1, j1, j2
+  REAL, ALLOCATABLE  :: vtmp(:,:)
+!-------------------------------------------------------------------------------
+  ii=assert_eq(SIZE(lon),            SIZE(vari,1),TRIM(modname)//" ii")
+  jj=assert_eq(SIZE(lat),            SIZE(vari,2),TRIM(modname)//" jj")
+  i1=assert_eq(SIZE(lon1),SIZE(lon2),SIZE(varo,1),TRIM(modname)//" i1")
+  j1=assert_eq(SIZE(lat1),           SIZE(varo,2),TRIM(modname)//" j1")
+  j2=SIZE(lat2)
+  ALLOCATE(vtmp(i1-1,j1))
+  IF(ibeg.AND.prt_level>1) THEN
+    WRITE(lunout,*)"---------------------------------------------------------"
+    WRITE(lunout,*)"$$$ Interpolation barycentrique pour "//TRIM(nam)//" $$$"
+    WRITE(lunout,*)"---------------------------------------------------------"
+  END IF
+  CALL inter_barxy(lon, lat(:jj-1), vari, lon2(:i1-1), lat2, vtmp)
+  CALL gr_int_dyn(vtmp, varo, i1-1, j1)
+
+END SUBROUTINE interp_startvar
+!
+!-------------------------------------------------------------------------------
+
+END MODULE etat0dyn
+!
+!*******************************************************************************
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/etat0phys_netcdf.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/etat0phys_netcdf.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/etat0phys_netcdf.F90	(revision 2408)
@@ -0,0 +1,454 @@
+MODULE etat0phys
+!
+!*******************************************************************************
+! Purpose: Create physical initial state using atmospheric fields from a
+!          database of atmospheric to initialize the model.
+!-------------------------------------------------------------------------------
+! Comments:
+!
+!    *  This module is designed to work for Earth (and with ioipsl)
+!
+!    *  etat0phys_netcdf routine can access to NetCDF data through subroutines:
+!         "start_init_phys" for variables contained in file "ECPHY.nc":
+!            'ST'     : Surface temperature
+!            'CDSW'   : Soil moisture
+!         "start_init_orog" for variables contained in file "Relief.nc":
+!            'RELIEF' : High resolution orography 
+!
+!    * The land mask and corresponding weights can be:
+!      1) computed using the ocean mask from the ocean model (to ensure ocean
+!         fractions are the same for atmosphere and ocean) for coupled runs.
+!         File name: "o2a.nc"  ;  variable name: "OceMask"
+!      2) computed from topography file "Relief.nc" for forced runs.
+!
+!    * Allowed values for read_climoz flag are 0, 1 and 2:
+!      0: do not read an ozone climatology
+!      1: read a single ozone climatology that will be used day and night
+!      2: read two ozone climatologies, the average day and night climatology
+!         and the daylight climatology
+!-------------------------------------------------------------------------------
+!    * There is a big mess with the longitude size. Should it be iml or iml+1 ?
+!  I have chosen to use the iml+1 as an argument to this routine and we declare
+!  internaly smaller fields when needed. This needs to be cleared once and for
+!  all in LMDZ. A convention is required.
+!-------------------------------------------------------------------------------
+
+  USE ioipsl,             ONLY: flininfo, flinopen, flinget, flinclo
+  USE assert_eq_m,        ONLY: assert_eq
+  USE dimphy,             ONLY: klon
+  USE conf_dat_m,         ONLY: conf_dat2d
+  USE phys_state_var_mod, ONLY: zmea, zstd, zsig, zgam, zthe, zpic, zval, z0m, &
+    rlon, solsw, radsol, t_ancien, wake_deltat, wake_s,  rain_fall, qsol, z0h, &
+    rlat, sollw, rugoro, q_ancien, wake_deltaq, wake_pe, snow_fall, ratqs,w01, &
+    sig1, ftsol, clwcon, fm_therm, wake_Cstar,  pctsrf,  entr_therm,radpas, f0,&
+    zmax0,fevap, rnebcon,falb_dir, wake_fip,    agesno,  detr_therm, pbl_tke,  &
+    phys_state_var_init
+
+  PRIVATE
+  PUBLIC :: etat0phys_netcdf
+
+  include "iniprint.h"
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom2.h"
+  include "comconst.h"
+  include "dimsoil.h"
+  include "temps.h"
+  include "clesphys.h"
+  REAL, SAVE :: deg2rad
+  REAL, SAVE, ALLOCATABLE :: tsol(:)
+  INTEGER,            SAVE      :: iml_phys, jml_phys, llm_phys, ttm_phys, fid_phys
+  REAL, ALLOCATABLE,  SAVE      :: lon_phys(:,:), lat_phys(:,:), levphys_ini(:)
+  CHARACTER(LEN=256), PARAMETER :: orofname="Relief.nc", orogvar="RELIEF"
+  CHARACTER(LEN=256), PARAMETER :: phyfname="ECPHY.nc",  psrfvar="SP"
+  CHARACTER(LEN=256), PARAMETER :: qsolvar="CDSW",       tsrfvar="ST"
+
+
+CONTAINS
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE etat0phys_netcdf(masque, phis)
+!
+!-------------------------------------------------------------------------------
+! Purpose: Creates initial states
+!-------------------------------------------------------------------------------
+! Notes:  1) This routine is designed to work for Earth
+!         2) If masque(:,:)/=-99999., masque and phis are already known.
+!         Otherwise: compute it.
+!-------------------------------------------------------------------------------
+  USE control_mod
+  USE fonte_neige_mod
+  USE pbl_surface_mod
+  USE regr_lat_time_climoz_m, ONLY: regr_lat_time_climoz
+  USE indice_sol_mod
+  USE conf_phys_m, ONLY: conf_phys
+  USE init_ssrf_m, ONLY: start_init_subsurf
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL,    INTENT(INOUT) :: masque(:,:) !--- Land mask           dim(iip1,jjp1)
+  REAL,    INTENT(INOUT) :: phis  (:,:) !--- Ground geopotential dim(iip1,jjp1)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname="etat0phys_netcdf", fmt
+  INTEGER            :: i, j, l, ji, iml, jml
+  LOGICAL            :: read_mask
+  REAL               :: phystep, dummy
+  REAL, DIMENSION(SIZE(masque,1),SIZE(masque,2)) :: masque_tmp
+  REAL, DIMENSION(klon)               :: sn, rugmer, run_off_lic_0, fder
+  REAL, DIMENSION(klon,nbsrf)         :: qsolsrf, snsrf
+  REAL, DIMENSION(klon,nsoilmx,nbsrf) :: tsoil
+
+!--- Arguments for conf_phys
+  LOGICAL :: ok_journe, ok_mensuel, ok_instan, ok_hf, ok_LES, callstats
+  REAL    :: solarlong0, seuil_inversion, fact_cldcon, facttemps
+  LOGICAL :: ok_newmicro
+  INTEGER :: iflag_radia, iflag_cldcon, iflag_ratqs
+  REAL    :: ratqsbas, ratqshaut, tau_ratqs
+  LOGICAL :: ok_ade, ok_aie, ok_cdnc, aerosol_couple
+  INTEGER :: flag_aerosol
+  LOGICAL :: flag_aerosol_strat
+  LOGICAL :: new_aod
+  REAL    :: bl95_b0, bl95_b1
+  INTEGER :: read_climoz                        !--- Read ozone climatology
+  REAL    :: alp_offset
+
+  deg2rad= pi/180.0
+  iml=assert_eq(SIZE(masque,1),SIZE(phis,1),TRIM(modname)//" iml")
+  jml=assert_eq(SIZE(masque,2),SIZE(phis,2),TRIM(modname)//" jml")
+
+! Physics configuration
+!*******************************************************************************
+  CALL conf_phys(  ok_journe, ok_mensuel, ok_instan, ok_hf, ok_LES,     &
+                   callstats,                                           &
+                   solarlong0,seuil_inversion,                          &
+                   fact_cldcon, facttemps,ok_newmicro,iflag_radia,      &
+                   iflag_cldcon,                                        &
+                   iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,            &
+                   ok_ade, ok_aie, ok_cdnc, aerosol_couple,             &
+                   flag_aerosol, flag_aerosol_strat, new_aod,           &
+                   bl95_b0, bl95_b1,                                    &
+                   read_climoz,                                         &
+                   alp_offset)
+  CALL phys_state_var_init(read_climoz)
+
+!--- Initial atmospheric CO2 conc. from .def file
+  co2_ppm0 = co2_ppm
+
+! Compute ground geopotential, sub-cells quantities and possibly the mask.
+!*******************************************************************************
+  read_mask=ANY(masque/=-99999.); masque_tmp=masque
+  CALL start_init_orog(rlonv, rlatu, phis, masque_tmp)
+  WRITE(fmt,"(i4,'i1)')")iml ; fmt='('//ADJUSTL(fmt)
+  IF(.NOT.read_mask) THEN                       !--- Keep mask form orography
+    masque=masque_tmp
+    IF(prt_level>=1) THEN
+      WRITE(lunout,*)'BUILT MASK :'
+      WRITE(lunout,fmt) NINT(masque)
+    END IF
+    WHERE(   masque(:,:)<EPSFRA) masque(:,:)=0.
+    WHERE(1.-masque(:,:)<EPSFRA) masque(:,:)=1.
+  END IF
+  CALL gr_dyn_fi(1,iml,jml,klon,masque,zmasq) !--- Land mask to physical grid
+
+! Compute tsol and qsol on physical grid, knowing phis on 2D grid.
+!*******************************************************************************
+  CALL start_init_phys(rlonu, rlatv, phis)
+
+! Some initializations.
+!*******************************************************************************
+  sn    (:) = 0.0                               !--- Snow
+  radsol(:) = 0.0                               !--- Net radiation at ground
+  rugmer(:) = 0.001                             !--- Ocean rugosity
+  IF(read_climoz>=1) &                          !--- Ozone climatology
+    CALL regr_lat_time_climoz(read_climoz)
+
+! Sub-surfaces initialization.
+!*******************************************************************************
+  CALL start_init_subsurf(read_mask)
+
+! Write physical initial state
+!*******************************************************************************
+  WRITE(lunout,*)'phystep ',dtvr,iphysiq,nbapp_rad
+  phystep = dtvr * FLOAT(iphysiq)
+  radpas  = NINT (86400./phystep/ FLOAT(nbapp_rad) )
+  WRITE(lunout,*)'phystep =', phystep, radpas
+
+! Init: ftsol, snsrf, qsolsrf, tsoil, rain_fall, snow_fall, solsw, sollw, z0
+!*******************************************************************************
+  DO i=1,nbsrf; ftsol(:,i) = tsol; END DO
+  DO i=1,nbsrf; snsrf(:,i) = sn;   END DO
+  falb_dir(:,is_ter,:) = 0.08
+  falb_dir(:,is_lic,:) = 0.6
+  falb_dir(:,is_oce,:) = 0.5
+  falb_dir(:,is_sic,:) = 0.6
+  fevap(:,:) = 0.
+  DO i=1,nbsrf; qsolsrf(:,i)=150.; END DO
+  DO i=1,nbsrf; DO j=1,nsoilmx; tsoil(:,j,i) = tsol; END DO; END DO
+  rain_fall  = 0.
+  snow_fall  = 0.
+  solsw      = 165.
+  sollw      = -53.
+  t_ancien   = 273.15
+  q_ancien   = 0.
+  agesno     = 0.
+
+  z0m(:,is_oce) = rugmer(:)
+  z0m(:,is_ter) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
+  z0m(:,is_lic) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
+  z0m(:,is_sic) = 0.001
+  z0h(:,:)=z0m(:,:)
+
+  fder    = 0.0
+  clwcon  = 0.0
+  rnebcon = 0.0
+  ratqs   = 0.0
+  run_off_lic_0 = 0.0 
+  rugoro  = 0.0
+
+! Before phyredem calling, surface modules and values to be saved in startphy.nc
+! are initialized
+!*******************************************************************************
+  dummy            = 1.0
+  pbl_tke(:,:,:)   = 1.e-8 
+  zmax0(:)         = 40.
+  f0(:)            = 1.e-5
+  sig1(:,:)        = 0.
+  w01(:,:)         = 0.
+  wake_deltat(:,:) = 0.
+  wake_deltaq(:,:) = 0.
+  wake_s(:)        = 0.
+  wake_cstar(:)    = 0.
+  wake_fip(:)      = 0.
+  wake_pe          = 0.
+  fm_therm         = 0.
+  entr_therm       = 0.
+  detr_therm       = 0.
+
+  CALL fonte_neige_init(run_off_lic_0)
+  CALL pbl_surface_init( fder, snsrf, qsolsrf, tsoil )
+  CALL phyredem( "startphy.nc" )
+
+!  WRITE(lunout,*)'CCCCCCCCCCCCCCCCCC REACTIVER SORTIE VISU DANS ETAT0'
+!  WRITE(lunout,*)'entree histclo'
+  CALL histclo()
+
+END SUBROUTINE etat0phys_netcdf
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_init_orog(lon_in,lat_in,phis,masque)
+!
+!===============================================================================
+! Comment:
+!   This routine launch grid_noro, which computes parameters for SSO scheme as
+!   described in LOTT & MILLER (1997) and LOTT(1999).
+!===============================================================================
+  USE grid_noro_m, ONLY: grid_noro
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL,    INTENT(IN)    :: lon_in(:), lat_in(:)   ! dim (iml) (jml)
+  REAL,    INTENT(INOUT) :: phis(:,:), masque(:,:) ! dim (iml,jml)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname
+  INTEGER            :: fid, llm_tmp,ttm_tmp, iml,jml, iml_rel,jml_rel, itau(1)
+  REAL               :: lev(1), date, dt
+  REAL, ALLOCATABLE  :: lon_rad(:), lon_ini(:), lon_rel(:,:), relief_hi(:,:)
+  REAL, ALLOCATABLE  :: lat_rad(:), lat_ini(:), lat_rel(:,:), tmp_var  (:,:)
+  REAL, ALLOCATABLE  :: zmea0(:,:), zstd0(:,:), zsig0(:,:)
+  REAL, ALLOCATABLE  :: zgam0(:,:), zthe0(:,:), zpic0(:,:), zval0(:,:)
+!-------------------------------------------------------------------------------
+  modname="start_init_orog"
+  iml=assert_eq(SIZE(lon_in),SIZE(phis,1),SIZE(masque,1),TRIM(modname)//" iml")
+  jml=assert_eq(SIZE(lat_in),SIZE(phis,2),SIZE(masque,2),TRIM(modname)//" jml")
+
+!--- HIGH RESOLUTION OROGRAPHY
+  CALL flininfo(orofname, iml_rel, jml_rel, llm_tmp, ttm_tmp, fid)
+
+  ALLOCATE(lat_rel(iml_rel,jml_rel),lon_rel(iml_rel,jml_rel))
+  CALL flinopen(orofname, .FALSE., iml_rel, jml_rel, llm_tmp, lon_rel, lat_rel,&
+                lev, ttm_tmp, itau, date, dt, fid)
+  ALLOCATE(relief_hi(iml_rel,jml_rel))
+  CALL flinget(fid, orogvar, iml_rel, jml_rel, llm_tmp, ttm_tmp, 1,1, relief_hi)
+  CALL flinclo(fid)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_rel),lat_ini(jml_rel))
+  lon_ini(:)=lon_rel(:,1); IF(MAXVAL(lon_rel)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_rel(1,:); IF(MAXVAL(lat_rel)>pi) lat_ini=lat_ini*deg2rad
+
+!--- FIELDS ARE PROCESSED TO BE ON STANDARD ANGULAR DOMAINS
+  ALLOCATE(lon_rad(iml_rel),lat_rad(jml_rel))
+  CALL conf_dat2d(orogvar, lon_ini, lat_ini, lon_rad, lat_rad, relief_hi,.FALSE.)
+  DEALLOCATE(lon_ini,lat_ini)
+
+!--- COMPUTING THE REQUIRED FIELDS USING ROUTINE grid_noro
+  WRITE(lunout,*)
+  WRITE(lunout,*)'*** Compute parameters needed for gravity wave drag code ***'
+
+!--- ALLOCATIONS OF SUB-CELL SCALES QUANTITIES
+  ALLOCATE(zmea0(iml,jml),zstd0(iml,jml)) !--- Mean orography and std deviation
+  ALLOCATE(zsig0(iml,jml),zgam0(iml,jml)) !--- Slope and nisotropy
+  ALLOCATE(zthe0(iml,jml))                !--- Highest slope orientation
+  ALLOCATE(zpic0(iml,jml),zval0(iml,jml)) !--- Peaks and valley heights
+
+!--- CALL OROGRAPHY MODULE TO COMPUTE FIELDS
+  CALL grid_noro(lon_rad,lat_rad,relief_hi,lon_in,lat_in,phis,zmea0,zstd0,     &
+                                      zsig0,zgam0,zthe0,zpic0,zval0,masque)
+  phis = phis * 9.81
+  phis(iml,:) = phis(1,:)
+  DEALLOCATE(relief_hi,lon_rad,lat_rad)
+
+!--- PUT QUANTITIES TO PHYSICAL GRID
+  CALL gr_dyn_fi(1,iml,jml,klon,zmea0,zmea); DEALLOCATE(zmea0)
+  CALL gr_dyn_fi(1,iml,jml,klon,zstd0,zstd); DEALLOCATE(zstd0)
+  CALL gr_dyn_fi(1,iml,jml,klon,zsig0,zsig); DEALLOCATE(zsig0)
+  CALL gr_dyn_fi(1,iml,jml,klon,zgam0,zgam); DEALLOCATE(zgam0)
+  CALL gr_dyn_fi(1,iml,jml,klon,zthe0,zthe); DEALLOCATE(zthe0)
+  CALL gr_dyn_fi(1,iml,jml,klon,zpic0,zpic); DEALLOCATE(zpic0)
+  CALL gr_dyn_fi(1,iml,jml,klon,zval0,zval); DEALLOCATE(zval0)
+
+
+END SUBROUTINE start_init_orog
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_init_phys(lon_in,lat_in,phis)
+!
+!===============================================================================
+! Purpose:   Compute tsol and qsol, knowing phis.
+!===============================================================================
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL,    INTENT(IN) :: lon_in(:),  lat_in(:)       ! dim (iml) (jml2)
+  REAL,    INTENT(IN) :: phis(:,:)                   ! dim (iml,jml)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname
+  REAL               :: date, dt
+  INTEGER            :: iml, jml, jml2, itau(1)
+  REAL, ALLOCATABLE  :: lon_rad(:), lon_ini(:), var_ana(:,:)
+  REAL, ALLOCATABLE  :: lat_rad(:), lat_ini(:)
+  REAL, ALLOCATABLE  :: ts(:,:), qs(:,:)
+!-------------------------------------------------------------------------------
+  modname="start_init_phys"
+  iml=assert_eq(SIZE(lon_in),SIZE(phis,1),TRIM(modname)//" iml")
+  jml=SIZE(phis,2); jml2=SIZE(lat_in)
+
+  WRITE(lunout,*)'Opening the surface analysis'
+  CALL flininfo(phyfname, iml_phys, jml_phys, llm_phys, ttm_phys, fid_phys)
+  WRITE(lunout,*) 'Values read: ',  iml_phys, jml_phys, llm_phys, ttm_phys
+
+  ALLOCATE(lat_phys(iml_phys,jml_phys),lon_phys(iml_phys,jml_phys))
+  ALLOCATE(levphys_ini(llm_phys))
+  CALL flinopen(phyfname, .FALSE., iml_phys, jml_phys, llm_phys,              &
+                lon_phys,lat_phys,levphys_ini,ttm_phys,itau,date,dt,fid_phys)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_phys),lat_ini(jml_phys))
+  lon_ini(:)=lon_phys(:,1); IF(MAXVAL(lon_phys)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_phys(1,:); IF(MAXVAL(lat_phys)>pi) lat_ini=lat_ini*deg2rad
+
+  ALLOCATE(var_ana(iml_phys,jml_phys),lon_rad(iml_phys),lat_rad(jml_phys))
+  CALL get_var_phys(tsrfvar,ts)                   !--- SURFACE TEMPERATURE
+  CALL get_var_phys(qsolvar,qs)                   !--- SOIL MOISTURE
+  CALL flinclo(fid_phys)
+  DEALLOCATE(var_ana,lon_rad,lat_rad,lon_ini,lat_ini)
+
+!--- TSOL AND QSOL ON PHYSICAL GRID
+  ALLOCATE(tsol(klon))
+  CALL gr_dyn_fi(1,iml,jml,klon,ts,tsol)
+  CALL gr_dyn_fi(1,iml,jml,klon,qs,qsol)
+  DEALLOCATE(ts,qs)
+
+CONTAINS
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE get_var_phys(title,field)
+!
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),  INTENT(IN)    :: title
+  REAL, ALLOCATABLE, INTENT(INOUT) :: field(:,:)
+!-------------------------------------------------------------------------------
+! Local variables:
+  INTEGER :: tllm
+!-------------------------------------------------------------------------------
+  SELECT CASE(title)
+    CASE(psrfvar);         tllm=0
+    CASE(tsrfvar,qsolvar); tllm=llm_phys
+  END SELECT
+  IF(ALLOCATED(field)) RETURN
+  ALLOCATE(field(iml,jml)); field(:,:)=0.
+  CALL flinget(fid_phys,title,iml_phys,jml_phys,tllm,ttm_phys,1,1,var_ana)
+  CALL conf_dat2d(title, lon_ini, lat_ini, lon_rad, lat_rad, var_ana, .TRUE.)
+  CALL interp_startvar(title, .TRUE., lon_rad, lat_rad, var_ana,               &
+                                      lon_in,  lat_in,  field)
+
+END SUBROUTINE get_var_phys
+!
+!-------------------------------------------------------------------------------
+!
+END SUBROUTINE start_init_phys
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE interp_startvar(nam,ibeg,lon,lat,vari,lon2,lat2,varo)
+!
+!-------------------------------------------------------------------------------
+  USE inter_barxy_m, ONLY: inter_barxy
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*), INTENT(IN)  :: nam
+  LOGICAL,          INTENT(IN)  :: ibeg
+  REAL,             INTENT(IN)  :: lon(:), lat(:)   ! dim (ii) (jj)
+  REAL,             INTENT(IN)  :: vari(:,:)        ! dim (ii,jj)
+  REAL,             INTENT(IN)  :: lon2(:), lat2(:) ! dim (i1) (j2)
+  REAL,             INTENT(OUT) :: varo(:,:)        ! dim (i1) (j1)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname
+  INTEGER            :: ii, jj, i1, j1, j2
+  REAL, ALLOCATABLE  :: vtmp(:,:)
+!-------------------------------------------------------------------------------
+  modname="interp_startvar"
+  ii=assert_eq(SIZE(lon), SIZE(vari,1),TRIM(modname)//" ii")
+  jj=assert_eq(SIZE(lat), SIZE(vari,2),TRIM(modname)//" jj")
+  i1=assert_eq(SIZE(lon2),SIZE(varo,1),TRIM(modname)//" i1")
+  j1=SIZE(varo,2); j2=SIZE(lat2)
+  ALLOCATE(vtmp(i1-1,j1))
+  IF(ibeg.AND.prt_level>1) THEN
+    WRITE(lunout,*)"--------------------------------------------------------"
+    WRITE(lunout,*)"$$$ Interpolation barycentrique pour "//TRIM(nam)//" $$$"
+    WRITE(lunout,*)"--------------------------------------------------------"
+  END IF
+  CALL inter_barxy(lon, lat(:jj-1), vari, lon2(:i1-1), lat2, vtmp)
+  CALL gr_int_dyn(vtmp, varo, i1-1, j1)
+
+END SUBROUTINE interp_startvar
+!
+!-------------------------------------------------------------------------------
+
+
+END MODULE etat0phys
+!
+!*******************************************************************************
+
Index: DZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/iniphysiq.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/iniphysiq.F90	(revision 2407)
+++ 	(revision )
@@ -1,204 +1,0 @@
-
-! $Id$
-
-
-SUBROUTINE iniphysiq(iim,jjm,nlayer,punjours, pdayref,ptimestep,         &
-                     rlatu,rlonv,aire,cu,cv,                             &
-                     prad,pg,pr,pcpp,iflag_phys)
-  USE dimphy, ONLY: klev ! number of atmospheric levels
-  USE mod_grid_phy_lmdz, ONLY: klon_glo ! number of atmospheric columns
-                                        ! (on full grid)
-  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
-                                klon_omp_begin, & ! start index of local omp subgrid
-                                klon_omp_end, & ! end index of local omp subgrid
-                                klon_mpi_begin ! start indes of columns (on local mpi grid)
-  USE comgeomphy, ONLY: initcomgeomphy, &
-                        airephy, & ! physics grid area (m2)
-                        cuphy, & ! cu coeff. (u_covariant = cu * u)
-                        cvphy, & ! cv coeff. (v_covariant = cv * v)
-                        rlond, & ! longitudes
-                        rlatd ! latitudes
-  USE phyaqua_mod, ONLY: iniaqua
-  IMPLICIT NONE
-
-  ! =======================================================================
-  ! Initialisation of the physical constants and some positional and
-  ! geometrical arrays for the physics
-  ! =======================================================================
-
-  include "YOMCST.h"
-  include "iniprint.h"
-
-  REAL, INTENT (IN) :: prad ! radius of the planet (m)
-  REAL, INTENT (IN) :: pg ! gravitational acceleration (m/s2)
-  REAL, INTENT (IN) :: pr ! ! reduced gas constant R/mu
-  REAL, INTENT (IN) :: pcpp ! specific heat Cp
-  REAL, INTENT (IN) :: punjours ! length (in s) of a standard day
-  INTEGER, INTENT (IN) :: nlayer ! number of atmospheric layers
-  INTEGER, INTENT (IN) :: iim ! number of atmospheric columns along longitudes
-  INTEGER, INTENT (IN) :: jjm ! number of atompsheric columns along latitudes
-  REAL, INTENT (IN) :: rlatu(jjm+1) ! latitudes of the physics grid
-  REAL, INTENT (IN) :: rlonv(iim+1) ! longitudes of the physics grid
-  REAL, INTENT (IN) :: aire(iim+1,jjm+1) ! area of the dynamics grid (m2)
-  REAL, INTENT (IN) :: cu((iim+1)*(jjm+1)) ! cu coeff. (u_covariant = cu * u)
-  REAL, INTENT (IN) :: cv((iim+1)*jjm) ! cv coeff. (v_covariant = cv * v)
-  INTEGER, INTENT (IN) :: pdayref ! reference day of for the simulation
-  REAL, INTENT (IN) :: ptimestep !physics time step (s)
-  INTEGER, INTENT (IN) :: iflag_phys ! type of physics to be called
-
-  INTEGER :: ibegin, iend, offset
-  INTEGER :: i,j
-  CHARACTER (LEN=20) :: modname = 'iniphysiq'
-  CHARACTER (LEN=80) :: abort_message
-  REAL :: total_area_phy, total_area_dyn
-
-
-  ! global array, on full physics grid:
-  REAL,ALLOCATABLE :: latfi(:)
-  REAL,ALLOCATABLE :: lonfi(:)
-  REAL,ALLOCATABLE :: cufi(:)
-  REAL,ALLOCATABLE :: cvfi(:)
-  REAL,ALLOCATABLE :: airefi(:)
-
-  IF (nlayer/=klev) THEN
-    WRITE (lunout, *) 'STOP in ', trim(modname)
-    WRITE (lunout, *) 'Problem with dimensions :'
-    WRITE (lunout, *) 'nlayer     = ', nlayer
-    WRITE (lunout, *) 'klev   = ', klev
-    abort_message = ''
-    CALL abort_gcm(modname, abort_message, 1)
-  END IF
-
-  !call init_phys_lmdz(iim,jjm+1,llm,1,(/(jjm-1)*iim+2/))
-  
-  ! Generate global arrays on full physics grid
-  ALLOCATE(latfi(klon_glo),lonfi(klon_glo),cufi(klon_glo),cvfi(klon_glo))
-  ALLOCATE(airefi(klon_glo))
-
-  IF (klon_glo>1) THEN ! general case
-    ! North pole
-    latfi(1)=rlatu(1)
-    lonfi(1)=0.
-    cufi(1) = cu(1)
-    cvfi(1) = cv(1)
-    DO j=2,jjm
-      DO i=1,iim
-        latfi((j-2)*iim+1+i)= rlatu(j)
-        lonfi((j-2)*iim+1+i)= rlonv(i)
-        cufi((j-2)*iim+1+i) = cu((j-1)*(iim+1)+i)
-        cvfi((j-2)*iim+1+i) = cv((j-1)*(iim+1)+i)
-      ENDDO
-    ENDDO
-    ! South pole
-    latfi(klon_glo)= rlatu(jjm+1)
-    lonfi(klon_glo)= 0.
-    cufi(klon_glo) = cu((iim+1)*jjm+1)
-    cvfi(klon_glo) = cv((iim+1)*jjm-iim)
-
-    ! build airefi(), mesh area on physics grid
-    CALL gr_dyn_fi(1,iim+1,jjm+1,klon_glo,aire,airefi)
-    ! Poles are single points on physics grid
-    airefi(1)=sum(aire(1:iim,1))
-    airefi(klon_glo)=sum(aire(1:iim,jjm+1))
-
-    ! Sanity check: do total planet area match between physics and dynamics?
-    total_area_dyn=sum(aire(1:iim,1:jjm+1))
-    total_area_phy=sum(airefi(1:klon_glo))
-    IF (total_area_dyn/=total_area_phy) THEN
-      WRITE (lunout, *) 'iniphysiq: planet total surface discrepancy !!!'
-      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
-      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
-      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
-        ! stop here if the relative difference is more than 0.001%
-        abort_message = 'planet total surface discrepancy'
-        CALL abort_gcm(modname, abort_message, 1)
-      ENDIF
-    ENDIF
-  ELSE ! klon_glo==1, running the 1D model
-    ! just copy over input values
-    latfi(1)=rlatu(1)
-    lonfi(1)=rlonv(1)
-    cufi(1)=cu(1)
-    cvfi(1)=cv(1)
-    airefi(1)=aire(1,1)
-  ENDIF ! of IF (klon_glo>1)
-
-!$OMP PARALLEL 
-  ! Now generate local lon/lat/cu/cv/area arrays
-  CALL initcomgeomphy
-
-  offset = klon_mpi_begin - 1
-  airephy(1:klon_omp) = airefi(offset+klon_omp_begin:offset+klon_omp_end)
-  cuphy(1:klon_omp) = cufi(offset+klon_omp_begin:offset+klon_omp_end)
-  cvphy(1:klon_omp) = cvfi(offset+klon_omp_begin:offset+klon_omp_end)
-  rlond(1:klon_omp) = lonfi(offset+klon_omp_begin:offset+klon_omp_end)
-  rlatd(1:klon_omp) = latfi(offset+klon_omp_begin:offset+klon_omp_end)
-
-    ! suphel => initialize some physical constants (orbital parameters,
-    !           geoid, gravity, thermodynamical constants, etc.) in the
-    !           physics
-  CALL suphel
-
-!$OMP END PARALLEL
-
-  ! check that physical constants set in 'suphel' are coherent
-  ! with values set in the dynamics:
-  IF (rday/=punjours) THEN
-    WRITE (lunout, *) 'iniphysiq: length of day discrepancy!!!'
-    WRITE (lunout, *) '  in the dynamics punjours=', punjours
-    WRITE (lunout, *) '   but in the physics RDAY=', rday
-    IF (abs(rday-punjours)>0.01*punjours) THEN
-        ! stop here if the relative difference is more than 1%
-      abort_message = 'length of day discrepancy'
-      CALL abort_gcm(modname, abort_message, 1)
-    END IF
-  END IF
-  IF (rg/=pg) THEN
-    WRITE (lunout, *) 'iniphysiq: gravity discrepancy !!!'
-    WRITE (lunout, *) '     in the dynamics pg=', pg
-    WRITE (lunout, *) '  but in the physics RG=', rg
-    IF (abs(rg-pg)>0.01*pg) THEN
-        ! stop here if the relative difference is more than 1%
-      abort_message = 'gravity discrepancy'
-      CALL abort_gcm(modname, abort_message, 1)
-    END IF
-  END IF
-  IF (ra/=prad) THEN
-    WRITE (lunout, *) 'iniphysiq: planet radius discrepancy !!!'
-    WRITE (lunout, *) '   in the dynamics prad=', prad
-    WRITE (lunout, *) '  but in the physics RA=', ra
-    IF (abs(ra-prad)>0.01*prad) THEN
-        ! stop here if the relative difference is more than 1%
-      abort_message = 'planet radius discrepancy'
-      CALL abort_gcm(modname, abort_message, 1)
-    END IF
-  END IF
-  IF (rd/=pr) THEN
-    WRITE (lunout, *) 'iniphysiq: reduced gas constant discrepancy !!!'
-    WRITE (lunout, *) '     in the dynamics pr=', pr
-    WRITE (lunout, *) '  but in the physics RD=', rd
-    IF (abs(rd-pr)>0.01*pr) THEN
-        ! stop here if the relative difference is more than 1%
-      abort_message = 'reduced gas constant discrepancy'
-      CALL abort_gcm(modname, abort_message, 1)
-    END IF
-  END IF
-  IF (rcpd/=pcpp) THEN
-    WRITE (lunout, *) 'iniphysiq: specific heat discrepancy !!!'
-    WRITE (lunout, *) '     in the dynamics pcpp=', pcpp
-    WRITE (lunout, *) '  but in the physics RCPD=', rcpd
-    IF (abs(rcpd-pcpp)>0.01*pcpp) THEN
-        ! stop here if the relative difference is more than 1%
-      abort_message = 'specific heat discrepancy'
-      CALL abort_gcm(modname, abort_message, 1)
-    END IF
-  END IF
-
-  ! Additional initializations for aquaplanets
-!$OMP PARALLEL
-  IF (iflag_phys>=100) THEN
-    CALL iniaqua(klon_omp, rlatd, rlond, iflag_phys)
-  END IF
-!$OMP END PARALLEL
-
-END SUBROUTINE iniphysiq
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/iniphysiq_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/iniphysiq_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/iniphysiq_mod.F90	(revision 2408)
@@ -0,0 +1,324 @@
+!
+! $Id$
+!
+MODULE iniphysiq_mod
+
+CONTAINS
+
+SUBROUTINE iniphysiq(ii,jj,nlayer, &
+                     nbp, communicator, &
+                     punjours, pdayref,ptimestep, &
+                     rlatu,rlatv,rlonu,rlonv,aire,cu,cv,       &
+                     prad,pg,pr,pcpp,iflag_phys)
+  USE dimphy, ONLY: init_dimphy
+  USE mod_grid_phy_lmdz, ONLY: klon_glo,  & ! number of atmospheric columns (on full grid)
+                               regular_lonlat, &  ! regular longitude-latitude grid type
+                               nbp_lon, nbp_lat, nbp_lev
+  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
+                                klon_omp_begin, & ! start index of local omp subgrid
+                                klon_omp_end, & ! end index of local omp subgrid
+                                klon_mpi_begin ! start indes of columns (on local mpi grid)
+  USE geometry_mod, ONLY : init_geometry
+  USE vertical_layers_mod, ONLY : init_vertical_layers
+  USE infotrac, ONLY: nqtot,nqo,nbtr,tname,ttext,type_trac,&
+                      niadv,conv_flg,pbl_flg,solsym,&
+                      nqfils,nqdesc,nqdesc_tot,iqfils,iqpere,&
+                      ok_isotopes,ok_iso_verif,ok_isotrac,&
+                      ok_init_iso,niso_possibles,tnat,&
+                      alpha_ideal,use_iso,iqiso,iso_num,&
+                      iso_indnum,zone_num,phase_num,&
+                      indnum_fn_num,index_trac,&
+                      niso,ntraceurs_zone,ntraciso
+#ifdef REPROBUS
+  USE CHEM_REP, ONLY : Init_chem_rep_phys
+#endif
+  USE control_mod, ONLY: dayref,anneeref,day_step,nday,offline, iphysiq
+  USE inifis_mod, ONLY: inifis
+  USE time_phylmdz_mod, ONLY: init_time
+  USE infotrac_phy, ONLY: init_infotrac_phy
+  USE phystokenc_mod, ONLY: init_phystokenc
+  USE phyaqua_mod, ONLY: iniaqua
+  USE physics_distribution_mod, ONLY : init_physics_distribution
+  USE regular_lonlat_mod, ONLY : init_regular_lonlat, &
+                                 east, west, north, south, &
+                                 north_east, north_west, &
+                                 south_west, south_east
+  USE mod_interface_dyn_phys, ONLY :  init_interface_dyn_phys
+#ifdef INCA
+  USE indice_sol_mod, ONLY: nbsrf, is_oce, is_sic, is_ter, is_lic
+  USE parallel_lmdz, ONLY : mpi_size
+  USE mod_const_mpi, ONLY : COMM_LMDZ
+  USE bands, ONLY : distrib_phys
+  USE mod_phys_lmdz_omp_data, ONLY: klon_omp 
+#endif
+  IMPLICIT NONE
+
+  ! =======================================================================
+  ! Initialisation of the physical constants and some positional and
+  ! geometrical arrays for the physics
+  ! =======================================================================
+
+  include "dimensions.h"
+  include "comvert.h"
+  include "comconst.h"
+  include "iniprint.h"
+  include "temps.h"
+  include "tracstoke.h"
+
+  REAL, INTENT (IN) :: prad ! radius of the planet (m)
+  REAL, INTENT (IN) :: pg ! gravitational acceleration (m/s2)
+  REAL, INTENT (IN) :: pr ! ! reduced gas constant R/mu
+  REAL, INTENT (IN) :: pcpp ! specific heat Cp
+  REAL, INTENT (IN) :: punjours ! length (in s) of a standard day
+  INTEGER, INTENT (IN) :: nlayer ! number of atmospheric layers
+  INTEGER, INTENT (IN) :: ii ! number of atmospheric columns along longitudes
+  INTEGER, INTENT (IN) :: jj ! number of atompsheric columns along latitudes
+  INTEGER, INTENT(IN) :: nbp ! number of physics columns for this MPI process
+  INTEGER, INTENT(IN) :: communicator ! MPI communicator
+  REAL, INTENT (IN) :: rlatu(jj+1) ! latitudes of the physics grid
+  REAL, INTENT (IN) :: rlatv(jj) ! latitude boundaries of the physics grid
+  REAL, INTENT (IN) :: rlonv(ii+1) ! longitudes of the physics grid
+  REAL, INTENT (IN) :: rlonu(ii+1) ! longitude boundaries of the physics grid
+  REAL, INTENT (IN) :: aire(ii+1,jj+1) ! area of the dynamics grid (m2)
+  REAL, INTENT (IN) :: cu((ii+1)*(jj+1)) ! cu coeff. (u_covariant = cu * u)
+  REAL, INTENT (IN) :: cv((ii+1)*jj) ! cv coeff. (v_covariant = cv * v)
+  INTEGER, INTENT (IN) :: pdayref ! reference day of for the simulation
+  REAL, INTENT (IN) :: ptimestep !physics time step (s)
+  INTEGER, INTENT (IN) :: iflag_phys ! type of physics to be called
+
+  INTEGER :: ibegin, iend, offset
+  INTEGER :: i,j,k
+  CHARACTER (LEN=20) :: modname = 'iniphysiq'
+  CHARACTER (LEN=80) :: abort_message
+  REAL :: total_area_phy, total_area_dyn
+
+  ! boundaries, on global grid
+  REAL,ALLOCATABLE :: boundslon_reg(:,:)
+  REAL,ALLOCATABLE :: boundslat_reg(:,:)
+
+  ! global array, on full physics grid:
+  REAL,ALLOCATABLE :: latfi_glo(:)
+  REAL,ALLOCATABLE :: lonfi_glo(:)
+  REAL,ALLOCATABLE :: cufi_glo(:)
+  REAL,ALLOCATABLE :: cvfi_glo(:)
+  REAL,ALLOCATABLE :: airefi_glo(:)
+  REAL,ALLOCATABLE :: boundslonfi_glo(:,:)
+  REAL,ALLOCATABLE :: boundslatfi_glo(:,:)
+
+  ! local arrays, on given MPI/OpenMP domain:
+  REAL,ALLOCATABLE,SAVE :: latfi(:)
+  REAL,ALLOCATABLE,SAVE :: lonfi(:)
+  REAL,ALLOCATABLE,SAVE :: cufi(:)
+  REAL,ALLOCATABLE,SAVE :: cvfi(:)
+  REAL,ALLOCATABLE,SAVE :: airefi(:)
+  REAL,ALLOCATABLE,SAVE :: boundslonfi(:,:)
+  REAL,ALLOCATABLE,SAVE :: boundslatfi(:,:)
+!$OMP THREADPRIVATE (latfi,lonfi,cufi,cvfi,airefi,boundslonfi,boundslatfi)
+
+  ! Initialize Physics distibution and parameters and interface with dynamics
+  IF (ii*jj>1) THEN ! general 3D case
+    CALL init_physics_distribution(regular_lonlat,4, &
+                                 nbp,ii,jj+1,nlayer,communicator)
+  ELSE ! For 1D model
+    CALL init_physics_distribution(regular_lonlat,4, &
+                                 1,1,1,nlayer,communicator)  
+  ENDIF
+  CALL init_interface_dyn_phys
+  
+  ! init regular global longitude-latitude grid points and boundaries
+  ALLOCATE(boundslon_reg(ii,2))
+  ALLOCATE(boundslat_reg(jj+1,2))
+  
+  DO i=1,ii
+   boundslon_reg(i,east)=rlonu(i) 
+   boundslon_reg(i,west)=rlonu(i+1) 
+  ENDDO
+
+  boundslat_reg(1,north)= PI/2 
+  boundslat_reg(1,south)= rlatv(1)
+  DO j=2,jj
+   boundslat_reg(j,north)=rlatv(j-1) 
+   boundslat_reg(j,south)=rlatv(j) 
+  ENDDO
+  boundslat_reg(jj+1,north)= rlatv(jj) 
+  boundslat_reg(jj+1,south)= -PI/2
+
+  ! Write values in module regular_lonlat_mod
+  CALL init_regular_lonlat(ii,jj+1, rlonv(1:ii), rlatu, &
+                           boundslon_reg, boundslat_reg)
+
+  ! Generate global arrays on full physics grid
+  ALLOCATE(latfi_glo(klon_glo),lonfi_glo(klon_glo))
+  ALLOCATE(cufi_glo(klon_glo),cvfi_glo(klon_glo))
+  ALLOCATE(airefi_glo(klon_glo))
+  ALLOCATE(boundslonfi_glo(klon_glo,4))
+  ALLOCATE(boundslatfi_glo(klon_glo,4))
+  
+
+  IF (klon_glo>1) THEN ! general case
+    ! North pole
+    latfi_glo(1)=rlatu(1)
+    lonfi_glo(1)=0.
+    cufi_glo(1) = cu(1)
+    cvfi_glo(1) = cv(1)
+    boundslonfi_glo(1,north_east)=0
+    boundslatfi_glo(1,north_east)=PI/2
+    boundslonfi_glo(1,north_west)=2*PI
+    boundslatfi_glo(1,north_west)=PI/2
+    boundslonfi_glo(1,south_west)=2*PI
+    boundslatfi_glo(1,south_west)=rlatv(1)
+    boundslonfi_glo(1,south_east)=0
+    boundslatfi_glo(1,south_east)=rlatv(1)
+    DO j=2,jj
+      DO i=1,ii
+        k=(j-2)*ii+1+i
+        latfi_glo(k)= rlatu(j)
+        lonfi_glo(k)= rlonv(i)
+        cufi_glo(k) = cu((j-1)*(ii+1)+i)
+        cvfi_glo(k) = cv((j-1)*(ii+1)+i)
+        boundslonfi_glo(k,north_east)=rlonu(i)
+        boundslatfi_glo(k,north_east)=rlatv(j-1)
+        boundslonfi_glo(k,north_west)=rlonu(i+1)
+        boundslatfi_glo(k,north_west)=rlatv(j-1)
+        boundslonfi_glo(k,south_west)=rlonu(i+1)
+        boundslatfi_glo(k,south_west)=rlatv(j)
+        boundslonfi_glo(k,south_east)=rlonu(i)
+        boundslatfi_glo(k,south_east)=rlatv(j)
+      ENDDO
+    ENDDO
+    ! South pole
+    latfi_glo(klon_glo)= rlatu(jj+1)
+    lonfi_glo(klon_glo)= 0.
+    cufi_glo(klon_glo) = cu((ii+1)*jj+1)
+    cvfi_glo(klon_glo) = cv((ii+1)*jj-ii)
+    boundslonfi_glo(klon_glo,north_east)= 0
+    boundslatfi_glo(klon_glo,north_east)= rlatv(jj)
+    boundslonfi_glo(klon_glo,north_west)= 2*PI
+    boundslatfi_glo(klon_glo,north_west)= rlatv(jj)
+    boundslonfi_glo(klon_glo,south_west)= 2*PI
+    boundslatfi_glo(klon_glo,south_west)= -PI/2
+    boundslonfi_glo(klon_glo,south_east)= 0
+    boundslatfi_glo(klon_glo,south_east)= -Pi/2
+
+    ! build airefi_glo(), mesh area on physics grid
+    CALL gr_dyn_fi(1,ii+1,jj+1,klon_glo,aire,airefi_glo)
+    ! Poles are single points on physics grid
+    airefi_glo(1)=sum(aire(1:ii,1))
+    airefi_glo(klon_glo)=sum(aire(1:ii,jj+1))
+
+    ! Sanity check: do total planet area match between physics and dynamics?
+    total_area_dyn=sum(aire(1:ii,1:jj+1))
+    total_area_phy=sum(airefi_glo(1:klon_glo))
+    IF (total_area_dyn/=total_area_phy) THEN
+      WRITE (lunout, *) 'iniphysiq: planet total surface discrepancy !!!'
+      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
+      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
+      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
+        ! stop here if the relative difference is more than 0.001%
+        abort_message = 'planet total surface discrepancy'
+        CALL abort_gcm(modname, abort_message, 1)
+      ENDIF
+    ENDIF
+  ELSE ! klon_glo==1, running the 1D model
+    ! just copy over input values
+    latfi_glo(1)=rlatu(1)
+    lonfi_glo(1)=rlonv(1)
+    cufi_glo(1)=cu(1)
+    cvfi_glo(1)=cv(1)
+    airefi_glo(1)=aire(1,1)
+    boundslonfi_glo(1,north_east)=rlonu(1)
+    boundslatfi_glo(1,north_east)=PI/2
+    boundslonfi_glo(1,north_west)=rlonu(2)
+    boundslatfi_glo(1,north_west)=PI/2
+    boundslonfi_glo(1,south_west)=rlonu(2)
+    boundslatfi_glo(1,south_west)=rlatv(1)
+    boundslonfi_glo(1,south_east)=rlonu(1)
+    boundslatfi_glo(1,south_east)=rlatv(1)
+  ENDIF ! of IF (klon_glo>1)
+
+!$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/)
+  ! Now generate local lon/lat/cu/cv/area/bounds arrays
+  ALLOCATE(latfi(klon_omp),lonfi(klon_omp),cufi(klon_omp),cvfi(klon_omp))
+  ALLOCATE(airefi(klon_omp))
+  ALLOCATE(boundslonfi(klon_omp,4))
+  ALLOCATE(boundslatfi(klon_omp,4))
+
+
+  offset = klon_mpi_begin - 1
+  airefi(1:klon_omp) = airefi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  cufi(1:klon_omp) = cufi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  cvfi(1:klon_omp) = cvfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  lonfi(1:klon_omp) = lonfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  latfi(1:klon_omp) = latfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  boundslonfi(1:klon_omp,:) = boundslonfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
+  boundslatfi(1:klon_omp,:) = boundslatfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
+
+  ! copy over local grid longitudes and latitudes
+  CALL init_geometry(klon_omp,lonfi,latfi,boundslonfi,boundslatfi, &
+                     airefi,cufi,cvfi)
+
+  ! copy over preff , ap(), bp(), etc 
+  CALL init_vertical_layers(nlayer,preff,scaleheight, &
+                            ap,bp,presnivs,pseudoalt)
+
+  ! Initialize physical constants in physics:
+  CALL inifis(punjours,prad,pg,pr,pcpp)
+
+  CALL init_time(annee_ref,day_ref,day_ini,start_time,nday,ptimestep)
+
+  ! Initialize dimphy module (unless in 1D where it has already been done)
+  IF (klon_glo>1) CALL Init_dimphy(klon_omp,nlayer)
+
+  ! Copy over "offline" settings
+  CALL init_phystokenc(offline,istphy)
+
+  ! Initialize tracer names, numbers, etc. for physics
+  CALL init_infotrac_phy(nqtot,nqo,nbtr,tname,ttext,type_trac,&
+                         niadv,conv_flg,pbl_flg,solsym,&
+                         nqfils,nqdesc,nqdesc_tot,iqfils,iqpere,&
+                         ok_isotopes,ok_iso_verif,ok_isotrac,&
+                         ok_init_iso,niso_possibles,tnat,&
+                         alpha_ideal,use_iso,iqiso,iso_num,&
+                         iso_indnum,zone_num,phase_num,&
+                         indnum_fn_num,index_trac,&
+                         niso,ntraceurs_zone,ntraciso)
+
+  ! Initializations for Reprobus
+  IF (type_trac == 'repr') THEN
+#ifdef REPROBUS
+    CALL Init_chem_rep_phys(klon_omp,nlayer)
+#endif
+  ENDIF
+!$OMP END PARALLEL
+
+  IF (type_trac == 'inca') THEN
+#ifdef INCA
+     call init_const_lmdz( &
+          anneeref,dayref, &
+          iphysiq,day_step,nday,  &
+          nbsrf, is_oce,is_sic, &
+          is_ter,is_lic, calend)
+     call init_inca_para( &
+          nbp_lon,nbp_lat,nbp_lev,klon_glo,mpi_size, &
+          distrib_phys,COMM_LMDZ)
+#endif
+  END IF
+!$OMP PARALLEL DEFAULT(SHARED) COPYIN(/temps/)
+
+  ! Additional initializations for aquaplanets 
+  IF (iflag_phys>=100) THEN
+    CALL iniaqua(klon_omp,iflag_phys)
+  END IF
+
+  IF (type_trac == 'inca') THEN
+#ifdef INCA
+     CALL init_inca_dim(klon_omp,nbp_lev,nbp_lon,nbp_lat - 1, &
+          rlonu,rlatu,rlonv,rlatv)
+#endif
+  END IF
+
+!$OMP END PARALLEL
+
+END SUBROUTINE iniphysiq
+
+END MODULE iniphysiq_mod
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/init_ssrf_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/init_ssrf_m.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/init_ssrf_m.F90	(revision 2408)
@@ -0,0 +1,111 @@
+MODULE init_ssrf_m
+!
+!*******************************************************************************
+
+  USE indice_sol_mod
+  USE dimphy,             ONLY: klon, zmasq
+  USE phys_state_var_mod, ONLY: pctsrf, rlon, rlat
+  USE grid_atob_m,        ONLY: grille_m
+  USE ioipsl,             ONLY: flininfo, flinopen, flinget, flinclo
+
+  CHARACTER(LEN=256), PARAMETER :: icefname="landiceref.nc", icevar="landice"
+  PRIVATE
+  PUBLIC :: start_init_subsurf
+  include "iniprint.h"
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom2.h"
+  include "comconst.h"
+
+CONTAINS
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_init_subsurf(known_mask)
+!
+!-------------------------------------------------------------------------------
+! Purpose: Subsurfaces initialization.
+!-------------------------------------------------------------------------------
+! Comment: Called by etat0phys_netcdf ; also called by limit_netcdf in case
+!          no starting states are required (ok_etat0==.FALSE.).
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  LOGICAL, INTENT(IN) :: known_mask
+!-------------------------------------------------------------------------------
+! Local variables:
+  INTEGER           :: iml_lic, jml_lic
+  INTEGER           :: fid, llm_tmp, ttm_tmp, itaul(1), ji, j
+  REAL, ALLOCATABLE :: dlon_lic(:), lon_lic(:,:), fraclic (:,:)
+  REAL, ALLOCATABLE :: dlat_lic(:), lat_lic(:,:), flic_tmp(:,:), vtmp(:,:)
+  REAL              :: date, lev(1), dt, deg2rad
+!-------------------------------------------------------------------------------
+  deg2rad= pi/180.0
+
+!--- Physical grid points coordinates
+  DO j=2,jjm; rlat((j-2)*iim+2:(j-1)*iim+1)=rlatu(j);    END DO
+  DO j=2,jjm; rlon((j-2)*iim+2:(j-1)*iim+1)=rlonv(1:im); END DO
+  rlat(1) = pi/2.; rlat(klon) = - pi/2.; rlat(:)=rlat(:)/deg2rad
+  rlon(1) = 0.0;   rlon(klon) = 0.0;     rlon(:)=rlon(:)/deg2rad
+
+! Compute ground geopotential, sub-cells quantities and possibly the mask.
+! 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
+
+  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 
+
+!--- Sub-surface ocean and sea ice (sea ice set to zero for start).
+  pctsrf(:,is_oce)=(1.-zmasq(:))
+  WHERE(pctsrf(:,is_oce)<EPSFRA) pctsrf(:,is_oce)=0.
+  IF(known_mask) pctsrf(:,is_oce)=1-zmasq(:)
+
+!--- It is checked that the sub-surfaces sum is equal to 1.
+  ji=COUNT((ABS(SUM(pctsrf(:,:),dim=2))-1.0)>EPSFRA)
+  IF(ji/=0) WRITE(lunout,*) 'Sub-cell distribution problem for ',ji,' points'
+
+END SUBROUTINE start_init_subsurf
+!
+!-------------------------------------------------------------------------------
+
+END MODULE init_ssrf_m
+!
+!*******************************************************************************
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/limit_netcdf.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/limit_netcdf.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/limit_netcdf.F90	(revision 2408)
@@ -0,0 +1,863 @@
+MODULE limit
+!
+!*******************************************************************************
+! Author : L. Fairhead, 27/01/94
+!-------------------------------------------------------------------------------
+! Purpose: Boundary conditions files building for new model using climatologies.
+!          Both grids have to be regular.
+!-------------------------------------------------------------------------------
+! Note: This routine is designed to work for Earth
+!-------------------------------------------------------------------------------
+! Modification history:
+!  * 23/03/1994: Z. X. Li
+!  *    09/1999: L. Fairhead (netcdf reading in LMDZ.3.3)
+!  *    07/2001: P. Le Van
+!  *    11/2009: L. Guez     (ozone day & night climatos, see etat0_netcdf.F90)
+!  *    12/2009: D. Cugnet   (f77->f90, calendars, files from coupled runs)
+!-------------------------------------------------------------------------------
+
+  USE ioipsl,             ONLY: flininfo, flinopen, flinget, flinclo,          &
+   ioconf_calendar, ioget_calendar, lock_calendar, ioget_mon_len, ioget_year_len
+  USE assert_eq_m,        ONLY: assert_eq
+  USE conf_dat_m,         ONLY: conf_dat2d, conf_dat3d
+  USE dimphy,             ONLY: klon, zmasq
+  USE phys_state_var_mod, ONLY: pctsrf, rlon, rlat
+  USE control_mod
+  USE init_ssrf_m,        ONLY: start_init_subsurf
+
+  CHARACTER(LEN=20), PARAMETER :: &
+  fsst(4)=['amipbc_sst_1x1.nc   ','cpl_atm_sst.nc      ','histmth_sst.nc      '&
+          ,'sstk.nc             ']
+  CHARACTER(LEN=20), PARAMETER :: &
+  fsic(4)=['amipbc_sic_1x1.nc   ','cpl_atm_sic.nc      ','histmth_sic.nc      '&
+          ,'ci.nc               ']
+  CHARACTER(LEN=10), PARAMETER :: &
+  vsst(4)=['tosbcs    ','SISUTESW  ','tsol_oce  ','sstk      '], &
+  vsic(4)=['sicbcs    ','SIICECOV  ','pourc_sic ','ci        ']
+  CHARACTER(LEN=10), PARAMETER :: &
+  frugo='Rugos.nc  ', falbe='Albedo.nc ', frelf='Relief.nc ',    &
+   vrug='RUGOS     ',  valb='ALBEDO    ',  vrel='RELIEF    '
+
+CONTAINS
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE limit_netcdf(masque, phis, extrap)
+!
+!-------------------------------------------------------------------------------
+! Author : L. Fairhead, 27/01/94
+!-------------------------------------------------------------------------------
+! Purpose: Boundary conditions files building for new model using climatologies.
+!          Both grids have to be regular.
+!-------------------------------------------------------------------------------
+! Note: This routine is designed to work for Earth
+!-------------------------------------------------------------------------------
+! Modification history:
+!  * 23/03/1994: Z. X. Li
+!  *    09/1999: L. Fairhead (netcdf reading in LMDZ.3.3)
+!  *    07/2001: P. Le Van
+!  *    11/2009: L. Guez     (ozone day & night climatos, see etat0_netcdf.F90)
+!  *    12/2009: D. Cugnet   (f77->f90, calendars, files from coupled runs)
+!-------------------------------------------------------------------------------
+#ifndef CPP_1D
+  USE indice_sol_mod
+  USE netcdf,             ONLY: NF90_OPEN,    NF90_CREATE,  NF90_CLOSE,        &
+                  NF90_DEF_DIM, NF90_DEF_VAR, NF90_PUT_VAR, NF90_PUT_ATT,      &
+                  NF90_NOERR,   NF90_NOWRITE, NF90_DOUBLE,  NF90_GLOBAL,       &
+		  NF90_CLOBBER, NF90_ENDDEF,  NF90_UNLIMITED, NF90_FLOAT
+  USE inter_barxy_m,      ONLY: inter_barxy
+  USE netcdf95,           ONLY: nf95_def_var, nf95_put_att, nf95_put_var
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  include "iniprint.h"
+  include "dimensions.h"
+  include "paramet.h"
+  REAL, DIMENSION(iip1,jjp1), INTENT(INOUT) :: masque ! land mask
+  REAL, DIMENSION(iip1,jjp1), INTENT(INOUT) :: phis   ! ground geopotential
+  LOGICAL,                    INTENT(IN)    :: extrap ! SST extrapolation flag
+!-------------------------------------------------------------------------------
+! Local variables:
+  include "logic.h"
+  include "comgeom2.h"
+  include "comconst.h"
+
+!--- INPUT NETCDF FILES NAMES --------------------------------------------------
+  CHARACTER(LEN=20) :: icefile, sstfile, dumstr, fnam
+  CHARACTER(LEN=10) :: varname
+
+!--- OUTPUT VARIABLES FOR NETCDF FILE ------------------------------------------
+  REAL               :: fi_ice(klon), verif(klon)
+  REAL, POINTER      :: phy_rug(:,:)=>NULL(), phy_ice(:,:)=>NULL()
+  REAL, POINTER      :: phy_sst(:,:)=>NULL(), phy_alb(:,:)=>NULL()
+  REAL, ALLOCATABLE  :: phy_bil(:,:), pctsrf_t(:,:,:)
+  INTEGER            :: nbad
+
+!--- VARIABLES FOR OUTPUT FILE WRITING -----------------------------------------
+  INTEGER :: ierr, nid, ndim, ntim, k, dims(2), ix_sic, ix_sst
+  INTEGER :: id_tim,  id_SST,  id_BILS, id_RUG, id_ALB
+  INTEGER :: id_FOCE, id_FSIC, id_FTER, id_FLIC, varid_longitude, varid_latitude
+  INTEGER :: NF90_FORMAT
+  INTEGER :: ndays                   !--- Depending on the output calendar
+
+!--- INITIALIZATIONS -----------------------------------------------------------
+#ifdef NC_DOUBLE
+  NF90_FORMAT=NF90_DOUBLE
+#else
+  NF90_FORMAT=NF90_FLOAT
+#endif
+  CALL inigeom
+
+!--- MASK, GROUND GEOPOT. & SUBSURFACES COMPUTATION (IN CASE ok_etat0==.FALSE.)
+   IF(ALL(masque==-99999.)) THEN
+    CALL start_init_orog0(rlonv,rlatu,phis,masque)
+    CALL gr_dyn_fi(1,iip1,jjp1,klon,masque,zmasq)          !--- To physical grid
+    ALLOCATE(rlon(klon),rlat(klon),pctsrf(klon,nbsrf))
+    CALL start_init_subsurf(.FALSE.)
+  END IF
+
+!--- Beware: anneeref (from gcm.def) is used to determine output time sampling
+  ndays=ioget_year_len(anneeref)
+
+!--- RUGOSITY TREATMENT --------------------------------------------------------
+  CALL msg(1,'Traitement de la rugosite')
+  CALL get_2Dfield(frugo,vrug,'RUG',ndays,phy_rug,mask=masque(1:iim,:))
+
+!--- OCEAN TREATMENT -----------------------------------------------------------
+  CALL msg(1,'Traitement de la glace oceanique')
+
+! Input SIC file selection
+! Open file only to test if available
+  DO ix_sic=1,SIZE(fsic)
+     IF ( NF90_OPEN(TRIM(fsic(ix_sic)),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
+        icefile=fsic(ix_sic); varname=vsic(ix_sic); EXIT
+     END IF
+  END DO
+  IF(ix_sic==SIZE(fsic)+1) THEN
+     WRITE(lunout,*) 'ERROR! No sea-ice input file was found.'
+     WRITE(lunout,*) 'One of following files must be available : '
+     DO k=1,SIZE(fsic); WRITE(lunout,*) TRIM(fsic(k)); END DO
+     CALL abort_physic('limit_netcdf','No sea-ice file was found',1)
+  END IF
+  CALL ncerr(NF90_CLOSE(nid),icefile)
+  CALL msg(-1,'Fichier choisi pour la glace de mer:'//TRIM(icefile))
+
+  CALL get_2Dfield(icefile,varname, 'SIC',ndays,phy_ice)
+
+  ALLOCATE(pctsrf_t(klon,nbsrf,ndays))
+  DO k=1,ndays
+     fi_ice=phy_ice(:,k)
+     WHERE(fi_ice>=1.0  ) fi_ice=1.0
+     WHERE(fi_ice<EPSFRA) fi_ice=0.0
+     pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)       ! land soil
+     pctsrf_t(:,is_lic,k)=pctsrf(:,is_lic)       ! land ice
+     SELECT CASE(ix_sic)
+        CASE(2)                                   ! SIC=pICE*(1-LIC-TER) (CPL)
+        pctsrf_t(:,is_sic,k)=fi_ice(:)*(1.-pctsrf(:,is_lic)-pctsrf(:,is_ter))
+        CASE(3)                                   ! SIC=pICE            (HIST)
+        pctsrf_t(:,is_sic,k)=fi_ice(:)
+        CASE DEFAULT                              ! SIC=pICE-LIC   (AMIP,ERAI)
+        pctsrf_t(:,is_sic,k)=fi_ice-pctsrf_t(:,is_lic,k)
+     END SELECT
+     WHERE(pctsrf_t(:,is_sic,k)<=0) pctsrf_t(:,is_sic,k)=0.
+     WHERE(1.0-zmasq<EPSFRA)
+        pctsrf_t(:,is_sic,k)=0.0
+        pctsrf_t(:,is_oce,k)=0.0
+     ELSEWHERE
+        WHERE(pctsrf_t(:,is_sic,k)>=1.0-zmasq)
+           pctsrf_t(:,is_sic,k)=1.0-zmasq
+           pctsrf_t(:,is_oce,k)=0.0
+        ELSEWHERE
+           pctsrf_t(:,is_oce,k)=1.0-zmasq-pctsrf_t(:,is_sic,k)
+           WHERE(pctsrf_t(:,is_oce,k)<EPSFRA)
+              pctsrf_t(:,is_oce,k)=0.0
+              pctsrf_t(:,is_sic,k)=1.0-zmasq
+           END WHERE
+        END WHERE
+     END WHERE
+     nbad=COUNT(pctsrf_t(:,is_oce,k)<0.0)
+     IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb points = ',nbad
+     nbad=COUNT(ABS(SUM(pctsrf_t(:,:,k),DIM=2)-1.0)>EPSFRA)
+     IF(nbad>0) WRITE(lunout,*) 'pb sous surface pour nb points = ',nbad
+  END DO
+  DEALLOCATE(phy_ice)
+
+!--- SST TREATMENT -------------------------------------------------------------
+  CALL msg(1,'Traitement de la sst')
+
+! Input SST file selection
+! Open file only to test if available
+  DO ix_sst=1,SIZE(fsst)
+     IF ( NF90_OPEN(TRIM(fsst(ix_sst)),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
+       sstfile=fsst(ix_sst); varname=vsst(ix_sst); EXIT
+     END IF
+  END DO
+  IF(ix_sst==SIZE(fsst)+1) THEN
+     WRITE(lunout,*) 'ERROR! No sst input file was found.'
+     WRITE(lunout,*) 'One of following files must be available : '
+     DO k=1,SIZE(fsst); WRITE(lunout,*) TRIM(fsst(k)); END DO
+     CALL abort_physic('limit_netcdf','No sst file was found',1)
+  END IF
+  CALL ncerr(NF90_CLOSE(nid),sstfile)
+  CALL msg(-1,'Fichier choisi pour la temperature de mer: '//TRIM(sstfile))
+
+  CALL get_2Dfield(sstfile,varname,'SST',ndays,phy_sst,flag=extrap)
+
+!--- ALBEDO TREATMENT ----------------------------------------------------------
+  CALL msg(1,'Traitement de l albedo')
+  CALL get_2Dfield(falbe,valb,'ALB',ndays,phy_alb)
+
+!--- REFERENCE GROUND HEAT FLUX TREATMENT --------------------------------------
+  ALLOCATE(phy_bil(klon,ndays)); phy_bil=0.0
+
+!--- OUTPUT FILE WRITING -------------------------------------------------------
+  CALL msg(5,'Ecriture du fichier limit : debut')
+  fnam="limit.nc"
+
+  !--- File creation
+  CALL ncerr(NF90_CREATE(fnam,NF90_CLOBBER,nid),fnam)
+  CALL ncerr(NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier conditions aux limites"),fnam)
+
+  !--- Dimensions creation
+  CALL ncerr(NF90_DEF_DIM(nid,"points_physiques",klon,ndim),fnam)
+  CALL ncerr(NF90_DEF_DIM(nid,"time",NF90_UNLIMITED,ntim),fnam)
+
+  dims=[ndim,ntim]
+
+  !--- Variables creation
+  CALL ncerr(NF90_DEF_VAR(nid,"TEMPS",NF90_FORMAT,[ntim],id_tim),fnam)
+  CALL ncerr(NF90_DEF_VAR(nid,"FOCE", NF90_FORMAT,dims,id_FOCE),fnam)
+  CALL ncerr(NF90_DEF_VAR(nid,"FSIC", NF90_FORMAT,dims,id_FSIC),fnam)
+  CALL ncerr(NF90_DEF_VAR(nid,"FTER", NF90_FORMAT,dims,id_FTER),fnam)
+  CALL ncerr(NF90_DEF_VAR(nid,"FLIC", NF90_FORMAT,dims,id_FLIC),fnam)
+  CALL ncerr(NF90_DEF_VAR(nid,"SST",  NF90_FORMAT,dims,id_SST),fnam)
+  CALL ncerr(NF90_DEF_VAR(nid,"BILS", NF90_FORMAT,dims,id_BILS),fnam)
+  CALL ncerr(NF90_DEF_VAR(nid,"ALB",  NF90_FORMAT,dims,id_ALB),fnam)
+  CALL ncerr(NF90_DEF_VAR(nid,"RUG",  NF90_FORMAT,dims,id_RUG),fnam)
+  call nf95_def_var(nid, "longitude", NF90_FLOAT, ndim, varid_longitude)
+  call nf95_def_var(nid, "latitude",  NF90_FLOAT, ndim, varid_latitude)
+
+  !--- Attributes creation
+  CALL ncerr(NF90_PUT_ATT(nid,id_tim, "title","Jour dans l annee"),fnam)
+  CALL ncerr(NF90_PUT_ATT(nid,id_FOCE,"title","Fraction ocean"),fnam)
+  CALL ncerr(NF90_PUT_ATT(nid,id_FSIC,"title","Fraction glace de mer"),fnam)
+  CALL ncerr(NF90_PUT_ATT(nid,id_FTER,"title","Fraction terre"),fnam)
+  CALL ncerr(NF90_PUT_ATT(nid,id_FLIC,"title","Fraction land ice"),fnam)
+  CALL ncerr(NF90_PUT_ATT(nid,id_SST ,"title","Temperature superficielle de la mer"),fnam)
+  CALL ncerr(NF90_PUT_ATT(nid,id_BILS,"title","Reference flux de chaleur au sol"),fnam)
+  CALL ncerr(NF90_PUT_ATT(nid,id_ALB, "title","Albedo a la surface"),fnam)
+  CALL ncerr(NF90_PUT_ATT(nid,id_RUG, "title","Rugosite"),fnam)
+
+  call nf95_put_att(nid, varid_longitude, "standard_name", "longitude")
+  call nf95_put_att(nid, varid_longitude, "units", "degrees_east")
+
+  call nf95_put_att(nid, varid_latitude, "standard_name", "latitude")
+  call nf95_put_att(nid, varid_latitude, "units", "degrees_north")
+
+  CALL ncerr(NF90_ENDDEF(nid),fnam)
+
+  !--- Variables saving
+  CALL ncerr(NF90_PUT_VAR(nid,id_tim,[(REAL(k),k=1,ndays)]),fnam)
+  CALL ncerr(NF90_PUT_VAR(nid,id_FOCE,pctsrf_t(:,is_oce,:),[1,1],[klon,ndays]),fnam)
+  CALL ncerr(NF90_PUT_VAR(nid,id_FSIC,pctsrf_t(:,is_sic,:),[1,1],[klon,ndays]),fnam)
+  CALL ncerr(NF90_PUT_VAR(nid,id_FTER,pctsrf_t(:,is_ter,:),[1,1],[klon,ndays]),fnam)
+  CALL ncerr(NF90_PUT_VAR(nid,id_FLIC,pctsrf_t(:,is_lic,:),[1,1],[klon,ndays]),fnam)
+  CALL ncerr(NF90_PUT_VAR(nid,id_SST ,phy_sst(:,:),[1,1],[klon,ndays]),fnam)
+  CALL ncerr(NF90_PUT_VAR(nid,id_BILS,phy_bil(:,:),[1,1],[klon,ndays]),fnam)
+  CALL ncerr(NF90_PUT_VAR(nid,id_ALB ,phy_alb(:,:),[1,1],[klon,ndays]),fnam)
+  CALL ncerr(NF90_PUT_VAR(nid,id_RUG ,phy_rug(:,:),[1,1],[klon,ndays]),fnam)
+  call nf95_put_var(nid, varid_longitude, rlon)
+  call nf95_put_var(nid, varid_latitude, rlat)
+
+  CALL ncerr(NF90_CLOSE(nid),fnam)
+
+  CALL msg(6,'Ecriture du fichier limit : fin')
+
+  DEALLOCATE(pctsrf_t,phy_sst,phy_bil,phy_alb,phy_rug)
+
+
+!===============================================================================
+!
+  CONTAINS
+!
+!===============================================================================
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE get_2Dfield(fnam, varname, mode, ndays, champo, flag, mask)
+!
+!-----------------------------------------------------------------------------
+! Comments:
+!   There are two assumptions concerning the NetCDF files, that are satisfied
+!   with files that are conforming NC convention:
+!     1) The last dimension of the variables used is the time record.
+!     2) Dimensional variables have the same names as corresponding dimensions.
+!-----------------------------------------------------------------------------
+  USE netcdf, ONLY: NF90_OPEN, NF90_INQ_VARID, NF90_INQUIRE_VARIABLE, &
+       NF90_CLOSE, NF90_INQ_DIMID, NF90_INQUIRE_DIMENSION, NF90_GET_VAR, &
+       NF90_GET_ATT
+  USE pchsp_95_m, only: pchsp_95
+  USE pchfe_95_m, only: pchfe_95
+  USE arth_m, only: arth
+  USE indice_sol_mod
+
+  IMPLICIT NONE
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom2.h"
+!-----------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),  INTENT(IN)     :: fnam     ! NetCDF file name
+  CHARACTER(LEN=10), INTENT(IN)     :: varname  ! NetCDF variable name
+  CHARACTER(LEN=3),  INTENT(IN)     :: mode     ! RUG, SIC, SST or ALB
+  INTEGER,           INTENT(IN)     :: ndays    ! current year number of days
+  REAL,    POINTER,  DIMENSION(:, :) :: champo  ! output field = f(t)
+  LOGICAL, OPTIONAL, INTENT(IN)     :: flag     ! extrapol. (SST) old ice (SIC)
+  REAL,    OPTIONAL, DIMENSION(iim, jjp1), INTENT(IN) :: mask
+!------------------------------------------------------------------------------
+! Local variables:
+!--- NetCDF
+  INTEGER           :: ncid, varid        ! NetCDF identifiers
+  CHARACTER(LEN=30) :: dnam               ! dimension name
+!--- dimensions
+  INTEGER           :: dids(4)            ! NetCDF dimensions identifiers
+  REAL, ALLOCATABLE :: dlon_ini(:)        ! initial longitudes vector
+  REAL, ALLOCATABLE :: dlat_ini(:)        ! initial latitudes  vector
+  REAL, POINTER     :: dlon(:), dlat(:)   ! reordered lon/lat  vectors
+!--- fields
+  INTEGER :: imdep, jmdep, lmdep          ! dimensions of 'champ'
+  REAL, ALLOCATABLE :: champ(:,:)         ! wanted field on initial grid
+  REAL, ALLOCATABLE :: yder(:), timeyear(:)
+  REAL              :: champint(iim,jjp1) ! interpolated field
+  REAL, ALLOCATABLE :: champtime(:,:,:)
+  REAL, ALLOCATABLE :: champan(:,:,:)
+!--- input files
+  CHARACTER(LEN=20) :: cal_in             ! calendar
+  CHARACTER(LEN=20) :: unit_sic           ! attribute unit in sea-ice file
+  INTEGER           :: ndays_in           ! number of days
+!--- misc
+  INTEGER           :: i, j, k, l         ! loop counters
+  REAL, ALLOCATABLE :: work(:,:)          ! used for extrapolation
+  CHARACTER(LEN=25) :: title              ! for messages
+  LOGICAL           :: extrp              ! flag for extrapolation
+  REAL              :: chmin, chmax
+  INTEGER ierr
+  integer n_extrap ! number of extrapolated points
+  logical skip
+
+!------------------------------------------------------------------------------
+!---Variables depending on keyword 'mode' -------------------------------------
+  NULLIFY(champo)
+
+  SELECT CASE(mode)
+  CASE('RUG'); title='Rugosite'
+  CASE('SIC'); title='Sea-ice'
+  CASE('SST'); title='SST'
+  CASE('ALB'); title='Albedo'
+  END SELECT
+  extrp=.FALSE.; IF(PRESENT(flag).AND.mode=='SST') extrp=flag
+
+!--- GETTING SOME DIMENSIONAL VARIABLES FROM FILE -----------------------------
+  CALL msg(5,' Now reading file : '//TRIM(fnam))
+  CALL ncerr(NF90_OPEN(fnam, NF90_NOWRITE, ncid),fnam)
+  CALL ncerr(NF90_INQ_VARID(ncid, trim(varname), varid),fnam)
+  CALL ncerr(NF90_INQUIRE_VARIABLE(ncid, varid, dimids=dids),fnam)
+
+!--- Read unit for sea-ice variable only
+  IF (mode=='SIC') THEN
+    IF(NF90_GET_ATT(ncid, varid, 'units', unit_sic)/=NF90_NOERR) THEN
+      CALL msg(5,'No unit in sea-ice file. Take percentage as default value')
+      unit_sic='X'
+    ELSE
+      CALL msg(5,'Sea-ice cover has unit='//TRIM(unit_sic))
+    END IF
+  END IF
+
+!--- Longitude
+  CALL ncerr(NF90_INQUIRE_DIMENSION(ncid, dids(1), name=dnam, len=imdep),fnam)
+  ALLOCATE(dlon_ini(imdep), dlon(imdep))
+  CALL ncerr(NF90_INQ_VARID(ncid, dnam, varid), fnam)
+  CALL ncerr(NF90_GET_VAR(ncid, varid, dlon_ini), fnam)
+  CALL msg(5,'variable '//TRIM(dnam)//' dimension ', imdep)
+
+!--- Latitude
+  CALL ncerr(NF90_INQUIRE_DIMENSION(ncid, dids(2), name=dnam, len=jmdep),fnam)
+  ALLOCATE(dlat_ini(jmdep), dlat(jmdep))
+  CALL ncerr(NF90_INQ_VARID(ncid, dnam, varid), fnam)
+  CALL ncerr(NF90_GET_VAR(ncid, varid, dlat_ini), fnam)
+  CALL msg(5,'variable '//TRIM(dnam)//' dimension ', jmdep)
+
+!--- Time (variable is not needed - it is rebuilt - but calendar is)
+  CALL ncerr(NF90_INQUIRE_DIMENSION(ncid, dids(3), name=dnam, len=lmdep), fnam)
+  ALLOCATE(timeyear(lmdep))
+  CALL ncerr(NF90_INQ_VARID(ncid, dnam, varid), fnam)
+  cal_in=' '
+  IF(NF90_GET_ATT(ncid, varid, 'calendar', cal_in)/=NF90_NOERR) THEN
+    SELECT CASE(mode)
+      CASE('RUG', 'ALB'); cal_in='360d'
+      CASE('SIC', 'SST'); cal_in='gregorian'
+    END SELECT
+  CALL msg(5,'WARNING: missing "calendar" attribute for "time" in '&
+     &//TRIM(fnam)//'. Choosing default value.')
+  END IF
+  CALL msg(5,'var, calendar, dim: '//TRIM(dnam)//' '//TRIM(cal_in), lmdep)
+  
+!--- CONSTRUCTING THE INPUT TIME VECTOR FOR INTERPOLATION --------------------
+  !--- Determining input file number of days, depending on calendar
+  ndays_in=year_len(anneeref, cal_in)
+
+!--- Time vector reconstruction (time vector from file is not trusted)
+!--- If input records are not monthly, time sampling has to be constant !
+  timeyear=mid_months(anneeref, cal_in, lmdep)
+  IF (lmdep /= 12) WRITE(lunout,*) 'Note : les fichiers de ', TRIM(mode), &
+       ' ne comportent pas 12, mais ', lmdep, ' enregistrements.'
+
+!--- GETTING THE FIELD AND INTERPOLATING IT ----------------------------------
+  ALLOCATE(champ(imdep, jmdep), champtime(iim, jjp1, lmdep))
+  IF(extrp) ALLOCATE(work(imdep, jmdep))
+  CALL msg(5,'')
+  CALL msg(5,'LECTURE ET INTERPOLATION HORIZ. DE ', lmdep, ' CHAMPS.')
+  CALL ncerr(NF90_INQ_VARID(ncid, varname, varid), fnam)
+  DO l=1, lmdep
+    CALL ncerr(NF90_GET_VAR(ncid,varid,champ,[1,1,l],[imdep,jmdep,1]),fnam)
+    CALL conf_dat2d(title, dlon_ini, dlat_ini, dlon, dlat, champ, .TRUE.)
+    IF(extrp) CALL extrapol(champ,imdep,jmdep,999999.,.TRUE.,.TRUE.,2,work)
+    IF(l==1) THEN
+      CALL msg(5,"----------------------------------------------------------")
+      CALL msg(5,"$$$ Interpolation barycentrique pour "//TRIM(title)//" $$$")
+      CALL msg(5,"----------------------------------------------------------")
+    END IF
+    IF(mode=='RUG') champ=LOG(champ)
+    CALL inter_barxy(dlon,dlat(:jmdep-1),champ,rlonu(:iim),rlatv,champint)
+    IF(mode=='RUG') THEN
+      champint=EXP(champint)
+      WHERE(NINT(mask)/=1) champint=0.001
+    END IF
+    champtime(:, :, l)=champint
+  END DO
+  CALL ncerr(NF90_CLOSE(ncid), fnam)
+
+  DEALLOCATE(dlon_ini, dlat_ini, dlon, dlat, champ)
+  IF(extrp) DEALLOCATE(work)
+
+!--- TIME INTERPOLATION ------------------------------------------------------
+  IF(prt_level>5) THEN
+     WRITE(lunout, *)
+     WRITE(lunout, *)'INTERPOLATION TEMPORELLE.'
+     WRITE(lunout, *)' Vecteur temps en entree: ', timeyear
+     WRITE(lunout, *)' Vecteur temps en sortie de 0 a ', ndays
+  END IF
+
+  ALLOCATE(yder(lmdep), champan(iip1, jjp1, ndays))
+  skip = .false.
+  n_extrap = 0
+  DO j=1, jjp1
+    DO i=1, iim
+      yder = pchsp_95(timeyear, champtime(i, j, :), ibeg=2, iend=2, &
+           vc_beg=0., vc_end=0.)
+      CALL pchfe_95(timeyear, champtime(i, j, :), yder, skip, &
+           arth(0., real(ndays_in) / ndays, ndays), champan(i, j, :), ierr)
+      if (ierr < 0) stop 1
+      n_extrap = n_extrap + ierr
+    END DO
+  END DO
+  if (n_extrap /= 0) then
+     WRITE(lunout,*) "get_2Dfield pchfe_95: n_extrap = ", n_extrap
+  end if
+  champan(iip1, :, :)=champan(1, :, :)
+  DEALLOCATE(yder, champtime, timeyear)
+
+!--- Checking the result
+  DO j=1, jjp1
+    CALL minmax(iip1, champan(1, j, 10), chmin, chmax)
+    IF (prt_level>5) WRITE(lunout, *)' ',TRIM(title),' au temps 10 ', chmin, chmax, j
+  END DO
+
+!--- SPECIAL FILTER FOR SST: SST>271.38 --------------------------------------
+  IF(mode=='SST') THEN
+    CALL msg(5,'Filtrage de la SST: SST >= 271.38')
+    WHERE(champan<271.38) champan=271.38
+  END IF
+
+!--- SPECIAL FILTER FOR SIC: 0.0<SIC<1.0 -------------------------------------
+  IF(mode=='SIC') THEN
+    CALL msg(5,'Filtrage de la SIC: 0.0 < Sea-ice < 1.0')
+
+    IF (unit_sic=='1') THEN
+       ! Nothing to be done for sea-ice field is already in fraction of 1
+       ! This is the case for sea-ice in file cpl_atm_sic.nc
+       CALL msg(5,'Sea-ice field already in fraction of 1')
+    ELSE
+       ! Convert sea ice from percentage to fraction of 1
+       CALL msg(5,'Transformt sea-ice field from percentage to fraction of 1.')
+       champan(:, :, :)=champan(:, :, :)/100.
+    END IF
+
+    champan(iip1, :, :)=champan(1, :, :)
+    WHERE(champan>1.0) champan=1.0
+    WHERE(champan<0.0) champan=0.0
+ END IF
+
+!--- DYNAMICAL TO PHYSICAL GRID ----------------------------------------------
+  ALLOCATE(champo(klon, ndays))
+  DO k=1, ndays
+    CALL gr_dyn_fi(1, iip1, jjp1, klon, champan(1, 1, k), champo(1, k))
+  END DO
+  DEALLOCATE(champan)
+
+END SUBROUTINE get_2Dfield
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_init_orog0(lon_in,lat_in,phis,masque)
+!
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!===============================================================================
+! Purpose:  Compute "phis" just like it would be in start_init_orog.
+!===============================================================================
+! Arguments:
+  REAL,             INTENT(IN)    :: lon_in(:), lat_in(:)   ! dim (iml) (jml)
+  REAL,             INTENT(INOUT) :: phis(:,:), masque(:,:) ! dim (iml,jml)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname="start_init_orog0"
+  INTEGER            :: fid, llm_tmp,ttm_tmp, iml,jml, iml_rel,jml_rel, itau(1)
+  REAL               :: lev(1), date, dt, deg2rad
+  REAL, ALLOCATABLE  :: lon_rad(:), lon_ini(:), lon_rel(:,:), relief_hi(:,:)
+  REAL, ALLOCATABLE  :: lat_rad(:), lat_ini(:), lat_rel(:,:)
+!-------------------------------------------------------------------------------
+  iml=assert_eq(SIZE(lon_in),SIZE(phis,1),SIZE(masque,1),TRIM(modname)//" iml")
+  jml=assert_eq(SIZE(lat_in),SIZE(phis,2),SIZE(masque,2),TRIM(modname)//" jml")
+  IF(iml/=iip1) CALL abort_gcm(TRIM(modname),'iml/=iip1',1)
+  IF(jml/=jjp1) CALL abort_gcm(TRIM(modname),'jml/=jjp1',1)
+  pi=2.0*ASIN(1.0); deg2rad=pi/180.0
+  IF(ANY(phis/=-99999.)) RETURN                  !--- phis ALREADY KNOWN
+
+!--- HIGH RESOLUTION OROGRAPHY
+  CALL flininfo(frelf, iml_rel, jml_rel, llm_tmp, ttm_tmp, fid)
+
+  ALLOCATE(lat_rel(iml_rel,jml_rel),lon_rel(iml_rel,jml_rel))
+  CALL flinopen(frelf, .FALSE., iml_rel, jml_rel, llm_tmp, lon_rel, lat_rel,   &
+                lev, ttm_tmp, itau, date, dt, fid)
+  ALLOCATE(relief_hi(iml_rel,jml_rel))
+  CALL flinget(fid, vrel, iml_rel, jml_rel, llm_tmp, ttm_tmp, 1, 1, relief_hi)
+  CALL flinclo(fid)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_rel),lat_ini(jml_rel))
+  lon_ini(:)=lon_rel(:,1); IF(MAXVAL(lon_rel)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_rel(1,:); IF(MAXVAL(lat_rel)>pi) lat_ini=lat_ini*deg2rad
+
+!--- FIELDS ARE PROCESSED TO BE ON STANDARD ANGULAR DOMAINS
+  ALLOCATE(lon_rad(iml_rel),lat_rad(jml_rel))
+  CALL conf_dat2d(vrel, lon_ini, lat_ini, lon_rad, lat_rad, relief_hi, .FALSE.)
+  DEALLOCATE(lon_ini,lat_ini)
+
+!--- COMPUTING SURFACE GEOPOTENTIAL USING ROUTINE grid_noro0
+  WRITE(lunout,*)
+  WRITE(lunout,*)'*** Compute surface geopotential ***'
+
+!--- CALL OROGRAPHY MODULE (REDUCED VERSION) TO COMPUTE FIELDS
+  CALL grid_noro0(lon_rad, lat_rad, relief_hi, lon_in, lat_in, phis, masque)
+  phis = phis * 9.81
+  phis(iml,:) = phis(1,:)
+  DEALLOCATE(relief_hi,lon_rad,lat_rad)
+
+END SUBROUTINE start_init_orog0
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE grid_noro0(xd,yd,zd,x,y,zphi,mask)
+!
+!===============================================================================
+! Purpose: Extracted from grid_noro to provide geopotential height for dynamics
+!          without any call to physics subroutines.
+!===============================================================================
+  IMPLICIT NONE 
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL, INTENT(IN)   :: xd(:), yd(:) !--- INPUT  COORDINATES     (imdp) (jmdp)
+  REAL, INTENT(IN)   :: zd(:,:)      !--- INPUT  FIELD           (imdp,jmdp)
+  REAL, INTENT(IN)   :: x(:), y(:)   !--- OUTPUT COORDINATES     (imar+1) (jmar)
+  REAL, INTENT(OUT)  :: zphi(:,:)    !--- GEOPOTENTIAL           (imar+1,jmar)
+  REAL, INTENT(INOUT):: mask(:,:)    !--- MASK                   (imar+1,jmar)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname="grid_noro0"
+  REAL, ALLOCATABLE :: xusn(:), yusn(:)           ! dim (imdp+2*iext) (jmdp+2)
+  REAL, ALLOCATABLE :: zusn(:,:)                  ! dim (imdp+2*iext,jmdp+2)
+  REAL, ALLOCATABLE :: weight(:,:)                ! dim (imar+1,jmar)
+  REAL, ALLOCATABLE :: mask_tmp(:,:), zmea(:,:)   ! dim (imar+1,jmar)
+  REAL, ALLOCATABLE :: num_tot(:,:), num_lan(:,:) ! dim (imax,jmax)
+  REAL, ALLOCATABLE :: a(:), b(:)                 ! dim (imax)
+  REAL, ALLOCATABLE :: c(:), d(:)                 ! dim (jmax)
+  LOGICAL :: masque_lu
+  INTEGER :: i, ii, imdp, imar, iext
+  INTEGER :: j, jj, jmdp, jmar, nn
+  REAL    :: xpi, zlenx, weighx, xincr,  zbordnor, zmeanor, zweinor, zbordest
+  REAL    :: rad, zleny, weighy, masque, zbordsud, zmeasud, zweisud, zbordoue
+!-------------------------------------------------------------------------------
+  imdp=assert_eq(SIZE(xd),SIZE(zd,1),TRIM(modname)//" imdp")
+  jmdp=assert_eq(SIZE(yd),SIZE(zd,2),TRIM(modname)//" jmdp")
+  imar=assert_eq(SIZE(x),SIZE(zphi,1),SIZE(mask,1),TRIM(modname)//" imar")-1
+  jmar=assert_eq(SIZE(y),SIZE(zphi,2),SIZE(mask,2),TRIM(modname)//" jmar")
+  IF(imar/=iim)   CALL abort_gcm(TRIM(modname),'imar/=iim'  ,1)
+  IF(jmar/=jjm+1) CALL abort_gcm(TRIM(modname),'jmar/=jjm+1',1)
+  iext=imdp/10
+  xpi = ACOS(-1.)
+  rad = 6371229.
+
+!--- ARE WE USING A READ MASK ?
+  masque_lu=ANY(mask/=-99999.); IF(.NOT.masque_lu) mask=0.0
+  WRITE(lunout,*)'Masque lu: ',masque_lu
+
+!--- EXTENSION OF THE INPUT DATABASE TO PROCEED COMPUTATIONS AT BOUNDARIES:
+  ALLOCATE(xusn(imdp+2*iext))
+  xusn(1     +iext:imdp  +iext)=xd(:)
+  xusn(1          :       iext)=xd(1+imdp-iext:imdp)-2.*xpi
+  xusn(1+imdp+iext:imdp+2*iext)=xd(1          :iext)+2.*xpi
+
+  ALLOCATE(yusn(jmdp+2))
+  yusn(1       )=yd(1)   +(yd(1)   -yd(2))
+  yusn(2:jmdp+1)=yd(:)
+  yusn(  jmdp+2)=yd(jmdp)+(yd(jmdp)-yd(jmdp-1))
+
+  ALLOCATE(zusn(imdp+2*iext,jmdp+2))
+  zusn(1       +iext:imdp  +iext,2:jmdp+1)=zd  (:                   ,     :)
+  zusn(1            :       iext,2:jmdp+1)=zd  (imdp-iext+1:imdp    ,     :)
+  zusn(1+imdp  +iext:imdp+2*iext,2:jmdp+1)=zd  (1:iext              ,     :)
+  zusn(1            :imdp/2+iext,       1)=zusn(1+imdp/2:imdp  +iext,     2)
+  zusn(1+imdp/2+iext:imdp+2*iext,       1)=zusn(1       :imdp/2+iext,     2)
+  zusn(1            :imdp/2+iext,  jmdp+2)=zusn(1+imdp/2:imdp  +iext,jmdp+1)
+  zusn(1+imdp/2+iext:imdp+2*iext,  jmdp+2)=zusn(1       :imdp/2+iext,jmdp+1)
+
+!--- COMPUTE LIMITS OF MODEL GRIDPOINT AREA (REGULAR GRID)
+  ALLOCATE(a(imar+1),b(imar+1))
+  b(1:imar)=(x(1:imar  )+ x(2:imar+1))/2.0
+  b(imar+1)= x(  imar+1)+(x(  imar+1)-x(imar))/2.0
+  a(1)=x(1)-(x(2)-x(1))/2.0
+  a(2:imar+1)= b(1:imar)
+
+  ALLOCATE(c(jmar),d(jmar))
+  d(1:jmar-1)=(y(1:jmar-1)+ y(2:jmar))/2.0
+  d(  jmar  )= y(  jmar  )+(y(  jmar)-y(jmar-1))/2.0
+  c(1)=y(1)-(y(2)-y(1))/2.0
+  c(2:jmar)=d(1:jmar-1)
+
+!--- INITIALIZATIONS:
+  ALLOCATE(weight(imar+1,jmar)); weight(:,:)= 0.0
+  ALLOCATE(zmea  (imar+1,jmar)); zmea  (:,:)= 0.0
+
+!--- SUMMATION OVER GRIDPOINT AREA
+  zleny=xpi/REAL(jmdp)*rad
+  xincr=xpi/REAL(jmdp)/2.
+  ALLOCATE(num_tot(imar+1,jmar)); num_tot(:,:)=0.
+  ALLOCATE(num_lan(imar+1,jmar)); num_lan(:,:)=0.
+  DO ii = 1, imar+1
+    DO jj = 1, jmar
+      DO j = 2,jmdp+1 
+        zlenx  =zleny  *COS(yusn(j))
+        zbordnor=(xincr+c(jj)-yusn(j))*rad
+        zbordsud=(xincr-d(jj)+yusn(j))*rad
+        weighy=AMAX1(0.,AMIN1(zbordnor,zbordsud,zleny))
+        IF(weighy/=0) THEN
+          DO i = 2, imdp+2*iext-1
+            zbordest=(xusn(i)-a(ii)+xincr)*rad*COS(yusn(j))
+            zbordoue=(b(ii)+xincr-xusn(i))*rad*COS(yusn(j))
+            weighx=AMAX1(0.,AMIN1(zbordest,zbordoue,zlenx))
+            IF(weighx/=0)THEN
+              num_tot(ii,jj)=num_tot(ii,jj)+1.0
+              IF(zusn(i,j)>=1.)num_lan(ii,jj)=num_lan(ii,jj)+1.0
+              weight(ii,jj)=weight(ii,jj)+weighx*weighy
+              zmea  (ii,jj)=zmea  (ii,jj)+zusn(i,j)*weighx*weighy !--- MEAN
+            END IF
+          END DO
+        END IF
+      END DO
+    END DO
+  END DO
+
+!--- COMPUTE PARAMETERS NEEDED BY LOTT & MILLER (1997) AND LOTT (1999) SSO SCHEME
+  IF(.NOT.masque_lu) THEN
+    WHERE(weight(:,1:jmar-1)/=0.0) mask=num_lan(:,:)/num_tot(:,:)
+  END IF
+  nn=COUNT(weight(:,1:jmar-1)==0.0)
+  IF(nn/=0) WRITE(lunout,*)'Problem with weight ; vanishing occurrences: ',nn
+  WHERE(weight/=0.0) zmea(:,:)=zmea(:,:)/weight(:,:)
+
+!--- MASK BASED ON GROUND MAXIMUM, 10% THRESHOLD (<10%: SURF PARAMS MEANINGLESS)
+  ALLOCATE(mask_tmp(imar+1,jmar)); mask_tmp(:,:)=0.0
+  WHERE(mask>=0.1) mask_tmp = 1.
+  WHERE(weight(:,:)/=0.0)
+    zphi(:,:)=mask_tmp(:,:)*zmea(:,:)
+    zmea(:,:)=mask_tmp(:,:)*zmea(:,:)
+  END WHERE
+  WRITE(lunout,*)'  MEAN ORO:' ,MAXVAL(zmea)
+
+!--- Values at poles
+  zphi(imar+1,:)=zphi(1,:)
+
+  zweinor=SUM(weight(1:imar,   1),DIM=1)
+  zweisud=SUM(weight(1:imar,jmar),DIM=1)
+  zmeanor=SUM(weight(1:imar,   1)*zmea(1:imar,   1),DIM=1)
+  zmeasud=SUM(weight(1:imar,jmar)*zmea(1:imar,jmar),DIM=1)
+  zphi(:,1)=zmeanor/zweinor; zphi(:,jmar)=zmeasud/zweisud
+
+END SUBROUTINE grid_noro0
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+FUNCTION year_len(y,cal_in)
+!
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER                       :: year_len
+  INTEGER,           INTENT(IN) :: y
+  CHARACTER(LEN=*),  INTENT(IN) :: cal_in
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=20)             :: cal_out              ! calendar (for outputs)
+!-------------------------------------------------------------------------------
+!--- Getting the input calendar to reset at the end of the function
+  CALL ioget_calendar(cal_out)
+
+!--- Unlocking calendar and setting it to wanted one
+  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
+
+!--- Getting the number of days in this year
+  year_len=ioget_year_len(y)
+
+!--- Back to original calendar
+  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
+
+END FUNCTION year_len
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+FUNCTION mid_months(y,cal_in,nm)
+!
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,                INTENT(IN) :: y               ! year
+  CHARACTER(LEN=*),       INTENT(IN) :: cal_in          ! calendar
+  INTEGER,                INTENT(IN) :: nm              ! months/year number
+  REAL,    DIMENSION(nm)             :: mid_months      ! mid-month times
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=99)                  :: mess            ! error message
+  CHARACTER(LEN=20)                  :: cal_out         ! calendar (for outputs)
+  INTEGER, DIMENSION(nm)             :: mnth            ! months lengths (days)
+  INTEGER                            :: m               ! months counter
+  INTEGER                            :: nd              ! number of days
+!-------------------------------------------------------------------------------
+  nd=year_len(y,cal_in)
+
+  IF(nm==12) THEN
+
+  !--- Getting the input calendar to reset at the end of the function
+    CALL ioget_calendar(cal_out)
+
+  !--- Unlocking calendar and setting it to wanted one
+    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
+
+  !--- Getting the length of each month
+    DO m=1,nm; mnth(m)=ioget_mon_len(y,m); END DO
+
+  !--- Back to original calendar
+    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
+
+  ELSE IF(MODULO(nd,nm)/=0) THEN
+    WRITE(mess,'(a,i3,a,i3,a)')'Unconsistent calendar: ',nd,' days/year, but ',&
+      nm,' months/year. Months number should divide days number.'
+    CALL abort_physic('mid_months',TRIM(mess),1)
+
+  ELSE
+    mnth=[(m,m=1,nm,nd/nm)]
+  END IF
+
+!--- Mid-months times
+  mid_months(1)=0.5*REAL(mnth(1))
+  DO k=2,nm
+    mid_months(k)=mid_months(k-1)+0.5*REAL(mnth(k-1)+mnth(k))
+  END DO
+
+END FUNCTION mid_months
+!
+!-------------------------------------------------------------------------------
+
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE msg(lev,str1,i,str2)
+!
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,                    INTENT(IN) :: lev
+  CHARACTER(LEN=*),           INTENT(IN) :: str1
+  INTEGER,          OPTIONAL, INTENT(IN) :: i
+  CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: str2
+!-------------------------------------------------------------------------------
+  IF(prt_level>lev) THEN
+    IF(PRESENT(str2)) THEN
+      WRITE(lunout,*) TRIM(str1), i, TRIM(str2)
+    ELSE IF(PRESENT(i)) THEN
+      WRITE(lunout,*) TRIM(str1), i
+    ELSE
+      WRITE(lunout,*) TRIM(str1)
+    END IF
+  END IF
+
+END SUBROUTINE msg
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE ncerr(ncres,fnam)
+!
+!-------------------------------------------------------------------------------
+! Purpose: NetCDF errors handling.
+!-------------------------------------------------------------------------------
+  USE netcdf, ONLY : NF90_NOERR, NF90_STRERROR
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,          INTENT(IN) :: ncres
+  CHARACTER(LEN=*), INTENT(IN) :: fnam
+!-------------------------------------------------------------------------------
+  IF(ncres/=NF90_NOERR) THEN
+    WRITE(lunout,*)'Problem with file '//TRIM(fnam)//' in routine limit_netcdf.'
+    CALL abort_physic('limit_netcdf',NF90_STRERROR(ncres),1)
+  END IF
+
+END SUBROUTINE ncerr
+!
+!-------------------------------------------------------------------------------
+
+#endif
+! of #ifndef CPP_1D
+END SUBROUTINE limit_netcdf
+
+END MODULE limit
+!
+!*******************************************************************************
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/test_disvert_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/test_disvert_m.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phylmd/test_disvert_m.F90	(revision 2408)
@@ -0,0 +1,68 @@
+module test_disvert_m
+
+  implicit none
+
+contains
+
+  subroutine test_disvert
+
+    ! Author: Lionel GUEZ
+
+    ! This procedure tests the order of pressure values at half-levels
+    ! and full levels. We arbitrarily choose to test ngrid values of
+    ! the surface pressure, which sample possible values on Earth.
+
+    use exner_hyb_m, only: exner_hyb
+    use vertical_layers_mod, only: ap,bp,preff
+
+    ! For llm:
+    include "dimensions.h"
+
+    ! For kappa, cpp:
+    include "comconst.h"
+
+    ! Local:
+    integer l, i
+    integer, parameter:: ngrid = 7
+    real p(ngrid, llm + 1) ! pressure at half-level, in Pa
+    real pks(ngrid) ! exner function at the surface, in J K-1 kg-1 
+    real pk(ngrid, llm) ! exner function at full level, in J K-1 kg-1 
+    real ps(ngrid) ! surface pressure, in Pa
+    real p_lay(ngrid, llm) ! pressure at full level, in Pa
+    real delta_ps ! in Pa
+
+    !---------------------
+
+    print *, "Call sequence information: test_disvert"
+
+    delta_ps = 6e4 / (ngrid - 1)
+    ps = (/(5e4 + delta_ps * i, i = 0, ngrid - 1)/)
+    forall (l = 1: llm + 1) p(:, l) = ap(l) + bp(l) * ps
+    call exner_hyb(ngrid, ps, p, pks, pk)
+    p_lay = preff * (pk / cpp)**(1. / kappa)
+
+    ! Are pressure values in the right order?
+    if (any(p(:, :llm) <= p_lay .or. p_lay <= p(:, 2:))) then
+       ! List details and stop:
+       do l = 1, llm
+          do i = 1, ngrid
+             if (p(i, l) <= p_lay(i, l)) then
+                print 1000, "ps = ", ps(i) / 100., "hPa, p(level ",  l, &
+                     ") = ", p(i, l) / 100., " hPa <= p(layer ", l, ") = ", &
+                     p_lay(i, l) / 100., " hPa"
+             end if
+             if (p_lay(i, l) <= p(i, l + 1)) then
+                print 1000, "ps = ", ps(i) / 100., "hPa, p(layer ", l, ") = ", &
+                     p_lay(i, l) / 100., " hPa <= p(level ", l + 1, ") = ", &
+                     p(i, l + 1) / 100., " hPa"
+             end if
+          end do
+       end do
+       call abort_physic("test_disvert", "bad order of pressure values", 1)
+    end if
+
+1000 format (3(a, g10.4, a, i0))
+
+  end subroutine test_disvert
+
+end module test_disvert_m
Index: DZ5/branches/testing/libf/dynlonlat_phylonlat/phymar/iniphysiq.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phymar/iniphysiq.F90	(revision 2407)
+++ 	(revision )
@@ -1,157 +1,0 @@
-!
-! $Id: iniphysiq.F 1403 2010-07-01 09:02:53Z fairhead $
-!
-SUBROUTINE iniphysiq(iim,jjm,nlayer,punjours, pdayref,ptimestep,         &
-                     rlatu,rlonv,aire,cu,cv,                             &
-                     prad,pg,pr,pcpp,iflag_phys)
-  USE dimphy, ONLY: klev ! number of atmospheric levels
-  USE mod_grid_phy_lmdz, ONLY: klon_glo ! number of atmospheric columns
-                                        ! (on full grid)
-  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
-                                klon_omp_begin, & ! start index of local omp subgrid
-                                klon_omp_end, & ! end index of local omp subgrid
-                                klon_mpi_begin ! start indes of columns (on local mpi grid)
-  USE comgeomphy, ONLY: initcomgeomphy, &
-                        airephy, & ! physics grid area (m2)
-                        cuphy, & ! cu coeff. (u_covariant = cu * u)
-                        cvphy, & ! cv coeff. (v_covariant = cv * v)
-                        rlond, & ! longitudes
-                        rlatd ! latitudes
-  USE comcstphy, ONLY: rradius, & ! planet radius (m)
-                       rr, & ! recuced gas constant: R/molar mass of atm
-                       rg, & ! gravity
-                       rcpp  ! specific heat of the atmosphere
-!  USE phyaqua_mod, ONLY: iniaqua
-  IMPLICIT NONE
-  !
-  !=======================================================================
-  !   Initialisation of the physical constants and some positional and 
-  !   geometrical arrays for the physics
-  !=======================================================================
- 
- 
-  include "iniprint.h"
-
-  REAL,INTENT(IN) :: prad ! radius of the planet (m)
-  REAL,INTENT(IN) :: pg ! gravitational acceleration (m/s2)
-  REAL,INTENT(IN) :: pr ! ! reduced gas constant R/mu
-  REAL,INTENT(IN) :: pcpp ! specific heat Cp
-  REAL,INTENT(IN) :: punjours ! length (in s) of a standard day
-  INTEGER, INTENT (IN) :: nlayer ! number of atmospheric layers
-  INTEGER, INTENT (IN) :: iim ! number of atmospheric coulumns along longitudes
-  INTEGER, INTENT (IN) :: jjm  ! number of atompsheric columns along latitudes
-  REAL, INTENT (IN) :: rlatu(jjm+1) ! latitudes of the physics grid
-  REAL, INTENT (IN) :: rlonv(iim+1) ! longitudes of the physics grid
-  REAL, INTENT (IN) :: aire(iim+1,jjm+1) ! area of the dynamics grid (m2)
-  REAL, INTENT (IN) :: cu((iim+1)*(jjm+1)) ! cu coeff. (u_covariant = cu * u)
-  REAL, INTENT (IN) :: cv((iim+1)*jjm) ! cv coeff. (v_covariant = cv * v)
-  INTEGER, INTENT (IN) :: pdayref ! reference day of for the simulation
-  REAL,INTENT(IN) :: ptimestep !physics time step (s)
-  INTEGER,INTENT(IN) :: iflag_phys ! type of physics to be called
-
-  INTEGER :: ibegin,iend,offset
-  INTEGER :: i,j
-  CHARACTER (LEN=20) :: modname='iniphysiq'
-  CHARACTER (LEN=80) :: abort_message
-  REAL :: total_area_phy, total_area_dyn
-
-
-  ! global array, on full physics grid:
-  REAL,ALLOCATABLE :: latfi(:)
-  REAL,ALLOCATABLE :: lonfi(:)
-  REAL,ALLOCATABLE :: cufi(:)
-  REAL,ALLOCATABLE :: cvfi(:)
-  REAL,ALLOCATABLE :: airefi(:)
- 
-  IF (nlayer.NE.klev) THEN
-    WRITE(lunout,*) 'STOP in ',trim(modname)
-    WRITE(lunout,*) 'Problem with dimensions :'
-    WRITE(lunout,*) 'nlayer     = ',nlayer
-    WRITE(lunout,*) 'klev   = ',klev
-    abort_message = ''
-    CALL abort_gcm (modname,abort_message,1)
-  ENDIF
-
-
-  ! Generate global arrays on full physics grid
-  ALLOCATE(latfi(klon_glo),lonfi(klon_glo),cufi(klon_glo),cvfi(klon_glo))
-  ALLOCATE(airefi(klon_glo))
-
-  IF (klon_glo>1) THEN ! general case
-    ! North pole
-    latfi(1)=rlatu(1)
-    lonfi(1)=0.
-    cufi(1) = cu(1)
-    cvfi(1) = cv(1)
-    DO j=2,jjm
-      DO i=1,iim
-        latfi((j-2)*iim+1+i)= rlatu(j)
-        lonfi((j-2)*iim+1+i)= rlonv(i)
-        cufi((j-2)*iim+1+i) = cu((j-1)*iim+1+i)
-        cvfi((j-2)*iim+1+i) = cv((j-1)*iim+1+i)
-      ENDDO
-    ENDDO
-    ! South pole
-    latfi(klon_glo)= rlatu(jjm+1)
-    lonfi(klon_glo)= 0.
-    cufi(klon_glo) = cu((iim+1)*jjm+1)
-    cvfi(klon_glo) = cv((iim+1)*jjm-iim)
-
-    ! build airefi(), mesh area on physics grid
-    CALL gr_dyn_fi(1,iim+1,jjm+1,klon_glo,aire,airefi)
-    ! Poles are single points on physics grid
-    airefi(1)=sum(aire(1:iim,1))
-    airefi(klon_glo)=sum(aire(1:iim,jjm+1))
-
-    ! Sanity check: do total planet area match between physics and dynamics?
-    total_area_dyn=sum(aire(1:iim,1:jjm+1))
-    total_area_phy=sum(airefi(1:klon_glo))
-    IF (total_area_dyn/=total_area_phy) THEN
-      WRITE (lunout, *) 'iniphysiq: planet total surface discrepancy !!!'
-      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
-      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
-      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
-        ! stop here if the relative difference is more than 0.001%
-        abort_message = 'planet total surface discrepancy'
-        CALL abort_gcm(modname, abort_message, 1)
-      ENDIF
-    ENDIF
-  ELSE ! klon_glo==1, running the 1D model
-    ! just copy over input values
-    latfi(1)=rlatu(1)
-    lonfi(1)=rlonv(1)
-    cufi(1)=cu(1)
-    cvfi(1)=cv(1)
-    airefi(1)=aire(1,1)
-  ENDIF ! of IF (klon_glo>1)
-
-!$OMP PARALLEL
-  ! Now generate local lon/lat/cu/cv/area arrays
-  CALL initcomgeomphy
-      
-  offset = klon_mpi_begin - 1
-  airephy(1:klon_omp) = airefi(offset+klon_omp_begin:offset+klon_omp_end)
-  cuphy(1:klon_omp) = cufi(offset+klon_omp_begin:offset+klon_omp_end)
-  cvphy(1:klon_omp) = cvfi(offset+klon_omp_begin:offset+klon_omp_end)
-  rlond(1:klon_omp) = lonfi(offset+klon_omp_begin:offset+klon_omp_end)
-  rlatd(1:klon_omp) = latfi(offset+klon_omp_begin:offset+klon_omp_end)
-
-! copy some fundamental parameters to physics
-  rradius=prad
-  rg=pg
-  rr=pr
-  rcpp=pcpp
-
-!$OMP END PARALLEL
-
-!      print*,'ATTENTION !!! TRAVAILLER SUR INIPHYSIQ'
-!      print*,'CONTROLE DES LATITUDES, LONGITUDES, PARAMETRES ...'
-
-! Additional initializations for aquaplanets 
-!!$OMP PARALLEL
-!      if (iflag_phys>=100) then
-!        call iniaqua(klon_omp,rlatd,rlond,iflag_phys)
-!      endif
-!!$OMP END PARALLEL
-
-      END
Index: /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phymar/iniphysiq_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phymar/iniphysiq_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/dynlonlat_phylonlat/phymar/iniphysiq_mod.F90	(revision 2408)
@@ -0,0 +1,255 @@
+!
+! $Id: iniphysiq.F 1403 2010-07-01 09:02:53Z fairhead $
+!
+MODULE iniphysiq_mod
+
+CONTAINS
+
+SUBROUTINE iniphysiq(ii,jj,nlayer, &
+                     nbp, communicator, &
+                     punjours, pdayref,ptimestep, &
+                     rlatu,rlatv,rlonu,rlonv,aire,cu,cv,         &
+                     prad,pg,pr,pcpp,iflag_phys)
+  USE dimphy, ONLY: init_dimphy
+  USE mod_grid_phy_lmdz, ONLY: klon_glo,  & ! number of atmospheric columns (on full grid)
+                               regular_lonlat  ! regular longitude-latitude grid type
+  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
+                                klon_omp_begin, & ! start index of local omp subgrid
+                                klon_omp_end, & ! end index of local omp subgrid
+                                klon_mpi_begin ! start indes of columns (on local mpi grid)
+  USE geometry_mod, ONLY : init_geometry
+  USE infotrac, ONLY: nqtot
+  USE comcstphy, ONLY: rradius, & ! planet radius (m)
+                       rr, & ! recuced gas constant: R/molar mass of atm
+                       rg, & ! gravity
+                       rcpp  ! specific heat of the atmosphere
+!  USE phyaqua_mod, ONLY: iniaqua
+  USE physics_distribution_mod, ONLY : init_physics_distribution
+  USE regular_lonlat_mod, ONLY : init_regular_lonlat, &
+                                 east, west, north, south, &
+                                 north_east, north_west, &
+                                 south_west, south_east
+  USE mod_interface_dyn_phys, ONLY :  init_interface_dyn_phys
+  USE infotrac_phy, ONLY: init_infotrac_phy
+  USE nrtype, ONLY: pi
+  IMPLICIT NONE
+  !
+  !=======================================================================
+  !   Initialisation of the physical constants and some positional and 
+  !   geometrical arrays for the physics
+  !=======================================================================
+ 
+ 
+  include "iniprint.h"
+
+  REAL,INTENT(IN) :: prad ! radius of the planet (m)
+  REAL,INTENT(IN) :: pg ! gravitational acceleration (m/s2)
+  REAL,INTENT(IN) :: pr ! ! reduced gas constant R/mu
+  REAL,INTENT(IN) :: pcpp ! specific heat Cp
+  REAL,INTENT(IN) :: punjours ! length (in s) of a standard day
+  INTEGER, INTENT (IN) :: nlayer ! number of atmospheric layers
+  INTEGER, INTENT (IN) :: ii ! number of atmospheric coulumns along longitudes
+  INTEGER, INTENT (IN) :: jj  ! number of atompsheric columns along latitudes
+  INTEGER, INTENT(IN) :: nbp ! number of physics columns for this MPI process
+  INTEGER, INTENT(IN) :: communicator ! MPI communicator
+  REAL, INTENT (IN) :: rlatu(jj+1) ! latitudes of the physics grid
+  REAL, INTENT (IN) :: rlatv(jj) ! latitude boundaries of the physics grid
+  REAL, INTENT (IN) :: rlonv(ii+1) ! longitudes of the physics grid
+  REAL, INTENT (IN) :: rlonu(ii+1) ! longitude boundaries of the physics grid
+  REAL, INTENT (IN) :: aire(ii+1,jj+1) ! area of the dynamics grid (m2)
+  REAL, INTENT (IN) :: cu((ii+1)*(jj+1)) ! cu coeff. (u_covariant = cu * u)
+  REAL, INTENT (IN) :: cv((ii+1)*jj) ! cv coeff. (v_covariant = cv * v)
+  INTEGER, INTENT (IN) :: pdayref ! reference day of for the simulation
+  REAL,INTENT(IN) :: ptimestep !physics time step (s)
+  INTEGER,INTENT(IN) :: iflag_phys ! type of physics to be called
+
+  INTEGER :: ibegin,iend,offset
+  INTEGER :: i,j,k
+  CHARACTER (LEN=20) :: modname='iniphysiq'
+  CHARACTER (LEN=80) :: abort_message
+  REAL :: total_area_phy, total_area_dyn
+
+  ! boundaries, on global grid
+  REAL,ALLOCATABLE :: boundslon_reg(:,:)
+  REAL,ALLOCATABLE :: boundslat_reg(:,:)
+
+  ! global array, on full physics grid:
+  REAL,ALLOCATABLE :: latfi_glo(:)
+  REAL,ALLOCATABLE :: lonfi_glo(:)
+  REAL,ALLOCATABLE :: cufi_glo(:)
+  REAL,ALLOCATABLE :: cvfi_glo(:)
+  REAL,ALLOCATABLE :: airefi_glo(:)
+  REAL,ALLOCATABLE :: boundslonfi_glo(:,:)
+  REAL,ALLOCATABLE :: boundslatfi_glo(:,:)
+
+  ! local arrays, on given MPI/OpenMP domain:
+  REAL,ALLOCATABLE,SAVE :: latfi(:)
+  REAL,ALLOCATABLE,SAVE :: lonfi(:)
+  REAL,ALLOCATABLE,SAVE :: cufi(:)
+  REAL,ALLOCATABLE,SAVE :: cvfi(:)
+  REAL,ALLOCATABLE,SAVE :: airefi(:)
+  REAL,ALLOCATABLE,SAVE :: boundslonfi(:,:)
+  REAL,ALLOCATABLE,SAVE :: boundslatfi(:,:)
+!$OMP THREADPRIVATE (latfi,lonfi,cufi,cvfi,airefi,boundslonfi,boundslatfi)
+
+  ! Initialize Physics distibution and parameters and interface with dynamics
+  CALL init_physics_distribution(regular_lonlat,4, &
+                                 nbp,ii,jj+1,nlayer,communicator)
+  CALL init_interface_dyn_phys
+  
+  ! init regular global longitude-latitude grid points and boundaries
+  ALLOCATE(boundslon_reg(ii,2))
+  ALLOCATE(boundslat_reg(jj+1,2))
+  
+  DO i=1,ii
+   boundslon_reg(i,east)=rlonu(i) 
+   boundslon_reg(i,west)=rlonu(i+1) 
+  ENDDO
+
+  boundslat_reg(1,north)= PI/2 
+  boundslat_reg(1,south)= rlatv(1)
+  DO j=2,jj
+   boundslat_reg(j,north)=rlatv(j-1) 
+   boundslat_reg(j,south)=rlatv(j) 
+  ENDDO
+  boundslat_reg(jj+1,north)= rlatv(jj) 
+  boundslat_reg(jj+1,south)= -PI/2
+
+  ! Write values in module regular_lonlat_mod
+  CALL init_regular_lonlat(ii,jj+1, rlonv(1:ii), rlatu, &
+                           boundslon_reg, boundslat_reg)
+
+  ! Generate global arrays on full physics grid
+  ALLOCATE(latfi_glo(klon_glo),lonfi_glo(klon_glo))
+  ALLOCATE(cufi_glo(klon_glo),cvfi_glo(klon_glo))
+  ALLOCATE(airefi_glo(klon_glo))
+  ALLOCATE(boundslonfi_glo(klon_glo,4))
+  ALLOCATE(boundslatfi_glo(klon_glo,4))
+
+  IF (klon_glo>1) THEN ! general case
+    ! North pole
+    latfi_glo(1)=rlatu(1)
+    lonfi_glo(1)=0.
+    cufi_glo(1) = cu(1)
+    cvfi_glo(1) = cv(1)
+    boundslonfi_glo(1,north_east)=0
+    boundslatfi_glo(1,north_east)=PI/2
+    boundslonfi_glo(1,north_west)=2*PI
+    boundslatfi_glo(1,north_west)=PI/2
+    boundslonfi_glo(1,south_west)=2*PI
+    boundslatfi_glo(1,south_west)=rlatv(1)
+    boundslonfi_glo(1,south_east)=0
+    boundslatfi_glo(1,south_east)=rlatv(1)
+    DO j=2,jj
+      DO i=1,ii
+        k=(j-2)*ii+1+i
+        latfi_glo((j-2)*ii+1+i)= rlatu(j)
+        lonfi_glo((j-2)*ii+1+i)= rlonv(i)
+        cufi_glo((j-2)*ii+1+i) = cu((j-1)*(ii+1)+i)
+        cvfi_glo((j-2)*ii+1+i) = cv((j-1)*(ii+1)+i)
+        boundslonfi_glo(k,north_east)=rlonu(i)
+        boundslatfi_glo(k,north_east)=rlatv(j-1)
+        boundslonfi_glo(k,north_west)=rlonu(i+1)
+        boundslatfi_glo(k,north_west)=rlatv(j-1)
+        boundslonfi_glo(k,south_west)=rlonu(i+1)
+        boundslatfi_glo(k,south_west)=rlatv(j)
+        boundslonfi_glo(k,south_east)=rlonu(i)
+        boundslatfi_glo(k,south_east)=rlatv(j)
+      ENDDO
+    ENDDO
+    ! South pole
+    latfi_glo(klon_glo)= rlatu(jj+1)
+    lonfi_glo(klon_glo)= 0.
+    cufi_glo(klon_glo) = cu((ii+1)*jj+1)
+    cvfi_glo(klon_glo) = cv((ii+1)*jj-ii)
+    boundslonfi_glo(klon_glo,north_east)= 0
+    boundslatfi_glo(klon_glo,north_east)= rlatv(jj)
+    boundslonfi_glo(klon_glo,north_west)= 2*PI
+    boundslatfi_glo(klon_glo,north_west)= rlatv(jj)
+    boundslonfi_glo(klon_glo,south_west)= 2*PI
+    boundslatfi_glo(klon_glo,south_west)= -PI/2
+    boundslonfi_glo(klon_glo,south_east)= 0
+    boundslatfi_glo(klon_glo,south_east)= -Pi/2
+
+    ! build airefi(), mesh area on physics grid
+    CALL gr_dyn_fi(1,ii+1,jj+1,klon_glo,aire,airefi_glo)
+    ! Poles are single points on physics grid
+    airefi_glo(1)=sum(aire(1:ii,1))
+    airefi_glo(klon_glo)=sum(aire(1:ii,jj+1))
+
+    ! Sanity check: do total planet area match between physics and dynamics?
+    total_area_dyn=sum(aire(1:ii,1:jj+1))
+    total_area_phy=sum(airefi_glo(1:klon_glo))
+    IF (total_area_dyn/=total_area_phy) THEN
+      WRITE (lunout, *) 'iniphysiq: planet total surface discrepancy !!!'
+      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
+      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
+      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
+        ! stop here if the relative difference is more than 0.001%
+        abort_message = 'planet total surface discrepancy'
+        CALL abort_gcm(modname, abort_message, 1)
+      ENDIF
+    ENDIF
+  ELSE ! klon_glo==1, running the 1D model
+    ! just copy over input values
+    latfi_glo(1)=rlatu(1)
+    lonfi_glo(1)=rlonv(1)
+    cufi_glo(1)=cu(1)
+    cvfi_glo(1)=cv(1)
+    airefi_glo(1)=aire(1,1)
+    boundslonfi_glo(1,north_east)=rlonu(1)
+    boundslatfi_glo(1,north_east)=PI/2
+    boundslonfi_glo(1,north_west)=rlonu(2)
+    boundslatfi_glo(1,north_west)=PI/2
+    boundslonfi_glo(1,south_west)=rlonu(2)
+    boundslatfi_glo(1,south_west)=rlatv(1)
+    boundslonfi_glo(1,south_east)=rlonu(1)
+    boundslatfi_glo(1,south_east)=rlatv(1)
+  ENDIF ! of IF (klon_glo>1)
+
+!$OMP PARALLEL
+  ! Now generate local lon/lat/cu/cv/area/bounds arrays
+  ALLOCATE(latfi(klon_omp),lonfi(klon_omp),cufi(klon_omp),cvfi(klon_omp))
+  ALLOCATE(airefi(klon_omp))
+  ALLOCATE(boundslonfi(klon_omp,4))
+  ALLOCATE(boundslatfi(klon_omp,4))
+
+
+  offset = klon_mpi_begin - 1
+  airefi(1:klon_omp) = airefi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  cufi(1:klon_omp) = cufi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  cvfi(1:klon_omp) = cvfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  lonfi(1:klon_omp) = lonfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  latfi(1:klon_omp) = latfi_glo(offset+klon_omp_begin:offset+klon_omp_end)
+  boundslonfi(1:klon_omp,:) = boundslonfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
+  boundslatfi(1:klon_omp,:) = boundslatfi_glo(offset+klon_omp_begin:offset+klon_omp_end,:)
+
+  ! copy over local grid longitudes and latitudes
+  CALL init_geometry(klon_omp,lonfi,latfi,boundslonfi,boundslatfi, &
+                     airefi,cufi,cvfi)
+
+
+  ! Initialize tracer names, numbers, etc. for physics
+  CALL init_infotrac_phy(nqtot)
+
+! copy some fundamental parameters to physics
+  rradius=prad
+  rg=pg
+  rr=pr
+  rcpp=pcpp
+
+!$OMP END PARALLEL
+
+!      print*,'ATTENTION !!! TRAVAILLER SUR INIPHYSIQ'
+!      print*,'CONTROLE DES LATITUDES, LONGITUDES, PARAMETRES ...'
+
+! Additional initializations for aquaplanets 
+!!$OMP PARALLEL
+!      if (iflag_phys>=100) then
+!        call iniaqua(klon_omp,rlatd,rlond,iflag_phys)
+!      endif
+!!$OMP END PARALLEL
+
+END SUBROUTINE iniphysiq
+
+END MODULE iniphysiq_mod
Index: DZ5/branches/testing/libf/misc/misc_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/misc/misc_mod.F90	(revision 2407)
+++ 	(revision )
@@ -1,6 +1,0 @@
-module misc_mod
-  integer,save :: itaumax
-  logical,save :: adjust
-  integer,save :: ItCount
-  logical,save :: debug
-end module misc_mod 
Index: /LMDZ5/branches/testing/libf/misc/q_sat.F
===================================================================
--- /LMDZ5/branches/testing/libf/misc/q_sat.F	(revision 2408)
+++ /LMDZ5/branches/testing/libf/misc/q_sat.F	(revision 2408)
@@ -0,0 +1,72 @@
+!
+! $Header$
+!
+!
+!
+
+      subroutine q_sat(np,temp,pres,qsat)
+!
+      IMPLICIT none
+!======================================================================
+! Autheur(s): Z.X. Li (LMD/CNRS)
+!  reecriture vectorisee par F. Hourdin.
+! Objet: calculer la vapeur d'eau saturante (formule Centre Euro.)
+!======================================================================
+! Arguments:
+! kelvin---input-R: temperature en Kelvin
+! millibar--input-R: pression en mb
+!
+! q_sat----output-R: vapeur d'eau saturante en kg/kg
+!======================================================================
+!
+      integer np
+      REAL temp(np),pres(np),qsat(np)
+!
+      REAL r2es
+      PARAMETER (r2es=611.14 *18.0153/28.9644)
+!
+      REAL r3les, r3ies, r3es
+      PARAMETER (R3LES=17.269)
+      PARAMETER (R3IES=21.875)
+!
+      REAL r4les, r4ies, r4es
+      PARAMETER (R4LES=35.86)
+      PARAMETER (R4IES=7.66)
+!
+      REAL rtt
+      PARAMETER (rtt=273.16)
+!
+      REAL retv
+      PARAMETER (retv=28.9644/18.0153 - 1.0)
+
+      real zqsat
+      integer ip
+!
+!     ------------------------------------------------------------------
+!
+!
+
+      do ip=1,np
+
+!      write(*,*)'kelvin,millibar=',kelvin,millibar
+!       write(*,*)'temp,pres=',temp(ip),pres(ip)
+!
+         IF (temp(ip) .LE. rtt) THEN
+            r3es = r3ies
+            r4es = r4ies
+         ELSE
+            r3es = r3les
+            r4es = r4les
+         ENDIF
+!
+         zqsat=r2es/pres(ip)*EXP(r3es*(temp(ip)-rtt)/(temp(ip)-r4es))
+         zqsat=MIN(0.5,ZQSAT)
+         zqsat=zqsat/(1.-retv *zqsat)
+!
+         qsat(ip)= zqsat
+!      write(*,*)'qsat=',qsat(ip)
+
+      enddo
+!
+      RETURN
+      END
Index: /LMDZ5/branches/testing/libf/misc/write_field.F90
===================================================================
--- /LMDZ5/branches/testing/libf/misc/write_field.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/misc/write_field.F90	(revision 2408)
@@ -0,0 +1,326 @@
+!
+! $Id$
+!
+module write_field
+implicit none
+
+  integer, parameter :: MaxWriteField = 100
+  integer, dimension(MaxWriteField),save :: FieldId
+  integer, dimension(MaxWriteField),save :: FieldVarId
+  integer, dimension(MaxWriteField),save :: FieldIndex
+  character(len=255), dimension(MaxWriteField) ::  FieldName 
+   
+  integer,save :: NbField = 0
+  
+  interface WriteField
+    module procedure WriteField3d,WriteField2d,WriteField1d
+  end interface WriteField
+  contains
+  
+    function GetFieldIndex(name)
+    implicit none
+      integer          :: GetFieldindex
+      character(len=*) :: name
+    
+      character(len=255) :: TrueName
+      integer            :: i
+       
+      
+      TrueName=TRIM(ADJUSTL(name))
+    
+      GetFieldIndex=-1
+      do i=1,NbField
+        if (TrueName==FieldName(i)) then
+          GetFieldIndex=i
+          exit
+        endif
+      enddo
+    end function GetFieldIndex
+ 
+    subroutine WriteField3d(name,Field)
+    implicit none
+      character(len=*) :: name
+      real, dimension(:,:,:) :: Field 
+      integer, dimension(3) :: Dim
+      
+      Dim=shape(Field)
+      call WriteField_gen(name,Field,Dim(1),Dim(2),Dim(3))  
+  
+    end subroutine WriteField3d
+    
+    subroutine WriteField2d(name,Field)
+    implicit none
+      character(len=*) :: name
+      real, dimension(:,:) :: Field 
+      integer, dimension(2) :: Dim
+      
+      Dim=shape(Field)
+      call WriteField_gen(name,Field,Dim(1),Dim(2),1)  
+  
+    end subroutine WriteField2d
+    
+    subroutine WriteField1d(name,Field)
+    implicit none
+      character(len=*) :: name
+      real, dimension(:) :: Field 
+      integer, dimension(1) :: Dim
+      
+      Dim=shape(Field)
+      call WriteField_gen(name,Field,Dim(1),1,1)  
+  
+    end subroutine WriteField1d
+        
+    subroutine WriteField_gen(name,Field,dimx,dimy,dimz)
+    implicit none
+    include 'netcdf.inc'
+      character(len=*) :: name
+      integer :: dimx,dimy,dimz
+      real,dimension(dimx,dimy,dimz) :: Field
+      integer,dimension(dimx*dimy*dimz) :: ndex
+      integer :: status
+      integer :: index
+      integer :: start(4)
+      integer :: count(4)
+      
+           
+      Index=GetFieldIndex(name)
+      if (Index==-1) then
+        call CreateNewField(name,dimx,dimy,dimz)
+	Index=GetFieldIndex(name)
+      else
+        FieldIndex(Index)=FieldIndex(Index)+1.
+      endif
+      
+      start(1)=1
+      start(2)=1
+      start(3)=1
+      start(4)=FieldIndex(Index)
+
+      count(1)=dimx
+      count(2)=dimy
+      count(3)=dimz
+      count(4)=1
+
+      status = NF_PUT_VARA_DOUBLE(FieldId(Index),FieldVarId(Index),start,count,Field)
+      status = NF_SYNC(FieldId(Index))
+      
+    end subroutine WriteField_gen
+       
+    subroutine CreateNewField(name,dimx,dimy,dimz)
+    implicit none
+    include 'netcdf.inc'  
+      character(len=*) :: name
+      integer :: dimx,dimy,dimz
+      integer :: TabDim(4)
+      integer :: status
+      
+      
+      NbField=NbField+1
+      FieldName(NbField)=TRIM(ADJUSTL(name))
+      FieldIndex(NbField)=1
+      
+      
+      status = NF_CREATE(TRIM(ADJUSTL(name))//'.nc', NF_CLOBBER, FieldId(NbField))
+      status = NF_DEF_DIM(FieldId(NbField),'X',dimx,TabDim(1))
+      status = NF_DEF_DIM(FieldId(NbField),'Y',dimy,TabDim(2))
+      status = NF_DEF_DIM(FieldId(NbField),'Z',dimz,TabDim(3))
+      status = NF_DEF_DIM(FieldId(NbField),'iter',NF_UNLIMITED,TabDim(4))
+      status = NF_DEF_VAR(FieldId(NbField),FieldName(NbField),NF_DOUBLE,4,TabDim,FieldVarId(NbField))
+      status = NF_ENDDEF(FieldId(NbField))
+
+    end subroutine CreateNewField
+    
+    
+    
+  subroutine write_field1D(name,Field)
+    implicit none
+  
+    integer, parameter :: MaxDim=1
+    character(len=*)   :: name
+    real, dimension(:) :: Field
+    real, dimension(:),allocatable :: New_Field
+    character(len=20) :: str
+    integer, dimension(MaxDim) :: Dim
+    integer :: i,nb
+    integer, parameter :: id=10
+    integer, parameter :: NbCol=4
+    integer :: ColumnSize 
+    integer :: pos
+    character(len=255) :: form
+    character(len=255) :: MaxLen
+    
+    
+    open(unit=id,file=name//'.field',form='formatted',status='replace')
+    write (id,'("----- Field '//name//'",//)')
+    Dim=shape(Field)
+    MaxLen=int2str(len(trim(int2str(Dim(1)))))
+    ColumnSize=20+6+3+len(trim(int2str(Dim(1))))
+    Nb=0
+    Pos=2
+    do i=1,Dim(1)
+      nb=nb+1
+      
+      if (MOD(nb,NbCol)==0) then
+        form='(t'//trim(int2str(pos))// ',i'//trim(MaxLen) //'," ---> ",g22.16,/)'
+        Pos=2
+      else
+        form='(t'//trim(int2str(pos))// ',i'//trim(MaxLen) //'," ---> ",g22.16," | ",)'
+        Pos=Pos+ColumnSize
+      endif
+      write (id,form,advance='no') i,Field(i)
+    enddo
+     
+    close(id)
+
+  end subroutine write_field1D
+
+  subroutine write_field2D(name,Field)
+    implicit none
+  
+    integer, parameter :: MaxDim=2
+    character(len=*)   :: name
+    real, dimension(:,:) :: Field
+    real, dimension(:,:),allocatable :: New_Field
+    character(len=20) :: str
+    integer, dimension(MaxDim) :: Dim
+    integer :: i,j,nb
+    integer, parameter :: id=10
+    integer, parameter :: NbCol=4
+    integer :: ColumnSize 
+    integer :: pos,offset
+    character(len=255) :: form
+    character(len=255) :: spacing
+    
+    open(unit=id,file=name//'.field',form='formatted',status='replace')
+    write (id,'("----- Field '//name//'",//)')
+    
+    Dim=shape(Field)
+    offset=len(trim(int2str(Dim(1))))+len(trim(int2str(Dim(2))))+3
+    ColumnSize=20+6+3+offset
+
+    spacing='(t2,"'//repeat('-',ColumnSize*NbCol)//'")'
+    
+    do i=1,Dim(2)
+      nb=0
+      Pos=2
+      do j=1,Dim(1)
+        nb=nb+1
+      
+        if (MOD(nb,NbCol)==0) then
+          form='(t'//trim(int2str(pos))//            &
+               ',"('//trim(int2str(j))//','          &
+                    //trim(int2str(i))//')",t'       & 
+                    //trim(int2str(pos+offset))     &    
+                    //'," ---> ",g22.16,/)'
+          Pos=2
+        else
+          form='(t'//trim(int2str(pos))//            &
+               ',"('//trim(int2str(j))//','          &
+                    //trim(int2str(i))//')",t'       & 
+                    //trim(int2str(pos+offset))     &    
+                    //'," ---> ",g22.16," | ")'
+          Pos=Pos+ColumnSize
+        endif
+        write (id,form,advance='no') Field(j,i)
+      enddo
+      if (MOD(nb,NbCol)==0) then
+        write (id,spacing)
+      else
+        write (id,'("")')
+        write (id,spacing)
+      endif
+    enddo
+     
+  end subroutine write_field2D
+  
+  subroutine write_field3D(name,Field)
+    implicit none
+  
+    integer, parameter :: MaxDim=3
+    character(len=*)   :: name
+    real, dimension(:,:,:) :: Field
+    real, dimension(:,:,:),allocatable :: New_Field
+    integer, dimension(MaxDim) :: Dim
+    integer :: i,j,k,nb
+    integer, parameter :: id=10
+    integer, parameter :: NbCol=4
+    integer :: ColumnSize 
+    integer :: pos,offset
+    character(len=255) :: form
+    character(len=255) :: spacing
+
+    open(unit=id,file=name//'.field',form='formatted',status='replace')
+    write (id,'("----- Field '//name//'"//)')
+    
+    Dim=shape(Field)
+    offset=len(trim(int2str(Dim(1))))+len(trim(int2str(Dim(2))))+len(trim(int2str(Dim(3))))+4
+    ColumnSize=22+6+3+offset
+
+!    open(unit=id,file=name,form=formatted
+   
+    spacing='(t2,"'//repeat('-',ColumnSize*NbCol)//'")'
+    
+    do i=1,Dim(3)
+    
+      do j=1,Dim(2)
+        nb=0
+        Pos=2
+        
+        do k=1,Dim(1)
+        nb=nb+1
+      
+          if (MOD(nb,NbCol)==0) then
+            form='(t'//trim(int2str(pos))//            &
+                 ',"('//trim(int2str(k))//','          &
+                      //trim(int2str(j))//','          &
+                      //trim(int2str(i))//')",t'       & 
+                      //trim(int2str(pos+offset))      &    
+                      //'," ---> ",g22.16,/)'
+           Pos=2
+          else
+            form='(t'//trim(int2str(pos))//            &
+                 ',"('//trim(int2str(k))//','          &
+                      //trim(int2str(j))//','          &
+                      //trim(int2str(i))//')",t'       & 
+                      //trim(int2str(pos+offset))      &    
+                      //'," ---> ",g22.16," | ")'
+! dépent de l'implémention, sur compaq, c'est necessaire
+!            Pos=Pos+ColumnSize
+          endif
+          write (id,form,advance='no') Field(k,j,i)
+        enddo
+        if (MOD(nb,NbCol)==0) then
+          write (id,spacing)
+        else
+          write (id,'("")')
+          write (id,spacing)
+        endif
+      enddo
+      write (id,spacing)
+    enddo
+    
+    close(id)
+  
+  end subroutine write_field3D  
+  
+  function int2str(int)
+    implicit none
+    integer, parameter :: MaxLen=10
+    integer,intent(in) :: int
+    character(len=MaxLen) :: int2str
+    logical :: flag
+    integer :: i
+    flag=.true.
+    
+    i=int
+    
+    int2str=''
+    do while (flag)
+      int2str=CHAR(MOD(i,10)+48)//int2str
+      i=i/10
+      if (i==0) flag=.false.
+    enddo
+  end function int2str
+
+end module write_field
+  
Index: /LMDZ5/branches/testing/libf/misc/wxios.F90
===================================================================
--- /LMDZ5/branches/testing/libf/misc/wxios.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/misc/wxios.F90	(revision 2408)
@@ -191,5 +191,5 @@
                 CALL xios_set_context_attr_hdl(g_ctx, calendar_type= "NoLeap")
                 IF (prt_level >= 10) WRITE(lunout,*) 'wxios_set_cal: Calendrier terrestre a 365 jours/an'
-            CASE('earth_366d')
+            CASE('gregorian')
                 CALL xios_set_context_attr_hdl(g_ctx, calendar_type= "Gregorian")
                 IF (prt_level >= 10) WRITE(lunout,*) 'wxios_set_cal: Calendrier gregorien'
Index: /LMDZ5/branches/testing/libf/obsolete/LIST.txt
===================================================================
--- /LMDZ5/branches/testing/libf/obsolete/LIST.txt	(revision 2408)
+++ /LMDZ5/branches/testing/libf/obsolete/LIST.txt	(revision 2408)
@@ -0,0 +1,7 @@
+# File    last revison it was included in
+phylmd/ecrireg.F90            2320
+phylmd/ecribin.F90            2320
+phylmd/statto.h               2320
+phylmd/wstats.F90             2320
+phylmd/mkstat.F90             2320
+phylmd/inistats.F90           2320
Index: /LMDZ5/branches/testing/libf/obsolete/ecribin.F90
===================================================================
--- /LMDZ5/branches/testing/libf/obsolete/ecribin.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/obsolete/ecribin.F90	(revision 2408)
@@ -0,0 +1,103 @@
+
+! $Header$
+
+SUBROUTINE ecribins(unit, pz)
+  USE dimphy
+  IMPLICIT NONE
+  ! -----------------------------------------------------------------------
+  include "dimensions.h"
+  ! ccc#include "dimphy.h"
+  include "paramet.h"
+  include "comgeom.h"
+
+  ! arguments:
+  ! ----------
+  INTEGER unit
+  REAL pz(klon)
+
+  ! local:
+  ! ------
+  INTEGER i, j, ig
+  REAL zz(iim+1, jjm+1)
+  ! -----------------------------------------------------------------------
+  ! passage a la grille dynamique:
+  ! ------------------------------
+  DO i = 1, iim + 1
+    zz(i, 1) = pz(1)
+    zz(i, jjm+1) = pz(klon)
+  END DO
+  ! traitement des point normaux
+  DO j = 2, jjm
+    ig = 2 + (j-2)*iim
+    CALL scopy(iim, pz(ig), 1, zz(1,j), 1)
+    zz(iim+1, j) = zz(1, j)
+  END DO
+  ! -----------------------------------------------------------------------
+#ifdef VPP
+  CALL ecriture(unit, zz, (iim+1)*(jjm+1))
+#else
+  WRITE (unit) zz
+#endif
+
+
+  RETURN
+END SUBROUTINE ecribins
+SUBROUTINE ecribina(unit, pz)
+  USE dimphy
+  IMPLICIT NONE
+  ! -----------------------------------------------------------------------
+  include "dimensions.h"
+  ! ccc#include "dimphy.h"
+  include "paramet.h"
+  include "comgeom.h"
+
+  ! arguments:
+  ! ----------
+  INTEGER unit
+  REAL pz(klon, klev)
+
+  ! local:
+  ! ------
+  INTEGER i, j, ilay, ig
+  REAL zz(iim+1, jjm+1, llm)
+  ! -----------------------------------------------------------------------
+  ! passage a la grille dynamique:
+  ! ------------------------------
+  DO ilay = 1, llm
+    ! traitement des poles
+    DO i = 1, iim + 1
+      zz(i, 1, ilay) = pz(1, ilay)
+      zz(i, jjm+1, ilay) = pz(klon, ilay)
+    END DO
+    ! traitement des point normaux
+    DO j = 2, jjm
+      ig = 2 + (j-2)*iim
+      CALL scopy(iim, pz(ig,ilay), 1, zz(1,j,ilay), 1)
+      zz(iim+1, j, ilay) = zz(1, j, ilay)
+    END DO
+  END DO
+  ! -----------------------------------------------------------------------
+  DO ilay = 1, llm
+#ifdef VPP
+    CALL ecriture(unit, zz(1,1,ilay), (iim+1)*(jjm+1))
+#else
+    WRITE (unit)((zz(i,j,ilay),i=1,iim+1), j=1, jjm+1)
+#endif
+  END DO
+
+  RETURN
+END SUBROUTINE ecribina
+#ifdef VPP
+@OPTIONS NODOUBLE
+SUBROUTINE ecriture(nunit, r8, n)
+  INTEGER nunit, n, i
+  REAL (KIND=8) r8(n)
+  REAL r4(n)
+
+  DO i = 1, n
+    r4(i) = r8(i)
+  END DO
+  WRITE (nunit) r4
+  RETURN
+END SUBROUTINE ecriture
+#endif
Index: /LMDZ5/branches/testing/libf/obsolete/ecrireg.F90
===================================================================
--- /LMDZ5/branches/testing/libf/obsolete/ecrireg.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/obsolete/ecrireg.F90	(revision 2408)
@@ -0,0 +1,117 @@
+
+! $Header$
+
+SUBROUTINE ecriregs(unit, pz)
+  USE dimphy
+  IMPLICIT NONE
+  ! -----------------------------------------------------------------------
+  include "dimensions.h"
+  ! ccc#include "dimphy.h"
+  include "paramet.h"
+  include "comgeom.h"
+  include "regdim.h"
+
+  ! arguments:
+  ! ----------
+  INTEGER unit
+  REAL pz(klon)
+
+  ! local:
+  ! ------
+  INTEGER i, j, ig
+  REAL zz(iim, jjm+1)
+  INTEGER nleng
+  PARAMETER (nleng=(i2_fin-i2_deb+1+i1_fin-i1_deb+1)*(j_fin-j_deb+1))
+  REAL zzz(nleng)
+
+  ! -----------------------------------------------------------------------
+  ! passage a la grille dynamique:
+  ! ------------------------------
+  DO i = 1, iim
+    zz(i, 1) = pz(1)
+    zz(i, jjm+1) = pz(klon)
+  END DO
+
+  ! traitement des point normaux
+  DO j = 2, jjm
+    ig = 2 + (j-2)*iim
+    CALL scopy(iim, pz(ig), 1, zz(1,j), 1)
+  END DO
+  ! -----------------------------------------------------------------------
+  ig = 0
+  DO j = j_deb, j_fin
+    DO i = i1_deb, i1_fin
+      ig = ig + 1
+      zzz(ig) = zz(i, j)
+    END DO
+    DO i = i2_deb, i2_fin
+      ig = ig + 1
+      zzz(ig) = zz(i, j)
+    END DO
+  END DO
+#ifdef VPP
+  CALL ecriture(unit, zzz, nleng)
+#else
+  WRITE (unit) zzz
+#endif
+  RETURN
+END SUBROUTINE ecriregs
+SUBROUTINE ecrirega(unit, pz)
+  USE dimphy
+  IMPLICIT NONE
+  ! -----------------------------------------------------------------------
+  include "dimensions.h"
+  ! ccc#include "dimphy.h"
+  include "paramet.h"
+  include "comgeom.h"
+  include "regdim.h"
+
+  ! arguments:
+  ! ----------
+  INTEGER unit
+  REAL pz(klon, klev)
+
+  ! local:
+  ! ------
+  INTEGER i, j, ilay, ig
+  REAL zz(iim, jjm+1, llm)
+  INTEGER nleng
+  PARAMETER (nleng=(i2_fin-i2_deb+1+i1_fin-i1_deb+1)*(j_fin-j_deb+1))
+  REAL zzz(nleng)
+  ! -----------------------------------------------------------------------
+  ! passage a la grille dynamique:
+  ! ------------------------------
+  DO ilay = 1, llm
+    ! traitement des poles
+    DO i = 1, iim
+      zz(i, 1, ilay) = pz(1, ilay)
+      zz(i, jjm+1, ilay) = pz(klon, ilay)
+    END DO
+    ! traitement des point normaux
+    DO j = 2, jjm
+      ig = 2 + (j-2)*iim
+      CALL scopy(iim, pz(ig,ilay), 1, zz(1,j,ilay), 1)
+    END DO
+  END DO
+  ! -----------------------------------------------------------------------
+  DO ilay = 1, llm
+    ig = 0
+    DO j = j_deb, j_fin
+      DO i = i1_deb, i1_fin
+        ig = ig + 1
+        zzz(ig) = zz(i, j, ilay)
+      END DO
+      DO i = i2_deb, i2_fin
+        ig = ig + 1
+        zzz(ig) = zz(i, j, ilay)
+      END DO
+    END DO
+#ifdef VPP
+    CALL ecriture(unit, zzz, nleng)
+#else
+    WRITE (unit) zzz
+#endif
+  END DO
+
+  RETURN
+END SUBROUTINE ecrirega
Index: /LMDZ5/branches/testing/libf/obsolete/inistats.F90
===================================================================
--- /LMDZ5/branches/testing/libf/obsolete/inistats.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/obsolete/inistats.F90	(revision 2408)
@@ -0,0 +1,128 @@
+SUBROUTINE inistats(ierr)
+
+  USE vertical_layers_mod, ONLY: ap,bp,preff,presnivs,pseudoalt
+
+  IMPLICIT NONE
+
+  include "dimensions.h"
+  include "paramet.h"
+  include "comgeom.h"
+  include "comconst.h"
+  include "statto.h"
+  include "netcdf.inc"
+
+  INTEGER, INTENT (OUT) :: ierr
+  INTEGER :: nid
+  INTEGER :: l, nsteppd
+  REAL, DIMENSION (llm) :: sig_s
+  INTEGER :: idim_lat, idim_lon, idim_llm, idim_llmp1, idim_time
+  REAL, DIMENSION (istime) :: lt
+  INTEGER :: nvarid
+
+  WRITE (*, *)
+  WRITE (*, *) '                        || STATS ||'
+  WRITE (*, *)
+  WRITE (*, *) 'daysec', daysec
+  WRITE (*, *) 'dtphys', dtphys
+  nsteppd = nint(daysec/dtphys)
+  WRITE (*, *) 'nsteppd=', nsteppd
+  IF (abs(float(nsteppd)-daysec/dtphys)>1.E-8*daysec) &
+    STOP 'Dans Instat:  1jour .ne. n pas physiques'
+
+  IF (mod(nsteppd,istime)/=0) STOP &
+    'Dans Instat:  1jour .ne. n*istime pas physiques'
+
+  istats = nsteppd/istime
+  WRITE (*, *) 'istats=', istats
+  WRITE (*, *) 'Storing ', istime, 'times per day'
+  WRITE (*, *) 'thus every ', istats, 'physical timestep '
+  WRITE (*, *)
+
+  DO l = 1, llm
+    sig_s(l) = ((ap(l)+ap(l+1))/preff+bp(l)+bp(l+1))/2.
+  END DO
+
+  ierr = nf_create('stats.nc', nf_clobber, nid)
+  IF (ierr/=nf_noerr) THEN
+    WRITE (*, *) nf_strerror(ierr)
+    STOP ''
+  END IF
+
+  ierr = nf_def_dim(nid, 'latitude', jjp1, idim_lat)
+  ierr = nf_def_dim(nid, 'longitude', iip1, idim_lon)
+  ierr = nf_def_dim(nid, 'altitude', llm, idim_llm)
+  ierr = nf_def_dim(nid, 'llmp1', llm+1, idim_llmp1)
+  ierr = nf_def_dim(nid, 'Time', nf_unlimited, idim_time)
+
+  ierr = nf_enddef(nid)
+  CALL def_var_stats(nid, 'Time', 'Time', 'hours since 0000-00-0 00:00:00', &
+    1, idim_time, nvarid, ierr)
+  ! Time is initialised later by mkstats subroutine
+
+  CALL def_var_stats(nid, 'latitude', 'latitude', 'degrees_north', 1, &
+    idim_lat, nvarid, ierr)
+#ifdef NC_DOUBLE
+  ierr = nf_put_var_double(nid, nvarid, rlatu/pi*180)
+#else
+  ierr = nf_put_var_real(nid, nvarid, rlatu/pi*180)
+#endif
+  CALL def_var_stats(nid, 'longitude', 'East longitude', 'degrees_east', 1, &
+    idim_lon, nvarid, ierr)
+#ifdef NC_DOUBLE
+  ierr = nf_put_var_double(nid, nvarid, rlonv/pi*180)
+#else
+  ierr = nf_put_var_real(nid, nvarid, rlonv/pi*180)
+#endif
+
+  ! Niveaux verticaux, aps et bps
+  ierr = nf_redef(nid)
+  ! presnivs
+#ifdef NC_DOUBLE
+  ierr = nf_def_var(nid, 'presnivs', nf_double, 1, idim_llm, nvarid)
+#else
+  ierr = nf_def_var(nid, 'presnivs', nf_float, 1, idim_llm, nvarid)
+#endif
+  ierr = nf_put_att_text(nid, nvarid, 'long_name', 15, 'Vertical levels')
+  ierr = nf_put_att_text(nid, nvarid, 'units', 2, 'Pa')
+  ierr = nf_put_att_text(nid, nvarid, 'positive', 4, 'down')
+  ierr = nf_enddef(nid)
+#ifdef NC_DOUBLE
+  ierr = nf_put_var_double(nid, nvarid, presnivs(1:llm))
+#else
+  ierr = nf_put_var_real(nid, nvarid, presnivs(1:llm))
+#endif
+  ! Pseudo alts
+#ifdef NC_DOUBLE
+  ierr = nf_def_var(nid, 'altitude', nf_double, 1, idim_llm, nvarid)
+#else
+  ierr = nf_def_var(nid, 'altitude', nf_float, 1, idim_llm, nvarid)
+#endif
+  ierr = nf_put_att_text(nid, nvarid, 'long_name', 8, 'altitude')
+  ierr = nf_put_att_text(nid, nvarid, 'units', 2, 'km')
+  ierr = nf_put_att_text(nid, nvarid, 'positive', 2, 'up')
+  ierr = nf_enddef(nid)
+#ifdef NC_DOUBLE
+  ierr = nf_put_var_double(nid, nvarid, pseudoalt)
+#else
+  ierr = nf_put_var_real(nid, nvarid, pseudoalt)
+#endif
+  ! call def_var_stats(nid,"aps","hybrid pressure at midlayers"," ",
+  ! &            1,idim_llm,nvarid,ierr)
+  ! #ifdef NC_DOUBLE
+  ! ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,aps)
+  ! #else
+  ! ierr = NF_PUT_VAR_REAL (nid,nvarid,aps)
+  ! #endif
+
+  ! call def_var_stats(nid,"bps","hybrid sigma at midlayers"," ",
+  ! &            1,idim_llm,nvarid,ierr)
+  ! #ifdef NC_DOUBLE
+  ! ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,bps)
+  ! #else
+  ! ierr = NF_PUT_VAR_REAL (nid,nvarid,bps)
+  ! #endif
+
+  ierr = nf_close(nid)
+
+END SUBROUTINE inistats
+
Index: /LMDZ5/branches/testing/libf/obsolete/mkstat.F90
===================================================================
--- /LMDZ5/branches/testing/libf/obsolete/mkstat.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/obsolete/mkstat.F90	(revision 2408)
@@ -0,0 +1,164 @@
+subroutine mkstats(ierr)
+
+ 
+!
+!  This program writes a stats.nc file from sums and sums of squares
+!  to means and standard deviations and also writes netcdf style
+!  file so that the data can be viewed easily.  The data file is
+!  overwritten in place.  
+!  SRL  21 May 1996
+!  Yann W. july 2003
+
+
+implicit none
+
+#include "dimensions.h"
+#include "statto.h"
+#include "netcdf.inc"
+
+integer,parameter :: iip1=iim+1
+integer,parameter :: jjp1=jjm+1
+integer :: ierr,nid,nbvar,i,ndims,lt,nvarid
+integer, dimension(4) :: id,varid,start,size
+integer, dimension(5) :: dimids
+character (len=50) :: name,nameout,units,title
+real, dimension(iip1,jjp1,llm) :: sum3d,square3d,mean3d,sd3d
+real, dimension(iip1,jjp1) :: sum2d,square2d,mean2d,sd2d
+real, dimension(istime) :: time
+real, dimension(jjp1) :: lat
+real, dimension(iip1) :: lon
+real, dimension(llm) :: alt
+logical :: lcopy=.true.
+!integer :: latid,lonid,altid,timeid
+integer :: meanid,sdid
+!integer, dimension(4) :: dimout
+
+! Incrementation of count for the last step, which is not done in wstats
+count(istime)=count(istime)+1
+
+ierr = NF_OPEN("stats.nc",NF_WRITE,nid)
+
+! We catch the id of dimensions of the stats file
+
+ierr= NF_INQ_DIMID(nid,"latitude",id(1))
+ierr= NF_INQ_DIMID(nid,"longitude",id(2))
+ierr= NF_INQ_DIMID(nid,"altitude",id(3))
+ierr= NF_INQ_DIMID(nid,"Time",id(4))
+
+ierr= NF_INQ_VARID(nid,"latitude",varid(1))
+ierr= NF_INQ_VARID(nid,"longitude",varid(2))
+ierr= NF_INQ_VARID(nid,"altitude",varid(3))
+ierr= NF_INQ_VARID(nid,"Time",varid(4))
+
+! Time initialisation
+
+do i=1,istime
+   time(i)=i*24./istime
+#ifdef NC_DOUBLE
+   ierr= NF_PUT_VARA_DOUBLE(nid,varid(4),i,1,time(i))
+#else
+   ierr= NF_PUT_VARA_REAL(nid,varid(4),i,1,time(i))
+#endif
+enddo
+
+! We catche the values of the variables
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,varid(1),lat)
+         ierr = NF_GET_VAR_DOUBLE(nid,varid(2),lon)
+         ierr = NF_GET_VAR_DOUBLE(nid,varid(3),alt)
+#else
+         ierr = NF_GET_VAR_REAL(nid,varid(1),lat)
+         ierr = NF_GET_VAR_REAL(nid,varid(2),lon)
+         ierr = NF_GET_VAR_REAL(nid,varid(3),alt)
+#endif
+
+! We catch the number of variables in the stats file
+ierr = NF_INQ_NVARS(nid,nbvar)
+
+! to catche the "real" number of variables (without the "additionnal variables")
+nbvar=(nbvar-4)/2 
+
+do i=1,nbvar
+   varid=(i-1)*2+5
+
+   ! What's the variable's name?
+   ierr=NF_INQ_VARNAME(nid,varid,name)
+   write(*,*) "OK variable ",name
+   ! Its units?
+   units=" "
+   ierr=NF_GET_ATT_TEXT(nid,varid,"units",units)
+   ! Its title?
+   title=" "
+   ierr=NF_GET_ATT_TEXT(nid,varid,"title",title)
+   ! Its number of dimensions?   
+   ierr=NF_INQ_VARNDIMS(nid,varid,ndims)
+   ! Its values?
+
+   if(ndims==4) then ! lat, lon, alt & time
+
+!      dimout(1)=lonid
+!      dimout(2)=latid
+!      dimout(3)=altid
+!      dimout(4)=timeid
+
+      size=(/iip1,jjp1,llm,1/)
+      do lt=1,istime
+         start=(/1,1,1,lt/)
+         ! Extraction of the "source" variables
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VARA_DOUBLE(nid,varid,start,size,sum3d)
+         ierr = NF_GET_VARA_DOUBLE(nid,varid+1,start,size,square3d)
+#else
+         ierr = NF_GET_VARA_REAL(nid,varid,start,size,sum3d)
+         ierr = NF_GET_VARA_REAL(nid,varid+1,start,size,square3d)
+#endif
+         ! Calculation of these variables
+         mean3d=sum3d/count(lt)
+         sd3d=sqrt(max(0.,square3d/count(lt)-mean3d**2))
+         ! Writing of the variables
+#ifdef NC_DOUBLE
+         ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,mean3d)
+         ierr = NF_PUT_VARA_DOUBLE(nid,varid+1,start,size,sd3d)
+#else
+         ierr = NF_PUT_VARA_REAL(nid,varid,start,size,mean3d)
+         ierr = NF_PUT_VARA_REAL(nid,varid+1,start,size,sd3d)
+#endif
+      enddo
+
+    else if (ndims.eq.3) then
+
+!      dimout(1)=lonid
+!      dimout(2)=latid
+!      dimout(3)=timeid
+
+      size=(/iip1,jjp1,1,0/)
+      do lt=1,istime
+         start=(/1,1,lt,0/)
+         ! Extraction of the "source" variables
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VARA_DOUBLE(nid,varid,start,size,sum2d)
+         ierr = NF_GET_VARA_DOUBLE(nid,varid+1,start,size,square2d)
+#else
+         ierr = NF_GET_VARA_REAL(nid,varid,start,size,sum2d)
+         ierr = NF_GET_VARA_REAL(nid,varid+1,start,size,square2d)
+#endif
+         ! Calculation of these variables
+         mean2d=sum2d/count(lt)
+         sd2d=sqrt(max(0.,square2d/count(lt)-mean2d**2))
+         ! Writing of the variables
+#ifdef NC_DOUBLE
+         ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,mean2d)
+         ierr = NF_PUT_VARA_DOUBLE(nid,varid+1,start,size,sd2d)
+#else
+         ierr = NF_PUT_VARA_REAL(nid,varid,start,size,mean2d)
+         ierr = NF_PUT_VARA_REAL(nid,varid+1,start,size,sd2d)
+#endif
+      enddo
+
+    endif 
+enddo
+
+ierr= NF_CLOSE(nid)
+
+end
Index: /LMDZ5/branches/testing/libf/obsolete/statto.h
===================================================================
--- /LMDZ5/branches/testing/libf/obsolete/statto.h	(revision 2408)
+++ /LMDZ5/branches/testing/libf/obsolete/statto.h	(revision 2408)
@@ -0,0 +1,34 @@
+
+!  statto:
+!     This include file controls the production of statistics.
+!     Some variables could be set in a namelist, but it is easier to
+!     do it here since arrays can then be dimensioned using parameters
+!     and values shouldn't have to change too often.   SRL
+
+!     Calculate stats every istats physics timesteps, starting at first
+!     call.  If istats=0 then don't do statistics at all.  Check value
+!     if number of physics timesteps changes.
+	integer istats
+
+!     Calculate itime independent sums and sums of squares,
+!     example, istat=1,istime=1 gives a single time mean
+	integer, parameter :: istime=12
+
+!     Number of 2D and 3D variables on which to do statistics.
+	integer n2dvar, n3dvar
+	parameter (n2dvar = 8, n3dvar = 5)
+
+!     Units for writing stats header and data
+	integer usdata
+
+!     count tab to know the variable record
+        integer count(istime)
+
+!     Record of the number of stores made for each time.
+	integer nstore(istime)
+
+! Size of the "controle" array
+        integer, parameter :: cntrlsize=15
+
+!       common /sttcom/ dummy,nstore,istats,usdata
+        common /sttcom/ nstore,istats,usdata,count
Index: /LMDZ5/branches/testing/libf/obsolete/wstats.F90
===================================================================
--- /LMDZ5/branches/testing/libf/obsolete/wstats.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/obsolete/wstats.F90	(revision 2408)
@@ -0,0 +1,351 @@
+subroutine wstats(ngrid,nom,titre,unite,dim,px)
+
+implicit none
+
+#include "dimensions.h"
+#include "statto.h"
+#include "netcdf.inc"
+
+integer,intent(in) :: ngrid
+character (len=*),intent(in) :: nom,titre,unite
+integer,intent(in) :: dim
+real, dimension(ngrid,llm),intent(in) :: px
+integer,parameter :: iip1=iim+1
+integer,parameter :: jjp1=jjm+1
+real, dimension(iip1,jjp1,llm) :: mean3d,sd3d,dx3
+real, dimension(iip1,jjp1) :: mean2d,sd2d,dx2
+character (len=50) :: namebis
+character (len=50), save :: firstvar
+integer :: ierr,varid,nbdim,nid
+integer :: meanid,sdid
+integer, dimension(4)  :: id,start,size
+logical, save :: firstcall=.TRUE.
+integer :: l,i,j,ig0
+integer,save :: index
+
+integer, save :: step=0
+
+
+if (firstcall) then
+   firstcall=.false.
+   firstvar=trim((nom))
+   call inistats(ierr)
+endif
+
+if (firstvar==nom) then ! If we're back to the first variable
+      step = step + 1
+endif
+
+if (mod(step,istats).ne.0) then
+   RETURN
+endif
+
+ierr = NF_OPEN("stats.nc",NF_WRITE,nid)
+
+namebis=trim(nom)
+ierr= NF_INQ_VARID(nid,namebis,meanid)
+
+if (ierr.ne.NF_NOERR) then
+
+   if (firstvar==nom) then 
+      index=1
+      count=0
+   endif
+
+
+!declaration de la variable
+
+! choix du nom des coordonnees
+   ierr= NF_INQ_DIMID(nid,"longitude",id(1))
+   ierr= NF_INQ_DIMID(nid,"latitude",id(2))
+   if (dim.eq.3) then
+      ierr= NF_INQ_DIMID(nid,"altitude",id(3))
+      ierr= NF_INQ_DIMID(nid,"Time",id(4))
+      nbdim=4
+   else if (dim==2) then
+      ierr= NF_INQ_DIMID(nid,"Time",id(3))
+      nbdim=3
+   endif
+
+   write (*,*) "====================="
+   write (*,*) "STATS: creation de ",nom
+   namebis=trim(nom)
+   call def_var_stats(nid,namebis,titre,unite,nbdim,id,meanid,ierr)
+   call inivar(nid,meanid,ngrid,dim,index,px,ierr)
+   namebis=trim(nom)//"_sd"
+   call def_var_stats(nid,namebis,trim(titre)//" total standard deviation over the season",unite,nbdim,id,sdid,ierr)
+   call inivar(nid,sdid,ngrid,dim,index,px,ierr)
+
+   ierr= NF_CLOSE(nid)
+   return
+
+else
+   namebis=trim(nom)//"_sd"
+   ierr= NF_INQ_VARID(nid,namebis,sdid)
+
+endif
+
+if (firstvar==nom) then 
+   count(index)=count(int(index))+1
+   index=index+1
+   if (index>istime) then
+      index=1
+   endif
+endif
+
+if (count(index)==0) then
+   if (dim.eq.3) then
+      start=(/1,1,1,index/)
+      size=(/iip1,jjp1,llm,1/)
+      mean3d=0
+      sd3d=0
+   else if (dim.eq.2) then
+      start=(/1,1,index,0/)
+      size=(/iip1,jjp1,1,0/)
+      mean2d=0
+      sd2d=0
+   endif
+else
+   if (dim.eq.3) then
+      start=(/1,1,1,index/)
+      size=(/iip1,jjp1,llm,1/)
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,size,mean3d)
+      ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,size,sd3d)
+#else
+      ierr = NF_GET_VARA_REAL(nid,meanid,start,size,mean3d)
+      ierr = NF_GET_VARA_REAL(nid,sdid,start,size,sd3d)
+#endif
+      if (ierr.ne.NF_NOERR) then
+         write (*,*) NF_STRERROR(ierr)
+         stop ""
+      endif
+
+   else if (dim.eq.2) then
+      start=(/1,1,index,0/)
+      size=(/iip1,jjp1,1,0/)
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,size,mean2d)
+      ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,size,sd2d)
+#else
+      ierr = NF_GET_VARA_REAL(nid,meanid,start,size,mean2d)
+      ierr = NF_GET_VARA_REAL(nid,sdid,start,size,sd2d)
+#endif
+      if (ierr.ne.NF_NOERR) then
+         write (*,*) NF_STRERROR(ierr)
+         stop ""
+      endif
+   endif
+endif
+
+if (dim.eq.3) then
+
+!  Passage variable physique -->  variable dynamique
+
+   DO l=1,llm
+      DO i=1,iip1
+         dx3(i,1,l)=px(1,l)
+         dx3(i,jjp1,l)=px(ngrid,l)
+      ENDDO
+      DO j=2,jjm
+         ig0= 1+(j-2)*iim
+         DO i=1,iim
+            dx3(i,j,l)=px(ig0+i,l)
+         ENDDO
+         dx3(iip1,j,l)=dx3(1,j,l)
+      ENDDO
+   ENDDO
+
+   mean3d(:,:,:)= mean3d(:,:,:)+dx3(:,:,:)
+   sd3d(:,:,:)= sd3d(:,:,:)+dx3(:,:,:)**2
+
+#ifdef NC_DOUBLE
+   ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,size,mean3d)
+   ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,size,sd3d)
+#else
+   ierr = NF_PUT_VARA_REAL(nid,meanid,start,size,mean3d)
+   ierr = NF_PUT_VARA_REAL(nid,sdid,start,size,sd3d)
+#endif
+   if (ierr.ne.NF_NOERR) then
+     write (*,*) NF_STRERROR(ierr)
+     stop ""
+   endif
+
+else if (dim.eq.2) then
+
+!    Passage variable physique -->  physique dynamique
+
+  DO i=1,iip1
+     dx2(i,1)=px(1,1)
+     dx2(i,jjp1)=px(ngrid,1)
+  ENDDO
+  DO j=2,jjm
+     ig0= 1+(j-2)*iim
+     DO i=1,iim
+        dx2(i,j)=px(ig0+i,1)
+     ENDDO
+     dx2(iip1,j)=dx2(1,j)
+  ENDDO
+
+   mean2d(:,:)= mean2d(:,:)+dx2(:,:)
+   sd2d(:,:)= sd2d(:,:)+dx2(:,:)**2
+
+#ifdef NC_DOUBLE
+   ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,size,mean2d)
+   ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,size,sd2d)
+#else
+   ierr = NF_PUT_VARA_REAL(nid,meanid,start,size,mean2d)
+   ierr = NF_PUT_VARA_REAL(nid,sdid,start,size,sd2d)
+#endif
+   if (ierr.ne.NF_NOERR) then
+     write (*,*) NF_STRERROR(ierr)
+     stop ""
+   endif
+
+endif
+
+ierr= NF_CLOSE(nid)
+
+end subroutine wstats
+
+!======================================================
+subroutine inivar(nid,varid,ngrid,dim,index,px,ierr)
+
+implicit none
+
+include "dimensions.h"
+!!!!!!include "dimphys.h"
+include "netcdf.inc"
+
+integer, intent(in) :: nid,varid,dim,index,ngrid
+real, dimension(ngrid,llm), intent(in) :: px
+integer, intent(out) :: ierr
+
+integer,parameter :: iip1=iim+1
+integer,parameter :: jjp1=jjm+1
+
+integer :: l,i,j,ig0
+integer, dimension(4) :: start,size
+real, dimension(iip1,jjp1,llm) :: dx3
+real, dimension(iip1,jjp1) :: dx2
+
+if (dim.eq.3) then
+
+   start=(/1,1,1,index/)
+   size=(/iip1,jjp1,llm,1/)
+
+!  Passage variable physique -->  variable dynamique
+
+   DO l=1,llm
+      DO i=1,iip1
+         dx3(i,1,l)=px(1,l)
+         dx3(i,jjp1,l)=px(ngrid,l)
+      ENDDO
+      DO j=2,jjm
+         ig0= 1+(j-2)*iim
+         DO i=1,iim
+            dx3(i,j,l)=px(ig0+i,l)
+         ENDDO
+         dx3(iip1,j,l)=dx3(1,j,l)
+      ENDDO
+   ENDDO
+
+#ifdef NC_DOUBLE
+   ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,dx3)
+#else
+   ierr = NF_PUT_VARA_REAL(nid,varid,start,size,dx3)
+#endif
+
+else if (dim.eq.2) then
+
+      start=(/1,1,index,0/)
+      size=(/iip1,jjp1,1,0/)
+
+!    Passage variable physique -->  physique dynamique
+
+  DO i=1,iip1
+     dx2(i,1)=px(1,1)
+     dx2(i,jjp1)=px(ngrid,1)
+  ENDDO
+  DO j=2,jjm
+     ig0= 1+(j-2)*iim
+     DO i=1,iim
+        dx2(i,j)=px(ig0+i,1)
+     ENDDO
+     dx2(iip1,j)=dx2(1,j)
+  ENDDO
+
+#ifdef NC_DOUBLE
+   ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,dx2)
+#else
+   ierr = NF_PUT_VARA_REAL(nid,varid,start,size,dx2)
+#endif
+
+endif
+
+end subroutine inivar
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+subroutine def_var_stats(nid,name,title,units,nbdim,dimids,nvarid,ierr)
+
+! This subroutine defines variable 'name' in a (pre-existing and opened)
+! NetCDF file (known from its NetCDF ID 'nid').
+! The number of dimensions 'nbdim' of the variable, as well as the IDs of
+! corresponding dimensions must be set (in array 'dimids').
+! Upon successfull definition of the variable, 'nvarid' contains the
+! NetCDF ID of the variable.
+! The variables' attributes 'title' (Note that 'long_name' would be more
+! appropriate) and 'units' are also set. 
+
+implicit none
+
+#include "netcdf.inc"
+
+integer,intent(in) :: nid ! NetCDF file ID
+character(len=*),intent(in) :: name ! the variable's name
+character(len=*),intent(in) :: title ! 'title' attribute of variable
+character(len=*),intent(in) :: units ! 'units' attribute of variable
+integer,intent(in) :: nbdim ! number of dimensions of the variable
+integer,dimension(nbdim),intent(in) :: dimids ! NetCDF IDs of the dimensions
+                                              ! the variable is defined along
+integer,intent(out) :: nvarid ! NetCDF ID of the variable
+integer,intent(out) :: ierr ! returned NetCDF staus code
+
+! 1. Switch to NetCDF define mode 
+ierr=NF_REDEF(nid)
+
+! 2. Define the variable
+#ifdef NC_DOUBLE
+ierr = NF_DEF_VAR (nid,adjustl(name),NF_DOUBLE,nbdim,dimids,nvarid)
+#else
+ierr = NF_DEF_VAR (nid,adjustl(name),NF_FLOAT,nbdim,dimids,nvarid)
+#endif
+if(ierr/=NF_NOERR) then
+   write(*,*) "def_var_stats: Failed defining variable "//trim(name)
+   write(*,*) NF_STRERROR(ierr)
+   stop ""
+endif
+
+! 3. Write attributes
+ierr=NF_PUT_ATT_TEXT(nid,nvarid,"title",&
+                     len_trim(adjustl(title)),adjustl(title))
+if(ierr/=NF_NOERR) then
+   write(*,*) "def_var_stats: Failed writing title attribute for "//trim(name)
+   write(*,*) NF_STRERROR(ierr)
+   stop ""
+endif
+
+ierr=NF_PUT_ATT_TEXT(nid,nvarid,"units",&
+                     len_trim(adjustl(units)),adjustl(units))
+if(ierr/=NF_NOERR) then
+   write(*,*) "def_var_stats: Failed writing units attribute for "//trim(name)
+   write(*,*) NF_STRERROR(ierr)
+   stop ""
+endif
+
+! 4. Switch out of NetCDF define mode
+ierr = NF_ENDDEF(nid)
+
+end subroutine def_var_stats
+
Index: /LMDZ5/branches/testing/libf/phy_common/abort_physic.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/abort_physic.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/abort_physic.F90	(revision 2408)
@@ -0,0 +1,50 @@
+! $Id: $
+      SUBROUTINE abort_physic(modname, message, ierr)
+     
+#ifdef CPP_IOIPSL
+      USE IOIPSL
+#else
+! if not using IOIPSL, we still need to use (a local version of) getin_dump
+      USE ioipsl_getincom
+#endif
+      USE mod_phys_lmdz_para
+      USE print_control_mod, ONLY: lunout
+      IMPLICIT NONE
+!
+! Stops the simulation cleanly, closing files and printing various
+! comments
+!
+!  Input: modname = name of calling program
+!         message = stuff to print
+!         ierr    = severity of situation ( = 0 normal )
+
+      character(len=*), intent(in):: modname
+      integer ierr, ierror_mpi
+      character(len=*), intent(in):: message
+
+      write(lunout,*) 'in abort_physic'
+#ifdef CPP_IOIPSL
+!$OMP MASTER
+      call histclo
+      call restclo
+      if (mpi_rank .eq. 0) then
+         call getin_dump
+      endif
+!$OMP END MASTER
+#endif
+
+      write(lunout,*) 'Stopping in ', modname
+      write(lunout,*) 'Reason = ',message
+      if (ierr .eq. 0) then
+        write(lunout,*) 'Everything is cool'
+      else
+        write(lunout,*) 'Houston, we have a problem, ierr = ', ierr
+#ifdef CPP_MPI
+!$OMP CRITICAL (MPI_ABORT_PHYSIC)
+        call MPI_ABORT(COMM_LMDZ_PHY, 1, ierror_mpi)
+!$OMP END CRITICAL (MPI_ABORT_PHYSIC)
+#else
+        stop 1
+#endif          
+      endif
+      END
Index: /LMDZ5/branches/testing/libf/phy_common/geometry_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/geometry_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/geometry_mod.F90	(revision 2408)
@@ -0,0 +1,74 @@
+MODULE geometry_mod
+
+! Store informations concerning the local (to MPI/OpenMP core) geometry
+
+  REAL,SAVE,ALLOCATABLE :: longitude(:) ! longitude of the cell (rad)
+!$OMP THREADPRIVATE(longitude)
+
+  REAL,SAVE,ALLOCATABLE :: latitude(:)! latitude of the cell (rad)
+!$OMP THREADPRIVATE(latitude)
+
+  REAL,SAVE,ALLOCATABLE :: longitude_deg(:) ! longitude of the cell (degree)
+!$OMP THREADPRIVATE(longitude_deg)
+
+  REAL,SAVE,ALLOCATABLE :: latitude_deg(:)! latitude of the cell (degree)
+!$OMP THREADPRIVATE(latitude_deg)
+
+  REAL,SAVE,ALLOCATABLE :: boundslon(:,:)  ! boundaries of the cell (rad)
+!$OMP THREADPRIVATE(boundslon)
+
+  REAL,SAVE,ALLOCATABLE :: boundslat(:,:) ! boundaries of the cell (rad)
+!$OMP THREADPRIVATE(boundslat)
+
+  REAL,SAVE,ALLOCATABLE :: dx(:)      ! resolution of longitude cell (valid only for 2D grid)
+!$OMP THREADPRIVATE(dx)
+  
+  REAL,SAVE,ALLOCATABLE :: dy(:)      ! resolution of latitude cell (valid only for 2D grid)
+!$OMP THREADPRIVATE(dy)
+
+  REAL,SAVE,ALLOCATABLE :: cell_area(:)      ! area of the cell
+!$OMP THREADPRIVATE(cell_area)
+
+
+CONTAINS
+
+  SUBROUTINE init_geometry(klon,longitude_,latitude_, &
+                           boundslon_,boundslat_, &
+                           cell_area_,dx_,dy_)
+  USE mod_grid_phy_lmdz, ONLY: nvertex
+  USE nrtype, ONLY : PI
+  IMPLICIT NONE
+    INTEGER,INTENT(IN) :: klon ! number of columns for this MPI/OpenMP domain
+    REAL,INTENT(IN) :: longitude_(klon)
+    REAL,INTENT(IN) :: latitude_(klon)
+    REAL,INTENT(IN) :: boundslon_(klon,nvertex)
+    REAL,INTENT(IN) :: boundslat_(klon,nvertex)
+    REAL,INTENT(IN) :: cell_area_(klon)
+    REAL,OPTIONAL,INTENT(IN) :: dx_(klon)
+    REAL,OPTIONAL,INTENT(IN) :: dy_(klon)
+    
+    ALLOCATE(longitude(klon))
+    ALLOCATE(latitude(klon))
+    ALLOCATE(longitude_deg(klon))
+    ALLOCATE(latitude_deg(klon))
+    ALLOCATE(boundslon(klon,nvertex))
+    ALLOCATE(boundslat(klon,nvertex))
+    ALLOCATE(cell_area(klon))
+    IF (PRESENT(dx_)) ALLOCATE(dx(klon))
+    IF (PRESENT(dy_))ALLOCATE(dy(klon))
+    
+    longitude(:) = longitude_(:)
+    latitude(:) = latitude_(:)
+    longitude_deg(:) = longitude(:)*180./PI
+    latitude_deg(:) = latitude(:)*180./PI
+    boundslon(:,:) = boundslon_(:,:)
+    boundslat(:,:) = boundslat_(:,:)
+    cell_area(:) = cell_area_(:)
+    IF (PRESENT(dx_)) dx(:) = dx_(:)
+    IF (PRESENT(dy_)) dy(:) = dy_(:)
+    
+  END SUBROUTINE init_geometry
+
+
+END MODULE geometry_mod
+
Index: /LMDZ5/branches/testing/libf/phy_common/ioipsl_getin_p_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/ioipsl_getin_p_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/ioipsl_getin_p_mod.F90	(revision 2408)
@@ -0,0 +1,169 @@
+!
+! $Id$
+!
+MODULE ioipsl_getin_p_mod
+! To use getin in a parallel context
+!---------------------------------------------------------------------
+#ifdef CPP_IOIPSL
+USE ioipsl, ONLY: getin
+#else
+USE ioipsl_getincom, ONLY: getin
+#endif
+USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
+USE mod_phys_lmdz_transfert_para, ONLY : bcast
+!-
+IMPLICIT NONE
+!-
+PRIVATE
+PUBLIC :: getin_p
+!-
+INTERFACE getin_p
+
+  MODULE PROCEDURE getinrs_p, getinr1d_p, getinr2d_p, &
+ &                 getinis_p, getini1d_p, getini2d_p, &
+ &                 getincs_p, 		              &
+ &                 getinls_p, getinl1d_p, getinl2d_p
+END INTERFACE
+!-
+CONTAINS
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!!   Definition des getin -> bcast      !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+!! -- Les chaines de caracteres -- !!
+  
+  SUBROUTINE getincs_p(VarIn,VarOut)
+    IMPLICIT NONE    
+    CHARACTER(LEN=*),INTENT(IN) :: VarIn
+    CHARACTER(LEN=*),INTENT(INOUT) :: VarOut    
+
+!$OMP BARRIER
+    IF (is_mpi_root .AND. is_omp_root) THEN
+    	CALL getin(VarIn,VarOut)
+    ENDIF
+    CALL bcast(VarOut)
+  END SUBROUTINE getincs_p
+
+!! -- Les entiers -- !!
+  
+  SUBROUTINE getinis_p(VarIn,VarOut)
+    IMPLICIT NONE    
+    CHARACTER(LEN=*),INTENT(IN) :: VarIn
+    INTEGER,INTENT(INOUT) :: VarOut    
+
+!$OMP BARRIER
+    IF (is_mpi_root .AND. is_omp_root) THEN
+    	CALL getin(VarIn,VarOut)
+    ENDIF
+    CALL bcast(VarOut)
+  END SUBROUTINE getinis_p
+
+  SUBROUTINE getini1d_p(VarIn,VarOut)
+    IMPLICIT NONE    
+    CHARACTER(LEN=*),INTENT(IN) :: VarIn
+    INTEGER,INTENT(INOUT) :: VarOut(:)
+
+!$OMP BARRIER
+    IF (is_mpi_root .AND. is_omp_root) THEN
+    	CALL getin(VarIn,VarOut)
+    ENDIF
+    CALL bcast(VarOut)
+  END SUBROUTINE getini1d_p
+
+  SUBROUTINE getini2d_p(VarIn,VarOut)
+    IMPLICIT NONE    
+    CHARACTER(LEN=*),INTENT(IN) :: VarIn
+    INTEGER,INTENT(INOUT) :: VarOut(:,:)
+
+!$OMP BARRIER
+    IF (is_mpi_root .AND. is_omp_root) THEN
+    	CALL getin(VarIn,VarOut)
+    ENDIF
+    CALL bcast(VarOut)
+  END SUBROUTINE getini2d_p
+
+!! -- Les flottants -- !!
+  
+  SUBROUTINE getinrs_p(VarIn,VarOut)
+    IMPLICIT NONE    
+    CHARACTER(LEN=*),INTENT(IN) :: VarIn
+    REAL,INTENT(INOUT) :: VarOut
+
+!$OMP BARRIER
+    IF (is_mpi_root .AND. is_omp_root) THEN
+    	CALL getin(VarIn,VarOut)
+    ENDIF
+    CALL bcast(VarOut)
+  END SUBROUTINE getinrs_p
+
+  SUBROUTINE getinr1d_p(VarIn,VarOut)
+    IMPLICIT NONE    
+    CHARACTER(LEN=*),INTENT(IN) :: VarIn
+    REAL,INTENT(INOUT) :: VarOut(:)
+
+!$OMP BARRIER
+    IF (is_mpi_root .AND. is_omp_root) THEN
+    	CALL getin(VarIn,VarOut)
+    ENDIF
+    CALL bcast(VarOut)
+  END SUBROUTINE getinr1d_p
+
+  SUBROUTINE getinr2d_p(VarIn,VarOut)
+    IMPLICIT NONE    
+    CHARACTER(LEN=*),INTENT(IN) :: VarIn
+    REAL,INTENT(INOUT) :: VarOut(:,:)
+
+!$OMP BARRIER
+    IF (is_mpi_root .AND. is_omp_root) THEN
+    	CALL getin(VarIn,VarOut)
+    ENDIF
+    CALL bcast(VarOut)
+  END SUBROUTINE getinr2d_p
+
+!! -- Les Booleens -- !!
+  
+  SUBROUTINE getinls_p(VarIn,VarOut)
+    IMPLICIT NONE    
+    CHARACTER(LEN=*),INTENT(IN) :: VarIn
+    LOGICAL,INTENT(INOUT) :: VarOut
+
+!$OMP BARRIER
+    IF (is_mpi_root .AND. is_omp_root) THEN
+    	CALL getin(VarIn,VarOut)
+    ENDIF
+    CALL bcast(VarOut)
+  END SUBROUTINE getinls_p
+
+  SUBROUTINE getinl1d_p(VarIn,VarOut)
+    IMPLICIT NONE    
+    CHARACTER(LEN=*),INTENT(IN) :: VarIn
+    LOGICAL,INTENT(INOUT) :: VarOut(:)
+
+!$OMP BARRIER
+    IF (is_mpi_root .AND. is_omp_root) THEN
+    	CALL getin(VarIn,VarOut)
+    ENDIF
+    CALL bcast(VarOut)
+  END SUBROUTINE getinl1d_p
+
+  SUBROUTINE getinl2d_p(VarIn,VarOut)
+    IMPLICIT NONE    
+    CHARACTER(LEN=*),INTENT(IN) :: VarIn
+    LOGICAL,INTENT(INOUT) :: VarOut(:,:)
+
+!$OMP BARRIER
+    IF (is_mpi_root .AND. is_omp_root) THEN
+    	CALL getin(VarIn,VarOut)
+    ENDIF
+    CALL bcast(VarOut)
+  END SUBROUTINE getinl2d_p
+!-
+!-----------------------------
+!-----------------------------
+!-----------------------------
+
+END MODULE ioipsl_getin_p_mod
+
Index: /LMDZ5/branches/testing/libf/phy_common/mod_grid_phy_lmdz.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/mod_grid_phy_lmdz.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/mod_grid_phy_lmdz.F90	(revision 2408)
@@ -0,0 +1,468 @@
+!
+!$Id $
+!
+MODULE mod_grid_phy_lmdz
+
+  PUBLIC
+  PRIVATE :: grid1dTo2d_glo_igen, grid1dTo2d_glo_rgen, grid1dTo2d_glo_lgen, &
+             grid2dTo1d_glo_igen, grid2dTo1d_glo_rgen, grid2dTo1d_glo_lgen
+  
+  INTEGER,PARAMETER :: unstructured=0
+  INTEGER,PARAMETER :: regular_lonlat=1
+
+  INTEGER,SAVE :: grid_type
+  INTEGER,SAVE :: nvertex
+  INTEGER,SAVE :: nbp_lon  ! == iim
+  INTEGER,SAVE :: nbp_lat  ! == jjmp1 (or == 1 if running 1D model)
+  INTEGER,SAVE :: nbp_lev  ! == llm
+  INTEGER,SAVE :: klon_glo ! total number of atmospheric columns
+
+  INTERFACE grid1dTo2d_glo
+    MODULE PROCEDURE grid1dTo2d_glo_i,grid1dTo2d_glo_i1,grid1dTo2d_glo_i2,grid1dTo2d_glo_i3, &
+                     grid1dTo2d_glo_r,grid1dTo2d_glo_r1,grid1dTo2d_glo_r2,grid1dTo2d_glo_r3, &
+		     grid1dTo2d_glo_l,grid1dTo2d_glo_l1,grid1dTo2d_glo_l2,grid1dTo2d_glo_l3
+   END INTERFACE 
+
+   INTERFACE grid2dTo1d_glo
+    MODULE PROCEDURE grid2dTo1d_glo_i,grid2dTo1d_glo_i1,grid2dTo1d_glo_i2,grid2dTo1d_glo_i3, &
+                     grid2dTo1d_glo_r,grid2dTo1d_glo_r1,grid2dTo1d_glo_r2,grid2dTo1d_glo_r3, &
+		     grid2dTo1d_glo_l,grid2dTo1d_glo_l1,grid2dTo1d_glo_l2,grid2dTo1d_glo_l3
+   END INTERFACE 
+ 
+CONTAINS
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! SUBROUTINE grid1dTo2d  !!  
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+
+  SUBROUTINE init_grid_phy_lmdz(grid_type_,nvertex_,nbp_lon_,nbp_lat_,nbp_lev_)
+  IMPLICIT NONE
+  INTEGER,INTENT(IN)  :: grid_type_ 
+  INTEGER,INTENT(IN)  :: nvertex_ 
+  INTEGER, INTENT(IN) :: nbp_lon_
+  INTEGER, INTENT(IN) :: nbp_lat_
+  INTEGER, INTENT(IN) :: nbp_lev_
+  
+    grid_type = grid_type_
+    nvertex   = nvertex_
+    nbp_lon   = nbp_lon_
+    nbp_lat   = nbp_lat_
+    nbp_lev   = nbp_lev_
+    
+    IF (nbp_lon*nbp_lat==1) THEN
+      klon_glo=1
+    ELSE    
+      klon_glo=(nbp_lon*nbp_lat)-2*(nbp_lon-1)
+    ENDIF
+  
+  END SUBROUTINE init_grid_phy_lmdz
+  
+  
+  SUBROUTINE grid1dTo2d_glo_i(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:)     :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_igen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid1dTo2d_glo_i
+  
+
+  SUBROUTINE grid1dTo2d_glo_i1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:)     :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_igen(VarIn,VarOut,size(VarIn,2))
+  
+  END SUBROUTINE grid1dTo2d_glo_i1
+
+  SUBROUTINE grid1dTo2d_glo_i2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_igen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
+  
+  END SUBROUTINE grid1dTo2d_glo_i2
+  
+  SUBROUTINE grid1dTo2d_glo_i3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_igen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid1dTo2d_glo_i3
+
+
+  SUBROUTINE grid1dTo2d_glo_r(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:)     :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_rgen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid1dTo2d_glo_r
+  
+
+  SUBROUTINE grid1dTo2d_glo_r1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:)     :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_rgen(VarIn,VarOut,size(VarIn,2))
+  
+  END SUBROUTINE grid1dTo2d_glo_r1
+
+  SUBROUTINE grid1dTo2d_glo_r2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_rgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
+  
+  END SUBROUTINE grid1dTo2d_glo_r2
+  
+  SUBROUTINE grid1dTo2d_glo_r3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_rgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid1dTo2d_glo_r3
+  
+  
+  
+  SUBROUTINE grid1dTo2d_glo_l(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:)     :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_lgen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid1dTo2d_glo_l
+  
+
+  SUBROUTINE grid1dTo2d_glo_l1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:)     :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_lgen(VarIn,VarOut,size(VarIn,2))
+  
+  END SUBROUTINE grid1dTo2d_glo_l1
+
+  SUBROUTINE grid1dTo2d_glo_l2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_lgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
+  
+  END SUBROUTINE grid1dTo2d_glo_l2
+  
+  SUBROUTINE grid1dTo2d_glo_l3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_glo_lgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid1dTo2d_glo_l3  
+  
+    SUBROUTINE grid2dTo1d_glo_i(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_igen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid2dTo1d_glo_i
+  
+
+  SUBROUTINE grid2dTo1d_glo_i1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_igen(VarIn,VarOut,size(VarIn,3))
+  
+  END SUBROUTINE grid2dTo1d_glo_i1
+
+  SUBROUTINE grid2dTo1d_glo_i2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_igen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid2dTo1d_glo_i2
+  
+  SUBROUTINE grid2dTo1d_glo_i3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_igen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
+  
+  END SUBROUTINE grid2dTo1d_glo_i3
+ 
+
+
+
+  SUBROUTINE grid2dTo1d_glo_r(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_rgen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid2dTo1d_glo_r
+  
+
+  SUBROUTINE grid2dTo1d_glo_r1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_rgen(VarIn,VarOut,size(VarIn,3))
+  
+  END SUBROUTINE grid2dTo1d_glo_r1
+
+  SUBROUTINE grid2dTo1d_glo_r2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_rgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid2dTo1d_glo_r2
+  
+  SUBROUTINE grid2dTo1d_glo_r3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_rgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
+  
+  END SUBROUTINE grid2dTo1d_glo_r3
+
+
+
+  SUBROUTINE grid2dTo1d_glo_l(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_lgen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid2dTo1d_glo_l
+  
+
+  SUBROUTINE grid2dTo1d_glo_l1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_lgen(VarIn,VarOut,size(VarIn,3))
+  
+  END SUBROUTINE grid2dTo1d_glo_l1
+
+  SUBROUTINE grid2dTo1d_glo_l2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_lgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid2dTo1d_glo_l2
+  
+  SUBROUTINE grid2dTo1d_glo_l3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_glo_lgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
+  
+  END SUBROUTINE grid2dTo1d_glo_l3
+
+!---------------------------------------------------------------- 
+!  Generic (private) fonctions
+!---------------------------------------------------------------- 
+  
+  SUBROUTINE grid1dTo2d_glo_igen(VarIn,VarOut,dimsize)
+
+    IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    INTEGER,INTENT(IN) ,DIMENSION(klon_glo,dimsize)       :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(nbp_lon*nbp_lat,dimsize)  :: VarOut
+    INTEGER :: i,ij,Offset
+
+    
+    Offset=nbp_lon
+        
+    DO i=1,dimsize
+      DO ij=1,klon_glo
+        VarOut(ij+offset-1,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO
+    
+    
+    DO i=1,dimsize
+      DO ij=1,nbp_lon
+       VarOut(ij,i)=VarIn(1,i)
+      ENDDO
+    ENDDO
+    
+    
+    DO i=1,dimsize
+      DO ij=nbp_lon*(nbp_lat-1)+1,nbp_lat*nbp_lon
+       VarOut(ij,i)=VarIn(klon_glo,i)
+      ENDDO
+    ENDDO
+
+  END SUBROUTINE grid1dTo2d_glo_igen   
+
+
+  SUBROUTINE grid1dTo2d_glo_rgen(VarIn,VarOut,dimsize)
+
+    IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    REAL,INTENT(IN) ,DIMENSION(klon_glo,dimsize)       :: VarIn
+    REAL,INTENT(OUT),DIMENSION(nbp_lon*nbp_lat,dimsize)  :: VarOut
+    INTEGER :: i,ij,Offset
+
+   
+    Offset=nbp_lon
+        
+    DO i=1,dimsize
+      DO ij=1,klon_glo
+        VarOut(ij+offset-1,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO
+    
+    
+    DO i=1,dimsize
+      DO ij=1,nbp_lon
+       VarOut(ij,i)=VarIn(1,i)
+      ENDDO
+    ENDDO
+    
+    
+    DO i=1,dimsize
+      DO ij=nbp_lon*(nbp_lat-1)+1,nbp_lat*nbp_lon
+       VarOut(ij,i)=VarIn(klon_glo,i)
+      ENDDO
+    ENDDO
+
+  END SUBROUTINE grid1dTo2d_glo_rgen   
+
+  SUBROUTINE grid1dTo2d_glo_lgen(VarIn,VarOut,dimsize)
+
+    IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: dimsize
+    LOGICAL,INTENT(IN) ,DIMENSION(klon_glo,dimsize)       :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(nbp_lon*nbp_lat,dimsize)  :: VarOut
+    INTEGER :: i,ij,Offset
+
+    Offset=nbp_lon
+        
+    DO i=1,dimsize
+      DO ij=1,klon_glo
+        VarOut(ij+offset-1,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO
+    
+    
+    DO i=1,dimsize
+      DO ij=1,nbp_lon
+       VarOut(ij,i)=VarIn(1,i)
+      ENDDO
+    ENDDO
+    
+    
+    DO i=1,dimsize
+      DO ij=nbp_lon*(nbp_lat-1)+1,nbp_lat*nbp_lon
+       VarOut(ij,i)=VarIn(klon_glo,i)
+      ENDDO
+    ENDDO
+
+  END SUBROUTINE grid1dTo2d_glo_lgen     
+  
+  
+  SUBROUTINE grid2dTo1d_glo_igen(VarIn,VarOut,dimsize)
+
+    IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    INTEGER,INTENT(IN) ,DIMENSION(nbp_lon*nbp_lat,dimsize) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(klon_glo,dimsize)      :: VarOut
+    INTEGER :: i,ij,offset
+
+    offset=nbp_lon
+
+    DO i=1,dimsize
+      DO ij=1,klon_glo
+        VarOut(ij,i)=VarIn(ij+offset-1,i)
+      ENDDO
+    ENDDO
+
+    DO i=1,dimsize
+      VarOut(1,i)=VarIn(1,i)
+    ENDDO
+    
+  END SUBROUTINE grid2dTo1d_glo_igen   
+  
+  SUBROUTINE grid2dTo1d_glo_rgen(VarIn,VarOut,dimsize)
+
+    IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    REAL,INTENT(IN) ,DIMENSION(nbp_lon*nbp_lat,dimsize) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(klon_glo,dimsize)      :: VarOut
+    INTEGER :: i,ij,offset
+
+    offset=nbp_lon
+
+    DO i=1,dimsize
+      DO ij=1,klon_glo
+        VarOut(ij,i)=VarIn(ij+offset-1,i)
+      ENDDO
+    ENDDO
+
+    DO i=1,dimsize
+      VarOut(1,i)=VarIn(1,i)
+    ENDDO
+    
+  END SUBROUTINE grid2dTo1d_glo_rgen 
+    
+  SUBROUTINE grid2dTo1d_glo_lgen(VarIn,VarOut,dimsize)
+
+    IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    LOGICAL,INTENT(IN) ,DIMENSION(nbp_lon*nbp_lat,dimsize) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(klon_glo,dimsize)      :: VarOut
+    INTEGER :: i,ij,offset
+
+    offset=nbp_lon
+
+    DO i=1,dimsize
+      DO ij=1,klon_glo
+        VarOut(ij,i)=VarIn(ij+offset-1,i)
+      ENDDO
+    ENDDO
+
+    DO i=1,dimsize
+      VarOut(1,i)=VarIn(1,i)
+    ENDDO
+    
+  END SUBROUTINE grid2dTo1d_glo_lgen   
+
+END MODULE mod_grid_phy_lmdz
Index: /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_mpi_data.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_mpi_data.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_mpi_data.F90	(revision 2408)
@@ -0,0 +1,225 @@
+!
+!$Header$
+!
+MODULE mod_phys_lmdz_mpi_data
+!  USE mod_const_mpi
+  
+  INTEGER,SAVE :: ii_begin
+  INTEGER,SAVE :: ii_end
+  INTEGER,SAVE :: jj_begin
+  INTEGER,SAVE :: jj_end
+  INTEGER,SAVE :: jj_nb
+  INTEGER,SAVE :: ij_begin
+  INTEGER,SAVE :: ij_end
+  INTEGER,SAVE :: ij_nb
+  INTEGER,SAVE :: klon_mpi_begin
+  INTEGER,SAVE :: klon_mpi_end
+  INTEGER,SAVE :: klon_mpi
+  
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: jj_para_nb
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: jj_para_begin
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: jj_para_end
+
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ii_para_begin
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ii_para_end
+
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ij_para_nb
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ij_para_begin
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: ij_para_end
+
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: klon_mpi_para_nb
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: klon_mpi_para_begin
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:) :: klon_mpi_para_end 
+
+  
+  INTEGER,SAVE :: mpi_rank
+  INTEGER,SAVE :: mpi_size
+  INTEGER,SAVE :: mpi_master
+!  INTEGER,SAVE :: mpi_root
+  LOGICAL,SAVE :: is_mpi_root
+  LOGICAL,SAVE :: is_using_mpi
+  
+  
+  LOGICAL,SAVE :: is_north_pole
+  LOGICAL,SAVE :: is_south_pole
+  INTEGER,SAVE :: COMM_LMDZ_PHY
+  INTEGER,SAVE :: MPI_REAL_LMDZ   ! MPI_REAL8
+
+CONTAINS
+  
+!  SUBROUTINE Init_phys_lmdz_mpi_data(iim,jjp1,nb_proc,distrib)
+  SUBROUTINE init_phys_lmdz_mpi_data(nbp, nbp_lon, nbp_lat, communicator)
+!  USE mod_const_mpi, ONLY : COMM_LMDZ
+  IMPLICIT NONE
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+    INTEGER,INTENT(in) :: nbp
+    INTEGER,INTENT(in) :: nbp_lon
+    INTEGER,INTENT(in) :: nbp_lat
+    INTEGER,INTENT(in) :: communicator
+    
+    INTEGER,ALLOCATABLE :: distrib(:)
+    INTEGER :: ierr
+    INTEGER :: klon_glo
+    INTEGER :: i
+    
+#ifdef CPP_MPI
+    is_using_mpi=.TRUE.
+#else
+    is_using_mpi=.FALSE.
+#endif
+    
+    if ((nbp_lon.eq.1).and.(nbp_lat.eq.1)) then ! running 1D column model
+       klon_glo=1
+    else
+    ! The usual global physics grid: 1 point for each pole and nbp_lon points
+    ! for all other latitudes
+       klon_glo=nbp_lon*(nbp_lat-2)+2
+    endif
+    
+    COMM_LMDZ_PHY=communicator
+
+    IF (is_using_mpi) THEN    
+#ifdef CPP_MPI
+      MPI_REAL_LMDZ=MPI_REAL8
+      CALL MPI_COMM_SIZE(COMM_LMDZ_PHY,mpi_size,ierr)    
+      CALL MPI_COMM_RANK(COMM_LMDZ_PHY,mpi_rank,ierr)
+#endif
+    ELSE
+      mpi_size=1
+      mpi_rank=0
+    ENDIF
+    
+    ALLOCATE(distrib(0:mpi_size-1))
+
+    IF (is_using_mpi) THEN    
+#ifdef CPP_MPI
+    CALL MPI_ALLGATHER(nbp,1,MPI_INTEGER,distrib,1,MPI_INTEGER,COMM_LMDZ_PHY,ierr)
+#endif
+    ELSE
+     distrib(:)=nbp
+    ENDIF
+
+
+    IF (mpi_rank == 0) THEN
+      mpi_master = 0
+      is_mpi_root = .true.
+    ENDIF
+    
+    IF (mpi_rank == 0) THEN 
+      is_north_pole = .TRUE.
+    ELSE
+      is_north_pole = .FALSE.
+    ENDIF
+    
+    IF (mpi_rank == mpi_size-1) THEN
+      is_south_pole = .TRUE.
+    ELSE
+      is_south_pole = .FALSE.
+    ENDIF
+    
+    ALLOCATE(jj_para_nb(0:mpi_size-1))
+    ALLOCATE(jj_para_begin(0:mpi_size-1))
+    ALLOCATE(jj_para_end(0:mpi_size-1))
+    
+    ALLOCATE(ij_para_nb(0:mpi_size-1))
+    ALLOCATE(ij_para_begin(0:mpi_size-1))
+    ALLOCATE(ij_para_end(0:mpi_size-1))
+    
+    ALLOCATE(ii_para_begin(0:mpi_size-1))
+    ALLOCATE(ii_para_end(0:mpi_size-1))
+
+    ALLOCATE(klon_mpi_para_nb(0:mpi_size-1))
+    ALLOCATE(klon_mpi_para_begin(0:mpi_size-1))
+    ALLOCATE(klon_mpi_para_end(0:mpi_size-1))
+  
+      
+    klon_mpi_para_nb(0:mpi_size-1)=distrib(0:mpi_size-1)
+
+    DO i=0,mpi_size-1
+      IF (i==0) THEN 
+        klon_mpi_para_begin(i)=1
+      ELSE 
+        klon_mpi_para_begin(i)=klon_mpi_para_end(i-1)+1
+      ENDIF
+        klon_mpi_para_end(i)=klon_mpi_para_begin(i)+klon_mpi_para_nb(i)-1
+    ENDDO
+
+
+    DO i=0,mpi_size-1
+      
+      IF (i==0) THEN
+        ij_para_begin(i) = 1
+      ELSE
+        ij_para_begin(i) = klon_mpi_para_begin(i)+nbp_lon-1
+      ENDIF
+
+      jj_para_begin(i) = (ij_para_begin(i)-1)/nbp_lon + 1
+      ii_para_begin(i) = MOD(ij_para_begin(i)-1,nbp_lon) + 1
+
+      
+      ij_para_end(i) = klon_mpi_para_end(i)+nbp_lon-1
+      jj_para_end(i) = (ij_para_end(i)-1)/nbp_lon + 1
+      ii_para_end(i) = MOD(ij_para_end(i)-1,nbp_lon) + 1
+
+
+      ij_para_nb(i) = ij_para_end(i)-ij_para_begin(i)+1
+      jj_para_nb(i) = jj_para_end(i)-jj_para_begin(i)+1
+         
+    ENDDO
+  
+    ii_begin = ii_para_begin(mpi_rank)
+    ii_end   = ii_para_end(mpi_rank)
+    jj_begin = jj_para_begin(mpi_rank)
+    jj_end   = jj_para_end(mpi_rank)
+    jj_nb    = jj_para_nb(mpi_rank)
+    ij_begin = ij_para_begin(mpi_rank)
+    ij_end   = ij_para_end(mpi_rank)
+    ij_nb    = ij_para_nb(mpi_rank)
+    klon_mpi_begin = klon_mpi_para_begin(mpi_rank)
+    klon_mpi_end   = klon_mpi_para_end(mpi_rank)
+    klon_mpi       = klon_mpi_para_nb(mpi_rank)
+   
+    CALL Print_module_data
+    
+  END SUBROUTINE Init_phys_lmdz_mpi_data
+
+  SUBROUTINE print_module_data
+!  USE print_control_mod, ONLY: lunout
+  IMPLICIT NONE
+  INCLUDE "iniprint.h" 
+  
+    WRITE(lunout,*) 'ii_begin =', ii_begin
+    WRITE(lunout,*) 'ii_end =', ii_end
+    WRITE(lunout,*) 'jj_begin =',jj_begin
+    WRITE(lunout,*) 'jj_end =', jj_end
+    WRITE(lunout,*) 'jj_nb =', jj_nb
+    WRITE(lunout,*) 'ij_begin =', ij_begin
+    WRITE(lunout,*) 'ij_end =', ij_end
+    WRITE(lunout,*) 'ij_nb =', ij_nb
+    WRITE(lunout,*) 'klon_mpi_begin =', klon_mpi_begin
+    WRITE(lunout,*) 'klon_mpi_end =', klon_mpi_end
+    WRITE(lunout,*) 'klon_mpi =', klon_mpi
+    WRITE(lunout,*) 'jj_para_nb =', jj_para_nb
+    WRITE(lunout,*) 'jj_para_begin =', jj_para_begin
+    WRITE(lunout,*) 'jj_para_end =', jj_para_end
+    WRITE(lunout,*) 'ii_para_begin =', ii_para_begin
+    WRITE(lunout,*) 'ii_para_end =', ii_para_end
+    WRITE(lunout,*) 'ij_para_nb =', ij_para_nb
+    WRITE(lunout,*) 'ij_para_begin =', ij_para_begin
+    WRITE(lunout,*) 'ij_para_end =', ij_para_end
+    WRITE(lunout,*) 'klon_mpi_para_nb =', klon_mpi_para_nb
+    WRITE(lunout,*) 'klon_mpi_para_begin =', klon_mpi_para_begin
+    WRITE(lunout,*) 'klon_mpi_para_end  =', klon_mpi_para_end 
+    WRITE(lunout,*) 'mpi_rank =', mpi_rank
+    WRITE(lunout,*) 'mpi_size =', mpi_size
+    WRITE(lunout,*) 'mpi_master =', mpi_master
+    WRITE(lunout,*) 'is_mpi_root =', is_mpi_root
+    WRITE(lunout,*) 'is_north_pole =', is_north_pole
+    WRITE(lunout,*) 'is_south_pole =', is_south_pole
+    WRITE(lunout,*) 'COMM_LMDZ_PHY =', COMM_LMDZ_PHY
+  
+  END SUBROUTINE print_module_data
+  
+END MODULE mod_phys_lmdz_mpi_data
Index: /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_mpi_transfert.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_mpi_transfert.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_mpi_transfert.F90	(revision 2408)
@@ -0,0 +1,1903 @@
+!
+!$Header$
+!
+MODULE mod_phys_lmdz_mpi_transfert
+
+
+  INTERFACE bcast_mpi
+    MODULE PROCEDURE bcast_mpi_c,                                                     &
+                     bcast_mpi_i,bcast_mpi_i1,bcast_mpi_i2,bcast_mpi_i3,bcast_mpi_i4, &
+                     bcast_mpi_r,bcast_mpi_r1,bcast_mpi_r2,bcast_mpi_r3,bcast_mpi_r4, &
+                     bcast_mpi_l,bcast_mpi_l1,bcast_mpi_l2,bcast_mpi_l3,bcast_mpi_l4
+  END INTERFACE
+
+  INTERFACE scatter_mpi
+    MODULE PROCEDURE scatter_mpi_i,scatter_mpi_i1,scatter_mpi_i2,scatter_mpi_i3, &
+                     scatter_mpi_r,scatter_mpi_r1,scatter_mpi_r2,scatter_mpi_r3, &
+                     scatter_mpi_l,scatter_mpi_l1,scatter_mpi_l2,scatter_mpi_l3
+  END INTERFACE
+
+  
+  INTERFACE gather_mpi
+    MODULE PROCEDURE gather_mpi_i,gather_mpi_i1,gather_mpi_i2,gather_mpi_i3, &
+                     gather_mpi_r,gather_mpi_r1,gather_mpi_r2,gather_mpi_r3, &
+                     gather_mpi_l,gather_mpi_l1,gather_mpi_l2,gather_mpi_l3  
+  END INTERFACE
+  
+  INTERFACE scatter2D_mpi
+    MODULE PROCEDURE scatter2D_mpi_i,scatter2D_mpi_i1,scatter2D_mpi_i2,scatter2D_mpi_i3, &
+                     scatter2D_mpi_r,scatter2D_mpi_r1,scatter2D_mpi_r2,scatter2D_mpi_r3, &
+                     scatter2D_mpi_l,scatter2D_mpi_l1,scatter2D_mpi_l2,scatter2D_mpi_l3
+  END INTERFACE
+
+  INTERFACE gather2D_mpi
+    MODULE PROCEDURE gather2D_mpi_i,gather2D_mpi_i1,gather2D_mpi_i2,gather2D_mpi_i3, &
+                     gather2D_mpi_r,gather2D_mpi_r1,gather2D_mpi_r2,gather2D_mpi_r3, &
+                     gather2D_mpi_l,gather2D_mpi_l1,gather2D_mpi_l2,gather2D_mpi_l3
+  END INTERFACE 
+  
+  INTERFACE reduce_sum_mpi
+    MODULE PROCEDURE reduce_sum_mpi_i,reduce_sum_mpi_i1,reduce_sum_mpi_i2,reduce_sum_mpi_i3,reduce_sum_mpi_i4, &
+                     reduce_sum_mpi_r,reduce_sum_mpi_r1,reduce_sum_mpi_r2,reduce_sum_mpi_r3,reduce_sum_mpi_r4
+  END INTERFACE 
+
+ INTERFACE grid1dTo2d_mpi
+    MODULE PROCEDURE grid1dTo2d_mpi_i,grid1dTo2d_mpi_i1,grid1dTo2d_mpi_i2,grid1dTo2d_mpi_i3, &
+                     grid1dTo2d_mpi_r,grid1dTo2d_mpi_r1,grid1dTo2d_mpi_r2,grid1dTo2d_mpi_r3, &
+                     grid1dTo2d_mpi_l,grid1dTo2d_mpi_l1,grid1dTo2d_mpi_l2,grid1dTo2d_mpi_l3
+ END INTERFACE 
+
+ INTERFACE grid2dTo1d_mpi
+    MODULE PROCEDURE grid2dTo1d_mpi_i,grid2dTo1d_mpi_i1,grid2dTo1d_mpi_i2,grid2dTo1d_mpi_i3, &
+                     grid2dTo1d_mpi_r,grid2dTo1d_mpi_r1,grid2dTo1d_mpi_r2,grid2dTo1d_mpi_r3, &
+                     grid2dTo1d_mpi_l,grid2dTo1d_mpi_l1,grid2dTo1d_mpi_l2,grid2dTo1d_mpi_l3
+ END INTERFACE 
+    
+CONTAINS
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Broadcast --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+!! -- Les chaine de charactère -- !!
+
+  SUBROUTINE bcast_mpi_c(var1)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(INOUT) :: Var1
+   
+    CALL bcast_mpi_cgen(Var1,len(Var1))
+
+  END SUBROUTINE bcast_mpi_c
+
+!! -- Les entiers -- !!
+  
+  SUBROUTINE bcast_mpi_i(var)
+  USE mod_phys_lmdz_mpi_data, ONLY : is_mpi_root
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var
+    
+    INTEGER               :: var_tmp(1)
+    
+    IF (is_mpi_root) var_tmp(1)=var
+    CALL bcast_mpi_igen(Var_tmp,1)
+    var=var_tmp(1)
+    
+  END SUBROUTINE bcast_mpi_i
+
+  SUBROUTINE bcast_mpi_i1(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:)
+
+    CALL bcast_mpi_igen(Var,size(Var))
+    
+  END SUBROUTINE bcast_mpi_i1
+
+  SUBROUTINE bcast_mpi_i2(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:)
+   
+    CALL bcast_mpi_igen(Var,size(Var))
+  
+  END SUBROUTINE bcast_mpi_i2
+
+  SUBROUTINE bcast_mpi_i3(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:,:)
+   
+    CALL bcast_mpi_igen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_i3
+
+  SUBROUTINE bcast_mpi_i4(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:,:,:)
+   
+    CALL bcast_mpi_igen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_i4
+
+
+!! -- Les reels -- !!
+
+  SUBROUTINE bcast_mpi_r(var)
+  USE mod_phys_lmdz_mpi_data, ONLY : is_mpi_root
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var
+    REAL               :: var_tmp(1)
+    
+    IF (is_mpi_root) var_tmp(1)=var
+    CALL bcast_mpi_rgen(Var_tmp,1)
+    var=var_tmp(1)   
+
+  END SUBROUTINE bcast_mpi_r
+
+  SUBROUTINE bcast_mpi_r1(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:)
+   
+    CALL bcast_mpi_rgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_r1
+
+  SUBROUTINE bcast_mpi_r2(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:)
+   
+    CALL bcast_mpi_rgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_r2
+
+  SUBROUTINE bcast_mpi_r3(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:,:)
+   
+    CALL bcast_mpi_rgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_r3
+
+  SUBROUTINE bcast_mpi_r4(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:,:,:)
+   
+    CALL bcast_mpi_rgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_r4
+  
+!! -- Les booleans -- !!
+
+  SUBROUTINE bcast_mpi_l(var)
+  USE mod_phys_lmdz_mpi_data, ONLY : is_mpi_root
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var
+    LOGICAL               :: var_tmp(1)
+    
+    IF (is_mpi_root) var_tmp(1)=var
+    CALL bcast_mpi_lgen(Var_tmp,1)
+    var=var_tmp(1)   
+
+  END SUBROUTINE bcast_mpi_l
+
+  SUBROUTINE bcast_mpi_l1(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:)
+   
+    CALL bcast_mpi_lgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_l1
+
+  SUBROUTINE bcast_mpi_l2(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:)
+   
+    CALL bcast_mpi_lgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_l2
+
+  SUBROUTINE bcast_mpi_l3(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:,:)
+   
+    CALL bcast_mpi_lgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_l3
+
+  SUBROUTINE bcast_mpi_l4(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:,:,:)
+   
+    CALL bcast_mpi_lgen(Var,size(Var))
+
+  END SUBROUTINE bcast_mpi_l4
+  
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Scatter   --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  SUBROUTINE scatter_mpi_i(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    CALL scatter_mpi_igen(VarIn,Varout,1)
+    
+  END SUBROUTINE scatter_mpi_i
+
+  SUBROUTINE scatter_mpi_i1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    CALL scatter_mpi_igen(VarIn,Varout,Size(VarOut,2))
+    
+  END SUBROUTINE scatter_mpi_i1
+  
+  SUBROUTINE scatter_mpi_i2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    CALL scatter_mpi_igen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3))
+
+  END SUBROUTINE scatter_mpi_i2
+
+  SUBROUTINE scatter_mpi_i3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    CALL scatter_mpi_igen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4))
+  
+  END SUBROUTINE scatter_mpi_i3
+
+
+  SUBROUTINE scatter_mpi_r(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+      CALL scatter_mpi_rgen(VarIn,Varout,1)
+  
+  END SUBROUTINE scatter_mpi_r
+
+  SUBROUTINE scatter_mpi_r1(VarIn, VarOut)
+  USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+  IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+      CALL scatter_mpi_rgen(VarIn,Varout,Size(VarOut,2))
+  
+  END SUBROUTINE scatter_mpi_r1
+  
+  SUBROUTINE scatter_mpi_r2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+      CALL scatter_mpi_rgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3))
+  
+  END SUBROUTINE scatter_mpi_r2
+
+  SUBROUTINE scatter_mpi_r3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+      CALL scatter_mpi_rgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4))
+  
+  END SUBROUTINE scatter_mpi_r3
+
+
+  SUBROUTINE scatter_mpi_l(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+      CALL scatter_mpi_lgen(VarIn,Varout,1)
+    
+  END SUBROUTINE scatter_mpi_l
+
+  SUBROUTINE scatter_mpi_l1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+      CALL scatter_mpi_lgen(VarIn,Varout,Size(VarOut,2))
+  
+  END SUBROUTINE scatter_mpi_l1
+  
+  SUBROUTINE scatter_mpi_l2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+      CALL scatter_mpi_lgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3))
+  
+  END SUBROUTINE scatter_mpi_l2
+
+  SUBROUTINE scatter_mpi_l3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+      CALL scatter_mpi_lgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4))
+  
+  END SUBROUTINE scatter_mpi_l3  
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Gather   --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ 
+!!!!! --> Les entiers
+
+  SUBROUTINE gather_mpi_i(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+      CALL gather_mpi_igen(VarIn,VarOut,1)
+  
+  END SUBROUTINE gather_mpi_i
+  
+
+!!!!!
+
+  SUBROUTINE gather_mpi_i1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+      CALL gather_mpi_igen(VarIn,VarOut,Size(VarIn,2))
+  
+  END SUBROUTINE gather_mpi_i1
+
+!!!!!
+  
+  SUBROUTINE gather_mpi_i2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+      CALL gather_mpi_igen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3))
+  
+  END SUBROUTINE gather_mpi_i2
+
+!!!!!
+
+  SUBROUTINE gather_mpi_i3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+      CALL gather_mpi_igen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4))
+  
+  END SUBROUTINE gather_mpi_i3
+
+!!!!! --> Les reels
+
+  SUBROUTINE gather_mpi_r(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+      CALL gather_mpi_rgen(VarIn,VarOut,1)
+  
+  END SUBROUTINE gather_mpi_r
+
+!!!!!
+
+  SUBROUTINE gather_mpi_r1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+      CALL gather_mpi_rgen(VarIn,VarOut,Size(VarIn,2))
+  
+  END SUBROUTINE gather_mpi_r1
+
+!!!!!
+  
+  SUBROUTINE gather_mpi_r2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+      CALL gather_mpi_rgen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3))
+  
+  END SUBROUTINE gather_mpi_r2
+
+!!!!!
+
+  SUBROUTINE gather_mpi_r3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+      CALL gather_mpi_rgen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4))
+  
+  END SUBROUTINE gather_mpi_r3
+
+!!!!! --> Les booleen
+
+  SUBROUTINE gather_mpi_l(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+      CALL gather_mpi_lgen(VarIn,VarOut,1)
+  
+  END SUBROUTINE gather_mpi_l
+
+!!!!!
+
+  SUBROUTINE gather_mpi_l1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+      CALL gather_mpi_lgen(VarIn,VarOut,Size(VarIn,2))
+  
+  END SUBROUTINE gather_mpi_l1
+
+!!!!!
+  
+  SUBROUTINE gather_mpi_l2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+      CALL gather_mpi_lgen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3))
+  
+  END SUBROUTINE gather_mpi_l2
+
+!!!!!
+
+  SUBROUTINE gather_mpi_l3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    CALL gather_mpi_lgen(VarIn,VarOut,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4))
+  
+  END SUBROUTINE gather_mpi_l3
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Scatter2D   --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  SUBROUTINE scatter2D_mpi_i(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    INTEGER,DIMENSION(klon_glo) :: Var_tmp    
+    
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_mpi_i
+
+  SUBROUTINE scatter2D_mpi_i1(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    INTEGER,DIMENSION(klon_glo,size(VarOut,2)) :: Var_tmp
+
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_mpi_i1
+
+  SUBROUTINE scatter2D_mpi_i2(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+
+    INTEGER,DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3)) :: Var_tmp
+
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_mpi_i2
+  
+  SUBROUTINE scatter2D_mpi_i3(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    INTEGER,DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3),size(VarOut,4)) :: Var_tmp
+
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+    
+  END SUBROUTINE scatter2D_mpi_i3
+
+
+
+  SUBROUTINE scatter2D_mpi_r(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    REAL,DIMENSION(klon_glo) :: Var_tmp    
+    
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_mpi_R
+
+
+  SUBROUTINE scatter2D_mpi_r1(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    REAL,DIMENSION(klon_glo,size(VarOut,2)) :: Var_tmp
+    
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_mpi_r1
+
+
+  SUBROUTINE scatter2D_mpi_r2(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+
+    REAL,DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3)) :: Var_tmp
+    
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_mpi_r2
+  
+  SUBROUTINE scatter2D_mpi_r3(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    REAL,DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3),size(VarOut,4)) :: Var_tmp
+
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+ 
+  END SUBROUTINE scatter2D_mpi_r3
+  
+  
+  SUBROUTINE scatter2D_mpi_l(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    LOGICAL,DIMENSION(klon_glo) :: Var_tmp    
+    
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_mpi_l
+
+
+  SUBROUTINE scatter2D_mpi_l1(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    LOGICAL,DIMENSION(klon_glo,size(VarOut,2)) :: Var_tmp
+
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+  
+  END SUBROUTINE scatter2D_mpi_l1
+
+
+  SUBROUTINE scatter2D_mpi_l2(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    LOGICAL, DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3)) :: Var_tmp
+  
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_mpi_l2
+  
+  SUBROUTINE scatter2D_mpi_l3(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    LOGICAL,DIMENSION(klon_glo,size(VarOut,2),size(VarOut,3),size(VarOut,4)) :: Var_tmp
+
+    CALL grid2dTo1d_glo(VarIn,Var_tmp)
+    CALL scatter_mpi(Var_tmp,VarOut)
+ 
+  END SUBROUTINE scatter2D_mpi_l3
+  
+  
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Gather2D   --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  SUBROUTINE gather2D_mpi_i(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    INTEGER,DIMENSION(klon_glo) :: Var_tmp
+    
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_i
+
+  SUBROUTINE gather2D_mpi_i1(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+
+    INTEGER,DIMENSION(klon_glo,size(VarOut,3)) :: Var_tmp
+
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_i1
+
+  SUBROUTINE gather2D_mpi_i2(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+
+    INTEGER,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4)) :: Var_tmp
+    
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_i2
+  
+  SUBROUTINE gather2D_mpi_i3(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
+ 
+    INTEGER,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4),SIZE(VarOut,5)) :: Var_tmp
+    
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_i3
+
+
+
+  SUBROUTINE gather2D_mpi_r(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    REAL,DIMENSION(klon_glo) :: Var_tmp
+    
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_r
+
+  SUBROUTINE gather2D_mpi_r1(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    REAL,DIMENSION(klon_glo,size(VarOut,3)) :: Var_tmp
+
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_r1
+
+  SUBROUTINE gather2D_mpi_r2(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    REAL,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4)) :: Var_tmp
+
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_r2
+  
+  SUBROUTINE gather2D_mpi_r3(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
+    
+    REAL,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4),SIZE(VarOut,5)) :: Var_tmp
+    
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_r3
+
+  
+  
+  SUBROUTINE gather2D_mpi_l(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    LOGICAL,DIMENSION(klon_glo) :: Var_tmp
+    
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_l
+
+  SUBROUTINE gather2D_mpi_l1(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    LOGICAL,DIMENSION(klon_glo,size(VarOut,3)) :: Var_tmp
+
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_l1
+
+  SUBROUTINE gather2D_mpi_l2(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    LOGICAL,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4)) :: Var_tmp
+
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_l2
+  
+  SUBROUTINE gather2D_mpi_l3(VarIn, VarOut)
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
+    
+    LOGICAL,DIMENSION(klon_glo,size(VarOut,3),SIZE(VarOut,4),SIZE(VarOut,5)) :: Var_tmp
+    
+    CALL gather_mpi(VarIn,Var_tmp)
+    CALL grid1dTo2d_glo(Var_tmp,VarOut)
+
+  END SUBROUTINE gather2D_mpi_l3
+  
+  
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des reduce_sum   --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  SUBROUTINE reduce_sum_mpi_i(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN)  :: VarIn
+    INTEGER,INTENT(OUT) :: VarOut
+    INTEGER             :: VarIn_tmp(1)
+    INTEGER             :: VarOut_tmp(1)
+    
+    VarIn_tmp(1)=VarIn    
+    CALL reduce_sum_mpi_igen(VarIn_tmp,Varout_tmp,1)
+    VarOut=VarOut_tmp(1)
+    
+  END SUBROUTINE reduce_sum_mpi_i
+
+  SUBROUTINE reduce_sum_mpi_i1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+    CALL reduce_sum_mpi_igen(VarIn,Varout,SIZE(VarIn))
+  
+  END SUBROUTINE reduce_sum_mpi_i1
+
+  SUBROUTINE reduce_sum_mpi_i2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    CALL reduce_sum_mpi_igen(VarIn,Varout,SIZE(VarIn))
+  
+  END SUBROUTINE reduce_sum_mpi_i2
+
+  SUBROUTINE reduce_sum_mpi_i3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    CALL reduce_sum_mpi_igen(VarIn,Varout,SIZE(VarIn))
+  
+  END SUBROUTINE reduce_sum_mpi_i3
+
+  SUBROUTINE reduce_sum_mpi_i4(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    CALL reduce_sum_mpi_igen(VarIn,Varout,SIZE(VarIn))
+  
+  END SUBROUTINE reduce_sum_mpi_i4                  
+  
+  
+  SUBROUTINE reduce_sum_mpi_r(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN)  :: VarIn
+    REAL,INTENT(OUT) :: VarOut
+    REAL             :: VarIn_tmp(1)
+    REAL             :: VarOut_tmp(1)
+    
+    VarIn_tmp(1)=VarIn    
+    CALL reduce_sum_mpi_rgen(VarIn_tmp,Varout_tmp,1)
+    VarOut=VarOut_tmp(1)
+  
+  END SUBROUTINE reduce_sum_mpi_r
+
+  SUBROUTINE reduce_sum_mpi_r1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+    CALL reduce_sum_mpi_rgen(VarIn,Varout,SIZE(VarIn))
+     
+  END SUBROUTINE reduce_sum_mpi_r1
+
+  SUBROUTINE reduce_sum_mpi_r2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    CALL reduce_sum_mpi_rgen(VarIn,Varout,SIZE(VarIn))
+  
+  END SUBROUTINE reduce_sum_mpi_r2
+
+  SUBROUTINE reduce_sum_mpi_r3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    CALL reduce_sum_mpi_rgen(VarIn,Varout,SIZE(VarIn))
+  
+  END SUBROUTINE reduce_sum_mpi_r3
+
+  SUBROUTINE reduce_sum_mpi_r4(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    CALL reduce_sum_mpi_rgen(VarIn,Varout,SIZE(VarIn))
+  
+  END SUBROUTINE reduce_sum_mpi_r4 
+  
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! SUBROUTINE grid1dTo2d  !!  
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+
+  SUBROUTINE grid1dTo2d_mpi_i(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:)     :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_igen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid1dTo2d_mpi_i
+  
+
+  SUBROUTINE grid1dTo2d_mpi_i1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:)     :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_igen(VarIn,VarOut,size(VarIn,2))
+  
+  END SUBROUTINE grid1dTo2d_mpi_i1
+
+  SUBROUTINE grid1dTo2d_mpi_i2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_igen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
+  
+  END SUBROUTINE grid1dTo2d_mpi_i2
+  
+  SUBROUTINE grid1dTo2d_mpi_i3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_igen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid1dTo2d_mpi_i3
+
+
+  SUBROUTINE grid1dTo2d_mpi_r(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:)     :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_rgen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid1dTo2d_mpi_r
+  
+
+  SUBROUTINE grid1dTo2d_mpi_r1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:)     :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_rgen(VarIn,VarOut,size(VarIn,2))
+  
+  END SUBROUTINE grid1dTo2d_mpi_r1
+
+  SUBROUTINE grid1dTo2d_mpi_r2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_rgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
+  
+  END SUBROUTINE grid1dTo2d_mpi_r2
+  
+  SUBROUTINE grid1dTo2d_mpi_r3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_rgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid1dTo2d_mpi_r3
+  
+  
+  
+  SUBROUTINE grid1dTo2d_mpi_l(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:)     :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_lgen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid1dTo2d_mpi_l
+  
+
+  SUBROUTINE grid1dTo2d_mpi_l1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:)     :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_lgen(VarIn,VarOut,size(VarIn,2))
+  
+  END SUBROUTINE grid1dTo2d_mpi_l1
+
+  SUBROUTINE grid1dTo2d_mpi_l2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:)     :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_lgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3))
+  
+  END SUBROUTINE grid1dTo2d_mpi_l2
+  
+  SUBROUTINE grid1dTo2d_mpi_l3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:)     :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:,:)  :: VarOut
+    
+    CALL grid1dTo2d_mpi_lgen(VarIn,VarOut,size(VarIn,2)*size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid1dTo2d_mpi_l3
+
+
+  SUBROUTINE grid2dTo1d_mpi_i(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_igen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid2dTo1d_mpi_i
+  
+
+  SUBROUTINE grid2dTo1d_mpi_i1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_igen(VarIn,VarOut,size(VarIn,3))
+  
+  END SUBROUTINE grid2dTo1d_mpi_i1
+
+  SUBROUTINE grid2dTo1d_mpi_i2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_igen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid2dTo1d_mpi_i2
+  
+  SUBROUTINE grid2dTo1d_mpi_i3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_igen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
+  
+  END SUBROUTINE grid2dTo1d_mpi_i3
+ 
+
+
+
+  SUBROUTINE grid2dTo1d_mpi_r(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_rgen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid2dTo1d_mpi_r
+  
+
+  SUBROUTINE grid2dTo1d_mpi_r1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_rgen(VarIn,VarOut,size(VarIn,3))
+  
+  END SUBROUTINE grid2dTo1d_mpi_r1
+
+  SUBROUTINE grid2dTo1d_mpi_r2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_rgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid2dTo1d_mpi_r2
+  
+  SUBROUTINE grid2dTo1d_mpi_r3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_rgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
+  
+  END SUBROUTINE grid2dTo1d_mpi_r3
+
+
+
+  SUBROUTINE grid2dTo1d_mpi_l(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_lgen(VarIn,VarOut,1)
+  
+  END SUBROUTINE grid2dTo1d_mpi_l
+  
+
+  SUBROUTINE grid2dTo1d_mpi_l1(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_lgen(VarIn,VarOut,size(VarIn,3))
+  
+  END SUBROUTINE grid2dTo1d_mpi_l1
+
+
+
+  SUBROUTINE grid2dTo1d_mpi_l2(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_lgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4))
+  
+  END SUBROUTINE grid2dTo1d_mpi_l2
+
+  
+  SUBROUTINE grid2dTo1d_mpi_l3(VarIn,VarOut)  
+  IMPLICIT NONE  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:)  :: VarOut
+    
+    CALL grid2dTo1d_mpi_lgen(VarIn,VarOut,size(VarIn,3)*size(VarIn,4)*size(VarIn,5))
+  
+  END SUBROUTINE grid2dTo1d_mpi_l3
+
+               
+
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! DEFINITION DES FONCTIONS DE TRANSFERT GENERIQUES !
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  SUBROUTINE bcast_mpi_cgen(var,nb)
+    USE mod_phys_lmdz_mpi_data 
+    IMPLICIT NONE
+    
+    CHARACTER(LEN=*),INTENT(INOUT) :: Var
+    INTEGER,INTENT(IN) :: nb
+    
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+    INTEGER :: ierr
+
+    IF (.not.is_using_mpi) RETURN
+    
+#ifdef CPP_MPI
+    CALL MPI_BCAST(Var,nb,MPI_CHARACTER,mpi_master,COMM_LMDZ_PHY,ierr)
+#endif
+        
+  END SUBROUTINE bcast_mpi_cgen
+
+
+      
+  SUBROUTINE bcast_mpi_igen(var,nb)
+    USE mod_phys_lmdz_mpi_data
+    IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: nb
+    INTEGER,DIMENSION(nb),INTENT(INOUT) :: Var
+    
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+    INTEGER :: ierr
+
+    IF (.not.is_using_mpi) RETURN
+
+#ifdef CPP_MPI
+    CALL MPI_BCAST(Var,nb,MPI_INTEGER,mpi_master,COMM_LMDZ_PHY,ierr)
+#endif
+        
+  END SUBROUTINE bcast_mpi_igen
+
+
+
+  
+  SUBROUTINE bcast_mpi_rgen(var,nb)
+    USE mod_phys_lmdz_mpi_data
+    IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: nb
+    REAL,DIMENSION(nb),INTENT(INOUT) :: Var
+    
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+    INTEGER :: ierr
+
+    IF (.not.is_using_mpi) RETURN
+
+#ifdef CPP_MPI
+    CALL MPI_BCAST(Var,nb,MPI_REAL_LMDZ,mpi_master,COMM_LMDZ_PHY,ierr)
+#endif
+    
+  END SUBROUTINE bcast_mpi_rgen
+  
+
+
+
+  SUBROUTINE bcast_mpi_lgen(var,nb)
+    USE mod_phys_lmdz_mpi_data
+    IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: nb
+    LOGICAL,DIMENSION(nb),INTENT(INOUT) :: Var
+    
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+    INTEGER :: ierr
+
+    IF (.not.is_using_mpi) RETURN
+
+#ifdef CPP_MPI
+    CALL MPI_BCAST(Var,nb,MPI_LOGICAL,mpi_master,COMM_LMDZ_PHY,ierr)
+#endif
+
+  END SUBROUTINE bcast_mpi_lgen
+
+  
+
+  SUBROUTINE scatter_mpi_igen(VarIn, VarOut, dimsize)
+    USE mod_phys_lmdz_mpi_data 
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN) :: dimsize
+    INTEGER,INTENT(IN),DIMENSION(klon_glo,dimsize) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
+  
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+    INTEGER,DIMENSION(0:mpi_size-1) :: displs
+    INTEGER,DIMENSION(0:mpi_size-1) :: counts
+    INTEGER,DIMENSION(dimsize*klon_glo) :: VarTmp
+    INTEGER :: nb,i,index,rank
+    INTEGER :: ierr
+
+
+    IF (.not.is_using_mpi) THEN
+      VarOut(:,:)=VarIn(:,:)
+      RETURN
+    ENDIF
+
+    
+    IF (is_mpi_root) THEN
+      Index=1
+      DO rank=0,mpi_size-1
+        nb=klon_mpi_para_nb(rank)
+        displs(rank)=Index-1
+        counts(rank)=nb*dimsize
+        DO i=1,dimsize
+          VarTmp(Index:Index+nb-1)=VarIn(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)
+          Index=Index+nb
+        ENDDO
+      ENDDO
+    ENDIF
+      
+#ifdef CPP_MPI 
+    CALL MPI_SCATTERV(VarTmp,counts,displs,MPI_INTEGER,VarOut,klon_mpi*dimsize,   &
+                      MPI_INTEGER,mpi_master, COMM_LMDZ_PHY,ierr)
+#endif
+
+  END SUBROUTINE scatter_mpi_igen
+
+  SUBROUTINE scatter_mpi_rgen(VarIn, VarOut, dimsize)
+    USE mod_phys_lmdz_mpi_data 
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN) :: dimsize
+    REAL,INTENT(IN),DIMENSION(klon_glo,dimsize) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
+  
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+
+    INTEGER,DIMENSION(0:mpi_size-1) :: displs
+    INTEGER,DIMENSION(0:mpi_size-1) :: counts
+    REAL,DIMENSION(dimsize*klon_glo) :: VarTmp
+    INTEGER :: nb,i,index,rank
+    INTEGER :: ierr
+
+    IF (.not.is_using_mpi) THEN
+      VarOut(:,:)=VarIn(:,:)
+      RETURN
+    ENDIF
+    
+    IF (is_mpi_root) THEN
+      Index=1
+      DO rank=0,mpi_size-1
+        nb=klon_mpi_para_nb(rank)
+        displs(rank)=Index-1
+        counts(rank)=nb*dimsize
+        DO i=1,dimsize
+          VarTmp(Index:Index+nb-1)=VarIn(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)
+          Index=Index+nb
+        ENDDO
+      ENDDO
+    ENDIF
+      
+#ifdef CPP_MPI 
+    CALL MPI_SCATTERV(VarTmp,counts,displs,MPI_REAL_LMDZ,VarOut,klon_mpi*dimsize,   &
+                      MPI_REAL_LMDZ,mpi_master, COMM_LMDZ_PHY,ierr)
+
+#endif
+
+  END SUBROUTINE scatter_mpi_rgen
+
+  
+  SUBROUTINE scatter_mpi_lgen(VarIn, VarOut, dimsize)
+    USE mod_phys_lmdz_mpi_data 
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN) :: dimsize
+    LOGICAL,INTENT(IN),DIMENSION(klon_glo,dimsize) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
+  
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+
+    INTEGER,DIMENSION(0:mpi_size-1) :: displs
+    INTEGER,DIMENSION(0:mpi_size-1) :: counts
+    LOGICAL,DIMENSION(dimsize*klon_glo) :: VarTmp
+    INTEGER :: nb,i,index,rank
+    INTEGER :: ierr
+
+    IF (.not.is_using_mpi) THEN
+      VarOut(:,:)=VarIn(:,:)
+      RETURN
+    ENDIF
+    
+    IF (is_mpi_root) THEN
+      Index=1
+      DO rank=0,mpi_size-1
+        nb=klon_mpi_para_nb(rank)
+        displs(rank)=Index-1
+        counts(rank)=nb*dimsize
+        DO i=1,dimsize
+          VarTmp(Index:Index+nb-1)=VarIn(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)
+          Index=Index+nb
+        ENDDO
+      ENDDO
+    ENDIF
+      
+#ifdef CPP_MPI
+    CALL MPI_SCATTERV(VarTmp,counts,displs,MPI_LOGICAL,VarOut,klon_mpi*dimsize,   &
+                      MPI_LOGICAL,mpi_master, COMM_LMDZ_PHY,ierr)
+#endif
+
+  END SUBROUTINE scatter_mpi_lgen  
+
+
+
+
+  SUBROUTINE gather_mpi_igen(VarIn, VarOut, dimsize)
+    USE mod_phys_lmdz_mpi_data
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+    
+    INTEGER,INTENT(IN) :: dimsize
+    INTEGER,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(klon_glo,dimsize) :: VarOut
+  
+    INTEGER,DIMENSION(0:mpi_size-1) :: displs
+    INTEGER,DIMENSION(0:mpi_size-1) :: counts
+    INTEGER,DIMENSION(dimsize*klon_glo) :: VarTmp
+    INTEGER :: nb,i,index,rank
+    INTEGER :: ierr
+
+    IF (.not.is_using_mpi) THEN
+      VarOut(:,:)=VarIn(:,:)
+      RETURN
+    ENDIF
+
+    IF (is_mpi_root) THEN
+      Index=1
+      DO rank=0,mpi_size-1
+        nb=klon_mpi_para_nb(rank)
+        displs(rank)=Index-1
+        counts(rank)=nb*dimsize
+        Index=Index+nb*dimsize
+      ENDDO
+     
+    ENDIF
+    
+#ifdef CPP_MPI
+    CALL MPI_GATHERV(VarIn,klon_mpi*dimsize,MPI_INTEGER,VarTmp,counts,displs,   &
+                     MPI_INTEGER,mpi_master, COMM_LMDZ_PHY,ierr)
+#endif
+
+                          
+    IF (is_mpi_root) THEN
+      Index=1
+      DO rank=0,mpi_size-1
+        nb=klon_mpi_para_nb(rank)
+        DO i=1,dimsize
+          VarOut(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)=VarTmp(Index:Index+nb-1)
+          Index=Index+nb
+        ENDDO
+      ENDDO
+    ENDIF
+
+  END SUBROUTINE gather_mpi_igen  
+
+  SUBROUTINE gather_mpi_rgen(VarIn, VarOut, dimsize)
+    USE mod_phys_lmdz_mpi_data 
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+    
+    INTEGER,INTENT(IN) :: dimsize
+    REAL,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(klon_glo,dimsize) :: VarOut
+  
+    INTEGER,DIMENSION(0:mpi_size-1) :: displs
+    INTEGER,DIMENSION(0:mpi_size-1) :: counts
+    REAL,DIMENSION(dimsize*klon_glo) :: VarTmp
+    INTEGER :: nb,i,index,rank
+    INTEGER :: ierr
+
+    IF (is_mpi_root) THEN
+      Index=1
+      DO rank=0,mpi_size-1
+        nb=klon_mpi_para_nb(rank)
+        displs(rank)=Index-1
+        counts(rank)=nb*dimsize
+        Index=Index+nb*dimsize
+      ENDDO
+    ENDIF
+    
+    IF (.not.is_using_mpi) THEN
+      VarOut(:,:)=VarIn(:,:)
+      RETURN
+    ENDIF
+
+#ifdef CPP_MPI
+    CALL MPI_GATHERV(VarIn,klon_mpi*dimsize,MPI_REAL_LMDZ,VarTmp,counts,displs,   &
+                      MPI_REAL_LMDZ,mpi_master, COMM_LMDZ_PHY,ierr)
+#endif
+                          
+    IF (is_mpi_root) THEN
+      Index=1
+      DO rank=0,mpi_size-1
+        nb=klon_mpi_para_nb(rank)
+        DO i=1,dimsize
+          VarOut(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)=VarTmp(Index:Index+nb-1)
+          Index=Index+nb
+        ENDDO
+      ENDDO
+    ENDIF
+
+  END SUBROUTINE gather_mpi_rgen  
+
+  SUBROUTINE gather_mpi_lgen(VarIn, VarOut, dimsize)
+    USE mod_phys_lmdz_mpi_data
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN) :: dimsize
+    LOGICAL,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(klon_glo,dimsize) :: VarOut
+  
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+
+    INTEGER,DIMENSION(0:mpi_size-1) :: displs
+    INTEGER,DIMENSION(0:mpi_size-1) :: counts
+    LOGICAL,DIMENSION(dimsize*klon_glo) :: VarTmp
+    INTEGER :: nb,i,index,rank
+    INTEGER :: ierr
+    
+    IF (.not.is_using_mpi) THEN
+      VarOut(:,:)=VarIn(:,:)
+      RETURN
+    ENDIF
+
+    IF (is_mpi_root) THEN
+      Index=1
+      DO rank=0,mpi_size-1
+        nb=klon_mpi_para_nb(rank)
+        displs(rank)=Index-1
+        counts(rank)=nb*dimsize
+        Index=Index+nb*dimsize
+      ENDDO
+    ENDIF
+    
+
+#ifdef CPP_MPI
+    CALL MPI_GATHERV(VarIn,klon_mpi*dimsize,MPI_LOGICAL,VarTmp,counts,displs,   &
+                      MPI_LOGICAL,mpi_master, COMM_LMDZ_PHY,ierr)
+#endif
+                          
+    IF (is_mpi_root) THEN
+      Index=1
+      DO rank=0,mpi_size-1
+        nb=klon_mpi_para_nb(rank)
+        DO i=1,dimsize
+          VarOut(klon_mpi_para_begin(rank):klon_mpi_para_end(rank),i)=VarTmp(Index:Index+nb-1)
+          Index=Index+nb
+        ENDDO
+      ENDDO
+    ENDIF
+
+  END SUBROUTINE gather_mpi_lgen
+  
+
+
+  SUBROUTINE reduce_sum_mpi_igen(VarIn,VarOut,nb)
+    USE mod_phys_lmdz_mpi_data 
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+    
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+   
+    INTEGER,INTENT(IN) :: nb
+    INTEGER,DIMENSION(nb),INTENT(IN) :: VarIn
+    INTEGER,DIMENSION(nb),INTENT(OUT) :: VarOut    
+    INTEGER :: ierr
+   
+    IF (.not.is_using_mpi) THEN
+      VarOut(:)=VarIn(:)
+      RETURN
+    ENDIF
+
+
+#ifdef CPP_MPI
+    CALL MPI_REDUCE(VarIn,VarOut,nb,MPI_INTEGER,MPI_SUM,mpi_master,COMM_LMDZ_PHY,ierr)
+#endif
+            
+  END SUBROUTINE reduce_sum_mpi_igen
+  
+  SUBROUTINE reduce_sum_mpi_rgen(VarIn,VarOut,nb)
+    USE mod_phys_lmdz_mpi_data 
+    USE mod_grid_phy_lmdz
+
+    IMPLICIT NONE
+
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif
+    
+    INTEGER,INTENT(IN) :: nb
+    REAL,DIMENSION(nb),INTENT(IN) :: VarIn
+    REAL,DIMENSION(nb),INTENT(OUT) :: VarOut    
+    INTEGER :: ierr
+ 
+    IF (.not.is_using_mpi) THEN
+      VarOut(:)=VarIn(:)
+      RETURN
+    ENDIF
+   
+#ifdef CPP_MPI
+    CALL MPI_REDUCE(VarIn,VarOut,nb,MPI_REAL_LMDZ,MPI_SUM,mpi_master,COMM_LMDZ_PHY,ierr)
+#endif
+        
+  END SUBROUTINE reduce_sum_mpi_rgen
+
+
+
+  SUBROUTINE grid1dTo2d_mpi_igen(VarIn,VarOut,dimsize)
+    USE mod_phys_lmdz_mpi_data
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: dimsize
+    INTEGER,INTENT(IN) ,DIMENSION(klon_mpi,dimsize)       :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(nbp_lon*jj_nb,dimsize)  :: VarOut
+    INTEGER :: i,ij,Offset
+
+    
+    VarOut(1:nbp_lon,:)=0
+    VarOut(nbp_lon*(jj_nb-1)+1:nbp_lon*jj_nb,:)=0
+    
+    offset=ii_begin
+    IF (is_north_pole) Offset=nbp_lon
+    
+    
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        VarOut(ij+offset-1,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO
+    
+    
+    IF (is_north_pole) THEN 
+      DO i=1,dimsize
+        DO ij=1,nbp_lon
+         VarOut(ij,i)=VarIn(1,i)
+        ENDDO
+      ENDDO
+    ENDIF
+    
+    IF (is_south_pole) THEN 
+      DO i=1,dimsize
+        DO ij=nbp_lon*(jj_nb-1)+1,nbp_lon*jj_nb
+         VarOut(ij,i)=VarIn(klon_mpi,i)
+        ENDDO
+      ENDDO
+    ENDIF
+
+  END SUBROUTINE grid1dTo2d_mpi_igen   
+
+
+  SUBROUTINE grid1dTo2d_mpi_rgen(VarIn,VarOut,dimsize)
+    USE mod_phys_lmdz_mpi_data
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: dimsize
+    REAL,INTENT(IN) ,DIMENSION(klon_mpi,dimsize)       :: VarIn
+    REAL,INTENT(OUT),DIMENSION(nbp_lon*jj_nb,dimsize)  :: VarOut
+    INTEGER :: i,ij,Offset
+
+    
+    VarOut(1:nbp_lon,:)=0
+    VarOut(nbp_lon*(jj_nb-1)+1:nbp_lon*jj_nb,:)=0
+    
+    offset=ii_begin
+    IF (is_north_pole) Offset=nbp_lon
+    
+    
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        VarOut(ij+offset-1,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO
+    
+    
+    IF (is_north_pole) THEN 
+      DO i=1,dimsize
+        DO ij=1,nbp_lon
+         VarOut(ij,i)=VarIn(1,i)
+        ENDDO
+      ENDDO
+    ENDIF
+    
+    IF (is_south_pole) THEN 
+      DO i=1,dimsize
+        DO ij=nbp_lon*(jj_nb-1)+1,nbp_lon*jj_nb
+         VarOut(ij,i)=VarIn(klon_mpi,i)
+        ENDDO
+      ENDDO
+    ENDIF
+
+   END SUBROUTINE grid1dTo2d_mpi_rgen   
+
+
+
+  SUBROUTINE grid1dTo2d_mpi_lgen(VarIn,VarOut,dimsize)
+    USE mod_phys_lmdz_mpi_data
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: dimsize
+    LOGICAL,INTENT(IN) ,DIMENSION(klon_mpi,dimsize)       :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(nbp_lon*jj_nb,dimsize)  :: VarOut
+    INTEGER :: i,ij,Offset
+
+    
+    VarOut(1:nbp_lon,:)=.FALSE.
+    VarOut(nbp_lon*(jj_nb-1)+1:nbp_lon*jj_nb,:)=.FALSE.
+    
+    offset=ii_begin
+    IF (is_north_pole) Offset=nbp_lon
+    
+    
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        VarOut(ij+offset-1,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO
+    
+    
+    IF (is_north_pole) THEN 
+      DO i=1,dimsize
+        DO ij=1,nbp_lon
+         VarOut(ij,i)=VarIn(1,i)
+        ENDDO
+      ENDDO
+    ENDIF
+    
+    IF (is_south_pole) THEN 
+      DO i=1,dimsize
+        DO ij=nbp_lon*(jj_nb-1)+1,nbp_lon*jj_nb
+         VarOut(ij,i)=VarIn(klon_mpi,i)
+        ENDDO
+      ENDDO
+    ENDIF
+
+   END SUBROUTINE grid1dTo2d_mpi_lgen   
+
+  
+
+
+  SUBROUTINE grid2dTo1d_mpi_igen(VarIn,VarOut,dimsize)
+    USE mod_phys_lmdz_mpi_data
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: dimsize
+    INTEGER,INTENT(IN) ,DIMENSION(nbp_lon*jj_nb,dimsize) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(klon_mpi,dimsize)      :: VarOut
+    INTEGER :: i,ij,offset
+
+    offset=ii_begin
+    IF (is_north_pole) offset=nbp_lon
+
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        VarOut(ij,i)=VarIn(ij+offset-1,i)
+      ENDDO
+    ENDDO
+
+    IF (is_north_pole) THEN 
+      DO i=1,dimsize
+        VarOut(1,i)=VarIn(1,i)
+      ENDDO
+    ENDIF
+    
+    
+  END SUBROUTINE grid2dTo1d_mpi_igen   
+
+
+
+  SUBROUTINE grid2dTo1d_mpi_rgen(VarIn,VarOut,dimsize)
+    USE mod_phys_lmdz_mpi_data
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: dimsize
+    REAL,INTENT(IN) ,DIMENSION(nbp_lon*jj_nb,dimsize) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize)      :: VarOut
+    INTEGER :: i,ij,offset
+
+    offset=ii_begin
+    IF (is_north_pole) offset=nbp_lon
+
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        VarOut(ij,i)=VarIn(ij+offset-1,i)
+      ENDDO
+    ENDDO
+
+    IF (is_north_pole) THEN 
+      DO i=1,dimsize
+         VarOut(1,i)=VarIn(1,i)
+      ENDDO
+    ENDIF
+    
+    
+  END SUBROUTINE grid2dTo1d_mpi_rgen   
+  
+
+  SUBROUTINE grid2dTo1d_mpi_lgen(VarIn,VarOut,dimsize)
+    USE mod_phys_lmdz_mpi_data
+    USE mod_grid_phy_lmdz
+    IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: dimsize
+    LOGICAL,INTENT(IN) ,DIMENSION(nbp_lon*jj_nb,dimsize) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize)      :: VarOut
+    INTEGER :: i,ij,offset
+
+    offset=ii_begin
+    IF (is_north_pole) offset=nbp_lon
+
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        VarOut(ij,i)=VarIn(ij+offset-1,i)
+      ENDDO
+    ENDDO
+
+    IF (is_north_pole) THEN 
+      DO i=1,dimsize
+        VarOut(1,i)=VarIn(1,i)
+      ENDDO
+    ENDIF
+    
+    
+  END SUBROUTINE grid2dTo1d_mpi_lgen   
+
+END MODULE mod_phys_lmdz_mpi_transfert
+
Index: /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_omp_data.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_omp_data.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_omp_data.F90	(revision 2408)
@@ -0,0 +1,109 @@
+!
+!$Id$
+!
+MODULE mod_phys_lmdz_omp_data
+
+  INTEGER,SAVE :: omp_size
+  INTEGER,SAVE :: omp_rank
+  LOGICAL,SAVE :: is_omp_root
+  LOGICAL,SAVE :: is_using_omp
+  
+  INTEGER,SAVE,DIMENSION(:),ALLOCATABLE :: klon_omp_para_nb
+  INTEGER,SAVE,DIMENSION(:),ALLOCATABLE :: klon_omp_para_begin
+  INTEGER,SAVE,DIMENSION(:),ALLOCATABLE :: klon_omp_para_end    
+  
+  INTEGER,SAVE :: klon_omp
+  INTEGER,SAVE :: klon_omp_begin
+  INTEGER,SAVE :: klon_omp_end
+!$OMP  THREADPRIVATE(omp_rank,klon_omp,is_omp_root,klon_omp_begin,klon_omp_end)
+
+CONTAINS
+  
+  SUBROUTINE Init_phys_lmdz_omp_data(klon_mpi)
+    USE dimphy
+    IMPLICIT NONE
+    INTEGER, INTENT(in) :: klon_mpi
+
+    INTEGER :: i
+
+    CHARACTER (LEN=20) :: modname='Init_phys_lmdz_omp_data'
+    CHARACTER (LEN=80) :: abort_message
+
+
+#ifdef CPP_OMP    
+    INTEGER :: OMP_GET_NUM_THREADS
+    EXTERNAL OMP_GET_NUM_THREADS
+    INTEGER :: OMP_GET_THREAD_NUM
+    EXTERNAL OMP_GET_THREAD_NUM
+#endif  
+
+#ifdef CPP_OMP
+!$OMP MASTER
+        is_using_omp=.TRUE.
+        omp_size=OMP_GET_NUM_THREADS()
+!$OMP END MASTER
+        omp_rank=OMP_GET_THREAD_NUM()    
+#else    
+    is_using_omp=.FALSE.
+    omp_size=1
+    omp_rank=0
+#endif
+
+   is_omp_root=.FALSE.
+!$OMP MASTER
+   IF (omp_rank==0) THEN
+     is_omp_root=.TRUE.
+   ELSE
+     abort_message = 'ANORMAL : OMP_MASTER /= 0'
+     CALL abort_gcm (modname,abort_message,1)
+   ENDIF
+!$OMP END MASTER
+
+
+!$OMP MASTER 
+    ALLOCATE(klon_omp_para_nb(0:omp_size-1))
+    ALLOCATE(klon_omp_para_begin(0:omp_size-1))
+    ALLOCATE(klon_omp_para_end(0:omp_size-1))
+    
+    DO i=0,omp_size-1
+      klon_omp_para_nb(i)=klon_mpi/omp_size
+      IF (i<MOD(klon_mpi,omp_size)) klon_omp_para_nb(i)=klon_omp_para_nb(i)+1
+    ENDDO
+    
+    klon_omp_para_begin(0) = 1
+    klon_omp_para_end(0) = klon_omp_para_nb(0)
+    
+    DO i=1,omp_size-1
+      klon_omp_para_begin(i)=klon_omp_para_end(i-1)+1
+      klon_omp_para_end(i)=klon_omp_para_begin(i)+klon_omp_para_nb(i)-1
+    ENDDO
+!$OMP END MASTER
+!$OMP BARRIER
+   
+    klon_omp=klon_omp_para_nb(omp_rank)
+    klon_omp_begin=klon_omp_para_begin(omp_rank)
+    klon_omp_end=klon_omp_para_end(omp_rank)
+    
+    CALL Print_module_data
+    
+  END SUBROUTINE Init_phys_lmdz_omp_data
+
+  SUBROUTINE Print_module_data
+  IMPLICIT NONE
+  INCLUDE "iniprint.h"
+
+!$OMP CRITICAL  
+  WRITE(lunout,*)'--------> TASK ',omp_rank
+  WRITE(lunout,*)'omp_size =',omp_size
+  WRITE(lunout,*)'omp_rank =',omp_rank
+  WRITE(lunout,*)'is_omp_root =',is_omp_root
+  WRITE(lunout,*)'klon_omp_para_nb =',klon_omp_para_nb
+  WRITE(lunout,*)'klon_omp_para_begin =',klon_omp_para_begin
+  WRITE(lunout,*)'klon_omp_para_end =',klon_omp_para_end    
+  WRITE(lunout,*)'klon_omp =',klon_omp
+  WRITE(lunout,*)'klon_omp_begin =',klon_omp_begin
+  WRITE(lunout,*)'klon_omp_end =',klon_omp_end    
+!$OMP END CRITICAL
+
+  END SUBROUTINE Print_module_data
+END MODULE mod_phys_lmdz_omp_data
Index: /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_omp_transfert.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_omp_transfert.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_omp_transfert.F90	(revision 2408)
@@ -0,0 +1,1064 @@
+!
+!$Header$
+!
+MODULE mod_phys_lmdz_omp_transfert
+
+  PRIVATE
+  
+  INTEGER,PARAMETER :: grow_factor=1.5
+  INTEGER,PARAMETER :: size_min=1024
+  
+  CHARACTER(LEN=size_min),SAVE            :: buffer_c
+!  INTEGER,SAVE                            :: size_c=0
+  INTEGER,SAVE,ALLOCATABLE,DIMENSION(:)   :: buffer_i
+  INTEGER,SAVE                            :: size_i=0
+  REAL,SAVE,ALLOCATABLE,DIMENSION(:)      :: buffer_r
+  INTEGER,SAVE                            :: size_r=0
+  LOGICAL,SAVE,ALLOCATABLE,DIMENSION(:)   :: buffer_l
+  INTEGER,SAVE                            :: size_l=0
+
+
+  
+  
+  INTERFACE bcast_omp
+    MODULE PROCEDURE bcast_omp_c,                                                     &
+                     bcast_omp_i,bcast_omp_i1,bcast_omp_i2,bcast_omp_i3,bcast_omp_i4, &
+                     bcast_omp_r,bcast_omp_r1,bcast_omp_r2,bcast_omp_r3,bcast_omp_r4, &
+                     bcast_omp_l,bcast_omp_l1,bcast_omp_l2,bcast_omp_l3,bcast_omp_l4
+  END INTERFACE
+
+  INTERFACE scatter_omp
+    MODULE PROCEDURE scatter_omp_i,scatter_omp_i1,scatter_omp_i2,scatter_omp_i3, &
+                     scatter_omp_r,scatter_omp_r1,scatter_omp_r2,scatter_omp_r3, &
+                     scatter_omp_l,scatter_omp_l1,scatter_omp_l2,scatter_omp_l3
+  END INTERFACE
+
+  
+  INTERFACE gather_omp
+    MODULE PROCEDURE gather_omp_i,gather_omp_i1,gather_omp_i2,gather_omp_i3, &
+                     gather_omp_r,gather_omp_r1,gather_omp_r2,gather_omp_r3, &
+                     gather_omp_l,gather_omp_l1,gather_omp_l2,gather_omp_l3  
+  END INTERFACE
+  
+  
+  INTERFACE reduce_sum_omp
+    MODULE PROCEDURE reduce_sum_omp_i,reduce_sum_omp_i1,reduce_sum_omp_i2,reduce_sum_omp_i3,reduce_sum_omp_i4, &
+                     reduce_sum_omp_r,reduce_sum_omp_r1,reduce_sum_omp_r2,reduce_sum_omp_r3,reduce_sum_omp_r4
+  END INTERFACE 
+
+
+  PUBLIC bcast_omp,scatter_omp,gather_omp,reduce_sum_omp, omp_barrier
+
+CONTAINS
+
+  SUBROUTINE omp_barrier
+  IMPLICIT NONE
+
+!$OMP BARRIER
+
+  END SUBROUTINE omp_barrier
+  
+  SUBROUTINE check_buffer_i(buff_size)
+  IMPLICIT NONE
+  INTEGER :: buff_size
+
+!$OMP BARRIER
+!$OMP MASTER
+    IF (buff_size>size_i) THEN
+      IF (ALLOCATED(buffer_i)) DEALLOCATE(buffer_i)
+      size_i=MAX(size_min,INT(grow_factor*buff_size))
+      ALLOCATE(buffer_i(size_i))
+    ENDIF
+!$OMP END MASTER
+!$OMP BARRIER
+  
+  END SUBROUTINE check_buffer_i
+  
+  SUBROUTINE check_buffer_r(buff_size)
+  IMPLICIT NONE
+  INTEGER :: buff_size
+
+!$OMP BARRIER
+!$OMP MASTER
+    IF (buff_size>size_r) THEN
+      IF (ALLOCATED(buffer_r)) DEALLOCATE(buffer_r)
+      size_r=MAX(size_min,INT(grow_factor*buff_size))
+      ALLOCATE(buffer_r(size_r))
+    ENDIF
+!$OMP END MASTER
+!$OMP BARRIER
+  
+  END SUBROUTINE check_buffer_r
+  
+  SUBROUTINE check_buffer_l(buff_size)
+  IMPLICIT NONE
+  INTEGER :: buff_size
+
+!$OMP BARRIER
+!$OMP MASTER
+    IF (buff_size>size_l) THEN
+      IF (ALLOCATED(buffer_l)) DEALLOCATE(buffer_l)
+      size_l=MAX(size_min,INT(grow_factor*buff_size))
+      ALLOCATE(buffer_l(size_l))
+    ENDIF
+!$OMP END MASTER
+!$OMP BARRIER
+  
+  END SUBROUTINE check_buffer_l
+    
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Broadcast --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+!! -- Les chaine de charactère -- !!
+
+  SUBROUTINE bcast_omp_c(var)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(INOUT) :: Var
+    
+    CALL bcast_omp_cgen(Var,len(Var),buffer_c)
+    
+  END SUBROUTINE bcast_omp_c
+
+!! -- Les entiers -- !!
+  
+  SUBROUTINE bcast_omp_i(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var
+    INTEGER :: Var_tmp(1)
+    
+    Var_tmp(1)=Var
+    CALL check_buffer_i(1)
+    CALL bcast_omp_igen(Var_tmp,1,buffer_i)
+    Var=Var_tmp(1)
+
+  END SUBROUTINE bcast_omp_i
+
+
+  SUBROUTINE bcast_omp_i1(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:)
+   
+    CALL check_buffer_i(size(Var))
+    CALL bcast_omp_igen(Var,size(Var),buffer_i)
+
+  END SUBROUTINE bcast_omp_i1
+
+
+  SUBROUTINE bcast_omp_i2(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:)
+   
+    CALL check_buffer_i(size(Var))
+    CALL bcast_omp_igen(Var,size(Var),buffer_i)
+
+  END SUBROUTINE bcast_omp_i2
+
+
+  SUBROUTINE bcast_omp_i3(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:,:)
+
+    CALL check_buffer_i(size(Var))
+    CALL bcast_omp_igen(Var,size(Var),buffer_i)
+
+  END SUBROUTINE bcast_omp_i3
+
+
+  SUBROUTINE bcast_omp_i4(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:,:,:)
+   
+    CALL check_buffer_i(size(Var))
+    CALL bcast_omp_igen(Var,size(Var),buffer_i)
+
+  END SUBROUTINE bcast_omp_i4
+
+
+!! -- Les reels -- !!
+
+  SUBROUTINE bcast_omp_r(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var
+    REAL :: Var_tmp(1)
+    
+    Var_tmp(1)=Var
+    CALL check_buffer_r(1)
+    CALL bcast_omp_rgen(Var_tmp,1,buffer_r)
+    Var=Var_tmp(1)
+
+  END SUBROUTINE bcast_omp_r
+
+
+  SUBROUTINE bcast_omp_r1(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:)
+   
+    CALL check_buffer_r(size(Var))
+    CALL bcast_omp_rgen(Var,size(Var),buffer_r)
+
+  END SUBROUTINE bcast_omp_r1
+
+
+  SUBROUTINE bcast_omp_r2(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:)
+   
+    CALL check_buffer_r(size(Var))
+    CALL bcast_omp_rgen(Var,size(Var),buffer_r)
+
+  END SUBROUTINE bcast_omp_r2
+
+
+  SUBROUTINE bcast_omp_r3(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:,:)
+
+    CALL check_buffer_r(size(Var))
+    CALL bcast_omp_rgen(Var,size(Var),buffer_r)
+
+  END SUBROUTINE bcast_omp_r3
+
+
+  SUBROUTINE bcast_omp_r4(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:,:,:)
+   
+    CALL check_buffer_r(size(Var))
+    CALL bcast_omp_rgen(Var,size(Var),buffer_r)
+
+  END SUBROUTINE bcast_omp_r4
+
+  
+!! -- Les booleans -- !!
+
+  SUBROUTINE bcast_omp_l(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var
+    LOGICAL :: Var_tmp(1)
+    
+    Var_tmp(1)=Var
+    CALL check_buffer_l(1)
+    CALL bcast_omp_lgen(Var_tmp,1,buffer_l)
+    Var=Var_tmp(1)
+
+  END SUBROUTINE bcast_omp_l
+
+
+  SUBROUTINE bcast_omp_l1(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:)
+   
+    CALL check_buffer_l(size(Var))
+    CALL bcast_omp_lgen(Var,size(Var),buffer_l)
+
+  END SUBROUTINE bcast_omp_l1
+
+
+  SUBROUTINE bcast_omp_l2(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:)
+   
+    CALL check_buffer_l(size(Var))
+    CALL bcast_omp_lgen(Var,size(Var),buffer_l)
+
+  END SUBROUTINE bcast_omp_l2
+
+
+  SUBROUTINE bcast_omp_l3(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:,:)
+
+    CALL check_buffer_l(size(Var))
+    CALL bcast_omp_lgen(Var,size(Var),buffer_l)
+
+  END SUBROUTINE bcast_omp_l3
+
+
+  SUBROUTINE bcast_omp_l4(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:,:,:)
+   
+    CALL check_buffer_l(size(Var))
+    CALL bcast_omp_lgen(Var,size(Var),buffer_l)
+
+  END SUBROUTINE bcast_omp_l4
+
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Scatter   --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  SUBROUTINE scatter_omp_i(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    CALL Check_buffer_i(size(VarIn))   
+    CALL scatter_omp_igen(VarIn,Varout,1,buffer_i)
+    
+  END SUBROUTINE scatter_omp_i
+
+
+  SUBROUTINE scatter_omp_i1(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+
+    CALL Check_buffer_i(size(VarIn))   
+    CALL scatter_omp_igen(VarIn,Varout,Size(VarOut,2),buffer_i)
+    
+  END SUBROUTINE scatter_omp_i1
+  
+  
+  SUBROUTINE scatter_omp_i2(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    CALL Check_buffer_i(size(VarIn))   
+    CALL scatter_omp_igen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3),buffer_i)
+
+  END SUBROUTINE scatter_omp_i2
+
+
+  SUBROUTINE scatter_omp_i3(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    CALL Check_buffer_i(size(VarIn))   
+    CALL scatter_omp_igen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4),buffer_i)
+  
+  END SUBROUTINE scatter_omp_i3
+
+
+
+
+  SUBROUTINE scatter_omp_r(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    CALL Check_buffer_r(size(VarIn))   
+    CALL scatter_omp_rgen(VarIn,Varout,1,buffer_r)
+    
+  END SUBROUTINE scatter_omp_r
+
+
+  SUBROUTINE scatter_omp_r1(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    CALL Check_buffer_r(size(VarIn))   
+    CALL scatter_omp_rgen(VarIn,Varout,Size(VarOut,2),buffer_r)
+        
+  END SUBROUTINE scatter_omp_r1
+  
+  
+  SUBROUTINE scatter_omp_r2(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    CALL Check_buffer_r(size(VarIn))   
+    CALL scatter_omp_rgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3),buffer_r)
+
+  END SUBROUTINE scatter_omp_r2
+
+
+  SUBROUTINE scatter_omp_r3(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    CALL Check_buffer_r(size(VarIn))   
+    CALL scatter_omp_rgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4),buffer_r)
+  
+  END SUBROUTINE scatter_omp_r3
+  
+
+
+  SUBROUTINE scatter_omp_l(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    CALL Check_buffer_l(size(VarIn))   
+    CALL scatter_omp_lgen(VarIn,Varout,1,buffer_l)
+    
+  END SUBROUTINE scatter_omp_l
+
+
+  SUBROUTINE scatter_omp_l1(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    CALL Check_buffer_l(size(VarIn))   
+    CALL scatter_omp_lgen(VarIn,Varout,Size(VarOut,2),buffer_l)
+    
+  END SUBROUTINE scatter_omp_l1
+  
+  
+  SUBROUTINE scatter_omp_l2(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    CALL Check_buffer_l(size(VarIn))   
+    CALL scatter_omp_lgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3),buffer_l)
+
+  END SUBROUTINE scatter_omp_l2
+
+
+  SUBROUTINE scatter_omp_l3(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    CALL Check_buffer_l(size(VarIn))   
+    CALL scatter_omp_lgen(VarIn,Varout,Size(VarOut,2)*Size(VarOut,3)*Size(VarOut,4),buffer_l)
+  
+  END SUBROUTINE scatter_omp_l3  
+  
+
+  SUBROUTINE gather_omp_i(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    CALL Check_buffer_i(size(VarOut))   
+    CALL gather_omp_igen(VarIn,Varout,1,buffer_i)
+    
+  END SUBROUTINE gather_omp_i
+
+
+  SUBROUTINE gather_omp_i1(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    CALL Check_buffer_i(size(VarOut))   
+    CALL gather_omp_igen(VarIn,Varout,Size(VarIn,2),buffer_i)
+    
+  END SUBROUTINE gather_omp_i1
+
+
+  SUBROUTINE gather_omp_i2(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    CALL Check_buffer_i(size(VarOut))   
+    CALL gather_omp_igen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3),buffer_i)
+          
+  END SUBROUTINE gather_omp_i2
+  
+
+  SUBROUTINE gather_omp_i3(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    CALL Check_buffer_i(size(VarOut))   
+    CALL gather_omp_igen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4),buffer_i)
+    
+  END SUBROUTINE gather_omp_i3
+
+
+
+  SUBROUTINE gather_omp_r(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    CALL Check_buffer_r(size(VarOut))   
+    CALL gather_omp_rgen(VarIn,Varout,1,buffer_r)
+    
+  END SUBROUTINE gather_omp_r
+
+
+  SUBROUTINE gather_omp_r1(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+
+    CALL Check_buffer_r(size(VarOut))   
+    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2),buffer_r)
+        
+  END SUBROUTINE gather_omp_r1
+
+
+  SUBROUTINE gather_omp_r2(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    CALL Check_buffer_r(size(VarOut))   
+    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3),buffer_r)
+    
+  END SUBROUTINE gather_omp_r2
+  
+
+  SUBROUTINE gather_omp_r3(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+
+    CALL Check_buffer_r(size(VarOut))       
+    CALL gather_omp_rgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4),buffer_r)
+    
+  END SUBROUTINE gather_omp_r3
+
+
+  SUBROUTINE gather_omp_l(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    CALL Check_buffer_l(size(VarOut))   
+    CALL gather_omp_lgen(VarIn,Varout,1,buffer_l)
+    
+  END SUBROUTINE gather_omp_l
+
+
+  SUBROUTINE gather_omp_l1(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    CALL Check_buffer_l(size(VarOut))   
+    CALL gather_omp_lgen(VarIn,Varout,Size(VarIn,2),buffer_l)
+    
+  END SUBROUTINE gather_omp_l1
+
+
+  SUBROUTINE gather_omp_l2(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    CALL Check_buffer_l(size(VarOut))   
+    CALL gather_omp_lgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3),buffer_l)
+    
+  END SUBROUTINE gather_omp_l2
+  
+
+  SUBROUTINE gather_omp_l3(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    CALL Check_buffer_l(size(VarOut))   
+    CALL gather_omp_lgen(VarIn,Varout,Size(VarIn,2)*Size(VarIn,3)*Size(VarIn,4),buffer_l)
+    
+  END SUBROUTINE gather_omp_l3
+
+
+
+
+  SUBROUTINE reduce_sum_omp_i(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN)  :: VarIn
+    INTEGER,INTENT(OUT) :: VarOut
+    INTEGER             :: VarIn_tmp(1)
+    INTEGER             :: VarOut_tmp(1)
+    
+    VarIn_tmp(1)=VarIn
+    CALL Check_buffer_i(1)   
+    CALL reduce_sum_omp_igen(VarIn_tmp,Varout_tmp,1,buffer_i)
+    VarOut=VarOut_tmp(1)
+    
+  END SUBROUTINE reduce_sum_omp_i
+
+  SUBROUTINE reduce_sum_omp_i1(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+    CALL Check_buffer_i(size(VarIn))   
+    CALL reduce_sum_omp_igen(VarIn,Varout,Size(VarIn),buffer_i)
+   
+  END SUBROUTINE reduce_sum_omp_i1
+  
+  
+  SUBROUTINE reduce_sum_omp_i2(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+
+    CALL Check_buffer_i(size(VarIn))   
+    CALL reduce_sum_omp_igen(VarIn,Varout,Size(VarIn),buffer_i)
+  
+  END SUBROUTINE reduce_sum_omp_i2
+
+
+  SUBROUTINE reduce_sum_omp_i3(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    CALL Check_buffer_i(size(VarIn))   
+    CALL reduce_sum_omp_igen(VarIn,Varout,Size(VarIn),buffer_i)
+  
+  END SUBROUTINE reduce_sum_omp_i3
+
+
+  SUBROUTINE reduce_sum_omp_i4(VarIn, VarOut)
+    IMPLICIT NONE
+
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+  
+    CALL Check_buffer_i(size(VarIn))   
+    CALL reduce_sum_omp_igen(VarIn,Varout,Size(VarIn),buffer_i)
+  
+  END SUBROUTINE reduce_sum_omp_i4
+
+
+  SUBROUTINE reduce_sum_omp_r(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN)  :: VarIn
+    REAL,INTENT(OUT) :: VarOut
+    REAL             :: VarIn_tmp(1)
+    REAL             :: VarOut_tmp(1)
+    
+    VarIn_tmp(1)=VarIn
+    CALL Check_buffer_r(1)   
+    CALL reduce_sum_omp_rgen(VarIn_tmp,Varout_tmp,1,buffer_r)
+    VarOut=VarOut_tmp(1)
+  
+  END SUBROUTINE reduce_sum_omp_r
+
+  SUBROUTINE reduce_sum_omp_r1(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+    CALL Check_buffer_r(size(VarIn))   
+    CALL reduce_sum_omp_rgen(VarIn,Varout,Size(VarIn),buffer_r)
+   
+  END SUBROUTINE reduce_sum_omp_r1
+  
+  
+  SUBROUTINE reduce_sum_omp_r2(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    CALL Check_buffer_r(size(VarIn))   
+    CALL reduce_sum_omp_rgen(VarIn,Varout,Size(VarIn),buffer_r)
+  
+  END SUBROUTINE reduce_sum_omp_r2
+
+
+  SUBROUTINE reduce_sum_omp_r3(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    CALL Check_buffer_r(size(VarIn))   
+    CALL reduce_sum_omp_rgen(VarIn,Varout,Size(VarIn),buffer_r)
+  
+  END SUBROUTINE reduce_sum_omp_r3
+
+
+  SUBROUTINE reduce_sum_omp_r4(VarIn, VarOut)
+    IMPLICIT NONE
+
+    REAL,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+  
+    CALL Check_buffer_r(size(VarIn))   
+    CALL reduce_sum_omp_rgen(VarIn,Varout,Size(VarIn),buffer_r)
+  
+  END SUBROUTINE reduce_sum_omp_r4
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!    LES ROUTINES GENERIQUES    !
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  SUBROUTINE bcast_omp_cgen(Var,Nb,Buff)
+  IMPLICIT NONE
+    
+    CHARACTER(LEN=*),INTENT(INOUT) :: Var
+    CHARACTER(LEN=*),INTENT(INOUT) :: Buff
+    INTEGER,INTENT(IN) :: Nb
+    
+    INTEGER :: i
+  
+  !$OMP MASTER
+      Buff=Var
+  !$OMP END MASTER
+  !$OMP BARRIER
+
+    DO i=1,Nb
+      Var=Buff
+    ENDDO
+  !$OMP BARRIER      
+  
+  END SUBROUTINE bcast_omp_cgen
+
+
+      
+  SUBROUTINE bcast_omp_igen(Var,Nb,Buff)
+  IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: Nb
+    INTEGER,DIMENSION(Nb),INTENT(INOUT) :: Var
+    INTEGER,DIMENSION(Nb),INTENT(INOUT) :: Buff
+
+    INTEGER :: i
+    
+  !$OMP MASTER
+    DO i=1,Nb
+      Buff(i)=Var(i)
+    ENDDO
+  !$OMP END MASTER
+  !$OMP BARRIER
+
+    DO i=1,Nb
+      Var(i)=Buff(i)
+    ENDDO
+  !$OMP BARRIER        
+
+  END SUBROUTINE bcast_omp_igen
+
+
+  SUBROUTINE bcast_omp_rgen(Var,Nb,Buff)
+  IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: Nb
+    REAL,DIMENSION(Nb),INTENT(INOUT) :: Var
+    REAL,DIMENSION(Nb),INTENT(INOUT) :: Buff
+
+    INTEGER :: i
+    
+  !$OMP MASTER
+    DO i=1,Nb
+      Buff(i)=Var(i)
+    ENDDO
+  !$OMP END MASTER
+  !$OMP BARRIER
+
+    DO i=1,Nb
+      Var(i)=Buff(i)
+    ENDDO
+  !$OMP BARRIER        
+
+  END SUBROUTINE bcast_omp_rgen
+
+  SUBROUTINE bcast_omp_lgen(Var,Nb,Buff)
+  IMPLICIT NONE
+    
+    INTEGER,INTENT(IN) :: Nb
+    LOGICAL,DIMENSION(Nb),INTENT(INOUT) :: Var
+    LOGICAL,DIMENSION(Nb),INTENT(INOUT) :: Buff
+  
+    INTEGER :: i
+    
+  !$OMP MASTER
+    DO i=1,Nb
+      Buff(i)=Var(i)
+    ENDDO
+  !$OMP END MASTER
+  !$OMP BARRIER
+
+    DO i=1,Nb
+      Var(i)=Buff(i)
+    ENDDO
+  !$OMP BARRIER        
+
+  END SUBROUTINE bcast_omp_lgen
+
+
+  SUBROUTINE scatter_omp_igen(VarIn,VarOut,dimsize,Buff)
+    USE mod_phys_lmdz_omp_data
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
+    IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    INTEGER,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(klon_omp,dimsize) :: VarOut
+    INTEGER,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
+
+    INTEGER :: i,ij
+    
+  !$OMP MASTER
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        Buff(ij,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO  
+  !$OMP END MASTER
+  !$OMP BARRIER
+ 
+    DO i=1,dimsize
+      DO ij=1,klon_omp
+        VarOut(ij,i)=Buff(klon_omp_begin-1+ij,i)
+      ENDDO
+    ENDDO
+  !$OMP BARRIER  
+ 
+  END SUBROUTINE scatter_omp_igen
+
+
+  SUBROUTINE scatter_omp_rgen(VarIn,VarOut,dimsize,Buff)
+  USE mod_phys_lmdz_omp_data
+  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
+  IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    REAL,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(klon_omp,dimsize) :: VarOut
+    REAL,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
+
+    INTEGER :: i,ij
+    
+  !$OMP MASTER
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        Buff(ij,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO  
+  !$OMP END MASTER
+  !$OMP BARRIER
+
+    DO i=1,dimsize
+      DO ij=1,klon_omp
+        VarOut(ij,i)=Buff(klon_omp_begin-1+ij,i)
+      ENDDO
+    ENDDO
+  !$OMP BARRIER  
+
+  END SUBROUTINE scatter_omp_rgen
+
+
+  SUBROUTINE scatter_omp_lgen(VarIn,VarOut,dimsize,Buff)
+  USE mod_phys_lmdz_omp_data
+  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
+  IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    LOGICAL,INTENT(IN),DIMENSION(klon_mpi,dimsize) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(klon_omp,dimsize) :: VarOut
+    LOGICAL,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
+
+    INTEGER :: i,ij
+    
+ !$OMP MASTER 
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        Buff(ij,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO  
+  !$OMP END MASTER
+  !$OMP BARRIER
+
+    DO i=1,dimsize
+      DO ij=1,klon_omp
+        VarOut(ij,i)=Buff(klon_omp_begin-1+ij,i)
+      ENDDO
+    ENDDO
+  !$OMP BARRIER  
+
+  END SUBROUTINE scatter_omp_lgen
+
+
+
+
+
+  SUBROUTINE gather_omp_igen(VarIn,VarOut,dimsize,Buff)
+  USE mod_phys_lmdz_omp_data
+  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
+  IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    INTEGER,INTENT(IN),DIMENSION(klon_omp,dimsize) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
+    INTEGER,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
+
+    INTEGER :: i,ij
+    
+    DO i=1,dimsize
+      DO ij=1,klon_omp
+        Buff(klon_omp_begin-1+ij,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO
+  !$OMP BARRIER  
+  
+  
+  !$OMP MASTER
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        VarOut(ij,i)=Buff(ij,i)
+      ENDDO
+    ENDDO  
+  !$OMP END MASTER
+  !$OMP BARRIER
+
+  END SUBROUTINE gather_omp_igen
+
+
+  SUBROUTINE gather_omp_rgen(VarIn,VarOut,dimsize,Buff)
+  USE mod_phys_lmdz_omp_data
+  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
+  IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    REAL,INTENT(IN),DIMENSION(klon_omp,dimsize) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
+    REAL,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
+
+    INTEGER :: i,ij
+    
+    DO i=1,dimsize
+      DO ij=1,klon_omp
+        Buff(klon_omp_begin-1+ij,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO
+  !$OMP BARRIER  
+
+
+  !$OMP MASTER
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        VarOut(ij,i)=Buff(ij,i)
+      ENDDO
+    ENDDO  
+  !$OMP END MASTER
+  !$OMP BARRIER
+
+  END SUBROUTINE gather_omp_rgen
+
+
+  SUBROUTINE gather_omp_lgen(VarIn,VarOut,dimsize,Buff)
+  USE mod_phys_lmdz_omp_data
+  USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi 
+  IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    LOGICAL,INTENT(IN),DIMENSION(klon_omp,dimsize) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(klon_mpi,dimsize) :: VarOut
+    LOGICAL,INTENT(INOUT),DIMENSION(klon_mpi,dimsize) :: Buff
+
+    INTEGER :: i,ij
+    
+    DO i=1,dimsize
+      DO ij=1,klon_omp
+        Buff(klon_omp_begin-1+ij,i)=VarIn(ij,i)
+      ENDDO
+    ENDDO
+  !$OMP BARRIER  
+
+
+  !$OMP MASTER
+    DO i=1,dimsize
+      DO ij=1,klon_mpi
+        VarOut(ij,i)=Buff(ij,i)
+      ENDDO
+    ENDDO  
+  !$OMP END MASTER
+  !$OMP BARRIER
+
+  END SUBROUTINE gather_omp_lgen
+
+
+  SUBROUTINE reduce_sum_omp_igen(VarIn,VarOut,dimsize,Buff)
+  IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    INTEGER,INTENT(IN),DIMENSION(dimsize) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(dimsize) :: VarOut
+    INTEGER,INTENT(INOUT),DIMENSION(dimsize) :: Buff
+
+    INTEGER :: i
+
+  !$OMP MASTER
+    Buff(:)=0
+  !$OMP END MASTER
+  !$OMP BARRIER
+  
+  !$OMP CRITICAL     
+    DO i=1,dimsize
+      Buff(i)=Buff(i)+VarIn(i)
+    ENDDO
+  !$OMP END CRITICAL
+  !$OMP BARRIER  
+  
+  !$OMP MASTER
+    DO i=1,dimsize
+      VarOut(i)=Buff(i)
+    ENDDO
+  !$OMP END MASTER
+  !$OMP BARRIER
+  
+  END SUBROUTINE reduce_sum_omp_igen
+
+  SUBROUTINE reduce_sum_omp_rgen(VarIn,VarOut,dimsize,Buff)
+  IMPLICIT NONE
+
+    INTEGER,INTENT(IN) :: dimsize
+    REAL,INTENT(IN),DIMENSION(dimsize) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(dimsize) :: VarOut
+    REAL,INTENT(INOUT),DIMENSION(dimsize) :: Buff
+
+    INTEGER :: i
+
+  !$OMP MASTER
+    Buff(:)=0
+  !$OMP END MASTER
+  !$OMP BARRIER
+  
+  !$OMP CRITICAL     
+    DO i=1,dimsize
+      Buff(i)=Buff(i)+VarIn(i)
+    ENDDO
+  !$OMP END CRITICAL
+  !$OMP BARRIER  
+  
+  !$OMP MASTER
+    DO i=1,dimsize
+      VarOut(i)=Buff(i)
+    ENDDO
+  !$OMP END MASTER
+  !$OMP BARRIER
+  
+  END SUBROUTINE reduce_sum_omp_rgen
+
+END MODULE mod_phys_lmdz_omp_transfert
Index: /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_para.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_para.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_para.F90	(revision 2408)
@@ -0,0 +1,113 @@
+!
+!$Header$
+!
+MODULE mod_phys_lmdz_para
+  USE mod_phys_lmdz_transfert_para
+  USE mod_phys_lmdz_mpi_data
+  USE mod_phys_lmdz_omp_data
+    
+  INTEGER,SAVE :: klon_loc
+  LOGICAL,SAVE :: is_sequential
+  LOGICAL,SAVE :: is_parallel
+  LOGICAL,SAVE :: is_master
+  
+!$OMP THREADPRIVATE(klon_loc,is_master)
+  
+CONTAINS
+
+  SUBROUTINE Init_phys_lmdz_para(nbp,nbp_lon,nbp_lat,communicator)
+  IMPLICIT NONE
+    INTEGER,INTENT(in) :: nbp
+    INTEGER,INTENT(in) :: nbp_lon
+    INTEGER,INTENT(in) :: nbp_lat
+    INTEGER,INTENT(in) :: communicator
+
+    CALL Init_phys_lmdz_mpi_data(nbp,nbp_lon,nbp_lat,communicator)
+!$OMP PARALLEL
+    CALL Init_phys_lmdz_omp_data(klon_mpi)
+    klon_loc=klon_omp
+    IF (is_mpi_root .AND. is_omp_root) THEN 
+       is_master=.TRUE.
+     ELSE
+       is_master=.FALSE.
+     ENDIF
+     CALL Test_transfert
+!$OMP END PARALLEL    
+     IF (is_using_mpi .OR. is_using_omp) THEN
+       is_sequential=.FALSE.
+       is_parallel=.TRUE.
+     ELSE
+       is_sequential=.TRUE.
+       is_parallel=.FALSE.
+     ENDIF
+      
+  END SUBROUTINE Init_phys_lmdz_para
+
+  SUBROUTINE Test_transfert
+  USE mod_grid_phy_lmdz
+  IMPLICIT NONE
+    INCLUDE "iniprint.h"
+ 
+    REAL :: Test_Field1d_glo(klon_glo,nbp_lev)
+    REAL :: tmp1d_glo(klon_glo,nbp_lev)
+    REAL :: Test_Field2d_glo(nbp_lon,nbp_lat,nbp_lev)
+    REAL :: tmp2d_glo(nbp_lon,nbp_lat,nbp_lev)
+    REAL :: Test_Field1d_loc(klon_loc,nbp_lev)
+    REAL :: Test_Field2d_loc(nbp_lon,jj_nb,nbp_lev)
+    REAL :: CheckSum
+    
+    INTEGER :: i,l
+  
+    Test_Field1d_glo = 0.
+    Test_Field2d_glo = 0.
+    Test_Field1d_loc = 0.
+    Test_Field2d_loc = 0.
+  
+    IF (is_mpi_root) THEN
+!$OMP MASTER
+      DO l=1,nbp_lev
+        DO i=1,klon_glo
+!          Test_Field1d_glo(i,l)=MOD(i,10)+10*(l-1)
+           Test_Field1d_glo(i,l)=1
+        ENDDO
+      ENDDO
+!$OMP END MASTER  
+    ENDIF
+  
+    CALL Scatter(Test_Field1d_glo,Test_Field1d_loc)
+    CALL Gather(Test_Field1d_loc,tmp1d_glo)
+  
+    IF (is_mpi_root) THEN
+!$OMP MASTER  
+      Checksum=sum(Test_Field1d_glo-tmp1d_glo)
+      WRITE(lunout,*) "------> Checksum =",Checksum," MUST BE 0"
+!$OMP END MASTER
+    ENDIF
+    
+    CALL grid1dTo2d_glo(Test_Field1d_glo,Test_Field2d_glo)
+    CALL scatter2D(Test_Field2d_glo,Test_Field1d_loc)
+    CALL gather2d(Test_Field1d_loc,Test_Field2d_glo)
+    CALL grid2dTo1d_glo(Test_Field2d_glo,tmp1d_glo)
+
+    IF (is_mpi_root) THEN
+!$OMP MASTER  
+      Checksum=sum(Test_Field1d_glo-tmp1d_glo)
+      WRITE(lunout,*) "------> Checksum =",Checksum," MUST BE 0"
+!$OMP END MASTER
+    ENDIF
+
+    CALL bcast(Test_Field1d_glo)
+    CALL reduce_sum(Test_Field1d_glo,tmp1d_glo)
+
+    IF (is_mpi_root) THEN
+!$OMP MASTER  
+      Checksum=sum(Test_Field1d_glo*omp_size*mpi_size-tmp1d_glo)
+      WRITE(lunout,*) "------> Checksum =",Checksum," MUST BE 0"
+!$OMP END MASTER
+    ENDIF
+    
+     
+   END SUBROUTINE Test_transfert
+  
+END MODULE mod_phys_lmdz_para
+    
Index: /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_transfert_para.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_transfert_para.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/mod_phys_lmdz_transfert_para.F90	(revision 2408)
@@ -0,0 +1,1275 @@
+!
+!$Header$
+!
+MODULE mod_phys_lmdz_transfert_para
+
+  USE mod_phys_lmdz_mpi_transfert
+  USE mod_phys_lmdz_omp_transfert 
+
+
+
+  INTERFACE bcast
+    MODULE PROCEDURE bcast_c,                                     &
+                     bcast_i,bcast_i1,bcast_i2,bcast_i3,bcast_i4, &
+                     bcast_r,bcast_r1,bcast_r2,bcast_r3,bcast_r4, &
+		     bcast_l,bcast_l1,bcast_l2,bcast_l3,bcast_l4
+  END INTERFACE
+
+  INTERFACE scatter
+    MODULE PROCEDURE scatter_i,scatter_i1,scatter_i2,scatter_i3, &
+                     scatter_r,scatter_r1,scatter_r2,scatter_r3, &
+		     scatter_l,scatter_l1,scatter_l2,scatter_l3
+  END INTERFACE
+
+  
+  INTERFACE gather
+    MODULE PROCEDURE gather_i,gather_i1,gather_i2,gather_i3, &
+                     gather_r,gather_r1,gather_r2,gather_r3, &
+		     gather_l,gather_l1,gather_l2,gather_l3  
+  END INTERFACE
+  
+  INTERFACE scatter2D
+    MODULE PROCEDURE scatter2D_i,scatter2D_i1,scatter2D_i2,scatter2D_i3, &
+                     scatter2D_r,scatter2D_r1,scatter2D_r2,scatter2D_r3, &
+		     scatter2D_l,scatter2D_l1,scatter2D_l2,scatter2D_l3
+  END INTERFACE
+
+  INTERFACE gather2D
+    MODULE PROCEDURE gather2D_i,gather2D_i1,gather2D_i2,gather2D_i3, &
+                     gather2D_r,gather2D_r1,gather2D_r2,gather2D_r3, &
+		     gather2D_l,gather2D_l1,gather2D_l2,gather2D_l3
+  END INTERFACE 
+  
+  INTERFACE reduce_sum
+    MODULE PROCEDURE reduce_sum_i,reduce_sum_i1,reduce_sum_i2,reduce_sum_i3,reduce_sum_i4, &
+                     reduce_sum_r,reduce_sum_r1,reduce_sum_r2,reduce_sum_r3,reduce_sum_r4
+  END INTERFACE 
+
+   
+CONTAINS
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Broadcast --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+!! -- Les chaine de charactère -- !!
+
+  SUBROUTINE bcast_c(var)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(INOUT) :: Var
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_c
+
+!! -- Les entiers -- !!
+  
+  SUBROUTINE bcast_i(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_i
+
+  SUBROUTINE bcast_i1(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_i1
+
+
+  SUBROUTINE bcast_i2(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_i2
+
+
+  SUBROUTINE bcast_i3(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_i3
+
+
+  SUBROUTINE bcast_i4(var)
+  IMPLICIT NONE
+    INTEGER,INTENT(INOUT) :: Var(:,:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_i4
+
+ 
+!! -- Les reels -- !!
+  
+  SUBROUTINE bcast_r(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var
+
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_r
+
+  SUBROUTINE bcast_r1(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_r1
+
+
+  SUBROUTINE bcast_r2(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_r2
+
+
+  SUBROUTINE bcast_r3(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_r3
+
+
+  SUBROUTINE bcast_r4(var)
+  IMPLICIT NONE
+    REAL,INTENT(INOUT) :: Var(:,:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_r4 
+
+
+!! -- Les booleens -- !!
+  
+  SUBROUTINE bcast_l(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_l
+
+  SUBROUTINE bcast_l1(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_l1
+
+
+  SUBROUTINE bcast_l2(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_l2
+
+
+  SUBROUTINE bcast_l3(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_l3
+
+
+  SUBROUTINE bcast_l4(var)
+  IMPLICIT NONE
+    LOGICAL,INTENT(INOUT) :: Var(:,:,:,:)
+   
+!$OMP MASTER
+    CALL bcast_mpi(Var)
+!$OMP END MASTER
+    CALL bcast_omp(Var)
+    
+  END SUBROUTINE bcast_l4
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Scatter   --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  SUBROUTINE scatter_i(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    INTEGER,DIMENSION(klon_mpi) :: Var_tmp
+    
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+
+      CALL scatter_omp(Var_tmp,Varout)
+    
+  END SUBROUTINE scatter_i
+
+
+  SUBROUTINE scatter_i1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+
+    INTEGER,DIMENSION(klon_mpi,SIZE(Varout,2)) :: Var_tmp
+
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+      CALL scatter_omp(Var_tmp,Varout)
+    
+  END SUBROUTINE scatter_i1
+
+
+  SUBROUTINE scatter_i2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    INTEGER,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3)) :: Var_tmp
+
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+      CALL scatter_omp(Var_tmp,Varout)
+    
+  END SUBROUTINE scatter_i2
+
+
+  SUBROUTINE scatter_i3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+
+    INTEGER,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3),SIZE(Varout,4)) :: Var_tmp
+
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+      CALL scatter_omp(Var_tmp,VarOut)
+    
+  END SUBROUTINE scatter_i3
+
+
+  SUBROUTINE scatter_r(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    REAL,DIMENSION(klon_mpi) :: Var_tmp
+    
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+
+      CALL scatter_omp(Var_tmp,Varout)
+    
+  END SUBROUTINE scatter_r
+
+
+  SUBROUTINE scatter_r1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+
+    REAL,DIMENSION(klon_mpi,SIZE(Varout,2)) :: Var_tmp
+
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+      CALL scatter_omp(Var_tmp,Varout)
+    
+  END SUBROUTINE scatter_r1
+
+
+  SUBROUTINE scatter_r2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    REAL,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3)) :: Var_tmp
+
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+      CALL scatter_omp(Var_tmp,Varout)
+    
+  END SUBROUTINE scatter_r2
+
+
+  SUBROUTINE scatter_r3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+
+    REAL,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3),SIZE(Varout,4)) :: Var_tmp
+
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+      CALL scatter_omp(Var_tmp,VarOut)
+    
+  END SUBROUTINE scatter_r3
+  
+  
+
+  SUBROUTINE scatter_l(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    LOGICAL,DIMENSION(klon_mpi) :: Var_tmp
+    
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+
+      CALL scatter_omp(Var_tmp,Varout)
+    
+  END SUBROUTINE scatter_l
+
+
+  SUBROUTINE scatter_l1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+
+    LOGICAL,DIMENSION(klon_mpi,SIZE(Varout,2)) :: Var_tmp
+
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+      CALL scatter_omp(Var_tmp,Varout)
+    
+  END SUBROUTINE scatter_l1
+
+
+  SUBROUTINE scatter_l2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    LOGICAL,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3)) :: Var_tmp
+
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+      CALL scatter_omp(Var_tmp,Varout)
+    
+  END SUBROUTINE scatter_l2
+
+
+  SUBROUTINE scatter_l3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+
+    LOGICAL,DIMENSION(klon_mpi,SIZE(Varout,2),SIZE(Varout,3),SIZE(Varout,4)) :: Var_tmp
+
+!$OMP MASTER
+      CALL scatter_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+      CALL scatter_omp(Var_tmp,VarOut)
+    
+  END SUBROUTINE scatter_l3
+
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Gather   --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ 
+!!!!! --> Les entiers
+
+  SUBROUTINE gather_i(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+    INTEGER, DIMENSION(klon_mpi) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,Varout)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_i
+
+
+  SUBROUTINE gather_i1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    INTEGER, DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,Varout)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_i1
+
+
+  SUBROUTINE gather_i2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    INTEGER, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_i2
+
+
+  SUBROUTINE gather_i3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    INTEGER, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_i3
+
+
+!!!!! --> Les reels
+
+  SUBROUTINE gather_r(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+    REAL, DIMENSION(klon_mpi) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_r
+
+
+  SUBROUTINE gather_r1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    REAL, DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_r1
+
+
+  SUBROUTINE gather_r2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    REAL, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_r2
+
+
+  SUBROUTINE gather_r3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    REAL, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_r3
+
+
+!!!!! --> Les booleens
+
+  SUBROUTINE gather_l(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+    LOGICAL, DIMENSION(klon_mpi) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_l
+
+
+  SUBROUTINE gather_l1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    LOGICAL, DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_l1
+
+
+  SUBROUTINE gather_l2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    LOGICAL, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_l2
+
+
+  SUBROUTINE gather_l3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    LOGICAL, DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
+    
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE gather_l3
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Scatter2D   --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+
+!!!!! --> Les entiers
+
+  SUBROUTINE scatter2D_i(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    INTEGER,DIMENSION(klon_mpi) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_i
+
+
+  SUBROUTINE scatter2D_i1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+
+    INTEGER,DIMENSION(klon_mpi,SIZE(VarOut,2)) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_i1
+  
+
+  SUBROUTINE scatter2D_i2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+
+    INTEGER,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3)) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_i2  
+
+
+  SUBROUTINE scatter2D_i3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+
+    INTEGER,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3),SIZE(VarOut,4)) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_i3
+  
+
+!!!!! --> Les reels
+
+  SUBROUTINE scatter2D_r(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    REAL,DIMENSION(klon_mpi) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_r
+
+
+  SUBROUTINE scatter2D_r1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+
+    REAL,DIMENSION(klon_mpi,SIZE(VarOut,2)) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_r1
+  
+
+  SUBROUTINE scatter2D_r2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+
+    REAL,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3)) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_r2  
+
+
+  SUBROUTINE scatter2D_r3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+
+    REAL,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3),SIZE(VarOut,4)) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_r3
+    
+    
+!!!!! --> Les booleens
+
+
+  SUBROUTINE scatter2D_l(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:) :: VarOut
+
+    LOGICAL,DIMENSION(klon_mpi) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_l
+
+
+  SUBROUTINE scatter2D_l1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+
+    LOGICAL,DIMENSION(klon_mpi,SIZE(VarOut,2)) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_l1
+  
+
+  SUBROUTINE scatter2D_l2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+
+    LOGICAL,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3)) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_l2  
+
+
+  SUBROUTINE scatter2D_l3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+
+    LOGICAL,DIMENSION(klon_mpi,SIZE(VarOut,2),SIZE(VarOut,3),SIZE(VarOut,4)) :: Var_tmp    
+
+!$OMP MASTER    
+    CALL scatter2D_mpi(VarIn,Var_tmp)
+!$OMP END MASTER
+    CALL scatter_omp(Var_tmp,VarOut)
+
+  END SUBROUTINE scatter2D_l3
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des Gather2D   --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+!!!!! --> Les entiers
+
+  SUBROUTINE gather2D_i(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    INTEGER,DIMENSION(klon_mpi) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_i
+  
+
+  SUBROUTINE gather2D_i1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    INTEGER,DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_i1
+
+  
+  SUBROUTINE gather2D_i2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    INTEGER,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_i2
+
+
+  SUBROUTINE gather2D_i3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
+    
+    INTEGER,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_i3
+
+
+!!!!! --> Les reels
+
+  SUBROUTINE gather2D_r(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    REAL,DIMENSION(klon_mpi) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_r
+  
+
+  SUBROUTINE gather2D_r1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    REAL,DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_r1
+
+  
+  SUBROUTINE gather2D_r2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    REAL,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_r2
+
+
+  SUBROUTINE gather2D_r3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
+    
+    REAL,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_r3
+  
+
+!!!!! --> Les booleens
+
+  SUBROUTINE gather2D_l(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    LOGICAL,DIMENSION(klon_mpi) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_l
+  
+
+  SUBROUTINE gather2D_l1(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    LOGICAL,DIMENSION(klon_mpi,SIZE(VarIn,2)) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_l1
+
+  
+  SUBROUTINE gather2D_l2(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    LOGICAL,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3)) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_l2
+
+
+  SUBROUTINE gather2D_l3(VarIn, VarOut)
+    USE mod_phys_lmdz_mpi_data, ONLY : klon_mpi
+    IMPLICIT NONE
+  
+    LOGICAL,INTENT(IN),DIMENSION(:,:,:,:) :: VarIn
+    LOGICAL,INTENT(OUT),DIMENSION(:,:,:,:,:) :: VarOut
+    
+    LOGICAL,DIMENSION(klon_mpi,SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4)) :: Var_tmp
+
+    CALL gather_omp(VarIn,Var_tmp)
+!$OMP MASTER
+    CALL gather2D_mpi(Var_tmp,VarOut)
+!$OMP END MASTER    
+
+  END SUBROUTINE gather2D_l3
+  
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition des reduce_sum   --> 4D   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+! Les entiers
+
+  SUBROUTINE reduce_sum_i(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN)  :: VarIn
+    INTEGER,INTENT(OUT) :: VarOut
+    
+    INTEGER             :: Var_tmp
+           
+    CALL reduce_sum_omp(VarIn,Var_tmp)
+!$OMP MASTER      
+    CALL reduce_sum_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE reduce_sum_i  
+
+
+  SUBROUTINE reduce_sum_i1(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+    INTEGER,DIMENSION(SIZE(VarIn))   :: Var_tmp
+           
+    CALL reduce_sum_omp(VarIn,Var_tmp)
+!$OMP MASTER      
+    CALL reduce_sum_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE reduce_sum_i1  
+
+
+  SUBROUTINE reduce_sum_i2(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    INTEGER,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2)) :: Var_tmp
+           
+    CALL reduce_sum_omp(VarIn,Var_tmp)
+!$OMP MASTER      
+    CALL reduce_sum_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE reduce_sum_i2  
+  
+
+  SUBROUTINE reduce_sum_i3(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    INTEGER,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2),SIZE(VarIn,3))  :: Var_tmp
+           
+    CALL reduce_sum_omp(VarIn,Var_tmp)
+!$OMP MASTER      
+    CALL reduce_sum_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE reduce_sum_i3  
+
+
+  SUBROUTINE reduce_sum_i4(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    INTEGER,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
+    INTEGER,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    INTEGER,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4))  :: Var_tmp
+           
+    CALL reduce_sum_omp(VarIn,Var_tmp)
+!$OMP MASTER      
+    CALL reduce_sum_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE reduce_sum_i4  
+
+
+! Les reels
+
+  SUBROUTINE reduce_sum_r(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN)  :: VarIn
+    REAL,INTENT(OUT) :: VarOut
+    
+    REAL             :: Var_tmp
+           
+    CALL reduce_sum_omp(VarIn,Var_tmp)
+!$OMP MASTER      
+    CALL reduce_sum_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE reduce_sum_r  
+
+
+  SUBROUTINE reduce_sum_r1(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:) :: VarOut
+    
+    REAL,DIMENSION(SIZE(VarIn))   :: Var_tmp
+           
+    CALL reduce_sum_omp(VarIn,Var_tmp)
+!$OMP MASTER      
+    CALL reduce_sum_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE reduce_sum_r1  
+
+
+  SUBROUTINE reduce_sum_r2(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:) :: VarOut
+    
+    REAL,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2)) :: Var_tmp
+           
+    CALL reduce_sum_omp(VarIn,Var_tmp)
+!$OMP MASTER      
+    CALL reduce_sum_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE reduce_sum_r2  
+  
+
+  SUBROUTINE reduce_sum_r3(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:) :: VarOut
+    
+    REAL,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2),SIZE(VarIn,3))  :: Var_tmp
+           
+    CALL reduce_sum_omp(VarIn,Var_tmp)
+!$OMP MASTER      
+    CALL reduce_sum_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE reduce_sum_r3  
+
+
+  SUBROUTINE reduce_sum_r4(VarIn, VarOut)
+    IMPLICIT NONE
+  
+    REAL,INTENT(IN),DIMENSION(:,:,:,:)  :: VarIn
+    REAL,INTENT(OUT),DIMENSION(:,:,:,:) :: VarOut
+    
+    REAL,DIMENSION(SIZE(VarIn,1),SIZE(VarIn,2),SIZE(VarIn,3),SIZE(VarIn,4))  :: Var_tmp
+           
+    CALL reduce_sum_omp(VarIn,Var_tmp)
+!$OMP MASTER      
+    CALL reduce_sum_mpi(Var_tmp,VarOut)
+!$OMP END MASTER
+  
+  END SUBROUTINE reduce_sum_r4  
+
+   
+END MODULE mod_phys_lmdz_transfert_para
+
Index: /LMDZ5/branches/testing/libf/phy_common/physics_distribution_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/physics_distribution_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/physics_distribution_mod.F90	(revision 2408)
@@ -0,0 +1,71 @@
+!
+!$Id$
+!
+MODULE physics_distribution_mod
+
+
+CONTAINS
+
+  SUBROUTINE init_physics_distribution(grid_type, nvertex, &
+                                       nbp, nbp_lon, nbp_lat, nbp_lev, &
+                                       communicator)
+  USE mod_phys_lmdz_para, ONLY: init_phys_lmdz_para
+  USE mod_grid_phy_lmdz, ONLY: init_grid_phy_lmdz
+  IMPLICIT NONE
+    INTEGER,INTENT(IN) :: grid_type 
+    INTEGER,INTENT(IN) :: nvertex 
+    INTEGER,INTENT(IN) :: nbp           
+    INTEGER,INTENT(IN) :: nbp_lon
+    INTEGER,INTENT(IN) :: nbp_lat
+    INTEGER,INTENT(IN) :: nbp_lev
+    INTEGER,INTENT(IN) :: communicator
+
+
+    CALL init_grid_phy_lmdz(grid_type,nvertex, nbp_lon,nbp_lat,nbp_lev)
+    CALL init_phys_lmdz_para(nbp,nbp_lon, nbp_lat, communicator)
+
+  END SUBROUTINE init_physics_distribution  
+
+!SUBROUTINE Init_Phys_lmdz(iim,jjp1,llm,nb_proc,distrib)
+!  USE mod_phys_lmdz_para, ONLY: Init_phys_lmdz_para!, klon_omp
+!  USE mod_grid_phy_lmdz, ONLY: Init_grid_phy_lmdz!, nbp_lev
+!  USE dimphy, ONLY : Init_dimphy
+!  USE infotrac_phy, ONLY : type_trac
+!#ifdef REPROBUS
+!  USE CHEM_REP, ONLY : Init_chem_rep_phys
+!#endif
+
+!  IMPLICIT NONE
+  
+!    INTEGER,INTENT(in) :: iim
+!    INTEGER,INTENT(in) :: jjp1
+!    INTEGER,INTENT(in) :: llm
+!    INTEGER,INTENT(in) :: nb_proc
+!    INTEGER,INTENT(in) :: distrib(0:nb_proc-1)
+
+
+!    CALL Init_grid_phy_lmdz(iim,jjp1,llm)
+!    CALL Init_phys_lmdz_para(iim,jjp1,nb_proc,distrib)
+!!$OMP PARALLEL
+!    CALL Init_dimphy(klon_omp,nbp_lev)
+!
+!! Initialization of Reprobus
+!    IF (type_trac == 'repr') THEN
+!#ifdef REPROBUS
+!       CALL Init_chem_rep_phys(klon_omp,nbp_lev)
+!#endif
+!    END IF
+!
+!!$OMP END PARALLEL
+ 
+!END SUBROUTINE Init_Phys_lmdz  
+
+
+
+
+
+
+
+
+END MODULE physics_distribution_mod
+
Index: /LMDZ5/branches/testing/libf/phy_common/print_control_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/print_control_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/print_control_mod.F90	(revision 2408)
@@ -0,0 +1,63 @@
+! $Id: $
+MODULE print_control_mod
+
+  INTEGER,SAVE :: lunout ! default output file identifier (6==screen)
+  INTEGER,SAVE :: prt_level ! debug output level
+  LOGICAL,SAVE :: debug ! flag to specify if in "debug mode"
+!$OMP THREADPRIVATE(lunout,prt_level,debug)
+
+CONTAINS
+
+  SUBROUTINE init_print_control
+  USE ioipsl_getin_p_mod, ONLY : getin_p
+  USE mod_phys_lmdz_para, ONLY: is_omp_root, is_master
+  IMPLICIT NONE
+
+    LOGICAL :: opened
+    INTEGER :: number
+    
+    !Config  Key  = prt_level
+    !Config  Desc = niveau d'impressions de débogage
+    !Config  Def  = 0
+    !Config  Help = Niveau d'impression pour le débogage
+    !Config         (0 = minimum d'impression)
+    prt_level = 0
+    CALL getin_p('prt_level',prt_level)
+
+    !Config  Key  = lunout
+    !Config  Desc = unite de fichier pour les impressions
+    !Config  Def  = 6
+    !Config  Help = unite de fichier pour les impressions 
+    !Config         (defaut sortie standard = 6)
+    lunout=6
+    CALL getin_p('lunout', lunout)
+
+    IF (is_omp_root) THEN
+      IF (lunout /= 5 .and. lunout /= 6) THEN
+         INQUIRE(FILE='lmdz.out_0000',OPENED=opened,NUMBER=number)
+         IF (opened) THEN
+           lunout=number
+         ELSE
+           OPEN(UNIT=lunout,FILE='lmdz.out_0000',ACTION='write',  &
+                STATUS='unknown',FORM='formatted')
+         ENDIF
+      ENDIF
+    ENDIF
+
+    !Config  Key  = debug
+    !Config  Desc = mode debogage
+    !Config  Def  = false
+    !Config  Help = positionne le mode debogage
+
+    debug = .FALSE.
+    CALL getin_p('debug',debug)
+    
+    IF (is_master) THEN
+      WRITE(lunout,*)"init_print_control: prt_level=",prt_level
+      WRITE(lunout,*)"init_print_control: lunout=",lunout
+      WRITE(lunout,*)"init_print_control: debug=",debug      
+    ENDIF
+    
+  END SUBROUTINE init_print_control  
+
+END MODULE print_control_mod
Index: /LMDZ5/branches/testing/libf/phy_common/regular_lonlat_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/regular_lonlat_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/regular_lonlat_mod.F90	(revision 2408)
@@ -0,0 +1,55 @@
+MODULE regular_lonlat_mod
+
+  ! Store information on the global physics grid
+  ! for a regular (longitude-latitude) grid
+  
+  INTEGER, PARAMETER :: north_east=1     ! boundaries of regular lontlat
+  INTEGER, PARAMETER :: north_west=2     ! boundaries of regular lontlat
+  INTEGER, PARAMETER :: south_west=3     ! boundaries of regular lontlat
+  INTEGER, PARAMETER :: south_east=4     ! boundaries of regular lontlat
+  INTEGER, PARAMETER :: east=1           ! boundaries of regular lontlat
+  INTEGER, PARAMETER :: west=2           ! boundaries of regular lontlat
+  INTEGER, PARAMETER :: north=1          ! boundaries of regular lontlat
+  INTEGER, PARAMETER :: south=2          ! boundaries of regular lontlat
+
+! Global definition, shared by all threads
+! Do not set threadprivate directives
+
+  REAL,SAVE,ALLOCATABLE :: lon_reg(:)      ! value of longitude cell (rad)
+
+  REAL,SAVE,ALLOCATABLE :: lat_reg(:)      ! value of longitude cell (rad)
+
+  REAL,SAVE,ALLOCATABLE :: boundslon_reg(:,:)      ! value of boundaries cell (1=>east, 2=>west)(rad)
+
+  REAL,SAVE,ALLOCATABLE :: boundslat_reg(:,:)      ! value of longitude cell (1=>north, 2=>south)(rad)
+
+
+CONTAINS
+  
+  SUBROUTINE init_regular_lonlat(nbp_lon, nbp_lat, lon_reg_, lat_reg_, boundslon_reg_, boundslat_reg_)
+    IMPLICIT NONE
+    INTEGER,INTENT(IN) :: nbp_lon
+    INTEGER,INTENT(IN) :: nbp_lat
+    REAL,   INTENT(IN) :: lon_reg_(nbp_lon)  
+    REAL,   INTENT(IN) :: lat_reg_(nbp_lat) 
+    REAL,   INTENT(IN) :: boundslon_reg_(nbp_lon,2) 
+    REAL,   INTENT(IN) :: boundslat_reg_(nbp_lat,2)  
+
+    
+    ALLOCATE(lon_reg(nbp_lon))
+    lon_reg(:)=lon_reg_(:)
+
+    ALLOCATE(lat_reg(nbp_lat)) 
+    lat_reg(:)=lat_reg_(:)
+
+    ALLOCATE(boundslon_reg(nbp_lon,2)) 
+    boundslon_reg(:,:)=boundslon_reg_(:,:)
+
+    ALLOCATE(boundslat_reg(nbp_lat,2))  
+    boundslat_reg(:,:)=boundslat_reg_(:,:)
+
+  
+  END SUBROUTINE init_regular_lonlat    
+
+END MODULE regular_lonlat_mod
+
Index: /LMDZ5/branches/testing/libf/phy_common/write_field_phy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phy_common/write_field_phy.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phy_common/write_field_phy.F90	(revision 2408)
@@ -0,0 +1,37 @@
+!
+! $Id$
+!
+MODULE write_field_phy
+
+  ! Dump a field on the global (nbp_lon by nbp_lat) physics grid
+  
+  CONTAINS 
+ 
+    SUBROUTINE WriteField_phy(name,Field,ll)
+    USE mod_phys_lmdz_para, ONLY: klon_omp, is_mpi_root, &
+                                  Gather
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, &
+                                 Grid1Dto2D_glo
+    USE Write_Field, ONLY: WriteField
+    
+    IMPLICIT NONE
+
+    CHARACTER(len=*),INTENT(IN) :: name
+    INTEGER,INTENT(IN) :: ll
+    REAL,INTENT(IN) :: Field(klon_omp,ll)
+
+    real, dimension(klon_glo,ll):: New_Field
+    real, dimension(nbp_lon,nbp_lat,ll):: Field_2d
+
+    CALL Gather(Field,New_Field)
+!$OMP MASTER
+    IF (is_mpi_root) THEN	
+      CALL Grid1Dto2D_glo(New_Field,Field_2D)
+      CALL WriteField(name,Field_2d)
+    ENDIF
+!$OMP END MASTER
+
+  
+   END SUBROUTINE WriteField_phy
+ 
+ END MODULE write_field_phy
Index: DZ5/branches/testing/libf/phydev/comgeomphy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phydev/comgeomphy.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../phylmd/comgeomphy.F90
Index: /LMDZ5/branches/testing/libf/phydev/infotrac_phy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phydev/infotrac_phy.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phydev/infotrac_phy.F90	(revision 2408)
@@ -0,0 +1,27 @@
+
+! $Id: $
+
+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)
+
+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_
+
+    nqtot=nqtot_
+    type_trac=type_trac_
+  
+  END SUBROUTINE init_infotrac_phy
+
+END MODULE infotrac_phy
Index: /LMDZ5/branches/testing/libf/phydev/inifis_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phydev/inifis_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phydev/inifis_mod.F90	(revision 2408)
@@ -0,0 +1,28 @@
+! $Id: $
+MODULE inifis_mod
+
+CONTAINS
+
+  SUBROUTINE inifis(prad, pg, pr, pcpp)
+  ! Initialize some physical constants and settings
+  USE print_control_mod, ONLY: init_print_control
+  USE comcstphy, ONLY: rradius, & ! planet radius (m)
+                       rr, & ! recuced gas constant: R/molar mass of atm
+                       rg, & ! gravity
+                       rcpp  ! specific heat of the atmosphere
+  IMPLICIT NONE
+
+  REAL,INTENT(IN) :: prad, pg, pr, pcpp
+
+  ! Initialize flags lunout, prt_level, debug
+  CALL init_print_control
+
+  ! copy some fundamental parameters to physics
+  rradius=prad
+  rg=pg
+  rr=pr
+  rcpp=pcpp
+
+  END SUBROUTINE inifis
+  
+END MODULE inifis_mod
Index: DZ5/branches/testing/libf/phydev/init_phys_lmdz.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phydev/init_phys_lmdz.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../phylmd/init_phys_lmdz.F90
Index: /LMDZ5/branches/testing/libf/phydev/iophy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phydev/iophy.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phydev/iophy.F90	(revision 2408)
@@ -46,4 +46,6 @@
                                 is_sequential, is_south_pole
   USE mod_grid_phy_lmdz, only: nbp_lon, nbp_lat, klon_glo
+  USE print_control_mod, ONLY: lunout, prt_level
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
 #ifdef CPP_IOIPSL
   USE ioipsl, only: flio_dom_set
@@ -53,6 +55,4 @@
 #endif
   implicit none
-  include 'dimensions.h'
-  include 'iniprint.h'
     real,dimension(klon),intent(in) :: rlon
     real,dimension(klon),intent(in) :: rlat
@@ -77,15 +77,19 @@
     
 !$OMP MASTER  
-    ALLOCATE(io_lat(jjm+1-1/(iim*jjm)))
+    ALLOCATE(io_lat(nbp_lat))
     io_lat(1)=rlat_glo(1)
-    io_lat(jjm+1-1/(iim*jjm))=rlat_glo(klon_glo)
-    IF ((iim*jjm) > 1) then
-      DO i=2,jjm
-        io_lat(i)=rlat_glo(2+(i-2)*iim)
+    io_lat(nbp_lat)=rlat_glo(klon_glo)
+    IF ((nbp_lon*nbp_lat) > 1) then
+      DO i=2,nbp_lat-1
+        io_lat(i)=rlat_glo(2+(i-2)*nbp_lon)
       ENDDO
     ENDIF
 
-    ALLOCATE(io_lon(iim))
-    io_lon(:)=rlon_glo(2-1/(iim*jjm):iim+1-1/(iim*jjm))
+    ALLOCATE(io_lon(nbp_lon))
+    IF ((nbp_lon*nbp_lat) > 1) THEN
+      io_lon(:)=rlon_glo(2:nbp_lon+1)
+    ELSE
+      io_lon(1)=rlon_glo(1)
+    ENDIF
 !! (I) dtnb   : total number of domains
 !! (I) dnb    : domain number
@@ -103,13 +107,13 @@
 !!              These names are case insensitive.
     ddid=(/ 1,2 /)
-    dsg=(/ iim, jjm+1-1/(iim*jjm) /)
-    dsl=(/ iim, jj_nb /)
+    dsg=(/ nbp_lon, nbp_lat /)
+    dsl=(/ nbp_lon, jj_nb /)
     dpf=(/ 1,jj_begin /)
-    dpl=(/ iim, jj_end /)
+    dpl=(/ nbp_lon, jj_end /)
     dhs=(/ ii_begin-1,0 /)
     if (mpi_rank==mpi_size-1) then
       dhe=(/0,0/)
     else
-      dhe=(/ iim-ii_end,0 /)  
+      dhe=(/ nbp_lon-ii_end,0 /)  
     endif
     
@@ -155,6 +159,7 @@
   USE mod_phys_lmdz_para, only: is_sequential, jj_begin, jj_end, jj_nb
   use ioipsl, only: histbeg
+  USE print_control_mod, ONLY: prt_level, lunout
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon
   implicit none
-  include 'dimensions.h'
     
     character*(*), intent(IN) :: name
@@ -167,9 +172,9 @@
 !$OMP MASTER    
     if (is_sequential) then
-      call histbeg(name,iim,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
-                   1,iim,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
+      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
+                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
     else
-      call histbeg(name,iim,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
-                   1,iim,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
+      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
+                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
     endif
 !$OMP END MASTER
@@ -186,5 +191,4 @@
   use wxios, only: wxios_add_file
   IMPLICIT NONE
-  include 'dimensions.h'
     
     character*(*), INTENT(IN) :: name
@@ -219,6 +223,6 @@
                                 jj_nb, klon_mpi
   USE ioipsl, only: histwrite
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon
   implicit none
-  include 'dimensions.h'
     
     integer,intent(in) :: nid
@@ -229,10 +233,10 @@
     REAL,dimension(klon_mpi) :: buffer_omp
     INTEGER, allocatable, dimension(:) :: index2d
-    REAL :: Field2d(iim,jj_nb)
+    REAL :: Field2d(nbp_lon,jj_nb)
 
     integer :: ip
     real,allocatable,dimension(:) :: fieldok
 
-    IF (size(field)/=klon) CALL abort_gcm('iophy::histwrite2d','Field first dimension not equal to klon',1)
+    IF (size(field)/=klon) CALL abort_physic('iophy::histwrite2d','Field first dimension not equal to klon',1)
     
     CALL Gather_omp(field,buffer_omp)    
@@ -240,7 +244,7 @@
     CALL grid1Dto2D_mpi(buffer_omp,Field2d)
     if(.NOT.lpoint) THEN
-     ALLOCATE(index2d(iim*jj_nb))
-     ALLOCATE(fieldok(iim*jj_nb))
-     CALL histwrite(nid,name,itau,Field2d,iim*jj_nb,index2d)
+     ALLOCATE(index2d(nbp_lon*jj_nb))
+     ALLOCATE(fieldok(nbp_lon*jj_nb))
+     CALL histwrite(nid,name,itau,Field2d,nbp_lon*jj_nb,index2d)
     else
      ALLOCATE(fieldok(npstn))
@@ -278,6 +282,6 @@
                                 jj_nb, klon_mpi
   USE ioipsl, only: histwrite
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon
   implicit none
-  include 'dimensions.h'
     
     integer,intent(in) :: nid
@@ -287,10 +291,10 @@
     real,dimension(:,:),intent(in) :: field  ! --> field(klon,:)
     REAL,dimension(klon_mpi,size(field,2)) :: buffer_omp
-    REAL :: Field3d(iim,jj_nb,size(field,2))
+    REAL :: Field3d(nbp_lon,jj_nb,size(field,2))
     INTEGER :: ip, n, nlev
     INTEGER, ALLOCATABLE, dimension(:) :: index3d
     real,allocatable, dimension(:,:) :: fieldok
 
-    IF (size(field,1)/=klon) CALL abort_gcm('iophy::histwrite3d','Field first dimension not equal to klon',1)
+    IF (size(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first dimension not equal to klon',1)
     nlev=size(field,2)
 
@@ -299,7 +303,7 @@
     CALL grid1Dto2D_mpi(buffer_omp,field3d)
     if(.NOT.lpoint) THEN
-     ALLOCATE(index3d(iim*jj_nb*nlev))
-     ALLOCATE(fieldok(iim*jj_nb,nlev))
-     CALL histwrite(nid,name,itau,Field3d,iim*jj_nb*nlev,index3d)
+     ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
+     ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
+     CALL histwrite(nid,name,itau,Field3d,nbp_lon*jj_nb*nlev,index3d)
     else
       nlev=size(field,2)
@@ -341,9 +345,7 @@
                                 jj_nb, klon_mpi
   USE xios, only: xios_send_field
-
-
+  USE print_control_mod, ONLY: prt_level, lunout
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'
-  INCLUDE 'iniprint.h'
 
     CHARACTER(LEN=*), INTENT(IN) :: field_name
@@ -351,9 +353,9 @@
       
     REAL,DIMENSION(klon_mpi) :: buffer_omp
-    REAL :: Field2d(iim,jj_nb)
+    REAL :: Field2d(nbp_lon,jj_nb)
 
     IF (prt_level >= 10) WRITE(lunout,*)'Begin histrwrite2d_xios ',trim(field_name)
 
-    IF (SIZE(field)/=klon) CALL abort_gcm('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon',1)
+    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon',1)
     
     CALL Gather_omp(field,buffer_omp)    
@@ -377,9 +379,8 @@
                                 jj_nb, klon_mpi
   USE xios, only: xios_send_field
-
+  USE print_control_mod, ONLY: prt_level,lunout
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon
 
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'
-  INCLUDE 'iniprint.h'
 
     CHARACTER(LEN=*), INTENT(IN) :: field_name
@@ -387,5 +388,5 @@
 
     REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
-    REAL :: Field3d(iim,jj_nb,SIZE(field,2))
+    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
     INTEGER :: ip, n, nlev
 
@@ -393,5 +394,5 @@
 
     !Et on.... écrit
-    IF (SIZE(field,1)/=klon) CALL abort_gcm('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
+    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
     nlev=SIZE(field,2)
 
Index: /LMDZ5/branches/testing/libf/phydev/phyaqua_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phydev/phyaqua_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phydev/phyaqua_mod.F90	(revision 2408)
@@ -8,5 +8,5 @@
 CONTAINS
 
-  SUBROUTINE iniaqua(nlon, latfi, lonfi, iflag_phys)
+  SUBROUTINE iniaqua(nlon, iflag_phys)
 
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -15,22 +15,11 @@
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-  USE phys_state_var_mod, ONLY: rlat, rlon, phys_state_var_init
+  USE phys_state_var_mod, ONLY: phys_state_var_init
   USE mod_phys_lmdz_para, ONLY: klon_omp
-  USE comgeomphy, ONLY: rlond, rlatd
   IMPLICIT NONE
       
   INTEGER,INTENT(IN) :: nlon,iflag_phys
-  REAL,INTENT(IN) :: lonfi(nlon),latfi(nlon)
-
-  ! local variables
-  REAL :: pi
-
-  ! initializations:
-  pi=2.*ASIN(1.)
 
   CALL phys_state_var_init()
-
-  rlat(1:klon_omp)=rlatd(1:klon_omp)*180./pi
-  rlon(1:klon_omp)=rlond(1:klon_omp)*180./pi
 
 
Index: /LMDZ5/branches/testing/libf/phydev/phyetat0.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phydev/phyetat0.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phydev/phyetat0.F90	(revision 2408)
@@ -2,32 +2,64 @@
 ! $Id $
 !
-subroutine phyetat0(fichnom)
+SUBROUTINE phyetat0(fichnom)
 ! Load initial state for the physics
 ! and do some resulting initializations
 
-use iostart, only : open_startphy,get_field,close_startphy
-use iophy, only : init_iophy_new
-use phys_state_var_mod, only : rlat,rlon
+  USE dimphy, only: klon
+  USE iostart, ONLY : open_startphy,get_field,close_startphy
+  USE iophy, ONLY : init_iophy_new
+  USE geometry_mod, ONLY : longitude_deg, latitude_deg
 
-implicit none
+  IMPLICIT NONE
 
-character(len=*),intent(in) :: fichnom ! input file name
+  CHARACTER(len=*),INTENT(in) :: fichnom ! input file name
 
-! open physics initial state file:
-call open_startphy(fichnom)
+  REAL :: lon_startphy(klon), lat_startphy(klon)
+  INTEGER :: i
 
-! read latitudes
-call get_field("latitude",rlat)
+  ! open physics initial state file:
+  CALL open_startphy(fichnom)
 
-! read longitudes
-call get_field("longitude",rlon)
+  ! 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 in other variables here ...
+  ! 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
+      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
+    IF (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
+  ENDDO
 
-! close file
-call close_startphy
+  ! read in other variables here ...
 
-! do some more initializations
-call init_iophy_new(rlat,rlon)
+  ! close file
+  CALL close_startphy
 
-end subroutine phyetat0
+  ! do some more initializations
+  CALL init_iophy_new(latitude_deg,longitude_deg)
+
+END SUBROUTINE phyetat0
Index: /LMDZ5/branches/testing/libf/phydev/phyredem.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phydev/phyredem.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phydev/phyredem.F90	(revision 2408)
@@ -4,6 +4,6 @@
 SUBROUTINE phyredem (fichnom)
 
+  USE geometry_mod, ONLY : longitude_deg, latitude_deg
   USE iostart, ONLY: open_restartphy, close_restartphy, put_var, put_field
-  USE phys_state_var_mod, ONLY: rlon, rlat
 
   IMPLICIT NONE
@@ -27,7 +27,7 @@
   ! coordinates
 
-  CALL put_field("longitude", "Longitudes on physics grid", rlon)
+  CALL put_field("longitude", "Longitudes on physics grid", longitude_deg)
      
-  CALL put_field("latitude", "Latitudes on physics grid", rlat)
+  CALL put_field("latitude", "Latitudes on physics grid", latitude_deg)
 
   ! close file
Index: /LMDZ5/branches/testing/libf/phydev/phys_state_var_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phydev/phys_state_var_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phydev/phys_state_var_mod.F90	(revision 2408)
@@ -7,9 +7,9 @@
 !======================================================================
 
-USE dimphy, only : klon
+!USE dimphy, only : klon
  
 
-REAL, ALLOCATABLE, SAVE :: rlat(:), rlon(:)
-!$OMP THREADPRIVATE(rlat,rlon)
+!REAL, ALLOCATABLE, SAVE :: rlat(:), rlon(:)
+!!$OMP THREADPRIVATE(rlat,rlon)
 
 CONTAINS
@@ -17,11 +17,11 @@
 !======================================================================
   SUBROUTINE phys_state_var_init()
-  use dimphy, only : klon
+!  use dimphy, only : klon
 
-  if (.not.allocated(rlat)) then
-    ALLOCATE(rlat(klon),rlon(klon))
-  else
-    write(*,*) "phys_state_var_init: warning, rlat already allocated"
-  endif
+!  if (.not.allocated(rlat)) then
+!    ALLOCATE(rlat(klon),rlon(klon))
+!  else
+!    write(*,*) "phys_state_var_init: warning, rlat already allocated"
+!  endif
   
   END SUBROUTINE phys_state_var_init
@@ -29,7 +29,7 @@
 !======================================================================
   SUBROUTINE phys_state_var_end
-  use dimphy, only : klon
+!  use dimphy, only : klon
 
-  deallocate(rlat,rlon)
+!  deallocate(rlat,rlon)
 
   END SUBROUTINE phys_state_var_end
Index: /LMDZ5/branches/testing/libf/phydev/physiq.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phydev/physiq.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phydev/physiq.F90	(revision 2408)
@@ -5,5 +5,5 @@
      &            debut,lafin,jD_cur, jH_cur,pdtphys, &
      &            paprs,pplay,pphi,pphis,presnivs, &
-     &            u,v,t,qx, &
+     &            u,v,rot,t,qx, &
      &            flxmass_w, &
      &            d_u, d_v, d_t, d_qx, d_ps &
@@ -11,6 +11,6 @@
 
       USE dimphy, only : klon,klev
-      USE infotrac, only : nqtot
-      USE comgeomphy, only : rlatd
+      USE infotrac_phy, only : nqtot
+      USE geometry_mod, only : latitude
       USE comcstphy, only : rg
       USE iophy, only : histbeg_phy,histwrite_phy
@@ -18,4 +18,5 @@
       USE mod_phys_lmdz_para, only : jj_nb
       USE phys_state_var_mod, only : phys_state_var_init
+      USE mod_grid_phy_lmdz, ONLY: nbp_lon,nbp_lat
 
 #ifdef CPP_XIOS
@@ -26,8 +27,4 @@
 
       IMPLICIT none
-#include "dimensions.h"
-
-      integer,parameter :: jjmp1=jjm+1-1/jjm
-      integer,parameter :: iip1=iim+1
 !
 ! Routine argument:
@@ -55,5 +52,7 @@
       real,intent(out) :: d_qx(klon,klev,nqtot) ! physics tendency on tracers
       real,intent(out) :: d_ps(klon) ! physics tendency on surface pressure
-      real,intent(in) :: dudyn(iim+1,jjmp1,klev) ! Not used
+      real,intent(in) :: dudyn(nbp_lon+1,nbp_lat,klev) ! Not used
+      REAL, intent(in):: rot(klon, klev) ! Not used
+      ! relative vorticity, in s-1, needed for frontal waves 
 
 integer,save :: itau=0 ! counter to count number of calls to physics
@@ -114,14 +113,14 @@
   ! define variables which will be written in "histins.nc" file
   call histdef(nid_hist,'temperature','Atmospheric temperature','K', &
-               iim,jj_nb,nhori,klev,1,klev,zvertid,32, &
+               nbp_lon,jj_nb,nhori,klev,1,klev,zvertid,32, &
                'inst(X)',t_ops,t_wrt)
   call histdef(nid_hist,'u','Eastward Zonal Wind','m/s', &
-               iim,jj_nb,nhori,klev,1,klev,zvertid,32, &
+               nbp_lon,jj_nb,nhori,klev,1,klev,zvertid,32, &
                'inst(X)',t_ops,t_wrt)
   call histdef(nid_hist,'v','Northward Meridional Wind','m/s', &
-               iim,jj_nb,nhori,klev,1,klev,zvertid,32, &
+               nbp_lon,jj_nb,nhori,klev,1,klev,zvertid,32, &
                'inst(X)',t_ops,t_wrt)
   call histdef(nid_hist,'ps','Surface Pressure','Pa', &
-               iim,jj_nb,nhori,1,1,1,zvertid,32, &
+               nbp_lon,jj_nb,nhori,1,1,1,zvertid,32, &
                'inst(X)',t_ops,t_wrt)
   ! end definition sequence
@@ -160,5 +159,5 @@
 ! newtonian relaxation towards temp_newton()
 do k=1,klev
-  temp_newton(1:klon,k)=280.+cos(rlatd(1:klon))*40.-pphi(1:klon,k)/rg*6.e-3
+  temp_newton(1:klon,k)=280.+cos(latitude(1:klon))*40.-pphi(1:klon,k)/rg*6.e-3
   d_t(1:klon,k)=(temp_newton(1:klon,k)-t(1:klon,k))/1.e5
 enddo
Index: /LMDZ5/branches/testing/libf/phylmd/YOEGWD.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/YOEGWD.h	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/YOEGWD.h	(revision 2408)
@@ -20,8 +20,12 @@
 !     S_c in equation (12) of Lott (JGR, vol 118, page 8897, 2013)
 
+      REAL GWD_FRONT_RUWMAX,GWD_FRONT_SAT 
+! Same as GWD_RANDO params but for fronal GWs
+
 
       COMMON/YOEGWD/ GFRCRIT,GKWAKE,GRCRIT,GVCRIT,GKDRAG,GKLIFT,        &
      &     GHMAX,GRAHILO,GSIGCR,NKTOPG,NSTRA,GSSEC,GTSEC,GVSEC,         &
-     &     GWD_RANDO_RUWMAX, gwd_rando_sat
+     &     GWD_RANDO_RUWMAX, gwd_rando_sat,                             &
+     &     GWD_FRONT_RUWMAX, gwd_front_sat
 
       save /YOEGWD/
Index: /LMDZ5/branches/testing/libf/phylmd/aaam_bud.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/aaam_bud.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/aaam_bud.F90	(revision 2408)
@@ -6,4 +6,5 @@
 
   USE dimphy
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo
   IMPLICIT NONE
   ! ======================================================================
@@ -58,8 +59,8 @@
   ! ===================
 
-  ! iim--common-I: Number of longitude intervals
-  ! jjm--common-I: Number of latitude intervals
+  ! nbp_lon--common-I: Number of longitude intervals
+  ! (nbp_lat-1)--common-I: Number of latitude intervals
   ! klon-common-I: Number of points seen by the physics
-  ! iim*(jjm-1)+2 for instance
+  ! nbp_lon*(nbp_lat-2)+2 for instance
   ! klev-common-I: Number of vertical layers
   ! ======================================================================
@@ -84,7 +85,4 @@
   ! ======================================================================
 
-  include "dimensions.h"
-  ! cc#include "dimphy.h"
-
   ! ARGUMENTS
 
@@ -121,7 +119,7 @@
   ! PUT AAM QUANTITIES AT ZERO:
 
-  IF (iim+1>801 .OR. jjm+1>401) THEN
+  IF (nbp_lon+1>801 .OR. nbp_lat>401) THEN
     abort_message = 'Pb de dimension dans aaam_bud'
-    CALL abort_gcm(modname, abort_message, 1)
+    CALL abort_physic(modname, abort_message, 1)
   END IF
 
@@ -129,6 +127,10 @@
   hadley = 1.E18
   hadday = 1.E18*24.*3600.
-  dlat = xpi/real(jjm)
-  dlon = 2.*xpi/real(iim)
+  IF(klon_glo.EQ.1) THEN
+    dlat = xpi
+  ELSE
+    dlat = xpi/real(nbp_lat-1)
+  ENDIF
+  dlon = 2.*xpi/real(nbp_lon)
 
   DO iax = 1, 3
@@ -155,5 +157,5 @@
   zlat(1) = plat(l)*xpi/180.
 
-  DO i = 1, iim + 1
+  DO i = 1, nbp_lon + 1
 
     zs(i, 1) = phis(l)/rg
@@ -169,26 +171,26 @@
 
 
-  DO j = 2, jjm
+  DO j = 2, nbp_lat-1
 
     ! Values at Greenwich (Periodicity)
 
-    zs(iim+1, j) = phis(l+1)/rg
-    ps(iim+1, j) = p(l+1, 1)
-    ssou(iim+1, j) = dragu(l+1) + liftu(l+1)
-    ssov(iim+1, j) = dragv(l+1) + liftv(l+1)
-    blsu(iim+1, j) = phyu(l+1) - dragu(l+1) - liftu(l+1)
-    blsv(iim+1, j) = phyv(l+1) - dragv(l+1) - liftv(l+1)
-    zlon(iim+1) = -plon(l+1)*xpi/180.
+    zs(nbp_lon+1, j) = phis(l+1)/rg
+    ps(nbp_lon+1, j) = p(l+1, 1)
+    ssou(nbp_lon+1, j) = dragu(l+1) + liftu(l+1)
+    ssov(nbp_lon+1, j) = dragv(l+1) + liftv(l+1)
+    blsu(nbp_lon+1, j) = phyu(l+1) - dragu(l+1) - liftu(l+1)
+    blsv(nbp_lon+1, j) = phyv(l+1) - dragv(l+1) - liftv(l+1)
+    zlon(nbp_lon+1) = -plon(l+1)*xpi/180.
     zlat(j) = plat(l+1)*xpi/180.
 
-    ub(iim+1, j) = 0.
-    vb(iim+1, j) = 0.
+    ub(nbp_lon+1, j) = 0.
+    vb(nbp_lon+1, j) = 0.
     DO k = 1, nlev
-      ub(iim+1, j) = ub(iim+1, j) + u(l+1, k)*(p(l+1,k)-p(l+1,k+1))/rg
-      vb(iim+1, j) = vb(iim+1, j) + v(l+1, k)*(p(l+1,k)-p(l+1,k+1))/rg
-    END DO
-
-
-    DO i = 1, iim
+      ub(nbp_lon+1, j) = ub(nbp_lon+1, j) + u(l+1, k)*(p(l+1,k)-p(l+1,k+1))/rg
+      vb(nbp_lon+1, j) = vb(nbp_lon+1, j) + v(l+1, k)*(p(l+1,k)-p(l+1,k+1))/rg
+    END DO
+
+
+    DO i = 1, nbp_lon
 
       l = l + 1
@@ -215,23 +217,23 @@
   ! South Pole
 
-  IF (jjm>1) THEN
+  IF (nbp_lat-1>1) THEN
     l = l + 1
-    ub(1, jjm+1) = 0.
-    vb(1, jjm+1) = 0.
+    ub(1, nbp_lat) = 0.
+    vb(1, nbp_lat) = 0.
     DO k = 1, nlev
-      ub(1, jjm+1) = ub(1, jjm+1) + u(l, k)*(p(l,k)-p(l,k+1))/rg
-      vb(1, jjm+1) = vb(1, jjm+1) + v(l, k)*(p(l,k)-p(l,k+1))/rg
-    END DO
-    zlat(jjm+1) = plat(l)*xpi/180.
-
-    DO i = 1, iim + 1
-      zs(i, jjm+1) = phis(l)/rg
-      ps(i, jjm+1) = p(l, 1)
-      ssou(i, jjm+1) = dragu(l) + liftu(l)
-      ssov(i, jjm+1) = dragv(l) + liftv(l)
-      blsu(i, jjm+1) = phyu(l) - dragu(l) - liftu(l)
-      blsv(i, jjm+1) = phyv(l) - dragv(l) - liftv(l)
-      ub(i, jjm+1) = ub(1, jjm+1)
-      vb(i, jjm+1) = vb(1, jjm+1)
+      ub(1, nbp_lat) = ub(1, nbp_lat) + u(l, k)*(p(l,k)-p(l,k+1))/rg
+      vb(1, nbp_lat) = vb(1, nbp_lat) + v(l, k)*(p(l,k)-p(l,k+1))/rg
+    END DO
+    zlat(nbp_lat) = plat(l)*xpi/180.
+
+    DO i = 1, nbp_lon + 1
+      zs(i, nbp_lat) = phis(l)/rg
+      ps(i, nbp_lat) = p(l, 1)
+      ssou(i, nbp_lat) = dragu(l) + liftu(l)
+      ssov(i, nbp_lat) = dragv(l) + liftv(l)
+      blsu(i, nbp_lat) = phyu(l) - dragu(l) - liftu(l)
+      blsv(i, nbp_lat) = phyv(l) - dragv(l) - liftv(l)
+      ub(i, nbp_lat) = ub(1, nbp_lat)
+      vb(i, nbp_lat) = vb(1, nbp_lat)
     END DO
   END IF
@@ -240,6 +242,6 @@
   ! MOMENT ANGULAIRE
 
-  DO j = 1, jjm
-    DO i = 1, iim
+  DO j = 1, nbp_lat-1
+    DO i = 1, nbp_lon
 
       raam(1) = raam(1) - rea**3*dlon*dlat*0.5*(cos(zlon(i))*sin(zlat(j))*cos &
@@ -274,6 +276,6 @@
 
 
-  DO j = 1, jjm
-    DO i = 1, iim
+  DO j = 1, nbp_lat-1
+    DO i = 1, nbp_lon
       tmou(1) = tmou(1) - rea**2*dlon*0.5*sin(zlon(i))*(zs(i,j)-zs(i,j+1))*( &
         cos(zlat(j+1))*ps(i,j+1)+cos(zlat(j))*ps(i,j))
@@ -283,6 +285,6 @@
   END DO
 
-  DO j = 2, jjm
-    DO i = 1, iim
+  DO j = 2, nbp_lat-1
+    DO i = 1, nbp_lon
       tmou(1) = tmou(1) + rea**2*dlat*0.5*sin(zlat(j))*(zs(i+1,j)-zs(i,j))*( &
         cos(zlon(i+1))*ps(i+1,j)+cos(zlon(i))*ps(i,j))
@@ -298,6 +300,6 @@
 
   l = 1
-  DO j = 2, jjm
-    DO i = 1, iim
+  DO j = 2, nbp_lat-1
+    DO i = 1, nbp_lon
       l = l + 1
       tsso(1) = tsso(1) - rea**3*cos(zlat(j))*dlon*dlat*ssou(i, j)*sin(zlat(j &
@@ -341,12 +343,12 @@
 100 FORMAT (F12.5, 15(1X,F12.5))
 
-  ! write(iam+1,*)((zs(i,j),i=1,iim),j=1,jjm+1)
-  ! write(iam+1,*)((ps(i,j),i=1,iim),j=1,jjm+1)
-  ! write(iam+1,*)((ub(i,j),i=1,iim),j=1,jjm+1)
-  ! write(iam+1,*)((vb(i,j),i=1,iim),j=1,jjm+1)
-  ! write(iam+1,*)((ssou(i,j),i=1,iim),j=1,jjm+1)
-  ! write(iam+1,*)((ssov(i,j),i=1,iim),j=1,jjm+1)
-  ! write(iam+1,*)((blsu(i,j),i=1,iim),j=1,jjm+1)
-  ! write(iam+1,*)((blsv(i,j),i=1,iim),j=1,jjm+1)
+  ! write(iam+1,*)((zs(i,j),i=1,nbp_lon),j=1,nbp_lat)
+  ! write(iam+1,*)((ps(i,j),i=1,nbp_lon),j=1,nbp_lat)
+  ! write(iam+1,*)((ub(i,j),i=1,nbp_lon),j=1,nbp_lat)
+  ! write(iam+1,*)((vb(i,j),i=1,nbp_lon),j=1,nbp_lat)
+  ! write(iam+1,*)((ssou(i,j),i=1,nbp_lon),j=1,nbp_lat)
+  ! write(iam+1,*)((ssov(i,j),i=1,nbp_lon),j=1,nbp_lat)
+  ! write(iam+1,*)((blsu(i,j),i=1,nbp_lon),j=1,nbp_lat)
+  ! write(iam+1,*)((blsv(i,j),i=1,nbp_lon),j=1,nbp_lat)
 
   aam = raam(3)
Index: /LMDZ5/branches/testing/libf/phylmd/acama_gwd_rando_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/acama_gwd_rando_m.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/acama_gwd_rando_m.F90	(revision 2408)
@@ -0,0 +1,493 @@
+module ACAMA_GWD_rando_m
+
+  implicit none
+
+contains
+
+  SUBROUTINE ACAMA_GWD_rando(DTIME, pp, plat, tt, uu, vv, rot, &
+       zustr, zvstr, d_u, d_v,east_gwstress,west_gwstress)
+
+    ! Parametrization of the momentum flux deposition due to a discrete
+    ! number of gravity waves. 
+    ! Author: F. Lott, A. de la Camara
+    ! July, 24th, 2014
+    ! Gaussian distribution of the source, source is vorticity squared
+    ! Reference: de la Camara and Lott (GRL, 2015, vol 42, 2071-2078 )
+    ! Lott et al (JAS, 2010, vol 67, page 157-170)
+    ! Lott et al (JAS, 2012, vol 69, page 2134-2151)
+
+!  ONLINE:
+    use dimphy, only: klon, klev
+    use assert_m, only: assert
+    include "YOMCST.h"
+    include "clesphys.h"
+!  OFFLINE:
+!   include "dimensions.h"
+!   include "dimphy.h"
+!END DIFFERENCE
+    include "YOEGWD.h"
+
+    ! 0. DECLARATIONS:
+
+    ! 0.1 INPUTS
+    REAL, intent(in)::DTIME ! Time step of the Physics
+    REAL, intent(in):: PP(:, :) ! (KLON, KLEV) Pressure at full levels
+    REAL, intent(in):: ROT(:,:) ! Relative vorticity              
+    REAL, intent(in):: TT(:, :) ! (KLON, KLEV) Temp at full levels 
+    REAL, intent(in):: UU(:, :) ! (KLON, KLEV) Zonal wind at full levels
+    REAL, intent(in):: VV(:, :) ! (KLON, KLEV) Merid wind at full levels
+    REAL, intent(in):: PLAT(:) ! (KLON) LATITUDE                   
+
+    ! 0.2 OUTPUTS
+    REAL, intent(out):: zustr(:), zvstr(:) ! (KLON) Surface Stresses
+
+    REAL, intent(inout):: d_u(:, :), d_v(:, :) 
+    REAL, intent(inout):: east_gwstress(:, :) !  Profile of eastward stress
+    REAL, intent(inout):: west_gwstress(:, :) !  Profile of westward stress 
+    ! (KLON, KLEV) tendencies on winds
+
+    ! O.3 INTERNAL ARRAYS
+    REAL BVLOW(klon)  !  LOW LEVEL BV FREQUENCY
+    REAL ROTBA(KLON),CORIO(KLON)  !  BAROTROPIC REL. VORTICITY AND PLANETARY
+    REAL UZ(KLON, KLEV + 1)
+
+    INTEGER II, JJ, LL
+
+    ! 0.3.0 TIME SCALE OF THE LIFE CYCLE OF THE WAVES PARAMETERIZED
+
+    REAL DELTAT
+
+    ! 0.3.1 GRAVITY-WAVES SPECIFICATIONS
+
+    INTEGER, PARAMETER:: NK = 2, NP = 2, NO = 2, NW = NK * NP * NO
+    INTEGER JK, JP, JO, JW
+    INTEGER, PARAMETER:: NA = 5  !number of realizations to get the phase speed
+    REAL KMIN, KMAX ! Min and Max horizontal wavenumbers
+    REAL CMIN, CMAX ! Min and Max absolute ph. vel.
+    REAL CPHA ! absolute PHASE VELOCITY frequency
+    REAL ZK(NW, KLON) ! Horizontal wavenumber amplitude
+    REAL ZP(NW, KLON) ! Horizontal wavenumber angle 
+    REAL ZO(NW, KLON) ! Absolute frequency !
+
+    ! Waves Intr. freq. at the 1/2 lev surrounding the full level
+    REAL ZOM(NW, KLON), ZOP(NW, KLON)
+
+    ! Wave EP-fluxes at the 2 semi levels surrounding the full level
+    REAL WWM(NW, KLON), WWP(NW, KLON)
+
+    REAL RUW0(NW, KLON) ! Fluxes at launching level
+
+    REAL RUWP(NW, KLON), RVWP(NW, KLON)
+    ! Fluxes X and Y for each waves at 1/2 Levels
+
+    INTEGER LAUNCH, LTROP ! Launching altitude and tropo altitude
+
+    REAL XLAUNCH ! Controle the launching altitude
+    REAL XTROP ! SORT of Tropopause altitude 
+    REAL RUW(KLON, KLEV + 1) ! Flux x at semi levels
+    REAL RVW(KLON, KLEV + 1) ! Flux y at semi levels
+
+    REAL PRMAX ! Maximum value of PREC, and for which our linear formula
+    ! for GWs parameterisation apply
+
+    ! 0.3.2 PARAMETERS OF WAVES DISSIPATIONS
+
+    REAL RDISS, ZOISEC ! COEFF DE DISSIPATION, SECURITY FOR INTRINSIC FREQ
+    REAL CORSEC ! SECURITY FOR INTRINSIC CORIOLIS
+    REAL RUWFRT,SATFRT
+
+    ! 0.3.3 BACKGROUND FLOW AT 1/2 LEVELS AND VERTICAL COORDINATE
+
+    REAL H0 ! Characteristic Height of the atmosphere
+    REAL DZ ! Characteristic depth of the source!
+    REAL PR, TR ! Reference Pressure and Temperature
+
+    REAL ZH(KLON, KLEV + 1) ! Log-pressure altitude
+
+    REAL UH(KLON, KLEV + 1), VH(KLON, KLEV + 1) ! Winds at 1/2 levels
+    REAL PH(KLON, KLEV + 1) ! Pressure at 1/2 levels
+    REAL PSEC ! Security to avoid division by 0 pressure
+    REAL PHM1(KLON, KLEV + 1) ! 1/Press at 1/2 levels
+    REAL BV(KLON, KLEV + 1) ! Brunt Vaisala freq. (BVF) at 1/2 levels
+    REAL BVSEC ! Security to avoid negative BVF
+
+    !-----------------------------------------------------------------
+
+    ! 1. INITIALISATIONS
+
+    ! 1.1 Basic parameter
+
+    ! Are provided from elsewhere (latent heat of vaporization, dry
+    ! gaz constant for air, gravity constant, heat capacity of dry air
+    ! at constant pressure, earth rotation rate, pi).
+
+    ! 1.2 Tuning parameters of V14
+
+! Values for linear in rot (recommended):
+!   RUWFRT=0.005 ! As RUWMAX but for frontal waves 
+!   SATFRT=1.00  ! As SAT    but for frontal waves
+! Values when rot^2 is used                          
+!    RUWFRT=0.02  ! As RUWMAX but for frontal waves 
+!    SATFRT=1.00  ! As SAT    but for frontal waves
+!    CMAX = 30.   ! Characteristic phase speed
+! Values when rot^2*EXP(-pi*sqrt(J)) is used                          
+!   RUWFRT=2.5   ! As RUWMAX but for frontal waves ~ N0*F0/4*DZ
+!   SATFRT=0.60   ! As SAT    but for frontal waves
+    RUWFRT=gwd_front_ruwmax  
+    SATFRT=gwd_front_sat
+    CMAX = 40.    ! Characteristic phase speed
+! Phase speed test
+!   RUWFRT=0.01
+!   CMAX = 50.   ! Characteristic phase speed (TEST)
+! Values when rot^2 and exp(-m^2*dz^2) are used      
+!   RUWFRT=0.03  ! As RUWMAX but for frontal waves 
+!   SATFRT=1.00  ! As SAT    but for frontal waves
+! CRUCIAL PARAMETERS FOR THE WIND FILTERING
+    XLAUNCH=0.95 ! Parameter that control launching altitude
+    RDISS = 1    ! Diffusion parameter 
+
+    ! maximum of rain for which our theory applies (in kg/m^2/s)
+
+    DZ = 1000. ! Characteristic depth of the source
+    XTROP=0.2 ! Parameter that control tropopause altitude
+    DELTAT=24.*3600. ! Time scale of the waves (first introduced in 9b)
+!   DELTAT=DTIME     ! No AR-1 Accumulation, OR OFFLINE             
+
+    KMIN = 2.E-5
+    ! minimum horizontal wavenumber (inverse of the subgrid scale resolution)
+
+    KMAX = 1.E-3  ! Max horizontal wavenumber
+    CMIN = 1.     ! Min phase velocity
+
+    TR = 240. ! Reference Temperature
+    PR = 101300. ! Reference pressure
+    H0 = RD * TR / RG ! Characteristic vertical scale height
+
+    BVSEC = 5.E-3 ! Security to avoid negative BVF 
+    PSEC = 1.E-6 ! Security to avoid division by 0 pressure
+    ZOISEC = 1.E-6 ! Security FOR 0 INTRINSIC FREQ
+    CORSEC = ROMEGA*2.*SIN(2.*RPI/180.)! Security for CORIO
+
+!  ONLINE
+    call assert(klon == (/size(pp, 1), size(tt, 1), size(uu, 1), &
+         size(vv, 1), size(rot,1), size(zustr), size(zvstr), size(d_u, 1), &
+         size(d_v, 1), &
+        size(east_gwstress,1), size(west_gwstress,1) /), &
+        "ACAMA_GWD_RANDO klon")
+    call assert(klev == (/size(pp, 2), size(tt, 2), size(uu, 2), &
+         size(vv, 2), size(d_u, 2), size(d_v, 2), &
+         size(east_gwstress,2), size(west_gwstress,2) /), &
+         "ACAMA_GWD_RANDO klev")
+!  END ONLINE
+
+    IF(DELTAT < DTIME)THEN
+       PRINT *, 'flott_gwd_rando: deltat < dtime!'
+       STOP 1
+    ENDIF
+
+    IF (KLEV < NW) THEN
+       PRINT *, 'flott_gwd_rando: you will have problem with random numbers'
+       STOP 1
+    ENDIF
+
+    ! 2. EVALUATION OF THE BACKGROUND FLOW AT SEMI-LEVELS
+
+    ! Pressure and Inv of pressure
+    DO LL = 2, KLEV
+       PH(:, LL) = EXP((LOG(PP(:, LL)) + LOG(PP(:, LL - 1))) / 2.)
+       PHM1(:, LL) = 1. / PH(:, LL) 
+    end DO
+
+    PH(:, KLEV + 1) = 0. 
+    PHM1(:, KLEV + 1) = 1. / PSEC
+    PH(:, 1) = 2. * PP(:, 1) - PH(:, 2)
+
+    ! Launching altitude
+
+    LAUNCH=0
+    LTROP =0
+    DO LL = 1, KLEV
+       IF (PH(KLON / 2, LL) / PH(KLON / 2, 1) > XLAUNCH) LAUNCH = LL
+    ENDDO
+    DO LL = 1, KLEV
+       IF (PH(KLON / 2, LL) / PH(KLON / 2, 1) > XTROP) LTROP = LL
+    ENDDO
+
+!   PRINT *,'LAUNCH IN ACAMARA:',LAUNCH
+
+    ! Log pressure vert. coordinate
+    DO LL = 1, KLEV + 1 
+       ZH(:, LL) = H0 * LOG(PR / (PH(:, LL) + PSEC))
+    end DO
+
+    ! BV frequency
+    DO LL = 2, KLEV
+       ! BVSEC: BV Frequency (UH USED IS AS A TEMPORARY ARRAY DOWN TO WINDS)
+       UH(:, LL) = 0.5 * (TT(:, LL) + TT(:, LL - 1)) &
+            * RD**2 / RCPD / H0**2 + (TT(:, LL) &
+            - TT(:, LL - 1)) / (ZH(:, LL) - ZH(:, LL - 1)) * RD / H0
+    end DO
+    BVLOW = 0.5 * (TT(:, LTROP )+ TT(:, LAUNCH)) &
+         * RD**2 / RCPD / H0**2 + (TT(:, LTROP ) &
+         - TT(:, LAUNCH))/(ZH(:, LTROP )- ZH(:, LAUNCH)) * RD / H0
+
+    UH(:, 1) = UH(:, 2)
+    UH(:, KLEV + 1) = UH(:, KLEV)
+    BV(:, 1) = UH(:, 2)
+    BV(:, KLEV + 1) = UH(:, KLEV)
+    ! SMOOTHING THE BV HELPS
+    DO LL = 2, KLEV
+       BV(:, LL)=(UH(:, LL+1)+2.*UH(:, LL)+UH(:, LL-1))/4.
+    end DO
+
+    BV=MAX(SQRT(MAX(BV, 0.)), BVSEC)
+    BVLOW=MAX(SQRT(MAX(BVLOW, 0.)), BVSEC)
+
+    ! WINDS
+    DO LL = 2, KLEV
+       UH(:, LL) = 0.5 * (UU(:, LL) + UU(:, LL - 1)) ! Zonal wind
+       VH(:, LL) = 0.5 * (VV(:, LL) + VV(:, LL - 1)) ! Meridional wind
+       UZ(:, LL) = ABS((SQRT(UU(:, LL)**2+VV(:, LL)**2) & 
+          - SQRT(UU(:,LL-1)**2+VV(:, LL-1)**2)) &
+          /(ZH(:, LL)-ZH(:, LL-1)) )
+    end DO
+    UH(:, 1) = 0.
+    VH(:, 1) = 0.
+    UH(:, KLEV + 1) = UU(:, KLEV)
+    VH(:, KLEV + 1) = VV(:, KLEV)
+
+    UZ(:, 1) = UZ(:, 2)
+    UZ(:, KLEV + 1) = UZ(:, KLEV)
+    UZ(:, :) = MAX(UZ(:,:), PSEC)
+
+   ! BAROTROPIC VORTICITY AND INTEGRATED CORIOLIS PARAMETER
+    
+    CORIO(:) = MAX(ROMEGA*2.*ABS(SIN(PLAT(:)*RPI/180.)),CORSEC)
+    ROTBA(:)=0.
+    DO LL = 1,KLEV-1
+        !ROTBA(:) = ROTBA(:) + (ROT(:,LL)+ROT(:,LL+1))/2./RG*(PP(:,LL)-PP(:,LL+1))
+        ! Introducing the complete formula (exp of Richardson number):
+        ROTBA(:) = ROTBA(:) + &
+                !((ROT(:,LL)+ROT(:,LL+1))/2.)**2 &
+                (CORIO(:)*TANH(ABS(ROT(:,LL)+ROT(:,LL+1))/2./CORIO(:)))**2 &
+                /RG*(PP(:,LL)-PP(:,LL+1)) &
+                * EXP(-RPI*BV(:,LL+1)/UZ(:,LL+1)) &
+!               * DZ*BV(:,LL+1)/4./ABS(CORIO(:)) 
+                * DZ*BV(:,LL+1)/4./1.E-4           !  Changes after 1991
+!ARRET
+    ENDDO
+    !   PRINT *,'MAX ROTBA:',MAXVAL(ROTBA)
+    !   ROTBA(:)=(1.*ROTBA(:)  & ! Testing zone
+    !           +0.15*CORIO(:)**2                &
+    !           /(COS(PLAT(:)*RPI/180.)+0.02)  &
+    !           )*DZ*0.01/0.0001/4. ! & ! Testing zone
+    !   MODIF GWD4 AFTER 1985
+    !            *(1.25+SIN(PLAT(:)*RPI/180.))/(1.05+SIN(PLAT(:)*RPI/180.))/1.25
+    !          *1./(COS(PLAT(:)*RPI/180.)+0.02)
+    !    CORIO(:) = MAX(ROMEGA*2.*ABS(SIN(PLAT(:)*RPI/180.)),ZOISEC)/RG*PP(:,1)
+
+    ! 3 WAVES CHARACTERISTICS CHOSEN RANDOMLY AT THE LAUNCH ALTITUDE
+
+    ! The mod functions of weird arguments are used to produce the
+    ! waves characteristics in an almost stochastic way
+
+    JW = 0
+    DO JP = 1, NP
+       DO JK = 1, NK
+          DO JO = 1, NO
+             JW = JW + 1
+             ! Angle
+             DO II = 1, KLON
+                ! Angle (0 or PI so far)
+                ! ZP(JW, II) = (SIGN(1., 0.5 - MOD(TT(II, JW) * 10., 1.)) + 1.) &
+                !      * RPI / 2.
+                ! Angle between 0 and pi
+                  ZP(JW, II) = MOD(TT(II, JW) * 10., 1.) * RPI
+! TEST WITH POSITIVE WAVES ONLY (Part I/II)
+!               ZP(JW, II) = 0.
+                ! Horizontal wavenumber amplitude
+                ZK(JW, II) = KMIN + (KMAX - KMIN) * MOD(TT(II, JW) * 100., 1.)
+                ! Horizontal phase speed
+                CPHA = 0.
+                DO JJ = 1, NA
+                    CPHA = CPHA + &
+         CMAX*2.*(MOD(TT(II, JW+4*(JJ-1)+JJ)**2, 1.)-0.5)*SQRT(3.)/SQRT(NA*1.)
+                END DO
+                IF (CPHA.LT.0.)  THEN
+                   CPHA = -1.*CPHA
+                   ZP(JW,II) = ZP(JW,II) + RPI
+! TEST WITH POSITIVE WAVES ONLY (Part II/II)
+!               ZP(JW, II) = 0.
+                ENDIF
+                CPHA = CPHA + CMIN !we dont allow |c|<1m/s
+                ! Absolute frequency is imposed
+                ZO(JW, II) = CPHA * ZK(JW, II) 
+                ! Intrinsic frequency is imposed
+                ZO(JW, II) = ZO(JW, II) &
+                     + ZK(JW, II) * COS(ZP(JW, II)) * UH(II, LAUNCH) &
+                     + ZK(JW, II) * SIN(ZP(JW, II)) * VH(II, LAUNCH)
+                ! Momentum flux at launch lev 
+                ! LAUNCHED RANDOM WAVES WITH LOG-NORMAL AMPLITUDE
+                !  RIGHT IN THE SH (GWD4 after 1990)
+                  RUW0(JW, II) = 0.
+                 DO JJ = 1, NA
+                    RUW0(JW, II) = RUW0(JW,II) + &
+         2.*(MOD(TT(II, JW+4*(JJ-1)+JJ)**2, 1.)-0.5)*SQRT(3.)/SQRT(NA*1.)
+                END DO
+                RUW0(JW, II) = RUWFRT &
+                          * EXP(RUW0(JW,II))/1250. &  ! 2 mpa at south pole
+       *((1.05+SIN(PLAT(II)*RPI/180.))/(1.01+SIN(PLAT(II)*RPI/180.))-2.05/2.01)
+                ! RUW0(JW, II) = RUWFRT
+             ENDDO
+          end DO
+       end DO
+    end DO
+
+    ! 4. COMPUTE THE FLUXES
+
+    ! 4.0 
+
+    ! 4.1 Vertical velocity at launching altitude to ensure 
+    ! the correct value to the imposed fluxes.
+
+    DO JW = 1, NW
+
+       ! Evaluate intrinsic frequency at launching altitude:
+       ZOP(JW, :) = ZO(JW, :) &
+            - ZK(JW, :) * COS(ZP(JW, :)) * UH(:, LAUNCH) &
+            - ZK(JW, :) * SIN(ZP(JW, :)) * VH(:, LAUNCH) 
+
+       ! VERSION WITH FRONTAL SOURCES
+
+       ! Momentum flux at launch level imposed by vorticity sources
+
+       ! tanh limitation for values above CORIO (inertial instability).
+       ! WWP(JW, :) = RUW0(JW, :) &
+       WWP(JW, :) = RUWFRT      &
+       !     * (CORIO(:)*TANH(ROTBA(:)/CORIO(:)))**2 &
+       !    * ABS((CORIO(:)*TANH(ROTBA(:)/CORIO(:)))*CORIO(:)) &
+       !  CONSTANT FLUX
+       !    * (CORIO(:)*CORIO(:)) &
+       ! MODERATION BY THE DEPTH OF THE SOURCE (DZ HERE)
+       !      *EXP(-BVLOW(:)**2/MAX(ABS(ZOP(JW, :)),ZOISEC)**2 &
+       !      *ZK(JW, :)**2*DZ**2) &
+       ! COMPLETE FORMULA:
+            !* CORIO(:)**2*TANH(ROTBA(:)/CORIO(:)**2) &
+            * ROTBA(:) &
+       !  RESTORE DIMENSION OF A FLUX
+       !     *RD*TR/PR
+             *1. + RUW0(JW, :)
+
+       ! Factor related to the characteristics of the waves: NONE
+
+       ! Moderation by the depth of the source (dz here): NONE
+
+       ! Put the stress in the right direction:
+
+        RUWP(JW, :) = SIGN(1., ZOP(JW, :))*COS(ZP(JW, :)) * WWP(JW, :)
+        RVWP(JW, :) = SIGN(1., ZOP(JW, :))*SIN(ZP(JW, :)) * WWP(JW, :)
+
+    end DO
+
+    ! 4.2 Uniform values below the launching altitude
+
+    DO LL = 1, LAUNCH
+       RUW(:, LL) = 0
+       RVW(:, LL) = 0
+       DO JW = 1, NW
+          RUW(:, LL) = RUW(:, LL) + RUWP(JW, :)
+          RVW(:, LL) = RVW(:, LL) + RVWP(JW, :)
+       end DO
+    end DO
+
+    ! 4.3 Loop over altitudes, with passage from one level to the next
+    ! done by i) conserving the EP flux, ii) dissipating a little,
+    ! iii) testing critical levels, and vi) testing the breaking.
+
+    DO LL = LAUNCH, KLEV - 1
+       ! Warning: all the physics is here (passage from one level
+       ! to the next)
+       DO JW = 1, NW
+          ZOM(JW, :) = ZOP(JW, :)
+          WWM(JW, :) = WWP(JW, :)
+          ! Intrinsic Frequency
+          ZOP(JW, :) = ZO(JW, :) - ZK(JW, :) * COS(ZP(JW, :)) * UH(:, LL + 1) &
+               - ZK(JW, :) * SIN(ZP(JW, :)) * VH(:, LL + 1) 
+
+          ! No breaking (Eq.6)
+          ! Dissipation (Eq. 8)
+          WWP(JW, :) = WWM(JW, :) * EXP(- 2. * RDISS * PR / (PH(:, LL + 1) &
+               + PH(:, LL)) * ((BV(:, LL + 1) + BV(:, LL)) / 2.)**3 &
+               / MAX(ABS(ZOP(JW, :) + ZOM(JW, :)) / 2., ZOISEC)**4 &
+               * ZK(JW, :)**3 * (ZH(:, LL + 1) - ZH(:, LL)))
+
+          ! Critical levels (forced to zero if intrinsic frequency changes sign)
+          ! Saturation (Eq. 12)
+          WWP(JW, :) = min(WWP(JW, :), MAX(0., &
+               SIGN(1., ZOP(JW, :) * ZOM(JW, :))) * ABS(ZOP(JW, :))**3 &
+          !    / BV(:, LL + 1) * EXP(- ZH(:, LL + 1) / H0) * SATFRT**2 * KMIN**2 &
+               / BV(:, LL + 1) * EXP(- ZH(:, LL + 1) / H0) * KMIN**2 &
+!              *(SATFRT*(2.5+1.5*TANH((ZH(:,LL+1)/H0-8.)/2.)))**2 &
+               *SATFRT**2       &
+               / ZK(JW, :)**4)
+       end DO
+
+       ! Evaluate EP-flux from Eq. 7 and give the right orientation to
+       ! the stress
+
+       DO JW = 1, NW
+          RUWP(JW, :) = SIGN(1., ZOP(JW, :))*COS(ZP(JW, :)) * WWP(JW, :)
+          RVWP(JW, :) = SIGN(1., ZOP(JW, :))*SIN(ZP(JW, :)) * WWP(JW, :)
+       end DO
+
+       RUW(:, LL + 1) = 0.
+       RVW(:, LL + 1) = 0.
+
+       DO JW = 1, NW
+          RUW(:, LL + 1) = RUW(:, LL + 1) + RUWP(JW, :) 
+          RVW(:, LL + 1) = RVW(:, LL + 1) + RVWP(JW, :) 
+          EAST_GWSTRESS(:, LL)=EAST_GWSTRESS(:, LL)+MAX(0.,RUWP(JW,:))/FLOAT(NW)
+          WEST_GWSTRESS(:, LL)=WEST_GWSTRESS(:, LL)+MIN(0.,RUWP(JW,:))/FLOAT(NW)
+       end DO
+    end DO
+
+    ! 5 CALCUL DES TENDANCES:
+
+    ! 5.1 Rectification des flux au sommet et dans les basses couches
+
+    RUW(:, KLEV + 1) = 0.
+    RVW(:, KLEV + 1) = 0.
+    RUW(:, 1) = RUW(:, LAUNCH)
+    RVW(:, 1) = RVW(:, LAUNCH)
+    DO LL = 1, LAUNCH
+       RUW(:, LL) = RUW(:, LAUNCH+1)
+       RVW(:, LL) = RVW(:, LAUNCH+1)
+       EAST_GWSTRESS(:, LL)=EAST_GWSTRESS(:, LAUNCH)
+       WEST_GWSTRESS(:, LL)=WEST_GWSTRESS(:, LAUNCH)
+    end DO
+
+    ! AR-1 RECURSIVE FORMULA (13) IN VERSION 4
+    DO LL = 1, KLEV
+       D_U(:, LL) = (1.-DTIME/DELTAT) * D_U(:, LL) + DTIME/DELTAT/REAL(NW) * &
+            RG * (RUW(:, LL + 1) - RUW(:, LL)) &
+            / (PH(:, LL + 1) - PH(:, LL)) * DTIME
+!  NO AR1 FOR MERIDIONAL TENDENCIES
+!      D_V(:, LL) = (1.-DTIME/DELTAT) * D_V(:, LL) + DTIME/DELTAT/REAL(NW) * &
+       D_V(:, LL) =                                            1./REAL(NW) * &
+            RG * (RVW(:, LL + 1) - RVW(:, LL)) &
+            / (PH(:, LL + 1) - PH(:, LL)) * DTIME
+    ENDDO
+
+    ! Cosmetic: evaluation of the cumulated stress
+    ZUSTR = 0.
+    ZVSTR = 0.
+    DO LL = 1, KLEV
+       ZUSTR = ZUSTR + D_U(:, LL) / RG * (PH(:, LL + 1) - PH(:, LL))/DTIME
+!      ZVSTR = ZVSTR + D_V(:, LL) / RG * (PH(:, LL + 1) - PH(:, LL))/DTIME
+    ENDDO
+! COSMETICS TO VISUALIZE ROTBA
+    ZVSTR = ROTBA
+
+  END SUBROUTINE ACAMA_GWD_RANDO
+
+end module ACAMA_GWD_rando_m
Index: /LMDZ5/branches/testing/libf/phylmd/add_pbl_tend.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/add_pbl_tend.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/add_pbl_tend.F90	(revision 2408)
@@ -15,13 +15,16 @@
   USE phys_local_var_mod
   USE phys_state_var_mod
+  USE mod_grid_phy_lmdz, ONLY: nbp_lev
   IMPLICIT NONE
-  include "dimensions.h"
-  REAL hthturb_gcssold(llm)
-  REAL hqturb_gcssold(llm)
-  REAL dtime_frcg
+  REAL,SAVE,ALLOCATABLE :: hthturb_gcssold(:)
+  REAL,SAVE,ALLOCATABLE :: hqturb_gcssold(:)
+!$OMP THREADPRIVATE(hthturb_gcssold,hqturb_gcssold)
+  REAL,SAVE :: dtime_frcg
+  LOGICAL,SAVE :: turb_fcg_gcssold
+  LOGICAL,SAVE :: firstcall=.true.
+!$OMP THREADPRIVATE(firstcall,turb_fcg_gcssold,dtime_frcg)
   INTEGER abortphy
-  LOGICAL turb_fcg_gcssold
-  COMMON /turb_forcing/dtime_frcg, hthturb_gcssold, hqturb_gcssold, &
-    turb_fcg_gcssold
+!  COMMON /turb_forcing/dtime_frcg, hthturb_gcssold, hqturb_gcssold, &
+!    turb_fcg_gcssold
 
   ! Arguments :
@@ -36,4 +39,10 @@
   REAL zzdt(klon, klev), zzdq(klon, klev)
   INTEGER i, k
+
+  IF (firstcall) THEN
+    ALLOCATE(hthturb_gcssold(nbp_lev))
+    ALLOCATE(hqturb_gcssold(nbp_lev))
+    firstcall=.false.
+  ENDIF
 
   IF (turb_fcg_gcssold) THEN
Index: /LMDZ5/branches/testing/libf/phylmd/add_phys_tend.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/add_phys_tend.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/add_phys_tend.F90	(revision 2408)
@@ -17,6 +17,6 @@
 use phys_local_var_mod
 use phys_state_var_mod
+use print_control_mod, only: prt_level
 IMPLICIT none
-  include "iniprint.h"
   include "YOMCST.h"
   include "clesphys.h"
Index: /LMDZ5/branches/testing/libf/phylmd/aero_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/aero_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/aero_mod.F90	(revision 2408)
@@ -62,5 +62,19 @@
 
 ! 3/ Number of aerosol groups
-  INTEGER, PARAMETER :: naero_grp = 9 
+  INTEGER, PARAMETER :: naero_grp = 12
+  ! if info_trac = inca
+  ! 1 = ZERO    
+  ! 2 = AER total    
+  ! 3 = NAT    
+  ! 4 = BC    
+  ! 5 = SO4    
+  ! 6 = POM    
+  ! 7 = DUST    
+  ! 8 = SS    
+  ! 9 = FNO3    
+  ! 10 = DNO3
+  ! 11 = SNO3
+  ! 12 = empty actually 
+  ! else 
   ! 1 = ZERO    
   ! 2 = AER total    
Index: /LMDZ5/branches/testing/libf/phylmd/aeropt.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/aeropt.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/aeropt.F90	(revision 2408)
@@ -10,6 +10,4 @@
 
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
@@ -81,5 +79,5 @@
       IF (rh<0.) THEN
         abort_message = 'aeropt: RH < 0 not possible'
-        CALL abort_gcm(modname, abort_message, 1)
+        CALL abort_physic(modname, abort_message, 1)
       END IF
       IF (rh>85.) rh_num = 10
Index: /LMDZ5/branches/testing/libf/phylmd/aeropt_2bands.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/aeropt_2bands.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/aeropt_2bands.F90	(revision 2408)
@@ -22,5 +22,4 @@
 
   INCLUDE "YOMCST.h"
-  INCLUDE "iniprint.h"
 
   !
@@ -30,8 +29,6 @@
   REAL,                           INTENT(in)  :: delt
   REAL, DIMENSION(klon,klev,naero_tot),   INTENT(in)  :: m_allaer
-!RAF
   REAL, DIMENSION(klon,klev,naero_tot),   INTENT(in)  :: m_allaer_pi
   REAL, DIMENSION(klon,klev),     INTENT(in)  :: RHcl       ! humidite relative ciel clair
-!RAF  REAL, DIMENSION(klon,naero_tot),INTENT(in)  :: fractnat_allaer
   INTEGER,                        INTENT(in)  :: flag_aerosol
   REAL, DIMENSION(klon,klev),     INTENT(in)  :: pplay
@@ -49,5 +46,4 @@
   !
   REAL, DIMENSION(klon,klev,naero_tot,nbands) ::  tau_ae
-!RAF
   REAL, DIMENSION(klon,klev,naero_tot,nbands) ::  tau_ae_pi
   REAL, DIMENSION(klon,klev,naero_tot,nbands) ::  piz_ae
@@ -536,5 +532,5 @@
           A1_SSSSM_b2(klev), A2_SSSSM_b2(klev), A3_SSSSM_b2(klev),&
           B1_SSSSM_b2(klev), B2_SSSSM_b2(klev), C1_SSSSM_b2(klev), C2_SSSSM_b2(klev), stat=ierr)
-        IF (ierr /= 0) CALL abort_gcm('aeropt_2bands', 'pb in allocation 1',1)
+        IF (ierr /= 0) CALL abort_physic('aeropt_2bands', 'pb in allocation 1',1)
      END IF
      
@@ -595,8 +591,5 @@
     DO i=1, klon
       zrho=pplay(i,k)/t_seri(i,k)/RD                  ! kg/m3
-!CDIR UNROLL=naero_spc
       mass_temp(i,k,:) = m_allaer(i,k,:) / zrho / 1.e+9
-!RAF zrho
-!CDIR UNROLL=naero_spc
       mass_temp_pi(i,k,:) = m_allaer_pi(i,k,:) / zrho / 1.e+9
       zdp1(i,k)=pdel(i,k)/(gravit*delt)      ! air mass auxiliary  variable --> zdp1 [kg/(m^2 *s)]
@@ -654,5 +647,4 @@
 
 
-!!CDIR ON_ADB(RH_tab)
 !CDIR ON_ADB(fact_RH)
 !CDIR SHORTLOOP
@@ -662,5 +654,4 @@
    
   DO k=1, KLEV
-!!CDIR ON_ADB(RH_tab)
 !CDIR ON_ADB(fact_RH)
     DO i=1, KLON
@@ -945,24 +936,24 @@
           DO i=1, KLON
             tau_allaer(i,k,mrfspecies,inu)=tau_ae(i,k,id_ASSO4M_phy,inu)+tau_ae(i,k,id_CSSO4M_phy,inu)+ &
-                                           tau_ae(i,k,id_ASBCM_phy,inu)+tau_ae(i,k,id_AIBCM_phy,inu)+   &						     
-                                           tau_ae(i,k,id_ASPOMM_phy,inu)+tau_ae(i,k,id_AIPOMM_phy,inu)+ &	
+                                           tau_ae(i,k,id_ASBCM_phy,inu)+tau_ae(i,k,id_AIBCM_phy,inu)+   &
+                                           tau_ae(i,k,id_ASPOMM_phy,inu)+tau_ae(i,k,id_AIPOMM_phy,inu)+ &
                                            tau_ae(i,k,id_ASSSM_phy,inu)+tau_ae(i,k,id_CSSSM_phy,inu)+   &
                                            tau_ae(i,k,id_SSSSM_phy,inu)+ tau_ae(i,k,id_CIDUSTM_phy,inu)
-	     tau_allaer(i,k,mrfspecies,inu)=MAX(tau_allaer(i,k,mrfspecies,inu),1e-5)
+            tau_allaer(i,k,mrfspecies,inu)=MAX(tau_allaer(i,k,mrfspecies,inu),1e-5)
                  
-             piz_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_ASSO4M_phy,inu)*piz_ae(i,k,id_ASSO4M_phy,inu)+ &
-                                             tau_ae(i,k,id_CSSO4M_phy,inu)*piz_ae(i,k,id_CSSO4M_phy,inu)+ &
-                                             tau_ae(i,k,id_ASBCM_phy,inu)*piz_ae(i,k,id_ASBCM_phy,inu)+ &
-                                             tau_ae(i,k,id_AIBCM_phy,inu)*piz_ae(i,k,id_AIBCM_phy,inu)+ &
-                                             tau_ae(i,k,id_ASPOMM_phy,inu)*piz_ae(i,k,id_ASPOMM_phy,inu)+ &
-                                             tau_ae(i,k,id_AIPOMM_phy,inu)*piz_ae(i,k,id_AIPOMM_phy,inu)+ &	
-                                             tau_ae(i,k,id_ASSSM_phy,inu)*piz_ae(i,k,id_ASSSM_phy,inu)+ &
-                                             tau_ae(i,k,id_CSSSM_phy,inu)*piz_ae(i,k,id_CSSSM_phy,inu)+ &
-                                             tau_ae(i,k,id_SSSSM_phy,inu)*piz_ae(i,k,id_SSSSM_phy,inu)+ &
-                                             tau_ae(i,k,id_CIDUSTM_phy,inu)*piz_ae(i,k,id_CIDUSTM_phy,inu)) &
+            piz_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_ASSO4M_phy,inu)*piz_ae(i,k,id_ASSO4M_phy,inu)+ &
+                                            tau_ae(i,k,id_CSSO4M_phy,inu)*piz_ae(i,k,id_CSSO4M_phy,inu)+ &
+                                            tau_ae(i,k,id_ASBCM_phy,inu)*piz_ae(i,k,id_ASBCM_phy,inu)+   &
+                                            tau_ae(i,k,id_AIBCM_phy,inu)*piz_ae(i,k,id_AIBCM_phy,inu)+   &
+                                            tau_ae(i,k,id_ASPOMM_phy,inu)*piz_ae(i,k,id_ASPOMM_phy,inu)+ &
+                                            tau_ae(i,k,id_AIPOMM_phy,inu)*piz_ae(i,k,id_AIPOMM_phy,inu)+ &
+                                            tau_ae(i,k,id_ASSSM_phy,inu)*piz_ae(i,k,id_ASSSM_phy,inu)+   &
+                                            tau_ae(i,k,id_CSSSM_phy,inu)*piz_ae(i,k,id_CSSSM_phy,inu)+   &
+                                            tau_ae(i,k,id_SSSSM_phy,inu)*piz_ae(i,k,id_SSSSM_phy,inu)+   &
+                                            tau_ae(i,k,id_CIDUSTM_phy,inu)*piz_ae(i,k,id_CIDUSTM_phy,inu)) &
                                             /tau_allaer(i,k,mrfspecies,inu)
-	     piz_allaer(i,k,mrfspecies,inu)=MAX(piz_allaer(i,k,mrfspecies,inu),0.1)
-
-             cg_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_ASSO4M_phy,inu)* &
+            piz_allaer(i,k,mrfspecies,inu)=MAX(piz_allaer(i,k,mrfspecies,inu),0.1)
+
+            cg_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_ASSO4M_phy,inu)* &
               piz_ae(i,k,id_ASSO4M_phy,inu)*cg_ae(i,k,id_ASSO4M_phy,inu)+ &
               tau_ae(i,k,id_CSSO4M_phy,inu)*piz_ae(i,k,id_CSSO4M_phy,inu)* &
@@ -992,31 +983,31 @@
         DO k=1, KLEV
           DO i=1, KLON
-!RAF
-	 	 tau_allaer(i,k,mrfspecies,inu)=tau_ae_pi(i,k,id_ASSO4M_phy,inu)+ &
+
+              tau_allaer(i,k,mrfspecies,inu)=tau_ae_pi(i,k,id_ASSO4M_phy,inu)+ &
                       tau_ae_pi(i,k,id_CSSO4M_phy,inu)+ &
-                      tau_ae_pi(i,k,id_ASBCM_phy,inu)+ &
-                      tau_ae_pi(i,k,id_AIBCM_phy,inu)+ &
+                      tau_ae_pi(i,k,id_ASBCM_phy,inu)+  &
+                      tau_ae_pi(i,k,id_AIBCM_phy,inu)+  &
                       tau_ae_pi(i,k,id_ASPOMM_phy,inu)+ &
-                      tau_ae_pi(i,k,id_AIPOMM_phy,inu)+ &	
-                      tau_ae_pi(i,k,id_ASSSM_phy,inu)+ &
-                      tau_ae_pi(i,k,id_CSSSM_phy,inu)+ &
-                      tau_ae_pi(i,k,id_SSSSM_phy,inu)+ &
+                      tau_ae_pi(i,k,id_AIPOMM_phy,inu)+ &
+                      tau_ae_pi(i,k,id_ASSSM_phy,inu)+  &
+                      tau_ae_pi(i,k,id_CSSSM_phy,inu)+  &
+                      tau_ae_pi(i,k,id_SSSSM_phy,inu)+  &
                       tau_ae_pi(i,k,id_CIDUSTM_phy,inu)
-	         tau_allaer(i,k,mrfspecies,inu)=MAX(tau_allaer(i,k,mrfspecies,inu),1e-5)
-
-	 	 piz_allaer(i,k,mrfspecies,inu)=(tau_ae_pi(i,k,id_ASSO4M_phy,inu)*piz_ae(i,k,id_ASSO4M_phy,inu)+ &
+              tau_allaer(i,k,mrfspecies,inu)=MAX(tau_allaer(i,k,mrfspecies,inu),1e-5)
+
+              piz_allaer(i,k,mrfspecies,inu)=(tau_ae_pi(i,k,id_ASSO4M_phy,inu)*piz_ae(i,k,id_ASSO4M_phy,inu)+ &
                       tau_ae_pi(i,k,id_CSSO4M_phy,inu)*piz_ae(i,k,id_CSSO4M_phy,inu)+ &
-                      tau_ae_pi(i,k,id_ASBCM_phy,inu)*piz_ae(i,k,id_ASBCM_phy,inu)+ &
-                      tau_ae_pi(i,k,id_AIBCM_phy,inu)*piz_ae(i,k,id_AIBCM_phy,inu)+ &
+                      tau_ae_pi(i,k,id_ASBCM_phy,inu)*piz_ae(i,k,id_ASBCM_phy,inu)+   &
+                      tau_ae_pi(i,k,id_AIBCM_phy,inu)*piz_ae(i,k,id_AIBCM_phy,inu)+   &
                       tau_ae_pi(i,k,id_ASPOMM_phy,inu)*piz_ae(i,k,id_ASPOMM_phy,inu)+ &
-                      tau_ae_pi(i,k,id_AIPOMM_phy,inu)*piz_ae(i,k,id_AIPOMM_phy,inu)+ &	
-                      tau_ae_pi(i,k,id_ASSSM_phy,inu)*piz_ae(i,k,id_ASSSM_phy,inu)+ &
-                      tau_ae_pi(i,k,id_CSSSM_phy,inu)*piz_ae(i,k,id_CSSSM_phy,inu)+ &
-                      tau_ae_pi(i,k,id_SSSSM_phy,inu)*piz_ae(i,k,id_SSSSM_phy,inu)+ &
+                      tau_ae_pi(i,k,id_AIPOMM_phy,inu)*piz_ae(i,k,id_AIPOMM_phy,inu)+ &
+                      tau_ae_pi(i,k,id_ASSSM_phy,inu)*piz_ae(i,k,id_ASSSM_phy,inu)+   &
+                      tau_ae_pi(i,k,id_CSSSM_phy,inu)*piz_ae(i,k,id_CSSSM_phy,inu)+   &
+                      tau_ae_pi(i,k,id_SSSSM_phy,inu)*piz_ae(i,k,id_SSSSM_phy,inu)+   &
                       tau_ae_pi(i,k,id_CIDUSTM_phy,inu)*piz_ae(i,k,id_CIDUSTM_phy,inu)) &
                       /tau_allaer(i,k,mrfspecies,inu)
-	         piz_allaer(i,k,mrfspecies,inu)=MAX(piz_allaer(i,k,mrfspecies,inu),0.1)
-
-	 	 cg_allaer(i,k,mrfspecies,inu)=(&
+              piz_allaer(i,k,mrfspecies,inu)=MAX(piz_allaer(i,k,mrfspecies,inu),0.1)
+
+              cg_allaer(i,k,mrfspecies,inu)=(&
                       tau_ae_pi(i,k,id_ASSO4M_phy,inu)*piz_ae(i,k,id_ASSO4M_phy,inu)*cg_ae(i,k,id_ASSO4M_phy,inu)+ &
                       tau_ae_pi(i,k,id_CSSO4M_phy,inu)*piz_ae(i,k,id_CSSO4M_phy,inu)*cg_ae(i,k,id_CSSO4M_phy,inu)+ &
@@ -1037,10 +1028,10 @@
         DO k=1, KLEV
           DO i=1, KLON
-	    tau_allaer(i,k,mrfspecies,inu)=tau_ae(i,k,id_ASBCM_phy,inu)+tau_ae(i,k,id_AIBCM_phy,inu)
-	    tau_allaer(i,k,mrfspecies,inu)=MAX(tau_allaer(i,k,mrfspecies,inu),1e-5)
-	    piz_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_ASBCM_phy,inu)*piz_ae(i,k,id_ASBCM_phy,inu) &
+            tau_allaer(i,k,mrfspecies,inu)=tau_ae(i,k,id_ASBCM_phy,inu)+tau_ae(i,k,id_AIBCM_phy,inu)
+            tau_allaer(i,k,mrfspecies,inu)=MAX(tau_allaer(i,k,mrfspecies,inu),1e-5)
+            piz_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_ASBCM_phy,inu)*piz_ae(i,k,id_ASBCM_phy,inu) &
                       +tau_ae(i,k,id_AIBCM_phy,inu)*piz_ae(i,k,id_AIBCM_phy,inu))/ &
                       tau_allaer(i,k,mrfspecies,inu)
-	    piz_allaer(i,k,mrfspecies,inu)=MAX(piz_allaer(i,k,mrfspecies,inu),0.1)
+            piz_allaer(i,k,mrfspecies,inu)=MAX(piz_allaer(i,k,mrfspecies,inu),0.1)
             cg_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_ASBCM_phy,inu)*piz_ae(i,k,id_ASBCM_phy,inu) *cg_ae(i,k,id_ASBCM_phy,inu)&
                       +tau_ae(i,k,id_AIBCM_phy,inu)*piz_ae(i,k,id_AIBCM_phy,inu)*cg_ae(i,k,id_AIBCM_phy,inu))/ &
@@ -1054,9 +1045,9 @@
           DO i=1, KLON
             tau_allaer(i,k,mrfspecies,inu)=tau_ae(i,k,id_ASSO4M_phy,inu)+tau_ae(i,k,id_CSSO4M_phy,inu)
-	    tau_allaer(i,k,mrfspecies,inu)=MAX(tau_allaer(i,k,mrfspecies,inu),1e-5)
+            tau_allaer(i,k,mrfspecies,inu)=MAX(tau_allaer(i,k,mrfspecies,inu),1e-5)
             piz_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_CSSO4M_phy,inu)*piz_ae(i,k,id_CSSO4M_phy,inu) &
                       +tau_ae(i,k,id_ASSO4M_phy,inu)*piz_ae(i,k,id_ASSO4M_phy,inu))/ &
                       tau_allaer(i,k,mrfspecies,inu)
-	    piz_allaer(i,k,mrfspecies,inu)=MAX(piz_allaer(i,k,mrfspecies,inu),0.1)
+            piz_allaer(i,k,mrfspecies,inu)=MAX(piz_allaer(i,k,mrfspecies,inu),0.1)
             cg_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_CSSO4M_phy,inu)* &
             piz_ae(i,k,id_CSSO4M_phy,inu) *cg_ae(i,k,id_CSSO4M_phy,inu)&
@@ -1073,9 +1064,9 @@
             tau_allaer(i,k,mrfspecies,inu)=tau_ae(i,k,id_ASPOMM_phy,inu)+tau_ae(i,k,id_AIPOMM_phy,inu)
             tau_allaer(i,k,mrfspecies,inu)=MAX(tau_allaer(i,k,mrfspecies,inu),1e-5)
-	    piz_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_ASPOMM_phy,inu)*piz_ae(i,k,id_ASPOMM_phy,inu) &
+            piz_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_ASPOMM_phy,inu)*piz_ae(i,k,id_ASPOMM_phy,inu) &
                       +tau_ae(i,k,id_AIPOMM_phy,inu)*piz_ae(i,k,id_AIPOMM_phy,inu))/ &
                       tau_allaer(i,k,mrfspecies,inu)
-	    piz_allaer(i,k,mrfspecies,inu)=MAX(piz_allaer(i,k,mrfspecies,inu),0.1)
-	    cg_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_ASPOMM_phy,inu)*piz_ae(i,k,id_ASPOMM_phy,inu) *cg_ae(i,k,id_ASPOMM_phy,inu)&
+            piz_allaer(i,k,mrfspecies,inu)=MAX(piz_allaer(i,k,mrfspecies,inu),0.1)
+            cg_allaer(i,k,mrfspecies,inu)=(tau_ae(i,k,id_ASPOMM_phy,inu)*piz_ae(i,k,id_ASPOMM_phy,inu)*cg_ae(i,k,id_ASPOMM_phy,inu)&
                       +tau_ae(i,k,id_AIPOMM_phy,inu)*piz_ae(i,k,id_AIPOMM_phy,inu)*cg_ae(i,k,id_AIPOMM_phy,inu))/ &
                       (tau_allaer(i,k,mrfspecies,inu)*piz_allaer(i,k,mrfspecies,inu))
@@ -1088,7 +1079,7 @@
           DO i=1, KLON
             tau_allaer(i,k,mrfspecies,inu)=tau_ae(i,k,id_CIDUSTM_phy,inu)
-	    tau_allaer(i,k,mrfspecies,inu)=MAX(tau_allaer(i,k,mrfspecies,inu),1e-5)
+            tau_allaer(i,k,mrfspecies,inu)=MAX(tau_allaer(i,k,mrfspecies,inu),1e-5)
             piz_allaer(i,k,mrfspecies,inu)=piz_ae(i,k,id_CIDUSTM_phy,inu)
-	    cg_allaer(i,k,mrfspecies,inu)=cg_ae(i,k,id_CIDUSTM_phy,inu)
+            cg_allaer(i,k,mrfspecies,inu)=cg_ae(i,k,id_CIDUSTM_phy,inu)
           ENDDO
         ENDDO
@@ -1136,10 +1127,9 @@
     ENDDO
   ENDDO
-   
 
   inu=1
   DO i=1, KLON
      absvisaer(i)=SUM((1-piz_allaer(i,:,:,inu))*tau_allaer(i,:,:,inu))
-  END DO	
+  ENDDO
 
   DEALLOCATE(aerosol_name) 
Index: /LMDZ5/branches/testing/libf/phylmd/aeropt_5wv.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/aeropt_5wv.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/aeropt_5wv.F90	(revision 2408)
@@ -67,6 +67,4 @@
   !
   REAL, DIMENSION(klon), INTENT(out)          :: ai      ! POLDER aerosol index 
-!  REAL, DIMENSION(klon,nwave,naero_spc), INTENT(out)      :: tausum
-!  REAL, DIMENSION(klon,klev,nwave,naero_spc), INTENT(out) :: tau
   REAL, DIMENSION(klon,nwave,naero_tot), INTENT(out)      :: tausum
   REAL, DIMENSION(klon,klev,nwave,naero_tot), INTENT(out) :: tau
@@ -588,5 +586,5 @@
           A1_SSSSM(klev), A2_SSSSM(klev), A3_SSSSM(klev),&
           B1_SSSSM(klev), B2_SSSSM(klev), C1_SSSSM(klev), C2_SSSSM(klev), stat=ierr)
-        IF (ierr /= 0) CALL abort_gcm('aeropt_5mw', 'pb in allocation 1',1)
+        IF (ierr /= 0) CALL abort_physic('aeropt_5mw', 'pb in allocation 1',1)
      END IF
 
@@ -626,9 +624,6 @@
   DO k=1, klev
     DO i=1, klon
-!      IF (t_seri(i,k).EQ.0) stop 'stop aeropt_5wv T '
-!      IF (pplay(i,k).EQ.0) stop  'stop aeropt_5wv p '
       zrho=pplay(i,k)/t_seri(i,k)/RD                  ! kg/m3
       dh(i,k)=pdel(i,k)/(gravit*zrho)
-!CDIR UNROLL=naero_spc
       mass_temp(i,k,:) = m_allaer(i,k,:) / zrho / 1.e+9
       zdp1(i,k)=pdel(i,k)/(gravit*delt)     ! air mass auxiliary  variable --> zdp1 [kg/(m^2 *s)]
@@ -760,9 +755,7 @@
     ENDIF
 
-!Bug 21 12 10 AI
-!    used_tau(spsol)=.TRUE.
     IF (soluble) then
       used_tau(spsol)=.TRUE.
-       ELSE
+    ELSE
       used_tau(naero_soluble+spinsol)=.TRUE.
     ENDIF
@@ -866,12 +859,14 @@
      DO m=1,naero_spc
         od550aer(i)=od550aer(i)+tausum(i,2,m)
-     END DO
-  END DO
+     ENDDO
+  ENDDO
+
   DO i=1, klon
      od865aer(i)=0.
      DO m=1,naero_spc
         od865aer(i)=od865aer(i)+tausum(i,5,m)
-     END DO
-  END DO
+     ENDDO
+  ENDDO
+
   DO i=1, klon
      DO k=1, KLEV
@@ -879,13 +874,11 @@
         DO m=1,naero_spc
            ec550aer(i,k)=ec550aer(i,k)+tau(i,k,2,m)/dh(i,k)
-        END DO
-     END DO
-  END DO
+        ENDDO
+     ENDDO
+  ENDDO
   
-   od550lt1aer(:)=tausum(:,2,id_ASSO4M_phy)+tausum(:,2,id_ASBCM_phy)+tausum(:,2,id_AIBCM_phy)+ &
-	tausum(:,2,id_ASPOMM_phy)+tausum(:,2,id_AIPOMM_phy)+tausum(:,2,id_ASSSM_phy)+ &
-	0.03*tausum(:,2,id_CSSSM_phy)+0.4*tausum(:,2,id_CIDUSTM_phy)
-
-
+   od550lt1aer(:)=tausum(:,2,id_ASSO4M_phy)+tausum(:,2,id_ASBCM_phy)+tausum(:,2,id_AIBCM_phy)+  &
+                  tausum(:,2,id_ASPOMM_phy)+tausum(:,2,id_AIPOMM_phy)+tausum(:,2,id_ASSSM_phy)+ &
+                  0.03*tausum(:,2,id_CSSSM_phy)+0.4*tausum(:,2,id_CIDUSTM_phy)
 
   DEALLOCATE(aerosol_name) 
Index: /LMDZ5/branches/testing/libf/phylmd/ajsec.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ajsec.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/ajsec.F90	(revision 2408)
@@ -14,6 +14,4 @@
   ! d_t-----output-R-Incrementation de la temperature
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   REAL paprs(klon, klev+1), pplay(klon, klev)
@@ -168,6 +166,4 @@
   ! d_t-----output-R-Incrementation de la temperature
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   REAL paprs(klon, klev+1), pplay(klon, klev)
@@ -319,6 +315,4 @@
   ! d_t-----output-R-Incrementation de la temperature
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   REAL paprs(klon, klev+1), pplay(klon, klev)
Index: /LMDZ5/branches/testing/libf/phylmd/albedo.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/albedo.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/albedo.F90	(revision 2408)
@@ -1,191 +1,175 @@
+! $Id$
+module albedo
 
-! $Id$
+  IMPLICIT NONE
 
+contains
 
+  SUBROUTINE alboc(rjour, rlat, albedo)
+    USE dimphy
+    ! ======================================================================
+    ! Auteur(s): Z.X. Li (LMD/CNRS) (adaptation du GCM du LMD)
+    ! Date: le 16 mars 1995
+    ! Objet: Calculer l'albedo sur l'ocean
+    ! Methode: Integrer numeriquement l'albedo pendant une journee
 
-SUBROUTINE alboc(rjour, rlat, albedo)
-  USE dimphy
-  IMPLICIT NONE
-  ! ======================================================================
-  ! Auteur(s): Z.X. Li (LMD/CNRS) (adaptation du GCM du LMD)
-  ! Date: le 16 mars 1995
-  ! Objet: Calculer l'albedo sur l'ocean
-  ! Methode: Integrer numeriquement l'albedo pendant une journee
+    ! Arguments;
+    ! rjour (in,R)  : jour dans l'annee (a compter du 1 janvier)
+    ! rlat (in,R)   : latitude en degre
+    ! albedo (out,R): albedo obtenu (de 0 a 1)
+    ! ======================================================================
+    include "YOMCST.h"
+    include "clesphys.h"
 
-  ! Arguments;
-  ! rjour (in,R)  : jour dans l'annee (a compter du 1 janvier)
-  ! rlat (in,R)   : latitude en degre
-  ! albedo (out,R): albedo obtenu (de 0 a 1)
-  ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  include "YOMCST.h"
-  include "clesphys.h"
+    ! fmagic -> clesphys.h/.inc
+    ! REAL fmagic ! un facteur magique pour regler l'albedo
+    ! cc      PARAMETER (fmagic=0.7)
+    ! ccIM => a remplacer
+    ! PARAMETER (fmagic=1.32)
+    ! PARAMETER (fmagic=1.0)
+    ! PARAMETER (fmagic=0.7)
+    INTEGER npts ! il controle la precision de l'integration
+    PARAMETER (npts=120) ! 120 correspond a l'interval 6 minutes
 
-  ! fmagic -> clesphys.h/.inc
-  ! REAL fmagic ! un facteur magique pour regler l'albedo
-  ! cc      PARAMETER (fmagic=0.7)
-  ! ccIM => a remplacer
-  ! PARAMETER (fmagic=1.32)
-  ! PARAMETER (fmagic=1.0)
-  ! PARAMETER (fmagic=0.7)
-  INTEGER npts ! il controle la precision de l'integration
-  PARAMETER (npts=120) ! 120 correspond a l'interval 6 minutes
+    REAL rlat(klon), rjour, albedo(klon)
+    REAL zdist, zlonsun, zpi, zdeclin
+    REAL rmu, alb, srmu, salb, fauxo, aa, bb
+    INTEGER i, k
+    ! ccIM
+    LOGICAL ancien_albedo
+    PARAMETER (ancien_albedo=.FALSE.)
+    ! SAVE albedo
 
-  REAL rlat(klon), rjour, albedo(klon)
-  REAL zdist, zlonsun, zpi, zdeclin
-  REAL rmu, alb, srmu, salb, fauxo, aa, bb
-  INTEGER i, k
-  ! ccIM
-  LOGICAL ancien_albedo
-  PARAMETER (ancien_albedo=.FALSE.)
-  ! SAVE albedo
+    IF (ancien_albedo) THEN
 
-  IF (ancien_albedo) THEN
+       zpi = 4.*atan(1.)
 
-    zpi = 4.*atan(1.)
+       ! Calculer la longitude vraie de l'orbite terrestre:
+       CALL orbite(rjour, zlonsun, zdist)
 
-    ! Calculer la longitude vraie de l'orbite terrestre:
-    CALL orbite(rjour, zlonsun, zdist)
+       ! Calculer la declinaison du soleil (qui varie entre + et - R_incl):
+       zdeclin = asin(sin(zlonsun*zpi/180.0)*sin(r_incl*zpi/180.0))
 
-    ! Calculer la declinaison du soleil (qui varie entre + et - R_incl):
-    zdeclin = asin(sin(zlonsun*zpi/180.0)*sin(r_incl*zpi/180.0))
+       DO i = 1, klon
+          aa = sin(rlat(i)*zpi/180.0)*sin(zdeclin)
+          bb = cos(rlat(i)*zpi/180.0)*cos(zdeclin)
 
-    DO i = 1, klon
-      aa = sin(rlat(i)*zpi/180.0)*sin(zdeclin)
-      bb = cos(rlat(i)*zpi/180.0)*cos(zdeclin)
+          ! Midi local (angle du temps = 0.0):
+          rmu = aa + bb*cos(0.0)
+          rmu = max(0.0, rmu)
+          fauxo = (1.47-acos(rmu))/.15
+          alb = 0.03 + 0.630/(1.+fauxo*fauxo)
+          srmu = rmu
+          salb = alb*rmu
 
-      ! Midi local (angle du temps = 0.0):
-      rmu = aa + bb*cos(0.0)
-      rmu = max(0.0, rmu)
-      fauxo = (1.47-acos(rmu))/.15
-      alb = 0.03 + 0.630/(1.+fauxo*fauxo)
-      srmu = rmu
-      salb = alb*rmu
+          ! Faire l'integration numerique de midi a minuit (le facteur 2
+          ! prend en compte l'autre moitie de la journee):
+          DO k = 1, npts
+             rmu = aa + bb*cos(real(k)/real(npts)*zpi)
+             rmu = max(0.0, rmu)
+             fauxo = (1.47-acos(rmu))/.15
+             alb = 0.03 + 0.630/(1.+fauxo*fauxo)
+             srmu = srmu + rmu*2.0
+             salb = salb + alb*rmu*2.0
+          END DO
+          IF (srmu/=0.0) THEN
+             albedo(i) = salb/srmu*fmagic + pmagic
+          ELSE ! nuit polaire (on peut prendre une valeur quelconque)
+             albedo(i) = fmagic
+          END IF
+       END DO
 
-      ! Faire l'integration numerique de midi a minuit (le facteur 2
-      ! prend en compte l'autre moitie de la journee):
-      DO k = 1, npts
-        rmu = aa + bb*cos(real(k)/real(npts)*zpi)
-        rmu = max(0.0, rmu)
-        fauxo = (1.47-acos(rmu))/.15
-        alb = 0.03 + 0.630/(1.+fauxo*fauxo)
-        srmu = srmu + rmu*2.0
-        salb = salb + alb*rmu*2.0
-      END DO
-      IF (srmu/=0.0) THEN
-        albedo(i) = salb/srmu*fmagic + pmagic
-      ELSE ! nuit polaire (on peut prendre une valeur quelconque)
-        albedo(i) = fmagic
-      END IF
-    END DO
+       ! nouvel albedo
 
-    ! nouvel albedo
+    ELSE
 
-  ELSE
+       zpi = 4.*atan(1.)
 
-    zpi = 4.*atan(1.)
+       ! Calculer la longitude vraie de l'orbite terrestre:
+       CALL orbite(rjour, zlonsun, zdist)
 
-    ! Calculer la longitude vraie de l'orbite terrestre:
-    CALL orbite(rjour, zlonsun, zdist)
+       ! Calculer la declinaison du soleil (qui varie entre + et - R_incl):
+       zdeclin = asin(sin(zlonsun*zpi/180.0)*sin(r_incl*zpi/180.0))
 
-    ! Calculer la declinaison du soleil (qui varie entre + et - R_incl):
-    zdeclin = asin(sin(zlonsun*zpi/180.0)*sin(r_incl*zpi/180.0))
+       DO i = 1, klon
+          aa = sin(rlat(i)*zpi/180.0)*sin(zdeclin)
+          bb = cos(rlat(i)*zpi/180.0)*cos(zdeclin)
 
-    DO i = 1, klon
-      aa = sin(rlat(i)*zpi/180.0)*sin(zdeclin)
-      bb = cos(rlat(i)*zpi/180.0)*cos(zdeclin)
+          ! Midi local (angle du temps = 0.0):
+          rmu = aa + bb*cos(0.0)
+          rmu = max(0.0, rmu)
+          ! IM cf. PB  alb = 0.058/(rmu + 0.30)
+          ! alb = 0.058/(rmu + 0.30) * 1.5
+          alb = 0.058/(rmu+0.30)*1.2
+          ! alb = 0.058/(rmu + 0.30) * 1.3
+          srmu = rmu
+          salb = alb*rmu
 
-      ! Midi local (angle du temps = 0.0):
-      rmu = aa + bb*cos(0.0)
-      rmu = max(0.0, rmu)
-      ! IM cf. PB  alb = 0.058/(rmu + 0.30)
-      ! alb = 0.058/(rmu + 0.30) * 1.5
-      alb = 0.058/(rmu+0.30)*1.2
-      ! alb = 0.058/(rmu + 0.30) * 1.3
-      srmu = rmu
-      salb = alb*rmu
+          ! Faire l'integration numerique de midi a minuit (le facteur 2
+          ! prend en compte l'autre moitie de la journee):
+          DO k = 1, npts
+             rmu = aa + bb*cos(real(k)/real(npts)*zpi)
+             rmu = max(0.0, rmu)
+             ! IM cf. PB      alb = 0.058/(rmu + 0.30)
+             ! alb = 0.058/(rmu + 0.30) * 1.5
+             alb = 0.058/(rmu+0.30)*1.2
+             ! alb = 0.058/(rmu + 0.30) * 1.3
+             srmu = srmu + rmu*2.0
+             salb = salb + alb*rmu*2.0
+          END DO
+          IF (srmu/=0.0) THEN
+             albedo(i) = salb/srmu*fmagic + pmagic
+          ELSE ! nuit polaire (on peut prendre une valeur quelconque)
+             albedo(i) = fmagic
+          END IF
+       END DO
+    END IF
+    RETURN
+  END SUBROUTINE alboc
+  ! =====================================================================
+  SUBROUTINE alboc_cd(rmu0, albedo)
+    USE dimphy
 
-      ! Faire l'integration numerique de midi a minuit (le facteur 2
-      ! prend en compte l'autre moitie de la journee):
-      DO k = 1, npts
-        rmu = aa + bb*cos(real(k)/real(npts)*zpi)
-        rmu = max(0.0, rmu)
-        ! IM cf. PB      alb = 0.058/(rmu + 0.30)
-        ! alb = 0.058/(rmu + 0.30) * 1.5
-        alb = 0.058/(rmu+0.30)*1.2
-        ! alb = 0.058/(rmu + 0.30) * 1.3
-        srmu = srmu + rmu*2.0
-        salb = salb + alb*rmu*2.0
-      END DO
-      IF (srmu/=0.0) THEN
-        albedo(i) = salb/srmu*fmagic + pmagic
-      ELSE ! nuit polaire (on peut prendre une valeur quelconque)
-        albedo(i) = fmagic
-      END IF
-    END DO
-  END IF
-  RETURN
-END SUBROUTINE alboc
-! =====================================================================
-SUBROUTINE alboc_cd(rmu0, albedo)
-  USE dimphy
-  IMPLICIT NONE
-  ! ======================================================================
-  ! Auteur(s): Z.X. Li (LMD/CNRS)
-  ! date: 19940624
-  ! Calculer l'albedo sur l'ocean en fonction de l'angle zenithal moyen
-  ! Formule due a Larson and Barkstrom (1977) Proc. of the symposium
-  ! on radiation in the atmosphere, 19-28 August 1976, science Press,
-  ! 1977 pp 451-453, ou These de 3eme cycle de Sylvie Joussaume.
+    ! Auteur(s): Z.X. Li (LMD/CNRS)
+    ! date: 19940624
+    ! Calculer l'albedo sur l'ocean en fonction de l'angle zenithal moyen
+    ! Formule due a Larson and Barkstrom (1977) Proc. of the symposium
+    ! on radiation in the atmosphere, 19-28 August 1976, science Press,
+    ! 1977 pp 451-453, ou These de 3eme cycle de Sylvie Joussaume.
 
-  ! Arguments
-  ! rmu0    (in): cosinus de l'angle solaire zenithal
-  ! albedo (out): albedo de surface de l'ocean
-  ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  include "clesphys.h"
-  REAL rmu0(klon), albedo(klon)
+    ! Arguments
+    ! rmu0    (in): cosinus de l'angle solaire zenithal
+    ! albedo (out): albedo de surface de l'ocean
+    ! ======================================================================
+    include "clesphys.h"
+    REAL, intent(in):: rmu0(klon)
+    real, intent(out):: albedo(klon)
 
-  ! REAL fmagic ! un facteur magique pour regler l'albedo
-  ! cc      PARAMETER (fmagic=0.7)
-  ! ccIM => a remplacer
-  ! PARAMETER (fmagic=1.32)
-  ! PARAMETER (fmagic=1.0)
-  ! PARAMETER (fmagic=0.7)
+    ! REAL fmagic ! un facteur magique pour regler l'albedo
+    ! cc      PARAMETER (fmagic=0.7)
+    ! ccIM => a remplacer
+    ! PARAMETER (fmagic=1.32)
+    ! PARAMETER (fmagic=1.0)
+    ! PARAMETER (fmagic=0.7)
 
-  REAL fauxo
-  INTEGER i
-  ! ccIM
-  LOGICAL ancien_albedo
-  PARAMETER (ancien_albedo=.FALSE.)
-  ! SAVE albedo
+    REAL fauxo
+    INTEGER i
+    LOGICAL ancien_albedo
+    PARAMETER (ancien_albedo=.FALSE.)
 
-  IF (ancien_albedo) THEN
+    IF (ancien_albedo) THEN
+       DO i = 1, klon
+          fauxo = (1.47-acos(max(rmu0(i), 0.0)))/0.15
+          albedo(i) = fmagic*(.03+.630/(1.+fauxo*fauxo)) + pmagic
+          albedo(i) = max(min(albedo(i),0.60), 0.04)
+       END DO
+    ELSE
+       DO i = 1, klon
+          albedo(i) = fmagic*0.058/(max(rmu0(i), 0.0)+0.30) + pmagic
+          albedo(i) = max(min(albedo(i),0.60), 0.04)
+       END DO
+    END IF
 
-    DO i = 1, klon
+  END SUBROUTINE alboc_cd
 
-      rmu0(i) = max(rmu0(i), 0.0)
-
-      fauxo = (1.47-acos(rmu0(i)))/0.15
-      albedo(i) = fmagic*(.03+.630/(1.+fauxo*fauxo)) + pmagic
-      albedo(i) = max(min(albedo(i),0.60), 0.04)
-    END DO
-
-    ! nouvel albedo
-
-  ELSE
-
-    DO i = 1, klon
-      rmu0(i) = max(rmu0(i), 0.0)
-      ! IM:orig albedo(i) = 0.058/(rmu0(i) + 0.30)
-      albedo(i) = fmagic*0.058/(rmu0(i)+0.30) + pmagic
-      albedo(i) = max(min(albedo(i),0.60), 0.04)
-    END DO
-
-  END IF
-
-  RETURN
-END SUBROUTINE alboc_cd
-! ========================================================================
+end module albedo
Index: /LMDZ5/branches/testing/libf/phylmd/atm2geo.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/atm2geo.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/atm2geo.F90	(revision 2408)
@@ -6,5 +6,4 @@
   USE mod_phys_lmdz_para
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'
   INCLUDE 'YOMCST.h'
 !
Index: /LMDZ5/branches/testing/libf/phylmd/calbeta_clim.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/calbeta_clim.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/calbeta_clim.F90	(revision 2408)
@@ -14,4 +14,5 @@
 
   USE phys_cal_mod, only: year_len
+  USE print_control_mod, ONLY: prt_level
 
   implicit none
@@ -24,5 +25,4 @@
   real lat_nord,lat_sud
 
-  include "iniprint.h"
   !==============================================
 
Index: /LMDZ5/branches/testing/libf/phylmd/calcul_divers.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/calcul_divers.h	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/calcul_divers.h	(revision 2408)
@@ -8,5 +8,5 @@
          DO i=1, klon
             IF(pctsrf(i,is_ter).GT.0.) THEN
-               paire_ter(i)=airephy(i)*pctsrf(i,is_ter)
+               paire_ter(i)=cell_area(i)*pctsrf(i,is_ter)
             ENDIF 
          ENDDO
Index: /LMDZ5/branches/testing/libf/phylmd/calltherm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/calltherm.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/calltherm.F90	(revision 2408)
@@ -21,10 +21,8 @@
       USE dimphy
       USE indice_sol_mod
+      USE print_control_mod, ONLY: prt_level,lunout
 
       implicit none
-#include "dimensions.h"
-!#include "dimphy.h"
-#include "thermcell.h"
-#include "iniprint.h"
+      include "thermcell.h"
 
 
@@ -208,5 +206,5 @@
           else if (iflag_thermals.eq.11) then
               abort_message = 'cas non prevu dans calltherm'
-              CALL abort_gcm (modname,abort_message,1)
+              CALL abort_physic (modname,abort_message,1)
 
 !           CALL thermcell_pluie(klon,klev,zdt  &
@@ -260,5 +258,5 @@
          else
            abort_message = 'Cas des thermiques non prevu'
-           CALL abort_gcm (modname,abort_message,1)
+           CALL abort_physic (modname,abort_message,1)
          endif
 
Index: /LMDZ5/branches/testing/libf/phylmd/calwake.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/calwake.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/calwake.F90	(revision 2408)
@@ -22,6 +22,4 @@
   IMPLICIT NONE
   ! ======================================================================
-  include "dimensions.h"
-  ! #include "dimphy.h"
   include "YOMCST.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/carbon_cycle_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/carbon_cycle_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/carbon_cycle_mod.F90	(revision 2408)
@@ -86,14 +86,14 @@
 
     USE dimphy
-    USE comgeomphy
+    USE geometry_mod, ONLY : cell_area 
     USE mod_phys_lmdz_transfert_para
-    USE infotrac
+    USE infotrac_phy, ONLY: nbtr, nqo, niadv, tname
     USE IOIPSL
     USE surface_data, ONLY : ok_veget, type_ocean
     USE phys_cal_mod, ONLY : mth_len
+    USE print_control_mod, ONLY: lunout
 
     IMPLICIT NONE
     INCLUDE "clesphys.h"
-    INCLUDE "iniprint.h"
  
 ! Input argument
@@ -135,5 +135,5 @@
        WRITE(lunout,*) 'carbon_cycle_emis_comp = ',carbon_cycle_emis_comp
        IF (carbon_cycle_emis_comp) THEN
-          CALL abort_gcm('carbon_cycle_init', 'carbon_cycle_emis_comp option not yet implemented!!',1)
+          CALL abort_physic('carbon_cycle_init', 'carbon_cycle_emis_comp option not yet implemented!!',1)
        END IF
     END IF
@@ -226,5 +226,5 @@
           co2trac(itc)%updatefreq = 86400
           ! DOES THIS WORK ???? Problematic due to implementation of the coupled fluxes...
-          CALL abort_gcm('carbon_cycle_init','transport of total CO2 has to be implemented and tested',1)
+          CALL abort_physic('carbon_cycle_init','transport of total CO2 has to be implemented and tested',1)
        END SELECT
     END DO
@@ -248,5 +248,5 @@
     ! Allocate vector for storing fluxes to inject
     ALLOCATE(dtr_add(klon,maxco2trac), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('carbon_cycle_init', 'pb in allocation 11',1)       
+    IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation 11',1)       
     
     ! Allocate variables for cumulating fluxes from ORCHIDEE
@@ -254,9 +254,9 @@
        IF (.NOT. carbon_cycle_tr .AND. carbon_cycle_cpl) THEN
           ALLOCATE(fco2_land_day(klon), stat=ierr)
-          IF (ierr /= 0) CALL abort_gcm('carbon_cycle_init', 'pb in allocation 2',1)
+          IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation 2',1)
           fco2_land_day(1:klon) = 0.
           
           ALLOCATE(fco2_lu_day(klon), stat=ierr)
-          IF (ierr /= 0) CALL abort_gcm('carbon_cycle_init', 'pb in allocation 3',1)
+          IF (ierr /= 0) CALL abort_physic('carbon_cycle_init', 'pb in allocation 3',1)
           fco2_lu_day(1:klon)   = 0.
        END IF
@@ -268,10 +268,10 @@
 !    IF (carbon_cycle_cpl .AND. type_ocean/='couple') THEN
 !       WRITE(lunout,*) 'Coupling with ocean model is needed for carbon_cycle_cpl'
-!       CALL abort_gcm('carbon_cycle_init', 'coupled ocean is needed for carbon_cycle_cpl',1)
+!       CALL abort_physic('carbon_cycle_init', 'coupled ocean is needed for carbon_cycle_cpl',1)
 !    END IF
 !
 !    IF (carbon_cycle_cpl .AND..NOT. ok_veget) THEN
 !       WRITE(lunout,*) 'Coupling with surface land model ORCHDIEE is needed for carbon_cycle_cpl'
-!       CALL abort_gcm('carbon_cycle_init', 'ok_veget is needed for carbon_cycle_cpl',1)
+!       CALL abort_physic('carbon_cycle_init', 'ok_veget is needed for carbon_cycle_cpl',1)
 !    END IF
 
@@ -279,5 +279,5 @@
     teststop=0
     DO it=1,teststop
-       CALL abort_gcm('carbon_cycle_init', 'Entering loop from 1 to 0',1)
+       CALL abort_physic('carbon_cycle_init', 'Entering loop from 1 to 0',1)
     END DO
 
@@ -285,10 +285,10 @@
        ! No carbon tracers found in tracer.def. It is not possible to do carbon cycle 
        WRITE(lunout,*) 'No carbon tracers found in tracer.def. Not ok with carbon_cycle_tr and/or carbon_cycle_cp'
-       CALL abort_gcm('carbon_cycle_init', 'No carbon tracers found in tracer.def',1)
+       CALL abort_physic('carbon_cycle_init', 'No carbon tracers found in tracer.def',1)
     END IF
     
 ! 5) Calculate total area of the earth surface
 ! --------------------------------------------
-    CALL reduce_sum(SUM(airephy),airetot)
+    CALL reduce_sum(SUM(cell_area),airetot)
     CALL bcast(airetot)
 
@@ -304,16 +304,16 @@
 ! - Calculate CO2 flux to send to ocean and land models (PISCES and ORCHIDEE)
 
-    USE infotrac
+    USE infotrac_phy, ONLY: nbtr
     USE dimphy
     USE mod_phys_lmdz_transfert_para
     USE phys_cal_mod, ONLY : mth_cur, mth_len
     USE phys_cal_mod, ONLY : day_cur
-    USE comgeomphy
     USE indice_sol_mod
+    USE print_control_mod, ONLY: lunout
+    USE geometry_mod, ONLY : cell_area
 
     IMPLICIT NONE
 
     INCLUDE "clesphys.h"
-    INCLUDE "iniprint.h"
     INCLUDE "YOMCST.h"
 
@@ -371,5 +371,5 @@
              CASE DEFAULT
                 WRITE(lunout,*) 'Error with tracer ',co2trac(it)%name
-                CALL abort_gcm('carbon_cycle', 'No coupling implemented for this tracer',1)
+                CALL abort_physic('carbon_cycle', 'No coupling implemented for this tracer',1)
              END SELECT
           ELSE
@@ -444,5 +444,5 @@
 
           ! Calculate a global mean value of delta CO2 flux
-          fco2_tmp(1:klon) = fco2_tmp(1:klon) * airephy(1:klon)
+          fco2_tmp(1:klon) = fco2_tmp(1:klon) * cell_area(1:klon)
           CALL reduce_sum(SUM(fco2_tmp),sumtmp)
           CALL bcast(sumtmp)
Index: /LMDZ5/branches/testing/libf/phylmd/cdrag.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cdrag.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cdrag.F90	(revision 2408)
@@ -9,4 +9,5 @@
   USE dimphy
   USE indice_sol_mod
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
 ! ================================================================= c
@@ -98,5 +99,4 @@
 !  INCLUDE "indicesol.h"
   INCLUDE "clesphys.h"
-  INCLUDE "iniprint.h"
 !
 ! Quelques constantes et options:
@@ -143,5 +143,5 @@
       WRITE(lunout,*)" The negative q1 is set to zero "
 !      abort_message="voir ci-dessus"
-!      CALL abort_gcm(modname,abort_message,1)
+!      CALL abort_physic(modname,abort_message,1)
   ENDIF
   IF (ng_qsurf.GT.0) THEN
@@ -150,5 +150,5 @@
       WRITE(lunout,*)" The negative qsurf is set to zero "
 !      abort_message="voir ci-dessus"
-!      CALL abort_gcm(modname,abort_message,1)
+!      CALL abort_physic(modname,abort_message,1)
   ENDIF
 
Index: /LMDZ5/branches/testing/libf/phylmd/cfmip_point_locations.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cfmip_point_locations.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cfmip_point_locations.F90	(revision 2408)
@@ -34,8 +34,7 @@
   USE dimphy
   USE iophy
-  USE mod_grid_phy_lmdz
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo
 
   IMPLICIT none 
-#include "dimensions.h"
   INTEGER :: npCFMIP
   REAL, DIMENSION(npCFMIP) :: lonCFMIP, latCFMIP
@@ -44,13 +43,13 @@
   REAL :: dlon1, dlon2
   REAL :: dlat1, dlat2
-  REAL, DIMENSION(iim+1) :: lon
+  REAL, DIMENSION(nbp_lon+1) :: lon
   INTEGER, DIMENSION(npCFMIP) :: tabijGCM
   REAL, DIMENSION(npCFMIP) :: lonGCM, latGCM
 
-  lon(1:iim)=io_lon(:)
-  lon(iim+1)=-1*lon(1)
+  lon(1:nbp_lon)=io_lon(:)
+  lon(nbp_lon+1)=-1*lon(1)
   OPEN(22, file="LMDZ_pointsCFMIP.txt")
   DO np=1, npCFMIP
-  DO i=1, iim
+  DO i=1, nbp_lon
 !
 ! PRINT*,'IM np i lonCF lonGCM lonGCM+1',np,i,lonCFMIP(np),lon(i), &
@@ -85,5 +84,5 @@
    ELSE
     j=j+1
-    IF(j.LE.jjm) THEN 
+    IF(j.LE.nbp_lat-1) THEN 
      GOTO 40
     ENDIF
@@ -99,9 +98,9 @@
      lonGCM(ip)=lon(ipt(ip))
      latGCM(ip)=io_lat(jpt(ip))
-     if(jpt(ip).GE.2.AND.jpt(ip).LE.jjm) THEN     
-      tabijGCM(ip)=1+(jpt(ip)-2)*iim+ipt(ip)
+     if(jpt(ip).GE.2.AND.jpt(ip).LE.nbp_lat-1) THEN     
+      tabijGCM(ip)=1+(jpt(ip)-2)*nbp_lon+ipt(ip)
      else if(jpt(ip).EQ.1) THEN
       tabijGCM(ip)=1
-     else if(jpt(ip).EQ.jjm+1) THEN
+     else if(jpt(ip).EQ.nbp_lat) THEN
       tabijGCM(ip)=klon_glo
      else 
Index: /LMDZ5/branches/testing/libf/phylmd/change_srf_frac_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/change_srf_frac_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/change_srf_frac_mod.F90	(revision 2408)
@@ -33,6 +33,6 @@
     USE ocean_slab_mod, ONLY : fsic, ocean_slab_frac
     USE indice_sol_mod
-
-    INCLUDE "iniprint.h"
+    USE print_control_mod, ONLY: lunout
+    
     INCLUDE "YOMCST.h"
 !albedo SB >>>
@@ -109,5 +109,5 @@
           WRITE(lunout,*)'at point = ',MINLOC(pctsrf(:,:))
           WRITE(lunout,*)'value = ',MINVAL(pctsrf(:,:)) 
-          CALL abort_gcm('change_srf_frac','Negative fraction',1)
+          CALL abort_physic('change_srf_frac','Negative fraction',1)
        END IF
 
@@ -116,5 +116,5 @@
           DO i= 1, klon
              tmpsum = SUM(pctsrf(i,:))
-             IF (ABS(1. - tmpsum) > 0.05) CALL abort_gcm('change_srf_frac','Total fraction not equal 1.',1)
+             IF (ABS(1. - tmpsum) > 0.05) CALL abort_physic('change_srf_frac','Total fraction not equal 1.',1)
           END DO
        END IF
Index: /LMDZ5/branches/testing/libf/phylmd/clcdrag.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/clcdrag.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/clcdrag.F90	(revision 2408)
@@ -73,5 +73,5 @@
 
   abort_message='obsolete, remplace par cdrag, use at you own risk'
-  CALL abort_gcm(modname,abort_message,1)
+  CALL abort_physic(modname,abort_message,1)
 
 
Index: /LMDZ5/branches/testing/libf/phylmd/climb_wind_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/climb_wind_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/climb_wind_mod.F90	(revision 2408)
@@ -44,23 +44,23 @@
 
     ALLOCATE(alf1(klon), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm(modname,'Pb in allocate alf1',1)
+    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocate alf1',1)
 
     ALLOCATE(alf2(klon), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm(modname,'Pb in allocate alf2',1)
+    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocate alf2',1)
 
     ALLOCATE(Kcoefm(klon,klev), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm(modname,'Pb in allocate Kcoefm',1)
+    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocate Kcoefm',1)
 
     ALLOCATE(Ccoef_U(klon,klev), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm(modname,'Pb in allocate Ccoef_U',1)
+    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocate Ccoef_U',1)
 
     ALLOCATE(Dcoef_U(klon,klev), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm(modname,'Pb in allocation Dcoef_U',1)
+    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocation Dcoef_U',1)
 
     ALLOCATE(Ccoef_V(klon,klev), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm(modname,'Pb in allocation Ccoef_V',1)
+    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocation Ccoef_V',1)
 
     ALLOCATE(Dcoef_V(klon,klev), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm(modname,'Pb in allocation Dcoef_V',1)
+    IF (ierr /= 0) CALL abort_physic(modname,'Pb in allocation Dcoef_V',1)
 
     ALLOCATE(Acoef_U(klon), Bcoef_U(klon), Acoef_V(klon), Bcoef_V(klon), STAT=ierr)
Index: /LMDZ5/branches/testing/libf/phylmd/cloudth.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cloudth.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cloudth.F90	(revision 2408)
@@ -19,5 +19,4 @@
 #include "YOETHF.h"
 #include "FCTTRE.h"
-#include "iniprint.h"
 #include "thermcell.h"
 
@@ -284,5 +283,4 @@
 #include "YOETHF.h"
 #include "FCTTRE.h"
-#include "iniprint.h"
 #include "thermcell.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/coef_diff_turb_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/coef_diff_turb_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/coef_diff_turb_mod.F90	(revision 2408)
@@ -18,4 +18,5 @@
     USE dimphy
     USE indice_sol_mod
+    USE print_control_mod, ONLY: prt_level, lunout
 !
 ! Calculate coefficients(ycoefm, ycoefh) for turbulent diffusion in the 
@@ -56,5 +57,4 @@
 !****************************************************************************************
     INCLUDE "clesphys.h"
-    INCLUDE "iniprint.h"
     INCLUDE "compbl.h"
     INCLUDE "YOETHF.h"
@@ -188,4 +188,5 @@
     USE dimphy
     USE indice_sol_mod
+    USE print_control_mod, ONLY: prt_level, lunout
   
 !======================================================================
@@ -211,5 +212,4 @@
     INCLUDE "YOMCST.h"
     INCLUDE "FCTTRE.h"
-    INCLUDE "iniprint.h"
     INCLUDE "compbl.h"
 !
Index: /LMDZ5/branches/testing/libf/phylmd/coefcdrag.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/coefcdrag.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/coefcdrag.F90	(revision 2408)
@@ -78,5 +78,5 @@
 
   abort_message='obsolete, remplace par cdrag, use at you own risk'
-  CALL abort_gcm(modname,abort_message,1)
+  CALL abort_physic(modname,abort_message,1)
 
 !
Index: DZ5/branches/testing/libf/phylmd/comgeomphy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/comgeomphy.F90	(revision 2407)
+++ 	(revision )
@@ -1,23 +1,0 @@
-module comgeomphy
-   real,save,allocatable :: airephy(:)
-   real,save,allocatable :: cuphy(:)
-   real,save,allocatable :: cvphy(:)
-   real,save,allocatable :: rlatd(:)
-   real,save,allocatable :: rlond(:)
-!$OMP THREADPRIVATE(airephy,cuphy,cvphy,rlatd,rlond)
-contains
-  
-  subroutine InitComgeomphy
-  USE mod_phys_lmdz_para
-  implicit none
-    
- 
-    allocate(airephy(klon_omp))
-    allocate(cuphy(klon_omp))
-    allocate(cvphy(klon_omp))
-    allocate(rlatd(klon_omp))
-    allocate(rlond(klon_omp))
-
-  end subroutine InitComgeomphy
-  
-end module comgeomphy
Index: DZ5/branches/testing/libf/phylmd/comgeomphy.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/comgeomphy.h	(revision 2407)
+++ 	(revision )
@@ -1,9 +1,0 @@
-!
-! $Header$
-!
-c
-c
-c Common de passage de la geometrie de la dynamique a la physique
-      real airephy(klon),cuphy(klon),cvphy(klon)
-      REAL rlatd(klon), rlond(klon)
-      common/comgeomphy/airephy,cuphy,cvphy,rlatd, rlond
Index: DZ5/branches/testing/libf/phylmd/compar1d.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/compar1d.h	(revision 2407)
+++ 	(revision )
@@ -1,51 +1,0 @@
-!
-! $Id: compar1d.h 2010-08-04 17:02:56Z lahellec $
-!
-      integer :: forcing_type
-      integer :: tend_u,tend_v,tend_w,tend_t,tend_q,tend_rayo
-      real :: nudge_u,nudge_v,nudge_w,nudge_t,nudge_q
-      integer :: iflag_nudge
-      real :: nat_surf
-      real :: tsurf
-      real :: rugos
-      real :: xqsol(1:2)
-      real :: qsurf
-      real :: psurf
-      real :: zsurf
-      real :: albedo
-
-      real :: time
-      real :: time_ini
-      real :: xlat 
-      real :: xlon 
-      real :: airefi
-      real :: wtsurf 
-      real :: wqsurf 
-      real :: restart_runoff 
-      real :: xagesno 
-      real :: qsolinp 
-      real :: zpicinp 
-
-      logical :: restart
-      logical :: ok_old_disvert
-
-      common/com_par1d/                                                 &
-     & nat_surf,tsurf,rugos,                                            &
-     & xqsol,qsurf,psurf,zsurf,albedo,time,time_ini,xlat,xlon,airefi,   &
-     & wtsurf,wqsurf,restart_runoff,xagesno,qsolinp,zpicinp,            &
-     & forcing_type,tend_u,tend_v,tend_w,tend_t,tend_q,tend_rayo,       &
-     & nudge_u,nudge_v,nudge_w,nudge_t,nudge_q,                         &
-     & iflag_nudge,                                                     &
-     & restart,ok_old_disvert
-
-!$OMP THREADPRIVATE(/com_par1d/)
-
-
-
-
-
-
-
-
-
-
Index: /LMDZ5/branches/testing/libf/phylmd/conccm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/conccm.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/conccm.F90	(revision 2408)
@@ -12,6 +12,4 @@
   ! (schema standard du modele NCAR CCM2)
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -160,6 +158,4 @@
   ! simplifier la lecture et la comprehension.
   ! -----------------------------------------------------------------------
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   INTEGER pcnst ! nombre de traceurs passifs
   PARAMETER (pcnst=1)
Index: /LMDZ5/branches/testing/libf/phylmd/concvl.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/concvl.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/concvl.F90	(revision 2408)
@@ -29,6 +29,7 @@
 
   USE dimphy
-  USE infotrac, ONLY: nbtr
+  USE infotrac_phy, ONLY: nbtr
   USE phys_local_var_mod, ONLY: omega
+  USE print_control_mod, ONLY: prt_level, lunout
   IMPLICIT NONE
 ! ======================================================================
@@ -60,5 +61,5 @@
 ! Ma---------output-R-adiabatic ascent mass flux (kg/m2/s)
 ! mip--------output-R-mass flux shed by adiabatic ascent (kg/m2/s)
-! Vprecip----output-R-vertical profile of precipitations (kg/m2/s)
+! Vprecip----output-R-vertical profile of total precipitation (kg/m2/s)
 ! Tconv------output-R-environment temperature seen by convective scheme (K)
 ! Cape-------output-R-CAPE (J/kg)
@@ -83,5 +84,4 @@
 
   include "clesphys.h"
-  include "dimensions.h"
 
   INTEGER iflag_clos
@@ -109,4 +109,5 @@
 !!       REAL Ma(klon,klev), mip(klon,klev),Vprecip(klon,klev)     !jyg
   REAL Ma(klon, klev), mip(klon, klev), Vprecip(klon, klev+1)      !jyg
+  REAL Vprecipi(klon, klev+1)                                      !jyg
   REAL wght(klon, klev)                                            !RL
 
@@ -214,5 +215,4 @@
   include "YOETHF.h"
   include "FCTTRE.h"
-  include "iniprint.h"
 !jyg<
   include "conema3.h"
@@ -415,5 +415,5 @@
                     iflag, d_t, d_q, d_u, d_v, d_tra, rain, kbas, ktop, &
                     cbmf, plcl, plfc, wbeff, sig1, w01, ptop2, sigd, &
-                    Ma, mip, Vprecip, upwd, dnwd, dnwdbis, qcondc, wd, &
+                    Ma, mip, Vprecip, Vprecipi, upwd, dnwd, dnwdbis, qcondc, wd, &
                     cape, cin, tvp, &
                     dd_t, dd_q, plim1, plim2, asupmax, supmax0, &
@@ -476,15 +476,24 @@
     END DO
   END DO
-!                                                   !jyg
-! --Separation neige/pluie (pour diagnostics)       !jyg
-  DO k = 1, klev                                    !jyg
-    DO i = 1, klon                                  !jyg
-      IF (t1(i,k)<rtt) THEN                         !jyg
-        pmflxs(i, k) = Vprecip(i, k)                !jyg
-      ELSE                                          !jyg
-        pmflxr(i, k) = Vprecip(i, k)                !jyg
-      END IF                                        !jyg
-    END DO                                          !jyg
-  END DO                                            !jyg
+!                                                     !jyg
+  IF (iflag_con == 30 .OR. iflag_ice_thermo ==0) THEN
+! --Separation neige/pluie (pour diagnostics)         !jyg
+    DO k = 1, klev                                    !jyg
+      DO i = 1, klon                                  !jyg
+        IF (t1(i,k)<rtt) THEN                         !jyg
+          pmflxs(i, k) = Vprecip(i, k)                !jyg
+        ELSE                                          !jyg
+          pmflxr(i, k) = Vprecip(i, k)                !jyg
+        END IF                                        !jyg
+      END DO                                          !jyg
+    END DO                                            !jyg
+  ELSE
+    DO k = 1, klev                                    !jyg
+      DO i = 1, klon                                  !jyg
+        pmflxs(i, k) = Vprecipi(i, k)                 !jyg
+        pmflxr(i, k) = Vprecip(i, k)-Vprecipi(i, k)   !jyg
+      END DO                                          !jyg
+    END DO                                            !jyg
+  ENDIF
 
 ! c      IF (if_ebil.ge.2) THEN
Index: /LMDZ5/branches/testing/libf/phylmd/condsurf.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/condsurf.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/condsurf.F90	(revision 2408)
@@ -6,4 +6,5 @@
   USE mod_phys_lmdz_para
   USE indice_sol_mod
+  USE time_phylmdz_mod, ONLY: annee_ref
   IMPLICIT NONE
 
@@ -24,7 +25,4 @@
   INTEGER epais(2)
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  include "temps.h"
   include "clesphys.h"
 
@@ -56,5 +54,5 @@
   IF (jour<0 .OR. jour>(360-1)) THEN
     PRINT *, 'Le jour demande n est pas correct: ', jour
-    CALL abort_gcm('condsurf', '', 1)
+    CALL abort_physic('condsurf', '', 1)
   END IF
 
@@ -76,5 +74,5 @@
     PRINT *, ' trouve pas sur les ', nannemax, ' annees a partir de '
     PRINT *, ' l annee de debut', annee_ref
-    CALL abort_gcm('condsurf', '', 1)
+    CALL abort_physic('condsurf', '', 1)
 
 100 CONTINUE
@@ -96,5 +94,5 @@
       WRITE (6, *) '       l an 2000 )  ,  n existe  pas !  '
       WRITE (6, *) ' ierr = ', ierr
-      CALL abort_gcm('condsurf', '', 1)
+      CALL abort_physic('condsurf', '', 1)
     END IF
     ! DO k = 1, jour
@@ -109,5 +107,5 @@
     ierr = nf_inq_varid(nid, 'BILS', nvarid)
     IF (ierr/=nf_noerr) THEN
-      CALL abort_gcm('cond_surf', 'Le champ <BILS> est absent', 1)
+      CALL abort_physic('cond_surf', 'Le champ <BILS> est absent', 1)
     END IF
     PRINT *, 'debut,epais', debut, epais, 'jour,jourvrai', jour, jourvrai
@@ -118,5 +116,5 @@
 #endif
     IF (ierr/=nf_noerr) THEN
-      CALL abort_gcm('condsurf', 'Lecture echouee pour <BILS>', 1)
+      CALL abort_physic('condsurf', 'Lecture echouee pour <BILS>', 1)
     END IF
     ! ENDDO !k = 1, jour
Index: /LMDZ5/branches/testing/libf/phylmd/conema3.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/conema3.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/conema3.F90	(revision 2408)
@@ -8,5 +8,5 @@
 
   USE dimphy
-  USE infotrac, ONLY: nbtr
+  USE infotrac_phy, ONLY: nbtr
   IMPLICIT NONE
   ! ======================================================================
@@ -53,5 +53,4 @@
   ! ======================================================================
 
-  include "dimensions.h"
   include "conema3.h"
   INTEGER i, l, m, itra
Index: /LMDZ5/branches/testing/libf/phylmd/conemav.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/conemav.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/conemav.F90	(revision 2408)
@@ -8,5 +8,5 @@
 
   USE dimphy
-  USE infotrac, ONLY: nbtr
+  USE infotrac_phy, ONLY: nbtr
   IMPLICIT NONE
   ! ======================================================================
@@ -41,6 +41,4 @@
   ! Ice_flag-input-L-TRUE->prise en compte de la thermodynamique de la glace
   ! ======================================================================
-
-  include "dimensions.h"
 
 
Index: /LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90	(revision 2408)
@@ -27,7 +27,6 @@
     USE phys_cal_mod
     USE carbon_cycle_mod, ONLY : carbon_cycle_tr, carbon_cycle_cpl
-    USE control_mod
     USE mod_grid_phy_lmdz, only: klon_glo
-
+    USE print_control_mod, ONLY: lunout
 
 
@@ -39,5 +38,4 @@
 
     include "thermcell.h"
-    include "iniprint.h"
 
 
@@ -206,5 +204,8 @@
     LOGICAL,SAVE :: ok_strato_omp
     LOGICAL,SAVE :: ok_hines_omp, ok_gwd_rando_omp
-    real, SAVE:: GWD_RANDO_RUWMAX_omp, gwd_rando_sat_omp
+    real, SAVE:: gwd_rando_ruwmax_omp, gwd_rando_sat_omp
+    real, SAVE:: gwd_front_ruwmax_omp, gwd_front_sat_omp
+    real, save:: sso_gkdrag_omp,sso_grahil_omp,sso_grcrit_omp
+    real, save:: sso_gfrcri_omp,sso_gkwake_omp,sso_gklift_omp
     LOGICAL,SAVE :: ok_qch4_omp
     LOGICAL,SAVE      :: carbon_cycle_tr_omp
@@ -220,5 +221,5 @@
     !-----------------------------------------------------------------
 
-     print*,'CONFPHYS ENTREE'
+    print*,'CONFPHYS ENTREE'
     !$OMP MASTER 
     !Config Key  = type_ocean 
@@ -249,5 +250,5 @@
        WRITE(lunout,*)'Variable OCEAN has been replaced by the variable type_ocean.'
        WRITE(lunout,*)'You have to update your parameter file physiq.def to succed running'
-       CALL abort_gcm('conf_phys','Variable OCEAN no longer existing, use variable name type_ocean',1)
+       CALL abort_physic('conf_phys','Variable OCEAN no longer existing, use variable name type_ocean',1)
     END IF
 
@@ -262,5 +263,5 @@
        WRITE(lunout,*)'ERROR! Timestep of coupling between atmosphere and ocean'
        WRITE(lunout,*)'cannot be zero.'
-       CALL abort_gcm('conf_phys','t_coupl = 0.',1)
+       CALL abort_physic('conf_phys','t_coupl = 0.',1)
     END IF
 
@@ -915,5 +916,5 @@
     NSW_omp = 6
     call getin('NSW',NSW_omp)
-!albedo SB >>>
+    !albedo SB >>>
     iflag_albedo_omp = 0
     call getin('iflag_albedo',iflag_albedo_omp)
@@ -921,5 +922,5 @@
     ok_chlorophyll_omp=.false.
     call getin('ok_chlorophyll',ok_chlorophyll_omp)
-!albedo SB <<<
+    !albedo SB <<<
 
     !
@@ -930,7 +931,7 @@
     !
     iflag_cld_th_omp = 1
-! On lit deux fois avec l'ancien et le nouveau nom 
-! pour assurer une retrocompatiblite.
-! A abandonner un jour
+    ! On lit deux fois avec l'ancien et le nouveau nom 
+    ! pour assurer une retrocompatiblite.
+    ! A abandonner un jour
     call getin('iflag_cldcon',iflag_cld_th_omp)
     call getin('iflag_cld_th',iflag_cld_th_omp)
@@ -1680,5 +1681,5 @@
     !
 
-! Gustiness flags
+    ! Gustiness flags
     f_z0qh_oce_omp = 1.
     call getin('f_z0qh_oce',f_z0qh_oce_omp)
@@ -1813,4 +1814,5 @@
     !Config  Def  = .FALSE.
     !Config  Help = active la version stratosph\'erique de LMDZ de F. Lott
+    !               Et la sponge layer (Runs Stratospheriques)
 
     ok_strato_omp=.FALSE.
@@ -1821,8 +1823,29 @@
     !Config  Def  = .FALSE.
     !Config  Help = Clefs controlant la parametrization de Hines
-    !               Et la sponge layer (Runs Stratospheriques)
 
     ok_hines_omp=.FALSE.
     CALL getin('ok_hines',ok_hines_omp)
+
+    !  Parametres pour les ondes de gravite
+    !  
+    !  Subgrid Scale Orography (Lott Miller (1997), Lott (1999))
+
+    sso_gkdrag_omp = merge(0.1875, 0.2, ok_strato_omp)
+    CALL getin('sso_gkdrag', sso_gkdrag_omp)
+
+    sso_grahil_omp=merge(0.1,1.,ok_strato_omp)
+    CALL getin('sso_grahil', sso_grahil_omp)
+
+    sso_grcrit_omp =merge(1.,0.01,ok_strato_omp)
+    CALL getin('sso_grcrit', sso_grcrit_omp)
+
+    sso_gfrcri_omp = 1.
+    CALL getin('sso_gfrcri', sso_gfrcri_omp)
+
+    sso_gkwake_omp = 0.50
+    CALL getin('sso_gkwake', sso_gkwake_omp)
+
+    sso_gklift_omp = merge(0.25,0.50,ok_strato_omp)
+    CALL getin('sso_gklift', sso_gklift_omp)
 
     ! Random gravity waves:
@@ -1836,9 +1859,16 @@
     ENDIF
 
-    GWD_RANDO_RUWMAX_omp = 0.01
-    CALL getin('gwd_rando_ruwmax', GWD_RANDO_RUWMAX_omp)
+    gwd_rando_ruwmax_omp = 2.00
+    CALL getin('gwd_rando_ruwmax', gwd_rando_ruwmax_omp)
 
     gwd_rando_sat_omp = 0.25
     CALL getin('gwd_rando_sat', gwd_rando_sat_omp)
+
+    gwd_front_ruwmax_omp = 2.50
+    CALL getin('gwd_front_ruwmax', gwd_front_ruwmax_omp)
+
+    gwd_front_sat_omp = 0.60
+    CALL getin('gwd_front_sat', gwd_front_sat_omp)
+
 
     !Config  key = ok_qch4
@@ -2022,4 +2052,6 @@
     iflag_radia = iflag_radia_omp
     iflag_rrtm = iflag_rrtm_omp
+    iflag_albedo = iflag_albedo_omp
+    ok_chlorophyll = ok_chlorophyll_omp
     NSW = NSW_omp
     iflag_cld_th = iflag_cld_th_omp
@@ -2098,9 +2130,19 @@
     tmax_fonte_cv = tmax_fonte_cv_omp
     alphas = alphas_omp
+
+    gkdrag=sso_gkdrag_omp
+    grahilo=sso_grahil_omp
+    grcrit=sso_grcrit_omp
+    gfrcrit=sso_gfrcri_omp
+    gkwake=sso_gkwake_omp 
+    gklift=sso_gklift_omp 
+
     ok_strato = ok_strato_omp
     ok_hines = ok_hines_omp
     ok_gwd_rando = ok_gwd_rando_omp
-    GWD_RANDO_RUWMAX = GWD_RANDO_RUWMAX_omp
+    gwd_rando_ruwmax = gwd_rando_ruwmax_omp
     gwd_rando_sat = gwd_rando_sat_omp
+    gwd_front_ruwmax = gwd_front_ruwmax_omp
+    gwd_front_sat = gwd_front_sat_omp
     ok_qch4 = ok_qch4_omp
     ok_LES = ok_LES_omp
@@ -2113,5 +2155,5 @@
     IF (type_ocean=='couple' .AND. (version_ocean/='opa8' .AND. version_ocean/='nemo') ) THEN
        WRITE(lunout,*)' ERROR version_ocean=',version_ocean,' not valid in coupled configuration'
-       CALL abort_gcm('conf_phys','version_ocean not valid',1)
+       CALL abort_physic('conf_phys','version_ocean not valid',1)
     END IF
 
@@ -2119,7 +2161,7 @@
        version_ocean='sicOBS'
     ELSE IF (type_ocean=='slab' .AND. version_ocean/='sicOBS' &
-             .AND. version_ocean/='sicINT' .AND. version_ocean/='sicNO') THEN
+         .AND. version_ocean/='sicINT' .AND. version_ocean/='sicNO') THEN
        WRITE(lunout,*)' ERROR version_ocean=',version_ocean,' not valid with slab ocean'
-       CALL abort_gcm('conf_phys','version_ocean not valid',1)
+       CALL abort_physic('conf_phys','version_ocean not valid',1)
     END IF
 
@@ -2128,8 +2170,8 @@
     IF (ok_ade .OR. ok_aie) THEN 
        IF ( flag_aerosol .EQ. 0 ) THEN
-          CALL abort_gcm('conf_phys','flag_aerosol=0 not compatible avec ok_ade ou ok_aie=.TRUE.',1)
+          CALL abort_physic('conf_phys','flag_aerosol=0 not compatible avec ok_ade ou ok_aie=.TRUE.',1)
        END IF
        IF ( .NOT. new_aod .AND.  flag_aerosol .NE. 1) THEN
-          CALL abort_gcm('conf_phys','new_aod=.FALSE. not compatible avec flag_aerosol=1',1)
+          CALL abort_physic('conf_phys','new_aod=.FALSE. not compatible avec flag_aerosol=1',1)
        END IF
     END IF
@@ -2137,5 +2179,5 @@
     ! ok_cdnc must be set to y if ok_aie is activated
     IF (ok_aie .AND. .NOT. ok_cdnc) THEN
-       CALL abort_gcm('conf_phys', 'ok_cdnc must be set to y if ok_aie is activated',1)
+       CALL abort_physic('conf_phys', 'ok_cdnc must be set to y if ok_aie is activated',1)
     ENDIF
 
@@ -2308,6 +2350,14 @@
     write(lunout,*) 'ok_gwd_rando = ',  ok_gwd_rando
     write(lunout,*) 'ok_qch4 = ',  ok_qch4
-    write(lunout,*) 'GWD_RANDO_RUWMAX = ', GWD_RANDO_RUWMAX
+    write(lunout,*) 'gwd_rando_ruwmax = ', gwd_rando_ruwmax
     write(lunout,*) 'gwd_rando_sat = ', gwd_rando_sat
+    write(lunout,*) 'gwd_front_ruwmax = ', gwd_front_ruwmax
+    write(lunout,*) 'gwd_front_sat = ', gwd_front_sat
+    write(lunout,*) 'SSO gkdrag =',gkdrag
+    write(lunout,*) 'SSO grahilo=',grahilo
+    write(lunout,*) 'SSO grcrit=',grcrit
+    write(lunout,*) 'SSO gfrcrit=',gfrcrit
+    write(lunout,*) 'SSO gkwake=',gkwake
+    write(lunout,*) 'SSO gklift=',gklift
     write(lunout,*) 'read_climoz = ', read_climoz
     write(lunout,*) 'carbon_cycle_tr = ', carbon_cycle_tr
@@ -2328,6 +2378,6 @@
 
   use IOIPSL
+  USE print_control_mod, ONLY: lunout
   implicit none
-  include "iniprint.h"
   ! Configuration de l'interace atm/surf
   !
Index: /LMDZ5/branches/testing/libf/phylmd/conflx.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/conflx.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/conflx.F90	(revision 2408)
@@ -16,6 +16,4 @@
   ! et lessivage des traceurs passifs.
   ! ======================================================================
-  ! yminclude "dimensions.h"
-  ! yminclude "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -210,6 +208,4 @@
   IMPLICIT NONE
   ! ------------------------------------------------------------------
-  ! yminclude "dimensions.h"
-  ! yminclude "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -489,6 +485,4 @@
   ! AND INITIALIZES VALUES FOR UPDRAFTS
   ! ----------------------------------------------------------------------
-  ! yminclude "dimensions.h"
-  ! yminclude "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -619,6 +613,4 @@
   ! (NON ENTRAINING PLUME,I.E.CONSTANT MASSFLUX)
   ! ----------------------------------------------------------------------
-  ! yminclude "dimensions.h"
-  ! yminclude "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -696,6 +688,4 @@
   ! FOR CUMULUS PARAMETERIZATION
   ! ----------------------------------------------------------------------
-  ! yminclude "dimensions.h"
-  ! yminclude "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -992,4 +982,5 @@
     pdpmel, ktopm2, pmflxr, pmflxs)
   USE dimphy
+  USE print_control_mod, ONLY: prt_level
   IMPLICIT NONE
   ! ----------------------------------------------------------------------
@@ -997,10 +988,7 @@
   ! FLUXES IN THE CLOUD LAYER AND IN THE SUBCLOUD LAYER
   ! ----------------------------------------------------------------------
-  ! yminclude "dimensions.h"
-  ! yminclude "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
   include "YOECUMF.h"
-  include "iniprint.h"
 
   REAL cevapcu(klon, klev)
@@ -1242,6 +1230,4 @@
   ! calculer les tendances T et Q
   ! ----------------------------------------------------------------------
-  ! yminclude "dimensions.h"
-  ! yminclude "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -1319,6 +1305,4 @@
   ! MOIST ENVIRONMENTAL AIR AND CLOUD AIR.
   ! ----------------------------------------------------------------------
-  ! yminclude "dimensions.h"
-  ! yminclude "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -1428,6 +1412,4 @@
 
   ! ----------------------------------------------------------------------
-  ! yminclude "dimensions.h"
-  ! yminclude "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -1535,6 +1517,4 @@
   ! kcall=2  EVAPORATION IN DOWNDRAFTS (E.G. CUDLFS,CUDDRAF)
 
-  ! yminclude "dimensions.h"
-  ! yminclude "dimphy.h"
   include "YOMCST.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/conlmd.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/conlmd.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/conlmd.F90	(revision 2408)
@@ -11,6 +11,4 @@
   ! Ajustement humide (Manabe) + Ajustement convectif (Kuo)
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -105,6 +103,4 @@
   ! du modele.
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
@@ -310,6 +306,4 @@
   ! et itop est le haut du plus haut bloc
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
@@ -1059,6 +1053,4 @@
   ! N.B. version vectorielle (le 6 oct. 1997)
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
@@ -1578,6 +1570,4 @@
   ! kcbot---output-I- Niveau du bas de la convection
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -1682,6 +1672,4 @@
   ! KCALL=2  EVAPORATION IN DOWNDRAFTS (E.G. CUDLFS,CUDDRAF)
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
@@ -1777,6 +1765,4 @@
   ! Ajustement humide (Schema de convection de Manabe)
   ! .
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
@@ -2062,6 +2048,4 @@
   IMPLICIT NONE
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/convect1.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/convect1.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/convect1.F90	(revision 2408)
@@ -111,7 +111,4 @@
   USE dimphy
   IMPLICIT NONE
-
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
 
   INTEGER len
Index: /LMDZ5/branches/testing/libf/phylmd/convect2.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/convect2.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/convect2.F90	(revision 2408)
@@ -150,7 +150,4 @@
   USE dimphy
   IMPLICIT NONE
-
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
 
   INTEGER kmax2, imax2, kmin2, imin2
Index: /LMDZ5/branches/testing/libf/phylmd/convect3.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/convect3.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/convect3.F90	(revision 2408)
@@ -16,7 +16,6 @@
   ! #################################################################
   USE dimphy
-  USE infotrac, ONLY: nbtr
+  USE infotrac_phy, ONLY: nbtr
   IMPLICIT NONE
-  include "dimensions.h"
   INTEGER na
   PARAMETER (na=60)
Index: /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_mod.F90	(revision 2408)
@@ -80,5 +80,8 @@
            by the ISCCP Simulator","K", (/ ('', i=1, 3) /))
 
-   LOGICAL, SAVE :: cosp_varsdefined = .FALSE. ! ug PAS THREADPRIVATE ET C'EST NORMAL
+  LOGICAL, SAVE :: cosp_varsdefined = .FALSE. ! ug PAS THREADPRIVATE ET C'EST NORMAL
+  REAL, SAVE  :: Cosp_fill_value
+!$OMP THREADPRIVATE(Cosp_fill_value)
+ 
 
 CONTAINS
@@ -97,4 +100,6 @@
   USE ioipsl
   USE phys_cal_mod
+  USE time_phylmdz_mod, ONLY: day_ref, annee_ref, day_ini, start_time, itau_phy
+  USE print_control_mod, ONLY: lunout
 
 #ifdef CPP_XIOS
@@ -119,6 +124,4 @@
 
 !!! Variables d'entree
-  include "temps.h"
-  INCLUDE 'iniprint.h'
 
 #ifdef CPP_XIOS
@@ -172,4 +175,10 @@
 
 #ifdef CPP_XIOS
+    
+! recuperer la valeur indefine Xios
+!    CALL xios_get_field_attr("clcalipso",default_value=Cosp_fill_value)
+!         Cosp_fill_value=missing_val
+          Cosp_fill_value=0.
+         print*,'Cosp_fill_value=',Cosp_fill_value
     ! ug R\'eglage du calendrier xios
     !Temps julian => an, mois, jour, heure
@@ -230,4 +239,8 @@
 
       CALL histvert(cosp_nidfiles(iff),"column","column","count",Ncolumns,column_ax(1:Ncolumns),nvertcol(iff))
+
+!!! Valeur indefinie en cas IOIPSL
+     Cosp_fill_value=0.
+
 #endif
 
Index: /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_write_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_write_mod.F90	(revision 2408)
@@ -21,5 +21,6 @@
 
     USE ioipsl
-    USE control_mod
+    USE time_phylmdz_mod, ONLY: itau_phy, start_time, day_step_phy
+    USE print_control_mod, ONLY: lunout,prt_level
 
 #ifdef CPP_XIOS
@@ -44,15 +45,12 @@
   real, dimension(Npoints,PARASOL_NREFL) :: parasolcrefl, Ncref
 
-  include "temps.h"
-  include "iniprint.h"
-
   Nlevout = vgrid%Nlvgrid
   Ncolout = Ncolumns
 
 ! A refaire
-       itau_wcosp = itau_phy + itap + start_time * day_step / iphysiq
+       itau_wcosp = itau_phy + itap + start_time * day_step_phy
         if (prt_level >= 10) then
-             WRITE(lunout,*)'itau_wcosp, itap, start_time, day_step, iphysiq =', & 
-                             itau_wcosp, itap, start_time, day_step, iphysiq
+             WRITE(lunout,*)'itau_wcosp, itap, start_time, day_step_phy =', & 
+                             itau_wcosp, itap, start_time, day_step_phy
         endif
 
@@ -92,5 +90,5 @@
      do ip = 1,Npoints
      if(stlidar%lidarcld(ip,k).eq.R_UNDEF)then
-      stlidar%lidarcld(ip,k)=0.
+      stlidar%lidarcld(ip,k)=Cosp_fill_value
      endif
      enddo
@@ -99,5 +97,5 @@
       do ip = 1,Npoints
        if(stlidar%cfad_sr(ip,ii,k).eq.R_UNDEF)then
-        stlidar%cfad_sr(ip,ii,k)=0.
+        stlidar%cfad_sr(ip,ii,k)=Cosp_fill_value
        endif
       enddo
@@ -108,10 +106,10 @@
    do k = 1,Nlevlmdz
      if(sglidar%beta_mol(ip,k).eq.R_UNDEF)then
-      sglidar%beta_mol(ip,k)=0.
+      sglidar%beta_mol(ip,k)=Cosp_fill_value
      endif
 
      do ii= 1,Ncolumns
        if(sglidar%beta_tot(ip,ii,k).eq.R_UNDEF)then
-        sglidar%beta_tot(ip,ii,k)=0.
+        sglidar%beta_tot(ip,ii,k)=Cosp_fill_value
        endif
      enddo
@@ -123,5 +121,5 @@
     do ip = 1,Npoints
      if(stlidar%cldlayer(ip,k).eq.R_UNDEF)then
-      stlidar%cldlayer(ip,k)=0.
+      stlidar%cldlayer(ip,k)=Cosp_fill_value
      endif
     enddo
@@ -167,20 +165,20 @@
    do ip = 1,Npoints
     if(isccp%totalcldarea(ip).eq.-1.E+30)then
-      isccp%totalcldarea(ip)=0.
+      isccp%totalcldarea(ip)=Cosp_fill_value
     endif
     if(isccp%meanptop(ip).eq.-1.E+30)then
-      isccp%meanptop(ip)=0.
+      isccp%meanptop(ip)=Cosp_fill_value
     endif
     if(isccp%meantaucld(ip).eq.-1.E+30)then
-      isccp%meantaucld(ip)=0.
+      isccp%meantaucld(ip)=Cosp_fill_value
     endif
     if(isccp%meanalbedocld(ip).eq.-1.E+30)then
-      isccp%meanalbedocld(ip)=0.
+      isccp%meanalbedocld(ip)=Cosp_fill_value
     endif
     if(isccp%meantb(ip).eq.-1.E+30)then
-      isccp%meantb(ip)=0.
+      isccp%meantb(ip)=Cosp_fill_value
     endif
     if(isccp%meantbclr(ip).eq.-1.E+30)then
-      isccp%meantbclr(ip)=0.
+      isccp%meantbclr(ip)=Cosp_fill_value
     endif
 
@@ -188,5 +186,5 @@
      do ii=1,7
      if(isccp%fq_isccp(ip,ii,k).eq.-1.E+30)then
-      isccp%fq_isccp(ip,ii,k)=0.
+      isccp%fq_isccp(ip,ii,k)=Cosp_fill_value
      endif
      enddo
@@ -195,5 +193,5 @@
     do ii=1,Ncolumns
      if(isccp%boxtau(ip,ii).eq.-1.E+30)then
-       isccp%boxtau(ip,ii)=0.
+       isccp%boxtau(ip,ii)=Cosp_fill_value
      endif
     enddo
@@ -201,5 +199,5 @@
     do ii=1,Ncolumns
      if(isccp%boxptop(ip,ii).eq.-1.E+30)then
-       isccp%boxptop(ip,ii)=0.
+       isccp%boxptop(ip,ii)=Cosp_fill_value
      endif
     enddo
@@ -268,4 +266,6 @@
     use iophy
     USE mod_phys_lmdz_para
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon
+    USE print_control_mod, ONLY: lunout,prt_level
 #ifdef CPP_XIOS
   USE wxios
@@ -274,8 +274,5 @@
     IMPLICIT NONE
 
-    INCLUDE "dimensions.h"
-    INCLUDE "temps.h"
     INCLUDE "clesphys.h"
-    include "iniprint.h"
 
     INTEGER                          :: iff
@@ -320,5 +317,5 @@
        IF ( var%cles(iff) ) THEN
           CALL histdef (cosp_nidfiles(iff), var%name, var%description, var%unit, &
-               iim,jj_nb,nhoricosp(iff), 1,1,1, -99, 32, &
+               nbp_lon,jj_nb,nhoricosp(iff), 1,1,1, -99, 32, &
                typeecrit, zstophym,zoutm_cosp(iff))
        ENDIF
@@ -332,4 +329,6 @@
     use iophy
     USE mod_phys_lmdz_para
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon
+    USE print_control_mod, ONLY: lunout,prt_level
 
 #ifdef CPP_XIOS
@@ -340,8 +339,5 @@
     IMPLICIT NONE
 
-    INCLUDE "dimensions.h"
-    INCLUDE "temps.h"
     INCLUDE "clesphys.h"
-    include "iniprint.h"
 
     INTEGER                        :: iff, klevs
@@ -415,5 +411,5 @@
        IF ( var%cles(iff) ) THEN
           CALL histdef (cosp_nidfiles(iff), nom, var%description, var%unit, &
-               iim, jj_nb, nhoricosp(iff), klevs, 1, &
+               nbp_lon, jj_nb, nhoricosp(iff), klevs, 1, &
                klevs, nvertsave, 32, typeecrit, &
                zstophym, zoutm_cosp(iff))
@@ -428,4 +424,6 @@
   USE ioipsl
   use iophy
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon
+  USE print_control_mod, ONLY: lunout,prt_level
 
 #ifdef CPP_XIOS
@@ -434,6 +432,4 @@
 
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'
-  INCLUDE 'iniprint.h'
   INCLUDE 'clesphys.h'
 
@@ -445,5 +441,5 @@
     REAL,DIMENSION(klon_mpi) :: buffer_omp
     INTEGER, allocatable, DIMENSION(:) :: index2d
-    REAL :: Field2d(iim,jj_nb)
+    REAL :: Field2d(nbp_lon,jj_nb)
     CHARACTER(LEN=20) ::  nomi, nom
     character(len=2) :: str2
@@ -467,5 +463,5 @@
     !Et sinon on.... Ã©crit
     IF (SIZE(field)/=klon) &
-  CALL abort_gcm('iophy::histwrite2d_cosp','Field first DIMENSION not equal to klon',1) 
+  CALL abort_physic('iophy::histwrite2d_cosp','Field first DIMENSION not equal to klon',1) 
 
     CALL Gather_omp(field,buffer_omp)
@@ -477,7 +473,7 @@
       DO iff=1, 3
            IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
-                ALLOCATE(index2d(iim*jj_nb))
+                ALLOCATE(index2d(nbp_lon*jj_nb))
 #ifndef CPP_IOIPSL_NO_OUTPUT
-        CALL histwrite(cosp_nidfiles(iff),var%name,itau_iocosp,Field2d,iim*jj_nb,index2d) 
+        CALL histwrite(cosp_nidfiles(iff),var%name,itau_iocosp,Field2d,nbp_lon*jj_nb,index2d) 
 #endif
                 deallocate(index2d)
@@ -517,4 +513,6 @@
   USE ioipsl
   use iophy
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon
+  USE print_control_mod, ONLY: lunout,prt_level
 
 #ifdef CPP_XIOS
@@ -524,6 +522,4 @@
 
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'
-  INCLUDE 'iniprint.h'
   INCLUDE 'clesphys.h'
 
@@ -536,5 +532,5 @@
 
     REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
-    REAL :: Field3d(iim,jj_nb,SIZE(field,2))
+    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
     INTEGER :: ip, n, nlev
     INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
@@ -568,5 +564,5 @@
     !Et sinon on.... Ã©crit
     IF (SIZE(field,1)/=klon) &
-   CALL abort_gcm('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)                                  
+   CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)                                  
     nlev=SIZE(field,2)
 
@@ -580,7 +576,7 @@
      DO iff=1, 3
         IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
-           ALLOCATE(index3d(iim*jj_nb*nlev))
+           ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
 #ifndef CPP_IOIPSL_NO_OUTPUT
-    CALL histwrite(cosp_nidfiles(iff),nom,itau_iocosp,Field3d,iim*jj_nb*nlev,index3d) 
+    CALL histwrite(cosp_nidfiles(iff),nom,itau_iocosp,Field3d,nbp_lon*jj_nb*nlev,index3d) 
 #endif
 
@@ -613,7 +609,7 @@
     !   en utilisant les routines getin de IOIPSL  
     use ioipsl
+    USE print_control_mod, ONLY: lunout,prt_level
 
     IMPLICIT NONE
-    include 'iniprint.h'
 
    CHARACTER(LEN=20)               :: nam_var, nnam_var
Index: /LMDZ5/branches/testing/libf/phylmd/cosp/phys_cosp.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cosp/phys_cosp.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cosp/phys_cosp.F90	(revision 2408)
@@ -124,6 +124,4 @@
 !$OMP THREADPRIVATE(debut_cosp)
 
-  include "dimensions.h"
-  
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Input variables from LMDZ-GCM
   integer                         :: overlaplmdz   !  overlap type: 1=max, 2=rand, 3=max/rand ! cosp input (output lmdz)
Index: /LMDZ5/branches/testing/libf/phylmd/cpl_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cpl_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cpl_mod.F90	(revision 2408)
@@ -24,6 +24,5 @@
   USE oasis
   USE write_field_phy
-  USE control_mod
-
+  USE time_phylmdz_mod, ONLY: day_step_phy
   
 ! Global attributes
@@ -102,8 +101,7 @@
     USE surface_data
     USE indice_sol_mod
-
-    INCLUDE "dimensions.h"
-    INCLUDE "temps.h"
-    INCLUDE "iniprint.h"
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
+    USE time_phylmdz_mod, ONLY: annee_ref, day_ini, itau_phy, itaufin_phy
+    USE print_control_mod, ONLY: lunout
 
 ! Input arguments
@@ -121,5 +119,5 @@
     INTEGER                           :: npas ! only for OASIS2
     REAL                              :: zjulian
-    REAL, DIMENSION(iim,jjm+1)        :: zx_lon, zx_lat
+    REAL, DIMENSION(nbp_lon,nbp_lat)  :: zx_lon, zx_lat
     CHARACTER(len = 20)               :: modname = 'cpl_init'
     CHARACTER(len = 80)               :: abort_message
@@ -131,5 +129,5 @@
 !*************************************************************************************
      
-    npas = itaufin/ iphysiq
+    npas = itaufin_phy
 !    nexca = 86400 / dtime
     nexca = t_coupl / dtime
@@ -172,25 +170,25 @@
     ALLOCATE(cpl_taumod(klon,2), stat = error)
     sum_error = sum_error + error
-    ALLOCATE(cpl_rriv2D(iim,jj_nb), stat=error)
-    sum_error = sum_error + error
-    ALLOCATE(cpl_rcoa2D(iim,jj_nb), stat=error)
-    sum_error = sum_error + error
-    ALLOCATE(cpl_rlic2D(iim,jj_nb), stat=error)
-    sum_error = sum_error + error
-    ALLOCATE(read_sst(iim, jj_nb), stat = error)
-    sum_error = sum_error + error
-    ALLOCATE(read_sic(iim, jj_nb), stat = error)
-    sum_error = sum_error + error
-    ALLOCATE(read_sit(iim, jj_nb), stat = error)
-    sum_error = sum_error + error
-    ALLOCATE(read_alb_sic(iim, jj_nb), stat = error)
-    sum_error = sum_error + error
-    ALLOCATE(read_u0(iim, jj_nb), stat = error)
-    sum_error = sum_error + error
-    ALLOCATE(read_v0(iim, jj_nb), stat = error)
+    ALLOCATE(cpl_rriv2D(nbp_lon,jj_nb), stat=error)
+    sum_error = sum_error + error
+    ALLOCATE(cpl_rcoa2D(nbp_lon,jj_nb), stat=error)
+    sum_error = sum_error + error
+    ALLOCATE(cpl_rlic2D(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
+    ALLOCATE(read_sic(nbp_lon, jj_nb), stat = error)
+    sum_error = sum_error + error
+    ALLOCATE(read_sit(nbp_lon, jj_nb), stat = error)
+    sum_error = sum_error + error
+    ALLOCATE(read_alb_sic(nbp_lon, jj_nb), stat = error)
+    sum_error = sum_error + error
+    ALLOCATE(read_u0(nbp_lon, jj_nb), stat = error)
+    sum_error = sum_error + error
+    ALLOCATE(read_v0(nbp_lon, jj_nb), stat = error)
     sum_error = sum_error + error
 
     IF (carbon_cycle_cpl) THEN
-       ALLOCATE(read_co2(iim, jj_nb), stat = error)
+       ALLOCATE(read_co2(nbp_lon, jj_nb), stat = error)
        sum_error = sum_error + error
        ALLOCATE(cpl_atm_co2(klon,2), stat = error)
@@ -204,5 +202,5 @@
     IF (sum_error /= 0) THEN
        abort_message='Pb allocation variables couplees'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
 !*************************************************************************************
@@ -230,26 +228,26 @@
        idayref = day_ini
        CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
-       CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlon,zx_lon)
-       DO i = 1, iim
+       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlon,zx_lon)
+       DO i = 1, nbp_lon
           zx_lon(i,1) = rlon(i+1)
-          zx_lon(i,jjm+1) = rlon(i+1)
+          zx_lon(i,nbp_lat) = rlon(i+1)
        ENDDO
-       CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlat,zx_lat)
+       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlat,zx_lat)
        clintocplnam="cpl_atm_tauflx"
-       CALL histbeg(clintocplnam, iim,zx_lon(:,1),jjm+1,zx_lat(1,:),&
-            1,iim,1,jjm+1, itau_phy,zjulian,dtime,nhoridct,nidct) 
+       CALL histbeg(clintocplnam,nbp_lon,zx_lon(:,1),nbp_lat,zx_lat(1,:),&
+            1,nbp_lon,1,nbp_lat, itau_phy,zjulian,dtime,nhoridct,nidct) 
 ! no vertical axis
        CALL histdef(nidct, 'tauxe','tauxe', &
-            "-",iim, jjm+1, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
+            "-",nbp_lon,nbp_lat, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
        CALL histdef(nidct, 'tauyn','tauyn', &
-            "-",iim, jjm+1, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
+            "-",nbp_lon,nbp_lat, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
        CALL histdef(nidct, 'tmp_lon','tmp_lon', &
-            "-",iim, jjm+1, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
+            "-",nbp_lon,nbp_lat, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
        CALL histdef(nidct, 'tmp_lat','tmp_lat', &
-            "-",iim, jjm+1, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
+            "-",nbp_lon,nbp_lat, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
        DO jf=1,maxsend
          IF (infosend(i)%action) THEN
              CALL histdef(nidct, infosend(i)%name ,infosend(i)%name , &
-                "-",iim, jjm+1, nhoridct, 1, 1, 1, -99, 32, "inst", dtime,dtime)
+                "-",nbp_lon,nbp_lat,nhoridct,1,1,1,-99,32,"inst",dtime,dtime)
          ENDIF
        END DO
@@ -258,5 +256,5 @@
        
        clfromcplnam="cpl_atm_sst"
-       CALL histbeg(clfromcplnam, iim,zx_lon(:,1),jjm+1,zx_lat(1,:),1,iim,1,jjm+1, &
+       CALL histbeg(clfromcplnam,nbp_lon,zx_lon(:,1),nbp_lat,zx_lat(1,:),1,nbp_lon,1,nbp_lat, &
             0,zjulian,dtime,nhoridcs,nidcs) 
 ! no vertical axis
@@ -264,5 +262,5 @@
          IF (inforecv(i)%action) THEN
              CALL histdef(nidcs,inforecv(i)%name ,inforecv(i)%name , &
-                "-",iim, jjm+1, nhoridcs, 1, 1, 1, -99, 32, "inst", dtime,dtime)
+                "-",nbp_lon,nbp_lat,nhoridcs,1,1,1,-99,32,"inst",dtime,dtime)
          ENDIF
        END DO
@@ -279,5 +277,5 @@
     IF (carbon_cycle_cpl .AND. version_ocean=='opa8') THEN
        abort_message='carbon_cycle_cpl does not work with opa8'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     END IF
 
@@ -297,9 +295,8 @@
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
     USE indice_sol_mod
-
-    INCLUDE "temps.h"
-    INCLUDE "iniprint.h"
+    USE time_phylmdz_mod, ONLY: start_time, itau_phy
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
+
     INCLUDE "YOMCST.h"
-    INCLUDE "dimensions.h"
 
 ! Arguments
@@ -314,13 +311,13 @@
     INTEGER                                 :: j, i, time_sec
     INTEGER                                 :: itau_w
-    INTEGER, DIMENSION(iim*(jjm+1))         :: ndexcs
+    INTEGER, DIMENSION(nbp_lon*nbp_lat)     :: ndexcs
     CHARACTER(len = 20)                     :: modname = 'cpl_receive_frac'
     CHARACTER(len = 80)                     :: abort_message
     REAL, DIMENSION(klon)                   :: read_sic1D
-    REAL, DIMENSION(iim,jj_nb,maxrecv)      :: tab_read_flds
+    REAL, DIMENSION(nbp_lon,jj_nb,maxrecv)      :: tab_read_flds
     REAL, DIMENSION(klon,nbsrf)             :: pctsrf_old
     REAL, DIMENSION(klon_mpi)               :: rlon_mpi, rlat_mpi
-    REAL, DIMENSION(iim, jj_nb)             :: tmp_lon, tmp_lat
-    REAL, DIMENSION(iim, jj_nb)             :: tmp_r0
+    REAL, DIMENSION(nbp_lon,jj_nb)             :: tmp_lon, tmp_lat
+    REAL, DIMENSION(nbp_lon,jj_nb)             :: tmp_r0
 
 !*************************************************************************************
@@ -346,8 +343,8 @@
        IF (is_sequential) THEN
           ndexcs(:) = 0
-          itau_w = itau_phy + itime + start_time * day_step / iphysiq
+          itau_w = itau_phy + itime + start_time * day_step_phy
           DO i = 1, maxrecv
             IF (inforecv(i)%action) THEN
-                CALL histwrite(nidcs,inforecv(i)%name,itau_w,tab_read_flds(:,:,i),iim*(jjm+1),ndexcs)
+                CALL histwrite(nidcs,inforecv(i)%name,itau_w,tab_read_flds(:,:,i),nbp_lon*(nbp_lat),ndexcs)
             ENDIF
           END DO
@@ -374,5 +371,5 @@
 ! Transform the currents from cartesian to spheric coordinates
 ! tmp_r0 should be zero
-          CALL geo2atm(iim, jj_nb, tab_read_flds(:,:,idr_curenx), &
+          CALL geo2atm(nbp_lon, jj_nb, tab_read_flds(:,:,idr_curenx), &
              tab_read_flds(:,:,idr_cureny), tab_read_flds(:,:,idr_curenz), &
                tmp_lon, tmp_lat, &
@@ -543,5 +540,5 @@
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send
     USE indice_sol_mod
-    INCLUDE "dimensions.h"
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
 
 ! Input arguments
@@ -636,31 +633,31 @@
        IF (.NOT. ALLOCATED(cpl_sols2D)) THEN
           sum_error = 0
-          ALLOCATE(cpl_sols2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_nsol2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_rain2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_snow2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_evap2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_tsol2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_fder2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_albe2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_taux2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_tauy2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_windsp2D(iim,jj_nb), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_taumod2D(iim,jj_nb,2), stat=error)
+          ALLOCATE(cpl_sols2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_nsol2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_rain2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_snow2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_evap2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_tsol2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_fder2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_albe2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_taux2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_tauy2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_windsp2D(nbp_lon,jj_nb), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_taumod2D(nbp_lon,jj_nb,2), stat=error)
           sum_error = sum_error + error
           
           IF (carbon_cycle_cpl) THEN
-             ALLOCATE(cpl_atm_co22D(iim,jj_nb), stat=error)
+             ALLOCATE(cpl_atm_co22D(nbp_lon,jj_nb), stat=error)
              sum_error = sum_error + error
           END IF
@@ -668,5 +665,5 @@
           IF (sum_error /= 0) THEN
              abort_message='Pb allocation variables couplees pour l''ecriture'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
@@ -734,5 +731,5 @@
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
     USE indice_sol_mod
-    INCLUDE "dimensions.h"
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
 
 ! Input arguments
@@ -821,31 +818,31 @@
        IF (.NOT. ALLOCATED(cpl_sols2D)) THEN
           sum_error = 0
-          ALLOCATE(cpl_sols2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_nsol2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_rain2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_snow2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_evap2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_tsol2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_fder2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_albe2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_taux2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_tauy2D(iim,jj_nb,2), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_windsp2D(iim,jj_nb), stat=error)
-          sum_error = sum_error + error
-          ALLOCATE(cpl_taumod2D(iim,jj_nb,2), stat=error)
+          ALLOCATE(cpl_sols2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_nsol2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_rain2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_snow2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_evap2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_tsol2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_fder2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_albe2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_taux2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_tauy2D(nbp_lon,jj_nb,2), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_windsp2D(nbp_lon,jj_nb), stat=error)
+          sum_error = sum_error + error
+          ALLOCATE(cpl_taumod2D(nbp_lon,jj_nb,2), stat=error)
           sum_error = sum_error + error
 
           IF (carbon_cycle_cpl) THEN
-             ALLOCATE(cpl_atm_co22D(iim,jj_nb), stat=error)
+             ALLOCATE(cpl_atm_co22D(nbp_lon,jj_nb), stat=error)
              sum_error = sum_error + error
           END IF
@@ -853,5 +850,5 @@
           IF (sum_error /= 0) THEN
              abort_message='Pb allocation variables couplees pour l''ecriture'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
@@ -914,5 +911,5 @@
 ! (it is done in cpl_send_seaice_fields).
 !
-    INCLUDE "dimensions.h"
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
 
 ! Input arguments
@@ -926,6 +923,6 @@
 ! Local variables
 !*************************************************************************************
-    REAL, DIMENSION(iim,jj_nb)             :: rriv2D
-    REAL, DIMENSION(iim,jj_nb)             :: rcoa2D
+    REAL, DIMENSION(nbp_lon,jj_nb)             :: rriv2D
+    REAL, DIMENSION(nbp_lon,jj_nb)             :: rcoa2D
 
 !*************************************************************************************
@@ -973,5 +970,5 @@
 !
 
-    INCLUDE "dimensions.h"
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
 
 ! Input varibales
@@ -984,5 +981,5 @@
 ! Local varibales
 !*************************************************************************************
-    REAL, DIMENSION(iim,jj_nb)             :: rlic2D
+    REAL, DIMENSION(nbp_lon,jj_nb)             :: rlic2D
 
 !*************************************************************************************
@@ -1028,9 +1025,8 @@
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
     USE indice_sol_mod
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
+    USE time_phylmdz_mod, ONLY: start_time, itau_phy
 ! Some includes
-!*************************************************************************************
-    INCLUDE "temps.h"
-    INCLUDE "dimensions.h"
-    
+!    
 ! Input arguments
 !*************************************************************************************
@@ -1046,18 +1042,18 @@
     INTEGER                                              :: itau_w
     INTEGER                                              :: time_sec
-    INTEGER, DIMENSION(iim*(jjm+1))                      :: ndexct
+    INTEGER, DIMENSION(nbp_lon*(nbp_lat))                      :: ndexct
     REAL                                                 :: Up, Down
-    REAL, DIMENSION(iim, jj_nb)                          :: tmp_lon, tmp_lat
-    REAL, DIMENSION(iim, jj_nb, 4)                       :: pctsrf2D
-    REAL, DIMENSION(iim, jj_nb)                          :: deno
+    REAL, DIMENSION(nbp_lon, jj_nb)                          :: tmp_lon, tmp_lat
+    REAL, DIMENSION(nbp_lon, jj_nb, 4)                       :: pctsrf2D
+    REAL, DIMENSION(nbp_lon, jj_nb)                          :: deno
     CHARACTER(len = 20)                                  :: modname = 'cpl_send_all'
     CHARACTER(len = 80)                                  :: abort_message
    
 ! Variables with fields to coupler
-    REAL, DIMENSION(iim, jj_nb)                          :: tmp_taux
-    REAL, DIMENSION(iim, jj_nb)                          :: tmp_tauy
-    REAL, DIMENSION(iim, jj_nb)                          :: tmp_calv
+    REAL, DIMENSION(nbp_lon, jj_nb)                          :: tmp_taux
+    REAL, DIMENSION(nbp_lon, jj_nb)                          :: tmp_tauy
+    REAL, DIMENSION(nbp_lon, jj_nb)                          :: tmp_calv
 ! Table with all fields to send to coupler
-    REAL, DIMENSION(iim, jj_nb, maxsend)                 :: tab_flds
+    REAL, DIMENSION(nbp_lon, jj_nb, maxsend)                 :: tab_flds
     REAL, DIMENSION(klon_mpi)                            :: rlon_mpi, rlat_mpi
 
@@ -1113,6 +1109,6 @@
 
       DO j = 1, jj_nb
-         tmp_calv(:,j) = DOT_PRODUCT (cpl_rlic2D(1:iim,j), &
-              pctsrf2D(1:iim,j,is_lic)) / REAL(iim)
+         tmp_calv(:,j) = DOT_PRODUCT (cpl_rlic2D(1:nbp_lon,j), &
+              pctsrf2D(1:nbp_lon,j,is_lic)) / REAL(nbp_lon)
       ENDDO
     
@@ -1134,9 +1130,9 @@
          
          IF (.NOT. is_north_pole .AND. ii_begin /=1) THEN
-            Up=Up+tmp_calv(iim,1)
+            Up=Up+tmp_calv(nbp_lon,1)
             tmp_calv(:,1)=Up
          ENDIF
          
-         IF (.NOT. is_south_pole .AND. ii_end /= iim) THEN
+         IF (.NOT. is_south_pole .AND. ii_end /= nbp_lon) THEN
             Down=Down+tmp_calv(1,jj_nb)
             tmp_calv(:,jj_nb)=Down	 
@@ -1227,5 +1223,5 @@
     IF (is_sequential) THEN
        IF (is_north_pole) tmp_lon(:,1)     = tmp_lon(:,2)
-       IF (is_south_pole) tmp_lon(:,jjm+1) = tmp_lon(:,jjm)
+       IF (is_south_pole) tmp_lon(:,nbp_lat) = tmp_lon(:,nbp_lat-1)
     ENDIF
       
@@ -1233,9 +1229,9 @@
     IF (is_sequential) THEN
        ndexct(:) = 0
-       itau_w = itau_phy + itime + start_time * day_step / iphysiq
-       CALL histwrite(nidct,'tauxe',itau_w,tmp_taux,iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,'tauyn',itau_w,tmp_tauy,iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,'tmp_lon',itau_w,tmp_lon,iim*(jjm+1),ndexct)
-       CALL histwrite(nidct,'tmp_lat',itau_w,tmp_lat,iim*(jjm+1),ndexct)
+       itau_w = itau_phy + itime + start_time * day_step_phy
+       CALL histwrite(nidct,'tauxe',itau_w,tmp_taux,nbp_lon*(nbp_lat),ndexct)
+       CALL histwrite(nidct,'tauyn',itau_w,tmp_tauy,nbp_lon*(nbp_lat),ndexct)
+       CALL histwrite(nidct,'tmp_lon',itau_w,tmp_lon,nbp_lon*(nbp_lat),ndexct)
+       CALL histwrite(nidct,'tmp_lat',itau_w,tmp_lat,nbp_lon*(nbp_lat),ndexct)
     ENDIF
 
@@ -1243,5 +1239,5 @@
 ! cartesian 3D coordinates 
 !$OMP MASTER
-    CALL atm2geo (iim, jj_nb, tmp_taux, tmp_tauy, tmp_lon, tmp_lat, &
+    CALL atm2geo (nbp_lon, jj_nb, tmp_taux, tmp_tauy, tmp_lon, tmp_lat, &
          tab_flds(:,:,ids_tauxxu), tab_flds(:,:,ids_tauyyu), tab_flds(:,:,ids_tauzzu) )
     
@@ -1258,5 +1254,5 @@
         DO j=1,maxsend
           IF (infosend(j)%action) CALL histwrite(nidct,infosend(j)%name, itau_w, &
-             tab_flds(:,:,j),iim*(jjm+1),ndexct)
+             tab_flds(:,:,j),nbp_lon*(nbp_lat),ndexct)
         ENDDO
     ENDIF
@@ -1291,5 +1287,5 @@
     IF (sum_error /= 0) THEN
        abort_message='Pb in deallocation of cpl_xxxx2D coupling variables'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
     
@@ -1312,9 +1308,9 @@
 !   champ_out    champ sur la grille 'gatherd'
 !
-    INCLUDE "dimensions.h"
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
 
 ! Input
     INTEGER, INTENT(IN)                       :: knon
-    REAL, DIMENSION(iim,jj_nb), INTENT(IN)    :: champ_in
+    REAL, DIMENSION(nbp_lon,jj_nb), INTENT(IN)    :: champ_in
     INTEGER, DIMENSION(klon), INTENT(IN)      :: knindex
 
@@ -1331,5 +1327,5 @@
     
 
-! Transform from 2 dimensions (iim,jj_nb) to 1 dimension (klon)
+! Transform from 2 dimensions (nbp_lon,jj_nb) to 1 dimension (klon)
 !$OMP MASTER 
     CALL Grid2Dto1D_mpi(champ_in,temp_mpi)
@@ -1361,5 +1357,5 @@
 !   champ_out    champ sur la grille 2D
 !
-    INCLUDE "dimensions.h"
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
     
 ! Input arguments
@@ -1371,5 +1367,5 @@
 ! Output arguments
 !*************************************************************************************
-    REAL, DIMENSION(iim,jj_nb), INTENT(OUT) :: champ_out
+    REAL, DIMENSION(nbp_lon,jj_nb), INTENT(OUT) :: champ_out
 
 ! Local variables
@@ -1387,5 +1383,5 @@
     ENDDO
 
-! Transform from 1 dimension (klon) to 2 dimensions (iim,jj_nb)
+! Transform from 1 dimension (klon) to 2 dimensions (nbp_lon,jj_nb)
     CALL gather_omp(temp_omp,temp_mpi)
 
Index: /LMDZ5/branches/testing/libf/phylmd/ctstar.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ctstar.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/ctstar.F90	(revision 2408)
@@ -0,0 +1,128 @@
+SUBROUTINE CTSTAR(KPROMA,KSTART,KPROF,PTB,PRESBH,PRESBF,POROG,PTSTAR,PT0)
+
+!**** *CTSTAR* - COMPUTES STANDARD SURFACE TEMPERATURE
+!                              AND SURFACE TEMPERATURE.
+
+!     PURPOSE.
+!     --------
+
+!           COMPUTES THE STANDARD SURFACE TEMPERATURE AND THE SURFACE
+!           TEMPERATURE TO BE USED FOR EXTRAPOLATIONS OF TEMPERATURE
+!           AND GEOPOTENTIEL.
+
+!**   INTERFACE.
+!     ----------
+!        *CALL* *CTSTAR(..)*
+
+!        EXPLICIT ARGUMENTS
+!        --------------------
+
+!        KPROMA         - HORIZONTAL DIMENSIONS.             (INPUT)
+!        KSTART         - START OF WORK                      (INPUT)
+!        KPROF          - DEPTH OF WORK                      (INPUT)
+
+!        PTB(KPROMA)    - TEMPERATURE AT NFLEVG-1             (INPUT)
+!        PRESBH(KPROMA) - LOWEST MODEL HALF LEVEL PRESSURES  (INPUT)
+
+!        PRESBF(KPROMA) - PRESSURE AT NFLEVG-1                (INPUT)
+!        POROG(KPROMA)  - MODEL ORGRAPHY                     (INPUT)
+
+
+!        PTSTAR(KPROMA) - SURFACE TEMPERATURE                (OUTPUT)
+
+!        PT0(KPROMA)    - STANDARD SURFACE TEMPERATURE       (OUTPUT)
+
+!        IMPLICIT ARGUMENTS :    CONSTANTS FROM YOMSTA,YOMCST.
+!        --------------------
+
+!     METHOD.
+!     -------
+!        SEE DOCUMENTATION
+
+!     EXTERNALS.   NONE.
+!     ----------
+
+!     REFERENCE.
+!     ----------
+!        ECMWF Research Department documentation of the IFS
+
+!     AUTHOR.
+!     -------
+!        MATS HAMRUD AND PHILIPPE COURTIER  *ECMWF*
+
+!     MODIFICATIONS.
+!     --------------
+!        ORIGINAL : 89-05-02
+
+!      Modification : 93-06-01 M.Hamrud (Comment only, now T from NFLEVG-1)
+!        M.Hamrud      01-Oct-2003 CY28 Cleaning
+
+!     ------------------------------------------------------------------
+
+!USE PARKIND1 
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/xrd/module/parkind1.F90.php#parkind1>  ,ONLY : JPIM     ,JPRB
+!USE YOMHOOK 
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/xrd/module/yomhook.F90.php#yomhook>   ,ONLY : LHOOK,   DR_HOOK
+
+!USE YOMCST, ONLY : RG, RD 
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/arp/module/yomcst.F90.php#yomcst>   , ONLY :  RG
+
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/xrd/support/rg.F.php#rg>       ,RD
+!USE YOMSTA 
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/arp/module/yomsta.F90.php#yomsta>   , ONLY : RDTDZ1
+
+IMPLICIT NONE
+
+include "YOMCST.h"
+!IM INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA
+!IM INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART
+!IM INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF
+INTEGER,INTENT(IN)    :: KPROMA
+INTEGER,INTENT(IN)    :: KSTART
+INTEGER,INTENT(IN)    :: KPROF
+!IM REAL(KIND=JPRB)   ,INTENT(IN)    :: PTB(KPROMA)
+REAL   ,INTENT(IN)    :: PTB(KPROMA)
+!IM REAL(KIND=JPRB)   ,INTENT(IN)    :: PRESBH(KPROMA)
+REAL   ,INTENT(IN)    :: PRESBH(KPROMA)
+!IM REAL(KIND=JPRB)   ,INTENT(IN)    :: PRESBF(KPROMA)
+REAL   ,INTENT(IN)    :: PRESBF(KPROMA)
+!IM REAL(KIND=JPRB)   ,INTENT(IN)    :: POROG(KPROMA)
+REAL   ,INTENT(IN)    :: POROG(KPROMA)
+!IM REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTSTAR(KPROMA)
+REAL   ,INTENT(OUT)   :: PTSTAR(KPROMA)
+!IM REAL(KIND=JPRB)   ,INTENT(OUT)   :: PT0(KPROMA)
+REAL   ,INTENT(OUT)   :: PT0(KPROMA)
+!IM INTEGER(KIND=JPIM) :: JL
+INTEGER :: JL
+
+!IM REAL(KIND=JPRB) :: ZALPHA, ZDTDZSG
+REAL :: ZALPHA, ZDTDZSG
+!IM REAL(KIND=JPRB) :: ZHOOK_HANDLE
+REAL :: ZHOOK_HANDLE
+!IM beg
+REAL, PARAMETER                  :: RDTDZ1=-0.0065 !or USE YOMSTA
+!IM end
+
+!     ------------------------------------------------------------------
+
+!*       1.    COMPUTES SURFACE TEMPERATURE
+!*             THEN STANDARD SURFACE TEMPERATURE.
+
+!IF (LHOOK) CALL DR_HOOK('CTSTAR',0,ZHOOK_HANDLE)
+ZDTDZSG=-RDTDZ1/RG 
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/xrd/support/rg.F.php#rg>
+ZALPHA=ZDTDZSG*RD
+DO JL=KSTART,KPROF
+
+   !IM PTSTAR(JL)=PTB(JL)*(1.0_JPRB+ZALPHA*(PRESBH(JL)/PRESBF(JL)-1.0_JPRB))
+   PTSTAR(JL)=PTB(JL)*(1.0+ZALPHA*(PRESBH(JL)/PRESBF(JL)-1.0))
+   PT0(JL)=PTSTAR(JL)+ZDTDZSG*POROG(JL)
+!  print*,'cstar JL ptb zalpha PRESBH PRESBF ptstar' &
+!  ,JL,PTB(JL),ZALPHA,PRESBH(JL),PRESBF(JL),PTSTAR(JL)
+ENDDO
+
+
+!     ------------------------------------------------------------------
+
+!IF (LHOOK) CALL DR_HOOK('CTSTAR',1,ZHOOK_HANDLE)
+END SUBROUTINE CTSTAR
Index: /LMDZ5/branches/testing/libf/phylmd/cv30_routines.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv30_routines.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cv30_routines.F90	(revision 2408)
@@ -733,8 +733,8 @@
     iflag, nk, icb, icbs, plcl, tnk, qnk, gznk, pbase, buoybase, t, q, qs, u, &
     v, gz, th, tra, h, lv, cpn, p, ph, tv, tp, tvp, clw, sig, w0)
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
 
   include "cv30param.h"
-  include 'iniprint.h'
 
   ! inputs:
@@ -813,5 +813,5 @@
     WRITE (lunout, *) 'strange! nn not equal to ncum: ', nn, ncum
     abort_message = ''
-    CALL abort_gcm(modname, abort_message, 1)
+    CALL abort_physic(modname, abort_message, 1)
   END IF
 
Index: /LMDZ5/branches/testing/libf/phylmd/cv3_inicp.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3_inicp.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3_inicp.F90	(revision 2408)
@@ -109,5 +109,5 @@
       PRINT *, 'WARNING:: AREA OF MIXING PDF IS::', aire
       abort_message = ''
-      CALL abort_gcm(modname, abort_message, 1)
+      CALL abort_physic(modname, abort_message, 1)
     ELSE
       PRINT *, 'Area, mean & std deviation are ::', aire, mu, sigma
Index: /LMDZ5/branches/testing/libf/phylmd/cv3_inip.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3_inip.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3_inip.F90	(revision 2408)
@@ -30,9 +30,8 @@
 !----------------------------------------------
 
+  USE print_control_mod, ONLY: prt_level, lunout
   IMPLICIT NONE
 
   include "YOMCST2.h"
-
-  include 'iniprint.h'
 
 !----------------------------------------------
@@ -138,5 +137,5 @@
       WRITE (lunout, *) 'WARNING:: AREA OF MIXING PDF IS::', aire
       abort_message = ''
-      CALL abort_gcm(modname, abort_message, 1)
+      CALL abort_physic(modname, abort_message, 1)
     ELSE
       PRINT *, 'Area, mean & std deviation are ::', aire, mu, sigma
Index: /LMDZ5/branches/testing/libf/phylmd/cv3_routines.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3_routines.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3_routines.F90	(revision 2408)
@@ -41,4 +41,5 @@
 
 
+! Local variables
   CHARACTER (LEN=20) :: modname = 'cv3_param'
   CHARACTER (LEN=80) :: abort_message
@@ -384,5 +385,5 @@
     IF (ok_new_feed) THEN
       IF (iter==niter) THEN
-        DO k = minorig, nd
+        DO k = minorig, nl
           DO i = 1, len
             IF (ph(i,k)>=plclfeed(i)) pfeedmin(i) = ph(i, k)
@@ -891,8 +892,8 @@
                         h, lv, cpn, p, ph, tv, tp, tvp, clw, &
                         sig, w0)
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
 
   include "cv3param.h"
-  include 'iniprint.h'
 
 !inputs:
@@ -971,5 +972,5 @@
     WRITE (lunout, *) 'strange! nn not equal to ncum: ', nn, ncum
     abort_message = ''
-    CALL abort_gcm(modname, abort_message, 1)
+    CALL abort_physic(modname, abort_message, 1)
   END IF
 
@@ -1074,4 +1075,5 @@
   REAL, DIMENSION (nloc, nd), INTENT (OUT)           :: ep, sigp, hp
   REAL, DIMENSION (nloc, nd), INTENT (OUT)           :: buoy
+  REAL, DIMENSION (nloc, nd), INTENT (OUT)           :: frac
 
 !local variables:
@@ -1082,5 +1084,4 @@
   REAL by, defrac, pden, tbis
   REAL ah0(nloc), cape(nloc), capem(nloc), byp(nloc)
-  REAL frac(nloc, nd)
   LOGICAL lcape(nloc)
   INTEGER iposit(nloc)
@@ -1515,5 +1516,5 @@
 ! =====================================================================
 
-  DO k = 1, nd
+  DO k = 1, nl
     DO i = 1, ncum
       hp(i, k) = h(i, k)
@@ -1532,4 +1533,12 @@
           hp(i, k) = hnk(i) + (lv(i,k)+(cpd-cpv)*t(i,k)+frac(i,k)*lf(i,k))* &
                               ep(i, k)*clw(i, k)
+        END IF
+      END DO
+    END DO
+! Below cloud base, set ice fraction to cloud base value
+    DO k = 1, nl
+      DO i = 1, ncum
+        IF (k<icb(i)) THEN
+          frac(i,k) = frac(i,icb(i))
         END IF
       END DO
@@ -2181,6 +2190,6 @@
 ! MAF: renormalisation de MENT
   CALL zilch(zm, nloc*na)
-  DO jm = 1, nd
-    DO im = 1, nd
+  DO jm = 1, nl
+    DO im = 1, nl
       DO il = 1, ncum
         zm(il, im) = zm(il, im) + (1.-sij(il,im,jm))*ment(il, im, jm)
@@ -2189,6 +2198,6 @@
   END DO
 
-  DO jm = 1, nd
-    DO im = 1, nd
+  DO jm = 1, nl
+    DO im = 1, nl
       DO il = 1, ncum
         IF (zm(il,im)/=0.) THEN
@@ -2199,6 +2208,6 @@
   END DO
 
-  DO jm = 1, nd
-    DO im = 1, nd
+  DO jm = 1, nl
+    DO im = 1, nl
       DO il = 1, ncum
         qents(il, im, jm) = qent(il, im, jm)
@@ -2218,4 +2227,5 @@
                      faci, b, sigd, &
                      wdtrainA, wdtrainM)                                      ! RomP
+  USE print_control_mod, ONLY: prt_level, lunout
   IMPLICIT NONE
 
@@ -2227,31 +2237,35 @@
 
 !inputs:
-  INTEGER ncum, nd, na, ntra, nloc
-  INTEGER icb(nloc), inb(nloc)
-  REAL delt, plcl(nloc)
-  REAL t(nloc, nd), rr(nloc, nd), rs(nloc, nd), gz(nloc, na)
-  REAL u(nloc, nd), v(nloc, nd)
+  INTEGER, INTENT (IN)                               :: ncum, nd, na, ntra, nloc
+  INTEGER, DIMENSION (nloc), INTENT (IN)             :: icb, inb
+  REAL, INTENT(IN)                                   :: delt
+  REAL, DIMENSION (nloc), INTENT (IN)                :: plcl
+  REAL, DIMENSION (nloc, nd), INTENT (IN)            :: t, rr, rs
+  REAL, DIMENSION (nloc, na), INTENT (IN)            :: gz
+  REAL, DIMENSION (nloc, nd), INTENT (IN)            :: u, v
   REAL tra(nloc, nd, ntra)
   REAL p(nloc, nd), ph(nloc, nd+1)
-  REAL ep(nloc, na), sigp(nloc, na), clw(nloc, na)
-  REAL th(nloc, na), tv(nloc, na), lv(nloc, na), cpn(nloc, na)
-  REAL lf(nloc, na)
-  REAL m(nloc, na), ment(nloc, na, na), elij(nloc, na, na)
-  REAL coef_clos(nloc)
+  REAL, DIMENSION (nloc, na), INTENT (IN)            :: ep, sigp, clw
+  REAL, DIMENSION (nloc, na), INTENT (IN)            :: th, tv, lv, cpn
+  REAL, DIMENSION (nloc, na), INTENT (IN)            :: lf
+  REAL, DIMENSION (nloc, na), INTENT (IN)            :: m
+  REAL, DIMENSION (nloc, na, na), INTENT (IN)        :: ment, elij
+  REAL, DIMENSION (nloc), INTENT (IN)                :: coef_clos
 
 !input/output
-  INTEGER iflag(nloc)
+  INTEGER, DIMENSION (nloc), INTENT (INOUT)          :: iflag(nloc)
 
 !outputs:
-  REAL mp(nloc, na), rp(nloc, na), up(nloc, na), vp(nloc, na)
-  REAL water(nloc, na), evap(nloc, na), wt(nloc, na)
-  REAL ice(nloc, na), fondue(nloc, na), faci(nloc, na)
-  REAL trap(nloc, na, ntra)
-  REAL b(nloc, na), sigd(nloc)
+  REAL, DIMENSION (nloc, na), INTENT (OUT)           :: mp, rp, up, vp
+  REAL, DIMENSION (nloc, na), INTENT (OUT)           :: water, evap, wt
+  REAL, DIMENSION (nloc, na), INTENT (OUT)           :: ice, fondue, faci
+  REAL, DIMENSION (nloc, na, ntra), INTENT (OUT)     :: trap
+  REAL, DIMENSION (nloc, na), INTENT (OUT)           :: b
+  REAL, DIMENSION (nloc), INTENT (OUT)               :: sigd
 ! 25/08/10 - RomP---- ajout des masses precipitantes ejectees
 ! de l ascendance adiabatique et des flux melanges Pa et Pm.
 ! Distinction des wdtrain
 ! Pa = wdtrainA     Pm = wdtrainM
-  REAL wdtrainA(nloc, na), wdtrainM(nloc, na)
+  REAL, DIMENSION (nloc, na), INTENT (OUT)           :: wdtrainA, wdtrainM
 
 !local variables
@@ -2273,10 +2287,10 @@
 ! ------------------------------------------------------
 
-  delti = 1./delt
-  tinv = 1./3.
-
-  mp(:, :) = 0.
-
-  DO i = 1, nl
+! =============================
+! --- INITIALIZE OUTPUT ARRAYS 
+! =============================
+!  (loops up to nl+1)
+
+  DO i = 1, nlp
     DO il = 1, ncum
       mp(il, i) = 0.0
@@ -2286,16 +2300,43 @@
       wt(il, i) = 0.001
       water(il, i) = 0.0
-      frac(il, i) = 0.0
       faci(il, i) = 0.0
-      fraci(il, i) = 0.0
       ice(il, i) = 0.0
-      prec(il, i) = 0.0
       fondue(il, i) = 0.0
       evap(il, i) = 0.0
       b(il, i) = 0.0
+    END DO
+  END DO
+!! RomP >>>
+  DO i = 1, nlp
+    DO il = 1, ncum
+      wdtrainA(il, i) = 0.0
+      wdtrainM(il, i) = 0.0
+    END DO
+  END DO
+!! RomP <<<
+
+! ***  Set the fractionnal area sigd of precipitating downdraughts
+  DO il = 1, ncum
+    sigd(il) = sigdz*coef_clos(il)
+  END DO
+
+! =====================================================================
+! --- INITIALIZE VARIOUS ARRAYS AND PARAMETERS USED IN THE COMPUTATIONS
+! =====================================================================
+!  (loops up to nl+1)
+
+  delti = 1./delt
+  tinv = 1./3.
+
+  DO i = 1, nlp
+    DO il = 1, ncum
+      frac(il, i) = 0.0
+      fraci(il, i) = 0.0
+      prec(il, i) = 0.0
       lvcp(il, i) = lv(il, i)/cpn(il, i)
       lfcp(il, i) = lf(il, i)/cpn(il, i)
     END DO
   END DO
+
 !AC!        do k=1,ntra
 !AC!         do i=1,nd
@@ -2305,12 +2346,4 @@
 !AC!         enddo
 !AC!        enddo
-!! RomP >>>
-  DO i = 1, nd
-    DO il = 1, ncum
-      wdtrainA(il, i) = 0.0
-      wdtrainM(il, i) = 0.0
-    END DO
-  END DO
-!! RomP <<<
 
 ! ***  check whether ep(inb)=0, if so, skip precipitating    ***
@@ -2322,9 +2355,4 @@
 !!          if(ep(il,inb(il)).lt.0.0001)lwork(il)=.FALSE.
     lwork(il) = ep(il, inb(il)) >= 0.0001
-  END DO
-
-! ***  Set the fractionnal area sigd of precipitating downdraughts
-  DO il = 1, ncum
-    sigd(il) = sigdz*coef_clos(il)
   END DO
 
@@ -2440,4 +2468,10 @@
         bfac = 1./(sigd(il)*wt(il,i))
 
+!
+    IF (prt_level >= 20) THEN
+      Print*, 'cv3_unsat after provisional rp estimate: rp, afac, bfac ', &
+          i, rp(1, i), afac,bfac
+    ENDIF
+!
 !JYG1
 ! cc        sigt=1.0
@@ -2514,4 +2548,10 @@
           evap(il, i) = (wdtrain(il)+sigd(il)*wt(il,i)*(prec(il,i+1)-prec(il,i))) / &
                         (sigd(il)*(ph(il,i)-ph(il,i+1))*100.)
+!
+    IF (prt_level >= 20) THEN
+      Print*, 'cv3_unsat after evap computation: wdtrain, sigd, wt, prec(i+1),prec(i) ', &
+          i, wdtrain(1), sigd(1), wt(1,i), prec(1,i+1),prec(1,i)
+    ENDIF
+!
 
           d6 = bfac*wdtrain(il) - 100.*sigd(il)*bfac*(ph(il,i)-ph(il,i+1))*evap(il, i)
@@ -2713,4 +2753,10 @@
     END DO
 ! ----------------------------------------------------------------
+!
+    IF (prt_level >= 20) THEN
+      Print*, 'cv3_unsat after mp computation: mp, b(i), b(i-1) ', &
+          i, mp(1, i), b(1,i), b(1,max(i-1,1))
+    ENDIF
+!
 
 ! ***       find mixing ratio of precipitating downdraft     ***
@@ -2804,5 +2850,6 @@
                      nent, elij, traent, sig, &
                      tv, tvp, wghti, &
-                     iflag, precip, Vprecip, ft, fr, fu, fv, ftra, &
+                     iflag, precip, Vprecip, Vprecipi, &     ! jyg: Vprecipi
+                     ft, fr, fu, fv, ftra, &                 ! jyg
                      cbmf, upwd, dnwd, dnwd0, ma, mip, &
 !!                     tls, tps,                             ! useless . jyg
@@ -2818,46 +2865,54 @@
 
 !inputs:
-      INTEGER iflag_mix
-      INTEGER ncum, nd, na, ntra, nloc
-      LOGICAL ok_conserv_q
-      INTEGER icb(nloc), inb(nloc)
-      REAL delt
-      REAL t(nloc, nd), rr(nloc, nd), u(nloc, nd), v(nloc, nd)
-      REAL t_wake(nloc, nd), rr_wake(nloc, nd)
-      REAL s_wake(nloc)
-      REAL tra(nloc, nd, ntra), sig(nloc, nd)
-      REAL gz(nloc, na), ph(nloc, nd+1), h(nloc, na), hp(nloc, na)
-      REAL th(nloc, na), p(nloc, nd), tp(nloc, na)
-      REAL lv(nloc, na), cpn(nloc, na), ep(nloc, na), clw(nloc, na)
-      REAL lf(nloc, na)
-      REAL m(nloc, na), mp(nloc, na), rp(nloc, na), up(nloc, na)
-      REAL vp(nloc, na), wt(nloc, nd), trap(nloc, nd, ntra)
-      REAL water(nloc, na), evap(nloc, na), b(nloc, na), sigd(nloc)
-      REAL fondue(nloc, na), faci(nloc, na), ice(nloc, na)
-      REAL ment(nloc, na, na), qent(nloc, na, na), uent(nloc, na, na)
-      REAL hent(nloc, na, na)
-!IM bug   real vent(nloc,na,na), nent(nloc,na), elij(nloc,na,na)
-      REAL vent(nloc, na, na), elij(nloc, na, na)
-      INTEGER nent(nloc, nd)
-      REAL traent(nloc, na, na, ntra)
-      REAL tv(nloc, nd), tvp(nloc, nd), wghti(nloc, nd)
+      INTEGER, INTENT (IN)                               :: iflag_mix
+      INTEGER, INTENT (IN)                               :: ncum, nd, na, ntra, nloc
+      LOGICAL, INTENT (IN)                               :: ok_conserv_q
+      INTEGER, DIMENSION (nloc), INTENT (IN)             :: icb, inb
+      REAL, INTENT (IN)                                  :: delt
+      REAL, DIMENSION (nloc, nd), INTENT (IN)            :: t, rr, u, v
+      REAL, DIMENSION (nloc, nd), INTENT (IN)            :: t_wake, rr_wake
+      REAL, DIMENSION (nloc), INTENT (IN)                :: s_wake
+      REAL, DIMENSION (nloc, nd, ntra), INTENT (IN)      :: tra
+      REAL, DIMENSION (nloc, nd), INTENT (IN)            :: p
+      REAL, DIMENSION (nloc, nd+1), INTENT (IN)          :: ph
+      REAL, DIMENSION (nloc, na), INTENT (IN)            :: gz, h, hp
+      REAL, DIMENSION (nloc, na), INTENT (IN)            :: th, tp
+      REAL, DIMENSION (nloc, na), INTENT (IN)            :: lv, cpn, ep, clw
+      REAL, DIMENSION (nloc, na), INTENT (IN)            :: lf
+      REAL, DIMENSION (nloc, na), INTENT (IN)            :: rp, up
+      REAL, DIMENSION (nloc, na), INTENT (IN)            :: vp
+      REAL, DIMENSION (nloc, nd), INTENT (IN)            :: wt
+      REAL, DIMENSION (nloc, nd, ntra), INTENT (IN)      :: trap
+      REAL, DIMENSION (nloc, na), INTENT (IN)            :: water, evap, b
+      REAL, DIMENSION (nloc, na), INTENT (IN)            :: fondue, faci, ice
+      REAL, DIMENSION (nloc, na, na), INTENT (IN)        :: qent, uent
+      REAL, DIMENSION (nloc, na, na), INTENT (IN)        :: hent
+      REAL, DIMENSION (nloc, na, na), INTENT (IN)        :: vent, elij
+      INTEGER, DIMENSION (nloc, nd), INTENT (IN)         :: nent
+      REAL, DIMENSION (nloc, na, na, ntra), INTENT (IN)  :: traent
+      REAL, DIMENSION (nloc, nd), INTENT (IN)            :: tv, tvp, wghti
+      REAL,INTENT(IN)                                    :: tau_cld_cv, coefw_cld_cv
 !
 !input/output:
-      INTEGER iflag(nloc)
-      REAL,INTENT(in) :: tau_cld_cv, coefw_cld_cv
+      REAL, DIMENSION (nloc, na), INTENT (INOUT)         :: m, mp
+      REAL, DIMENSION (nloc, na, na), INTENT (INOUT)     :: ment
+      INTEGER, DIMENSION (nloc), INTENT (INOUT)          :: iflag
+      REAL, DIMENSION (nloc, nd), INTENT (INOUT)         :: sig
+      REAL, DIMENSION (nloc), INTENT (INOUT)             :: sigd
 !
 !outputs:
-      REAL precip(nloc)
-      REAL ft(nloc, nd), fr(nloc, nd), fu(nloc, nd), fv(nloc, nd)
-      REAL ftd(nloc, nd), fqd(nloc, nd)
-      REAL ftra(nloc, nd, ntra)
-      REAL upwd(nloc, nd), dnwd(nloc, nd), ma(nloc, nd)
-      REAL dnwd0(nloc, nd), mip(nloc, nd)
-      REAL Vprecip(nloc, nd+1)
-!!      REAL tls(nloc, nd), tps(nloc, nd)                 ! useless . jyg
-      REAL qcondc(nloc, nd) ! cld
-      REAL qtc(nloc,nd), sigt(nloc,nd) ! cld
-      REAL wd(nloc) ! gust
-      REAL cbmf(nloc)
+      REAL, DIMENSION (nloc), INTENT (OUT)               :: precip
+      REAL, DIMENSION (nloc, nd), INTENT (OUT)           :: ft, fr, fu, fv
+      REAL, DIMENSION (nloc, nd), INTENT (OUT)           :: ftd, fqd
+      REAL, DIMENSION (nloc, nd, ntra), INTENT (OUT)     :: ftra
+      REAL, DIMENSION (nloc, nd), INTENT (OUT)           :: upwd, dnwd, ma
+      REAL, DIMENSION (nloc, nd), INTENT (OUT)           :: dnwd0, mip
+      REAL, DIMENSION (nloc, nd+1), INTENT (OUT)         :: Vprecip
+      REAL, DIMENSION (nloc, nd+1), INTENT (OUT)         :: Vprecipi
+!!      REAL tls(nloc, nd), tps(nloc, nd)                    ! useless . jyg
+      REAL, DIMENSION (nloc, nd), INTENT (OUT)           :: qcondc                      ! cld
+      REAL, DIMENSION (nloc, nd), INTENT (OUT)           :: qtc, sigt                   ! cld
+      REAL, DIMENSION (nloc), INTENT (OUT)               :: wd                          ! gust
+      REAL, DIMENSION (nloc), INTENT (OUT)               :: cbmf
 !
 !local variables:
@@ -2887,22 +2942,27 @@
   delti = 1.0/delt
 ! print*,'cv3_yield initialisation delt', delt
-!
+
   DO il = 1, ncum
     precip(il) = 0.0
-    Vprecip(il, nd+1) = 0.0
     wd(il) = 0.0 ! gust
   END DO
 
-  DO i = 1, nd
+!   Fluxes are on a staggered grid : loops extend up to nl+1
+  DO i = 1, nlp
     DO il = 1, ncum
       Vprecip(il, i) = 0.0
+      Vprecipi(il, i) = 0.0                               ! jyg
+      upwd(il, i) = 0.0
+      dnwd(il, i) = 0.0
+      dnwd0(il, i) = 0.0
+      mip(il, i) = 0.0
+    END DO
+  END DO
+  DO i = 1, nl
+    DO il = 1, ncum
       ft(il, i) = 0.0
       fr(il, i) = 0.0
       fu(il, i) = 0.0
       fv(il, i) = 0.0
-      upwd(il, i) = 0.0
-      dnwd(il, i) = 0.0
-      dnwd0(il, i) = 0.0
-      mip(il, i) = 0.0
       ftd(il, i) = 0.0
       fqd(il, i) = 0.0
@@ -2957,6 +3017,8 @@
         IF (cvflag_ice) THEN
           Vprecip(il, i) = wt(il, i)*sigd(il)*(water(il,i)+ice(il,i))/grav
+          Vprecipi(il, i) = wt(il, i)*sigd(il)*ice(il,i)/grav                   ! jyg
         ELSE
           Vprecip(il, i) = wt(il, i)*sigd(il)*water(il, i)/grav
+          Vprecipi(il, i) = 0.                                                  ! jyg
         END IF
       END IF
@@ -3126,6 +3188,12 @@
     IF (num1<=0) GO TO 500
 
-    CALL zilch(amp1, ncum)
-    CALL zilch(ad, ncum)
+!jyg<
+!!    CALL zilch(amp1, ncum)
+!!    CALL zilch(ad, ncum)
+    DO il = 1,ncum
+      amp1(il) = 0.
+      ad(il) = 0.
+    ENDDO
+!>jyg
 
     DO k = 1, nl + 1
@@ -3588,4 +3656,7 @@
     END IF
   END DO
+!
+!    print *,' YIELD : alpha_qpos ',alpha_qpos(1)
+!
   DO il = 1, ncum
     IF (iflag(il)<=1) THEN
@@ -3605,5 +3676,6 @@
         m(il, i) = m(il, i)/alpha_qpos(il)
         mp(il, i) = mp(il, i)/alpha_qpos(il)
-        Vprecip(il, i) = vprecip(il, i)/alpha_qpos(il)
+        Vprecip(il, i) = Vprecip(il, i)/alpha_qpos(il)
+        Vprecipi(il, i) = Vprecipi(il, i)/alpha_qpos(il)                     ! jyg
       END IF
     END DO
@@ -3642,5 +3714,5 @@
 
 
-  DO i = 1, nd
+  DO i = 1, nl
     DO il = 1, ncum
       upwd(il, i) = 0.0
@@ -3654,9 +3726,11 @@
     END DO
   END DO
-  DO i = nl + 1, nd
-    DO il = 1, ncum
-      dnwd0(il, i) = 0.
-    END DO
-  END DO
+!jyg<  (loops stop at nl)
+!!  DO i = nl + 1, nd
+!!    DO il = 1, ncum
+!!      dnwd0(il, i) = 0.
+!!    END DO
+!!  END DO
+!>jyg
 
 
@@ -3753,11 +3827,13 @@
   END DO
 
-  DO i = nl + 1, nd
-    DO il = 1, ncum
-      mip(il, i) = 0.
-    END DO
-  END DO
-
-  DO i = 1, nd
+!jyg<  (loops stop at nl)
+!!  DO i = nl + 1, nd
+!!    DO il = 1, ncum
+!!      mip(il, i) = 0.
+!!    END DO
+!!  END DO
+!>jyg
+
+  DO i = 1, nlp
     DO il = 1, ncum
       ma(il, i) = 0
@@ -3773,9 +3849,11 @@
   END DO
 
-  DO i = nl + 1, nd
-    DO il = 1, ncum
-      ma(il, i) = 0.
-    END DO
-  END DO
+!jyg<  (loops stop at nl)
+!!  DO i = nl + 1, nd
+!!    DO il = 1, ncum
+!!      ma(il, i) = 0.
+!!    END DO
+!!  END DO
+!>jyg
 
   DO i = 1, nl
@@ -3811,5 +3889,5 @@
 !! cld                                                               
                                                                      
-  DO i = 1, nd                                                       ! cld
+  DO i = 1, nl+1                                                     ! cld
     DO il = 1, ncum                                                  ! cld
       mac(il, i) = 0.0                                               ! cld
@@ -3953,6 +4031,6 @@
 ! fraction deau condensee dans les melanges convertie en precip : epm
 ! et eau condensée précipitée dans masse d'air saturé : l_m*dM_m/dzdz.dzdz
-  DO j = 1, na
-    DO k = 1, na
+  DO j = 1, nl
+    DO k = 1, nl
       DO i = 1, ncum
         IF (k>=icb(i) .AND. k<=inb(i) .AND. & 
@@ -3969,6 +4047,6 @@
 
 
-  DO j = 1, na
-    DO k = 1, na
+  DO j = 1, nl
+    DO k = 1, nl
       DO i = 1, ncum
         IF (k>=icb(i) .AND. k<=inb(i)) THEN
@@ -3980,5 +4058,5 @@
   END DO
 
-  DO j = 1, na
+  DO j = 1, nl
     DO k = 1, j - 1
       DO i = 1, ncum
@@ -3991,6 +4069,6 @@
 
 ! matrices pour calculer la tendance des concentrations dans cvltr.F90
-  DO j = 1, na
-    DO k = 1, na
+  DO j = 1, nl
+    DO k = 1, nl
       DO i = 1, ncum
         da(i, j) = da(i, j) + (1.-sigij(i,k,j))*ment(i, k, j)
Index: /LMDZ5/branches/testing/libf/phylmd/cv3a_compress.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3a_compress.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3a_compress.F90	(revision 2408)
@@ -154,5 +154,5 @@
     PRINT *, 'WARNING nn not equal to ncum: ', nn, ncum
     abort_message = ''
-    CALL abort_gcm(modname, abort_message, 1)
+    CALL abort_physic(modname, abort_message, 1)
   END IF
 
@@ -185,5 +185,5 @@
     PRINT *, 'WARNING nn not equal to ncum: ', nn, ncum
     abort_message = ''
-    CALL abort_gcm(modname, abort_message, 1)
+    CALL abort_physic(modname, abort_message, 1)
   END IF
 !
Index: /LMDZ5/branches/testing/libf/phylmd/cv3a_uncompress.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3a_uncompress.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3a_uncompress.F90	(revision 2408)
@@ -3,5 +3,5 @@
                            precip, cbmf, plcl, plfc, wbeff, sig, w0, ptop2, &
                            ft, fq, fu, fv, ftra,  &
-                           sigd, ma, mip, vprecip, upwd, dnwd, dnwd0, &
+                           sigd, ma, mip, vprecip, vprecipi, upwd, dnwd, dnwd0, &
                            qcondc, wd, cape, cin, &
                            tvp, &
@@ -17,5 +17,5 @@
                            precip1, cbmf1, plcl1, plfc1, wbeff1, sig1, w01, ptop21, &
                            ft1, fq1, fu1, fv1, ftra1, &
-                           sigd1, ma1, mip1, vprecip1, upwd1, dnwd1, dnwd01, &
+                           sigd1, ma1, mip1, vprecip1, vprecipi1, upwd1, dnwd1, dnwd01, &
                            qcondc1, wd1, cape1, cin1, &
                            tvp1, &
@@ -57,4 +57,5 @@
   REAL, DIMENSION (nloc, nd), INTENT (IN)            :: ma, mip
   REAL, DIMENSION (nloc, nd+1), INTENT (IN)          :: vprecip
+  REAL, DIMENSION (nloc, nd+1), INTENT (IN)          :: vprecipi
   REAL, DIMENSION (nloc, nd), INTENT (IN)            :: upwd, dnwd, dnwd0
   REAL, DIMENSION (nloc, nd), INTENT (IN)            :: qcondc
@@ -91,4 +92,5 @@
   REAL, DIMENSION (len, nd), INTENT (OUT)            :: ma1, mip1
   REAL, DIMENSION (len, nd+1), INTENT (OUT)          :: vprecip1
+  REAL, DIMENSION (len, nd+1), INTENT (OUT)          :: vprecipi1
   REAL, DIMENSION (len, nd), INTENT (OUT)            :: upwd1, dnwd1, dnwd01
   REAL, DIMENSION (len, nd), INTENT (OUT)            :: qcondc1
@@ -144,5 +146,5 @@
     END DO
    
-    DO k = 1, nl+1
+    DO k = 1, nl
       DO i = 1, ncum
         sig1(idcum(i), k) = sig(i, k)
@@ -155,4 +157,5 @@
         mip1(idcum(i), k) = mip(i, k)
         vprecip1(idcum(i), k) = vprecip(i, k)
+        vprecipi1(idcum(i), k) = vprecipi(i, k)
         upwd1(idcum(i), k) = upwd(i, k)
         dnwd1(idcum(i), k) = dnwd(i, k)
@@ -178,4 +181,14 @@
    
       END DO
+    END DO
+
+! Fluxes are defined on a staggered grid and extend up to nl+1
+    DO i = 1, ncum
+      ma1(idcum(i), nlp) = 0.
+      vprecip1(idcum(i), nlp) = 0.
+      vprecipi1(idcum(i), nlp) = 0.
+      upwd1(idcum(i), nlp) = 0.
+      dnwd1(idcum(i), nlp) = 0.
+      dnwd01(idcum(i), nlp) = 0.
     END DO
    
@@ -203,12 +216,26 @@
 !!      END DO
 !!    END DO
-      DO i = 1, ncum
-        jdcum=idcum(i)
-        phi1    (jdcum, 1:nl+1, 1:nl+1) = phi    (i, 1:nl+1, 1:nl+1)          !AC!
-        phi21   (jdcum, 1:nl+1, 1:nl+1) = phi2   (i, 1:nl+1, 1:nl+1)          !RomP
-        sigij1  (jdcum, 1:nl+1, 1:nl+1) = sigij  (i, 1:nl+1, 1:nl+1)          !RomP
-        elij1   (jdcum, 1:nl+1, 1:nl+1) = elij   (i, 1:nl+1, 1:nl+1)          !RomP
-        epmlmMm1(jdcum, 1:nl+1, 1:nl+1) = epmlmMm(i, 1:nl+1, 1:nl+1)          !RomP+jyg
+
+!!      DO i = 1, ncum
+!!        jdcum=idcum(i)
+!!        phi1    (jdcum, 1:nl+1, 1:nl+1) = phi    (i, 1:nl+1, 1:nl+1)          !AC!
+!!        phi21   (jdcum, 1:nl+1, 1:nl+1) = phi2   (i, 1:nl+1, 1:nl+1)          !RomP
+!!        sigij1  (jdcum, 1:nl+1, 1:nl+1) = sigij  (i, 1:nl+1, 1:nl+1)          !RomP
+!!        elij1   (jdcum, 1:nl+1, 1:nl+1) = elij   (i, 1:nl+1, 1:nl+1)          !RomP
+!!        epmlmMm1(jdcum, 1:nl+1, 1:nl+1) = epmlmMm(i, 1:nl+1, 1:nl+1)          !RomP+jyg
+!!      END DO
+!  These tracer associated arrays are defined up to nl, not nl+1
+  DO i = 1, ncum
+    jdcum=idcum(i)
+    DO k = 1,nl
+      DO j = 1,nl
+        phi1    (jdcum, j, k) = phi    (i, j, k)          !AC!
+        phi21   (jdcum, j, k) = phi2   (i, j, k)          !RomP
+        sigij1  (jdcum, j, k) = sigij  (i, j, k)          !RomP
+        elij1   (jdcum, j, k) = elij   (i, j, k)          !RomP
+        epmlmMm1(jdcum, j, k) = epmlmMm(i, j, k)          !RomP+jyg
       END DO
+    ENDDO
+  ENDDO
 !>jyg
     ! AC!
@@ -246,40 +273,49 @@
       asupmaxmin1(:) = asupmaxmin(:)
 !
-      sig1(:, 1:nl+1) = sig(:, 1:nl+1)
-      w01(:, 1:nl+1) = w0(:, 1:nl+1)
-      ft1(:, 1:nl+1) = ft(:, 1:nl+1)
-      fq1(:, 1:nl+1) = fq(:, 1:nl+1)
-      fu1(:, 1:nl+1) = fu(:, 1:nl+1)
-      fv1(:, 1:nl+1) = fv(:, 1:nl+1)
-      ma1(:, 1:nl+1) = ma(:, 1:nl+1)
-      mip1(:, 1:nl+1) = mip(:, 1:nl+1)
-      vprecip1(:, 1:nl+1) = vprecip(:, 1:nl+1)
-      upwd1(:, 1:nl+1) = upwd(:, 1:nl+1)
-      dnwd1(:, 1:nl+1) = dnwd(:, 1:nl+1)
-      dnwd01(:, 1:nl+1) = dnwd0(:, 1:nl+1)
-      qcondc1(:, 1:nl+1) = qcondc(:, 1:nl+1)
-      tvp1(:, 1:nl+1) = tvp(:, 1:nl+1)
-      ftd1(:, 1:nl+1) = ftd(:, 1:nl+1)
-      fqd1(:, 1:nl+1) = fqd(:, 1:nl+1)
-      asupmax1(:, 1:nl+1) = asupmax(:, 1:nl+1)
-
-      da1(:, 1:nl+1) = da(:, 1:nl+1)              !AC!
-      mp1(:, 1:nl+1) = mp(:, 1:nl+1)              !RomP
-      d1a1(:, 1:nl+1) = d1a(:, 1:nl+1)            !RomP
-      dam1(:, 1:nl+1) = dam(:, 1:nl+1)            !RomP
-      clw1(:, 1:nl+1) = clw(:, 1:nl+1)            !RomP
-      evap1(:, 1:nl+1) = evap(:, 1:nl+1)          !RomP
-      ep1(:, 1:nl+1) = ep(:, 1:nl+1)              !RomP
-      eplamM1(:, 1:nl+1) = eplamM(:, 1:nl+1)       !RomP+jyg
-      wdtrainA1(:, 1:nl+1) = wdtrainA(:, 1:nl+1)  !RomP
-      wdtrainM1(:, 1:nl+1) = wdtrainM(:, 1:nl+1)  !RomP
-      qtc1(:, 1:nl+1) = qtc(:, 1:nl+1)
-      sigt1(:, 1:nl+1) = sigt(:, 1:nl+1)
-!
-      phi1    (:, 1:nl+1, 1:nl+1) = phi    (:, 1:nl+1, 1:nl+1)  !AC!
-      phi21   (:, 1:nl+1, 1:nl+1) = phi2   (:, 1:nl+1, 1:nl+1)  !RomP
-      sigij1  (:, 1:nl+1, 1:nl+1) = sigij  (:, 1:nl+1, 1:nl+1)  !RomP
-      elij1   (:, 1:nl+1, 1:nl+1) = elij   (:, 1:nl+1, 1:nl+1)  !RomP
-      epmlmMm1(:, 1:nl+1, 1:nl+1) = epmlmMm(:, 1:nl+1, 1:nl+1)  !RomP+jyg
+      sig1(:, 1:nl) = sig(:, 1:nl)
+      w01(:, 1:nl) = w0(:, 1:nl)
+      ft1(:, 1:nl) = ft(:, 1:nl)
+      fq1(:, 1:nl) = fq(:, 1:nl)
+      fu1(:, 1:nl) = fu(:, 1:nl)
+      fv1(:, 1:nl) = fv(:, 1:nl)
+      ma1(:, 1:nl) = ma(:, 1:nl)
+      mip1(:, 1:nl) = mip(:, 1:nl)
+      vprecip1(:, 1:nl) = vprecip(:, 1:nl)
+      vprecipi1(:, 1:nl) = vprecipi(:, 1:nl)
+      upwd1(:, 1:nl) = upwd(:, 1:nl)
+      dnwd1(:, 1:nl) = dnwd(:, 1:nl)
+      dnwd01(:, 1:nl) = dnwd0(:, 1:nl)
+      qcondc1(:, 1:nl) = qcondc(:, 1:nl)
+      tvp1(:, 1:nl) = tvp(:, 1:nl)
+      ftd1(:, 1:nl) = ftd(:, 1:nl)
+      fqd1(:, 1:nl) = fqd(:, 1:nl)
+      asupmax1(:, 1:nl) = asupmax(:, 1:nl)
+
+      da1(:, 1:nl) = da(:, 1:nl)              !AC!
+      mp1(:, 1:nl) = mp(:, 1:nl)              !RomP
+      d1a1(:, 1:nl) = d1a(:, 1:nl)            !RomP
+      dam1(:, 1:nl) = dam(:, 1:nl)            !RomP
+      clw1(:, 1:nl) = clw(:, 1:nl)            !RomP
+      evap1(:, 1:nl) = evap(:, 1:nl)          !RomP
+      ep1(:, 1:nl) = ep(:, 1:nl)              !RomP
+      eplamM1(:, 1:nl) = eplamM(:, 1:nl)       !RomP+jyg
+      wdtrainA1(:, 1:nl) = wdtrainA(:, 1:nl)  !RomP
+      wdtrainM1(:, 1:nl) = wdtrainM(:, 1:nl)  !RomP
+      qtc1(:, 1:nl) = qtc(:, 1:nl)
+      sigt1(:, 1:nl) = sigt(:, 1:nl)
+!
+      ma1(:, nlp) = 0.
+      vprecip1(:, nlp) = 0.
+      vprecipi1(:, nlp) = 0.
+      upwd1(:, nlp) = 0.
+      dnwd1(:, nlp) = 0.
+      dnwd01(:, nlp) = 0.
+
+!
+      phi1    (:, 1:nl, 1:nl) = phi    (:, 1:nl, 1:nl)  !AC!
+      phi21   (:, 1:nl, 1:nl) = phi2   (:, 1:nl, 1:nl)  !RomP
+      sigij1  (:, 1:nl, 1:nl) = sigij  (:, 1:nl, 1:nl)  !RomP
+      elij1   (:, 1:nl, 1:nl) = elij   (:, 1:nl, 1:nl)  !RomP
+      epmlmMm1(:, 1:nl, 1:nl) = epmlmMm(:, 1:nl, 1:nl)  !RomP+jyg
   ENDIF !(compress)
 !>jyg
Index: /LMDZ5/branches/testing/libf/phylmd/cv3p1_closure.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3p1_closure.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3p1_closure.F90	(revision 2408)
@@ -19,4 +19,5 @@
   ! **************************************************************
 
+  USE print_control_mod, ONLY: prt_level, lunout
   IMPLICIT NONE
 
@@ -26,5 +27,4 @@
   include "YOMCST.h"
   include "conema3.h"
-  include "iniprint.h"
 
   ! input:
@@ -552,5 +552,5 @@
         , il, alp2(il), alp(il), cin(il)
       abort_message = ''
-      CALL abort_gcm(modname, abort_message, 1)
+      CALL abort_physic(modname, abort_message, 1)
     END IF
     cbmfmax(il) = sigmax*wb2(il)*100.*p(il, icb(il))/(rrd*tv(il,icb(il)))
Index: /LMDZ5/branches/testing/libf/phylmd/cv3p2_closure.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3p2_closure.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3p2_closure.F90	(revision 2408)
@@ -0,0 +1,700 @@
+
+
+SUBROUTINE cv3p2_closure(nloc, ncum, nd, icb, inb, pbase, plcl, p, ph, tv, &
+    tvp, buoy, supmax, ok_inhib, ale, alp, omega,sig, w0, ptop2, cape, cin, m, &
+    iflag, coef, plim1, plim2, asupmax, supmax0, asupmaxmin, cbmflast, plfc, &
+    wbeff)
+
+
+  ! **************************************************************
+  ! *
+  ! CV3P2_CLOSURE                                               *
+  ! Ale & Alp Closure of Convect3              *
+  ! *
+  ! written by   :   Kerry Emanuel                              *
+  ! vectorization:   S. Bony                                    *
+  ! modified by :    Jean-Yves Grandpeix, 18/06/2003, 19.32.10  *
+  ! Julie Frohwirth,     14/10/2005  17.44.22  *
+  ! **************************************************************
+
+  USE print_control_mod, ONLY: prt_level, lunout
+  IMPLICIT NONE
+
+  include "cvthermo.h"
+  include "cv3param.h"
+  include "YOMCST2.h"
+  include "YOMCST.h"
+  include "conema3.h"
+
+  ! input:
+  INTEGER, INTENT (IN)                               :: ncum, nd, nloc
+  INTEGER, DIMENSION (nloc), INTENT (IN)             :: icb, inb
+  REAL, DIMENSION (nloc), INTENT (IN)                :: pbase, plcl
+  REAL, DIMENSION (nloc, nd), INTENT (IN)            :: p
+  REAL, DIMENSION (nloc, nd+1), INTENT (IN)          :: ph
+  REAL, DIMENSION (nloc, nd), INTENT (IN)            :: tv, tvp, buoy
+  REAL, DIMENSION (nloc, nd), INTENT (IN)            :: supmax
+  LOGICAL, INTENT (IN)                               :: ok_inhib ! enable convection inhibition by dryness
+  REAL, DIMENSION (nloc), INTENT (IN)                :: ale, alp
+  REAL, DIMENSION (nloc, nd), INTENT (IN)            :: omega
+
+  ! input/output:
+  REAL, DIMENSION (nloc, nd), INTENT (INOUT)         :: sig, w0
+  REAL, DIMENSION (nloc), INTENT (INOUT)             :: ptop2
+
+  ! output:
+  REAL, DIMENSION (nloc), INTENT (OUT)               :: cape, cin
+  REAL, DIMENSION (nloc, nd), INTENT (OUT)           :: m
+  REAL, DIMENSION (nloc), INTENT (OUT)               :: plim1, plim2
+  REAL, DIMENSION (nloc, nd), INTENT (OUT)           :: asupmax
+  REAL, DIMENSION (nloc), INTENT (OUT)               :: supmax0
+  REAL, DIMENSION (nloc), INTENT (OUT)               :: asupmaxmin
+  REAL, DIMENSION (nloc), INTENT (OUT)               :: cbmflast, plfc
+  REAL, DIMENSION (nloc), INTENT (OUT)               :: wbeff
+  INTEGER, DIMENSION (nloc), INTENT (OUT)            :: iflag
+
+  ! local variables:
+  INTEGER                                            :: il, i, j, k, icbmax
+  INTEGER, DIMENSION (nloc)                          :: i0, klfc
+  REAL                                               :: deltap, fac, w, amu
+  REAL, DIMENSION (nloc, nd)                         :: rhodp               ! Factor such that m=rhodp*sig*w
+  REAL                                               :: pbmxup
+  REAL, DIMENSION (nloc, nd)                         :: dtmin, sigold
+  REAL, DIMENSION (nloc, nd)                         :: coefmix
+  REAL, DIMENSION (nloc)                             :: pzero, ptop2old
+  REAL, DIMENSION (nloc)                             :: cina, cinb
+  INTEGER, DIMENSION (nloc)                          :: ibeg
+  INTEGER, DIMENSION (nloc)                          :: nsupmax
+  REAL                                               :: supcrit
+  REAL, DIMENSION (nloc, nd)                         :: temp
+  REAL, DIMENSION (nloc)                             :: p1, pmin
+  REAL, DIMENSION (nloc)                             :: asupmax0
+  LOGICAL, DIMENSION (nloc)                          :: ok
+  REAL, DIMENSION (nloc, nd)                         :: siglim, wlim, mlim
+  REAL, DIMENSION (nloc)                             :: wb2
+  REAL, DIMENSION (nloc)                             :: cbmf0        ! initial cloud base mass flux
+  REAL, DIMENSION (nloc)                             :: cbmflim      ! cbmf given by Cape closure
+  REAL, DIMENSION (nloc)                             :: cbmfalp      ! cbmf given by Alp closure
+  REAL, DIMENSION (nloc)                             :: cbmfalpb     ! bounded cbmf given by Alp closure
+  REAL, DIMENSION (nloc)                             :: cbmfmax      ! upper bound on cbmf
+  REAL, DIMENSION (nloc)                             :: coef
+  REAL, DIMENSION (nloc)                             :: xp, xq, xr, discr, b3, b4
+  REAL, DIMENSION (nloc)                             :: theta, bb
+  REAL                                               :: term1, term2, term3
+  REAL, DIMENSION (nloc)                             :: alp2                  ! Alp with offset
+
+  REAL                                               :: sigmax
+  PARAMETER (sigmax=0.1)
+!!  PARAMETER (sigmax=10.)
+
+  CHARACTER (LEN=20)                                 :: modname = 'cv3p2_closure'
+  CHARACTER (LEN=80)                                 :: abort_message
+
+  INTEGER,SAVE                                       :: igout=1
+!$OMP THREADPRIVATE(igout)
+
+ IF (prt_level>=20) print *,' -> cv3p2_closure, Ale ',ale(igout)
+
+
+  ! -------------------------------------------------------
+  ! -- Initialization
+  ! -------------------------------------------------------
+
+
+  DO il = 1, ncum
+    alp2(il) = max(alp(il), 1.E-5)
+    ! IM
+    alp2(il) = max(alp(il), 1.E-12)
+  END DO
+
+  pbmxup = 50. ! PBMXUP+PBCRIT = cloud depth above which mixed updraughts
+  ! exist (if any)
+
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure nloc ncum nd icb inb nl', nloc, &
+    ncum, nd, icb(nloc), inb(nloc), nl
+  DO k = 1, nl
+    DO il = 1, ncum
+      m(il, k) = 0.0
+      rhodp(il,k) = 0.007*p(il, k)*(ph(il,k)-ph(il,k+1))/tv(il, k)
+    END DO
+  END DO
+
+  ! -------------------------------------------------------
+  ! -- Reset sig(i) and w0(i) for i>inb and i<icb
+  ! -------------------------------------------------------
+
+  ! update sig and w0 above LNB:
+
+  DO k = 1, nl - 1
+    DO il = 1, ncum
+      IF ((inb(il)<(nl-1)) .AND. (k>=(inb(il)+1))) THEN
+        sig(il, k) = beta*sig(il, k) + 2.*alpha*buoy(il, inb(il))*abs(buoy(il,inb(il)))
+        sig(il, k) = amax1(sig(il,k), 0.0)
+        w0(il, k) = beta*w0(il, k)
+      END IF
+    END DO
+  END DO
+
+  ! if(prt.level.GE.20) print*,'cv3p2_closure apres 100'
+  ! compute icbmax:
+
+  icbmax = 2
+  DO il = 1, ncum
+    icbmax = max(icbmax, icb(il))
+  END DO
+  ! if(prt.level.GE.20) print*,'cv3p2_closure apres 200'
+
+  ! update sig and w0 below cloud base:
+
+  DO k = 1, icbmax
+    DO il = 1, ncum
+      IF (k<=icb(il)) THEN
+        sig(il, k) = beta*sig(il, k) - 2.*alpha*buoy(il, icb(il))*buoy(il,icb(il))
+        sig(il, k) = amax1(sig(il,k), 0.0)
+        w0(il, k) = beta*w0(il, k)
+      END IF
+    END DO
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres 300'
+
+  ! -------------------------------------------------------------
+  ! -- Reset fractional areas of updrafts and w0 at initial time
+  ! -- and after 10 time steps of no convection
+  ! -------------------------------------------------------------
+
+  DO k = 1, nl - 1
+    DO il = 1, ncum
+      IF (sig(il,nd)<1.5 .OR. sig(il,nd)>12.0) THEN
+        sig(il, k) = 0.0
+        w0(il, k) = 0.0
+      END IF
+    END DO
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres 400'
+
+  ! -------------------------------------------------------
+  ! -- Compute initial cloud base mass flux (Cbmf0)
+  ! -------------------------------------------------------
+  DO il = 1, ncum
+    cbmf0(il) = 0.0
+  END DO
+
+  DO k = 1, nl
+    DO il = 1, ncum
+      IF (k>=icb(il) .AND. k<=inb(il) & 
+          .AND. icb(il)+1<=inb(il)) THEN
+        cbmf0(il) = cbmf0(il) + sig(il, k)*w0(il,k)*rhodp(il,k)
+      END IF
+    END DO
+  END DO
+
+  ! -------------------------------------------------------------
+  ! jyg1
+  ! --  Calculate adiabatic ascent top pressure (ptop)
+  ! -------------------------------------------------------------
+
+
+  ! c 1. Start at first level where precipitations form
+  DO il = 1, ncum
+    pzero(il) = plcl(il) - pbcrit
+  END DO
+
+  ! c 2. Add offset
+  DO il = 1, ncum
+    pzero(il) = pzero(il) - pbmxup
+  END DO
+  DO il = 1, ncum
+    ptop2old(il) = ptop2(il)
+  END DO
+
+  DO il = 1, ncum
+    ! CR:c est quoi ce 300??
+    p1(il) = pzero(il) - 300.
+  END DO
+
+  ! compute asupmax=abs(supmax) up to lnm+1
+
+  DO il = 1, ncum
+    ok(il) = .TRUE.
+    nsupmax(il) = inb(il)
+  END DO
+
+  DO i = 1, nl
+    DO il = 1, ncum
+      IF (i>icb(il) .AND. i<=inb(il)) THEN
+        IF (p(il,i)<=pzero(il) .AND. supmax(il,i)<0 .AND. ok(il)) THEN
+          nsupmax(il) = i
+          ok(il) = .FALSE.
+        END IF ! end IF (P(i) ...  )
+      END IF ! end IF (icb+1 le i le inb)
+    END DO
+  END DO
+
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres 2.'
+  DO i = 1, nl
+    DO il = 1, ncum
+      asupmax(il, i) = abs(supmax(il,i))
+    END DO
+  END DO
+
+
+  DO il = 1, ncum
+    asupmaxmin(il) = 10.
+    pmin(il) = 100.
+    ! IM ??
+    asupmax0(il) = 0.
+  END DO
+
+  ! c 3.  Compute in which level is Pzero
+
+  ! IM bug      i0 = 18
+  DO il = 1, ncum
+    i0(il) = nl
+  END DO
+
+  DO i = 1, nl
+    DO il = 1, ncum
+      IF (i>icb(il) .AND. i<=inb(il)) THEN
+        IF (p(il,i)<=pzero(il) .AND. p(il,i)>=p1(il)) THEN
+          IF (pzero(il)>p(il,i) .AND. pzero(il)<p(il,i-1)) THEN
+            i0(il) = i
+          END IF
+        END IF
+      END IF
+    END DO
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres 3.'
+
+  ! c 4.  Compute asupmax at Pzero
+
+  DO i = 1, nl
+    DO il = 1, ncum
+      IF (i>icb(il) .AND. i<=inb(il)) THEN
+        IF (p(il,i)<=pzero(il) .AND. p(il,i)>=p1(il)) THEN
+          asupmax0(il) = ((pzero(il)-p(il,i0(il)-1))*asupmax(il,i0(il))- &
+            (pzero(il)-p(il,i0(il)))*asupmax(il,i0(il)-1))/(p(il,i0(il))-p(il,i0(il)-1))
+        END IF
+      END IF
+    END DO
+  END DO
+
+
+  DO i = 1, nl
+    DO il = 1, ncum
+      IF (p(il,i)==pzero(il)) THEN
+        asupmax(i, il) = asupmax0(il)
+      END IF
+    END DO
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres 4.'
+
+  ! c 5. Compute asupmaxmin, minimum of asupmax
+
+  DO i = 1, nl
+    DO il = 1, ncum
+      IF (i>icb(il) .AND. i<=inb(il)) THEN
+        IF (p(il,i)<=pzero(il) .AND. p(il,i)>=p1(il)) THEN
+          IF (asupmax(il,i)<asupmaxmin(il)) THEN
+            asupmaxmin(il) = asupmax(il, i)
+            pmin(il) = p(il, i)
+          END IF
+        END IF
+      END IF
+    END DO
+  END DO
+
+  DO il = 1, ncum
+    ! IM
+    IF (prt_level>=20) THEN
+      PRINT *, 'cv3p2_closure il asupmax0 asupmaxmin', il, asupmax0(il), &
+        asupmaxmin(il), pzero(il), pmin(il)
+    END IF
+    IF (asupmax0(il)<asupmaxmin(il)) THEN
+      asupmaxmin(il) = asupmax0(il)
+      pmin(il) = pzero(il)
+    END IF
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres 5.'
+
+
+  ! Compute Supmax at Pzero
+
+  DO i = 1, nl
+    DO il = 1, ncum
+      IF (i>icb(il) .AND. i<=inb(il)) THEN
+        IF (p(il,i)<=pzero(il)) THEN
+          supmax0(il) = ((p(il,i)-pzero(il))*asupmax(il,i-1)- &
+            (p(il,i-1)-pzero(il))*asupmax(il,i))/(p(il,i)-p(il,i-1))
+          GO TO 425
+        END IF ! end IF (P(i) ... )
+      END IF ! end IF (icb+1 le i le inb)
+    END DO
+  END DO
+
+425 CONTINUE
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres 425.'
+
+  ! c 6. Calculate ptop2
+
+  DO il = 1, ncum
+    IF (asupmaxmin(il)<supcrit1) THEN
+      ptop2(il) = pmin(il)
+    END IF
+
+    IF (asupmaxmin(il)>supcrit1 .AND. asupmaxmin(il)<supcrit2) THEN
+      ptop2(il) = ptop2old(il)
+    END IF
+
+    IF (asupmaxmin(il)>supcrit2) THEN
+      ptop2(il) = ph(il, inb(il))
+    END IF
+  END DO
+
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres 6.'
+
+  ! c 7. Compute multiplying factor for adiabatic updraught mass flux
+
+
+  IF (ok_inhib) THEN
+
+    DO i = 1, nl
+      DO il = 1, ncum
+        IF (i<=nl) THEN
+          coefmix(il, i) = (min(ptop2(il),ph(il,i))-ph(il,i))/(ph(il,i+1)-ph(il,i))
+          coefmix(il, i) = min(coefmix(il,i), 1.)
+        END IF
+      END DO
+    END DO
+
+
+  ELSE ! when inhibition is not taken into account, coefmix=1
+
+
+
+    DO i = 1, nl
+      DO il = 1, ncum
+        IF (i<=nl) THEN
+          coefmix(il, i) = 1.
+        END IF
+      END DO
+    END DO
+
+  END IF ! ok_inhib
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres 7.'
+  ! -------------------------------------------------------------------
+  ! -------------------------------------------------------------------
+
+
+  ! jyg2
+
+  ! ==========================================================================
+
+
+  ! -------------------------------------------------------------
+  ! -- Calculate convective inhibition (CIN)
+  ! -------------------------------------------------------------
+
+  ! do i=1,nloc
+  ! print*,'avant cine p',pbase(i),plcl(i)
+  ! enddo
+  ! do j=1,nd
+  ! do i=1,nloc
+  ! print*,'avant cine t',tv(i),tvp(i)
+  ! enddo
+  ! enddo
+  CALL cv3_cine(nloc, ncum, nd, icb, inb, pbase, plcl, p, ph, tv, tvp, cina, &
+    cinb, plfc)
+
+  DO il = 1, ncum
+    cin(il) = cina(il) + cinb(il)
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure after cv3_cine: cina, cinb, cin ', &
+                              cina(igout), cinb(igout), cin(igout)
+  ! -------------------------------------------------------------
+  ! --Update buoyancies to account for Ale
+  ! -------------------------------------------------------------
+
+  CALL cv3_buoy(nloc, ncum, nd, icb, inb, pbase, plcl, p, ph, ale, cin, tv, &
+    tvp, buoy)
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure after cv3_buoy'
+
+  ! -------------------------------------------------------------
+  ! -- Calculate convective available potential energy (cape),
+  ! -- vertical velocity (w), fractional area covered by
+  ! -- undilute updraft (sig), and updraft mass flux (m)
+  ! -------------------------------------------------------------
+
+  DO il = 1, ncum
+    cape(il) = 0.0
+  END DO
+
+  ! compute dtmin (minimum buoyancy between ICB and given level k):
+
+  DO k = 1, nl
+    DO il = 1, ncum
+      dtmin(il, k) = 100.0
+    END DO
+  END DO
+
+  DO k = 1, nl
+    DO j = minorig, nl
+      DO il = 1, ncum
+        IF ((k>=(icb(il)+1)) .AND. (k<=inb(il)) .AND. (j>=icb(il)) &
+                             .AND. (j<=(k-1))) THEN
+          dtmin(il, k) = amin1(dtmin(il,k), buoy(il,j))
+        END IF
+      END DO
+    END DO
+  END DO
+!
+  IF (prt_level >= 20) THEN
+    print *,'cv3p2_closure: dtmin ', (k, dtmin(igout,k), k=1,nl)
+  ENDIF
+!
+  ! the interval on which cape is computed starts at pbase :
+
+  DO k = 1, nl
+    DO il = 1, ncum
+
+      IF ((k>=(icb(il)+1)) .AND. (k<=inb(il))) THEN
+
+        deltap = min(pbase(il), ph(il,k-1)) - min(pbase(il), ph(il,k))
+        cape(il) = cape(il) + rrd*buoy(il, k-1)*deltap/p(il, k-1)
+        cape(il) = amax1(0.0, cape(il))
+        sigold(il, k) = sig(il, k)
+
+
+        ! jyg       Coefficient coefmix limits convection to levels where a
+        ! sufficient
+        ! fraction of mixed draughts are ascending.
+        siglim(il, k) = coefmix(il, k)*alpha1*dtmin(il, k)*abs(dtmin(il,k))
+        siglim(il, k) = amax1(siglim(il,k), 0.0)
+        siglim(il, k) = amin1(siglim(il,k), 0.01)
+        ! c         fac=AMIN1(((dtcrit-dtmin(il,k))/dtcrit),1.0)
+        fac = 1.
+        wlim(il, k) = fac*sqrt(cape(il))
+        amu = siglim(il, k)*wlim(il, k)
+!!        rhodp(il,k) = 0.007*p(il, k)*(ph(il,k)-ph(il,k+1))/tv(il, k) !cor jyg : computed earlier
+        mlim(il, k) = amu*rhodp(il,k)
+        ! print*, 'siglim ', k,siglim(1,k)
+      END IF
+
+    END DO
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres 600'
+
+  DO il = 1, ncum
+    ! IM beg
+    IF (prt_level>=20) THEN
+      PRINT *, 'cv3p2_closure il icb mlim ph ph+1 ph+2', il, icb(il), &
+        mlim(il, icb(il)+1), ph(il, icb(il)), ph(il, icb(il)+1), &
+        ph(il, icb(il)+2)
+    END IF
+
+    IF (icb(il)+1<=inb(il)) THEN
+      ! IM end
+      mlim(il, icb(il)) = 0.5*mlim(il,icb(il)+1)*(ph(il,icb(il))-ph(il,icb(il)+1))/ &
+                                               (ph(il,icb(il)+1)-ph(il,icb(il)+2))
+      ! IM beg
+    END IF !(icb(il.le.inb(il))) then
+    ! IM end
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres 700'
+
+  ! 
+  ! ------------------------------------------------------------------------
+  ! c     Compute Cloud base mass flux given by Cape closure (cbmflim = cbmf of 
+  ! c     elementary systems), cbmf given by Alp closure (cbmfalp), cbmf given by Alp 
+  ! c     closure with an upper bound imposed (cbmfalpb) and cbmf resulting from
+  ! c     time integration (cbmflast).
+  ! ------------------------------------------------------------------------
+
+  DO il = 1, ncum
+    cbmflim(il) = 0.
+    cbmfalp(il) = 0.
+    cbmfalpb(il) = 0.
+    cbmflast(il) = 0.
+  END DO
+
+  ! c 1. Compute cloud base mass flux of elementary system (Cbmflim)
+
+  DO k = 1, nl
+    DO il = 1, ncum
+      ! old       IF (k .ge. icb(il) .and. k .le. inb(il)) THEN
+      ! IM        IF (k .ge. icb(il)+1 .and. k .le. inb(il)) THEN
+      IF (k>=icb(il) .AND. k<=inb(il) & !cor jyg
+          .AND. icb(il)+1<=inb(il)) THEN !cor jyg
+        cbmflim(il) = cbmflim(il) + mlim(il, k)
+      END IF
+    END DO
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure after cbmflim: cbmflim ', cbmflim(igout)
+
+  ! 1.5 Compute cloud base mass flux given by Alp closure (Cbmfalp), maximum
+  !     allowed mass flux (Cbmfmax) and bounded mass flux (Cbmfalpb)
+  !     Cbmfalpb is set to zero if Cbmflim (the mass flux of elementary cloud)
+  !     is exceedingly small.
+
+  DO il = 1, ncum
+    wb2(il) = sqrt(2.*max(ale(il)+cin(il),0.))
+  END DO
+
+  DO il = 1, ncum
+    IF (plfc(il)<100.) THEN
+      ! This is an irealistic value for plfc => no calculation of wbeff
+      wbeff(il) = 100.1
+    ELSE
+      ! Calculate wbeff
+      IF (flag_wb==0) THEN
+        wbeff(il) = wbmax
+      ELSE IF (flag_wb==1) THEN
+        wbeff(il) = wbmax/(1.+500./(ph(il,1)-plfc(il)))
+      ELSE IF (flag_wb==2) THEN
+        wbeff(il) = wbmax*(0.01*(ph(il,1)-plfc(il)))**2
+      END IF
+    END IF
+  END DO
+
+!CR:Compute k at plfc
+  DO il=1,ncum
+           klfc(il)=nl
+  ENDDO
+  DO k=1,nl
+     DO il=1,ncum
+        if ((plfc(il).lt.ph(il,k)).and.(plfc(il).ge.ph(il,k+1))) then
+           klfc(il)=k
+        endif
+     ENDDO
+  ENDDO
+!RC
+
+  DO il = 1, ncum
+    ! jyg    Modification du coef de wb*wb pour conformite avec papier Wake
+    ! c       cbmfalp(il) = alp2(il)/(0.5*wb*wb-Cin(il))
+    cbmfalp(il) = alp2(il)/(2.*wbeff(il)*wbeff(il)-cin(il))
+!CR: Add large-scale component to the mass-flux
+!encore connu sous le nom "Experience du tube de dentifrice"
+    if ((coef_clos_ls.gt.0.).and.(plfc(il).gt.0.)) then 
+       cbmfalp(il) = cbmfalp(il) - coef_clos_ls*min(0.,1./RG*omega(il,klfc(il)))
+    endif
+!RC
+    IF (cbmfalp(il)==0 .AND. alp2(il)/=0.) THEN
+      WRITE (lunout, *) 'cv3p2_closure cbmfalp=0 and alp NE 0 il alp2 alp cin ' , &
+                         il, alp2(il), alp(il), cin(il)
+      abort_message = ''
+      CALL abort_physic(modname, abort_message, 1)
+    END IF
+    cbmfmax(il) = sigmax*wb2(il)*100.*p(il, icb(il))/(rrd*tv(il,icb(il)))
+  END DO
+
+  DO il = 1, ncum
+    IF (cbmflim(il)>1.E-6) THEN
+      ! ATTENTION TEST CR
+      ! if (cbmfmax(il).lt.1.e-12) then
+      cbmfalpb(il) = min(cbmfalp(il), cbmfmax(il))
+      ! else
+      ! cbmfalpb(il) = cbmfalp(il)
+      ! endif
+      ! print*,'cbmfalpb',cbmfalp(il),cbmfmax(il)
+    END IF
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres cbmfalpb: cbmfalpb ',cbmfalpb(igout)
+
+  ! c 2. Compute coefficient and apply correction
+
+  DO il = 1, ncum
+    coef(il) = (cbmfalpb(il)+1.E-10)/(cbmflim(il)+1.E-10)
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres coef_plantePLUS'
+
+     DO k = 1, nl
+       DO il = 1, ncum
+         IF (k>=icb(il)+1 .AND. k<=inb(il)) THEN
+           amu = beta*sig(il, k)*w0(il, k) + (1.-beta)*coef(il)*siglim(il, k)*wlim(il, k)
+           w0(il, k) = wlim(il, k)
+           w0(il, k) = max(w0(il,k), 1.E-10)
+           sig(il, k) = amu/w0(il, k)
+           sig(il, k) = min(sig(il,k), 1.)
+           ! c         amu = 0.5*(SIG(il,k)+sigold(il,k))*W0(il,k)
+           !jyg m(il, k) = amu*0.007*p(il, k)*(ph(il,k)-ph(il,k+1))/tv(il, k)
+           m(il, k) = amu*rhodp(il,k)
+         END IF
+       END DO
+     END DO
+  ! jyg2
+  DO il = 1, ncum
+    w0(il, icb(il)) = 0.5*w0(il, icb(il)+1)
+    m(il, icb(il)) = 0.5*m(il, icb(il)+1)*(ph(il,icb(il))-ph(il,icb(il)+1))/ &
+                                         (ph(il,icb(il)+1)-ph(il,icb(il)+2))
+    sig(il, icb(il)) = sig(il, icb(il)+1)
+    sig(il, icb(il)-1) = sig(il, icb(il))
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres w0_sig_M: w0, sig ', &
+                         (k,w0(igout,k),sig(igout,k), k=icb(igout),inb(igout))
+
+  ! c 3. Compute final cloud base mass flux;
+  ! c    set iflag to 3 if cloud base mass flux is exceedingly small and is 
+  ! c     decreasing (i.e. if the final mass flux (cbmflast) is greater than 
+  ! c     the target mass flux (cbmfalpb)).
+
+!jyg  DO il = 1, ncum
+!jyg    cbmflast(il) = 0.
+!jyg  END DO
+
+  DO k = 1, nl
+    DO il = 1, ncum
+      IF (k>=icb(il) .AND. k<=inb(il)) THEN
+          !IMpropo??      IF ((k.ge.(icb(il)+1)).and.(k.le.inb(il))) THEN
+        cbmflast(il) = cbmflast(il) + m(il, k)
+      END IF
+    END DO
+  END DO
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure apres cbmflast: cbmflast ',cbmflast(igout)
+
+  DO il = 1, ncum
+    IF (cbmflast(il)<1.E-6 .AND. cbmflast(il)>=cbmfalpb(il)) THEN
+      iflag(il) = 3
+    END IF
+  END DO
+
+  DO k = 1, nl
+    DO il = 1, ncum
+      IF (iflag(il)>=3) THEN
+        m(il, k) = 0.
+        sig(il, k) = 0.
+        w0(il, k) = 0.
+      END IF
+    END DO
+  END DO
+!
+  IF (prt_level >= 10) THEN
+   print *,'cv3p2_closure: iflag ',iflag(igout)
+  ENDIF
+!
+
+  ! c 4. Introduce a correcting factor for coef, in order to obtain an
+  ! effective
+  ! c    sigdz larger in the present case (using cv3p2_closure) than in the
+  ! old
+  ! c    closure (using cv3_closure).
+  IF (1==0) THEN
+    DO il = 1, ncum
+      ! c      coef(il) = 2.*coef(il)
+      coef(il) = 5.*coef(il)
+    END DO
+    ! version CVS du ..2008
+  ELSE
+    IF (iflag_cvl_sigd==0) THEN
+      ! test pour verifier qu on fait la meme chose qu avant: sid constant
+      coef(1:ncum) = 1.
+    ELSE
+      coef(1:ncum) = min(2.*coef(1:ncum), 5.)
+      coef(1:ncum) = max(2.*coef(1:ncum), 0.2)
+    END IF
+  END IF
+
+  IF (prt_level>=20) PRINT *, 'cv3p2_closure FIN'
+  RETURN
+END SUBROUTINE cv3p2_closure
+
+
Index: /LMDZ5/branches/testing/libf/phylmd/cv3p_mixing.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv3p_mixing.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cv3p_mixing.F90	(revision 2408)
@@ -13,4 +13,6 @@
 ! **************************************************************
 
+  USE print_control_mod, ONLY: mydebug=>debug , lunout, prt_level
+
   IMPLICIT NONE
 
@@ -30,5 +32,5 @@
   REAL, DIMENSION (nloc, nd, ntra), INTENT (IN)      :: tra ! input of convect3
   REAL, DIMENSION (nloc, na), INTENT (IN)            :: lv
-  REAL, DIMENSION (nloc, na), INTENT (IN)            :: h  !liquid water static energy of environMent
+  REAL, DIMENSION (nloc, na), INTENT (IN)            :: h  !liquid water static energy of environment
   REAL, DIMENSION (nloc, na), INTENT (IN)            :: hp !liquid water static energy of air shed from adiab. asc.
   REAL, DIMENSION (nloc, na), INTENT (IN)            :: tv, tvp
@@ -39,5 +41,5 @@
   REAL, DIMENSION (nloc, na, na), INTENT (OUT)       :: uent, vent
   REAL, DIMENSION (nloc, na, na), INTENT (OUT)       :: Sigij, elij
-  REAL, DIMENSION (nloc, na), INTENT (OUT)           :: supmax(nloc, na) ! Highest mixing fraction of mixed
+  REAL, DIMENSION (nloc, na), INTENT (OUT)           :: supmax           ! Highest mixing fraction of mixed
                                                                          ! updraughts with the sign of (h-hp)
   REAL, DIMENSION (nloc, nd, nd, ntra), INTENT (OUT) :: traent
@@ -68,4 +70,7 @@
   INTEGER nstep
 
+  INTEGER,SAVE                                       :: igout=1
+!$OMP THREADPRIVATE(igout)
+
 ! --   Mixing probability distribution functions
 
@@ -97,4 +102,8 @@
     Qcoef1max = Qcoef1(Fmax)
     Qcoef2max = Qcoef2(Fmax)
+!<jyg
+   print*, 'fmax, gammas, qqa1, qqa2, Qcoef1max, Qcoef2max ', &
+            fmax, gammas, qqa1, qqa2, Qcoef1max, Qcoef2max
+!>jyg
 
   END IF
@@ -131,13 +140,13 @@
 !AC!
 
-  DO k = 1, ntra
-    DO j = 1, nd ! instead nlp
-      DO i = 1, nd ! instead nlp
-        DO il = 1, ncum
-          traent(il, i, j, k) = tra(il, j, k)
-        END DO
-      END DO
-    END DO
-  END DO
+!jyg!  DO k = 1, ntra
+!jyg!    DO j = 1, nd ! instead nlp
+!jyg!      DO i = 1, nd ! instead nlp
+!jyg!        DO il = 1, ncum
+!jyg!          traent(il, i, j, k) = tra(il, j, k)
+!jyg!        END DO
+!jyg!      END DO
+!jyg!    END DO
+!jyg!  END DO
 
 ! =====================================================================
@@ -188,4 +197,12 @@
     END DO
 
+!jygdebug<
+    IF (prt_level >= 10) THEN
+      print *,'cv3p_mixing i, nent(i), icb, inb ',i, nent(igout,i), icb(igout), inb(igout)
+      IF (nent(igout,i) .gt. 0) THEN
+        print *,'i,(j,Sij(i,j),j=icb-1,inb) ',i,(j,Sij(igout,i,j),j=icb(igout)-1,inb(igout))
+      ENDIF
+    ENDIF
+!>jygdebug
 
 ! ***   if no air can entrain at level i assume that updraft detrains  ***
@@ -209,13 +226,13 @@
   END DO
 
-  DO j = 1, ntra
-    DO i = minorig + 1, nl
-      DO il = 1, ncum
-        IF (i>=icb(il) .AND. i<=inb(il) .AND. nent(il,i)==0) THEN
-          traent(il, i, i, j) = tra(il, nk(il), j)
-        END IF
-      END DO
-    END DO
-  END DO
+!jyg!  DO j = 1, ntra
+!jyg!    DO i = minorig + 1, nl
+!jyg!      DO il = 1, ncum
+!jyg!        IF (i>=icb(il) .AND. i<=inb(il) .AND. nent(il,i)==0) THEN
+!jyg!          traent(il, i, i, j) = tra(il, nk(il), j)
+!jyg!        END IF
+!jyg!      END DO
+!jyg!    END DO
+!jyg!  END DO
 
   DO j = minorig, nl
@@ -470,16 +487,16 @@
         END IF
       END DO
-      DO k = 1, ntra
-        DO il = 1, ncum
-          IF ((i>=icb(il)) .AND. (i<=inb(il)) .AND. &
-              (j>=(icb(il)-1)) .AND. (j<=inb(il)) .AND. &
-              lwork(il)) THEN
-            IF (Sij(il,i,j)>0.0) THEN
-              traent(il, i, j, k) = Sigij(il, i, j)*tra(il, i, k) + &
-                                    (1.-Sigij(il,i,j))*tra(il, nk(il), k)
-            END IF
-          END IF
-        END DO
-      END DO
+!jyg!      DO k = 1, ntra
+!jyg!        DO il = 1, ncum
+!jyg!          IF ((i>=icb(il)) .AND. (i<=inb(il)) .AND. &
+!jyg!              (j>=(icb(il)-1)) .AND. (j<=inb(il)) .AND. &
+!jyg!              lwork(il)) THEN
+!jyg!            IF (Sij(il,i,j)>0.0) THEN
+!jyg!              traent(il, i, j, k) = Sigij(il, i, j)*tra(il, i, k) + &
+!jyg!                                    (1.-Sigij(il,i,j))*tra(il, nk(il), k)
+!jyg!            END IF
+!jyg!          END IF
+!jyg!        END DO
+!jyg!      END DO
 
 ! --    If I=J (detrainement and entrainement at the same level), then only the
@@ -504,15 +521,15 @@
           END IF
         END DO
-        DO k = 1, ntra
-          DO il = 1, ncum
-            IF ((i>=icb(il)) .AND. (i<=inb(il)) .AND. &
-                (j>=(icb(il)-1)) .AND. (j<=inb(il)) .AND. &
-                lwork(il)) THEN
-              IF (Sij(il,i,j)>0.0) THEN
-                traent(il, i, i, k) = tra(il, nk(il), k)
-              END IF
-            END IF
-          END DO
-        END DO
+!jyg!        DO k = 1, ntra
+!jyg!          DO il = 1, ncum
+!jyg!            IF ((i>=icb(il)) .AND. (i<=inb(il)) .AND. &
+!jyg!                (j>=(icb(il)-1)) .AND. (j<=inb(il)) .AND. &
+!jyg!                lwork(il)) THEN
+!jyg!              IF (Sij(il,i,j)>0.0) THEN
+!jyg!                traent(il, i, i, k) = tra(il, nk(il), k)
+!jyg!              END IF
+!jyg!            END IF
+!jyg!          END DO
+!jyg!        END DO
 
       END IF
@@ -568,12 +585,12 @@
     END DO ! il
 
-    DO j = 1, ntra
-      DO il = 1, ncum
-        IF (i>=icb(il) .AND. i<=inb(il) .AND. lwork(il) .AND. csum(il,i)<1.) THEN
-! cc     :     .and. csum(il,i).lt.m(il,i) ) then
-          traent(il, i, i, j) = tra(il, nk(il), j)
-        END IF
-      END DO
-    END DO
+!jyg!    DO j = 1, ntra
+!jyg!      DO il = 1, ncum
+!jyg!        IF (i>=icb(il) .AND. i<=inb(il) .AND. lwork(il) .AND. csum(il,i)<1.) THEN
+!jyg!! cc     :     .and. csum(il,i).lt.m(il,i) ) then
+!jyg!          traent(il, i, i, j) = tra(il, nk(il), j)
+!jyg!        END IF
+!jyg!      END DO
+!jyg!    END DO
 
 ! ---------------------------------------------------------------
Index: /LMDZ5/branches/testing/libf/phylmd/cv_driver.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv_driver.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cv_driver.F90	(revision 2408)
@@ -95,7 +95,4 @@
 
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-
   ! Input
   INTEGER len
Index: /LMDZ5/branches/testing/libf/phylmd/cv_routines.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cv_routines.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cv_routines.F90	(revision 2408)
@@ -396,4 +396,5 @@
     tp1, tvp1, clw1, iflag, nk, icb, cbmf, plcl, tnk, qnk, gznk, t, q, qs, u, &
     v, gz, h, lv, cpn, p, ph, tv, tp, tvp, clw, dph)
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
 
@@ -422,6 +423,4 @@
   CHARACTER (LEN=20) :: modname = 'cv_compress'
   CHARACTER (LEN=80) :: abort_message
-
-  include 'iniprint.h'
 
 
@@ -453,5 +452,5 @@
     WRITE (lunout, *) 'strange! nn not equal to ncum: ', nn, ncum
     abort_message = ''
-    CALL abort_gcm(modname, abort_message, 1)
+    CALL abort_physic(modname, abort_message, 1)
   END IF
 
Index: /LMDZ5/branches/testing/libf/phylmd/cva_driver.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cva_driver.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cva_driver.F90	(revision 2408)
@@ -16,5 +16,5 @@
                       sig1, w01, & !input/output
                       ptop21, sigd1, &
-                      ma1, mip1, Vprecip1, upwd1, dnwd1, dnwd01, &
+                      ma1, mip1, Vprecip1, Vprecipi1, upwd1, dnwd1, dnwd01, &      ! jyg
                       qcondc1, wd1, &
                       cape1, cin1, tvp1, &
@@ -39,4 +39,5 @@
 
   USE dimphy
+  USE print_control_mod, ONLY: prt_level, lunout
   IMPLICIT NONE
 
@@ -98,5 +99,6 @@
 ! Ma1           Real           Output       mass flux adiabatic updraft
 ! mip1          Real           Output       mass flux shed by the adiabatic updraft
-! Vprecip1      Real           Output       vertical profile of precipitations
+! Vprecip1      Real           Output       vertical profile of total precipitation
+! Vprecipi1     Real           Output       vertical profile of ice precipitation
 ! upwd1         Real           Output       total upward mass flux (adiab+mixed)
 ! dnwd1         Real           Output       saturated downward mass flux (mixed)
@@ -158,7 +160,4 @@
 
 
-  include "dimensions.h"
-!!!!!#include "dimphy.h"
-  include 'iniprint.h'
 
 ! Input
@@ -222,4 +221,5 @@
 ! real Vprecip1(len,nd)
   REAL, DIMENSION (len, ndp1), INTENT (OUT)          :: vprecip1
+  REAL, DIMENSION (len, ndp1), INTENT (OUT)          :: vprecipi1
   REAL, DIMENSION (len, nd), INTENT (OUT)            :: upwd1
   REAL, DIMENSION (len, nd), INTENT (OUT)            :: dnwd1
@@ -500,4 +500,5 @@
 ! real Vprecip(nloc,klev)
   REAL vprecip(nloc, klev+1)
+  REAL vprecipi(nloc, klev+1)
   REAL tra(nloc, klev, ntra), trap(nloc, klev, ntra)
   REAL ftra(nloc, klev, ntra), traent(nloc, klev, klev, ntra)
@@ -529,4 +530,7 @@
   CHARACTER (LEN=80) :: abort_message
 
+  INTEGER,SAVE                                       :: igout=1
+!$OMP THREADPRIVATE(igout)
+
 
 ! print *, 't1, t1_wake ',(k,t1(1,k),t1_wake(1,k),k=1,klev)
@@ -588,4 +592,7 @@
   precip1(:) = 0.
   cbmf1(:) = 0.
+  plcl1(:) = 0.
+  plfc1(:) = 0.
+  wbeff1(:) = 0.
   ptop21(:) = 0.
   sigd1(:) = 0.
@@ -593,4 +600,5 @@
   mip1(:, :) = 0.
   vprecip1(:, :) = 0.
+  vprecipi1(:, :) = 0.
   upwd1(:, :) = 0.
   dnwd1(:, :) = 0.
@@ -635,4 +643,5 @@
   sigij1(:, :, :) = 0.
   elij1(:, :, :) = 0.
+  wghti1(:,:) = 0.
   phi21(:, :, :) = 0.
   d1a1(:, :) = 0.
@@ -686,5 +695,5 @@
     WRITE (lunout, *) 'changer la valeur de sig2feed dans physiq.def'
     abort_message = ''
-    CALL abort_gcm(modname, abort_message, 1)
+    CALL abort_physic(modname, abort_message, 1)
   END IF
 
@@ -911,5 +920,5 @@
                          pbase, p, ph, tv, buoy, &
                          sig, w0, cape, m, iflag)
-      END IF
+      END IF   ! iflag_clos==0
 
       ok_inhib = iflag_mix == 2
@@ -921,5 +930,6 @@
 ! c    :                       ,supmax
 ! c    o                       ,sig,w0,ptop2,cape,cin,m)
-      END IF
+      END IF   ! iflag_clos==1
+
       IF (iflag_clos==2) THEN
         CALL cv3p1_closure(nloc, ncum, nd, icb, inb, &         ! na->nd
@@ -931,6 +941,17 @@
         if (prt_level >= 10) &
              PRINT *, 'cv3p1_closure-> plfc,wbeff ', plfc(1), wbeff(1)
-      END IF
-    END IF ! iflag_con.eq.3
+      END IF   ! iflag_clos==2
+
+      IF (iflag_clos==3) THEN
+        CALL cv3p2_closure(nloc, ncum, nd, icb, inb, &         ! na->nd
+                           pbase, plcl, p, ph, tv, tvp, buoy, &
+                           supmax, ok_inhib, Ale, Alp, omega, &
+                           sig, w0, ptop2, cape, cin, m, iflag, coef_clos, &
+                           Plim1, plim2, asupmax, supmax0, &
+                           asupmaxmin, cbmf, plfc, wbeff)
+        if (prt_level >= 10) &
+             PRINT *, 'cv3p2_closure-> plfc,wbeff ', plfc(1), wbeff(1)
+      END IF   ! iflag_clos==3
+    END IF ! iflag_con==3
 
     IF (iflag_con==4) THEN
@@ -971,6 +992,6 @@
       PRINT *, ' cv_mixing ->'
     END IF !(debut) THEN
-! do i = 1,klev
-! print*,'cv_mixing-> i,ment ',i,(ment(1,i,j),j=1,klev)
+! do i = 1,nd
+! print*,'cv_mixing-> i,ment ',i,(ment(1,i,j),j=1,nd)
 ! enddo
 
@@ -991,5 +1012,20 @@
                      faci, b, sigd, &
                      wdtrainA, wdtrainM)                                       ! RomP
-    END IF
+!
+      IF (prt_level >= 10) THEN
+        Print *, 'cva_driver after cv3_unsat:mp , water, ice, evap, fondue '
+        DO k = 1,nd
+        write (6, '(i4,5(1x,e13.6))'), &
+          k, mp(idcum(igout),k), water(idcum(igout),k), ice(idcum(igout),k), &
+           evap(idcum(igout),k), fondue(idcum(igout),k)
+        ENDDO
+        Print *, 'cva_driver after cv3_unsat: wdtrainA, wdtrainM '
+        DO k = 1,nd
+        write (6, '(i4,2(1x,e13.6))'), &
+           k, wdtrainA(idcum(igout),k), wdtrainM(idcum(igout),k)
+        ENDDO
+      ENDIF
+!
+    END IF  !(iflag_con==3)
 
     IF (iflag_con==4) THEN
@@ -1022,14 +1058,22 @@
                      nent, elij, traent, sig, &
                      tv, tvp, wghti, &
-                     iflag, precip, vprecip, ft, fq, fu, fv, ftra, &
+                     iflag, precip, Vprecip, Vprecipi, ft, fq, fu, fv, ftra, &      ! jyg
                      cbmf, upwd, dnwd, dnwd0, ma, mip, &
 !!                     tls, tps, &                            ! useless . jyg
                      qcondc, wd, &
                      ftd, fqd, qnk, qtc, sigt, tau_cld_cv, coefw_cld_cv)
-    END IF
-
-    IF (debut) THEN
-      PRINT *, ' cv3_yield -> fqd(1) = ', fqd(1, 1)
-    END IF !(debut) THEN
+!
+      IF (debut) THEN
+        PRINT *, ' cv3_yield -> fqd(1) = ', fqd(idcum(igout), 1)
+      END IF !(debut) THEN
+!   
+      IF (prt_level >= 10) THEN
+        Print *, 'cva_driver after cv3_yield:ft(1) , ftd(1) ', &
+                    ft(idcum(igout),1), ftd(idcum(igout),1)
+        Print *, 'cva_driver after cv3_yield:fq(1) , fqd(1) ', &
+                    fq(idcum(igout),1), fqd(idcum(igout),1)
+      ENDIF
+!   
+    END IF
 
     IF (iflag_con==4) THEN
@@ -1071,5 +1115,5 @@
                            precip, cbmf, plcl, plfc, wbeff, sig, w0, ptop2, &
                            ft, fq, fu, fv, ftra, &
-                           sigd, ma, mip, vprecip, upwd, dnwd, dnwd0, &
+                           sigd, ma, mip, vprecip, vprecipi, upwd, dnwd, dnwd0, &
                            qcondc, wd, cape, cin, &
                            tvp, &
@@ -1084,5 +1128,5 @@
                            precip1, cbmf1, plcl1, plfc1, wbeff1, sig1, w01, ptop21, &
                            ft1, fq1, fu1, fv1, ftra1, &
-                           sigd1, ma1, mip1, vprecip1, upwd1, dnwd1, dnwd01, &
+                           sigd1, ma1, mip1, vprecip1, vprecipi1, upwd1, dnwd1, dnwd01, &
                            qcondc1, wd1, cape1, cin1, &
                            tvp1, &
Index: /LMDZ5/branches/testing/libf/phylmd/cvltr.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cvltr.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cvltr.F90	(revision 2408)
@@ -12,5 +12,5 @@
   USE IOIPSL 
   USE dimphy
-  USE infotrac, ONLY : nbtr,tname
+  USE infotrac_phy, ONLY : nbtr,tname
   IMPLICIT NONE 
 !=====================================================================
Index: /LMDZ5/branches/testing/libf/phylmd/cvltr_noscav.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cvltr_noscav.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cvltr_noscav.F90	(revision 2408)
@@ -4,5 +4,5 @@
 SUBROUTINE cvltr_noscav(it,pdtime,da, phi, mp,wght_cvfd,paprs,pplay,x,upd,dnd,dx)
   USE dimphy
-  USE infotrac, ONLY : nbtr
+  USE infotrac_phy, ONLY : nbtr
   IMPLICIT NONE 
 !=====================================================================
Index: /LMDZ5/branches/testing/libf/phylmd/cvltr_scav.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cvltr_scav.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cvltr_scav.F90	(revision 2408)
@@ -13,5 +13,5 @@
   USE IOIPSL 
   USE dimphy
-  USE infotrac, ONLY : nbtr,tname
+  USE infotrac_phy, ONLY : nbtr,tname
   IMPLICIT NONE 
   !=====================================================================
Index: /LMDZ5/branches/testing/libf/phylmd/cvltr_spl.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cvltr_spl.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cvltr_spl.F90	(revision 2408)
@@ -13,5 +13,5 @@
   USE IOIPSL 
   USE dimphy
-  USE infotrac, ONLY : nbtr,tname
+  USE infotrac_phy, ONLY : nbtr,tname
   IMPLICIT NONE 
 !=====================================================================
Index: /LMDZ5/branches/testing/libf/phylmd/cvltrorig.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/cvltrorig.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/cvltrorig.F90	(revision 2408)
@@ -4,5 +4,5 @@
 SUBROUTINE cvltrorig(it,pdtime,da, phi, mp,paprs,pplay,x,upd,dnd,dx)
   USE dimphy
-  USE infotrac, ONLY : nbtr
+  USE infotrac_phy, ONLY : nbtr
   IMPLICIT NONE 
 !=====================================================================
Index: /LMDZ5/branches/testing/libf/phylmd/diag_slp.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/diag_slp.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/diag_slp.F90	(revision 2408)
@@ -0,0 +1,45 @@
+SUBROUTINE diag_slp(nlon,t,pab,pal,pphis,tasfc,tastd,pmer)
+ USE dimphy
+ USE phys_output_write_mod
+ USE phys_output_ctrlout_mod
+ USE phys_local_var_mod
+ IMPLICIT NONE
+  !>======================================================================
+  !!
+  !! Auteur(s) I.Musat (LMD/CNRS) date: 20151106
+  !!
+  !! Objet: Calcul pression au niveau de la mer cf. Arpege-IFS 
+  !! ctstar: calcule la temperature de l'air a la surface (tasfc) et
+  !!                 la temperature de l'air standard a la surface (tastd)
+  !! pppmer: calcule la slp a partir de tasfc, tastd, de la pression a la surface (pab1)
+  !!                 et du geopotentiel de la surface
+  !!======================================================================
+  !! nlon--input-R-temperature au milieu de chaque couche (en K)
+  !! t--input-R-temperature au milieu de chaque couche (en K)
+  !! pab--input-R-pression pour chaque inter-couche (en Pa)
+  !! pal---input-R-pression pour le mileu de chaque couche (en Pa)
+  !! pphis---input-R-geopotentiel du sol (en m2/s2)
+  !! tasfc---output-R-temperature air au sol (en K)
+  !! tastd---output-R-temperature air 'standard' au sol (en K)
+  !! pmer---output-R-pression au niveau de la mer (en Pa)
+  !!======================================================================
+  INTEGER nlon
+  REAL t(nlon,klev)
+  REAL pab(nlon,klev+1)
+  REAL pal(nlon,klev)
+  REAL pphis(nlon)
+  REAL tasfc(nlon), tastd(nlon)
+  REAL pmer(nlon)
+!!!
+!!! calcul tasfc et tastd
+  tal1(:)=t(:,1)
+  pab2(:)=pab(:,2)
+  pal1(:)=pal(:,1)
+  CALL ctstar(nlon,1,nlon,tal1,pab2,pal1,pphis,tasfc,tastd)
+!!!
+!!! calcul slp
+  pab1(:)=pab(:,1)
+  CALL pppmer(nlon,1,nlon,pab1,pphis,tasfc,tastd,pmer)
+!
+  RETURN
+  END
Index: /LMDZ5/branches/testing/libf/phylmd/diagphy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/diagphy.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/diagphy.F90	(revision 2408)
@@ -50,6 +50,4 @@
   IMPLICIT NONE
 
-  include "dimensions.h"
-  ! cccc#include "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -209,6 +207,4 @@
   IMPLICIT NONE
 
-  include "dimensions.h"
-  ! ccccc#include "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/1DUTILS.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/1DUTILS.h	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/1DUTILS.h	(revision 2408)
@@ -1,4 +1,3 @@
 #include "conf_gcm.F90"
-#include "q_sat.F"
 
 !
@@ -15,4 +14,5 @@
       use ioipsl_getincom
 #endif
+      USE print_control_mod, ONLY: lunout
       IMPLICIT NONE
 !-----------------------------------------------------------------------
@@ -27,5 +27,4 @@
 #include "fcg_gcssold.h"
 #include "fcg_racmo.h"
-#include "iniprint.h"
 !
 !
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_decl_cases.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_decl_cases.h	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_decl_cases.h	(revision 2408)
@@ -51,5 +51,4 @@
         real dth_rico(llm)
         real dqh_rico(llm)
-        real du_age(llm),dv_age(llm)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 ! Declarations specifiques au cas TWPice
@@ -251,4 +250,5 @@
         real hu_mod_cas(llm),vu_mod_cas(llm),du_mod_cas(llm)
         real hv_mod_cas(llm),vv_mod_cas(llm),dv_mod_cas(llm)
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
+        integer day_ini_cas
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_interp_cases.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_interp_cases.h	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_interp_cases.h	(revision 2408)
@@ -1,2 +1,5 @@
+!
+! $Id$
+!
 !---------------------------------------------------------------------
 ! Interpolation forcing in time and onto model levels
@@ -610,15 +613,17 @@
 
 ! time interpolation:
-        CALL interp_case_time(daytime,day1,annee_ref                        &
-     &       ,year_ini_cas,day_ju_ini_cas,nt_cas,pdt_cas,nlev_cas       &
-     &       ,ts_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                 &
+        CALL interp_case_time(daytime,day1,annee_ref                                        &
+!    &       ,year_ini_cas,day_ju_ini_cas,nt_cas,pdt_cas,nlev_cas                           &
+     &       ,nt_cas,nlev_cas                                                               &
+     &       ,ts_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)
+     &       ,sens_prof_cas,ustar_prof_cas,uw_prof_cas,vw_prof_cas,q1_prof_cas,q2_prof_cas)
 
              ts_cur = ts_prof_cas 
@@ -746,4 +751,5 @@
         if (tend_rayo.eq.1) then
            dt_cooling(l) = dtrad_mod_cas(l)
+!          print *,'dt_cooling=',dt_cooling(l)
         else
            dt_cooling(l) = 0.0
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_read_forc_cases.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_read_forc_cases.h	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/1D_read_forc_cases.h	(revision 2408)
@@ -1,2 +1,5 @@
+!
+! $Id$
+!
 !----------------------------------------------------------------------
 ! forcing_les = .T. : Impose a constant cooling 
@@ -323,5 +326,5 @@
       write(*,*) 'SST initiale mxcalc: ',tsurf,mxcalc
       do l = 1, llm
-! Ligne du dessous à decommenter si on lit theta au lieu de temp
+! Ligne du dessous ?? decommenter si on lit theta au lieu de temp
 !      temp(l) = t_mod(l)*(play(l)/pzero)**rkappa 
        temp(l) = t_mod(l) 
@@ -407,5 +410,5 @@
      &         ,ht_mod,hq_mod,hu_mod,hv_mod,w_mod,omega_mod,mxcalc)
 
-! Pour tester les advections horizontales de T et Q, on met w_mod et omega_mod à zero (MPL 20131108)
+! Pour tester les advections horizontales de T et Q, on met w_mod et omega_mod ?? zero (MPL 20131108)
 !     w_mod(:,:)=0.
 !     omega_mod(:,:)=0.
@@ -421,5 +424,5 @@
       write(*,*) 'SST initiale mxcalc: ',tsurf,mxcalc
       do l = 1, llm
-! Ligne du dessous à decommenter si on lit theta au lieu de temp
+! Ligne du dessous ?? decommenter si on lit theta au lieu de temp
        temp(l) = th_mod(l)*(play(l)/pzero)**rkappa 
 !      temp(l) = t_mod(l) 
@@ -733,14 +736,17 @@
 !Time interpolation for initial conditions using TOGA interpolation routine
          write(*,*) 'AVT 1ere INTERPOLATION: day,day1 = ',daytime,day1   
-      CALL interp_case_time(day,day1,annee_ref                &
-     &         ,year_ini_cas,day_ju_ini_cas,nt_cas,pdt_cas,nlev_cas       &
-     &         ,ts_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                 &
-     &         ,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)
+      CALL interp_case_time(day,day1,annee_ref                                                              &
+!    &         ,year_ini_cas,day_ju_ini_cas,nt_cas,pdt_cas,nlev_cas                                         &
+     &         ,nt_cas,nlev_cas                                                                             &
+     &         ,ts_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)
 
 ! vertical interpolation using TOGA interpolation routine:
@@ -778,5 +784,15 @@
        d_u_adv(l) = (hv_mod_cas(l)+vv_mod_cas(l))
       enddo     
-       
+
+! In case fluxes are imposed
+       IF (ok_flux_surf) THEN
+       fsens=sens_prof_cas
+       flat=lat_prof_cas
+       ENDIF
+       IF (ok_prescr_ust) THEN
+       ust=ustar_prof_cas
+       print *,'ust=',ust
+       ENDIF
+
       endif !forcing_case
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/1Dconv.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/1Dconv.h	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/1Dconv.h	(revision 2408)
@@ -1,2 +1,5 @@
+!
+! $Id$
+!
         subroutine get_uvd(itap,dtime,file_forctl,file_fordat,                  &
      &       ht,hq,hw,hu,hv,hthturb,hqturb,                                     &
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/compar1d.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/compar1d.h	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/compar1d.h	(revision 2408)
@@ -0,0 +1,51 @@
+!
+! $Id: compar1d.h 2010-08-04 17:02:56Z lahellec $
+!
+      integer :: forcing_type
+      integer :: tend_u,tend_v,tend_w,tend_t,tend_q,tend_rayo
+      real :: nudge_u,nudge_v,nudge_w,nudge_t,nudge_q
+      integer :: iflag_nudge
+      real :: nat_surf
+      real :: tsurf
+      real :: rugos
+      real :: xqsol(1:2)
+      real :: qsurf
+      real :: psurf
+      real :: zsurf
+      real :: albedo
+
+      real :: time
+      real :: time_ini
+      real :: xlat 
+      real :: xlon 
+      real :: airefi
+      real :: wtsurf 
+      real :: wqsurf 
+      real :: restart_runoff 
+      real :: xagesno 
+      real :: qsolinp 
+      real :: zpicinp 
+
+      logical :: restart
+      logical :: ok_old_disvert
+
+      common/com_par1d/                                                 &
+     & nat_surf,tsurf,rugos,                                            &
+     & xqsol,qsurf,psurf,zsurf,albedo,time,time_ini,xlat,xlon,airefi,   &
+     & wtsurf,wqsurf,restart_runoff,xagesno,qsolinp,zpicinp,            &
+     & forcing_type,tend_u,tend_v,tend_w,tend_t,tend_q,tend_rayo,       &
+     & nudge_u,nudge_v,nudge_w,nudge_t,nudge_q,                         &
+     & iflag_nudge,                                                     &
+     & restart,ok_old_disvert
+
+!$OMP THREADPRIVATE(/com_par1d/)
+
+
+
+
+
+
+
+
+
+
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/date_cas.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/date_cas.h	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/date_cas.h	(revision 2408)
@@ -0,0 +1,9 @@
+      integer :: year_ini_cas    ! initial year of the case
+      integer :: mth_ini_cas     ! initial month of the case
+      integer :: day_deb         ! initial day of the case
+      real :: heure_ini_cas      ! start time of the case
+      real :: pdt_cas            ! forcing_frequency
+      real :: day_ju_ini_cas     ! julian day of initial day of the case
+
+      common /date_cas/year_ini_cas,mth_ini_cas,day_deb,heure_ini_cas,pdt_cas,day_ju_ini_cas
+
Index: DZ5/branches/testing/libf/phylmd/dyn1d/iniphysiq.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/iniphysiq.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../../dynlonlat_phylonlat/phylmd/iniphysiq.F90
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/iniphysiq_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/iniphysiq_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/iniphysiq_mod.F90	(revision 2408)
@@ -0,0 +1,1 @@
+link ../../dynlonlat_phylonlat/phylmd/iniphysiq_mod.F90
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/lmdz1d.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/lmdz1d.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/lmdz1d.F90	(revision 2408)
@@ -8,18 +8,32 @@
       PROGRAM lmdz1d
 
-      USE ioipsl, only: ju2ymds, ymds2ju, ioconf_calendar
-      use phys_state_var_mod
-      use dimphy
-      use surface_data, only : type_ocean,ok_veget
-      use pbl_surface_mod, only : ftsoil, pbl_surface_init,                     &
+   USE ioipsl, only: ju2ymds, ymds2ju, ioconf_calendar
+   USE phys_state_var_mod, ONLY : phys_state_var_init, phys_state_var_end, &
+       clwcon, detr_therm, &
+       qsol, fevap, z0m, z0h, agesno, &
+       du_gwd_rando, du_gwd_front, entr_therm, f0, fm_therm, &
+       falb_dir, falb_dif, &
+       ftsol, pbl_tke, pctsrf, radsol, rain_fall, snow_fall, ratqs, &
+       rlat, rlon, rnebcon, rugoro, sig1, w01, solaire_etat0, sollw, sollwdown, &
+       solsw, t_ancien, q_ancien, u_ancien, v_ancien, wake_cstar, wake_deltaq, &
+       wake_deltat, wake_delta_pbl_TKE, delta_tsurf, wake_fip, wake_pe, &
+       wake_s, zgam, &
+       zmax0, zmea, zpic, zsig, &
+       zstd, zthe, zval, ale_bl, ale_bl_trig, alp_bl
+   use dimphy
+   use surface_data, only : type_ocean,ok_veget
+   use pbl_surface_mod, only : ftsoil, pbl_surface_init,                     &
      &                            pbl_surface_final
       use fonte_neige_mod, only : fonte_neige_init, fonte_neige_final 
 
-      use infotrac ! new
-      use control_mod
-      USE indice_sol_mod
-      USE phyaqua_mod
-      USE mod_1D_cases_read
-      USE mod_1D_amma_read
+   use infotrac ! new
+   use control_mod
+   USE indice_sol_mod
+   USE phyaqua_mod
+   USE mod_1D_cases_read
+   USE mod_1D_amma_read
+   USE print_control_mod, ONLY: prt_level
+   USE iniphysiq_mod, ONLY: iniphysiq
+   USE mod_const_mpi, ONLY: comm_lmdz
 
       implicit none
@@ -28,5 +42,4 @@
 #include "temps.h"
 !!#include "control.h"
-#include "iniprint.h"
 #include "clesphys.h"
 #include "dimsoil.h"
@@ -36,4 +49,5 @@
 #include "compar1d.h"
 #include "flux_arp.h"
+#include "date_cas.h"
 #include "tsoilnudge.h"
 #include "fcg_gcssold.h"
@@ -124,5 +138,5 @@
 !vertical advection computation
 !       real d_t_z(llm), d_q_z(llm)
-!       real d_t_dyn_z(llm), d_q_dyn_z(llm)
+!       real d_t_dyn_z(llm), dq_dyn_z(llm)
 !       real zz(llm)
 !       real zfact
@@ -164,4 +178,5 @@
       real :: phi(llm)
       real :: teta(llm),tetal(llm),temp(llm),u(llm),v(llm),w(llm)
+      REAL rot(1, llm) ! relative vorticity, in s-1
       real :: rlat_rad(1),rlon_rad(1)
       real :: omega(llm+1),omega2(llm),rho(llm+1)
@@ -173,4 +188,5 @@
       real :: d_u_nudge(llm),d_v_nudge(llm)
       real :: du_adv(llm),dv_adv(llm)
+      real :: du_age(llm),dv_age(llm)
       real :: alpha
       real :: ttt
@@ -237,4 +253,18 @@
 ! INITIALIZATIONS 
 !=====================================================================
+      du_phys(:)=0.
+      dv_phys(:)=0.
+      dt_phys(:)=0.
+      dt_dyn(:)=0.
+      dt_cooling(:)=0.
+      d_th_adv(:)=0.
+      d_t_nudge(:)=0.
+      d_u_nudge(:)=0.
+      d_v_nudge(:)=0.
+      du_adv(:)=0.
+      dv_adv(:)=0.
+      du_age(:)=0.
+      dv_age(:)=0.
+      
 ! Initialization of Common turb_forcing
        dtime_frcg = 0.
@@ -284,7 +314,9 @@
 !             Different stages: soil model alone, atm. model alone
 !             then both models coupled
-!forcing_type = 10 ==> forcing_case = .true.
+!forcing_type >= 100 ==> forcing_case = .true.
 !             initial profiles and large scale forcings in cas.nc
 !             LS convergence, omega and SST imposed from CINDY-DYNAMO files 
+!             101=cindynamo
+!             102=bomex
 !forcing_type = 40 ==> forcing_GCSSold = .true.
 !             initial profile from GCSS file
@@ -323,6 +355,18 @@
       elseif (forcing_type .eq.7) THEN
        forcing_dice = .true.
-      elseif (forcing_type .eq.10) THEN
+      elseif (forcing_type .eq.101) THEN ! Cindynamo starts 1-10-2011 0h
        forcing_case = .true.
+       year_ini_cas=2011
+       mth_ini_cas=10
+       day_deb=1
+       heure_ini_cas=0.
+       pdt_cas=3*3600.         ! forcing frequency
+      elseif (forcing_type .eq.102) THEN ! Bomex starts 24-6-1969 0h
+       forcing_case = .true.
+       year_ini_cas=1969
+       mth_ini_cas=6
+       day_deb=24
+       heure_ini_cas=0.
+       pdt_cas=1800.         ! forcing frequency
       elseif (forcing_type .eq.40) THEN
        forcing_GCSSold = .true.
@@ -396,4 +440,5 @@
          fnday=-nday/float(day_step)
       endif
+      print *,'fnday=',fnday
 
 ! Special case for arm_cu which lasts less than one day : 53100s !! (MPL 20111026)
@@ -432,11 +477,12 @@
      & (year_ini_dice,mth_ini_dice,day_ini_dice,heure_ini_dice             & 
      & ,day_ju_ini_dice)
-      ELSEIF (forcing_type .eq.10) THEN
+      ELSEIF (forcing_type .gt.100) THEN
 ! Convert the initial date to Julian day
-      print*,'time cindy',year_ini_cas,mth_ini_cas,day_ini_cas
+      day_ini_cas=day_deb
+      print*,'time case',year_ini_cas,mth_ini_cas,day_ini_cas
       call ymds2ju                                                         &
-     & (year_ini_cas,mth_ini_cas,day_ini_cas,heure_ini_cas &
+     & (year_ini_cas,mth_ini_cas,day_ini_cas,heure_ini_cas              &
      & ,day_ju_ini_cas)
-      print*,'time cindy 2',day_ju_ini_cas
+      print*,'time case 2',day_ini_cas,day_ju_ini_cas
       ELSEIF (forcing_type .eq.59) THEN
 ! Convert the initial date of Sandu case to Julian day
@@ -467,5 +513,7 @@
 ! Initialization of dimensions, geometry and initial state
 !---------------------------------------------------------------------
-      call init_phys_lmdz(1,1,llm,1,(/1/))
+!      call init_phys_lmdz(1,1,llm,1,(/1/)) ! job now done via iniphysiq
+!     but we still need to initialize dimphy module (klon,klev,etc.)  here.
+      call init_dimphy(1,llm)
       call suphel
       call infotrac_init 
@@ -478,4 +526,10 @@
       allocate(d_q_nudge(llm,nqtot)) 
 !      allocate(d_th_adv(llm)) 
+
+      q(:,:) = 0.
+      dq(:,:) = 0.
+      dq_dyn(:,:) = 0.
+      d_q_adv(:,:) = 0.
+      d_q_nudge(:,:) = 0.
 
 !
@@ -540,8 +594,9 @@
 !       Dans ce cas, on lit ap,bp dans le fichier hybrid.txt
       ENDIF
+      ! initialize ap,bp, etc. in vertical_layers_mod
       sig_s=presnivs/preff
       plev =ap+bp*psurf
       play = 0.5*(plev(1:llm)+plev(2:llm+1))
-!cc      zlay=-rd*300.*log(play/psurf)/rg ! moved after reading profiles
+      zlay=-rd*300.*log(play/psurf)/rg ! moved after reading profiles
 
       IF (forcing_type .eq. 59) THEN
@@ -572,8 +627,8 @@
 
       print*,'mxcalc=',mxcalc
-      print*,'zlay=',zlay(mxcalc)
+!     print*,'zlay=',zlay(mxcalc)
       print*,'play=',play(mxcalc)
 
-!Al1 pour SST forced, appellé depuis ocean_forced_noice
+!Al1 pour SST forced, appell?? depuis ocean_forced_noice
       ts_cur = tsurf ! SST used in read_tsurf1d
 !=====================================================================
@@ -600,9 +655,19 @@
       zcvfi=airefi
 !
-      rlat_rad(:)=rlat(:)*rpi/180.
-      rlon_rad(:)=rlon(:)*rpi/180.
-
-      call iniphysiq(iim,jjm,llm,rday,day_ini,timestep,                        &
-     &     rlat_rad,rlon_rad,airefi,zcufi,zcvfi,ra,rg,rd,rcpd,(/1/))
+      rlat_rad(1)=rlat(1)*rpi/180.
+      rlon_rad(1)=rlon(1)*rpi/180.
+
+     ! Ehouarn: iniphysiq requires arrays related to (3D) dynamics grid,
+     ! e.g. for cell boundaries, which are meaningless in 1D; so pad these 
+     ! with '0.' when necessary
+      call iniphysiq(iim,jjm,llm, &
+           1,comm_lmdz, &
+           rday,day_ini,timestep,  &
+           (/rlat_rad(1),0./),(/0./), &
+           (/0.,0./),(/rlon_rad(1),0./),  &
+           (/ (/airefi,0./),(/0.,0./) /), &
+           (/zcufi,0.,0.,0./), &
+           (/zcvfi,0./), &
+           ra,rg,rd,rcpd,1)
       print*,'apres iniphysiq'
 
@@ -682,8 +747,10 @@
         solsw=0.
         sollw=0.
+        sollwdown=rsigma*tsurf**4
         radsol=0.
         rnebcon=0.
         ratqs=0.
         clwcon=0.
+        zmax0 = 0.
         zmea=0.
         zstd=0.
@@ -694,4 +761,21 @@
         sig1=0.
         w01=0.
+        wake_cstar = 0.
+        wake_deltaq = 0.
+        wake_deltat = 0.
+        wake_delta_pbl_TKE = 0.
+        delta_tsurf = 0.
+        wake_fip = 0.
+        wake_pe = 0.
+        wake_s = 0.
+        ale_bl = 0.
+        ale_bl_trig = 0.
+        alp_bl = 0.
+        IF (ALLOCATED(du_gwd_rando)) du_gwd_rando = 0.
+        IF (ALLOCATED(du_gwd_front)) du_gwd_front = 0.
+        entr_therm = 0.
+        detr_therm = 0.
+        f0 = 0.
+        fm_therm = 0.
         u_ancien(1,:)=u(:)
         v_ancien(1,:)=v(:)
@@ -704,5 +788,5 @@
 ! pctsrf(:,is_sic),ftsol(:,nsrf),tsoil(:,isoil,nsrf),qsurf(:,nsrf)
 ! qsol,falb_dir(:,nsrf),falb_dif(:,nsrf),evap(:,nsrf),snow(:,nsrf)
-! radsol,solsw,sollw,fder,rain_fall,snow_fall,frugs(:,nsrf)
+! radsol,solsw,sollw, sollwdown,fder,rain_fall,snow_fall,frugs(:,nsrf)
 ! agesno(:,nsrf),zmea,zstd,zsig,zgam,zthe,zpic,zval,rugoro
 ! t_ancien,q_ancien,,frugs(:,is_oce),clwcon(:,1),rnebcon(:,1),ratqs(:,1)
@@ -805,5 +889,5 @@
        if (prt_level.ge.1) then
          print*,'XXXXXXXXXXXXXXXXXXX ITAP,day,time=',                       &
-     &                                it,day,time,nint(fnday*day_step)
+     &             it,day,time,nint(fnday*day_step),day_step
          print*,'PAS DE TEMPS ',timestep
        endif
@@ -853,11 +937,10 @@
 !---------------------------------------------------------------------
 
-        call physiq(ngrid,llm,                                              &
-     &              firstcall,lastcall,                                     &
-     &              day,time,timestep,                                      &
-     &              plev,play,phi,phis,presnivs,                            &
-     &              u,v,temp,q,omega2,                                      &
-     &              du_phys,dv_phys,dt_phys,dq,dpsrf,                        &
-     &              dudyn)
+       call physiq(ngrid,llm, &
+            firstcall,lastcall, day,time,timestep, &
+            plev,play,phi,phis,presnivs, &
+            u,v, rot, temp,q,omega2, &
+            du_phys,dv_phys,dt_phys,dq,dpsrf, &
+            dudyn)
         firstcall=.false.
 
@@ -892,4 +975,5 @@
          d_q_adv=0.0
        endif
+!      print*, 'calcul de fcoriolis ', fcoriolis
 
        if (forcing_toga .or. forcing_GCSSold .or. forcing_twpice            &
@@ -901,8 +985,10 @@
         endif
 
-      print*, 'fcoriolis ', fcoriolis, xlat
-
-        du_age(1:mxcalc)=fcoriolis*(v(1:mxcalc)-vg(1:mxcalc))
+      IF (prt_level >= 1) print*, 'fcoriolis, xlat,mxcalc ', &
+                                   fcoriolis, xlat,mxcalc
+
+       du_age(1:mxcalc)=fcoriolis*(v(1:mxcalc)-vg(1:mxcalc))
        dv_age(1:mxcalc)=-fcoriolis*(u(1:mxcalc)-ug(1:mxcalc))
+!       print *,'u-ug=',u-ug
 
 !!!!!!!!!!!!!!!!!!!!!!!!
@@ -911,4 +997,5 @@
        sfdt = sin(0.5*fcoriolis*timestep)
        cfdt = cos(0.5*fcoriolis*timestep)
+!       print *,'fcoriolis,sfdt,cfdt,timestep',fcoriolis,sfdt,cfdt,timestep
 !
         du_age(1:mxcalc)= -2.*sfdt/timestep*                                &
@@ -970,5 +1057,8 @@
      &    'physiq-> temp(1),dt_phys(1),d_th_adv(1),dt_cooling(1) ',         &
      &              temp(1),dt_phys(1),d_th_adv(1),dt_cooling(1)
-           print*,du_phys
+           print* ,'dv_phys=',dv_phys
+           print* ,'dv_age=',dv_age
+           print* ,'dv_adv=',dv_adv
+           print* ,'d_v_nudge=',d_v_nudge
            print*, v
            print*, vg
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_1D_amma_read.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_1D_amma_read.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_1D_amma_read.F90	(revision 2408)
@@ -0,0 +1,504 @@
+MODULE mod_1D_amma_read
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!Declarations specifiques au cas AMMA
+        character*80 :: fich_amma
+! Option du cas AMMA ou on impose la discretisation verticale (Ap,Bp)
+        integer nlev_amma, nt_amma
+
+
+        integer year_ini_amma, day_ini_amma, mth_ini_amma
+        real heure_ini_amma
+        real day_ju_ini_amma   ! Julian day of amma first day
+        parameter (year_ini_amma=2006)
+        parameter (mth_ini_amma=7)
+        parameter (day_ini_amma=10)  ! 10 = 10Juil2006
+        parameter (heure_ini_amma=0.) !0h en secondes
+        real dt_amma
+        parameter (dt_amma=1800.)
+
+!profils initiaux:
+        real, allocatable::  plev_amma(:)
+
+        real, allocatable::  z_amma(:)
+        real, allocatable::  th_amma(:),q_amma(:)
+        real, allocatable::  u_amma(:)
+        real, allocatable::  v_amma(:)
+
+        real, allocatable::  th_ammai(:),q_ammai(:)
+        real, allocatable::  u_ammai(:)
+        real, allocatable::  v_ammai(:)
+        real, allocatable::  vitw_ammai(:)
+        real, allocatable::  ht_ammai(:)
+        real, allocatable::  hq_ammai(:)
+        real, allocatable::  vt_ammai(:)
+        real, allocatable::  vq_ammai(:)
+
+!forcings
+        real, allocatable::  ht_amma(:,:)
+        real, allocatable::  hq_amma(:,:)
+        real, allocatable::  vitw_amma(:,:)
+        real, allocatable::  lat_amma(:),sens_amma(:)
+
+!champs interpoles
+        real, allocatable::  vitw_profamma(:)
+        real, allocatable::  ht_profamma(:)
+        real, allocatable::  hq_profamma(:)
+        real lat_profamma,sens_profamma
+        real, allocatable::  vt_profamma(:)
+        real, allocatable::  vq_profamma(:)
+        real, allocatable::  th_profamma(:)
+        real, allocatable::  q_profamma(:)
+        real, allocatable::  u_profamma(:)
+        real, allocatable::  v_profamma(:)
+
+
+CONTAINS
+
+SUBROUTINE read_1D_cases
+      implicit none
+
+#include "netcdf.inc"
+
+      INTEGER nid,rid,ierr
+
+      fich_amma='amma.nc'
+      print*,'fich_amma ',fich_amma
+      ierr = NF_OPEN(fich_amma,NF_NOWRITE,nid)
+      print*,'fich_amma,NF_NOWRITE,nid ',fich_amma,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,'lev',rid)
+      IF (ierr.NE.NF_NOERR) THEN
+         print*, 'Oh probleme lecture dimension zz'
+      ENDIF
+      ierr=NF_INQ_DIMLEN(nid,rid,nlev_amma)
+      print*,'OK nid,rid,nlev_amma',nid,rid,nlev_amma
+!.......................................................................
+      ierr=NF_INQ_DIMID(nid,'time',rid)
+      print*,'nid,rid',nid,rid
+      nt_amma=0
+      IF (ierr.NE.NF_NOERR) THEN
+        stop 'probleme lecture dimension sens'
+      ENDIF
+      ierr=NF_INQ_DIMLEN(nid,rid,nt_amma)
+      print*,'nid,rid,nlev_amma',nid,rid,nt_amma
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!profils initiaux:
+        allocate(plev_amma(nlev_amma))
+        
+        allocate(z_amma(nlev_amma))
+        allocate(th_amma(nlev_amma),q_amma(nlev_amma))
+        allocate(u_amma(nlev_amma))
+        allocate(v_amma(nlev_amma))
+
+!forcings
+        allocate(ht_amma(nlev_amma,nt_amma))
+        allocate(hq_amma(nlev_amma,nt_amma))
+        allocate(vitw_amma(nlev_amma,nt_amma))
+        allocate(lat_amma(nt_amma),sens_amma(nt_amma))
+
+!profils initiaux:
+        allocate(th_ammai(nlev_amma),q_ammai(nlev_amma))
+        allocate(u_ammai(nlev_amma))
+        allocate(v_ammai(nlev_amma))
+        allocate(vitw_ammai(nlev_amma) )
+        allocate(ht_ammai(nlev_amma))
+        allocate(hq_ammai(nlev_amma))
+        allocate(vt_ammai(nlev_amma))
+        allocate(vq_ammai(nlev_amma))
+
+!champs interpoles
+        allocate(vitw_profamma(nlev_amma))
+        allocate(ht_profamma(nlev_amma))
+        allocate(hq_profamma(nlev_amma))
+        allocate(vt_profamma(nlev_amma))
+        allocate(vq_profamma(nlev_amma))
+        allocate(th_profamma(nlev_amma))
+        allocate(q_profamma(nlev_amma))
+        allocate(u_profamma(nlev_amma))
+        allocate(v_profamma(nlev_amma))
+
+        print*,'Allocations OK'
+        call read_amma(nid,nlev_amma,nt_amma                                  &
+     &     ,z_amma,plev_amma,th_amma,q_amma,u_amma,v_amma,vitw_amma         &
+     &     ,ht_amma,hq_amma,sens_amma,lat_amma)
+
+END SUBROUTINE read_1D_cases
+
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+SUBROUTINE deallocate_1D_cases
+!profils initiaux:
+        deallocate(plev_amma)
+        
+        deallocate(z_amma)
+        deallocate(th_amma,q_amma)
+        deallocate(u_amma)
+        deallocate(v_amma)
+
+        deallocate(th_ammai,q_ammai)
+        deallocate(u_ammai)
+        deallocate(v_ammai)
+        deallocate(vitw_ammai )
+        deallocate(ht_ammai)
+        deallocate(hq_ammai)
+        deallocate(vt_ammai)
+        deallocate(vq_ammai)
+        
+!forcings
+        deallocate(ht_amma)
+        deallocate(hq_amma)
+        deallocate(vitw_amma)
+        deallocate(lat_amma,sens_amma)
+
+!champs interpoles
+        deallocate(vitw_profamma)
+        deallocate(ht_profamma)
+        deallocate(hq_profamma)
+        deallocate(vt_profamma)
+        deallocate(vq_profamma)
+        deallocate(th_profamma)
+        deallocate(q_profamma)
+        deallocate(u_profamma)
+        deallocate(v_profamma)
+END SUBROUTINE deallocate_1D_cases
+
+
+END MODULE mod_1D_amma_read
+!=====================================================================
+      subroutine read_amma(nid,nlevel,ntime                          &
+     &     ,zz,pp,temp,qv,u,v,dw                   &
+     &     ,dt,dq,sens,flat)
+
+!program reading forcings of the AMMA case study
+      implicit none
+#include "netcdf.inc"
+
+      integer ntime,nlevel
+
+      real zz(nlevel)
+      real temp(nlevel),pp(nlevel)
+      real qv(nlevel),u(nlevel)
+      real v(nlevel)
+      real dw(nlevel,ntime)
+      real dt(nlevel,ntime)
+      real dq(nlevel,ntime)
+      real flat(ntime),sens(ntime)
+
+
+      integer nid, ierr,rid
+      integer nbvar3d
+      parameter(nbvar3d=30)
+      integer var3didin(nbvar3d)
+
+       ierr=NF_INQ_VARID(nid,"zz",var3didin(1)) 
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'lev'
+         endif
+
+
+      ierr=NF_INQ_VARID(nid,"temp",var3didin(2))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'temp'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"qv",var3didin(3))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'qv'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"u",var3didin(4))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'u'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"v",var3didin(5))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'v'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"dw",var3didin(6))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'dw'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"dt",var3didin(7))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'dt'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"dq",var3didin(8))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'dq'
+         endif
+      
+      ierr=NF_INQ_VARID(nid,"sens",var3didin(9))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'sens'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"flat",var3didin(10))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'flat'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"pp",var3didin(11))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+      endif
+
+!dimensions lecture
+!      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
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture z ok',zz
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(2),temp)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(2),temp)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture th ok',temp
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(3),qv)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(3),qv)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture qv ok',qv
+ 
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(4),u)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(4),u)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          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
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture v ok',v
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(6),dw)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(6),dw)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture w ok',dw
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(7),dt)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(7),dt)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dt ok',dt
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(8),dq)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(8),dq)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dq ok',dq
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(9),sens)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(9),sens)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture sens ok',sens
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(10),flat)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(10),flat)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture flat ok',flat
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(11),pp)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(11),pp)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture pp ok',pp
+
+         return 
+         end subroutine read_amma
+!======================================================================
+        SUBROUTINE interp_amma_time(day,day1,annee_ref                     &
+     &         ,year_ini_amma,day_ini_amma,nt_amma,dt_amma,nlev_amma       &
+     &         ,vitw_amma,ht_amma,hq_amma,lat_amma,sens_amma               &
+     &         ,vitw_prof,ht_prof,hq_prof,lat_prof,sens_prof)
+        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_amma: total nb of data in the forcing (e.g. 48 for AMMA)
+! dt_amma: total time interval (in sec) between 2 forcing data (e.g. 30min for AMMA)
+!---------------------------------------------------------------------------------------
+
+#include "compar1d.h"
+
+! inputs:
+        integer annee_ref
+        integer nt_amma,nlev_amma
+        integer year_ini_amma
+        real day, day1,day_ini_amma,dt_amma
+        real vitw_amma(nlev_amma,nt_amma)
+        real ht_amma(nlev_amma,nt_amma)
+        real hq_amma(nlev_amma,nt_amma)
+        real lat_amma(nt_amma)
+        real sens_amma(nt_amma)
+! outputs:
+        real vitw_prof(nlev_amma)
+        real ht_prof(nlev_amma)
+        real hq_prof(nlev_amma)
+        real lat_prof,sens_prof
+! local:
+        integer it_amma1, it_amma2,k
+        real timeit,time_amma1,time_amma2,frac
+
+
+        if (forcing_type.eq.6) 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_ini_amma) then
+        print*,'AMMA a débuté le 10 juillet 2006',day1,day_ini_amma
+        print*,'Changer dayref dans run.def'
+        stop
+       endif
+       if (annee_ref.eq.2006 .and. day1.gt.day_ini_amma+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 of AMMA:
+!       timeit=(day-day1)*86400.
+!       if (annee_ref.eq.1992) then
+!        timeit=(day-day_ini_toga)*86400.
+!       else
+!        timeit=(day+61.-1.)*86400. ! 61 days between Nov01 and Dec31 1992
+!       endif
+      timeit=(day-day_ini_amma)*86400
+
+! Determine the closest observation times:
+!       it_amma1=INT(timeit/dt_amma)+1
+!       it_amma2=it_amma1 + 1
+!       time_amma1=(it_amma1-1)*dt_amma
+!       time_amma2=(it_amma2-1)*dt_amma
+
+       it_amma1=INT(timeit/dt_amma)+1
+       IF (it_amma1 .EQ. nt_amma) THEN
+       it_amma2=it_amma1 
+       ELSE
+       it_amma2=it_amma1 + 1
+       ENDIF
+       time_amma1=(it_amma1-1)*dt_amma
+       time_amma2=(it_amma2-1)*dt_amma
+
+       if (it_amma1 .gt. nt_amma) then
+        write(*,*) 'PB-stop: day, it_amma1, it_amma2, timeit: '            &
+     &        ,day,day_ini_amma,it_amma1,it_amma2,timeit/86400.
+        stop
+       endif
+
+! time interpolation:
+       IF (it_amma1 .EQ. it_amma2) THEN
+          frac=0.
+       ELSE 
+          frac=(time_amma2-timeit)/(time_amma2-time_amma1)
+          frac=max(frac,0.0)
+       ENDIF
+
+       lat_prof = lat_amma(it_amma2)                                       &
+     &          -frac*(lat_amma(it_amma2)-lat_amma(it_amma1)) 
+       sens_prof = sens_amma(it_amma2)                                     &
+     &          -frac*(sens_amma(it_amma2)-sens_amma(it_amma1))
+
+       do k=1,nlev_amma
+        vitw_prof(k) = vitw_amma(k,it_amma2)                               &
+     &          -frac*(vitw_amma(k,it_amma2)-vitw_amma(k,it_amma1))
+        ht_prof(k) = ht_amma(k,it_amma2)                                   &
+     &          -frac*(ht_amma(k,it_amma2)-ht_amma(k,it_amma1))
+        hq_prof(k) = hq_amma(k,it_amma2)                                   &
+     &          -frac*(hq_amma(k,it_amma2)-hq_amma(k,it_amma1))
+        enddo
+
+        return
+        END
+
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_1D_cases_read.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_1D_cases_read.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_1D_cases_read.F90	(revision 2408)
@@ -0,0 +1,1174 @@
+!
+! $Id$
+!
+MODULE mod_1D_cases_read
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!Declarations specifiques au cas standard
+        character*80 :: fich_cas
+! Discr?tisation 
+        integer nlev_cas, nt_cas
+
+
+!       integer year_ini_cas, day_ini_cas, mth_ini_cas
+!       real heure_ini_cas
+!       real day_ju_ini_cas   ! Julian day of case first day
+!       parameter (year_ini_cas=2011)
+!       parameter (year_ini_cas=1969)
+!       parameter (mth_ini_cas=10)
+!       parameter (mth_ini_cas=6)
+!       parameter (day_ini_cas=1)  ! 10 = 10Juil2006
+!       parameter (day_ini_cas=24)  ! 24 = 24 juin 1969
+!       parameter (heure_ini_cas=0.) !0h en secondes
+!       real pdt_cas
+!       parameter (pdt_cas=3.*3600)
+
+!CR ATTENTION TEST AMMA
+!        parameter (year_ini_cas=2006)
+!        parameter (mth_ini_cas=7)
+!        parameter (day_ini_cas=10)  ! 10 = 10Juil2006
+!        parameter (heure_ini_cas=0.) !0h en secondes
+!        parameter (pdt_cas=1800.)
+
+!profils environnementaux
+        real, allocatable::  plev_cas(:,:)
+
+        real, allocatable::  z_cas(:,:)
+        real, allocatable::  t_cas(:,:),q_cas(:,:),rh_cas(:,:)
+        real, allocatable::  th_cas(:,:),rv_cas(:,:)
+        real, allocatable::  u_cas(:,:)
+        real, allocatable::  v_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::  vitw_cas(:,:)
+        real, allocatable::  ug_cas(:,:),vg_cas(:,:)
+        real, allocatable::  lat_cas(:),sens_cas(:),ts_cas(:),ustar_cas(:)
+        real, allocatable::  uw_cas(:,:),vw_cas(:,:),q1_cas(:,:),q2_cas(:,:)
+
+!champs interpoles
+        real, allocatable::  plev_prof_cas(:)
+        real, allocatable::  t_prof_cas(:)
+        real, allocatable::  q_prof_cas(:)
+        real, allocatable::  u_prof_cas(:)
+        real, allocatable::  v_prof_cas(:)        
+
+        real, allocatable::  vitw_prof_cas(:)
+        real, allocatable::  ug_prof_cas(:)
+        real, allocatable::  vg_prof_cas(:)
+        real, allocatable::  ht_prof_cas(:)
+        real, allocatable::  hq_prof_cas(:)
+        real, allocatable::  vt_prof_cas(:)
+        real, allocatable::  vq_prof_cas(:)
+        real, allocatable::  dt_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,ustar_prof_cas
+      
+
+
+CONTAINS
+
+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
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!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),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_cas(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 deallocate_1D_cases
+!profils environnementaux:
+        deallocate(plev_cas)
+        
+        deallocate(z_cas)
+        deallocate(t_cas,q_cas,rh_cas)
+        deallocate(th_cas,rv_cas)
+        deallocate(u_cas)
+        deallocate(v_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(vitw_cas)
+        deallocate(ug_cas)
+        deallocate(vg_cas)
+        deallocate(lat_cas,sens_cas,ts_cas,ustar_cas,uw_cas,vw_cas,q1_cas,q2_cas)
+
+!champs interpoles
+        deallocate(plev_prof_cas)
+        deallocate(t_prof_cas)
+        deallocate(q_prof_cas)
+        deallocate(u_prof_cas)
+        deallocate(v_prof_cas)
+
+        deallocate(vitw_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(q_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 deallocate_1D_cases
+
+
+END MODULE mod_1D_cases_read
+!=====================================================================
+      subroutine read_cas(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
+#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)
+
+
+      integer nid, ierr,rid
+      integer nbvar3d
+      parameter(nbvar3d=39)
+      integer var3didin(nbvar3d)
+
+       ierr=NF_INQ_VARID(nid,"zz",var3didin(1)) 
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'lev'
+         endif
+      
+      ierr=NF_INQ_VARID(nid,"pp",var3didin(2)) 
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'plev'
+         endif
+
+
+      ierr=NF_INQ_VARID(nid,"temp",var3didin(3))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'temp'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"qv",var3didin(4))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'qv'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"rh",var3didin(5))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'rh'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"theta",var3didin(6))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'theta'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"rv",var3didin(7))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'rv'
+         endif
+
+
+      ierr=NF_INQ_VARID(nid,"u",var3didin(8))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'u'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"v",var3didin(9))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'v'
+         endif
+
+       ierr=NF_INQ_VARID(nid,"ug",var3didin(10))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'ug'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"vg",var3didin(11))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'vg'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"w",var3didin(12))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'w'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"advu",var3didin(13))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'advu'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"hu",var3didin(14))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'hu'
+         endif
+
+       ierr=NF_INQ_VARID(nid,"vu",var3didin(15))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'vu'
+         endif
+
+       ierr=NF_INQ_VARID(nid,"advv",var3didin(16))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'advv'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"hv",var3didin(17))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'hv'
+         endif
+
+       ierr=NF_INQ_VARID(nid,"vv",var3didin(18))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'vv'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"advT",var3didin(19))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'advT'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"hT",var3didin(20))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'hT'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"vT",var3didin(21))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'vT'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"advq",var3didin(22))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'advq'
+         endif
+      
+      ierr=NF_INQ_VARID(nid,"hq",var3didin(23))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'hq'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"vq",var3didin(24))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'vq'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"advth",var3didin(25))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'advth'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"hth",var3didin(26))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'hth'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"vth",var3didin(27))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'vth'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"advr",var3didin(28))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'advr'
+         endif
+      
+      ierr=NF_INQ_VARID(nid,"hr",var3didin(29))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'hr'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"vr",var3didin(30))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'vr'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"radT",var3didin(31))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'radT'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"sens",var3didin(32))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'sens'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"flat",var3didin(33))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'flat'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"ts",var3didin(34))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'ts'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"ustar",var3didin(35))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'ustar'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"uw",var3didin(36))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'uw'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"vw",var3didin(37))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'vw'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"q1",var3didin(38))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'q1'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"q2",var3didin(39))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'q2'
+         endif
+ 
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(1),zz)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(1),zz)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture z ok',zz
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(2),pp)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(2),pp)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture pp ok',pp
+
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(3),temp)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(3),temp)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture T ok',temp
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(4),qv)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(4),qv)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture qv ok',qv
+ 
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(5),rh)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(5),rh)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture rh ok',rh
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(6),theta)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(6),theta)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture theta ok',theta
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(7),rv)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(7),rv)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture rv ok',rv
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(8),u)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(8),u)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture u ok',u
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(9),v)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(9),v)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture v ok',v
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(10),ug)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(10),ug)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture ug ok',ug
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(11),vg)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(11),vg)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture vg ok',vg
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(12),w)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(12),w)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture w ok',w
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(13),du)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(13),du)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture du ok',du
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(14),hu)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(14),hu)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture hu ok',hu
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(15),vu)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(15),vu)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture vu ok',vu
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(16),dv)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(16),dv)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dv ok',dv
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(17),hv)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(17),hv)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture hv ok',hv
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(18),vv)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(18),vv)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture vv ok',vv
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(19),dt)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(19),dt)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dt ok',dt
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(20),ht)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(20),ht)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture ht ok',ht
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(21),vt)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(21),vt)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture vt ok',vt
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(22),dq)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(22),dq)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dq ok',dq
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(23),hq)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(23),hq)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture hq ok',hq
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(24),vq)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(24),vq)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture vq ok',vq
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(25),dth)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(25),dth)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dth ok',dth
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(26),hth)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(26),hth)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture hth ok',hth
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(27),vth)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(27),vth)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture vth ok',vth
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(28),dr)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(28),dr)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dr ok',dr
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(29),hr)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(29),hr)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture hr ok',hr
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(30),vr)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(30),vr)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture vr ok',vr
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(31),dtrad)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(31),dtrad)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dtrad ok',dtrad
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(32),sens)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(32),sens)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture sens ok',sens
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(33),flat)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(33),flat)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture flat ok',flat
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(34),ts)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(34),ts)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture ts ok',ts
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(35),ustar)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(35),ustar)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!         write(*,*)'lecture ustar ok',ustar
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(36),uw)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(36),uw)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!         write(*,*)'lecture uw ok',uw
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(37),vw)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(37),vw)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!         write(*,*)'lecture vw ok',vw
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(38),q1)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(38),q1)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!         write(*,*)'lecture q1 ok',q1
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(39),q2)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(39),q2)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!         write(*,*)'lecture q2 ok',q2
+
+
+         return 
+         end subroutine read_cas
+!======================================================================
+        SUBROUTINE interp_case_time(day,day1,annee_ref                &
+!    &         ,year_cas,day_cas,nt_cas,pdt_forc,nlev_cas      &
+     &         ,nt_cas,nlev_cas                                       &
+     &         ,ts_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)
+        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_cas1
+      print *,'it_cas2=',it_cas2
+      print *,'time_cas1=',time_cas1
+      print *,'time_cas2=',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
+
+!**********************************************************************************************
Index: DZ5/branches/testing/libf/phylmd/dyn1d/mod_grid_phy_lmdz.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_grid_phy_lmdz.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../../dynlonlat_phylonlat/mod_grid_phy_lmdz.F90
Index: /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_interface_dyn_phys.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_interface_dyn_phys.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_interface_dyn_phys.F90	(revision 2408)
@@ -0,0 +1,1 @@
+link ../../dynlonlat_phylonlat/mod_interface_dyn_phys.F90
Index: DZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_mpi_data.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_mpi_data.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../../dynlonlat_phylonlat/mod_phys_lmdz_mpi_data.F90
Index: DZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_mpi_transfert.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_mpi_transfert.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../../dynlonlat_phylonlat/mod_phys_lmdz_mpi_transfert.F90
Index: DZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_omp_data.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_omp_data.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../../dynlonlat_phylonlat/mod_phys_lmdz_omp_data.F90
Index: DZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_omp_transfert.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_omp_transfert.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../../dynlonlat_phylonlat/mod_phys_lmdz_omp_transfert.F90
Index: DZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_para.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_para.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../../dynlonlat_phylonlat/mod_phys_lmdz_para.F90
Index: DZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_transfert_para.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/mod_phys_lmdz_transfert_para.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../../dynlonlat_phylonlat/mod_phys_lmdz_transfert_para.F90
Index: DZ5/branches/testing/libf/phylmd/dyn1d/q_sat.F
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/q_sat.F	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../../dyn3d_common/q_sat.F
Index: DZ5/branches/testing/libf/phylmd/dyn1d/write_field.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/dyn1d/write_field.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../../dyn3d_common/write_field.F90
Index: DZ5/branches/testing/libf/phylmd/ecribin.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ecribin.F90	(revision 2407)
+++ 	(revision )
@@ -1,105 +1,0 @@
-
-! $Header$
-
-SUBROUTINE ecribins(unit, pz)
-  USE dimphy
-  IMPLICIT NONE
-  ! -----------------------------------------------------------------------
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
-  include "paramet.h"
-  include "comgeom.h"
-  include "comvert.h"
-
-  ! arguments:
-  ! ----------
-  INTEGER unit
-  REAL pz(klon)
-
-  ! local:
-  ! ------
-  INTEGER i, j, ig
-  REAL zz(iim+1, jjm+1)
-  ! -----------------------------------------------------------------------
-  ! passage a la grille dynamique:
-  ! ------------------------------
-  DO i = 1, iim + 1
-    zz(i, 1) = pz(1)
-    zz(i, jjm+1) = pz(klon)
-  END DO
-  ! traitement des point normaux
-  DO j = 2, jjm
-    ig = 2 + (j-2)*iim
-    CALL scopy(iim, pz(ig), 1, zz(1,j), 1)
-    zz(iim+1, j) = zz(1, j)
-  END DO
-  ! -----------------------------------------------------------------------
-#ifdef VPP
-  CALL ecriture(unit, zz, (iim+1)*(jjm+1))
-#else
-  WRITE (unit) zz
-#endif
-
-
-  RETURN
-END SUBROUTINE ecribins
-SUBROUTINE ecribina(unit, pz)
-  USE dimphy
-  IMPLICIT NONE
-  ! -----------------------------------------------------------------------
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
-  include "paramet.h"
-  include "comgeom.h"
-  include "comvert.h"
-
-  ! arguments:
-  ! ----------
-  INTEGER unit
-  REAL pz(klon, klev)
-
-  ! local:
-  ! ------
-  INTEGER i, j, ilay, ig
-  REAL zz(iim+1, jjm+1, llm)
-  ! -----------------------------------------------------------------------
-  ! passage a la grille dynamique:
-  ! ------------------------------
-  DO ilay = 1, llm
-    ! traitement des poles
-    DO i = 1, iim + 1
-      zz(i, 1, ilay) = pz(1, ilay)
-      zz(i, jjm+1, ilay) = pz(klon, ilay)
-    END DO
-    ! traitement des point normaux
-    DO j = 2, jjm
-      ig = 2 + (j-2)*iim
-      CALL scopy(iim, pz(ig,ilay), 1, zz(1,j,ilay), 1)
-      zz(iim+1, j, ilay) = zz(1, j, ilay)
-    END DO
-  END DO
-  ! -----------------------------------------------------------------------
-  DO ilay = 1, llm
-#ifdef VPP
-    CALL ecriture(unit, zz(1,1,ilay), (iim+1)*(jjm+1))
-#else
-    WRITE (unit)((zz(i,j,ilay),i=1,iim+1), j=1, jjm+1)
-#endif
-  END DO
-
-  RETURN
-END SUBROUTINE ecribina
-#ifdef VPP
-@OPTIONS NODOUBLE
-SUBROUTINE ecriture(nunit, r8, n)
-  INTEGER nunit, n, i
-  REAL (KIND=8) r8(n)
-  REAL r4(n)
-
-  DO i = 1, n
-    r4(i) = r8(i)
-  END DO
-  WRITE (nunit) r4
-  RETURN
-END SUBROUTINE ecriture
-#endif
Index: DZ5/branches/testing/libf/phylmd/ecrireg.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ecrireg.F90	(revision 2407)
+++ 	(revision )
@@ -1,119 +1,0 @@
-
-! $Header$
-
-SUBROUTINE ecriregs(unit, pz)
-  USE dimphy
-  IMPLICIT NONE
-  ! -----------------------------------------------------------------------
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
-  include "paramet.h"
-  include "comgeom.h"
-  include "comvert.h"
-  include "regdim.h"
-
-  ! arguments:
-  ! ----------
-  INTEGER unit
-  REAL pz(klon)
-
-  ! local:
-  ! ------
-  INTEGER i, j, ig
-  REAL zz(iim, jjm+1)
-  INTEGER nleng
-  PARAMETER (nleng=(i2_fin-i2_deb+1+i1_fin-i1_deb+1)*(j_fin-j_deb+1))
-  REAL zzz(nleng)
-
-  ! -----------------------------------------------------------------------
-  ! passage a la grille dynamique:
-  ! ------------------------------
-  DO i = 1, iim
-    zz(i, 1) = pz(1)
-    zz(i, jjm+1) = pz(klon)
-  END DO
-
-  ! traitement des point normaux
-  DO j = 2, jjm
-    ig = 2 + (j-2)*iim
-    CALL scopy(iim, pz(ig), 1, zz(1,j), 1)
-  END DO
-  ! -----------------------------------------------------------------------
-  ig = 0
-  DO j = j_deb, j_fin
-    DO i = i1_deb, i1_fin
-      ig = ig + 1
-      zzz(ig) = zz(i, j)
-    END DO
-    DO i = i2_deb, i2_fin
-      ig = ig + 1
-      zzz(ig) = zz(i, j)
-    END DO
-  END DO
-#ifdef VPP
-  CALL ecriture(unit, zzz, nleng)
-#else
-  WRITE (unit) zzz
-#endif
-  RETURN
-END SUBROUTINE ecriregs
-SUBROUTINE ecrirega(unit, pz)
-  USE dimphy
-  IMPLICIT NONE
-  ! -----------------------------------------------------------------------
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
-  include "paramet.h"
-  include "comgeom.h"
-  include "comvert.h"
-  include "regdim.h"
-
-  ! arguments:
-  ! ----------
-  INTEGER unit
-  REAL pz(klon, klev)
-
-  ! local:
-  ! ------
-  INTEGER i, j, ilay, ig
-  REAL zz(iim, jjm+1, llm)
-  INTEGER nleng
-  PARAMETER (nleng=(i2_fin-i2_deb+1+i1_fin-i1_deb+1)*(j_fin-j_deb+1))
-  REAL zzz(nleng)
-  ! -----------------------------------------------------------------------
-  ! passage a la grille dynamique:
-  ! ------------------------------
-  DO ilay = 1, llm
-    ! traitement des poles
-    DO i = 1, iim
-      zz(i, 1, ilay) = pz(1, ilay)
-      zz(i, jjm+1, ilay) = pz(klon, ilay)
-    END DO
-    ! traitement des point normaux
-    DO j = 2, jjm
-      ig = 2 + (j-2)*iim
-      CALL scopy(iim, pz(ig,ilay), 1, zz(1,j,ilay), 1)
-    END DO
-  END DO
-  ! -----------------------------------------------------------------------
-  DO ilay = 1, llm
-    ig = 0
-    DO j = j_deb, j_fin
-      DO i = i1_deb, i1_fin
-        ig = ig + 1
-        zzz(ig) = zz(i, j, ilay)
-      END DO
-      DO i = i2_deb, i2_fin
-        ig = ig + 1
-        zzz(ig) = zz(i, j, ilay)
-      END DO
-    END DO
-#ifdef VPP
-    CALL ecriture(unit, zzz, nleng)
-#else
-    WRITE (unit) zzz
-#endif
-  END DO
-
-  RETURN
-END SUBROUTINE ecrirega
Index: /LMDZ5/branches/testing/libf/phylmd/ener_conserv.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ener_conserv.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/ener_conserv.F90	(revision 2408)
@@ -88,5 +88,5 @@
    ELSE
       abort_message = 'iflag_ener_conserv non prevu'
-      CALL abort_gcm (modname,abort_message,1)
+      CALL abort_physic (modname,abort_message,1)
    ENDIF
 
Index: DZ5/branches/testing/libf/phylmd/etat0_netcdf.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/etat0_netcdf.F90	(revision 2407)
+++ 	(revision )
@@ -1,541 +1,0 @@
-!
-! $Id: etat0_netcdf.F90 1625 2012-05-09 13:14:48Z lguez $
-!
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE etat0_netcdf(ib, masque, phis, letat0)
-#ifndef CPP_1D
-!
-!-------------------------------------------------------------------------------
-! Purpose: Creates initial states
-!-------------------------------------------------------------------------------
-! Note: This routine is designed to work for Earth
-!-------------------------------------------------------------------------------
-  USE control_mod
-#ifdef CPP_EARTH
-  USE startvar
-  USE ioipsl
-  USE dimphy
-  USE infotrac
-  USE fonte_neige_mod
-  USE pbl_surface_mod
-  USE phys_state_var_mod
-  USE filtreg_mod
-  USE regr_lat_time_climoz_m, ONLY: regr_lat_time_climoz
-  USE conf_phys_m,            ONLY: conf_phys
-! For parameterization of ozone chemistry:
-  USE regr_lat_time_coefoz_m, only: regr_lat_time_coefoz
-  USE press_coefoz_m, only: press_coefoz
-  USE regr_pr_o3_m, only: regr_pr_o3
-  USE netcdf, ONLY : NF90_OPEN, NF90_NOWRITE, NF90_CLOSE, NF90_NOERR
-  USE indice_sol_mod
-  use exner_hyb_m, only: exner_hyb
-  use exner_milieu_m, only: exner_milieu
-  use test_disvert_m, only: test_disvert
-#endif
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-#include "dimensions.h"
-#include "paramet.h"
-#include "iniprint.h"
-  LOGICAL,                    INTENT(IN)    :: ib     ! barycentric interpolat.
-  REAL, DIMENSION(iip1,jjp1), INTENT(INOUT) :: masque ! land mask
-  REAL, DIMENSION(iip1,jjp1), INTENT(OUT)   :: phis   ! geopotentiel au sol
-  LOGICAL,                    INTENT(IN)    :: letat0 ! F: masque only required
-#ifndef CPP_EARTH
-  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
-#else
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "comgeom2.h"
-#include "comvert.h"
-#include "comconst.h"
-#include "dimsoil.h"
-#include "temps.h"
-  REAL,    DIMENSION(klon)                 :: tsol
-  REAL,    DIMENSION(klon)                 :: sn, rugmer, run_off_lic_0
-  REAL,    DIMENSION(iip1,jjp1)            :: orog, rugo, psol
-  REAL,    DIMENSION(iip1,jjp1,llm+1)      :: p3d
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: uvent, t3d, tpot, qsat, qd
-  REAL,    DIMENSION(iip1,jjm ,llm)        :: vvent
-  REAL,    DIMENSION(:,:,:,:), ALLOCATABLE :: q3d
-  REAL,    DIMENSION(klon,nbsrf)           :: qsolsrf, snsrf
-  REAL,    DIMENSION(klon,nsoilmx,nbsrf)   :: tsoil
-
-!--- Local variables for sea-ice reading:
-  INTEGER                                  :: iml_lic, jml_lic, llm_tmp
-  INTEGER                                  :: ttm_tmp, iret, fid
-  INTEGER, DIMENSION(1)                    :: itaul
-  REAL,    DIMENSION(1)                    :: lev
-  REAL                                     :: date
-  REAL,    DIMENSION(:,:),   ALLOCATABLE   ::  lon_lic,  lat_lic, fraclic
-  REAL,    DIMENSION(:),     ALLOCATABLE   :: dlon_lic, dlat_lic
-  REAL,    DIMENSION(iip1,jjp1)            :: flic_tmp
-
-!--- Misc
-  CHARACTER(LEN=80)                        :: x, fmt
-  INTEGER                                  :: i, j, l, ji
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: pk, pls, y
-  REAL,    DIMENSION(ip1jmp1)              :: pks
-
-#include "comdissnew.h"
-#include "serre.h"
-#include "clesphys.h"
-
-  REAL,    DIMENSION(iip1,jjp1,llm)        :: masse
-  INTEGER :: itau, iday
-  REAL    :: xpn, xps, time, phystep
-  REAL,    DIMENSION(iim)                  :: xppn, xpps
-  REAL,    DIMENSION(ip1jmp1,llm)          :: pbaru, phi, w
-  REAL,    DIMENSION(ip1jm  ,llm)          :: pbarv
-  REAL,    DIMENSION(klon)                 :: fder
-
-!--- Local variables for ocean mask reading:
-  INTEGER :: nid_o2a, iml_omask, jml_omask
-  LOGICAL :: couple=.FALSE.
-  REAL,    DIMENSION(:,:), ALLOCATABLE ::  lon_omask, lat_omask, ocemask, ocetmp
-  REAL,    DIMENSION(:),   ALLOCATABLE :: dlon_omask,dlat_omask
-  REAL,    DIMENSION(klon)             :: ocemask_fi
-  INTEGER, DIMENSION(klon-2)           :: isst
-  REAL,    DIMENSION(iim,jjp1)         :: zx_tmp_2d
-  REAL    :: dummy
-  LOGICAL :: ok_newmicro, ok_journe, ok_mensuel, ok_instan, ok_hf
-  LOGICAL :: ok_LES, ok_ade, ok_aie, ok_cdnc, aerosol_couple, new_aod, callstats
-  INTEGER :: iflag_radia, flag_aerosol
-  LOGICAL :: flag_aerosol_strat
-  REAL    :: bl95_b0, bl95_b1, fact_cldcon, facttemps, ratqsbas, ratqshaut
-  REAL    :: tau_ratqs
-  INTEGER :: iflag_cldcon, iflag_ratqs, iflag_coupl, iflag_clos, iflag_wake
-  INTEGER :: iflag_thermals, nsplit_thermals
-  INTEGER :: iflag_thermals_ed, iflag_thermals_optflux
-  REAL    :: tau_thermals, solarlong0,  seuil_inversion
-  INTEGER :: read_climoz ! read ozone climatology
-!  Allowed values are 0, 1 and 2
-!     0: do not read an ozone climatology
-!     1: read a single ozone climatology that will be used day and night
-!     2: read two ozone climatologies, the average day and night
-!     climatology and the daylight climatology
-!-------------------------------------------------------------------------------
-  REAL    :: alp_offset
-  logical found
-
-!--- Constants
-  pi     = 4. * ATAN(1.)
-  rad    = 6371229.
-  daysec = 86400.
-  omeg   = 2.*pi/daysec
-  g      = 9.8
-  kappa  = 0.2857143
-  cpp    = 1004.70885
-  preff  = 101325.
-  pa     = 50000.
-  jmp1   = jjm + 1
-
-!--- CONSTRUCT A GRID
-  CALL conf_phys(  ok_journe, ok_mensuel, ok_instan, ok_hf, ok_LES,     &
-                   callstats,                                           &
-                   solarlong0,seuil_inversion,                          &
-                   fact_cldcon, facttemps,ok_newmicro,iflag_radia,      &
-                   iflag_cldcon,                                        &
-                   iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,            &
-                   ok_ade, ok_aie, ok_cdnc, aerosol_couple,             &
-                   flag_aerosol, flag_aerosol_strat, new_aod,           &
-                   bl95_b0, bl95_b1,                                    &
-                   read_climoz,                                         &
-                   alp_offset)
-
-! co2_ppm0 : initial value of atmospheric CO2 from .def file (co2_ppm value)
-  co2_ppm0 = co2_ppm
-
-  dtvr   = daysec/FLOAT(day_step)
-  WRITE(lunout,*)'dtvr',dtvr
-
-  CALL iniconst()
-  if (pressure_exner) call test_disvert
-  CALL inigeom()
-
-!--- Initializations for tracers
-  CALL infotrac_init
-  ALLOCATE(q3d(iip1,jjp1,llm,nqtot))
-
-  CALL inifilr()
-  CALL phys_state_var_init(read_climoz)
-
-  rlat(1) = ASIN(1.0)
-  DO j=2,jjm; rlat((j-2)*iim+2:(j-1)*iim+1)=rlatu(j);     END DO
-  rlat(klon) = - ASIN(1.0)
-  rlat(:)=rlat(:)*(180.0/pi)
-
-  rlon(1) = 0.0
-  DO j=2,jjm; rlon((j-2)*iim+2:(j-1)*iim+1)=rlonv(1:iim); END DO
-  rlon(klon) = 0.0
-  rlon(:)=rlon(:)*(180.0/pi)
-
-! For a coupled simulation, the ocean mask from ocean model is used to compute
-! the weights an to insure ocean fractions are the same for atmosphere and ocean
-! Otherwise, mask is created using Relief file.
-
-  WRITE(lunout,*)'Essai de lecture masque ocean'
-  iret = NF90_OPEN("o2a.nc", NF90_NOWRITE, nid_o2a)
-  IF(iret/=NF90_NOERR) THEN
-    WRITE(lunout,*)'ATTENTION!! pas de fichier o2a.nc trouve'
-    WRITE(lunout,*)'Run force'
-    x='masque'
-    masque(:,:)=0.0
-    CALL startget_phys2d(x, iip1, jjp1, rlonv, rlatu, masque, 0.0, jjm, &
-   &              rlonu, rlatv, ib)
-    WRITE(lunout,*)'MASQUE construit : Masque'
-    if (prt_level >= 1) WRITE(lunout,'(97I1)') nINT(masque)
-    CALL gr_dyn_fi(1, iip1, jjp1, klon, masque, zmasq)
-    WHERE(   zmasq(:)<EPSFRA) zmasq(:)=0.
-    WHERE(1.-zmasq(:)<EPSFRA) zmasq(:)=1.
-  ELSE
-    WRITE(lunout,*)'ATTENTION!! fichier o2a.nc trouve'
-    WRITE(lunout,*)'Run couple'
-    couple=.true.
-    iret=NF90_CLOSE(nid_o2a)
-    CALL flininfo("o2a.nc", iml_omask, jml_omask, llm_tmp, ttm_tmp, nid_o2a)
-    IF(iml_omask/=iim .OR.jml_omask/=jjp1) THEN
-      WRITE(lunout,*)'Dimensions non compatibles pour masque ocean'
-      WRITE(lunout,*)'iim = ',iim,' iml_omask = ',iml_omask
-      WRITE(lunout,*)'jjp1 = ',jjp1,' jml_omask = ',jml_omask
-      CALL abort_gcm('etat0_netcdf','Dimensions non compatibles pour masque oc&
-     &ean',1)
-    END IF
-    ALLOCATE(   ocemask(iml_omask,jml_omask),   ocetmp(iml_omask,jml_omask))
-    ALLOCATE( lon_omask(iml_omask,jml_omask),lat_omask(iml_omask,jml_omask))
-    ALLOCATE(dlon_omask(iml_omask),         dlat_omask(jml_omask))
-    CALL flinopen("o2a.nc", .FALSE., iml_omask, jml_omask, llm_tmp, lon_omask,&
-   &              lat_omask, lev, ttm_tmp, itaul, date, dt, fid)
-    CALL flinget(fid, 'OceMask', iml_omask, jml_omask, llm_tmp, ttm_tmp, &
-   &              1, 1, ocetmp)
-    CALL flinclo(fid)
-    dlon_omask(1:iml_omask) = lon_omask(1:iml_omask,1)
-    dlat_omask(1:jml_omask) = lat_omask(1,1:jml_omask)
-    ocemask = ocetmp
-    IF(dlat_omask(1)<dlat_omask(jml_omask)) THEN
-      DO j=1,jml_omask
-        ocemask(:,j) = ocetmp(:,jml_omask-j+1)
-      END DO
-    END IF
-!
-! Ocean mask to physical grid
-!*******************************************************************************
-    WRITE(lunout,*)'ocemask '
-    WRITE(fmt,"(i4,'i1)')")iml_omask ; fmt='('//ADJUSTL(fmt)
-    WRITE(lunout,fmt)int(ocemask)
-    ocemask_fi(1)=ocemask(1,1)
-    DO j=2,jjm; ocemask_fi((j-2)*iim+2:(j-1)*iim+1)=ocemask(1:iim,j); END DO
-    ocemask_fi(klon)=ocemask(1,jjp1)
-    zmasq=1.-ocemask_fi
-  END IF
-
-  CALL gr_fi_dyn(1,klon,iip1,jjp1,zmasq,masque)
-
-  ! The startget calls need to be replaced by a call to restget to get the
-  ! values in the restart file
-  x = 'relief'; orog(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu, orog, 0.0,jjm,rlonu,rlatv,ib,&
- &               masque)
-
-  x = 'rugosite'; rugo(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu, rugo, 0.0,jjm, rlonu,rlatv,ib)
-!  WRITE(lunout,'(49I1)') INT(orog(:,:)*10)
-!  WRITE(lunout,'(49I1)') INT(rugo(:,:)*10)
-
-! Sub-surfaces initialization
-!*******************************************************************************
-  pctsrf=0.
-  x = 'psol'; psol(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu,psol,0.0,jjm,rlonu,rlatv,ib)
-!  WRITE(lunout,*) 'PSOL :', psol(10,20)
-!  WRITE(lunout,*) ap(:), bp(:)
-
-! Mid-levels pressure computation
-!*******************************************************************************
-  CALL pression(ip1jmp1, ap, bp, psol, p3d)
-  if (pressure_exner) then
-    CALL exner_hyb(ip1jmp1, psol, p3d, pks, pk)
-  else
-    CALL exner_milieu(ip1jmp1,psol,p3d, pks,pk)
-  endif
-  pls(:,:,:)=preff*(pk(:,:,:)/cpp)**(1./kappa)
-!  WRITE(lunout,*) 'P3D :', p3d(10,20,:)
-!  WRITE(lunout,*) 'PK:',    pk(10,20,:)
-!  WRITE(lunout,*) 'PLS :', pls(10,20,:)
-
-  x = 'surfgeo'; phis(:,:) = 0.0
-  CALL startget_phys2d(x,iip1,jjp1,rlonv,rlatu,phis, 0.0,jjm, rlonu,rlatv,ib)
-
-  x = 'u';    uvent(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonu,rlatu,pls,y,uvent,0.0,  &
- &                  rlonv,rlatv,ib)
-
-  x = 'v';    vvent(:,:,:) = 0.0
-  CALL startget_dyn(x, rlonv,rlatv,pls(:, :jjm, :),y(:, :jjm, :),vvent,0.0, &
- &                  rlonu,rlatu(:jjm),ib)
-
-  x = 't';    t3d(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,y,t3d,0.0,    &
- &                  rlonu,rlatv,ib)
-
-  x = 'tpot'; tpot(:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,pk,tpot,0.0,  &
- &                  rlonu,rlatv,ib)
-
-  WRITE(lunout,*) 'T3D min,max:',minval(t3d(:,:,:)),maxval(t3d(:,:,:))
-  WRITE(lunout,*) 'PLS min,max:',minval(pls(:,:,:)),maxval(pls(:,:,:))
-
-! Humidity at saturation computation
-!*******************************************************************************
-  WRITE(lunout,*) 'avant q_sat'
-  CALL q_sat(llm*jjp1*iip1, t3d, pls, qsat)
-  WRITE(lunout,*) 'apres q_sat'
-  WRITE(lunout,*) 'QSAT min,max:',minval(qsat(:,:,:)),maxval(qsat(:,:,:))
-!  WRITE(lunout,*) 'QSAT :',qsat(10,20,:)
-
-  x = 'q';    qd (:,:,:) = 0.0
-  CALL startget_dyn(x,rlonv,rlatu,pls,qsat,qd,0.0, rlonu,rlatv,ib)
-  q3d(:,:,:,:) = 0.0 ; q3d(:,:,:,1) = qd(:,:,:)
-
-! Parameterization of ozone chemistry:
-! Look for ozone tracer:
-  i = 1
-  DO
-    found = tname(i)=="O3" .OR. tname(i)=="o3"
-    if (found .or. i == nqtot) exit
-    i = i + 1
-  end do
-  if (found) then
-    call regr_lat_time_coefoz
-    call press_coefoz
-    call regr_pr_o3(p3d, q3d(:, :, :, i))
-!   Convert from mole fraction to mass fraction:
-    q3d(:, :, :, i) = q3d(:, :, :, i)  * 48. / 29.
-  end if
-
-!--- OZONE CLIMATOLOGY
-  IF(read_climoz>=1) CALL regr_lat_time_climoz(read_climoz)
-
-  x = 'tsol'; tsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,tsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'qsol';  qsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,qsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'snow';  sn(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,sn,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'rads';  radsol(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,radsol,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'rugmer'; rugmer(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,rugmer,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zmea';  zmea(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zmea,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zstd';  zstd(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zstd,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zsig';  zsig(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zsig,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zgam';  zgam(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zgam,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zthe';  zthe(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zthe,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zpic';  zpic(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zpic,0.0,jjm,rlonu,rlatv,ib)
-
-  x = 'zval';  zval(:) = 0.0
-  CALL startget_phys1d(x,iip1,jjp1,rlonv,rlatu,klon,zval,0.0,jjm,rlonu,rlatv,ib)
-
-!  WRITE(lunout,'(48I3)') 'TSOL :', INT(tsol(2:klon)-273)
-
-! Soil ice file reading for soil fraction and soil ice fraction
-!*******************************************************************************
-  CALL flininfo("landiceref.nc", iml_lic, jml_lic, llm_tmp, ttm_tmp, fid)
-  ALLOCATE( lat_lic(iml_lic,jml_lic),lon_lic(iml_lic, jml_lic))
-  ALLOCATE(dlat_lic(jml_lic),       dlon_lic(iml_lic))
-  ALLOCATE( fraclic(iml_lic,jml_lic))
-  CALL flinopen("landiceref.nc", .FALSE., iml_lic, jml_lic, llm_tmp,  &
- &               lon_lic, lat_lic, lev, ttm_tmp, itaul, date, dt, fid)
-  CALL flinget(fid, 'landice', iml_lic, jml_lic, llm_tmp, ttm_tmp, 1,1, fraclic)
-  CALL flinclo(fid)
-
-! Interpolation on model T-grid
-!*******************************************************************************
-  WRITE(lunout,*)'dimensions de landice iml_lic, jml_lic : ',iml_lic,jml_lic
-! conversion if coordinates are in degrees
-  IF(MAXVAL(lon_lic)>pi) lon_lic=lon_lic*pi/180.
-  IF(MAXVAL(lat_lic)>pi) lat_lic=lat_lic*pi/180.
-  dlon_lic(:)=lon_lic(:,1)
-  dlat_lic(:)=lat_lic(1,:)
-  CALL grille_m( iml_lic, jml_lic, dlon_lic, dlat_lic, fraclic, iim,jjp1,   &
- &               rlonv, rlatu, flic_tmp(1:iim,:) )
-  flic_tmp(iip1,:)=flic_tmp(1,:)
-
-!--- To the physical grid
-  CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp, pctsrf(:,is_lic))
-
-!--- 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 
-
-! sub-surface ocean and sea ice (sea ice set to zero for start)
-!*******************************************************************************
-  pctsrf(:,is_oce)=(1.-zmasq(:))
-  WHERE(pctsrf(:,is_oce)<EPSFRA) pctsrf(:,is_oce)=0.
-  IF(couple) pctsrf(:,is_oce)=ocemask_fi(:)
-  isst=0
-  WHERE(pctsrf(2:klon-1,is_oce)>0.) isst=1
-
-! It is checked that the sub-surfaces sum is equal to 1
-!*******************************************************************************
-  ji=COUNT((ABS(SUM(pctsrf(:,:),dim=2))-1.0)>EPSFRA)
-  IF(ji/=0) WRITE(lunout,*) 'pb repartition sous maille pour ',ji,' points'
-  CALL gr_fi_ecrit(1, klon, iim, jjp1, zmasq, zx_tmp_2d)
-!  WRITE(fmt,"(i3,')')")iim; fmt='(i'//ADJUSTL(fmt)
-!  WRITE(lunout,*)'zmasq = '
-!  WRITE(lunout,TRIM(fmt))NINT(zx_tmp_2d)
-  CALL gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
-  WRITE(fmt,"(i4,'i1)')")iip1 ; fmt='('//ADJUSTL(fmt)
-  WRITE(lunout,*) 'MASQUE construit : Masque'
-  if (prt_level >= 1) WRITE(lunout,TRIM(fmt))NINT(masque(:,:))
-
-! Intermediate computation
-!*******************************************************************************
-  CALL massdair(p3d,masse)
-  WRITE(lunout,*)' ALPHAX ',alphax
-  DO l=1,llm
-    xppn(:)=aire(1:iim,1   )*masse(1:iim,1   ,l)
-    xpps(:)=aire(1:iim,jjp1)*masse(1:iim,jjp1,l)
-    xpn=SUM(xppn)/apoln
-    xps=SUM(xpps)/apols
-    masse(:,1   ,l)=xpn
-    masse(:,jjp1,l)=xps
-  END DO
-  q3d(iip1,:,:,:)=q3d(1,:,:,:)
-  phis(iip1,:) = phis(1,:)
-
-  IF(.NOT.letat0) RETURN
-
-! Writing
-!*******************************************************************************
-  CALL inidissip(lstardis, nitergdiv, nitergrot, niterh, tetagdiv, tetagrot, &
-       tetatemp, vert_prof_dissip)
-  WRITE(lunout,*)'sortie inidissip'
-  itau=0
-  itau_dyn=0
-  itau_phy=0
-  iday=dayref+itau/day_step
-  time=FLOAT(itau-(iday-dayref)*day_step)/day_step
-  IF(time>1.) THEN
-   time=time-1
-   iday=iday+1
-  END IF
-  day_ref=dayref
-  annee_ref=anneeref
-
-  CALL geopot( ip1jmp1, tpot, pk, pks, phis, phi )
-  WRITE(lunout,*)'sortie geopot'
-
-  CALL caldyn0( itau, uvent, vvent, tpot, psol, masse, pk, phis,               &
-                phi,  w, pbaru, pbarv, time+iday-dayref)
-  WRITE(lunout,*)'sortie caldyn0'     
-  CALL dynredem0( "start.nc", dayref, phis)
-  WRITE(lunout,*)'sortie dynredem0'
-  CALL dynredem1( "start.nc", 0.0, vvent, uvent, tpot, q3d, masse, psol)
-  WRITE(lunout,*)'sortie dynredem1' 
-
-! Physical initial state writting
-!*******************************************************************************
-  WRITE(lunout,*)'phystep ',dtvr,iphysiq,nbapp_rad
-  phystep   = dtvr * FLOAT(iphysiq)
-  radpas    = NINT (86400./phystep/ FLOAT(nbapp_rad) )
-  WRITE(lunout,*)'phystep =', phystep, radpas
-
-! Init: tsol, qsol, sn, evap, tsoil, rain_fall, snow_fall, solsw, sollw, frugs
-!*******************************************************************************
-  DO i=1,nbsrf; ftsol(:,i) = tsol; END DO
-  DO i=1,nbsrf; snsrf(:,i) = sn;   END DO
-!albedo SB >>>
-  falb_dir(:,is_ter,:)=0.08; falb_dir(:,is_lic,:)=0.6
-  falb_dir(:,is_oce,:)=0.5;  falb_dir(:,is_sic,:)=0.6
-!albedo SB <<<
-  fevap(:,:) = 0.
-  DO i=1,nbsrf; qsolsrf(:,i)=150.; END DO
-  DO i=1,nbsrf; DO j=1,nsoilmx; tsoil(:,j,i) = tsol; END DO; END DO
-  rain_fall = 0.; snow_fall = 0.
-  solsw = 165.;   sollw = -53.
-  t_ancien = 273.15
-  q_ancien = 0.
-  agesno = 0.
-
-  z0m(:,is_oce) = rugmer(:)
-  z0m(:,is_ter) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
-  z0m(:,is_lic) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
-  z0m(:,is_sic) = 0.001
-  z0h(:,:)=z0m(:,:)
-
-  fder = 0.0
-  clwcon = 0.0
-  rnebcon = 0.0
-  ratqs = 0.0
-  run_off_lic_0 = 0.0 
-  rugoro = 0.0
-
-! Before phyredem calling, surface modules and values to be saved in startphy.nc
-! are initialized
-!*******************************************************************************
-  dummy = 1.0
-  pbl_tke(:,:,:) = 1.e-8 
-  zmax0(:) = 40.
-  f0(:) = 1.e-5
-  sig1(:,:) = 0.
-  w01(:,:) = 0.
-  wake_deltat(:,:) = 0.
-  wake_deltaq(:,:) = 0.
-  wake_s(:) = 0.
-  wake_cstar(:) = 0.
-  wake_fip(:) = 0.
-  wake_pe = 0.
-  fm_therm = 0.
-  entr_therm = 0.
-  detr_therm = 0.
-
-  CALL fonte_neige_init(run_off_lic_0)
-  CALL pbl_surface_init( fder, snsrf, qsolsrf, tsoil )
-  CALL phyredem( "startphy.nc" )
-
-!  WRITE(lunout,*)'CCCCCCCCCCCCCCCCCC REACTIVER SORTIE VISU DANS ETAT0'
-!  WRITE(lunout,*)'entree histclo'
-  CALL histclo()
-
-#endif 
-!#endif of #ifdef CPP_EARTH
-  RETURN
-#endif
-!#endif of ifndef CPP_1D
-END SUBROUTINE etat0_netcdf
-!
-!-------------------------------------------------------------------------------
Index: /LMDZ5/branches/testing/libf/phylmd/fisrtilp.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/fisrtilp.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/fisrtilp.F90	(revision 2408)
@@ -14,4 +14,5 @@
   USE dimphy
   USE icefrac_lsc_mod ! compute ice fraction (JBM 3/14)
+  USE print_control_mod, ONLY: prt_level, lunout
   IMPLICIT none
   !======================================================================
@@ -22,11 +23,7 @@
   !======================================================================
   !======================================================================
-  !ym include "dimensions.h"
-  !ym include "dimphy.h"
   include "YOMCST.h"
-  include "tracstoke.h"
   include "fisrtilp.h"
   include "nuage.h" ! JBM (3/14)
-  include "iniprint.h"
 
   !
Index: /LMDZ5/branches/testing/libf/phylmd/fisrtilp_tr.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/fisrtilp_tr.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/fisrtilp_tr.F90	(revision 2408)
@@ -10,4 +10,5 @@
 
   USE dimphy
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
   ! ======================================================================
@@ -18,9 +19,5 @@
   ! ======================================================================
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
-  include "tracstoke.h"
-  include "iniprint.h"
 
   ! Arguments:
Index: /LMDZ5/branches/testing/libf/phylmd/flott_gwd_rando_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/flott_gwd_rando_m.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/flott_gwd_rando_m.F90	(revision 2408)
@@ -6,5 +6,5 @@
 
   SUBROUTINE FLOTT_GWD_rando(DTIME, pp, tt, uu, vv, prec, zustr, zvstr, d_u, &
-       d_v)
+       d_v,east_gwstress,west_gwstress)
 
     ! Parametrization of the momentum flux deposition due to a discrete
@@ -15,9 +15,13 @@
     ! Reference: Lott (JGR, vol 118, page 8897, 2013)
 
-    use dimphy, only: klon, klev
-    use assert_m, only: assert
-
-    include "YOMCST.h"
-    include "clesphys.h"
+    !ONLINE:
+      use dimphy, only: klon, klev
+      use assert_m, only: assert
+      include "YOMCST.h"
+      include "clesphys.h"
+    ! OFFLINE:
+    ! include "dimensions.h"
+    ! include "dimphy.h"
+    ! END OF DIFFERENCE ONLINE-OFFLINE
     include "YOEGWD.h"
 
@@ -36,10 +40,14 @@
 
     REAL, intent(inout):: d_u(:, :), d_v(:, :) 
+    REAL, intent(inout):: east_gwstress(:, :) !  Profile of eastward stress
+    REAL, intent(inout):: west_gwstress(:, :) !  Profile of westward stress 
+
     ! (KLON, KLEV) tendencies on winds
 
     ! O.3 INTERNAL ARRAYS
     REAL BVLOW(klon)
-
-    INTEGER II, LL
+    REAL DZ   !  Characteristic depth of the Source
+
+    INTEGER II, JJ, LL
 
     ! 0.3.0 TIME SCALE OF THE LIFE CYCLE OF THE WAVES PARAMETERIZED
@@ -51,6 +59,8 @@
     INTEGER, PARAMETER:: NK = 2, NP = 2, NO = 2, NW = NK * NP * NO
     INTEGER JK, JP, JO, JW
+    INTEGER, PARAMETER:: NA = 5  !number of realizations to get the phase speed
     REAL KMIN, KMAX ! Min and Max horizontal wavenumbers
-    REAL CMIN, CMAX ! Min and Max absolute ph. vel.
+    REAL CMAX ! standard deviation of the phase speed distribution
+    REAL RUWMAX,SAT  ! ONLINE SPECIFIED IN run.def
     REAL CPHA ! absolute PHASE VELOCITY frequency
     REAL ZK(NW, KLON) ! Horizontal wavenumber amplitude
@@ -86,5 +96,4 @@
 
     REAL H0 ! Characteristic Height of the atmosphere
-    REAL DZ ! Characteristic depth of the source!
     REAL PR, TR ! Reference Pressure and Temperature
 
@@ -110,13 +119,26 @@
     ! 1.2 Tuning parameters of V14
 
-    RDISS = 1. ! Diffusion parameter 
+    
+    RDISS = 1. ! Diffusion parameter
+    ! ONLINE 
+      RUWMAX=GWD_RANDO_RUWMAX
+      SAT=gwd_rando_sat
+    !END ONLINE
+    ! OFFLINE
+    ! RUWMAX= 1.75    ! Launched flux
+    ! SAT=0.25     ! Saturation parameter
+    ! END OFFLINE
 
     PRMAX = 20. / 24. /3600.
     ! maximum of rain for which our theory applies (in kg/m^2/s)
 
-    DZ = 1000. ! Characteristic depth of the source
+ ! Characteristic depth of the source
+    DZ = 1000.
     XLAUNCH=0.5 ! Parameter that control launching altitude
     XTROP=0.2 ! Parameter that control tropopause altitude
     DELTAT=24.*3600. ! Time scale of the waves (first introduced in 9b)
+    !  OFFLINE
+    !  DELTAT=DTIME
+    !  END OFFLINE
 
     KMIN = 2.E-5
@@ -124,6 +146,5 @@
 
     KMAX = 1.E-3 ! Max horizontal wavenumber
-    CMIN = 1. ! Min phase velocity
-    CMAX = 50. ! Max phase speed velocity
+    CMAX = 30. ! Max phase speed velocity
 
     TR = 240. ! Reference Temperature
@@ -135,9 +156,15 @@
     ZOISEC = 1.E-6 ! Security FOR 0 INTRINSIC FREQ
 
-    call assert(klon == (/size(pp, 1), size(tt, 1), size(uu, 1), &
-         size(vv, 1), size(prec), size(zustr), size(zvstr), size(d_u, 1), &
-         size(d_v, 1)/), "FLOTT_GWD_RANDO klon")
-    call assert(klev == (/size(pp, 2), size(tt, 2), size(uu, 2), &
-         size(vv, 2), size(d_u, 2), size(d_v, 2)/), "FLOTT_GWD_RANDO klev")
+    !ONLINE
+        call assert(klon == (/size(pp, 1), size(tt, 1), size(uu, 1), &
+         size(vv, 1), size(zustr), size(zvstr), size(d_u, 1), &
+         size(d_v, 1), &
+         size(east_gwstress, 1), size(west_gwstress, 1) /), &
+         "FLOTT_GWD_RANDO klon")
+     call assert(klev == (/size(pp, 2), size(tt, 2), size(uu, 2), &
+          size(vv, 2), size(d_u, 2), size(d_v, 2), &
+          size(east_gwstress,2), size(west_gwstress,2) /), &
+          "FLOTT_GWD_RANDO klev")
+    !END ONLINE
 
     IF(DELTAT < DTIME)THEN
@@ -186,5 +213,5 @@
             - TT(:, LL - 1)) / (ZH(:, LL) - ZH(:, LL - 1)) * RD / H0
     end DO
-    BVLOW = 0.5 * (TT(:, LTROP )+ TT(:, LAUNCH)) &
+    BVLOW(:) = 0.5 * (TT(:, LTROP )+ TT(:, LAUNCH)) &
          * RD**2 / RCPD / H0**2 + (TT(:, LTROP ) &
          - TT(:, LAUNCH))/(ZH(:, LTROP )- ZH(:, LAUNCH)) * RD / H0
@@ -201,4 +228,5 @@
     BV=MAX(SQRT(MAX(BV, 0.)), BVSEC)
     BVLOW=MAX(SQRT(MAX(BVLOW, 0.)), BVSEC)
+
 
     ! WINDS
@@ -230,5 +258,13 @@
                 ZK(JW, II) = KMIN + (KMAX - KMIN) * MOD(TT(II, JW) * 100., 1.)
                 ! Horizontal phase speed
-                CPHA = CMIN + (CMAX - CMIN) * MOD(TT(II, JW)**2, 1.)
+                CPHA = 0.
+                DO JJ = 1, NA
+                    CPHA = CPHA + &
+         CMAX*2.*(MOD(TT(II, JW+3*JJ)**2, 1.)-0.5)*SQRT(3.)/SQRT(NA*1.)
+                END DO
+                IF (CPHA.LT.0.)  THEN
+                   CPHA = -1.*CPHA
+                   ZP(JW,II) = ZP(JW,II) + RPI
+                ENDIF
                 ! Absolute frequency is imposed
                 ZO(JW, II) = CPHA * ZK(JW, II) 
@@ -238,5 +274,5 @@
                      + ZK(JW, II) * SIN(ZP(JW, II)) * VH(II, LAUNCH)
                 ! Momentum flux at launch lev 
-                RUW0(JW, II) = GWD_RANDO_RUWMAX
+                RUW0(JW, II) = RUWMAX
              ENDDO
           end DO
@@ -264,13 +300,13 @@
        ! tanh limitation to values above prmax:
        WWP(JW, :) = RUW0(JW, :) &
-            * (RD / RCPD / H0 * RLVTT * PRMAX * TANH(PREC / PRMAX))**2
+            * (RD / RCPD / H0 * RLVTT * PRMAX * TANH(PREC(:) / PRMAX))**2
 
        ! Factor related to the characteristics of the waves:
-       WWP(JW, :) = WWP(JW, :) * ZK(JW, :)**3 / KMIN / BVLOW &
+       WWP(JW, :) = WWP(JW, :) * ZK(JW, :)**3 / KMIN / BVLOW(:)  &
             / MAX(ABS(ZOP(JW, :)), ZOISEC)**3 
 
        ! Moderation by the depth of the source (dz here):
        WWP(JW, :) = WWP(JW, :) &
-            * EXP(- BVLOW**2 / MAX(ABS(ZOP(JW, :)), ZOISEC)**2 * ZK(JW, :)**2 &
+            * EXP(- BVLOW(:)**2 / MAX(ABS(ZOP(JW, :)), ZOISEC)**2 * ZK(JW, :)**2 &
             * DZ**2)
 
@@ -281,4 +317,5 @@
             * BV(:, LAUNCH) * SIN(ZP(JW, :)) * WWP(JW, :)**2
     end DO
+
 
     ! 4.2 Uniform values below the launching altitude
@@ -318,6 +355,6 @@
           WWP(JW, :) = min(WWP(JW, :), MAX(0., &
                SIGN(1., ZOP(JW, :) * ZOM(JW, :))) * ABS(ZOP(JW, :))**3 &
-               / BV(:, LL + 1) * EXP(- ZH(:, LL + 1) / H0) * GWD_RANDO_SAT**2 &
-               * KMIN**2 / ZK(JW, :)**4)
+               / BV(:, LL + 1) * EXP(- ZH(:, LL + 1) / H0) * KMIN**2  &
+               * SAT**2 / ZK(JW, :)**4)
        end DO
 
@@ -336,6 +373,13 @@
           RUW(:, LL + 1) = RUW(:, LL + 1) + RUWP(JW, :) 
           RVW(:, LL + 1) = RVW(:, LL + 1) + RVWP(JW, :) 
+          EAST_GWSTRESS(:, LL)=EAST_GWSTRESS(:, LL)+MAX(0.,RUWP(JW,:))/FLOAT(NW)
+          WEST_GWSTRESS(:, LL)=WEST_GWSTRESS(:, LL)+MIN(0.,RUWP(JW,:))/FLOAT(NW)
        end DO
     end DO
+! OFFLINE ONLY
+!   PRINT *,'SAT PROFILE:'
+!   DO LL=1,KLEV
+!   PRINT *,ZH(KLON/2,LL)/1000.,SAT*(2.+TANH(ZH(KLON/2,LL)/H0-8.))
+!   ENDDO
 
     ! 5 CALCUL DES TENDANCES:
@@ -350,4 +394,6 @@
        RUW(:, LL) = RUW(:, LAUNCH+1)
        RVW(:, LL) = RVW(:, LAUNCH+1)
+       EAST_GWSTRESS(:, LL)  = EAST_GWSTRESS(:, LAUNCH)
+       WEST_GWSTRESS(:, LL)  = WEST_GWSTRESS(:, LAUNCH)
     end DO
 
@@ -357,5 +403,6 @@
             RG * (RUW(:, LL + 1) - RUW(:, LL)) &
             / (PH(:, LL + 1) - PH(:, LL)) * DTIME
-       D_V(:, LL) = (1.-DTIME/DELTAT) * D_V(:, LL) + DTIME/DELTAT/REAL(NW) * &
+       ! NO AR-1 FOR MERIDIONAL TENDENCIES
+       D_V(:, LL) =                                            1./REAL(NW) * &
             RG * (RVW(:, LL + 1) - RVW(:, LL)) &
             / (PH(:, LL + 1) - PH(:, LL)) * DTIME
Index: /LMDZ5/branches/testing/libf/phylmd/flxtr.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/flxtr.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/flxtr.F90	(revision 2408)
@@ -25,6 +25,4 @@
   ! =====================================================================
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOECUMF.h"
Index: /LMDZ5/branches/testing/libf/phylmd/fonte_neige_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/fonte_neige_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/fonte_neige_mod.F90	(revision 2408)
@@ -63,5 +63,5 @@
     IF (error /= 0) THEN
        abort_message='Pb allocation run_off_lic'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
     run_off_lic_0(:) = restart_runoff(:) 
@@ -74,5 +74,5 @@
     IF (error /= 0) THEN
        abort_message='Pb allocation run_off_ter'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
     run_off_ter(:) = 0.
@@ -81,5 +81,5 @@
     IF (error /= 0) THEN
        abort_message='Pb allocation run_off_lic'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
     run_off_lic(:) = 0.
@@ -88,5 +88,5 @@
     IF (error /= 0) THEN
        abort_message='Pb allocation ffonte_global'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
     ffonte_global(:,:) = 0.0
@@ -95,5 +95,5 @@
     IF (error /= 0) THEN
        abort_message='Pb allocation fqfonte_global'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
     fqfonte_global(:,:) = 0.0
@@ -102,5 +102,5 @@
     IF (error /= 0) THEN
        abort_message='Pb allocation fqcalving_global'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
     fqcalving_global(:,:) = 0.0
@@ -141,5 +141,4 @@
 !   evap
 !
-  INCLUDE "dimensions.h"
   INCLUDE "YOETHF.h"
   INCLUDE "YOMCST.h"
Index: /LMDZ5/branches/testing/libf/phylmd/geo2atm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/geo2atm.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/geo2atm.F90	(revision 2408)
@@ -7,5 +7,4 @@
 
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'
   INCLUDE 'YOMCST.h'
 
Index: /LMDZ5/branches/testing/libf/phylmd/grid_noro_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/grid_noro_m.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/grid_noro_m.F90	(revision 2408)
@@ -0,0 +1,353 @@
+MODULE grid_noro_m
+!
+!*******************************************************************************
+
+  PRIVATE
+  PUBLIC :: grid_noro
+
+
+CONTAINS
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE grid_noro(xd,yd,zd,x,y,zphi,zmea,zstd,zsig,zgam,zthe,zpic,zval,mask)
+!
+!-------------------------------------------------------------------------------
+! Author: F. Lott (see also Z.X. Li, A. Harzallah et L. Fairhead)
+!-------------------------------------------------------------------------------
+! Purpose: Compute the Parameters of the SSO scheme as described in LOTT &MILLER
+!         (1997) and LOTT(1999).
+!-------------------------------------------------------------------------------
+! Comments:
+!  * Target points are on a rectangular grid:
+!      iim+1 latitudes including North and South Poles;
+!      jjm+1 longitudes, with periodicity jjm+1=1.
+!  * At the poles, the fields value is repeated jjm+1 time.
+!  * The parameters a,b,c,d represent the limits of the target gridpoint region.
+!    The means over this region are calculated from USN data, ponderated by a
+!    weight proportional to the surface occupated by the data inside the model
+!    gridpoint area. In most circumstances, this weight is the ratio between the
+!    surfaces of the USN gridpoint area and the model gridpoint area. 
+!
+!           (c)
+!        ----d-----
+!        | . . . .|
+!        |        |
+!     (b)a . * . .b(a)
+!        |        |
+!        | . . . .|
+!        ----c-----
+!           (d)
+!  * Hard-coded US Navy dataset dimensions (imdp=2160 ; jmdp=1080) have been
+!    removed (ALLOCATABLE used).
+!  * iext (currently 10% of imdp) represents the margin to ensure output cells
+!    on the edge are contained in input cells.
+!===============================================================================
+  USE assert_eq_m, ONLY: assert_eq
+  USE print_control_mod, ONLY: lunout
+  IMPLICIT NONE 
+  REAL, PARAMETER :: epsfra = 1.e-5
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL, INTENT(IN)  :: xd(:), yd(:)  !--- INPUT  COORDINATES     (imdp) (jmdp)
+  REAL, INTENT(IN)  :: zd(:,:)       !--- INPUT  FIELD           (imdp,jmdp)
+  REAL, INTENT(IN)  :: x(:), y(:)    !--- OUTPUT COORDINATES     (imar+1) (jmar)
+  REAL, INTENT(OUT) :: zphi(:,:)     !--- GEOPOTENTIAL           (imar+1,jmar)
+  REAL, INTENT(OUT) :: zmea(:,:)     !--- MEAN OROGRAPHY         (imar+1,jmar)
+  REAL, INTENT(OUT) :: zstd(:,:)     !--- STANDARD DEVIATION     (imar+1,jmar)
+  REAL, INTENT(OUT) :: zsig(:,:)     !--- SLOPE                  (imar+1,jmar)
+  REAL, INTENT(OUT) :: zgam(:,:)     !--- ANISOTROPY             (imar+1,jmar)
+  REAL, INTENT(OUT) :: zthe(:,:)     !--- SMALL AXIS ORIENTATION (imar+1,jmar)
+  REAL, INTENT(OUT) :: zpic(:,:)     !--- MAXIMUM ALTITITUDE     (imar+1,jmar)
+  REAL, INTENT(OUT) :: zval(:,:)     !--- MINIMUM ALTITITUDE     (imar+1,jmar)
+  REAL, INTENT(OUT) :: mask(:,:)     !--- MASK                   (imar+1,jmar)
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=256) :: modname="grid_noro"
+  REAL, ALLOCATABLE :: xusn(:), yusn(:)           ! dim (imdp+2*iext) (jmdp+2)
+  REAL, ALLOCATABLE :: zusn(:,:)                  ! dim (imdp+2*iext,jmdp+2)
+! CORRELATIONS OF OROGRAPHY GRADIENT              ! dim (imar+1,jmar)
+  REAL, ALLOCATABLE :: ztz(:,:), zxtzx(:,:), zytzy(:,:), zxtzy(:,:), weight(:,:)
+! CORRELATIONS OF USN OROGRAPHY GRADIENTS         ! dim (imar+2*iext,jmdp+2)
+  REAL, ALLOCATABLE :: zxtzxusn(:,:), zytzyusn(:,:), zxtzyusn(:,:)
+  REAL, ALLOCATABLE :: mask_tmp(:,:), zmea0(:,:)  ! dim (imar+1,jmar)
+  REAL, ALLOCATABLE :: num_tot(:,:), num_lan(:,:) ! dim (imax,jmax)
+  REAL, ALLOCATABLE :: a(:), b(:)                 ! dim (imax)
+  REAL, ALLOCATABLE :: c(:), d(:)                 ! dim (jmax)
+  LOGICAL :: masque_lu
+  INTEGER :: i, ii, imdp, imar, iext
+  INTEGER :: j, jj, jmdp, jmar, nn
+  REAL    :: xpi, zdeltax, zlenx, weighx, xincr,  zmeanor0
+  REAL    :: rad, zdeltay, zleny, weighy, masque, zmeasud0
+  REAL    :: zbordnor, zmeanor, zstdnor, zsignor, zweinor, zpicnor, zvalnor
+  REAL    :: zbordsud, zmeasud, zstdsud, zsigsud, zweisud, zpicsud, zvalsud
+  REAL    :: zbordest, zbordoue, xk, xl, xm, xp, xq, xw
+!-------------------------------------------------------------------------------
+  imdp=assert_eq(SIZE(xd),SIZE(zd,1),TRIM(modname)//" imdp")
+  jmdp=assert_eq(SIZE(yd),SIZE(zd,2),TRIM(modname)//" jmdp")
+  imar=assert_eq([SIZE(x),SIZE(zphi,1),SIZE(zmea,1),SIZE(zstd,1),SIZE(zsig,1), &
+                          SIZE(zgam,1),SIZE(zthe,1),SIZE(zpic,1),SIZE(zval,1), &
+                          SIZE(mask,1)],TRIM(modname)//" imar")-1
+  jmar=assert_eq([SIZE(y),SIZE(zphi,2),SIZE(zmea,2),SIZE(zstd,2),SIZE(zsig,2), &
+                          SIZE(zgam,2),SIZE(zthe,2),SIZE(zpic,2),SIZE(zval,2), &
+                          SIZE(mask,2)],TRIM(modname)//" jmar")
+!  IF(imar/=iim)   CALL abort_physic(TRIM(modname),'imar/=iim'  ,1)
+!  IF(jmar/=jjm+1) CALL abort_physic(TRIM(modname),'jmar/=jjm+1',1)
+  iext=imdp/10                                !--- OK up to 36 degrees cell
+  xpi = ACOS(-1.)
+  rad = 6371229.
+  zdeltay=2.*xpi/REAL(jmdp)*rad
+  WRITE(lunout,*)"*** Orography parameters at sub-cell scale ***"
+
+!--- ARE WE USING A READ MASK ?
+  masque_lu=ANY(mask/=-99999.); IF(.NOT.masque_lu) mask=0.0
+  WRITE(lunout,*)'Masque lu: ',masque_lu
+
+!--- EXTENSION OF THE INPUT DATABASE TO PROCEED COMPUTATIONS AT BOUNDARIES:
+  ALLOCATE(xusn(imdp+2*iext))
+  xusn(1     +iext:imdp  +iext)=xd(:)
+  xusn(1          :       iext)=xd(1+imdp-iext:imdp)-2.*xpi
+  xusn(1+imdp+iext:imdp+2*iext)=xd(1          :iext)+2.*xpi
+
+  ALLOCATE(yusn(jmdp+2))
+  yusn(1       )=yd(1)   +(yd(1)   -yd(2))
+  yusn(2:jmdp+1)=yd(:)
+  yusn(  jmdp+2)=yd(jmdp)+(yd(jmdp)-yd(jmdp-1))
+
+  ALLOCATE(zusn(imdp+2*iext,jmdp+2))
+  zusn(1       +iext:imdp  +iext,2:jmdp+1)=zd  (:                   ,     :)
+  zusn(1            :       iext,2:jmdp+1)=zd  (imdp-iext+1:imdp    ,     :)
+  zusn(1+imdp  +iext:imdp+2*iext,2:jmdp+1)=zd  (1:iext              ,     :)
+  zusn(1            :imdp/2+iext,       1)=zusn(1+imdp/2:imdp  +iext,     2)
+  zusn(1+imdp/2+iext:imdp+2*iext,       1)=zusn(1       :imdp/2+iext,     2)
+  zusn(1            :imdp/2+iext,  jmdp+2)=zusn(1+imdp/2:imdp  +iext,jmdp+1)
+  zusn(1+imdp/2+iext:imdp+2*iext,  jmdp+2)=zusn(1       :imdp/2+iext,jmdp+1)
+
+!--- COMPUTE LIMITS OF MODEL GRIDPOINT AREA (REGULAR GRID)
+  ALLOCATE(a(imar+1),b(imar+1))
+  b(1:imar)=(x(1:imar  )+ x(2:imar+1))/2.0
+  b(imar+1)= x(  imar+1)+(x(  imar+1)-x(imar))/2.0
+  a(1)=x(1)-(x(2)-x(1))/2.0
+  a(2:imar+1)= b(1:imar)
+
+  ALLOCATE(c(jmar),d(jmar))
+  d(1:jmar-1)=(y(1:jmar-1)+ y(2:jmar))/2.0
+  d(  jmar  )= y(  jmar  )+(y(  jmar)-y(jmar-1))/2.0
+  c(1)=y(1)-(y(2)-y(1))/2.0
+  c(2:jmar)=d(1:jmar-1)
+
+!--- INITIALIZATIONS:
+  ALLOCATE(weight(imar+1,jmar)); weight(:,:)= 0.0
+  ALLOCATE(zxtzx (imar+1,jmar)); zxtzx (:,:)= 0.0
+  ALLOCATE(zytzy (imar+1,jmar)); zytzy (:,:)= 0.0
+  ALLOCATE(zxtzy (imar+1,jmar)); zxtzy (:,:)= 0.0
+  ALLOCATE(ztz   (imar+1,jmar)); ztz   (:,:)= 0.0
+  zmea(:,:)= 0.0
+  zpic(:,:)=-1.E+10
+  zval(:,:)= 1.E+10
+
+!--- COMPUTE SLOPES CORRELATIONS ON USN GRID
+! CORRELATIONS OF USN OROGRAPHY GRADIENTS  ! dim (imdp+2*iext,jmdp+2)
+  ALLOCATE(zytzyusn(imdp+2*iext,jmdp+2)); zytzyusn(:,:)=0.0
+  ALLOCATE(zxtzxusn(imdp+2*iext,jmdp+2)); zxtzxusn(:,:)=0.0
+  ALLOCATE(zxtzyusn(imdp+2*iext,jmdp+2)); zxtzyusn(:,:)=0.0
+  DO j = 2, jmdp+1
+    zdeltax=zdeltay*cos(yusn(j))
+    DO i = 2, imdp+2*iext-1
+      zytzyusn(i,j)=(zusn(i,j+1)-zusn(i,j-1))**2/zdeltay**2
+      zxtzxusn(i,j)=(zusn(i+1,j)-zusn(i-1,j))**2/zdeltax**2
+      zxtzyusn(i,j)=(zusn(i,j+1)-zusn(i,j-1))   /zdeltay  &
+     &             *(zusn(i+1,j)-zusn(i-1,j))   /zdeltax
+    END DO
+  END DO
+
+!--- SUMMATION OVER GRIDPOINT AREA
+  zleny=xpi/REAL(jmdp)*rad
+  xincr=xpi/REAL(jmdp)/2.
+  ALLOCATE(num_tot(imar+1,jmar)); num_tot(:,:)=0.
+  ALLOCATE(num_lan(imar+1,jmar)); num_lan(:,:)=0.
+  DO ii = 1, imar+1
+    DO jj = 1, jmar
+      DO j = 2,jmdp+1 
+        zlenx  =zleny  *COS(yusn(j))
+        zdeltax=zdeltay*COS(yusn(j))
+        zbordnor=(xincr+c(jj)-yusn(j))*rad
+        zbordsud=(xincr-d(jj)+yusn(j))*rad
+        weighy=AMAX1(0.,AMIN1(zbordnor,zbordsud,zleny))
+        IF(weighy==0.) CYCLE
+        DO i = 2, imdp+2*iext-1
+          zbordest=(xusn(i)-a(ii)+xincr)*rad*COS(yusn(j))
+          zbordoue=(b(ii)+xincr-xusn(i))*rad*COS(yusn(j))
+          weighx=AMAX1(0.,AMIN1(zbordest,zbordoue,zlenx))
+          IF(weighx==0.) CYCLE
+          num_tot(ii,jj)=num_tot(ii,jj)+1.0
+          IF(zusn(i,j)>=1.)num_lan(ii,jj)=num_lan(ii,jj)+1.0
+          weight(ii,jj)=weight(ii,jj)+weighx*weighy
+          zxtzx(ii,jj)=zxtzx(ii,jj)+zxtzxusn(i,j)*weighx*weighy
+          zytzy(ii,jj)=zytzy(ii,jj)+zytzyusn(i,j)*weighx*weighy
+          zxtzy(ii,jj)=zxtzy(ii,jj)+zxtzyusn(i,j)*weighx*weighy
+          ztz  (ii,jj)=  ztz(ii,jj)+zusn(i,j)*zusn(i,j)*weighx*weighy
+          zmea (ii,jj)= zmea(ii,jj)+zusn(i,j)*weighx*weighy !--- MEAN
+          zpic (ii,jj)=AMAX1(zpic(ii,jj),zusn(i,j))         !--- PEAKS
+          zval (ii,jj)=AMIN1(zval(ii,jj),zusn(i,j))         !--- VALLEYS
+        END DO
+      END DO
+    END DO
+  END DO
+
+!--- COMPUTE PARAMETERS NEEDED BY LOTT & MILLER (1997) AND LOTT (1999) SSO SCHEME
+  IF(.NOT.masque_lu) THEN
+    WHERE(weight(:,1:jmar-1)/=0.0) mask=num_lan(:,:)/num_tot(:,:)
+  END IF
+  nn=COUNT(weight(:,1:jmar-1)==0.0)
+  IF(nn/=0) WRITE(lunout,*)'Problem with weight ; vanishing occurrences: ',nn
+  WHERE(weight(:,:)/=0.0)
+    zmea (:,:)=zmea (:,:)/weight(:,:)
+    zxtzx(:,:)=zxtzx(:,:)/weight(:,:)
+    zytzy(:,:)=zytzy(:,:)/weight(:,:)
+    zxtzy(:,:)=zxtzy(:,:)/weight(:,:)
+    ztz  (:,:)=ztz  (:,:)/weight(:,:)
+    zstd (:,:)=ztz  (:,:)-zmea(:,:)**2
+  END WHERE
+  WHERE(zstd(:,:)<0) zstd(:,:)=0.
+  zstd (:,:)=SQRT(zstd(:,:))
+
+!--- CORRECT VALUES OF HORIZONTAL SLOPE NEAR THE POLES:
+  zxtzx(:,   1)=zxtzx(:,     2)
+  zxtzx(:,jmar)=zxtzx(:,jmar-1)
+  zxtzy(:,   1)=zxtzy(:,     2)
+  zxtzy(:,jmar)=zxtzy(:,jmar-1)
+  zytzy(:,   1)=zytzy(:,     2)
+  zytzy(:,jmar)=zytzy(:,jmar-1)
+
+!=== FILTERS TO SMOOTH OUT FIELDS FOR INPUT INTO SSO SCHEME.
+!--- FIRST FILTER, MOVING AVERAGE OVER 9 POINTS.
+!-------------------------------------------------------------------------------
+  ALLOCATE(zmea0(imar+1,jmar))
+  zmea0(:,:)=zmea(:,:)                           ! GK211005 (CG) UNSMOOTHED TOPO
+  CALL MVA9(zmea);  CALL MVA9(zstd);  CALL MVA9(zpic);  CALL MVA9(zval)
+  CALL MVA9(zxtzx); CALL MVA9(zxtzy); CALL MVA9(zytzy)
+
+!--- MASK BASED ON GROUND MAXIMUM, 10% THRESHOLD. (SURFACE PARAMS MEANINGLESS)
+  ALLOCATE(mask_tmp(imar+1,jmar)); mask_tmp(:,:)=0.0
+  WHERE(mask>=0.1) mask_tmp = 1.
+  WHERE(weight(:,:)/=0.0)
+!   zphi (:,:)= mask_tmp(:,:)*zmea (:,:) ! GK211005 (CG) not necessarly smoothed
+    zphi (:,:)= mask_tmp(:,:)*zmea0(:,:)
+    zmea0(:,:)= mask_tmp(:,:)*zmea0(:,:)
+    zmea (:,:)= mask_tmp(:,:)*zmea (:,:)
+    zpic (:,:)= mask_tmp(:,:)*zpic (:,:)
+    zval (:,:)= mask_tmp(:,:)*zval (:,:)
+    zstd (:,:)= mask_tmp(:,:)*zstd (:,:)
+  END WHERE
+  DO ii = 1, imar
+    DO jj = 1, jmar
+      IF (weight(ii,jj)/=0.0) THEN
+      !--- Coefficients K, L et M:
+        xk=(zxtzx(ii,jj)+zytzy(ii,jj))/2.
+        xl=(zxtzx(ii,jj)-zytzy(ii,jj))/2.
+        xm=zxtzy(ii,jj)
+        xp=xk-SQRT(xl**2+xm**2)
+        xq=xk+SQRT(xl**2+xm**2)
+        xw=1.e-8
+        IF(xp<=xw) xp=0.
+        IF(xq<=xw) xq=xw
+        IF(ABS(xm)<=xw) xm=xw*SIGN(1.,xm)
+      !--- SLOPE
+        zsig(ii,jj)=SQRT(xq)*mask_tmp(ii,jj)
+      !---ISOTROPY
+        zgam(ii,jj)=xp/xq*mask_tmp(ii,jj)
+      !--- THETA ANGLE
+        zthe(ii,jj)=57.29577951*ATAN2(xm,xl)/2.*mask_tmp(ii,jj)
+      END IF
+    END DO
+  END DO
+  WRITE(lunout,*)'  MEAN ORO:' ,MAXVAL(zmea)
+  WRITE(lunout,*)'  ST. DEV.:' ,MAXVAL(zstd)
+  WRITE(lunout,*)'  PENTE:'    ,MAXVAL(zsig)
+  WRITE(lunout,*)'  ANISOTROP:',MAXVAL(zgam)
+  WRITE(lunout,*)'  ANGLE:'    ,MINVAL(zthe),MAXVAL(zthe)
+  WRITE(lunout,*)'  pic:'      ,MAXVAL(zpic)
+  WRITE(lunout,*)'  val:'      ,MAXVAL(zval)
+      
+!--- Values at poles
+  zmea0(imar+1,:)=zmea0(1,:)
+  zmea (imar+1,:)=zmea (1,:)
+  zphi (imar+1,:)=zphi (1,:)
+  zpic (imar+1,:)=zpic (1,:)
+  zval (imar+1,:)=zval (1,:)
+  zstd (imar+1,:)=zstd (1,:)
+  zsig (imar+1,:)=zsig (1,:)
+  zgam (imar+1,:)=zgam (1,:)
+  zthe (imar+1,:)=zthe (1,:)
+
+  zweinor =SUM(weight(1:imar,   1),DIM=1)
+  zweisud =SUM(weight(1:imar,jmar),DIM=1)
+  zmeanor0=SUM(weight(1:imar,   1)*zmea0(1:imar,   1),DIM=1)
+  zmeasud0=SUM(weight(1:imar,jmar)*zmea0(1:imar,jmar),DIM=1)
+  zmeanor =SUM(weight(1:imar,   1)*zmea (1:imar,   1),DIM=1)
+  zmeasud =SUM(weight(1:imar,jmar)*zmea (1:imar,jmar),DIM=1)
+  zstdnor =SUM(weight(1:imar,   1)*zstd (1:imar,   1),DIM=1)
+  zstdsud =SUM(weight(1:imar,jmar)*zstd (1:imar,jmar),DIM=1)
+  zsignor =SUM(weight(1:imar,   1)*zsig (1:imar,   1),DIM=1)
+  zsigsud =SUM(weight(1:imar,jmar)*zsig (1:imar,jmar),DIM=1)
+  zpicnor =SUM(weight(1:imar,   1)*zpic (1:imar,   1),DIM=1)
+  zpicsud =SUM(weight(1:imar,jmar)*zpic (1:imar,jmar),DIM=1)
+  zvalnor =SUM(weight(1:imar,   1)*zval (1:imar,   1),DIM=1)
+  zvalsud =SUM(weight(1:imar,jmar)*zval (1:imar,jmar),DIM=1)
+
+  zmea(:,1)=zmeanor /zweinor; zmea(:,jmar)=zmeasud /zweisud
+!  zphi(:,1)=zmeanor0/zweinor; zphi(:,jmar)=zmeasud0/zweisud   TO COMMIT
+  zphi(:,1)=zmeanor /zweinor; zphi(:,jmar)=zmeasud /zweisud
+  zpic(:,1)=zpicnor /zweinor; zpic(:,jmar)=zpicsud /zweisud
+  zval(:,1)=zvalnor /zweinor; zval(:,jmar)=zvalsud /zweisud
+  zstd(:,1)=zstdnor /zweinor; zstd(:,jmar)=zstdsud /zweisud
+  zsig(:,1)=zsignor /zweinor; zsig(:,jmar)=zsigsud /zweisud
+  zgam(:,1)=1.;               zgam(:,jmar)=1.
+  zthe(:,1)=0.;               zthe(:,jmar)=0.
+
+END SUBROUTINE grid_noro
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE MVA9(x)
+!
+!-------------------------------------------------------------------------------
+  IMPLICIT NONE
+! MAKE A MOVING AVERAGE OVER 9 GRIDPOINTS OF THE X FIELDS
+!-------------------------------------------------------------------------------
+! Arguments:
+  REAL, INTENT(INOUT) :: x(:,:)
+!-------------------------------------------------------------------------------
+! Local variables:
+  REAL    :: xf(SIZE(x,DIM=1),SIZE(x,DIM=2)), WEIGHTpb(-1:1,-1:1)
+  INTEGER :: i, j, imar, jmar
+!-------------------------------------------------------------------------------
+  WEIGHTpb=RESHAPE([((1./REAL((1+i**2)*(1+j**2)),i=-1,1),j=-1,1)],SHAPE=[3,3])
+  WEIGHTpb=WEIGHTpb/SUM(WEIGHTpb)
+  imar=SIZE(X,DIM=1); jmar=SIZE(X,DIM=2)
+  DO j=2,jmar-1
+    DO i=2,imar-1
+      xf(i,j)=SUM(x(i-1:i+1,j-1:j+1)*WEIGHTpb(:,:))
+    END DO
+  END DO
+  DO j=2,jmar-1
+    xf(1,j)=SUM(x(imar-1,j-1:j+1)*WEIGHTpb(-1,:))
+    xf(1,j)=xf(1,j)+SUM(x(1:2,j-1:j+1)*WEIGHTpb(0:1,-1:1))
+    xf(imar,j)=xf(1,j)
+  END DO
+  xf(:,   1)=xf(:,     2)
+  xf(:,jmar)=xf(:,jmar-1)
+  x(:,:)=xf(:,:)
+
+END SUBROUTINE MVA9
+!
+!-------------------------------------------------------------------------------
+
+
+END MODULE grid_noro_m
+
Index: /LMDZ5/branches/testing/libf/phylmd/hbtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/hbtm.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/hbtm.F90	(revision 2408)
@@ -41,6 +41,4 @@
 
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   REAL rlvcp, reps
Index: /LMDZ5/branches/testing/libf/phylmd/hbtm2l.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/hbtm2l.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/hbtm2l.F90	(revision 2408)
@@ -29,6 +29,4 @@
   ! * re-ecriture complete Alain Mars 2012 dans LMDZ5V5           *
   ! ***************************************************************
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   REAL rlvcp, reps
Index: /LMDZ5/branches/testing/libf/phylmd/hgardfou.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/hgardfou.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/hgardfou.F90	(revision 2408)
@@ -5,11 +5,10 @@
   USE phys_state_var_mod
   USE indice_sol_mod
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
   ! ======================================================================
   ! Verifier la temperature
   ! ======================================================================
-  include "dimensions.h"
   include "YOMCST.h"
-  include "iniprint.h"
   REAL t(klon, klev), tsol(klon, nbsrf)
   CHARACTER(len=*), intent(in):: text
@@ -129,5 +128,5 @@
   END DO
 
-!  IF (.NOT. ok) CALL abort_gcm(modname, text, 1)
+!  IF (.NOT. ok) CALL abort_physic(modname, text, 1)
   IF (.NOT. ok) abortphy=1
 
Index: /LMDZ5/branches/testing/libf/phylmd/hines_gwd.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/hines_gwd.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/hines_gwd.F90	(revision 2408)
@@ -16,6 +16,4 @@
   IMPLICIT NONE
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOEGWD.h"
   include "YOMCST.h"
Index: /LMDZ5/branches/testing/libf/phylmd/histo_o500_pctau.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/histo_o500_pctau.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/histo_o500_pctau.F90	(revision 2408)
@@ -8,6 +8,4 @@
   INTEGER :: ij, k, l, nw
   INTEGER :: nreg, nbreg
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   INTEGER, PARAMETER :: kmax = 8, lmax = 8
   INTEGER, PARAMETER :: kmaxm1 = kmax - 1, lmaxm1 = lmax - 1
Index: /LMDZ5/branches/testing/libf/phylmd/homogene.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/homogene.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/homogene.F90	(revision 2408)
@@ -18,6 +18,4 @@
   ! dv:   output, incrementation pour v
   ! ==============================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
 
   REAL paprs(klon, klev+1)
Index: /LMDZ5/branches/testing/libf/phylmd/hydrol.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/hydrol.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/hydrol.F90	(revision 2408)
@@ -25,6 +25,4 @@
   ! snow: couverture neigeuse
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/infotrac_phy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/infotrac_phy.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/infotrac_phy.F90	(revision 2408)
@@ -0,0 +1,209 @@
+
+! $Id: $
+
+MODULE infotrac_phy
+
+! Infotrac for physics; for now contains the same information as infotrac for
+! the dynamics (could be further cleaned) and is initialized using values
+! provided by the dynamics
+
+! nqtot : total number of tracers and higher order of moment, water vapor and liquid included
+  INTEGER, SAVE :: nqtot
+!$OMP THREADPRIVATE(nqtot)
+
+!CR: on ajoute le nombre de traceurs de l eau
+  INTEGER, SAVE :: nqo
+!$OMP THREADPRIVATE(nqo)
+
+! nbtr : number of tracers not including higher order of moment or water vapor or liquid
+!        number of tracers used in the physics
+  INTEGER, SAVE :: nbtr
+!$OMP THREADPRIVATE(nbtr)
+
+! CRisi: nb traceurs pères= directement advectés par l'air
+  INTEGER, SAVE :: nqperes
+
+! Name variables
+  CHARACTER(len=20), ALLOCATABLE, DIMENSION(:), SAVE :: tname ! tracer short name for restart and diagnostics
+  CHARACTER(len=23), ALLOCATABLE, DIMENSION(:), SAVE :: ttext ! tracer long name for diagnostics
+!$OMP THREADPRIVATE(tname,ttext)
+
+!! iadv  : index of trasport schema for each tracer
+!  INTEGER, ALLOCATABLE, DIMENSION(:), SAVE    :: iadv
+
+! niadv : vector keeping the coorspondance between all tracers(nqtot) treated in the 
+!         dynamic part of the code and the tracers (nbtr+2) used in the physics part of the code. 
+  INTEGER, ALLOCATABLE, DIMENSION(:), SAVE    :: niadv ! equivalent dyn / physique
+!$OMP THREADPRIVATE(niadv)
+
+! CRisi: tableaux de fils
+  INTEGER, ALLOCATABLE, DIMENSION(:), SAVE    :: nqfils
+  INTEGER, ALLOCATABLE, DIMENSION(:), SAVE    :: nqdesc ! nombres de fils + nombre de tous les petits fils sur toutes les générations
+  INTEGER, SAVE :: nqdesc_tot
+  INTEGER, ALLOCATABLE, DIMENSION(:,:), SAVE    :: iqfils
+  INTEGER, ALLOCATABLE, DIMENSION(:), SAVE    :: iqpere
+!$OMP THREADPRIVATE(nqfils,nqdesc,nqdesc_tot,iqfils,iqpers)
+
+! conv_flg(it)=0 : convection desactivated for tracer number it 
+  INTEGER, ALLOCATABLE, DIMENSION(:), SAVE  :: conv_flg
+!$OMP THREADPRIVATE(conv_flg)
+
+! pbl_flg(it)=0  : boundary layer diffusion desactivaded for tracer number it 
+  INTEGER, ALLOCATABLE, DIMENSION(:), SAVE  :: pbl_flg
+!$OMP THREADPRIVATE(pbl_flg)
+
+  CHARACTER(len=4),SAVE :: type_trac
+!$OMP THREADPRIVATE(type_trac)
+  CHARACTER(len=8),DIMENSION(:),ALLOCATABLE, SAVE :: solsym
+!$OMP THREADPRIVATE(solsym)
+   
+    ! CRisi: cas particulier des isotopes
+    LOGICAL,SAVE :: ok_isotopes,ok_iso_verif,ok_isotrac,ok_init_iso
+!$OMP THREADPRIVATE(ok_isotopes,ok_iso_verif,ok_isotrac,ok_init_iso)
+    INTEGER :: niso_possibles   
+    PARAMETER ( niso_possibles=5)
+    real, DIMENSION (niso_possibles),SAVE :: tnat,alpha_ideal
+!$OMP THREADPRIVATE(tnat,alpha_ideal)
+    LOGICAL, DIMENSION(niso_possibles),SAVE ::  use_iso
+!$OMP THREADPRIVATE(use_iso)
+    INTEGER, ALLOCATABLE, DIMENSION(:,:), SAVE ::  iqiso ! donne indice iq en fn de (ixt,phase) 
+!$OMP THREADPRIVATE(iqiso)
+    INTEGER, ALLOCATABLE, DIMENSION(:), SAVE ::  iso_num ! donne numéro iso entre 1 et niso_possibles en fn de nqtot
+!$OMP THREADPRIVATE(iso_num)
+    INTEGER, ALLOCATABLE, DIMENSION(:), SAVE ::  iso_indnum ! donne numéro iso entre 1 et niso effectif en fn de nqtot
+!$OMP THREADPRIVATE(iso_indnum)
+    INTEGER, ALLOCATABLE, DIMENSION(:), SAVE ::  zone_num ! donne numéro de la zone de tracage en fn de nqtot
+!$OMP THREADPRIVATE(zone_num)
+    INTEGER, ALLOCATABLE, DIMENSION(:), SAVE ::  phase_num ! donne numéro de la zone de tracage en fn de nqtot
+!$OMP THREADPRIVATE(phase_num)
+    INTEGER, DIMENSION(niso_possibles), SAVE :: indnum_fn_num ! donne indice entre entre 1 et niso en fonction du numéro d isotope entre 1 et niso_possibles
+!$OMP THREADPRIVATE(indnum_fn_num)
+    INTEGER, ALLOCATABLE, DIMENSION(:,:), SAVE ::  index_trac ! numéro ixt en fn izone, indnum entre 1 et niso
+!$OMP THREADPRIVATE(index_trac)
+    INTEGER,SAVE :: niso,ntraceurs_zone,ntraciso
+!$OMP THREADPRIVATE(niso,ntraceurs_zone,ntraciso)
+ 
+CONTAINS
+
+  SUBROUTINE init_infotrac_phy(nqtot_,nqo_,nbtr_,tname_,ttext_,type_trac_,&
+                               niadv_,conv_flg_,pbl_flg_,solsym_,&
+                               nqfils_,nqdesc_,nqdesc_tot_,iqfils_,iqpere_,&
+                               ok_isotopes_,ok_iso_verif_,ok_isotrac_,&
+                               ok_init_iso_,niso_possibles_,tnat_,&
+                               alpha_ideal_,use_iso_,iqiso_,iso_num_,&
+                               iso_indnum_,zone_num_,phase_num_,&
+                               indnum_fn_num_,index_trac_,&
+                               niso_,ntraceurs_zone_,ntraciso_)
+  ! transfer information on tracers from dynamics to physics
+  USE print_control_mod, ONLY: prt_level, lunout
+  IMPLICIT NONE
+    INTEGER,INTENT(IN) :: nqtot_
+    INTEGER,INTENT(IN) :: nqo_
+    INTEGER,INTENT(IN) :: nbtr_
+    CHARACTER(len=20),INTENT(IN) :: tname_(nqtot_) ! tracer short name for restart and diagnostics
+    CHARACTER(len=23),INTENT(IN) :: ttext_(nqtot_) ! tracer long name for diagnostics
+    CHARACTER(len=4),INTENT(IN) :: type_trac_
+    INTEGER,INTENT(IN) :: niadv_ (nqtot_) ! equivalent dyn / physique
+    INTEGER,INTENT(IN) :: conv_flg_(nbtr_)
+    INTEGER,INTENT(IN) :: pbl_flg_(nbtr_)
+    CHARACTER(len=8),INTENT(IN) :: solsym_(nbtr_)
+    ! Isotopes:
+    INTEGER,INTENT(IN) :: nqfils_(nqtot_)
+    INTEGER,INTENT(IN) :: nqdesc_(nqtot_)
+    INTEGER,INTENT(IN) :: nqdesc_tot_
+    INTEGER,INTENT(IN) :: iqfils_(nqtot_,nqtot_)
+    INTEGER,INTENT(IN) :: iqpere_(nqtot_)
+    LOGICAL,INTENT(IN) :: ok_isotopes_
+    LOGICAL,INTENT(IN) :: ok_iso_verif_
+    LOGICAL,INTENT(IN) :: ok_isotrac_
+    LOGICAL,INTENT(IN) :: ok_init_iso_
+    INTEGER,INTENT(IN) :: niso_possibles_
+    REAL,INTENT(IN) :: tnat_(niso_possibles_)
+    REAL,INTENT(IN) :: alpha_ideal_(niso_possibles_)
+    LOGICAL,INTENT(IN) :: use_iso_(niso_possibles_)
+    INTEGER,INTENT(IN) :: iqiso_(ntraciso_,nqo_)
+    INTEGER,INTENT(IN) :: iso_num_(nqtot_)
+    INTEGER,INTENT(IN) :: iso_indnum_(nqtot_)
+    INTEGER,INTENT(IN) :: zone_num_(nqtot_)
+    INTEGER,INTENT(IN) :: phase_num_(nqtot_)
+    INTEGER,INTENT(IN) :: indnum_fn_num_(niso_possibles_)
+    INTEGER,INTENT(IN) :: index_trac_(ntraceurs_zone_,niso_)
+    INTEGER,INTENT(IN) :: niso_
+    INTEGER,INTENT(IN) :: ntraceurs_zone_
+    INTEGER,INTENT(IN) :: ntraciso_
+
+    CHARACTER(LEN=30) :: modname="init_infotrac_phy"
+
+    nqtot=nqtot_
+    nqo=nqo_
+    nbtr=nbtr_
+    ALLOCATE(tname(nqtot))
+    tname(:) = tname_(:)
+    ALLOCATE(ttext(nqtot))
+    ttext(:) = ttext_(:)
+    type_trac = type_trac_
+    ALLOCATE(niadv(nqtot))
+    niadv(:)=niadv_(:)
+    ALLOCATE(conv_flg(nbtr))
+    conv_flg(:)=conv_flg_(:)
+    ALLOCATE(pbl_flg(nbtr))
+    pbl_flg(:)=pbl_flg_(:)
+    ALLOCATE(solsym(nbtr))
+    solsym(:)=solsym_(:)
+  
+    IF(prt_level.ge.1) THEN
+      write(lunout,*) TRIM(modname)//": nqtot,nqo,nbtr",nqtot,nqo,nbtr
+    ENDIF
+    
+    ! Isotopes:
+    
+    ! First check that the "niso_possibles" has the correct value
+    IF (niso_possibles.ne.niso_possibles_) THEN
+      CALL abort_physic(modname,&
+           "wrong value for parameter niso_possibles in infotrac_phy",1)
+    ENDIF
+    
+    ok_isotopes=ok_isotopes_
+    ok_iso_verif=ok_iso_verif_
+    ok_isotrac=ok_isotrac_
+    ok_init_iso=ok_init_iso_
+    
+    niso=niso_
+    ntraceurs_zone=ntraceurs_zone_
+    ntraciso=ntraciso_
+    
+    IF (ok_isotopes) THEN
+      ALLOCATE(nqfils(nqtot))
+      nqfils(:)=nqfils_(:)
+      ALLOCATE(nqdesc(nqtot))
+      nqdesc(:)=nqdesc_(:)
+      nqdesc_tot=nqdesc_tot_
+      ALLOCATE(iqfils(nqtot,nqtot))
+      iqfils(:,:)=iqfils_(:,:)
+      ALLOCATE(iqpere(nqtot))
+      iqpere(:)=iqpere_(:)
+    
+      tnat(:)=tnat_(:)
+      alpha_ideal(:)=alpha_ideal_(:)
+      use_iso(:)=use_iso_(:)
+    
+      ALLOCATE(iqiso(ntraciso,nqo))
+      iqiso(:,:)=iqiso_(:,:)
+      ALLOCATE(iso_num(nqtot))
+      iso_num(:)=iso_num_(:)
+      ALLOCATE(iso_indnum(nqtot))
+      iso_indnum(:)=iso_indnum_(:)
+      ALLOCATE(zone_num(nqtot))
+      zone_num(:)=zone_num_(:)
+      ALLOCATE(phase_num(nqtot))
+      phase_num(:)=phase_num_(:)
+      
+      indnum_fn_num(:)=indnum_fn_num_(:)
+      
+      ALLOCATE(index_trac(ntraceurs_zone,niso))
+      index_trac(:,:)=index_trac_(:,:)
+    ENDIF ! of IF(ok_isotopes)
+  
+  END SUBROUTINE init_infotrac_phy
+
+END MODULE infotrac_phy
Index: /LMDZ5/branches/testing/libf/phylmd/ini_histday_seri.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ini_histday_seri.h	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/ini_histday_seri.h	(revision 2408)
@@ -7,5 +7,5 @@
       IF (type_run.EQ."AMIP") THEN
 !
-       zstophy = dtime
+       zstophy = pdtphys
        zout = ecrit_day
 !
@@ -13,13 +13,13 @@
          CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
 !
-         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon,zx_lon)
-         DO i = 1, iim
+         CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlon,zx_lon)
+         DO i = 1, nbp_lon
             zx_lon(i,1) = rlon(i+1)
-            zx_lon(i,jjmp1) = rlon(i+1)
+            zx_lon(i,nbp_lat) = rlon(i+1)
          ENDDO
          DO ll=1,klev
             znivsig(ll)=REAL(ll)
          ENDDO
-         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
+         CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlat,zx_lat)
 !
          imin_debut=1 
@@ -29,5 +29,5 @@
 !
          CALL histbeg("histday_seri.nc",  &
-                       iim,zx_lon(:,1), jjmp1,zx_lat(1,:), &
+                       nbp_lon,zx_lon(:,1),nbp_lat,zx_lat(1,:), &
                        imin_debut,nbpti,jmin_debut,nbptj, &
                        itau_phy, zjulian, dtime, &
@@ -40,15 +40,15 @@
          CALL histdef(nid_day_seri, "bilTOA",  &
                       "Net radiation at model top", "W/m2", &
-                      iim,jjmp1,nhori, 1,1,1, -99, 32,  &
+                      nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32,  &
                       "ave(X)", zstophy,zout)
 !
          CALL histdef(nid_day_seri, "bils",  &
                       "Net downward energy flux at surface","W/m2", &
-                      iim,jjmp1,nhori, 1,1,1, -99, 32,  &
+                      nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32,  &
                       "ave(X)", zstophy,zout)
 !
          CALL histdef(nid_day_seri, "ecin",  &
                       "Total kinetic energy (per unit area)","J/m2", &
-                      iim,jjmp1,nhori, 1,1,1, -99, 32, &
+                      nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32, &
                       "ave(X)", zstophy,zout)
 !
@@ -59,15 +59,15 @@
                      "Total relative angular momentum (per unit area)", &
                      "kg/s", &
-                      iim,jjmp1,nhori, 1,1,1, -99, 32, &
+                      nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32, &
                       "ave(X)", zstophy,zout)
 !
          CALL histdef(nid_day_seri, "frictor",  &
                      "Friction torque (per unit area)", "N/m", &
-                      iim,jjmp1,nhori, 1,1,1, -99, 32, &
+                      nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32, &
                       "ave(X)", zstophy,zout)
 !
          CALL histdef(nid_day_seri, "mountor",  &
                      "Mountain torque (per unit area)", "N/m", &
-                      iim,jjmp1,nhori, 1,1,1, -99, 32, &
+                      nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32, &
                       "ave(X)", zstophy,zout)
 !
@@ -77,10 +77,10 @@
                      "Axial angular momentum (per unit area)", &
                      "kg/s", &
-                      iim,jjmp1,nhori, 1,1,1, -99, 32, &
+                      nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32, &
                       "ave(X)", zstophy,zout)
 !
          CALL histdef(nid_day_seri, "torsfc",  &
               "Total surface torque (including mountain torque)", "N/m", &
-                      iim,jjmp1,nhori, 1,1,1, -99, 32, &
+                      nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32, &
                       "ave(X)", zstophy,zout)
 !
@@ -89,10 +89,10 @@
          CALL histdef(nid_day_seri, "tamv",  &
                       "Temperature (mass-weighted vert. ave)", "K", &
-                      iim,jjmp1,nhori, 1,1,1, -99, 32, &
+                      nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32, &
                       "ave(X)", zstophy,zout)
 !
          CALL histdef(nid_day_seri, "psol",  &
                       "Surface pressure", "Pa", &
-                      iim,jjmp1,nhori, 1,1,1, -99, 32,  &
+                      nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32,  &
                       "ave(X)", zstophy,zout)
 !
@@ -100,5 +100,5 @@
                       "Evaporation and sublimation (per unit area)",  &
                       "kg/(m2*s)", &
-                      iim,jjmp1,nhori, 1,1,1, -99, 32,  &
+                      nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32,  &
                       "ave(X)", zstophy,zout)
 !
@@ -106,5 +106,5 @@
 !    .         "SnowFrac", 
 !    .         "Snow-covered area ", "%",  
-!    .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+!    .         nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32,
 !    .         "ave(X)", zstophy,zout)
 !
@@ -113,5 +113,5 @@
 !IM 191104  .                "Snow Depth (water equivalent)", "kg/m2",
 !    .                "Snow Mass", "kg/m2",
-!    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+!    .                nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32, 
 !    .               "ave(X)", zstophy,zout)
 !
@@ -119,5 +119,5 @@
                "tsol_"//clnsurf(is_oce),  &
                "SST over open (ice-free) ocean ", "K",   &
-               iim,jjmp1,nhori, 1,1,1, -99, 32, &
+               nbp_lon,nbp_lat,nhori, 1,1,1, -99, 32, &
                "ave(X)", zstophy,zout)
 !
Index: /LMDZ5/branches/testing/libf/phylmd/ini_paramLMDZ_phy.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ini_paramLMDZ_phy.h	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/ini_paramLMDZ_phy.h	(revision 2408)
@@ -9,5 +9,5 @@
       if (is_mpi_root) then
 !
-       zstophy = dtime
+       zstophy = pdtphys
        zout = mth_len*un_jour
 !
@@ -15,12 +15,12 @@
        CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
 !
-       CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon_glo,zx_lon)
-       if (iim.gt.1) then
-       DO i = 1, iim
+       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlon_glo,zx_lon)
+       if (nbp_lon.gt.1) then
+       DO i = 1, nbp_lon
          zx_lon(i,1) = rlon_glo(i+1)
-         zx_lon(i,jjmp1) = rlon_glo(i+1)
+         zx_lon(i,nbp_lat) = rlon_glo(i+1)
        ENDDO
        endif
-       CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat_glo,zx_lat)
+       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlat_glo,zx_lat)
 !
        CALL histbeg("paramLMDZ_phy.nc",  &
Index: /LMDZ5/branches/testing/libf/phylmd/ini_undefSTD.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ini_undefSTD.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/ini_undefSTD.F90	(revision 2408)
@@ -31,7 +31,4 @@
   ! ====================================================================
 
-  ! ym #include "dimensions.h"
-  ! ym      integer jjmp1
-  ! ym      parameter (jjmp1=jjm+1-1/jjm)
   ! ym #include "dimphy.h"
   ! variables Input/Output
Index: /LMDZ5/branches/testing/libf/phylmd/ini_wake.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ini_wake.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/ini_wake.F90	(revision 2408)
@@ -4,4 +4,5 @@
 SUBROUTINE ini_wake(wape, fip, it_wape_prescr, wape_prescr, fip_prescr, &
     alp_bl_prescr, ale_bl_prescr)
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
   ! **************************************************************
@@ -38,5 +39,4 @@
   ! alpbl  = Alp de PBL lue
 
-  include 'iniprint.h'
   ! declarations
   REAL wape, fip, wape_prescr, fip_prescr
Index: DZ5/branches/testing/libf/phylmd/inifis.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/inifis.F90	(revision 2407)
+++ 	(revision )
@@ -1,80 +1,0 @@
-
-! $Id$
-
-SUBROUTINE inifis(ngrid, nlayer, punjours, pdayref, ptimestep, plat, plon, &
-    parea, prad, pg, pr, pcpp)
-  USE dimphy
-  IMPLICIT NONE
-
-  ! =======================================================================
-
-  ! subject:
-  ! --------
-
-  ! Initialisation for the physical parametrisations of the LMD
-  ! martian atmospheric general circulation modele.
-
-  ! author: Frederic Hourdin 15 / 10 /93
-  ! -------
-
-  ! arguments:
-  ! ----------
-
-  ! input:
-  ! ------
-
-  ! ngrid                 Size of the horizontal grid.
-  ! All internal loops are performed on that grid.
-  ! nlayer                Number of vertical layers.
-  ! pdayref               Day of reference for the simulation
-  ! firstcall             True at the first call
-  ! lastcall              True at the last call
-  ! pday                  Number of days counted from the North. Spring
-  ! equinoxe.
-
-  ! =======================================================================
-
-  ! -----------------------------------------------------------------------
-  ! declarations:
-  ! -------------
-
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-
-  include 'iniprint.h'
-  REAL prad, pg, pr, pcpp, punjours
-
-  INTEGER ngrid, nlayer
-  REAL plat(ngrid), plon(ngrid), parea(klon)
-  INTEGER pdayref
-
-  REAL ptimestep
-  CHARACTER (LEN=20) :: modname = 'inifis'
-  CHARACTER (LEN=80) :: abort_message
-
-
-  IF (nlayer/=klev) THEN
-    PRINT *, 'STOP in inifis'
-    PRINT *, 'Probleme de dimensions :'
-    PRINT *, 'nlayer     = ', nlayer
-    PRINT *, 'klev   = ', klev
-    abort_message = ''
-    CALL abort_gcm(modname, abort_message, 1)
-  END IF
-
-  IF (ngrid/=klon) THEN
-    PRINT *, 'STOP in inifis'
-    PRINT *, 'Probleme de dimensions :'
-    PRINT *, 'ngrid     = ', ngrid
-    PRINT *, 'klon   = ', klon
-    abort_message = ''
-    CALL abort_gcm(modname, abort_message, 1)
-  END IF
-
-  RETURN
-  abort_message = 'Cette version demande les fichier rnatur.dat &
-    &                                                         &
-    &        et surf.def'
-  CALL abort_gcm(modname, abort_message, 1)
-
-END SUBROUTINE inifis
Index: /LMDZ5/branches/testing/libf/phylmd/inifis_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/inifis_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/inifis_mod.F90	(revision 2408)
@@ -0,0 +1,80 @@
+! $Id$
+MODULE inifis_mod
+
+CONTAINS
+
+  SUBROUTINE inifis(punjours, prad, pg, pr, pcpp)
+  ! Initialize some physical constants and settings
+  USE print_control_mod, ONLY: init_print_control, lunout
+  IMPLICIT NONE
+
+  include "YOMCST.h"
+  REAL,INTENT(IN) :: prad, pg, pr, pcpp, punjours
+
+  CHARACTER (LEN=20) :: modname = 'inifis'
+  CHARACTER (LEN=80) :: abort_message
+
+  ! Initialize flags lunout, prt_level, debug
+  CALL init_print_control
+
+  ! suphel => initialize some physical constants (orbital parameters,
+  !           geoid, gravity, thermodynamical constants, etc.) in the
+  !           physics
+  CALL suphel
+
+  ! check that physical constants set in 'suphel' are coherent
+  ! with values set in the dynamics:
+  IF (rday/=punjours) THEN
+    WRITE (lunout, *) 'inifis: length of day discrepancy!!!'
+    WRITE (lunout, *) '  in the dynamics punjours=', punjours
+    WRITE (lunout, *) '   but in the physics RDAY=', rday
+    IF (abs(rday-punjours)>0.01*punjours) THEN
+        ! stop here if the relative difference is more than 1%
+      abort_message = 'length of day discrepancy'
+      CALL abort_physic(modname, abort_message, 1)
+    END IF
+  END IF
+  IF (rg/=pg) THEN
+    WRITE (lunout, *) 'inifis: gravity discrepancy !!!'
+    WRITE (lunout, *) '     in the dynamics pg=', pg
+    WRITE (lunout, *) '  but in the physics RG=', rg
+    IF (abs(rg-pg)>0.01*pg) THEN
+        ! stop here if the relative difference is more than 1%
+      abort_message = 'gravity discrepancy'
+      CALL abort_physic(modname, abort_message, 1)
+    END IF
+  END IF
+  IF (ra/=prad) THEN
+    WRITE (lunout, *) 'inifis: planet radius discrepancy !!!'
+    WRITE (lunout, *) '   in the dynamics prad=', prad
+    WRITE (lunout, *) '  but in the physics RA=', ra
+    IF (abs(ra-prad)>0.01*prad) THEN
+        ! stop here if the relative difference is more than 1%
+      abort_message = 'planet radius discrepancy'
+      CALL abort_physic(modname, abort_message, 1)
+    END IF
+  END IF
+  IF (rd/=pr) THEN
+    WRITE (lunout, *) 'inifis: reduced gas constant discrepancy !!!'
+    WRITE (lunout, *) '     in the dynamics pr=', pr
+    WRITE (lunout, *) '  but in the physics RD=', rd
+    IF (abs(rd-pr)>0.01*pr) THEN
+        ! stop here if the relative difference is more than 1%
+      abort_message = 'reduced gas constant discrepancy'
+      CALL abort_physic(modname, abort_message, 1)
+    END IF
+  END IF
+  IF (rcpd/=pcpp) THEN
+    WRITE (lunout, *) 'inifis: specific heat discrepancy !!!'
+    WRITE (lunout, *) '     in the dynamics pcpp=', pcpp
+    WRITE (lunout, *) '  but in the physics RCPD=', rcpd
+    IF (abs(rcpd-pcpp)>0.01*pcpp) THEN
+        ! stop here if the relative difference is more than 1%
+      abort_message = 'specific heat discrepancy'
+      CALL abort_physic(modname, abort_message, 1)
+    END IF
+  END IF
+
+  END SUBROUTINE inifis
+  
+END MODULE inifis_mod
Index: DZ5/branches/testing/libf/phylmd/iniphysiq.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/iniphysiq.F90	(revision 2407)
+++ 	(revision )
@@ -1,204 +1,0 @@
-
-! $Id$
-
-
-SUBROUTINE iniphysiq(iim,jjm,nlayer,punjours, pdayref,ptimestep,         &
-                     rlatu,rlonv,aire,cu,cv,                             &
-                     prad,pg,pr,pcpp,iflag_phys)
-  USE dimphy, ONLY: klev ! number of atmospheric levels
-  USE mod_grid_phy_lmdz, ONLY: klon_glo ! number of atmospheric columns
-                                        ! (on full grid)
-  USE mod_phys_lmdz_para, ONLY: klon_omp, & ! number of columns (on local omp grid)
-                                klon_omp_begin, & ! start index of local omp subgrid
-                                klon_omp_end, & ! end index of local omp subgrid
-                                klon_mpi_begin ! start indes of columns (on local mpi grid)
-  USE comgeomphy, ONLY: initcomgeomphy, &
-                        airephy, & ! physics grid area (m2)
-                        cuphy, & ! cu coeff. (u_covariant = cu * u)
-                        cvphy, & ! cv coeff. (v_covariant = cv * v)
-                        rlond, & ! longitudes
-                        rlatd ! latitudes
-  USE phyaqua_mod, ONLY: iniaqua
-  IMPLICIT NONE
-
-  ! =======================================================================
-  ! Initialisation of the physical constants and some positional and
-  ! geometrical arrays for the physics
-  ! =======================================================================
-
-  include "YOMCST.h"
-  include "iniprint.h"
-
-  REAL, INTENT (IN) :: prad ! radius of the planet (m)
-  REAL, INTENT (IN) :: pg ! gravitational acceleration (m/s2)
-  REAL, INTENT (IN) :: pr ! ! reduced gas constant R/mu
-  REAL, INTENT (IN) :: pcpp ! specific heat Cp
-  REAL, INTENT (IN) :: punjours ! length (in s) of a standard day
-  INTEGER, INTENT (IN) :: nlayer ! number of atmospheric layers
-  INTEGER, INTENT (IN) :: iim ! number of atmospheric columns along longitudes
-  INTEGER, INTENT (IN) :: jjm ! number of atompsheric columns along latitudes
-  REAL, INTENT (IN) :: rlatu(jjm+1) ! latitudes of the physics grid
-  REAL, INTENT (IN) :: rlonv(iim+1) ! longitudes of the physics grid
-  REAL, INTENT (IN) :: aire(iim+1,jjm+1) ! area of the dynamics grid (m2)
-  REAL, INTENT (IN) :: cu((iim+1)*(jjm+1)) ! cu coeff. (u_covariant = cu * u)
-  REAL, INTENT (IN) :: cv((iim+1)*jjm) ! cv coeff. (v_covariant = cv * v)
-  INTEGER, INTENT (IN) :: pdayref ! reference day of for the simulation
-  REAL, INTENT (IN) :: ptimestep !physics time step (s)
-  INTEGER, INTENT (IN) :: iflag_phys ! type of physics to be called
-
-  INTEGER :: ibegin, iend, offset
-  INTEGER :: i,j
-  CHARACTER (LEN=20) :: modname = 'iniphysiq'
-  CHARACTER (LEN=80) :: abort_message
-  REAL :: total_area_phy, total_area_dyn
-
-
-  ! global array, on full physics grid:
-  REAL,ALLOCATABLE :: latfi(:)
-  REAL,ALLOCATABLE :: lonfi(:)
-  REAL,ALLOCATABLE :: cufi(:)
-  REAL,ALLOCATABLE :: cvfi(:)
-  REAL,ALLOCATABLE :: airefi(:)
-
-  IF (nlayer/=klev) THEN
-    WRITE (lunout, *) 'STOP in ', trim(modname)
-    WRITE (lunout, *) 'Problem with dimensions :'
-    WRITE (lunout, *) 'nlayer     = ', nlayer
-    WRITE (lunout, *) 'klev   = ', klev
-    abort_message = ''
-    CALL abort_gcm(modname, abort_message, 1)
-  END IF
-
-  !call init_phys_lmdz(iim,jjm+1,llm,1,(/(jjm-1)*iim+2/))
-  
-  ! Generate global arrays on full physics grid
-  ALLOCATE(latfi(klon_glo),lonfi(klon_glo),cufi(klon_glo),cvfi(klon_glo))
-  ALLOCATE(airefi(klon_glo))
-
-  IF (klon_glo>1) THEN ! general case
-    ! North pole
-    latfi(1)=rlatu(1)
-    lonfi(1)=0.
-    cufi(1) = cu(1)
-    cvfi(1) = cv(1)
-    DO j=2,jjm
-      DO i=1,iim
-        latfi((j-2)*iim+1+i)= rlatu(j)
-        lonfi((j-2)*iim+1+i)= rlonv(i)
-        cufi((j-2)*iim+1+i) = cu((j-1)*(iim+1)+i)
-        cvfi((j-2)*iim+1+i) = cv((j-1)*(iim+1)+i)
-      ENDDO
-    ENDDO
-    ! South pole
-    latfi(klon_glo)= rlatu(jjm+1)
-    lonfi(klon_glo)= 0.
-    cufi(klon_glo) = cu((iim+1)*jjm+1)
-    cvfi(klon_glo) = cv((iim+1)*jjm-iim)
-
-    ! build airefi(), mesh area on physics grid
-    CALL gr_dyn_fi(1,iim+1,jjm+1,klon_glo,aire,airefi)
-    ! Poles are single points on physics grid
-    airefi(1)=sum(aire(1:iim,1))
-    airefi(klon_glo)=sum(aire(1:iim,jjm+1))
-
-    ! Sanity check: do total planet area match between physics and dynamics?
-    total_area_dyn=sum(aire(1:iim,1:jjm+1))
-    total_area_phy=sum(airefi(1:klon_glo))
-    IF (total_area_dyn/=total_area_phy) THEN
-      WRITE (lunout, *) 'iniphysiq: planet total surface discrepancy !!!'
-      WRITE (lunout, *) '     in the dynamics total_area_dyn=', total_area_dyn
-      WRITE (lunout, *) '  but in the physics total_area_phy=', total_area_phy
-      IF (abs(total_area_dyn-total_area_phy)>0.00001*total_area_dyn) THEN
-        ! stop here if the relative difference is more than 0.001%
-        abort_message = 'planet total surface discrepancy'
-        CALL abort_gcm(modname, abort_message, 1)
-      ENDIF
-    ENDIF
-  ELSE ! klon_glo==1, running the 1D model
-    ! just copy over input values
-    latfi(1)=rlatu(1)
-    lonfi(1)=rlonv(1)
-    cufi(1)=cu(1)
-    cvfi(1)=cv(1)
-    airefi(1)=aire(1,1)
-  ENDIF ! of IF (klon_glo>1)
-
-!$OMP PARALLEL 
-  ! Now generate local lon/lat/cu/cv/area arrays
-  CALL initcomgeomphy
-
-  offset = klon_mpi_begin - 1
-  airephy(1:klon_omp) = airefi(offset+klon_omp_begin:offset+klon_omp_end)
-  cuphy(1:klon_omp) = cufi(offset+klon_omp_begin:offset+klon_omp_end)
-  cvphy(1:klon_omp) = cvfi(offset+klon_omp_begin:offset+klon_omp_end)
-  rlond(1:klon_omp) = lonfi(offset+klon_omp_begin:offset+klon_omp_end)
-  rlatd(1:klon_omp) = latfi(offset+klon_omp_begin:offset+klon_omp_end)
-
-    ! suphel => initialize some physical constants (orbital parameters,
-    !           geoid, gravity, thermodynamical constants, etc.) in the
-    !           physics
-  CALL suphel
-
-!$OMP END PARALLEL
-
-  ! check that physical constants set in 'suphel' are coherent
-  ! with values set in the dynamics:
-  IF (rday/=punjours) THEN
-    WRITE (lunout, *) 'iniphysiq: length of day discrepancy!!!'
-    WRITE (lunout, *) '  in the dynamics punjours=', punjours
-    WRITE (lunout, *) '   but in the physics RDAY=', rday
-    IF (abs(rday-punjours)>0.01) THEN
-        ! stop here if the relative difference is more than 1%
-      abort_message = 'length of day discrepancy'
-      CALL abort_gcm(modname, abort_message, 1)
-    END IF
-  END IF
-  IF (rg/=pg) THEN
-    WRITE (lunout, *) 'iniphysiq: gravity discrepancy !!!'
-    WRITE (lunout, *) '     in the dynamics pg=', pg
-    WRITE (lunout, *) '  but in the physics RG=', rg
-    IF (abs(rg-pg)>0.01) THEN
-        ! stop here if the relative difference is more than 1%
-      abort_message = 'gravity discrepancy'
-      CALL abort_gcm(modname, abort_message, 1)
-    END IF
-  END IF
-  IF (ra/=prad) THEN
-    WRITE (lunout, *) 'iniphysiq: planet radius discrepancy !!!'
-    WRITE (lunout, *) '   in the dynamics prad=', prad
-    WRITE (lunout, *) '  but in the physics RA=', ra
-    IF (abs(ra-prad)>0.01) THEN
-        ! stop here if the relative difference is more than 1%
-      abort_message = 'planet radius discrepancy'
-      CALL abort_gcm(modname, abort_message, 1)
-    END IF
-  END IF
-  IF (rd/=pr) THEN
-    WRITE (lunout, *) 'iniphysiq: reduced gas constant discrepancy !!!'
-    WRITE (lunout, *) '     in the dynamics pr=', pr
-    WRITE (lunout, *) '  but in the physics RD=', rd
-    IF (abs(rd-pr)>0.01) THEN
-        ! stop here if the relative difference is more than 1%
-      abort_message = 'reduced gas constant discrepancy'
-      CALL abort_gcm(modname, abort_message, 1)
-    END IF
-  END IF
-  IF (rcpd/=pcpp) THEN
-    WRITE (lunout, *) 'iniphysiq: specific heat discrepancy !!!'
-    WRITE (lunout, *) '     in the dynamics pcpp=', pcpp
-    WRITE (lunout, *) '  but in the physics RCPD=', rcpd
-    IF (abs(rcpd-pcpp)>0.01) THEN
-        ! stop here if the relative difference is more than 1%
-      abort_message = 'specific heat discrepancy'
-      CALL abort_gcm(modname, abort_message, 1)
-    END IF
-  END IF
-
-  ! Additional initializations for aquaplanets
-!$OMP PARALLEL
-  IF (iflag_phys>=100) THEN
-    CALL iniaqua(klon_omp, rlatd, rlond, iflag_phys)
-  END IF
-!$OMP END PARALLEL
-
-END SUBROUTINE iniphysiq
Index: DZ5/branches/testing/libf/phylmd/inistats.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/inistats.F90	(revision 2407)
+++ 	(revision )
@@ -1,128 +1,0 @@
-SUBROUTINE inistats(ierr)
-
-  IMPLICIT NONE
-
-  include "dimensions.h"
-  include "paramet.h"
-  include "comgeom.h"
-  include "comvert.h"
-  include "comconst.h"
-  include "statto.h"
-  include "netcdf.inc"
-
-  INTEGER, INTENT (OUT) :: ierr
-  INTEGER :: nid
-  INTEGER :: l, nsteppd
-  REAL, DIMENSION (llm) :: sig_s
-  INTEGER :: idim_lat, idim_lon, idim_llm, idim_llmp1, idim_time
-  REAL, DIMENSION (istime) :: lt
-  INTEGER :: nvarid
-
-  WRITE (*, *)
-  WRITE (*, *) '                        || STATS ||'
-  WRITE (*, *)
-  WRITE (*, *) 'daysec', daysec
-  WRITE (*, *) 'dtphys', dtphys
-  nsteppd = nint(daysec/dtphys)
-  WRITE (*, *) 'nsteppd=', nsteppd
-  IF (abs(float(nsteppd)-daysec/dtphys)>1.E-8*daysec) &
-    STOP 'Dans Instat:  1jour .ne. n pas physiques'
-
-  IF (mod(nsteppd,istime)/=0) STOP &
-    'Dans Instat:  1jour .ne. n*istime pas physiques'
-
-  istats = nsteppd/istime
-  WRITE (*, *) 'istats=', istats
-  WRITE (*, *) 'Storing ', istime, 'times per day'
-  WRITE (*, *) 'thus every ', istats, 'physical timestep '
-  WRITE (*, *)
-
-  DO l = 1, llm
-    sig_s(l) = ((ap(l)+ap(l+1))/preff+bp(l)+bp(l+1))/2.
-    pseudoalt(l) = log(preff/presnivs(l))*8.
-  END DO
-
-  ierr = nf_create('stats.nc', nf_clobber, nid)
-  IF (ierr/=nf_noerr) THEN
-    WRITE (*, *) nf_strerror(ierr)
-    STOP ''
-  END IF
-
-  ierr = nf_def_dim(nid, 'latitude', jjp1, idim_lat)
-  ierr = nf_def_dim(nid, 'longitude', iip1, idim_lon)
-  ierr = nf_def_dim(nid, 'altitude', llm, idim_llm)
-  ierr = nf_def_dim(nid, 'llmp1', llm+1, idim_llmp1)
-  ierr = nf_def_dim(nid, 'Time', nf_unlimited, idim_time)
-
-  ierr = nf_enddef(nid)
-  CALL def_var_stats(nid, 'Time', 'Time', 'hours since 0000-00-0 00:00:00', &
-    1, idim_time, nvarid, ierr)
-  ! Time is initialised later by mkstats subroutine
-
-  CALL def_var_stats(nid, 'latitude', 'latitude', 'degrees_north', 1, &
-    idim_lat, nvarid, ierr)
-#ifdef NC_DOUBLE
-  ierr = nf_put_var_double(nid, nvarid, rlatu/pi*180)
-#else
-  ierr = nf_put_var_real(nid, nvarid, rlatu/pi*180)
-#endif
-  CALL def_var_stats(nid, 'longitude', 'East longitude', 'degrees_east', 1, &
-    idim_lon, nvarid, ierr)
-#ifdef NC_DOUBLE
-  ierr = nf_put_var_double(nid, nvarid, rlonv/pi*180)
-#else
-  ierr = nf_put_var_real(nid, nvarid, rlonv/pi*180)
-#endif
-
-  ! Niveaux verticaux, aps et bps
-  ierr = nf_redef(nid)
-  ! presnivs
-#ifdef NC_DOUBLE
-  ierr = nf_def_var(nid, 'presnivs', nf_double, 1, idim_llm, nvarid)
-#else
-  ierr = nf_def_var(nid, 'presnivs', nf_float, 1, idim_llm, nvarid)
-#endif
-  ierr = nf_put_att_text(nid, nvarid, 'long_name', 15, 'Vertical levels')
-  ierr = nf_put_att_text(nid, nvarid, 'units', 2, 'Pa')
-  ierr = nf_put_att_text(nid, nvarid, 'positive', 4, 'down')
-  ierr = nf_enddef(nid)
-#ifdef NC_DOUBLE
-  ierr = nf_put_var_double(nid, nvarid, presnivs(1:llm))
-#else
-  ierr = nf_put_var_real(nid, nvarid, presnivs(1:llm))
-#endif
-  ! Pseudo alts
-#ifdef NC_DOUBLE
-  ierr = nf_def_var(nid, 'altitude', nf_double, 1, idim_llm, nvarid)
-#else
-  ierr = nf_def_var(nid, 'altitude', nf_float, 1, idim_llm, nvarid)
-#endif
-  ierr = nf_put_att_text(nid, nvarid, 'long_name', 8, 'altitude')
-  ierr = nf_put_att_text(nid, nvarid, 'units', 2, 'km')
-  ierr = nf_put_att_text(nid, nvarid, 'positive', 2, 'up')
-  ierr = nf_enddef(nid)
-#ifdef NC_DOUBLE
-  ierr = nf_put_var_double(nid, nvarid, pseudoalt)
-#else
-  ierr = nf_put_var_real(nid, nvarid, pseudoalt)
-#endif
-  ! call def_var_stats(nid,"aps","hybrid pressure at midlayers"," ",
-  ! &            1,idim_llm,nvarid,ierr)
-  ! #ifdef NC_DOUBLE
-  ! ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,aps)
-  ! #else
-  ! ierr = NF_PUT_VAR_REAL (nid,nvarid,aps)
-  ! #endif
-
-  ! call def_var_stats(nid,"bps","hybrid sigma at midlayers"," ",
-  ! &            1,idim_llm,nvarid,ierr)
-  ! #ifdef NC_DOUBLE
-  ! ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,bps)
-  ! #else
-  ! ierr = NF_PUT_VAR_REAL (nid,nvarid,bps)
-  ! #endif
-
-  ierr = nf_close(nid)
-
-END SUBROUTINE inistats
-
Index: /LMDZ5/branches/testing/libf/phylmd/init_be.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/init_be.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/init_be.F90	(revision 2408)
@@ -5,7 +5,7 @@
 
   USE dimphy
-  USE comgeomphy
-  USE infotrac, ONLY : nbtr
+  USE infotrac_phy, ONLY : nbtr
   USE indice_sol_mod
+  USE geometry_mod, ONLY : longitude, latitude
     
   IMPLICIT NONE 
@@ -65,5 +65,5 @@
 ! la source est maintenant définie independemment de la valeur de klev.
 !!! Source actuellement definie pour klev = 19 et klev >= 39
-!!  IF (klev /= 19 .AND. klev<39) CALL abort_gcm("init_be","Source du be7 necessite klev=19 ou klev>=39",1)
+!!  IF (klev /= 19 .AND. klev<39) CALL abort_physic("init_be","Source du be7 necessite klev=19 ou klev>=39",1)
 !!!
 ! Definition des constantes
@@ -114,8 +114,8 @@
 
   DO i = 1,klon
-     qcos=sin(glt)*sin(rlatd(i))
+     qcos=sin(glt)*sin(latitude(i))
 !!jyg
-!!     qcos=qcos+cos(glt)*cos(rlatd(i))*cos(rlond(i)+glg)
-     qcos=qcos+cos(glt)*cos(rlatd(i))*cos(rlond(i)-glg)
+!!     qcos=qcos+cos(glt)*cos(latitude(i))*cos(longitude(i)+glg)
+     qcos=qcos+cos(glt)*cos(latitude(i))*cos(longitude(i)-glg)
 !!jyg end
      IF ( qcos .LT. -1.) qcos = -1.
Index: DZ5/branches/testing/libf/phylmd/init_phys_lmdz.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/init_phys_lmdz.F90	(revision 2407)
+++ 	(revision )
@@ -1,36 +1,0 @@
-!
-!$Header$
-!
-SUBROUTINE Init_Phys_lmdz(iim,jjp1,llm,nb_proc,distrib)
-  USE mod_phys_lmdz_para, ONLY: Init_phys_lmdz_para, klon_omp
-  USE mod_grid_phy_lmdz, ONLY: Init_grid_phy_lmdz, nbp_lev
-  USE dimphy, ONLY : Init_dimphy
-  USE infotrac, ONLY : type_trac
-#ifdef REPROBUS
-  USE CHEM_REP, ONLY : Init_chem_rep_phys
-#endif
-
-  IMPLICIT NONE
-  
-    INTEGER,INTENT(in) :: iim
-    INTEGER,INTENT(in) :: jjp1
-    INTEGER,INTENT(in) :: llm
-    INTEGER,INTENT(in) :: nb_proc
-    INTEGER,INTENT(in) :: distrib(0:nb_proc-1)
-
-
-    CALL Init_grid_phy_lmdz(iim,jjp1,llm)
-    CALL Init_phys_lmdz_para(iim,jjp1,nb_proc,distrib)
-!$OMP PARALLEL
-    CALL Init_dimphy(klon_omp,nbp_lev)
-
-! Initialization of Reprobus
-    IF (type_trac == 'repr') THEN
-#ifdef REPROBUS
-       CALL Init_chem_rep_phys(klon_omp,nbp_lev)
-#endif
-    END IF
-
-!$OMP END PARALLEL
- 
-END SUBROUTINE Init_Phys_lmdz  
Index: /LMDZ5/branches/testing/libf/phylmd/initphysto.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/initphysto.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/initphysto.F90	(revision 2408)
@@ -8,6 +8,7 @@
   USE IOIPSL
   USE iophy
-  USE control_mod
   USE indice_sol_mod
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev
+  USE time_phylmdz_mod, ONLY: day_ref, annee_ref
   
   IMPLICIT NONE
@@ -37,14 +38,4 @@
 !
 ! =====================================================================
-!
-!   Declarations
-  INCLUDE "dimensions.h"
-  INCLUDE "paramet.h"
-  INCLUDE "comconst.h"
-  INCLUDE "comgeom.h"
-  INCLUDE "temps.h"
-  INCLUDE "logic.h"
-  INCLUDE "description.h"
-  INCLUDE "serre.h"
 
 !   Arguments
@@ -58,5 +49,5 @@
   INTEGER nhoriid, i
   INTEGER l,k
-  REAL nivsigs(llm)
+  REAL nivsigs(nbp_lev)
   INTEGER tau0
   REAL zjulian
@@ -66,10 +57,9 @@
   INTEGER zan, idayref
   LOGICAL ok_sync
-  REAL zx_lon(iim,jjm+1), zx_lat(iim,jjm+1)
+  REAL zx_lon(nbp_lon,nbp_lat), zx_lat(nbp_lon,nbp_lat)
   CHARACTER(len=12) :: nvar
 
 !  Initialisations
 !
-  pi = 4. * ATAN (1.)
   ok_sync= .TRUE.
 !
@@ -88,5 +78,5 @@
 !  Appel a histvert pour la grille verticale
 !
-  DO l=1,llm
+  DO l=1,nbp_lev
      nivsigs(l)=REAL(l)
   ENDDO
@@ -94,107 +84,107 @@
   CALL histvert(fileid, 'sig_s', 'Niveaux sigma', &
        'sigma_level', &
-       llm, nivsigs, zvertiid)
+       nbp_lev, nivsigs, zvertiid)
 !
 !  Appels a histdef pour la definition des variables a sauvegarder
 !
   CALL histdef(fileid, "phis", "Surface geop. height", "-", &
-       iim,jj_nb,nhoriid, 1,1,1, -99, 32, &
+       nbp_lon,jj_nb,nhoriid, 1,1,1, -99, 32, &
        "once", t_ops, t_wrt)
   
   CALL histdef(fileid, "aire", "Grid area", "-", &
-       iim,jj_nb,nhoriid, 1,1,1, -99, 32, &
+       nbp_lon,jj_nb,nhoriid, 1,1,1, -99, 32, &
        "once", t_ops, t_wrt)
 
   CALL histdef(fileid, "longitudes", "longitudes", "-", &
-       iim,jj_nb,nhoriid, 1,1,1, -99, 32, &
+       nbp_lon,jj_nb,nhoriid, 1,1,1, -99, 32, &
        "once", t_ops, t_wrt)
 
   CALL histdef(fileid, "latitudes", "latitudes", "-", &
-       iim,jj_nb,nhoriid, 1,1,1, -99, 32, &
+       nbp_lon,jj_nb,nhoriid, 1,1,1, -99, 32, &
        "once", t_ops, t_wrt)
 ! T 
-  CALL histdef(fileid, 't', 'Temperature', 'K', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 't', 'Temperature', 'K', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! mfu 
-  CALL histdef(fileid, 'mfu', 'flx m. pan. mt', 'kg m/s',iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'mfu', 'flx m. pan. mt', 'kg m/s',nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! mfd 
-  CALL histdef(fileid, 'mfd', 'flx m. pan. des', 'kg m/s',iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'mfd', 'flx m. pan. des', 'kg m/s',nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! en_u 
-  CALL histdef(fileid, 'en_u', 'flx ent pan mt', 'kg m/s', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'en_u', 'flx ent pan mt', 'kg m/s', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! de_u 
-  CALL histdef(fileid, 'de_u', 'flx det pan mt', 'kg m/s',iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'de_u', 'flx det pan mt', 'kg m/s',nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! en_d 
-  CALL histdef(fileid, 'en_d', 'flx ent pan dt', 'kg m/s', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'en_d', 'flx ent pan dt', 'kg m/s', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! de_d 
-  CALL histdef(fileid, 'de_d', 'flx det pan dt', 'kg m/s', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'de_d', 'flx det pan dt', 'kg m/s', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! coefh
-  CALL histdef(fileid, "coefh", " ", " ", iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, "inst(X)", t_ops, t_wrt)
+  CALL histdef(fileid, "coefh", " ", " ", nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, "inst(X)", t_ops, t_wrt)
 ! fm_th
-  CALL histdef(fileid, "fm_th", " ", " ",iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, "inst(X)", t_ops, t_wrt)
+  CALL histdef(fileid, "fm_th", " ", " ",nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, "inst(X)", t_ops, t_wrt)
 ! en_th
-  CALL histdef(fileid, "en_th", " ", " ",iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, "inst(X)", t_ops, t_wrt)
+  CALL histdef(fileid, "en_th", " ", " ",nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, "inst(X)", t_ops, t_wrt)
 ! frac_impa
-  CALL histdef(fileid, 'frac_impa', ' ', ' ',iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'frac_impa', ' ', ' ',nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! frac_nucl
-  CALL histdef(fileid, 'frac_nucl', ' ', ' ',iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid,32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'frac_nucl', ' ', ' ',nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid,32, 'inst(X)', t_ops, t_wrt)
 ! pyu1
-  CALL histdef(fileid, "pyu1", " ", " ", iim,jj_nb,nhoriid, &
+  CALL histdef(fileid, "pyu1", " ", " ", nbp_lon,jj_nb,nhoriid, &
        1,1,1, -99, 32, "inst(X)", t_ops, t_wrt)
 ! pyv1
-  CALL histdef(fileid, "pyv1", " ", " ", iim,jj_nb,nhoriid, &
+  CALL histdef(fileid, "pyv1", " ", " ", nbp_lon,jj_nb,nhoriid, &
        1,1,1, -99, 32,"inst(X)", t_ops, t_wrt)    
 ! ftsol1
-  CALL histdef(fileid, "ftsol1", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "ftsol1", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1,1, -99,32, "inst(X)", t_ops, t_wrt)
 ! ftsol2
-  CALL histdef(fileid, "ftsol2", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "ftsol2", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1,1, -99,32, "inst(X)", t_ops, t_wrt)
 ! ftsol3
-  CALL histdef(fileid, "ftsol3", " ", " ", iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "ftsol3", " ", " ", nbp_lon, jj_nb, nhoriid, &
        1, 1,1, -99,32, "inst(X)", t_ops, t_wrt)
 ! ftsol4
-  CALL histdef(fileid, "ftsol4", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "ftsol4", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1,1, -99, 32, "inst(X)", t_ops, t_wrt)
 ! psrf1
-  CALL histdef(fileid, "psrf1", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "psrf1", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1, 1, -99,32, "inst(X)", t_ops, t_wrt)
 ! psrf2
-  CALL histdef(fileid, "psrf2", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "psrf2", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1, 1, -99, 32, "inst(X)", t_ops, t_wrt)
 ! psrf3
-  CALL histdef(fileid, "psrf3", " ", " ",iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "psrf3", " ", " ",nbp_lon, jj_nb, nhoriid, &
        1, 1, 1, -99, 32, "inst(X)", t_ops, t_wrt)
 ! psrf4
-  CALL histdef(fileid, "psrf4", " ", " ", iim, jj_nb, nhoriid, &
+  CALL histdef(fileid, "psrf4", " ", " ", nbp_lon, jj_nb, nhoriid, &
        1, 1, 1, -99,32, "inst(X)", t_ops, t_wrt)
 ! sh
-  CALL histdef(fileid, 'sh', '', '', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'sh', '', '', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! da
-  CALL histdef(fileid, 'da', '', '', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'da', '', '', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! mp
-  CALL histdef(fileid, 'mp', '', '', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'mp', '', '', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! upwd
-  CALL histdef(fileid, 'upwd', '', '', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'upwd', '', '', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 ! dnwd
-  CALL histdef(fileid, 'dnwd', '', '', iim, jj_nb, nhoriid, &
-       llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+  CALL histdef(fileid, 'dnwd', '', '', nbp_lon, jj_nb, nhoriid, &
+       nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
 
 ! phi
-  DO k=1,llm
+  DO k=1,nbp_lev
      IF (k<10) THEN
         WRITE(nvar,'(i1)') k
@@ -206,6 +196,6 @@
      nvar='phi_lev'//trim(nvar)
      
-     CALL histdef(fileid, nvar, '', '', iim, jj_nb, nhoriid, &
-          llm, 1, llm, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
+     CALL histdef(fileid, nvar, '', '', nbp_lon, jj_nb, nhoriid, &
+          nbp_lev, 1, nbp_lev, zvertiid, 32, 'inst(X)', t_ops, t_wrt)
   END DO
 
Index: /LMDZ5/branches/testing/libf/phylmd/initrrnpb.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/initrrnpb.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/initrrnpb.F90	(revision 2408)
@@ -4,5 +4,5 @@
 SUBROUTINE  initrrnpb(ftsol,pctsrf,masktr,fshtr,hsoltr,tautr,vdeptr,scavtr)
   USE dimphy
-  USE infotrac, ONLY : nbtr
+  USE infotrac_phy, ONLY : nbtr
   USE traclmdz_mod, ONLY : id_rn, id_pb
   USE indice_sol_mod
Index: /LMDZ5/branches/testing/libf/phylmd/interfoce_lim.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/interfoce_lim.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/interfoce_lim.F90	(revision 2408)
@@ -118,5 +118,5 @@
         IF (ierr.NE.NF_NOERR) THEN
            abort_message = 'Pb d''ouverture du fichier de conditions aux limites'
-           CALL abort_gcm(modname,abort_message,1)
+           CALL abort_physic(modname,abort_message,1)
         ENDIF
 
@@ -135,5 +135,5 @@
            IF (ierr /= NF_NOERR) THEN
               abort_message = 'Le champ <FOCE> est absent'
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
            ENDIF
 #ifdef NC_DOUBLE
@@ -144,5 +144,5 @@
            IF (ierr /= NF_NOERR) THEN
               abort_message = 'Lecture echouee pour <FOCE>'
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
            ENDIF
            !
@@ -152,5 +152,5 @@
            IF (ierr /= NF_NOERR) THEN
               abort_message = 'Le champ <FSIC> est absent'
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
            ENDIF
 #ifdef NC_DOUBLE
@@ -161,5 +161,5 @@
            IF (ierr /= NF_NOERR) THEN
               abort_message = 'Lecture echouee pour <FSIC>'
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
            ENDIF
            !
@@ -169,5 +169,5 @@
            IF (ierr /= NF_NOERR) THEN
               abort_message = 'Le champ <FTER> est absent'
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
            ENDIF
 #ifdef NC_DOUBLE
@@ -178,5 +178,5 @@
            IF (ierr /= NF_NOERR) THEN
               abort_message = 'Lecture echouee pour <FTER>'
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
            ENDIF
            !
@@ -186,5 +186,5 @@
            IF (ierr /= NF_NOERR) THEN
               abort_message = 'Le champ <FLIC> est absent'
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
            ENDIF
 #ifdef NC_DOUBLE
@@ -195,5 +195,5 @@
            IF (ierr /= NF_NOERR) THEN
               abort_message = 'Lecture echouee pour <FLIC>'
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
            ENDIF
            !
@@ -203,5 +203,5 @@
            IF (ierr /= NF_NOERR) THEN
               abort_message = 'Le champ <NAT> est absent'
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
            ENDIF
 #ifdef NC_DOUBLE
@@ -212,5 +212,5 @@
            IF (ierr /= NF_NOERR) THEN
               abort_message = 'Lecture echouee pour <NAT>'
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
            ENDIF
 !
@@ -237,5 +237,5 @@
         IF (ierr /= NF_NOERR) THEN
            abort_message = 'Le champ <SST> est absent'
-           CALL abort_gcm(modname,abort_message,1)
+           CALL abort_physic(modname,abort_message,1)
         ENDIF
 #ifdef NC_DOUBLE
@@ -246,5 +246,5 @@
         IF (ierr /= NF_NOERR) THEN
            abort_message = 'Lecture echouee pour <SST>'
-           CALL abort_gcm(modname,abort_message,1)
+           CALL abort_physic(modname,abort_message,1)
         ENDIF
           
Index: /LMDZ5/branches/testing/libf/phylmd/iophy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/iophy.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/iophy.F90	(revision 2408)
@@ -46,4 +46,5 @@
                                 is_sequential, is_south_pole
   USE mod_grid_phy_lmdz, only: nbp_lon, nbp_lat, klon_glo
+  USE print_control_mod, ONLY: prt_level,lunout 
 #ifdef CPP_IOIPSL
   USE ioipsl, only: flio_dom_set
@@ -53,6 +54,4 @@
 #endif
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'
-  include 'iniprint.h'
     REAL,DIMENSION(klon),INTENT(IN) :: rlon
     REAL,DIMENSION(klon),INTENT(IN) :: rlat
@@ -77,15 +76,22 @@
     
 !$OMP MASTER  
-    ALLOCATE(io_lat(jjm+1-1/(iim*jjm)))
-    io_lat(1)=rlat_glo(1)
-    io_lat(jjm+1-1/(iim*jjm))=rlat_glo(klon_glo)
-    IF ((iim*jjm) > 1) then
-      DO i=2,jjm
-        io_lat(i)=rlat_glo(2+(i-2)*iim)
+    ALLOCATE(io_lat(nbp_lat))
+    IF (klon_glo == 1) THEN
+      io_lat(1)=rlat_glo(1)
+    ELSE
+      io_lat(1)=rlat_glo(1)
+      io_lat(nbp_lat)=rlat_glo(klon_glo)
+      DO i=2,nbp_lat-1
+        io_lat(i)=rlat_glo(2+(i-2)*nbp_lon)
       ENDDO
     ENDIF
 
-    ALLOCATE(io_lon(iim))
-    io_lon(:)=rlon_glo(2-1/(iim*jjm):iim+1-1/(iim*jjm))
+    ALLOCATE(io_lon(nbp_lon))
+    IF (klon_glo == 1) THEN
+      io_lon(1)=rlon_glo(1)
+    ELSE 
+      io_lon(1:nbp_lon)=rlon_glo(2:nbp_lon+1)
+    ENDIF
+
 !! (I) dtnb   : total number of domains
 !! (I) dnb    : domain number
@@ -104,13 +110,13 @@
 
     ddid=(/ 1,2 /)
-    dsg=(/ iim, jjm+1-1/(iim*jjm) /)
-    dsl=(/ iim, jj_nb /)
+    dsg=(/ nbp_lon, nbp_lat /)
+    dsl=(/ nbp_lon, jj_nb /)
     dpf=(/ 1,jj_begin /)
-    dpl=(/ iim, jj_end /)
+    dpl=(/ nbp_lon, jj_end /)
     dhs=(/ ii_begin-1,0 /)
     IF (mpi_rank==mpi_size-1) THEN
       dhe=(/0,0/)
     ELSE
-      dhe=(/ iim-ii_end,0 /)  
+      dhe=(/ nbp_lon-ii_end,0 /)  
     ENDIF
 
@@ -155,8 +161,8 @@
                                 mpi_size, mpi_rank 
   USE ioipsl, only: flio_dom_set
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'   
-    REAL,DIMENSION(iim),INTENT(IN) :: lon
-    REAL,DIMENSION(jjm+1-1/(iim*jjm)),INTENT(IN) :: lat
+    REAL,DIMENSION(nbp_lon),INTENT(IN) :: lon
+    REAL,DIMENSION(nbp_lat),INTENT(IN) :: lat
 
     INTEGER,DIMENSION(2) :: ddid
@@ -169,19 +175,19 @@
 
 !$OMP MASTER  
-    allocate(io_lat(jjm+1-1/(iim*jjm)))
+    allocate(io_lat(nbp_lat))
     io_lat(:)=lat(:)
-    allocate(io_lon(iim))
+    allocate(io_lon(nbp_lon))
     io_lon(:)=lon(:)
    
     ddid=(/ 1,2 /)
-    dsg=(/ iim, jjm+1-1/(iim*jjm) /)
-    dsl=(/ iim, jj_nb /)
+    dsg=(/ nbp_lon, nbp_lat /)
+    dsl=(/ nbp_lon, jj_nb /)
     dpf=(/ 1,jj_begin /)
-    dpl=(/ iim, jj_end /)
+    dpl=(/ nbp_lon, jj_end /)
     dhs=(/ ii_begin-1,0 /)
     if (mpi_rank==mpi_size-1) then
       dhe=(/0,0/)
     else
-      dhe=(/ iim-ii_end,0 /)  
+      dhe=(/ nbp_lon-ii_end,0 /)  
     endif
     
@@ -198,4 +204,5 @@
   USE mod_phys_lmdz_para, only: is_sequential, is_using_mpi, is_mpi_root, &
                                 jj_begin, jj_end, jj_nb
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
   use ioipsl, only: histbeg
 #ifdef CPP_XIOS
@@ -203,5 +210,4 @@
 #endif
   IMPLICIT NONE
-  include 'dimensions.h'
   include 'clesphys.h'
     
@@ -217,9 +223,9 @@
 !$OMP MASTER    
     if (is_sequential) then
-      call histbeg(name,iim,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
-                   1,iim,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
+      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
+                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
     else
-      call histbeg(name,iim,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
-                   1,iim,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
+      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
+                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
     endif
 
@@ -240,8 +246,8 @@
 
   USE mod_phys_lmdz_para, only: jj_begin, jj_end, jj_nb, is_sequential
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
   use ioipsl, only: histbeg
 
   IMPLICIT NONE
-  include 'dimensions.h'
     
     character*(*), INTENT(IN) :: name
@@ -255,9 +261,9 @@
 #ifndef CPP_IOIPSL_NO_OUTPUT 
     if (is_sequential) then
-      call histbeg(name,iim,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
-                   1,iim,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
+      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
+                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
     else
-      call histbeg(name,iim,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
-                   1,iim,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
+      call histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
+                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
     endif
 #endif
@@ -274,9 +280,8 @@
                                 is_sequential, klon_mpi_begin, klon_mpi_end, &
                                 mpi_rank
-  USE mod_grid_phy_lmdz, only: klon_glo
+  USE mod_grid_phy_lmdz, only: klon_glo, nbp_lon, nbp_lat
   use ioipsl, only: histbeg
 
   IMPLICIT NONE
-  include 'dimensions.h' 
 
     REAL,DIMENSION(klon),INTENT(IN) :: rlon
@@ -304,6 +309,5 @@
     REAL, allocatable, DIMENSION(:) :: npplat, npplon
     REAL, allocatable, DIMENSION(:,:) :: npplat_bounds, npplon_bounds
-    INTEGER, PARAMETER :: jjmp1=jjm+1-1/jjm
-    REAL, DIMENSION(iim,jjmp1) :: zx_lon, zx_lat
+    REAL, DIMENSION(nbp_lon,nbp_lat) :: zx_lon, zx_lat
 
     CALL gather(rlat,rlat_glo)
@@ -330,10 +334,10 @@
      endif
 !
-     IF ( tabij(i).LE.iim) THEN
+     IF ( tabij(i).LE.nbp_lon) THEN
       plat_bounds(i,1)=rlat_glo(tabij(i))
      ELSE
-      plat_bounds(i,1)=rlat_glo(tabij(i)-iim)
+      plat_bounds(i,1)=rlat_glo(tabij(i)-nbp_lon)
      ENDIF
-     plat_bounds(i,2)=rlat_glo(tabij(i)+iim)
+     plat_bounds(i,2)=rlat_glo(tabij(i)+nbp_lon)
 !
 !    print*,'CFMIP_iophy point i lon lon_bds',i,plon_bounds(i,1),rlon_glo(tabij(i)),plon_bounds(i,2) 
@@ -351,12 +355,12 @@
      ENDDO
 
-       CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon_glo,zx_lon)
-       if ((iim*jjm).gt.1) then
-       DO i = 1, iim
+       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlon_glo,zx_lon)
+       if ((nbp_lon*nbp_lat).gt.1) then
+       DO i = 1, nbp_lon
          zx_lon(i,1) = rlon_glo(i+1)
-         zx_lon(i,jjmp1) = rlon_glo(i+1)
+         zx_lon(i,nbp_lat) = rlon_glo(i+1)
        ENDDO
        endif
-       CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat_glo,zx_lat)
+       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlat_glo,zx_lat)
 
     DO i=1,pim
@@ -367,9 +371,9 @@
 
      if (ipt(i).EQ.1) then
-      plon_bounds(i,1)=zx_lon(iim,jpt(i))
+      plon_bounds(i,1)=zx_lon(nbp_lon,jpt(i))
       plon_bounds(i,2)=360.+zx_lon(ipt(i)+1,jpt(i))
      endif
  
-     if (ipt(i).EQ.iim) then
+     if (ipt(i).EQ.nbp_lon) then
       plon_bounds(i,2)=360.+zx_lon(1,jpt(i))
      endif
@@ -383,7 +387,7 @@
      endif
  
-     if (jpt(i).EQ.jjmp1) then
-      plat_bounds(i,1)=zx_lat(ipt(i),jjmp1)+0.001
-      plat_bounds(i,2)=zx_lat(ipt(i),jjmp1)-0.001
+     if (jpt(i).EQ.nbp_lat) then
+      plat_bounds(i,1)=zx_lat(ipt(i),nbp_lat)+0.001
+      plat_bounds(i,2)=zx_lat(ipt(i),nbp_lat)-0.001
      endif
 !
@@ -451,8 +455,7 @@
     use phys_output_var_mod, only: type_ecri, zoutm, zdtime_moy, lev_files, &
                                    nid_files, nhorim, swaero_diag, nfiles
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
     IMPLICIT NONE
 
-    INCLUDE "dimensions.h"
-    INCLUDE "temps.h"
     INCLUDE "clesphys.h"
 
@@ -478,5 +481,5 @@
        IF ( flag_var(iff)<=lev_files(iff) ) THEN
           CALL histdef (nid_files(iff),nomvar,titrevar,unitvar, &
-               iim,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
+               nbp_lon,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
                type_ecri(iff), zstophym,zoutm(iff))                
        ENDIF
@@ -507,9 +510,7 @@
                                    nhorim, zdtime_moy, levmin, levmax, &
                                    nvertm, nfiles
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
     IMPLICIT NONE
 
-    INCLUDE "dimensions.h"
-    INCLUDE "temps.h"
-!    INCLUDE "indicesol.h"
     INCLUDE "clesphys.h"
 
@@ -535,5 +536,5 @@
        IF ( flag_var(iff)<=lev_files(iff) ) THEN
           CALL histdef (nid_files(iff), nomvar, titrevar, unitvar, &
-               iim, jj_nb, nhorim(iff), klev, levmin(iff), &
+               nbp_lon, jj_nb, nhorim(iff), klev, levmin(iff), &
                levmax(iff)-levmin(iff)+1, nvertm(iff), 32, type_ecri(iff), &
                zstophym, zoutm(iff))
@@ -563,4 +564,6 @@
                                    clef_stations, phys_out_filenames, lev_files, &
                                    nid_files, nhorim, swaero_diag
+    USE print_control_mod, ONLY: prt_level,lunout 
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
 #ifdef CPP_XIOS
     use wxios, only: wxios_add_field_to_file
@@ -568,8 +571,5 @@
     IMPLICIT NONE
 
-    INCLUDE "dimensions.h"
-    INCLUDE "temps.h"
     INCLUDE "clesphys.h"
-    INCLUDE "iniprint.h"
 
     INTEGER                          :: iff
@@ -621,5 +621,5 @@
        IF ( var%flag(iff)<=lev_files(iff) ) THEN
           CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
-               iim,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
+               nbp_lon,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
                typeecrit, zstophym,zoutm(iff))                
        ENDIF
@@ -650,4 +650,6 @@
                                    nid_files, nhorim, swaero_diag, levmin, &
                                    levmax, nvertm
+    USE print_control_mod, ONLY: prt_level,lunout
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
 #ifdef CPP_XIOS
     use wxios, only: wxios_add_field_to_file
@@ -655,8 +657,5 @@
     IMPLICIT NONE
 
-    INCLUDE "dimensions.h"
-    INCLUDE "temps.h"
     INCLUDE "clesphys.h"
-    INCLUDE "iniprint.h"
 
     INTEGER                          :: iff
@@ -708,5 +707,5 @@
        IF ( var%flag(iff)<=lev_files(iff) ) THEN
           CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
-               iim, jj_nb, nhorim(iff), klev, levmin(iff), &
+               nbp_lon, jj_nb, nhorim(iff), klev, levmin(iff), &
                levmax(iff)-levmin(iff)+1, nvertm(iff), 32, typeecrit, &
                zstophym, zoutm(iff))
@@ -728,7 +727,6 @@
     use ioipsl, only: getin
     use phys_output_var_mod, only: nfiles
+    USE print_control_mod, ONLY: prt_level,lunout
     IMPLICIT NONE
-
-    include 'iniprint.h'
 
     CHARACTER(LEN=20)                :: nam_var
@@ -750,7 +748,7 @@
                                 jj_nb, klon_mpi
   USE ioipsl, only: histwrite
+  USE print_control_mod, ONLY: prt_level,lunout
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
   IMPLICIT NONE
-  include 'dimensions.h'
-  include 'iniprint.h'
     
     integer,INTENT(IN) :: nid
@@ -761,5 +759,5 @@
     REAL,DIMENSION(klon_mpi) :: buffer_omp
     INTEGER, allocatable, DIMENSION(:) :: index2d
-    REAL :: Field2d(iim,jj_nb)
+    REAL :: Field2d(nbp_lon,jj_nb)
 
     integer :: ip
@@ -767,5 +765,5 @@
 
 
-    IF (size(field)/=klon) CALL abort_gcm('iophy::histwrite2d','Field first DIMENSION not equal to klon',1)
+    IF (size(field)/=klon) CALL abort_physic('iophy::histwrite2d','Field first DIMENSION not equal to klon',1)
     
     CALL Gather_omp(field,buffer_omp)    
@@ -773,8 +771,8 @@
     CALL grid1Dto2D_mpi(buffer_omp,Field2d)
     if(.NOT.lpoint) THEN
-     ALLOCATE(index2d(iim*jj_nb))
-     ALLOCATE(fieldok(iim*jj_nb))
+     ALLOCATE(index2d(nbp_lon*jj_nb))
+     ALLOCATE(fieldok(nbp_lon*jj_nb))
      IF (prt_level >= 10) write(lunout,*)'Sending ',name,' to IOIPSL'
-     CALL histwrite(nid,name,itau,Field2d,iim*jj_nb,index2d)
+     CALL histwrite(nid,name,itau,Field2d,nbp_lon*jj_nb,index2d)
      IF (prt_level >= 10) write(lunout,*)'Finished sending ',name,' to IOIPSL'
     else
@@ -814,8 +812,8 @@
                                 is_sequential, klon_mpi_begin, klon_mpi_end, &
                                 jj_nb, klon_mpi
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
   use ioipsl, only: histwrite
+  USE print_control_mod, ONLY: prt_level,lunout
   IMPLICIT NONE
-  include 'dimensions.h'
-  include 'iniprint.h'
     
     integer,INTENT(IN) :: nid
@@ -825,5 +823,5 @@
     REAL,DIMENSION(:,:),INTENT(IN) :: field  ! --> field(klon,:)
     REAL,DIMENSION(klon_mpi,size(field,2)) :: buffer_omp
-    REAL :: Field3d(iim,jj_nb,size(field,2))
+    REAL :: Field3d(nbp_lon,jj_nb,size(field,2))
     INTEGER :: ip, n, nlev
     INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
@@ -831,5 +829,5 @@
 
 
-    IF (size(field,1)/=klon) CALL abort_gcm('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
+    IF (size(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
     nlev=size(field,2)
 
@@ -838,8 +836,8 @@
     CALL grid1Dto2D_mpi(buffer_omp,field3d)
     if(.NOT.lpoint) THEN
-     ALLOCATE(index3d(iim*jj_nb*nlev))
-     ALLOCATE(fieldok(iim*jj_nb,nlev))
+     ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
+     ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
      IF (prt_level >= 10) write(lunout,*)'Sending ',name,' to IOIPSL'
-     CALL histwrite(nid,name,itau,Field3d,iim*jj_nb*nlev,index3d)
+     CALL histwrite(nid,name,itau,Field3d,nbp_lon*jj_nb*nlev,index3d)
      IF (prt_level >= 10) write(lunout,*)'Finished sending ',name,' to IOIPSL'
    else
@@ -889,4 +887,6 @@
                                  nfiles, vars_defined, clef_stations, &
                                  nid_files
+  USE print_control_mod, ONLY: prt_level,lunout
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
 #ifdef CPP_XIOS
   USE xios, only: xios_send_field
@@ -895,6 +895,4 @@
 
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'
-  INCLUDE 'iniprint.h'
   include 'clesphys.h'
 
@@ -909,5 +907,5 @@
     REAL,DIMENSION(klon_mpi) :: buffer_omp
     INTEGER, allocatable, DIMENSION(:) :: index2d
-    REAL :: Field2d(iim,jj_nb)
+    REAL :: Field2d(nbp_lon,jj_nb)
 
     INTEGER :: ip
@@ -945,5 +943,5 @@
 
     !Et sinon on.... écrit
-    IF (SIZE(field)/=klon) CALL abort_gcm('iophy::histwrite2d_phy','Field first DIMENSION not equal to klon',1)
+    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_phy','Field first DIMENSION not equal to klon',1)
     
     if (prt_level >= 10) then
@@ -971,5 +969,5 @@
           endif
 #else
-        CALL abort_gcm ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
+        CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
 #endif
       ELSE  
@@ -990,8 +988,8 @@
 
                   IF(.NOT.clef_stations(iff)) THEN
-                        ALLOCATE(index2d(iim*jj_nb))
-                        ALLOCATE(fieldok(iim*jj_nb))
+                        ALLOCATE(index2d(nbp_lon*jj_nb))
+                        ALLOCATE(fieldok(nbp_lon*jj_nb))
 #ifndef CPP_IOIPSL_NO_OUTPUT 
-                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field2d,iim*jj_nb,index2d)
+                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field2d,nbp_lon*jj_nb,index2d)
 #endif
 !#ifdef CPP_XIOS
@@ -1049,12 +1047,11 @@
                                  nfiles, vars_defined, clef_stations, &
                                  nid_files
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
 #ifdef CPP_XIOS
   USE xios, only: xios_send_field
 #endif
-
+  USE print_control_mod, ONLY: prt_level,lunout
 
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'
-  INCLUDE 'iniprint.h'
   include 'clesphys.h'
 
@@ -1067,5 +1064,5 @@
 !$OMP THREADPRIVATE(firstx)
     REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
-    REAL :: Field3d(iim,jj_nb,SIZE(field,2))
+    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
     INTEGER :: ip, n, nlev, nlevx
     INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
@@ -1095,5 +1092,5 @@
   ELSE
     !Et sinon on.... écrit
-    IF (SIZE(field,1)/=klon) CALL abort_gcm('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
+    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
     nlev=SIZE(field,2)
     if (nlev.eq.klev+1) then
@@ -1119,5 +1116,5 @@
           CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
 #else
-        CALL abort_gcm ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
+        CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
 #endif
       ELSE  
@@ -1133,5 +1130,5 @@
                   write(lunout,*)'histwrite3d_phy: call xios_send_field for ', &
                                   trim(var%name), ' with iim jjm nlevx = ', &
-                                  iim,jj_nb,nlevx
+                                  nbp_lon,jj_nb,nlevx
                 endif
                 CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
@@ -1140,9 +1137,9 @@
 #endif
                 IF (.NOT.clef_stations(iff)) THEN
-                        ALLOCATE(index3d(iim*jj_nb*nlev))
-                        ALLOCATE(fieldok(iim*jj_nb,nlev))
+                        ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
+                        ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
 
 #ifndef CPP_IOIPSL_NO_OUTPUT 
-                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field3d,iim*jj_nb*nlev,index3d)
+                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field3d,nbp_lon*jj_nb*nlev,index3d)
 #endif
 
@@ -1196,10 +1193,9 @@
                                 is_sequential, klon_mpi_begin, klon_mpi_end, &
                                 jj_nb, klon_mpi
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
   USE xios, only: xios_send_field
-
+  USE print_control_mod, ONLY: prt_level,lunout
 
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'
-  INCLUDE 'iniprint.h'
 
     CHARACTER(LEN=*), INTENT(IN) :: field_name
@@ -1208,5 +1204,5 @@
     REAL,DIMENSION(klon_mpi) :: buffer_omp
     INTEGER, allocatable, DIMENSION(:) :: index2d
-    REAL :: Field2d(iim,jj_nb)
+    REAL :: Field2d(nbp_lon,jj_nb)
 
     INTEGER :: ip
@@ -1216,5 +1212,5 @@
 
     !Et sinon on.... écrit
-    IF (SIZE(field)/=klon) CALL abort_gcm('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon',1)
+    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon',1)
     
     CALL Gather_omp(field,buffer_omp)    
@@ -1227,6 +1223,6 @@
     !IF(.NOT.clef_stations(iff)) THEN
     IF (.TRUE.) THEN
-        ALLOCATE(index2d(iim*jj_nb))
-        ALLOCATE(fieldok(iim*jj_nb))
+        ALLOCATE(index2d(nbp_lon*jj_nb))
+        ALLOCATE(fieldok(nbp_lon*jj_nb))
 
 
@@ -1268,9 +1264,8 @@
                                 jj_nb, klon_mpi
   USE xios, only: xios_send_field
-
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
+  USE print_control_mod, ONLY: prt_level,lunout
 
   IMPLICIT NONE
-  INCLUDE 'dimensions.h'
-  INCLUDE 'iniprint.h'
 
     CHARACTER(LEN=*), INTENT(IN) :: field_name
@@ -1278,5 +1273,5 @@
 
     REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
-    REAL :: Field3d(iim,jj_nb,SIZE(field,2))
+    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
     INTEGER :: ip, n, nlev
     INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
@@ -1286,5 +1281,5 @@
 
     !Et on.... écrit
-    IF (SIZE(field,1)/=klon) CALL abort_gcm('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
+    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
     nlev=SIZE(field,2)
 
@@ -1299,6 +1294,6 @@
     !IF (.NOT.clef_stations(iff)) THEN
     IF(.TRUE.)THEN
-        ALLOCATE(index3d(iim*jj_nb*nlev))
-        ALLOCATE(fieldok(iim*jj_nb,nlev))
+        ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
+        ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
         CALL xios_send_field(field_name, Field3d(:,:,1:nlev))
                         
Index: /LMDZ5/branches/testing/libf/phylmd/iostart.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/iostart.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/iostart.F90	(revision 2408)
@@ -41,5 +41,5 @@
         write(6,*)' Pb d''ouverture du fichier '//filename
         write(6,*)' ierr = ', ierr
-        CALL ABORT_GCM("", "", 1)
+        CALL abort_physic("", "", 1)
       ENDIF
     ENDIF
@@ -166,5 +166,5 @@
       IF (.NOT. tmp_found) THEN
         PRINT*, 'phyetat0: Le champ <'//field_name//'> est absent'
-        call abort_gcm("", "", 1)
+        call abort_physic("", "", 1)
       ENDIF
     ENDIF
@@ -186,10 +186,10 @@
               IF (ierr/=NF90_NOERR) THEN
                  PRINT*, 'phyetat0: Lecture echouee aussi en 2D pour <'//field_name//'>'
-                 call abort_gcm("", "", 1)
+                 call abort_physic("", "", 1)
               ELSE
                  PRINT*, 'phyetat0: La variable <'//field_name//'> lu sur surface seulement'!, selon ancien format, le reste mis a zero'
               END IF
            ELSE
-              call abort_gcm("", "", 1)
+              call abort_physic("", "", 1)
            ENDIF
          ENDIF
@@ -282,5 +282,5 @@
         IF (ierr/=NF90_NOERR) THEN
           PRINT*, 'phyetat0: Lecture echouee pour <'//var_name//'>'
-          call abort_gcm("", "", 1)
+          call abort_physic("", "", 1)
         ENDIF
         tmp_found=.TRUE.
@@ -302,5 +302,5 @@
       IF (.NOT. tmp_found) THEN
         PRINT*, 'phyetat0: La variable champ <'//var_name//'> est absente'
-        call abort_gcm("", "", 1)
+        call abort_physic("", "", 1)
       ENDIF
     ENDIF
@@ -323,5 +323,5 @@
         write(6,*)' Pb d''ouverture du fichier '//filename
         write(6,*)' ierr = ', ierr
-        CALL ABORT_GCM("", "", 1)
+        CALL abort_physic("", "", 1)
       ENDIF
 
@@ -410,5 +410,5 @@
       ELSE
         PRINT *, "erreur phyredem : probleme de dimension"
-        CALL ABORT_GCM("", "", 1)
+        CALL abort_physic("", "", 1)
       ENDIF
          
@@ -487,5 +487,5 @@
       IF (var_size/=length) THEN
         PRINT *, "erreur phyredem : probleme de dimension"
-        call abort_gcm("", "", 1)
+        call abort_physic("", "", 1)
       ENDIF
       
Index: DZ5/branches/testing/libf/phylmd/limit_netcdf.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/limit_netcdf.F90	(revision 2407)
+++ 	(revision )
@@ -1,667 +1,0 @@
-!
-! $Id: limit_netcdf.F90 1508 2011-04-15 13:05:34Z jghattas $
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE limit_netcdf(interbar, extrap, oldice, masque)
-#ifndef CPP_1D
-!
-!-------------------------------------------------------------------------------
-! Author : L. Fairhead, 27/01/94
-!-------------------------------------------------------------------------------
-! Purpose: Boundary conditions files building for new model using climatologies.
-!          Both grids have to be regular.
-!-------------------------------------------------------------------------------
-! Note: This routine is designed to work for Earth
-!-------------------------------------------------------------------------------
-! Modification history:
-!  * 23/03/1994: Z. X. Li
-!  *    09/1999: L. Fairhead (netcdf reading in LMDZ.3.3)
-!  *    07/2001: P. Le Van
-!  *    11/2009: L. Guez     (ozone day & night climatos, see etat0_netcdf.F90)
-!  *    12/2009: D. Cugnet   (f77->f90, calendars, files from coupled runs)
-!-------------------------------------------------------------------------------
-  USE control_mod
-  USE indice_sol_mod
-#ifdef CPP_EARTH
-  USE dimphy
-  USE ioipsl,             ONLY : ioget_year_len
-  USE phys_state_var_mod, ONLY : pctsrf, rlon, rlat
-  USE netcdf,             ONLY : NF90_OPEN,    NF90_CREATE,  NF90_CLOSE,       &
-                   NF90_DEF_DIM, NF90_DEF_VAR, NF90_PUT_VAR, NF90_PUT_ATT,     &
-                   NF90_NOERR,   NF90_NOWRITE, NF90_DOUBLE,  NF90_GLOBAL,      &
-		   NF90_CLOBBER, NF90_ENDDEF,  NF90_UNLIMITED, NF90_FLOAT
-  USE inter_barxy_m, only: inter_barxy
-  use netcdf95, only: nf95_def_var, nf95_put_att, nf95_put_var
-#endif
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-#include "dimensions.h"
-#include "paramet.h"
-#include "iniprint.h"
-  LOGICAL,                    INTENT(IN) :: interbar ! barycentric interpolation
-  LOGICAL,                    INTENT(IN) :: extrap   ! SST extrapolation flag
-  LOGICAL,                    INTENT(IN) :: oldice   ! old way ice computation
-  REAL, DIMENSION(iip1,jjp1), INTENT(IN) :: masque   ! land mask
-#ifndef CPP_EARTH
-  CALL abort_gcm('limit_netcdf','Earth-specific routine, needs Earth physics',1)
-#else
-!-------------------------------------------------------------------------------
-! Local variables:
-#include "logic.h"
-#include "comvert.h"
-#include "comgeom2.h"
-#include "comconst.h"
-
-!--- INPUT NETCDF FILES NAMES --------------------------------------------------
-  CHARACTER(LEN=25) :: icefile, sstfile, dumstr
-  CHARACTER(LEN=25), PARAMETER :: famipsst ='amipbc_sst_1x1.nc        ',        &
-                                  famipsic ='amipbc_sic_1x1.nc        ',        &
-                                  fcpldsst ='cpl_atm_sst.nc           ',        &
-                                  fcpldsic ='cpl_atm_sic.nc           ',        &
-                                  fhistsst ='histmth_sst.nc           ',        &
-                                  fhistsic ='histmth_sic.nc           ',        &
-                                  frugo    ='Rugos.nc                 ',        &
-                                  falbe    ='Albedo.nc                ',        &
-                                  feraisstk='sstk.nc                  ',        &
-                                  feraici  ='ci.nc                    '
-  CHARACTER(LEN=10) :: varname
-!--- OUTPUT VARIABLES FOR NETCDF FILE ------------------------------------------
-  REAL,   DIMENSION(klon)                :: fi_ice, verif
-  REAL,   DIMENSION(:,:),   POINTER      :: phy_rug=>NULL(), phy_ice=>NULL()
-  REAL,   DIMENSION(:,:),   POINTER      :: phy_sst=>NULL(), phy_alb=>NULL()
-  REAL,   DIMENSION(:,:),   ALLOCATABLE  :: phy_bil
-  REAL,   DIMENSION(:,:,:), ALLOCATABLE  :: pctsrf_t
-  INTEGER                                :: nbad
-
-!--- VARIABLES FOR OUTPUT FILE WRITING -----------------------------------------
-  INTEGER :: ierr, nid, ndim, ntim, k
-  INTEGER, DIMENSION(2) :: dims
-  INTEGER :: id_tim,  id_SST,  id_BILS, id_RUG, id_ALB
-  INTEGER :: id_FOCE, id_FSIC, id_FTER, id_FLIC, varid_longitude, varid_latitude
-  INTEGER :: NF90_FORMAT
-  INTEGER :: ndays                   !--- Depending on the output calendar
-
-!--- INITIALIZATIONS -----------------------------------------------------------
-#ifdef NC_DOUBLE
-  NF90_FORMAT=NF90_DOUBLE
-#else
-  NF90_FORMAT=NF90_FLOAT
-#endif
-
-  pi    = 4.*ATAN(1.)
-  rad   = 6371229.
-  daysec= 86400.
-  omeg  = 2.*pi/daysec
-  g     = 9.8
-  kappa = 0.2857143
-  cpp   = 1004.70885
-  dtvr  = daysec/REAL(day_step)
-  CALL inigeom
-
-!--- Beware: anneeref (from gcm.def) is used to determine output time sampling
-  ndays=ioget_year_len(anneeref)
-
-!--- RUGOSITY TREATMENT --------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la rugosite'
-  varname='RUGOS'
-  CALL get_2Dfield(frugo,varname,'RUG',interbar,ndays,phy_rug,mask=masque(1:iim,:))
-
-!--- OCEAN TREATMENT -----------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la glace oceanique'
-
-! Input SIC file selection
-! Open file only to test if available
-  IF ( NF90_OPEN(TRIM(famipsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     icefile=TRIM(famipsic)
-     varname='sicbcs'
-  ELSE IF( NF90_OPEN(TRIM(fcpldsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     icefile=TRIM(fcpldsic)
-     varname='SIICECOV'
-  ELSE IF ( NF90_OPEN(TRIM(fhistsic),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     icefile=TRIM(fhistsic)
-     varname='pourc_sic'
-  ELSE IF ( NF90_OPEN(TRIM(feraici),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     icefile=TRIM(feraici)
-     varname='ci'
-  ELSE
-     WRITE(lunout,*) 'ERROR! No sea-ice input file was found.'
-
-     WRITE(lunout,*) 'One of following files must be availible : ',trim(famipsic),', ',trim(fcpldsic),', ', &
-                      trim(fhistsic), trim(feraici)
-
-     CALL abort_gcm('limit_netcdf','No sea-ice file was found',1)
-  END IF
-  ierr=NF90_CLOSE(nid)
-  IF (prt_level>=0) WRITE(lunout,*)'Pour la glace de mer a ete choisi le fichier '//TRIM(icefile)
-
-  CALL get_2Dfield(icefile,varname, 'SIC',interbar,ndays,phy_ice,flag=oldice)
-
-  ALLOCATE(pctsrf_t(klon,nbsrf,ndays))
-  DO k=1,ndays
-     fi_ice=phy_ice(:,k)
-     WHERE(fi_ice>=1.0  ) fi_ice=1.0
-     WHERE(fi_ice<EPSFRA) fi_ice=0.0
-     pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)       ! land soil
-     pctsrf_t(:,is_lic,k)=pctsrf(:,is_lic)       ! land ice
-     IF (icefile==trim(fcpldsic)) THEN           ! SIC=pICE*(1-LIC-TER)
-        pctsrf_t(:,is_sic,k)=fi_ice(:)*(1.-pctsrf(:,is_lic)-pctsrf(:,is_ter))
-     ELSE IF (icefile==trim(fhistsic)) THEN      ! SIC=pICE
-        pctsrf_t(:,is_sic,k)=fi_ice(:)
-     ELSE ! icefile==famipsic                    ! SIC=pICE-LIC
-        pctsrf_t(:,is_sic,k)=fi_ice-pctsrf_t(:,is_lic,k)
-     END IF
-     WHERE(pctsrf_t(:,is_sic,k)<=0) pctsrf_t(:,is_sic,k)=0.
-     WHERE(1.0-zmasq<EPSFRA)
-        pctsrf_t(:,is_sic,k)=0.0
-        pctsrf_t(:,is_oce,k)=0.0
-     ELSEWHERE
-        WHERE(pctsrf_t(:,is_sic,k)>=1.0-zmasq)
-           pctsrf_t(:,is_sic,k)=1.0-zmasq
-           pctsrf_t(:,is_oce,k)=0.0
-        ELSEWHERE
-           pctsrf_t(:,is_oce,k)=1.0-zmasq-pctsrf_t(:,is_sic,k)
-           WHERE(pctsrf_t(:,is_oce,k)<EPSFRA)
-              pctsrf_t(:,is_oce,k)=0.0
-              pctsrf_t(:,is_sic,k)=1.0-zmasq
-           END WHERE
-        END WHERE
-     END WHERE
-     nbad=COUNT(pctsrf_t(:,is_oce,k)<0.0)
-     IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb point = ',nbad
-     nbad=COUNT(abs(sum(pctsrf_t(:,:,k),dim=2)-1.0)>EPSFRA)
-     IF(nbad>0) WRITE(lunout,*) 'pb sous surface pour nb points = ',nbad
-  END DO
-  DEALLOCATE(phy_ice)
-
-!--- SST TREATMENT -------------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de la sst'
-
-! Input SST file selection
-! Open file only to test if available
-  IF ( NF90_OPEN(TRIM(famipsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     sstfile=TRIM(famipsst)
-     varname='tosbcs'
-  ELSE IF ( NF90_OPEN(TRIM(fcpldsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     sstfile=TRIM(fcpldsst)
-     varname='SISUTESW'
-  ELSE IF ( NF90_OPEN(TRIM(fhistsst),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     sstfile=TRIM(fhistsst)
-     varname='tsol_oce'
-  ELSE IF ( NF90_OPEN(TRIM(feraisstk),NF90_NOWRITE,nid)==NF90_NOERR ) THEN
-     sstfile=TRIM(feraisstk)
-     varname='sstk'
-  ELSE
-     WRITE(lunout,*) 'ERROR! No sst input file was found.'
-     WRITE(lunout,*) 'One of following files must be availible : ',trim(famipsst),trim(fcpldsst),trim(fhistsst),trim(feraisstk)
-     CALL abort_gcm('limit_netcdf','No sst file was found',1)
-  END IF
-  ierr=NF90_CLOSE(nid)
-  IF (prt_level>=0) WRITE(lunout,*)'Pour la temperature de mer a ete choisi un fichier '//TRIM(sstfile)
-
-  CALL get_2Dfield(sstfile,varname,'SST',interbar,ndays,phy_sst,flag=extrap)
-
-!--- ALBEDO TREATMENT ----------------------------------------------------------
-  IF (prt_level>1) WRITE(lunout,*) 'Traitement de l albedo'
-  varname='ALBEDO'
-  CALL get_2Dfield(falbe,varname,'ALB',interbar,ndays,phy_alb)
-
-!--- REFERENCE GROUND HEAT FLUX TREATMENT --------------------------------------
-  ALLOCATE(phy_bil(klon,ndays)); phy_bil=0.0
-
-!--- OUTPUT FILE WRITING -------------------------------------------------------
-  IF (prt_level>5) WRITE(lunout,*) 'Ecriture du fichier limit : debut'
-
-  !--- File creation
-  ierr=NF90_CREATE("limit.nc",NF90_CLOBBER,nid)
-  ierr=NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier conditions aux limites")
-
-  !--- Dimensions creation
-  ierr=NF90_DEF_DIM(nid,"points_physiques",klon,ndim)
-  ierr=NF90_DEF_DIM(nid,"time",NF90_UNLIMITED,ntim)
-
-  dims=(/ndim,ntim/)
-
-  !--- Variables creation
-  ierr=NF90_DEF_VAR(nid,"TEMPS",NF90_FORMAT,(/ntim/),id_tim)
-  ierr=NF90_DEF_VAR(nid,"FOCE", NF90_FORMAT,dims,id_FOCE)
-  ierr=NF90_DEF_VAR(nid,"FSIC", NF90_FORMAT,dims,id_FSIC)
-  ierr=NF90_DEF_VAR(nid,"FTER", NF90_FORMAT,dims,id_FTER)
-  ierr=NF90_DEF_VAR(nid,"FLIC", NF90_FORMAT,dims,id_FLIC)
-  ierr=NF90_DEF_VAR(nid,"SST",  NF90_FORMAT,dims,id_SST)
-  ierr=NF90_DEF_VAR(nid,"BILS", NF90_FORMAT,dims,id_BILS)
-  ierr=NF90_DEF_VAR(nid,"ALB",  NF90_FORMAT,dims,id_ALB)
-  ierr=NF90_DEF_VAR(nid,"RUG",  NF90_FORMAT,dims,id_RUG)
-  call nf95_def_var(nid, "longitude", NF90_FLOAT, ndim, varid_longitude)
-  call nf95_def_var(nid, "latitude", NF90_FLOAT, ndim, varid_latitude)
-
-  !--- Attributes creation
-  ierr=NF90_PUT_ATT(nid,id_tim, "title","Jour dans l annee")
-  ierr=NF90_PUT_ATT(nid,id_FOCE,"title","Fraction ocean")
-  ierr=NF90_PUT_ATT(nid,id_FSIC,"title","Fraction glace de mer")
-  ierr=NF90_PUT_ATT(nid,id_FTER,"title","Fraction terre")
-  ierr=NF90_PUT_ATT(nid,id_FLIC,"title","Fraction land ice")
-  ierr=NF90_PUT_ATT(nid,id_SST ,"title","Temperature superficielle de la mer")
-  ierr=NF90_PUT_ATT(nid,id_BILS,"title","Reference flux de chaleur au sol")
-  ierr=NF90_PUT_ATT(nid,id_ALB, "title","Albedo a la surface")
-  ierr=NF90_PUT_ATT(nid,id_RUG, "title","Rugosite")
-
-  call nf95_put_att(nid, varid_longitude, "standard_name", "longitude")
-  call nf95_put_att(nid, varid_longitude, "units", "degrees_east")
-
-  call nf95_put_att(nid, varid_latitude, "standard_name", "latitude")
-  call nf95_put_att(nid, varid_latitude, "units", "degrees_north")
-
-  ierr=NF90_ENDDEF(nid)
-
-  !--- Variables saving
-  ierr=NF90_PUT_VAR(nid,id_tim,(/(REAL(k),k=1,ndays)/))
-  ierr=NF90_PUT_VAR(nid,id_FOCE,pctsrf_t(:,is_oce,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FSIC,pctsrf_t(:,is_sic,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FTER,pctsrf_t(:,is_ter,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_FLIC,pctsrf_t(:,is_lic,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_SST ,phy_sst(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_BILS,phy_bil(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_ALB ,phy_alb(:,:),(/1,1/),(/klon,ndays/))
-  ierr=NF90_PUT_VAR(nid,id_RUG ,phy_rug(:,:),(/1,1/),(/klon,ndays/))
-  call nf95_put_var(nid, varid_longitude, rlon)
-  call nf95_put_var(nid, varid_latitude, rlat)
-
-  ierr=NF90_CLOSE(nid)
-
-  IF (prt_level>5) WRITE(lunout,*) 'Ecriture du fichier limit : fin'
-
-  DEALLOCATE(pctsrf_t,phy_sst,phy_bil,phy_alb,phy_rug)
-
-
-!===============================================================================
-!
-  CONTAINS
-!
-!===============================================================================
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE get_2Dfield(fnam, varname, mode, ibar, ndays, champo, flag, mask)
-!
-!-----------------------------------------------------------------------------
-! Comments:
-!   There are two assumptions concerning the NetCDF files, that are satisfied
-!   with files that are conforming NC convention:
-!     1) The last dimension of the variables used is the time record.
-!     2) Dimensional variables have the same names as corresponding dimensions.
-!-----------------------------------------------------------------------------
-  USE netcdf, ONLY: NF90_OPEN, NF90_INQ_VARID, NF90_INQUIRE_VARIABLE, &
-       NF90_CLOSE, NF90_INQ_DIMID, NF90_INQUIRE_DIMENSION, NF90_GET_VAR, &
-       NF90_GET_ATT
-  USE dimphy, ONLY : klon
-  USE phys_state_var_mod, ONLY : pctsrf
-  USE control_mod
-  USE pchsp_95_m, only: pchsp_95
-  USE pchfe_95_m, only: pchfe_95
-  USE arth_m, only: arth
-  USE indice_sol_mod
-
-  IMPLICIT NONE
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom2.h"
-#include "iniprint.h"
-!-----------------------------------------------------------------------------
-! Arguments:
-  CHARACTER(LEN=*),  INTENT(IN)     :: fnam     ! NetCDF file name
-  CHARACTER(LEN=10), INTENT(IN)     :: varname  ! NetCDF variable name
-  CHARACTER(LEN=3),  INTENT(IN)     :: mode     ! RUG, SIC, SST or ALB
-  LOGICAL,           INTENT(IN)     :: ibar     ! interp on pressure levels
-  INTEGER,           INTENT(IN)     :: ndays    ! current year number of days
-  REAL,    POINTER,  DIMENSION(:, :) :: champo  ! output field = f(t)
-  LOGICAL, OPTIONAL, INTENT(IN)     :: flag     ! extrapol. (SST) old ice (SIC)
-  REAL,    OPTIONAL, DIMENSION(iim, jjp1), INTENT(IN) :: mask
-!------------------------------------------------------------------------------
-! Local variables:
-!--- NetCDF
-  INTEGER :: ncid, varid                  ! NetCDF identifiers
-  CHARACTER(LEN=30)               :: dnam       ! dimension name
-!--- dimensions
-  INTEGER,           DIMENSION(4) :: dids       ! NetCDF dimensions identifiers
-  REAL, ALLOCATABLE, DIMENSION(:) :: dlon_ini   ! initial longitudes vector
-  REAL, ALLOCATABLE, DIMENSION(:) :: dlat_ini   ! initial latitudes  vector
-  REAL, POINTER,     DIMENSION(:) :: dlon, dlat ! reordered lon/lat  vectors
-!--- fields
-  INTEGER :: imdep, jmdep, lmdep                ! dimensions of 'champ'
-  REAL, ALLOCATABLE, DIMENSION(:, :) :: champ   ! wanted field on initial grid
-  REAL, ALLOCATABLE, DIMENSION(:) :: yder, timeyear
-  REAL,              DIMENSION(iim, jjp1) :: champint   ! interpolated field
-  REAL, ALLOCATABLE, DIMENSION(:, :, :)    :: champtime
-  REAL, ALLOCATABLE, DIMENSION(:, :, :)    :: champan
-!--- input files
-  CHARACTER(LEN=20)                 :: cal_in   ! calendar
-  CHARACTER(LEN=20)                 :: unit_sic ! attribute unit in sea-ice file
-  INTEGER                           :: ndays_in ! number of days
-!--- misc
-  INTEGER :: i, j, k, l                         ! loop counters
-  REAL, ALLOCATABLE, DIMENSION(:, :) :: work     ! used for extrapolation
-  CHARACTER(LEN=25)                 :: title    ! for messages
-  LOGICAL                           :: extrp    ! flag for extrapolation
-  LOGICAL                           :: oldice   ! flag for old way ice computation 
-  REAL                              :: chmin, chmax
-  INTEGER ierr
-  integer n_extrap ! number of extrapolated points
-  logical skip
-
-!------------------------------------------------------------------------------
-!---Variables depending on keyword 'mode' -------------------------------------
-  NULLIFY(champo)
-
-  SELECT CASE(mode)
-  CASE('RUG'); title='Rugosite'
-  CASE('SIC'); title='Sea-ice'
-  CASE('SST'); title='SST'
-  CASE('ALB'); title='Albedo'
-  END SELECT
-  
-
-  extrp=.FALSE. 
-  oldice=.FALSE.
-  IF ( PRESENT(flag) ) THEN 
-    IF ( flag .AND. mode=='SST' ) extrp=.TRUE. 
-    IF ( flag .AND. mode=='SIC' ) oldice=.TRUE. 
-  END IF
-
-!--- GETTING SOME DIMENSIONAL VARIABLES FROM FILE -----------------------------
-  IF (prt_level>5) WRITE(lunout,*) ' Now reading file : ',fnam
-  ierr=NF90_OPEN(fnam, NF90_NOWRITE, ncid);             CALL ncerr(ierr, fnam)
-  ierr=NF90_INQ_VARID(ncid, trim(varname), varid);            CALL ncerr(ierr, fnam)
-  ierr=NF90_INQUIRE_VARIABLE(ncid, varid, dimids=dids); CALL ncerr(ierr, fnam)
-
-!--- Read unit for sea-ice variable only
-  IF (mode=='SIC') THEN
-     ierr=NF90_GET_ATT(ncid, varid, 'units', unit_sic)
-     IF(ierr/=NF90_NOERR) THEN
-        IF (prt_level>5) WRITE(lunout,*) 'No unit was given in sea-ice file. Take percentage as default value'
-        unit_sic='X'
-     ELSE
-        IF (prt_level>5) WRITE(lunout,*) ' Sea-ice cover has unit=',unit_sic
-     END IF
-  END IF
-
-!--- Longitude
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(1), name=dnam, len=imdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(dlon_ini(imdep), dlon(imdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  ierr=NF90_GET_VAR(ncid, varid, dlon_ini);              CALL ncerr(ierr, fnam)
-  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', imdep
-
-!--- Latitude
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(2), name=dnam, len=jmdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(dlat_ini(jmdep), dlat(jmdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  ierr=NF90_GET_VAR(ncid, varid, dlat_ini);              CALL ncerr(ierr, fnam)
-  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', jmdep
-
-!--- Time (variable is not needed - it is rebuilt - but calendar is)
-  ierr=NF90_INQUIRE_DIMENSION(ncid, dids(3), name=dnam, len=lmdep)
-  CALL ncerr(ierr, fnam); ALLOCATE(timeyear(lmdep))
-  ierr=NF90_INQ_VARID(ncid, dnam, varid);                CALL ncerr(ierr, fnam)
-  cal_in=' '
-  ierr=NF90_GET_ATT(ncid, varid, 'calendar', cal_in)
-  IF(ierr/=NF90_NOERR) THEN
-    SELECT CASE(mode)
-      CASE('RUG', 'ALB'); cal_in='360d'
-      CASE('SIC', 'SST'); cal_in='gregorian'
-    END SELECT
-    IF (prt_level>5) WRITE(lunout, *)'ATTENTION: variable "time" sans attribut "calendrier" ' &
-         // 'dans '//TRIM(fnam)//'. On choisit la valeur par defaut.'
-  END IF
-  IF (prt_level>5) WRITE(lunout, *) 'variable ', dnam, 'dimension ', lmdep, 'calendrier ', &
-       cal_in
-
-  
-!--- CONSTRUCTING THE INPUT TIME VECTOR FOR INTERPOLATION --------------------
-  !--- Determining input file number of days, depending on calendar
-  ndays_in=year_len(anneeref, cal_in)
-
-!--- Time vector reconstruction (time vector from file is not trusted)
-!--- If input records are not monthly, time sampling has to be constant !
-  timeyear=mid_months(anneeref, cal_in, lmdep)
-  IF (lmdep /= 12) WRITE(lunout,*) 'Note : les fichiers de ', TRIM(mode), &
-       ' ne comportent pas 12, mais ', lmdep, ' enregistrements.'
-
-!--- GETTING THE FIELD AND INTERPOLATING IT ----------------------------------
-  ALLOCATE(champ(imdep, jmdep), champtime(iim, jjp1, lmdep))
-  IF(extrp) ALLOCATE(work(imdep, jmdep))
-
-  IF (prt_level>5) WRITE(lunout, *)
-  IF (prt_level>5) WRITE(lunout,*)'LECTURE ET INTERPOLATION HORIZ. DE ', lmdep, ' CHAMPS.'
-  ierr=NF90_INQ_VARID(ncid, varname, varid);             CALL ncerr(ierr, fnam)
-  DO l=1, lmdep
-    ierr=NF90_GET_VAR(ncid, varid, champ, (/1, 1, l/), (/imdep, jmdep, 1/))
-    CALL ncerr(ierr, fnam)
-    CALL conf_dat2d(title, imdep, jmdep, dlon_ini, dlat_ini, dlon, dlat, &
-         champ, ibar)
-
-    IF (extrp) CALL extrapol(champ, imdep, jmdep, 999999., .TRUE., .TRUE., 2, &
-         work)
-
-    IF(ibar .AND. .NOT.oldice) THEN
-      IF(l==1 .AND. prt_level>5) THEN
-        WRITE(lunout, *) '-------------------------------------------------------------------------'
-        WRITE(lunout, *) 'Utilisation de l''interpolation barycentrique pour ',TRIM(title),' $$$'
-        WRITE(lunout, *) '-------------------------------------------------------------------------'
-      END IF
-      IF(mode=='RUG') champ=LOG(champ)
-      CALL inter_barxy(dlon, dlat(:jmdep-1), champ, rlonu(:iim),     &
-                         rlatv, champint)
-      IF(mode=='RUG') THEN
-        champint=EXP(champint)
-        WHERE(NINT(mask)/=1) champint=0.001
-      END IF
-    ELSE
-      SELECT CASE(mode)
-        CASE('RUG');       CALL rugosite(imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint, mask)
-        CASE('SIC');       CALL sea_ice (imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint)
-        CASE('SST', 'ALB'); CALL grille_m(imdep, jmdep, dlon, dlat, champ,    &
-                                    iim, jjp1, rlonv, rlatu, champint)
-      END SELECT
-    END IF
-    champtime(:, :, l)=champint
-  END DO
-  ierr=NF90_CLOSE(ncid);                                 CALL ncerr(ierr, fnam)
-
-  DEALLOCATE(dlon_ini, dlat_ini, dlon, dlat, champ)
-  IF(extrp) DEALLOCATE(work)
-
-!--- TIME INTERPOLATION ------------------------------------------------------
-  IF (prt_level>5) THEN
-     WRITE(lunout, *)
-     WRITE(lunout, *)'INTERPOLATION TEMPORELLE.'
-     WRITE(lunout, *)' Vecteur temps en entree: ', timeyear
-     WRITE(lunout, *)' Vecteur temps en sortie de 0 a ', ndays
-  END IF
-
-  ALLOCATE(yder(lmdep), champan(iip1, jjp1, ndays))
-  skip = .false.
-  n_extrap = 0
-  DO j=1, jjp1
-    DO i=1, iim
-      yder = pchsp_95(timeyear, champtime(i, j, :), ibeg=2, iend=2, &
-           vc_beg=0., vc_end=0.)
-      CALL pchfe_95(timeyear, champtime(i, j, :), yder, skip, &
-           arth(0., real(ndays_in) / ndays, ndays), champan(i, j, :), ierr)
-      if (ierr < 0) stop 1
-      n_extrap = n_extrap + ierr
-    END DO
-  END DO
-  if (n_extrap /= 0) then
-     WRITE(lunout,*) "get_2Dfield pchfe_95: n_extrap = ", n_extrap
-  end if
-  champan(iip1, :, :)=champan(1, :, :)
-  DEALLOCATE(yder, champtime, timeyear)
-
-!--- Checking the result
-  DO j=1, jjp1
-    CALL minmax(iip1, champan(1, j, 10), chmin, chmax)
-    IF (prt_level>5) WRITE(lunout, *)' ',TRIM(title),' au temps 10 ', chmin, chmax, j
-  END DO
-
-!--- SPECIAL FILTER FOR SST: SST>271.38 --------------------------------------
-  IF(mode=='SST') THEN
-    IF (prt_level>5) WRITE(lunout, *) 'Filtrage de la SST: SST >= 271.38'
-    WHERE(champan<271.38) champan=271.38
-  END IF
-
-!--- SPECIAL FILTER FOR SIC: 0.0<SIC<1.0 -------------------------------------
-  IF(mode=='SIC') THEN
-    IF (prt_level>5) WRITE(lunout, *) 'Filtrage de la SIC: 0.0 < Sea-ice < 1.0'
-
-    IF (unit_sic=='1') THEN
-       ! Nothing to be done for sea-ice field is already in fraction of 1
-       ! This is the case for sea-ice in file cpl_atm_sic.nc
-       IF (prt_level>5) WRITE(lunout,*) 'Sea-ice field already in fraction of 1'
-    ELSE
-       ! Convert sea ice from percentage to fraction of 1
-       IF (prt_level>5) WRITE(lunout,*) 'Transformt sea-ice field from percentage to fraction of 1.' 
-       champan(:, :, :)=champan(:, :, :)/100.
-    END IF
-
-    champan(iip1, :, :)=champan(1, :, :)
-    WHERE(champan>1.0) champan=1.0
-    WHERE(champan<0.0) champan=0.0
- END IF
-
-!--- DYNAMICAL TO PHYSICAL GRID ----------------------------------------------
-  ALLOCATE(champo(klon, ndays))
-  DO k=1, ndays
-    CALL gr_dyn_fi(1, iip1, jjp1, klon, champan(1, 1, k), champo(1, k))
-  END DO
-  DEALLOCATE(champan)
-
-END SUBROUTINE get_2Dfield
-!
-!-------------------------------------------------------------------------------
-
-
-
-!-------------------------------------------------------------------------------
-!
-FUNCTION year_len(y,cal_in)
-!
-!-------------------------------------------------------------------------------
-  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_year_len
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER                       :: year_len
-  INTEGER,           INTENT(IN) :: y
-  CHARACTER(LEN=*),  INTENT(IN) :: cal_in
-!-------------------------------------------------------------------------------
-! Local variables:
-  CHARACTER(LEN=20)             :: cal_out              ! calendar (for outputs)
-!-------------------------------------------------------------------------------
-!--- Getting the input calendar to reset at the end of the function
-  CALL ioget_calendar(cal_out)
-
-!--- Unlocking calendar and setting it to wanted one
-  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
-
-!--- Getting the number of days in this year
-  year_len=ioget_year_len(y)
-
-!--- Back to original calendar
-  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
-
-END FUNCTION year_len
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-FUNCTION mid_months(y,cal_in,nm)
-!
-!-------------------------------------------------------------------------------
-  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_mon_len
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER,                INTENT(IN) :: y               ! year
-  CHARACTER(LEN=*),       INTENT(IN) :: cal_in          ! calendar
-  INTEGER,                INTENT(IN) :: nm              ! months/year number
-  REAL,    DIMENSION(nm)             :: mid_months      ! mid-month times
-!-------------------------------------------------------------------------------
-! Local variables:
-  CHARACTER(LEN=99)                  :: mess            ! error message
-  CHARACTER(LEN=20)                  :: cal_out         ! calendar (for outputs)
-  INTEGER, DIMENSION(nm)             :: mnth            ! months lengths (days)
-  INTEGER                            :: m               ! months counter
-  INTEGER                            :: nd              ! number of days
-!-------------------------------------------------------------------------------
-  nd=year_len(y,cal_in)
-
-  IF(nm==12) THEN
-
-  !--- Getting the input calendar to reset at the end of the function
-    CALL ioget_calendar(cal_out)
-
-  !--- Unlocking calendar and setting it to wanted one
-    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
-
-  !--- Getting the length of each month
-    DO m=1,nm; mnth(m)=ioget_mon_len(y,m); END DO
-
-  !--- Back to original calendar
-    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
-
-  ELSE IF(MODULO(nd,nm)/=0) THEN
-    WRITE(mess,'(a,i3,a,i3,a)')'Unconsistent calendar: ',nd,' days/year, but ',&
-      nm,' months/year. Months number should divide days number.'
-    CALL abort_gcm('mid_months',TRIM(mess),1)
-
-  ELSE
-    mnth=(/(m,m=1,nm,nd/nm)/)
-  END IF
-
-!--- Mid-months times
-  mid_months(1)=0.5*REAL(mnth(1))
-  DO k=2,nm
-    mid_months(k)=mid_months(k-1)+0.5*REAL(mnth(k-1)+mnth(k))
-  END DO
-
-END FUNCTION mid_months
-!
-!-------------------------------------------------------------------------------
-
-
-!-------------------------------------------------------------------------------
-!
-SUBROUTINE ncerr(ncres,fnam)
-!
-!-------------------------------------------------------------------------------
-! Purpose: NetCDF errors handling.
-!-------------------------------------------------------------------------------
-  USE netcdf, ONLY : NF90_NOERR, NF90_STRERROR
-  IMPLICIT NONE
-!-------------------------------------------------------------------------------
-! Arguments:
-  INTEGER,          INTENT(IN) :: ncres
-  CHARACTER(LEN=*), INTENT(IN) :: fnam
-!-------------------------------------------------------------------------------
-#include "iniprint.h"
-  IF(ncres/=NF90_NOERR) THEN
-    WRITE(lunout,*)'Problem with file '//TRIM(fnam)//' in routine limit_netcdf.'
-    CALL abort_gcm('limit_netcdf',NF90_STRERROR(ncres),1)
-  END IF
-
-END SUBROUTINE ncerr
-!
-!-------------------------------------------------------------------------------
-
-#endif
-! of #ifdef CPP_EARTH
-
-#endif
-! of #ifndef CPP_1D
-END SUBROUTINE limit_netcdf
Index: /LMDZ5/branches/testing/libf/phylmd/limit_read_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/limit_read_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/limit_read_mod.F90	(revision 2408)
@@ -151,6 +151,4 @@
     IMPLICIT NONE
     
-    INCLUDE "iniprint.h"
-
 ! In- and ouput arguments
 !****************************************************************************************
@@ -195,10 +193,10 @@
        IF ( type_ocean /= 'couple' ) THEN
           ALLOCATE(pctsrf(klon,nbsrf), sst(klon), stat=ierr)
-          IF (ierr /= 0) CALL abort_gcm(modname, 'PB in allocating pctsrf and sst',1)
+          IF (ierr /= 0) CALL abort_physic(modname, 'PB in allocating pctsrf and sst',1)
        END IF
 
        IF ( .NOT. ok_veget ) THEN
           ALLOCATE(rugos(klon), albedo(klon), stat=ierr)
-          IF (ierr /= 0) CALL abort_gcm(modname, 'PB in allocating rugos and albedo',1)
+          IF (ierr /= 0) CALL abort_physic(modname, 'PB in allocating rugos and albedo',1)
        END IF
 
@@ -220,5 +218,5 @@
 
           ierr = NF90_OPEN ('limit.nc', NF90_NOWRITE, nid)
-          IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,&
+          IF (ierr /= NF90_NOERR) CALL abort_physic(modname,&
                'Pb d''ouverture du fichier de conditions aux limites',1)
           
@@ -239,15 +237,15 @@
 ! Ocean fraction
              ierr = NF90_INQ_VARID(nid, 'FOCE', nvarid)
-             IF (ierr /= NF90_NOERR) CALL abort_gcm(modname, 'Le champ <FOCE> est absent',1)
+             IF (ierr /= NF90_NOERR) CALL abort_physic(modname, 'Le champ <FOCE> est absent',1)
              
              ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_oce),start,epais)
-             IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Lecture echouee pour <FOCE>' ,1)
+             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FOCE>' ,1)
 !
 ! Sea-ice fraction
              ierr = NF90_INQ_VARID(nid, 'FSIC', nvarid)
-             IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Le champ <FSIC> est absent',1)
+             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <FSIC> est absent',1)
 
              ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_sic),start,epais)
-             IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Lecture echouee pour <FSIC>' ,1)
+             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FSIC>' ,1)
 
 
@@ -257,15 +255,15 @@
 ! Land fraction
                 ierr = NF90_INQ_VARID(nid, 'FTER', nvarid)
-                IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Le champ <FTER> est absent',1)
+                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <FTER> est absent',1)
                 
                 ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_ter),start,epais)
-                IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Lecture echouee pour <FTER>',1)
+                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FTER>',1)
 !
 ! Continentale ice fraction
                 ierr = NF90_INQ_VARID(nid, 'FLIC', nvarid)
-                IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Le champ <FLIC> est absent',1)
+                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <FLIC> est absent',1)
 
                 ierr = NF90_GET_VAR(nid,nvarid,pct_glo(:,is_lic),start,epais)
-                IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Lecture echouee pour <FLIC>',1)
+                IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <FLIC>',1)
              END IF
 
@@ -279,8 +277,8 @@
 
              ierr = NF90_INQ_VARID(nid, 'SST', nvarid)
-             IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Le champ <SST> est absent',1)
+             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <SST> est absent',1)
 
              ierr = NF90_GET_VAR(nid,nvarid,sst_glo,start,epais)
-             IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Lecture echouee pour <SST>',1)
+             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <SST>',1)
           
           END IF
@@ -295,15 +293,15 @@
 ! Read albedo
              ierr = NF90_INQ_VARID(nid, 'ALB', nvarid)
-             IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Le champ <ALB> est absent',1)
+             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <ALB> est absent',1)
 
              ierr = NF90_GET_VAR(nid,nvarid,alb_glo,start,epais)
-             IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Lecture echouee pour <ALB>',1)
+             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <ALB>',1)
 !
 ! Read rugosity
              ierr = NF90_INQ_VARID(nid, 'RUG', nvarid)
-             IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Le champ <RUG> est absent',1)
+             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Le champ <RUG> est absent',1)
 
              ierr = NF90_GET_VAR(nid,nvarid,rug_glo,start,epais)
-             IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Lecture echouee pour <RUG>',1)
+             IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Lecture echouee pour <RUG>',1)
 
           END IF
@@ -314,5 +312,5 @@
 !****************************************************************************************
           ierr = NF90_CLOSE(nid)
-          IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Pb when closing file', 1)
+          IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Pb when closing file', 1)
        ENDIF ! is_mpi_root
 
Index: /LMDZ5/branches/testing/libf/phylmd/limit_slab.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/limit_slab.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/limit_slab.F90	(revision 2408)
@@ -4,5 +4,5 @@
 
   USE dimphy
-  USE mod_grid_phy_lmdz
+  USE mod_grid_phy_lmdz, ONLY: klon_glo
   USE mod_phys_lmdz_para
   USE netcdf 
@@ -11,7 +11,5 @@
   IMPLICIT NONE
 
-  INCLUDE "temps.h"
   INCLUDE "clesphys.h"
-  INCLUDE "dimensions.h"
 
 ! In- and ouput arguments
@@ -113,5 +111,5 @@
 !****************************************************************************************
         ierr = NF90_CLOSE(nid)
-        IF (ierr /= NF90_NOERR) CALL abort_gcm(modname,'Pb when closing file', 1)
+        IF (ierr /= NF90_NOERR) CALL abort_physic(modname,'Pb when closing file', 1)
         END IF ! Read File
         IF (read_sst) THEN
@@ -133,5 +131,5 @@
      IF (.NOT. ALLOCATED(bils_save)) THEN
         ALLOCATE(bils_save(klon), diff_sst_save(klon), diff_siv_save(klon), stat=ierr)
-        IF (ierr /= 0) CALL abort_gcm('limit_slab', 'pb in allocation',1)
+        IF (ierr /= 0) CALL abort_physic('limit_slab', 'pb in allocation',1)
      END IF
 
Index: /LMDZ5/branches/testing/libf/phylmd/lsc_scav.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/lsc_scav.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/lsc_scav.F90	(revision 2408)
@@ -13,6 +13,5 @@
   USE mod_phys_lmdz_para
   USE traclmdz_mod
-  USE infotrac,ONLY : nbtr
-  USE comgeomphy
+  USE infotrac_phy,ONLY : nbtr
   USE iophy
   IMPLICIT NONE 
@@ -24,5 +23,4 @@
 !=====================================================================
 
-  include "dimensions.h"
   include "chem.h"
   include "YOMCST.h"
Index: /LMDZ5/branches/testing/libf/phylmd/minmaxqfi.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/minmaxqfi.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/minmaxqfi.F90	(revision 2408)
@@ -4,4 +4,5 @@
 SUBROUTINE minmaxqfi(zq,qmin,qmax,comment)
   USE dimphy
+  USE print_control_mod, ONLY: prt_level
   IMPLICIT NONE
 
@@ -15,6 +16,4 @@
   INTEGER                     :: i, jbad, k
 
-  include "iniprint.h"
-  
   DO k = 1, klev
      jbad = 0
Index: DZ5/branches/testing/libf/phylmd/mkstat.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/mkstat.F90	(revision 2407)
+++ 	(revision )
@@ -1,164 +1,0 @@
-subroutine mkstats(ierr)
-
- 
-!
-!  This program writes a stats.nc file from sums and sums of squares
-!  to means and standard deviations and also writes netcdf style
-!  file so that the data can be viewed easily.  The data file is
-!  overwritten in place.  
-!  SRL  21 May 1996
-!  Yann W. july 2003
-
-
-implicit none
-
-#include "dimensions.h"
-#include "statto.h"
-#include "netcdf.inc"
-
-integer,parameter :: iip1=iim+1
-integer,parameter :: jjp1=jjm+1
-integer :: ierr,nid,nbvar,i,ndims,lt,nvarid
-integer, dimension(4) :: id,varid,start,size
-integer, dimension(5) :: dimids
-character (len=50) :: name,nameout,units,title
-real, dimension(iip1,jjp1,llm) :: sum3d,square3d,mean3d,sd3d
-real, dimension(iip1,jjp1) :: sum2d,square2d,mean2d,sd2d
-real, dimension(istime) :: time
-real, dimension(jjp1) :: lat
-real, dimension(iip1) :: lon
-real, dimension(llm) :: alt
-logical :: lcopy=.true.
-!integer :: latid,lonid,altid,timeid
-integer :: meanid,sdid
-!integer, dimension(4) :: dimout
-
-! Incrementation of count for the last step, which is not done in wstats
-count(istime)=count(istime)+1
-
-ierr = NF_OPEN("stats.nc",NF_WRITE,nid)
-
-! We catch the id of dimensions of the stats file
-
-ierr= NF_INQ_DIMID(nid,"latitude",id(1))
-ierr= NF_INQ_DIMID(nid,"longitude",id(2))
-ierr= NF_INQ_DIMID(nid,"altitude",id(3))
-ierr= NF_INQ_DIMID(nid,"Time",id(4))
-
-ierr= NF_INQ_VARID(nid,"latitude",varid(1))
-ierr= NF_INQ_VARID(nid,"longitude",varid(2))
-ierr= NF_INQ_VARID(nid,"altitude",varid(3))
-ierr= NF_INQ_VARID(nid,"Time",varid(4))
-
-! Time initialisation
-
-do i=1,istime
-   time(i)=i*24./istime
-#ifdef NC_DOUBLE
-   ierr= NF_PUT_VARA_DOUBLE(nid,varid(4),i,1,time(i))
-#else
-   ierr= NF_PUT_VARA_REAL(nid,varid(4),i,1,time(i))
-#endif
-enddo
-
-! We catche the values of the variables
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,varid(1),lat)
-         ierr = NF_GET_VAR_DOUBLE(nid,varid(2),lon)
-         ierr = NF_GET_VAR_DOUBLE(nid,varid(3),alt)
-#else
-         ierr = NF_GET_VAR_REAL(nid,varid(1),lat)
-         ierr = NF_GET_VAR_REAL(nid,varid(2),lon)
-         ierr = NF_GET_VAR_REAL(nid,varid(3),alt)
-#endif
-
-! We catch the number of variables in the stats file
-ierr = NF_INQ_NVARS(nid,nbvar)
-
-! to catche the "real" number of variables (without the "additionnal variables")
-nbvar=(nbvar-4)/2 
-
-do i=1,nbvar
-   varid=(i-1)*2+5
-
-   ! What's the variable's name?
-   ierr=NF_INQ_VARNAME(nid,varid,name)
-   write(*,*) "OK variable ",name
-   ! Its units?
-   units=" "
-   ierr=NF_GET_ATT_TEXT(nid,varid,"units",units)
-   ! Its title?
-   title=" "
-   ierr=NF_GET_ATT_TEXT(nid,varid,"title",title)
-   ! Its number of dimensions?   
-   ierr=NF_INQ_VARNDIMS(nid,varid,ndims)
-   ! Its values?
-
-   if(ndims==4) then ! lat, lon, alt & time
-
-!      dimout(1)=lonid
-!      dimout(2)=latid
-!      dimout(3)=altid
-!      dimout(4)=timeid
-
-      size=(/iip1,jjp1,llm,1/)
-      do lt=1,istime
-         start=(/1,1,1,lt/)
-         ! Extraction of the "source" variables
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VARA_DOUBLE(nid,varid,start,size,sum3d)
-         ierr = NF_GET_VARA_DOUBLE(nid,varid+1,start,size,square3d)
-#else
-         ierr = NF_GET_VARA_REAL(nid,varid,start,size,sum3d)
-         ierr = NF_GET_VARA_REAL(nid,varid+1,start,size,square3d)
-#endif
-         ! Calculation of these variables
-         mean3d=sum3d/count(lt)
-         sd3d=sqrt(max(0.,square3d/count(lt)-mean3d**2))
-         ! Writing of the variables
-#ifdef NC_DOUBLE
-         ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,mean3d)
-         ierr = NF_PUT_VARA_DOUBLE(nid,varid+1,start,size,sd3d)
-#else
-         ierr = NF_PUT_VARA_REAL(nid,varid,start,size,mean3d)
-         ierr = NF_PUT_VARA_REAL(nid,varid+1,start,size,sd3d)
-#endif
-      enddo
-
-    else if (ndims.eq.3) then
-
-!      dimout(1)=lonid
-!      dimout(2)=latid
-!      dimout(3)=timeid
-
-      size=(/iip1,jjp1,1,0/)
-      do lt=1,istime
-         start=(/1,1,lt,0/)
-         ! Extraction of the "source" variables
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VARA_DOUBLE(nid,varid,start,size,sum2d)
-         ierr = NF_GET_VARA_DOUBLE(nid,varid+1,start,size,square2d)
-#else
-         ierr = NF_GET_VARA_REAL(nid,varid,start,size,sum2d)
-         ierr = NF_GET_VARA_REAL(nid,varid+1,start,size,square2d)
-#endif
-         ! Calculation of these variables
-         mean2d=sum2d/count(lt)
-         sd2d=sqrt(max(0.,square2d/count(lt)-mean2d**2))
-         ! Writing of the variables
-#ifdef NC_DOUBLE
-         ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,mean2d)
-         ierr = NF_PUT_VARA_DOUBLE(nid,varid+1,start,size,sd2d)
-#else
-         ierr = NF_PUT_VARA_REAL(nid,varid,start,size,mean2d)
-         ierr = NF_PUT_VARA_REAL(nid,varid+1,start,size,sd2d)
-#endif
-      enddo
-
-    endif 
-enddo
-
-ierr= NF_CLOSE(nid)
-
-end
Index: DZ5/branches/testing/libf/phylmd/mod_1D_amma_read.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/mod_1D_amma_read.F90	(revision 2407)
+++ 	(revision )
@@ -1,500 +1,0 @@
-MODULE mod_1D_amma_read
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!Declarations specifiques au cas AMMA
-        character*80 :: fich_amma
-! Option du cas AMMA ou on impose la discretisation verticale (Ap,Bp)
-        integer nlev_amma, nt_amma
-
-
-        integer year_ini_amma, day_ini_amma, mth_ini_amma
-        real heure_ini_amma
-        real day_ju_ini_amma   ! Julian day of amma first day
-        parameter (year_ini_amma=2006)
-        parameter (mth_ini_amma=7)
-        parameter (day_ini_amma=10)  ! 10 = 10Juil2006
-        parameter (heure_ini_amma=0.) !0h en secondes
-        real dt_amma
-        parameter (dt_amma=1800.)
-
-!profils initiaux:
-        real, allocatable::  plev_amma(:)
-
-        real, allocatable::  z_amma(:)
-        real, allocatable::  th_amma(:),q_amma(:)
-        real, allocatable::  u_amma(:)
-        real, allocatable::  v_amma(:)
-
-        real, allocatable::  th_ammai(:),q_ammai(:)
-        real, allocatable::  u_ammai(:)
-        real, allocatable::  v_ammai(:)
-        real, allocatable::  vitw_ammai(:)
-        real, allocatable::  ht_ammai(:)
-        real, allocatable::  hq_ammai(:)
-        real, allocatable::  vt_ammai(:)
-        real, allocatable::  vq_ammai(:)
-
-!forcings
-        real, allocatable::  ht_amma(:,:)
-        real, allocatable::  hq_amma(:,:)
-        real, allocatable::  vitw_amma(:,:)
-        real, allocatable::  lat_amma(:),sens_amma(:)
-
-!champs interpoles
-        real, allocatable::  vitw_profamma(:)
-        real, allocatable::  ht_profamma(:)
-        real, allocatable::  hq_profamma(:)
-        real lat_profamma,sens_profamma
-        real, allocatable::  vt_profamma(:)
-        real, allocatable::  vq_profamma(:)
-        real, allocatable::  th_profamma(:)
-        real, allocatable::  q_profamma(:)
-        real, allocatable::  u_profamma(:)
-        real, allocatable::  v_profamma(:)
-
-
-CONTAINS
-
-SUBROUTINE read_1D_cases
-      implicit none
-
-#include "netcdf.inc"
-
-      INTEGER nid,rid,ierr
-
-      fich_amma='amma.nc'
-      print*,'fich_amma ',fich_amma
-      ierr = NF_OPEN(fich_amma,NF_NOWRITE,nid)
-      print*,'fich_amma,NF_NOWRITE,nid ',fich_amma,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,'lev',rid)
-      IF (ierr.NE.NF_NOERR) THEN
-         print*, 'Oh probleme lecture dimension zz'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,nlev_amma)
-      print*,'OK nid,rid,nlev_amma',nid,rid,nlev_amma
-!.......................................................................
-      ierr=NF_INQ_DIMID(nid,'time',rid)
-      print*,'nid,rid',nid,rid
-      nt_amma=0
-      IF (ierr.NE.NF_NOERR) THEN
-        stop 'probleme lecture dimension sens'
-      ENDIF
-      ierr=NF_INQ_DIMLEN(nid,rid,nt_amma)
-      print*,'nid,rid,nlev_amma',nid,rid,nt_amma
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!profils initiaux:
-        allocate(plev_amma(nlev_amma))
-        
-        allocate(z_amma(nlev_amma))
-        allocate(th_amma(nlev_amma),q_amma(nlev_amma))
-        allocate(u_amma(nlev_amma))
-        allocate(v_amma(nlev_amma))
-
-!forcings
-        allocate(ht_amma(nlev_amma,nt_amma))
-        allocate(hq_amma(nlev_amma,nt_amma))
-        allocate(vitw_amma(nlev_amma,nt_amma))
-        allocate(lat_amma(nt_amma),sens_amma(nt_amma))
-
-!profils initiaux:
-        allocate(th_ammai(nlev_amma),q_ammai(nlev_amma))
-        allocate(u_ammai(nlev_amma))
-        allocate(v_ammai(nlev_amma))
-        allocate(vitw_ammai(nlev_amma) )
-        allocate(ht_ammai(nlev_amma))
-        allocate(hq_ammai(nlev_amma))
-        allocate(vt_ammai(nlev_amma))
-        allocate(vq_ammai(nlev_amma))
-
-!champs interpoles
-        allocate(vitw_profamma(nlev_amma))
-        allocate(ht_profamma(nlev_amma))
-        allocate(hq_profamma(nlev_amma))
-        allocate(vt_profamma(nlev_amma))
-        allocate(vq_profamma(nlev_amma))
-        allocate(th_profamma(nlev_amma))
-        allocate(q_profamma(nlev_amma))
-        allocate(u_profamma(nlev_amma))
-        allocate(v_profamma(nlev_amma))
-
-        print*,'Allocations OK'
-        call read_amma(nid,nlev_amma,nt_amma                                  &
-     &     ,z_amma,plev_amma,th_amma,q_amma,u_amma,v_amma,vitw_amma         &
-     &     ,ht_amma,hq_amma,sens_amma,lat_amma)
-
-END SUBROUTINE read_1D_cases
-
-
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-SUBROUTINE deallocate_1D_cases
-!profils initiaux:
-        deallocate(plev_amma)
-        
-        deallocate(z_amma)
-        deallocate(th_amma,q_amma)
-        deallocate(u_amma)
-        deallocate(v_amma)
-
-        deallocate(th_ammai,q_ammai)
-        deallocate(u_ammai)
-        deallocate(v_ammai)
-        deallocate(vitw_ammai )
-        deallocate(ht_ammai)
-        deallocate(hq_ammai)
-        deallocate(vt_ammai)
-        deallocate(vq_ammai)
-        
-!forcings
-        deallocate(ht_amma)
-        deallocate(hq_amma)
-        deallocate(vitw_amma)
-        deallocate(lat_amma,sens_amma)
-
-!champs interpoles
-        deallocate(vitw_profamma)
-        deallocate(ht_profamma)
-        deallocate(hq_profamma)
-        deallocate(vt_profamma)
-        deallocate(vq_profamma)
-        deallocate(th_profamma)
-        deallocate(q_profamma)
-        deallocate(u_profamma)
-        deallocate(v_profamma)
-END SUBROUTINE deallocate_1D_cases
-
-
-END MODULE mod_1D_amma_read
-!=====================================================================
-      subroutine read_amma(nid,nlevel,ntime                          &
-     &     ,zz,pp,temp,qv,u,v,dw                   &
-     &     ,dt,dq,sens,flat)
-
-!program reading forcings of the AMMA case study
-      implicit none
-#include "netcdf.inc"
-
-      integer ntime,nlevel
-
-      real zz(nlevel)
-      real temp(nlevel),pp(nlevel)
-      real qv(nlevel),u(nlevel)
-      real v(nlevel)
-      real dw(nlevel,ntime)
-      real dt(nlevel,ntime)
-      real dq(nlevel,ntime)
-      real flat(ntime),sens(ntime)
-
-
-      integer nid, ierr,rid
-      integer nbvar3d
-      parameter(nbvar3d=30)
-      integer var3didin(nbvar3d)
-
-       ierr=NF_INQ_VARID(nid,"zz",var3didin(1)) 
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'lev'
-         endif
-
-
-      ierr=NF_INQ_VARID(nid,"temp",var3didin(2))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'temp'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"qv",var3didin(3))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'qv'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"u",var3didin(4))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'u'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"v",var3didin(5))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'v'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"dw",var3didin(6))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'dw'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"dt",var3didin(7))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'dt'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"dq",var3didin(8))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'dq'
-         endif
-      
-      ierr=NF_INQ_VARID(nid,"sens",var3didin(9))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'sens'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"flat",var3didin(10))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'flat'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"pp",var3didin(11))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-      endif
-
-!dimensions lecture
-!      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
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture z ok',zz
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(2),temp)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(2),temp)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture th ok',temp
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(3),qv)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(3),qv)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture qv ok',qv
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(4),u)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(4),u)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          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
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture v ok',v
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(6),dw)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(6),dw)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture w ok',dw
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(7),dt)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(7),dt)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture dt ok',dt
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(8),dq)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(8),dq)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture dq ok',dq
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(9),sens)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(9),sens)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture sens ok',sens
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(10),flat)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(10),flat)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture flat ok',flat
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(11),pp)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(11),pp)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture pp ok',pp
-
-         return 
-         end subroutine read_amma
-!======================================================================
-        SUBROUTINE interp_amma_time(day,day1,annee_ref                     &
-     &         ,year_ini_amma,day_ini_amma,nt_amma,dt_amma,nlev_amma       &
-     &         ,vitw_amma,ht_amma,hq_amma,lat_amma,sens_amma               &
-     &         ,vitw_prof,ht_prof,hq_prof,lat_prof,sens_prof)
-        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_amma: total nb of data in the forcing (e.g. 48 for AMMA)
-! dt_amma: total time interval (in sec) between 2 forcing data (e.g. 30min for AMMA)
-!---------------------------------------------------------------------------------------
-
-#include "compar1d.h"
-
-! inputs:
-        integer annee_ref
-        integer nt_amma,nlev_amma
-        integer year_ini_amma
-        real day, day1,day_ini_amma,dt_amma
-        real vitw_amma(nlev_amma,nt_amma)
-        real ht_amma(nlev_amma,nt_amma)
-        real hq_amma(nlev_amma,nt_amma)
-        real lat_amma(nt_amma)
-        real sens_amma(nt_amma)
-! outputs:
-        real vitw_prof(nlev_amma)
-        real ht_prof(nlev_amma)
-        real hq_prof(nlev_amma)
-        real lat_prof,sens_prof
-! local:
-        integer it_amma1, it_amma2,k
-        real timeit,time_amma1,time_amma2,frac
-
-
-        if (forcing_type.eq.6) 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_ini_amma) then
-        print*,'AMMA a débuté le 10 juillet 2006',day1,day_ini_amma
-        print*,'Changer dayref dans run.def'
-        stop
-       endif
-       if (annee_ref.eq.2006 .and. day1.gt.day_ini_amma+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 of AMMA:
-!       timeit=(day-day1)*86400.
-!       if (annee_ref.eq.1992) then
-!        timeit=(day-day_ini_toga)*86400.
-!       else
-!        timeit=(day+61.-1.)*86400. ! 61 days between Nov01 and Dec31 1992
-!       endif
-      timeit=(day-day_ini_amma)*86400
-
-! Determine the closest observation times:
-!       it_amma1=INT(timeit/dt_amma)+1
-!       it_amma2=it_amma1 + 1
-!       time_amma1=(it_amma1-1)*dt_amma
-!       time_amma2=(it_amma2-1)*dt_amma
-
-       it_amma1=INT(timeit/dt_amma)+1
-       IF (it_amma1 .EQ. nt_amma) THEN
-       it_amma2=it_amma1 
-       ELSE
-       it_amma2=it_amma1 + 1
-       ENDIF
-       time_amma1=(it_amma1-1)*dt_amma
-       time_amma2=(it_amma2-1)*dt_amma
-
-       if (it_amma1 .gt. nt_amma) then
-        write(*,*) 'PB-stop: day, it_amma1, it_amma2, timeit: '            &
-     &        ,day,day_ini_amma,it_amma1,it_amma2,timeit/86400.
-        stop
-       endif
-
-! time interpolation:
-       frac=(time_amma2-timeit)/(time_amma2-time_amma1)
-       frac=max(frac,0.0)
-
-       lat_prof = lat_amma(it_amma2)                                       &
-     &          -frac*(lat_amma(it_amma2)-lat_amma(it_amma1)) 
-       sens_prof = sens_amma(it_amma2)                                     &
-     &          -frac*(sens_amma(it_amma2)-sens_amma(it_amma1))
-
-       do k=1,nlev_amma
-        vitw_prof(k) = vitw_amma(k,it_amma2)                               &
-     &          -frac*(vitw_amma(k,it_amma2)-vitw_amma(k,it_amma1))
-        ht_prof(k) = ht_amma(k,it_amma2)                                   &
-     &          -frac*(ht_amma(k,it_amma2)-ht_amma(k,it_amma1))
-        hq_prof(k) = hq_amma(k,it_amma2)                                   &
-     &          -frac*(hq_amma(k,it_amma2)-hq_amma(k,it_amma1))
-        enddo
-
-        return
-        END
-
Index: DZ5/branches/testing/libf/phylmd/mod_1D_cases_read.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/mod_1D_cases_read.F90	(revision 2407)
+++ 	(revision )
@@ -1,1052 +1,0 @@
-MODULE mod_1D_cases_read
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!Declarations specifiques au cas standard
-        character*80 :: fich_cas
-! Discrétisation 
-        integer nlev_cas, nt_cas
-
-
-        integer year_ini_cas, day_ini_cas, mth_ini_cas
-        real heure_ini_cas
-        real day_ju_ini_cas   ! Julian day of case first day
-        parameter (year_ini_cas=2011)
-        parameter (mth_ini_cas=10)
-        parameter (day_ini_cas=1)  ! 10 = 10Juil2006
-        parameter (heure_ini_cas=0.) !0h en secondes
-        real pdt_cas
-        parameter (pdt_cas=3.*3600)
-
-!CR ATTENTION TEST AMMA
-!        parameter (year_ini_cas=2006)
-!        parameter (mth_ini_cas=7)
-!        parameter (day_ini_cas=10)  ! 10 = 10Juil2006
-!        parameter (heure_ini_cas=0.) !0h en secondes
-!        parameter (pdt_cas=1800.)
-
-!profils environnementaux
-        real, allocatable::  plev_cas(:,:)
-
-        real, allocatable::  z_cas(:,:)
-        real, allocatable::  t_cas(:,:),q_cas(:,:),rh_cas(:,:)
-        real, allocatable::  th_cas(:,:),rv_cas(:,:)
-        real, allocatable::  u_cas(:,:)
-        real, allocatable::  v_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::  vitw_cas(:,:)
-        real, allocatable::  ug_cas(:,:),vg_cas(:,:)
-        real, allocatable::  lat_cas(:),sens_cas(:),ts_cas(:)
-
-!champs interpoles
-        real, allocatable::  plev_prof_cas(:)
-        real, allocatable::  t_prof_cas(:)
-        real, allocatable::  q_prof_cas(:)
-        real, allocatable::  u_prof_cas(:)
-        real, allocatable::  v_prof_cas(:)        
-
-        real, allocatable::  vitw_prof_cas(:)
-        real, allocatable::  ug_prof_cas(:)
-        real, allocatable::  vg_prof_cas(:)
-        real, allocatable::  ht_prof_cas(:)
-        real, allocatable::  hq_prof_cas(:)
-        real, allocatable::  vt_prof_cas(:)
-        real, allocatable::  vq_prof_cas(:)
-        real, allocatable::  dt_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 lat_prof_cas,sens_prof_cas,ts_prof_cas
-      
-
-
-CONTAINS
-
-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*,'OK 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*,'OK 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*,'OK 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*,'nid,rid,nlev_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))
-
-
-!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))
-
-        print*,'Allocations OK'
-        call read_cas(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)
-
-
-END SUBROUTINE read_1D_cas
-
-
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-SUBROUTINE deallocate_1D_cases
-!profils environnementaux:
-        deallocate(plev_cas)
-        
-        deallocate(z_cas)
-        deallocate(t_cas,q_cas,rh_cas)
-        deallocate(th_cas,rv_cas)
-        deallocate(u_cas)
-        deallocate(v_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(vitw_cas)
-        deallocate(ug_cas)
-        deallocate(vg_cas)
-        deallocate(lat_cas,sens_cas,ts_cas)
-
-!champs interpoles
-        deallocate(plev_prof_cas)
-        deallocate(t_prof_cas)
-        deallocate(q_prof_cas)
-        deallocate(u_prof_cas)
-        deallocate(v_prof_cas)
-
-        deallocate(vitw_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(q_prof_cas)
-        deallocate(u_prof_cas)
-        deallocate(v_prof_cas)
-
-END SUBROUTINE deallocate_1D_cases
-
-
-END MODULE mod_1D_cases_read
-!=====================================================================
-      subroutine read_cas(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)
-
-!program reading forcing of the case study
-      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)
-
-
-      integer nid, ierr,rid
-      integer nbvar3d
-      parameter(nbvar3d=34)
-      integer var3didin(nbvar3d)
-
-       ierr=NF_INQ_VARID(nid,"zz",var3didin(1)) 
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'lev'
-         endif
-      
-      ierr=NF_INQ_VARID(nid,"pp",var3didin(2)) 
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'plev'
-         endif
-
-
-      ierr=NF_INQ_VARID(nid,"temp",var3didin(3))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'temp'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"qv",var3didin(4))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'qv'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"rh",var3didin(5))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'rh'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"theta",var3didin(6))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'theta'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"rv",var3didin(7))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'rv'
-         endif
-
-
-      ierr=NF_INQ_VARID(nid,"u",var3didin(8))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'u'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"v",var3didin(9))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'v'
-         endif
-
-       ierr=NF_INQ_VARID(nid,"ug",var3didin(10))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'ug'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"vg",var3didin(11))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'vg'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"w",var3didin(12))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'w'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"advu",var3didin(13))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'advu'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"hu",var3didin(14))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'hu'
-         endif
-
-       ierr=NF_INQ_VARID(nid,"vu",var3didin(15))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'vu'
-         endif
-
-       ierr=NF_INQ_VARID(nid,"advv",var3didin(16))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'advv'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"hv",var3didin(17))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'hv'
-         endif
-
-       ierr=NF_INQ_VARID(nid,"vv",var3didin(18))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'vv'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"advT",var3didin(19))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'advT'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"hT",var3didin(20))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'hT'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"vT",var3didin(21))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'vT'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"advq",var3didin(22))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'advq'
-         endif
-      
-      ierr=NF_INQ_VARID(nid,"hq",var3didin(23))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'hq'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"vq",var3didin(24))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'vq'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"advth",var3didin(25))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'advth'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"hth",var3didin(26))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'hth'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"vth",var3didin(27))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'vth'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"advr",var3didin(28))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'advr'
-         endif
-      
-      ierr=NF_INQ_VARID(nid,"hr",var3didin(29))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'hr'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"vr",var3didin(30))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'vr'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"radT",var3didin(31))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'radT'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"sens",var3didin(32))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'sens'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"flat",var3didin(33))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'flat'
-         endif
-
-      ierr=NF_INQ_VARID(nid,"ts",var3didin(34))
-         if(ierr/=NF_NOERR) then
-           write(*,*) NF_STRERROR(ierr)
-           stop 'ts'
-         endif
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(1),zz)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(1),zz)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture z ok',zz
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(2),pp)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(2),pp)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture pp ok',pp
-
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(3),temp)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(3),temp)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture T ok',temp
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(4),qv)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(4),qv)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture qv ok',qv
- 
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(5),rh)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(5),rh)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture rh ok',rh
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(6),theta)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(6),theta)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture theta ok',theta
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(7),rv)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(7),rv)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture rv ok',rv
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(8),u)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(8),u)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture u ok',u
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(9),v)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(9),v)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture v ok',v
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(10),ug)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(10),ug)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture ug ok',ug
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(11),vg)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(11),vg)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture vg ok',vg
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(12),w)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(12),w)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture w ok',w
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(13),du)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(13),du)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture du ok',du
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(14),hu)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(14),hu)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture hu ok',hu
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(15),vu)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(15),vu)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture vu ok',vu
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(16),dv)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(16),dv)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture dv ok',dv
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(17),hv)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(17),hv)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture hv ok',hv
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(18),vv)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(18),vv)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture vv ok',vv
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(19),dt)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(19),dt)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture dt ok',dt
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(20),ht)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(20),ht)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture ht ok',ht
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(21),vt)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(21),vt)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture vt ok',vt
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(22),dq)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(22),dq)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture dq ok',dq
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(23),hq)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(23),hq)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture hq ok',hq
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(24),vq)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(24),vq)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture vq ok',vq
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(25),dth)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(25),dth)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture dth ok',dth
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(26),hth)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(26),hth)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture hth ok',hth
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(27),vth)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(27),vth)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture vth ok',vth
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(28),dr)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(28),dr)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture dr ok',dr
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(29),hr)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(29),hr)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture hr ok',hr
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(30),vr)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(30),vr)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture vr ok',vr
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(31),dtrad)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(31),dtrad)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture dtrad ok',dtrad
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(32),sens)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(32),sens)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture sens ok',sens
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(33),flat)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(33),flat)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture flat ok',flat
-
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(34),ts)
-#else
-         ierr = NF_GET_VAR_REAL(nid,var3didin(34),ts)
-#endif
-         if(ierr/=NF_NOERR) then
-            write(*,*) NF_STRERROR(ierr)
-            stop "getvarup"
-         endif
-!          write(*,*)'lecture ts ok',ts
-
-         return 
-         end subroutine read_cas
-!======================================================================
-        SUBROUTINE interp_case_time(day,day1,annee_ref                &
-     &         ,year_ini_cas,day_ini_cas,nt_cas,pdt_cas,nlev_cas      &
-     &         ,ts_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          &
-     &         ,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)
-          
-
-        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"
-
-! inputs:
-        integer annee_ref
-        integer nt_cas,nlev_cas
-        integer year_ini_cas
-        real day_ini_cas
-        real day, day1,pdt_cas
-        real ts_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)
-
-! 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
-! local:
-        integer it_cas1, it_cas2,k
-        real timeit,time_cas1,time_cas2,frac
-
-
-        print*,'Check time',day1,day_ini_cas,day_ini_cas+90
-
-        if ((forcing_type.eq.10).and.(1.eq.1)) then
-! Check that initial day of the simulation consistent with the case:
-       if (annee_ref.ne.2011) then
-        print*,'Pour CINDY, annee_ref doit etre 2011'
-        print*,'Changer annee_ref dans run.def'
-        stop
-       endif
-       if (annee_ref.eq.2011 .and. day1.lt.day_ini_cas) then
-        print*,'CINDY a débuté le 1 octobre 2011',day1,day_ini_cas
-        print*,'Changer dayref dans run.def'
-        stop
-       endif
-       if (annee_ref.eq.2011 .and. day1.gt.day_ini_cas+90) then
-        print*,'CINDY a fini le 31 decembre'
-        print*,'Changer dayref ou nday dans run.def',day1,day_ini_cas+90
-        stop
-       endif
-       endif
-!CR:ATTENTION TEST AMMA
-      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_ini_cas) then
-        print*,'AMMA a débuté le 10 juillet 2006',day1,day_ini_cas
-        print*,'Changer dayref dans run.def'
-        stop
-       endif
-       if (annee_ref.eq.2006 .and. day1.gt.day_ini_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_ini_cas)*86400.
-!       else
-!        timeit=(day+61.-1.)*86400. ! 61 days between Nov01 and Dec31 1992
-!       endif
-      timeit=(day-day_ini_cas)*86400
-
-! 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
-
-       if (it_cas1 .gt. nt_cas) then
-        write(*,*) 'PB-stop: day, it_cas1, it_cas2, timeit: '            &
-     &        ,day,day_ini_cas,it_cas1,it_cas2,timeit/86400.
-        stop
-       endif
-
-! time interpolation:
-       frac=(time_cas2-timeit)/(time_cas2-time_cas1)
-       frac=max(frac,0.0)
-
-       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))
-
-       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))
-        enddo
-
-        return
-        END
-
-!**********************************************************************************************
Index: /LMDZ5/branches/testing/libf/phylmd/mod_surf_para.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/mod_surf_para.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/mod_surf_para.F90	(revision 2408)
@@ -49,5 +49,5 @@
 
   SUBROUTINE Init_surf_para(knon)
-  USE mod_phys_lmdz_para, mpi_rank_root=>mpi_root
+  USE mod_phys_lmdz_para
 #ifdef CPP_MPI
   INCLUDE 'mpif.h'
@@ -168,5 +168,5 @@
      
   SUBROUTINE gather_surf_mpi_i(FieldIn,FieldOut)
-  USE mod_phys_lmdz_para, mpi_rank_root => mpi_root
+  USE mod_phys_lmdz_para
 #ifdef CPP_MPI
   INCLUDE 'mpif.h'
@@ -180,5 +180,5 @@
       CALL MPI_Gatherv(FieldIn,knon_mpi,MPI_INTEGER,                                &
                        FieldOut,knon_mpi_para,knon_mpi_begin_para(:)-1,MPI_INTEGER, &
-                       mpi_rank_root,COMM_LMDZ_PHY,ierr)
+                       mpi_master,COMM_LMDZ_PHY,ierr)
 #endif
     ELSE
@@ -223,5 +223,5 @@
      
   SUBROUTINE gather_surf_mpi_r(FieldIn,FieldOut)
-  USE mod_phys_lmdz_para, mpi_rank_root => mpi_root
+  USE mod_phys_lmdz_para
 #ifdef CPP_MPI
   INCLUDE 'mpif.h'
@@ -235,5 +235,5 @@
       CALL MPI_Gatherv(FieldIn,knon_mpi,MPI_REAL_LMDZ,                                 &
                        FieldOut,knon_mpi_para,knon_mpi_begin_para(:)-1,MPI_REAL_LMDZ,  &
-                       mpi_rank_root,COMM_LMDZ_PHY,ierr)            
+                       mpi_master,COMM_LMDZ_PHY,ierr)            
 #endif
     ELSE
@@ -276,5 +276,5 @@
      
   SUBROUTINE scatter_surf_mpi_i(FieldIn,FieldOut)
-  USE mod_phys_lmdz_para, mpi_rank_root => mpi_root
+  USE mod_phys_lmdz_para
 #ifdef CPP_MPI
   INCLUDE 'mpif.h'
@@ -288,5 +288,5 @@
       CALL MPI_Scatterv(FieldIn,knon_mpi_para,knon_mpi_begin_para(:)-1,MPI_INTEGER,   &
                         FieldOut,knon_mpi,MPI_INTEGER,                                &
-                        mpi_rank_root,COMM_LMDZ_PHY,ierr)
+                        mpi_master,COMM_LMDZ_PHY,ierr)
 #endif
     ELSE
@@ -328,5 +328,5 @@
      
   SUBROUTINE scatter_surf_mpi_r(FieldIn,FieldOut)
-  USE mod_phys_lmdz_para, mpi_rank_root => mpi_root
+  USE mod_phys_lmdz_para
 #ifdef CPP_MPI
   INCLUDE 'mpif.h'
@@ -340,5 +340,5 @@
       CALL MPI_Scatterv(FieldIn,knon_mpi_para,knon_mpi_begin_para(:)-1,MPI_INTEGER,   &
                         FieldOut,knon_mpi,MPI_INTEGER,                                &
-                        mpi_rank_root,COMM_LMDZ_PHY,ierr)
+                        mpi_master,COMM_LMDZ_PHY,ierr)
 #endif
     ELSE
@@ -349,2 +349,3 @@
 
 END MODULE mod_surf_para
+
Index: /LMDZ5/branches/testing/libf/phylmd/moy_undefSTD.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/moy_undefSTD.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/moy_undefSTD.F90	(revision 2408)
@@ -35,8 +35,4 @@
   ! NB: mettre "inst(X)" dans le write_hist*NMC.h !
   ! ====================================================================
-  ! ym#include "dimensions.h"
-  ! ym      integer jjmp1
-  ! ym      parameter (jjmp1=jjm+1-1/jjm)
-  ! ym#include "dimphy.h"
 
 
@@ -78,5 +74,5 @@
     ! calcul 1 fois pas mois, 1 fois par jour ou toutes les 6h
 
-    IF (n==1 .AND. itap==itapm1 .OR. n>1 .AND. mod(itap,nint(freq_outnmc(n)/ &
+    IF (n==1 .AND. itap==itapm1 .OR. n>1 .AND. mod(itap,nint(freq_outnmc(n)/ & 
         dtime))==0) THEN
 
Index: /LMDZ5/branches/testing/libf/phylmd/moyglo_aire.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/moyglo_aire.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/moyglo_aire.F90	(revision 2408)
@@ -16,6 +16,4 @@
   ! ==================================================================
 
-  include "dimensions.h"
-  ! ym#include "dimphy.h"
   INTEGER i, nhori
   REAL champ(klon), aire(klon), msk(klon)
@@ -74,6 +72,4 @@
 
   ! ==================================================================
-  include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   INTEGER i, k, nhori, nvert
@@ -119,6 +115,4 @@
 
   ! ==================================================================
-  include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   INTEGER i, k, nhori, nvert
Index: /LMDZ5/branches/testing/libf/phylmd/nonlocal.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/nonlocal.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/nonlocal.F90	(revision 2408)
@@ -21,5 +21,4 @@
   ! ======================================================================
   include "YOMCST.h"
-  include "iniprint.h"
 
   ! Arguments:
Index: /LMDZ5/branches/testing/libf/phylmd/nuage.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/nuage.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/nuage.F90	(revision 2408)
@@ -37,6 +37,4 @@
   include "nuage.h" ! JBM 3/14
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   REAL paprs(klon, klev+1), pplay(klon, klev)
   REAL t(klon, klev)
@@ -246,6 +244,4 @@
   ! ces nuages. Je dois avouer que c'est une frustration.
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
@@ -323,6 +319,4 @@
   IMPLICIT NONE
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/o3_chem_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/o3_chem_m.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/o3_chem_m.F90	(revision 2408)
@@ -14,5 +14,5 @@
 
     ! All the 2-dimensional arrays are on the partial "physics" grid.
-    ! Their shape is "(/klon, llm/)".
+    ! Their shape is "(/klon, nbp_lev/)".
     ! Index "(i, :)" is for longitude "rlon(i)", latitude "rlat(i)".
 
@@ -20,10 +20,12 @@
     use dimphy, only: klon
     use regr_pr_comb_coefoz_m, only: c_Mob, a4_mass, a2, r_het_interm
+    use mod_grid_phy_lmdz, only: nbp_lev
+    use nrtype, only: pi
 
     integer, intent(in):: julien ! jour julien, 1 <= julien <= 360
     real, intent(in):: gmtime ! heure de la journée en fraction de jour
-    real, intent(in):: t_seri(:, :) ! (klon, llm) temperature, in K
+    real, intent(in):: t_seri(:, :) ! (klon, nbp_lev) temperature, in K
 
-    real, intent(in):: zmasse(:, :) ! (klon, llm)
+    real, intent(in):: zmasse(:, :) ! (klon, nbp_lev)
     ! (column-density of mass of air in a cell, in kg m-2)
     ! "zmasse(:, k)" is for layer "k".)
@@ -34,24 +36,22 @@
     ! (longitude and latitude of each horizontal position, in degrees)
 
-    real, intent(inout):: q(:, :) ! (klon, llm) mass fraction of ozone
+    real, intent(inout):: q(:, :) ! (klon, nbp_lev) mass fraction of ozone
     ! "q(:, k)" is at middle of layer "k".)
 
     ! Variables local to the procedure:
-    include "dimensions.h"
-    include "comconst.h"
     ! (for "pi")
     integer k
 
-    real c(klon, llm)
+    real c(klon, nbp_lev)
     ! (constant term during a time step in the net mass production
     ! rate of ozone by chemistry, per unit mass of air, in s-1)
     ! "c(:, k)" is at middle of layer "k".)
 
-    real b(klon, llm)
+    real b(klon, nbp_lev)
     ! (coefficient of "q" in the net mass production
     ! rate of ozone by chemistry, per unit mass of air, in s-1)
     ! "b(:, k)" is at middle of layer "k".)
 
-    real dq_o3_chem(klon, llm)
+    real dq_o3_chem(klon, nbp_lev)
     ! (variation of ozone mass fraction due to chemistry during a time step)
     ! "dq_o3_chem(:, k)" is at middle of layer "k".)
@@ -69,6 +69,6 @@
     call assert(klon == (/size(q, 1), size(t_seri, 1), size(zmasse, 1), &
          size(rlat), size(rlon)/), "o3_chem klon")
-    call assert(llm == (/size(q, 2), size(t_seri, 2), size(zmasse, 2)/), &
-         "o3_chem llm")
+    call assert(nbp_lev == (/size(q, 2), size(t_seri, 2), size(zmasse, 2)/), &
+         "o3_chem nbp_lev")
 
     c = c_Mob + a4_mass * t_seri
@@ -86,5 +86,5 @@
     call orbite(real(julien), earth_long, trash1)
     call zenang(earth_long, gmtime, pdtphys, rlat, rlon, pmu0, trash2)
-    forall (k = 1: llm)
+    forall (k = 1: nbp_lev)
        where (pmu0 <= cos(87. / 180. * pi)) b(:, k) = 0.
     end forall
@@ -112,5 +112,5 @@
 
     ! All the 2-dimensional arrays are on the partial "physics" grid.
-    ! Their shape is "(/klon, llm/)".
+    ! Their shape is "(/klon, nbp_lev/)".
     ! Index "(i, :)" is for longitude "rlon(i)", latitude "rlat(i)".
 
@@ -118,4 +118,5 @@
     use assert_m, only: assert
     use dimphy, only: klon
+    use mod_grid_phy_lmdz, only: nbp_lev
 
     real, intent(in):: q(:, :) ! mass fraction of ozone
@@ -136,7 +137,5 @@
     ! ("b(:, k)" is at middle of layer "k".)
 
-    include "dimensions.h"
-
-    real o3_prod(klon, llm)
+    real o3_prod(klon, nbp_lev)
     ! (net mass production rate of ozone by chemistry, per unit mass
     ! of air, in s-1)
@@ -145,5 +144,5 @@
     ! Variables local to the procedure:
 
-    real sigma_mass(klon, llm)
+    real sigma_mass(klon, nbp_lev)
     ! (mass column-density of ozone above point, in kg m-2)
     ! ("sigma_mass(:, k)" is at middle of layer "k".)
@@ -155,5 +154,5 @@
     call assert(klon == (/size(q, 1), size(zmasse, 1), size(c, 1), &
          size(b, 1)/), "o3_prod 1")
-    call assert(llm == (/size(q, 2), size(zmasse, 2), size(c, 2), &
+    call assert(nbp_lev == (/size(q, 2), size(zmasse, 2), size(c, 2), &
          size(b, 2)/), "o3_prod 2")
 
@@ -161,6 +160,6 @@
     ! "k", and, as a first approximation, take it as column-density
     ! above the middle of layer "k":
-    sigma_mass(:, llm) = zmasse(:, llm) * q(:, llm) ! top layer
-    do k =  llm - 1, 1, -1
+    sigma_mass(:, nbp_lev) = zmasse(:, nbp_lev) * q(:, nbp_lev) ! top layer
+    do k =  nbp_lev - 1, 1, -1
        sigma_mass(:, k) = sigma_mass(:, k+1) + zmasse(:, k) * q(:, k)
     end do
Index: /LMDZ5/branches/testing/libf/phylmd/o3cm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/o3cm.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/o3cm.F90	(revision 2408)
@@ -32,5 +32,5 @@
   IF (ntab>499) THEN
     abort_message = 'BIG ntab'
-    CALL abort_gcm(modname, abort_message, 1)
+    CALL abort_physic(modname, abort_message, 1)
   END IF
   xincr = (bmb-amb)/real(ntab)
Index: /LMDZ5/branches/testing/libf/phylmd/oasis.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/oasis.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/oasis.F90	(revision 2408)
@@ -99,8 +99,6 @@
     USE wxios, ONLY : wxios_context_init 
 #endif
-
-
-    INCLUDE "dimensions.h"
-    INCLUDE "iniprint.h"
+    USE print_control_mod, ONLY: lunout
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
 
 ! Local variables
@@ -218,5 +216,5 @@
        IF (ierror .NE. PRISM_Ok) THEN
           abort_message=' Probleme init dans prism_init_comp '
-          CALL abort_gcm(modname,abort_message,1)
+          CALL abort_physic(modname,abort_message,1)
        ELSE
           WRITE(lunout,*) 'inicma : init psmile ok '
@@ -229,8 +227,8 @@
 !************************************************************************************
     ig_paral(1) = 1                            ! apple partition for //
-    ig_paral(2) = (jj_begin-1)*iim+ii_begin-1  ! offset
-    ig_paral(3) = (jj_end*iim+ii_end) - (jj_begin*iim+ii_begin) + 1
-
-    IF (mpi_rank==mpi_size-1) ig_paral(3)=ig_paral(3)+iim-1
+    ig_paral(2) = (jj_begin-1)*nbp_lon+ii_begin-1  ! offset
+    ig_paral(3) = (jj_end*nbp_lon+ii_end) - (jj_begin*nbp_lon+ii_begin) + 1
+
+    IF (mpi_rank==mpi_size-1) ig_paral(3)=ig_paral(3)+nbp_lon-1
     WRITE(lunout,*) mpi_rank,'ig_paral--->',ig_paral(2),ig_paral(3)
     
@@ -240,5 +238,5 @@
     IF (ierror .NE. PRISM_Ok) THEN
        abort_message=' Probleme dans prism_def_partition '
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ELSE
        WRITE(lunout,*) 'inicma : decomposition domaine psmile ok '
@@ -249,7 +247,7 @@
 
     il_var_actual_shape(1) = 1
-    il_var_actual_shape(2) = iim
+    il_var_actual_shape(2) = nbp_lon
     il_var_actual_shape(3) = 1
-    il_var_actual_shape(4) = jjm+1
+    il_var_actual_shape(4) = nbp_lat
    
     il_var_type = PRISM_Real
@@ -268,5 +266,5 @@
                   inforecv(jf)%name
              abort_message=' Problem in call to prism_def_var_proto for fields to receive'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
@@ -286,5 +284,5 @@
                   infosend(jf)%name
              abort_message=' Problem in call to prism_def_var_proto for fields to send'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
@@ -297,5 +295,5 @@
     IF (ierror .NE. PRISM_Ok) THEN
        abort_message=' Problem in call to prism_endef_proto'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ELSE
        WRITE(lunout,*) 'inicma : endef psmile ok '
@@ -320,6 +318,6 @@
 !======================================================================
 !
-    INCLUDE "dimensions.h"
-    INCLUDE "iniprint.h"
+    USE print_control_mod, ONLY: lunout
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
 ! Input arguments
 !************************************************************************************
@@ -328,5 +326,5 @@
 ! Output arguments
 !************************************************************************************
-    REAL, DIMENSION(iim, jj_nb,maxrecv), INTENT(OUT) :: tab_get
+    REAL, DIMENSION(nbp_lon, jj_nb,maxrecv), INTENT(OUT) :: tab_get
 
 ! Local variables
@@ -336,5 +334,5 @@
     CHARACTER (len = 20)          :: modname = 'fromcpl'
     CHARACTER (len = 80)          :: abort_message 
-    REAL, DIMENSION(iim*jj_nb)    :: field
+    REAL, DIMENSION(nbp_lon*jj_nb)    :: field
 
 !************************************************************************************
@@ -345,7 +343,7 @@
     istart=ii_begin
     IF (is_south_pole) THEN
-       iend=(jj_end-jj_begin)*iim+iim
+       iend=(jj_end-jj_begin)*nbp_lon+nbp_lon
     ELSE
-       iend=(jj_end-jj_begin)*iim+ii_end
+       iend=(jj_end-jj_begin)*nbp_lon+ii_end
     ENDIF
     
@@ -354,5 +352,5 @@
           field(:) = -99999.
           CALL prism_get_proto(inforecv(i)%nid, ktime, field(istart:iend), ierror)
-          tab_get(:,:,i) = RESHAPE(field(:),(/iim,jj_nb/))
+          tab_get(:,:,i) = RESHAPE(field(:),(/nbp_lon,jj_nb/))
        
           IF (ierror .NE. PRISM_Ok .AND. ierror.NE.PRISM_Recvd .AND. &
@@ -362,5 +360,5 @@
               WRITE (lunout,*)  'Error with receiving filed : ', inforecv(i)%name, ktime   
               abort_message=' Problem in prism_get_proto '
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
           ENDIF
       ENDIF
@@ -382,11 +380,11 @@
 !
 ! 
-    INCLUDE "dimensions.h"
-    INCLUDE "iniprint.h"
+    USE print_control_mod, ONLY: lunout
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
 ! Input arguments
 !************************************************************************************
     INTEGER, INTENT(IN)                              :: ktime
     LOGICAL, INTENT(IN)                              :: last
-    REAL, DIMENSION(iim, jj_nb, maxsend), INTENT(IN) :: tab_put
+    REAL, DIMENSION(nbp_lon, jj_nb, maxsend), INTENT(IN) :: tab_put
 
 ! Local variables
@@ -396,5 +394,5 @@
     INTEGER                          :: wstart,wend
     INTEGER                          :: ierror, i
-    REAL, DIMENSION(iim*jj_nb)       :: field
+    REAL, DIMENSION(nbp_lon*jj_nb)       :: field
     CHARACTER (len = 20),PARAMETER   :: modname = 'intocpl'
     CHARACTER (len = 80)             :: abort_message 
@@ -411,7 +409,7 @@
     istart=ii_begin
     IF (is_south_pole) THEN
-       iend=(jj_end-jj_begin)*iim+iim
+       iend=(jj_end-jj_begin)*nbp_lon+nbp_lon
     ELSE
-       iend=(jj_end-jj_begin)*iim+ii_end
+       iend=(jj_end-jj_begin)*nbp_lon+ii_end
     ENDIF
     
@@ -419,10 +417,10 @@
        wstart=istart
        wend=iend
-       IF (is_north_pole) wstart=istart+iim-1
-       IF (is_south_pole) wend=iend-iim+1
+       IF (is_north_pole) wstart=istart+nbp_lon-1
+       IF (is_south_pole) wend=iend-nbp_lon+1
        
        DO i = 1, maxsend
           IF (infosend(i)%action) THEN
-             field = RESHAPE(tab_put(:,:,i),(/iim*jj_nb/))
+             field = RESHAPE(tab_put(:,:,i),(/nbp_lon*jj_nb/))
              CALL writefield_phy(infosend(i)%name,field(wstart:wend),1)
           END IF
@@ -436,5 +434,5 @@
     DO i = 1, maxsend
       IF (infosend(i)%action .AND. infosend(i)%nid .NE. -1 ) THEN
-          field = RESHAPE(tab_put(:,:,i),(/iim*jj_nb/))
+          field = RESHAPE(tab_put(:,:,i),(/nbp_lon*jj_nb/))
           CALL prism_put_proto(infosend(i)%nid, ktime, field(istart:iend), ierror)
           
@@ -444,5 +442,5 @@
               WRITE (lunout,*) 'Error with sending field :', infosend(i)%name, ktime   
               abort_message=' Problem in prism_put_proto '
-              CALL abort_gcm(modname,abort_message,1)
+              CALL abort_physic(modname,abort_message,1)
           ENDIF
       ENDIF
@@ -459,5 +457,5 @@
           IF (ierror .NE. PRISM_Ok) THEN
              abort_message=' Problem in prism_terminate_proto '
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
Index: /LMDZ5/branches/testing/libf/phylmd/ocean_slab_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ocean_slab_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/ocean_slab_mod.F90	(revision 2408)
@@ -88,5 +88,4 @@
     use IOIPSL
 
-    INCLUDE "iniprint.h"
     ! For ok_xxx vars (Ekman...)
     INCLUDE "clesphys.h"
@@ -110,5 +109,5 @@
     IF (error /= 0) THEN
        abort_message='Pb allocation tmp_pctsrf_slab'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
     fsic(:)=0.
@@ -121,5 +120,5 @@
 !****************************************************************************************
     ALLOCATE(tslab(klon,nslay), stat=error)
-       IF (error /= 0) CALL abort_gcm &
+       IF (error /= 0) CALL abort_physic &
          (modname,'pb allocation tslab', 1)
 
@@ -127,5 +126,5 @@
     IF (error /= 0) THEN
        abort_message='Pb allocation slab_bils'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
     slab_bils(:) = 0.0   
@@ -133,5 +132,5 @@
     IF (error /= 0) THEN
        abort_message='Pb allocation slab_bils_cum'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
     bils_cum(:) = 0.0   
@@ -141,5 +140,5 @@
         IF (error /= 0) THEN
            abort_message='Pb allocation slab_bilg'
-           CALL abort_gcm(modname,abort_message,1)
+           CALL abort_physic(modname,abort_message,1)
         ENDIF
         slab_bilg(:) = 0.0   
@@ -147,5 +146,5 @@
         IF (error /= 0) THEN
            abort_message='Pb allocation slab_bilg_cum'
-           CALL abort_gcm(modname,abort_message,1)
+           CALL abort_physic(modname,abort_message,1)
         ENDIF
         bilg_cum(:) = 0.0   
@@ -153,10 +152,10 @@
         IF (error /= 0) THEN
            abort_message='Pb allocation slab_tice'
-           CALL abort_gcm(modname,abort_message,1)
+           CALL abort_physic(modname,abort_message,1)
         ENDIF
         ALLOCATE(seaice(klon), stat = error)
         IF (error /= 0) THEN
            abort_message='Pb allocation slab_seaice'
-           CALL abort_gcm(modname,abort_message,1)
+           CALL abort_physic(modname,abort_message,1)
         ENDIF
     END IF
@@ -169,5 +168,5 @@
     IF (error /= 0) THEN
        abort_message='Pb allocation slabh'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
     slabh(1)=50.
@@ -226,5 +225,4 @@
     USE calcul_fluxs_mod
 
-    INCLUDE "iniprint.h"
     INCLUDE "clesphys.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/orbite.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/orbite.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/orbite.F90	(revision 2408)
@@ -63,6 +63,4 @@
   ! la journee (0 a 1)
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   REAL longi
   REAL lati(klon), frac(klon), muzero(klon)
@@ -104,5 +102,5 @@
 END SUBROUTINE angle
 ! ====================================================================
-SUBROUTINE zenang(longi, gmtime, pdtrad, lat, long, pmu0, frac)
+SUBROUTINE zenang(longi, gmtime, pdtrad1, pdtrad2, lat, long, pmu0, frac)
   USE dimphy
   IMPLICIT NONE
@@ -116,22 +114,24 @@
   ! fournit des moyennes de pmu0 et non des valeurs
   ! instantanees, du coup frac prend toutes les valeurs
-  ! entre 0 et 1.
+  ! entre 0 et 1. La routine integre entre gmtime+pdtrad1 et 
+  ! gmtime+pdtrad2 avec pdtrad1 et pdtrad2 exprimes en secondes.
   ! Date   : premiere version le 13 decembre 1994
   ! revu pour  GCM  le 30 septembre 1996
+  ! revu le 3 septembre 2015 pour les bornes de l'integrale
   ! ===============================================================
   ! longi : la longitude vraie de la terre dans son plan
   ! solaire a partir de l'equinoxe de printemps (degre)
   ! gmtime : temps universel en fraction de jour
-  ! pdtrad : pas de temps du rayonnement (secondes)
+  ! pdtrad1 : borne inferieure du pas de temps du rayonnement (secondes)
+  ! pdtrad2 : borne inferieure du pas de temps du rayonnement (secondes)
+  ! pdtrad2-pdtrad1 correspond a pdtrad, le pas de temps du rayonnement (secondes)
   ! lat------INPUT : latitude en degres
   ! long-----INPUT : longitude en degres
-  ! pmu0-----OUTPUT: angle zenithal moyen entre gmtime et gmtime+pdtrad
-  ! frac-----OUTPUT: ensoleillement moyen entre gmtime et gmtime+pdtrad
-  ! ================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  include "YOMCST.h"
-  ! ================================================================
-  REAL, INTENT (IN) :: longi, gmtime, pdtrad
+  ! pmu0-----OUTPUT: angle zenithal moyen entre gmtime+pdtrad1 et gmtime+pdtrad2
+  ! frac-----OUTPUT: ensoleillement moyen entre gmtime+pdtrad1 et gmtime+pdtrad2
+  ! ================================================================
+  include "YOMCST.h"
+  ! ================================================================
+  REAL, INTENT (IN) :: longi, gmtime, pdtrad1, pdtrad2
   REAL lat(klon), long(klon), pmu0(klon), frac(klon)
   ! ================================================================
@@ -147,5 +147,5 @@
   REAL lat_sun ! declinaison en radian
   REAL lon_sun ! longitude solaire en radian
-  REAL latr ! latitude du pt de grille en radian
+  REAL latr    ! latitude du pt de grille en radian
   ! ================================================================
 
@@ -157,6 +157,6 @@
   lat_sun = asin(sin(lon_sun)*sin(incl))
 
-  gmtime1 = gmtime*86400.
-  gmtime2 = gmtime*86400. + pdtrad
+  gmtime1 = gmtime*86400. + pdtrad1
+  gmtime2 = gmtime*86400. + pdtrad2
 
   DO i = 1, klon
@@ -164,23 +164,10 @@
     latr = lat(i)*pi_local/180.
 
-    ! --pose probleme quand lat=+/-90 degres
-
-    ! omega = -TAN(latr)*TAN(lat_sun)
-    ! omega = ACOS(omega)
-    ! IF (latr.GE.(pi_local/2.+lat_sun)
-    ! .    .OR. latr.LE.(-pi_local/2.+lat_sun)) THEN
-    ! omega = 0.0       ! nuit polaire
-    ! ENDIF
-    ! IF (latr.GE.(pi_local/2.-lat_sun)
-    ! .          .OR. latr.LE.(-pi_local/2.-lat_sun)) THEN
-    ! omega = pi_local  ! journee polaire
-    ! ENDIF
-
-    ! --remplace par cela (le cas par defaut est different)
-
     omega = 0.0 !--nuit polaire
+
     IF (latr>=(pi_local/2.-lat_sun) .OR. latr<=(-pi_local/2.-lat_sun)) THEN
       omega = pi_local ! journee polaire
     END IF
+
     IF (latr<(pi_local/2.+lat_sun) .AND. latr>(-pi_local/2.+lat_sun) .AND. &
         latr<(pi_local/2.-lat_sun) .AND. latr>(-pi_local/2.-lat_sun)) THEN
@@ -266,6 +253,4 @@
 
   ! ====================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   ! ====================================================================
Index: /LMDZ5/branches/testing/libf/phylmd/orografi.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/orografi.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/orografi.F90	(revision 2408)
@@ -24,6 +24,4 @@
   ! d_v-----output-R-increment de la vitesse v
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
@@ -171,6 +169,4 @@
 
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -404,6 +400,4 @@
 
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -849,6 +843,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -980,6 +972,4 @@
 
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -1209,6 +1199,4 @@
   ! d_v-----output-R-increment de la vitesse v
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
@@ -1324,6 +1312,4 @@
 
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -1369,5 +1355,5 @@
   IF (nlon/=klon .OR. nlev/=klev) THEN
     abort_message = 'pb dimension'
-    CALL abort_gcm(modname, abort_message, 1)
+    CALL abort_physic(modname, abort_message, 1)
   END IF
   zcons1 = 1./rd
@@ -1670,11 +1656,11 @@
   gsigcr = 0.80
 
-  gkdrag = 0.2
-  grahilo = 1.
-  grcrit = 0.01
-  gfrcrit = 1.0
-  gkwake = 0.50
-
-  gklift = 0.50
+!  Values now specified in run.def, or conf_phys_m.F90
+!  gkdrag = 0.2
+!  grahilo = 1.
+!  grcrit = 0.01
+!  gfrcrit = 1.0
+!  gkwake = 0.50
+! gklift = 0.50
   gvcrit = 0.0
 
Index: /LMDZ5/branches/testing/libf/phylmd/orografi_strato.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/orografi_strato.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/orografi_strato.F90	(revision 2408)
@@ -61,6 +61,4 @@
 
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -239,6 +237,4 @@
 
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -541,6 +537,4 @@
 
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -995,6 +989,4 @@
   IMPLICIT NONE
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -1114,6 +1106,4 @@
   IMPLICIT NONE
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -1350,6 +1340,4 @@
   ! ======================================================================
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -1510,6 +1498,4 @@
 
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
   include "YOEGWD.h"
@@ -1558,5 +1544,5 @@
   IF (nlon/=klon .OR. nlev/=klev) THEN
     abort_message = 'pb dimension'
-    CALL abort_gcm(modname, abort_message, 1)
+    CALL abort_physic(modname, abort_message, 1)
   END IF
   zcons1 = 1./rd
@@ -1847,5 +1833,5 @@
 
   zpr = 100000.
-  ztop = 0.001
+  ZTOP=0.00005
   zsigt = 0.94
   ! old  ZPR=80000.
@@ -1873,15 +1859,15 @@
   PRINT *, ' DANS SUGWD nktopg=', nktopg
   PRINT *, ' DANS SUGWD nstra=', nstra
-  if (nstra == 0) call abort_gcm("sugwd_strato", "no level in stratosphere", 1)
-
-  gsigcr = 0.80
-
-  gkdrag = 0.1875
-  grahilo = 0.1
-  grcrit = 1.00
-  gfrcrit = 1.00
-  gkwake = 0.50
-
-  gklift = 0.25
+  if (nstra == 0) call abort_physic("sugwd_strato", "no level in stratosphere", 1)
+
+!  Valeurs lues dans les .def, ou attribues dans conf_phys
+  !gkdrag = 0.2   
+  !grahilo = 0.1
+  !grcrit = 1.00
+  !gfrcrit = 0.70
+  !gkwake = 0.40
+  !gklift = 0.25
+
+  gsigcr = 0.80 ! Top of low level flow
   gvcrit = 0.1
 
Index: /LMDZ5/branches/testing/libf/phylmd/pbl_surface_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/pbl_surface_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/pbl_surface_mod.F90	(revision 2408)
@@ -23,5 +23,4 @@
   USE climb_wind_mod,      ONLY : climb_wind_down, climb_wind_up
   USE coef_diff_turb_mod,  ONLY : coef_diff_turb
-  USE control_mod
 
 
@@ -49,7 +48,7 @@
 
     USE indice_sol_mod
+    USE print_control_mod, ONLY: lunout
 
     INCLUDE "dimsoil.h"
-    INCLUDE "iniprint.h"
  
 ! Input variables
@@ -73,14 +72,14 @@
 !****************************************************************************************    
     ALLOCATE(fder(klon), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('pbl_surface_init', 'pb in allocation',1)
+    IF (ierr /= 0) CALL abort_physic('pbl_surface_init', 'pb in allocation',1)
 
     ALLOCATE(snow(klon,nbsrf), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('pbl_surface_init', 'pb in allocation',1)
+    IF (ierr /= 0) CALL abort_physic('pbl_surface_init', 'pb in allocation',1)
 
     ALLOCATE(qsurf(klon,nbsrf), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('pbl_surface_init', 'pb in allocation',1)
+    IF (ierr /= 0) CALL abort_physic('pbl_surface_init', 'pb in allocation',1)
 
     ALLOCATE(ftsoil(klon,nsoilmx,nbsrf), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('pbl_surface_init', 'pb in allocation',1)
+    IF (ierr /= 0) CALL abort_physic('pbl_surface_init', 'pb in allocation',1)
 
 
@@ -100,5 +99,5 @@
       WRITE(lunout,*)"or on doit commencer par les surfaces continentales"
       abort_message="voir ci-dessus"
-      CALL abort_gcm(modname,abort_message,1)
+      CALL abort_physic(modname,abort_message,1)
     ENDIF
 
@@ -109,5 +108,5 @@
       WRITE(lunout,*)' or is_oce = ',is_oce, '> is_sic = ',is_sic
       abort_message='voir ci-dessus'
-      CALL abort_gcm(modname,abort_message,1)
+      CALL abort_physic(modname,abort_message,1)
     ENDIF
 
@@ -118,5 +117,5 @@
       WRITE(lunout,*)' or is_lic = ',is_lic, '> is_sic = ',is_sic
       abort_message='voir ci-dessus'
-      CALL abort_gcm(modname,abort_message,1)
+      CALL abort_physic(modname,abort_message,1)
     ENDIF
 
@@ -130,5 +129,5 @@
        WRITE(lunout,*)'Option couplage pour l''ocean = ', type_ocean
        abort_message='option pour l''ocean non valable'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
     ENDIF
 
@@ -261,4 +260,7 @@
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send
     USE indice_sol_mod
+    USE time_phylmdz_mod, ONLY: day_ini,annee_ref,itau_phy
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
+    USE print_control_mod, ONLY: prt_level,lunout
 
     IMPLICIT NONE
@@ -266,11 +268,8 @@
     INCLUDE "dimsoil.h"
     INCLUDE "YOMCST.h"
-    INCLUDE "iniprint.h"
     INCLUDE "YOETHF.h"
     INCLUDE "FCTTRE.h"
     INCLUDE "clesphys.h"
     INCLUDE "compbl.h"
-    INCLUDE "dimensions.h"
-    INCLUDE "temps.h"
     INCLUDE "flux_arp.h"
 !****************************************************************************************
@@ -733,9 +732,9 @@
 
 ! For debugging with IOIPSL
-    INTEGER, DIMENSION(iim*(jjm+1))    :: ndexbg
+    INTEGER, DIMENSION(nbp_lon*nbp_lat)    :: ndexbg
     REAL                               :: zjulian
     REAL, DIMENSION(klon)              :: tabindx
-    REAL, DIMENSION(iim,jjm+1)         :: zx_lon, zx_lat
-    REAL, DIMENSION(iim,jjm+1)         :: debugtab
+    REAL, DIMENSION(nbp_lon,nbp_lat)         :: zx_lon, zx_lat
+    REAL, DIMENSION(nbp_lon,nbp_lat)         :: debugtab
 
 
@@ -794,12 +793,12 @@
           idayref = day_ini
           CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
-          CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlon,zx_lon)
-          DO i = 1, iim
+          CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlon,zx_lon)
+          DO i = 1, nbp_lon
              zx_lon(i,1) = rlon(i+1)
-             zx_lon(i,jjm+1) = rlon(i+1)
+             zx_lon(i,nbp_lat) = rlon(i+1)
           ENDDO
-          CALL gr_fi_ecrit(1,klon,iim,jjm+1,rlat,zx_lat)
-          CALL histbeg("sous_index", iim,zx_lon(:,1),jjm+1,zx_lat(1,:), &
-               1,iim,1,jjm+1, &
+          CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlat,zx_lat)
+          CALL histbeg("sous_index",nbp_lon,zx_lon(:,1),nbp_lat,zx_lat(1,:), &
+               1,nbp_lon,1,nbp_lat, &
                itau_phy,zjulian,dtime,nhoridbg,nidbg) 
           ! no vertical axis
@@ -809,6 +808,6 @@
           cl_surf(4)='sic'
           DO nsrf=1,nbsrf
-             CALL histdef(nidbg, cl_surf(nsrf),cl_surf(nsrf), "-",iim, &
-                  jjm+1,nhoridbg, 1, 1, 1, -99, 32, "inst", dtime,dtime) 
+             CALL histdef(nidbg, cl_surf(nsrf),cl_surf(nsrf), "-",nbp_lon, &
+                  nbp_lat,nhoridbg, 1, 1, 1, -99, 32, "inst", dtime,dtime) 
           END DO
 
@@ -1144,5 +1143,5 @@
           ndexbg(:) = 0
           CALL gath2cpl(tabindx,debugtab,knon,ni)
-          CALL histwrite(nidbg,cl_surf(nsrf),itap,debugtab,iim*(jjm+1), ndexbg)
+          CALL histwrite(nidbg,cl_surf(nsrf),itap,debugtab,nbp_lon*nbp_lat, ndexbg)
        ENDIF
        
@@ -1318,5 +1317,5 @@
 !     *sqrt(yu(i,1)*yu(i,1)+yv(i,1)*yv(i,1)))
        ycdragm(i) = ust*ust/(1.+vent)/vent
-       print *,'ycdragm ust yu yv apres=',ycdragm(i),ust,yu(i,1),yv(i,1)
+!      print *,'ycdragm ust yu yv apres=',ycdragm(i),ust,yu(i,1),yv(i,1)
       ENDDO
      ENDIF
@@ -1343,8 +1342,8 @@
         IF (ok_prescr_ust) then
          DO i = 1, knon
-          print *,'ycdragm_x avant=',ycdragm_x(i)
+!         print *,'ycdragm_x avant=',ycdragm_x(i)
           vent= sqrt(yu_x(i,1)*yu_x(i,1)+yv_x(i,1)*yv_x(i,1))
           ycdragm_x(i) = ust*ust/(1.+vent)/vent
-          print *,'ycdragm_x ust yu yv apres=',ycdragm_x(i),ust,yu_x(i,1),yv_x(i,1)
+!         print *,'ycdragm_x ust yu yv apres=',ycdragm_x(i),ust,yu_x(i,1),yv_x(i,1)
          ENDDO
         ENDIF
@@ -1367,11 +1366,11 @@
             ycdragm_w, ycdragh_w, zri1_w, pref_w )
 
-! --- special Dice. JYG+MPL 25112013
+! --- special Dice. JYG+MPL 25112013 puis BOMEX
         IF (ok_prescr_ust) then
          DO i = 1, knon
-          print *,'ycdragm_w avant=',ycdragm_w(i)
+!         print *,'ycdragm_w avant=',ycdragm_w(i)
           vent= sqrt(yu_w(i,1)*yu_w(i,1)+yv_w(i,1)*yv_w(i,1))
           ycdragm_w(i) = ust*ust/(1.+vent)/vent
-          print *,'ycdragm_w ust yu yv apres=',ycdragm_w(i),ust,yu_w(i,1),yv_w(i,1)
+!         print *,'ycdragm_w ust yu yv apres=',ycdragm_w(i),ust,yu_w(i,1),yv_w(i,1)
          ENDDO
         ENDIF
@@ -1747,6 +1746,7 @@
                y_flux_u1, y_flux_v1 )
                
-! Special DICE MPL 05082013
+! Special DICE MPL 05082013 puis BOMEX
        IF (ok_prescr_ust) THEN
+          do j=1,knon
 !         ysnow(:)=0.
 !         yqsol(:)=0.
@@ -1761,6 +1761,7 @@
 !         y_dflux_t(:)=0.
 !         y_dflux_q(:)=0.
-          y_flux_u1(:)=ycdragm(:)*(1.+sqrt(yu(:,1)*yu(:,1)+yv(:,1)*yv(:,1)))*yu(:,1)*ypplay(:,1)/RD/yt(:,1)
-          y_flux_v1(:)=ycdragm(:)*(1.+sqrt(yu(:,1)*yu(:,1)+yv(:,1)*yv(:,1)))*yv(:,1)*ypplay(:,1)/RD/yt(:,1)
+          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
 
@@ -1797,4 +1798,11 @@
           END DO
           ! 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
           
        CASE(is_oce)
@@ -1825,4 +1833,11 @@
           print *,'arg de surf_ocean: ytsurf_new ',ytsurf_new
        ENDIF
+! 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
           
        CASE(is_sic)
@@ -1844,9 +1859,16 @@
                y_flux_u1, y_flux_v1)
           
+! 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
 
        CASE DEFAULT
           WRITE(lunout,*) 'Surface index = ', nsrf
           abort_message = 'Surface index not valid'
-          CALL abort_gcm(modname,abort_message,1)
+          CALL abort_physic(modname,abort_message,1)
        END SELECT
 
@@ -1886,6 +1908,8 @@
 !
           IF (iflag_split .eq.0) THEN
-             Kech_h(:) = ycdragh(:) * (1.0+SQRT(yu(:,1)**2+yv(:,1)**2)) * &
-                  ypplay(:,1)/(RD*yt(:,1))
+             do j=1,knon
+             Kech_h(j) = ycdragh(j) * (1.0+SQRT(yu(j,1)**2+yv(j,1)**2)) * &
+                  ypplay(j,1)/(RD*yt(j,1))
+             enddo
           ENDIF ! (iflag_split .eq.0)
 
@@ -1895,9 +1919,13 @@
           ENDDO
 
-          y_d_ts(:) = ytsurf_new(:) - yts(:) 
+          do j=1,knon
+          y_d_ts(j) = ytsurf_new(j) - yts(j) 
+          enddo
 
         ELSE ! (ok_flux_surf)
-          y_flux_t1(:) =  yfluxsens(:)
-          y_flux_q1(:) = -yevap(:)
+          do j=1,knon
+          y_flux_t1(j) =  yfluxsens(j)
+          y_flux_q1(j) = -yevap(j)
+          enddo
         ENDIF
 
@@ -3060,5 +3088,5 @@
                 ! Security abort. This option has never been tested. To test, comment the following line.
 !                abort_message='The fraction of the continents have changed!'
-!                CALL abort_gcm(modname,abort_message,1)
+!                CALL abort_physic(modname,abort_message,1)
                 nfois(nsrf) = nfois(nsrf) + 1
              END IF
Index: /LMDZ5/branches/testing/libf/phylmd/perturb_radlwsw.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/perturb_radlwsw.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/perturb_radlwsw.F90	(revision 2408)
@@ -0,0 +1,27 @@
+      SUBROUTINE perturb_radlwsw(zxtsol,iflag_radia)
+!
+!Case-specific radiative setup
+!
+      use dimphy
+      IMPLICIT none
+      INCLUDE "flux_arp.h"     
+!
+! Arguments :
+!------------
+      REAL,DIMENSION(klon), INTENT(INOUT) :: zxtsol
+      INTEGER, INTENT(IN)                 :: iflag_radia
+!
+!======================================================================
+!
+      IF (iflag_radia == 2) THEN
+!
+! Iflag_radia = 2 : DICE case : 
+!               on force zxtsol=tg pour le rayonnement (MPL 20130806)
+!Sonia : Cas dice lmdz1d force en flux : on impose Tg pour imposer le LWUP
+!
+        zxtsol(:) =  tg
+      ENDIF
+!
+      RETURN
+      END
+
Index: /LMDZ5/branches/testing/libf/phylmd/phyaqua_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phyaqua_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/phyaqua_mod.F90	(revision 2408)
@@ -5,5 +5,5 @@
 CONTAINS
 
-  SUBROUTINE iniaqua(nlon, latfi, lonfi, iflag_phys)
+  SUBROUTINE iniaqua(nlon, iflag_phys)
 
     ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -19,27 +19,24 @@
     ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-    USE comgeomphy, ONLY: rlatd, rlond
     USE dimphy, ONLY: klon
+    USE geometry_mod, ONLY : latitude
     USE surface_data, ONLY: type_ocean, ok_veget
     USE pbl_surface_mod, ONLY: pbl_surface_init
     USE fonte_neige_mod, ONLY: fonte_neige_init
     USE phys_state_var_mod
-    USE control_mod, ONLY: dayref, nday, iphysiq
+    USE time_phylmdz_mod, ONLY: day_ref, ndays, pdtphys, &
+                                day_ini,day_end
     USE indice_sol_mod
-
+    USE nrtype, ONLY: pi
     USE ioipsl
     IMPLICIT NONE
 
-    include "dimensions.h"
-    ! #include "dimphy.h"
-    ! #include "YOMCST.h"
-    include "comconst.h"
+    include "YOMCST.h"
     include "clesphys.h"
     include "dimsoil.h"
-    include "temps.h"
 
     INTEGER, INTENT (IN) :: nlon, iflag_phys
     ! IM ajout latfi, lonfi
-    REAL, INTENT (IN) :: lonfi(nlon), latfi(nlon)
+!    REAL, INTENT (IN) :: lonfi(nlon), latfi(nlon)
 
     INTEGER type_profil, type_aqua
@@ -120,8 +117,8 @@
     INTEGER l, ierr, aslun
 
-    REAL longitude, latitude
+!    REAL longitude, latitude
     REAL paire
 
-    DATA latitude, longitude/48., 0./
+!    DATA latitude, longitude/48., 0./
 
     ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -152,8 +149,8 @@
 
     ! IM ajout latfi, lonfi
-    rlatd = latfi
-    rlond = lonfi
-    rlat = rlatd*180./pi
-    rlon = rlond*180./pi
+!    rlatd = latfi
+!    rlond = lonfi
+!    rlat = rlatd*180./pi
+!    rlon = rlond*180./pi
 
     ! -----------------------------------------------------------------------
@@ -161,9 +158,9 @@
     ! -----------------------------------------------------------------------
 
-    day_ini = dayref
-    day_end = day_ini + nday
-    airefi = 1.
-    zcufi = 1.
-    zcvfi = 1.
+    day_ini = day_ref
+    day_end = day_ini + ndays
+!    airefi = 1.
+!    zcufi = 1.
+!    zcvfi = 1.
     !$OMP MASTER
     nbapp_rad_omp = 24
@@ -263,5 +260,5 @@
     END DO
     ! IM calcul profil sst
-    CALL profil_sst(nlon, rlatd, type_profil, phy_sst)
+    CALL profil_sst(nlon, latitude, type_profil, phy_sst)
 
     CALL writelim(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, phy_ice, &
@@ -276,6 +273,6 @@
     ! Ecriture etat initial physique
 
-    timestep = dtvr*float(iphysiq)
-    radpas = nint(daysec/timestep/float(nbapp_rad))
+    timestep = pdtphys
+    radpas = nint(rday/timestep/float(nbapp_rad))
 
     DO i = 1, longcles
@@ -492,6 +489,4 @@
     USE mod_phys_lmdz_transfert_para, ONLY: gather
     IMPLICIT NONE
-    ! #include "dimensions.h"
-    ! #include "dimphy.h"
     include "netcdf.inc"
 
Index: /LMDZ5/branches/testing/libf/phylmd/phyetat0.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phyetat0.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/phyetat0.F90	(revision 2408)
@@ -11,5 +11,5 @@
   USE phys_state_var_mod, ONLY : ancien_ok, clwcon, detr_therm, dtime, &
        qsol, fevap, z0m, z0h, agesno, &
-       du_gwd_rando, dv_gwd_rando, entr_therm, f0, fm_therm, &
+       du_gwd_rando, du_gwd_front, entr_therm, f0, fm_therm, &
        falb_dir, falb_dif, &
        ftsol, pbl_tke, pctsrf, q_ancien, radpas, radsol, rain_fall, ratqs, &
@@ -21,9 +21,10 @@
        zstd, zthe, zval, ale_bl, ale_bl_trig, alp_bl
   USE iostart, ONLY : close_startphy, get_field, get_var, open_startphy
-  USE infotrac, only: nbtr, nqo, type_trac, tname, niadv
+  USE infotrac_phy, only: nbtr, nqo, type_trac, tname, niadv
   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: tslab, seaice, tice, ocean_slab_init
+  USE time_phylmdz_mod, ONLY: init_iteration, pdtphys, itau_phy
 
   IMPLICIT none
@@ -32,9 +33,7 @@
   ! Objet: Lecture de l'etat initial pour la physique
   !======================================================================
-  include "dimensions.h"
   include "netcdf.inc"
   include "dimsoil.h"
   include "clesphys.h"
-  include "temps.h"
   include "thermcell.h"
   include "compbl.h"
@@ -75,5 +74,5 @@
   ! FH1D
   !     real iolat(jjm+1)
-  real iolat(jjm+1-1/(iim*jjm))
+  !real iolat(jjm+1-1/(iim*jjm))
 
   ! Ouvrir le fichier contenant l'etat initial:
@@ -100,5 +99,5 @@
   ENDDO
 
-  tab_cntrl(1)=dtime
+  tab_cntrl(1)=pdtphys
   tab_cntrl(2)=radpas
 
@@ -134,4 +133,7 @@
   clesphy0(7)=tab_cntrl( 11 )
   clesphy0(8)=tab_cntrl( 12 )
+
+  ! set time iteration
+   CALL init_iteration(itau_phy)
 
   ! Lecture des latitudes (coordonnees):
@@ -223,5 +225,5 @@
         IF (isw.GT.99) THEN
            PRINT*, "Trop de bandes SW"
-           call abort_gcm("phyetat0", "", 1)
+           call abort_physic("phyetat0", "", 1)
         ENDIF
         WRITE(str2, '(i2.2)') isw
@@ -238,5 +240,5 @@
         IF (isoil.GT.99) THEN
            PRINT*, "Trop de couches "
-           call abort_gcm("phyetat0", "", 1)
+           call abort_physic("phyetat0", "", 1)
         ENDIF
         WRITE(str2,'(i2.2)') isoil
@@ -359,5 +361,5 @@
      IF (carbon_cycle_cpl) THEN
         ALLOCATE(co2_send(klon), stat=ierr)
-        IF (ierr /= 0) CALL abort_gcm('phyetat0', 'pb allocation co2_send', 1)
+        IF (ierr /= 0) CALL abort_physic('phyetat0', 'pb allocation co2_send', 1)
         found=phyetat0_get(1,co2_send,"co2_send","co2 send",0.)
      END IF
@@ -369,8 +371,8 @@
 
 !  ondes de gravite non orographiques
-  if (ok_gwd_rando) then
-     found=phyetat0_get(klev,du_gwd_rando,"du_gwd_rando","du_gwd_rando",0.)
-     found=phyetat0_get(klev,dv_gwd_rando,"dv_gwd_rando","dv_gwd_rando",0.)
-  end if
+  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
@@ -449,7 +451,7 @@
 USE iostart, ONLY : get_field
 USE dimphy, only: klon 
+USE print_control_mod, ONLY: lunout
 
 IMPLICIT NONE
-INCLUDE "iniprint.h"
 
 LOGICAL phyetat0_get
@@ -488,7 +490,7 @@
 USE dimphy, only: klon 
 USE indice_sol_mod, only: nbsrf
+USE print_control_mod, ONLY: lunout
 
 IMPLICIT NONE
-INCLUDE "iniprint.h"
 
 LOGICAL phyetat0_srf
@@ -506,5 +508,5 @@
      IF (nbsrf.GT.99) THEN
         WRITE(lunout,*) "Trop de sous-mailles"
-        call abort_gcm("phyetat0", "", 1)
+        call abort_physic("phyetat0", "", 1)
      ENDIF
 
Index: /LMDZ5/branches/testing/libf/phylmd/phyredem.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phyredem.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/phyredem.F90	(revision 2408)
@@ -1,30 +1,37 @@
-! $Id$
-
 SUBROUTINE phyredem (fichnom)
-
-  USE dimphy
-  USE mod_grid_phy_lmdz
-  USE mod_phys_lmdz_para
+!
+!-------------------------------------------------------------------------------
+! Author: Z.X. Li (LMD/CNRS), 1993/08/18
+!-------------------------------------------------------------------------------
+! Purpose: Write restart state for physics.
+!-------------------------------------------------------------------------------
+  USE dimphy, ONLY: klon, klev
   USE fonte_neige_mod,  ONLY : fonte_neige_final
   USE pbl_surface_mod,  ONLY : pbl_surface_final
-  USE phys_state_var_mod
-  USE iostart
+  USE phys_state_var_mod, ONLY: radpas, zmasq, pctsrf, ftsol, falb_dir, &
+                                falb_dif, qsol, fevap, radsol, solsw, sollw, &
+                                sollwdown, rain_fall, snow_fall, z0m, z0h, &
+                                agesno, zmea, zstd, zsig, zgam, zthe, zpic, &
+                                zval, rugoro, t_ancien, q_ancien, u_ancien, &
+                                v_ancien, clwcon, rnebcon, ratqs, pbl_tke, &
+                                wake_delta_pbl_tke, zmax0, f0, sig1, w01, &
+                                wake_deltat, wake_deltaq, wake_s, wake_cstar, &
+                                wake_pe, wake_fip, fm_therm, entr_therm, &
+                                detr_therm, Ale_bl, Ale_bl_trig, Alp_bl, &
+                                du_gwd_rando, du_gwd_front
+  USE geometry_mod, ONLY : longitude_deg, latitude_deg
+  USE iostart, ONLY: open_restartphy, close_restartphy, put_field, put_var
   USE traclmdz_mod, ONLY : traclmdz_to_restart
-  USE infotrac
-  USE control_mod
+  USE infotrac_phy, ONLY: type_trac, niadv, tname, nbtr, nqo
   USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send
-  USE indice_sol_mod
-  USE surface_data
+  USE indice_sol_mod, ONLY: nbsrf, is_oce, is_sic, is_ter, is_lic, epsfra
+  USE surface_data, ONLY: type_ocean, version_ocean
   USE ocean_slab_mod, ONLY : tslab, seaice, tice, fsic
+  USE time_phylmdz_mod, ONLY: annee_ref, day_end, itau_phy, pdtphys
 
   IMPLICIT none
-  !======================================================================
-  ! Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
-  ! Objet: Ecriture de l'etat de redemarrage pour la physique
-  !======================================================================
-  include "netcdf.inc"
+
   include "dimsoil.h"
   include "clesphys.h"
-  include "temps.h"
   include "thermcell.h"
   include "compbl.h"
@@ -49,5 +56,5 @@
   INTEGER isoil, nsrf,isw
   CHARACTER (len=7) :: str7
-  CHARACTER (len=2) :: str2
+  CHARACTER (len=256) :: nam, lnam
   INTEGER           :: it, iiq
 
@@ -68,5 +75,5 @@
      tab_cntrl(ierr) = 0.0
   ENDDO
-  tab_cntrl(1) = dtime
+  tab_cntrl(1) = pdtphys
   tab_cntrl(2) = radpas
   ! co2_ppm : current value of atmospheric CO2
@@ -92,7 +99,7 @@
 
   CALL put_field("longitude", &
-       "Longitudes de la grille physique", rlon)
-
-  CALL put_field("latitude", "Latitudes de la grille physique", rlat)
+       "Longitudes de la grille physique", longitude_deg)
+
+  CALL put_field("latitude", "Latitudes de la grille physique", latitude_deg)
 
   ! PB ajout du masque terre/mer
@@ -126,81 +133,31 @@
   CALL put_field("FSIC", "fraction glace mer", pctsrf(:, is_sic))
 
-  DO nsrf = 1, nbsrf
-     IF (nsrf.LE.99) THEN
-        WRITE(str2, '(i2.2)') nsrf
-        CALL put_field("TS"//str2, "Temperature de surface No."//str2, &
-             ftsol(:, nsrf))
-     ELSE
-        PRINT*, "Trop de sous-mailles"
-        call abort_gcm("phyredem", "", 1)
-     ENDIF
-  ENDDO
+  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
+
+  CALL put_field_srf1("TS","Temperature",ftsol(:,:))
 
 ! ================== Albedo =======================================
   print*,'PHYREDEM NOUVEAU'
-  DO nsrf = 1, nbsrf
-     DO isw=1, nsw
-        IF (isw.LE.99 .AND. nsrf.LE.99) THEN
-           WRITE(str7, '(i2.2, "srf", i2.2)') isw, nsrf
-  print*,'PHYREDEM ',"A_dir_SW"//str7
-           CALL put_field("A_dir_SW"//str7, "Albedo direct du sol bande "//str7, &
-                falb_dir(:, isw, nsrf))
-           CALL put_field("A_dif_SW"//str7, "Albedo difus du sol bande "//str7, &
-                falb_dif(:, isw, nsrf))
-        ELSE
-           PRINT*, "Trop de couches"
-           call abort_gcm("phyredem", "", 1)
-        ENDIF
-     ENDDO
-  ENDDO
-
-! ================== Tsoil =======================================
-  DO nsrf = 1, nbsrf
-     DO isoil=1, nsoilmx
-        IF (isoil.LE.99 .AND. nsrf.LE.99) THEN
-           WRITE(str7, '(i2.2, "srf", i2.2)') isoil, nsrf
-           CALL put_field("Tsoil"//str7, "Temperature du sol No."//str7, &
-                tsoil(:, isoil, nsrf))
-        ELSE
-           PRINT*, "Trop de couches"
-           call abort_gcm("phyredem", "", 1)
-        ENDIF
-     ENDDO
-  ENDDO
-
-  DO nsrf = 1, nbsrf
-     IF (nsrf.LE.99) THEN
-        WRITE(str2, '(i2.2)') nsrf
-        CALL put_field("QS"//str2, "Humidite de surface No."//str2, &
-             qsurf(:, nsrf))
-     ELSE
-        PRINT*, "Trop de sous-mailles"
-        call abort_gcm("phyredem", "", 1)
-     ENDIF
-  END DO
-
-  CALL put_field("QSOL", "Eau dans le sol (mm)", qsol)
-
-  DO nsrf = 1, nbsrf
-     IF (nsrf.LE.99) THEN
-        WRITE(str2, '(i2.2)') nsrf
-        CALL put_field("EVAP"//str2, "Evaporation de surface No."//str2 &
-             , fevap(:, nsrf))
-     ELSE
-        PRINT*, "Trop de sous-mailles"
-        call abort_gcm("phyredem", "", 1)
-     ENDIF
-  ENDDO
-
-  DO nsrf = 1, nbsrf
-     IF (nsrf.LE.99) THEN
-        WRITE(str2, '(i2.2)') nsrf
-        CALL put_field("SNOW"//str2, "Neige de surface No."//str2, &
-             snow(:, nsrf))
-     ELSE
-        PRINT*, "Trop de sous-mailles"
-        call abort_gcm("phyredem", "", 1)
-     ENDIF
-  ENDDO
+  CALL put_field_srf2("A_dir_SW","Albedo direct",falb_dir(:,:,:))
+  CALL put_field_srf2("A_dif_SW","Albedo diffus",falb_dif(:,:,:))
+
+! ================== Tsoil =========================================
+  CALL put_field_srf2("Tsoil","Temperature",tsoil(:,:,:))
+
+  CALL put_field_srf1("QS"  , "Humidite",qsurf(:,:))
+
+  CALL put_field     ("QSOL", "Eau dans le sol (mm)", qsol)
+
+  CALL put_field_srf1("EVAP", "Evaporation", fevap(:,:))
+
+  CALL put_field_srf1("SNOW", "Neige", snow(:,:))
 
   CALL put_field("RADS", "Rayonnement net a la surface", radsol)
@@ -210,5 +167,5 @@
   CALL put_field("sollw", "Rayonnement IF a la surface", sollw)
 
-  CALL put_field("sollwdown", "Rayonnement down IF a la surface", sollw)
+  CALL put_field("sollwdown", "Rayonnement down IF a la surface", sollwdown)
 
   CALL put_field("fder", "Derive de flux", fder)
@@ -218,28 +175,9 @@
   CALL put_field("snow_f", "precipitation solide", snow_fall)
 
-  DO nsrf = 1, nbsrf
-     IF (nsrf.LE.99) THEN
-        WRITE(str2, '(i2.2)') nsrf
-        CALL put_field("Z0m"//str2, "rugosite de surface No."//str2, &
-             z0m(:, nsrf))
-        CALL put_field("Z0h"//str2, "rugosite de surface No."//str2, &
-             z0h(:, nsrf))
-     ELSE
-        PRINT*, "Trop de sous-mailles"
-        call abort_gcm("phyredem", "", 1)
-     ENDIF
-  ENDDO
-
-  DO nsrf = 1, nbsrf
-     IF (nsrf.LE.99) THEN
-        WRITE(str2, '(i2.2)') nsrf
-        CALL put_field("AGESNO"//str2, &
-             "Age de la neige surface No."//str2, &
-             agesno(:, nsrf))
-     ELSE
-        PRINT*, "Trop de sous-mailles"
-        call abort_gcm("phyredem", "", 1)
-     ENDIF
-  ENDDO
+  CALL put_field_srf1("Z0m", "rugosite", z0m(:,:))
+
+  CALL put_field_srf1("Z0h", "rugosite", z0h(:,:))
+
+  CALL put_field_srf1("AGESNO", "Age de la neige", agesno(:,:))
 
   CALL put_field("ZMEA", "ZMEA", zmea)
@@ -280,17 +218,9 @@
 
   IF (iflag_pbl>1) then
-     DO nsrf = 1, nbsrf
-        IF (nsrf.LE.99) THEN
-           WRITE(str2, '(i2.2)') nsrf
-           CALL put_field("TKE"//str2, "Energ. Cineti. Turb."//str2, &
-                pbl_tke(:, 1:klev+1, nsrf))
-           CALL put_field("DELTATKE"//str2, "Del TKE wk/env."//str2, &
-                wake_delta_pbl_tke(:, 1:klev+1, nsrf))
-        ELSE
-           PRINT*, "Trop de sous-mailles"
-           call abort_gcm("phyredem", "", 1)
-        ENDIF
-     ENDDO
-  ENDIF
+    CALL put_field_srf3("TKE", "Energ. Cineti. Turb.", &
+         pbl_tke(:,:,:))
+    CALL put_field_srf3("DELTATKE", "Del TKE wk/env.", &
+         wake_delta_pbl_tke(:,:,:))
+  END IF
 
   ! FIN TKE PBL !
@@ -360,15 +290,67 @@
   END IF
 
-  if (ok_gwd_rando) then
-     call put_field("du_gwd_rando", &
-          "tendency on zonal wind due to gravity waves", &
-          du_gwd_rando)
-     call put_field("dv_gwd_rando", &
-          "tendency on meriodional wind due to gravity waves", &
-          dv_gwd_rando)
-  end if
+  if (ok_gwd_rando) call put_field("du_gwd_rando", &
+       "tendency on zonal wind due to flott gravity waves", du_gwd_rando)
+
+  IF (.not. ok_hines .and. ok_gwd_rando) call put_field("du_gwd_front", &
+       "tendency on zonal wind due to acama gravity waves", du_gwd_front)
 
   CALL close_restartphy
   !$OMP BARRIER
 
+
+  CONTAINS
+
+
+SUBROUTINE put_field_srf1(nam,lnam,field)
+
+  IMPLICIT NONE
+  CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
+  REAL,              INTENT(IN) :: field(:,:)
+  CHARACTER(LEN=256) :: nm, lm, str
+  DO nsrf = 1, SIZE(field,2)
+    WRITE(str, '(i2.2)') nsrf
+    nm=TRIM(nam)//TRIM(str)
+    lm=TRIM(lnam)//" de surface No. "//TRIM(str)
+    CALL put_field(nm,lm,field(:,nsrf))
+  END DO
+
+END SUBROUTINE put_field_srf1
+
+
+SUBROUTINE put_field_srf2(nam,lnam,field)
+
+  IMPLICIT NONE
+  CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
+  REAL,              INTENT(IN) :: field(:,:,:)
+  CHARACTER(LEN=256) :: nm, lm, str
+  DO nsrf = 1, SIZE(field,3)
+    DO isoil=1, SIZE(field,2)
+      WRITE(str, '(i2.2,"srf",i2.2)')isoil,nsrf
+!      WRITE(lunout,*)"PHYREDEM ",TRIM(nam)//TRIM(str)
+      nm=TRIM(nam)//TRIM(str)
+      lm=TRIM(lnam)//" du sol No. "//TRIM(str)
+      CALL put_field(nm,lm,field(:,isoil,nsrf))
+    END DO
+  END DO
+
+END SUBROUTINE put_field_srf2
+
+
+SUBROUTINE put_field_srf3(nam,lnam,field)
+
+  IMPLICIT NONE
+  CHARACTER(LEN=*),  INTENT(IN) :: nam, lnam
+  REAL,              INTENT(IN) :: field(:,:,:)
+  CHARACTER(LEN=256) :: nm, lm, str
+  DO nsrf = 1, SIZE(field,3)
+    WRITE(str, '(i2.2)') nsrf
+    nm=TRIM(nam)//TRIM(str)
+    lm=TRIM(lnam)//TRIM(str)
+    CALL put_field(nm,lm,field(:,1:klev+1,nsrf))
+  END DO
+
+END SUBROUTINE put_field_srf3
+
+
 END SUBROUTINE phyredem
Index: /LMDZ5/branches/testing/libf/phylmd/phys_cal_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_cal_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_cal_mod.F90	(revision 2408)
@@ -1,22 +1,55 @@
 ! $Id:$
 MODULE phys_cal_mod
-! This module contains information on the calendar at the actual time step
+! This module contains information on the calendar at the current time step
 
-  SAVE
-
-  INTEGER :: year_cur      ! current year
-  INTEGER :: mth_cur       ! current month
-  INTEGER :: day_cur       ! current day
-  INTEGER :: days_elapsed  ! number of whole days since start of the simulation 
-  INTEGER :: mth_len       ! number of days in the current month
-  INTEGER year_len ! number of days in the current year
-  REAL    :: hour
-  REAL    :: jD_1jan
-  REAL    :: jH_1jan
-  REAL    :: xjour
+  INTEGER,SAVE :: year_cur      ! current year
+!$OMP THREADPRIVATE(year_cur)
+  INTEGER,SAVE :: mth_cur       ! current month
+!$OMP THREADPRIVATE(mth_cur)
+  INTEGER,SAVE :: day_cur       ! current day
+!$OMP THREADPRIVATE(day_cur)
+  INTEGER,SAVE :: days_elapsed  ! number of whole days since start of the simulation 
+!$OMP THREADPRIVATE(days_elapsed)
+  INTEGER,SAVE :: mth_len       ! number of days in the current month
+!$OMP THREADPRIVATE(mth_len)
+  INTEGER,SAVE :: year_len      ! number of days in the current year
+!$OMP THREADPRIVATE(year_len)
+  REAL,SAVE    :: hour
+!$OMP THREADPRIVATE(hour)
+  REAL,SAVE    :: jD_1jan
+!$OMP THREADPRIVATE(jD_1jan)
+  REAL,SAVE    :: jH_1jan
+!$OMP THREADPRIVATE(jH_1jan)
+  REAL,SAVE    :: xjour
+!$OMP THREADPRIVATE(xjour)
+  REAL,SAVE    :: jD_cur  ! jour courant a l'appel de la physique (jour julien)
+!$OMP THREADPRIVATE(jD_cur)
+  REAL,SAVE    :: jH_cur  ! heure courante a l'appel de la physique (jour julien)
+!$OMP THREADPRIVATE(jH_cur)
+  REAL,SAVE    :: jD_ref  ! jour du demarage de la simulation (jour julien)
+!$OMP THREADPRIVATE(jD_ref)
+ CHARACTER (len=10) :: calend ! type of calendar to use
+                              ! (can be earth_360d, earth_365d or earth_366d)
+!$OMP THREADPRIVATE(calend)
 
 
 CONTAINS
   
+  SUBROUTINE phys_cal_init(annee_ref,day_ref)
+  USE IOIPSL, ONLY:  ymds2ju
+  USE ioipsl_getin_p_mod, ONLY: getin_p
+  IMPLICIT NONE
+    INTEGER,INTENT(IN) :: annee_ref
+    INTEGER,INTENT(IN) :: day_ref
+
+    ! Find out which type of calendar we are using
+    calend = 'earth_360d' ! default
+    CALL getin_p("calend",calend)
+     
+    CALL ymds2ju(annee_ref, 1, day_ref, 0., jD_ref)
+    jD_ref=INT(jD_ref)
+  
+  END SUBROUTINE  phys_cal_init
+
   SUBROUTINE phys_cal_update(jD_cur, jH_cur)
     ! This subroutine updates the module saved variables.
@@ -43,2 +76,3 @@
 
 END MODULE phys_cal_mod
+
Index: /LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90	(revision 2408)
@@ -81,8 +81,16 @@
       !$OMP THREADPRIVATE(d_u_lif, d_v_lif)
 ! Tendances Ondes de G non oro (runs strato).
-      REAL, SAVE, ALLOCATABLE :: d_u_hin(:,:)
-      !$OMP THREADPRIVATE(d_u_hin)
-      REAL, SAVE, ALLOCATABLE :: d_v_hin(:,:)
-      !$OMP THREADPRIVATE(d_v_hin)
+      REAL, SAVE, ALLOCATABLE :: du_gwd_hines(:,:)
+      !$OMP THREADPRIVATE(du_gwd_hines)
+      REAL, SAVE, ALLOCATABLE :: dv_gwd_hines(:,:)
+      !$OMP THREADPRIVATE(dv_gwd_hines)
+      REAL, SAVE, ALLOCATABLE :: dv_gwd_rando(:,:)
+      !$OMP THREADPRIVATE(dv_gwd_rando)
+      REAL, SAVE, ALLOCATABLE :: dv_gwd_front(:,:)
+      !$OMP THREADPRIVATE(dv_gwd_front)
+      REAL, SAVE, ALLOCATABLE :: east_gwstress(:,:)
+      !$OMP THREADPRIVATE(east_gwstress)
+      REAL, SAVE, ALLOCATABLE :: west_gwstress(:,:)
+      !$OMP THREADPRIVATE(west_gwstress)
       REAL, SAVE, ALLOCATABLE :: d_t_hin(:,:)
       !$OMP THREADPRIVATE(d_t_hin)
@@ -231,6 +239,8 @@
 
 !Ajout de celles nÃ©cessaires au phys_output_write_mod
-      REAL, SAVE, ALLOCATABLE :: slp(:)
-!$OMP THREADPRIVATE(slp)
+      REAL, SAVE, ALLOCATABLE :: tal1(:), pal1(:), pab1(:), pab2(:)
+!$OMP THREADPRIVATE(tal1, pal1, pab1, pab2)
+      REAL, SAVE, ALLOCATABLE :: ptstar(:), pt0(:), slp(:)
+!$OMP THREADPRIVATE(ptstar, pt0, slp)
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: sens, flwp, fiwp 
 !$OMP THREADPRIVATE(sens, flwp, fiwp)
@@ -375,5 +385,5 @@
 SUBROUTINE phys_local_var_init
 USE dimphy
-USE infotrac, ONLY : nbtr
+USE infotrac_phy, ONLY : nbtr
 USE aero_mod
 USE indice_sol_mod
@@ -434,5 +444,8 @@
       allocate(topsw0_aero(klon,naero_grp), solsw0_aero(klon,naero_grp))
       allocate(topswcf_aero(klon,3), solswcf_aero(klon,3))
-      allocate(d_u_hin(klon,klev),d_v_hin(klon,klev),d_t_hin(klon,klev))
+      allocate(du_gwd_hines(klon,klev),dv_gwd_hines(klon,klev))
+      allocate(dv_gwd_rando(klon,klev),dv_gwd_front(klon,klev))
+      allocate(east_gwstress(klon,klev),west_gwstress(klon,klev))
+      allocate(d_t_hin(klon,klev))
       allocate(d_q_ch4(klon,klev))
 !      allocate(tausum_aero(klon,nwave,naero_spc))
@@ -496,5 +509,6 @@
 ! FH Ajout de celles nÃ©cessaires au phys_output_write_mod
 
-      ALLOCATE(slp(klon))
+      ALLOCATE(tal1(klon), pal1(klon), pab1(klon), pab2(klon))
+      ALLOCATE(ptstar(klon),pt0(klon),slp(klon))
       ALLOCATE(ale_wake(klon), alp_wake(klon), bils(klon))
       ALLOCATE(cdragm(klon), cdragh(klon), cldh(klon), cldl(klon))
@@ -679,6 +693,8 @@
       deallocate(load_tmp6)
       deallocate(load_tmp7)
-      deallocate(d_u_hin,d_v_hin,d_t_hin)
+      deallocate(du_gwd_hines,dv_gwd_hines,d_t_hin)
       deallocate(d_q_ch4)
+      deallocate(dv_gwd_rando,dv_gwd_front)
+      deallocate(east_gwstress,west_gwstress)
 
 !IM ajout variables CFMIP2/CMIP5
@@ -696,5 +712,6 @@
 
 ! FH Ajout de celles nÃ©cessaires au phys_output_write_mod
-      DEALLOCATE(slp)
+      DEALLOCATE(tal1, pal1, pab1, pab2)
+      DEALLOCATE(ptstar, pt0, slp)
       DEALLOCATE(ale_wake, alp_wake, bils)
       DEALLOCATE(cdragm, cdragh, cldh, cldl)
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 2408)
@@ -43,4 +43,8 @@
   TYPE(ctrl_out), SAVE :: o_flat = ctrl_out((/ 5, 1, 10, 10, 5, 10, 11, 11, 11 /), &
     'flat', 'Latent heat flux', 'W/m2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_ptstar = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
+    'ptstar', 'Air Surface Temperature', 'K', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_pt0 = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
+    'pt0', 'Standard Air Surface Temperature', 'K', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_slp = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
     'slp', 'Sea Level Pressure', 'Pa', (/ ('', i=1, 9) /))
@@ -481,28 +485,28 @@
     'ale_bl', 'ALE BL', 'm2/s2', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_alp_bl = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
-    'alp_bl', 'ALP BL', 'm2/s2', (/ ('', i=1, 9) /))
+    'alp_bl', 'ALP BL', 'W/m2', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_ale_wk = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
     'ale_wk', 'ALE WK', 'm2/s2', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_alp_wk = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
-    'alp_wk', 'ALP WK', 'm2/s2', (/ ('', i=1, 9) /))
+    'alp_wk', 'ALP WK', 'W/m2', (/ ('', i=1, 9) /))
 !!!
 !nrlmd+jyg<
-  type(ctrl_out),save :: o_dtvdf_x        = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
+  type(ctrl_out),save :: o_dtvdf_x        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'dtvdf_x', ' dtvdf off_wake','K/s', (/ ('', i=1, 9) /))
-  type(ctrl_out),save :: o_dtvdf_w        = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
+  type(ctrl_out),save :: o_dtvdf_w        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'dtvdf_w', ' dtvdf within_wake','K/s', (/ ('', i=1, 9) /))
-  type(ctrl_out),save :: o_dqvdf_x        = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
+  type(ctrl_out),save :: o_dqvdf_x        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'dqvdf_x', ' dqvdf off_wake','kg/kg/s', (/ ('', i=1, 9) /))
-  type(ctrl_out),save :: o_dqvdf_w        = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
+  type(ctrl_out),save :: o_dqvdf_w        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'dqvdf_w', ' dqvdf within_wake','kg/kg/s', (/ ('', i=1, 9) /))
 !!
   type(ctrl_out),save :: o_sens_x        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
-'sens_x', 'ALP WK', 'm2/s2', (/ ('', i=1, 9) /))
+'sens_x', 'sens off_wake', 'W/m2', (/ ('', i=1, 9) /))
   type(ctrl_out),save :: o_sens_w        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
-'sens_w', 'ALP WK', 'm2/s2', (/ ('', i=1, 9) /))                                                                                   
+'sens_w', 'sens within_wake', 'W/m2', (/ ('', i=1, 9) /))                                                                                   
   type(ctrl_out),save :: o_flat_x        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
-'flat_x', 'ALP WK', 'm2/s2', (/ ('', i=1, 9) /))                                                                                   
+'flat_x', 'flat off_wake', 'W/m2', (/ ('', i=1, 9) /))                                                                                   
   type(ctrl_out),save :: o_flat_w        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
-'flat_w', 'ALP WK', 'm2/s2', (/ ('', i=1, 9) /))
+'flat_w', 'flat within_wake', 'W/m2', (/ ('', i=1, 9) /))
 !!
   type(ctrl_out),save :: o_delta_tsurf    = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
@@ -531,27 +535,27 @@
     'cin', 'Convective INhibition', 'm2/s2', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_wape = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
-    'wape', '', '', (/ ('', i=1, 9) /))
+    'wape', '', 'm2/s2', (/ ('', i=1, 9) /))
 
 !!! nrlmd le 10/04/2012
 
 !-------Spectre de thermiques de type 2 au LCL
-  TYPE(ctrl_out), SAVE :: o_n2 = ctrl_out((/ 1, 1, 1, 6, 10, 10, 11, 11, 11 /), &
+  TYPE(ctrl_out), SAVE :: o_n2 = ctrl_out((/ 1, 6, 6, 6, 10, 10, 11, 11, 11 /), &
     'n2', 'Nombre de panaches de type 2', ' ', (/ ('', i=1, 9) /))
-  TYPE(ctrl_out), SAVE :: o_s2 = ctrl_out((/ 1, 1, 1, 6, 10, 10, 11, 11, 11 /), &
+  TYPE(ctrl_out), SAVE :: o_s2 = ctrl_out((/ 1, 6, 6, 6, 10, 10, 11, 11, 11 /), &
     's2', 'Surface moyenne des panaches de type 2', 'm2', (/ ('', i=1, 9) /))
                                                                              
 !-------Déclenchement stochastique                                           
-  TYPE(ctrl_out), SAVE :: o_proba_notrig = ctrl_out((/ 1, 1, 1, 6, 10, 10, 11, 11, 11 /), &
+  TYPE(ctrl_out), SAVE :: o_proba_notrig = ctrl_out((/ 1, 6, 6, 6, 10, 10, 11, 11, 11 /), &
     'proba_notrig', &
                          'Probabilite de non-declenchement', ' ', (/ ('', i=1, 9) /))
-  TYPE(ctrl_out), SAVE :: o_random_notrig = ctrl_out((/ 1, 1, 1, 6, 10, 10, 11, 11, 11 /), &
+  TYPE(ctrl_out), SAVE :: o_random_notrig = ctrl_out((/ 1, 6, 6, 6, 10, 10, 11, 11, 11 /), &
     'random_notrig', &
                          'Tirage aleatoire de non-declenchement', ' ', (/ ('', i=1, 9) /))
-  TYPE(ctrl_out), SAVE :: o_ale_bl_stat = ctrl_out((/ 1, 1, 1, 6, 10, 10, 11, 11, 11 /), &
+  TYPE(ctrl_out), SAVE :: o_ale_bl_stat = ctrl_out((/ 1, 6, 6, 6, 10, 10, 11, 11, 11 /), &
     'ale_bl_stat', &
        'ALE_BL_STAT', 'm2/s2', (/ ('', i=1, 9) /))
-  TYPE(ctrl_out), SAVE :: o_ale_bl_trig = ctrl_out((/ 1, 1, 1, 6, 10, 10, 11, 11, 11 /), &
+  TYPE(ctrl_out), SAVE :: o_ale_bl_trig = ctrl_out((/ 1, 6, 6, 6, 10, 10, 11, 11, 11 /), &
     'ale_bl_trig', &
-       'ALE_BL_STAT + Condition P>Pseuil', 'm2/s2', (/ ('', i=1, 9) /))
+       'ALE_BL_STAT + Condition S>Sthreshold', 'm2/s2', (/ ('', i=1, 9) /))
 
 !-------Fermeture statistique
@@ -1085,7 +1089,7 @@
   TYPE(ctrl_out), SAVE :: o_wake_omg = ctrl_out((/ 4, 5, 10, 10, 10, 10, 11, 11, 11 /), &
     'wake_omg', 'wake_omg', ' ', (/ ('', i=1, 9) /))
-  TYPE(ctrl_out), SAVE :: o_wdtrainA = ctrl_out((/ 4, 1, 10,  4,  1, 10, 11, 11, 110 /), &
+  TYPE(ctrl_out), SAVE :: o_wdtrainA = ctrl_out((/ 4, 5, 10,  4, 10, 10, 11, 11, 110 /), &
     'wdtrainA', 'precipitation from AA', '-', (/ ('', i=1, 9) /))
-  TYPE(ctrl_out), SAVE :: o_wdtrainM = ctrl_out((/ 4, 1, 10,  4,  1, 10, 11, 11, 110 /), &
+  TYPE(ctrl_out), SAVE :: o_wdtrainM = ctrl_out((/ 4, 5, 10,  4, 10, 10, 11, 11, 110 /), &
     'wdtrainM', 'precipitation from mixture', '-', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_Vprecip = ctrl_out((/ 10, 10, 10, 10, 10, 10, 11, 11, 11 /), &
@@ -1190,8 +1194,16 @@
   TYPE(ctrl_out), SAVE :: o_dvlif = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'dvlif', 'Orography dV', 'm/s2', (/ ('', i=1, 9) /))
-  TYPE(ctrl_out), SAVE :: o_duhin = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
-    'duhin', 'Hines GWD dU', 'm/s2', (/ ('', i=1, 9) /))
-  TYPE(ctrl_out), SAVE :: o_dvhin = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
-    'dvhin', 'Hines GWD dV', 'm/s2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_du_gwd_hines = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'du_gwd_hines', 'Hines GWD dU', 'm/s2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_dv_gwd_hines = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'dv_gwd_hines', 'Hines GWD dV', 'm/s2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_du_gwd_front = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'du_gwd_front', 'Fronts GWD dU', 'm/s2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_dv_gwd_front = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'dv_gwd_front', 'Fronts GWD dV', 'm/s2', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_east_gwstress = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'east_gwstress', 'Eastward GW Stress', 'Pa', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_west_gwstress = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'west_gwstress', 'Westward GW Stress', 'Pa', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_dtoro = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'dtoro', 'Orography dT', 'K/s', (/ ('', i=1, 9) /))
@@ -1209,4 +1221,19 @@
        = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), 'dv_gwd_rando', &
        "Random gravity waves dV/dt", "m/s2", (/ ('', i=1, 9) /))
+  type(ctrl_out), save:: o_ustr_gwd_hines &
+       = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), 'ustr_gwd_hines', &
+       "zonal wind stress Hines gravity waves", "Pa", (/ ('', i=1, 9) /))
+  type(ctrl_out), save:: o_vstr_gwd_hines &
+       = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), 'vstr_gwd_hines', &
+       "meridional wind stress Hines gravity waves", "Pa", (/ ('', i=1, 9) /))
+  type(ctrl_out), save:: o_ustr_gwd_front &
+       = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), 'ustr_gwd_front', &
+       "zonal wind stress fronts gravity waves", "Pa", (/ ('', i=1, 9) /))
+  type(ctrl_out), save:: o_vstr_gwd_front &
+       = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), 'vstr_gwd_front', &
+       "meridional wind stress fronts gravity waves", "Pa", (/ ('', i=1, 9) /))
+  type(ctrl_out), save:: o_ustr_gwd_rando &
+       = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), 'ustr_gwd_rando', &
+       "zonal wind stress random gravity waves", "Pa", (/ ('', i=1, 9) /))
   type(ctrl_out), save:: o_vstr_gwd_rando &
        = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), 'vstr_gwd_rando', &
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90	(revision 2408)
@@ -36,7 +36,7 @@
     USE iophy 
     USE dimphy
-    USE infotrac
+    USE infotrac_phy, ONLY: nqtot, nqo, niadv, tname, ttext
     USE ioipsl
-    USE phys_cal_mod, only : hour
+    USE phys_cal_mod, only : hour, calend
     USE mod_phys_lmdz_para
     USE aero_mod, only : naero_spc,name_aero
@@ -44,6 +44,8 @@
     USE surface_data, ONLY : ok_snow
     USE phys_output_ctrlout_mod
-    USE mod_grid_phy_lmdz, only: klon_glo
-
+    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
+    USE time_phylmdz_mod, ONLY: day_ini, itau_phy, start_time, annee_ref, day_ref
 #ifdef CPP_XIOS
     ! ug Pour les sorties XIOS
@@ -52,10 +54,6 @@
 
     IMPLICIT NONE
-    include "dimensions.h"
-    include "temps.h"
     include "clesphys.h"
     include "thermcell.h"
-    include "comvert.h"
-    include "iniprint.h"
 
     ! ug Nouveaux arguments n\'ecessaires au histwrite_mod:
@@ -69,5 +67,5 @@
     REAL, DIMENSION(klon, klev+1), INTENT(IN)   :: paprs
     REAL, DIMENSION(klon,klev,nqtot), INTENT(IN):: qx, d_qx
-    REAL, DIMENSION(klon, llm), INTENT(IN)      :: zmasse
+    REAL, DIMENSION(klon, klev), INTENT(IN)      :: zmasse
 
 
@@ -106,6 +104,6 @@
     CHARACTER(LEN=2)                      :: bb3
     CHARACTER(LEN=6)                      :: type_ocean
-    INTEGER, DIMENSION(iim*jjmp1)         ::  ndex2d
-    INTEGER, DIMENSION(iim*jjmp1*klev)    :: ndex3d
+    INTEGER, DIMENSION(nbp_lon*jjmp1)         ::  ndex2d
+    INTEGER, DIMENSION(nbp_lon*jjmp1*klev)    :: ndex3d
     INTEGER                               :: imin_ins, imax_ins
     INTEGER                               :: jmin_ins, jmax_ins
@@ -290,4 +288,9 @@
     WRITE(lunout,*)'Alt approx des couches pour une haut d echelle de 8km = ',Alt(1:klev)
     !          endif
+
+  ecrit_files(7) = ecrit_files(1)
+  ecrit_files(8) = ecrit_files(2)
+  ecrit_files(9) = ecrit_files(3)
+
   DO iff=1,nfiles
 
@@ -343,10 +346,10 @@
           IF (phys_out_regfkey(iff)) then
              imin_ins=1
-             imax_ins=iim
+             imax_ins=nbp_lon
              jmin_ins=1
              jmax_ins=jjmp1
 
              ! correction abderr        
-             do i=1,iim
+             do i=1,nbp_lon
                 WRITE(lunout,*)'io_lon(i)=',io_lon(i)
                 IF (io_lon(i).le.phys_out_lonmin(iff)) imin_ins=i
@@ -367,5 +370,5 @@
                   io_lat(jmax_ins),io_lat(jmin_ins)
 
-             CALL histbeg(phys_out_filenames(iff),iim,io_lon,jjmp1,io_lat, &
+             CALL histbeg(phys_out_filenames(iff),nbp_lon,io_lon,jjmp1,io_lat, &
                   imin_ins,imax_ins-imin_ins+1, &
                   jmin_ins,jmax_ins-jmin_ins+1, &
@@ -418,5 +421,5 @@
             DO iq=nqo+1,nqtot 
             iiq=niadv(iq)
-            o_trac(iq-nqo) = ctrl_out((/ 4, 5, 1, 1, 1, 10, 11, 11, 11 /), &
+            o_trac(iq-nqo) = ctrl_out((/ 4, 5, 5, 5, 10, 10, 11, 11, 11 /), &
                            tname(iiq),'Tracer '//ttext(iiq), "-",  &
                            (/ '', '', '', '', '', '', '', '', '' /))
@@ -523,4 +526,6 @@
     use ioipsl
     USE phys_cal_mod
+    USE time_phylmdz_mod, ONLY: day_ref, annee_ref
+    USE print_control_mod, ONLY: lunout
 
     IMPLICIT NONE
@@ -531,7 +536,4 @@
     real                :: ttt,xxx,timestep,dayseconde,dtime
     parameter (dayseconde=86400.)
-    include "temps.h"
-    include "comconst.h"
-    include "iniprint.h"
 
     ipos=scan(str,'0123456789.',.TRUE.)
@@ -540,5 +542,5 @@
     WRITE(lunout,*) "ipos = ", ipos
     WRITE(lunout,*) "il = ", il
-    if (ipos == 0) call abort_gcm("convers_timesteps", "bad str", 1)
+    if (ipos == 0) call abort_physic("convers_timesteps", "bad str", 1)
     read(str(1:ipos),*) ttt
     WRITE(lunout,*)ttt
@@ -568,2 +570,3 @@
 END MODULE phys_output_mod
 
+
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90	(revision 2408)
@@ -59,5 +59,9 @@
   LOGICAL, SAVE :: vars_defined = .FALSE. ! ug PAS THREADPRIVATE ET C'EST NORMAL
 
+  REAL, allocatable:: zustr_gwd_hines(:), zvstr_gwd_hines(:) ! (klon)
+  REAL, allocatable:: zustr_gwd_front(:), zvstr_gwd_front(:) ! (klon)
   REAL, allocatable:: zustr_gwd_rando(:), zvstr_gwd_rando(:) ! (klon)
+  !$OMP THREADPRIVATE(zustr_gwd_hines, zvstr_gwd_hines)
+  !$OMP THREADPRIVATE(zustr_gwd_front, zvstr_gwd_front)
   !$OMP THREADPRIVATE(zustr_gwd_rando, zvstr_gwd_rando)
 
@@ -86,4 +90,7 @@
     allocate (bils_ec(klon),bils_ech(klon),bils_tke(klon),bils_diss(klon),bils_kinetic(klon),bils_enthalp(klon),bils_latent(klon))
 
+    IF (ok_hines) allocate(zustr_gwd_hines(klon), zvstr_gwd_hines(klon))
+    IF (.not.ok_hines.and.ok_gwd_rando) &
+                  allocate(zustr_gwd_front(klon), zvstr_gwd_front(klon))
     IF (ok_gwd_rando) allocate(zustr_gwd_rando(klon), zvstr_gwd_rando(klon))
 
Index: /LMDZ5/branches/testing/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_output_write_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_output_write_mod.F90	(revision 2408)
@@ -1,4 +1,4 @@
 !
-! $Id$
+! $Header$
 !
 MODULE phys_output_write_mod
@@ -25,8 +25,9 @@
 
     USE dimphy, only: klon, klev, klevp1, nslay
-    USE control_mod, only: day_step, iphysiq
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
+    USE time_phylmdz_mod, only: day_step_phy, start_time, itau_phy
     USE phys_output_ctrlout_mod, only: o_phis, o_aire, is_ter, is_lic, is_oce, &
          is_ave, is_sic, o_contfracATM, o_contfracOR, &
-         o_aireTER, o_flat, o_slp, o_tsol, &
+         o_aireTER, o_flat, o_slp, o_ptstar, o_pt0, o_tsol, &
          o_t2m, o_t2m_min, o_t2m_max, &
          o_t2m_min_mon, o_t2m_max_mon, &
@@ -70,4 +71,9 @@
          o_tSTDlevs, epsfra, o_t_oce_sic, &
          o_ale_bl, o_alp_bl, o_ale_wk, o_alp_wk, &
+         o_dtvdf_x    , o_dtvdf_w    , o_dqvdf_x    , o_dqvdf_w    , &
+         o_sens_x     , o_sens_w     , o_flat_x     , o_flat_w     , &
+         o_delta_tsurf, &
+         o_cdragh_x   , o_cdragh_w   , o_cdragm_x   , o_cdragm_w   , &
+         o_kh         , o_kh_x       , o_kh_w       , &
          o_ale, o_alp, o_cin, o_WAPE, o_wake_h, &
          o_wake_s, o_wake_deltat, o_wake_deltaq, &
@@ -132,5 +138,7 @@
          o_duvdf, o_dvvdf, o_duoro, o_dvoro, &
          o_dtoro, o_dulif, o_dvlif, o_dtlif, &
-         o_duhin, o_dvhin, o_dthin, o_dqch4, o_rsu, &
+         o_du_gwd_hines, o_dv_gwd_hines, o_dthin, o_dqch4, o_rsu, &
+         o_du_gwd_front, o_dv_gwd_front, &
+         o_east_gwstress, o_west_gwstress, &
          o_rsd, o_rlu, o_rld, o_rsucs, o_rsdcs, &
          o_rlucs, o_rldcs, o_tnt, o_tntr, &
@@ -151,5 +159,6 @@
          o_dtr_ls, o_dtr_trsp, o_dtr_sscav, &
          o_dtr_sat, o_dtr_uscav, o_trac_cum, o_du_gwd_rando, o_dv_gwd_rando, &
-         o_vstr_gwd_rando
+         o_ustr_gwd_hines,o_vstr_gwd_hines,o_ustr_gwd_rando,o_vstr_gwd_rando, &
+         o_ustr_gwd_front,o_vstr_gwd_front
 
     USE phys_state_var_mod, only: pctsrf, paire_ter, rain_fall, snow_fall, &
@@ -160,7 +169,8 @@
          SWdn200, SWdn200clr, LWup200, LWup200clr, &
          LWdn200, LWdn200clr, solsw, solsw0, sollw, &
-         radsol, sollw0, sollwdown, sollw, gustiness, &
+         radsol, swradcorr, sollw0, sollwdown, sollw, gustiness, &
          sollwdownclr, lwdn0, ftsol, ustar, u10m, &
          v10m, pbl_tke, wake_delta_pbl_TKE, &
+         delta_tsurf, &
          wstar, cape, ema_pcb, ema_pct, &
          ema_cbmf, Ma, fm_therm, ale_bl, alp_bl, ale, &
@@ -174,10 +184,10 @@
          vqsumSTD, vTsumSTD, O3daysumSTD, wqsumSTD, &
          vphisumSTD, wTsumSTD, u2sumSTD, v2sumSTD, &
-         T2sumSTD, nlevSTD, du_gwd_rando, dv_gwd_rando, &
+         T2sumSTD, nlevSTD, du_gwd_rando, du_gwd_front, &
          ulevSTD, vlevSTD, wlevSTD, philevSTD, qlevSTD, tlevSTD, &
          rhlevSTD, O3STD, O3daySTD, uvSTD, vqSTD, vTSTD, wqSTD, &
          vphiSTD, wTSTD, u2STD, v2STD, T2STD, missing_val_nf90
 
-    USE phys_local_var_mod, only: zxfluxlat, slp, zxtsol, zt2m, &
+    USE phys_local_var_mod, only: zxfluxlat, slp, ptstar, pt0, zxtsol, zt2m, &
          t2m_min_mon, t2m_max_mon, evap, &
          zu10m, zv10m, zq2m, zustar, zxqsurf, &
@@ -193,5 +203,10 @@
          s_pblh, s_pblt, s_lcl, s_therm, uwriteSTD, &
          vwriteSTD, wwriteSTD, phiwriteSTD, qwriteSTD, &
-         twriteSTD, ale_wake, alp_wake, wake_h, &
+         twriteSTD, ale_wake, alp_wake, &
+         dtvdf_x    ,dtvdf_w    ,dqvdf_x    ,dqvdf_w    , &
+         sens_x     ,sens_w     ,zxfluxlat_x,zxfluxlat_w, &
+         cdragh_x   ,cdragh_w   ,cdragm_x   ,cdragm_w   , &
+         kh         ,kh_x       ,kh_w       , &
+         wake_h, &
          wake_omg, d_t_wake, d_q_wake, Vprecip, &
          wdtrainA, wdtrainM, n2, s2, proba_notrig, &
@@ -230,15 +245,19 @@
          zw2, fraca, zmax_th, d_q_ajsb, d_t_ec, d_u_vdf, &
          d_v_vdf, d_u_oro, d_v_oro, d_t_oro, d_u_lif, &
-         d_v_lif, d_t_lif, d_u_hin, d_v_hin, d_t_hin, &
+         d_v_lif, d_t_lif, du_gwd_hines, dv_gwd_hines, d_t_hin, &
+         dv_gwd_rando, dv_gwd_front, &
+         east_gwstress, west_gwstress, &
          d_q_ch4, pmfd, pmfu, ref_liq, ref_ice, rhwriteSTD
 
     USE phys_output_var_mod, only: vars_defined, snow_o, zfra_o, bils_diss, &
          bils_ec,bils_ech, bils_tke, bils_kinetic, bils_latent, bils_enthalp, &
-         itau_con, nfiles, clef_files, nid_files, zvstr_gwd_rando
+         itau_con, nfiles, clef_files, nid_files, &
+         zustr_gwd_hines, zvstr_gwd_hines,zustr_gwd_rando, zvstr_gwd_rando, &
+         zustr_gwd_front, zvstr_gwd_front                                   
     USE ocean_slab_mod, only: tslab, slab_bils, slab_bilg, tice, seaice
     USE pbl_surface_mod, only: snow
     USE indice_sol_mod, only: nbsrf
-    USE infotrac, only: nqtot, nqo, type_trac
-    USE comgeomphy, only: airephy
+    USE infotrac_phy, only: nqtot, nqo, type_trac
+    USE geometry_mod, only: cell_area
     USE surface_data, only: type_ocean, version_ocean, ok_veget, ok_snow
 !    USE aero_mod, only: naero_spc
@@ -247,4 +266,6 @@
     USE iophy, only: set_itau_iophy, histwrite_phy
     USE netcdf, only: nf90_fill_real
+    USE print_control_mod, ONLY: prt_level,lunout
+
 
 #ifdef CPP_XIOS
@@ -259,11 +280,8 @@
 
 
-    INCLUDE "temps.h"
     INCLUDE "clesphys.h"
     INCLUDE "thermcell.h"
     INCLUDE "compbl.h"
     INCLUDE "YOMCST.h"
-    INCLUDE "dimensions.h"
-    include "iniprint.h"
 
     ! Input
@@ -280,5 +298,5 @@
     REAL, DIMENSION(klon, klev+1) :: paprs
     REAL, DIMENSION(klon,klev,nqtot) :: qx, d_qx
-    REAL, DIMENSION(klon, llm) :: zmasse
+    REAL, DIMENSION(klon, klev) :: zmasse
     LOGICAL :: flag_aerosol_strat
     INTEGER :: flag_aerosol 
@@ -287,5 +305,4 @@
 
     ! Local
-    INTEGER, PARAMETER :: jjmp1=jjm+1-1/jjm
     INTEGER :: itau_w
     INTEGER :: i, iinit, iinitend=1, iff, iq, nsrf, k, ll, naero
@@ -294,6 +311,6 @@
     REAL, DIMENSION (klon,klev+1) :: zx_tmp_fi3d1
     CHARACTER (LEN=4)              :: bb2
-    INTEGER, DIMENSION(iim*jjmp1)  :: ndex2d
-    INTEGER, DIMENSION(iim*jjmp1*klev) :: ndex3d
+    INTEGER, DIMENSION(nbp_lon*nbp_lat)  :: ndex2d
+    INTEGER, DIMENSION(nbp_lon*nbp_lat*klev) :: ndex3d
     REAL, PARAMETER :: dobson_u = 2.1415e-05 ! Dobson unit, in kg m-2
 !   REAL, PARAMETER :: missing_val=nf90_fill_real
@@ -304,5 +321,5 @@
 
     ! On calcul le nouveau tau:
-    itau_w = itau_phy + itap + start_time * day_step / iphysiq
+    itau_w = itau_phy + itap + start_time * day_step_phy
     ! On le donne à iophy pour que les histwrite y aient accès:
     CALL set_itau_iophy(itau_w)
@@ -331,5 +348,5 @@
 !!! Champs 1D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        CALL histwrite_phy(o_phis, pphis)
-       CALL histwrite_phy(o_aire, airephy)
+       CALL histwrite_phy(o_aire, cell_area)
 
        IF (vars_defined) THEN
@@ -344,4 +361,6 @@
 !!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        CALL histwrite_phy(o_flat, zxfluxlat)
+       CALL histwrite_phy(o_ptstar, ptstar)
+       CALL histwrite_phy(o_pt0, pt0)
        CALL histwrite_phy(o_slp, slp)
        CALL histwrite_phy(o_tsol, zxtsol)
@@ -418,69 +437,69 @@
        CALL histwrite_phy(o_fsnow, zfra_o)
        CALL histwrite_phy(o_evap, evap)
-       CALL histwrite_phy(o_tops, topsw)
-       CALL histwrite_phy(o_tops0, topsw0)
+       CALL histwrite_phy(o_tops, topsw*swradcorr)
+       CALL histwrite_phy(o_tops0, topsw0*swradcorr)
        CALL histwrite_phy(o_topl, toplw)
        CALL histwrite_phy(o_topl0, toplw0)
 
        IF (vars_defined) THEN
-          zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
+          zx_tmp_fi2d(:) = swup(:,klevp1)*swradcorr(:)
        ENDIF
        CALL histwrite_phy(o_SWupTOA, zx_tmp_fi2d)
 
        IF (vars_defined) THEN
-          zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, klevp1 )
+          zx_tmp_fi2d(:) = swup0(:,klevp1)*swradcorr(:)
        ENDIF
        CALL histwrite_phy(o_SWupTOAclr, zx_tmp_fi2d)
 
        IF (vars_defined) THEN
-          zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
+          zx_tmp_fi2d(:) = swdn(:,klevp1)*swradcorr(:)
        ENDIF
        CALL histwrite_phy(o_SWdnTOA, zx_tmp_fi2d)
 
        IF (vars_defined) THEN
-          zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, klevp1 )
+          zx_tmp_fi2d(:) = swdn0(:,klevp1)*swradcorr(:)
        ENDIF
        CALL histwrite_phy(o_SWdnTOAclr, zx_tmp_fi2d)
 
        IF (vars_defined) THEN
-          zx_tmp_fi2d(:) = topsw(:)-toplw(:)
+          zx_tmp_fi2d(:) = topsw(:)*swradcorr(:)-toplw(:)
        ENDIF
        CALL histwrite_phy(o_nettop, zx_tmp_fi2d)
-       CALL histwrite_phy(o_SWup200, SWup200)
-       CALL histwrite_phy(o_SWup200clr, SWup200clr)
-       CALL histwrite_phy(o_SWdn200, SWdn200)
-       CALL histwrite_phy(o_SWdn200clr, SWdn200clr)
+       CALL histwrite_phy(o_SWup200, SWup200*swradcorr)
+       CALL histwrite_phy(o_SWup200clr, SWup200clr*swradcorr)
+       CALL histwrite_phy(o_SWdn200, SWdn200*swradcorr)
+       CALL histwrite_phy(o_SWdn200clr, SWdn200clr*swradcorr)
        CALL histwrite_phy(o_LWup200, LWup200)
        CALL histwrite_phy(o_LWup200clr, LWup200clr)
        CALL histwrite_phy(o_LWdn200, LWdn200)
        CALL histwrite_phy(o_LWdn200clr, LWdn200clr)
-       CALL histwrite_phy(o_sols, solsw)
-       CALL histwrite_phy(o_sols0, solsw0)
+       CALL histwrite_phy(o_sols, solsw*swradcorr)
+       CALL histwrite_phy(o_sols0, solsw0*swradcorr)
        CALL histwrite_phy(o_soll, sollw)
+       CALL histwrite_phy(o_soll0, sollw0)
        CALL histwrite_phy(o_radsol, radsol)
-       CALL histwrite_phy(o_soll0, sollw0)
-
-       IF (vars_defined) THEN
-          zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 1 )
+
+       IF (vars_defined) THEN
+          zx_tmp_fi2d(:) = swup(:,1)*swradcorr(:)
        ENDIF
        CALL histwrite_phy(o_SWupSFC, zx_tmp_fi2d)
 
        IF (vars_defined) THEN
-          zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 1 )
+          zx_tmp_fi2d(:) = swup0(:,1)*swradcorr(:)
        ENDIF
        CALL histwrite_phy(o_SWupSFCclr, zx_tmp_fi2d)
 
        IF (vars_defined) THEN
-          zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 1 )
+          zx_tmp_fi2d(:) = swdn(:,1)*swradcorr(:)
        ENDIF
        CALL histwrite_phy(o_SWdnSFC, zx_tmp_fi2d)
 
        IF (vars_defined) THEN
-          zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 1 )
+          zx_tmp_fi2d(:) = swdn0(:,1)*swradcorr(:)
        ENDIF
        CALL histwrite_phy(o_SWdnSFCclr, zx_tmp_fi2d)
 
        IF (vars_defined) THEN
-          zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
+          zx_tmp_fi2d(:)=sollwdown(:)-sollw(:)
        ENDIF
        CALL histwrite_phy(o_LWupSFC, zx_tmp_fi2d)
@@ -746,4 +765,26 @@
              CALL histwrite_phy(o_ale_wk, ale_wake)
              CALL histwrite_phy(o_alp_wk, alp_wake)
+             IF (iflag_pbl_split>=1) THEN
+               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=dtvdf_x(1:klon,1:klev)/pdtphys
+               CALL histwrite_phy(o_dtvdf_x    ,zx_tmp_fi3d) 
+               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=dtvdf_w(1:klon,1:klev)/pdtphys
+               CALL histwrite_phy(o_dtvdf_w    ,zx_tmp_fi3d) 
+               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=dqvdf_x(1:klon,1:klev)/pdtphys
+               CALL histwrite_phy(o_dqvdf_x    ,zx_tmp_fi3d) 
+               IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=dqvdf_w(1:klon,1:klev)/pdtphys
+               CALL histwrite_phy(o_dqvdf_w    ,zx_tmp_fi3d) 
+               CALL histwrite_phy(o_sens_x     ,sens_x     ) 
+               CALL histwrite_phy(o_sens_w     ,sens_w     ) 
+               CALL histwrite_phy(o_flat_x     ,zxfluxlat_x) 
+               CALL histwrite_phy(o_flat_w     ,zxfluxlat_w) 
+               CALL histwrite_phy(o_delta_tsurf,delta_tsurf) 
+               CALL histwrite_phy(o_cdragh_x   ,cdragh_x   ) 
+               CALL histwrite_phy(o_cdragh_w   ,cdragh_w   ) 
+               CALL histwrite_phy(o_cdragm_x   ,cdragm_x   ) 
+               CALL histwrite_phy(o_cdragm_w   ,cdragm_w   ) 
+               CALL histwrite_phy(o_kh         ,kh         ) 
+               CALL histwrite_phy(o_kh_x       ,kh_x       ) 
+               CALL histwrite_phy(o_kh_w       ,kh_w       ) 
+             ENDIF   ! (iflag_pbl_split>=1)
              CALL histwrite_phy(o_ale, ale)
              CALL histwrite_phy(o_alp, alp)
@@ -895,8 +936,8 @@
        ENDIF
        IF (ok_ade) THEN
-          CALL histwrite_phy(o_topswad, topswad_aero)
-          CALL histwrite_phy(o_topswad0, topswad0_aero)
-          CALL histwrite_phy(o_solswad, solswad_aero)
-          CALL histwrite_phy(o_solswad0, solswad0_aero)
+          CALL histwrite_phy(o_topswad, topswad_aero*swradcorr)
+          CALL histwrite_phy(o_topswad0, topswad0_aero*swradcorr)
+          CALL histwrite_phy(o_solswad, solswad_aero*swradcorr)
+          CALL histwrite_phy(o_solswad0, solswad0_aero*swradcorr)
           CALL histwrite_phy(o_toplwad, toplwad_aero)
           CALL histwrite_phy(o_toplwad0, toplwad0_aero)
@@ -905,21 +946,35 @@
           !====MS forcing diagnostics
           if (new_aod) then
-             CALL histwrite_phy(o_swtoaas_nat, topsw_aero(:,1))
-             CALL histwrite_phy(o_swsrfas_nat, solsw_aero(:,1))
-             CALL histwrite_phy(o_swtoacs_nat, topsw0_aero(:,1))
-             CALL histwrite_phy(o_swsrfcs_nat, solsw0_aero(:,1))
+             zx_tmp_fi2d(:)=topsw_aero(:,1)*swradcorr(:)
+             CALL histwrite_phy(o_swtoaas_nat,zx_tmp_fi2d)
+             zx_tmp_fi2d(:)=solsw_aero(:,1)*swradcorr(:)
+             CALL histwrite_phy(o_swsrfas_nat,zx_tmp_fi2d)
+             zx_tmp_fi2d(:)=topsw0_aero(:,1)*swradcorr(:)
+             CALL histwrite_phy(o_swtoacs_nat,zx_tmp_fi2d)
+             zx_tmp_fi2d(:)=solsw0_aero(:,1)*swradcorr(:)
+             CALL histwrite_phy(o_swsrfcs_nat,zx_tmp_fi2d)
              !ant
-             CALL histwrite_phy(o_swtoaas_ant, topsw_aero(:,2))
-             CALL histwrite_phy(o_swsrfas_ant, solsw_aero(:,2))
-             CALL histwrite_phy(o_swtoacs_ant, topsw0_aero(:,2))
-             CALL histwrite_phy(o_swsrfcs_ant, solsw0_aero(:,2))
+             zx_tmp_fi2d(:)=topsw_aero(:,2)*swradcorr(:)
+             CALL histwrite_phy(o_swtoaas_ant,zx_tmp_fi2d)
+             zx_tmp_fi2d(:)=solsw_aero(:,2)*swradcorr(:)
+             CALL histwrite_phy(o_swsrfas_ant,zx_tmp_fi2d)
+             zx_tmp_fi2d(:)=topsw0_aero(:,2)*swradcorr(:)
+             CALL histwrite_phy(o_swtoacs_ant,zx_tmp_fi2d)
+             zx_tmp_fi2d(:)=solsw0_aero(:,2)*swradcorr(:)
+             CALL histwrite_phy(o_swsrfcs_ant,zx_tmp_fi2d)
              !cf
              if (.not. aerosol_couple) then
-                CALL histwrite_phy(o_swtoacf_nat, topswcf_aero(:,1))
-                CALL histwrite_phy(o_swsrfcf_nat, solswcf_aero(:,1))
-                CALL histwrite_phy(o_swtoacf_ant, topswcf_aero(:,2))
-                CALL histwrite_phy(o_swsrfcf_ant, solswcf_aero(:,2))
-                CALL histwrite_phy(o_swtoacf_zero,topswcf_aero(:,3))
-                CALL histwrite_phy(o_swsrfcf_zero,solswcf_aero(:,3))
+                zx_tmp_fi2d(:)=topswcf_aero(:,1)*swradcorr(:)
+                CALL histwrite_phy(o_swtoacf_nat,zx_tmp_fi2d)
+                zx_tmp_fi2d(:)=solswcf_aero(:,1)*swradcorr(:)
+                CALL histwrite_phy(o_swsrfcf_nat,zx_tmp_fi2d)
+                zx_tmp_fi2d(:)=topswcf_aero(:,2)*swradcorr(:)
+                CALL histwrite_phy(o_swtoacf_ant,zx_tmp_fi2d)
+                zx_tmp_fi2d(:)=solswcf_aero(:,2)*swradcorr(:)
+                CALL histwrite_phy(o_swsrfcf_ant,zx_tmp_fi2d)
+                zx_tmp_fi2d(:)=topswcf_aero(:,3)*swradcorr(:)
+                CALL histwrite_phy(o_swtoacf_zero,zx_tmp_fi2d)
+                zx_tmp_fi2d(:)=solswcf_aero(:,3)*swradcorr(:)
+                CALL histwrite_phy(o_swsrfcf_zero,zx_tmp_fi2d)
              endif
           endif ! new_aod
@@ -927,6 +982,6 @@
        ENDIF
        IF (ok_aie) THEN
-          CALL histwrite_phy(o_topswai, topswai_aero)
-          CALL histwrite_phy(o_solswai, solswai_aero)
+          CALL histwrite_phy(o_topswai, topswai_aero*swradcorr)
+          CALL histwrite_phy(o_solswai, solswai_aero*swradcorr)
        ENDIF
        IF (flag_aerosol.GT.0.AND.ok_cdnc) THEN
@@ -959,34 +1014,15 @@
        CALL histwrite_phy(o_pres, pplay)
        CALL histwrite_phy(o_paprs, paprs(:,1:klev))
-       IF (vars_defined) THEN
-          DO i=1, klon
-             zx_tmp_fi3d1(i,1)= pphis(i)/RG
-             !020611   zx_tmp_fi3d(i,1)= pphis(i)/RG
-          ENDDO
-          DO k=1, klev
-             !020611        DO k=1, klev-1
-             DO i=1, klon
-                !020611         zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - (t_seri(i,k) *RD * 
-                zx_tmp_fi3d1(i,k+1)= zx_tmp_fi3d1(i,k) - (t_seri(i,k) *RD *  &
-                     (paprs(i,k+1) - paprs(i,k))) / ( pplay(i,k) * RG ) 
-             ENDDO
-          ENDDO
-       ENDIF
-       CALL histwrite_phy(o_zfull,zx_tmp_fi3d1(:,2:klevp1))
-       !020611    $o_zfull%name,itau_w,zx_tmp_fi3d)
+       CALL histwrite_phy(o_zfull,zphi/RG)
 
        IF (vars_defined)  THEN
-          DO i=1, klon
-             zx_tmp_fi3d(i,1)= pphis(i)/RG - ( &
-                  (t_seri(i,1)+zxtsol(i))/2. *RD * &
-                  (pplay(i,1) - paprs(i,1)))/( (paprs(i,1)+pplay(i,1))/2.* RG)
-          ENDDO
-          DO k=1, klev-1
-             DO i=1, klon
-                zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - ( &
-                     (t_seri(i,k)+t_seri(i,k+1))/2. *RD *  &
-                     (pplay(i,k+1) - pplay(i,k))) / ( paprs(i,k) * RG ) 
-             ENDDO
-          ENDDO
+        zx_tmp_fi3d(:,1)= pphis(:)/RG
+        DO k = 2, klev
+         DO i = 1, klon
+            zx_tmp_fi3d(i,k) = zphi(i,k)/RG + &
+                          (zphi(i,k)-zphi(i,k-1))/RG * &
+                          (paprs(i,k)-pplay(i,k))/(pplay(i,k)-pplay(i,k-1))
+         ENDDO
+        ENDDO
        ENDIF
        CALL histwrite_phy(o_zhalf, zx_tmp_fi3d)
@@ -1216,10 +1252,17 @@
 
        IF (ok_hines) THEN
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_u_hin(1:klon,1:klev)/pdtphys
-          CALL histwrite_phy(o_duhin, zx_tmp_fi3d)
-          IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_v_hin(1:klon,1:klev)/pdtphys
-          CALL histwrite_phy(o_dvhin, zx_tmp_fi3d)
+          CALL histwrite_phy(o_du_gwd_hines, du_gwd_hines/pdtphys)
+          CALL histwrite_phy(o_dv_gwd_hines, dv_gwd_hines/pdtphys)
           IF(vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_hin(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dthin, zx_tmp_fi3d)
+          CALL histwrite_phy(o_ustr_gwd_hines, zustr_gwd_hines)
+          CALL histwrite_phy(o_vstr_gwd_hines, zvstr_gwd_hines)
+       end IF
+
+       if (.not. ok_hines .and. ok_gwd_rando) then
+          CALL histwrite_phy(o_du_gwd_front, du_gwd_front / pdtphys)
+          CALL histwrite_phy(o_dv_gwd_front, dv_gwd_front / pdtphys)
+          CALL histwrite_phy(o_ustr_gwd_front, zustr_gwd_front)
+          CALL histwrite_phy(o_vstr_gwd_front, zvstr_gwd_front)
        ENDIF
 
@@ -1227,5 +1270,8 @@
           CALL histwrite_phy(o_du_gwd_rando, du_gwd_rando / pdtphys)
           CALL histwrite_phy(o_dv_gwd_rando, dv_gwd_rando / pdtphys)
+          CALL histwrite_phy(o_ustr_gwd_rando, zustr_gwd_rando)
           CALL histwrite_phy(o_vstr_gwd_rando, zvstr_gwd_rando)
+          CALL histwrite_phy(o_east_gwstress, east_gwstress )
+          CALL histwrite_phy(o_west_gwstress, west_gwstress )
        end IF
 
@@ -1234,12 +1280,26 @@
        ENDIF
 
-       CALL histwrite_phy(o_rsu, swup)
-       CALL histwrite_phy(o_rsd, swdn)
+       DO k=1, klevp1
+         zx_tmp_fi3d1(:,k)=swup(:,k)*swradcorr(:)
+       ENDDO
+       CALL histwrite_phy(o_rsu, zx_tmp_fi3d1)
+       DO k=1, klevp1
+         zx_tmp_fi3d1(:,k)=swdn(:,k)*swradcorr(:)
+       ENDDO
+       CALL histwrite_phy(o_rsd, zx_tmp_fi3d1)
+       DO k=1, klevp1
+         zx_tmp_fi3d1(:,k)=swup0(:,k)*swradcorr(:)
+       ENDDO
+       CALL histwrite_phy(o_rsucs, zx_tmp_fi3d1)
+       DO k=1, klevp1
+         zx_tmp_fi3d1(:,k)=swdn0(:,k)*swradcorr(:)
+       ENDDO
+       CALL histwrite_phy(o_rsdcs, zx_tmp_fi3d1)
+
        CALL histwrite_phy(o_rlu, lwup)
        CALL histwrite_phy(o_rld, lwdn)
-       CALL histwrite_phy(o_rsucs, swup0)
-       CALL histwrite_phy(o_rsdcs, swdn0)
        CALL histwrite_phy(o_rlucs, lwup0)
        CALL histwrite_phy(o_rldcs, lwdn0)
+
        IF(vars_defined) THEN
           zx_tmp_fi3d(1:klon,1:klev)=d_t(1:klon,1:klev)+ &
@@ -1247,4 +1307,5 @@
        ENDIF
        CALL histwrite_phy(o_tnt, zx_tmp_fi3d)
+
        IF(vars_defined) THEN
           zx_tmp_fi3d(1:klon,1:klev)=d_t_swr(1:klon,1:klev)/pdtphys + &
@@ -1294,19 +1355,31 @@
             RN2O_per.NE.RN2O_act.OR.RCFC11_per.NE.RCFC11_act.OR. &
             RCFC12_per.NE.RCFC12_act) THEN
-          IF(vars_defined) zx_tmp_fi2d(1 : klon) = swupp ( 1 : klon, klevp1 )
+          IF(vars_defined) zx_tmp_fi2d(:) = swupp(:,klevp1)*swradcorr(:)
           CALL histwrite_phy(o_rsut4co2, zx_tmp_fi2d)
-          IF(vars_defined) zx_tmp_fi2d(1 : klon) = lwupp ( 1 : klon, klevp1 )
+          IF(vars_defined) zx_tmp_fi2d(:) = lwupp(:,klevp1)
           CALL histwrite_phy(o_rlut4co2, zx_tmp_fi2d)
-          IF(vars_defined) zx_tmp_fi2d(1 : klon) = swup0p ( 1 : klon, klevp1 )
+          IF(vars_defined) zx_tmp_fi2d(:) = swup0p(:,klevp1)*swradcorr(:)
           CALL histwrite_phy(o_rsutcs4co2, zx_tmp_fi2d)
-          IF(vars_defined) zx_tmp_fi2d(1 : klon) = lwup0p ( 1 : klon, klevp1 )
+          IF(vars_defined) zx_tmp_fi2d(:) = lwup0p(:,klevp1)
           CALL histwrite_phy(o_rlutcs4co2, zx_tmp_fi2d)
-          CALL histwrite_phy(o_rsu4co2, swupp)
+          DO k=1, klevp1
+            zx_tmp_fi3d1(:,k)=swupp(:,k)*swradcorr(:)
+          ENDDO
+          CALL histwrite_phy(o_rsu4co2, zx_tmp_fi3d1)
+          DO k=1, klevp1
+            zx_tmp_fi3d1(:,k)=swup0p(:,k)*swradcorr(:)
+          ENDDO
+          CALL histwrite_phy(o_rsucs4co2, zx_tmp_fi3d1)
+          DO k=1, klevp1
+            zx_tmp_fi3d1(:,k)=swdnp(:,k)*swradcorr(:)
+          ENDDO
+          CALL histwrite_phy(o_rsd4co2, zx_tmp_fi3d1)
+          DO k=1, klevp1
+            zx_tmp_fi3d1(:,k)=swdn0p(:,k)*swradcorr(:)
+          ENDDO
+          CALL histwrite_phy(o_rsdcs4co2, zx_tmp_fi3d1)
           CALL histwrite_phy(o_rlu4co2, lwupp)
-          CALL histwrite_phy(o_rsucs4co2, swup0p)
           CALL histwrite_phy(o_rlucs4co2, lwup0p)
-          CALL histwrite_phy(o_rsd4co2, swdnp)
           CALL histwrite_phy(o_rld4co2, lwdnp)
-          CALL histwrite_phy(o_rsdcs4co2, swdn0p)
           CALL histwrite_phy(o_rldcs4co2, lwdn0p)
        ENDIF
Index: /LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90	(revision 2408)
@@ -48,4 +48,6 @@
       REAL, ALLOCATABLE, SAVE :: radsol(:)
 !$OMP THREADPRIVATE(radsol)
+      REAL, ALLOCATABLE, SAVE :: swradcorr(:)
+!$OMP THREADPRIVATE(swradcorr)
 
 !clesphy0 param physiq
@@ -395,6 +397,6 @@
 !!! fin nrlmd le 10/04/2012
 
-      REAL, ALLOCATABLE, SAVE:: du_gwd_rando(:, :), dv_gwd_rando(:, :)
-      !$OMP THREADPRIVATE(du_gwd_rando, dv_gwd_rando)
+      REAL, ALLOCATABLE, SAVE:: du_gwd_rando(:, :), du_gwd_front(:, :)
+      !$OMP THREADPRIVATE(du_gwd_rando, du_gwd_front)
       ! tendencies on wind due to gravity waves
 
@@ -404,7 +406,6 @@
 SUBROUTINE phys_state_var_init(read_climoz)
 USE dimphy
-USE control_mod
 USE aero_mod
-USE infotrac, ONLY : nbtr
+USE infotrac_phy, ONLY : nbtr
 USE indice_sol_mod
 IMPLICIT NONE
@@ -434,4 +435,5 @@
       ALLOCATE(solsw(klon), sollw(klon))
       ALLOCATE(radsol(klon))
+      ALLOCATE(swradcorr(klon))
       ALLOCATE(zmea(klon), zstd(klon), zsig(klon), zgam(klon))
       ALLOCATE(zthe(klon), zpic(klon), zval(klon))
@@ -581,6 +583,6 @@
       ALLOCATE(ale_bl_trig(klon))
 !!! fin nrlmd le 10/04/2012
-      if (ok_gwd_rando) allocate(du_gwd_rando(klon, klev), &
-           dv_gwd_rando(klon, klev))
+      if (ok_gwd_rando) allocate(du_gwd_rando(klon, klev))
+      if (.not. ok_hines .and. ok_gwd_rando) allocate(du_gwd_front(klon, klev))
 
 END SUBROUTINE phys_state_var_init
@@ -589,5 +591,4 @@
 SUBROUTINE phys_state_var_end
 USE dimphy
-USE control_mod
 USE indice_sol_mod
 IMPLICIT NONE
@@ -596,5 +597,5 @@
       deallocate(rlat, rlon, pctsrf, ftsol, falb1, falb2)
       deallocate(qsol,fevap,z0m,z0h,agesno)
-      deallocate(rain_fall, snow_fall, solsw, sollw, radsol)
+      deallocate(rain_fall, snow_fall, solsw, sollw, radsol, swradcorr)
       deallocate(zmea, zstd, zsig, zgam)
       deallocate(zthe, zpic, zval)
@@ -705,5 +706,6 @@
       deallocate(tau_aero_lw_rrtm,piz_aero_lw_rrtm,cg_aero_lw_rrtm)
       deallocate(ccm)
-      if (ok_gwd_rando) deallocate(du_gwd_rando, dv_gwd_rando)
+      if (ok_gwd_rando) deallocate(du_gwd_rando)
+      if (.not. ok_hines .and. ok_gwd_rando) deallocate(du_gwd_front)
        
 !!! nrlmd le 10/04/2012
Index: /LMDZ5/branches/testing/libf/phylmd/physiq.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/physiq.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/physiq.F90	(revision 2408)
@@ -3,7 +3,7 @@
 
 SUBROUTINE physiq (nlon,nlev, &
-     debut,lafin,jD_cur, jH_cur,pdtphys, &
+     debut,lafin,jD_cur_,jH_cur_,pdtphys_, &
      paprs,pplay,pphi,pphis,presnivs, &
-     u,v,t,qx, &
+     u,v,rot,t,qx, &
      flxmass_w, &
      d_u, d_v, d_t, d_qx, d_ps &
@@ -12,14 +12,16 @@
   USE ioipsl, only: histbeg, histvert, histdef, histend, histsync, &
        histwrite, ju2ymds, ymds2ju, getin
-  USE comgeomphy
+  USE geometry_mod, ONLY: cell_area, latitude_deg, longitude_deg
   USE phys_cal_mod, only: year_len, mth_len, days_elapsed, jh_1jan, year_cur, &
-       mth_cur, phys_cal_update
+       mth_cur,jD_cur, jH_cur, jD_ref, phys_cal_update
   USE write_field_phy
   USE dimphy
-  USE infotrac
-  USE mod_grid_phy_lmdz
+  USE infotrac_phy, ONLY: nqtot, nbtr, nqo, type_trac
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev, klon_glo
   USE mod_phys_lmdz_para
   USE iophy
-  USE misc_mod, mydebug=>debug
+  USE print_control_mod, ONLY: mydebug=>debug , lunout, prt_level
+  USE phystokenc_mod, ONLY: offline, phystokenc
+  USE time_phylmdz_mod, only: raz_date, day_step_phy
   USE vampir
   USE pbl_surface_mod, ONLY : pbl_surface
@@ -46,5 +48,7 @@
   use radlwsw_m, only: radlwsw
   use phyaqua_mod, only: zenang_an
-  USE control_mod
+  USE time_phylmdz_mod, only: day_step_phy, annee_ref, day_ref, itau_phy, &
+                              start_time, pdtphys, day_ini
+  USE tracinca_mod, ONLY: config_inca
 #ifdef CPP_XIOS
   USE wxios, ONLY: missing_val, missing_val_omp
@@ -60,8 +64,11 @@
   USE YOERAD   , ONLY : NRADLP
 #endif
+  USE ioipsl_getin_p_mod, ONLY : getin_p
+
 
   !IM stations CFMIP
   USE CFMIP_point_locations
   use FLOTT_GWD_rando_m, only: FLOTT_GWD_rando
+  use ACAMA_GWD_rando_m, only: ACAMA_GWD_rando
 
   IMPLICIT none
@@ -109,15 +116,12 @@
   !! d_ps----output-R-tendance physique de la pression au sol
   !!======================================================================
-  include "dimensions.h"
   integer jjmp1
-  parameter (jjmp1=jjm+1-1/jjm)
-  integer iip1
-  parameter (iip1=iim+1)
+!  parameter (jjmp1=jjm+1-1/jjm) ! => (jjmp1=nbp_lat-1/(nbp_lat-1))
+!  integer iip1
+!  parameter (iip1=iim+1)
 
   include "regdim.h"
   include "dimsoil.h"
   include "clesphys.h"
-  include "temps.h"
-  include "iniprint.h"
   include "thermcell.h"
   !======================================================================
@@ -139,6 +143,7 @@
   !======================================================================
   ! Clef controlant l'activation du cycle diurne:
-  !cc      LOGICAL cycle_diurne
-  !cc      PARAMETER (cycle_diurne=.FALSE.)
+  ! en attente du codage des cles par Fred
+        INTEGER iflag_cycle_diurne
+        PARAMETER (iflag_cycle_diurne=1)
   !======================================================================
   ! Modele thermique du sol, a activer pour le cycle diurne:
@@ -215,7 +220,8 @@
   INTEGER nlon
   INTEGER nlev
-  REAL, intent(in):: jD_cur, jH_cur
-
-  REAL pdtphys
+  REAL, intent(in):: jD_cur_, jH_cur_ 
+! JD_cur and JH_cur to be used in physics are in phys_cal_mod
+  REAL,INTENT(IN) :: pdtphys_
+! NB: pdtphys to be used in physics is in time_phylmdz_mod
   LOGICAL debut, lafin
   REAL paprs(klon,klev+1)
@@ -229,4 +235,8 @@
   REAL u(klon,klev)
   REAL v(klon,klev)
+
+  REAL, intent(in):: rot(klon, klev)
+  ! relative vorticity, in s-1, needed for frontal waves
+
   REAL t(klon,klev),thetal(klon,klev)
   ! thetal: ligne suivante a decommenter si vous avez les fichiers     MPL 20130625
@@ -404,4 +414,8 @@
   REAL dt_a(klon,klev)
   REAL dq_a(klon,klev)
+  REAL d_t_adjwk(klon,klev)                !jyg
+  REAL d_q_adjwk(klon,klev)                !jyg
+  LOGICAL,SAVE :: ok_adjwk=.FALSE.
+  !$OMP THREADPRIVATE(ok_adjwk) 
   REAL, dimension(klon) :: www
   REAL, SAVE :: alp_offset
@@ -440,4 +454,7 @@
   integer :: tau_trig(klon)
 
+  REAL,SAVE :: random_notrig_max=1.
+  !$OMP THREADPRIVATE(random_notrig_max) 
+
   !--------Statistical Boundary Layer Closure: ALP_BL--------
   !---Profils de TKE dans et hors du thermique
@@ -494,5 +511,5 @@
   SAVE lmt_pas                ! frequence de mise a jour
   !$OMP THREADPRIVATE(lmt_pas) 
-  real zmasse(klon, llm),exner(klon, llm) 
+  real zmasse(klon, nbp_lev),exner(klon, nbp_lev) 
   !     (column-density of mass of air in a cell, in kg m-2)
   real, parameter:: dobson_u = 2.1415e-05 ! Dobson unit, in kg m-2
@@ -528,8 +545,4 @@
   EXTERNAL suphel    ! initialiser certaines constantes
   EXTERNAL transp    ! transport total de l'eau et de l'energie
-  EXTERNAL ecribina  ! ecrire le fichier binaire global
-  EXTERNAL ecribins  ! ecrire le fichier binaire global
-  EXTERNAL ecrirega  ! ecrire le fichier binaire regional
-  EXTERNAL ecriregs  ! ecrire le fichier binaire regional
   !IM
   EXTERNAL haut2bas  !variables de haut en bas
@@ -574,7 +587,9 @@
   !  REAL zxsnow(klon)
   REAL zxsnow_dummy(klon)
+  REAL zsav_tsol(klon)
   !
   REAL dist, rmu0(klon), fract(klon)
-  REAL zdtime, zlongi
+  REAL zrmu0(klon), zfract(klon)
+  REAL zdtime, zdtime1, zdtime2, zlongi
   !
   REAL qcheck
@@ -682,5 +697,5 @@
   REAL tabcntr0( length       )
   !
-  INTEGER ndex2d(iim*jjmp1)
+  INTEGER ndex2d(nbp_lon*nbp_lat)
   !IM
   !
@@ -691,15 +706,16 @@
   REAL zustrli(klon), zvstrli(klon)
   REAL zustrph(klon), zvstrph(klon)
-  REAL zustrhi(klon), zvstrhi(klon)
   REAL aam, torsfc
   !IM 141004 END
   !IM 190504 BEG
-  INTEGER ij, imp1jmp1
-  PARAMETER(imp1jmp1=(iim+1)*jjmp1)
+  INTEGER ij
+!  INTEGER imp1jmp1
+!  PARAMETER(imp1jmp1=(iim+1)*jjmp1)
   !ym A voir plus tard
-  REAL zx_tmp(imp1jmp1), airedyn(iim+1,jjmp1)
-  REAL padyn(iim+1,jjmp1,klev+1)
-  REAL dudyn(iim+1,jjmp1,klev)
-  REAL rlatdyn(iim+1,jjmp1)
+  REAL zx_tmp((nbp_lon+1)*nbp_lat)
+  REAL airedyn(nbp_lon+1,nbp_lat)
+  REAL padyn(nbp_lon+1,nbp_lat,klev+1)
+  REAL dudyn(nbp_lon+1,nbp_lat,klev)
+  REAL rlatdyn(nbp_lon+1,nbp_lat)
   !IM 190504 END
   LOGICAL ok_msk
@@ -713,6 +729,7 @@
   REAL zx_tmp_fi2d(klon)      ! variable temporaire grille physique
   REAL zx_tmp_fi3d(klon,klev) ! variable temporaire pour champs 3D 
-  REAL zx_tmp_2d(iim,jjmp1)
-  REAL zx_lon(iim,jjmp1), zx_lat(iim,jjmp1)
+  REAL zx_tmp_2d(nbp_lon,nbp_lat)
+  REAL zx_lon(nbp_lon,nbp_lat)
+  REAL zx_lat(nbp_lon,nbp_lat)
   !
   INTEGER nid_day_seri, nid_ctesGCM
@@ -889,7 +906,13 @@
 !albedo SB <<<
 
+  ! Ehouarn: set value of jjmp1 since it is no longer a "fixed parameter"
+  jjmp1=nbp_lat
+
   !======================================================================
   ! Gestion calendrier : mise a jour du module phys_cal_mod
   !
+  JD_cur=JD_cur_
+  JH_cur=JH_cur_
+  pdtphys=pdtphys_
   CALL phys_cal_update(jD_cur,jH_cur)
 
@@ -902,5 +925,5 @@
      igout=klon/2+1/klon
      write(lunout,*) 'DEBUT DE PHYSIQ !!!!!!!!!!!!!!!!!!!!'
-     write(lunout,*) 'igout, rlat, rlon ',igout, rlatd(igout)*180./3.141593, rlond(igout)*180./3.141593
+     write(lunout,*) 'igout, rlat, rlon ',igout, latitude_deg(igout), longitude_deg(igout)
      write(lunout,*) &
           'nlon,klev,nqtot,debut,lafin, jD_cur, jH_cur,pdtphys'
@@ -975,9 +998,11 @@
   pde_u(:,:) = 0.
   aam=0.
+  d_t_adjwk(:,:)=0
+  d_q_adjwk(:,:)=0
 
   alp_bl_conv(:)=0.
 
   torsfc=0.
-  forall (k=1: llm) zmasse(:, k) = (paprs(:, k)-paprs(:, k+1)) / rg
+  forall (k=1: nbp_lev) zmasse(:, k) = (paprs(:, k)-paprs(:, k+1)) / rg
 
 
@@ -993,4 +1018,6 @@
   IF (debut) THEN
      CALL suphel ! initialiser constantes et parametres phys.
+     CALL getin_p('random_notrig_max',random_notrig_max)
+     CALL getin_p('ok_adjwk',ok_adjwk)
   ENDIF
 
@@ -1033,4 +1060,8 @@
         piz_aero(:,:,:,:) = 0.
         cg_aero(:,:,:,:) = 0.
+
+        config_inca='none' ! default
+        CALL getin_p('config_inca',config_inca)
+
      END IF
 
@@ -1045,9 +1076,9 @@
      print*,'iflag_coupl,iflag_clos,iflag_wake', &
           iflag_coupl,iflag_clos,iflag_wake
-     print*,'CYCLE_DIURNE', cycle_diurne
+     print*,'iflag_CYCLE_DIURNE', iflag_cycle_diurne
      !
      IF (iflag_con.EQ.2.AND.iflag_cld_th.GT.-1) THEN
         abort_message = 'Tiedtke needs iflag_cld_th=-2 or -1'
-        CALL abort_gcm (modname,abort_message,1)
+        CALL abort_physic (modname,abort_message,1)
      ENDIF
      !
@@ -1073,5 +1104,12 @@
      ! pour obtenir le meme resultat.
      dtime=pdtphys
-     radpas = NINT( 86400./dtime/nbapp_rad)
+     IF (MOD(INT(86400./dtime),nbapp_rad).EQ.0) THEN
+       radpas = NINT( 86400./dtime/nbapp_rad)
+     ELSE 
+       WRITE(lunout,*) 'le nombre de pas de temps physique doit etre un multiple de nbapp_rad'
+       WRITE(lunout,*) 'changer nbapp_rad ou alors commenter ce test mais 1+1<>2'
+       abort_message='nbre de pas de temps physique n est pas multiple de nbapp_rad'
+       call abort_physic(modname,abort_message,1)
+     ENDIF
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -1097,8 +1135,4 @@
      ENDIF
 
-     !IM cf. AM 081204 BEG
-     PRINT*,'cycle_diurne3 =',cycle_diurne
-     !IM cf. AM 081204 END
-     !
      CALL printflag( tabcntr0,radpas,ok_journe, &
           ok_instan, ok_region )
@@ -1108,5 +1142,5 @@
              pdtphys
         abort_message='Pas physique n est pas correct '
-        !           call abort_gcm(modname,abort_message,1)
+        !           call abort_physic(modname,abort_message,1)
         dtime=pdtphys
      ENDIF
@@ -1115,5 +1149,5 @@
              klon
         abort_message='nlon et klon ne sont pas coherents'
-        call abort_gcm(modname,abort_message,1)
+        call abort_physic(modname,abort_message,1)
      ENDIF
      IF (nlev .NE. klev) THEN
@@ -1121,12 +1155,12 @@
              klev
         abort_message='nlev et klev ne sont pas coherents'
-        call abort_gcm(modname,abort_message,1)
+        call abort_physic(modname,abort_message,1)
      ENDIF
      !
-     IF (dtime*REAL(radpas).GT.21600..AND.cycle_diurne) THEN 
+     IF (dtime*REAL(radpas).GT.21600..AND.iflag_cycle_diurne.GE.1) THEN 
         WRITE(lunout,*)'Nbre d appels au rayonnement insuffisant'
         WRITE(lunout,*)"Au minimum 4 appels par jour si cycle diurne"
         abort_message='Nbre d appels au rayonnement insuffisant'
-        call abort_gcm(modname,abort_message,1)
+        call abort_physic(modname,abort_message,1)
      ENDIF
      WRITE(lunout,*)"Clef pour la convection, iflag_con=", iflag_con
@@ -1183,5 +1217,5 @@
            IF(nCFMIP.GT.npCFMIP) THEN
               print*,'nCFMIP > npCFMIP : augmenter npCFMIP et recompiler'
-              call abort_gcm("physiq", "", 1)
+              call abort_physic("physiq", "", 1)
            else
               print*,'physiq npCFMIP=',npCFMIP,'nCFMIP=',nCFMIP
@@ -1331,5 +1365,5 @@
              rg, &
              ra, &
-             airephy, &
+             cell_area, &
              rlat, &
              rlon, &
@@ -1538,5 +1572,5 @@
   IF (ip_ebil_phy.ge.1) THEN 
      ztit='after dynamic'
-     CALL diagetpq(airephy,ztit,ip_ebil_phy,1,1,dtime &
+     CALL diagetpq(cell_area,ztit,ip_ebil_phy,1,1,dtime &
           , t_seri,q_seri,ql_seri,qs_seri,u_seri,v_seri,paprs,pplay &
           , d_h_vcol, d_qt, d_qw, d_ql, d_qs, d_ec)
@@ -1545,5 +1579,5 @@
      !     est egale a la variation de la physique au pas de temps precedent.
      !     Donc la somme de ces 2 variations devrait etre nulle.
-     call diagphy(airephy,ztit,ip_ebil_phy &
+     call diagphy(cell_area,ztit,ip_ebil_phy &
           , zero_v, zero_v, zero_v, zero_v, zero_v &
           , zero_v, zero_v, zero_v, ztsol &
@@ -1688,5 +1722,5 @@
         IF (read_climoz/=-1) THEN
            abort_message ='read_climoz=-1 is recommended when solarlong0=1000.'
-           CALL abort_gcm (modname,abort_message,1)
+           CALL abort_physic (modname,abort_message,1)
         ENDIF
      ELSE
@@ -1749,8 +1783,8 @@
   IF (ip_ebil_phy.ge.2) THEN 
      ztit='after reevap'
-     CALL diagetpq(airephy,ztit,ip_ebil_phy,2,1,dtime &
+     CALL diagetpq(cell_area,ztit,ip_ebil_phy,2,1,dtime &
           , t_seri,q_seri,ql_seri,qs_seri,u_seri,v_seri,paprs,pplay &
           , d_h_vcol, d_qt, d_qw, d_ql, d_qs, d_ec)
-     call diagphy(airephy,ztit,ip_ebil_phy &
+     call diagphy(cell_area,ztit,ip_ebil_phy &
           , zero_v, zero_v, zero_v, zero_v, zero_v &
           , zero_v, zero_v, zero_v, ztsol &
@@ -1796,29 +1830,55 @@
   ! non nul aux poles.
   IF (abs(solarlong0-1000.)<1.e-4) then
-     call zenang_an(cycle_diurne,jH_cur,rlat,rlon,rmu0,fract)
+     call zenang_an(iflag_cycle_diurne.GE.1,jH_cur,rlat,rlon,rmu0,fract)
+     JrNt = 1.0
   ELSE
-     !  Avec ou sans cycle diurne
-     IF (cycle_diurne) THEN
+  ! recode par Olivier Boucher en sept 2015
+     SELECT CASE (iflag_cycle_diurne)
+     CASE(0)  
+     !  Sans cycle diurne
+        CALL angle(zlongi, rlat, fract, rmu0)
+        swradcorr = 1.0
+        JrNt = 1.0
+        zrmu0 = rmu0
+     CASE(1)  
+     !  Avec cycle diurne sans application des poids
+     !  bit comparable a l ancienne formulation cycle_diurne=true
+     !  on integre entre gmtime et gmtime+radpas
         zdtime=dtime*REAL(radpas) ! pas de temps du rayonnement (s)
-        CALL zenang(zlongi,jH_cur,zdtime,rlat,rlon,rmu0,fract)
-     ELSE
-        CALL angle(zlongi, rlat, fract, rmu0)
-     ENDIF
+        CALL zenang(zlongi,jH_cur,0.0,zdtime,rlat,rlon,rmu0,fract)
+        zrmu0 = rmu0
+        swradcorr = 1.0
+     ! Calcul du flag jour-nuit
+        JrNt = 0.0
+        WHERE (fract.GT.0.0) JrNt = 1.0
+     CASE(2)  
+     !  Avec cycle diurne sans application des poids
+     !  On integre entre gmtime-pdtphys et gmtime+pdtphys*(radpas-1)
+     !  Comme cette routine est appele a tous les pas de temps de la physique
+     !  meme si le rayonnement n'est pas appele je remonte en arriere les
+     !  radpas-1 pas de temps suivant. Petite ruse avec MOD pour prendre en
+     !  compte le premier pas de temps de la physique pendant lequel itaprad=0 
+        zdtime1=dtime*REAL(-MOD(itaprad,radpas)-1)      
+        zdtime2=dtime*REAL(radpas-MOD(itaprad,radpas)-1) 
+        CALL zenang(zlongi,jH_cur,zdtime1,zdtime2,rlat,rlon,rmu0,fract)
+     !
+     ! Calcul des poids
+     !
+        zdtime1=-dtime !--on corrige le rayonnement pour representer le
+        zdtime2=0.0    !--pas de temps de la physique qui se termine
+        CALL zenang(zlongi,jH_cur,zdtime1,zdtime2,rlat,rlon,zrmu0,zfract)
+        swradcorr = 0.0
+        WHERE (rmu0.GE.1.e-10 .OR. fract.GE.1.e-10) swradcorr=zfract/fract*zrmu0/rmu0
+     ! Calcul du flag jour-nuit
+        JrNt = 0.0
+        WHERE (zfract.GT.0.0) JrNt = 1.0 
+     END SELECT 
   ENDIF
 
-  ! AI Janv 2014 
-  do i = 1, klon
-     if (fract(i).le.0.) then
-        JrNt(i)=0.
-     else
-        JrNt(i)=1.
-     endif
-  enddo
-
   if (mydebug) then
-     call writefield_phy('u_seri',u_seri,llm)
-     call writefield_phy('v_seri',v_seri,llm)
-     call writefield_phy('t_seri',t_seri,llm)
-     call writefield_phy('q_seri',q_seri,llm)
+     call writefield_phy('u_seri',u_seri,nbp_lev)
+     call writefield_phy('v_seri',v_seri,nbp_lev)
+     call writefield_phy('t_seri',t_seri,nbp_lev)
+     call writefield_phy('q_seri',q_seri,nbp_lev)
   endif
 
@@ -1887,5 +1947,5 @@
           dtime,     date0,     itap,    days_elapsed+1, &
           debut,     lafin, &
-          rlon,      rlat,      rugoro,  rmu0,      &
+          rlon,      rlat,      rugoro,  zrmu0,      &
           zsig,      sollwdown, pphi,    cldt,      &
           rain_fall, snow_fall, solsw,   sollw,     &
@@ -1963,8 +2023,8 @@
 
      if (mydebug) then
-        call writefield_phy('u_seri',u_seri,llm)
-        call writefield_phy('v_seri',v_seri,llm)
-        call writefield_phy('t_seri',t_seri,llm)
-        call writefield_phy('q_seri',q_seri,llm)
+        call writefield_phy('u_seri',u_seri,nbp_lev)
+        call writefield_phy('v_seri',v_seri,nbp_lev)
+        call writefield_phy('t_seri',t_seri,nbp_lev)
+        call writefield_phy('q_seri',q_seri,nbp_lev)
      endif
 
@@ -2007,8 +2067,8 @@
      IF (ip_ebil_phy.ge.2) THEN 
         ztit='after surface_main'
-        CALL diagetpq(airephy,ztit,ip_ebil_phy,2,2,dtime &
+        CALL diagetpq(cell_area,ztit,ip_ebil_phy,2,2,dtime &
              , t_seri,q_seri,ql_seri,qs_seri,u_seri,v_seri,paprs,pplay &
              , d_h_vcol, d_qt, d_qw, d_ql, d_qs, d_ec)
-        call diagphy(airephy,ztit,ip_ebil_phy &
+        call diagphy(cell_area,ztit,ip_ebil_phy &
              , zero_v, zero_v, zero_v, zero_v, sens &
              , evap  , zero_v, zero_v, ztsol &
@@ -2057,5 +2117,5 @@
   ENDDO
   IF (check) THEN
-     za = qcheck(klon,klev,paprs,q_seri,ql_seri,airephy)
+     za = qcheck(klon,klev,paprs,q_seri,ql_seri,cell_area)
      WRITE(lunout,*) "avantcon=", za
   ENDIF
@@ -2077,5 +2137,5 @@
   DO k = 1, klev
      DO i = 1, klon
-        omega(i,k) = RG*flxmass_w(i,k) / airephy(i)
+        omega(i,k) = RG*flxmass_w(i,k) / cell_area(i)
      END DO
   END DO
@@ -2085,5 +2145,5 @@
   IF (iflag_con.EQ.1) THEN
      abort_message ='reactiver le call conlmd dans physiq.F'
-     CALL abort_gcm (modname,abort_message,1)
+     CALL abort_physic (modname,abort_message,1)
      !     CALL conlmd (dtime, paprs, pplay, t_seri, q_seri, conv_q,
      !    .             d_t_con, d_q_con,
@@ -2133,4 +2193,29 @@
         enddo
      enddo
+!
+!jyg<
+     ! Perform dry adiabatic adjustment on wake profile
+     ! The corresponding tendencies are added to the convective tendencies
+     ! after the call to the convective scheme.
+     IF (iflag_wake>=1) then
+      IF (ok_adjwk) THEN
+        limbas(:) = 1
+        CALL ajsec(paprs, pplay, t_wake, q_wake, limbas, &
+                  d_t_adjwk, d_q_adjwk)
+      ENDIF
+!
+      DO k=1,klev
+        DO i=1,klon
+          IF (wake_s(i) .GT. 1.e-3) THEN
+            t_wake(i,k) = t_wake(i,k) + d_t_adjwk(i,k)
+            q_wake(i,k) = q_wake(i,k) + d_q_adjwk(i,k)
+            wake_deltat(i,k) = wake_deltat(i,k) + d_t_adjwk(i,k)
+            wake_deltaq(i,k) = wake_deltaq(i,k) + d_q_adjwk(i,k)
+          ENDIF
+        ENDDO
+      ENDDO
+     ENDIF ! (iflag_wake>=1)
+!>jyg
+!
 
      ! Calcul de l'energie disponible ALE (J/kg) et de la puissance
@@ -2223,5 +2308,5 @@
            else
        abort_message ='Ne pas passer la car www non calcule'
-       CALL abort_gcm (modname,abort_message,1)
+       CALL abort_physic (modname,abort_message,1)
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -2322,5 +2407,19 @@
            if (iflagctrl(i).le.1) itau_con(i)=itau_con(i)+1
         enddo
-
+!
+!jyg<
+!    Add the tendency due to the dry adjustment of the wake profile
+      IF (iflag_wake>=1) THEN
+        DO k=1,klev
+          DO i=1,klon
+            ftd(i,k) = ftd(i,k) + wake_s(i)*d_t_adjwk(i,k)/dtime
+            fqd(i,k) = fqd(i,k) + wake_s(i)*d_q_adjwk(i,k)/dtime
+            d_t_con(i,k) = d_t_con(i,k) + wake_s(i)*d_t_adjwk(i,k)
+            d_q_con(i,k) = d_q_con(i,k) + wake_s(i)*d_q_adjwk(i,k)
+          ENDDO
+        ENDDO
+      ENDIF
+!>jyg
+!
      ELSE ! ok_cvl
 
@@ -2403,5 +2502,5 @@
   ELSE
      WRITE(lunout,*) "iflag_con non-prevu", iflag_con
-     call abort_gcm("physiq", "", 1)
+     call abort_physic("physiq", "", 1)
   ENDIF
 
@@ -2415,8 +2514,8 @@
 
   if (mydebug) then
-     call writefield_phy('u_seri',u_seri,llm)
-     call writefield_phy('v_seri',v_seri,llm)
-     call writefield_phy('t_seri',t_seri,llm)
-     call writefield_phy('q_seri',q_seri,llm)
+     call writefield_phy('u_seri',u_seri,nbp_lev)
+     call writefield_phy('v_seri',v_seri,nbp_lev)
+     call writefield_phy('t_seri',t_seri,nbp_lev)
+     call writefield_phy('q_seri',q_seri,nbp_lev)
   endif
 
@@ -2424,8 +2523,8 @@
   IF (ip_ebil_phy.ge.2) THEN 
      ztit='after convect'
-     CALL diagetpq(airephy,ztit,ip_ebil_phy,2,2,dtime &
+     CALL diagetpq(cell_area,ztit,ip_ebil_phy,2,2,dtime &
           , t_seri,q_seri,ql_seri,qs_seri,u_seri,v_seri,paprs,pplay &
           , d_h_vcol, d_qt, d_qw, d_ql, d_qs, d_ec)
-     call diagphy(airephy,ztit,ip_ebil_phy &
+     call diagphy(cell_area,ztit,ip_ebil_phy &
           , zero_v, zero_v, zero_v, zero_v, zero_v &
           , zero_v, rain_con, snow_con, ztsol &
@@ -2435,12 +2534,12 @@
   !
   IF (check) THEN
-     za = qcheck(klon,klev,paprs,q_seri,ql_seri,airephy)
+     za = qcheck(klon,klev,paprs,q_seri,ql_seri,cell_area)
      WRITE(lunout,*)"aprescon=", za
      zx_t = 0.0
      za = 0.0
      DO i = 1, klon
-        za = za + airephy(i)/REAL(klon)
+        za = za + cell_area(i)/REAL(klon)
         zx_t = zx_t + (rain_con(i)+ &
-             snow_con(i))*airephy(i)/REAL(klon)
+             snow_con(i))*cell_area(i)/REAL(klon)
      ENDDO
      zx_t = zx_t/za*dtime
@@ -2589,8 +2688,8 @@
   IF (ip_ebil_phy.ge.2) THEN 
      ztit='after wake'
-     CALL diagetpq(airephy,ztit,ip_ebil_phy,2,2,dtime &
+     CALL diagetpq(cell_area,ztit,ip_ebil_phy,2,2,dtime &
           , t_seri,q_seri,ql_seri,qs_seri,u_seri,v_seri,paprs,pplay &
           , d_h_vcol, d_qt, d_qw, d_ql, d_qs, d_ec)
-     call diagphy(airephy,ztit,ip_ebil_phy &
+     call diagphy(cell_area,ztit,ip_ebil_phy &
           , zero_v, zero_v, zero_v, zero_v, zero_v &
           , zero_v, zero_v, zero_v, ztsol &
@@ -2682,5 +2781,5 @@
              ,ztv,zpspsk,ztla,zthl &
              !cc nrlmd le 10/04/2012
-             ,pbl_tke_input,pctsrf,omega,airephy &
+             ,pbl_tke_input,pctsrf,omega,cell_area &
              ,zlcl_th,fraca0,w0,w_conv,therm_tke_max0,env_tke_max0 &
              ,n2,s2,ale_bl_stat &
@@ -2734,4 +2833,5 @@
               proba_notrig(i)=1.
               random_notrig(i)=1e6*ale_bl_stat(i)-int(1e6*ale_bl_stat(i))
+              if ( random_notrig(i) > random_notrig_max ) random_notrig(i)=0.
               if ( ale_bl_trig(i) .lt. abs(cin(i))+1.e-10 ) then 
                  tau_trig(i)=tau_trig_shallow
@@ -2905,8 +3005,8 @@
   IF (ip_ebil_phy.ge.2) THEN 
      ztit='after dry_adjust'
-     CALL diagetpq(airephy,ztit,ip_ebil_phy,2,2,dtime &
+     CALL diagetpq(cell_area,ztit,ip_ebil_phy,2,2,dtime &
           , t_seri,q_seri,ql_seri,qs_seri,u_seri,v_seri,paprs,pplay &
           , d_h_vcol, d_qt, d_qw, d_ql, d_qs, d_ec)
-     call diagphy(airephy,ztit,ip_ebil_phy &
+     call diagphy(cell_area,ztit,ip_ebil_phy &
           , zero_v, zero_v, zero_v, zero_v, zero_v &
           , zero_v, zero_v, zero_v, ztsol &
@@ -2958,12 +3058,12 @@
   ENDDO
   IF (check) THEN
-     za = qcheck(klon,klev,paprs,q_seri,ql_seri,airephy)
+     za = qcheck(klon,klev,paprs,q_seri,ql_seri,cell_area)
      WRITE(lunout,*)"apresilp=", za
      zx_t = 0.0
      za = 0.0
      DO i = 1, klon
-        za = za + airephy(i)/REAL(klon)
+        za = za + cell_area(i)/REAL(klon)
         zx_t = zx_t + (rain_lsc(i) &
-             + snow_lsc(i))*airephy(i)/REAL(klon)
+             + snow_lsc(i))*cell_area(i)/REAL(klon)
      ENDDO
      zx_t = zx_t/za*dtime
@@ -2973,8 +3073,8 @@
   IF (ip_ebil_phy.ge.2) THEN 
      ztit='after fisrt'
-     CALL diagetpq(airephy,ztit,ip_ebil_phy,2,2,dtime &
+     CALL diagetpq(cell_area,ztit,ip_ebil_phy,2,2,dtime &
           , t_seri,q_seri,ql_seri,qs_seri,u_seri,v_seri,paprs,pplay &
           , d_h_vcol, d_qt, d_qw, d_ql, d_qs, d_ec)
-     call diagphy(airephy,ztit,ip_ebil_phy &
+     call diagphy(cell_area,ztit,ip_ebil_phy &
           , zero_v, zero_v, zero_v, zero_v, zero_v &
           , zero_v, rain_lsc, snow_lsc, ztsol &
@@ -2984,8 +3084,8 @@
 
   if (mydebug) then
-     call writefield_phy('u_seri',u_seri,llm)
-     call writefield_phy('v_seri',v_seri,llm)
-     call writefield_phy('t_seri',t_seri,llm)
-     call writefield_phy('q_seri',q_seri,llm)
+     call writefield_phy('u_seri',u_seri,nbp_lev)
+     call writefield_phy('v_seri',v_seri,nbp_lev)
+     call writefield_phy('t_seri',t_seri,nbp_lev)
+     call writefield_phy('q_seri',q_seri,nbp_lev)
   endif
 
@@ -3056,5 +3156,5 @@
      !jq - Johannes Quaas, 27/11/2003 (quaas@lmd.jussieu.fr)
      IF (flag_aerosol .gt. 0) THEN
-        IF (iflag_rrtm .EQ. 0) THEN !--old radiation
+         IF (iflag_rrtm .EQ. 0) THEN !--old radiation
            IF (.NOT. aerosol_couple) THEN
               !
@@ -3069,8 +3169,11 @@
            IF (aerosol_couple .AND. config_inca == 'aero' ) THEN
             abort_message='config_inca=aero et rrtm=1 impossible'
-            call abort_gcm(modname,abort_message,1)
+            call abort_physic(modname,abort_message,1)
            ELSE
 !
 #ifdef CPP_RRTM
+           IF (NSW.EQ.6) THEN
+!--new aerosol properties
+!
              CALL readaerosol_optic_rrtm( debut, aerosol_couple, &
              new_aod, flag_aerosol, itap, jD_cur-jD_ref, &
@@ -3080,9 +3183,32 @@
              tausum_aero, tau3d_aero)
 
-             CALL aeropt_lw_rrtm
+           ELSE IF (NSW.EQ.2) THEN 
+!--for now we use the old aerosol properties
+!
+              CALL readaerosol_optic( &
+                   debut, new_aod, flag_aerosol, itap, jD_cur-jD_ref, &
+                   pdtphys, pplay, paprs, t_seri, rhcl, presnivs,  &
+                   mass_solu_aero, mass_solu_aero_pi,  &
+                   tau_aero, piz_aero, cg_aero,  &
+                   tausum_aero, tau3d_aero)
+!
+                   !--natural aerosols
+                   tau_aero_sw_rrtm(:,:,1,:)=tau_aero(:,:,3,:)
+                   piz_aero_sw_rrtm(:,:,1,:)=piz_aero(:,:,3,:)
+                   cg_aero_sw_rrtm (:,:,1,:)=cg_aero (:,:,3,:)
+                   !--all aerosols
+                   tau_aero_sw_rrtm(:,:,2,:)=tau_aero(:,:,2,:)
+                   piz_aero_sw_rrtm(:,:,2,:)=piz_aero(:,:,2,:)
+                   cg_aero_sw_rrtm (:,:,2,:)=cg_aero (:,:,2,:)
+           ELSE
+              abort_message='Only NSW=2 or 6 are possible with aerosols and iflag_rrtm=1'
+              call abort_physic(modname,abort_message,1)
+           ENDIF
+
+           CALL aeropt_lw_rrtm
+!
 #else
-
-              abort_message='You should compile with -rrtm if running with iflag_rrtm=1'
-              call abort_gcm(modname,abort_message,1)
+           abort_message='You should compile with -rrtm if running with iflag_rrtm=1'
+           call abort_physic(modname,abort_message,1)
 #endif
               !
@@ -3117,5 +3243,5 @@
 
            abort_message='You should compile with -rrtm if running with iflag_rrtm=1'
-           call abort_gcm(modname,abort_message,1)
+           call abort_physic(modname,abort_message,1)
 #endif
         ENDIF
@@ -3217,8 +3343,8 @@
   IF (ip_ebil_phy.ge.2) THEN 
      ztit="after diagcld"
-     CALL diagetpq(airephy,ztit,ip_ebil_phy,2,2,dtime &
+     CALL diagetpq(cell_area,ztit,ip_ebil_phy,2,2,dtime &
           , t_seri,q_seri,ql_seri,qs_seri,u_seri,v_seri,paprs,pplay &
           , d_h_vcol, d_qt, d_qw, d_ql, d_qs, d_ec)
-     call diagphy(airephy,ztit,ip_ebil_phy &
+     call diagphy(cell_area,ztit,ip_ebil_phy &
           , zero_v, zero_v, zero_v, zero_v, zero_v &
           , zero_v, zero_v, zero_v, ztsol &
@@ -3286,5 +3412,5 @@
         CALL AEROSOL_METEO_CALC( &
              calday,pdtphys,pplay,paprs,t,pmflxr,pmflxs, &
-             prfl,psfl,pctsrf,airephy,rlat,rlon,u10m,v10m)
+             prfl,psfl,pctsrf,cell_area,rlat,rlon,u10m,v10m)
      END IF
 
@@ -3297,5 +3423,5 @@
           rlat, &
           rlon, &
-          airephy, &
+          cell_area, &
           paprs, &
           pplay, &
@@ -3316,6 +3442,6 @@
           ibas_con, &
           cldfra, &
-          iim, &
-          jjm, &
+          nbp_lon, &
+          nbp_lat-1, &
           tr_seri, &
           ftsol, &
@@ -3346,10 +3472,10 @@
         IF (ok_cdnc.AND.NRADLP.NE.3) THEN
            abort_message='RRTM choix incoherent NRADLP doit etre egal a 3 pour ok_cdnc' 
-           call abort_gcm(modname,abort_message,1)
+           call abort_physic(modname,abort_message,1)
         endif
 #else
 
         abort_message='You should compile with -rrtm if running with iflag_rrtm=1'
-        call abort_gcm(modname,abort_message,1)
+        call abort_physic(modname,abort_message,1)
 #endif
      ENDIF
@@ -3376,4 +3502,5 @@
   cldtaupirad = cldtaupi
   cldemirad   = cldemi
+  cldfrarad   = cldfra
 
   !
@@ -3444,9 +3571,18 @@
 
      if (mydebug) then
-        call writefield_phy('u_seri',u_seri,llm)
-        call writefield_phy('v_seri',v_seri,llm)
-        call writefield_phy('t_seri',t_seri,llm)
-        call writefield_phy('q_seri',q_seri,llm)
+        call writefield_phy('u_seri',u_seri,nbp_lev)
+        call writefield_phy('v_seri',v_seri,nbp_lev)
+        call writefield_phy('t_seri',t_seri,nbp_lev)
+        call writefield_phy('q_seri',q_seri,nbp_lev)
      endif
+
+!
+!sonia :   If Iflag_radia >=2, pertubation of some variables input to radiation
+!(DICE)
+!
+      IF (iflag_radia .ge. 2) THEN
+        zsav_tsol (:) = zxtsol(:)
+        call perturb_radlwsw(zxtsol,iflag_radia)
+      ENDIF
 
      IF (aerosol_couple) THEN 
@@ -3457,5 +3593,5 @@
              wo(:, :, 1), &
              cldfrarad, cldemirad, cldtaurad, &
-             heat,heat0,cool,cool0,radsol,albpla, &
+             heat,heat0,cool,cool0,albpla, &
              topsw,toplw,solsw,sollw, &
              sollwdown, &
@@ -3503,5 +3639,5 @@
              zqsat, flwc, fiwc, &
              ref_liq, ref_ice, ref_liq_pi, ref_ice_pi, &
-             heat,heat0,cool,cool0,radsol,albpla, &
+             heat,heat0,cool,cool0,albpla, &
              topsw,toplw,solsw,sollw, &
              sollwdown, &
@@ -3559,5 +3695,5 @@
                    zqsat, flwc, fiwc, &
                    ref_liq, ref_ice, ref_liq_pi, ref_ice_pi, &
-                   heatp,heat0p,coolp,cool0p,radsolp,albplap, &
+                   heatp,heat0p,coolp,cool0p,albplap, &
                    topswp,toplwp,solswp,sollwp, &
                    sollwdownp, &
@@ -3583,4 +3719,10 @@
      ENDIF ! aerosol_couple
      itaprad = 0
+!
+!  If Iflag_radia >=2, reset pertubed variables
+!
+      IF (iflag_radia .ge. 2) THEN
+        zxtsol(:) = zsav_tsol (:)
+      ENDIF
   ENDIF ! MOD(itaprad,radpas)
   itaprad = itaprad + 1
@@ -3600,6 +3742,4 @@
      swup=0.    ! MPL 27102011 pour les fichiers AMMA_profiles et AMMA_scalars
      swup0=0.
-     swdn=0.
-     swdn0=0.
      lwup=0.
      lwup0=0.
@@ -3609,10 +3749,25 @@
 
   !
+  ! Calculer radsol a l'exterieur de radlwsw
+  ! pour prendre en compte le cycle diurne
+  ! recode par Olivier Boucher en sept 2015
+  !
+  radsol=solsw*swradcorr+sollw
+  if (ok_4xCO2atm) then
+    radsolp=solswp*swradcorr+sollwp
+  endif
+
+  !
   ! Ajouter la tendance des rayonnements (tous les pas)
-  !
-  d_t_swr(:,:)=heat(:,:)*dtime/RDAY
-  d_t_lwr(:,:)=-cool(:,:)*dtime/RDAY
-  d_t_sw0(:,:)=heat0(:,:)*dtime/RDAY
-  d_t_lw0(:,:)=-cool0(:,:)*dtime/RDAY
+  ! avec une correction pour le cycle diurne dans le SW
+  !
+  
+  DO k=1, klev
+    d_t_swr(:,k)=swradcorr(:)*heat(:,k)*dtime/RDAY
+    d_t_sw0(:,k)=swradcorr(:)*heat0(:,k)*dtime/RDAY
+    d_t_lwr(:,k)=-cool(:,k)*dtime/RDAY
+    d_t_lw0(:,k)=-cool0(:,k)*dtime/RDAY
+  ENDDO
+
   CALL add_phys_tend(du0,dv0,d_t_swr,dq0,dql0,dqi0,paprs,'SW',abortphy)
   CALL add_phys_tend(du0,dv0,d_t_lwr,dq0,dql0,dqi0,paprs,'LW',abortphy)
@@ -3620,8 +3775,8 @@
   !
   if (mydebug) then
-     call writefield_phy('u_seri',u_seri,llm)
-     call writefield_phy('v_seri',v_seri,llm)
-     call writefield_phy('t_seri',t_seri,llm)
-     call writefield_phy('q_seri',q_seri,llm)
+     call writefield_phy('u_seri',u_seri,nbp_lev)
+     call writefield_phy('v_seri',v_seri,nbp_lev)
+     call writefield_phy('t_seri',t_seri,nbp_lev)
+     call writefield_phy('q_seri',q_seri,nbp_lev)
   endif
 
@@ -3629,8 +3784,8 @@
   IF (ip_ebil_phy.ge.2) THEN 
      ztit='after rad'
-     CALL diagetpq(airephy,ztit,ip_ebil_phy,2,2,dtime &
+     CALL diagetpq(cell_area,ztit,ip_ebil_phy,2,2,dtime &
           , t_seri,q_seri,ql_seri,qs_seri,u_seri,v_seri,paprs,pplay &
           , d_h_vcol, d_qt, d_qw, d_ql, d_qs, d_ec)
-     call diagphy(airephy,ztit,ip_ebil_phy &
+     call diagphy(cell_area,ztit,ip_ebil_phy &
           , topsw, toplw, solsw, sollw, zero_v &
           , zero_v, zero_v, zero_v, ztsol &
@@ -3705,8 +3860,8 @@
   !
   if (mydebug) then
-     call writefield_phy('u_seri',u_seri,llm)
-     call writefield_phy('v_seri',v_seri,llm)
-     call writefield_phy('t_seri',t_seri,llm)
-     call writefield_phy('q_seri',q_seri,llm)
+     call writefield_phy('u_seri',u_seri,nbp_lev)
+     call writefield_phy('v_seri',v_seri,nbp_lev)
+     call writefield_phy('t_seri',t_seri,nbp_lev)
+     call writefield_phy('q_seri',q_seri,nbp_lev)
   endif
 
@@ -3742,23 +3897,48 @@
              d_t_lif, d_u_lif, d_v_lif)
      ENDIF
-     !   
-     !-----------------------------------------------------------------------------------------
+
      ! ajout des tendances de la portance de l'orographie
-     CALL add_phys_tend(d_u_lif,d_v_lif,d_t_lif,dq0,dql0,dqi0,paprs,'lif',abortphy)
-     !-----------------------------------------------------------------------------------------
-     !
+     CALL add_phys_tend(d_u_lif, d_v_lif, d_t_lif, dq0, dql0, dqi0, paprs, &
+          'lif', abortphy)
   ENDIF ! fin de test sur ok_orolf
-  !  HINES GWD PARAMETRIZATION
 
   IF (ok_hines) then
-
-     CALL hines_gwd(klon,klev,dtime,paprs,pplay, &
-          rlat,t_seri,u_seri,v_seri, &
-          zustrhi,zvstrhi, &
-          d_t_hin, d_u_hin, d_v_hin)
-     !
-     !  ajout des tendances
-     CALL add_phys_tend(d_u_hin,d_v_hin,d_t_hin,dq0,dql0,dqi0,paprs,'hin',abortphy)
-
+     !  HINES GWD PARAMETRIZATION
+     east_gwstress=0.
+     west_gwstress=0.
+     du_gwd_hines=0.
+     dv_gwd_hines=0.
+     CALL hines_gwd(klon, klev, dtime, paprs, pplay, rlat, t_seri, u_seri, &
+          v_seri, zustr_gwd_hines, zvstr_gwd_hines, d_t_hin, du_gwd_hines, &
+          dv_gwd_hines)
+     zustr_gwd_hines=0.
+     zvstr_gwd_hines=0.
+     DO k = 1, klev
+        zustr_gwd_hines(:)=zustr_gwd_hines(:)+ du_gwd_hines(:, k)/dtime &
+             * (paprs(:, k)-paprs(:, k+1))/rg
+        zvstr_gwd_hines(:)=zvstr_gwd_hines(:)+ dv_gwd_hines(:, k)/dtime &
+             * (paprs(:, k)-paprs(:, k+1))/rg
+     ENDDO
+
+     d_t_hin(:, :)=0.
+     CALL add_phys_tend(du_gwd_hines, dv_gwd_hines, d_t_hin, dq0, dql0, dqi0, &
+          paprs, 'hin', abortphy)
+  ENDIF
+
+  IF (.not. ok_hines .and. ok_gwd_rando) then
+     CALL acama_GWD_rando(DTIME, pplay, rlat, t_seri, u_seri, v_seri, rot, &
+          zustr_gwd_front, zvstr_gwd_front, du_gwd_front, dv_gwd_front, &
+          east_gwstress, west_gwstress)
+     zustr_gwd_front=0.
+     zvstr_gwd_front=0.
+     DO k = 1, klev
+        zustr_gwd_front(:)=zustr_gwd_front(:)+ du_gwd_front(:, k)/dtime &
+             * (paprs(:, k)-paprs(:, k+1))/rg
+        zvstr_gwd_front(:)=zvstr_gwd_front(:)+ dv_gwd_front(:, k)/dtime &
+             * (paprs(:, k)-paprs(:, k+1))/rg
+     ENDDO
+
+     CALL add_phys_tend(du_gwd_front, dv_gwd_front, dt0, dq0, dql0, dqi0, &
+          paprs, 'front_gwd_rando', abortphy)
   ENDIF
 
@@ -3766,7 +3946,15 @@
      call FLOTT_GWD_rando(DTIME, pplay, t_seri, u_seri, v_seri, &
           rain_fall + snow_fall, zustr_gwd_rando, zvstr_gwd_rando, &
-          du_gwd_rando, dv_gwd_rando)
-     CALL add_phys_tend(du_gwd_rando, dv_gwd_rando, dt0, dq0, dql0,dqi0,paprs, &
-          'flott_gwd_rando',abortphy)
+          du_gwd_rando, dv_gwd_rando, east_gwstress, west_gwstress)
+     CALL add_phys_tend(du_gwd_rando, dv_gwd_rando, dt0, dq0, dql0, dqi0, &
+          paprs, 'flott_gwd_rando', abortphy)
+     zustr_gwd_rando=0.
+     zvstr_gwd_rando=0.
+     DO k = 1, klev
+        zustr_gwd_rando(:)=zustr_gwd_rando(:)+ du_gwd_rando(:, k)/dtime &
+             * (paprs(:, k)-paprs(:, k+1))/rg
+        zvstr_gwd_rando(:)=zvstr_gwd_rando(:)+ dv_gwd_rando(:, k)/dtime &
+             * (paprs(:, k)-paprs(:, k+1))/rg
+     ENDDO
   end if
 
@@ -3774,8 +3962,8 @@
 
   if (mydebug) then
-     call writefield_phy('u_seri',u_seri,llm)
-     call writefield_phy('v_seri',v_seri,llm)
-     call writefield_phy('t_seri',t_seri,llm)
-     call writefield_phy('q_seri',q_seri,llm)
+     call writefield_phy('u_seri',u_seri,nbp_lev)
+     call writefield_phy('v_seri',v_seri,nbp_lev)
+     call writefield_phy('t_seri',t_seri,nbp_lev)
+     call writefield_phy('q_seri',q_seri,nbp_lev)
   endif
 
@@ -3808,8 +3996,8 @@
   IF (ip_ebil_phy.ge.2) THEN 
      ztit='after orography'
-     CALL diagetpq(airephy,ztit,ip_ebil_phy,2,2,dtime &
+     CALL diagetpq(cell_area,ztit,ip_ebil_phy,2,2,dtime &
           , t_seri,q_seri,ql_seri,qs_seri,u_seri,v_seri,paprs,pplay &
           , d_h_vcol, d_qt, d_qw, d_ql, d_qs, d_ec)
-     call diagphy(airephy,ztit,ip_ebil_phy &
+     call diagphy(cell_area,ztit,ip_ebil_phy &
           , zero_v, zero_v, zero_v, zero_v, zero_v &
           , zero_v, zero_v, zero_v, ztsol &
@@ -3822,5 +4010,6 @@
      CALL METHOX(1,klon,klon,klev,q_seri,d_q_ch4,pplay)
   ! ajout de la tendance d'humidite due au methane
-     CALL add_phys_tend(du0,dv0,dt0,d_q_ch4*dtime,dql0,'q_ch4',abortphy)
+     CALL add_phys_tend(du0, dv0, dt0, d_q_ch4*dtime, dql0, dqi0, paprs, &
+          'q_ch4', abortphy)
   END IF
   !
@@ -3915,5 +4104,5 @@
           cdragh,coefh(1:klon,1:klev,is_ave),u1,v1,ftsol,pctsrf, &
           frac_impa, frac_nucl, &
-          pphis,airephy,dtime,itap, &
+          pphis,cell_area,dtime,itap, &
           qx(:,:,ivap),da,phi,mp,upwd,dnwd)
 
@@ -3946,5 +4135,5 @@
 
   d_t_ec(:,:)=0.
-  forall (k=1: llm) exner(:, k) = (pplay(:, k)/paprs(:,1))**RKAPPA
+  forall (k=1: nbp_lev) exner(:, k) = (pplay(:, k)/paprs(:,1))**RKAPPA
   CALL ener_conserv(klon,klev,pdtphys,u,v,t,qx(:,:,ivap), &
        u_seri,v_seri,t_seri,q_seri,pbl_tke(:,:,is_ave)-tke0(:,:), &
@@ -3955,5 +4144,5 @@
   IF (ip_ebil_phy.ge.1) THEN 
      ztit='after physic'
-     CALL diagetpq(airephy,ztit,ip_ebil_phy,1,1,dtime &
+     CALL diagetpq(cell_area,ztit,ip_ebil_phy,1,1,dtime &
           , t_seri,q_seri,ql_seri,qs_seri,u_seri,v_seri,paprs,pplay &
           , d_h_vcol, d_qt, d_qw, d_ql, d_qs, d_ec)
@@ -3963,5 +4152,5 @@
      !     Donc la somme de ces 2 variations devrait etre nulle.
 
-     call diagphy(airephy,ztit,ip_ebil_phy &
+     call diagphy(cell_area,ztit,ip_ebil_phy &
           , topsw, toplw, solsw, sollw, sens &
           , evap, rain_fall, snow_fall, ztsol &
@@ -3998,6 +4187,6 @@
   include "calcul_STDlev.h"
   !
-  ! slp sea level pressure
-  slp(:) = paprs(:,1)*exp(pphis(:)/(RD*t_seri(:,1)))
+  ! slp sea level pressure derived from Arpege-IFS : CALL ctstar + CALL pppmer
+  CALL diag_slp(klon,t_seri,paprs,pplay,pphis,ptstar,pt0,slp)
   !
   !cc prw = eau precipitable
@@ -4023,5 +4212,5 @@
           paprs, &
           q_seri, &
-          airephy, &
+          cell_area, &
           pphi, &
           pphis, &
@@ -4042,8 +4231,8 @@
   !
   if (mydebug) then
-     call writefield_phy('u_seri',u_seri,llm)
-     call writefield_phy('v_seri',v_seri,llm)
-     call writefield_phy('t_seri',t_seri,llm)
-     call writefield_phy('q_seri',q_seri,llm)
+     call writefield_phy('u_seri',u_seri,nbp_lev)
+     call writefield_phy('v_seri',v_seri,nbp_lev)
+     call writefield_phy('t_seri',t_seri,nbp_lev)
+     call writefield_phy('q_seri',q_seri,nbp_lev)
   endif
 
@@ -4133,9 +4322,16 @@
      enddo
 
-     write(lunout,*) 'd_t_oli,d_t_vdf,d_t_oro,d_t_lif,d_t_ec'
+!jyg<     (En attendant de statuer sur le sort de d_t_oli)
+!jyg!     write(lunout,*) 'd_t_oli,d_t_vdf,d_t_oro,d_t_lif,d_t_ec'
+!jyg!     do k=1,klev
+!jyg!        write(lunout,*) d_t_oli(igout,k),d_t_vdf(igout,k), &
+!jyg!             d_t_oro(igout,k),d_t_lif(igout,k),d_t_ec(igout,k)
+!jyg!     enddo
+     write(lunout,*) 'd_t_vdf,d_t_oro,d_t_lif,d_t_ec'
      do k=1,klev
-        write(lunout,*) d_t_oli(igout,k),d_t_vdf(igout,k), &
+        write(lunout,*) d_t_vdf(igout,k), &
              d_t_oro(igout,k),d_t_lif(igout,k),d_t_ec(igout,k)
      enddo
+!>jyg
 
      write(lunout,*) 'd_ps ',d_ps(igout)
@@ -4238,5 +4434,5 @@
     IF (abortphy==1) THEN
        abort_message ='Plantage hgardfou'
-       CALL abort_gcm (modname,abort_message,1)
+       CALL abort_physic (modname,abort_message,1)
     ENDIF
 
@@ -4248,57 +4444,4 @@
   !====================================================================
   !
-
-  !        -----------------------------------------------------------------
-  !        WSTATS: Saving statistics
-  !        -----------------------------------------------------------------
-  !        ("stats" stores and accumulates 8 key variables in file "stats.nc"
-  !        which can later be used to make the statistic files of the run:
-  !        "stats")          only possible in 3D runs !
-
-
-  IF (callstats) THEN
-
-     call wstats(klon,o_psol%name,"Surface pressure","Pa" &
-          ,2,paprs(:,1))
-     call wstats(klon,o_tsol%name,"Surface temperature","K", &
-          2,zxtsol)
-     zx_tmp_fi2d(:) = rain_fall(:) + snow_fall(:)
-     call wstats(klon,o_precip%name,"Precip Totale liq+sol", &
-          "kg/(s*m2)",2,zx_tmp_fi2d)
-     zx_tmp_fi2d(:) = rain_lsc(:) + snow_lsc(:)
-     call wstats(klon,o_plul%name,"Large-scale Precip", &
-          "kg/(s*m2)",2,zx_tmp_fi2d)
-     zx_tmp_fi2d(:) = rain_con(:) + snow_con(:)
-     call wstats(klon,o_pluc%name,"Convective Precip", &
-          "kg/(s*m2)",2,zx_tmp_fi2d)
-     call wstats(klon,o_sols%name,"Solar rad. at surf.", &
-          "W/m2",2,solsw)
-     call wstats(klon,o_soll%name,"IR rad. at surf.", &
-          "W/m2",2,sollw)
-     zx_tmp_fi2d(:) = topsw(:)-toplw(:)
-     call wstats(klon,o_nettop%name,"Net dn radiatif flux at TOA", &
-          "W/m2",2,zx_tmp_fi2d)
-
-
-
-     call wstats(klon,o_temp%name,"Air temperature","K", &
-          3,t_seri)
-     call wstats(klon,o_vitu%name,"Zonal wind","m.s-1", &
-          3,u_seri)
-     call wstats(klon,o_vitv%name,"Meridional wind", &
-          "m.s-1",3,v_seri)
-     call wstats(klon,o_vitw%name,"Vertical wind", &
-          "m.s-1",3,omega)
-     call wstats(klon,o_ovap%name,"Specific humidity", "kg/kg", &
-          3,q_seri)
-
-
-
-     IF(lafin) THEN
-        write (*,*) "Writing stats..."
-        call mkstats(ierr)
-     ENDIF
-
-  ENDIF !if callstats
 
   IF (lafin) THEN
Index: DZ5/branches/testing/libf/phylmd/phystokenc.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phystokenc.F90	(revision 2407)
+++ 	(revision )
@@ -1,363 +1,0 @@
-SUBROUTINE phystokenc (nlon,nlev,pdtphys,rlon,rlat, &
-     pt,pmfu, pmfd, pen_u, pde_u, pen_d, pde_d, &
-     pfm_therm,pentr_therm, &
-     cdragh, pcoefh,yu1,yv1,ftsol,pctsrf, &
-     frac_impa,frac_nucl, &
-     pphis,paire,dtime,itap, &
-     psh, pda, pphi, pmp, pupwd, pdnwd)
-  
-  USE ioipsl
-  USE dimphy
-  USE infotrac, ONLY : nqtot
-  USE iophy
-  USE control_mod
-  USE indice_sol_mod
-  
-  IMPLICIT NONE
-  
-!======================================================================
-! Auteur(s) FH
-! Objet: Ecriture des variables pour transport offline
-!
-!======================================================================
-  INCLUDE "dimensions.h"
-  INCLUDE "tracstoke.h"
-  INCLUDE "iniprint.h"
-!======================================================================
-
-! Arguments:
-!
-  REAL,DIMENSION(klon,klev), INTENT(IN)     :: psh   ! humidite specifique
-  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pda
-  REAL,DIMENSION(klon,klev,klev), INTENT(IN):: pphi
-  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pmp
-  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pupwd ! saturated updraft mass flux
-  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pdnwd ! saturated downdraft mass flux
-
-!   EN ENTREE:
-!   ==========
-!
-!   divers:
-!   -------
-!
-  INTEGER nlon ! nombre de points horizontaux
-  INTEGER nlev ! nombre de couches verticales
-  REAL pdtphys ! pas d'integration pour la physique (seconde)
-  INTEGER itap
-  INTEGER, SAVE :: physid
-!$OMP THREADPRIVATE(physid)
-
-!   convection:
-!   -----------
-!
-  REAL pmfu(klon,klev)  ! flux de masse dans le panache montant
-  REAL pmfd(klon,klev)  ! flux de masse dans le panache descendant
-  REAL pen_u(klon,klev) ! flux entraine dans le panache montant
-  REAL pde_u(klon,klev) ! flux detraine dans le panache montant
-  REAL pen_d(klon,klev) ! flux entraine dans le panache descendant
-  REAL pde_d(klon,klev) ! flux detraine dans le panache descendant
-  REAL pt(klon,klev)
-  REAL,ALLOCATABLE,SAVE :: t(:,:)
-!$OMP THREADPRIVATE(t)
-!
-  REAL rlon(klon), rlat(klon), dtime
-  REAL zx_tmp_3d(iim,jjm+1,klev),zx_tmp_2d(iim,jjm+1)
-
-!   Couche limite:
-!   --------------
-!
-  REAL cdragh(klon)          ! cdrag
-  REAL pcoefh(klon,klev)     ! coeff melange CL
-  REAL pcoefh_buf(klon,klev) ! coeff melange CL + cdrag
-  REAL yv1(klon)
-  REAL yu1(klon),pphis(klon),paire(klon)
-
-!   Les Thermiques : (Abderr 25 11 02)
-!   ---------------
-  REAL, INTENT(IN) ::  pfm_therm(klon,klev+1)
-  REAL pentr_therm(klon,klev)
-  
-  REAL,ALLOCATABLE,SAVE :: entr_therm(:,:)
-  REAL,ALLOCATABLE,SAVE :: fm_therm(:,:)
-!$OMP THREADPRIVATE(entr_therm)
-!$OMP THREADPRIVATE(fm_therm)
-!
-!   Lessivage:
-!   ----------
-!
-  REAL frac_impa(klon,klev)
-  REAL frac_nucl(klon,klev)
-!
-! Arguments necessaires pour les sources et puits de traceur
-!
-  REAL ftsol(klon,nbsrf)  ! Temperature du sol (surf)(Kelvin)
-  REAL pctsrf(klon,nbsrf) ! Pourcentage de sol f(nature du sol)
-!======================================================================
-!
-  INTEGER i, k, kk
-  REAL,ALLOCATABLE,SAVE :: mfu(:,:)  ! flux de masse dans le panache montant
-  REAL,ALLOCATABLE,SAVE :: mfd(:,:)  ! flux de masse dans le panache descendant
-  REAL,ALLOCATABLE,SAVE :: en_u(:,:) ! flux entraine dans le panache montant
-  REAL,ALLOCATABLE,SAVE :: de_u(:,:) ! flux detraine dans le panache montant
-  REAL,ALLOCATABLE,SAVE :: en_d(:,:) ! flux entraine dans le panache descendant
-  REAL,ALLOCATABLE,SAVE :: de_d(:,:) ! flux detraine dans le panache descendant
-  REAL,ALLOCATABLE,SAVE :: coefh(:,:) ! flux detraine dans le panache descendant
-  
-  REAL,ALLOCATABLE,SAVE :: pyu1(:)
-  REAL,ALLOCATABLE,SAVE :: pyv1(:)
-  REAL,ALLOCATABLE,SAVE :: pftsol(:,:)
-  REAL,ALLOCATABLE,SAVE :: ppsrf(:,:)
-!$OMP THREADPRIVATE(mfu,mfd,en_u,de_u,en_d,de_d,coefh)
-!$OMP THREADPRIVATE(pyu1,pyv1,pftsol,ppsrf)
-
-
-  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: sh  
-  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: da
-  REAL,DIMENSION(:,:,:), ALLOCATABLE,SAVE   :: phi
-  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: mp
-  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: upwd
-  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: dnwd
-  
-  REAL, SAVE :: dtcum
-  INTEGER, SAVE:: iadvtr=0
-!$OMP THREADPRIVATE(dtcum,iadvtr)
-  REAL zmin,zmax
-  LOGICAL ok_sync
-  CHARACTER(len=12) :: nvar
-  logical, parameter :: lstokenc=.FALSE.
-!
-!======================================================================
-
-  iadvtr=iadvtr+1
-
-! Dans le meme vecteur on recombine le drag et les coeff d'echange
-  pcoefh_buf(:,1)      = cdragh(:)
-  pcoefh_buf(:,2:klev) = pcoefh(:,2:klev)
-  
-  ok_sync = .TRUE.
-
-! Initialization done only once
-!======================================================================
-  IF (iadvtr==1) THEN
-     ALLOCATE( t(klon,klev))
-     ALLOCATE( mfu(klon,klev))  
-     ALLOCATE( mfd(klon,klev))  
-     ALLOCATE( en_u(klon,klev)) 
-     ALLOCATE( de_u(klon,klev)) 
-     ALLOCATE( en_d(klon,klev)) 
-     ALLOCATE( de_d(klon,klev)) 
-     ALLOCATE( coefh(klon,klev)) 
-     ALLOCATE( entr_therm(klon,klev))
-     ALLOCATE( fm_therm(klon,klev))
-     ALLOCATE( pyu1(klon))
-     ALLOCATE( pyv1(klon))
-     ALLOCATE( pftsol(klon,nbsrf))
-     ALLOCATE( ppsrf(klon,nbsrf))
-     
-     ALLOCATE(sh(klon,klev)) 
-     ALLOCATE(da(klon,klev)) 
-     ALLOCATE(phi(klon,klev,klev)) 
-     ALLOCATE(mp(klon,klev)) 
-     ALLOCATE(upwd(klon,klev)) 
-     ALLOCATE(dnwd(klon,klev)) 
-
-     CALL initphysto('phystoke', dtime, dtime*istphy,dtime*istphy,physid)
-     
-     ! Write field phis and aire only once
-     CALL histwrite_phy(physid,lstokenc,"phis",itap,pphis)
-     CALL histwrite_phy(physid,lstokenc,"aire",itap,paire)
-     CALL histwrite_phy(physid,lstokenc,"longitudes",itap,rlon)
-     CALL histwrite_phy(physid,lstokenc,"latitudes",itap,rlat)
-
-  END IF
-  
-  
-! Set to zero cumulating fields
-!======================================================================
-  IF (MOD(iadvtr,istphy)==1.OR.istphy==1) THEN
-     WRITE(lunout,*)'reinitialisation des champs cumules a iadvtr=',iadvtr
-     mfu(:,:)=0.
-     mfd(:,:)=0.
-     en_u(:,:)=0.
-     de_u(:,:)=0.
-     en_d(:,:)=0.
-     de_d(:,:)=0.
-     coefh(:,:)=0.
-     t(:,:)=0.
-     fm_therm(:,:)=0.
-     entr_therm(:,:)=0.
-     pyv1(:)=0.
-     pyu1(:)=0.
-     pftsol(:,:)=0.
-     ppsrf(:,:)=0.
-     sh(:,:)=0.
-     da(:,:)=0.
-     phi(:,:,:)=0.
-     mp(:,:)=0.
-     upwd(:,:)=0.
-     dnwd(:,:)=0.
-     dtcum=0.
-  ENDIF
-  
-
-! Cumulate fields at each time step
-!======================================================================
-  DO k=1,klev
-     DO i=1,klon
-        mfu(i,k)=mfu(i,k)+pmfu(i,k)*pdtphys
-        mfd(i,k)=mfd(i,k)+pmfd(i,k)*pdtphys
-        en_u(i,k)=en_u(i,k)+pen_u(i,k)*pdtphys
-        de_u(i,k)=de_u(i,k)+pde_u(i,k)*pdtphys
-        en_d(i,k)=en_d(i,k)+pen_d(i,k)*pdtphys
-        de_d(i,k)=de_d(i,k)+pde_d(i,k)*pdtphys
-        coefh(i,k)=coefh(i,k)+pcoefh_buf(i,k)*pdtphys
-        t(i,k)=t(i,k)+pt(i,k)*pdtphys
-        fm_therm(i,k)=fm_therm(i,k)+pfm_therm(i,k)*pdtphys
-        entr_therm(i,k)=entr_therm(i,k)+pentr_therm(i,k)*pdtphys
-        sh(i,k) = sh(i,k) + psh(i,k)*pdtphys
-        da(i,k) = da(i,k) + pda(i,k)*pdtphys
-        mp(i,k) = mp(i,k) + pmp(i,k)*pdtphys
-        upwd(i,k) = upwd(i,k) + pupwd(i,k)*pdtphys
-        dnwd(i,k) = dnwd(i,k) + pdnwd(i,k)*pdtphys
-     ENDDO
-  ENDDO
-
-  DO kk=1,klev
-     DO k=1,klev
-        DO i=1,klon
-           phi(i,k,kk) = phi(i,k,kk) + pphi(i,k,kk)*pdtphys
-        END DO
-     END DO
-  END DO
-
-  DO i=1,klon
-     pyv1(i)=pyv1(i)+yv1(i)*pdtphys
-     pyu1(i)=pyu1(i)+yu1(i)*pdtphys
-  END DO
-  DO k=1,nbsrf
-     DO i=1,klon
-        pftsol(i,k)=pftsol(i,k)+ftsol(i,k)*pdtphys
-        ppsrf(i,k)=ppsrf(i,k)+pctsrf(i,k)*pdtphys
-     ENDDO
-  ENDDO
-  
-! Add time step to cumulated time
-  dtcum=dtcum+pdtphys
-  
-
-! Write fields to file, if it is time to do so
-!======================================================================
-  IF(MOD(iadvtr,istphy)==0) THEN 
-
-     ! normalize with time period
-     DO k=1,klev
-        DO i=1,klon
-           mfu(i,k)=mfu(i,k)/dtcum
-           mfd(i,k)=mfd(i,k)/dtcum
-           en_u(i,k)=en_u(i,k)/dtcum
-           de_u(i,k)=de_u(i,k)/dtcum
-           en_d(i,k)=en_d(i,k)/dtcum
-           de_d(i,k)=de_d(i,k)/dtcum
-           coefh(i,k)=coefh(i,k)/dtcum
-           t(i,k)=t(i,k)/dtcum	
-           fm_therm(i,k)=fm_therm(i,k)/dtcum
-           entr_therm(i,k)=entr_therm(i,k)/dtcum
-           sh(i,k)=sh(i,k)/dtcum
-           da(i,k)=da(i,k)/dtcum
-           mp(i,k)=mp(i,k)/dtcum
-           upwd(i,k)=upwd(i,k)/dtcum
-           dnwd(i,k)=dnwd(i,k)/dtcum
-        ENDDO
-     ENDDO
-     DO kk=1,klev
-        DO k=1,klev
-           DO i=1,klon
-              phi(i,k,kk) = phi(i,k,kk)/dtcum
-           END DO
-        END DO
-     END DO
-     DO i=1,klon
-        pyv1(i)=pyv1(i)/dtcum
-        pyu1(i)=pyu1(i)/dtcum
-     END DO
-     DO k=1,nbsrf
-        DO i=1,klon
-           pftsol(i,k)=pftsol(i,k)/dtcum
-           ppsrf(i,k)=ppsrf(i,k)/dtcum
-        ENDDO
-     ENDDO
-
-     ! write fields
-     CALL histwrite_phy(physid,lstokenc,"t",itap,t)
-     CALL histwrite_phy(physid,lstokenc,"mfu",itap,mfu)
-     CALL histwrite_phy(physid,lstokenc,"mfd",itap,mfd)
-     CALL histwrite_phy(physid,lstokenc,"en_u",itap,en_u)
-     CALL histwrite_phy(physid,lstokenc,"de_u",itap,de_u)
-     CALL histwrite_phy(physid,lstokenc,"en_d",itap,en_d)
-     CALL histwrite_phy(physid,lstokenc,"de_d",itap,de_d)
-     CALL histwrite_phy(physid,lstokenc,"coefh",itap,coefh)	
-     CALL histwrite_phy(physid,lstokenc,"fm_th",itap,fm_therm)
-     CALL histwrite_phy(physid,lstokenc,"en_th",itap,entr_therm)
-     CALL histwrite_phy(physid,lstokenc,"frac_impa",itap,frac_impa)
-     CALL histwrite_phy(physid,lstokenc,"frac_nucl",itap,frac_nucl)
-     CALL histwrite_phy(physid,lstokenc,"pyu1",itap,pyu1)
-     CALL histwrite_phy(physid,lstokenc,"pyv1",itap,pyv1)
-     CALL histwrite_phy(physid,lstokenc,"ftsol1",itap,pftsol(:,1))
-     CALL histwrite_phy(physid,lstokenc,"ftsol2",itap,pftsol(:,2))
-     CALL histwrite_phy(physid,lstokenc,"ftsol3",itap,pftsol(:,3))
-     CALL histwrite_phy(physid,lstokenc,"ftsol4",itap,pftsol(:,4))
-     CALL histwrite_phy(physid,lstokenc,"psrf1",itap,ppsrf(:,1))
-     CALL histwrite_phy(physid,lstokenc,"psrf2",itap,ppsrf(:,2))
-     CALL histwrite_phy(physid,lstokenc,"psrf3",itap,ppsrf(:,3))
-     CALL histwrite_phy(physid,lstokenc,"psrf4",itap,ppsrf(:,4))
-     CALL histwrite_phy(physid,lstokenc,"sh",itap,sh)
-     CALL histwrite_phy(physid,lstokenc,"da",itap,da)
-     CALL histwrite_phy(physid,lstokenc,"mp",itap,mp)
-     CALL histwrite_phy(physid,lstokenc,"upwd",itap,upwd)
-     CALL histwrite_phy(physid,lstokenc,"dnwd",itap,dnwd)
-
-
-! phi
-     DO k=1,klev
-        IF (k<10) THEN
-           WRITE(nvar,'(i1)') k
-        ELSE IF (k<100) THEN
-           WRITE(nvar,'(i2)') k
-        ELSE
-           WRITE(nvar,'(i3)') k
-        END IF
-        nvar='phi_lev'//trim(nvar)
-        
-        CALL histwrite_phy(physid,lstokenc,nvar,itap,phi(:,:,k))
-     END DO
-     
-     ! Syncronize file
-!$OMP MASTER
-     IF (ok_sync) CALL histsync(physid)
-!$OMP END MASTER
-     
-     
-     ! Calculate min and max values for some fields (coefficients de lessivage)
-     zmin=1e33
-     zmax=-1e33
-     DO k=1,klev
-        DO i=1,klon
-           zmax=MAX(zmax,frac_nucl(i,k))
-           zmin=MIN(zmin,frac_nucl(i,k))
-        ENDDO
-     ENDDO
-     WRITE(lunout,*)'------ coefs de lessivage (min et max) --------'
-     WRITE(lunout,*)'facteur de nucleation ',zmin,zmax
-     zmin=1e33
-     zmax=-1e33
-     DO k=1,klev
-        DO i=1,klon
-           zmax=MAX(zmax,frac_impa(i,k))
-           zmin=MIN(zmin,frac_impa(i,k))
-        ENDDO
-     ENDDO
-     WRITE(lunout,*)'facteur d impaction ',zmin,zmax
-     
-  ENDIF ! IF(MOD(iadvtr,istphy)==0)
-
-END SUBROUTINE phystokenc
Index: /LMDZ5/branches/testing/libf/phylmd/phystokenc_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phystokenc_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/phystokenc_mod.F90	(revision 2408)
@@ -0,0 +1,387 @@
+!
+! $Id$
+!
+MODULE phystokenc_mod
+
+  IMPLICIT NONE
+
+  LOGICAL,SAVE :: offline
+!$OMP THREADPRIVATE(offline)
+  INTEGER,SAVE :: istphy
+!$OMP THREADPRIVATE(istphy)
+
+
+CONTAINS
+
+  SUBROUTINE init_phystokenc(offline_dyn,istphy_dyn)
+    IMPLICIT NONE
+    LOGICAL,INTENT(IN) :: offline_dyn
+    INTEGER,INTENT(IN) :: istphy_dyn
+
+    offline=offline_dyn
+    istphy=istphy_dyn
+
+  END SUBROUTINE init_phystokenc
+
+SUBROUTINE phystokenc (nlon,nlev,pdtphys,rlon,rlat, &
+     pt,pmfu, pmfd, pen_u, pde_u, pen_d, pde_d, &
+     pfm_therm,pentr_therm, &
+     cdragh, pcoefh,yu1,yv1,ftsol,pctsrf, &
+     frac_impa,frac_nucl, &
+     pphis,paire,dtime,itap, &
+     psh, pda, pphi, pmp, pupwd, pdnwd)
+  
+  USE ioipsl
+  USE dimphy
+  USE infotrac_phy, ONLY : nqtot
+  USE iophy
+  USE indice_sol_mod
+  USE print_control_mod, ONLY: lunout
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
+  
+  IMPLICIT NONE
+  
+!======================================================================
+! Auteur(s) FH
+! Objet: Ecriture des variables pour transport offline
+!
+!======================================================================
+
+! Arguments:
+!
+  REAL,DIMENSION(klon,klev), INTENT(IN)     :: psh   ! humidite specifique
+  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pda
+  REAL,DIMENSION(klon,klev,klev), INTENT(IN):: pphi
+  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pmp
+  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pupwd ! saturated updraft mass flux
+  REAL,DIMENSION(klon,klev), INTENT(IN)     :: pdnwd ! saturated downdraft mass flux
+
+!   EN ENTREE:
+!   ==========
+!
+!   divers:
+!   -------
+!
+  INTEGER nlon ! nombre de points horizontaux
+  INTEGER nlev ! nombre de couches verticales
+  REAL pdtphys ! pas d'integration pour la physique (seconde)
+  INTEGER itap
+  INTEGER, SAVE :: physid
+!$OMP THREADPRIVATE(physid)
+
+!   convection:
+!   -----------
+!
+  REAL pmfu(klon,klev)  ! flux de masse dans le panache montant
+  REAL pmfd(klon,klev)  ! flux de masse dans le panache descendant
+  REAL pen_u(klon,klev) ! flux entraine dans le panache montant
+  REAL pde_u(klon,klev) ! flux detraine dans le panache montant
+  REAL pen_d(klon,klev) ! flux entraine dans le panache descendant
+  REAL pde_d(klon,klev) ! flux detraine dans le panache descendant
+  REAL pt(klon,klev)
+  REAL,ALLOCATABLE,SAVE :: t(:,:)
+!$OMP THREADPRIVATE(t)
+!
+  REAL rlon(klon), rlat(klon), dtime
+  REAL zx_tmp_3d(nbp_lon,nbp_lat,klev),zx_tmp_2d(nbp_lon,nbp_lat)
+
+!   Couche limite:
+!   --------------
+!
+  REAL cdragh(klon)          ! cdrag
+  REAL pcoefh(klon,klev)     ! coeff melange CL
+  REAL pcoefh_buf(klon,klev) ! coeff melange CL + cdrag
+  REAL yv1(klon)
+  REAL yu1(klon),pphis(klon),paire(klon)
+
+!   Les Thermiques : (Abderr 25 11 02)
+!   ---------------
+  REAL, INTENT(IN) ::  pfm_therm(klon,klev+1)
+  REAL pentr_therm(klon,klev)
+  
+  REAL,ALLOCATABLE,SAVE :: entr_therm(:,:)
+  REAL,ALLOCATABLE,SAVE :: fm_therm(:,:)
+!$OMP THREADPRIVATE(entr_therm)
+!$OMP THREADPRIVATE(fm_therm)
+!
+!   Lessivage:
+!   ----------
+!
+  REAL frac_impa(klon,klev)
+  REAL frac_nucl(klon,klev)
+!
+! Arguments necessaires pour les sources et puits de traceur
+!
+  REAL ftsol(klon,nbsrf)  ! Temperature du sol (surf)(Kelvin)
+  REAL pctsrf(klon,nbsrf) ! Pourcentage de sol f(nature du sol)
+!======================================================================
+!
+  INTEGER i, k, kk
+  REAL,ALLOCATABLE,SAVE :: mfu(:,:)  ! flux de masse dans le panache montant
+  REAL,ALLOCATABLE,SAVE :: mfd(:,:)  ! flux de masse dans le panache descendant
+  REAL,ALLOCATABLE,SAVE :: en_u(:,:) ! flux entraine dans le panache montant
+  REAL,ALLOCATABLE,SAVE :: de_u(:,:) ! flux detraine dans le panache montant
+  REAL,ALLOCATABLE,SAVE :: en_d(:,:) ! flux entraine dans le panache descendant
+  REAL,ALLOCATABLE,SAVE :: de_d(:,:) ! flux detraine dans le panache descendant
+  REAL,ALLOCATABLE,SAVE :: coefh(:,:) ! flux detraine dans le panache descendant
+  
+  REAL,ALLOCATABLE,SAVE :: pyu1(:)
+  REAL,ALLOCATABLE,SAVE :: pyv1(:)
+  REAL,ALLOCATABLE,SAVE :: pftsol(:,:)
+  REAL,ALLOCATABLE,SAVE :: ppsrf(:,:)
+!$OMP THREADPRIVATE(mfu,mfd,en_u,de_u,en_d,de_d,coefh)
+!$OMP THREADPRIVATE(pyu1,pyv1,pftsol,ppsrf)
+
+
+  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: sh  
+  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: da
+  REAL,DIMENSION(:,:,:), ALLOCATABLE,SAVE   :: phi
+  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: mp
+  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: upwd
+  REAL,DIMENSION(:,:), ALLOCATABLE,SAVE     :: dnwd
+  
+  REAL, SAVE :: dtcum
+  INTEGER, SAVE:: iadvtr=0
+!$OMP THREADPRIVATE(dtcum,iadvtr)
+  REAL zmin,zmax
+  LOGICAL ok_sync
+  CHARACTER(len=12) :: nvar
+  logical, parameter :: lstokenc=.FALSE.
+!
+!======================================================================
+
+  iadvtr=iadvtr+1
+
+! Dans le meme vecteur on recombine le drag et les coeff d'echange
+  pcoefh_buf(:,1)      = cdragh(:)
+  pcoefh_buf(:,2:klev) = pcoefh(:,2:klev)
+  
+  ok_sync = .TRUE.
+
+! Initialization done only once
+!======================================================================
+  IF (iadvtr==1) THEN
+     ALLOCATE( t(klon,klev))
+     ALLOCATE( mfu(klon,klev))  
+     ALLOCATE( mfd(klon,klev))  
+     ALLOCATE( en_u(klon,klev)) 
+     ALLOCATE( de_u(klon,klev)) 
+     ALLOCATE( en_d(klon,klev)) 
+     ALLOCATE( de_d(klon,klev)) 
+     ALLOCATE( coefh(klon,klev)) 
+     ALLOCATE( entr_therm(klon,klev))
+     ALLOCATE( fm_therm(klon,klev))
+     ALLOCATE( pyu1(klon))
+     ALLOCATE( pyv1(klon))
+     ALLOCATE( pftsol(klon,nbsrf))
+     ALLOCATE( ppsrf(klon,nbsrf))
+     
+     ALLOCATE(sh(klon,klev)) 
+     ALLOCATE(da(klon,klev)) 
+     ALLOCATE(phi(klon,klev,klev)) 
+     ALLOCATE(mp(klon,klev)) 
+     ALLOCATE(upwd(klon,klev)) 
+     ALLOCATE(dnwd(klon,klev)) 
+
+     CALL initphysto('phystoke', dtime, dtime*istphy,dtime*istphy,physid)
+     
+     ! Write field phis and aire only once
+     CALL histwrite_phy(physid,lstokenc,"phis",itap,pphis)
+     CALL histwrite_phy(physid,lstokenc,"aire",itap,paire)
+     CALL histwrite_phy(physid,lstokenc,"longitudes",itap,rlon)
+     CALL histwrite_phy(physid,lstokenc,"latitudes",itap,rlat)
+
+  END IF
+  
+  
+! Set to zero cumulating fields
+!======================================================================
+  IF (MOD(iadvtr,istphy)==1.OR.istphy==1) THEN
+     WRITE(lunout,*)'reinitialisation des champs cumules a iadvtr=',iadvtr
+     mfu(:,:)=0.
+     mfd(:,:)=0.
+     en_u(:,:)=0.
+     de_u(:,:)=0.
+     en_d(:,:)=0.
+     de_d(:,:)=0.
+     coefh(:,:)=0.
+     t(:,:)=0.
+     fm_therm(:,:)=0.
+     entr_therm(:,:)=0.
+     pyv1(:)=0.
+     pyu1(:)=0.
+     pftsol(:,:)=0.
+     ppsrf(:,:)=0.
+     sh(:,:)=0.
+     da(:,:)=0.
+     phi(:,:,:)=0.
+     mp(:,:)=0.
+     upwd(:,:)=0.
+     dnwd(:,:)=0.
+     dtcum=0.
+  ENDIF
+  
+
+! Cumulate fields at each time step
+!======================================================================
+  DO k=1,klev
+     DO i=1,klon
+        mfu(i,k)=mfu(i,k)+pmfu(i,k)*pdtphys
+        mfd(i,k)=mfd(i,k)+pmfd(i,k)*pdtphys
+        en_u(i,k)=en_u(i,k)+pen_u(i,k)*pdtphys
+        de_u(i,k)=de_u(i,k)+pde_u(i,k)*pdtphys
+        en_d(i,k)=en_d(i,k)+pen_d(i,k)*pdtphys
+        de_d(i,k)=de_d(i,k)+pde_d(i,k)*pdtphys
+        coefh(i,k)=coefh(i,k)+pcoefh_buf(i,k)*pdtphys
+        t(i,k)=t(i,k)+pt(i,k)*pdtphys
+        fm_therm(i,k)=fm_therm(i,k)+pfm_therm(i,k)*pdtphys
+        entr_therm(i,k)=entr_therm(i,k)+pentr_therm(i,k)*pdtphys
+        sh(i,k) = sh(i,k) + psh(i,k)*pdtphys
+        da(i,k) = da(i,k) + pda(i,k)*pdtphys
+        mp(i,k) = mp(i,k) + pmp(i,k)*pdtphys
+        upwd(i,k) = upwd(i,k) + pupwd(i,k)*pdtphys
+        dnwd(i,k) = dnwd(i,k) + pdnwd(i,k)*pdtphys
+     ENDDO
+  ENDDO
+
+  DO kk=1,klev
+     DO k=1,klev
+        DO i=1,klon
+           phi(i,k,kk) = phi(i,k,kk) + pphi(i,k,kk)*pdtphys
+        END DO
+     END DO
+  END DO
+
+  DO i=1,klon
+     pyv1(i)=pyv1(i)+yv1(i)*pdtphys
+     pyu1(i)=pyu1(i)+yu1(i)*pdtphys
+  END DO
+  DO k=1,nbsrf
+     DO i=1,klon
+        pftsol(i,k)=pftsol(i,k)+ftsol(i,k)*pdtphys
+        ppsrf(i,k)=ppsrf(i,k)+pctsrf(i,k)*pdtphys
+     ENDDO
+  ENDDO
+  
+! Add time step to cumulated time
+  dtcum=dtcum+pdtphys
+  
+
+! Write fields to file, if it is time to do so
+!======================================================================
+  IF(MOD(iadvtr,istphy)==0) THEN 
+
+     ! normalize with time period
+     DO k=1,klev
+        DO i=1,klon
+           mfu(i,k)=mfu(i,k)/dtcum
+           mfd(i,k)=mfd(i,k)/dtcum
+           en_u(i,k)=en_u(i,k)/dtcum
+           de_u(i,k)=de_u(i,k)/dtcum
+           en_d(i,k)=en_d(i,k)/dtcum
+           de_d(i,k)=de_d(i,k)/dtcum
+           coefh(i,k)=coefh(i,k)/dtcum
+           t(i,k)=t(i,k)/dtcum	
+           fm_therm(i,k)=fm_therm(i,k)/dtcum
+           entr_therm(i,k)=entr_therm(i,k)/dtcum
+           sh(i,k)=sh(i,k)/dtcum
+           da(i,k)=da(i,k)/dtcum
+           mp(i,k)=mp(i,k)/dtcum
+           upwd(i,k)=upwd(i,k)/dtcum
+           dnwd(i,k)=dnwd(i,k)/dtcum
+        ENDDO
+     ENDDO
+     DO kk=1,klev
+        DO k=1,klev
+           DO i=1,klon
+              phi(i,k,kk) = phi(i,k,kk)/dtcum
+           END DO
+        END DO
+     END DO
+     DO i=1,klon
+        pyv1(i)=pyv1(i)/dtcum
+        pyu1(i)=pyu1(i)/dtcum
+     END DO
+     DO k=1,nbsrf
+        DO i=1,klon
+           pftsol(i,k)=pftsol(i,k)/dtcum
+           ppsrf(i,k)=ppsrf(i,k)/dtcum
+        ENDDO
+     ENDDO
+
+     ! write fields
+     CALL histwrite_phy(physid,lstokenc,"t",itap,t)
+     CALL histwrite_phy(physid,lstokenc,"mfu",itap,mfu)
+     CALL histwrite_phy(physid,lstokenc,"mfd",itap,mfd)
+     CALL histwrite_phy(physid,lstokenc,"en_u",itap,en_u)
+     CALL histwrite_phy(physid,lstokenc,"de_u",itap,de_u)
+     CALL histwrite_phy(physid,lstokenc,"en_d",itap,en_d)
+     CALL histwrite_phy(physid,lstokenc,"de_d",itap,de_d)
+     CALL histwrite_phy(physid,lstokenc,"coefh",itap,coefh)	
+     CALL histwrite_phy(physid,lstokenc,"fm_th",itap,fm_therm)
+     CALL histwrite_phy(physid,lstokenc,"en_th",itap,entr_therm)
+     CALL histwrite_phy(physid,lstokenc,"frac_impa",itap,frac_impa)
+     CALL histwrite_phy(physid,lstokenc,"frac_nucl",itap,frac_nucl)
+     CALL histwrite_phy(physid,lstokenc,"pyu1",itap,pyu1)
+     CALL histwrite_phy(physid,lstokenc,"pyv1",itap,pyv1)
+     CALL histwrite_phy(physid,lstokenc,"ftsol1",itap,pftsol(:,1))
+     CALL histwrite_phy(physid,lstokenc,"ftsol2",itap,pftsol(:,2))
+     CALL histwrite_phy(physid,lstokenc,"ftsol3",itap,pftsol(:,3))
+     CALL histwrite_phy(physid,lstokenc,"ftsol4",itap,pftsol(:,4))
+     CALL histwrite_phy(physid,lstokenc,"psrf1",itap,ppsrf(:,1))
+     CALL histwrite_phy(physid,lstokenc,"psrf2",itap,ppsrf(:,2))
+     CALL histwrite_phy(physid,lstokenc,"psrf3",itap,ppsrf(:,3))
+     CALL histwrite_phy(physid,lstokenc,"psrf4",itap,ppsrf(:,4))
+     CALL histwrite_phy(physid,lstokenc,"sh",itap,sh)
+     CALL histwrite_phy(physid,lstokenc,"da",itap,da)
+     CALL histwrite_phy(physid,lstokenc,"mp",itap,mp)
+     CALL histwrite_phy(physid,lstokenc,"upwd",itap,upwd)
+     CALL histwrite_phy(physid,lstokenc,"dnwd",itap,dnwd)
+
+
+! phi
+     DO k=1,klev
+        IF (k<10) THEN
+           WRITE(nvar,'(i1)') k
+        ELSE IF (k<100) THEN
+           WRITE(nvar,'(i2)') k
+        ELSE
+           WRITE(nvar,'(i3)') k
+        END IF
+        nvar='phi_lev'//trim(nvar)
+        
+        CALL histwrite_phy(physid,lstokenc,nvar,itap,phi(:,:,k))
+     END DO
+     
+     ! Syncronize file
+!$OMP MASTER
+     IF (ok_sync) CALL histsync(physid)
+!$OMP END MASTER
+     
+     
+     ! Calculate min and max values for some fields (coefficients de lessivage)
+     zmin=1e33
+     zmax=-1e33
+     DO k=1,klev
+        DO i=1,klon
+           zmax=MAX(zmax,frac_nucl(i,k))
+           zmin=MIN(zmin,frac_nucl(i,k))
+        ENDDO
+     ENDDO
+     WRITE(lunout,*)'------ coefs de lessivage (min et max) --------'
+     WRITE(lunout,*)'facteur de nucleation ',zmin,zmax
+     zmin=1e33
+     zmax=-1e33
+     DO k=1,klev
+        DO i=1,klon
+           zmax=MAX(zmax,frac_impa(i,k))
+           zmin=MIN(zmin,frac_impa(i,k))
+        ENDDO
+     ENDDO
+     WRITE(lunout,*)'facteur d impaction ',zmin,zmax
+     
+  ENDIF ! IF(MOD(iadvtr,istphy)==0)
+
+END SUBROUTINE phystokenc
+
+END MODULE phystokenc_mod
Index: /LMDZ5/branches/testing/libf/phylmd/phytrac_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/phytrac_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/phytrac_mod.F90	(revision 2408)
@@ -89,26 +89,22 @@
     USE phys_cal_mod, only : hour
     USE dimphy
-    USE infotrac
+    USE infotrac_phy, ONLY: nbtr, type_trac, conv_flg, solsym, pbl_flg
     USE mod_grid_phy_lmdz
     USE mod_phys_lmdz_para
-    USE comgeomphy
     USE iophy
     USE traclmdz_mod
     USE tracinca_mod
     USE tracreprobus_mod
-    USE control_mod
     USE indice_sol_mod
 
     USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    USE print_control_mod, ONLY: lunout
+    USE aero_mod, ONLY : naero_grp
 
     IMPLICIT NONE
 
     INCLUDE "YOMCST.h"
-    INCLUDE "dimensions.h"
     INCLUDE "clesphys.h"
-    INCLUDE "temps.h"
-    INCLUDE "paramet.h"
     INCLUDE "thermcell.h"
-    INCLUDE "iniprint.h"
     !==========================================================================
     !                   -- ARGUMENT DESCRIPTION --
@@ -173,8 +169,8 @@
     LOGICAL,INTENT(IN)                       :: aerosol_couple
     REAL,DIMENSION(klon,klev),INTENT(IN)     :: flxmass_w
-    REAL,DIMENSION(klon,klev,9,2),INTENT(IN) :: tau_aero
-    REAL,DIMENSION(klon,klev,9,2),INTENT(IN) :: piz_aero
-    REAL,DIMENSION(klon,klev,9,2),INTENT(IN) :: cg_aero
-    CHARACTER(len=4),DIMENSION(9),INTENT(IN) :: rfname 
+    REAL,DIMENSION(klon,klev,naero_grp,2),INTENT(IN) :: tau_aero
+    REAL,DIMENSION(klon,klev,naero_grp,2),INTENT(IN) :: piz_aero
+    REAL,DIMENSION(klon,klev,naero_grp,2),INTENT(IN) :: cg_aero
+    CHARACTER(len=4),DIMENSION(naero_grp),INTENT(IN) :: rfname 
     REAL,DIMENSION(klon,klev,2),INTENT(IN)   :: ccm 
     !... K.Emanuel
@@ -445,8 +441,8 @@
        WRITE(*,*) 'FIRST TIME IN PHYTRAC : pdtphys(sec) = ',pdtphys,'ecrit_tra (sec) = ',ecrit_tra
        ALLOCATE( source(klon,nbtr), stat=ierr)
-       IF (ierr /= 0) CALL abort_gcm('phytrac', 'pb in allocation 1',1)
+       IF (ierr /= 0) CALL abort_physic('phytrac', 'pb in allocation 1',1)
 
        ALLOCATE( aerosol(nbtr), stat=ierr)
-       IF (ierr /= 0) CALL abort_gcm('phytrac', 'pb in allocation 2',1)
+       IF (ierr /= 0) CALL abort_physic('phytrac', 'pb in allocation 2',1)
 
 
@@ -503,5 +499,5 @@
 !                ELSE 
 !                   WRITE(lunout,*) 'pb it=', it
-!                   CALL abort_gcm('phytrac','pb it scavenging',1)
+!                   CALL abort_physic('phytrac','pb it scavenging',1)
 !                ENDIF
                 !--test OB 
@@ -539,5 +535,5 @@
 
        IF (lessivage.AND.config_inca.EQ.'inca') THEN
-          CALL abort_gcm('phytrac', 'lessivage=T config_inca=inca impossible',1)
+          CALL abort_physic('phytrac', 'lessivage=T config_inca=inca impossible',1)
           STOP
        ENDIF
@@ -740,5 +736,5 @@
     ELSE
        !
-       CALL abort_gcm('iflag_vdf_trac', 'cas non prevu',1)
+       CALL abort_physic('iflag_vdf_trac', 'cas non prevu',1)
        !
     END IF ! couche limite
Index: /LMDZ5/branches/testing/libf/phylmd/plevel.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/plevel.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/plevel.F90	(revision 2408)
@@ -16,7 +16,4 @@
 #endif
   IMPLICIT NONE
-
-  ! ym#include "dimensions.h"
-  ! y#include "dimphy.h"
 
   ! ================================================================
Index: /LMDZ5/branches/testing/libf/phylmd/plevel_new.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/plevel_new.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/plevel_new.F90	(revision 2408)
@@ -18,7 +18,4 @@
 
   IMPLICIT NONE
-
-  ! ym#include "dimensions.h"
-  ! y#include "dimphy.h"
 
   ! ================================================================
Index: /LMDZ5/branches/testing/libf/phylmd/pppmer.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/pppmer.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/pppmer.F90	(revision 2408)
@@ -0,0 +1,161 @@
+SUBROUTINE PPPMER(KPROMA,KSTART,KPROF,PRPRESS,POROG,PTSTAR,PT0,PMSLPPP)
+
+!**** *PPPMER* - POST-PROCESS MSL PRESSURE.
+
+!     PURPOSE.
+!     --------
+!           COMPUTES MSL PRESSURE.
+
+!**   INTERFACE.
+!     ----------
+
+!        *CALL* *PPPMER(KPROMA,KSTART,KPROF,PRPRESS,POROG,PTSTAR,PT0,
+!    S                  PMSLPPP)
+
+!        EXPLICIT ARGUMENTS
+!        --------------------
+
+
+!        KPROMA                    - HORIZONTAL DIMENSION.             (INPUT)
+!        KSTART                    - START OF WORK.                    (INPUT)
+!        KPROF                     - DEPTH OF WORK.                    (INPUT)
+!        PRPRESS(KPROMA)           - SURFACE PRESSURE                  (INPUT)
+!        POROG(KPROMA)             - MODEL OROGRAPHY.                  (INPUT)
+!        PTSTAR(KPROMA)            - SURFACE TEMPERATURE               (INPUT)
+!        PT0(KPROMA)               - STANDARD SURFACE TEMPERATURE      (INPUT)
+!        PMSLPPP(KPROMA)           - POST-PROCESSED MSL PRESSURE       (OUTPUT)
+!        IMPLICIT ARGUMENTS :  CONSTANTS FROM YOMCST,YOMGEM,YOMSTA.
+!        --------------------
+
+!     METHOD.
+!     -------
+!        SEE DOCUMENTATION
+
+!     EXTERNALS.  NONE
+!     ----------
+
+!     REFERENCE.
+!     ----------
+!        ECMWF Research Department documentation of the IFS
+
+!     AUTHOR.
+!     -------
+!        MATS HAMRUD AND PHILIPPE COURTIER  *ECMWF*
+
+!     MODIFICATIONS.
+!     --------------
+!        ORIGINAL : 89-01-26
+
+!     E. A-son, J-F Geleyn 920409 Mod. T*, T0 and alpha below surface.
+!        M.Hamrud      01-Oct-2003 CY28 Cleaning
+
+!     ------------------------------------------------------------------
+
+! USE PARKIND1 
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/xrd/module/parkind1.F90.php#parkind1>  ,ONLY : JPIM     ,JPRB
+! USE YOMHOOK 
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/xrd/module/yomhook.F90.php#yomhook>   ,ONLY : LHOOK,   DR_HOOK
+
+!USE YOMCST, ONLY : RG, RD
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/arp/module/yomcst.F90.php#yomcst>   , ONLY : RG
+
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/xrd/support/rg.F.php#rg>       ,RD
+! USE YOMSTA 
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/arp/module/yomsta.F90.php#yomsta>   , ONLY : RDTDZ1
+
+  IMPLICIT NONE
+
+include "YOMCST.h"
+!IM INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA
+!IM INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART
+!IM INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF
+ INTEGER,INTENT(IN)    :: KPROMA
+ INTEGER,INTENT(IN)    :: KSTART
+ INTEGER,INTENT(IN)    :: KPROF
+!IM REAL(KIND=JPRB)   ,INTENT(IN)    :: PRPRESS(KPROMA)
+!IM REAL(KIND=JPRB)   ,INTENT(IN)    :: POROG(KPROMA)
+!IM REAL(KIND=JPRB)   ,INTENT(IN)    :: PTSTAR(KPROMA)
+!IM REAL(KIND=JPRB)   ,INTENT(IN)    :: PT0(KPROMA)
+!IM REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMSLPPP(KPROMA)
+!IM REAL(KIND=JPRB) :: ZTSTAR(KPROMA)
+!IM REAL(KIND=JPRB) :: ZALPHA(KPROMA)
+ REAL,INTENT(IN)    :: PRPRESS(KPROMA)
+ REAL,INTENT(IN)    :: POROG(KPROMA)
+ REAL,INTENT(IN)    :: PTSTAR(KPROMA)
+ REAL,INTENT(IN)    :: PT0(KPROMA)
+ REAL,INTENT(OUT)   :: PMSLPPP(KPROMA)
+ REAL :: ZTSTAR(KPROMA)
+ REAL :: ZALPHA(KPROMA)
+
+!IM INTEGER(KIND=JPIM) :: JL
+ INTEGER :: JL
+
+!IM REAL(KIND=JPRB) :: ZDTDZSG, ZOROG, ZT0, ZTX, ZTY, ZX, ZY, ZY2
+!IM REAL(KIND=JPRB) :: ZHOOK_HANDLE
+ REAL :: ZDTDZSG, ZOROG, ZT0, ZTX, ZTY, ZX, ZY, ZY2
+ REAL :: ZHOOK_HANDLE
+!IM beg
+REAL, PARAMETER                  :: RDTDZ1=-0.0065 !or USE YOMSTA
+!IM end
+
+!     ------------------------------------------------------------------
+
+!*       1.    POST-PROCESS MSL PRESSURE.
+!              --------------------------
+
+!*       1.1   COMPUTATION OF MODIFIED ALPHA AND TSTAR.
+
+!IM IF (LHOOK) CALL DR_HOOK('PPPMER',0,ZHOOK_HANDLE)
+!IM ZTX=290.5_JPRB
+!IM ZTY=255.0_JPRB
+ ZTX=290.5
+ ZTY=255.0
+ ZDTDZSG=-RDTDZ1/RG 
+!<http://intra.cnrm.meteo.fr/eac/ARPCLI5.2/doci/code/arpcli5.2/xrd/support/rg.F.php#rg>
+ DO JL=KSTART,KPROF
+
+   IF(PTSTAR(JL) < ZTY) THEN
+!IM  ZTSTAR(JL)=0.5_JPRB*(ZTY+PTSTAR(JL))
+     ZTSTAR(JL)=0.5*(ZTY+PTSTAR(JL))
+   ELSEIF(PTSTAR(JL) < ZTX) THEN
+     ZTSTAR(JL)=PTSTAR(JL)
+   ELSE
+!IM    ZTSTAR(JL)=0.5_JPRB*(ZTX+PTSTAR(JL))
+     ZTSTAR(JL)=0.5*(ZTX+PTSTAR(JL))
+   ENDIF
+
+   ZT0=ZTSTAR(JL)+ZDTDZSG*POROG(JL)
+   IF(ZTX > ZTSTAR(JL) .AND. ZT0 > ZTX) THEN
+     ZT0=ZTX
+   ELSEIF(ZTX <= ZTSTAR(JL) .AND. ZT0 > ZTSTAR(JL)) THEN
+     ZT0=ZTSTAR(JL)
+   ELSE
+     ZT0=PT0(JL)
+   ENDIF
+
+!IM  ZOROG=SIGN(MAX(1.0_JPRB,ABS(POROG(JL))),POROG(JL))
+   ZOROG=SIGN(MAX(1.0,ABS(POROG(JL))),POROG(JL))
+   ZALPHA(JL)=RD*(ZT0-ZTSTAR(JL))/ZOROG
+ ENDDO
+
+!*       1.2   COMPUTATION OF MSL PRESSURE.
+
+ DO JL=KSTART,KPROF
+!IM  IF (ABS(POROG(JL)) >= 0.001_JPRB) THEN
+   IF (ABS(POROG(JL)) >= 0.001) THEN
+     ZX=POROG(JL)/(RD*ZTSTAR(JL))
+     ZY=ZALPHA(JL)*ZX
+     ZY2=ZY*ZY
+
+!IM    PMSLPPP(JL)=PRPRESS(JL)*EXP(ZX*(1.0_JPRB-0.5_JPRB*ZY+1.0_JPRB/3._JPRB*ZY2))
+     PMSLPPP(JL)=PRPRESS(JL)*EXP(ZX*(1.0-0.5*ZY+1.0/3.*ZY2))
+   ELSE
+     PMSLPPP(JL)=PRPRESS(JL)
+   ENDIF
+ ENDDO
+
+
+!     ------------------------------------------------------------------
+
+!IM IF (LHOOK) CALL DR_HOOK('PPPMER',1,ZHOOK_HANDLE)
+ END SUBROUTINE PPPMER
Index: /LMDZ5/branches/testing/libf/phylmd/radiation_AR4.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/radiation_AR4.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/radiation_AR4.F90	(revision 2408)
@@ -6,11 +6,8 @@
     psolswai, ok_ade, ok_aie)
   USE dimphy
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "YOMCST.h"
-  include "iniprint.h"
 
   ! ------------------------------------------------------------------
@@ -317,7 +314,4 @@
     rtdumg, rth2o, rtumg
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "radepsi.h"
   include "radopt.h"
@@ -485,5 +479,5 @@
   USE dimphy
   USE radiation_ar4_param, ONLY: rsun, rray
-  USE infotrac, ONLY: type_trac
+  USE infotrac_phy, ONLY: type_trac
 #ifdef REPROBUS
   USE chem_rep, ONLY: rsuntime, ok_suntime
@@ -491,8 +485,4 @@
 
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"i
-  include "iniprint.h"
 
   ! ------------------------------------------------------------------
@@ -710,5 +700,5 @@
   USE dimphy
   USE radiation_ar4_param, ONLY: rsun, rray
-  USE infotrac, ONLY: type_trac
+  USE infotrac_phy, ONLY: type_trac
 #ifdef REPROBUS
   USE chem_rep, ONLY: rsuntime, ok_suntime
@@ -716,7 +706,4 @@
 
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "radepsi.h"
 
@@ -1211,7 +1198,4 @@
   USE radiation_ar4_param, ONLY: taua, rpiza, rcga
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "radepsi.h"
   include "radopt.h"
@@ -1542,7 +1526,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "radepsi.h"
   include "radopt.h"
@@ -1872,7 +1853,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
 
   ! ------------------------------------------------------------------
@@ -1999,7 +1977,4 @@
   USE radiation_ar4_param, ONLY: apad, bpad, d
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
 
   ! -----------------------------------------------------------------------
@@ -2071,7 +2046,4 @@
   USE radiation_ar4_param, ONLY: apad, bpad, d
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
 
   ! -----------------------------------------------------------------------
@@ -2152,11 +2124,8 @@
     plwup, plwdn, plwup0, plwdn0)
   USE dimphy
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "raddimlw.h"
   include "YOMCST.h"
-  include "iniprint.h"
 
   ! -----------------------------------------------------------------------
@@ -2343,5 +2312,5 @@
   USE dimphy
   USE radiation_ar4_param, ONLY: tref, rt1, raer, at, bt, oct
-  USE infotrac, ONLY: type_trac
+  USE infotrac_phy, ONLY: type_trac
 #ifdef REPROBUS
   USE chem_rep, ONLY: rch42d, rn2o2d, rcfc112d, rcfc122d, ok_rtime2d
@@ -2349,7 +2318,4 @@
 
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "raddimlw.h"
   include "YOMCST.h"
@@ -2715,7 +2681,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "raddimlw.h"
   include "YOMCST.h"
@@ -2804,7 +2767,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "radepsi.h"
   include "radopt.h"
@@ -3184,7 +3144,4 @@
   USE radiation_ar4_param, ONLY: tintp, xp, ga, gb
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "raddimlw.h"
 
@@ -4586,7 +4543,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "raddimlw.h"
   include "YOMCST.h"
@@ -4694,7 +4648,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "raddimlw.h"
   include "radopt.h"
@@ -4996,7 +4947,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "raddimlw.h"
 
@@ -5232,7 +5180,4 @@
   USE radiation_ar4_param, ONLY: wg1
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "raddimlw.h"
 
@@ -5427,7 +5372,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "raddimlw.h"
 
@@ -5603,7 +5545,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! ym#include "raddim.h"
   include "raddimlw.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/radio_decay.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/radio_decay.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/radio_decay.F90	(revision 2408)
@@ -7,5 +7,5 @@
 !
   USE dimphy
-  USE infotrac, ONLY : nbtr
+  USE infotrac_phy, ONLY : nbtr
   USE traclmdz_mod, ONLY : id_rn, id_pb
   IMPLICIT NONE
Index: /LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90	(revision 2408)
@@ -24,5 +24,5 @@
    qsat, flwc, fiwc, &
    ref_liq, ref_ice, ref_liq_pi, ref_ice_pi, &
-   heat,heat0,cool,cool0,radsol,albpla,&
+   heat,heat0,cool,cool0,albpla,&
    topsw,toplw,solsw,sollw,&
    sollwdown,&
@@ -48,5 +48,5 @@
   USE DIMPHY
   USE assert_m, ONLY : assert
-  USE infotrac, ONLY : type_trac
+  USE infotrac_phy, ONLY : type_trac
   USE write_field_phy
 #ifdef REPROBUS
@@ -77,7 +77,6 @@
       USE YOERRTWN , ONLY : DELWAVE   ,TOTPLNK      
       USE YOMPHY3  , ONLY : RII0
-#else
-      USE aero_mod, ONLY : nbands_lw_rrtm
 #endif
+      USE aero_mod
 
   !======================================================================
@@ -111,5 +110,4 @@
   ! heat-----output-R- echauffement atmospherique (visible) (K/jour)
   ! cool-----output-R- refroidissement dans l'IR (K/jour)
-  ! radsol---output-R- bilan radiatif net au sol (W/m**2) (+ vers le bas)
   ! albpla---output-R- albedo planetaire (entre 0 et 1)
   ! topsw----output-R- flux solaire net au sommet de l'atm.
@@ -171,5 +169,4 @@
   include "YOMCST.h"
   include "clesphys.h"
-  include "iniprint.h"
 
 ! Input arguments
@@ -195,7 +192,7 @@
   LOGICAL, INTENT(in)  :: flag_aerosol_strat                             ! use stratospheric aerosols
   REAL,    INTENT(in)  :: cldfra(KLON,KLEV), cldemi(KLON,KLEV), cldtaupd(KLON,KLEV)
-  REAL,    INTENT(in)  :: tau_aero(KLON,KLEV,9,2)                        ! aerosol optical properties (see aeropt.F)
-  REAL,    INTENT(in)  :: piz_aero(KLON,KLEV,9,2)                        ! aerosol optical properties (see aeropt.F)
-  REAL,    INTENT(in)  :: cg_aero(KLON,KLEV,9,2)                         ! aerosol optical properties (see aeropt.F)
+  REAL,    INTENT(in)  :: tau_aero(KLON,KLEV,naero_grp,2)                        ! aerosol optical properties (see aeropt.F)
+  REAL,    INTENT(in)  :: piz_aero(KLON,KLEV,naero_grp,2)                        ! aerosol optical properties (see aeropt.F)
+  REAL,    INTENT(in)  :: cg_aero(KLON,KLEV,naero_grp,2)                         ! aerosol optical properties (see aeropt.F)
 !--OB
   REAL,    INTENT(in)  :: tau_aero_sw_rrtm(KLON,KLEV,2,NSW)                 ! aerosol optical properties RRTM
@@ -225,5 +222,5 @@
   REAL,    INTENT(out) :: heat(KLON,KLEV), cool(KLON,KLEV)
   REAL,    INTENT(out) :: heat0(KLON,KLEV), cool0(KLON,KLEV)
-  REAL,    INTENT(out) :: radsol(KLON), topsw(KLON), toplw(KLON)
+  REAL,    INTENT(out) :: topsw(KLON), toplw(KLON)
   REAL,    INTENT(out) :: solsw(KLON), sollw(KLON), albpla(KLON)
   REAL,    INTENT(out) :: topsw0(KLON), toplw0(KLON), solsw0(KLON), sollw0(KLON)
@@ -293,7 +290,7 @@
   REAL(KIND=8) zsolsw0(kdlon), zsollw0(kdlon)
   REAL(KIND=8) zznormcp
-  REAL(KIND=8) tauaero(kdlon,kflev,9,2)                     ! aer opt properties
-  REAL(KIND=8) pizaero(kdlon,kflev,9,2)
-  REAL(KIND=8) cgaero(kdlon,kflev,9,2)
+  REAL(KIND=8) tauaero(kdlon,kflev,naero_grp,2)                     ! aer opt properties
+  REAL(KIND=8) pizaero(kdlon,kflev,naero_grp,2)
+  REAL(KIND=8) cgaero(kdlon,kflev,naero_grp,2)
   REAL(KIND=8) PTAUA(kdlon,2,kflev)                         ! present-day value of cloud opt thickness (PTAU is pre-industrial value), local use
   REAL(KIND=8) POMEGAA(kdlon,2,kflev)                       ! dito for single scatt albedo
@@ -393,9 +390,9 @@
   IF (nb_gr*kdlon .NE. KLON) THEN
       PRINT*, "kdlon mauvais:", KLON, kdlon, nb_gr
-      call abort_gcm("radlwsw", "", 1)
+      call abort_physic("radlwsw", "", 1)
   ENDIF
   IF (kflev .NE. KLEV) THEN
       PRINT*, "kflev differe de KLEV, kflev, KLEV"
-      call abort_gcm("radlwsw", "", 1)
+      call abort_physic("radlwsw", "", 1)
   ENDIF
   !-------------------------------------------
@@ -1000,5 +997,7 @@
           zalbpla(i)   = ZFSUP(i,klev+1)/ZFSDN(i,klev+1)
          ENDIF
-         zsollwdown(i)= ZFLDN(i,1)
+!!! 5 juin 2015
+!!! Correction MP bug RRTM
+         zsollwdown(i)= -1.*ZFLDN(i,1)
       ENDDO
 !     print*,'OK2'
@@ -1025,5 +1024,5 @@
 #else
     abort_message="You should compile with -rrtm if running with iflag_rrtm=1"
-    call abort_gcm(modname, abort_message, 1)
+    call abort_physic(modname, abort_message, 1)
 #endif
     ENDIF ! iflag_rrtm
@@ -1031,5 +1030,4 @@
 
     DO i = 1, kdlon
-      radsol(iof+i) = zsolsw(i) + zsollw(i)
       topsw(iof+i) = ztopsw(i)
       toplw(iof+i) = ztoplw(i)
Index: /LMDZ5/branches/testing/libf/phylmd/read_map2D.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/read_map2D.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/read_map2D.F90	(revision 2408)
@@ -6,5 +6,5 @@
   USE mod_grid_phy_lmdz
   USE mod_phys_lmdz_para
-
+  USE print_control_mod, ONLY: lunout
 
   IMPLICIT NONE
@@ -27,5 +27,4 @@
   REAL, DIMENSION(nbp_lon,nbp_lat) :: var_glo2D_tmp ! 2D global
   REAL, DIMENSION(klon_glo)        :: var_glo1D     ! 1D global
-  INCLUDE "iniprint.h"
 
 ! Read variable from file. Done by master process MPI and master thread OpenMP
@@ -66,7 +65,7 @@
   CONTAINS
     SUBROUTINE write_err_mess(err_mess)
-
+      USE print_control_mod, ONLY: lunout
+      IMPLICIT NONE
       CHARACTER(len=*), INTENT(IN) :: err_mess
-      INCLUDE "iniprint.h"
       
       WRITE(lunout,*) 'Error in read_map2D, filename = ', trim(filename)
@@ -74,5 +73,5 @@
       WRITE(lunout,*) 'Error in read_map2D, timestep = ', timestep
 
-      CALL abort_gcm(modname, err_mess, 1)
+      CALL abort_physic(modname, err_mess, 1)
 
     END SUBROUTINE write_err_mess
Index: /LMDZ5/branches/testing/libf/phylmd/read_pstoke.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/read_pstoke.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/read_pstoke.F90	(revision 2408)
@@ -19,41 +19,39 @@
   USE netcdf
   USE dimphy
-  USE control_mod
   USE indice_sol_mod
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev
 
   IMPLICIT NONE
 
   include "netcdf.inc"
-  include "dimensions.h"
-  include "paramet.h"
-  include "comconst.h"
-  include "comgeom.h"
-  include "temps.h"
-  include "ener.h"
-  include "logic.h"
-  include "description.h"
-  include "serre.h"
-  ! ccc#include "dimphy.h"
 
   INTEGER klono, klevo, imo, jmo
-  PARAMETER (imo=iim/2, jmo=(jjm+1)/2)
-  PARAMETER (klono=(jmo-1)*imo+2, klevo=llm)
-  REAL phisfi(klono)
-  REAL phisfi2(imo, jmo+1), airefi2(imo, jmo+1)
-
-  REAL mfu(klono, klevo), mfd(klono, klevo)
-  REAL en_u(klono, klevo), de_u(klono, klevo)
-  REAL en_d(klono, klevo), de_d(klono, klevo)
-  REAL coefh(klono, klevo)
-  REAL fm_therm(klono, klevo), en_therm(klono, klevo)
-
-  REAL mfu2(imo, jmo+1, klevo), mfd2(imo, jmo+1, klevo)
-  REAL en_u2(imo, jmo+1, klevo), de_u2(imo, jmo+1, klevo)
-  REAL en_d2(imo, jmo+1, klevo), de_d2(imo, jmo+1, klevo)
-  REAL coefh2(imo, jmo+1, klevo)
-  REAL fm_therm2(imo, jmo+1, klevo)
-  REAL en_therm2(imo, jmo+1, klevo)
-
-  REAL pl(klevo)
+!  PARAMETER (imo=iim/2, jmo=(jjm+1)/2)
+!  PARAMETER (klono=(jmo-1)*imo+2, klevo=llm)
+  REAL :: phisfi(((nbp_lat/2)-1)*(nbp_lon/2)+2) !phisfi(klono)
+  REAL,ALLOCATABLE :: phisfi2(:,:) !phisfi2(imo,jmo+1)
+  REAL,ALLOCATABLE :: airefi2(:,:) !airefi2(imo, jmo+1)
+
+  REAL :: mfu(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) ! mfu(klono, klevo)
+  REAL :: mfd(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) ! mfd(klono, klevo)
+  REAL :: en_u(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !en_u(klono, klevo)
+  REAL :: de_u(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !de_u(klono, klevo)
+  REAL :: en_d(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !en_d(klono, klevo)
+  REAL :: de_d(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !de_d(klono, klevo)
+  REAL :: coefh(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !coefh(klono, klevo)
+  REAL :: fm_therm(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !fm_therm(klono, klevo)
+  REAL :: en_therm(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !en_therm(klono, klevo)
+
+  REAL,ALLOCATABLE :: mfu2(:,:,:) !mfu2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: mfd2(:,:,:) !mfd2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: en_u2(:,:,:) !en_u2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: de_u2(:,:,:) !de_u2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: en_d2(:,:,:) !en_d2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: de_d2(:,:,:) !de_d2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: coefh2(:,:,:) !coefh2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: fm_therm2(:,:,:) !fm_therm2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: en_therm2(:,:,:) !en_therm2(imo, jmo+1, klevo)
+
+  REAL,ALLOCATABLE :: pl(:) !pl(klevo)
   INTEGER irec
   INTEGER xid, yid, zid, tid
@@ -61,5 +59,5 @@
   INTEGER ncrec, ncklono, ncklevo, ncim, ncjm
 
-  REAL airefi(klono)
+  REAL :: airefi(((nbp_lat/2)-1)*(nbp_lon/2)+2) !airefi(klono)
   CHARACTER *20 namedim
 
@@ -69,43 +67,75 @@
 
 
-  REAL frac_impa(klono, klevo), frac_nucl(klono, klevo)
-  REAL frac_impa2(imo, jmo+1, klevo), frac_nucl2(imo, jmo+1, klevo)
-  REAL pyu1(klono), pyv1(klono)
-  REAL pyu12(imo, jmo+1), pyv12(imo, jmo+1)
-  REAL ftsol(klono, nbsrf)
-  REAL psrf(klono, nbsrf)
-  REAL ftsol1(klono), ftsol2(klono), ftsol3(klono), ftsol4(klono)
-  REAL psrf1(klono), psrf2(klono), psrf3(klono), psrf4(klono)
-  REAL ftsol12(imo, jmo+1), ftsol22(imo, jmo+1), ftsol32(imo, jmo+1), &
-    ftsol42(imo, jmo+1)
-  REAL psrf12(imo, jmo+1), psrf22(imo, jmo+1), psrf32(imo, jmo+1), &
-    psrf42(imo, jmo+1)
-  REAL t(klono, klevo)
-  REAL t2(imo, jmo+1, klevo)
-  INTEGER ncidp
-  SAVE ncidp
-  INTEGER varidt
-  INTEGER varidmfu, varidmfd, varidps, varidenu, variddeu
-  INTEGER varidend, varidded, varidch, varidfi, varidfn
-  INTEGER varidfmth, varidenth
-  INTEGER varidyu1, varidyv1, varidpl, varidai, varididvt
-  INTEGER varidfts1, varidfts2, varidfts3, varidfts4
-  INTEGER varidpsr1, varidpsr2, varidpsr3, varidpsr4
-  SAVE varidmfu, varidmfd, varidps, varidenu, variddeu
-  SAVE varidend, varidded, varidch, varidfi, varidfn
-  SAVE varidfmth, varidenth
-  SAVE varidyu1, varidyv1, varidpl, varidai, varididvt
-  SAVE varidfts1, varidfts2, varidfts3, varidfts4
-  SAVE varidpsr1, varidpsr2, varidpsr3, varidpsr4
-  SAVE varidt
+  REAL :: frac_impa(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !frac_impa(klono, klevo)
+  REAL :: frac_nucl(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !frac_nucl(klono, klevo)
+  REAL,ALLOCATABLE :: frac_impa2(:,:,:) !frac_impa2(imo, jmo+1, klevo)
+  REAL,ALLOCATABLE :: frac_nucl2(:,:,:) !frac_nucl2(imo, jmo+1, klevo)
+  REAL :: pyu1(((nbp_lat/2)-1)*(nbp_lon/2)+2) !pyu1(klono)
+  REAL :: pyv1(((nbp_lat/2)-1)*(nbp_lon/2)+2) !pyv1(klono)
+  REAL,ALLOCATABLE :: pyu12(:,:), pyv12(:,:) !pyu12(imo, jmo+1), pyv12(imo, jmo+1)
+  REAL :: ftsol(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !ftsol(klono, nbsrf)
+  REAL :: psrf(((nbp_lat/2)-1)*(nbp_lon/2)+2,nbp_lev) !psrf(klono, nbsrf)
+  REAL,ALLOCATABLE :: ftsol1(:),ftsol2(:) !ftsol1(klono), ftsol2(klono)
+  REAL,ALLOCATABLE :: ftsol3(:),ftsol4(:) !ftsol3(klono), ftsol4(klono)
+  REAL,ALLOCATABLE :: psrf1(:), psrf2(:) !psrf1(klono), psrf2(klono)
+  REAL,ALLOCATABLE :: psrf3(:), psrf4(:) !psrf3(klono), psrf4(klono)
+  REAL,ALLOCATABLE :: ftsol12(:,:) !ftsol12(imo, jmo+1)
+  REAL,ALLOCATABLE :: ftsol22(:,:) !ftsol22(imo, jmo+1)
+  REAL,ALLOCATABLE :: ftsol32(:,:) !ftsol32(imo, jmo+1)
+  REAL,ALLOCATABLE :: ftsol42(:,:) !ftsol42(imo, jmo+1)
+  REAL,ALLOCATABLE :: psrf12(:,:) !psrf12(imo, jmo+1)
+  REAL,ALLOCATABLE :: psrf22(:,:) !psrf22(imo, jmo+1)
+  REAL,ALLOCATABLE :: psrf32(:,:) !psrf32(imo, jmo+1)
+  REAL,ALLOCATABLE :: psrf42(:,:) !psrf42(imo, jmo+1)
+  REAL :: t(((nbp_lon/2)-1)*(nbp_lat/2)+2,nbp_lev) !t(klono, klevo)
+  REAL,ALLOCATABLE :: t2(:,:,:) !t2(imo, jmo+1, klevo)
+  INTEGER,SAVE :: ncidp
+  INTEGER,SAVE :: varidt
+  INTEGER,SAVE :: varidmfu, varidmfd, varidps, varidenu, variddeu
+  INTEGER,SAVE :: varidend, varidded, varidch, varidfi, varidfn
+  INTEGER,SAVE :: varidfmth, varidenth
+  INTEGER,SAVE :: varidyu1, varidyv1, varidpl, varidai, varididvt
+  INTEGER,SAVE :: varidfts1, varidfts2, varidfts3, varidfts4
+  INTEGER,SAVE :: varidpsr1, varidpsr2, varidpsr3, varidpsr4
 
   INTEGER l, i
   INTEGER start(4), count(4), status
   REAL rcode
-  LOGICAL first
-  SAVE first
-  DATA first/.TRUE./
-
-
+  LOGICAL,SAVE :: first=.TRUE.
+
+  ! Allocate arrays
+  imo=nbp_lon/2
+  jmo=nbp_lat/2
+  klono=(jmo-1)*imo+2
+  klevo=nbp_lev
+  
+  ALLOCATE(phisfi2(imo,jmo+1))
+  ALLOCATE(airefi2(imo, jmo+1))
+  ALLOCATE(mfu2(imo, jmo+1, klevo))
+  ALLOCATE(mfd2(imo, jmo+1, klevo))
+  ALLOCATE(en_u2(imo, jmo+1, klevo))
+  ALLOCATE(de_u2(imo, jmo+1, klevo))
+  ALLOCATE(en_d2(imo, jmo+1, klevo))
+  ALLOCATE(de_d2(imo, jmo+1, klevo))
+  ALLOCATE(coefh2(imo, jmo+1, klevo))
+  ALLOCATE(fm_therm2(imo, jmo+1, klevo))
+  ALLOCATE(en_therm2(imo, jmo+1, klevo))
+  ALLOCATE(pl(klevo))
+  ALLOCATE(frac_impa2(imo, jmo+1, klevo))
+  ALLOCATE(frac_nucl2(imo, jmo+1, klevo))
+  ALLOCATE(pyu12(imo, jmo+1), pyv12(imo, jmo+1))
+  ALLOCATE(ftsol1(klono), ftsol2(klono))
+  ALLOCATE(ftsol3(klono), ftsol4(klono))
+  ALLOCATE(psrf1(klono), psrf2(klono))
+  ALLOCATE(psrf3(klono), psrf4(klono))
+  ALLOCATE(ftsol12(imo, jmo+1))
+  ALLOCATE(ftsol22(imo, jmo+1))
+  ALLOCATE(ftsol32(imo, jmo+1))
+  ALLOCATE(ftsol42(imo, jmo+1))
+  ALLOCATE(psrf12(imo, jmo+1))
+  ALLOCATE(psrf22(imo, jmo+1))
+  ALLOCATE(psrf32(imo, jmo+1))
+  ALLOCATE(psrf42(imo, jmo+1))
+  ALLOCATE(t2(imo, jmo+1, klevo))
 
   ! ---------------------------------------------
Index: /LMDZ5/branches/testing/libf/phylmd/read_pstoke0.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/read_pstoke0.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/read_pstoke0.F90	(revision 2408)
@@ -18,46 +18,44 @@
   USE netcdf
   USE dimphy
-  USE control_mod
   USE indice_sol_mod
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev
 
   IMPLICIT NONE
 
   include "netcdf.inc"
-  include "dimensions.h"
-  include "paramet.h"
-  include "comconst.h"
-  include "comgeom.h"
-  include "temps.h"
-  include "ener.h"
-  include "logic.h"
-  include "description.h"
-  include "serre.h"
-  ! ccc#include "dimphy.h"
 
   INTEGER kon, kev, zkon, zkev
-  PARAMETER (kon=iim*(jjm-1)+2, kev=llm)
-  REAL phisfi(kon)
-  REAL phisfi2(iim, jjm+1), airefi2(iim, jjm+1)
-
-  REAL mfu(kon, kev), mfd(kon, kev)
-  REAL en_u(kon, kev), de_u(kon, kev)
-  REAL en_d(kon, kev), de_d(kon, kev)
-  REAL coefh(kon, kev)
+!  PARAMETER (kon=iim*(jjm-1)+2, kev=llm)
+  REAL :: phisfi(nbp_lon*(nbp_lat-2)+2) !phisfi(kon)
+  REAL,ALLOCATABLE :: phisfi2(:,:) !phisfi2(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: airefi2(:,:) !airefi2(nbp_lon, nbp_lat)
+
+  REAL :: mfu(nbp_lon*(nbp_lat-2)+2,nbp_lev) !mfu(kon, kev)
+  REAL :: mfd(nbp_lon*(nbp_lat-2)+2,nbp_lev) !mfd(kon, kev)
+  REAL :: en_u(nbp_lon*(nbp_lat-2)+2,nbp_lev) !en_u(kon, kev)
+  REAL :: de_u(nbp_lon*(nbp_lat-2)+2,nbp_lev) !de_u(kon, kev)
+  REAL :: en_d(nbp_lon*(nbp_lat-2)+2,nbp_lev) !en_d(kon, kev)
+  REAL :: de_d(nbp_lon*(nbp_lat-2)+2,nbp_lev) !de_d(kon, kev)
+  REAL :: coefh(nbp_lon*(nbp_lat-2)+2,nbp_lev) !coefh(kon, kev)
 
   ! abd 25 11 02
   ! Thermiques
-  REAL fm_therm(kon, kev), en_therm(kon, kev)
-  REAL t(kon, kev)
-
-  REAL mfu2(iim, jjm+1, kev), mfd2(iim, jjm+1, kev)
-  REAL en_u2(iim, jjm+1, kev), de_u2(iim, jjm+1, kev)
-  REAL en_d2(iim, jjm+1, kev), de_d2(iim, jjm+1, kev)
-  REAL coefh2(iim, jjm+1, kev)
-  REAL t2(iim, jjm+1, kev)
+  REAL :: fm_therm(nbp_lon*(nbp_lat-2)+2,nbp_lev) !fm_therm(kon, kev)
+  REAL :: en_therm(nbp_lon*(nbp_lat-2)+2,nbp_lev) !en_therm(kon, kev)
+  REAL :: t(nbp_lon*(nbp_lat-2)+2,nbp_lev) !t(kon, kev)
+
+  REAL,ALLOCATABLE :: mfu2(:,:,:) !mfu2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: mfd2(:,:,:) !mfd2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: en_u2(:,:,:) !en_u2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: de_u2(:,:,:) !de_u2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: en_d2(:,:,:) !en_d2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: de_d2(:,:,:) !de_d2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: coefh2(:,:,:) !coefh2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: t2(:,:,:) !t2(nbp_lon, nbp_lat, kev)
   ! Thermiques
-  REAL fm_therm2(iim, jjm+1, kev)
-  REAL en_therm2(iim, jjm+1, kev)
-
-  REAL pl(kev)
+  REAL,ALLOCATABLE :: fm_therm2(:,:,:) !fm_therm2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: en_therm2(:,:,:) !en_therm2(nbp_lon, nbp_lat, kev)
+
+  REAL,ALLOCATABLE :: pl(:) !pl(kev)
   INTEGER irec
   INTEGER xid, yid, zid, tid
@@ -65,5 +63,5 @@
   INTEGER ncrec, nckon, nckev, ncim, ncjm
 
-  REAL airefi(kon)
+  REAL :: airefi(nbp_lon*(nbp_lat-2)+2) !airefi(kon)
   CHARACTER *20 namedim
 
@@ -72,44 +70,73 @@
   ! dim de phis??
 
-  REAL frac_impa(kon, kev), frac_nucl(kon, kev)
-  REAL frac_impa2(iim, jjm+1, kev), frac_nucl2(iim, jjm+1, kev)
-  REAL pyu1(kon), pyv1(kon)
-  REAL pyu12(iim, jjm+1), pyv12(iim, jjm+1)
-  REAL ftsol(kon, nbsrf)
-  REAL psrf(kon, nbsrf)
-  REAL ftsol1(kon), ftsol2(kon), ftsol3(kon), ftsol4(kon)
-  REAL psrf1(kon), psrf2(kon), psrf3(kon), psrf4(kon)
-  REAL ftsol12(iim, jjm+1), ftsol22(iim, jjm+1), ftsol32(iim, jjm+1), &
-    ftsol42(iim, jjm+1)
-  REAL psrf12(iim, jjm+1), psrf22(iim, jjm+1), psrf32(iim, jjm+1), &
-    psrf42(iim, jjm+1)
-
-  INTEGER ncidp
-  SAVE ncidp
-  INTEGER varidmfu, varidmfd, varidps, varidenu, variddeu
-  INTEGER varidt
-  INTEGER varidend, varidded, varidch, varidfi, varidfn
+  REAL :: frac_impa(nbp_lon*(nbp_lat-2)+2,nbp_lev) !frac_impa(kon, kev)
+  REAL :: frac_nucl(nbp_lon*(nbp_lat-2)+2,nbp_lev) !frac_nucl(kon, kev)
+  REAL,ALLOCATABLE :: frac_impa2(:,:,:) !frac_impa2(nbp_lon, nbp_lat, kev)
+  REAL,ALLOCATABLE :: frac_nucl2(:,:,:) !frac_nucl2(nbp_lon, nbp_lat, kev)
+  REAL :: pyu1(nbp_lon*(nbp_lat-2)+2) !pyu1(kon)
+  REAL :: pyv1(nbp_lon*(nbp_lat-2)+2) !pyv1(kon)
+  REAL,ALLOCATABLE :: pyu12(:,:), pyv12(:,:) !pyu12(nbp_lon, nbp_lat), pyv12(nbp_lon, nbp_lat)
+  REAL :: ftsol(nbp_lon*(nbp_lat-2)+2,nbp_lev) !ftsol(kon, nbsrf)
+  REAL :: psrf(nbp_lon*(nbp_lat-2)+2,nbp_lev) !psrf(kon, nbsrf)
+  REAL,ALLOCATABLE :: ftsol1(:),ftsol2(:) !ftsol1(kon), ftsol2(kon)
+  REAL,ALLOCATABLE :: ftsol3(:),ftsol4(:) !ftsol3(kon), ftsol4(kon)
+  REAL,ALLOCATABLE :: psrf1(:), psrf2(:) !psrf1(kon), psrf2(kon)
+  REAL,ALLOCATABLE :: psrf3(:), psrf4(:) !psrf3(kon), psrf4(kon)
+  REAL,ALLOCATABLE :: ftsol12(:,:) !ftsol12(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: ftsol22(:,:) !ftsol22(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: ftsol32(:,:) !ftsol32(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: ftsol42(:,:) !ftsol42(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: psrf12(:,:) !psrf12(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: psrf22(:,:) !psrf22(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: psrf32(:,:) !psrf32(nbp_lon, nbp_lat)
+  REAL,ALLOCATABLE :: psrf42(:,:) !psrf42(nbp_lon, nbp_lat)
+
+  INTEGER,SAVE :: ncidp
+  INTEGER,SAVE :: varidmfu, varidmfd, varidps, varidenu, variddeu
+  INTEGER,SAVE :: varidt
+  INTEGER,SAVE :: varidend, varidded, varidch, varidfi, varidfn
   ! therm
-  INTEGER varidfmth, varidenth
-  INTEGER varidyu1, varidyv1, varidpl, varidai, varididvt
-  INTEGER varidfts1, varidfts2, varidfts3, varidfts4
-  INTEGER varidpsr1, varidpsr2, varidpsr3, varidpsr4
-  SAVE varidmfu, varidmfd, varidps, varidenu, variddeu
-  SAVE varidt
-  SAVE varidend, varidded, varidch, varidfi, varidfn
-  ! therm
-  SAVE varidfmth, varidenth
-  SAVE varidyu1, varidyv1, varidpl, varidai, varididvt
-  SAVE varidfts1, varidfts2, varidfts3, varidfts4
-  SAVE varidpsr1, varidpsr2, varidpsr3, varidpsr4
+  INTEGER,SAVE :: varidfmth, varidenth
+  INTEGER,SAVE :: varidyu1, varidyv1, varidpl, varidai, varididvt
+  INTEGER,SAVE :: varidfts1, varidfts2, varidfts3, varidfts4
+  INTEGER,SAVE :: varidpsr1, varidpsr2, varidpsr3, varidpsr4
 
   INTEGER l, i
   INTEGER start(4), count(4), status
   REAL rcode
-  LOGICAL first
-  SAVE first
-  DATA first/.TRUE./
-
-
+  LOGICAL,SAVE :: first=.TRUE.
+
+  ! Allocate arrays
+  kon=nbp_lon*(nbp_lat-2)+2
+  kev=nbp_lev
+
+  ALLOCATE(phisfi2(nbp_lon, nbp_lat))
+  ALLOCATE(airefi2(nbp_lon, nbp_lat))
+  ALLOCATE(mfu2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(mfd2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(en_u2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(de_u2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(en_d2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(de_d2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(coefh2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(t2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(fm_therm2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(en_therm2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(pl(kev))
+  ALLOCATE(frac_impa2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(frac_nucl2(nbp_lon, nbp_lat, kev))
+  ALLOCATE(pyu12(nbp_lon, nbp_lat), pyv12(nbp_lon, nbp_lat))
+  ALLOCATE(ftsol1(kon), ftsol2(kon))
+  ALLOCATE(ftsol3(kon), ftsol4(kon))
+  ALLOCATE(psrf1(kon), psrf2(kon))
+  ALLOCATE(psrf3(kon), psrf4(kon))
+  ALLOCATE(ftsol12(nbp_lon, nbp_lat))
+  ALLOCATE(ftsol22(nbp_lon, nbp_lat))
+  ALLOCATE(ftsol32(nbp_lon, nbp_lat))
+  ALLOCATE(ftsol42(nbp_lon, nbp_lat))
+  ALLOCATE(psrf12(nbp_lon, nbp_lat))
+  ALLOCATE(psrf22(nbp_lon, nbp_lat))
+  ALLOCATE(psrf32(nbp_lon, nbp_lat))
+  ALLOCATE(psrf42(nbp_lon, nbp_lat))
 
   ! ---------------------------------------------
@@ -248,5 +275,5 @@
     status = nf_get_vara_real(ncidp, varidps, start, count, phisfi2)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, phisfi2, phisfi)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, phisfi2, phisfi)
 
     ! **** Aires des mails aux sol ************************************
@@ -257,5 +284,5 @@
     status = nf_get_vara_real(ncidp, varidai, start, count, airefi2)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, airefi2, airefi)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, airefi2, airefi)
   ELSE
 
@@ -288,5 +315,5 @@
     status = nf_get_vara_real(ncidp, varidt, start, count, t2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, t2, t)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, t2, t)
 
     ! **** Flux pour la convection (Tiedtk)
@@ -298,5 +325,5 @@
     status = nf_get_vara_real(ncidp, varidmfu, start, count, mfu2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, mfu2, mfu)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, mfu2, mfu)
 
     ! mfd
@@ -306,5 +333,5 @@
     status = nf_get_vara_real(ncidp, varidmfd, start, count, mfd2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, mfd2, mfd)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, mfd2, mfd)
 
     ! en_u
@@ -314,5 +341,5 @@
     status = nf_get_vara_real(ncidp, varidenu, start, count, en_u2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, en_u2, en_u)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, en_u2, en_u)
 
     ! de_u
@@ -322,5 +349,5 @@
     status = nf_get_vara_real(ncidp, variddeu, start, count, de_u2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, de_u2, de_u)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, de_u2, de_u)
 
     ! en_d
@@ -330,5 +357,5 @@
     status = nf_get_vara_real(ncidp, varidend, start, count, en_d2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, en_d2, en_d)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, en_d2, en_d)
 
     ! de_d
@@ -338,5 +365,5 @@
     status = nf_get_vara_real(ncidp, varidded, start, count, de_d2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, de_d2, de_d)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, de_d2, de_d)
 
     ! **** Coefficient de mellange turbulent
@@ -349,5 +376,5 @@
     status = nf_get_vara_real(ncidp, varidch, start, count, coefh2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, coefh2, coefh)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, coefh2, coefh)
     ! call dump2d(iip1,jjp1,coefh2(1,2),'COEFH2READ   ')
     ! call dump2d(iim ,jjm ,coefh (2,2),'COEFH2READ   ')
@@ -362,5 +389,5 @@
     status = nf_get_vara_real(ncidp, varidfmth, start, count, fm_therm2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, fm_therm2, fm_therm)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, fm_therm2, fm_therm)
     PRINT *, 'LECTURE de en_therm a irec =', irec
 #ifdef NC_DOUBLE
@@ -369,5 +396,5 @@
     status = nf_get_vara_real(ncidp, varidenth, start, count, en_therm2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, en_therm2, en_therm)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, en_therm2, en_therm)
 
     ! **** Coefficients de lessivage
@@ -379,5 +406,5 @@
     status = nf_get_vara_real(ncidp, varidfi, start, count, frac_impa2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, frac_impa2, frac_impa)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, frac_impa2, frac_impa)
 
     ! frac_nucl
@@ -388,5 +415,5 @@
     status = nf_get_vara_real(ncidp, varidfn, start, count, frac_nucl2)
 #endif
-    CALL gr_ecrit_fi(kev, kon, iim, jjm+1, frac_nucl2, frac_nucl)
+    CALL gr_ecrit_fi(kev, kon, nbp_lon, nbp_lat, frac_nucl2, frac_nucl)
 
     ! **** Vents aux sol ********************************************
@@ -404,5 +431,5 @@
     status = nf_get_vara_real(ncidp, varidyu1, start, count, pyu12)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, pyu12, pyu1)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, pyu12, pyu1)
 
     ! pyv1
@@ -413,5 +440,5 @@
     status = nf_get_vara_real(ncidp, varidyv1, start, count, pyv12)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, pyv12, pyv1)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, pyv12, pyv1)
 
     ! **** Temerature au sol ********************************************
@@ -423,5 +450,5 @@
     status = nf_get_vara_real(ncidp, varidfts1, start, count, ftsol12)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, ftsol12, ftsol1)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, ftsol12, ftsol1)
 
     ! ftsol2
@@ -432,5 +459,5 @@
     status = nf_get_vara_real(ncidp, varidfts2, start, count, ftsol22)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, ftsol22, ftsol2)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, ftsol22, ftsol2)
 
     ! ftsol3
@@ -441,5 +468,5 @@
     status = nf_get_vara_real(ncidp, varidfts3, start, count, ftsol32)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, ftsol32, ftsol3)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, ftsol32, ftsol3)
 
     ! ftsol4
@@ -449,5 +476,5 @@
     status = nf_get_vara_real(ncidp, varidfts4, start, count, ftsol42)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, ftsol42, ftsol4)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, ftsol42, ftsol4)
 
     ! **** Nature sol ********************************************
@@ -459,5 +486,5 @@
 #endif
     ! call dump2d(iip1-1,jjm+1,psrf12,'PSRF1NC')
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, psrf12, psrf1)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, psrf12, psrf1)
 
     ! psrf2
@@ -468,5 +495,5 @@
 #endif
     ! call dump2d(iip1-1,jjm+1,psrf22,'PSRF2NC')
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, psrf22, psrf2)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, psrf22, psrf2)
 
     ! psrf3
@@ -476,5 +503,5 @@
     status = nf_get_vara_real(ncidp, varidpsr3, start, count, psrf32)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, psrf32, psrf3)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, psrf32, psrf3)
 
     ! psrf4
@@ -484,5 +511,5 @@
     status = nf_get_vara_real(ncidp, varidpsr4, start, count, psrf42)
 #endif
-    CALL gr_ecrit_fi(1, kon, iim, jjm+1, psrf42, psrf4)
+    CALL gr_ecrit_fi(1, kon, nbp_lon, nbp_lat, psrf42, psrf4)
 
     DO i = 1, kon
Index: /LMDZ5/branches/testing/libf/phylmd/readaerosol.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/readaerosol.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/readaerosol.F90	(revision 2408)
@@ -20,8 +20,7 @@
 !****************************************************************************************
   USE dimphy
+  USE print_control_mod, ONLY: lunout
 
   IMPLICIT NONE
-
- INCLUDE "iniprint.h"
 
   ! Input arguments
@@ -130,5 +129,5 @@
            IF (klev_src /= klev_src2) THEN
               WRITE(lunout,*) 'Two aerosols files with different number of vertical levels is not allowded'
-              CALL abort_gcm('readaersosol','Error in number of vertical levels',1)
+              CALL abort_physic('readaersosol','Error in number of vertical levels',1)
            END IF
            
@@ -162,5 +161,5 @@
   ELSE
      WRITE(lunout,*)'This option is not implemented : aer_type = ', type,' name_aero=',name_aero
-     CALL abort_gcm('readaerosol','Error : aer_type parameter not accepted',1)
+     CALL abort_physic('readaerosol','Error : aer_type parameter not accepted',1)
   END IF ! type
 
@@ -179,5 +178,5 @@
 ! 3) Read field month by month
 ! 4) Close file  
-! 5) Transform the global field from 2D(iim, jjp+1) to 1D(klon_glo)
+! 5) Transform the global field from 2D(nbp_lon,nbp_lat) to 1D(klon_glo)
 !     - Also the levels and the latitudes have to be inversed
 !
@@ -189,13 +188,12 @@
     USE netcdf
     USE dimphy
-    USE mod_grid_phy_lmdz
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, &
+                                 grid2Dto1D_glo
     USE mod_phys_lmdz_para
     USE iophy, ONLY : io_lon, io_lat
+    USE print_control_mod, ONLY: lunout
 
     IMPLICIT NONE
       
-    INCLUDE "dimensions.h"      
-    INCLUDE "iniprint.h"
-
 ! Input argumets
     CHARACTER(len=7), INTENT(IN)          :: varname
@@ -224,11 +222,11 @@
     REAL, ALLOCATABLE, DIMENSION(:)       :: varktmp
 
-    REAL, DIMENSION(iim,jjm+1,12)         :: psurf_glo2D   ! Surface pression for 12 months on dynamics global grid
+    REAL, DIMENSION(nbp_lon,nbp_lat,12)         :: psurf_glo2D   ! Surface pression for 12 months on dynamics global grid
     REAL, DIMENSION(klon_glo,12)          :: psurf_glo1D   ! -"- on physical global grid
-    REAL, DIMENSION(iim,jjm+1,12)         :: load_glo2D    ! Load for 12 months on dynamics global grid
+    REAL, DIMENSION(nbp_lon,nbp_lat,12)         :: load_glo2D    ! Load for 12 months on dynamics global grid
     REAL, DIMENSION(klon_glo,12)          :: load_glo1D    ! -"- on physical global grid
-    REAL, DIMENSION(iim,jjm+1)            :: vartmp
-    REAL, DIMENSION(iim)                  :: lon_src              ! longitudes in file
-    REAL, DIMENSION(jjm+1)                :: lat_src, lat_src_inv ! latitudes in file
+    REAL, DIMENSION(nbp_lon,nbp_lat)            :: vartmp
+    REAL, DIMENSION(nbp_lon)                  :: lon_src              ! longitudes in file
+    REAL, DIMENSION(nbp_lat)                :: lat_src, lat_src_inv ! latitudes in file
     LOGICAL                               :: new_file             ! true if new file format detected
     LOGICAL                               :: invert_lat           ! true if the field has to be inverted for latitudes
@@ -260,5 +258,5 @@
           WRITE(lunout,*) 'longitudes in model :', io_lon
           
-          CALL abort_gcm('get_aero_fromfile', 'longitudes are not the same in file and model',1)
+          CALL abort_physic('get_aero_fromfile', 'longitudes are not the same in file and model',1)
        END IF
 
@@ -268,6 +266,6 @@
 
        ! Invert source latitudes
-       DO j = 1, jjm+1
-          lat_src_inv(j) = lat_src(jjm+1 +1 -j)
+       DO j = 1, nbp_lat
+          lat_src_inv(j) = lat_src(nbp_lat +1 -j)
        END DO
 
@@ -283,5 +281,5 @@
           WRITE(lunout,*) 'latitudes in file ', TRIM(fname),' : ', lat_src      
           WRITE(lunout,*) 'latitudes in model :', io_lat
-          CALL abort_gcm('get_aero_fromfile', 'latitudes do not correspond between file and model',1)
+          CALL abort_physic('get_aero_fromfile', 'latitudes do not correspond between file and model',1)
        END IF
 
@@ -297,5 +295,5 @@
           IF (ierr /= NF90_NOERR) THEN
              ! Dimension PRESNIVS not found either
-             CALL abort_gcm('get_aero_fromfile', 'dimension lev or presnivs not in file',1)
+             CALL abort_physic('get_aero_fromfile', 'dimension lev or presnivs not in file',1)
           ELSE 
              ! Old file found
@@ -314,9 +312,9 @@
        
      ! Allocate variables depending on the number of vertical levels
-       ALLOCATE(varmth(iim, jjm+1, klev_src), varyear(iim, jjm+1, klev_src, 12), stat=ierr)
-       IF (ierr /= 0) CALL abort_gcm('get_aero_fromfile', 'pb in allocation 1',1)
+       ALLOCATE(varmth(nbp_lon,nbp_lat, klev_src), varyear(nbp_lon,nbp_lat, klev_src, 12), stat=ierr)
+       IF (ierr /= 0) CALL abort_physic('get_aero_fromfile', 'pb in allocation 1',1)
 
        ALLOCATE(pt_ap(klev_src), pt_b(klev_src), varktmp(klev_src), stat=ierr)
-       IF (ierr /= 0) CALL abort_gcm('get_aero_fromfile', 'pb in allocation 2',1)
+       IF (ierr /= 0) CALL abort_physic('get_aero_fromfile', 'pb in allocation 2',1)
 
 ! 3) Read all variables from file
@@ -333,5 +331,6 @@
 !       IF (nbr_tsteps /= 12 .AND. nbr_tsteps /= 14) THEN
        IF (nbr_tsteps /= 12 ) THEN
-         CALL abort_gcm('get_aero_fromfile', 'not the right number of months in aerosol file read (should be 12 for the moment)',1)
+    CALL abort_physic('get_aero_fromfile', 'not the right number of months in aerosol file read (should be 12 for the moment)' &
+                     ,1)
        ENDIF
 
@@ -435,5 +434,5 @@
      
 
-! 5) Transform the global field from 2D(iim, jjp+1) to 1D(klon_glo)
+! 5) Transform the global field from 2D(nbp_lon,nbp_lat) to 1D(klon_glo)
 !****************************************************************************************
 ! Test if vertical levels have to be inversed
@@ -448,6 +447,6 @@
              varmth(:,:,:) = varyear(:,:,:,imth) ! use varmth temporarly
              DO k=1, klev_src
-                DO j=1, jjm+1
-                   DO i=1,iim 
+                DO j=1, nbp_lat
+                   DO i=1, nbp_lon
                       varyear(i,j,k,imth) = varmth(i,j,klev_src+1-k)
                    END DO
@@ -482,7 +481,7 @@
              varmth(:,:,:) = varyear(:,:,:,imth) ! use varmth temporarly
              DO k=1,klev_src
-                DO j=1,jjm+1
-                   DO i=1,iim
-                      varyear(i,j,k,imth) = varmth(i,jjm+1+1-j,k)
+                DO j=1,nbp_lat
+                   DO i=1,nbp_lon
+                      varyear(i,j,k,imth) = varmth(i,nbp_lat+1-j,k)
                    END DO
                 END DO
@@ -491,7 +490,7 @@
              ! Invert latitudes for surface pressure
              vartmp(:,:) = psurf_glo2D(:,:,imth)
-             DO j=1, jjm+1
-                DO i=1,iim
-                   psurf_glo2D(i,j,imth)= vartmp(i,jjm+1+1-j)
+             DO j=1,nbp_lat
+                DO i=1,nbp_lon
+                   psurf_glo2D(i,j,imth)= vartmp(i,nbp_lat+1-j)
                 END DO
              END DO
@@ -499,7 +498,7 @@
              ! Invert latitudes for the load
              vartmp(:,:) = load_glo2D(:,:,imth)
-             DO j=1, jjm+1
-                DO i=1,iim
-                   load_glo2D(i,j,imth)= vartmp(i,jjm+1+1-j)
+             DO j=1,nbp_lat
+                DO i=1,nbp_lon
+                   load_glo2D(i,j,imth)= vartmp(i,nbp_lat+1-j)
                 END DO
              END DO
@@ -509,18 +508,18 @@
           DO k=1, klev_src
              npole=0.  ! North pole, j=1
-             spole=0.  ! South pole, j=jjm+1         
-             DO i=1,iim
+             spole=0.  ! South pole, j=nbp_lat        
+             DO i=1,nbp_lon
                 npole = npole + varyear(i,1,k,imth)
-                spole = spole + varyear(i,jjm+1,k,imth)
+                spole = spole + varyear(i,nbp_lat,k,imth)
              END DO
-             npole = npole/REAL(iim)
-             spole = spole/REAL(iim)
+             npole = npole/REAL(nbp_lon)
+             spole = spole/REAL(nbp_lon)
              varyear(:,1,    k,imth) = npole
-             varyear(:,jjm+1,k,imth) = spole
+             varyear(:,nbp_lat,k,imth) = spole
           END DO
        END DO ! imth
        
        ALLOCATE(varyear_glo1D(klon_glo, klev_src, 12), stat=ierr)
-       IF (ierr /= 0) CALL abort_gcm('get_aero_fromfile', 'pb in allocation 3',1)
+       IF (ierr /= 0) CALL abort_physic('get_aero_fromfile', 'pb in allocation 3',1)
        
        ! Transform from 2D to 1D field
@@ -546,5 +545,5 @@
     IF (.NOT. ASSOCIATED(pt_ap)) THEN  ! if pt_ap is allocated also pt_b is allocated
        ALLOCATE(pt_ap(klev_src), pt_b(klev_src), stat=ierr)
-       IF (ierr /= 0) CALL abort_gcm('get_aero_fromfile', 'pb in allocation 4',1)
+       IF (ierr /= 0) CALL abort_physic('get_aero_fromfile', 'pb in allocation 4',1)
     END IF
     CALL bcast(pt_ap)
@@ -554,5 +553,5 @@
     IF (ASSOCIATED(pt_year)) DEALLOCATE(pt_year)
     ALLOCATE(pt_year(klon, klev_src, 12), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('get_aero_fromfile', 'pb in allocation 5',1)
+    IF (ierr /= 0) CALL abort_physic('get_aero_fromfile', 'pb in allocation 5',1)
 
     ! Scatter global field to local domain at local process
@@ -572,7 +571,7 @@
   SUBROUTINE check_err(status,text)
     USE netcdf
+    USE print_control_mod, ONLY: lunout
     IMPLICIT NONE
 
-    INCLUDE "iniprint.h"
     INTEGER, INTENT (IN) :: status
     CHARACTER(len=*), INTENT (IN), OPTIONAL :: text
@@ -583,5 +582,5 @@
           WRITE(lunout,*) 'Error in get_aero_fromfile : ',text
        END IF
-       CALL abort_gcm('get_aero_fromfile',trim(nf90_strerror(status)),1)
+       CALL abort_physic('get_aero_fromfile',trim(nf90_strerror(status)),1)
     END IF
 
Index: /LMDZ5/branches/testing/libf/phylmd/readaerosol_interp.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/readaerosol_interp.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/readaerosol_interp.F90	(revision 2408)
@@ -21,4 +21,5 @@
   USE phys_cal_mod
   USE pres2lev_mod
+  USE print_control_mod, ONLY: lunout
 
   IMPLICIT NONE
@@ -26,9 +27,6 @@
   INCLUDE "YOMCST.h"
   INCLUDE "chem.h"      
-  INCLUDE "temps.h"      
   INCLUDE "clesphys.h"
-  INCLUDE "iniprint.h"
-  INCLUDE "dimensions.h"
-  INCLUDE "comvert.h"
+
 !
 ! Input:
@@ -150,13 +148,13 @@
   IF (.NOT. ALLOCATED(var_day)) THEN
      ALLOCATE( var_day(klon, klev, naero_spc), stat=ierr)
-     IF (ierr /= 0) CALL abort_gcm('readaerosol_interp', 'pb in allocation 1',1)
+     IF (ierr /= 0) CALL abort_physic('readaerosol_interp', 'pb in allocation 1',1)
      ALLOCATE( pi_var_day(klon, klev, naero_spc), stat=ierr)
-     IF (ierr /= 0) CALL abort_gcm('readaerosol_interp', 'pb in allocation 2',1)
+     IF (ierr /= 0) CALL abort_physic('readaerosol_interp', 'pb in allocation 2',1)
 
      ALLOCATE( psurf_year(klon, 12, naero_spc), pi_psurf_year(klon, 12, naero_spc), stat=ierr)
-     IF (ierr /= 0) CALL abort_gcm('readaerosol_interp', 'pb in allocation 3',1)
+     IF (ierr /= 0) CALL abort_physic('readaerosol_interp', 'pb in allocation 3',1)
 
      ALLOCATE( load_year(klon, 12, naero_spc), pi_load_year(klon, 12, naero_spc), stat=ierr)
-     IF (ierr /= 0) CALL abort_gcm('readaerosol_interp', 'pb in allocation 4',1)
+     IF (ierr /= 0) CALL abort_physic('readaerosol_interp', 'pb in allocation 4',1)
 
      lnewday=.TRUE.
@@ -209,5 +207,5 @@
         END IF
      ELSE
-        CALL abort_gcm('readaerosol_interp', 'this aer_type not supported',1)
+        CALL abort_physic('readaerosol_interp', 'this aer_type not supported',1)
      END IF
 
@@ -216,5 +214,5 @@
      IF (.NOT. ALLOCATED(var_year)) THEN
         ALLOCATE(var_year(klon, klev_src, 12, naero_spc), stat=ierr)
-        IF (ierr /= 0) CALL abort_gcm('readaerosol_interp', 'pb in allocation 5',1)
+        IF (ierr /= 0) CALL abort_physic('readaerosol_interp', 'pb in allocation 5',1)
      END IF
      var_year(:,:,:,id_aero) = pt_tmp(:,:,:)
@@ -230,10 +228,10 @@
         WRITE(lunout,*) 'Error! All forcing files for the same aerosol must have the same vertical dimension'
         WRITE(lunout,*) 'Aerosol : ', name_aero(id_aero)
-        CALL abort_gcm('readaerosol_interp','Differnt vertical axes in aerosol forcing files',1)
+        CALL abort_physic('readaerosol_interp','Differnt vertical axes in aerosol forcing files',1)
      END IF
 
      IF (.NOT. ALLOCATED(pi_var_year)) THEN
         ALLOCATE(pi_var_year(klon, klev_src, 12, naero_spc), stat=ierr)
-        IF (ierr /= 0) CALL abort_gcm('readaerosol_interp', 'pb in allocation 6',1)
+        IF (ierr /= 0) CALL abort_physic('readaerosol_interp', 'pb in allocation 6',1)
      END IF
      pi_var_year(:,:,:,id_aero) = pt_tmp(:,:,:)
@@ -259,10 +257,10 @@
         IF (  psurf_year(1,1,id_aero) /= pi_psurf_year(1,1,id_aero) ) THEN
            WRITE(lunout,*) 'Warning! All forcing files for the same aerosol must have the same structure'
-           CALL abort_gcm('readaerosol_interp', 'The aerosol files have not the same format',1)
+           CALL abort_physic('readaerosol_interp', 'The aerosol files have not the same format',1)
         END IF
         
         IF (klev /= klev_src) THEN
            WRITE(lunout,*) 'Old format of aerosol file do not allowed vertical interpolation'
-           CALL abort_gcm('readaerosol_interp', 'Old aerosol file not possible',1)
+           CALL abort_physic('readaerosol_interp', 'Old aerosol file not possible',1)
         END IF
 
@@ -336,5 +334,5 @@
        END IF
      ELSE
-       CALL abort_gcm('readaerosol_interp', 'number of months undefined',1)
+       CALL abort_physic('readaerosol_interp', 'number of months undefined',1)
      ENDIF
      if (debug) then
@@ -345,8 +343,8 @@
      ! Time interpolation, still on vertical source grid
      ALLOCATE(tmp1(klon,klev_src), tmp2(klon,klev_src),stat=ierr)
-     IF (ierr /= 0) CALL abort_gcm('readaerosol_interp', 'pb in allocation 7',1)
+     IF (ierr /= 0) CALL abort_physic('readaerosol_interp', 'pb in allocation 7',1)
 
      ALLOCATE(pplay_src(klon,klev_src), stat=ierr)
-     IF (ierr /= 0) CALL abort_gcm('readaerosol_interp', 'pb in allocation 8',1)
+     IF (ierr /= 0) CALL abort_physic('readaerosol_interp', 'pb in allocation 8',1)
      
 
@@ -544,5 +542,5 @@
                  WRITE(lunout,*) 'stop for aerosol : ',name_aero(id_aero)
                  WRITE(lunout,*) 'day1, day2, jDay = ', day1, day2, jDay 
-                 CALL abort_gcm('readaerosol_interp','Error in interpolation 1',1)
+                 CALL abort_physic('readaerosol_interp','Error in interpolation 1',1)
               END IF
            END DO 
@@ -563,5 +561,5 @@
                  
                  WRITE(lunout,*) 'stop for aerosol : ',name_aero(id_aero)
-                 CALL abort_gcm('readaerosol_interp','Error in interpolation 2',1)
+                 CALL abort_physic('readaerosol_interp','Error in interpolation 2',1)
               END IF
            END DO
Index: /LMDZ5/branches/testing/libf/phylmd/readaerosol_optic.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/readaerosol_optic.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/readaerosol_optic.F90	(revision 2408)
@@ -68,6 +68,6 @@
   REAL, DIMENSION(klon,klev)   :: ssacu_pi
   REAL, DIMENSION(klon,klev)   :: pdel
-  REAL, DIMENSION(klon,klev,naero_spc) :: m_allaer
-  REAL, DIMENSION(klon,klev,naero_spc) :: m_allaer_pi !RAF  
+  REAL, DIMENSION(klon,klev,naero_tot) :: m_allaer
+  REAL, DIMENSION(klon,klev,naero_tot) :: m_allaer_pi !RAF  
 !  REAL, DIMENSION(klon,naero_tot)      :: fractnat_allaer !RAF delete??
 
@@ -156,24 +156,28 @@
   m_allaer(:,:,id_AIBCM_phy)  = bcins(:,:)        ! AIBCM
   m_allaer(:,:,id_AIPOMM_phy) = pomins(:,:)       ! AIPOMM
+  m_allaer(:,:,id_ASNO3M_phy) = 0.0
+  m_allaer(:,:,id_CSNO3M_phy) = 0.0
+  m_allaer(:,:,id_CINO3M_phy) = 0.0
 
 !RAF
-  m_allaer_pi(:,:,1)  = bcsol_pi(:,:)        ! ASBCM pre-ind
-  m_allaer_pi(:,:,2)  = pomsol_pi(:,:)       ! ASPOMM pre-ind
-  m_allaer_pi(:,:,3)  = sulfate_pi(:,:)      ! ASSO4M (= SO4) pre-ind
-  m_allaer_pi(:,:,4)  = 0.                ! CSSO4M pre-ind
-  m_allaer_pi(:,:,5)  = sssupco_pi(:,:)      ! SSSSM pre-ind
-  m_allaer_pi(:,:,6)  = sscoarse_pi(:,:)     ! CSSSM pre-ind
-  m_allaer_pi(:,:,7)  = ssacu_pi(:,:)        ! ASSSM pre-ind
-  m_allaer_pi(:,:,8)  = cidust_pi(:,:)       ! CIDUSTM pre-ind
-  m_allaer_pi(:,:,9)  = bcins_pi(:,:)        ! AIBCM pre-ind
-  m_allaer_pi(:,:,10) = pomins_pi(:,:)       ! AIPOMM pre-ind
+  m_allaer_pi(:,:,id_ASBCM_phy)   = bcsol_pi(:,:)        ! ASBCM pre-ind
+  m_allaer_pi(:,:,id_ASPOMM_phy)  = pomsol_pi(:,:)       ! ASPOMM pre-ind
+  m_allaer_pi(:,:,id_ASSO4M_phy)  = sulfate_pi(:,:)      ! ASSO4M (= SO4) pre-ind
+  m_allaer_pi(:,:,id_CSSO4M_phy)  = 0.                   ! CSSO4M pre-ind
+  m_allaer_pi(:,:,id_SSSSM_phy)   = sssupco_pi(:,:)      ! SSSSM pre-ind
+  m_allaer_pi(:,:,id_ASSSM_phy)   = sscoarse_pi(:,:)     ! CSSSM pre-ind
+  m_allaer_pi(:,:,id_CIDUSTM_phy) = ssacu_pi(:,:)        ! ASSSM pre-ind
+  m_allaer_pi(:,:,id_AIBCM_phy)   = cidust_pi(:,:)       ! CIDUSTM pre-ind
+  m_allaer_pi(:,:,id_AIBCM_phy)   = bcins_pi(:,:)        ! AIBCM pre-ind
+  m_allaer_pi(:,:,id_AIPOMM_phy)  = pomins_pi(:,:)       ! AIPOMM pre-ind
+  m_allaer_pi(:,:,id_ASNO3M_phy) = 0.0
+  m_allaer_pi(:,:,id_CSNO3M_phy) = 0.0
+  m_allaer_pi(:,:,id_CINO3M_phy) = 0.0
 
 !
 ! Calculate the total mass of all soluble aersosols
 !
-  mass_solu_aero(:,:)    = sulfate(:,:)    + bcsol(:,:)    + pomsol(:,:) !   + &
-!       sscoarse(:,:)    + ssacu(:,:)    + sssupco(:,:) 
-  mass_solu_aero_pi(:,:) = sulfate_pi(:,:) + bcsol_pi(:,:) + pomsol_pi(:,:) ! + &
-!       sscoarse_pi(:,:) + ssacu_pi(:,:) + sssupco_pi(:,:)
+  mass_solu_aero(:,:)    = sulfate(:,:)    + bcsol(:,:)    + pomsol(:,:) + ssacu(:,:)
+  mass_solu_aero_pi(:,:) = sulfate_pi(:,:) + bcsol_pi(:,:) + pomsol_pi(:,:) + ssacu_pi(:,:)
 
 !****************************************************************************************
@@ -214,5 +218,5 @@
 ! Diagnostics calculation for CMIP5 protocol
   sconcso4(:)=m_allaer(:,1,id_ASSO4M_phy)*1.e-9
-!  sconcno3(:)=m_allaer(:,1,id_ASNO3M_phy)*1.e-9
+  sconcno3(:)=m_allaer(:,1,id_ASNO3M_phy)*1.e-9
   sconcoa(:)=(m_allaer(:,1,id_ASPOMM_phy)+m_allaer(:,1,id_AIPOMM_phy))*1.e-9
   sconcbc(:)=(m_allaer(:,1,id_ASBCM_phy)+m_allaer(:,1,id_AIBCM_phy))*1.e-9
@@ -220,5 +224,5 @@
   sconcdust(:)=m_allaer(:,1,id_CIDUSTM_phy)*1.e-9
   concso4(:,:)=m_allaer(:,:,id_ASSO4M_phy)*1.e-9
-!  concno3(:,:)=m_allaer(:,:,id_ASNO3M_phy)*1.e-9
+  concno3(:,:)=m_allaer(:,:,id_ASNO3M_phy)*1.e-9
   concoa(:,:)=(m_allaer(:,:,id_ASPOMM_phy)+m_allaer(:,:,id_AIPOMM_phy))*1.e-9
   concbc(:,:)=(m_allaer(:,:,id_ASBCM_phy)+m_allaer(:,:,id_AIBCM_phy))*1.e-9
Index: /LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90	(revision 2408)
@@ -6,5 +6,6 @@
 
     USE phys_cal_mod, ONLY : mth_cur
-    USE mod_grid_phy_lmdz
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, &
+                                 grid2dto1d_glo
     USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
     USE mod_phys_lmdz_para 
@@ -17,5 +18,4 @@
 
     include "YOMCST.h"
-    include "dimensions.h"
 
 ! Variable input
@@ -85,6 +85,6 @@
     n_lat = size(latitude)
     print *, 'LAT aerosol strato=', n_lat, latitude
-    IF (n_lat.NE.jjm+1) THEN 
-       print *,'Le nombre de lat n est pas egal a jjm+1'
+    IF (n_lat.NE.nbp_lat) THEN 
+       print *,'Le nombre de lat n est pas egal a nbp_lat'
        STOP
     ENDIF
@@ -94,6 +94,6 @@
     n_lon = size(longitude)
     print *, 'LON aerosol strato=', n_lon, longitude
-    IF (n_lon.NE.iim) THEN 
-       print *,'Le nombre de lon n est pas egal a iim'
+    IF (n_lon.NE.nbp_lon) THEN 
+       print *,'Le nombre de lon n est pas egal a nbp_lon'
        STOP
     ENDIF
Index: /LMDZ5/branches/testing/libf/phylmd/readchlorophyll.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/readchlorophyll.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/readchlorophyll.F90	(revision 2408)
@@ -10,15 +10,13 @@
 
     USE phys_cal_mod, ONLY : mth_cur
-    USE mod_grid_phy_lmdz
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, &
+                                 grid2dto1d_glo
     USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    USE mod_phys_lmdz_para 
-    USE phys_state_var_mod
-    USE phys_local_var_mod
-    USE dimphy
+    USE mod_phys_lmdz_para, ONLY: scatter 
+    USE phys_state_var_mod, ONLY: chl_con
 
     implicit none
 
     include "YOMCST.h"
-    include "dimensions.h"
 
 ! Variable input
@@ -62,6 +60,6 @@
     n_lon = size(longitude)
 !    print *, 'LON chlorophyll=', n_lon, longitude
-    IF (n_lon.NE.iim) THEN
-       print *,'Le nombre de lon n est pas egal a iim'
+    IF (n_lon.NE.nbp_lon) THEN
+       print *,'Le nombre de lon n est pas egal a nbp_lon'
        STOP
     ENDIF
@@ -72,6 +70,6 @@
     n_lat = size(latitude)
 !    print *, 'LAT chlorophyll=', n_lat, latitude
-    IF (n_lat.NE.jjm+1) THEN 
-       print *,'Le nombre de lat n est pas egal a jjm+1'
+    IF (n_lat.NE.nbp_lat) THEN 
+       print *,'Le nombre de lat n est pas egal a jnbp_lat'
        STOP
     ENDIF
@@ -93,5 +91,5 @@
     CALL nf95_inq_varid(ncid_in, "CHL", varid)
     ncerr = nf90_get_var(ncid_in, varid, chlorocon)
-    print *,'code erreur readaerosolstrato=', ncerr, varid
+    print *,'code erreur readchlorophyll=', ncerr, varid
 
     CALL nf95_close(ncid_in)
@@ -99,5 +97,5 @@
 !---select the correct month
     IF (mth_cur.LT.1.OR.mth_cur.GT.12) THEN
-      print *,'probleme avec le mois dans readaerosolstrat =', mth_cur
+      print *,'probleme avec le mois dans readchlorophyll =', mth_cur
     ENDIF
     chlorocon_mois(:,:) = chlorocon(:,:,mth_cur)
@@ -109,5 +107,7 @@
     print*,"chrolophyll current month",mth_cur
     do i=1,klon_glo
-      if(isnan(chlorocon_mois_glo(i)))then
+!      if(isnan(chlorocon_mois_glo(i)))then ! isnan() is not in the Fortran standard...
+!      Another way to check for NaN:
+       if(chlorocon_mois_glo(i).ne.chlorocon_mois_glo(i)) then
          chlorocon_mois_glo(i)=0.
       endif
Index: /LMDZ5/branches/testing/libf/phylmd/regr_lat_time_climoz_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/regr_lat_time_climoz_m.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/regr_lat_time_climoz_m.F90	(revision 2408)
@@ -66,4 +66,5 @@
     ! year.
 
+    use mod_grid_phy_lmdz, ONLY : nbp_lat
     use regr1_step_av_m, only: regr1_step_av
     use regr3_lint_m, only: regr3_lint
@@ -73,4 +74,6 @@
     use netcdf, only: nf90_get_att, nf90_get_var, nf90_noerr, nf90_nowrite
     use assert_m, only: assert
+    use regular_lonlat_mod, only : boundslat_reg, south
+    use nrtype, only: pi
 
     integer, intent(in):: read_climoz ! read ozone climatology
@@ -81,13 +84,4 @@
 
     ! Variables local to the procedure:
-
-    include "dimensions.h"
-    ! (for "jjm")
-    include "paramet.h"
-    ! (for the other included files)
-    include "comgeom2.h"
-    ! (for "rlatv")
-    include "comconst.h"
-    ! (for "pi")
 
     integer n_plev ! number of pressure levels in the input data
@@ -289,6 +283,6 @@
     call nf95_close(ncid_in)
 
-    allocate(o3_regr_lat(jjm + 1, n_plev, 0:13, read_climoz))
-    allocate(o3_out(jjm + 1, n_plev, 360, read_climoz))
+    allocate(o3_regr_lat(nbp_lat, n_plev, 0:13, read_climoz))
+    allocate(o3_out(nbp_lat, n_plev, 360, read_climoz))
 
     ! Regrid in latitude:
@@ -298,6 +292,6 @@
        print *, &
             "Found 12 months in ozone climatologies, assuming periodicity..."
-       o3_regr_lat(jjm+1:1:-1, :, 1:12, :) = regr1_step_av(o3_in, &
-            xs=sin(lat_in_edg), xt=sin((/- pi / 2, rlatv(jjm:1:-1), pi / 2/)))
+       o3_regr_lat(nbp_lat:1:-1, :, 1:12, :) = regr1_step_av(o3_in, &
+            xs=sin(lat_in_edg), xt=sin((/- pi / 2, boundslat_reg(nbp_lat-1:1:-1,south), pi / 2/)))
        ! (invert order of indices in "o3_regr_lat" because "rlatu" is
        ! in descending order)
@@ -309,6 +303,6 @@
     else
        print *, "Using 14 months in ozone climatologies..."
-       o3_regr_lat(jjm+1:1:-1, :, :, :) = regr1_step_av(o3_in, &
-            xs=sin(lat_in_edg), xt=sin((/- pi / 2, rlatv(jjm:1:-1), pi / 2/)))
+       o3_regr_lat(nbp_lat:1:-1, :, :, :) = regr1_step_av(o3_in, &
+            xs=sin(lat_in_edg), xt=sin((/- pi / 2, boundslat_reg(nbp_lat-1:1:-1,south), pi / 2/)))
        ! (invert order of indices in "o3_regr_lat" because "rlatu" is
        ! in descending order)
@@ -320,5 +314,5 @@
     ! Write to file:
     do m = 1, read_climoz
-       call nf95_put_var(ncid_out, varid_out(m), o3_out(jjm+1:1:-1, :, :, m))
+       call nf95_put_var(ncid_out, varid_out(m), o3_out(nbp_lat:1:-1, :, :, m))
        ! (The order of "rlatu" is inverted in the output file)
     end do
@@ -336,7 +330,10 @@
     ! dimensions and variables, and writes one of the coordinate variables.
 
+    use mod_grid_phy_lmdz, ONLY : nbp_lat
     use netcdf95, only: nf95_create, nf95_def_dim, nf95_def_var, &
          nf95_put_att, nf95_enddef, nf95_copy_att, nf95_put_var
     use netcdf, only: nf90_clobber, nf90_float, nf90_global
+    use nrtype, only: pi
+    use regular_lonlat_mod, only : lat_reg
 
     integer, intent(in):: ncid_in, n_plev
@@ -349,13 +346,4 @@
     ! Variables local to the procedure:
 
-    include "dimensions.h"
-    ! (for "jjm")
-    include "paramet.h"
-    ! (for the other included files)
-    include "comgeom2.h"
-    ! (for "rlatu")
-    include "comconst.h"
-    ! (for "pi")
-
     integer ncerr
     integer dimid_rlatu, dimid_plev, dimid_time
@@ -371,5 +359,5 @@
     call nf95_def_dim(ncid_out, "time", 360, dimid_time)
     call nf95_def_dim(ncid_out, "plev", n_plev, dimid_plev)
-    call nf95_def_dim(ncid_out, "rlatu", jjm + 1, dimid_rlatu)
+    call nf95_def_dim(ncid_out, "rlatu", nbp_lat, dimid_rlatu)
 
     ! Define coordinate variables:
@@ -432,5 +420,5 @@
 
     ! Write one of the coordinate variables:
-    call nf95_put_var(ncid_out, varid_rlatu, rlatu(jjm+1:1:-1) / pi * 180.)
+    call nf95_put_var(ncid_out, varid_rlatu, lat_reg(nbp_lat:1:-1) / pi * 180.)
     ! (convert from rad to degrees and sort in ascending order)
 
Index: /LMDZ5/branches/testing/libf/phylmd/regr_lat_time_coefoz_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/regr_lat_time_coefoz_m.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/regr_lat_time_coefoz_m.F90	(revision 2408)
@@ -40,4 +40,5 @@
     ! when we regrid in pressure).
 
+    use mod_grid_phy_lmdz, ONLY : nbp_lat
     use regr1_step_av_m, only: regr1_step_av
     use regr3_lint_m, only: regr3_lint
@@ -45,14 +46,8 @@
          nf95_put_var, nf95_gw_var
     use netcdf, only: nf90_nowrite, nf90_get_var
+    use nrtype, only: pi
+    use regular_lonlat_mod, only: boundslat_reg, south
 
     ! Variables local to the procedure:
-
-    include "dimensions.h"
-    ! (for "jjm")
-    include "paramet.h"
-    include "comgeom2.h"
-    ! (for "rlatv")
-    include "comconst.h"
-    ! (for "pi")
 
     integer ncid_in, ncid_out ! NetCDF IDs for input and output files
@@ -164,5 +159,5 @@
     call nf95_inq_varid(ncid_in, "latitude", varid)
     call nf95_gw_var(ncid_in, varid, latitude)
-    ! Convert from degrees to rad, because "rlatv" is in rad:
+    ! Convert from degrees to rad, because "boundslat_reg" is in rad:
     latitude = latitude / 180. * pi
     n_lat = size(latitude)
@@ -200,6 +195,6 @@
 
     allocate(o3_par_in(n_lat, n_plev, 12))
-    allocate(v_regr_lat(jjm + 1, n_plev, 0:13))
-    allocate(o3_par_out(jjm + 1, n_plev, 360))
+    allocate(v_regr_lat(nbp_lat, n_plev, 0:13))
+    allocate(o3_par_out(nbp_lat, n_plev, 360))
 
     do i_v = 1, n_o3_param
@@ -214,6 +209,6 @@
        ! We average with respect to sine of latitude, which is
        ! equivalent to weighting by cosine of latitude:
-       v_regr_lat(jjm+1:1:-1, :, 1:12) = regr1_step_av(o3_par_in, &
-            xs=sin(lat_in_edg), xt=sin((/- pi / 2, rlatv(jjm:1:-1), pi / 2/)))
+       v_regr_lat(nbp_lat:1:-1, :, 1:12) = regr1_step_av(o3_par_in, &
+            xs=sin(lat_in_edg), xt=sin((/- pi / 2, boundslat_reg(nbp_lat-1:1:-1,south), pi / 2/)))
        ! (invert order of indices in "v_regr_lat" because "rlatu" is
        ! in descending order)
@@ -229,5 +224,5 @@
        ! Write to file:
        call nf95_put_var(ncid_out, varid_out(i_v), &
-            o3_par_out(jjm+1:1:-1, :, :))
+            o3_par_out(nbp_lat:1:-1, :, :))
        ! (The order of "rlatu" is inverted in the output file)
     end do
@@ -246,4 +241,5 @@
     ! dimensions and variables, and writes one of the coordinate variables.
 
+    use mod_grid_phy_lmdz, ONLY : nbp_lat
     use assert_eq_m, only: assert_eq
 
@@ -251,4 +247,6 @@
          nf95_put_att, nf95_enddef, nf95_copy_att, nf95_put_var
     use netcdf, only: nf90_clobber, nf90_float, nf90_copy_att, nf90_global
+    use nrtype, only: pi
+    use regular_lonlat_mod, only : lat_reg
 
     integer, intent(in):: ncid_in, varid_in(:), n_plev
@@ -257,12 +255,4 @@
 
     ! Variables local to the procedure:
-
-    include "dimensions.h"
-    ! (for "jjm")
-    include "paramet.h"
-    include "comgeom2.h"
-    ! (for "rlatu")
-    include "comconst.h"
-    ! (for "pi")
 
     integer ncerr
@@ -282,5 +272,5 @@
     call nf95_def_dim(ncid_out, "time", 360, dimid_time)
     call nf95_def_dim(ncid_out, "plev", n_plev, dimid_plev)
-    call nf95_def_dim(ncid_out, "rlatu", jjm + 1, dimid_rlatu)
+    call nf95_def_dim(ncid_out, "rlatu", nbp_lat, dimid_rlatu)
 
     ! Define coordinate variables:
@@ -332,5 +322,5 @@
 
     ! Write one of the coordinate variables:
-    call nf95_put_var(ncid_out, varid_rlatu, rlatu(jjm+1:1:-1) / pi * 180.)
+    call nf95_put_var(ncid_out, varid_rlatu, lat_reg(nbp_lat:1:-1) / pi * 180.)
     ! (convert from rad to degrees and sort in ascending order)
 
Index: /LMDZ5/branches/testing/libf/phylmd/regr_pr_av_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/regr_pr_av_m.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/regr_pr_av_m.F90	(revision 2408)
@@ -40,5 +40,5 @@
     use regr1_step_av_m, only: regr1_step_av
     use mod_phys_lmdz_mpi_data, only: is_mpi_root
-
+    use mod_grid_phy_lmdz, only: nbp_lon, nbp_lat, nbp_lev
     use mod_phys_lmdz_transfert_para, only: scatter2d
     ! (pack to the LMDZ horizontal "physics" grid and scatter)
@@ -63,8 +63,7 @@
     ! Variables local to the procedure:
 
-    include "dimensions.h"
     integer varid, ncerr ! for NetCDF
 
-    real  v1(iim, jjm + 1, size(press_in_edg) - 1, size(name))
+    real  v1(nbp_lon, nbp_lat, size(press_in_edg) - 1, size(name))
     ! input fields at day "julien", on the global "dynamics" horizontal grid
     ! First dimension is for longitude.
@@ -84,7 +83,7 @@
     !--------------------------------------------
 
-    call assert(size(v3, 1) == klon, size(v3, 2) == llm, "regr_pr_av v3 klon")
+    call assert(size(v3, 1) == klon, size(v3, 2) == nbp_lev, "regr_pr_av v3 klon")
     n_var = assert_eq(size(name), size(v3, 3), "regr_pr_av v3 n_var")
-    call assert(shape(paprs) == (/klon, llm+1/), "regr_pr_av paprs")
+    call assert(shape(paprs) == (/klon, nbp_lev+1/), "regr_pr_av paprs")
 
     !$omp master
@@ -102,8 +101,8 @@
        ! Latitudes are in ascending order in the input file while
        ! "rlatu" is in descending order so we need to invert order:
-       v1(1, :, :, :) = v1(1, jjm+1:1:-1, :, :)
+       v1(1, :, :, :) = v1(1, nbp_lat:1:-1, :, :)
 
        ! Duplicate on all longitudes:
-       v1(2:, :, :, :) = spread(v1(1, :, :, :), dim=1, ncopies=iim-1)
+       v1(2:, :, :, :) = spread(v1(1, :, :, :), dim=1, ncopies=nbp_lon-1)
     end if
     !$omp end master
@@ -113,6 +112,6 @@
     ! Regrid in pressure at each horizontal position:
     do i = 1, klon
-       v3(i, llm:1:-1, :) = regr1_step_av(v2(i, :, :), press_in_edg, &
-            paprs(i, llm+1:1:-1))
+       v3(i, nbp_lev:1:-1, :) = regr1_step_av(v2(i, :, :), press_in_edg, &
+            paprs(i, nbp_lev+1:1:-1))
        ! (invert order of indices because "paprs" is in descending order)
     end do
Index: /LMDZ5/branches/testing/libf/phylmd/regr_pr_comb_coefoz_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/regr_pr_comb_coefoz_m.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/regr_pr_comb_coefoz_m.F90	(revision 2408)
@@ -40,7 +40,7 @@
 
     use dimphy, only: klon
+    use mod_grid_phy_lmdz, only: nbp_lev
 
     ! Variables local to the procedure:
-    include "dimensions.h"
 
     !---------------------------------------
@@ -49,6 +49,6 @@
     print *, "Call sequence information: alloc_coefoz"
     !$omp end master
-    allocate(c_Mob(klon, llm), a2(klon, llm), a4_mass(klon, llm))
-    allocate(a6_mass(klon, llm), r_het_interm(klon, llm))
+    allocate(c_Mob(klon, nbp_lev), a2(klon, nbp_lev), a4_mass(klon, nbp_lev))
+    allocate(a6_mass(klon, nbp_lev), r_het_interm(klon, nbp_lev))
 
   end subroutine alloc_coefoz
@@ -79,4 +79,5 @@
     use regr_pr_int_m, only: regr_pr_int
     use press_coefoz_m, only: press_in_edg, plev
+    use mod_grid_phy_lmdz, only: nbp_lev
 
     integer, intent(in):: julien ! jour julien, 1 <= julien <= 360
@@ -85,16 +86,15 @@
     ! (latitude on the partial "physics" grid, in degrees)
 
-    real, intent(in):: paprs(:, :) ! (klon, llm + 1)
+    real, intent(in):: paprs(:, :) ! (klon, nbp_lev + 1)
     ! (pression pour chaque inter-couche, en Pa)
 
-    real, intent(in):: pplay(:, :) ! (klon, llm)
+    real, intent(in):: pplay(:, :) ! (klon, nbp_lev)
     ! (pression pour le mileu de chaque couche, en Pa)
 
     ! Variables local to the procedure:
 
-    include "dimensions.h"
     integer ncid ! for NetCDF
 
-    real coefoz(klon, llm, 7)
+    real coefoz(klon, nbp_lev, 7)
     ! (temporary storage for 7 ozone coefficients)
     ! (On the partial "physics" grid.
@@ -102,5 +102,5 @@
     ! middle of layer "k".)
 
-    real a6(klon, llm)
+    real a6(klon, nbp_lev)
     ! (derivative of "P_net_Mob" with respect to column-density of ozone
     ! above, in cm2 s-1)
@@ -121,6 +121,6 @@
     call assert((/size(rlat), size(paprs, 1), size(pplay, 1)/) == klon, &
          "regr_pr_comb_coefoz klon")
-    call assert((/size(paprs, 2) - 1, size(pplay, 2)/) == llm, &
-         "regr_pr_comb_coefoz llm")
+    call assert((/size(paprs, 2) - 1, size(pplay, 2)/) == nbp_lev, &
+         "regr_pr_comb_coefoz nbp_lev")
 
     !$omp master
@@ -150,5 +150,5 @@
     r_het_interm = coefoz(:, :, 7)
     ! Heterogeneous chemistry is only at high latitudes:
-    forall (k = 1: llm)
+    forall (k = 1: nbp_lev)
        where (abs(rlat) <= 45.) r_het_interm(:, k) = 0.
     end forall
Index: /LMDZ5/branches/testing/libf/phylmd/regr_pr_int_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/regr_pr_int_m.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/regr_pr_int_m.F90	(revision 2408)
@@ -30,5 +30,5 @@
     use regr1_lint_m, only: regr1_lint
     use mod_phys_lmdz_mpi_data, only: is_mpi_root
-
+    use mod_grid_phy_lmdz, only: nbp_lon, nbp_lat, nbp_lev
     use mod_phys_lmdz_transfert_para, only: scatter2d
     ! (pack to the LMDZ horizontal "physics" grid and scatter)
@@ -41,5 +41,5 @@
     ! (pressure level of input data, in Pa, in strictly ascending order)
 
-    real, intent(in):: pplay(:, :) ! (klon, llm)
+    real, intent(in):: pplay(:, :) ! (klon, nbp_lev)
     ! (pression pour le mileu de chaque couche, en Pa)
 
@@ -47,5 +47,5 @@
     ! (extra value of field at 0 pressure)
 
-    real, intent(out):: v3(:, :) ! (klon, llm)
+    real, intent(out):: v3(:, :) ! (klon, nbp_lev)
     ! (regridded field on the partial "physics" grid)
     ! ("v3(i, k)" is at longitude "xlon(i)", latitude
@@ -54,8 +54,7 @@
     ! Variables local to the procedure:
 
-    include "dimensions.h"
     integer varid, ncerr ! for NetCDF
 
-    real  v1(iim, jjm + 1, 0:size(plev))
+    real  v1(nbp_lon, nbp_lat, 0:size(plev))
     ! (input field at day "julien", on the global "dynamics" horizontal grid)
     ! (First dimension is for longitude.
@@ -72,6 +71,6 @@
     !--------------------------------------------
 
-    call assert(shape(v3) == (/klon, llm/), "regr_pr_int v3")
-    call assert(shape(pplay) == (/klon, llm/), "regr_pr_int pplay")
+    call assert(shape(v3) == (/klon, nbp_lev/), "regr_pr_int v3")
+    call assert(shape(pplay) == (/klon, nbp_lev/), "regr_pr_int pplay")
 
     !$omp master
@@ -84,5 +83,5 @@
        ! Latitudes are in ascending order in the input file while
        ! "rlatu" is in descending order so we need to invert order:
-       v1(1, :, 1:) = v1(1, jjm+1:1:-1, 1:)
+       v1(1, :, 1:) = v1(1, nbp_lat:1:-1, 1:)
 
        ! Complete "v1" with the value at 0 pressure:
@@ -90,5 +89,5 @@
 
        ! Duplicate on all longitudes:
-       v1(2:, :, :) = spread(v1(1, :, :), dim=1, ncopies=iim-1)
+       v1(2:, :, :) = spread(v1(1, :, :), dim=1, ncopies=nbp_lon-1)
     end if
     !$omp end master
@@ -98,5 +97,5 @@
     ! Regrid in pressure at each horizontal position:
     do i = 1, klon
-       v3(i, llm:1:-1) = regr1_lint(v2(i, :), (/0., plev/), pplay(i, llm:1:-1))
+       v3(i, nbp_lev:1:-1) = regr1_lint(v2(i, :), (/0., plev/), pplay(i, nbp_lev:1:-1))
        ! (invert order of indices because "pplay" is in descending order)
     end do
Index: /LMDZ5/branches/testing/libf/phylmd/regr_pr_o3_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/regr_pr_o3_m.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/regr_pr_o3_m.F90	(revision 2408)
@@ -30,5 +30,6 @@
     use regr1_step_av_m, only: regr1_step_av
     use press_coefoz_m, only: press_in_edg
-    use control_mod, only: dayref
+    use time_phylmdz_mod, only: day_ref
+    use mod_grid_phy_lmdz, only: nbp_lon, nbp_lat, nbp_lev
 
     REAL, intent(in):: p3d(:, :, :) ! pressure at layer interfaces, in Pa
@@ -43,11 +44,9 @@
     ! Variables local to the procedure:
 
-    include "dimensions.h"
-
     integer ncid, varid, ncerr ! for NetCDF
     integer i, j
 
-    real r_mob(jjm + 1, size(press_in_edg) - 1)
-    ! (ozone mole fraction from Mobidic at day "dayref")
+    real r_mob(nbp_lat, size(press_in_edg) - 1)
+    ! (ozone mole fraction from Mobidic at day "day_ref")
     ! (r_mob(j, k) is at latitude "rlatu(j)", in pressure interval
     ! "[press_in_edg(k), press_in_edg(k+1)]".)
@@ -56,7 +55,7 @@
 
     print *, "Call sequence information: regr_pr_o3"
-    call assert(shape(o3_mob_regr) == (/iim + 1, jjm + 1, llm/), &
+    call assert(shape(o3_mob_regr) == (/nbp_lon + 1, nbp_lat, nbp_lev/), &
          "regr_pr_o3 o3_mob_regr")
-    call assert(shape(p3d) == (/iim + 1, jjm + 1, llm + 1/), "regr_pr_o3 p3d")
+    call assert(shape(p3d) == (/nbp_lon + 1, nbp_lat, nbp_lev + 1/), "regr_pr_o3 p3d")
 
     call nf95_open("coefoz_LMDZ.nc", nf90_nowrite, ncid)
@@ -64,9 +63,9 @@
     call nf95_inq_varid(ncid, "r_Mob", varid)
     ! Get data at the right day from the input file:
-    ncerr = nf90_get_var(ncid, varid, r_mob, start=(/1, 1, dayref/))
+    ncerr = nf90_get_var(ncid, varid, r_mob, start=(/1, 1, day_ref/))
     call handle_err("nf90_get_var r_Mob", ncerr)
     ! Latitudes are in ascending order in the input file while
     ! "rlatu" is in descending order so we need to invert order:
-    r_mob = r_mob(jjm+1:1:-1, :)
+    r_mob = r_mob(nbp_lat:1:-1, :)
 
     call nf95_close(ncid)
@@ -75,16 +74,16 @@
 
     ! Poles:
-    do j = 1, jjm + 1, jjm
-       o3_mob_regr(1, j, llm:1:-1) &
-            = regr1_step_av(r_mob(j, :), press_in_edg, p3d(1, j, llm+1:1:-1))
+    do j = 1, nbp_lat, nbp_lat-1
+       o3_mob_regr(1, j, nbp_lev:1:-1) &
+            = regr1_step_av(r_mob(j, :), press_in_edg, p3d(1, j, nbp_lev+1:1:-1))
        ! (invert order of indices because "p3d" is in descending order)
     end do
 
     ! Other latitudes:
-    do j = 2, jjm
-       do i = 1, iim
-          o3_mob_regr(i, j, llm:1:-1) &
+    do j = 2, nbp_lat-1
+       do i = 1, nbp_lon
+          o3_mob_regr(i, j, nbp_lev:1:-1) &
                = regr1_step_av(r_mob(j, :), press_in_edg, &
-               p3d(i, j, llm+1:1:-1))
+               p3d(i, j, nbp_lev+1:1:-1))
              ! (invert order of indices because "p3d" is in descending order)
        end do
@@ -92,10 +91,10 @@
 
     ! Duplicate pole values on all longitudes:
-    o3_mob_regr(2:, 1, :) = spread(o3_mob_regr(1, 1, :), dim=1, ncopies=iim)
-    o3_mob_regr(2:, jjm + 1, :) &
-         = spread(o3_mob_regr(1, jjm + 1, :), dim=1, ncopies=iim)
+    o3_mob_regr(2:, 1, :) = spread(o3_mob_regr(1, 1, :), dim=1, ncopies=nbp_lon)
+    o3_mob_regr(2:, nbp_lat, :) &
+         = spread(o3_mob_regr(1, nbp_lat, :), dim=1, ncopies=nbp_lon)
 
     ! Duplicate first longitude to last longitude:
-    o3_mob_regr(iim + 1, 2:jjm, :) = o3_mob_regr(1, 2:jjm, :)
+    o3_mob_regr(nbp_lon + 1, 2:nbp_lat-1, :) = o3_mob_regr(1, 2:nbp_lat-1, :)
 
   end subroutine regr_pr_o3
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/aeropt_6bands_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/aeropt_6bands_rrtm.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/aeropt_6bands_rrtm.F90	(revision 2408)
@@ -22,5 +22,4 @@
 
   INCLUDE "YOMCST.h"
-  INCLUDE "iniprint.h"
   INCLUDE "clesphys.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosol_optic_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosol_optic_rrtm.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosol_optic_rrtm.F90	(revision 2408)
@@ -288,8 +288,6 @@
   ! Calculate the total mass of all soluble aersosols
   ! to be revisited for AR6
-  mass_solu_aero(:,:)    = sulfacc(:,:)    + bcsol(:,:)    + pomsol(:,:)   + nitracc(:,:)   ! + & 
-  !                           sscoarse(:,:)    + ssacu(:,:)    + sssupco(:,:) 
-  mass_solu_aero_pi(:,:) = sulfacc_pi(:,:) + bcsol_pi(:,:) + pomsol_pi(:,:) + nitracc_pi(:,:) ! + &
-  !                           sscoarse_pi(:,:) + ssacu_pi(:,:) + sssupco_pi(:,:)
+  mass_solu_aero(:,:)    = sulfacc(:,:)    + bcsol(:,:)    + pomsol(:,:)   + nitracc(:,:) + ssacu(:,:)
+  mass_solu_aero_pi(:,:) = sulfacc_pi(:,:) + bcsol_pi(:,:) + pomsol_pi(:,:) + nitracc_pi(:,:) + ssacu_pi(:,:) 
 
   !****************************************************************************************
@@ -303,4 +301,5 @@
   END DO
 
+!--new aerosol properties
   ! aeropt_6bands for rrtm
   CALL aeropt_6bands_rrtm( &
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato_rrtm.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato_rrtm.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato_rrtm.F90	(revision 2408)
@@ -9,5 +9,5 @@
 
     USE phys_cal_mod, ONLY : mth_cur
-    USE mod_grid_phy_lmdz
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo
     USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
     USE mod_phys_lmdz_para 
@@ -21,5 +21,4 @@
 
     include "YOMCST.h"
-    include "dimensions.h"
 
 ! Variable input
@@ -103,6 +102,6 @@
     n_lat = size(latitude)
     print *, 'LAT aerosol strato=', n_lat, latitude
-    IF (n_lat.NE.jjm+1) THEN 
-       print *,'Le nombre de lat n est pas egal a jjm+1'
+    IF (n_lat.NE.nbp_lat) THEN 
+       print *,'Le nombre de lat n est pas egal a nbp_lat'
        STOP
     ENDIF
@@ -112,6 +111,6 @@
     n_lon = size(longitude)
     print *, 'LON aerosol strato=', n_lon, longitude
-    IF (n_lon.NE.iim) THEN 
-       print *,'Le nombre de lon n est pas egal a iim'
+    IF (n_lon.NE.nbp_lon) THEN 
+       print *,'Le nombre de lon n est pas egal a nbp_lon'
        STOP
     ENDIF
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/rrtm_rtrn1a_140gp.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/rrtm_rtrn1a_140gp.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/rrtm_rtrn1a_140gp.F90	(revision 2408)
@@ -496,5 +496,5 @@
 !    Z_FACCMB2D(I_LEV-1) = Z_FACCLD1D(I_LEV-1) * Z_FACCLR2D(I_LEV) *&
 !     & (1.0_JPRB - Z_CLDFRAC(I_LEV+1))  
-    if (istcldd(i_lev).ne.1) then
+    if (istcldd(i_lev).ne.1.and.i_lev.ne.0) then
        z_faccmb1d(i_lev-1) = max(0.,min(z_cldfrac(i_lev+1)-z_cldfrac(i_lev), &
                             z_cldfrac(i_lev-1)-z_cldfrac(i_lev)))
Index: /LMDZ5/branches/testing/libf/phylmd/rrtm/suphec.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/rrtm/suphec.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/rrtm/suphec.F90	(revision 2408)
@@ -87,4 +87,5 @@
 USE YOM_PHYS_GRID ,ONLY : PHYS_GRID
 USE YOMCT0  , ONLY  : LSCMEC   ,LROUGH   ,REXTZ0M  ,REXTZ0H
+USE vertical_layers_mod, ONLY: ap,bp
 
 IMPLICIT NONE
@@ -114,6 +115,4 @@
 #include "suvdfs.intfb.h"
 #include "suwcou.intfb.h"
-#include "dimensions.h"
-#include "comvert.h"
 
 !     ------------------------------------------------------------------
@@ -168,6 +167,4 @@
 !ALLOCATE(VBH    (0:MAX(JPMXLE,NFLEVG)))  from suallo.F90
 !! 
-!! ATTENTION, il faut que ~dyn3d/comvert.h soit conforme au Fortran 90 !!
-!! 
 ALLOCATE(VAH    (0:NFLEVG))  ! Ajout ALLOCATE MPL 200509
 ALLOCATE(VBH    (0:NFLEVG))
@@ -177,5 +174,5 @@
 VP00=101325.     !!!!! A REVOIR (MPL)
 ZPRES(NFLEVG)=VP00
-! on recupere ap et bp de dyn3d (comvert.h) MPL 19.05.09
+! on recupere ap et bp de dyn3d (vertical_layers_mod) MPL 19.05.09
 ! Attention, VAH et VBH sont inverses, comme les niveaux
 ! plev(l)=PAPRS(klon,nlayer+1-l) de 1 a nlayer (apllmd.F)
Index: /LMDZ5/branches/testing/libf/phylmd/sisvat/surf_sisvat_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/sisvat/surf_sisvat_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/sisvat/surf_sisvat_mod.F90	(revision 2408)
@@ -1188,5 +1188,4 @@
     USE VARxSV          
     USE VARtSV
-    USE control_mod
     USE indice_sol_mod
 
@@ -1201,5 +1200,4 @@
     include "dimsoil.h"
     include "clesphys.h"
-    include "temps.h"
     include "thermcell.h"
     include "compbl.h"
@@ -1500,5 +1498,4 @@
     USE VARySV !hj tmp 12 03 2010
     USE VARtSV
-    USE control_mod
     USE indice_sol_mod
 
@@ -1509,5 +1506,4 @@
     include "dimsoil.h"
     include "clesphys.h" 
-    include "temps.h"
     include "thermcell.h"
     include "compbl.h"
Index: /LMDZ5/branches/testing/libf/phylmd/soil.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/soil.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/soil.F90	(revision 2408)
@@ -8,4 +8,5 @@
   USE mod_phys_lmdz_para
   USE indice_sol_mod
+  USE print_control_mod, ONLY: lunout
 
   IMPLICIT NONE
@@ -55,5 +56,4 @@
   INCLUDE "dimsoil.h"
   INCLUDE "comsoil.h"
-  INCLUDE "iniprint.h"
 !-----------------------------------------------------------------------
 ! Arguments
@@ -178,5 +178,5 @@
   ELSE
      WRITE(lunout,*) "valeur d indice non prevue", indice
-     call abort_gcm("soil", "", 1)
+     call abort_physic("soil", "", 1)
   ENDIF
 
Index: /LMDZ5/branches/testing/libf/phylmd/solarlong.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/solarlong.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/solarlong.F90	(revision 2408)
@@ -2,4 +2,5 @@
 
   USE ioipsl
+  USE print_control_mod, ONLY: lunout
 
   IMPLICIT NONE
@@ -46,5 +47,4 @@
   include "planete.h"
   include "YOMCST.h"
-  include 'iniprint.h'
 
   ! arguments:
Index: DZ5/branches/testing/libf/phylmd/statto.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/statto.h	(revision 2407)
+++ 	(revision )
@@ -1,34 +1,0 @@
-
-!  statto:
-!     This include file controls the production of statistics.
-!     Some variables could be set in a namelist, but it is easier to
-!     do it here since arrays can then be dimensioned using parameters
-!     and values shouldn't have to change too often.   SRL
-
-!     Calculate stats every istats physics timesteps, starting at first
-!     call.  If istats=0 then don't do statistics at all.  Check value
-!     if number of physics timesteps changes.
-	integer istats
-
-!     Calculate itime independent sums and sums of squares,
-!     example, istat=1,istime=1 gives a single time mean
-	integer, parameter :: istime=12
-
-!     Number of 2D and 3D variables on which to do statistics.
-	integer n2dvar, n3dvar
-	parameter (n2dvar = 8, n3dvar = 5)
-
-!     Units for writing stats header and data
-	integer usdata
-
-!     count tab to know the variable record
-        integer count(istime)
-
-!     Record of the number of stores made for each time.
-	integer nstore(istime)
-
-! Size of the "controle" array
-        integer, parameter :: cntrlsize=15
-
-!       common /sttcom/ dummy,nstore,istats,usdata
-        common /sttcom/ nstore,istats,usdata,count
Index: /LMDZ5/branches/testing/libf/phylmd/surf_land_bucket_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/surf_land_bucket_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/surf_land_bucket_mod.F90	(revision 2408)
@@ -24,5 +24,5 @@
     USE cpl_mod
     USE dimphy
-    USE comgeomphy
+    USE geometry_mod, ONLY: latitude 
     USE mod_grid_phy_lmdz
     USE mod_phys_lmdz_para
@@ -99,5 +99,5 @@
     CALL calbeta(dtime, is_ter, knon, snow, qsol, beta, capsol, dif_grnd)
     if (type_veget=='betaclim') then
-       CALL calbeta_clim(knon,jour,rlatd(knindex(1:knon)),beta)
+       CALL calbeta_clim(knon,jour,latitude(knindex(1:knon)),beta)
     endif
        
Index: /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_mod.F90	(revision 2408)
@@ -16,7 +16,7 @@
   USE cpl_mod,      ONLY : cpl_send_land_fields
   USE surface_data, ONLY : type_ocean
-  USE comgeomphy,   ONLY : cuphy, cvphy
+  USE geometry_mod, ONLY : dx, dy
   USE mod_grid_phy_lmdz
-  USE mod_phys_lmdz_para, mpi_root_rank=>mpi_root
+  USE mod_phys_lmdz_para, mpi_root_rank=>mpi_master
 
   IMPLICIT NONE
@@ -45,5 +45,9 @@
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
     USE indice_sol_mod
-
+    USE print_control_mod, ONLY: lunout
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
+#ifdef CPP_VEGET
+    USE time_phylmdz_mod, ONLY: itau_phy 
+#endif
 !    
 ! Cette routine sert d'interface entre le modele atmospherique et le 
@@ -98,8 +102,5 @@
 !   qsurf        air moisture at surface
 !
-    INCLUDE "temps.h"
     INCLUDE "YOMCST.h"
-    INCLUDE "iniprint.h"
-    INCLUDE "dimensions.h"
   
 !
@@ -210,5 +211,5 @@
 #ifndef CPP_VEGET
        abort_message='Pb de coherence: ok_veget = .true. mais CPP_VEGET = .false.'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
 #endif
 
@@ -230,5 +231,5 @@
        DO igrid = 2, klon - 1
           indi = indi + 1
-          IF ( indi > iim) THEN
+          IF ( indi > nbp_lon) THEN
              indi = 1
              indj = indj + 1
@@ -238,5 +239,5 @@
        ENDDO
        ig(klon) = 1
-       jg(klon) = jjm + 1
+       jg(klon) = nbp_lat
 
        IF ((.NOT. ALLOCATED(lalo))) THEN
@@ -244,19 +245,19 @@
           IF (error /= 0) THEN
              abort_message='Pb allocation lalo'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
        IF ((.NOT. ALLOCATED(lon_scat))) THEN
-          ALLOCATE(lon_scat(iim,jjm+1), stat = error)
+          ALLOCATE(lon_scat(nbp_lon,nbp_lat), stat = error)
           IF (error /= 0) THEN
              abort_message='Pb allocation lon_scat'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
        IF ((.NOT. ALLOCATED(lat_scat))) THEN
-          ALLOCATE(lat_scat(iim,jjm+1), stat = error)
+          ALLOCATE(lat_scat(nbp_lon,nbp_lat), stat = error)
           IF (error /= 0) THEN
              abort_message='Pb allocation lat_scat'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
@@ -276,6 +277,6 @@
        IF (is_mpi_root) THEN
           index = 1
-          DO jj = 2, jjm
-             DO ij = 1, iim
+          DO jj = 2, nbp_lat-1
+             DO ij = 1, nbp_lon
                 index = index + 1
                 lon_scat(ij,jj) = rlon_g(index)
@@ -285,6 +286,6 @@
           lon_scat(:,1) = lon_scat(:,2)
           lat_scat(:,1) = rlat_g(1)
-          lon_scat(:,jjm+1) = lon_scat(:,2)
-          lat_scat(:,jjm+1) = rlat_g(klon_glo)
+          lon_scat(:,nbp_lat) = lon_scat(:,2)
+          lat_scat(:,nbp_lat) = rlat_g(klon_glo)
        ENDIF
    
@@ -298,5 +299,5 @@
           IF (error /= 0) THEN
              abort_message='Pb allocation neighbours'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
@@ -306,5 +307,5 @@
           IF (error /= 0) THEN
              abort_message='Pb allocation contfrac'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
@@ -324,11 +325,11 @@
           IF (error /= 0) THEN
              abort_message='Pb allocation resolution'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
        DO igrid = 1, knon
           ij = knindex(igrid)
-          resolution(igrid,1) = cuphy(ij)
-          resolution(igrid,2) = cvphy(ij)
+          resolution(igrid,1) = dx(ij)
+          resolution(igrid,2) = dy(ij)
        ENDDO
      
@@ -336,5 +337,5 @@
        IF (error /= 0) THEN
           abort_message='Pb allocation coastalflow'
-          CALL abort_gcm(modname,abort_message,1)
+          CALL abort_physic(modname,abort_message,1)
        ENDIF
        
@@ -342,5 +343,5 @@
        IF (error /= 0) THEN
           abort_message='Pb allocation riverflow'
-          CALL abort_gcm(modname,abort_message,1)
+          CALL abort_physic(modname,abort_message,1)
        ENDIF
 !
@@ -349,5 +350,5 @@
        IF (carbon_cycle_cpl) THEN
           abort_message='carbon_cycle_cpl not yet possible with this interface of ORCHIDEE'
-          CALL abort_gcm(modname,abort_message,1)
+          CALL abort_physic(modname,abort_message,1)
        END IF
        
@@ -396,5 +397,5 @@
 
 #ifdef CPP_VEGET
-          CALL intersurf_main (itime+itau_phy-1, iim, jjm+1, knon, ktindex, dtime, &
+          CALL intersurf_main (itime+itau_phy-1, nbp_lon, nbp_lat, knon, ktindex, dtime, &
                lrestart_read, lrestart_write, lalo, &
                contfrac, neighbours, resolution, date0, &
@@ -420,5 +421,5 @@
     IF (knon > 0) THEN
 #ifdef CPP_VEGET    
-       CALL intersurf_main (itime+itau_phy, iim, jjm+1, knon, ktindex, dtime,  &
+       CALL intersurf_main (itime+itau_phy, nbp_lon, nbp_lat, knon, ktindex, dtime,  &
             lrestart_read, lrestart_write, lalo, &
             contfrac, neighbours, resolution, date0, &
Index: /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noopenmp_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noopenmp_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noopenmp_mod.F90	(revision 2408)
@@ -21,5 +21,5 @@
   USE cpl_mod,      ONLY : cpl_send_land_fields
   USE surface_data, ONLY : type_ocean
-  USE comgeomphy,   ONLY : cuphy, cvphy
+  USE geometry_mod, ONLY : dx, dy
   USE mod_grid_phy_lmdz
   USE mod_phys_lmdz_para
@@ -98,10 +98,12 @@
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, fco2_land_inst, fco2_lu_inst
     USE indice_sol_mod
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
+    USE print_control_mod, ONLY: lunout
+#ifdef CPP_VEGET
+    USE time_phylmdz_mod, ONLY: itau_phy 
+#endif
     IMPLICIT NONE
 
-    INCLUDE "temps.h"
     INCLUDE "YOMCST.h"
-    INCLUDE "iniprint.h"
-    INCLUDE "dimensions.h"
   
 !
@@ -215,5 +217,5 @@
        IF (carbon_cycle_cpl) THEN
           abort_message='You must define preprossing key ORCH_NEW when running carbon_cycle_cpl=y'
-          CALL abort_gcm(modname,abort_message,1)
+          CALL abort_physic(modname,abort_message,1)
        END IF
 #endif
@@ -232,5 +234,5 @@
        DO igrid = 2, klon - 1
           indi = indi + 1
-          IF ( indi > iim) THEN
+          IF ( indi > nbp_lon) THEN
              indi = 1
              indj = indj + 1
@@ -240,5 +242,5 @@
        ENDDO
        ig(klon) = 1
-       jg(klon) = jjm + 1
+       jg(klon) = nbp_lat
 
        IF ((.NOT. ALLOCATED(lalo))) THEN
@@ -246,19 +248,19 @@
           IF (error /= 0) THEN
              abort_message='Pb allocation lalo'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
        IF ((.NOT. ALLOCATED(lon_scat))) THEN
-          ALLOCATE(lon_scat(iim,jjm+1), stat = error)
+          ALLOCATE(lon_scat(nbp_lon,nbp_lat), stat = error)
           IF (error /= 0) THEN
              abort_message='Pb allocation lon_scat'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
        IF ((.NOT. ALLOCATED(lat_scat))) THEN
-          ALLOCATE(lat_scat(iim,jjm+1), stat = error)
+          ALLOCATE(lat_scat(nbp_lon,nbp_lat), stat = error)
           IF (error /= 0) THEN
              abort_message='Pb allocation lat_scat'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
@@ -278,6 +280,6 @@
        IF (is_mpi_root) THEN
           index = 1
-          DO jj = 2, jjm
-             DO ij = 1, iim
+          DO jj = 2, nbp_lat-1
+             DO ij = 1, nbp_lon
                 index = index + 1
                 lon_scat(ij,jj) = rlon_g(index)
@@ -287,6 +289,6 @@
           lon_scat(:,1) = lon_scat(:,2)
           lat_scat(:,1) = rlat_g(1)
-          lon_scat(:,jjm+1) = lon_scat(:,2)
-          lat_scat(:,jjm+1) = rlat_g(klon_glo)
+          lon_scat(:,nbp_lat) = lon_scat(:,2)
+          lat_scat(:,nbp_lat) = rlat_g(klon_glo)
        ENDIF
 
@@ -301,5 +303,5 @@
           IF (error /= 0) THEN
              abort_message='Pb allocation neighbours'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
@@ -309,5 +311,5 @@
           IF (error /= 0) THEN
              abort_message='Pb allocation contfrac'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
@@ -327,11 +329,11 @@
           IF (error /= 0) THEN
              abort_message='Pb allocation resolution'
-             CALL abort_gcm(modname,abort_message,1)
+             CALL abort_physic(modname,abort_message,1)
           ENDIF
        ENDIF
        DO igrid = 1, knon
           ij = knindex(igrid)
-          resolution(igrid,1) = cuphy(ij)
-          resolution(igrid,2) = cvphy(ij)
+          resolution(igrid,1) = dx(ij)
+          resolution(igrid,2) = dy(ij)
        ENDDO
      
@@ -339,5 +341,5 @@
        IF (error /= 0) THEN
           abort_message='Pb allocation coastalflow'
-          CALL abort_gcm(modname,abort_message,1)
+          CALL abort_physic(modname,abort_message,1)
        ENDIF
        
@@ -345,5 +347,5 @@
        IF (error /= 0) THEN
           abort_message='Pb allocation riverflow'
-          CALL abort_gcm(modname,abort_message,1)
+          CALL abort_physic(modname,abort_message,1)
        ENDIF
 
@@ -359,12 +361,12 @@
        IF (carbon_cycle_cpl) THEN
           ALLOCATE(fco2_land_inst(klon),stat=error)
-          IF (error /= 0)  CALL abort_gcm(modname,'Pb in allocation fco2_land_inst',1)
+          IF (error /= 0)  CALL abort_physic(modname,'Pb in allocation fco2_land_inst',1)
           
           ALLOCATE(fco2_lu_inst(klon),stat=error)
-          IF(error /=0) CALL abort_gcm(modname,'Pb in allocation fco2_lu_inst',1)
+          IF(error /=0) CALL abort_physic(modname,'Pb in allocation fco2_lu_inst',1)
        END IF
 
        ALLOCATE(fields_cpl(klon,nb_fields_cpl), stat = error)
-       IF (error /= 0) CALL abort_gcm(modname,'Pb in allocation fields_cpl',1)
+       IF (error /= 0) CALL abort_physic(modname,'Pb in allocation fields_cpl',1)
 
     ENDIF                          ! (fin debut) 
@@ -399,9 +401,9 @@
 !  if (pole_nord) then 
 !    offset=0
-!    ktindex(:)=ktindex(:)+iim-1
+!    ktindex(:)=ktindex(:)+nbp_lon-1
 !  else
-!    offset = klon_mpi_begin-1+iim-1
-!    ktindex(:)=ktindex(:)+MOD(offset,iim)
-!    offset=offset-MOD(offset,iim)
+!    offset = klon_mpi_begin-1+nbp_lon-1
+!    ktindex(:)=ktindex(:)+MOD(offset,nbp_lon)
+!    offset=offset-MOD(offset,nbp_lon)
 !  endif
   
@@ -413,5 +415,5 @@
 #ifndef CPP_MPI
           ! Interface for ORCHIDEE compiled in sequential mode(without preprocessing flag CPP_MPI)
-          CALL intersurf_main (itime+itau_phy-1, iim, jjm+1, knon, ktindex, dtime, &
+          CALL intersurf_main (itime+itau_phy-1, nbp_lon, nbp_lat, knon, ktindex, dtime, &
                lrestart_read, lrestart_write, lalo, &
                contfrac, neighbours, resolution, date0, &
@@ -430,5 +432,5 @@
 #else          
           ! Interface for ORCHIDEE version 1.9 or later(1.9.2, 1.9.3, 1.9.4, 1.9.5) compiled in parallel mode(with preprocessing flag CPP_MPI)
-          CALL intersurf_main (itime+itau_phy-1, iim, jjm+1, offset, knon, ktindex, & 
+          CALL intersurf_main (itime+itau_phy-1, nbp_lon, nbp_lat, offset, knon, ktindex, & 
                orch_comm, dtime, lrestart_read, lrestart_write, lalo, &
                contfrac, neighbours, resolution, date0, &
@@ -458,5 +460,5 @@
 #ifndef CPP_MPI
        ! Interface for ORCHIDEE compiled in sequential mode(without preprocessing flag CPP_MPI)
-       CALL intersurf_main (itime+itau_phy, iim, jjm+1, knon, ktindex, dtime, &
+       CALL intersurf_main (itime+itau_phy, nbp_lon, nbp_lat, knon, ktindex, dtime, &
             lrestart_read, lrestart_write, lalo, &
             contfrac, neighbours, resolution, date0, &
@@ -474,5 +476,5 @@
 #else
        ! Interface for ORCHIDEE version 1.9 or later compiled in parallel mode(with preprocessing flag CPP_MPI)
-       CALL intersurf_main (itime+itau_phy, iim, jjm+1,offset, knon, ktindex, & 
+       CALL intersurf_main (itime+itau_phy, nbp_lon, nbp_lat,offset, knon, ktindex, & 
             orch_comm,dtime, lrestart_read, lrestart_write, lalo, &
             contfrac, neighbours, resolution, date0, &
@@ -530,5 +532,5 @@
   SUBROUTINE Init_orchidee_index(knon,orch_comm,knindex,offset,ktindex)
     
-    INCLUDE "dimensions.h"
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
 
 #ifdef CPP_MPI
@@ -563,5 +565,5 @@
 !****************************************************************************************
 
-    MyLastPoint=klon_mpi_begin-1+knindex(knon)+iim-1
+    MyLastPoint=klon_mpi_begin-1+knindex(knon)+nbp_lon-1
     
     IF (is_parallel) THEN
@@ -592,8 +594,8 @@
        offset=0
     ELSE
-       offset=LastPoint-MOD(LastPoint,iim)
-    ENDIF
-    
-    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin+iim-1)-offset-1	
+       offset=LastPoint-MOD(LastPoint,nbp_lon)
+    ENDIF
+    
+    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin+nbp_lon-1)-offset-1	
     
 
@@ -635,6 +637,6 @@
     
     USE indice_sol_mod
-
-    INCLUDE "dimensions.h"
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
+
 #ifdef CPP_MPI
     INCLUDE 'mpif.h'
@@ -662,5 +664,5 @@
     INTEGER, DIMENSION(8)                :: offset  
     INTEGER, DIMENSION(knon)             :: ktindex_p
-    INTEGER, DIMENSION(iim,jjm+1)        :: correspond
+    INTEGER, DIMENSION(nbp_lon,nbp_lat)        :: correspond
     INTEGER, ALLOCATABLE, DIMENSION(:)   :: ktindex_g
     INTEGER, ALLOCATABLE, DIMENSION(:,:) :: neighbours_g
@@ -695,5 +697,5 @@
    ENDIF
     
-    ktindex_p(1:knon)=ktindex(1:knon)+klon_mpi_begin-1+iim-1
+    ktindex_p(1:knon)=ktindex(1:knon)+klon_mpi_begin-1+nbp_lon-1
     
     IF (is_sequential) THEN
@@ -714,15 +716,15 @@
 !
 ! offset bord ouest
-       off_ini(1,1) = - iim  ; off_ini(2,1) = - iim + 1; off_ini(3,1) = 1
-       off_ini(4,1) = iim + 1; off_ini(5,1) = iim      ; off_ini(6,1) = 2 * iim - 1
-       off_ini(7,1) = iim -1 ; off_ini(8,1) = - 1
+       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) = - iim  ; off_ini(2,2) = - iim + 1; off_ini(3,2) = 1
-       off_ini(4,2) = iim + 1; off_ini(5,2) = iim      ; off_ini(6,2) = iim - 1
-       off_ini(7,2) = -1     ; off_ini(8,2) = - iim - 1
+       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) = - iim; off_ini(2,3) = - 2 * iim + 1; off_ini(3,3) = - iim + 1
-       off_ini(4,3) =  1   ; off_ini(5,3) = iim          ; off_ini(6,3) = iim - 1
-       off_ini(7,3) = -1   ; off_ini(8,3) = - iim - 1
+       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
 !
 !
@@ -731,6 +733,6 @@
        DO igrid = 1, knon_g
           index = ktindex_g(igrid)
-          jj = INT((index - 1)/iim) + 1
-          ij = index - (jj - 1) * iim
+          jj = INT((index - 1)/nbp_lon) + 1
+          ij = index - (jj - 1) * nbp_lon
           correspond(ij,jj) = igrid
        ENDDO
@@ -738,7 +740,7 @@
        DO igrid = 1, knon_g
           iglob = ktindex_g(igrid)
-          IF (MOD(iglob, iim) == 1) THEN
+          IF (MOD(iglob, nbp_lon) == 1) THEN
              offset = off_ini(:,1)
-          ELSE IF(MOD(iglob, iim) == 0) THEN
+          ELSE IF(MOD(iglob, nbp_lon) == 0) THEN
              offset = off_ini(:,3)
           ELSE
@@ -747,8 +749,8 @@
           DO i = 1, 8
              index = iglob + offset(i)
-             ireal = (MIN(MAX(1, index - iim + 1), klon_glo))
+             ireal = (MIN(MAX(1, index - nbp_lon + 1), klon_glo))
              IF (pctsrf_g(ireal) > EPSFRA) THEN
-                jj = INT((index - 1)/iim) + 1
-                ij = index - (jj - 1) * iim
+                jj = INT((index - 1)/nbp_lon) + 1
+                ij = index - (jj - 1) * nbp_lon
                 neighbours_g(igrid, i) = correspond(ij, jj)
              ENDIF
Index: /LMDZ5/branches/testing/libf/phylmd/surf_landice_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/surf_landice_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/surf_landice_mod.F90	(revision 2408)
@@ -209,5 +209,5 @@
 #else
        abort_message='Pb de coherence: ok_snow = .true. mais CPP_SISVAT = .false.'
-       CALL abort_gcm(modname,abort_message,1)
+       CALL abort_physic(modname,abort_message,1)
 #endif
     ELSE ! ok_snow=FALSE
Index: /LMDZ5/branches/testing/libf/phylmd/surf_ocean_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/surf_ocean_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/surf_ocean_mod.F90	(revision 2408)
@@ -20,10 +20,11 @@
        flux_u1, flux_v1)
 
-  USE dimphy
+  use albedo, only: alboc, alboc_cd
+  USE dimphy, ONLY: klon, zmasq
   USE surface_data, ONLY     : type_ocean
   USE ocean_forced_mod, ONLY : ocean_forced_noice
   USE ocean_slab_mod, ONLY   : ocean_slab_noice
   USE ocean_cpl_mod, ONLY    : ocean_cpl_noice
-  USE indice_sol_mod
+  USE indice_sol_mod, ONLY : nbsrf, is_oce
 !
 ! This subroutine will make a call to ocean_XXX_noice according to the ocean mode (force, 
@@ -91,4 +92,5 @@
     REAL, DIMENSION(klon) :: radsol
     REAL, DIMENSION(klon) :: cdragq ! Cdrag pour l'evaporation
+    CHARACTER(len=20),PARAMETER :: modname="surf_ocean"
 
 ! End definition
@@ -216,5 +218,5 @@
     ENDDO
 ELSE
-       STOP'version non prevue'
+       CALL abort_physic(modname,'version non prevue',1)
 ENDIF
 !
Index: /LMDZ5/branches/testing/libf/phylmd/sw_aeroAR4.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/sw_aeroAR4.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/sw_aeroAR4.F90	(revision 2408)
@@ -22,9 +22,10 @@
   USE dimphy
   USE phys_output_mod, ONLY : swaero_diag
+  USE print_control_mod, ONLY: lunout
+  USE aero_mod, ONLY : naero_grp
   IMPLICIT NONE
 
 #include "YOMCST.h"
 #include "clesphys.h"
-#include "iniprint.h"
   !
   !     ------------------------------------------------------------------
@@ -140,7 +141,7 @@
   LOGICAL flag_aerosol_strat ! use stratospehric aerosols
   INTEGER flag_aerosol      ! global flag for aerosol 0 (no aerosol) or 1-5 (aerosols)
-  REAL(KIND=8) tauaero(kdlon,kflev,9,2)  ! aerosol optical properties
-  REAL(KIND=8) pizaero(kdlon,kflev,9,2)  ! (see aeropt.F)
-  REAL(KIND=8) cgaero(kdlon,kflev,9,2)   ! -"-
+  REAL(KIND=8) tauaero(kdlon,kflev,naero_grp,2)  ! aerosol optical properties
+  REAL(KIND=8) pizaero(kdlon,kflev,naero_grp,2)  ! (see aeropt.F)
+  REAL(KIND=8) cgaero(kdlon,kflev,naero_grp,2)   ! -"-
   REAL(KIND=8) PTAUA(KDLON,2,KFLEV)    ! CLOUD OPTICAL THICKNESS (present-day value)
   REAL(KIND=8) POMEGAA(KDLON,2,KFLEV)  ! SINGLE SCATTERING ALBEDO
Index: DZ5/branches/testing/libf/phylmd/test_disvert_m.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/test_disvert_m.F90	(revision 2407)
+++ 	(revision )
@@ -1,70 +1,0 @@
-module test_disvert_m
-
-  implicit none
-
-contains
-
-  subroutine test_disvert
-
-    ! Author: Lionel GUEZ
-
-    ! This procedure tests the order of pressure values at half-levels
-    ! and full levels. We arbitrarily choose to test ngrid values of
-    ! the surface pressure, which sample possible values on Earth.
-
-    use exner_hyb_m, only: exner_hyb
-
-    ! For llm:
-    include "dimensions.h"
-
-    ! For ap, bp, preff:
-    include "comvert.h"
-
-    ! For kappa, cpp:
-    include "comconst.h"
-
-    ! Local:
-    integer l, i
-    integer, parameter:: ngrid = 7
-    real p(ngrid, llm + 1) ! pressure at half-level, in Pa
-    real pks(ngrid) ! exner function at the surface, in J K-1 kg-1 
-    real pk(ngrid, llm) ! exner function at full level, in J K-1 kg-1 
-    real ps(ngrid) ! surface pressure, in Pa
-    real p_lay(ngrid, llm) ! pressure at full level, in Pa
-    real delta_ps ! in Pa
-
-    !---------------------
-
-    print *, "Call sequence information: test_disvert"
-
-    delta_ps = 6e4 / (ngrid - 1)
-    ps = (/(5e4 + delta_ps * i, i = 0, ngrid - 1)/)
-    forall (l = 1: llm + 1) p(:, l) = ap(l) + bp(l) * ps
-    call exner_hyb(ngrid, ps, p, pks, pk)
-    p_lay = preff * (pk / cpp)**(1. / kappa)
-
-    ! Are pressure values in the right order?
-    if (any(p(:, :llm) <= p_lay .or. p_lay <= p(:, 2:))) then
-       ! List details and stop:
-       do l = 1, llm
-          do i = 1, ngrid
-             if (p(i, l) <= p_lay(i, l)) then
-                print 1000, "ps = ", ps(i) / 100., "hPa, p(level ",  l, &
-                     ") = ", p(i, l) / 100., " hPa <= p(layer ", l, ") = ", &
-                     p_lay(i, l) / 100., " hPa"
-             end if
-             if (p_lay(i, l) <= p(i, l + 1)) then
-                print 1000, "ps = ", ps(i) / 100., "hPa, p(layer ", l, ") = ", &
-                     p_lay(i, l) / 100., " hPa <= p(level ", l + 1, ") = ", &
-                     p(i, l + 1) / 100., " hPa"
-             end if
-          end do
-       end do
-       call abort_gcm("test_disvert", "bad order of pressure values", 1)
-    end if
-
-1000 format (3(a, g10.4, a, i0))
-
-  end subroutine test_disvert
-
-end module test_disvert_m
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell.F90	(revision 2408)
@@ -34,6 +34,4 @@
   ! -------------
 
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
   include "YOMCST.h"
 
@@ -766,5 +764,5 @@
       IF (fracd(ig,l)<0.1) THEN
         abort_message = 'fracd trop petit'
-        CALL abort_gcm(modname, abort_message, 1)
+        CALL abort_physic(modname, abort_message, 1)
 
       ELSE
@@ -998,6 +996,4 @@
   IMPLICIT NONE
 
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
   include "YOMCST.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/thermcellV0_main.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcellV0_main.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcellV0_main.F90	(revision 2408)
@@ -13,5 +13,5 @@
 
       USE dimphy
-      USE comgeomphy , ONLY:rlond,rlatd
+      USE print_control_mod, ONLY: prt_level,lunout
       IMPLICIT NONE
 
@@ -41,9 +41,7 @@
 !   -------------
 
-      include "dimensions.h"
       include "YOMCST.h"
       include "YOETHF.h"
       include "FCTTRE.h"
-      include "iniprint.h"
 
 !   arguments:
@@ -465,5 +463,5 @@
       if (.not. (f0(1).ge.0.) ) then
         abort_message = 'Dans thermcell_main f0(1).lt.0 '
-        CALL abort_gcm (modname,abort_message,1)
+        CALL abort_physic (modname,abort_message,1)
       endif
 
@@ -591,5 +589,5 @@
            zcon2(ig)=zlay(ig,nlay)-(pcon(ig)-pplay(ig,nlay))/(RG*rho(ig,nlay))/100.
            abort_message = 'thermcellV0_main: les thermiques vont trop haut '
-           CALL abort_gcm (modname,abort_message,1)
+           CALL abort_physic (modname,abort_message,1)
         endif
       enddo
@@ -790,6 +788,6 @@
 
       subroutine testV0_ltherm(klon,klev,pplev,pplay,long,seuil,ztv,po,ztva,zqla,f_star,zw2,comment)
+      USE print_control_mod, ONLY: prt_level
       IMPLICIT NONE
-      include "iniprint.h"
 
       integer i, k, klon,klev
@@ -833,7 +831,7 @@
 !thermcell_closure: fermeture, determination de f
 !-------------------------------------------------------------------------
+      USE print_control_mod, ONLY: prt_level,lunout
       IMPLICIT NONE
 
-      include "iniprint.h"
       include "thermcell.h"
       INTEGER ngrid,nlay
@@ -880,5 +878,5 @@
                 print*,'wmax_sec',wmax_sec(ig)
                 abort_message = 'zdenom<1.e-14'
-                CALL abort_gcm (modname,abort_message,1)
+                CALL abort_physic (modname,abort_message,1)
              endif
              if ((zmax_sec(ig).gt.1.e-10).and.(iflag_thermals_ed.eq.0)) then 
@@ -913,4 +911,5 @@
 !--------------------------------------------------------------------------
 
+      USE print_control_mod, ONLY: prt_level
       IMPLICIT NONE
 
@@ -918,5 +917,4 @@
       include "YOETHF.h"
       include "FCTTRE.h"
-      include "iniprint.h"
       include "thermcell.h"
 
@@ -1711,7 +1709,7 @@
 !thermcell_dry: calcul de zmax et wmax du thermique sec
 !--------------------------------------------------------------------------
+       USE print_control_mod, ONLY: prt_level
        IMPLICIT NONE
       include "YOMCST.h"       
-      include "iniprint.h"
        INTEGER l,ig
 
@@ -1923,6 +1921,6 @@
 !thermcell_init: calcul du profil d alimentation du thermique
 !----------------------------------------------------------------------
+      USE print_control_mod, ONLY: prt_level
       IMPLICIT NONE
-      include "iniprint.h"
       include "thermcell.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_alim.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_alim.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_alim.F90	(revision 2408)
@@ -0,0 +1,121 @@
+!
+! $Id: thermcell_plume.F90 2311 2015-06-25 07:45:24Z emillour $
+!
+      SUBROUTINE thermcell_alim(flag,ngrid,klev,ztv,d_temp,zlev,alim_star,lalim)
+IMPLICIT NONE
+
+!--------------------------------------------------------------------------
+! FH : 2015/11/06
+! thermcell_alim: calcule la distribution verticale de l'alimentation 
+! laterale a la base des panaches thermiques
+!--------------------------------------------------------------------------
+
+#include "YOMCST.h"
+#include "YOETHF.h"
+#include "FCTTRE.h"
+#include "thermcell.h"
+
+!      fort(10) ptimestep,ztv,zthl,po,zl,rhobarz,zlev,pplev,pphi,zpspsk,f0
+      INTEGER, INTENT(IN) :: ngrid,klev
+      REAL, INTENT(IN) :: ztv(ngrid,klev)
+      REAL, INTENT(IN) :: d_temp(ngrid)
+      REAL, INTENT(IN) :: zlev(ngrid,klev+1)
+      REAL, INTENT(OUT) :: alim_star(ngrid,klev)
+      INTEGER, INTENT(OUT) :: lalim(ngrid)
+      INTEGER, INTENT(IN) :: flag
+
+      REAL :: alim_star_tot(ngrid),zi(ngrid),zh(ngrid)
+      REAL :: zlay(ngrid,klev)
+      REAL ztv_parcel
+
+      INTEGER ig,l
+
+      REAL h,z,falim
+      falim(h,z)=0.2*((z-h)**5+h**5)
+
+
+!===================================================================
+
+   lalim(:)=1
+   alim_star_tot(:)=0.
+
+   IF (ngrid==1) PRINT*,'NEW ALIM flag=',flag
+
+!-------------------------------------------------------------------------
+! Definition de l'alimentation a l'origine dans thermcell_init
+!-------------------------------------------------------------------------
+   IF (flag==0) THEN ! CMIP5 version
+      do l=1,klev-1
+         do ig=1,ngrid
+            if (ztv(ig,l)> ztv(ig,l+1) .and. ztv(ig,1)>=ztv(ig,l) ) then
+               alim_star(ig,l)=MAX((ztv(ig,l)-ztv(ig,l+1)),0.)  &
+     &                       *sqrt(zlev(ig,l+1)) 
+               lalim(ig)=l+1
+               alim_star_tot(ig)=alim_star_tot(ig)+alim_star(ig,l)
+            endif
+         enddo
+      enddo
+      do l=1,klev
+         do ig=1,ngrid 
+            if (alim_star_tot(ig) > 1.e-10 ) then
+               alim_star(ig,l)=alim_star(ig,l)/alim_star_tot(ig)
+            endif
+         enddo
+      enddo
+      alim_star_tot(:)=1.
+
+!-------------------------------------------------------------------------
+! Nouvelle definition avec possibilite d'introduire un DT en surface
+! On suppose que la forme du profile d'alimentation scale avec la hauteur
+! d'inversion calculée avec une particule partant de la premieere couche
+
+! Fonction  f(z) = z ( h - z ) , avec h = zi/3
+! On utilise l'integralle
+! Int_0^z f(z') dz' = z^2 ( h/2 - z/3 ) = falim(h,z)
+! Pour calculer l'alimentation des couches
+!-------------------------------------------------------------------------
+   ELSE
+! Computing inversion height zi and zh=zi/3.
+      zi(:)=0.
+! Il faut recalculer zlay qui n'est pas dispo dans thermcell_plume
+! A changer eventuellement.
+      do l=1,klev
+         zlay(:,l)=0.5*(zlev(:,l)+zlev(:,l+1))
+      enddo
+
+      do l=1,klev-1
+         do ig=1,ngrid
+            ztv_parcel=ztv(ig,1)+d_temp(ig)
+            if (ztv_parcel<ztv(ig,l+1) .and. lalim(ig)==1 ) THEN
+                lalim(ig)=l
+                zi(ig)=zlay(ig,l)+(zlay(ig,l+1)-zlay(ig,l))/(ztv(ig,l+1)-ztv(ig,l))*(ztv_parcel-ztv(ig,l))
+                IF (zi(ig)<0.) STOP
+            endif
+         enddo
+      enddo
+      zh(:)=zi(:)/2.
+      alim_star_tot(:)=0.
+      alim_star(:,:)=0.
+      lalim(:)=0
+      do l=1,klev-1
+         do ig=1,ngrid
+            if (zlev(ig,l+1)<=zh(ig)) THEN
+               alim_star(ig,l)=(falim(zh(ig),zlev(ig,l+1))-falim(zh(ig),zlev(ig,l)))/falim(zh(ig),zh(ig))
+               lalim(ig)=l
+            ELSE IF (zlev(ig,l)<=zh(ig)) THEN
+               alim_star(ig,l)=(falim(zh(ig),zh(ig))-falim(zh(ig),zlev(ig,l)))/falim(zh(ig),zh(ig))
+               lalim(ig)=l
+            ELSE
+               alim_star(ig,l)=0.
+            ENDIF
+         ENDDO
+         alim_star_tot(:)=alim_star_tot(:)+alim_star(:,l)
+      ENDDO
+      IF (ngrid==1) print*,'NEW ALIM CALCUL DE ZI ',alim_star_tot
+      alim_star_tot(:)=1.
+
+   ENDIF
+
+
+RETURN
+END
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_alp.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_alp.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_alp.F90	(revision 2408)
@@ -0,0 +1,475 @@
+! $Id: thermcell_main.F90 2351 2015-08-25 15:14:59Z emillour $
+!
+      SUBROUTINE thermcell_alp(ngrid,nlay,ptimestep  &
+     &                  ,pplay,pplev  &
+     &                  ,fm0,entr0,lmax  &
+     &                  ,ale_bl,alp_bl,lalim_conv,wght_th &
+     &                  ,zw2,fraca &
+!!! ncessaire en plus
+     &                  ,pcon,rhobarz,wth3,wmax_sec,lalim,fm,alim_star,zmax &
+!!! nrlmd le 10/04/2012
+     &                  ,pbl_tke,pctsrf,omega,airephy &
+     &                  ,zlcl,fraca0,w0,w_conv,therm_tke_max0,env_tke_max0 &
+     &                  ,n2,s2,ale_bl_stat &
+     &                  ,therm_tke_max,env_tke_max &
+     &                  ,alp_bl_det,alp_bl_fluct_m,alp_bl_fluct_tke &
+     &                  ,alp_bl_conv,alp_bl_stat &
+!!! fin nrlmd le 10/04/2012
+     &)
+
+      USE dimphy
+      USE indice_sol_mod
+      IMPLICIT NONE
+
+!=======================================================================
+!   Auteurs: Frederic Hourdin, Catherine Rio, Anne Mathieu
+!   Version du 09.02.07
+!   Calcul du transport vertical dans la couche limite en presence
+!   de "thermiques" explicitement representes avec processus nuageux
+!
+!   Reecriture a partir d'un listing papier a Habas, le 14/02/00
+!
+!   le thermique est suppose homogene et dissipe par melange avec
+!   son environnement. la longueur l_mix controle l'efficacite du
+!   melange
+!
+!   Le calcul du transport des differentes especes se fait en prenant
+!   en compte:
+!     1. un flux de masse montant
+!     2. un flux de masse descendant
+!     3. un entrainement
+!     4. un detrainement
+!
+! Modif 2013/01/04 (FH hourdin@lmd.jussieu.fr)
+!    Introduction of an implicit computation of vertical advection in
+!    the environment of thermal plumes in thermcell_dq
+!    impl =     0 : explicit, 1 : implicit, -1 : old version
+!    controled by iflag_thermals =
+!       15, 16 run with impl=-1 : numerical convergence with NPv3
+!       17, 18 run with impl=1  : more stable
+!    15 and 17 correspond to the activation of the stratocumulus "bidouille"
+!
+!=======================================================================
+!-----------------------------------------------------------------------
+!   declarations:
+!   -------------
+
+#include "YOMCST.h"
+#include "YOETHF.h"
+#include "FCTTRE.h"
+#include "thermcell.h"
+
+!   arguments:
+!   ----------
+
+!IM 140508
+
+      INTEGER ngrid,nlay
+      real ptimestep
+      REAL pplay(ngrid,nlay),pplev(ngrid,nlay+1)
+
+!   local:
+!   ------
+
+
+      REAL susqr2pi, reuler
+
+      INTEGER ig,k,l
+      INTEGER lmax(klon),lalim(klon)
+      real zmax(klon),zw2(klon,klev+1)
+
+!on garde le zmax du pas de temps precedent
+
+
+      real fraca(klon,klev+1)
+      real wth3(klon,klev)
+! FH probleme de dimensionnement avec l'allocation dynamique
+!     common/comtherm/thetath2,wth2
+      real rhobarz(klon,klev)
+
+      real wmax_sec(klon)
+      real fm0(klon,klev+1),entr0(klon,klev)
+      real fm(klon,klev+1)
+
+!niveau de condensation
+      real pcon(klon)
+
+      real alim_star(klon,klev)
+
+!!! nrlmd le 10/04/2012
+
+!------Entrées
+      real pbl_tke(klon,klev+1,nbsrf)
+      real pctsrf(klon,nbsrf)
+      real omega(klon,klev)
+      real airephy(klon)
+!------Sorties
+      real zlcl(klon),fraca0(klon),w0(klon),w_conv(klon)
+      real therm_tke_max0(klon),env_tke_max0(klon)
+      real n2(klon),s2(klon)
+      real ale_bl_stat(klon)
+      real therm_tke_max(klon,klev),env_tke_max(klon,klev)
+      real alp_bl_det(klon),alp_bl_fluct_m(klon),alp_bl_fluct_tke(klon),alp_bl_conv(klon),alp_bl_stat(klon)
+!------Local
+      integer nsrf
+      real rhobarz0(klon)                    ! Densité au LCL
+      logical ok_lcl(klon)                   ! Existence du LCL des thermiques
+      integer klcl(klon)                     ! Niveau du LCL
+      real interp(klon)                      ! Coef d'interpolation pour le LCL
+!--Triggering
+      real Su                                ! Surface unité: celle d'un updraft élémentaire
+      parameter(Su=4e4)
+      real hcoef                             ! Coefficient directeur pour le calcul de s2
+      parameter(hcoef=1)
+      real hmincoef                          ! Coefficient directeur pour l'ordonnée à l'origine pour le calcul de s2 
+      parameter(hmincoef=0.3)
+      real eps1                              ! Fraction de surface occupée par la population 1 : eps1=n1*s1/(fraca0*Sd)
+      parameter(eps1=0.3)
+      real hmin(ngrid)                       ! Ordonnée à l'origine pour le calcul de s2
+      real zmax_moy(ngrid)                   ! Hauteur moyenne des thermiques : zmax_moy = zlcl + 0.33 (zmax-zlcl)
+      real zmax_moy_coef
+      parameter(zmax_moy_coef=0.33)
+      real depth(klon)                       ! Epaisseur moyenne du cumulus
+      real w_max(klon)                       ! Vitesse max statistique 
+      real s_max(klon)
+!--Closure
+      real pbl_tke_max(klon,klev)            ! Profil de TKE moyenne 
+      real pbl_tke_max0(klon)                ! TKE moyenne au LCL
+      real w_ls(klon,klev)                   ! Vitesse verticale grande échelle (m/s)
+      real coef_m                            ! On considère un rendement pour alp_bl_fluct_m
+      parameter(coef_m=1.)
+      real coef_tke                          ! On considère un rendement pour alp_bl_fluct_tke
+      parameter(coef_tke=1.)
+
+!!! fin nrlmd le 10/04/2012
+
+!
+      !nouvelles variables pour la convection
+      real ale_bl(klon)
+      real alp_bl(klon)
+      real alp_int(klon),dp_int(klon),zdp
+      real fm_tot(klon)
+      real wght_th(klon,klev)
+      integer lalim_conv(klon)
+!v1d     logical therm
+!v1d     save therm
+
+
+!------------------------------------------------------------
+!  Initialize output arrays related to stochastic triggering
+!------------------------------------------------------------
+  DO ig = 1,klon
+     zlcl(ig) = 0.
+     fraca0(ig) = 0.
+     w0(ig) = 0.
+     w_conv(ig) = 0.
+     therm_tke_max0(ig) = 0.
+     env_tke_max0(ig) = 0.
+     n2(ig) = 0.
+     s2(ig) = 0.
+     ale_bl_stat(ig) = 0.
+     alp_bl_det(ig) = 0.
+     alp_bl_fluct_m(ig) = 0.
+     alp_bl_fluct_tke(ig) = 0.
+     alp_bl_conv(ig) = 0.
+     alp_bl_stat(ig) = 0.
+  ENDDO
+  DO l = 1,klev
+    DO ig = 1,klon
+     therm_tke_max(ig,l) = 0.
+     env_tke_max(ig,l) = 0.
+    ENDDO
+  ENDDO
+!------------------------------------------------------------
+
+
+!------------Test sur le LCL des thermiques
+    do ig=1,ngrid
+      ok_lcl(ig)=.false.
+      if ( (pcon(ig) .gt. pplay(ig,klev-1)) .and. (pcon(ig) .lt. pplay(ig,1)) ) ok_lcl(ig)=.true.
+    enddo
+
+!------------Localisation des niveaux entourant le LCL et du coef d'interpolation
+    do l=1,nlay-1
+      do ig=1,ngrid
+        if (ok_lcl(ig)) then 
+!ATTENTION,zw2 calcule en pplev
+!          if ((pplay(ig,l) .ge. pcon(ig)) .and. (pplay(ig,l+1) .le. pcon(ig))) then
+!          klcl(ig)=l
+!          interp(ig)=(pcon(ig)-pplay(ig,klcl(ig)))/(pplay(ig,klcl(ig)+1)-pplay(ig,klcl(ig)))
+!          endif
+          if ((pplev(ig,l) .ge. pcon(ig)) .and. (pplev(ig,l+1) .le. pcon(ig))) then
+          klcl(ig)=l
+          interp(ig)=(pcon(ig)-pplev(ig,klcl(ig)))/(pplev(ig,klcl(ig)+1)-pplev(ig,klcl(ig)))
+          endif
+        endif
+      enddo
+    enddo
+
+!------------Hauteur des thermiques
+!!jyg le 27/04/2012
+!!    do ig =1,ngrid
+!!    rhobarz0(ig)=rhobarz(ig,klcl(ig))+(rhobarz(ig,klcl(ig)+1) &
+!! &               -rhobarz(ig,klcl(ig)))*interp(ig)
+!!    zlcl(ig)=(pplev(ig,1)-pcon(ig))/(rhobarz0(ig)*RG)
+!!      if ( (.not.ok_lcl(ig)) .or. (zlcl(ig).gt.zmax(ig)) ) zlcl(ig)=zmax(ig) ! Si zclc > zmax alors on pose zlcl = zmax
+!!    enddo
+    do ig =1,ngrid
+!CR:REHABILITATION ZMAX CONTINU
+     if (ok_lcl(ig)) then 
+      rhobarz0(ig)=rhobarz(ig,klcl(ig))+(rhobarz(ig,klcl(ig)+1) &
+ &               -rhobarz(ig,klcl(ig)))*interp(ig)
+      zlcl(ig)=(pplev(ig,1)-pcon(ig))/(rhobarz0(ig)*RG)
+      zlcl(ig)=min(zlcl(ig),zmax(ig))   ! Si zlcl > zmax alors on pose zlcl = zmax
+     else
+      rhobarz0(ig)=0.
+      zlcl(ig)=zmax(ig)
+     endif
+    enddo
+!!jyg fin
+
+!------------Calcul des propriétés du thermique au LCL 
+  IF ( (iflag_trig_bl.ge.1) .or. (iflag_clos_bl.ge.1) ) THEN 
+
+  !-----Initialisation de la TKE moyenne 
+   do l=1,nlay
+    do ig=1,ngrid
+     pbl_tke_max(ig,l)=0.
+    enddo
+   enddo
+
+!-----Calcul de la TKE moyenne 
+   do nsrf=1,nbsrf
+    do l=1,nlay
+     do ig=1,ngrid
+     pbl_tke_max(ig,l)=pctsrf(ig,nsrf)*pbl_tke(ig,l,nsrf)+pbl_tke_max(ig,l)
+     enddo
+    enddo
+   enddo
+
+!-----Initialisations des TKE dans et hors des thermiques 
+   do l=1,nlay
+    do ig=1,ngrid
+    therm_tke_max(ig,l)=pbl_tke_max(ig,l)
+    env_tke_max(ig,l)=pbl_tke_max(ig,l)
+    enddo
+   enddo
+
+!-----Calcul de la TKE transportée par les thermiques : therm_tke_max
+   call thermcell_tke_transport(ngrid,nlay,ptimestep,fm0,entr0,  &
+  &           rg,pplev,therm_tke_max)
+!   print *,' thermcell_tke_transport -> '   !!jyg
+
+!-----Calcul des profils verticaux de TKE hors thermiques : env_tke_max, et de la vitesse verticale grande échelle : W_ls
+   do l=1,nlay
+    do ig=1,ngrid
+     pbl_tke_max(ig,l)=fraca(ig,l)*therm_tke_max(ig,l)+(1.-fraca(ig,l))*env_tke_max(ig,l)         !  Recalcul de TKE moyenne aprés transport de TKE_TH
+     env_tke_max(ig,l)=(pbl_tke_max(ig,l)-fraca(ig,l)*therm_tke_max(ig,l))/(1.-fraca(ig,l))       !  Recalcul de TKE dans  l'environnement aprés transport de TKE_TH
+     w_ls(ig,l)=-1.*omega(ig,l)/(RG*rhobarz(ig,l))                                                !  Vitesse verticale de grande échelle
+    enddo
+   enddo
+!    print *,' apres w_ls = '   !!jyg
+
+  do ig=1,ngrid
+   if (ok_lcl(ig)) then
+     fraca0(ig)=fraca(ig,klcl(ig))+(fraca(ig,klcl(ig)+1) &
+ &             -fraca(ig,klcl(ig)))*interp(ig)
+     w0(ig)=zw2(ig,klcl(ig))+(zw2(ig,klcl(ig)+1) &
+ &         -zw2(ig,klcl(ig)))*interp(ig)
+     w_conv(ig)=w_ls(ig,klcl(ig))+(w_ls(ig,klcl(ig)+1) &
+ &             -w_ls(ig,klcl(ig)))*interp(ig)
+     therm_tke_max0(ig)=therm_tke_max(ig,klcl(ig)) &
+ &                     +(therm_tke_max(ig,klcl(ig)+1)-therm_tke_max(ig,klcl(ig)))*interp(ig)
+     env_tke_max0(ig)=env_tke_max(ig,klcl(ig))+(env_tke_max(ig,klcl(ig)+1) &
+ &                   -env_tke_max(ig,klcl(ig)))*interp(ig)
+     pbl_tke_max0(ig)=pbl_tke_max(ig,klcl(ig))+(pbl_tke_max(ig,klcl(ig)+1) &
+ &                   -pbl_tke_max(ig,klcl(ig)))*interp(ig)
+     if (therm_tke_max0(ig).ge.20.) therm_tke_max0(ig)=20.
+     if (env_tke_max0(ig).ge.20.) env_tke_max0(ig)=20.
+     if (pbl_tke_max0(ig).ge.20.) pbl_tke_max0(ig)=20.
+   else 
+     fraca0(ig)=0.
+     w0(ig)=0.
+!!jyg le 27/04/2012
+!!     zlcl(ig)=0.
+!!
+   endif
+  enddo
+
+  ENDIF ! IF ( (iflag_trig_bl.ge.1) .or. (iflag_clos_bl.ge.1) )
+!  print *,'ENDIF  ( (iflag_trig_bl.ge.1) .or. (iflag_clos_bl.ge.1) ) '    !!jyg
+
+!------------Triggering------------------
+  IF (iflag_trig_bl.ge.1) THEN 
+
+!-----Initialisations
+   depth(:)=0.
+   n2(:)=0.
+   s2(:)=100. ! some low value, arbitrary
+   s_max(:)=0.
+
+!-----Epaisseur du nuage (depth) et détermination de la queue du spectre de panaches (n2,s2) et du panache le plus gros (s_max)
+   do ig=1,ngrid
+     zmax_moy(ig)=zlcl(ig)+zmax_moy_coef*(zmax(ig)-zlcl(ig))
+     depth(ig)=zmax_moy(ig)-zlcl(ig)
+     hmin(ig)=hmincoef*zlcl(ig)
+     if (depth(ig).ge.10.) then 
+       s2(ig)=(hcoef*depth(ig)+hmin(ig))**2
+       n2(ig)=(1.-eps1)*fraca0(ig)*airephy(ig)/s2(ig)
+!!
+!!jyg le 27/04/2012
+!!       s_max(ig)=s2(ig)*log(n2(ig))
+!!       if (n2(ig) .lt. 1) s_max(ig)=0.
+       s_max(ig)=s2(ig)*log(max(n2(ig),1.))
+!!fin jyg
+     else
+       n2(ig)=0.
+       s_max(ig)=0.
+     endif
+   enddo
+!   print *,'avant Calcul de Wmax '    !!jyg
+
+!-----Calcul de Wmax et ALE_BL_STAT associée
+!!jyg le 30/04/2012
+!!   do ig=1,ngrid
+!!     if ( (depth(ig).ge.10.) .and. (s_max(ig).gt.1.) ) then
+!!     w_max(ig)=w0(ig)*(1.+sqrt(2.*log(s_max(ig)/su)-log(2.*3.14)-log(2.*log(s_max(ig)/su)-log(2.*3.14))))
+!!     ale_bl_stat(ig)=0.5*w_max(ig)**2
+!!     else
+!!     w_max(ig)=0.
+!!     ale_bl_stat(ig)=0.
+!!     endif
+!!   enddo
+   susqr2pi=su*sqrt(2.*Rpi)
+   reuler=exp(1.)
+   do ig=1,ngrid
+     if ( (depth(ig).ge.10.) .and. (s_max(ig).gt.susqr2pi*reuler) ) then
+      w_max(ig)=w0(ig)*(1.+sqrt(2.*log(s_max(ig)/susqr2pi)-log(2.*log(s_max(ig)/susqr2pi))))
+      ale_bl_stat(ig)=0.5*w_max(ig)**2
+     else
+      w_max(ig)=0.
+      ale_bl_stat(ig)=0.
+     endif
+   enddo
+
+  ENDIF ! iflag_trig_bl
+!  print *,'ENDIF  iflag_trig_bl'    !!jyg
+
+!------------Closure------------------
+
+  IF (iflag_clos_bl.ge.2) THEN 
+
+!-----Calcul de ALP_BL_STAT
+  do ig=1,ngrid
+  alp_bl_det(ig)=0.5*coef_m*rhobarz0(ig)*(w0(ig)**3)*fraca0(ig)*(1.-2.*fraca0(ig))/((1.-fraca0(ig))**2)
+  alp_bl_fluct_m(ig)=1.5*rhobarz0(ig)*fraca0(ig)*(w_conv(ig)+coef_m*w0(ig))* &
+ &                   (w0(ig)**2)
+  alp_bl_fluct_tke(ig)=3.*coef_m*rhobarz0(ig)*w0(ig)*fraca0(ig)*(therm_tke_max0(ig)-env_tke_max0(ig)) &
+ &                    +3.*rhobarz0(ig)*w_conv(ig)*pbl_tke_max0(ig)
+    if (iflag_clos_bl.ge.2) then 
+    alp_bl_conv(ig)=1.5*coef_m*rhobarz0(ig)*fraca0(ig)*(fraca0(ig)/(1.-fraca0(ig)))*w_conv(ig)* &
+ &                   (w0(ig)**2)
+    else
+    alp_bl_conv(ig)=0.
+    endif
+  alp_bl_stat(ig)=alp_bl_det(ig)+alp_bl_fluct_m(ig)+alp_bl_fluct_tke(ig)+alp_bl_conv(ig)
+  enddo
+
+!-----Sécurité ALP infinie
+  do ig=1,ngrid
+   if (fraca0(ig).gt.0.98) alp_bl_stat(ig)=2.
+  enddo
+
+  ENDIF ! (iflag_clos_bl.ge.2)
+
+!!! fin nrlmd le 10/04/2012
+
+!      print*,'avant calcul ale et alp' 
+!calcul de ALE et ALP pour la convection
+      alp_bl(:)=0.
+      ale_bl(:)=0.
+!          print*,'ALE,ALP ,l,zw2(ig,l),ale_bl(ig),alp_bl(ig)'
+      do l=1,nlay
+      do ig=1,ngrid
+           alp_bl(ig)=max(alp_bl(ig),0.5*rhobarz(ig,l)*wth3(ig,l) )
+           ale_bl(ig)=max(ale_bl(ig),0.5*zw2(ig,l)**2)
+!          print*,'ALE,ALP',l,zw2(ig,l),ale_bl(ig),alp_bl(ig)
+      enddo
+      enddo
+
+! ale sec (max de wmax/2 sous la zone d'inhibition) dans
+! le cas iflag_trig_bl=3
+      IF (iflag_trig_bl==3) ale_bl(:)=0.5*wmax_sec(:)**2
+
+!test:calcul de la ponderation des couches pour KE
+!initialisations
+
+      fm_tot(:)=0.
+      wght_th(:,:)=1.
+      lalim_conv(:)=lalim(:)
+
+      do k=1,klev
+         do ig=1,ngrid
+            if (k<=lalim_conv(ig)) fm_tot(ig)=fm_tot(ig)+fm(ig,k)
+         enddo
+      enddo
+
+! assez bizarre car, si on est dans la couche d'alim et que alim_star et
+! plus petit que 1.e-10, on prend wght_th=1.
+      do k=1,klev
+         do ig=1,ngrid
+            if (k<=lalim_conv(ig).and.alim_star(ig,k)>1.e-10) then
+               wght_th(ig,k)=alim_star(ig,k)
+            endif
+         enddo
+      enddo
+
+!      print*,'apres wght_th'
+!test pour prolonger la convection
+      do ig=1,ngrid
+!v1d  if ((alim_star(ig,1).lt.1.e-10).and.(therm)) then
+      if ((alim_star(ig,1).lt.1.e-10)) then
+      lalim_conv(ig)=1
+      wght_th(ig,1)=1.
+!      print*,'lalim_conv ok',lalim_conv(ig),wght_th(ig,1)
+      endif
+      enddo
+
+!------------------------------------------------------------------------
+! Modif CR/FH 20110310 : alp integree sur la verticale.
+! Integrale verticale de ALP.
+! wth3 etant aux niveaux inter-couches, on utilise d play comme masse des
+! couches
+!------------------------------------------------------------------------
+
+      alp_int(:)=0.
+      dp_int(:)=0.
+      do l=2,nlay
+        do ig=1,ngrid
+           if(l.LE.lmax(ig)) THEN
+           zdp=pplay(ig,l-1)-pplay(ig,l)
+           alp_int(ig)=alp_int(ig)+0.5*rhobarz(ig,l)*wth3(ig,l)*zdp
+           dp_int(ig)=dp_int(ig)+zdp
+           endif
+        enddo
+      enddo
+
+      if (iflag_coupl>=3 .and. iflag_coupl<=5) then
+      do ig=1,ngrid
+!valeur integree de alp_bl * 0.5:
+        if (dp_int(ig)>0.) then
+        alp_bl(ig)=alp_int(ig)/dp_int(ig)
+        endif
+      enddo!
+      endif
+
+
+! Facteur multiplicatif sur alp_bl
+      alp_bl(:)=alp_bl_k*alp_bl(:)
+
+!------------------------------------------------------------------------
+
+
+
+      return
+      end
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_closure.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_closure.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_closure.F90	(revision 2408)
@@ -17,5 +17,4 @@
       IMPLICIT NONE
 
-#include "iniprint.h"
 #include "thermcell.h"
 INTEGER ngrid,nlay
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_dq.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_dq.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_dq.F90	(revision 2408)
@@ -1,7 +1,7 @@
       subroutine thermcell_dq(ngrid,nlay,impl,ptimestep,fm,entr,  &
      &           masse,q,dq,qa,lev_out)
+      USE print_control_mod, ONLY: prt_level
       implicit none
 
-#include "iniprint.h"
 !=======================================================================
 !
@@ -55,5 +55,5 @@
                print*,'entr*dt>m,1',k,entr(ig,k)*ptimestep,masse(ig,k)
                abort_message = 'entr dt > m, 1st'
-               CALL abort_gcm (modname,abort_message,1)
+               CALL abort_physic (modname,abort_message,1)
             endif
          enddo
@@ -152,7 +152,7 @@
       subroutine thermcell_dq_o(ngrid,nlay,impl,ptimestep,fm,entr,  &
      &           masse,q,dq,qa,lev_out)
+      USE print_control_mod, ONLY: prt_level
       implicit none
 
-#include "iniprint.h"
 !=======================================================================
 !
@@ -196,5 +196,5 @@
                print*,'entr*dt>m,2',k,entr(ig,k)*ptimestep,masse(ig,k)
                abort_message = 'entr dt > m, 2nd'
-               CALL abort_gcm (modname,abort_message,1)
+               CALL abort_physic (modname,abort_message,1)
             endif
          enddo
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_dry.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_dry.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_dry.F90	(revision 2408)
@@ -15,7 +15,7 @@
 !--------------------------------------------------------------------------
 
+       USE print_control_mod, ONLY: prt_level
        IMPLICIT NONE
 #include "YOMCST.h"       
-#include "iniprint.h"
        INTEGER l,ig
 
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_dtke.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_dtke.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_dtke.F90	(revision 2408)
@@ -1,7 +1,7 @@
       subroutine thermcell_dtke(ngrid,nlay,nsrf,ptimestep,fm0,entr0,  &
      &           rg,pplev,tke)
+      USE print_control_mod, ONLY: prt_level
       implicit none
 
-#include "iniprint.h"
 !=======================================================================
 !
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_dv2.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_dv2.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_dv2.F90	(revision 2408)
@@ -2,7 +2,7 @@
      &    ,fraca,larga  &
      &    ,u,v,du,dv,ua,va,lev_out)
+      USE print_control_mod, ONLY: prt_level,lunout
       implicit none
 
-#include "iniprint.h"
 !=======================================================================
 !
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_env.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_env.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_env.F90	(revision 2408)
@@ -7,4 +7,5 @@
 !--------------------------------------------------------------
 
+      USE print_control_mod, ONLY: prt_level
       IMPLICIT NONE
 
@@ -12,5 +13,4 @@
 #include "YOETHF.h"
 #include "FCTTRE.h"      
-#include "iniprint.h"
 
       INTEGER ngrid,nlay
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_flux.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_flux.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_flux.F90	(revision 2408)
@@ -14,6 +14,6 @@
 !---------------------------------------------------------------------------
 
+      USE print_control_mod, ONLY: prt_level,lunout
       IMPLICIT NONE
-#include "iniprint.h"
       
       INTEGER ig,l
@@ -103,5 +103,5 @@
                     print*,'detr_star(ig,l)',detr_star(ig,l)
                     abort_message = ''
-                    CALL abort_gcm (modname,abort_message,1)
+                    CALL abort_physic (modname,abort_message,1)
                endif
             endif
@@ -268,5 +268,5 @@
                print*,'N1 ig,l,entr',ig,l,entr(ig,l)
                abort_message = 'entr negatif'
-               CALL abort_gcm (modname,abort_message,1)
+               CALL abort_physic (modname,abort_message,1)
             endif
             if (detr(ig,l).gt.fm(ig,l)) then
@@ -297,5 +297,5 @@
                print*,'fm(ig,l)',fm(ig,l)
                abort_message = 'probleme dans thermcell flux'
-               CALL abort_gcm (modname,abort_message,1)
+               CALL abort_physic (modname,abort_message,1)
             endif
          enddo
@@ -325,5 +325,5 @@
                print*,'fm(ig,l)',fm(ig,l)
                abort_message = 'probleme dans thermcell flux'
-               CALL abort_gcm (modname,abort_message,1)
+               CALL abort_physic (modname,abort_message,1)
             endif
         enddo
@@ -427,5 +427,5 @@
                          print*,'fm(ig,l)',fm(ig,l)
                          abort_message = 'probleme dans thermcell_flux'
-                         CALL abort_gcm (modname,abort_message,1)
+                         CALL abort_physic (modname,abort_message,1)
                       endif
                       entr(ig,l+1)=entr(ig,l+1)-ddd
@@ -511,5 +511,5 @@
           print*,'fm(igout,l)',fm(igout,l)
           abort_message = ''
-          CALL abort_gcm (modname,abort_message,1)
+          CALL abort_physic (modname,abort_message,1)
           endif
       enddo
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_flux2.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_flux2.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_flux2.F90	(revision 2408)
@@ -13,6 +13,6 @@
 !---------------------------------------------------------------------------
 
+      USE print_control_mod, ONLY: prt_level
       IMPLICIT NONE
-#include "iniprint.h"
 #include "thermcell.h"
       
@@ -50,5 +50,5 @@
       save fomass_max,alphamax
 
-      logical check_debug,labort_gcm
+      logical check_debug,labort_physic
 
       character (len=20) :: modname='thermcell_flux2'
@@ -108,6 +108,6 @@
                     print*,'detr_star(ig,l)',detr_star(ig,l)
                     abort_message = ''
-                    labort_gcm=.true.
-                    CALL abort_gcm (modname,abort_message,1)
+                    labort_physic=.true.
+                    CALL abort_physic (modname,abort_message,1)
                endif
             endif
@@ -270,8 +270,8 @@
 
 
-         labort_gcm=.false.
+         labort_physic=.false.
          do ig=1,ngrid
             if (entr(ig,l)<0.) then
-               labort_gcm=.true.
+               labort_physic=.true.
                igout=ig
                lout=l
@@ -279,8 +279,8 @@
          enddo
 
-         if (labort_gcm) then
+         if (labort_physic) then
             print*,'N1 ig,l,entr',igout,lout,entr(igout,lout)
             abort_message = 'entr negatif'
-            CALL abort_gcm (modname,abort_message,1)
+            CALL abort_physic (modname,abort_message,1)
          endif
 
@@ -310,12 +310,12 @@
          enddo
 
-         labort_gcm=.false.
+         labort_physic=.false.
          do ig=1,ngrid
             if (entr(ig,l).lt.0.) then
-               labort_gcm=.true.
+               labort_physic=.true.
                igout=ig
             endif
          enddo
-         if (labort_gcm) then
+         if (labort_physic) then
             ig=igout
             print*,'ig,l,lmax(ig)',ig,l,lmax(ig)
@@ -323,5 +323,5 @@
             print*,'fm(ig,l)',fm(ig,l)
             abort_message = 'probleme dans thermcell flux'
-            CALL abort_gcm (modname,abort_message,1)
+            CALL abort_physic (modname,abort_message,1)
          endif
 
@@ -348,12 +348,12 @@
          enddo
 
-         labort_gcm=.false.
+         labort_physic=.false.
          do ig=1,ngrid
             if (detr(ig,l).lt.0.) then
-               labort_gcm=.true.
+               labort_physic=.true.
                igout=ig
             endif
         enddo
-        if (labort_gcm) then
+        if (labort_physic) then
                ig=igout
                print*,'cas 2 : ig,l,lmax(ig)',ig,l,lmax(ig)
@@ -361,5 +361,5 @@
                print*,'fm(ig,l)',fm(ig,l)
                abort_message = 'probleme dans thermcell flux'
-               CALL abort_gcm (modname,abort_message,1)
+               CALL abort_physic (modname,abort_message,1)
         endif
 !    enddo
@@ -427,5 +427,5 @@
 
       if (1.eq.1) then
-      labort_gcm=.false.
+      labort_physic=.false.
       do l=1,klev-1
          do ig=1,ngrid
@@ -450,5 +450,5 @@
                          igout=ig
                          lout=l
-                         labort_gcm=.true.
+                         labort_physic=.true.
                       endif
                       entr(ig,l+1)=entr(ig,l+1)-ddd
@@ -461,5 +461,5 @@
          enddo
       enddo
-      if (labort_gcm) then
+      if (labort_physic) then
                          ig=igout
                          l=lout
@@ -479,5 +479,5 @@
                          print*,'fm(ig,l)',fm(ig,l)
                          abort_message = 'probleme dans thermcell_flux'
-                         CALL abort_gcm (modname,abort_message,1)
+                         CALL abort_physic (modname,abort_message,1)
       endif
       endif
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_height.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_height.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_height.F90	(revision 2408)
@@ -6,5 +6,4 @@
 !-----------------------------------------------------------------------------
       IMPLICIT NONE
-#include "iniprint.h"
 #include "thermcell.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_init.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_init.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_init.F90	(revision 2408)
@@ -8,6 +8,6 @@
 !thermcell_init: calcul du profil d alimentation du thermique
 !----------------------------------------------------------------------
+      USE print_control_mod, ONLY: lunout
       IMPLICIT NONE
-#include "iniprint.h"
 #include "thermcell.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_main.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_main.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_main.F90	(revision 2408)
@@ -23,6 +23,6 @@
       USE dimphy
       USE ioipsl
-      USE comgeomphy , ONLY:rlond,rlatd
       USE indice_sol_mod
+      USE print_control_mod, ONLY: lunout,prt_level
       IMPLICIT NONE
 
@@ -62,9 +62,7 @@
 !   -------------
 
-#include "dimensions.h"
 #include "YOMCST.h"
 #include "YOETHF.h"
 #include "FCTTRE.h"
-#include "iniprint.h"
 #include "thermcell.h"
 
@@ -565,5 +563,5 @@
       if (.not. (f0(1).ge.0.) ) then
               abort_message = '.not. (f0(1).ge.0.)'
-              CALL abort_gcm (modname,abort_message,1)
+              CALL abort_physic (modname,abort_message,1)
       endif
 
@@ -695,5 +693,5 @@
       if (ierr==1) then
            abort_message = 'thermcellV0_main: les thermiques vont trop haut '
-           CALL abort_gcm (modname,abort_message,1)
+           CALL abort_physic (modname,abort_message,1)
       endif
 
@@ -749,302 +747,23 @@
       enddo
 !
-
+! $Id$
+!
+      CALL thermcell_alp(ngrid,nlay,ptimestep  &
+     &                  ,pplay,pplev  &
+     &                  ,fm0,entr0,lmax  &
+     &                  ,Ale_bl,Alp_bl,lalim_conv,wght_th &
+     &                  ,zw2,fraca &
+!!! necessire en plus
+     &                  ,pcon,rhobarz,wth3,wmax_sec,lalim,fm,alim_star,zmax &
 !!! nrlmd le 10/04/2012
-
-!------------Test sur le LCL des thermiques
-    do ig=1,ngrid
-      ok_lcl(ig)=.false.
-      if ( (pcon(ig) .gt. pplay(ig,klev-1)) .and. (pcon(ig) .lt. pplay(ig,1)) ) ok_lcl(ig)=.true.
-    enddo
-
-!------------Localisation des niveaux entourant le LCL et du coef d'interpolation
-    do l=1,nlay-1
-      do ig=1,ngrid
-        if (ok_lcl(ig)) then 
-!ATTENTION,zw2 calcule en pplev
-!          if ((pplay(ig,l) .ge. pcon(ig)) .and. (pplay(ig,l+1) .le. pcon(ig))) then
-!          klcl(ig)=l
-!          interp(ig)=(pcon(ig)-pplay(ig,klcl(ig)))/(pplay(ig,klcl(ig)+1)-pplay(ig,klcl(ig)))
-!          endif
-          if ((pplev(ig,l) .ge. pcon(ig)) .and. (pplev(ig,l+1) .le. pcon(ig))) then
-          klcl(ig)=l
-          interp(ig)=(pcon(ig)-pplev(ig,klcl(ig)))/(pplev(ig,klcl(ig)+1)-pplev(ig,klcl(ig)))
-          endif
-        endif
-      enddo
-    enddo
-
-!------------Hauteur des thermiques
-!!jyg le 27/04/2012
-!!    do ig =1,ngrid
-!!    rhobarz0(ig)=rhobarz(ig,klcl(ig))+(rhobarz(ig,klcl(ig)+1) &
-!! &               -rhobarz(ig,klcl(ig)))*interp(ig)
-!!    zlcl(ig)=(pplev(ig,1)-pcon(ig))/(rhobarz0(ig)*RG)
-!!    zmax(ig)=pphi(ig,lmax(ig))/rg
-!!      if ( (.not.ok_lcl(ig)) .or. (zlcl(ig).gt.zmax(ig)) ) zlcl(ig)=zmax(ig) ! Si zclc > zmax alors on pose zlcl = zmax
-!!    enddo
-    do ig =1,ngrid
-!CR:REHABILITATION ZMAX CONTINU
-!     zmax(ig)=pphi(ig,lmax(ig))/rg
-     if (ok_lcl(ig)) then 
-      rhobarz0(ig)=rhobarz(ig,klcl(ig))+(rhobarz(ig,klcl(ig)+1) &
- &               -rhobarz(ig,klcl(ig)))*interp(ig)
-      zlcl(ig)=(pplev(ig,1)-pcon(ig))/(rhobarz0(ig)*RG)
-      zlcl(ig)=min(zlcl(ig),zmax(ig))   ! Si zlcl > zmax alors on pose zlcl = zmax
-     else
-      rhobarz0(ig)=0.
-      zlcl(ig)=zmax(ig)
-     endif
-    enddo
-!!jyg fin
-
-!------------Calcul des propriétés du thermique au LCL 
-  IF ( (iflag_trig_bl.ge.1) .or. (iflag_clos_bl.ge.1) ) THEN 
-
-  !-----Initialisation de la TKE moyenne 
-   do l=1,nlay
-    do ig=1,ngrid
-     pbl_tke_max(ig,l)=0.
-    enddo
-   enddo
-
-!-----Calcul de la TKE moyenne 
-   do nsrf=1,nbsrf
-    do l=1,nlay
-     do ig=1,ngrid
-     pbl_tke_max(ig,l)=pctsrf(ig,nsrf)*pbl_tke(ig,l,nsrf)+pbl_tke_max(ig,l)
-     enddo
-    enddo
-   enddo
-
-!-----Initialisations des TKE dans et hors des thermiques 
-   do l=1,nlay
-    do ig=1,ngrid
-    therm_tke_max(ig,l)=pbl_tke_max(ig,l)
-    env_tke_max(ig,l)=pbl_tke_max(ig,l)
-    enddo
-   enddo
-
-!-----Calcul de la TKE transportée par les thermiques : therm_tke_max
-   call thermcell_tke_transport(ngrid,nlay,ptimestep,fm0,entr0,  &
-  &           rg,pplev,therm_tke_max)
-!   print *,' thermcell_tke_transport -> '   !!jyg
-
-!-----Calcul des profils verticaux de TKE hors thermiques : env_tke_max, et de la vitesse verticale grande échelle : W_ls
-   do l=1,nlay
-    do ig=1,ngrid
-     pbl_tke_max(ig,l)=fraca(ig,l)*therm_tke_max(ig,l)+(1.-fraca(ig,l))*env_tke_max(ig,l)         !  Recalcul de TKE moyenne aprés transport de TKE_TH
-     env_tke_max(ig,l)=(pbl_tke_max(ig,l)-fraca(ig,l)*therm_tke_max(ig,l))/(1.-fraca(ig,l))       !  Recalcul de TKE dans  l'environnement aprés transport de TKE_TH
-     w_ls(ig,l)=-1.*omega(ig,l)/(RG*rhobarz(ig,l))                                                !  Vitesse verticale de grande échelle
-    enddo
-   enddo
-!    print *,' apres w_ls = '   !!jyg
-
-  do ig=1,ngrid
-   if (ok_lcl(ig)) then
-     fraca0(ig)=fraca(ig,klcl(ig))+(fraca(ig,klcl(ig)+1) &
- &             -fraca(ig,klcl(ig)))*interp(ig)
-     w0(ig)=zw2(ig,klcl(ig))+(zw2(ig,klcl(ig)+1) &
- &         -zw2(ig,klcl(ig)))*interp(ig)
-     w_conv(ig)=w_ls(ig,klcl(ig))+(w_ls(ig,klcl(ig)+1) &
- &             -w_ls(ig,klcl(ig)))*interp(ig)
-     therm_tke_max0(ig)=therm_tke_max(ig,klcl(ig)) &
- &                     +(therm_tke_max(ig,klcl(ig)+1)-therm_tke_max(ig,klcl(ig)))*interp(ig)
-     env_tke_max0(ig)=env_tke_max(ig,klcl(ig))+(env_tke_max(ig,klcl(ig)+1) &
- &                   -env_tke_max(ig,klcl(ig)))*interp(ig)
-     pbl_tke_max0(ig)=pbl_tke_max(ig,klcl(ig))+(pbl_tke_max(ig,klcl(ig)+1) &
- &                   -pbl_tke_max(ig,klcl(ig)))*interp(ig)
-     if (therm_tke_max0(ig).ge.20.) therm_tke_max0(ig)=20.
-     if (env_tke_max0(ig).ge.20.) env_tke_max0(ig)=20.
-     if (pbl_tke_max0(ig).ge.20.) pbl_tke_max0(ig)=20.
-   else 
-     fraca0(ig)=0.
-     w0(ig)=0.
-!!jyg le 27/04/2012
-!!     zlcl(ig)=0.
-!!
-   endif
-  enddo
-
-  ENDIF ! IF ( (iflag_trig_bl.ge.1) .or. (iflag_clos_bl.ge.1) )
-!  print *,'ENDIF  ( (iflag_trig_bl.ge.1) .or. (iflag_clos_bl.ge.1) ) '    !!jyg
-
-!------------Triggering------------------
-  IF (iflag_trig_bl.ge.1) THEN 
-
-!-----Initialisations
-   depth(:)=0.
-   n2(:)=0.
-   s2(:)=100. ! some low value, arbitrary
-   s_max(:)=0.
-
-!-----Epaisseur du nuage (depth) et détermination de la queue du spectre de panaches (n2,s2) et du panache le plus gros (s_max)
-   do ig=1,ngrid
-     zmax_moy(ig)=zlcl(ig)+zmax_moy_coef*(zmax(ig)-zlcl(ig))
-     depth(ig)=zmax_moy(ig)-zlcl(ig)
-     hmin(ig)=hmincoef*zlcl(ig)
-     if (depth(ig).ge.10.) then 
-       s2(ig)=(hcoef*depth(ig)+hmin(ig))**2
-       n2(ig)=(1.-eps1)*fraca0(ig)*airephy(ig)/s2(ig)
-!!
-!!jyg le 27/04/2012
-!!       s_max(ig)=s2(ig)*log(n2(ig))
-!!       if (n2(ig) .lt. 1) s_max(ig)=0.
-       s_max(ig)=s2(ig)*log(max(n2(ig),1.))
-!!fin jyg
-     else
-       n2(ig)=0.
-       s_max(ig)=0.
-     endif
-   enddo
-!   print *,'avant Calcul de Wmax '    !!jyg
-
-!-----Calcul de Wmax et ALE_BL_STAT associée
-!!jyg le 30/04/2012
-!!   do ig=1,ngrid
-!!     if ( (depth(ig).ge.10.) .and. (s_max(ig).gt.1.) ) then
-!!     w_max(ig)=w0(ig)*(1.+sqrt(2.*log(s_max(ig)/su)-log(2.*3.14)-log(2.*log(s_max(ig)/su)-log(2.*3.14))))
-!!     ale_bl_stat(ig)=0.5*w_max(ig)**2
-!!     else
-!!     w_max(ig)=0.
-!!     ale_bl_stat(ig)=0.
-!!     endif
-!!   enddo
-   susqr2pi=su*sqrt(2.*Rpi)
-   Reuler=exp(1.)
-   do ig=1,ngrid
-     if ( (depth(ig).ge.10.) .and. (s_max(ig).gt.susqr2pi*Reuler) ) then
-      w_max(ig)=w0(ig)*(1.+sqrt(2.*log(s_max(ig)/susqr2pi)-log(2.*log(s_max(ig)/susqr2pi))))
-      ale_bl_stat(ig)=0.5*w_max(ig)**2
-     else
-      w_max(ig)=0.
-      ale_bl_stat(ig)=0.
-     endif
-   enddo
-
-  ENDIF ! iflag_trig_bl
-!  print *,'ENDIF  iflag_trig_bl'    !!jyg
-
-!------------Closure------------------
-
-  IF (iflag_clos_bl.ge.2) THEN 
-
-!-----Calcul de ALP_BL_STAT
-  do ig=1,ngrid
-  alp_bl_det(ig)=0.5*coef_m*rhobarz0(ig)*(w0(ig)**3)*fraca0(ig)*(1.-2.*fraca0(ig))/((1.-fraca0(ig))**2)
-  alp_bl_fluct_m(ig)=1.5*rhobarz0(ig)*fraca0(ig)*(w_conv(ig)+coef_m*w0(ig))* &
- &                   (w0(ig)**2)
-  alp_bl_fluct_tke(ig)=3.*coef_m*rhobarz0(ig)*w0(ig)*fraca0(ig)*(therm_tke_max0(ig)-env_tke_max0(ig)) &
- &                    +3.*rhobarz0(ig)*w_conv(ig)*pbl_tke_max0(ig)
-    if (iflag_clos_bl.ge.2) then 
-    alp_bl_conv(ig)=1.5*coef_m*rhobarz0(ig)*fraca0(ig)*(fraca0(ig)/(1.-fraca0(ig)))*w_conv(ig)* &
- &                   (w0(ig)**2)
-    else
-    alp_bl_conv(ig)=0.
-    endif
-  alp_bl_stat(ig)=alp_bl_det(ig)+alp_bl_fluct_m(ig)+alp_bl_fluct_tke(ig)+alp_bl_conv(ig)
-  enddo
-
-!-----Sécurité ALP infinie
-  do ig=1,ngrid
-   if (fraca0(ig).gt.0.98) alp_bl_stat(ig)=2.
-  enddo
-
-  ENDIF ! (iflag_clos_bl.ge.2)
-
+     &                  ,pbl_tke,pctsrf,omega,airephy &
+     &                  ,zlcl,fraca0,w0,w_conv,therm_tke_max0,env_tke_max0 &
+     &                  ,n2,s2,ale_bl_stat &
+     &                  ,therm_tke_max,env_tke_max &
+     &                  ,alp_bl_det,alp_bl_fluct_m,alp_bl_fluct_tke &
+     &                  ,alp_bl_conv,alp_bl_stat &
 !!! fin nrlmd le 10/04/2012
-
-      if (prt_level.ge.10) then
-         ig=igout
-         do l=1,nlay
-            print*,'14f OK convect8 ig,l,zha zh zpspsk ',ig,l,zha(ig,l),zh(ig,l),zpspsk(ig,l)
-            print*,'14g OK convect8 ig,l,po',ig,l,po(ig,l)
-         enddo
-      endif
-
-!      print*,'avant calcul ale et alp' 
-!calcul de ALE et ALP pour la convection
-      Alp_bl(:)=0.
-      Ale_bl(:)=0.
-!          print*,'ALE,ALP ,l,zw2(ig,l),Ale_bl(ig),Alp_bl(ig)'
-      do l=1,nlay
-      do ig=1,ngrid
-           Alp_bl(ig)=max(Alp_bl(ig),0.5*rhobarz(ig,l)*wth3(ig,l) )
-           Ale_bl(ig)=max(Ale_bl(ig),0.5*zw2(ig,l)**2)
-!          print*,'ALE,ALP',l,zw2(ig,l),Ale_bl(ig),Alp_bl(ig)
-      enddo
-      enddo
-
-! Ale sec (max de wmax/2 sous la zone d'inhibition) dans
-! le cas iflag_trig_bl=3
-      IF (iflag_trig_bl==3) Ale_bl(:)=0.5*wmax_sec(:)**2
-
-!test:calcul de la ponderation des couches pour KE
-!initialisations
-
-      fm_tot(:)=0.
-      wght_th(:,:)=1.
-      lalim_conv(:)=lalim(:)
-
-      do k=1,klev
-         do ig=1,ngrid
-            if (k<=lalim_conv(ig)) fm_tot(ig)=fm_tot(ig)+fm(ig,k)
-         enddo
-      enddo
-
-! assez bizarre car, si on est dans la couche d'alim et que alim_star et
-! plus petit que 1.e-10, on prend wght_th=1.
-      do k=1,klev
-         do ig=1,ngrid
-            if (k<=lalim_conv(ig).and.alim_star(ig,k)>1.e-10) then
-               wght_th(ig,k)=alim_star(ig,k)
-            endif
-         enddo
-      enddo
-
-!      print*,'apres wght_th'
-!test pour prolonger la convection
-      do ig=1,ngrid
-!v1d  if ((alim_star(ig,1).lt.1.e-10).and.(therm)) then
-      if ((alim_star(ig,1).lt.1.e-10)) then
-      lalim_conv(ig)=1
-      wght_th(ig,1)=1.
-!      print*,'lalim_conv ok',lalim_conv(ig),wght_th(ig,1)
-      endif
-      enddo
-
-!------------------------------------------------------------------------
-! Modif CR/FH 20110310 : Alp integree sur la verticale.
-! Integrale verticale de ALP.
-! wth3 etant aux niveaux inter-couches, on utilise d play comme masse des
-! couches
-!------------------------------------------------------------------------
-
-      alp_int(:)=0.
-      dp_int(:)=0.
-      do l=2,nlay
-        do ig=1,ngrid
-           if(l.LE.lmax(ig)) THEN
-           zdp=pplay(ig,l-1)-pplay(ig,l)
-           alp_int(ig)=alp_int(ig)+0.5*rhobarz(ig,l)*wth3(ig,l)*zdp
-           dp_int(ig)=dp_int(ig)+zdp
-           endif
-        enddo
-      enddo
-
-      if (iflag_coupl>=3 .and. iflag_coupl<=5) then
-      do ig=1,ngrid
-!valeur integree de alp_bl * 0.5:
-        if (dp_int(ig)>0.) then
-        Alp_bl(ig)=alp_int(ig)/dp_int(ig)
-        endif
-      enddo!
-      endif
-
-
-! Facteur multiplicatif sur Alp_bl
-      Alp_bl(:)=alp_bl_k*Alp_bl(:)
-
-!------------------------------------------------------------------------
+     &                   )
+
 
 
@@ -1097,6 +816,6 @@
 
       subroutine test_ltherm(klon,klev,pplev,pplay,long,seuil,ztv,po,ztva,zqla,f_star,zw2,comment)
+      USE print_control_mod, ONLY: prt_level
       IMPLICIT NONE
-#include "iniprint.h"
 
       integer i, k, klon,klev
@@ -1138,7 +857,7 @@
       subroutine thermcell_tke_transport(ngrid,nlay,ptimestep,fm0,entr0,  &
      &           rg,pplev,therm_tke_max)
+      USE print_control_mod, ONLY: prt_level
       implicit none
 
-#include "iniprint.h"
 !=======================================================================
 !
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_old.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_old.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_old.F90	(revision 2408)
@@ -31,5 +31,4 @@
   ! -------------
 
-  include "dimensions.h"
   include "YOMCST.h"
 
@@ -520,5 +519,5 @@
       IF (fracd(ig,l)<0.1) THEN
         abort_message = 'fracd trop petit'
-        CALL abort_gcm(modname, abort_message, 1)
+        CALL abort_physic(modname, abort_message, 1)
       ELSE
         ! vitesse descendante "diagnostique"
@@ -742,6 +741,4 @@
   ! -------------
 
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -1747,5 +1744,5 @@
         PRINT *, 'THERMCELL PB ig=', ig, '   l=', l
         abort_message = 'THERMCELL PB'
-        CALL abort_gcm(modname, abort_message, 1)
+        CALL abort_physic(modname, abort_message, 1)
       END IF
       ! if ((zw2(ig,l+1).gt.1.e-10).and.(zw2(ig,l).gt.1.e-10).and.
@@ -2051,5 +2048,5 @@
       IF (fracd(ig,l)<0.1 .AND. (test(ig)==1)) THEN
         abort_message = 'fracd trop petit'
-        CALL abort_gcm(modname, abort_message, 1)
+        CALL abort_physic(modname, abort_message, 1)
       ELSE
         ! vitesse descendante "diagnostique"
@@ -2345,6 +2342,4 @@
   ! -------------
 
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
   include "YOMCST.h"
   include "YOETHF.h"
@@ -3101,5 +3096,5 @@
       IF (fracd(ig,l)<0.1) THEN
         abort_message = 'fracd trop petit'
-        CALL abort_gcm(modname, abort_message, 1)
+        CALL abort_physic(modname, abort_message, 1)
       ELSE
         ! vitesse descendante "diagnostique"
@@ -3278,6 +3273,4 @@
   ! -------------
 
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
   include "YOMCST.h"
 
@@ -3906,5 +3899,5 @@
       IF (fracd(ig,l)<0.1) THEN
         abort_message = 'fracd trop petit'
-        CALL abort_gcm(modname, abort_message, 1)
+        CALL abort_physic(modname, abort_message, 1)
       ELSE
         ! vitesse descendante "diagnostique"
@@ -4139,7 +4132,4 @@
   ! =======================================================================
 
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
-
   INTEGER ngrid, nlay
 
@@ -4235,7 +4225,4 @@
 
   ! =======================================================================
-
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
 
   INTEGER ngrid, nlay
@@ -4342,7 +4329,4 @@
   ! =======================================================================
 
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
-
   INTEGER ngrid, nlay
 
@@ -4419,7 +4403,4 @@
 
   ! =======================================================================
-
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
 
   INTEGER ngrid, nlay
@@ -4561,6 +4542,4 @@
   ! -------------
 
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
   include "YOMCST.h"
 
@@ -5209,5 +5188,5 @@
       IF (fracd(ig,l)<0.1) THEN
         abort_message = 'fracd trop petit'
-        CALL abort_gcm(modname, abort_message, 1)
+        CALL abort_physic(modname, abort_message, 1)
       ELSE
         ! vitesse descendante "diagnostique"
Index: /LMDZ5/branches/testing/libf/phylmd/thermcell_plume.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/thermcell_plume.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/thermcell_plume.F90	(revision 2408)
@@ -13,4 +13,5 @@
 USE IOIPSL, ONLY : getin
 
+       USE print_control_mod, ONLY: prt_level
        IMPLICIT NONE
 
@@ -18,5 +19,4 @@
 #include "YOETHF.h"
 #include "FCTTRE.h"
-#include "iniprint.h"
 #include "thermcell.h"
 
@@ -82,4 +82,5 @@
       real zbuoyjam(ngrid,klev),zdqtjam(ngrid,klev)
       real zbuoybis,zdz2,zdz3,lmel,entrbis,zdzbis
+      real d_temp(ngrid)
       real ztv1,ztv2,factinv,zinv,zlmel
       real zlmelup,zlmeldwn,zlt,zltdwn,zltup
@@ -104,4 +105,5 @@
       REAL,SAVE :: detr_q_power,detr_q_power_omp=0.5
       REAL,SAVE :: mix0,mix0_omp=0.
+      INTEGER,SAVE :: thermals_flag_alim,thermals_flag_alim_omp=0
 
       LOGICAL, SAVE :: first=.true.
@@ -127,4 +129,5 @@
      CALL getin('thermals_detr_q_power',detr_q_power_omp)
      CALL getin('thermals_mix0',mix0_omp)
+     CALL getin('thermals_flag_alim',thermals_flag_alim_omp)
 !    CALL getin('thermals_X',X_omp)
 !    X=X_omp
@@ -140,4 +143,5 @@
      detr_q_power=detr_q_power_omp
      mix0=mix0_omp
+     thermals_flag_alim=thermals_flag_alim_omp
       first=.false.
       ENDIF
@@ -188,5 +192,4 @@
       lmix_bis(:)=2
       wmaxa(:)=0.
-      lalim(:)=1
 
 
@@ -195,31 +198,10 @@
 ! couches sont instables.
 !-------------------------------------------------------------------------
+
       active(:)=ztv(:,1)>ztv(:,2)
-
-!-------------------------------------------------------------------------
-! Definition de l'alimentation a l'origine dans thermcell_init
-!-------------------------------------------------------------------------
-      do l=1,klev-1
-         do ig=1,ngrid
-            if (ztv(ig,l)> ztv(ig,l+1) .and. ztv(ig,1)>=ztv(ig,l) ) then
-               alim_star(ig,l)=MAX((ztv(ig,l)-ztv(ig,l+1)),0.)  &
-     &                       *sqrt(zlev(ig,l+1)) 
-               lalim(ig)=l+1
-               alim_star_tot(ig)=alim_star_tot(ig)+alim_star(ig,l)
-!               print*,'alim2',l,ztv(ig,l),ztv(ig,l+1),alim_star(ig,l)
-            endif
-         enddo
-      enddo
-      do l=1,klev
-         do ig=1,ngrid 
-            if (alim_star_tot(ig) > 1.e-10 ) then
-               alim_star(ig,l)=alim_star(ig,l)/alim_star_tot(ig)
-            endif
-         enddo
-      enddo
-      alim_star_tot(:)=1.
-
-
-
+      d_temp(:)=0. ! Pour activer un contraste de temperature a la base
+                   ! du panache
+!  Cet appel pourrait être fait avant thermcell_plume dans thermcell_main
+      CALL thermcell_alim(thermals_flag_alim,ngrid,klev,ztv,d_temp,zlev,alim_star,lalim)
 
 !------------------------------------------------------------------------------
@@ -811,4 +793,5 @@
 !--------------------------------------------------------------------------
 
+      USE print_control_mod, ONLY: prt_level
       IMPLICIT NONE
 
@@ -816,5 +799,4 @@
 #include "YOETHF.h"
 #include "FCTTRE.h"
-#include "iniprint.h"
 #include "thermcell.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/time_phylmdz_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/time_phylmdz_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/time_phylmdz_mod.F90	(revision 2408)
@@ -0,0 +1,80 @@
+!
+! $Id: $
+!
+MODULE time_phylmdz_mod
+
+    IMPLICIT NONE
+    REAL,SAVE    :: pdtphys     ! physics time step (s)
+!$OMP THREADPRIVATE(pdtphys)
+    INTEGER,SAVE :: day_step_phy    ! number of physical steps per day
+!$OMP THREADPRIVATE(day_step_phy)
+    INTEGER,SAVE :: ndays       ! number of days to run
+!$OMP THREADPRIVATE(ndays)
+    INTEGER,SAVE :: annee_ref   ! reference year from the origin
+!$OMP THREADPRIVATE(annee_ref)
+    INTEGER,SAVE :: day_ref     ! reference year of the origin
+!$OMP THREADPRIVATE(day_ref)
+    INTEGER,SAVE :: day_ini     ! initial day of the run starting from 1st january of annee_ref
+!$OMP THREADPRIVATE(day_ini)
+    INTEGER,SAVE :: day_end     ! final day of the run starting from 1st january of annee_ref
+!$OMP THREADPRIVATE(day_end)
+    REAL,SAVE    :: start_time  ! starting time from the begining of the initial day
+!$OMP THREADPRIVATE(start_time)
+    INTEGER,SAVE :: raz_date
+!$OMP THREADPRIVATE(raz_date)
+
+    INTEGER,SAVE :: itau_phy     ! number of physiq iteration from origin
+!$OMP THREADPRIVATE(itau_phy)
+    INTEGER,SAVE :: itaufin_phy      ! final iteration (in itau_phy steps)
+!$OMP THREADPRIVATE(itaufin_phy)
+    REAL,SAVE    :: current_time ! current elapsed time (s) from the begining of the run
+!$OMP THREADPRIVATE(current_time)
+    
+
+CONTAINS
+
+  SUBROUTINE init_time(annee_ref_, day_ref_, day_ini_, start_time_, &
+                       ndays_, pdtphys_)
+  USE ioipsl_getin_p_mod, ONLY : getin_p
+  USE phys_cal_mod, ONLY: phys_cal_init
+  IMPLICIT NONE
+  INCLUDE 'YOMCST.h'
+    INTEGER, INTENT(IN) :: annee_ref_  
+    INTEGER, INTENT(IN) :: day_ref_    
+    INTEGER, INTENT(IN) :: day_ini_    
+    REAL,    INTENT(IN) :: start_time_ 
+    INTEGER, INTENT(IN) :: ndays_      
+    REAL,    INTENT(IN) :: pdtphys_    
+    
+    annee_ref    = annee_ref_
+    day_ref      = day_ref_
+    day_ini      = day_ini_
+    start_time   = start_time_
+    ndays        = ndays_
+    pdtphys      = pdtphys_
+    
+    ! Initialize module variable not inherited from dynamics
+    day_step_phy = NINT(rday/pdtphys)
+    day_end  = day_ini + ndays
+  
+    raz_date = 0
+    CALL getin_p('raz_date', raz_date)
+
+    current_time=0
+    
+    CALL phys_cal_init(annee_ref,day_ref)
+    
+  END SUBROUTINE init_time
+
+  SUBROUTINE init_iteration(itau_phy_)
+  IMPLICIT NONE
+    INTEGER, INTENT(IN) :: itau_phy_
+    itau_phy=itau_phy_
+    IF (raz_date==1) itau_phy=0
+    
+    itaufin_phy=itau_phy+NINT(ndays/pdtphys)
+    
+  END SUBROUTINE init_iteration
+
+END MODULE time_phylmdz_mod      
+
Index: /LMDZ5/branches/testing/libf/phylmd/tracinca_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/tracinca_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/tracinca_mod.F90	(revision 2408)
@@ -5,5 +5,11 @@
 ! This module prepares and calls the INCA main subroutines. 
 !
-
+  IMPLICIT NONE  
+
+  CHARACTER(len=4),SAVE :: config_inca
+!$OMP THREADPRIVATE(config_inca)
+                     ! config_inca='none' => without INCA
+                     ! config_inca='chem' => INCA with chemistry
+                     ! config_inca='aero' => INCA with aerosols
 CONTAINS
 
@@ -11,5 +17,6 @@
     ! This subroutine initialize some control varaibles. 
 
-    USE infotrac
+    USE infotrac_phy, ONLY: nbtr
+    USE ioipsl_getin_p_mod, ONLY: getin_p
     IMPLICIT NONE
     
@@ -22,5 +29,5 @@
     lessivage  =.FALSE.
     aerosol(:) = .FALSE.
-        
+
   END SUBROUTINE tracinca_init
 
@@ -42,16 +49,12 @@
 
     USE dimphy
-    USE infotrac
+    USE infotrac_phy, ONLY: nbtr
     USE vampir
-    USE comgeomphy
-    USE control_mod
     USE indice_sol_mod
-
-    
+    USE geometry_mod, ONLY: cell_area
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
+    USE aero_mod, ONLY : naero_grp
     IMPLICIT NONE
     
-    INCLUDE "dimensions.h"
-    INCLUDE "paramet.h"
-
 !==========================================================================
 !                   -- DESCRIPTION DES ARGUMENTS --
@@ -97,8 +100,8 @@
     LOGICAL,INTENT(IN)                       :: aerosol_couple
     REAL,DIMENSION(klon,klev),INTENT(IN)     :: flxmass_w
-    REAL,DIMENSION(klon,klev,9,2),INTENT(IN) :: tau_aero
-    REAL,DIMENSION(klon,klev,9,2),INTENT(IN) :: piz_aero
-    REAL,DIMENSION(klon,klev,9,2),INTENT(IN) :: cg_aero
-    CHARACTER(len=4),DIMENSION(9),INTENT(IN) :: rfname 
+    REAL,DIMENSION(klon,klev,naero_grp,2),INTENT(IN) :: tau_aero
+    REAL,DIMENSION(klon,klev,naero_grp,2),INTENT(IN) :: piz_aero
+    REAL,DIMENSION(klon,klev,naero_grp,2),INTENT(IN) :: cg_aero
+    CHARACTER(len=4),DIMENSION(naero_grp),INTENT(IN) :: rfname 
     REAL,DIMENSION(klon,klev,2),INTENT(IN)   :: ccm 
 
@@ -145,5 +148,5 @@
          pplay,pdel,prfl,pmflxr,psfl,    &
          pmflxs,zpmfu,itop_con,ibas_con,  &
-         pphi,airephy,nstep,rneb,t_seri, &      
+         pphi,cell_area,nstep,rneb,t_seri, &      
          rh,tau_aero,piz_aero,cg_aero,   &
          rfname,ccm,lafin, config_inca)
@@ -162,5 +165,5 @@
          pplay,      & !pmid
          pdel,       & !pdel
-         airephy,    &
+         cell_area,  &
          pctsrf(1,1),& !oro
          ftsol,      & !tsurf
@@ -183,6 +186,6 @@
          sh,         & !sh
          rh,         & !rh
-         iip1,       & !nx
-         jjp1,       & !ny
+         nbp_lon+1,  & !nx
+         nbp_lat,    & !ny
          source )
 #endif
Index: /LMDZ5/branches/testing/libf/phylmd/traclmdz_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/traclmdz_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/traclmdz_mod.F90	(revision 2408)
@@ -67,5 +67,5 @@
     
     USE dimphy
-    USE infotrac
+    USE infotrac_phy
     
     ! Input argument
@@ -77,5 +77,5 @@
     ! Allocate restart variables trs
     ALLOCATE( trs(klon,nbtr), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('traclmdz_from_restart', 'pb in allocation 1',1)
+    IF (ierr /= 0) CALL abort_physic('traclmdz_from_restart', 'pb in allocation 1',1)
     
     ! Initialize trs with values read from restart file 
@@ -89,5 +89,5 @@
     ! Initialization of the tracers should be done here only for those not found in the restart file.
     USE dimphy
-    USE infotrac
+    USE infotrac_phy
     USE regr_pr_comb_coefoz_m, ONLY: alloc_coefoz
     USE press_coefoz_m, ONLY: press_coefoz
@@ -96,6 +96,6 @@
     USE mod_phys_lmdz_para
     USE indice_sol_mod
-
-    INCLUDE "iniprint.h"
+    USE print_control_mod, ONLY: lunout
+
 ! Input variables
     REAL,DIMENSION(klon,nbsrf),INTENT(IN)     :: pctsrf ! Pourcentage de sol f(nature du sol)
@@ -133,26 +133,26 @@
 ! --------------------------------------------
     ALLOCATE( scavtr(nbtr), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('traclmdz_init', 'pb in allocation 9',1)
+    IF (ierr /= 0) CALL abort_physic('traclmdz_init', 'pb in allocation 9',1)
     scavtr(:)=1.
     
     ALLOCATE( radio(nbtr), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('traclmdz_init', 'pb in allocation 11',1)
+    IF (ierr /= 0) CALL abort_physic('traclmdz_init', 'pb in allocation 11',1)
     radio(:) = .false.    ! Par defaut pas decroissance radioactive
     
     ALLOCATE( masktr(klon,nbtr), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('traclmdz_init', 'pb in allocation 2',1)
+    IF (ierr /= 0) CALL abort_physic('traclmdz_init', 'pb in allocation 2',1)
     
     ALLOCATE( fshtr(klon,nbtr), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('traclmdz_init', 'pb in allocation 3',1)
+    IF (ierr /= 0) CALL abort_physic('traclmdz_init', 'pb in allocation 3',1)
     
     ALLOCATE( hsoltr(nbtr), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('traclmdz_init', 'pb in allocation 4',1)
+    IF (ierr /= 0) CALL abort_physic('traclmdz_init', 'pb in allocation 4',1)
     
     ALLOCATE( tautr(nbtr), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('traclmdz_init', 'pb in allocation 5',1)
+    IF (ierr /= 0) CALL abort_physic('traclmdz_init', 'pb in allocation 5',1)
     tautr(:)  = 0.
     
     ALLOCATE( vdeptr(nbtr), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm('traclmdz_init', 'pb in allocation 6',1)
+    IF (ierr /= 0) CALL abort_physic('traclmdz_init', 'pb in allocation 6',1)
     vdeptr(:) = 0.
 
@@ -343,5 +343,5 @@
     
     USE dimphy
-    USE infotrac
+    USE infotrac_phy
     USE regr_pr_comb_coefoz_m, ONLY: regr_pr_comb_coefoz
     USE o3_chem_m, ONLY: o3_chem
@@ -626,5 +626,5 @@
     ! variable trs is written to restart file (restartphy.nc)
     USE dimphy
-    USE infotrac
+    USE infotrac_phy
     
     REAL,DIMENSION(klon,nbtr), INTENT(OUT) :: trs_out
Index: /LMDZ5/branches/testing/libf/phylmd/tracreprobus_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/tracreprobus_mod.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/tracreprobus_mod.F90	(revision 2408)
@@ -12,5 +12,5 @@
 
     USE dimphy
-    USE infotrac
+    USE infotrac_phy
 #ifdef REPROBUS 
     USE CHEM_REP, ONLY : pdt_rep, &  ! pas de temps reprobus
Index: /LMDZ5/branches/testing/libf/phylmd/transp.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/transp.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/transp.F90	(revision 2408)
@@ -13,6 +13,4 @@
   ! ======================================================================
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/transp_lay.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/transp_lay.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/transp_lay.F90	(revision 2408)
@@ -13,6 +13,4 @@
   ! ======================================================================
 
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/undefSTD.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/undefSTD.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/undefSTD.F90	(revision 2408)
@@ -37,7 +37,4 @@
   ! ====================================================================
 
-  ! ym#include "dimensions.h"
-  ! ym      integer jjmp1
-  ! ym      parameter (jjmp1=jjm+1-1/jjm)
   ! ym#include "dimphy.h"
   ! variables Input
Index: /LMDZ5/branches/testing/libf/phylmd/ustarhb.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/ustarhb.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/ustarhb.F90	(revision 2408)
@@ -18,6 +18,4 @@
   ! model. J. of Climate, vol. 6, 1825-1842.
   ! ======================================================================
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
   include "YOMCST.h"
 
Index: /LMDZ5/branches/testing/libf/phylmd/vdif_kcay.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/vdif_kcay.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/vdif_kcay.F90	(revision 2408)
@@ -6,8 +6,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! .......................................................................
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! .......................................................................
 
   ! dt : pas de temps
Index: /LMDZ5/branches/testing/libf/phylmd/vertical_layers_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/vertical_layers_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phylmd/vertical_layers_mod.F90	(revision 2408)
@@ -0,0 +1,46 @@
+! $Id: $
+
+MODULE vertical_layers_mod
+
+   REAL,SAVE             :: preff  ! reference surface pressure (Pa)
+   REAL,SAVE             :: scaleheight ! atmospheric reference scale height (km)
+   REAL,SAVE,ALLOCATABLE :: ap(:) ! hybrid (pressure contribution) coordinate 
+                                  ! at layer interfaces (Pa)
+   REAL,SAVE,ALLOCATABLE :: bp(:) ! hybrid (sigma contribution) coordinate 
+                                  ! at layer interfaces (Pa)
+   REAL,SAVE,ALLOCATABLE :: presnivs(:) ! reference pressure at mid-layer (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,presnivs,pseudoalt)
+
+
+CONTAINS
+
+  SUBROUTINE init_vertical_layers(nlayer,preff_,scaleheight_,ap_,bp_,&
+                                 presnivs_, pseudoalt_)
+    IMPLICIT NONE
+    INTEGER,INTENT(IN) :: nlayer ! number of atmospheric layers
+    REAL,INTENT(IN)    :: preff_ ! reference surface pressure (Pa)
+    REAL,INTENT(IN)    :: scaleheight_ ! atmospheric scale height (km)
+    REAL,INTENT(IN)    :: ap_(nlayer+1) ! hybrid coordinate at interfaces
+    REAL,INTENT(IN)    :: bp_(nlayer+1) ! hybrid coordinate at interfaces
+    REAL,INTENT(IN)    :: presnivs_(nlayer) ! Appproximative pressure of atm. layers (Pa)
+    REAL,INTENT(IN)    :: pseudoalt_(nlayer) ! pseudo-altitude of atm. layers (km)
+  
+    ALLOCATE(ap(nlayer+1))
+    ALLOCATE(bp(nlayer+1))
+    ALLOCATE(presnivs(nlayer))
+    ALLOCATE(pseudoalt(nlayer))
+  
+    preff = preff_
+    scaleheight=scaleheight_
+    ap(:) = ap_(:)
+    bp(:) = bp_(:)
+    presnivs(:) = presnivs_(:)
+    pseudoalt(:) = pseudoalt_(:)
+
+  END SUBROUTINE init_vertical_layers
+
+END MODULE vertical_layers_mod
Index: /LMDZ5/branches/testing/libf/phylmd/wake.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/wake.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/wake.F90	(revision 2408)
@@ -2,9 +2,12 @@
 ! $Id$
 
-SUBROUTINE wake(p, ph, pi, dtime, sigd_con, te0, qe0, omgb, dtdwn, dqdwn, &
-    amdwn, amup, dta, dqa, wdtpbl, wdqpbl, udtpbl, udqpbl, deltatw, deltaqw, &
-    dth, hw, sigmaw, wape, fip, gfl, dtls, dqls, ktopw, omgbdth, dp_omgb, &
-    wdens, tu, qu, dtke, dqke, dtpbl, dqpbl, omg, dp_deltomg, spread, cstar, &
-    d_deltat_gw, d_deltatw2, d_deltaqw2)
+SUBROUTINE wake(p, ph, pi, dtime, sigd_con, &
+                te0, qe0, omgb, &
+                dtdwn, dqdwn, amdwn, amup, dta, dqa, &
+                wdtpbl, wdqpbl, udtpbl, udqpbl, &
+                deltatw, deltaqw, dth, hw, sigmaw, wape, fip, gfl, &
+                dtls, dqls, ktopw, omgbdth, dp_omgb, wdens, tu, qu, &
+                dtke, dqke, dtpbl, dqpbl, omg, dp_deltomg, spread, cstar, &
+                d_deltat_gw, d_deltatw2, d_deltaqw2)
 
 
@@ -20,4 +23,5 @@
   USE dimphy
   use mod_phys_lmdz_para
+  USE print_control_mod, ONLY: prt_level
   IMPLICIT NONE
   ! ============================================================================
@@ -110,40 +114,41 @@
   ! -------------------------------------------------------------------------
 
-  include "dimensions.h"
   include "YOMCST.h"
   include "cvthermo.h"
-  include "iniprint.h"
 
   ! Arguments en entree
   ! --------------------
 
-  REAL, DIMENSION (klon, klev) :: p, pi
-  REAL, DIMENSION (klon, klev+1) :: ph, omgb
-  REAL dtime
-  REAL, DIMENSION (klon, klev) :: te0, qe0
-  REAL, DIMENSION (klon, klev) :: dtdwn, dqdwn
-  REAL, DIMENSION (klon, klev) :: wdtpbl, wdqpbl
-  REAL, DIMENSION (klon, klev) :: udtpbl, udqpbl
-  REAL, DIMENSION (klon, klev) :: amdwn, amup
-  REAL, DIMENSION (klon, klev) :: dta, dqa
-  REAL, DIMENSION (klon) :: sigd_con
+  REAL, DIMENSION (klon, klev),     INTENT(IN)          :: p, pi
+  REAL, DIMENSION (klon, klev+1),   INTENT(IN)          :: ph, omgb
+  REAL,                             INTENT(IN)          :: dtime
+  REAL, DIMENSION (klon, klev),     INTENT(IN)          :: te0, qe0
+  REAL, DIMENSION (klon, klev),     INTENT(IN)          :: dtdwn, dqdwn
+  REAL, DIMENSION (klon, klev),     INTENT(IN)          :: wdtpbl, wdqpbl, udtpbl, udqpbl ! UNUSED
+  REAL, DIMENSION (klon, klev),     INTENT(IN)          :: amdwn, amup
+  REAL, DIMENSION (klon, klev),     INTENT(IN)          :: dta, dqa
+  REAL, DIMENSION (klon),           INTENT(IN)          :: sigd_con
+
+  !
+  ! Input/Output
+  REAL, DIMENSION (klon, klev),     INTENT(INOUT)       :: deltatw, deltaqw
+  REAL, DIMENSION (klon),           INTENT(INOUT)       :: sigmaw
 
   ! Sorties
   ! --------
 
-  REAL, DIMENSION (klon, klev) :: deltatw, deltaqw, dth
-  REAL, DIMENSION (klon, klev) :: tu, qu
-  REAL, DIMENSION (klon, klev) :: dtls, dqls
-  REAL, DIMENSION (klon, klev) :: dtke, dqke
-  REAL, DIMENSION (klon, klev) :: dtpbl, dqpbl
-  REAL, DIMENSION (klon, klev) :: spread
-  REAL, DIMENSION (klon, klev) :: d_deltatgw
-  REAL, DIMENSION (klon, klev) :: d_deltatw2, d_deltaqw2
-  REAL, DIMENSION (klon, klev+1) :: omgbdth, omg
-  REAL, DIMENSION (klon, klev) :: dp_omgb, dp_deltomg
-  REAL, DIMENSION (klon, klev) :: d_deltat_gw
-  REAL, DIMENSION (klon) :: hw, sigmaw, wape, fip, gfl, cstar
-  REAL, DIMENSION (klon) :: wdens
-  INTEGER, DIMENSION (klon) :: ktopw
+  REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: dth
+  REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: tu, qu
+  REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: dtls, dqls
+  REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: dtke, dqke
+  REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: dtpbl, dqpbl
+  REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: spread
+  REAL, DIMENSION (klon, klev),     INTENT(OUT)         :: d_deltatw2, d_deltaqw2
+  REAL, DIMENSION (klon, klev+1),   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
+  REAL, DIMENSION (klon),           INTENT(OUT)         :: wdens
+  INTEGER, DIMENSION (klon),        INTENT(OUT)         :: ktopw
 
   ! Variables internes
@@ -1734,6 +1739,9 @@
       wape(i) = 0.
       cstar(i) = 0.
-      hw(i) = hwmin
-      sigmaw(i) = sigmad
+!!jyg   Outside subroutine "Wake" hw and sigmaw are zero when there are no wakes
+!!      hw(i) = hwmin                       !jyg
+!!      sigmaw(i) = sigmad                  !jyg
+      hw(i) = 0.                            !jyg
+      sigmaw(i) = 0.                        !jyg
       fip(i) = 0.
     ELSE
Index: DZ5/branches/testing/libf/phylmd/write_field_phy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/write_field_phy.F90	(revision 2407)
+++ 	(revision )
@@ -1,36 +1,0 @@
-!
-! $Header$
-!
-MODULE write_field_phy
-
-  CONTAINS 
- 
-    SUBROUTINE WriteField_phy(name,Field,ll)
-    USE dimphy
-    USE mod_phys_lmdz_para
-    USE mod_grid_phy_lmdz
-    USE Write_Field
-    
-    IMPLICIT NONE
-    include 'dimensions.h'
-    include 'paramet.h'
-
-    character(len=*)   :: name
-    INTEGER :: ll
-    real, dimension(klon_omp,ll) :: Field
-    real,save,allocatable :: Field_tmp(:,:)
-    real, dimension(klon_glo,ll):: New_Field
-    real, dimension(iim,jjp1,ll):: Field_2d
-
-    CALL Gather(Field,New_Field)
-!$OMP MASTER
-    IF (is_mpi_root) THEN	
-      CALL Grid1Dto2D_glo(New_Field,Field_2D)
-      CALL WriteField(name,Field_2d)
-    ENDIF
-!$OMP END MASTER
-
-  
-   END SUBROUTINE WriteField_phy
- 
- END MODULE write_field_phy
Index: /LMDZ5/branches/testing/libf/phylmd/write_histday_seri.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/write_histday_seri.h	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/write_histday_seri.h	(revision 2408)
@@ -7,5 +7,5 @@
 !
       ndex2d = 0
-      itau_w = itau_phy + itap + start_time * day_step / iphysiq
+      itau_w = itau_phy + itap + start_time * day_step_phy
 !
 ! Champs 2D:
@@ -20,20 +20,20 @@
       ok_msk=.FALSE.
       msk(1:klon)=pctsrf(1:klon,is_ter)
-      CALL moyglo_pondaire(klon, zx_tmp_fi2d, airephy,  &
-           ok_msk, msk, moyglo)
-      zx_tmp_fi2d(1:klon)=moyglo
-!
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL moyglo_pondaire(klon, zx_tmp_fi2d, cell_area,  &
+           ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+!
+      CALL gr_fi_ecrit(1, klon,nbp_lon,nbp_lat, zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day_seri,"bilTOA",itau_w, &
-                     zx_tmp_2d,iim*jjmp1,ndex2d)
-!
-      ok_msk=.FALSE.
-      CALL moyglo_pondaire(klon, bils, airephy,  &
-           ok_msk, msk, moyglo)
-      zx_tmp_fi2d(1:klon)=moyglo
-!
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+                     zx_tmp_2d,nbp_lon*nbp_lat,ndex2d)
+!
+      ok_msk=.FALSE.
+      CALL moyglo_pondaire(klon, bils, cell_area,  &
+           ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+!
+      CALL gr_fi_ecrit(1, klon,nbp_lon,nbp_lat, zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day_seri,"bils",itau_w, &
-                     zx_tmp_2d,iim*jjmp1,ndex2d)
+                     zx_tmp_2d,nbp_lon*nbp_lat,ndex2d)
 !
       DO k=1, klev
@@ -45,10 +45,10 @@
 !
       CALL moyglo_pondaima(klon, klev, zx_tmp_fi3d,  &
-           airephy, paprs, moyglo)
-      zx_tmp_fi2d(1:klon)=moyglo
-!
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+           cell_area, paprs, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+!
+      CALL gr_fi_ecrit(1, klon,nbp_lon,nbp_lat, zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day_seri,"ecin",itau_w, &
-                     zx_tmp_2d,iim*jjmp1,ndex2d) 
+                     zx_tmp_2d,nbp_lon*nbp_lat,ndex2d) 
 !
 !IM 151004 BEG
@@ -62,10 +62,10 @@
 !
       CALL moyglo_pondaima(klon, klev, zx_tmp_fi3d,  &
-           airephy, paprs, moyglo)
-      zx_tmp_fi2d(1:klon)=moyglo
-!
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+           cell_area, paprs, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+!
+      CALL gr_fi_ecrit(1, klon,nbp_lon,nbp_lat, zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day_seri,"momang",itau_w,zx_tmp_2d, &
-                     iim*jjmp1,ndex2d)
+                     nbp_lon*nbp_lat,ndex2d)
 !
 ! friction torque
@@ -76,23 +76,23 @@
 !
       ok_msk=.FALSE.
-      CALL moyglo_pondaire(klon, zx_tmp_fi2d, airephy,  &
-           ok_msk, msk, moyglo)
-      zx_tmp_fi2d(1:klon)=moyglo
-!
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL moyglo_pondaire(klon, zx_tmp_fi2d, cell_area,  &
+           ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+!
+      CALL gr_fi_ecrit(1, klon,nbp_lon,nbp_lat, zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day_seri,"frictor",itau_w,zx_tmp_2d, &
-                     iim*jjmp1,ndex2d)
+                     nbp_lon*nbp_lat,ndex2d)
 !
 ! mountain torque
 !
 !IM 190504 BEG
-      CALL gr_fi_dyn(1,klon,iim+1,jjm+1,airephy,airedyn)
-      CALL gr_fi_dyn(klev+1,klon,iim+1,jjm+1,paprs,padyn)
-      CALL gr_fi_dyn(1,klon,iim+1,jjm+1,rlat,rlatdyn)
+      CALL gr_fi_dyn(1,klon,nbp_lon+1,nbp_lat,cell_area,airedyn)
+      CALL gr_fi_dyn(klev+1,klon,nbp_lon+1,nbp_lat,paprs,padyn)
+      CALL gr_fi_dyn(1,klon,nbp_lon+1,nbp_lat,rlat,rlatdyn)
       mountor=0.
       airetot=0.
-      DO j = 1, jjmp1
-       DO i = 1, iim+1
-        ij=i+(iim+1)*(j-1)
+      DO j = 1, nbp_lat
+       DO i = 1, nbp_lon+1
+        ij=i+(nbp_lon+1)*(j-1)
         zx_tmp(ij)=0.
         DO k = 1, klev
@@ -113,17 +113,17 @@
 !
 !IM 190504 END
-      zx_tmp_2d(1:iim,1:jjmp1)=mountor
+      zx_tmp_2d(1:nbp_lon,1:nbp_lat)=mountor
       CALL histwrite(nid_day_seri,"mountor",itau_w,zx_tmp_2d, &
-                     iim*jjmp1,ndex2d)
+                     nbp_lon*nbp_lat,ndex2d)
 !
       ENDIF !(1.EQ.0) THEN
 !
 !
-      CALL gr_fi_dyn(1,klon,iim+1,jjm+1,airephy,airedyn)
-      CALL gr_fi_ecrit(1,klon,iim,jjmp1,airephy,zx_tmp_2d)
+      CALL gr_fi_dyn(1,klon,nbp_lon+1,nbp_lat,cell_area,airedyn)
+      CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,cell_area,zx_tmp_2d)
       airetot=0.
-!     DO j = 1, jjmp1
-!      DO i = 1, iim+1
-!       ij=i+(iim+1)*(j-1)
+!     DO j = 1, nbp_lat
+!      DO i = 1, nbp_lon+1
+!       ij=i+(nbp_lon+1)*(j-1)
 !       DO k = 1, klev
 !        airetot=airetot+airedyn(i,j)
@@ -134,11 +134,11 @@
 !
       DO i=1, klon
-       airetot=airetot+airephy(i)
+       airetot=airetot+cell_area(i)
       ENDDO
 !     IF(itap.EQ.1) PRINT*,'airetotphy=',airetot
 !
       airetot=0.
-      DO j=1, jjmp1
-       DO i=1, iim
+      DO j=1, nbp_lat
+       DO i=1, nbp_lon
         airetot=airetot+zx_tmp_2d(i,j)
        ENDDO
@@ -149,40 +149,40 @@
 !
       zx_tmp_fi2d(1:klon)=aam/airetot
-      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day_seri,"momang",itau_w,zx_tmp_2d, &
-                     iim*jjmp1,ndex2d)
+                     nbp_lon*nbp_lat,ndex2d)
 !
       zx_tmp_fi2d(1:klon)=torsfc/airetot
-      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day_seri,"torsfc",itau_w,zx_tmp_2d, &
-                     iim*jjmp1,ndex2d)
+                     nbp_lon*nbp_lat,ndex2d)
 !
 !IM 151004 END
 !
       CALL moyglo_pondmass(klon, klev, t_seri, &
-           airephy, paprs, moyglo)
-      zx_tmp_fi2d(1:klon)=moyglo
-!
-      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+           cell_area, paprs, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+!
+      CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day_seri,"tamv",itau_w, &
-                     zx_tmp_2d,iim*jjmp1,ndex2d)
-!
-      ok_msk=.FALSE.
-      CALL moyglo_pondaire(klon, paprs(:,1), airephy,  &
-           ok_msk, msk, moyglo)
-      zx_tmp_fi2d(1:klon)=moyglo
-!
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+                     zx_tmp_2d,nbp_lon*nbp_lat,ndex2d)
+!
+      ok_msk=.FALSE.
+      CALL moyglo_pondaire(klon, paprs(:,1), cell_area,  &
+           ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+!
+      CALL gr_fi_ecrit(1, klon,nbp_lon,nbp_lat, zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day_seri,"psol",itau_w, &
-                     zx_tmp_2d,iim*jjmp1,ndex2d)
-!
-      ok_msk=.FALSE.
-      CALL moyglo_pondaire(klon, evap, airephy,  &
-           ok_msk, msk, moyglo)
-      zx_tmp_fi2d(1:klon)=moyglo
-!
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+                     zx_tmp_2d,nbp_lon*nbp_lat,ndex2d)
+!
+      ok_msk=.FALSE.
+      CALL moyglo_pondaire(klon, evap, cell_area,  &
+           ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+!
+      CALL gr_fi_ecrit(1, klon,nbp_lon,nbp_lat, zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day_seri,"evap",itau_w, &
-                     zx_tmp_2d,iim*jjmp1,ndex2d)
+                     zx_tmp_2d,nbp_lon*nbp_lat,ndex2d)
 !
 !     DO i=1, klon
@@ -192,11 +192,11 @@
 !     ok_msk=.TRUE.
 !     msk(1:klon)=pctsrf(1:klon,is_ter)
-!     CALL moyglo_pondaire(klon, zx_tmp_fi2d, airephy, 
+!     CALL moyglo_pondaire(klon, zx_tmp_fi2d, cell_area, 
 !    .                     ok_msk, msk, moyglo)
 !     zx_tmp_fi2d(1:klon)=moyglo
 !
-!     CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+!     CALL gr_fi_ecrit(1, klon,nbp_lon,nbp_lat,zx_tmp_fi2d,zx_tmp_2d)
 !     CALL histwrite(nid_day_seri,"SnowFrac",
-!    .               itau_w,zx_tmp_2d,iim*jjmp1,ndex2d) 
+!    .               itau_w,zx_tmp_2d,nbp_lon*nbp_lat,ndex2d) 
 !
 !     DO i=1, klon
@@ -208,11 +208,11 @@
 !     ok_msk=.TRUE.
 !     msk(1:klon)=pctsrf(1:klon,is_ter)
-!     CALL moyglo_pondaire(klon, zx_tmp_fi2d, airephy, 
+!     CALL moyglo_pondaire(klon, zx_tmp_fi2d, cell_area, 
 !    .     ok_msk, msk, moyglo)
 !     zx_tmp_fi2d(1:klon)=moyglo
 !
-!     CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+!     CALL gr_fi_ecrit(1, klon,nbp_lon,nbp_lat,zx_tmp_fi2d,zx_tmp_2d)
 !     CALL histwrite(nid_day_seri,"snow_depth",itau_w,
-!    .               zx_tmp_2d,iim*jjmp1,ndex2d)
+!    .               zx_tmp_2d,nbp_lon*nbp_lat,ndex2d)
 !
       DO i=1, klon
@@ -222,11 +222,11 @@
       ok_msk=.TRUE.
       msk(1:klon)=pctsrf(1:klon,is_oce)
-      CALL moyglo_pondaire(klon, zx_tmp_fi2d, airephy,  &
-           ok_msk, msk, moyglo)
-      zx_tmp_fi2d(1:klon)=moyglo
-!
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
+      CALL moyglo_pondaire(klon, zx_tmp_fi2d, cell_area,  &
+           ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+!
+      CALL gr_fi_ecrit(1, klon,nbp_lon,nbp_lat, zx_tmp_fi2d, zx_tmp_2d)
       CALL histwrite(nid_day_seri,"tsol_"//clnsurf(is_oce), &
-                     itau_w,zx_tmp_2d,iim*jjmp1,ndex2d) 
+                     itau_w,zx_tmp_2d,nbp_lon*nbp_lat,ndex2d) 
 !
 !=================================================================
Index: /LMDZ5/branches/testing/libf/phylmd/write_paramLMDZ_phy.h
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/write_paramLMDZ_phy.h	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/write_paramLMDZ_phy.h	(revision 2408)
@@ -2,24 +2,24 @@
 ! calcul moyennes globales
 !
-       zx_tmp_fi2d=bils*airephy
-       CALL global_mean(zx_tmp_fi2d,airephy,.TRUE.,gbils)
-       zx_tmp_fi2d=evap*airephy
-       CALL global_mean(zx_tmp_fi2d,airephy,.TRUE.,gevap)
-       zx_tmp_fi2d(:)=fevap(:, is_ter)*airephy(:)
-       CALL global_mean(zx_tmp_fi2d,airephy,.TRUE.,gevapt)
-       zx_tmp_fi2d=zxfluxlat*airephy
-       CALL global_mean(zx_tmp_fi2d,airephy,.TRUE.,glat)
-       zx_tmp_fi2d=(topsw0-toplw0)*airephy
-       CALL global_mean(zx_tmp_fi2d,airephy,.TRUE.,gnet0)
-       zx_tmp_fi2d=(topsw-toplw)*airephy
-       CALL global_mean(zx_tmp_fi2d,airephy,.TRUE.,gnet)
-       zx_tmp_fi2d=(rain_fall+snow_fall)*airephy
-       CALL global_mean(zx_tmp_fi2d,airephy,.TRUE.,grain)
-       zx_tmp_fi2d=zxtsol*airephy
-       CALL global_mean(zx_tmp_fi2d,airephy,.TRUE.,gtsol)
-       zx_tmp_fi2d=zt2m*airephy
-       CALL global_mean(zx_tmp_fi2d,airephy,.TRUE.,gt2m)
-       zx_tmp_fi2d=prw*airephy
-       CALL global_mean(zx_tmp_fi2d,airephy,.TRUE.,gprw)
+       zx_tmp_fi2d=bils*cell_area
+       CALL global_mean(zx_tmp_fi2d,cell_area,.TRUE.,gbils)
+       zx_tmp_fi2d=evap*cell_area
+       CALL global_mean(zx_tmp_fi2d,cell_area,.TRUE.,gevap)
+       zx_tmp_fi2d(:)=fevap(:, is_ter)*cell_area(:)
+       CALL global_mean(zx_tmp_fi2d,cell_area,.TRUE.,gevapt)
+       zx_tmp_fi2d=zxfluxlat*cell_area
+       CALL global_mean(zx_tmp_fi2d,cell_area,.TRUE.,glat)
+       zx_tmp_fi2d=(topsw0-toplw0)*cell_area
+       CALL global_mean(zx_tmp_fi2d,cell_area,.TRUE.,gnet0)
+       zx_tmp_fi2d=(topsw-toplw)*cell_area
+       CALL global_mean(zx_tmp_fi2d,cell_area,.TRUE.,gnet)
+       zx_tmp_fi2d=(rain_fall+snow_fall)*cell_area
+       CALL global_mean(zx_tmp_fi2d,cell_area,.TRUE.,grain)
+       zx_tmp_fi2d=zxtsol*cell_area
+       CALL global_mean(zx_tmp_fi2d,cell_area,.TRUE.,gtsol)
+       zx_tmp_fi2d=zt2m*cell_area
+       CALL global_mean(zx_tmp_fi2d,cell_area,.TRUE.,gt2m)
+       zx_tmp_fi2d=prw*cell_area
+       CALL global_mean(zx_tmp_fi2d,cell_area,.TRUE.,gprw)
 !
 !$OMP MASTER
@@ -27,5 +27,5 @@
 !
       ndex2d = 0
-      itau_w = itau_phy + itap + int(start_time * day_step / iphysiq)
+      itau_w = itau_phy + itap + int(start_time * day_step_phy)
 !
 ! Variables globales
Index: DZ5/branches/testing/libf/phylmd/wstats.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/wstats.F90	(revision 2407)
+++ 	(revision )
@@ -1,351 +1,0 @@
-subroutine wstats(ngrid,nom,titre,unite,dim,px)
-
-implicit none
-
-#include "dimensions.h"
-#include "statto.h"
-#include "netcdf.inc"
-
-integer,intent(in) :: ngrid
-character (len=*),intent(in) :: nom,titre,unite
-integer,intent(in) :: dim
-real, dimension(ngrid,llm),intent(in) :: px
-integer,parameter :: iip1=iim+1
-integer,parameter :: jjp1=jjm+1
-real, dimension(iip1,jjp1,llm) :: mean3d,sd3d,dx3
-real, dimension(iip1,jjp1) :: mean2d,sd2d,dx2
-character (len=50) :: namebis
-character (len=50), save :: firstvar
-integer :: ierr,varid,nbdim,nid
-integer :: meanid,sdid
-integer, dimension(4)  :: id,start,size
-logical, save :: firstcall=.TRUE.
-integer :: l,i,j,ig0
-integer,save :: index
-
-integer, save :: step=0
-
-
-if (firstcall) then
-   firstcall=.false.
-   firstvar=trim((nom))
-   call inistats(ierr)
-endif
-
-if (firstvar==nom) then ! If we're back to the first variable
-      step = step + 1
-endif
-
-if (mod(step,istats).ne.0) then
-   RETURN
-endif
-
-ierr = NF_OPEN("stats.nc",NF_WRITE,nid)
-
-namebis=trim(nom)
-ierr= NF_INQ_VARID(nid,namebis,meanid)
-
-if (ierr.ne.NF_NOERR) then
-
-   if (firstvar==nom) then 
-      index=1
-      count=0
-   endif
-
-
-!declaration de la variable
-
-! choix du nom des coordonnees
-   ierr= NF_INQ_DIMID(nid,"longitude",id(1))
-   ierr= NF_INQ_DIMID(nid,"latitude",id(2))
-   if (dim.eq.3) then
-      ierr= NF_INQ_DIMID(nid,"altitude",id(3))
-      ierr= NF_INQ_DIMID(nid,"Time",id(4))
-      nbdim=4
-   else if (dim==2) then
-      ierr= NF_INQ_DIMID(nid,"Time",id(3))
-      nbdim=3
-   endif
-
-   write (*,*) "====================="
-   write (*,*) "STATS: creation de ",nom
-   namebis=trim(nom)
-   call def_var_stats(nid,namebis,titre,unite,nbdim,id,meanid,ierr)
-   call inivar(nid,meanid,ngrid,dim,index,px,ierr)
-   namebis=trim(nom)//"_sd"
-   call def_var_stats(nid,namebis,trim(titre)//" total standard deviation over the season",unite,nbdim,id,sdid,ierr)
-   call inivar(nid,sdid,ngrid,dim,index,px,ierr)
-
-   ierr= NF_CLOSE(nid)
-   return
-
-else
-   namebis=trim(nom)//"_sd"
-   ierr= NF_INQ_VARID(nid,namebis,sdid)
-
-endif
-
-if (firstvar==nom) then 
-   count(index)=count(int(index))+1
-   index=index+1
-   if (index>istime) then
-      index=1
-   endif
-endif
-
-if (count(index)==0) then
-   if (dim.eq.3) then
-      start=(/1,1,1,index/)
-      size=(/iip1,jjp1,llm,1/)
-      mean3d=0
-      sd3d=0
-   else if (dim.eq.2) then
-      start=(/1,1,index,0/)
-      size=(/iip1,jjp1,1,0/)
-      mean2d=0
-      sd2d=0
-   endif
-else
-   if (dim.eq.3) then
-      start=(/1,1,1,index/)
-      size=(/iip1,jjp1,llm,1/)
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,size,mean3d)
-      ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,size,sd3d)
-#else
-      ierr = NF_GET_VARA_REAL(nid,meanid,start,size,mean3d)
-      ierr = NF_GET_VARA_REAL(nid,sdid,start,size,sd3d)
-#endif
-      if (ierr.ne.NF_NOERR) then
-         write (*,*) NF_STRERROR(ierr)
-         stop ""
-      endif
-
-   else if (dim.eq.2) then
-      start=(/1,1,index,0/)
-      size=(/iip1,jjp1,1,0/)
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,size,mean2d)
-      ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,size,sd2d)
-#else
-      ierr = NF_GET_VARA_REAL(nid,meanid,start,size,mean2d)
-      ierr = NF_GET_VARA_REAL(nid,sdid,start,size,sd2d)
-#endif
-      if (ierr.ne.NF_NOERR) then
-         write (*,*) NF_STRERROR(ierr)
-         stop ""
-      endif
-   endif
-endif
-
-if (dim.eq.3) then
-
-!  Passage variable physique -->  variable dynamique
-
-   DO l=1,llm
-      DO i=1,iip1
-         dx3(i,1,l)=px(1,l)
-         dx3(i,jjp1,l)=px(ngrid,l)
-      ENDDO
-      DO j=2,jjm
-         ig0= 1+(j-2)*iim
-         DO i=1,iim
-            dx3(i,j,l)=px(ig0+i,l)
-         ENDDO
-         dx3(iip1,j,l)=dx3(1,j,l)
-      ENDDO
-   ENDDO
-
-   mean3d(:,:,:)= mean3d(:,:,:)+dx3(:,:,:)
-   sd3d(:,:,:)= sd3d(:,:,:)+dx3(:,:,:)**2
-
-#ifdef NC_DOUBLE
-   ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,size,mean3d)
-   ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,size,sd3d)
-#else
-   ierr = NF_PUT_VARA_REAL(nid,meanid,start,size,mean3d)
-   ierr = NF_PUT_VARA_REAL(nid,sdid,start,size,sd3d)
-#endif
-   if (ierr.ne.NF_NOERR) then
-     write (*,*) NF_STRERROR(ierr)
-     stop ""
-   endif
-
-else if (dim.eq.2) then
-
-!    Passage variable physique -->  physique dynamique
-
-  DO i=1,iip1
-     dx2(i,1)=px(1,1)
-     dx2(i,jjp1)=px(ngrid,1)
-  ENDDO
-  DO j=2,jjm
-     ig0= 1+(j-2)*iim
-     DO i=1,iim
-        dx2(i,j)=px(ig0+i,1)
-     ENDDO
-     dx2(iip1,j)=dx2(1,j)
-  ENDDO
-
-   mean2d(:,:)= mean2d(:,:)+dx2(:,:)
-   sd2d(:,:)= sd2d(:,:)+dx2(:,:)**2
-
-#ifdef NC_DOUBLE
-   ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,size,mean2d)
-   ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,size,sd2d)
-#else
-   ierr = NF_PUT_VARA_REAL(nid,meanid,start,size,mean2d)
-   ierr = NF_PUT_VARA_REAL(nid,sdid,start,size,sd2d)
-#endif
-   if (ierr.ne.NF_NOERR) then
-     write (*,*) NF_STRERROR(ierr)
-     stop ""
-   endif
-
-endif
-
-ierr= NF_CLOSE(nid)
-
-end subroutine wstats
-
-!======================================================
-subroutine inivar(nid,varid,ngrid,dim,index,px,ierr)
-
-implicit none
-
-include "dimensions.h"
-!!!!!!include "dimphys.h"
-include "netcdf.inc"
-
-integer, intent(in) :: nid,varid,dim,index,ngrid
-real, dimension(ngrid,llm), intent(in) :: px
-integer, intent(out) :: ierr
-
-integer,parameter :: iip1=iim+1
-integer,parameter :: jjp1=jjm+1
-
-integer :: l,i,j,ig0
-integer, dimension(4) :: start,size
-real, dimension(iip1,jjp1,llm) :: dx3
-real, dimension(iip1,jjp1) :: dx2
-
-if (dim.eq.3) then
-
-   start=(/1,1,1,index/)
-   size=(/iip1,jjp1,llm,1/)
-
-!  Passage variable physique -->  variable dynamique
-
-   DO l=1,llm
-      DO i=1,iip1
-         dx3(i,1,l)=px(1,l)
-         dx3(i,jjp1,l)=px(ngrid,l)
-      ENDDO
-      DO j=2,jjm
-         ig0= 1+(j-2)*iim
-         DO i=1,iim
-            dx3(i,j,l)=px(ig0+i,l)
-         ENDDO
-         dx3(iip1,j,l)=dx3(1,j,l)
-      ENDDO
-   ENDDO
-
-#ifdef NC_DOUBLE
-   ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,dx3)
-#else
-   ierr = NF_PUT_VARA_REAL(nid,varid,start,size,dx3)
-#endif
-
-else if (dim.eq.2) then
-
-      start=(/1,1,index,0/)
-      size=(/iip1,jjp1,1,0/)
-
-!    Passage variable physique -->  physique dynamique
-
-  DO i=1,iip1
-     dx2(i,1)=px(1,1)
-     dx2(i,jjp1)=px(ngrid,1)
-  ENDDO
-  DO j=2,jjm
-     ig0= 1+(j-2)*iim
-     DO i=1,iim
-        dx2(i,j)=px(ig0+i,1)
-     ENDDO
-     dx2(iip1,j)=dx2(1,j)
-  ENDDO
-
-#ifdef NC_DOUBLE
-   ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,dx2)
-#else
-   ierr = NF_PUT_VARA_REAL(nid,varid,start,size,dx2)
-#endif
-
-endif
-
-end subroutine inivar
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-subroutine def_var_stats(nid,name,title,units,nbdim,dimids,nvarid,ierr)
-
-! This subroutine defines variable 'name' in a (pre-existing and opened)
-! NetCDF file (known from its NetCDF ID 'nid').
-! The number of dimensions 'nbdim' of the variable, as well as the IDs of
-! corresponding dimensions must be set (in array 'dimids').
-! Upon successfull definition of the variable, 'nvarid' contains the
-! NetCDF ID of the variable.
-! The variables' attributes 'title' (Note that 'long_name' would be more
-! appropriate) and 'units' are also set. 
-
-implicit none
-
-#include "netcdf.inc"
-
-integer,intent(in) :: nid ! NetCDF file ID
-character(len=*),intent(in) :: name ! the variable's name
-character(len=*),intent(in) :: title ! 'title' attribute of variable
-character(len=*),intent(in) :: units ! 'units' attribute of variable
-integer,intent(in) :: nbdim ! number of dimensions of the variable
-integer,dimension(nbdim),intent(in) :: dimids ! NetCDF IDs of the dimensions
-                                              ! the variable is defined along
-integer,intent(out) :: nvarid ! NetCDF ID of the variable
-integer,intent(out) :: ierr ! returned NetCDF staus code
-
-! 1. Switch to NetCDF define mode 
-ierr=NF_REDEF(nid)
-
-! 2. Define the variable
-#ifdef NC_DOUBLE
-ierr = NF_DEF_VAR (nid,adjustl(name),NF_DOUBLE,nbdim,dimids,nvarid)
-#else
-ierr = NF_DEF_VAR (nid,adjustl(name),NF_FLOAT,nbdim,dimids,nvarid)
-#endif
-if(ierr/=NF_NOERR) then
-   write(*,*) "def_var_stats: Failed defining variable "//trim(name)
-   write(*,*) NF_STRERROR(ierr)
-   stop ""
-endif
-
-! 3. Write attributes
-ierr=NF_PUT_ATT_TEXT(nid,nvarid,"title",&
-                     len_trim(adjustl(title)),adjustl(title))
-if(ierr/=NF_NOERR) then
-   write(*,*) "def_var_stats: Failed writing title attribute for "//trim(name)
-   write(*,*) NF_STRERROR(ierr)
-   stop ""
-endif
-
-ierr=NF_PUT_ATT_TEXT(nid,nvarid,"units",&
-                     len_trim(adjustl(units)),adjustl(units))
-if(ierr/=NF_NOERR) then
-   write(*,*) "def_var_stats: Failed writing units attribute for "//trim(name)
-   write(*,*) NF_STRERROR(ierr)
-   stop ""
-endif
-
-! 4. Switch out of NetCDF define mode
-ierr = NF_ENDDEF(nid)
-
-end subroutine def_var_stats
-
Index: /LMDZ5/branches/testing/libf/phylmd/yamada.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/yamada.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/yamada.F90	(revision 2408)
@@ -6,8 +6,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! .......................................................................
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! .......................................................................
 
   ! dt : pas de temps
Index: /LMDZ5/branches/testing/libf/phylmd/yamada4.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/yamada4.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/yamada4.F90	(revision 2408)
@@ -5,10 +5,6 @@
     cd, q2, km, kn, kq, ustar, iflag_pbl)
   USE dimphy
+  USE print_control_mod, ONLY: prt_level
   IMPLICIT NONE
-  include "iniprint.h"
-  ! .......................................................................
-  ! ym#include "dimensions.h"
-  ! ym#include "dimphy.h"
-  ! .......................................................................
 
   ! dt : pas de temps
@@ -344,10 +340,12 @@
     ! print*,'Longueur ',l(:,:)
     DO k = 2, klev - 1
-      l(:, k) = max(l(:,k), 1.)
-      km(:, k) = l(:, k)*sqrt(q2(:,k))*sm(:, k)
-      q2(:, k) = q2(:, k) + dt*km(:, k)*m2(:, k)*(1.-rif(:,k))
-      q2(:, k) = min(max(q2(:,k),1.E-10), 1.E4)
-      q2(:, k) = 1./(1./sqrt(q2(:,k))+dt/(2*l(:,k)*b1))
-      q2(:, k) = q2(:, k)*q2(:, k)
+      DO ig = 1, ngrid
+        l(ig, k) = max(l(ig,k), 1.)
+        km(ig, k) = l(ig, k)*sqrt(q2(ig,k))*sm(ig, k)
+        q2(ig, k) = q2(ig, k) + dt*km(ig, k)*m2(ig, k)*(1.-rif(ig,k))
+        q2(ig, k) = min(max(q2(ig,k),1.E-10), 1.E4)
+        q2(ig, k) = 1./(1./sqrt(q2(ig,k))+dt/(2*l(ig,k)*b1))
+        q2(ig, k) = q2(ig, k)*q2(ig, k)
+      END DO
     END DO
 
@@ -496,8 +494,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! .......................................................................
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
-  ! .......................................................................
 
   ! dt : pas de temps
@@ -572,8 +566,4 @@
   USE dimphy
   IMPLICIT NONE
-  ! .......................................................................
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
-  ! .......................................................................
 
   ! dt : pas de temps
Index: /LMDZ5/branches/testing/libf/phylmd/yamada_c.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phylmd/yamada_c.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phylmd/yamada_c.F90	(revision 2408)
@@ -5,12 +5,8 @@
      &   ,pu,pv,pt,d_u,d_v,d_t,cd,q2,km,kn,kq,d_t_diss,ustar &
      &   ,iflag_pbl,okiophys)
-      use dimphy
+      USE dimphy, ONLY: klon, klev
+      USE print_control_mod, ONLY: prt_level
       IMPLICIT NONE
-#include "iniprint.h"
 #include "YOMCST.h"
-!.......................................................................
-!ym#include "dimensions.h"
-!ym#include "dimphy.h"
-!.......................................................................
 !
 ! timestep : pas de temps
@@ -117,5 +113,6 @@
       real w2yam(klon,klev),t2yam(klon,klev)
       logical,save :: firstcall=.true.
-
+!$OMP THREADPRIVATE(firstcall)       
+      CHARACTER(len=20),PARAMETER :: modname="yamada_c"
 REAL, DIMENSION(klon,klev+1) :: fluxu,fluxv,fluxt
 REAL, DIMENSION(klon,klev+1) :: dddu,dddv,dddt
@@ -123,5 +120,4 @@
 REAL, DIMENSION(klon,klev+1) :: masseb,q2old,q2neg
 
-!$OMP THREADPRIVATE(firstcall)       
       frif(ri)=0.6588*(ri+0.1776-sqrt(ri*ri-0.3221*ri+0.03156))
       falpha(ri)=1.318*(0.2231-ri)/(0.2341-ri)
@@ -575,5 +571,5 @@
 
       else
-         stop'Cas nom prevu dans yamada4'
+         CALL abort_physic(modname,'Cas nom prevu dans yamada4',1)
 
       endif ! Fin du cas 8
Index: /LMDZ5/branches/testing/libf/phymar/Mod_PHY_AT_kkl.f90
===================================================================
--- /LMDZ5/branches/testing/libf/phymar/Mod_PHY_AT_kkl.f90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phymar/Mod_PHY_AT_kkl.f90	(revision 2408)
@@ -88,5 +88,6 @@
       real(kind=real8), SAVE,ALLOCATABLE ,dimension(:)    ::  P___AT  ! Auxiliary   Term               P                           [-]
       real(kind=real8), SAVE,ALLOCATABLE ,dimension(:)    ::  Q___AT  ! Auxiliary   Term               Q                           [-]
-      real*16         ,ALLOCATABLE ,dimension(:)    ::  X___AT  ! Auxiliary   Unknown            X                           [x]
+!      real*16         ,ALLOCATABLE ,dimension(:)    ::  X___AT  ! Auxiliary   Unknown            X                           [x]
+      double precision,ALLOCATABLE ,dimension(:)    ::  X___AT  ! Auxiliary   Unknown            X                           [x]
 
       real(kind=real8), SAVE,ALLOCATABLE ,dimension(:)    ::  LMO_AT  ! Monin-Obukhov     Length         (Grid Cell Average)       [m]
Index: DZ5/branches/testing/libf/phymar/comgeomphy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phymar/comgeomphy.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../phylmd/comgeomphy.F90
Index: /LMDZ5/branches/testing/libf/phymar/infotrac_phy.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phymar/infotrac_phy.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phymar/infotrac_phy.F90	(revision 2408)
@@ -0,0 +1,32 @@
+
+! $Id: $
+
+MODULE infotrac_phy
+
+! Infotrac for physics; for now contains the same information as infotrac for
+! the dynamics (could be further cleaned) and is initialized using values
+! provided by the dynamics
+
+! nqtot : total number of tracers and higher order of moment, water vapor and liquid included
+  INTEGER, SAVE :: nqtot
+!$OMP THREADPRIVATE(nqtot)
+ 
+CONTAINS
+
+  SUBROUTINE init_infotrac_phy(nqtot_)
+  ! transfer information on tracers from dynamics to physics
+  USE print_control_mod, ONLY: prt_level, lunout
+  IMPLICIT NONE
+    INTEGER,INTENT(IN) :: nqtot_
+
+    CHARACTER(LEN=30) :: modname="init_infotrac_phy"
+
+    nqtot=nqtot_
+  
+    IF(prt_level.ge.1) THEN
+      write(lunout,*) TRIM(modname)//": nqtot",nqtot
+    ENDIF
+    
+  END SUBROUTINE init_infotrac_phy
+
+END MODULE infotrac_phy
Index: DZ5/branches/testing/libf/phymar/init_phys_lmdz.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phymar/init_phys_lmdz.F90	(revision 2407)
+++ 	(revision )
@@ -1,1 +1,0 @@
-link ../phylmd/init_phys_lmdz.F90
Index: DZ5/branches/testing/libf/phymar/phyaqua.F
===================================================================
--- /LMDZ5/branches/testing/libf/phymar/phyaqua.F	(revision 2407)
+++ 	(revision )
@@ -1,41 +1,0 @@
-!
-! $Id: $
-!
-
-      subroutine iniaqua(nlon,latfi,lonfi,iflag_phys)
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!  Create an initial state (startphy.nc) for the physics
-!  Usefull for idealised cases (e.g. aquaplanets or testcases)
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-      use phys_state_var_mod, only : rlat,rlon,
-     &                               phys_state_var_init
-      use mod_phys_lmdz_para, only : klon_omp
-      use comgeomphy, only : rlond,rlatd
-      implicit none
-      
-      integer,intent(in) :: nlon,iflag_phys
-      real,intent(in) :: lonfi(nlon),latfi(nlon)
-
-! local variables
-      real :: pi
-
-! initializations:
-      pi=2.*asin(1.)
-
-      call phys_state_var_init()
-
-      rlat(1:klon_omp)=rlatd(1:klon_omp)*180./pi
-      rlon(1:klon_omp)=rlond(1:klon_omp)*180./pi
-
-
-! Here you could create an initial condition for the physics
-! ...
-! ... fill in the fields...
-! ...
-! ... and create a "startphy.nc" file
-      CALL phyredem ("startphy.nc")
-
-      end
-
Index: /LMDZ5/branches/testing/libf/phymar/phyaqua_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phymar/phyaqua_mod.F90	(revision 2408)
+++ /LMDZ5/branches/testing/libf/phymar/phyaqua_mod.F90	(revision 2408)
@@ -0,0 +1,45 @@
+!
+! $Id: $
+!
+MODULE phyaqua_mod
+
+  IMPLICIT NONE
+
+CONTAINS
+
+  SUBROUTINE iniaqua(nlon, iflag_phys)
+
+  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  !  Create an initial state (startphy.nc) for the physics
+  !  Usefull for idealised cases (e.g. aquaplanets or testcases)
+  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  USE phys_state_var_mod, ONLY: rlat, rlon, phys_state_var_init
+  USE mod_phys_lmdz_para, ONLY: klon_omp
+  USE geometry_mod, ONLY: longitude_deg, latitude_deg
+  IMPLICIT NONE
+      
+  INTEGER,INTENT(IN) :: nlon,iflag_phys
+
+  ! local variables
+  REAL :: pi
+
+  ! initializations:
+  pi=2.*ASIN(1.)
+
+  CALL phys_state_var_init()
+
+  rlat(1:klon_omp)=latitude_deg(1:klon_omp)
+  rlon(1:klon_omp)=longitude_deg(1:klon_omp)
+
+
+  ! Here you could create an initial condition for the physics
+  ! ...
+  ! ... fill in the fields...
+  ! ...
+  ! ... and create a "startphy.nc" file
+      CALL phyredem ("startphy.nc")
+
+  END SUBROUTINE iniaqua
+
+END MODULE phyaqua_mod
Index: /LMDZ5/branches/testing/libf/phymar/physiq.F90
===================================================================
--- /LMDZ5/branches/testing/libf/phymar/physiq.F90	(revision 2407)
+++ /LMDZ5/branches/testing/libf/phymar/physiq.F90	(revision 2408)
@@ -11,5 +11,5 @@
      &            debut,lafin,jD_cur, jH_cur,pdtphys, &
      &            paprs,pplay,pphi,pphis,ppresnivs, &
-     &            u,v,t,qx, &
+     &            u,v,rot,t,qx, &
      &            flxmass_w, &
      &            d_u, d_v, d_t, d_qx, d_ps &
@@ -17,6 +17,6 @@
 
       USE dimphy, only : klon,klev,klevp1
-      USE infotrac, only : nqtot
-      USE comgeomphy, only : rlatd,rlond,airephy
+      USE infotrac_phy, only : nqtot
+      USE geometry_mod, only : latitude,longitude,cell_area
       !USE comcstphy, only : rg
       USE iophy, only : histbeg_phy,histwrite_phy
@@ -120,4 +120,6 @@
       real,intent(in) :: u(klon,klev) ! eastward zonal wind (m/s)
       real,intent(in) :: v(klon,klev) ! northward meridional wind (m/s)
+      REAL, intent(in):: rot(klon, klev) ! relative vorticity,
+                                         ! in s-1, needed for frontal waves
       real,intent(in) :: t(klon,klev) ! temperature (K)
       real,intent(in) :: qx(klon,klev,nqtot) ! tracers (.../kg_air)
@@ -498,11 +500,11 @@
 
 DO i=1,klon
-  IF (rlond(i) .LT. 0) THEN
-    lonh_HOST(i)=rlond(i)*12./rpi+24. ! from radians to hours
+  IF (longitude(i) .LT. 0) THEN
+    lonh_HOST(i)=longitude(i)*12./rpi+24. ! from radians to hours
    ELSE
-    lonh_HOST(i)=rlond(i)*12./rpi ! from radians to hours
+    lonh_HOST(i)=longitude(i)*12./rpi ! from radians to hours
   ENDIF
 ENDDO
-latr_HOST(:)=rlatd(:) ! from radians to radians
+latr_HOST(:)=latitude(:) ! from radians to radians
 
 !PRINT*, 'lonh_HOST(:)=',lonh_HOST(:)
@@ -689,6 +691,6 @@
 PRINT*, 'Initialisation de la temperature de surface avec les SST aquaplanète'
           DO i = 1,klon
-            Ts___HOST(i)=273.+27.*(1-sin(1.5*rlatd(i))**2)
-            IF ((rlatd(i).GT.1.0471975).OR.(rlatd(i).LT.-1.0471975)) THEN
+            Ts___HOST(i)=273.+27.*(1-sin(1.5*latitude(i))**2)
+            IF ((latitude(i).GT.1.0471975).OR.(latitude(i).LT.-1.0471975)) THEN
               Ts___HOST(i)=273.
             ENDIF
@@ -791,6 +793,6 @@
 DO k = 1, klev
   i=klev+1-k
-  !omega(i,k) = RG*flxmass_w(i,k) / airephy(i) ! omega en Pa/s
-  Wa___HOST(:,i)=flxmass_w(:,k) / airephy(:) * (gZam_HOST(:,i+1) - gZam_HOST(:,i))/(paprs(:,k+1)-paprs(:,k)) ! Equilibre hydrostatique
+  !omega(i,k) = RG*flxmass_w(i,k) / cell_area(i) ! omega en Pa/s
+  Wa___HOST(:,i)=flxmass_w(:,k) / cell_area(:) * (gZam_HOST(:,i+1) - gZam_HOST(:,i))/(paprs(:,k+1)-paprs(:,k)) ! Equilibre hydrostatique
 END DO
 Wa___HOST(:,klev)=0 ! Vitesse nulle à la surface.
@@ -853,6 +855,6 @@
 !IF (debut) THEN
   DO i=1,klon
-    sst__HOST(i)=273.+27.*(1-sin(1.5*rlatd(i))**2)
-    IF ((rlatd(i).GT.1.0471975).OR.(rlatd(i).LT.-1.0471975)) THEN
+    sst__HOST(i)=273.+27.*(1-sin(1.5*latitude(i))**2)
+    IF ((latitude(i).GT.1.0471975).OR.(latitude(i).LT.-1.0471975)) THEN
       sst__HOST(i)=273.
     ENDIF
@@ -908,6 +910,6 @@
       ikl0 = i
       PRINT*,'Attention : NaN at'
-      PRINT*,'longitude=',rlond(i)*180/rpi
-      PRINT*,'latitude=',rlatd(i)*180/rpi
+      PRINT*,'longitude=',longitude(i)*180/rpi
+      PRINT*,'latitude=',latitude(i)*180/rpi
     ENDIF
   ENDDO
Index: /LMDZ5/branches/testing/makelmdz
===================================================================
--- /LMDZ5/branches/testing/makelmdz	(revision 2407)
+++ /LMDZ5/branches/testing/makelmdz	(revision 2408)
@@ -296,7 +296,8 @@
 then
    #We'll use some physics
-   src_dirs="$src_dirs phy$physique"
+   src_dirs="$src_dirs phy_common phy$physique"
    LIBPHY='$(LIBO)/libphy'"$physique"'.a'
-   lib_phy='-lphy'"$physique"
+   LIBPHY_COMMON='$(LIBO)/libphy_common.a'
+   lib_phy='-lphy'"$physique"' -lphy_common'
    CPP_KEY="$CPP_KEY CPP_PHYS"
    if [[ $phys_root == "lmd" ]]
@@ -690,4 +691,5 @@
 "PHYS=$physique" \
 LIBPHY=${LIBPHY} \
+LIBPHY_COMMON=${LIBPHY_COMMON} \
 LIBDYN_PHYS=${LIBDYN_PHYS} \
 DIM=$dimc \
@@ -721,4 +723,5 @@
 "PHYS=$physique" \
 LIBPHY=${LIBPHY} \
+LIBPHY_COMMON=${LIBPHY_COMMON} \
 LIBDYN_PHYS=${LIBDYN_PHYS} \
 DIM=$dimc \
Index: /LMDZ5/branches/testing/makelmdz_fcm
===================================================================
--- /LMDZ5/branches/testing/makelmdz_fcm	(revision 2407)
+++ /LMDZ5/branches/testing/makelmdz_fcm	(revision 2408)
@@ -34,4 +34,5 @@
 job=1
 full=''
+libphy=false
 
 LMDGCM=`/bin/pwd`
@@ -43,4 +44,5 @@
 DYN_PHYS_PATH=$LMDGCM/.void_dir
 DYN_PHYS_SUB_PATH=$LMDGCM/.void_dir
+PHY_COMMON_PATH=$LMDGCM/.void_dir
 RRTM_PATH=$LMDGCM/.void_dir
 SISVAT_PATH=$LMDGCM/.void_dir
@@ -96,4 +98,5 @@
 [-j n]                     : active parallel compiling on ntask
 [-full]                    : full recompiling 
+[-libphy]                  : only compile physics package (no dynamics or main program)
 [-fcm_path path]           : path to the fcm tool (default: tools/fcm/bin)
 [-ext_src path]            : path to an additional set of routines to compile with the model
@@ -170,8 +173,13 @@
       "-ext_src")
 	  EXT_SRC=$2 ; shift ; shift ;;
+
       "-j")
 	  job=$2 ; shift ; shift ;;
+
       "-full")
 	  full="-full" ; shift ;;
+
+      "-libphy")
+	  libphy="true" ; shift ;;
 
       "-arch")
@@ -182,12 +190,4 @@
   esac
 done
-
-if [[ $code = ce0l && $paramem = mem ]]
-then
-    echo "There is no parallel version of ce0l at the moment."
-    echo "Please compile the sequential version of the code to produce the" \
-	"executable ce0l."
-    exit 1
-fi
 
 ###############################################################
@@ -252,4 +252,6 @@
    CPP_KEY="$CPP_KEY CPP_EARTH"
    fi
+   # set physics common utilities path
+   PHY_COMMON_PATH="${LIBFGCM}/phy_common"
    # set the dyn/phys interface path
    DYN_PHYS_PATH="${LIBFGCM}/dynlonlat_phylonlat"
@@ -541,4 +543,19 @@
 fi
 
+if [[ $libphy == "true" ]]
+then
+  # special case where we compile only the physics
+  DYN=$LMDGCM/.void_dir
+  DYN_COMMON_PATH=$LMDGCM/.void_dir
+  FILTRE_PATH=$LMDGCM/.void_dir
+  DYN_PHYS_PATH=$LMDGCM/.void_dir
+  DYN_PHYS_SUB_PATH=$LMDGCM/.void_dir
+  #and there is no main program to generate
+  code=""
+  SUFF_NAME=""
+else
+  SUFF_NAME=${SUFF_NAME}.e
+fi
+
 cd $LMDGCM
 config_fcm="config.fcm"
@@ -557,4 +574,5 @@
 echo "%DYN           $DYN"           >> $config_fcm
 echo "%DYN_COMMON    $DYN_COMMON_PATH" >> $config_fcm
+echo "%PHY_COMMON    $PHY_COMMON_PATH" >> $config_fcm
 echo "%FILTRE        $FILTRE_PATH"   >> $config_fcm
 echo "%PHYS          phy${physique}" >> $config_fcm
@@ -588,5 +606,5 @@
 rm -rf config
 ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config config
-ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config/tmp tmp_src
+ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config/ppsrc tmp_src
 
 
