Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/restart.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/restart.F90	(revision 13895)
+++ NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/IOM/restart.F90	(revision 14018)
@@ -111,5 +111,5 @@
             ELSE
 #if defined key_iomput
-               cwxios_context = "rstw_"//TRIM(ADJUSTL(clkt))
+               cw_ocerst_cxt = "rstw_"//TRIM(ADJUSTL(clkt))
                IF( TRIM(Agrif_CFixed()) == '0' ) THEN
                   clpname = clname
@@ -117,6 +117,6 @@
                   clpname = TRIM(Agrif_CFixed())//"_"//clname   
                ENDIF
-               CALL iom_init( cwxios_context, TRIM(clpath)//TRIM(clpname), .false. )
-               CALL xios_update_calendar(nitrst)
+               numrow = iom_xios_setid(TRIM(clpath)//TRIM(clpname))
+               CALL iom_init( cw_ocerst_cxt, kdid = numrow, ld_closedef = .false. )
                CALL iom_swap(      cxios_context          )
 #else
@@ -147,30 +147,30 @@
       INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
       !!----------------------------------------------------------------------
-                     IF(lwxios) CALL iom_swap(      cwxios_context          )
-                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rn_Dt       , ldxios = lwxios)   ! dynamics time step
-                     CALL iom_delay_rst( 'WRITE', 'OCE', numrow )   ! save only ocean delayed global communication variables
+                     CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rn_Dt       )   ! dynamics time step
+                     IF(.NOT.lwxios) CALL iom_delay_rst( 'WRITE', 'OCE', numrow )   ! save only ocean delayed global communication variables
 
       IF ( .NOT. ln_diurnal_only ) THEN
-                     CALL iom_rstput( kt, nitrst, numrow, 'ub'     , uu(:,:,:       ,Kbb), ldxios = lwxios        )     ! before fields
-                     CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vv(:,:,:       ,Kbb), ldxios = lwxios        )
-                     CALL iom_rstput( kt, nitrst, numrow, 'tb'     , ts(:,:,:,jp_tem,Kbb), ldxios = lwxios )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sb'     , ts(:,:,:,jp_sal,Kbb), ldxios = lwxios )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sshb'   ,ssh(:,:         ,Kbb), ldxios = lwxios      )
+                     CALL iom_rstput( kt, nitrst, numrow, 'ub'     , uu(:,:,:       ,Kbb) )     ! before fields
+                     CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vv(:,:,:       ,Kbb) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'tb'     , ts(:,:,:,jp_tem,Kbb) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'sb'     , ts(:,:,:,jp_sal,Kbb) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , ssh(:,:         ,Kbb))
                      !
-                     CALL iom_rstput( kt, nitrst, numrow, 'un'     , uu(:,:,:       ,Kmm), ldxios = lwxios        )     ! now fields
-                     CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vv(:,:,:       ,Kmm), ldxios = lwxios        )
-                     CALL iom_rstput( kt, nitrst, numrow, 'tn'     , ts(:,:,:,jp_tem,Kmm), ldxios = lwxios )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sn'     , ts(:,:,:,jp_sal,Kmm), ldxios = lwxios )
-                     CALL iom_rstput( kt, nitrst, numrow, 'sshn'   ,ssh(:,:         ,Kmm), ldxios = lwxios      )
-                     CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop, ldxios = lwxios      )
+                     CALL iom_rstput( kt, nitrst, numrow, 'un'     , uu(:,:,:       ,Kmm) )     ! now fields
+                     CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vv(:,:,:       ,Kmm) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'tn'     , ts(:,:,:,jp_tem,Kmm) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'sn'     , ts(:,:,:,jp_sal,Kmm) )
+                     CALL iom_rstput( kt, nitrst, numrow, 'sshn'   , ssh(:,:         ,Kmm))
+                     CALL iom_rstput( kt, nitrst, numrow, 'rhop'   , rhop      )
       ENDIF
       
-      IF (ln_diurnal) CALL iom_rstput( kt, nitrst, numrow, 'Dsst', x_dsst, ldxios = lwxios )  
-      IF(lwxios) CALL iom_swap(      cxios_context          )
+      IF (ln_diurnal) CALL iom_rstput( kt, nitrst, numrow, 'Dsst', x_dsst )  
       IF( kt == nitrst ) THEN
          IF(.NOT.lwxios) THEN
             CALL iom_close( numrow )     ! close the restart file (only at last time step)
          ELSE
-            CALL iom_context_finalize(      cwxios_context          )
+            CALL iom_context_finalize(      cw_ocerst_cxt          )
+            iom_file(numrow)%nfid       = 0
+            numrow = 0
          ENDIF
 !!gm         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
@@ -195,6 +195,7 @@
       !!                the file has already been opened
       !!----------------------------------------------------------------------
-      LOGICAL        ::   llok
-      CHARACTER(lc)  ::   clpath   ! full path to ocean output restart file
+      LOGICAL             ::   llok
+      CHARACTER(len=lc)   ::   clpath   ! full path to ocean output restart file
+      CHARACTER(len=lc+2) ::   clpname  ! file name including agrif prefix
       !!----------------------------------------------------------------------
       !
@@ -213,18 +214,18 @@
 ! can handle checking if variable is in the restart file (there will be no need to open
 ! restart)
-         IF( .NOT.lxios_set )   lrxios = lrxios.AND.lxios_sini
-         IF( lrxios ) THEN
-             crxios_context = 'nemo_rst'
-             IF( .NOT.lxios_set ) THEN
-                 IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS'
-                 CALL iom_init( crxios_context )
-                 lxios_set = .TRUE.
-             ENDIF
-         ENDIF
-         IF( TRIM(Agrif_CFixed()) /= '0' .AND. lrxios ) THEN
-             CALL iom_init( crxios_context )
-             IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for AGRIF'
-             lxios_set = .TRUE.
-         ENDIF 
+         lrxios = lrxios.AND.lxios_sini
+
+         IF( lrxios) THEN
+             cr_ocerst_cxt = 'oce_rst'
+             IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS'
+!            IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+!               clpname = cn_ocerst_in
+!            ELSE
+!               clpname = TRIM(Agrif_CFixed())//"_"//cn_ocerst_in   
+!            ENDIF
+             CALL iom_init( cr_ocerst_cxt, kdid = numror, ld_closedef = .TRUE. )
+             CALL iom_swap(      cxios_context          )
+         ENDIF
+
       ENDIF
 
@@ -252,13 +253,13 @@
       !!----------------------------------------------------------------------
       !
-      CALL iom_delay_rst( 'READ', 'OCE', numror )   ! read only ocean delayed global communication variables
+      IF(.NOT.lrxios ) CALL iom_delay_rst( 'READ', 'OCE', numror )   ! read only ocean delayed global communication variables
       !
       !                             !*  Diurnal DSST 
-      IF( ln_diurnal )   CALL iom_get( numror, jpdom_auto, 'Dsst' , x_dsst, ldxios = lrxios ) 
+      IF( ln_diurnal )   CALL iom_get( numror, jpdom_auto, 'Dsst' , x_dsst ) 
       IF ( ln_diurnal_only ) THEN 
          IF(lwp) WRITE( numout, * ) &
          &   "rst_read:- ln_diurnal_only set, setting rhop=rho0" 
          rhop = rho0
-         CALL iom_get( numror, jpdom_auto, 'tn'     , w3d, ldxios = lrxios ) 
+         CALL iom_get( numror, jpdom_auto, 'tn'     , w3d ) 
          ts(:,:,1,jp_tem,Kmm) = w3d(:,:,1)
          RETURN 
@@ -267,8 +268,8 @@
       !                             !*  Read Kmm fields
       IF(lwp) WRITE(numout,*)    '           Kmm u, v and T-S fields read in the restart file'
-      CALL iom_get( numror, jpdom_auto, 'un'     , uu(:,:,:       ,Kmm), ldxios = lrxios, cd_type = 'U', psgn = -1._wp )
-      CALL iom_get( numror, jpdom_auto, 'vn'     , vv(:,:,:       ,Kmm), ldxios = lrxios, cd_type = 'V', psgn = -1._wp )
-      CALL iom_get( numror, jpdom_auto, 'tn'     , ts(:,:,:,jp_tem,Kmm), ldxios = lrxios )
-      CALL iom_get( numror, jpdom_auto, 'sn'     , ts(:,:,:,jp_sal,Kmm), ldxios = lrxios )
+      CALL iom_get( numror, jpdom_auto, 'un'     , uu(:,:,:       ,Kmm), cd_type = 'U', psgn = -1._wp )
+      CALL iom_get( numror, jpdom_auto, 'vn'     , vv(:,:,:       ,Kmm), cd_type = 'V', psgn = -1._wp )
+      CALL iom_get( numror, jpdom_auto, 'tn'     , ts(:,:,:,jp_tem,Kmm) )
+      CALL iom_get( numror, jpdom_auto, 'sn'     , ts(:,:,:,jp_sal,Kmm) )
       !
       IF( l_1st_euler ) THEN        !*  Euler restart
@@ -279,12 +280,12 @@
       ELSE                          !* Leap frog restart
          IF(lwp) WRITE(numout,*) '           Kbb u, v and T-S fields read in the restart file'
-         CALL iom_get( numror, jpdom_auto, 'ub'     , uu(:,:,:       ,Kbb), ldxios = lrxios, cd_type = 'U', psgn = -1._wp )
-         CALL iom_get( numror, jpdom_auto, 'vb'     , vv(:,:,:       ,Kbb), ldxios = lrxios, cd_type = 'V', psgn = -1._wp )
-         CALL iom_get( numror, jpdom_auto, 'tb'     , ts(:,:,:,jp_tem,Kbb), ldxios = lrxios )
-         CALL iom_get( numror, jpdom_auto, 'sb'     , ts(:,:,:,jp_sal,Kbb), ldxios = lrxios )
+         CALL iom_get( numror, jpdom_auto, 'ub'     , uu(:,:,:       ,Kbb), cd_type = 'U', psgn = -1._wp )
+         CALL iom_get( numror, jpdom_auto, 'vb'     , vv(:,:,:       ,Kbb), cd_type = 'V', psgn = -1._wp )
+         CALL iom_get( numror, jpdom_auto, 'tb'     , ts(:,:,:,jp_tem,Kbb) )
+         CALL iom_get( numror, jpdom_auto, 'sb'     , ts(:,:,:,jp_sal,Kbb) )
       ENDIF
       !
       IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN
-         CALL iom_get( numror, jpdom_auto, 'rhop'   , rhop, ldxios = lrxios )   ! now    potential density
+         CALL iom_get( numror, jpdom_auto, 'rhop'   , rhop )   ! now    potential density
       ELSE
          CALL eos( ts(:,:,:,:,Kmm), rhd, rhop, gdept(:,:,:,Kmm) )   
