Index: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90
===================================================================
--- branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 4147)
+++ branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 4148)
@@ -464,5 +464,5 @@
             IF( nn_dyn2d(ib_bdy) .gt. 0 .and. ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) ) THEN 
 
-               IF( nn_tra(ib_bdy) .ne. 4 ) THEN ! runoff condition : no ssh reading
+               IF( nn_dyn2d(ib_bdy) .ne. jp_frs .and. nn_tra(ib_bdy) .ne. 4 ) THEN ! runoff condition : no ssh reading
                   jfld = jfld + 1
                   blf_i(jfld) = bn_ssh
@@ -560,6 +560,6 @@
             ! Recalculate field counts
             !-------------------------
-            nb_bdy_fld_sum = 0
             IF( ib_bdy .eq. 1 ) THEN 
+               nb_bdy_fld_sum = 0
                nb_bdy_fld(ib_bdy) = jfld
                nb_bdy_fld_sum     = jfld              
@@ -604,5 +604,5 @@
                ALLOCATE( dta_bdy(ib_bdy)%u2d(ilen0(2)) )
                ALLOCATE( dta_bdy(ib_bdy)%v2d(ilen0(3)) )
-               IF (nn_dyn2d_dta(ib_bdy).eq.1.or.nn_dyn2d_dta(ib_bdy).eq.3) THEN
+               IF ( nn_dyn2d(ib_bdy) .ne. jp_frs .and. (nn_dyn2d_dta(ib_bdy).eq.1.or.nn_dyn2d_dta(ib_bdy).eq.3) ) THEN
                   jfld = jfld + 1
                   dta_bdy(ib_bdy)%ssh => bf(jfld)%fnow(:,1,1)
Index: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim2.F90
===================================================================
--- branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim2.F90	(revision 4147)
+++ branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim2.F90	(revision 4148)
@@ -32,5 +32,5 @@
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: bdyice.F90 2715 2011-03-30 15:58:35Z rblod $
+   !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -76,5 +76,5 @@
       INTEGER,         INTENT(in) ::   ib_bdy  ! BDY set index
       !!
-      INTEGER  ::   jb, jk, jgrd   ! dummy loop indices
+      INTEGER  ::   jb, jgrd   ! dummy loop indices
       INTEGER  ::   ii, ij         ! local scalar
       REAL(wp) ::   zwgt, zwgt1    ! local scalar
@@ -86,5 +86,4 @@
       !
       DO jb = 1, idx%nblen(jgrd)
-         DO jk = 1, jpkm1
             ii    = idx%nbi(jb,jgrd)
             ij    = idx%nbj(jb,jgrd)
@@ -94,5 +93,4 @@
             hicif(ii,ij) = ( hicif(ii,ij) * zwgt1 + dta%hicif(jb) * zwgt ) * tmask(ii,ij,1)     ! Ice depth 
             hsnif(ii,ij) = ( hsnif(ii,ij) * zwgt1 + dta%hsnif(jb) * zwgt ) * tmask(ii,ij,1)     ! Snow depth
-         END DO
       END DO 
       CALL lbc_bdy_lnk( frld, 'T', 1., ib_bdy )                                         ! lateral boundary conditions
Index: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90
===================================================================
--- branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 4147)
+++ branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 4148)
@@ -1049,4 +1049,17 @@
       
       bdytmask(:,:) = tmask(:,:,1)
+      IF( .not. ln_mask_file ) THEN
+         ! If .not. ln_mask_file then we need to derive mask on U and V grid 
+         ! from mask on T grid here.
+         bdyumask(:,:) = 0.e0
+         bdyvmask(:,:) = 0.e0
+         DO ij=1, jpjm1
+            DO ii=1, jpim1
+               bdyumask(ii,ij)=bdytmask(ii,ij)*bdytmask(ii+1, ij )
+               bdyvmask(ii,ij)=bdytmask(ii,ij)*bdytmask(ii  ,ij+1)  
+            END DO
+         END DO
+         CALL lbc_lnk( bdyumask(:,:), 'U', 1. )   ;   CALL lbc_lnk( bdyvmask(:,:), 'V', 1. )      ! Lateral boundary cond.
+      ENDIF
 
       ! bdy masks and bmask are now set to zero on boundary points:
Index: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90
===================================================================
--- branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 4147)
+++ branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 4148)
@@ -350,4 +350,5 @@
                DO jn = 1, nptr
                   tn_jk(:,:,jn) = ptr_tjk( tsn(:,:,:,jp_tem), btmsk(:,:,jn) ) * r1_sjk(:,:,jn)
+                  sn_jk(:,:,jn) = ptr_tjk( tsn(:,:,:,jp_sal), btmsk(:,:,jn) ) * r1_sjk(:,:,jn)
                END DO
             ENDIF
@@ -570,6 +571,6 @@
       !!-------------------------------------------------------------------- 
       !
-      CALL wrk_alloc( jpi      , zphi , zfoo )
-      CALL wrk_alloc( jpi , jpk, z_1 )
+      CALL wrk_alloc( jpj      , zphi , zfoo )
+      CALL wrk_alloc( jpj , jpk, z_1 )
 
       ! define time axis
@@ -885,6 +886,6 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi      , zphi , zfoo )
-      CALL wrk_dealloc( jpi , jpk, z_1 )
+      CALL wrk_dealloc( jpj      , zphi , zfoo )
+      CALL wrk_dealloc( jpj , jpk, z_1 )
       !
   END SUBROUTINE dia_ptr_wri
Index: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4147)
+++ branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4148)
@@ -176,5 +176,5 @@
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE zgr_z  ***
-      !!                   
+      !!                    
       !! ** Purpose :   set the depth of model levels and the resulting 
       !!      vertical scale factors.
@@ -645,4 +645,5 @@
          END DO
       END DO
+      IF( lk_mpp )   CALL mpp_sum( icompt )
       IF( icompt == 0 ) THEN
          IF(lwp) WRITE(numout,*)'     no isolated ocean grid points'
@@ -1105,6 +1106,9 @@
       INTEGER  ::   ios                      ! Local integer output status for namelist read
       REAL(wp) ::   zrmax, ztaper   ! temporary scalars
-      !
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: zenv, ztmp, zmsk, zri, zrj, zhbat
+      REAL(wp) ::   zrfact   ! temporary scalars
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: ztmpi1, ztmpi2, ztmpj1, ztmpj2
+
+      !
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: zenv, zri, zrj, zhbat
 
       NAMELIST/namzgr_sco/ln_s_sh94, ln_s_sf12, ln_sigcrit, rn_sbot_min, rn_sbot_max, rn_hc, rn_rmax,rn_theta, &
@@ -1114,6 +1118,7 @@
       IF( nn_timing == 1 )  CALL timing_start('zgr_sco')
       !
-      CALL wrk_alloc( jpi, jpj,      zenv, ztmp, zmsk, zri, zrj, zhbat                           )
-      !
+      CALL wrk_alloc( jpi, jpj,      ztmpi1, ztmpi2, ztmpj1, ztmpj2         )
+      CALL wrk_alloc( jpi, jpj,      zenv, zri, zrj, zhbat     )
+     !
       REWIND( numnam_ref )              ! Namelist namzgr_sco in reference namelist : Sigma-stretching parameters
       READ  ( numnam_ref, namzgr_sco, IOSTAT = ios, ERR = 901)
@@ -1168,9 +1173,11 @@
       !                                        ! =============================
       ! use r-value to create hybrid coordinates
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zenv(ji,jj) = MAX( bathy(ji,jj), rn_sbot_min )
-         END DO
-      END DO
+!     DO jj = 1, jpj
+!        DO ji = 1, jpi
+!           zenv(ji,jj) = MAX( bathy(ji,jj), 0._wp )
+!        END DO
+!     END DO
+!     CALL lbc_lnk( zenv, 'T', 1._wp )
+      zenv(:,:) = bathy(:,:)
       ! 
       ! Smooth the bathymetry (if required)
@@ -1180,82 +1187,73 @@
       jl = 0
       zrmax = 1._wp
-      !                                                     ! ================ !
-      DO WHILE( jl <= 10000 .AND. zrmax > rn_rmax )         !  Iterative loop  !
-         !                                                  ! ================ !
+      !     
+      ! set scaling factor used in reducing vertical gradients
+      zrfact = ( 1._wp - rn_rmax ) / ( 1._wp + rn_rmax ) 
+      !
+      ! initialise temporary evelope depth arrays
+      ztmpi1(:,:) = zenv(:,:)
+      ztmpi2(:,:) = zenv(:,:)
+      ztmpj1(:,:) = zenv(:,:)
+      ztmpj2(:,:) = zenv(:,:)
+      !
+      ! initialise temporary r-value arrays
+      zri(:,:) = 1._wp
+      zrj(:,:) = 1._wp
+      !                                                            ! ================ !
+      DO WHILE( jl <= 10000 .AND. ( zrmax - rn_rmax ) > 1.e-8_wp ) !  Iterative loop  !
+         !                                                         ! ================ !
          jl = jl + 1
          zrmax = 0._wp
-         zmsk(:,:) = 0._wp
+         ! we set zrmax from previous r-values (zri abd zrj) first
+         ! if set after current r-value calculation (as previously)
+         ! we could exit DO WHILE prematurely before checking r-value
+         ! of current zenv
+         DO jj = 1, nlcj
+            DO ji = 1, nlci
+               zrmax = MAX( zrmax, ABS(zri(ji,jj)), ABS(zrj(ji,jj)) )
+            END DO
+         END DO
+         zri(:,:) = 0._wp
+         zrj(:,:) = 0._wp
          DO jj = 1, nlcj
             DO ji = 1, nlci
                iip1 = MIN( ji+1, nlci )      ! force zri = 0 on last line (ji=ncli+1 to jpi)
                ijp1 = MIN( jj+1, nlcj )      ! force zrj = 0 on last raw  (jj=nclj+1 to jpj)
-               zri(ji,jj) = ABS( zenv(iip1,jj  ) - zenv(ji,jj) ) / ( zenv(iip1,jj  ) + zenv(ji,jj) )
-               zrj(ji,jj) = ABS( zenv(ji  ,ijp1) - zenv(ji,jj) ) / ( zenv(ji  ,ijp1) + zenv(ji,jj) )
-               zrmax = MAX( zrmax, zri(ji,jj), zrj(ji,jj) )
-               IF( zri(ji,jj) > rn_rmax )   zmsk(ji  ,jj  ) = 1._wp
-               IF( zri(ji,jj) > rn_rmax )   zmsk(iip1,jj  ) = 1._wp
-               IF( zrj(ji,jj) > rn_rmax )   zmsk(ji  ,jj  ) = 1._wp
-               IF( zrj(ji,jj) > rn_rmax )   zmsk(ji  ,ijp1) = 1._wp
+               IF( (zenv(ji,jj) > 0._wp) .AND. (zenv(iip1,jj) > 0._wp)) THEN
+                  zri(ji,jj) = ( zenv(iip1,jj  ) - zenv(ji,jj) ) / ( zenv(iip1,jj  ) + zenv(ji,jj) )
+               END IF
+               IF( (zenv(ji,jj) > 0._wp) .AND. (zenv(ji,ijp1) > 0._wp)) THEN
+                  zrj(ji,jj) = ( zenv(ji  ,ijp1) - zenv(ji,jj) ) / ( zenv(ji  ,ijp1) + zenv(ji,jj) )
+               END IF
+               IF( zri(ji,jj) >  rn_rmax )   ztmpi1(ji  ,jj  ) = zenv(iip1,jj  ) * zrfact
+               IF( zri(ji,jj) < -rn_rmax )   ztmpi2(iip1,jj  ) = zenv(ji  ,jj  ) * zrfact 
+               IF( zrj(ji,jj) >  rn_rmax )   ztmpj1(ji  ,jj  ) = zenv(ji  ,ijp1) * zrfact
+               IF( zrj(ji,jj) < -rn_rmax )   ztmpj2(ji  ,ijp1) = zenv(ji  ,jj  ) * zrfact
             END DO
          END DO
          IF( lk_mpp )   CALL mpp_max( zrmax )   ! max over the global domain
-         ! lateral boundary condition on zmsk: keep 1 along closed boundary (use of MAX)
-         ztmp(:,:) = zmsk(:,:)   ;   CALL lbc_lnk( zmsk, 'T', 1._wp )
-         DO jj = 1, nlcj
-            DO ji = 1, nlci
-                zmsk(ji,jj) = MAX( zmsk(ji,jj), ztmp(ji,jj) )
-            END DO
-         END DO
          !
-         IF(lwp)WRITE(numout,*) 'zgr_sco :   iter= ',jl, ' rmax= ', zrmax, ' nb of pt= ', INT( SUM(zmsk(:,:) ) )
+         IF(lwp)WRITE(numout,*) 'zgr_sco :   iter= ',jl, ' rmax= ', zrmax
          !
          DO jj = 1, nlcj
             DO ji = 1, nlci
-               iip1 = MIN( ji+1, nlci )     ! last  line (ji=nlci)
-               ijp1 = MIN( jj+1, nlcj )     ! last  raw  (jj=nlcj)
-               iim1 = MAX( ji-1,  1  )      ! first line (ji=nlci)
-               ijm1 = MAX( jj-1,  1  )      ! first raw  (jj=nlcj)
-               IF( zmsk(ji,jj) == 1._wp ) THEN
-                  ztmp(ji,jj) =   (                                                                                   &
-             &      zenv(iim1,ijp1)*zmsk(iim1,ijp1) + zenv(ji,ijp1)*zmsk(ji,ijp1) + zenv(iip1,ijp1)*zmsk(iip1,ijp1)   &
-             &    + zenv(iim1,jj  )*zmsk(iim1,jj  ) + zenv(ji,jj  )*    2._wp     + zenv(iip1,jj  )*zmsk(iip1,jj  )   &
-             &    + zenv(iim1,ijm1)*zmsk(iim1,ijm1) + zenv(ji,ijm1)*zmsk(ji,ijm1) + zenv(iip1,ijm1)*zmsk(iip1,ijm1)   &
-             &                    ) / (                                                                               &
-             &                      zmsk(iim1,ijp1) +               zmsk(ji,ijp1) +                 zmsk(iip1,ijp1)   &
-             &    +                 zmsk(iim1,jj  ) +                   2._wp     +                 zmsk(iip1,jj  )   &
-             &    +                 zmsk(iim1,ijm1) +               zmsk(ji,ijm1) +                 zmsk(iip1,ijm1)   &
-             &                        )
-               ENDIF
+               zenv(ji,jj) = MAX(zenv(ji,jj), ztmpi1(ji,jj), ztmpi2(ji,jj), ztmpj1(ji,jj), ztmpj2(ji,jj) )
             END DO
          END DO
          !
-         DO jj = 1, nlcj
-            DO ji = 1, nlci
-               IF( zmsk(ji,jj) == 1._wp )   zenv(ji,jj) = MAX( ztmp(ji,jj), bathy(ji,jj) )
-            END DO
-         END DO
-         !
-         ! Apply lateral boundary condition   CAUTION: keep the value when the lbc field is zero
-         ztmp(:,:) = zenv(:,:)   ;   CALL lbc_lnk( zenv, 'T', 1._wp )
-         DO jj = 1, nlcj
-            DO ji = 1, nlci
-               IF( zenv(ji,jj) == 0._wp )   zenv(ji,jj) = ztmp(ji,jj)
-            END DO
-         END DO
+         CALL lbc_lnk( zenv, 'T', 1._wp )
          !                                                  ! ================ !
       END DO                                                !     End loop     !
       !                                                     ! ================ !
       !
-      ! Fill ghost rows with appropriate values to avoid undefined e3 values with some mpp decompositions
-      DO ji = nlci+1, jpi 
-         zenv(ji,1:nlcj) = zenv(nlci,1:nlcj)
-      END DO
-      !
-      DO jj = nlcj+1, jpj
-         zenv(:,jj) = zenv(:,nlcj)
-      END DO
+!     DO jj = 1, jpj
+!        DO ji = 1, jpi
+!           zenv(ji,jj) = MAX( zenv(ji,jj), rn_sbot_min ) ! set all points to avoid undefined scale values
+!        END DO
+!     END DO
       !
       ! Envelope bathymetry saved in hbatt
       hbatt(:,:) = zenv(:,:) 
+
       IF( MINVAL( gphit(:,:) ) * MAXVAL( gphit(:,:) ) <= 0._wp ) THEN
          CALL ctl_warn( ' s-coordinates are tapered in vicinity of the Equator' )
@@ -1503,6 +1501,5 @@
       END DO
       !
-      CALL wrk_dealloc( jpi, jpj,      zenv, ztmp, zmsk, zri, zrj, zhbat                           )
-      !
+      CALL wrk_dealloc( jpi, jpj,      zenv, ztmpi1, ztmpi2, ztmpj1, ztmpj2, zri, zrj, zhbat                           )      !
       IF( nn_timing == 1 )  CALL timing_stop('zgr_sco')
       !
Index: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 4147)
+++ branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 4148)
@@ -36,4 +36,5 @@
    USE xios
 # endif
+   USE ioipsl, ONLY :  ju2ymds    ! for calendar
 
    IMPLICIT NONE
@@ -52,6 +53,6 @@
    PRIVATE iom_p1d, iom_p2d, iom_p3d
 #if defined key_iomput
-   PRIVATE iom_set_domain_attr, iom_set_axis_attr, iom_set_field_attr, iom_set_file_attr, iom_set_grid_attr
-   PRIVATE set_grid, set_scalar, set_xmlatt, set_mooring
+   PRIVATE iom_set_domain_attr, iom_set_axis_attr, iom_set_field_attr, iom_set_file_attr, iom_get_file_attr, iom_set_grid_attr
+   PRIVATE set_grid, set_scalar, set_xmlatt, set_mooring, iom_update_file_name, iom_sdate
 # endif
 
@@ -130,11 +131,11 @@
 
       ! end file definition
-       dtime%second=rdt
-       CALL xios_set_timestep(dtime)
-       CALL xios_close_context_definition()
-
-       CALL xios_update_calendar(0)
+      dtime%second = rdt
+      CALL xios_set_timestep(dtime)
+      CALL xios_close_context_definition()
+      
+      CALL xios_update_calendar(0)
 #endif
-
+      
    END SUBROUTINE iom_init
 
@@ -174,9 +175,9 @@
       LOGICAL         , INTENT(in   ), OPTIONAL ::   ldiof    ! Interp On the Fly, needed for AGRIF (default = .FALSE.)
 
-      CHARACTER(LEN=100)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
-      CHARACTER(LEN=100)    ::   cltmpn    ! tempory name to store clname (in writting mode)
+      CHARACTER(LEN=256)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
+      CHARACTER(LEN=256)    ::   cltmpn    ! tempory name to store clname (in writting mode)
       CHARACTER(LEN=10)     ::   clsuffix  ! ".nc" or ".dimg"
       CHARACTER(LEN=15)     ::   clcpu     ! the cpu number (max jpmax_digits digits)
-      CHARACTER(LEN=100)    ::   clinfo    ! info character
+      CHARACTER(LEN=256)    ::   clinfo    ! info character
       LOGICAL               ::   llok      ! check the existence 
       LOGICAL               ::   llwrt     ! local definition of ldwrt
@@ -561,6 +562,6 @@
       REAL(wp)                       ::   zscf, zofs  ! sacle_factor and add_offset
       INTEGER                        ::   itmp        ! temporary integer
-      CHARACTER(LEN=100)             ::   clinfo      ! info character
-      CHARACTER(LEN=100)             ::   clname      ! file name
+      CHARACTER(LEN=256)             ::   clinfo      ! info character
+      CHARACTER(LEN=256)             ::   clname      ! file name
       CHARACTER(LEN=1)               ::   clrankpv, cldmspc      ! 
       !---------------------------------------------------------------------
@@ -1010,10 +1011,9 @@
    !!----------------------------------------------------------------------
 
-
 #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,   &
+   SUBROUTINE iom_set_domain_attr( cdid, 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, mask )
-      CHARACTER(LEN=*)                 , INTENT(in) ::   cdname
+      CHARACTER(LEN=*)                 , INTENT(in) ::   cdid
       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
@@ -1022,50 +1022,81 @@
       LOGICAL, DIMENSION(:,:), OPTIONAL, INTENT(in) ::   mask
 
-      IF ( xios_is_valid_domain     (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,                         &
+      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 ,   &
+            &    zoom_ibegin=zoom_ibegin, zoom_jbegin=zoom_jbegin, zoom_ni=zoom_ni, zoom_nj=zoom_nj,                       &
             &    lonvalue=lonvalue, latvalue=latvalue,mask=mask )
       ENDIF
 
-      IF ( xios_is_valid_domaingroup(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,                         &
+      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 ,   &
+            &    zoom_ibegin=zoom_ibegin, zoom_jbegin=zoom_jbegin, zoom_ni=zoom_ni, zoom_nj=zoom_nj,                       &
             &    lonvalue=lonvalue, latvalue=latvalue,mask=mask )
       ENDIF
+      CALL xios_solve_inheritance()
 
    END SUBROUTINE iom_set_domain_attr
 
 
-   SUBROUTINE iom_set_axis_attr( cdname, paxis )
-      CHARACTER(LEN=*)      , INTENT(in) ::   cdname
+   SUBROUTINE iom_set_axis_attr( cdid, paxis )
+      CHARACTER(LEN=*)      , INTENT(in) ::   cdid
       REAL(wp), DIMENSION(:), INTENT(in) ::   paxis
-      IF ( xios_is_valid_axis     (cdname) )   CALL xios_set_axis_attr     ( cdname, size=size(paxis),value=paxis )
-      IF ( xios_is_valid_axisgroup(cdname) )   CALL xios_set_axisgroup_attr( cdname, size=size(paxis),value=paxis )
+      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 )
+      CALL xios_solve_inheritance()
    END SUBROUTINE iom_set_axis_attr
 
 
-   SUBROUTINE iom_set_field_attr( cdname, freq_op)
-      CHARACTER(LEN=*)          , INTENT(in) ::   cdname
+   SUBROUTINE iom_set_field_attr( cdid, freq_op, freq_offset )
+      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
       CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   freq_op
-      IF ( xios_is_valid_field     (cdname) )   CALL xios_set_field_attr     ( cdname, freq_op=freq_op )
-      IF ( xios_is_valid_fieldgroup(cdname) )   CALL xios_set_fieldgroup_attr( cdname, freq_op=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 )
+      CALL xios_solve_inheritance()
    END SUBROUTINE iom_set_field_attr
 
 
-   SUBROUTINE iom_set_file_attr( cdname, name, name_suffix )
-      CHARACTER(LEN=*)          , INTENT(in) ::   cdname
+   SUBROUTINE iom_set_file_attr( cdid, name, name_suffix )
+      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
       CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   name, name_suffix
-      IF ( xios_is_valid_file     (cdname) )   CALL xios_set_file_attr     ( cdname, name=name, name_suffix=name_suffix )
-      IF ( xios_is_valid_filegroup(cdname) )   CALL xios_set_filegroup_attr( cdname, name=name, name_suffix=name_suffix )
+      IF ( xios_is_valid_file     (cdid) )   CALL xios_set_file_attr     ( cdid, name=name, name_suffix=name_suffix )
+      IF ( xios_is_valid_filegroup(cdid) )   CALL xios_set_filegroup_attr( cdid, name=name, name_suffix=name_suffix )
+      CALL xios_solve_inheritance()
    END SUBROUTINE iom_set_file_attr
 
 
-   SUBROUTINE iom_set_grid_attr( cdname, mask )
-      CHARACTER(LEN=*)                   , INTENT(in) ::   cdname
+   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
+      LOGICAL                                 ::   llexist1,llexist2,llexist3
+      !---------------------------------------------------------------------
+      IF( PRESENT( name        ) )   name = ''          ! default values
+      IF( PRESENT( name_suffix ) )   name_suffix = ''
+      IF( PRESENT( output_freq ) )   output_freq = ''
+      IF ( xios_is_valid_file     (cdid) ) THEN
+         CALL xios_solve_inheritance()
+         CALL xios_is_defined_file_attr     ( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3)
+         IF(llexist1)   CALL xios_get_file_attr     ( cdid, name = name )
+         IF(llexist2)   CALL xios_get_file_attr     ( cdid, name_suffix = name_suffix )
+         IF(llexist3)   CALL xios_get_file_attr     ( cdid, output_freq = output_freq )
+      ENDIF
+      IF ( xios_is_valid_filegroup(cdid) ) THEN
+         CALL xios_solve_inheritance()
+         CALL xios_is_defined_filegroup_attr( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3)
+         IF(llexist1)   CALL xios_get_filegroup_attr( cdid, name = name )
+         IF(llexist2)   CALL xios_get_filegroup_attr( cdid, name_suffix = name_suffix )
+         IF(llexist3)   CALL xios_get_filegroup_attr( cdid, output_freq = output_freq )
+      ENDIF
+   END SUBROUTINE iom_get_file_attr
+
+
+   SUBROUTINE iom_set_grid_attr( cdid, mask )
+      CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
       LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(in) ::   mask
-      IF ( xios_is_valid_grid     (cdname) )   CALL xios_set_grid_attr     ( cdname, mask=mask )
-      IF ( xios_is_valid_gridgroup(cdname) )   CALL xios_set_gridgroup_attr( cdname, mask=mask )
+      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 )
+      CALL xios_solve_inheritance()
    END SUBROUTINE iom_set_grid_attr
 
@@ -1073,5 +1104,5 @@
    SUBROUTINE set_grid( cdgrd, plon, plat )
       !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE   ***
+      !!                     ***  ROUTINE set_grid  ***
       !!
       !! ** Purpose :   define horizontal grids
@@ -1101,6 +1132,6 @@
          END SELECT
          !
-         CALL iom_set_domain_attr( "grid_"//cdgrd       , mask = zmask(:,:,1) /= 0. )
-         CALL iom_set_grid_attr  ( "grid_"//cdgrd//"_3D", mask = zmask(:,:,:) /= 0. )
+         CALL iom_set_domain_attr( "grid_"//cdgrd       , mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,1),(/ni,nj    /)) /= 0. )
+         CALL iom_set_grid_attr  ( "grid_"//cdgrd//"_3D", mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,:),(/ni,nj,jpk/)) /= 0. )
       ENDIF
       
@@ -1110,5 +1141,5 @@
    SUBROUTINE set_scalar
       !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE   ***
+      !!                     ***  ROUTINE set_scalar  ***
       !!
       !! ** Purpose :   define fake grids for scalar point
@@ -1126,19 +1157,14 @@
    SUBROUTINE set_xmlatt
       !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE   ***
+      !!                     ***  ROUTINE set_xmlatt  ***
       !!
       !! ** Purpose :   automatic definitions of some of the xml attributs...
       !!
       !!----------------------------------------------------------------------
-      CHARACTER(len=6),DIMENSION( 8) ::   clsuff                   ! suffix name
       CHARACTER(len=1),DIMENSION( 3) ::   clgrd                    ! suffix name
-      CHARACTER(len=50)              ::   clname                   ! file name
+      CHARACTER(len=256)             ::   clsuff                   ! suffix name
       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
-      INTEGER                        ::   iyymo                    ! number of months in 1 year
-      INTEGER                        ::   jg, jh, jd, jm, jy       ! loop counters
+      INTEGER                        ::   ji, jg                   ! loop counters
       INTEGER                        ::   ix, iy                   ! i-,j- index
       REAL(wp)        ,DIMENSION(11) ::   zlontao                  ! longitudes of tao    moorings
@@ -1150,39 +1176,18 @@
       !!----------------------------------------------------------------------
       ! 
-      idt   = NINT( rdttra(1)     )
-      iddss = NINT( rday          )                                         ! number of seconds in 1 day
-      ihhss = NINT( rmmss * rhhmm )                                         ! number of seconds in 1 hour
-      iyymo = NINT( raamo         )                                         ! number of months in 1 year
-
       ! frequency of the call of iom_put (attribut: freq_op)
-      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')
-      CALL iom_set_field_attr('ptrc_T', freq_op=TRIM(i2str(idt* nn_dttrc))//'s')
-      CALL iom_set_field_attr('diad_T', freq_op=TRIM(i2str(idt* nn_dttrc))//'s')
+      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_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')
        
       ! output file names (attribut: name)
-      clsuff(:) = (/ 'grid_T', 'grid_U', 'grid_V', 'grid_W', 'icemod', 'ptrc_T', 'diad_T', 'scalar' /)      
-      DO jg = 1, SIZE(clsuff)                                                                  ! grid type
-         DO jh = 1, 24                                                                         ! 1-24 hours
-            WRITE(cl2,'(i2)') jh 
-            CALL dia_nam( clname, jh * ihhss, clsuff(jg), ldfsec = .TRUE. )
-            CALL iom_set_file_attr(TRIM(ADJUSTL(cl2))//'h_'//clsuff(jg), name=TRIM(clname))
-         END DO
-         DO jd = 1, 30                                                                         ! 1-30 days
-            WRITE(cl1,'(i1)') jd 
-            CALL dia_nam( clname, jd * iddss, clsuff(jg), ldfsec = .TRUE. )
-            CALL iom_set_file_attr(cl1//'d_'//clsuff(jg), name=TRIM(clname))
-         END DO
-         DO jm = 1, 11                                                                         ! 1-11 months
-            WRITE(cl1,'(i1)') jm 
-            CALL dia_nam( clname, -jm, clsuff(jg) )
-            CALL iom_set_file_attr(cl1//'m_'//clsuff(jg), name=TRIM(clname))
-         END DO
-         DO jy = 1, 50                                                                         ! 1-50 years  
-            WRITE(cl2,'(i2)') jy 
-            CALL dia_nam( clname, -jy * iyymo, clsuff(jg) )
-            CALL iom_set_file_attr(TRIM(ADJUSTL(cl2))//'y_'//clsuff(jg), name=TRIM(clname))
-         END DO
+      DO ji = 1, 9
+         WRITE(cl1,'(i1)') ji 
+         CALL iom_update_file_name('file'//cl1)
+      END DO
+      DO ji = 1, 99
+         WRITE(cl2,'(i2.2)') ji 
+         CALL iom_update_file_name('file'//cl2)
       END DO
 
@@ -1193,6 +1198,8 @@
          ! Equatorial section (attributs: jbegin, ni, name_suffix)
          CALL dom_ngb( 0., 0., ix, iy, cl1 )
-         CALL iom_set_domain_attr('Eq'//cl1, zoom_jbegin=iy, zoom_ni=jpiglo)
-         CALL iom_set_file_attr('Eq'//cl1, name_suffix= '_Eq')
+         CALL iom_set_domain_attr ('Eq'//cl1, zoom_jbegin=iy, zoom_ni=jpiglo)
+         CALL iom_get_file_attr   ('Eq'//cl1, name_suffix = clsuff             )
+         CALL iom_set_file_attr   ('Eq'//cl1, name_suffix = TRIM(clsuff)//'_Eq')
+         CALL iom_update_file_name('Eq'//cl1)
       END DO
       ! TAO moorings (attributs: ibegin, jbegin, name_suffix)
@@ -1214,5 +1221,5 @@
    SUBROUTINE set_mooring( plon, plat)
       !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE   ***
+      !!                     ***  ROUTINE set_mooring  ***
       !!
       !! ** Purpose :   automatic definitions of moorings xml attributs...
@@ -1223,5 +1230,6 @@
 !!$      CHARACTER(len=1),DIMENSION(4) ::   clgrd = (/ 'T', 'U', 'V', 'W' /)   ! suffix name
       CHARACTER(len=1),DIMENSION(1) ::   clgrd = (/ 'T' /)        ! suffix name
-      CHARACTER(len=50)             ::   clname                   ! file name
+      CHARACTER(len=256)            ::   clname                   ! file name
+      CHARACTER(len=256)            ::   clsuff                   ! suffix name
       CHARACTER(len=1)              ::   cl1                      ! 1 character
       CHARACTER(len=6)              ::   clon,clat                ! name of longitude, latitude
@@ -1269,6 +1277,8 @@
                ENDIF
                clname = TRIM(ADJUSTL(clat))//TRIM(ADJUSTL(clon))
-               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))
+               CALL iom_set_domain_attr (TRIM(clname)//cl1, zoom_ibegin= ix, zoom_jbegin= iy)
+               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))
+               CALL iom_update_file_name(TRIM(clname)//cl1)
             END DO
          END DO
@@ -1277,4 +1287,139 @@
    END SUBROUTINE set_mooring
 
+   
+   SUBROUTINE iom_update_file_name( cdid )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE iom_update_file_name  ***
+      !!
+      !! ** Purpose :   
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
+      !
+      CHARACTER(LEN=256) ::   clname
+      CHARACTER(LEN=20)  ::   clfreq
+      CHARACTER(LEN=20)  ::   cldate
+      INTEGER            ::   idx
+      INTEGER            ::   jn
+      INTEGER            ::   itrlen
+      INTEGER            ::   iyear, imonth, iday, isec
+      REAL(wp)           ::   zsec
+      LOGICAL            ::   llexist
+      !!----------------------------------------------------------------------
+
+      DO jn = 1,2
+
+         IF( jn == 1 )   CALL iom_get_file_attr( cdid, name        = clname, output_freq = clfreq )
+         IF( jn == 2 )   CALL iom_get_file_attr( cdid, name_suffix = clname )
+
+         IF ( TRIM(clname) /= '' ) THEN 
+
+            idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@')
+            DO WHILE ( idx /= 0 ) 
+               clname = clname(1:idx-1)//TRIM(cexper)//clname(idx+9:LEN_TRIM(clname))
+               idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@')
+            END DO
+
+            idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
+            DO WHILE ( idx /= 0 ) 
+               IF ( TRIM(clfreq) /= '' ) THEN
+                  itrlen = LEN_TRIM(clfreq)
+                  IF ( clfreq(itrlen-1:itrlen) == 'mo' ) clfreq = clfreq(1:itrlen-1)
+                  clname = clname(1:idx-1)//TRIM(clfreq)//clname(idx+6:LEN_TRIM(clname))
+               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
+               idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
+            END DO
+
+            idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
+            DO WHILE ( idx /= 0 ) 
+               cldate = iom_sdate( fjulday - rdttra(1) / rday )
+               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+11:LEN_TRIM(clname))
+               idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
+            END DO
+
+            idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
+            DO WHILE ( idx /= 0 ) 
+               cldate = iom_sdate( fjulday - rdttra(1) / rday, ldfull = .TRUE. )
+               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+15:LEN_TRIM(clname))
+               idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
+            END DO
+
+            idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
+            DO WHILE ( idx /= 0 ) 
+               cldate = iom_sdate( fjulday + rdttra(1) / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE. )
+               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+9:LEN_TRIM(clname))
+               idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
+            END DO
+
+            idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
+            DO WHILE ( idx /= 0 ) 
+               cldate = iom_sdate( fjulday + rdttra(1) / rday * REAL( nitend - nit000, wp ), ld24 = .TRUE., ldfull = .TRUE. )
+               clname = clname(1:idx-1)//TRIM(cldate)//clname(idx+13:LEN_TRIM(clname))
+               idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
+            END DO
+
+            IF( jn == 1 )   CALL iom_set_file_attr( cdid, name        = clname )
+            IF( jn == 2 )   CALL iom_set_file_attr( cdid, name_suffix = clname )
+
+         ENDIF
+
+      END DO
+
+   END SUBROUTINE iom_update_file_name
+
+
+   FUNCTION iom_sdate( pjday, ld24, ldfull )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE iom_sdate  ***
+      !!
+      !! ** Purpose :   send back the date corresponding to the given julian day
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in   )           ::   pjday         ! julian day
+      LOGICAL , INTENT(in   ), OPTIONAL ::   ld24          ! true to force 24:00 instead of 00:00
+      LOGICAL , INTENT(in   ), OPTIONAL ::   ldfull        ! true to get the compleate date: yyyymmdd_hh:mm:ss
+      !
+      CHARACTER(LEN=20) ::   iom_sdate
+      CHARACTER(LEN=50) ::   clfmt                         !  format used to write the date 
+      INTEGER           ::   iyear, imonth, iday, ihour, iminute, isec
+      REAL(wp)          ::   zsec
+      LOGICAL           ::   ll24, llfull
+      !
+      IF( PRESENT(ld24) ) THEN   ;   ll24 = ld24
+      ELSE                       ;   ll24 = .FALSE.
+      ENDIF
+
+      IF( PRESENT(ldfull) ) THEN   ;   llfull = ldfull
+      ELSE                         ;   llfull = .FALSE.
+      ENDIF
+
+      CALL ju2ymds( pjday, iyear, imonth, iday, zsec )
+      isec = NINT(zsec)
+
+      IF ( ll24 .AND. isec == 0 ) THEN   ! 00:00 of the next day -> move to 24:00 of the current day
+         CALL ju2ymds( pjday - 1., iyear, imonth, iday, zsec )
+         isec = 86400
+      ENDIF
+
+      IF( iyear < 10000 ) THEN   ;   clfmt = "i4.4,2i2.2"                ! format used to write the date 
+      ELSE                       ;   WRITE(clfmt, "('i',i1,',2i2.2')") INT(LOG10(REAL(iyear,wp))) + 1
+      ENDIF
+      
+      IF( llfull ) THEN 
+         clfmt = TRIM(clfmt)//",'_',i2.2,':',i2.2,':',i2.2"
+         ihour   = isec / 3600
+         isec    = MOD(isec, 3600)
+         iminute = isec / 60
+         isec    = MOD(isec, 60)
+         WRITE(iom_sdate, '('//TRIM(clfmt)//')') iyear, imonth, iday, ihour, iminute, isec    ! date of the end of run
+      ELSE
+         WRITE(iom_sdate, '('//TRIM(clfmt)//')') iyear, imonth, iday                          ! date of the end of run
+      ENDIF
+
+   END FUNCTION iom_sdate
+
 #else
 
@@ -1285,13 +1430,4 @@
 
 #endif
-
-   FUNCTION i2str(int)
-   IMPLICIT NONE
-      INTEGER, INTENT(IN) :: int
-      CHARACTER(LEN=255) :: i2str
-
-      WRITE(i2str,*) int
-      
-   END FUNCTION i2str  
    
    !!======================================================================
Index: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90
===================================================================
--- branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 4147)
+++ branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 4148)
@@ -163,16 +163,16 @@
 
    ! Arrays used in mpp_lbc_north_3d()
-   REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE, SAVE   ::   ztab, znorthloc
-   REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE, SAVE   ::   znorthgloio
-   REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE, SAVE   ::   zfoldwk      ! Workspace for message transfers avoiding mpi_allgather
+   REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE, SAVE   ::   tab_3d, xnorthloc
+   REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE, SAVE   ::   xnorthgloio
+   REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE, SAVE   ::   foldwk      ! Workspace for message transfers avoiding mpi_allgather
 
    ! Arrays used in mpp_lbc_north_2d()
-   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE, SAVE    ::   ztab_2d, znorthloc_2d
-   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE, SAVE    ::   znorthgloio_2d
-   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE, SAVE    ::   zfoldwk_2d    ! Workspace for message transfers avoiding mpi_allgather
+   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE, SAVE    ::   tab_2d, xnorthloc_2d
+   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE, SAVE    ::   xnorthgloio_2d
+   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE, SAVE    ::   foldwk_2d    ! Workspace for message transfers avoiding mpi_allgather
 
    ! Arrays used in mpp_lbc_north_e()
-   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE, SAVE    ::   ztab_e, znorthloc_e
-   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE, SAVE    ::   znorthgloio_e
+   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE, SAVE    ::   tab_e, xnorthloc_e
+   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE, SAVE    ::   xnorthgloio_e
 
    ! North fold arrays used to minimise the use of allgather operations. Set in nemo_northcomms (nemogcm) so need to be public
@@ -208,11 +208,11 @@
          &      t2p1(jpi,jprecj    ,2)   , t2p2(jpi,jprecj    ,2)   ,                                            &
          !
-         &      ztab(jpiglo,4,jpk) , znorthloc(jpi,4,jpk) , znorthgloio(jpi,4,jpk,jpni) ,                        &
-         &      zfoldwk(jpi,4,jpk) ,                                                                             &
-         !
-         &      ztab_2d(jpiglo,4)  , znorthloc_2d(jpi,4)  , znorthgloio_2d(jpi,4,jpni)  ,                        &
-         &      zfoldwk_2d(jpi,4)  ,                                                                             &
-         !
-         &      ztab_e(jpiglo,4+2*jpr2dj) , znorthloc_e(jpi,4+2*jpr2dj) , znorthgloio_e(jpi,4+2*jpr2dj,jpni) ,   &
+         &      tab_3d(jpiglo,4,jpk) , xnorthloc(jpi,4,jpk) , xnorthgloio(jpi,4,jpk,jpni) ,                        &
+         &      foldwk(jpi,4,jpk) ,                                                                             &
+         !
+         &      tab_2d(jpiglo,4)  , xnorthloc_2d(jpi,4)  , xnorthgloio_2d(jpi,4,jpni)  ,                        &
+         &      foldwk_2d(jpi,4)  ,                                                                             &
+         !
+         &      tab_e(jpiglo,4+2*jpr2dj) , xnorthloc_e(jpi,4+2*jpr2dj) , xnorthgloio_e(jpi,4+2*jpr2dj,jpni) ,   &
          !
          &      STAT=lib_mpp_alloc )
@@ -2608,12 +2608,12 @@
       ityp = -1
       ijpjm1 = 3
-      ztab(:,:,:) = 0.e0
-      !
-      DO jj = nlcj - ijpj +1, nlcj          ! put in znorthloc the last 4 jlines of pt3d
+      tab_3d(:,:,:) = 0.e0
+      !
+      DO jj = nlcj - ijpj +1, nlcj          ! put in xnorthloc the last 4 jlines of pt3d
          ij = jj - nlcj + ijpj
-         znorthloc(:,ij,:) = pt3d(:,jj,:)
+         xnorthloc(:,ij,:) = pt3d(:,jj,:)
       END DO
       !
-      !                                     ! Build in procs of ncomm_north the znorthgloio
+      !                                     ! Build in procs of ncomm_north the xnorthgloio
       itaille = jpi * jpk * ijpj
       IF ( l_north_nogather ) THEN
@@ -2625,5 +2625,5 @@
             ij = jj - nlcj + ijpj
             DO ji = 1, nlci
-               ztab(ji+nimpp-1,ij,:) = pt3d(ji,jj,:)
+               tab_3d(ji+nimpp-1,ij,:) = pt3d(ji,jj,:)
             END DO
          END DO
@@ -2650,8 +2650,8 @@
 
             DO jr = 1,nsndto(ityp)
-               CALL mppsend(5, znorthloc, itaille, isendto(jr,ityp), ml_req_nf(jr) )
+               CALL mppsend(5, xnorthloc, itaille, isendto(jr,ityp), ml_req_nf(jr) )
             END DO
             DO jr = 1,nsndto(ityp)
-               CALL mpprecv(5, zfoldwk, itaille, isendto(jr,ityp))
+               CALL mpprecv(5, foldwk, itaille, isendto(jr,ityp))
                iproc = isendto(jr,ityp) + 1
                ildi = nldit (iproc)
@@ -2660,5 +2660,5 @@
                DO jj = 1, ijpj
                   DO ji = ildi, ilei
-                     ztab(ji+iilb-1,jj,:) = zfoldwk(ji,jj,:)
+                     tab_3d(ji+iilb-1,jj,:) = foldwk(ji,jj,:)
                   END DO
                END DO
@@ -2675,6 +2675,6 @@
 
       IF ( ityp .lt. 0 ) THEN
-         CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,                &
-            &                znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+         CALL MPI_ALLGATHER( xnorthloc  , itaille, MPI_DOUBLE_PRECISION,                &
+            &                xnorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
          !
          DO jr = 1, ndim_rank_north         ! recover the global north array
@@ -2685,5 +2685,5 @@
             DO jj = 1, ijpj
                DO ji = ildi, ilei
-                  ztab(ji+iilb-1,jj,:) = znorthgloio(ji,jj,:,jr)
+                  tab_3d(ji+iilb-1,jj,:) = xnorthgloio(ji,jj,:,jr)
                END DO
             END DO
@@ -2691,5 +2691,5 @@
       ENDIF
       !
-      ! The ztab array has been either:
+      ! The tab_3d array has been either:
       !  a. Fully populated by the mpi_allgather operation or
       !  b. Had the active points for this domain and northern neighbours populated
@@ -2698,10 +2698,10 @@
       ! this domain will be identical.
       !
-      CALL lbc_nfd( ztab, cd_type, psgn )   ! North fold boundary condition
+      CALL lbc_nfd( tab_3d, cd_type, psgn )   ! North fold boundary condition
       !
       DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
          ij = jj - nlcj + ijpj
          DO ji= 1, nlci
-            pt3d(ji,jj,:) = ztab(ji+nimpp-1,ij,:)
+            pt3d(ji,jj,:) = tab_3d(ji+nimpp-1,ij,:)
          END DO
       END DO
@@ -2740,12 +2740,12 @@
       ityp = -1
       ijpjm1 = 3
-      ztab_2d(:,:) = 0.e0
-      !
-      DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc_2d the last 4 jlines of pt2d
+      tab_2d(:,:) = 0.e0
+      !
+      DO jj = nlcj-ijpj+1, nlcj             ! put in xnorthloc_2d the last 4 jlines of pt2d
          ij = jj - nlcj + ijpj
-         znorthloc_2d(:,ij) = pt2d(:,jj)
+         xnorthloc_2d(:,ij) = pt2d(:,jj)
       END DO
 
-      !                                     ! Build in procs of ncomm_north the znorthgloio_2d
+      !                                     ! Build in procs of ncomm_north the xnorthgloio_2d
       itaille = jpi * ijpj
       IF ( l_north_nogather ) THEN
@@ -2757,5 +2757,5 @@
             ij = jj - nlcj + ijpj
             DO ji = 1, nlci
-               ztab_2d(ji+nimpp-1,ij) = pt2d(ji,jj)
+               tab_2d(ji+nimpp-1,ij) = pt2d(ji,jj)
             END DO
          END DO
@@ -2783,8 +2783,8 @@
 
             DO jr = 1,nsndto(ityp)
-               CALL mppsend(5, znorthloc_2d, itaille, isendto(jr,ityp), ml_req_nf(jr) )
+               CALL mppsend(5, xnorthloc_2d, itaille, isendto(jr,ityp), ml_req_nf(jr) )
             END DO
             DO jr = 1,nsndto(ityp)
-               CALL mpprecv(5, zfoldwk_2d, itaille, isendto(jr,ityp))
+               CALL mpprecv(5, foldwk_2d, itaille, isendto(jr,ityp))
                iproc = isendto(jr,ityp) + 1
                ildi = nldit (iproc)
@@ -2793,5 +2793,5 @@
                DO jj = 1, ijpj
                   DO ji = ildi, ilei
-                     ztab_2d(ji+iilb-1,jj) = zfoldwk_2d(ji,jj)
+                     tab_2d(ji+iilb-1,jj) = foldwk_2d(ji,jj)
                   END DO
                END DO
@@ -2808,6 +2808,6 @@
 
       IF ( ityp .lt. 0 ) THEN
-         CALL MPI_ALLGATHER( znorthloc_2d  , itaille, MPI_DOUBLE_PRECISION,        &
-            &                znorthgloio_2d, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+         CALL MPI_ALLGATHER( xnorthloc_2d  , itaille, MPI_DOUBLE_PRECISION,        &
+            &                xnorthgloio_2d, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
          !
          DO jr = 1, ndim_rank_north            ! recover the global north array
@@ -2818,5 +2818,5 @@
             DO jj = 1, ijpj
                DO ji = ildi, ilei
-                  ztab_2d(ji+iilb-1,jj) = znorthgloio_2d(ji,jj,jr)
+                  tab_2d(ji+iilb-1,jj) = xnorthgloio_2d(ji,jj,jr)
                END DO
             END DO
@@ -2824,5 +2824,5 @@
       ENDIF
       !
-      ! The ztab array has been either:
+      ! The tab array has been either:
       !  a. Fully populated by the mpi_allgather operation or
       !  b. Had the active points for this domain and northern neighbours populated
@@ -2831,5 +2831,5 @@
       ! this domain will be identical.
       !
-      CALL lbc_nfd( ztab_2d, cd_type, psgn )   ! North fold boundary condition
+      CALL lbc_nfd( tab_2d, cd_type, psgn )   ! North fold boundary condition
       !
       !
@@ -2837,5 +2837,5 @@
          ij = jj - nlcj + ijpj
          DO ji = 1, nlci
-            pt2d(ji,jj) = ztab_2d(ji+nimpp-1,ij)
+            pt2d(ji,jj) = tab_2d(ji+nimpp-1,ij)
          END DO
       END DO
@@ -2870,18 +2870,18 @@
       !
       ijpj=4
-      ztab_e(:,:) = 0.e0
+      tab_e(:,:) = 0.e0
 
       ij=0
-      ! put in znorthloc_e the last 4 jlines of pt2d
+      ! put in xnorthloc_e the last 4 jlines of pt2d
       DO jj = nlcj - ijpj + 1 - jpr2dj, nlcj +jpr2dj
          ij = ij + 1
          DO ji = 1, jpi
-            znorthloc_e(ji,ij)=pt2d(ji,jj)
+            xnorthloc_e(ji,ij)=pt2d(ji,jj)
          END DO
       END DO
       !
       itaille = jpi * ( ijpj + 2 * jpr2dj )
-      CALL MPI_ALLGATHER( znorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
-         &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+      CALL MPI_ALLGATHER( xnorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
+         &                xnorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
       !
       DO jr = 1, ndim_rank_north            ! recover the global north array
@@ -2892,5 +2892,5 @@
          DO jj = 1, ijpj+2*jpr2dj
             DO ji = ildi, ilei
-               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
+               tab_e(ji+iilb-1,jj) = xnorthgloio_e(ji,jj,jr)
             END DO
          END DO
@@ -2900,5 +2900,5 @@
       ! 2. North-Fold boundary conditions
       ! ----------------------------------
-      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = jpr2dj )
+      CALL lbc_nfd( tab_e(:,:), cd_type, psgn, pr2dj = jpr2dj )
 
       ij = jpr2dj
@@ -2907,5 +2907,5 @@
       ij  = ij +1
          DO ji= 1, nlci
-            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
+            pt2d(ji,jj) = tab_e(ji+nimpp-1,ij)
          END DO
       END DO
Index: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90
===================================================================
--- branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 4147)
+++ branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 4148)
@@ -71,4 +71,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx    , sfx_b    !: salt flux                                    [PSU/m2/s]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   emp_tot           !: total E-P over ocean and ice                 [Kg/m2/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fmmflx            !: freshwater budget: freezing/melting          [Kg/m2/s]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rnf    , rnf_b    !: river runoff   [Kg/m2/s]  
    !!
@@ -116,5 +117,5 @@
          &      qsr_tot(jpi,jpj) , qsr  (jpi,jpj) ,                        &
          &      emp    (jpi,jpj) , emp_b(jpi,jpj) ,                        &
-         &      sfx    (jpi,jpj) , sfx_b(jpi,jpj) , emp_tot(jpi,jpj) , STAT=ierr(2) )
+         &      sfx    (jpi,jpj) , sfx_b(jpi,jpj) , emp_tot(jpi,jpj), fmmflx(jpi,jpj), STAT=ierr(2) )
          !
       ALLOCATE( rnf  (jpi,jpj) , sbc_tsc  (jpi,jpj,jpts) , qsr_hc  (jpi,jpj,jpk) ,     &
Index: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90
===================================================================
--- branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 4147)
+++ branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 4148)
@@ -373,5 +373,5 @@
       !
       IF( TRIM( sn_rcv_tau%cldes ) /= 'oce and ice' ) THEN        ! 'oce and ice' case ocean stress on ocean mesh used
-         srcv(jpr_itx1:jpr_itz2)%laction = .FALSE.    ! ice components not received
+         srcv(jpr_itz1:jpr_itz2)%laction = .FALSE.    ! ice components not received (itx1 and ity1 used later)
          srcv(jpr_itx1)%clgrid = 'U'                  ! ocean stress used after its transformation
          srcv(jpr_ity1)%clgrid = 'V'                  ! i.e. it is always at U- & V-points for i- & j-comp. resp.
@@ -896,8 +896,8 @@
       !!                 third  as  2 components on the cp_ice_msh point 
       !!
-      !!                In 'oce and ice' case, only one vector stress field 
+      !!                Except in 'oce and ice' case, only one vector stress field 
       !!             is received. It has already been processed in sbc_cpl_rcv
       !!             so that it is now defined as (i,j) components given at U-
-      !!             and V-points, respectively. Therefore, here only the third
+      !!             and V-points, respectively. Therefore, only the third
       !!             transformation is done and only if the ice-grid is a 'I'-grid. 
       !!
Index: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 4147)
+++ branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 4148)
@@ -153,4 +153,6 @@
       sfx(:,:) = 0.0_wp                            ! the salt flux due to freezing/melting will be computed (i.e. will be non-zero) 
                                                    ! only if sea-ice is present
+ 
+      fmmflx(:,:) = 0.0_wp                        ! freezing-melting array initialisation
 
       !                                            ! restartability   
@@ -371,4 +373,5 @@
                                                                 ! (includes virtual salt flux beneath ice 
                                                                 ! in linear free surface case)
+         CALL iom_put( "fmmflx", fmmflx  )                      ! Freezing-melting water flux
          CALL iom_put( "qt"    , qns  + qsr )                   ! total heat flux 
          CALL iom_put( "qns"   , qns        )                   ! solar heat flux
