Index: /branches/UKMO/dev_r5518_Surge_Modelling/NEMOGCM/CONFIG/AMM7_SURGE/EXP00/iodef.xml
===================================================================
--- /branches/UKMO/dev_r5518_Surge_Modelling/NEMOGCM/CONFIG/AMM7_SURGE/EXP00/iodef.xml	(revision 15721)
+++ /branches/UKMO/dev_r5518_Surge_Modelling/NEMOGCM/CONFIG/AMM7_SURGE/EXP00/iodef.xml	(revision 15722)
@@ -2,5 +2,5 @@
 <simulation> 
 
- <context id="nemo" time_origin="1950-01-01 00:00:00" >
+ <context id="nemo" >
     
     <!-- $id$ -->
@@ -89,16 +89,34 @@
    
    <grid_definition>    
-     <grid id="grid_T_2D" domain_ref="grid_T"/>
-     <grid id="grid_T_3D" domain_ref="grid_T" axis_ref="deptht"/>
-     <grid id="grid_U_2D" domain_ref="grid_U"/>
-     <grid id="grid_U_3D" domain_ref="grid_U" axis_ref="depthu"/>
-     <grid id="grid_V_2D" domain_ref="grid_V"/>
-     <grid id="grid_V_3D" domain_ref="grid_V" axis_ref="depthv"/>
-     <grid id="grid_W_2D" domain_ref="grid_W"/>
-     <grid id="grid_W_3D" domain_ref="grid_W" axis_ref="depthw"/>
-     <grid id="gznl_T_2D" domain_ref="gznl"/>
-     <grid id="gznl_T_3D" domain_ref="gznl" axis_ref="deptht"/>
-     <grid id="gznl_W_3D" domain_ref="gznl" axis_ref="depthw"/>
-    </grid_definition>   
+    <grid id="grid_T_2D" > 
+      <domain id="grid_T" /> 
+    </grid> 
+    <grid id="grid_T_3D" > 
+      <domain id="grid_T" /> 
+      <axis id="deptht" /> 
+    </grid> 
+    <grid id="grid_U_2D" > 
+      <domain id="grid_U" /> 
+    </grid> 
+    <grid id="grid_U_3D" > 
+      <domain id="grid_U" /> 
+      <axis id="depthu" /> 
+    </grid> 
+    <grid id="grid_V_2D" > 
+      <domain id="grid_V" /> 
+    </grid> 
+    <grid id="grid_V_3D" > 
+      <domain id="grid_V" /> 
+      <axis id="depthv" /> 
+    </grid> 
+    <grid id="grid_W_2D" > 
+      <domain id="grid_W" /> 
+    </grid> 
+    <grid id="grid_W_3D" > 
+      <domain id="grid_W" /> 
+      <axis id="depthw" /> 
+    </grid> 
+    <grid id="scalarpoint" /> 
+    </grid_definition>  
   </context>
   
@@ -111,9 +129,7 @@
         We must have buffer_size > jpi*jpj*jpk*8 (with jpi and jpj the subdomain size)
 -->
-	  <variable id="buffer_size"               type="integer">10000000</variable>
-	  <variable id="buffer_server_factor_size" type="integer">2</variable>
-	  <variable id="info_level"                type="integer">0</variable>
-	  <variable id="using_server"              type="boolean">true</variable>
-	  <variable id="using_oasis"               type="boolean">false</variable>
+    <variable id="info_level"                type="int">0</variable> 
+    <variable id="using_server"              type="bool">true</variable> 
+    <variable id="using_oasis"               type="bool">false</variable> 
 	  <variable id="oasis_codes_id"            type="string" >oceanx</variable>
 	
Index: /branches/UKMO/dev_r5518_Surge_Modelling/NEMOGCM/CONFIG/AMM7_SURGE/cpp_AMM7_SURGE.fcm
===================================================================
--- /branches/UKMO/dev_r5518_Surge_Modelling/NEMOGCM/CONFIG/AMM7_SURGE/cpp_AMM7_SURGE.fcm	(revision 15721)
+++ /branches/UKMO/dev_r5518_Surge_Modelling/NEMOGCM/CONFIG/AMM7_SURGE/cpp_AMM7_SURGE.fcm	(revision 15722)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys  key_nosignedzero key_bdy key_tide key_dynspg_ts key_vvl key_diainstant key_mpp_mpi key_iomput key_surge
+ bld::tool::fppkeys  key_nosignedzero key_bdy key_tide key_dynspg_ts key_vvl key_diainstant key_mpp_mpi key_iomput key_surge key_xios2
Index: /branches/UKMO/dev_r5518_Surge_Modelling/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- /branches/UKMO/dev_r5518_Surge_Modelling/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 15721)
+++ /branches/UKMO/dev_r5518_Surge_Modelling/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 15722)
@@ -94,14 +94,21 @@
       CHARACTER(len=*), INTENT(in)  :: cdname
 #if defined key_iomput
-      TYPE(xios_time)   :: dtime    = xios_time(0, 0, 0, 0, 0, 0)
-      CHARACTER(len=19) :: cldate 
-      CHARACTER(len=10) :: clname
-      INTEGER           ::   ji
+#if ! defined key_xios2
+       TYPE(xios_time)     :: dtime    = xios_time(0, 0, 0, 0, 0, 0)
+       CHARACTER(len=19)   :: cldate 
+#else
+       TYPE(xios_duration) :: dtime    = xios_duration(0, 0, 0, 0, 0, 0)
+       TYPE(xios_date)     :: start_date
+#endif
+       CHARACTER(len=10)   :: clname
+       INTEGER             :: ji
       !
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: z_bnds
       !!----------------------------------------------------------------------
-
+#if ! defined key_xios2
       ALLOCATE( z_bnds(jpk,2) )
-
+#else
+       ALLOCATE( z_bnds(2,jpk) )
+#endif
       clname = cdname
       IF( TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(cdname)
@@ -110,4 +117,5 @@
 
       ! calendar parameters
+#if ! defined key_xios2
       SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
       CASE ( 1)   ;   CALL xios_set_context_attr(TRIM(clname), calendar_type= "Gregorian")
@@ -117,5 +125,15 @@
       WRITE(cldate,"(i4.4,'-',i2.2,'-',i2.2,' ',i2.2,':',i2.2,':00')") nyear,nmonth,nday,nhour,nminute
       CALL xios_set_context_attr(TRIM(clname), start_date=cldate )
-
+#else
+       ! 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(1950,01,01,00,00,00), &
+           &                                    start_date = xios_date(nyear,nmonth,nday,nhour,nminute,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,nhour,nminute,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,nhour,nminute,0) )
+       END SELECT
+#endif
       ! horizontal grid definition
       CALL set_scalar
@@ -170,13 +188,25 @@
 
       ! Add vertical grid bounds
+#if ! defined key_xios2
       z_bnds(:      ,1) = gdepw_1d(:)
       z_bnds(1:jpkm1,2) = gdepw_1d(2:jpk)
       z_bnds(jpk:   ,2) = gdepw_1d(jpk) + e3t_1d(jpk)
+#else
+       z_bnds(1      ,:) = gdepw_1d(:)
+       z_bnds(2,1:jpkm1) = gdepw_1d(2:jpk)
+       z_bnds(2,jpk:   ) = gdepw_1d(jpk) + e3t_1d(jpk)
+#endif
       CALL iom_set_axis_attr( "deptht", bounds=z_bnds )
       CALL iom_set_axis_attr( "depthu", bounds=z_bnds )
       CALL iom_set_axis_attr( "depthv", bounds=z_bnds )
-      z_bnds(:    ,2) = gdept_1d(:)
-      z_bnds(2:jpk,1) = gdept_1d(1:jpkm1)
-      z_bnds(1    ,1) = gdept_1d(1) - e3w_1d(1)
+#if ! defined key_xios2
+       z_bnds(:    ,2)  = gdept_1d(:)
+       z_bnds(2:jpk,1)  = gdept_1d(1:jpkm1)
+       z_bnds(1    ,1)  = gdept_1d(1) - e3w_1d(1)
+#else
+       z_bnds(2,:    )  = gdept_1d(:)
+       z_bnds(1,2:jpk)  = gdept_1d(1:jpkm1)
+       z_bnds(1,1    )  = gdept_1d(1) - e3w_1d(1)
+#endif
       CALL iom_set_axis_attr( "depthw", bounds=z_bnds )
 
@@ -1104,9 +1134,14 @@
       CHARACTER(LEN=*), INTENT(in) ::   cdname
       REAL(wp)        , INTENT(in) ::   pfield0d
+#if ! defined key_xios2
       REAL(wp)        , DIMENSION(jpi,jpj) ::   zz     ! masson
+#endif
 #if defined key_iomput
+#if ! defined key_xios2
       zz(:,:)=pfield0d
       CALL xios_send_field(cdname, zz)
-      !CALL xios_send_field(cdname, (/pfield0d/)) 
+#else
+       CALL xios_send_field(cdname, (/pfield0d/)) 
+#endif
 #else
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
@@ -1156,6 +1191,10 @@
       REAL(wp), DIMENSION(:)   , OPTIONAL, INTENT(in) ::   lonvalue, latvalue
       REAL(wp), DIMENSION(:,:) , OPTIONAL, INTENT(in) ::   bounds_lon, bounds_lat, area
+#if ! defined key_xios2
       LOGICAL,  DIMENSION(:,:) , OPTIONAL, INTENT(in) ::   mask
-
+#else
+       LOGICAL,  DIMENSION(:) , OPTIONAL, INTENT(in) ::   mask
+#endif
+#if ! defined key_xios2
       IF ( xios_is_valid_domain     (cdid) ) THEN
          CALL xios_set_domain_attr     ( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
@@ -1173,9 +1212,31 @@
             &    bounds_lat=bounds_lat, area=area )
       ENDIF
+#else
+       IF ( xios_is_valid_domain     (cdid) ) THEN
+          CALL xios_set_domain_attr     ( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
+             &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
+             &    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
+       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,   &
+             &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
+             &    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
       CALL xios_solve_inheritance()
 
    END SUBROUTINE iom_set_domain_attr
-
-
+#if defined key_xios2
+   SUBROUTINE iom_set_zoom_domain_attr( cdid, ibegin, jbegin, ni, nj)
+      CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
+      INTEGER                  , OPTIONAL, INTENT(in) ::   ibegin, jbegin, ni, nj
+      IF ( xios_is_valid_zoom_domain     (cdid) ) THEN
+          CALL xios_set_zoom_domain_attr     ( cdid, ibegin=ibegin, jbegin=jbegin, ni=ni,    &
+            &   nj=nj)
+     ENDIF
+   END SUBROUTINE iom_set_zoom_domain_attr
+#endif
    SUBROUTINE iom_set_axis_attr( cdid, paxis, bounds )
       CHARACTER(LEN=*)      , INTENT(in) ::   cdid
@@ -1183,6 +1244,11 @@
       REAL(wp), DIMENSION(:,:), OPTIONAL, INTENT(in) ::   bounds
       IF ( PRESENT(paxis) ) THEN
+#if ! defined key_xios2
          IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, size=SIZE(paxis), value=paxis )
          IF ( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, size=SIZE(paxis), value=paxis )
+#else
+          IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, n_glo=SIZE(paxis), value=paxis )
+          IF ( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, n_glo=SIZE(paxis), value=paxis )
+#endif
       ENDIF
       IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, bounds=bounds )
@@ -1194,8 +1260,15 @@
    SUBROUTINE iom_set_field_attr( cdid, freq_op, freq_offset )
       CHARACTER(LEN=*)          , INTENT(in) ::   cdid
-      CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   freq_op
-      CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   freq_offset
-      IF ( xios_is_valid_field     (cdid) )   CALL xios_set_field_attr     ( cdid, freq_op=freq_op, freq_offset=freq_offset )
-      IF ( xios_is_valid_fieldgroup(cdid) )   CALL xios_set_fieldgroup_attr( cdid, freq_op=freq_op, freq_offset=freq_offset )
+#if ! defined key_xios2
+       CHARACTER(LEN=*)   ,OPTIONAL , INTENT(in) ::   freq_op
+       CHARACTER(LEN=*)   ,OPTIONAL , INTENT(in) ::   freq_offset
+#else
+       TYPE(xios_duration),OPTIONAL , INTENT(in) ::   freq_op
+       TYPE(xios_duration),OPTIONAL , INTENT(in) ::   freq_offset
+#endif
+       IF ( xios_is_valid_field     (cdid) )   CALL xios_set_field_attr       &
+     &     ( cdid, freq_op=freq_op, freq_offset=freq_offset )
+       IF ( xios_is_valid_fieldgroup(cdid) )   CALL xios_set_fieldgroup_attr  &
+     &                    ( cdid, freq_op=freq_op, freq_offset=freq_offset )
       CALL xios_solve_inheritance()
    END SUBROUTINE iom_set_field_attr
@@ -1213,10 +1286,19 @@
    SUBROUTINE iom_get_file_attr( cdid, name, name_suffix, output_freq )
       CHARACTER(LEN=*)          , INTENT(in ) ::   cdid
-      CHARACTER(LEN=*),OPTIONAL , INTENT(out) ::   name, name_suffix, output_freq
+       CHARACTER(LEN=*),OPTIONAL , INTENT(out) ::   name, name_suffix
+#if ! defined key_xios2
+       CHARACTER(LEN=*),OPTIONAL , INTENT(out) ::    output_freq
+#else
+       TYPE(xios_duration)   ,OPTIONAL , INTENT(out) :: output_freq
+#endif 
       LOGICAL                                 ::   llexist1,llexist2,llexist3
       !---------------------------------------------------------------------
       IF( PRESENT( name        ) )   name = ''          ! default values
       IF( PRESENT( name_suffix ) )   name_suffix = ''
+#if ! defined key_xios2
       IF( PRESENT( output_freq ) )   output_freq = ''
+#else
+       IF( PRESENT( output_freq ) )   output_freq = xios_duration(0,0,0,0,0,0)
+#endif
       IF ( xios_is_valid_file     (cdid) ) THEN
          CALL xios_solve_inheritance()
@@ -1239,6 +1321,11 @@
       CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
       LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(in) ::   mask
+#if ! defined key_xios2
       IF ( xios_is_valid_grid     (cdid) )   CALL xios_set_grid_attr     ( cdid, mask=mask )
       IF ( xios_is_valid_gridgroup(cdid) )   CALL xios_set_gridgroup_attr( cdid, mask=mask )
+#else
+       IF ( xios_is_valid_grid     (cdid) )   CALL xios_set_grid_attr     ( cdid, mask_3D=mask )
+       IF ( xios_is_valid_gridgroup(cdid) )   CALL xios_set_gridgroup_attr( cdid, mask_3D=mask )
+#endif
       CALL xios_solve_inheritance()
    END SUBROUTINE iom_set_grid_attr
@@ -1281,6 +1368,9 @@
       
       ni=nlei-nldi+1 ; nj=nlej-nldj+1
-
+#if ! defined key_xios2
       CALL iom_set_domain_attr("grid_"//cdgrd, ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-1, jbegin=njmpp+nldj-1, ni=ni, nj=nj)
+#else
+      CALL iom_set_domain_attr("grid_"//cdgrd, ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj)
+#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 /)),   &
@@ -1296,5 +1386,9 @@
          END SELECT
          !
+#if ! defined key_xios2
          CALL iom_set_domain_attr( "grid_"//cdgrd       , mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,1),(/ni,nj    /)) /= 0. )
+#else
+          CALL iom_set_domain_attr( "grid_"//cdgrd       , mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,1),(/ni*nj    /)) /= 0. )
+#endif 
          CALL iom_set_grid_attr  ( "grid_"//cdgrd//"_3D", mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,:),(/ni,nj,jpk/)) /= 0. )
       ENDIF
@@ -1429,5 +1523,6 @@
       ni=nlei-nldi+1 ; nj=nlej-nldj+1            ! define zonal mean domain (jpj*jpk)
       ALLOCATE( zlon(ni*nj) )       ;       zlon(:) = 0.
-
+       CALL dom_ngb( -168.7, 65.6, ix, iy, 'T' ) !  i-line that passes across Bering strait to avoid land processor (used in plots)
+#if ! defined key_xios2
       CALL iom_set_domain_attr("gznl", ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-1, jbegin=njmpp+nldj-1, ni=ni, nj=nj)
       CALL iom_set_domain_attr("gznl", data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
@@ -1435,6 +1530,13 @@
          &                             latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /)))  
       !
-      CALL dom_ngb( 180., 90., ix, iy, 'T' ) !  i-line that passes near the North Pole : Reference latitude (used in plots)
       CALL iom_set_domain_attr ('ptr', zoom_ibegin=ix, zoom_nj=jpjglo)
+#else
+ ! Pas teste : attention aux indices !
+       CALL iom_set_domain_attr("gznl", ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj)
+       CALL iom_set_domain_attr("gznl", data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
+       CALL iom_set_domain_attr("gznl", lonvalue = zlon,   &
+          &                             latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /))) 
+        CALL iom_set_zoom_domain_attr ("ptr", ibegin=ix-1, jbegin=0, ni=1, nj=jpjglo)
+#endif
       CALL iom_update_file_name('ptr')
       !
@@ -1450,5 +1552,9 @@
       REAL(wp), DIMENSION(1)   ::   zz = 1.
       !!----------------------------------------------------------------------
+#if ! defined key_xios2
       CALL iom_set_domain_attr('scalarpoint', ni_glo=jpnij, nj_glo=1, ibegin=narea, jbegin=1, ni=1, nj=1)
+#else
+       CALL iom_set_domain_attr('scalarpoint', ni_glo=jpnij, nj_glo=1, ibegin=narea-1, jbegin=0, ni=1, nj=1)
+#endif
       CALL iom_set_domain_attr('scalarpoint', data_dim=2, data_ibegin = 1, data_ni = 1, data_jbegin = 1, data_nj = 1)
       
@@ -1479,12 +1585,32 @@
       REAL(wp)        ,DIMENSION( 3) ::   zlonpira                 ! longitudes of pirata moorings
       REAL(wp)        ,DIMENSION( 9) ::   zlatpira                 ! latitudes  of pirata moorings
+#if  defined key_xios2
+       TYPE(xios_duration)            ::   f_op, f_of
+#endif
+  
       !!----------------------------------------------------------------------
       ! 
       ! frequency of the call of iom_put (attribut: freq_op)
-      WRITE(cl1,'(i1)')        1   ;   CALL iom_set_field_attr('field_definition', freq_op = cl1//'ts', freq_offset='0ts')
-      WRITE(cl1,'(i1)')  nn_fsbc   ;   CALL iom_set_field_attr('SBC'             , freq_op = cl1//'ts', freq_offset='0ts')
-      WRITE(cl1,'(i1)')  nn_fsbc   ;   CALL iom_set_field_attr('SBC_scalar'      , freq_op = cl1//'ts', freq_offset='0ts')
-      WRITE(cl1,'(i1)') nn_dttrc   ;   CALL iom_set_field_attr('ptrc_T'          , freq_op = cl1//'ts', freq_offset='0ts')
-      WRITE(cl1,'(i1)') nn_dttrc   ;   CALL iom_set_field_attr('diad_T'          , freq_op = cl1//'ts', freq_offset='0ts')
+#if ! defined key_xios2
+       WRITE(cl1,'(i1)')        1   ;   CALL iom_set_field_attr('field_definition', freq_op=cl1//'ts', freq_offset='0ts')
+       WRITE(cl1,'(i1)')        2   ;   CALL iom_set_field_attr('trendT_even'      , freq_op=cl1//'ts', freq_offset='0ts')
+       WRITE(cl1,'(i1)')        2   ;   CALL iom_set_field_attr('trendT_odd'       , freq_op=cl1//'ts', freq_offset='-1ts')
+       WRITE(cl1,'(i1)')        2   ;   CALL iom_set_field_attr('ptrd_T_even'      , freq_op=cl1//'ts', freq_offset='0ts')
+       WRITE(cl1,'(i1)')        2   ;   CALL iom_set_field_attr('ptrd_T_odd'       , freq_op=cl1//'ts', freq_offset='-1ts')
+       WRITE(cl1,'(i1)')  nn_fsbc   ;   CALL iom_set_field_attr('SBC'             , freq_op=cl1//'ts', freq_offset='0ts')
+       WRITE(cl1,'(i1)')  nn_fsbc   ;   CALL iom_set_field_attr('SBC_scalar'      , freq_op=cl1//'ts', freq_offset='0ts')
+       WRITE(cl1,'(i1)') nn_dttrc   ;   CALL iom_set_field_attr('ptrc_T'          , freq_op=cl1//'ts', freq_offset='0ts')
+       WRITE(cl1,'(i1)') nn_dttrc   ;   CALL iom_set_field_attr('diad_T'          , freq_op=cl1//'ts', freq_offset='0ts')
+#else
+       f_op%timestep = 1        ;  f_of%timestep = 0  ; CALL iom_set_field_attr('field_definition', freq_op=f_op, freq_offset=f_of)
+       f_op%timestep = 2        ;  f_of%timestep = 0  ; CALL iom_set_field_attr('trendT_even'      , freq_op=f_op, freq_offset=f_of)
+       f_op%timestep = 2        ;  f_of%timestep = -1 ; CALL iom_set_field_attr('trendT_odd'       , freq_op=f_op, freq_offset=f_of)
+       f_op%timestep = 2        ;  f_of%timestep = 0  ; CALL iom_set_field_attr('ptrd_T_even'      , freq_op=f_op, freq_offset=f_of)
+       f_op%timestep = 2        ;  f_of%timestep = -1 ; CALL iom_set_field_attr('ptrd_T_odd'       , freq_op=f_op, freq_offset=f_of)
+       f_op%timestep = nn_fsbc  ;  f_of%timestep = 0  ; CALL iom_set_field_attr('SBC'             , freq_op=f_op, freq_offset=f_of)
+       f_op%timestep = nn_fsbc  ;  f_of%timestep = 0  ; CALL iom_set_field_attr('SBC_scalar'      , freq_op=f_op, freq_offset=f_of)
+       f_op%timestep = nn_dttrc ;  f_of%timestep = 0  ; CALL iom_set_field_attr('ptrc_T'          , freq_op=f_op, freq_offset=f_of)
+       f_op%timestep = nn_dttrc ;  f_of%timestep = 0  ; CALL iom_set_field_attr('diad_T'          , freq_op=f_op, freq_offset=f_of)
+#endif
        
       ! output file names (attribut: name)
@@ -1508,5 +1634,9 @@
          ! Equatorial section (attributs: jbegin, ni, name_suffix)
          CALL dom_ngb( 0., 0., ix, iy, cl1 )
+#if ! defined key_xios2
          CALL iom_set_domain_attr ('Eq'//cl1, zoom_jbegin=iy, zoom_ni=jpiglo)
+#else
+          CALL iom_set_zoom_domain_attr ('Eq'//cl1, jbegin=iy-1, ni=jpiglo)
+#endif
          CALL iom_get_file_attr   ('Eq'//cl1, name_suffix = clsuff             )
          CALL iom_set_file_attr   ('Eq'//cl1, name_suffix = TRIM(clsuff)//'_Eq')
@@ -1588,5 +1718,9 @@
                ENDIF
                clname = TRIM(ADJUSTL(clat))//TRIM(ADJUSTL(clon))
+#if ! defined key_xios2
                CALL iom_set_domain_attr (TRIM(clname)//cl1, zoom_ibegin= ix, zoom_jbegin= iy)
+#else
+                CALL iom_set_zoom_domain_attr  (TRIM(clname)//cl1, ibegin= ix-1, jbegin= iy-1)
+#endif
                CALL iom_get_file_attr   (TRIM(clname)//cl1, name_suffix = clsuff                         )
                CALL iom_set_file_attr   (TRIM(clname)//cl1, name_suffix = TRIM(clsuff)//'_'//TRIM(clname))
@@ -1617,9 +1751,16 @@
       REAL(wp)           ::   zsec
       LOGICAL            ::   llexist
+#if  defined key_xios2
+       TYPE(xios_duration)   ::   output_freq 
+#endif     
       !!----------------------------------------------------------------------
 
       DO jn = 1,2
-
+#if ! defined key_xios2
          IF( jn == 1 )   CALL iom_get_file_attr( cdid, name        = clname, output_freq = clfreq )
+#else
+          output_freq = xios_duration(0,0,0,0,0,0)
+          IF( jn == 1 )   CALL iom_get_file_attr( cdid, name        = clname, output_freq = output_freq )
+#endif
          IF( jn == 2 )   CALL iom_get_file_attr( cdid, name_suffix = clname )
 
@@ -1631,5 +1772,5 @@
                idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@')
             END DO
-
+#if ! defined key_xios2
             idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
             DO WHILE ( idx /= 0 ) 
@@ -1644,5 +1785,36 @@
                idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
             END DO
-
+#else
+             idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
+             DO WHILE ( idx /= 0 ) 
+               IF ( output_freq%timestep /= 0) THEN
+                  WRITE(clfreq,'(I18,A2)')INT(output_freq%timestep),'ts'
+                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
+               ELSE IF ( output_freq%second /= 0 ) THEN
+                  WRITE(clfreq,'(I19,A1)')INT(output_freq%second),'s'
+                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
+               ELSE IF ( output_freq%minute /= 0 ) THEN
+                  WRITE(clfreq,'(I18,A2)')INT(output_freq%minute),'mi'
+                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
+               ELSE IF ( output_freq%hour /= 0 ) THEN
+                  WRITE(clfreq,'(I19,A1)')INT(output_freq%hour),'h'
+                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
+               ELSE IF ( output_freq%day /= 0 ) THEN
+                  WRITE(clfreq,'(I19,A1)')INT(output_freq%day),'d'
+                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
+               ELSE IF ( output_freq%month /= 0 ) THEN
+                  WRITE(clfreq,'(I19,A1)')INT(output_freq%month),'m'
+                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
+               ELSE IF ( output_freq%year /= 0 ) THEN
+                  WRITE(clfreq,'(I19,A1)')INT(output_freq%year),'y'
+                  itrlen = LEN_TRIM(ADJUSTL(clfreq))
+               ELSE
+                   CALL ctl_stop('error in the name of file id '//TRIM(cdid),   &
+                      & ' attribute output_freq is undefined -> cannot replace @freq@ in '//TRIM(clname) )
+               ENDIF
+               clname = clname(1:idx-1)//TRIM(ADJUSTL(clfreq))//clname(idx+6:LEN_TRIM(clname))
+               idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
+             END DO
+#endif
             idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
             DO WHILE ( idx /= 0 ) 
