Index: branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 3677)
+++ branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 3695)
@@ -32,6 +32,5 @@
    USE phycst          ! physical constants
    USE dianam          ! build name of file
-   USE mod_event_client
-   USE mod_attribut
+   USE xios
 # endif
 
@@ -51,5 +50,5 @@
    PRIVATE iom_p1d, iom_p2d, iom_p3d
 #if defined key_iomput
-   PRIVATE set_grid
+   PRIVATE iom_set_domain_attr, iom_set_field_attr, iom_set_file_attr, set_grid, set_scalar, set_xmlatt, set_mooring
 # endif
 
@@ -68,5 +67,5 @@
 #if defined key_iomput
    INTERFACE iom_setkt
-      MODULE PROCEDURE event__set_timestep
+      MODULE PROCEDURE xios_update_calendar
    END INTERFACE
 # endif
@@ -88,23 +87,24 @@
       !!----------------------------------------------------------------------
 #if defined key_iomput
-      REAL(wp) ::   ztmp
-      !!----------------------------------------------------------------------
-      ! read the xml file
-      IF( Agrif_Root() ) CALL event__parse_xml_file( 'iodef.xml' )   ! <- to get from the nameliste (namrun)...
+      TYPE(xios_time)   :: dtime    = xios_time(0, 0, 0, 0, 0, 0)
+      CHARACTER(len=19) :: cldate 
+      INTEGER           ::   ji
+      !!----------------------------------------------------------------------
+
+      CALL xios_context_initialize("nemo", mpi_comm_opa)
       CALL iom_swap
 
       ! calendar parameters
       SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
-      CASE ( 1)   ;   CALL event__set_calendar('gregorian')
-      CASE ( 0)   ;   CALL event__set_calendar('noleap'   )
-      CASE (30)   ;   CALL event__set_calendar('360d'     )
+      CASE ( 1)   ;   CALL xios_set_context_attr("nemo", calendar_type= "Gregorian")
+      CASE ( 0)   ;   CALL xios_set_context_attr("nemo", calendar_type= "NoLeap")
+      CASE (30)   ;   CALL xios_set_context_attr("nemo", calendar_type= "D360")
       END SELECT
-      ztmp = fjulday - adatrj
-      IF( ABS(ztmp  - REAL(NINT(ztmp),wp)) < 0.1 / rday )   ztmp = REAL(NINT(ztmp),wp)   ! avoid truncation error
-      CALL event__set_time_parameters( nit000 - 1, ztmp, rdt )
+      WRITE(cldate,"(i4.4,'-',i2.2,'-',i2.2,' 00:00:00')") nyear,nmonth,nday 
+      CALL xios_set_context_attr("nemo", start_date=cldate )
 
       ! horizontal grid definition
       CALL set_scalar
-      CALL set_grid( "grid_T", glamt, gphit )
+      CALL set_grid( "grid_T", glamt, gphit ) 
       CALL set_grid( "grid_U", glamu, gphiu )
       CALL set_grid( "grid_V", glamv, gphiv )
@@ -112,10 +112,10 @@
 
       ! vertical grid definition
-      CALL event__set_vert_axis( "deptht", gdept_0 )
-      CALL event__set_vert_axis( "depthu", gdept_0 )
-      CALL event__set_vert_axis( "depthv", gdept_0 )
-      CALL event__set_vert_axis( "depthw", gdepw_0 )
+      CALL xios_set_axis_attr("deptht",size=size(gdept_0),value=gdept_0)
+      CALL xios_set_axis_attr("depthu",size=size(gdept_0),value=gdept_0)
+      CALL xios_set_axis_attr("depthv",size=size(gdept_0),value=gdept_0)
+      CALL xios_set_axis_attr("depthw",size=size(gdepw_0),value=gdepw_0)
 # if defined key_floats
-      CALL event__set_vert_axis( "nfloat", REAL(nfloat,wp)  )
+      CALL xios_set_axis_attr("nfloat",size=nfloat,value=(ji, ji=1,nfloat))
 # endif
       
@@ -124,5 +124,9 @@
 
       ! end file definition
-      CALL event__close_io_definition
+       dtime%second=rdt
+       CALL xios_set_timestep(dtime)
+       CALL xios_close_context_definition()
+
+       CALL xios_update_calendar(0)
 #endif
 
@@ -137,10 +141,12 @@
       !!---------------------------------------------------------------------
 #if defined key_iomput
+      TYPE(xios_context) :: nemo_hdl
 
      IF( TRIM(Agrif_CFixed()) == '0' ) THEN
-        CALL event__swap_context("nemo")
+        CALL xios_get_handle("nemo",nemo_hdl)
      ELSE
-        CALL event__swap_context(TRIM(Agrif_CFixed())//"_nemo")
+        CALL xios_get_handle(TRIM(Agrif_CFixed())//"_nemo",nemo_hdl)
      ENDIF
+     CALL xios_set_current_context(nemo_hdl)
 
 #endif
@@ -349,5 +355,5 @@
          i_e = jpmax_files
 #if defined key_iomput
-         CALL event__stop_ioserver
+         CALL xios_context_finalize()
 #endif
       ENDIF
@@ -960,5 +966,5 @@
       REAL(wp)        , INTENT(in) ::   pfield0d
 #if defined key_iomput
-      CALL event__write_field2D( cdname, RESHAPE( (/pfield0d/), (/1,1/) ) )
+      CALL xios_send_field(cdname, (/pfield0d/))
 #else
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
@@ -969,8 +975,6 @@
       CHARACTER(LEN=*)          , INTENT(in) ::   cdname
       REAL(wp),     DIMENSION(:), INTENT(in) ::   pfield1d
-      INTEGER :: jpz
 #if defined key_iomput
-      jpz=SIZE(pfield1d)
-      CALL event__write_field3D( cdname, RESHAPE( (/pfield1d/), (/1,1,jpz/) ) )
+      CALL xios_send_field( cdname, RESHAPE( (/pfield1d/), (/1,1,SIZE(pfield1d)/) ) )
 #else
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield1d   ! useless test to avoid compilation warnings
@@ -982,5 +986,5 @@
       REAL(wp),     DIMENSION(:,:), INTENT(in) ::   pfield2d
 #if defined key_iomput
-      CALL event__write_field2D( cdname, pfield2d(nldi:nlei, nldj:nlej) )
+      CALL xios_send_field(cdname, pfield2d)
 #else
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield2d   ! useless test to avoid compilation warnings
@@ -992,5 +996,5 @@
       REAL(wp),       DIMENSION(:,:,:), INTENT(in) ::   pfield3d
 #if defined key_iomput
-      CALL event__write_field3D( cdname, pfield3d(nldi:nlei, nldj:nlej, :) )
+      CALL xios_send_field(cdname, pfield3d)
 #else
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield3d   ! useless test to avoid compilation warnings
@@ -1002,4 +1006,57 @@
 #if defined key_iomput
 
+   SUBROUTINE iom_set_domain_attr( cdname, ni_glo, nj_glo, ibegin, jbegin, ni, nj, zoom_ibegin, zoom_jbegin, zoom_ni, zoom_nj,   &
+      &                                    data_dim, data_ibegin, data_ni, data_jbegin, data_nj, lonvalue, latvalue )
+      CHARACTER(LEN=*)                , INTENT(in) ::   cdname
+      INTEGER               , OPTIONAL, INTENT(in) ::   ni_glo, nj_glo, ibegin, jbegin, ni, nj
+      INTEGER               , OPTIONAL, INTENT(in) ::   data_dim, data_ibegin, data_ni, data_jbegin, data_nj
+      INTEGER               , OPTIONAL, INTENT(in) ::   zoom_ibegin, zoom_jbegin, zoom_ni, zoom_nj
+      REAL(wp), DIMENSION(:), OPTIONAL, INTENT(in) ::   lonvalue, latvalue
+
+      IF ( xios_is_valid_domain(TRIM(cdname)) ) THEN
+         CALL xios_set_domain_attr( cdname, 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,   &
+            &    zoom_ibegin=zoom_ibegin, zoom_jbegin=zoom_jbegin, zoom_ni=zoom_ni, zoom_nj=zoom_nj,                      &
+            &    lonvalue=lonvalue, latvalue=latvalue )
+      ENDIF
+
+      IF ( xios_is_valid_domaingroup(TRIM(cdname)) ) THEN
+         CALL xios_set_domaingroup_attr( cdname, 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   ,   &
+            &    zoom_ibegin=zoom_ibegin, zoom_jbegin=zoom_jbegin, zoom_ni=zoom_ni, zoom_nj=zoom_nj,                         &
+            &    lonvalue=lonvalue, latvalue=latvalue )
+      ENDIF
+
+   END SUBROUTINE iom_set_domain_attr
+
+
+   SUBROUTINE iom_set_field_attr( cdname, freq_op)
+      CHARACTER(LEN=*)          , INTENT(in) ::   cdname
+      CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   freq_op
+
+      IF ( xios_is_valid_field(TRIM(cdname)) ) THEN
+         CALL xios_set_field_attr( cdname, freq_op=freq_op )
+      ENDIF
+      IF ( xios_is_valid_fieldgroup(TRIM(cdname)) ) THEN
+         CALL xios_set_fieldgroup_attr( cdname, freq_op=freq_op )
+      ENDIF
+
+   END SUBROUTINE iom_set_field_attr
+
+
+   SUBROUTINE iom_set_file_attr( cdname, name, name_suffix )
+      CHARACTER(LEN=*)          , INTENT(in) ::   cdname
+      CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   name, name_suffix
+
+      IF ( xios_is_valid_file(TRIM(cdname)) ) THEN
+         CALL xios_set_file_attr( cdname, name=name, name_suffix=name_suffix )
+      ENDIF
+      IF ( xios_is_valid_filegroup(TRIM(cdname)) ) THEN
+         CALL xios_set_filegroup_attr( cdname, name=name, name_suffix=name_suffix )
+      ENDIF
+
+   END SUBROUTINE iom_set_file_attr
+
+
    SUBROUTINE set_grid( cdname, plon, plat )
       !!----------------------------------------------------------------------
@@ -1012,10 +1069,13 @@
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plon
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
-
-      CALL event__set_grid_dimension( cdname, jpiglo, jpjglo)
-      CALL event__set_grid_domain( cdname, nlei-nldi+1, nlej-nldj+1, nimpp+nldi-1, njmpp+nldj-1, &
-         &                         plon(nldi:nlei, nldj:nlej), plat(nldi:nlei, nldj:nlej) )
-      CALL event__set_grid_type_nemo( cdname )
-
+      INTEGER  :: ni,nj
+      
+      ni=nlei-nldi+1 ; nj=nlej-nldj+1
+
+      CALL iom_set_domain_attr(cdname, ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-1, jbegin=njmpp+nldj-1, ni=ni, nj=nj)
+      CALL iom_set_domain_attr(cdname, data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
+      CALL iom_set_domain_attr(cdname, lonvalue = RESHAPE(plon(nldi:nlei, nldj:nlej),(/ ni*nj /)),   &
+         &                             latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /)))   
+      
    END SUBROUTINE set_grid
 
@@ -1030,7 +1090,7 @@
       REAL(wp), DIMENSION(1,1) ::   zz = 1.
       !!----------------------------------------------------------------------
-      CALL event__set_grid_dimension( 'scalarpoint', jpnij, 1)
-      CALL event__set_grid_domain   ( 'scalarpoint', 1, 1, narea, 1, zz, zz )
-      CALL event__set_grid_type_nemo( 'scalarpoint' )
+      CALL iom_set_domain_attr('scalarpoint', ni_glo=jpnij, nj_glo=1, ibegin=narea, jbegin=1, ni=1, nj=1)
+      CALL iom_set_domain_attr('scalarpoint', data_dim=1)
+      CALL iom_set_domain_attr('scalarpoint', lonvalue=(/ zz /), latvalue=(/ zz /))
 
    END SUBROUTINE set_scalar
@@ -1049,4 +1109,5 @@
       CHARACTER(len=1)               ::   cl1                      ! 1 character
       CHARACTER(len=2)               ::   cl2                      ! 1 character
+      CHARACTER(len=255)             ::   tfo
       INTEGER                        ::   idt                      ! time-step in seconds
       INTEGER                        ::   iddss, ihhss             ! number of seconds in 1 day, 1 hour and 1 year
@@ -1068,7 +1129,8 @@
 
       ! frequency of the call of iom_put (attribut: freq_op)
-      CALL event__set_attribut( 'field_definition', attr( field__freq_op, idt           ) )    ! model time-step
-      CALL event__set_attribut( 'SBC'             , attr( field__freq_op, idt * nn_fsbc ) )    ! SBC time-step
-      
+      tfo = TRIM(i2str(idt))//'s'
+      CALL iom_set_field_attr('field_definition', freq_op=tfo)
+      CALL iom_set_field_attr('SBC', freq_op=TRIM(i2str(idt* nn_fsbc))//'s')
+       
       ! output file names (attribut: name)
       clsuff(:) = (/ 'grid_T', 'grid_U', 'grid_V', 'grid_W', 'icemod', 'ptrc_T', 'diad_T', 'scalar' /)      
@@ -1078,5 +1140,5 @@
                WRITE(cl2,'(i2)') jh 
                CALL dia_nam( clname, jh * ihhss, clsuff(jg), ldfsec = .TRUE. )
-               CALL event__set_attribut( TRIM(ADJUSTL(cl2))//'h_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
+               CALL iom_set_file_attr(TRIM(ADJUSTL(cl2))//'h_'//clsuff(jg), name=TRIM(clname))
             ENDIF
          END DO
@@ -1084,5 +1146,5 @@
             WRITE(cl1,'(i1)') jd 
             CALL dia_nam( clname, jd * iddss, clsuff(jg), ldfsec = .TRUE. )
-            CALL event__set_attribut( cl1//'d_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
+            CALL iom_set_file_attr(cl1//'d_'//clsuff(jg), name=TRIM(clname))
          END DO
          DO jm = 1, 6                                                                          ! 1, 2, 3, 4, 6 months
@@ -1090,5 +1152,5 @@
                WRITE(cl1,'(i1)') jm 
                CALL dia_nam( clname, -jm, clsuff(jg) )
-               CALL event__set_attribut( cl1//'m_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
+               CALL iom_set_file_attr(cl1//'m_'//clsuff(jg), name=TRIM(clname))
             ENDIF
          END DO
@@ -1097,5 +1159,5 @@
                WRITE(cl2,'(i2)') jy 
                CALL dia_nam( clname, -jy * iyymo, clsuff(jg) )
-               CALL event__set_attribut( TRIM(ADJUSTL(cl2))//'y_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
+               CALL iom_set_file_attr(TRIM(ADJUSTL(cl2))//'y_'//clsuff(jg), name=TRIM(clname))
             ENDIF
          END DO
@@ -1108,7 +1170,6 @@
          ! Equatorial section (attributs: jbegin, ni, name_suffix)
          CALL dom_ngb( 0., 0., ix, iy, cl1 )
-         CALL event__set_attribut( 'Eq'//cl1, attr( zoom__jbegin     , iy     ) )
-         CALL event__set_attribut( 'Eq'//cl1, attr( zoom__ni         , jpiglo ) )
-         CALL event__set_attribut( 'Eq'//cl1, attr( file__name_suffix, '_Eq'  ) )
+         CALL iom_set_domain_attr('Eq'//cl1, zoom_jbegin=iy, zoom_ni=jpiglo)
+         CALL iom_set_file_attr('Eq'//cl1, name_suffix= '_Eq')
       END DO
       ! TAO moorings (attributs: ibegin, jbegin, name_suffix)
@@ -1185,7 +1246,6 @@
                ENDIF
                clname = TRIM(ADJUSTL(clat))//TRIM(ADJUSTL(clon))
-               CALL event__set_attribut( TRIM(clname)//cl1, attr( zoom__ibegin     , ix                ) )
-               CALL event__set_attribut( TRIM(clname)//cl1, attr( zoom__jbegin     , iy                ) )
-               CALL event__set_attribut( TRIM(clname)//cl1, attr( file__name_suffix, '_'//TRIM(clname) ) )      
+               CALL iom_set_domain_attr(TRIM(clname)//cl1, zoom_ibegin= ix, zoom_jbegin= iy)
+               CALL iom_set_file_attr(TRIM(clname)//cl1, name_suffix= '_'//TRIM(clname))
             END DO
          END DO
@@ -1203,5 +1263,13 @@
 #endif
 
-
+   FUNCTION i2str(int)
+   IMPLICIT NONE
+      INTEGER, INTENT(IN) :: int
+      CHARACTER(LEN=255) :: i2str
+
+      WRITE(i2str,*) int
+      
+   END FUNCTION i2str  
+   
    !!======================================================================
 END MODULE iom
