Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/main/bibliography.bib
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/main/bibliography.bib	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/main/bibliography.bib	(revision 14018)
@@ -1906,4 +1906,14 @@
 }
 
+@Article{        love_PRSLA1909,
+  author       = "A. E. H. Love",
+  title        = "The Yielding of the Earth to Disturbing Forces",
+  journal      = "Proc. R. Soc. Lond. A",
+  year         = "1909",
+  volume       = "82",
+  pages        = "73-88",
+  doi          = "10.1098/rspa.1909.0008"
+}
+
 @article{         losch_JGR08,
   title         = "Modeling ice shelf cavities in a z coordinate Ocean
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_DIA.tex
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_DIA.tex	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_DIA.tex	(revision 14018)
@@ -119,6 +119,7 @@
 \subsection{XIOS: Reading and writing restart file}
 
-XIOS may be used to read single file restart produced by \NEMO. Currently only the variables written to
-file \forcode{numror} can be handled by XIOS. To activate restart reading using XIOS, set \np[=.true. ]{ln_xios_read}{ln\_xios\_read}
+XIOS may be used to read single file restart produced by \NEMO. The variables written to
+file \forcode{numror} (OCE), \forcode{numrir} (SI3), \forcode{numrtr} (TOP), \forcode{numrsr} (SED) can be handled by XIOS. 
+To activate restart reading using XIOS, set \np[=.true. ]{ln_xios_read}{ln\_xios\_read}
 in \textit{namelist\_cfg}. This setting will be ignored when multiple restart files are present, and default \NEMO
 functionality will be used for reading. There is no need to change iodef.xml file to use XIOS to read
@@ -142,15 +143,4 @@
 have to be rebuild before continuing the run. This option aims to reduce number of restart files generated by \NEMO\ only,
 and may be useful when there is a need to change number of processors used to run simulation.
-
-If an additional variable must be written to a restart file, the following steps are needed:
-\begin{enumerate}
-\item Add variable name to a list of restart variables (in subroutine \rou{iom\_set\_rst\_vars,} \mdl{iom}) and
-define correct grid for the variable (\forcode{grid_N_3D} - 3D variable, \forcode{grid_N} - 2D variable, \forcode{grid_vector} -
-1D variable, \forcode{grid_scalar} - scalar),
-\item Add variable to the list of fields written by restart.  This can be done either in subroutine
-\rou{iom\_set\_rstw\_core} (\mdl{iom}) or by calling  \rou{iom\_set\_rstw\_active} (\mdl{iom}) with the name of a variable
-as an argument. This convention follows approach for writing restart using iom, where variables are
-written either by \rou{rst\_write} or by calling \rou{iom\_rstput} from individual routines.
-\end{enumerate}
 
 An older versions of XIOS do not support reading functionality. It's recommended to use at least XIOS2@1451.
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_DYN.tex
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_DYN.tex	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_DYN.tex	(revision 14018)
@@ -1245,5 +1245,5 @@
 the atmospheric pressure is taken into account when computing the surface pressure gradient.
 
-(2) When \np[=.true.]{ln_tide_pot}{ln\_tide\_pot} and \np[=.true.]{ln_tide}{ln\_tide} (see \autoref{sec:SBC_tide}),
+(2) When \np[=.true.]{ln_tide_pot}{ln\_tide\_pot} and \np[=.true.]{ln_tide}{ln\_tide} (see \autoref{sec:SBC_TDE}),
 the tidal potential is taken into account when computing the surface pressure gradient.
 
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_LBC.tex
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_LBC.tex	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_LBC.tex	(revision 14018)
@@ -16,4 +16,5 @@
     Release & Author(s) & Modifications \\
     \hline
+    {\em  next} & {\em Simon M{\" u}ller} & {\em Minor update of \autoref{subsec:LBC_bdy_tides}} \\[2mm]
     {\em   4.0} & {\em ...} & {\em ...} \\
     {\em   3.6} & {\em ...} & {\em ...} \\
@@ -665,38 +666,33 @@
 
 Tidal forcing at open boundaries requires the activation of surface
-tides (i.e., in \nam{_tide}{\_tide}, \np{ln_tide}{ln\_tide} needs to be set to
-\forcode{.true.} and the required constituents need to be activated by
-including their names in the \np{clname}{clname} array; see
-\autoref{sec:SBC_tide}). Specific options related to the reading in of
+tides (i.e., in \nam{_tide}{\_tide}, \np[=.true.]{ln_tide}{ln\_tide} with the active tidal
+constituents listed in the \np{sn_tide_cnames}{sn\_tide\_cnames} array; see
+\autoref{sec:SBC_TDE}). The specific options related to the reading in of
 the complex harmonic amplitudes of elevation (SSH) and barotropic
-velocity (u,v) at open boundaries are defined through the
-\nam{bdy_tide}{bdy\_tide} namelist parameters.\\
+velocity components (u,v) at the open boundaries are defined through the
+\nam{bdy_tide}{bdy\_tide} namelist parameters.\par
 
 The tidal harmonic data at open boundaries can be specified in two
 different ways, either on a two-dimensional grid covering the entire
 model domain or along open boundary segments; these two variants can
-be selected by setting \np{ln_bdytide_2ddta }{ln\_bdytide\_2ddta } to \forcode{.true.} or
-\forcode{.false.}, respectively. In either case, the real and
-imaginary parts of SSH and the two barotropic velocity components for
-each activated tidal constituent \textit{tcname} have to be provided
-separately: when two-dimensional data is used, variables
-\textit{tcname\_z1} and \textit{tcname\_z2} for real and imaginary SSH,
-respectively, are expected in input file \np{filtide}{filtide} with suffix
-\ifile{\_grid\_T}, variables \textit{tcname\_u1} and
-\textit{tcname\_u2} for real and imaginary u, respectively, are
-expected in input file \np{filtide}{filtide} with suffix \ifile{\_grid\_U}, and
-\textit{tcname\_v1} and \textit{tcname\_v2} for real and imaginary v,
-respectively, are expected in input file \np{filtide}{filtide} with suffix
-\ifile{\_grid\_V}; when data along open boundary segments is used,
-variables \textit{z1} and \textit{z2} (real and imaginary part of SSH)
-are expected to be available from file \np{filtide}{filtide} with suffix
-\ifile{tcname\_grid\_T}, variables \textit{u1} and \textit{u2} (real
-and imaginary part of u) are expected to be available from file
-\np{filtide}{filtide} with suffix \ifile{tcname\_grid\_U}, and variables
-\textit{v1} and \textit{v2} (real and imaginary part of v) are
-expected to be available from file \np{filtide}{filtide} with suffix
-\ifile{tcname\_grid\_V}. If \np{ln_bdytide_conj}{ln\_bdytide\_conj} is set to
-\forcode{.true.}, the data is expected to be in complex conjugate
-form.
+be selected by setting \np[=.true.]{ln_bdytide_2ddta}{ln\_bdytide\_2ddta} or
+\np[=.false.]{ln_bdytide_2ddta}{ln\_bdytide\_2ddta}, respectively. In either
+case, the real and imaginary parts of SSH, u, and v amplitudes associated with
+each activated tidal constituent \texttt{<constituent>} have to be provided
+separately as fields in input files with names based on
+\np[=<input>]{filtide}{filtide}: when two-dimensional data is used, variables
+\texttt{<constituent>\_z1} and \texttt{<constituent>\_z2} for the real and imaginary parts of
+SSH, respectively, are expected to be available in file
+\ifile{<input>\_grid\_T}, variables \texttt{<constituent>\_u1} and
+\texttt{<constituent>\_u2} for the real and imaginary parts of u, respectively, in file
+\ifile{<input>\_grid\_U}, and \texttt{<constituent>\_v1} and
+\texttt{<constituent>\_v2} for the real and imaginary parts of v, respectively, in file
+\ifile{<input>\_grid\_V}; when data along open boundary segments is used,
+variables \texttt{z1} and \texttt{z2} (real and imaginary part of SSH) are
+expected to be available in file \ifile{<input><constituent>\_grid\_T},
+variables \texttt{u1} and \texttt{u2} (real and imaginary part of u) in file
+\ifile{<input><constituent>\_grid\_U}, and variables \texttt{v1} and \texttt{v2}
+(real and imaginary part of v) in file
+\ifile{<input><constituent>\_grid\_V}.\par
 
 Note that the barotropic velocity components are assumed to be defined
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_SBC.tex
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_SBC.tex	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/latex/NEMO/subfiles/chap_SBC.tex	(revision 14018)
@@ -5,5 +5,5 @@
 \begin{document}
 
-\chapter{Surface Boundary Condition (SBC, SAS, ISF, ICB)}
+\chapter{Surface Boundary Condition (SBC, SAS, ISF, ICB, TDE)}
 \label{chap:SBC}
 
@@ -18,4 +18,5 @@
     Release & Author(s) & Modifications \\
     \hline
+    {\em  next} & {\em Simon M{\" u}ller} & {\em Update of \autoref{sec:SBC_TDE}}\\[2mm]
     {\em   4.0} & {\em ...} & {\em ...} \\
     {\em   3.6} & {\em ...} & {\em ...} \\
@@ -1013,6 +1014,6 @@
 
 %% =================================================================================================
-\section[Surface tides (\textit{sbctide.F90})]{Surface tides (\protect\mdl{sbctide})}
-\label{sec:SBC_tide}
+\section{Surface tides (TDE)}
+\label{sec:SBC_TDE}
 
 \begin{listing}
@@ -1022,43 +1023,80 @@
 \end{listing}
 
-The tidal forcing, generated by the gravity forces of the Earth-Moon and Earth-Sun sytems,
-is activated if \np{ln_tide}{ln\_tide} and \np{ln_tide_pot}{ln\_tide\_pot} are both set to \forcode{.true.} in \nam{_tide}{\_tide}.
-This translates as an additional barotropic force in the momentum \autoref{eq:MB_PE_dyn} such that:
+\subsection{Tidal constituents}
+Ocean model component TDE provides the common functionality for tidal forcing
+and tidal analysis in the model framework. This includes the computation of the gravitational
+surface forcing, as well as support for lateral forcing at open boundaries (see
+\autoref{subsec:LBC_bdy_tides}) and tidal harmonic analysis (see
+\autoref{subsec:DIA_diamlr} and \autoref{subsec:DIA_diadetide}). The module is
+activated with \np[=.true.]{ln_tide}{ln\_tide} in namelist
+\nam{_tide}{\_tide}. It provides the same 34 tidal constituents that are
+included in the
+\href{https://www.aviso.altimetry.fr/en/data/products/auxiliary-products/global-tide-fes.html}{FES2014
+  ocean tide model}: Mf, Mm, Ssa, Mtm, Msf, Msqm, Sa, K1, O1, P1, Q1, J1, S1,
+M2, S2, N2, K2, nu2, mu2, 2N2, L2, T2, eps2, lam2, R2, M3, MKS2, MN4, MS4, M4,
+N4, S4, M6, and M8; see file \hf{tide} and \mdl{tide\_mod} for further
+information and references\footnote{As a legacy option \np{ln_tide_var} can be
+  set to \forcode{0}, in which case the 19 tidal constituents (M2, N2, 2N2, S2,
+  K2, K1, O1, Q1, P1, M4, Mf, Mm, Msqm, Mtm, S1, MU2, NU2, L2, and T2; see file
+  \hf{tide}) and associated parameters that have been available in NEMO version
+  4.0 and earlier are available}. Constituents to be included in the tidal forcing
+(surface and lateral boundaries) are selected by enumerating their respective
+names in namelist array \np{sn_tide_cnames}{sn\_tide\_cnames}.\par
+
+\subsection{Surface tidal forcing}
+Surface tidal forcing can be represented in the model through an additional
+barotropic force in the momentum equation (\autoref{eq:MB_PE_dyn}) such that:
 \[
-  % \label{eq:SBC_PE_dyn_tides}
-  \frac{\partial {\mathrm {\mathbf U}}_h }{\partial t}= ...
-  +g\nabla (\Pi_{eq} + \Pi_{sal})
+  \frac{\partial {\mathrm {\mathbf U}}_h }{\partial t} = \ldots +g\nabla (\gamma
+  \Pi_{eq} + \Pi_{sal})
 \]
-where $\Pi_{eq}$ stands for the equilibrium tidal forcing and
-$\Pi_{sal}$ is a self-attraction and loading term (SAL).
-
-The equilibrium tidal forcing is expressed as a sum over a subset of
-constituents chosen from the set of available tidal constituents
-defined in file \hf{SBC/tide} (this comprises the tidal
-constituents \textit{M2, N2, 2N2, S2, K2, K1, O1, Q1, P1, M4, Mf, Mm,
-  Msqm, Mtm, S1, MU2, NU2, L2}, and \textit{T2}). Individual
-constituents are selected by including their names in the array
-\np{clname}{clname} in \nam{_tide}{\_tide} (e.g., \np{clname}{clname}\forcode{(1)='M2', }
-\np{clname}{clname}\forcode{(2)='S2'} to select solely the tidal consituents \textit{M2}
-and \textit{S2}). Optionally, when \np{ln_tide_ramp}{ln\_tide\_ramp} is set to
-\forcode{.true.}, the equilibrium tidal forcing can be ramped up
-linearly from zero during the initial \np{rdttideramp}{rdttideramp} days of the
-model run.
+where $\gamma \Pi_{eq}$ stands for the equilibrium tidal forcing scaled by a spatially
+uniform tilt factor $\gamma$, and $\Pi_{sal}$ is an optional
+self-attraction and loading term (SAL). These additional terms are enabled when,
+in addition to \np[=.true.]{ln_tide}{ln\_tide}),
+\np[=.true.]{ln_tide_pot}{ln\_tide\_pot}.\par
+
+The equilibrium tidal forcing is expressed as a sum over the subset of
+constituents listed in \np{sn_tide_cnames}{sn\_tide\_cnames} of
+\nam{_tide} (e.g.,
+\begin{forlines}
+      sn_tide_cnames(1) = 'M2'
+      sn_tide_cnames(2) = 'K1'
+      sn_tide_cnames(3) = 'S2'
+      sn_tide_cnames(4) = 'O1'
+\end{forlines}
+to select the four tidal constituents of strongest equilibrium tidal
+potential). The tidal tilt factor $\gamma = 1 + k - h$ includes the
+Love numbers $k$ and $h$ \citep{love_prsla1909}; this factor is
+configurable using \np{rn_tide_gamma} (default value 0.7). Optionally,
+when \np[=.true.]{ln_tide_ramp}{ln\_tide\_ramp}, the equilibrium tidal
+forcing can be ramped up linearly from zero during the initial
+\np{rn_tide_ramp_dt}{rn\_tide\_ramp\_dt} days of the model run.\par
 
 The SAL term should in principle be computed online as it depends on
 the model tidal prediction itself (see \citet{arbic.garner.ea_DSR04} for a
-discussion about the practical implementation of this term).
-Nevertheless, the complex calculations involved would make this
-computationally too expensive. Here, two options are available:
-$\Pi_{sal}$ generated by an external model can be read in
-(\np[=.true.]{ln_read_load}{ln\_read\_load}), or a ``scalar approximation'' can be
-used (\np[=.true.]{ln_scal_load}{ln\_scal\_load}). In the latter case
+discussion about the practical implementation of this term). The complex
+calculations involved in such computations, however, are computationally very
+expensive. Here, two mutually exclusive simpler variants are available:
+amplitudes generated by an external model for oscillatory $\Pi_{sal}$
+contributions from each of the selected tidal constituents can be read in
+(\np[=.true.]{ln_read_load}{ln\_read\_load}) from the file specified in
+\np{cn_tide_load}{cn\_tide\_load} (the variable names are comprised of the
+tidal-constituent name and suffixes \forcode{_z1} and \forcode{_z2} for the two
+orthogonal components, respectively); alternatively, a ``scalar approximation''
+can be used (\np[=.true.]{ln_scal_load}{ln\_scal\_load}), where
 \[
   \Pi_{sal} = \beta \eta,
 \]
-where $\beta$ (\np{rn_scal_load}{rn\_scal\_load} with a default value of 0.094) is a
-spatially constant scalar, often chosen to minimize tidal prediction
-errors. Setting both \np{ln_read_load}{ln\_read\_load} and \np{ln_scal_load}{ln\_scal\_load} to
-\forcode{.false.} removes the SAL contribution.
+with a spatially uniform coefficient $\beta$, which can be configured
+via \np{rn_scal_load}{rn\_scal\_load} (default value 0.094) and is
+often tuned to minimize tidal prediction errors.\par
+
+For diagnostic purposes, the forcing potential of the individual tidal
+constituents (incl. load ptential, if activated) and the total forcing
+potential (incl. load potential, if activated) can be made available
+as diagnostic output by setting
+\np[=.true.]{ln_tide_dia}{ln\_tide\_dia} (fields
+\forcode{tide_pot_<constituent>} and \forcode{tide_pot}).\par
 
 %% =================================================================================================
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/namelists/nam_tide
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/namelists/nam_tide	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/namelists/nam_tide	(revision 14018)
@@ -3,12 +3,16 @@
 !-----------------------------------------------------------------------
    ln_tide     = .false.      ! Activate tides
-      ln_tide_pot   = .true.                !  use tidal potential forcing
+      nn_tide_var   = 1          !  Variant of tidal parameter set and tide-potential computation
+      !                          !     (1: default; 0: compatibility with previous versions)
+      ln_tide_dia   = .false.    !  Enable tidal diagnostic output
+      ln_tide_pot   = .false.               !  use tidal potential forcing
+         rn_tide_gamma = 0.7                   ! Tidal tilt factor
          ln_scal_load  = .false.               ! Use scalar approximation for
             rn_scal_load = 0.094               !     load potential
          ln_read_load  = .false.               ! Or read load potential from file
             cn_tide_load = 'tide_LOAD_grid_T.nc'  ! filename for load potential
-            !      
+            !
       ln_tide_ramp  = .false.               !  Use linear ramp for tides at startup
-         rdttideramp   =    0.                 !  ramp duration in days
-      clname(1)     = 'DUMMY'               !  name of constituent - all tidal components must be set in namelist_cfg
+         rn_tide_ramp_dt = 0.               !  ramp duration in days
+      sn_tide_cnames(1) = 'DUMMY'               !  name of constituent - all tidal components must be set in namelist_cfg
 /
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/namelists/nambdy_tide
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/namelists/nambdy_tide	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/doc/namelists/nambdy_tide	(revision 14018)
@@ -4,4 +4,3 @@
    filtide          = 'bdydta/amm12_bdytide_'   !  file name root of tidal forcing files
    ln_bdytide_2ddta = .false.                   !
-   ln_bdytide_conj  = .false.                   ! 
 /
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icedia.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icedia.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icedia.F90	(revision 14018)
@@ -261,9 +261,9 @@
          ! Write in numriw (if iter == nitrst)
          ! ------------------ 
-         CALL iom_rstput( iter, nitrst, numriw, 'frc_voltop' , frc_voltop  )
-         CALL iom_rstput( iter, nitrst, numriw, 'frc_volbot' , frc_volbot  )
-         CALL iom_rstput( iter, nitrst, numriw, 'frc_temtop' , frc_temtop  )
-         CALL iom_rstput( iter, nitrst, numriw, 'frc_tembot' , frc_tembot  )
-         CALL iom_rstput( iter, nitrst, numriw, 'frc_sal'    , frc_sal     )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_voltop' , frc_voltop )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_volbot' , frc_volbot )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_temtop' , frc_temtop )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_tembot' , frc_tembot )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_sal'    , frc_sal    )
          CALL iom_rstput( iter, nitrst, numriw, 'vol_loc_ini', vol_loc_ini )
          CALL iom_rstput( iter, nitrst, numriw, 'tem_loc_ini', tem_loc_ini )
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icedyn_adv_pra.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icedyn_adv_pra.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icedyn_adv_pra.F90	(revision 14018)
@@ -989,18 +989,28 @@
             DO jk = 1, nlay_s
                WRITE(zchar1,'(I2.2)') jk
-               znam = 'sxc0'//'_l'//zchar1  ;   CALL iom_get( numrir, jpdom_auto, znam , z3d, psgn = -1._wp )   ;   sxc0 (:,:,jk,:) = z3d(:,:,:)
-               znam = 'syc0'//'_l'//zchar1  ;   CALL iom_get( numrir, jpdom_auto, znam , z3d, psgn = -1._wp )   ;   syc0 (:,:,jk,:) = z3d(:,:,:)
-               znam = 'sxxc0'//'_l'//zchar1 ;   CALL iom_get( numrir, jpdom_auto, znam , z3d )   ;   sxxc0(:,:,jk,:) = z3d(:,:,:)
-               znam = 'syyc0'//'_l'//zchar1 ;   CALL iom_get( numrir, jpdom_auto, znam , z3d )   ;   syyc0(:,:,jk,:) = z3d(:,:,:)
-               znam = 'sxyc0'//'_l'//zchar1 ;   CALL iom_get( numrir, jpdom_auto, znam , z3d )   ;   sxyc0(:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxc0'//'_l'//zchar1  
+               CALL iom_get( numrir, jpdom_auto, znam , z3d, psgn = -1._wp )   ;   sxc0 (:,:,jk,:) = z3d(:,:,:)
+               znam = 'syc0'//'_l'//zchar1  
+               CALL iom_get( numrir, jpdom_auto, znam , z3d, psgn = -1._wp )   ;   syc0 (:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxxc0'//'_l'//zchar1 
+               CALL iom_get( numrir, jpdom_auto, znam , z3d )   ;   sxxc0(:,:,jk,:) = z3d(:,:,:)
+               znam = 'syyc0'//'_l'//zchar1 
+               CALL iom_get( numrir, jpdom_auto, znam , z3d )   ;   syyc0(:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxyc0'//'_l'//zchar1 
+               CALL iom_get( numrir, jpdom_auto, 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_auto, znam , z3d, psgn = -1._wp )   ;   sxe (:,:,jk,:) = z3d(:,:,:)
-               znam = 'sye'//'_l'//zchar1   ;   CALL iom_get( numrir, jpdom_auto, znam , z3d, psgn = -1._wp )   ;   sye (:,:,jk,:) = z3d(:,:,:)
-               znam = 'sxxe'//'_l'//zchar1  ;   CALL iom_get( numrir, jpdom_auto, znam , z3d )   ;   sxxe(:,:,jk,:) = z3d(:,:,:)
-               znam = 'syye'//'_l'//zchar1  ;   CALL iom_get( numrir, jpdom_auto, znam , z3d )   ;   syye(:,:,jk,:) = z3d(:,:,:)
-               znam = 'sxye'//'_l'//zchar1  ;   CALL iom_get( numrir, jpdom_auto, znam , z3d )   ;   sxye(:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxe'//'_l'//zchar1   
+               CALL iom_get( numrir, jpdom_auto, znam , z3d, psgn = -1._wp )   ;   sxe (:,:,jk,:) = z3d(:,:,:)
+               znam = 'sye'//'_l'//zchar1   
+               CALL iom_get( numrir, jpdom_auto, znam , z3d, psgn = -1._wp )   ;   sye (:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxxe'//'_l'//zchar1  
+               CALL iom_get( numrir, jpdom_auto, znam , z3d )   ;   sxxe(:,:,jk,:) = z3d(:,:,:)
+               znam = 'syye'//'_l'//zchar1  
+               CALL iom_get( numrir, jpdom_auto, znam , z3d )   ;   syye(:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxye'//'_l'//zchar1  
+               CALL iom_get( numrir, jpdom_auto, znam , z3d )   ;   sxye(:,:,jk,:) = z3d(:,:,:)
             END DO
             !
@@ -1067,50 +1077,60 @@
          !
          !                                                           ! ice thickness
-         CALL iom_rstput( iter, nitrst, numriw, 'sxice' , sxice  )
-         CALL iom_rstput( iter, nitrst, numriw, 'syice' , syice  )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxxice', sxxice )
-         CALL iom_rstput( iter, nitrst, numriw, 'syyice', syyice )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxyice', sxyice )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxice' , sxice)
+         CALL iom_rstput( iter, nitrst, numriw, 'syice' , syice)
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxice', sxxice)
+         CALL iom_rstput( iter, nitrst, numriw, 'syyice', syyice)
+         CALL iom_rstput( iter, nitrst, numriw, 'sxyice', sxyice)
          !                                                           ! snow thickness
-         CALL iom_rstput( iter, nitrst, numriw, 'sxsn'  , sxsn   )
-         CALL iom_rstput( iter, nitrst, numriw, 'sysn'  , sysn   )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxxsn' , sxxsn  )
-         CALL iom_rstput( iter, nitrst, numriw, 'syysn' , syysn  )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxysn' , sxysn  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxsn'  , sxsn )
+         CALL iom_rstput( iter, nitrst, numriw, 'sysn'  , sysn )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxsn' , sxxsn )
+         CALL iom_rstput( iter, nitrst, numriw, 'syysn' , syysn )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxysn' , sxysn )
          !                                                           ! ice concentration
-         CALL iom_rstput( iter, nitrst, numriw, 'sxa'   , sxa    )
-         CALL iom_rstput( iter, nitrst, numriw, 'sya'   , sya    )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxxa'  , sxxa   )
-         CALL iom_rstput( iter, nitrst, numriw, 'syya'  , syya   )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxya'  , sxya   )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxa'   , sxa  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sya'   , sya  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxa'  , sxxa  )
+         CALL iom_rstput( iter, nitrst, numriw, 'syya'  , syya  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxya'  , sxya  )
          !                                                           ! ice salinity
-         CALL iom_rstput( iter, nitrst, numriw, 'sxsal' , sxsal  )
-         CALL iom_rstput( iter, nitrst, numriw, 'sysal' , sysal  )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxxsal', sxxsal )
-         CALL iom_rstput( iter, nitrst, numriw, 'syysal', syysal )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxysal', sxysal )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxsal' , sxsal)
+         CALL iom_rstput( iter, nitrst, numriw, 'sysal' , sysal)
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxsal', sxxsal)
+         CALL iom_rstput( iter, nitrst, numriw, 'syysal', syysal)
+         CALL iom_rstput( iter, nitrst, numriw, 'sxysal', sxysal)
          !                                                           ! ice age
-         CALL iom_rstput( iter, nitrst, numriw, 'sxage' , sxage  )
-         CALL iom_rstput( iter, nitrst, numriw, 'syage' , syage  )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxxage', sxxage )
-         CALL iom_rstput( iter, nitrst, numriw, 'syyage', syyage )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxyage', sxyage )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxage' , sxage)
+         CALL iom_rstput( iter, nitrst, numriw, 'syage' , syage)
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxage', sxxage)
+         CALL iom_rstput( iter, nitrst, numriw, 'syyage', syyage)
+         CALL iom_rstput( iter, nitrst, numriw, 'sxyage', sxyage)
          !                                                           ! snow layers heat content
          DO jk = 1, nlay_s
             WRITE(zchar1,'(I2.2)') jk
-            znam = 'sxc0'//'_l'//zchar1  ;   z3d(:,:,:) = sxc0 (:,:,jk,:)  ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'syc0'//'_l'//zchar1  ;   z3d(:,:,:) = syc0 (:,:,jk,:)  ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'sxxc0'//'_l'//zchar1 ;   z3d(:,:,:) = sxxc0(:,:,jk,:)  ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'syyc0'//'_l'//zchar1 ;   z3d(:,:,:) = syyc0(:,:,jk,:)  ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'sxyc0'//'_l'//zchar1 ;   z3d(:,:,:) = sxyc0(:,:,jk,:)  ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+            znam = 'sxc0'//'_l'//zchar1  ;   z3d(:,:,:) = sxc0 (:,:,jk,:)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d)
+            znam = 'syc0'//'_l'//zchar1  ;   z3d(:,:,:) = syc0 (:,:,jk,:)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d)
+            znam = 'sxxc0'//'_l'//zchar1 ;   z3d(:,:,:) = sxxc0(:,:,jk,:)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d)
+            znam = 'syyc0'//'_l'//zchar1 ;   z3d(:,:,:) = syyc0(:,:,jk,:)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d)
+            znam = 'sxyc0'//'_l'//zchar1 ;   z3d(:,:,:) = sxyc0(:,:,jk,:)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d)
          END DO
          !                                                           ! ice layers heat content
          DO jk = 1, nlay_i
             WRITE(zchar1,'(I2.2)') jk
-            znam = 'sxe'//'_l'//zchar1   ;   z3d(:,:,:) = sxe (:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'sye'//'_l'//zchar1   ;   z3d(:,:,:) = sye (:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'sxxe'//'_l'//zchar1  ;   z3d(:,:,:) = sxxe(:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'syye'//'_l'//zchar1  ;   z3d(:,:,:) = syye(:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
-            znam = 'sxye'//'_l'//zchar1  ;   z3d(:,:,:) = sxye(:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+            znam = 'sxe'//'_l'//zchar1   ;   z3d(:,:,:) = sxe (:,:,jk,:)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d)
+            znam = 'sye'//'_l'//zchar1   ;   z3d(:,:,:) = sye (:,:,jk,:)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d)
+            znam = 'sxxe'//'_l'//zchar1  ;   z3d(:,:,:) = sxxe(:,:,jk,:)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d)
+            znam = 'syye'//'_l'//zchar1  ;   z3d(:,:,:) = syye(:,:,jk,:)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d)
+            znam = 'sxye'//'_l'//zchar1  ;   z3d(:,:,:) = sxye(:,:,jk,:)
+            CALL iom_rstput( iter, nitrst, numriw, znam , z3d)
          END DO
          !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icedyn_rhg_evp.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icedyn_rhg_evp.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icedyn_rhg_evp.F90	(revision 14018)
@@ -1033,6 +1033,6 @@
          iter = kt + nn_fsbc - 1             ! ice restarts are written at kt == nitrst - nn_fsbc + 1
          !
-         CALL iom_rstput( iter, nitrst, numriw, 'stress1_i' , stress1_i  )
-         CALL iom_rstput( iter, nitrst, numriw, 'stress2_i' , stress2_i  )
+         CALL iom_rstput( iter, nitrst, numriw, 'stress1_i' , stress1_i )
+         CALL iom_rstput( iter, nitrst, numriw, 'stress2_i' , stress2_i )
          CALL iom_rstput( iter, nitrst, numriw, 'stress12_i', stress12_i )
          !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icerst.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icerst.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icerst.F90	(revision 14018)
@@ -55,4 +55,5 @@
       CHARACTER(len=50)   ::   clname   ! ice output restart file name
       CHARACTER(len=256)  ::   clpath   ! full path to ice output restart file 
+      CHARACTER(LEN=52)   ::   clpname   ! ocean output restart file name including prefix for AGRIF
       !!----------------------------------------------------------------------
       !
@@ -84,5 +85,22 @@
             ENDIF
             !
-            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl, cdcomp = 'ICE' )
+            IF(.NOT.lwxios) THEN
+               CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl, cdcomp = 'ICE' )
+            ELSE
+#if defined key_iomput
+               cw_icerst_cxt = "rstwi_"//TRIM(ADJUSTL(clkt))
+               IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+                  clpname = clname
+               ELSE
+                  clpname = TRIM(Agrif_CFixed())//"_"//clname
+               ENDIF
+               numriw = iom_xios_setid(TRIM(clpath)//TRIM(clpname))
+               CALL iom_init( cw_icerst_cxt, kdid = numriw, ld_closedef = .FALSE. )
+               CALL iom_swap( cxios_context )
+#else
+               clinfo = 'Can not use XIOS in rst_opn'
+               CALL ctl_stop(TRIM(clinfo))
+#endif
+            ENDIF
             lrst_ice = .TRUE.
          ENDIF
@@ -117,5 +135,5 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'         
       ENDIF
-
+      
       ! Write in numriw (if iter == nitrst)
       ! ------------------ 
@@ -123,5 +141,6 @@
       CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) )      ! time-step 
       CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ) )      ! date
-      CALL iom_delay_rst( 'WRITE', 'ICE', numriw )   ! save only ice delayed global communication variables
+      
+      IF(.NOT.lwxios) CALL iom_delay_rst( 'WRITE', 'ICE', numriw )   ! save only ice delayed global communication variables
 
       ! Prognostic variables
@@ -154,5 +173,5 @@
       IF( ln_cpl ) THEN
          CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice )
-         CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice  )
+         CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice )
       ENDIF
       !
@@ -161,5 +180,11 @@
       ! ------------------
       IF( iter == nitrst ) THEN
-         CALL iom_close( numriw )
+         IF(.NOT.lwxios) THEN
+            CALL iom_close( numriw )
+         ELSE
+            CALL iom_context_finalize(      cw_icerst_cxt          )
+            iom_file(numriw)%nfid       = 0
+            numriw = 0
+         ENDIF
          lrst_ice = .FALSE.
       ENDIF
@@ -181,4 +206,5 @@
       CHARACTER(len=2)  ::   zchar, zchar1
       REAL(wp)          ::   zfice, ziter
+      CHARACTER(lc)     ::   clpname
       REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
       !!----------------------------------------------------------------------
@@ -190,5 +216,17 @@
       ENDIF
 
+      lxios_sini = .FALSE.
       CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir )
+
+      IF( lrxios) THEN
+          cr_icerst_cxt = 'si3_rst'
+          IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for SI3'
+!         IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+!            clpname = cn_icerst_in
+!         ELSE
+!            clpname = TRIM(Agrif_CFixed())//"_"//cn_icerst_in   
+!         ENDIF
+          CALL iom_init( cr_icerst_cxt, kdid = numrir, ld_closedef = .TRUE. )
+      ENDIF
 
       ! test if v_i exists 
@@ -198,5 +236,4 @@
       IF( id0 > 0 ) THEN   ! == case of a normal restart == !
          !                 ! ------------------------------ !
-         
          ! Time info
          CALL iom_get( numrir, 'nn_fsbc', zfice )
@@ -278,6 +315,5 @@
          ENDIF
 
-         CALL iom_delay_rst( 'READ', 'ICE', numrir )   ! read only ice delayed global communication variables
-
+         IF(.NOT.lrxios) CALL iom_delay_rst( 'READ', 'ICE', numrir )   ! read only ice delayed global communication variables
          !                 ! ---------------------------------- !
       ELSE                 ! == case of a simplified restart == !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icestp.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icestp.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/ICE/icestp.F90	(revision 14018)
@@ -291,5 +291,8 @@
       tn_ice(:,:,:) = t_su(:,:,:)      ! initialisation of surface temp for coupled simu
       !
-      IF( ln_rstart )   CALL iom_close( numrir )  ! close input ice restart file
+      IF( ln_rstart )  THEN
+         CALL iom_close( numrir )  ! close input ice restart file
+         IF(lrxios) CALL iom_context_finalize(      cr_icerst_cxt         )
+      ENDIF
       !
    END SUBROUTINE ice_init
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/C1D/step_c1d.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/C1D/step_c1d.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/C1D/step_c1d.F90	(revision 14018)
@@ -122,4 +122,7 @@
                         CALL dyn_atf    ( kstp, Nbb, Nnn, Naa , uu, vv, e3t, e3u, e3v )  ! time filtering of "now" fields
       IF(.NOT.ln_linssh)CALL ssh_atf    ( kstp, Nbb, Nnn, Naa , ssh )                    ! time filtering of "now" sea surface height
+      IF( kstp == nit000 .AND. ln_linssh) THEN
+         ssh(:,:,Naa) = ssh(:,:,Nnn)  ! init ssh after in ln_linssh case
+      ENDIF
       !
       ! Swap time levels
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DIA/diahsb.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DIA/diahsb.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DIA/diahsb.F90	(revision 14018)
@@ -267,20 +267,20 @@
             IF(lwp) WRITE(numout,*) '   dia_hsb_rst : read hsb restart at it= ', kt,' date= ', ndastp
             IF(lwp) WRITE(numout,*)
-            CALL iom_get( numror, 'frc_v', frc_v, ldxios = lrxios )
-            CALL iom_get( numror, 'frc_t', frc_t, ldxios = lrxios )
-            CALL iom_get( numror, 'frc_s', frc_s, ldxios = lrxios )
+            CALL iom_get( numror, 'frc_v', frc_v )
+            CALL iom_get( numror, 'frc_t', frc_t )
+            CALL iom_get( numror, 'frc_s', frc_s )
             IF( ln_linssh ) THEN
-               CALL iom_get( numror, 'frc_wn_t', frc_wn_t, ldxios = lrxios )
-               CALL iom_get( numror, 'frc_wn_s', frc_wn_s, ldxios = lrxios )
+               CALL iom_get( numror, 'frc_wn_t', frc_wn_t )
+               CALL iom_get( numror, 'frc_wn_s', frc_wn_s )
             ENDIF
-            CALL iom_get( numror, jpdom_auto, 'surf_ini'  , surf_ini  , ldxios = lrxios ) ! ice sheet coupling
-            CALL iom_get( numror, jpdom_auto, 'ssh_ini'   , ssh_ini   , ldxios = lrxios )
-            CALL iom_get( numror, jpdom_auto, 'e3t_ini'   , e3t_ini   , ldxios = lrxios )
-            CALL iom_get( numror, jpdom_auto, 'tmask_ini' , tmask_ini , ldxios = lrxios )
-            CALL iom_get( numror, jpdom_auto, 'hc_loc_ini', hc_loc_ini, ldxios = lrxios )
-            CALL iom_get( numror, jpdom_auto, 'sc_loc_ini', sc_loc_ini, ldxios = lrxios )
+            CALL iom_get( numror, jpdom_auto, 'surf_ini'  , surf_ini   ) ! ice sheet coupling
+            CALL iom_get( numror, jpdom_auto, 'ssh_ini'   , ssh_ini    )
+            CALL iom_get( numror, jpdom_auto, 'e3t_ini'   , e3t_ini    )
+            CALL iom_get( numror, jpdom_auto, 'tmask_ini' , tmask_ini  )
+            CALL iom_get( numror, jpdom_auto, 'hc_loc_ini', hc_loc_ini )
+            CALL iom_get( numror, jpdom_auto, 'sc_loc_ini', sc_loc_ini )
             IF( ln_linssh ) THEN
-               CALL iom_get( numror, jpdom_auto, 'ssh_hc_loc_ini', ssh_hc_loc_ini, ldxios = lrxios )
-               CALL iom_get( numror, jpdom_auto, 'ssh_sc_loc_ini', ssh_sc_loc_ini, ldxios = lrxios )
+               CALL iom_get( numror, jpdom_auto, 'ssh_hc_loc_ini', ssh_hc_loc_ini )
+               CALL iom_get( numror, jpdom_auto, 'ssh_sc_loc_ini', ssh_sc_loc_ini )
             ENDIF
          ELSE
@@ -323,23 +323,21 @@
          IF(lwp) WRITE(numout,*)
          !
-         IF( lwxios ) CALL iom_swap(      cwxios_context          )
-         CALL iom_rstput( kt, nitrst, numrow, 'frc_v', frc_v, ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'frc_t', frc_t, ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'frc_s', frc_s, ldxios = lwxios )
+         CALL iom_rstput( kt, nitrst, numrow, 'frc_v', frc_v )
+         CALL iom_rstput( kt, nitrst, numrow, 'frc_t', frc_t )
+         CALL iom_rstput( kt, nitrst, numrow, 'frc_s', frc_s )
          IF( ln_linssh ) THEN
-            CALL iom_rstput( kt, nitrst, numrow, 'frc_wn_t', frc_wn_t, ldxios = lwxios )
-            CALL iom_rstput( kt, nitrst, numrow, 'frc_wn_s', frc_wn_s, ldxios = lwxios )
+            CALL iom_rstput( kt, nitrst, numrow, 'frc_wn_t', frc_wn_t )
+            CALL iom_rstput( kt, nitrst, numrow, 'frc_wn_s', frc_wn_s )
          ENDIF
-         CALL iom_rstput( kt, nitrst, numrow, 'surf_ini'  , surf_ini  , ldxios = lwxios )      ! ice sheet coupling
-         CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini'   , ssh_ini   , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini'   , e3t_ini   , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'tmask_ini' , tmask_ini , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini, ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini, ldxios = lwxios )
+         CALL iom_rstput( kt, nitrst, numrow, 'surf_ini'  , surf_ini   )      ! ice sheet coupling
+         CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini'   , ssh_ini    )
+         CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini'   , e3t_ini    )
+         CALL iom_rstput( kt, nitrst, numrow, 'tmask_ini' , tmask_ini  )
+         CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini )
+         CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini )
          IF( ln_linssh ) THEN
-            CALL iom_rstput( kt, nitrst, numrow, 'ssh_hc_loc_ini', ssh_hc_loc_ini, ldxios = lwxios )
-            CALL iom_rstput( kt, nitrst, numrow, 'ssh_sc_loc_ini', ssh_sc_loc_ini, ldxios = lwxios )
+            CALL iom_rstput( kt, nitrst, numrow, 'ssh_hc_loc_ini', ssh_hc_loc_ini )
+            CALL iom_rstput( kt, nitrst, numrow, 'ssh_sc_loc_ini', ssh_sc_loc_ini )
          ENDIF
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
          !
       ENDIF
@@ -385,21 +383,4 @@
       IF( .NOT. ln_diahsb )   RETURN
 
-      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')
-        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')
-        ENDIF
-      ENDIF
       ! ------------------- !
       ! 1 - Allocate memory !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/daymod.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/daymod.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/daymod.F90	(revision 14018)
@@ -149,12 +149,4 @@
       CALL day( nit000 )
       !
-      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')
-      ENDIF
-
    END SUBROUTINE day_init
 
@@ -324,8 +316,7 @@
 
       IF( TRIM(cdrw) == 'READ' ) THEN
-
          IF( iom_varid( numror, 'kt', ldstop = .FALSE. ) > 0 ) THEN
             ! Get Calendar informations
-            CALL iom_get( numror, 'kt', zkt, ldxios = lrxios )   ! last time-step of previous run
+            CALL iom_get( numror, 'kt', zkt )   ! last time-step of previous run
             IF(lwp) THEN
                WRITE(numout,*) ' *** Info read in restart : '
@@ -346,8 +337,8 @@
             IF ( nrstdt == 2 ) THEN
                ! read the parameters corresponding to nit000 - 1 (last time step of previous run)
-               CALL iom_get( numror, 'ndastp', zndastp, ldxios = lrxios )
+               CALL iom_get( numror, 'ndastp', zndastp )
                ndastp = NINT( zndastp )
-               CALL iom_get( numror, 'adatrj', adatrj , ldxios = lrxios )
-	       CALL iom_get( numror, 'ntime' , ktime  , ldxios = lrxios )
+               CALL iom_get( numror, 'adatrj', adatrj  )
+	       CALL iom_get( numror, 'ntime' , ktime   )
                nn_time0 = NINT(ktime)
                ! calculate start time in hours and minutes
@@ -410,11 +401,9 @@
          ENDIF
          ! calendar control
-         IF( lwxios ) CALL iom_swap(      cwxios_context          )
-         CALL iom_rstput( kt, nitrst, numrow, 'kt'     , REAL( kt    , wp)  , ldxios = lwxios )   ! time-step
-         CALL iom_rstput( kt, nitrst, numrow, 'ndastp' , REAL( ndastp, wp)  , ldxios = lwxios )   ! date
-         CALL iom_rstput( kt, nitrst, numrow, 'adatrj' , adatrj             , ldxios = lwxios            )   ! number of elapsed days since
+         CALL iom_rstput( kt, nitrst, numrow, 'kt'     , REAL( kt    , wp)   )   ! time-step
+         CALL iom_rstput( kt, nitrst, numrow, 'ndastp' , REAL( ndastp, wp)   )   ! date
+         CALL iom_rstput( kt, nitrst, numrow, 'adatrj' , adatrj              )   ! number of elapsed days since
          !                                                                                                   ! the begining of the run [s]
-         CALL iom_rstput( kt, nitrst, numrow, 'ntime'  , REAL( nn_time0, wp), ldxios = lwxios ) ! time
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
+         CALL iom_rstput( kt, nitrst, numrow, 'ntime'  , REAL( nn_time0, wp) ) ! time
       ENDIF
       !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/domain.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/domain.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/domain.F90	(revision 14018)
@@ -67,5 +67,5 @@
 CONTAINS
 
-   SUBROUTINE dom_init( Kbb, Kmm, Kaa, cdstr )
+   SUBROUTINE dom_init( Kbb, Kmm, Kaa )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE dom_init  ***
@@ -83,5 +83,4 @@
       !!----------------------------------------------------------------------
       INTEGER          , INTENT(in) :: Kbb, Kmm, Kaa          ! ocean time level indices
-      CHARACTER (len=*), INTENT(in) :: cdstr                  ! model: NEMO or SAS. Determines core restart variables
       !
       INTEGER ::   ji, jj, jk, jt   ! dummy loop indices
@@ -129,6 +128,6 @@
       !           !==  Reference coordinate system  ==!
       !
-      CALL dom_glo                     ! global domain versus local domain
-      CALL dom_nam( cdstr )                     ! read namelist ( namrun, namdom )
+      CALL dom_glo                      ! global domain versus local domain
+      CALL dom_nam                      ! read namelist ( namrun, namdom )
       !
       CALL dom_hgr                      ! Horizontal mesh
@@ -175,6 +174,8 @@
       !
       !                                 != ssh initialization
-      IF( cdstr /= 'SAS' ) THEN
+      IF( .NOT.l_offline .AND. .NOT.l_SAS ) THEN
          CALL ssh_init_rst( Kbb, Kmm, Kaa )
+      ELSE
+         ssh(:,:,:) = 0._wp
       ENDIF
       !
@@ -296,5 +297,5 @@
 
 
-   SUBROUTINE dom_nam( cdstr )
+   SUBROUTINE dom_nam
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE dom_nam  ***
@@ -308,6 +309,4 @@
       USE ioipsl
       !!
-      CHARACTER (len=*), INTENT(in) ::   cdstr   ! model: NEMO or SAS. Determines core restart variables
-      !
       INTEGER ::   ios   ! Local integer
       REAL(wp)::   zrdt
@@ -360,4 +359,9 @@
       rDt   = 2._wp * rn_Dt
       r1_Dt = 1._wp / rDt
+      !
+      IF( l_SAS .AND. .NOT.ln_linssh ) THEN
+         CALL ctl_warn( 'SAS requires linear ssh : force ln_linssh = T' )
+         ln_linssh = .TRUE.
+      ENDIF
       !
 #if defined key_qco
@@ -429,5 +433,4 @@
       !
       !                                        !==  Set parameters for restart reading using xIOS  ==!
-      lwxios = .FALSE.
       !
       IF( TRIM(Agrif_CFixed()) == '0' ) THEN
@@ -436,17 +439,4 @@
          nxioso = nn_wxios
       ENDIF
-      !
-      IF( lwxios ) THEN                                 !*  define names for restart write and set core output (restart.F90)
-         CALL iom_set_rst_vars ( rst_wfields )
-         CALL iom_set_rstw_core( cdstr )
-      ENDIF
-      !
-      IF( cdstr == 'SAS' ) THEN                         !*  reset namelist for SAS
-         IF( lrxios ) THEN
-            IF(lwp) WRITE(numout,*) 'Disable reading restart file using XIOS for SAS'
-            lrxios = .FALSE.
-         ENDIF
-      ENDIF
-      !
       !                                        !==  Check consistency between ln_rstart and ln_1st_euler  ==!   (i.e. set l_1st_euler)
       l_1st_euler = ln_1st_euler
@@ -459,5 +449,5 @@
          !
          IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 ) THEN     !- Check time-step consistency and force Euler restart if changed
-            CALL iom_get( numror, 'rdt', zrdt, ldxios = lrxios )
+            CALL iom_get( numror, 'rdt', zrdt )
             IF( zrdt /= rn_Dt ) THEN
                IF(lwp) WRITE( numout,*)
@@ -469,6 +459,6 @@
          ENDIF
          !
-         IF( iom_varid( numror, 'sshb', ldstop = .FALSE. ) <= 0 ) THEN   !- Check absence of one of the Kbb field (here sshb)
-            !                                                            !  (any Kbb field is missing ==> all Kbb fields are missing) 
+         IF( .NOT.l_SAS .AND. iom_varid( numror, 'sshb', ldstop = .FALSE. ) <= 0 ) THEN   !- Check absence of one of the Kbb field (here sshb)
+            !                                                                             !  (any Kbb field is missing ==> all Kbb fields are missing) 
             IF( .NOT.l_1st_euler ) THEN
                CALL ctl_warn('dom_nam : ssh at Kbb not found in restart files ',   &
@@ -484,5 +474,4 @@
          l_1st_euler = .TRUE.
       ENDIF
-      
       !
       !                                        !==  control of output frequency  ==!
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/domqco.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/domqco.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/domqco.F90	(revision 14018)
@@ -95,9 +95,4 @@
       r3v(:,:,Kaa) = r3v(:,:,Kmm)
 #endif
-      !
-      IF(lwxios) THEN   ! define variables in restart file when writing with XIOS
-         CALL iom_set_rstw_var_active('sshb')
-         CALL iom_set_rstw_var_active('sshn')
-      ENDIF
       !
    END SUBROUTINE dom_qco_init
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/domvvl.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/domvvl.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/domvvl.F90	(revision 14018)
@@ -282,22 +282,4 @@
       ENDIF
       !
-      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')
-         !                                           ! ----------------------- !
-         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')
-         END IF
-         !                                           ! -------------!    
-         IF( ln_vvl_ztilde ) THEN                    ! z_tilde case !
-            !                                        ! ------------ !
-            CALL iom_set_rstw_var_active('hdiv_lf')
-         ENDIF
-         !
-      ENDIF
-      !
    END SUBROUTINE dom_vvl_zgr
 
@@ -825,5 +807,5 @@
             !                                                           !*  scale factors
             IF(lwp) WRITE(numout,*)    '          Kmm scale factor read in the restart file'
-            CALL iom_get( numror, jpdom_auto, 'e3t_n', e3t(:,:,:,Kmm), ldxios = lrxios )
+            CALL iom_get( numror, jpdom_auto, 'e3t_n', e3t(:,:,:,Kmm) )
             WHERE ( tmask(:,:,:) == 0.0_wp ) 
                e3t(:,:,:,Kmm) = e3t_0(:,:,:)
@@ -834,5 +816,5 @@
             ELSE                                         ! leap frog
                IF(lwp) WRITE(numout,*) '          Kbb scale factor read in the restart file'
-               CALL iom_get( numror, jpdom_auto, 'e3t_b', e3t(:,:,:,Kbb), ldxios = lrxios )
+               CALL iom_get( numror, jpdom_auto, 'e3t_b', e3t(:,:,:,Kbb) )
                WHERE ( tmask(:,:,:) == 0.0_wp ) 
                   e3t(:,:,:,Kbb) = e3t_0(:,:,:)
@@ -851,5 +833,5 @@
                IF( id4 > 0 ) THEN                                       !*  scale factor increments
                   IF(lwp) WRITE(numout,*)    '          Kmm scale factor increments read in the restart file'
-                  CALL iom_get( numror, jpdom_auto, 'tilde_e3t_n', tilde_e3t_n(:,:,:), ldxios = lrxios )
+                  CALL iom_get( numror, jpdom_auto, 'tilde_e3t_n', tilde_e3t_n(:,:,:) )
                   IF( l_1st_euler ) THEN                 ! euler
                      IF(lwp) WRITE(numout,*) '          Euler first time step : tilde_e3t(Kbb) = tilde_e3t(Kmm)'
@@ -857,5 +839,5 @@
                   ELSE                                   ! leap frog
                      IF(lwp) WRITE(numout,*) '          Kbb scale factor increments read in the restart file'
-                     CALL iom_get( numror, jpdom_auto, 'tilde_e3t_b', tilde_e3t_b(:,:,:), ldxios = lrxios )
+                     CALL iom_get( numror, jpdom_auto, 'tilde_e3t_b', tilde_e3t_b(:,:,:) )
                   ENDIF
                ELSE 
@@ -867,5 +849,5 @@
                   !                                   ! ------------ !
                   IF( id5 > 0 ) THEN  ! required array exists
-                     CALL iom_get( numror, jpdom_auto, 'hdiv_lf', hdiv_lf(:,:,:), ldxios = lrxios )
+                     CALL iom_get( numror, jpdom_auto, 'hdiv_lf', hdiv_lf(:,:,:) )
                   ELSE                ! array is missing
                      hdiv_lf(:,:,:) = 0.0_wp 
@@ -892,23 +874,21 @@
          !
          IF(lwp) WRITE(numout,*) '---- dom_vvl_rst ----'
-         IF( lwxios ) CALL iom_swap(      cwxios_context          )
          !                                           ! --------- !
          !                                           ! all cases !
          !                                           ! --------- !
-         CALL iom_rstput( kt, nitrst, numrow, 'e3t_b', e3t(:,:,:,Kbb), ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'e3t_n', e3t(:,:,:,Kmm), ldxios = lwxios )
+         CALL iom_rstput( kt, nitrst, numrow, 'e3t_b', e3t(:,:,:,Kbb) )
+         CALL iom_rstput( kt, nitrst, numrow, 'e3t_n', e3t(:,:,:,Kmm) )
          !                                           ! ----------------------- !
          IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN  ! z_tilde and layer cases !
             !                                        ! ----------------------- !
-            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_b', tilde_e3t_b(:,:,:), ldxios = lwxios)
-            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_n', tilde_e3t_n(:,:,:), ldxios = lwxios)
+            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_b', tilde_e3t_b(:,:,:))
+            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_n', tilde_e3t_n(:,:,:))
          END IF
          !                                           ! -------------!    
          IF( ln_vvl_ztilde ) THEN                    ! z_tilde case !
             !                                        ! ------------ !
-            CALL iom_rstput( kt, nitrst, numrow, 'hdiv_lf', hdiv_lf(:,:,:), ldxios = lwxios)
+            CALL iom_rstput( kt, nitrst, numrow, 'hdiv_lf', hdiv_lf(:,:,:))
          ENDIF
          !
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
       ENDIF
       !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DYN/dynspg_ts.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DYN/dynspg_ts.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DYN/dynspg_ts.F90	(revision 14018)
@@ -933,21 +933,21 @@
          !                                   ! ---------------
          IF( ln_rstart .AND. ln_bt_fw .AND. .NOT.l_1st_euler ) THEN    !* Read the restart file
-            CALL iom_get( numror, jpdom_auto, 'ub2_b'  , ub2_b  (:,:), cd_type = 'U', psgn = -1._wp, ldxios = lrxios )   
-            CALL iom_get( numror, jpdom_auto, 'vb2_b'  , vb2_b  (:,:), cd_type = 'V', psgn = -1._wp, ldxios = lrxios ) 
-            CALL iom_get( numror, jpdom_auto, 'un_bf'  , un_bf  (:,:), cd_type = 'U', psgn = -1._wp, ldxios = lrxios )   
-            CALL iom_get( numror, jpdom_auto, 'vn_bf'  , vn_bf  (:,:), cd_type = 'V', psgn = -1._wp, ldxios = lrxios ) 
+            CALL iom_get( numror, jpdom_auto, 'ub2_b'  , ub2_b  (:,:), cd_type = 'U', psgn = -1._wp )   
+            CALL iom_get( numror, jpdom_auto, 'vb2_b'  , vb2_b  (:,:), cd_type = 'V', psgn = -1._wp ) 
+            CALL iom_get( numror, jpdom_auto, 'un_bf'  , un_bf  (:,:), cd_type = 'U', psgn = -1._wp )   
+            CALL iom_get( numror, jpdom_auto, 'vn_bf'  , vn_bf  (:,:), cd_type = 'V', psgn = -1._wp ) 
             IF( .NOT.ln_bt_av ) THEN
-               CALL iom_get( numror, jpdom_auto, 'sshbb_e'  , sshbb_e(:,:), cd_type = 'T', psgn =  1._wp, ldxios = lrxios )   
-               CALL iom_get( numror, jpdom_auto, 'ubb_e'    ,   ubb_e(:,:), cd_type = 'U', psgn = -1._wp, ldxios = lrxios )   
-               CALL iom_get( numror, jpdom_auto, 'vbb_e'    ,   vbb_e(:,:), cd_type = 'V', psgn = -1._wp, ldxios = lrxios )
-               CALL iom_get( numror, jpdom_auto, 'sshb_e'   ,  sshb_e(:,:), cd_type = 'T', psgn =  1._wp, ldxios = lrxios ) 
-               CALL iom_get( numror, jpdom_auto, 'ub_e'     ,    ub_e(:,:), cd_type = 'U', psgn = -1._wp, ldxios = lrxios )   
-               CALL iom_get( numror, jpdom_auto, 'vb_e'     ,    vb_e(:,:), cd_type = 'V', psgn = -1._wp, ldxios = lrxios )
+               CALL iom_get( numror, jpdom_auto, 'sshbb_e'  , sshbb_e(:,:), cd_type = 'T', psgn =  1._wp )   
+               CALL iom_get( numror, jpdom_auto, 'ubb_e'    ,   ubb_e(:,:), cd_type = 'U', psgn = -1._wp )   
+               CALL iom_get( numror, jpdom_auto, 'vbb_e'    ,   vbb_e(:,:), cd_type = 'V', psgn = -1._wp )
+               CALL iom_get( numror, jpdom_auto, 'sshb_e'   ,  sshb_e(:,:), cd_type = 'T', psgn =  1._wp ) 
+               CALL iom_get( numror, jpdom_auto, 'ub_e'     ,    ub_e(:,:), cd_type = 'U', psgn = -1._wp )   
+               CALL iom_get( numror, jpdom_auto, 'vb_e'     ,    vb_e(:,:), cd_type = 'V', psgn = -1._wp )
             ENDIF
 #if defined key_agrif
             ! Read time integrated fluxes
             IF ( .NOT.Agrif_Root() ) THEN
-               CALL iom_get( numror, jpdom_auto, 'ub2_i_b'  , ub2_i_b(:,:), cd_type = 'U', psgn = -1._wp, ldxios = lrxios )   
-               CALL iom_get( numror, jpdom_auto, 'vb2_i_b'  , vb2_i_b(:,:), cd_type = 'V', psgn = -1._wp, ldxios = lrxios )
+               CALL iom_get( numror, jpdom_auto, 'ub2_i_b'  , ub2_i_b(:,:), cd_type = 'U', psgn = -1._wp )   
+               CALL iom_get( numror, jpdom_auto, 'vb2_i_b'  , vb2_i_b(:,:), cd_type = 'V', psgn = -1._wp )
             ELSE
                ub2_i_b(:,:) = 0._wp   ;   vb2_i_b(:,:) = 0._wp   ! used in the 1st update of agrif
@@ -968,26 +968,24 @@
          !                                   ! -------------------
          IF(lwp) WRITE(numout,*) '---- ts_rst ----'
-         IF( lwxios ) CALL iom_swap(      cwxios_context          )
-         CALL iom_rstput( kt, nitrst, numrow, 'ub2_b'   , ub2_b  (:,:), ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'vb2_b'   , vb2_b  (:,:), ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'un_bf'   , un_bf  (:,:), ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'vn_bf'   , vn_bf  (:,:), ldxios = lwxios )
+         CALL iom_rstput( kt, nitrst, numrow, 'ub2_b'   , ub2_b  (:,:) )
+         CALL iom_rstput( kt, nitrst, numrow, 'vb2_b'   , vb2_b  (:,:) )
+         CALL iom_rstput( kt, nitrst, numrow, 'un_bf'   , un_bf  (:,:) )
+         CALL iom_rstput( kt, nitrst, numrow, 'vn_bf'   , vn_bf  (:,:) )
          !
          IF (.NOT.ln_bt_av) THEN
-            CALL iom_rstput( kt, nitrst, numrow, 'sshbb_e'  , sshbb_e(:,:), ldxios = lwxios ) 
-            CALL iom_rstput( kt, nitrst, numrow, 'ubb_e'    ,   ubb_e(:,:), ldxios = lwxios )
-            CALL iom_rstput( kt, nitrst, numrow, 'vbb_e'    ,   vbb_e(:,:), ldxios = lwxios )
-            CALL iom_rstput( kt, nitrst, numrow, 'sshb_e'   ,  sshb_e(:,:), ldxios = lwxios )
-            CALL iom_rstput( kt, nitrst, numrow, 'ub_e'     ,    ub_e(:,:), ldxios = lwxios )
-            CALL iom_rstput( kt, nitrst, numrow, 'vb_e'     ,    vb_e(:,:), ldxios = lwxios )
+            CALL iom_rstput( kt, nitrst, numrow, 'sshbb_e'  , sshbb_e(:,:) ) 
+            CALL iom_rstput( kt, nitrst, numrow, 'ubb_e'    ,   ubb_e(:,:) )
+            CALL iom_rstput( kt, nitrst, numrow, 'vbb_e'    ,   vbb_e(:,:) )
+            CALL iom_rstput( kt, nitrst, numrow, 'sshb_e'   ,  sshb_e(:,:) )
+            CALL iom_rstput( kt, nitrst, numrow, 'ub_e'     ,    ub_e(:,:) )
+            CALL iom_rstput( kt, nitrst, numrow, 'vb_e'     ,    vb_e(:,:) )
          ENDIF
 #if defined key_agrif
          ! Save time integrated fluxes
          IF ( .NOT.Agrif_Root() ) THEN
-            CALL iom_rstput( kt, nitrst, numrow, 'ub2_i_b'  , ub2_i_b(:,:), ldxios = lwxios )
-            CALL iom_rstput( kt, nitrst, numrow, 'vb2_i_b'  , vb2_i_b(:,:), ldxios = lwxios )
+            CALL iom_rstput( kt, nitrst, numrow, 'ub2_i_b'  , ub2_i_b(:,:) )
+            CALL iom_rstput( kt, nitrst, numrow, 'vb2_i_b'  , vb2_i_b(:,:) )
          ENDIF
 #endif
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
       ENDIF
       !
@@ -1081,28 +1079,4 @@
       !                             ! read restart when needed
       CALL ts_rst( nit000, 'READ' )
-      !
-      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')
-         !
-         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')
-         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')
-         ENDIF
-#endif
-      ENDIF
       !
    END SUBROUTINE dyn_spg_ts_init
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DYN/sshwzv.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DYN/sshwzv.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DYN/sshwzv.F90	(revision 14018)
@@ -473,5 +473,5 @@
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*)    '      Kmm sea surface height read in the restart file'
-         CALL iom_get( numror, jpdom_auto, 'sshn'   , ssh(:,:,Kmm), ldxios = lrxios )
+         CALL iom_get( numror, jpdom_auto, 'sshn'   , ssh(:,:,Kmm) )
          !
          IF( l_1st_euler ) THEN                !* Euler at first time-step
@@ -483,5 +483,5 @@
             IF(lwp) WRITE(numout,*)
             IF(lwp) WRITE(numout,*) '      Kbb sea surface height read in the restart file'
-            CALL iom_get( numror, jpdom_auto, 'sshb', ssh(:,:,Kbb), ldxios = lrxios )
+            CALL iom_get( numror, jpdom_auto, 'sshb', ssh(:,:,Kbb) )
          ENDIF
          !                         !============================!
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/in_out_manager.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/in_out_manager.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/in_out_manager.F90	(revision 14018)
@@ -89,9 +89,14 @@
    LOGICAL ::   lrst_abl              !: logical to control the abl restart write 
    INTEGER ::   numror = 0            !: logical unit for ocean restart (read). Init to 0 is needed for SAS (in daymod.F90)
-   INTEGER ::   numrir                !: logical unit for ice   restart (read)
-   INTEGER ::   numrar                !: logical unit for abl   restart (read)
-   INTEGER ::   numrow                !: logical unit for ocean restart (write)
-   INTEGER ::   numriw                !: logical unit for ice   restart (write)
-   INTEGER ::   numraw                !: logical unit for abl   restart (write)
+   INTEGER ::   numrir = 0            !: logical unit for ice   restart (read)
+   INTEGER ::   numrar = 0            !: logical unit for abl   restart (read)
+   INTEGER ::   numrow = 0            !: logical unit for ocean restart (write)
+   INTEGER ::   numriw = 0            !: logical unit for ice   restart (write)
+   INTEGER ::   numraw = 0            !: logical unit for abl   restart (write)
+   INTEGER ::   numrtr = 0            !: trc restart (read )
+   INTEGER ::   numrtw = 0            !: trc restart (write )
+   INTEGER ::   numrsr = 0            !: logical unit for sed restart (read)
+   INTEGER ::   numrsw = 0            !: logical unit for sed restart (write)
+
    INTEGER ::   nrst_lst              !: number of restart to output next
 
@@ -165,7 +170,16 @@
    LOGICAL       ::   lwp      = .FALSE.    !: boolean : true on the 1st processor only .OR. sn_cfctl%l_oceout=T
    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(LEN=lc) ::   cxios_context     !: context name used in xios
+   CHARACTER(LEN=lc) ::   cr_ocerst_cxt     !: context name used in xios to read OCE restart
+   CHARACTER(LEN=lc) ::   cw_ocerst_cxt     !: context name used in xios to write OCE restart file
+   CHARACTER(LEN=lc) ::   cr_icerst_cxt     !: context name used in xios to read SI3 restart
+   CHARACTER(LEN=lc) ::   cw_icerst_cxt     !: context name used in xios to write SI3 restart file
+   CHARACTER(LEN=lc) ::   cr_toprst_cxt     !: context name used in xios to read TOP restart
+   CHARACTER(LEN=lc) ::   cw_toprst_cxt     !: context name used in xios to write TOP restart file
+   CHARACTER(LEN=lc) ::   cr_sedrst_cxt     !: context name used in xios to read SEDIMENT restart
+   CHARACTER(LEN=lc) ::   cw_sedrst_cxt     !: context name used in xios to write SEDIMENT restart file
+
+
+
 
    !! * Substitutions
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/iom.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/iom.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/iom.F90	(revision 14018)
@@ -46,4 +46,6 @@
    USE lib_fortran 
    USE diu_bulk, ONLY : ln_diurnal_only, ln_diurnal
+   USE iom_nf90
+   USE netcdf
 
    IMPLICIT NONE
@@ -58,4 +60,5 @@
    PUBLIC iom_chkatt, iom_getatt, iom_putatt, iom_getszuld, iom_rstput, iom_delay_rst, iom_put
    PUBLIC iom_use, iom_context_finalize, iom_update_file_name, iom_miss_val
+   PUBLIC iom_xios_setid
 
    PRIVATE iom_rp0d_sp, iom_rp1d_sp, iom_rp2d_sp, iom_rp3d_sp
@@ -69,7 +72,8 @@
    PRIVATE iom_set_domain_attr, iom_set_axis_attr, iom_set_field_attr, iom_set_file_attr, iom_get_file_attr, iom_set_grid_attr
    PRIVATE set_grid, set_grid_bounds, set_scalar, set_xmlatt, set_mooring, iom_sdate
-   PRIVATE iom_set_rst_context, iom_set_rstw_active, iom_set_rstr_active
+   PRIVATE iom_set_rst_context, iom_set_vars_active
 # endif
-   PUBLIC iom_set_rstw_var_active, iom_set_rstw_core, iom_set_rst_vars
+   PRIVATE set_xios_context
+   PRIVATE iom_set_rstw_active
 
    INTERFACE iom_get
@@ -101,5 +105,5 @@
 CONTAINS
 
-   SUBROUTINE iom_init( cdname, fname, ld_closedef ) 
+   SUBROUTINE iom_init( cdname, kdid, ld_closedef ) 
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE   ***
@@ -109,5 +113,5 @@
       !!----------------------------------------------------------------------
       CHARACTER(len=*),           INTENT(in)  :: cdname
-      CHARACTER(len=*), OPTIONAL, INTENT(in)  :: fname
+      INTEGER         , OPTIONAL, INTENT(in)  :: kdid          
       LOGICAL         , OPTIONAL, INTENT(in)  :: ld_closedef
 #if defined key_iomput
@@ -118,12 +122,15 @@
       INTEGER             :: irefyear, irefmonth, irefday
       INTEGER           :: ji
-      LOGICAL :: llrst_context              ! is context related to restart
+      LOGICAL           :: llrst_context              ! is context related to restart
+      LOGICAL           :: llrstr, llrstw 
+      INTEGER           :: inum
       !
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zt_bnds, zw_bnds
       REAL(wp), DIMENSION(2,jpkam1)         :: za_bnds   ! ABL vertical boundaries
-      LOGICAL ::   ll_closedef = .TRUE.
+      LOGICAL ::   ll_closedef
       LOGICAL ::   ll_exist
       !!----------------------------------------------------------------------
       !
+      ll_closedef = .TRUE.
       IF ( PRESENT(ld_closedef) ) ll_closedef = ld_closedef
       !
@@ -134,5 +141,14 @@
       CALL xios_context_initialize(TRIM(clname), mpi_comm_oce)
       CALL iom_swap( cdname )
-      llrst_context =  (TRIM(cdname) == TRIM(crxios_context) .OR. TRIM(cdname) == TRIM(cwxios_context))
+
+      llrstr = (cdname == cr_ocerst_cxt) .OR. (cdname == cr_icerst_cxt)
+      llrstr = llrstr .OR. (cdname == cr_toprst_cxt)
+      llrstr = llrstr .OR. (cdname == cr_sedrst_cxt)
+
+      llrstw = (cdname == cw_ocerst_cxt) .OR. (cdname == cw_icerst_cxt)
+      llrstw = llrstw .OR. (cdname == cw_toprst_cxt)
+      llrstw = llrstw .OR. (cdname == cw_sedrst_cxt)
+
+      llrst_context = llrstr .OR. llrstw
 
       ! Calendar type is now defined in xml file 
@@ -153,5 +169,5 @@
       IF(.NOT.llrst_context) CALL set_scalar
       !
-      IF( TRIM(cdname) == TRIM(cxios_context) ) THEN  
+      IF( cdname == cxios_context ) THEN  
          CALL set_grid( "T", glamt, gphit, .FALSE., .FALSE. ) 
          CALL set_grid( "U", glamu, gphiu, .FALSE., .FALSE. )
@@ -200,74 +216,72 @@
       ! vertical grid definition
       IF(.NOT.llrst_context) THEN
-          CALL iom_set_axis_attr(  "deptht", paxis = gdept_1d )
-          CALL iom_set_axis_attr(  "depthu", paxis = gdept_1d )
-          CALL iom_set_axis_attr(  "depthv", paxis = gdept_1d )
-          CALL iom_set_axis_attr(  "depthw", paxis = gdepw_1d )
+         CALL iom_set_axis_attr(  "deptht", paxis = gdept_1d )
+         CALL iom_set_axis_attr(  "depthu", paxis = gdept_1d )
+         CALL iom_set_axis_attr(  "depthv", paxis = gdept_1d )
+         CALL iom_set_axis_attr(  "depthw", paxis = gdepw_1d )
           CALL iom_set_axis_attr(  "depthf", paxis = gdept_1d )
 
           ! ABL
-          IF( .NOT. ALLOCATED(ght_abl) ) THEN   ! force definition for xml files (xios) 
-             ALLOCATE( ght_abl(jpka), ghw_abl(jpka), e3t_abl(jpka), e3w_abl(jpka) )   ! default allocation needed by iom
-             ght_abl(:) = -1._wp   ;   ghw_abl(:) = -1._wp
-             e3t_abl(:) = -1._wp   ;   e3w_abl(:) = -1._wp
-          ENDIF
-          CALL iom_set_axis_attr( "ght_abl", ght_abl(2:jpka) )
-          CALL iom_set_axis_attr( "ghw_abl", ghw_abl(2:jpka) )
+         IF( .NOT. ALLOCATED(ght_abl) ) THEN   ! force definition for xml files (xios) 
+            ALLOCATE( ght_abl(jpka), ghw_abl(jpka), e3t_abl(jpka), e3w_abl(jpka) )   ! default allocation needed by iom
+            ght_abl(:) = -1._wp   ;   ghw_abl(:) = -1._wp
+            e3t_abl(:) = -1._wp   ;   e3w_abl(:) = -1._wp
+         ENDIF
+         CALL iom_set_axis_attr( "ght_abl", ght_abl(2:jpka) )
+         CALL iom_set_axis_attr( "ghw_abl", ghw_abl(2:jpka) )
           
-          ! Add vertical grid bounds
-          zt_bnds(2,:      ) = gdept_1d(:)
-          zt_bnds(1,2:jpk  ) = gdept_1d(1:jpkm1)
-          zt_bnds(1,1      ) = gdept_1d(1) - e3w_1d(1)
-          zw_bnds(1,:      ) = gdepw_1d(:)
-          zw_bnds(2,1:jpkm1) = gdepw_1d(2:jpk)
-          zw_bnds(2,jpk:   ) = gdepw_1d(jpk) + e3t_1d(jpk)
-          CALL iom_set_axis_attr(  "deptht", bounds=zw_bnds )
-          CALL iom_set_axis_attr(  "depthu", bounds=zw_bnds )
-          CALL iom_set_axis_attr(  "depthv", bounds=zw_bnds )
-          CALL iom_set_axis_attr(  "depthw", bounds=zt_bnds )
+         ! Add vertical grid bounds
+         zt_bnds(2,:      ) = gdept_1d(:)
+         zt_bnds(1,2:jpk  ) = gdept_1d(1:jpkm1)
+         zt_bnds(1,1      ) = gdept_1d(1) - e3w_1d(1)
+         zw_bnds(1,:      ) = gdepw_1d(:)
+         zw_bnds(2,1:jpkm1) = gdepw_1d(2:jpk)
+         zw_bnds(2,jpk:   ) = gdepw_1d(jpk) + e3t_1d(jpk)
+         CALL iom_set_axis_attr(  "deptht", bounds=zw_bnds )
+         CALL iom_set_axis_attr(  "depthu", bounds=zw_bnds )
+         CALL iom_set_axis_attr(  "depthv", bounds=zw_bnds )
+         CALL iom_set_axis_attr(  "depthw", bounds=zt_bnds )
           CALL iom_set_axis_attr(  "depthf", bounds=zw_bnds )
 
-          ! ABL
-          za_bnds(1,:) = ghw_abl(1:jpkam1)
-          za_bnds(2,:) = ghw_abl(2:jpka  )
-          CALL iom_set_axis_attr( "ght_abl", bounds=za_bnds )
-          za_bnds(1,:) = ght_abl(2:jpka  )
-          za_bnds(2,:) = ght_abl(2:jpka  ) + e3w_abl(2:jpka)
-          CALL iom_set_axis_attr( "ghw_abl", bounds=za_bnds )
-
-          CALL iom_set_axis_attr(  "nfloat", (/ (REAL(ji,wp), ji=1,jpnfl) /) )
+         ! ABL
+         za_bnds(1,:) = ghw_abl(1:jpkam1)
+         za_bnds(2,:) = ghw_abl(2:jpka  )
+         CALL iom_set_axis_attr( "ght_abl", bounds=za_bnds )
+         za_bnds(1,:) = ght_abl(2:jpka  )
+         za_bnds(2,:) = ght_abl(2:jpka  ) + e3w_abl(2:jpka)
+         CALL iom_set_axis_attr( "ghw_abl", bounds=za_bnds )
+
+         CALL iom_set_axis_attr(  "nfloat", (/ (REAL(ji,wp), ji=1,jpnfl) /) )
 # if defined key_si3
-          CALL iom_set_axis_attr( "ncatice", (/ (REAL(ji,wp), ji=1,jpl) /) )
-          ! SIMIP diagnostics (4 main arctic straits)
-          CALL iom_set_axis_attr( "nstrait", (/ (REAL(ji,wp), ji=1,4) /) )
+         CALL iom_set_axis_attr( "ncatice", (/ (REAL(ji,wp), ji=1,jpl) /) )
+         ! SIMIP diagnostics (4 main arctic straits)
+         CALL iom_set_axis_attr( "nstrait", (/ (REAL(ji,wp), ji=1,4) /) )
 # endif
 #if defined key_top
-          IF( ALLOCATED(profsed) ) CALL iom_set_axis_attr( "profsed", paxis = profsed )
-#endif
-          CALL iom_set_axis_attr( "icbcla", class_num )
-          CALL iom_set_axis_attr( "iax_20C", (/ REAL(20,wp) /) )   ! strange syntaxe and idea...
-          CALL iom_set_axis_attr( "iax_26C", (/ REAL(26,wp) /) )   ! strange syntaxe and idea...
-          CALL iom_set_axis_attr( "iax_28C", (/ REAL(28,wp) /) )   ! strange syntaxe and idea...
-          ! for diaprt, we need to define an axis which size can be 1 (default) or 5 (if the file subbasins.nc exists)
-          INQUIRE( FILE = 'subbasins.nc', EXIST = ll_exist )
-          nbasin = 1 + 4 * COUNT( (/ll_exist/) )
-          CALL iom_set_axis_attr( "basin"  , (/ (REAL(ji,wp), ji=1,nbasin) /) )
+         IF( ALLOCATED(profsed) ) CALL iom_set_axis_attr( "profsed", paxis = profsed )
+#endif
+         CALL iom_set_axis_attr( "icbcla", class_num )
+         CALL iom_set_axis_attr( "iax_20C", (/ REAL(20,wp) /) )   ! strange syntaxe and idea...
+         CALL iom_set_axis_attr( "iax_26C", (/ REAL(26,wp) /) )   ! strange syntaxe and idea...
+         CALL iom_set_axis_attr( "iax_28C", (/ REAL(28,wp) /) )   ! strange syntaxe and idea...
+         ! for diaprt, we need to define an axis which size can be 1 (default) or 5 (if the file subbasins.nc exists)
+         INQUIRE( FILE = 'subbasins.nc', EXIST = ll_exist )
+         nbasin = 1 + 4 * COUNT( (/ll_exist/) )
+         CALL iom_set_axis_attr( "basin"  , (/ (REAL(ji,wp), ji=1,nbasin) /) )
       ENDIF
       !
       ! automatic definitions of some of the xml attributs
-      IF( TRIM(cdname) == TRIM(crxios_context) ) THEN
-!set names of the fields in restart file IF using XIOS to read data
-          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()
-      ELSE IF( TRIM(cdname) == TRIM(cwxios_context) ) THEN
-!set names of the fields in restart file IF using XIOS to write data
-          CALL iom_set_rst_context(.FALSE.)
-          CALL iom_set_rst_vars(rst_wfields)
-!set which fields are to be written to a restart file
-          CALL iom_set_rstw_active(fname)
+      IF(llrstr) THEN
+         IF(PRESENT(kdid)) THEN
+            CALL iom_set_rst_context(.TRUE.)
+!set which fields will be read from restart file
+            CALL iom_set_vars_active(kdid)
+         ELSE
+            CALL ctl_stop( 'iom_init:', 'restart read with XIOS: missing pointer to NETCDF file' )
+         ENDIF
+      ELSE IF(llrstw) THEN
+         CALL iom_set_rstw_file(iom_file(kdid)%name)
       ELSE
-          CALL set_xmlatt
+         CALL set_xmlatt
       ENDIF
       !
@@ -285,5 +299,5 @@
    END SUBROUTINE iom_init
 
-   SUBROUTINE iom_init_closedef
+   SUBROUTINE iom_init_closedef(cdname)
       !!----------------------------------------------------------------------
       !!            ***  SUBROUTINE iom_init_closedef  ***
@@ -293,8 +307,24 @@
       !!
       !!----------------------------------------------------------------------
-
+      CHARACTER(len=*), OPTIONAL, INTENT(IN) :: cdname
 #if defined key_iomput
-      CALL xios_close_context_definition()
-      CALL xios_update_calendar( 0 )
+      LOGICAL :: llrstw
+
+      llrstw = .FALSE.
+      IF(PRESENT(cdname)) THEN
+         llrstw = (cdname == cw_ocerst_cxt)
+         llrstw = llrstw .OR. (cdname == cw_icerst_cxt)
+         llrstw = llrstw .OR. (cdname == cw_toprst_cxt)
+         llrstw = llrstw .OR. (cdname == cw_sedrst_cxt)
+      ENDIF
+
+      IF( llrstw ) THEN
+!set names of the fields in restart file IF using XIOS to write data
+         CALL iom_set_rst_context(.FALSE.)
+         CALL xios_close_context_definition()
+      ELSE
+         CALL xios_close_context_definition()
+         CALL xios_update_calendar( 0 )
+      ENDIF
 #else
       IF( .FALSE. )   WRITE(numout,*) 'iom_init_closedef: should not see this'   ! useless statement to avoid compilation warnings
@@ -303,252 +333,143 @@
    END SUBROUTINE iom_init_closedef
 
-   SUBROUTINE iom_set_rstw_var_active(field)
+   SUBROUTINE iom_set_vars_active(idnum)
       !!---------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_set_rstw_var_active  ***
-      !!
-      !! ** Purpose :  enable variable in restart file when writing with XIOS 
+      !!                   ***  SUBROUTINE  iom_set_vars_active  ***
+      !!
+      !! ** Purpose :  define filename in XIOS context for reading file,
+      !!               enable variables present in a file for reading with XIOS 
+      !!               id of the file is assumed to be rrestart.
       !!---------------------------------------------------------------------
-   CHARACTER(len = *), INTENT(IN) :: field
-   INTEGER :: i
-   LOGICAL :: llis_set
-   CHARACTER(LEN=256) :: clinfo    ! info character
-
+      INTEGER, INTENT(IN) :: idnum 
+      
 #if defined key_iomput
-   llis_set = .FALSE.
-
-   DO i = 1, max_rst_fields
-       IF(TRIM(rst_wfields(i)%vname) == field) THEN 
-          rst_wfields(i)%active = .TRUE.
-          llis_set = .TRUE.
-          EXIT
-       ENDIF
-   ENDDO
-!Warn if variable is not in defined in rst_wfields
-   IF(.NOT.llis_set) THEN
-      WRITE(ctmp1,*) 'iom_set_rstw_var_active: variable ', field ,' is available for writing but not defined' 
-      CALL ctl_stop( 'iom_set_rstw_var_active:', ctmp1 )
-   ENDIF
-#else
-        clinfo = 'iom_set_rstw_var_active: key_iomput is needed to use XIOS restart read/write functionality'
-        CALL ctl_stop('STOP', TRIM(clinfo))
-#endif
-
-   END SUBROUTINE iom_set_rstw_var_active
-
-   SUBROUTINE iom_set_rstr_active()
+      INTEGER                                    :: ndims, nvars, natts, unlimitedDimId, dimlen, xtype,mdims
+      TYPE(xios_field)                           :: field_hdl
+      TYPE(xios_file)                            :: file_hdl
+      TYPE(xios_filegroup)                       :: filegroup_hdl
+      INTEGER                                    :: dimids(4), jv,i, idim
+      CHARACTER(LEN=256)                         :: clinfo               ! info character
+      INTEGER, ALLOCATABLE                       :: indimlens(:)
+      CHARACTER(LEN=nf90_max_name), ALLOCATABLE  :: indimnames(:)
+      CHARACTER(LEN=nf90_max_name)               :: dimname, varname
+      INTEGER                                    :: iln
+      CHARACTER(LEN=lc)                          :: fname
+      LOGICAL                                    :: lmeta
+!metadata in restart file for restart read with XIOS
+      INTEGER, PARAMETER                         :: NMETA = 10
+      CHARACTER(LEN=lc)                          :: meta(NMETA)
+
+
+      meta(1) = "nav_lat"
+      meta(2) = "nav_lon"
+      meta(3) = "nav_lev"
+      meta(4) = "time_instant"
+      meta(5) = "time_instant_bounds"
+      meta(6) = "time_counter"
+      meta(7) = "time_counter_bounds"
+      meta(8) = "x"
+      meta(9) = "y"
+      meta(10) = "numcat"
+
+      clinfo = '          iom_set_vars_active, file: '//TRIM(iom_file(idnum)%name)
+
+      iln = INDEX( iom_file(idnum)%name, '.nc' )
+!XIOS doee not need .nc
+      IF(iln > 0) THEN
+        fname =  iom_file(idnum)%name(1:iln-1)
+      ELSE
+        fname =  iom_file(idnum)%name
+      ENDIF
+
+!set name of the restart file and enable available fields
+      CALL xios_get_handle("file_definition", filegroup_hdl )
+      CALL xios_add_child(filegroup_hdl, file_hdl, 'rrestart')
+      CALL xios_set_file_attr( "rrestart", name=fname, type="one_file",      &
+           par_access="collective", enabled=.TRUE., mode="read",              &
+                                                    output_freq=xios_timestep )
+
+      CALL iom_nf90_check( nf90_inquire(iom_file(idnum)%nfid, ndims, nvars, natts ), clinfo )
+      ALLOCATE(indimlens(ndims), indimnames(ndims))
+      CALL iom_nf90_check( nf90_inquire(iom_file(idnum)%nfid, unlimitedDimId = unlimitedDimId ), clinfo )
+
+      DO idim = 1, ndims
+         CALL iom_nf90_check( nf90_inquire_dimension(iom_file(idnum)%nfid, idim, dimname, dimlen ), clinfo )
+         indimlens(idim) = dimlen
+         indimnames(idim) = dimname
+      ENDDO
+
+      DO jv =1, nvars
+         lmeta = .FALSE.
+         CALL iom_nf90_check( nf90_inquire_variable(iom_file(idnum)%nfid, jv, varname, xtype, ndims, dimids, natts ), clinfo )
+         DO i = 1, NMETA
+           IF(varname == meta(i)) THEN
+             lmeta = .TRUE.
+           ENDIF
+         ENDDO
+         IF(.NOT.lmeta) THEN
+            CALL xios_add_child(file_hdl, field_hdl, varname)
+            mdims = ndims
+
+            IF(ANY(dimids(1:ndims) == unlimitedDimId)) THEN
+               mdims = mdims - 1
+            ENDIF
+
+            IF(mdims == 3) THEN
+               CALL xios_set_attr (field_hdl, enabled = .TRUE., name = varname,   &
+                                   domain_ref="grid_N",                           &
+                                   axis_ref=iom_axis(indimlens(dimids(mdims))),   &
+                                   prec = 8, operation = "instant"                )
+            ELSEIF(mdims == 2) THEN
+               CALL xios_set_attr (field_hdl, enabled = .TRUE., name = varname,  &
+                                   domain_ref="grid_N", prec = 8,                &
+                                   operation = "instant"                         ) 
+            ELSEIF(mdims == 1) THEN
+               CALL xios_set_attr (field_hdl, enabled = .TRUE., name = varname, &
+                                   axis_ref=iom_axis(indimlens(dimids(mdims))), &
+                                   prec = 8, operation = "instant"              )
+            ELSEIF(mdims == 0) THEN
+               CALL xios_set_attr (field_hdl, enabled = .TRUE., name = varname, &
+                                   scalar_ref = "grid_scalar", prec = 8,        &
+                                   operation = "instant"                        )
+            ELSE
+               WRITE(ctmp1,*) 'iom_set_vars_active: variable ', TRIM(varname) ,' incorrect number of dimensions' 
+               CALL ctl_stop( 'iom_set_vars_active:', ctmp1 )
+            ENDIF
+         ENDIF
+      ENDDO
+      DEALLOCATE(indimlens, indimnames)
+#endif
+   END SUBROUTINE iom_set_vars_active
+
+   SUBROUTINE iom_set_rstw_file(cdrst_file)
       !!---------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_set_rstr_active  ***
-      !!
-      !! ** Purpose :  define file name in XIOS context for reading restart file,
-      !!               enable variables present in restart file for reading with XIOS 
+      !!                   ***  SUBROUTINE iom_set_rstw_file   ***
+      !!
+      !! ** Purpose :  define file name in XIOS context for writing restart
       !!---------------------------------------------------------------------
-
-!sets enabled = .TRUE. for each field in restart file
-   CHARACTER(len=256) :: rst_file
-
+      CHARACTER(len=*) :: cdrst_file
 #if defined key_iomput
-   TYPE(xios_field) :: field_hdl
-   TYPE(xios_file) :: file_hdl
-   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)//TRIM(Agrif_CFixed())//'_'//TRIM(cn_ocerst_in)
-        ENDIF
+      TYPE(xios_file) :: file_hdl
+      TYPE(xios_filegroup) :: filegroup_hdl
+
 !set name of the restart file and enable available fields
-        if(lwp) WRITE(numout,*) 'Setting restart filename (for XIOS) to: ',rst_file
-        CALL xios_get_handle("file_definition", filegroup_hdl )
-        CALL xios_add_child(filegroup_hdl, file_hdl, 'rrestart')
-        CALL xios_set_file_attr( "rrestart", name=trim(rst_file), type="one_file", &
-             par_access="collective", enabled=.TRUE., mode="read",                 &
-             output_freq=xios_timestep)
-!define variables for restart context
-        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
-                CALL xios_add_child(file_hdl, field_hdl, TRIM(rst_rfields(i)%vname))
-                SELECT CASE (TRIM(rst_rfields(i)%grid))
-                 CASE ("grid_N_3D")
-                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
-                        domain_ref="grid_N", axis_ref="nav_lev", operation = "instant")
-                 CASE ("grid_N")
-                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
-                        domain_ref="grid_N", operation = "instant") 
-                CASE ("grid_vector")
-                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
-                         axis_ref="nav_lev", operation = "instant")
-                 CASE ("grid_scalar")
-                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
-                        scalar_ref = "grid_scalar", operation = "instant")
-                END SELECT
-                IF(lwp) WRITE(numout,*) 'XIOS read: ', TRIM(rst_rfields(i)%vname), ' enabled in ', TRIM(rst_file)
-           ENDIF
-         ENDIF
-        END DO
-#endif
-   END SUBROUTINE iom_set_rstr_active
-
-   SUBROUTINE iom_set_rstw_core(cdmdl)
-      !!---------------------------------------------------------------------
-      !!                   ***  SUBROUTINE  iom_set_rstw_core  ***
-      !!
-      !! ** Purpose :  set variables which are always in restart file 
-      !!---------------------------------------------------------------------
-   CHARACTER (len=*), INTENT (IN) :: cdmdl ! model OPA or SAS
-   CHARACTER(LEN=256)             :: clinfo    ! info character
-#if defined key_iomput
-   IF(cdmdl == "OPA") THEN
-!from restart.F90
-   CALL iom_set_rstw_var_active("rn_Dt")
-   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('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')
-      ENDIF
-      IF(ln_diurnal) CALL iom_set_rstw_var_active('Dsst')
-!from trasbc.F90
-         CALL iom_set_rstw_var_active('sbc_hc_b')
-         CALL iom_set_rstw_var_active('sbc_sc_b')
-   ENDIF
-#else
-        clinfo = 'iom_set_rstw_core: key_iomput is needed to use XIOS restart read/write functionality'
-        CALL ctl_stop('STOP', TRIM(clinfo))
-#endif
-   END SUBROUTINE iom_set_rstw_core
-
-   SUBROUTINE iom_set_rst_vars(fields)
-      !!---------------------------------------------------------------------
-      !!                   ***  SUBROUTINE iom_set_rst_vars   ***
-      !!
-      !! ** Purpose :  Fill array fields with the information about all 
-      !!               possible variables and corresponding grids definition 
-      !!               for reading/writing restart with XIOS
-      !!---------------------------------------------------------------------
-   TYPE(RST_FIELD), INTENT(INOUT) :: fields(max_rst_fields)
-   INTEGER :: i
-
-        i = 0
-        i = i + 1; fields(i)%vname="rn_Dt";            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"
-                                               fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="greenland_icesheet_timelapsed"
-                                               fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="greenland_icesheet_mass_roc"
-                                               fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="antarctica_icesheet_mass"
-                                               fields(i)%grid="grid_scalar"
-        i = i + 1; fields(i)%vname="antarctica_icesheet_timelapsed"
-                                               fields(i)%grid="grid_scalar"
-        i = i + 1; 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
-   END SUBROUTINE iom_set_rst_vars
-
-
-   SUBROUTINE iom_set_rstw_active(cdrst_file)
+      IF(lwp) WRITE(numout,*) 'Setting restart filename (for XIOS write) to: ', TRIM(cdrst_file)
+      CALL xios_get_handle("file_definition", filegroup_hdl )
+      CALL xios_add_child(filegroup_hdl, file_hdl, 'wrestart')
+      IF(nxioso.eq.1) THEN 
+         CALL xios_set_file_attr( "wrestart", type="one_file", enabled=.TRUE.,& 
+                                       mode="write", output_freq=xios_timestep) 
+         IF(lwp) write(numout,*) 'OPEN ', trim(cdrst_file), ' in one_file mode' 
+      ELSE  
+         CALL xios_set_file_attr( "wrestart", type="multiple_file", enabled=.TRUE.,& 
+                                            mode="write", output_freq=xios_timestep) 
+         IF(lwp) write(numout,*) 'OPEN ', trim(cdrst_file), ' in multiple_file mode' 
+      ENDIF 
+      CALL xios_set_file_attr( "wrestart", name=trim(cdrst_file))
+#endif
+   END SUBROUTINE iom_set_rstw_file
+
+
+   SUBROUTINE iom_set_rstw_active(sdfield, rd0, rs0, rd1, rs1, rd2, rs2, rd3, rs3)
       !!---------------------------------------------------------------------
       !!                   ***  SUBROUTINE iom_set_rstw_active   ***
@@ -558,51 +479,110 @@
       !!---------------------------------------------------------------------
 !sets enabled = .TRUE. for each field in restart file
-   CHARACTER(len=*) :: cdrst_file
+      CHARACTER(len = *), INTENT(IN)                     :: sdfield
+      REAL(dp), OPTIONAL, INTENT(IN)                     :: rd0
+      REAL(sp), OPTIONAL, INTENT(IN)                     :: rs0
+      REAL(dp), OPTIONAL, INTENT(IN), DIMENSION(:)       :: rd1
+      REAL(sp), OPTIONAL, INTENT(IN), DIMENSION(:)       :: rs1
+      REAL(dp), OPTIONAL, INTENT(IN), DIMENSION(:, :)    :: rd2
+      REAL(sp), OPTIONAL, INTENT(IN), DIMENSION(:, :)    :: rs2
+      REAL(dp), OPTIONAL, INTENT(IN), DIMENSION(:, :, :) :: rd3  
+      REAL(sp), OPTIONAL, INTENT(IN), DIMENSION(:, :, :) :: rs3
 #if defined key_iomput
-   TYPE(xios_field) :: field_hdl
-   TYPE(xios_file) :: file_hdl
-   TYPE(xios_filegroup) :: filegroup_hdl
-   INTEGER :: i
-   CHARACTER(lc)  ::   clpath
-
-!set name of the restart file and enable available fields
-        IF(lwp) WRITE(numout,*) 'Setting restart filename (for XIOS write) to: ',cdrst_file
-        CALL xios_get_handle("file_definition", filegroup_hdl )
-        CALL xios_add_child(filegroup_hdl, file_hdl, 'wrestart')
-        IF(nxioso.eq.1) THEN 
-           CALL xios_set_file_attr( "wrestart", type="one_file", enabled=.TRUE.,& 
-                                    mode="write", output_freq=xios_timestep) 
-           if(lwp) write(numout,*) 'OPEN ', trim(cdrst_file), ' in one_file mode' 
-        ELSE  
-           CALL xios_set_file_attr( "wrestart", type="multiple_file", enabled=.TRUE.,& 
-                                    mode="write", output_freq=xios_timestep) 
-           if(lwp) write(numout,*) 'OPEN ', trim(cdrst_file), ' in multiple_file mode' 
-        ENDIF 
-        CALL xios_set_file_attr( "wrestart", name=trim(cdrst_file))
+      TYPE(xios_field) :: field_hdl
+      TYPE(xios_file) :: file_hdl
+
+      CALL xios_get_handle("wrestart", file_hdl)
 !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))
-                 CASE ("grid_N_3D")
-                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_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), &
-                        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), &
-                         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), &
-                        scalar_ref = "grid_scalar", prec = 8, operation = "instant")
-                END SELECT
-         ENDIF
-        END DO
+      CALL xios_add_child(file_hdl, field_hdl, sdfield)
+
+      IF(PRESENT(rd3)) THEN
+         CALL xios_set_attr (field_hdl, enabled = .TRUE., name = sdfield, &
+                             domain_ref = "grid_N",                       &
+                             axis_ref = iom_axis(size(rd3, 3)),           &
+                             prec = 8, operation = "instant"              )
+      ELSEIF(PRESENT(rs3)) THEN
+         CALL xios_set_attr (field_hdl, enabled = .TRUE., name = sdfield, &
+                             domain_ref = "grid_N",                       &
+                             axis_ref = iom_axis(size(rd3, 3)),           &
+                             prec = 4, operation = "instant"              )
+      ELSEIF(PRESENT(rd2)) THEN
+         CALL xios_set_attr (field_hdl, enabled = .TRUE., name = sdfield, &
+                             domain_ref = "grid_N", prec = 8,             &
+                             operation = "instant"                        ) 
+      ELSEIF(PRESENT(rs2)) THEN
+         CALL xios_set_attr (field_hdl, enabled = .TRUE., name = sdfield, &
+                             domain_ref = "grid_N", prec = 4,             &
+                             operation = "instant"                        )
+      ELSEIF(PRESENT(rd1)) THEN
+         CALL xios_set_attr (field_hdl, enabled = .TRUE., name = sdfield, &
+                             axis_ref = iom_axis(size(rd1, 1)),           &
+                             prec = 8, operation = "instant"              )
+      ELSEIF(PRESENT(rs1)) THEN
+         CALL xios_set_attr (field_hdl, enabled = .TRUE., name = sdfield, &
+                             axis_ref = iom_axis(size(rd1, 1)),           &
+                             prec = 4, operation = "instant"              )
+      ELSEIF(PRESENT(rd0)) THEN
+         CALL xios_set_attr (field_hdl, enabled = .TRUE., name = sdfield, &
+                             scalar_ref = "grid_scalar", prec = 8,        &
+                             operation = "instant"                        )
+      ELSEIF(PRESENT(rs0)) THEN
+         CALL xios_set_attr (field_hdl, enabled = .TRUE., name = sdfield, &
+                             scalar_ref = "grid_scalar", prec = 4,        &
+                             operation = "instant"                        )
+      ENDIF
 #endif
    END SUBROUTINE iom_set_rstw_active
 
+   FUNCTION iom_axis(idlev) result(axis_ref)
+      !!---------------------------------------------------------------------
+      !!                   ***  FUNCTION  iom_axis  ***
+      !!
+      !! ** Purpose : Used for grid definition when XIOS is used to read/write
+      !!              restart. Returns axis corresponding to the number of levels
+      !!              given as an input variable. Axes are defined in routine 
+      !!              iom_set_rst_context
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(IN) :: idlev
+      CHARACTER(len=lc)   :: axis_ref
+      CHARACTER(len=12)   :: str
+      IF(idlev == jpk) THEN
+         axis_ref="nav_lev"
+#if defined key_si3
+      ELSEIF(idlev == jpl) THEN
+         axis_ref="numcat"
+#endif         
+      ELSE
+         write(str, *) idlev
+         CALL ctl_stop( 'iom_axis', 'Definition for axis with '//TRIM(ADJUSTL(str))//' levels missing')
+      ENDIF
+   END FUNCTION iom_axis
+
+   FUNCTION iom_xios_setid(cdname) result(kid)
+     !!---------------------------------------------------------------------
+      !!                   ***  FUNCTION    ***
+      !!
+      !! ** Purpose : this function returns first available id to keep information about file 
+      !!              sets filename in iom_file structure and sets name
+      !!              of XIOS context depending on cdcomp
+      !!              corresponds to iom_nf90_open
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in   ) :: cdname      ! File name
+      INTEGER                         :: kid      ! identifier of the opened file
+      INTEGER                         :: jl
+
+      kid = 0
+      DO jl = jpmax_files, 1, -1
+         IF( iom_file(jl)%nfid == 0 )   kid = jl
+      ENDDO
+
+      iom_file(kid)%name   = TRIM(cdname)
+      iom_file(kid)%nfid   = 1
+      iom_file(kid)%nvars  = 0
+      iom_file(kid)%irec   = -1
+
+   END FUNCTION iom_xios_setid
+
    SUBROUTINE iom_set_rst_context(ld_rstr) 
-     !!---------------------------------------------------------------------
+      !!---------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_set_rst_context  ***
       !!
@@ -611,30 +591,71 @@
       !!               
       !!---------------------------------------------------------------------
-   LOGICAL, INTENT(IN)               :: ld_rstr
-!ld_rstr is true for restart context. There is no need to define grid for 
-!restart read, because it's read from file
+      LOGICAL, INTENT(IN)               :: ld_rstr
+      INTEGER :: ji
 #if defined key_iomput
-   TYPE(xios_domaingroup)            :: domaingroup_hdl 
-   TYPE(xios_domain)                 :: domain_hdl 
-   TYPE(xios_axisgroup)              :: axisgroup_hdl 
-   TYPE(xios_axis)                   :: axis_hdl 
-   TYPE(xios_scalar)                 :: scalar_hdl 
-   TYPE(xios_scalargroup)            :: scalargroup_hdl 
-
-     CALL xios_get_handle("domain_definition",domaingroup_hdl) 
-     CALL xios_add_child(domaingroup_hdl, domain_hdl, "grid_N") 
-     CALL set_grid("N", glamt, gphit, .TRUE., ld_rstr) 
+      TYPE(xios_domaingroup)            :: domaingroup_hdl 
+      TYPE(xios_domain)                 :: domain_hdl 
+      TYPE(xios_axisgroup)              :: axisgroup_hdl 
+      TYPE(xios_axis)                   :: axis_hdl 
+      TYPE(xios_scalar)                 :: scalar_hdl 
+      TYPE(xios_scalargroup)            :: scalargroup_hdl 
+
+      CALL xios_get_handle("domain_definition",domaingroup_hdl) 
+      CALL xios_add_child(domaingroup_hdl, domain_hdl, "grid_N") 
+      CALL set_grid("N", glamt, gphit, .TRUE., ld_rstr) 
  
-     CALL xios_get_handle("axis_definition",axisgroup_hdl) 
-     CALL xios_add_child(axisgroup_hdl, axis_hdl, "nav_lev") 
+      CALL xios_get_handle("axis_definition",axisgroup_hdl) 
+      CALL xios_add_child(axisgroup_hdl, axis_hdl, "nav_lev") 
 !AGRIF fails to compile when unit= is in call to xios_set_axis_attr
-!    CALL xios_set_axis_attr( "nav_lev", long_name="Vertical levels",  unit="m", positive="down") 
-     CALL xios_set_axis_attr( "nav_lev", long_name="Vertical levels in meters", positive="down")
-     CALL iom_set_axis_attr( "nav_lev", paxis = gdept_1d ) 
-
-     CALL xios_get_handle("scalar_definition", scalargroup_hdl) 
-     CALL xios_add_child(scalargroup_hdl, scalar_hdl, "grid_scalar") 
+!     CALL xios_set_axis_attr( "nav_lev", long_name="Vertical levels",  unit="m", positive="down") 
+      CALL xios_set_axis_attr( "nav_lev", long_name = "Vertical levels in meters", positive = "down")
+      CALL iom_set_axis_attr( "nav_lev", paxis = gdept_1d ) 
+#if defined key_si3
+      CALL xios_add_child(axisgroup_hdl, axis_hdl, "numcat")
+      CALL iom_set_axis_attr( "numcat", (/ (REAL(ji,wp), ji=1,jpl) /) )
+#endif
+      CALL xios_get_handle("scalar_definition", scalargroup_hdl) 
+      CALL xios_add_child(scalargroup_hdl, scalar_hdl, "grid_scalar") 
 #endif
    END SUBROUTINE iom_set_rst_context
+
+
+   SUBROUTINE set_xios_context(kdid, cdcont) 
+      !!---------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_set_rst_context  ***
+      !!
+      !! ** Purpose : set correct XIOS context based on kdid
+      !!               
+      !!---------------------------------------------------------------------
+      INTEGER,           INTENT(IN)     :: kdid           ! Identifier of the file
+      CHARACTER(LEN=lc), INTENT(OUT)    :: cdcont         ! name of the context for XIOS read/write
+      
+      cdcont = "NONE"
+
+      IF(lrxios) THEN
+         IF(kdid == numror) THEN
+            cdcont = cr_ocerst_cxt
+         ELSEIF(kdid == numrir) THEN
+            cdcont = cr_icerst_cxt 
+         ELSEIF(kdid == numrtr) THEN
+            cdcont = cr_toprst_cxt
+         ELSEIF(kdid == numrsr) THEN
+            cdcont = cr_sedrst_cxt
+         ENDIF
+      ENDIF
+
+      IF(lwxios) THEN
+         IF(kdid == numrow) THEN
+            cdcont = cw_ocerst_cxt
+         ELSEIF(kdid == numriw) THEN
+            cdcont = cw_icerst_cxt
+         ELSEIF(kdid == numrtw) THEN
+            cdcont = cw_toprst_cxt
+         ELSEIF(kdid == numrsw) THEN
+            cdcont = cw_sedrst_cxt
+         ENDIF
+      ENDIF
+   END SUBROUTINE set_xios_context
+
 
    SUBROUTINE iom_swap( cdname )
@@ -647,5 +668,4 @@
 #if defined key_iomput
       TYPE(xios_context) :: nemo_hdl
-
       IF( TRIM(Agrif_CFixed()) == '0' ) THEN
         CALL xios_get_handle(TRIM(cdname),nemo_hdl)
@@ -897,5 +917,5 @@
    !!                   INTERFACE iom_get
    !!----------------------------------------------------------------------
-   SUBROUTINE iom_g0d_sp( kiomid, cdvar, pvar, ktime, ldxios )
+   SUBROUTINE iom_g0d_sp( kiomid, cdvar, pvar, ktime )
       INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
       CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
@@ -903,5 +923,4 @@
       REAL(dp)                                        ::   ztmp_pvar ! tmp var to read field
       INTEGER         , INTENT(in   ),     OPTIONAL   ::   ktime     ! record number
-      LOGICAL         , INTENT(in   ),     OPTIONAL   ::   ldxios    ! use xios to read restart
       !
       INTEGER                                         ::   idvar     ! variable id
@@ -911,10 +930,9 @@
       CHARACTER(LEN=100)                              ::   clname    ! file name
       CHARACTER(LEN=1)                                ::   cldmspc   !
-      LOGICAL                                         ::   llxios
-      !
-      llxios = .FALSE.
-      IF( PRESENT(ldxios) ) llxios = ldxios
-
-      IF(.NOT.llxios) THEN  ! read data using default library
+      CHARACTER(LEN=lc)                               ::   context
+      !
+      CALL set_xios_context(kiomid, context)
+
+      IF(context == "NONE") THEN  ! read data using default library
          itime = 1
          IF( PRESENT(ktime) ) itime = ktime
@@ -939,7 +957,7 @@
 #if defined key_iomput
          IF(lwp) WRITE(numout,*) 'XIOS RST READ (0D): ', trim(cdvar)
-         CALL iom_swap( TRIM(crxios_context) )
+         CALL iom_swap(context)
          CALL xios_recv_field( trim(cdvar), pvar)
-         CALL iom_swap( TRIM(cxios_context) )
+         CALL iom_swap(cxios_context)
 #else
          WRITE(ctmp1,*) 'Can not use XIOS in iom_g0d, file: '//trim(clname)//', var:'//trim(cdvar)
@@ -949,10 +967,9 @@
    END SUBROUTINE iom_g0d_sp
 
-   SUBROUTINE iom_g0d_dp( kiomid, cdvar, pvar, ktime, ldxios )
+   SUBROUTINE iom_g0d_dp( kiomid, cdvar, pvar, ktime )
       INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
       CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
       REAL(dp)        , INTENT(  out)                 ::   pvar      ! read field
       INTEGER         , INTENT(in   ),     OPTIONAL   ::   ktime     ! record number
-      LOGICAL         , INTENT(in   ),     OPTIONAL   ::   ldxios    ! use xios to read restart
       !
       INTEGER                                         ::   idvar     ! variable id
@@ -962,10 +979,9 @@
       CHARACTER(LEN=100)                              ::   clname    ! file name
       CHARACTER(LEN=1)                                ::   cldmspc   !
-      LOGICAL                                         ::   llxios
-      !
-      llxios = .FALSE.
-      IF( PRESENT(ldxios) ) llxios = ldxios
-
-      IF(.NOT.llxios) THEN  ! read data using default library
+      CHARACTER(LEN=lc)                               ::   context
+      !
+      CALL set_xios_context(kiomid, context)
+
+      IF(context == "NONE") THEN  ! read data using default library
          itime = 1
          IF( PRESENT(ktime) ) itime = ktime
@@ -989,7 +1005,7 @@
 #if defined key_iomput
          IF(lwp) WRITE(numout,*) 'XIOS RST READ (0D): ', trim(cdvar)
-         CALL iom_swap( TRIM(crxios_context) )
+         CALL iom_swap(context)
          CALL xios_recv_field( trim(cdvar), pvar)
-         CALL iom_swap( TRIM(cxios_context) )
+         CALL iom_swap(cxios_context)
 #else
          WRITE(ctmp1,*) 'Can not use XIOS in iom_g0d, file: '//trim(clname)//', var:'//trim(cdvar)
@@ -999,5 +1015,5 @@
    END SUBROUTINE iom_g0d_dp
 
-   SUBROUTINE iom_g1d_sp( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, ldxios )
+   SUBROUTINE iom_g1d_sp( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
       INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
       INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
@@ -1008,5 +1024,4 @@
       INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading 
       INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
-      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS
       !
       IF( kiomid > 0 ) THEN
@@ -1014,6 +1029,5 @@
             ALLOCATE(ztmp_pvar(size(pvar,1)))
             CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=ztmp_pvar,   &
-              &                                                     ktime=ktime, kstart=kstart, kcount=kcount, &
-              &                                                     ldxios=ldxios )
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
             pvar = ztmp_pvar
             DEALLOCATE(ztmp_pvar)
@@ -1023,5 +1037,5 @@
 
 
-   SUBROUTINE iom_g1d_dp( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, ldxios )
+   SUBROUTINE iom_g1d_dp( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
       INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
       INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
@@ -1031,14 +1045,12 @@
       INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading 
       INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
-      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_r1d=pvar,   &
-              &                                                     ktime=ktime, kstart=kstart, kcount=kcount, &
-              &                                                     ldxios=ldxios )
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount)
       ENDIF
    END SUBROUTINE iom_g1d_dp
 
-   SUBROUTINE iom_g2d_sp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios)
+   SUBROUTINE iom_g2d_sp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount)
       INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
       INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
@@ -1052,5 +1064,4 @@
       INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kstart    ! start axis position of the reading 
       INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kcount    ! number of points in each axis
-      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS
       !
       IF( kiomid > 0 ) THEN
@@ -1059,5 +1070,5 @@
             CALL iom_get_123d( kiomid, kdom, cdvar      , pv_r2d = ztmp_pvar  , ktime = ktime,   &
              &                                                      cd_type = cd_type, psgn   = psgn  , kfill = kfill,   &
-             &                                                      kstart  = kstart , kcount = kcount, ldxios=ldxios  )
+             &                                                      kstart  = kstart , kcount = kcount  )
             pvar = ztmp_pvar
             DEALLOCATE(ztmp_pvar)
@@ -1066,5 +1077,5 @@
    END SUBROUTINE iom_g2d_sp
 
-   SUBROUTINE iom_g2d_dp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios)
+   SUBROUTINE iom_g2d_dp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount)
       INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
       INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
@@ -1077,14 +1088,13 @@
       INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kstart    ! start axis position of the reading 
       INTEGER         , INTENT(in   ), DIMENSION(2), OPTIONAL ::   kcount    ! number of points in each axis
-      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_r2d = pvar  , ktime = ktime,   &
             &                                                       cd_type = cd_type, psgn   = psgn  , kfill = kfill,   &
-            &                                                       kstart  = kstart , kcount = kcount, ldxios=ldxios  )
+            &                                                       kstart  = kstart , kcount = kcount                )
       ENDIF
    END SUBROUTINE iom_g2d_dp
 
-   SUBROUTINE iom_g3d_sp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios )
+   SUBROUTINE iom_g3d_sp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount )
       INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
       INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
@@ -1098,5 +1108,4 @@
       INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kstart    ! start axis position of the reading 
       INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kcount    ! number of points in each axis
-      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS
       !
       IF( kiomid > 0 ) THEN
@@ -1105,5 +1114,5 @@
             CALL iom_get_123d( kiomid, kdom, cdvar      , pv_r3d = ztmp_pvar  , ktime = ktime,   &
             &                                                       cd_type = cd_type, psgn   = psgn  , kfill = kfill,   &
-            &                                                       kstart  = kstart , kcount = kcount, ldxios=ldxios  )
+            &                                                       kstart  = kstart , kcount = kcount                )
             pvar = ztmp_pvar
             DEALLOCATE(ztmp_pvar)
@@ -1112,5 +1121,5 @@
    END SUBROUTINE iom_g3d_sp
 
-   SUBROUTINE iom_g3d_dp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount, ldxios )
+   SUBROUTINE iom_g3d_dp( kiomid, kdom, cdvar, pvar, ktime, cd_type, psgn, kfill, kstart, kcount )
       INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
       INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
@@ -1123,5 +1132,4 @@
       INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kstart    ! start axis position of the reading 
       INTEGER         , INTENT(in   ), DIMENSION(3), OPTIONAL ::   kcount    ! number of points in each axis
-      LOGICAL         , INTENT(in   ),               OPTIONAL ::   ldxios    ! read data using XIOS
       !
       IF( kiomid > 0 ) THEN
@@ -1129,5 +1137,5 @@
             CALL iom_get_123d( kiomid, kdom, cdvar      , pv_r3d = pvar  , ktime = ktime,   &
             &                                                       cd_type = cd_type, psgn   = psgn  , kfill = kfill,   &
-            &                                                       kstart  = kstart , kcount = kcount, ldxios=ldxios  )
+            &                                                       kstart  = kstart , kcount = kcount                )
          END IF
       ENDIF
@@ -1137,5 +1145,5 @@
 
    SUBROUTINE iom_get_123d( kiomid , kdom, cdvar, pv_r1d, pv_r2d, pv_r3d, ktime ,   &
-         &                  cd_type, psgn, kfill, kstart, kcount, ldxios )
+         &                  cd_type, psgn, kfill, kstart, kcount )
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_get_123d  ***
@@ -1157,8 +1165,6 @@
       INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart    ! start position of the reading in each axis 
       INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount    ! number of points to be read in each axis
-      LOGICAL                    , INTENT(in   ), OPTIONAL ::   ldxios    ! use XIOS to read restart
       !
       LOGICAL                        ::   llok        ! true if ok!
-      LOGICAL                        ::   llxios      ! local definition for XIOS read
       INTEGER                        ::   jl          ! loop on number of dimension 
       INTEGER                        ::   idom        ! type of domain
@@ -1187,15 +1193,14 @@
       REAL(dp)                       ::   gma, gmi
       !---------------------------------------------------------------------
-      !
+      CHARACTER(LEN=lc)                               ::   context
+      !
+      CALL set_xios_context(kiomid, context)
       inlev = -1
       IF( PRESENT(pv_r3d) )   inlev = SIZE(pv_r3d, 3)
       !
-      llxios = .FALSE.
-      IF( PRESENT(ldxios) )   llxios = ldxios
-      !
       idom = kdom
       istop = nstop
       !
-      IF(.NOT.llxios) THEN
+      IF(context == "NONE") THEN
          clname = iom_file(kiomid)%name   !   esier to read
          clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
@@ -1364,18 +1369,28 @@
 #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) ) 
+         idvar = iom_varid( kiomid, cdvar )
+         CALL iom_swap(context)
+         zsgn = 1._wp
+         IF( PRESENT(psgn   ) )   zsgn    = psgn
+         cl_type = 'T'
+         IF( PRESENT(cd_type) )   cl_type = cd_type
+
          IF( PRESENT(pv_r3d) ) THEN
             IF(lwp) WRITE(numout,*) 'XIOS RST READ (3D): ',TRIM(cdvar)
-            CALL xios_recv_field( trim(cdvar), pv_r3d)
-            IF(idom /= jpdom_unknown )   CALL lbc_lnk( 'iom', pv_r3d,'Z', -999., kfillmode = jpfillnothing)
+            CALL xios_recv_field( trim(cdvar), pv_r3d(:, :, :))
+            IF(idom /= jpdom_unknown .AND. cl_type /= 'Z' ) THEN
+               CALL lbc_lnk( 'iom', pv_r3d, cl_type, zsgn, kfillmode = kfill)
+            ENDIF
          ELSEIF( PRESENT(pv_r2d) ) THEN
             IF(lwp) WRITE(numout,*) 'XIOS RST READ (2D): ', TRIM(cdvar)
-            CALL xios_recv_field( trim(cdvar), pv_r2d)
-            IF(idom /= jpdom_unknown )   CALL lbc_lnk('iom', pv_r2d,'Z',-999., kfillmode = jpfillnothing)
+            CALL xios_recv_field( trim(cdvar), pv_r2d(:, :))
+            IF(idom /= jpdom_unknown .AND. cl_type /= 'Z' ) THEN
+               CALL lbc_lnk('iom', pv_r2d, cl_type, zsgn, kfillmode = kfill)
+            ENDIF
          ELSEIF( PRESENT(pv_r1d) ) THEN
             IF(lwp) WRITE(numout,*) 'XIOS RST READ (1D): ', TRIM(cdvar)
             CALL xios_recv_field( trim(cdvar), pv_r1d)
          ENDIF
-         CALL iom_swap( TRIM(cxios_context) )
+         CALL iom_swap(cxios_context)
 #else
          istop = istop + 1 
@@ -1392,12 +1407,12 @@
       zofs = iom_file(kiomid)%ofs(idvar)      ! offset
       IF(     PRESENT(pv_r1d) ) THEN
-         IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
-         IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
+         IF( zscf /= 1._wp )   pv_r1d(:) = pv_r1d(:) * zscf 
+         IF( zofs /= 0._wp )   pv_r1d(:) = pv_r1d(:) + zofs
       ELSEIF( PRESENT(pv_r2d) ) THEN
-         IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
-         IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
+         IF( zscf /= 1._wp)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
+         IF( zofs /= 0._wp)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
       ELSEIF( PRESENT(pv_r3d) ) THEN
-         IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
-         IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
+         IF( zscf /= 1._wp)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
+         IF( zofs /= 0._wp)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
       ENDIF
       !
@@ -1573,5 +1588,5 @@
    !!                   INTERFACE iom_rstput
    !!----------------------------------------------------------------------
-   SUBROUTINE iom_rp0d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
+   SUBROUTINE iom_rp0d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype )
       INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
       INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
@@ -1580,16 +1595,26 @@
       REAL(sp)        , INTENT(in)                         ::   pvar     ! written field
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
-      LOGICAL :: llx                ! local xios write flag
-      INTEGER :: ivid   ! variable id
-
-      llx = .FALSE.
-      IF(PRESENT(ldxios)) llx = ldxios
+      !
+      LOGICAL           :: llx                ! local xios write flag
+      INTEGER           :: ivid   ! variable id
+      CHARACTER(LEN=lc) :: context
+      !
+      CALL set_xios_context(kiomid, context)
+
+      llx = .NOT. (context == "NONE")
+
       IF( llx ) THEN
 #ifdef key_iomput
-      IF( kt == kwrite ) THEN
-          IF(lwp) write(numout,*) 'RESTART: write (XIOS 0D) ',trim(cdvar)
-          CALL xios_send_field(trim(cdvar), pvar)
-      ENDIF
+         IF( kt == kwrite ) THEN
+            IF(lwp) write(numout,*) 'RESTART: write (XIOS 0D) ',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_put(trim(cdvar), pvar)
+            CALL iom_swap(cxios_context)
+         ELSE
+            IF(lwp) write(numout,*) 'RESTART: define (XIOS 0D) ',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_set_rstw_active( trim(cdvar), rs0 = pvar ) 
+            CALL iom_swap(cxios_context)
+         ENDIF
 #endif
       ELSE
@@ -1603,5 +1628,5 @@
    END SUBROUTINE iom_rp0d_sp
 
-   SUBROUTINE iom_rp0d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
+   SUBROUTINE iom_rp0d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype )
       INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
       INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
@@ -1610,16 +1635,26 @@
       REAL(dp)        , INTENT(in)                         ::   pvar     ! written field
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
-      LOGICAL :: llx                ! local xios write flag
-      INTEGER :: ivid   ! variable id
-
-      llx = .FALSE.
-      IF(PRESENT(ldxios)) llx = ldxios
+      !
+      LOGICAL           :: llx                ! local xios write flag
+      INTEGER           :: ivid   ! variable id
+      CHARACTER(LEN=lc) :: context
+      !
+      CALL set_xios_context(kiomid, context)
+
+      llx = .NOT. (context == "NONE")
+
       IF( llx ) THEN
 #ifdef key_iomput
-      IF( kt == kwrite ) THEN
-          IF(lwp) write(numout,*) 'RESTART: write (XIOS 0D) ',trim(cdvar)
-          CALL xios_send_field(trim(cdvar), pvar)
-      ENDIF
+         IF( kt == kwrite ) THEN
+            IF(lwp) write(numout,*) 'RESTART: write (XIOS 0D) ',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_put(trim(cdvar), pvar)
+            CALL iom_swap(cxios_context)
+         ELSE
+            IF(lwp) write(numout,*) 'RESTART: define (XIOS 0D) ',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_set_rstw_active( trim(cdvar), rd0 = pvar ) 
+            CALL iom_swap(cxios_context)
+         ENDIF
 #endif
       ELSE
@@ -1634,5 +1669,5 @@
 
 
-   SUBROUTINE iom_rp1d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
+   SUBROUTINE iom_rp1d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype )
       INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
       INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
@@ -1641,16 +1676,26 @@
       REAL(sp)        , INTENT(in), DIMENSION(          :) ::   pvar     ! written field
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      LOGICAL, OPTIONAL                                    ::   ldxios   ! xios write flag
-      LOGICAL :: llx                ! local xios write flag
-      INTEGER :: ivid   ! variable id
-
-      llx = .FALSE.
-      IF(PRESENT(ldxios)) llx = ldxios
+      !
+      LOGICAL           :: llx                ! local xios write flag
+      INTEGER           :: ivid   ! variable id
+      CHARACTER(LEN=lc) :: context
+      !
+      CALL set_xios_context(kiomid, context)
+
+      llx = .NOT. (context == "NONE")
+
       IF( llx ) THEN
 #ifdef key_iomput
-      IF( kt == kwrite ) THEN
-         IF(lwp) write(numout,*) 'RESTART: write (XIOS 1D) ',trim(cdvar)
-         CALL xios_send_field(trim(cdvar), pvar)
-      ENDIF
+         IF( kt == kwrite ) THEN
+            IF(lwp) write(numout,*) 'RESTART: write (XIOS 1D) ',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_put(trim(cdvar), pvar)
+            CALL iom_swap(cxios_context)
+         ELSE
+            IF(lwp) write(numout,*) 'RESTART: define (XIOS 1D)',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_set_rstw_active( trim(cdvar), rs1 = pvar )
+            CALL iom_swap(cxios_context)
+         ENDIF
 #endif
       ELSE
@@ -1664,5 +1709,5 @@
    END SUBROUTINE iom_rp1d_sp
 
-   SUBROUTINE iom_rp1d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
+   SUBROUTINE iom_rp1d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype )
       INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
       INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
@@ -1671,16 +1716,26 @@
       REAL(dp)        , INTENT(in), DIMENSION(          :) ::   pvar     ! written field
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      LOGICAL, OPTIONAL                                    ::   ldxios   ! xios write flag
-      LOGICAL :: llx                ! local xios write flag
-      INTEGER :: ivid   ! variable id
-
-      llx = .FALSE.
-      IF(PRESENT(ldxios)) llx = ldxios
+      !
+      LOGICAL           :: llx                ! local xios write flag
+      INTEGER           :: ivid   ! variable id
+      CHARACTER(LEN=lc) :: context
+      !
+      CALL set_xios_context(kiomid, context)
+
+      llx = .NOT. (context == "NONE")
+
       IF( llx ) THEN
 #ifdef key_iomput
-      IF( kt == kwrite ) THEN
-         IF(lwp) write(numout,*) 'RESTART: write (XIOS 1D) ',trim(cdvar)
-         CALL xios_send_field(trim(cdvar), pvar)
-      ENDIF
+         IF( kt == kwrite ) THEN
+            IF(lwp) write(numout,*) 'RESTART: write (XIOS 1D) ',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_put(trim(cdvar), pvar)
+            CALL iom_swap(cxios_context)
+         ELSE
+            IF(lwp) write(numout,*) 'RESTART: define (XIOS 1D)',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_set_rstw_active( trim(cdvar), rd1 = pvar )
+            CALL iom_swap(cxios_context)
+         ENDIF
 #endif
       ELSE
@@ -1695,5 +1750,5 @@
 
 
-   SUBROUTINE iom_rp2d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
+   SUBROUTINE iom_rp2d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype )
       INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
       INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
@@ -1702,16 +1757,26 @@
       REAL(sp)        , INTENT(in), DIMENSION(:,    :    ) ::   pvar     ! written field
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
-      LOGICAL :: llx
-      INTEGER :: ivid   ! variable id
-
-      llx = .FALSE.
-      IF(PRESENT(ldxios)) llx = ldxios
+      !
+      LOGICAL            :: llx
+      INTEGER            :: ivid   ! variable id
+      CHARACTER(LEN=lc)  :: context
+      !
+      CALL set_xios_context(kiomid, context)
+
+      llx = .NOT. (context == "NONE")
+
       IF( llx ) THEN
 #ifdef key_iomput
-      IF( kt == kwrite ) THEN
-         IF(lwp) write(numout,*) 'RESTART: write (XIOS 2D) ',trim(cdvar)
-         CALL xios_send_field(trim(cdvar), pvar)
-      ENDIF
+         IF( kt == kwrite ) THEN
+            IF(lwp) write(numout,*) 'RESTART: write (XIOS 2D) ',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_put(trim(cdvar), pvar)
+            CALL iom_swap(cxios_context)
+         ELSE
+            IF(lwp) write(numout,*) 'RESTART: define (XIOS 2D)',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_set_rstw_active( trim(cdvar), rs2 = pvar )
+            CALL iom_swap(cxios_context)
+         ENDIF
 #endif
       ELSE
@@ -1725,5 +1790,5 @@
    END SUBROUTINE iom_rp2d_sp
 
-   SUBROUTINE iom_rp2d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
+   SUBROUTINE iom_rp2d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype )
       INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
       INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
@@ -1732,16 +1797,26 @@
       REAL(dp)        , INTENT(in), DIMENSION(:,    :    ) ::   pvar     ! written field
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
-      LOGICAL :: llx
-      INTEGER :: ivid   ! variable id
-
-      llx = .FALSE.
-      IF(PRESENT(ldxios)) llx = ldxios
+      !
+      LOGICAL           :: llx
+      INTEGER           :: ivid   ! variable id
+      CHARACTER(LEN=lc) :: context
+      !
+      CALL set_xios_context(kiomid, context)
+
+      llx = .NOT. (context == "NONE")
+
       IF( llx ) THEN
 #ifdef key_iomput
-      IF( kt == kwrite ) THEN
-         IF(lwp) write(numout,*) 'RESTART: write (XIOS 2D) ',trim(cdvar)
-         CALL xios_send_field(trim(cdvar), pvar)
-      ENDIF
+         IF( kt == kwrite ) THEN
+            IF(lwp) write(numout,*) 'RESTART: write (XIOS 2D) ',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_put(trim(cdvar), pvar)
+            CALL iom_swap(cxios_context)
+         ELSE
+            IF(lwp) write(numout,*) 'RESTART: define (XIOS 2D)',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_set_rstw_active( trim(cdvar), rd2 = pvar )
+            CALL iom_swap(cxios_context)
+         ENDIF
 #endif
       ELSE
@@ -1756,5 +1831,5 @@
 
 
-   SUBROUTINE iom_rp3d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
+   SUBROUTINE iom_rp3d_sp( kt, kwrite, kiomid, cdvar, pvar, ktype )
       INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
       INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
@@ -1763,16 +1838,26 @@
       REAL(sp)        , INTENT(in),       DIMENSION(:,:,:) ::   pvar     ! written field
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
-      LOGICAL :: llx                 ! local xios write flag
-      INTEGER :: ivid   ! variable id
-
-      llx = .FALSE.
-      IF(PRESENT(ldxios)) llx = ldxios
+      !
+      LOGICAL           :: llx                 ! local xios write flag
+      INTEGER           :: ivid   ! variable id
+      CHARACTER(LEN=lc) :: context
+      !
+      CALL set_xios_context(kiomid, context)
+
+      llx = .NOT. (context == "NONE")
+
       IF( llx ) THEN
 #ifdef key_iomput
-      IF( kt == kwrite ) THEN
-         IF(lwp) write(numout,*) 'RESTART: write (XIOS 3D) ',trim(cdvar)
-         CALL xios_send_field(trim(cdvar), pvar)
-      ENDIF
+         IF( kt == kwrite ) THEN
+            IF(lwp) write(numout,*) 'RESTART: write (XIOS 3D) ',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_put(trim(cdvar), pvar)
+            CALL iom_swap(cxios_context)
+         ELSE
+            IF(lwp) write(numout,*) 'RESTART: define (XIOS 3D)',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_set_rstw_active( trim(cdvar), rs3 = pvar )
+            CALL iom_swap(cxios_context)
+         ENDIF
 #endif
       ELSE
@@ -1786,5 +1871,5 @@
    END SUBROUTINE iom_rp3d_sp
 
-   SUBROUTINE iom_rp3d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
+   SUBROUTINE iom_rp3d_dp( kt, kwrite, kiomid, cdvar, pvar, ktype )
       INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
       INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
@@ -1793,16 +1878,26 @@
       REAL(dp)        , INTENT(in),       DIMENSION(:,:,:) ::   pvar     ! written field
       INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
-      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
-      LOGICAL :: llx                 ! local xios write flag
-      INTEGER :: ivid   ! variable id
-
-      llx = .FALSE.
-      IF(PRESENT(ldxios)) llx = ldxios
+      !
+      LOGICAL           :: llx                 ! local xios write flag
+      INTEGER           :: ivid   ! variable id
+      CHARACTER(LEN=lc) :: context
+      !
+      CALL set_xios_context(kiomid, context)
+
+      llx = .NOT. (context == "NONE")
+
       IF( llx ) THEN
 #ifdef key_iomput
-      IF( kt == kwrite ) THEN
-         IF(lwp) write(numout,*) 'RESTART: write (XIOS 3D) ',trim(cdvar)
-         CALL xios_send_field(trim(cdvar), pvar)
-      ENDIF
+         IF( kt == kwrite ) THEN
+            IF(lwp) write(numout,*) 'RESTART: write (XIOS 3D) ',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_put(trim(cdvar), pvar)
+            CALL iom_swap(cxios_context)
+         ELSE
+            IF(lwp) write(numout,*) 'RESTART: define (XIOS 3D)',trim(cdvar)
+            CALL iom_swap(context)
+            CALL iom_set_rstw_active( trim(cdvar), rd3 = pvar )
+            CALL iom_swap(cxios_context)
+         ENDIF
 #endif
       ELSE
@@ -2150,5 +2245,5 @@
       CALL iom_swap( cdname )   ! swap to cdname context
       CALL xios_update_calendar(kt)
-      IF( cdname /= TRIM(cxios_context) )   CALL iom_swap( TRIM(cxios_context) )   ! return back to nemo context
+      IF( cdname /= TRIM(cxios_context) )   CALL iom_swap( cxios_context )   ! return back to nemo context
    END SUBROUTINE iom_setkt
 
@@ -2164,5 +2259,5 @@
          CALL iom_swap( cdname )   ! swap to cdname context
          CALL xios_context_finalize() ! finalize the context
-         IF( cdname /= TRIM(cxios_context) ) CALL iom_swap( TRIM(cxios_context) )   ! return back to nemo context
+         IF( cdname /= cxios_context ) CALL iom_swap( cxios_context )   ! return back to nemo context
       ENDIF
       !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/iom_def.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/iom_def.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/iom_def.F90	(revision 14018)
@@ -9,4 +9,5 @@
    !!----------------------------------------------------------------------
    USE par_kind
+   USE netcdf
 
    IMPLICIT NONE
@@ -36,7 +37,8 @@
    INTEGER, PUBLIC            ::   nxioso = 0          !: type of restart file when writing using XIOS 1 - single, 2 - multiple
 !XIOS read restart   
-   LOGICAL, PUBLIC            ::   lrxios = .FALSE.     !: read single file restart using XIOS
+   LOGICAL, PUBLIC            ::   lrxios = .FALSE.     !: read single file restart using XIOS main switch
    LOGICAL, PUBLIC            ::   lxios_sini = .FALSE. ! is restart in a single file
-   LOGICAL, PUBLIC            ::   lxios_set  = .FALSE. 
+
+
 
    TYPE, PUBLIC ::   file_descriptor
@@ -59,13 +61,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
-   TYPE, PUBLIC :: RST_FIELD  
-    CHARACTER(len=30) :: vname = "NO_NAME" ! names of variables in restart file
-    CHARACTER(len=30) :: grid = "NO_GRID"
-    LOGICAL           :: active =.FALSE. ! for restart write only: true - write field, false do not write field
-   END TYPE RST_FIELD
 !$AGRIF_END_DO_NOT_TREAT
-   !
-   TYPE(RST_FIELD), PUBLIC, SAVE :: rst_wfields(max_rst_fields), rst_rfields(max_rst_fields)
    !
    !! * Substitutions
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/iom_nf90.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/iom_nf90.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/iom_nf90.F90	(revision 14018)
@@ -31,4 +31,5 @@
    PUBLIC iom_nf90_open  , iom_nf90_close, iom_nf90_varid, iom_nf90_get, iom_nf90_rstput
    PUBLIC iom_nf90_chkatt, iom_nf90_getatt, iom_nf90_putatt
+   PUBLIC iom_nf90_check
 
    INTERFACE iom_nf90_get
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/restart.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/restart.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/restart.F90	(revision 14018)
@@ -111,5 +111,5 @@
             ELSE
 #if defined key_iomput
-               cwxios_context = "rstw_"//TRIM(ADJUSTL(clkt))
+               cw_ocerst_cxt = "rstw_"//TRIM(ADJUSTL(clkt))
                IF( TRIM(Agrif_CFixed()) == '0' ) THEN
                   clpname = clname
@@ -117,6 +117,6 @@
                   clpname = TRIM(Agrif_CFixed())//"_"//clname   
                ENDIF
-               CALL iom_init( cwxios_context, TRIM(clpath)//TRIM(clpname), .false. )
-               CALL xios_update_calendar(nitrst)
+               numrow = iom_xios_setid(TRIM(clpath)//TRIM(clpname))
+               CALL iom_init( cw_ocerst_cxt, kdid = numrow, ld_closedef = .false. )
                CALL iom_swap(      cxios_context          )
 #else
@@ -147,30 +147,30 @@
       INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
       !!----------------------------------------------------------------------
-                     IF(lwxios) CALL iom_swap(      cwxios_context          )
-                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rn_Dt       , ldxios = lwxios)   ! dynamics time step
-                     CALL iom_delay_rst( 'WRITE', 'OCE', numrow )   ! save only ocean delayed global communication variables
+                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rn_Dt       )   ! dynamics time step
+                     IF(.NOT.lwxios) CALL iom_delay_rst( 'WRITE', 'OCE', numrow )   ! save only ocean delayed global communication variables
 
       IF ( .NOT. ln_diurnal_only ) THEN
-                     CALL iom_rstput( kt, nitrst, numrow, 'ub'     , uu(:,:,:       ,Kbb), ldxios = lwxios        )     ! before fields
-                     CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vv(:,:,:       ,Kbb), ldxios = lwxios        )
-                     CALL iom_rstput( kt, nitrst, numrow, 'tb'     , ts(:,:,:,jp_tem,Kbb), ldxios = lwxios )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sb'     , ts(:,:,:,jp_sal,Kbb), ldxios = lwxios )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sshb'   ,ssh(:,:         ,Kbb), ldxios = lwxios      )
+                     CALL iom_rstput( kt, nitrst, numrow, 'ub'     , uu(:,:,:       ,Kbb) )     ! before fields
+                     CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vv(:,:,:       ,Kbb) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'tb'     , ts(:,:,:,jp_tem,Kbb) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'sb'     , ts(:,:,:,jp_sal,Kbb) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , ssh(:,:         ,Kbb))
                      !
-                     CALL iom_rstput( kt, nitrst, numrow, 'un'     , uu(:,:,:       ,Kmm), ldxios = lwxios        )     ! now fields
-                     CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vv(:,:,:       ,Kmm), ldxios = lwxios        )
-                     CALL iom_rstput( kt, nitrst, numrow, 'tn'     , ts(:,:,:,jp_tem,Kmm), ldxios = lwxios )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sn'     , ts(:,:,:,jp_sal,Kmm), ldxios = lwxios )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sshn'   ,ssh(:,:         ,Kmm), ldxios = lwxios      )
-                     CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop, ldxios = lwxios      )
+                     CALL iom_rstput( kt, nitrst, numrow, 'un'     , uu(:,:,:       ,Kmm) )     ! now fields
+                     CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vv(:,:,:       ,Kmm) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'tn'     , ts(:,:,:,jp_tem,Kmm) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'sn'     , ts(:,:,:,jp_sal,Kmm) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'sshn'   , ssh(:,:         ,Kmm))
+                     CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop      )
       ENDIF
       
-      IF (ln_diurnal) CALL iom_rstput( kt, nitrst, numrow, 'Dsst', x_dsst, ldxios = lwxios )  
-      IF(lwxios) CALL iom_swap(      cxios_context          )
+      IF (ln_diurnal) CALL iom_rstput( kt, nitrst, numrow, 'Dsst', x_dsst )  
       IF( kt == nitrst ) THEN
          IF(.NOT.lwxios) THEN
             CALL iom_close( numrow )     ! close the restart file (only at last time step)
          ELSE
-            CALL iom_context_finalize(      cwxios_context          )
+            CALL iom_context_finalize(      cw_ocerst_cxt          )
+            iom_file(numrow)%nfid       = 0
+            numrow = 0
          ENDIF
 !!gm         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
@@ -195,6 +195,7 @@
       !!                the file has already been opened
       !!----------------------------------------------------------------------
-      LOGICAL        ::   llok
-      CHARACTER(lc)  ::   clpath   ! full path to ocean output restart file
+      LOGICAL             ::   llok
+      CHARACTER(len=lc)   ::   clpath   ! full path to ocean output restart file
+      CHARACTER(len=lc+2) ::   clpname  ! file name including agrif prefix
       !!----------------------------------------------------------------------
       !
@@ -213,18 +214,18 @@
 ! can handle checking if variable is in the restart file (there will be no need to open
 ! restart)
-         IF( .NOT.lxios_set )   lrxios = lrxios.AND.lxios_sini
-         IF( lrxios ) THEN
-             crxios_context = 'nemo_rst'
-             IF( .NOT.lxios_set ) THEN
-                 IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS'
-                 CALL iom_init( crxios_context )
-                 lxios_set = .TRUE.
-             ENDIF
-         ENDIF
-         IF( TRIM(Agrif_CFixed()) /= '0' .AND. lrxios ) THEN
-             CALL iom_init( crxios_context )
-             IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for AGRIF'
-             lxios_set = .TRUE.
-         ENDIF 
+         lrxios = lrxios.AND.lxios_sini
+
+         IF( lrxios) THEN
+             cr_ocerst_cxt = 'oce_rst'
+             IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS'
+!            IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+!               clpname = cn_ocerst_in
+!            ELSE
+!               clpname = TRIM(Agrif_CFixed())//"_"//cn_ocerst_in   
+!            ENDIF
+             CALL iom_init( cr_ocerst_cxt, kdid = numror, ld_closedef = .TRUE. )
+             CALL iom_swap(      cxios_context          )
+         ENDIF
+
       ENDIF
 
@@ -252,13 +253,13 @@
       !!----------------------------------------------------------------------
       !
-      CALL iom_delay_rst( 'READ', 'OCE', numror )   ! read only ocean delayed global communication variables
+      IF(.NOT.lrxios ) CALL iom_delay_rst( 'READ', 'OCE', numror )   ! read only ocean delayed global communication variables
       !
       !                             !*  Diurnal DSST 
-      IF( ln_diurnal )   CALL iom_get( numror, jpdom_auto, 'Dsst' , x_dsst, ldxios = lrxios ) 
+      IF( ln_diurnal )   CALL iom_get( numror, jpdom_auto, 'Dsst' , x_dsst ) 
       IF ( ln_diurnal_only ) THEN 
          IF(lwp) WRITE( numout, * ) &
          &   "rst_read:- ln_diurnal_only set, setting rhop=rho0" 
          rhop = rho0
-         CALL iom_get( numror, jpdom_auto, 'tn'     , w3d, ldxios = lrxios ) 
+         CALL iom_get( numror, jpdom_auto, 'tn'     , w3d ) 
          ts(:,:,1,jp_tem,Kmm) = w3d(:,:,1)
          RETURN 
@@ -267,8 +268,8 @@
       !                             !*  Read Kmm fields
       IF(lwp) WRITE(numout,*)    '           Kmm u, v and T-S fields read in the restart file'
-      CALL iom_get( numror, jpdom_auto, 'un'     , uu(:,:,:       ,Kmm), ldxios = lrxios, cd_type = 'U', psgn = -1._wp )
-      CALL iom_get( numror, jpdom_auto, 'vn'     , vv(:,:,:       ,Kmm), ldxios = lrxios, cd_type = 'V', psgn = -1._wp )
-      CALL iom_get( numror, jpdom_auto, 'tn'     , ts(:,:,:,jp_tem,Kmm), ldxios = lrxios )
-      CALL iom_get( numror, jpdom_auto, 'sn'     , ts(:,:,:,jp_sal,Kmm), ldxios = lrxios )
+      CALL iom_get( numror, jpdom_auto, 'un'     , uu(:,:,:       ,Kmm), cd_type = 'U', psgn = -1._wp )
+      CALL iom_get( numror, jpdom_auto, 'vn'     , vv(:,:,:       ,Kmm), cd_type = 'V', psgn = -1._wp )
+      CALL iom_get( numror, jpdom_auto, 'tn'     , ts(:,:,:,jp_tem,Kmm) )
+      CALL iom_get( numror, jpdom_auto, 'sn'     , ts(:,:,:,jp_sal,Kmm) )
       !
       IF( l_1st_euler ) THEN        !*  Euler restart
@@ -279,12 +280,12 @@
       ELSE                          !* Leap frog restart
          IF(lwp) WRITE(numout,*) '           Kbb u, v and T-S fields read in the restart file'
-         CALL iom_get( numror, jpdom_auto, 'ub'     , uu(:,:,:       ,Kbb), ldxios = lrxios, cd_type = 'U', psgn = -1._wp )
-         CALL iom_get( numror, jpdom_auto, 'vb'     , vv(:,:,:       ,Kbb), ldxios = lrxios, cd_type = 'V', psgn = -1._wp )
-         CALL iom_get( numror, jpdom_auto, 'tb'     , ts(:,:,:,jp_tem,Kbb), ldxios = lrxios )
-         CALL iom_get( numror, jpdom_auto, 'sb'     , ts(:,:,:,jp_sal,Kbb), ldxios = lrxios )
+         CALL iom_get( numror, jpdom_auto, 'ub'     , uu(:,:,:       ,Kbb), cd_type = 'U', psgn = -1._wp )
+         CALL iom_get( numror, jpdom_auto, 'vb'     , vv(:,:,:       ,Kbb), cd_type = 'V', psgn = -1._wp )
+         CALL iom_get( numror, jpdom_auto, 'tb'     , ts(:,:,:,jp_tem,Kbb) )
+         CALL iom_get( numror, jpdom_auto, 'sb'     , ts(:,:,:,jp_sal,Kbb) )
       ENDIF
       !
       IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN
-         CALL iom_get( numror, jpdom_auto, 'rhop'   , rhop, ldxios = lrxios )   ! now    potential density
+         CALL iom_get( numror, jpdom_auto, 'rhop'   , rhop )   ! now    potential density
       ELSE
          CALL eos( ts(:,:,:,:,Kmm), rhd, rhop, gdept(:,:,:,Kmm) )   
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ISF/isfcav.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ISF/isfcav.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ISF/isfcav.F90	(revision 14018)
@@ -183,7 +183,10 @@
       ! cavity mask
       mskisf_cav(:,:)    = (1._wp - tmask(:,:,1)) * ssmask(:,:)
-      !
-      !================
-      ! 2: read restart
+      !================
+      ! 2: activate restart
+      !================
+      !
+      !================
+      ! 3: read restart
       !================
       !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ISF/isfcpl.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ISF/isfcpl.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ISF/isfcpl.F90	(revision 14018)
@@ -120,13 +120,4 @@
       e3t(:,:,:,Kbb)   = e3t(:,:,:,Kmm)
 #endif 
-      ! prepare writing restart
-      IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active('ssmask')
-         CALL iom_set_rstw_var_active('tmask')
-         CALL iom_set_rstw_var_active('e3t_n')
-         CALL iom_set_rstw_var_active('e3u_n')
-         CALL iom_set_rstw_var_active('e3v_n')
-      END IF
-      !
    END SUBROUTINE isfcpl_init
 
@@ -154,12 +145,10 @@
       END DO 
       !
-      IF( lwxios ) CALL iom_swap( cwxios_context )
-      CALL iom_rstput( kt, nitrst, numrow, 'tmask'  , tmask , ldxios = lwxios )
-      CALL iom_rstput( kt, nitrst, numrow, 'ssmask' , ssmask, ldxios = lwxios )
-      CALL iom_rstput( kt, nitrst, numrow, 'e3t_n'  , ze3t , ldxios = lwxios )
-      CALL iom_rstput( kt, nitrst, numrow, 'e3u_n'  , ze3u , ldxios = lwxios )
-      CALL iom_rstput( kt, nitrst, numrow, 'e3v_n'  , ze3v , ldxios = lwxios )
-      CALL iom_rstput( kt, nitrst, numrow, 'gdepw_n', zgdepw , ldxios = lwxios )
-      IF( lwxios ) CALL iom_swap( cxios_context )
+      CALL iom_rstput( kt, nitrst, numrow, 'tmask'  , tmask  )
+      CALL iom_rstput( kt, nitrst, numrow, 'ssmask' , ssmask )
+      CALL iom_rstput( kt, nitrst, numrow, 'e3t_n'  , ze3t   )
+      CALL iom_rstput( kt, nitrst, numrow, 'e3u_n'  , ze3u   )
+      CALL iom_rstput( kt, nitrst, numrow, 'e3v_n'  , ze3v   )
+      CALL iom_rstput( kt, nitrst, numrow, 'gdepw_n', zgdepw )
       !
    END SUBROUTINE isfcpl_rst_write
@@ -185,5 +174,5 @@
       !!----------------------------------------------------------------------
       !
-      CALL iom_get( numror, jpdom_auto, 'ssmask'  , zssmask_b, ldxios = lrxios   ) ! need to extrapolate T/S
+      CALL iom_get( numror, jpdom_auto, 'ssmask'  , zssmask_b   ) ! need to extrapolate T/S
 
       ! compute new ssh if we open a full water column 
@@ -267,7 +256,7 @@
       !!----------------------------------------------------------------------
       ! 
-      CALL iom_get( numror, jpdom_auto, 'tmask'  , ztmask_b, ldxios = lrxios   ) ! need to extrapolate T/S
-      !CALL iom_get( numror, jpdom_auto, 'wmask'  , zwmask_b, ldxios = lrxios   ) ! need to extrapolate T/S
-      !CALL iom_get( numror, jpdom_auto, 'gdepw_n', zdepw_b(:,:,:), ldxios = lrxios ) ! need to interpol vertical profile (vvl)
+      CALL iom_get( numror, jpdom_auto, 'tmask'  , ztmask_b   ) ! need to extrapolate T/S
+      !CALL iom_get( numror, jpdom_auto, 'wmask'  , zwmask_b  ) ! need to extrapolate T/S
+      !CALL iom_get( numror, jpdom_auto, 'gdepw_n', zdepw_b(:,:,:) ) ! need to interpol vertical profile (vvl)
       !
       ! 
@@ -414,7 +403,7 @@
       !!----------------------------------------------------------------------
       !
-      CALL iom_get( numror, jpdom_auto, 'tmask'  , ztmask_b, ldxios = lrxios )
-      CALL iom_get( numror, jpdom_auto, 'e3u_n'  , ze3u_b  , ldxios = lrxios )
-      CALL iom_get( numror, jpdom_auto, 'e3v_n'  , ze3v_b  , ldxios = lrxios )
+      CALL iom_get( numror, jpdom_auto, 'tmask'  , ztmask_b )
+      CALL iom_get( numror, jpdom_auto, 'e3u_n'  , ze3u_b   )
+      CALL iom_get( numror, jpdom_auto, 'e3v_n'  , ze3v_b   )
       !
       ! 1.0: compute horizontal volume flux divergence difference before-after coupling
@@ -525,8 +514,8 @@
 
       ! get restart variable
-      CALL iom_get( numror, jpdom_auto, 'tmask'  , ztmask_b(:,:,:), ldxios = lrxios   ) ! need to extrapolate T/S
-      CALL iom_get( numror, jpdom_auto, 'e3t_n'  , ze3t_b(:,:,:)  , ldxios = lrxios )
-      CALL iom_get( numror, jpdom_auto, 'tn'     , zt_b(:,:,:)    , ldxios = lrxios )
-      CALL iom_get( numror, jpdom_auto, 'sn'     , zs_b(:,:,:)    , ldxios = lrxios )
+      CALL iom_get( numror, jpdom_auto, 'tmask'  , ztmask_b(:,:,:) ) ! need to extrapolate T/S
+      CALL iom_get( numror, jpdom_auto, 'e3t_n'  , ze3t_b(:,:,:)   )
+      CALL iom_get( numror, jpdom_auto, 'tn'     , zt_b(:,:,:)     )
+      CALL iom_get( numror, jpdom_auto, 'sn'     , zs_b(:,:,:)     )
 
       ! compute run length
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ISF/isfrst.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ISF/isfrst.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ISF/isfrst.F90	(revision 14018)
@@ -53,16 +53,10 @@
       IF( .NOT.l_1st_euler ) THEN
          IF(lwp) WRITE(numout,*) '          nit000-1 isf tracer content forcing fields read in the restart file'
-         CALL iom_get( numror, jpdom_auto, cfwf_b, pfwf_b(:,:)        , ldxios = lrxios )   ! before ice shelf melt
-         CALL iom_get( numror, jpdom_auto, chc_b , ptsc_b (:,:,jp_tem), ldxios = lrxios )   ! before ice shelf heat flux
-         CALL iom_get( numror, jpdom_auto, csc_b , ptsc_b (:,:,jp_sal), ldxios = lrxios )   ! before ice shelf heat flux
+         CALL iom_get( numror, jpdom_auto, cfwf_b, pfwf_b(:,:)         )   ! before ice shelf melt
+         CALL iom_get( numror, jpdom_auto, chc_b , ptsc_b (:,:,jp_tem) )   ! before ice shelf heat flux
+         CALL iom_get( numror, jpdom_auto, csc_b , ptsc_b (:,:,jp_sal) )   ! before ice shelf heat flux
       ELSE
          pfwf_b(:,:)   = pfwf(:,:)
          ptsc_b(:,:,:) = ptsc(:,:,:)
-      ENDIF
-      !
-      IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active( TRIM(chc_b ) )
-         CALL iom_set_rstw_var_active( TRIM(csc_b ) )
-         CALL iom_set_rstw_var_active( TRIM(cfwf_b) )
       ENDIF
       !
@@ -96,9 +90,7 @@
       !
       ! write restart variable
-      IF( lwxios ) CALL iom_swap( cwxios_context )
-      CALL iom_rstput( kt, nitrst, numrow, cfwf_b, pfwf(:,:)       , ldxios = lwxios )
-      CALL iom_rstput( kt, nitrst, numrow, chc_b , ptsc(:,:,jp_tem), ldxios = lwxios )
-      CALL iom_rstput( kt, nitrst, numrow, csc_b , ptsc(:,:,jp_sal), ldxios = lwxios )
-      IF( lwxios ) CALL iom_swap( cxios_context )
+      CALL iom_rstput( kt, nitrst, numrow, cfwf_b, pfwf(:,:)        )
+      CALL iom_rstput( kt, nitrst, numrow, chc_b , ptsc(:,:,jp_tem) )
+      CALL iom_rstput( kt, nitrst, numrow, csc_b , ptsc(:,:,jp_sal) )
       !
    END SUBROUTINE isfrst_write
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcapr.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcapr.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcapr.F90	(revision 14018)
@@ -65,5 +65,4 @@
       CHARACTER(len=100) ::  cn_dir   ! Root directory for location of ssr files
       TYPE(FLD_N)        ::  sn_apr   ! informations about the fields to be read
-      LOGICAL            ::  lrxios   ! read restart using XIOS?
       !!
       NAMELIST/namsbc_apr/ cn_dir, sn_apr, ln_ref_apr, rn_pref, ln_apr_obc
@@ -108,7 +107,4 @@
             CALL ctl_warn( 'sbc_apr: use inverse barometer ssh at open boundary ONLY requires ln_apr_dyn=T' )
       !
-      IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active('ssh_ibb')
-      ENDIF
    END SUBROUTINE sbc_apr_init
 
@@ -154,5 +150,5 @@
          IF( ln_rstart .AND. .NOT.l_1st_euler ) THEN 
             IF(lwp) WRITE(numout,*) 'sbc_apr:   ssh_ibb read in the restart file'
-            CALL iom_get( numror, jpdom_auto, 'ssh_ibb', ssh_ibb, ldxios = lrxios )   ! before inv. barometer ssh
+            CALL iom_get( numror, jpdom_auto, 'ssh_ibb', ssh_ibb )   ! before inv. barometer ssh
             !
          ELSE                                         !* no restart: set from nit000 values
@@ -167,7 +163,5 @@
          IF(lwp) WRITE(numout,*) 'sbc_apr : ssh_ib written in ocean restart file at it= ', kt,' date= ', ndastp
          IF(lwp) WRITE(numout,*) '~~~~'
-         IF( lwxios ) CALL iom_swap(      cwxios_context          )
-         CALL iom_rstput( kt, nitrst, numrow, 'ssh_ibb' , ssh_ib, ldxios = lwxios )
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
+         CALL iom_rstput( kt, nitrst, numrow, 'ssh_ibb' , ssh_ib )
       ENDIF
       !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcmod.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcmod.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcmod.F90	(revision 14018)
@@ -359,14 +359,4 @@
       IF( ln_wave     )   CALL sbc_wave_init                     ! surface wave initialisation
       !
-      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')
-         ! 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')
-      ENDIF
-
    END SUBROUTINE sbc_init
 
@@ -509,12 +499,12 @@
          IF( ln_rstart .AND. .NOT.l_1st_euler ) THEN            !* Restart: read in restart file
             IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields read in the restart file'
-            CALL iom_get( numror, jpdom_auto, 'utau_b', utau_b, ldxios = lrxios, cd_type = 'U', psgn = -1._wp )   ! i-stress
-            CALL iom_get( numror, jpdom_auto, 'vtau_b', vtau_b, ldxios = lrxios, cd_type = 'V', psgn = -1._wp )   ! j-stress
-            CALL iom_get( numror, jpdom_auto,  'qns_b',  qns_b, ldxios = lrxios                               )   ! non solar heat flux
-            CALL iom_get( numror, jpdom_auto,  'emp_b',  emp_b, ldxios = lrxios                               )   ! freshwater flux
+            CALL iom_get( numror, jpdom_auto, 'utau_b', utau_b )   ! i-stress
+            CALL iom_get( numror, jpdom_auto, 'vtau_b', vtau_b )   ! j-stress
+            CALL iom_get( numror, jpdom_auto,  'qns_b',  qns_b )   ! non solar heat flux
+            CALL iom_get( numror, jpdom_auto,  'emp_b',  emp_b )   ! freshwater flux
             ! NB: The 3D heat content due to qsr forcing (qsr_hc_b) is treated in traqsr
             ! To ensure restart capability with 3.3x/3.4 restart files    !! to be removed in v3.6
             IF( iom_varid( numror, 'sfx_b', ldstop = .FALSE. ) > 0 ) THEN
-               CALL iom_get( numror, jpdom_auto, 'sfx_b', sfx_b, ldxios = lrxios )  ! before salt flux (T-point)
+               CALL iom_get( numror, jpdom_auto, 'sfx_b', sfx_b )  ! before salt flux (T-point)
             ELSE
                sfx_b (:,:) = sfx(:,:)
@@ -536,13 +526,11 @@
             &                    'at it= ', kt,' date= ', ndastp
          IF(lwp) WRITE(numout,*) '~~~~'
-         IF( lwxios ) CALL iom_swap(      cwxios_context          )
-         CALL iom_rstput( kt, nitrst, numrow, 'utau_b' , utau, ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'vtau_b' , vtau, ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'qns_b'  , qns, ldxios = lwxios  )
+         CALL iom_rstput( kt, nitrst, numrow, 'utau_b' , utau )
+         CALL iom_rstput( kt, nitrst, numrow, 'vtau_b' , vtau )
+         CALL iom_rstput( kt, nitrst, numrow, 'qns_b'  , qns  )
          ! The 3D heat content due to qsr forcing is treated in traqsr
          ! CALL iom_rstput( kt, nitrst, numrow, 'qsr_b'  , qsr  )
-         CALL iom_rstput( kt, nitrst, numrow, 'emp_b'  , emp, ldxios = lwxios  )
-         CALL iom_rstput( kt, nitrst, numrow, 'sfx_b'  , sfx, ldxios = lwxios  )
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
+         CALL iom_rstput( kt, nitrst, numrow, 'emp_b'  , emp  )
+         CALL iom_rstput( kt, nitrst, numrow, 'sfx_b'  , sfx  )
       ENDIF
       !                                                ! ---------------------------------------- !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcrnf.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcrnf.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcrnf.F90	(revision 14018)
@@ -159,7 +159,7 @@
          IF( ln_rstart .AND. .NOT.l_1st_euler ) THEN         !* Restart: read in restart file
             IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields red in the restart file', lrxios
-            CALL iom_get( numror, jpdom_auto, 'rnf_b'   , rnf_b                , ldxios = lrxios )   ! before runoff
-            CALL iom_get( numror, jpdom_auto, 'rnf_hc_b', rnf_tsc_b(:,:,jp_tem), ldxios = lrxios )   ! before heat content of runoff
-            CALL iom_get( numror, jpdom_auto, 'rnf_sc_b', rnf_tsc_b(:,:,jp_sal), ldxios = lrxios )   ! before salinity content of runoff
+            CALL iom_get( numror, jpdom_auto, 'rnf_b'   , rnf_b                 )   ! before runoff
+            CALL iom_get( numror, jpdom_auto, 'rnf_hc_b', rnf_tsc_b(:,:,jp_tem) )   ! before heat content of runoff
+            CALL iom_get( numror, jpdom_auto, 'rnf_sc_b', rnf_tsc_b(:,:,jp_sal) )   ! before salinity content of runoff
          ELSE                                                !* no restart: set from nit000 values
             IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields set to nit000'
@@ -175,9 +175,7 @@
             &                    'at it= ', kt,' date= ', ndastp
          IF(lwp) WRITE(numout,*) '~~~~'
-         IF( lwxios ) CALL iom_swap(      cwxios_context         )
-         CALL iom_rstput( kt, nitrst, numrow, 'rnf_b'   , rnf                , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'rnf_hc_b', rnf_tsc(:,:,jp_tem), ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'rnf_sc_b', rnf_tsc(:,:,jp_sal), ldxios = lwxios )
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
+         CALL iom_rstput( kt, nitrst, numrow, 'rnf_b'   , rnf                 )
+         CALL iom_rstput( kt, nitrst, numrow, 'rnf_hc_b', rnf_tsc(:,:,jp_tem) )
+         CALL iom_rstput( kt, nitrst, numrow, 'rnf_sc_b', rnf_tsc(:,:,jp_sal) )
       ENDIF
       !
@@ -479,10 +477,4 @@
       ENDIF
       !
-      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')
-      ENDIF
-
    END SUBROUTINE sbc_rnf_init
 
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcssm.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcssm.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/SBC/sbcssm.F90	(revision 14018)
@@ -154,15 +154,13 @@
             IF(lwp) WRITE(numout,*) '~~~~~~~'
             zf_sbc = REAL( nn_fsbc, wp )
-            IF( lwxios ) CALL iom_swap(      cwxios_context          )
-            CALL iom_rstput( kt, nitrst, numrow, 'nn_fsbc', zf_sbc, ldxios = lwxios )    ! sbc frequency
-            CALL iom_rstput( kt, nitrst, numrow, 'ssu_m'  , ssu_m, ldxios = lwxios  )    ! sea surface mean fields
-            CALL iom_rstput( kt, nitrst, numrow, 'ssv_m'  , ssv_m, ldxios = lwxios  )
-            CALL iom_rstput( kt, nitrst, numrow, 'sst_m'  , sst_m, ldxios = lwxios  )
-            CALL iom_rstput( kt, nitrst, numrow, 'sss_m'  , sss_m, ldxios = lwxios  )
-            CALL iom_rstput( kt, nitrst, numrow, 'ssh_m'  , ssh_m, ldxios = lwxios  )
-            CALL iom_rstput( kt, nitrst, numrow, 'e3t_m'  , e3t_m, ldxios = lwxios  )
-            CALL iom_rstput( kt, nitrst, numrow, 'frq_m'  , frq_m, ldxios = lwxios  )
-            !
-            IF( lwxios ) CALL iom_swap(      cxios_context          )
+            CALL iom_rstput( kt, nitrst, numrow, 'nn_fsbc', zf_sbc )    ! sbc frequency
+            CALL iom_rstput( kt, nitrst, numrow, 'ssu_m'  , ssu_m  )    ! sea surface mean fields
+            CALL iom_rstput( kt, nitrst, numrow, 'ssv_m'  , ssv_m  )
+            CALL iom_rstput( kt, nitrst, numrow, 'sst_m'  , sst_m  )
+            CALL iom_rstput( kt, nitrst, numrow, 'sss_m'  , sss_m  )
+            CALL iom_rstput( kt, nitrst, numrow, 'ssh_m'  , ssh_m  )
+            CALL iom_rstput( kt, nitrst, numrow, 'e3t_m'  , e3t_m  )
+            CALL iom_rstput( kt, nitrst, numrow, 'frq_m'  , frq_m  )
+            !
          ENDIF
          !
@@ -208,14 +206,14 @@
          IF( ln_rstart .AND. iom_varid( numror, 'nn_fsbc', ldstop = .FALSE. ) > 0 ) THEN
             l_ssm_mean = .TRUE.
-            CALL iom_get( numror            , 'nn_fsbc', zf_sbc,ldxios = lrxios )     ! sbc frequency of previous run
-            CALL iom_get( numror, jpdom_auto, 'ssu_m'  , ssu_m, ldxios = lrxios, cd_type = 'U', psgn = -1._wp )    ! sea surface mean velocity    (U-point)
-            CALL iom_get( numror, jpdom_auto, 'ssv_m'  , ssv_m, ldxios = lrxios, cd_type = 'V', psgn = -1._wp )    !   "         "    velocity    (V-point)
-            CALL iom_get( numror, jpdom_auto, 'sst_m'  , sst_m, ldxios = lrxios )    !   "         "    temperature (T-point)
-            CALL iom_get( numror, jpdom_auto, 'sss_m'  , sss_m, ldxios = lrxios )    !   "         "    salinity    (T-point)
-            CALL iom_get( numror, jpdom_auto, 'ssh_m'  , ssh_m, ldxios = lrxios )    !   "         "    height      (T-point)
-            CALL iom_get( numror, jpdom_auto, 'e3t_m'  , e3t_m, ldxios = lrxios )    ! 1st level thickness          (T-point)
+            CALL iom_get( numror            , 'nn_fsbc', zf_sbc )     ! sbc frequency of previous run
+            CALL iom_get( numror, jpdom_auto, 'ssu_m'  , ssu_m, cd_type = 'U', psgn = -1._wp )    ! sea surface mean velocity    (U-point)
+            CALL iom_get( numror, jpdom_auto, 'ssv_m'  , ssv_m, cd_type = 'V', psgn = -1._wp )    !   "         "    velocity    (V-point)
+            CALL iom_get( numror, jpdom_auto, 'sst_m'  , sst_m )    !   "         "    temperature (T-point)
+            CALL iom_get( numror, jpdom_auto, 'sss_m'  , sss_m )    !   "         "    salinity    (T-point)
+            CALL iom_get( numror, jpdom_auto, 'ssh_m'  , ssh_m )    !   "         "    height      (T-point)
+            CALL iom_get( numror, jpdom_auto, 'e3t_m'  , e3t_m )    ! 1st level thickness          (T-point)
             ! fraction of solar net radiation absorbed in 1st T level
             IF( iom_varid( numror, 'frq_m', ldstop = .FALSE. ) > 0 ) THEN
-               CALL iom_get( numror, jpdom_auto, 'frq_m'  , frq_m, ldxios = lrxios  )
+               CALL iom_get( numror, jpdom_auto, 'frq_m'  , frq_m  )
             ELSE
                frq_m(:,:) = 1._wp   ! default definition
@@ -255,15 +253,4 @@
       IF( .NOT. ln_traqsr )   fraqsr_1lev(:,:) = 1._wp   ! default definition: qsr 100% in the fisrt level 
       !
-      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')
-      ENDIF
-
    END SUBROUTINE sbc_ssm_init
 
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/TRA/traqsr.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/TRA/traqsr.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/TRA/traqsr.F90	(revision 14018)
@@ -138,5 +138,5 @@
             IF(lwp) WRITE(numout,*) '          nit000-1 qsr tracer content forcing field read in the restart file'
             z1_2 = 0.5_wp
-            CALL iom_get( numror, jpdom_auto, 'qsr_hc_b', qsr_hc_b, ldxios = lrxios )   ! before heat content trend due to Qsr flux
+            CALL iom_get( numror, jpdom_auto, 'qsr_hc_b', qsr_hc_b )   ! before heat content trend due to Qsr flux
          ELSE                                           ! No restart or Euler forward at 1st time step
             z1_2 = 1._wp
@@ -292,8 +292,6 @@
       !
       IF( lrst_oce ) THEN     ! write in the ocean restart file
-         IF( lwxios ) CALL iom_swap(      cwxios_context          )
-         CALL iom_rstput( kt, nitrst, numrow, 'qsr_hc_b'   , qsr_hc     , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'fraqsr_1lev', fraqsr_1lev, ldxios = lwxios ) 
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
+         CALL iom_rstput( kt, nitrst, numrow, 'qsr_hc_b'   , qsr_hc      )
+         CALL iom_rstput( kt, nitrst, numrow, 'fraqsr_1lev', fraqsr_1lev ) 
       ENDIF
       !
@@ -431,14 +429,9 @@
       ! 1st ocean level attenuation coefficient (used in sbcssm)
       IF( iom_varid( numror, 'fraqsr_1lev', ldstop = .FALSE. ) > 0 ) THEN
-         CALL iom_get( numror, jpdom_auto, 'fraqsr_1lev'  , fraqsr_1lev, ldxios = lrxios  )
+         CALL iom_get( numror, jpdom_auto, 'fraqsr_1lev'  , fraqsr_1lev  )
       ELSE
          fraqsr_1lev(:,:) = 1._wp   ! default : no penetration
       ENDIF
       !
-      IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active('qsr_hc_b')
-         CALL iom_set_rstw_var_active('fraqsr_1lev')
-      ENDIF
-      !
    END SUBROUTINE tra_qsr_init
 
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/TRA/trasbc.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/TRA/trasbc.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/TRA/trasbc.F90	(revision 14018)
@@ -111,6 +111,6 @@
             zfact = 0.5_wp
             sbc_tsc(:,:,:) = 0._wp            ! CAUTION: here only the halos should be set to 0 due to rst_put
-            CALL iom_get( numror, jpdom_auto, 'sbc_hc_b', sbc_tsc_b(:,:,jp_tem), ldxios = lrxios )   ! before heat content sbc trend
-            CALL iom_get( numror, jpdom_auto, 'sbc_sc_b', sbc_tsc_b(:,:,jp_sal), ldxios = lrxios )   ! before salt content sbc trend
+            CALL iom_get( numror, jpdom_auto, 'sbc_hc_b', sbc_tsc_b(:,:,jp_tem) )   ! before heat content sbc trend
+            CALL iom_get( numror, jpdom_auto, 'sbc_sc_b', sbc_tsc_b(:,:,jp_sal) )   ! before salt content sbc trend
          ELSE                                             ! No restart or restart not found: Euler forward time stepping
             zfact = 1._wp
@@ -144,8 +144,6 @@
       !                  
       IF( lrst_oce ) THEN           !==  write sbc_tsc in the ocean restart file  ==!
-         IF( lwxios ) CALL iom_swap(      cwxios_context          )
-         CALL iom_rstput( kt, nitrst, numrow, 'sbc_hc_b', sbc_tsc(:,:,jp_tem), ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'sbc_sc_b', sbc_tsc(:,:,jp_sal), ldxios = lwxios )
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
+         CALL iom_rstput( kt, nitrst, numrow, 'sbc_hc_b', sbc_tsc(:,:,jp_tem) )
+         CALL iom_rstput( kt, nitrst, numrow, 'sbc_sc_b', sbc_tsc(:,:,jp_sal) )
       ENDIF
       !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdfgls.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdfgls.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdfgls.F90	(revision 14018)
@@ -1057,11 +1057,4 @@
       CALL gls_rst( nit000, 'READ' )      ! (en, avt_k, avm_k, hmxl_n)
       !
-      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')
-      ENDIF
-      !
    END SUBROUTINE zdf_gls_init
 
@@ -1097,8 +1090,8 @@
             !
             IF( MIN( id1, id2, id3, id4 ) > 0 ) THEN        ! all required arrays exist
-               CALL iom_get( numror, jpdom_auto, 'en'    , en    , ldxios = lrxios )
-               CALL iom_get( numror, jpdom_auto, 'avt_k' , avt_k , ldxios = lrxios )
-               CALL iom_get( numror, jpdom_auto, 'avm_k' , avm_k , ldxios = lrxios )
-               CALL iom_get( numror, jpdom_auto, 'hmxl_n', hmxl_n, ldxios = lrxios )
+               CALL iom_get( numror, jpdom_auto, 'en'    , en     )
+               CALL iom_get( numror, jpdom_auto, 'avt_k' , avt_k  )
+               CALL iom_get( numror, jpdom_auto, 'avm_k' , avm_k  )
+               CALL iom_get( numror, jpdom_auto, 'hmxl_n', hmxl_n )
             ELSE                        
                IF(lwp) WRITE(numout,*)
@@ -1119,10 +1112,8 @@
          !                                   ! -------------------
          IF(lwp) WRITE(numout,*) '---- gls-rst ----'
-         IF( lwxios ) CALL iom_swap(      cwxios_context         )
-         CALL iom_rstput( kt, nitrst, numrow, 'en'    , en    , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'avt_k' , avt_k , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'avm_k' , avm_k , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'hmxl_n', hmxl_n, ldxios = lwxios )
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
+         CALL iom_rstput( kt, nitrst, numrow, 'en'    , en     )
+         CALL iom_rstput( kt, nitrst, numrow, 'avt_k' , avt_k  )
+         CALL iom_rstput( kt, nitrst, numrow, 'avm_k' , avm_k  )
+         CALL iom_rstput( kt, nitrst, numrow, 'hmxl_n', hmxl_n )
          !
       ENDIF
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdfosm.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdfosm.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdfosm.F90	(revision 14018)
@@ -1437,9 +1437,4 @@
      ghamv(:,:,:) = 0.
      !
-     IF( lwxios ) THEN
-        CALL iom_set_rstw_var_active('wn')
-        CALL iom_set_rstw_var_active('hbl')
-        CALL iom_set_rstw_var_active('hbli')
-     ENDIF
    END SUBROUTINE zdf_osm_init
 
@@ -1474,5 +1469,5 @@
         id1 = iom_varid( numror, 'wn'   , ldstop = .FALSE. )
         IF( id1 > 0 ) THEN                       ! 'wn' exists; read
-           CALL iom_get( numror, jpdom_auto, 'wn', ww, ldxios = lrxios )
+           CALL iom_get( numror, jpdom_auto, 'wn', ww )
            WRITE(numout,*) ' ===>>>> :  ww read from restart file'
         ELSE
@@ -1483,6 +1478,6 @@
         id2 = iom_varid( numror, 'hbli'   , ldstop = .FALSE. )
         IF( id1 > 0 .AND. id2 > 0) THEN                       ! 'hbl' exists; read and return
-           CALL iom_get( numror, jpdom_auto, 'hbl' , hbl , ldxios = lrxios )
-           CALL iom_get( numror, jpdom_auto, 'hbli', hbli, ldxios = lrxios  )
+           CALL iom_get( numror, jpdom_auto, 'hbl' , hbl  )
+           CALL iom_get( numror, jpdom_auto, 'hbli', hbli  )
            WRITE(numout,*) ' ===>>>> :  hbl & hbli read from restart file'
            RETURN
@@ -1497,7 +1492,7 @@
      IF( TRIM(cdrw) == 'WRITE') THEN     !* Write hbli into the restart file, then return
         IF(lwp) WRITE(numout,*) '---- osm-rst ----'
-         CALL iom_rstput( kt, nitrst, numrow, 'wn'     , ww  , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'hbl'    , hbl , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'hbli'   , hbli, ldxios = lwxios )
+         CALL iom_rstput( kt, nitrst, numrow, 'wn'     , ww   )
+         CALL iom_rstput( kt, nitrst, numrow, 'hbl'    , hbl  )
+         CALL iom_rstput( kt, nitrst, numrow, 'hbli'   , hbli )
         RETURN
      END IF
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdfric.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdfric.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdfric.F90	(revision 14018)
@@ -103,8 +103,4 @@
       CALL ric_rst( nit000, 'READ' )  !* read or initialize all required files
       !
-      IF( lwxios ) THEN
-         CALL iom_set_rstw_var_active('avt_k')
-         CALL iom_set_rstw_var_active('avm_k')
-      ENDIF
    END SUBROUTINE zdf_ric_init
 
@@ -214,6 +210,6 @@
             !
             IF( MIN( id1, id2 ) > 0 ) THEN         ! restart exists => read it
-               CALL iom_get( numror, jpdom_auto, 'avt_k', avt_k, ldxios = lrxios )
-               CALL iom_get( numror, jpdom_auto, 'avm_k', avm_k, ldxios = lrxios )
+               CALL iom_get( numror, jpdom_auto, 'avt_k', avt_k )
+               CALL iom_get( numror, jpdom_auto, 'avm_k', avm_k )
             ENDIF
          ENDIF
@@ -223,8 +219,6 @@
          !                                   ! -------------------
          IF(lwp) WRITE(numout,*) '---- ric-rst ----'
-         IF( lwxios ) CALL iom_swap(      cwxios_context          )
-         CALL iom_rstput( kt, nitrst, numrow, 'avt_k', avt_k, ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'avm_k', avm_k, ldxios = lwxios)
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
+         CALL iom_rstput( kt, nitrst, numrow, 'avt_k', avt_k )
+         CALL iom_rstput( kt, nitrst, numrow, 'avm_k', avm_k)
          !
       ENDIF
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdftke.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdftke.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/ZDF/zdftke.F90	(revision 14018)
@@ -721,10 +721,4 @@
       CALL tke_rst( nit000, 'READ' )      ! (en, avt_k, avm_k, dissl) 
       !
-      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')
-      ENDIF
    END SUBROUTINE zdf_tke_init
 
@@ -758,8 +752,8 @@
             !
             IF( MIN( id1, id2, id3, id4 ) > 0 ) THEN      ! fields exist
-               CALL iom_get( numror, jpdom_auto, 'en'   , en   , ldxios = lrxios )
-               CALL iom_get( numror, jpdom_auto, 'avt_k', avt_k, ldxios = lrxios )
-               CALL iom_get( numror, jpdom_auto, 'avm_k', avm_k, ldxios = lrxios )
-               CALL iom_get( numror, jpdom_auto, 'dissl', dissl, ldxios = lrxios )
+               CALL iom_get( numror, jpdom_auto, 'en'   , en    )
+               CALL iom_get( numror, jpdom_auto, 'avt_k', avt_k )
+               CALL iom_get( numror, jpdom_auto, 'avm_k', avm_k )
+               CALL iom_get( numror, jpdom_auto, 'dissl', dissl )
             ELSE                                          ! start TKE from rest
                IF(lwp) WRITE(numout,*)
@@ -780,10 +774,8 @@
          !                                   ! -------------------
          IF(lwp) WRITE(numout,*) '---- tke_rst ----'
-         IF( lwxios ) CALL iom_swap(      cwxios_context          ) 
-         CALL iom_rstput( kt, nitrst, numrow, 'en'   , en   , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'avt_k', avt_k, ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'avm_k', avm_k, ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'dissl', dissl, ldxios = lwxios )
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
+         CALL iom_rstput( kt, nitrst, numrow, 'en'   , en    )
+         CALL iom_rstput( kt, nitrst, numrow, 'avt_k', avt_k )
+         CALL iom_rstput( kt, nitrst, numrow, 'avm_k', avm_k )
+         CALL iom_rstput( kt, nitrst, numrow, 'dissl', dissl )
          !
       ENDIF
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/nemogcm.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/nemogcm.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/nemogcm.F90	(revision 14018)
@@ -415,6 +415,6 @@
      CALL Agrif_Declare_Var_ini   !  "      "   "   "      "  DOM
 #endif
-                           CALL     dom_init( Nbb, Nnn, Naa, "OCE")   ! Domain
-      IF( ln_crs       )   CALL     crs_init(      Nnn            )   ! coarsened grid: domain initialization 
+                           CALL     dom_init( Nbb, Nnn, Naa )   ! Domain
+      IF( ln_crs       )   CALL     crs_init(      Nnn      )   ! coarsened grid: domain initialization 
       IF( sn_cfctl%l_prtctl )   &
          &                 CALL prt_ctl_init        ! Print control
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/oce.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/oce.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/oce.F90	(revision 14018)
@@ -71,4 +71,8 @@
    !! Shallow Water Eq. case (SWE)
    LOGICAL, PUBLIC ::   lk_SWE = .FALSE.                                   !: shallow water flag =T in SWE configurations only
+
+   !! Stand-Alone Surface module (SAS)
+   LOGICAL, PUBLIC ::   l_SAS = .FALSE.                                    !: SAS flag =T in SAS configurations only
+   
    
    !!----------------------------------------------------------------------
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/step.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/step.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/step.F90	(revision 14018)
@@ -122,4 +122,21 @@
          IF( ln_crs      )   CALL iom_init( TRIM(cxios_context)//"_crs" )  ! for coarse grid
       ENDIF
+      IF((kstp == nitrst) .AND. lwxios) THEN
+         CALL iom_swap(      cw_ocerst_cxt          )
+         CALL iom_init_closedef(cw_ocerst_cxt)
+         CALL iom_setkt( kstp - nit000 + 1,      cw_ocerst_cxt          )
+#if defined key_top
+         CALL iom_swap(      cw_toprst_cxt          )
+         CALL iom_init_closedef(cw_toprst_cxt)
+         CALL iom_setkt( kstp - nit000 + 1,      cw_toprst_cxt          )
+#endif
+      ENDIF
+#if defined key_si3
+      IF(((kstp + nn_fsbc - 1) == nitrst) .AND. lwxios) THEN
+         CALL iom_swap(      cw_icerst_cxt          )
+         CALL iom_init_closedef(cw_icerst_cxt)
+         CALL iom_setkt( kstp - nit000 + 1,      cw_icerst_cxt          )
+      ENDIF
+#endif
       IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
                              CALL iom_setkt( kstp - nit000 + 1,      cxios_context          )   ! tell IOM we are at time step kstp
@@ -336,4 +353,5 @@
       IF( kstp == nit000 ) THEN                          ! 1st time step only
                                         CALL iom_close( numror )   ! close input  ocean restart file
+         IF( lrxios )                   CALL iom_context_finalize(      cr_ocerst_cxt         )
          IF(lwm)                        CALL FLUSH    ( numond )   ! flush output namelist oce
          IF(lwm .AND. numoni /= -1 )    CALL FLUSH    ( numoni )   ! flush output namelist ice (if exist)
@@ -351,5 +369,4 @@
       IF( kstp == nitend .OR. nstop > 0 ) THEN 
                       CALL iom_context_finalize(      cxios_context          ) ! needed for XIOS+AGRIF
-         IF( lrxios ) CALL iom_context_finalize(      crxios_context         )
          IF( ln_crs ) CALL iom_context_finalize( trim(cxios_context)//"_crs" ) ! 
       ENDIF
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OFF/dtadyn.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OFF/dtadyn.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OFF/dtadyn.F90	(revision 14018)
@@ -46,5 +46,5 @@
    USE fldread         ! read input fields 
    USE timing          ! Timing
-   USE trc, ONLY : ln_rsttr, numrtr, numrtw, lrst_trc
+   USE trc, ONLY : ln_rsttr, lrst_trc
 
    IMPLICIT NONE
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OFF/nemogcm.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OFF/nemogcm.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OFF/nemogcm.F90	(revision 14018)
@@ -130,4 +130,10 @@
          ENDIF
          !
+      IF((istp == nitrst) .AND. lwxios) THEN
+         CALL iom_swap(      cw_toprst_cxt          )
+         CALL iom_init_closedef(cw_toprst_cxt)
+         CALL iom_setkt( istp - nit000 + 1,      cw_toprst_cxt          )
+      ENDIF
+
          IF( istp /= nit000 )   CALL day        ( istp )         ! Calendar (day was already called at nit000 in day_init)
                                 CALL iom_setkt  ( istp - nit000 + 1, cxios_context )   ! say to iom that we are at time step kstp
@@ -344,5 +350,5 @@
                            CALL     eos_init        ! Equation of state
       IF( lk_c1d       )   CALL     c1d_init        ! 1D column configuration
-                           CALL     dom_init( Nbb, Nnn, Naa, "OPA") ! Domain
+                           CALL     dom_init( Nbb, Nnn, Naa ) ! Domain
       IF( sn_cfctl%l_prtctl )   &
          &                 CALL prt_ctl_init        ! Print control
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SAO/nemogcm.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SAO/nemogcm.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SAO/nemogcm.F90	(revision 14018)
@@ -235,5 +235,5 @@
                            CALL phy_cst            ! Physical constants
                            CALL eos_init           ! Equation of state
-                           CALL dom_init( Nbb, Nnn, Naa, 'SAO')    ! Domain
+                           CALL dom_init( Nbb, Nnn, Naa )    ! Domain
 
 
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SAS/nemogcm.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SAS/nemogcm.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SAS/nemogcm.F90	(revision 14018)
@@ -215,8 +215,10 @@
       !!----------------------------------------------------------------------
       !
-      IF( lk_oasis ) THEN   ;   cxios_context = 'sas'
-      ELSE                  ;   cxios_context = 'nemo'
+      IF( lk_oasis ) THEN   ;   cxios_context = 'sas'    ! when coupling SAS to OCE
+      ELSE                  ;   cxios_context = 'nemo'   ! 
       ENDIF
       nn_hls = 1
+      !
+      l_SAS = .TRUE.   ! used in domain:dom_nam
       !
       !                             !-------------------------------------------------!
@@ -374,5 +376,5 @@
      CALL Agrif_Declare_Var_ini   !  "      "   "   "      "  DOM
 #endif
-                           CALL dom_init( Nbb, Nnn, Naa, 'SAS') ! Domain
+                           CALL dom_init( Nbb, Nnn, Naa ) ! Domain
       IF( sn_cfctl%l_prtctl )   &
          &                 CALL prt_ctl_init        ! Print control
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SAS/step.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SAS/step.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SAS/step.F90	(revision 14018)
@@ -89,6 +89,24 @@
 #endif   
       IF( kstp == nit000 )   CALL iom_init( cxios_context ) ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
+                             CALL iom_setkt( kstp - nit000 + 1, cxios_context )   ! tell iom we are at time step kstp
+      IF((kstp == nitrst) .AND. lwxios) THEN
+         CALL iom_swap(      cw_ocerst_cxt          )
+         CALL iom_init_closedef(cw_ocerst_cxt)
+         CALL iom_setkt( kstp - nit000 + 1,      cw_ocerst_cxt          )
+#if defined key_top
+         CALL iom_swap(      cw_toprst_cxt          )
+         CALL iom_init_closedef(cw_toprst_cxt)
+         CALL iom_setkt( kstp - nit000 + 1,      cw_toprst_cxt          )
+#endif
+      ENDIF
       IF( kstp /= nit000 )   CALL day( kstp )             ! Calendar (day was already called at nit000 in day_init)
-                             CALL iom_setkt( kstp - nit000 + 1, cxios_context )   ! tell iom we are at time step kstp
+
+#if defined key_si3
+      IF(((kstp + nn_fsbc - 1) == nitrst) .AND. lwxios) THEN
+         CALL iom_swap(      cw_icerst_cxt          )
+         CALL iom_init_closedef(cw_icerst_cxt)
+         CALL iom_setkt( kstp - nit000 + 1,      cw_icerst_cxt          )
+      ENDIF
+#endif
 
       ! ==> clem: open boundaries is mandatory for sea-ice because ice BDY is not decoupled from  
@@ -128,5 +146,8 @@
       ! File manipulation at the end of the first time step
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<                         
-      IF( kstp == nit000   ) CALL iom_close( numror )                          ! close input  ocean restart file
+      IF( kstp == nit000   ) THEN
+            CALL iom_close( numror )                          ! close input  ocean restart file
+            IF( lrxios )     CALL iom_context_finalize(      cr_ocerst_cxt      )
+      ENDIF
       
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -140,5 +161,7 @@
             CALL iom_close( numrow )     
          ELSE
-            CALL iom_context_finalize( cwxios_context )
+            CALL iom_context_finalize( cw_ocerst_cxt )
+            iom_file(numrow)%nfid       = 0
+            numrow = 0
          ENDIF
          lrst_oce = .FALSE.
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/nemogcm.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/nemogcm.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/nemogcm.F90	(revision 14018)
@@ -296,5 +296,5 @@
                            r1_rho0_rcp = 1._wp / rho0_rcp 
       !
-                           CALL     dom_init( Nbb, Nnn, Naa, "OPA") ! Domain
+                           CALL     dom_init( Nbb, Nnn, Naa ) ! Domain
 
       IF( sn_cfctl%l_prtctl )   &
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/C14/trcsms_c14.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/C14/trcsms_c14.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/C14/trcsms_c14.F90	(revision 14018)
@@ -144,9 +144,9 @@
          IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
          !
-         CALL iom_rstput( kt, nitrst, numrtw, 'co2sbc', co2sbc )       ! These five need      &
-         CALL iom_rstput( kt, nitrst, numrtw, 'c14sbc', c14sbc )     ! &    to be written   &
+         CALL iom_rstput( kt, nitrst, numrtw, 'co2sbc', co2sbc ) ! These five need      &
+         CALL iom_rstput( kt, nitrst, numrtw, 'c14sbc', c14sbc ) ! &    to be written   &
          CALL iom_rstput( kt, nitrst, numrtw, 'exch_co2', exch_co2 ) ! &    for temporal    &
          CALL iom_rstput( kt, nitrst, numrtw, 'exch_c14', exch_c14 ) ! &    averages        &
-         CALL iom_rstput( kt, nitrst, numrtw, 'qtr_c14', qtr_c14 )   ! &    to be coherent.
+         CALL iom_rstput( kt, nitrst, numrtw, 'qtr_c14', qtr_c14   ) ! &    to be coherent.
          CALL iom_rstput( kt, nitrst, numrtw, 'qint_c14', qint_c14 ) ! Cumulative
          !
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/P4Z/p4zsms.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/P4Z/p4zsms.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/P4Z/p4zsms.F90	(revision 14018)
@@ -369,6 +369,6 @@
             IF(lwp) WRITE(numout,*) '~~~~~~~'
          ENDIF
-         CALL iom_rstput( kt, nitrst, numrtw, 'PH', hi(:,:,:) )
-         CALL iom_rstput( kt, nitrst, numrtw, 'Silicalim', xksi(:,:) )
+         CALL iom_rstput( kt, nitrst, numrtw, 'PH', hi(:,:,:)           )
+         CALL iom_rstput( kt, nitrst, numrtw, 'Silicalim', xksi(:,:)    )
          CALL iom_rstput( kt, nitrst, numrtw, 'Silicamax', xksimax(:,:) )
          CALL iom_rstput( kt, nitrst, numrtw, 'tcflxcum', t_oce_co2_flx_cum )
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/SED/sed.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/SED/sed.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/SED/sed.F90	(revision 14018)
@@ -44,5 +44,4 @@
    REAL    , PUBLIC               ::  sedmask
    REAL(wp), PUBLIC               ::  denssol                !: density of solid material
-   INTEGER , PUBLIC               ::  numrsr, numrsw   !: logical unit for sed restart (read and write)
    LOGICAL , PUBLIC               ::  lrst_sed       !: logical to control the trc restart write
    LOGICAL , PUBLIC               ::  ln_rst_sed  = .TRUE.     !: initialisation from a restart file or not
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/SED/sedrst.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/SED/sedrst.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/SED/sedrst.F90	(revision 14018)
@@ -42,4 +42,5 @@
       CHARACTER(LEN=50)   ::   clname   ! trc output restart file name
       CHARACTER(LEN=256)  ::   clpath   ! full path to ocean output restart file
+      CHARACTER(LEN=52)   ::   clpname   ! trc output restart file name including AGRIF
       !!----------------------------------------------------------------------
       !
@@ -80,5 +81,22 @@
          IF(lwp) WRITE(numsed,*) &
              '             open sed restart.output NetCDF file: ',TRIM(clpath)//clname
-         CALL iom_open( TRIM(clpath)//TRIM(clname), numrsw, ldwrt = .TRUE., kdlev = jpksed, cdcomp = 'SED' )
+         IF(.NOT.lwxios) THEN
+            CALL iom_open( TRIM(clpath)//TRIM(clname), numrsw, ldwrt = .TRUE., kdlev = jpksed, cdcomp = 'SED' )
+         ELSE
+#if defined key_iomput
+            cw_sedrst_cxt = "rstws_"//TRIM(ADJUSTL(clkt))
+            IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+               clpname = clname
+            ELSE
+               clpname = TRIM(Agrif_CFixed())//"_"//clname
+            ENDIF
+            numrsw = iom_xios_setid(TRIM(clpath)//TRIM(clpname))
+            CALL iom_init( cw_sedrst_cxt, kdid = numrsw, ld_closedef = .FALSE. )
+#else
+               clinfo = 'Can not use XIOS in trc_rst_opn'
+               CALL ctl_stop(TRIM(clinfo))
+#endif
+            ENDIF
+
          lrst_sed = .TRUE.
       ENDIF
@@ -196,5 +214,4 @@
       CALL pack_arr( jpoce, sedligand(1:jpoce,1:jpksed), &
          &             zdta2(1:jpi,1:jpj,1:jpksed), iarroce(1:jpoce) )
-
       IF( ln_timing )  CALL timing_stop('sed_rst_read')
      
@@ -240,7 +257,6 @@
       !! 1. WRITE in nutwrs
       !! ------------------
-
-      zinfo(1) = REAL( kt)
-      CALL iom_rstput( kt, nitrst, numrsw, 'kt', zinfo  )
+!     zinfo(1) = REAL( kt)
+      CALL iom_rstput( kt, nitrst, numrsw, 'kt', REAL( kt    , wp) )
 
       ! Back to 2D geometry
@@ -299,5 +315,11 @@
 
       IF( kt == nitrst ) THEN
-          CALL iom_close( numrsw )     ! close the restart file (only at last time step)
+          IF(.NOT.lwxios) THEN
+             CALL iom_close( numrsw )     ! close the restart file (only at last time step)
+          ELSE
+             CALL iom_context_finalize( cw_sedrst_cxt ) 
+             iom_file(numrsw)%nfid       = 0
+             numrsw = 0
+          ENDIF
           IF( l_offline .AND. ln_rst_list ) THEN
              nrst_lst = nrst_lst + 1
@@ -342,4 +364,5 @@
       REAL(wp) ::  zkt, zrdttrc1
       REAL(wp) ::  zndastp
+      CHARACTER(len = 82) :: clpname
 
       ! Time domain : restart
@@ -353,7 +376,18 @@
 
          IF( ln_rst_sed ) THEN
+            lxios_sini = .FALSE.
             CALL iom_open( TRIM(cn_sedrst_indir)//'/'//cn_sedrst_in, numrsr )
+
+            IF( lrxios) THEN
+                cr_sedrst_cxt = 'sed_rst'
+                IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for SED'
+!               IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+!                  clpname = cn_sedrst_in
+!               ELSE
+!                  clpname = TRIM(Agrif_CFixed())//"_"//cn_sedrst_in   
+!               ENDIF
+                CALL iom_init( cr_sedrst_cxt, kdid = numrsr, ld_closedef = .TRUE. )
+            ENDIF
             CALL iom_get ( numrsr, 'kt', zkt )   ! last time-step of previous run
-
             IF(lwp) THEN
                WRITE(numsed,*) ' *** Info read in restart : '
@@ -402,9 +436,10 @@
             IF(lwp) WRITE(numsed,*) 'trc_wri : write the TOP restart file (NetCDF) at it= ', kt, ' date= ', ndastp
             IF(lwp) WRITE(numsed,*) '~~~~~~~'
+            IF( lwxios ) CALL iom_init_closedef(cw_sedrst_cxt)
          ENDIF
          CALL iom_rstput( kt, nitrst, numrsw, 'kt'     , REAL( kt    , wp) )   ! time-step
          CALL iom_rstput( kt, nitrst, numrsw, 'ndastp' , REAL( ndastp, wp) )   ! date
-         CALL iom_rstput( kt, nitrst, numrsw, 'adatrj' , adatrj            )   ! number of elapsed days since
-         !                                                                     ! the begining of the run [s]
+         CALL iom_rstput( kt, nitrst, numrsw, 'adatrj' , adatrj )   ! number of elapsed days since
+         !                                                                                      ! the begining of the run [s]
       ENDIF
 
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/SED/sedstp.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/SED/sedstp.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/PISCES/SED/sedstp.F90	(revision 14018)
@@ -86,5 +86,6 @@
       IF( kt == nitsed000 ) THEN
           CALL iom_close( numrsr )       ! close input tracer restart file
-!          IF(lwm) CALL FLUSH( numont )   ! flush namelist output
+          IF(lrxios) CALL iom_context_finalize(      cr_sedrst_cxt  )
+!         IF(lwm) CALL FLUSH( numont )   ! flush namelist output
       ENDIF
       IF( lrst_sed )            CALL sed_rst_wri( kt )   ! restart file output
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/trc.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/trc.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/trc.F90	(revision 14018)
@@ -21,6 +21,4 @@
    INTEGER, PUBLIC ::   numonr     = -1   !: reference passive tracer namelist output output.namelist.top
    INTEGER, PUBLIC ::   numstr            !: tracer statistics
-   INTEGER, PUBLIC ::   numrtr     = -1   !: trc restart (read )
-   INTEGER, PUBLIC ::   numrtw            !: trc restart ( write )
    CHARACTER(:), ALLOCATABLE, PUBLIC ::   numnat_ref   !: character buffer for reference passive tracer namelist_top_ref
    CHARACTER(:), ALLOCATABLE, PUBLIC ::   numnat_cfg   !: character buffer for configuration specific passive tracer namelist_top_cfg
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/trcrst.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/trcrst.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/trcrst.F90	(revision 14018)
@@ -52,4 +52,5 @@
       CHARACTER(LEN=50)   ::   clname   ! trc output restart file name
       CHARACTER(LEN=256)  ::   clpath   ! full path to ocean output restart file
+      CHARACTER(LEN=50)   ::   clpname  ! trc output restart file name including AGRIF
       !!----------------------------------------------------------------------
       !
@@ -91,5 +92,21 @@
          IF(lwp) WRITE(numout,*) &
              '             open trc restart.output NetCDF file: ',TRIM(clpath)//clname
-         CALL iom_open( TRIM(clpath)//TRIM(clname), numrtw, ldwrt = .TRUE. )
+         IF(.NOT.lwxios) THEN
+            CALL iom_open( TRIM(clpath)//TRIM(clname), numrtw, ldwrt = .TRUE. )
+         ELSE
+#if defined key_iomput
+            cw_toprst_cxt = "rstwt_"//TRIM(ADJUSTL(clkt))
+            IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+               clpname = clname
+            ELSE
+               clpname = TRIM(Agrif_CFixed())//"_"//clname
+            ENDIF
+            numrtw = iom_xios_setid(TRIM(clpath)//TRIM(clpname))
+            CALL iom_init( cw_toprst_cxt, kdid = numrtw, ld_closedef = .FALSE. )
+#else
+               clinfo = 'Can not use XIOS in trc_rst_opn'
+               CALL ctl_stop(TRIM(clinfo))
+#endif
+            ENDIF
          lrst_trc = .TRUE.
       ENDIF
@@ -121,6 +138,5 @@
       END DO
       !
-      CALL iom_delay_rst( 'READ', 'TOP', numrtr )   ! read only TOP delayed global communication variables
-      
+      IF(.NOT.lrxios) CALL iom_delay_rst( 'READ', 'TOP', numrtr )   ! read only TOP delayed global communication variables
    END SUBROUTINE trc_rst_read
 
@@ -147,10 +163,16 @@
          CALL iom_rstput( kt, nitrst, numrtw, 'TRB'//ctrcnm(jn), tr(:,:,:,jn,Kbb) )
       END DO
-      !
-      CALL iom_delay_rst( 'WRITE', 'TOP', numrtw )   ! save only TOP delayed global communication variables
+
+      IF( .NOT. lwxios ) CALL iom_delay_rst( 'WRITE', 'TOP', numrtw )   ! save only TOP delayed global communication variables
     
       IF( kt == nitrst ) THEN
           CALL trc_rst_stat( Kmm, Krhs )             ! statistics
-          CALL iom_close( numrtw )     ! close the restart file (only at last time step)
+          IF(lwxios) THEN
+             CALL iom_context_finalize(      cw_toprst_cxt          )
+             iom_file(numrtw)%nfid       = 0
+             numrtw = 0
+          ELSE
+             CALL iom_close( numrtw )     ! close the restart file (only at last time step)
+          ENDIF
 #if ! defined key_trdmxl_trc
           lrst_trc = .FALSE.
@@ -196,4 +218,5 @@
       REAL(wp) ::  zrdttrc1, zkt, zndastp, zdayfrac, ksecs, ktime
       INTEGER  ::   ihour, iminute
+      CHARACTER(len=82) :: clpname
 
       ! Time domain : restart
@@ -207,5 +230,17 @@
 
          IF( ln_rsttr ) THEN
+            lxios_sini = .FALSE.
             CALL iom_open( TRIM(cn_trcrst_indir)//'/'//cn_trcrst_in, numrtr )
+            IF( lrxios) THEN
+                cr_toprst_cxt = 'top_rst'
+                IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for TOP'
+!               IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+!                  clpname = cn_trcrst_in
+!               ELSE
+!                  clpname = TRIM(Agrif_CFixed())//"_"//cn_trcrst_in   
+!               ENDIF
+                CALL iom_init( cr_toprst_cxt, kdid = numrtr, ld_closedef = .TRUE. )
+            ENDIF
+
             CALL iom_get ( numrtr, 'kt', zkt )   ! last time-step of previous run
 
@@ -293,9 +328,9 @@
             IF(lwp) WRITE(numout,*) '~~~~~~~'
          ENDIF
-         CALL iom_rstput( kt, nitrst, numrtw, 'kt'     , REAL( kt    , wp) )   ! time-step
-         CALL iom_rstput( kt, nitrst, numrtw, 'ndastp' , REAL( ndastp, wp) )   ! date
-         CALL iom_rstput( kt, nitrst, numrtw, 'adatrj' , adatrj            )   ! number of elapsed days since
+         CALL iom_rstput( kt, nitrst, numrtw, 'kt'     , REAL( kt    , wp)   )   ! time-step
+         CALL iom_rstput( kt, nitrst, numrtw, 'ndastp' , REAL( ndastp, wp)   )   ! date
+         CALL iom_rstput( kt, nitrst, numrtw, 'adatrj' , adatrj              )   ! number of elapsed days since
          !                                                                     ! the begining of the run [s]
-         CALL iom_rstput( kt, nitrst, numrtw, 'ntime'  , REAL( nn_time0, wp)) ! time
+         CALL iom_rstput( kt, nitrst, numrtw, 'ntime'  , REAL( nn_time0, wp) ) ! time
       ENDIF
 
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/trcstp.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/trcstp.F90	(revision 14017)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/trcstp.F90	(revision 14018)
@@ -110,4 +110,5 @@
       IF( kt == nittrc000 ) THEN
          CALL iom_close( numrtr )                         ! close input tracer restart file
+         IF(lrxios) CALL iom_context_finalize(      cr_toprst_cxt          )
          IF(lwm) CALL FLUSH( numont )                     ! flush namelist output
       ENDIF
@@ -196,5 +197,4 @@
            &                              .AND. iom_varid( numrtr, 'ktdcy'    , ldstop = .FALSE. ) > 0  &
            &                              .AND. iom_varid( numrtr, 'nrdcy'    , ldstop = .FALSE. ) > 0  ) THEN
-
             CALL iom_get( numrtr, 'ktdcy', zkt )  
             rsecfst = INT( zkt ) * rn_Dt
