Index: trunk/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 888)
+++ trunk/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 911)
@@ -7,5 +7,6 @@
    !!             " "  !  05-11  (V. Garnier, G. Madec)  optimization
    !!             9.0  !  06-08  (S. Masson)  distributed restart using iom
-   !!             9.0  !  08-01  (R. Benshila)  change averaging method
+   !!              "   !  08-01  (R. Benshila)  change averaging method
+   !!              "   !  07-07  (D. Storkey) calls to BDY routines
    !!---------------------------------------------------------------------
 #if defined key_dynspg_ts   ||   defined key_esopa
@@ -30,4 +31,9 @@
    USE obc_oce         ! Lateral open boundary condition
    USE obc_par         ! open boundary condition parameters
+   USE bdy_oce         ! unstructured open boundaries
+   USE bdy_par         ! unstructured open boundaries
+   USE bdydta          ! unstructured open boundaries
+   USE bdydyn          ! unstructured open boundaries
+   USE bdytides        ! tidal forcing at unstructured open boundaries.
    USE lib_mpp         ! distributed memory computing library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
@@ -102,9 +108,9 @@
          zua, zva, zub, zvb,                &  !     "        "
          zssha_b, zua_b, zva_b,             &  !     "        "
-         zsshb_e, zub_e, zvb_e,             &  !     "        "
+         zub_e, zvb_e,                      &  !     "        "
          zun_e, zvn_e                          !     "        "
       !! Variable volume
       REAL(wp), DIMENSION(jpi,jpj)     ::   &
-         zspgu_1, zspgv_1, zsshun_e, zsshvn_e, hu_e, hv_e         ! 2D workspace
+         zspgu_1, zspgv_1, zsshun_e, zsshvn_e                     ! 2D workspace
       REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zfse3un_e, zfse3vn_e  ! 3D workspace
       !!----------------------------------------------------------------------
@@ -130,4 +136,6 @@
          ua_e(:,:)   = un_b(:,:)
          va_e(:,:)   = vn_b(:,:)
+         hu_e(:,:)   = hu(:,:)
+         hv_e(:,:)   = hv(:,:)
 
          IF( ln_dynvor_een ) THEN
@@ -300,5 +308,5 @@
 
       ! variables for the barotropic equations
-      zsshb_e(:,:) = sshn_b(:,:)       ! (barotropic) sea surface height (before and now)
+      sshb_e (:,:) = sshn_b(:,:)       ! (barotropic) sea surface height (before and now)
       sshn_e (:,:) = sshn_b(:,:)
       zub_e  (:,:) = un_b  (:,:)       ! barotropic transports issued from the barotropic equations (before and now)
@@ -309,9 +317,9 @@
       zua_b  (:,:) = 0.e0
       zva_b  (:,:) = 0.e0
+      hu_e   (:,:) = hu   (:,:)     ! (barotropic) ocean depth at u-point
+      hv_e   (:,:) = hv   (:,:)     ! (barotropic) ocean depth at v-point
       IF( lk_vvl ) THEN
          zsshun_e(:,:)    = sshu (:,:)     ! (barotropic) sea surface height (now) at u-point
          zsshvn_e(:,:)    = sshv (:,:)     ! (barotropic) sea surface height (now) at v-point
-         hu_e(:,:)        = hu   (:,:)     ! (barotropic) ocean depth at u-point
-         hv_e(:,:)        = hv   (:,:)     ! (barotropic) ocean depth at v-point
          zfse3un_e(:,:,:) = fse3u(:,:,:)   ! (barotropic) scale factors  at u-point
          zfse3un_e(:,:,:) = fse3v(:,:,:)   ! (barotropic) scale factors  at v-point
@@ -338,7 +346,9 @@
          ! Time interpolation of open boundary condition data
          IF( lk_obc )   CALL obc_dta_bt( kt, jit )
+         IF( lk_bdy .or. lk_bdy_tides)   CALL bdy_dta_bt( kt, jit+1 )
 
          ! Horizontal divergence of barotropic transports
          !--------------------------------------------------
+         zhdiv(:,:) = 0.e0
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -360,9 +370,17 @@
 #endif
 
+         IF( lk_bdy .or. lk_bdy_tides ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zhdiv(ji,jj) = zhdiv(ji,jj)*bdytmask(ji,jj)
+               END DO
+            END DO
+         ENDIF
+
          ! Sea surface height from the barotropic system
          !----------------------------------------------
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               ssha_e(ji,jj) = ( zsshb_e(ji,jj) - z2dt_e *  ( zraur * emp(ji,jj)  &
+               ssha_e(ji,jj) = ( sshb_e(ji,jj) - z2dt_e *  ( zraur * emp(ji,jj)  &
             &            +  zhdiv(ji,jj) ) ) * tmask(ji,jj,1)
             END DO
@@ -457,5 +475,5 @@
          !         - Correct the barotropic transports
          IF( lk_obc )   CALL obc_fla_ts
-
+         IF( lk_bdy .or. lk_bdy_tides )   CALL bdy_dyn_fla
 
          ! ... Boundary conditions on ua_e, va_e, ssha_e
@@ -475,5 +493,5 @@
          ! ---------------------------------------
          IF( neuler == 0 .AND. jit == 1 ) THEN   ! Euler (forward) time stepping
-            zsshb_e(:,:) = sshn_e(:,:)
+            sshb_e (:,:) = sshn_e(:,:)
             zub_e  (:,:) = zun_e (:,:)
             zvb_e  (:,:) = zvn_e (:,:)
@@ -482,5 +500,5 @@
             zvn_e  (:,:) = va_e  (:,:)
          ELSE                                        ! Asselin filtering
-            zsshb_e(:,:) = atfp * ( zsshb_e(:,:) + ssha_e(:,:) ) + atfp1 * sshn_e(:,:)
+            sshb_e (:,:) = atfp * ( sshb_e(:,:) + ssha_e(:,:) ) + atfp1 * sshn_e(:,:)
             zub_e  (:,:) = atfp * ( zub_e  (:,:) + ua_e  (:,:) ) + atfp1 * zun_e  (:,:)
             zvb_e  (:,:) = atfp * ( zvb_e  (:,:) + va_e  (:,:) ) + atfp1 * zvn_e  (:,:)
@@ -571,4 +589,12 @@
       IF( lp_obc_south )   zhdiv(nis0  :nis1  ,njs0  :njs1)   = 0.e0    ! south
 #endif
+
+      IF ( lk_bdy .or. lk_bdy_tides ) THEN
+         DO jj = 1, jpj
+           DO ji = 1, jpi
+             zhdiv(ji,jj) = zhdiv(ji,jj)*bdytmask(ji,jj)
+           END DO
+         END DO
+      ENDIF
 
       ! sea surface height
