Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icerst.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icerst.F90	(revision 11922)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icerst.F90	(revision 11923)
@@ -226,5 +226,5 @@
                    TRIM(cn_icerst_indir)//'/'//TRIM(Agrif_CFixed())//"_"//cn_icerst_in, ld_tmppatch = .false. )
            ELSE
-              IF(lwp) WRITE(numout,*) 'Enable SI3 restart reading by XIOS for AGRIF'
+              IF(lwp) WRITE(numout,*) 'Enable SI3 restart reading by XIOS'
               CALL iom_init( crixios_context, TRIM(cn_icerst_indir)//'/'//cn_icerst_in, ld_tmppatch = .false. )
            ENDIF
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/domain.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/domain.F90	(revision 11922)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/domain.F90	(revision 11923)
@@ -126,11 +126,4 @@
          CALL iom_set_rstw_core(rst_wfields, cdstr)
       ENDIF
-!reset namelist for SAS
-      IF(cdstr == 'SAS') THEN
-         IF(lrxios) THEN
-               IF(lwp) write(numout,*) 'Disable reading restart file using XIOS for SAS'
-               lrxios = .FALSE.
-         ENDIF
-      ENDIF
       !
       CALL dom_hgr                     ! Horizontal mesh
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom.F90	(revision 11922)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom.F90	(revision 11923)
@@ -71,8 +71,8 @@
    PRIVATE set_grid, set_grid_bounds, set_scalar, set_xmlatt, set_mooring, iom_update_file_name, iom_sdate
    PRIVATE iom_set_rst_context, iom_set_rstw_active, iom_set_rstr_active
+   PRIVATE iom_add
 # endif
    PRIVATE iom_define_restartw, iom_set_rstw_validate
    PUBLIC iom_set_rstw_var_active, iom_set_rstw_core, iom_set_rst_vars
-   PRIVATE iom_add
    INTEGER,           PRIVATE    :: numrst
    CHARACTER(len=12), PRIVATE    :: snr
@@ -569,5 +569,5 @@
    CHARACTER(len=2)  ::   zchar
    CHARACTER(len=25) ::   znam
-
+#if defined key_iomput
         i = 0
         i = iom_add(i); fields(i)%vname="rdt";            fields(i)%grid="grid_scalar"
@@ -798,4 +798,5 @@
         i = iom_add(i); fields(i)%vname="snwice_mass_b"; fields(i)%grid="grid_N"
 #endif
+#endif
    END SUBROUTINE iom_set_rst_vars
 
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/nemogcm.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/nemogcm.F90	(revision 11922)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/nemogcm.F90	(revision 11923)
@@ -194,4 +194,5 @@
       ELSE                  ;   cxios_context = 'nemo'
       ENDIF
+      cwxios_context = 'nemo_rstw'
       !
       !                             !-------------------------------------------------!
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/step.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/step.F90	(revision 11922)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/step.F90	(revision 11923)
@@ -88,5 +88,8 @@
                              indic = 0                    ! although indic is not changed in stp_ctl
                                                           ! need to keep the same interface 
-      IF( kstp == nit000 )   CALL iom_init( cxios_context ) ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
+      IF( kstp == nit000 ) THEN
+        CALL iom_init( cxios_context ) ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
+        IF( lwxios      )   CALL iom_init( cwxios_context              )  ! restart write context
+      ENDIF
       IF( kstp /= nit000 )   CALL day( kstp )             ! Calendar (day was already called at nit000 in day_init)
                              CALL iom_setkt( kstp - nit000 + 1, cxios_context )   ! tell iom we are at time step kstp
@@ -134,6 +137,4 @@
          IF(.NOT.lwxios) THEN
             CALL iom_close( numrow )     
-         ELSE
-            CALL iom_context_finalize( cwxios_context )
          ENDIF
          lrst_oce = .FALSE.
@@ -146,4 +147,7 @@
                              CALL iom_context_finalize( crxios_context)
                   ENDIF
+
+                  IF(lwxios) CALL iom_context_finalize(      cwxios_context          )
+
                              CALL iom_context_finalize( cxios_context ) ! needed for XIOS+AGRIF
       ENDIF
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/tests/ICE_AGRIF/EXPREF/iodef.xml
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/tests/ICE_AGRIF/EXPREF/iodef.xml	(revision 11922)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/tests/ICE_AGRIF/EXPREF/iodef.xml	(revision 11923)
@@ -28,4 +28,9 @@
   <context id="nemo" src="./context_nemo.xml"/>       <!--  NEMO       -->
   <context id="1_nemo" src="./1_context_nemo.xml"/>
+  <context id="nemo_rstw" src="./nemo_rstw.xml"/>
+  <context id="si3_rst" src="./si3_rst.xml"/>
+  <context id="1_nemo_rstw" src="./1_nemo_rstw.xml"/>
+  <context id="1_si3_rst" src="./1_si3_rst.xml"/>
+
 <!--
   <context id="2_nemo" src="./2_context_nemo.xml"/>  
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/tests/VORTEX/MY_SRC/domvvl.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/tests/VORTEX/MY_SRC/domvvl.F90	(revision 11922)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/tests/VORTEX/MY_SRC/domvvl.F90	(revision 11923)
@@ -247,16 +247,16 @@
       IF(lwxios) THEN
 ! define variables in restart file when writing with XIOS
-         CALL iom_set_rstw_var_active('e3t_b')
-         CALL iom_set_rstw_var_active('e3t_n')
+         CALL iom_set_rstw_var_active(rst_wfields, 'e3t_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'e3t_n')
          !                                           ! ----------------------- !
          IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN  ! z_tilde and layer cases !
             !                                        ! ----------------------- !
-            CALL iom_set_rstw_var_active('tilde_e3t_b')
-            CALL iom_set_rstw_var_active('tilde_e3t_n')
+            CALL iom_set_rstw_var_active(rst_wfields, 'tilde_e3t_b')
+            CALL iom_set_rstw_var_active(rst_wfields, 'tilde_e3t_n')
          END IF
          !                                           ! -------------!    
          IF( ln_vvl_ztilde ) THEN                    ! z_tilde case !
             !                                        ! ------------ !
-            CALL iom_set_rstw_var_active('hdiv_lf')
+            CALL iom_set_rstw_var_active(rst_wfields, 'hdiv_lf')
          ENDIF
          !
@@ -806,4 +806,5 @@
          IF( ln_rstart ) THEN                   !* Read the restart file
             CALL rst_read_open                  !  open the restart file if necessary
+            IF(lrxios) CALL iom_swap(crxios_context)
             CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn, ldxios = lrxios    )
             !
@@ -881,4 +882,6 @@
             ENDIF
             !
+            IF(lrxios) CALL iom_swap(cxios_context)
+            !
          ELSE                                   !* Initialize at "rest"
             !
