Index: trunk/LMDZ.COMMON/libf/phy_common/geometry_mod.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/phy_common/geometry_mod.F90	(revision 1621)
+++ trunk/LMDZ.COMMON/libf/phy_common/geometry_mod.F90	(revision 1682)
@@ -30,4 +30,6 @@
 !$OMP THREADPRIVATE(cell_area)
 
+  INTEGER,SAVE,ALLOCATABLE :: ind_cell_glo(:)      ! global index 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: trunk/LMDZ.COMMON/libf/phy_common/init_print_control_mod.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/phy_common/init_print_control_mod.F90	(revision 1682)
+++ trunk/LMDZ.COMMON/libf/phy_common/init_print_control_mod.F90	(revision 1682)
@@ -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: trunk/LMDZ.COMMON/libf/phy_common/mod_phys_lmdz_mpi_data.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/phy_common/mod_phys_lmdz_mpi_data.F90	(revision 1621)
+++ trunk/LMDZ.COMMON/libf/phy_common/mod_phys_lmdz_mpi_data.F90	(revision 1682)
@@ -3,5 +3,4 @@
 !
 MODULE mod_phys_lmdz_mpi_data
-!  USE mod_const_mpi
   
   INTEGER,SAVE :: ii_begin
@@ -36,5 +35,4 @@
   INTEGER,SAVE :: mpi_size
   INTEGER,SAVE :: mpi_master
-!  INTEGER,SAVE :: mpi_root
   LOGICAL,SAVE :: is_mpi_root
   LOGICAL,SAVE :: is_using_mpi
@@ -48,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(:)
@@ -187,7 +183,6 @@
 
   SUBROUTINE print_module_data
-!  USE print_control_mod, ONLY: lunout
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
-  INCLUDE "iniprint.h" 
   
     WRITE(lunout,*) 'ii_begin =', ii_begin
Index: trunk/LMDZ.COMMON/libf/phy_common/mod_phys_lmdz_omp_data.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/phy_common/mod_phys_lmdz_omp_data.F90	(revision 1621)
+++ trunk/LMDZ.COMMON/libf/phy_common/mod_phys_lmdz_omp_data.F90	(revision 1682)
@@ -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,6 @@
 
   SUBROUTINE Print_module_data
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
-  INCLUDE "iniprint.h"
 
 !$OMP CRITICAL  
Index: trunk/LMDZ.COMMON/libf/phy_common/mod_phys_lmdz_para.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/phy_common/mod_phys_lmdz_para.F90	(revision 1621)
+++ trunk/LMDZ.COMMON/libf/phy_common/mod_phys_lmdz_para.F90	(revision 1682)
@@ -19,8 +19,8 @@
   SUBROUTINE Init_phys_lmdz_para(nbp,nbp_lon,nbp_lat,communicator)
   IMPLICIT NONE
-    INTEGER,INTENT(in) :: nbp
-    INTEGER,INTENT(in) :: nbp_lon
-    INTEGER,INTENT(in) :: nbp_lat
-    INTEGER,INTENT(in) :: communicator
+    INTEGER,INTENT(IN) :: nbp
+    INTEGER,INTENT(IN) :: nbp_lon
+    INTEGER,INTENT(IN) :: nbp_lat
+    INTEGER,INTENT(IN) :: communicator
 
     CALL Init_phys_lmdz_mpi_data(nbp,nbp_lon,nbp_lat,communicator)
@@ -49,6 +49,6 @@
   SUBROUTINE Test_transfert
   USE mod_grid_phy_lmdz
+  USE print_control_mod, ONLY: lunout
   IMPLICIT NONE
-    INCLUDE "iniprint.h"
  
     REAL :: Test_Field1d_glo(klon_glo,nbp_lev)
Index: trunk/LMDZ.COMMON/libf/phy_common/physics_distribution_mod.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/phy_common/physics_distribution_mod.F90	(revision 1621)
+++ trunk/LMDZ.COMMON/libf/phy_common/physics_distribution_mod.F90	(revision 1682)
@@ -10,6 +10,8 @@
                                        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
+
   IMPLICIT NONE
     INTEGER,INTENT(IN) :: grid_type 
@@ -24,4 +26,7 @@
     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)
+!$OMP END PARALLEL
 
   END SUBROUTINE init_physics_distribution  
Index: trunk/LMDZ.COMMON/libf/phy_common/print_control_mod.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/phy_common/print_control_mod.F90	(revision 1621)
+++ trunk/LMDZ.COMMON/libf/phy_common/print_control_mod.F90	(revision 1682)
@@ -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: trunk/LMDZ.COMMON/libf/phy_common/xios_writefield.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/phy_common/xios_writefield.F90	(revision 1682)
+++ trunk/LMDZ.COMMON/libf/phy_common/xios_writefield.F90	(revision 1682)
@@ -0,0 +1,294 @@
+MODULE xios_writefield_mod
+#ifdef CPP_XIOS
+  PRIVATE
+  
+  INTEGER,PARAMETER :: size_name=255
+  INTEGER, PARAMETER :: MaxWriteField = 100
+  CHARACTER(len=size_name), SAVE ::  FieldName(MaxWriteField) 
+!$OMP THREADPRIVATE(FieldName)
+  INTEGER,                  SAVE  :: FieldIt (MaxWriteField)
+!$OMP THREADPRIVATE(FieldIt)
+  INTEGER,SAVE :: NbField = 0
+!$OMP THREADPRIVATE(NbField) 
+
+  INTERFACE xios_writefield
+    MODULE PROCEDURE xios_writefield2d,xios_writefield3d
+  END INTERFACE
+
+  LOGICAL,SAVE :: output_native_grid
+!$OMP THREADPRIVATE( output_native_grid)  
+
+  INTEGER,SAVE :: ni_glo , nj_glo
+!$OMP THREADPRIVATE( ni_glo, nj_glo)  
+
+   
+  PUBLIC xios_writefield
+
+CONTAINS
+  
+  FUNCTION NameId(name_in)
+  IMPLICIT NONE
+    CHARACTER(LEN=*),INTENT(IN)      :: name_in
+    INTEGER                          :: nameId
+    CHARACTER(LEN=size_name)         :: name
+    INTEGER :: n  
+    
+    name=name_in
+     
+    DO n=1,NbField
+      IF (name==fieldName(n)) THEN
+        nameId=n
+        RETURN
+      ENDIF
+    ENDDO
+      
+    nameId=0
+    RETURN
+  END FUNCTION NameId
+     
+ 
+ 
+  SUBROUTINE xios_writefield2d(field,name_in)
+  USE dimphy
+  USE mod_phys_lmdz_para
+  USE xios
+  USE print_control_mod, ONLY:  lunout
+  USE mod_grid_phy_lmdz, only: nbp_lon, nbp_lat, klon_glo, grid_type, unstructured, regular_lonlat
+  USE wxios, ONLY: wxios_domain_param_unstructured, wxios_domain_param,  wxios_set_context
+  USE ioipsl
+  IMPLICIT NONE
+  REAL, DIMENSION(:), INTENT(IN) :: field
+  CHARACTER(LEN=*)                 :: name_in
+  CHARACTER(LEN=size_name)         :: name 
+  TYPE(xios_context) :: xios_ctx
+  TYPE(xios_domaingroup) :: domain_definition
+  TYPE(xios_domaingroup) :: my_domaingroup
+  TYPE(xios_domain)      :: my_domain
+  TYPE(xios_domain)      :: my_regular_domain
+  TYPE(xios_filegroup)   :: file_definition
+  TYPE(xios_file)        :: my_file
+  TYPE(xios_field)       :: my_field
+  TYPE(xios_fieldgroup)  :: field_definition
+  TYPE(xios_generate_rectilinear_domain) :: generate_domain 
+  TYPE(xios_interpolate_domain) :: interpolate_domain
+  INTEGER                :: id
+  REAL,DIMENSION(klon_mpi) :: field_mpi  
+  REAL :: Field2d(nbp_lon,jj_nb)
+  
+    
+    IF (size(field,1) /= klon_omp) THEN
+      WRITE(lunout,*) 'xios_writefield :: '//FieldName//' is not on the model grid'
+      RETURN
+    ENDIF
+  
+    name = TRIM(ADJUSTL(name_in))
+    id=nameId(name)
+    
+    IF (id/=0) THEN
+      IF (is_omp_master) THEN
+        CALL xios_get_handle('context_lmdz_'//TRIM(name), xios_ctx)    !Récupération
+        CALL xios_set_current_context(xios_ctx)            !Activation
+      ENDIF
+    ELSE
+      output_native_grid=.FALSE.
+      ni_glo=0
+      nj_glo=0
+      IF (is_master) CALL getin("xios_writefield_nlon",ni_glo)
+      IF (is_master) CALL getin("xios_writefield_nlat",nj_glo)
+      CALL bcast(ni_glo)
+      CALL bcast(nj_glo)
+      IF (ni_glo==0 .OR. nj_glo==0) output_native_grid=.TRUE.
+
+      IF (is_omp_master) THEN
+        CALL xios_context_initialize('context_lmdz_'//TRIM(name), COMM_LMDZ_PHY)
+        CALL xios_get_handle('context_lmdz_'//TRIM(name), xios_ctx)    !Récupération
+        CALL xios_set_current_context(xios_ctx)            !Activation
+      
+        CALL xios_define_calendar("D360")
+        CALL xios_set_start_date(xios_date(2000,1,1,0,0,0))
+        CALL xios_set_time_origin(xios_date(2000,1,1,0,0,0))
+        CALL xios_set_timestep(xios_second)
+      
+        CALL xios_get_handle("domain_definition",domain_definition)
+        CALL xios_add_child(domain_definition,my_domaingroup,"domaingroup")
+        CALL xios_add_child(my_domaingroup,my_domain,"domain")
+        IF (grid_type==unstructured .AND. .NOT. output_native_grid ) THEN
+          CALL xios_add_child(domain_definition, my_regular_domain, "regular_domain")
+          CALL xios_set_attr(my_regular_domain,ni_glo=ni_glo, nj_glo=nj_glo, type="rectilinear")
+          CALL xios_add_child(my_regular_domain,generate_domain)
+          CALL xios_set_attr(generate_domain,lon_start=-180., lat_start=90., lat_end=-90.)
+          CALL xios_add_child(my_regular_domain,interpolate_domain)
+        ENDIF
+          
+      ENDIF
+      
+      IF (grid_type==regular_lonlat) THEN
+        CALL wxios_domain_param("domain")
+      ELSE IF (grid_type==unstructured) THEN
+        CALL wxios_domain_param_unstructured("domaingroup")
+      ENDIF       
+      
+      IF (is_omp_master) THEN
+        CALL xios_get_handle("file_definition",file_definition)
+        CALL xios_add_child(file_definition, my_file)
+        CALL xios_set_attr(my_file,name=TRIM(name),output_freq=xios_timestep,sync_freq=xios_timestep,type="one_file")
+        CALL xios_get_handle("field_definition",field_definition) 
+        CALL xios_add_child(field_definition, my_field, TRIM(name))
+        CALL xios_set_attr(my_field,domain_ref="domain",operation="instant")
+        CALL xios_add_child(my_file, my_field)
+        CALL xios_set_attr(my_field,field_ref=TRIM(name))
+        IF (grid_type==unstructured .AND. .NOT. output_native_grid) CALL xios_set_attr(my_field,domain_ref="regular_domain")
+
+        CALL xios_close_context_definition()
+      
+        NbField=NbField+1
+        FieldName(NbField)=TRIM(name)
+        FieldIt(NbField)=0
+        id=NbField
+      ENDIF
+    ENDIF
+ 
+    CALL Gather_omp(field,field_mpi)
+
+    IF (is_omp_master) THEN
+      FieldIt(id)=FieldIt(id)+1
+      CALL xios_update_calendar(FieldIt(id)) 
+
+      IF (grid_type==regular_lonlat) THEN
+        CALL grid1Dto2D_mpi(field_mpi,Field2d)   
+        CALL xios_send_field(TRIM(name), Field2d)
+      ELSE IF (grid_type==unstructured) THEN
+        CALL xios_send_field(TRIM(name), field_mpi)
+      ENDIF
+    ENDIF
+    
+    CALL wxios_set_context()
+  
+  END SUBROUTINE  xios_writefield2d
+
+  SUBROUTINE xios_writefield3d(field,name_in)
+  USE dimphy
+  USE mod_phys_lmdz_para
+  USE xios
+  USE print_control_mod, ONLY:  lunout
+  USE mod_grid_phy_lmdz, only: nbp_lon, nbp_lat, klon_glo, grid_type, unstructured, regular_lonlat
+  USE wxios, ONLY: wxios_domain_param_unstructured, wxios_domain_param,  wxios_set_context
+  USE ioipsl
+  IMPLICIT NONE
+  REAL, DIMENSION(:,:), INTENT(IN) :: field
+  CHARACTER(LEN=*)                 :: name_in
+  CHARACTER(LEN=size_name)         :: name 
+  TYPE(xios_context) :: xios_ctx
+  TYPE(xios_domaingroup) :: domain_definition
+  TYPE(xios_domaingroup) :: my_domaingroup
+  TYPE(xios_domain)      :: my_domain
+  TYPE(xios_domain)      :: my_regular_domain
+  TYPE(xios_filegroup)   :: file_definition
+  TYPE(xios_file)        :: my_file
+  TYPE(xios_field)       :: my_field
+  TYPE(xios_fieldgroup)  :: field_definition
+  TYPE(xios_generate_rectilinear_domain) :: generate_domain 
+  TYPE(xios_interpolate_domain) :: interpolate_domain
+  TYPE(xios_axisgroup)   :: axis_definition
+  TYPE(xios_axis)        :: my_axis
+  INTEGER                :: id
+  REAL,DIMENSION(klon_mpi,size(field,2)) :: field_mpi  
+  REAL :: Field2d(nbp_lon,jj_nb,size(field,2))
+  REAL :: axis_value(size(field,2))
+  INTEGER :: i
+    
+    IF (size(field,1) /= klon_omp) THEN
+      WRITE(lunout,*) 'xios_writefield :: '//FieldName//' is not on the model grid'
+      RETURN
+    ENDIF
+  
+    name = TRIM(ADJUSTL(name_in))
+    id=nameId(name)
+    
+    IF (id/=0) THEN
+   
+      IF (is_omp_master) CALL xios_get_handle('context_lmdz_'//TRIM(name), xios_ctx)    !Récupération
+      IF (is_omp_master) CALL xios_set_current_context(xios_ctx)            !Activation
+   
+    ELSE
+      output_native_grid=.FALSE.
+      ni_glo=0
+      nj_glo=0
+      IF (is_master) CALL getin("xios_writefield_nlon",ni_glo)
+      IF (is_master) CALL getin("xios_writefield_nlat",nj_glo)
+      CALL bcast(ni_glo)
+      CALL bcast(nj_glo)
+      IF (ni_glo==0 .OR. nj_glo==0) output_native_grid=.TRUE.
+
+      IF (is_omp_master) THEN
+        CALL xios_context_initialize('context_lmdz_'//TRIM(name), COMM_LMDZ_PHY)
+        CALL xios_get_handle('context_lmdz_'//TRIM(name), xios_ctx)    !Récupération
+        CALL xios_set_current_context(xios_ctx)            !Activation
+      
+        CALL xios_define_calendar("D360")
+        CALL xios_set_start_date(xios_date(2000,1,1,0,0,0))
+        CALL xios_set_time_origin(xios_date(2000,1,1,0,0,0))
+        CALL xios_set_timestep(xios_second)
+      
+        CALL xios_get_handle("domain_definition",domain_definition)
+        CALL xios_add_child(domain_definition,my_domaingroup,"domaingroup")
+        CALL xios_add_child(my_domaingroup,my_domain,"domain")
+        IF (grid_type==unstructured .AND. .NOT. output_native_grid) THEN
+          CALL xios_add_child(domain_definition, my_regular_domain, "regular_domain")
+          CALL xios_set_attr(my_regular_domain,ni_glo=ni_glo, nj_glo=nj_glo, type="rectilinear")
+          CALL xios_add_child(my_regular_domain,generate_domain)
+          CALL xios_set_attr(generate_domain,lon_start=-180., lat_start=90., lat_end=-90.)
+          CALL xios_add_child(my_regular_domain,interpolate_domain)
+        ENDIF
+        CALL xios_get_handle("axis_definition",axis_definition)
+        CALL xios_add_child(axis_definition,my_axis,"axis")
+        axis_value=(/(i,i=1,size(field,2))/)
+        CALL xios_set_attr(my_axis,name="z",n_glo=size(field,2),value=axis_value, unit="level" )        
+      ENDIF
+      
+      IF (grid_type==regular_lonlat) THEN
+        CALL wxios_domain_param("domain")
+      ELSE IF (grid_type==unstructured) THEN
+        CALL wxios_domain_param_unstructured("domaingroup")
+      ENDIF       
+      
+      IF (is_omp_master) THEN
+        CALL xios_get_handle("file_definition",file_definition)
+        CALL xios_add_child(file_definition, my_file)
+        CALL xios_set_attr(my_file,name=TRIM(name),output_freq=xios_timestep,sync_freq=xios_timestep,type="one_file")
+        CALL xios_get_handle("field_definition",field_definition) 
+        CALL xios_add_child(field_definition, my_field, TRIM(name))
+        CALL xios_set_attr(my_field,domain_ref="domain",axis_ref="axis", operation="instant")
+        CALL xios_add_child(my_file, my_field)
+        CALL xios_set_attr(my_field,field_ref=TRIM(name))
+        IF (grid_type==unstructured .AND. .NOT. output_native_grid) CALL xios_set_attr(my_field,domain_ref="regular_domain")
+
+        CALL xios_close_context_definition()
+      
+        NbField=NbField+1
+        FieldName(NbField)=TRIM(name)
+        FieldIt(NbField)=0
+        id=NbField
+      ENDIF
+    ENDIF
+ 
+    CALL Gather_omp(field,field_mpi)
+
+    IF (is_omp_master) THEN
+      FieldIt(id)=FieldIt(id)+1
+      CALL xios_update_calendar(FieldIt(id)) 
+
+      IF (grid_type==regular_lonlat) THEN
+        CALL grid1Dto2D_mpi(field_mpi,Field2d)   
+        CALL xios_send_field(TRIM(name), Field2d)
+      ELSE IF (grid_type==unstructured) THEN
+        CALL xios_send_field(TRIM(name), field_mpi)
+      ENDIF
+    ENDIF
+    
+    CALL wxios_set_context()
+  
+  END SUBROUTINE  xios_writefield3d
+
+#endif
+END MODULE
