Index: NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom.F90
===================================================================
--- NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom.F90	(revision 11870)
+++ NEMO/branches/2019/dev_r11756_SI3restart_XIOS/src/OCE/IOM/iom.F90	(revision 11893)
@@ -64,5 +64,5 @@
    PUBLIC iom_use, iom_context_finalize, iom_miss_val
 
-   PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
+   PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d, iom_rp4d
    PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_g4d, iom_get_123d
    PRIVATE iom_p1d, iom_p2d, iom_p3d
@@ -89,5 +89,5 @@
    END INTERFACE
    INTERFACE iom_rstput
-      MODULE PROCEDURE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
+      MODULE PROCEDURE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d, iom_rp4d
    END INTERFACE
    INTERFACE iom_put
@@ -451,19 +451,21 @@
                 CALL xios_add_child(file_hdl, field_hdl, TRIM(rst_rfields(i)%vname))
                 SELECT CASE (TRIM(rst_rfields(i)%grid))
-!                CASE ("grid_Ni_4D")
-!                   CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
-!                       domain_ref="grid_N", axis_ref="nlay_i", axis_ref="numcat", operation = "instant")
-!                CASE ("grid_Ns_4D")
-!                   CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
-!                       domain_ref="grid_N", axis_ref="nlay_s", axis_ref="numcat", operation = "instant")
+#if defined key_si3
+                 CASE ("grid_Ni_4D")
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
+                         grid_ref="grid_Ni_4D", operation = "instant")
+                 CASE ("grid_Ns_4D")
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
+                         grid_ref="grid_Ns_4D", operation = "instant")
                  CASE ("grid_Ni_3D")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
-                        domain_ref="grid_N", axis_ref="numcat", operation = "instant")
+                         domain_ref="grid_N", axis_ref="numcat", operation = "instant")
+#endif
                  CASE ("grid_N_3D")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
-                        domain_ref="grid_N", axis_ref="nav_lev", operation = "instant")
+                         domain_ref="grid_N", axis_ref="nav_lev", operation = "instant")
                  CASE ("grid_N")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
-                        domain_ref="grid_N", operation = "instant") 
+                         domain_ref="grid_N", operation = "instant") 
                 CASE ("grid_vector")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
@@ -471,5 +473,5 @@
                  CASE ("grid_scalar")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(rst_rfields(i)%vname), &
-                        scalar_ref = "grid_scalar", operation = "instant")
+                         scalar_ref = "grid_scalar", operation = "instant")
                 END SELECT
                 IF(lwp) WRITE(numout,*) 'XIOS read: ', TRIM(rst_rfields(i)%vname), ' enabled in ', TRIM(rst_file)
@@ -526,27 +528,20 @@
          CALL iom_set_rstw_var_active(drst_wfields, 'sbc_sc_b')
    ELSE IF(cdmdl == "SI3") THEN
+#if defined key_si3
       CALL iom_set_rstw_var_active(drst_wfields, 'nn_fsbc_ice')
-      CALL iom_set_rstw_var_active(drst_wfields, 'kt_ice')
-      CALL iom_set_rstw_var_active(drst_wfields, 'v_i')
-      CALL iom_set_rstw_var_active(drst_wfields, 'v_s')
-      CALL iom_set_rstw_var_active(drst_wfields, 'sv_i')
-      CALL iom_set_rstw_var_active(drst_wfields, 'a_i')
-      CALL iom_set_rstw_var_active(drst_wfields, 't_su')
-      CALL iom_set_rstw_var_active(drst_wfields, 'u_ice')
-      CALL iom_set_rstw_var_active(drst_wfields, 'v_ice')
-      CALL iom_set_rstw_var_active(drst_wfields, 'oa_i')
-      CALL iom_set_rstw_var_active(drst_wfields, 'a_ip')
-      CALL iom_set_rstw_var_active(drst_wfields, 'v_ip')
-      DO jk = 1, nlay_s 
-         WRITE(zchar1,'(I2.2)') jk
-         znam = 'e_s'//'_l'//zchar1
-         CALL iom_set_rstw_var_active(drst_wfields, znam )
-      END DO
-      ! Ice enthalpy
-      DO jk = 1, nlay_i 
-         WRITE(zchar1,'(I2.2)') jk
-         znam = 'e_i'//'_l'//zchar1
-         CALL iom_set_rstw_var_active(drst_wfields, znam )
-      END DO
+      CALL iom_set_rstw_var_active(drst_wfields, 'kt_ice'     )
+      CALL iom_set_rstw_var_active(drst_wfields, 'v_i'        )
+      CALL iom_set_rstw_var_active(drst_wfields, 'v_s'        )
+      CALL iom_set_rstw_var_active(drst_wfields, 'sv_i'       )
+      CALL iom_set_rstw_var_active(drst_wfields, 'a_i'        )
+      CALL iom_set_rstw_var_active(drst_wfields, 't_su'       )
+      CALL iom_set_rstw_var_active(drst_wfields, 'u_ice'      )
+      CALL iom_set_rstw_var_active(drst_wfields, 'v_ice'      )
+      CALL iom_set_rstw_var_active(drst_wfields, 'oa_i'       )
+      CALL iom_set_rstw_var_active(drst_wfields, 'a_ip'       )
+      CALL iom_set_rstw_var_active(drst_wfields, 'v_ip'       )
+      CALL iom_set_rstw_var_active(drst_wfields, 'e_s'        )
+      CALL iom_set_rstw_var_active(drst_wfields, 'e_i'        )
+#endif
    ENDIF
 #else
@@ -707,5 +702,5 @@
         i = iom_add(i); fields(i)%vname="syyage";         fields(i)%grid="grid_Ni_3D"
         i = iom_add(i); fields(i)%vname="sxyage";         fields(i)%grid="grid_Ni_3D"
-!this part is in addition to 4D grids, to handle old format of SI3 resart
+!this part is in addition to 4D grids, to handle old format for SI3 resart
 !NEMO format restart
         DO jk = 1, nlay_s
@@ -727,5 +722,5 @@
         i = iom_add(i); fields(i)%vname="sxxc0";          fields(i)%grid="grid_Ns_4D"
         i = iom_add(i); fields(i)%vname="syyc0";          fields(i)%grid="grid_Ns_4D"
-        i = iom_add(i); fields(i)%vname="sxxc0";          fields(i)%grid="grid_Ns_4D"
+        i = iom_add(i); fields(i)%vname="sxyc0";          fields(i)%grid="grid_Ns_4D"
         !
 !NEMO format restart
@@ -839,24 +834,27 @@
                 CALL xios_add_child(file_hdl, field_hdl, TRIM(drst_wfields(i)%vname)//"_"//TRIM(ADJUSTL(snr)))
                 SELECT CASE (TRIM(drst_wfields(i)%grid))
+#if defined key_si3
+                 CASE ("grid_Ni_4D")
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
+                         grid_ref="grid_Ni_4D", prec = 8, operation = "instant")
+                 CASE ("grid_Ns_4D")
+                    CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
+                         grid_ref="grid_Ns_4D", prec = 8, operation = "instant")
                  CASE ("grid_Ni_3D")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
-                        domain_ref="grid_N", axis_ref="numcat", prec = 8, operation = "once",            &
-                        freq_offset=(kdstep -1) * xios_timestep)
+                         domain_ref="grid_N", axis_ref="numcat", prec = 8, operation = "instant")
+#endif
                  CASE ("grid_N_3D")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
-                        domain_ref="grid_N", axis_ref="nav_lev", prec = 8, operation = "once",           &
-                        freq_offset=(kdstep -1) * xios_timestep)
+                         domain_ref="grid_N", axis_ref="nav_lev", prec = 8, operation = "instant")
                  CASE ("grid_N")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
-                        domain_ref="grid_N", prec = 8, operation = "once",                               &
-                        freq_offset=(kdstep -1) * xios_timestep)
+                         domain_ref="grid_N", prec = 8, operation = "instant")
                  CASE ("grid_vector")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
-                         axis_ref="nav_lev", prec = 8, operation = "once",                               &
-                        freq_offset=(kdstep -1) * xios_timestep)
+                         axis_ref="nav_lev", prec = 8, operation = "instant")
                  CASE ("grid_scalar")
                     CALL xios_set_attr (field_hdl, enabled = .TRUE., name = TRIM(drst_wfields(i)%vname), &
-                        scalar_ref = "grid_scalar", prec = 8, operation = "once",                        &
-                        freq_offset=(kdstep -1) * xios_timestep)
+                         scalar_ref = "grid_scalar", prec = 8, operation = "instant")
                 END SELECT
          ENDIF
@@ -1953,6 +1951,32 @@
    END SUBROUTINE iom_rp3d
 
-
-  SUBROUTINE iom_delay_rst( cdaction, cdcpnt, kncid )
+   SUBROUTINE iom_rp4d( kt, kwrite, kiomid, cdvar, pvar, ktype, ldxios )
+      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
+      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
+      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
+      REAL(wp)        , INTENT(in),     DIMENSION(:,:,:,:) ::   pvar     ! written field
+      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
+      LOGICAL, OPTIONAL :: ldxios   ! xios write flag
+      LOGICAL :: llx                 ! local xios write flag
+      INTEGER :: ivid   ! variable id
+
+      llx = .FALSE.
+      IF(PRESENT(ldxios)) llx = ldxios
+      IF( llx ) THEN
+#ifdef key_iomput
+      IF( kt == kwrite ) THEN
+         IF(lwp) write(numout,*) 'RESTART: write (XIOS 4D) ',trim(cdvar)
+         write(snr, *) nitrst
+         CALL xios_send_field(trim(cdvar)//"_"//TRIM(ADJUSTL(snr)), pvar)
+      ENDIF
+#endif
+      ELSE
+        CALL ctl_stop('Error in the name  iom_rp4d for variable '//TRIM(cdvar),   &
+           & 'Restart with iom_nf90_rstput can not handle 4D cases' )
+      ENDIF
+   END SUBROUTINE iom_rp4d
+
+   SUBROUTINE iom_delay_rst( cdaction, cdcpnt, kncid )
       !!---------------------------------------------------------------------
       !!   Routine iom_delay_rst: used read/write restart related to mpp_delay
@@ -1970,5 +1994,9 @@
       !
       !return for now. When XIOS is used to write restart it also should be used to write this attribute
-      IF(lwxios) return
+      IF(lwxios) THEN
+         CALL ctl_warn( 'From iom_delay_rst: ', 'Can not '//cdaction//' mpp_delay information with XIOS')
+         RETURN
+      ENDIF
+
       !                                      ===================================
       IF( TRIM(cdaction) == 'READ' ) THEN   ! read restart related to mpp_delay !
@@ -2740,5 +2768,5 @@
    IF( iom_add > max_rst_fields) THEN
      WRITE(ctmp1,*) 'E R R O R : iom_set_rst_vars SIZE of RST_FIELD array is too small'
-     CALL ctl_stop( 'iom_add:', ctmp1 )
+     CALL ctl_stop( 'iom_add:', ctmp1, 'Increase parameter max_rst_fields')
    ENDIF
 
