Index: branches/2012/dev_MERGE_2012/NEMOGCM/CONFIG/cfg.txt
===================================================================
--- branches/2012/dev_MERGE_2012/NEMOGCM/CONFIG/cfg.txt	(revision 3768)
+++ branches/2012/dev_MERGE_2012/NEMOGCM/CONFIG/cfg.txt	(revision 3769)
@@ -3,5 +3,4 @@
 GYRE_BFM OPA_SRC TOP_SRC
 GYRE_PISCES OPA_SRC TOP_SRC
-ORCA2_LIM OPA_SRC LIM_SRC_2 NST_SRC
 ORCA2_LIM3 OPA_SRC LIM_SRC_3
 ORCA2_LIM_PISCES OPA_SRC LIM_SRC_2 NST_SRC TOP_SRC
@@ -9,2 +8,3 @@
 ORCA2_SAS_LIM OPA_SRC SAS_SRC LIM_SRC_2 NST_SRC
 ORCA2_LIM_CFC_C14b OPA_SRC LIM_SRC_2 NST_SRC TOP_SRC
+ORCA2_LIM OPA_SRC LIM_SRC_2 NST_SRC
Index: branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90
===================================================================
--- branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 3768)
+++ branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 3769)
@@ -91,4 +91,5 @@
       istp = nit000
          !
+      CALL iom_init            ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
       DO WHILE ( istp <= nitend .AND. nstop == 0 )    ! time stepping
          !
@@ -101,4 +102,7 @@
          IF( lk_mpp )   CALL mpp_max( nstop )
       END DO
+#if defined key_iomput
+      CALL xios_context_finalize() ! needed for XIOS+AGRIF
+#endif
 
       !                            !------------------------!
@@ -250,5 +254,4 @@
       !                                     ! Dynamics
                             CALL dta_dyn_init   ! Initialization for the dynamics
-                            CALL     iom_init       ! iom_put initialization
 
       IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
Index: branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 3768)
+++ branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 3769)
@@ -359,7 +359,4 @@
          i_s = 1
          i_e = jpmax_files
-#if defined key_iomput
-         CALL xios_context_finalize()
-#endif
       ENDIF
 
Index: branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 3768)
+++ branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 3769)
@@ -194,11 +194,12 @@
       !
       CALL nemo_closefile
-#if defined key_oasis3 || defined key_oasis4
+#if defined key_iomput
+      CALL xios_finalize                ! end mpp communications with xios
+# if defined key_oasis3 || defined key_oasis4
       CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
+# endif
 #else
-# if defined key_iomput
-      IF( Agrif_Root() ) THEN
-         CALL xios_finalize             ! end mpp communications
-      ENDIF
+# if defined key_oasis3 || defined key_oasis4
+      CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
 # else
       IF( lk_mpp )   CALL mppstop       ! end mpp communications
@@ -390,5 +391,4 @@
       !                                     ! Diagnostics
       IF( lk_floats     )   CALL     flo_init   ! drifting Floats
-                            CALL     iom_init   ! iom_put initialization
       IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
                             CALL dia_ptr_init   ! Poleward TRansports initialization
Index: branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 3768)
+++ branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 3769)
@@ -30,11 +30,4 @@
    !!----------------------------------------------------------------------
    USE step_oce         ! time stepping definition modules
-#if defined key_top
-   USE trcstp           ! passive tracer time-stepping      (trc_stp routine)
-#endif
-#if defined key_agrif
-   USE agrif_opa_sponge ! Momemtum and tracers sponges
-#endif
-   USE restart          ! restart
 
    IMPLICIT NONE
@@ -89,4 +82,5 @@
 #endif
                              indic = 0                ! reset to no error condition
+      IF( kstp == nit000 )   CALL iom_init            ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
       IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
                              CALL iom_setkt( kstp - nit000 + 1 )   ! say to iom that we are at time step kstp
@@ -276,4 +270,8 @@
       IF( lk_cpl           )   CALL sbc_cpl_snd( kstp )     ! coupled mode : field exchanges
       !
+#if defined key_iomput
+      IF( kstp == nitend   )   CALL xios_context_finalize() ! needed for XIOS+AGRIF
+#endif
+      !
       IF( nn_timing == 1 .AND.  kstp == nit000  )   CALL timing_reset
       !
Index: branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/step_oce.F90
===================================================================
--- branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 3768)
+++ branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 3769)
@@ -14,4 +14,8 @@
    USE iom              !
    USE lbclnk
+   USE restart          ! restart
+#if defined key_iomput
+   USE xios
+#endif
 
    USE daymod           ! calendar                         (day     routine)
@@ -109,4 +113,7 @@
    USE agrif_opa_sponge ! Momemtum and tracers sponges
 #endif
+#if defined key_top
+   USE trcstp           ! passive tracer time-stepping      (trc_stp routine)
+#endif
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
Index: branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90
===================================================================
--- branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 3768)
+++ branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 3769)
@@ -51,5 +51,5 @@
    USE lib_mpp         ! distributed memory computing
 #if defined key_iomput
-   USE mod_ioclient
+   USE xios
 #endif
    USE sbcssm
@@ -135,5 +135,9 @@
       !
       CALL nemo_closefile
+#if defined key_iomput
+      CALL xios_finalize                ! end mpp communications with xios
+#else
       IF( lk_mpp )   CALL mppstop       ! end mpp communications
+#endif
       !
    END SUBROUTINE nemo_gcm
@@ -167,5 +171,5 @@
 #if defined key_iomput
       IF( Agrif_Root() ) THEN
-         CALL  init_ioclient( ilocal_comm )                 ! exchange io_server nemo local communicator with the io_server
+         CALL  xios_initialize( "nemo",return_comm=ilocal_comm )
       ENDIF
       narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection
@@ -258,5 +262,4 @@
                             CALL sbc_init   ! Forcings : surface module 
       
-                            CALL iom_init   ! iom_put initialization
       IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
       !
Index: branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/SAS_SRC/step.F90
===================================================================
--- branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 3768)
+++ branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 3769)
@@ -19,4 +19,7 @@
    USE iom              !
    USE lbclnk
+#if defined key_iomput
+   USE xios
+#endif
 
    USE daymod           ! calendar                         (day     routine)
@@ -72,4 +75,5 @@
 # endif   
 #endif   
+      IF( kstp == nit000 )   CALL iom_init            ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
       IF( kstp /= nit000 )   CALL day( kstp )             ! Calendar (day was already called at nit000 in day_init)
                              CALL iom_setkt( kstp )       ! say to iom that we are at time step kstp
@@ -82,4 +86,7 @@
                                                           ! need to keep the same interface 
                              CALL stp_ctl( kstp, indic )
+#if defined key_iomput
+      IF( kstp == nitend )   CALL xios_context_finalize() ! needed for XIOS+AGRIF
+#endif
       !
       IF( nn_timing == 1 .AND.  kstp == nit000  )   CALL timing_reset
