Index: /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/icedia.F90
===================================================================
--- /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/icedia.F90	(revision 12956)
+++ /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/icedia.F90	(revision 12957)
@@ -221,16 +221,18 @@
          IF( ln_rstart ) THEN                   !* Read the restart file
             !
-            CALL iom_get( numrir, 'kt_ice' , ziter )
+            IF(lrxios) CALL iom_swap(crixios_context)
+            CALL iom_get( numrir, 'kt_ice' , ziter, ldxios = lrxios )
             IF(lwp) WRITE(numout,*)
             IF(lwp) WRITE(numout,*) 'ice_dia_rst read at time step = ', ziter
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
-            CALL iom_get( numrir, 'frc_voltop' , frc_voltop  )
-            CALL iom_get( numrir, 'frc_volbot' , frc_volbot  )
-            CALL iom_get( numrir, 'frc_temtop' , frc_temtop  )
-            CALL iom_get( numrir, 'frc_tembot' , frc_tembot  )
-            CALL iom_get( numrir, 'frc_sal'    , frc_sal     )
-            CALL iom_get( numrir, jpdom_autoglo, 'vol_loc_ini', vol_loc_ini )
-            CALL iom_get( numrir, jpdom_autoglo, 'tem_loc_ini', tem_loc_ini )
-            CALL iom_get( numrir, jpdom_autoglo, 'sal_loc_ini', sal_loc_ini )
+            CALL iom_get( numrir, 'frc_voltop' , frc_voltop, ldxios = lrxios  )
+            CALL iom_get( numrir, 'frc_volbot' , frc_volbot, ldxios = lrxios  )
+            CALL iom_get( numrir, 'frc_temtop' , frc_temtop, ldxios = lrxios  )
+            CALL iom_get( numrir, 'frc_tembot' , frc_tembot, ldxios = lrxios  )
+            CALL iom_get( numrir, 'frc_sal'    , frc_sal, ldxios = lrxios     )
+            CALL iom_get( numrir, jpdom_autoglo, 'vol_loc_ini', vol_loc_ini, ldxios = lrxios )
+            CALL iom_get( numrir, jpdom_autoglo, 'tem_loc_ini', tem_loc_ini, ldxios = lrxios )
+            CALL iom_get( numrir, jpdom_autoglo, 'sal_loc_ini', sal_loc_ini, ldxios = lrxios )
+            IF(lrxios) CALL iom_swap(cxios_context)
          ELSE
             IF(lwp) WRITE(numout,*)
@@ -261,12 +263,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/2020/dev_12905_xios_restart/src/ICE/icedyn_adv_pra.F90
===================================================================
--- /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/icedyn_adv_pra.F90	(revision 12956)
+++ /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/icedyn_adv_pra.F90	(revision 12957)
@@ -770,67 +770,79 @@
          !
          IF( id1 > 0 ) THEN                     !**  Read the restart file  **!
+            IF(lrxios) CALL iom_swap(crixios_context)
             !
             !                                                        ! ice thickness
-            CALL iom_get( numrir, jpdom_autoglo, 'sxice' , sxice  )
-            CALL iom_get( numrir, jpdom_autoglo, 'syice' , syice  )
-            CALL iom_get( numrir, jpdom_autoglo, 'sxxice', sxxice )
-            CALL iom_get( numrir, jpdom_autoglo, 'syyice', syyice )
-            CALL iom_get( numrir, jpdom_autoglo, 'sxyice', sxyice )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxice' , sxice, ldxios = lrxios  )
+            CALL iom_get( numrir, jpdom_autoglo, 'syice' , syice, ldxios = lrxios  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxice', sxxice, ldxios = lrxios )
+            CALL iom_get( numrir, jpdom_autoglo, 'syyice', syyice, ldxios = lrxios )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxyice', sxyice, ldxios = lrxios )
             !                                                        ! snow thickness
-            CALL iom_get( numrir, jpdom_autoglo, 'sxsn'  , sxsn   )
-            CALL iom_get( numrir, jpdom_autoglo, 'sysn'  , sysn   )
-            CALL iom_get( numrir, jpdom_autoglo, 'sxxsn' , sxxsn  )
-            CALL iom_get( numrir, jpdom_autoglo, 'syysn' , syysn  )
-            CALL iom_get( numrir, jpdom_autoglo, 'sxysn' , sxysn  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxsn'  , sxsn, ldxios = lrxios   )
+            CALL iom_get( numrir, jpdom_autoglo, 'sysn'  , sysn, ldxios = lrxios   )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxsn' , sxxsn, ldxios = lrxios  )
+            CALL iom_get( numrir, jpdom_autoglo, 'syysn' , syysn, ldxios = lrxios  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxysn' , sxysn, ldxios = lrxios  )
             !                                                        ! ice concentration
-            CALL iom_get( numrir, jpdom_autoglo, 'sxa'   , sxa    )
-            CALL iom_get( numrir, jpdom_autoglo, 'sya'   , sya    )
-            CALL iom_get( numrir, jpdom_autoglo, 'sxxa'  , sxxa   )
-            CALL iom_get( numrir, jpdom_autoglo, 'syya'  , syya   )
-            CALL iom_get( numrir, jpdom_autoglo, 'sxya'  , sxya   )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxa'   , sxa, ldxios = lrxios    )
+            CALL iom_get( numrir, jpdom_autoglo, 'sya'   , sya, ldxios = lrxios    )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxa'  , sxxa, ldxios = lrxios   )
+            CALL iom_get( numrir, jpdom_autoglo, 'syya'  , syya, ldxios = lrxios   )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxya'  , sxya, ldxios = lrxios   )
             !                                                        ! ice salinity
-            CALL iom_get( numrir, jpdom_autoglo, 'sxsal' , sxsal  )
-            CALL iom_get( numrir, jpdom_autoglo, 'sysal' , sysal  )
-            CALL iom_get( numrir, jpdom_autoglo, 'sxxsal', sxxsal )
-            CALL iom_get( numrir, jpdom_autoglo, 'syysal', syysal )
-            CALL iom_get( numrir, jpdom_autoglo, 'sxysal', sxysal )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxsal' , sxsal, ldxios = lrxios  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sysal' , sysal, ldxios = lrxios  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxsal', sxxsal, ldxios = lrxios )
+            CALL iom_get( numrir, jpdom_autoglo, 'syysal', syysal, ldxios = lrxios )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxysal', sxysal, ldxios = lrxios )
             !                                                        ! ice age
-            CALL iom_get( numrir, jpdom_autoglo, 'sxage' , sxage  )
-            CALL iom_get( numrir, jpdom_autoglo, 'syage' , syage  )
-            CALL iom_get( numrir, jpdom_autoglo, 'sxxage', sxxage )
-            CALL iom_get( numrir, jpdom_autoglo, 'syyage', syyage )
-            CALL iom_get( numrir, jpdom_autoglo, 'sxyage', sxyage )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxage' , sxage, ldxios = lrxios  )
+            CALL iom_get( numrir, jpdom_autoglo, 'syage' , syage, ldxios = lrxios  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxage', sxxage, ldxios = lrxios )
+            CALL iom_get( numrir, jpdom_autoglo, 'syyage', syyage, ldxios = lrxios )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxyage', sxyage, ldxios = lrxios )
             !                                                        ! snow layers heat content
             DO jk = 1, nlay_s
                WRITE(zchar1,'(I2.2)') jk
-               znam = 'sxc0'//'_l'//zchar1  ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   sxc0 (:,:,jk,:) = z3d(:,:,:)
-               znam = 'syc0'//'_l'//zchar1  ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   syc0 (:,:,jk,:) = z3d(:,:,:)
-               znam = 'sxxc0'//'_l'//zchar1 ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   sxxc0(:,:,jk,:) = z3d(:,:,:)
-               znam = 'syyc0'//'_l'//zchar1 ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   syyc0(:,:,jk,:) = z3d(:,:,:)
-               znam = 'sxyc0'//'_l'//zchar1 ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   sxyc0(:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxc0'//'_l'//zchar1  
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )   ;   sxc0 (:,:,jk,:) = z3d(:,:,:)
+               znam = 'syc0'//'_l'//zchar1  
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )   ;   syc0 (:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxxc0'//'_l'//zchar1 
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )   ;   sxxc0(:,:,jk,:) = z3d(:,:,:)
+               znam = 'syyc0'//'_l'//zchar1 
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )   ;   syyc0(:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxyc0'//'_l'//zchar1 
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )   ;   sxyc0(:,:,jk,:) = z3d(:,:,:)
             END DO
             !                                                        ! ice layers heat content
             DO jk = 1, nlay_i
                WRITE(zchar1,'(I2.2)') jk
-               znam = 'sxe'//'_l'//zchar1   ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   sxe (:,:,jk,:) = z3d(:,:,:)
-               znam = 'sye'//'_l'//zchar1   ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   sye (:,:,jk,:) = z3d(:,:,:)
-               znam = 'sxxe'//'_l'//zchar1  ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   sxxe(:,:,jk,:) = z3d(:,:,:)
-               znam = 'syye'//'_l'//zchar1  ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   syye(:,:,jk,:) = z3d(:,:,:)
-               znam = 'sxye'//'_l'//zchar1  ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   sxye(:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxe'//'_l'//zchar1   
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )   ;   sxe (:,:,jk,:) = z3d(:,:,:)
+               znam = 'sye'//'_l'//zchar1   
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )   ;   sye (:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxxe'//'_l'//zchar1  
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )   ;   sxxe(:,:,jk,:) = z3d(:,:,:)
+               znam = 'syye'//'_l'//zchar1  
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )   ;   syye(:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxye'//'_l'//zchar1  
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )   ;   sxye(:,:,jk,:) = z3d(:,:,:)
             END DO
             !
             IF( ln_pnd_H12 ) THEN                                    ! melt pond fraction
-               CALL iom_get( numrir, jpdom_autoglo, 'sxap' , sxap  )
-               CALL iom_get( numrir, jpdom_autoglo, 'syap' , syap  )
-               CALL iom_get( numrir, jpdom_autoglo, 'sxxap', sxxap )
-               CALL iom_get( numrir, jpdom_autoglo, 'syyap', syyap )
-               CALL iom_get( numrir, jpdom_autoglo, 'sxyap', sxyap )
+               CALL iom_get( numrir, jpdom_autoglo, 'sxap' , sxap,  ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 'syap' , syap,  ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 'sxxap', sxxap, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 'syyap', syyap, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 'sxyap', sxyap, ldxios = lrxios )
                !                                                     ! melt pond volume
-               CALL iom_get( numrir, jpdom_autoglo, 'sxvp' , sxvp  )
-               CALL iom_get( numrir, jpdom_autoglo, 'syvp' , syvp  )
-               CALL iom_get( numrir, jpdom_autoglo, 'sxxvp', sxxvp )
-               CALL iom_get( numrir, jpdom_autoglo, 'syyvp', syyvp )
-               CALL iom_get( numrir, jpdom_autoglo, 'sxyvp', sxyvp )
+               CALL iom_get( numrir, jpdom_autoglo, 'sxvp' , sxvp,  ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 'syvp' , syvp,  ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 'sxxvp', sxxvp, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 'syyvp', syyvp, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 'sxyvp', sxyvp, ldxios = lrxios )
             ENDIF
+            IF(lrxios) CALL iom_swap(cxios_context)
             !
          ELSE                                   !**  start rheology from rest  **!
@@ -862,65 +874,77 @@
          !
          !                                                           ! 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(      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(      cxios_context         )
          !
       ENDIF
Index: /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/icedyn_rhg_evp.F90
===================================================================
--- /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/icedyn_rhg_evp.F90	(revision 12956)
+++ /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/icedyn_rhg_evp.F90	(revision 12957)
@@ -839,4 +839,5 @@
          IF( ln_rstart ) THEN                   !* Read the restart file
             !
+            IF(lrxios) CALL iom_swap(crixios_context)
             id1 = iom_varid( numrir, 'stress1_i' , ldstop = .FALSE. )
             id2 = iom_varid( numrir, 'stress2_i' , ldstop = .FALSE. )
@@ -844,7 +845,7 @@
             !
             IF( MIN( id1, id2, id3 ) > 0 ) THEN      ! fields exist
-               CALL iom_get( numrir, jpdom_autoglo, 'stress1_i' , stress1_i  )
-               CALL iom_get( numrir, jpdom_autoglo, 'stress2_i' , stress2_i  )
-               CALL iom_get( numrir, jpdom_autoglo, 'stress12_i', stress12_i )
+               CALL iom_get( numrir, jpdom_autoglo, 'stress1_i' , stress1_i,  ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 'stress2_i' , stress2_i,  ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 'stress12_i', stress12_i, ldxios = lrxios )
             ELSE                                     ! start rheology from rest
                IF(lwp) WRITE(numout,*)
@@ -854,4 +855,5 @@
                stress12_i(:,:) = 0._wp
             ENDIF
+            IF(lrxios) CALL iom_swap(cxios_context)
          ELSE                                   !* Start from rest
             IF(lwp) WRITE(numout,*)
@@ -867,7 +869,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(      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(      cxios_context         )
          !
       ENDIF
Index: /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/icerst.F90
===================================================================
--- /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/icerst.F90	(revision 12956)
+++ /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/icerst.F90	(revision 12957)
@@ -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,21 @@
             ENDIF
             !
-            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl, cdcomp = 'ICE' )
+            IF(.NOT.lwxios) THEN
+               CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl, cdcomp = 'ICE' )
+            ELSE
+#if defined key_iomput
+               cwixios_context = "rstwi_"//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., ld_closedef = .FALSE. )
+               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 +134,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 +155,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 +162,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 +175,9 @@
       ! ------------------
       IF( iter == nitrst ) THEN
-         CALL iom_close( numriw )
+         IF(.NOT.lwxios) THEN
+            CALL iom_close( numriw )
+         ELSE
+            CALL iom_context_finalize(      cwixios_context          )
+         ENDIF
          lrst_ice = .FALSE.
       ENDIF
@@ -176,4 +199,5 @@
       CHARACTER(len=2)  ::   zchar, zchar1
       REAL(wp)          ::   zfice, ziter
+      CHARACTER(lc)     ::   clpname
       REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
       !!----------------------------------------------------------------------
@@ -185,5 +209,20 @@
       ENDIF
 
+      lxios_sini = .FALSE.
       CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir )
+
+      IF( lrxios .AND. .NOT. lxios_sini) STOP 'OCE and ICE restart must be in a single file'
+      IF(lwp) write(numout, *) 'USE XIOS to read restart: ', lrxios
+      IF(lwp) CALL FLUSH(numout)
+      IF( lrxios) THEN
+          crixios_context = 'si3_rst'
+          IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for SI3'
+          IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+             clpname = cn_icerst_in
+          ELSE
+             clpname = TRIM(Agrif_CFixed())//"_"//cn_icerst_in   
+          ENDIF
+          CALL iom_init( crixios_context, fname = TRIM(cn_icerst_indir)//'/'//TRIM(clpname), ld_tmppatch = .TRUE. )
+      ENDIF
 
       ! test if v_i exists 
@@ -193,8 +232,8 @@
       IF( id0 > 0 ) THEN   ! == case of a normal restart == !
          !                 ! ------------------------------ !
-         
+         IF(lrxios) CALL iom_swap(crixios_context) 
          ! Time info
-         CALL iom_get( numrir, 'nn_fsbc', zfice )
-         CALL iom_get( numrir, 'kt_ice' , ziter )    
+         CALL iom_get( numrir, 'nn_fsbc', zfice, ldxios = lrxios )
+         CALL iom_get( numrir, 'kt_ice' , ziter, ldxios = lrxios )    
          IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
          IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
@@ -211,16 +250,16 @@
 
          ! --- mandatory fields --- ! 
-         CALL iom_get( numrir, jpdom_autoglo, 'v_i'  , v_i   )
-         CALL iom_get( numrir, jpdom_autoglo, 'v_s'  , v_s   )
-         CALL iom_get( numrir, jpdom_autoglo, 'sv_i' , sv_i  )
-         CALL iom_get( numrir, jpdom_autoglo, 'a_i'  , a_i   )
-         CALL iom_get( numrir, jpdom_autoglo, 't_su' , t_su  )
-         CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
-         CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
+         CALL iom_get( numrir, jpdom_autoglo, 'v_i'  , v_i,   ldxios = lrxios )
+         CALL iom_get( numrir, jpdom_autoglo, 'v_s'  , v_s,   ldxios = lrxios )
+         CALL iom_get( numrir, jpdom_autoglo, 'sv_i' , sv_i,  ldxios = lrxios )
+         CALL iom_get( numrir, jpdom_autoglo, 'a_i'  , a_i,   ldxios = lrxios )
+         CALL iom_get( numrir, jpdom_autoglo, 't_su' , t_su,  ldxios = lrxios )
+         CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice, ldxios = lrxios )
+         CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice, ldxios = lrxios )
          ! Snow enthalpy
          DO jk = 1, nlay_s
             WRITE(zchar1,'(I2.2)') jk
             znam = 'e_s'//'_l'//zchar1
-            CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
+            CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )
             e_s(:,:,jk,:) = z3d(:,:,:)
          END DO
@@ -229,5 +268,5 @@
             WRITE(zchar1,'(I2.2)') jk
             znam = 'e_i'//'_l'//zchar1
-            CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
+            CALL iom_get( numrir, jpdom_autoglo, znam , z3d, ldxios = lrxios )
             e_i(:,:,jk,:) = z3d(:,:,:)
          END DO
@@ -236,5 +275,5 @@
          id1 = iom_varid( numrir, 'oa_i' , ldstop = .FALSE. )
          IF( id1 > 0 ) THEN                       ! fields exist
-            CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i )
+            CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i, ldxios = lrxios )
          ELSE                                     ! start from rest
             IF(lwp) WRITE(numout,*) '   ==>>   previous run without ice age output then set it to zero'
@@ -244,6 +283,6 @@
          id2 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. )
          IF( id2 > 0 ) THEN                       ! fields exist
-            CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip )
-            CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip )
+            CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip, ldxios = lrxios )
+            CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip, ldxios = lrxios )
          ELSE                                     ! start from rest
             IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it to zero'
@@ -256,6 +295,6 @@
             id4 = iom_varid( numrir, 't1_ice'  , ldstop = .FALSE. )
             IF( id3 > 0 .AND. id4 > 0 ) THEN         ! fields exist
-               CALL iom_get( numrir, jpdom_autoglo, 'cnd_ice', cnd_ice )
-               CALL iom_get( numrir, jpdom_autoglo, 't1_ice' , t1_ice  )
+               CALL iom_get( numrir, jpdom_autoglo, 'cnd_ice', cnd_ice, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 't1_ice' , t1_ice,  ldxios = lrxios )
             ELSE                                     ! start from rest
                IF(lwp) WRITE(numout,*) '   ==>>   previous run without conductivity output then set it to zero'
@@ -266,5 +305,5 @@
 
          CALL iom_delay_rst( 'READ', 'ICE', numrir )   ! read only ice delayed global communication variables
-
+         IF(lrxios) CALL iom_swap(cxios_context)
          !                 ! ---------------------------------- !
       ELSE                 ! == case of a simplified restart == !
Index: /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/iceupdate.F90
===================================================================
--- /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/iceupdate.F90	(revision 12956)
+++ /NEMO/branches/2020/dev_12905_xios_restart/src/ICE/iceupdate.F90	(revision 12957)
@@ -417,6 +417,8 @@
             !
             IF( id1 > 0 ) THEN                       ! fields exist
-               CALL iom_get( numrir, jpdom_autoglo, 'snwice_mass'  , snwice_mass   )
-               CALL iom_get( numrir, jpdom_autoglo, 'snwice_mass_b', snwice_mass_b )
+               IF(lrxios) CALL iom_swap(crixios_context) 
+               CALL iom_get( numrir, jpdom_autoglo, 'snwice_mass'  , snwice_mass,   ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, 'snwice_mass_b', snwice_mass_b, ldxios = lrxios )
+               IF(lrxios) CALL iom_swap(cxios_context)
             ELSE                                     ! start from rest
                IF(lwp) WRITE(numout,*) '   ==>>   previous run without snow-ice mass output then set it'
@@ -435,6 +437,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/2020/dev_12905_xios_restart/src/OCE/DOM/daymod.F90
===================================================================
--- /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/DOM/daymod.F90	(revision 12956)
+++ /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/DOM/daymod.F90	(revision 12957)
@@ -403,5 +403,4 @@
          ! calendar control
          IF( lwxios ) CALL iom_swap(      cwxios_context          )
-         ENDIF
          CALL iom_rstput( kt, nitrst, numrow, 'kt'     , REAL( kt    , wp)  , ldxios = lwxios )   ! time-step
          CALL iom_rstput( kt, nitrst, numrow, 'ndastp' , REAL( ndastp, wp)  , ldxios = lwxios )   ! date
Index: /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/IOM/in_out_manager.F90
===================================================================
--- /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/IOM/in_out_manager.F90	(revision 12956)
+++ /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/IOM/in_out_manager.F90	(revision 12957)
@@ -180,4 +180,7 @@
    CHARACTER(lc) ::   crxios_context        !: context name used in xios to read restart
    CHARACTER(lc) ::   cwxios_context        !: context name used in xios to write 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 file
+
 
    !! * Substitutions
Index: /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/IOM/iom.F90
===================================================================
--- /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/IOM/iom.F90	(revision 12956)
+++ /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/IOM/iom.F90	(revision 12957)
@@ -114,5 +114,6 @@
       INTEGER             :: irefyear, irefmonth, irefday
       INTEGER           :: ji
-      LOGICAL :: llrst_context              ! is context related to restart
+      LOGICAL           :: llrst_context              ! is context related to restart
+      INTEGER           :: inum
       !
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zt_bnds, zw_bnds
@@ -142,9 +143,12 @@
       ALLOCATE( zt_bnds(2,jpk), zw_bnds(2,jpk) )
       !
+      IF(lwp) write(numout, *) 'TEST IOM_INIT: ', TRIM(cdname),' File: ', TRIM(fname)
+      IF(lwp) CALL FLUSH(numout)
       clname = cdname
       IF( TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(cdname)
       CALL xios_context_initialize(TRIM(clname), mpi_comm_oce)
       CALL iom_swap( cdname )
-      llrst_context =  (TRIM(cdname) == TRIM(crxios_context) .OR. TRIM(cdname) == TRIM(cwxios_context))
+      llrst_context = (TRIM(cdname) == TRIM(crxios_context)) .OR. (TRIM(cdname) == TRIM(cwxios_context))
+      llrst_context = llrst_context .OR. (TRIM(cdname) == TRIM(crixios_context)) .OR. (TRIM(cdname) == TRIM(cwixios_context))
 
       ! Calendar type is now defined in xml file 
@@ -260,10 +264,18 @@
       !
       ! automatic definitions of some of the xml attributs
-      IF( TRIM(cdname) == TRIM(crxios_context) ) THEN
-!set names of the fields in restart file IF using XIOS to read data
+      IF(lwp) write(numout, *) 'TEST IOM_INIT: ', TRIM(cdname), TRIM(cdname) == TRIM(crixios_context)
+      IF(lwp) CALL FLUSH(numout)
+      IF( TRIM(cdname) == TRIM(crxios_context) .OR. TRIM(cdname) == TRIM(crixios_context)) THEN
+          IF(TRIM(cdname) == TRIM(crxios_context) ) THEN
+             inum = numror
+          ELSEIF(TRIM(cdname) == TRIM(crixios_context)) THEN
+             inum = numrir 
+          ELSE
+             CALL ctl_stop( 'iom_init:', 'restart read with XIOS: Unknown restart context' )
+          ENDIF
           CALL iom_set_rst_context(.TRUE.)
-!set which fields are to be read from restart file
-          CALL iom_set_rstr_active()
-      ELSE IF( TRIM(cdname) == TRIM(cwxios_context) ) THEN
+!set which fields will be read from restart file
+          CALL iom_set_rstr_active(fname, inum)
+      ELSE IF( (TRIM(cdname) == TRIM(cwxios_context)) .OR. (TRIM(cdname) == TRIM(cwixios_context))) THEN
           CALL iom_set_rstw_file(fname)
       ELSE
@@ -298,5 +310,15 @@
    CHARACTER(len=*), OPTIONAL, INTENT(IN) :: cdname
 #if defined key_iomput
-      IF( TRIM(cdname) == TRIM(cwxios_context) ) THEN
+   LOGICAL :: llrstw
+
+      IF(lwp) write(numout, *) 'XIOS CLOSE definitions for: ', TRIM(cdname)
+      llrstw = .FALSE.
+     IF(PRESENT(cdname)) THEN
+         IF((TRIM(cdname) == TRIM(cwxios_context)) .OR. (TRIM(cdname) == TRIM(cwixios_context))) THEN
+           llrstw = .TRUE.
+         ENDIF
+      ENDIF
+
+      IF( llrstw ) THEN
 !set names of the fields in restart file IF using XIOS to write data
           CALL iom_set_rst_context(.FALSE.)
@@ -305,5 +327,5 @@
       CALL xios_close_context_definition()
 
-      IF(.NOT. (TRIM(cdname) == TRIM(cwxios_context)))  CALL xios_update_calendar( 0 )
+      IF(.NOT. llrstw)  CALL xios_update_calendar( 0 )
 
 #else
@@ -313,5 +335,5 @@
    END SUBROUTINE iom_init_closedef
 
-   SUBROUTINE iom_set_rstr_active()
+   SUBROUTINE iom_set_rstr_active(cdfname, idnum)
       !!---------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_set_rstr_active  ***
@@ -322,5 +344,6 @@
 
 !sets enabled = .TRUE. for each field in restart file
-   CHARACTER(len=256) :: rst_file
+   CHARACTER(len=*), INTENT(IN) :: cdfname
+   INTEGER         , INTENT(IN) :: idnum 
 #if defined key_iomput
    INTEGER                                    :: ndims, nvars, natts, unlimitedDimId, dimlen, xtype,mdims
@@ -329,5 +352,4 @@
    TYPE(xios_filegroup)                       :: filegroup_hdl
    INTEGER                                    :: dimids(4), jv,i, idim
-   CHARACTER(LEN=lc)                          :: clpath
    CHARACTER(LEN=256)                         :: clinfo               ! info character
    INTEGER, ALLOCATABLE                       :: indimlens(:)
@@ -353,27 +375,21 @@
         meta(10) = "numcat"
 
-        clpath = TRIM(cn_ocerst_indir)
-        IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
-        IF( TRIM(Agrif_CFixed()) == '0' ) THEN
-           rst_file = TRIM(clpath)//TRIM(cn_ocerst_in)
-        ELSE
-           rst_file = TRIM(clpath)//TRIM(Agrif_CFixed())//'_'//TRIM(cn_ocerst_in)
-        ENDIF
-
-        clinfo = '          iom_set_rstr_active, file: '//TRIM(rst_file)
-
+        clinfo = '          iom_set_rstr_active, file: '//TRIM(cdfname)
+
+        IF(lwp) write(numout, *) TRIM(clinfo)
+        IF(lwp) CALL FLUSH(numout)
 !set name of the restart file and enable available fields
         CALL xios_get_handle("file_definition", filegroup_hdl )
         CALL xios_add_child(filegroup_hdl, file_hdl, 'rrestart')
-        CALL xios_set_file_attr( "rrestart", name=trim(rst_file), type="one_file", &
+        CALL xios_set_file_attr( "rrestart", name=trim(cdfname), type="one_file", &
              par_access="collective", enabled=.TRUE., mode="read",                 &
              output_freq=xios_timestep)
 
-        CALL iom_nf90_check( nf90_inquire( iom_file(numror)%nfid, ndims, nvars, natts ), clinfo )
+        CALL iom_nf90_check( nf90_inquire( iom_file(idnum)%nfid, ndims, nvars, natts ), clinfo )
         ALLOCATE(indimlens(ndims), indimnames(ndims))
-        CALL iom_nf90_check( nf90_inquire( iom_file(numror)%nfid, unlimitedDimId = unlimitedDimId ), clinfo )
+        CALL iom_nf90_check( nf90_inquire( iom_file(idnum)%nfid, unlimitedDimId = unlimitedDimId ), clinfo )
 
         DO idim = 1, ndims
-           CALL iom_nf90_check( nf90_inquire_dimension( iom_file(numror)%nfid, idim, dimname, dimlen ), clinfo )
+           CALL iom_nf90_check( nf90_inquire_dimension( iom_file(idnum)%nfid, idim, dimname, dimlen ), clinfo )
            indimlens(idim) = dimlen
            indimnames(idim) = dimname
@@ -382,5 +398,5 @@
         DO jv =1, nvars
             lmeta = .FALSE.
-            CALL iom_nf90_check( nf90_inquire_variable( iom_file(numror)%nfid, jv, varname, xtype, ndims, dimids, natts ), clinfo )
+            CALL iom_nf90_check( nf90_inquire_variable( iom_file(idnum)%nfid, jv, varname, xtype, ndims, dimids, natts ), clinfo )
             DO i = 1, NMETA
                IF(TRIM(varname) == TRIM(meta(i))) THEN
@@ -390,4 +406,6 @@
             IF(.NOT.lmeta) THEN
                CALL xios_add_child(file_hdl, field_hdl, TRIM(varname))
+               if(lwp) write(numout, *) 'ADD field: ', TRIM(varname)
+               IF(lwp) CALL FLUSH(numout)
                mdims = ndims
 
@@ -397,19 +415,34 @@
 
                IF(mdims == 3) THEN
+                      if(lwp) write(numout, *) '3D', indimlens(ndims)
+                      IF(lwp) CALL FLUSH(numout)
+
                       CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(varname),   &
                                    domain_ref="grid_N", axis_ref=TRIM(iom_axis(indimlens(ndims))), &
                                    prec = 8, operation = "instant")
                ELSEIF(mdims == 2) THEN
+                      if(lwp) write(numout, *) '2D'
+                      IF(lwp) CALL FLUSH(numout)
+
                       CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(varname), &
                                           domain_ref="grid_N", prec = 8, operation = "instant") 
                ELSEIF(mdims == 1) THEN
+                      if(lwp) write(numout, *) '1D', indimlens(ndims)
+                      IF(lwp) CALL FLUSH(numout)
+
                       CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(varname), &
                                           axis_ref=TRIM(iom_axis(indimlens(ndims))), prec = 8, operation = "instant")
                ELSEIF(mdims == 0) THEN
+                      if(lwp) write(numout, *) '0D'
+                      IF(lwp) CALL FLUSH(numout)
+
                       CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(varname), &
                                                 scalar_ref = "grid_scalar", prec = 8, operation = "instant")
                ELSE
-                   WRITE(ctmp1,*) 'iom_set_rstr_active: variable ', TRIM(varname) ,' incorrect number of dimensions' 
-                   CALL ctl_stop( 'iom_set_rstr_active:', ctmp1 )
+                      if(lwp) write(numout, *) 'WAHT?'
+                      IF(lwp) CALL FLUSH(numout)
+
+                      WRITE(ctmp1,*) 'iom_set_rstr_active: variable ', TRIM(varname) ,' incorrect number of dimensions' 
+                      CALL ctl_stop( 'iom_set_rstr_active:', ctmp1 )
                ENDIF
             ENDIF
@@ -434,4 +467,5 @@
 !set name of the restart file and enable available fields
         IF(lwp) WRITE(numout,*) 'Setting restart filename (for XIOS write) to: ',cdrst_file
+        IF(lwp) CALL FLUSH(numout)
         CALL xios_get_handle("file_definition", filegroup_hdl )
         CALL xios_add_child(filegroup_hdl, file_hdl, 'wrestart')
@@ -1869,4 +1903,5 @@
       !!----------------------------------------------------------------------
       clname = cdname
+      IF(lwp) write(numout, *) 'Finalize: ', TRIM(cdname)
       IF( TRIM(Agrif_CFixed()) .NE. '0' ) clname = TRIM(Agrif_CFixed())//"_"//clname 
       IF( xios_is_valid_context(clname) ) THEN
Index: /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/IOM/restart.F90
===================================================================
--- /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/IOM/restart.F90	(revision 12956)
+++ /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/IOM/restart.F90	(revision 12957)
@@ -190,6 +190,7 @@
       !!                the file has already been opened
       !!----------------------------------------------------------------------
-      LOGICAL        ::   llok
-      CHARACTER(lc)  ::   clpath   ! full path to ocean output restart file
+      LOGICAL         ::   llok
+      CHARACTER(lc)   ::   clpath   ! full path to ocean output restart file
+      CHARACTER(lc+2) ::   clpname  ! file name including agrif prefix
       !!----------------------------------------------------------------------
       !
@@ -209,17 +210,19 @@
 ! restart)
          IF(.NOT.lxios_set) lrxios = lrxios.AND.lxios_sini
+
          IF( lrxios) THEN
-             crxios_context = 'nemo_rst'
+             crxios_context = 'oce_rst'
              IF( .NOT.lxios_set ) THEN
                  IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS'
-                 CALL iom_init( crxios_context, ld_tmppatch = .TRUE. )
+                 IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+                    clpname = cn_ocerst_in
+                 ELSE
+                    clpname = TRIM(Agrif_CFixed())//"_"//cn_ocerst_in   
+                 ENDIF
+                 CALL iom_init( crxios_context, fname = TRIM(clpath)//TRIM(clpname), ld_tmppatch = .TRUE. )
                  lxios_set = .TRUE.
              ENDIF
          ENDIF
-         IF( TRIM(Agrif_CFixed()) /= '0' .AND. lrxios) THEN
-             CALL iom_init( crxios_context, ld_tmppatch = .TRUE. )
-             IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for AGRIF'
-             lxios_set = .TRUE.
-         ENDIF 
+
       ENDIF
 
Index: /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/step.F90
===================================================================
--- /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/step.F90	(revision 12956)
+++ /NEMO/branches/2020/dev_12905_xios_restart/src/OCE/step.F90	(revision 12957)
@@ -122,10 +122,17 @@
                              CALL iom_init_closedef
          IF( ln_crs      )   CALL iom_init( TRIM(cxios_context)//"_crs" )  ! for coarse grid
-      ELSEIF((kstp == nitrst) .AND. lwxios) THEN
+      ENDIF
+      IF((kstp == nitrst) .AND. lwxios) THEN
          CALL iom_swap(      cwxios_context          )
          CALL iom_init_closedef(cwxios_context)
          CALL iom_setkt( kstp - nit000 + 1,      cwxios_context          )
-         CALL iom_swap(      cwxios_context          )
-      ENDIF
+      ENDIF
+#if defined key_si3
+      IF(((kstp + nn_fsbc - 1) == nitrst) .AND. lwxios) THEN
+         CALL iom_swap(      cwixios_context          )
+         CALL iom_init_closedef(cwixios_context)
+         CALL iom_setkt( kstp - nit000 + 1,      cwixios_context          )
+      ENDIF
+#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
@@ -355,5 +362,10 @@
       IF( kstp == nitend .OR. indic < 0 ) THEN 
                       CALL iom_context_finalize(      cxios_context          ) ! needed for XIOS+AGRIF
-         IF( lrxios ) CALL iom_context_finalize(      crxios_context         )
+         IF( lrxios ) THEN
+                      CALL iom_context_finalize(      crxios_context         )
+#if defined key_si3
+                      CALL iom_context_finalize(      crixios_context         )
+#endif
+         ENDIF
          IF( ln_crs ) CALL iom_context_finalize( trim(cxios_context)//"_crs" ) ! 
       ENDIF
