Index: branches/UKMO/dev_r7573_xios_write/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- branches/UKMO/dev_r7573_xios_write/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 8297)
+++ branches/UKMO/dev_r7573_xios_write/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 8299)
@@ -153,5 +153,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) ::   wxios_context = "nemo_rstw" !: context name used in xios to write restart file
+   CHARACTER(lc) ::   wxios_context         !: context name used in xios to write restart file
 
    !!----------------------------------------------------------------------
Index: branches/UKMO/dev_r7573_xios_write/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- branches/UKMO/dev_r7573_xios_write/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 8297)
+++ branches/UKMO/dev_r7573_xios_write/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 8299)
@@ -92,5 +92,5 @@
 CONTAINS
 
-   SUBROUTINE iom_init( cdname, filename, it ) 
+   SUBROUTINE iom_init( cdname ) 
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE   ***
@@ -112,7 +112,4 @@
       !
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_bnds
-      CHARACTER(len=*), OPTIONAL, INTENT(in)  :: filename 
-      LOGICAL :: lrst_context              ! is context related to restart
-      INTEGER, OPTIONAL :: it              ! timestep when subroutine was called
       !!----------------------------------------------------------------------
 #if ! defined key_xios2
@@ -126,5 +123,4 @@
       CALL xios_context_initialize(TRIM(clname), mpi_comm_opa)
       CALL iom_swap( cdname )
-      lrst_context =  (TRIM(cdname) == TRIM(wxios_context))
 
       ! calendar parameters
@@ -153,13 +149,12 @@
       CALL set_scalar
 
-      IF( TRIM(cdname) == TRIM(cxios_context) .OR. lrst_context ) THEN  
-         CALL set_grid( "T", glamt, gphit, ln_mskland ) 
-         CALL set_grid( "U", glamu, gphiu, ln_mskland )
-         CALL set_grid( "V", glamv, gphiv, ln_mskland )
-         CALL set_grid( "W", glamt, gphit, ln_mskland )
+      IF( TRIM(cdname) == TRIM(cxios_context)) THEN  
+         CALL set_grid( "T", glamt, gphit, .TRUE. ) 
+         CALL set_grid( "U", glamu, gphiu, .TRUE. )
+         CALL set_grid( "V", glamv, gphiv, .TRUE. )
+         CALL set_grid( "W", glamt, gphit, .TRUE. )
          CALL set_grid_znl( gphit )
-         CALL set_grid("N",glamt, gphit, .FALSE.)        ! not masked values
          !
-         IF( ln_cfmeta .AND. .NOT.lrst_context) THEN   ! Add additional grid metadata
+         IF( ln_cfmeta ) THEN   ! Add additional grid metadata
             CALL iom_set_domain_attr("grid_T", area = e12t(nldi:nlei, nldj:nlej))
             CALL iom_set_domain_attr("grid_U", area = e12u(nldi:nlei, nldj:nlej))
@@ -184,5 +179,5 @@
          CALL dom_grid_glo   ! Return to parent grid domain
          !
-         IF( ln_cfmeta .AND. .NOT.lrst_context) THEN   ! Add additional grid metadata
+         IF( ln_cfmeta) 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))
@@ -239,11 +234,5 @@
       CALL iom_set_axis_attr( "iax_28C", (/ REAL(28,wp) /) )
       
-      ! automatic definitions of some of the xml attributs
-      IF( TRIM(cdname) == TRIM(wxios_context)) THEN
-!set which fields are to be read from restart file
-       CALL set_rstw_active(filename, it)
-      ELSE
-       CALL set_xmlatt
-      ENDIF
+      CALL set_xmlatt
 
       CALL set_1point
@@ -262,9 +251,81 @@
    END SUBROUTINE iom_init
 
+   SUBROUTINE iom_rstw_init( cdname, filename, it ) 
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE   ***
+      !!
+      !! ** Purpose :   
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in)  :: cdname
+#if defined key_iomput
+#if defined key_xios2
+      TYPE(xios_duration) :: dtime    = xios_duration(0, 0, 0, 0, 0, 0)
+      TYPE(xios_date)     :: start_date
+      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
+#endif
+      CHARACTER(len=128)   :: clname
+      INTEGER             :: ji
+      !
+      CHARACTER(len=*), OPTIONAL, INTENT(in)  :: filename 
+      INTEGER, OPTIONAL :: it              ! timestep when subroutine was called
+      !!----------------------------------------------------------------------
+
+      clname = cdname 
+      if(lwp) write(numout,*) 'initialize CONTEXT:', TRIM(cdname)
+      IF( TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(cdname)
+      CALL xios_context_initialize(TRIM(clname), mpi_comm_opa)
+      CALL iom_swap( cdname )
+      ! calendar parameters
+#if defined key_xios2
+      ! Calendar type is now defined in xml file 
+      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
+      CASE ( 1)   ; CALL xios_define_calendar( TYPE = "Gregorian", time_origin = xios_date(1900,01,01,00,00,00), &
+          &                                    start_date = xios_date(nyear,nmonth,nday,0,0,0) )
+      CASE ( 0)   ; CALL xios_define_calendar( TYPE = "NoLeap"   , time_origin = xios_date(1900,01,01,00,00,00), &
+          &                                    start_date = xios_date(nyear,nmonth,nday,0,0,0) )
+      CASE (30)   ; CALL xios_define_calendar( TYPE = "D360"     , time_origin = xios_date(1900,01,01,00,00,00), &
+          &                                    start_date = xios_date(nyear,nmonth,nday,0,0,0) )
+      END SELECT
+
+#endif
+      CALL xios_get_handle("domain_definition",domaingroup_hdl)
+      CALL xios_add_child(domaingroup_hdl, domain_hdl, "grid_N")
+      CALL set_grid("N", glamt, gphit, .FALSE.)
+
+      CALL xios_get_handle("axis_definition",axisgroup_hdl)
+      CALL xios_add_child(axisgroup_hdl, axis_hdl, "deptht")
+      CALL xios_set_axis_attr( "deptht", long_name="Vertical levels",  unit="m", positive="down")
+      ! vertical grid definition
+      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")
+      CALL xios_set_scalar_attr( "grid_scalar", value=1. )
+
+      ! automatic definitions of some of the xml attributs
+      IF( TRIM(cdname) == TRIM(wxios_context)) THEN
+!set which fields are to be read from restart file
+       CALL set_rstw_active(filename, it)
+      ENDIF
+
+      ! end file definition
+      dtime%second = rdt
+      CALL xios_set_timestep(dtime)
+      CALL xios_close_context_definition()
+      
+#endif
+
+   END SUBROUTINE iom_rstw_init
+
    SUBROUTINE set_rstw_active(rst_file, it)
 !sets enabled = .TRUE. for each field in restart file
    CHARACTER(len=*) :: rst_file
    INTEGER, INTENT(in) :: it ! timestep when iom_init was called
-   TYPE(xios_field) :: field_hdl
    TYPE(xios_file) :: file_hdl
    TYPE(xios_filegroup) :: filegroup_hdl
@@ -285,107 +346,113 @@
 
         CALL xios_set_file_attr( "wrestart", name=trim(rst_file))
+        CALL set_numro_active(file_hdl)
+
+    END SUBROUTINE set_rstw_active
+
+    SUBROUTINE set_numro_active(file_hdl)
+    TYPE(xios_field) :: field_hdl
+    TYPE(xios_file) :: file_hdl
 
         CALL xios_add_child(file_hdl, field_hdl, "rdt")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "rdttra1")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "un")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "ub")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "vn")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "vb")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "tn")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "tb")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "sn")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "sb")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "sshn")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "sshb")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "hdivn")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "hdivb")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "rhop")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "rotn")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
         CALL xios_add_child(file_hdl, field_hdl, "rotb")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
-
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
 !in daymod.F90
            CALL xios_add_child(file_hdl, field_hdl, "kt")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_scalar", operation = "instant")
+                     scalar_ref = "grid_scalar", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "ndastp")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_scalar", operation = "instant")
+                     scalar_ref = "grid_scalar", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "adatrj")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_scalar", operation = "instant")
+                     scalar_ref = "grid_scalar", operation = "instant")
 !end daymod.F90
 !sbcmod.F90
            CALL xios_add_child(file_hdl, field_hdl, "utau_b")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "vtau_b")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "qns_b")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "emp_b")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "sfx_b")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 !end sbcmod.F90
 !ALL FIELDS ABOUVE ALWAYS
@@ -394,25 +461,25 @@
            CALL xios_add_child(file_hdl, field_hdl, "en")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N_3D", operation = "instant")
+                     domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "avt")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N_3D", operation = "instant")
+                     domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "avm")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N_3D", operation = "instant")
+                     domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "avmu")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N_3D", operation = "instant")
+                     domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "avmv")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N_3D", operation = "instant")
+                     domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "dissl")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N_3D", operation = "instant")
+                     domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 #endif
 !end zdftke.F90
@@ -420,9 +487,9 @@
        CALL xios_add_child(file_hdl, field_hdl, "qsr_hc_b")
        CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N_3D" , operation = "instant")        
+                     domain_ref="grid_N", axis_ref="deptht" , operation = "instant")        
 
        CALL xios_add_child(file_hdl, field_hdl, "fraqsr_1lev")
        CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")        
+                     domain_ref = "grid_N", operation = "instant")        
 !END traqsr.F90
 #if defined key_dynspg_flt   ||   defined key_esopa 
@@ -430,9 +497,9 @@
            CALL xios_add_child(file_hdl, field_hdl, "gcx")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "gcxb")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 !end dynspg_flt.F90
 #endif
@@ -440,21 +507,21 @@
            CALL xios_add_child(file_hdl, field_hdl, "sbc_hc_b")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "sbc_sc_b")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "fwf_isf_b")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "isf_sc_b")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
            CALL xios_add_child(file_hdl, field_hdl, "isf_hc_b")
            CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 !trasbc.F90 END
         IF( lk_oasis) THEN
@@ -463,25 +530,25 @@
              CALL xios_add_child(file_hdl, field_hdl, "greenland_icesheet_mass")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "greenland_icesheet_timelapsed")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "greenland_icesheet_mass_roc")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "antarctica_icesheet_mass")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "antarctica_icesheet_timelapsed")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "antarctica_icesheet_mass_roc")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
           ENDIF
         ENDIF
@@ -489,5 +556,5 @@
         CALL xios_add_child(file_hdl, field_hdl, "rhd")
         CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-             grid_ref = "grid_N_3D", operation = "instant")
+             domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 #endif
 !dia_hsb_rst
@@ -496,29 +563,29 @@
              CALL xios_add_child(file_hdl, field_hdl, "frc_v")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "frc_t")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "frc_s")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "ssh_ini")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "e3t_ini")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "hc_loc_ini")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "sc_loc_ini")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
 
@@ -526,17 +593,17 @@
                 CALL xios_add_child(file_hdl, field_hdl, "frc_wn_t")
                 CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_scalar", operation = "instant")
+                     scalar_ref = "grid_scalar", operation = "instant")
 
                 CALL xios_add_child(file_hdl, field_hdl, "frc_wn_s")
                 CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_scalar", operation = "instant")
+                     scalar_ref = "grid_scalar", operation = "instant")
 
                 CALL xios_add_child(file_hdl, field_hdl, "ssh_hc_loc_ini")
                 CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
                 CALL xios_add_child(file_hdl, field_hdl, "ssh_sc_loc_ini")
                 CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
 
@@ -549,23 +616,23 @@
              CALL xios_add_child(file_hdl, field_hdl, "fse3t_b")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "fse3t_n")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N_3D", operation = "instant")
+                  domain_ref="grid_N", axis_ref="deptht", operation = "instant")
 
            IF( lr_vvl_ztilde .OR. lr_vvl_layer ) THEN  ! z_tilde and layer cases !
              CALL xios_add_child(file_hdl, field_hdl, "tilde_e3t_b")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "tilde_e3t_n")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
             END IF
             IF( lr_vvl_ztilde ) THEN                    ! z_tilde case !
             CALL xios_add_child(file_hdl, field_hdl, "hdiv_lf")
             CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
             ENDIF
          ENDIF
@@ -575,9 +642,9 @@
          CALL xios_add_child(file_hdl, field_hdl, "ub2_b")
          CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-              grid_ref = "grid_N", operation = "instant")
+              domain_ref = "grid_N", operation = "instant")
 
          CALL xios_add_child(file_hdl, field_hdl, "vb2_b")
          CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-              grid_ref = "grid_N", operation = "instant")
+              domain_ref = "grid_N", operation = "instant")
 
 
@@ -585,25 +652,25 @@
             CALL xios_add_child(file_hdl, field_hdl, "sshbb_e")
             CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                 grid_ref = "grid_N", operation = "instant")
+                 domain_ref = "grid_N", operation = "instant")
 
             CALL xios_add_child(file_hdl, field_hdl, "ubb_e")
             CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                 grid_ref = "grid_N", operation = "instant")
+                 domain_ref = "grid_N", operation = "instant")
 
             CALL xios_add_child(file_hdl, field_hdl, "vbb_e")
             CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                 grid_ref = "grid_N", operation = "instant")
+                 domain_ref = "grid_N", operation = "instant")
 
             CALL xios_add_child(file_hdl, field_hdl, "sshb_e")
             CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                 grid_ref = "grid_N", operation = "instant")
+                 domain_ref = "grid_N", operation = "instant")
 
             CALL xios_add_child(file_hdl, field_hdl, "ub_e")
             CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                 grid_ref = "grid_N", operation = "instant")
+                 domain_ref = "grid_N", operation = "instant")
 
             CALL xios_add_child(file_hdl, field_hdl, "vb_e")
             CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                 grid_ref = "grid_N", operation = "instant")
+                 domain_ref = "grid_N", operation = "instant")
          ENDIF
 #if defined key_agrif
@@ -612,9 +679,9 @@
                CALL xios_add_child(file_hdl, field_hdl, "ub2_i_b")
                CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                    grid_ref = "GRID_N", operation = "instant")
+                    domain_ref = "grid_N", operation = "instant")
 
                CALL xios_add_child(file_hdl, field_hdl, "vb2_i_b")
                CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                    grid_ref = "grid_N", operation = "instant")
+                    domain_ref = "grid_N", operation = "instant")
          ENDIF
 #endif
@@ -625,5 +692,5 @@
              CALL xios_add_child(file_hdl, field_hdl, "ssh_ibb")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
           ENDIF
 !end sbcapr.F90
@@ -632,13 +699,13 @@
              CALL xios_add_child(file_hdl, field_hdl, "rnf_b")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "rnf_hc_b")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "rnf_sc_b")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
         ENDIF 
 !end sbcrnf.F90
@@ -647,34 +714,34 @@
              CALL xios_add_child(file_hdl, field_hdl, "nn_fsbc")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_scalar", operation = "instant")
+                  scalar_ref = "grid_scalar", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "ssu_m")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "ssv_m")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "sst_m")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "sss_m")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "ssh_m")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                  grid_ref = "grid_N", operation = "instant")
+                  domain_ref = "grid_N", operation = "instant")
 
              CALL xios_add_child(file_hdl, field_hdl, "frq_m")
              CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
 
              IF( lk_vvl )  THEN
                 CALL xios_add_child(file_hdl, field_hdl, "e3t_m")
                 CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-                     grid_ref = "grid_N", operation = "instant")
+                     domain_ref = "grid_N", operation = "instant")
              ENDIF 
         ENDIF
@@ -683,12 +750,12 @@
           CALL xios_add_child(file_hdl, field_hdl, "avmb")
           CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-               grid_ref = "Vgrid", operation = "instant")
+               axis_ref = "deptht", operation = "instant")
 
           CALL xios_add_child(file_hdl, field_hdl, "avtb")
           CALL xios_set_attr (field_hdl, enabled = .TRUE., prec = 8,           &
-               grid_ref = "Vgrid", operation = "instant")
+               axis_ref = "deptht", operation = "instant")
        ENDIF
 
-   END SUBROUTINE set_rstw_active
+   END SUBROUTINE set_numro_active
 
    SUBROUTINE iom_swap( cdname )
@@ -1871,5 +1938,5 @@
 
 
-   SUBROUTINE set_grid( cdgrd, plon, plat, lmask )
+   SUBROUTINE set_grid( cdgrd, plon, plat, lxios )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE set_grid  ***
@@ -1884,5 +1951,5 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmask
       INTEGER  :: ni,nj
-      LOGICAL :: lmask
+      LOGICAL :: lxios
       
       ni=nlei-nldi+1 ; nj=nlej-nldj+1
@@ -1894,8 +1961,8 @@
 #endif     
       CALL iom_set_domain_attr("grid_"//cdgrd, data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
-      CALL iom_set_domain_attr("grid_"//cdgrd, lonvalue = RESHAPE(plon(nldi:nlei, nldj:nlej),(/ ni*nj /)),   &
+      if(.NOT.lxios) CALL iom_set_domain_attr("grid_"//cdgrd, lonvalue = RESHAPE(plon(nldi:nlei, nldj:nlej),(/ ni*nj /)),   &
          &                                     latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /)))  
 
-      IF ( lmask ) THEN
+      IF ( ln_mskland.AND.(.NOT.lxios) ) THEN
          ! mask land points, keep values on coast line -> specific mask for U, V and W points
          SELECT CASE ( cdgrd )
Index: branches/UKMO/dev_r7573_xios_write/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90
===================================================================
--- branches/UKMO/dev_r7573_xios_write/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 8297)
+++ branches/UKMO/dev_r7573_xios_write/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 8299)
@@ -126,5 +126,6 @@
                CALL iom_open( TRIM(clpath)//TRIM(clname), numrow, ldwrt = .TRUE., kiolib = jprstlib )
             ELSE
-               CALL iom_init( wxios_context, TRIM(clpath)//TRIM(clname) )
+               wxios_context = "rstw_"//TRIM(ADJUSTL(clkt))
+               CALL iom_rstw_init( wxios_context, TRIM(clpath)//TRIM(clname) )
                CALL xios_update_calendar(nitrst)
                CALL iom_swap(      cxios_context          )
