Index: XIOS/dev/branch_yushan/src/test/test_complete.f90
===================================================================
--- XIOS/dev/branch_yushan/src/test/test_complete.f90	(revision 1102)
+++ XIOS/dev/branch_yushan/src/test/test_complete.f90	(revision 1109)
@@ -5,5 +5,5 @@
   IMPLICIT NONE
   INCLUDE "mpif.h"
-  INTEGER :: rank
+  INTEGER :: rank, size
   INTEGER :: size_loc
   INTEGER :: ierr
@@ -28,11 +28,13 @@
   INTEGER, ALLOCATABLE :: kindex(:)
   INTEGER :: ni,ibegin,iend,nj,jbegin,jend
-  INTEGER :: i,j,l,ts,n, nb_pt
+  INTEGER :: i,j,l,ts,n, nb_pt, provided
 
 !!! MPI Initialization
 
-  CALL MPI_INIT(ierr)
-
-  CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)  
+  CALL MPI_INIT_THREAD(3, provided, ierr)
+    if(provided .NE. 3) then
+      print*, "provided thread level = ", provided
+      call MPI_Abort()
+    endif 
 
   
@@ -40,5 +42,7 @@
   CALL init_wait
 
-  if (rank <2) then
+  CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)
+  CALL MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierr)
+  if(rank < size-1) then
 
 !!! XIOS Initialization (get the local communicator)
@@ -86,5 +90,4 @@
 
   CALL xios_context_initialize("atmosphere",comm)
-!   print*, "init context atmosphere comm = ", comm
 
   CALL xios_get_handle("atmosphere",ctx_hdl)
@@ -96,5 +99,4 @@
 
   CALL xios_set_axis_attr("axis_atm",n_glo=llm ,value=lval) ;
-!  CALL xios_set_zoom_axis_attr("axis_atm_zoom",n=2);
 
   CALL xios_set_domain_attr("domain_atm",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj, type='curvilinear')
@@ -105,5 +107,5 @@
   CALL xios_set_domain_attr("domain_atm_zoom",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
   CALL xios_set_domain_attr("domain_atm_zoom",lonvalue_2D=lon,latvalue_2D=lat)
-!  CALL xios_set_zoom_domain_attr("domain_atm_zoom",ibegin=39, ni=20, jbegin=39, nj=5)
+
 
 !!! Activation du groupe field_definition
@@ -143,5 +145,5 @@
   CALL xios_close_context_definition()
 
-!   print *, "xios_close_context_definition(atmosphere)"
+   print *, "xios_close_context_definition(atmosphere)"
 
 !!! Test des valeurs des champs/fichiers
@@ -180,5 +182,5 @@
 
   CALL xios_context_initialize("surface",comm)
-!   print*, "init context surface comm = ", comm
+
 
   CALL xios_get_handle("surface",ctx_hdl)
@@ -227,5 +229,5 @@
   CALL xios_close_context_definition()
 
-!  print *, "xios_close_context_definition(surface)" 
+  print *, "xios_close_context_definition(surface)" 
 
 
@@ -266,5 +268,5 @@
     ENDDO
 
-!     print *, "end temporal loop"
+     print *, "end temporal loop"
 
 !####################################################################################
@@ -274,38 +276,43 @@
 !!! Fin des contextes
 
-    !print *, "start : xios_context_finalize(surface)"
 
     CALL xios_get_handle("surface",ctx_hdl) 
-    !print *, "xios_get_handle (surface) OK"
+
     CALL xios_set_current_context(ctx_hdl)
-    !print *, "xios_set_current_context (surface) OK"
+
     CALL xios_context_finalize()
 
-!     print *, "xios_context_finalize(surface)" 
+    print *, "xios_context_finalize(surface)" 
 
      CALL xios_get_handle("atmosphere",ctx_hdl)
-!     !print *, "xios_get_handle (atmosphere) OK"
+
      CALL xios_set_current_context(ctx_hdl)
-!     !print *, "xios_set_current_context (atmosphere) OK"
+
      CALL xios_context_finalize()
 
-!     print *, "xios_context_finalize(atmosphere)"
+     print *, "xios_context_finalize(atmosphere)"
+
+    
+
+!!! Fin de XIOS
+
+    
+
+    CALL xios_finalize()
 
     DEALLOCATE(lon, lat, field_A_atm, lonvalue)
-   ! DEALLOCATE(kindex, field_A_srf)
-
-!!! Fin de XIOS
+    DEALLOCATE(kindex, field_A_srf)
+
+     print *, "Client : xios_finalize "
 
     CALL MPI_COMM_FREE(comm, ierr)
 
-    CALL xios_finalize()
-
-     print *, "Client : xios_finalize "
-
-  else 
+  else
+
     CALL xios_init_server
-
     print *, "Server : xios_finalize "
-  endif
+  
+    endif
+
 
     CALL MPI_FINALIZE(ierr)
Index: XIOS/dev/branch_yushan/src/test/test_complete_omp.f90
===================================================================
--- XIOS/dev/branch_yushan/src/test/test_complete_omp.f90	(revision 1109)
+++ XIOS/dev/branch_yushan/src/test/test_complete_omp.f90	(revision 1109)
@@ -0,0 +1,340 @@
+PROGRAM test_complete_omp
+
+  USE xios
+  USE mod_wait
+  use omp_lib
+  IMPLICIT NONE
+  INCLUDE "mpif.h"
+  INTEGER :: rank, size
+  INTEGER :: size_loc
+  INTEGER :: ierr
+
+  CHARACTER(len=*),PARAMETER :: id="client"
+  INTEGER :: comm, comm2
+  TYPE(xios_duration)  :: dtime
+  TYPE(xios_context) :: ctx_hdl
+  INTEGER,PARAMETER :: ni_glo=100
+  INTEGER,PARAMETER :: nj_glo=100
+  INTEGER,PARAMETER :: llm=5
+  DOUBLE PRECISION  :: lval(llm)=1
+  TYPE(xios_field) :: field_hdl
+  TYPE(xios_fieldgroup) :: fieldgroup_hdl
+  TYPE(xios_file) :: file_hdl
+  LOGICAL :: ok
+  CHARACTER(len=256) :: crname
+
+  DOUBLE PRECISION,DIMENSION(ni_glo,nj_glo) :: lon_glo,lat_glo
+  DOUBLE PRECISION :: field_A_glo(ni_glo,nj_glo,llm)
+  DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),field_A_atm(:,:,:), field_A_srf(:,:), lonvalue(:,:)
+  INTEGER, ALLOCATABLE :: kindex(:)
+  INTEGER :: ni,ibegin,iend,nj,jbegin,jend
+  INTEGER :: i,j,l,ts,n, nb_pt, provided
+
+!!! 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,ierr)
+  if(rank < size-1) then
+
+  !$omp parallel default(private)
+
+!!! 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)
+
+  size_loc = size*omp_get_num_threads()
+  rank = rank*omp_get_num_threads() + omp_get_thread_num()
+
+
+!###########################################################################
+! Contexte ATM
+!###########################################################################
+
+!!! Initialisation des coordonnes globales et locales pour la grille rgulire
+
+  DO j=1,nj_glo
+    DO i=1,ni_glo
+      lon_glo(i,j)=(i-1)+(j-1)*ni_glo
+      lat_glo(i,j)=1000+(i-1)+(j-1)*ni_glo
+      DO l=1,llm
+        field_A_glo(i,j,l)=(i-1)+(j-1)*ni_glo+10000*l
+      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),field_A_atm(0:ni+1,-1:nj+2,llm),lonvalue(ni,nj))
+  lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1)
+  lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1)
+  field_A_atm(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
+
+
+!!! Context ATMOSPHERE
+
+  CALL xios_context_initialize("atmosphere",comm)
+
+  CALL xios_get_handle("atmosphere",ctx_hdl)
+  CALL xios_set_current_context(ctx_hdl)
+
+  CALL xios_define_calendar(type="Gregorian", &
+                            start_date=xios_date(2000, 01, 01, 00, 00, 00), &
+                            time_origin=xios_date(1999, 01, 01, 15, 00, 00))
+
+  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='curvilinear')
+  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_zoom",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj)
+  CALL xios_set_domain_attr("domain_atm_zoom",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
+  CALL xios_set_domain_attr("domain_atm_zoom",lonvalue_2D=lon,latvalue_2D=lat)
+
+
+!!! Activation du groupe field_definition
+
+  CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.)
+
+!!! Cration d un nouveau champ
+
+  CALL xios_get_handle("field_definition",fieldgroup_hdl)
+  CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B_atm")
+
+!!! Heritage des attributs d un autre champ
+
+  CALL xios_set_attr(field_hdl,field_ref="field_A_atm_zoom",name="field_B_atm")
+
+!!! Affectation de ce nouveau champ au fichier avec un nouveau nom
+
+  CALL xios_get_handle("output_atmosphere",file_hdl)
+  CALL xios_add_child(file_hdl,field_hdl)
+  CALL xios_set_attr(field_hdl,field_ref="field_B_atm",name="field_C_atm")
+
+!!! Definition du timestep
+
+  dtime%second=3600
+  CALL xios_set_timestep(timestep=dtime)
+
+!!! Recupration des valeurs des longitudes et de taille des domaines locaux (pour test de fonctionnalit)
+
+  ni=0 ; lonvalue(:,:)=0
+  CALL xios_get_domain_attr("domain_atm",ni=ni,lonvalue_2D=lonvalue)
+
+  !PRINT *,"ni",ni
+  !PRINT *,"lonvalue",lonvalue;
+
+!!! Fin de la definition du contexte
+
+  CALL xios_close_context_definition()
+
+   print *, "xios_close_context_definition(atmosphere)"
+
+!!! Test des valeurs des champs/fichiers
+
+  !!! Attribut defini ?
+
+  CALL xios_is_defined_field_attr("field_A_atm",enabled=ok)
+  PRINT *,"field_A_atm : attribute enabled is defined ? ",ok
+
+  !!! Recuperer la valeur d un attribut
+
+  CALL xios_get_field_attr("field_A_atm",name=crname)
+  PRINT *,"field_A_atm : attribute name is : ",TRIM(crname)
+
+  !!! Champ actif (besoin de fournir la valeur) ?
+
+    PRINT*,"field field_A_atm is active ? ",xios_field_is_active("field_A_atm")
+
+  !!! Champ defini ?
+
+    PRINT*,"field field_A_atm is valid ?",xios_is_valid_field("field_A_atm")
+
+
+!###########################################################################
+! Contexte SRF
+!###########################################################################
+
+!!! Initialisation des coordonnes globales et locales pour la grille indexee (1 point sur 2)
+
+    nb_pt=ni*nj/2
+    ALLOCATE(kindex(nb_pt),field_A_srf(nb_pt,llm))
+    DO i=1,nb_pt
+      kindex(i)=2*i-1
+    ENDDO
+    field_A_srf(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_define_calendar(type="Gregorian", &
+                            start_date=xios_date(2000, 01, 01, 00, 00, 00), &
+                            time_origin=xios_date(1999, 01, 01, 15, 00, 00))
+
+  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='curvilinear')
+  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)
+
+!!! Cration d un nouveau champ
+
+  CALL xios_get_handle("field_definition",fieldgroup_hdl)
+  CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B_srf")
+
+!!! Heritage des attributs d un autre champ
+
+  CALL xios_set_attr(field_hdl,field_ref="field_A_srf",name="field_B_srf")
+
+!!! Affectation de ce nouveau champ au fichier avec un nouveau nom
+
+  CALL xios_get_handle("output_surface",file_hdl)
+  CALL xios_add_child(file_hdl,field_hdl)
+  CALL xios_set_attr(field_hdl,field_ref="field_B_srf",name="field_C_srf")
+
+!!! Definition du timestep
+
+  dtime%second=1800
+  CALL xios_set_timestep(timestep=dtime)
+
+!!! Recupration des valeurs des longitudes et de taille des domaines locaux (pour test de fonctionnalit)
+
+  ni=0 ; lonvalue(:,:)=0
+  CALL xios_get_domain_attr("domain_srf",ni=ni,lonvalue_2D=lonvalue)
+
+  !PRINT *,"ni",ni
+  !PRINT *,"lonvalue",lonvalue ;
+
+!!! Fin de la definition du contexte SRF
+
+  CALL xios_close_context_definition()
+
+  print *, "xios_close_context_definition(surface)" 
+
+
+!####################################################################################
+!!! Boucle temporelle
+!####################################################################################
+
+    DO ts=1,24*10
+    !DO ts=1,24
+
+      CALL xios_get_handle("atmosphere",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
+
+      CALL xios_send_field("field_A_atm",field_A_atm)
+
+!!! 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_A_srf",field_A_srf)
+
+      CALL wait_us(5000) ;
+
+
+    ENDDO
+
+     print *, "end temporal loop"
+
+!####################################################################################
+!!! Finalisation
+!####################################################################################
+
+!!! Fin des contextes
+
+
+    CALL xios_get_handle("surface",ctx_hdl) 
+
+    CALL xios_set_current_context(ctx_hdl)
+
+    CALL xios_context_finalize()
+
+    print *, "xios_context_finalize(surface)" 
+
+     CALL xios_get_handle("atmosphere",ctx_hdl)
+
+     CALL xios_set_current_context(ctx_hdl)
+
+     CALL xios_context_finalize()
+
+     print *, "xios_context_finalize(atmosphere)"
+
+    
+
+!!! Fin de XIOS
+
+    
+
+    CALL xios_finalize()
+
+    DEALLOCATE(lon, lat, field_A_atm, lonvalue)
+    DEALLOCATE(kindex, field_A_srf)
+
+     print *, "Client : xios_finalize "
+
+    !$omp master
+    CALL MPI_COMM_FREE(comm, ierr)
+    !$omp end master
+
+    !$omp barrier
+
+    print*, "MPI_COMM_FREE OK", rank, size_loc
+
+  !$omp end parallel
+
+  else
+
+    CALL xios_init_server
+    print *, "Server : xios_finalize "
+  
+    endif
+
+
+    CALL MPI_FINALIZE(ierr)
+
+  END PROGRAM test_complete_omp
+
+
+
+
+
+
Index: XIOS/dev/branch_yushan/src/test/test_omp.f90
===================================================================
--- XIOS/dev/branch_yushan/src/test/test_omp.f90	(revision 1102)
+++ XIOS/dev/branch_yushan/src/test/test_omp.f90	(revision 1109)
@@ -44,5 +44,6 @@
 
     CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)
-    if(rank < 2) then
+    CALL MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierr)
+    if(rank < size-1) then
 
     !$omp parallel default(private)
@@ -100,13 +101,13 @@
     CALL xios_set_domain_attr("domain_A",lonvalue_2D=lon,latvalue_2D=lat)
     CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.)
-!     print*, "test block OK", rank, size
+     print*, "test block OK", rank, size
 
-!   CALL xios_get_handle("field_definition",fieldgroup_hdl)
-!   CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B")
-!   CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B")
+    CALL xios_get_handle("field_definition",fieldgroup_hdl)
+    CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B")
+    CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B")
 
-!   CALL xios_get_handle("output",file_hdl)
-!   CALL xios_add_child(file_hdl,field_hdl)
-!   CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_C")
+    CALL xios_get_handle("output",file_hdl)
+    CALL xios_add_child(file_hdl,field_hdl)
+    CALL xios_set_attr(field_hdl,field_ref="field_A_zoom",name="field_C")
 
     dtime%second = 3600
@@ -158,4 +159,8 @@
     print*, "xios_context_finalize OK", rank, size
 
+    CALL xios_finalize()
+    print*, "xios finalize OK", rank, size
+
+    DEALLOCATE(lon, lat, field_A, lonvalue)
     !$omp master 
     !call MPI_Barrier(comm)
@@ -167,8 +172,4 @@
      print*, "MPI_COMM_FREE OK", rank, size
 
-    CALL xios_finalize()
-    print*, "xios finalize OK", rank, size
-
-    DEALLOCATE(lon, lat, field_A, lonvalue)
 
 
