Index: branches/2013/dev_UKMO_NOC_reproducibililty_env_bathy/NEMOGCM/CONFIG/AMM12/EXP00/namelist
===================================================================
--- branches/2013/dev_UKMO_NOC_reproducibililty_env_bathy/NEMOGCM/CONFIG/AMM12/EXP00/namelist	(revision 4178)
+++ branches/2013/dev_UKMO_NOC_reproducibililty_env_bathy/NEMOGCM/CONFIG/AMM12/EXP00/namelist	(revision 4179)
@@ -28,5 +28,5 @@
    nn_it000    =       1   !  first time step
    nn_itend    =    2880   !  last  time step (std 1 day = 288)
-   nn_date0    =  20070101 !  date at nit_0000 (format yyyymmdd) used if ln_rstart=F or (ln_rstart=T and nn_rstctl=0 or 1)
+   nn_date0    =  20120101 !  date at nit_0000 (format yyyymmdd) used if ln_rstart=F or (ln_rstart=T and nn_rstctl=0 or 1)
    nn_leapy    =       1   !  Leap year calendar (1) or not (0)
    ln_rstart   =  .true.  !  start from rest (F) or from a restart file (T)
@@ -140,5 +140,5 @@
    nn_fsbc     = 1         !  frequency of surface boundary condition computation
                            !     (also = the frequency of sea-ice model call)
-   ln_ana      = .false    !  analytical formulation (T => fill namsbc_ana )
+   ln_ana      = .false.   !  analytical formulation (T => fill namsbc_ana )
    ln_flx      = .true.    !  flux formulation       (T => fill namsbc_flx )
    ln_blk_clio = .false.   !  CLIO bulk formulation                     (T => fill namsbc_clio)
@@ -466,9 +466,9 @@
 !              !   file name    ! frequency (hours) !  variable  ! time interpol. !  clim   ! 'yearly'/ ! weights  ! rotation !
 !              !                !  (if <0  months)  !    name    !    (logical)   !  (T/F)  ! 'monthly' ! filename ! pairing  !
-   bn_ssh =     'amm12_bdyT_u2d' ,         24        , 'sossheig' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
-   bn_u2d =     'amm12_bdyU_u2d' ,         24        , 'vobtcrtx' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
-   bn_v2d =     'amm12_bdyV_u2d' ,         24        , 'vobtcrty' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
-   bn_u3d  =    'amm12_bdyU_u3d' ,         24        , 'vozocrtx' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
-   bn_v3d  =    'amm12_bdyV_u3d' ,         24        , 'vomecrty' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
+   bn_ssh =     'amm12_bdyT_dyn2d' ,         24        , 'sossheig' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
+   bn_u2d =     'amm12_bdyU_dyn2d' ,         24        , 'vobtcrtx' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
+   bn_v2d =     'amm12_bdyV_dyn2d' ,         24        , 'vobtcrty' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
+   bn_u3d  =    'amm12_bdyU_dyn3d' ,         24        , 'vozocrtx' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
+   bn_v3d  =    'amm12_bdyV_dyn3d' ,         24        , 'vomecrty' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
    bn_tem  =    'amm12_bdyT_tra' ,         24        , 'votemper' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
    bn_sal  =    'amm12_bdyT_tra' ,         24        , 'vosaline' ,     .true.     , .false. ,  'daily'  ,    ''    ,   ''
Index: branches/2013/dev_UKMO_NOC_reproducibililty_env_bathy/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- branches/2013/dev_UKMO_NOC_reproducibililty_env_bathy/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4178)
+++ branches/2013/dev_UKMO_NOC_reproducibililty_env_bathy/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4179)
@@ -1163,13 +1163,25 @@
       !                                        ! =============================
       ! use r-value to create hybrid coordinates
-!     DO jj = 1, jpj
-!        DO ji = 1, jpi
-!           zenv(ji,jj) = MAX( bathy(ji,jj), 0._wp )
-!        END DO
-!     END DO
-!     CALL lbc_lnk( zenv, 'T', 1._wp )
       zenv(:,:) = bathy(:,:)
+      !
+      ! set first land point adjacent to a wet cell to sbot_min as this needs to be included in smoothing
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+           IF( bathy(ji,jj) == 0._wp ) THEN
+             iip1 = MIN( ji+1, jpi )
+             ijp1 = MIN( jj+1, jpj )
+             iim1 = MAX( ji-1, 1 )
+             ijm1 = MAX( jj-1, 1 )
+             IF( (bathy(iip1,jj) + bathy(iim1,jj) + bathy(ji,ijp1) + bathy(ji,ijm1) +              &
+        &         bathy(iip1,ijp1) + bathy(iim1,ijm1) + bathy(iip1,ijp1) + bathy(iim1,ijm1)) > 0._wp ) THEN
+               zenv(ji,jj) = rn_sbot_min
+             ENDIF
+           ENDIF
+         END DO
+      END DO
+      ! apply lateral boundary condition   CAUTION: keep the value when the lbc field is zero
+      CALL lbc_lnk( zenv, 'T', 1._wp, 'no0' )
       ! 
-      ! Smooth the bathymetry (if required)
+      ! smooth the bathymetry (if required)
       scosrf(:,:) = 0._wp             ! ocean surface depth (here zero: no under ice-shelf sea)
       scobot(:,:) = bathy(:,:)        ! ocean bottom  depth
@@ -1195,5 +1207,5 @@
          jl = jl + 1
          zrmax = 0._wp
-         ! we set zrmax from previous r-values (zri abd zrj) first
+         ! we set zrmax from previous r-values (zri and zrj) first
          ! if set after current r-value calculation (as previously)
          ! we could exit DO WHILE prematurely before checking r-value
@@ -1231,15 +1243,14 @@
             END DO
          END DO
-         !
-         CALL lbc_lnk( zenv, 'T', 1._wp )
+         ! apply lateral boundary condition   CAUTION: keep the value when the lbc field is zero
+         CALL lbc_lnk( zenv, 'T', 1._wp, 'no0' )
          !                                                  ! ================ !
       END DO                                                !     End loop     !
       !                                                     ! ================ !
-      !
-!     DO jj = 1, jpj
-!        DO ji = 1, jpi
-!           zenv(ji,jj) = MAX( zenv(ji,jj), rn_sbot_min ) ! set all points to avoid undefined scale values
-!        END DO
-!     END DO
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zenv(ji,jj) = MAX( zenv(ji,jj), rn_sbot_min ) ! set all points to avoid undefined scale value warnings
+         END DO
+      END DO
       !
       ! Envelope bathymetry saved in hbatt
@@ -1250,5 +1261,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               ztaper = EXP( -(gphit(ji,jj)/8._wp)**2 )
+               ztaper = EXP( -(gphit(ji,jj)/8._wp)**2._wp )
                hbatt(ji,jj) = rn_sbot_max * ztaper + hbatt(ji,jj) * ( 1._wp - ztaper )
             END DO
@@ -1365,11 +1376,11 @@
       fsde3w(:,:,:) = gdep3w(:,:,:)
       !
-      where (e3t   (:,:,:).eq.0.0)  e3t(:,:,:) = 1.0
-      where (e3u   (:,:,:).eq.0.0)  e3u(:,:,:) = 1.0
-      where (e3v   (:,:,:).eq.0.0)  e3v(:,:,:) = 1.0
-      where (e3f   (:,:,:).eq.0.0)  e3f(:,:,:) = 1.0
-      where (e3w   (:,:,:).eq.0.0)  e3w(:,:,:) = 1.0
-      where (e3uw  (:,:,:).eq.0.0)  e3uw(:,:,:) = 1.0
-      where (e3vw  (:,:,:).eq.0.0)  e3vw(:,:,:) = 1.0
+      where (e3t   (:,:,:).eq.0.0)  e3t(:,:,:) = 1._wp
+      where (e3u   (:,:,:).eq.0.0)  e3u(:,:,:) = 1._wp
+      where (e3v   (:,:,:).eq.0.0)  e3v(:,:,:) = 1._wp
+      where (e3f   (:,:,:).eq.0.0)  e3f(:,:,:) = 1._wp
+      where (e3w   (:,:,:).eq.0.0)  e3w(:,:,:) = 1._wp
+      where (e3uw  (:,:,:).eq.0.0)  e3uw(:,:,:) = 1._wp
+      where (e3vw  (:,:,:).eq.0.0)  e3vw(:,:,:) = 1._wp
 
 #if defined key_agrif
@@ -1748,9 +1759,4 @@
       ENDDO
       !
-      CALL lbc_lnk(e3t ,'T',1.) ; CALL lbc_lnk(e3u ,'T',1.)
-      CALL lbc_lnk(e3v ,'T',1.) ; CALL lbc_lnk(e3f ,'T',1.)
-      CALL lbc_lnk(e3w ,'T',1.)
-      CALL lbc_lnk(e3uw,'T',1.) ; CALL lbc_lnk(e3vw,'T',1.)
-      !
       !                                               ! =============
 
@@ -1849,5 +1855,5 @@
       !!----------------------------------------------------------------------
       !
-      pf =   (   TANH( rn_theta * ( -(pk-0.5_wp) / REAL(jpkm1) + rn_thetb )  )   &
+      pf =   (   TANH( rn_theta * ( -(pk-0.5_wp) / REAL(jpkm1,wp) + rn_thetb )  )   &
          &     - TANH( rn_thetb * rn_theta                                )  )   &
          & * (   COSH( rn_theta                           )                      &
@@ -1875,8 +1881,8 @@
       !
       IF ( rn_theta == 0 ) then      ! uniform sigma
-         pf1 = - ( pk1 - 0.5_wp ) / REAL( jpkm1 )
+         pf1 = - ( pk1 - 0.5_wp ) / REAL( jpkm1,wp )
       ELSE                        ! stretched sigma
-         pf1 =   ( 1._wp - pbb ) * ( SINH( rn_theta*(-(pk1-0.5_wp)/REAL(jpkm1)) ) ) / SINH( rn_theta )              &
-            &  + pbb * (  (TANH( rn_theta*( (-(pk1-0.5_wp)/REAL(jpkm1)) + 0.5_wp) ) - TANH( 0.5_wp * rn_theta )  )  &
+         pf1 =   ( 1._wp - pbb ) * ( SINH( rn_theta*(-(pk1-0.5_wp)/REAL(jpkm1,wp)) ) ) / SINH( rn_theta )              &
+            &  + pbb * (  (TANH( rn_theta*( (-(pk1-0.5_wp)/REAL(jpkm1,wp)) + 0.5_wp) ) - TANH( 0.5_wp * rn_theta )  )  &
             &        / ( 2._wp * TANH( 0.5_wp * rn_theta ) )  )
       ENDIF
