Index: /branches/UKMO/r6232_HZG_WAVE-coupling/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- /branches/UKMO/r6232_HZG_WAVE-coupling/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 9461)
+++ /branches/UKMO/r6232_HZG_WAVE-coupling/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 9462)
@@ -1067,4 +1067,9 @@
 
       ! Write all fields on T grid
+      IF( ln_wave .AND. ln_sdw ) THEN 
+         CALL histwrite( id_i, "sdzocrtx", kt, usd           , jpi*jpj*jpk, idex)     ! now StokesDrift i-velocity 
+         CALL histwrite( id_i, "sdmecrty", kt, vsd           , jpi*jpj*jpk, idex)     ! now StokesDrift j-velocity 
+         CALL histwrite( id_i, "sdvecrtz", kt, wsd           , jpi*jpj*jpk, idex)     ! now StokesDrift k-velocity 
+      ENDIF 
       CALL histwrite( id_i, "votemper", kt, tsn(:,:,:,jp_tem), jpi*jpj*jpk, idex )    ! now temperature
       CALL histwrite( id_i, "vosaline", kt, tsn(:,:,:,jp_sal), jpi*jpj*jpk, idex )    ! now salinity
@@ -1083,10 +1088,4 @@
          CALL histwrite( id_i, "vovvle3t", kt, fse3t_n (:,:,:), jpi*jpj*jpk, idex )!  T-cell thickness  
       END IF
-      
-      IF( ln_wave .AND. ln_sdw ) THEN 
-         CALL histwrite( id_i, "sdzocrtx", kt, usd           , jpi*jpj*jpk, idex)     ! now StokesDrift i-velocity 
-         CALL histwrite( id_i, "sdmecrty", kt, vsd           , jpi*jpj*jpk, idex)     ! now StokesDrift j-velocity 
-         CALL histwrite( id_i, "sdvecrtz", kt, wsd           , jpi*jpj*jpk, idex)     ! now StokesDrift k-velocity 
-      ENDIF 
 
       ! 3. Close the file
Index: /branches/UKMO/r6232_HZG_WAVE-coupling/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- /branches/UKMO/r6232_HZG_WAVE-coupling/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 9461)
+++ /branches/UKMO/r6232_HZG_WAVE-coupling/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 9462)
@@ -467,5 +467,15 @@
                 &                        + fwfisf(:,:) + fwfisf_b(:,:)                     )
       ENDIF
-      ! 
+      !                                   !* Fill boundary data arrays for AGRIF
+      !                                   ! ------------------------------------
+#if defined key_agrif
+         IF( .NOT.Agrif_Root() ) CALL agrif_dta_ts( kt )
+#endif
+      !
+      ! -----------------------------------------------------------------------
+      !  Phase 2 : Integration of the barotropic equations 
+      ! -----------------------------------------------------------------------
+      !
+      ! Moved here to allow merging with other branch 
       IF( ln_sdw ) THEN                         ! Stokes drift divergence added if necessary 
          zssh_frc(:,:) = zssh_frc(:,:) + div_sd(:,:) 
@@ -478,14 +488,4 @@
       ENDIF
 #endif
-      !                                   !* Fill boundary data arrays for AGRIF
-      !                                   ! ------------------------------------
-#if defined key_agrif
-         IF( .NOT.Agrif_Root() ) CALL agrif_dta_ts( kt )
-#endif
-      !
-      ! -----------------------------------------------------------------------
-      !  Phase 2 : Integration of the barotropic equations 
-      ! -----------------------------------------------------------------------
-      !
       !                                             ! ==================== !
       !                                             !    Initialisations   !
Index: /branches/UKMO/r6232_HZG_WAVE-coupling/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90
===================================================================
--- /branches/UKMO/r6232_HZG_WAVE-coupling/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 9461)
+++ /branches/UKMO/r6232_HZG_WAVE-coupling/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 9462)
@@ -335,8 +335,8 @@
       ! ---------------------------------
       !
-      SELECT CASE ( nn_bc_surf )
-      !
-      CASE ( 0 )             ! Dirichlet case
-         IF( ln_phioc ) THEN  ! wave induced mixing case with forced/coupled fields
+      IF( ln_phioc ) THEN
+         SELECT CASE ( nn_bc_surf )
+         !
+         CASE ( 0 )             ! Dirichlet case
             IF( nn_wmix==jp_janssen ) THEN
                ! First level
@@ -367,23 +367,5 @@
                !
             ENDIF
-         ELSE                 ! wave induced mixing case with default values
-            en(:,:,1) = rc02r * ustars2(:,:) * (1._wp + rsbc_tke1_default)**(2._wp/3._wp)
-            en(:,:,1) = MAX(en(:,:,1), rn_emin) 
-            z_elem_a(:,:,1) = en(:,:,1)
-            z_elem_c(:,:,1) = 0._wp
-            z_elem_b(:,:,1) = 1._wp
-            ! 
-            ! One level below
-            en(:,:,2) = rc02r * ustars2(:,:) * (1._wp + rsbc_tke1_default * ((zhsro(:,:)+fsdepw(:,:,2)) &
-                &            / zhsro(:,:) )**(1.5_wp*ra_sf))**(2._wp/3._wp)
-            en(:,:,2) = MAX(en(:,:,2), rn_emin )
-            z_elem_a(:,:,2) = 0._wp 
-            z_elem_c(:,:,2) = 0._wp
-            z_elem_b(:,:,2) = 1._wp
-            !
-            !
-         ENDIF
-      CASE ( 1 )             ! Neumann boundary condition on d(e)/dz
-         IF( ln_phioc ) THEN   ! Shear free case: d(e)/dz=Fw with forced/coupled fields
+         CASE ( 1 )             ! Neumann boundary condition on d(e)/dz
             IF( nn_wmix==jp_janssen ) THEN
                ! Dirichlet conditions at k=1
@@ -416,25 +398,46 @@
                !
             ENDIF
-         ELSE                  ! Shear free case: d(e)/dz=Fw with default values
-            ! Dirichlet conditions at k=1
-            en(:,:,1)       = rc02r * ustars2(:,:) * (1._wp + rsbc_tke1_default)**(2._wp/3._wp)
-            en(:,:,1)       = MAX(en(:,:,1), rn_emin)      
-            z_elem_a(:,:,1) = en(:,:,1)
-            z_elem_c(:,:,1) = 0._wp
-            z_elem_b(:,:,1) = 1._wp
-            !
-            ! at k=2, set de/dz=Fw
-            !cbr
-            z_elem_b(:,:,2) = z_elem_b(:,:,2) +  z_elem_a(:,:,2) ! Remove z_elem_a from z_elem_b
-            z_elem_a(:,:,2) = 0._wp
-            zkar(:,:)       = (rl_sf + (vkarmn-rl_sf)*(1.-exp(-rtrans_default*fsdept(:,:,1)/zhsro(:,:)) ))
-            zflxs(:,:)      = rsbc_tke2 * ustars2(:,:)**1.5_wp * zkar(:,:) &
-                 &                      * ((zhsro(:,:)+fsdept(:,:,1))/zhsro(:,:) )**(1.5_wp*ra_sf)
-
-            en(:,:,2) = en(:,:,2) + zflxs(:,:)/fse3w(:,:,2)
-            !
-            !
-         ENDIF
+         END SELECT
+      ELSE
+      SELECT CASE ( nn_bc_surf )
+      !
+      CASE ( 0 )             ! Dirichlet case
+      ! First level
+      en(:,:,1) = rc02r * ustars2(:,:) * (1._wp + rsbc_tke1_default)**(2._wp/3._wp)
+      en(:,:,1) = MAX(en(:,:,1), rn_emin) 
+      z_elem_a(:,:,1) = en(:,:,1)
+      z_elem_c(:,:,1) = 0._wp
+      z_elem_b(:,:,1) = 1._wp
+      ! 
+      ! One level below
+      en(:,:,2) = rc02r * ustars2(:,:) * (1._wp + rsbc_tke1_default * ((zhsro(:,:)+fsdepw(:,:,2)) &
+          &            / zhsro(:,:) )**(1.5_wp*ra_sf))**(2._wp/3._wp)
+      en(:,:,2) = MAX(en(:,:,2), rn_emin )
+      z_elem_a(:,:,2) = 0._wp 
+      z_elem_c(:,:,2) = 0._wp
+      z_elem_b(:,:,2) = 1._wp
+      !
+      !
+      CASE ( 1 )             ! Neumann boundary condition on d(e)/dz
+      ! Dirichlet conditions at k=1
+      en(:,:,1)       = rc02r * ustars2(:,:) * (1._wp + rsbc_tke1_default)**(2._wp/3._wp)
+      en(:,:,1)       = MAX(en(:,:,1), rn_emin)      
+      z_elem_a(:,:,1) = en(:,:,1)
+      z_elem_c(:,:,1) = 0._wp
+      z_elem_b(:,:,1) = 1._wp
+      !
+      ! at k=2, set de/dz=Fw
+      !cbr
+      z_elem_b(:,:,2) = z_elem_b(:,:,2) +  z_elem_a(:,:,2) ! Remove z_elem_a from z_elem_b
+      z_elem_a(:,:,2) = 0._wp
+      zkar(:,:)       = (rl_sf + (vkarmn-rl_sf)*(1.-exp(-rtrans_default*fsdept(:,:,1)/zhsro(:,:)) ))
+      zflxs(:,:)      = rsbc_tke2 * ustars2(:,:)**1.5_wp * zkar(:,:) &
+           &                      * ((zhsro(:,:)+fsdept(:,:,1))/zhsro(:,:) )**(1.5_wp*ra_sf)
+
+      en(:,:,2) = en(:,:,2) + zflxs(:,:)/fse3w(:,:,2)
+      !
+      !
       END SELECT
+      ENDIF ! ln_phioc
 
       ! Bottom boundary condition on tke
