Index: /XIOS/dev/branch_openmp/bld.cfg
===================================================================
--- /XIOS/dev/branch_openmp/bld.cfg	(revision 1349)
+++ /XIOS/dev/branch_openmp/bld.cfg	(revision 1350)
@@ -37,5 +37,5 @@
 #bld::target test_expand_domain.exe
 #bld::target test_new_features.exe 
-#bld::target test_unstruct_complete.exe 
+bld::target test_unstruct_complete.exe 
 #bld::target test_omp.exe 
 bld::target test_complete_omp.exe 
@@ -48,8 +48,8 @@
 #bld::target test_complete.exe
 #bld::target test_remap.exe
-#bld::target test_unstruct.exe
 #bld::target test_xios2_cmip6.exe
 #bld::target test_connectivity_expand.exe
-#bld::target toy_cmip6.exe
+bld::target toy_cmip6.exe
+bld::target toy_cmip6_omp.exe
 bld::exe_dep
 
Index: /XIOS/dev/branch_openmp/src/test/test_unstruct_complete.f90
===================================================================
--- /XIOS/dev/branch_openmp/src/test/test_unstruct_complete.f90	(revision 1349)
+++ /XIOS/dev/branch_openmp/src/test/test_unstruct_complete.f90	(revision 1350)
@@ -44,9 +44,12 @@
   DOUBLE PRECISION,ALLOCATABLE :: field_A_compressed(:,:)
 
+  CALL MPI_INIT(ierr)
+  CALL init_wait
+
   CALL xios_initialize(id,return_comm=comm)
   CALL MPI_COMM_RANK(comm,mpi_rank,ierr)
   CALL MPI_COMM_SIZE(comm,mpi_size,ierr)
 
-  CALL init_wait
+  
 
   ncell_glo=0
@@ -207,5 +210,5 @@
   CALL xios_set_domain_attr("domain_srf", lonvalue_1D=lon, latvalue_1D=lat)
   CALL xios_set_domain_attr("domain_srf", nvertex=4, bounds_lon_1D=bounds_lon, bounds_lat_1D=bounds_lat)
-!  CALL xios_set_compute_connectivity_domain_attr("compute", n_neighbor=n_local, local_neighbor=local_neighbor)
+  CALL xios_set_compute_connectivity_domain_attr("compute", n_neighbor=n_local, local_neighbor=local_neighbor)
 
 
@@ -248,7 +251,8 @@
   DEALLOCATE(data_i_index)
 
+  CALL xios_finalize()
   CALL MPI_COMM_FREE(comm, ierr)
-
-  CALL xios_finalize()
+  
+  CALL MPI_FINALIZE(ierr)
 
 CONTAINS
Index: /XIOS/dev/branch_openmp/src/test/test_unstruct_omp.f90
===================================================================
--- /XIOS/dev/branch_openmp/src/test/test_unstruct_omp.f90	(revision 1349)
+++ /XIOS/dev/branch_openmp/src/test/test_unstruct_omp.f90	(revision 1350)
@@ -1,7 +1,6 @@
-PROGRAM test_unstruct_omp
+PROGRAM test_unstruct_complete_omp
 
   USE xios
   USE mod_wait
-  use omp_lib
   IMPLICIT NONE
   INCLUDE "mpif.h"
@@ -41,7 +40,8 @@
   INTEGER :: list_ind(nlon,nlat)
   INTEGER :: rank,j1,j2,np,ncell_x
-  INTEGER :: data_n_index, provided
+  INTEGER :: data_n_index
   INTEGER,ALLOCATABLE :: data_i_index(:)
   DOUBLE PRECISION,ALLOCATABLE :: field_A_compressed(:,:)
+  INTEGER :: provided
 
   CALL MPI_INIT_THREAD(3, provided, ierr)
@@ -50,10 +50,11 @@
       call MPI_Abort()
     endif
+
+  
   CALL init_wait
-  CALL MPI_COMM_RANK(MPI_COMM_WORLD,mpi_rank,ierr)
-  CALL MPI_COMM_SIZE(MPI_COMM_WORLD,mpi_size,ierr)
-  if(mpi_rank < mpi_size-2) then
-
-  !$omp parallel default(firstprivate) firstprivate(dtime)
+
+  CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)
+  CALL MPI_COMM_SIZE(MPI_COMM_WORLD,size_loc,ierr)
+  if(rank < size_loc-2) then
 
   CALL xios_initialize(id,return_comm=comm)
@@ -61,6 +62,4 @@
   CALL MPI_COMM_SIZE(comm,mpi_size,ierr)
 
-  mpi_rank = mpi_rank*omp_get_num_threads() + omp_get_thread_num()
-  mpi_size = mpi_size*omp_get_num_threads()
 
 
@@ -79,12 +78,4 @@
   ALLOCATE(field_A_glo(ncell_glo,llm))
   ALLOCATE(mask_glo(ncell_glo))
-
-  lon_glo(:) = 0
-  lat_glo(:) = 0
-  bounds_lon_glo(:,:) = 0
-  bounds_lat_glo(:,:) = 0
-  i_index_glo(:) = 0
-  field_A_glo(:,:) = 0
-  mask_glo(:) = 0
 
   ind=0
@@ -189,14 +180,4 @@
   ALLOCATE(mask(ncell))
   ALLOCATE(n_local(ncell))
- 
-  i_index(:)=0
-  lon(:)=0
-  lat(:)=0
-  bounds_lon(:,:)=0
-  bounds_lat(:,:)=0
-  field_A_srf(:,:)=0
-  mask(:)=0
-  n_local(:)=0
-
   ncell=0
   data_n_index=0
@@ -221,8 +202,4 @@
   ALLOCATE(field_A_compressed(data_n_index,llm))
   ALLOCATE(data_i_index(data_n_index))
-  field_A_compressed(:,:)=0
-  data_i_index(:)=0
-
-
   data_n_index=0
   DO ind=1,ncell
@@ -256,7 +233,7 @@
   CALL xios_close_context_definition()
 
-  !CALL xios_get_compute_connectivity_domain_attr("compute", n_neighbor_max=nbMax)
-  !ALLOCATE(local_neighbor(nbMax,ncell))
-  !CALL xios_get_compute_connectivity_domain_attr("compute", n_neighbor=n_local, local_neighbor=local_neighbor)
+  CALL xios_get_compute_connectivity_domain_attr("compute", n_neighbor_max=nbMax)
+  ALLOCATE(local_neighbor(nbMax,ncell))
+  CALL xios_get_compute_connectivity_domain_attr("compute", n_neighbor=n_local, local_neighbor=local_neighbor)
 
    DO ts=1,24*10
@@ -284,20 +261,16 @@
   DEALLOCATE(field_A_compressed)
   DEALLOCATE(data_i_index)
-  !DEALLOCATE(local_neighbor)
   
-
   CALL xios_finalize()
-
-print *, mpi_rank, "Client : xios_finalize "
-
-  !$omp barrier
-
-  !$omp master 
-  CALL MPI_COMM_FREE(comm, ierr)
-  !$omp end master
-
-  !$omp barrier
-
-  !$omp end parallel
+    print*, "xios finalize OK", rank, size_loc
+    
+    !$omp master 
+    !call MPI_Barrier(comm)
+    CALL MPI_COMM_FREE(comm, ierr)
+    !$omp end master
+
+    !$omp barrier
+    
+    !$omp end parallel
 
 
@@ -307,6 +280,7 @@
     print *, "Server : xios_finalize "
   
-    endif
-
+    endif  
+
+  CALL MPI_FINALIZE(ierr)
 
 CONTAINS
@@ -388,8 +362,8 @@
 END SUBROUTINE MSE_XIOS_GAUSS_GRID
 
-END PROGRAM test_unstruct_omp
-
-
-
-
-
+END PROGRAM test_unstruct_complete_omp
+
+
+
+
+
Index: /XIOS/dev/branch_openmp/src/test/toy_cmip6_omp.f90
===================================================================
--- /XIOS/dev/branch_openmp/src/test/toy_cmip6_omp.f90	(revision 1350)
+++ /XIOS/dev/branch_openmp/src/test/toy_cmip6_omp.f90	(revision 1350)
@@ -0,0 +1,371 @@
+PROGRAM toy_cmip6_omp 
+
+  USE xios
+  USE mod_wait
+  IMPLICIT NONE
+  INCLUDE "mpif.h"
+
+  INTEGER,PARAMETER :: il_unit=10
+  INTEGER :: comm, rank, size_loc, ierr
+  INTEGER :: ni,ibegin,iend,nj,jbegin,jend
+  INTEGER :: i,j,l,ts,n, nb_pt, il_run
+  DOUBLE PRECISION :: sypd, timestep_in_seconds, simulated_seconds_per_seconds, elapsed_per_timestep
+  CHARACTER(len=*),PARAMETER :: id="client"
+  CHARACTER(1000):: duration, timestep
+  INTEGER :: start_year,start_month,start_day
+  TYPE(xios_date) :: cdate, edate
+  TYPE(xios_duration)  :: dtime
+  TYPE(xios_context) :: ctx_hdl
+  REAL :: ilon,jlat
+  DOUBLE PRECISION,ALLOCATABLE :: lon_glo(:,:),lat_glo(:,:),lval(:)
+  DOUBLE PRECISION,ALLOCATABLE :: field_A_glo (:,:,:), pressure_glo (:,:,:), height_glo (:,:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: bounds_lon_glo(:,:,:),bounds_lat_glo(:,:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: pressure (:,:,:), height (:,:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),lonvalue(:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: bounds_lon(:,:,:),bounds_lat(:,:,:) 
+  DOUBLE PRECISION,ALLOCATABLE :: field_atm_2D(:,:),field_atm_3D(:,:,:),field_srf_2D(:),field_srf_3D(:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: field_atm_2D_miss(:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: field_oce_2D(:,:),field_oce_3D(:,:,:)
+  INTEGER, ALLOCATABLE :: kindex(:)
+  INTEGER :: provided
+
+  INTEGER :: ni_glo, nj_glo,llm
+
+  NAMELIST /param_toy/ ni_glo, nj_glo,llm,timestep,duration,sypd,start_year,start_month,start_day
+
+!!! MPI Initialization
+
+  CALL MPI_INIT_THREAD(3, provided, ierr)
+    if(provided .NE. 3) then
+      print*, "provided thread level = ", provided
+      call MPI_Abort()
+    endif
+
+  CALL init_wait
+
+  CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)
+  CALL MPI_COMM_SIZE(MPI_COMM_WORLD,size_loc,ierr)
+  if(rank < size_loc-2) then
+
+!!! Lecture des parametres du run
+
+  OPEN(unit=il_unit, file='param.def',status='old',iostat=ierr)
+  READ (il_unit, nml=param_toy)
+  !PRINT *, ni_glo, nj_glo,llm,duration
+
+  !$omp parallel default(firstprivate)
+
+!!! XIOS Initialization (get the local communicator)
+
+  CALL xios_initialize(id,return_comm=comm)
+
+  CALL MPI_COMM_RANK(comm,rank,ierr)
+  CALL MPI_COMM_SIZE(comm,size_loc,ierr)
+
+
+!!! Initialisation et allocation des coordonnÃ©es globales et locales pour la grille rÃ©guliÃšre
+
+  ALLOCATE (lon_glo(ni_glo,nj_glo),lat_glo(ni_glo,nj_glo))
+  ALLOCATE(bounds_lon_glo(4,ni_glo,nj_glo))
+  ALLOCATE(bounds_lat_glo(4,ni_glo,nj_glo))
+  ALLOCATE (field_A_glo(ni_glo,nj_glo,llm))
+  ALLOCATE (pressure_glo(ni_glo,nj_glo,llm))
+  ALLOCATE (height_glo(ni_glo,nj_glo,llm))
+  ALLOCATE (lval(llm))
+
+  DO j=1,nj_glo
+    DO i=1,ni_glo
+
+      ilon=i-0.5
+      jlat=j-0.5
+
+      lat_glo(i,j)= 90-(jlat*180./nj_glo)
+      lon_glo(i,j)= (ilon*360./ni_glo)
+      !print*, 'i/lon=',i,'lon=',lon_glo(i,j), 'j/lat=',j,'lat=',lat_glo(i,j)
+
+      bounds_lat_glo(1,i,j)= 90-((jlat-0.5)*180./nj_glo)
+      bounds_lon_glo(1,i,j)=((ilon-0.5)*360./ni_glo)
+
+      bounds_lat_glo(2,i,j)= 90-((jlat-0.5)*180./nj_glo)
+      bounds_lon_glo(2,i,j)=((ilon+0.5)*360./ni_glo)
+
+      bounds_lat_glo(3,i,j)= 90-((jlat+0.5)*180./nj_glo)
+      bounds_lon_glo(3,i,j)=((ilon+0.5)*360./ni_glo)
+
+      bounds_lat_glo(4,i,j)= 90-((jlat+0.5)*180./nj_glo)
+      bounds_lon_glo(4,i,j)=((ilon-0.5)*360./ni_glo)
+
+      WHERE (abs(bounds_lat_glo(:,i,j) - 90) < 0.000000001) bounds_lat_glo(:,i,j) = 90
+      WHERE (abs(bounds_lat_glo(:,i,j) + 90) < 0.000000001) bounds_lat_glo(:,i,j) = -90
+
+      DO l=1,llm
+         field_A_glo(i,j,l)=(i-1)+(j-1)*ni_glo+10000*l
+         ! pressure at half levels. First index value is high altitude, low pressure
+         pressure_glo(i,j,l)=((l-0.)/llm)*100000 + (jlat -nj_glo/2.)/nj_glo * 10000
+         height_glo(i,j,l)=(llm-l+0.5)/llm * 15000 + jlat * 100
+      ENDDO
+    ENDDO
+  ENDDO
+  ni=ni_glo ; ibegin=0
+
+  jbegin=0
+  DO n=0,size_loc-1
+    nj=nj_glo/size_loc
+    IF (n<MOD(nj_glo,size_loc)) nj=nj+1
+    IF (n==rank) exit
+    jbegin=jbegin+nj
+  ENDDO
+
+  iend=ibegin+ni-1 ; jend=jbegin+nj-1
+
+  ALLOCATE(lon(ni,nj),lat(ni,nj),lonvalue(ni,nj))
+  ALLOCATE(bounds_lon(4,ni,nj))
+  ALLOCATE(bounds_lat(4,ni,nj))
+  lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1)
+  lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1)
+  bounds_lon(:,:,:)=bounds_lon_glo(:,ibegin+1:iend+1,jbegin+1:jend+1)
+  bounds_lat(:,:,:)=bounds_lat_glo(:,ibegin+1:iend+1,jbegin+1:jend+1)
+
+
+  DO i=1,llm
+    lval(i)=i
+ ENDDO
+ 
+
+  
+!###########################################################################
+! Contexte ATM
+!###########################################################################
+ ALLOCATE(field_atm_2D(0:ni+1,-1:nj+2),field_atm_3D(0:ni+1,-1:nj+2,llm))
+ ALLOCATE(field_atm_2D_miss(0:ni+1,-1:nj+2))
+ ALLOCATE(pressure(0:ni+1,-1:nj+2,llm))
+ ALLOCATE(height(0:ni+1,-1:nj+2,llm))
+  field_atm_2D(1:ni,1:nj)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,1)
+  field_atm_2D_miss(1:ni,1:nj)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,1)
+  field_atm_3D(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
+  pressure(1:ni,1:nj,:)=pressure_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
+  height(1:ni,1:nj,:)=height_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
+
+  CALL xios_context_initialize("arpsfx",comm)
+  CALL xios_define_calendar("Gregorian", &
+     start_date=xios_date(start_year,start_month,start_day,0,0,0), &
+     time_origin=xios_date(1850,1,1,0,0,0))
+
+  !write(0,*) 'atm context initialized' ; call flush(0)
+  CALL xios_get_handle("arpsfx",ctx_hdl)
+  CALL xios_set_current_context(ctx_hdl)
+
+  CALL xios_set_axis_attr("axis_atm",n_glo=llm ,value=lval) ;
+
+  CALL xios_set_domain_attr("domain_atm",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, &
+       ni=ni,jbegin=jbegin,nj=nj, type='rectilinear')
+  CALL xios_set_domain_attr("domain_atm",data_dim=2, data_ibegin=-1, &
+       data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
+  CALL xios_set_domain_attr("domain_atm",lonvalue_2D=lon,latvalue_2D=lat)
+  CALL xios_set_domain_attr("domain_atm", nvertex=4, bounds_lon_2d=bounds_lon, bounds_lat_2d=bounds_lat)
+  print *,'latmax/min=',minval(lat),maxval(lat)
+  print *,'latmax/min bounds=',minval(bounds_lat),maxval(bounds_lat)
+  print *,'lonmax/min=',minval(lon),maxval(lon)
+  print *,'lonmax/min bounds=',minval(bounds_lon),maxval(bounds_lon)
+
+
+!!! Definition du timestep
+
+  CALL xios_get_start_date(cdate)
+  edate=cdate+xios_duration_convert_from_string(duration)
+  dtime=xios_duration_convert_from_string(timestep)
+  CALL xios_set_timestep(timestep=dtime)
+
+!!! Fin de la definition du contexte
+
+  !CALL xios_close_context_definition()
+
+!!! Calcul de temps elaps par seconde pour respecter le SYPD (hyp : pas de dÃ©lai d'I/O)
+  
+  timestep_in_seconds=xios_date_convert_to_seconds(cdate+dtime) - xios_date_convert_to_seconds(cdate)
+  simulated_seconds_per_seconds=sypd * 365 
+  elapsed_per_timestep=timestep_in_seconds/simulated_seconds_per_seconds ! in seconds
+
+!###########################################################################
+! Contexte SRF
+!###########################################################################
+
+!!! Initialisation des coordonnÃ©es globales et locales pour la grille indexee (1 point sur 2)
+
+    nb_pt=ni*nj/2
+    ALLOCATE(kindex(nb_pt),field_srf_2D(nb_pt),field_srf_3D(nb_pt,llm))
+    DO i=1,nb_pt
+      kindex(i)=2*i-1
+    ENDDO
+    field_srf_2D(1:nb_pt)=RESHAPE(field_A_glo(ibegin+1:iend+1:2,jbegin+1:jend+1,1),(/ nb_pt /))
+    field_srf_3D(1:nb_pt,:)=RESHAPE(field_A_glo(ibegin+1:iend+1:2,jbegin+1:jend+1,:),(/ nb_pt,llm /))
+
+  !CALL xios_context_initialize("surface",comm)
+  !CALL xios_get_handle("surface",ctx_hdl)
+  !CALL xios_set_current_context(ctx_hdl)
+
+  CALL xios_set_axis_attr("axis_srf",n_glo=llm ,value=lval)
+  CALL xios_set_domain_attr("domain_srf",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj, type='rectilinear')
+  CALL xios_set_domain_attr("domain_srf",data_dim=1, data_ibegin=0, data_ni=nb_pt)
+  CALL xios_set_domain_attr("domain_srf",data_i_index=kindex)
+  CALL xios_set_domain_attr("domain_srf",lonvalue_2D=lon,latvalue_2D=lat)
+  CALL xios_set_domain_attr("domain_srf", nvertex=4, bounds_lon_2d=bounds_lon, bounds_lat_2d=bounds_lat)
+
+!!! Definition du timestep
+
+  !dtime%second=timestep
+  !dtime=xios_duration_convert_from_string(timestep)
+  !CALL xios_set_timestep(timestep=dtime)
+
+!!! Fin de la definition du contexte SRF
+
+  CALL xios_close_context_definition()
+  !write(0,*) 'srf context def closed' ; call flush(0)
+
+!###########################################################################
+! Contexte OCE
+!###########################################################################
+  ALLOCATE(field_oce_2D(0:ni+1,-1:nj+2),field_oce_3D(0:ni+1,-1:nj+2,llm))
+  field_oce_2D(1:ni,1:nj)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,1)
+  field_oce_3D(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
+
+  CALL xios_context_initialize("nemo",comm)
+  CALL xios_define_calendar("Gregorian", &
+     start_date=xios_date(start_year,start_month,start_day,0,0,0), &
+     time_origin=xios_date(1850,1,1,0,0,0))
+  CALL xios_get_handle("nemo",ctx_hdl)
+  CALL xios_set_current_context(ctx_hdl)
+
+  CALL xios_set_axis_attr("axis_oce",n_glo=llm ,value=lval) ;
+
+  CALL xios_set_domain_attr("domain_oce",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj, type='curvilinear')
+  CALL xios_set_domain_attr("domain_oce",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
+  CALL xios_set_domain_attr("domain_oce",lonvalue_2D=lon,latvalue_2D=lat)
+
+
+!!! Definition du timestep
+
+  dtime=xios_duration_convert_from_string(timestep)
+  CALL xios_set_timestep(timestep=dtime)
+
+  CALL xios_close_context_definition()
+
+!####################################################################################
+!!! Boucle temporelle
+!####################################################################################
+  ts=1
+  cdate=cdate+dtime
+  DO while ( cdate <= edate )
+
+      CALL xios_get_handle("arpsfx",ctx_hdl)
+      CALL xios_set_current_context(ctx_hdl)
+
+!!! Mise a jour du pas de temps
+
+      CALL xios_update_calendar(ts)
+
+!!! On donne la valeur du champ atm
+
+      !print *,'sending field_atm_2d at timestep',ts
+      CALL xios_send_field("field_atm_scalar",field_atm_2D(1,1)+ts)
+      CALL xios_send_field("field_atm_1D",field_atm_3D(1,1,:)+ts)
+      CALL xios_send_field("field_atm_2D",field_atm_2D+ts)
+      CALL xios_send_field("field_atm_3D",field_atm_3D+ts)
+      CALL xios_send_field("pressure" ,pressure)
+      CALL xios_send_field("height"   ,height)
+      if (mod(ts,2)==0) then
+         CALL xios_send_field("field_sub",field_atm_2D+ts)
+      endif
+      !! On crÃ©e un champ avec des missings qui bougent
+      !! dans le temps : un bande verticale de 1 Ã  ni-3
+      field_atm_2D_miss(:,:)= field_atm_2D(:,:)+ts
+      field_atm_2D_miss(mod(ts,ni-3)+1,:)=1.e+20
+      CALL xios_send_field("field_miss",field_atm_2D_miss)
+      
+!!! On change de contexte
+
+      !CALL xios_get_handle("surface",ctx_hdl)
+      !CALL xios_set_current_context(ctx_hdl)
+
+!!! Mise a jour du pas de temps
+
+      !CALL xios_update_calendar(ts)
+
+!!! On donne la valeur du champ srf
+
+      CALL xios_send_field("field_srf_2D",field_srf_2D)
+      CALL xios_send_field("field_srf_3D",field_srf_3D)
+
+!!! On change de contexte
+
+      CALL xios_get_handle("nemo",ctx_hdl)
+      CALL xios_set_current_context(ctx_hdl)
+
+!!! Mise a jour du pas de temps
+
+      CALL xios_update_calendar(ts)
+
+!!! On donne la valeur du champ oce
+
+      CALL xios_send_field("field_oce_scalar",field_oce_2D(1,1)+ts)
+      CALL xios_send_field("field_oce_grid_2D",field_oce_2D)
+      CALL xios_send_field("field_oce_grid_3D",field_oce_3D)
+
+      CALL wait_us(int(elapsed_per_timestep*1.e6))   ! micro-secondes
+      cdate=cdate+dtime
+      ts=ts+1
+
+   ENDDO
+
+!####################################################################################
+!!! Finalisation
+!####################################################################################
+
+!!! Fin des contextes
+
+    CALL xios_context_finalize()
+    CALL xios_get_handle("arpsfx",ctx_hdl)
+    CALL xios_set_current_context(ctx_hdl)
+    CALL xios_context_finalize()
+    !CALL xios_get_handle("surface",ctx_hdl)
+    !CALL xios_set_current_context(ctx_hdl)
+    !CALL xios_context_finalize()
+
+    DEALLOCATE(lon, lat, lonvalue, field_atm_2D, field_atm_3D)
+    DEALLOCATE(pressure,height,pressure_glo,height_glo)
+    DEALLOCATE(kindex, field_srf_2D, field_srf_3D)
+    DEALLOCATE(field_oce_2D, field_oce_3D)
+    DEALLOCATE(lon_glo,lat_glo,field_A_glo,lval)
+
+!!! Fin de XIOS
+
+    CALL xios_finalize()
+    print*, "xios finalize OK", rank, size_loc
+    
+    !$omp master 
+    !call MPI_Barrier(comm)
+    CALL MPI_COMM_FREE(comm, ierr)
+    !$omp end master
+
+    !$omp barrier
+    
+    !$omp end parallel
+
+
+    else
+
+    CALL xios_init_server
+    print *, "Server : xios_finalize "
+  
+    endif  
+    
+
+  CALL MPI_FINALIZE(ierr)
+
+END PROGRAM toy_cmip6_omp
+
+
+
+
+
+
