Index: trunk/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 1159)
+++ trunk/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 1161)
@@ -144,5 +144,5 @@
 
    REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
-      hdept, hdepw, e3tp, e3wp   !: ???
+      hdept, hdepw, e3tp, e3wp   !: bottom depth and thickness at T and W points
 
    !! s-coordinate and hybrid z-s-coordinate
Index: trunk/NEMO/OPA_SRC/DOM/domwri.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DOM/domwri.F90	(revision 1159)
+++ trunk/NEMO/OPA_SRC/DOM/domwri.F90	(revision 1161)
@@ -15,4 +15,6 @@
    USE in_out_manager
    USE iom
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp
 
    IMPLICIT NONE
@@ -80,4 +82,71 @@
        clnam4 = 'mesh_zgr'   ! filename (vertical   mesh informations)
 
+      SELECT CASE (nmsh)
+         !                                  ! ============================
+      CASE ( 1 )                            !  create 'mesh_mask.nc' file
+         !                                  ! ============================
+         CALL iom_open( TRIM(clnam0), inum0, ldwrt = .TRUE., kiolib = jprstlib )
+         inum2 = inum0                                            ! put all the informations
+         inum3 = inum0                                            ! in unit inum0
+         inum4 = inum0
+         
+         !                                  ! ============================
+      CASE ( 2 )                            !  create 'mesh.nc' and 
+         !                                  !         'mask.nc' files
+         !                                  ! ============================
+         CALL iom_open( TRIM(clnam1), inum1, ldwrt = .TRUE., kiolib = jprstlib )
+         CALL iom_open( TRIM(clnam2), inum2, ldwrt = .TRUE., kiolib = jprstlib )
+         inum3 = inum1                                            ! put mesh informations 
+         inum4 = inum1                                            ! in unit inum1 
+         !                                  ! ============================
+      CASE ( 3 )                            !  create 'mesh_hgr.nc'
+         !                                  !         'mesh_zgr.nc' and
+         !                                  !         'mask.nc'     files
+         !                                  ! ============================
+         CALL iom_open( TRIM(clnam2), inum2, ldwrt = .TRUE., kiolib = jprstlib )
+         CALL iom_open( TRIM(clnam3), inum3, ldwrt = .TRUE., kiolib = jprstlib )
+         CALL iom_open( TRIM(clnam4), inum4, ldwrt = .TRUE., kiolib = jprstlib )
+         
+      END SELECT
+      
+      !                                                         ! masks (inum2) 
+      CALL iom_rstput( 0, 0, inum2, 'tmask', tmask, ktype = jp_i1 )     !    ! land-sea mask
+      CALL iom_rstput( 0, 0, inum2, 'umask', umask, ktype = jp_i1 )
+      CALL iom_rstput( 0, 0, inum2, 'vmask', vmask, ktype = jp_i1 )
+      CALL iom_rstput( 0, 0, inum2, 'fmask', fmask, ktype = jp_i1 )
+      
+      
+      zprt = tmask(:,:,1) * dom_uniq('T')                               !    ! unique point mask
+      CALL iom_rstput( 0, 0, inum2, 'tmaskutil', zprt, ktype = jp_i1 )  
+      zprt = umask(:,:,1) * dom_uniq('U')
+      CALL iom_rstput( 0, 0, inum2, 'umaskutil', zprt, ktype = jp_i1 )  
+      zprt = vmask(:,:,1) * dom_uniq('V')
+      CALL iom_rstput( 0, 0, inum2, 'vmaskutil', zprt, ktype = jp_i1 )  
+      zprt = fmask(:,:,1) * dom_uniq('F')
+      CALL iom_rstput( 0, 0, inum2, 'fmaskutil', zprt, ktype = jp_i1 )  
+
+      !                                                         ! horizontal mesh (inum3)
+      CALL iom_rstput( 0, 0, inum3, 'glamt', glamt, ktype = jp_r4 )     !    ! latitude
+      CALL iom_rstput( 0, 0, inum3, 'glamu', glamu, ktype = jp_r4 )
+      CALL iom_rstput( 0, 0, inum3, 'glamv', glamv, ktype = jp_r4 )
+      CALL iom_rstput( 0, 0, inum3, 'glamf', glamf, ktype = jp_r4 )
+      
+      CALL iom_rstput( 0, 0, inum3, 'gphit', gphit, ktype = jp_r4 )     !    ! longitude
+      CALL iom_rstput( 0, 0, inum3, 'gphiu', gphiu, ktype = jp_r4 )
+      CALL iom_rstput( 0, 0, inum3, 'gphiv', gphiv, ktype = jp_r4 )
+      CALL iom_rstput( 0, 0, inum3, 'gphif', gphif, ktype = jp_r4 )
+      
+      CALL iom_rstput( 0, 0, inum3, 'e1t', e1t, ktype = jp_r8 )         !    ! e1 scale factors
+      CALL iom_rstput( 0, 0, inum3, 'e1u', e1u, ktype = jp_r8 )
+      CALL iom_rstput( 0, 0, inum3, 'e1v', e1v, ktype = jp_r8 )
+      CALL iom_rstput( 0, 0, inum3, 'e1f', e1f, ktype = jp_r8 )
+      
+      CALL iom_rstput( 0, 0, inum3, 'e2t', e2t, ktype = jp_r8 )         !    ! e2 scale factors
+      CALL iom_rstput( 0, 0, inum3, 'e2u', e2u, ktype = jp_r8 )
+      CALL iom_rstput( 0, 0, inum3, 'e2v', e2v, ktype = jp_r8 )
+      CALL iom_rstput( 0, 0, inum3, 'e2f', e2f, ktype = jp_r8 )
+      
+      CALL iom_rstput( 0, 0, inum3, 'ff', ff, ktype = jp_r8 )           !    ! coriolis factor
+      
 !       note that mbathy has been modified in dommsk or in solver.
 !       it is the number of non-zero "w" levels in the water, and the minimum 
@@ -86,126 +155,103 @@
 !
       zprt = tmask(:,:,1)*(mbathy-1)
-
-      SELECT CASE (nmsh)
-         !                                     ! ============================
-         CASE ( 1 )                            !  create 'mesh_mask.nc' file
-            !                                  ! ============================
-            CALL iom_open( TRIM(clnam0), inum0, ldwrt = .TRUE., kiolib = jprstlib )
-            inum2 = inum0                                            ! put all the informations
-            inum3 = inum0                                            ! in unit inum0
-            inum4 = inum0
-
-            !                                  ! ============================
-         CASE ( 2 )                            !  create 'mesh.nc' and 
-            !                                  !         'mask.nc' files
-            !                                  ! ============================
-            CALL iom_open( TRIM(clnam1), inum1, ldwrt = .TRUE., kiolib = jprstlib )
-            CALL iom_open( TRIM(clnam2), inum2, ldwrt = .TRUE., kiolib = jprstlib )
-            inum3 = inum1                                            ! put mesh informations 
-            inum4 = inum1                                            ! in unit inum1 
-            !                                  ! ============================
-         CASE ( 3 )                            !  create 'mesh_hgr.nc'
-            !                                  !         'mesh_zgr.nc' and
-            !                                  !         'mask.nc'     files
-            !                                  ! ============================
-            CALL iom_open( TRIM(clnam2), inum2, ldwrt = .TRUE., kiolib = jprstlib )
-            CALL iom_open( TRIM(clnam3), inum3, ldwrt = .TRUE., kiolib = jprstlib )
-            CALL iom_open( TRIM(clnam4), inum4, ldwrt = .TRUE., kiolib = jprstlib )
-
-         END SELECT
-
-         !                                                         ! masks (inum2) 
-         CALL iom_rstput( 0, 0, inum2, 'tmask', tmask, ktype = jp_i1 ) 
-         CALL iom_rstput( 0, 0, inum2, 'umask', umask, ktype = jp_i1 )
-         CALL iom_rstput( 0, 0, inum2, 'vmask', vmask, ktype = jp_i1 )
-         CALL iom_rstput( 0, 0, inum2, 'fmask', fmask, ktype = jp_i1 )
-
-         !                                                         ! horizontal mesh (inum3)
-         CALL iom_rstput( 0, 0, inum3, 'glamt', glamt, ktype = jp_r4 )     !    ! latitude
-         CALL iom_rstput( 0, 0, inum3, 'glamu', glamu, ktype = jp_r4 )
-         CALL iom_rstput( 0, 0, inum3, 'glamv', glamv, ktype = jp_r4 )
-         CALL iom_rstput( 0, 0, inum3, 'glamf', glamf, ktype = jp_r4 )
-
-         CALL iom_rstput( 0, 0, inum3, 'gphit', gphit, ktype = jp_r4 )     !    ! longitude
-         CALL iom_rstput( 0, 0, inum3, 'gphiu', gphiu, ktype = jp_r4 )
-         CALL iom_rstput( 0, 0, inum3, 'gphiv', gphiv, ktype = jp_r4 )
-         CALL iom_rstput( 0, 0, inum3, 'gphif', gphif, ktype = jp_r4 )
-
-         CALL iom_rstput( 0, 0, inum3, 'e1t', e1t, ktype = jp_r8 )         !    ! e1 scale factors
-         CALL iom_rstput( 0, 0, inum3, 'e1u', e1u, ktype = jp_r8 )
-         CALL iom_rstput( 0, 0, inum3, 'e1v', e1v, ktype = jp_r8 )
-         CALL iom_rstput( 0, 0, inum3, 'e1f', e1f, ktype = jp_r8 )
-
-         CALL iom_rstput( 0, 0, inum3, 'e2t', e2t, ktype = jp_r8 )         !    ! e2 scale factors
-         CALL iom_rstput( 0, 0, inum3, 'e2u', e2u, ktype = jp_r8 )
-         CALL iom_rstput( 0, 0, inum3, 'e2v', e2v, ktype = jp_r8 )
-         CALL iom_rstput( 0, 0, inum3, 'e2f', e2f, ktype = jp_r8 )
-
-         CALL iom_rstput( 0, 0, inum3, 'ff', ff, ktype = jp_r8 )           !    ! coriolis factor
-
-         CALL iom_rstput( 0, 0, inum4, 'mbathy', zprt, ktype = jp_i2 )
-
+      CALL iom_rstput( 0, 0, inum4, 'mbathy', zprt, ktype = jp_i2 )
+            
 #if ! defined key_zco
-         IF( ln_sco ) THEN                                         ! s-coordinate
-            CALL iom_rstput( 0, 0, inum4, 'hbatt', hbatt )      !    ! depth
-            CALL iom_rstput( 0, 0, inum4, 'hbatu', hbatu ) 
-            CALL iom_rstput( 0, 0, inum4, 'hbatv', hbatv )
-            CALL iom_rstput( 0, 0, inum4, 'hbatf', hbatf )
+      IF( ln_sco ) THEN                                         ! s-coordinate
+         CALL iom_rstput( 0, 0, inum4, 'hbatt', hbatt )         !    ! depth
+         CALL iom_rstput( 0, 0, inum4, 'hbatu', hbatu ) 
+         CALL iom_rstput( 0, 0, inum4, 'hbatv', hbatv )
+         CALL iom_rstput( 0, 0, inum4, 'hbatf', hbatf )
+         
+         CALL iom_rstput( 0, 0, inum4, 'gsigt', gsigt )         !    ! scaling coef.
+         CALL iom_rstput( 0, 0, inum4, 'gsigw', gsigw )  
+         CALL iom_rstput( 0, 0, inum4, 'gsi3w', gsi3w )
+         CALL iom_rstput( 0, 0, inum4, 'esigt', esigt )
+         CALL iom_rstput( 0, 0, inum4, 'esigw', esigw )
+         
+         CALL iom_rstput( 0, 0, inum4, 'e3t', e3t )             !    ! scale factors
+         CALL iom_rstput( 0, 0, inum4, 'e3u', e3u )
+         CALL iom_rstput( 0, 0, inum4, 'e3v', e3v )
+         CALL iom_rstput( 0, 0, inum4, 'e3w', e3w )
+         
+         CALL iom_rstput( 0, 0, inum4, 'gdept_0' , gdept_0 )    !    ! stretched system
+         CALL iom_rstput( 0, 0, inum4, 'gdepw_0' , gdepw_0 )
+      ENDIF
+      
+      IF( ln_zps ) THEN                                         ! z-coordinate - partial steps
+         CALL iom_rstput( 0, 0, inum4, 'hdept' , hdept  )       !    ! bottom depth
+         CALL iom_rstput( 0, 0, inum4, 'hdepw' , hdepw  ) 
+         
+         CALL iom_rstput( 0, 0, inum4, 'e3t_ps', e3tp   )       !    ! bottom scale factors
+         CALL iom_rstput( 0, 0, inum4, 'e3w_ps', e3wp   ) 
+	
+         CALL iom_rstput( 0, 0, inum4, 'gdept_0', gdept_0 )     !    ! reference z-coord.
+         CALL iom_rstput( 0, 0, inum4, 'gdepw_0', gdepw_0 )
+         CALL iom_rstput( 0, 0, inum4, 'e3t_0'  , e3t_0   )
+         CALL iom_rstput( 0, 0, inum4, 'e3w_0'  , e3w_0   )
+      ENDIF
+      
+#endif
+      
+      IF( ln_zco ) THEN
+         !                                                      ! z-coordinate - full steps
+         CALL iom_rstput( 0, 0, inum4, 'gdept_0', gdept_0 )     !    ! depth
+         CALL iom_rstput( 0, 0, inum4, 'gdepw_0', gdepw_0 )
+         CALL iom_rstput( 0, 0, inum4, 'e3t_0'  , e3t_0   )     !    ! scale factors
+         CALL iom_rstput( 0, 0, inum4, 'e3w_0'  , e3w_0   )
+      ENDIF
+      !                                     ! ============================
+      !                                     !        close the files 
+      !                                     ! ============================
+      SELECT CASE ( nmsh )
+      CASE ( 1 )                
+         CALL iom_close( inum0 )
+      CASE ( 2 )
+         CALL iom_close( inum1 )
+         CALL iom_close( inum2 )
+      CASE ( 3 )
+         CALL iom_close( inum2 )
+         CALL iom_close( inum3 )
+         CALL iom_close( inum4 )
+      END SELECT
+      
+   END SUBROUTINE dom_wri
+
+
+   FUNCTION dom_uniq( cdgrd )   RESULT( puniq )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_uniq  ***
+      !!                   
+      !! ** Purpose :   identify unique point of a grid (TUVF)
+      !!
+      !! ** Method  :   1) aplly lbc_lnk on an array with different values for each element
+      !!                2) check which elements have been changed
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(len=1)            , INTENT(in   ) ::  cdgrd   ! 
+      REAL(wp), DIMENSION(jpi,jpj)                ::  puniq   ! 
+
+      REAL(wp), DIMENSION(jpi,jpj  ) ::  ztstref   ! array with different values for each element 
+      REAL(wp)                       ::  zshift    ! shift value link to the process number
+      LOGICAL , DIMENSION(jpi,jpj,1) ::  lldbl     ! is the point unique or not?
+      INTEGER                        ::  ji        ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      ! build an array with different values for each element 
+      ! in mpp: make sure that these values are different even between process
+      ! -> apply a shift value according to the process number
+      zshift = jpi * jpj * ( narea - 1 )
+      ztstref(:,:) = RESHAPE( (/ (zshift + REAL(ji, wp), ji = 1, jpi*jpj) /), (/ jpi, jpj /) )
    
-            CALL iom_rstput( 0, 0, inum4, 'gsigt', gsigt )        !    ! scaling coef.
-            CALL iom_rstput( 0, 0, inum4, 'gsigw', gsigw )  
-            CALL iom_rstput( 0, 0, inum4, 'gsi3w', gsi3w )
-            CALL iom_rstput( 0, 0, inum4, 'esigt', esigt )
-            CALL iom_rstput( 0, 0, inum4, 'esigw', esigw )
-
-            CALL iom_rstput( 0, 0, inum4, 'e3t', e3t )       !    ! scale factors
-            CALL iom_rstput( 0, 0, inum4, 'e3u', e3u )
-            CALL iom_rstput( 0, 0, inum4, 'e3v', e3v )
-            CALL iom_rstput( 0, 0, inum4, 'e3w', e3w )
-
-            CALL iom_rstput( 0, 0, inum4, 'gdept_0' , gdept_0 )  !    ! stretched system
-            CALL iom_rstput( 0, 0, inum4, 'gdepw_0' , gdepw_0 )
-         ENDIF
-
-         IF( ln_zps ) THEN                                         ! z-coordinate - partial steps
-            CALL iom_rstput( 0, 0, inum4, 'hdept' , hdept  )    !    ! depth
-            CALL iom_rstput( 0, 0, inum4, 'hdepw' , hdepw  ) 
-
-            CALL iom_rstput( 0, 0, inum4, 'e3t' , e3t )      !    ! scale factors
-            CALL iom_rstput( 0, 0, inum4, 'e3u' , e3u )
-            CALL iom_rstput( 0, 0, inum4, 'e3v' , e3v )
-            CALL iom_rstput( 0, 0, inum4, 'e3w' , e3w )
-
-            CALL iom_rstput( 0, 0, inum4, 'gdept_0', gdept_0 )   !    ! reference z-coord.
-            CALL iom_rstput( 0, 0, inum4, 'gdepw_0', gdepw_0 )
-            CALL iom_rstput( 0, 0, inum4, 'e3t_0'  , e3t_0   )
-            CALL iom_rstput( 0, 0, inum4, 'e3w_0'  , e3w_0   )
-         ENDIF
-
-#endif
-
-         IF( ln_zco ) THEN
-         !                                                         ! z-coordinate - full steps
-            CALL iom_rstput( 0, 0, inum4, 'gdept_0', gdept_0 )   !    ! depth
-            CALL iom_rstput( 0, 0, inum4, 'gdepw_0', gdepw_0 )
-            CALL iom_rstput( 0, 0, inum4, 'e3t_0'  , e3t_0   )   !    ! scale factors
-            CALL iom_rstput( 0, 0, inum4, 'e3w_0'  , e3w_0   )
-         ENDIF
-         !                                     ! ============================
-         !                                     !        close the files 
-         !                                     ! ============================
-         SELECT CASE ( nmsh )
-            CASE ( 1 )                
-               CALL iom_close( inum0 )
-            CASE ( 2 )
-               CALL iom_close( inum1 )
-               CALL iom_close( inum2 )
-            CASE ( 3 )
-               CALL iom_close( inum2 )
-               CALL iom_close( inum3 )
-               CALL iom_close( inum4 )
-         END SELECT
-
-   END SUBROUTINE dom_wri
+      puniq(:,:) = ztstref(:,:)                   ! default definition
+      CALL lbc_lnk( puniq, cdgrd, 1. )            ! apply boundary conditions
+      lldbl(:,:,1) = puniq(:,:) == ztstref(:,:)   ! check which values have been changed 
+      
+      puniq(:,:) = 1.                             ! default definition
+      ! fill only the inner part of the cpu with llbl converted into real 
+      puniq(nldi:nlei,nldj:nlej) = REAL(COUNT( lldbl(nldi:nlei,nldj:nlej,:), dim = 3 ), wp)
+
+   END FUNCTION dom_uniq
+
 
    !!======================================================================
