Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedia.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedia.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedia.F90	(revision 11837)
@@ -225,16 +225,18 @@
          IF( ln_rstart ) THEN                   !* Read the restart file
             !
-            CALL iom_get( numrir, 'kt_ice' , ziter )
+            IF(lrxios) CALL iom_swap( TRIM(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( TRIM(cxios_context) )
          ELSE
             IF(lwp) WRITE(numout,*)
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 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedyn_adv_pra.F90	(revision 11837)
@@ -706,65 +706,92 @@
             !
             !                                                        ! 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 )
+            IF(lrxios) CALL iom_swap( TRIM(crixios_context) )
+            !
+            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(:,:,:)
-            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(:,:,:)
-            END DO
+            IF(lrsi3_nemo) THEN
+               DO jk = 1, nlay_s
+                  WRITE(zchar1,'(I2.2)') jk
+                  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, 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
+            ELSE
+               CALL iom_get( numrir, jpdom_autoglo, "sxc0", sxc0, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, "syc0", syc0, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, "sxxc0", sxxc0, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, "syyc0", syyc0, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, "sxyc0", sxyc0, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, "sxe", sxc0, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, "sye", syc0, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, "sxxe", sxxc0, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, "syye", syyc0, ldxios = lrxios )
+               CALL iom_get( numrir, jpdom_autoglo, "sxye", sxyc0, ldxios = lrxios )
+            ENDIF
             !
             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( TRIM(cxios_context) )
             !
          ELSE                                   !**  start rheology from rest  **!
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 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icedyn_rhg_evp.F90	(revision 11837)
@@ -879,7 +879,9 @@
             !
             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 )
+               IF(lrxios) CALL iom_swap( TRIM(crixios_context) )
+               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 )
+               IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
             ELSE                                     ! start rheology from rest
                IF(lwp) WRITE(numout,*)
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icerst.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icerst.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/icerst.F90	(revision 11837)
@@ -184,4 +184,5 @@
       ENDIF
 
+      lxios_sini = .FALSE.
       CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kdlev = jpl )
 
@@ -192,8 +193,24 @@
       IF( id0 > 0 ) THEN   ! == case of a normal restart == !
          !                 ! ------------------------------ !
-         
+         IF(.NOT.lxios_set) THEN
+            lrxios = lrxios.AND.lxios_sini
+         ELSE
+            IF(.NOT.lxios_sini) THEN
+               WRITE(ctmp1,*) 'E R R O R : XIOS can not be used to read SI3 restart from multiple files'
+               CALL ctl_stop( 'ice_rst_read:', ctmp1 )
+            ENDIF
+         ENDIF
+
+         lrsi3_nemo = .TRUE.                       ! SI3 restart written by NEMO
+
+         IF(lrxios) THEN
+           crixios_context = 'si3_rst'
+           CALL iom_init( crixios_context, TRIM(cn_icerst_indir)//'/'//cn_icerst_in, ld_tmppatch = .false. )
+           lxios_set = .TRUE.
+         ENDIF
+
          ! 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
@@ -210,30 +227,37 @@
 
          ! --- 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 )
-            e_s(:,:,jk,:) = z3d(:,:,:)
-         END DO
-         ! Ice enthalpy
-         DO jk = 1, nlay_i
-            WRITE(zchar1,'(I2.2)') jk
-            znam = 'e_i'//'_l'//zchar1
-            CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
-            e_i(:,:,jk,:) = z3d(:,:,:)
-         END DO
+         IF(lrsi3_nemo) THEN
+!NEMO read inerface
+            DO jk = 1, nlay_s
+               WRITE(zchar1,'(I2.2)') jk
+               znam = 'e_s'//'_l'//zchar1
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
+               e_s(:,:,jk,:) = z3d(:,:,:)
+            END DO
+            ! Ice enthalpy
+            DO jk = 1, nlay_i
+               WRITE(zchar1,'(I2.2)') jk
+               znam = 'e_i'//'_l'//zchar1
+               CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
+               e_i(:,:,jk,:) = z3d(:,:,:)
+            END DO
+         ELSE
+!XIOS read interface
+            CALL iom_get( numrir, jpdom_autoglo, "e_s" , e_s )
+            CALL iom_get( numrir, jpdom_autoglo, "e_i" , e_i ) 
+         ENDIF
          ! -- optional fields -- !
          ! ice age
          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'
@@ -243,6 +267,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'
@@ -255,6 +279,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'
@@ -263,5 +287,5 @@
             ENDIF
          ENDIF
-
+         IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
          CALL iom_delay_rst( 'READ', 'ICE', numrir )   ! read only ice delayed global communication 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 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/ICE/iceupdate.F90	(revision 11837)
@@ -424,6 +424,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( TRIM(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( TRIM(cxios_context) )
             ELSE                                     ! start from rest
                IF(lwp) WRITE(numout,*) '   ==>>   previous run without snow-ice mass output then set it'
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DIA/diahsb.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DIA/diahsb.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DIA/diahsb.F90	(revision 11837)
@@ -256,4 +256,5 @@
       IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
          IF( ln_rstart ) THEN                   !* Read the restart file
+            IF(lrxios) CALL iom_swap(crxios_context)
             !
             IF(lwp) WRITE(numout,*)
@@ -276,4 +277,5 @@
                CALL iom_get( numror, jpdom_autoglo, 'ssh_sc_loc_ini', ssh_sc_loc_ini, ldxios = lrxios )
             ENDIF
+            IF(lrxios) CALL iom_swap(cxios_context)
          ELSE
             IF(lwp) WRITE(numout,*)
@@ -377,17 +379,17 @@
       IF(lwxios) THEN
 ! define variables in restart file when writing with XIOS
-        CALL iom_set_rstw_var_active('frc_v')
-        CALL iom_set_rstw_var_active('frc_t')
-        CALL iom_set_rstw_var_active('frc_s')
-        CALL iom_set_rstw_var_active('surf_ini')
-        CALL iom_set_rstw_var_active('ssh_ini')
-        CALL iom_set_rstw_var_active('e3t_ini')
-        CALL iom_set_rstw_var_active('hc_loc_ini')
-        CALL iom_set_rstw_var_active('sc_loc_ini')
+        CALL iom_set_rstw_var_active(rst_wfields, 'frc_v')
+        CALL iom_set_rstw_var_active(rst_wfields, 'frc_t')
+        CALL iom_set_rstw_var_active(rst_wfields, 'frc_s')
+        CALL iom_set_rstw_var_active(rst_wfields, 'surf_ini')
+        CALL iom_set_rstw_var_active(rst_wfields, 'ssh_ini')
+        CALL iom_set_rstw_var_active(rst_wfields, 'e3t_ini')
+        CALL iom_set_rstw_var_active(rst_wfields, 'hc_loc_ini')
+        CALL iom_set_rstw_var_active(rst_wfields, 'sc_loc_ini')
         IF( ln_linssh ) THEN
-           CALL iom_set_rstw_var_active('ssh_hc_loc_ini')
-           CALL iom_set_rstw_var_active('ssh_sc_loc_ini')
-           CALL iom_set_rstw_var_active('frc_wn_t')
-           CALL iom_set_rstw_var_active('frc_wn_s')
+           CALL iom_set_rstw_var_active(rst_wfields, 'ssh_hc_loc_ini')
+           CALL iom_set_rstw_var_active(rst_wfields, 'ssh_sc_loc_ini')
+           CALL iom_set_rstw_var_active(rst_wfields, 'frc_wn_t')
+           CALL iom_set_rstw_var_active(rst_wfields, 'frc_wn_s')
         ENDIF
       ENDIF
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/daymod.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/daymod.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/daymod.F90	(revision 11837)
@@ -145,8 +145,8 @@
       IF( lwxios ) THEN
 ! define variables in restart file when writing with XIOS
-          CALL iom_set_rstw_var_active('kt')
-          CALL iom_set_rstw_var_active('ndastp')
-          CALL iom_set_rstw_var_active('adatrj')
-          CALL iom_set_rstw_var_active('ntime')
+          CALL iom_set_rstw_var_active(rst_wfields, 'kt')
+          CALL iom_set_rstw_var_active(rst_wfields, 'ndastp')
+          CALL iom_set_rstw_var_active(rst_wfields, 'adatrj')
+          CALL iom_set_rstw_var_active(rst_wfields, 'ntime')
       ENDIF
 
@@ -323,5 +323,5 @@
 
       IF( TRIM(cdrw) == 'READ' ) THEN
-
+         IF(lrxios) CALL iom_swap(crxios_context)
          IF( iom_varid( numror, 'kt', ldstop = .FALSE. ) > 0 ) THEN
             ! Get Calendar informations
@@ -381,4 +381,5 @@
                ! note this is wrong if time step has changed during run
             ENDIF
+            IF(lrxios) CALL iom_swap(cxios_context)
          ELSE
             ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day)
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/domvvl.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/domvvl.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/domvvl.F90	(revision 11837)
@@ -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"
             !
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/iscplrst.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/iscplrst.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DOM/iscplrst.F90	(revision 11837)
@@ -58,4 +58,5 @@
       !
       !                       ! get restart variable
+      IF(lrxios) CALL iom_swap(crxios_context)
       CALL iom_get( numror, jpdom_autoglo, 'tmask'  , ztmask_b, ldxios = lrxios   ) ! need to extrapolate T/S
       CALL iom_get( numror, jpdom_autoglo, 'umask'  , zumask_b, ldxios = lrxios   ) ! need to correct barotropic velocity
@@ -66,4 +67,5 @@
       CALL iom_get( numror, jpdom_autoglo, 'e3v_n'  , ze3v_b(:,:,:), ldxios = lrxios )  ! need to correct barotropic velocity
       CALL iom_get( numror, jpdom_autoglo, 'gdepw_n', zdepw_b(:,:,:), ldxios = lrxios ) ! need to interpol vertical profile (vvl)
+      IF(lrxios) CALL iom_swap(cxios_context)
       !
       CALL iscpl_init()       ! read namelist
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DYN/dynspg_ts.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DYN/dynspg_ts.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/DYN/dynspg_ts.F90	(revision 11837)
@@ -934,4 +934,5 @@
       IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
          !                                   ! ---------------
+         IF(lrxios) CALL iom_swap(crxios_context)
          IF( ln_rstart .AND. ln_bt_fw .AND. (neuler/=0) ) THEN    !* Read the restart file
             CALL iom_get( numror, jpdom_autoglo, 'ub2_b'  , ub2_b  (:,:), ldxios = lrxios )   
@@ -954,4 +955,6 @@
             ENDIF
 #endif
+         IF(lrxios) CALL iom_swap(cxios_context)
+         !
          ELSE                                   !* Start from rest
             IF(lwp) WRITE(numout,*)
@@ -1089,22 +1092,22 @@
       IF( lwxios ) THEN
 ! define variables in restart file when writing with XIOS
-         CALL iom_set_rstw_var_active('ub2_b')
-         CALL iom_set_rstw_var_active('vb2_b')
-         CALL iom_set_rstw_var_active('un_bf')
-         CALL iom_set_rstw_var_active('vn_bf')
+         CALL iom_set_rstw_var_active(rst_wfields, 'ub2_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'vb2_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'un_bf')
+         CALL iom_set_rstw_var_active(rst_wfields, 'vn_bf')
          !
          IF (.NOT.ln_bt_av) THEN
-            CALL iom_set_rstw_var_active('sshbb_e')
-            CALL iom_set_rstw_var_active('ubb_e')
-            CALL iom_set_rstw_var_active('vbb_e')
-            CALL iom_set_rstw_var_active('sshb_e')
-            CALL iom_set_rstw_var_active('ub_e')
-            CALL iom_set_rstw_var_active('vb_e')
+            CALL iom_set_rstw_var_active(rst_wfields, 'sshbb_e')
+            CALL iom_set_rstw_var_active(rst_wfields, 'ubb_e')
+            CALL iom_set_rstw_var_active(rst_wfields, 'vbb_e')
+            CALL iom_set_rstw_var_active(rst_wfields, 'sshb_e')
+            CALL iom_set_rstw_var_active(rst_wfields, 'ub_e')
+            CALL iom_set_rstw_var_active(rst_wfields, 'vb_e')
          ENDIF
 #if defined key_agrif
          ! Save time integrated fluxes
          IF ( .NOT.Agrif_Root() ) THEN
-            CALL iom_set_rstw_var_active('ub2_i_b')
-            CALL iom_set_rstw_var_active('vb2_i_b')
+            CALL iom_set_rstw_var_active(rst_wfields, 'ub2_i_b')
+            CALL iom_set_rstw_var_active(rst_wfields, 'vb2_i_b')
          ENDIF
 #endif
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 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/in_out_manager.F90	(revision 11837)
@@ -168,6 +168,8 @@
    LOGICAL       ::   lsp_area = .TRUE.     !: to make a control print over a specific area
    CHARACTER(lc) ::   cxios_context         !: context name used in xios
-   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) ::   crxios_context        !: context name used in xios to read NEMO restart
+   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
+   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 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom.F90	(revision 11837)
@@ -47,4 +47,8 @@
    USE lib_fortran 
    USE diurnal_bulk, ONLY : ln_diurnal_only, ln_diurnal
+#if defined key_si3
+   USE ice, ONLY: nlay_i, nlay_s
+#endif
+
 
    IMPLICIT NONE
@@ -61,5 +65,5 @@
 
    PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
-   PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_get_123d
+   PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_g4d, iom_get_123d
    PRIVATE iom_p1d, iom_p2d, iom_p3d
 #if defined key_iomput
@@ -69,7 +73,9 @@
 # endif
    PUBLIC iom_set_rstw_var_active, iom_set_rstw_core, iom_set_rst_vars
+   PRIVATE iom_add
+   INTEGER, PRIVATE :: numrst
 
    INTERFACE iom_get
-      MODULE PROCEDURE iom_g0d, iom_g1d, iom_g2d, iom_g3d
+      MODULE PROCEDURE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_g4d
    END INTERFACE
    INTERFACE iom_getatt
@@ -227,10 +233,12 @@
       !
       ! automatic definitions of some of the xml attributs
-      IF( TRIM(cdname) == TRIM(crxios_context) ) THEN
+      IF( TRIM(cdname) == TRIM(crxios_context) .OR. TRIM(cdname) == TRIM(crixios_context) ) THEN
+          numrst = numror
+          IF(TRIM(cdname) == TRIM(crixios_context)) numrst = numrir 
 !set names of the fields in restart file IF using XIOS to read data
           CALL iom_set_rst_context(.TRUE.)
           CALL iom_set_rst_vars(rst_rfields)
 !set which fields are to be read from restart file
-          CALL iom_set_rstr_active()
+          CALL iom_set_rstr_active(fname)
       ELSE IF( TRIM(cdname) == TRIM(cwxios_context) ) THEN
 !set names of the fields in restart file IF using XIOS to write data
@@ -238,5 +246,5 @@
           CALL iom_set_rst_vars(rst_wfields)
 !set which fields are to be written to a restart file
-          CALL iom_set_rstw_active(fname)
+          CALL iom_set_rstw_active(rst_wfields, fname)
       ELSE
           CALL set_xmlatt
@@ -259,5 +267,5 @@
    END SUBROUTINE iom_init
 
-   SUBROUTINE iom_set_rstw_var_active(field)
+   SUBROUTINE iom_set_rstw_var_active(drst_wfields, field)
       !!---------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_set_rstw_var_active  ***
@@ -266,4 +274,5 @@
       !!---------------------------------------------------------------------
    CHARACTER(len = *), INTENT(IN) :: field
+   TYPE(RST_FIELD),    INTENT(INOUT) :: drst_wfields(max_rst_fields)
    INTEGER :: i
    LOGICAL :: llis_set
@@ -274,11 +283,11 @@
 
    DO i = 1, max_rst_fields
-       IF(TRIM(rst_wfields(i)%vname) == field) THEN 
-          rst_wfields(i)%active = .TRUE.
+       IF(TRIM(drst_wfields(i)%vname) == field) THEN 
+          drst_wfields(i)%active = .TRUE.
           llis_set = .TRUE.
           EXIT
        ENDIF
    ENDDO
-!Warn if variable is not in defined in rst_wfields
+!Warn if variable is not in defined in drst_wfields
    IF(.NOT.llis_set) THEN
       WRITE(ctmp1,*) 'iom_set_rstw_var_active: variable ', field ,' is available for writing but not defined' 
@@ -292,5 +301,5 @@
    END SUBROUTINE iom_set_rstw_var_active
 
-   SUBROUTINE iom_set_rstr_active()
+   SUBROUTINE iom_set_rstr_active(rst_file)
       !!---------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_set_rstr_active  ***
@@ -308,13 +317,5 @@
    TYPE(xios_filegroup) :: filegroup_hdl
    INTEGER :: i
-   CHARACTER(lc)  ::   clpath
-
-        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)//'1_'//TRIM(cn_ocerst_in)
-        ENDIF
+
 !set name of the restart file and enable available fields
         if(lwp) WRITE(numout,*) 'Setting restart filename (for XIOS) to: ',rst_file
@@ -327,7 +328,17 @@
         DO i = 1, max_rst_fields
          IF( TRIM(rst_rfields(i)%vname) /= "NO_NAME") THEN
-           IF( iom_varid( numror, TRIM(rst_rfields(i)%vname), ldstop = .FALSE. ) > 0 ) THEN
+           IF( iom_varid( numrst, TRIM(rst_rfields(i)%vname), ldstop = .FALSE. ) > 0 ) THEN
+                IF(TRIM(rst_rfields(i)%vname) == "e_s") lrsi3_nemo = .FALSE.       ! SI3 restart written by XIOS
                 CALL xios_add_child(file_hdl, field_hdl, TRIM(rst_rfields(i)%vname))
                 SELECT CASE (TRIM(rst_rfields(i)%grid))
+!                CASE ("grid_Ni_4D")
+!                   CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
+!                       domain_ref="grid_N", axis_ref="nlay_i", axis_ref="numcat", operation = "instant")
+!                CASE ("grid_Ns_4D")
+!                   CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
+!                       domain_ref="grid_N", axis_ref="nlay_s", axis_ref="numcat", operation = "instant")
+                 CASE ("grid_Ni_3D")
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
+                        domain_ref="grid_N", axis_ref="numcat", operation = "instant")
                  CASE ("grid_N_3D")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
@@ -361,34 +372,34 @@
    IF(cdmdl == "OPA") THEN
 !from restart.F90
-   CALL iom_set_rstw_var_active("rdt")
+   CALL iom_set_rstw_var_active(rst_wfields, "rdt")
    IF ( .NOT. ln_diurnal_only ) THEN
-        CALL iom_set_rstw_var_active('ub'  )
-        CALL iom_set_rstw_var_active('vb'  )
-        CALL iom_set_rstw_var_active('tb'  )
-        CALL iom_set_rstw_var_active('sb'  )
-        CALL iom_set_rstw_var_active('sshb')
+        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('un'  )
-        CALL iom_set_rstw_var_active('vn'  )
-        CALL iom_set_rstw_var_active('tn'  )
-        CALL iom_set_rstw_var_active('sn'  )
-        CALL iom_set_rstw_var_active('sshn')
-        CALL iom_set_rstw_var_active('rhop')
+        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')
      ! extra variable needed for the ice sheet coupling
         IF ( ln_iscpl ) THEN
-             CALL iom_set_rstw_var_active('tmask')
-             CALL iom_set_rstw_var_active('umask')
-             CALL iom_set_rstw_var_active('vmask')
-             CALL iom_set_rstw_var_active('smask')
-             CALL iom_set_rstw_var_active('e3t_n')
-             CALL iom_set_rstw_var_active('e3u_n')
-             CALL iom_set_rstw_var_active('e3v_n')
-             CALL iom_set_rstw_var_active('gdepw_n')
+             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')
         END IF
       ENDIF
-      IF(ln_diurnal) CALL iom_set_rstw_var_active('Dsst')
+      IF(ln_diurnal) CALL iom_set_rstw_var_active(rst_wfields, 'Dsst')
 !from trasbc.F90
-         CALL iom_set_rstw_var_active('sbc_hc_b')
-         CALL iom_set_rstw_var_active('sbc_sc_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'sbc_hc_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'sbc_sc_b')
    ENDIF
 #else
@@ -407,115 +418,240 @@
       !!---------------------------------------------------------------------
    TYPE(RST_FIELD), INTENT(INOUT) :: fields(max_rst_fields)
-   INTEGER :: i
+   INTEGER :: i, jk
+   CHARACTER(len=2)  ::   zchar
+   CHARACTER(len=25) ::   znam
 
         i = 0
-        i = i + 1; fields(i)%vname="rdt";            fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="un";             fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="ub";             fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="vn";             fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="vb";             fields(i)%grid="grid_N_3D"  
-        i = i + 1; fields(i)%vname="tn";             fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="tb";             fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="sn";             fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="sb";             fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="sshn";           fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="sshb";           fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="rhop";           fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="kt";             fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="ndastp";         fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="adatrj";         fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="utau_b";         fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="vtau_b";         fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="qns_b";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="emp_b";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="sfx_b";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="en" ;            fields(i)%grid="grid_N_3D" 
-        i = i + 1; fields(i)%vname="avt_k";            fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="avm_k";            fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="dissl";          fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="sbc_hc_b";       fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="sbc_sc_b";       fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="qsr_hc_b";       fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="fraqsr_1lev";    fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="greenland_icesheet_mass"
+        i = iom_add(i); fields(i)%vname="rdt";            fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="un";             fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="ub";             fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="vn";             fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="vb";             fields(i)%grid="grid_N_3D"  
+        i = iom_add(i); fields(i)%vname="tn";             fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="tb";             fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="sn";             fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="sb";             fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="sshn";           fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="sshb";           fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="rhop";           fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="kt";             fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="ndastp";         fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="adatrj";         fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="utau_b";         fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="vtau_b";         fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="qns_b";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="emp_b";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="sfx_b";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="en" ;            fields(i)%grid="grid_N_3D" 
+        i = iom_add(i); fields(i)%vname="avt_k";            fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="avm_k";            fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="dissl";          fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="sbc_hc_b";       fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="sbc_sc_b";       fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="qsr_hc_b";       fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="fraqsr_1lev";    fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="greenland_icesheet_mass"
                                                fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="greenland_icesheet_timelapsed"
+        i = iom_add(i); fields(i)%vname="greenland_icesheet_timelapsed"
                                                fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="greenland_icesheet_mass_roc"
+        i = iom_add(i); fields(i)%vname="greenland_icesheet_mass_roc"
                                                fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="antarctica_icesheet_mass"
+        i = iom_add(i); fields(i)%vname="antarctica_icesheet_mass"
                                                fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="antarctica_icesheet_timelapsed"
+        i = iom_add(i); fields(i)%vname="antarctica_icesheet_timelapsed"
                                                fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="antarctica_icesheet_mass_roc"
+        i = iom_add(i); fields(i)%vname="antarctica_icesheet_mass_roc"
                                                fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="frc_v";          fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="frc_t";          fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="frc_s";          fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="frc_wn_t";       fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="frc_wn_s";       fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="ssh_ini";        fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="e3t_ini";        fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="hc_loc_ini";     fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="sc_loc_ini";     fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="ssh_hc_loc_ini"; fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="ssh_sc_loc_ini"; fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="tilde_e3t_b";    fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="tilde_e3t_n";    fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="hdiv_lf";        fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="ub2_b";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="vb2_b";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="sshbb_e";        fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="ubb_e";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="vbb_e";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="sshb_e";         fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="ub_e";           fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="vb_e";           fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="fwf_isf_b";      fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="isf_sc_b";       fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="isf_hc_b";       fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="ssh_ibb";        fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="rnf_b";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="rnf_hc_b";       fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="rnf_sc_b";       fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="nn_fsbc";        fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="ssu_m";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="ssv_m";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="sst_m";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="sss_m";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="ssh_m";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="e3t_m";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="frq_m";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="avmb";           fields(i)%grid="grid_vector"
-        i = i + 1; fields(i)%vname="avtb";           fields(i)%grid="grid_vector"
-        i = i + 1; fields(i)%vname="ub2_i_b";        fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="vb2_i_b";        fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="ntime";          fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="Dsst";           fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="tmask";          fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="umask";          fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="vmask";          fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="smask";          fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="gdepw_n";        fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="e3t_n";          fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="e3u_n";          fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="e3v_n";          fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="surf_ini";       fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="e3t_b";          fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="hmxl_n";         fields(i)%grid="grid_N_3D"
-        i = i + 1; fields(i)%vname="un_bf";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="vn_bf";          fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="hbl";            fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="hbli";           fields(i)%grid="grid_N"
-        i = i + 1; fields(i)%vname="wn";             fields(i)%grid="grid_N_3D"
-
-        IF( i-1 > max_rst_fields) THEN
-           WRITE(ctmp1,*) 'E R R O R : iom_set_rst_vars SIZE of RST_FIELD array is too small'
-           CALL ctl_stop( 'iom_set_rst_vars:', ctmp1 )
-        ENDIF
+        i = iom_add(i); fields(i)%vname="frc_v";          fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="frc_t";          fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="frc_s";          fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="frc_wn_t";       fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="frc_wn_s";       fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="ssh_ini";        fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="e3t_ini";        fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="hc_loc_ini";     fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="sc_loc_ini";     fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="ssh_hc_loc_ini"; fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="ssh_sc_loc_ini"; fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="tilde_e3t_b";    fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="tilde_e3t_n";    fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="hdiv_lf";        fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="ub2_b";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="vb2_b";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="sshbb_e";        fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="ubb_e";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="vbb_e";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="sshb_e";         fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="ub_e";           fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="vb_e";           fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="fwf_isf_b";      fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="isf_sc_b";       fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="isf_hc_b";       fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="ssh_ibb";        fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="rnf_b";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="rnf_hc_b";       fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="rnf_sc_b";       fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="nn_fsbc";        fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="ssu_m";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="ssv_m";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="sst_m";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="sss_m";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="ssh_m";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="e3t_m";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="frq_m";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="avmb";           fields(i)%grid="grid_vector"
+        i = iom_add(i); fields(i)%vname="avtb";           fields(i)%grid="grid_vector"
+        i = iom_add(i); fields(i)%vname="ub2_i_b";        fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="vb2_i_b";        fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="ntime";          fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="Dsst";           fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="tmask";          fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="umask";          fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="vmask";          fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="smask";          fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="gdepw_n";        fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="e3t_n";          fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="e3u_n";          fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="e3v_n";          fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="surf_ini";       fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="e3t_b";          fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="hmxl_n";         fields(i)%grid="grid_N_3D"
+        i = iom_add(i); fields(i)%vname="un_bf";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="vn_bf";          fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="hbl";            fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="hbli";           fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="wn";             fields(i)%grid="grid_N_3D"
+#ifdef key_si3
+!ICE/icedia.F90
+        i = iom_add(i); fields(i)%vname="kt_ice";         fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="frc_voltop";     fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="frc_volbot";     fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="frc_temtop";     fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="frc_tembot";     fields(i)%grid="grid_scalar" 
+        i = iom_add(i); fields(i)%vname="frc_sal";        fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="vol_loc_ini";    fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="tem_loc_ini";    fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="sal_loc_ini";    fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="sal_loc_ini";    fields(i)%grid="grid_N"
+!ICE/icedyn_adv_pra.F90 grid_Ni_3D - jpi,jpj,jpl 
+        i = iom_add(i); fields(i)%vname="sxice";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="syice";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxxice";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="syyice";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxyice";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxsn";           fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sysn";           fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxxsn";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="syysn";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxysn";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxa";            fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sya";            fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxxa";           fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="syya";           fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxya";           fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxsal";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sysal";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxxsal";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="syysal";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxysal";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxage";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="syage";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxxage";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="syyage";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxyage";         fields(i)%grid="grid_Ni_3D"
+!this part is in addition to 4D grids, to handle old format of SI3 resart
+!NEMO format restart
+        DO jk = 1, nlay_s
+           WRITE(zchar,'(I2.2)') jk
+           znam = 'sxc0'//'_l'//zchar
+           i = iom_add(i); fields(i)%vname=znam;          fields(i)%grid="grid_Ni_3D"
+           znam = 'syc0'//'_l'//zchar
+           i = iom_add(i); fields(i)%vname=znam;          fields(i)%grid="grid_Ni_3D"
+           znam = 'sxxc0'//'_l'//zchar
+           i = iom_add(i); fields(i)%vname=znam;          fields(i)%grid="grid_Ni_3D"
+           znam = 'syyc0'//'_l'//zchar
+           i = iom_add(i); fields(i)%vname=znam;          fields(i)%grid="grid_Ni_3D"
+           znam = 'sxyc0'//'_l'//zchar
+           i = iom_add(i); fields(i)%vname=znam;          fields(i)%grid="grid_Ni_3D"
+        END DO
+!XIOS format restart
+        i = iom_add(i); fields(i)%vname="sxc0";           fields(i)%grid="grid_Ns_4D"
+        i = iom_add(i); fields(i)%vname="syc0";           fields(i)%grid="grid_Ns_4D"
+        i = iom_add(i); fields(i)%vname="sxxc0";          fields(i)%grid="grid_Ns_4D"
+        i = iom_add(i); fields(i)%vname="syyc0";          fields(i)%grid="grid_Ns_4D"
+        i = iom_add(i); fields(i)%vname="sxxc0";          fields(i)%grid="grid_Ns_4D"
+        !
+!NEMO format restart
+        DO jk = 1, nlay_i
+           WRITE(zchar,'(I2.2)') jk
+           znam = 'sxe'//'_l'//zchar
+           i = iom_add(i); fields(i)%vname=znam;          fields(i)%grid="grid_Ni_3D"
+           znam = 'sye'//'_l'//zchar  
+           i = iom_add(i); fields(i)%vname=znam;          fields(i)%grid="grid_Ni_3D"
+           znam = 'sxxe'//'_l'//zchar
+           i = iom_add(i); fields(i)%vname=znam;          fields(i)%grid="grid_Ni_3D"
+           znam = 'syye'//'_l'//zchar
+           i = iom_add(i); fields(i)%vname=znam;          fields(i)%grid="grid_Ni_3D"
+           znam = 'sxye'//'_l'//zchar
+           i = iom_add(i); fields(i)%vname=znam;          fields(i)%grid="grid_Ni_3D"
+        ENDDO
+!XIOS format restart
+        i = iom_add(i); fields(i)%vname="sxe";           fields(i)%grid="grid_Ni_4D"
+        i = iom_add(i); fields(i)%vname="sye";           fields(i)%grid="grid_Ni_4D"
+        i = iom_add(i); fields(i)%vname="sxxe";          fields(i)%grid="grid_Ni_4D"
+        i = iom_add(i); fields(i)%vname="syye";          fields(i)%grid="grid_Ni_4D"
+        i = iom_add(i); fields(i)%vname="sxye";          fields(i)%grid="grid_Ni_4D"
+!common for both
+        i = iom_add(i); fields(i)%vname="sxap";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="syap";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxxap";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="syyap";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxyap";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxvp";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="syvp";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxxvp";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="syyvp";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sxyvp";         fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="stress1_i";     fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="stress2_i";     fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="stress12_i";    fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="nn_fsbc";       fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="kt_ice";        fields(i)%grid="grid_scalar"
+        i = iom_add(i); fields(i)%vname="v_i";           fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="v_s";           fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="sv_i";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="a_i";           fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="t_su";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="u_ice";         fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="v_ice";         fields(i)%grid="grid_N"
+!NEMO format restat
+        DO jk = 1, nlay_s
+           WRITE(zchar,'(I2.2)') jk
+           znam = 'e_s'//'_l'//zchar
+           i = iom_add(i); fields(i)%vname=znam;         fields(i)%grid="grid_Ni_3D"
+        END DO
+!XIOS format restart
+        i = iom_add(i); fields(i)%vname="e_s";           fields(i)%grid="grid_Ns_4D"
+!NEMO format restat
+        DO jk = 1, nlay_i
+           WRITE(zchar,'(I2.2)') jk
+           znam = 'e_i'//'_l'//zchar
+           i = iom_add(i); fields(i)%vname=znam;         fields(i)%grid="grid_Ni_3D"
+        END DO
+!XIOS format restart
+        i = iom_add(i); fields(i)%vname="e_i";           fields(i)%grid="grid_Ni_4D"
+!common for both
+        i = iom_add(i); fields(i)%vname="oa_i";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="a_ip";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="v_ip";          fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="cnd_ice";       fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="t1_ice";        fields(i)%grid="grid_Ni_3D"
+        i = iom_add(i); fields(i)%vname="snwice_mass";   fields(i)%grid="grid_N"
+        i = iom_add(i); fields(i)%vname="snwice_mass_b"; fields(i)%grid="grid_N"
+#endif
    END SUBROUTINE iom_set_rst_vars
 
 
-   SUBROUTINE iom_set_rstw_active(cdrst_file)
+   SUBROUTINE iom_set_rstw_active(drst_wfields, cdrst_file)
       !!---------------------------------------------------------------------
       !!                   ***  SUBROUTINE iom_set_rstw_active   ***
@@ -525,5 +661,6 @@
       !!---------------------------------------------------------------------
 !sets enabled = .TRUE. for each field in restart file
-   CHARACTER(len=*) :: cdrst_file
+   CHARACTER(len=*), INTENT(IN) :: cdrst_file
+   TYPE(RST_FIELD),  INTENT(IN) :: drst_wfields(max_rst_fields)
 #if defined key_iomput
    TYPE(xios_field) :: field_hdl
@@ -549,18 +686,18 @@
 !define fields for restart context
         DO i = 1, max_rst_fields
-         IF( rst_wfields(i)%active ) THEN
-                CALL xios_add_child(file_hdl, field_hdl, TRIM(rst_wfields(i)%vname))
-                SELECT CASE (TRIM(rst_wfields(i)%grid))
+         IF( drst_wfields(i)%active ) THEN
+                CALL xios_add_child(file_hdl, field_hdl, TRIM(drst_wfields(i)%vname))
+                SELECT CASE (TRIM(drst_wfields(i)%grid))
                  CASE ("grid_N_3D")
-                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_wfields(i)%vname), &
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
                         domain_ref="grid_N", axis_ref="nav_lev", prec = 8, operation = "instant")
                  CASE ("grid_N")
-                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_wfields(i)%vname), &
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
                         domain_ref="grid_N", prec = 8, operation = "instant") 
                  CASE ("grid_vector")
-                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_wfields(i)%vname), &
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
                          axis_ref="nav_lev", prec = 8, operation = "instant")
                  CASE ("grid_scalar")
-                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_wfields(i)%vname), &
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
                         scalar_ref = "grid_scalar", prec = 8, operation = "instant")
                 END SELECT
@@ -588,4 +725,5 @@
    TYPE(xios_scalar)                 :: scalar_hdl 
    TYPE(xios_scalargroup)            :: scalargroup_hdl 
+   INTEGER                           :: ji
 
      CALL xios_get_handle("domain_definition",domaingroup_hdl) 
@@ -602,4 +740,13 @@
      CALL xios_get_handle("scalar_definition", scalargroup_hdl) 
      CALL xios_add_child(scalargroup_hdl, scalar_hdl, "grid_scalar") 
+#if defined key_si3
+     CALL xios_get_handle("axis_definition",axisgroup_hdl) 
+     CALL xios_add_child(axisgroup_hdl, axis_hdl, "numcat")
+     CALL iom_set_axis_attr( "numcat", (/ (REAL(ji,wp), ji=1,jpl) /) )
+     CALL xios_add_child(axisgroup_hdl, axis_hdl, "nlay_i")
+     CALL iom_set_axis_attr( "nlay_i", (/ (REAL(ji,wp), ji=1,nlay_i) /) )
+     CALL xios_add_child(axisgroup_hdl, axis_hdl, "nlay_s")
+     CALL iom_set_axis_attr( "nlay_s", (/ (REAL(ji,wp), ji=1,nlay_s) /) )
+#endif
 #endif
    END SUBROUTINE iom_set_rst_context
@@ -614,5 +761,5 @@
 #if defined key_iomput
       TYPE(xios_context) :: nemo_hdl
-
+      
       IF( TRIM(Agrif_CFixed()) == '0' ) THEN
         CALL xios_get_handle(TRIM(cdname),nemo_hdl)
@@ -942,7 +1089,5 @@
 #if defined key_iomput
          IF(lwp) WRITE(numout,*) 'XIOS RST READ (0D): ', trim(cdvar)
-         CALL iom_swap( TRIM(crxios_context) )
          CALL xios_recv_field( trim(cdvar), pvar)
-         CALL iom_swap( TRIM(cxios_context) )
 #else
          WRITE(ctmp1,*) 'Can not use XIOS in iom_g0d, file: '//trim(clname)//', var:'//trim(cdvar)
@@ -1010,8 +1155,29 @@
       ENDIF
    END SUBROUTINE iom_g3d
+
+   SUBROUTINE iom_g4d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lrowattr, ldxios )
+      INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file
+      INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read
+      CHARACTER(len=*), INTENT(in   )                             ::   cdvar     ! Name of the variable
+      REAL(wp)        , INTENT(  out), DIMENSION(:,:,:,:)         ::   pvar      ! read field
+      INTEGER         , INTENT(in   )                  , OPTIONAL ::   ktime     ! record number
+      INTEGER         , INTENT(in   ), DIMENSION(4)    , OPTIONAL ::   kstart    ! start axis position of the reading 
+      INTEGER         , INTENT(in   ), DIMENSION(4)    , OPTIONAL ::   kcount    ! number of points in each axis
+      LOGICAL         , INTENT(in   )                  , OPTIONAL ::   lrowattr  ! logical flag telling iom_get to
+                                                                                 ! look for and use a file attribute
+                                                                                 ! called open_ocean_jstart to set the start
+                                                                                 ! value for the 2nd dimension (netcdf only)
+      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios        ! read data using XIOS
+      !
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r4d=pvar,   &
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount, &
+              &                                                     lrowattr=lrowattr, ldxios=ldxios )
+      ENDIF
+   END SUBROUTINE iom_g4d
    !!----------------------------------------------------------------------
 
    SUBROUTINE iom_get_123d( kiomid, kdom  , cdvar ,   &
-         &                  pv_r1d, pv_r2d, pv_r3d,   &
+         &                  pv_r1d, pv_r2d, pv_r3d, pv_r4d,  &
          &                  ktime , kstart, kcount,   &
          &                  lrowattr, ldxios        )
@@ -1029,4 +1195,5 @@
       REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
       REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
+      REAL(wp), DIMENSION(:,:,:,:),INTENT(  out), OPTIONAL ::   pv_r4d     ! read field (4D case)
       INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime      ! record number
       INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart     ! start position of the reading in each axis 
@@ -1293,6 +1460,12 @@
 #if defined key_iomput
 !would be good to be able to check which context is active and swap only if current is not restart
-         CALL iom_swap( TRIM(crxios_context) ) 
-         IF( PRESENT(pv_r3d) ) THEN
+         IF( PRESENT(pv_r4d) ) THEN
+            pv_r4d(:, :, :, :) = 0.
+            if(lwp) write(numout,*) 'XIOS RST READ (4D): ',trim(cdvar)
+            CALL xios_recv_field( trim(cdvar), pv_r4d)
+            IF(idom /= jpdom_unknown ) then
+                CALL lbc_lnk( 'iom', pv_r4d,'Z', -999., kfillmode = jpfillnothing)
+            ENDIF
+         ELSEIF( PRESENT(pv_r3d) ) THEN
             pv_r3d(:, :, :) = 0.
             if(lwp) write(numout,*) 'XIOS RST READ (3D): ',trim(cdvar)
@@ -1313,5 +1486,4 @@
             CALL xios_recv_field( trim(cdvar), pv_r1d)
          ENDIF
-         CALL iom_swap( TRIM(cxios_context) )
 #else
          istop = istop + 1 
@@ -1336,4 +1508,7 @@
          IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
          IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
+      ELSEIF( PRESENT(pv_r4d) ) THEN
+         IF( zscf /= 1.)   pv_r4d(:,:,:,:) = pv_r4d(:,:,:,:) * zscf
+         IF( zofs /= 0.)   pv_r4d(:,:,:,:) = pv_r4d(:,:,:,:) + zofs
       ENDIF
       !
@@ -2395,4 +2570,15 @@
    END FUNCTION iom_sdate
 
+   INTEGER FUNCTION iom_add(idm)
+   INTEGER :: idm
+
+   iom_add = idm + 1
+   IF( iom_add > max_rst_fields) THEN
+     WRITE(ctmp1,*) 'E R R O R : iom_set_rst_vars SIZE of RST_FIELD array is too small'
+     CALL ctl_stop( 'iom_add:', ctmp1 )
+   ENDIF
+
+   END FUNCTION iom_add
+
 #else
    !!----------------------------------------------------------------------
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 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom_def.F90	(revision 11837)
@@ -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 = 95 !: maximum number of restart variables defined in iom_set_rst_vars
+   INTEGER, PARAMETER, PUBLIC                   :: max_rst_fields = 360!: 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
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/restart.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/restart.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/restart.F90	(revision 11837)
@@ -224,12 +224,12 @@
          IF( lrxios) THEN
              crxios_context = 'nemo_rst'
-             IF( .NOT.lxios_set ) THEN
+             IF( .NOT. lxios_set ) THEN
                  IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS'
-                 CALL iom_init( crxios_context, ld_tmppatch = .false. )
+                 CALL iom_init( crxios_context, TRIM(clpath)//cn_ocerst_in, ld_tmppatch = .false. )
                  lxios_set = .TRUE.
              ENDIF
          ENDIF
          IF( TRIM(Agrif_CFixed()) /= '0' .AND. lrxios) THEN
-             CALL iom_init( crxios_context, ld_tmppatch = .false. )
+             CALL iom_init( crxios_context, TRIM(clpath)//cn_ocerst_in, ld_tmppatch = .false. )
              IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for AGRIF'
              lxios_set = .TRUE.
@@ -256,4 +256,5 @@
 
       ! Check dynamics and tracer time-step consistency and force Euler restart if changed
+      IF(lrxios) CALL iom_swap(crxios_context)
       IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
          CALL iom_get( numror, 'rdt', zrdt, ldxios = lrxios )
@@ -270,4 +271,5 @@
          rhop = rau0
          CALL iom_get( numror, jpdom_autoglo, 'tn'     , w3d, ldxios = lrxios ) 
+         IF(lrxios) CALL iom_swap(cxios_context)
          tsn(:,:,1,jp_tem) = w3d(:,:,1)
          RETURN 
@@ -308,4 +310,5 @@
          !
       ENDIF
+      IF(lrxios) CALL iom_swap(cxios_context)
       !
    END SUBROUTINE rst_read
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcapr.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcapr.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcapr.F90	(revision 11837)
@@ -111,5 +111,5 @@
       !
       IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active('ssh_ibb')
+         CALL iom_set_rstw_var_active(rst_wfields, 'ssh_ibb')
       ENDIF
    END SUBROUTINE sbc_apr_init
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcisf.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcisf.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcisf.F90	(revision 11837)
@@ -206,8 +206,10 @@
          IF( ln_rstart .AND.    &                     ! Restart: read in restart file
             &   iom_varid( numror, 'fwf_isf_b', ldstop = .FALSE. ) > 0 ) THEN
+            IF(lrxios) CALL iom_swap(crxios_context)
             IF(lwp) WRITE(numout,*) '          nit000-1 isf tracer content forcing fields read in the restart file'
             CALL iom_get( numror, jpdom_autoglo, 'fwf_isf_b', fwfisf_b(:,:)         , ldxios = lrxios )   ! before salt content isf_tsc trend
             CALL iom_get( numror, jpdom_autoglo, 'isf_sc_b' , risf_tsc_b(:,:,jp_sal), ldxios = lrxios )   ! before salt content isf_tsc trend
             CALL iom_get( numror, jpdom_autoglo, 'isf_hc_b' , risf_tsc_b(:,:,jp_tem), ldxios = lrxios )   ! before salt content isf_tsc trend
+            IF(lrxios) CALL iom_swap(cxios_context)
          ELSE
             fwfisf_b(:,:)    = fwfisf(:,:)
@@ -402,7 +404,7 @@
 
       IF( lwxios ) THEN
-          CALL iom_set_rstw_var_active('fwf_isf_b')
-          CALL iom_set_rstw_var_active('isf_hc_b')
-          CALL iom_set_rstw_var_active('isf_sc_b')
+          CALL iom_set_rstw_var_active(rst_wfields, 'fwf_isf_b')
+          CALL iom_set_rstw_var_active(rst_wfields, 'isf_hc_b')
+          CALL iom_set_rstw_var_active(rst_wfields, 'isf_sc_b')
       ENDIF
 
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcmod.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcmod.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcmod.F90	(revision 11837)
@@ -351,11 +351,11 @@
       !
       IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active('utau_b')
-         CALL iom_set_rstw_var_active('vtau_b')
-         CALL iom_set_rstw_var_active('qns_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'utau_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'vtau_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'qns_b')
          ! The 3D heat content due to qsr forcing is treated in traqsr
          ! CALL iom_set_rstw_var_active('qsr_b')
-         CALL iom_set_rstw_var_active('emp_b')
-         CALL iom_set_rstw_var_active('sfx_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'emp_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'sfx_b')
       ENDIF
 
@@ -499,4 +499,5 @@
          IF( ln_rstart .AND.    &                               !* Restart: read in restart file
             & iom_varid( numror, 'utau_b', ldstop = .FALSE. ) > 0 ) THEN
+            IF(lrxios) CALL iom_swap(crxios_context)
             IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields red in the restart file'
             CALL iom_get( numror, jpdom_autoglo, 'utau_b', utau_b, ldxios = lrxios )   ! before i-stress  (U-point)
@@ -512,4 +513,5 @@
                sfx_b (:,:) = sfx(:,:)
             ENDIF
+            IF(lrxios) CALL iom_swap(cxios_context)
          ELSE                                                   !* no restart: set from nit000 values
             IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields set to nit000'
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcrnf.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcrnf.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcrnf.F90	(revision 11837)
@@ -146,8 +146,10 @@
          IF( ln_rstart .AND.    &                               !* Restart: read in restart file
             & iom_varid( numror, 'rnf_b', ldstop = .FALSE. ) > 0 ) THEN
+            IF(lrxios) CALL iom_swap(crxios_context)
             IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields red in the restart file', lrxios
             CALL iom_get( numror, jpdom_autoglo, 'rnf_b', rnf_b, ldxios = lrxios )     ! before runoff
             CALL iom_get( numror, jpdom_autoglo, 'rnf_hc_b', rnf_tsc_b(:,:,jp_tem), ldxios = lrxios )   ! before heat content of runoff
             CALL iom_get( numror, jpdom_autoglo, 'rnf_sc_b', rnf_tsc_b(:,:,jp_sal), ldxios = lrxios )   ! before salinity content of runoff
+            IF(lrxios) CALL iom_swap(cxios_context)
          ELSE                                                   !* no restart: set from nit000 values
             IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields set to nit000'
@@ -467,7 +469,7 @@
       !
       IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active('rnf_b')
-         CALL iom_set_rstw_var_active('rnf_hc_b')
-         CALL iom_set_rstw_var_active('rnf_sc_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'rnf_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'rnf_hc_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'rnf_sc_b')
       ENDIF
 
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcssm.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcssm.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/SBC/sbcssm.F90	(revision 11837)
@@ -208,4 +208,5 @@
          !
          IF( ln_rstart .AND. iom_varid( numror, 'nn_fsbc', ldstop = .FALSE. ) > 0 ) THEN
+            IF(lrxios) CALL iom_swap(crxios_context)
             l_ssm_mean = .TRUE.
             CALL iom_get( numror               , 'nn_fsbc', zf_sbc, ldxios = lrxios )    ! sbc frequency of previous run
@@ -222,4 +223,5 @@
                frq_m(:,:) = 1._wp   ! default definition
             ENDIF
+            IF(lrxios) CALL iom_swap(cxios_context)
             !
             IF( zf_sbc /= REAL( nn_fsbc, wp ) ) THEN      ! nn_fsbc has changed between 2 runs
@@ -257,12 +259,12 @@
       !
       IF( lwxios.AND.nn_fsbc > 1 ) THEN
-         CALL iom_set_rstw_var_active('nn_fsbc')
-         CALL iom_set_rstw_var_active('ssu_m')
-         CALL iom_set_rstw_var_active('ssv_m')
-         CALL iom_set_rstw_var_active('sst_m')
-         CALL iom_set_rstw_var_active('sss_m')
-         CALL iom_set_rstw_var_active('ssh_m')
-         CALL iom_set_rstw_var_active('e3t_m')
-         CALL iom_set_rstw_var_active('frq_m')
+         CALL iom_set_rstw_var_active(rst_wfields, 'nn_fsbc')
+         CALL iom_set_rstw_var_active(rst_wfields, 'ssu_m')
+         CALL iom_set_rstw_var_active(rst_wfields, 'ssv_m')
+         CALL iom_set_rstw_var_active(rst_wfields, 'sst_m')
+         CALL iom_set_rstw_var_active(rst_wfields, 'sss_m')
+         CALL iom_set_rstw_var_active(rst_wfields, 'ssh_m')
+         CALL iom_set_rstw_var_active(rst_wfields, 'e3t_m')
+         CALL iom_set_rstw_var_active(rst_wfields, 'frq_m')
       ENDIF
 
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/TRA/traqsr.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/TRA/traqsr.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/TRA/traqsr.F90	(revision 11837)
@@ -137,5 +137,7 @@
             IF(lwp) WRITE(numout,*) '          nit000-1 qsr tracer content forcing field read in the restart file'
             z1_2 = 0.5_wp
+            IF(lrxios) CALL iom_swap(crxios_context)
             CALL iom_get( numror, jpdom_autoglo, 'qsr_hc_b', qsr_hc_b, ldxios = lrxios )   ! before heat content trend due to Qsr flux
+            IF(lrxios) CALL iom_swap(cxios_context)
          ELSE                                           ! No restart or restart not found: Euler forward time stepping
             z1_2 = 1._wp
@@ -423,5 +425,7 @@
       ! 1st ocean level attenuation coefficient (used in sbcssm)
       IF( iom_varid( numror, 'fraqsr_1lev', ldstop = .FALSE. ) > 0 ) THEN
+         IF(lrxios) CALL iom_swap(crxios_context)
          CALL iom_get( numror, jpdom_autoglo, 'fraqsr_1lev'  , fraqsr_1lev, ldxios = lrxios  )
+         IF(lrxios) CALL iom_swap(cxios_context)
       ELSE
          fraqsr_1lev(:,:) = 1._wp   ! default : no penetration
@@ -429,6 +433,6 @@
       !
       IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active('qsr_hc_b')
-         CALL iom_set_rstw_var_active('fraqsr_1lev')
+         CALL iom_set_rstw_var_active(rst_wfields, 'qsr_hc_b')
+         CALL iom_set_rstw_var_active(rst_wfields, 'fraqsr_1lev')
       ENDIF
       !
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/TRA/trasbc.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/TRA/trasbc.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/TRA/trasbc.F90	(revision 11837)
@@ -107,4 +107,5 @@
          IF( ln_rstart .AND.    &               ! Restart: read in restart file
               & iom_varid( numror, 'sbc_hc_b', ldstop = .FALSE. ) > 0 ) THEN
+            IF(lrxios) CALL iom_swap(crxios_context)
             IF(lwp) WRITE(numout,*) '          nit000-1 sbc tracer content field read in the restart file'
             zfact = 0.5_wp
@@ -112,4 +113,5 @@
             CALL iom_get( numror, jpdom_autoglo, 'sbc_hc_b', sbc_tsc_b(:,:,jp_tem), ldxios = lrxios )   ! before heat content sbc trend
             CALL iom_get( numror, jpdom_autoglo, 'sbc_sc_b', sbc_tsc_b(:,:,jp_sal), ldxios = lrxios )   ! before salt content sbc trend
+            IF(lrxios) CALL iom_swap(cxios_context)
          ELSE                                   ! No restart or restart not found: Euler forward time stepping
             zfact = 1._wp
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdfgls.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdfgls.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdfgls.F90	(revision 11837)
@@ -1133,8 +1133,8 @@
       !
       IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active('en')
-         CALL iom_set_rstw_var_active('avt_k')
-         CALL iom_set_rstw_var_active('avm_k')
-         CALL iom_set_rstw_var_active('hmxl_n')
+         CALL iom_set_rstw_var_active(rst_wfields, 'en')
+         CALL iom_set_rstw_var_active(rst_wfields, 'avt_k')
+         CALL iom_set_rstw_var_active(rst_wfields, 'avm_k')
+         CALL iom_set_rstw_var_active(rst_wfields, 'hmxl_n')
       ENDIF
       !
@@ -1172,8 +1172,10 @@
             !
             IF( MIN( id1, id2, id3, id4 ) > 0 ) THEN        ! all required arrays exist
+               IF(lrxios) CALL iom_swap(crxios_context)
                CALL iom_get( numror, jpdom_autoglo, 'en'    , en    , ldxios = lrxios )
                CALL iom_get( numror, jpdom_autoglo, 'avt_k' , avt_k , ldxios = lrxios )
                CALL iom_get( numror, jpdom_autoglo, 'avm_k' , avm_k , ldxios = lrxios )
                CALL iom_get( numror, jpdom_autoglo, 'hmxl_n', hmxl_n, ldxios = lrxios )
+               IF(lrxios) CALL iom_swap(cxios_context)
             ELSE                        
                IF(lwp) WRITE(numout,*)
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdfosm.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdfosm.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdfosm.F90	(revision 11837)
@@ -1510,7 +1510,7 @@
      !
      IF( lwxios ) THEN
-        CALL iom_set_rstw_var_active('wn')
-        CALL iom_set_rstw_var_active('hbl')
-        CALL iom_set_rstw_var_active('hbli')
+        CALL iom_set_rstw_var_active(rst_wfields, 'wn')
+        CALL iom_set_rstw_var_active(rst_wfields, 'hbl')
+        CALL iom_set_rstw_var_active(rst_wfields, 'hbli')
      ENDIF
    END SUBROUTINE zdf_osm_init
@@ -1543,4 +1543,5 @@
      !!-----------------------------------------------------------------------------
      IF( TRIM(cdrw) == 'READ'.AND. ln_rstart) THEN
+        IF(lrxios) CALL iom_swap(crxios_context)
         id1 = iom_varid( numror, 'wn'   , ldstop = .FALSE. )
         IF( id1 > 0 ) THEN                       ! 'wn' exists; read
@@ -1561,4 +1562,5 @@
            WRITE(numout,*) ' ===>>>> : previous run without osmosis scheme, hbl computed from stratification'
         END IF
+        IF(lrxios) CALL iom_swap(cxios_context)
      END IF
 
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdfric.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdfric.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdfric.F90	(revision 11837)
@@ -106,6 +106,6 @@
       !
       IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active('avt_k')
-         CALL iom_set_rstw_var_active('avm_k')
+         CALL iom_set_rstw_var_active(rst_wfields, 'avt_k')
+         CALL iom_set_rstw_var_active(rst_wfields, 'avm_k')
       ENDIF
    END SUBROUTINE zdf_ric_init
@@ -222,4 +222,5 @@
          !           !* Read the restart file
          IF( ln_rstart ) THEN
+            IF(lrxios) CALL iom_swap(crxios_context)
             id1 = iom_varid( numror, 'avt_k', ldstop = .FALSE. )
             id2 = iom_varid( numror, 'avm_k', ldstop = .FALSE. )
@@ -229,4 +230,5 @@
                CALL iom_get( numror, jpdom_autoglo, 'avm_k', avm_k, ldxios = lrxios )
             ENDIF
+            IF(lrxios) CALL iom_swap(cxios_context)
          ENDIF
          !           !* otherwise Kz already set to the background value in zdf_phy_init
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdftke.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdftke.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/ZDF/zdftke.F90	(revision 11837)
@@ -740,8 +740,8 @@
       !
       IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active('en')
-         CALL iom_set_rstw_var_active('avt_k')
-         CALL iom_set_rstw_var_active('avm_k')
-         CALL iom_set_rstw_var_active('dissl')
+         CALL iom_set_rstw_var_active(rst_wfields, 'en')
+         CALL iom_set_rstw_var_active(rst_wfields, 'avt_k')
+         CALL iom_set_rstw_var_active(rst_wfields, 'avm_k')
+         CALL iom_set_rstw_var_active(rst_wfields, 'dissl')
       ENDIF
    END SUBROUTINE zdf_tke_init
@@ -776,8 +776,10 @@
             !
             IF( MIN( id1, id2, id3, id4 ) > 0 ) THEN      ! fields exist
+               IF(lrxios) CALL iom_swap(crxios_context)
                CALL iom_get( numror, jpdom_autoglo, 'en'   , en   , ldxios = lrxios )
                CALL iom_get( numror, jpdom_autoglo, 'avt_k', avt_k, ldxios = lrxios )
                CALL iom_get( numror, jpdom_autoglo, 'avm_k', avm_k, ldxios = lrxios )
                CALL iom_get( numror, jpdom_autoglo, 'dissl', dissl, ldxios = lrxios )
+               IF(lrxios) CALL iom_swap(cxios_context)
             ELSE                                          ! start TKE from rest
                IF(lwp) WRITE(numout,*)
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/step.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/step.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/step.F90	(revision 11837)
@@ -311,5 +311,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
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/daymod.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/daymod.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/daymod.F90	(revision 11837)
@@ -143,8 +143,8 @@
       CALL day( nit000 )
       IF( lwxios ) THEN
-        CALL iom_set_rstw_var_active('kt')
-        CALL iom_set_rstw_var_active('ndastp')
-        CALL iom_set_rstw_var_active('adatrj')
-        CALL iom_set_rstw_var_active('ntime')
+        CALL iom_set_rstw_var_active(rst_wfields, 'kt')
+        CALL iom_set_rstw_var_active(rst_wfields, 'ndastp')
+        CALL iom_set_rstw_var_active(rst_wfields, 'adatrj')
+        CALL iom_set_rstw_var_active(rst_wfields, 'ntime')
       ENDIF
       !
@@ -323,4 +323,5 @@
 
          IF( iom_varid( numror, 'kt', ldstop = .FALSE. ) > 0 ) THEN
+            IF(lrxios) CALL iom_swap(crxios_context)
             ! Get Calendar informations
             CALL iom_get( numror, 'kt', zkt, ldxios = lrxios )   ! last time-step of previous run
@@ -379,4 +380,5 @@
                ! note this is wrong if time step has changed during run
             ENDIF
+            IF(lrxios) CALL iom_swap(cxios_context)
          ELSE
             ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day)
Index: /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/step.F90
===================================================================
--- /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/step.F90	(revision 11836)
+++ /NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/SAS/step.F90	(revision 11837)
@@ -140,4 +140,10 @@
       ENDIF
       IF( kstp == nitend .OR. indic < 0 ) THEN
+                  IF(lrxios) THEN
+#if defined key_si3
+                             CALL iom_context_finalize( crixios_context)
+#endif
+                             CALL iom_context_finalize( crxios_context)
+                  ENDIF
                              CALL iom_context_finalize( cxios_context ) ! needed for XIOS+AGRIF
       ENDIF
