Index: branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90
===================================================================
--- branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90	(revision 7312)
+++ branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90	(revision 7320)
@@ -1166,22 +1166,22 @@
          ENDDO
 
-         WRITE(narea+8000-1,*)"nfipproc(ji,jj),narea :",nfipproc(iproci,iprocj),narea
-         WRITE(narea+8000-1,*)"proc i,j ",iproci,iprocj
-         WRITE(narea+8000-1,*)"jpni  jpnj jpnij ",jpni,jpnj,jpnij
-         WRITE(narea+8000-1,*)"nperio jperio ",nperio,jperio
-         WRITE(narea+8000-1,*)"nowe noea",nowe,noea
-         WRITE(narea+8000-1,*)"noso nono",noso,nono
-         WRITE(narea+8000-1,*)"nbondi nbondj ",nbondi,nbondj
-         WRITE(narea+8000-1,*)"jpiglo jpjglo ",jpiglo,jpjglo
-         WRITE(narea+8000-1,*)"jpi jpj ",jpi,jpj
-         WRITE(narea+8000-1,*)"nbondi nbondj",nbondi,nbondj
-         WRITE(narea+8000-1,*)"nimpp njmpp ",nimpp,njmpp
-         WRITE(narea+8000-1,*)"loc jpi nldi,nlei,nlci ",jpi, nldi        ,nlei         ,nlci
-         WRITE(narea+8000-1,*)"glo jpi nldi,nlei      ",jpi, nldi+nimpp-1,nlei+nimpp-1
-         WRITE(narea+8000-1,*)"loc jpj nldj,nlej,nlcj ",jpj, nldj        ,nlej         ,nlcj
-         WRITE(narea+8000-1,*)"glo jpj nldj,nlej      ",jpj, nldj+njmpp-1,nlej+njmpp-1
-         WRITE(narea+8000-1,*)"jpiglo_crs jpjglo_crs ",jpiglo_crs,jpjglo_crs
-         WRITE(narea+8000-1,*)"jpi_crs jpj_crs ",jpi_crs,jpj_crs
-         WRITE(narea+8000-1,*)"glamt gphit ",glamt(1,1),gphit(jpi,jpj),glamt(jpi,jpj),gphit(jpi,jpj)
+         !WRITE(narea+8000-1,*)"nfipproc(ji,jj),narea :",nfipproc(iproci,iprocj),narea
+         !WRITE(narea+8000-1,*)"proc i,j ",iproci,iprocj
+         !WRITE(narea+8000-1,*)"jpni  jpnj jpnij ",jpni,jpnj,jpnij
+         !WRITE(narea+8000-1,*)"nperio jperio ",nperio,jperio
+         !WRITE(narea+8000-1,*)"nowe noea",nowe,noea
+         !WRITE(narea+8000-1,*)"noso nono",noso,nono
+         !WRITE(narea+8000-1,*)"nbondi nbondj ",nbondi,nbondj
+         !WRITE(narea+8000-1,*)"jpiglo jpjglo ",jpiglo,jpjglo
+         !WRITE(narea+8000-1,*)"jpi jpj ",jpi,jpj
+         !WRITE(narea+8000-1,*)"nbondi nbondj",nbondi,nbondj
+         !WRITE(narea+8000-1,*)"nimpp njmpp ",nimpp,njmpp
+         !WRITE(narea+8000-1,*)"loc jpi nldi,nlei,nlci ",jpi, nldi        ,nlei         ,nlci
+         !WRITE(narea+8000-1,*)"glo jpi nldi,nlei      ",jpi, nldi+nimpp-1,nlei+nimpp-1
+         !WRITE(narea+8000-1,*)"loc jpj nldj,nlej,nlcj ",jpj, nldj        ,nlej         ,nlcj
+         !WRITE(narea+8000-1,*)"glo jpj nldj,nlej      ",jpj, nldj+njmpp-1,nlej+njmpp-1
+         !WRITE(narea+8000-1,*)"jpiglo_crs jpjglo_crs ",jpiglo_crs,jpjglo_crs
+         !WRITE(narea+8000-1,*)"jpi_crs jpj_crs ",jpi_crs,jpj_crs
+         !WRITE(narea+8000-1,*)"glamt gphit ",glamt(1,1),gphit(jpi,jpj),glamt(jpi,jpj),gphit(jpi,jpj)
 
          !==========================================================================
Index: branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90
===================================================================
--- branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90	(revision 7312)
+++ branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90	(revision 7320)
@@ -57,5 +57,4 @@
       INTEGER           ::   inum3    ! temprary units for 'mesh_hgr.nc'  file
       INTEGER           ::   inum4    ! temprary units for 'mesh_zgr.nc'  file
-      INTEGER           ::   iif, iil, ijf, ijl
       CHARACTER(len=21) ::   clnam0   ! filename (mesh and mask informations)
       CHARACTER(len=21) ::   clnam1   ! filename (mesh informations)
@@ -127,35 +126,4 @@
       CALL iom_rstput( 0, 0, inum2, 'vmask', vmask_crs, ktype = jp_i1 )
       CALL iom_rstput( 0, 0, inum2, 'fmask', fmask_crs, ktype = jp_i1 )
-      
-      
-      tmask_i_crs(:,:) = tmask_crs(:,:,1)
-      iif = jpreci
-      iil = nlci_crs - jpreci + 1
-      ijf = jpreci
-      ijl = nlcj_crs - jprecj + 1
-     
-      tmask_i_crs( 1:iif ,    :  ) = 0._wp
-      tmask_i_crs(iil:jpi_crs,    :  ) = 0._wp
-      tmask_i_crs(   :   , 1:ijf ) = 0._wp
-      tmask_i_crs(   :   ,ijl:jpj_crs) = 0._wp
-      
-      
-      tpol_crs(1:jpiglo_crs,:) = 1._wp
-      fpol_crs(1:jpiglo_crs,:) = 1._wp
-      IF( jperio == 3 .OR. jperio == 4 ) THEN
-         tpol_crs(jpiglo_crs/2+1:jpiglo_crs,:) = 0._wp
-         fpol_crs(       1      :jpiglo_crs,:) = 0._wp
-         IF( mjg_crs(nlej_crs) == jpiglo_crs ) THEN
-            DO ji = iif+1, iil-1
-               tmask_i_crs(ji,nlej_crs-1) = tmask_i_crs(ji,nlej_crs-1) &
-               & * tpol_crs(mig_crs(ji),1)
-            ENDDO
-         ENDIF
-      ENDIF
-      IF( jperio == 5 .OR. jperio == 6 ) THEN
-         tpol_crs(      1       :jpiglo_crs,:)=0._wp
-         fpol_crs(jpiglo_crs/2+1:jpiglo_crs,:)=0._wp
-      ENDIF
-      
       CALL iom_rstput( 0, 0, inum2, 'tmaskutil', tmask_i_crs, ktype = jp_i1 )
                                    !    ! unique point mask
Index: branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90
===================================================================
--- branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90	(revision 7312)
+++ branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90	(revision 7320)
@@ -67,7 +67,8 @@
       !!-------------------------------------------------------------------
       !! Local variables
-      INTEGER  :: ji,jj,jk      ! dummy indices
-      INTEGER  :: ierr                                ! allocation error status
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      INTEGER  :: ji,jj,jk           ! dummy indices
+      INTEGER  :: ierr               ! allocation error status
+      INTEGER  :: ios                ! Local integer output status for namelist read
+      INTEGER  :: iif, iil, ijf, ijl ! indices for tmask_i_crs construction
       REAL(wp) :: zmin,zmax
       REAL(wp), DIMENSION(:,:,:), POINTER :: zfse3t, zfse3u, zfse3v, zfse3w
@@ -309,10 +310,33 @@
 
      !---------------------------------------------------------
-     ! 5.  Coarse grid ocean volume and averaging weights
-     !---------------------------------------------------------
-     !CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
-     !CALL ldf_tra_crs_init
-     !CALL dom_grid_glo   ! Return to parent grid domain
-
+     ! 5.  Build tmask_i_crs ( for crsdomwri and lib_fortran_crs (glob_sum)
+     !---------------------------------------------------------
+     tmask_i_crs(:,:) = tmask_crs(:,:,1)
+     iif = jpreci
+     iil = nlci_crs - jpreci + 1
+     ijf = jpreci
+     ijl = nlcj_crs - jprecj + 1
+
+     tmask_i_crs( 1:iif ,    :  ) = 0._wp
+     tmask_i_crs(iil:jpi_crs,    :  ) = 0._wp
+     tmask_i_crs(   :   , 1:ijf ) = 0._wp
+     tmask_i_crs(   :   ,ijl:jpj_crs) = 0._wp
+
+     tpol_crs(1:jpiglo_crs,:) = 1._wp
+     fpol_crs(1:jpiglo_crs,:) = 1._wp
+     IF( jperio == 3 .OR. jperio == 4 ) THEN
+        tpol_crs(jpiglo_crs/2+1:jpiglo_crs,:) = 0._wp
+        fpol_crs(       1      :jpiglo_crs,:) = 0._wp
+        IF( mjg_crs(nlej_crs) == jpiglo_crs ) THEN
+           DO ji = iif+1, iil-1
+              tmask_i_crs(ji,nlej_crs-1) = tmask_i_crs(ji,nlej_crs-1) &
+              & * tpol_crs(mig_crs(ji),1)
+           ENDDO
+        ENDIF
+     ENDIF
+     IF( jperio == 5 .OR. jperio == 6 ) THEN
+        tpol_crs(      1       :jpiglo_crs,:)=0._wp
+        fpol_crs(jpiglo_crs/2+1:jpiglo_crs,:)=0._wp
+     ENDIF
 
      !
Index: branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/lib_fortran_crs.F90
===================================================================
--- branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/lib_fortran_crs.F90	(revision 7320)
+++ branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/lib_fortran_crs.F90	(revision 7320)
@@ -0,0 +1,83 @@
+MODULE lib_fortran_crs
+   !!======================================================================
+   !!                       ***  MODULE  lib_fortran  ***
+   !! Fortran utilities:  includes some low levels fortran functionality
+   !!======================================================================
+   !! History :  3.2  !  2010-05  (M. Dunphy, R. Benshila)  Original code
+   !!            3.4  !  2013-06  (C. Rousset)  add glob_min, glob_max 
+   !!                                           + 3d dim. of input is fexible (jpk, jpl...) 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   glob_sum    : generic interface for global masked summation over
+   !!                 the interior domain for 1 or 2 2D or 3D arrays
+   !!                 it works only for T points
+   !!   SIGN        : generic interface for SIGN to overwrite f95 behaviour
+   !!                 of intrinsinc sign function
+   !!----------------------------------------------------------------------
+   USE par_oce         ! Ocean parameter
+   USE lib_mpp         ! distributed memory computing
+   USE crs
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   glob_sum_crs   ! used in many places
+
+   INTERFACE glob_sum_crs
+      MODULE PROCEDURE glob_sum_2d, glob_sum_3d
+   END INTERFACE
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: lib_fortran.F90 4161 2013-11-07 10:01:27Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+#if ! defined key_mpp_rep
+   ! --- SUM ---
+
+   FUNCTION glob_sum_2d( ptab )
+      !!-----------------------------------------------------------------------
+      !!                  ***  FUNCTION  glob_sum_2D  ***
+      !!
+      !! ** Purpose : perform a masked sum on the inner global domain of a 2D array
+      !!-----------------------------------------------------------------------
+      REAL(wp), INTENT(in), DIMENSION(:,:) ::   ptab          ! input 2D array
+      REAL(wp)                             ::   glob_sum_2d   ! global masked sum
+      !!-----------------------------------------------------------------------
+      !
+      glob_sum_2d = SUM( ptab(:,:)*tmask_i_crs(:,:) )
+      IF( lk_mpp )   CALL mpp_sum( glob_sum_2d )
+      !
+   END FUNCTION glob_sum_2d
+
+
+   FUNCTION glob_sum_3d( ptab )
+      !!-----------------------------------------------------------------------
+      !!                  ***  FUNCTION  glob_sum_3D  ***
+      !!
+      !! ** Purpose : perform a masked sum on the inner global domain of a 3D array
+      !!-----------------------------------------------------------------------
+      REAL(wp), INTENT(in), DIMENSION(:,:,:) ::   ptab          ! input 3D array
+      REAL(wp)                               ::   glob_sum_3d   ! global masked sum
+      !!
+      INTEGER :: jk
+      INTEGER :: ijpk ! local variable: size of the 3d dimension of ptab
+      !!-----------------------------------------------------------------------
+      !
+      ijpk = SIZE(ptab,3)
+      !
+      glob_sum_3d = 0.e0
+      DO jk = 1, ijpk
+         glob_sum_3d = glob_sum_3d + SUM( ptab(:,:,jk)*tmask_i_crs(:,:) )
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( glob_sum_3d )
+      !
+   END FUNCTION glob_sum_3d
+
+#endif
+
+   !!======================================================================
+END MODULE lib_fortran_crs
Index: branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90
===================================================================
--- branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90	(revision 7312)
+++ branches/2015/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90	(revision 7320)
@@ -36,5 +36,5 @@
 
    !* Fortran utilities                         
-   USE lib_fortran
+   USE lib_fortran_crs , ONLY : glob_sum => glob_sum_crs
 
    !* Lateral boundary conditions                         
@@ -382,5 +382,5 @@
 
    !* Fortran utilities                         
-   USE lib_fortran
+   USE lib_fortran , ONLY : glob_sum => glob_sum
 
    !* Lateral boundary conditions                         
