Index: NEMO/branches/2020/dev_12905_xios_ancil/cfgs/SHARED/namelist_ref
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/cfgs/SHARED/namelist_ref	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/cfgs/SHARED/namelist_ref	(revision 13016)
@@ -94,4 +94,5 @@
    ln_use_jattr = .false.    !  use (T) the file attribute: open_ocean_jstart, if present
    !                         !  in netcdf input files, as the start j-row for reading
+   ln_xios_cfg = .false.     !  Read configuration data using XIOS (T)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DIA/diahsb.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DIA/diahsb.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DIA/diahsb.F90	(revision 13016)
@@ -258,4 +258,5 @@
       IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
          IF( ln_rstart ) THEN                   !* Read the restart file
+            IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
             !
             IF(lwp) WRITE(numout,*)
@@ -279,4 +280,5 @@
                CALL iom_get( numror, jpdom_autoglo, 'ssh_sc_loc_ini', ssh_sc_loc_ini, ldxios = lrxios )
             ENDIF
+            IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
          ELSE
             IF(lwp) WRITE(numout,*)
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/closea.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/closea.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/closea.F90	(revision 13016)
@@ -20,7 +20,8 @@
    !!----------------------------------------------------------------------
    USE in_out_manager  ! I/O manager
+   USE iom_def
    !
    USE diu_bulk    , ONLY: ln_diurnal_only            ! used for sanity check
-   USE iom         , ONLY: iom_open, iom_get, iom_close, jpdom_data ! I/O routines
+   USE iom         , ONLY: iom_open, iom_get, iom_close, jpdom_data, iom_swap ! I/O routines
    USE lib_fortran , ONLY: glob_sum                   ! fortran library
    USE lib_mpp     , ONLY: mpp_max, ctl_nam, ctl_stop ! MPP library
@@ -235,6 +236,9 @@
       !!----------------------------------------------------------------------
       !
+      IF(lcfg_xios) CALL iom_swap("dom_context")
+
       CALL iom_open ( cd_file, ics )
-      CALL iom_get  ( ics, jpdom_data, TRIM(cd_var), zdta )
+      CALL iom_get  ( ics, jpdom_data, TRIM(cd_var), zdta,  ldxios = lcfg_xios )
+
       CALL iom_close( ics )
       k_mskout(:,:) = NINT(zdta(:,:))
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/daymod.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/daymod.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/daymod.F90	(revision 13016)
@@ -323,5 +323,5 @@
 
       IF( TRIM(cdrw) == 'READ' ) THEN
-
+         IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
          IF( iom_varid( numror, 'kt', ldstop = .FALSE. ) > 0 ) THEN
             ! Get Calendar informations
@@ -401,4 +401,5 @@
          ENDIF
          !
+         IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
       ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
          !
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domain.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domain.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domain.F90	(revision 13016)
@@ -122,4 +122,6 @@
       CALL dom_glo                     ! global domain versus local domain
       CALL dom_nam                     ! read namelist ( namrun, namdom )
+
+      lcfg_xios = ln_xios_cfg .AND. (.NOT. ln_use_jattr)
       !
       IF( lwxios ) THEN
@@ -301,5 +303,4 @@
       ENDIF
       !
-      !
       READ  ( numnam_ref, namrun, IOSTAT = ios, ERR = 901)
 901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namrun in reference namelist' )
@@ -340,4 +341,5 @@
             WRITE(numout,*) '      READ restart for a single file using XIOS ln_xios_read =', ln_xios_read
             WRITE(numout,*) '      Write restart using XIOS        nn_wxios   = ', nn_wxios
+            WRITE(numout,*) '      READ config using XIOS          ln_xios_cfg  = ', ln_xios_cfg
          ELSE
             WRITE(numout,*) "      AGRIF: nn_wxios will be ingored. See setting for parent"
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domhgr.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domhgr.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domhgr.F90	(revision 13016)
@@ -189,29 +189,33 @@
       CALL iom_open( cn_domcfg, inum )
       !
-      CALL iom_get( inum, jpdom_data, 'glamt', plamt, lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'glamu', plamu, lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'glamv', plamv, lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'glamf', plamf, lrowattr=ln_use_jattr )
-      !
-      CALL iom_get( inum, jpdom_data, 'gphit', pphit, lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'gphiu', pphiu, lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'gphiv', pphiv, lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'gphif', pphif, lrowattr=ln_use_jattr )
-      !
-      CALL iom_get( inum, jpdom_data, 'e1t'  , pe1t  , lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'e1u'  , pe1u  , lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'e1v'  , pe1v  , lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'e1f'  , pe1f  , lrowattr=ln_use_jattr )
-      !
-      CALL iom_get( inum, jpdom_data, 'e2t'  , pe2t  , lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'e2u'  , pe2u  , lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'e2v'  , pe2v  , lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'e2f'  , pe2f  , lrowattr=ln_use_jattr )
+      IF(lcfg_xios) THEN
+         CALL iom_dom_context(cn_domcfg, inum)
+         CALL iom_swap("dom_context")
+      ENDIF
+      CALL iom_get( inum, jpdom_data, 'glamt', plamt, lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'glamu', plamu, lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'glamv', plamv, lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'glamf', plamf, lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      !
+      CALL iom_get( inum, jpdom_data, 'gphit', pphit, lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'gphiu', pphiu, lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'gphiv', pphiv, lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'gphif', pphif, lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      !
+      CALL iom_get( inum, jpdom_data, 'e1t'  , pe1t  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'e1u'  , pe1u  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'e1v'  , pe1v  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'e1f'  , pe1f  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      !
+      CALL iom_get( inum, jpdom_data, 'e2t'  , pe2t  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'e2u'  , pe2u  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'e2v'  , pe2v  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+      CALL iom_get( inum, jpdom_data, 'e2f'  , pe2f  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
       !
       IF(  iom_varid( inum, 'ff_f', ldstop = .FALSE. ) > 0  .AND.  &
          & iom_varid( inum, 'ff_t', ldstop = .FALSE. ) > 0    ) THEN
          IF(lwp) WRITE(numout,*) '           Coriolis factor at f- and t-points read in ', TRIM( cn_domcfg ), ' file'
-         CALL iom_get( inum, jpdom_data, 'ff_f'  , pff_f  , lrowattr=ln_use_jattr )
-         CALL iom_get( inum, jpdom_data, 'ff_t'  , pff_t  , lrowattr=ln_use_jattr )
+         CALL iom_get( inum, jpdom_data, 'ff_f'  , pff_f  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+         CALL iom_get( inum, jpdom_data, 'ff_t'  , pff_t  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
          kff = 1
       ELSE
@@ -221,6 +225,6 @@
       IF( iom_varid( inum, 'e1e2u', ldstop = .FALSE. ) > 0 ) THEN
          IF(lwp) WRITE(numout,*) '           e1e2u & e1e2v read in ', TRIM( cn_domcfg ), ' file'
-         CALL iom_get( inum, jpdom_data, 'e1e2u'  , pe1e2u  , lrowattr=ln_use_jattr )
-         CALL iom_get( inum, jpdom_data, 'e1e2v'  , pe1e2v  , lrowattr=ln_use_jattr )
+         CALL iom_get( inum, jpdom_data, 'e1e2u'  , pe1e2u  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+         CALL iom_get( inum, jpdom_data, 'e1e2v'  , pe1e2v  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
          ke1e2u_v = 1
       ELSE
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domvvl.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domvvl.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domvvl.F90	(revision 13016)
@@ -793,4 +793,5 @@
          IF( ln_rstart ) THEN                   !* Read the restart file
             CALL rst_read_open                  !  open the restart file if necessary
+            IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
             CALL iom_get( numror, jpdom_autoglo, 'sshn'   , ssh(:,:,Kmm), ldxios = lrxios    )
             !
@@ -870,4 +871,5 @@
             ENDIF
             !
+            IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
          ELSE                                   !* Initialize at "rest"
             !
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domzgr.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domzgr.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DOM/domzgr.F90	(revision 13016)
@@ -219,4 +219,6 @@
       !
       CALL iom_open( cn_domcfg, inum )
+
+      IF(lcfg_xios) CALL iom_swap("dom_context")
       !
       !                          !* type of vertical coordinate
@@ -229,18 +231,18 @@
       !
       !                          !* ocean cavities under iceshelves
-      CALL iom_get( inum, 'ln_isfcav', z_cav )
+      CALL iom_get( inum, 'ln_isfcav', z_cav, ldxios = lcfg_xios )
       IF( z_cav == 0._wp ) THEN   ;   ld_isfcav = .false.   ;   ELSE   ;   ld_isfcav = .true.   ;   ENDIF
       !
       !                          !* vertical scale factors
-      CALL iom_get( inum, jpdom_unknown, 'e3t_1d'  , pe3t_1d  )                     ! 1D reference coordinate
-      CALL iom_get( inum, jpdom_unknown, 'e3w_1d'  , pe3w_1d  )
-      !
-      CALL iom_get( inum, jpdom_data, 'e3t_0'  , pe3t  , lrowattr=ln_use_jattr )    ! 3D coordinate
-      CALL iom_get( inum, jpdom_data, 'e3u_0'  , pe3u  , lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'e3v_0'  , pe3v  , lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'e3f_0'  , pe3f  , lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'e3w_0'  , pe3w  , lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'e3uw_0' , pe3uw , lrowattr=ln_use_jattr )
-      CALL iom_get( inum, jpdom_data, 'e3vw_0' , pe3vw , lrowattr=ln_use_jattr )
+      CALL iom_get( inum, jpdom_unknown, 'e3t_1d'  , pe3t_1d, ldxios = lcfg_xios   )                     ! 1D reference coordinate
+      CALL iom_get( inum, jpdom_unknown, 'e3w_1d'  , pe3w_1d, ldxios = lcfg_xios   )
+      !
+      CALL iom_get( inum, jpdom_data, 'e3t_0'  , pe3t  , lrowattr=ln_use_jattr, ldxios = lcfg_xios  )    ! 3D coordinate
+      CALL iom_get( inum, jpdom_data, 'e3u_0'  , pe3u  , lrowattr=ln_use_jattr, ldxios = lcfg_xios  )
+      CALL iom_get( inum, jpdom_data, 'e3v_0'  , pe3v  , lrowattr=ln_use_jattr, ldxios = lcfg_xios  )
+      CALL iom_get( inum, jpdom_data, 'e3f_0'  , pe3f  , lrowattr=ln_use_jattr, ldxios = lcfg_xios  )
+      CALL iom_get( inum, jpdom_data, 'e3w_0'  , pe3w  , lrowattr=ln_use_jattr, ldxios = lcfg_xios  )
+      CALL iom_get( inum, jpdom_data, 'e3uw_0' , pe3uw , lrowattr=ln_use_jattr, ldxios = lcfg_xios  )
+      CALL iom_get( inum, jpdom_data, 'e3vw_0' , pe3vw , lrowattr=ln_use_jattr, ldxios = lcfg_xios  )
       !
       !                          !* depths
@@ -252,8 +254,8 @@
          CALL ctl_warn( 'zgr_read : old definition of depths and scale factors used ', & 
             &           '           depths at t- and w-points read in the domain configuration file')
-         CALL iom_get( inum, jpdom_unknown, 'gdept_1d', pdept_1d )   
-         CALL iom_get( inum, jpdom_unknown, 'gdepw_1d', pdepw_1d )
-         CALL iom_get( inum, jpdom_data   , 'gdept_0' , pdept , lrowattr=ln_use_jattr )
-         CALL iom_get( inum, jpdom_data   , 'gdepw_0' , pdepw , lrowattr=ln_use_jattr )
+         CALL iom_get( inum, jpdom_unknown, 'gdept_1d', pdept_1d, ldxios = lcfg_xios )   
+         CALL iom_get( inum, jpdom_unknown, 'gdepw_1d', pdepw_1d, ldxios = lcfg_xios )
+         CALL iom_get( inum, jpdom_data   , 'gdept_0' , pdept , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
+         CALL iom_get( inum, jpdom_data   , 'gdepw_0' , pdepw , lrowattr=ln_use_jattr, ldxios = lcfg_xios )
          !
       ELSE                                !- depths computed from e3. scale factors
@@ -269,12 +271,15 @@
       !
       !                          !* ocean top and bottom level
-      CALL iom_get( inum, jpdom_data, 'top_level'    , z2d  , lrowattr=ln_use_jattr )   ! 1st wet T-points (ISF)
+      CALL iom_get( inum, jpdom_data, 'top_level'    , z2d  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )   ! 1st wet T-points (ISF)
       k_top(:,:) = NINT( z2d(:,:) )
-      CALL iom_get( inum, jpdom_data, 'bottom_level' , z2d  , lrowattr=ln_use_jattr )   ! last wet T-points
+      CALL iom_get( inum, jpdom_data, 'bottom_level' , z2d  , lrowattr=ln_use_jattr, ldxios = lcfg_xios )   ! last wet T-points
       k_bot(:,:) = NINT( z2d(:,:) )
       !
       ! reference depth for negative bathy (wetting and drying only)
-      IF( ll_wd )  CALL iom_get( inum,  'rn_wd_ref_depth' , ssh_ref   )
-      !
+      IF( ll_wd )  CALL iom_get( inum,  'rn_wd_ref_depth' , ssh_ref, ldxios = lcfg_xios   )
+      !
+      IF(lcfg_xios) THEN
+         CALL iom_context_finalize( "dom_context")
+      ENDIF
       CALL iom_close( inum )
       !
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DYN/dynspg_ts.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DYN/dynspg_ts.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/DYN/dynspg_ts.F90	(revision 13016)
@@ -890,4 +890,5 @@
       IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
          !                                   ! ---------------
+         IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
          IF( ln_rstart .AND. ln_bt_fw .AND. (.NOT.l_1st_euler) ) THEN    !* Read the restart file
             CALL iom_get( numror, jpdom_autoglo, 'ub2_b'  , ub2_b  (:,:), ldxios = lrxios )   
@@ -923,4 +924,5 @@
          ENDIF
          !
+         IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
       ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
          !                                   ! -------------------
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/in_out_manager.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/in_out_manager.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/in_out_manager.F90	(revision 13016)
@@ -45,4 +45,5 @@
    LOGICAL       ::   ln_xios_read     !: use xios to read single file restart
    INTEGER       ::   nn_wxios         !: write resart using xios 0 - no, 1 - single, 2 - multiple file output
+   LOGICAL       ::   ln_xios_cfg      !: use xios to read single file restart in namelist
    INTEGER       ::   nn_no            !: Assimilation cycle
 
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/iom.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/iom.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/iom.F90	(revision 13016)
@@ -46,4 +46,6 @@
    USE lib_fortran 
    USE diu_bulk, ONLY : ln_diurnal_only, ln_diurnal
+   USE netcdf
+   USE iom_nf90
 
    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_dom_context
 
    PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
@@ -65,5 +68,5 @@
    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_rstw_active, iom_set_rstr_active, iom_set_vars_active
 # endif
    PUBLIC iom_set_rstw_var_active, iom_set_rstw_core, iom_set_rst_vars
@@ -306,4 +309,124 @@
 
    END SUBROUTINE iom_init_closedef
+
+   SUBROUTINE iom_set_vars_active(cdfname, idnum)
+      !!---------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_set_vars_active  ***
+      !!
+      !! ** Purpose :  define filename in XIOS context for reading file,
+      !!               enable variables present in restart file for reading with XIOS 
+      !!               id of a file is assumed to be rrestart.
+      !!---------------------------------------------------------------------
+
+!sets enabled = .TRUE. for each field in restart file
+   CHARACTER(len=*), INTENT(IN) :: cdfname
+   INTEGER         , INTENT(IN) :: idnum 
+#if defined key_iomput
+   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
+   LOGICAL                                    :: lmeta
+
+        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(cdfname)
+
+        IF(lwp) write(numout, *) TRIM(clinfo)
+        IF(lwp) CALL FLUSH(numout)
+!set name of the restart file and enable available fields
+        CALL xios_get_handle("file_definition", filegroup_hdl )
+        CALL xios_add_child(filegroup_hdl, file_hdl, 'rrestart')
+        CALL xios_set_file_attr( "rrestart", name=trim(cdfname), type="one_file", &
+             par_access="collective", enabled=.TRUE., mode="read",                 &
+             output_freq=xios_timestep)
+
+        CALL iom_nf90_check( nf90_inquire(idnum, ndims, nvars, natts ), clinfo )
+        ALLOCATE(indimlens(ndims), indimnames(ndims))
+        CALL iom_nf90_check( nf90_inquire(idnum, unlimitedDimId = unlimitedDimId ), clinfo )
+
+        DO idim = 1, ndims
+           CALL iom_nf90_check( nf90_inquire_dimension(idnum, idim, dimname, dimlen ), clinfo )
+           indimlens(idim) = dimlen
+           indimnames(idim) = dimname
+        ENDDO
+
+        DO jv =1, nvars
+            lmeta = .FALSE.
+            CALL iom_nf90_check( nf90_inquire_variable(idnum, jv, varname, xtype, ndims, dimids, natts ), clinfo )
+            DO i = 1, NMETA
+               IF(TRIM(varname) == TRIM(meta(i))) THEN
+                  lmeta = .TRUE.
+               ENDIF
+            ENDDO
+            IF(.NOT.lmeta) THEN
+               CALL xios_add_child(file_hdl, field_hdl, TRIM(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 = TRIM(varname),   &
+                                   domain_ref="grid_N", axis_ref=TRIM(iom_axis(indimlens(dimids(mdims)))), &
+                                   prec = 8, operation = "instant")
+               ELSEIF(mdims == 2) THEN
+                      CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(varname), &
+                                          domain_ref="grid_N", prec = 8, operation = "instant") 
+               ELSEIF(mdims == 1) THEN
+                      CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(varname), &
+                                          axis_ref=TRIM(iom_axis(indimlens(dimids(mdims)))), prec = 8, operation = "instant")
+               ELSEIF(mdims == 0) THEN
+                      CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(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
+
+   FUNCTION iom_axis(idlev) result(axis_ref)
+     !!---------------------------------------------------------------------
+      !!                   ***  FUNCTION  iom_axis  ***
+      !!
+      !! ** Purpose : Used for grid definition when XIOS is used to read/write
+      !!              restart or configuration data. Returns axis corresponding 
+      !!              to the number of levels given as an input variable. Axes 
+      !!              are defined in routine iom_set_rst_context or iom_dom_context
+      !!              depending on 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
 
    SUBROUTINE iom_set_rstw_var_active(field)
@@ -659,4 +782,5 @@
       !
       CALL xios_set_current_context(nemo_hdl)
+      
 #endif
       !
@@ -980,8 +1104,6 @@
       ELSE
 #if defined key_iomput
-         IF(lwp) WRITE(numout,*) 'XIOS RST READ (0D): ', trim(cdvar)
-         CALL iom_swap( TRIM(crxios_context) )
+         IF(lwp) WRITE(numout,*) 'XIOS READ (0D): ', trim(cdvar)
          CALL xios_recv_field( trim(cdvar), pvar)
-         CALL iom_swap( TRIM(cxios_context) )
 #else
          WRITE(ctmp1,*) 'Can not use XIOS in iom_g0d, file: '//trim(clname)//', var:'//trim(cdvar)
@@ -1334,8 +1456,7 @@
 #if defined key_iomput
 !would be good to be able to check which context is active and swap only if current is not restart
-         CALL iom_swap( TRIM(crxios_context) ) 
          IF( PRESENT(pv_r3d) ) THEN
             pv_r3d(:, :, :) = 0.
-            if(lwp) write(numout,*) 'XIOS RST READ (3D): ',trim(cdvar)
+            if(lwp) write(numout,*) 'XIOS READ (3D): ',trim(cdvar)
             CALL xios_recv_field( trim(cdvar), pv_r3d)
             IF(idom /= jpdom_unknown ) then
@@ -1344,5 +1465,5 @@
          ELSEIF( PRESENT(pv_r2d) ) THEN
             pv_r2d(:, :) = 0.
-            if(lwp) write(numout,*) 'XIOS RST READ (2D): ', trim(cdvar)
+            if(lwp) write(numout,*) 'XIOS READ (2D): ', trim(cdvar)
             CALL xios_recv_field( trim(cdvar), pv_r2d)
             IF(idom /= jpdom_unknown ) THEN
@@ -1351,8 +1472,7 @@
          ELSEIF( PRESENT(pv_r1d) ) THEN
             pv_r1d(:) = 0.
-            if(lwp) write(numout,*) 'XIOS RST READ (1D): ', trim(cdvar)
+            if(lwp) write(numout,*) 'XIOS READ (1D): ', trim(cdvar)
             CALL xios_recv_field( trim(cdvar), pv_r1d)
          ENDIF
-         CALL iom_swap( TRIM(cxios_context) )
 #else
          istop = istop + 1 
@@ -1394,4 +1514,72 @@
    END SUBROUTINE iom_get_var
 
+   SUBROUTINE iom_dom_context(fdname, numr)  
+      !!-----------------------------------------------------------------------
+      !!                  ***  FUNCTION  iom_getszuld  ***
+      !!
+      !! ** Purpose : initialize context for reading domain information
+      !!-----------------------------------------------------------------------
+      INTEGER, PARAMETER                   :: maxf = 48
+      CHARACTER(len=*), INTENT(IN)         :: fdname
+      INTEGER,          INTENT(IN)         :: numr
+      !local variables
+      CHARACTER(len=lc)                    :: cxname
+      CHARACTER(len=lc)                    :: cfile
+      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 
+      TYPE(xios_field) :: field_hdl
+      TYPE(xios_file) :: file_hdl
+      TYPE(xios_filegroup) :: filegroup_hdl
+      TYPE(xios_duration) :: dtime    = xios_duration(0, 0, 0, 0, 0, 0)
+      INTEGER :: i
+      INTEGER :: ni
+      INTEGER :: nj
+      !!-----------------------------------------------------------------------
+
+#if defined key_iomput
+      cxname = "dom_context"
+      IF( TRIM(Agrif_CFixed()) .NE. '0' ) THEN
+         CALL xios_context_initialize(TRIM(Agrif_CFixed())//"_"//TRIM(cxname), mpi_comm_oce)
+      ELSE
+         CALL xios_context_initialize(TRIM(cxname), mpi_comm_oce)
+      ENDIF
+      CALL iom_swap( cxname )
+!calendar must be defined always
+      CALL xios_define_calendar( TYPE = "NoLeap"   , time_origin = xios_date(1,1,1,00,00,00), &
+          &                                    start_date = xios_date(1,1,1,0,0,0) )
+     CALL xios_get_handle("domain_definition",domaingroup_hdl) 
+     CALL xios_add_child(domaingroup_hdl, domain_hdl, "grid_N") 
+     ni = nlei-nldi+1
+     nj = nlej-nldj+1
+     !
+     CALL iom_set_domain_attr("grid_N", ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj)
+     CALL iom_set_domain_attr("grid_N", data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
+ 
+     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 in meters", positive="down")
+     CALL xios_set_axis_attr ("nav_lev", n_glo=jpk )
+
+     CALL xios_get_handle("scalar_definition", scalargroup_hdl) 
+     CALL xios_add_child(scalargroup_hdl, scalar_hdl, "grid_scalar") 
+
+     IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+        cfile = TRIM(fdname)
+     ELSE
+        cfile = TRIM(Agrif_CFixed())//"_"//TRIM(fdname)
+     ENDIF
+     CALL iom_set_vars_active(cfile, iom_file(numr)%nfid)
+    ! set time step length
+     dtime%second = rn_Dt
+     CALL xios_set_timestep( dtime )
+
+     CALL iom_init_closedef
+#endif
+   END SUBROUTINE iom_dom_context
 
    FUNCTION iom_getszuld ( kiomid )  
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/iom_def.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/iom_def.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/iom_def.F90	(revision 13016)
@@ -9,4 +9,5 @@
    !!----------------------------------------------------------------------
    USE par_kind
+   USE netcdf
 
    IMPLICIT NONE
@@ -45,4 +46,6 @@
    LOGICAL, PUBLIC            ::   lxios_sini = .FALSE. ! is restart in a single file
    LOGICAL, PUBLIC            ::   lxios_set  = .FALSE. 
+!XIOS configuration read
+   LOGICAL, PUBLIC            ::   lcfg_xios       !: read configuration using XIOS
 
 
@@ -73,4 +76,7 @@
     LOGICAL           :: active =.FALSE. ! for restart write only: true - write field, false do not write field
    END TYPE RST_FIELD
+!metadata in restart file for restart read with XIOS
+   INTEGER, PUBLIC, PARAMETER :: NMETA = 10
+   CHARACTER(LEN=nf90_max_name), PUBLIC :: meta(NMETA)
 !$AGRIF_END_DO_NOT_TREAT
    !
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/iom_nf90.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/iom_nf90.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/iom_nf90.F90	(revision 13016)
@@ -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_12905_xios_ancil/src/OCE/IOM/restart.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/restart.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/IOM/restart.F90	(revision 13016)
@@ -243,5 +243,5 @@
 
       CALL rst_read_open           ! open restart for reading (if not already opened)
-
+      IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
       ! Check dynamics and tracer time-step consistency and force Euler restart if changed
       IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
@@ -304,4 +304,5 @@
       ENDIF
       !
+      IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
    END SUBROUTINE rst_read
 
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ISF/isfcpl.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ISF/isfcpl.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ISF/isfcpl.F90	(revision 13016)
@@ -166,5 +166,7 @@
       !!----------------------------------------------------------------------
       !
+      IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
       CALL iom_get( numror, jpdom_autoglo, 'ssmask'  , zssmask_b, ldxios = lrxios   ) ! need to extrapolate T/S
+      IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
 
       ! compute new ssh if we open a full water column 
@@ -244,8 +246,10 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk,jpts) :: zts0
       !!----------------------------------------------------------------------
-      ! 
+      !
+      IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
       CALL iom_get( numror, jpdom_autoglo, 'tmask'  , ztmask_b, ldxios = lrxios   ) ! need to extrapolate T/S
       !CALL iom_get( numror, jpdom_autoglo, 'wmask'  , zwmask_b, ldxios = lrxios   ) ! need to extrapolate T/S
       !CALL iom_get( numror, jpdom_autoglo, 'gdepw_n', zdepw_b(:,:,:), ldxios = lrxios ) ! need to interpol vertical profile (vvl)
+      IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
       !
       ! 
@@ -391,7 +395,9 @@
       !!----------------------------------------------------------------------
       !
+      IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
       CALL iom_get( numror, jpdom_autoglo, 'tmask'  , ztmask_b, ldxios = lrxios )
       CALL iom_get( numror, jpdom_autoglo, 'e3u_n'  , ze3u_b  , ldxios = lrxios )
       CALL iom_get( numror, jpdom_autoglo, 'e3v_n'  , ze3v_b  , ldxios = lrxios )
+      IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
       !
       ! 1.0: compute horizontal volume flux divergence difference before-after coupling
@@ -495,8 +501,10 @@
 
       ! get restart variable
+      IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
       CALL iom_get( numror, jpdom_autoglo, 'tmask'  , ztmask_b(:,:,:), ldxios = lrxios   ) ! need to extrapolate T/S
       CALL iom_get( numror, jpdom_autoglo, 'e3t_n'  , ze3t_b(:,:,:)  , ldxios = lrxios )
       CALL iom_get( numror, jpdom_autoglo, 'tn'     , zt_b(:,:,:)    , ldxios = lrxios )
       CALL iom_get( numror, jpdom_autoglo, 'sn'     , zs_b(:,:,:)    , ldxios = lrxios )
+      IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
 
       ! compute run length
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ISF/isfrst.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ISF/isfrst.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ISF/isfrst.F90	(revision 13016)
@@ -52,8 +52,10 @@
       ! read restart
       IF( iom_varid( numror, cfwf_b, ldstop = .FALSE. ) > 0 ) THEN
+         IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
          IF(lwp) WRITE(numout,*) '          nit000-1 isf tracer content forcing fields read in the restart file'
          CALL iom_get( numror, jpdom_autoglo, cfwf_b, pfwf_b(:,:)        , ldxios = lrxios )   ! before ice shelf melt
          CALL iom_get( numror, jpdom_autoglo, chc_b , ptsc_b (:,:,jp_tem), ldxios = lrxios )   ! before ice shelf heat flux
          CALL iom_get( numror, jpdom_autoglo, csc_b , ptsc_b (:,:,jp_sal), ldxios = lrxios )   ! before ice shelf heat flux
+         IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
       ELSE
          pfwf_b(:,:)   = pfwf(:,:)
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcapr.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcapr.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcapr.F90	(revision 13016)
@@ -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
@@ -154,5 +153,7 @@
          IF( ln_rstart .AND. iom_varid( numror, 'ssh_ibb', ldstop = .FALSE. ) > 0 ) THEN 
             IF(lwp) WRITE(numout,*) 'sbc_apr:   ssh_ibb read in the restart file'
+            IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
             CALL iom_get( numror, jpdom_autoglo, 'ssh_ibb', ssh_ibb, ldxios = lrxios )   ! before inv. barometer ssh
+            IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
             !
          ELSE                                         !* no restart: set from nit000 values
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcmod.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcmod.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcmod.F90	(revision 13016)
@@ -517,4 +517,5 @@
             & iom_varid( numror, 'utau_b', ldstop = .FALSE. ) > 0 ) THEN
             IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields red in the restart file'
+            IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
             CALL iom_get( numror, jpdom_autoglo, 'utau_b', utau_b, ldxios = lrxios )   ! before i-stress  (U-point)
             CALL iom_get( numror, jpdom_autoglo, 'vtau_b', vtau_b, ldxios = lrxios )   ! before j-stress  (V-point)
@@ -529,4 +530,5 @@
                sfx_b (:,:) = sfx(:,:)
             ENDIF
+            IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
          ELSE                                                   !* no restart: set from nit000 values
             IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields set to nit000'
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcrnf.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcrnf.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcrnf.F90	(revision 13016)
@@ -159,7 +159,9 @@
             & iom_varid( numror, 'rnf_b', ldstop = .FALSE. ) > 0 ) THEN
             IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields red in the restart file', lrxios
+            IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
             CALL iom_get( numror, jpdom_autoglo, 'rnf_b', rnf_b, ldxios = lrxios )     ! before runoff
             CALL iom_get( numror, jpdom_autoglo, 'rnf_hc_b', rnf_tsc_b(:,:,jp_tem), ldxios = lrxios )   ! before heat content of runoff
             CALL iom_get( numror, jpdom_autoglo, 'rnf_sc_b', rnf_tsc_b(:,:,jp_sal), ldxios = lrxios )   ! before salinity content of runoff
+            IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
          ELSE                                                   !* no restart: set from nit000 values
             IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields set to nit000'
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcssm.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcssm.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/SBC/sbcssm.F90	(revision 13016)
@@ -207,4 +207,5 @@
          IF( ln_rstart .AND. iom_varid( numror, 'nn_fsbc', ldstop = .FALSE. ) > 0 ) THEN
             l_ssm_mean = .TRUE.
+            IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
             CALL iom_get( numror               , 'nn_fsbc', zf_sbc, ldxios = lrxios )    ! sbc frequency of previous run
             CALL iom_get( numror, jpdom_autoglo, 'ssu_m'  , ssu_m, ldxios = lrxios  )    ! sea surface mean velocity    (U-point)
@@ -234,4 +235,5 @@
                IF(lwp) WRITE(numout,*) '   mean fields read in the ocean restart file'
             ENDIF
+            IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
          ENDIF
       ENDIF
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/TRA/traqsr.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/TRA/traqsr.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/TRA/traqsr.F90	(revision 13016)
@@ -402,5 +402,7 @@
       ! 1st ocean level attenuation coefficient (used in sbcssm)
       IF( iom_varid( numror, 'fraqsr_1lev', ldstop = .FALSE. ) > 0 ) THEN
+         IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
          CALL iom_get( numror, jpdom_autoglo, 'fraqsr_1lev'  , fraqsr_1lev, ldxios = lrxios  )
+         IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
       ELSE
          fraqsr_1lev(:,:) = 1._wp   ! default : no penetration
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/TRA/trasbc.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/TRA/trasbc.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/TRA/trasbc.F90	(revision 13016)
@@ -108,4 +108,5 @@
          IF( ln_rstart .AND.    &               ! Restart: read in restart file
               & iom_varid( numror, 'sbc_hc_b', ldstop = .FALSE. ) > 0 ) THEN
+            IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
             IF(lwp) WRITE(numout,*) '          nit000-1 sbc tracer content field read in the restart file'
             zfact = 0.5_wp
@@ -113,4 +114,5 @@
             CALL iom_get( numror, jpdom_autoglo, 'sbc_hc_b', sbc_tsc_b(:,:,jp_tem), ldxios = lrxios )   ! before heat content sbc trend
             CALL iom_get( numror, jpdom_autoglo, 'sbc_sc_b', sbc_tsc_b(:,:,jp_sal), ldxios = lrxios )   ! before salt content sbc trend
+            IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
          ELSE                                   ! No restart or restart not found: Euler forward time stepping
             zfact = 1._wp
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdfgls.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdfgls.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdfgls.F90	(revision 13016)
@@ -1059,4 +1059,5 @@
          !                                   ! ---------------
          IF( ln_rstart ) THEN                   !* Read the restart file
+            IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
             id1 = iom_varid( numror, 'en'    , ldstop = .FALSE. )
             id2 = iom_varid( numror, 'avt_k' , ldstop = .FALSE. )
@@ -1076,4 +1077,5 @@
                ! avt_k, avm_k already set to the background value in zdf_phy_init
             ENDIF
+            IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
          ELSE                                   !* Start from rest
             IF(lwp) WRITE(numout,*)
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdfosm.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdfosm.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdfosm.F90	(revision 13016)
@@ -1459,4 +1459,5 @@
      !!-----------------------------------------------------------------------------
      IF( TRIM(cdrw) == 'READ'.AND. ln_rstart) THEN
+        IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
         id1 = iom_varid( numror, 'wn'   , ldstop = .FALSE. )
         IF( id1 > 0 ) THEN                       ! 'wn' exists; read
@@ -1477,4 +1478,5 @@
            WRITE(numout,*) ' ===>>>> : previous run without osmosis scheme, hbl computed from stratification'
         END IF
+        IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
      END IF
 
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdfric.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdfric.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdfric.F90	(revision 13016)
@@ -210,4 +210,5 @@
          !           !* Read the restart file
          IF( ln_rstart ) THEN
+            IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
             id1 = iom_varid( numror, 'avt_k', ldstop = .FALSE. )
             id2 = iom_varid( numror, 'avm_k', ldstop = .FALSE. )
@@ -217,4 +218,5 @@
                CALL iom_get( numror, jpdom_autoglo, 'avm_k', avm_k, ldxios = lrxios )
             ENDIF
+            IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
          ENDIF
          !           !* otherwise Kz already set to the background value in zdf_phy_init
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdftke.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdftke.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/ZDF/zdftke.F90	(revision 13016)
@@ -665,4 +665,5 @@
          !                                   ! ---------------
          IF( ln_rstart ) THEN                   !* Read the restart file
+            IF(lrxios) CALL iom_swap( TRIM(crxios_context) )
             id1 = iom_varid( numror, 'en'   , ldstop = .FALSE. )
             id2 = iom_varid( numror, 'avt_k', ldstop = .FALSE. )
@@ -682,4 +683,5 @@
                ! avt_k, avm_k already set to the background value in zdf_phy_init
             ENDIF
+            IF(lrxios) CALL iom_swap( TRIM(cxios_context) )
          ELSE                                   !* Start from rest
             IF(lwp) WRITE(numout,*)
Index: NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/nemogcm.F90
===================================================================
--- NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/nemogcm.F90	(revision 13003)
+++ NEMO/branches/2020/dev_12905_xios_ancil/src/OCE/nemogcm.F90	(revision 13016)
@@ -273,5 +273,5 @@
          &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,             &
          &             ln_timing, ln_diacfl
-      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
+      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr, ln_xios_cfg
       !!----------------------------------------------------------------------
       !
