Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 6667)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 6717)
@@ -17,17 +17,19 @@
    !!            3.2  ! 2009-07  (R. Benshila) Suppression of rigid-lid option
    !!            3.6  ! 2015-05  (P. Mathiot) ISF: add wmask,wumask and wvmask
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dom_msk        : compute land/ocean mask
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
+   !!            4.0  ! 2016-06  (G. Madec, S. Flavoni)  domain configuration / user defined interface
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dom_msk       : compute land/ocean mask
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE usrdef_fmask   ! user defined fmask
    !
-   USE in_out_manager  ! I/O manager
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         !
-   USE wrk_nemo        ! Memory allocation
-   USE timing          ! Timing
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp        ! Massively Parallel Processing library
+   USE wrk_nemo       ! Memory allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -73,10 +75,5 @@
       !!                as MPP halos.
       !!      tmask_h : halo mask at t-point, i.e. excluding duplicated rows/lines
-      !!                due to cyclic or North Fold boundaries as well
-      !!                as MPP halos.
-      !!
-      !!      In case of open boundaries (lk_bdy=T):
-      !!        - tmask is set to 1 on the points to be computed by the open
-      !!          boundaries routines.
+      !!                due to cyclic or North Fold boundaries as well as MPP halos.
       !!
       !! ** Action :   tmask, umask, vmask, wmask, wumask, wvmask : land/ocean mask 
@@ -90,11 +87,10 @@
       INTEGER, DIMENSION(:,:), INTENT(in) ::   k_top, k_bot   ! first and last ocean level
       !
-      INTEGER  ::   ji, jj, jk               ! dummy loop indices
-      INTEGER  ::   iif, iil, ii0, ii1, ii   ! local integers
-      INTEGER  ::   ijf, ijl, ij0, ij1       !   -       -
-      INTEGER  ::   iktop, ikbot             !   -       -
+      INTEGER  ::   ji, jj, jk     ! dummy loop indices
+      INTEGER  ::   iif, iil       ! local integers
+      INTEGER  ::   ijf, ijl       !   -       -
+      INTEGER  ::   iktop, ikbot   !   -       -
       INTEGER  ::   ios
-      INTEGER  ::   isrow                    ! index for ORCA1 starting row
-      REAL(wp), POINTER, DIMENSION(:,:) ::  zwf
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zwf   ! 2D workspace
       !!
       NAMELIST/namlbc/ rn_shlat, ln_vorlat
@@ -144,10 +140,44 @@
       END DO  
 
-      ! 2D ocean mask (=1 if at least one level of the water column is ocean, =0 otherwise)
-      WHERE( k_bot(:,:) > 0 )   ;   ssmask(:,:) = 1._wp
-      ELSEWHERE                 ;   ssmask(:,:) = 0._wp
-      END WHERE
       
-      
+      !  Ocean/land mask at u-, v-, and f-points   (computed from tmask)
+      ! ----------------------------------------
+      ! NB: at this point, fmask is designed for free slip lateral boundary condition
+      DO jk = 1, jpk
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector loop
+               umask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji+1,jj  ,jk)
+               vmask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji  ,jj+1,jk)
+            END DO
+            DO ji = 1, jpim1      ! NO vector opt.
+               fmask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji+1,jj  ,jk)   &
+                  &            * tmask(ji,jj+1,jk) * tmask(ji+1,jj+1,jk)
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( umask  , 'U', 1._wp )      ! Lateral boundary conditions
+      CALL lbc_lnk( vmask  , 'V', 1._wp )
+      CALL lbc_lnk( fmask  , 'F', 1._wp )
+
+ 
+      ! Ocean/land mask at wu-, wv- and w points    (computed from tmask)
+      !-----------------------------------------
+      wmask (:,:,1) = tmask(:,:,1)     ! surface
+      wumask(:,:,1) = umask(:,:,1)
+      wvmask(:,:,1) = vmask(:,:,1)
+      DO jk = 2, jpk                   ! interior values
+         wmask (:,:,jk) = tmask(:,:,jk) * tmask(:,:,jk-1)
+         wumask(:,:,jk) = umask(:,:,jk) * umask(:,:,jk-1)   
+         wvmask(:,:,jk) = vmask(:,:,jk) * vmask(:,:,jk-1)
+      END DO
+
+
+      ! Ocean/land column mask at t-, u-, and v-points   (i.e. at least 1 wet cell in the vertical)
+      ! ----------------------------------------------
+      ssmask (:,:) = MAXVAL( tmask(:,:,:), DIM=3 )
+      ssumask(:,:) = MAXVAL( umask(:,:,:), DIM=3 )
+      ssvmask(:,:) = MAXVAL( vmask(:,:,:), DIM=3 )
+
+
       ! Interior domain mask  (used for global sum)
       ! --------------------
@@ -185,168 +215,51 @@
 
 
-      !  Ocean/land mask at u-, v-, and z-points (computed from tmask)
-      ! ----------------------------------------
-      DO jk = 1, jpk
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector loop
-               umask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji+1,jj  ,jk)
-               vmask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji  ,jj+1,jk)
-            END DO
-            DO ji = 1, jpim1      ! NO vector opt.
-               fmask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji+1,jj  ,jk)   &
-                  &            * tmask(ji,jj+1,jk) * tmask(ji+1,jj+1,jk)
+      ! Lateral boundary conditions on velocity (modify fmask)
+      ! ---------------------------------------  
+      IF( rn_shlat /= 0 ) THEN      ! Not free-slip lateral boundary condition
+         !
+         CALL wrk_alloc( jpi,jpj,   zwf )
+         !
+         DO jk = 1, jpk
+            zwf(:,:) = fmask(:,:,jk)         
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  IF( fmask(ji,jj,jk) == 0._wp ) THEN
+                     fmask(ji,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,jj), zwf(ji,jj+1),   &
+                        &                                           zwf(ji-1,jj), zwf(ji,jj-1)  )  )
+                  ENDIF
+               END DO
+            END DO
+            DO jj = 2, jpjm1
+               IF( fmask(1,jj,jk) == 0._wp ) THEN
+                  fmask(1  ,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(2,jj), zwf(1,jj+1), zwf(1,jj-1) ) )
+               ENDIF
+               IF( fmask(jpi,jj,jk) == 0._wp ) THEN
+                  fmask(jpi,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(jpi,jj+1), zwf(jpim1,jj), zwf(jpi,jj-1) ) )
+               ENDIF
+            END DO         
+            DO ji = 2, jpim1
+               IF( fmask(ji,1,jk) == 0._wp ) THEN
+                  fmask(ji, 1 ,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,1), zwf(ji,2), zwf(ji-1,1) ) )
+               ENDIF
+               IF( fmask(ji,jpj,jk) == 0._wp ) THEN
+                  fmask(ji,jpj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,jpj), zwf(ji-1,jpj), zwf(ji,jpjm1) ) )
+               ENDIF
             END DO
          END DO
-      END DO
-      ! (ISF) MIN(1,SUM(umask)) is here to check if you have effectively at least 1 wet cell at u point
-      DO jj = 1, jpjm1
-         DO ji = 1, fs_jpim1   ! vector loop
-!!gm  simpler :
-!            ssumask(ji,jj)  = MIN(  1._wp , SUM( umask(ji,jj,:) )  )
-!            ssvmask(ji,jj)  = MIN(  1._wp , SUM( vmask(ji,jj,:) )  )
-!!gm
-!!gm  faster :
-!         ssumask(ji,jj) = ssmask(ji,jj) * tmask(ji+1,jj  )
-!         ssvmask(ji,jj) = ssmask(ji,jj) * tmask(ji  ,jj+1)
-!!gm
-            ssumask(ji,jj)  = ssmask(ji,jj) * ssmask(ji+1,jj  )  * MIN(1._wp,SUM(umask(ji,jj,:)))
-            ssvmask(ji,jj)  = ssmask(ji,jj) * ssmask(ji  ,jj+1)  * MIN(1._wp,SUM(vmask(ji,jj,:)))
-!!end
-         END DO
-         DO ji = 1, jpim1      ! NO vector opt.
-!!gm faster
-!            ssfmask(ji,jj) =  ssmask(ji,jj  ) * ssmask(ji+1,jj  )   &
-!               &            * ssmask(ji,jj+1) * ssmask(ji+1,jj+1)
-!!gm 
-            ssfmask(ji,jj) =  ssmask(ji,jj  ) * ssmask(ji+1,jj  )   &
-               &            * ssmask(ji,jj+1) * ssmask(ji+1,jj+1) * MIN(1._wp,SUM(fmask(ji,jj,:)))
-!!gm
-         END DO
-      END DO
-      CALL lbc_lnk( umask  , 'U', 1._wp )      ! Lateral boundary conditions
-      CALL lbc_lnk( vmask  , 'V', 1._wp )
-!      CALL lbc_lnk( fmask  , 'F', 1._wp )         ! applied after the specification of lateral b.c.
-      CALL lbc_lnk( ssumask, 'U', 1._wp )
-      CALL lbc_lnk( ssvmask, 'V', 1._wp )
-      CALL lbc_lnk( ssfmask, 'F', 1._wp )
-
-
-      ! Ocean/land mask at wu-, wv- and w points 
-      !----------------------------------------------
-      wmask (:,:,1) = tmask(:,:,1)     ! surface
-      wumask(:,:,1) = umask(:,:,1)
-      wvmask(:,:,1) = vmask(:,:,1)
-      DO jk = 2, jpk                   ! interior values
-         wmask (:,:,jk) = tmask(:,:,jk) * tmask(:,:,jk-1)
-         wumask(:,:,jk) = umask(:,:,jk) * umask(:,:,jk-1)   
-         wvmask(:,:,jk) = vmask(:,:,jk) * vmask(:,:,jk-1)
-      END DO
-
-
-      ! Lateral boundary conditions on velocity (modify fmask)
-      ! ---------------------------------------     
-      CALL wrk_alloc( jpi,jpj,   zwf  )
-      !
-      DO jk = 1, jpk
-         zwf(:,:) = fmask(:,:,jk)         
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               IF( fmask(ji,jj,jk) == 0._wp ) THEN
-                  fmask(ji,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,jj), zwf(ji,jj+1),   &
-                     &                                           zwf(ji-1,jj), zwf(ji,jj-1)  )  )
-               ENDIF
-            END DO
-         END DO
-         DO jj = 2, jpjm1
-            IF( fmask(1,jj,jk) == 0._wp ) THEN
-               fmask(1  ,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(2,jj), zwf(1,jj+1), zwf(1,jj-1) ) )
-            ENDIF
-            IF( fmask(jpi,jj,jk) == 0._wp ) THEN
-               fmask(jpi,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(jpi,jj+1), zwf(jpim1,jj), zwf(jpi,jj-1) ) )
-            ENDIF
-         END DO         
-         DO ji = 2, jpim1
-            IF( fmask(ji,1,jk) == 0._wp ) THEN
-               fmask(ji, 1 ,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,1), zwf(ji,2), zwf(ji-1,1) ) )
-            ENDIF
-            IF( fmask(ji,jpj,jk) == 0._wp ) THEN
-               fmask(ji,jpj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,jpj), zwf(ji-1,jpj), zwf(ji,jpjm1) ) )
-            ENDIF
-         END DO
-      END DO
-      !
-      CALL wrk_dealloc( jpi,jpj,   zwf  )
-      !
-      IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN   ! ORCA_R2 configuration
-         !                                                 ! Increased lateral friction near of some straits
-         !                                ! Gibraltar strait  : partial slip (fmask=0.5)
-         ij0 = 101   ;   ij1 = 101
-         ii0 = 139   ;   ii1 = 140   ;   fmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) =  0.5_wp
-         ij0 = 102   ;   ij1 = 102
-         ii0 = 139   ;   ii1 = 140   ;   fmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) =  0.5_wp
-         !
-         !                                ! Bab el Mandeb : partial slip (fmask=1)
-         ij0 =  87   ;   ij1 =  88
-         ii0 = 160   ;   ii1 = 160   ;   fmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) =  1._wp
-         ij0 =  88   ;   ij1 =  88
-         ii0 = 159   ;   ii1 = 159   ;   fmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) =  1._wp
-         !
-         !                                ! Danish straits  : strong slip (fmask > 2)
-! We keep this as an example but it is instable in this case 
-!         ij0 = 115   ;   ij1 = 115
-!         ii0 = 145   ;   ii1 = 146   ;   fmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) = 4._wp
-!         ij0 = 116   ;   ij1 = 116
-!         ii0 = 145   ;   ii1 = 146   ;   fmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) = 4._wp
-         !
-      ENDIF
-      !
-      IF( cp_cfg == "orca" .AND. jp_cfg == 1 ) THEN   ! ORCA R1 configuration
-         !                                                 ! Increased lateral friction near of some straits
-         ! This dirty section will be suppressed by simplification process:
-         ! all this will come back in input files
-         ! Currently these hard-wired indices relate to configuration with
-         ! extend grid (jpjglo=332)
-         !
-         isrow = 332 - jpjglo
-         !
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '   orca_r1: increase friction near the following straits : '
-         IF(lwp) WRITE(numout,*) '      Gibraltar '
-         ii0 = 282           ;   ii1 = 283        ! Gibraltar Strait 
-         ij0 = 241 - isrow   ;   ij1 = 241 - isrow   ;   fmask( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 2._wp  
-
-         IF(lwp) WRITE(numout,*) '      Bhosporus '
-         ii0 = 314           ;   ii1 = 315        ! Bhosporus Strait 
-         ij0 = 248 - isrow   ;   ij1 = 248 - isrow   ;   fmask( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 2._wp  
-
-         IF(lwp) WRITE(numout,*) '      Makassar (Top) '
-         ii0 =  48           ;   ii1 =  48        ! Makassar Strait (Top) 
-         ij0 = 189 - isrow   ;   ij1 = 190 - isrow   ;   fmask( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 3._wp  
-
-         IF(lwp) WRITE(numout,*) '      Lombok '
-         ii0 =  44           ;   ii1 =  44        ! Lombok Strait 
-         ij0 = 164 - isrow   ;   ij1 = 165 - isrow   ;   fmask( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 2._wp  
-
-         IF(lwp) WRITE(numout,*) '      Ombai '
-         ii0 =  53           ;   ii1 =  53        ! Ombai Strait 
-         ij0 = 164 - isrow   ;   ij1 = 165 - isrow   ;   fmask( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 2._wp  
-
-         IF(lwp) WRITE(numout,*) '      Timor Passage '
-         ii0 =  56           ;   ii1 =  56        ! Timor Passage 
-         ij0 = 164 - isrow   ;   ij1 = 165 - isrow   ;   fmask( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 2._wp  
-
-         IF(lwp) WRITE(numout,*) '      West Halmahera '
-         ii0 =  58           ;   ii1 =  58        ! West Halmahera Strait 
-         ij0 = 181 - isrow   ;   ij1 = 182 - isrow   ;   fmask( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 3._wp  
-
-         IF(lwp) WRITE(numout,*) '      East Halmahera '
-         ii0 =  55           ;   ii1 =  55        ! East Halmahera Strait 
-         ij0 = 181 - isrow   ;   ij1 = 182 - isrow   ;   fmask( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 3._wp  
-         !
-      ENDIF
-      !
-      CALL lbc_lnk( fmask, 'F', 1._wp )      ! Lateral boundary conditions on fmask
-      !
-      ! CAUTION : The fmask may be further modified in dyn_vor_init ( dynvor.F90 )
+         !
+         CALL wrk_dealloc( jpi,jpj,   zwf )
+         !
+         CALL lbc_lnk( fmask, 'F', 1._wp )      ! Lateral boundary conditions on fmask
+         !
+         ! CAUTION : The fmask may be further modified in dyn_vor_init ( dynvor.F90 ) depending on ln_vorlat
+         !
+      ENDIF
+      
+      ! User defined alteration of fmask (use to reduce ocean transport in specified straits)
+      ! -------------------------------- 
+      !
+      CALL usr_def_fmask( cp_cfg, jp_cfg, fmask )
+      !
       !
       IF( nn_timing == 1 )  CALL timing_stop('dom_msk')
