Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 8800)
@@ -32,4 +32,5 @@
    USE timing          ! preformance summary
    USE wrk_nemo        ! work arrays
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -255,19 +256,19 @@
            IF(lwp) WRITE(numout,*) ' dia_hsb_rst at it= ', kt,' date= ', ndastp
            IF(lwp) WRITE(numout,*) '~~~~~~~'
-           CALL iom_get( numror, 'frc_v', frc_v )
-           CALL iom_get( numror, 'frc_t', frc_t )
-           CALL iom_get( numror, 'frc_s', frc_s )
+           CALL iom_get( numror, 'frc_v', frc_v, ldxios = lxios_read  )
+           CALL iom_get( numror, 'frc_t', frc_t, ldxios = lxios_read )
+           CALL iom_get( numror, 'frc_s', frc_s, ldxios = lxios_read )
            IF( ln_linssh ) THEN
-              CALL iom_get( numror, 'frc_wn_t', frc_wn_t )
-              CALL iom_get( numror, 'frc_wn_s', frc_wn_s )
+              CALL iom_get( numror, 'frc_wn_t', frc_wn_t, ldxios = lxios_read )
+              CALL iom_get( numror, 'frc_wn_s', frc_wn_s, ldxios = lxios_read )
            ENDIF
-           CALL iom_get( numror, jpdom_autoglo, 'surf_ini', surf_ini ) ! ice sheet coupling
-           CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini(:,:) )
-           CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini(:,:,:) )
-           CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini(:,:,:) )
-           CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini(:,:,:) )
+           CALL iom_get( numror, jpdom_autoglo, 'surf_ini', surf_ini, ldxios = lxios_read ) ! ice sheet coupling
+           CALL iom_get( numror, jpdom_autoglo, 'ssh_ini', ssh_ini(:,:), ldxios = lxios_read )
+           CALL iom_get( numror, jpdom_autoglo, 'e3t_ini', e3t_ini(:,:,:), ldxios = lxios_read )
+           CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini(:,:,:), ldxios = lxios_read )
+           CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini(:,:,:), ldxios = lxios_read )
            IF( ln_linssh ) THEN
-              CALL iom_get( numror, jpdom_autoglo, 'ssh_hc_loc_ini', ssh_hc_loc_ini(:,:) )
-              CALL iom_get( numror, jpdom_autoglo, 'ssh_sc_loc_ini', ssh_sc_loc_ini(:,:) )
+              CALL iom_get( numror, jpdom_autoglo, 'ssh_hc_loc_ini', ssh_hc_loc_ini(:,:), ldxios = lxios_read )
+              CALL iom_get( numror, jpdom_autoglo, 'ssh_sc_loc_ini', ssh_sc_loc_ini(:,:), ldxios = lxios_read )
            ENDIF
        ELSE
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 8800)
@@ -33,4 +33,5 @@
    USE timing         ! Timing
    USE restart        ! restart
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -318,5 +319,5 @@
          IF( iom_varid( numror, 'kt', ldstop = .FALSE. ) > 0 ) THEN
             ! Get Calendar informations
-            CALL iom_get( numror, 'kt', zkt )   ! last time-step of previous run
+            CALL iom_get( numror, 'kt', zkt, ldxios = lxios_read )   ! last time-step of previous run
             IF(lwp) THEN
                WRITE(numout,*) ' *** Info read in restart : '
@@ -337,8 +338,8 @@
             IF ( nrstdt == 2 ) THEN
                ! read the parameters corresponding to nit000 - 1 (last time step of previous run)
-               CALL iom_get( numror, 'ndastp', zndastp )
+               CALL iom_get( numror, 'ndastp', zndastp, ldxios = lxios_read )
                ndastp = NINT( zndastp )
-               CALL iom_get( numror, 'adatrj', adatrj  )
-	       CALL iom_get( numror, 'ntime', ktime )
+               CALL iom_get( numror, 'adatrj', adatrj, ldxios = lxios_read )
+	       CALL iom_get( numror, 'ntime', ktime, ldxios = lxios_read )
 	       nn_time0=INT(ktime)
                ! calculate start time in hours and minutes
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 8800)
@@ -47,4 +47,5 @@
    USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -285,5 +286,5 @@
          &             nn_it000, nn_itend , nn_date0    , nn_time0     , nn_leapy  , nn_istate ,     &
          &             nn_stock, nn_write , ln_mskland  , ln_clobber   , nn_chunksz, nn_euler  ,     &
-         &             ln_cfmeta, ln_iscpl
+         &             ln_cfmeta, ln_iscpl, ln_xios_read
       NAMELIST/namdom/ ln_linssh, nn_closea, nn_msh, rn_isfhmin, rn_rdt, rn_atfp, ln_crs
 #if defined key_netcdf4
@@ -293,4 +294,5 @@
       !!----------------------------------------------------------------------
       !
+      ln_xios_read = .false.            ! set in case ln_xios_read is not in namelist
       REWIND( numnam_ref )              ! Namelist namrun in reference namelist : Parameters of the run
       READ  ( numnam_ref, namrun, IOSTAT = ios, ERR = 901)
@@ -333,4 +335,8 @@
          WRITE(numout,*) '      NetCDF chunksize (bytes)        nn_chunksz = ', nn_chunksz
          WRITE(numout,*) '      IS coupling at the restart step ln_iscpl   = ', ln_iscpl
+         WRITE(numout,*) '      READ restart for a single file using XIOS ln_xios_read =', ln_xios_read
+      IF( TRIM(Agrif_CFixed()) /= '0') THEN
+         WRITE(numout,*) '      READ restart for a single file using XIOS WILL not use AGRIF setting.'
+      ENDIF
       ENDIF
 
@@ -347,4 +353,7 @@
       nwrite = nn_write
       neuler = nn_euler
+      IF( TRIM(Agrif_CFixed()) == '0') THEN 
+       lxios_read = ln_xios_read.AND.ln_rstart
+      ENDIF
       IF ( neuler == 1 .AND. .NOT. ln_rstart ) THEN
          WRITE(ctmp1,*) 'ln_rstart =.FALSE., nn_euler is forced to 0 '
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 8800)
@@ -33,4 +33,5 @@
    USE wrk_nemo        ! Memory allocation
    USE timing          ! Timing
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -799,5 +800,5 @@
          IF( ln_rstart ) THEN                   !* Read the restart file
             CALL rst_read_open                  !  open the restart file if necessary
-            CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn    )
+            CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn, ldxios = lxios_read    )
             !
             id1 = iom_varid( numror, 'e3t_b', ldstop = .FALSE. )
@@ -810,6 +811,6 @@
             !                             ! --------- !
             IF( MIN( id1, id2 ) > 0 ) THEN       ! all required arrays exist
-               CALL iom_get( numror, jpdom_autoglo, 'e3t_b', e3t_b(:,:,:) )
-               CALL iom_get( numror, jpdom_autoglo, 'e3t_n', e3t_n(:,:,:) )
+               CALL iom_get( numror, jpdom_autoglo, 'e3t_b', e3t_b(:,:,:), ldxios = lxios_read )
+               CALL iom_get( numror, jpdom_autoglo, 'e3t_n', e3t_n(:,:,:), ldxios = lxios_read )
                ! needed to restart if land processor not computed 
                IF(lwp) write(numout,*) 'dom_vvl_rst : e3t_b and e3t_n found in restart files'
@@ -825,5 +826,5 @@
                IF(lwp) write(numout,*) 'e3t_n set equal to e3t_b.'
                IF(lwp) write(numout,*) 'neuler is forced to 0'
-               CALL iom_get( numror, jpdom_autoglo, 'e3t_b', e3t_b(:,:,:) )
+               CALL iom_get( numror, jpdom_autoglo, 'e3t_b', e3t_b(:,:,:), ldxios = lxios_read )
                e3t_n(:,:,:) = e3t_b(:,:,:)
                neuler = 0
@@ -832,5 +833,5 @@
                IF(lwp) write(numout,*) 'e3t_b set equal to e3t_n.'
                IF(lwp) write(numout,*) 'neuler is forced to 0'
-               CALL iom_get( numror, jpdom_autoglo, 'e3t_n', e3t_n(:,:,:) )
+               CALL iom_get( numror, jpdom_autoglo, 'e3t_n', e3t_n(:,:,:), ldxios = lxios_read )
                e3t_b(:,:,:) = e3t_n(:,:,:)
                neuler = 0
@@ -857,6 +858,6 @@
                !                          ! ----------------------- !
                IF( MIN( id3, id4 ) > 0 ) THEN  ! all required arrays exist
-                  CALL iom_get( numror, jpdom_autoglo, 'tilde_e3t_b', tilde_e3t_b(:,:,:) )
-                  CALL iom_get( numror, jpdom_autoglo, 'tilde_e3t_n', tilde_e3t_n(:,:,:) )
+                  CALL iom_get( numror, jpdom_autoglo, 'tilde_e3t_b', tilde_e3t_b(:,:,:), ldxios = lxios_read )
+                  CALL iom_get( numror, jpdom_autoglo, 'tilde_e3t_n', tilde_e3t_n(:,:,:), ldxios = lxios_read )
                ELSE                            ! one at least array is missing
                   tilde_e3t_b(:,:,:) = 0.0_wp
@@ -867,5 +868,5 @@
                   !                       ! ------------ !
                   IF( id5 > 0 ) THEN  ! required array exists
-                     CALL iom_get( numror, jpdom_autoglo, 'hdiv_lf', hdiv_lf(:,:,:) )
+                     CALL iom_get( numror, jpdom_autoglo, 'hdiv_lf', hdiv_lf(:,:,:), ldxios = lxios_read )
                   ELSE                ! array is missing
                      hdiv_lf(:,:,:) = 0.0_wp
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90	(revision 8800)
@@ -25,4 +25,5 @@
    USE iscplini        ! ice sheet coupling: initialisation
    USE iscplhsb        ! ice sheet coupling: conservation
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -64,12 +65,12 @@
 
       !! get restart variable
-      CALL iom_get( numror, jpdom_autoglo, 'tmask'  , ztmask_b   ) ! need to extrapolate T/S
-      CALL iom_get( numror, jpdom_autoglo, 'umask'  , zumask_b   ) ! need to correct barotropic velocity
-      CALL iom_get( numror, jpdom_autoglo, 'vmask'  , zvmask_b   ) ! need to correct barotropic velocity
-      CALL iom_get( numror, jpdom_autoglo, 'smask'  , zsmask_b   ) ! need to correct barotropic velocity
-      CALL iom_get( numror, jpdom_autoglo, 'e3t_n'  , ze3t_b(:,:,:) )  ! need to compute temperature correction
-      CALL iom_get( numror, jpdom_autoglo, 'e3u_n'  , ze3u_b(:,:,:) )  ! need to correct barotropic velocity
-      CALL iom_get( numror, jpdom_autoglo, 'e3v_n'  , ze3v_b(:,:,:) )  ! need to correct barotropic velocity
-      CALL iom_get( numror, jpdom_autoglo, 'gdepw_n', zdepw_b(:,:,:) ) ! need to interpol vertical profile (vvl)
+      CALL iom_get( numror, jpdom_autoglo, 'tmask'  , ztmask_b, ldxios = lxios_read   ) ! need to extrapolate T/S
+      CALL iom_get( numror, jpdom_autoglo, 'umask'  , zumask_b, ldxios = lxios_read   ) ! need to correct barotropic velocity
+      CALL iom_get( numror, jpdom_autoglo, 'vmask'  , zvmask_b, ldxios = lxios_read   ) ! need to correct barotropic velocity
+      CALL iom_get( numror, jpdom_autoglo, 'smask'  , zsmask_b, ldxios = lxios_read   ) ! need to correct barotropic velocity
+      CALL iom_get( numror, jpdom_autoglo, 'e3t_n'  , ze3t_b(:,:,:), ldxios = lxios_read )  ! need to compute temperature correction
+      CALL iom_get( numror, jpdom_autoglo, 'e3u_n'  , ze3u_b(:,:,:), ldxios = lxios_read )  ! need to correct barotropic velocity
+      CALL iom_get( numror, jpdom_autoglo, 'e3v_n'  , ze3v_b(:,:,:), ldxios = lxios_read )  ! need to correct barotropic velocity
+      CALL iom_get( numror, jpdom_autoglo, 'gdepw_n', zdepw_b(:,:,:), ldxios = lxios_read ) ! need to interpol vertical profile (vvl)
 
       !! read namelist
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 8800)
@@ -56,4 +56,5 @@
    USE asminc          ! Assimilation increment
 #endif
+   USE iom_def, ONLY : lxios_read
 
 
@@ -1198,19 +1199,19 @@
       !
       IF( TRIM(cdrw) == 'READ' ) THEN
-         CALL iom_get( numror, jpdom_autoglo, 'ub2_b'  , ub2_b  (:,:) )   
-         CALL iom_get( numror, jpdom_autoglo, 'vb2_b'  , vb2_b  (:,:) ) 
+         CALL iom_get( numror, jpdom_autoglo, 'ub2_b'  , ub2_b  (:,:), ldxios = lxios_read )   
+         CALL iom_get( numror, jpdom_autoglo, 'vb2_b'  , vb2_b  (:,:), ldxios = lxios_read ) 
          IF( .NOT.ln_bt_av ) THEN
-            CALL iom_get( numror, jpdom_autoglo, 'sshbb_e'  , sshbb_e(:,:) )   
-            CALL iom_get( numror, jpdom_autoglo, 'ubb_e'    ,   ubb_e(:,:) )   
-            CALL iom_get( numror, jpdom_autoglo, 'vbb_e'    ,   vbb_e(:,:) )
-            CALL iom_get( numror, jpdom_autoglo, 'sshb_e'   ,  sshb_e(:,:) ) 
-            CALL iom_get( numror, jpdom_autoglo, 'ub_e'     ,    ub_e(:,:) )   
-            CALL iom_get( numror, jpdom_autoglo, 'vb_e'     ,    vb_e(:,:) )
+            CALL iom_get( numror, jpdom_autoglo, 'sshbb_e'  , sshbb_e(:,:), ldxios = lxios_read )   
+            CALL iom_get( numror, jpdom_autoglo, 'ubb_e'    ,   ubb_e(:,:), ldxios = lxios_read )   
+            CALL iom_get( numror, jpdom_autoglo, 'vbb_e'    ,   vbb_e(:,:), ldxios = lxios_read )
+            CALL iom_get( numror, jpdom_autoglo, 'sshb_e'   ,  sshb_e(:,:), ldxios = lxios_read ) 
+            CALL iom_get( numror, jpdom_autoglo, 'ub_e'     ,    ub_e(:,:), ldxios = lxios_read )   
+            CALL iom_get( numror, jpdom_autoglo, 'vb_e'     ,    vb_e(:,:), ldxios = lxios_read )
          ENDIF
 #if defined key_agrif
          ! Read time integrated fluxes
          IF ( .NOT.Agrif_Root() ) THEN
-            CALL iom_get( numror, jpdom_autoglo, 'ub2_i_b'  , ub2_i_b(:,:) )   
-            CALL iom_get( numror, jpdom_autoglo, 'vb2_i_b'  , vb2_i_b(:,:) )
+            CALL iom_get( numror, jpdom_autoglo, 'ub2_i_b'  , ub2_i_b(:,:), ldxios = lxios_read )   
+            CALL iom_get( numror, jpdom_autoglo, 'vb2_i_b'  , vb2_i_b(:,:), ldxios = lxios_read )
          ENDIF
 #endif
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 8800)
@@ -44,4 +44,5 @@
    LOGICAL       ::   ln_clobber       !: clobber (overwrite) an existing file
    INTEGER       ::   nn_chunksz       !: chunksize (bytes) for NetCDF file (works only with iom_nf90 routines)
+   LOGICAL       ::   ln_xios_read     !: use xios to read single file restart
 
 #if defined key_netcdf4
@@ -150,4 +151,5 @@
    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
 
    !!----------------------------------------------------------------------
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 8800)
@@ -41,7 +41,9 @@
    USE dianam          ! build name of file
    USE xios
+   USE iom_def, ONLY : max_rst_fields, rst_fields
 # endif
    USE ioipsl, ONLY :  ju2ymds    ! for calendar
    USE crs             ! Grid coarsening
+   USE lib_fortran 
 
    IMPLICIT NONE
@@ -63,4 +65,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_update_file_name, iom_sdate
+   PRIVATE set_rst_vars, set_rstr_active, set_rst_context
 # endif
 
@@ -103,4 +106,5 @@
       CHARACTER(len=10) :: clname
       INTEGER           :: ji, jkmin
+      LOGICAL :: llrst_context              ! is context related to restart
       !
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zt_bnds, zw_bnds
@@ -113,5 +117,5 @@
       CALL xios_context_initialize(TRIM(clname), mpi_comm_opa)
       CALL iom_swap( cdname )
-
+      llrst_context =  (TRIM(cdname) == TRIM(crxios_context))
 
       ! Calendar type is now defined in xml file 
@@ -126,11 +130,11 @@
 
       ! horizontal grid definition
-      CALL set_scalar
+      IF(.NOT.llrst_context) CALL set_scalar
 
       IF( TRIM(cdname) == TRIM(cxios_context) ) THEN  
-         CALL set_grid( "T", glamt, gphit ) 
-         CALL set_grid( "U", glamu, gphiu )
-         CALL set_grid( "V", glamv, gphiv )
-         CALL set_grid( "W", glamt, gphit )
+         CALL set_grid( "T", glamt, gphit, .FALSE. ) 
+         CALL set_grid( "U", glamu, gphiu, .FALSE. )
+         CALL set_grid( "V", glamv, gphiv, .FALSE. )
+         CALL set_grid( "W", glamt, gphit, .FALSE. )
          CALL set_grid_znl( gphit )
          !
@@ -150,13 +154,13 @@
          CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
          !
-         CALL set_grid( "T", glamt_crs, gphit_crs ) 
-         CALL set_grid( "U", glamu_crs, gphiu_crs ) 
-         CALL set_grid( "V", glamv_crs, gphiv_crs ) 
-         CALL set_grid( "W", glamt_crs, gphit_crs ) 
+         CALL set_grid( "T", glamt_crs, gphit_crs, .FALSE. ) 
+         CALL set_grid( "U", glamu_crs, gphiu_crs, .FALSE. ) 
+         CALL set_grid( "V", glamv_crs, gphiv_crs, .FALSE. ) 
+         CALL set_grid( "W", glamt_crs, gphit_crs, .FALSE. ) 
          CALL set_grid_znl( gphit_crs )
           !
          CALL dom_grid_glo   ! Return to parent grid domain
          !
-         IF( ln_cfmeta ) THEN   ! Add additional grid metadata
+         IF( ln_cfmeta .AND. TRIM(cdname) .NE. TRIM(crxios_context)) THEN   ! Add additional grid metadata
             CALL iom_set_domain_attr("grid_T", area = e1e2t_crs(nldi:nlei, nldj:nlej))
             CALL iom_set_domain_attr("grid_U", area = e1u_crs(nldi:nlei, nldj:nlej) * e2u_crs(nldi:nlei, nldj:nlej))
@@ -171,35 +175,44 @@
 
       ! vertical grid definition
-      CALL iom_set_axis_attr( "deptht", gdept_1d )
-      CALL iom_set_axis_attr( "depthu", gdept_1d )
-      CALL iom_set_axis_attr( "depthv", gdept_1d )
-      CALL iom_set_axis_attr( "depthw", gdepw_1d )
-
-      ! Add vertical grid bounds
-      jkmin = MIN(2,jpk)  ! in case jpk=1 (i.e. sas2D)
-      zt_bnds(2,:        ) = gdept_1d(:)
-      zt_bnds(1,jkmin: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(jkmin:jpk)
-      zw_bnds(2,jpk:     ) = gdepw_1d(jpk) + e3t_1d(jpk)
-      CALL iom_set_axis_attr( "deptht", bounds=zt_bnds )
-      CALL iom_set_axis_attr( "depthu", bounds=zt_bnds )
-      CALL iom_set_axis_attr( "depthv", bounds=zt_bnds )
-      CALL iom_set_axis_attr( "depthw", bounds=zw_bnds )
+      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 )
+
+          ! Add vertical grid bounds
+          jkmin = MIN(2,jpk)  ! in case jpk=1 (i.e. sas2D)
+          zt_bnds(2,:        ) = gdept_1d(:)
+          zt_bnds(1,jkmin: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(jkmin:jpk)
+          zw_bnds(2,jpk:     ) = gdepw_1d(jpk) + e3t_1d(jpk)
+          CALL iom_set_axis_attr( "deptht", bounds=zt_bnds )
+          CALL iom_set_axis_attr( "depthu", bounds=zt_bnds )
+          CALL iom_set_axis_attr( "depthv", bounds=zt_bnds )
+          CALL iom_set_axis_attr( "depthw", bounds=zw_bnds )
 
 
 # if defined key_floats
-      CALL iom_set_axis_attr( "nfloat", (/ (REAL(ji,wp), ji=1,nfloat) /) )
+          CALL iom_set_axis_attr( "nfloat", (/ (REAL(ji,wp), ji=1,nfloat) /) )
 # endif
 #if defined key_lim3 || defined key_lim2
-      CALL iom_set_axis_attr( "ncatice", (/ (REAL(ji,wp), ji=1,jpl) /) )
+          CALL iom_set_axis_attr( "ncatice", (/ (REAL(ji,wp), ji=1,jpl) /) )
 #endif
-      CALL iom_set_axis_attr( "icbcla", class_num )
-      CALL iom_set_axis_attr( "iax_20C", (/ REAL(20,wp) /) )
-      CALL iom_set_axis_attr( "iax_28C", (/ REAL(28,wp) /) )
-      
+          CALL iom_set_axis_attr( "icbcla", class_num )
+          CALL iom_set_axis_attr( "iax_20C", (/ REAL(20,wp) /) )
+          CALL iom_set_axis_attr( "iax_28C", (/ REAL(28,wp) /) )
+      ENDIF   
       ! automatic definitions of some of the xml attributs
-      CALL set_xmlatt
+      IF( llrst_context ) THEN
+!set names of the fields in restart file IF using XIOS to read/write data
+       CALL set_rst_context()
+       CALL set_rst_vars()
+!set which fields are to be read from restart file
+       CALL set_rstr_active()
+      ELSE
+       CALL set_xmlatt
+      ENDIF
 
       ! end file definition
@@ -213,7 +226,186 @@
 
 #endif
-      
+
    END SUBROUTINE iom_init
 
+   
+   SUBROUTINE set_rst_vars()
+!set names for variables in restart file
+   INTEGER :: i
+        rst_fields(:)%vname="NO_NAME";         rst_fields(:)%grid="NO_GRID"
+        i = 0
+        i = i + 1; rst_fields(i)%vname="rdt";            rst_fields(i)% grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="un";             rst_fields(i)% grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="ub";             rst_fields(i)% grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="vn";             rst_fields(i)% grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="vb";             rst_fields(i)% grid="grid_N_3D"  
+        i = i + 1; rst_fields(i)%vname="tn";             rst_fields(i)% grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="tb";             rst_fields(i)% grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="sn";             rst_fields(i)% grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="sb";             rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="sshn";           rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="sshb";           rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="rhop";           rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="kt";             rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="ndastp";         rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="adatrj";         rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="utau_b";         rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="vtau_b";         rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="qns_b";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="emp_b";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="sfx_b";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="en" ;            rst_fields(i)%grid="grid_N_3D" 
+        i = i + 1; rst_fields(i)%vname="avt";            rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="avm";            rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="avmu";           rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="avmv";           rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="dissl";          rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="sbc_hc_b";       rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="sbc_sc_b";       rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="qsr_hc_b";       rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="fraqsr_1lev";    rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="greenland_icesheet_mass"
+                                               rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="greenland_icesheet_timelapsed"
+                                               rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="greenland_icesheet_mass_roc"
+                                               rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="antarctica_icesheet_mass"
+                                               rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="antarctica_icesheet_timelapsed"
+                                               rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="antarctica_icesheet_mass_roc"
+                                               rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="frc_v";          rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="frc_t";          rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="frc_s";          rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="frc_wn_t";       rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="frc_wn_s";       rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="ssh_ini";        rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="e3t_ini";        rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="hc_loc_ini";     rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="sc_loc_ini";     rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="ssh_hc_loc_ini"; rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="ssh_sc_loc_ini"; rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="tilde_e3t_b";    rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="tilde_e3t_n";    rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="hdiv_lf";        rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="ub2_b";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="vb2_b";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="sshbb_e";        rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="ubb_e";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="vbb_e";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="sshb_e";         rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="ub_e";           rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="vb_e";           rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="fwf_isf_b";      rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="isf_sc_b";       rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="isf_hc_b";       rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="ssh_ibb";        rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="rnf_b";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="rnf_hc_b";       rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="rnf_sc_b";       rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="nn_fsbc";        rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="ssu_m";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="ssv_m";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="sst_m";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="sss_m";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="ssh_m";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="e3t_m";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="frq_m";          rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="avmb";           rst_fields(i)%grid="grid_vector"
+        i = i + 1; rst_fields(i)%vname="avtb";           rst_fields(i)%grid="grid_vector"
+        i = i + 1; rst_fields(i)%vname="ub2_i_b";        rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="vb2_i_b";        rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="ntime";          rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="Dsst";           rst_fields(i)%grid="grid_scalar"
+        i = i + 1; rst_fields(i)%vname="tmask";          rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="umask";          rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="vmask";          rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="smask";          rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="gdepw_n";        rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="e3t_n";          rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="e3u_n";          rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="e3v_n";          rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="surf_ini";       rst_fields(i)%grid="grid_N"
+        i = i + 1; rst_fields(i)%vname="e3t_b";          rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="e3t_n";          rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="mxln";           rst_fields(i)%grid="grid_N_3D"
+        i = i + 1; rst_fields(i)%vname="e3t_m";          rst_fields(i)%grid="grid_N_3D"
+   END SUBROUTINE set_rst_vars
+
+
+   SUBROUTINE set_rstr_active()
+!sets enabled = .TRUE. for each field in restart file
+   CHARACTER(len=256) :: rst_file
+   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)//'1_'//TRIM(cn_ocerst_in)
+        ENDIF
+!set name of the restart file and enable available fields
+        if(lwp) WRITE(numout,*) 'Setting restart filename (for XIOS) to: ',rst_file
+        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)
+!defin files for restart context
+        DO i = 1, max_rst_fields
+         IF( TRIM(rst_fields(i)%vname) /= "NO_NAME") THEN
+           IF( iom_varid( numror, TRIM(rst_fields(i)%vname), ldstop = .FALSE. ) > 0 ) THEN
+                CALL xios_add_child(file_hdl, field_hdl, TRIM(rst_fields(i)%vname))
+                SELECT CASE (TRIM(rst_fields(i)%grid))
+                 CASE ("grid_N_3D")
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_fields(i)%vname), &
+                        domain_ref="grid_N", axis_ref="deptht", operation = "instant")
+                 CASE ("grid_N")
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_fields(i)%vname), &
+                        domain_ref="grid_N", operation = "instant") 
+                CASE ("grid_vector")
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_fields(i)%vname), &
+                         axis_ref="deptht", operation = "instant")
+                 CASE ("grid_scalar")
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_fields(i)%vname), &
+                        scalar_ref = "grid_scalar", operation = "instant")
+                END SELECT
+                IF(lwp) WRITE(numout,*) 'XIOS read: ', TRIM(rst_fields(i)%vname), ' enabled in ', TRIM(rst_file)
+           ENDIF
+         ENDIF
+        END DO
+   END SUBROUTINE set_rstr_active
+
+   SUBROUTINE set_rst_context( ) 
+#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.) 
+ 
+     CALL xios_get_handle("axis_definition",axisgroup_hdl) 
+     CALL xios_add_child(axisgroup_hdl, axis_hdl, "deptht") 
+!AGRIF fails to compile when unit= is in call to xios_set_axis_attr
+!    CALL xios_set_axis_attr( "deptht", long_name="Vertical levels",  unit="m", positive="down") 
+     CALL xios_set_axis_attr( "deptht", long_name="Vertical levels in meters", positive="down")
+     CALL iom_set_axis_attr( "deptht", paxis = gdept_1d ) 
+
+     CALL xios_get_handle("scalar_definition", scalargroup_hdl) 
+     CALL xios_add_child(scalargroup_hdl, scalar_hdl, "grid_scalar") 
+#endif
+   END SUBROUTINE set_rst_context
 
    SUBROUTINE iom_swap( cdname )
@@ -347,4 +539,6 @@
             icnt = icnt + 1
          END DO
+      ELSE
+         lxios_sini = .TRUE.
       ENDIF
       IF( llwrt ) THEN
@@ -530,9 +724,10 @@
    !!                   INTERFACE iom_get
    !!----------------------------------------------------------------------
-   SUBROUTINE iom_g0d( kiomid, cdvar, pvar, ktime )
+   SUBROUTINE iom_g0d( kiomid, cdvar, pvar, ktime, ldxios )
       INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
       CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
       REAL(wp)        , 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
@@ -542,30 +737,41 @@
       CHARACTER(LEN=100)                              ::   clname    ! file name
       CHARACTER(LEN=1)                                ::   cldmspc   !
-      !
-      itime = 1
-      IF( PRESENT(ktime) ) itime = ktime
-      !
-      clname = iom_file(kiomid)%name
-      clinfo = '          iom_g0d, file: '//trim(clname)//', var: '//trim(cdvar)
-      !
-      IF( kiomid > 0 ) THEN
-         idvar = iom_varid( kiomid, cdvar )
-         IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
-            idmspc = iom_file ( kiomid )%ndims( idvar )
-            IF( iom_file(kiomid)%luld(idvar) )  idmspc = idmspc - 1
-            WRITE(cldmspc , fmt='(i1)') idmspc
-            IF( idmspc > 0 )  CALL ctl_stop( TRIM(clinfo), 'When reading to a 0D array, we do not accept data', &
-                                 &                         'with 1 or more spatial dimensions: '//cldmspc//' were found.' , &
-                                 &                         'Use ncwa -a to suppress the unnecessary dimensions' )
-            SELECT CASE (iom_file(kiomid)%iolib)
-            CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar, itime )
-            CASE DEFAULT
-               CALL ctl_stop( 'iom_g0d: accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
-            END SELECT
-         ENDIF
+      LOGICAL                                         ::   llxios
+      !
+      llxios = .FALSE.
+      IF( PRESENT(ldxios) ) llxios = ldxios
+
+      IF(.NOT.llxios) THEN  ! read data using default library
+         itime = 1
+         IF( PRESENT(ktime) ) itime = ktime
+         !
+         clname = iom_file(kiomid)%name
+         clinfo = '          iom_g0d, file: '//trim(clname)//', var: '//trim(cdvar)
+         !
+         IF( kiomid > 0 ) THEN
+            idvar = iom_varid( kiomid, cdvar )
+            IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
+               idmspc = iom_file ( kiomid )%ndims( idvar )
+               IF( iom_file(kiomid)%luld(idvar) )  idmspc = idmspc - 1
+               WRITE(cldmspc , fmt='(i1)') idmspc
+               IF( idmspc > 0 )  CALL ctl_stop( TRIM(clinfo), 'When reading to a 0D array, we do not accept data', &
+                                    &                         'with 1 or more spatial dimensions: '//cldmspc//' were found.' , &
+                                    &                         'Use ncwa -a to suppress the unnecessary dimensions' )
+               SELECT CASE (iom_file(kiomid)%iolib)
+               CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar, itime )
+               CASE DEFAULT
+                  CALL ctl_stop( 'iom_g0d: accepted IO library is only jpnf90 (jpioipsl option has been removed)' )
+               END SELECT
+            ENDIF
+         ENDIF
+      ELSE
+         IF(lwp) WRITE(numout,*) 'XIOS RST READ (0D): ', trim(cdvar)
+         CALL iom_swap( TRIM(crxios_context) )
+         CALL xios_recv_field( trim(cdvar), pvar)
+         CALL iom_swap( TRIM(cxios_context) )
       ENDIF
    END SUBROUTINE iom_g0d
 
-   SUBROUTINE iom_g1d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
+   SUBROUTINE iom_g1d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, ldxios )
       INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
       INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
@@ -575,12 +781,14 @@
       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 )
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount, &
+              &                                                     ldxios=ldxios )
       ENDIF
    END SUBROUTINE iom_g1d
 
-   SUBROUTINE iom_g2d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lrowattr )
+   SUBROUTINE iom_g2d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lrowattr, ldxios)
       INTEGER         , INTENT(in   )                           ::   kiomid    ! Identifier of the file
       INTEGER         , INTENT(in   )                           ::   kdom      ! Type of domain to be read
@@ -594,13 +802,14 @@
                                                                                ! called open_ocean_jstart to set the start
                                                                                ! value for the 2nd dimension (netcdf only)
+      LOGICAL         , INTENT(in   ),                 OPTIONAL ::   ldxios    ! read data using XIOS
       !
       IF( kiomid > 0 ) THEN
          IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   &
               &                                                     ktime=ktime, kstart=kstart, kcount=kcount, &
-              &                                                     lrowattr=lrowattr )
+              &                                                     lrowattr=lrowattr,  ldxios=ldxios)
       ENDIF
    END SUBROUTINE iom_g2d
 
-   SUBROUTINE iom_g3d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lrowattr )
+   SUBROUTINE iom_g3d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount, lrowattr, ldxios )
       INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file
       INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read
@@ -614,9 +823,10 @@
                                                                                  ! called open_ocean_jstart to set the start
                                                                                  ! value for the 2nd dimension (netcdf only)
+      LOGICAL         , INTENT(in   ),                   OPTIONAL ::   ldxios    ! read data using XIOS
       !
       IF( kiomid > 0 ) THEN
          IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   &
               &                                                     ktime=ktime, kstart=kstart, kcount=kcount, &
-              &                                                     lrowattr=lrowattr )
+              &                                                     lrowattr=lrowattr, ldxios=ldxios )
       ENDIF
    END SUBROUTINE iom_g3d
@@ -626,5 +836,5 @@
          &                  pv_r1d, pv_r2d, pv_r3d,   &
          &                  ktime , kstart, kcount,   &
-         &                  lrowattr                )
+         &                  lrowattr, ldxios        )
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_get_123d  ***
@@ -647,5 +857,7 @@
                                                                            ! called open_ocean_jstart to set the start
                                                                            ! value for the 2nd dimension (netcdf only)
-      !
+      LOGICAL                    , INTENT(in   ), OPTIONAL ::   ldxios     ! use XIOS to read restart
+      !
+      LOGICAL                        ::   llxios       ! local definition for XIOS read
       LOGICAL                        ::   llnoov      ! local definition to read overlap
       LOGICAL                        ::   luse_jattr  ! local definition to read open_ocean_jstart file attribute
@@ -674,15 +886,21 @@
       !---------------------------------------------------------------------
       !
-      clname = iom_file(kiomid)%name   !   esier to read
-      clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
-      ! local definition of the domain ?
+      REAL(wp)                       :: gma, gmi
+      llxios = .FALSE.
+      if(PRESENT(ldxios)) llxios = ldxios
+      idvar = iom_varid( kiomid, cdvar ) 
       idom = kdom
-      ! do we read the overlap 
-      ! ugly patch SM+JMM+RB to overwrite global definition in some cases
-      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
-      ! check kcount and kstart optionals parameters...
-      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
-      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
-      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown .AND.  idom /= jpdom_autoglo_xy  ) &
+
+      IF(.NOT.llxios) THEN
+          clname = iom_file(kiomid)%name   !   esier to read
+          clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
+          ! local definition of the domain ?
+          ! do we read the overlap 
+          ! ugly patch SM+JMM+RB to overwrite global definition in some cases
+          llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif 
+          ! check kcount and kstart optionals parameters...
+          IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
+          IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
+          IF( PRESENT(kstart) .AND. idom /= jpdom_unknown .AND.  idom /= jpdom_autoglo_xy  ) &
      &           CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown or kdom = jpdom_autoglo_xy')
 
@@ -701,76 +919,75 @@
       ENDIF
 
-      ! Search for the variable in the data base (eventually actualize data)
-      istop = nstop
-      idvar = iom_varid( kiomid, cdvar )
-      !
-      IF( idvar > 0 ) THEN
-         ! to write iom_file(kiomid)%dimsz in a shorter way !
-         idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) 
-         inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
-         idmspc = inbdim                                   ! number of spatial dimensions in the file
-         IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
-         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
-         !
-         ! update idom definition...
-         ! Identify the domain in case of jpdom_auto(glo/dta) definition
-         IF( idom == jpdom_autoglo_xy ) THEN
-            ll_depth_spec = .TRUE.
-            idom = jpdom_autoglo
-         ELSE
-            ll_depth_spec = .FALSE.
-         ENDIF
-         IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN            
-            IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
-            ELSE                               ;   idom = jpdom_data
-            ENDIF
-            ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
-            ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
-            IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
-         ENDIF
-         ! Identify the domain in case of jpdom_local definition
-         IF( idom == jpdom_local ) THEN
-            IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
-            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
-            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
-            ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
-            ENDIF
-         ENDIF
-         !
-         ! check the consistency between input array and data rank in the file
-         !
-         ! initializations
-         itime = 1
-         IF( PRESENT(ktime) ) itime = ktime
-
-         irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
-         WRITE(clrankpv, fmt='(i1)') irankpv
-         WRITE(cldmspc , fmt='(i1)') idmspc
-         !
-         IF(     idmspc <  irankpv ) THEN 
-            CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
+          ! Search for the variable in the data base (eventually actualize data)
+          istop = nstop
+          !
+          IF( idvar > 0 ) THEN
+             ! to write iom_file(kiomid)%dimsz in a shorter way !
+             idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) 
+             inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
+             idmspc = inbdim                                   ! number of spatial dimensions in the file
+             IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
+             IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
+             !
+             ! update idom definition...
+             ! Identify the domain in case of jpdom_auto(glo/dta) definition
+             IF( idom == jpdom_autoglo_xy ) THEN
+                ll_depth_spec = .TRUE.
+                idom = jpdom_autoglo
+             ELSE
+                ll_depth_spec = .FALSE.
+             ENDIF
+             IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN            
+                IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
+                ELSE                               ;   idom = jpdom_data
+                ENDIF
+                ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
+                ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
+                IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
+             ENDIF
+             ! Identify the domain in case of jpdom_local definition
+             IF( idom == jpdom_local ) THEN
+                IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
+                ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
+                ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
+                ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
+                ENDIF
+             ENDIF
+             !
+             ! check the consistency between input array and data rank in the file
+             !
+             ! initializations
+             itime = 1
+             IF( PRESENT(ktime) ) itime = ktime
+
+             irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
+             WRITE(clrankpv, fmt='(i1)') irankpv
+             WRITE(cldmspc , fmt='(i1)') idmspc
+             !
+             IF(     idmspc <  irankpv ) THEN 
+                CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
                &                         'it is impossible to read a '//clrankpv//'D array from this file...' )
-         ELSEIF( idmspc == irankpv ) THEN
-            IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
+             ELSEIF( idmspc == irankpv ) THEN
+                IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
                &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
-         ELSEIF( idmspc >  irankpv ) THEN
-               IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
-                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
+             ELSEIF( idmspc >  irankpv ) THEN
+                   IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
+                      CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
                         &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
                         &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
-                  idmspc = idmspc - 1
-               ELSE
-                  CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
+                      idmspc = idmspc - 1
+                   ELSE
+                      CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
                      &                         'we do not accept data with '//cldmspc//' spatial dimensions',   &
                      &                         'Use ncwa -a to suppress the unnecessary dimensions' )
-               ENDIF
-         ENDIF
-
-         !
-         ! definition of istart and icnt
-         !
-         icnt  (:) = 1
-         istart(:) = 1
-         istart(idmspc+1) = itime
+                   ENDIF
+             ENDIF
+
+             !
+             ! definition of istart and icnt
+             !
+             icnt  (:) = 1
+             istart(:) = 1
+             istart(idmspc+1) = itime
 
          IF( PRESENT(kstart) .AND. .NOT. ll_depth_spec ) THEN 
@@ -793,5 +1010,5 @@
 ! JMM + SM: ugly patch before getting the new version of lib_mpp)
 !                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
-                  IF( llnoov .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
+                      IF( llnoov .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
                   ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej 
 ! JMM + SM: ugly patch before getting the new version of lib_mpp)
@@ -810,64 +1027,64 @@
          ENDIF
 
-         ! check that istart and icnt can be used with this file
-         !-
-         DO jl = 1, jpmax_dims
-            itmp = istart(jl)+icnt(jl)-1
-            IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
-               WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
-               WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
-               CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
-            ENDIF
-         END DO
-
-         ! check that icnt matches the input array
-         !-     
-         IF( idom == jpdom_unknown ) THEN
-            IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
-            IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
-            IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
-            ctmp1 = 'd'
-         ELSE
-            IF( irankpv == 2 ) THEN
+             ! check that istart and icnt can be used with this file
+             !-
+             DO jl = 1, jpmax_dims
+                itmp = istart(jl)+icnt(jl)-1
+                IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
+                   WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
+                   WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
+                   CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
+                ENDIF
+             END DO
+
+             ! check that icnt matches the input array
+             !-     
+             IF( idom == jpdom_unknown ) THEN
+                IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
+                IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
+                IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
+                ctmp1 = 'd'
+             ELSE
+                IF( irankpv == 2 ) THEN
 ! JMM + SM: ugly patch before getting the new version of lib_mpp)
 !               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)'
-               IF( llnoov ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
-               ELSE              ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
-               ENDIF
-            ENDIF
-            IF( irankpv == 3 ) THEN 
+                   IF( llnoov ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
+                   ELSE              ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
+                   ENDIF
+                ENDIF
+                IF( irankpv == 3 ) THEN 
 ! JMM + SM: ugly patch before getting the new version of lib_mpp)
 !               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)'
-               IF( llnoov ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)'
-               ELSE              ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)'
-               ENDIF
-            ENDIF
-         ENDIF
+                   IF( llnoov ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)'
+                   ELSE              ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)'
+                   ENDIF
+                ENDIF
+             ENDIF
          
-         DO jl = 1, irankpv
-            WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
-            IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
-         END DO
-
-      ENDIF
-
-      ! read the data
-      !-     
-      IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
-         !
-         ! find the right index of the array to be read
+             DO jl = 1, irankpv
+                WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
+                IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
+             END DO
+
+          ENDIF
+
+          ! read the data
+          !-     
+          IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
+             !
+             ! find the right index of the array to be read
 ! JMM + SM: ugly patch before getting the new version of lib_mpp)
 !         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
 !         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
 !         ENDIF
-         IF( llnoov ) THEN
-            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
-            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
-            ENDIF
-         ELSE
-            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
-            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
-            ENDIF
-         ENDIF
+             IF( llnoov ) THEN
+                IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
+                ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
+                ENDIF
+             ELSE
+                IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
+                ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
+                ENDIF
+             ENDIF
       
          SELECT CASE (iom_file(kiomid)%iolib)
@@ -878,42 +1095,73 @@
          END SELECT
 
-         IF( istop == nstop ) THEN   ! no additional errors until this point...
-            IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i6,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name)
+             IF( istop == nstop ) THEN   ! no additional errors until this point...
+                IF(lwp) WRITE(numout,"(10x,' read ',a,' (rec: ',i6,') in ',a,' ok')") TRIM(cdvar), itime, TRIM(iom_file(kiomid)%name)
           
-            !--- overlap areas and extra hallows (mpp)
-            IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
-               CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
-            ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
-               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
-               IF( icnt(3) == jpk ) THEN
-                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
-               ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
-                  DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
-                  DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
-               ENDIF
-            ENDIF
-            
-            ! C1D case : always call lbc_lnk to replicate the central value over the whole 3X3 domain
-            IF( lk_c1d .AND. PRESENT(pv_r2d) )   CALL lbc_lnk( pv_r2d,'Z',1. )
-            IF( lk_c1d .AND. PRESENT(pv_r3d) )   CALL lbc_lnk( pv_r3d,'Z',1. )
-    
-            !--- Apply scale_factor and offset
-            zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
-            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
-            ELSEIF( PRESENT(pv_r2d) ) THEN
-               IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
-               IF( zofs /= 0.)   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
-            ENDIF
-            !
-         ENDIF
-         !
-      ENDIF
-      !
+                !--- overlap areas and extra hallows (mpp)
+                IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
+                   CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
+                ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
+                   ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
+                   IF( icnt(3) == jpk ) THEN
+                      CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
+                   ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
+                      DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
+                      DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
+                   ENDIF
+                ENDIF
+                !
+             ELSE
+                ! return if istop == nstop is false
+                RETURN
+             ENDIF
+          ELSE
+             ! return if statment idvar > 0 .AND. istop == nstop is false
+             RETURN
+          ENDIF
+          !
+       ELSE        ! read using XIOS. Only if KEY_IOMPUT is defined
+#if defined key_iomput
+!would be good to be able to check which context is active and swap only if current is not restart
+          CALL iom_swap( TRIM(crxios_context) ) 
+          IF( PRESENT(pv_r3d) ) THEN
+             if(lwp) write(numout,*) 'XIOS RST READ (3D): ',trim(cdvar)
+             CALL xios_recv_field( trim(cdvar), pv_r3d)
+             IF(idom /= jpdom_unknown ) then
+                 CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
+             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 ) THEN
+                 CALL lbc_lnk(pv_r2d,'Z',-999.,'no0')
+             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) )
+#else
+          istop = istop + 1 
+          clinfo = 'Can not use XIOS in iom_get_123d, file: '//trim(clname)//', var:'//trim(cdvar)
+#endif
+       ENDIF
+!some final adjustments
+       ! C1D case : always call lbc_lnk to replicate the central value over the whole 3X3 domain
+       IF( lk_c1d .AND. PRESENT(pv_r2d) )   CALL lbc_lnk( pv_r2d,'Z',1. )
+       IF( lk_c1d .AND. PRESENT(pv_r3d) )   CALL lbc_lnk( pv_r3d,'Z',1. )
+
+       !--- Apply scale_factor and offset
+       zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
+       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
+       ELSEIF( PRESENT(pv_r2d) ) THEN
+          IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
+          IF( zofs /= 0.)   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
+       ENDIF
    END SUBROUTINE iom_get_123d
 
@@ -1262,5 +1510,5 @@
             &    lonvalue_1D=lonvalue, latvalue_1D=latvalue, mask_1D=mask, nvertex=nvertex, bounds_lon_1D=bounds_lon,      &
             &    bounds_lat_1D=bounds_lat, area=area, type='curvilinear')
-     ENDIF
+      ENDIF
       IF ( xios_is_valid_domaingroup(cdid) ) THEN
          CALL xios_set_domaingroup_attr( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
@@ -1378,5 +1626,5 @@
 
 
-   SUBROUTINE set_grid( cdgrd, plon, plat )
+   SUBROUTINE set_grid( cdgrd, plon, plat, ldxios )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE set_grid  ***
@@ -1391,4 +1639,5 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmask
       INTEGER  :: ni,nj
+      LOGICAL, INTENT(IN) :: ldxios
       
       ni=nlei-nldi+1 ; nj=nlej-nldj+1
@@ -1399,5 +1648,5 @@
          &                                     latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /)))  
 
-      IF ( ln_mskland ) THEN
+      IF ( ln_mskland.AND.(.NOT.ldxios) ) THEN
          ! mask land points, keep values on coast line -> specific mask for U, V and W points
          SELECT CASE ( cdgrd )
@@ -1439,5 +1688,5 @@
       ! Offset of coordinate representing bottom-left corner
       SELECT CASE ( TRIM(cdgrd) )
-         CASE ('T', 'W')
+         CASE ('T', 'W', 'N')
             icnr = -1 ; jcnr = -1
          CASE ('U')
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90	(revision 8800)
@@ -46,4 +46,8 @@
 !$AGRIF_DO_NOT_TREAT
    INTEGER, PUBLIC            ::   iom_open_init = 0   !: used to initialize iom_file(:)%nfid to 0
+!XIOS read restart   
+   LOGICAL, PUBLIC            ::   lxios_read          !: read single file restart using XIOS
+   LOGICAL, PUBLIC            ::   lxios_sini = .FALSE. ! is restart in a single file
+   LOGICAL, PUBLIC            ::   lxios_set  = .FALSE. 
 
    TYPE, PUBLIC ::   file_descriptor
@@ -66,5 +70,14 @@
    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  
+
 !$AGRIF_END_DO_NOT_TREAT
+
+   TYPE, PUBLIC :: RST_FIELD  
+    CHARACTER(len=30) :: vname ! names of variables in restart file
+    CHARACTER(len=30) :: grid
+   END TYPE RST_FIELD
+   TYPE(RST_FIELD), PUBLIC :: rst_fields(max_rst_fields)
 
    !!=====================================================================
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 8800)
@@ -126,6 +126,6 @@
             CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'x', kdompar(1,1)  , idmy ), clinfo)
             CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'y', kdompar(2,1)  , idmy ), clinfo)
-            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'z', jpk           , idmy ), clinfo)
-            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 't', NF90_UNLIMITED, idmy ), clinfo)
+            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'nav_lev', jpk           , idmy ), clinfo)
+            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'time_counter', NF90_UNLIMITED, idmy ), clinfo)
             ! global attributes
             CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_number_total'   , jpnij              ), clinfo)
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 8800)
@@ -193,9 +193,27 @@
             WRITE(numout,*) '~~~~~~~~'
          ENDIF
-
+         lxios_sini = .FALSE.
          clpath = TRIM(cn_ocerst_indir)
          IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
          CALL iom_open( TRIM(clpath)//cn_ocerst_in, numror, kiolib = jlibalt )
-      ENDIF
+! are we using XIOS to read the data? Part above will have to modified once XIOS
+! can handle checking if variable is in the restart file (there will be no need to open
+! restart)
+         IF(.NOT.lxios_set) lxios_read = lxios_read.AND.lxios_sini
+         IF( lxios_read) 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. lxios_read) THEN
+            CALL iom_init( crxios_context )
+            IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for AGRIF'
+            lxios_set = .TRUE.
+         ENDIF 
+      ENDIF
+
    END SUBROUTINE rst_read_open
 
@@ -211,4 +229,6 @@
       REAL(wp) ::   zrdt
       INTEGER  ::   jk
+      TYPE(xios_duration):: dtime
+      integer::ni,nj,nk
       !!----------------------------------------------------------------------
 
@@ -217,35 +237,35 @@
       ! Check dynamics and tracer time-step consistency and force Euler restart if changed
       IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
-         CALL iom_get( numror, 'rdt', zrdt )
+         CALL iom_get( numror, 'rdt', zrdt, ldxios = lxios_read )
          IF( zrdt /= rdt )   neuler = 0
       ENDIF
 
       ! Diurnal DSST 
-      IF( ln_diurnal ) CALL iom_get( numror, jpdom_autoglo, 'Dsst' , x_dsst  ) 
+      IF( ln_diurnal ) CALL iom_get( numror, jpdom_autoglo, 'Dsst' , x_dsst, ldxios = lxios_read ) 
       IF ( ln_diurnal_only ) THEN 
          IF(lwp) WRITE( numout, * ) &
          &   "rst_read:- ln_diurnal_only set, setting rhop=rau0" 
          rhop = rau0
-         CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,1,jp_tem) ) 
+         CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,1,jp_tem), ldxios = lxios_read ) 
          RETURN 
       ENDIF  
       
       IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN
-         CALL iom_get( numror, jpdom_autoglo, 'ub'     , ub      )   ! before fields
-         CALL iom_get( numror, jpdom_autoglo, 'vb'     , vb      )
-         CALL iom_get( numror, jpdom_autoglo, 'tb'     , tsb(:,:,:,jp_tem) )
-         CALL iom_get( numror, jpdom_autoglo, 'sb'     , tsb(:,:,:,jp_sal) )
-         CALL iom_get( numror, jpdom_autoglo, 'sshb'   , sshb    )
+         CALL iom_get( numror, jpdom_autoglo, 'ub'     , ub, ldxios = lxios_read                )   ! before fields
+         CALL iom_get( numror, jpdom_autoglo, 'vb'     , vb, ldxios = lxios_read                )
+         CALL iom_get( numror, jpdom_autoglo, 'tb'     , tsb(:,:,:,jp_tem), ldxios = lxios_read )
+         CALL iom_get( numror, jpdom_autoglo, 'sb'     , tsb(:,:,:,jp_sal), ldxios = lxios_read )
+         CALL iom_get( numror, jpdom_autoglo, 'sshb'   , sshb, ldxios = lxios_read              )
       ELSE
          neuler = 0
       ENDIF
       !
-      CALL iom_get( numror, jpdom_autoglo, 'un'     , un      )   ! now    fields
-      CALL iom_get( numror, jpdom_autoglo, 'vn'     , vn      )
-      CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,:,jp_tem) )
-      CALL iom_get( numror, jpdom_autoglo, 'sn'     , tsn(:,:,:,jp_sal) )
-      CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn    )
+      CALL iom_get( numror, jpdom_autoglo, 'un'     , un, ldxios = lxios_read )   ! now    fields
+      CALL iom_get( numror, jpdom_autoglo, 'vn'     , vn, ldxios = lxios_read )
+      CALL iom_get( numror, jpdom_autoglo, 'tn'     , tsn(:,:,:,jp_tem), ldxios = lxios_read )
+      CALL iom_get( numror, jpdom_autoglo, 'sn'     , tsn(:,:,:,jp_sal), ldxios = lxios_read )
+      CALL iom_get( numror, jpdom_autoglo, 'sshn'   , sshn, ldxios = lxios_read )
       IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN
-         CALL iom_get( numror, jpdom_autoglo, 'rhop'   , rhop    )   ! now    potential density
+         CALL iom_get( numror, jpdom_autoglo, 'rhop'   , rhop, ldxios = lxios_read )   ! now    potential density
       ELSE
          CALL eos( tsn, rhd, rhop, gdept_n(:,:,:) )   
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90	(revision 8800)
@@ -65,4 +65,5 @@
       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            ::  lxios_read ! read restart using XIOS?
       !!
       NAMELIST/namsbc_apr/ cn_dir, sn_apr, ln_ref_apr, rn_pref, ln_apr_obc
@@ -152,5 +153,5 @@
          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'
-            CALL iom_get( numror, jpdom_autoglo, 'ssh_ibb', ssh_ibb )   ! before inv. barometer ssh
+            CALL iom_get( numror, jpdom_autoglo, 'ssh_ibb', ssh_ibb, ldxios = lxios_read )   ! before inv. barometer ssh
             !
          ELSE                                         !* no restart: set from nit000 values
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90	(revision 8800)
@@ -27,4 +27,5 @@
    USE timing          ! Timing
    USE lib_fortran     ! glob_sum
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -218,7 +219,7 @@
                  & iom_varid( numror, 'fwf_isf_b', ldstop = .FALSE. ) > 0 ) THEN
                IF(lwp) WRITE(numout,*) '          nit000-1 isf tracer content forcing fields read in the restart file'
-               CALL iom_get( numror, jpdom_autoglo, 'fwf_isf_b', fwfisf_b(:,:) )   ! before salt content isf_tsc trend
-               CALL iom_get( numror, jpdom_autoglo, 'isf_sc_b', risf_tsc_b(:,:,jp_sal) )   ! before salt content isf_tsc trend
-               CALL iom_get( numror, jpdom_autoglo, 'isf_hc_b', risf_tsc_b(:,:,jp_tem) )   ! before salt content isf_tsc trend
+               CALL iom_get( numror, jpdom_autoglo, 'fwf_isf_b', fwfisf_b(:,:), ldxios = lxios_read )   ! before salt content isf_tsc trend
+               CALL iom_get( numror, jpdom_autoglo, 'isf_sc_b', risf_tsc_b(:,:,jp_sal), ldxios = lxios_read )   ! before salt content isf_tsc trend
+               CALL iom_get( numror, jpdom_autoglo, 'isf_hc_b', risf_tsc_b(:,:,jp_tem), ldxios = lxios_read )   ! before salt content isf_tsc trend
            ELSE
                fwfisf_b(:,:)    = fwfisf(:,:)
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 8800)
@@ -58,4 +58,5 @@
 
    USE diurnal_bulk, ONLY:   ln_diurnal_only   ! diurnal SST diagnostic
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -457,13 +458,13 @@
             & iom_varid( numror, 'utau_b', ldstop = .FALSE. ) > 0 ) THEN
             IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields red in the restart file'
-            CALL iom_get( numror, jpdom_autoglo, 'utau_b', utau_b )   ! before i-stress  (U-point)
-            CALL iom_get( numror, jpdom_autoglo, 'vtau_b', vtau_b )   ! before j-stress  (V-point)
-            CALL iom_get( numror, jpdom_autoglo, 'qns_b' , qns_b  )   ! before non solar heat flux (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'utau_b', utau_b, ldxios = lxios_read )   ! before i-stress  (U-point)
+            CALL iom_get( numror, jpdom_autoglo, 'vtau_b', vtau_b, ldxios = lxios_read )   ! before j-stress  (V-point)
+            CALL iom_get( numror, jpdom_autoglo, 'qns_b' , qns_b, ldxios = lxios_read  )   ! before non solar heat flux (T-point)
             ! The 3D heat content due to qsr forcing is treated in traqsr
-            ! CALL iom_get( numror, jpdom_autoglo, 'qsr_b' , qsr_b  ) ! before     solar heat flux (T-point)
-            CALL iom_get( numror, jpdom_autoglo, 'emp_b', emp_b  )    ! before     freshwater flux (T-point)
+            ! CALL iom_get( numror, jpdom_autoglo, 'qsr_b' , qsr_b, ldxios = lxios_read  ) ! before     solar heat flux (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'emp_b', emp_b, ldxios = lxios_read  )    ! before     freshwater flux (T-point)
             ! 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_autoglo, 'sfx_b', sfx_b )  ! before salt flux (T-point)
+               CALL iom_get( numror, jpdom_autoglo, 'sfx_b', sfx_b, ldxios = lxios_read )  ! before salt flux (T-point)
             ELSE
                sfx_b (:,:) = sfx(:,:)
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 8800)
@@ -28,4 +28,5 @@
    USE lib_mpp        ! MPP library
    USE wrk_nemo       ! Memory allocation
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -147,8 +148,8 @@
          IF( ln_rstart .AND.    &                               !* Restart: read in restart file
             & iom_varid( numror, 'rnf_b', ldstop = .FALSE. ) > 0 ) THEN
-            IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields red in the restart file'
-            CALL iom_get( numror, jpdom_autoglo, 'rnf_b', rnf_b )     ! before runoff
-            CALL iom_get( numror, jpdom_autoglo, 'rnf_hc_b', rnf_tsc_b(:,:,jp_tem) )   ! before heat content of runoff
-            CALL iom_get( numror, jpdom_autoglo, 'rnf_sc_b', rnf_tsc_b(:,:,jp_sal) )   ! before salinity content of runoff
+            IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields red in the restart file', lxios_read
+            CALL iom_get( numror, jpdom_autoglo, 'rnf_b', rnf_b, ldxios = lxios_read )     ! before runoff
+            CALL iom_get( numror, jpdom_autoglo, 'rnf_hc_b', rnf_tsc_b(:,:,jp_tem), ldxios = lxios_read )   ! before heat content of runoff
+            CALL iom_get( numror, jpdom_autoglo, 'rnf_sc_b', rnf_tsc_b(:,:,jp_sal), ldxios = lxios_read )   ! before salinity content of runoff
          ELSE                                                   !* no restart: set from nit000 values
             IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields set to nit000'
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 8800)
@@ -22,4 +22,5 @@
    USE prtctl         ! Print control
    USE iom            ! IOM library
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -206,14 +207,15 @@
          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 )    ! sbc frequency of previous run
-            CALL iom_get( numror, jpdom_autoglo, 'ssu_m'  , ssu_m  )    ! sea surface mean velocity    (U-point)
-            CALL iom_get( numror, jpdom_autoglo, 'ssv_m'  , ssv_m  )    !   "         "    velocity    (V-point)
-            CALL iom_get( numror, jpdom_autoglo, 'sst_m'  , sst_m  )    !   "         "    temperature (T-point)
-            CALL iom_get( numror, jpdom_autoglo, 'sss_m'  , sss_m  )    !   "         "    salinity    (T-point)
-            CALL iom_get( numror, jpdom_autoglo, 'ssh_m'  , ssh_m  )    !   "         "    height      (T-point)
-            CALL iom_get( numror, jpdom_autoglo, 'e3t_m'  , e3t_m  )    ! 1st level thickness          (T-point)
+            CALL iom_get( numror               , 'nn_fsbc', zf_sbc, ldxios = lxios_read )    ! sbc frequency of previous run
+            CALL iom_get( numror, jpdom_autoglo, 'ssu_m'  , ssu_m, ldxios = lxios_read  )    ! sea surface mean velocity    (U-point)
+            CALL iom_get( numror, jpdom_autoglo, 'ssv_m'  , ssv_m, ldxios = lxios_read  )    !   "         "    velocity    (V-point)
+            CALL iom_get( numror, jpdom_autoglo, 'sst_m'  , sst_m, ldxios = lxios_read  )    !   "         "    temperature (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'sss_m'  , sss_m, ldxios = lxios_read  )    !   "         "    salinity    (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'ssh_m'  , ssh_m, ldxios = lxios_read  )    !   "         "    height      (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'e3t_m'  , e3t_m, ldxios = lxios_read  )    ! 1st level thickness          (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'e3t_m', e3t_m, ldxios = lxios_read )
             ! 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_autoglo, 'frq_m'  , frq_m  )
+               CALL iom_get( numror, jpdom_autoglo, 'frq_m'  , frq_m, ldxios = lxios_read  )
             ELSE
                frq_m(:,:) = 1._wp   ! default definition
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 8800)
@@ -36,5 +36,5 @@
    USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
-
+   USE iom_def, ONLY : lxios_read
    IMPLICIT NONE
    PRIVATE
@@ -139,5 +139,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_autoglo, 'qsr_hc_b', qsr_hc_b )   ! before heat content trend due to Qsr flux
+            CALL iom_get( numror, jpdom_autoglo, 'qsr_hc_b', qsr_hc_b, ldxios = lxios_read )   ! before heat content trend due to Qsr flux
          ELSE                                           ! No restart or restart not found: Euler forward time stepping
             z1_2 = 1._wp
@@ -430,5 +430,5 @@
       ! 1st ocean level attenuation coefficient (used in sbcssm)
       IF( iom_varid( numror, 'fraqsr_1lev', ldstop = .FALSE. ) > 0 ) THEN
-         CALL iom_get( numror, jpdom_autoglo, 'fraqsr_1lev'  , fraqsr_1lev  )
+         CALL iom_get( numror, jpdom_autoglo, 'fraqsr_1lev'  , fraqsr_1lev, ldxios = lxios_read  )
       ELSE
          fraqsr_1lev(:,:) = 1._wp   ! default : no penetration
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 8800)
@@ -34,4 +34,5 @@
    USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -108,6 +109,6 @@
             zfact = 0.5_wp
             sbc_tsc(:,:,:) = 0._wp
-            CALL iom_get( numror, jpdom_autoglo, 'sbc_hc_b', sbc_tsc_b(:,:,jp_tem) )   ! before heat content sbc trend
-            CALL iom_get( numror, jpdom_autoglo, 'sbc_sc_b', sbc_tsc_b(:,:,jp_sal) )   ! before salt content sbc trend
+            CALL iom_get( numror, jpdom_autoglo, 'sbc_hc_b', sbc_tsc_b(:,:,jp_tem), ldxios = lxios_read )   ! before heat content sbc trend
+            CALL iom_get( numror, jpdom_autoglo, 'sbc_sc_b', sbc_tsc_b(:,:,jp_sal), ldxios = lxios_read )   ! before salt content sbc trend
          ELSE                                   ! No restart or restart not found: Euler forward time stepping
             zfact = 1._wp
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_rst.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_rst.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_rst.F90	(revision 8800)
@@ -150,18 +150,18 @@
       IF( ln_trdmxl_instant ) THEN 
          !-- Temperature
-         CALL iom_get( inum, jpdom_autoglo, 'tmlbb'           , tmlbb          )
-         CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          )
-         CALL iom_get( inum, jpdom_autoglo, 'tmlatfb'         , tmlatfb        )
+         CALL iom_get( inum, jpdom_autoglo, 'tmlbb'           , tmlbb )
+         CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn )
+         CALL iom_get( inum, jpdom_autoglo, 'tmlatfb'         , tmlatfb )
          !
          !-- Salinity
-         CALL iom_get( inum, jpdom_autoglo, 'smlbb'           , smlbb          )
-         CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          )
-         CALL iom_get( inum, jpdom_autoglo, 'smlatfb'         , smlatfb        )
+         CALL iom_get( inum, jpdom_autoglo, 'smlbb'           , smlbb )
+         CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn )
+         CALL iom_get( inum, jpdom_autoglo, 'smlatfb'         , smlatfb )
       ELSE
-         CALL iom_get( inum, jpdom_autoglo, 'hmxlbn'          , hmxlbn         ) ! needed for hmxl_sum
+         CALL iom_get( inum, jpdom_autoglo, 'hmxlbn'          , hmxlbn ) ! needed for hmxl_sum
          !
          !-- Temperature
-         CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          ) ! needed for tml_sum
-         CALL iom_get( inum, jpdom_autoglo, 'tml_sumb'        , tml_sumb       )
+         CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn ) ! needed for tml_sum
+         CALL iom_get( inum, jpdom_autoglo, 'tml_sumb'        , tml_sumb )
          DO jk = 1, jpltrd
             IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I1)")   jk
@@ -173,6 +173,6 @@
          !
          !-- Salinity
-         CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          ) ! needed for sml_sum
-         CALL iom_get( inum, jpdom_autoglo, 'sml_sumb'        , sml_sumb       )
+         CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn ) ! needed for sml_sum
+         CALL iom_get( inum, jpdom_autoglo, 'sml_sumb'        , sml_sumb )
          DO jk = 1, jpltrd
             IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('smltrd_csum_ub_', I1)")   jk
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 8800)
@@ -34,4 +34,5 @@
    USE timing         ! Timing
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -1175,10 +1176,10 @@
             !
             IF( MIN( id1, id2, id3, id4, id5, id6 ) > 0 ) THEN        ! all required arrays exist
-               CALL iom_get( numror, jpdom_autoglo, 'en'    , en     )
-               CALL iom_get( numror, jpdom_autoglo, 'avt'   , avt    )
-               CALL iom_get( numror, jpdom_autoglo, 'avm'   , avm    )
-               CALL iom_get( numror, jpdom_autoglo, 'avmu'  , avmu   )
-               CALL iom_get( numror, jpdom_autoglo, 'avmv'  , avmv   )
-               CALL iom_get( numror, jpdom_autoglo, 'mxln'  , mxln   )
+               CALL iom_get( numror, jpdom_autoglo, 'en'    , en, ldxios = lxios_read     )
+               CALL iom_get( numror, jpdom_autoglo, 'avt'   , avt, ldxios = lxios_read    )
+               CALL iom_get( numror, jpdom_autoglo, 'avm'   , avm, ldxios = lxios_read    )
+               CALL iom_get( numror, jpdom_autoglo, 'avmu'  , avmu, ldxios = lxios_read   )
+               CALL iom_get( numror, jpdom_autoglo, 'avmv'  , avmv, ldxios = lxios_read   )
+               CALL iom_get( numror, jpdom_autoglo, 'mxln'  , mxln, ldxios = lxios_read   )
             ELSE                        
                IF(lwp) WRITE(numout,*) ' ===>>>> : previous run without gls scheme, en and mxln computed by iterative loop'
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90	(revision 8800)
@@ -28,4 +28,5 @@
    USE iom             ! IOM library
    USE lib_mpp         ! distribued memory computing
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -159,6 +160,6 @@
          ! file in traadv_cen2 end read here. 
          IF( iom_varid( numror, 'avmb', ldstop = .FALSE. ) > 0 ) THEN
-            CALL iom_get( numror, jpdom_unknown, 'avmb', avmb )
-            CALL iom_get( numror, jpdom_unknown, 'avtb', avtb )
+            CALL iom_get( numror, jpdom_unknown, 'avmb', avmb, ldxios = lxios_read )
+            CALL iom_get( numror, jpdom_unknown, 'avtb', avtb, ldxios = lxios_read )
          ENDIF
       ENDIF
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 8800)
@@ -57,4 +57,5 @@
    USE agrif_opa_update
 #endif
+   USE iom_def, ONLY : lxios_read
 
    IMPLICIT NONE
@@ -845,11 +846,11 @@
            !
            IF( id1 > 0 ) THEN                       ! 'en' exists
-              CALL iom_get( numror, jpdom_autoglo, 'en', en )
+              CALL iom_get( numror, jpdom_autoglo, 'en', en, ldxios = lxios_read )
               IF( MIN( id2, id3, id4, id5, id6 ) > 0 ) THEN        ! all required arrays exist
-                 CALL iom_get( numror, jpdom_autoglo, 'avt'  , avt   )
-                 CALL iom_get( numror, jpdom_autoglo, 'avm'  , avm   )
-                 CALL iom_get( numror, jpdom_autoglo, 'avmu' , avmu  )
-                 CALL iom_get( numror, jpdom_autoglo, 'avmv' , avmv  )
-                 CALL iom_get( numror, jpdom_autoglo, 'dissl', dissl )
+                 CALL iom_get( numror, jpdom_autoglo, 'avt'  , avt, ldxios = lxios_read   )
+                 CALL iom_get( numror, jpdom_autoglo, 'avm'  , avm, ldxios = lxios_read   )
+                 CALL iom_get( numror, jpdom_autoglo, 'avmu' , avmu, ldxios = lxios_read  )
+                 CALL iom_get( numror, jpdom_autoglo, 'avmv' , avmv, ldxios = lxios_read  )
+                 CALL iom_get( numror, jpdom_autoglo, 'dissl', dissl, ldxios = lxios_read )
               ELSE                                                 ! one at least array is missing
                  CALL tke_avn                                          ! compute avt, avm, avmu, avmv and dissl (approximation)
Index: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 8799)
+++ branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 8800)
@@ -345,4 +345,5 @@
       IF( kstp == nitend .OR. indic < 0 ) THEN 
                       CALL iom_context_finalize(      cxios_context          ) ! needed for XIOS+AGRIF
+                      IF(lxios_read) CALL iom_context_finalize(      crxios_context          )
          IF( ln_crs ) CALL iom_context_finalize( trim(cxios_context)//"_crs" ) ! 
       ENDIF
