Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OFF_SRC/domain.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OFF_SRC/domain.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OFF_SRC/domain.F90	(revision 3632)
@@ -205,5 +205,4 @@
       rdtmax    = rn_rdtmin
       rdth      = rn_rdth
-      nclosea   = nn_closea
 
       REWIND( numnam )             ! Namelist cross land advection
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 3632)
@@ -773,5 +773,5 @@
             DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
                nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
-               nbj => idx_bdy(ib_bdy)%nbi(ib,igrd)
+               nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
                flagu => idx_bdy(ib_bdy)%flagu(ib)
                bdysurftot = bdysurftot + hu     (nbi  , nbj)                           &
@@ -786,5 +786,5 @@
             DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
                nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
-               nbj => idx_bdy(ib_bdy)%nbi(ib,igrd)
+               nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
                flagv => idx_bdy(ib_bdy)%flagv(ib)
                bdysurftot = bdysurftot + hv     (nbi, nbj  )                           &
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 3632)
@@ -38,6 +38,9 @@
   USE dianam          ! build name of file
   USE lib_mpp         ! distributed memory computing library
-#if defined key_lim2 || defined key_lim3
-  USE ice
+#if defined key_lim2
+  USE ice_2
+#endif
+#if defined key_lim3
+  USE ice_3
 #endif
   USE domvvl
@@ -362,5 +365,5 @@
               WRITE(numout,*)"      List of points in global domain:"
               DO jpt=1,iptglo
-                 WRITE(numout,*)'        # I J ',jpt,coordtemp(jpt)
+                 WRITE(numout,*)'        # I J ',jpt,coordtemp(jpt),directemp(jpt)
               ENDDO                  
            ENDIF
@@ -403,9 +406,7 @@
 
               IF(jsec==nn_secdebug .AND. secs(jsec)%nb_point .NE. 0)THEN
-              WRITE(narea+200,*)'avant secs(jsec)%nb_point iptloc ',secs(jsec)%nb_point,iptloc
               DO jpt = 1,iptloc
                  iiglo = secs(jsec)%listPoint(jpt)%I + jpizoom - 1 + nimpp - 1
                  ijglo = secs(jsec)%listPoint(jpt)%J + jpjzoom - 1 + njmpp - 1
-                 WRITE(narea+200,*)'avant # I J : ',iiglo,ijglo
               ENDDO
               ENDIF
@@ -421,9 +422,7 @@
            ENDIF
            IF(jsec==nn_secdebug .AND. secs(jsec)%nb_point .NE. 0)THEN
-              WRITE(narea+200,*)'apres secs(jsec)%nb_point iptloc ',secs(jsec)%nb_point,iptloc
               DO jpt = 1,secs(jsec)%nb_point
                  iiglo = secs(jsec)%listPoint(jpt)%I + jpizoom - 1 + nimpp - 1
                  ijglo = secs(jsec)%listPoint(jpt)%J + jpjzoom - 1 + njmpp - 1
-                 WRITE(narea+200,*)'apres # I J : ',iiglo,ijglo
               ENDDO
            ENDIF
@@ -626,6 +625,7 @@
         ELSE                                ; isgnv =  1
         ENDIF
-
-        IF( ld_debug )write(numout,*)"isgnu isgnv ",isgnu,isgnv
+        IF( sec%slopeSection .GE. 9999. )     isgnv =  1
+
+        IF( ld_debug )write(numout,*)"sec%slopeSection isgnu isgnv ",sec%slopeSection,isgnu,isgnv
 
         !--------------------------------------!
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 3632)
@@ -175,5 +175,5 @@
          z3d(:,:,jpk) = 0.e0
          DO jk = 1, jpkm1
-            z3d(:,:,jk) = rau0 * un(:,:,jk) * e1u(:,:) * fse3u(:,:,jk)
+            z3d(:,:,jk) = rau0 * un(:,:,jk) * e2u(:,:) * fse3u(:,:,jk)
          END DO
          CALL iom_put( "u_masstr", z3d )                  ! mass transport in i-direction
@@ -190,5 +190,5 @@
          CALL iom_put( "u_heattr", z2d )                  ! heat transport in i-direction
          DO jk = 1, jpkm1
-            z3d(:,:,jk) = rau0 * vn(:,:,jk) * e2v(:,:) * fse3v(:,:,jk)
+            z3d(:,:,jk) = rau0 * vn(:,:,jk) * e1v(:,:) * fse3v(:,:,jk)
          END DO
          CALL iom_put( "v_masstr", z3d )                  ! mass transport in j-direction
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/closea.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/closea.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/closea.F90	(revision 3632)
@@ -7,4 +7,5 @@
    !!             8.5  !  02-06  (E. Durand, G. Madec)  F90
    !!             9.0  !  06-07  (G. Madec)  add clo_rnf, clo_ups, clo_bat
+   !!        NEMO 3.4  !  03-12  (P.G. Fogli) sbc_clo bug fix & mpp reproducibility
    !!----------------------------------------------------------------------
 
@@ -18,9 +19,11 @@
    USE oce             ! dynamics and tracers
    USE dom_oce         ! ocean space and time domain
-   USE phycst
+   USE phycst          ! physical constants
    USE in_out_manager  ! I/O manager
    USE sbc_oce         ! ocean surface boundary conditions
-   USE lib_mpp         ! distributed memory computing library
-   USE lbclnk          ! ???
+   USE lib_fortran,    ONLY: glob_sum, DDPDD
+   USE lbclnk          ! lateral boundary condition - MPP exchanges
+   USE lib_mpp         ! MPP library
+   USE timing
 
    IMPLICIT NONE
@@ -86,4 +89,12 @@
          SELECT CASE ( jp_cfg )
          !                                           ! =======================
+         CASE ( 1 )                                  ! ORCA_R1 configuration
+            !                                        ! =======================
+            ncsnr(1)   = 1    ; ncstt(1)   = 0           ! Caspian Sea
+            ncsi1(1)   = 332  ; ncsj1(1)   = 203
+            ncsi2(1)   = 344  ; ncsj2(1)   = 235
+            ncsir(1,1) = 1    ; ncsjr(1,1) = 1
+            !                                        
+            !                                        ! =======================
          CASE ( 2 )                                  !  ORCA_R2 configuration
             !                                        ! =======================
@@ -174,13 +185,17 @@
       !!      put as run-off in open ocean.
       !!
-      !! ** Action  :   emp   updated surface freshwater flux at kt
+      !! ** Action  :   emp updated surface freshwater fluxes and associated heat content at kt
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean model time step
       !
-      INTEGER                     ::   ji, jj, jc, jn   ! dummy loop indices
-      REAL(wp)                    ::   zze2, zcoef, zcoef1
-      REAL(wp), DIMENSION (jpncs) ::   zfwf 
-      !!----------------------------------------------------------------------
-      !
+      INTEGER             ::   ji, jj, jc, jn   ! dummy loop indices
+      REAL(wp), PARAMETER ::   rsmall = 1.e-20_wp    ! Closed sea correction epsilon
+      REAL(wp)            ::   zze2, ztmp, zcorr     ! 
+      REAL(wp)            ::   zcoef, zcoef1         ! 
+      COMPLEX(wp)         ::   ctmp 
+      REAL(wp), DIMENSION(jpncs) ::   zfwf   ! 1D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('sbc_clo')
       !                                                   !------------------!
       IF( kt == nit000 ) THEN                             !  Initialisation  !
@@ -190,16 +205,31 @@
          IF(lwp) WRITE(numout,*)'~~~~~~~'
 
-         ! Total surface of ocean
-         surf(jpncs+1) = SUM( e1t(:,:) * e2t(:,:) * tmask_i(:,:) )
-
-         DO jc = 1, jpncs
-            surf(jc) =0.e0
-            DO jj = ncsj1(jc), ncsj2(jc)
-               DO ji = ncsi1(jc), ncsi2(jc)
-                  surf(jc) = surf(jc) + e1t(ji,jj) * e2t(ji,jj) * tmask_i(ji,jj)      ! surface of closed seas
+         surf(:) = 0.e0_wp
+         !
+         surf(jpncs+1) = glob_sum( e1e2t(:,:) )   ! surface of the global ocean
+         !
+         !                                        ! surface of closed seas 
+         IF( lk_mpp_rep ) THEN                         ! MPP reproductible calculation
+            DO jc = 1, jpncs
+               ctmp = CMPLX( 0.e0, 0.e0, wp )
+               DO jj = ncsj1(jc), ncsj2(jc)
+                  DO ji = ncsi1(jc), ncsi2(jc)
+                     ztmp = e1e2t(ji,jj) * tmask_i(ji,jj)
+                     CALL DDPDD( CMPLX( ztmp, 0.e0, wp ), ctmp )
+                  END DO 
                END DO 
-            END DO 
-         END DO 
-         IF( lk_mpp )   CALL mpp_sum ( surf, jpncs+1 )       ! mpp: sum over all the global domain
+               IF( lk_mpp )   CALL mpp_sum( ctmp )
+               surf(jc) = REAL(ctmp,wp)
+            END DO
+         ELSE                                          ! Standard calculation           
+            DO jc = 1, jpncs
+               DO jj = ncsj1(jc), ncsj2(jc)
+                  DO ji = ncsi1(jc), ncsi2(jc)
+                     surf(jc) = surf(jc) + e1e2t(ji,jj) * tmask_i(ji,jj)      ! surface of closed seas
+                  END DO 
+               END DO 
+            END DO 
+            IF( lk_mpp )   CALL mpp_sum ( surf, jpncs )       ! mpp: sum over all the global domain
+         ENDIF
 
          IF(lwp) WRITE(numout,*)'     Closed sea surfaces'
@@ -216,79 +246,116 @@
       !                                                   !--------------------!
       !                                                   !  update emp        !
-      zfwf = 0.e0                                         !--------------------!
-      DO jc = 1, jpncs
-         DO jj = ncsj1(jc), ncsj2(jc)
-            DO ji = ncsi1(jc), ncsi2(jc)
-               zfwf(jc) = zfwf(jc) + e1t(ji,jj) * e2t(ji,jj) * ( emp(ji,jj)-rnf(ji,jj) ) * tmask_i(ji,jj) 
-            END DO  
-         END DO 
-      END DO
-      IF( lk_mpp )   CALL mpp_sum ( zfwf(:) , jpncs )       ! mpp: sum over all the global domain
+      zfwf = 0.e0_wp                                      !--------------------!
+      IF( lk_mpp_rep ) THEN                         ! MPP reproductible calculation
+         DO jc = 1, jpncs
+            ctmp = CMPLX( 0.e0, 0.e0, wp )
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  ztmp = e1e2t(ji,jj) * ( emp(ji,jj)-rnf(ji,jj) ) * tmask_i(ji,jj)
+                  CALL DDPDD( CMPLX( ztmp, 0.e0, wp ), ctmp )
+               END DO  
+            END DO 
+            IF( lk_mpp )   CALL mpp_sum( ctmp )
+            zfwf(jc) = REAL(ctmp,wp)
+         END DO
+      ELSE                                          ! Standard calculation           
+         DO jc = 1, jpncs
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  zfwf(jc) = zfwf(jc) + e1e2t(ji,jj) * ( emp(ji,jj)-rnf(ji,jj) ) * tmask_i(ji,jj) 
+               END DO  
+            END DO 
+         END DO
+         IF( lk_mpp )   CALL mpp_sum ( zfwf(:) , jpncs )       ! mpp: sum over all the global domain
+      ENDIF
 
       IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN      ! Black Sea case for ORCA_R2 configuration
-         zze2    = ( zfwf(3) + zfwf(4) ) / 2.
+         zze2    = ( zfwf(3) + zfwf(4) ) * 0.5_wp
          zfwf(3) = zze2
          zfwf(4) = zze2
       ENDIF
 
+      zcorr = 0._wp
+
       DO jc = 1, jpncs
          !
-         IF( ncstt(jc) == 0 ) THEN 
-            ! water/evap excess is shared by all open ocean
-            zcoef  = zfwf(jc) / surf(jpncs+1)
-            zcoef1 = rcp * zcoef
-            emp(:,:) = emp(:,:) + zcoef
-            qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:)
-         ELSEIF( ncstt(jc) == 1 ) THEN 
-            ! Excess water in open sea, at outflow location, excess evap shared
-            IF ( zfwf(jc) <= 0.e0 ) THEN 
-                DO jn = 1, ncsnr(jc)
+         ! The following if avoids the redistribution of the round off
+         IF ( ABS(zfwf(jc) / surf(jpncs+1) ) > rsmall) THEN
+            !
+            IF( ncstt(jc) == 0 ) THEN           ! water/evap excess is shared by all open ocean
+               zcoef    = zfwf(jc) / surf(jpncs+1)
+               zcoef1   = rcp * zcoef
+               emp(:,:) = emp(:,:) + zcoef
+               qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:)
+               ! accumulate closed seas correction
+               zcorr    = zcorr    + zcoef
+               !
+            ELSEIF( ncstt(jc) == 1 ) THEN       ! Excess water in open sea, at outflow location, excess evap shared
+               IF ( zfwf(jc) <= 0.e0_wp ) THEN 
+                   DO jn = 1, ncsnr(jc)
+                     ji = mi0(ncsir(jc,jn))
+                     jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
+                     IF (      ji > 1 .AND. ji < jpi   &
+                         .AND. jj > 1 .AND. jj < jpj ) THEN 
+                         zcoef      = zfwf(jc) / ( REAL(ncsnr(jc)) * e1e2t(ji,jj) )
+                         zcoef1     = rcp * zcoef
+                         emp(ji,jj) = emp(ji,jj) + zcoef
+                         qns(ji,jj) = qns(ji,jj) - zcoef1 * sst_m(ji,jj)
+                     ENDIF 
+                   END DO 
+               ELSE 
+                   zcoef    = zfwf(jc) / surf(jpncs+1)
+                   zcoef1   = rcp * zcoef
+                   emp(:,:) = emp(:,:) + zcoef
+                   qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:)
+                   ! accumulate closed seas correction
+                   zcorr    = zcorr    + zcoef
+               ENDIF
+            ELSEIF( ncstt(jc) == 2 ) THEN       ! Excess e-p-r (either sign) goes to open ocean, at outflow location
+               DO jn = 1, ncsnr(jc)
                   ji = mi0(ncsir(jc,jn))
                   jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
-                  IF (      ji > 1 .AND. ji < jpi   &
-                      .AND. jj > 1 .AND. jj < jpj ) THEN 
-                      zcoef  = zfwf(jc) / ( REAL(ncsnr(jc), wp) * e1t(ji,jj) * e2t(ji,jj) )
-                      zcoef1 = rcp * zcoef
-                      emp(ji,jj) = emp(ji,jj) + zcoef
-                      qns(ji,jj) = qns(ji,jj) - zcoef1 * sst_m(ji,jj)
-                  END IF 
-                END DO 
-            ELSE 
-                zcoef  = zfwf(jc) / surf(jpncs+1)
-                zcoef1 = rcp * zcoef
-                emp(:,:) = emp(:,:) + zcoef
-                qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:)
-            ENDIF
-         ELSEIF( ncstt(jc) == 2 ) THEN 
-            ! Excess e-p+r (either sign) goes to open ocean, at outflow location
-            IF(      ji > 1 .AND. ji < jpi    &
-               .AND. jj > 1 .AND. jj < jpj ) THEN 
-                DO jn = 1, ncsnr(jc)
-                  ji = mi0(ncsir(jc,jn))
-                  jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
-                  zcoef  = zfwf(jc) / ( REAL(ncsnr(jc), wp) * e1t(ji,jj) * e2t(ji,jj) )
-                  zcoef1 = rcp * zcoef
-                  emp(ji,jj) = emp(ji,jj) + zcoef
-                  qns(ji,jj) = qns(ji,jj) - zcoef1 * sst_m(ji,jj)
-                END DO 
+                  IF(      ji > 1 .AND. ji < jpi    &
+                     .AND. jj > 1 .AND. jj < jpj ) THEN 
+                     zcoef      = zfwf(jc) / ( REAL(ncsnr(jc)) *  e1e2t(ji,jj) )
+                     zcoef1     = rcp * zcoef
+                     emp(ji,jj) = emp(ji,jj) + zcoef
+                     qns(ji,jj) = qns(ji,jj) - zcoef1 * sst_m(ji,jj)
+                  ENDIF 
+               END DO 
             ENDIF 
-         ENDIF 
-         !
-         DO jj = ncsj1(jc), ncsj2(jc)
-            DO ji = ncsi1(jc), ncsi2(jc)
-               zcoef  = zfwf(jc) / surf(jc)
-               zcoef1 = rcp * zcoef
-               emp(ji,jj) = emp(ji,jj) - zcoef
-               qns(ji,jj) = qns(ji,jj) + zcoef1 * sst_m(ji,jj)
-            END DO  
-         END DO 
-         !
+            !
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  zcoef      = zfwf(jc) / surf(jc)
+                  zcoef1     = rcp * zcoef
+                  emp(ji,jj) = emp(ji,jj) - zcoef
+                  qns(ji,jj) = qns(ji,jj) + zcoef1 * sst_m(ji,jj)
+               END DO  
+            END DO 
+            !
+         END IF
       END DO 
-      !
-      CALL lbc_lnk( emp , 'T', 1. )
+
+      IF ( ABS(zcorr) > rsmall ) THEN      ! remove the global correction from the closed seas
+         DO jc = 1, jpncs                  ! only if it is large enough
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  emp(ji,jj) = emp(ji,jj) - zcorr
+                  qns(ji,jj) = qns(ji,jj) + rcp * zcorr * sst_m(ji,jj)
+               END DO  
+             END DO 
+          END DO
+      ENDIF
+      !
+      emp (:,:) = emp (:,:) * tmask(:,:,1)
+      !
+      CALL lbc_lnk( emp , 'T', 1._wp )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('sbc_clo')
       !
    END SUBROUTINE sbc_clo
-   
-   
+
+
    SUBROUTINE clo_rnf( p_rnfmsk )
       !!---------------------------------------------------------------------
@@ -314,5 +381,5 @@
                ii = mi0( ncsir(jc,jn) )
                ij = mj0( ncsjr(jc,jn) )
-               p_rnfmsk(ii,ij) = MAX( p_rnfmsk(ii,ij), 1.0 )
+               p_rnfmsk(ii,ij) = MAX( p_rnfmsk(ii,ij), 1.0_wp )
             END DO 
          ENDIF 
@@ -342,5 +409,5 @@
          DO jj = ncsj1(jc), ncsj2(jc)
             DO ji = ncsi1(jc), ncsi2(jc)
-               p_upsmsk(ji,jj) = 0.5            ! mixed upstream/centered scheme over closed seas
+               p_upsmsk(ji,jj) = 0.5_wp         ! mixed upstream/centered scheme over closed seas
             END DO 
          END DO 
@@ -380,2 +447,3 @@
    !!======================================================================
 END MODULE closea
+
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 3632)
@@ -52,5 +52,4 @@
    REAL(wp), PUBLIC ::   rdtmax          !: maximum time step on tracers
    REAL(wp), PUBLIC ::   rdth            !: depth variation of tracer step
-   INTEGER , PUBLIC ::   nclosea         !: =0 suppress closed sea/lake from the ORCA domain or not (=1)
 
    !                                                  !!! associated variables
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 3632)
@@ -238,5 +238,4 @@
       rdtmax    = rn_rdtmin
       rdth      = rn_rdth
-      nclosea   = nn_closea
 
       REWIND( numnam )              ! Namelist cross land advection
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 3632)
@@ -422,7 +422,7 @@
             CALL iom_close( inum )
             mbathy(:,:) = INT( bathy(:,:) )
-            !                                                ! =====================
+            !
             IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN    ! ORCA R2 configuration
-               !                                             ! =====================
+               !
                IF( nn_cla == 0 ) THEN
                   ii0 = 140   ;   ii1 = 140                  ! Gibraltar Strait open 
@@ -454,7 +454,7 @@
             CALL iom_get  ( inum, jpdom_data, 'Bathymetry', bathy )
             CALL iom_close( inum )
-            !                                                ! =====================
+            !                                                
             IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN    ! ORCA R2 configuration
-               !                                             ! =====================
+               !
               IF( nn_cla == 0 ) THEN
                  ii0 = 140   ;   ii1 = 140                   ! Gibraltar Strait open 
@@ -489,20 +489,7 @@
       ENDIF
       !
-      !                                               ! =========================== !
-      IF( nclosea == 0 ) THEN                         !   NO closed seas or lakes   !
-         DO jl = 1, jpncs                             ! =========================== !
-            DO jj = ncsj1(jl), ncsj2(jl)
-               DO ji = ncsi1(jl), ncsi2(jl)
-                  mbathy(ji,jj) = 0                   ! suppress closed seas and lakes from bathymetry
-                  bathy (ji,jj) = 0._wp               
-               END DO
-            END DO
-         END DO
-      ENDIF
-      !
-      !                                               ! =========================== !
-      !                                               !     set a minimum depth     !
-      !                                               ! =========================== !
-      IF ( .not. ln_sco ) THEN
+      IF( nn_closea == 0 )   CALL clo_bat( bathy, mbathy )    !==  NO closed seas or lakes  ==!
+      !                       
+      IF ( .not. ln_sco ) THEN                                !==  set a minimum depth  ==!
          IF( rn_hmin < 0._wp ) THEN    ;   ik = - INT( rn_hmin )                                      ! from a nb of level
          ELSE                          ;   ik = MINLOC( gdepw_0, mask = gdepw_0 > rn_hmin, dim = 1 )  ! from a depth
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 3632)
@@ -678,11 +678,10 @@
       REAL(wp) :: zrhdt1 
       REAL(wp) :: zdpdx1, zdpdx2, zdpdy1, zdpdy2
-      INTEGER  :: zbhitwe, zbhitns
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdeptht, zrhh 
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdept, zrhh 
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp
       !!----------------------------------------------------------------------
       !
       CALL wrk_alloc( jpi,jpj,jpk, zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp ) 
-      CALL wrk_alloc( jpi,jpj,jpk, zdeptht, zrhh ) 
+      CALL wrk_alloc( jpi,jpj,jpk, zdept, zrhh ) 
       !
       IF( kt == nit000 ) THEN
@@ -717,23 +716,15 @@
       END DO
 
-      ! Transfer the depth of "T(:,:,:)" to vertical coordinate "zdeptht(:,:,:)"
-      DO jj = 1, jpj
-        DO ji = 1, jpi
-          zdeptht(ji,jj,1) = 0.5_wp * fse3w(ji,jj,1)
-          zdeptht(ji,jj,1) = zdeptht(ji,jj,1) - sshn(ji,jj) * znad
-          DO jk = 2, jpk
-             zdeptht(ji,jj,jk) = zdeptht(ji,jj,jk-1) + fse3w(ji,jj,jk)
-          END DO
-        END DO
-      END DO
-
-      DO jk = 1, jpkm1
-        DO jj = 1, jpj
-          DO ji = 1, jpi
-            fsp(ji,jj,jk) = zrhh(ji,jj,jk)
-            xsp(ji,jj,jk) = zdeptht(ji,jj,jk)
-          END DO
-        END DO
-      END DO
+      ! Transfer the depth of "T(:,:,:)" to vertical coordinate "zdept(:,:,:)"
+      DO jj = 1, jpj;   DO ji = 1, jpi
+          zdept(ji,jj,1) = 0.5_wp * fse3w(ji,jj,1) - sshn(ji,jj) * znad
+      END DO        ;   END DO
+
+      DO jk = 2, jpk;   DO jj = 1, jpj;   DO ji = 1, jpi
+          zdept(ji,jj,jk) = zdept(ji,jj,jk-1) + fse3w(ji,jj,jk)
+      END DO        ;   END DO        ;   END DO
+
+      fsp(:,:,:) = zrhh(:,:,:)
+      xsp(:,:,:) = zdept(:,:,:)
 
       ! Construct the vertical density profile with the 
@@ -745,8 +736,7 @@
       DO jj = 2, jpj
         DO ji = 2, jpi 
-          zrhdt1 = zrhh(ji,jj,1) - interp3(zdeptht(ji,jj,1),asp(ji,jj,1), &
+          zrhdt1 = zrhh(ji,jj,1) - interp3(zdept(ji,jj,1),asp(ji,jj,1), &
                                          bsp(ji,jj,1),   csp(ji,jj,1), &
-                                         dsp(ji,jj,1) ) * 0.5_wp * zdeptht(ji,jj,1)
-          zrhdt1 = MAX(zrhdt1, 1000._wp - rau0)        ! no lighter than fresh water
+                                         dsp(ji,jj,1) ) * 0.25_wp * fse3w(ji,jj,1)
 
           ! assuming linear profile across the top half surface layer
@@ -760,5 +750,5 @@
           DO ji = 2, jpi
             zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) +                          &
-                             integ2(zdeptht(ji,jj,jk-1), zdeptht(ji,jj,jk),&
+                             integ_spline(zdept(ji,jj,jk-1), zdept(ji,jj,jk),&
                                     asp(ji,jj,jk-1),    bsp(ji,jj,jk-1), &
                                     csp(ji,jj,jk-1),    dsp(ji,jj,jk-1))
@@ -793,4 +783,16 @@
       END DO
 
+      DO jk = 1, jpkm1
+        DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+            zu(ji,jj,jk) = min(zu(ji,jj,jk), max(-zdept(ji,jj,jk), -zdept(ji+1,jj,jk)))
+            zu(ji,jj,jk) = max(zu(ji,jj,jk), min(-zdept(ji,jj,jk), -zdept(ji+1,jj,jk)))
+            zv(ji,jj,jk) = min(zv(ji,jj,jk), max(-zdept(ji,jj,jk), -zdept(ji,jj+1,jk)))
+            zv(ji,jj,jk) = max(zv(ji,jj,jk), min(-zdept(ji,jj,jk), -zdept(ji,jj+1,jk)))
+          END DO
+        END DO
+      END DO
+
+
       DO jk = 1, jpkm1                                  
         DO jj = 2, jpjm1     
@@ -803,5 +805,5 @@
             !!!!!     for u equation
             IF( jk <= mbku(ji,jj) ) THEN
-               IF( -zdeptht(ji+1,jj,mbku(ji,jj)) >= -zdeptht(ji,jj,mbku(ji,jj)) ) THEN
+               IF( -zdept(ji+1,jj,jk) >= -zdept(ji,jj,jk) ) THEN
                  jis = ji + 1; jid = ji
                ELSE
@@ -811,13 +813,12 @@
                ! integrate the pressure on the shallow side
                jk1 = jk 
-               zbhitwe = 0
-               DO WHILE ( -zdeptht(jis,jj,jk1) > zuijk )
+               DO WHILE ( -zdept(jis,jj,jk1) > zuijk )
                  IF( jk1 == mbku(ji,jj) ) THEN
-                   zbhitwe = 1
+                   zuijk = -zdept(jis,jj,jk1)
                    EXIT
                  ENDIF
-                 zdeps = MIN(zdeptht(jis,jj,jk1+1), -zuijk)
+                 zdeps = MIN(zdept(jis,jj,jk1+1), -zuijk)
                  zpwes = zpwes +                                    & 
-                      integ2(zdeptht(jis,jj,jk1), zdeps,            &
+                      integ_spline(zdept(jis,jj,jk1), zdeps,            &
                              asp(jis,jj,jk1),    bsp(jis,jj,jk1), &
                              csp(jis,jj,jk1),    dsp(jis,jj,jk1))
@@ -825,19 +826,18 @@
                END DO
             
-               IF(zbhitwe == 1) THEN
-                 zuijk = -zdeptht(jis,jj,jk1)
-               ENDIF
-
                ! integrate the pressure on the deep side
                jk1 = jk 
-               zbhitwe = 0
-               DO WHILE ( -zdeptht(jid,jj,jk1) < zuijk )
+               DO WHILE ( -zdept(jid,jj,jk1) < zuijk )
                  IF( jk1 == 1 ) THEN
-                   zbhitwe = 1
+                   zdeps = zdept(jid,jj,1) + MIN(zuijk, sshn(jid,jj)*znad)
+                   zrhdt1 = zrhh(jid,jj,1) - interp3(zdept(jid,jj,1), asp(jid,jj,1), &
+                                                     bsp(jid,jj,1),   csp(jid,jj,1), &
+                                                     dsp(jid,jj,1)) * zdeps
+                   zpwed  = zpwed + 0.5_wp * (zrhh(jid,jj,1) + zrhdt1) * zdeps
                    EXIT
                  ENDIF
-                 zdeps = MAX(zdeptht(jid,jj,jk1-1), -zuijk)
+                 zdeps = MAX(zdept(jid,jj,jk1-1), -zuijk)
                  zpwed = zpwed +                                        & 
-                        integ2(zdeps,              zdeptht(jid,jj,jk1), &
+                        integ_spline(zdeps,              zdept(jid,jj,jk1), &
                                asp(jid,jj,jk1-1), bsp(jid,jj,jk1-1),  &
                                csp(jid,jj,jk1-1), dsp(jid,jj,jk1-1) )
@@ -845,13 +845,4 @@
                END DO
             
-               IF( zbhitwe == 1 ) THEN
-                 zdeps = zdeptht(jid,jj,1) + MIN(zuijk, sshn(jid,jj)*znad)
-                 zrhdt1 = zrhh(jid,jj,1) - interp3(zdeptht(jid,jj,1), asp(jid,jj,1), &
-                                                 bsp(jid,jj,1),    csp(jid,jj,1), &
-                                                 dsp(jid,jj,1)) * zdeps
-                 zrhdt1 = MAX(zrhdt1, 1000._wp - rau0)        ! no lighter than fresh water
-                 zpwed  = zpwed + 0.5_wp * (zrhh(jid,jj,1) + zrhdt1) * zdeps
-               ENDIF
-
                ! update the momentum trends in u direction
 
@@ -870,5 +861,5 @@
             !!!!!     for v equation
             IF( jk <= mbkv(ji,jj) ) THEN
-               IF( -zdeptht(ji,jj+1,mbkv(ji,jj)) >= -zdeptht(ji,jj,mbkv(ji,jj)) ) THEN
+               IF( -zdept(ji,jj+1,jk) >= -zdept(ji,jj,jk) ) THEN
                  jjs = jj + 1; jjd = jj
                ELSE
@@ -878,13 +869,12 @@
                ! integrate the pressure on the shallow side
                jk1 = jk 
-               zbhitns = 0
-               DO WHILE ( -zdeptht(ji,jjs,jk1) > zvijk )
+               DO WHILE ( -zdept(ji,jjs,jk1) > zvijk )
                  IF( jk1 == mbkv(ji,jj) ) THEN
-                   zbhitns = 1
+                   zvijk = -zdept(ji,jjs,jk1)
                    EXIT
                  ENDIF
-                 zdeps = MIN(zdeptht(ji,jjs,jk1+1), -zvijk)
+                 zdeps = MIN(zdept(ji,jjs,jk1+1), -zvijk)
                  zpnss = zpnss +                                      & 
-                        integ2(zdeptht(ji,jjs,jk1), zdeps,            &
+                        integ_spline(zdept(ji,jjs,jk1), zdeps,            &
                                asp(ji,jjs,jk1),    bsp(ji,jjs,jk1), &
                                csp(ji,jjs,jk1),    dsp(ji,jjs,jk1) )
@@ -892,19 +882,18 @@
                END DO
             
-               IF(zbhitns == 1) THEN
-                 zvijk = -zdeptht(ji,jjs,jk1)
-               ENDIF
-
                ! integrate the pressure on the deep side
                jk1 = jk 
-               zbhitns = 0
-               DO WHILE ( -zdeptht(ji,jjd,jk1) < zvijk )
+               DO WHILE ( -zdept(ji,jjd,jk1) < zvijk )
                  IF( jk1 == 1 ) THEN
-                   zbhitns = 1
+                   zdeps = zdept(ji,jjd,1) + MIN(zvijk, sshn(ji,jjd)*znad)
+                   zrhdt1 = zrhh(ji,jjd,1) - interp3(zdept(ji,jjd,1), asp(ji,jjd,1), &
+                                                     bsp(ji,jjd,1),   csp(ji,jjd,1), &
+                                                     dsp(ji,jjd,1) ) * zdeps
+                   zpnsd  = zpnsd + 0.5_wp * (zrhh(ji,jjd,1) + zrhdt1) * zdeps
                    EXIT
                  ENDIF
-                 zdeps = MAX(zdeptht(ji,jjd,jk1-1), -zvijk)
+                 zdeps = MAX(zdept(ji,jjd,jk1-1), -zvijk)
                  zpnsd = zpnsd +                                        & 
-                        integ2(zdeps,              zdeptht(ji,jjd,jk1), &
+                        integ_spline(zdeps,              zdept(ji,jjd,jk1), &
                                asp(ji,jjd,jk1-1), bsp(ji,jjd,jk1-1), &
                                csp(ji,jjd,jk1-1), dsp(ji,jjd,jk1-1) )
@@ -912,12 +901,4 @@
                END DO
             
-               IF( zbhitns == 1 ) THEN
-                 zdeps = zdeptht(ji,jjd,1) + MIN(zvijk, sshn(ji,jjd)*znad)
-                 zrhdt1 = zrhh(ji,jjd,1) - interp3(zdeptht(ji,jjd,1), asp(ji,jjd,1), &
-                                                 bsp(ji,jjd,1),    csp(ji,jjd,1), &
-                                                 dsp(ji,jjd,1) ) * zdeps
-                 zrhdt1 = MAX(zrhdt1, 1000._wp - rau0)        ! no lighter than fresh water
-                 zpnsd  = zpnsd + 0.5_wp * (zrhh(ji,jjd,1) + zrhdt1) * zdeps
-               ENDIF
 
                ! update the momentum trends in v direction
@@ -941,5 +922,5 @@
       !
       CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp ) 
-      CALL wrk_dealloc( jpi,jpj,jpk, zdeptht, zrhh ) 
+      CALL wrk_dealloc( jpi,jpj,jpk, zdept, zrhh ) 
       !
    END SUBROUTINE hpg_prj
@@ -1121,5 +1102,5 @@
 
    
-   FUNCTION integ2(xl, xr, a, b, c, d)  RESULT(f) 
+   FUNCTION integ_spline(xl, xr, a, b, c, d)  RESULT(f) 
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE interp1  ***
@@ -1143,7 +1124,8 @@
          & xl * ( a + xl * ( za1 + xl * ( za2 + za3 * xl ) ) )
 
-   END FUNCTION integ2
+   END FUNCTION integ_spline
 
 
    !!======================================================================
 END MODULE dynhpg
+
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 3632)
@@ -81,10 +81,6 @@
    END INTERFACE
    INTERFACE mpp_sum
-# if defined key_mpp_rep
       MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real, &
                        mppsum_realdd, mppsum_a_realdd
-# else
-      MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real
-# endif
    END INTERFACE
    INTERFACE mpp_lbc_north
@@ -115,7 +111,5 @@
 !$AGRIF_END_DO_NOT_TREAT
 
-# if defined key_mpp_rep
    INTEGER :: MPI_SUMDD
-# endif
 
    ! variables used in case of sea-ice
@@ -350,7 +344,5 @@
       mynode = mpprank
       ! 
-#if defined key_mpp_rep
       CALL MPI_OP_CREATE(DDPDD_MPI, .TRUE., MPI_SUMDD, ierr)
-#endif
       !
    END FUNCTION mynode
@@ -1508,5 +1500,4 @@
    END SUBROUTINE mppsum_real
 
-# if defined key_mpp_rep
    SUBROUTINE mppsum_realdd( ytab, kcom )
       !!----------------------------------------------------------------------
@@ -1561,5 +1552,4 @@
 
    END SUBROUTINE mppsum_a_realdd
-# endif   
    
    SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki,kj )
@@ -2604,5 +2594,4 @@
    END SUBROUTINE mpi_init_opa
 
-#if defined key_mpp_rep
    SUBROUTINE DDPDD_MPI (ydda, yddb, ilen, itype)
       !!---------------------------------------------------------------------
@@ -2633,5 +2622,4 @@
 
    END SUBROUTINE DDPDD_MPI
-#endif
 
 #else
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 3632)
@@ -723,5 +723,4 @@
                !                                                       ! (geographical to local grid -> rotate the components)
                CALL rot_rep( frcv(jpr_otx1)%z3(:,:,1), frcv(jpr_oty1)%z3(:,:,1), srcv(jpr_otx1)%clgrid, 'en->i', ztx )   
-               frcv(jpr_otx1)%z3(:,:,1) = ztx(:,:)      ! overwrite 1st component on the 1st grid
                IF( srcv(jpr_otx2)%laction ) THEN
                   CALL rot_rep( frcv(jpr_otx2)%z3(:,:,1), frcv(jpr_oty2)%z3(:,:,1), srcv(jpr_otx2)%clgrid, 'en->j', zty )   
@@ -729,4 +728,5 @@
                   CALL rot_rep( frcv(jpr_otx1)%z3(:,:,1), frcv(jpr_oty1)%z3(:,:,1), srcv(jpr_otx1)%clgrid, 'en->j', zty )  
                ENDIF
+               frcv(jpr_otx1)%z3(:,:,1) = ztx(:,:)      ! overwrite 1st component on the 1st grid
                frcv(jpr_oty1)%z3(:,:,1) = zty(:,:)      ! overwrite 2nd component on the 2nd grid
             ENDIF
@@ -953,5 +953,4 @@
                !                                                       ! (geographical to local grid -> rotate the components)
                CALL rot_rep( frcv(jpr_itx1)%z3(:,:,1), frcv(jpr_ity1)%z3(:,:,1), srcv(jpr_itx1)%clgrid, 'en->i', ztx )   
-               frcv(jpr_itx1)%z3(:,:,1) = ztx(:,:)      ! overwrite 1st component on the 1st grid
                IF( srcv(jpr_itx2)%laction ) THEN
                   CALL rot_rep( frcv(jpr_itx2)%z3(:,:,1), frcv(jpr_ity2)%z3(:,:,1), srcv(jpr_itx2)%clgrid, 'en->j', zty )   
@@ -959,4 +958,5 @@
                   CALL rot_rep( frcv(jpr_itx1)%z3(:,:,1), frcv(jpr_ity1)%z3(:,:,1), srcv(jpr_itx1)%clgrid, 'en->j', zty )  
                ENDIF
+               frcv(jpr_itx1)%z3(:,:,1) = ztx(:,:)      ! overwrite 1st component on the 1st grid
                frcv(jpr_ity1)%z3(:,:,1) = zty(:,:)      ! overwrite 2nd component on the 1st grid
             ENDIF
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 3632)
@@ -289,25 +289,22 @@
       !                                            !==  Misc. Options  ==!
       
-      SELECT CASE( nn_ice )                                     ! Update heat and freshwater fluxes over sea-ice areas
-      CASE(  1 )   ;       CALL sbc_ice_if   ( kt )                  ! Ice-cover climatology ("Ice-if" model)
-         !                                                      
-      CASE(  2 )   ;       CALL sbc_ice_lim_2( kt, nsbc )            ! LIM-2 ice model
-         IF( lk_bdy )      CALL bdy_ice_lim_2( kt )                  ! BDY boundary condition
-         !                                                     
-      CASE(  3 )   ;       CALL sbc_ice_lim  ( kt, nsbc )            ! LIM-3 ice model
-         !
-      CASE(  4 )   ;       CALL sbc_ice_cice ( kt, nsbc )            ! CICE ice model
+      SELECT CASE( nn_ice )                                       ! Update heat and freshwater fluxes over sea-ice areas
+      CASE(  1 )   ;         CALL sbc_ice_if   ( kt )                ! Ice-cover climatology ("Ice-if" model)
+      CASE(  2 )   ;         CALL sbc_ice_lim_2( kt, nsbc )          ! LIM-2 ice model
+              IF( lk_bdy )   CALL bdy_ice_lim_2( kt )                ! BDY boundary condition
+      CASE(  3 )   ;         CALL sbc_ice_lim  ( kt, nsbc )          ! LIM-3 ice model
+      CASE(  4 )   ;         CALL sbc_ice_cice ( kt, nsbc )          ! CICE ice model
       END SELECT                                              
 
-      IF( ln_icebergs )    CALL icb_stp( kt )                   ! compute icebergs
-
-      IF( ln_rnf       )   CALL sbc_rnf( kt )                   ! add runoffs to fresh water fluxes
+      IF( ln_icebergs    )   CALL icb_stp( kt )                   ! compute icebergs
+
+      IF( ln_rnf         )   CALL sbc_rnf( kt )                   ! add runoffs to fresh water fluxes
  
-      IF( ln_ssr       )   CALL sbc_ssr( kt )                   ! add SST/SSS damping term
-
-      IF( nn_fwb  /= 0 )   CALL sbc_fwb( kt, nn_fwb, nn_fsbc )  ! control the freshwater budget
-
-      IF( nclosea == 1 )   CALL sbc_clo( kt )                   ! treatment of closed sea in the model domain 
-      !                                                         ! (update freshwater fluxes)
+      IF( ln_ssr         )   CALL sbc_ssr( kt )                   ! add SST/SSS damping term
+
+      IF( nn_fwb    /= 0 )   CALL sbc_fwb( kt, nn_fwb, nn_fsbc )  ! control the freshwater budget
+
+      IF( nn_closea == 1 )   CALL sbc_clo( kt )                   ! treatment of closed sea in the model domain 
+      !                                                           ! (update freshwater fluxes)
 !RBbug do not understand why see ticket 667
       CALL lbc_lnk( emp, 'T', 1. )
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 3632)
@@ -453,7 +453,7 @@
       CALL iom_close( inum )                                      ! close file
       !
-      IF( nclosea == 1 )    CALL clo_rnf( rnfmsk )                ! closed sea inflow set as ruver mouth
-      !
-      rnfmsk_z(:)   = 0._wp                                        ! vertical structure 
+      IF( nn_closea == 1 )   CALL clo_rnf( rnfmsk )               ! closed sea inflow set as ruver mouth
+      !
+      rnfmsk_z(:)   = 0._wp                                       ! vertical structure 
       rnfmsk_z(1)   = 1.0
       rnfmsk_z(2)   = 1.0                                         ! **********
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso_grif.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso_grif.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso_grif.F90	(revision 3632)
@@ -225,6 +225,6 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1  ! vector opt.
-                  zw3d(ji,jj,jk) = (psiy_eiv(ji,jj,jk) - psiy_eiv(ji,jj-1,jk))/e2v(ji,jj) + &
-                       &    (psix_eiv(ji,jj,jk) - psix_eiv(ji-1,jj,jk))/e1u(ji,jj) ! w_eiv = dpsiy/dy + dpsiy/dx
+                  zw3d(ji,jj,jk) = (psiy_eiv(ji,jj,jk) - psiy_eiv(ji,jj-1,jk))/e2t(ji,jj) + &
+                       &    (psix_eiv(ji,jj,jk) - psix_eiv(ji-1,jj,jk))/e1t(ji,jj) ! w_eiv = dpsiy/dy + dpsiy/dx
                END DO
             END DO
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 3632)
@@ -8,5 +8,5 @@
    !!            3.3  !  2010-06  (C. Ethe) merge TRA-TRC 
    !!----------------------------------------------------------------------
-#if  defined key_trdtra || defined key_trdmld || defined key_trdmld_trc 
+#if  defined key_trdtra || defined key_trdtrc || defined key_trdmld || defined key_trdmld_trc 
    !!----------------------------------------------------------------------
    !!   trd_tra      : Call the trend to be computed
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 3632)
@@ -88,4 +88,6 @@
    REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   htau           ! depth of tke penetration (nn_htau)
    REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dissl          ! now mixing lenght of dissipation
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   avt_k , avm_k  ! not enhanced Kz
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   avmu_k, avmv_k ! not enhanced Kz
 #if defined key_c1d
    !                                                                        !!** 1D cfg only  **   ('key_c1d')
@@ -113,5 +115,7 @@
          &      e_pdl(jpi,jpj,jpk) , e_ric(jpi,jpj,jpk) ,                          &
 #endif
-         &      en   (jpi,jpj,jpk) , htau (jpi,jpj)     , dissl(jpi,jpj,jpk) , STAT= zdf_tke_alloc )
+         &      en    (jpi,jpj,jpk) , htau  (jpi,jpj)    , dissl(jpi,jpj,jpk) ,     & 
+         &      avt_k (jpi,jpj,jpk) , avm_k (jpi,jpj,jpk),                          &
+         &      avmu_k(jpi,jpj,jpk) , avmv_k(jpi,jpj,jpk), STAT= zdf_tke_alloc      )
          !
       IF( lk_mpp             )   CALL mpp_sum ( zdf_tke_alloc )
@@ -169,7 +173,19 @@
       !!----------------------------------------------------------------------
       !
+      IF( kt /= nit000 ) THEN   ! restore before value to compute tke
+         avt (:,:,:) = avt_k (:,:,:) 
+         avm (:,:,:) = avm_k (:,:,:) 
+         avmu(:,:,:) = avmu_k(:,:,:) 
+         avmv(:,:,:) = avmv_k(:,:,:) 
+      ENDIF 
+      !
       CALL tke_tke      ! now tke (en)
       !
       CALL tke_avn      ! now avt, avm, avmu, avmv
+      !
+      avt_k (:,:,:) = avt (:,:,:) 
+      avm_k (:,:,:) = avm (:,:,:) 
+      avmu_k(:,:,:) = avmu(:,:,:) 
+      avmv_k(:,:,:) = avmv(:,:,:) 
       !
    END SUBROUTINE zdf_tke
@@ -812,10 +828,10 @@
         !                                   ! -------------------
         IF(lwp) WRITE(numout,*) '---- tke-rst ----'
-        CALL iom_rstput( kt, nitrst, numrow, 'en'   , en    )
-        CALL iom_rstput( kt, nitrst, numrow, 'avt'  , avt   )
-        CALL iom_rstput( kt, nitrst, numrow, 'avm'  , avm   )
-        CALL iom_rstput( kt, nitrst, numrow, 'avmu' , avmu  )
-        CALL iom_rstput( kt, nitrst, numrow, 'avmv' , avmv  )
-        CALL iom_rstput( kt, nitrst, numrow, 'dissl', dissl )
+        CALL iom_rstput( kt, nitrst, numrow, 'en'   , en     )
+        CALL iom_rstput( kt, nitrst, numrow, 'avt'  , avt_k  )
+        CALL iom_rstput( kt, nitrst, numrow, 'avm'  , avm_k  )
+        CALL iom_rstput( kt, nitrst, numrow, 'avmu' , avmu_k )
+        CALL iom_rstput( kt, nitrst, numrow, 'avmv' , avmv_k )
+        CALL iom_rstput( kt, nitrst, numrow, 'dissl', dissl  )
         !
      ENDIF
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/lib_fortran.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/lib_fortran.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/OPA_SRC/lib_fortran.F90	(revision 3632)
@@ -14,13 +14,14 @@
    !!                 of intrinsinc sign function
    !!----------------------------------------------------------------------
-   USE par_oce          ! Ocean parameter
-   USE lib_mpp          ! distributed memory computing
-   USE dom_oce          ! ocean domain
-   USE in_out_manager   ! I/O manager
+   USE par_oce         ! Ocean parameter
+   USE dom_oce         ! ocean domain
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC glob_sum
+   PUBLIC   glob_sum   ! used in many places
+   PUBLIC   DDPDD      ! also used in closea module
 #if defined key_nosignedzero
    PUBLIC SIGN
@@ -47,4 +48,5 @@
 
 #if ! defined key_mpp_rep
+
    FUNCTION glob_sum_2d( ptab ) 
       !!-----------------------------------------------------------------------
@@ -246,4 +248,5 @@
    END FUNCTION glob_sum_3d_a   
 
+#endif
 
    SUBROUTINE DDPDD( ydda, yddb )
@@ -280,5 +283,4 @@
       !
    END SUBROUTINE DDPDD
-#endif
 
 #if defined key_nosignedzero
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/TOP_SRC/PISCES/p4zsink.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/TOP_SRC/PISCES/p4zsink.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/TOP_SRC/PISCES/p4zsink.F90	(revision 3632)
@@ -296,5 +296,5 @@
       ENDIF
       !
-      CALL wrk_alloc( jpi, jpj, jpk, znum3d )
+      CALL wrk_dealloc( jpi, jpj, jpk, znum3d )
       !
       IF( nn_timing == 1 )  CALL timing_stop('p4z_sink')
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 3632)
@@ -101,5 +101,5 @@
       END SELECT
 
-      IF( l_trdtra )   THEN                      ! save the vertical diffusive trends for further diagnostics
+      IF( l_trdtrc )   THEN                      ! save the vertical diffusive trends for further diagnostics
          DO jn = 1, jptra
             DO jk = 1, jpkm1
Index: branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc.F90
===================================================================
--- branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc.F90	(revision 3631)
+++ branches/2012/dev_NOC_2012_rev3555/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc.F90	(revision 3632)
@@ -59,4 +59,5 @@
       ! Mixed layer trends for passive tracers
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+#if defined key_trdmld_trc  
       IF( lk_trdmld_trc .AND. ln_trdtrc( kjn ) ) THEN
          !
@@ -82,17 +83,23 @@
          !
       END IF
+#endif
 
       IF( lk_trdtrc .AND. ln_trdtrc( kjn ) ) THEN
          !
          SELECT CASE( ktrd )
-         CASE( jptra_trd_xad )       ;    WRITE (cltra,'("XAD_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_yad )       ;    WRITE (cltra,'("YAD_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_zad )       ;    WRITE (cltra,'("ZAD_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_ldf )       ;    WRITE (cltra,'("LDF_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_bbl )       ;    WRITE (cltra,'("BBL_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_zdf )       ;    WRITE (cltra,'("ZDF_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_dmp )       ;    WRITE (cltra,'("DMP_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_nsr )       ;    WRITE (cltra,'("FOR_",16a)')   ctrcnm(kjn)
+         CASE( jptra_trd_xad  )       ;    WRITE (cltra,'("XAD_",4a)')
+         CASE( jptra_trd_yad  )       ;    WRITE (cltra,'("YAD_",4a)')
+         CASE( jptra_trd_zad  )       ;    WRITE (cltra,'("ZAD_",4a)')
+         CASE( jptra_trd_ldf  )       ;    WRITE (cltra,'("LDF_",4a)')
+         CASE( jptra_trd_bbl  )       ;    WRITE (cltra,'("BBL_",4a)')
+         CASE( jptra_trd_nsr  )       ;    WRITE (cltra,'("FOR_",4a)')
+         CASE( jptra_trd_zdf  )       ;    WRITE (cltra,'("ZDF_",4a)')
+         CASE( jptra_trd_dmp  )       ;    WRITE (cltra,'("DMP_",4a)')
+         CASE( jptra_trd_sms  )       ;    WRITE (cltra,'("SMS_",4a)')
+         CASE( jptra_trd_atf  )       ;    WRITE (cltra,'("ATF_",4a)')
+         CASE( jptra_trd_radb )       ;    WRITE (cltra,'("RDB_",4a)')
+         CASE( jptra_trd_radn )       ;    WRITE (cltra,'("RDN_",4a)')
          END SELECT
+                                          cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
                                           CALL iom_put( cltra,  ptrtrd(:,:,:) )
          !
@@ -111,5 +118,7 @@
       !!----------------------------------------------------------------------
 
+#if defined key_trdmld_trc  
       CALL trd_mld_bio_zint( ptrbio, ktrd ) ! Verticaly integrated biological trends
+#endif
 
    END SUBROUTINE trd_mod_trc_bio
