Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedia.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedia.F90	(revision 11839)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedia.F90	(revision 11840)
@@ -202,4 +202,14 @@
          IF( ice_dia_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'ice_dia_init : unable to allocate arrays' )   ! allocate tke arrays
          CALL ice_dia_rst( 'READ' )   ! read or initialize all required files
+         IF(lwxios) THEN
+            CALL iom_set_rstw_var_active(rsti_wfields, 'frc_voltop' )
+            CALL iom_set_rstw_var_active(rsti_wfields, 'frc_volbot' )
+            CALL iom_set_rstw_var_active(rsti_wfields, 'frc_temtop' )
+            CALL iom_set_rstw_var_active(rsti_wfields, 'frc_tembot' )
+            CALL iom_set_rstw_var_active(rsti_wfields, 'frc_sal'    )
+            CALL iom_set_rstw_var_active(rsti_wfields, 'vol_loc_ini')
+            CALL iom_set_rstw_var_active(rsti_wfields, 'tem_loc_ini')
+            CALL iom_set_rstw_var_active(rsti_wfields, 'sal_loc_ini')
+         ENDIF
       ENDIF
       !
@@ -267,12 +277,14 @@
          ! Write in numriw (if iter == nitrst)
          ! ------------------ 
-         CALL iom_rstput( iter, nitrst, numriw, 'frc_voltop' , frc_voltop  )
-         CALL iom_rstput( iter, nitrst, numriw, 'frc_volbot' , frc_volbot  )
-         CALL iom_rstput( iter, nitrst, numriw, 'frc_temtop' , frc_temtop  )
-         CALL iom_rstput( iter, nitrst, numriw, 'frc_tembot' , frc_tembot  )
-         CALL iom_rstput( iter, nitrst, numriw, 'frc_sal'    , frc_sal     )
-         CALL iom_rstput( iter, nitrst, numriw, 'vol_loc_ini', vol_loc_ini )
-         CALL iom_rstput( iter, nitrst, numriw, 'tem_loc_ini', tem_loc_ini )
-         CALL iom_rstput( iter, nitrst, numriw, 'sal_loc_ini', sal_loc_ini )
+         IF(lwxios) CALL iom_swap(      cwixios_context          )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_voltop' , frc_voltop,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_volbot' , frc_volbot,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_temtop' , frc_temtop,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_tembot' , frc_tembot,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_sal'    , frc_sal,     ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'vol_loc_ini', vol_loc_ini, ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'tem_loc_ini', tem_loc_ini, ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sal_loc_ini', sal_loc_ini, ldxios = lwxios )
+         IF(lwxios) CALL iom_swap(      cxios_context          )
          !
       ENDIF
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedyn_adv_pra.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedyn_adv_pra.F90	(revision 11839)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedyn_adv_pra.F90	(revision 11840)
@@ -650,4 +650,7 @@
       !!-------------------------------------------------------------------
       INTEGER ::   ierr
+      INTEGER ::   jk
+      CHARACTER(len=25) ::   znam
+      CHARACTER(len=2)  ::   zchar1
       !!-------------------------------------------------------------------
       !
@@ -671,5 +674,72 @@
       IF( ierr /= 0 )   CALL ctl_stop('STOP', 'adv_pra_init : unable to allocate ice arrays for Prather advection scheme')
       !
-      CALL adv_pra_rst( 'READ' )    !* read or initialize all required files
+      CALL adv_pra_rst( 'READ' )    !* read or initialize all required files 
+      !
+      IF(lwxios) THEN
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxice')
+         CALL iom_set_rstw_var_active(rsti_wfields, 'syice')
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxxice')
+         CALL iom_set_rstw_var_active(rsti_wfields, 'syyice')
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxyice')
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxsn'  )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sysn'  )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxxsn' )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'syysn' )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxysn' )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxa'   )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sya'   )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxxa'  )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'syya'  )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxya'  )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxsal' )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sysal' )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxxsal')
+         CALL iom_set_rstw_var_active(rsti_wfields, 'syysal')
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxysal')
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxage' )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'syage' )
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxxage')
+         CALL iom_set_rstw_var_active(rsti_wfields, 'syyage')
+         CALL iom_set_rstw_var_active(rsti_wfields, 'sxyage')
+         DO jk = 1, nlay_s
+            WRITE(zchar1,'(I2.2)') jk
+            znam = 'sxc0'//'_l'//zchar1  
+            CALL iom_set_rstw_var_active(rsti_wfields, znam )
+            znam = 'syc0'//'_l'//zchar1  
+            CALL iom_set_rstw_var_active(rsti_wfields, znam )
+            znam = 'sxxc0'//'_l'//zchar1 
+            CALL iom_set_rstw_var_active(rsti_wfields, znam )
+            znam = 'syyc0'//'_l'//zchar1 
+            CALL iom_set_rstw_var_active(rsti_wfields, znam )
+            znam = 'sxyc0'//'_l'//zchar1 
+            CALL iom_set_rstw_var_active(rsti_wfields, znam )
+         END DO
+         DO jk = 1, nlay_i
+            WRITE(zchar1,'(I2.2)') jk
+            znam = 'sxe'//'_l'//zchar1   
+            CALL iom_set_rstw_var_active(rsti_wfields, znam )
+            znam = 'sye'//'_l'//zchar1   
+            CALL iom_set_rstw_var_active(rsti_wfields, znam )
+            znam = 'sxxe'//'_l'//zchar1  
+            CALL iom_set_rstw_var_active(rsti_wfields, znam )
+            znam = 'syye'//'_l'//zchar1  
+            CALL iom_set_rstw_var_active(rsti_wfields, znam )
+            znam = 'sxye'//'_l'//zchar1  
+            CALL iom_set_rstw_var_active(rsti_wfields, znam )
+         END DO
+         !
+         IF( ln_pnd_H12 ) THEN                                       ! melt pond fraction
+            CALL iom_set_rstw_var_active(rsti_wfields, 'sxap' )
+            CALL iom_set_rstw_var_active(rsti_wfields, 'syap' )
+            CALL iom_set_rstw_var_active(rsti_wfields, 'sxxap')
+            CALL iom_set_rstw_var_active(rsti_wfields, 'syyap')
+            CALL iom_set_rstw_var_active(rsti_wfields, 'sxyap')
+            CALL iom_set_rstw_var_active(rsti_wfields, 'sxvp' )
+            CALL iom_set_rstw_var_active(rsti_wfields, 'syvp' )
+            CALL iom_set_rstw_var_active(rsti_wfields, 'sxxvp')
+            CALL iom_set_rstw_var_active(rsti_wfields, 'syyvp')
+            CALL iom_set_rstw_var_active(rsti_wfields, 'sxyvp')
+         ENDIF
+      ENDIF
       !
    END SUBROUTINE adv_pra_init
@@ -823,65 +893,92 @@
          !
          !                                                           ! ice thickness
-         CALL iom_rstput( iter, nitrst, numriw, 'sxice' , sxice  )
-         CALL iom_rstput( iter, nitrst, numriw, 'syice' , syice  )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxxice', sxxice )
-         CALL iom_rstput( iter, nitrst, numriw, 'syyice', syyice )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxyice', sxyice )
+         IF(lwxios) CALL iom_swap( TRIM(cwixios_context) )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxice' , sxice,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'syice' , syice,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxice', sxxice, ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'syyice', syyice, ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxyice', sxyice, ldxios = lwxios )
          !                                                           ! snow thickness
-         CALL iom_rstput( iter, nitrst, numriw, 'sxsn'  , sxsn   )
-         CALL iom_rstput( iter, nitrst, numriw, 'sysn'  , sysn   )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxxsn' , sxxsn  )
-         CALL iom_rstput( iter, nitrst, numriw, 'syysn' , syysn  )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxysn' , sxysn  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxsn'  , sxsn,   ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sysn'  , sysn,   ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxsn' , sxxsn,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'syysn' , syysn,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxysn' , sxysn,  ldxios = lwxios )
          !                                                           ! ice concentration
-         CALL iom_rstput( iter, nitrst, numriw, 'sxa'   , sxa    )
-         CALL iom_rstput( iter, nitrst, numriw, 'sya'   , sya    )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxxa'  , sxxa   )
-         CALL iom_rstput( iter, nitrst, numriw, 'syya'  , syya   )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxya'  , sxya   )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxa'   , sxa,    ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sya'   , sya,    ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxa'  , sxxa,   ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'syya'  , syya,   ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxya'  , sxya,   ldxios = lwxios )
          !                                                           ! ice salinity
-         CALL iom_rstput( iter, nitrst, numriw, 'sxsal' , sxsal  )
-         CALL iom_rstput( iter, nitrst, numriw, 'sysal' , sysal  )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxxsal', sxxsal )
-         CALL iom_rstput( iter, nitrst, numriw, 'syysal', syysal )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxysal', sxysal )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxsal' , sxsal,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sysal' , sysal,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxsal', sxxsal, ldxios = lwxios ) 
+         CALL iom_rstput( iter, nitrst, numriw, 'syysal', syysal, ldxios = lwxios ) 
+         CALL iom_rstput( iter, nitrst, numriw, 'sxysal', sxysal, ldxios = lwxios ) 
          !                                                           ! ice age
-         CALL iom_rstput( iter, nitrst, numriw, 'sxage' , sxage  )
-         CALL iom_rstput( iter, nitrst, numriw, 'syage' , syage  )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxxage', sxxage )
-         CALL iom_rstput( iter, nitrst, numriw, 'syyage', syyage )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxyage', sxyage )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxage' , sxage,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'syage' , syage,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxage', sxxage, ldxios = lwxios ) 
+         CALL iom_rstput( iter, nitrst, numriw, 'syyage', syyage, ldxios = lwxios ) 
+         CALL iom_rstput( iter, nitrst, numriw, 'sxyage', sxyage, ldxios = lwxios ) 
          !                                                           ! snow layers heat content
          DO jk = 1, nlay_s
             WRITE(zchar1,'(I2.2)') jk
-            znam = 'sxc0'//'_l'//zchar1  ;   z3d(:,:,:) = sxc0 (:,:,jk,:)  ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'syc0'//'_l'//zchar1  ;   z3d(:,:,:) = syc0 (:,:,jk,:)  ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'sxxc0'//'_l'//zchar1 ;   z3d(:,:,:) = sxxc0(:,:,jk,:)  ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'syyc0'//'_l'//zchar1 ;   z3d(:,:,:) = syyc0(:,:,jk,:)  ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'sxyc0'//'_l'//zchar1 ;   z3d(:,:,:) = sxyc0(:,:,jk,:)  ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+            znam = 'sxc0'//'_l'//zchar1  
+            z3d(:,:,:) = sxc0 (:,:,jk,:)  
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d,  ldxios = lwxios )
+
+            znam = 'syc0'//'_l'//zchar1  
+            z3d(:,:,:) = syc0 (:,:,jk,:)  
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d,  ldxios = lwxios )
+
+            znam = 'sxxc0'//'_l'//zchar1 
+            z3d(:,:,:) = sxxc0(:,:,jk,:)  
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d,  ldxios = lwxios )
+
+            znam = 'syyc0'//'_l'//zchar1 
+            z3d(:,:,:) = syyc0(:,:,jk,:)  
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d,  ldxios = lwxios )
+
+            znam = 'sxyc0'//'_l'//zchar1 
+            z3d(:,:,:) = sxyc0(:,:,jk,:)  
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d,  ldxios = lwxios )
          END DO
          !                                                           ! ice layers heat content
          DO jk = 1, nlay_i
             WRITE(zchar1,'(I2.2)') jk
-            znam = 'sxe'//'_l'//zchar1   ;   z3d(:,:,:) = sxe (:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'sye'//'_l'//zchar1   ;   z3d(:,:,:) = sye (:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'sxxe'//'_l'//zchar1  ;   z3d(:,:,:) = sxxe(:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'syye'//'_l'//zchar1  ;   z3d(:,:,:) = syye(:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'sxye'//'_l'//zchar1  ;   z3d(:,:,:) = sxye(:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+            znam = 'sxe'//'_l'//zchar1   
+            z3d(:,:,:) = sxe (:,:,jk,:)   
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d,  ldxios = lwxios )
+            znam = 'sye'//'_l'//zchar1   
+            z3d(:,:,:) = sye (:,:,jk,:)   
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d,  ldxios = lwxios )
+            znam = 'sxxe'//'_l'//zchar1  
+            z3d(:,:,:) = sxxe(:,:,jk,:)   
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d,  ldxios = lwxios )
+            znam = 'syye'//'_l'//zchar1  
+            z3d(:,:,:) = syye(:,:,jk,:)   
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d,  ldxios = lwxios )
+            znam = 'sxye'//'_l'//zchar1  
+            z3d(:,:,:) = sxye(:,:,jk,:)   
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d,  ldxios = lwxios )
          END DO
          !
          IF( ln_pnd_H12 ) THEN                                       ! melt pond fraction
-            CALL iom_rstput( iter, nitrst, numriw, 'sxap' , sxap  )
-            CALL iom_rstput( iter, nitrst, numriw, 'syap' , syap  )
-            CALL iom_rstput( iter, nitrst, numriw, 'sxxap', sxxap )
-            CALL iom_rstput( iter, nitrst, numriw, 'syyap', syyap )
-            CALL iom_rstput( iter, nitrst, numriw, 'sxyap', sxyap )
+            CALL iom_rstput( iter, nitrst, numriw, 'sxap' , sxap,   ldxios = lwxios )
+            CALL iom_rstput( iter, nitrst, numriw, 'syap' , syap,   ldxios = lwxios )
+            CALL iom_rstput( iter, nitrst, numriw, 'sxxap', sxxap,  ldxios = lwxios )
+            CALL iom_rstput( iter, nitrst, numriw, 'syyap', syyap,  ldxios = lwxios )
+            CALL iom_rstput( iter, nitrst, numriw, 'sxyap', sxyap,  ldxios = lwxios )
             !                                                        ! melt pond volume
-            CALL iom_rstput( iter, nitrst, numriw, 'sxvp' , sxvp  )
-            CALL iom_rstput( iter, nitrst, numriw, 'syvp' , syvp  )
-            CALL iom_rstput( iter, nitrst, numriw, 'sxxvp', sxxvp )
-            CALL iom_rstput( iter, nitrst, numriw, 'syyvp', syyvp )
-            CALL iom_rstput( iter, nitrst, numriw, 'sxyvp', sxyvp )
+            CALL iom_rstput( iter, nitrst, numriw, 'sxvp' , sxvp,   ldxios = lwxios )
+            CALL iom_rstput( iter, nitrst, numriw, 'syvp' , syvp,   ldxios = lwxios )
+            CALL iom_rstput( iter, nitrst, numriw, 'sxxvp', sxxvp,  ldxios = lwxios )
+            CALL iom_rstput( iter, nitrst, numriw, 'syyvp', syyvp,  ldxios = lwxios )
+            CALL iom_rstput( iter, nitrst, numriw, 'sxyvp', sxyvp,  ldxios = lwxios )
          ENDIF
+         !
+         IF(lwxios) CALL iom_swap( TRIM(cxios_context) )
          !
       ENDIF
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedyn_rhg_evp.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedyn_rhg_evp.F90	(revision 11839)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedyn_rhg_evp.F90	(revision 11840)
@@ -872,4 +872,10 @@
       IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialize
          !                                   ! ---------------
+         IF(lwxios) THEN
+            CALL iom_set_rstw_var_active(rsti_wfields, 'stress1_i' )
+            CALL iom_set_rstw_var_active(rsti_wfields, 'stress2_i' )
+            CALL iom_set_rstw_var_active(rsti_wfields, 'stress12_i')
+         ENDIF
+         !
          IF( ln_rstart ) THEN                   !* Read the restart file
             !
@@ -904,7 +910,9 @@
          iter = kt + nn_fsbc - 1             ! ice restarts are written at kt == nitrst - nn_fsbc + 1
          !
-         CALL iom_rstput( iter, nitrst, numriw, 'stress1_i' , stress1_i  )
-         CALL iom_rstput( iter, nitrst, numriw, 'stress2_i' , stress2_i  )
-         CALL iom_rstput( iter, nitrst, numriw, 'stress12_i', stress12_i )
+         IF(lwxios) CALL iom_swap( TRIM(cwixios_context) )
+         CALL iom_rstput( iter, nitrst, numriw, 'stress1_i' , stress1_i,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'stress2_i' , stress2_i,  ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 'stress12_i', stress12_i, ldxios = lwxios )
+         IF(lwxios) CALL iom_swap( TRIM(cxios_context) )
          !
       ENDIF
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icerst.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icerst.F90	(revision 11839)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icerst.F90	(revision 11840)
@@ -51,4 +51,5 @@
       CHARACTER(len=50)   ::   clname   ! ice output restart file name
       CHARACTER(len=256)  ::   clpath   ! full path to ice output restart file 
+      CHARACTER(LEN=52)   ::   clpname   ! ocean output restart file name including prefix for AGRIF
       !!----------------------------------------------------------------------
       !
@@ -80,5 +81,22 @@
             ENDIF
             !
-            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl )
+            IF(.NOT.lwxios) THEN
+               CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl )
+            ELSE
+#if defined key_iomput
+               cwixios_context = "si3_rstw_"//TRIM(ADJUSTL(clkt))
+               IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+                  clpname = clname
+               ELSE
+                  clpname = TRIM(Agrif_CFixed())//"_"//clname
+               ENDIF
+               CALL iom_init( cwixios_context, TRIM(clpath)//TRIM(clpname), .false. )
+               CALL xios_update_calendar(nitrst)
+               CALL iom_swap(      cxios_context          )
+#else
+               clinfo = 'Can not use XIOS in rst_opn'
+               CALL ctl_stop(TRIM(clinfo))
+#endif
+            ENDIF
             lrst_ice = .TRUE.
          ENDIF
@@ -117,19 +135,20 @@
       ! ------------------ 
       !                                                                        ! calendar control
-      CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) )      ! time-step 
-      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ) )      ! date
+      IF(lwxios) CALL iom_swap(      cwixios_context          )
+      CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ), ldxios = lwxios )      ! time-step 
+      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ), ldxios = lwxios )      ! date
       CALL iom_delay_rst( 'WRITE', 'ICE', numriw )   ! save only ice delayed global communication variables
 
       ! Prognostic variables
-      CALL iom_rstput( iter, nitrst, numriw, 'v_i'  , v_i   )
-      CALL iom_rstput( iter, nitrst, numriw, 'v_s'  , v_s   )
-      CALL iom_rstput( iter, nitrst, numriw, 'sv_i' , sv_i  )
-      CALL iom_rstput( iter, nitrst, numriw, 'a_i'  , a_i   )
-      CALL iom_rstput( iter, nitrst, numriw, 't_su' , t_su  )
-      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice )
-      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice )
-      CALL iom_rstput( iter, nitrst, numriw, 'oa_i' , oa_i  )
-      CALL iom_rstput( iter, nitrst, numriw, 'a_ip' , a_ip  )
-      CALL iom_rstput( iter, nitrst, numriw, 'v_ip' , v_ip  )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_i'  , v_i, ldxios = lwxios   )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_s'  , v_s, ldxios = lwxios   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sv_i' , sv_i, ldxios = lwxios  )
+      CALL iom_rstput( iter, nitrst, numriw, 'a_i'  , a_i, ldxios = lwxios   )
+      CALL iom_rstput( iter, nitrst, numriw, 't_su' , t_su, ldxios = lwxios  )
+      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice, ldxios = lwxios )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice, ldxios = lwxios )
+      CALL iom_rstput( iter, nitrst, numriw, 'oa_i' , oa_i, ldxios = lwxios  )
+      CALL iom_rstput( iter, nitrst, numriw, 'a_ip' , a_ip, ldxios = lwxios  )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_ip' , v_ip, ldxios = lwxios  )
       ! Snow enthalpy
       DO jk = 1, nlay_s 
@@ -137,5 +156,5 @@
          znam = 'e_s'//'_l'//zchar1
          z3d(:,:,:) = e_s(:,:,jk,:)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+         CALL iom_rstput( iter, nitrst, numriw, znam , z3d, ldxios = lwxios )
       END DO
       ! Ice enthalpy
@@ -144,11 +163,12 @@
          znam = 'e_i'//'_l'//zchar1
          z3d(:,:,:) = e_i(:,:,jk,:)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+         CALL iom_rstput( iter, nitrst, numriw, znam , z3d, ldxios = lwxios )
       END DO
       ! fields needed for Met Office (Jules) coupling
       IF( ln_cpl ) THEN
-         CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice )
-         CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice  )
-      ENDIF
+         CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice, ldxios = lwxios )
+         CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice, ldxios = lwxios  )
+      ENDIF
+      IF(lwxios) CALL iom_swap(      cxios_context          )
       !
 
@@ -156,5 +176,9 @@
       ! ------------------
       IF( iter == nitrst ) THEN
-         CALL iom_close( numriw )
+         IF(lwxios) THEN
+            CALL iom_context_finalize(      cwixios_context          )
+         ELSE
+            CALL iom_close( numriw )
+         ENDIF
          lrst_ice = .FALSE.
       ENDIF
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icestp.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icestp.F90	(revision 11839)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icestp.F90	(revision 11840)
@@ -239,4 +239,8 @@
       CALL par_init                ! set some ice run parameters
       !
+      IF(lwxios) THEN
+        CALL iom_set_rst_vars(rsti_wfields)
+        CALL iom_set_rstw_core(rsti_wfields, "SI3")
+      ENDIF
       !                                ! Allocate the ice arrays (sbc_ice already allocated in sbc_init)
       ierr =        ice_alloc        ()      ! ice variables
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/iceupdate.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/iceupdate.F90	(revision 11839)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/iceupdate.F90	(revision 11840)
@@ -398,4 +398,8 @@
       !
       CALL update_rst( 'READ' )  !* read or initialize all required files
+      IF( lwxios ) THEN
+         CALL iom_set_rstw_var_active(rsti_wfields, 'snwice_mass')
+         CALL iom_set_rstw_var_active(rsti_wfields, 'snwice_mass_b')
+      ENDIF
       !
    END SUBROUTINE ice_update_init
@@ -444,6 +448,8 @@
          iter = kt + nn_fsbc - 1             ! ice restarts are written at kt == nitrst - nn_fsbc + 1
          !
-         CALL iom_rstput( iter, nitrst, numriw, 'snwice_mass'  , snwice_mass   )
-         CALL iom_rstput( iter, nitrst, numriw, 'snwice_mass_b', snwice_mass_b )
+         IF(lwxios) CALL iom_swap(      cwixios_context          )
+         CALL iom_rstput( iter, nitrst, numriw, 'snwice_mass'  , snwice_mass, ldxios = lwxios   )
+         CALL iom_rstput( iter, nitrst, numriw, 'snwice_mass_b', snwice_mass_b, ldxios = lwxios )
+         IF(lwxios) CALL iom_swap(      cxios_context          )
          !
       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 11839)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/domain.F90	(revision 11840)
@@ -124,5 +124,5 @@
 !define names for restart write and set core output (restart.F90)
          CALL iom_set_rst_vars(rst_wfields)
-         CALL iom_set_rstw_core(cdstr)
+         CALL iom_set_rstw_core(rst_wfields, cdstr)
       ENDIF
 !reset namelist for SAS
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/in_out_manager.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/in_out_manager.F90	(revision 11839)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/in_out_manager.F90	(revision 11840)
@@ -171,4 +171,5 @@
    CHARACTER(lc) ::   cwxios_context        !: context name used in xios to write NEMO restart file
    CHARACTER(lc) ::   crixios_context       !: context name used in xios to read SI3 restart
+   CHARACTER(lc) ::   cwixios_context       !: context name used in xios to write SI3 restart
    LOGICAL       ::   lrsi3_nemo            !: is SI3 irestart in nemo format
 
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 11839)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom.F90	(revision 11840)
@@ -244,7 +244,11 @@
 !set names of the fields in restart file IF using XIOS to write data
           CALL iom_set_rst_context(.FALSE.)
-          CALL iom_set_rst_vars(rst_wfields)
 !set which fields are to be written to a restart file
           CALL iom_set_rstw_active(rst_wfields, fname)
+      ELSE IF( TRIM(cdname) == TRIM(cwixios_context) ) THEN
+!set names of the fields in restart file IF using XIOS to write data
+          CALL iom_set_rst_context(.FALSE.)
+!set which fields are to be written to a restart file
+          CALL iom_set_rstw_active(rsti_wfields, fname)
       ELSE
           CALL set_xmlatt
@@ -361,5 +365,5 @@
    END SUBROUTINE iom_set_rstr_active
 
-   SUBROUTINE iom_set_rstw_core(cdmdl)
+   SUBROUTINE iom_set_rstw_core(drst_wfields, cdmdl)
       !!---------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_set_rstw_core  ***
@@ -367,39 +371,67 @@
       !! ** Purpose :  set variables which are always in restart file 
       !!---------------------------------------------------------------------
-   CHARACTER (len=*), INTENT (IN) :: cdmdl ! model OPA or SAS
-   CHARACTER(LEN=256)             :: clinfo    ! info character
+   CHARACTER (len=*), INTENT (IN)   :: cdmdl ! model OPA, SAS or SI3
+   TYPE(RST_FIELD),   INTENT(INOUT) :: drst_wfields(max_rst_fields)
+   CHARACTER(LEN=256)               :: clinfo    ! info character
+   CHARACTER(len=25) ::   znam
+   CHARACTER(len=2)  ::   zchar1
+   INTEGER           ::   jk
 #if defined key_iomput
    IF(cdmdl == "OPA") THEN
 !from restart.F90
-   CALL iom_set_rstw_var_active(rst_wfields, "rdt")
+   CALL iom_set_rstw_var_active(drst_wfields, "rdt")
    IF ( .NOT. ln_diurnal_only ) THEN
-        CALL iom_set_rstw_var_active(rst_wfields, 'ub'  )
-        CALL iom_set_rstw_var_active(rst_wfields, 'vb'  )
-        CALL iom_set_rstw_var_active(rst_wfields, 'tb'  )
-        CALL iom_set_rstw_var_active(rst_wfields, 'sb'  )
-        CALL iom_set_rstw_var_active(rst_wfields, 'sshb')
+        CALL iom_set_rstw_var_active(drst_wfields, 'ub'  )
+        CALL iom_set_rstw_var_active(drst_wfields, 'vb'  )
+        CALL iom_set_rstw_var_active(drst_wfields, 'tb'  )
+        CALL iom_set_rstw_var_active(drst_wfields, 'sb'  )
+        CALL iom_set_rstw_var_active(drst_wfields, 'sshb')
         !
-        CALL iom_set_rstw_var_active(rst_wfields, 'un'  )
-        CALL iom_set_rstw_var_active(rst_wfields, 'vn'  )
-        CALL iom_set_rstw_var_active(rst_wfields, 'tn'  )
-        CALL iom_set_rstw_var_active(rst_wfields, 'sn'  )
-        CALL iom_set_rstw_var_active(rst_wfields, 'sshn')
-        CALL iom_set_rstw_var_active(rst_wfields, 'rhop')
+        CALL iom_set_rstw_var_active(drst_wfields, 'un'  )
+        CALL iom_set_rstw_var_active(drst_wfields, 'vn'  )
+        CALL iom_set_rstw_var_active(drst_wfields, 'tn'  )
+        CALL iom_set_rstw_var_active(drst_wfields, 'sn'  )
+        CALL iom_set_rstw_var_active(drst_wfields, 'sshn')
+        CALL iom_set_rstw_var_active(drst_wfields, 'rhop')
      ! extra variable needed for the ice sheet coupling
         IF ( ln_iscpl ) THEN
-             CALL iom_set_rstw_var_active(rst_wfields, 'tmask')
-             CALL iom_set_rstw_var_active(rst_wfields, 'umask')
-             CALL iom_set_rstw_var_active(rst_wfields, 'vmask')
-             CALL iom_set_rstw_var_active(rst_wfields, 'smask')
-             CALL iom_set_rstw_var_active(rst_wfields, 'e3t_n')
-             CALL iom_set_rstw_var_active(rst_wfields, 'e3u_n')
-             CALL iom_set_rstw_var_active(rst_wfields, 'e3v_n')
-             CALL iom_set_rstw_var_active(rst_wfields, 'gdepw_n')
+             CALL iom_set_rstw_var_active(drst_wfields, 'tmask')
+             CALL iom_set_rstw_var_active(drst_wfields, 'umask')
+             CALL iom_set_rstw_var_active(drst_wfields, 'vmask')
+             CALL iom_set_rstw_var_active(drst_wfields, 'smask')
+             CALL iom_set_rstw_var_active(drst_wfields, 'e3t_n')
+             CALL iom_set_rstw_var_active(drst_wfields, 'e3u_n')
+             CALL iom_set_rstw_var_active(drst_wfields, 'e3v_n')
+             CALL iom_set_rstw_var_active(drst_wfields, 'gdepw_n')
         END IF
       ENDIF
-      IF(ln_diurnal) CALL iom_set_rstw_var_active(rst_wfields, 'Dsst')
+      IF(ln_diurnal) CALL iom_set_rstw_var_active(drst_wfields, 'Dsst')
 !from trasbc.F90
-         CALL iom_set_rstw_var_active(rst_wfields, 'sbc_hc_b')
-         CALL iom_set_rstw_var_active(rst_wfields, 'sbc_sc_b')
+         CALL iom_set_rstw_var_active(drst_wfields, 'sbc_hc_b')
+         CALL iom_set_rstw_var_active(drst_wfields, 'sbc_sc_b')
+   ELSE IF(cdmdl == "SI3") THEN
+      CALL iom_set_rstw_var_active(drst_wfields, 'nn_fsbc')
+      CALL iom_set_rstw_var_active(drst_wfields, 'kt_ice')
+      CALL iom_set_rstw_var_active(drst_wfields, 'v_i')
+      CALL iom_set_rstw_var_active(drst_wfields, 'v_s')
+      CALL iom_set_rstw_var_active(drst_wfields, 'sv_i')
+      CALL iom_set_rstw_var_active(drst_wfields, 'a_i')
+      CALL iom_set_rstw_var_active(drst_wfields, 't_su')
+      CALL iom_set_rstw_var_active(drst_wfields, 'u_ice')
+      CALL iom_set_rstw_var_active(drst_wfields, 'v_ice')
+      CALL iom_set_rstw_var_active(drst_wfields, 'oa_i')
+      CALL iom_set_rstw_var_active(drst_wfields, 'a_ip')
+      CALL iom_set_rstw_var_active(drst_wfields, 'v_ip')
+      DO jk = 1, nlay_s 
+         WRITE(zchar1,'(I2.2)') jk
+         znam = 'e_s'//'_l'//zchar1
+         CALL iom_set_rstw_var_active(drst_wfields, znam )
+      END DO
+      ! Ice enthalpy
+      DO jk = 1, nlay_i 
+         WRITE(zchar1,'(I2.2)') jk
+         znam = 'e_i'//'_l'//zchar1
+         CALL iom_set_rstw_var_active(drst_wfields, znam )
+      END DO
    ENDIF
 #else
@@ -689,4 +721,7 @@
                 CALL xios_add_child(file_hdl, field_hdl, TRIM(drst_wfields(i)%vname))
                 SELECT CASE (TRIM(drst_wfields(i)%grid))
+                 CASE ("grid_Ni_3D")
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
+                        domain_ref="grid_N", axis_ref="numcat", prec = 8, operation = "instant")
                  CASE ("grid_N_3D")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom_def.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom_def.F90	(revision 11839)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom_def.F90	(revision 11840)
@@ -67,5 +67,5 @@
    END TYPE file_descriptor
    TYPE(file_descriptor), DIMENSION(jpmax_files), PUBLIC ::   iom_file !: array containing the info for all opened files
-   INTEGER, PARAMETER, PUBLIC                   :: max_rst_fields = 360!: maximum number of restart variables defined in iom_set_rst_vars
+   INTEGER, PARAMETER, PUBLIC                   :: max_rst_fields = 190!: maximum number of restart variables defined in iom_set_rst_vars
    TYPE, PUBLIC :: RST_FIELD  
     CHARACTER(len=30) :: vname = "NO_NAME" ! names of variables in restart file
@@ -75,5 +75,5 @@
 !$AGRIF_END_DO_NOT_TREAT
    !
-   TYPE(RST_FIELD), PUBLIC, SAVE :: rst_wfields(max_rst_fields), rst_rfields(max_rst_fields)
+   TYPE(RST_FIELD), PUBLIC, SAVE :: rst_wfields(max_rst_fields), rst_rfields(max_rst_fields), rsti_wfields(max_rst_fields)
    !
    !!----------------------------------------------------------------------
