Index: /LMDZ6/trunk/DefLists/context_lmdz.xml
===================================================================
--- /LMDZ6/trunk/DefLists/context_lmdz.xml	(revision 3434)
+++ /LMDZ6/trunk/DefLists/context_lmdz.xml	(revision 3435)
@@ -25,5 +25,18 @@
   <!-- Define domains and groups of domains -->
   <domain_definition>
-    <domain id="dom_glo" data_dim="2" />
+
+    <domain id="dom_glo"  data_dim="1" />
+
+    <domain id="greordered"  domain_ref="dom_glo">
+      <reorder_domain invert_lat="true" shift_lon_fraction="0.5" min_lon="0" max_lon="360" />
+    </domain> 
+   
+    <domain id="dom_regular" ni_glo="144" nj_glo="142" type="rectilinear"  >
+      <generate_rectilinear_domain/>
+      <interpolate_domain order="1"/>
+    </domain>
+   
+    <domain id="dom_out" domain_ref="dom_glo"/>
+    
   </domain_definition>
   
@@ -42,22 +55,19 @@
   <!-- Define groups of vertical axes -->
   <axis_definition>
-    <axis id="presnivs" standard_name="Vertical levels" unit="Pa">
-    </axis>
-    <axis id="Ahyb" standard_name="Ahyb comp of Hyb Cord" unit="Pa">
-    </axis> 
-    <axis id="Bhyb" standard_name="Bhyb comp of Hyb Cord" unit="">
-    </axis>
-    <axis id="Ahyb_inter" standard_name="A comp of Hyb Cord at interface" unit="Pa">
-    </axis> 
-    <axis id="Bhyb_inter" standard_name="B comp of Hyb Cord at interface" unit="">
-    </axis>
-    <axis id="Alt" standard_name="Height approx for scale heigh of 8km at levels" unit="km">
-    </axis>
-    <axis id="plev" standard_name="model_level_number" unit="Pa">
-    </axis>
-    <axis id="klev"  prec="8" long_name = "hybrid sigma pressure coordinate"
-          standard_name ="atmosphere_hybrid_sigma_pressure_coordinate" unit="1">
-    </axis>
-    <axis id="bnds" standard_name="bounds" unit="1" >
+    <axis id="time_month" n_glo="12" value="(0,11) [1 2 3 4 5 6 7 8 9 10 11 12]"/>
+    <axis id="time_year" unit="day" />
+    <axis id="presnivs" standard_name="Vertical levels" unit="Pa"/>
+    <axis id="Ahyb" standard_name="Ahyb comp of Hyb Cord" unit="Pa"/>
+    <axis id="Bhyb" standard_name="Bhyb comp of Hyb Cord" unit=""/>
+    <axis id="Ahyb_inter" standard_name="A comp of Hyb Cord at interface" unit="Pa"/>
+    <axis id="Bhyb_inter" standard_name="B comp of Hyb Cord at interface" unit=""/>
+    <axis id="Alt" standard_name="Height approx for scale heigh of 8km at levels" unit="km"/>
+    <axis id="plev" standard_name="model_level_number" unit="Pa"/>
+    <axis id="klev"  prec="8" long_name="number of layers" standard_name="number of layers" unit="1" />
+    <axis id="klevp1"  prec="8" long_name="number of layer interfaces" standard_name="number of layer interfaces" unit="1" />
+    <axis id="bnds" standard_name="bounds" unit="1" />
+    <axis id="spectband" standard_name="Sensor Band Central Radiation Wavenumber" unit="m-1"/>
+    <axis id="axis_lat" standard_name="Latitude axis">
+      <reduce_domain operation="average" direction="iDir" />
     </axis>
     <axis id="spectband" standard_name="Sensor Band Central Radiation Wavenumber" unit="m-1">
@@ -97,48 +107,95 @@
 
     <grid id="klev_bnds"> <axis axis_ref="klev" /> <axis axis_ref="bnds" /> </grid>
+    <grid id="klevp1_bnds"> <axis axis_ref="klevp1" /> <axis axis_ref="bnds" /> </grid>
 
      <grid id="grid_glo">
-        <domain id="dom_glo" />
-     </grid>
+        <domain domain_ref="dom_glo" />
+     </grid>
+
+     <grid id="grid_out">
+        <domain domain_ref="dom_out" />
+     </grid>
+
 
      <grid id="grid_glo_presnivs">
-        <domain id="dom_glo" />
-        <axis id="presnivs" />
-     </grid>
-
+        <domain domain_ref="dom_glo" />
+        <axis axis_ref="presnivs" />
+     </grid>
+
+     <grid id="grid_out_presnivs">
+        <domain domain_ref="dom_out" />
+        <axis axis_ref="presnivs" />
+     </grid>
 
      <grid id="grid_glo_plev">
-        <domain id="dom_glo" />
-        <axis id="plev" />
-     </grid>
+        <domain domain_ref="dom_glo" />
+        <axis axis_ref="plev" />
+     </grid>
+
+     <grid id="grid_out_plev">
+        <domain domain_ref="dom_out" />
+        <axis axis_ref="plev" />
+     </grid>
+
 
      <grid id="grid_glo_spectband">
-        <domain id="dom_glo" />
-        <axis id="spectband" />
-     </grid>
+        <domain domain_ref="dom_glo" />
+        <axis axis_ref="spectband" />
+     </grid>
+
+     <grid id="grid_out_spectband">
+        <domain domain_ref="dom_out" />
+        <axis axis_ref="spectband" />
+     </grid>
+
 
      <grid id="grid_glo_height">
-        <domain id="dom_glo" />
-        <axis id="height" />
+        <domain domain_ref="dom_glo" />
+        <axis axis_ref="height" />
+     </grid>
+
+     <grid id="grid_out_height">
+        <domain domain_ref="dom_out" />
+        <axis axis_ref="height" />
      </grid>
 
      <grid id="grid_glo_heightmlev">
-        <domain id="dom_glo" />
-        <axis id="height_mlev" />
+        <domain domain_ref="dom_glo" />
+        <axis axis_ref="height_mlev" />
+     </grid>
+
+     <grid id="grid_out_heightmlev">
+        <domain domain_ref="dom_out" />
+        <axis axis_ref="height_mlev" />
      </grid>
 
      <grid id="grid_glo_temp">
-        <domain id="dom_glo" />
-        <axis id="temp" />
+        <domain domain_ref="dom_glo" />
+        <axis axis_ref="temp" />
+     </grid>
+
+     <grid id="grid_gloout_temp">
+        <domain domain_ref="dom_out" />
+        <axis axis_ref="temp" />
      </grid>
 
      <grid id="grid_glo_sza">
-        <domain id="dom_glo" />
-        <axis id="sza" />
+        <domain domain_ref="dom_glo" />
+        <axis axis_ref="sza" />
+     </grid>
+
+     <grid id="grid_out_sza">
+        <domain domain_ref="dom_out" />
+        <axis axis_ref="sza" />
      </grid>
 
      <grid id="grid_glo_column">
-        <domain id="dom_glo" />
-        <axis id="column" />
+        <domain domain_ref="dom_glo" />
+        <axis axis_ref="column" />
+     </grid>
+
+     <grid id="grid_out_column">
+        <domain domain_ref="dom_out" />
+        <axis axis_ref="column" />
      </grid>
 
Index: /LMDZ6/trunk/arch/arch-X64_IRENE.fcm
===================================================================
--- /LMDZ6/trunk/arch/arch-X64_IRENE.fcm	(revision 3434)
+++ /LMDZ6/trunk/arch/arch-X64_IRENE.fcm	(revision 3435)
@@ -11,4 +11,5 @@
 %DEV_FFLAGS          -fp-model strict -p -g -O2 -traceback -fp-stack-check
 %DEBUG_FFLAGS        -fp-model strict -p -g -traceback -fp-stack-check -ftrapuv
+#%DEBUG_FFLAGS        -fp-model strict -p -g -traceback -fp-stack-check -ftrapuv -check bounds,noarg_temp_created,pointers,stack,uninit -debug full -init=arrays -init=snan
 %MPI_FFLAGS
 %OMP_FFLAGS          -qopenmp
Index: /LMDZ6/trunk/libf/dyn3d/gcm.F90
===================================================================
--- /LMDZ6/trunk/libf/dyn3d/gcm.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dyn3d/gcm.F90	(revision 3435)
@@ -241,4 +241,5 @@
        'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
   if (.not.read_start) then
+     annee_ref=anneeref
      CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
   endif
@@ -377,4 +378,28 @@
        tetagdiv, tetagrot , tetatemp, vert_prof_dissip)
 
+  !  numero de stockage pour les fichiers de redemarrage:
+
+  !-----------------------------------------------------------------------
+  !   Initialisation des I/O :
+  !   ------------------------
+
+
+  if (nday>=0) then
+     day_end = day_ini + nday
+  else
+     day_end = day_ini - nday/day_step
+  endif
+  WRITE(lunout,300)day_ini,day_end
+300 FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
+
+#ifdef CPP_IOIPSL
+  call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
+  write (lunout,301)jour, mois, an
+  call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
+  write (lunout,302)jour, mois, an
+301 FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
+302 FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
+#endif
+
   !-----------------------------------------------------------------------
   !   Initialisation de la physique :
@@ -391,28 +416,4 @@
 #endif
   ENDIF ! of IF ((iflag_phys==1).or.(iflag_phys>=100))
-
-  !  numero de stockage pour les fichiers de redemarrage:
-
-  !-----------------------------------------------------------------------
-  !   Initialisation des I/O :
-  !   ------------------------
-
-
-  if (nday>=0) then
-     day_end = day_ini + nday
-  else
-     day_end = day_ini - nday/day_step
-  endif
-  WRITE(lunout,300)day_ini,day_end
-300 FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
-
-#ifdef CPP_IOIPSL
-  call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
-  write (lunout,301)jour, mois, an
-  call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
-  write (lunout,302)jour, mois, an
-301 FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
-302 FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
-#endif
 
   !      if (planet_type.eq."earth") then
Index: /LMDZ6/trunk/libf/dyn3dmem/caladvtrac_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/dyn3dmem/caladvtrac_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dyn3dmem/caladvtrac_mod.F90	(revision 3435)
@@ -44,5 +44,7 @@
     CALL allocate_u(massem,llm,d)
     CALL allocate_u(pbaruc,llm,d)
+    pbaruc(:,:)=0
     CALL allocate_v(pbarvc,llm,d)
+    pbarvc(:,:)=0
     CALL allocate_u(pbarug,llm,d)
     CALL allocate_v(pbarvg,llm,d)
Index: /LMDZ6/trunk/libf/dyn3dmem/call_calfis_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/dyn3dmem/call_calfis_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dyn3dmem/call_calfis_mod.F90	(revision 3435)
@@ -52,5 +52,7 @@
     CALL allocate_u(p,llmp1,d)
     CALL allocate_u(pks,d)
+    pks(:)=0
     CALL allocate_u(pk,llm,d)
+    pk(:,:)=0
     CALL allocate_u(pkf,llm,d)
     CALL allocate_u(phi,llm,d)
Index: /LMDZ6/trunk/libf/dyn3dmem/call_dissip_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/dyn3dmem/call_dissip_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dyn3dmem/call_dissip_mod.F90	(revision 3435)
@@ -31,5 +31,7 @@
 
     CALL allocate_u(ucov,llm,d)
+    ucov(:,:)=0
     CALL allocate_v(vcov,llm,d)
+    vcov(:,:)=0
     CALL allocate_u(teta,llm,d)
     CALL allocate_u(p,llmp1,d)
Index: /LMDZ6/trunk/libf/dyn3dmem/gcm.F90
===================================================================
--- /LMDZ6/trunk/libf/dyn3dmem/gcm.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dyn3dmem/gcm.F90	(revision 3435)
@@ -233,4 +233,5 @@
        'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
   if (.not.read_start) then
+     annee_ref=anneeref
      CALL iniacademic_loc(vcov,ucov,teta,q,masse,ps,phis,time_0)
   endif
@@ -368,4 +369,27 @@
 
   !-----------------------------------------------------------------------
+  !   Initialisation des I/O :
+  !   ------------------------
+
+
+  if (nday>=0) then
+     day_end = day_ini + nday
+  else
+     day_end = day_ini - nday/day_step
+  endif
+
+  WRITE(lunout,300)day_ini,day_end
+300 FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
+
+#ifdef CPP_IOIPSL
+  call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
+  write (lunout,301)jour, mois, an
+  call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
+  write (lunout,302)jour, mois, an
+301 FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
+302 FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
+#endif
+
+  !-----------------------------------------------------------------------
   !   Initialisation de la physique :
   !   -------------------------------
@@ -381,27 +405,4 @@
   ENDIF ! of IF ((iflag_phys==1).or.(iflag_phys>=100))
 
-
-  !-----------------------------------------------------------------------
-  !   Initialisation des I/O :
-  !   ------------------------
-
-
-  if (nday>=0) then
-     day_end = day_ini + nday
-  else
-     day_end = day_ini - nday/day_step
-  endif
-
-  WRITE(lunout,300)day_ini,day_end
-300 FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
-
-#ifdef CPP_IOIPSL
-  call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
-  write (lunout,301)jour, mois, an
-  call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
-  write (lunout,302)jour, mois, an
-301 FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
-302 FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
-#endif
 
   !      if (planet_type.eq."earth") then
Index: /LMDZ6/trunk/libf/dyn3dmem/iniacademic_loc.F90
===================================================================
--- /LMDZ6/trunk/libf/dyn3dmem/iniacademic_loc.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dyn3dmem/iniacademic_loc.F90	(revision 3435)
@@ -101,5 +101,5 @@
   time_0=0.
   day_ref=1
-  annee_ref=0
+  ! annee_ref=0
 
   im         = iim
Index: /LMDZ6/trunk/libf/dyn3dmem/integrd_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/dyn3dmem/integrd_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dyn3dmem/integrd_mod.F90	(revision 3435)
@@ -23,4 +23,5 @@
     CALL allocate_u(deltap,llm,d)
     CALL allocate_u(ps,d)
+    ps(:)=0
 
     
Index: /LMDZ6/trunk/libf/dyn3dmem/vlsplt_loc.F
===================================================================
--- /LMDZ6/trunk/libf/dyn3dmem/vlsplt_loc.F	(revision 3434)
+++ /LMDZ6/trunk/libf/dyn3dmem/vlsplt_loc.F	(revision 3435)
@@ -19,4 +19,5 @@
       include "dimensions.h"
       include "paramet.h"
+      include "iniprint.h"
 c
 c
@@ -872,4 +873,5 @@
       include "dimensions.h"
       include "paramet.h"
+      include "iniprint.h"
 c
 c
@@ -1027,5 +1029,7 @@
       ELSE ! countcfl>=1
 
-      PRINT*,'vlz passage dans le non local'
+      IF (prt_level>9) THEN
+        WRITE(lunout,*)'vlz passage dans le non local'
+      ENDIF
 c ---------------------------------------------------------------
 c  Debut du traitement du cas ou on viole le CFL : w > masse
@@ -1059,5 +1063,7 @@
 c  le critère
       DO WHILE (countcfl>=1) 
-      print*,'On viole le CFL Vertical sur ',countcfl,' pts'
+        IF (prt_level>9) THEN
+          WRITE(lunout,*)'On viole le CFL Vertical sur ',countcfl,' pts'
+        ENDIF
       countcfl=0
 
Index: /LMDZ6/trunk/libf/dynphy_lonlat/inigeomphy_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/dynphy_lonlat/inigeomphy_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dynphy_lonlat/inigeomphy_mod.F90	(revision 3435)
@@ -76,5 +76,6 @@
   REAL,ALLOCATABLE,SAVE :: boundslonfi(:,:)
   REAL,ALLOCATABLE,SAVE :: boundslatfi(:,:)
-!$OMP THREADPRIVATE (latfi,lonfi,cufi,cvfi,airefi,boundslonfi,boundslatfi)
+  INTEGER,ALLOCATABLE,SAVE :: ind_cell_glo_fi(:)
+!$OMP THREADPRIVATE (latfi,lonfi,cufi,cvfi,airefi,boundslonfi,boundslatfi,ind_cell_glo_fi)
 
   ! Initialize Physics distibution and parameters and interface with dynamics
@@ -93,6 +94,6 @@
   
   DO i=1,iim
+   boundslon_reg(i,east)=rlonu(i+1) 
    boundslon_reg(i,west)=rlonu(i) 
-   boundslon_reg(i,east)=rlonu(i+1) 
   ENDDO
 
@@ -204,4 +205,5 @@
   ALLOCATE(boundslonfi(klon_omp,4))
   ALLOCATE(boundslatfi(klon_omp,4))
+  ALLOCATE(ind_cell_glo_fi(klon_omp))
 
 
@@ -214,8 +216,9 @@
   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,:)
+  ind_cell_glo_fi(1:klon_omp)=(/ (i,i=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)
+                     airefi,ind_cell_glo_fi,cufi,cvfi)
 
   ! copy over preff , ap(), bp(), etc 
Index: /LMDZ6/trunk/libf/dynphy_lonlat/phydev/iniphysiq_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/dynphy_lonlat/phydev/iniphysiq_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dynphy_lonlat/phydev/iniphysiq_mod.F90	(revision 3435)
@@ -71,7 +71,4 @@
   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)
Index: /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/etat0dyn_netcdf.F90
===================================================================
--- /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/etat0dyn_netcdf.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/etat0dyn_netcdf.F90	(revision 3435)
@@ -100,5 +100,6 @@
 
   deg2rad = pi/180.0
-
+  y(:,:,:)=0  !ym warning unitialized variable
+  
 ! Compute psol AND tsol, knowing phis.
 !*******************************************************************************
Index: /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/etat0phys_netcdf.F90
===================================================================
--- /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/etat0phys_netcdf.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/etat0phys_netcdf.F90	(revision 3435)
@@ -44,5 +44,5 @@
     zmax0,fevap, rnebcon,falb_dir, wake_fip,    agesno,  detr_therm, pbl_tke,  &
     phys_state_var_init, ql_ancien, qs_ancien, prlw_ancien, prsw_ancien, &
-    prw_ancien
+    prw_ancien, sollwdown
   USE comconst_mod, ONLY: pi, dtvr
 
@@ -201,4 +201,6 @@
   solsw      = 165.
   sollw      = -53.
+!ym warning missing init for sollwdown => set to 0
+  sollwdown  = 0.
   t_ancien   = 273.15
   q_ancien   = 0.
@@ -315,5 +317,8 @@
   ALLOCATE(zmea0(iml,jml),zstd0(iml,jml)) !--- Mean orography and std deviation
   ALLOCATE(zsig0(iml,jml),zgam0(iml,jml)) !--- Slope and nisotropy
+  zsig0(:,:)=0   !ym uninitialized variable
+  zgam0(:,:)=0   !ym uninitialized variable
   ALLOCATE(zthe0(iml,jml))                !--- Highest slope orientation
+  zthe0(:,:)=0   !ym uninitialized variable
   ALLOCATE(zpic0(iml,jml),zval0(iml,jml)) !--- Peaks and valley heights
 
Index: /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/dynphy_lonlat/phylmd/iniphysiq_mod.F90	(revision 3435)
@@ -35,4 +35,5 @@
   USE phystokenc_mod, ONLY: init_phystokenc
   USE phyaqua_mod, ONLY: iniaqua
+  USE comconst_mod, ONLY: omeg, rad
 #ifdef INCA
   USE indice_sol_mod, ONLY: nbsrf, is_oce, is_sic, is_ter, is_lic
@@ -118,5 +119,5 @@
 
   ! Initialize dimphy module (unless in 1D where it has already been done)
-  IF (klon_glo>1) CALL Init_dimphy(klon_omp,nlayer)
+!  IF (klon_glo>1) CALL Init_dimphy(klon_omp,nlayer)
 
   ! Copy over "offline" settings
@@ -134,5 +135,5 @@
                                   cu,cuvsurcv,cv,cvusurcu, &
                                   aire,apoln,apols, &
-                                  aireu,airev,rlatvdyn) 
+                                  aireu,airev,rlatvdyn,rad,omeg) 
   END IF
 
Index: /LMDZ6/trunk/libf/misc/handle_err_m.F90
===================================================================
--- /LMDZ6/trunk/libf/misc/handle_err_m.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/misc/handle_err_m.F90	(revision 3435)
@@ -39,5 +39,5 @@
           end if
        end if
-       call abort_gcm("NetCDF95 handle_err", "", 1)
+       call abort_physic("NetCDF95 handle_err", "", 1)
     end if
 
Index: /LMDZ6/trunk/libf/misc/regr1_step_av_m.F90
===================================================================
--- /LMDZ6/trunk/libf/misc/regr1_step_av_m.F90	(revision 3435)
+++ /LMDZ6/trunk/libf/misc/regr1_step_av_m.F90	(revision 3435)
@@ -0,0 +1,268 @@
+! $Id: regr1_step_av_m.F90 3065 2017-11-10 13:25:09Z fairhead $
+module regr1_step_av_m
+
+  ! Author: Lionel GUEZ
+
+  implicit none
+
+  interface regr1_step_av
+
+     ! Each procedure regrids a step function by averaging it.
+     ! The regridding operation is done on the first dimension of the
+     ! input array.
+     ! Source grid contains edges of steps.
+     ! Target grid contains positions of cell edges.
+     ! The target grid should be included in the source grid: no
+     ! extrapolation is allowed.
+     ! The difference between the procedures is the rank of the first argument.
+
+     module procedure regr11_step_av, regr12_step_av, regr13_step_av, &
+          regr14_step_av
+  end interface
+
+  private
+  public regr1_step_av
+
+contains
+
+  function regr11_step_av(vs, xs, xt) result(vt)
+
+    ! "vs" has rank 1.
+
+    use assert_eq_m, only: assert_eq
+    use assert_m, only: assert
+    use interpolation, only: locate
+
+    real, intent(in):: vs(:) ! values of steps on the source grid
+    ! (Step "is" is between "xs(is)" and "xs(is + 1)".)
+
+    real, intent(in):: xs(:)
+    ! (edges of of steps on the source grid, in strictly increasing order)
+
+    real, intent(in):: xt(:)
+    ! (edges of cells of the target grid, in strictly increasing order)
+
+    real vt(size(xt) - 1) ! average values on the target grid
+    ! (Cell "it" is between "xt(it)" and "xt(it + 1)".)
+
+    ! Variables local to the procedure:
+    integer is, it, ns, nt
+    real left_edge
+
+    !---------------------------------------------
+
+    ns = assert_eq(size(vs), size(xs) - 1, "regr11_step_av ns")
+    nt = size(xt) - 1
+    ! Quick check on sort order:
+    call assert(xs(1) < xs(2), "regr11_step_av xs bad order")
+    call assert(xt(1) < xt(2), "regr11_step_av xt bad order")
+
+    call assert(xs(1) <= xt(1) .and. xt(nt + 1) <= xs(ns + 1), &
+         "regr11_step_av extrapolation")
+
+    is = locate(xs, xt(1)) ! 1 <= is <= ns, because we forbid extrapolation
+    do it = 1, nt
+       ! 1 <= is <= ns
+       ! xs(is) <= xt(it) < xs(is + 1)
+       ! Compute "vt(it)":
+       left_edge = xt(it)
+       vt(it) = 0.
+       do while (xs(is + 1) < xt(it + 1))
+          ! 1 <= is <= ns - 1
+          vt(it) = vt(it) + (xs(is + 1) - left_edge) * vs(is)
+          is = is + 1
+          left_edge = xs(is)
+       end do
+       ! 1 <= is <= ns
+       vt(it) = (vt(it) + (xt(it + 1) - left_edge) * vs(is)) &
+            / (xt(it + 1) - xt(it))
+       if (xs(is + 1) == xt(it + 1)) is = is + 1
+       ! 1 <= is <= ns .or. it == nt
+    end do
+
+  end function regr11_step_av
+
+  !********************************************
+
+  function regr12_step_av(vs, xs, xt) result(vt)
+
+    ! "vs" has rank 2.
+
+    use assert_eq_m, only: assert_eq
+    use assert_m, only: assert
+    use interpolation, only: locate
+
+    real, intent(in):: vs(:, :) ! values of steps on the source grid
+    ! (Step "is" is between "xs(is)" and "xs(is + 1)".)
+
+    real, intent(in):: xs(:)
+    ! (edges of steps on the source grid, in strictly increasing order)
+
+    real, intent(in):: xt(:)
+    ! (edges of cells of the target grid, in strictly increasing order)
+
+    real vt(size(xt) - 1, size(vs, 2)) ! average values on the target grid
+    ! (Cell "it" is between "xt(it)" and "xt(it + 1)".)
+
+    ! Variables local to the procedure:
+    integer is, it, ns, nt
+    real left_edge
+
+    !---------------------------------------------
+
+    ns = assert_eq(size(vs, 1), size(xs) - 1, "regr12_step_av ns")
+    nt = size(xt) - 1
+
+    ! Quick check on sort order:
+    call assert(xs(1) < xs(2), "regr12_step_av xs bad order")
+    call assert(xt(1) < xt(2), "regr12_step_av xt bad order")
+
+    call assert(xs(1) <= xt(1) .and. xt(nt + 1) <= xs(ns + 1), &
+         "regr12_step_av extrapolation")
+
+    is = locate(xs, xt(1)) ! 1 <= is <= ns, because we forbid extrapolation
+    do it = 1, nt
+       ! 1 <= is <= ns
+       ! xs(is) <= xt(it) < xs(is + 1)
+       ! Compute "vt(it, :)":
+       left_edge = xt(it)
+       vt(it, :) = 0.
+       do while (xs(is + 1) < xt(it + 1))
+          ! 1 <= is <= ns - 1
+          vt(it, :) = vt(it, :) + (xs(is + 1) - left_edge) * vs(is, :)
+          is = is + 1
+          left_edge = xs(is)
+       end do
+       ! 1 <= is <= ns
+       vt(it, :) = (vt(it, :) + (xt(it + 1) - left_edge) * vs(is, :)) &
+            / (xt(it + 1) - xt(it))
+       if (xs(is + 1) == xt(it + 1)) is = is + 1
+       ! 1 <= is <= ns .or. it == nt
+    end do
+
+  end function regr12_step_av
+
+  !********************************************
+
+  function regr13_step_av(vs, xs, xt) result(vt)
+
+    ! "vs" has rank 3.
+
+    use assert_eq_m, only: assert_eq
+    use assert_m, only: assert
+    use interpolation, only: locate
+
+    real, intent(in):: vs(:, :, :) ! values of steps on the source grid
+    ! (Step "is" is between "xs(is)" and "xs(is + 1)".)
+
+    real, intent(in):: xs(:)
+    ! (edges of steps on the source grid, in strictly increasing order)
+
+    real, intent(in):: xt(:)
+    ! (edges of cells of the target grid, in strictly increasing order)
+
+    real vt(size(xt) - 1, size(vs, 2), size(vs, 3)) 
+    ! (average values on the target grid)
+    ! (Cell "it" is between "xt(it)" and "xt(it + 1)".)
+
+    ! Variables local to the procedure:
+    integer is, it, ns, nt
+    real left_edge
+
+    !---------------------------------------------
+
+    ns = assert_eq(size(vs, 1), size(xs) - 1, "regr13_step_av ns")
+    nt = size(xt) - 1
+
+    ! Quick check on sort order:
+    call assert(xs(1) < xs(2), "regr13_step_av xs bad order")
+    call assert(xt(1) < xt(2), "regr13_step_av xt bad order")
+
+    call assert(xs(1) <= xt(1) .and. xt(nt + 1) <= xs(ns + 1), &
+         "regr13_step_av extrapolation")
+
+    is = locate(xs, xt(1)) ! 1 <= is <= ns, because we forbid extrapolation
+    do it = 1, nt
+       ! 1 <= is <= ns
+       ! xs(is) <= xt(it) < xs(is + 1)
+       ! Compute "vt(it, :, :)":
+       left_edge = xt(it)
+       vt(it, :, :) = 0.
+       do while (xs(is + 1) < xt(it + 1))
+          ! 1 <= is <= ns - 1
+          vt(it, :, :) = vt(it, :, :) + (xs(is + 1) - left_edge) * vs(is, :, :)
+          is = is + 1
+          left_edge = xs(is)
+       end do
+       ! 1 <= is <= ns
+       vt(it, :, :) = (vt(it, :, :) &
+            + (xt(it + 1) - left_edge) * vs(is, :, :)) / (xt(it + 1) - xt(it))
+       if (xs(is + 1) == xt(it + 1)) is = is + 1
+       ! 1 <= is <= ns .or. it == nt
+    end do
+
+  end function regr13_step_av
+
+  !********************************************
+
+  function regr14_step_av(vs, xs, xt) result(vt)
+
+    ! "vs" has rank 4.
+
+    use assert_eq_m, only: assert_eq
+    use assert_m, only: assert
+    use interpolation, only: locate
+
+    real, intent(in):: vs(:, :, :, :) ! values of steps on the source grid
+    ! (Step "is" is between "xs(is)" and "xs(is + 1)".)
+
+    real, intent(in):: xs(:)
+    ! (edges of steps on the source grid, in strictly increasing order)
+
+    real, intent(in):: xt(:)
+    ! (edges of cells of the target grid, in strictly increasing order)
+
+    real vt(size(xt) - 1, size(vs, 2), size(vs, 3), size(vs, 4))
+    ! (average values on the target grid)
+    ! (Cell "it" is between "xt(it)" and "xt(it + 1)".)
+
+    ! Variables local to the procedure:
+    integer is, it, ns, nt
+    real left_edge
+
+    !---------------------------------------------
+
+    ns = assert_eq(size(vs, 1), size(xs) - 1, "regr14_step_av ns")
+    nt = size(xt) - 1
+
+    ! Quick check on sort order:
+    call assert(xs(1) < xs(2), "regr14_step_av xs bad order")
+    call assert(xt(1) < xt(2), "regr14_step_av xt bad order")
+
+    call assert(xs(1) <= xt(1) .and. xt(nt + 1) <= xs(ns + 1), &
+         "regr14_step_av extrapolation")
+
+    is = locate(xs, xt(1)) ! 1 <= is <= ns, because we forbid extrapolation
+    do it = 1, nt
+       ! 1 <= is <= ns
+       ! xs(is) <= xt(it) < xs(is + 1)
+       ! Compute "vt(it, :, :, :)":
+       left_edge = xt(it)
+       vt(it, :, :, :) = 0.
+       do while (xs(is + 1) < xt(it + 1))
+          ! 1 <= is <= ns - 1
+          vt(it, :, :, :) = vt(it, :, :, :) + (xs(is + 1) - left_edge) &
+               * vs(is, :, :, :)
+          is = is + 1
+          left_edge = xs(is)
+       end do
+       ! 1 <= is <= ns
+       vt(it, :, :, :) = (vt(it, :, :, :) + (xt(it + 1) - left_edge) &
+            * vs(is, :, :, :)) / (xt(it + 1) - xt(it))
+       if (xs(is + 1) == xt(it + 1)) is = is + 1
+       ! 1 <= is <= ns .or. it == nt
+    end do
+
+  end function regr14_step_av
+
+end module regr1_step_av_m
Index: /LMDZ6/trunk/libf/misc/wxios.F90
===================================================================
--- /LMDZ6/trunk/libf/misc/wxios.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/misc/wxios.F90	(revision 3435)
@@ -15,5 +15,5 @@
     
     INTEGER, SAVE :: g_comm
-    CHARACTER(len=100), SAVE :: g_ctx_name
+    CHARACTER(len=100), SAVE :: g_ctx_name ="LMDZ"
     TYPE(xios_context), SAVE :: g_ctx
 !$OMP THREADPRIVATE(g_comm,g_cts_name,g_ctx)
@@ -136,8 +136,8 @@
         g_ctx_name = xios_ctx_name
         
-        ! Si couple alors init fait dans cpl_init
-        IF (.not. PRESENT(type_ocean)) THEN
-            CALL wxios_context_init()
-        ENDIF
+!        ! Si couple alors init fait dans cpl_init
+!        IF (.not. PRESENT(type_ocean)) THEN
+!            CALL wxios_context_init()
+!        ENDIF
 
     END SUBROUTINE wxios_init
@@ -145,5 +145,5 @@
     SUBROUTINE wxios_context_init()
         USE print_control_mod, ONLY : prt_level, lunout
-!        USE mod_phys_lmdz_mpi_data, ONLY : COMM_LMDZ_PHY
+        USE mod_phys_lmdz_mpi_data, ONLY : COMM_LMDZ_PHY
         IMPLICIT NONE
 
@@ -152,5 +152,6 @@
 !$OMP MASTER
         !Initialisation du contexte:
-        CALL xios_context_initialize(g_ctx_name, g_comm)
+        !!CALL xios_context_initialize(g_ctx_name, g_comm)
+        CALL xios_context_initialize(g_ctx_name, COMM_LMDZ_PHY)
         CALL xios_get_handle(g_ctx_name, xios_ctx)    !Récupération
         CALL xios_set_current_context(xios_ctx)            !Activation
@@ -165,4 +166,16 @@
 !$OMP END MASTER
     END SUBROUTINE wxios_context_init
+
+
+    SUBROUTINE wxios_set_context()
+        IMPLICIT NONE
+        TYPE(xios_context) :: xios_ctx
+
+       !$OMP MASTER
+        CALL xios_get_handle(g_ctx_name, xios_ctx)    !Récupération
+        CALL xios_set_current_context(xios_ctx)            !Activation
+       !$OMP END MASTER
+
+    END SUBROUTINE wxios_set_context
 
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -203,5 +216,5 @@
             CASE DEFAULT
                 abort_message = 'wxios_set_cal: Mauvais choix de calendrier'
-                CALL abort_gcm('Gcm:Xios',abort_message,1)
+                CALL abort_physic('Gcm:Xios',abort_message,1)
         END SELECT
         
@@ -237,56 +250,61 @@
     ! Pour initialiser un domaine !!!!!!!!!!!!!!!!!!!!
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    SUBROUTINE wxios_domain_param(dom_id, is_sequential, ni, nj, ni_glo, nj_glo,        &
-                                    ibegin, iend, ii_begin, ii_end, jbegin, jend,       &
-                                    data_ni, data_ibegin, data_iend,                    &
-                                    io_lat, io_lon,is_south_pole,mpi_rank)
-         
-
-        USE print_control_mod, ONLY : prt_level, lunout
-        IMPLICIT NONE
-
+    SUBROUTINE wxios_domain_param(dom_id)
+       USE dimphy, only: klon
+       USE mod_phys_lmdz_transfert_para, ONLY: gather, bcast
+       USE mod_phys_lmdz_para, only: jj_nb, jj_begin, jj_end, ii_begin, ii_end, &
+                                     mpi_size, mpi_rank, klon_mpi, &
+                                     is_sequential, is_south_pole_dyn
+       USE mod_grid_phy_lmdz, only: nbp_lon, nbp_lat, klon_glo         
+       USE print_control_mod, ONLY : prt_level, lunout
+       USE geometry_mod
+
+       IMPLICIT NONE
         CHARACTER(len=*),INTENT(IN) :: dom_id ! domain identifier
-        LOGICAL,INTENT(IN) :: is_sequential ! flag
-        INTEGER,INTENT(IN) :: ni ! local MPI domain number of longitudes
-        INTEGER,INTENT(IN) :: nj ! local MPI domain number of latitudes
-        INTEGER,INTENT(IN) :: ni_glo ! global grid number of longitudes
-        INTEGER,INTENT(IN) :: nj_glo ! global grid number of latitudes
-        INTEGER,INTENT(IN) :: ibegin ! start index, on global grid, of local MPI domain 
-        INTEGER,INTENT(IN) :: iend ! end index, on global grid, of local MPI domain
-        INTEGER,INTENT(IN) :: ii_begin ! i index at which local data starts (first row)
-        INTEGER,INTENT(IN) :: ii_end ! i index at which local data ends (last row)
-        INTEGER,INTENT(IN) :: jbegin ! start index, on global grid, of local MPI domain 
-        INTEGER,INTENT(IN) :: jend ! end index, on global grid, of local MPI domain
-        INTEGER,INTENT(IN) :: data_ni
-        INTEGER,INTENT(IN) :: data_ibegin
-        INTEGER,INTENT(IN) :: data_iend
-        REAL,INTENT(IN) :: io_lat(:) ! latitudes (of global grid)
-        REAL,INTENT(IN) :: io_lon(:) ! longitudes (of global grid)
-        logical,intent(in) :: is_south_pole ! does this process include the south pole?
-        integer,intent(in) :: mpi_rank ! rank of process
-        
+
+        REAL   :: rlat_glo(klon_glo)
+        REAL   :: rlon_glo(klon_glo)
+        REAL   :: io_lat(nbp_lat)
+        REAL   :: io_lon(nbp_lon)
+        LOGICAL :: mask(nbp_lon,jj_nb) !Masque pour les problèmes de recouvrement MPI
         TYPE(xios_domain) :: dom
+        INTEGER :: i
         LOGICAL :: boool
         
-        !Masque pour les problèmes de recouvrement MPI:
-        LOGICAL :: mask(ni,nj)
+
+
+        CALL gather(latitude_deg,rlat_glo) 
+        CALL bcast(rlat_glo)
+        CALL gather(longitude_deg,rlon_glo)
+        CALL bcast(rlon_glo)
+    
+  !$OMP MASTER  
+        io_lat(1)=rlat_glo(1)
+        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
+
+        IF (klon_glo == 1) THEN
+          io_lon(1)=rlon_glo(1)
+        ELSE 
+          io_lon(1:nbp_lon)=rlon_glo(2:nbp_lon+1)
+        ENDIF
+
         
         !On récupère le handle:
         CALL xios_get_domain_handle(dom_id, dom)
         
-        IF (prt_level >= 10) THEN
-          WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," ni:",ni," ni_glo:", ni_glo, " nj:", nj, " nj_glo:", nj_glo
-          WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," ibegin:",ibegin," iend:", iend, " jbegin:", jbegin, " jend:", jend
-          WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," ii_begin:",ii_begin," ii_end:", ii_end
-          WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," Size io_lon:", SIZE(io_lon(ibegin:iend)), " io_lat:", SIZE(io_lat(jbegin:jend))
-        ENDIF
-        
         !On parametrise le domaine:
-        CALL xios_set_domain_attr_hdl(dom, ni_glo=ni_glo, ibegin=ibegin-1, ni=ni, type="rectilinear")
-        CALL xios_set_domain_attr_hdl(dom, nj_glo=nj_glo, jbegin=jbegin-1, nj=nj, data_dim=2)
-        CALL xios_set_domain_attr_hdl(dom, lonvalue_1d=io_lon(ibegin:iend), latvalue_1d=io_lat(jbegin:jend))
+        CALL xios_set_domain_attr_hdl(dom, ni_glo=nbp_lon, ibegin=0, ni=nbp_lon, type="rectilinear")
+        CALL xios_set_domain_attr_hdl(dom, nj_glo=nbp_lat, jbegin=jj_begin-1, nj=jj_nb, data_dim=2)
+        CALL xios_set_domain_attr_hdl(dom, lonvalue_1d=io_lon(1:nbp_lon), latvalue_1d=io_lat(jj_begin:jj_end))
+        CALL xios_set_domain_attr("dom_out", domain_ref=dom_id)
+
         !On definit un axe de latitudes pour les moyennes zonales
         IF (xios_is_valid_axis("axis_lat")) THEN
-           CALL xios_set_axis_attr( "axis_lat", n_glo=nj_glo, n=nj, begin=jbegin-1, value=io_lat(jbegin:jend))
+           CALL xios_set_axis_attr( "axis_lat", n_glo=nbp_lat, n=jj_nb, begin=jj_begin-1, value=io_lat(jj_begin:jj_end))
         ENDIF
 
@@ -294,10 +312,10 @@
             mask(:,:)=.TRUE.
             if (ii_begin>1) mask(1:ii_begin-1,1) = .FALSE.
-            if (ii_end<ni) mask(ii_end+1:ni,nj) = .FALSE.
+            if (ii_end<nbp_lon) mask(ii_end+1:nbp_lon,jj_nb) = .FALSE.
             ! special case for south pole
-            if ((ii_end.eq.1).and.(is_south_pole)) mask(1:ni,nj)=.true.
+            if ((ii_end==1).and.(is_south_pole_dyn)) mask(1:nbp_lon,jj_nb)=.true.
             IF (prt_level >= 10) THEN
               WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," mask(:,1)=",mask(:,1)
-              WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," mask(:,nj)=",mask(:,nj)
+              WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," mask(:,jj_nb)=",mask(:,jj_nb)
             ENDIF
             CALL xios_set_domain_attr_hdl(dom, mask_2d=mask)
@@ -311,6 +329,54 @@
             IF (prt_level >= 10) WRITE(lunout,*) "wxios_domain_param: Invalid domain: ", trim(dom_id)
         END IF
+!$OMP END MASTER
+        
     END SUBROUTINE wxios_domain_param
     
+
+    SUBROUTINE wxios_domain_param_unstructured(dom_id)
+        USE geometry_mod, ONLY : longitude, latitude, boundslon, boundslat,ind_cell_glo
+        USE mod_grid_phy_lmdz, ONLY : nvertex, klon_glo
+        USE mod_phys_lmdz_para 
+        USE nrtype, ONLY : PI
+        USE ioipsl_getin_p_mod, ONLY : getin_p
+        IMPLICIT NONE
+        CHARACTER(len=*),INTENT(IN) :: dom_id ! domain identifier
+        REAL :: lon_mpi(klon_mpi)
+        REAL :: lat_mpi(klon_mpi)
+        REAL :: boundslon_mpi(klon_mpi,nvertex)
+        REAL :: boundslat_mpi(klon_mpi,nvertex)
+        INTEGER :: ind_cell_glo_mpi(klon_mpi)
+        TYPE(xios_domain) :: dom
+        LOGICAL :: remap_output
+
+        CALL gather_omp(longitude*180/PI,lon_mpi)
+        CALL gather_omp(latitude*180/PI,lat_mpi)
+        CALL gather_omp(boundslon*180/PI,boundslon_mpi)
+        CALL gather_omp(boundslat*180/PI,boundslat_mpi)
+        CALL gather_omp(ind_cell_glo,ind_cell_glo_mpi)
+        
+        remap_output=.TRUE.
+        CALL getin_p("remap_output",remap_output)
+
+!$OMP MASTER
+        CALL xios_get_domain_handle(dom_id, dom)
+        
+        !On parametrise le domaine:
+        CALL xios_set_attr(dom, ni_glo=klon_glo, ibegin=ij_begin-1, ni=ij_nb, type="unstructured")
+        CALL xios_set_attr(dom, nvertex=nvertex, lonvalue_1d=lon_mpi, latvalue_1d=lat_mpi, &
+                           bounds_lon_1d=TRANSPOSE(boundslon_mpi), bounds_lat_1d=TRANSPOSE(boundslat_mpi) )
+        CALL xios_set_attr(dom, i_index=ind_cell_glo_mpi(:)-1)
+        IF (remap_output) THEN
+          CALL xios_set_domain_attr("dom_out", domain_ref="dom_regular")
+          CALL xios_set_fieldgroup_attr("dom_out", domain_ref="dom_regular")
+          CALL xios_set_fieldgroup_attr("remap_expr", expr="@this_ref")
+        ENDIF
+!$OMP END MASTER
+
+    END SUBROUTINE wxios_domain_param_unstructured
+
+
+
+
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     ! Pour déclarer un axe vertical !!!!!!!!!!!!!!!
Index: /LMDZ6/trunk/libf/phy_common/geometry_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phy_common/geometry_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phy_common/geometry_mod.F90	(revision 3435)
@@ -30,4 +30,6 @@
 !$OMP THREADPRIVATE(cell_area)
 
+  INTEGER,SAVE,ALLOCATABLE :: ind_cell_glo(:)      ! global indice of a local cell
+!$OMP THREADPRIVATE(ind_cell_glo)
 
 CONTAINS
@@ -35,5 +37,5 @@
   SUBROUTINE init_geometry(klon,longitude_,latitude_, &
                            boundslon_,boundslat_, &
-                           cell_area_,dx_,dy_)
+                           cell_area_,ind_cell_glo_,dx_,dy_)
   USE mod_grid_phy_lmdz, ONLY: nvertex
   USE nrtype, ONLY : PI
@@ -45,4 +47,5 @@
     REAL,INTENT(IN) :: boundslat_(klon,nvertex)
     REAL,INTENT(IN) :: cell_area_(klon)
+    INTEGER,OPTIONAL,INTENT(IN) :: ind_cell_glo_(klon)
     REAL,OPTIONAL,INTENT(IN) :: dx_(klon)
     REAL,OPTIONAL,INTENT(IN) :: dy_(klon)
@@ -55,4 +58,5 @@
     ALLOCATE(boundslat(klon,nvertex))
     ALLOCATE(cell_area(klon))
+    IF (PRESENT(ind_cell_glo_)) ALLOCATE(ind_cell_glo(klon))
     IF (PRESENT(dx_)) ALLOCATE(dx(klon))
     IF (PRESENT(dy_))ALLOCATE(dy(klon))
@@ -65,4 +69,5 @@
     boundslat(:,:) = boundslat_(:,:)
     cell_area(:) = cell_area_(:)
+    IF (PRESENT(ind_cell_glo_)) ind_cell_glo(:) = ind_cell_glo_(:)
     IF (PRESENT(dx_)) dx(:) = dx_(:)
     IF (PRESENT(dy_)) dy(:) = dy_(:)
Index: /LMDZ6/trunk/libf/phy_common/init_print_control_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phy_common/init_print_control_mod.F90	(revision 3435)
+++ /LMDZ6/trunk/libf/phy_common/init_print_control_mod.F90	(revision 3435)
@@ -0,0 +1,67 @@
+MODULE init_print_control_mod
+
+! init_print_control to initialize print_control_mod variables
+! not included there because of circular dependecy issues
+
+CONTAINS
+
+  SUBROUTINE init_print_control
+  USE print_control_mod, ONLY : set_print_control
+  USE ioipsl_getin_p_mod, ONLY : getin_p
+  USE mod_phys_lmdz_para, ONLY: is_omp_root, is_master
+  IMPLICIT NONE
+
+    INTEGER :: lunout ! default output file identifier (6==screen)
+    INTEGER :: prt_level ! Output level
+    LOGICAL :: debug ! flag to specify if in "debug mode"
+    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
+    
+    CALL set_print_control(lunout,prt_level,debug)
+
+  END SUBROUTINE init_print_control  
+
+END MODULE init_print_control_mod
+
Index: /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_mpi_data.F90
===================================================================
--- /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_mpi_data.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_mpi_data.F90	(revision 3435)
@@ -3,5 +3,4 @@
 !
 MODULE mod_phys_lmdz_mpi_data
-!  USE mod_const_mpi
   
   INTEGER,SAVE :: ii_begin
@@ -36,11 +35,8 @@
   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
   LOGICAL,SAVE :: is_north_pole_dyn
   LOGICAL,SAVE :: is_south_pole_dyn
@@ -50,15 +46,13 @@
 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,INTENT(IN) :: nbp
+    INTEGER,INTENT(IN) :: nbp_lon
+    INTEGER,INTENT(IN) :: nbp_lat
+    INTEGER,INTENT(IN) :: communicator
     
     INTEGER,ALLOCATABLE :: distrib(:)
@@ -189,7 +183,7 @@
 
   SUBROUTINE print_module_data
-!  USE print_control_mod, ONLY: lunout
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
-  INCLUDE "iniprint.h" 
+!  INCLUDE "iniprint.h" 
   
     WRITE(lunout,*) 'ii_begin =', ii_begin
Index: /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_omp_data.F90
===================================================================
--- /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_omp_data.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_omp_data.F90	(revision 3435)
@@ -7,4 +7,5 @@
   INTEGER,SAVE :: omp_rank
   LOGICAL,SAVE :: is_omp_root
+  LOGICAL,SAVE :: is_omp_master  ! alias of is_omp_root
   LOGICAL,SAVE :: is_using_omp
   LOGICAL,SAVE :: is_north_pole_phy, is_south_pole_phy
@@ -17,5 +18,5 @@
   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)
+!$OMP  THREADPRIVATE(omp_rank,klon_omp,is_omp_root,is_omp_master,klon_omp_begin,klon_omp_end)
 !$OMP  THREADPRIVATE(is_north_pole_phy, is_south_pole_phy)
 
@@ -60,8 +61,8 @@
    ELSE
      abort_message = 'ANORMAL : OMP_MASTER /= 0'
-     CALL abort_gcm (modname,abort_message,1)
+     CALL abort_physic (modname,abort_message,1)
    ENDIF
 !$OMP END MASTER
-
+   is_omp_master=is_omp_root
 
 !$OMP MASTER 
@@ -106,6 +107,7 @@
 
   SUBROUTINE Print_module_data
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
-  INCLUDE "iniprint.h"
+!  INCLUDE "iniprint.h"
 
 !$OMP CRITICAL  
Index: /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_para.F90
===================================================================
--- /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_para.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phy_common/mod_phys_lmdz_para.F90	(revision 3435)
@@ -49,6 +49,7 @@
   SUBROUTINE Test_transfert
   USE mod_grid_phy_lmdz
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
-    INCLUDE "iniprint.h"
+!    INCLUDE "iniprint.h"
  
     REAL :: Test_Field1d_glo(klon_glo,nbp_lev)
Index: /LMDZ6/trunk/libf/phy_common/physics_distribution_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phy_common/physics_distribution_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phy_common/physics_distribution_mod.F90	(revision 3435)
@@ -10,6 +10,12 @@
                                        nbp, nbp_lon, nbp_lat, nbp_lev, &
                                        communicator)
-  USE mod_phys_lmdz_para, ONLY: init_phys_lmdz_para
+  USE mod_phys_lmdz_para, ONLY: init_phys_lmdz_para, klon_omp
   USE mod_grid_phy_lmdz, ONLY: init_grid_phy_lmdz
+  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) :: grid_type 
@@ -24,4 +30,15 @@
     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)
+!$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_physics_distribution  
Index: /LMDZ6/trunk/libf/phy_common/print_control_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phy_common/print_control_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phy_common/print_control_mod.F90	(revision 3435)
@@ -7,57 +7,21 @@
 !$OMP THREADPRIVATE(lunout,prt_level,debug)
 
+  ! NB: Module variable Initializations done by set_print_control
+  !     routine from init_print_control_mod to avoid circular
+  !     module dependencies
+
 CONTAINS
 
-  SUBROUTINE init_print_control
-  USE ioipsl_getin_p_mod, ONLY : getin_p
-  USE mod_phys_lmdz_para, ONLY: is_omp_root, is_master
+  SUBROUTINE set_print_control(lunout_,prt_level_,debug_)
   IMPLICIT NONE
-
-    LOGICAL :: opened
-    INTEGER :: number
+    INTEGER :: lunout_
+    INTEGER :: prt_level_
+    LOGICAL :: debug_
+      
+    lunout = lunout_
+    prt_level = prt_level_
+    debug = debug_
     
-    !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 SUBROUTINE set_print_control
 
 END MODULE print_control_mod
Index: /LMDZ6/trunk/libf/phydev/inifis_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phydev/inifis_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phydev/inifis_mod.F90	(revision 3435)
@@ -1,3 +1,3 @@
-! $Id: $
+! $Id$
 MODULE inifis_mod
 
@@ -6,5 +6,5 @@
   SUBROUTINE inifis(prad, pg, pr, pcpp)
   ! Initialize some physical constants and settings
-  USE print_control_mod, ONLY: init_print_control
+  USE init_print_control_mod, ONLY: init_print_control
   USE comcstphy, ONLY: rradius, & ! planet radius (m)
                        rr, & ! recuced gas constant: R/molar mass of atm
Index: /LMDZ6/trunk/libf/phylmd/add_phys_tend_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/add_phys_tend_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/add_phys_tend_mod.F90	(revision 3435)
@@ -1,2 +1,5 @@
+!
+! $Id$
+!
 !
 MODULE add_phys_tend_mod
@@ -98,5 +101,5 @@
 
 USE dimphy, ONLY: klon, klev
-USE phys_state_var_mod, ONLY : dtime
+USE phys_state_var_mod, ONLY : phys_tstep
 USE phys_local_var_mod, ONLY: u_seri, v_seri, ql_seri, qs_seri, q_seri, t_seri
 USE phys_state_var_mod, ONLY: ftsol
@@ -451,17 +454,17 @@
     ! ------------------------------------------------
 
-    d_qw_col(:) = (zqw_col(:,2)-zqw_col(:,1))/dtime
-    d_ql_col(:) = (zql_col(:,2)-zql_col(:,1))/dtime
-    d_qs_col(:) = (zqs_col(:,2)-zqs_col(:,1))/dtime
+    d_qw_col(:) = (zqw_col(:,2)-zqw_col(:,1))/phys_tstep
+    d_ql_col(:) = (zql_col(:,2)-zql_col(:,1))/phys_tstep
+    d_qs_col(:) = (zqs_col(:,2)-zqs_col(:,1))/phys_tstep
     d_qt_col(:) = d_qw_col(:) + d_ql_col(:) + d_qs_col(:)
 
-    d_ek_col(:) = (zek_col(:,2)-zek_col(:,1))/dtime
-
-    d_h_dair_col(:) = (zh_dair_col(:,2)-zh_dair_col(:,1))/dtime
-    d_h_qw_col(:) = (zh_qw_col(:,2)-zh_qw_col(:,1))/dtime
-    d_h_ql_col(:) = (zh_ql_col(:,2)-zh_ql_col(:,1))/dtime
-    d_h_qs_col(:) = (zh_qs_col(:,2)-zh_qs_col(:,1))/dtime
-
-    d_h_col = (zh_col(:,2)-zh_col(:,1))/dtime 
+    d_ek_col(:) = (zek_col(:,2)-zek_col(:,1))/phys_tstep
+
+    d_h_dair_col(:) = (zh_dair_col(:,2)-zh_dair_col(:,1))/phys_tstep
+    d_h_qw_col(:) = (zh_qw_col(:,2)-zh_qw_col(:,1))/phys_tstep
+    d_h_ql_col(:) = (zh_ql_col(:,2)-zh_ql_col(:,1))/phys_tstep
+    d_h_qs_col(:) = (zh_qs_col(:,2)-zh_qs_col(:,1))/phys_tstep
+
+    d_h_col = (zh_col(:,2)-zh_col(:,1))/phys_tstep 
 
   end if ! end if (fl_ebil .GT. 0)
@@ -494,5 +497,5 @@
 !======================================================================
 
-USE phys_state_var_mod, ONLY : dtime, ftsol
+USE phys_state_var_mod, ONLY : phys_tstep, ftsol
 USE geometry_mod, ONLY: longitude_deg, latitude_deg
 USE print_control_mod, ONLY: prt_level
@@ -621,10 +624,10 @@
     ! ------------------------------------------------
 
-    d_qw_col(:) = (zqw_col(:,2)-zqw_col(:,1))/dtime
-    d_ql_col(:) = (zql_col(:,2)-zql_col(:,1))/dtime
-    d_qs_col(:) = (zqs_col(:,2)-zqs_col(:,1))/dtime
+    d_qw_col(:) = (zqw_col(:,2)-zqw_col(:,1))/phys_tstep
+    d_ql_col(:) = (zql_col(:,2)-zql_col(:,1))/phys_tstep
+    d_qs_col(:) = (zqs_col(:,2)-zqs_col(:,1))/phys_tstep
     d_qt_col(:) = d_qw_col(:) + d_ql_col(:) + d_qs_col(:)
 
-    d_ek_col(:) = (zek_col(:,2)-zek_col(:,1))/dtime
+    d_ek_col(:) = (zek_col(:,2)-zek_col(:,1))/phys_tstep
 
    print *,'zdu ', zdu
@@ -632,10 +635,10 @@
    print *,'d_ek_col, zek_col(2), zek_col(1) ',d_ek_col(1), zek_col(1,2), zek_col(1,1)
 
-    d_h_dair_col(:) = (zh_dair_col(:,2)-zh_dair_col(:,1))/dtime
-    d_h_qw_col(:) = (zh_qw_col(:,2)-zh_qw_col(:,1))/dtime
-    d_h_ql_col(:) = (zh_ql_col(:,2)-zh_ql_col(:,1))/dtime
-    d_h_qs_col(:) = (zh_qs_col(:,2)-zh_qs_col(:,1))/dtime
-
-    d_h_col = (zh_col(:,2)-zh_col(:,1))/dtime 
+    d_h_dair_col(:) = (zh_dair_col(:,2)-zh_dair_col(:,1))/phys_tstep
+    d_h_qw_col(:) = (zh_qw_col(:,2)-zh_qw_col(:,1))/phys_tstep
+    d_h_ql_col(:) = (zh_ql_col(:,2)-zh_ql_col(:,1))/phys_tstep
+    d_h_qs_col(:) = (zh_qs_col(:,2)-zh_qs_col(:,1))/phys_tstep
+
+    d_h_col = (zh_col(:,2)-zh_col(:,1))/phys_tstep 
 
   end if ! end if (fl_ebil .GT. 0)
@@ -716,5 +719,5 @@
 
 USE dimphy, ONLY: klon, klev
-USE phys_state_var_mod, ONLY : dtime
+USE phys_state_var_mod, ONLY : phys_tstep
 USE phys_state_var_mod, ONLY : topsw, toplw, solsw, sollw, rain_con, snow_con
 USE geometry_mod, ONLY: longitude_deg, latitude_deg
Index: /LMDZ6/trunk/libf/phylmd/calcul_divers.h
===================================================================
--- /LMDZ6/trunk/libf/phylmd/calcul_divers.h	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/calcul_divers.h	(revision 3435)
@@ -1,4 +1,5 @@
 !
-! $Header$
+! $Id$
+!
 !
 ! Initialisations diverses au tout debut
@@ -14,5 +15,5 @@
 
 ! Calcul fin de journee : total_rain, nday_rain
-      IF(MOD(itap,NINT(un_jour/dtime)).EQ.0) THEN
+      IF(MOD(itap,NINT(un_jour/phys_tstep)).EQ.0) THEN
 !        print*,'calcul nday_rain itap ',itap
          DO i = 1, klon
@@ -23,6 +24,6 @@
 
 ! Initialisation fin de mois
-      IF(MOD(itap-itapm1,NINT(mth_len*un_jour/dtime)).EQ.0) THEN
-        itapm1=itapm1+NINT(mth_len*un_jour/dtime)
+      IF(MOD(itap-itapm1,NINT(mth_len*un_jour/phys_tstep)).EQ.0) THEN
+        itapm1=itapm1+NINT(mth_len*un_jour/phys_tstep)
 !       print*,'initialisation itapm1 ',itapm1
       ENDIF
@@ -35,5 +36,5 @@
      t2m_max_mon=0.
   ENDIF
-  IF(MOD(itap,NINT(un_jour/dtime)).EQ.1) THEN
+  IF(MOD(itap,NINT(un_jour/phys_tstep)).EQ.1) THEN
      zt2m_min_mon=zt2m
      zt2m_max_mon=zt2m
@@ -45,5 +46,5 @@
      ENDDO
 !fin de journee
-  IF(MOD(itap,NINT(un_jour/dtime)).EQ.0) THEN
+  IF(MOD(itap,NINT(un_jour/phys_tstep)).EQ.0) THEN
    t2m_min_mon=t2m_min_mon+zt2m_min_mon 
    t2m_max_mon=t2m_max_mon+zt2m_max_mon 
Index: /LMDZ6/trunk/libf/phylmd/carbon_cycle_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/carbon_cycle_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/carbon_cycle_mod.F90	(revision 3435)
@@ -582,5 +582,5 @@
   SUBROUTINE infocfields_init
 
-    USE control_mod, ONLY: planet_type
+!    USE control_mod, ONLY: planet_type
     USE phys_cal_mod, ONLY : mth_cur
     USE mod_synchro_omp
@@ -656,4 +656,6 @@
 
   CHARACTER(len=*),parameter :: modname="infocfields"
+
+  CHARACTER(len=10),SAVE :: planet_type="earth"
 
 !-----------------------------------------------------------------------
@@ -718,5 +720,5 @@
                   WRITE(lunout,*) 'abort_gcm --- nbcf_in : ',nbcf_in
                   WRITE(lunout,*) 'abort_gcm --- nbcf_out: ',nbcf_out
-                  CALL abort_gcm('infocfields_init','Problem in the definition of the coupling fields',1)
+                  CALL abort_physic('infocfields_init','Problem in the definition of the coupling fields',1)
                ENDIF
              ENDDO !DO iq=1,nbcf
@@ -836,11 +838,11 @@
 
  ALLOCATE(fields_in(klon,nbcf_in),stat=error)
- IF (error /= 0)  CALL abort_gcm(modname,'Pb in allocation fields_in',1)
+ IF (error /= 0)  CALL abort_physic(modname,'Pb in allocation fields_in',1)
  ALLOCATE(yfields_in(klon,nbcf_in),stat=error)
- IF (error /= 0)  CALL abort_gcm(modname,'Pb in allocation yfields_in',1)
+ IF (error /= 0)  CALL abort_physic(modname,'Pb in allocation yfields_in',1)
  ALLOCATE(fields_out(klon,nbcf_out),stat=error)
- IF (error /= 0)  CALL abort_gcm(modname,'Pb in allocation fields_out',1)
+ IF (error /= 0)  CALL abort_physic(modname,'Pb in allocation fields_out',1)
  ALLOCATE(yfields_out(klon,nbcf_out),stat=error)
- IF (error /= 0)  CALL abort_gcm(modname,'Pb in allocation yfields_out',1)
+ IF (error /= 0)  CALL abort_physic(modname,'Pb in allocation yfields_out',1)
 
 END SUBROUTINE infocfields_init
Index: /LMDZ6/trunk/libf/phylmd/clesphys.h
===================================================================
--- /LMDZ6/trunk/libf/phylmd/clesphys.h	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/clesphys.h	(revision 3435)
@@ -70,6 +70,4 @@
 !IM freq_outNMC : frequences de sortie fichiers niveaux de pression (histmthNMC, histdayNMC, histhfNMC)
 !IM freq_calNMC : frequences de calcul fis. hist*NMC.nc
-!IM pasphys : pas de temps de physique (secondes)
-       REAL pasphys
        LOGICAL ok_histNMC(3)
        INTEGER levout_histNMC(3)
@@ -111,5 +109,5 @@
      &     , min_wind_speed,f_gust_wk,f_gust_bl,f_qsat_oce,f_z0qh_oce   &
      &     , z0m_seaice,z0h_seaice                                      &
-     &     , pasphys            , freq_outNMC, freq_calNMC              &
+     &     , freq_outNMC, freq_calNMC                                   &
      &     , lonmin_ins, lonmax_ins, latmin_ins, latmax_ins             &
      &     , freq_ISCCP, ecrit_ISCCP, freq_COSP, freq_AIRS              &
Index: /LMDZ6/trunk/libf/phylmd/coef_diff_turb_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/coef_diff_turb_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/coef_diff_turb_mod.F90	(revision 3435)
@@ -65,4 +65,9 @@
 
 
+    ykmm = 0 !ym missing init
+    ykmn = 0 !ym missing init
+    ykmq = 0 !ym missing init
+    
+    
 !****************************************************************************************    
 ! Calcul de coefficients de diffusion turbulent de l'atmosphere : 
Index: /LMDZ6/trunk/libf/phylmd/conf_phys_m.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/conf_phys_m.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/conf_phys_m.F90	(revision 3435)
@@ -29,4 +29,5 @@
     USE mod_grid_phy_lmdz, ONLY: klon_glo
     USE print_control_mod, ONLY: lunout
+    USE phys_state_var_mod, ONLY: phys_tstep
 
     INCLUDE "conema3.h"
@@ -150,5 +151,5 @@
 
     REAL,SAVE :: R_ecc_omp,R_peri_omp,R_incl_omp,solaire_omp
-    REAL      :: solaire_omp_init
+    REAL,SAVE      :: solaire_omp_init
     LOGICAL,SAVE :: ok_suntime_rrtm_omp
     REAL,SAVE :: co2_ppm_omp, RCO2_omp, co2_ppm_per_omp, RCO2_per_omp
@@ -1030,5 +1031,5 @@
     ! - 1 = stratospheric aerosols scaled from 550 nm AOD 
     ! - 2 = stratospheric aerosol properties from CMIP6
-    !Option 2 is only available with RRTM, this is tested later on
+    !Option 2 is only available with RRTM, this is tested later on 
     !Config Def  = 0
     !Config Help = Used in physiq.F
@@ -1723,10 +1724,10 @@
     !Config Desc = freq_calNMC(2) = frequence de calcul fichiers histdayNMC
     !Config Desc = freq_calNMC(3) = frequence de calcul fichiers histhfNMC
-    !Config Def  = pasphys
-    !Config Help =
-    !
-    freq_calNMC_omp(1) = pasphys
-    freq_calNMC_omp(2) = pasphys
-    freq_calNMC_omp(3) = pasphys
+    !Config Def  = phys_tstep
+    !Config Help =
+    !
+    freq_calNMC_omp(1) = phys_tstep
+    freq_calNMC_omp(2) = phys_tstep
+    freq_calNMC_omp(3) = phys_tstep
     CALL getin('freq_calNMC',freq_calNMC_omp)
     !
Index: /LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/cosp/phys_cosp.F90	(revision 3435)
@@ -354,5 +354,4 @@
       !$OMP END MASTER
       !$OMP BARRIER
-        debut_cosp=.false.
       endif ! debut_cosp
 !    else
@@ -366,5 +365,5 @@
 !        call cosp(overlap,Ncolumns,cfg,vgrid,gbx,sgx,sgradar,sglidar,isccp,misr,modis,rttov,stradar,stlidar)
 !#else
-        call cosp(overlap,Ncolumns,cfg,vgrid,gbx,sgx,sgradar,sglidar,isccp,misr,modis,stradar,stlidar)
+     if (.NOT. debut_cosp) call cosp(overlap,Ncolumns,cfg,vgrid,gbx,sgx,sgradar,sglidar,isccp,misr,modis,stradar,stlidar)
 !#endif
 !!
@@ -374,5 +373,5 @@
 
 !       print *, 'Calling write output'
-        call cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, freq_COSP, missing_val, &
+     if (.NOT. debut_cosp) call cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, freq_COSP, missing_val, &
                                cfg, gbx, vgrid, sglidar, sgradar, stlidar, stradar, & 
                                isccp, misr, modis)
@@ -400,4 +399,7 @@
 !  call system_clock(t1,count_rate,count_max)
 !  print *,(t1-t0)*1.0/count_rate
+    if (debut_cosp) then 
+      debut_cosp=.false.
+    endif
  
   CONTAINS 
Index: /LMDZ6/trunk/libf/phylmd/cosp2/cosp_output_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/cosp2/cosp_output_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/cosp2/cosp_output_mod.F90	(revision 3435)
@@ -359,5 +359,5 @@
    WRITE(lunout,*) 'wxios_add_vaxis cth16 numMISRHgtBins, misr_histHgtCenters ', & 
                     numMISRHgtBins, misr_histHgtCenters 
-   CALL wxios_add_vaxis("cth", numMISRHgtBins, misr_histHgtCenters)
+   CALL wxios_add_vaxis("cth16", numMISRHgtBins, misr_histHgtCenters)
 
    WRITE(lunout,*) 'wxios_add_vaxis dbze DBZE_BINS, dbze_ax ', &
Index: /LMDZ6/trunk/libf/phylmd/cpl_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/cpl_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/cpl_mod.F90	(revision 3435)
@@ -105,5 +105,5 @@
     USE surface_data
     USE indice_sol_mod
-    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
+    USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid1dTo2d_glo
     USE time_phylmdz_mod, ONLY: annee_ref, day_ini, itau_phy, itaufin_phy
     USE print_control_mod, ONLY: lunout
@@ -236,10 +236,10 @@
        idayref = day_ini
        CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
-       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlon,zx_lon)
+       CALL grid1dTo2d_glo(rlon,zx_lon)
        DO i = 1, nbp_lon
           zx_lon(i,1) = rlon(i+1)
           zx_lon(i,nbp_lat) = rlon(i+1)
        ENDDO
-       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlat,zx_lat)
+       CALL grid1dTo2d_glo(rlat,zx_lat)
        clintocplnam="cpl_atm_tauflx"
        CALL histbeg(clintocplnam,nbp_lon,zx_lon(:,1),nbp_lat,zx_lat(1,:),&
Index: /LMDZ6/trunk/libf/phylmd/create_etat0_limit_unstruct.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/create_etat0_limit_unstruct.F90	(revision 3435)
+++ /LMDZ6/trunk/libf/phylmd/create_etat0_limit_unstruct.F90	(revision 3435)
@@ -0,0 +1,98 @@
+MODULE etat0_limit_unstruct_mod
+
+  LOGICAL, SAVE  :: create_etat0_limit
+!$OMP THREADPRIVATE(create_etat0_limit) 
+
+
+
+
+CONTAINS
+  
+  SUBROUTINE init_etat0_limit_unstruct
+  USE xios
+  USE mod_phys_lmdz_para
+  USE mod_grid_phy_lmdz
+  USE ioipsl, ONLY : getin, ioget_year_len
+  USE time_phylmdz_mod, ONLY : annee_ref
+  IMPLICIT NONE
+  
+    INTEGER :: iflag_phys,i
+    INTEGER :: ndays
+    REAL,ALLOCATABLE :: value(:)
+    
+      IF (grid_type==unstructured) THEN
+        IF (is_master) CALL getin("iflag_phys",iflag_phys)
+        CALL bcast(iflag_phys)
+        
+        IF (is_master) CALL getin('create_etat0_limit',create_etat0_limit) 
+        CALL bcast(create_etat0_limit)
+        
+        ndays=ioget_year_len(annee_ref)
+        ALLOCATE(value(ndays))
+        DO i=1,ndays
+          value(i)=i-1
+        ENDDO
+        
+        IF (is_omp_master) CALL xios_set_axis_attr("time_year",n_glo=ndays,value=value) 
+        
+        IF (create_etat0_limit) THEN
+          IF (iflag_phys<100) THEN
+            IF (is_omp_master) CALL xios_set_fieldgroup_attr("etat0_limit_read",read_access=.TRUE.,enabled=.TRUE.)
+            IF (is_omp_master) CALL xios_set_filegroup_attr("etat0_limit_read",enabled=.TRUE.)
+          ENDIF
+          IF (is_omp_master) CALL xios_set_file_attr("limit_write",enabled=.TRUE.)
+        ENDIF
+      
+      ENDIF  
+
+  END SUBROUTINE init_etat0_limit_unstruct
+  
+  SUBROUTINE create_etat0_limit_unstruct
+  USE mod_grid_phy_lmdz
+  USE create_etat0_unstruct_mod
+  USE create_limit_unstruct_mod
+  USE phyaqua_mod
+  USE mod_phys_lmdz_para
+  USE ioipsl, ONLY : getin
+  USE dimphy
+  USE xios
+  IMPLICIT NONE
+      INTEGER :: iflag_phys
+  
+      IF (grid_type==unstructured) THEN
+  
+        IF (is_master) CALL getin("iflag_phys",iflag_phys)
+        CALL bcast(iflag_phys)
+
+        IF (iflag_phys<100) THEN
+          IF ( create_etat0_limit) THEN
+              CALL create_etat0_unstruct
+              CALL create_limit_unstruct
+              IF (is_omp_master)  THEN
+                CALL xios_context_finalize()
+                CALL xios_set_current_context("icosagcm")   ! very bad, need to find an other solution
+                CALL xios_context_finalize()
+                CALL xios_finalize()
+              ENDIF
+!$OMP BARRIER
+              STOP 'create_etat0_limit_unstruct, Initial state file are created, all is fine' 
+          ENDIF 
+        ELSE
+          IF (create_etat0_limit) THEN 
+            CALL iniaqua(klon,iflag_phys)
+              IF (is_omp_master)  THEN
+                CALL xios_context_finalize()
+                CALL xios_set_current_context("icosagcm")   ! very bad, need to find an other solution
+                CALL xios_context_finalize()
+                CALL xios_finalize()
+              ENDIF
+!$OMP BARRIER
+              STOP 'create_etat0_limit_unstruct, Initial state file are created, all is fine' 
+          ENDIF
+        ENDIF
+      ENDIF
+        
+  END SUBROUTINE create_etat0_limit_unstruct
+  
+END MODULE etat0_limit_unstruct_mod
+
Index: /LMDZ6/trunk/libf/phylmd/create_etat0_unstruct.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/create_etat0_unstruct.F90	(revision 3435)
+++ /LMDZ6/trunk/libf/phylmd/create_etat0_unstruct.F90	(revision 3435)
@@ -0,0 +1,190 @@
+MODULE create_etat0_unstruct_mod
+
+
+
+
+
+
+CONTAINS
+
+  SUBROUTINE create_etat0_unstruct
+  USE dimphy
+#ifdef CPP_XIOS
+  USE xios
+  USE infotrac_phy
+  USE fonte_neige_mod
+  USE pbl_surface_mod
+  USE phys_state_var_mod
+  USE indice_sol_mod
+  USE mod_phys_lmdz_para
+  IMPLICIT NONE
+  INCLUDE 'dimsoil.h'
+
+    REAL,    DIMENSION(klon)                 :: tsol
+    REAL,    DIMENSION(klon)                 :: sn
+    REAL,    DIMENSION(klon)                 :: rugmer
+    REAL,    DIMENSION(klon)                 :: run_off_lic_0
+    REAL,    DIMENSION(klon)                 :: lic
+    REAL,    DIMENSION(klon)                 :: fder
+
+    REAL,    DIMENSION(klon,nbsrf)           :: qsolsrf, snsrf
+    REAL,    DIMENSION(klon,nsoilmx,nbsrf)   :: tsoil
+    
+    REAL,    DIMENSION(klon_mpi)             :: tsol_mpi, qsol_mpi, zmasq_mpi, lic_mpi
+    REAL,    DIMENSION(klon_mpi)             :: zmea_mpi, zstd_mpi, zsig_mpi, zgam_mpi, zthe_mpi
+
+    INTEGER :: ji,j,i
+ 
+    IF (is_omp_master) THEN
+      CALL xios_recv_field("ts",tsol_mpi)
+      CALL xios_recv_field("qs",qsol_mpi)
+      CALL xios_recv_field("mask",zmasq_mpi)
+      CALL xios_recv_field("landice",lic_mpi)
+      CALL xios_recv_field("zmea",zmea_mpi)
+      CALL xios_recv_field("zstd",zstd_mpi)
+      CALL xios_recv_field("zsig",zsig_mpi)
+      CALL xios_recv_field("zgam",zgam_mpi)
+      CALL xios_recv_field("zthe",zthe_mpi)
+    ENDIF
+    CALL scatter_omp(tsol_mpi,tsol)
+    CALL scatter_omp(qsol_mpi,qsol)
+    CALL scatter_omp(zmasq_mpi,zmasq)
+    CALL scatter_omp(lic_mpi,lic)
+    CALL scatter_omp(zmea_mpi,zmea)
+    CALL scatter_omp(zstd_mpi,zstd)
+    CALL scatter_omp(zsig_mpi,zsig)
+    CALL scatter_omp(zgam_mpi,zgam)
+    CALL scatter_omp(zthe_mpi,zthe)
+
+    radsol(:)   = 0.0
+    rugmer(:) = 0.001
+    sn(:)     = 0
+
+    WHERE(qsol(:)<0) qsol(:)=0 
+        
+    WHERE(   zmasq(:)<EPSFRA) zmasq(:)=0.
+    WHERE(1.-zmasq(:)<EPSFRA) zmasq(:)=1.
+
+    pctsrf(:,:) = 0
+    pctsrf(:,is_lic)=lic
+    WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0. 
+    WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
+
+    pctsrf(:,is_ter)=zmasq(:)
+
+!--- Adequation with soil/sea mask
+    DO ji=1,klon
+      IF(zmasq(ji)>EPSFRA) THEN 
+        IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
+          pctsrf(ji,is_lic)=zmasq(ji)
+          pctsrf(ji,is_ter)=0.
+        ELSE
+          pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
+          IF(pctsrf(ji,is_ter)<EPSFRA) THEN
+            pctsrf(ji,is_ter)=0.
+            pctsrf(ji,is_lic)=zmasq(ji)
+          END IF 
+        END IF 
+      END IF 
+    END DO 
+    
+! 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.
+    
+    zval(:)=max(0.,zmea-2*zstd(:))
+    zpic(:)=zmea+2*zstd(:)
+    
+!! WARNING    DON'T FORGET FOR LATER
+!!ym  IF(couple) pctsrf(:,is_oce)=ocemask_fi(:)
+!! 
+    
+! 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 >>>
+!ym error : the sub surface dimension is the third not second
+!    falb_dir(:,is_ter,:)=0.08; falb_dir(:,is_lic,:)=0.6
+!    falb_dir(:,is_oce,:)=0.5;  falb_dir(:,is_sic,:)=0.6
+    falb_dir(:,:,is_ter)=0.08; falb_dir(:,:,is_lic)=0.6
+    falb_dir(:,:,is_oce)=0.5;  falb_dir(:,:,is_sic)=0.6
+
+!ym falb_dif has been forgotten, initialize with defaukt value found in phyetat0 or 0 ?
+!ym probably the uninitialized value was 0 for standard (regular grid) case
+    falb_dif(:,:,:)=0
+
+!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.
+!ym warning missing init for sollwdown => set to 0
+  sollwdown  = 0.
+    
+    
+    t_ancien = 273.15
+    u_ancien=0
+    v_ancien=0
+    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
+!*******************************************************************************
+    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.
+    ale_bl = 0.
+    ale_bl_trig =0. 
+    alp_bl =0.
+    CALL fonte_neige_init(run_off_lic_0)
+    CALL pbl_surface_init( fder, snsrf, qsolsrf, tsoil )
+    CALL phyredem( "startphy.nc" )
+
+#endif
+  END SUBROUTINE create_etat0_unstruct
+
+
+END MODULE create_etat0_unstruct_mod
Index: /LMDZ6/trunk/libf/phylmd/create_limit_unstruct.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/create_limit_unstruct.F90	(revision 3435)
+++ /LMDZ6/trunk/libf/phylmd/create_limit_unstruct.F90	(revision 3435)
@@ -0,0 +1,277 @@
+MODULE create_limit_unstruct_mod
+    PRIVATE
+    INTEGER, PARAMETER                             :: lmdep=12
+
+    PUBLIC create_limit_unstruct
+
+CONTAINS
+
+  SUBROUTINE create_limit_unstruct
+  USE dimphy
+#ifdef CPP_XIOS
+  USE xios
+  USE ioipsl,             ONLY : ioget_year_len
+  USE time_phylmdz_mod, ONLY : annee_ref
+  USE indice_sol_mod
+  USE phys_state_var_mod
+  USE mod_phys_lmdz_para
+  IMPLICIT NONE
+    INCLUDE "iniprint.h"
+    REAL,    DIMENSION(klon,lmdep)                 :: sic
+    REAL,    DIMENSION(klon,lmdep)                 :: sst
+    REAL,    DIMENSION(klon,lmdep)                 :: rugos
+    REAL,    DIMENSION(klon,lmdep)                 :: albedo
+    REAL,    DIMENSION(klon_mpi,lmdep)             :: sic_mpi
+    REAL,    DIMENSION(klon_mpi,lmdep)             :: sst_mpi
+    REAL,    DIMENSION(klon_mpi,lmdep)             :: rugos_mpi
+    REAL,    DIMENSION(klon_mpi,lmdep)             :: albedo_mpi
+    INTEGER                                        :: ndays
+    REAL                                           :: fi_ice(klon)
+    REAL, ALLOCATABLE                              :: sic_year(:,:)
+    REAL, ALLOCATABLE                              :: sst_year(:,:)
+    REAL, ALLOCATABLE                              :: rugos_year(:,:)
+    REAL, ALLOCATABLE                              :: albedo_year(:,:)
+    REAL, ALLOCATABLE                              :: pctsrf_t(:,:,:)
+    REAL, ALLOCATABLE                              :: phy_bil(:,:)
+    REAL, ALLOCATABLE                              :: sst_year_mpi(:,:)
+    REAL, ALLOCATABLE                              :: rugos_year_mpi(:,:)
+    REAL, ALLOCATABLE                              :: albedo_year_mpi(:,:)
+    REAL, ALLOCATABLE                              :: pctsrf_t_mpi(:,:,:)
+    REAL, ALLOCATABLE                              :: phy_bil_mpi(:,:)
+    INTEGER :: l,k
+    INTEGER :: nbad
+    
+    ndays=ioget_year_len(annee_ref)
+    
+    IF (is_omp_master) THEN
+      CALL xios_recv_field("sic_limit",sic_mpi)
+      CALL xios_recv_field("sst_limit",sst_mpi)
+      CALL xios_recv_field("rugos_limit",rugos_mpi)
+      CALL xios_recv_field("albedo_limit",albedo_mpi)
+    ENDIF
+    CALL scatter_omp(sic_mpi,sic)
+    CALL scatter_omp(sst_mpi,sst)
+    CALL scatter_omp(rugos_mpi,rugos)
+    CALL scatter_omp(albedo_mpi,albedo)
+    
+    ALLOCATE(sic_year(klon,ndays))
+    ALLOCATE(sst_year(klon,ndays))
+    ALLOCATE(rugos_year(klon,ndays))
+    ALLOCATE(albedo_year(klon,ndays))
+    ALLOCATE(pctsrf_t(klon,nbsrf,ndays))
+    ALLOCATE(phy_bil(klon,ndays)); phy_bil=0.0
+
+! sic
+    CALL time_interpolation(ndays,sic,'gregorian',sic_year)
+    sic_year(:,:)=sic_year(:,:)/100.  ! convert percent to fraction
+    WHERE(sic_year(:,:)>1.0) sic_year(:,:)=1.0    ! Some fractions have some time large negative values
+    WHERE(sic_year(:,:)<0.0) sic_year(:,:)=0.0    ! probably better to apply alse this filter before horizontal interpolation
+    
+! sst
+    CALL time_interpolation(ndays,sst,'gregorian',sst_year)
+    WHERE(sst_year(:,:)<271.38) sst_year(:,:)=271.38
+
+! rugos    
+    DO l=1, lmdep
+      WHERE(NINT(zmasq(:))/=1) rugos(:,l)=0.001
+    ENDDO
+    CALL time_interpolation(ndays,rugos,'360d',rugos_year)
+
+! albedo    
+    CALL time_interpolation(ndays,albedo,'360d',albedo_year)
+
+
+    DO k=1,ndays
+      fi_ice=sic_year(:,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
+    
+    ALLOCATE(sst_year_mpi(klon_mpi,ndays))
+    ALLOCATE(rugos_year_mpi(klon_mpi,ndays))
+    ALLOCATE(albedo_year_mpi(klon_mpi,ndays))
+    ALLOCATE(pctsrf_t_mpi(klon_mpi,nbsrf,ndays))
+    ALLOCATE(phy_bil_mpi(klon_mpi,ndays))
+    
+    CALL gather_omp(pctsrf_t   , pctsrf_t_mpi)
+    CALL gather_omp(sst_year   , sst_year_mpi)
+    CALL gather_omp(phy_bil    , phy_bil_mpi)
+    CALL gather_omp(albedo_year, albedo_year_mpi)
+    CALL gather_omp(rugos_year , rugos_year_mpi)
+
+    IF (is_omp_master) THEN
+      CALL xios_send_field("foce_limout",pctsrf_t_mpi(:,is_oce,:))
+      CALL xios_send_field("fsic_limout",pctsrf_t_mpi(:,is_sic,:))
+      CALL xios_send_field("fter_limout",pctsrf_t_mpi(:,is_ter,:))
+      CALL xios_send_field("flic_limout",pctsrf_t_mpi(:,is_lic,:))
+      CALL xios_send_field("sst_limout", sst_year_mpi)
+      CALL xios_send_field("bils_limout",phy_bil_mpi)
+      CALL xios_send_field("alb_limout", albedo_year_mpi) 
+      CALL xios_send_field("rug_limout", rugos_year_mpi) 
+    ENDIF
+#endif
+  END SUBROUTINE create_limit_unstruct
+  
+  
+  SUBROUTINE time_interpolation(ndays,field_in,calendar,field_out)
+  USE pchsp_95_m, only: pchsp_95
+  USE pchfe_95_m, only: pchfe_95
+  USE arth_m, only: arth
+  USE dimphy, ONLY : klon
+  USE ioipsl,             ONLY : ioget_year_len
+  USE time_phylmdz_mod, ONLY : annee_ref
+  USE mod_phys_lmdz_para
+  IMPLICIT NONE
+   INCLUDE "iniprint.h"
+
+   INTEGER,         INTENT(IN)  :: ndays
+   REAL,            INTENT(IN)  :: field_in(klon,lmdep)
+   CHARACTER(LEN=*),INTENT(IN)  :: calendar
+   REAL,            INTENT(OUT) :: field_out(klon,ndays)
+ 
+   INTEGER :: ndays_in
+   REAL    :: timeyear(lmdep)   
+   REAL    :: yder(lmdep)   
+   INTEGER :: ij,ierr, n_extrap
+   LOGICAL :: skip
+   
+  
+   IF (is_omp_master) ndays_in=year_len(annee_ref, calendar)
+   CALL bcast_omp(ndays_in)
+   timeyear=mid_months(annee_ref, calendar, lmdep)
+    
+   n_extrap = 0
+   skip=.FALSE.
+   DO ij=1,klon
+     yder = pchsp_95(timeyear, field_in(ij, :), ibeg=2, iend=2, vc_beg=0., vc_end=0.)
+     CALL pchfe_95(timeyear, field_in(ij, :), yder, skip, arth(0., real(ndays_in) / ndays, ndays), field_out(ij, :), ierr)
+     if (ierr < 0) stop 1
+     n_extrap = n_extrap + ierr
+   END DO
+   
+   IF (n_extrap /= 0) then
+     WRITE(lunout,*) "get_2Dfield pchfe_95: n_extrap = ", n_extrap
+   ENDIF 
+  
+  
+  END SUBROUTINE time_interpolation
+  !-------------------------------------------------------------------------------
+  !
+  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
+    INTEGER                            :: k
+  !-------------------------------------------------------------------------------
+    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
+  
+
+END MODULE create_limit_unstruct_mod
Index: /LMDZ6/trunk/libf/phylmd/cv3_routines.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/cv3_routines.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/cv3_routines.F90	(revision 3435)
@@ -3749,5 +3749,10 @@
     END DO ! cld
 
+!ym BIG Warning : it seems that the k loop is missing !!!
+!ym Strong advice to check this
+!ym add a k loop temporary 
+
 ! (particular case: no detraining level is found)                              ! cld
+! Verif merge Dynamico<<<<<<< .working
     DO il = 1, ncum                                                            ! cld
       IF (i<=inb(il) .AND. nent(il,i)==0 .AND. iflag(il)<=1) THEN              ! cld
@@ -3761,4 +3766,15 @@
       END IF                                                                   ! cld
     END DO                                                                     ! cld
+! Verif merge Dynamico =======
+! Verif merge Dynamico     DO k = i + 1, nl
+! Verif merge Dynamico       DO il = 1, ncum        !ym k loop added                                    ! cld
+! Verif merge Dynamico         IF (i<=inb(il) .AND. nent(il,i)==0 .AND. iflag(il)<=1) THEN              ! cld
+! Verif merge Dynamico           qcond(il, i) = qcond(il, i) + (1.-ep(il,i))*clw(il, i)                 ! cld
+! Verif merge Dynamico           qtment(il, i) = qent(il,k,i) + qtment(il,i)                          ! cld
+! Verif merge Dynamico           nqcond(il, i) = nqcond(il, i) + 1.                                     ! cld
+! Verif merge Dynamico         END IF                                                                   ! cld
+! Verif merge Dynamico       END DO
+! Verif merge Dynamico     ENDDO                                                                     ! cld
+! Verif merge Dynamico >>>>>>> .merge-right.r3413
 
     DO il = 1, ncum                                                            ! cld
Index: /LMDZ6/trunk/libf/phylmd/cva_driver.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/cva_driver.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/cva_driver.F90	(revision 3435)
@@ -613,4 +613,7 @@
   asupmaxmin1(:) = 0.
 
+  tvp(:, :) = 0. !ym missing init, need to have a look by developpers
+  tv(:, :) = 0. !ym missing init, need to have a look by developpers
+   
   DO il = 1, len
     cin1(il) = -100000.
Index: /LMDZ6/trunk/libf/phylmd/dimphy.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/dimphy.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/dimphy.F90	(revision 3435)
@@ -33,4 +33,5 @@
 !$OMP END MASTER    
     ALLOCATE(zmasq(klon))    
+    zmasq=0.
     
   END SUBROUTINE Init_dimphy
Index: /LMDZ6/trunk/libf/phylmd/grid_noro_m.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/grid_noro_m.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/grid_noro_m.F90	(revision 3435)
@@ -1,2 +1,5 @@
+!
+! $Id$
+!
 MODULE grid_noro_m
 !
@@ -334,6 +337,4 @@
   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.)
Index: /LMDZ6/trunk/libf/phylmd/ini_undefSTD.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ini_undefSTD.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/ini_undefSTD.F90	(revision 3435)
@@ -55,5 +55,5 @@
 
     IF (n==1 .AND. itap-itapm1==1 .OR. n>1 .AND. mod(itap,nint( &
-        freq_outnmc(n)/dtime))==1) THEN
+        freq_outnmc(n)/phys_tstep))==1) THEN
       ! print*,'ini_undefSTD n itap',n,itap
       DO k = 1, nlevstd
Index: /LMDZ6/trunk/libf/phylmd/inifis_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/inifis_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/inifis_mod.F90	(revision 3435)
@@ -6,5 +6,6 @@
   SUBROUTINE inifis(punjours, prad, pg, pr, pcpp)
   ! Initialize some physical constants and settings
-  USE print_control_mod, ONLY: init_print_control, lunout
+  USE init_print_control_mod, ONLY : init_print_control
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
 
Index: /LMDZ6/trunk/libf/phylmd/iophy.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/iophy.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/iophy.F90	(revision 3435)
@@ -18,10 +18,5 @@
 #ifdef CPP_XIOS
   INTERFACE histwrite_phy
-!#ifdef CPP_XIOSnew
     MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old,histwrite2d_xios,histwrite3d_xios,histwrite0d_xios
-!#else
-!    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old,histwrite2d_xios,histwrite3d_xios
-!#endif
-
   END INTERFACE
 #else
@@ -52,11 +47,11 @@
                                   mpi_size, mpi_rank, klon_mpi, &
                                 is_sequential, is_south_pole_dyn
-    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo
-    USE print_control_mod, ONLY: prt_level,lunout 
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid_type, unstructured
+  USE print_control_mod, ONLY: prt_level,lunout 
 #ifdef CPP_IOIPSL
     USE ioipsl, ONLY: flio_dom_set
 #endif
 #ifdef CPP_XIOS
-    USE wxios, ONLY: wxios_domain_param
+  use wxios, ONLY: wxios_domain_param, wxios_domain_param_unstructured, wxios_context_init
 #endif
     IMPLICIT NONE
@@ -77,8 +72,21 @@
     INTEGER :: data_ibegin, data_iend
 
-    CALL gather(rlat,rlat_glo)
-    CALL bcast(rlat_glo)
-    CALL gather(rlon,rlon_glo)
-    CALL bcast(rlon_glo)
+#ifdef CPP_XIOS
+      CALL wxios_context_init
+#endif
+    
+
+    IF (grid_type==unstructured) THEN
+    
+#ifdef CPP_XIOS
+      CALL wxios_domain_param_unstructured("dom_glo")
+#endif
+
+    ELSE
+
+      CALL gather(rlat,rlat_glo)
+      CALL bcast(rlat_glo)
+      CALL gather(rlon,rlon_glo)
+      CALL bcast(rlon_glo)
     
 !$OMP MASTER  
@@ -133,32 +141,34 @@
 #endif
 #ifdef CPP_XIOS
-    ! Set values for the mask:
-    IF (mpi_rank == 0) THEN
-        data_ibegin = 0
-    ELSE 
-        data_ibegin = ii_begin - 1
-    ENDIF
-
-    IF (mpi_rank == mpi_size-1) THEN
-        data_iend = nbp_lon
-    ELSE
-        data_iend = ii_end + 1
-    ENDIF
-
-    IF (prt_level>=10) THEN
-      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," iibegin=",ii_begin , " ii_end=",ii_end," jjbegin=",jj_begin," jj_nb=",jj_nb," jj_end=",jj_end
-      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," nbp_lon=",nbp_lon," nbp_lat=",nbp_lat
-      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
-      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
-      write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," is_south_pole=",is_south_pole_dyn
-    ENDIF
-
-    ! Initialize the XIOS domain coreesponding to this process:
-    CALL wxios_domain_param("dom_glo", is_sequential, nbp_lon, jj_nb, nbp_lon, nbp_lat, &
-                            1, nbp_lon, ii_begin, ii_end, jj_begin, jj_end,             &
-                            klon_mpi+2*(nbp_lon-1), data_ibegin, data_iend,             &
-                            io_lat, io_lon,is_south_pole_dyn,mpi_rank)
+      ! Set values for the mask:
+      IF (mpi_rank == 0) THEN
+          data_ibegin = 0
+      ELSE 
+          data_ibegin = ii_begin - 1
+      END IF
+
+      IF (mpi_rank == mpi_size-1) THEN
+          data_iend = nbp_lon
+      ELSE
+          data_iend = ii_end + 1
+      END IF
+
+      IF (prt_level>=10) THEN
+        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," iibegin=",ii_begin , " ii_end=",ii_end," jjbegin=",jj_begin," jj_nb=",jj_nb," jj_end=",jj_end
+        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," nbp_lon=",nbp_lon," nbp_lat=",nbp_lat
+        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
+        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
+        write(lunout,*) "init_iophy_new: mpirank=",mpi_rank," is_south_pole_dyn=",is_south_pole_dyn
+      ENDIF
+
+      ! Initialize the XIOS domain coreesponding to this process:
 #endif
 !$OMP END MASTER
+
+#ifdef CPP_XIOS    
+        CALL wxios_domain_param("dom_glo")
+#endif
+      
+    ENDIF
       
   END SUBROUTINE init_iophy_new
@@ -291,5 +301,5 @@
                                 is_sequential, klon_mpi_begin, klon_mpi_end, &
                                 mpi_rank
-  USE mod_grid_phy_lmdz, ONLY: klon_glo, nbp_lon, nbp_lat
+  USE mod_grid_phy_lmdz, ONLY: klon_glo, nbp_lon, nbp_lat, grid1dTo2d_glo
   USE ioipsl, ONLY: histbeg
 
@@ -366,5 +376,5 @@
      ENDDO
 
-       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlon_glo,zx_lon)
+       CALL grid1dTo2d_glo(rlon_glo,zx_lon)
        IF ((nbp_lon*nbp_lat).GT.1) THEN
        DO i = 1, nbp_lon
@@ -373,5 +383,5 @@
        ENDDO
        ENDIF
-       CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlat_glo,zx_lat)
+       CALL grid1dTo2d_glo(rlat_glo,zx_lat)
 
     DO i=1,pim
@@ -963,8 +973,9 @@
                                  nid_files, swaerofree_diag, swaero_diag, dryaod_diag, ok_4xCO2atm
   USE print_control_mod, ONLY: prt_level,lunout
-  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid_type, unstructured, regular_lonlat
 #ifdef CPP_XIOS
   USE xios, ONLY: xios_send_field
 #endif
+  USE print_control_mod, ONLY: lunout, prt_level
 
   IMPLICIT NONE
@@ -1007,5 +1018,6 @@
       IF (.not. ok_all_xml) THEN
       IF (prt_level >= 10) THEN
-      WRITE (lunout,*)"histwrite2d_phy: .not.vars_defined ; time to define ", trim(var%name)
+      write(lunout,*)"histwrite2d_phy: .not.vars_defined ; time to define ", &
+                     trim(var%name)
       ENDIF
       DO iff=iff_beg, iff_end
@@ -1037,5 +1049,5 @@
     ENDIF
 !$OMP MASTER
-    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
+    IF (grid_type==regular_lonlat) CALL grid1Dto2D_mpi(buffer_omp,Field2d)
 
 ! La boucle sur les fichiers:
@@ -1047,11 +1059,17 @@
              write(lunout,*)'Dans iophy histwrite2D,var%name ', trim(var%name)                       
           ENDIF
-          IF (SIZE(field) == klon) then
+          
+          IF (grid_type==regular_lonlat) THEN
+            IF (SIZE(field) == klon) then
               CALL xios_send_field(var%name, Field2d)
-          ELSE
-             CALL xios_send_field(var%name, field)
-          ENDIF 
+            ELSE
+               CALL xios_send_field(var%name, field)
+            ENDIF 
+          ELSE IF (grid_type==unstructured) THEN
+            CALL xios_send_field(var%name, buffer_omp)
+          ENDIF
           IF (prt_level >= 10) THEN
-             WRITE (lunout,*)'Dans iophy histwrite2D,var%name apres xios_send ', trim(var%name)                       
+             write(lunout,*)'Dans iophy histwrite2D,var%name apres xios_send ',&
+                             trim(var%name)                       
           ENDIF
 #else
@@ -1065,12 +1083,18 @@
                IF (firstx) THEN
                   IF (prt_level >= 10) THEN
-                     WRITE (lunout,*)'Dans iophy histwrite2D,iff,var%name ', iff,trim(var%name)                       
-                     WRITE (lunout,*)"histwrite2d_phy:.NOT.clef_stations(iff)and iff==iff_beg, call xios_send_field"
+                     write(lunout,*)'Dans iophy histwrite2D,iff,var%name ',&
+                                    iff,trim(var%name)                       
+                     write(lunout,*)"histwrite2d_phy:.NOT.clef_stations(iff)and iff==iff_beg, call xios_send_field"
                   ENDIF
-                  IF (SIZE(field) == klon) then
-                     CALL xios_send_field(var%name, Field2d)
-                  ELSE
-                     CALL xios_send_field(var%name, field)
+                  IF (grid_type==regular_lonlat) THEN
+                    IF (SIZE(field) == klon) then
+                       CALL xios_send_field(var%name, Field2d)
+                    ELSE
+                       CALL xios_send_field(var%name, field)
+                    ENDIF
+                  ELSE IF (grid_type==unstructured) THEN
+                    CALL xios_send_field(var%name, buffer_omp)
                   ENDIF
+
                   firstx=.false.
                ENDIF
@@ -1085,7 +1109,7 @@
 !#ifdef CPP_XIOS
 !                        IF (iff == iff_beg) THEN
-!                          if (prt_level >= 10) then
+!                          IF (prt_level >= 10) THEN
 !                            write(lunout,*)"histwrite2d_phy: .NOT.clef_stations(iff) and iff==iff_beg, call xios_send_field"
-!                          endif
+!                          ENDIF
 !                          CALL xios_send_field(var%name, Field2d)
 !                        ENDIF
@@ -1109,5 +1133,5 @@
                        ENDIF ! of IF (is_sequential)
 #ifndef CPP_IOIPSL_NO_OUTPUT 
-                       IF (prt_level >= 10) THEn
+                       IF (prt_level >= 10) THEN
                          write(lunout,*)"histwrite2d_phy: clef_stations(iff) and iff==iff_beg, call wxios_write_2D"
                        ENDIF
@@ -1141,5 +1165,5 @@
                                  nfiles, vars_defined, clef_stations, &
                                  nid_files, swaerofree_diag
-  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid_type, regular_lonlat, unstructured
 #ifdef CPP_XIOS
   USE xios, ONLY: xios_send_field
@@ -1206,5 +1230,5 @@
     ENDIF
 !$OMP MASTER
-    CALL grid1Dto2D_mpi(buffer_omp,field3d)
+    IF (grid_type==regular_lonlat) CALL grid1Dto2D_mpi(buffer_omp,field3d)
 
 ! BOUCLE SUR LES FICHIERS
@@ -1213,12 +1237,18 @@
     IF (ok_all_xml) THEN
 #ifdef CPP_XIOS
-        IF (prt_level >= 10) THEN
-             write(lunout,*)'Dans iophy histwrite3D,var%name ',trim(var%name)                       
+          IF (prt_level >= 10) THEN
+             write(lunout,*)'Dans iophy histwrite3D,var%name ',&
+                             trim(var%name)                       
+          ENDIF
+          IF (grid_type==regular_lonlat) THEN
+            IF (SIZE(field,1) == klon) then
+               CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
+            ELSE
+               CALL xios_send_field(var%name, field)
+            ENDIF
+          ELSE IF (grid_type==unstructured) THEN
+            CALL xios_send_field(var%name, buffer_omp(:,1:nlevx))
         ENDIF
-        IF (SIZE(field,1) == klon) then
-             CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
-        ELSE
-             CALL xios_send_field(var%name, field)
-        ENDIF
+
 #else
         CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
@@ -1230,16 +1260,21 @@
 #ifdef CPP_XIOS
               IF (firstx) THEN
-                IF (prt_level >= 10) THEn
-                  WRITE (lunout,*)'Dans iophy, histwrite3D iff nlev klev firstx', &
+                IF (prt_level >= 10) THEN
+                  write(lunout,*)'Dans iophy, histwrite3D iff nlev klev firstx', &
                                   iff,nlev,klev, firstx                       
-                  WRITE (lunout,*)'histwrite3d_phy: call xios_send_field for ', &
+                  write(lunout,*)'histwrite3d_phy: call xios_send_field for ', &
                                   trim(var%name), ' with iim jjm nlevx = ', &
                                   nbp_lon,jj_nb,nlevx
                 ENDIF
-                IF (SIZE(field,1) == klon) then
-                    CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
-                ELSE
-                     CALL xios_send_field(var%name, field)
+                IF (grid_type==regular_lonlat) THEN
+                  IF (SIZE(field,1) == klon) then
+                      CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
+                  ELSE
+                       CALL xios_send_field(var%name, field)
+                  ENDIF
+                ELSE IF (grid_type==unstructured) THEN
+                  CALL xios_send_field(var%name, buffer_omp(:,1:nlevx))
                 ENDIF
+
                 firstx=.false.
               ENDIF
@@ -1305,5 +1340,5 @@
                                 is_sequential, klon_mpi_begin, klon_mpi_end, &
                                 jj_nb, klon_mpi, is_master
-  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid_type, unstructured
   USE xios, ONLY: xios_send_field
   USE print_control_mod, ONLY: prt_level,lunout
@@ -1335,4 +1370,11 @@
         CALL Gather_omp(field,buffer_omp)    
 !$OMP MASTER
+
+      IF (grid_type==unstructured) THEN
+  
+        CALL xios_send_field(field_name, buffer_omp)
+
+      ELSE
+
         CALL grid1Dto2D_mpi(buffer_omp,Field2d)
     
@@ -1342,7 +1384,4 @@
     !IF(.NOT.clef_stations(iff)) THEN
         IF (.TRUE.) THEN
-            ALLOCATE(index2d(nbp_lon*jj_nb))
-            ALLOCATE(fieldok(nbp_lon*jj_nb))
-    
     
             CALL xios_send_field(field_name, Field2d)
@@ -1365,9 +1404,9 @@
                 ENDDO
             ENDIF
-    
-        ENDIF
-                  
-        DEALLOCATE(index2d)
-        DEALLOCATE(fieldok)
+            DEALLOCATE(index2d)
+            DEALLOCATE(fieldok)
+    
+        ENDIF                  
+      ENDIF
 !$OMP END MASTER   
   ENDIF
@@ -1385,5 +1424,5 @@
                                 jj_nb, klon_mpi, is_master
   USE xios, ONLY: xios_send_field
-  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat
+  USE mod_grid_phy_lmdz, ONLY : nbp_lon, nbp_lat, grid_type, unstructured
   USE print_control_mod, ONLY: prt_level,lunout
 
@@ -1416,4 +1455,10 @@
         CALL Gather_omp(field,buffer_omp)
 !$OMP MASTER
+
+    IF (grid_type==unstructured) THEN
+
+      CALL xios_send_field(field_name, buffer_omp(:,1:nlev))
+
+    ELSE
         CALL grid1Dto2D_mpi(buffer_omp,field3d)
 
@@ -1423,7 +1468,6 @@
     !IF (.NOT.clef_stations(iff)) THEN
         IF(.TRUE.)THEN
-            ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
-            ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
-            CALL xios_send_field(field_name, Field3d(:,:,1:nlev))
+
+           CALL xios_send_field(field_name, Field3d(:,:,1:nlev))
                             
         ELSE 
@@ -1448,7 +1492,8 @@
                 ENDDO
             ENDIF
+            DEALLOCATE(index3d)
+            DEALLOCATE(fieldok)
         ENDIF 
-        DEALLOCATE(index3d)
-        DEALLOCATE(fieldok)
+      ENDIF
 !$OMP END MASTER   
   ENDIF
Index: /LMDZ6/trunk/libf/phylmd/iostart.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/iostart.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/iostart.F90	(revision 3435)
@@ -117,4 +117,5 @@
   USE netcdf
   USE dimphy
+  USE geometry_mod
   USE mod_grid_phy_lmdz
   USE mod_phys_lmdz_para
@@ -126,14 +127,19 @@
     
     REAL    :: field_glo(klon_glo,field_size)
+    REAL    :: field_glo_tmp(klon_glo,field_size)
+    INTEGER :: ind_cell_glo_glo(klon_glo)
     LOGICAL :: tmp_found
     INTEGER :: varid
-    INTEGER :: ierr
-    
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    INTEGER :: ierr,i
+
+!    IF (is_master) ALLOCATE(ind_cell_glo_glo(1:klon_glo))
+    CALL gather(ind_cell_glo,ind_cell_glo_glo)
+    
+    IF (is_master) THEN
   
       ierr=NF90_INQ_VARID(nid_start,Field_name,varid)
       
       IF (ierr==NF90_NOERR) THEN
-        CALL body(field_glo)
+        CALL body(field_glo_tmp)
         tmp_found=.TRUE.
       ELSE
@@ -146,4 +152,9 @@
 
     IF (tmp_found) THEN
+      IF (is_master) THEN  
+        DO i=1,klon_glo
+         field_glo(i,:)=field_glo_tmp(ind_cell_glo_glo(i),:)
+        ENDDO
+      ENDIF
       CALL scatter(field_glo,field)
     ENDIF
@@ -358,4 +369,5 @@
   USE netcdf
   USE dimphy
+  USE geometry_mod
   USE mod_grid_phy_lmdz
   USE mod_phys_lmdz_para
@@ -367,12 +379,23 @@
   
   REAL                           :: field_glo(klon_glo,field_size)
-  INTEGER                        :: ierr
+  REAL                           :: field_glo_tmp(klon_glo,field_size)
+!  INTEGER,ALLOCATABLE            :: ind_cell_glo_glo(:)
+  INTEGER                        :: ind_cell_glo_glo(klon_glo)
+  INTEGER                        :: ierr,i
   INTEGER                        :: nvarid
   INTEGER                        :: idim
    
    
-    CALL gather(field,field_glo)
-    
-    IF (is_mpi_root .AND. is_omp_root) THEN
+!    IF (is_master) ALLOCATE(ind_cell_glo_glo(klon_glo))
+    CALL gather(ind_cell_glo,ind_cell_glo_glo)
+
+    CALL gather(field,field_glo_tmp)
+    
+    IF (is_master) THEN
+
+      DO i=1,klon_glo
+       field_glo(ind_cell_glo_glo(i),:)=field_glo_tmp(i,:)
+      ENDDO
+
 
       IF (field_size==1) THEN
Index: /LMDZ6/trunk/libf/phylmd/limit_read_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/limit_read_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/limit_read_mod.F90	(revision 3435)
@@ -1,4 +1,4 @@
 !
-! $Header$
+! $Id$
 !
 MODULE limit_read_mod
@@ -31,4 +31,26 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
+
+  SUBROUTINE init_limit_read(first_day)
+  USE mod_grid_phy_lmdz
+  USE surface_data
+  USE mod_phys_lmdz_para
+#ifdef CPP_XIOS
+  USE XIOS
+#endif
+  IMPLICIT NONE
+    INTEGER, INTENT(IN) :: first_day
+    
+    
+    IF ( type_ocean /= 'couple') THEN
+      IF (grid_type==unstructured) THEN
+#ifdef CPP_XIOS
+        IF (is_omp_master) CALL xios_set_file_attr("limit_read",enabled=.TRUE.,record_offset=first_day)
+#endif
+      ENDIF  
+    ENDIF
+
+  END SUBROUTINE init_limit_read
+  
   SUBROUTINE limit_read_frac(itime, dtime, jour, pctsrf_new, is_modified)
 !
@@ -150,5 +172,8 @@
     USE phys_cal_mod, ONLY : calend, year_len
     USE print_control_mod, ONLY: lunout, prt_level
-
+#ifdef CPP_XIOS
+    USE XIOS, ONLY: xios_recv_field
+#endif
+    
     IMPLICIT NONE
     
@@ -179,4 +204,10 @@
     REAL, DIMENSION(klon_glo)                 :: rug_glo  ! rugosity at global grid
     REAL, DIMENSION(klon_glo)                 :: alb_glo  ! albedo at global grid
+
+    REAL, DIMENSION(klon_mpi,nbsrf)           :: pct_mpi  ! fraction at global grid
+    REAL, DIMENSION(klon_mpi)                 :: sst_mpi  ! sea-surface temperature at global grid
+    REAL, DIMENSION(klon_mpi)                 :: rug_mpi  ! rugosity at global grid
+    REAL, DIMENSION(klon_mpi)                 :: alb_mpi  ! albedo at global grid
+
     CHARACTER(len=20)                         :: modname='limit_read_mod'     
     CHARACTER(LEN=99)                         :: abort_message, calendar, str
@@ -220,13 +251,21 @@
           END IF
 
-          !--- ERROR IF FILE RECORDS NUMBER IS NOT EQUAL TO EXPECTED NUMBER OF DAYS
-          ierr=NF90_INQUIRE(nid, UnlimitedDimID=ndimid)
+          !--- ERROR IF FILE RECORDS NUMBER IS NOT EQUAL TO EXPECTED NUMBER OF DAYS          
+          IF (grid_type==unstructured) THEN
+            ierr=NF90_INQ_DIMID(nid,"time_year",ndimid)
+          ELSE
+            ierr=NF90_INQUIRE(nid, UnlimitedDimID=ndimid)
+          ENDIF
           ierr=NF90_INQUIRE_DIMENSION(nid, ndimid, len=nn)
-          WRITE(abort_message,'(a,2(i3,a))')'limit.nc records number (',nn,') does no'//&
+          WRITE(abort_message,'(a,2(i0,a))')'limit.nc records number (',nn,') does no'//&
             't match year length (',year_len,')'
           IF(nn/=year_len) CALL abort_physic(modname,abort_message,1)
 
           !--- ERROR IF FILES AND LMDZ HORIZONTAL RESOLUTIONS DO NOT MATCH
-          ierr=NF90_INQ_DIMID(nid, 'points_physiques', ndimid)
+          IF (grid_type==unstructured) THEN
+            ierr=NF90_INQ_DIMID(nid, 'cell', ndimid)
+          ELSE
+            ierr=NF90_INQ_DIMID(nid, 'points_physiques', ndimid)
+          ENDIF
           ierr=NF90_INQUIRE_DIMENSION(nid, ndimid, len=nn)
           WRITE(abort_message,'(a,2(i0,a))')'limit.nc horizontal number of cells (',nn, &
@@ -249,9 +288,54 @@
 
     is_modified = .FALSE.
-    IF (MOD(itime-1, lmt_pas) == 0 .OR. jour_lu /= jour ) THEN   ! time to read
+!ym    IF (MOD(itime-1, lmt_pas) == 0 .OR. jour_lu /= jour ) THEN   ! time to read
+!  not REALLY PERIODIC
+    IF (MOD(itime-1, lmt_pas) == 0 .OR. (jour_lu /= jour .AND. grid_type /= unstructured)) THEN   ! time to read
+!    IF (MOD(itime-1, lmt_pas) == 0) THEN   ! time to read
        jour_lu = jour
        is_modified = .TRUE.
+
+      IF (grid_type==unstructured) THEN
+
+#ifdef CPP_XIOS
+        IF ( type_ocean /= 'couple') THEN
+
+           IF (is_omp_master) CALL xios_recv_field("foce_limin",pct_mpi(:,is_oce))
+           IF (is_omp_master) CALL xios_recv_field("fsic_limin",pct_mpi(:,is_sic))
+  !         IF (read_continents .OR. itime == 1) THEN
+           IF (is_omp_master) CALL xios_recv_field("fter_limin",pct_mpi(:,is_ter))
+           IF (is_omp_master) CALL xios_recv_field("flic_limin",pct_mpi(:,is_lic))
+  !         ENDIF
+         ENDIF! type_ocean /= couple
+         
+         IF ( type_ocean /= 'couple') THEN                    
+             IF (is_omp_master) CALL xios_recv_field("sst_limin",sst_mpi)
+         ENDIF
+       
+         IF (.NOT. ok_veget) THEN
+           IF (is_omp_master) CALL xios_recv_field("alb_limin",alb_mpi)
+           IF (is_omp_master) CALL xios_recv_field("rug_limin",rug_mpi)
+         ENDIF
+
+       IF ( type_ocean /= 'couple') THEN
+          CALL Scatter_omp(sst_mpi,sst)
+          CALL Scatter_omp(pct_mpi(:,is_oce),pctsrf(:,is_oce))
+          CALL Scatter_omp(pct_mpi(:,is_sic),pctsrf(:,is_sic))
+!          IF (read_continents .OR. itime == 1) THEN
+             CALL Scatter_omp(pct_mpi(:,is_ter),pctsrf(:,is_ter))
+             CALL Scatter_omp(pct_mpi(:,is_lic),pctsrf(:,is_lic))
+!          END IF
+       END IF
+
+       IF (.NOT. ok_veget) THEN
+          CALL Scatter_omp(alb_mpi, albedo)
+          CALL Scatter_omp(rug_mpi, rugos)
+       END IF
+#endif
+
+ 
+     ELSE      ! grid_type==regular
+
 !$OMP MASTER  ! Only master thread
-       IF (is_mpi_root) THEN ! Only master processus
+       IF (is_mpi_root) THEN ! Only master processus!
 
           ierr = NF90_OPEN ('limit.nc', NF90_NOWRITE, nid)
@@ -371,4 +455,6 @@
        END IF
 
+      ENDIF ! Grid type
+
     ENDIF ! time to read
 
Index: /LMDZ6/trunk/libf/phylmd/moy_undefSTD.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/moy_undefSTD.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/moy_undefSTD.F90	(revision 3435)
@@ -75,5 +75,5 @@
 
     IF (n==1 .AND. itap==itapm1 .OR. n>1 .AND. mod(itap,nint(freq_outnmc(n)/ & 
-        dtime))==0) THEN
+        phys_tstep))==0) THEN
 
       ! print*,'moy_undefSTD n itap itapm1',n,itap,itapm1
@@ -140,5 +140,5 @@
         END DO !i
       END DO !k
-    END IF !MOD(itap,NINT(freq_outNMC(n)/dtime)).EQ.0
+    END IF !MOD(itap,NINT(freq_outNMC(n)/phys_tstep)).EQ.0
 
   END DO !n
Index: /LMDZ6/trunk/libf/phylmd/pbl_surface_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/pbl_surface_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/pbl_surface_mod.F90	(revision 3435)
@@ -59,4 +59,5 @@
     USE print_control_mod, ONLY: lunout
     USE ioipsl_getin_p_mod, ONLY : getin_p
+    IMPLICIT NONE
 
     INCLUDE "dimsoil.h"
@@ -287,5 +288,5 @@
     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 mod_grid_phy_lmdz,  ONLY : nbp_lon, nbp_lat, grid1dto2d_glo
     USE print_control_mod,  ONLY : prt_level,lunout
     USE ioipsl_getin_p_mod, ONLY : getin_p
@@ -852,10 +853,10 @@
           idayref = day_ini
           CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
-          CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlon,zx_lon)
+          CALL grid1dTo2d_glo(rlon,zx_lon)
           DO i = 1, nbp_lon
              zx_lon(i,1) = rlon(i+1)
              zx_lon(i,nbp_lat) = rlon(i+1)
           ENDDO
-          CALL gr_fi_ecrit(1,klon,nbp_lon,nbp_lat,rlat,zx_lat)
+          CALL grid1dTo2d_glo(rlat,zx_lat)
           CALL histbeg("sous_index",nbp_lon,zx_lon(:,1),nbp_lat,zx_lat(1,:), &
                1,nbp_lon,1,nbp_lat, &
@@ -1927,5 +1928,5 @@
                itap, dtime, jour, knon, ni, &
 !!jyg               ypplay(:,1), zgeo1/RG, ycdragh, ycdragm, yrain_f, ysnow_f, yt(:,1), yq(:,1),&
-               ypplay(:,1), zgeo1/RG, ycdragh, ycdragm, yrain_f, ysnow_f, yt1, yq1,&
+               ypplay(:,1), zgeo1(1:knon)/RG, ycdragh, ycdragm, yrain_f, ysnow_f, yt(:,1), yq(:,1),&    ! ym missing init
                AcoefH, AcoefQ, BcoefH, BcoefQ, &
                AcoefU, AcoefV, BcoefU, BcoefV, &
Index: /LMDZ6/trunk/libf/phylmd/phyaqua_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/phyaqua_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/phyaqua_mod.F90	(revision 3435)
@@ -29,5 +29,9 @@
     USE indice_sol_mod
     USE nrtype, ONLY: pi
-    USE ioipsl
+!    USE ioipsl
+    USE mod_phys_lmdz_para, ONLY: is_master
+    USE mod_phys_lmdz_transfert_para, ONLY: bcast
+    USE mod_grid_phy_lmdz
+    USE ioipsl_getin_p_mod, ONLY : getin_p
     IMPLICIT NONE
 
@@ -57,6 +61,4 @@
     INTEGER it, unit, i, k, itap
 
-    REAL airefi, zcufi, zcvfi
-
     REAL rugos, albedo
     REAL tsurf
@@ -64,9 +66,5 @@
     REAL qsol_f
     REAL rugsrel(nlon)
-    ! real zmea(nlon),zstd(nlon),zsig(nlon)
-    ! real zgam(nlon),zthe(nlon),zpic(nlon),zval(nlon)
-    ! real rlon(nlon),rlat(nlon)
     LOGICAL alb_ocean
-    ! integer demih_pas
 
     CHARACTER *80 ans, file_forctl, file_fordat, file_start
@@ -86,11 +84,6 @@
 
     INTEGER, SAVE :: read_climoz = 0 ! read ozone climatology
-
-    ! intermediate variables to use getin (need to be "save" to be shared by
-    ! all threads)
-    INTEGER, SAVE :: nbapp_rad_omp
-    REAL, SAVE :: co2_ppm_omp, solaire_omp
-    LOGICAL, SAVE :: alb_ocean_omp
-    REAL, SAVE :: rugos_omp
+!$OMP THREADPRIVATE(read_climoz)
+
     ! -------------------------------------------------------------------------
     ! declaration pour l'appel a phyredem
@@ -117,8 +110,6 @@
     INTEGER l, ierr, aslun
 
-!    REAL longitude, latitude
     REAL paire
 
-!    DATA latitude, longitude/48., 0./
 
     ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -148,10 +139,4 @@
     time = 0.
 
-    ! IM ajout latfi, lonfi
-!    rlatd = latfi
-!    rlond = lonfi
-!    rlat = rlatd*180./pi
-!    rlon = rlond*180./pi
-
     ! -----------------------------------------------------------------------
     ! initialisations de la physique
@@ -160,13 +145,7 @@
     day_ini = day_ref
     day_end = day_ini + ndays
-!    airefi = 1.
-!    zcufi = 1.
-!    zcvfi = 1.
-    !$OMP MASTER
-    nbapp_rad_omp = 24
-    CALL getin('nbapp_rad', nbapp_rad_omp)
-    !$OMP END MASTER
-    !$OMP BARRIER
-    nbapp_rad = nbapp_rad_omp
+
+    nbapp_rad = 24
+    CALL getin_p('nbapp_rad', nbapp_rad)
 
     ! ---------------------------------------------------------------------
@@ -175,20 +154,17 @@
     ! Initialisations des constantes
     ! Ajouter les manquants dans planete.def... (albedo etc)
-    !$OMP MASTER
-    co2_ppm_omp = 348.
-    CALL getin('co2_ppm', co2_ppm_omp)
-    solaire_omp = 1365.
-    CALL getin('solaire', solaire_omp)
+    co2_ppm = 348.
+    CALL getin_p('co2_ppm', co2_ppm)
+
+    solaire = 1365.
+    CALL getin_p('solaire', solaire)
+ 
     ! CALL getin('albedo',albedo) ! albedo is set below, depending on
     ! type_aqua
-    alb_ocean_omp = .TRUE.
-    CALL getin('alb_ocean', alb_ocean_omp)
-    !$OMP END MASTER
-    !$OMP BARRIER
-    co2_ppm = co2_ppm_omp
+    alb_ocean = .TRUE.
+    CALL getin_p('alb_ocean', alb_ocean)
+
     WRITE (*, *) 'iniaqua: co2_ppm=', co2_ppm
-    solaire = solaire_omp
     WRITE (*, *) 'iniaqua: solaire=', solaire
-    alb_ocean = alb_ocean_omp
     WRITE (*, *) 'iniaqua: alb_ocean=', alb_ocean
 
@@ -226,10 +202,6 @@
     END IF
 
-    !$OMP MASTER
-    rugos_omp = rugos
-    CALL getin('rugos', rugos_omp)
-    !$OMP END MASTER
-    !$OMP BARRIER
-    rugos = rugos_omp
+    CALL getin_p('rugos', rugos)
+
     WRITE (*, *) 'iniaqua: rugos=', rugos
     zmasq(:) = pctsrf(:, is_ter)
@@ -262,7 +234,12 @@
     CALL profil_sst(nlon, latitude, type_profil, phy_sst)
 
-    CALL writelim(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, phy_ice, &
-      phy_fter, phy_foce, phy_flic, phy_fsic)
-
+    IF (grid_type==unstructured) THEN
+      CALL writelim_unstruct(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, phy_ice, &
+                             phy_fter, phy_foce, phy_flic, phy_fsic)
+    ELSE
+      
+       CALL writelim(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, phy_ice, &
+                     phy_fter, phy_foce, phy_flic, phy_fsic)
+    ENDIF
 
     ! ---------------------------------------------------------------------
@@ -339,5 +316,5 @@
     PRINT *, 'iniaqua: before phyredem'
 
-    pbl_tke(:,:,:)=1.e-8
+    pbl_tke(:,:,:) = 1.e-8 
     falb1 = albedo
     falb2 = albedo
@@ -349,5 +326,5 @@
     wake_deltaq = 0.
     wake_s = 0.
-    wake_dens = 0. 
+    wake_dens = 0.
     wake_cstar = 0.
     wake_pe = 0.
@@ -360,4 +337,14 @@
     alp_bl =0.
     treedrg(:,:,:)=0.
+
+!ym error : the sub surface dimension is the third not second : forgotten for iniaqua
+!    falb_dir(:,is_ter,:)=0.08; falb_dir(:,is_lic,:)=0.6
+!    falb_dir(:,is_oce,:)=0.5;  falb_dir(:,is_sic,:)=0.6
+    falb_dir(:,:,is_ter)=0.08; falb_dir(:,:,is_lic)=0.6
+    falb_dir(:,:,is_oce)=0.5;  falb_dir(:,:,is_sic)=0.6
+
+!ym falb_dif has been forgotten, initialize with defaukt value found in phyetat0 or 0 ?
+!ym probably the uninitialized value was 0 for standard (regular grid) case
+    falb_dif(:,:,:)=0
 
 
@@ -488,11 +475,14 @@
   ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-  SUBROUTINE writelim(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, &
+  SUBROUTINE writelim_unstruct(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, &
       phy_ice, phy_fter, phy_foce, phy_flic, phy_fsic)
 
-    USE mod_phys_lmdz_para, ONLY: is_mpi_root, is_omp_root
-    USE mod_grid_phy_lmdz, ONLY: klon_glo
-    USE mod_phys_lmdz_transfert_para, ONLY: gather
+    USE mod_phys_lmdz_para, ONLY: is_omp_master, klon_mpi
+    USE mod_phys_lmdz_transfert_para, ONLY: gather_omp
+#ifdef CPP_XIOS
+    USE xios
+#endif
     IMPLICIT NONE
+
     include "netcdf.inc"
 
@@ -509,4 +499,59 @@
     REAL, INTENT (IN) :: phy_fsic(klon, 360)
 
+    REAL :: phy_mpi(klon_mpi, 360) ! temporary variable, to store phy_***(:)
+      ! on the whole physics grid
+ 
+#ifdef CPP_XIOS
+    PRINT *, 'writelim: Ecriture du fichier limit'
+
+    CALL gather_omp(phy_foce, phy_mpi)
+    IF (is_omp_master) CALL xios_send_field('foce_limout',phy_mpi)
+
+    CALL gather_omp(phy_fsic, phy_mpi)
+    IF (is_omp_master) CALL xios_send_field('fsic_limout',phy_mpi)
+      
+    CALL gather_omp(phy_fter, phy_mpi)
+    IF (is_omp_master) CALL xios_send_field('fter_limout',phy_mpi)
+      
+    CALL gather_omp(phy_flic, phy_mpi)
+    IF (is_omp_master) CALL xios_send_field('flic_limout',phy_mpi)
+
+    CALL gather_omp(phy_sst, phy_mpi)
+    IF (is_omp_master) CALL xios_send_field('sst_limout',phy_mpi)
+
+    CALL gather_omp(phy_bil, phy_mpi)
+    IF (is_omp_master) CALL xios_send_field('bils_limout',phy_mpi)
+
+    CALL gather_omp(phy_alb, phy_mpi)
+    IF (is_omp_master) CALL xios_send_field('alb_limout',phy_mpi)
+
+    CALL gather_omp(phy_rug, phy_mpi)
+    IF (is_omp_master) CALL xios_send_field('rug_limout',phy_mpi)
+#endif
+  END SUBROUTINE writelim_unstruct
+
+
+
+  SUBROUTINE writelim(klon, phy_nat, phy_alb, phy_sst, phy_bil, phy_rug, &
+      phy_ice, phy_fter, phy_foce, phy_flic, phy_fsic)
+
+    USE mod_phys_lmdz_para, ONLY: is_master
+    USE mod_grid_phy_lmdz, ONLY: klon_glo
+    USE mod_phys_lmdz_transfert_para, ONLY: gather
+    IMPLICIT NONE
+    include "netcdf.inc"
+
+    INTEGER, INTENT (IN) :: klon
+    REAL, INTENT (IN) :: phy_nat(klon, 360)
+    REAL, INTENT (IN) :: phy_alb(klon, 360)
+    REAL, INTENT (IN) :: phy_sst(klon, 360)
+    REAL, INTENT (IN) :: phy_bil(klon, 360)
+    REAL, INTENT (IN) :: phy_rug(klon, 360)
+    REAL, INTENT (IN) :: phy_ice(klon, 360)
+    REAL, INTENT (IN) :: phy_fter(klon, 360)
+    REAL, INTENT (IN) :: phy_foce(klon, 360)
+    REAL, INTENT (IN) :: phy_flic(klon, 360)
+    REAL, INTENT (IN) :: phy_fsic(klon, 360)
+
     REAL :: phy_glo(klon_glo, 360) ! temporary variable, to store phy_***(:)
       ! on the whole physics grid
@@ -522,5 +567,5 @@
     INTEGER id_fter, id_foce, id_fsic, id_flic
 
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
 
       PRINT *, 'writelim: Ecriture du fichier limit'
@@ -627,10 +672,10 @@
       END DO
 
-    END IF ! of if (is_mpi_root.and.is_omp_root)
+    END IF ! of if (is_master)
 
     ! write the fields, after having collected them on master
 
     CALL gather(phy_nat, phy_glo)
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
 #ifdef NC_DOUBLE
       ierr = nf_put_var_double(nid, id_nat, phy_glo)
@@ -645,5 +690,5 @@
 
     CALL gather(phy_sst, phy_glo)
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
 #ifdef NC_DOUBLE
       ierr = nf_put_var_double(nid, id_sst, phy_glo)
@@ -658,5 +703,5 @@
 
     CALL gather(phy_bil, phy_glo)
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
 #ifdef NC_DOUBLE
       ierr = nf_put_var_double(nid, id_bils, phy_glo)
@@ -671,5 +716,5 @@
 
     CALL gather(phy_alb, phy_glo)
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
 #ifdef NC_DOUBLE
       ierr = nf_put_var_double(nid, id_alb, phy_glo)
@@ -684,5 +729,5 @@
 
     CALL gather(phy_rug, phy_glo)
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
 #ifdef NC_DOUBLE
       ierr = nf_put_var_double(nid, id_rug, phy_glo)
@@ -697,5 +742,5 @@
 
     CALL gather(phy_fter, phy_glo)
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
 #ifdef NC_DOUBLE
       ierr = nf_put_var_double(nid, id_fter, phy_glo)
@@ -710,5 +755,5 @@
 
     CALL gather(phy_foce, phy_glo)
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
 #ifdef NC_DOUBLE
       ierr = nf_put_var_double(nid, id_foce, phy_glo)
@@ -723,5 +768,5 @@
 
     CALL gather(phy_fsic, phy_glo)
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
 #ifdef NC_DOUBLE
       ierr = nf_put_var_double(nid, id_fsic, phy_glo)
@@ -736,5 +781,5 @@
 
     CALL gather(phy_flic, phy_glo)
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
 #ifdef NC_DOUBLE
       ierr = nf_put_var_double(nid, id_flic, phy_glo)
@@ -749,5 +794,5 @@
 
     ! close file:
-    IF (is_mpi_root .AND. is_omp_root) THEN
+    IF (is_master) THEN
       ierr = nf_close(nid)
     END IF
Index: /LMDZ6/trunk/libf/phylmd/phyetat0.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/phyetat0.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/phyetat0.F90	(revision 3435)
@@ -9,5 +9,5 @@
   USE pbl_surface_mod,  ONLY : pbl_surface_init
   USE surface_data,     ONLY : type_ocean, version_ocean
-  USE phys_state_var_mod, ONLY : ancien_ok, clwcon, detr_therm, dtime, &
+  USE phys_state_var_mod, ONLY : ancien_ok, clwcon, detr_therm, phys_tstep, &
        qsol, fevap, z0m, z0h, agesno, &
        du_gwd_rando, du_gwd_front, entr_therm, f0, fm_therm, &
@@ -472,5 +472,5 @@
 
   IF ( type_ocean == 'slab' ) THEN
-      CALL ocean_slab_init(dtime, pctsrf)
+      CALL ocean_slab_init(phys_tstep, pctsrf)
       IF (nslay.EQ.1) THEN
         found=phyetat0_get(1,tslab,"tslab01","tslab",0.)
@@ -521,8 +521,8 @@
   ! Initialize module ocean_cpl_mod for the case of coupled ocean
   IF ( type_ocean == 'couple' ) THEN
-     CALL ocean_cpl_init(dtime, longitude_deg, latitude_deg)
-  ENDIF
-
-  CALL init_iophy_new(latitude_deg, longitude_deg)
+     CALL ocean_cpl_init(phys_tstep, longitude_deg, latitude_deg)
+  ENDIF
+
+!  CALL init_iophy_new(latitude_deg, longitude_deg)
 
   ! Initilialize module fonte_neige_mod      
Index: /LMDZ6/trunk/libf/phylmd/phys_cal_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/phys_cal_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/phys_cal_mod.F90	(revision 3435)
@@ -1,3 +1,3 @@
-! $Id:$
+! $Id$
 MODULE phys_cal_mod
 ! This module contains information on the calendar at the current time step
@@ -37,5 +37,6 @@
   SUBROUTINE phys_cal_init(annee_ref,day_ref)
 
-    USE IOIPSL, ONLY:  ymds2ju
+    USE IOIPSL, ONLY:  ymds2ju, ioconf_calendar
+    USE mod_phys_lmdz_para, ONLY:  is_master,is_omp_master
     USE ioipsl_getin_p_mod, ONLY: getin_p
 
@@ -47,4 +48,17 @@
     calend = 'earth_360d' ! default
     CALL getin_p("calend",calend)
+
+    IF (is_omp_master) THEN
+      IF (calend == 'earth_360d') THEN
+        CALL ioconf_calendar('360d')
+      ELSE IF (calend == 'earth_365d') THEN
+        CALL ioconf_calendar('noleap')
+      ELSE IF (calend == 'earth_366d') THEN
+        CALL ioconf_calendar('gregorian')
+      ELSE
+        CALL abort_physic('phys_cal_init','Mauvais choix de calendrier',1)
+      ENDIF
+    ENDIF
+!$OMP BARRIER
      
     CALL ymds2ju(annee_ref, 1, day_ref, 0., jD_ref)
Index: /LMDZ6/trunk/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 3435)
@@ -343,5 +343,5 @@
 !$OMP THREADPRIVATE(zxfluxlat_x, zxfluxlat_w)
 !jyg<
-!!! Entr\E9es suppl\E9mentaires couche-limite
+!!! Entrees supplementaires couche-limite
 !!      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: t_x, t_w
 !!!$OMP THREADPRIVATE(t_x, t_w)
@@ -349,5 +349,10 @@
 !!!$OMP THREADPRIVATE(q_x, q_w)
 !>jyg
-! Variables suppl\E9mentaires dans physiq.F relative au splitting de la surface
+!!! Sorties ferret
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: dtvdf_x, dtvdf_w
+!$OMP THREADPRIVATE(dtvdf_x, dtvdf_w)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: dqvdf_x, dqvdf_w
+!$OMP THREADPRIVATE(dqvdf_x, dqvdf_w)
+! Variables supplementaires dans physiq.F relative au splitting de la surface
       REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:) :: pbl_tke_input
 !$OMP THREADPRIVATE(pbl_tke_input)
@@ -578,4 +583,8 @@
       ALLOCATE(plul_st(klon),plul_th(klon))
       ALLOCATE(d_t_vdf(klon,klev),d_q_vdf(klon,klev),d_t_diss(klon,klev))
+
+      ALLOCATE(d_t_vdf_w(klon,klev),d_q_vdf_w(klon,klev))
+      ALLOCATE(d_t_vdf_x(klon,klev),d_q_vdf_x(klon,klev))
+
       ALLOCATE(d_u_vdf(klon,klev),d_v_vdf(klon,klev))
       ALLOCATE(d_t_oli(klon,klev),d_t_oro(klon,klev))
@@ -589,4 +598,5 @@
 ! Special RRTM
       ALLOCATE(ZLWFT0_i(klon,klev+1),ZSWFT0_i(klon,klev+1),ZFLDN0(klon,klev+1))
+      ZFLDN0= 0.
       ALLOCATE(ZFLUP0(klon,klev+1),ZFSDN0(klon,klev+1),ZFSUP0(klon,klev+1))
 !
@@ -603,4 +613,6 @@
       ALLOCATE(dv_gwd_rando(klon,klev),dv_gwd_front(klon,klev))
       ALLOCATE(east_gwstress(klon,klev),west_gwstress(klon,klev))
+      east_gwstress(:,:)=0 !ym missing init
+      west_gwstress(:,:)=0 !ym missing init
       ALLOCATE(d_t_hin(klon,klev))
       ALLOCATE(d_q_ch4(klon,klev))
@@ -627,5 +639,7 @@
       ALLOCATE(od865aer(klon))
       ALLOCATE(dryod550aer(klon))
+      dryod550aer(:) = 0.
       ALLOCATE(abs550aer(klon))
+      abs550aer(:) = 0.
       ALLOCATE(ec550aer(klon,klev))
       ALLOCATE(od550lt1aer(klon))
@@ -672,5 +686,5 @@
       ALLOCATE(toplwad0_aerop(klon), sollwad0_aerop(klon))
 
-! FH Ajout de celles n??cessaires au phys_output_write_mod
+! FH Ajout de celles necessaires au phys_output_write_mod
 
       ALLOCATE(tal1(klon), pal1(klon), pab1(klon), pab2(klon))
@@ -721,6 +735,8 @@
 !!      ALLOCATE(q_x(klon,klev), q_w(klon,klev))
 !>jyg
-      ALLOCATE(d_t_vdf_x(klon,klev), d_t_vdf_w(klon,klev))
-      ALLOCATE(d_q_vdf_x(klon,klev), d_q_vdf_w(klon,klev))
+      ALLOCATE(dtvdf_x(klon,klev), dtvdf_w(klon,klev))
+      dtvdf_x = 0 ; dtvdf_w=0 ;   !ym missing init
+      ALLOCATE(dqvdf_x(klon,klev), dqvdf_w(klon,klev))
+      dqvdf_x = 0 ; dqvdf_w=0 ;   !ym missing init
       ALLOCATE(pbl_tke_input(klon,klev+1,nbsrf))
       ALLOCATE(t_therm(klon,klev), q_therm(klon,klev),u_therm(klon,klev), v_therm(klon,klev))
@@ -738,6 +754,9 @@
       ALLOCATE(sens(klon), flwp(klon), fiwp(klon))
       ALLOCATE(alp_bl_conv(klon), alp_bl_det(klon))
+      ale_bl_stat(:)=0 ; alp_bl_conv(:)=0 ;  alp_bl_det(:)=0
       ALLOCATE(alp_bl_fluct_m(klon), alp_bl_fluct_tke(klon))
+      alp_bl_fluct_m(:)=0 ; alp_bl_fluct_tke(:)= 0.
       ALLOCATE(alp_bl_stat(klon), n2(klon), s2(klon))
+      alp_bl_stat(:)=0
       ALLOCATE(proba_notrig(klon), random_notrig(klon))
       ALLOCATE(cv_gen(klon))
@@ -968,5 +987,5 @@
       DEALLOCATE(toplwad0_aerop, sollwad0_aerop)
 
-! FH Ajout de celles n??cessaires au phys_output_write_mod
+! FH Ajout de celles necessaires au phys_output_write_mod
       DEALLOCATE(tal1, pal1, pab1, pab2)
       DEALLOCATE(ptstar, pt0, slp)
Index: /LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 3435)
@@ -367,5 +367,5 @@
     ! ug Pour les sorties XIOS
     USE xios
-    USE wxios, ONLY: wxios_closedef, missing_val
+    USE wxios, ONLY: wxios_closedef, missing_val, wxios_set_context
 #endif
     USE phys_cal_mod, ONLY : mth_len
@@ -437,9 +437,13 @@
     CALL set_itau_iophy(itau_w)
 
-    IF (.NOT.vars_defined) THEN
-       iinitend = 2
-    ELSE
+ !   IF (.NOT.vars_defined) THEN
        iinitend = 1
-    ENDIF
+ !   ELSE
+ !      iinitend = 1
+ !   ENDIF
+
+#ifdef CPP_XIOS
+    CALL wxios_set_context
+#endif
 
     DO ilev=1,klev
@@ -712,6 +716,15 @@
        CALL histwrite_phy(o_fsnow, zfra_o)
        CALL histwrite_phy(o_evap, evap)
-       CALL histwrite_phy(o_tops, topsw*swradcorr)
-       CALL histwrite_phy(o_tops0, topsw0*swradcorr)
+
+       IF (vars_defined) THEN
+         zx_tmp_fi2d = topsw*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_tops, zx_tmp_fi2d)
+
+       IF (vars_defined) THEN
+         zx_tmp_fi2d = topsw0*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_tops0, zx_tmp_fi2d)
+
        CALL histwrite_phy(o_topl, toplw)
        CALL histwrite_phy(o_topl0, toplw0)
@@ -746,14 +759,41 @@
        ENDIF
        CALL histwrite_phy(o_nettop, zx_tmp_fi2d)
-       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)
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = SWup200*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_SWup200, zx_tmp_fi2d)
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = SWup200clr*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_SWup200clr, zx_tmp_fi2d)
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = SWdn200*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_SWdn200, zx_tmp_fi2d)
+       
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = SWdn200clr*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_SWdn200clr, zx_tmp_fi2d)
+       
        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*swradcorr)
-       CALL histwrite_phy(o_sols0, solsw0*swradcorr)
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = solsw*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_sols, zx_tmp_fi2d)
+       
+       
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = solsw0*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_sols0, zx_tmp_fi2d)
        CALL histwrite_phy(o_soll, sollw)
        CALL histwrite_phy(o_soll0, sollw0)
@@ -950,8 +990,17 @@
        CALL histwrite_phy(o_cldt, cldt)
        CALL histwrite_phy(o_JrNt, JrNt)
-       CALL histwrite_phy(o_cldljn, cldl*JrNt)
-       CALL histwrite_phy(o_cldmjn, cldm*JrNt)
-       CALL histwrite_phy(o_cldhjn, cldh*JrNt)
-       CALL histwrite_phy(o_cldtjn, cldt*JrNt)
+       
+       IF (vars_defined)  zx_tmp_fi2d=cldl*JrNt      
+       CALL histwrite_phy(o_cldljn, zx_tmp_fi2d)
+       
+       IF (vars_defined)  zx_tmp_fi2d=cldm*JrNt      
+       CALL histwrite_phy(o_cldmjn, zx_tmp_fi2d)
+       
+       IF (vars_defined)  zx_tmp_fi2d=cldh*JrNt
+       CALL histwrite_phy(o_cldhjn, zx_tmp_fi2d)
+       
+       IF (vars_defined)  zx_tmp_fi2d=cldt*JrNt
+       CALL histwrite_phy(o_cldtjn, zx_tmp_fi2d)
+       
        CALL histwrite_phy(o_cldq, cldq)
        IF (vars_defined)       zx_tmp_fi2d(1:klon) = flwp(1:klon)
@@ -1154,5 +1203,5 @@
              IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_wake(1:klon,1:klev)/pdtphys
              CALL histwrite_phy(o_dqwak, zx_tmp_fi3d)
-             CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+             IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
              CALL histwrite_phy(o_dqwak2d, zx_tmp_fi2d)
           ENDIF ! iflag_wake>=1
@@ -1318,13 +1367,18 @@
 
 ! ThL -- In the following, we assume read_climoz == 1
-       zx_tmp_fi2d = 0.0    ! Computation for strato, added ThL
-       DO k=1, klev
-          zx_tmp_fi2d(:) = zx_tmp_fi2d(:) + wo(:,k,1) * stratomask(:,k) * 1.e3
-       END DO
+       IF (vars_defined) THEN
+         zx_tmp_fi2d = 0.0    ! Computation for strato, added ThL
+         DO k=1, klev
+            zx_tmp_fi2d(:) = zx_tmp_fi2d(:) + wo(:,k,1) * stratomask(:,k) * 1.e3
+         END DO
+       ENDIF
        CALL histwrite_phy(o_col_O3_strato, zx_tmp_fi2d) ! Added ThL
-       zx_tmp_fi2d = 0.0    ! Computation for tropo, added ThL
-       DO k=1, klev
-          zx_tmp_fi2d(:) = zx_tmp_fi2d(:) + wo(:,k,1) * (1.0-stratomask(:,k)) * 1.e3
-       END DO
+
+       IF (vars_defined) THEN
+         zx_tmp_fi2d = 0.0    ! Computation for tropo, added ThL
+         DO k=1, klev
+            zx_tmp_fi2d(:) = zx_tmp_fi2d(:) + wo(:,k,1) * (1.0-stratomask(:,k)) * 1.e3
+         END DO
+       ENDIF
        CALL histwrite_phy(o_col_O3_tropo, zx_tmp_fi2d)   ! Added ThL
 ! end add ThL
@@ -1367,8 +1421,16 @@
 #endif
        IF (ok_ade) THEN
-          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)
+          IF (vars_defined) zx_tmp_fi2d(:)=topswad_aero*swradcorr
+          CALL histwrite_phy(o_topswad, zx_tmp_fi2d)
+          
+          IF (vars_defined) zx_tmp_fi2d(:)=topswad0_aero*swradcorr
+          CALL histwrite_phy(o_topswad0, zx_tmp_fi2d)
+                    
+          IF (vars_defined) zx_tmp_fi2d(:)=solswad_aero*swradcorr
+          CALL histwrite_phy(o_solswad, zx_tmp_fi2d)
+                    
+          IF (vars_defined) zx_tmp_fi2d(:)=solswad0_aero*swradcorr
+          CALL histwrite_phy(o_solswad0, zx_tmp_fi2d)
+          
           CALL histwrite_phy(o_toplwad, toplwad_aero)
           CALL histwrite_phy(o_toplwad0, toplwad0_aero)
@@ -1377,34 +1439,37 @@
           !====MS forcing diagnostics
           IF (new_aod) THEN
-             zx_tmp_fi2d(:)=topsw_aero(:,1)*swradcorr(:)
+          !ym warning : topsw_aero, solsw_aero, topsw0_aero, solsw0_aero are not defined by model
+          !ym => init to 0 in radlwsw_m.F90 ztopsw_aero, zsolsw_aero, ztopsw0_aero, zsolsw0_aero
+
+             IF (vars_defined) zx_tmp_fi2d(:)=topsw_aero(:,1)*swradcorr(:)
              CALL histwrite_phy(o_swtoaas_nat,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=solsw_aero(:,1)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=solsw_aero(:,1)*swradcorr(:)
              CALL histwrite_phy(o_swsrfas_nat,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=topsw0_aero(:,1)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=topsw0_aero(:,1)*swradcorr(:)
              CALL histwrite_phy(o_swtoacs_nat,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=solsw0_aero(:,1)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=solsw0_aero(:,1)*swradcorr(:)
              CALL histwrite_phy(o_swsrfcs_nat,zx_tmp_fi2d)
              !ant
-             zx_tmp_fi2d(:)=topsw_aero(:,2)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=topsw_aero(:,2)*swradcorr(:)
              CALL histwrite_phy(o_swtoaas_ant,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=solsw_aero(:,2)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=solsw_aero(:,2)*swradcorr(:)
              CALL histwrite_phy(o_swsrfas_ant,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=topsw0_aero(:,2)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=topsw0_aero(:,2)*swradcorr(:)
              CALL histwrite_phy(o_swtoacs_ant,zx_tmp_fi2d)
-             zx_tmp_fi2d(:)=solsw0_aero(:,2)*swradcorr(:)
+             IF (vars_defined) zx_tmp_fi2d(:)=solsw0_aero(:,2)*swradcorr(:)
              CALL histwrite_phy(o_swsrfcs_ant,zx_tmp_fi2d)
              !cf
              IF (.not. aerosol_couple) THEN
-                zx_tmp_fi2d(:)=topswcf_aero(:,1)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=topswcf_aero(:,1)*swradcorr(:)
                 CALL histwrite_phy(o_swtoacf_nat,zx_tmp_fi2d)
-                zx_tmp_fi2d(:)=solswcf_aero(:,1)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=solswcf_aero(:,1)*swradcorr(:)
                 CALL histwrite_phy(o_swsrfcf_nat,zx_tmp_fi2d)
-                zx_tmp_fi2d(:)=topswcf_aero(:,2)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=topswcf_aero(:,2)*swradcorr(:)
                 CALL histwrite_phy(o_swtoacf_ant,zx_tmp_fi2d)
-                zx_tmp_fi2d(:)=solswcf_aero(:,2)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=solswcf_aero(:,2)*swradcorr(:)
                 CALL histwrite_phy(o_swsrfcf_ant,zx_tmp_fi2d)
-                zx_tmp_fi2d(:)=topswcf_aero(:,3)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=topswcf_aero(:,3)*swradcorr(:)
                 CALL histwrite_phy(o_swtoacf_zero,zx_tmp_fi2d)
-                zx_tmp_fi2d(:)=solswcf_aero(:,3)*swradcorr(:)
+                IF (vars_defined) zx_tmp_fi2d(:)=solswcf_aero(:,3)*swradcorr(:)
                 CALL histwrite_phy(o_swsrfcf_zero,zx_tmp_fi2d)
              ENDIF
@@ -1413,8 +1478,15 @@
        ENDIF
        IF (ok_aie) THEN
-          CALL histwrite_phy(o_topswai, topswai_aero*swradcorr)
-          CALL histwrite_phy(o_toplwai, toplwai_aero*swradcorr)
-          CALL histwrite_phy(o_solswai, solswai_aero*swradcorr)
-          CALL histwrite_phy(o_sollwai, sollwai_aero*swradcorr)
+          IF (vars_defined) zx_tmp_fi2d(:)= topswai_aero*swradcorr
+          CALL histwrite_phy(o_topswai, zx_tmp_fi2d)
+          
+          IF (vars_defined) zx_tmp_fi2d(:)=toplwai_aero*swradcorr
+          CALL histwrite_phy(o_toplwai, zx_tmp_fi2d)
+          
+          IF (vars_defined) zx_tmp_fi2d(:)=solswai_aero*swradcorr
+          CALL histwrite_phy(o_solswai, zx_tmp_fi2d)
+          
+          IF (vars_defined) zx_tmp_fi2d(:)=sollwai_aero*swradcorr
+          CALL histwrite_phy(o_sollwai, zx_tmp_fi2d)
        ENDIF
        IF (flag_aerosol.GT.0.AND.ok_cdnc) THEN
@@ -1446,5 +1518,8 @@
        CALL histwrite_phy(o_ovap, q_seri)
        CALL histwrite_phy(o_oliq, ql_seri)
-       CALL histwrite_phy(o_ocond, ql_seri+qs_seri)
+
+       IF (vars_defined) zx_tmp_fi3d = ql_seri+qs_seri
+       CALL histwrite_phy(o_ocond, zx_tmp_fi3d)
+
        CALL histwrite_phy(o_geop, zphi)
        CALL histwrite_phy(o_vitu, u_seri)
@@ -1453,5 +1528,7 @@
        CALL histwrite_phy(o_pres, pplay)
        CALL histwrite_phy(o_paprs, paprs(:,1:klev))
-       CALL histwrite_phy(o_zfull,zphi/RG)
+       
+       IF (vars_defined) zx_tmp_fi3d = zphi/RG
+       CALL histwrite_phy(o_zfull,zx_tmp_fi3d)
 
 #ifdef CPP_XIOS
@@ -1498,10 +1575,11 @@
        CALL histwrite_phy(o_rnebjn, zx_tmp_fi3d)
        CALL histwrite_phy(o_rhum, zx_rh)
-       CALL histwrite_phy(o_ozone, &
-            wo(:, :, 1) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
+       
+       IF (vars_defined) zx_tmp_fi3d = wo(:, :, 1) * dobson_u * 1e3 / zmasse / rmo3 * rmd
+       CALL histwrite_phy(o_ozone, zx_tmp_fi3d)
 
        IF (read_climoz == 2) THEN
-          CALL histwrite_phy(o_ozone_light, &
-               wo(:, :, 2) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
+         IF (vars_defined) zx_tmp_fi3d = wo(:, :, 2) * dobson_u * 1e3 / zmasse / rmo3 * rmd 
+         CALL histwrite_phy(o_ozone_light, zx_tmp_fi3d)
        ENDIF
 
@@ -1511,14 +1589,14 @@
 
        CALL histwrite_phy(o_dqphy,  d_qx(:,:,ivap))
-       CALL water_int(klon,klev,d_qx(:,:,ivap),zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,d_qx(:,:,ivap),zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqphy2d,  zx_tmp_fi2d)
 
        CALL histwrite_phy(o_dqlphy,  d_qx(:,:,iliq))
-       CALL water_int(klon,klev,d_qx(:,:,iliq),zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,d_qx(:,:,iliq),zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqlphy2d,  zx_tmp_fi2d)
 
        IF (nqo.EQ.3) THEN
        CALL histwrite_phy(o_dqsphy,  d_qx(:,:,isol))
-       CALL water_int(klon,klev,d_qx(:,:,isol),zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,d_qx(:,:,isol),zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqsphy2d,  zx_tmp_fi2d)
        ELSE 
@@ -1605,5 +1683,5 @@
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dqcon, zx_tmp_fi3d)
-       CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqcon2d, zx_tmp_fi2d)
 
@@ -1627,5 +1705,5 @@
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dqlsc, zx_tmp_fi3d)
-       CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqlsc2d, zx_tmp_fi2d)
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=beta_prec(1:klon,1:klev)
@@ -1640,9 +1718,9 @@
           IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscth(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dqlscth, zx_tmp_fi3d)
-          CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+          IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
           CALL histwrite_phy(o_dqlscth2d, zx_tmp_fi2d)
           IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_lscst(1:klon,1:klev)/pdtphys
           CALL histwrite_phy(o_dqlscst, zx_tmp_fi3d)
-          CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+          IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
           CALL histwrite_phy(o_dqlscst2d, zx_tmp_fi2d)
           CALL histwrite_phy(o_plulth, plul_th)
@@ -1698,5 +1776,5 @@
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dqvdf, zx_tmp_fi3d)
-       CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqvdf2d, zx_tmp_fi2d)
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
@@ -1704,5 +1782,5 @@
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dqeva, zx_tmp_fi3d)
-       CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqeva2d, zx_tmp_fi2d)
        CALL histwrite_phy(o_ratqs, ratqs)
@@ -1743,5 +1821,5 @@
           ENDIF
           CALL histwrite_phy(o_dqthe, zx_tmp_fi3d)
-          CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+          IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
           CALL histwrite_phy(o_dqthe2d, zx_tmp_fi2d)
        ENDIF !iflag_thermals
@@ -1750,5 +1828,5 @@
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_q_ajsb(1:klon,1:klev)/pdtphys
        CALL histwrite_phy(o_dqajs, zx_tmp_fi3d)
-       CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
+       IF (vars_defined) CALL water_int(klon,klev,zx_tmp_fi3d,zmasse,zx_tmp_fi2d)
        CALL histwrite_phy(o_dqajs2d, zx_tmp_fi2d)
        IF (vars_defined) zx_tmp_fi3d(1:klon,1:klev)=d_t_swr(1:klon,1:klev)/pdtphys
@@ -1786,6 +1864,10 @@
 
        IF (ok_hines) THEN
-          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=du_gwd_hines/pdtphys
+          CALL histwrite_phy(o_du_gwd_hines, zx_tmp_fi3d)
+
+          IF (vars_defined) zx_tmp_fi3d= dv_gwd_hines/pdtphys          
+          CALL histwrite_phy(o_dv_gwd_hines, zx_tmp_fi3d)
+          
           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)
@@ -1795,6 +1877,10 @@
 
        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)
+          IF (vars_defined)  zx_tmp_fi3d=du_gwd_front / pdtphys
+          CALL histwrite_phy(o_du_gwd_front, zx_tmp_fi3d)
+          
+          IF (vars_defined)  zx_tmp_fi3d=dv_gwd_front / pdtphys
+          CALL histwrite_phy(o_dv_gwd_front, zx_tmp_fi3d)
+          
           CALL histwrite_phy(o_ustr_gwd_front, zustr_gwd_front)
           CALL histwrite_phy(o_vstr_gwd_front, zvstr_gwd_front)
@@ -1802,6 +1888,9 @@
 
        IF (ok_gwd_rando) THEN
-          CALL histwrite_phy(o_du_gwd_rando, du_gwd_rando / pdtphys)
-          CALL histwrite_phy(o_dv_gwd_rando, dv_gwd_rando / pdtphys)
+          IF (vars_defined)  zx_tmp_fi3d=du_gwd_rando / pdtphys
+          CALL histwrite_phy(o_du_gwd_rando, zx_tmp_fi3d)
+          
+          IF (vars_defined)  zx_tmp_fi3d=dv_gwd_rando / pdtphys
+          CALL histwrite_phy(o_dv_gwd_rando, zx_tmp_fi3d)
           CALL histwrite_phy(o_ustr_gwd_rando, zustr_gwd_rando)
           CALL histwrite_phy(o_vstr_gwd_rando, zvstr_gwd_rando)
@@ -1811,30 +1900,53 @@
 
        IF (ok_qch4) THEN
-          CALL histwrite_phy(o_dqch4, d_q_ch4 / pdtphys)
-       ENDIF
-
-       DO k=1, klevp1
-         zx_tmp_fi3d1(:,k)=swup(:,k)*swradcorr(:)
-       ENDDO
+          IF (vars_defined) zx_tmp_fi3d=d_q_ch4 / pdtphys
+          CALL histwrite_phy(o_dqch4, zx_tmp_fi3d)
+       ENDIF
+       
+       IF (vars_defined) THEN
+         DO k=1, klevp1
+           zx_tmp_fi3d1(:,k)=swup(:,k)*swradcorr(:)
+         ENDDO
+       ENDIF
+       
        CALL histwrite_phy(o_rsu, zx_tmp_fi3d1)
-       DO k=1, klevp1
-         zx_tmp_fi3d1(:,k)=swdn(:,k)*swradcorr(:)
-       ENDDO
+
+
+       IF (vars_defined) THEN
+         DO k=1, klevp1
+           zx_tmp_fi3d1(:,k)=swdn(:,k)*swradcorr(:)
+         ENDDO
+       ENDIF
+       
        CALL histwrite_phy(o_rsd, zx_tmp_fi3d1)
-       DO k=1, klevp1
-         zx_tmp_fi3d1(:,k)=swup0(:,k)*swradcorr(:)
-       ENDDO
+
+       IF (vars_defined) THEN
+         DO k=1, klevp1
+           zx_tmp_fi3d1(:,k)=swup0(:,k)*swradcorr(:)
+         ENDDO
+       ENDIF
+       
        CALL histwrite_phy(o_rsucs, zx_tmp_fi3d1)
-       DO k=1, klevp1
-         zx_tmp_fi3d1(:,k)=swupc0(:,k)*swradcorr(:)
-       ENDDO
+
+       IF (vars_defined) THEN
+         DO k=1, klevp1
+           zx_tmp_fi3d1(:,k)=swupc0(:,k)*swradcorr(:)
+         ENDDO
+       ENDIF
        CALL histwrite_phy(o_rsucsaf, zx_tmp_fi3d1)
-       DO k=1, klevp1
-         zx_tmp_fi3d1(:,k)=swdn0(:,k)*swradcorr(:)
-       ENDDO
+
+       IF (vars_defined) THEN
+         DO k=1, klevp1
+           zx_tmp_fi3d1(:,k)=swdn0(:,k)*swradcorr(:)
+         ENDDO
+       ENDIF
        CALL histwrite_phy(o_rsdcs, zx_tmp_fi3d1)
-       DO k=1, klevp1
-         zx_tmp_fi3d1(:,k)=swdnc0(:,k)*swradcorr(:)
-       ENDDO
+
+
+       IF (vars_defined) THEN
+         DO k=1, klevp1
+           zx_tmp_fi3d1(:,k)=swdnc0(:,k)*swradcorr(:)
+         ENDDO
+       ENDIF
        CALL histwrite_phy(o_rsdcsaf, zx_tmp_fi3d1)
 
@@ -1890,5 +2002,6 @@
        ELSE IF (iflag_con == 2) THEN
           CALL histwrite_phy(o_mcd,  pmfd)
-          CALL histwrite_phy(o_dmc,  pmfu + pmfd)
+          IF (vars_defined) zx_tmp_fi3d = pmfu + pmfd
+          CALL histwrite_phy(o_dmc,  zx_tmp_fi3d)
        ENDIF
        CALL histwrite_phy(o_ref_liq, ref_liq)
@@ -1904,19 +2017,27 @@
           IF (vars_defined) zx_tmp_fi2d(:) = lwup0p(:,klevp1)
           CALL histwrite_phy(o_rlutcs4co2, zx_tmp_fi2d)
-          DO k=1, klevp1
-            zx_tmp_fi3d1(:,k)=swupp(:,k)*swradcorr(:)
-          ENDDO
+          IF (vars_defined) THEN
+            DO k=1, klevp1
+              zx_tmp_fi3d1(:,k)=swupp(:,k)*swradcorr(:)
+            ENDDO
+          ENDIF
           CALL histwrite_phy(o_rsu4co2, zx_tmp_fi3d1)
-          DO k=1, klevp1
-            zx_tmp_fi3d1(:,k)=swup0p(:,k)*swradcorr(:)
-          ENDDO
+          IF (vars_defined) THEN
+            DO k=1, klevp1
+              zx_tmp_fi3d1(:,k)=swup0p(:,k)*swradcorr(:)
+            ENDDO
+          ENDIF
           CALL histwrite_phy(o_rsucs4co2, zx_tmp_fi3d1)
-          DO k=1, klevp1
-            zx_tmp_fi3d1(:,k)=swdnp(:,k)*swradcorr(:)
-          ENDDO
+          IF (vars_defined) THEN
+            DO k=1, klevp1
+              zx_tmp_fi3d1(:,k)=swdnp(:,k)*swradcorr(:)
+            ENDDO
+          ENDIF
           CALL histwrite_phy(o_rsd4co2, zx_tmp_fi3d1)
-          DO k=1, klevp1
-            zx_tmp_fi3d1(:,k)=swdn0p(:,k)*swradcorr(:)
-          ENDDO
+          IF (vars_defined) THEN
+            DO k=1, klevp1
+              zx_tmp_fi3d1(:,k)=swdn0p(:,k)*swradcorr(:)
+            ENDDO
+          ENDIF
           CALL histwrite_phy(o_rsdcs4co2, zx_tmp_fi3d1)
           CALL histwrite_phy(o_rlu4co2, lwupp)
@@ -2071,20 +2192,20 @@
             IF (type_trac == 'lmdz' .OR. type_trac == 'repr' .OR. type_trac == 'coag') THEN
              !--3D fields
-             CALL histwrite_phy(o_trac(iq-nqo), tr_seri(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_vdf(iq-nqo),d_tr_cl(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_the(iq-nqo),d_tr_th(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_con(iq-nqo),d_tr_cv(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_lessi_impa(iq-nqo),d_tr_lessi_impa(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_lessi_nucl(iq-nqo),d_tr_lessi_nucl(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_insc(iq-nqo),d_tr_insc(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_bcscav(iq-nqo),d_tr_bcscav(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_evapls(iq-nqo),d_tr_evapls(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_ls(iq-nqo),d_tr_ls(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_trsp(iq-nqo),d_tr_trsp(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_sscav(iq-nqo),d_tr_sscav(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_sat(iq-nqo),d_tr_sat(:,:,iq-nqo))
-             CALL histwrite_phy(o_dtr_uscav(iq-nqo),d_tr_uscav(:,:,iq-nqo))
+!             CALL histwrite_phy(o_trac(iq-nqo), tr_seri(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_vdf(iq-nqo),d_tr_cl(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_the(iq-nqo),d_tr_th(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_con(iq-nqo),d_tr_cv(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_lessi_impa(iq-nqo),d_tr_lessi_impa(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_lessi_nucl(iq-nqo),d_tr_lessi_nucl(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_insc(iq-nqo),d_tr_insc(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_bcscav(iq-nqo),d_tr_bcscav(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_evapls(iq-nqo),d_tr_evapls(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_ls(iq-nqo),d_tr_ls(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_trsp(iq-nqo),d_tr_trsp(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_sscav(iq-nqo),d_tr_sscav(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_sat(iq-nqo),d_tr_sat(:,:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_uscav(iq-nqo),d_tr_uscav(:,:,iq-nqo))
              !--2D fields
-             CALL histwrite_phy(o_dtr_dry(iq-nqo), flux_tr_dry(:,iq-nqo))
+!             CALL histwrite_phy(o_dtr_dry(iq-nqo), flux_tr_dry(:,iq-nqo))
              zx_tmp_fi2d=0.
              IF (vars_defined) THEN
Index: /LMDZ6/trunk/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/phys_state_var_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/phys_state_var_mod.F90	(revision 3435)
@@ -18,5 +18,5 @@
       INTEGER, SAVE :: radpas  ! radiation is called every "radpas" step
       INTEGER, SAVE :: cvpas   ! convection is called every "cvpas" step
-      INTEGER, SAVE :: cvpas_0 ! reference value for cvpas
+      INTEGER, SAVE :: cvpas_0 = 1 ! reference value for cvpas
       INTEGER, SAVE :: wkpas   ! wake scheme is called every "wkpas" step
       REAL, PARAMETER :: missing_val_nf90=nf90_fill_real
@@ -25,6 +25,6 @@
 !$OMP THREADPRIVATE(cvpas_0)
 !$OMP THREADPRIVATE(wkpas)
-      REAL, SAVE :: dtime, solaire_etat0
-!$OMP THREADPRIVATE(dtime, solaire_etat0)
+      REAL, SAVE :: phys_tstep=0, solaire_etat0
+!$OMP THREADPRIVATE(phys_tstep, solaire_etat0)
 
       REAL, ALLOCATABLE, SAVE :: pctsrf(:,:)
@@ -286,4 +286,6 @@
       REAL,ALLOCATABLE,SAVE :: total_rain(:), nday_rain(:)  
 !$OMP THREADPRIVATE(total_rain,nday_rain)
+      REAL,ALLOCATABLE,SAVE :: paire_ter(:)
+!$OMP THREADPRIVATE(paire_ter)
 ! albsol1: albedo du sol total pour SW visible
 ! albsol2: albedo du sol total pour SW proche IR
@@ -417,4 +419,7 @@
       ! tendencies on wind due to gravity waves
 
+      LOGICAL,SAVE :: is_initialized=.FALSE.
+!$OMP THREADPRIVATE(is_initialized)    
+
 CONTAINS
 
@@ -437,4 +442,6 @@
 include "clesphys.h"
 
+      IF (is_initialized) RETURN
+      is_initialized=.TRUE.
       ALLOCATE(pctsrf(klon,nbsrf))
       ALLOCATE(ftsol(klon,nbsrf))
@@ -452,4 +459,5 @@
       ALLOCATE(snow_fall(klon))
       ALLOCATE(solsw(klon), sollw(klon))
+      sollw=0.0
       ALLOCATE(radsol(klon))
       ALLOCATE(swradcorr(klon))
@@ -541,4 +549,5 @@
       ALLOCATE(wake_deltat(klon,klev), wake_deltaq(klon,klev))
       ALLOCATE(wake_s(klon), awake_dens(klon), wake_dens(klon))
+      awake_dens = 0.
       ALLOCATE(wake_Cstar(klon))
       ALLOCATE(wake_pe(klon), wake_fip(klon))
@@ -549,4 +558,5 @@
       ALLOCATE(pfrac_1nucl(klon,klev))
       ALLOCATE(total_rain(klon), nday_rain(klon))
+      ALLOCATE(paire_ter(klon))
       ALLOCATE(albsol1(klon), albsol2(klon))
 !albedo SB >>>
@@ -566,6 +576,8 @@
       ALLOCATE(topsw(klon), toplw(klon))
       ALLOCATE(sollwdown(klon), sollwdownclr(klon))
+      sollwdown = 0.
       ALLOCATE(toplwdown(klon), toplwdownclr(klon))
       ALLOCATE(topsw0(klon),toplw0(klon),solsw0(klon),sollw0(klon))
+      sollw0 = 0.
       ALLOCATE(albpla(klon))
 !IM ajout variables CFMIP2/CMIP5
@@ -604,7 +616,12 @@
       ALLOCATE(ale_bl_trig(klon))
 !!! fin nrlmd le 10/04/2012
-      if (ok_gwd_rando) allocate(du_gwd_rando(klon, klev))
-      if (.not. ok_hines .and. ok_gwd_rando) allocate(du_gwd_front(klon, klev))
-
+      IF (ok_gwd_rando) THEN
+        allocate(du_gwd_rando(klon, klev))
+        du_gwd_rando(:,:)=0.
+      ENDIF
+      IF (.not. ok_hines .and. ok_gwd_rando) THEN
+        ALLOCATE(du_gwd_front(klon, klev))
+        du_gwd_front(:,:) = 0 !ym missing init   
+      ENDIF
 END SUBROUTINE phys_state_var_init
 
@@ -691,4 +708,5 @@
       deallocate(pfrac_1nucl)
       deallocate(total_rain, nday_rain)
+      deallocate(paire_ter)
       deallocate(albsol1, albsol2)
 !albedo SB >>>
@@ -738,5 +756,5 @@
       deallocate(ale_bl_trig)
 !!! fin nrlmd le 10/04/2012
-
+      is_initialized=.FALSE.
 END SUBROUTINE phys_state_var_end
 
Index: /LMDZ6/trunk/libf/phylmd/physiq_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 3435)
@@ -25,5 +25,5 @@
     USE dimphy
     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_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, nbp_lev, klon_glo, grid1dTo2d_glo, grid_type, unstructured
     USE mod_phys_lmdz_para
     USE iophy
@@ -265,4 +265,12 @@
     USE ACAMA_GWD_rando_m, only: ACAMA_GWD_rando
     USE VERTICAL_LAYERS_MOD, ONLY: aps,bps
+    USE etat0_limit_unstruct_mod
+#ifdef CPP_XIOS
+    USE xios, ONLY: xios_update_calendar, xios_context_finalize
+#endif
+    USE limit_read_mod, ONLY : init_limit_read
+    USE regr_horiz_time_climoz_m, ONLY: regr_horiz_time_climoz
+    USE readaerosol_mod, ONLY : init_aero_fromfile
+    USE readaerosolstrato_m, ONLY : init_readaerosolstrato
 
     IMPLICIT NONE
@@ -1165,4 +1173,5 @@
     !albedo SB >>>
     real,dimension(6),save :: SFRWL
+!$OMP THREADPRIVATE(SFRWL)
     !albedo SB <<<
 
@@ -1183,4 +1192,8 @@
     pdtphys=pdtphys_
     CALL update_time(pdtphys)
+    phys_tstep=NINT(pdtphys)
+#ifdef CPP_XIOS
+    IF (.NOT. debut .AND. is_omp_master) CALL xios_update_calendar(itap+1)
+#endif
 
     !======================================================================
@@ -1215,4 +1228,6 @@
 
     IF (first) THEN 
+       CALL init_etat0_limit_unstruct
+       IF (.NOT. create_etat0_limit) CALL init_limit_read(days_elapsed)
        !CR:nvelles variables convection/poches froides
 
@@ -1221,5 +1236,4 @@
        CALL phys_local_var_init
        !
-       pasphys=pdtphys
        !     appel a la lecture du run.def physique
        CALL conf_phys(ok_journe, ok_mensuel, &
@@ -1239,4 +1253,6 @@
        CALL phys_state_var_init(read_climoz)
        CALL phys_output_var_init
+       IF(read_climoz>=1 .AND. create_etat0_limit .AND. grid_type==unstructured) CALL regr_horiz_time_climoz(read_climoz,ok_daily_climoz)
+
        print*, '================================================='
        !
@@ -1369,4 +1385,8 @@
        ENDIF
 
+       tau_aero(:,:,:,:) = 1.e-15
+       piz_aero(:,:,:,:) = 1.
+       cg_aero(:,:,:,:)  = 0.
+
        IF (aerosol_couple .AND. (config_inca /= "aero" &
             .AND. config_inca /= "aeNP ")) THEN
@@ -1417,14 +1437,12 @@
        ! pour obtenir le meme resultat.
 !jyg for fh<
-!!       dtime=pdtphys
-       dtime=NINT(pdtphys)
-       WRITE(lunout,*) 'Pas de temps dtime pdtphys ',dtime,pdtphys
-       IF (abs(dtime-pdtphys)>1.e-10) THEN
+       WRITE(lunout,*) 'Pas de temps phys_tstep pdtphys ',phys_tstep,pdtphys
+       IF (abs(phys_tstep-pdtphys)>1.e-10) THEN
           abort_message='pas de temps doit etre entier en seconde pour orchidee et XIOS'
           CALL abort_physic(modname,abort_message,1)
        ENDIF
 !>jyg
-       IF (MOD(NINT(86400./dtime),nbapp_rad).EQ.0) THEN
-          radpas = NINT( 86400./dtime)/nbapp_rad
+       IF (MOD(NINT(86400./phys_tstep),nbapp_rad).EQ.0) THEN
+          radpas = NINT( 86400./phys_tstep)/nbapp_rad
        ELSE 
           WRITE(lunout,*) 'le nombre de pas de temps physique doit etre un ', &
@@ -1436,9 +1454,9 @@
           CALL abort_physic(modname,abort_message,1)
        ENDIF
-       IF (nbapp_cv .EQ. 0) nbapp_cv=86400./dtime
-       IF (nbapp_wk .EQ. 0) nbapp_wk=86400./dtime
+       IF (nbapp_cv .EQ. 0) nbapp_cv=86400./phys_tstep
+       IF (nbapp_wk .EQ. 0) nbapp_wk=86400./phys_tstep
        print *,'physiq, nbapp_cv, nbapp_wk ',nbapp_cv,nbapp_wk
-       IF (MOD(NINT(86400./dtime),nbapp_cv).EQ.0) THEN
-          cvpas_0 = NINT( 86400./dtime)/nbapp_cv
+       IF (MOD(NINT(86400./phys_tstep),nbapp_cv).EQ.0) THEN
+          cvpas_0 = NINT( 86400./phys_tstep)/nbapp_cv
           cvpas = cvpas_0
        print *,'physiq, cvpas ',cvpas
@@ -1452,6 +1470,6 @@
           call abort_physic(modname,abort_message,1)
        ENDIF
-       IF (MOD(NINT(86400./dtime),nbapp_wk).EQ.0) THEN
-          wkpas = NINT( 86400./dtime)/nbapp_wk
+       IF (MOD(NINT(86400./phys_tstep),nbapp_wk).EQ.0) THEN
+          wkpas = NINT( 86400./phys_tstep)/nbapp_wk
        print *,'physiq, wkpas ',wkpas
        ELSE 
@@ -1465,6 +1483,101 @@
        ENDIF
        ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
+       CALL init_iophy_new(latitude_deg,longitude_deg)
+
+          !===================================================================
+          !IM stations CFMIP
+          nCFMIP=npCFMIP
+          OPEN(98,file='npCFMIP_param.data',status='old', &
+               form='formatted',iostat=iostat)
+          IF (iostat == 0) THEN
+             READ(98,*,end=998) nCFMIP
+998          CONTINUE
+             CLOSE(98)
+             CONTINUE
+             IF(nCFMIP.GT.npCFMIP) THEN
+                print*,'nCFMIP > npCFMIP : augmenter npCFMIP et recompiler'
+                CALL abort_physic("physiq", "", 1)
+             ELSE
+                print*,'physiq npCFMIP=',npCFMIP,'nCFMIP=',nCFMIP
+             ENDIF
+
+             !
+             ALLOCATE(tabCFMIP(nCFMIP))
+             ALLOCATE(lonCFMIP(nCFMIP), latCFMIP(nCFMIP))
+             ALLOCATE(tabijGCM(nCFMIP))
+             ALLOCATE(lonGCM(nCFMIP), latGCM(nCFMIP))
+             ALLOCATE(iGCM(nCFMIP), jGCM(nCFMIP))
+             !
+             ! lecture des nCFMIP stations CFMIP, de leur numero 
+             ! et des coordonnees geographiques lonCFMIP, latCFMIP
+             !
+             CALL read_CFMIP_point_locations(nCFMIP, tabCFMIP,  &
+                  lonCFMIP, latCFMIP)
+             !
+             ! identification des
+             ! 1) coordonnees lonGCM, latGCM des points CFMIP dans la
+             ! grille de LMDZ
+             ! 2) indices points tabijGCM de la grille physique 1d sur
+             ! klon points
+             ! 3) indices iGCM, jGCM de la grille physique 2d
+             !
+             CALL LMDZ_CFMIP_point_locations(nCFMIP, lonCFMIP, latCFMIP, &
+                  tabijGCM, lonGCM, latGCM, iGCM, jGCM)
+             !
+          ELSE
+             ALLOCATE(tabijGCM(0))
+             ALLOCATE(lonGCM(0), latGCM(0))
+             ALLOCATE(iGCM(0), jGCM(0))
+          ENDIF
+
+#ifdef CPP_IOIPSL
+
+       !$OMP MASTER
+       ! FH : if ok_sync=.true. , the time axis is written at each time step
+       ! in the output files. Only at the end in the opposite case
+       ok_sync_omp=.false.
+       CALL getin('ok_sync',ok_sync_omp)
+       CALL phys_output_open(longitude_deg,latitude_deg,nCFMIP,tabijGCM, &
+            iGCM,jGCM,lonGCM,latGCM, &
+            jjmp1,nlevSTD,clevSTD,rlevSTD, phys_tstep,ok_veget, &
+            type_ocean,iflag_pbl,iflag_pbl_split,ok_mensuel,ok_journe, &
+            ok_hf,ok_instan,ok_LES,ok_ade,ok_aie, &
+            read_climoz, phys_out_filestations, &
+            new_aod, aerosol_couple, &
+            flag_aerosol_strat, pdtphys, paprs, pphis,  &
+            pplay, lmax_th, ptconv, ptconvth, ivap,  &
+            d_u, d_t, qx, d_qx, zmasse, ok_sync_omp)
+       !$OMP END MASTER
+       !$OMP BARRIER
+       ok_sync=ok_sync_omp
+
+       freq_outNMC(1) = ecrit_files(7)
+       freq_outNMC(2) = ecrit_files(8)
+       freq_outNMC(3) = ecrit_files(9)
+       WRITE(lunout,*)'OK freq_outNMC(1)=',freq_outNMC(1)
+       WRITE(lunout,*)'OK freq_outNMC(2)=',freq_outNMC(2)
+       WRITE(lunout,*)'OK freq_outNMC(3)=',freq_outNMC(3)
+
+#ifndef CPP_XIOS
+       CALL ini_paramLMDZ_phy(phys_tstep,nid_ctesGCM)
+#endif
+
+#endif
+       ecrit_reg = ecrit_reg * un_jour
+       ecrit_tra = ecrit_tra * un_jour
+
+       !XXXPB Positionner date0 pour initialisation de ORCHIDEE
+       date0 = jD_ref 
+       WRITE(*,*) 'physiq date0 : ',date0
+       !
+
+!       CALL create_climoz(read_climoz)
+       CALL init_aero_fromfile(flag_aerosol)  !! initialise aero from file for XIOS interpolation (unstructured_grid)
+       CALL init_readaerosolstrato(flag_aerosol_strat)  !! initialise aero strato from file for XIOS interpolation (unstructured_grid)
+
+       IF(read_climoz>=1 .AND. create_etat0_limit .AND. grid_type==unstructured) CALL regr_horiz_time_climoz(read_climoz,ok_daily_climoz)
+       CALL create_etat0_limit_unstruct
        CALL phyetat0 ("startphy.nc",clesphy0,tabcntr0)
+
 !jyg<
        IF (klon_glo==1) THEN
@@ -1480,6 +1593,37 @@
               pbl_tke(:,:,:) = 0.
           ENDIF  ! (iflag_pbl > 1)
+        ELSE
+          pbl_tke(:,:,is_ave) = 0. !ym missing init : maybe must be initialized in the same way that for klon_glo==1 ??
 !>jyg
        ENDIF
+#ifdef CPP_COSP
+
+      IF (ok_cosp) THEN
+         CALL phys_cosp(itap,phys_tstep,freq_cosp, &
+               ok_mensuelCOSP,ok_journeCOSP,ok_hfCOSP, &
+               ecrit_mth,ecrit_day,ecrit_hf, ok_all_xml, missing_val, &
+               klon,klev,longitude_deg,latitude_deg,presnivs,overlap, &
+               JrNt,ref_liq,ref_ice, &
+               pctsrf(:,is_ter)+pctsrf(:,is_lic), &
+               zu10m,zv10m,pphis, &
+               zphi,paprs(:,1:klev),pplay,zxtsol,t_seri, &
+               qx(:,:,ivap),zx_rh,cldfra,rnebcon,flwc,fiwc, &
+               prfl(:,1:klev),psfl(:,1:klev), &
+               pmflxr(:,1:klev),pmflxs(:,1:klev), &
+               mr_ozone,cldtau, cldemi)
+      ENDIF
+#endif
+
+       CALL phys_output_write(itap, pdtphys, paprs, pphis,                    &
+                              pplay, lmax_th, aerosol_couple,                 &
+                              ok_ade, ok_aie, ivap, iliq, isol, new_aod, ok_sync,&
+                              ptconv, read_climoz, clevSTD,                   &
+                              ptconvth, d_u, d_t, qx, d_qx, zmasse,           &
+                              flag_aerosol, flag_aerosol_strat, ok_cdnc)
+
+#ifdef CPP_XIOS
+       IF (is_omp_master) CALL xios_update_calendar(1)
+#endif
+
        !IM begin
        print*,'physiq: clwcon rnebcon ratqs',clwcon(1,1),rnebcon(1,1) &
@@ -1496,14 +1640,11 @@
        ENDIF
 
-       CALL printflag( tabcntr0,radpas,ok_journe, &
-            ok_instan, ok_region )
-       !
-       IF (ABS(dtime-pdtphys).GT.0.001) THEN
-          WRITE(lunout,*) 'Pas physique n est pas correct',dtime, &
-               pdtphys
-          abort_message='Pas physique n est pas correct '
-          !           call abort_physic(modname,abort_message,1)
-          dtime=pdtphys
-       ENDIF
+!       IF (ABS(phys_tstep-pdtphys).GT.0.001) THEN
+!          WRITE(lunout,*) 'Pas physique n est pas correct',phys_tstep, &
+!               pdtphys
+!          abort_message='Pas physique n est pas correct '
+!          !           call abort_physic(modname,abort_message,1)
+!          phys_tstep=pdtphys
+!       ENDIF
        IF (nlon .NE. klon) THEN
           WRITE(lunout,*)'nlon et klon ne sont pas coherents', nlon,  &
@@ -1519,5 +1660,5 @@
        ENDIF
        !
-       IF (dtime*REAL(radpas).GT.21600..AND.iflag_cycle_diurne.GE.1) THEN 
+       IF (phys_tstep*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"
@@ -1581,53 +1722,8 @@
           !        enddo
 
-          !===================================================================
-          !IM stations CFMIP
-          nCFMIP=npCFMIP
-          OPEN(98,file='npCFMIP_param.data',status='old', &
-               form='formatted',iostat=iostat)
-          IF (iostat == 0) THEN
-             READ(98,*,end=998) nCFMIP
-998          CONTINUE
-             CLOSE(98)
-             CONTINUE
-             IF(nCFMIP.GT.npCFMIP) THEN
-                print*,'nCFMIP > npCFMIP : augmenter npCFMIP et recompiler'
-                CALL abort_physic("physiq", "", 1)
-             ELSE
-                print*,'physiq npCFMIP=',npCFMIP,'nCFMIP=',nCFMIP
-             ENDIF
-
-             !
-             ALLOCATE(tabCFMIP(nCFMIP))
-             ALLOCATE(lonCFMIP(nCFMIP), latCFMIP(nCFMIP))
-             ALLOCATE(tabijGCM(nCFMIP))
-             ALLOCATE(lonGCM(nCFMIP), latGCM(nCFMIP))
-             ALLOCATE(iGCM(nCFMIP), jGCM(nCFMIP))
-             !
-             ! lecture des nCFMIP stations CFMIP, de leur numero 
-             ! et des coordonnees geographiques lonCFMIP, latCFMIP
-             !
-             CALL read_CFMIP_point_locations(nCFMIP, tabCFMIP,  &
-                  lonCFMIP, latCFMIP)
-             !
-             ! identification des
-             ! 1) coordonnees lonGCM, latGCM des points CFMIP dans la
-             ! grille de LMDZ
-             ! 2) indices points tabijGCM de la grille physique 1d sur
-             ! klon points
-             ! 3) indices iGCM, jGCM de la grille physique 2d
-             !
-             CALL LMDZ_CFMIP_point_locations(nCFMIP, lonCFMIP, latCFMIP, &
-                  tabijGCM, lonGCM, latGCM, iGCM, jGCM)
-             !
-          ELSE
-             ALLOCATE(tabijGCM(0))
-             ALLOCATE(lonGCM(0), latGCM(0))
-             ALLOCATE(iGCM(0), jGCM(0))
-          ENDIF
-       ELSE
-          ALLOCATE(tabijGCM(0))
-          ALLOCATE(lonGCM(0), latGCM(0))
-          ALLOCATE(iGCM(0), jGCM(0))
+       !ELSE
+       !   ALLOCATE(tabijGCM(0))
+       !   ALLOCATE(lonGCM(0), latGCM(0))
+       !   ALLOCATE(iGCM(0), jGCM(0))
        ENDIF
 
@@ -1665,5 +1761,5 @@
        !
        !
-       lmt_pas = NINT(86400./dtime * 1.0)   ! tous les jours
+       lmt_pas = NINT(86400./phys_tstep * 1.0)   ! tous les jours
        WRITE(lunout,*)'La frequence de lecture surface est de ',  &
             lmt_pas
@@ -1681,4 +1777,13 @@
        !   Initialisation des sorties
        !=============================================================
+
+#ifdef CPP_XIOS
+       ! Get "missing_val" value from XML files (from temperature variable)
+       !$OMP MASTER
+       CALL xios_get_field_attr("temp",default_value=missing_val_omp)
+       !$OMP END MASTER
+       !$OMP BARRIER
+       missing_val=missing_val_omp
+#endif
 
 #ifdef CPP_XIOS 
@@ -1693,43 +1798,7 @@
 #endif 
 
-#ifdef CPP_IOIPSL
-
-       !$OMP MASTER
-       ! FH : if ok_sync=.true. , the time axis is written at each time step
-       ! in the output files. Only at the end in the opposite case
-       ok_sync_omp=.false.
-       CALL getin('ok_sync',ok_sync_omp)
-       CALL phys_output_open(longitude_deg,latitude_deg,nCFMIP,tabijGCM, &
-            iGCM,jGCM,lonGCM,latGCM, &
-            jjmp1,nlevSTD,clevSTD,rlevSTD, dtime,ok_veget, &
-            type_ocean,iflag_pbl,iflag_pbl_split,ok_mensuel,ok_journe, &
-            ok_hf,ok_instan,ok_LES,ok_ade,ok_aie, &
-            read_climoz, phys_out_filestations, &
-            new_aod, aerosol_couple, &
-            flag_aerosol_strat, pdtphys, paprs, pphis,  &
-            pplay, lmax_th, ptconv, ptconvth, ivap,  &
-            d_u, d_t, qx, d_qx, zmasse, ok_sync_omp)
-       !$OMP END MASTER
-       !$OMP BARRIER
-       ok_sync=ok_sync_omp
-
-       freq_outNMC(1) = ecrit_files(7)
-       freq_outNMC(2) = ecrit_files(8)
-       freq_outNMC(3) = ecrit_files(9)
-       WRITE(lunout,*)'OK freq_outNMC(1)=',freq_outNMC(1)
-       WRITE(lunout,*)'OK freq_outNMC(2)=',freq_outNMC(2)
-       WRITE(lunout,*)'OK freq_outNMC(3)=',freq_outNMC(3)
-
-#ifndef CPP_XIOS
-       CALL ini_paramLMDZ_phy(dtime,nid_ctesGCM)
-#endif
-
-#endif
-       ecrit_reg = ecrit_reg * un_jour
-       ecrit_tra = ecrit_tra * un_jour
-
-       !XXXPB Positionner date0 pour initialisation de ORCHIDEE
-       date0 = jD_ref 
-       WRITE(*,*) 'physiq date0 : ',date0
+
+       CALL printflag( tabcntr0,radpas,ok_journe, &
+            ok_instan, ok_region )
        !
        !
@@ -1891,5 +1960,5 @@
     ! on the surface fraction.
     !
-    CALL change_srf_frac(itap, dtime, days_elapsed+1,  &
+    CALL change_srf_frac(itap, phys_tstep, days_elapsed+1,  &
          pctsrf, fevap, z0m, z0h, agesno,              &
          falb_dir, falb_dif, ftsol, ustar, u10m, v10m, pbl_tke)
@@ -2021,20 +2090,20 @@
     IF (ancien_ok) THEN
     !
-       d_u_dyn(:,:)  = (u_seri(:,:)-u_ancien(:,:))/dtime
-       d_v_dyn(:,:)  = (v_seri(:,:)-v_ancien(:,:))/dtime
-       d_t_dyn(:,:)  = (t_seri(:,:)-t_ancien(:,:))/dtime
-       d_q_dyn(:,:)  = (q_seri(:,:)-q_ancien(:,:))/dtime
-       d_ql_dyn(:,:) = (ql_seri(:,:)-ql_ancien(:,:))/dtime
-       d_qs_dyn(:,:) = (qs_seri(:,:)-qs_ancien(:,:))/dtime
+       d_u_dyn(:,:)  = (u_seri(:,:)-u_ancien(:,:))/phys_tstep
+       d_v_dyn(:,:)  = (v_seri(:,:)-v_ancien(:,:))/phys_tstep
+       d_t_dyn(:,:)  = (t_seri(:,:)-t_ancien(:,:))/phys_tstep
+       d_q_dyn(:,:)  = (q_seri(:,:)-q_ancien(:,:))/phys_tstep
+       d_ql_dyn(:,:) = (ql_seri(:,:)-ql_ancien(:,:))/phys_tstep
+       d_qs_dyn(:,:) = (qs_seri(:,:)-qs_ancien(:,:))/phys_tstep
        CALL water_int(klon,klev,q_seri,zmasse,zx_tmp_fi2d)
-       d_q_dyn2d(:)=(zx_tmp_fi2d(:)-prw_ancien(:))/dtime
+       d_q_dyn2d(:)=(zx_tmp_fi2d(:)-prw_ancien(:))/phys_tstep
        CALL water_int(klon,klev,ql_seri,zmasse,zx_tmp_fi2d)
-       d_ql_dyn2d(:)=(zx_tmp_fi2d(:)-prlw_ancien(:))/dtime
+       d_ql_dyn2d(:)=(zx_tmp_fi2d(:)-prlw_ancien(:))/phys_tstep
        CALL water_int(klon,klev,qs_seri,zmasse,zx_tmp_fi2d)
-       d_qs_dyn2d(:)=(zx_tmp_fi2d(:)-prsw_ancien(:))/dtime
+       d_qs_dyn2d(:)=(zx_tmp_fi2d(:)-prsw_ancien(:))/phys_tstep
        ! !! RomP >>>   td dyn traceur
        IF (nqtot.GT.nqo) THEN     ! jyg
           DO iq = nqo+1, nqtot      ! jyg
-              d_tr_dyn(:,:,iq-nqo)=(tr_seri(:,:,iq-nqo)-tr_ancien(:,:,iq-nqo))/dtime ! jyg
+              d_tr_dyn(:,:,iq-nqo)=(tr_seri(:,:,iq-nqo)-tr_ancien(:,:,iq-nqo))/phys_tstep ! jyg
           ENDDO
        ENDIF
@@ -2213,5 +2282,5 @@
           !  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)
+          zdtime=phys_tstep*REAL(radpas) ! pas de temps du rayonnement (s)
           CALL zenang(zlongi,jH_cur,0.0,zdtime, &
                latitude_deg,longitude_deg,rmu0,fract)
@@ -2230,6 +2299,6 @@
           !  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) 
+          zdtime1=phys_tstep*REAL(-MOD(itaprad,radpas)-1)      
+          zdtime2=phys_tstep*REAL(radpas-MOD(itaprad,radpas)-1) 
           CALL zenang(zlongi,jH_cur,zdtime1,zdtime2, &
                latitude_deg,longitude_deg,rmu0,fract)
@@ -2237,5 +2306,5 @@
           ! Calcul des poids
           !
-          zdtime1=-dtime !--on corrige le rayonnement pour representer le
+          zdtime1=-phys_tstep !--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, &
@@ -2295,4 +2364,7 @@
        !
        !-------gustiness calculation-------!
+       !ym : Warning gustiness non inialized for iflag_gusts=2 & iflag_gusts=3
+       gustiness=0  !ym missing init
+       
        IF (iflag_gusts==0) THEN
           gustiness(1:klon)=0
@@ -2315,5 +2387,5 @@
 
        CALL pbl_surface(  &
-            dtime,     date0,     itap,    days_elapsed+1, &
+            phys_tstep,     date0,     itap,    days_elapsed+1, &
             debut,     lafin, &
             longitude_deg, latitude_deg, rugoro,  zrmu0,      &
@@ -2482,7 +2554,7 @@
        DO i = 1, klon
           conv_q(i,k) = d_q_dyn(i,k)  &
-               + d_q_vdf(i,k)/dtime
+               + d_q_vdf(i,k)/phys_tstep
           conv_t(i,k) = d_t_dyn(i,k)  &
-               + d_t_vdf(i,k)/dtime
+               + d_t_vdf(i,k)/phys_tstep
        ENDDO
     ENDDO
@@ -2549,9 +2621,9 @@
        abort_message ='reactiver le call conlmd dans physiq.F'
        CALL abort_physic (modname,abort_message,1)
-       !     CALL conlmd (dtime, paprs, pplay, t_seri, q_seri, conv_q,
+       !     CALL conlmd (phys_tstep, paprs, pplay, t_seri, q_seri, conv_q,
        !    .             d_t_con, d_q_con,
        !    .             rain_con, snow_con, ibas_con, itop_con)
     ELSE IF (iflag_con.EQ.2) THEN
-       CALL conflx(dtime, paprs, pplay, t_seri, q_seri, &
+       CALL conflx(phys_tstep, paprs, pplay, t_seri, q_seri, &
             conv_t, conv_q, -evap, omega, &
             d_t_con, d_q_con, rain_con, snow_con, &
@@ -2629,5 +2701,5 @@
 
 !jyg<
-       CALL alpale( debut, itap, dtime, paprs, omega, t_seri,   &
+       CALL alpale( debut, itap, phys_tstep, paprs, omega, t_seri,   &
                     alp_offset, it_wape_prescr,  wape_prescr, fip_prescr, &
                     ale_bl_prescr, alp_bl_prescr, &
@@ -2671,5 +2743,5 @@
           !c          CALL concvl (iflag_con,iflag_clos,
           CALL concvl (iflag_clos, &
-               dtime, paprs, pplay, k_upper_cv, t_x,q_x, &
+               phys_tstep, paprs, pplay, k_upper_cv, t_x,q_x, &
                t_w,q_w,wake_s, &
                u_seri,v_seri,tr_seri,nbtr_tmp, &
@@ -2741,6 +2813,6 @@
               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
+                    ftd(i,k) = ftd(i,k) + wake_s(i)*d_t_adjwk(i,k)/phys_tstep
+                    fqd(i,k) = fqd(i,k) + wake_s(i)*d_q_adjwk(i,k)/phys_tstep
                     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)
@@ -2754,5 +2826,5 @@
 
           ! MAF conema3 ne contient pas les traceurs
-          CALL conema3 (dtime, &
+          CALL conema3 (phys_tstep, &
                paprs,pplay,t_seri,q_seri, &
                u_seri,v_seri,tr_seri,ntra, &
@@ -2886,5 +2958,5 @@
                snow_con(i))*cell_area(i)/REAL(klon)
        ENDDO
-       zx_t = zx_t/za*dtime
+       zx_t = zx_t/za*phys_tstep
        WRITE(lunout,*)"Precip=", zx_t
     ENDIF
@@ -2900,5 +2972,5 @@
        ENDDO
        DO i = 1, klon
-          z_factor(i) = (z_avant(i)-(rain_con(i)+snow_con(i))*dtime) &
+          z_factor(i) = (z_avant(i)-(rain_con(i)+snow_con(i))*phys_tstep) &
                /z_apres(i)
        ENDDO
@@ -2937,6 +3009,6 @@
                 M_dwn(i,k)   = dnwd0(i,k)
                 M_up(i,k)    = upwd(i,k)
-                dt_a(i,k)    = d_t_con(i,k)/dtime - ftd(i,k) 
-                dq_a(i,k)    = d_q_con(i,k)/dtime - fqd(i,k)
+                dt_a(i,k)    = d_t_con(i,k)/phys_tstep - ftd(i,k) 
+                dq_a(i,k)    = d_q_con(i,k)/phys_tstep - fqd(i,k)
              ENDDO
           ENDDO
@@ -2946,7 +3018,7 @@
              DO k = 1,klev
                 dt_dwn(:,k)= dt_dwn(:,k)+ &
-                     ok_wk_lsp(:)*(d_t_eva(:,k)+d_t_lsc(:,k))/dtime
+                     ok_wk_lsp(:)*(d_t_eva(:,k)+d_t_lsc(:,k))/phys_tstep
                 dq_dwn(:,k)= dq_dwn(:,k)+ &
-                     ok_wk_lsp(:)*(d_q_eva(:,k)+d_q_lsc(:,k))/dtime
+                     ok_wk_lsp(:)*(d_q_eva(:,k)+d_q_lsc(:,k))/phys_tstep
              ENDDO
           ELSEIF (iflag_wake==3) THEN
@@ -2959,7 +3031,7 @@
                       ! l'eau se reevapore).
                       dt_dwn(i,k)= dt_dwn(i,k)+ &
-                           ok_wk_lsp(i)*d_t_lsc(i,k)/dtime
+                           ok_wk_lsp(i)*d_t_lsc(i,k)/phys_tstep
                       dq_dwn(i,k)= dq_dwn(i,k)+ &
-                           ok_wk_lsp(i)*d_q_lsc(i,k)/dtime
+                           ok_wk_lsp(i)*d_q_lsc(i,k)/phys_tstep
                    ENDIF
                 ENDDO
@@ -2969,5 +3041,5 @@
           !
           !calcul caracteristiques de la poche froide
-          CALL calWAKE (iflag_wake_tend, paprs, pplay, dtime, &
+          CALL calWAKE (iflag_wake_tend, paprs, pplay, phys_tstep, &
                t_seri, q_seri, omega,  &
                dt_dwn, dq_dwn, M_dwn, M_up,  &
@@ -3016,5 +3088,5 @@
        IF (iflag_alp_wk_cond .GT. 0.) THEN
 
-         CALL alpale_wk(dtime, cell_area, wake_k, wake_s, wake_dens, wake_fip_0, &
+         CALL alpale_wk(phys_tstep, cell_area, wake_k, wake_s, wake_dens, wake_fip_0, &
                         wake_fip)
        ELSE
@@ -3156,5 +3228,5 @@
           !
 !
-          CALL alpale_th( dtime, lmax_th, t_seri, cell_area,  &
+          CALL alpale_th( phys_tstep, lmax_th, t_seri, cell_area,  &
                           cin, s2, n2,  &
                           ale_bl_trig, ale_bl_stat, ale_bl,  &
@@ -3246,5 +3318,5 @@
     ENDIF
     !
-    CALL fisrtilp(dtime,paprs,pplay, &
+    CALL fisrtilp(phys_tstep,paprs,pplay, &
          t_seri, q_seri,ptconv,ratqs, &
          d_t_lsc, d_q_lsc, d_ql_lsc, d_qi_lsc, rneb, cldliq, &
@@ -3306,5 +3378,5 @@
                + snow_lsc(i))*cell_area(i)/REAL(klon)
        ENDDO
-       zx_t = zx_t/za*dtime
+       zx_t = zx_t/za*phys_tstep
        WRITE(lunout,*)"Precip=", zx_t
     ENDIF
@@ -3526,5 +3598,5 @@
        calday = REAL(days_elapsed + 1) + jH_cur
 
-       CALL chemtime(itap+itau_phy-1, date0, dtime, itap)
+       CALL chemtime(itap+itau_phy-1, date0, phys_tstep, itap)
        IF (config_inca == 'aero' .OR. config_inca == 'aeNP') THEN
           CALL AEROSOL_METEO_CALC( &
@@ -4072,8 +4144,8 @@
 
     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
+       d_t_swr(:,k)=swradcorr(:)*heat(:,k)*phys_tstep/RDAY
+       d_t_sw0(:,k)=swradcorr(:)*heat0(:,k)*phys_tstep/RDAY
+       d_t_lwr(:,k)=-cool(:,k)*phys_tstep/RDAY
+       d_t_lw0(:,k)=-cool0(:,k)*phys_tstep/RDAY
     ENDDO
 
@@ -4131,5 +4203,5 @@
        IF (ok_strato) THEN
 
-          CALL drag_noro_strato(0,klon,klev,dtime,paprs,pplay, &
+          CALL drag_noro_strato(0,klon,klev,phys_tstep,paprs,pplay, &
                zmea,zstd, zsig, zgam, zthe,zpic,zval, &
                igwd,idx,itest, &
@@ -4139,5 +4211,5 @@
 
        ELSE
-          CALL drag_noro(klon,klev,dtime,paprs,pplay, &
+          CALL drag_noro(klon,klev,phys_tstep,paprs,pplay, &
                zmea,zstd, zsig, zgam, zthe,zpic,zval, &
                igwd,idx,itest, &
@@ -4180,5 +4252,5 @@
        IF (ok_strato) THEN
 
-          CALL lift_noro_strato(klon,klev,dtime,paprs,pplay, &
+          CALL lift_noro_strato(klon,klev,phys_tstep,paprs,pplay, &
                latitude_deg,zmea,zstd,zpic,zgam,zthe,zpic,zval, &
                igwd,idx,itest, &
@@ -4188,5 +4260,5 @@
 
        ELSE
-          CALL lift_noro(klon,klev,dtime,paprs,pplay, &
+          CALL lift_noro(klon,klev,phys_tstep,paprs,pplay, &
                latitude_deg,zmea,zstd,zpic, &
                itest, &
@@ -4208,5 +4280,5 @@
        du_gwd_hines=0.
        dv_gwd_hines=0.
-       CALL hines_gwd(klon, klev, dtime, paprs, pplay, latitude_deg, t_seri, &
+       CALL hines_gwd(klon, klev, phys_tstep, paprs, pplay, latitude_deg, t_seri, &
             u_seri, v_seri, zustr_gwd_hines, zvstr_gwd_hines, d_t_hin, &
             du_gwd_hines, dv_gwd_hines)
@@ -4214,7 +4286,7 @@
        zvstr_gwd_hines=0.
        DO k = 1, klev
-          zustr_gwd_hines(:)=zustr_gwd_hines(:)+ du_gwd_hines(:, k)/dtime &
+          zustr_gwd_hines(:)=zustr_gwd_hines(:)+ du_gwd_hines(:, k)/phys_tstep &
                * (paprs(:, k)-paprs(:, k+1))/rg
-          zvstr_gwd_hines(:)=zvstr_gwd_hines(:)+ dv_gwd_hines(:, k)/dtime &
+          zvstr_gwd_hines(:)=zvstr_gwd_hines(:)+ dv_gwd_hines(:, k)/phys_tstep &
                * (paprs(:, k)-paprs(:, k+1))/rg
        ENDDO
@@ -4227,5 +4299,6 @@
 
     IF (.not. ok_hines .and. ok_gwd_rando) then
-       CALL acama_GWD_rando(DTIME, pplay, latitude_deg, t_seri, u_seri, &
+       ! ym missing init for east_gwstress & west_gwstress -> added in phys_local_var_mod
+       CALL acama_GWD_rando(PHYS_TSTEP, pplay, latitude_deg, t_seri, u_seri, &
             v_seri, rot, zustr_gwd_front, zvstr_gwd_front, du_gwd_front, &
             dv_gwd_front, east_gwstress, west_gwstress)
@@ -4233,7 +4306,7 @@
        zvstr_gwd_front=0.
        DO k = 1, klev
-          zustr_gwd_front(:)=zustr_gwd_front(:)+ du_gwd_front(:, k)/dtime &
+          zustr_gwd_front(:)=zustr_gwd_front(:)+ du_gwd_front(:, k)/phys_tstep &
                * (paprs(:, k)-paprs(:, k+1))/rg
-          zvstr_gwd_front(:)=zvstr_gwd_front(:)+ dv_gwd_front(:, k)/dtime &
+          zvstr_gwd_front(:)=zvstr_gwd_front(:)+ dv_gwd_front(:, k)/phys_tstep &
                * (paprs(:, k)-paprs(:, k+1))/rg
        ENDDO
@@ -4245,5 +4318,5 @@
 
     IF (ok_gwd_rando) THEN
-       CALL FLOTT_GWD_rando(DTIME, pplay, t_seri, u_seri, v_seri, &
+       CALL FLOTT_GWD_rando(PHYS_TSTEP, pplay, t_seri, u_seri, v_seri, &
             rain_fall + snow_fall, zustr_gwd_rando, zvstr_gwd_rando, &
             du_gwd_rando, dv_gwd_rando, east_gwstress, west_gwstress)
@@ -4254,7 +4327,7 @@
        zvstr_gwd_rando=0.
        DO k = 1, klev
-          zustr_gwd_rando(:)=zustr_gwd_rando(:)+ du_gwd_rando(:, k)/dtime &
+          zustr_gwd_rando(:)=zustr_gwd_rando(:)+ du_gwd_rando(:, k)/phys_tstep &
                * (paprs(:, k)-paprs(:, k+1))/rg
-          zvstr_gwd_rando(:)=zvstr_gwd_rando(:)+ dv_gwd_rando(:, k)/dtime &
+          zvstr_gwd_rando(:)=zvstr_gwd_rando(:)+ dv_gwd_rando(:, k)/phys_tstep &
                * (paprs(:, k)-paprs(:, k+1))/rg
        ENDDO
@@ -4276,7 +4349,7 @@
     DO k = 1, klev
        DO i = 1, klon
-          zustrph(i)=zustrph(i)+(u_seri(i,k)-u(i,k))/dtime* &
+          zustrph(i)=zustrph(i)+(u_seri(i,k)-u(i,k))/phys_tstep* &
                (paprs(i,k)-paprs(i,k+1))/rg
-          zvstrph(i)=zvstrph(i)+(v_seri(i,k)-v(i,k))/dtime* &
+          zvstrph(i)=zvstrph(i)+(v_seri(i,k)-v(i,k))/phys_tstep* &
                (paprs(i,k)-paprs(i,k+1))/rg
        ENDDO
@@ -4299,8 +4372,8 @@
        CALL METHOX(1,klon,klon,klev,q_seri,d_q_ch4,pplay)
        ! ajout de la tendance d'humidite due au methane
-       d_q_ch4_dtime(:,:) = d_q_ch4(:,:)*dtime
+       d_q_ch4_dtime(:,:) = d_q_ch4(:,:)*phys_tstep
        CALL add_phys_tend(du0, dv0, dt0, d_q_ch4_dtime, dql0, dqi0, paprs, &
             'q_ch4', abortphy,flag_inhib_tend,itap,0)
-       d_q_ch4(:,:) = d_q_ch4_dtime(:,:)/dtime
+       d_q_ch4(:,:) = d_q_ch4_dtime(:,:)/phys_tstep
     ENDIF
     !
@@ -4390,5 +4463,5 @@
 
 
-       CALL drag_noro_strato(addtkeoro,klon,klev,dtime,paprs,pplay, &
+       CALL drag_noro_strato(addtkeoro,klon,klev,phys_tstep,paprs,pplay, &
                zmea,zstd, zsig, zgam, zthe,zpic,zval, &
                igwd,idx,itest, &
@@ -4431,5 +4504,5 @@
        ! adeclarer 
 #ifdef CPP_COSP
-       IF (itap.eq.1.or.MOD(itap,NINT(freq_cosp/dtime)).EQ.0) THEN
+       IF (itap.eq.1.or.MOD(itap,NINT(freq_cosp/phys_tstep)).EQ.0) THEN
 
           IF (prt_level .GE.10) THEN
@@ -4439,5 +4512,5 @@
           !       print*,'Dans physiq.F avant appel cosp ref_liq,ref_ice=',
           !     s        ref_liq,ref_ice
-          CALL phys_cosp(itap,dtime,freq_cosp, &
+          CALL phys_cosp(itap,phys_tstep,freq_cosp, &
                ok_mensuelCOSP,ok_journeCOSP,ok_hfCOSP, &
                ecrit_mth,ecrit_day,ecrit_hf, ok_all_xml, missing_val, &
@@ -4462,5 +4535,5 @@
 
 #ifdef CPP_COSP2
-       IF (itap.eq.1.or.MOD(itap,NINT(freq_cosp/dtime)).EQ.0) THEN
+       IF (itap.eq.1.or.MOD(itap,NINT(freq_cosp/phys_tstep)).EQ.0) THEN
 
           IF (prt_level .GE.10) THEN
@@ -4470,5 +4543,5 @@
                  print*,'Dans physiq.F avant appel '
           !     s        ref_liq,ref_ice
-          CALL phys_cosp2(itap,dtime,freq_cosp, &
+          CALL phys_cosp2(itap,phys_tstep,freq_cosp, &
                ok_mensuelCOSP,ok_journeCOSP,ok_hfCOSP, &
                ecrit_mth,ecrit_day,ecrit_hf, ok_all_xml, missing_val, &
@@ -4492,5 +4565,5 @@
   IF (ok_airs) then
 
-  IF (itap.eq.1.or.MOD(itap,NINT(freq_airs/dtime)).EQ.0) THEN
+  IF (itap.eq.1.or.MOD(itap,NINT(freq_airs/phys_tstep)).EQ.0) THEN
      write(*,*) 'je vais appeler simu_airs, ok_airs, freq_airs=', ok_airs, freq_airs
      CALL simu_airs(itap,rneb, t_seri, cldemi, fiwc, ref_ice, pphi, pplay, paprs,&
@@ -4547,5 +4620,5 @@
     CALL phytrac ( &
          itap,     days_elapsed+1,    jH_cur,   debut, &
-         lafin,    dtime,     u, v,     t, &
+         lafin,    phys_tstep,     u, v,     t, &
          paprs,    pplay,     pmfu,     pmfd, &
          pen_u,    pde_u,     pen_d,    pde_d, &
@@ -4582,5 +4655,5 @@
             cdragh,coefh(1:klon,1:klev,is_ave),u1,v1,ftsol,pctsrf, &
             frac_impa, frac_nucl, &
-            pphis,cell_area,dtime,itap, &
+            pphis,cell_area,phys_tstep,itap, &
             qx(:,:,ivap),da,phi,mp,upwd,dnwd)
 
@@ -4653,5 +4726,5 @@
 
        CALL chemhook_end ( &
-            dtime, &
+            phys_tstep, &
             pplay, &
             t_seri, &
@@ -4688,12 +4761,12 @@
     DO k = 1, klev
        DO i = 1, klon
-          d_u(i,k) = ( u_seri(i,k) - u(i,k) ) / dtime
-          d_v(i,k) = ( v_seri(i,k) - v(i,k) ) / dtime
-          d_t(i,k) = ( t_seri(i,k)-t(i,k) ) / dtime
-          d_qx(i,k,ivap) = ( q_seri(i,k) - qx(i,k,ivap) ) / dtime
-          d_qx(i,k,iliq) = ( ql_seri(i,k) - qx(i,k,iliq) ) / dtime
+          d_u(i,k) = ( u_seri(i,k) - u(i,k) ) / phys_tstep
+          d_v(i,k) = ( v_seri(i,k) - v(i,k) ) / phys_tstep
+          d_t(i,k) = ( t_seri(i,k)-t(i,k) ) / phys_tstep
+          d_qx(i,k,ivap) = ( q_seri(i,k) - qx(i,k,ivap) ) / phys_tstep
+          d_qx(i,k,iliq) = ( ql_seri(i,k) - qx(i,k,iliq) ) / phys_tstep
           !CR: on ajoute le contenu en glace
           IF (nqo.eq.3) THEN
-             d_qx(i,k,isol) = ( qs_seri(i,k) - qx(i,k,isol) ) / dtime
+             d_qx(i,k,isol) = ( qs_seri(i,k) - qx(i,k,isol) ) / phys_tstep
           ENDIF
        ENDDO
@@ -4707,6 +4780,6 @@
           DO  k = 1, klev
              DO  i = 1, klon
-                ! d_qx(i,k,iq) = ( tr_seri(i,k,iq-2) - qx(i,k,iq) ) / dtime
-                d_qx(i,k,iq) = ( tr_seri(i,k,iq-nqo) - qx(i,k,iq) ) / dtime
+                ! d_qx(i,k,iq) = ( tr_seri(i,k,iq-2) - qx(i,k,iq) ) / phys_tstep
+                d_qx(i,k,iq) = ( tr_seri(i,k,iq-nqo) - qx(i,k,iq) ) / phys_tstep
              ENDDO
           ENDDO
@@ -4962,13 +5035,17 @@
        !         write(97) u_seri,v_seri,t_seri,q_seri
        !         close(97)
-       !$OMP MASTER
-       IF (read_climoz >= 1) THEN
-          IF (is_mpi_root) THEN
-             CALL nf95_close(ncid_climoz)
-          ENDIF
-          DEALLOCATE(press_edg_climoz) ! pointer
-          DEALLOCATE(press_cen_climoz) ! pointer
-       ENDIF
-       !$OMP END MASTER
+      
+       IF (is_omp_master) THEN
+       
+         IF (read_climoz >= 1) THEN
+           IF (is_mpi_root) CALL nf95_close(ncid_climoz)
+            DEALLOCATE(press_edg_climoz) ! pointer
+            DEALLOCATE(press_cen_climoz) ! pointer
+         ENDIF
+       
+       ENDIF
+#ifdef CPP_XIOS
+       IF (is_omp_master) CALL xios_context_finalize
+#endif
        print *,' physiq fin, nombre de steps ou cvpas = 1 : ', Ncvpaseq1
     ENDIF
Index: /LMDZ6/trunk/libf/phylmd/radlwsw_m.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/radlwsw_m.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/radlwsw_m.F90	(revision 3435)
@@ -398,4 +398,9 @@
   cgaero(:,:,:,:)=0.
   lldebug=.FALSE.
+
+  ztopsw_aero(:,:)  = 0. !ym missing init : warning : not initialized in SW_AEROAR4
+  ztopsw0_aero(:,:) = 0. !ym missing init : warning : not initialized in SW_AEROAR4
+  zsolsw_aero(:,:)  = 0. !ym missing init : warning : not initialized in SW_AEROAR4
+  zsolsw0_aero(:,:) = 0. !ym missing init : warning : not initialized in SW_AEROAR4
   
   !
Index: /LMDZ6/trunk/libf/phylmd/readaerosol.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/readaerosol.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/readaerosol.F90	(revision 3435)
@@ -4,4 +4,11 @@
 
   REAL, SAVE :: not_valid=-333.
+  
+  INTEGER, SAVE :: nbp_lon_src
+!$OMP THREADPRIVATE(nbp_lon_src)  
+  INTEGER, SAVE :: nbp_lat_src
+!$OMP THREADPRIVATE(nbp_lat_src)  
+  REAL, ALLOCATABLE, SAVE    :: psurf_interp(:,:)
+!$OMP THREADPRIVATE(psurf_interp)  
 
 CONTAINS
@@ -167,4 +174,74 @@
 
 
+  SUBROUTINE init_aero_fromfile(flag_aerosol)
+  USE netcdf
+  USE mod_phys_lmdz_para
+  USE mod_grid_phy_lmdz, ONLY: grid_type, unstructured
+  USE xios
+  IMPLICIT NONE
+  INTEGER, INTENT(IN) :: flag_aerosol
+  REAL,ALLOCATABLE :: lat_src(:)
+  REAL,ALLOCATABLE :: lon_src(:)
+  CHARACTER(LEN=*),PARAMETER :: file_aerosol='aerosols.nat.nc'
+  CHARACTER(LEN=*),PARAMETER :: file_so4='so4.nat.nc'
+  INTEGER :: klev_src
+  INTEGER :: ierr ,ncid, dimID, varid
+  REAL :: null_array(0)
+
+  IF (flag_aerosol>0 .AND. grid_type==unstructured) THEN
+  
+    IF (is_omp_root) THEN
+  
+      IF (is_mpi_root) THEN
+    
+        IF (nf90_open(TRIM(file_aerosol), NF90_NOWRITE, ncid) /= NF90_NOERR) THEN
+          CALL check_err( nf90_open(TRIM(file_so4), NF90_NOWRITE, ncid), "pb open "//trim(file_so4) )
+        ENDIF
+
+        ! Read and test longitudes
+        CALL check_err( nf90_inq_dimid(ncid, "lon", dimID),"pb inq dim lon") 
+        CALL check_err( nf90_inquire_dimension(ncid, dimID, len = nbp_lon_src),"pb inq dim lon")
+        CALL check_err( nf90_inq_varid(ncid, 'lon', varid),"pb inq lon" )
+        ALLOCATE(lon_src(nbp_lon_src))
+        CALL check_err( nf90_get_var(ncid, varid, lon_src(:)),"pb get lon" )
+
+        ! Read and test latitudes
+        CALL check_err( nf90_inq_dimid(ncid, "lat", dimID),"pb inq dim lat") 
+        CALL check_err( nf90_inquire_dimension(ncid, dimID, len = nbp_lat_src),"pb inq dim lat")
+        CALL check_err( nf90_inq_varid(ncid, 'lat', varid),"pb inq lat" )
+        ALLOCATE(lat_src(nbp_lat_src))
+        CALL check_err( nf90_get_var(ncid, varid, lat_src(:)),"pb get lat" )
+        IF (nf90_inq_dimid(ncid, 'lev', dimid) /= NF90_NOERR) THEN
+          IF (nf90_inq_dimid(ncid, 'presnivs', dimid)/= NF90_NOERR) THEN
+             CALL check_err(nf90_inq_dimid(ncid, 'PRESNIVS', dimid),'dimension lev,PRESNIVS or presnivs not in file')
+          ENDIF
+        ENDIF
+        CALL check_err( nf90_inquire_dimension(ncid, dimid, len = klev_src),"pb inq dim for PRESNIVS or lev" )
+        CALL check_err( nf90_close(ncid),"pb in close" )   
+      ENDIF
+
+      CALL bcast_mpi(nbp_lat_src)
+      CALL bcast_mpi(nbp_lon_src)
+      CALL bcast_mpi(klev_src)
+
+      IF (is_mpi_root ) THEN
+        CALL xios_set_domain_attr("domain_aerosol",nj_glo=nbp_lat_src, nj=nbp_lat_src, jbegin=0, latvalue_1d=lat_src)
+        CALL xios_set_domain_attr("domain_aerosol",ni_glo=nbp_lon_src, ni=nbp_lon_src, ibegin=0, lonvalue_1d=lon_src)
+      ELSE
+        CALL xios_set_domain_attr("domain_aerosol",nj_glo=nbp_lat_src, nj=0, jbegin=0, latvalue_1d=null_array )
+        CALL xios_set_domain_attr("domain_aerosol",ni_glo=nbp_lon_src, ni=0, ibegin=0, lonvalue_1d=null_array)
+      ENDIF
+      CALL xios_set_axis_attr("axis_aerosol",n_glo=klev_src)
+      CALL xios_set_fieldgroup_attr("aerosols", enabled=.TRUE.)
+  
+    ENDIF
+    
+  ENDIF    
+ 
+  END SUBROUTINE init_aero_fromfile
+
+
+    
+
   SUBROUTINE get_aero_fromfile(varname, cyr, filename, klev_src, pt_ap, pt_b, pt_year, psurf_out, load_out)
 !****************************************************************************************
@@ -187,9 +264,10 @@
     USE netcdf
     USE dimphy
-    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, &
-                                 grid2Dto1D_glo
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon_=>nbp_lon, nbp_lat_=>nbp_lat, klon_glo, &
+                                 grid2Dto1D_glo, grid_type, unstructured
     USE mod_phys_lmdz_para
     USE iophy, ONLY : io_lon, io_lat
     USE print_control_mod, ONLY: lunout
+    USE xios
 
     IMPLICIT NONE
@@ -205,6 +283,9 @@
     REAL, POINTER, DIMENSION(:)           :: pt_b         ! Pointer for describing the vertical levels      
     REAL, POINTER, DIMENSION(:,:,:)       :: pt_year      ! Pointer-variabale from file, 12 month, grid : klon,klev_src
+    REAL, POINTER, DIMENSION(:,:,:)       :: pt_year_mpi  ! Pointer-variabale from file, 12 month, grid : klon,klev_src
     REAL, DIMENSION(klon,12), INTENT(OUT) :: psurf_out    ! Surface pression for 12 months
+    REAL, DIMENSION(klon_mpi,12)          :: psurf_out_mpi    ! Surface pression for 12 months
     REAL, DIMENSION(klon,12), INTENT(OUT) :: load_out     ! Aerosol mass load in each column
+    REAL, DIMENSION(klon_mpi,12)          :: load_out_mpi     ! Aerosol mass load in each column
     INTEGER                               :: nbr_tsteps   ! number of month in file read
 
@@ -220,15 +301,39 @@
     REAL, ALLOCATABLE, DIMENSION(:)       :: varktmp
 
-    REAL, DIMENSION(nbp_lon,nbp_lat,12)   :: psurf_glo2D   ! Surface pression for 12 months on dynamics global grid
+    REAL,  ALLOCATABLE                    :: psurf_glo2D(:,:,:)   ! Surface pression for 12 months on dynamics global grid
     REAL, DIMENSION(klon_glo,12)          :: psurf_glo1D   ! -"- on physical global grid
-    REAL, DIMENSION(nbp_lon,nbp_lat,12)   :: load_glo2D    ! Load for 12 months on dynamics global grid
+    REAL,  ALLOCATABLE                    :: load_glo2D(:,:,:)    ! Load for 12 months on dynamics global grid
     REAL, DIMENSION(klon_glo,12)          :: load_glo1D    ! -"- on physical global grid
-    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
+    REAL, ALLOCATABLE, DIMENSION(:,:)     :: vartmp
+    REAL, ALLOCATABLE,DIMENSION(:)        :: lon_src              ! longitudes in file
+    REAL, ALLOCATABLE,DIMENSION(:)        :: 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
-
-
+    INTEGER                               :: nbp_lon, nbp_lat
+    LOGICAL,SAVE                          :: first=.TRUE.
+!$OMP THREADPRIVATE(first)
+    
+    IF (grid_type==unstructured) THEN
+      nbp_lon=nbp_lon_src
+      nbp_lat=nbp_lat_src
+    ELSE
+      nbp_lon=nbp_lon_
+      nbp_lat=nbp_lat_
+    ENDIF
+    
+    IF (is_mpi_root) THEN
+    
+      ALLOCATE(psurf_glo2D(nbp_lon,nbp_lat,12))
+      ALLOCATE(load_glo2D(nbp_lon,nbp_lat,12))
+      ALLOCATE(vartmp(nbp_lon,nbp_lat))
+      ALLOCATE(lon_src(nbp_lon))
+      ALLOCATE(lat_src(nbp_lat))
+      ALLOCATE(lat_src_inv(nbp_lat))
+    ELSE
+      ALLOCATE(varyear(0,0,0,0))
+      ALLOCATE(psurf_glo2D(0,0,0))
+      ALLOCATE(load_glo2D(0,0,0))
+    ENDIF
+            
     ! Deallocate pointers
     IF (ASSOCIATED(pt_ap)) DEALLOCATE(pt_ap)
@@ -245,41 +350,44 @@
        CALL check_err( nf90_open(TRIM(fname), NF90_NOWRITE, ncid), "pb open "//trim(fname) )
 
+
+       IF (grid_type/=unstructured) THEN
+
 ! Test for equal longitudes and latitudes in file and model
 !****************************************************************************************
        ! Read and test longitudes
-       CALL check_err( nf90_inq_varid(ncid, 'lon', varid),"pb inq lon" )
-       CALL check_err( nf90_get_var(ncid, varid, lon_src(:)),"pb get lon" )
+         CALL check_err( nf90_inq_varid(ncid, 'lon', varid),"pb inq lon" )
+         CALL check_err( nf90_get_var(ncid, varid, lon_src(:)),"pb get lon" )
        
-       IF (maxval(ABS(lon_src - io_lon)) > 0.001) THEN
-          WRITE(lunout,*) 'Problem in longitudes read from file : ',TRIM(fname)
-          WRITE(lunout,*) 'longitudes in file ', TRIM(fname),' : ', lon_src
-          WRITE(lunout,*) 'longitudes in model :', io_lon
+         IF (maxval(ABS(lon_src - io_lon)) > 0.001) THEN
+            WRITE(lunout,*) 'Problem in longitudes read from file : ',TRIM(fname)
+            WRITE(lunout,*) 'longitudes in file ', TRIM(fname),' : ', lon_src
+            WRITE(lunout,*) 'longitudes in model :', io_lon
           
-          CALL abort_physic('get_aero_fromfile', 'longitudes are not the same in file and model',1)
-       END IF
-
-       ! Read and test latitudes
-       CALL check_err( nf90_inq_varid(ncid, 'lat', varid),"pb inq lat" )
-       CALL check_err( nf90_get_var(ncid, varid, lat_src(:)),"pb get lat" )
-
-       ! Invert source latitudes
-       DO j = 1, nbp_lat
-          lat_src_inv(j) = lat_src(nbp_lat +1 -j)
-       END DO
-
-       IF (maxval(ABS(lat_src - io_lat)) < 0.001) THEN
-          ! Latitudes are the same
-          invert_lat=.FALSE.
-       ELSE IF (maxval(ABS(lat_src_inv - io_lat)) < 0.001) THEN
-          ! Inverted source latitudes correspond to model latitudes
-          WRITE(lunout,*) 'latitudes will be inverted for file : ',TRIM(fname)
-          invert_lat=.TRUE.
-       ELSE
-          WRITE(lunout,*) 'Problem in latitudes read from file : ',TRIM(fname)
-          WRITE(lunout,*) 'latitudes in file ', TRIM(fname),' : ', lat_src      
-          WRITE(lunout,*) 'latitudes in model :', io_lat
-          CALL abort_physic('get_aero_fromfile', 'latitudes do not correspond between file and model',1)
-       END IF
-
+            CALL abort_physic('get_aero_fromfile', 'longitudes are not the same in file and model',1)
+         END IF
+
+         ! Read and test latitudes
+         CALL check_err( nf90_inq_varid(ncid, 'lat', varid),"pb inq lat" )
+         CALL check_err( nf90_get_var(ncid, varid, lat_src(:)),"pb get lat" )
+
+         ! Invert source latitudes
+         DO j = 1, nbp_lat
+            lat_src_inv(j) = lat_src(nbp_lat +1 -j)
+         END DO
+
+         IF (maxval(ABS(lat_src - io_lat)) < 0.001) THEN
+            ! Latitudes are the same
+            invert_lat=.FALSE.
+         ELSE IF (maxval(ABS(lat_src_inv - io_lat)) < 0.001) THEN
+            ! Inverted source latitudes correspond to model latitudes
+            WRITE(lunout,*) 'latitudes will be inverted for file : ',TRIM(fname)
+            invert_lat=.TRUE.
+         ELSE
+            WRITE(lunout,*) 'Problem in latitudes read from file : ',TRIM(fname)
+            WRITE(lunout,*) 'latitudes in file ', TRIM(fname),' : ', lat_src      
+            WRITE(lunout,*) 'latitudes in model :', io_lat
+            CALL abort_physic('get_aero_fromfile', 'latitudes do not correspond between file and model',1)
+         END IF
+       ENDIF
 
 ! 2) Check if old or new file is avalabale.
@@ -487,60 +595,64 @@
        END IF
 
-!     - Invert latitudes if necessary
-       DO imth=1, 12
-          IF (invert_lat) THEN
-
-             ! Invert latitudes for the variable
-             varmth(:,:,:) = varyear(:,:,:,imth) ! use varmth temporarly
-             DO k=1,klev_src
-                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
-             END DO
+
+       IF (grid_type/=unstructured) THEN
+  !     - Invert latitudes if necessary
+         DO imth=1, 12
+            IF (invert_lat) THEN
+
+               ! Invert latitudes for the variable
+               varmth(:,:,:) = varyear(:,:,:,imth) ! use varmth temporarly
+               DO k=1,klev_src
+                  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
+               END DO
              
-             ! Invert latitudes for surface pressure
-             vartmp(:,:) = psurf_glo2D(:,:,imth)
-             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
+               ! Invert latitudes for surface pressure
+               vartmp(:,:) = psurf_glo2D(:,:,imth)
+               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
              
-             ! Invert latitudes for the load
-             vartmp(:,:) = load_glo2D(:,:,imth)
-             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
-          END IF ! invert_lat
+               ! Invert latitudes for the load
+               vartmp(:,:) = load_glo2D(:,:,imth)
+               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
+            END IF ! invert_lat
              
-          ! Do zonal mead at poles and distribut at whole first and last latitude
-          DO k=1, klev_src
-             npole=0.  ! North pole, j=1
-             spole=0.  ! South pole, j=nbp_lat        
-             DO i=1,nbp_lon
-                npole = npole + varyear(i,1,k,imth)
-                spole = spole + varyear(i,nbp_lat,k,imth)
-             END DO
-             npole = npole/REAL(nbp_lon)
-             spole = spole/REAL(nbp_lon)
-             varyear(:,1,    k,imth) = npole
-             varyear(:,nbp_lat,k,imth) = spole
-          END DO
-       END DO ! imth
+            ! Do zonal mead at poles and distribut at whole first and last latitude
+            DO k=1, klev_src
+               npole=0.  ! North pole, j=1
+               spole=0.  ! South pole, j=nbp_lat        
+               DO i=1,nbp_lon
+                  npole = npole + varyear(i,1,k,imth)
+                  spole = spole + varyear(i,nbp_lat,k,imth)
+               END DO
+               npole = npole/REAL(nbp_lon)
+               spole = spole/REAL(nbp_lon)
+               varyear(:,1,    k,imth) = npole
+               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_physic('get_aero_fromfile', 'pb in allocation 3',1)
+         ALLOCATE(varyear_glo1D(klon_glo, klev_src, 12), stat=ierr)
+         IF (ierr /= 0) CALL abort_physic('get_aero_fromfile', 'pb in allocation 3',1)
        
-       ! Transform from 2D to 1D field
-       CALL grid2Dto1D_glo(varyear,varyear_glo1D)
-       CALL grid2Dto1D_glo(psurf_glo2D,psurf_glo1D)
-       CALL grid2Dto1D_glo(load_glo2D,load_glo1D)
-
+         ! Transform from 2D to 1D field
+         CALL grid2Dto1D_glo(varyear,varyear_glo1D)
+         CALL grid2Dto1D_glo(psurf_glo2D,psurf_glo1D)
+         CALL grid2Dto1D_glo(load_glo2D,load_glo1D)
+      
+      ENDIF
+      
     ELSE
-      ALLOCATE(varyear_glo1D(0,0,0))        
+        ALLOCATE(varyear_glo1D(0,0,0))        
     END IF ! is_mpi_root .AND. is_omp_root
 
@@ -566,11 +678,29 @@
     IF (ASSOCIATED(pt_year)) DEALLOCATE(pt_year)
     ALLOCATE(pt_year(klon, klev_src, 12), stat=ierr)
+    ALLOCATE(pt_year_mpi(klon_mpi, klev_src, 12), stat=ierr)
     IF (ierr /= 0) CALL abort_physic('get_aero_fromfile', 'pb in allocation 5',1)
 
-    ! Scatter global field to local domain at local process
-    CALL scatter(varyear_glo1D, pt_year)
-    CALL scatter(psurf_glo1D, psurf_out)
-    CALL scatter(load_glo1D,  load_out)
-
+    IF (grid_type==unstructured) THEN
+      IF (is_omp_master) THEN
+        CALL xios_send_field(TRIM(varname)//"_in",varyear)
+        CALL xios_recv_field(TRIM(varname)//"_out",pt_year_mpi)
+        CALL xios_send_field("load_"//TRIM(varname)//"_in",load_glo2D)
+        CALL xios_recv_field("load_"//TRIM(varname)//"_out",load_out_mpi)
+        IF (first) THEN
+          ALLOCATE(psurf_interp(klon_mpi,12))
+          CALL xios_send_field("psurf_aerosol_in",psurf_glo2D)
+          CALL xios_recv_field("psurf_aerosol_out",psurf_interp)
+        ENDIF
+      ENDIF
+      CALL scatter_omp(pt_year_mpi,pt_year)
+      CALL scatter_omp(load_out_mpi,load_out)
+      CALL scatter_omp(psurf_interp,psurf_out)
+      first=.FALSE.
+    ELSE
+      ! Scatter global field to local domain at local process
+      CALL scatter(varyear_glo1D, pt_year)
+      CALL scatter(psurf_glo1D, psurf_out)
+      CALL scatter(load_glo1D,  load_out)
+    ENDIF
 ! 7) Test for negative values
 !****************************************************************************************
Index: /LMDZ6/trunk/libf/phylmd/readaerosolstrato.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/readaerosolstrato.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/readaerosolstrato.F90	(revision 3435)
@@ -7,5 +7,5 @@
     USE phys_cal_mod, ONLY : mth_cur
     USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, &
-                                 grid2dto1d_glo
+                                 grid2dto1d_glo, grid_type, unstructured
     USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
     USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
@@ -15,4 +15,5 @@
     USE aero_mod
     USE dimphy
+    USE xios
 
     implicit none
@@ -43,4 +44,5 @@
     real, allocatable:: tauaerstrat_mois(:, :, :)
     real, allocatable:: tauaerstrat_mois_glo(:, :)
+    real, allocatable:: tau_aer_strat_mpi(:, :)
 
 ! For NetCDF:
@@ -87,18 +89,22 @@
     n_lat = size(latitude)
     print *, 'LAT aerosol strato=', n_lat, latitude
-    IF (n_lat.NE.nbp_lat) THEN 
-       print *,'Le nombre de lat n est pas egal a nbp_lat'
-       STOP
-    ENDIF
-
+    IF (grid_type/=unstructured) THEN
+      IF (n_lat.NE.nbp_lat) THEN 
+         print *,'Le nombre de lat n est pas egal a nbp_lat'
+         STOP
+      ENDIF
+    ENDIF
+    
     CALL nf95_inq_varid(ncid_in, "LON", varid)
     CALL nf95_gw_var(ncid_in, varid, longitude)
     n_lon = size(longitude)
-    print *, 'LON aerosol strato=', n_lon, longitude
-    IF (n_lon.NE.nbp_lon) THEN 
-       print *,'Le nombre de lon n est pas egal a nbp_lon'
-       STOP
-    ENDIF
-
+    IF (grid_type/=unstructured) THEN
+      print *, 'LON aerosol strato=', n_lon, longitude
+      IF (n_lon.NE.nbp_lon) THEN 
+         print *,'Le nombre de lon n est pas egal a nbp_lon'
+         STOP
+      ENDIF
+    ENDIF
+    
     CALL nf95_inq_varid(ncid_in, "TIME", varid)
     CALL nf95_gw_var(ncid_in, varid, time)
@@ -130,10 +136,23 @@
     CALL grid2dTo1d_glo(tauaerstrat_mois,tauaerstrat_mois_glo)
 
+    ELSE
+      ALLOCATE(tauaerstrat_mois(0,0,0))
     ENDIF !--is_mpi_root and is_omp_root
 
 !$OMP BARRIER
 
+    IF (grid_type==unstructured) THEN
+      IF (is_omp_master) THEN
+        CALL xios_send_field("taustrat_in",tauaerstrat_mois)
+        ALLOCATE(tau_aer_strat_mpi(klon_mpi, klev))
+        CALL xios_recv_field("taustrat_out",tau_aer_strat_mpi)
+      ELSE
+        ALLOCATE(tau_aer_strat_mpi(0,0))
+      ENDIF
+      CALL scatter_omp(tau_aer_strat_mpi,tau_aer_strat)
+    ELSE  
 !--scatter on all proc
-    CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
+      CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
+    ENDIF
 
 !--keep memory of previous month
Index: /LMDZ6/trunk/libf/phylmd/readaerosolstrato_m.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/readaerosolstrato_m.F90	(revision 3435)
+++ /LMDZ6/trunk/libf/phylmd/readaerosolstrato_m.F90	(revision 3435)
@@ -0,0 +1,135 @@
+MODULE readaerosolstrato_m
+
+
+CONTAINS
+
+  SUBROUTINE init_readaerosolstrato(flag_aerosol_strat)
+  USE mod_grid_phy_lmdz, ONLY: grid_type, unstructured
+  IMPLICIT NONE
+  INTEGER,INTENT(IN) :: flag_aerosol_strat
+    
+    IF (grid_type==unstructured)  THEN 
+   
+      IF (flag_aerosol_strat == 1) THEN
+        CALL init_readaerosolstrato1
+      ELSE IF (flag_aerosol_strat == 2) THEN
+        CALL init_readaerosolstrato2
+      ENDIF
+  
+    ENDIF
+  
+  END SUBROUTINE init_readaerosolstrato
+  
+
+
+  SUBROUTINE init_readaerosolstrato1
+  USE netcdf
+  USE netcdf95, ONLY: nf95_close, nf95_gw_var, nf95_inq_dimid, & 
+                      nf95_inq_varid, nf95_open
+  USE mod_phys_lmdz_para
+  USE xios
+  USE YOERAD, ONLY : NLW
+  IMPLICIT NONE
+  REAL, POINTER:: latitude(:)
+  REAL, POINTER:: longitude(:)
+  INTEGER :: nlat, nlon
+  REAL    :: null_array(0)
+  INTEGER :: ncid_in, varid
+  
+    IF (is_omp_master) THEN  
+      IF (is_mpi_root) THEN
+        CALL nf95_open("taustrat.nc", nf90_nowrite, ncid_in)
+        CALL nf95_inq_varid(ncid_in, "LAT", varid)
+        CALL nf95_gw_var(ncid_in, varid, latitude)
+        CALL nf95_inq_varid(ncid_in, "LON", varid)
+        CALL nf95_gw_var(ncid_in, varid, longitude)
+        CALL nf95_close(ncid_in)
+        nlat=size(latitude)
+        nlon=size(longitude)
+      ENDIF
+      CALL bcast_mpi(nlat)
+      CALL bcast_mpi(nlon)
+
+      IF (is_mpi_root) THEN
+        CALL xios_set_domain_attr("domain_taustrat",nj_glo=nlat, nj=nlat, jbegin=0, latvalue_1d=latitude)
+        CALL xios_set_domain_attr("domain_taustrat",ni_glo=nlon, ni=nlon, ibegin=0, lonvalue_1d = longitude)
+       ELSE
+        CALL xios_set_domain_attr("domain_taustrat",nj_glo=nlat, nj=0, jbegin=0, latvalue_1d=null_array )
+        CALL xios_set_domain_attr("domain_taustrat",ni_glo=nlon, ni=0, ibegin=0, lonvalue_1d=null_array)
+      ENDIF    
+  
+      CALL xios_set_fieldgroup_attr("aerosol_strato1",enabled=.TRUE.)
+    ENDIF
+    
+  END SUBROUTINE init_readaerosolstrato1
+  
+  SUBROUTINE init_readaerosolstrato2
+  USE netcdf
+  USE netcdf95, ONLY: nf95_close, nf95_gw_var, nf95_inq_dimid, & 
+                      nf95_inq_varid, nf95_open
+  USE mod_phys_lmdz_para
+  USE xios
+  USE YOERAD, ONLY : NLW
+  IMPLICIT NONE
+  REAL, POINTER:: latitude(:)
+  REAL, POINTER:: wav(:)
+  INTEGER :: nlat,n_wav
+  REAL    :: null_array(0)
+  INTEGER :: ncid_in, varid
+
+    IF (is_omp_master) THEN    
+      IF (is_mpi_root) THEN
+        CALL nf95_open("tauswstrat.2D.nc", nf90_nowrite, ncid_in)
+        CALL nf95_inq_varid(ncid_in, "LAT", varid)
+        CALL nf95_gw_var(ncid_in, varid, latitude)
+        CALL nf95_inq_varid(ncid_in, "WAV", varid)
+        CALL nf95_gw_var(ncid_in, varid, wav)
+        CALL nf95_close(ncid_in)
+        nlat=size(latitude)
+        n_wav = size(wav)
+      ENDIF
+      CALL bcast_mpi(nlat)
+      CALL bcast_mpi(n_wav)
+
+      IF (is_mpi_root) THEN
+        CALL xios_set_domain_attr("domain_tauswstrat",nj_glo=nlat, nj=nlat, jbegin=0, latvalue_1d=latitude)
+        CALL xios_set_domain_attr("domain_tauswstrat",ni_glo=8, ni=8, ibegin=0, lonvalue_1d = (/ 0.,45.,90.,135.,180.,225.,270., 315. /))
+        DEALLOCATE(latitude)
+      ELSE
+        CALL xios_set_domain_attr("domain_tauswstrat",nj_glo=nlat, nj=0, jbegin=0, latvalue_1d=null_array )
+        CALL xios_set_domain_attr("domain_tauswstrat",ni_glo=8, ni=0, ibegin=0, lonvalue_1d=null_array)
+      ENDIF    
+      CALL  xios_set_axis_attr("nsw", n_glo=n_wav)
+    
+      IF (is_mpi_root) THEN
+        CALL nf95_open("taulwstrat.2D.nc", nf90_nowrite, ncid_in)
+        CALL nf95_inq_varid(ncid_in, "LAT", varid)
+        CALL nf95_gw_var(ncid_in, varid, latitude)
+        CALL nf95_inq_varid(ncid_in, "WAV", varid)
+        CALL nf95_gw_var(ncid_in, varid, wav)
+        CALL nf95_close(ncid_in)
+        nlat=size(latitude)
+        n_wav = size(wav)
+      ENDIF
+      CALL bcast_mpi(nlat)
+      CALL bcast_mpi(n_wav)
+
+      IF (is_mpi_root) THEN
+        CALL xios_set_domain_attr("domain_taulwstrat",nj_glo=nlat, nj=nlat, jbegin=0, latvalue_1d=latitude)
+        CALL xios_set_domain_attr("domain_taulwstrat",ni_glo=8, ni=8, ibegin=0, lonvalue_1d = (/ 0.,45.,90.,135.,180.,225.,270., 315. /))
+        DEALLOCATE(latitude)
+      ELSE
+        CALL xios_set_domain_attr("domain_taulwstrat",nj_glo=nlat, nj=0, jbegin=0, latvalue_1d=null_array )
+        CALL xios_set_domain_attr("domain_taulwstrat",ni_glo=8, ni=0, ibegin=0, lonvalue_1d=null_array)
+      ENDIF    
+    
+      CALL  xios_set_axis_attr("nlw", n_glo=n_wav)
+      CALL xios_set_fieldgroup_attr("aerosol_strato2",enabled=.TRUE.)
+
+    ENDIF
+    
+  END SUBROUTINE init_readaerosolstrato2
+  
+
+END MODULE readaerosolstrato_m
+
Index: /LMDZ6/trunk/libf/phylmd/regr_horiz_time_climoz_m.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/regr_horiz_time_climoz_m.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/regr_horiz_time_climoz_m.F90	(revision 3435)
@@ -2,5 +2,5 @@
 
   USE interpolation,     ONLY: locate
-  USE mod_grid_phy_lmdz, ONLY: nlon_ou => nbp_lon, nlat_ou => nbp_lat
+  USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, grid_type, unstructured
   USE nrtype,            ONLY: pi
   USE netcdf,   ONLY: NF90_CLOBBER, NF90_FLOAT,     NF90_GET_VAR, NF90_OPEN,   &
@@ -11,4 +11,5 @@
           NF95_CLOSE, NF95_ENDDEF,  NF95_PUT_ATT,   NF95_PUT_VAR, NF95_COPY_ATT
   USE print_control_mod, ONLY: lunout
+  USE dimphy
   IMPLICIT NONE
   PRIVATE
@@ -16,4 +17,10 @@
   REAL, PARAMETER :: deg2rad=pi/180.
   CHARACTER(LEN=13), PARAMETER :: vars_in(2)=['tro3         ','tro3_daylight']
+
+  INTEGER :: nlat_ou, nlon_ou
+  REAL, ALLOCATABLE :: latitude_glo(:)
+!$OMP THREADPRIVATE(latitude_glo)
+  INTEGER, ALLOCATABLE :: ind_cell_glo_glo(:)
+!$OMP THREADPRIVATE(ind_cell_glo_glo)
 
 CONTAINS
@@ -52,5 +59,6 @@
   USE assert_m,           ONLY: assert
   USE cal_tools_m,        ONLY: year_len, mid_month
-  USE control_mod,        ONLY: anneeref
+!!  USE control_mod,        ONLY: anneeref
+  USE time_phylmdz_mod,   ONLY: annee_ref
   USE ioipsl,             ONLY: ioget_year_len, ioget_calendar
   USE regr_conserv_m,     ONLY: regr_conserv
@@ -58,4 +66,9 @@
   USE regular_lonlat_mod, ONLY: boundslon_reg, boundslat_reg, south, west, east
   USE slopes_m,           ONLY: slopes
+  USE xios
+  USE mod_phys_lmdz_para, ONLY: is_mpi_root, is_master, is_omp_master, gather, gather_mpi, bcast_mpi, klon_mpi
+  USE geometry_mod, ONLY : latitude_deg, ind_cell_glo
+  USE mod_grid_phy_lmdz, ONLY: klon_glo
+
 !-------------------------------------------------------------------------------
 ! Arguments:
@@ -83,5 +96,7 @@
   CHARACTER(LEN=20) :: cal_in              ! Calendar
   REAL, ALLOCATABLE :: o3_in3(:,:,:,:,:)   ! Ozone climatologies
+  REAL, ALLOCATABLE :: o3_in3bis(:,:,:,:,:)   ! Ozone climatologies
   REAL, ALLOCATABLE :: o3_in2  (:,:,:,:)   ! Ozone climatologies
+  REAL, ALLOCATABLE :: o3_in2bis(:,:,:,:,:)   ! Ozone climatologies
   ! last index: 1 for the day-night average, 2 for the daylight field.
   REAL :: NaN
@@ -91,6 +106,9 @@
   REAL, ALLOCATABLE :: o3_regr_lonlat(:,:,:,:,:) ! (nlon_ou,nlat_ou,:,0:13   ,:)
   REAL, ALLOCATABLE :: o3_out3       (:,:,:,:,:) ! (nlon_ou,nlat_ou,:,ntim_ou,:)
+  REAL, ALLOCATABLE :: o3_out3_glo   (:,:,:,:) !   (nbp_lat,:,ntim_ou,:)
   REAL, ALLOCATABLE :: o3_regr_lat     (:,:,:,:) !         (nlat_in,:,0:13   ,:)
   REAL, ALLOCATABLE :: o3_out2         (:,:,:,:) !         (nlat_ou,:,ntim_ou,:)
+  REAL, ALLOCATABLE :: o3_out2_glo     (:,:,:,:) !         (nbp_lat,:,ntim_ou,:)
+  REAL, ALLOCATABLE :: o3_out          (:,:,:,:) !         (nbp_lat,:,ntim_ou,:)
 ! Dimension number  | Interval                | Contains  | For variables:
 !   1 (longitude)   | [rlonu(i-1), rlonu(i)]  | rlonv(i)  | all
@@ -116,282 +134,425 @@
   INTEGER, ALLOCATABLE :: sta(:), cnt(:)
   CHARACTER(LEN=80) :: sub, dim_nam, msg
-!-------------------------------------------------------------------------------
-  sub="regr_horiz_time_climoz"
-  WRITE(lunout,*)"Call sequence information: "//TRIM(sub)
-  CALL assert(read_climoz == 1 .OR. read_climoz == 2, "regr_lat_time_climoz")
-
-  CALL  NF95_OPEN("climoz.nc"  , NF90_NOWRITE, fID_in)
-  lprev=NF90_OPEN("climoz_m.nc", NF90_NOWRITE, fID_in_m)==NF90_NOERR
-  lnext=NF90_OPEN("climoz_p.nc", NF90_NOWRITE, fID_in_p)==NF90_NOERR
-
-  !--- Get coordinates from the input file. Converts lon/lat in radians.
-  !    Few inversions because "regr_conserv" and gcm need ascending vectors.
-  CALL NF95_INQ_VARID(fID_in, vars_in(1), varid)
-  CALL NF95_INQUIRE_VARIABLE(fID_in, varid, dimids=dIDs, ndims=ndims)
-  l3D=ndims==4; l2D=ndims==3
-  IF(l3D) WRITE(lunout,*)"Input files contain full 3D ozone fields."
-  IF(l2D) WRITE(lunout,*)"Input files contain zonal 2D ozone fields."
-  DO i=1,ndims
-    CALL NF95_INQUIRE_DIMENSION(fID_in, dIDs(i), name=dim_nam, nclen=dln)
-    CALL NF95_INQ_VARID(fID_in, dim_nam, varid)
-    ii=i; IF(l2D) ii=i+1                              !--- ndims==3:NO LONGITUDE 
-    SELECT CASE(ii)
-      CASE(1)                                         !--- LONGITUDE
-        CALL NF95_GW_VAR(fID_in, varid, lon_in)
-        ldec_lon=lon_in(1)>lon_in(dln); IF(ldec_lon) lon_in=lon_in(dln:1:-1)
-        nlon_in=dln; lon_in=lon_in*deg2rad
-      CASE(2)                                         !--- LATITUDE
-        CALL NF95_GW_VAR(fID_in, varid, lat_in)
-        ldec_lat=lat_in(1)>lat_in(dln); IF(ldec_lat) lat_in=lat_in(dln:1:-1)
-        nlat_in=dln; lat_in=lat_in*deg2rad
-      CASE(3)                                         !--- PRESSURE LEVELS
-        CALL NF95_GW_VAR(fID_in, varid, lev_in)
-        ldec_lev=lev_in(1)>lev_in(dln); IF(ldec_lev) lev_in=lev_in(dln:1:-1)
-        nlev_in=dln
-        CALL NF95_GET_ATT(fID_in, varid, "units", press_unit)
-        k=LEN_TRIM(press_unit)
-        DO WHILE(ICHAR(press_unit(k:k))==0)
-          press_unit(k:k)=' '; k=LEN_TRIM(press_unit) !--- REMOVE NULL END CHAR
-        END DO
-        IF(press_unit ==  "Pa") THEN
-          lev_in = lev_in/100.                        !--- CONVERT TO hPa
-        ELSE IF(press_unit /= "hPa") THEN
-          CALL abort_physic(sub, "the only recognized units are Pa and hPa.",1)
-        END IF
-      CASE(4)                                         !--- TIME
-        CALL NF95_INQUIRE_DIMENSION(fID_in, dIDs(i), nclen=nmth_in)
-        cal_in='gregorian'
-        IF(NF90_GET_ATT(fID_in, varid, 'calendar', cal_in)/=NF90_NOERR)        &
-          WRITE(lunout,*)'WARNING: missing "calendar" attribute for "'//       &
-          TRIM(dim_nam)//'" in "climoz.nc". Choosing default: "gregorian".'
-        k=LEN_TRIM(cal_in)
-        DO WHILE(ICHAR(cal_in(k:k))==0)
-          cal_in(k:k)=' '; k=LEN_TRIM(cal_in)         !--- REMOVE NULL END CHAR
-        END DO
-    END SELECT
-  END DO
-
-  !--- Longitudes management:
-  !    * Need to shift data if the origin of input file longitudes /= -pi
-  !    * Need to add some margin in longitude to ensure input interval contains
-  !      all the output intervals => at least one longitudes slice has to be
-  !      duplicated, possibly more for undersampling.
-  IF(l3D) THEN
-    !--- Compute input edges longitudes vector (no end point yet)
-    ALLOCATE(v1(nlon_in+1))
-    v1(1)=(lon_in(nlon_in)+lon_in(1))/2.-pi
-    FORALL(i=2:nlon_in) v1(i)=(lon_in(i-1)+lon_in(i))/2.
-    v1(nlon_in+1)=v1(1)+2.*pi
-    DEALLOCATE(lon_in)
-
-    !--- Shift input longitudes vector until it contains first output point boundslon_reg(1,west)
-    v1=v1+2*pi*REAL(FLOOR((boundslon_reg(1,west)-v1(1))/(2.*pi)))
+  REAL :: null_array(0)
+  LOGICAL,SAVE :: first=.TRUE.
+!$OMP THREADPRIVATE(first)  
+  REAL, ALLOCATABLE :: test_o3_in(:,:)
+  REAL, ALLOCATABLE :: test_o3_out(:)
+
+
+  IF (grid_type==unstructured) THEN 
+    IF (first) THEN
+      IF (is_master) THEN
+        ALLOCATE(latitude_glo(klon_glo))
+        ALLOCATE(ind_cell_glo_glo(klon_glo))
+      ELSE
+        ALLOCATE(latitude_glo(0))
+        ALLOCATE(ind_cell_glo_glo(0))
+      ENDIF
+      CALL gather(latitude_deg,  latitude_glo)
+      CALL gather(ind_cell_glo,  ind_cell_glo_glo)
+    ENDIF 
+  ENDIF
+    
+  IF (is_omp_master) THEN
+    nlat_ou=nbp_lat
+    nlon_ou=nbp_lon
+    
+   !-------------------------------------------------------------------------------
+    IF (is_mpi_root) THEN
+      sub="regr_horiz_time_climoz"
+      WRITE(lunout,*)"Call sequence information: "//TRIM(sub)
+      CALL assert(read_climoz == 1 .OR. read_climoz == 2, "regr_lat_time_climoz")
+
+      CALL  NF95_OPEN("climoz.nc"  , NF90_NOWRITE, fID_in)
+      lprev=NF90_OPEN("climoz_m.nc", NF90_NOWRITE, fID_in_m)==NF90_NOERR
+      lnext=NF90_OPEN("climoz_p.nc", NF90_NOWRITE, fID_in_p)==NF90_NOERR
+
+      !--- Get coordinates from the input file. Converts lon/lat in radians.
+      !    Few inversions because "regr_conserv" and gcm need ascending vectors.
+      CALL NF95_INQ_VARID(fID_in, vars_in(1), varid)
+      CALL NF95_INQUIRE_VARIABLE(fID_in, varid, dimids=dIDs, ndims=ndims)
+      l3D=ndims==4; l2D=ndims==3
+      IF(l3D) WRITE(lunout,*)"Input files contain full 3D ozone fields."
+      IF(l2D) WRITE(lunout,*)"Input files contain zonal 2D ozone fields."
+      DO i=1,ndims
+        CALL NF95_INQUIRE_DIMENSION(fID_in, dIDs(i), name=dim_nam, nclen=dln)
+        CALL NF95_INQ_VARID(fID_in, dim_nam, varid)
+        ii=i; IF(l2D) ii=i+1                              !--- ndims==3:NO LONGITUDE 
+        SELECT CASE(ii)
+          CASE(1)                                         !--- LONGITUDE
+            CALL NF95_GW_VAR(fID_in, varid, lon_in)
+            ldec_lon=lon_in(1)>lon_in(dln); IF(ldec_lon) lon_in=lon_in(dln:1:-1)
+            nlon_in=dln; lon_in=lon_in*deg2rad
+          CASE(2)                                         !--- LATITUDE
+            CALL NF95_GW_VAR(fID_in, varid, lat_in)
+            ldec_lat=lat_in(1)>lat_in(dln); IF(ldec_lat) lat_in=lat_in(dln:1:-1)
+            nlat_in=dln; lat_in=lat_in*deg2rad
+          CASE(3)                                         !--- PRESSURE LEVELS
+            CALL NF95_GW_VAR(fID_in, varid, lev_in)
+            ldec_lev=lev_in(1)>lev_in(dln); IF(ldec_lev) lev_in=lev_in(dln:1:-1)
+            nlev_in=dln
+            CALL NF95_GET_ATT(fID_in, varid, "units", press_unit)
+            k=LEN_TRIM(press_unit)
+            DO WHILE(ICHAR(press_unit(k:k))==0)
+              press_unit(k:k)=' '; k=LEN_TRIM(press_unit) !--- REMOVE NULL END CHAR
+            END DO
+            IF(press_unit ==  "Pa") THEN
+              lev_in = lev_in/100.                        !--- CONVERT TO hPa
+            ELSE IF(press_unit /= "hPa") THEN
+              CALL abort_physic(sub, "the only recognized units are Pa and hPa.",1)
+            END IF
+          CASE(4)                                         !--- TIME
+            CALL NF95_INQUIRE_DIMENSION(fID_in, dIDs(i), nclen=nmth_in)
+            cal_in='gregorian'
+            IF(NF90_GET_ATT(fID_in, varid, 'calendar', cal_in)/=NF90_NOERR)        &  
+            WRITE(lunout,*)'WARNING: missing "calendar" attribute for "'//       &
+            TRIM(dim_nam)//'" in "climoz.nc". Choosing default: "gregorian".'
+            k=LEN_TRIM(cal_in)
+            DO WHILE(ICHAR(cal_in(k:k))==0)
+              cal_in(k:k)=' '; k=LEN_TRIM(cal_in)         !--- REMOVE NULL END CHAR
+            END DO
+        END SELECT
+      END DO
 
     !--- Ensure first input longitudes interval contains first output point boundslon_reg(1,west)
     dx1=locate(v1,boundslon_reg(1,west))-1
     v1=CSHIFT(v1,SHIFT=dx1,DIM=1); v1(nlon_in-dx1+2:)=v1(nlon_in-dx1+2:)+2.*pi
-
     !--- Extend input longitudes vector until last interval contains boundslon_reg(nlon_ou,east)
     dx2=0; DO WHILE(v1(1+dx2)+2.*pi<=boundslon_reg(nlon_ou,east)); dx2=dx2+1; END DO
 
-    !--- Final edges longitudes vector (with margin and end point)
-    ALLOCATE(lon_in_edge(nlon_in+dx2+1)); lon_in_edge=[v1,v1(2:1+dx2)+2.*pi]
-    DEALLOCATE(v1)
-  END IF
-
-  !--- Compute sinus of intervals edges latitudes:
-  ALLOCATE(sinlat_in_edge(nlat_in+1))
-  sinlat_in_edge(1) = -1. ; sinlat_in_edge(nlat_in+1) = 1.
-  FORALL(j=2:nlat_in) sinlat_in_edge(j)=SIN((lat_in(j-1)+lat_in(j))/2.)
-  DEALLOCATE(lat_in)
-
-  !--- Prepare quantities for time interpolation
-  tmidmonth=mid_month(anneeref, cal_in)
-  IF(interpt) THEN
-    ntim_ou=ioget_year_len(anneeref)
-    ALLOCATE(tmidday(ntim_ou))
-    tmidday=[(REAL(k)-0.5,k=1,ntim_ou)]
-    CALL ioget_calendar(cal_ou)
-  ELSE
-    ntim_ou=14
-    cal_ou=cal_in
-  END IF
-
-  !--- Create the output file and get the variable IDs:
-  CALL prepare_out(fID_in,nlev_in,ntim_ou, fID_ou,levID_ou,timID_ou,vID_ou, &
-                   ndims, cal_ou)
-
-  !--- Write remaining coordinate variables:
-  CALL NF95_PUT_VAR(fID_ou, levID_ou, lev_in); DEALLOCATE(lev_in)
-  IF(     interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidday)
-  IF(.NOT.interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidmonth)
-
-  !--- Check for contiguous years:
-  ib=0; ie=13
-  IF(nmth_in == 14) THEN; lprev=.FALSE.; lnext=.FALSE.
-    WRITE(lunout,*)'Using 14 months ozone climatology "climoz.nc"...'
-  ELSE
-    IF(     lprev) WRITE(lunout,*)'Using "climoz_m.nc" last record (previous year).'
-    IF(.NOT.lprev) WRITE(lunout,*)"No previous year file ; assuming periodicity."
-    IF(     lnext) WRITE(lunout,*)'Using "climoz_p.nc" first record (next year).'
-    IF(.NOT.lnext) WRITE(lunout,*)"No next year file ; assuming periodicity."
-    IF(.NOT.lprev) ib=1
-    IF(.NOT.lnext) ie=12
-  END IF
-  ALLOCATE(sta(ndims),cnt(ndims)); sta(:)=1
-  IF(l3D) cnt=[nlon_in,nlat_in,nlev_in,1]
-  IF(l2D) cnt=[        nlat_in,nlev_in,1]
-  IF(l3D) ALLOCATE(o3_in3(nlon_in+dx2,nlat_in,nlev_in,ib:ie,read_climoz))
-  IF(l2D) ALLOCATE(o3_in2(            nlat_in,nlev_in,ib:ie,read_climoz))
-
-  !--- Read full current file and one record each available contiguous file
-  DO iv=1,read_climoz
-    msg=TRIM(sub)//" NF90_GET_VAR "//TRIM(vars_in(iv))
-    CALL NF95_INQ_VARID(fID_in, vars_in(1), vID_in(iv))
-    IF(l3D) ncerr=NF90_GET_VAR(fID_in, vID_in(iv), o3_in3(1:nlon_in,:,:,1:12,iv))
-    IF(l2D) ncerr=NF90_GET_VAR(fID_in, vID_in(iv), o3_in2(          :,:,1:12,iv))
-    CALL handle_err(TRIM(msg), ncerr, fID_in)
-    IF(lprev) THEN; sta(ndims)=12
-      CALL NF95_INQ_VARID(fID_in_m, vars_in(1), vID_in(iv))
-      IF(l3D) ncerr=NF90_GET_VAR(fID_in_m,vID_in(iv),o3_in3(1:nlon_in,:,:, 0,iv),sta,cnt)
-      IF(l2d) ncerr=NF90_GET_VAR(fID_in_m,vID_in(iv),o3_in2(          :,:, 0,iv),sta,cnt)
-      CALL handle_err(TRIM(msg)//" previous", ncerr, fID_in_m)
+      IF (first) THEN
+        first=.FALSE.
+        RETURN
+      ENDIF
+    ENDIF
+    
+    
+    IF (is_mpi_root) THEN     
+      !--- Longitudes management:
+      !    * Need to shift data if the origin of input file longitudes /= -pi
+      !    * Need to add some margin in longitude to ensure input interval contains
+      !      all the output intervals => at least one longitudes slice has to be
+      !      duplicated, possibly more for undersampling.
+      IF(l3D) THEN
+        IF (grid_type==unstructured) THEN
+          dx2=0
+        ELSE
+          !--- Compute input edges longitudes vector (no end point yet)
+          ALLOCATE(v1(nlon_in+1))
+          v1(1)=(lon_in(nlon_in)+lon_in(1))/2.-pi
+          FORALL(i=2:nlon_in) v1(i)=(lon_in(i-1)+lon_in(i))/2.
+          v1(nlon_in+1)=v1(1)+2.*pi
+          DEALLOCATE(lon_in)
+
+          !--- Shift input longitudes vector until it contains first output point boundslon_reg(1,west)
+          v1=v1+2*pi*REAL(FLOOR((boundslon_reg(1,west)-v1(1))/(2.*pi)))
+
+          !--- Ensure first input longitudes interval contains first output point boundslon_reg(1,west)
+          dx1=locate(v1,boundslon_reg(1,west))-1
+          v1=CSHIFT(v1,SHIFT=dx1,DIM=1) 
+          v1(nlon_in-dx1+1:)=v1(nlon_in-dx1+1:)+2.*pi
+    
+          !--- Extend input longitudes vector until last interval contains boundslon_reg(nlat_ou,east)
+          dx2=0; DO WHILE(v1(1+dx2)+2.*pi<boundslon_reg(nlon_ou,east)); dx2=dx2+1; END DO
+
+          !--- Final edges longitudes vector (with margin and end point)
+          ALLOCATE(lon_in_edge(nlon_in+dx2+1)); lon_in_edge=[v1,v1(2:1+dx2)+2.*pi]
+          DEALLOCATE(v1)
+        ENDIF
+      END IF
+
+      !--- Compute sinus of intervals edges latitudes:
+      ALLOCATE(sinlat_in_edge(nlat_in+1))
+      sinlat_in_edge(1) = -1. ; sinlat_in_edge(nlat_in+1) = 1.
+      FORALL(j=2:nlat_in) sinlat_in_edge(j)=SIN((lat_in(j-1)+lat_in(j))/2.)
+      DEALLOCATE(lat_in)
+
+
+
+      !--- Check for contiguous years:
+      ib=0; ie=13
+      IF(nmth_in == 14) THEN; lprev=.FALSE.; lnext=.FALSE.
+        WRITE(lunout,*)'Using 14 months ozone climatology "climoz.nc"...'
+      ELSE  
+        IF(     lprev) WRITE(lunout,*)'Using "climoz_m.nc" last record (previous year).'
+        IF(.NOT.lprev) WRITE(lunout,*)"No previous year file ; assuming periodicity."
+        IF(     lnext) WRITE(lunout,*)'Using "climoz_p.nc" first record (next year).'
+        IF(.NOT.lnext) WRITE(lunout,*)"No next year file ; assuming periodicity."
+        IF(.NOT.lprev) ib=1
+        IF(.NOT.lnext) ie=12
+      END IF
+      ALLOCATE(sta(ndims),cnt(ndims)); sta(:)=1  
+      IF(l3D) cnt=[nlon_in,nlat_in,nlev_in,1]
+      IF(l2D) cnt=[        nlat_in,nlev_in,1]  
+      IF(l3D) ALLOCATE(o3_in3(nlon_in+dx2,nlat_in,nlev_in,ib:ie,read_climoz))
+      IF(l2D) ALLOCATE(o3_in2(            nlat_in,nlev_in,ib:ie,read_climoz))
+
+      !--- Read full current file and one record each available contiguous file
+      DO iv=1,read_climoz
+        msg=TRIM(sub)//" NF90_GET_VAR "//TRIM(vars_in(iv))
+        CALL NF95_INQ_VARID(fID_in, vars_in(1), vID_in(iv))
+        IF(l3D) ncerr=NF90_GET_VAR(fID_in, vID_in(iv), o3_in3(1:nlon_in,:,:,1:12,iv))
+        IF(l2D) ncerr=NF90_GET_VAR(fID_in, vID_in(iv), o3_in2(          :,:,1:12,iv))
+        CALL handle_err(TRIM(msg), ncerr, fID_in)
+        IF(lprev) THEN; sta(ndims)=12  
+          CALL NF95_INQ_VARID(fID_in_m, vars_in(1), vID_in(iv))
+          IF(l3D) ncerr=NF90_GET_VAR(fID_in_m,vID_in(iv),o3_in3(1:nlon_in,:,:, 0,iv),sta,cnt)
+          IF(l2d) ncerr=NF90_GET_VAR(fID_in_m,vID_in(iv),o3_in2(          :,:, 0,iv),sta,cnt)
+          CALL handle_err(TRIM(msg)//" previous", ncerr, fID_in_m)
+        END IF
+        IF(lnext) THEN; sta(ndims)=1  
+          CALL NF95_INQ_VARID(fID_in_p, vars_in(1), vID_in(iv))
+          IF(l3D) ncerr=NF90_GET_VAR(fID_in_p,vID_in(iv),o3_in3(1:nlon_in,:,:,13,iv),sta,cnt)
+          IF(l2D) ncerr=NF90_GET_VAR(fID_in_p,vID_in(iv),o3_in2(          :,:,13,iv),sta,cnt)
+          CALL handle_err(TRIM(msg)//" next", ncerr, fID_in_p)
+        END IF
+      END DO
+      IF(lprev.OR.lnext) DEALLOCATE(sta,cnt)
+      IF(lprev) CALL NF95_CLOSE(fID_in_m)
+      IF(lnext) CALL NF95_CLOSE(fID_in_p)
+
+      !--- Revert decreasing coordinates vector
+      IF(l3D) THEN
+        IF(ldec_lon) o3_in3(1:nlon_in,:,:,:,:) = o3_in3(nlon_in:1:-1,:,:,:,:)
+        IF(ldec_lat) o3_in3 = o3_in3(:,nlat_in:1:-1,:,:,:)
+        IF(ldec_lev) o3_in3 = o3_in3(:,:,nlev_in:1:-1,:,:)
+        
+        IF (grid_type /= unstructured) THEN
+          !--- Shift values for longitude and duplicate some longitudes slices
+          o3_in3(1:nlon_in,:,:,:,:)=CSHIFT(o3_in3(1:nlon_in,:,:,:,:),SHIFT=dx1,DIM=1)
+          o3_in3(nlon_in+1:nlon_in+dx2,:,:,:,:)=o3_in3(1:dx2,:,:,:,:)
+        ENDIF
+      ELSE
+        IF(ldec_lat) o3_in2 = o3_in2(  nlat_in:1:-1,:,:,:)
+        IF(ldec_lev) o3_in2 = o3_in2(  :,nlev_in:1:-1,:,:)
+      END IF
+
+     !--- Deal with missing values 
+      DO m=1, read_climoz
+        WRITE(msg,'(a,i0)')"regr_lat_time_climoz: field Nr.",m
+        IF(NF90_GET_ATT(fID_in,vID_in(m),"missing_value",NaN)/= NF90_NOERR) THEN
+          IF(NF90_GET_ATT(fID_in, vID_in(m),"_FillValue",NaN)/= NF90_NOERR) THEN
+            WRITE(lunout,*)TRIM(msg)//": no missing value attribute found."; CYCLE
+          END IF
+        END IF
+        WRITE(lunout,*)TRIM(msg)//": missing value attribute found."
+        WRITE(lunout,*)"Trying to fill in NaNs ; a full field would be better."
+
+        !--- Check top layer contains no NaNs & search NaNs from top to ground
+        msg=TRIM(sub)//": NaNs in top layer !"
+        IF(l3D) THEN
+          IF(ANY(o3_in3(:,:,1,:,m)==NaN)) CALL abort_physic(sub,msg,1)
+          DO k = 2,nlev_in
+            WHERE(o3_in3(:,:,k,:,m)==NaN) o3_in3(:,:,k,:,m)=o3_in3(:,:,k-1,:,m)
+          END DO
+        ELSE
+          IF(ANY(o3_in2(  :,1,:,m)==NaN)) THEN
+            WRITE(lunout,*)msg
+            !--- Fill in latitudes where all values are missing
+            DO l=1,nmth_in
+              !--- Next to south pole
+              j=1;       DO WHILE(o3_in2(j,1,l,m)==NaN); j=j+1; END DO
+              IF(j>1) &
+                o3_in2(:j-1,:,l,m)=SPREAD(o3_in2(j,:,l,m),DIM=1,ncopies=j-1)
+              !--- Next to north pole
+              j=nlat_in; DO WHILE(o3_in2(j,1,l,m)==NaN); j=j+1; END DO
+              IF(j<nlat_in) &
+                o3_in2(j+1:,:,l,m)=SPREAD(o3_in2(j,:,l,m),DIM=1,ncopies=nlat_in-j)
+            END DO
+          END IF
+
+          !--- Fill in high latitudes missing values
+          !--- Highest level been filled-in, so has always valid values.
+          DO k = 2,nlev_in
+            WHERE(o3_in2(:,k,:,m)==NaN) o3_in2(:,k,:,m)=o3_in2(:,k-1,:,m)
+          END DO
+        END IF
+      END DO
+
+    ENDIF
+    
+    !=============================================================================
+    IF(l3D) THEN                                                   !=== 3D FIELDS
+    !=============================================================================
+     IF (grid_type==unstructured) THEN
+       nlat_ou=klon_mpi
+       
+       IF (is_mpi_root) THEN 
+         ALLOCATE(o3_in3bis(nlon_in,nlat_in,nlev_in,0:13,read_climoz)) 
+         o3_in3bis(:,:,:,ib:ie,:)=o3_in3(1:nlon_in,:,:,ib:ie,:)
+       ELSE
+         ALLOCATE(o3_in3bis(0,0,0,0,read_climoz))
+       ENDIF
+       ALLOCATE(o3_regr_lonlat(1, nlat_ou, nlev_in, 0:13, read_climoz))
+       
+       CALL xios_send_field("tro3_in",o3_in3bis(:,:,:,:,:))
+       CALL xios_recv_field("tro3_out",o3_regr_lonlat(1,:,:,:,:))
+
+     ELSE
+          
+       !--- Regrid in longitude
+        ALLOCATE(o3_regr_lon(nlon_ou, nlat_in, nlev_in, ie-ib+1, read_climoz))
+        CALL regr_conserv(1, o3_in3, xs = lon_in_edge,                             &
+                            xt = [boundslon_reg(1,west),boundslon_reg(:,east)],    &
+                            vt = o3_regr_lon, slope = slopes(1,o3_in3, lon_in_edge))
+        DEALLOCATE(o3_in3)
+
+        !--- Regrid in latitude: averaging with respect to SIN(lat) is
+        !                        equivalent to weighting by COS(lat)
+        !--- (inverted indices in "o3_regr_lonlat" because "rlatu" is decreasing)
+        ALLOCATE(o3_regr_lonlat(nlon_ou, nlat_ou, nlev_in, 0:13, read_climoz))
+        CALL regr_conserv(2, o3_regr_lon, xs = sinlat_in_edge,                     &
+                        xt = [- 1., SIN(boundslat_reg(nlat_ou-1:1:-1,south)), 1.], &
+                        vt = o3_regr_lonlat(:,nlat_ou:1:- 1,:,ib:ie,:),            &
+                   slope = slopes(2,o3_regr_lon, sinlat_in_edge))
+        DEALLOCATE(o3_regr_lon)
+
+     ENDIF
+
+     !--- Duplicate previous/next record(s) if they are not available
+     IF(.NOT.lprev) o3_regr_lonlat(:,:,:, 0,:) = o3_regr_lonlat(:,:,:,12,:)
+     IF(.NOT.lnext) o3_regr_lonlat(:,:,:,13,:) = o3_regr_lonlat(:,:,:, 1,:)
+      
+     !--- Regrid in time by linear interpolation:
+     ALLOCATE(o3_out3(nlon_ou, nlat_ou, nlev_in, ntim_ou, read_climoz))
+     IF(     interpt) CALL regr_lint(4,o3_regr_lonlat,tmidmonth,tmidday,o3_out3)
+     IF(.NOT.interpt) o3_out3=o3_regr_lonlat
+     DEALLOCATE(o3_regr_lonlat)
+
+     nlat_ou=nbp_lat
+     IF (grid_type==unstructured) THEN
+       CALL xios_send_field('o3_out',o3_out3)
+       ndims=3 
+       ALLOCATE(o3_out3_glo(nlat_ou, nlev_in, ntim_ou, read_climoz))
+       CALL gather_mpi(o3_out3(1,:,:,:,:), o3_out3_glo)
+     ENDIF
+
+    !--- Create the output file and get the variable IDs:
+    CALL prepare_out(fID_in,nlev_in,ntim_ou, fID_ou,levID_ou,timID_ou,vID_ou, &
+                     ndims, cal_ou)
+
+    IF (is_mpi_root) THEN
+      !--- Write remaining coordinate variables:
+      CALL NF95_PUT_VAR(fID_ou, levID_ou, lev_in); DEALLOCATE(lev_in)
+      IF(     interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidday)
+      IF(.NOT.interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidmonth)
+
+      !--- Write to file (the order of "rlatu" is inverted in the output file):
+        IF (grid_type==unstructured) THEN
+
+          ALLOCATE(o3_out(nlat_ou, nlev_in, ntim_ou, read_climoz))
+          DO i=1,klon_glo
+            o3_out(ind_cell_glo_glo(i),:,:,:)=o3_out3_glo(i,:,:,:)
+          ENDDO
+
+          DO m = 1, read_climoz
+            CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out(nlat_ou:1:-1,:,:,m))
+          END DO
+          
+        ELSE
+          DO m = 1, read_climoz
+            CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out3(:,nlat_ou:1:-1,:,:,m))
+          END DO
+      ENDIF
+      CALL NF95_CLOSE(fID_ou)
+
+
+    ENDIF
+
+
+    !=============================================================================
+    ELSE                                                         !=== ZONAL FIELDS
+    !=============================================================================
+   
+     IF (grid_type==unstructured) THEN
+       nlat_ou=klon_mpi
+
+       IF (is_mpi_root) THEN 
+         ALLOCATE(o3_in2bis(8,nlat_in,nlev_in,0:13,read_climoz)) 
+         o3_in2bis(:,:,:,ib:ie,:)=SPREAD(o3_in2,1,8)
+       ELSE
+         ALLOCATE(o3_in2bis(0,0,0,0,read_climoz))
+       ENDIF
+       ALLOCATE(o3_regr_lat(nlat_ou, nlev_in, 0:13, read_climoz))
+       CALL xios_send_field("tro3_in",o3_in2bis(:,:,:,:,:))
+       CALL xios_recv_field("tro3_out",o3_regr_lat(:,:,:,:))
+       IF(.NOT.lprev) o3_regr_lat(:,:, 0, :) = o3_regr_lat(:,:,12,:)
+       IF(.NOT.lnext) o3_regr_lat(:,:,13, :) = o3_regr_lat(:,:, 1,:)
+       
+     
+     ELSE 
+        !--- Regrid in latitude: averaging with respect to SIN(lat) is
+        !                        equivalent to weighting by COS(lat)
+        !--- (inverted indices in "o3_regr_lat" because "rlatu" is decreasing)
+        ALLOCATE(o3_regr_lat(nlat_ou, nlev_in, 0:13, read_climoz))
+        CALL regr_conserv(1, o3_in2, xs = sinlat_in_edge,                          &
+                        xt = [- 1., SIN(boundslat_reg(nlat_ou-1:1:-1,south)), 1.], &
+                        vt = o3_regr_lat(nlat_ou:1:- 1,:,ib:ie,:),                 &
+                     slope = slopes(1,o3_in2, sinlat_in_edge))
+        DEALLOCATE(o3_in2)
+
+        !--- Duplicate previous/next record(s) if they are not available
+        IF(.NOT.lprev) o3_regr_lat(:,:, 0,:) = o3_regr_lat(:,:,12,:)
+        IF(.NOT.lnext) o3_regr_lat(:,:,13,:) = o3_regr_lat(:,:, 1,:)
+
+     ENDIF
+     
+      !--- Regrid in time by linear interpolation:
+      ALLOCATE(o3_out2(nlat_ou, nlev_in, ntim_ou, read_climoz))
+      IF(     interpt) CALL regr_lint(3,o3_regr_lat, tmidmonth, tmidday, o3_out2)
+      IF(.NOT.interpt) o3_out2=o3_regr_lat
+      DEALLOCATE(o3_regr_lat)
+
+      nlat_ou=nbp_lat
+    
+      IF (grid_type==unstructured) THEN
+        ndims=3 
+        ALLOCATE(o3_out2_glo(nlat_ou, nlev_in, ntim_ou, read_climoz))
+        CALL gather_mpi(o3_out2, o3_out2_glo)
+      ENDIF
+      
+      !--- Create the output file and get the variable IDs:
+      CALL prepare_out(fID_in,nlev_in,ntim_ou, fID_ou,levID_ou,timID_ou,vID_ou, &
+                         ndims, cal_ou)
+
+      IF (is_mpi_root) THEN
+      
+        !--- Write remaining coordinate variables:
+        CALL NF95_PUT_VAR(fID_ou, levID_ou, lev_in); DEALLOCATE(lev_in)
+        IF(     interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidday)
+        IF(.NOT.interpt) CALL NF95_PUT_VAR(fID_ou, timID_ou, tmidmonth)
+
+        IF (grid_type==unstructured) THEN
+
+          ALLOCATE(o3_out3_glo(nlat_ou, nlev_in, ntim_ou, read_climoz))
+          DO i=1,klon_glo
+            o3_out(ind_cell_glo_glo(i),:,:,:)=o3_out2_glo(i,:,:,:)
+          ENDDO
+
+
+          DO m = 1, read_climoz
+            CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out(nlat_ou:1:-1,:,:,m))
+          END DO
+        ELSE
+          !--- Write to file (the order of "rlatu" is inverted in the output file):
+          DO m = 1, read_climoz
+            CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out2(nlat_ou:1:-1,:,:,m))
+          END DO
+        ENDIF
+        
+        CALL NF95_CLOSE(fID_ou)
+      
+      ENDIF
+
+    !=============================================================================
     END IF
-    IF(lnext) THEN; sta(ndims)=1
-      CALL NF95_INQ_VARID(fID_in_p, vars_in(1), vID_in(iv))
-      IF(l3D) ncerr=NF90_GET_VAR(fID_in_p,vID_in(iv),o3_in3(1:nlon_in,:,:,13,iv),sta,cnt)
-      IF(l2D) ncerr=NF90_GET_VAR(fID_in_p,vID_in(iv),o3_in2(          :,:,13,iv),sta,cnt)
-      CALL handle_err(TRIM(msg)//" next", ncerr, fID_in_p)
-    END IF
-  END DO
-  IF(lprev.OR.lnext) DEALLOCATE(sta,cnt)
-  IF(lprev) CALL NF95_CLOSE(fID_in_m)
-  IF(lnext) CALL NF95_CLOSE(fID_in_p)
-
-  !--- Revert decreasing coordinates vector
-  IF(l3D) THEN
-    IF(ldec_lon) o3_in3(1:nlon_in,:,:,:,:) = o3_in3(nlon_in:1:-1,:,:,:,:)
-    IF(ldec_lat) o3_in3 = o3_in3(:,nlat_in:1:-1,:,:,:)
-    IF(ldec_lev) o3_in3 = o3_in3(:,:,nlev_in:1:-1,:,:)
-    !--- Shift values for longitude and duplicate some longitudes slices
-    o3_in3(1:nlon_in,:,:,:,:)=CSHIFT(o3_in3(1:nlon_in,:,:,:,:),SHIFT=dx1,DIM=1)
-    o3_in3(nlon_in+1:nlon_in+dx2,:,:,:,:)=o3_in3(1:dx2,:,:,:,:)
-  ELSE
-    IF(ldec_lat) o3_in2 = o3_in2(  nlat_in:1:-1,:,:,:)
-    IF(ldec_lev) o3_in2 = o3_in2(  :,nlev_in:1:-1,:,:)
-  END IF
-
- !--- Deal with missing values
-  DO m=1, read_climoz
-    WRITE(msg,'(a,i0)')"regr_lat_time_climoz: field Nr.",m
-    IF(NF90_GET_ATT(fID_in,vID_in(m),"missing_value",NaN)/= NF90_NOERR) THEN
-      IF(NF90_GET_ATT(fID_in, vID_in(m),"_FillValue",NaN)/= NF90_NOERR) THEN
-        WRITE(lunout,*)TRIM(msg)//": no missing value attribute found."; CYCLE
-      END IF
-    END IF
-    WRITE(lunout,*)TRIM(msg)//": missing value attribute found."
-    WRITE(lunout,*)"Trying to fill in NaNs ; a full field would be better."
-
-    !--- Check top layer contains no NaNs & search NaNs from top to ground
-    msg=TRIM(sub)//": NaNs in top layer !"
-    IF(l3D) THEN
-      IF(ANY(o3_in3(:,:,1,:,m)==NaN)) CALL abort_physic(sub,msg,1)
-      DO k = 2,nlev_in
-        WHERE(o3_in3(:,:,k,:,m)==NaN) o3_in3(:,:,k,:,m)=o3_in3(:,:,k-1,:,m)
-      END DO
-    ELSE
-      IF(ANY(o3_in2(  :,1,:,m)==NaN)) THEN
-        WRITE(lunout,*)msg
-        !--- Fill in latitudes where all values are missing
-        DO l=1,nmth_in
-          !--- Next to south pole
-          j=1;       DO WHILE(o3_in2(j,1,l,m)==NaN); j=j+1; END DO
-          IF(j>1) &
-            o3_in2(:j-1,:,l,m)=SPREAD(o3_in2(j,:,l,m),DIM=1,ncopies=j-1)
-          !--- Next to north pole
-          j=nlat_in; DO WHILE(o3_in2(j,1,l,m)==NaN); j=j+1; END DO
-          IF(j<nlat_in) &
-            o3_in2(j+1:,:,l,m)=SPREAD(o3_in2(j,:,l,m),DIM=1,ncopies=nlat_in-j)
-        END DO
-      END IF
-
-      !--- Fill in high latitudes missing values
-      !--- Highest level been filled-in, so has always valid values.
-      DO k = 2,nlev_in
-        WHERE(o3_in2(:,k,:,m)==NaN) o3_in2(:,k,:,m)=o3_in2(:,k-1,:,m)
-      END DO
-    END IF
-  END DO
-  CALL NF95_CLOSE(fID_in)
-
-  !=============================================================================
-  IF(l3D) THEN                                                   !=== 3D FIELDS
-  !=============================================================================
-    !--- Regrid in longitude
-    ALLOCATE(o3_regr_lon(nlon_ou, nlat_in, nlev_in, ie-ib+1, read_climoz))
-    CALL regr_conserv(1, o3_in3, xs = lon_in_edge,                             &
-                        xt = [boundslon_reg(1,west),boundslon_reg(:,east)],    &
-                        vt = o3_regr_lon, slope = slopes(1,o3_in3, lon_in_edge))
-    DEALLOCATE(o3_in3)
-
-    !--- Regrid in latitude: averaging with respect to SIN(lat) is
-    !                        equivalent to weighting by COS(lat)
-    !--- (inverted indices in "o3_regr_lonlat" because "rlatu" is decreasing)
-    ALLOCATE(o3_regr_lonlat(nlon_ou, nlat_ou, nlev_in, 0:13, read_climoz))
-    CALL regr_conserv(2, o3_regr_lon, xs = sinlat_in_edge,                     &
-                    xt = [- 1., SIN(boundslat_reg(nlat_ou-1:1:-1,south)), 1.], &
-                    vt = o3_regr_lonlat(:,nlat_ou:1:- 1,:,ib:ie,:),            &
-                 slope = slopes(2,o3_regr_lon, sinlat_in_edge))
-    DEALLOCATE(o3_regr_lon)
-
-    !--- Duplicate previous/next record(s) if they are not available
-    IF(.NOT.lprev) o3_regr_lonlat(:,:,:, 0,:) = o3_regr_lonlat(:,:,:,12,:)
-    IF(.NOT.lnext) o3_regr_lonlat(:,:,:,13,:) = o3_regr_lonlat(:,:,:, 1,:)
-
-    !--- Regrid in time by linear interpolation:
-    ALLOCATE(o3_out3(nlon_ou, nlat_ou, nlev_in, ntim_ou, read_climoz))
-    IF(     interpt) CALL regr_lint(4,o3_regr_lonlat,tmidmonth,tmidday,o3_out3)
-    IF(.NOT.interpt) o3_out3=o3_regr_lonlat
-    DEALLOCATE(o3_regr_lonlat)
-
-    !--- Write to file (the order of "rlatu" is inverted in the output file):
-    DO m = 1, read_climoz
-      CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out3(:,nlat_ou:1:-1,:,:,m))
-    END DO
-
-  !=============================================================================
-  ELSE                                                         !=== ZONAL FIELDS
-  !=============================================================================
-    !--- Regrid in latitude: averaging with respect to SIN(lat) is
-    !                        equivalent to weighting by COS(lat)
-    !--- (inverted indices in "o3_regr_lat" because "rlatu" is decreasing)
-    ALLOCATE(o3_regr_lat(nlat_ou, nlev_in, 0:13, read_climoz))
-    CALL regr_conserv(1, o3_in2, xs = sinlat_in_edge,                          &
-                    xt = [- 1., SIN(boundslat_reg(nlat_ou-1:1:-1,south)), 1.], &
-                    vt = o3_regr_lat(nlat_ou:1:- 1,:,ib:ie,:),                 &
-                 slope = slopes(1,o3_in2, sinlat_in_edge))
-    DEALLOCATE(o3_in2)
-
-    !--- Duplicate previous/next record(s) if they are not available
-    IF(.NOT.lprev) o3_regr_lat(:,:, 0,:) = o3_regr_lat(:,:,12,:)
-    IF(.NOT.lnext) o3_regr_lat(:,:,13,:) = o3_regr_lat(:,:, 1,:)
-
-    !--- Regrid in time by linear interpolation:
-    ALLOCATE(o3_out2(nlat_ou, nlev_in, ntim_ou, read_climoz))
-    IF(     interpt) CALL regr_lint(3,o3_regr_lat, tmidmonth, tmidday, o3_out2)
-    IF(.NOT.interpt) o3_out2=o3_regr_lat
-    DEALLOCATE(o3_regr_lat)
-
-    !--- Write to file (the order of "rlatu" is inverted in the output file):
-    DO m = 1, read_climoz
-      CALL NF95_PUT_VAR(fID_ou, vID_ou(m), o3_out2(nlat_ou:1:-1,:,:,m))
-    END DO
-
-  !=============================================================================
-  END IF
-  !=============================================================================
-
-  CALL NF95_CLOSE(fID_ou)
-
+    !=============================================================================
+
+    IF (is_mpi_root) CALL NF95_CLOSE(fID_in)
+
+  ENDIF ! is_omp_master
+
+  first=.FALSE.
 END SUBROUTINE regr_horiz_time_climoz
 !
@@ -408,4 +569,8 @@
 !-------------------------------------------------------------------------------
   USE regular_lonlat_mod, ONLY: lon_reg, lat_reg
+  USE regular_lonlat_mod, ONLY: lon_reg, lat_reg
+  USE mod_phys_lmdz_para, ONLY: is_mpi_root
+  USE mod_grid_phy_lmdz, ONLY: klon_glo
+!
 !-------------------------------------------------------------------------------
 ! Arguments:
@@ -419,68 +584,83 @@
   INTEGER :: dlonID, dlatID, dlevID, dtimID, dIDs(4)
   INTEGER :: vlonID, vlatID, ncerr,  is
+  REAL,ALLOCATABLE    :: latitude_glo_(:)
   CHARACTER(LEN=80) :: sub
-!-------------------------------------------------------------------------------
-  sub="prepare_out"
-  WRITE(lunout,*)"CALL sequence information: "//TRIM(sub)
-  CALL NF95_CREATE("climoz_LMDZ.nc", NF90_clobber, fID_ou)
+  INTEGER :: i
+
+
+!-------------------------------------------------------------------------------
+  
+  IF (is_mpi_root) THEN  
+    sub="prepare_out"
+    WRITE(lunout,*)"CALL sequence information: "//TRIM(sub)
+    CALL NF95_CREATE("climoz_LMDZ.nc", NF90_clobber, fID_ou)
 
   !--- Dimensions:
-  IF(ndims==4) &
-  CALL NF95_DEF_DIM(fID_ou, "rlonv", nlon_ou, dlonID)
-  CALL NF95_DEF_DIM(fID_ou, "rlatu", nlat_ou, dlatID)
-  CALL NF95_DEF_DIM(fID_ou, "plev",  nlev_in, dlevID)
-  CALL NF95_DEF_DIM(fID_ou, "time",  ntim_ou, dtimID)
-
-  !--- Define coordinate variables:
-  IF(ndims==4) &
-  CALL NF95_DEF_VAR(fID_ou, "rlonv", NF90_FLOAT, dlonID, vlonID)
-  CALL NF95_DEF_VAR(fID_ou, "rlatu", NF90_FLOAT, dlatID, vlatID)
-  CALL NF95_DEF_VAR(fID_ou, "plev",  NF90_FLOAT, dlevID, vlevID)
-  CALL NF95_DEF_VAR(fID_ou, "time",  NF90_FLOAT, dtimID, vtimID)
-  IF(ndims==4) &
-  CALL NF95_PUT_ATT(fID_ou, vlonID, "units", "degrees_east")
-  CALL NF95_PUT_ATT(fID_ou, vlatID, "units", "degrees_north")
-  CALL NF95_PUT_ATT(fID_ou, vlevID, "units", "millibar")
-  CALL NF95_PUT_ATT(fID_ou, vtimID, "units", "days since 2000-1-1")
-  IF(ndims==4) &
-  CALL NF95_PUT_ATT(fID_ou, vlonID, "standard_name", "longitude")
-  CALL NF95_PUT_ATT(fID_ou, vlatID, "standard_name", "latitude")
-  CALL NF95_PUT_ATT(fID_ou, vlevID, "standard_name", "air_pressure")
-  CALL NF95_PUT_ATT(fID_ou, vtimID, "standard_name", "time")
-  CALL NF95_PUT_ATT(fID_ou, vlevID, "long_name",     "air pressure")
-  CALL NF95_PUT_ATT(fID_ou, vtimID, "calendar",      cal_ou)
+    IF(ndims==4) &
+    CALL NF95_DEF_DIM(fID_ou, "rlonv", nlon_ou, dlonID)
+    CALL NF95_DEF_DIM(fID_ou, "rlatu", nlat_ou, dlatID)
+    CALL NF95_DEF_DIM(fID_ou, "plev",  nlev_in, dlevID)
+    CALL NF95_DEF_DIM(fID_ou, "time",  ntim_ou, dtimID)
+
+    !--- Define coordinate variables:
+    IF(ndims==4) &
+    CALL NF95_DEF_VAR(fID_ou, "rlonv", NF90_FLOAT, dlonID, vlonID)
+    CALL NF95_DEF_VAR(fID_ou, "rlatu", NF90_FLOAT, dlatID, vlatID)
+    CALL NF95_DEF_VAR(fID_ou, "plev",  NF90_FLOAT, dlevID, vlevID)
+    CALL NF95_DEF_VAR(fID_ou, "time",  NF90_FLOAT, dtimID, vtimID)
+    IF(ndims==4) &
+    CALL NF95_PUT_ATT(fID_ou, vlonID, "units", "degrees_east")
+    CALL NF95_PUT_ATT(fID_ou, vlatID, "units", "degrees_north")
+    CALL NF95_PUT_ATT(fID_ou, vlevID, "units", "millibar")
+    CALL NF95_PUT_ATT(fID_ou, vtimID, "units", "days since 2000-1-1")
+    IF(ndims==4) &
+    CALL NF95_PUT_ATT(fID_ou, vlonID, "standard_name", "longitude")
+    CALL NF95_PUT_ATT(fID_ou, vlatID, "standard_name", "latitude")
+    CALL NF95_PUT_ATT(fID_ou, vlevID, "standard_name", "air_pressure")
+    CALL NF95_PUT_ATT(fID_ou, vtimID, "standard_name", "time")
+    CALL NF95_PUT_ATT(fID_ou, vlevID, "long_name",     "air pressure")
+    CALL NF95_PUT_ATT(fID_ou, vtimID, "calendar",      cal_ou)
 
   !--- Define the main variables:
-  IF(ndims==3) dIDs(1:3) = [ dlatID, dlevID, dtimID]
-  IF(ndims==4) dIDs=[dlonID, dlatID, dlevID, dtimID]
-  CALL NF95_DEF_VAR(fID_ou, vars_in(1), NF90_FLOAT, dIDs(1:ndims), vID_ou(1))
-  CALL NF95_PUT_ATT(fID_ou, vID_ou(1), "long_name", "ozone mole fraction")
-  CALL NF95_PUT_ATT(fID_ou, vID_ou(1), "standard_name", "mole_fraction_of_ozone&
+    IF(ndims==3) dIDs(1:3) = [ dlatID, dlevID, dtimID]
+    IF(ndims==4) dIDs=[dlonID, dlatID, dlevID, dtimID]
+    CALL NF95_DEF_VAR(fID_ou, vars_in(1), NF90_FLOAT, dIDs(1:ndims), vID_ou(1))
+    CALL NF95_PUT_ATT(fID_ou, vID_ou(1), "long_name", "ozone mole fraction")
+    CALL NF95_PUT_ATT(fID_ou, vID_ou(1), "standard_name", "mole_fraction_of_ozone&
       &_in_air")
-  IF(SIZE(vID_ou) == 2) THEN
-    CALL NF95_DEF_VAR(fID_ou, vars_in(2), NF90_FLOAT, dIDs(1:ndims), vID_ou(2))
-    CALL NF95_PUT_ATT(fID_ou, vID_ou(2), "long_name","ozone mole fraction in da&
-      &ylight")
-  END IF
+    IF(SIZE(vID_ou) == 2) THEN
+      CALL NF95_DEF_VAR(fID_ou, vars_in(2), NF90_FLOAT, dIDs(1:ndims), vID_ou(2))
+      CALL NF95_PUT_ATT(fID_ou, vID_ou(2), "long_name","ozone mole fraction in da&
+        &ylight")
+    END IF
 
   !--- Global attributes:
   ! The following commands, copying attributes, may fail. That is OK.
   ! It should just mean that the attribute is not defined in the input file.
-  CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"Conventions",fID_ou,NF90_GLOBAL, ncerr)
-  CALL handle_err_copy_att("Conventions")
-  CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"title",      fID_ou,NF90_GLOBAL, ncerr)
-  CALL handle_err_copy_att("title")
-  CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"institution",fID_ou,NF90_GLOBAL, ncerr)
-  CALL handle_err_copy_att("institution")
-  CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"source",     fID_ou,NF90_GLOBAL, ncerr)
-  CALL handle_err_copy_att("source")
-  CALL NF95_PUT_ATT (fID_ou,NF90_GLOBAL,"comment", "Regridded for LMDZ")
-  CALL NF95_ENDDEF(fID_ou)
-
-  !--- Write one of the coordinate variables:
-  IF(ndims==4) CALL NF95_PUT_VAR(fID_ou, vlonID, lon_reg/deg2rad)
-  CALL NF95_PUT_VAR(fID_ou, vlatID, lat_reg(nlat_ou:1:-1)/deg2rad)
-  !    (convert from rad to degrees and sort in ascending order)
-
+    CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"Conventions",fID_ou,NF90_GLOBAL, ncerr)
+    CALL handle_err_copy_att("Conventions")
+    CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"title",      fID_ou,NF90_GLOBAL, ncerr)
+    CALL handle_err_copy_att("title")
+    CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"institution",fID_ou,NF90_GLOBAL, ncerr)
+    CALL handle_err_copy_att("institution")
+    CALL NF95_COPY_ATT(fID_in,NF90_GLOBAL,"source",     fID_ou,NF90_GLOBAL, ncerr)
+    CALL handle_err_copy_att("source")
+    CALL NF95_PUT_ATT (fID_ou,NF90_GLOBAL,"comment", "Regridded for LMDZ")
+    CALL NF95_ENDDEF(fID_ou)
+
+    IF (grid_type==unstructured) THEN
+      ALLOCATE(latitude_glo_(klon_glo))
+      DO i=1,klon_glo
+        latitude_glo_(ind_cell_glo_glo(i))=latitude_glo(i)
+      ENDDO
+      CALL NF95_PUT_VAR(fID_ou, vlatID, latitude_glo_)
+    ELSE
+      !--- Write one of the coordinate variables:
+      IF(ndims==4) CALL NF95_PUT_VAR(fID_ou, vlonID, lon_reg/deg2rad)
+      CALL NF95_PUT_VAR(fID_ou, vlatID, lat_reg(nlat_ou:1:-1)/deg2rad)
+    !    (convert from rad to degrees and sort in ascending order)
+    ENDIF
+  ENDIF
+  
 CONTAINS
 
Index: /LMDZ6/trunk/libf/phylmd/regr_pr_time_av_m.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/regr_pr_time_av_m.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/regr_pr_time_av_m.F90	(revision 3435)
@@ -118,13 +118,14 @@
   USE assert_m,       ONLY: assert
   USE assert_eq_m,    ONLY: assert_eq
-  USE comvert_mod,    ONLY: scaleheight
+!!  USE comvert_mod,    ONLY: scaleheight
   USE interpolation,  ONLY: locate
   USE regr_conserv_m, ONLY: regr_conserv
   USE regr_lint_m,    ONLY: regr_lint
   USE slopes_m,       ONLY: slopes
-  USE mod_phys_lmdz_mpi_data,       ONLY: is_mpi_root
-  USE mod_grid_phy_lmdz, ONLY: nlon=>nbp_lon, nlat=>nbp_lat, nlev_ou=>nbp_lev
-  USE mod_phys_lmdz_transfert_para, ONLY: scatter2d, scatter
+  USE mod_phys_lmdz_para,           ONLY: is_mpi_root,is_master
+  USE mod_grid_phy_lmdz,            ONLY: nlon=>nbp_lon, nlat=>nbp_lat, nlev_ou=>nbp_lev, klon_glo, grid_type, unstructured
+  USE mod_phys_lmdz_transfert_para, ONLY: scatter2d, scatter, gather
   USE phys_cal_mod,                 ONLY: calend, year_len, days_elapsed, jH_cur
+  USE geometry_mod,                 ONLY: ind_cell_glo
 !-------------------------------------------------------------------------------
 ! Arguments:
@@ -175,4 +176,5 @@
     v2i(klon,SIZE(Pre_in)-1,SIZE(nam)), &     !--- v2 in Ploc=='I' case
     v2c(klon,SIZE(Pre_in)  ,SIZE(nam))        !--- v2 in Ploc=='C' case
+  INTEGER,ALLOCATABLE :: ind_cell_glo_glo(:)
   LOGICAL :: ll
 !--- For debug
@@ -255,14 +257,37 @@
     CALL bcast(lO3Tfile); CALL bcast(linterp)
   END IF
+  
+  IF (is_master) THEN 
+    ALLOCATE(ind_cell_glo_glo(klon_glo))
+  ELSE
+    ALLOCATE(ind_cell_glo_glo(0))
+  ENDIF
+  CALL gather(ind_cell_glo,ind_cell_glo_glo)
+  IF (is_master .AND. grid_type==unstructured) v1(:,:,:,:)=v1(:,ind_cell_glo_glo(:),:,:)
+  
   CALL scatter2d(v1,v2)
-  IF(lPrSfile) CALL scatter2d(pg1,Pgnd_in)
-  IF(lPrTfile) CALL scatter2d(pt1,Ptrp_in)
-  IF(lO3Tfile) CALL scatter2d(ot1,Otrp_in)
+
+  !--- No "ps" in input file => assumed to be equal to current LMDZ ground press
+  IF(lPrSfile) THEN
+    IF (is_master .AND. grid_type==unstructured) pg1(:,:)=pg1(:,ind_cell_glo_glo(:))
+    CALL scatter2d(pg1,Pgnd_in)
+  ELSE
+    Pgnd_in=Pre_ou(:,1)
+  END IF
+
+  IF(lPrTfile) THEN
+    IF (is_master .AND. grid_type==unstructured) pt1(:,:)=pt1(:,ind_cell_glo_glo(:))
+    CALL scatter2d(pt1,Ptrp_in)
+  ENDIF
+
+  IF(lO3Tfile) THEN
+    IF (is_master .AND. grid_type==unstructured) ot1(:,:)=ot1(:,ind_cell_glo_glo(:))
+    CALL scatter2d(ot1,Otrp_in)
+  ENDIF
   !--- No ground pressure in input file => choose it to be the one of LMDZ
   IF(lAdjTro.AND..NOT.lPrSfile) Pgnd_in(:)=Pgrnd_ou(:)
-  
-!-------------------------------------------------------------------------------
-  IF(.NOT.lAdjTro) THEN       !--- REGRID IN PRESSURE ; NO TROPOPAUSE ADJUSTMENT
-!-------------------------------------------------------------------------------
+
+  !--- REGRID IN PRESSURE ; 3rd index inverted because "paprs" is decreasing
+  IF(.NOT.lAdjTro) THEN
     DO i=1,klon
       Pres_ou=Pre_ou(i,SIZE(Pre_ou,2):1:-1)   !--- pplay & paprs are decreasing
Index: /LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato1_rrtm.F90	(revision 3435)
@@ -2,4 +2,5 @@
 ! $Id: readaerosolstrato1_rrtm.F90 2526 2016-05-26 22:13:40Z oboucher $
 !
+
 SUBROUTINE readaerosolstrato1_rrtm(debut)
 
@@ -9,7 +10,5 @@
 
     USE phys_cal_mod, ONLY : mth_cur
-    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo, grid_type, unstructured
     USE mod_phys_lmdz_para 
     USE phys_state_var_mod
@@ -19,4 +18,5 @@
     USE YOERAD, ONLY : NLW
     USE YOMCST
+    USE xios
 
     IMPLICIT NONE
@@ -45,4 +45,5 @@
     REAL, ALLOCATABLE:: tauaerstrat_mois(:, :, :)
     REAL, ALLOCATABLE:: tauaerstrat_mois_glo(:, :)
+    REAL, ALLOCATABLE:: tauaerstrat_mpi(:, :)
 
 ! For NetCDF:
@@ -102,18 +103,25 @@
     n_lat = size(latitude)
     print *, 'LAT aerosol strato=', n_lat, latitude
-    IF (n_lat.NE.nbp_lat) THEN 
-       print *,'Le nombre de lat n est pas egal a nbp_lat'
-       STOP
-    ENDIF
-
+
+    IF (grid_type/=unstructured) THEN
+      IF (n_lat.NE.nbp_lat) THEN 
+         print *,'Le nombre de lat n est pas egal a nbp_lat'
+         STOP
+      ENDIF
+    ENDIF
+    
     CALL nf95_inq_varid(ncid_in, "LON", varid)
     CALL nf95_gw_var(ncid_in, varid, longitude)
     n_lon = size(longitude)
     print *, 'LON aerosol strato=', n_lon, longitude
-    IF (n_lon.NE.nbp_lon) THEN 
-       print *,'Le nombre de lon n est pas egal a nbp_lon'
-       STOP
-    ENDIF
-
+
+    IF (grid_type/=unstructured) THEN
+      IF (n_lon.NE.nbp_lon) THEN 
+         print *,'Le nombre de lon n est pas egal a nbp_lon'
+         STOP
+      ENDIF
+    ENDIF
+    
+    
     CALL nf95_inq_varid(ncid_in, "TIME", varid)
     CALL nf95_gw_var(ncid_in, varid, time)
@@ -144,5 +152,7 @@
 !---reduce to a klon_glo grid 
     CALL grid2dTo1d_glo(tauaerstrat_mois,tauaerstrat_mois_glo)
-
+    
+    ELSE
+      ALLOCATE(tauaerstrat_mois(0,0,0))
     ENDIF !--is_mpi_root and is_omp_root
 
@@ -153,6 +163,18 @@
 
 !--scatter on all proc
-    CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
-
+    
+    IF (grid_type==unstructured) THEN
+      IF (is_omp_master) THEN
+        ALLOCATE(tauaerstrat_mpi(klon_mpi,klev))
+        CALL xios_send_field("taustrat_in",tauaerstrat_mois)
+        CALL xios_recv_field("taustrat_out",tauaerstrat_mpi)
+      ELSE
+        ALLOCATE(tauaerstrat_mpi(0,0))
+      ENDIF
+      CALL scatter_omp(tauaerstrat_mpi,tau_aer_strat)
+    ELSE  
+      CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
+    ENDIF
+    
     IF (is_mpi_root.AND.is_omp_root) THEN
 !
Index: /LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90	(revision 3435)
@@ -2,4 +2,5 @@
 ! $Id: readaerosolstrato2_rrtm.F90 2526 2016-05-26 22:13:40Z oboucher $
 !
+
 SUBROUTINE readaerosolstrato2_rrtm(debut)
 
@@ -9,7 +10,7 @@
 
     USE phys_cal_mod, ONLY : mth_cur
-    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo
-    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
-    USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo, grid_type, unstructured
+    USE mod_phys_lmdz_mpi_data
+    USE mod_phys_lmdz_omp_data
     USE mod_phys_lmdz_para 
     USE phys_state_var_mod
@@ -19,5 +20,5 @@
     USE YOERAD, ONLY : NLW
     USE YOMCST
-
+    USE xios
     IMPLICIT NONE
 
@@ -65,4 +66,8 @@
     REAL, ALLOCATABLE:: cgaerstrat_mois_glo(:, :, :)
     REAL, ALLOCATABLE:: taulwaerstrat_mois_glo(:, :, :)
+    REAL, ALLOCATABLE:: tauaerstrat_mpi(:, :, :)
+    REAL, ALLOCATABLE:: pizaerstrat_mpi(:, :, :)
+    REAL, ALLOCATABLE:: cgaerstrat_mpi(:, :, :)
+    REAL, ALLOCATABLE:: taulwaerstrat_mpi(:, :, :)
 
 ! For NetCDF:
@@ -107,8 +112,11 @@
         CALL nf95_gw_var(ncid_in, varid, latitude)
         n_lat = size(latitude)
-        IF (n_lat.NE.nbp_lat) THEN 
-           print *, 'latitude=', n_lat, nbp_lat
-           abort_message='Le nombre de lat n est pas egal a nbp_lat'
-           CALL abort_physic(modname,abort_message,1)
+
+        IF (grid_type/=unstructured) THEN
+           IF (n_lat.NE.nbp_lat) THEN 
+             print *, 'latitude=', n_lat, nbp_lat
+             abort_message='Le nombre de lat n est pas egal a nbp_lat'
+             CALL abort_physic(modname,abort_message,1)
+           ENDIF
         ENDIF
 
@@ -134,12 +142,4 @@
         ALLOCATE(cgaerstrat(n_lat, n_lev, n_wav, n_month))
 
-        ALLOCATE(tauaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-        ALLOCATE(pizaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-        ALLOCATE(cgaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-
-        ALLOCATE(tauaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-        ALLOCATE(pizaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-        ALLOCATE(cgaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-
 !--reading stratospheric aerosol tau per layer
         CALL nf95_inq_varid(ncid_in, "TAU_SUN", varid)
@@ -159,26 +159,36 @@
         CALL nf95_close(ncid_in)
 
+       
+        IF (grid_type/=unstructured) THEN
+          ALLOCATE(tauaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+          ALLOCATE(pizaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+          ALLOCATE(cgaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+
+          ALLOCATE(tauaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+          ALLOCATE(pizaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+          ALLOCATE(cgaerstrat_mois_glo(klon_glo, n_lev, n_wav))
 !--select the correct month
 !--and copy into 1st longitude
-        tauaerstrat_mois(1,:,:,:) = tauaerstrat(:,:,:,mth_cur)
-        pizaerstrat_mois(1,:,:,:) = pizaerstrat(:,:,:,mth_cur)
-        cgaerstrat_mois(1,:,:,:)  = cgaerstrat(:,:,:,mth_cur)
+          tauaerstrat_mois(1,:,:,:) = tauaerstrat(:,:,:,mth_cur)
+          pizaerstrat_mois(1,:,:,:) = pizaerstrat(:,:,:,mth_cur)
+          cgaerstrat_mois(1,:,:,:)  = cgaerstrat(:,:,:,mth_cur)
 
 !--copy longitudes
-        DO i=2, n_lon
-         tauaerstrat_mois(i,:,:,:) = tauaerstrat_mois(1,:,:,:)
-         pizaerstrat_mois(i,:,:,:) = pizaerstrat_mois(1,:,:,:)
-         cgaerstrat_mois(i,:,:,:)  = cgaerstrat_mois(1,:,:,:)
-        ENDDO
+          DO i=2, n_lon
+           tauaerstrat_mois(i,:,:,:) = tauaerstrat_mois(1,:,:,:)
+           pizaerstrat_mois(i,:,:,:) = pizaerstrat_mois(1,:,:,:)
+           cgaerstrat_mois(i,:,:,:)  = cgaerstrat_mois(1,:,:,:)
+          ENDDO
 
 !---reduce to a klon_glo grid 
-        DO band=1, NSW
-          CALL grid2dTo1d_glo(tauaerstrat_mois(:,:,:,band),tauaerstrat_mois_glo(:,:,band))
-          CALL grid2dTo1d_glo(pizaerstrat_mois(:,:,:,band),pizaerstrat_mois_glo(:,:,band))
-          CALL grid2dTo1d_glo(cgaerstrat_mois(:,:,:,band),cgaerstrat_mois_glo(:,:,band))
-        ENDDO
-
+          DO band=1, NSW
+            CALL grid2dTo1d_glo(tauaerstrat_mois(:,:,:,band),tauaerstrat_mois_glo(:,:,band))
+            CALL grid2dTo1d_glo(pizaerstrat_mois(:,:,:,band),pizaerstrat_mois_glo(:,:,band))
+            CALL grid2dTo1d_glo(cgaerstrat_mois(:,:,:,band),cgaerstrat_mois_glo(:,:,band))
+          ENDDO
+        ENDIF
 !--Now LW optical properties
 !
+
         CALL nf95_open("taulwstrat.2D.nc", nf90_nowrite, ncid_in)
 
@@ -194,9 +204,12 @@
         CALL nf95_gw_var(ncid_in, varid, latitude)
         n_lat = size(latitude)
-        IF (n_lat.NE.nbp_lat) THEN 
-           abort_message='Le nombre de lat n est pas egal a nbp_lat'
-           CALL abort_physic(modname,abort_message,1)
-        ENDIF
-
+
+        IF (grid_type/=unstructured) THEN
+          IF (n_lat.NE.nbp_lat) THEN 
+             abort_message='Le nombre de lat n est pas egal a nbp_lat'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+        ENDIF
+        
         CALL nf95_inq_varid(ncid_in, "TIME", varid)
         CALL nf95_gw_var(ncid_in, varid, time)
@@ -217,6 +230,4 @@
 
         ALLOCATE(taulwaerstrat(n_lat, n_lev, n_wav, n_month))
-        ALLOCATE(taulwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-        ALLOCATE(taulwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
 
 !--reading stratospheric aerosol lw tau per layer
@@ -227,17 +238,23 @@
         CALL nf95_close(ncid_in)
 
+        IF (grid_type/=unstructured) THEN
+
+          ALLOCATE(taulwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+          ALLOCATE(taulwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+
 !--select the correct month
 !--and copy into 1st longitude
-        taulwaerstrat_mois(1,:,:,:) = taulwaerstrat(:,:,:,mth_cur)
+          taulwaerstrat_mois(1,:,:,:) = taulwaerstrat(:,:,:,mth_cur)
 !--copy longitudes
-        DO i=2, n_lon
-          taulwaerstrat_mois(i,:,:,:) = taulwaerstrat_mois(1,:,:,:)
-        ENDDO
+          DO i=2, n_lon
+            taulwaerstrat_mois(i,:,:,:) = taulwaerstrat_mois(1,:,:,:)
+          ENDDO
 
 !---reduce to a klon_glo grid 
-        DO band=1, NLW
-          CALL grid2dTo1d_glo(taulwaerstrat_mois(:,:,:,band),taulwaerstrat_mois_glo(:,:,band))
-        ENDDO
-
+          DO band=1, NLW
+            CALL grid2dTo1d_glo(taulwaerstrat_mois(:,:,:,band),taulwaerstrat_mois_glo(:,:,band))
+          ENDDO
+        ENDIF
+      
       ELSE !--proc other than mpi_root and omp_root
            !--dummy allocation needed for debug mode
@@ -248,4 +265,10 @@
         ALLOCATE(taulwaerstrat_mois_glo(1,1,1))
 
+        ALLOCATE(tauaerstrat(0,0,0,12))
+        ALLOCATE(pizaerstrat(0,0,0,12))
+        ALLOCATE(cgaerstrat(0,0,0,12))
+        ALLOCATE(taulwaerstrat(0,0,0,12))
+
+
       ENDIF !--is_mpi_root and is_omp_root
 
@@ -255,20 +278,47 @@
       mth_pre=mth_cur
 
+      IF (grid_type==unstructured) THEN
+
+        IF (is_omp_master) THEN
+          ALLOCATE(tauaerstrat_mpi(klon_mpi, klev, NSW))
+          ALLOCATE(pizaerstrat_mpi(klon_mpi, klev, NSW))
+          ALLOCATE(cgaerstrat_mpi(klon_mpi, klev, NSW))        
+          ALLOCATE(taulwaerstrat_mpi(klon_mpi, klev, NLW))
+         
+          CALL xios_send_field("tauaerstrat_in",SPREAD(tauaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("tauaerstrat_out",tauaerstrat_mpi)
+          CALL xios_send_field("pizaerstrat_in",SPREAD(pizaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("pizaerstrat_out",pizaerstrat_mpi)
+          CALL xios_send_field("cgaerstrat_in",SPREAD(cgaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("cgaerstrat_out",cgaerstrat_mpi)
+          CALL xios_send_field("taulwaerstrat_in",SPREAD(taulwaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("taulwaerstrat_out",taulwaerstrat_mpi)
+        ELSE
+          ALLOCATE(tauaerstrat_mpi(0, 0, 0))
+          ALLOCATE(pizaerstrat_mpi(0, 0, 0))
+          ALLOCATE(cgaerstrat_mpi(0, 0, 0))        
+          ALLOCATE(taulwaerstrat_mpi(0, 0, 0))
+        ENDIF  
+        
+        CALL scatter_omp(tauaerstrat_mpi,tau_aer_strat)
+        CALL scatter_omp(pizaerstrat_mpi,piz_aer_strat)
+        CALL scatter_omp(cgaerstrat_mpi,cg_aer_strat)
+        CALL scatter_omp(taulwaerstrat_mpi,taulw_aer_strat)
+      ELSE  
+        
 !--scatter on all proc
-      CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
-      CALL scatter(pizaerstrat_mois_glo,piz_aer_strat)
-      CALL scatter(cgaerstrat_mois_glo,cg_aer_strat)
-      CALL scatter(taulwaerstrat_mois_glo,taulw_aer_strat)
+        CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
+        CALL scatter(pizaerstrat_mois_glo,piz_aer_strat)
+        CALL scatter(cgaerstrat_mois_glo,cg_aer_strat)
+        CALL scatter(taulwaerstrat_mois_glo,taulw_aer_strat)
+
+      ENDIF 
 
       IF (is_mpi_root.AND.is_omp_root) THEN
-!
-        DEALLOCATE(tauaerstrat, pizaerstrat, cgaerstrat)
         DEALLOCATE(tauaerstrat_mois, pizaerstrat_mois, cgaerstrat_mois)
-        DEALLOCATE(taulwaerstrat,taulwaerstrat_mois)
-!
-      ENDIF !--is_mpi_root and is_omp_root
-
-      DEALLOCATE(tauaerstrat_mois_glo,pizaerstrat_mois_glo,cgaerstrat_mois_glo)
-      DEALLOCATE(taulwaerstrat_mois_glo)
+        DEALLOCATE(taulwaerstrat_mois)
+        DEALLOCATE(tauaerstrat, pizaerstrat, cgaerstrat,taulwaerstrat)
+      ENDIF
+      
 
 !$OMP BARRIER
Index: /LMDZ6/trunk/libf/phylmd/rrtm/suinit.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/rrtm/suinit.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/rrtm/suinit.F90	(revision 3435)
@@ -126,5 +126,7 @@
 ALLOCATE(VDELA  (MAX(JPMXLE,NFLEVG)))
 ALLOCATE(VDELB  (MAX(JPMXLE,NFLEVG)))
+VDELB = 0  !ym missing init
 ALLOCATE( VC      (NFLEVG) )
+VC = 0    !ym missing init
 ALLOCATE( NLOEN   (NPROMA) )
 ALLOCATE( NLOENG   (NPROMA) )
Index: /LMDZ6/trunk/libf/phylmd/slab_heat_transp_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/slab_heat_transp_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/slab_heat_transp_mod.F90	(revision 3435)
@@ -83,6 +83,5 @@
                                   cu_,cuvsurcv_,cv_,cvusurcu_, &
                                   aire_,apoln_,apols_, &
-                                  aireu_,airev_,rlatv)
-    USE comconst_mod, ONLY: omeg, rad
+                                  aireu_,airev_,rlatv, rad, omeg)
     ! number of points in lon, lat
     IMPLICIT NONE
@@ -104,4 +103,6 @@
     REAL,INTENT(IN) :: airev_(ip1jm)
     REAL,INTENT(IN) :: rlatv(nbp_lat-1)
+    REAL,INTENT(IN) :: rad
+    REAL,INTENT(IN) :: omeg
 
     ! Sanity check on dimensions
Index: /LMDZ6/trunk/libf/phylmd/surf_land_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/surf_land_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/surf_land_mod.F90	(revision 3435)
@@ -41,5 +41,10 @@
     USE surf_land_orchidee_nofrein_mod
 #else
+#if ORCHIDEE_NOUNSTRUCT
+    ! Compilation with cpp key ORCHIDEE_NOUNSTRUCT
+    USE surf_land_orchidee_nounstruct_mod
+#else
     USE surf_land_orchidee_mod
+#endif
 #endif
 #endif
Index: /LMDZ6/trunk/libf/phylmd/surf_land_orchidee_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/surf_land_orchidee_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/surf_land_orchidee_mod.F90	(revision 3435)
@@ -4,4 +4,5 @@
 #ifndef ORCHIDEE_NOZ0H
 #ifndef ORCHIDEE_NOFREIN
+#ifndef ORCHIDEE_NOUNSTRUCT
 !
 ! This module controles the interface towards the model ORCHIDEE.
@@ -23,9 +24,10 @@
   USE cpl_mod,      ONLY : cpl_send_land_fields
   USE surface_data, ONLY : type_ocean
-  USE geometry_mod, ONLY : dx, dy
+  USE geometry_mod, ONLY : dx, dy, boundslon, boundslat,longitude, latitude, cell_area,  ind_cell_glo
   USE mod_grid_phy_lmdz
   USE mod_phys_lmdz_para, mpi_root_rank=>mpi_master
   USE carbon_cycle_mod, ONLY : nbcf_in_orc, nbcf_out, fields_in, yfields_in, yfields_out, cfname_in, cfname_out
-
+  USE nrtype, ONLY : PI
+  
   IMPLICIT NONE
 
@@ -165,4 +167,7 @@
     REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: lalo
     !$OMP THREADPRIVATE(lalo)
+! boundaries of cells
+    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE   :: bounds_lalo
+    !$OMP THREADPRIVATE(bounds_lalo)
 ! pts voisins
     INTEGER,ALLOCATABLE, DIMENSION(:,:), SAVE :: neighbours
@@ -178,4 +183,8 @@
     !$OMP THREADPRIVATE(lon_scat,lat_scat)
 
+! area of cells
+    REAL, ALLOCATABLE, DIMENSION (:), SAVE  :: area  
+    !$OMP THREADPRIVATE(area)
+
     LOGICAL, SAVE                             :: lrestart_read = .TRUE.
     !$OMP THREADPRIVATE(lrestart_read)
@@ -209,6 +218,17 @@
     !$OMP THREADPRIVATE(riverflow)
     
+    INTEGER :: orch_mpi_rank
+    INTEGER :: orch_mpi_size
     INTEGER :: orch_omp_rank
     INTEGER :: orch_omp_size
+
+    REAL, ALLOCATABLE, DIMENSION(:)         :: longitude_glo
+    REAL, ALLOCATABLE, DIMENSION(:)         :: latitude_glo
+    REAL, ALLOCATABLE, DIMENSION(:,:)       :: boundslon_glo
+    REAL, ALLOCATABLE, DIMENSION(:,:)       :: boundslat_glo
+    INTEGER, ALLOCATABLE, DIMENSION(:)      :: ind_cell_glo_glo
+    INTEGER, ALLOCATABLE, SAVE,DIMENSION(:) :: ind_cell
+    !$OMP THREADPRIVATE(ind_cell)
+    INTEGER :: begin, end
 !
 ! Fin definition
@@ -253,66 +273,123 @@
        jg(klon) = nbp_lat
 
-       IF ((.NOT. ALLOCATED(lalo))) THEN
-          ALLOCATE(lalo(knon,2), stat = error)
+       IF ((.NOT. ALLOCATED(area))) THEN
+          ALLOCATE(area(knon), stat = error)
           IF (error /= 0) THEN
+             abort_message='Pb allocation area'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       DO igrid = 1, knon
+          area(igrid) = cell_area(knindex(igrid))
+       ENDDO
+       
+       IF (grid_type==unstructured) THEN
+
+
+         IF ((.NOT. ALLOCATED(lon_scat))) THEN
+            ALLOCATE(lon_scat(nbp_lon,nbp_lat), stat = error)
+            IF (error /= 0) THEN
+               abort_message='Pb allocation lon_scat'
+               CALL abort_physic(modname,abort_message,1)
+            ENDIF
+         ENDIF
+ 
+         IF ((.NOT. ALLOCATED(lat_scat))) THEN
+            ALLOCATE(lat_scat(nbp_lon,nbp_lat), stat = error)
+            IF (error /= 0) THEN
+               abort_message='Pb allocation lat_scat'
+               CALL abort_physic(modname,abort_message,1)
+            ENDIF
+         ENDIF
+         CALL Gather(rlon,rlon_g)
+         CALL Gather(rlat,rlat_g)
+
+         IF (is_mpi_root) THEN
+            index = 1
+            DO jj = 2, nbp_lat-1
+               DO ij = 1, nbp_lon
+                  index = index + 1
+                  lon_scat(ij,jj) = rlon_g(index)
+                  lat_scat(ij,jj) = rlat_g(index)
+               ENDDO
+            ENDDO
+            lon_scat(:,1) = lon_scat(:,2)
+            lat_scat(:,1) = rlat_g(1)
+            lon_scat(:,nbp_lat) = lon_scat(:,2)
+            lat_scat(:,nbp_lat) = rlat_g(klon_glo)
+         ENDIF
+     
+         CALL bcast(lon_scat)
+         CALL bcast(lat_scat)
+                
+       ELSE IF (grid_type==regular_lonlat) THEN
+
+         IF ((.NOT. ALLOCATED(lalo))) THEN
+            ALLOCATE(lalo(knon,2), stat = error)
+            IF (error /= 0) THEN
+               abort_message='Pb allocation lalo'
+               CALL abort_physic(modname,abort_message,1)
+            ENDIF
+         ENDIF
+       
+         IF ((.NOT. ALLOCATED(bounds_lalo))) THEN
+           ALLOCATE(bounds_lalo(knon,nvertex,2), stat = error)
+           IF (error /= 0) THEN
              abort_message='Pb allocation lalo'
              CALL abort_physic(modname,abort_message,1)
-          ENDIF
-       ENDIF
-       IF ((.NOT. ALLOCATED(lon_scat))) THEN
-          ALLOCATE(lon_scat(nbp_lon,nbp_lat), stat = error)
-          IF (error /= 0) THEN
-             abort_message='Pb allocation lon_scat'
-             CALL abort_physic(modname,abort_message,1)
-          ENDIF
-       ENDIF
-       IF ((.NOT. ALLOCATED(lat_scat))) THEN
-          ALLOCATE(lat_scat(nbp_lon,nbp_lat), stat = error)
-          IF (error /= 0) THEN
-             abort_message='Pb allocation lat_scat'
-             CALL abort_physic(modname,abort_message,1)
-          ENDIF
-       ENDIF
-       lon_scat = 0.
-       lat_scat = 0.
-       DO igrid = 1, knon
-          index = knindex(igrid)
-          lalo(igrid,2) = rlon(index)
-          lalo(igrid,1) = rlat(index)
-       ENDDO
-
-       
-       
-       CALL Gather(rlon,rlon_g)
-       CALL Gather(rlat,rlat_g)
-
-       IF (is_mpi_root) THEN
-          index = 1
-          DO jj = 2, nbp_lat-1
-             DO ij = 1, nbp_lon
-                index = index + 1
-                lon_scat(ij,jj) = rlon_g(index)
-                lat_scat(ij,jj) = rlat_g(index)
-             ENDDO
-          ENDDO
-          lon_scat(:,1) = lon_scat(:,2)
-          lat_scat(:,1) = rlat_g(1)
-          lon_scat(:,nbp_lat) = lon_scat(:,2)
-          lat_scat(:,nbp_lat) = rlat_g(klon_glo)
-       ENDIF
+           ENDIF
+         ENDIF
+       
+         IF ((.NOT. ALLOCATED(lon_scat))) THEN
+            ALLOCATE(lon_scat(nbp_lon,nbp_lat), stat = error)
+            IF (error /= 0) THEN
+               abort_message='Pb allocation lon_scat'
+               CALL abort_physic(modname,abort_message,1)
+            ENDIF
+         ENDIF
+         IF ((.NOT. ALLOCATED(lat_scat))) THEN
+            ALLOCATE(lat_scat(nbp_lon,nbp_lat), stat = error)
+            IF (error /= 0) THEN
+               abort_message='Pb allocation lat_scat'
+               CALL abort_physic(modname,abort_message,1)
+            ENDIF
+         ENDIF
+         lon_scat = 0.
+         lat_scat = 0.
+         DO igrid = 1, knon
+            index = knindex(igrid)
+            lalo(igrid,2) = rlon(index)
+            lalo(igrid,1) = rlat(index)
+            bounds_lalo(igrid,:,2)=boundslon(index,:)*180./PI
+            bounds_lalo(igrid,:,1)=boundslat(index,:)*180./PI
+         ENDDO
+
+       
+       
+         CALL Gather(rlon,rlon_g)
+         CALL Gather(rlat,rlat_g)
+
+         IF (is_mpi_root) THEN
+            index = 1
+            DO jj = 2, nbp_lat-1
+               DO ij = 1, nbp_lon
+                  index = index + 1
+                  lon_scat(ij,jj) = rlon_g(index)
+                  lat_scat(ij,jj) = rlat_g(index)
+               ENDDO
+            ENDDO
+            lon_scat(:,1) = lon_scat(:,2)
+            lat_scat(:,1) = rlat_g(1)
+            lon_scat(:,nbp_lat) = lon_scat(:,2)
+            lat_scat(:,nbp_lat) = rlat_g(klon_glo)
+         ENDIF
    
-       CALL bcast(lon_scat)
-       CALL bcast(lat_scat)
+         CALL bcast(lon_scat)
+         CALL bcast(lat_scat)
+       
+       ENDIF
 !
 ! Allouer et initialiser le tableau des voisins et des fraction de continents
 !
-       IF ( (.NOT.ALLOCATED(neighbours))) THEN
-          ALLOCATE(neighbours(knon,8), stat = error)
-          IF (error /= 0) THEN
-             abort_message='Pb allocation neighbours'
-             CALL abort_physic(modname,abort_message,1)
-          ENDIF
-       ENDIF
-       neighbours = -1.
        IF (( .NOT. ALLOCATED(contfrac))) THEN
           ALLOCATE(contfrac(knon), stat = error)
@@ -329,5 +406,29 @@
 
 
-       CALL Init_neighbours(knon,neighbours,knindex,pctsrf(:,is_ter))
+       IF (grid_type==regular_lonlat) THEN
+ 
+         IF ( (.NOT.ALLOCATED(neighbours))) THEN
+          ALLOCATE(neighbours(knon,8), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation neighbours'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+         ENDIF
+         neighbours = -1.
+         CALL Init_neighbours(knon,neighbours,knindex,pctsrf(:,is_ter))
+
+       ELSE IF (grid_type==unstructured) THEN
+ 
+         IF ( (.NOT.ALLOCATED(neighbours))) THEN
+          ALLOCATE(neighbours(knon,12), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation neighbours'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+         ENDIF
+         neighbours = -1.
+ 
+       ENDIF
+         
 
 !
@@ -340,10 +441,13 @@
           ENDIF
        ENDIF
-       DO igrid = 1, knon
-          ij = knindex(igrid)
-          resolution(igrid,1) = dx(ij)
-          resolution(igrid,2) = dy(ij)
-       ENDDO
-     
+       
+       IF (grid_type==regular_lonlat) THEN
+         DO igrid = 1, knon
+            ij = knindex(igrid)
+            resolution(igrid,1) = dx(ij)
+           resolution(igrid,2) = dy(ij)
+         ENDDO
+       ENDIF
+        
        ALLOCATE(coastalflow(klon), stat = error)
        IF (error /= 0) THEN
@@ -397,18 +501,61 @@
     IF (debut) THEN
        CALL Init_orchidee_index(knon,knindex,offset,ktindex)
-       CALL Get_orchidee_communicator(orch_comm,orch_omp_size,orch_omp_rank)
+       CALL Get_orchidee_communicator(orch_comm,orch_mpi_size,orch_mpi_rank, orch_omp_size,orch_omp_rank)
+
+       IF (grid_type==unstructured) THEN
+         IF (knon==0) THEN
+           begin=1
+           end=0
+         ELSE
+           begin=offset+1
+           end=offset+ktindex(knon)
+         ENDIF
+        
+         IF (orch_mpi_rank==orch_mpi_size-1 .AND. orch_omp_rank==orch_omp_size-1) end=nbp_lon*nbp_lat 
+          
+         ALLOCATE(lalo(end-begin+1,2))
+         ALLOCATE(bounds_lalo(end-begin+1,nvertex,2))
+         ALLOCATE(ind_cell(end-begin+1))
+         
+         ALLOCATE(longitude_glo(klon_glo))
+         CALL gather(longitude,longitude_glo)
+         CALL bcast(longitude_glo)
+         lalo(:,2)=longitude_glo(begin:end)*180./PI
+ 
+         ALLOCATE(latitude_glo(klon_glo))
+         CALL gather(latitude,latitude_glo)
+         CALL bcast(latitude_glo)
+         lalo(:,1)=latitude_glo(begin:end)*180./PI
+
+         ALLOCATE(boundslon_glo(klon_glo,nvertex))
+         CALL gather(boundslon,boundslon_glo)
+         CALL bcast(boundslon_glo)
+         bounds_lalo(:,:,2)=boundslon_glo(begin:end,:)*180./PI
+ 
+         ALLOCATE(boundslat_glo(klon_glo,nvertex))
+         CALL gather(boundslat,boundslat_glo)
+         CALL bcast(boundslat_glo)
+         bounds_lalo(:,:,1)=boundslat_glo(begin:end,:)*180./PI
+         
+         ALLOCATE(ind_cell_glo_glo(klon_glo))
+         CALL gather(ind_cell_glo,ind_cell_glo_glo)
+         CALL bcast(ind_cell_glo_glo)
+         ind_cell(:)=ind_cell_glo_glo(begin:end)
+         
+       ENDIF
        CALL Init_synchro_omp
        
        IF (knon > 0) THEN
 #ifdef CPP_VEGET
-         CALL Init_intersurf(nbp_lon,nbp_lat,knon,ktindex,offset,orch_omp_size,orch_omp_rank,orch_comm)
+         CALL Init_intersurf(nbp_lon,nbp_lat,knon,ktindex,offset,orch_omp_size,orch_omp_rank,orch_comm,grid=grid_type)
 #endif
        ENDIF
 
        
-       IF (knon > 0) THEN
+       IF (knon > 0) THEN 
 
          print *,'OB before intersurf=', SIZE(cfname_in), SIZE(cfname_out)
 #ifdef CPP_VEGET
+
          CALL intersurf_initialize_gathered (itime+itau_phy-1, nbp_lon, nbp_lat, knon, ktindex, dtime, &
                lrestart_read, lrestart_write, lalo, contfrac, neighbours, resolution, date0, &
@@ -418,9 +565,7 @@
                evap, fluxsens, fluxlat, coastalflow, riverflow, &
                tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0m_new, &    
-! >> PC
-               !lon_scat, lat_scat, q2m, t2m, z0h_new, nvm_orch)
-               lon_scat, lat_scat, q2m, t2m, z0h_new, nvm_orch, &
+               lon_scat, lat_scat, q2m(1:knon), t2m(1:knon), z0h_new(1:knon), nvm_orch, &
+               grid=grid_type, bounds_latlon=bounds_lalo, cell_area=area, ind_cell_glo=ind_cell, &
                field_out_names=cfname_out, field_in_names=cfname_in(1:nbcf_in_orc))
-! << PC
 #endif         
        ENDIF
@@ -450,5 +595,5 @@
             evap(1:knon), fluxsens(1:knon), fluxlat(1:knon), coastalflow(1:knon), riverflow(1:knon), &
             tsol_rad(1:knon), tsurf_new(1:knon), qsurf(1:knon), albedo_out(1:knon,:), emis_new(1:knon), z0m_new(1:knon), &
-            lon_scat, lat_scat, q2m, t2m, z0h_new(1:knon),&
+            lon_scat, lat_scat, q2m(1:knon), t2m(1:knon), z0h_new(1:knon),&
             veget(1:knon,:),lai(1:knon,:),height(1:knon,:),&
             fields_out=yfields_out(1:knon,1:nbcf_out),  &
@@ -542,5 +687,5 @@
 ! 
 
-  SUBROUTINE Get_orchidee_communicator(orch_comm,orch_omp_size,orch_omp_rank)
+  SUBROUTINE Get_orchidee_communicator(orch_comm, orch_mpi_size, orch_mpi_rank, orch_omp_size,orch_omp_rank)
   USE  mod_surf_para
       
@@ -550,4 +695,6 @@
 
     INTEGER,INTENT(OUT) :: orch_comm
+    INTEGER,INTENT(OUT) :: orch_mpi_size
+    INTEGER,INTENT(OUT) :: orch_mpi_rank
     INTEGER,INTENT(OUT) :: orch_omp_size
     INTEGER,INTENT(OUT) :: orch_omp_rank
@@ -568,4 +715,6 @@
 #ifdef CPP_MPI    
       CALL MPI_COMM_SPLIT(COMM_LMDZ_PHY,color,mpi_rank,orch_comm,ierr)
+      CALL MPI_COMM_SIZE(orch_comm,orch_mpi_size,ierr)
+      CALL MPI_COMM_RANK(orch_comm,orch_mpi_rank,ierr)
 #endif
     
@@ -696,3 +845,4 @@
 #endif
 #endif
+#endif
 END MODULE surf_land_orchidee_mod
Index: /LMDZ6/trunk/libf/phylmd/surf_land_orchidee_nounstruct_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/surf_land_orchidee_nounstruct_mod.F90	(revision 3435)
+++ /LMDZ6/trunk/libf/phylmd/surf_land_orchidee_nounstruct_mod.F90	(revision 3435)
@@ -0,0 +1,680 @@
+!
+MODULE surf_land_orchidee_nounstruct_mod
+#ifdef ORCHIDEE_NOUNSTRUCT
+!
+! This module controles the interface towards the model ORCHIDEE.
+!
+! Compatibility with ORCHIDIEE :
+! The current version can be used with ORCHIDEE/trunk from revision xxxx.
+! This module is compiled only if cpp key ORCHIDEE_NOUNSTRUCT is defined.
+!
+! Subroutines in this module : surf_land_orchidee
+!                              Init_orchidee_index
+!                              Get_orchidee_communicator
+!                              Init_neighbours
+
+  USE dimphy
+#ifdef CPP_VEGET
+  USE intersurf     ! module d'ORCHIDEE
+#endif
+  USE cpl_mod,      ONLY : cpl_send_land_fields
+  USE surface_data, ONLY : type_ocean
+  USE geometry_mod, ONLY : dx, dy
+  USE mod_grid_phy_lmdz
+  USE mod_phys_lmdz_para, mpi_root_rank=>mpi_master
+
+  IMPLICIT NONE
+
+  PRIVATE
+  PUBLIC  :: surf_land_orchidee
+
+CONTAINS
+!
+!****************************************************************************************
+!  
+  SUBROUTINE surf_land_orchidee(itime, dtime, date0, knon, &
+       knindex, rlon, rlat, yrmu0, pctsrf, &
+       debut, lafin, &
+       plev,  u1_lay, v1_lay, gustiness, temp_air, spechum, epot_air, ccanopy, & 
+       tq_cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
+       precip_rain, precip_snow, lwdown, swnet, swdown, &
+       ps, q2m, t2m, &
+       evap, fluxsens, fluxlat, &              
+       tsol_rad, tsurf_new, alb1_new, alb2_new, &
+       emis_new, z0m_new, z0h_new, qsurf, &
+       veget, lai, height )
+
+
+    USE mod_surf_para
+    USE mod_synchro_omp
+    USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
+    USE indice_sol_mod
+    USE print_control_mod, ONLY: lunout
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat
+#ifdef CPP_VEGET
+    USE time_phylmdz_mod, ONLY: itau_phy 
+#endif
+!    
+! Cette routine sert d'interface entre le modele atmospherique et le 
+! modele de sol continental. Appel a sechiba
+!
+! L. Fairhead 02/2000
+!
+! input:
+!   itime        numero du pas de temps
+!   dtime        pas de temps de la physique (en s)
+!   nisurf       index de la surface a traiter (1 = sol continental)
+!   knon         nombre de points de la surface a traiter
+!   knindex      index des points de la surface a traiter
+!   rlon         longitudes de la grille entiere
+!   rlat         latitudes de la grille entiere
+!   pctsrf       tableau des fractions de surface de chaque maille
+!   debut        logical: 1er appel a la physique (lire les restart)
+!   lafin        logical: dernier appel a la physique (ecrire les restart)
+!                     (si false calcul simplifie des fluxs sur les continents)
+!   plev         hauteur de la premiere couche (Pa)      
+!   u1_lay       vitesse u 1ere couche
+!   v1_lay       vitesse v 1ere couche
+!   temp_air     temperature de l'air 1ere couche
+!   spechum      humidite specifique 1ere couche
+!   epot_air     temp pot de l'air
+!   ccanopy      concentration CO2 canopee, correspond au co2_send de 
+!                carbon_cycle_mod ou valeur constant co2_ppm
+!   tq_cdrag     cdrag
+!   petAcoef     coeff. A de la resolution de la CL pour t
+!   peqAcoef     coeff. A de la resolution de la CL pour q
+!   petBcoef     coeff. B de la resolution de la CL pour t
+!   peqBcoef     coeff. B de la resolution de la CL pour q
+!   precip_rain  precipitation liquide
+!   precip_snow  precipitation solide
+!   lwdown       flux IR descendant a la surface
+!   swnet        flux solaire net
+!   swdown       flux solaire entrant a la surface
+!   ps           pression au sol
+!   radsol       rayonnement net aus sol (LW + SW)
+!   
+!
+! output:
+!   evap         evaporation totale
+!   fluxsens     flux de chaleur sensible
+!   fluxlat      flux de chaleur latente
+!   tsol_rad     
+!   tsurf_new    temperature au sol
+!   alb1_new     albedo in visible SW interval
+!   alb2_new     albedo in near IR interval
+!   emis_new     emissivite
+!   z0m_new      surface roughness for momentum
+!   z0h_new      surface roughness for heat
+!   qsurf        air moisture at surface
+!
+    INCLUDE "YOMCST.h"
+    INCLUDE "dimpft.h"
+
+
+  
+!
+! Parametres d'entree
+!****************************************************************************************
+    INTEGER, INTENT(IN)                       :: itime
+    REAL, INTENT(IN)                          :: dtime
+    REAL, INTENT(IN)                          :: date0
+    INTEGER, INTENT(IN)                       :: knon
+    INTEGER, DIMENSION(klon), INTENT(IN)      :: knindex
+    LOGICAL, INTENT(IN)                       :: debut, lafin
+    REAL, DIMENSION(klon,nbsrf), INTENT(IN)   :: pctsrf
+    REAL, DIMENSION(klon), INTENT(IN)         :: rlon, rlat
+    REAL, DIMENSION(klon), INTENT(IN)         :: yrmu0 ! cosine of solar zenith angle
+    REAL, DIMENSION(klon), INTENT(IN)         :: plev
+    REAL, DIMENSION(klon), INTENT(IN)         :: u1_lay, v1_lay, gustiness
+    REAL, DIMENSION(klon), INTENT(IN)         :: temp_air, spechum
+    REAL, DIMENSION(klon), INTENT(IN)         :: epot_air, ccanopy
+    REAL, DIMENSION(klon), INTENT(IN)         :: tq_cdrag
+    REAL, DIMENSION(klon), INTENT(IN)         :: petAcoef, peqAcoef
+    REAL, DIMENSION(klon), INTENT(IN)         :: petBcoef, peqBcoef
+    REAL, DIMENSION(klon), INTENT(IN)         :: precip_rain, precip_snow
+    REAL, DIMENSION(klon), INTENT(IN)         :: lwdown, swnet, swdown, ps
+    REAL, DIMENSION(klon), INTENT(IN)         :: q2m, t2m
+
+! Parametres de sortie
+!****************************************************************************************
+    REAL, DIMENSION(klon), INTENT(OUT)        :: evap, fluxsens, fluxlat, qsurf
+    REAL, DIMENSION(klon), INTENT(OUT)        :: tsol_rad, tsurf_new
+    REAL, DIMENSION(klon), INTENT(OUT)        :: alb1_new, alb2_new
+    REAL, DIMENSION(klon), INTENT(OUT)        :: emis_new, z0m_new, z0h_new
+    REAL, DIMENSION(klon,nvm_lmdz), INTENT(OUT) :: veget
+    REAL, DIMENSION(klon,nvm_lmdz), INTENT(OUT) :: lai
+    REAL, DIMENSION(klon,nvm_lmdz), INTENT(OUT) :: height
+
+
+! Local
+!****************************************************************************************
+    INTEGER                                   :: ij, jj, igrid, ireal, index
+    INTEGER                                   :: error
+    REAL, DIMENSION(klon)                     :: swdown_vrai
+    CHARACTER (len = 20)                      :: modname = 'surf_land_orchidee'
+    CHARACTER (len = 80)                      :: abort_message
+    LOGICAL,SAVE                              :: check = .FALSE.
+    !$OMP THREADPRIVATE(check)
+
+! type de couplage dans sechiba
+!  character (len=10)   :: coupling = 'implicit' 
+! drapeaux controlant les appels dans SECHIBA
+!  type(control_type), save   :: control_in
+! Preserved albedo
+    REAL, ALLOCATABLE, DIMENSION(:), SAVE     :: albedo_keep, zlev
+    !$OMP THREADPRIVATE(albedo_keep,zlev)
+! coordonnees geographiques
+    REAL, ALLOCATABLE, DIMENSION(:,:), SAVE   :: lalo
+    !$OMP THREADPRIVATE(lalo)
+! pts voisins
+    INTEGER,ALLOCATABLE, DIMENSION(:,:), SAVE :: neighbours
+    !$OMP THREADPRIVATE(neighbours)
+! fractions continents
+    REAL,ALLOCATABLE, DIMENSION(:), SAVE      :: contfrac
+    !$OMP THREADPRIVATE(contfrac)
+! resolution de la grille
+    REAL, ALLOCATABLE, DIMENSION (:,:), SAVE  :: resolution
+    !$OMP THREADPRIVATE(resolution)
+
+    REAL, ALLOCATABLE, DIMENSION (:,:), SAVE  :: lon_scat, lat_scat  
+    !$OMP THREADPRIVATE(lon_scat,lat_scat)
+
+    LOGICAL, SAVE                             :: lrestart_read = .TRUE.
+    !$OMP THREADPRIVATE(lrestart_read)
+    LOGICAL, SAVE                             :: lrestart_write = .FALSE.
+    !$OMP THREADPRIVATE(lrestart_write)
+
+    REAL, DIMENSION(knon,2)                   :: albedo_out
+
+! Pb de nomenclature
+    REAL, DIMENSION(klon)                     :: petA_orc, peqA_orc
+    REAL, DIMENSION(klon)                     :: petB_orc, peqB_orc
+! Pb de correspondances de grilles
+    INTEGER, DIMENSION(:), SAVE, ALLOCATABLE  :: ig, jg
+    !$OMP THREADPRIVATE(ig,jg)
+    INTEGER :: indi, indj
+    INTEGER, SAVE, ALLOCATABLE,DIMENSION(:)   :: ktindex
+    !$OMP THREADPRIVATE(ktindex)
+
+! Essai cdrag
+    REAL, DIMENSION(klon)                     :: cdrag
+    INTEGER,SAVE                              :: offset
+    !$OMP THREADPRIVATE(offset)
+
+    REAL, DIMENSION(klon_glo)                 :: rlon_g,rlat_g
+    INTEGER, SAVE                             :: orch_comm
+    !$OMP THREADPRIVATE(orch_comm)
+
+    REAL, ALLOCATABLE, DIMENSION(:), SAVE     :: coastalflow
+    !$OMP THREADPRIVATE(coastalflow)
+    REAL, ALLOCATABLE, DIMENSION(:), SAVE     :: riverflow
+    !$OMP THREADPRIVATE(riverflow)
+    
+    INTEGER :: orch_omp_rank
+    INTEGER :: orch_omp_size
+!
+! Fin definition
+!****************************************************************************************
+
+    IF (check) WRITE(lunout,*)'Entree ', modname
+  
+! Initialisation
+  
+    IF (debut) THEN
+! Test of coherence between variable ok_veget and cpp key CPP_VEGET
+#ifndef CPP_VEGET
+       abort_message='Pb de coherence: ok_veget = .true. mais CPP_VEGET = .false.'
+       CALL abort_physic(modname,abort_message,1)
+#endif
+
+       CALL Init_surf_para(knon)
+       ALLOCATE(ktindex(knon))
+       IF ( .NOT. ALLOCATED(albedo_keep)) THEN
+!ym          ALLOCATE(albedo_keep(klon))
+!ym bizarre que non alloué en knon precedement
+          ALLOCATE(albedo_keep(knon))
+          ALLOCATE(zlev(knon))
+       ENDIF
+! Pb de correspondances de grilles
+       ALLOCATE(ig(klon))
+       ALLOCATE(jg(klon))
+       ig(1) = 1
+       jg(1) = 1
+       indi = 0
+       indj = 2
+       DO igrid = 2, klon - 1
+          indi = indi + 1
+          IF ( indi > nbp_lon) THEN
+             indi = 1
+             indj = indj + 1
+          ENDIF
+          ig(igrid) = indi
+          jg(igrid) = indj
+       ENDDO
+       ig(klon) = 1
+       jg(klon) = nbp_lat
+
+       IF ((.NOT. ALLOCATED(lalo))) THEN
+          ALLOCATE(lalo(knon,2), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation lalo'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       IF ((.NOT. ALLOCATED(lon_scat))) THEN
+          ALLOCATE(lon_scat(nbp_lon,nbp_lat), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation lon_scat'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       IF ((.NOT. ALLOCATED(lat_scat))) THEN
+          ALLOCATE(lat_scat(nbp_lon,nbp_lat), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation lat_scat'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       lon_scat = 0.
+       lat_scat = 0.
+       DO igrid = 1, knon
+          index = knindex(igrid)
+          lalo(igrid,2) = rlon(index)
+          lalo(igrid,1) = rlat(index)
+       ENDDO
+
+       
+       
+       CALL Gather(rlon,rlon_g)
+       CALL Gather(rlat,rlat_g)
+
+       IF (is_mpi_root) THEN
+          index = 1
+          DO jj = 2, nbp_lat-1
+             DO ij = 1, nbp_lon
+                index = index + 1
+                lon_scat(ij,jj) = rlon_g(index)
+                lat_scat(ij,jj) = rlat_g(index)
+             ENDDO
+          ENDDO
+          lon_scat(:,1) = lon_scat(:,2)
+          lat_scat(:,1) = rlat_g(1)
+          lon_scat(:,nbp_lat) = lon_scat(:,2)
+          lat_scat(:,nbp_lat) = rlat_g(klon_glo)
+       ENDIF
+   
+       CALL bcast(lon_scat)
+       CALL bcast(lat_scat)
+!
+! Allouer et initialiser le tableau des voisins et des fraction de continents
+!
+       IF ( (.NOT.ALLOCATED(neighbours))) THEN
+          ALLOCATE(neighbours(knon,8), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation neighbours'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       neighbours = -1.
+       IF (( .NOT. ALLOCATED(contfrac))) THEN
+          ALLOCATE(contfrac(knon), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation contfrac'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+
+       DO igrid = 1, knon
+          ireal = knindex(igrid)
+          contfrac(igrid) = pctsrf(ireal,is_ter)
+       ENDDO
+
+
+       CALL Init_neighbours(knon,neighbours,knindex,pctsrf(:,is_ter))
+
+!
+!  Allocation et calcul resolutions
+       IF ( (.NOT.ALLOCATED(resolution))) THEN
+          ALLOCATE(resolution(knon,2), stat = error)
+          IF (error /= 0) THEN
+             abort_message='Pb allocation resolution'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+       ENDIF
+       DO igrid = 1, knon
+          ij = knindex(igrid)
+          resolution(igrid,1) = dx(ij)
+          resolution(igrid,2) = dy(ij)
+       ENDDO
+     
+       ALLOCATE(coastalflow(klon), stat = error)
+       IF (error /= 0) THEN
+          abort_message='Pb allocation coastalflow'
+          CALL abort_physic(modname,abort_message,1)
+       ENDIF
+       
+       ALLOCATE(riverflow(klon), stat = error)
+       IF (error /= 0) THEN
+          abort_message='Pb allocation riverflow'
+          CALL abort_physic(modname,abort_message,1)
+       ENDIF
+!
+! carbon_cycle_cpl not possible with this interface and version of ORHCHIDEE
+!
+       IF (carbon_cycle_cpl) THEN
+          abort_message='carbon_cycle_cpl not yet possible with this interface of ORCHIDEE'
+          CALL abort_physic(modname,abort_message,1)
+       END IF
+       
+    ENDIF                          ! (fin debut) 
+ 
+
+! 
+! Appel a la routine sols continentaux
+!
+    IF (lafin) lrestart_write = .TRUE.
+    IF (check) WRITE(lunout,*)'lafin ',lafin,lrestart_write
+     
+    petA_orc(1:knon) = petBcoef(1:knon) * dtime
+    petB_orc(1:knon) = petAcoef(1:knon)
+    peqA_orc(1:knon) = peqBcoef(1:knon) * dtime
+    peqB_orc(1:knon) = peqAcoef(1:knon)
+
+    cdrag = 0.
+    cdrag(1:knon) = tq_cdrag(1:knon)
+
+! zlev(1:knon) = (100.*plev(1:knon))/((ps(1:knon)/287.05*temp_air(1:knon))*9.80665)
+!    zlev(1:knon) = (100.*plev(1:knon))/((ps(1:knon)/RD*temp_air(1:knon))*RG)
+     zlev(1:knon) = plev(1:knon)*RD*temp_air(1:knon)/((ps(1:knon)*100.0)*RG)
+
+
+! PF et PASB
+!   where(cdrag > 0.01) 
+!     cdrag = 0.01
+!   endwhere
+!  write(*,*)'Cdrag = ',minval(cdrag),maxval(cdrag)
+
+  
+    IF (debut) THEN
+       CALL Init_orchidee_index(knon,knindex,offset,ktindex)
+       CALL Get_orchidee_communicator(orch_comm,orch_omp_size,orch_omp_rank)
+       CALL Init_synchro_omp
+       
+       IF (knon > 0) THEN
+#ifdef CPP_VEGET
+         CALL Init_intersurf(nbp_lon,nbp_lat,knon,ktindex,offset,orch_omp_size,orch_omp_rank,orch_comm)
+#endif
+       ENDIF
+
+       
+       IF (knon > 0) THEN
+
+#ifdef CPP_VEGET
+         CALL intersurf_initialize_gathered (itime+itau_phy-1, nbp_lon, nbp_lat, knon, ktindex, dtime, &
+               lrestart_read, lrestart_write, lalo, contfrac, neighbours, resolution, date0, &
+               zlev,  u1_lay, v1_lay, spechum, temp_air, epot_air, &
+               cdrag, petA_orc, peqA_orc, petB_orc, peqB_orc, &
+               precip_rain, precip_snow, lwdown, swnet, swdown, ps, &
+               evap, fluxsens, fluxlat, coastalflow, riverflow, &
+               tsol_rad, tsurf_new, qsurf, albedo_out, emis_new, z0m_new, &    
+               lon_scat, lat_scat, q2m, t2m, z0h_new, nvm_orch)
+#endif         
+       ENDIF
+
+       CALL Synchro_omp
+
+       albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
+
+    ENDIF
+
+    
+!  swdown_vrai(1:knon) = swnet(1:knon)/(1. - albedo_keep(1:knon))
+    swdown_vrai(1:knon) = swdown(1:knon)
+
+    IF (knon > 0) THEN
+#ifdef CPP_VEGET    
+       IF (nvm_orch .NE. nvm_lmdz ) THEN
+          abort_message='Pb de dimensiosn PFT: nvm_orch et nvm_lmdz differents.'
+          CALL abort_physic(modname,abort_message,1)
+       ENDIF
+
+       CALL intersurf_main_gathered (itime+itau_phy, nbp_lon, nbp_lat, knon, ktindex, dtime,  &
+            lrestart_read, lrestart_write, lalo, &
+            contfrac, neighbours, resolution, date0, &
+            zlev,  u1_lay(1:knon), v1_lay(1:knon), spechum(1:knon), temp_air(1:knon), epot_air(1:knon), ccanopy(1:knon), &
+            cdrag(1:knon), petA_orc(1:knon), peqA_orc(1:knon), petB_orc(1:knon), peqB_orc(1:knon), &
+            precip_rain(1:knon), precip_snow(1:knon), lwdown(1:knon), swnet(1:knon), swdown_vrai(1:knon), ps(1:knon), &
+            evap(1:knon), fluxsens(1:knon), fluxlat(1:knon), coastalflow(1:knon), riverflow(1:knon), &
+            tsol_rad(1:knon), tsurf_new(1:knon), qsurf(1:knon), albedo_out(1:knon,:), emis_new(1:knon), z0m_new(1:knon), &
+            lon_scat, lat_scat, q2m, t2m, z0h_new(1:knon),&
+            veget(1:knon,:),lai(1:knon,:),height(1:knon,:),&
+            coszang=yrmu0(1:knon))
+#endif       
+    ENDIF
+
+    CALL Synchro_omp
+    
+    albedo_keep(1:knon) = (albedo_out(1:knon,1)+albedo_out(1:knon,2))/2.
+
+!* Send to coupler
+!
+    IF (type_ocean=='couple') THEN
+       CALL cpl_send_land_fields(itime, knon, knindex, &
+            riverflow, coastalflow)
+    ENDIF
+
+    alb1_new(1:knon) = albedo_out(1:knon,1) 
+    alb2_new(1:knon) = albedo_out(1:knon,2)
+
+! Convention orchidee: positif vers le haut
+    fluxsens(1:knon) = -1. * fluxsens(1:knon)
+    fluxlat(1:knon)  = -1. * fluxlat(1:knon)
+    
+!  evap     = -1. * evap
+
+    IF (debut) lrestart_read = .FALSE.
+    
+    IF (debut) CALL Finalize_surf_para
+
+    
+  END SUBROUTINE surf_land_orchidee
+!
+!****************************************************************************************
+!
+  SUBROUTINE Init_orchidee_index(knon,knindex,offset,ktindex)
+  USE mod_surf_para
+  USE mod_grid_phy_lmdz
+  
+    INTEGER,INTENT(IN)    :: knon
+    INTEGER,INTENT(IN)    :: knindex(klon)    
+    INTEGER,INTENT(OUT)   :: offset
+    INTEGER,INTENT(OUT)   :: ktindex(klon)
+    
+    INTEGER               :: ktindex_glo(knon_glo)
+    INTEGER               :: offset_para(0:omp_size*mpi_size-1)
+    INTEGER               :: LastPoint
+    INTEGER               :: task
+    
+    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin-1)+(klon_omp_begin-1)+nbp_lon-1
+    
+    CALL gather_surf(ktindex(1:knon),ktindex_glo) 
+    
+    IF (is_mpi_root .AND. is_omp_root) THEN
+      LastPoint=0
+      DO Task=0,mpi_size*omp_size-1
+        IF (knon_glo_para(Task)>0) THEN
+           offset_para(task)= LastPoint-MOD(LastPoint,nbp_lon)
+           LastPoint=ktindex_glo(knon_glo_end_para(task))
+        ENDIF
+      ENDDO
+    ENDIF
+    
+    CALL bcast(offset_para)
+    
+    offset=offset_para(omp_size*mpi_rank+omp_rank)
+    
+    ktindex(1:knon)=ktindex(1:knon)-offset
+
+  END SUBROUTINE Init_orchidee_index
+
+!
+!************************* ***************************************************************
+! 
+
+  SUBROUTINE Get_orchidee_communicator(orch_comm,orch_omp_size,orch_omp_rank)
+  USE  mod_surf_para
+      
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif    
+
+    INTEGER,INTENT(OUT) :: orch_comm
+    INTEGER,INTENT(OUT) :: orch_omp_size
+    INTEGER,INTENT(OUT) :: orch_omp_rank
+    INTEGER             :: color
+    INTEGER             :: i,ierr
+!
+! End definition
+!****************************************************************************************
+    
+    
+    IF (is_omp_root) THEN          
+      
+      IF (knon_mpi==0) THEN 
+         color = 0
+      ELSE 
+         color = 1
+      ENDIF
+    
+#ifdef CPP_MPI    
+      CALL MPI_COMM_SPLIT(COMM_LMDZ_PHY,color,mpi_rank,orch_comm,ierr)
+#endif
+    
+    ENDIF
+    CALL bcast_omp(orch_comm)
+    
+    IF (knon_mpi /= 0) THEN
+      orch_omp_size=0
+      DO i=0,omp_size-1
+        IF (knon_omp_para(i) /=0) THEN
+          orch_omp_size=orch_omp_size+1
+          IF (i==omp_rank) orch_omp_rank=orch_omp_size-1
+        ENDIF
+      ENDDO
+    ENDIF
+   
+    
+  END SUBROUTINE Get_orchidee_communicator
+!
+!****************************************************************************************
+!  
+
+  SUBROUTINE Init_neighbours(knon,neighbours,knindex,pctsrf)
+    USE mod_grid_phy_lmdz
+    USE mod_surf_para    
+    USE indice_sol_mod
+
+#ifdef CPP_MPI
+    INCLUDE 'mpif.h'
+#endif    
+
+! Input arguments
+!****************************************************************************************
+    INTEGER, INTENT(IN)                     :: knon
+    INTEGER, DIMENSION(klon), INTENT(IN)    :: knindex
+    REAL, DIMENSION(klon), INTENT(IN)       :: pctsrf
+    
+! Output arguments
+!****************************************************************************************
+    INTEGER, DIMENSION(knon,8), INTENT(OUT) :: neighbours
+
+! Local variables
+!****************************************************************************************
+    INTEGER                              :: i, igrid, jj, ij, iglob
+    INTEGER                              :: ierr, ireal, index
+    INTEGER, DIMENSION(8,3)              :: off_ini
+    INTEGER, DIMENSION(8)                :: offset  
+    INTEGER, DIMENSION(nbp_lon,nbp_lat)  :: correspond
+    INTEGER, DIMENSION(knon_glo)         :: ktindex_glo
+    INTEGER, DIMENSION(knon_glo,8)       :: neighbours_glo
+    REAL, DIMENSION(klon_glo)            :: pctsrf_glo
+    INTEGER                              :: ktindex(klon)
+!
+! End definition
+!****************************************************************************************
+
+    ktindex(1:knon)=knindex(1:knon)+(klon_mpi_begin-1)+(klon_omp_begin-1)+nbp_lon-1
+    
+    CALL gather_surf(ktindex(1:knon),ktindex_glo)
+    CALL gather(pctsrf,pctsrf_glo)
+    
+    IF (is_mpi_root .AND. is_omp_root) THEN
+      neighbours_glo(:,:)=-1
+!  Initialisation des offset    
+!
+! offset bord ouest
+       off_ini(1,1) = - nbp_lon   ; off_ini(2,1) = - nbp_lon + 1     ; off_ini(3,1) = 1
+       off_ini(4,1) = nbp_lon + 1 ; off_ini(5,1) = nbp_lon           ; off_ini(6,1) = 2 * nbp_lon - 1
+       off_ini(7,1) = nbp_lon -1  ; off_ini(8,1) = - 1 
+! offset point normal
+       off_ini(1,2) = - nbp_lon   ; off_ini(2,2) = - nbp_lon + 1     ; off_ini(3,2) = 1
+       off_ini(4,2) = nbp_lon + 1 ; off_ini(5,2) = nbp_lon           ; off_ini(6,2) = nbp_lon - 1
+       off_ini(7,2) = -1          ; off_ini(8,2) = - nbp_lon - 1
+! offset bord   est
+       off_ini(1,3) = - nbp_lon   ; off_ini(2,3) = - 2 * nbp_lon + 1 ; off_ini(3,3) = - nbp_lon + 1
+       off_ini(4,3) =  1          ; off_ini(5,3) = nbp_lon           ; off_ini(6,3) = nbp_lon - 1
+       off_ini(7,3) = -1          ; off_ini(8,3) = - nbp_lon - 1
+!
+!
+! Attention aux poles
+!
+       DO igrid = 1, knon_glo
+          index = ktindex_glo(igrid)
+          jj = INT((index - 1)/nbp_lon) + 1
+          ij = index - (jj - 1) * nbp_lon
+          correspond(ij,jj) = igrid
+       ENDDO
+!sonia : Les mailles des voisines doivent etre toutes egales (pour couplage orchidee)
+       IF (knon_glo == 1) THEN
+         igrid = 1
+         DO i = 1,8
+           neighbours_glo(igrid, i) = igrid
+         ENDDO
+       ELSE
+       print*,'sonia : knon_glo,ij,jj', knon_glo, ij,jj
+       
+       DO igrid = 1, knon_glo
+          iglob = ktindex_glo(igrid)
+          
+          IF (MOD(iglob, nbp_lon) == 1) THEN
+             offset = off_ini(:,1)
+          ELSE IF(MOD(iglob, nbp_lon) == 0) THEN
+             offset = off_ini(:,3)
+          ELSE
+             offset = off_ini(:,2)
+          ENDIF
+          
+          DO i = 1, 8
+             index = iglob + offset(i)
+             ireal = (MIN(MAX(1, index - nbp_lon + 1), klon_glo))
+             IF (pctsrf_glo(ireal) > EPSFRA) THEN
+                jj = INT((index - 1)/nbp_lon) + 1
+                ij = index - (jj - 1) * nbp_lon
+                neighbours_glo(igrid, i) = correspond(ij, jj)
+             ENDIF
+          ENDDO
+       ENDDO
+       ENDIF !fin knon_glo == 1
+
+    ENDIF
+    
+    DO i = 1, 8
+      CALL scatter_surf(neighbours_glo(:,i),neighbours(1:knon,i))
+    ENDDO
+  END SUBROUTINE Init_neighbours
+
+!
+!****************************************************************************************
+!
+#endif
+END MODULE surf_land_orchidee_nounstruct_mod
Index: /LMDZ6/trunk/libf/phylmd/tracco2i_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/tracco2i_mod.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/tracco2i_mod.F90	(revision 3435)
@@ -10,5 +10,5 @@
 
     USE dimphy
-    USE infotrac
+    USE infotrac_phy
     USE geometry_mod, ONLY : cell_area
     USE carbon_cycle_mod, ONLY : nbcf_in, fields_in, cfname_in, fco2_ocn_day, fco2_ff, fco2_bb
@@ -119,5 +119,5 @@
 
     USE dimphy
-    USE infotrac
+    USE infotrac_phy
     USE geometry_mod, ONLY : cell_area
     USE mod_grid_phy_lmdz
Index: /LMDZ6/trunk/libf/phylmd/undefSTD.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/undefSTD.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/undefSTD.F90	(revision 3435)
@@ -43,5 +43,4 @@
   ! PARAMETER(klevSTD=17)
   INTEGER itap
-  ! REAL dtime
 
   ! variables locales
@@ -67,8 +66,8 @@
 
 
-    ! calcul variables tous les freq_calNMC(n)/dtime pas de temps
+    ! calcul variables tous les freq_calNMC(n)/phys_tstep pas de temps
     ! de la physique
 
-    IF (mod(itap,nint(freq_calnmc(n)/dtime))==0) THEN
+    IF (mod(itap,nint(freq_calnmc(n)/phys_tstep))==0) THEN
       DO k = 1, nlevstd
         DO i = 1, klon
@@ -103,5 +102,5 @@
       END DO !k
 
-    END IF !MOD(itap,NINT(freq_calNMC(n)/dtime)).EQ.0
+    END IF !MOD(itap,NINT(freq_calNMC(n)/phys_tstep)).EQ.0
 
   END DO !n
Index: /LMDZ6/trunk/libf/phylmd/write_histrac.h
===================================================================
--- /LMDZ6/trunk/libf/phylmd/write_histrac.h	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/write_histrac.h	(revision 3435)
@@ -8,5 +8,5 @@
      
      CALL histwrite_phy(nid_tra,.FALSE.,"phis",itau_w,pphis)
-     CALL histwrite_phy(nid_tra,.FALSE.,"aire",itau_w,airephy)
+     CALL histwrite_phy(nid_tra,.FALSE.,"aire",itau_w,cell_area)
      CALL histwrite_phy(nid_tra,.FALSE.,"zmasse",itau_w,zmasse)
 ! RomP >>>
Index: /LMDZ6/trunk/libf/phylmd/yamada4.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/yamada4.F90	(revision 3434)
+++ /LMDZ6/trunk/libf/phylmd/yamada4.F90	(revision 3435)
@@ -734,6 +734,4 @@
   IMPLICIT NONE
  
-  include "dimensions.h"
-
 !    vdif_q2: subroutine qui calcule la diffusion de la TKE par la TKE
 !             avec un schema implicite en temps avec 
@@ -825,6 +823,4 @@
   IMPLICIT NONE
 
-  include "dimensions.h"
-!
 ! vdif_q2e: subroutine qui calcule la diffusion de TKE par la TKE
 !           avec un schema explicite en temps
Index: /LMDZ6/trunk/makelmdz
===================================================================
--- /LMDZ6/trunk/makelmdz	(revision 3434)
+++ /LMDZ6/trunk/makelmdz	(revision 3435)
@@ -112,4 +112,5 @@
 [-v false/orchidee2.0/orchidee1.9/true] : version of the vegetation model to include (default: false)
           false       : no vegetation model
+          orchidee2.1 : compile using ORCHIDEE 2.1 (or more recent version)
           orchidee2.0 : compile using ORCHIDEE 2.0 (or more recent version)
           orchidee1.9 : compile using ORCHIDEE up to the version including OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6
@@ -432,5 +433,5 @@
 
 #==============================================================================
-if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" ]
+if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" -o "$veget" = "orchidee2.1" ]
 then
 
@@ -442,4 +443,7 @@
    fi
    if [[ "$veget" == "orchidee2.0" ]] ; then
+      orch_libs="sechiba parameters stomate parallel orglob orchidee"
+      CPP_KEY="$CPP_KEY ORCHIDEE_NOUNSTRUCT"
+   elif [[ "$veget" == "orchidee2.1" ]] ; then
       orch_libs="sechiba parameters stomate parallel orglob orchidee"
    else
Index: /LMDZ6/trunk/makelmdz_fcm
===================================================================
--- /LMDZ6/trunk/makelmdz_fcm	(revision 3434)
+++ /LMDZ6/trunk/makelmdz_fcm	(revision 3435)
@@ -90,5 +90,6 @@
 [-v false/orchidee2.0/orchidee1.9/true] : version of the vegetation model to include (default: false)
           false       : no vegetation model
-          orchidee2.0 : compile using ORCHIDEE 2.0 (or more recent version)
+          orchidee2.1 : compile using ORCHIDEE 2.1 (or more recent version)
+          orchidee2.0 : compile using ORCHIDEE 2.0
           orchidee1.9 : compile using ORCHIDEE up to the version including OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6
           true        : (obsolete; for backward compatibility) use ORCHIDEE tag 1.9-1.9.6
@@ -373,5 +374,5 @@
 fi
 
-if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" ]
+if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" -o "$veget" = "orchidee2.1" ]
 then
 #NB: option 'true': for backward compatibility. To be used with ORCHIDEE tag 1.9-1.9.6
@@ -385,4 +386,7 @@
    fi
    if [[ "$veget" == "orchidee2.0" ]] ; then
+      orch_libs="sechiba parameters stomate parallel orglob orchidee"
+      CPP_KEY="$CPP_KEY ORCHIDEE_NOUNSTRUCT"
+   elif [[ "$veget" == "orchidee2.1" ]] ; then
       orch_libs="sechiba parameters stomate parallel orglob orchidee"
    else
Index: /LMDZ6/trunk/tools/fcm/lib/Fcm/CfgFile.pm
===================================================================
--- /LMDZ6/trunk/tools/fcm/lib/Fcm/CfgFile.pm	(revision 3434)
+++ /LMDZ6/trunk/tools/fcm/lib/Fcm/CfgFile.pm	(revision 3435)
@@ -19,4 +19,5 @@
 # Standard pragma
 use warnings;
+no warnings 'uninitialized';
 use strict;
 
