Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 2797)
@@ -18,5 +18,4 @@
    USE lib_mpp         ! distributed memory computing library
    USE trabbc          ! bottom boundary condition
-   USE bdy_par         ! (for lk_bdy)
    USE obc_par         ! (for lk_obc)
 
@@ -205,5 +204,5 @@
       WRITE(numout,*) "dia_hsb: heat salt volume budgets activated"
       WRITE(numout,*) "~~~~~~~  output written in the 'heat_salt_volume_budgets.txt' ASCII file"
-      IF( lk_obc .OR. lk_bdy) THEN
+      IF( lk_obc ) THEN
          CALL ctl_warn( 'dia_hsb does not take open boundary fluxes into account' )         
       ENDIF
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 2797)
@@ -25,5 +25,4 @@
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
-   USE obc_oce         ! ocean open boundary conditions
    USE in_out_manager  ! I/O manager
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/divcur.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/divcur.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/divcur.F90	(revision 2797)
@@ -27,5 +27,4 @@
    USE sbc_oce, ONLY : ln_rnf   ! surface boundary condition: ocean
    USE sbcrnf          ! river runoff 
-   USE obc_oce         ! ocean lateral open boundary condition
    USE cla             ! cross land advection             (cla_div routine)
    USE in_out_manager  ! I/O manager
@@ -121,14 +120,4 @@
          END DO
 
-#if defined key_obc
-         IF( Agrif_Root() ) THEN
-            ! open boundaries (div must be zero behind the open boundary)
-            !  mpp remark: The zeroing of hdivn can probably be extended to 1->jpi/jpj for the correct row/column
-            IF( lp_obc_east  )   hdivn(nie0p1:nie1p1,nje0  :nje1  ,jk) = 0.e0      ! east
-            IF( lp_obc_west  )   hdivn(niw0  :niw1  ,njw0  :njw1  ,jk) = 0.e0      ! west
-            IF( lp_obc_north )   hdivn(nin0  :nin1  ,njn0p1:njn1p1,jk) = 0.e0      ! north
-            IF( lp_obc_south )   hdivn(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.e0      ! south
-         ENDIF
-#endif         
          IF( .NOT. AGRIF_Root() ) THEN
             IF ((nbondi ==  1).OR.(nbondi == 2)) hdivn(nlci-1 , :     ,jk) = 0.e0      ! east
@@ -304,14 +293,4 @@
          END DO  
 
-#if defined key_obc
-         IF( Agrif_Root() ) THEN
-            ! open boundaries (div must be zero behind the open boundary)
-            !  mpp remark: The zeroing of hdivn can probably be extended to 1->jpi/jpj for the correct row/column
-            IF( lp_obc_east  )   hdivn(nie0p1:nie1p1,nje0  :nje1  ,jk) = 0.e0      ! east
-            IF( lp_obc_west  )   hdivn(niw0  :niw1  ,njw0  :njw1  ,jk) = 0.e0      ! west
-            IF( lp_obc_north )   hdivn(nin0  :nin1  ,njn0p1:njn1p1,jk) = 0.e0      ! north
-            IF( lp_obc_south )   hdivn(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.e0      ! south
-         ENDIF
-#endif         
          IF( .NOT. AGRIF_Root() ) THEN
             IF ((nbondi ==  1).OR.(nbondi == 2)) hdivn(nlci-1 , :     ,jk) = 0.e0      ! east
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 2797)
@@ -30,10 +30,7 @@
    USE domvvl          ! variable volume
    USE obc_oce         ! ocean open boundary conditions
-   USE obcdyn          ! open boundary condition for momentum (obc_dyn routine)
-   USE obcdyn_bt       ! 2D open boundary condition for momentum (obc_dyn_bt routine)
+   USE obcdyn3d        ! open boundary condition for baroclinic velocities
+   USE obcdyn2d        ! open boundary condition for barotropic variables
    USE obcvol          ! ocean open boundary condition (obc_vol routines)
-   USE bdy_oce         ! unstructured open boundary conditions
-   USE bdydta          ! unstructured open boundary conditions
-   USE bdydyn          ! unstructured open boundary conditions
    USE in_out_manager  ! I/O manager
    USE lbclnk          ! lateral boundary condition (or mpp link)
@@ -77,6 +74,5 @@
       !!              * Apply lateral boundary conditions on after velocity 
       !!             at the local domain boundaries through lbc_lnk call,
-      !!             at the radiative open boundaries (lk_obc=T),
-      !!             at the relaxed   open boundaries (lk_bdy=T), and
+      !!             at the one-way open boundaries (lk_obc=T),
       !!             at the AGRIF zoom     boundaries (lk_agrif=T)
       !!
@@ -157,12 +153,11 @@
 # if defined key_obc
       !                                !* OBC open boundaries
-      CALL obc_dyn( kt )
-      !
       IF( .NOT. lk_dynspg_flt ) THEN
-         ! Flather boundary condition : - Update sea surface height on each open boundary
-         !                                       sshn   (= after ssh   ) for explicit case (lk_dynspg_exp=T)
-         !                                       sshn_b (= after ssha_b) for time-splitting case (lk_dynspg_ts=T)
-         !                              - Correct the barotropic velocities
-         CALL obc_dyn_bt( kt )
+
+         CALL obc_dyn3d( kt )
+         !
+    !!!! ENDA'S FIX: NEED TO THINK ABOUT THIS !!!!
+         CALL obc_dta( kt+1, jit=0 )
+         CALL obc_dyn2d( kt, sshn_b )
          !
 !!gm ERROR - potential BUG: sshn should not be modified at this stage !!   ssh_nxt not alrady called
@@ -174,34 +169,4 @@
       ENDIF
       !
-# elif defined key_bdy 
-      !                                !* BDY open boundaries
-      IF( .NOT. lk_dynspg_flt ) THEN
-         CALL bdy_dyn_frs( kt )
-#  if ! defined key_vvl
-         ua_e(:,:) = 0.e0
-         va_e(:,:) = 0.e0
-         ! Set these variables for use in bdy_dyn_fla
-         hur_e(:,:) = hur(:,:)
-         hvr_e(:,:) = hvr(:,:)
-         DO jk = 1, jpkm1   !! Vertically integrated momentum trends
-            ua_e(:,:) = ua_e(:,:) + fse3u(:,:,jk) * umask(:,:,jk) * ua(:,:,jk)
-            va_e(:,:) = va_e(:,:) + fse3v(:,:,jk) * vmask(:,:,jk) * va(:,:,jk)
-         END DO
-         ua_e(:,:) = ua_e(:,:) * hur(:,:)
-         va_e(:,:) = va_e(:,:) * hvr(:,:)
-         DO jk = 1 , jpkm1
-            ua(:,:,jk) = ua(:,:,jk) - ua_e(:,:)
-            va(:,:,jk) = va(:,:,jk) - va_e(:,:)
-         END DO
-         CALL bdy_dta_fla( kt+1, 0,2*nn_baro)
-         CALL bdy_dyn_fla( sshn_b )
-         CALL lbc_lnk( ua_e, 'U', -1. )   ! Boundary points should be updated
-         CALL lbc_lnk( va_e, 'V', -1. )   !
-         DO jk = 1 , jpkm1
-            ua(:,:,jk) = ( ua(:,:,jk) + ua_e(:,:) ) * umask(:,:,jk)
-            va(:,:,jk) = ( va(:,:,jk) + va_e(:,:) ) * vmask(:,:,jk)
-         END DO
-#  endif
-      ENDIF
 # endif
       !
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 2797)
@@ -15,5 +15,4 @@
    USE dom_oce        ! ocean space and time domain variables
    USE phycst         ! physical constants
-   USE obc_oce        ! ocean open boundary conditions
    USE sbc_oce        ! surface boundary condition: ocean
    USE sbcapr         ! surface boundary condition: atmospheric pressure
@@ -222,13 +221,4 @@
       ENDIF
 
-#if defined key_obc
-      !                        ! Conservation of ocean volume (key_dynspg_flt)
-      IF( lk_dynspg_flt )   ln_vol_cst = .true.
-
-      !                        ! Application of Flather's algorithm at open boundaries
-      IF( lk_dynspg_flt )   ln_obc_fla = .false.
-      IF( lk_dynspg_exp )   ln_obc_fla = .true.
-      IF( lk_dynspg_ts  )   ln_obc_fla = .true.
-#endif
       !
    END SUBROUTINE dyn_spg_init
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 2797)
@@ -20,5 +20,4 @@
    USE obc_oce         ! Lateral open boundary condition
    USE phycst          ! physical constants
-   USE obc_par         ! open boundary condition parameters
    USE obcdta          ! open boundary condition data     (obc_dta_bt routine)
    USE in_out_manager  ! I/O manager
@@ -78,5 +77,5 @@
 
 !!gm bug ??  Rachid we have to discuss of the call below. I don't understand why it is here and not in ssh_wzv
-      IF( lk_obc )   CALL obc_dta_bt( kt, 0 )      ! OBC: read or estimate ssh and vertically integrated velocities
+      IF( lk_obc )   CALL obc_dta( kt, jit=0 )      ! OBC: read or estimate ssh and vertically integrated velocities
 !!gm
 
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_flt.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_flt.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_flt.F90	(revision 2797)
@@ -33,9 +33,6 @@
    USE solpcg          ! preconditionned conjugate gradient solver
    USE solsor          ! Successive Over-relaxation solver
-   USE obcdyn          ! ocean open boundary condition (obc_dyn routines)
+   USE obcdyn3d        ! ocean open boundary condition (obc_dyn3d routines)
    USE obcvol          ! ocean open boundary condition (obc_vol routines)
-   USE bdy_oce         ! Unstructured open boundaries condition
-   USE bdydyn          ! Unstructured open boundaries condition (bdy_dyn routine) 
-   USE bdyvol          ! Unstructured open boundaries condition (bdy_vol routine)
    USE cla             ! cross land advection
    USE in_out_manager  ! I/O manager
@@ -183,10 +180,6 @@
 
 #if defined key_obc
-      CALL obc_dyn( kt )      ! Update velocities on each open boundary with the radiation algorithm
+      CALL obc_dyn3d( kt )    ! Update velocities on each open boundary
       CALL obc_vol( kt )      ! Correction of the barotropic componant velocity to control the volume of the system
-#endif
-#if defined key_bdy
-      CALL bdy_dyn_frs( kt )       ! Update velocities on unstructured boundary using the Flow Relaxation Scheme
-      CALL bdy_vol( kt )           ! Correction of the barotropic component velocity to control the volume of the system
 #endif
 #if defined key_agrif
@@ -304,12 +297,8 @@
 #if defined key_obc
             ! caution : grad D = 0 along open boundaries
+            ! Remark: The filtering force could be reduced here in the FRS zone
+            !         by multiplying spgu/spgv by (1-alpha) ??  
             spgu(ji,jj) = z2dt * ztdgu * obcumask(ji,jj)
             spgv(ji,jj) = z2dt * ztdgv * obcvmask(ji,jj)
-#elif defined key_bdy
-            ! caution : grad D = 0 along open boundaries
-            ! Remark: The filtering force could be reduced here in the FRS zone
-            !         by multiplying spgu/spgv by (1-alpha) ??  
-            spgu(ji,jj) = z2dt * ztdgu * bdyumask(ji,jj)
-            spgv(ji,jj) = z2dt * ztdgv * bdyvmask(ji,jj)           
 #else
             spgu(ji,jj) = z2dt * ztdgu
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 2797)
@@ -25,14 +25,8 @@
    USE domvvl          ! variable volume
    USE zdfbfr          ! bottom friction
-   USE obcdta          ! open boundary condition data     
-   USE obcfla          ! Flather open boundary condition  
    USE dynvor          ! vorticity term
    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 obcdta          ! open boundary condition data     
+   USE obcdyn2d        ! open boundary conditions on barotropic variables
    USE lib_mpp         ! distributed memory computing library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
@@ -352,13 +346,4 @@
       zssh_sum(:,:) = sshn (:,:)
 
-#if defined key_obc
-      ! set ssh corrections to 0
-      ! ssh corrections are applied to normal velocities (Flather's algorithm) and averaged over the barotropic loop
-      IF( lp_obc_east  )   sshfoe_b(:,:) = 0.e0
-      IF( lp_obc_west  )   sshfow_b(:,:) = 0.e0
-      IF( lp_obc_south )   sshfos_b(:,:) = 0.e0
-      IF( lp_obc_north )   sshfon_b(:,:) = 0.e0
-#endif
-
       !                                             ! ==================== !
       DO jn = 1, icycle                             !  sub-time-step loop  ! (from NOW to AFTER+1)
@@ -367,8 +352,7 @@
          IF( jn == 1 )   z2dt_e = rdt / nn_baro
 
-         !                                                !* Update the forcing (OBC, BDY and tides)
+         !                                                !* Update the forcing (OBC and tides)
          !                                                !  ------------------
-         IF( lk_obc )   CALL obc_dta_bt ( kt, jn   )
-         IF( lk_bdy )   CALL bdy_dta_fla( kt, jn+1, icycle )
+         IF( lk_obc )   CALL obc_dta ( kt, jit=jn   )
 
          !                                                !* after ssh_e
@@ -384,13 +368,5 @@
          !
 #if defined key_obc
-         !                                                     ! OBC : zhdiv must be zero behind the open boundary
-!!  mpp remark: The zeroing of hdiv can probably be extended to 1->jpi/jpj for the correct row/column
-         IF( lp_obc_east  )   zhdiv(nie0p1:nie1p1,nje0  :nje1  ) = 0.e0      ! east
-         IF( lp_obc_west  )   zhdiv(niw0  :niw1  ,njw0  :njw1  ) = 0.e0      ! west
-         IF( lp_obc_north )   zhdiv(nin0  :nin1  ,njn0p1:njn1p1) = 0.e0      ! north
-         IF( lp_obc_south )   zhdiv(nis0  :nis1  ,njs0  :njs1  ) = 0.e0      ! south
-#endif
-#if defined key_bdy
-         zhdiv(:,:) = zhdiv(:,:) * bdytmask(:,:)               ! BDY mask
+         zhdiv(:,:) = zhdiv(:,:) * obctmask(:,:)               ! OBC mask
 #endif
          !
@@ -489,10 +465,6 @@
          !                                                !* domain lateral boundary
          !                                                !  -----------------------
-         !                                                      ! Flather's boundary condition for the barotropic loop :
-         !                                                      !         - Update sea surface height on each open boundary
-         !                                                      !         - Correct the velocity
-
-         IF( lk_obc               )   CALL obc_fla_ts ( ua_e, va_e, sshn_e, ssha_e )
-         IF( lk_bdy .OR. ln_tides )   CALL bdy_dyn_fla( sshn_e ) 
+                                                               ! OBC open boundaries
+         IF( lk_obc .OR. ln_tides )   CALL obc_dyn2d( kt, sshn_e ) 
          !
          CALL lbc_lnk( ua_e  , 'U', -1. )                      ! local domain boundaries 
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 2797)
@@ -26,7 +26,5 @@
    USE lbclnk          ! ocean lateral boundary condition (or mpp link)
    USE lib_mpp         ! MPP library
-   USE obc_par         ! open boundary cond. parameter
    USE obc_oce
-   USE bdy_oce
    USE diaar5, ONLY:   lk_diaar5
    USE iom
@@ -175,12 +173,6 @@
 #endif
 #if defined key_obc
-      IF( Agrif_Root() ) THEN 
-         ssha(:,:) = ssha(:,:) * obctmsk(:,:)
-         CALL lbc_lnk( ssha, 'T', 1. )                 ! absolutly compulsory !! (jmm)
-      ENDIF
-#endif
-#if defined key_bdy
-      ssha(:,:) = ssha(:,:) * bdytmask(:,:)
-      CALL lbc_lnk( ssha, 'T', 1. ) 
+      ssha(:,:) = ssha(:,:) * obctmask(:,:)
+      CALL lbc_lnk( ssha, 'T', 1. )                 ! absolutly compulsory !! (jmm)
 #endif
 
@@ -217,6 +209,6 @@
             &                      - ( fse3t_a(:,:,jk) - fse3t_b(:,:,jk) )    &
             &                         * tmask(:,:,jk) * z1_2dt
-#if defined key_bdy
-         wn(:,:,jk) = wn(:,:,jk) * bdytmask(:,:)
+#if defined key_obc
+         wn(:,:,jk) = wn(:,:,jk) * obctmask(:,:)
 #endif
       END DO
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 2797)
@@ -47,5 +47,4 @@
    !!   mppsync       :
    !!   mppstop       :
-   !!   mppobc        : variant of mpp_lnk for open boundary condition
    !!   mpp_ini_north : initialisation of north fold
    !!   mpp_lbc_north : north fold processors gathering
@@ -64,5 +63,5 @@
    PUBLIC   mpp_min, mpp_max, mpp_sum, mpp_minloc, mpp_maxloc
    PUBLIC   mpp_lnk_3d, mpp_lnk_3d_gather, mpp_lnk_2d, mpp_lnk_2d_e
-   PUBLIC   mppobc, mpp_ini_ice, mpp_ini_znl
+   PUBLIC   mpp_ini_ice, mpp_ini_znl
    PUBLIC   mppsize
    PUBLIC   lib_mpp_alloc   ! Called in nemogcm.F90
@@ -1726,209 +1725,4 @@
    END SUBROUTINE mppstop
 
-
-   SUBROUTINE mppobc( ptab, kd1, kd2, kl, kk, ktype, kij , kumout)
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppobc  ***
-      !! 
-      !! ** Purpose :   Message passing manadgement for open boundary
-      !!     conditions array
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!       between processors following neighboring subdomains.
-      !!       domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors 
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY:   ztab => wrk_2d_1
-      !
-      INTEGER , INTENT(in   )                     ::   kd1, kd2   ! starting and ending indices
-      INTEGER , INTENT(in   )                     ::   kl         ! index of open boundary
-      INTEGER , INTENT(in   )                     ::   kk         ! vertical dimension
-      INTEGER , INTENT(in   )                     ::   ktype      ! define north/south or east/west cdt
-      !                                                           !  = 1  north/south  ;  = 2  east/west
-      INTEGER , INTENT(in   )                     ::   kij        ! horizontal dimension
-      INTEGER , INTENT(in   )                     ::   kumout     ! ocean.output logical unit
-      REAL(wp), INTENT(inout), DIMENSION(kij,kk)  ::   ptab       ! variable array
-      !
-      INTEGER ::   ji, jj, jk, jl        ! dummy loop indices
-      INTEGER ::   iipt0, iipt1, ilpt1   ! local integers
-      INTEGER ::   ijpt0, ijpt1          !   -       -
-      INTEGER ::   imigr, iihom, ijhom   !   -       -
-      INTEGER ::   ml_req1, ml_req2, ml_err    ! for key_mpi_isend
-      INTEGER ::   ml_stat(MPI_STATUS_SIZE)    ! for key_mpi_isend
-      !!----------------------------------------------------------------------
-
-      IF( wrk_in_use(2, 1) ) THEN
-         WRITE(kumout, cform_err)
-         WRITE(kumout,*) 'mppobc : requested workspace array unavailable'
-         CALL mppstop
-      ENDIF
-
-      ! boundary condition initialization
-      ! ---------------------------------
-      ztab(:,:) = 0.e0
-      !
-      IF( ktype==1 ) THEN                                  ! north/south boundaries
-         iipt0 = MAX( 1, MIN(kd1 - nimpp+1, nlci     ) )
-         iipt1 = MAX( 0, MIN(kd2 - nimpp+1, nlci - 1 ) )
-         ilpt1 = MAX( 1, MIN(kd2 - nimpp+1, nlci     ) )
-         ijpt0 = MAX( 1, MIN(kl  - njmpp+1, nlcj     ) )
-         ijpt1 = MAX( 0, MIN(kl  - njmpp+1, nlcj - 1 ) )
-      ELSEIF( ktype==2 ) THEN                              ! east/west boundaries
-         iipt0 = MAX( 1, MIN(kl  - nimpp+1, nlci     ) )
-         iipt1 = MAX( 0, MIN(kl  - nimpp+1, nlci - 1 ) )
-         ijpt0 = MAX( 1, MIN(kd1 - njmpp+1, nlcj     ) )
-         ijpt1 = MAX( 0, MIN(kd2 - njmpp+1, nlcj - 1 ) )
-         ilpt1 = MAX( 1, MIN(kd2 - njmpp+1, nlcj     ) )
-      ELSE
-         WRITE(kumout, cform_err)
-         WRITE(kumout,*) 'mppobc : bad ktype'
-         CALL mppstop
-      ENDIF
-      
-      ! Communication level by level
-      ! ----------------------------
-!!gm Remark : this is very time consumming!!!
-      !                                         ! ------------------------ !
-      DO jk = 1, kk                             !   Loop over the levels   !
-         !                                      ! ------------------------ !
-         !
-         IF( ktype == 1 ) THEN                               ! north/south boundaries
-            DO jj = ijpt0, ijpt1
-               DO ji = iipt0, iipt1
-                  ztab(ji,jj) = ptab(ji,jk)
-               END DO
-            END DO
-         ELSEIF( ktype == 2 ) THEN                           ! east/west boundaries
-            DO jj = ijpt0, ijpt1
-               DO ji = iipt0, iipt1
-                  ztab(ji,jj) = ptab(jj,jk)
-               END DO
-            END DO
-         ENDIF
-
-
-         ! 1. East and west directions
-         ! ---------------------------
-         !
-         IF( nbondi /= 2 ) THEN         ! Read Dirichlet lateral conditions
-            iihom = nlci-nreci
-            DO jl = 1, jpreci
-               t2ew(:,jl,1) = ztab(jpreci+jl,:)
-               t2we(:,jl,1) = ztab(iihom +jl,:)
-            END DO
-         ENDIF
-         !
-         !                              ! Migrations
-         imigr=jpreci*jpj
-         !
-         IF( nbondi == -1 ) THEN
-            CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req1 )
-            CALL mpprecv( 1, t2ew(1,1,2), imigr )
-            IF(l_isend)   CALL mpi_wait( ml_req1, ml_stat, ml_err )
-         ELSEIF( nbondi == 0 ) THEN
-            CALL mppsend( 1, t2ew(1,1,1), imigr, nowe, ml_req1 )
-            CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req2 )
-            CALL mpprecv( 1, t2ew(1,1,2), imigr )
-            CALL mpprecv( 2, t2we(1,1,2), imigr )
-            IF(l_isend)   CALL mpi_wait( ml_req1, ml_stat, ml_err )
-            IF(l_isend)   CALL mpi_wait( ml_req2, ml_stat, ml_err )
-         ELSEIF( nbondi == 1 ) THEN
-            CALL mppsend( 1, t2ew(1,1,1), imigr, nowe, ml_req1 )
-            CALL mpprecv( 2, t2we(1,1,2), imigr )
-            IF(l_isend) CALL mpi_wait( ml_req1, ml_stat, ml_err )
-         ENDIF
-         !
-         !                              ! Write Dirichlet lateral conditions
-         iihom = nlci-jpreci
-         !
-         IF( nbondi == 0 .OR. nbondi == 1 ) THEN
-            DO jl = 1, jpreci
-               ztab(jl,:) = t2we(:,jl,2)
-            END DO
-         ENDIF
-         IF( nbondi == -1 .OR. nbondi == 0 ) THEN
-            DO jl = 1, jpreci
-               ztab(iihom+jl,:) = t2ew(:,jl,2)
-            END DO
-         ENDIF
-
-
-         ! 2. North and south directions
-         ! -----------------------------
-         !
-         IF( nbondj /= 2 ) THEN         ! Read Dirichlet lateral conditions
-            ijhom = nlcj-nrecj
-            DO jl = 1, jprecj
-               t2sn(:,jl,1) = ztab(:,ijhom +jl)
-               t2ns(:,jl,1) = ztab(:,jprecj+jl)
-            END DO
-         ENDIF
-         !
-         !                              ! Migrations
-         imigr = jprecj * jpi
-         !
-         IF( nbondj == -1 ) THEN
-            CALL mppsend( 4, t2sn(1,1,1), imigr, nono, ml_req1 )
-            CALL mpprecv( 3, t2ns(1,1,2), imigr )
-            IF(l_isend) CALL mpi_wait( ml_req1, ml_stat, ml_err )
-         ELSEIF( nbondj == 0 ) THEN
-            CALL mppsend( 3, t2ns(1,1,1), imigr, noso, ml_req1 )
-            CALL mppsend( 4, t2sn(1,1,1), imigr, nono, ml_req2 )
-            CALL mpprecv( 3, t2ns(1,1,2), imigr )
-            CALL mpprecv( 4, t2sn(1,1,2), imigr )
-            IF( l_isend )   CALL mpi_wait( ml_req1, ml_stat, ml_err )
-            IF( l_isend )   CALL mpi_wait( ml_req2, ml_stat, ml_err )
-         ELSEIF( nbondj == 1 ) THEN
-            CALL mppsend( 3, t2ns(1,1,1), imigr, noso, ml_req1 )
-            CALL mpprecv( 4, t2sn(1,1,2), imigr)
-            IF( l_isend )   CALL mpi_wait( ml_req1, ml_stat, ml_err )
-         ENDIF
-         !
-         !                              ! Write Dirichlet lateral conditions
-         ijhom = nlcj - jprecj
-         IF( nbondj == 0 .OR. nbondj == 1 ) THEN
-            DO jl = 1, jprecj
-               ztab(:,jl) = t2sn(:,jl,2)
-            END DO
-         ENDIF
-         IF( nbondj == 0 .OR. nbondj == -1 ) THEN
-            DO jl = 1, jprecj
-               ztab(:,ijhom+jl) = t2ns(:,jl,2)
-            END DO
-         ENDIF
-         IF( ktype==1 .AND. kd1 <= jpi+nimpp-1 .AND. nimpp <= kd2 ) THEN
-            DO jj = ijpt0, ijpt1            ! north/south boundaries
-               DO ji = iipt0,ilpt1
-                  ptab(ji,jk) = ztab(ji,jj)  
-               END DO
-            END DO
-         ELSEIF( ktype==2 .AND. kd1 <= jpj+njmpp-1 .AND. njmpp <= kd2 ) THEN
-            DO jj = ijpt0, ilpt1            ! east/west boundaries
-               DO ji = iipt0,iipt1
-                  ptab(jj,jk) = ztab(ji,jj) 
-               END DO
-            END DO
-         ENDIF
-         !
-      END DO
-      !
-      IF( wrk_not_released(2, 1) ) THEN
-         WRITE(kumout, cform_err)
-         WRITE(kumout,*) 'mppobc : failed to release workspace array'
-         CALL mppstop
-      ENDIF
-      !
-   END SUBROUTINE mppobc
-   
-
    SUBROUTINE mpp_comm_free( kcom )
       !!----------------------------------------------------------------------
@@ -2488,7 +2282,4 @@
       MODULE PROCEDURE mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real
    END INTERFACE
-   INTERFACE mppobc
-      MODULE PROCEDURE mppobc_1d, mppobc_2d, mppobc_3d, mppobc_4d
-   END INTERFACE
    INTERFACE mpp_minloc
       MODULE PROCEDURE mpp_minloc2d ,mpp_minloc3d
@@ -2603,28 +2394,4 @@
       WRITE(*,*) 'mppmin_int: You should not have seen this print! error?', kint, kcom
    END SUBROUTINE mppmin_int
-
-   SUBROUTINE mppobc_1d( parr, kd1, kd2, kl, kk, ktype, kij, knum )
-      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij, knum
-      REAL, DIMENSION(:) ::   parr           ! variable array
-      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1), kd1, kd2, kl, kk, ktype, kij, knum
-   END SUBROUTINE mppobc_1d
-
-   SUBROUTINE mppobc_2d( parr, kd1, kd2, kl, kk, ktype, kij, knum )
-      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij, knum
-      REAL, DIMENSION(:,:) ::   parr           ! variable array
-      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1,1), kd1, kd2, kl, kk, ktype, kij, knum
-   END SUBROUTINE mppobc_2d
-
-   SUBROUTINE mppobc_3d( parr, kd1, kd2, kl, kk, ktype, kij, knum )
-      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij, knum
-      REAL, DIMENSION(:,:,:) ::   parr           ! variable array
-      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1,1,1), kd1, kd2, kl, kk, ktype, kij, knum
-   END SUBROUTINE mppobc_3d
-
-   SUBROUTINE mppobc_4d( parr, kd1, kd2, kl, kk, ktype, kij, knum )
-      INTEGER  ::   kd1, kd2, kl , kk, ktype, kij, knum
-      REAL, DIMENSION(:,:,:,:) ::   parr           ! variable array
-      WRITE(*,*) 'mppobc: You should not have seen this print! error?', parr(1,1,1,1), kd1, kd2, kl, kk, ktype, kij, knum
-   END SUBROUTINE mppobc_4d
 
    SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki, kj )
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obc_oce.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obc_oce.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obc_oce.F90	(revision 2797)
@@ -1,285 +1,129 @@
 MODULE obc_oce
-   !!==============================================================================
+   !!======================================================================
    !!                       ***  MODULE obc_oce   ***
-   !! Open Boundary Cond. :   define related variables
-   !!==============================================================================
-   !! history :  OPA  ! 1991-01 (CLIPPER)  Original code 
-   !!   NEMO     1.0  ! 2002-02 (C. Talandier)  modules, F90
+   !! Unstructured Open Boundary Cond. :   define related variables
+   !!======================================================================
+   !! History :  1.0  !  2001-05  (J. Chanut, A. Sellar)  Original code
+   !!            3.0  !  2008-04  (NEMO team)  add in the reference version     
+   !!            3.3  !  2010-09  (D. Storkey) add ice boundary conditions
+   !!            3.4  !  2011     (D. Storkey, J. Chanut) OBC-BDY merge
    !!----------------------------------------------------------------------
-#if defined key_obc
+#if defined key_obc 
    !!----------------------------------------------------------------------
-   !!   'key_obc' :                                 Open Boundary Condition
+   !!   'key_obc'                      Unstructured Open Boundary Condition
    !!----------------------------------------------------------------------
    USE par_oce         ! ocean parameters
-   USE obc_par         ! open boundary condition parameters
+   USE obc_par         ! Unstructured boundary parameters
+   USE lib_mpp         ! distributed memory computing
 
    IMPLICIT NONE
    PUBLIC
-   
-   PUBLIC   obc_oce_alloc   ! called by obcini.F90 module
+
+   TYPE, PUBLIC ::   OBC_INDEX    !: Indices and weights which define the open boundary
+      INTEGER,          DIMENSION(jpbgrd) ::  nblen
+      INTEGER,          DIMENSION(jpbgrd) ::  nblenrim
+      INTEGER, POINTER, DIMENSION(:,:)   ::  nbi
+      INTEGER, POINTER, DIMENSION(:,:)   ::  nbj
+      INTEGER, POINTER, DIMENSION(:,:)   ::  nbr
+      INTEGER, POINTER, DIMENSION(:,:)   ::  nbmap
+      REAL   , POINTER, DIMENSION(:,:)   ::  nbw
+      REAL   , POINTER, DIMENSION(:)     ::  flagu
+      REAL   , POINTER, DIMENSION(:)     ::  flagv
+   END TYPE OBC_INDEX
+
+   TYPE, PUBLIC ::   OBC_DATA     !: Storage for external data
+      REAL, POINTER, DIMENSION(:)     ::  ssh
+      REAL, POINTER, DIMENSION(:)     ::  u2d
+      REAL, POINTER, DIMENSION(:)     ::  v2d
+      REAL, POINTER, DIMENSION(:,:)   ::  u3d
+      REAL, POINTER, DIMENSION(:,:)   ::  v3d
+      REAL, POINTER, DIMENSION(:,:)   ::  tem
+      REAL, POINTER, DIMENSION(:,:)   ::  sal
+#if defined key_lim2
+      REAL, POINTER, DIMENSION(:)     ::  frld
+      REAL, POINTER, DIMENSION(:)     ::  hicif
+      REAL, POINTER, DIMENSION(:)     ::  hsnif
+#endif
+   END TYPE OBC_DATA
 
    !!----------------------------------------------------------------------
-   !! open boundary variables
+   !! Namelist variables
    !!----------------------------------------------------------------------
+   CHARACTER(len=80), DIMENSION(jp_obc) ::   cn_coords_file !: Name of obc coordinates file
+   CHARACTER(len=80)                    ::   cn_mask_file   !: Name of obc mask file
    !
-   !                                            !!* Namelist namobc: open boundary condition *
-   INTEGER           ::   nn_obcdta   = 0        !:  = 0 use the initial state as obc data
-   !                                             !   = 1 read obc data in obcxxx.dta files
-   CHARACTER(len=20) ::   cn_obcdta   = 'annual' !: set to annual  if obc datafile hold 1 year of data
-   !                                             !  set to monthly if obc datafile hold 1 month of data
-   LOGICAL           ::   ln_obc_clim = .true.   !:  obc data files are climatological
-   LOGICAL           ::   ln_obc_fla  = .false.  !:  Flather open boundary condition not used
-   LOGICAL           ::   ln_vol_cst  = .true.   !:  Conservation of the whole volume
-   REAL(wp)          ::   rn_dpein    =  1.      !: damping time scale for inflow at East open boundary
-   REAL(wp)          ::   rn_dpwin    =  1.      !:    "                      "   at West open boundary
-   REAL(wp)          ::   rn_dpsin    =  1.      !:    "                      "   at South open boundary
-   REAL(wp)          ::   rn_dpnin    =  1.      !:    "                      "   at North open boundary
-   REAL(wp)          ::   rn_dpeob    = 15.      !: damping time scale for the climatology at East open boundary
-   REAL(wp)          ::   rn_dpwob    = 15.      !:    "                           "       at West open boundary
-   REAL(wp)          ::   rn_dpsob    = 15.      !:    "                           "       at South open boundary
-   REAL(wp)          ::   rn_dpnob    = 15.      !:    "                           "       at North open boundary
-   REAL(wp)          ::   rn_volemp   =  1.      !: = 0 the total volume will have the variability of the 
-   !                                             !      surface Flux E-P else (volemp = 1) the volume will be constant
-   !                                             !  = 1 the volume will be constant during all the integration.
+   LOGICAL, DIMENSION(jp_obc) ::   ln_coords_file           !: =T read obc coordinates from file; 
+   !                                                        !: =F read obc coordinates from namelist
+   LOGICAL                    ::   ln_mask_file             !: =T read obcmask from file
+   LOGICAL, DIMENSION(jp_obc) ::   ln_tides                 !: =T apply tidal harmonic forcing along open boundaries
+   LOGICAL                    ::   ln_vol                   !: =T volume correction             
+   LOGICAL, DIMENSION(jp_obc) ::   ln_clim                  !: =T obc data files contain climatological data (time-cyclic)
+   !
+   INTEGER                    ::   nb_obc                   !: number of open boundary sets
+   INTEGER, DIMENSION(jp_obc) ::   nn_rimwidth              !: boundary rim width
+   INTEGER, DIMENSION(jp_obc) ::   nn_dtactl      	    !: = 0 use the initial state as obc dta ; 
+                                                            !: = 1 read it in a NetCDF file
+   INTEGER                    ::   nn_volctl                !: = 0 the total volume will have the variability of the surface Flux E-P 
+   !                                                        !  = 1 the volume will be constant during all the integration.
+   INTEGER, DIMENSION(jp_obc) ::   nn_dyn2d                 ! Choice of boundary condition for barotropic variables (U,V,SSH)
+   INTEGER, DIMENSION(jp_obc) ::   nn_dyn3d                 ! Choice of boundary condition for baroclinic velocities 
+   INTEGER, DIMENSION(jp_obc) ::   nn_tra                   ! Choice of boundary condition for active tracers (T and S)
+#if defined key_lim2
+   INTEGER, DIMENSION(jp_obc) ::   nn_ice_lim2              ! Choice of boundary condition for sea ice variables 
+#endif
+   !
+   INTEGER, DIMENSION(jp_obc) ::   nn_dmp2d_in              ! Damping timescale (days) for 2D solution for inward radiation or FRS 
+   INTEGER, DIMENSION(jp_obc) ::   nn_dmp2d_out             ! Damping timescale (days) for 2D solution for outward radiation 
+   INTEGER, DIMENSION(jp_obc) ::   nn_dmp3d_in              ! Damping timescale (days) for 3D solution for inward radiation or FRS 
+   INTEGER, DIMENSION(jp_obc) ::   nn_dmp3d_out             ! Damping timescale (days) for 3D solution for outward radiation
 
-   !                                  !!! OLD non-DOCTOR name of namelist variables
-   INTEGER  ::   nbobc                 !: number of open boundaries ( 1=< nbobc =< 4 ) 
-   INTEGER  ::   nobc_dta              !:  = 0 use the initial state as obc data
-   REAL(wp) ::   rdpein                !: damping time scale for inflow at East open boundary
-   REAL(wp) ::   rdpwin                !:    "                      "   at West open boundary
-   REAL(wp) ::   rdpsin                !:    "                      "   at South open boundary
-   REAL(wp) ::   rdpnin                !:    "                      "   at North open boundary
-   REAL(wp) ::   rdpeob                !: damping time scale for the climatology at East open boundary
-   REAL(wp) ::   rdpwob                !:    "                           "       at West open boundary
-   REAL(wp) ::   rdpsob                !:    "                           "       at South open boundary
-   REAL(wp) ::   rdpnob                !:    "                           "       at North open boundary
-   REAL(wp) ::   volemp                !: = 0 the total volume will have the variability of the 
-   CHARACTER(len=20) :: cffile
+   
+   !!----------------------------------------------------------------------
+   !! Global variables
+   !!----------------------------------------------------------------------
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   obctmask   !: Mask defining computational domain at T-points
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   obcumask   !: Mask defining computational domain at U-points
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   obcvmask   !: Mask defining computational domain at V-points
 
-
-   !!General variables for open boundaries:
-   !!--------------------------------------
-   LOGICAL ::   lfbceast, lfbcwest      !: logical flag for a fixed East and West open boundaries       
-   LOGICAL ::   lfbcnorth, lfbcsouth    !: logical flag for a fixed North and South open boundaries       
-   !                                    !  These logical flags are set to 'true' if damping time 
-   !                                    !  scale are set to 0 in the namelist, for both inflow and outflow).
-
-   REAL(wp), PUBLIC ::   obcsurftot       !: Total lateral surface of open boundaries
-   
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: &  !:
-      obctmsk,            &  !: mask array identical to tmask, execpt along OBC where it is set to 0
-      !                      !  it used to calculate the cumulate flux E-P in the obcvol.F90 routine
-      obcumask, obcvmask     !: u-, v- Force filtering mask for the open
-      !                      !  boundary condition on grad D
-
-   !!--------------------
-   !! East open boundary:
-   !!--------------------
-   INTEGER ::   nie0  , nie1      !: do loop index in mpp case for jpieob
-   INTEGER ::   nie0p1, nie1p1    !: do loop index in mpp case for jpieob+1
-   INTEGER ::   nie0m1, nie1m1    !: do loop index in mpp case for jpieob-1
-   INTEGER ::   nje0  , nje1      !: do loop index in mpp case for jpjed, jpjef
-   INTEGER ::   nje0p1, nje1m1    !: do loop index in mpp case for jpjedp1,jpjefm1
-   INTEGER ::   nje1m2, nje0m1    !: do loop index in mpp case for jpjefm1-1,jpjed
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::   &  !:
-      sshfoe,           & !: now climatology of the east boundary sea surface height
-      ubtfoe,vbtfoe       !: now climatology of the east boundary barotropic transport
-     
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   &  !:
-      ufoe, vfoe,       & !: now climatology of the east boundary velocities 
-      tfoe, sfoe,       & !: now climatology of the east boundary temperature and salinity
-      uclie               !: baroclinic componant of the zonal velocity after radiation 
-      !                   ! in the obcdyn.F90 routine
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sshfoe_b   !: east boundary ssh correction averaged over the barotropic loop
-      !                                            !  (if Flather's algoritm applied at open boundary)
-
-   !!-------------------------------
-   !! Arrays for radiative East OBC: 
-   !!-------------------------------
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   uebnd, vebnd      !: baroclinic u & v component of the velocity over 3 rows 
-      !                                                    !  and 3 time step (now, before, and before before)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   tebnd, sebnd      !: East boundary temperature and salinity over 2 rows 
-      !                                                    !  and 2 time step (now and before)
-   REAL(wp), ALLOCATABLE, SAVE,     DIMENSION(:,:) ::   u_cxebnd, v_cxebnd    !: Zonal component of the phase speed ratio computed with 
-      !                                                    !  radiation of u and v velocity (respectively) at the 
-      !                                                    !  east open boundary (u_cxebnd = cx rdt )
-   REAL(wp), ALLOCATABLE, SAVE,     DIMENSION(:,:) ::   uemsk, vemsk, temsk   !: 2D mask for the East OB
-
-   ! Note that those arrays are optimized for mpp case 
-   ! (hence the dimension jpj is the size of one processor subdomain)
-
-   !!--------------------
-   !! West open boundary
-   !!--------------------
-   INTEGER ::   niw0  , niw1       !: do loop index in mpp case for jpiwob
-   INTEGER ::   niw0p1, niw1p1     !: do loop index in mpp case for jpiwob+1
-   INTEGER ::   njw0  , njw1       !: do loop index in mpp case for jpjwd, jpjwf
-   INTEGER ::   njw0p1, njw1m1     !: do loop index in mpp case for jpjwdp1,jpjwfm1
-   INTEGER ::   njw1m2, njw0m1     !: do loop index in mpp case for jpjwfm2,jpjwd
-
-   REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:) ::   &  !:
-      sshfow,           & !: now climatology of the west boundary sea surface height
-      ubtfow,vbtfow       !: now climatology of the west boundary barotropic transport
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   &  !:
-      ufow, vfow,       & !: now climatology of the west velocities 
-      tfow, sfow,       & !: now climatology of the west temperature and salinity
-      ucliw               !: baroclinic componant of the zonal velocity after the radiation 
-      !                   !  in the obcdyn.F90 routine
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sshfow_b    !: west boundary ssh correction averaged over the barotropic loop
-      !                                          !  (if Flather's algoritm applied at open boundary)
-
-   !!-------------------------------
-   !! Arrays for radiative West OBC
-   !!-------------------------------
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   uwbnd, vwbnd     !: baroclinic u & v components of the velocity over 3 rows 
-      !                                                   !  and 3 time step (now, before, and before before)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   twbnd, swbnd     !: west boundary temperature and salinity over 2 rows and 
-      !                                                   !  2 time step (now and before)
-   REAL(wp), ALLOCATABLE, SAVE,     DIMENSION(:,:) ::   u_cxwbnd, v_cxwbnd   !: Zonal component of the phase speed ratio computed with 
-      !                                                   !  radiation of zonal and meridional velocity (respectively) 
-      !                                                   !  at the west open boundary (u_cxwbnd = cx rdt )
-   REAL(wp), ALLOCATABLE, SAVE,     DIMENSION(:,:) ::   uwmsk, vwmsk, twmsk  !: 2D mask for the West OB
-
-   ! Note that those arrays are optimized for mpp case 
-   ! (hence the dimension jpj is the size of one processor subdomain)
-
-   !!---------------------
-   !! North open boundary
-   !!---------------------
-   INTEGER ::   nin0  , nin1       !: do loop index in mpp case for jpind, jpinf
-   INTEGER ::   nin0p1, nin1m1     !: do loop index in mpp case for jpindp1, jpinfm1
-   INTEGER ::   nin1m2, nin0m1     !: do loop index in mpp case for jpinfm1-1,jpind
-   INTEGER ::   njn0  , njn1       !: do loop index in mpp case for jpnob
-   INTEGER ::   njn0p1, njn1p1     !: do loop index in mpp case for jpnob+1
-   INTEGER ::   njn0m1, njn1m1     !: do loop index in mpp case for jpnob-1
-
-   REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:) ::   &  !:
-      sshfon,           & !: now climatology of the north boundary sea surface height
-      ubtfon,vbtfon       !: now climatology of the north boundary barotropic transport
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   &    !:
-      ufon, vfon,       & !: now climatology of the north boundary velocities
-      tfon, sfon,       & !: now climatology of the north boundary temperature and salinity
-      vclin               !: baroclinic componant of the meridian velocity after the radiation
-      !                   !  in yhe obcdyn.F90 routine
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sshfon_b      !: north boundary ssh correction averaged over the barotropic loop
-      !                                            !  (if Flather's algoritm applied at open boundary)
-
-   !!--------------------------------
-   !! Arrays for radiative North OBC
-   !!--------------------------------
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   unbnd, vnbnd      !: baroclinic u & v components of the velocity over 3
-      !                                                    !  rows and 3 time step (now, before, and before before)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   tnbnd, snbnd      !: north boundary temperature and salinity over
-      !                                                    !  2 rows and 2 time step (now and before)
-   REAL(wp), ALLOCATABLE, SAVE,     DIMENSION(:,:) ::   u_cynbnd, v_cynbnd    !: Meridional component of the phase speed ratio compu-
-      !                                                    !  ted with radiation of zonal and meridional velocity 
-      !                                                    !  (respectively) at the north OB (u_cynbnd = cx rdt )
-   REAL(wp), ALLOCATABLE, SAVE,     DIMENSION(:,:) ::   unmsk, vnmsk, tnmsk   !: 2D mask for the North OB
-
-   ! Note that those arrays are optimized for mpp case 
-   ! (hence the dimension jpj is the size of one processor subdomain)
-   
-   !!---------------------
-   !! South open boundary
-   !!---------------------
-   INTEGER ::   nis0  , nis1       !: do loop index in mpp case for jpisd, jpisf
-   INTEGER ::   nis0p1, nis1m1     !: do loop index in mpp case for jpisdp1, jpisfm1
-   INTEGER ::   nis1m2, nis0m1     !: do loop index in mpp case for jpisfm1-1,jpisd
-   INTEGER ::   njs0  , njs1       !: do loop index in mpp case for jpsob
-   INTEGER ::   njs0p1, njs1p1     !: do loop index in mpp case for jpsob+1
-
-   REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:) ::    &   !:
-      sshfos,           & !: now climatology of the south boundary sea surface height
-      ubtfos,vbtfos       !: now climatology of the south boundary barotropic transport
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::    &   !:
-      ufos, vfos,       & !: now climatology of the south boundary velocities 
-      tfos, sfos,       & !: now climatology of the south boundary temperature and salinity
-      vclis               !: baroclinic componant of the meridian velocity after the radiation 
-      !                   !  in the obcdyn.F90 routine
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sshfos_b     !: south boundary ssh correction averaged over the barotropic loop
-      !                                           !  (if Flather's algoritm applied at open boundary)
-
-   !!--------------------------------
-   !! Arrays for radiative South OBC   (computed by the forward time step in dynspg)
-   !!--------------------------------
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   usbnd, vsbnd     !: baroclinic u & v components of the velocity over 3 
-      !                                                   !  rows and 3 time step (now, before, and before before)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   tsbnd, ssbnd     !: south boundary temperature and salinity over
-      !                                                   !  2 rows and 2 time step (now and before)
-   REAL(wp), ALLOCATABLE, SAVE,     DIMENSION(:,:) ::   u_cysbnd, v_cysbnd   !: Meridional component of the phase speed ratio
-      !                                                   !  computed with radiation of zonal and meridional velocity 
-      !                                                   !  (repsectively) at the south OB (u_cynbnd = cx rdt )
-   REAL(wp), ALLOCATABLE, SAVE,     DIMENSION(:,:) ::   usmsk, vsmsk, tsmsk  !: 2D mask for the South OB
+   REAL(wp)                                    ::   obcsurftot !: Lateral surface of unstructured open boundary
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! open boundary data variables
+   !!----------------------------------------------------------------------
+
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)       ::   dta_global        !: workspace for reading in global data arrays
+   TYPE(OBC_INDEX), DIMENSION(jp_obc), TARGET    ::   idx_obc           !: obc indices (local process)
+   TYPE(OBC_DATA) , DIMENSION(jp_obc)            ::   dta_obc           !: obc external data (local process)
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
    !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 CONTAINS
 
-   INTEGER FUNCTION obc_oce_alloc()
+   FUNCTION obc_oce_alloc()
       !!----------------------------------------------------------------------
-      !!               ***  FUNCTION obc_oce_alloc  ***
+      USE lib_mpp, ONLY: ctl_warn, mpp_sum
+      !
+      INTEGER :: obc_oce_alloc
       !!----------------------------------------------------------------------
-
-      ALLOCATE(                                                               &
-              !! East open boundary
-              obctmsk(jpi,jpj), obcumask(jpi,jpj), obcvmask(jpi,jpj),        &
-              sshfoe(jpjed:jpjef), ubtfoe(jpjed:jpjef), vbtfoe(jpjed:jpjef), &
-              ufoe(jpj,jpk), vfoe(jpj,jpk), tfoe(jpj,jpk), sfoe(jpj,jpk),    &
-              uclie(jpj,jpk), sshfoe_b(jpjed:jpjef,jpj),                     &
-              !! Arrays for radiative East OBC
-              uebnd(jpj,jpk,3,3), vebnd(jpj,jpk,3,3) ,                       &
-              tebnd(jpj,jpk,2,2), sebnd(jpj,jpk,2,2),                        &
-              u_cxebnd(jpj,jpk), v_cxebnd(jpj,jpk),                          &
-              uemsk(jpj,jpk), vemsk(jpj,jpk), temsk(jpj,jpk),                &
-              !! West open boundary
-              sshfow(jpjwd:jpjwf), ubtfow(jpjwd:jpjwf), vbtfow(jpjwd:jpjwf), &
-              ufow(jpj,jpk), vfow(jpj,jpk), tfow(jpj,jpk),                   &
-              sfow(jpj,jpk), ucliw(jpj,jpk), sshfow_b(jpjwd:jpjwf,jpj),      &
-              !! Arrays for radiative West OBC
-              uwbnd(jpj,jpk,3,3), vwbnd(jpj,jpk,3,3),                        &
-              twbnd(jpj,jpk,2,2), swbnd(jpj,jpk,2,2),                        &
-              u_cxwbnd(jpj,jpk), v_cxwbnd(jpj,jpk),                          &
-              uwmsk(jpj,jpk), vwmsk(jpj,jpk), twmsk(jpj,jpk),                &
-              !! North open boundary
-              sshfon(jpind:jpinf), ubtfon(jpind:jpinf), vbtfon(jpind:jpinf), &
-              ufon(jpi,jpk), vfon(jpi,jpk), tfon(jpi,jpk),                   &
-              sfon(jpi,jpk), vclin(jpi,jpk), sshfon_b(jpind:jpinf,jpj),      &
-              !! Arrays for radiative North OBC
-              unbnd(jpi,jpk,3,3), vnbnd(jpi,jpk,3,3),                        &
-              tnbnd(jpi,jpk,2,2), snbnd(jpi,jpk,2,2),                        &
-              u_cynbnd(jpi,jpk), v_cynbnd(jpi,jpk),                          &
-              unmsk(jpi,jpk), vnmsk(jpi,jpk), tnmsk (jpi,jpk),               &
-              !! South open boundary
-              sshfos(jpisd:jpisf), ubtfos(jpisd:jpisf), vbtfos(jpisd:jpisf), &
-              ufos(jpi,jpk), vfos(jpi,jpk), tfos(jpi,jpk),                   &
-              sfos(jpi,jpk), vclis(jpi,jpk),                                 &
-              sshfos_b(jpisd:jpisf,jpj),                                     &
-              !! Arrays for radiative South OBC 
-              usbnd(jpi,jpk,3,3), vsbnd(jpi,jpk,3,3),                        &
-              tsbnd(jpi,jpk,2,2), ssbnd(jpi,jpk,2,2),                        &
-              u_cysbnd(jpi,jpk), v_cysbnd(jpi,jpk),                          &
-              usmsk(jpi,jpk), vsmsk(jpi,jpk), tsmsk(jpi,jpk),                &
-              !!
-              STAT=obc_oce_alloc )
+      !
+      ALLOCATE( obctmask(jpi,jpj) , obcumask(jpi,jpj), obcvmask(jpi,jpj),                    &  
+         &      STAT=obc_oce_alloc )
+         !
+      IF( lk_mpp             )   CALL mpp_sum ( obc_oce_alloc )
+      IF( obc_oce_alloc /= 0 )   CALL ctl_warn('obc_oce_alloc: failed to allocate arrays.')
       !
    END FUNCTION obc_oce_alloc
-   
+
 #else
    !!----------------------------------------------------------------------
-   !!   Default option         Empty module                          No OBC
+   !!   Dummy module                NO Unstructured Open Boundary Condition
    !!----------------------------------------------------------------------
+   LOGICAL ::   ln_tides = .false.  !: =T apply tidal harmonic forcing along open boundaries
 #endif
 
    !!======================================================================
 END MODULE obc_oce
+
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obc_par.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obc_par.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obc_par.F90	(revision 2797)
@@ -1,105 +1,33 @@
 MODULE obc_par
-   !!==============================================================================
-   !!                  ***  MODULE obc_par   ***
-   !! Open Boundary Cond. :   define related parameters
-   !!==============================================================================
-   !! history :  OPA  ! 1991-01 (CLIPPER)  Original code 
-   !!   NEMO     1.0  ! 2002-04   (C. Talandier)  modules
-   !!             -   ! 2004/06   (F. Durand) jptobc is defined as a parameter
+   !!======================================================================
+   !!                      ***  MODULE obc_par   ***
+   !! Unstructured Open Boundary Cond. :   define related parameters
+   !!======================================================================
+   !! History :  1.0  !  2005-01  (J. Chanut, A. Sellar)  Original code
+   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
+   !!            3.3  !  2010-09  (D. Storkey and E. O'Dea) update for Shelf configurations
    !!----------------------------------------------------------------------
-#if defined key_obc
+#if defined   key_obc
    !!----------------------------------------------------------------------
-   !!   'key_obc' :                                 Open Boundary Condition
+   !!   'key_obc' :                    Unstructured Open Boundary Condition
    !!----------------------------------------------------------------------
-   USE par_oce         ! ocean parameters
 
    IMPLICIT NONE
    PUBLIC
 
-#if ! defined key_agrif
-   LOGICAL, PUBLIC, PARAMETER ::   lk_obc = .TRUE.     !: Ocean Boundary Condition flag
-#else
-   LOGICAL, PUBLIC            ::   lk_obc = .TRUE.     !: Ocean Boundary Condition flag
-#endif
+   LOGICAL, PUBLIC, PARAMETER ::   lk_obc  = .TRUE.   !: Unstructured Ocean Boundary Condition flag
+   INTEGER, PUBLIC, PARAMETER ::   jp_obc  = 10       !: Maximum number of obc sets
+   INTEGER, PUBLIC, PARAMETER ::   jpbtime = 1000     !: Max number of time dumps per file
+   INTEGER, PUBLIC, PARAMETER ::   jpbgrd  = 3	      !: Number of horizontal grid types used  (T, U, V)
 
-# if defined key_eel_r5
-   !!----------------------------------------------------------------------
-   !!   'key_eel_r5' :                                 EEL R5 configuration
-   !!----------------------------------------------------------------------
-#    include "obc_par_EEL_R5.h90"
-
-# elif defined key_pomme_r025
-   !!----------------------------------------------------------------------
-   !!   'key_pomme_r025' :                         POMME R025 configuration
-   !!----------------------------------------------------------------------
-#    include "obc_par_POMME_R025.h90"
-
-# else
-   !!---------------------------------------------------------------------
-   !! open boundary parameter
-   !!---------------------------------------------------------------------
-   INTEGER, PARAMETER ::   jptobc      =  2        !: time dimension of the BCS fields on input
-   
-   !! * EAST open boundary
-   LOGICAL, PARAMETER ::   lp_obc_east = .FALSE.   !: to active or not the East open boundary
-   INTEGER   &
-#if !defined key_agrif
-     , PARAMETER   & 
-#endif
-    ::     & 
-      jpieob  = jpiglo-2,    &  !: i-localization of the East open boundary (must be ocean U-point)
-      jpjed   =        2,    &  !: j-starting indice of the East open boundary (must be land T-point)
-      jpjef   = jpjglo-1,    &  !: j-ending   indice of the East open boundary (must be land T-point)
-      jpjedp1 =  jpjed+1,    &  !: first ocean point         "                 "
-      jpjefm1 =  jpjef-1        !: last  ocean point         "                 "
-
-   !! * WEST open boundary
-   LOGICAL, PARAMETER ::   lp_obc_west = .FALSE.   !: to active or not the West open boundary
-   INTEGER   &
-#if !defined key_agrif
-     , PARAMETER   & 
-#endif
-    ::     & 
-      jpiwob  =	       2,    &  !: i-localization of the West open boundary (must be ocean U-point)
-      jpjwd   =	       2,    &  !: j-starting indice of the West open boundary (must be land T-point)
-      jpjwf   = jpjglo-1,    &  !: j-ending   indice of the West open boundary (must be land T-point)
-      jpjwdp1 =  jpjwd+1,    &  !: first ocean point         "                 "
-      jpjwfm1 =  jpjwf-1        !: last  ocean point         "                 "
-
-   !! * NORTH open boundary
-   LOGICAL, PARAMETER ::   lp_obc_north = .FALSE.   !: to active or not the North open boundary
-     INTEGER   &
-#if !defined key_agrif
-     , PARAMETER   & 
-#endif
-    ::     & 
-      jpjnob  = jpjglo-2,    &  !: j-localization of the North open boundary (must be ocean V-point)
-      jpind   =        2,    &  !: i-starting indice of the North open boundary (must be land T-point)
-      jpinf   = jpiglo-1,    &  !: i-ending   indice of the North open boundary (must be land T-point)
-      jpindp1 =  jpind+1,    &  !: first ocean point         "                 "
-      jpinfm1 =  jpinf-1        !: last  ocean point         "                 "
-
-   !! * SOUTH open boundary
-   LOGICAL, PARAMETER ::   lp_obc_south = .FALSE.   !: to active or not the South open boundary
-     INTEGER   &
-#if !defined key_agrif
-     , PARAMETER   & 
-#endif
-    ::     & 
-      jpjsob  =        2,    &  !: j-localization of the South open boundary (must be ocean V-point)
-      jpisd   =        2,    &  !: i-starting indice of the South open boundary (must be land T-point)
-      jpisf   = jpiglo-1,    &  !: i-ending   indice of the South open boundary (must be land T-point)
-      jpisdp1 =  jpisd+1,    &  !: first ocean point         "                 "
-      jpisfm1 =  jpisf-1        !: last  ocean point         "                 "
-   
-   INTEGER, PARAMETER ::   jpnic = 2700   !: maximum number of isolated coastlines points 
-
-# endif
-
+   !! Flags for choice of schemes
+   INTEGER, PUBLIC, PARAMETER ::   jp_none         = 0        !: Flag for no open boundary condition
+   INTEGER, PUBLIC, PARAMETER ::   jp_frs          = 1        !: Flag for Flow Relaxation Scheme
+   INTEGER, PUBLIC, PARAMETER ::   jp_flather      = 2        !: Flag for Flather
 #else
    !!----------------------------------------------------------------------
-   !!   Default option :                         NO open boundary condition
+   !!   Default option :            NO Unstructured open boundary condition
    !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_obc = .FALSE.  !: Ocean Boundary Condition flag
+   LOGICAL, PUBLIC, PARAMETER ::   lk_obc = .FALSE.   !: Unstructured Ocean Boundary Condition flag
 #endif
 
@@ -107,5 +35,5 @@
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
    !! $Id$ 
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!======================================================================
 END MODULE obc_par
Index: anches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obc_vectopt_loop_substitute.h90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obc_vectopt_loop_substitute.h90	(revision 2796)
+++ 	(revision )
@@ -1,30 +1,0 @@
-   !!----------------------------------------------------------------------
-   !!                 ***  obc_vectopt_loop_substitute.h90  ***
-   !!----------------------------------------------------------------------
-   !! ** purpose :   substitute the inner loop starting and inding indices 
-   !!      to allow unrolling of do-loop using CPP macro.
-   !!----------------------------------------------------------------------
-#if defined key_vectopt_loop && defined key_obc && ! defined key_mpp_mpi
-#  define fs_niw0  jpiwob 
-#  define fs_niw1  jpiwob
-#  define fs_nie0  jpieob 
-#  define fs_nie1  jpieob
-#  define fs_njn0  jpjnob
-#  define fs_njn1  jpjnob
-#  define fs_njs0  jpjsob
-#  define fs_njs1  jpjsob
-#else
-#  define fs_niw0  niw0 
-#  define fs_niw1  niw1
-#  define fs_nie0  nie0 
-#  define fs_nie1  nie1
-#  define fs_njn0  njn0
-#  define fs_njn1  njn1
-#  define fs_njs0  njs0
-#  define fs_njs1  njs1
-#endif
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdta.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdta.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdta.F90	(revision 2797)
@@ -1,1241 +1,488 @@
 MODULE obcdta
-   !!==============================================================================
-   !!                            ***  MODULE obcdta  ***
-   !! Open boundary data : read the data for the open boundaries.
-   !!==============================================================================
-   !! History :  OPA  ! 1998-05 (J.M. Molines) Original code
-   !!            8.5  ! 2002-10 (C. Talandier, A-M. Treguier) Free surface, F90
-   !!   NEMO     1.0  ! 2004-06 (F. Durand, A-M. Treguier) Netcdf BC files on input
-   !!            3.0  ! 2007-2008 (C. Langlais, P. Mathiot, J.M. Molines) high frequency boundaries data
-   !!------------------------------------------------------------------------------
+   !!======================================================================
+   !!                       ***  MODULE obcdta  ***
+   !! Open boundary data : read the data for the unstructured open boundaries.
+   !!======================================================================
+   !! History :  1.0  !  2005-01  (J. Chanut, A. Sellar)  Original code
+   !!             -   !  2007-01  (D. Storkey) Update to use IOM module
+   !!             -   !  2007-07  (D. Storkey) add obc_dta_fla
+   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
+   !!            3.3  !  2010-09  (E.O'Dea) modifications for Shelf configurations 
+   !!            3.3  !  2010-09  (D.Storkey) add ice boundary conditions
+   !!            3.4  ????????????????
+   !!----------------------------------------------------------------------
 #if defined key_obc
-   !!------------------------------------------------------------------------------
-   !!   'key_obc'         :                                Open Boundary Conditions
-   !!------------------------------------------------------------------------------
-   !!   obc_dta           : read u, v, t, s data along each open boundary
-   !!------------------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers 
+   !!----------------------------------------------------------------------
+   !!   'key_obc'                     Open Boundary Conditions
+   !!----------------------------------------------------------------------
+   !!    obc_dta        : read external data along open boundaries from file
+   !!    obc_dta_init   : initialise arrays etc for reading of external data
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE phycst          ! physical constants
-   USE obc_par         ! ocean open boundary conditions
    USE obc_oce         ! ocean open boundary conditions
+   USE obctides        ! tidal forcing at boundaries
+   USE fldread         ! read input fields
+   USE iom             ! IOM library
    USE in_out_manager  ! I/O logical units
-   USE lib_mpp         ! distributed memory computing
-   USE dynspg_oce      ! ocean: surface pressure gradient
-   USE ioipsl          ! now only for  ymds2ju function 
-   USE iom             ! 
+#if defined key_lim2
+   USE ice_2
+#endif
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   obc_dta         ! routine  called by step.F90
-   PUBLIC   obc_dta_bt      ! routine  called by dynspg_ts.F90
-   PUBLIC   obc_dta_alloc   ! function called by obcini.F90
-
-   REAL(wp),  DIMENSION(2)              ::   zjcnes_obc   ! 
-   REAL(wp),  DIMENSION(:), ALLOCATABLE ::   ztcobc
-   REAL(wp) :: rdt_obc
-   REAL(wp) :: zjcnes
-   INTEGER :: imm0, iyy0, idd0, iyy, imm, idd
-   INTEGER :: nt_a=2, nt_b=1, itobc, ndate0_cnes, nday_year0
-   INTEGER ::  itobce, itobcw, itobcs, itobcn, itobc_b  ! number of time steps in OBC files
-
-   INTEGER ::   ntobc        ! where we are in the obc file
-   INTEGER ::   ntobc_b      ! first record used
-   INTEGER ::   ntobc_a      ! second record used
-
-   CHARACTER (len=40) ::   cl_obc_eTS, cl_obc_eU   ! name of data files
-   CHARACTER (len=40) ::   cl_obc_wTS, cl_obc_wU   !   -       -
-   CHARACTER (len=40) ::   cl_obc_nTS, cl_obc_nV   !   -       -
-   CHARACTER (len=40) ::   cl_obc_sTS, cl_obc_sV   !   -       -
-
-   ! bt arrays for interpolating time dependent data on the boundaries
-   INTEGER ::   nt_m=0, ntobc_m
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: ubtedta, vbtedta, sshedta    ! East
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: ubtwdta, vbtwdta, sshwdta	   ! West
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: ubtndta, vbtndta, sshndta	   ! North
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: ubtsdta, vbtsdta, sshsdta	   ! South
-   ! arrays used for interpolating time dependent data on the boundaries
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: uedta, vedta, tedta, sedta    ! East
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: uwdta, vwdta, twdta, swdta    ! West
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: undta, vndta, tndta, sndta    ! North
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: usdta, vsdta, tsdta, ssdta    ! South
-
-   ! Masks set to .TRUE. after successful allocation below
-   LOGICAL , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: ltemsk, luemsk, lvemsk  ! boolean msks
-   LOGICAL , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: ltwmsk, luwmsk, lvwmsk  ! used for outliers
-   LOGICAL , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: ltnmsk, lunmsk, lvnmsk  ! checks
-   LOGICAL , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: ltsmsk, lusmsk, lvsmsk
-
-   !! * Substitutions
-#  include "obc_vectopt_loop_substitute.h90"
-#  include "domzgr_substitute.h90"
+   PUBLIC   obc_dta          ! routine called by step.F90 and dynspg_ts.F90
+   PUBLIC   obc_dta_init     ! routine called by nemogcm.F90
+
+   INTEGER, ALLOCATABLE, DIMENSION(:)   ::   nb_obc_fld        ! Number of fields to update for each boundary set.
+   INTEGER                              ::   nb_obc_fld_sum    ! Total number of fields to update for all boundary sets.
+
+   TYPE(FLD), PUBLIC, ALLOCATABLE, DIMENSION(:), TARGET ::   bf        ! structure of input fields (file informations, fields read)
+
+   TYPE(MAP_POINTER), ALLOCATABLE, DIMENSION(:) :: nbmap_ptr   ! array of pointers to nbmap
+
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 CONTAINS
 
-   INTEGER FUNCTION obc_dta_alloc()
-      !!-------------------------------------------------------------------
-      !!                     ***  ROUTINE obc_dta_alloc  ***
-      !!-------------------------------------------------------------------
-      INTEGER :: ierr(2)
-      !!-------------------------------------------------------------------
-# if defined key_dynspg_ts
-      ALLOCATE(   &     ! time-splitting : 0:jptobc
-         ! bt arrays for interpolating time dependent data on the boundaries
-         &      ubtedta  (jpj,0:jptobc) , vbtedta  (jpj,0:jptobc) , sshedta  (jpj,0:jptobc) ,    &
-         &      ubtwdta  (jpj,0:jptobc) , vbtwdta  (jpj,0:jptobc) , sshwdta  (jpj,0:jptobc) ,    &
-         &      ubtndta  (jpi,0:jptobc) , vbtndta  (jpi,0:jptobc) , sshndta  (jpi,0:jptobc) ,    &
-         &      ubtsdta  (jpi,0:jptobc) , vbtsdta  (jpi,0:jptobc) , sshsdta  (jpi,0:jptobc) ,    &
-         ! arrays used for interpolating time dependent data on the boundaries
-         &      uedta(jpj,jpk,0:jptobc) , vedta(jpj,jpk,0:jptobc)                           ,     &
-         &      tedta(jpj,jpk,0:jptobc) , sedta(jpj,jpk,0:jptobc)                           ,     &
-         &      uwdta(jpj,jpk,0:jptobc) , vwdta(jpj,jpk,0:jptobc)                           ,     &
-         &      twdta(jpj,jpk,0:jptobc) , swdta(jpj,jpk,0:jptobc)                           ,     &
-         &      undta(jpi,jpk,0:jptobc) , vndta(jpi,jpk,0:jptobc)                           ,     &
-         &      tndta(jpi,jpk,0:jptobc) , sndta(jpi,jpk,0:jptobc)                           ,     &
-         &      usdta(jpi,jpk,0:jptobc) , vsdta(jpi,jpk,0:jptobc)                           ,     &
-         &      tsdta(jpi,jpk,0:jptobc) , ssdta(jpi,jpk,0:jptobc)                           , STAT=ierr(1) )
-# else
-      ALLOCATE(   &     ! no time splitting : 1:jptobc
-         ! bt arrays for interpolating time dependent data on the boundaries
-         &      ubtedta  (jpj,jptobc) , vbtedta  (jpj,jptobc) , sshedta  (jpj,jptobc)  ,     &
-         &      ubtwdta  (jpj,jptobc) , vbtwdta  (jpj,jptobc) , sshwdta  (jpj,jptobc)  ,     &
-         &      ubtndta  (jpi,jptobc) , vbtndta  (jpi,jptobc) , sshndta  (jpi,jptobc)  ,     &
-         &      ubtsdta  (jpi,jptobc) , vbtsdta  (jpi,jptobc) , sshsdta  (jpi,jptobc)  ,     &
-         ! arrays used for interpolating time dependent data on the boundaries
-         &      uedta(jpj,jpk,jptobc) , vedta(jpj,jpk,jptobc)                          ,     &
-         &      tedta(jpj,jpk,jptobc) , sedta(jpj,jpk,jptobc)                          ,     &
-         &      uwdta(jpj,jpk,jptobc) , vwdta(jpj,jpk,jptobc)                          ,     &
-         &      twdta(jpj,jpk,jptobc) , swdta(jpj,jpk,jptobc)                          ,     &
-         &      undta(jpi,jpk,jptobc) , vndta(jpi,jpk,jptobc)                          ,     &
-         &      tndta(jpi,jpk,jptobc) , sndta(jpi,jpk,jptobc)                          ,     &
-         &      usdta(jpi,jpk,jptobc) , vsdta(jpi,jpk,jptobc)                          ,     &
-         &      tsdta(jpi,jpk,jptobc) , ssdta(jpi,jpk,jptobc)                          , STAT=ierr(1) )
-# endif
-
-      ALLOCATE( ltemsk(jpj,jpk) , luemsk(jpj,jpk) , lvemsk(jpj,jpk) ,     &
-         &      ltwmsk(jpj,jpk) , luwmsk(jpj,jpk) , lvwmsk(jpj,jpk) ,     &
-         &      ltnmsk(jpj,jpk) , lunmsk(jpj,jpk) , lvnmsk(jpj,jpk) ,     &
-         &      ltsmsk(jpj,jpk) , lusmsk(jpj,jpk) , lvsmsk(jpj,jpk) , STAT=ierr(2) )
-
-      obc_dta_alloc = MAXVAL( ierr )
-      IF( lk_mpp )   CALL mpp_sum( obc_dta_alloc )
-
-      IF( obc_dta_alloc == 0 )  THEN         ! Initialise mask values following successful allocation
-         !      east            !          west            !          north           !          south           !
-         ltemsk(:,:) = .TRUE.   ;   ltwmsk(:,:) = .TRUE.   ;   ltnmsk(:,:) = .TRUE.   ;   ltsmsk(:,:) = .TRUE.
-         luemsk(:,:) = .TRUE.   ;   luwmsk(:,:) = .TRUE.   ;   lunmsk(:,:) = .TRUE.   ;   lusmsk(:,:) = .TRUE.
-         lvemsk(:,:) = .TRUE.   ;   lvwmsk(:,:) = .TRUE.   ;   lvnmsk(:,:) = .TRUE.   ;   lvsmsk(:,:) = .TRUE.
-      END IF
-      !
-   END FUNCTION obc_dta_alloc
-
-
-   SUBROUTINE obc_dta( kt )
-      !!---------------------------------------------------------------------------
-      !!                      ***  SUBROUTINE obc_dta  ***
+      SUBROUTINE obc_dta( kt, jit )
+      !!----------------------------------------------------------------------
+      !!                   ***  SUBROUTINE obc_dta  ***
       !!                    
-      !! ** Purpose :   Find the climatological  boundary arrays for the specified date, 
-      !!                The boundary arrays are netcdf files. Three possible cases: 
-      !!                - one time frame only in the file (time dimension = 1).
-      !!                in that case the boundary data does not change in time.
-      !!                - many time frames. In that case,  if we have 12 frames
-      !!                we assume monthly fields. 
-      !!                Else, we assume that time_counter is in seconds 
-      !!                since the beginning of either the current year or a reference
-      !!                year given in the namelist.
-      !!                (no check is done so far but one would have to check the "unit"
-      !!                 attribute of variable time_counter).
+      !! ** Purpose :   Update external data for open boundary conditions
+      !!
+      !! ** Method  :   Use fldread.F90
+      !!                
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in )           ::   kt    ! ocean time-step index 
+      INTEGER, INTENT( in ), OPTIONAL ::   jit   ! subcycle time-step index (for timesplitting option)
+      !!
+      INTEGER     ::  ib_obc, jfld, jstart, jend            ! local indices
+      INTEGER, POINTER, DIMENSION(:)  ::   nblen, nblenrim  ! short cuts
       !!
       !!---------------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
-      !
-      INTEGER, SAVE :: immfile, iyyfile                     !
-      INTEGER :: nt              !  record indices (incrementation)
-      REAL(wp) ::   zsec, zxy, znum, zden ! time interpolation weight
+
+      ! for nn_dtactl = 0, initialise data arrays once for all
+      ! from initial conditions
+      !-------------------------------------------------------
+      IF( kt .eq. 1 .and. .not. PRESENT(jit) ) THEN
+
+         DO ib_obc = 1, nb_obc
+            IF( nn_dtactl(ib_obc) .eq. 0 ) THEN
+
+               !!! TO BE DONE !!!
+
+            ENDIF
+         ENDDO
+
+      ENDIF
+
+      ! for nn_dtactl = 1, update external data from files
+      !---------------------------------------------------
+     
+      jstart = 1
+      DO ib_obc = 1, nb_obc   
+         IF( nn_dtactl(ib_obc) .eq. 1 ) THEN
+      
+            IF( PRESENT(jit) ) THEN
+               ! Update barotropic boundary conditions only
+               ! jit is optional argument for fld_read
+               IF( nn_dyn2d(ib_obc) .gt. 0 ) THEN
+                  jend = jstart + 2
+                  CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), map=nbmap_ptr(jstart:jend), jit=jit )
+               ENDIF
+            ELSE
+               jend = jstart + nb_obc_fld(ib_obc) - 1
+               CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend ), map=nbmap_ptr(jstart:jend), timeshift=1 )
+            ENDIF
+            jstart = jend+1
+
+         END IF ! nn_dtactl(ib_obc) = 1
+      END DO  ! ib_obc
+
+      END SUBROUTINE obc_dta
+
+
+      SUBROUTINE obc_dta_init
+      !!----------------------------------------------------------------------
+      !!                   ***  SUBROUTINE obc_dta_init  ***
+      !!                    
+      !! ** Purpose :   Initialise arrays for reading of external data 
+      !!                for open boundary conditions
+      !!
+      !! ** Method  :   Use fldread.F90
+      !!                
+      !!----------------------------------------------------------------------
+      INTEGER     ::  ib_obc, jfld, jstart, jend, ierror  ! local indices
+      !!
+      CHARACTER(len=100)                     ::   cn_dir        ! Root directory for location of data files
+      CHARACTER(len=100), DIMENSION(nb_obc)  ::   cn_dir_array  ! Root directory for location of data files
+      INTEGER                                ::   ilen_global   ! Max length required for global obc dta arrays
+      INTEGER, ALLOCATABLE, DIMENSION(:)     ::   ilen1, ilen3  ! size of 1st and 3rd dimensions of local arrays
+      INTEGER, ALLOCATABLE, DIMENSION(:)     ::   iobc           ! obc set for a particular jfld
+      INTEGER, ALLOCATABLE, DIMENSION(:)     ::   igrid         ! index for grid type (1,2,3 = T,U,V)
+      INTEGER, POINTER, DIMENSION(:)         ::   nblen, nblenrim  ! short cuts
+      TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) ::   blf_i         !  array of namelist information structures
+      TYPE(FLD_N) ::   bn_tem, bn_sal, bn_u3d, bn_v3d   ! 
+      TYPE(FLD_N) ::   bn_ssh, bn_u2d, bn_v2d           ! informations about the fields to be read
+#if defined key_lim2
+      TYPE(FLD_N) ::   bn_frld, bn_hicif, bn_hsnif      !
+#endif
+      NAMELIST/namobc_dta/ cn_dir, bn_tem, bn_sal, bn_u3d, bn_v3d, bn_ssh, bn_u2d, bn_v2d 
+#if defined key_lim2
+      NAMELIST/namobc_dta/ bn_frld, bn_hicif, bn_hsnif
+#endif
       !!---------------------------------------------------------------------------
 
-      ! 0.  initialisation :
-      ! --------------------
-      IF ( kt == nit000  )  CALL obc_dta_ini ( kt )
-      IF ( nobc_dta == 0 )  RETURN   ! already done in obc_dta_ini
-      IF ( itobc == 1    )  RETURN   ! case of only one time frame in file done in obc_dta_ini
-
-      ! in the following code, we assume that obc data are read from files, with more than 1 time frame in it
-
-      iyyfile=iyy ; immfile = 00  ! set component of the current file name
-      IF ( cffile /= 'annual') immfile = imm   ! 
-      IF ( ln_obc_clim       ) iyyfile = 0000  ! assume that climatological files are labeled y0000
-
-      ! 1. Synchronize time of run with time of data files
-      !---------------------------------------------------
-      ! nday_year is the day number in the current year ( 1 for 01/01 )
-      zsec=MOD( (kt-nit000)*rdt - (nday_year - nday_year0 )*rday, rday ) ! number of seconds in the current day
-      IF (ln_obc_clim)  THEN 
-         zjcnes = nday_year - 1  + zsec/rday
-      ELSE
-         zjcnes = zjcnes + rdt/rday
+      ! Work out how many fields there are to read in and allocate arrays
+      ! -----------------------------------------------------------------
+      ALLOCATE( nb_obc_fld(nb_obc) )
+      nb_obc_fld(:) = 0
+      DO ib_obc = 1, nb_obc         
+         IF( nn_dtactl(ib_obc) .eq. 1 ) THEN
+            IF( nn_dyn2d(ib_obc) .gt. 0 ) THEN
+               nb_obc_fld(ib_obc) = nb_obc_fld(ib_obc) + 3
+            ENDIF
+            IF( nn_dyn3d(ib_obc) .gt. 0 ) THEN
+               nb_obc_fld(ib_obc) = nb_obc_fld(ib_obc) + 2
+            ENDIF
+            IF( nn_tra(ib_obc) .gt. 0 ) THEN
+               nb_obc_fld(ib_obc) = nb_obc_fld(ib_obc) + 2
+            ENDIF
+#if defined key_lim2
+            IF( nn_ice_lim2(ib_obc) .gt. 0 ) THEN
+               nb_obc_fld(ib_obc) = nb_obc_fld(ib_obc) + 3
+            ENDIF
+#endif               
+         ENDIF
+      ENDDO            
+
+      nb_obc_fld_sum = SUM( nb_obc_fld )
+
+      ALLOCATE( bf(nb_obc_fld_sum), STAT=ierror )
+      IF( ierror > 0 ) THEN   
+         CALL ctl_stop( 'obc_dta: unable to allocate bf structure' )   ;   RETURN  
       ENDIF
-
-      ! look for 'before' record number in the current file
-      ntobc = nrecbef ()  ! this function return the record number for 'before', relative to zjcnes
-
-      IF (MOD(kt-1,10)==0) THEN
-         IF (lwp) WRITE(numout,*) 'kt= ',kt,' zjcnes =', zjcnes,' ndastp =',ndastp, 'mm =',imm 
-      END IF
-
-      ! 2. read a new data if necessary 
-      !--------------------------------
-      IF ( ntobc /= ntobc_b ) THEN
-         ! we need to read the 'after' record
-         ! swap working index:
-# if defined key_dynspg_ts
-         nt=nt_m ; nt_m=nt_b ; nt_b=nt
-# endif
-         nt=nt_b ; nt_b=nt_a ; nt_a=nt
-         ntobc_b = ntobc
-
-         ! new record number :
-         ntobc_a = ntobc_a + 1 
-
-         ! all tricky things related to record number, changing files etc... are managed by obc_read
-
-         CALL obc_read (kt, nt_a, ntobc_a, iyyfile, immfile )
-
-         ! update zjcnes_obc
-# if defined key_dynspg_ts
-         ntobc_m=mod(ntobc_b-2+itobc,itobc)+1
-         zjcnes_obc(nt_m)= ztcobc(ntobc_m)
-# endif
-         zjcnes_obc(nt_b)= ztcobc(ntobc_b)
-         zjcnes_obc(nt_a)= ztcobc(ntobc_a)
+      ALLOCATE( blf_i(nb_obc_fld_sum), STAT=ierror )
+      IF( ierror > 0 ) THEN   
+         CALL ctl_stop( 'obc_dta: unable to allocate blf_i structure' )   ;   RETURN  
       ENDIF
-
-      ! 3.   interpolation at each time step
-      ! ------------------------------------
-      IF( ln_obc_clim) THEN
-         znum= MOD(zjcnes           - zjcnes_obc(nt_b), REAL(nyear_len(1),wp) )
-         IF( znum < 0 ) znum = znum + REAL(nyear_len(1),wp)
-         zden= MOD(zjcnes_obc(nt_a) - zjcnes_obc(nt_b), REAL(nyear_len(1),wp) ) 
-         IF( zden < 0 ) zden = zden + REAL(nyear_len(1),wp)
-      ELSE
-         znum= zjcnes           - zjcnes_obc(nt_b)
-         zden= zjcnes_obc(nt_a) - zjcnes_obc(nt_b)
+      ALLOCATE( nbmap_ptr(nb_obc_fld_sum), STAT=ierror )
+      IF( ierror > 0 ) THEN   
+         CALL ctl_stop( 'obc_dta: unable to allocate nbmap_ptr structure' )   ;   RETURN  
       ENDIF
-      zxy = znum / zden
-
-      IF( lp_obc_east ) THEN
-         !  fills sfoe, tfoe, ufoe ,vfoe
-         sfoe(:,:) = zxy * sedta (:,:,nt_a) + (1. - zxy)*sedta(:,:,nt_b)
-         tfoe(:,:) = zxy * tedta (:,:,nt_a) + (1. - zxy)*tedta(:,:,nt_b)
-         ufoe(:,:) = zxy * uedta (:,:,nt_a) + (1. - zxy)*uedta(:,:,nt_b)
-         vfoe(:,:) = zxy * vedta (:,:,nt_a) + (1. - zxy)*vedta(:,:,nt_b)
+      ALLOCATE( ilen1(nb_obc_fld_sum), ilen3(nb_obc_fld_sum) ) 
+      ALLOCATE( iobc(nb_obc_fld_sum) ) 
+      ALLOCATE( igrid(nb_obc_fld_sum) ) 
+
+      ! Read namelists
+      ! --------------
+      REWIND(numnam)
+      jfld = 0 
+      DO ib_obc = 1, nb_obc         
+         IF( nn_dtactl(ib_obc) .eq. 1 ) THEN
+            ! set file information
+            cn_dir = './'        ! directory in which the model is executed
+            ! ... default values (NB: frequency positive => hours, negative => months)
+            !                    !  file       ! frequency !  variable        ! time intep !  clim   ! 'yearly' or ! weights  ! rotation  !
+            !                    !  name       !  (hours)  !   name           !   (T/F)    !  (T/F)  !  'monthly'  ! filename ! pairs     !
+            bn_ssh     = FLD_N(  'obc_ssh'     ,    24     ,  'sossheig'    ,  .false.   , .false. ,   'yearly'  , ''       , ''        )
+            bn_u2d     = FLD_N(  'obc_vel2d_u' ,    24     ,  'vobtcrtx'    ,  .false.   , .false. ,   'yearly'  , ''       , ''        )
+            bn_v2d     = FLD_N(  'obc_vel2d_v' ,    24     ,  'vobtcrty'    ,  .false.   , .false. ,   'yearly'  , ''       , ''        )
+            bn_u3d     = FLD_N(  'obc_vel3d_u' ,    24     ,  'vozocrtx'    ,  .false.   , .false. ,   'yearly'  , ''       , ''        )
+            bn_v3d     = FLD_N(  'obc_vel3d_v' ,    24     ,  'vomecrty'    ,  .false.   , .false. ,   'yearly'  , ''       , ''        )
+            bn_tem     = FLD_N(  'obc_tem'     ,    24     ,  'votemper'    ,  .false.   , .false. ,   'yearly'  , ''       , ''        )
+            bn_sal     = FLD_N(  'obc_sal'     ,    24     ,  'vosaline'    ,  .false.   , .false. ,   'yearly'  , ''       , ''        )
+#if defined key_lim2
+            bn_frld    = FLD_N(  'obc_frld'    ,    24     ,  'ildsconc'    ,  .false.   , .false. ,   'yearly'  , ''       , ''        )
+            bn_hicif   = FLD_N(  'obc_hicif'   ,    24     ,  'iicethic'    ,  .false.   , .false. ,   'yearly'  , ''       , ''        )
+            bn_hsnif   = FLD_N(  'obc_hsnif'   ,    24     ,  'isnothic'    ,  .false.   , .false. ,   'yearly'  , ''       , ''        )
+#endif
+
+            ! Important NOT to rewind here.
+            READ( numnam, namobc_dta )
+
+            cn_dir_array(ib_obc) = cn_dir
+
+            nblen => idx_obc(ib_obc)%nblen
+            nblenrim => idx_obc(ib_obc)%nblenrim
+
+            ! Only read in necessary fields for this set.
+            ! Important that barotropic variables come first.
+            IF( nn_dyn2d(ib_obc) .gt. 0 ) THEN 
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_ssh
+               iobc(jfld) = ib_obc
+               igrid(jfld) = 1
+               IF( nn_dyn2d(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               ilen3(jfld) = 1
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_u2d
+               iobc(jfld) = ib_obc
+               igrid(jfld) = 2
+               IF( nn_dyn2d(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               ilen3(jfld) = 1
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_v2d
+               iobc(jfld) = ib_obc
+               igrid(jfld) = 3
+               IF( nn_dyn2d(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               ilen3(jfld) = 1
+
+            ENDIF
+
+            ! baroclinic velocities
+            IF( nn_dyn3d(ib_obc) .gt. 0 ) THEN
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_u3d
+               iobc(jfld) = ib_obc
+               igrid(jfld) = 2
+               IF( nn_dyn3d(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               ilen3(jfld) = jpk
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_v3d
+               iobc(jfld) = ib_obc
+               igrid(jfld) = 3
+               IF( nn_dyn3d(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               ilen3(jfld) = jpk
+
+            ENDIF
+
+            ! temperature and salinity
+            IF( nn_tra(ib_obc) .gt. 0 ) THEN
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_tem
+               iobc(jfld) = ib_obc
+               igrid(jfld) = 1
+               IF( nn_tra(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               ilen3(jfld) = jpk
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_sal
+               iobc(jfld) = ib_obc
+               igrid(jfld) = 1
+               IF( nn_tra(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               ilen3(jfld) = jpk
+
+            ENDIF
+
+#if defined key_lim2
+            ! sea ice
+            IF( nn_tra(ib_obc) .gt. 0 ) THEN
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_frld
+               iobc(jfld) = ib_obc
+               igrid(jfld) = 1
+               IF( nn_ice_lim2(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               ilen3(jfld) = 1
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_hicif
+               iobc(jfld) = ib_obc
+               igrid(jfld) = 1
+               IF( nn_ice_lim2(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               ilen3(jfld) = 1
+
+               jfld = jfld + 1
+               blf_i(jfld) = bn_hsnif
+               iobc(jfld) = ib_obc
+               igrid(jfld) = 1
+               IF( nn_ice_lim2(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(jfld) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(jfld) = nblenrim(igrid(jfld))
+               ENDIF
+               ilen3(jfld) = 1
+
+            ENDIF
+#endif
+         ENDIF ! nn_dtactl .eq. 1
+      ENDDO ! ib_obc
+
+      IF( jfld .ne. nb_obc_fld_sum ) THEN
+         CALL ctl_stop( 'obc_dta: error in initialisation: jpfld .ne. nb_obc_fld_sum' )   ;   RETURN  
       ENDIF
 
-      IF( lp_obc_west) THEN
-         !  fills sfow, tfow, ufow ,vfow
-         sfow(:,:) = zxy * swdta (:,:,nt_a) + (1. - zxy)*swdta(:,:,nt_b)
-         tfow(:,:) = zxy * twdta (:,:,nt_a) + (1. - zxy)*twdta(:,:,nt_b)
-         ufow(:,:) = zxy * uwdta (:,:,nt_a) + (1. - zxy)*uwdta(:,:,nt_b)
-         vfow(:,:) = zxy * vwdta (:,:,nt_a) + (1. - zxy)*vwdta(:,:,nt_b)
-      ENDIF
-
-      IF( lp_obc_north) THEN
-         !  fills sfon, tfon, ufon ,vfon
-         sfon(:,:) = zxy * sndta (:,:,nt_a) + (1. - zxy)*sndta(:,:,nt_b)
-         tfon(:,:) = zxy * tndta (:,:,nt_a) + (1. - zxy)*tndta(:,:,nt_b)
-         ufon(:,:) = zxy * undta (:,:,nt_a) + (1. - zxy)*undta(:,:,nt_b)
-         vfon(:,:) = zxy * vndta (:,:,nt_a) + (1. - zxy)*vndta(:,:,nt_b)
-      ENDIF
-
-      IF( lp_obc_south) THEN
-         !  fills sfos, tfos, ufos ,vfos
-         sfos(:,:) = zxy * ssdta (:,:,nt_a) + (1. - zxy)*ssdta(:,:,nt_b)
-         tfos(:,:) = zxy * tsdta (:,:,nt_a) + (1. - zxy)*tsdta(:,:,nt_b)
-         ufos(:,:) = zxy * usdta (:,:,nt_a) + (1. - zxy)*usdta(:,:,nt_b)
-         vfos(:,:) = zxy * vsdta (:,:,nt_a) + (1. - zxy)*vsdta(:,:,nt_b)
-      ENDIF
+      DO jfld = 1, nb_obc_fld_sum
+         ALLOCATE( bf(jfld)%fnow(ilen1(jfld),1,ilen3(jfld)) )
+         IF( blf_i(jfld)%ln_tint ) ALLOCATE( bf(jfld)%fdta(ilen1(jfld),1,ilen3(jfld),2) )
+         nbmap_ptr(jfld)%ptr => idx_obc(iobc(jfld))%nbmap(:,igrid(jfld))
+      ENDDO
+
+      ! fill bf with blf_i and control print
+      !-------------------------------------
+      jstart = 1
+      DO ib_obc = 1, nb_obc
+         jend = jstart + nb_obc_fld(ib_obc) - 1
+         CALL fld_fill( bf(jstart:jend), blf_i(jstart:jend), cn_dir_array(ib_obc), 'obc_dta', 'open boundary conditions', 'namobc_dta' )
+         jstart = jend + 1
+      ENDDO
+
+      ! Initialise local boundary data arrays
+      ! nn_dtactl=0 : allocate space - will be filled from initial conditions later
+      ! nn_dtactl=1 : point to "fnow" arrays
+      !-------------------------------------
+
+      jfld = 0
+      DO ib_obc=1, nb_obc
+
+         nblen => idx_obc(ib_obc)%nblen
+         nblenrim => idx_obc(ib_obc)%nblenrim
+
+         IF( nn_dtactl(ib_obc) .eq. 0 ) THEN
+               
+            ! nn_dtactl = 0 
+            ! Allocate space
+            !---------------
+            IF (nn_dyn2d(ib_obc) .gt. 0) THEN
+               IF( nn_dyn2d(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(1) = nblen(1)
+                  ilen1(2) = nblen(2)
+                  ilen1(3) = nblen(3)
+               ELSE
+                  ilen1(1) = nblenrim(1)
+                  ilen1(2) = nblenrim(2)
+                  ilen1(3) = nblenrim(3)
+               ENDIF
+               ALLOCATE( dta_obc(ib_obc)%ssh(ilen1(1)) )
+               ALLOCATE( dta_obc(ib_obc)%u2d(ilen1(2)) )
+               ALLOCATE( dta_obc(ib_obc)%v2d(ilen1(3)) )
+            ENDIF
+            IF (nn_dyn3d(ib_obc) .gt. 0) THEN
+               IF( nn_dyn3d(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(2) = nblen(2)
+                  ilen1(3) = nblen(3)
+               ELSE
+                  ilen1(2) = nblenrim(2)
+                  ilen1(3) = nblenrim(3)
+               ENDIF
+               ALLOCATE( dta_obc(ib_obc)%u3d(ilen1(2),jpk) )
+               ALLOCATE( dta_obc(ib_obc)%v3d(ilen1(3),jpk) )
+            ENDIF
+            IF (nn_tra(ib_obc) .gt. 0) THEN
+               IF( nn_tra(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(1) = nblen(1)
+               ELSE
+                  ilen1(1) = nblenrim(1)
+               ENDIF
+               ALLOCATE( dta_obc(ib_obc)%tem(ilen1(1),jpk) )
+               ALLOCATE( dta_obc(ib_obc)%sal(ilen1(1),jpk) )
+            ENDIF
+#if defined key_lim2
+            IF (nn_ice_lim2(ib_obc) .gt. 0) THEN
+               IF( nn_ice_lim2(ib_obc) .eq. jp_frs ) THEN
+                  ilen1(1) = nblen(igrid(jfld))
+               ELSE
+                  ilen1(1) = nblenrim(igrid(jfld))
+               ENDIF
+               ALLOCATE( dta_obc(ib_obc)%ssh(ilen1(1)) )
+               ALLOCATE( dta_obc(ib_obc)%u2d(ilen1(1)) )
+               ALLOCATE( dta_obc(ib_obc)%v2d(ilen1(1)) )
+            ENDIF
+#endif
+
+         ELSE
+
+            ! nn_dtactl = 1
+            ! Set boundary data arrays to point to relevant "fnow" arrays
+            !-----------------------------------------------------------
+            IF (nn_dyn2d(ib_obc) .gt. 0) THEN
+               jfld = jfld + 1
+               dta_obc(ib_obc)%ssh => bf(jfld)%fnow(:,1,1)
+               jfld = jfld + 1
+               dta_obc(ib_obc)%u2d => bf(jfld)%fnow(:,1,1)
+               jfld = jfld + 1
+               dta_obc(ib_obc)%v2d => bf(jfld)%fnow(:,1,1)
+            ENDIF
+            IF (nn_dyn3d(ib_obc) .gt. 0) THEN
+               jfld = jfld + 1
+               dta_obc(ib_obc)%u3d => bf(jfld)%fnow(:,1,:)
+               jfld = jfld + 1
+               dta_obc(ib_obc)%v3d => bf(jfld)%fnow(:,1,:)
+            ENDIF
+            IF (nn_tra(ib_obc) .gt. 0) THEN
+               jfld = jfld + 1
+               dta_obc(ib_obc)%tem => bf(jfld)%fnow(:,1,:)
+               jfld = jfld + 1
+               dta_obc(ib_obc)%sal => bf(jfld)%fnow(:,1,:)
+            ENDIF
+#if defined key_lim2
+            IF (nn_ice_lim2(ib_obc) .gt. 0) THEN
+               jfld = jfld + 1
+               dta_obc(ib_obc)%frld  => bf(jfld)%fnow(:,1,1)
+               jfld = jfld + 1
+               dta_obc(ib_obc)%hicif => bf(jfld)%fnow(:,1,1)
+               jfld = jfld + 1
+               dta_obc(ib_obc)%hsnif => bf(jfld)%fnow(:,1,1)
+            ENDIF
+#endif
+
+         ENDIF ! nn_dtactl .eq. 0
+
+      ENDDO ! ib_obc 
+
+      END SUBROUTINE obc_dta_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                   NO Open Boundary Conditions
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE obc_dta( kt, jit )              ! Empty routine
+      WRITE(*,*) 'obc_dta: You should not have seen this print! error?', kt
    END SUBROUTINE obc_dta
-
-
-   SUBROUTINE obc_dta_ini( kt )
-      !!-----------------------------------------------------------------------------
-      !!                       ***  SUBROUTINE obc_dta_ini  ***
-      !!
-      !! ** Purpose :   When obc_dta first call, realize some data initialization
-      !!----------------------------------------------------------------------------
-      INTEGER, INTENT(in)  :: kt      ! ocean time-step index
-      !
-      INTEGER ::   ji, jj   ! dummy loop indices
-      INTEGER, SAVE :: immfile, iyyfile                     !
-
-      ! variables for the julian day calculation
-      INTEGER :: iyear, imonth, iday
-      REAL(wp) :: zsec , zjulian, zjuliancnes   
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*)  'obc_dta : find boundary data'
-      IF(lwp) WRITE(numout,*)  '~~~~~~~'
-      IF (lwp) THEN
-         IF ( nobc_dta == 0 ) THEN 
-            WRITE(numout,*)  '          OBC data taken from initial conditions.'
-         ELSE      
-            WRITE(numout,*)  '          OBC data taken from netcdf files.'
-         ENDIF
-      ENDIF
-      nday_year0 = nday_year  ! to remember the day when kt=nit000
-
-      sedta(:,:,:) = 0.e0 ; tedta(:,:,:) = 0.e0 ; uedta(:,:,:) = 0.e0 ; vedta(:,:,:) = 0.e0 ! East
-      swdta(:,:,:) = 0.e0 ; twdta(:,:,:) = 0.e0 ; uwdta(:,:,:) = 0.e0 ; vwdta(:,:,:) = 0.e0 ! West
-      sndta(:,:,:) = 0.e0 ; tndta(:,:,:) = 0.e0 ; undta(:,:,:) = 0.e0 ; vndta(:,:,:) = 0.e0 ! North
-      ssdta(:,:,:) = 0.e0 ; tsdta(:,:,:) = 0.e0 ; usdta(:,:,:) = 0.e0 ; vsdta(:,:,:) = 0.e0 ! South
-
-      sfoe(:,:) = 0.e0  ; tfoe(:,:) = 0.e0 ; ufoe(:,:) = 0.e0 ; vfoe(:,:) = 0.e0   ! East
-      sfow(:,:) = 0.e0  ; tfow(:,:) = 0.e0 ; ufow(:,:) = 0.e0 ; vfow(:,:) = 0.e0   ! West
-      sfon(:,:) = 0.e0  ; tfon(:,:) = 0.e0 ; ufon(:,:) = 0.e0 ; vfon(:,:) = 0.e0   ! North
-      sfos(:,:) = 0.e0  ; tfos(:,:) = 0.e0 ; ufos(:,:) = 0.e0 ; vfos(:,:) = 0.e0   ! South
-
-      IF (nobc_dta == 0 ) THEN   ! boundary data are the initial data of this run (set only at nit000)
-         IF (lp_obc_east) THEN  ! East
-            DO ji = nie0 , nie1    
-               sfoe(nje0:nje1,:) = temsk(nje0:nje1,:) * sn (ji+1 , nje0:nje1 , :) * tmask(ji+1,nje0:nje1 , :)
-               tfoe(nje0:nje1,:) = temsk(nje0:nje1,:) * tn (ji+1 , nje0:nje1 , :) * tmask(ji+1,nje0:nje1 , :)
-               ufoe(nje0:nje1,:) = uemsk(nje0:nje1,:) * un (ji   , nje0:nje1 , :) * umask(ji,  nje0:nje1 , :)
-               vfoe(nje0:nje1,:) = vemsk(nje0:nje1,:) * vn (ji+1 , nje0:nje1 , :) * vmask(ji+1,nje0:nje1 , :)
-            END DO
-         ENDIF
-
-         IF (lp_obc_west) THEN  ! West
-            DO ji = niw0 , niw1    
-               sfow(njw0:njw1,:) = twmsk(njw0:njw1,:) * sn (ji , njw0:njw1 , :) * tmask(ji , njw0:njw1 , :)
-               tfow(njw0:njw1,:) = twmsk(njw0:njw1,:) * tn (ji , njw0:njw1 , :) * tmask(ji , njw0:njw1 , :)
-               ufow(njw0:njw1,:) = uwmsk(njw0:njw1,:) * un (ji , njw0:njw1 , :) * umask(ji , njw0:njw1 , :)
-               vfow(njw0:njw1,:) = vwmsk(njw0:njw1,:) * vn (ji , njw0:njw1 , :) * vmask(ji , njw0:njw1 , :)
-            END DO
-         ENDIF
-
-         IF (lp_obc_north) THEN ! North
-            DO jj = njn0 , njn1
-               sfon(nin0:nin1,:) = tnmsk(nin0:nin1,:) * sn (nin0:nin1 , jj+1 , :) * tmask(nin0:nin1 , jj+1 , :)
-               tfon(nin0:nin1,:) = tnmsk(nin0:nin1,:) * tn (nin0:nin1 , jj+1 , :) * tmask(nin0:nin1 , jj+1 , :)
-               ufon(nin0:nin1,:) = unmsk(nin0:nin1,:) * un (nin0:nin1 , jj+1 , :) * umask(nin0:nin1 , jj+1 , :)
-               vfon(nin0:nin1,:) = vnmsk(nin0:nin1,:) * vn (nin0:nin1 , jj   , :) * vmask(nin0:nin1 , jj   , :)
-            END DO
-         ENDIF
-
-         IF (lp_obc_south) THEN ! South
-            DO jj = njs0 , njs1
-               sfos(nis0:nis1,:) = tsmsk(nis0:nis1,:) * sn (nis0:nis1 , jj , :) * tmask(nis0:nis1 , jj , :)
-               tfos(nis0:nis1,:) = tsmsk(nis0:nis1,:) * tn (nis0:nis1 , jj , :) * tmask(nis0:nis1 , jj , :)
-               ufos(nis0:nis1,:) = usmsk(nis0:nis1,:) * un (nis0:nis1 , jj , :) * umask(nis0:nis1 , jj , :)
-               vfos(nis0:nis1,:) = vsmsk(nis0:nis1,:) * vn (nis0:nis1 , jj , :) * vmask(nis0:nis1 , jj , :)
-            END DO
-         ENDIF
-         RETURN  ! exit the routine all is done
-      ENDIF  ! nobc_dta = 0 
-
-!!!! In the following OBC data are read from files.
-      ! all logical-mask are initialzed to true when declared
-      WHERE ( temsk == 0 ) ltemsk=.FALSE. 
-      WHERE ( uemsk == 0 ) luemsk=.FALSE. 
-      WHERE ( vemsk == 0 ) lvemsk=.FALSE. 
-
-      WHERE ( twmsk == 0 ) ltwmsk=.FALSE. 
-      WHERE ( uwmsk == 0 ) luwmsk=.FALSE. 
-      WHERE ( vwmsk == 0 ) lvwmsk=.FALSE. 
-
-      WHERE ( tnmsk == 0 ) ltnmsk=.FALSE. 
-      WHERE ( unmsk == 0 ) lunmsk=.FALSE. 
-      WHERE ( vnmsk == 0 ) lvnmsk=.FALSE. 
-
-      WHERE ( tsmsk == 0 ) ltsmsk=.FALSE. 
-      WHERE ( usmsk == 0 ) lusmsk=.FALSE. 
-      WHERE ( vsmsk == 0 ) lvsmsk=.FALSE. 
-
-      iyear=1950;  imonth=01; iday=01;  zsec=0. 
-      ! zjuliancnes : julian day corresonding  to  01/01/1950
-      CALL ymds2ju(iyear, imonth, iday,zsec , zjuliancnes)
-
-      !current year and curent month 
-      iyy=INT(ndastp/10000) ; imm=INT((ndastp -iyy*10000)/100) ; idd=(ndastp-iyy*10000-imm*100)
-      IF (iyy <  1900)  iyy = iyy+1900  ! always assume that years are on 4 digits.
-      CALL ymds2ju(iyy, imm, idd ,zsec , zjulian)
-      ndate0_cnes = zjulian - zjuliancnes   ! jcnes day when call to obc_dta_ini
-
-      iyyfile=iyy ; immfile=0  ! set component of the current file name
-      IF ( cffile /= 'annual') immfile=imm
-      IF ( ln_obc_clim) iyyfile = 0  ! assume that climatological files are labeled y0000
-
-      CALL obc_dta_chktime ( iyyfile, immfile )
-
-      IF ( itobc == 1 ) THEN 
-         ! in this case we will provide boundary data only once.
-         nt_a=1 ; ntobc_a=1
-         CALL obc_read (nit000, nt_a, ntobc_a, iyyfile, immfile) 
-         IF( lp_obc_east ) THEN
-            !  fills sfoe, tfoe, ufoe ,vfoe
-            sfoe(:,:) =  sedta (:,:,1) ; tfoe(:,:) =  tedta (:,:,1)
-            ufoe(:,:) =  uedta (:,:,1) ; vfoe(:,:) =  vedta (:,:,1)
-         ENDIF
-
-         IF( lp_obc_west) THEN
-            !  fills sfow, tfow, ufow ,vfow
-            sfow(:,:) =  swdta (:,:,1) ; tfow(:,:) =  twdta (:,:,1)
-            ufow(:,:) =  uwdta (:,:,1) ; vfow(:,:) =  vwdta (:,:,1)
-         ENDIF
-
-         IF( lp_obc_north) THEN
-            !  fills sfon, tfon, ufon ,vfon
-            sfon(:,:) =  sndta (:,:,1) ; tfon(:,:) =  tndta (:,:,1)
-            ufon(:,:) =  undta (:,:,1) ; vfon(:,:) =  vndta (:,:,1)
-         ENDIF
-
-         IF( lp_obc_south) THEN
-            !  fills sfos, tfos, ufos ,vfos
-            sfos(:,:) =  ssdta (:,:,1) ; tfos(:,:) =  tsdta (:,:,1)
-            ufos(:,:) =  usdta (:,:,1) ; vfos(:,:) =  vsdta (:,:,1)
-         ENDIF
-         RETURN  ! we go out of obc_dta_ini -------------------------------------->>>>>
-      ENDIF
-
-      ! nday_year is the day number in the current year ( 1 for 01/01 )
-      ! we suppose that we always start from the begining of a day
-      !    zsec=MOD( (kt-nit000)*rdt - (nday_year - nday_year0 )*rday, rday ) ! number of seconds in the current day
-      zsec=0.e0  ! here, kt=nit000, nday_year = ndat_year0 
-
-      IF (ln_obc_clim)  THEN 
-         zjcnes = nday_year - 1  + zsec/rday  ! for clim file time is in days in a year
-      ELSE
-         zjcnes = ndate0_cnes + (nday_year - nday_year0 ) + zsec/rday
-      ENDIF
-
-      ! look for 'before' record number in the current file
-      ntobc = nrecbef ()
-
-      IF (lwp) WRITE(numout,*) 'obc files frequency :',cffile
-      IF (lwp) WRITE(numout,*) ' zjcnes0 =',zjcnes,' ndastp0 =',ndastp
-      IF (lwp) WRITE(numout,*) ' annee0 ',iyy,' month0 ', imm,' day0 ', idd
-      IF (lwp) WRITE(numout,*) 'first file open :',cl_obc_nTS
-
-      ! record initialisation
-      !--------------------
-      nt_b = 1 ; nt_a = 2
-
-      ntobc_a = ntobc + 1
-      ntobc_b = ntobc
-
-      CALL obc_read (kt, nt_b, ntobc_b, iyyfile, immfile)  ! read 'before' fields
-      CALL obc_read (kt, nt_a, ntobc_a, iyyfile, immfile)  ! read 'after' fields
-
-      ! additional frame in case of time-splitting
-# if defined key_dynspg_ts
-      nt_m = 0
-      ntobc_m=mod(ntobc_b-2+itobc,itobc)+1
-      zjcnes_obc(nt_m)= ztcobc(ntobc_m) ! FDbug has not checked that this is correct!!
-      IF (ln_rstart) THEN
-         CALL obc_read (kt, nt_m, ntobc_m, iyyfile, immfile)  ! read 'after' fields
-      ENDIF
-# endif
-
-      zjcnes_obc(nt_b)= ztcobc(ntobc_b)
-      zjcnes_obc(nt_a)= ztcobc(ntobc_a)
-      ! 
-   END SUBROUTINE obc_dta_ini
-
-
-   SUBROUTINE obc_dta_chktime (kyyfile, kmmfile)
-      !
-      ! check the number of time steps in the files and read ztcobc 
-      !
-      ! * Arguments
-      INTEGER, INTENT(in) :: kyyfile, kmmfile
-      ! * local variables
-      INTEGER :: istop       ! error control
-      INTEGER :: ji          ! dummy loop index
-
-      INTEGER ::  idvar, id_e, id_w, id_n, id_s       ! file identifiers
-      INTEGER, DIMENSION(1)  :: itmp
-      CHARACTER(LEN=25) :: cl_vname
-
-      ntobc_a = 0; itobce =0 ; itobcw = 0; itobcn = 0; itobcs = 0
-      ! build file name
-      IF(ln_obc_clim) THEN   ! revert to old convention for climatological OBC forcing
-         cl_obc_eTS='obceast_TS.nc'
-         cl_obc_wTS='obcwest_TS.nc'
-         cl_obc_nTS='obcnorth_TS.nc'
-         cl_obc_sTS='obcsouth_TS.nc'
-      ELSE                   ! convention for climatological OBC
-         WRITE(cl_obc_eTS ,'("obc_east_TS_y",i4.4,"m",i2.2,".nc")'  ) kyyfile,kmmfile
-         WRITE(cl_obc_wTS ,'("obc_west_TS_y",i4.4,"m",i2.2,".nc")'  ) kyyfile,kmmfile
-         WRITE(cl_obc_nTS ,'("obc_north_TS_y",i4.4,"m",i2.2,".nc")' ) kyyfile,kmmfile
-         WRITE(cl_obc_sTS ,'("obc_south_TS_y",i4.4,"m",i2.2,".nc")' ) kyyfile,kmmfile
-      ENDIF
-
-      cl_vname = 'time_counter'
-      IF ( lp_obc_east ) THEN
-         CALL iom_open ( cl_obc_eTS , id_e )
-         idvar = iom_varid( id_e, cl_vname, kdimsz = itmp ); itobce=itmp(1)
-      ENDIF
-      IF ( lp_obc_west ) THEN
-         CALL iom_open ( cl_obc_wTS , id_w )
-         idvar = iom_varid( id_w, cl_vname, kdimsz = itmp ) ; itobcw=itmp(1)
-      ENDIF
-      IF ( lp_obc_north ) THEN
-         CALL iom_open ( cl_obc_nTS , id_n )
-         idvar = iom_varid( id_n, cl_vname, kdimsz = itmp ) ; itobcn=itmp(1)
-      ENDIF
-      IF ( lp_obc_south ) THEN
-         CALL iom_open ( cl_obc_sTS , id_s )
-         idvar = iom_varid( id_s, cl_vname, kdimsz = itmp ) ; itobcs=itmp(1)
-      ENDIF
-
-      itobc = MAX( itobce, itobcw, itobcn, itobcs )
-      istop = 0
-      IF ( lp_obc_east  .AND. itobce /= itobc ) istop = istop+1 
-      IF ( lp_obc_west  .AND. itobcw /= itobc ) istop = istop+1      
-      IF ( lp_obc_north .AND. itobcn /= itobc ) istop = istop+1
-      IF ( lp_obc_south .AND. itobcs /= itobc ) istop = istop+1 
-      nstop = nstop + istop
-
-      IF ( istop /=  0 )  THEN
-         WRITE(ctmp1,*) ' east, west, north, south: ', itobce, itobcw, itobcn, itobcs
-         CALL ctl_stop( 'obcdta : all files must have the same number of time steps', ctmp1 )
-      ENDIF
-
-      IF ( itobc == 1 ) THEN 
-         IF (lwp) THEN
-            WRITE(numout,*) ' obcdta found one time step only in the OBC files'
-            IF (ln_obc_clim) THEN
-               ! OK no problem
-            ELSE
-               ln_obc_clim=.true.
-               WRITE(numout,*) ' we force ln_obc_clim to T'
-            ENDIF
-         ENDIF
-      ELSE
-         IF ( ALLOCATED(ztcobc) ) DEALLOCATE ( ztcobc )
-         ALLOCATE (ztcobc(itobc))
-         DO ji=1,1   ! use a dummy loop to read ztcobc only once
-            IF ( lp_obc_east ) THEN
-               CALL iom_gettime ( id_e, ztcobc, cl_vname ) ; CALL iom_close (id_e) ; EXIT
-            ENDIF
-            IF ( lp_obc_west ) THEN
-               CALL iom_gettime ( id_w, ztcobc, cl_vname ) ; CALL iom_close (id_w) ; EXIT
-            ENDIF
-            IF ( lp_obc_north ) THEN
-               CALL iom_gettime ( id_n, ztcobc, cl_vname ) ; CALL iom_close (id_n) ; EXIT
-            ENDIF
-            IF ( lp_obc_south ) THEN
-               CALL iom_gettime ( id_s, ztcobc, cl_vname ) ; CALL iom_close (id_s) ; EXIT
-            ENDIF
-         END DO
-         rdt_obc = ztcobc(2)-ztcobc(1)  !  just an information, not used for any computation
-         IF (lwp) WRITE(numout,*) ' obcdta found', itobc,' time steps in the OBC files'
-         IF (lwp) WRITE(numout,*) ' time step of obc data :', rdt_obc,' days'            
-      ENDIF
-      zjcnes = zjcnes - rdt/rday  ! trick : zcnes is always incremented by rdt/rday in obc_dta!
-   END SUBROUTINE obc_dta_chktime
-
-# if defined key_dynspg_ts || defined key_dynspg_exp
-   SUBROUTINE obc_dta_bt( kt, kbt )
-      !!---------------------------------------------------------------------------
-      !!                      ***  SUBROUTINE obc_dta  ***
-      !!
-      !! ** Purpose :   time interpolation of barotropic data for time-splitting scheme
-      !!                Data at the boundary must be in m2/s 
-      !!
-      !! History :  9.0  !  05-11 (V. garnier) Original code
-      !!---------------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
-      INTEGER, INTENT( in ) ::   kbt         ! barotropic ocean time-step index
-      !
-      INTEGER ::   ji, jj  ! dummy loop indices
-      INTEGER ::   i15
-      INTEGER ::   itobcm, itobcp
-      REAL(wp) ::  zxy
-      INTEGER ::   isrel           ! number of seconds since 1/1/1992
-      !!---------------------------------------------------------------------------
-
-      ! 1.   First call: check time frames available in files.
-      ! -------------------------------------------------------
-
-      IF( kt == nit000 ) THEN
-
-         ! 1.1  Barotropic tangential velocities set to zero
-         ! -------------------------------------------------
-         IF( lp_obc_east  ) vbtfoe(:) = 0.e0
-         IF( lp_obc_west  ) vbtfow(:) = 0.e0
-         IF( lp_obc_south ) ubtfos(:) = 0.e0
-         IF( lp_obc_north ) ubtfon(:) = 0.e0
-
-         ! 1.2  Sea surface height and normal barotropic velocities set to zero
-         !                               or initial conditions if nobc_dta == 0
-         ! --------------------------------------------------------------------
-
-         IF( lp_obc_east ) THEN
-            ! initialisation to zero
-            sshedta(:,:) = 0.e0
-            ubtedta(:,:) = 0.e0
-            vbtedta(:,:) = 0.e0 ! tangential component
-            !                                        ! ================== !
-            IF( nobc_dta == 0 )   THEN               ! initial state used !
-               !                                     ! ================== !
-               !  Fills sedta, tedta, uedta (global arrays)
-               !  Remark: this works for njzoom = 1. Should the definition of ij include njzoom?
-               DO ji = nie0, nie1
-                  DO jj = 1, jpj
-                     sshedta(jj,1) = sshn(ji+1,jj) * tmask(ji+1,jj,1)
-                  END DO
-               END DO
-            ENDIF
-         ENDIF
-
-         IF( lp_obc_west) THEN
-            ! initialisation to zero
-            sshwdta(:,:) = 0.e0
-            ubtwdta(:,:) = 0.e0
-            vbtwdta(:,:) = 0.e0 ! tangential component
-            !                                        ! ================== !
-            IF( nobc_dta == 0 )   THEN               ! initial state used !
-               !                                     ! ================== !
-               !  Fills swdta, twdta, uwdta (global arrays)
-               !  Remark: this works for njzoom = 1. Should the definition of ij include njzoom?
-               DO ji = niw0, niw1
-                  DO jj = 1, jpj
-                     sshwdta(jj,1) = sshn(ji,jj) * tmask(ji,jj,1)
-                  END DO
-               END DO
-            ENDIF
-         ENDIF
-
-         IF( lp_obc_north) THEN
-            ! initialisation to zero
-            sshndta(:,:) = 0.e0
-            ubtndta(:,:) = 0.e0 ! tangential component
-            vbtndta(:,:) = 0.e0
-            !                                        ! ================== !
-            IF( nobc_dta == 0 ) THEN                 ! initial state used !
-               !                                     ! ================== !
-               !  Fills sndta, tndta, vndta (global arrays)
-               !  Remark: this works for njzoom = 1. Should the definition of ij include njzoom?
-               DO jj = njn0, njn1
-                  DO ji = 1, jpi
-                     sshndta(ji,1) = sshn(ji,jj+1) * tmask(ji,jj+1,1)
-                  END DO
-               END DO
-            ENDIF
-         ENDIF
-
-         IF( lp_obc_south) THEN
-            ! initialisation to zero
-            sshsdta(:,:) = 0.e0
-            ubtsdta(:,:) = 0.e0 ! tangential component
-            vbtsdta(:,:) = 0.e0
-            !                                        ! ================== !
-            IF( nobc_dta == 0 )   THEN               ! initial state used !
-               !                                     ! ================== !
-               !  Fills ssdta, tsdta, vsdta (global arrays)
-               !  Remark: this works for njzoom = 1. Should the definition of ij include njzoom?
-               DO jj = njs0, njs1
-                  DO ji = 1, jpi
-                     sshsdta(ji,1) = sshn(ji,jj) * tmask(ji,jj,1)
-                  END DO
-               END DO
-            ENDIF
-         ENDIF
-
-         IF( nobc_dta == 0 ) CALL obc_depth_average(1)   ! depth averaged velocity from the OBC depth-dependent frames
-
-      ENDIF        !       END kt == nit000
-
-      !!------------------------------------------------------------------------------------
-      ! 2.      Initialize the time we are at. Does this every time the routine is called,
-      !         excepted when nobc_dta = 0
-      !
-
-      ! 3.  Call at every time step : Linear interpolation of BCs to current time step
-      ! ----------------------------------------------------------------------
-
-      IF( lk_dynspg_ts ) THEN
-         isrel = (kt-1)*rdt + kbt*(rdt/REAL(nn_baro,wp))
-      ELSE IF( lk_dynspg_exp ) THEN
-         isrel=kt*rdt
-      ENDIF
-
-      itobcm = nt_b
-      itobcp = nt_a
-      IF( itobc == 1 .OR. nobc_dta == 0 ) THEN
-         zxy = 0.e0
-         itobcm = 1
-         itobcp = 1
-      ELSE IF( itobc == 12 ) THEN
-         i15   = nday / 16
-         zxy = FLOAT( nday + 15 - 30 * i15 ) / 30.
-      ELSE
-         zxy = (zjcnes_obc(nt_a)-FLOAT(isrel)) / (zjcnes_obc(nt_a)-zjcnes_obc(nt_b))
-         IF( zxy < 0. ) THEN   ! case of extrapolation, switch to old time frames
-            itobcm = nt_m
-            itobcp = nt_b
-            zxy = (zjcnes_obc(nt_b)-FLOAT(isrel)) / (zjcnes_obc(nt_b)-zjcnes_obc(nt_m))
-         ENDIF
-      ENDIF
-
-      IF( lp_obc_east ) THEN           !  fills sshfoe, ubtfoe (local to each processor)
-         DO jj = 1, jpj
-            sshfoe(jj) = zxy * sshedta(jj,itobcp) + (1.-zxy) * sshedta(jj,itobcm)
-            ubtfoe(jj) = zxy * ubtedta(jj,itobcp) + (1.-zxy) * ubtedta(jj,itobcm)
-            vbtfoe(jj) = zxy * vbtedta(jj,itobcp) + (1.-zxy) * vbtedta(jj,itobcm)
-         END DO
-      ENDIF
-
-      IF( lp_obc_west) THEN            !  fills sshfow, ubtfow (local to each processor)
-         DO jj = 1, jpj
-            sshfow(jj) = zxy * sshwdta(jj,itobcp) + (1.-zxy) * sshwdta(jj,itobcm)
-            ubtfow(jj) = zxy * ubtwdta(jj,itobcp) + (1.-zxy) * ubtwdta(jj,itobcm)
-            vbtfow(jj) = zxy * vbtwdta(jj,itobcp) + (1.-zxy) * vbtwdta(jj,itobcm)
-         END DO
-      ENDIF
-
-      IF( lp_obc_north) THEN           !  fills sshfon, vbtfon (local to each processor)
-         DO ji = 1, jpi
-            sshfon(ji) = zxy * sshndta(ji,itobcp) + (1.-zxy) * sshndta(ji,itobcm)
-            ubtfon(ji) = zxy * ubtndta(ji,itobcp) + (1.-zxy) * ubtndta(ji,itobcm)
-            vbtfon(ji) = zxy * vbtndta(ji,itobcp) + (1.-zxy) * vbtndta(ji,itobcm)
-         END DO
-      ENDIF
-
-      IF( lp_obc_south) THEN           !  fills sshfos, vbtfos (local to each processor)
-         DO ji = 1, jpi
-            sshfos(ji) = zxy * sshsdta(ji,itobcp) + (1.-zxy) * sshsdta(ji,itobcm)
-            ubtfos(ji) = zxy * ubtsdta(ji,itobcp) + (1.-zxy) * ubtsdta(ji,itobcm)
-            vbtfos(ji) = zxy * vbtsdta(ji,itobcp) + (1.-zxy) * vbtsdta(ji,itobcm)
-         END DO
-      ENDIF
-
-   END SUBROUTINE obc_dta_bt
-
-# else
-   !!-----------------------------------------------------------------------------
-   !!   Default option
-   !!-----------------------------------------------------------------------------
-   SUBROUTINE obc_dta_bt ( kt, kbt )       ! Empty routine
-      !! * Arguments
-      INTEGER,INTENT(in) :: kt
-      INTEGER, INTENT( in ) ::   kbt         ! barotropic ocean time-step index
-      WRITE(*,*) 'obc_dta_bt: You should not have seen this print! error?', kt
-      WRITE(*,*) 'obc_dta_bt: You should not have seen this print! error?', kbt
-   END SUBROUTINE obc_dta_bt
-# endif
-
-   SUBROUTINE obc_read (kt, nt_x, ntobc_x, iyy, imm)
-      !!-------------------------------------------------------------------------
-      !!                      ***  ROUTINE obc_read  ***
-      !!
-      !! ** Purpose :  Read the boundary data in files identified by iyy and imm
-      !!               According to the validated open boundaries, return the 
-      !!               following arrays :
-      !!                sedta, tedta : East OBC salinity and temperature
-      !!                uedta, vedta :   "   "  u and v velocity component      
-      !!
-      !!                swdta, twdta : West OBC salinity and temperature
-      !!                uwdta, vwdta :   "   "  u and v velocity component      
-      !!
-      !!                sndta, tndta : North OBC salinity and temperature
-      !!                undta, vndta :   "   "  u and v velocity component      
-      !!
-      !!                ssdta, tsdta : South OBC salinity and temperature
-      !!                usdta, vsdta :   "   "  u and v velocity component      
-      !!
-      !! ** Method  :  These fields are read in the record ntobc_x of the files.
-      !!               The number of records is already known. If  ntobc_x is greater
-      !!               than the number of record, this routine will look for next file,
-      !!               updating the indices (case of inter-annual obcs) or loop at the
-      !!               begining in case of climatological file (ln_obc_clim = true ).
-      !! -------------------------------------------------------------------------
-      !! History:     !  2005  ( P. Mathiot, C. Langlais ) Original code
-      !!              !  2008  ( J,M, Molines ) Use IOM and cleaning
-      !!--------------------------------------------------------------------------
-
-      ! * Arguments
-      INTEGER, INTENT( in ) :: kt, nt_x
-      INTEGER, INTENT( inout ) :: ntobc_x , iyy, imm      ! yes ! inout !
-
-      ! * Local variables
-      CHARACTER (len=40) :: &    ! file names
-         cl_obc_eTS   , cl_obc_eU,  cl_obc_eV,&
-         cl_obc_wTS   , cl_obc_wU,  cl_obc_wV,&
-         cl_obc_nTS   , cl_obc_nU,  cl_obc_nV,&
-         cl_obc_sTS   , cl_obc_sU,  cl_obc_sV
-
-      INTEGER :: ikprint
-      REAL(wp) :: zmin, zmax   ! control of boundary values
-
-      !IOM stuff
-      INTEGER :: id_e, id_w, id_n, id_s
-      INTEGER, DIMENSION(2) :: istart, icount
-
-      !--------------------------------------------------------------------------
-      IF ( ntobc_x > itobc ) THEN
-         IF (ln_obc_clim) THEN  ! just loop on the same file
-            ntobc_x = 1 
-         ELSE
-            ! need to change file : it is always for an 'after' data
-            IF ( cffile == 'annual' ) THEN ! go to next year file
-               iyy = iyy + 1
-            ELSE IF ( cffile =='monthly' ) THEN  ! go to next month file
-               imm = imm + 1 
-               IF ( imm == 13 ) THEN 
-                  imm = 1 ; iyy = iyy + 1
-               ENDIF
-            ELSE
-               ctmp1='obcread : this type of obc file is not supported :( '
-               ctmp2=TRIM(cffile)
-               CALL ctl_stop (ctmp1, ctmp2)
-               ! cffile should be either annual or monthly ...
-            ENDIF
-            ! as the file is changed, need to update itobc etc ...
-            CALL obc_dta_chktime (iyy,imm)
-            ntobc_x = nrecbef() + 1 ! remember : this case occur for an after data
-         ENDIF
-      ENDIF
-
-      IF( lp_obc_east ) THEN 
-         ! ... Read datafile and set temperature, salinity and normal velocity
-         ! ... initialise the sedta, tedta, uedta arrays
-         IF(ln_obc_clim) THEN  ! revert to old convention for climatological OBC forcing
-            cl_obc_eTS='obceast_TS.nc'
-            cl_obc_eU ='obceast_U.nc'
-            cl_obc_eV ='obceast_V.nc'
-         ELSE                  ! convention for climatological OBC
-            WRITE(cl_obc_eTS ,'("obc_east_TS_y"  ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-            WRITE(cl_obc_eU  ,'("obc_east_U_y"   ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-            WRITE(cl_obc_eV  ,'("obc_east_V_y"   ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-         ENDIF
-         ! JMM this may change depending on the obc data format ...
-         istart(:)=(/nje0+njmpp-1,1/) ; icount(:)=(/nje1-nje0 +1,jpk/)
-         IF (lwp) WRITE(numout,*) 'read data in :', TRIM(cl_obc_eTS)
-         IF (nje1 >= nje0 ) THEN
-            CALL iom_open ( cl_obc_eTS , id_e )
-            CALL iom_get ( id_e, jpdom_unknown, 'votemper', tedta(nje0:nje1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-            CALL iom_get ( id_e, jpdom_unknown, 'vosaline', sedta(nje0:nje1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-# if defined key_dynspg_ts || defined key_dynspg_exp
-            CALL iom_get ( id_e, jpdom_unknown, 'vossurfh', sshedta(nje0:nje1,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-# endif
-            CALL iom_close (id_e)
-            !
-            CALL iom_open ( cl_obc_eU , id_e )
-            CALL iom_get  ( id_e, jpdom_unknown, 'vozocrtx', uedta(nje0:nje1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-            CALL iom_close ( id_e )
-            !
-            CALL iom_open ( cl_obc_eV , id_e )
-            CALL iom_get ( id_e, jpdom_unknown, 'vomecrty', vedta(nje0:nje1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-            CALL iom_close ( id_e )
-
-            ! mask the boundary values
-            tedta(:,:,nt_x) = tedta(:,:,nt_x)*temsk(:,:) ;  sedta(:,:,nt_x) = sedta(:,:,nt_x)*temsk(:,:)
-            uedta(:,:,nt_x) = uedta(:,:,nt_x)*uemsk(:,:) ;  vedta(:,:,nt_x) = vedta(:,:,nt_x)*vemsk(:,:)
-
-            ! check any outliers 
-            zmin=MINVAL( sedta(:,:,nt_x), mask=ltemsk ) ; zmax=MAXVAL(sedta(:,:,nt_x), mask=ltemsk)
-            IF (  zmin < 5 .OR. zmax > 50)   THEN
-               CALL ctl_stop('Error in sedta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( tedta(:,:,nt_x), mask=ltemsk ) ; zmax=MAXVAL(tedta(:,:,nt_x), mask=ltemsk)
-            IF (  zmin < -10. .OR. zmax > 40)   THEN
-               CALL ctl_stop('Error in tedta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( uedta(:,:,nt_x), mask=luemsk ) ; zmax=MAXVAL(uedta(:,:,nt_x), mask=luemsk)
-            IF (  zmin < -5. .OR. zmax > 5.)   THEN
-               CALL ctl_stop('Error in uedta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( vedta(:,:,nt_x), mask=lvemsk ) ; zmax=MAXVAL(vedta(:,:,nt_x), mask=lvemsk)
-            IF (  zmin < -5. .OR. zmax > 5.)   THEN
-               CALL ctl_stop('Error in vedta',' routine obcdta')
-            ENDIF
-
-            !               Usually printout is done only once at kt = nit000, unless nprint (namelist) > 1      
-            IF ( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 )  ) THEN
-               WRITE(numout,*)
-               WRITE(numout,*) ' Read East OBC data records ', ntobc_x
-               ikprint = jpj/20 +1
-               WRITE(numout,*) ' Temperature  record 1 - printout every 3 level'
-               CALL prihre( tedta(:,:,nt_x), jpj, jpk, 1, jpj, ikprint, jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Salinity  record 1 - printout every 3 level'
-               CALL prihre( sedta(:,:,nt_x), jpj, jpk, 1, jpj, ikprint, jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Normal velocity U  record 1  - printout every 3 level'
-               CALL prihre( uedta(:,:,nt_x), jpj, jpk, 1, jpj, ikprint, jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Tangential velocity V  record 1  - printout every 3 level'
-               CALL prihre( vedta(:,:,nt_x), jpj, jpk, 1, jpj, ikprint, jpk, 1, -3, 1., numout )
-            ENDIF
-         ENDIF
-      ENDIF
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      IF ( lp_obc_west ) THEN
-         ! ... Read datafile and set temperature, salinity and normal velocity
-         ! ... initialise the swdta, twdta, uwdta arrays
-         IF (ln_obc_clim) THEN   ! revert to old convention for climatological OBC forcing
-            cl_obc_wTS='obcwest_TS.nc'
-            cl_obc_wU ='obcwest_U.nc'
-            cl_obc_wV ='obcwest_V.nc'
-         ELSE                    ! convention for climatological OBC
-            WRITE(cl_obc_wTS ,'("obc_west_TS_y"  ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-            WRITE(cl_obc_wU  ,'("obc_west_U_y"   ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-            WRITE(cl_obc_wV  ,'("obc_west_V_y"   ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-         ENDIF
-         istart(:)=(/njw0+njmpp-1,1/) ; icount(:)=(/njw1-njw0 +1,jpk/)
-         IF (lwp) WRITE(numout,*) 'read data in :', TRIM(cl_obc_wTS)
-
-         IF ( njw1 >= njw0 ) THEN
-            CALL iom_open ( cl_obc_wTS , id_w )
-            CALL iom_get ( id_w, jpdom_unknown, 'votemper', twdta(njw0:njw1,:,nt_x), & 
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-
-            CALL iom_get ( id_w, jpdom_unknown, 'vosaline', swdta(njw0:njw1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount)
-# if defined key_dynspg_ts || defined key_dynspg_exp
-            CALL iom_get ( id_w, jpdom_unknown, 'vossurfh', sshwdta(njw0:njw1,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-# endif
-            CALL iom_close (id_w)
-            !
-            CALL iom_open ( cl_obc_wU , id_w )
-            CALL iom_get  ( id_w, jpdom_unknown, 'vozocrtx', uwdta(njw0:njw1,:,nt_x),&
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-            CALL iom_close ( id_w )
-            !
-            CALL iom_open ( cl_obc_wV , id_w )
-            CALL iom_get ( id_w, jpdom_unknown, 'vomecrty', vwdta(njw0:njw1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-            CALL iom_close ( id_w )
-
-            ! mask the boundary values
-            twdta(:,:,nt_x) = twdta(:,:,nt_x)*twmsk(:,:) ;  swdta(:,:,nt_x) = swdta(:,:,nt_x)*twmsk(:,:)
-            uwdta(:,:,nt_x) = uwdta(:,:,nt_x)*uwmsk(:,:) ;  vwdta(:,:,nt_x) = vwdta(:,:,nt_x)*vwmsk(:,:)
-
-            ! check any outliers
-            zmin=MINVAL( swdta(:,:,nt_x), mask=ltwmsk ) ; zmax=MAXVAL(swdta(:,:,nt_x), mask=ltwmsk)
-            IF (  zmin < 5 .OR. zmax > 50)   THEN
-               CALL ctl_stop('Error in swdta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( twdta(:,:,nt_x), mask=ltwmsk ) ; zmax=MAXVAL(twdta(:,:,nt_x), mask=ltwmsk)
-            IF (  zmin < -10. .OR. zmax > 40)   THEN
-               CALL ctl_stop('Error in twdta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( uwdta(:,:,nt_x), mask=luwmsk ) ; zmax=MAXVAL(uwdta(:,:,nt_x), mask=luwmsk)
-            IF (  zmin < -5. .OR. zmax > 5.)   THEN
-               CALL ctl_stop('Error in uwdta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( vwdta(:,:,nt_x), mask=lvwmsk ) ; zmax=MAXVAL(vwdta(:,:,nt_x), mask=lvwmsk)
-            IF (  zmin < -5. .OR. zmax > 5.)   THEN
-               CALL ctl_stop('Error in vwdta',' routine obcdta')
-            ENDIF
-
-
-            IF ( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 )  ) THEN
-               WRITE(numout,*)
-               WRITE(numout,*) ' Read West OBC data records ', ntobc_x
-               ikprint = jpj/20 +1
-               WRITE(numout,*) ' Temperature  record 1 - printout every 3 level'
-               CALL prihre( twdta(:,:,nt_x), jpj, jpk, 1, jpj, ikprint, jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Salinity  record 1 - printout every 3 level'
-               CALL prihre( swdta(:,:,nt_x),jpj,jpk, 1, jpj, ikprint,   jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Normal velocity U  record 1  - printout every 3 level'
-               CALL prihre( uwdta(:,:,nt_x), jpj, jpk, 1, jpj, ikprint, jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Tangential velocity V  record 1  - printout every 3 level'
-               CALL prihre( vwdta(:,:,nt_x), jpj, jpk, 1, jpj, ikprint, jpk, 1, -3, 1., numout )
-            ENDIF
-         END IF
-      ENDIF
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      IF( lp_obc_north) THEN
-         IF(ln_obc_clim) THEN   ! revert to old convention for climatological OBC forcing
-            cl_obc_nTS='obcnorth_TS.nc'
-            cl_obc_nU ='obcnorth_U.nc'
-            cl_obc_nV ='obcnorth_V.nc'
-         ELSE                   ! convention for climatological OBC
-            WRITE(cl_obc_nTS ,'("obc_north_TS_y" ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-            WRITE(cl_obc_nV  ,'("obc_north_V_y"  ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-            WRITE(cl_obc_nU  ,'("obc_north_U_y"  ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-         ENDIF
-         istart(:)=(/nin0+nimpp-1,1/) ; icount(:)=(/nin1-nin0 +1,jpk/)
-         IF (lwp) WRITE(numout,*) 'read data in :', TRIM(cl_obc_nTS)
-         IF ( nin1 >= nin0 ) THEN
-            CALL iom_open ( cl_obc_nTS , id_n )
-            CALL iom_get ( id_n, jpdom_unknown, 'votemper', tndta(nin0:nin1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-            CALL iom_get ( id_n, jpdom_unknown, 'vosaline', sndta(nin0:nin1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-# if defined key_dynspg_ts || defined key_dynspg_exp
-            CALL iom_get ( id_n, jpdom_unknown, 'vossurfh', sshndta(nin0:nin1,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-# endif
-            CALL iom_close (id_n)
-            !
-            CALL iom_open ( cl_obc_nU , id_n )
-            CALL iom_get  ( id_n, jpdom_unknown, 'vozocrtx', undta(nin0:nin1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-            CALL iom_close ( id_n )
-            !
-            CALL iom_open ( cl_obc_nV , id_n )
-            CALL iom_get  ( id_n, jpdom_unknown, 'vomecrty', vndta(nin0:nin1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-            CALL iom_close ( id_n )
-
-            ! mask the boundary values
-            tndta(:,:,nt_x) = tndta(:,:,nt_x)*tnmsk(:,:) ;  sndta(:,:,nt_x) = sndta(:,:,nt_x)*tnmsk(:,:)
-            undta(:,:,nt_x) = undta(:,:,nt_x)*unmsk(:,:) ;  vndta(:,:,nt_x) = vndta(:,:,nt_x)*vnmsk(:,:)
-
-            ! check any outliers
-            zmin=MINVAL( sndta(:,:,nt_x), mask=ltnmsk ) ; zmax=MAXVAL(sndta(:,:,nt_x), mask=ltnmsk)
-            IF (  zmin < 5 .OR. zmax > 50)   THEN
-               CALL ctl_stop('Error in sndta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( tndta(:,:,nt_x), mask=ltnmsk ) ; zmax=MAXVAL(tndta(:,:,nt_x), mask=ltnmsk)
-            IF (  zmin < -10. .OR. zmax > 40)   THEN
-               CALL ctl_stop('Error in tndta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( undta(:,:,nt_x), mask=lunmsk ) ; zmax=MAXVAL(undta(:,:,nt_x), mask=lunmsk)
-            IF (  zmin < -5. .OR. zmax > 5.)   THEN
-               CALL ctl_stop('Error in undta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( vndta(:,:,nt_x), mask=lvnmsk ) ; zmax=MAXVAL(vndta(:,:,nt_x), mask=lvnmsk)
-            IF (  zmin < -5. .OR. zmax > 5.)   THEN
-               CALL ctl_stop('Error in vndta',' routine obcdta')
-            ENDIF
-
-            IF ( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 )  ) THEN
-               WRITE(numout,*)
-               WRITE(numout,*) ' Read North OBC data records ', ntobc_x
-               ikprint = jpi/20 +1
-               WRITE(numout,*) ' Temperature  record 1 - printout every 3 level'
-               CALL prihre( tndta(:,:,nt_x), jpi, jpk, 1, jpi, ikprint, jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Salinity  record 1 - printout every 3 level'
-               CALL prihre( sndta(:,:,nt_x), jpi, jpk, 1, jpi, ikprint, jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Normal velocity V  record 1  - printout every 3 level'
-               CALL prihre( vndta(:,:,nt_x), jpi, jpk, 1, jpi, ikprint, jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Tangential  velocity U  record 1  - printout every 3 level'
-               CALL prihre( undta(:,:,nt_x), jpi, jpk, 1, jpi, ikprint, jpk, 1, -3, 1., numout )
-            ENDIF
-         ENDIF
-      ENDIF
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      IF( lp_obc_south) THEN 
-         IF(ln_obc_clim) THEN   ! revert to old convention for climatological OBC forcing
-            cl_obc_sTS='obcsouth_TS.nc'
-            cl_obc_sU ='obcsouth_U.nc'
-            cl_obc_sV ='obcsouth_V.nc'
-         ELSE                    ! convention for climatological OBC
-            WRITE(cl_obc_sTS ,'("obc_south_TS_y" ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-            WRITE(cl_obc_sV  ,'("obc_south_V_y"  ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-            WRITE(cl_obc_sU  ,'("obc_south_U_y"  ,i4.4,"m",i2.2,".nc")' ) iyy,imm
-         ENDIF
-         istart(:)=(/nis0+nimpp-1,1/) ; icount(:)=(/nis1-nis0 +1,jpk/)
-         IF (lwp) WRITE(numout,*) 'read data in :', TRIM(cl_obc_sTS)
-         IF ( nis1 >= nis0 ) THEN 
-            CALL iom_open ( cl_obc_sTS , id_s )
-            CALL iom_get ( id_s, jpdom_unknown, 'votemper', tsdta(nis0:nis1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-            CALL iom_get ( id_s, jpdom_unknown, 'vosaline', ssdta(nis0:nis1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-# if defined key_dynspg_ts || defined key_dynspg_exp
-            CALL iom_get ( id_s, jpdom_unknown, 'vossurfh', sshsdta(nis0:nis1,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-# endif
-            CALL iom_close (id_s)
-            !
-            CALL iom_open ( cl_obc_sU , id_s )
-            CALL iom_get  ( id_s, jpdom_unknown, 'vozocrtx', usdta(nis0:nis1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-            CALL iom_close ( id_s )
-            !
-            CALL iom_open ( cl_obc_sV , id_s )
-            CALL iom_get  ( id_s, jpdom_unknown, 'vomecrty', vsdta(nis0:nis1,:,nt_x), &
-               &               ktime=ntobc_x , kstart=istart, kcount= icount )
-            CALL iom_close ( id_s )
-
-            ! mask the boundary values
-            tsdta(:,:,nt_x) = tsdta(:,:,nt_x)*tsmsk(:,:) ;  ssdta(:,:,nt_x) = ssdta(:,:,nt_x)*tsmsk(:,:)
-            usdta(:,:,nt_x) = usdta(:,:,nt_x)*usmsk(:,:) ;  vsdta(:,:,nt_x) = vsdta(:,:,nt_x)*vsmsk(:,:)
-
-            ! check any outliers
-            zmin=MINVAL( ssdta(:,:,nt_x), mask=ltsmsk ) ; zmax=MAXVAL(ssdta(:,:,nt_x), mask=ltsmsk)
-            IF (  zmin < 5 .OR. zmax > 50)   THEN
-               CALL ctl_stop('Error in ssdta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( tsdta(:,:,nt_x), mask=ltsmsk ) ; zmax=MAXVAL(tsdta(:,:,nt_x), mask=ltsmsk)
-            IF (  zmin < -10. .OR. zmax > 40)   THEN
-               CALL ctl_stop('Error in tsdta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( usdta(:,:,nt_x), mask=lusmsk ) ; zmax=MAXVAL(usdta(:,:,nt_x), mask=lusmsk)
-            IF (  zmin < -5. .OR. zmax > 5.)   THEN
-               CALL ctl_stop('Error in usdta',' routine obcdta')
-            ENDIF
-            zmin=MINVAL( vsdta(:,:,nt_x), mask=lvsmsk ) ; zmax=MAXVAL(vsdta(:,:,nt_x), mask=lvsmsk)
-            IF (  zmin < -5. .OR. zmax > 5.)   THEN
-               CALL ctl_stop('Error in vsdta',' routine obcdta')
-            ENDIF
-
-            IF ( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 )  ) THEN
-               WRITE(numout,*)
-               WRITE(numout,*) ' Read South OBC data records ', ntobc_x
-               ikprint = jpi/20 +1
-               WRITE(numout,*) ' Temperature  record 1 - printout every 3 level'
-               CALL prihre( tsdta(:,:,nt_x), jpi, jpk, 1, jpi, ikprint, jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Salinity  record 1 - printout every 3 level'
-               CALL prihre( ssdta(:,:,nt_x), jpi, jpk, 1, jpi, ikprint, jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Normal velocity V  record 1  - printout every 3 level'
-               CALL prihre( vsdta(:,:,nt_x), jpi, jpk, 1, jpi, ikprint, jpk, 1, -3, 1., numout )
-               WRITE(numout,*)
-               WRITE(numout,*) ' Tangential velocity U  record 1  - printout every 3 level'
-               CALL prihre( usdta(:,:,nt_x), jpi, jpk, 1, jpi, ikprint, jpk, 1, -3, 1., numout )
-            ENDIF
-         ENDIF
-      ENDIF
-
-# if defined key_dynspg_ts || defined key_dynspg_exp
-      CALL obc_depth_average(nt_x)   ! computation of depth-averaged velocity
-# endif
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   END SUBROUTINE obc_read
-
-
-   INTEGER FUNCTION nrecbef()
-      !!-----------------------------------------------------------------------
-      !!                     ***    FUNCTION nrecbef   ***
-      !!
-      !!  Purpose : - provide the before record number in files, with respect to zjcnes
-      !!
-      !!    History : 2008-04 : ( J.M. Molines ) Original code
-      !!-----------------------------------------------------------------------
-
-      INTEGER :: it , idum
-
-      idum = itobc
-      DO it =1, itobc
-         IF ( ztcobc(it) > zjcnes ) THEN ;  idum = it - 1 ; EXIT ;  ENDIF
-         ENDDO
-         ! idum can be 0 (climato, before first record)
-         IF ( idum == 0 ) THEN
-            IF ( ln_obc_clim ) THEN
-               idum = itobc
-            ELSE
-               ctmp1='obc_dta: find ntobc == 0 for  non climatological file '
-               ctmp2='consider adding a first record in your data file '
-               CALL ctl_stop(ctmp1, ctmp2)
-            ENDIF
-         ENDIF
-         ! idum can be itobc ( zjcnes > ztcobc (itobc) )
-         !  This is not a problem ...
-         nrecbef = idum
-
-      END FUNCTION nrecbef
-
-
-      SUBROUTINE obc_depth_average(nt_x)
-         !!-----------------------------------------------------------------------
-         !!                     ***    ROUTINE obc_depth_average   ***
-         !!
-         !!  Purpose : - compute the depth-averaged velocity from depth-dependent OBC frames
-         !!
-         !!    History : 2009-01 : ( Fred Dupont ) Original code
-         !!-----------------------------------------------------------------------
-
-         ! * Arguments
-         INTEGER, INTENT( in ) :: nt_x
-
-         ! * Local variables
-         INTEGER :: ji, jj, jk
-
-
-         IF( lp_obc_east ) THEN
-            ! initialisation to zero
-            ubtedta(:,nt_x) = 0.e0
-            vbtedta(:,nt_x) = 0.e0
-            DO ji = nie0, nie1
-               DO jj = 1, jpj
-                  DO jk = 1, jpkm1
-                     ubtedta(jj,nt_x) = ubtedta(jj,nt_x) + uedta(jj,jk,nt_x)*fse3u(ji,jj,jk)
-                     vbtedta(jj,nt_x) = vbtedta(jj,nt_x) + vedta(jj,jk,nt_x)*fse3v(ji+1,jj,jk)
-                  END DO
-               END DO
-            END DO
-         ENDIF
-
-         IF( lp_obc_west) THEN
-            ! initialisation to zero
-            ubtwdta(:,nt_x) = 0.e0
-            vbtwdta(:,nt_x) = 0.e0
-            DO ji = niw0, niw1
-               DO jj = 1, jpj
-                  DO jk = 1, jpkm1
-                     ubtwdta(jj,nt_x) = ubtwdta(jj,nt_x) + uwdta(jj,jk,nt_x)*fse3u(ji,jj,jk)
-                     vbtwdta(jj,nt_x) = vbtwdta(jj,nt_x) + vwdta(jj,jk,nt_x)*fse3v(ji,jj,jk)
-                  END DO
-               END DO
-            END DO
-         ENDIF
-
-         IF( lp_obc_north) THEN
-            ! initialisation to zero
-            ubtndta(:,nt_x) = 0.e0
-            vbtndta(:,nt_x) = 0.e0
-            DO jj = njn0, njn1
-               DO ji = 1, jpi
-                  DO jk = 1, jpkm1
-                     ubtndta(ji,nt_x) = ubtndta(ji,nt_x) + undta(ji,jk,nt_x)*fse3u(ji,jj+1,jk)
-                     vbtndta(ji,nt_x) = vbtndta(ji,nt_x) + vndta(ji,jk,nt_x)*fse3v(ji,jj,jk)
-                  END DO
-               END DO
-            END DO
-         ENDIF
-
-         IF( lp_obc_south) THEN
-            ! initialisation to zero
-            ubtsdta(:,nt_x) = 0.e0
-            vbtsdta(:,nt_x) = 0.e0
-            DO jj = njs0, njs1
-               DO ji = nis0, nis1
-                  DO jk = 1, jpkm1
-                     ubtsdta(ji,nt_x) = ubtsdta(ji,nt_x) + usdta(ji,jk,nt_x)*fse3u(ji,jj,jk)
-                     vbtsdta(ji,nt_x) = vbtsdta(ji,nt_x) + vsdta(ji,jk,nt_x)*fse3v(ji,jj,jk)
-                  END DO
-               END DO
-            END DO
-         ENDIF
-
-      END SUBROUTINE obc_depth_average
-
-#else
-      !!------------------------------------------------------------------------------
-      !!   default option:           Dummy module          NO Open Boundary Conditions
-      !!------------------------------------------------------------------------------
-   CONTAINS
-      SUBROUTINE obc_dta( kt )             ! Dummy routine
-         INTEGER, INTENT (in) :: kt
-         WRITE(*,*) 'obc_dta: You should not have seen this print! error?', kt
-      END SUBROUTINE obc_dta
-#endif
+   SUBROUTINE obc_dta_init()                  ! Empty routine
+      WRITE(*,*) 'obc_dta_init: You should not have seen this print! error?'
+   END SUBROUTINE obc_dta_init
+#endif
+
    !!==============================================================================
-   END MODULE obcdta
+END MODULE obcdta
Index: anches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdyn.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdyn.F90	(revision 2796)
+++ 	(revision )
@@ -1,702 +1,0 @@
-MODULE obcdyn
-#if defined key_obc
-   !!=================================================================================
-   !!                       ***  MODULE  obcdyn  ***
-   !! Ocean dynamics:   Radiation of velocities on each open boundary
-   !!=================================================================================
-
-   !!---------------------------------------------------------------------------------
-   !!   obc_dyn        : call the subroutine for each open boundary
-   !!   obc_dyn_east   : radiation of the east open boundary velocities
-   !!   obc_dyn_west   : radiation of the west open boundary velocities
-   !!   obc_dyn_north  : radiation of the north open boundary velocities
-   !!   obc_dyn_south  : radiation of the south open boundary velocities
-   !!----------------------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------------------
-   !! * Modules used
-   USE oce             ! ocean dynamics and tracers 
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE obc_oce         ! ocean open boundary conditions
-   USE lbclnk          ! ???
-   USE lib_mpp         ! ???
-   USE in_out_manager  ! I/O manager
-   USE dynspg_oce
-
-   IMPLICIT NONE
-   PRIVATE
-
-   !! * Accessibility
-   PUBLIC obc_dyn     ! routine called in dynspg_flt (free surface case)
-
-   !! * Module variables
-   INTEGER ::   ji, jj, jk     ! dummy loop indices
-
-   INTEGER ::      & ! ... boundary space indices 
-      nib   = 1,   & ! nib   = boundary point
-      nibm  = 2,   & ! nibm  = 1st interior point
-      nibm2 = 3,   & ! nibm2 = 2nd interior point
-                     ! ... boundary time indices 
-      nit   = 1,   & ! nit    = now
-      nitm  = 2,   & ! nitm   = before
-      nitm2 = 3      ! nitm2  = before-before
-
-   REAL(wp) ::   rtaue  , rtauw  , rtaun  , rtaus  ,  &
-                 rtauein, rtauwin, rtaunin, rtausin
-
-   !!---------------------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE obc_dyn ( kt )
-      !!------------------------------------------------------------------------------
-      !!                      SUBROUTINE obc_dyn
-      !!                     ********************
-      !! ** Purpose :
-      !!      Compute  dynamics (u,v) at the open boundaries.
-      !!      if defined key_dynspg_flt: 
-      !!                 this routine is called by dynspg_flt and updates
-      !!                 ua, va which are the actual velocities (not trends)
-      !!
-      !!      The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north, 
-      !!      and/or lp_obc_south allow the user to determine which boundary is an
-      !!      open one (must be done in the param_obc.h90 file).
-      !!
-      !! ** Reference : 
-      !!      Marchesiello P., 1995, these de l'universite J. Fourier, Grenoble, France.
-      !!
-      !! History :
-      !!        !  95-03 (J.-M. Molines) Original, SPEM
-      !!        !  97-07 (G. Madec, J.-M. Molines) addition
-      !!   8.5  !  02-10 (C. Talandier, A-M. Treguier) Free surface, F90
-      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !!----------------------------------------------------------------------
-      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
-      !! $Id$ 
-      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
-      !!----------------------------------------------------------------------
-
-      ! 0. Local constant initialization
-      ! --------------------------------
-
-      IF( kt == nit000 .OR. ln_rstart) THEN
-         ! ... Boundary restoring coefficient
-         rtaue = 2. * rdt / rdpeob
-         rtauw = 2. * rdt / rdpwob
-         rtaun = 2. * rdt / rdpnob
-         rtaus = 2. * rdt / rdpsob
-         ! ... Boundary restoring coefficient for inflow ( all boundaries)
-         rtauein = 2. * rdt / rdpein 
-         rtauwin = 2. * rdt / rdpwin
-         rtaunin = 2. * rdt / rdpnin
-         rtausin = 2. * rdt / rdpsin 
-      END IF
-
-      IF( lp_obc_east  )   CALL obc_dyn_east ( kt )
-      IF( lp_obc_west  )   CALL obc_dyn_west ( kt )
-      IF( lp_obc_north )   CALL obc_dyn_north( kt )
-      IF( lp_obc_south )   CALL obc_dyn_south( kt )
-
-      IF( lk_mpp ) THEN
-         IF( kt >= nit000+3 .AND. ln_rstart ) THEN
-            CALL lbc_lnk( ub, 'U', -1. )
-            CALL lbc_lnk( vb, 'V', -1. )
-         END IF
-         CALL lbc_lnk( ua, 'U', -1. )
-         CALL lbc_lnk( va, 'V', -1. )
-      ENDIF
-
-   END SUBROUTINE obc_dyn
-
-
-   SUBROUTINE obc_dyn_east ( kt )
-      !!------------------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_dyn_east  ***
-      !!              
-      !! ** Purpose :
-      !!      Apply the radiation algorithm on east OBC velocities ua, va using the 
-      !!      phase velocities calculated in obc_rad_east subroutine in obcrad.F90 module
-      !!      If the logical lfbceast is .TRUE., there is no radiation but only fixed OBC
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
-      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declaration
-      REAL(wp) ::   z05cx, ztau, zin
-      !!------------------------------------------------------------------------------
-
-      ! 1. First three time steps and more if lfbceast is .TRUE.
-      !    In that case open boundary conditions are FIXED.
-      ! --------------------------------------------------------
-
-      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbceast .OR. lk_dynspg_exp ) THEN
-
-         ! 1.1 U zonal velocity    
-         ! --------------------
-         DO ji = nie0, nie1
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  ua(ji,jj,jk) = ua(ji,jj,jk) * (1.-uemsk(jj,jk)) + &
-                                 uemsk(jj,jk)*ufoe(jj,jk)
-               END DO
-            END DO
-         END DO
-
-         ! 1.2 V meridional velocity
-         ! -------------------------
-         DO ji = nie0+1, nie1+1
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  va(ji,jj,jk) = va(ji,jj,jk) * (1.-vemsk(jj,jk)) + &
-                                 vfoe(jj,jk)*vemsk(jj,jk)
-               END DO
-            END DO
-         END DO
-
-      ELSE
-
-      ! 2. Beyond the fourth time step if lfbceast is .FALSE.
-      ! -----------------------------------------------------
- 
-         ! 2.1. u-component of the velocity
-         ! ---------------------------------
-         !
-         !          nibm2      nibm      nib
-         !            |   nibm  |   nib   |///
-         !            |    |    |    |    |///
-         !  jj-line --f----v----f----v----f---
-         !            |    |    |    |    |///
-         !            |         |         |///
-         !  jj-line   u    T    u    T    u///
-         !            |         |         |///
-         !            |    |    |    |    |///
-         !          jpieob-2   jpieob-1   jpieob
-         !                 |         |        
-         !              jpieob-1    jpieob    
-         !  
-         ! ... If free surface formulation:
-         ! ... radiative conditions on the total part + relaxation toward climatology
-         ! ... (jpjedp1, jpjefm1),jpieob
-         DO ji = nie0, nie1
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  z05cx = u_cxebnd(jj,jk)
-                  z05cx = z05cx / e1t(ji,jj)
-                  z05cx = min( z05cx, 1. )
-         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
-         !           > 0, outflow zin=1, ztau=rtaue
-                  zin = sign( 1., z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-         ! ... for inflow rtauein is used for relaxation coefficient else rtaue
-                  ztau = (1.-zin ) * rtauein  + zin * rtaue
-                  z05cx = z05cx * zin
-         ! ... update ua with radiative or climatological velocity
-                  ua(ji,jj,jk) = ua(ji,jj,jk) * ( 1. - uemsk(jj,jk) ) +          &
-                                 uemsk(jj,jk) * (  ( 1. - z05cx - ztau )         &
-                                 * uebnd(jj,jk,nib ,nitm) + 2.*z05cx               &
-                                 * uebnd(jj,jk,nibm,nit ) + ztau * ufoe (jj,jk) )  &
-                                 / (1. + z05cx)
-               END DO
-            END DO
-         END DO
-
-         ! 2.2 v-component of the velocity
-         ! -------------------------------
-         !
-         !          nibm2       nibm     nib
-         !            |   nibm  |   nib///|///
-         !            |    |    |    |////|///
-         !  jj-line --v----f----v----f----v---
-         !            |    |    |    |////|///
-         !            |    |    |    |////|///
-         !            | jpieob-1 |  jpieob /|///
-         !            |         |         |   
-         !         jpieob-1    jpieob     jpieob+1
-         !
-         ! ... radiative condition
-         ! ... (jpjedp1, jpjefm1), jpieob+1
-         DO ji = nie0+1, nie1+1
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  z05cx = v_cxebnd(jj,jk) 
-                  z05cx = z05cx / e1f(ji-1,jj)
-                  z05cx = min( z05cx, 1. )
-         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
-         !           > 0, outflow zin=1, ztau=rtaue
-                  zin = sign( 1., z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-         ! ... for inflow rtauein is used for relaxation coefficient else rtaue
-                  ztau = (1.-zin ) * rtauein  + zin * rtaue
-                  z05cx = z05cx * zin
-         ! ... update va with radiative or climatological velocity
-                  va(ji,jj,jk) = va(ji,jj,jk) * (1. - vemsk(jj,jk) ) +          &
-                                 vemsk(jj,jk) * ( ( 1. - z05cx - ztau )         &
-                                 * vebnd(jj,jk,nib ,nitm) + 2.*z05cx              &
-                                 * vebnd(jj,jk,nibm,nit ) + ztau * vfoe(jj,jk) )  &
-                                 / (1. + z05cx)
-               END DO
-            END DO
-         END DO
-
-      END IF
-
-   END SUBROUTINE obc_dyn_east
-
-
-   SUBROUTINE obc_dyn_west ( kt )
-      !!------------------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_dyn_west  ***
-      !!                  
-      !! ** Purpose :
-      !!      Apply the radiation algorithm on west OBC velocities ua, va using the 
-      !!      phase velocities calculated in obc_rad_west subroutine in obcrad.F90 module
-      !!      If the logical lfbcwest is .TRUE., there is no radiation but only fixed OBC
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
-      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declaration
-      REAL(wp) ::   z05cx, ztau, zin
-      !!------------------------------------------------------------------------------
-
-      ! 1. First three time steps and more if lfbcwest is .TRUE.
-      !    In that case open boundary conditions are FIXED.
-      ! --------------------------------------------------------
-
-      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcwest .OR. lk_dynspg_exp ) THEN
-
-         ! 1.1 U zonal velocity
-         ! ---------------------
-         DO ji = niw0, niw1
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  ua(ji,jj,jk) = ua(ji,jj,jk) * (1.-uwmsk(jj,jk)) + &
-                                 uwmsk(jj,jk)*ufow(jj,jk)
-               END DO
-            END DO
-         END DO
-
-         ! 1.2 V meridional velocity
-         ! -------------------------
-         DO ji = niw0, niw1
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  va(ji,jj,jk) = va(ji,jj,jk) * (1.-vwmsk(jj,jk)) + &
-                                 vfow(jj,jk)*vwmsk(jj,jk)
-               END DO
-            END DO
-         END DO
-
-      ELSE
-
-      ! 2. Beyond the fourth time step if lfbcwest is .FALSE.
-      ! -----------------------------------------------------
- 
-         ! 2.1. u-component of the velocity
-         ! ---------------------------------
-         !
-         !        nib       nibm     nibm2
-         !      ///|   nib   |   nibm  |
-         !      ///|    |    |    |    |
-         !      ---f----v----f----v----f-- jj-line
-         !      ///|    |    |    |    |
-         !      ///|         |         |
-         !      ///u    T    u    T    u   jj-line
-         !      ///|         |         |
-         !      ///|    |    |    |    |
-         !       jpiwob    jpiwob+1    jpiwob+2
-         !              |         |        
-         !            jpiwob+1    jpiwob+2     
-         !
-         ! ... If free surface formulation:
-         ! ... radiative conditions on the total part + relaxation toward climatology
-         ! ... (jpjwdp1, jpjwfm1), jpiwob
-         DO ji = niw0, niw1
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  z05cx = u_cxwbnd(jj,jk)
-                  z05cx = z05cx / e1t(ji+1,jj)
-                  z05cx = max( z05cx, -1. )
-         ! ... z05c  > 0, inflow  zin=0, ztau=1    
-         !          =< 0, outflow zin=1, ztau=rtauw
-                  zin = sign( 1., -1. * z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-                  ztau = (1.-zin )* rtauwin + zin * rtauw
-                  z05cx = z05cx * zin
-         ! ... update un with radiative or climatological velocity
-                  ua(ji,jj,jk) = ua(ji,jj,jk) * ( 1. - uwmsk(jj,jk) ) +          &
-                                 uwmsk(jj,jk) * ( ( 1. + z05cx - ztau )          &
-                                 * uwbnd(jj,jk,nib ,nitm) - 2.*z05cx               &
-                                 * uwbnd(jj,jk,nibm,nit ) + ztau  * ufow (jj,jk) ) &
-                                 / (1. - z05cx)
-               END DO
-            END DO
-         END DO
-
-         ! 2.2 v-component of the velocity
-         ! -------------------------------
-         !
-         !    nib       nibm     nibm2
-         !  ///|///nib   |   nibm  |  nibm2
-         !  ///|////|    |    |    |    |    |
-         !  ---v----f----v----f----v----f----v-- jj-line
-         !  ///|////|    |    |    |    |    |
-         !  ///|////|    |    |    |    |    |
-         ! jpiwob     jpiwob+1    jpiwob+2
-         !          |         |         |   
-         !        jpiwob   jpiwob+1   jpiwob+2    
-         !
-         ! ... radiative condition plus Raymond-Kuo
-         ! ... (jpjwdp1, jpjwfm1),jpiwob
-         DO ji = niw0, niw1
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  z05cx = v_cxwbnd(jj,jk)  
-                  z05cx = z05cx / e1f(ji,jj)
-                  z05cx = max( z05cx, -1. )
-         ! ... z05cx > 0, inflow  zin=0, ztau=1    
-         !          =< 0, outflow zin=1, ztau=rtauw
-                  zin = sign( 1., -1. * z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-                  ztau = (1.-zin )*rtauwin + zin * rtauw
-                  z05cx = z05cx * zin 
-         ! ... update va with radiative or climatological velocity
-                  va(ji,jj,jk) = va(ji,jj,jk) * (1. - vwmsk(jj,jk) ) +          &
-                                 vwmsk(jj,jk) * ( ( 1. + z05cx - ztau )         &
-                                 * vwbnd(jj,jk,nib ,nitm) - 2.*z05cx              &
-                                 * vwbnd(jj,jk,nibm,nit ) + ztau * vfow (jj,jk) ) &
-                                 / (1. - z05cx)
-                END DO
-             END DO
-         END DO
-
-      END IF
-
-   END SUBROUTINE obc_dyn_west
-
-   SUBROUTINE obc_dyn_north ( kt )
-      !!------------------------------------------------------------------------------
-      !!                     SUBROUTINE obc_dyn_north
-      !!                    *************************
-      !! ** Purpose :
-      !!      Apply the radiation algorithm on north OBC velocities ua, va using the 
-      !!      phase velocities calculated in obc_rad_north subroutine in obcrad.F90 module
-      !!      If the logical lfbcnorth is .TRUE., there is no radiation but only fixed OBC
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
-      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declaration
-      REAL(wp) ::   z05cx, ztau, zin
-      !!------------------------------------------------------------------------------
-
-      ! 1. First three time steps and more if lfbcnorth is .TRUE.
-      !    In that case open boundary conditions are FIXED.
-      ! ---------------------------------------------------------
- 
-      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcnorth  .OR. lk_dynspg_exp ) THEN
-
-         ! 1.1 U zonal velocity
-         ! --------------------
-         DO jj = njn0+1, njn1+1
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  ua(ji,jj,jk)= ua(ji,jj,jk) * (1.-unmsk(ji,jk)) + &
-                                ufon(ji,jk)*unmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-
-         ! 1.2 V meridional velocity
-         ! -------------------------
-         DO jj = njn0, njn1
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  va(ji,jj,jk)= va(ji,jj,jk) * (1.-vnmsk(ji,jk)) + &
-                                vfon(ji,jk)*vnmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-
-      ELSE
-
-      ! 2. Beyond the fourth time step if lfbcnorth is .FALSE.
-      ! ------------------------------------------------------
-
-         ! 2.1. u-component of the velocity
-         ! --------------------------------
-         !
-         !            ji-row
-         !              |
-         !       nib ///u//////  jpjnob + 1
-         !         /////|//////
-         !     nib -----f-----   jpjnob
-         !              |    
-         !      nibm--  u   ---- jpjnob
-         !              |        
-         !    nibm -----f-----   jpjnob-1
-         !              |        
-         !     nibm2--  u   ---- jpjnob-1
-         !              |        
-         !   nibm2 -----f-----   jpjnob-2
-         !              |
-         !
-         ! ... radiative condition
-         ! ... jpjnob+1,(jpindp1, jpinfm1)
-         DO jj = njn0+1, njn1+1
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  z05cx= u_cynbnd(ji,jk) 
-                  z05cx = z05cx / e2f(ji, jj-1)
-                  z05cx = min( z05cx, 1. )
-         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
-         !           > 0, outflow zin=1, ztau=rtaun
-                  zin = sign( 1., z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-         ! ... for inflow rtaunin is used for relaxation coefficient else rtaun
-                  ztau = (1.-zin ) * rtaunin  + zin * rtaun
-         ! ... for u, when inflow, ufon is prescribed
-                  z05cx = z05cx * zin
-         ! ... update un with radiative or climatological velocity
-                  ua(ji,jj,jk) = ua(ji,jj,jk) * (1.-unmsk(ji,jk)) +             &
-                                 unmsk(ji,jk) * ( ( 1. - z05cx - ztau )         &
-                                 * unbnd(ji,jk,nib ,nitm) + 2.*z05cx              &
-                                 * unbnd(ji,jk,nibm,nit ) + ztau * ufon (ji,jk) ) &
-                                 / (1. + z05cx)
-               END DO
-            END DO
-         END DO
-
-         ! 2.2 v-component of the velocity
-         ! -------------------------------
-         !
-         !                ji-row    ji-row
-         !              |         |
-         !         /////|/////////////////
-         !    nib  -----f----v----f----  jpjnob
-         !              |         |
-         !      nib  -  u -- T -- u ---- jpjnob
-         !              |         |
-         !   nibm  -----f----v----f----  jpjnob-1
-         !              |         |
-         !     nibm --  u -- T -- u ---  jpjnob-1
-         !              |         |
-         !   nibm2 -----f----v----f----  jpjnob-2
-         !              |         |
-         !
-         ! ... Free surface formulation:
-         ! ... radiative conditions on the total part + relaxation toward climatology
-         ! ... jpjnob,(jpindp1, jpinfm1)
-         DO jj = njn0, njn1
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-         ! ... 2* gradj(v) (T-point i=nibm, time mean)
-                  z05cx = v_cynbnd(ji,jk)
-                  z05cx = z05cx / e2t(ji,jj)
-                  z05cx = min( z05cx, 1. )
-         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
-         !           > 0, outflow zin=1, ztau=rtaun
-                  zin = sign( 1., z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-         ! ... for inflow rtaunin is used for relaxation coefficient else rtaun
-                  ztau = (1.-zin ) * rtaunin + zin * rtaun
-                  z05cx = z05cx * zin
-         ! ... update va with radiative or climatological velocity
-                  va(ji,jj,jk) = va(ji,jj,jk) * (1.-vnmsk(ji,jk)) +             &
-                                 vnmsk(ji,jk) * ( ( 1. - z05cx - ztau )         &
-                                 * vnbnd(ji,jk,nib ,nitm) + 2.*z05cx              &
-                                 * vnbnd(ji,jk,nibm,nit ) + ztau * vfon (ji,jk) ) &
-                                 / (1. + z05cx)
-               END DO
-            END DO
-         END DO
-      END IF
-
-   END SUBROUTINE obc_dyn_north
-
-   SUBROUTINE obc_dyn_south ( kt )
-      !!------------------------------------------------------------------------------
-      !!                     SUBROUTINE obc_dyn_south
-      !!                    *************************
-      !! ** Purpose :
-      !!      Apply the radiation algorithm on south OBC velocities ua, va using the 
-      !!      phase velocities calculated in obc_rad_south subroutine in obcrad.F90 module
-      !!      If the logical lfbcsouth is .TRUE., there is no radiation but only fixed OBC
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
-      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declaration
-      REAL(wp) ::   z05cx, ztau, zin
-
-      !!------------------------------------------------------------------------------
-      !!  OPA 8.5, LODYC-IPSL (2002)
-      !!------------------------------------------------------------------------------
-
-      ! 1. First three time steps and more if lfbcsouth is .TRUE.
-      !    In that case open boundary conditions are FIXED.
-      ! ---------------------------------------------------------
-
-      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcsouth  .OR. lk_dynspg_exp ) THEN
-
-         ! 1.1 U zonal velocity
-         ! --------------------
-         DO jj = njs0, njs1
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  ua(ji,jj,jk)= ua(ji,jj,jk) * (1.-usmsk(ji,jk)) + &
-                                usmsk(ji,jk) * ufos(ji,jk)
-               END DO
-            END DO
-         END DO
-
-         ! 1.2 V meridional velocity
-         ! -------------------------
-         DO jj = njs0, njs1
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  va(ji,jj,jk)= va(ji,jj,jk) * (1.-vsmsk(ji,jk)) + &
-                                vsmsk(ji,jk) * vfos(ji,jk)
-               END DO
-            END DO
-         END DO
-
-      ELSE
-
-      ! 2. Beyond the fourth time step if lfbcsouth is .FALSE.
-      ! ------------------------------------------------------
-
-         ! 2.1. u-component of the velocity
-         ! --------------------------------
-         !
-         !            ji-row
-         !              |
-         !   nibm2 -----f-----   jpjsob +2
-         !              |    
-         !    nibm2 --  u   ---- jpjsob +2 
-         !              |        
-         !    nibm -----f-----   jpjsob +1
-         !              |        
-         !    nibm  --  u   ---- jpjsob +1
-         !              |        
-         !    nib  -----f-----   jpjsob
-         !         /////|//////
-         !    nib   ////u/////   jpjsob 
-         !
-         ! ... radiative condition plus Raymond-Kuo
-         ! ... jpjsob,(jpisdp1, jpisfm1)
-         DO jj = njs0, njs1
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  z05cx= u_cysbnd(ji,jk) 
-                  z05cx = z05cx / e2f(ji, jj)
-                  z05cx = max( z05cx, -1. )
-         ! ... z05cx > 0, inflow  zin=0, ztau=1 
-         !          =< 0, outflow zin=1, ztau=rtaus
-                  zin = sign( 1., -1. * z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-                  ztau = (1.-zin ) * rtausin + zin * rtaus
-                  z05cx = z05cx * zin 
-         ! ... update ua with radiative or climatological velocity
-                  ua(ji,jj,jk) = ua(ji,jj,jk) * (1.-usmsk(ji,jk)) +              &
-                                 usmsk(ji,jk) * (  ( 1. + z05cx - ztau )         &
-                                 * usbnd(ji,jk,nib ,nitm) - 2.*z05cx               &
-                                 * usbnd(ji,jk,nibm,nit ) + ztau * ufos (ji,jk) )  &
-                                 / (1. - z05cx)
-               END DO
-            END DO
-         END DO
-
-         ! 2.2 v-component of the velocity
-         ! -------------------------------
-         !
-         !                ji-row    ji-row
-         !              |         |
-         !  nibm2  -----f----v----f----  jpjsob+2
-         !              |         |
-         !    nibm   -  u -- T -- u ---- jpjsob+2
-         !              |         |
-         !   nibm  -----f----v----f----  jpjsob+1 
-         !              |         |
-         !   nib    --  u -- T -- u ---  jpjsob+1
-         !              |         |
-         !   nib   -----f----v----f----  jpjsob
-         !         /////////////////////
-         !
-         ! ... Free surface formulation:
-         ! ... radiative conditions on the total part + relaxation toward climatology
-         ! ... jpjsob,(jpisdp1,jpisfm1)
-         DO jj = njs0, njs1
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  z05cx = v_cysbnd(ji,jk)
-                  z05cx = z05cx / e2t(ji,jj+1)
-                  z05cx = max( z05cx, -1. )
-         ! ... z05c > 0, inflow  zin=0, ztau=1 
-         !         =< 0, outflow zin=1, ztau=rtaus
-                  zin = sign( 1., -1. * z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-                  ztau = (1.-zin )*rtausin + zin * rtaus
-                  z05cx = z05cx * zin
-         ! ... update va with radiative or climatological velocity
-                  va(ji,jj,jk) = va(ji,jj,jk) * (1.-vsmsk(ji,jk)) +             &
-                                 vsmsk(ji,jk) * ( ( 1. + z05cx - ztau )         &
-                                 * vsbnd(ji,jk,nib ,nitm) - 2.*z05cx              &
-                                 * vsbnd(ji,jk,nibm,nit ) + ztau * vfos (ji,jk) ) &
-                                 / (1. - z05cx)
-               END DO
-            END DO
-         END DO
-      END IF
-
-   END SUBROUTINE obc_dyn_south
-#else
-   !!=================================================================================
-   !!                       ***  MODULE  obcdyn  ***
-   !! Ocean dynamics:   Radiation of velocities on each open boundary
-   !!=================================================================================
-CONTAINS
-
-   SUBROUTINE obc_dyn
-                              ! No open boundaries ==> empty routine
-   END SUBROUTINE obc_dyn
-#endif
-
-END MODULE obcdyn
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdyn2d.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdyn2d.F90	(revision 2797)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdyn2d.F90	(revision 2797)
@@ -0,0 +1,157 @@
+MODULE obcdyn2d
+   !!======================================================================
+   !!                       ***  MODULE  obcdyn  ***
+   !! Unstructured Open Boundary Cond. :   Flow relaxation scheme on velocities
+   !!======================================================================
+   !! History :  1.0  !  2005-02  (J. Chanut, A. Sellar)  Original code
+   !!             -   !  2007-07  (D. Storkey) Move Flather implementation to separate routine.
+   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
+   !!            3.2  !  2008-04  (R. Benshila) consider velocity instead of transport 
+   !!            3.3  !  2010-09  (E.O'Dea) modifications for Shelf configurations 
+   !!            3.3  !  2010-09  (D.Storkey) add ice boundary conditions
+   !!----------------------------------------------------------------------
+#if defined key_obc 
+   !!----------------------------------------------------------------------
+   !!   'key_obc' :                    Unstructured Open Boundary Condition
+   !!----------------------------------------------------------------------
+   !!   obc_dyn2d      : Apply open boundary conditions to barotropic variables.
+   !!   obc_dyn2d_fla    : Apply Flather condition
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE obc_oce         ! ocean open boundary conditions
+   USE dynspg_oce      ! for barotropic variables
+   USE phycst          ! physical constants
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE obctides        ! for tidal harmonic forcing at boundary
+   USE in_out_manager  !
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   obc_dyn2d     ! routine called in dynspg_ts (time splitting case ONLY)
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: obcdyn.F90 2528 2010-12-27 17:33:53Z rblod $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE obc_dyn2d( kt, pssh )
+      !!----------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn2d  ***
+      !!
+      !! ** Purpose : - Apply open boundary conditions for barotropic variables
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER,                      INTENT(in) ::   kt   ! Main time step counter
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pssh
+      !!
+      INTEGER                                  ::   ib_obc ! Loop counter
+
+      DO ib_obc=1, nb_obc
+
+         SELECT CASE( nn_dyn2d(ib_obc) )
+         CASE(jp_none)
+            CYCLE
+         CASE(jp_flather)
+            CALL obc_dyn2d_fla( idx_obc(ib_obc), dta_obc(ib_obc), pssh )
+         CASE DEFAULT
+            CALL ctl_stop( 'obc_dyn3d : unrecognised option for open boundaries for barotropic variables' )
+         END SELECT
+      ENDDO
+
+   END SUBROUTINE obc_dyn2d
+
+   SUBROUTINE obc_dyn2d_fla( idx, dta, pssh )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_dyn_fla  ***
+      !!             
+      !!              - Apply Flather boundary conditions on normal barotropic velocities 
+      !!                (ln_dyn_fla=.true. or ln_tides=.true.)
+      !!
+      !! ** WARNINGS about FLATHER implementation:
+      !!1. According to Palma and Matano, 1998 "after ssh" is used. 
+      !!   In ROMS and POM implementations, it is "now ssh". In the current 
+      !!   implementation (tested only in the EEL-R5 conf.), both cases were unstable. 
+      !!   So I use "before ssh" in the following.
+      !!
+      !!2. We assume that the normal ssh gradient at the obc is zero. As a matter of 
+      !!   fact, the model ssh just inside the dynamical boundary is used (the outside  
+      !!   ssh in the code is not updated).
+      !!
+      !! References:  Flather, R. A., 1976: A tidal model of the northwest European
+      !!              continental shelf. Mem. Soc. R. Sci. Liege, Ser. 6,10, 141-164.     
+      !!----------------------------------------------------------------------
+      TYPE(OBC_INDEX),              INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),               INTENT(in) ::   dta  ! OBC external data
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pssh
+
+      INTEGER  ::   jb, igrd                         ! dummy loop indices
+      INTEGER  ::   ii, ij, iim1, iip1, ijm1, ijp1   ! 2D addresses
+      REAL(wp) ::   zcorr                            ! Flather correction
+      REAL(wp) ::   zforc                            ! temporary scalar
+      !!----------------------------------------------------------------------
+
+      ! ---------------------------------!
+      ! Flather boundary conditions     :!
+      ! ---------------------------------! 
+     
+!!!!!!!!!!!! SOME WORK TO DO ON THE TIDES HERE !!!!!!!!!!!!!
+
+      ! Fill temporary array with ssh data (here spgu):
+      igrd = 1
+      spgu(:,:) = 0.0
+      DO jb = 1, idx%nblenrim(igrd)
+         ii = idx%nbi(jb,igrd)
+         ij = idx%nbj(jb,igrd)
+         spgu(ii, ij) = dta%ssh(jb)
+!!$         IF( ln_tides )   spgu(ii, ij) = spgu(ii, ij) + sshtide(jb)
+      END DO
+      !
+      igrd = 2      ! Flather bc on u-velocity; 
+      !             ! remember that flagu=-1 if normal velocity direction is outward
+      !             ! I think we should rather use after ssh ?
+      DO jb = 1, idx%nblenrim(igrd)
+         ii  = idx%nbi(jb,igrd)
+         ij  = idx%nbj(jb,igrd) 
+         iim1 = ii + MAX( 0, INT( idx%flagu(jb) ) )   ! T pts i-indice inside the boundary
+         iip1 = ii - MIN( 0, INT( idx%flagu(jb) ) )   ! T pts i-indice outside the boundary 
+         !
+         zcorr = - idx%flagu(jb) * SQRT( grav * hur_e(ii, ij) ) * ( pssh(iim1, ij) - spgu(iip1,ij) )
+!!$         zforc = dta%u2d(jb) + utide(jb)
+         zforc = dta%u2d(jb)
+         ua_e(ii,ij) = zforc + zcorr * umask(ii,ij,1) 
+      END DO
+      !
+      igrd = 3      ! Flather bc on v-velocity
+      !             ! remember that flagv=-1 if normal velocity direction is outward
+      DO jb = 1, idx%nblenrim(igrd)
+         ii  = idx%nbi(jb,igrd)
+         ij  = idx%nbj(jb,igrd) 
+         ijm1 = ij + MAX( 0, INT( idx%flagv(jb) ) )   ! T pts j-indice inside the boundary
+         ijp1 = ij - MIN( 0, INT( idx%flagv(jb) ) )   ! T pts j-indice outside the boundary 
+         !
+         zcorr = - idx%flagv(jb) * SQRT( grav * hvr_e(ii, ij) ) * ( pssh(ii, ijm1) - spgu(ii,ijp1) )
+!!$         zforc = dta%v2d(jb) + vtide(jb)
+         zforc = dta%v2d(jb)
+         va_e(ii,ij) = zforc + zcorr * vmask(ii,ij,1)
+      END DO
+      CALL lbc_lnk( ua_e, 'U', -1. )   ! Boundary points should be updated
+      CALL lbc_lnk( va_e, 'V', -1. )   !
+      !
+      !
+   END SUBROUTINE obc_dyn2d_fla
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                   NO Unstruct Open Boundary Conditions
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE obc_dyn2d( kt )      ! Empty routine
+      WRITE(*,*) 'obc_dyn_frs: You should not have seen this print! error?', kt
+   END SUBROUTINE obc_dyn2d
+#endif
+
+   !!======================================================================
+END MODULE obcdyn2d
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdyn3d.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdyn3d.F90	(revision 2797)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdyn3d.F90	(revision 2797)
@@ -0,0 +1,126 @@
+MODULE obcdyn3d
+   !!======================================================================
+   !!                       ***  MODULE  obcdyn  ***
+   !! Unstructured Open Boundary Cond. :   Flow relaxation scheme on velocities
+   !!======================================================================
+   !! History :  1.0  !  2005-02  (J. Chanut, A. Sellar)  Original code
+   !!             -   !  2007-07  (D. Storkey) Move Flather implementation to separate routine.
+   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
+   !!            3.2  !  2008-04  (R. Benshila) consider velocity instead of transport 
+   !!            3.3  !  2010-09  (E.O'Dea) modifications for Shelf configurations 
+   !!            3.3  !  2010-09  (D.Storkey) add ice boundary conditions
+   !!----------------------------------------------------------------------
+#if defined key_obc 
+   !!----------------------------------------------------------------------
+   !!   'key_obc' :                    Unstructured Open Boundary Condition
+   !!----------------------------------------------------------------------
+   !!   obc_dyn3d        : apply open boundary conditions to baroclinic velocities
+   !!   obc_dyn3d_frs    : apply Flow Relaxation Scheme
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE obc_oce         ! ocean open boundary conditions
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  !
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   obc_dyn3d     ! routine called in dynspg_flt (free surface case ONLY)
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: obcdyn.F90 2528 2010-12-27 17:33:53Z rblod $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE obc_dyn3d( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn3d  ***
+      !!
+      !! ** Purpose : - Apply open boundary conditions for baroclinic velocities
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt     ! Main time step counter
+      !!
+      INTEGER               :: ib_obc ! loop index
+      !!
+
+      DO ib_obc=1, nb_obc
+
+!!$         IF ( using Orlanski radiation conditions ) THEN 
+!!$            CALL obc_rad( kt,  obcidx(ib_obc) )
+!!$         ENDIF
+
+         SELECT CASE( nn_dyn3d(ib_obc) )
+         CASE(jp_none)
+            CYCLE
+         CASE(jp_frs)
+            CALL obc_dyn3d_frs( idx_obc(ib_obc), dta_obc(ib_obc), kt )
+         CASE DEFAULT
+            CALL ctl_stop( 'obc_dyn3d : unrecognised option for open boundaries for baroclinic velocities' )
+         END SELECT
+      ENDDO
+
+   END SUBROUTINE obc_dyn3d
+
+   SUBROUTINE obc_dyn3d_frs( idx, dta, kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn3d_frs  ***
+      !!
+      !! ** Purpose : - Apply the Flow Relaxation Scheme for baroclinic velocities
+      !!                at open boundaries.
+      !!
+      !! References :- Engedahl H., 1995: Use of the flow relaxation scheme in 
+      !!               a three-dimensional baroclinic ocean model with realistic
+      !!               topography. Tellus, 365-382.
+      !!----------------------------------------------------------------------
+      INTEGER                     ::   kt
+      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
+      !!
+      INTEGER  ::   jb, jk         ! dummy loop indices
+      INTEGER  ::   ii, ij, igrd   ! local integers
+      REAL(wp) ::   zwgt           ! boundary weight
+      !!----------------------------------------------------------------------
+      !
+      !
+      igrd = 2                      ! Relaxation of zonal velocity
+      DO jb = 1, idx%nblen(igrd)
+         DO jk = 1, jpkm1
+            ii   = idx%nbi(jb,igrd)
+            ij   = idx%nbj(jb,igrd)
+            zwgt = idx%nbw(jb,igrd)
+            ua(ii,ij,jk) = ( ua(ii,ij,jk) + zwgt * ( dta%u3d(jb,jk) - ua(ii,ij,jk) ) ) * umask(ii,ij,jk)
+         END DO
+      END DO
+      !
+      igrd = 3                      ! Relaxation of meridional velocity
+      DO jb = 1, idx%nblen(igrd)
+         DO jk = 1, jpkm1
+            ii   = idx%nbi(jb,igrd)
+            ij   = idx%nbj(jb,igrd)
+            zwgt = idx%nbw(jb,igrd)
+            va(ii,ij,jk) = ( va(ii,ij,jk) + zwgt * ( dta%v3d(jb,jk) - va(ii,ij,jk) ) ) * vmask(ii,ij,jk)
+         END DO
+      END DO 
+      CALL lbc_lnk( ua, 'U', -1. )   ;   CALL lbc_lnk( va, 'V', -1. )   ! Boundary points should be updated
+      !
+      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
+
+   END SUBROUTINE obc_dyn3d_frs
+
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                   NO Unstruct Open Boundary Conditions
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE obc_dyn3d( kt )      ! Empty routine
+      WRITE(*,*) 'obc_dyn_frs: You should not have seen this print! error?', kt
+   END SUBROUTINE obc_dyn3d
+#endif
+
+   !!======================================================================
+END MODULE obcdyn3d
Index: anches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdyn_bt.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcdyn_bt.F90	(revision 2796)
+++ 	(revision )
@@ -1,317 +1,0 @@
-MODULE obcdyn_bt
-   !!======================================================================
-   !!                       ***  MODULE  obcdyn_bt  ***
-   !! Ocean dynamics:   Radiation/prescription of sea surface heights on each open boundary
-   !!======================================================================
-   !! History :  1.0  ! 2005-12  (V. Garnier) original code
-   !!----------------------------------------------------------------------
-#if ( defined key_dynspg_ts || defined key_dynspg_exp ) && defined key_obc
-   !!----------------------------------------------------------------------
-   !!   'key_dynspg_ts'     OR                   time spliting free surface
-   !!   'key_dynspg_exp'    AND                       explicit free surface
-   !!   'key_obc'                                   Open Boundary Condition
-   !!----------------------------------------------------------------------
-   !!   obc_dyn_bt        : call the subroutine for each open boundary
-   !!   obc_dyn_bt_east   : Flather's algorithm at the east open boundary
-   !!   obc_dyn_bt_west   : Flather's algorithm at the west open boundary
-   !!   obc_dyn_bt_north  : Flather's algorithm at the north open boundary
-   !!   obc_dyn_bt_south  : Flather's algorithm at the south open boundary
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers 
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE obc_oce         ! ocean open boundary conditions
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         ! distributed memory computing
-   USE obcdta          ! ocean open boundary conditions
-   USE in_out_manager  ! I/O manager
-   USE dynspg_oce      ! surface pressure gradient     (free surface with time-splitting)
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   obc_dyn_bt  ! routine called in dynnxt (explicit free surface case)
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE obc_dyn_bt( kt )
-      !!----------------------------------------------------------------------
-      !!                 ***  SUBROUTINE obc_dyn_bt  ***
-      !!
-      !! ** Purpose :   Apply Flather's algorithm at open boundaries for the explicit
-      !!              free surface case and free surface case with time-splitting
-      !!
-      !!      This routine is called in dynnxt.F routine and updates ua, va and sshn. 
-      !!
-      !!      The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north, 
-      !!      and/or lp_obc_south allow the user to determine which boundary is an
-      !!      open one (must be done in the param_obc.h90 file).
-      !!
-      !! Reference :   Flather, R. A., 1976, Mem. Soc. R. Sci. Liege, Ser. 6, 10, 141-164
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt
-      !!----------------------------------------------------------------------
-
-      IF( lp_obc_east  )   CALL obc_dyn_bt_east 
-      IF( lp_obc_west  )   CALL obc_dyn_bt_west 
-      IF( lp_obc_north )   CALL obc_dyn_bt_north
-      IF( lp_obc_south )   CALL obc_dyn_bt_south
-
-      IF( lk_mpp ) THEN
-         IF( kt >= nit000+3 .AND. ln_rstart ) THEN
-            CALL lbc_lnk( sshb, 'T',  1. )
-            CALL lbc_lnk( ub  , 'U', -1. )
-            CALL lbc_lnk( vb  , 'V', -1. )
-         END IF
-         CALL lbc_lnk( sshn, 'T',  1. )
-         CALL lbc_lnk( ua  , 'U', -1. )
-         CALL lbc_lnk( va  , 'V', -1. )
-      ENDIF
-
-   END SUBROUTINE obc_dyn_bt
-
-# if defined key_dynspg_exp
-
-   SUBROUTINE obc_dyn_bt_east 
-      !!----------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_dyn_bt_east  ***
-      !!              
-      !! ** Purpose :
-      !!      Apply Flather's algorithm on east OBC velocities ua, va 
-      !!      Fix sea surface height (sshn) on east open boundary
-      !!      The logical lfbceast must be .TRUE.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-
-      DO ji = nie0, nie1
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               ua(ji,jj,jk) = ua(ji,jj,jk) + sqrt( grav*hur (ji,jj) )               &
-                  &                      * ( ( sshn(ji,jj) + sshn(ji+1,jj) ) * 0.5  &
-                  &                          - sshfoe(jj) ) * uemsk(jj,jk)
-            END DO
-         END DO
-      END DO
-      DO ji = nie0p1, nie1p1
-         DO jj = 1, jpj
-            sshn(ji,jj) = sshn(ji,jj) * (1.-temsk(jj,1)) + temsk(jj,1)*sshfoe(jj)
-         END DO
-      END DO
-
-   END SUBROUTINE obc_dyn_bt_east
-
-
-   SUBROUTINE obc_dyn_bt_west 
-      !!----------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_dyn_bt_west  ***
-      !!                  
-      !! ** Purpose :
-      !!      Apply Flather algorithm on west OBC velocities ua, va
-      !!      Fix sea surface height (sshn) on west open boundary
-      !!      The logical lfbcwest must be .TRUE.
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO ji = niw0, niw1
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               ua(ji,jj,jk) = ua(ji,jj,jk) - sqrt( grav*hur (ji,jj) )               &
-                  &                      * ( ( sshn(ji,jj) + sshn(ji+1,jj) ) * 0.5  &
-                  &                          - sshfow(jj) ) * uwmsk(jj,jk)
-            END DO
-         END DO
-         DO jj = 1, jpj
-            sshn(ji,jj) = sshn(ji,jj) * (1.-twmsk(jj,1)) + twmsk(jj,1)*sshfow(jj)
-         END DO
-      END DO
-      !
-   END SUBROUTINE obc_dyn_bt_west
-
-
-   SUBROUTINE obc_dyn_bt_north 
-      !!------------------------------------------------------------------------------
-      !!                ***  SUBROUTINE obc_dyn_bt_north  ***
-      !!
-      !! ** Purpose :
-      !!      Apply Flather algorithm on north OBC velocities ua, va
-      !!      Fix sea surface height (sshn) on north open boundary
-      !!      The logical lfbcnorth must be .TRUE.
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO jj = njn0, njn1
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-               va(ji,jj,jk) = va(ji,jj,jk) + sqrt( grav*hvr (ji,jj) )               &
-                  &                      * ( ( sshn(ji,jj) + sshn(ji,jj+1) ) * 0.5  &
-                  &                          - sshfon(ji) ) * vnmsk(ji,jk)
-            END DO
-         END DO
-      END DO
-      DO jj = njn0p1, njn1p1
-         DO ji = 1, jpi
-            sshn(ji,jj)= sshn(ji,jj) * (1.-tnmsk(ji,1)) + sshfon(ji)*tnmsk(ji,1)
-         END DO
-      END DO
-      !
-   END SUBROUTINE obc_dyn_bt_north
-
-
-   SUBROUTINE obc_dyn_bt_south 
-      !!----------------------------------------------------------------------
-      !!                ***  SUBROUTINE obc_dyn_bt_south  ***
-      !!                    
-      !! ** Purpose :
-      !!      Apply Flather algorithm on south OBC velocities ua, va
-      !!      Fix sea surface height (sshn) on south open boundary
-      !!      The logical lfbcsouth must be .TRUE.
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO jj = njs0, njs1
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-               va(ji,jj,jk) = va(ji,jj,jk) - sqrt( grav*hvr (ji,jj) )               &
-                  &                       * ( ( sshn(ji,jj) + sshn(ji,jj+1) ) * 0.5 &
-                  &                           - sshfos(ji) ) * vsmsk(ji,jk)
-            END DO
-         END DO
-         DO ji = 1, jpi
-            sshn(ji,jj)= sshn(ji,jj) * (1.-tsmsk(ji,1)) + tsmsk(ji,1) * sshfos(ji)
-         END DO
-      END DO
-      !
-   END SUBROUTINE obc_dyn_bt_south
-
-# elif defined key_dynspg_ts
-
-   SUBROUTINE obc_dyn_bt_east 
-      !!------------------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_dyn_bt_east  ***
-      !!
-      !! ** Purpose :
-      !!      Apply Flather's algorithm on east OBC velocities ua, va
-      !!      Fix sea surface height (sshn) on east open boundary
-      !!      The logical lfbceast must be .TRUE.
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO ji = nie0, nie1
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               ua(ji,jj,jk) = ( ua(ji,jj,jk) + sshfoe_b(ji,jj) ) * uemsk(jj,jk)
-            END DO
-         END DO
-      END DO
-      DO ji = nie0p1, nie1p1
-         DO jj = 1, jpj
-            sshn(ji,jj) = sshn(ji,jj) * (1.-temsk(jj,1)) + temsk(jj,1)*sshn_b(ji,jj)
-         END DO
-      END DO
-      !
-   END SUBROUTINE obc_dyn_bt_east
-
-
-   SUBROUTINE obc_dyn_bt_west 
-      !!---------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_dyn_bt_west  ***
-      !!
-      !! ** Purpose :   Apply Flather algorithm on west OBC velocities ua, va
-      !!      Fix sea surface height (sshn) on west open boundary
-      !!      The logical lfbcwest must be .TRUE.
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO ji = niw0, niw1
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               ua(ji,jj,jk) = ( ua(ji,jj,jk) + sshfow_b(ji,jj) ) * uwmsk(jj,jk)
-            END DO
-         END DO
-         DO jj = 1, jpj
-            sshn(ji,jj) = sshn(ji,jj) * (1.-twmsk(jj,1)) + twmsk(jj,1)*sshn_b(ji,jj)
-         END DO
-      END DO
-      !
-   END SUBROUTINE obc_dyn_bt_west
-
-
-   SUBROUTINE obc_dyn_bt_north 
-      !!------------------------------------------------------------------------------
-      !!                ***  SUBROUTINE obc_dyn_bt_north  ***
-      !!                
-      !! ** Purpose :
-      !!      Apply Flather algorithm on north OBC velocities ua, va
-      !!      Fix sea surface height (sshn) on north open boundary
-      !!      The logical lfbcnorth must be .TRUE.
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO jj = njn0, njn1
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-               va(ji,jj,jk) = ( va(ji,jj,jk) + sshfon_b(ji,jj) ) * vnmsk(jj,jk)
-            END DO
-         END DO
-      END DO
-      DO jj = njn0p1, njn1p1
-         DO ji = 1, jpi
-            sshn(ji,jj)= sshn(ji,jj) * (1.-tnmsk(ji,1)) + sshn_b(ji,jj)*tnmsk(ji,1)
-         END DO
-      END DO
-      !
-   END SUBROUTINE obc_dyn_bt_north
-
-
-   SUBROUTINE obc_dyn_bt_south 
-      !!------------------------------------------------------------------------------
-      !!                ***  SUBROUTINE obc_dyn_bt_south  ***
-      !!                  
-      !! ** Purpose :
-      !!      Apply Flather algorithm on south OBC velocities ua, va
-      !!      Fix sea surface height (sshn) on south open boundary
-      !!      The logical lfbcsouth must be .TRUE.
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO jj = njs0, njs1
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-               va(ji,jj,jk) = ( va(ji,jj,jk) + sshfos_b(ji,jj) ) * vsmsk(jj,jk)
-            END DO
-         END DO
-         DO ji = 1, jpi
-            sshn(ji,jj)= sshn(ji,jj) * (1.-tsmsk(ji,1)) + tsmsk(ji,1) * sshn_b(ji,jj)
-         END DO
-      END DO
-      !
-   END SUBROUTINE obc_dyn_bt_south
-
-# endif
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option       No Open Boundaries or not explicit fre surface
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE obc_dyn_bt      ! Dummy routine
-   END SUBROUTINE obc_dyn_bt
-#endif
-
-   !!======================================================================
-END MODULE obcdyn_bt
Index: anches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcfla.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcfla.F90	(revision 2796)
+++ 	(revision )
@@ -1,193 +1,0 @@
-MODULE obcfla
-   !!======================================================================
-   !!                       ***  MODULE  obcfla  ***
-   !! Ocean dynamics:   Flather's algorithm at open boundaries for the time-splitting
-   !!======================================================================
-   !! History :  2.0  ! 2005-12  (V. Garnier) original code
-   !!            3.3  ! 2010-11  (G. Madec) 
-   !!            4.0  ! 2011-02  (G. Madec) velocity & ssh passed in argument
-   !!----------------------------------------------------------------------
-#if defined key_obc   &&   defined key_dynspg_ts
-   !!----------------------------------------------------------------------
-   !!   'key_obc'          and                      Open Boundary Condition
-   !!   'key_dynspg_ts'                    free surface with time splitting
-   !!----------------------------------------------------------------------
-   !!   obc_fla_ts        : call the subroutine for each open boundary
-   !!   obc_fla_ts_east   : Flather on the east  open boundary velocities & ssh
-   !!   obc_fla_ts_west   : Flather on the west  open boundary velocities & ssh
-   !!   obc_fla_ts_north  : Flather on the north open boundary velocities & ssh
-   !!   obc_fla_ts_south  : Flather on the south open boundary velocities & ssh
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers 
-   USE dom_oce         ! ocean space and time domain
-   USE dynspg_oce      ! surface pressure gradient variables
-   USE phycst          ! physical constants
-   USE obc_oce         ! ocean open boundary conditions
-   USE obcdta          ! ocean open boundary conditions: climatology
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   obc_fla_ts   ! routine called in dynspg_ts (free surface time splitting case)
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE obc_fla_ts( pua, pva, p_sshn, p_ssha )
-      !!----------------------------------------------------------------------
-      !!                      SUBROUTINE obc_fla_ts
-      !!
-      !! ** Purpose :   Apply Flather's algorithm at open boundaries for the 
-      !!      time-splitting free surface case (barotropic variables)
-      !!
-      !!      This routine is called in dynspg_ts.F90 routine 
-      !!
-      !!      The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north,
-      !!      and/or lp_obc_south allow the user to determine which boundary is an
-      !!      open one (must be done in the obc_par.F90 file).
-      !!
-      !! ** Reference : Flather, R. A., 1976, Mem. Soc. R. Sci. Liege, Ser. 6, 10, 141-164
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pua   , pva      ! after barotropic velocities
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_sshn, p_ssha   ! before, now, after sea surface height
-      !!----------------------------------------------------------------------
-      !
-      IF( lp_obc_east  )   CALL obc_fla_ts_east ( pua, pva, p_sshn, p_ssha ) 
-      IF( lp_obc_west  )   CALL obc_fla_ts_west ( pua, pva, p_sshn, p_ssha )
-      IF( lp_obc_north )   CALL obc_fla_ts_north( pua, pva, p_sshn, p_ssha )
-      IF( lp_obc_south )   CALL obc_fla_ts_south( pua, pva, p_sshn, p_ssha ) 
-      !
-   END SUBROUTINE obc_fla_ts
-
-
-   SUBROUTINE obc_fla_ts_east( pua, pva, p_sshn, p_ssha ) 
-      !!----------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_fla_ts_east  ***
-      !!
-      !! ** Purpose :   Apply Flather's algorithm on east OBC velocities ua, va
-      !!              Fix sea surface height (p_sshn) on east open boundary
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pua   , pva      ! after barotropic velocities
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_sshn, p_ssha   ! before, now, after sea surface height
-      !
-      INTEGER ::   ji, jj   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO ji = nie0, nie1
-         DO jj = 1, jpj
-            pua     (ji,jj) = (  ubtfoe(jj) * hur(ji,jj) + SQRT( grav*hur(ji,jj) )          &
-               &            * ( ( p_sshn(ji,jj) + p_sshn(ji+1,jj) ) * 0.5 - sshfoe(jj) )  ) * uemsk(jj,1)
-            sshfoe_b(ji,jj) =    sshfoe_b(ji,jj)         + SQRT( grav*hur(ji,jj) )          &
-               &            * ( ( p_sshn(ji,jj) + p_sshn(ji+1,jj) ) * 0.5 - sshfoe(jj) )    * uemsk(jj,1)
-         END DO
-      END DO
-      DO ji = nie0p1, nie1p1
-         DO jj = 1, jpj
-            p_ssha(ji,jj) = p_ssha(ji,jj) * ( 1. - temsk(jj,1) ) + temsk(jj,1) * sshfoe(jj)
-            pva   (ji,jj) = vbtfoe(jj) * hvr(ji,jj) * uemsk(jj,1)
-         END DO
-      END DO
-      !
-   END SUBROUTINE obc_fla_ts_east
-
-
-   SUBROUTINE obc_fla_ts_west( pua, pva, p_sshn, p_ssha )
-      !!----------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_fla_ts_west  ***
-      !! 
-      !! ** Purpose :   Apply Flather's algorithm on west OBC velocities ua, va
-      !!              Fix sea surface height (p_sshn) on west open boundary
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pua   , pva      ! after barotropic velocities
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_sshn, p_ssha   ! before, now, after sea surface height
-      !
-      INTEGER ::   ji, jj   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO ji = niw0, niw1
-         DO jj = 1, jpj
-            pua     (ji,jj) = ( ubtfow(jj) * hur(ji,jj) - sqrt( grav * hur(ji,jj) )            &
-               &            * ( ( p_sshn(ji,jj) + p_sshn(ji+1,jj) ) * 0.5 - sshfow(jj) ) ) * uwmsk(jj,1)
-            pva     (ji,jj) =   vbtfow(jj) * hvr(ji,jj) * uwmsk(jj,1)
-            sshfow_b(ji,jj) =   sshfow_b(ji,jj) - SQRT( grav * hur(ji,jj) )                    &
-               &            * ( ( p_sshn(ji,jj) + p_sshn(ji+1,jj) ) * 0.5 - sshfow(jj) )   * uwmsk(jj,1)
-            p_ssha  (ji,jj) = p_ssha(ji,jj) * ( 1. - twmsk(jj,1) ) + twmsk(jj,1)*sshfow(jj)
-         END DO
-      END DO
-      !
-   END SUBROUTINE obc_fla_ts_west
-
-
-   SUBROUTINE obc_fla_ts_north( pua, pva, p_sshn, p_ssha )
-      !!----------------------------------------------------------------------
-      !!                     SUBROUTINE obc_fla_ts_north
-      !!
-      !! ** Purpose :   Apply Flather's algorithm on north OBC velocities ua, va
-      !!              Fix sea surface height (p_sshn) on north open boundary
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pua   , pva      ! after barotropic velocities
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_sshn, p_ssha   ! before, now, after sea surface height
-      !
-      INTEGER ::   ji, jj   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO jj = njn0, njn1
-         DO ji = 1, jpi
-            pva     (ji,jj) = ( vbtfon(ji) * hvr(ji,jj) + sqrt( grav * hvr(ji,jj) )            &
-               &                * ( ( p_sshn(ji,jj) + p_sshn(ji,jj+1) ) * 0.5 - sshfon(ji) ) ) * vnmsk(ji,1)
-            sshfon_b(ji,jj) =   sshfon_b(ji,jj) + sqrt( grav * hvr(ji,jj) )                    &
-               &                * ( ( p_sshn(ji,jj) + p_sshn(ji,jj+1) ) * 0.5 - sshfon(ji) )   * vnmsk(ji,1)
-         END DO
-      END DO
-      DO jj = njn0p1, njn1p1
-         DO ji = 1, jpi
-            p_ssha(ji,jj) = p_ssha(ji,jj) * ( 1. - tnmsk(ji,1) ) + sshfon(ji) * tnmsk(ji,1)
-            pua   (ji,jj) = ubtfon(ji) * hur(ji,jj) * vnmsk(ji,1)
-         END DO
-      END DO
-      !
-   END SUBROUTINE obc_fla_ts_north
-
-
-   SUBROUTINE obc_fla_ts_south( pua, pva, p_sshn, p_ssha )
-      !!----------------------------------------------------------------------
-      !!                     SUBROUTINE obc_fla_ts_south
-      !!
-      !! ** Purpose :   Apply Flather's algorithm on south OBC velocities ua, va
-      !!              Fix sea surface height (p_sshn) on south open boundary
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pua   , pva      ! after barotropic velocities
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_sshn, p_ssha   ! before, now, after sea surface height
-      !
-      INTEGER ::   ji, jj   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO jj = njs0, njs1
-         DO ji = 1, jpi
-            pva     (ji,jj) = ( vbtfos(ji) * hvr(ji,jj) - sqrt( grav * hvr(ji,jj) )            &
-               &                * ( ( p_sshn(ji,jj) + p_sshn(ji,jj+1) ) * 0.5 - sshfos(ji) ) ) * vsmsk(ji,1)
-            pua     (ji,jj) =   ubtfos(ji) * hur(ji,jj) * vsmsk(ji,1)
-            sshfos_b(ji,jj) =   sshfos_b(ji,jj) - sqrt( grav * hvr(ji,jj) )                    &
-               &                * ( ( p_sshn(ji,jj) + p_sshn(ji,jj+1) ) * 0.5 - sshfos(ji) )   * vsmsk(ji,1)
-            p_ssha  (ji,jj) = p_ssha(ji,jj) * (1. - tsmsk(ji,1) ) + tsmsk(ji,1) * sshfos(ji)
-         END DO
-      END DO
-      !
-   END SUBROUTINE obc_fla_ts_south
-   
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module :                             No OBC or time-splitting
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE obc_fla_ts( pua, pva, p_sshn, p_ssha )
-      REAL, DIMENSION(:,:)::   pua, pva, p_sshn, p_ssha
-      WRITE(*,*) 'obc_fla_ts: You should not have seen this print! error?', pua(1,1), pva(1,1), p_sshn(1,1), p_ssha(1,1)
-   END SUBROUTINE obc_fla_ts
-#endif
-   !!======================================================================
-END MODULE obcfla
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcice_lim2.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcice_lim2.F90	(revision 2797)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcice_lim2.F90	(revision 2797)
@@ -0,0 +1,107 @@
+MODULE obcice_lim2
+   !!======================================================================
+   !!                       ***  MODULE  obcice_lim2  ***
+   !! Unstructured Open Boundary Cond. :  Flow Relaxation Scheme applied sea-ice (LIM2)
+   !!======================================================================
+   !!  History :  3.3  !  2010-09 (D. Storkey)  Original code
+   !!----------------------------------------------------------------------
+#if defined   key_obc   &&   defined key_lim2
+   !!----------------------------------------------------------------------
+   !!   'key_obc'            and                 Unstructured Open Boundary Conditions
+   !!   'key_lim2'                                                 LIM-2 sea ice model
+   !!----------------------------------------------------------------------
+   !!   obc_ice_lim_2      : Application of open boundaries to ice
+   !!   obc_ice_frs        : Application of Flow Relaxation Scheme
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE ice_2           ! LIM_2 ice variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE obc_oce         ! ocean open boundary conditions
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! write to numout file
+   USE lib_mpp         ! distributed memory computing
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   obc_ice_lim_2    ! routine called in sbcmod
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: obcice.F90 2715 2011-03-30 15:58:35Z rblod $
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE obc_ice_lim_2( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_ice_lim_2  ***
+      !!
+      !! ** Purpose : - Apply open boundary conditions for ice (LIM2)
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt     ! Main time step counter
+      !!
+      INTEGER               :: ib_obc ! Loop index
+
+      DO ib_obc=1, nb_obc
+
+         SELECT CASE( nn_ice_lim2(ib_obc) )
+         CASE(jp_none)
+            CYCLE
+         CASE(jp_frs)
+            CALL obc_ice_frs( idx_obc(ib_obc), dta_idx(ib_obc) )
+         CASE DEFAULT
+            CALL ctl_stop( 'obc_tra : unrecognised option for open boundaries for T an S' )
+         END SELECT
+      ENDDO
+
+   END SUBROUTINE obc_ice_lim_2
+
+   SUBROUTINE obc_ice_frs( idx, dta )
+      !!------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_ice_frs  ***
+      !!                    
+      !! ** Purpose : Apply the Flow Relaxation Scheme for sea-ice fields in the case 
+      !!              of unstructured open boundaries. Currently only tested for LIM2.
+      !! 
+      !! Reference : Engedahl H., 1995: Use of the flow relaxation scheme in a three-
+      !!             dimensional baroclinic ocean model with realistic topography. Tellus, 365-382.
+      !!------------------------------------------------------------------------------
+      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
+      !!
+      INTEGER  ::   jb, jk, jgrd   ! dummy loop indices
+      INTEGER  ::   ii, ij         ! local scalar
+      REAL(wp) ::   zwgt, zwgt1    ! local scalar
+      !!------------------------------------------------------------------------------
+      !
+      jgrd = 1      ! Everything is at T-points here
+      !
+      DO jb = 1, idx%nblen(jgrd)
+         DO jk = 1, jpkm1
+            ii    = idx%nbi(jb,jgrd)
+            ij    = idx%nbj(jb,jgrd)
+            zwgt  = idx%nbw(jb,jgrd)
+            zwgt1 = 1.e0 - idx%nbw(jb,jgrd)
+            frld (ii,ij) = ( frld (ii,ij) * zwgt1 + dta%frld (jb) * zwgt ) * tmask(ii,ij,1)     ! Leads fraction 
+            hicif(ii,ij) = ( hicif(ii,ij) * zwgt1 + dta%hicif(jb) * zwgt ) * tmask(ii,ij,1)     ! Ice depth 
+            hsnif(ii,ij) = ( hsnif(ii,ij) * zwgt1 + dta%hsnif(jb) * zwgt ) * tmask(ii,ij,1)     ! Snow depth
+         END DO
+      END DO 
+      CALL lbc_lnk( frld, 'T', 1. )                                         ! lateral boundary conditions
+      CALL lbc_lnk( hicif, 'T', 1. )   ;   CALL lbc_lnk( hsnif, 'T', 1. )
+      !      
+   END SUBROUTINE obc_ice_frs
+#else
+   !!---------------------------------------------------------------------------------
+   !!   Default option                                                    Empty module
+   !!---------------------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE obc_ice_lim_2( kt )      ! Empty routine
+      WRITE(*,*) 'obc_ice_frs: You should not have seen this print! error?', kt
+   END SUBROUTINE obc_ice_lim_2
+#endif
+
+   !!=================================================================================
+END MODULE obcice_lim2
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcini.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcini.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcini.F90	(revision 2797)
@@ -1,26 +1,30 @@
- MODULE obcini
+MODULE obcini
    !!======================================================================
    !!                       ***  MODULE  obcini  ***
-   !! OBC initial state :  Open boundary initial state
+   !! Unstructured open boundaries : initialisation
    !!======================================================================
-   !! History :  8.0  !  97-07  (J.M. Molines, G. Madec)  Original code
-   !!   NEMO     1.0  !  02-11  (C. Talandier, A-M. Treguier) Free surface, F90
-   !!            2.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !! History :  1.0  !  2005-01  (J. Chanut, A. Sellar)  Original code
+   !!             -   !  2007-01  (D. Storkey) Update to use IOM module
+   !!             -   !  2007-01  (D. Storkey) Tidal forcing
+   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
+   !!            3.3  !  2010-09  (E.O'Dea) updates for Shelf configurations
+   !!            3.3  !  2010-09  (D.Storkey) add ice boundary conditions
+   !!            3.4  !  2011     (D. Storkey, J. Chanut) OBC-BDY merge
+   !!                 !  --- Renamed bdyini.F90 -> obcini.F90 ---
    !!----------------------------------------------------------------------
 #if defined key_obc
    !!----------------------------------------------------------------------
-   !!   'key_obc'                                  Open Boundary Conditions
+   !!   'key_obc'                     Unstructured Open Boundary Conditions
    !!----------------------------------------------------------------------
-   !!   obc_init       : initialization for the open boundary condition
+   !!   obc_init       : Initialization of unstructured open boundaries
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables
+   USE dom_oce         ! ocean space and time domain
+   USE obc_oce         ! unstructured open boundary conditions
+   USE obctides        ! tides at open boundaries initialization (tide_init routine)
+   USE in_out_manager  ! I/O units
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE phycst          ! physical constants
-   USE obc_oce         ! open boundary condition: ocean
-   USE obcdta          ! open boundary condition: data
-   USE in_out_manager  ! I/O units
-   USE lib_mpp         ! MPP library
-   USE dynspg_oce      ! flag lk_dynspg_flt
+   USE lib_mpp         ! for mpp_sum  
+   USE iom             ! I/O
 
    IMPLICIT NONE
@@ -29,8 +33,6 @@
    PUBLIC   obc_init   ! routine called by opa.F90
 
-   !! * Substitutions
-#  include "obc_vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -42,671 +44,505 @@
       !!                 ***  ROUTINE obc_init  ***
       !!         
-      !! ** Purpose :   Initialization of the dynamics and tracer fields at 
-      !!              the open boundaries.
+      !! ** Purpose :   Initialization of the dynamics and tracer fields with 
+      !!              unstructured open boundaries.
       !!
-      !! ** Method  :   initialization of open boundary variables
-      !!      (u, v) over 3 time step and 3 rows
-      !!      (t, s) over 2 time step and 2 rows
-      !!      if ln_rstart = .FALSE. : no restart, fields set to zero
-      !!      if ln_rstart = .TRUE.  : restart, fields are read in a file 
-      !!      if rdpxxx = 0 then lfbc is set true for this boundary.
+      !! ** Method  :   Read initialization arrays (mask, indices) to identify 
+      !!              an unstructured open boundary
       !!
-      !! ** Input   :   restart.obc file, restart file for open boundaries 
+      !! ** Input   :  obc_init.nc, input file for unstructured open boundaries
+      !!----------------------------------------------------------------------      
+      INTEGER  ::   ib_obc, ii, ij, ik, igrd, ib, ir   ! dummy loop indices
+      INTEGER  ::   icount, icountr, ibr_max, ilen1    ! local integers
+      INTEGER  ::   iw, ie, is, in, inum, id_dummy     !   -       -
+      INTEGER  ::   igrd_start, igrd_end, jpbdta       !   -       -
+      INTEGER, POINTER  ::  nbi, nbj, nbr              ! short cuts
+      REAL   , POINTER  ::  flagu, flagv               !    -   -
+      REAL(wp) ::   zefl, zwfl, znfl, zsfl             ! local scalars
+      INTEGER, DIMENSION (2)                ::   kdimsz
+      INTEGER, DIMENSION(jpbgrd,jp_obc)       ::   nblendta         ! Length of index arrays 
+      INTEGER, ALLOCATABLE, DIMENSION(:,:,:)  ::   nbidta, nbjdta   ! Index arrays: i and j indices of obc dta
+      INTEGER, ALLOCATABLE, DIMENSION(:,:,:)  ::   nbrdta           ! Discrete distance from rim points
+      REAL(wp), DIMENSION(jpidta,jpjdta)    ::   zmask            ! global domain mask
+      CHARACTER(LEN=80),DIMENSION(jpbgrd)  ::   clfile
+      CHARACTER(LEN=1),DIMENSION(jpbgrd)   ::   cgrid
+      !!
+      NAMELIST/namobc/ nb_obc, ln_coords_file, cn_coords_file,             &
+         &             ln_mask_file, cn_mask_file, nn_dyn2d, nn_dyn3d,     &
+         &             nn_tra,                                             &
+#if defined key_lim2
+         &             nn_ice_lim2,                                        &
+#endif
+         &             ln_tides, ln_vol, ln_clim, nn_dtactl, nn_volctl,    &
+         &             nn_rimwidth, nn_dmp2d_in, nn_dmp2d_out,             &
+         &             nn_dmp3d_in, nn_dmp3d_out
       !!----------------------------------------------------------------------
-      USE obcrst,   ONLY :   obc_rst_read   ! Make obc_rst_read routine available
-      !!
-      INTEGER  ::   ji, jj, istop , inumfbc
-      INTEGER, DIMENSION(4) ::   icorner
-      REAL(wp), DIMENSION(2) ::   ztestmask
-      !!
-      NAMELIST/namobc/ rn_dpein, rn_dpwin, rn_dpnin, rn_dpsin,       &
-         &             rn_dpeob, rn_dpwob, rn_dpnob, rn_dpsob,       &
-         &             rn_volemp, nn_obcdta, cn_obcdta,    &
-         &             ln_obc_clim, ln_vol_cst, ln_obc_fla
-      !!----------------------------------------------------------------------
-
-      REWIND( numnam )              ! Namelist namobc : open boundaries
-      READ  ( numnam, namobc )
-
-      ! convert DOCTOR namelist name into the OLD names
-      nobc_dta = nn_obcdta
-      cffile   = cn_obcdta
-      rdpein   = rn_dpein
-      rdpwin   = rn_dpwin
-      rdpsin   = rn_dpsin
-      rdpnin   = rn_dpnin
-      rdpeob   = rn_dpeob
-      rdpwob   = rn_dpwob
-      rdpsob   = rn_dpsob
-      rdpnob   = rn_dpnob
-      volemp   = rn_volemp
-
-      !                              ! allocate obc arrays
-      IF( obc_oce_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'obc_init : unable to allocate obc_oce arrays' )
-      IF( obc_dta_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'obc_init : unable to allocate obc_dta arrays' )
-
-      ! By security we set rdpxin and rdpxob respectively to 1. and 15. if the corresponding OBC is not activated
-      IF( .NOT.lp_obc_east  ) THEN   ;   rdpein = 1.   ;   rdpeob = 15.   ;   END IF
-      IF( .NOT.lp_obc_west  ) THEN   ;   rdpwin = 1.   ;   rdpwob = 15.   ;   END IF
-      IF( .NOT.lp_obc_north ) THEN   ;   rdpnin = 1.   ;   rdpnob = 15.   ;   END IF
-      IF( .NOT.lp_obc_south ) THEN   ;   rdpsin = 1.   ;   rdpsob = 15.   ;   END IF
-
-      ! number of open boudaries and open boundary indicators
-      nbobc = 0
-      IF( lp_obc_east  )   nbobc = nbobc + 1
-      IF( lp_obc_west  )   nbobc = nbobc + 1
-      IF( lp_obc_north )   nbobc = nbobc + 1
-      IF( lp_obc_south )   nbobc = nbobc + 1
+
+      IF( obc_oce_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'obc_init : unable to allocate oce arrays' )
 
       IF(lwp) WRITE(numout,*)
       IF(lwp) WRITE(numout,*) 'obc_init : initialization of open boundaries'
       IF(lwp) WRITE(numout,*) '~~~~~~~~'
-      IF(lwp) WRITE(numout,*) '   Number of open boundaries    nbobc = ', nbobc
-      IF(lwp) WRITE(numout,*)
-
-      ! control prints
-      IF(lwp) WRITE(numout,*) '   Namelist namobc'
-      IF(lwp) WRITE(numout,*) '      data in file (=1) or initial state used (=0)   nn_obcdta   = ', nn_obcdta
-      IF(lwp) WRITE(numout,*) '      climatology (true) or not                      ln_obc_clim = ', ln_obc_clim
-      IF(lwp) WRITE(numout,*) '      vol_cst (true) or not:                         ln_vol_cst  = ', ln_vol_cst
-      IF(lwp) WRITE(numout,*) ' '
-      IF(lwp) WRITE(numout,*) '   WARNING                                                  '
-      IF(lwp) WRITE(numout,*) '      Flather"s algorithm is applied with explicit free surface scheme                 '
-      IF(lwp) WRITE(numout,*) '      or with free surface time-splitting scheme                                       '
-      IF(lwp) WRITE(numout,*) '      Nor radiation neither relaxation is allowed with explicit free surface scheme:   '
-      IF(lwp) WRITE(numout,*) '      Radiation and/or relaxation is allowed with free surface time-splitting scheme '
-      IF(lwp) WRITE(numout,*) '      depending of the choice of rdpXin = rdpXob  = 0. for open boundaries             '
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '      For the filtered free surface case,                                              '
-      IF(lwp) WRITE(numout,*) '      radiation, relaxation or presciption of data can be applied                      '
-      IF(lwp) WRITE(numout,*)
-
-      IF( lwp.AND.lp_obc_east ) THEN
-         WRITE(numout,*) '      East open boundary :'
-         WRITE(numout,*) '         i index                    jpieob   = ', jpieob
-         WRITE(numout,*) '         damping time scale (days)  rn_dpeob = ', rn_dpeob
-         WRITE(numout,*) '         damping time scale (days)  rn_dpein = ', rn_dpein
+      !
+
+      IF( jperio /= 0 )   CALL ctl_stop( 'Cyclic or symmetric,',   &
+         &                               ' and general open boundary condition are not compatible' )
+
+      cgrid= (/'T','U','V'/)
+
+      ! -----------------------------------------
+      ! Initialise and read namelist parameters
+      ! -----------------------------------------
+
+      nb_obc            = 0
+      ln_coords_file(:) = .false.
+      cn_coords_file(:) = ''
+      ln_mask_file      = .false.
+      cn_mask_file(:)   = ''
+      nn_dyn2d(:)       = 0
+      nn_dyn3d(:)       = 0
+      nn_tra(:)         = 0
+#if defined key_lim2
+      nn_ice_lim2(:)    = 0
+#endif
+      ln_tides(:)       = .false.
+      ln_vol            = .false.
+      ln_clim(:)        = .false.
+      nn_dtactl(:)      = -1  ! uninitialised flag
+      nn_volctl         = -1  ! uninitialised flag
+      nn_rimwidth(:)    = -1  ! uninitialised flag
+      nn_dmp2d_in(:)    = -1  ! uninitialised flag
+      nn_dmp2d_out(:)   = -1  ! uninitialised flag
+      nn_dmp3d_in(:)    = -1  ! uninitialised flag
+      nn_dmp3d_out(:)   = -1  ! uninitialised flag
+
+      REWIND( numnam )                    
+      READ  ( numnam, namobc )
+
+      ! -----------------------------------------
+      ! Check and write out namelist parameters
+      ! -----------------------------------------
+
+      !                                   ! control prints
+      IF(lwp) WRITE(numout,*) '         namobc'
+
+      IF( nb_obc .eq. 0 ) THEN 
+        IF(lwp) WRITE(numout,*) 'nb_obc = 0, NO OPEN BOUNDARIES APPLIED.'
+      ELSE
+        IF(lwp) WRITE(numout,*) 'Number of open boundary sets : ',nb_obc
       ENDIF
 
-      IF( lwp.AND.lp_obc_west ) THEN
-         WRITE(numout,*) '      West open boundary :'
-         WRITE(numout,*) '         i index                    jpiwob   = ', jpiwob
-         WRITE(numout,*) '         damping time scale (days)  rn_dpwob = ', rn_dpwob
-         WRITE(numout,*) '         damping time scale (days)  rn_dpwin = ', rn_dpwin
+      DO ib_obc = 1,nb_obc
+        IF(lwp) WRITE(numout,*) ' ' 
+        IF(lwp) WRITE(numout,*) '------ Open boundary data set ',ib_obc,'------' 
+
+        !                                         ! check type of data used (nn_dtactl value)
+        SELECT CASE( nn_dtactl(ib_obc) )                   ! 
+          CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for obc data'        
+          CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
+          CASE DEFAULT   ;   CALL ctl_stop( 'nn_dtactl must be 0 or 1' )
+        END SELECT
+        IF(lwp) WRITE(numout,*)
+
+        IF(lwp) WRITE(numout,*) 'Boundary conditions for barotropic solution:  '
+        SELECT CASE( nn_dyn2d(ib_obc) )                  
+          CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
+          CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+          CASE( 2 )      ;   IF(lwp) WRITE(numout,*) '      Flather radiation condition'
+          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_dyn2d' )
+        END SELECT
+        IF(lwp) WRITE(numout,*)
+
+        IF(lwp) WRITE(numout,*) 'Boundary conditions for baroclinic velocities:  '
+        SELECT CASE( nn_dyn3d(ib_obc) )                  
+          CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
+          CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_dyn3d' )
+        END SELECT
+        IF(lwp) WRITE(numout,*)
+
+        IF(lwp) WRITE(numout,*) 'Boundary conditions for temperature and salinity:  '
+        SELECT CASE( nn_tra(ib_obc) )                  
+          CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
+          CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_tra' )
+        END SELECT
+        IF(lwp) WRITE(numout,*)
+
+#if defined key_lim2
+        IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
+        SELECT CASE( nn_tra(ib_obc) )                  
+          CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
+          CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_tra' )
+        END SELECT
+        IF(lwp) WRITE(numout,*)
+#endif
+
+        IF(lwp) WRITE(numout,*) 'Boundary rim width for the FRS nn_rimwidth = ', nn_rimwidth
+        IF(lwp) WRITE(numout,*)
+
+        IF( ln_tides(ib_obc) ) THEN
+          IF(lwp) WRITE(numout,*) 'Tidal harmonic forcing at unstructured open boundaries'
+          IF(lwp) WRITE(numout,*)
+        ENDIF
+
+!!$        ! Presumably will need to read in a separate namelist for each boundary that includes tides???
+!!$        IF( ln_tides )   CALL tide_init( ib_obc )      ! Read tides namelist 
+
+
+      ENDDO
+
+     IF( ln_vol ) THEN                     ! check volume conservation (nn_volctl value)
+       IF(lwp) WRITE(numout,*) 'Volume correction applied at open boundaries'
+       IF(lwp) WRITE(numout,*)
+       SELECT CASE ( nn_volctl )
+         CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      The total volume will be constant'
+         CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      The total volume will vary according to the surface E-P flux'
+         CASE DEFAULT   ;   CALL ctl_stop( 'nn_volctl must be 0 or 1' )
+       END SELECT
+       IF(lwp) WRITE(numout,*)
+     ELSE
+       IF(lwp) WRITE(numout,*) 'No volume correction applied at open boundaries'
+       IF(lwp) WRITE(numout,*)
+     ENDIF
+
+      ! -------------------------------------------------
+      ! Initialise indices arrays for open boundaries
+      ! -------------------------------------------------
+
+      ! Work out global dimensions of boundary data
+      ! ---------------------------------------------
+      DO ib_obc = 1, nb_obc
+
+         jpbdta = 1
+         IF( .NOT. ln_coords_file(ib_obc) ) THEN ! Work out size of global arrays from namelist parameters
+ 
+
+           !! 1. Read parameters from namelist
+           !! 2. Work out global size of boundary data arrays nblendta and jpbdta
+
+
+         ELSE            ! Read size of arrays in boundary coordinates file.
+
+
+            CALL iom_open( cn_coords_file(ib_obc), inum )
+            jpbdta = 1
+            DO igrd = 1, jpbgrd
+               id_dummy = iom_varid( inum, 'nbi'//cgrid(igrd), kdimsz=kdimsz )  
+               nblendta(igrd,ib_obc) = kdimsz(1)
+               jpbdta = MAX(jpbdta, kdimsz(1))
+            ENDDO
+
+         ENDIF 
+
+      ENDDO
+
+      ! Allocate arrays
+      !---------------
+      ALLOCATE( nbidta(jpbdta, jpbgrd, nb_obc), nbjdta(jpbdta, jpbgrd, nb_obc),    &
+         &      nbrdta(jpbdta, jpbgrd, nb_obc) )
+
+      ALLOCATE( dta_global(jpbdta, 1, jpk) )
+
+      ! Calculate global boundary index arrays or read in from file
+      !------------------------------------------------------------
+      DO ib_obc = 1, nb_obc
+
+         IF( .NOT. ln_coords_file(ib_obc) ) THEN ! Calculate global index arrays from namelist parameters
+
+           !! Calculate global index arrays from namelist parameters
+
+         ELSE            ! Read global index arrays from boundary coordinates file.
+
+            DO igrd = 1, jpbgrd
+               CALL iom_get( inum, jpdom_unknown, 'nbi'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_obc),:,1) )
+               DO ii = 1,nblendta(igrd,ib_obc)
+                  nbidta(ii,igrd,ib_obc) = INT( dta_global(ii,1,1) )
+               END DO
+               CALL iom_get( inum, jpdom_unknown, 'nbj'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_obc),:,1) )
+               DO ii = 1,nblendta(igrd,ib_obc)
+                  nbjdta(ii,igrd,ib_obc) = INT( dta_global(ii,1,1) )
+               END DO
+               CALL iom_get( inum, jpdom_unknown, 'nbr'//cgrid(igrd), dta_global(1:nblendta(igrd,ib_obc),:,1) )
+               DO ii = 1,nblendta(igrd,ib_obc)
+                  nbrdta(ii,igrd,ib_obc) = INT( dta_global(ii,1,1) )
+               END DO
+
+               ibr_max = MAXVAL( nbrdta(:,igrd,ib_obc) )
+               IF(lwp) WRITE(numout,*)
+               IF(lwp) WRITE(numout,*) ' Maximum rimwidth in file is ', ibr_max
+               IF(lwp) WRITE(numout,*) ' nn_rimwidth from namelist is ', nn_rimwidth(ib_obc)
+               IF (ibr_max < nn_rimwidth(ib_obc))   &
+                     CALL ctl_stop( 'nn_rimwidth is larger than maximum rimwidth in file',cn_coords_file(ib_obc) )
+
+            END DO
+            CALL iom_close( inum )
+
+         ENDIF 
+
+      ENDDO 
+
+      ! Work out dimensions of boundary data on each processor
+      ! ------------------------------------------------------
+     
+      iw = mig(1) + 1            ! if monotasking and no zoom, iw=2
+      ie = mig(1) + nlci-1 - 1   ! if monotasking and no zoom, ie=jpim1
+      is = mjg(1) + 1            ! if monotasking and no zoom, is=2
+      in = mjg(1) + nlcj-1 - 1   ! if monotasking and no zoom, in=jpjm1
+
+      DO ib_obc = 1, nb_obc
+         DO igrd = 1, jpbgrd
+            icount  = 0
+            icountr = 0
+            idx_obc(ib_obc)%nblen(igrd)    = 0
+            idx_obc(ib_obc)%nblenrim(igrd) = 0
+            DO ib = 1, nblendta(igrd,ib_obc)
+               ! check if point is in local domain
+               IF(  nbidta(ib,igrd,ib_obc) >= iw .AND. nbidta(ib,igrd,ib_obc) <= ie .AND.   &
+                  & nbjdta(ib,igrd,ib_obc) >= is .AND. nbjdta(ib,igrd,ib_obc) <= in       ) THEN
+                  !
+                  icount = icount  + 1
+                  !
+                  IF( nbrdta(ib,igrd,ib_obc) == 1 )   icountr = icountr+1
+               ENDIF
+            ENDDO
+            idx_obc(ib_obc)%nblenrim(igrd) = icountr !: length of rim boundary data on each proc
+            idx_obc(ib_obc)%nblen   (igrd) = icount  !: length of boundary data on each proc        
+         ENDDO  ! igrd
+
+         ! Allocate index arrays for this boundary set
+         !--------------------------------------------
+         ilen1 = MAXVAL(idx_obc(ib_obc)%nblen(:))
+         ALLOCATE( idx_obc(ib_obc)%nbi(ilen1,jpbgrd) )
+         ALLOCATE( idx_obc(ib_obc)%nbj(ilen1,jpbgrd) )
+         ALLOCATE( idx_obc(ib_obc)%nbr(ilen1,jpbgrd) )
+         ALLOCATE( idx_obc(ib_obc)%nbmap(ilen1,jpbgrd) )
+         ALLOCATE( idx_obc(ib_obc)%nbw(ilen1,jpbgrd) )
+         ALLOCATE( idx_obc(ib_obc)%flagu(ilen1) )
+         ALLOCATE( idx_obc(ib_obc)%flagv(ilen1) )
+
+         ! Dispatch mapping indices and discrete distances on each processor
+         ! -----------------------------------------------------------------
+
+         DO igrd = 1, jpbgrd
+            icount  = 0
+            ! Loop on rimwidth to ensure outermost points come first in the local arrays.
+            DO ir=1, nn_rimwidth(ib_obc)
+               DO ib = 1, nblendta(igrd,ib_obc)
+                  ! check if point is in local domain and equals ir
+                  IF(  nbidta(ib,igrd,ib_obc) >= iw .AND. nbidta(ib,igrd,ib_obc) <= ie .AND.   &
+                     & nbjdta(ib,igrd,ib_obc) >= is .AND. nbjdta(ib,igrd,ib_obc) <= in .AND.   &
+                     & nbrdta(ib,igrd,ib_obc) == ir  ) THEN
+                     !
+                     icount = icount  + 1
+                     idx_obc(ib_obc)%nbi(icount,igrd)   = nbidta(ib,igrd,ib_obc)- mig(1)+1
+                     idx_obc(ib_obc)%nbj(icount,igrd)   = nbjdta(ib,igrd,ib_obc)- mjg(1)+1
+                     idx_obc(ib_obc)%nbr(icount,igrd)   = nbrdta(ib,igrd,ib_obc)
+                     idx_obc(ib_obc)%nbmap(icount,igrd) = ib
+                  ENDIF
+               ENDDO
+            ENDDO
+         ENDDO 
+
+         ! Compute rim weights
+         ! -------------------
+         DO igrd = 1, jpbgrd
+            DO ib = 1, idx_obc(ib_obc)%nblen(igrd)
+               nbr => idx_obc(ib_obc)%nbr(ib,igrd)
+               idx_obc(ib_obc)%nbw(ib,igrd) = 1.- TANH( FLOAT( nbr - 1 ) *0.5 )      ! tanh formulation
+!              idx_obc(ib_obc)%nbw(ib,igrd) = (FLOAT(nn_rimwidth+1-nbr)/FLOAT(nn_rimwidth))**2      ! quadratic
+!              idx_obc(ib_obc)%nbw(ib,igrd) =  FLOAT(nn_rimwidth+1-nbr)/FLOAT(nn_rimwidth)          ! linear
+            END DO
+         END DO 
+
+      ENDDO
+
+      ! ------------------------------------------------------
+      ! Initialise masks and find normal/tangential directions
+      ! ------------------------------------------------------
+
+      ! Read global 2D mask at T-points: obctmask
+      ! -----------------------------------------
+      ! obctmask = 1  on the computational domain AND on open boundaries
+      !          = 0  elsewhere   
+ 
+      IF( cp_cfg == "eel" .AND. jp_cfg == 5 ) THEN          ! EEL configuration at 5km resolution
+         zmask(         :                ,:) = 0.e0
+         zmask(jpizoom+1:jpizoom+jpiglo-2,:) = 1.e0          
+      ELSE IF( ln_mask_file ) THEN
+         CALL iom_open( cn_mask_file, inum )
+         CALL iom_get ( inum, jpdom_data, 'obc_msk', zmask(:,:) )
+         CALL iom_close( inum )
+      ELSE
+         zmask(:,:) = 1.e0
       ENDIF
 
-      IF( lwp.AND.lp_obc_north ) THEN
-         WRITE(numout,*) '      North open boundary :'
-         WRITE(numout,*) '         j index                    jpjnob   = ', jpjnob
-         WRITE(numout,*) '         damping time scale (days)  rn_dpnob = ', rn_dpnob
-         WRITE(numout,*) '         damping time scale (days)  rn_dpnin = ', rn_dpnin
-      ENDIF
-
-      IF( lwp.AND.lp_obc_south ) THEN
-         WRITE(numout,*) '      South open boundary :'
-         WRITE(numout,*) '         j index                    jpjsob   = ', jpjsob
-         WRITE(numout,*) '         damping time scale (days)  rn_dpsob = ', rn_dpsob
-         WRITE(numout,*) '         damping time scale (days)  rn_dpsin = ', rn_dpsin
-         WRITE(numout,*)
-      ENDIF
-
-      IF( nbobc >= 2 .AND. jperio /= 0 )   &
-         &   CALL ctl_stop( ' Cyclic or symmetric, and open boundary condition are not compatible' )
-
-      ! 1. Initialisation of constants 
-      ! ------------------------------
-      ! ...                          convert rdp$ob in seconds
-      ! Fixed Bdy flag              inbound                outbound
-      lfbceast  = .FALSE.   ;   rdpein = rdpein * rday    ;   rdpeob = rdpeob * rday
-      lfbcwest  = .FALSE.   ;   rdpwin = rdpwin * rday    ;   rdpwob = rdpwob * rday
-      lfbcnorth = .FALSE.   ;   rdpnin = rdpnin * rday    ;   rdpnob = rdpnob * rday
-      lfbcsouth = .FALSE.   ;   rdpsin = rdpsin * rday    ;   rdpsob = rdpsob * rday
-      inumfbc = 0
-      ! ... look for Fixed Boundaries (rdp = 0 )
-      ! ... When specified, lbcxxx flags are set to TRUE and rdpxxx are set to
-      ! ...  a small arbitrary value, (to avoid division by zero further on). 
-      ! ...  rdpxxx is not used anymore.
-      IF( lp_obc_east )  THEN
-         IF( (rdpein+rdpeob) == 0 )  THEN
-            lfbceast = .TRUE.   ;   rdpein = 1e-3   ;   rdpeob = 1e-3
-            inumfbc = inumfbc+1
-         ELSEIF ( (rdpein*rdpeob) == 0 )  THEN
-            CALL ctl_stop( 'obc_init : rn_dpein & rn_dpeob must be both zero or non zero' )
-         END IF
-      END IF
-
-      IF( lp_obc_west )  THEN
-         IF( (rdpwin + rdpwob) == 0 )  THEN
-            lfbcwest = .TRUE.     ;     rdpwin = 1e-3     ;     rdpwob = 1e-3
-            inumfbc = inumfbc+1
-         ELSEIF ( (rdpwin*rdpwob) == 0 )  THEN
-            CALL ctl_stop( 'obc_init : rn_dpwin & rn_dpwob must be both zero or non zero' )
-         END IF
-      END IF
-      IF( lp_obc_north )  THEN
-         IF( (rdpnin + rdpnob) == 0 )  THEN
-            lfbcnorth = .TRUE.     ;     rdpnin = 1e-3     ;     rdpnob = 1e-3
-            inumfbc = inumfbc+1
-         ELSEIF ( (rdpnin*rdpnob) == 0 )  THEN
-            CALL ctl_stop( 'obc_init : rn_dpnin & rn_dpnob must be both zero or non zero' )
-         END IF
-      END IF
-      IF( lp_obc_south )  THEN
-         IF( (rdpsin + rdpsob) == 0 )  THEN
-            lfbcsouth = .TRUE.   ;   rdpsin = 1e-3   ;   rdpsob = 1e-3
-            inumfbc = inumfbc+1
-         ELSEIF ( (rdpsin*rdpsob) == 0 )  THEN
-            CALL ctl_stop( 'obc_init : rn_dpsin & rn_dpsob must be both zero or non zero' )
-         END IF
-      END IF
-
-      ! 2.  Clever mpp indices for loops on the open boundaries. 
-      !     The loops will be performed only on the processors 
-      !     that contain a given open boundary.
-      ! --------------------------------------------------------
-
-      IF( lp_obc_east ) THEN
-         ! ...   mpp initialization
-         nie0   = max( 1, min(jpieob   - nimpp+1, jpi     ) )
-         nie1   = max( 0, min(jpieob   - nimpp+1, jpi - 1 ) )
-         nie0p1 = max( 1, min(jpieob+1 - nimpp+1, jpi     ) )
-         nie1p1 = max( 0, min(jpieob+1 - nimpp+1, jpi - 1 ) )
-         nie0m1 = max( 1, min(jpieob-1 - nimpp+1, jpi     ) )
-         nie1m1 = max( 0, min(jpieob-1 - nimpp+1, jpi - 1 ) )
-         nje0   = max( 2, min(jpjed    - njmpp+1, jpj     ) )
-         nje1   = max( 0, min(jpjef    - njmpp+1, jpj - 1 ) )
-         nje0p1 = max( 1, min(jpjedp1  - njmpp+1, jpj     ) )
-         nje0m1 = max( 1, min(jpjed    - njmpp+1, jpj     ) )
-         nje1m1 = max( 0, min(jpjefm1  - njmpp+1, jpj - 1 ) )
-         nje1m2 = max( 0, min(jpjefm1-1- njmpp+1, jpj - 1 ) )
-         IF(lwp) THEN
-            IF( lfbceast ) THEN
-               WRITE(numout,*)'     '
-               WRITE(numout,*)'         Specified East Open Boundary'
+      DO ij = 1, nlcj      ! Save mask over local domain      
+         DO ii = 1, nlci
+            obctmask(ii,ij) = zmask( mig(ii), mjg(ij) )
+         END DO
+      END DO
+
+      ! Derive mask on U and V grid from mask on T grid
+      obcumask(:,:) = 0.e0
+      obcvmask(:,:) = 0.e0
+      DO ij=1, jpjm1
+         DO ii=1, jpim1
+            obcumask(ii,ij)=obctmask(ii,ij)*obctmask(ii+1, ij )
+            obcvmask(ii,ij)=obctmask(ii,ij)*obctmask(ii  ,ij+1)  
+         END DO
+      END DO
+      CALL lbc_lnk( obcumask(:,:), 'U', 1. )   ;   CALL lbc_lnk( obcvmask(:,:), 'V', 1. )      ! Lateral boundary cond.
+
+
+      ! Mask corrections
+      ! ----------------
+      DO ik = 1, jpkm1
+         DO ij = 1, jpj
+            DO ii = 1, jpi
+               tmask(ii,ij,ik) = tmask(ii,ij,ik) * obctmask(ii,ij)
+               umask(ii,ij,ik) = umask(ii,ij,ik) * obcumask(ii,ij)
+               vmask(ii,ij,ik) = vmask(ii,ij,ik) * obcvmask(ii,ij)
+               bmask(ii,ij)    = bmask(ii,ij)    * obctmask(ii,ij)
+            END DO      
+         END DO
+      END DO
+
+      DO ik = 1, jpkm1
+         DO ij = 2, jpjm1
+            DO ii = 2, jpim1
+               fmask(ii,ij,ik) = fmask(ii,ij,ik) * obctmask(ii,ij  ) * obctmask(ii+1,ij  )   &
+                  &                              * obctmask(ii,ij+1) * obctmask(ii+1,ij+1)
+            END DO      
+         END DO
+      END DO
+
+      tmask_i (:,:) = tmask(:,:,1) * tmask_i(:,:)             
+      obctmask(:,:) = tmask(:,:,1)
+
+      ! obc masks and bmask are now set to zero on boundary points:
+      igrd = 1       ! In the free surface case, bmask is at T-points
+      DO ib_obc = 1, nb_obc
+        DO ib = 1, idx_obc(ib_obc)%nblenrim(igrd)     
+          bmask(idx_obc(ib_obc)%nbi(ib,igrd), idx_obc(ib_obc)%nbj(ib,igrd)) = 0.e0
+        ENDDO
+      ENDDO
+      !
+      igrd = 1
+      DO ib_obc = 1, nb_obc
+        DO ib = 1, idx_obc(ib_obc)%nblenrim(igrd)      
+          obctmask(idx_obc(ib_obc)%nbi(ib,igrd), idx_obc(ib_obc)%nbj(ib,igrd)) = 0.e0
+        ENDDO
+      ENDDO
+      !
+      igrd = 2
+      DO ib_obc = 1, nb_obc
+        DO ib = 1, idx_obc(ib_obc)%nblenrim(igrd)
+          obcumask(idx_obc(ib_obc)%nbi(ib,igrd), idx_obc(ib_obc)%nbj(ib,igrd)) = 0.e0
+        ENDDO
+      ENDDO
+      !
+      igrd = 3
+      DO ib_obc = 1, nb_obc
+        DO ib = 1, idx_obc(ib_obc)%nblenrim(igrd)
+          obcvmask(idx_obc(ib_obc)%nbi(ib,igrd), idx_obc(ib_obc)%nbj(ib,igrd)) = 0.e0
+        ENDDO
+      ENDDO
+
+      ! Lateral boundary conditions
+      CALL lbc_lnk( fmask        , 'F', 1. )   ;   CALL lbc_lnk( obctmask(:,:), 'T', 1. )
+      CALL lbc_lnk( obcumask(:,:), 'U', 1. )   ;   CALL lbc_lnk( obcvmask(:,:), 'V', 1. )
+
+      DO ib_obc = 1, nb_obc       ! Indices and directions of rim velocity components
+
+         idx_obc(ib_obc)%flagu(:) = 0.e0
+         idx_obc(ib_obc)%flagv(:) = 0.e0
+         icount = 0 
+
+         !flagu = -1 : u component is normal to the dynamical boundary but its direction is outward
+         !flagu =  0 : u is tangential
+         !flagu =  1 : u is normal to the boundary and is direction is inward
+  
+         igrd = 2      ! u-component 
+         DO ib = 1, idx_obc(ib_obc)%nblenrim(igrd)  
+            nbi => idx_obc(ib_obc)%nbi(ib,igrd)
+            nbj => idx_obc(ib_obc)%nbj(ib,igrd)
+            zefl = obctmask(nbi  ,nbj)
+            zwfl = obctmask(nbi+1,nbj)
+            IF( zefl + zwfl == 2 ) THEN
+               icount = icount + 1
             ELSE
-               WRITE(numout,*)'     '
-               WRITE(numout,*)'         Radiative East Open Boundary'
+               idx_obc(ib_obc)%flagu(ib)=-zefl+zwfl
+            ENDIF
+         END DO
+
+         !flagv = -1 : u component is normal to the dynamical boundary but its direction is outward
+         !flagv =  0 : u is tangential
+         !flagv =  1 : u is normal to the boundary and is direction is inward
+
+         igrd = 3      ! v-component
+         DO ib = 1, idx_obc(ib_obc)%nblenrim(igrd)  
+            nbi => idx_obc(ib_obc)%nbi(ib,igrd)
+            nbj => idx_obc(ib_obc)%nbj(ib,igrd)
+            znfl = obctmask(nbi,nbj  )
+            zsfl = obctmask(nbi,nbj+1)
+            IF( znfl + zsfl == 2 ) THEN
+               icount = icount + 1
+            ELSE
+               idx_obc(ib_obc)%flagv(ib) = -znfl + zsfl
             END IF
-         END IF
-      END IF
-
-      IF( lp_obc_west ) THEN
-         ! ...   mpp initialization
-         niw0   = max( 1, min(jpiwob   - nimpp+1, jpi     ) )
-         niw1   = max( 0, min(jpiwob   - nimpp+1, jpi - 1 ) )
-         niw0p1 = max( 1, min(jpiwob+1 - nimpp+1, jpi     ) )
-         niw1p1 = max( 0, min(jpiwob+1 - nimpp+1, jpi - 1 ) )
-         njw0   = max( 2, min(jpjwd    - njmpp+1, jpj     ) )
-         njw1   = max( 0, min(jpjwf    - njmpp+1, jpj - 1 ) )
-         njw0p1 = max( 1, min(jpjwdp1  - njmpp+1, jpj     ) )
-         njw0m1 = max( 1, min(jpjwd    - njmpp+1, jpj     ) )
-         njw1m1 = max( 0, min(jpjwfm1  - njmpp+1, jpj - 1 ) )
-         njw1m2 = max( 0, min(jpjwfm1-1- njmpp+1, jpj - 1 ) )
-         IF(lwp) THEN
-            IF( lfbcwest ) THEN
-               WRITE(numout,*)'     '
-               WRITE(numout,*)'         Specified West Open Boundary'
-            ELSE
-               WRITE(numout,*)'     '
-               WRITE(numout,*)'         Radiative West Open Boundary'
-            END IF
-         END IF
-      END IF
+         END DO
  
-      IF( lp_obc_north ) THEN
-         ! ...   mpp initialization
-         nin0   = max( 2, min(jpind    - nimpp+1, jpi     ) )
-         nin1   = max( 0, min(jpinf    - nimpp+1, jpi - 1 ) )
-         nin0p1 = max( 1, min(jpindp1  - nimpp+1, jpi     ) )
-         nin0m1 = max( 1, min(jpind    - nimpp+1, jpi     ) )
-         nin1m1 = max( 0, min(jpinfm1  - nimpp+1, jpi - 1 ) )
-         nin1m2 = max( 0, min(jpinfm1-1- nimpp+1, jpi - 1 ) )
-         njn0   = max( 1, min(jpjnob   - njmpp+1, jpj     ) )
-         njn1   = max( 0, min(jpjnob   - njmpp+1, jpj - 1 ) )
-         njn0p1 = max( 1, min(jpjnob+1 - njmpp+1, jpj     ) )
-         njn1p1 = max( 0, min(jpjnob+1 - njmpp+1, jpj - 1 ) )
-         njn0m1 = max( 1, min(jpjnob-1 - njmpp+1, jpj     ) )
-         njn1m1 = max( 0, min(jpjnob-1 - njmpp+1, jpj - 1 ) )
-         IF(lwp) THEN
-            IF( lfbcnorth ) THEN
-               WRITE(numout,*)'     '
-               WRITE(numout,*)'         Specified North Open Boundary'
-            ELSE
-               WRITE(numout,*)'     '
-               WRITE(numout,*)'         Radiative North Open Boundary'
-            END IF
-         END IF
-      END IF
-
-      IF( lp_obc_south ) THEN
-         ! ...   mpp initialization
-         nis0   = max( 2, min(jpisd    - nimpp+1, jpi     ) )
-         nis1   = max( 0, min(jpisf    - nimpp+1, jpi - 1 ) )
-         nis0p1 = max( 1, min(jpisdp1  - nimpp+1, jpi     ) )
-         nis0m1 = max( 1, min(jpisd    - nimpp+1, jpi     ) )
-         nis1m1 = max( 0, min(jpisfm1  - nimpp+1, jpi - 1 ) )
-         nis1m2 = max( 0, min(jpisfm1-1- nimpp+1, jpi - 1 ) )
-         njs0   = max( 1, min(jpjsob   - njmpp+1, jpj     ) )
-         njs1   = max( 0, min(jpjsob   - njmpp+1, jpj - 1 ) )
-         njs0p1 = max( 1, min(jpjsob+1 - njmpp+1, jpj     ) )
-         njs1p1 = max( 0, min(jpjsob+1 - njmpp+1, jpj - 1 ) )
-         IF(lwp) THEN
-            IF( lfbcsouth ) THEN
-               WRITE(numout,*)'     '
-               WRITE(numout,*)'         Specified South Open Boundary'
-            ELSE
-               WRITE(numout,*)'     '
-               WRITE(numout,*)'         Radiative South Open Boundary'
-            END IF
-         END IF
-      END IF
-
-      ! 3. mask correction for OBCs
-      ! ---------------------------
-
-      IF( lp_obc_east ) THEN
-         !... (jpjed,jpjefm1),jpieob
-         bmask(nie0p1:nie1p1,nje0:nje1m1) = 0.e0
-
-         ! ... initilization to zero
-         uemsk(:,:) = 0.e0   ;   vemsk(:,:) = 0.e0   ;   temsk(:,:) = 0.e0
-
-         ! ... set 2D mask on East OBC,  Vopt
-         DO ji = fs_nie0, fs_nie1
-            DO jj = nje0, nje1
-               uemsk(jj,:) = umask(ji,  jj,:) * tmask_i(ji,jj)   * tmask_i(ji+1,jj)
-               vemsk(jj,:) = vmask(ji+1,jj,:) * tmask_i(ji+1,jj) 
-               temsk(jj,:) = tmask(ji+1,jj,:) * tmask_i(ji+1,jj) 
-            END DO
-         END DO
-
-      END IF
-
-      IF( lp_obc_west ) THEN
-         ! ... (jpjwd,jpjwfm1),jpiwob
-         bmask(niw0:niw1,njw0:njw1m1) = 0.e0
-
-         ! ... initilization to zero
-         uwmsk(:,:) = 0.e0   ;   vwmsk(:,:) = 0.e0   ;   twmsk(:,:) = 0.e0  
-
-         ! ... set 2D mask on West OBC,  Vopt
-         DO ji = fs_niw0, fs_niw1
-            DO jj = njw0, njw1
-               uwmsk(jj,:) = umask(ji,jj,:) * tmask_i(ji,jj)   * tmask_i(ji+1,jj)
-               vwmsk(jj,:) = vmask(ji,jj,:) * tmask_i(ji,jj)  
-               twmsk(jj,:) = tmask(ji,jj,:) * tmask_i(ji,jj)
-            END DO
-         END DO
-
-      END IF
-
-      IF( lp_obc_north ) THEN
-         ! ... jpjnob,(jpind,jpisfm1)
-         bmask(nin0:nin1m1,njn0p1:njn1p1) = 0.e0
-
-         ! ... initilization to zero
-         unmsk(:,:) = 0.e0   ;   vnmsk(:,:) = 0.e0   ;   tnmsk(:,:) = 0.e0
-
-         ! ... set 2D mask on North OBC,  Vopt
-         DO jj = fs_njn0, fs_njn1
-            DO ji = nin0, nin1
-               unmsk(ji,:) = umask(ji,jj+1,:) * tmask_i(ji,jj+1) 
-               vnmsk(ji,:) = vmask(ji,jj  ,:) * tmask_i(ji,jj)   * tmask_i(ji,jj+1)
-               tnmsk(ji,:) = tmask(ji,jj+1,:) * tmask_i(ji,jj+1)
-            END DO
-         END DO
-
-      END IF
-
-      IF( lp_obc_south ) THEN 
-         ! ... jpjsob,(jpisd,jpisfm1)
-         bmask(nis0:nis1m1,njs0:njs1) = 0.e0
-
-         ! ... initilization to zero
-         usmsk(:,:) = 0.e0   ;   vsmsk(:,:) = 0.e0   ;   tsmsk(:,:) = 0.e0
-
-         ! ... set 2D mask on South OBC,  Vopt
-         DO jj = fs_njs0, fs_njs1 
-            DO ji = nis0, nis1
-               usmsk(ji,:) = umask(ji,jj,:) * tmask_i(ji,jj) 
-               vsmsk(ji,:) = vmask(ji,jj,:) * tmask_i(ji,jj) * tmask_i(ji,jj+1)
-               tsmsk(ji,:) = tmask(ji,jj,:) * tmask_i(ji,jj)
-            END DO
-         END DO
-
-      END IF
-
-      ! ... Initialize obcumask and obcvmask for the Force filtering 
-      !     boundary condition in dynspg_flt
-      obcumask(:,:) = umask(:,:,1)
-      obcvmask(:,:) = vmask(:,:,1)
-
-      ! ... Initialize obctmsk on overlap region and obcs. This mask
-      !     is used in obcvol.F90 to calculate cumulate flux E-P. 
-      !     obc Tracer point are outside the domain ( U/V obc points) ==> masked by obctmsk
-      !     - no flux E-P on obcs and overlap region (jpreci = jprecj = 1)
-      obctmsk(:,:) = tmask_i(:,:)     
-
-      IF( lp_obc_east ) THEN
-         ! ... East obc Force filtering mask for the grad D
-         obcumask(nie0  :nie1  ,nje0p1:nje1m1) = 0.e0
-         obcvmask(nie0p1:nie1p1,nje0p1:nje1m1) = 0.e0
-         ! ... set to 0 on East OBC
-         obctmsk(nie0p1:nie1p1,nje0:nje1) = 0.e0
-      END IF
-
-      IF( lp_obc_west ) THEN
-         ! ... West obc Force filtering mask for the grad D
-         obcumask(niw0:niw1,njw0:njw1) = 0.e0
-         obcvmask(niw0:niw1,njw0:njw1) = 0.e0
-         ! ... set to 0 on West OBC
-         obctmsk(niw0:niw1,njw0:njw1) = 0.e0
-      END IF
-
-      IF( lp_obc_north ) THEN
-         ! ... North obc Force filtering mask for the grad D
-         obcumask(nin0p1:nin1m1,njn0p1:njn1p1) = 0.e0
-         obcvmask(nin0p1:nin1m1,njn0  :njn1  ) = 0.e0
-         ! ... set to 0 on North OBC
-         obctmsk(nin0:nin1,njn0p1:njn1p1) = 0.e0
-      END IF
-
-      IF( lp_obc_south ) THEN
-         ! ... South obc Force filtering mask for the grad D
-         obcumask(nis0p1:nis1m1,njs0:njs1) = 0.e0
-         obcvmask(nis0p1:nis1m1,njs0:njs1) = 0.e0
-         ! ... set to 0 on South OBC
-         obctmsk(nis0:nis1,njs0:njs1) = 0.e0
-      END IF
-
-      ! 3.1 Total lateral surface 
-      ! -------------------------
-      obcsurftot = 0.e0
-
-      IF( lp_obc_east ) THEN ! ... East open boundary lateral surface
-         DO ji = nie0, nie1
-            DO jj = 1, jpj 
-               obcsurftot = obcsurftot+hu(ji,jj)*e2u(ji,jj)*uemsk(jj,1) * MAX(obctmsk(ji,jj),obctmsk(ji+1,jj) )
-            END DO
-         END DO
-      END IF
-
-      IF( lp_obc_west ) THEN ! ... West open boundary lateral surface
-         DO ji = niw0, niw1
-            DO jj = 1, jpj 
-               obcsurftot = obcsurftot+hu(ji,jj)*e2u(ji,jj)*uwmsk(jj,1) * MAX(obctmsk(ji,jj),obctmsk(ji+1,jj) )
-            END DO
-         END DO
-      END IF
-
-      IF( lp_obc_north ) THEN ! ... North open boundary lateral surface
-         DO jj = njn0, njn1
-            DO ji = 1, jpi
-               obcsurftot = obcsurftot+hv(ji,jj)*e1v(ji,jj)*vnmsk(ji,1) * MAX(obctmsk(ji,jj),obctmsk(ji,jj+1) )
-            END DO
-         END DO
-      END IF
-
-      IF( lp_obc_south ) THEN ! ... South open boundary lateral surface
-         DO jj = njs0, njs1
-            DO ji = 1, jpi
-               obcsurftot = obcsurftot+hv(ji,jj)*e1v(ji,jj)*vsmsk(ji,1) * MAX(obctmsk(ji,jj),obctmsk(ji,jj+1) )
-            END DO
-         END DO
-      END IF
-
-      IF( lk_mpp )   CALL mpp_sum( obcsurftot )   ! sum over the global domain
-
-      ! 5. Control print on mask 
-      !    The extremities of the open boundaries must be in land
-      !    or else correspond to an "ocean corner" between two open boundaries. 
-      !    corner 1 is southwest, 2 is south east, 3 is northeast, 4 is northwest. 
-      ! --------------------------------------------------------------------------
-
-      icorner(:)=0
-
-      ! ... control of the west boundary
-      IF( lp_obc_west ) THEN
-         IF( jpiwob < 2 .OR.  jpiwob >= jpiglo-2 ) THEN
-            WRITE(ctmp1,*) ' jpiwob exceed ', jpiglo-2, 'or less than 2'
-            CALL ctl_stop( ctmp1 )
-         END IF
-         ztestmask(:)=0.
-         DO ji=niw0,niw1
-            IF( (njw0 + njmpp - 1) == jpjwd ) ztestmask(1)=ztestmask(1)+ tmask(ji,njw0,1)
-            IF( (njw1 + njmpp - 1) == jpjwf ) ztestmask(2)=ztestmask(2)+ tmask(ji,njw1,1)
-         END DO
-         IF( lk_mpp )   CALL mpp_sum( ztestmask, 2 )   ! sum over the global domain
-
-         IF( ztestmask(1) /= 0. ) icorner(1)=icorner(1)+1
-         IF( ztestmask(2) /= 0. ) icorner(4)=icorner(4)+1
-      END IF
-
-      ! ... control of the east boundary
-      IF( lp_obc_east ) THEN
-         IF( jpieob < 4 .OR.  jpieob >= jpiglo ) THEN
-            WRITE(ctmp1,*) ' jpieob exceed ', jpiglo, ' or less than 4'
-            CALL ctl_stop( ctmp1 )
-         END IF
-         ztestmask(:)=0.
-         DO ji=nie0p1,nie1p1
-            IF( (nje0 + njmpp - 1) == jpjed ) ztestmask(1)=ztestmask(1)+ tmask(ji,nje0,1)
-            IF( (nje1 + njmpp - 1) == jpjef ) ztestmask(2)=ztestmask(2)+ tmask(ji,nje1,1)
-         END DO
-         IF( lk_mpp )   CALL mpp_sum( ztestmask, 2 )   ! sum over the global domain
-
-        IF( ztestmask(1) /= 0. ) icorner(2)=icorner(2)+1
-        IF( ztestmask(2) /= 0. ) icorner(3)=icorner(3)+1
-      END IF
-
-      ! ... control of the north boundary
-      IF( lp_obc_north ) THEN
-         IF( jpjnob < 4 .OR.  jpjnob >= jpjglo ) THEN
-            WRITE(ctmp1,*) 'jpjnob exceed ', jpjglo, ' or less than 4'
-            CALL ctl_stop( ctmp1 )
-         END IF
-         ztestmask(:)=0.
-         DO jj=njn0p1,njn1p1
-            IF( (nin0 + nimpp - 1) == jpind ) ztestmask(1)=ztestmask(1)+ tmask(nin0,jj,1)
-            IF( (nin1 + nimpp - 1) == jpinf ) ztestmask(2)=ztestmask(2)+ tmask(nin1,jj,1)
-         END DO
-         IF( lk_mpp )   CALL mpp_sum( ztestmask, 2 )   ! sum over the global domain
-
-         IF( ztestmask(1) /= 0. ) icorner(4)=icorner(4)+1
-         IF( ztestmask(2) /= 0. ) icorner(3)=icorner(3)+1
-      END IF
-
-      ! ... control of the south boundary
-      IF( lp_obc_south ) THEN
-         IF( jpjsob < 2 .OR.  jpjsob >= jpjglo-2 ) THEN
-            WRITE(ctmp1,*) ' jpjsob exceed ', jpjglo-2, ' or less than 2'
-            CALL ctl_stop( ctmp1 )
-         END IF
-         ztestmask(:)=0.
-         DO jj=njs0,njs1
-            IF( (nis0 + nimpp - 1) == jpisd ) ztestmask(1)=ztestmask(1)+ tmask(nis0,jj,1)
-            IF( (nis1 + nimpp - 1) == jpisf ) ztestmask(2)=ztestmask(2)+ tmask(nis1,jj,1)
-         END DO
-         IF( lk_mpp )   CALL mpp_sum( ztestmask, 2 )   ! sum over the global domain
-
-         IF( ztestmask(1) /= 0. ) icorner(1)=icorner(1)+1
-         IF( ztestmask(2) /= 0. ) icorner(2)=icorner(2)+1
-      END IF
-
-      IF( icorner(1) == 2 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) ' South West ocean corner, two open boudaries'
-         IF(lwp) WRITE(numout,*) ' ========== '
-         IF(lwp) WRITE(numout,*)
-         IF( jpisd /= jpiwob.OR.jpjsob /= jpjwd ) &
-              &   CALL ctl_stop( ' Open boundaries do not fit, we stop' )
-
-      ELSE IF( icorner(1) == 1 ) THEN
-         CALL ctl_stop( ' Open boundaries do not fit at SW corner, we stop' )
-      END IF 
-
-      IF( icorner(2) == 2 ) THEN
-          IF(lwp) WRITE(numout,*)
-          IF(lwp) WRITE(numout,*) ' South East ocean corner, two open boudaries'
-          IF(lwp) WRITE(numout,*) ' ========== '
-          IF(lwp) WRITE(numout,*)
-          IF( jpisf /= jpieob+1.OR.jpjsob /= jpjed ) &
-               &   CALL ctl_stop( ' Open boundaries do not fit, we stop' )
-      ELSE IF( icorner(2) == 1 ) THEN
-         CALL ctl_stop( ' Open boundaries do not fit at SE corner, we stop' )
-      END IF 
-
-      IF( icorner(3) == 2 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) ' North East ocean corner, two open boudaries'
-         IF(lwp) WRITE(numout,*) ' ========== '
-         IF(lwp) WRITE(numout,*)
-         IF( jpinf /= jpieob+1 .OR. jpjnob+1 /= jpjef ) &
-              &   CALL ctl_stop( ' Open boundaries do not fit, we stop' )
-       ELSE IF( icorner(3) == 1 ) THEN
-          CALL ctl_stop( ' Open boundaries do not fit at NE corner, we stop' )
-       END IF 
-
-      IF( icorner(4) == 2 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) ' North West ocean corner, two open boudaries'
-         IF(lwp) WRITE(numout,*) ' ========== '
-         IF(lwp) WRITE(numout,*)
-         IF( jpind /= jpiwob.OR.jpjnob+1 /= jpjwf ) &
-              &   CALL ctl_stop( ' Open boundaries do not fit, we stop' )
-       ELSE IF( icorner(4) == 1 ) THEN
-          CALL ctl_stop( ' Open boundaries do not fit at NW corner, we stop' )
-       END IF 
-
-      ! 6. Initialization of open boundary variables (u, v, t, s)
-      ! --------------------------------------------------------------
-      !   only if at least one boundary is  radiative 
-      IF ( inumfbc < nbobc .AND.  ln_rstart ) THEN
-         !  Restart from restart.obc
-         CALL obc_rst_read
-      ELSE
-
-!         ! ... Initialization to zero of radiation arrays.
-!         !     Those have dimensions of local subdomains
-
-          uebnd(:,:,:,:) = 0.e0   ;   unbnd(:,:,:,:) = 0.e0
-          vebnd(:,:,:,:) = 0.e0   ;   vnbnd(:,:,:,:) = 0.e0
-          tebnd(:,:,:,:) = 0.e0   ;   tnbnd(:,:,:,:) = 0.e0
-          sebnd(:,:,:,:) = 0.e0   ;   snbnd(:,:,:,:) = 0.e0
-
-          uwbnd(:,:,:,:) = 0.e0   ;   usbnd(:,:,:,:) = 0.e0
-          vwbnd(:,:,:,:) = 0.e0   ;   vsbnd(:,:,:,:) = 0.e0
-          twbnd(:,:,:,:) = 0.e0   ;   tsbnd(:,:,:,:) = 0.e0
-          swbnd(:,:,:,:) = 0.e0   ;   ssbnd(:,:,:,:) = 0.e0
-
-      END IF
-
-      ! 7. Control print
-      ! -----------------------------------------------------------------
-
-      ! ... control of the east boundary
-      IF( lp_obc_east ) THEN
-         istop = 0
-         IF( jpieob < 4 .OR.  jpieob >= jpiglo ) THEN
-            IF(lwp) WRITE(numout,cform_err)
-            IF(lwp) WRITE(numout,*) '            jpieob exceed ', jpim1, ' or less than 4'
-            istop = istop + 1
-         END IF
-
-         IF( lk_mpp ) THEN
-            ! ... 
-            IF( nimpp > jpieob-5) THEN
-               IF(lwp) WRITE(numout,cform_err)
-               IF(lwp) WRITE(numout,*) '        A sub-domain is too close to the East OBC'
-               IF(lwp) WRITE(numout,*) '        nimpp must be < jpieob-5'
-               istop = istop + 1
-            ENDIF
-         ELSE
-
-            ! ... stop if  e r r o r (s)   detected
-            IF( istop /= 0 ) THEN
-               WRITE(ctmp1,*) istop,' obcini : E R R O R (S) detected : stop'
-               CALL ctl_stop( ctmp1 )
-            ENDIF
-         ENDIF
-      ENDIF
-
-      ! ... control of the west boundary
-      IF( lp_obc_west ) THEN
-         istop = 0
-         IF( jpiwob < 2 .OR.  jpiwob >= jpiglo ) THEN
-            IF(lwp) WRITE(numout,cform_err)
-            IF(lwp) WRITE(numout,*) '            jpiwob exceed ', jpim1, ' or less than 2'
-            istop = istop + 1
-         END IF
-
-         IF( lk_mpp ) THEN
-            IF( (nimpp < jpiwob+5) .AND. (nimpp > 1) ) THEN
-               IF(lwp) WRITE(numout,cform_err)
-               IF(lwp) WRITE(numout,*) '        A sub-domain is too close to the West OBC'
-               IF(lwp) WRITE(numout,*) '        nimpp must be > jpiwob-5 or =1'
-               istop = istop + 1
-            ENDIF
-         ELSE
-   
-            ! ... stop if  e r r o r (s)   detected
-            IF( istop /= 0 ) THEN
-               WRITE(ctmp1,*) istop,' obcini : E R R O R (S) detected : stop'
-               CALL ctl_stop( ctmp1 )
-            ENDIF
-         ENDIF
-      ENDIF
-
-      ! control of the north boundary
-      IF( lp_obc_north ) THEN
-         istop = 0
-         IF( jpjnob < 4 .OR.  jpjnob >= jpjglo ) THEN
-            IF(lwp) WRITE(numout,cform_err)
-            IF(lwp) WRITE(numout,*) '          jpjnob exceed ', jpjm1,' or less than 4'
-            istop = istop + 1
-         END IF
-
-         IF( lk_mpp ) THEN
-            IF( njmpp > jpjnob-5) THEN
-               IF(lwp) WRITE(numout,cform_err)
-               IF(lwp) WRITE(numout,*) '        A sub-domain is too close to the North OBC'
-               IF(lwp) WRITE(numout,*) '        njmpp must be < jpjnob-5'
-               istop = istop + 1
-            ENDIF
-         ELSE
-   
-            ! ... stop if  e r r o r (s)   detected
-            IF( istop /= 0 ) THEN
-                WRITE(ctmp1,*) istop,' obcini : E R R O R (S) detected : stop'
-               CALL ctl_stop( ctmp1 )
-           ENDIF
-         ENDIF
-      ENDIF
-
-      ! control of the south boundary
-      IF( lp_obc_south ) THEN
-         istop = 0
-         IF( jpjsob < 2 .OR. jpjsob >= jpjglo ) THEN
-            IF(lwp) WRITE(numout,cform_err)
-            IF(lwp) WRITE(numout,*) '          jpjsob exceed ', jpjm1,' or less than 2'
-            istop = istop + 1
-         END IF
-
-         IF( lk_mpp ) THEN
-            IF( (njmpp < jpjsob+5) .AND. (njmpp > 1) ) THEN
-               IF(lwp) WRITE(numout,cform_err)
-               IF(lwp) WRITE(numout,*) '        A sub-domain is too close to the South OBC'
-               IF(lwp) WRITE(numout,*) '        njmpp must be > jpjsob+5 or =1'
-               istop = istop + 1
-            ENDIF
-         ELSE
-   
-            ! ... stop if  e r r o r (s)   detected
-            IF( istop /= 0 ) THEN
-               WRITE(ctmp1,*) istop,' obcini : E R R O R (S) detected : stop'
-               CALL ctl_stop( ctmp1 )
-            ENDIF
-         ENDIF
-      ENDIF
+         IF( icount /= 0 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' E R R O R : Some data velocity points,',   &
+               ' are not boundary points. Check nbi, nbj, indices for boundary set ',ib_obc
+            IF(lwp) WRITE(numout,*) ' ========== '
+            IF(lwp) WRITE(numout,*)
+            nstop = nstop + 1
+         ENDIF 
+    
+      ENDDO
+
+      ! Compute total lateral surface for volume correction:
+      ! ----------------------------------------------------
+      obcsurftot = 0.e0 
+      IF( ln_vol ) THEN  
+         igrd = 2      ! Lateral surface at U-points
+         DO ib_obc = 1, nb_obc
+            DO ib = 1, idx_obc(ib_obc)%nblenrim(igrd)
+               nbi => idx_obc(ib_obc)%nbi(ib,igrd)
+               nbj => idx_obc(ib_obc)%nbi(ib,igrd)
+               flagu => idx_obc(ib_obc)%flagu(ib)
+               obcsurftot = obcsurftot + hu     (nbi  , nbj)                           &
+                  &                    * e2u    (nbi  , nbj) * ABS( flagu ) &
+                  &                    * tmask_i(nbi  , nbj)                           &
+                  &                    * tmask_i(nbi+1, nbj)                   
+            ENDDO
+         ENDDO
+
+         igrd=3 ! Add lateral surface at V-points
+         DO ib_obc = 1, nb_obc
+            DO ib = 1, idx_obc(ib_obc)%nblenrim(igrd)
+               nbi => idx_obc(ib_obc)%nbi(ib,igrd)
+               nbj => idx_obc(ib_obc)%nbi(ib,igrd)
+               flagv => idx_obc(ib_obc)%flagv(ib)
+               obcsurftot = obcsurftot + hv     (nbi, nbj  )                           &
+                  &                    * e1v    (nbi, nbj  ) * ABS( flagv ) &
+                  &                    * tmask_i(nbi, nbj  )                           &
+                  &                    * tmask_i(nbi, nbj+1)
+            ENDDO
+         ENDDO
+         !
+         IF( lk_mpp )   CALL mpp_sum( obcsurftot )      ! sum over the global domain
+      END IF   
+
+      ! Read in tidal constituents and adjust for model start time
+      ! ----------------------------------------------------------
+!!$      IF( ln_tides )   CALL tide_data
+      !
+      ! Tidy up
+      !--------
+      DEALLOCATE(nbidta, nbjdta, nbrdta)
 
    END SUBROUTINE obc_init
@@ -714,5 +550,5 @@
 #else
    !!---------------------------------------------------------------------------------
-   !!   Dummy module                                                NO open boundaries
+   !!   Dummy module                                   NO unstructured open boundaries
    !!---------------------------------------------------------------------------------
 CONTAINS
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcrad.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcrad.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcrad.F90	(revision 2797)
@@ -5,1157 +5,1157 @@
    !!=================================================================================
 #if defined key_obc
-   !!---------------------------------------------------------------------------------
-   !!   obc_rad        : call the subroutine for each open boundary
-   !!   obc_rad_east   : compute the east phase velocities
-   !!   obc_rad_west   : compute the west phase velocities
-   !!   obc_rad_north  : compute the north phase velocities
-   !!   obc_rad_south  : compute the south phase velocities
-   !!---------------------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE phycst          ! physical constants
-   USE obc_oce         ! ocean open boundary conditions
-   USE lib_mpp         ! for mppobc
-   USE in_out_manager  ! I/O units
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   obc_rad    ! routine called by step.F90
-
-   INTEGER ::   ji, jj, jk     ! dummy loop indices
-
-   INTEGER ::      & ! ... boundary space indices 
-      nib   = 1,   & ! nib   = boundary point
-      nibm  = 2,   & ! nibm  = 1st interior point
-      nibm2 = 3,   & ! nibm2 = 2nd interior point
-                     ! ... boundary time indices 
-      nit   = 1,   & ! nit    = now
-      nitm  = 2,   & ! nitm   = before
-      nitm2 = 3      ! nitm2  = before-before
-
-   !! * Substitutions
-#  include "obc_vectopt_loop_substitute.h90"
-   !!---------------------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!---------------------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE obc_rad ( kt )
-      !!------------------------------------------------------------------------------
-      !!                     SUBROUTINE obc_rad
-      !!                    ********************
-      !! ** Purpose :
-      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
-      !!      boundaries and calculate those phase speeds if the open boundaries are 
-      !!      not fixed. In case of fixed open boundaries does nothing.
-      !!
-      !!     The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north,
-      !!     and/or lp_obc_south allow the user to determine which boundary is an
-      !!     open one (must be done in the param_obc.h90 file).
-      !! 
-      !! ** Reference : 
-      !!     Marchesiello P., 1995, these de l'universite J. Fourier, Grenoble, France.
-      !!
-      !!  History :
-      !!    8.5  !  02-10  (C. Talandier, A-M. Treguier) Free surface, F90 from the 
-      !!                                                 J. Molines and G. Madec version
-      !!------------------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt
-      !!----------------------------------------------------------------------
-
-      IF( lp_obc_east  .AND. .NOT.lfbceast  )   CALL obc_rad_east ( kt )   ! East open boundary
-
-      IF( lp_obc_west  .AND. .NOT.lfbcwest  )   CALL obc_rad_west ( kt )   ! West open boundary
-
-      IF( lp_obc_north .AND. .NOT.lfbcnorth )   CALL obc_rad_north( kt )   ! North open boundary
-
-      IF( lp_obc_south .AND. .NOT.lfbcsouth )   CALL obc_rad_south( kt )   ! South open boundary
-
-   END SUBROUTINE obc_rad
-
-
-   SUBROUTINE obc_rad_east ( kt )
-      !!------------------------------------------------------------------------------
-      !!                     ***  SUBROUTINE obc_rad_east  ***
-      !!                   
-      !! ** Purpose :
-      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
-      !!      east boundary and calculate those phase speeds if this OBC is not fixed.
-      !!      In case of fixed OBC, this subrountine is not called.
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declarations
-      INTEGER  ::   ij
-      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
-      REAL(wp) ::   zucb, zucbm, zucbm2
-      !!------------------------------------------------------------------------------
-
-      ! 1. Swap arrays before calculating radiative velocities
-      ! ------------------------------------------------------
-
-      ! 1.1  zonal velocity 
-      ! -------------------
-
-      IF( kt > nit000 .OR. ln_rstart ) THEN 
-
-         ! ... advance in time (time filter, array swap) 
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               uebnd(jj,jk,nib  ,nitm2) = uebnd(jj,jk,nib  ,nitm)*uemsk(jj,jk)
-               uebnd(jj,jk,nibm ,nitm2) = uebnd(jj,jk,nibm ,nitm)*uemsk(jj,jk)
-               uebnd(jj,jk,nibm2,nitm2) = uebnd(jj,jk,nibm2,nitm)*uemsk(jj,jk)
-            END DO
-         END DO
-         ! ... fields nitm <== nit  plus time filter at the boundary 
-         DO ji = fs_nie0, fs_nie1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  uebnd(jj,jk,nib  ,nitm) = uebnd(jj,jk,nib,  nit)*uemsk(jj,jk)
-                  uebnd(jj,jk,nibm ,nitm) = uebnd(jj,jk,nibm ,nit)*uemsk(jj,jk)
-                  uebnd(jj,jk,nibm2,nitm) = uebnd(jj,jk,nibm2,nit)*uemsk(jj,jk)
-         ! ... fields nit <== now (kt+1) 
-         ! ... Total or baroclinic velocity at b, bm and bm2
-                  zucb   = un(ji,jj,jk)
-                  zucbm  = un(ji-1,jj,jk)
-                  zucbm2 = un(ji-2,jj,jk)
-                  uebnd(jj,jk,nib  ,nit) = zucb   *uemsk(jj,jk)
-                  uebnd(jj,jk,nibm ,nit) = zucbm  *uemsk(jj,jk) 
-                  uebnd(jj,jk,nibm2,nit) = zucbm2 *uemsk(jj,jk) 
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(uebnd,jpjed,jpjef,jpieob,jpk*3*3,2,jpj, numout )
-
-         ! ... extremeties nie0, nie1
-         ij = jpjed +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               uebnd(ij,jk,nibm,nitm) = uebnd(ij+1 ,jk,nibm,nitm)
-            END DO
-         END IF
-         ij = jpjef +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               uebnd(ij,jk,nibm,nitm) = uebnd(ij-1 ,jk,nibm,nitm)
-            END DO
-         END IF
-
-         ! 1.2 tangential velocity
-         ! -----------------------
-
-         ! ... advance in time (time filter, array swap)
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-         ! ... fields nitm2 <== nitm
-               vebnd(jj,jk,nib  ,nitm2) = vebnd(jj,jk,nib  ,nitm)*vemsk(jj,jk)
-               vebnd(jj,jk,nibm ,nitm2) = vebnd(jj,jk,nibm ,nitm)*vemsk(jj,jk)
-               vebnd(jj,jk,nibm2,nitm2) = vebnd(jj,jk,nibm2,nitm)*vemsk(jj,jk)
-            END DO
-         END DO
-
-         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  vebnd(jj,jk,nib  ,nitm) = vebnd(jj,jk,nib,  nit)*vemsk(jj,jk)
-                  vebnd(jj,jk,nibm ,nitm) = vebnd(jj,jk,nibm ,nit)*vemsk(jj,jk)
-                  vebnd(jj,jk,nibm2,nitm) = vebnd(jj,jk,nibm2,nit)*vemsk(jj,jk)
-         ! ... fields nit <== now (kt+1)
-                  vebnd(jj,jk,nib  ,nit) = vn(ji  ,jj,jk)*vemsk(jj,jk)
-                  vebnd(jj,jk,nibm ,nit) = vn(ji-1,jj,jk)*vemsk(jj,jk)
-                  vebnd(jj,jk,nibm2,nit) = vn(ji-2,jj,jk)*vemsk(jj,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(vebnd,jpjed,jpjef,jpieob+1,jpk*3*3,2,jpj, numout )
-
-         !... extremeties nie0, nie1
-         ij = jpjed +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               vebnd(ij,jk,nibm,nitm) = vebnd(ij+1 ,jk,nibm,nitm)
-            END DO 
-         END IF 
-         ij = jpjef +1 - njmpp 
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN 
-            DO jk = 1,jpkm1 
-               vebnd(ij,jk,nibm,nitm) = vebnd(ij-1 ,jk,nibm,nitm)
-            END DO 
-         END IF 
-
-         ! 1.3 Temperature and salinity
-         ! ----------------------------
-
-         ! ... advance in time (time filter, array swap)
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-         ! ... fields nitm <== nit  plus time filter at the boundary
-               tebnd(jj,jk,nib,nitm) = tebnd(jj,jk,nib,nit)*temsk(jj,jk)
-               sebnd(jj,jk,nib,nitm) = sebnd(jj,jk,nib,nit)*temsk(jj,jk)
-            END DO
-         END DO
-
-         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  tebnd(jj,jk,nibm,nitm) = tebnd(jj,jk,nibm,nit)*temsk(jj,jk)
-                  sebnd(jj,jk,nibm,nitm) = sebnd(jj,jk,nibm,nit)*temsk(jj,jk)
-         ! ... fields nit <== now (kt+1)
-                  tebnd(jj,jk,nib  ,nit) = tn(ji  ,jj,jk)*temsk(jj,jk)
-                  tebnd(jj,jk,nibm ,nit) = tn(ji-1,jj,jk)*temsk(jj,jk)
-                  sebnd(jj,jk,nib  ,nit) = sn(ji  ,jj,jk)*temsk(jj,jk)
-                  sebnd(jj,jk,nibm ,nit) = sn(ji-1,jj,jk)*temsk(jj,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(tebnd,jpjed,jpjef,jpieob+1,jpk*2*2,2,jpj, numout )
-         IF( lk_mpp )   CALL mppobc(sebnd,jpjed,jpjef,jpieob+1,jpk*2*2,2,jpj, numout )
-
-         ! ... extremeties nie0, nie1
-         ij = jpjed +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               tebnd(ij,jk,nibm,nitm) = tebnd(ij+1 ,jk,nibm,nitm)
-               sebnd(ij,jk,nibm,nitm) = sebnd(ij+1 ,jk,nibm,nitm)
-            END DO
-         END IF
-         ij = jpjef +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               tebnd(ij,jk,nibm,nitm) = tebnd(ij-1 ,jk,nibm,nitm)
-               sebnd(ij,jk,nibm,nitm) = sebnd(ij-1 ,jk,nibm,nitm)
-            END DO
-         END IF
-
-      END IF     ! End of array swap
-
-      ! 2 - Calculation of radiation velocities
-      ! ---------------------------------------
-
-      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
-
-         ! 2.1  Calculate the normal velocity U based on phase velocity u_cxebnd
-         ! ---------------------------------------------------------------------
-         !
-         !          nibm2      nibm      nib
-         !            |  nibm   |   nib   |///
-         !            |    |    |    |    |///
-         !  jj-line --f----v----f----v----f---
-         !            |    |    |    |    |///
-         !            |         |         |///
-         !  jj-line   u    T    u    T    u///
-         !            |         |         |///
-         !            |    |    |    |    |///
-         !          jpieob-2   jpieob-1   jpieob
-         !                 |         |        
-         !              jpieob-1    jpieob      
-         !
-         ! ... (jpjedp1, jpjefm1),jpieob
-         DO ji = fs_nie0, fs_nie1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 2, jpjm1
-         ! ... 2* gradi(u) (T-point i=nibm, time mean)
-                  z2dx = ( uebnd(jj,jk,nibm ,nit) + uebnd(jj,jk,nibm ,nitm2) &
-                           - 2.*uebnd(jj,jk,nibm2,nitm) ) / e1t(ji-1,jj)
-         ! ... 2* gradj(u) (u-point i=nibm, time nitm)
-                  z2dy = ( uebnd(jj+1,jk,nibm,nitm) - uebnd(jj-1,jk,nibm,nitm) ) / e2u(ji-1,jj)
-         ! ... square of the norm of grad(u)
-                  z4nor2 = z2dx * z2dx + z2dy * z2dy
-         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
-                  zdt = uebnd(jj,jk,nibm,nitm2) - uebnd(jj,jk,nibm,nit)
-         ! ... i-phase speed ratio (bounded by 1)               
-                  IF( z4nor2 == 0. ) THEN
-                     z4nor2=.00001
-                  END IF
-                  z05cx = zdt * z2dx / z4nor2
-                  u_cxebnd(jj,jk) = z05cx*uemsk(jj,jk)
-               END DO
-            END DO
-         END DO
-
-         ! 2.2  Calculate the tangential velocity based on phase velocity v_cxebnd
-         ! -----------------------------------------------------------------------
-         !
-         !          nibm2      nibm      nib
-         !            |   nibm  |   nib///|///
-         !            |    |    |    |////|///
-         !  jj-line --v----f----v----f----v---
-         !            |    |    |    |////|///
-         !            |    |    |    |////|///
-         !            | jpieob-1| jpieob /|///
-         !            |         |         |   
-         !         jpieob-1    jpieob     jpieob+1
-         !
-         ! ... (jpjedp1, jpjefm1), jpieob+1
-         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 2, jpjm1
-         ! ... 2* i-gradient of v (f-point i=nibm, time mean)
-                  z2dx = ( vebnd(jj,jk,nibm ,nit) + vebnd(jj,jk,nibm ,nitm2) &
-                          - 2.*vebnd(jj,jk,nibm2,nitm) ) / e1f(ji-2,jj)
-         ! ... 2* j-gradient of v (v-point i=nibm, time nitm)
-                  z2dy = ( vebnd(jj+1,jk,nibm,nitm) -  vebnd(jj-1,jk,nibm,nitm) ) / e2v(ji-1,jj)
-         ! ... square of the norm of grad(v)
-                  z4nor2 = z2dx * z2dx + z2dy * z2dy
-         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
-                  zdt = vebnd(jj,jk,nibm,nitm2) - vebnd(jj,jk,nibm,nit)
-         ! ... i-phase speed ratio (bounded by 1) and save the unbounded phase
-         !     velocity ratio no divided by e1f for the tracer radiation
-                  IF( z4nor2 == 0. ) THEN
-                     z4nor2=.000001
-                  END IF
-                  z05cx = zdt * z2dx / z4nor2
-                  v_cxebnd(jj,jk) = z05cx*vemsk(jj,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(v_cxebnd,jpjed,jpjef,jpieob+1,jpk,2,jpj, numout )
-
-         ! ... extremeties nie0, nie1
-         ij = jpjed +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               v_cxebnd(ij,jk) = v_cxebnd(ij+1 ,jk)
-            END DO
-         END IF
-         ij = jpjef +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               v_cxebnd(ij,jk) = v_cxebnd(ij-1 ,jk)
-            END DO
-         END IF
-
-      END IF
-
-   END SUBROUTINE obc_rad_east
-
-
-   SUBROUTINE obc_rad_west ( kt )
-      !!------------------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_rad_west  ***
-      !!                    
-      !! ** Purpose :
-      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
-      !!      west boundary and calculate those phase speeds if this OBC is not fixed.
-      !!      In case of fixed OBC, this subrountine is not called.
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declarations
-      INTEGER ::   ij
-      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
-      REAL(wp) ::   zucb, zucbm, zucbm2
-      !!------------------------------------------------------------------------------
-
-      ! 1. Swap arrays before calculating radiative velocities
-      ! ------------------------------------------------------
-
-      ! 1.1  zonal velocity 
-      ! -------------------
-
-      IF( kt > nit000 .OR. ln_rstart ) THEN
-
-         ! ... advance in time (time filter, array swap) 
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj 
-               uwbnd(jj,jk,nib  ,nitm2) = uwbnd(jj,jk,nib  ,nitm)*uwmsk(jj,jk)
-               uwbnd(jj,jk,nibm ,nitm2) = uwbnd(jj,jk,nibm ,nitm)*uwmsk(jj,jk)
-               uwbnd(jj,jk,nibm2,nitm2) = uwbnd(jj,jk,nibm2,nitm)*uwmsk(jj,jk)
-            END DO
-         END DO
-
-         ! ... fields nitm <== nit  plus time filter at the boundary 
-         DO ji = fs_niw0, fs_niw1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  uwbnd(jj,jk,nib  ,nitm) = uwbnd(jj,jk,nib  ,nit)*uwmsk(jj,jk)
-                  uwbnd(jj,jk,nibm ,nitm) = uwbnd(jj,jk,nibm ,nit)*uwmsk(jj,jk)
-                  uwbnd(jj,jk,nibm2,nitm) = uwbnd(jj,jk,nibm2,nit)*uwmsk(jj,jk)
-         ! ... total or baroclinic velocity at b, bm and bm2
-                  zucb   = un (ji,jj,jk)
-                  zucbm  = un (ji+1,jj,jk)
-                  zucbm2 = un (ji+2,jj,jk)
-
-         ! ... fields nit <== now (kt+1) 
-                  uwbnd(jj,jk,nib  ,nit) = zucb  *uwmsk(jj,jk)
-                  uwbnd(jj,jk,nibm ,nit) = zucbm *uwmsk(jj,jk)
-                  uwbnd(jj,jk,nibm2,nit) = zucbm2*uwmsk(jj,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(uwbnd,jpjwd,jpjwf,jpiwob,jpk*3*3,2,jpj, numout )
-
-         ! ... extremeties niw0, niw1
-         ij = jpjwd +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               uwbnd(ij,jk,nibm,nitm) = uwbnd(ij+1 ,jk,nibm,nitm)
-            END DO
-         END IF
-         ij = jpjwf +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               uwbnd(ij,jk,nibm,nitm) = uwbnd(ij-1 ,jk,nibm,nitm)
-            END DO
-         END IF
-
-         ! 1.2 tangential velocity
-         ! -----------------------
-
-         ! ... advance in time (time filter, array swap)
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj 
-         ! ... fields nitm2 <== nitm
-                  vwbnd(jj,jk,nib  ,nitm2) = vwbnd(jj,jk,nib  ,nitm)*vwmsk(jj,jk)
-                  vwbnd(jj,jk,nibm ,nitm2) = vwbnd(jj,jk,nibm ,nitm)*vwmsk(jj,jk)
-                  vwbnd(jj,jk,nibm2,nitm2) = vwbnd(jj,jk,nibm2,nitm)*vwmsk(jj,jk)
-            END DO
-         END DO
-
-         DO ji = fs_niw0, fs_niw1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  vwbnd(jj,jk,nib  ,nitm) = vwbnd(jj,jk,nib,  nit)*vwmsk(jj,jk)
-                  vwbnd(jj,jk,nibm ,nitm) = vwbnd(jj,jk,nibm ,nit)*vwmsk(jj,jk)
-                  vwbnd(jj,jk,nibm2,nitm) = vwbnd(jj,jk,nibm2,nit)*vwmsk(jj,jk)
-         ! ... fields nit <== now (kt+1)
-                  vwbnd(jj,jk,nib  ,nit) = vn(ji  ,jj,jk)*vwmsk(jj,jk)
-                  vwbnd(jj,jk,nibm ,nit) = vn(ji+1,jj,jk)*vwmsk(jj,jk)
-                  vwbnd(jj,jk,nibm2,nit) = vn(ji+2,jj,jk)*vwmsk(jj,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(vwbnd,jpjwd,jpjwf,jpiwob,jpk*3*3,2,jpj, numout )
-
-         ! ... extremeties niw0, niw1 
-         ij = jpjwd +1 - njmpp 
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN 
-            DO jk = 1,jpkm1 
-               vwbnd(ij,jk,nibm,nitm) = vwbnd(ij+1 ,jk,nibm,nitm)
-            END DO 
-         END IF
-         ij = jpjwf +1 - njmpp 
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN 
-            DO jk = 1,jpkm1 
-               vwbnd(ij,jk,nibm,nitm) = vwbnd(ij-1 ,jk,nibm,nitm)
-            END DO 
-         END IF 
- 
-         ! 1.3 Temperature and salinity
-         ! ----------------------------
- 
-         ! ... advance in time (time filter, array swap)
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-         ! ... fields nitm <== nit  plus time filter at the boundary
-               twbnd(jj,jk,nib,nitm) = twbnd(jj,jk,nib,nit)*twmsk(jj,jk)
-               swbnd(jj,jk,nib,nitm) = swbnd(jj,jk,nib,nit)*twmsk(jj,jk)
-            END DO
-         END DO
- 
-         DO ji = fs_niw0, fs_niw1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  twbnd(jj,jk,nibm ,nitm) = twbnd(jj,jk,nibm ,nit)*twmsk(jj,jk)
-                  swbnd(jj,jk,nibm ,nitm) = swbnd(jj,jk,nibm ,nit)*twmsk(jj,jk)
-         ! ... fields nit <== now (kt+1)
-                  twbnd(jj,jk,nib  ,nit) = tn(ji   ,jj,jk)*twmsk(jj,jk)
-                  twbnd(jj,jk,nibm ,nit) = tn(ji+1 ,jj,jk)*twmsk(jj,jk)
-                  swbnd(jj,jk,nib  ,nit) = sn(ji   ,jj,jk)*twmsk(jj,jk)
-                  swbnd(jj,jk,nibm ,nit) = sn(ji+1 ,jj,jk)*twmsk(jj,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(twbnd,jpjwd,jpjwf,jpiwob,jpk*2*2,2,jpj, numout )
-         IF( lk_mpp )   CALL mppobc(swbnd,jpjwd,jpjwf,jpiwob,jpk*2*2,2,jpj, numout )
-
-         ! ... extremeties niw0, niw1
-         ij = jpjwd +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               twbnd(ij,jk,nibm,nitm) = twbnd(ij+1 ,jk,nibm,nitm)
-               swbnd(ij,jk,nibm,nitm) = swbnd(ij+1 ,jk,nibm,nitm)
-            END DO
-         END IF
-         ij = jpjwf +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               twbnd(ij,jk,nibm,nitm) = twbnd(ij-1 ,jk,nibm,nitm)
-               swbnd(ij,jk,nibm,nitm) = swbnd(ij-1 ,jk,nibm,nitm)
-            END DO
-         END IF
- 
-      END IF     ! End of array swap
-
-      ! 2 - Calculation of radiation velocities
-      ! ---------------------------------------
-   
-      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
-  
-         ! 2.1  Calculate the normal velocity U based on phase velocity u_cxwbnd
-         ! ----------------------------------------------------------------------
-         !
-         !          nib       nibm      nibm2
-         !        ///|   nib   |   nibm  |
-         !        ///|    |    |    |    |
-         !        ---f----v----f----v----f-- jj-line
-         !        ///|    |    |    |    |
-         !        ///|         |         |
-         !        ///u    T    u    T    u   jj-line
-         !        ///|         |         |
-         !        ///|    |    |    |    |
-         !         jpiwob    jpiwob+1    jpiwob+2
-         !                |         |        
-         !              jpiwob+1    jpiwob+2     
-         !
-         ! ... If free surface formulation:
-         ! ... radiative conditions on the total part + relaxation toward climatology
-         ! ... (jpjwdp1, jpjwfm1), jpiwob
-         DO ji = fs_niw0, fs_niw1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 2, jpjm1
-         ! ... 2* gradi(u) (T-point i=nibm, time mean)
-                  z2dx = ( - uwbnd(jj,jk,nibm ,nit) -  uwbnd(jj,jk,nibm ,nitm2) &
-                           + 2.*uwbnd(jj,jk,nibm2,nitm) ) / e1t(ji+2,jj)
-         ! ... 2* gradj(u) (u-point i=nibm, time nitm)
-                  z2dy = ( uwbnd(jj+1,jk,nibm,nitm) - uwbnd(jj-1,jk,nibm,nitm) ) / e2u(ji+1,jj)
-         ! ... square of the norm of grad(u)
-                  z4nor2 = z2dx * z2dx + z2dy * z2dy
-         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
-                  zdt = uwbnd(jj,jk,nibm,nitm2) - uwbnd(jj,jk,nibm,nit)
-         ! ... i-phase speed ratio (bounded by -1)
-                  IF( z4nor2 == 0. ) THEN
-                     z4nor2=0.00001
-                  END IF
-                  z05cx = zdt * z2dx / z4nor2
-                  u_cxwbnd(jj,jk)=z05cx*uwmsk(jj,jk)
-               END DO
-            END DO
-         END DO
-
-         ! 2.2  Calculate the tangential velocity based on phase velocity v_cxwbnd
-         ! -----------------------------------------------------------------------
-         !
-         !      nib       nibm     nibm2
-         !    ///|///nib   |   nibm  |  nibm2
-         !    ///|////|    |    |    |    |    |
-         !    ---v----f----v----f----v----f----v-- jj-line
-         !    ///|////|    |    |    |    |    |
-         !    ///|////|    |    |    |    |    |
-         !   jpiwob     jpiwob+1    jpiwob+2
-         !            |         |         |   
-         !          jpiwob   jpiwob+1   jpiwob+2    
-         !
-         ! ... radiative condition plus Raymond-Kuo
-         ! ... (jpjwdp1, jpjwfm1),jpiwob
-         DO ji = fs_niw0, fs_niw1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 2, jpjm1
-         ! ... 2* i-gradient of v (f-point i=nibm, time mean)
-                  z2dx = ( - vwbnd(jj,jk,nibm ,nit) - vwbnd(jj,jk,nibm ,nitm2) &
-                           + 2.*vwbnd(jj,jk,nibm2,nitm) ) / e1f(ji+1,jj)
-         ! ... 2* j-gradient of v (v-point i=nibm, time nitm)
-                  z2dy = ( vwbnd(jj+1,jk,nibm,nitm) - vwbnd(jj-1,jk,nibm,nitm) ) / e2v(ji+1,jj)
-         ! ... square of the norm of grad(v)
-                  z4nor2 = z2dx * z2dx + z2dy * z2dy
-         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
-                  zdt = vwbnd(jj,jk,nibm,nitm2) - vwbnd(jj,jk,nibm,nit)
-         ! ... i-phase speed ratio (bounded by -1) and save the unbounded phase
-         !     velocity ratio no divided by e1f for the tracer radiation
-                  IF( z4nor2 == 0) THEN
-                     z4nor2=0.000001
-                  endif
-                  z05cx = zdt * z2dx / z4nor2
-                  v_cxwbnd(jj,jk) = z05cx*vwmsk(jj,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(v_cxwbnd,jpjwd,jpjwf,jpiwob,jpk,2,jpj, numout )
-
-         ! ... extremeties niw0, niw1
-         ij = jpjwd +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               v_cxwbnd(ij,jk) = v_cxwbnd(ij+1 ,jk)
-            END DO
-         END IF
-         ij = jpjwf +1 - njmpp
-         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
-            DO jk = 1,jpkm1
-               v_cxwbnd(ij,jk) = v_cxwbnd(ij-1 ,jk)
-            END DO
-         END IF
-
-      END IF
-
-   END SUBROUTINE obc_rad_west
-
-
-   SUBROUTINE obc_rad_north ( kt )
-      !!------------------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_rad_north  ***
-      !!           
-      !! ** Purpose :
-      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
-      !!      north boundary and calculate those phase speeds if this OBC is not fixed.
-      !!      In case of fixed OBC, this subrountine is not called.
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declarations
-      INTEGER  ::   ii
-      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
-      REAL(wp) ::   zvcb, zvcbm, zvcbm2
-      !!------------------------------------------------------------------------------
-
-      ! 1. Swap arrays before calculating radiative velocities
-      ! ------------------------------------------------------
-
-      ! 1.1  zonal velocity 
-      ! -------------------
-
-      IF( kt > nit000 .OR. ln_rstart ) THEN 
-
-         ! ... advance in time (time filter, array swap)
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-         ! ... fields nitm2 <== nitm
-               unbnd(ji,jk,nib  ,nitm2) = unbnd(ji,jk,nib  ,nitm)*unmsk(ji,jk)
-               unbnd(ji,jk,nibm ,nitm2) = unbnd(ji,jk,nibm ,nitm)*unmsk(ji,jk)
-               unbnd(ji,jk,nibm2,nitm2) = unbnd(ji,jk,nibm2,nitm)*unmsk(ji,jk)
-            END DO
-         END DO
-
-         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  unbnd(ji,jk,nib  ,nitm) = unbnd(ji,jk,nib,  nit)*unmsk(ji,jk)
-                  unbnd(ji,jk,nibm ,nitm) = unbnd(ji,jk,nibm ,nit)*unmsk(ji,jk)
-                  unbnd(ji,jk,nibm2,nitm) = unbnd(ji,jk,nibm2,nit)*unmsk(ji,jk)
-         ! ... fields nit <== now (kt+1)
-                  unbnd(ji,jk,nib  ,nit) = un(ji,jj,  jk)*unmsk(ji,jk)
-                  unbnd(ji,jk,nibm ,nit) = un(ji,jj-1,jk)*unmsk(ji,jk)
-                  unbnd(ji,jk,nibm2,nit) = un(ji,jj-2,jk)*unmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(unbnd,jpind,jpinf,jpjnob+1,jpk*3*3,1,jpi, numout )
-
-         ! ... extremeties njn0,njn1 
-         ii = jpind + 1 - nimpp 
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN 
-            DO jk = 1, jpkm1
-                unbnd(ii,jk,nibm,nitm) = unbnd(ii+1,jk,nibm,nitm)
-            END DO
-         END IF 
-         ii = jpinf + 1 - nimpp 
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               unbnd(ii,jk,nibm,nitm) = unbnd(ii-1,jk,nibm,nitm)
-            END DO
-         END IF
- 
-         ! 1.2. normal velocity 
-         ! --------------------
-
-         ! ... advance in time (time filter, array swap) 
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-         ! ... fields nitm2 <== nitm 
-               vnbnd(ji,jk,nib  ,nitm2) = vnbnd(ji,jk,nib  ,nitm)*vnmsk(ji,jk)
-               vnbnd(ji,jk,nibm ,nitm2) = vnbnd(ji,jk,nibm ,nitm)*vnmsk(ji,jk)
-               vnbnd(ji,jk,nibm2,nitm2) = vnbnd(ji,jk,nibm2,nitm)*vnmsk(ji,jk)
-            END DO
-         END DO
-
-         DO jj = fs_njn0, fs_njn1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  vnbnd(ji,jk,nib  ,nitm) = vnbnd(ji,jk,nib,  nit)*vnmsk(ji,jk)
-                  vnbnd(ji,jk,nibm ,nitm) = vnbnd(ji,jk,nibm ,nit)*vnmsk(ji,jk)
-                  vnbnd(ji,jk,nibm2,nitm) = vnbnd(ji,jk,nibm2,nit)*vnmsk(ji,jk)
-         ! ... fields nit <== now (kt+1)
-         ! ... total or baroclinic velocity at b, bm and bm2
-                  zvcb   = vn (ji,jj,jk)
-                  zvcbm  = vn (ji,jj-1,jk)
-                  zvcbm2 = vn (ji,jj-2,jk)
-         ! ... fields nit <== now (kt+1) 
-                  vnbnd(ji,jk,nib  ,nit) = zvcb  *vnmsk(ji,jk)
-                  vnbnd(ji,jk,nibm ,nit) = zvcbm *vnmsk(ji,jk)
-                  vnbnd(ji,jk,nibm2,nit) = zvcbm2*vnmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(vnbnd,jpind,jpinf,jpjnob,jpk*3*3,1,jpi, numout )
-
-         ! ... extremeties njn0,njn1
-         ii = jpind + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               vnbnd(ii,jk,nibm,nitm) = vnbnd(ii+1,jk,nibm,nitm)
-            END DO
-         END IF
-         ii = jpinf + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               vnbnd(ii,jk,nibm,nitm) = vnbnd(ii-1,jk,nibm,nitm)
-            END DO
-         END IF
-
-         ! 1.3 Temperature and salinity
-         ! ----------------------------
-
-         ! ... advance in time (time filter, array swap)
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-         ! ... fields nitm <== nit  plus time filter at the boundary
-               tnbnd(ji,jk,nib ,nitm) = tnbnd(ji,jk,nib,nit)*tnmsk(ji,jk)
-               snbnd(ji,jk,nib ,nitm) = snbnd(ji,jk,nib,nit)*tnmsk(ji,jk)
-            END DO
-         END DO
-
-         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  tnbnd(ji,jk,nibm ,nitm) = tnbnd(ji,jk,nibm ,nit)*tnmsk(ji,jk)
-                  snbnd(ji,jk,nibm ,nitm) = snbnd(ji,jk,nibm ,nit)*tnmsk(ji,jk)
-         ! ... fields nit <== now (kt+1)
-                  tnbnd(ji,jk,nib  ,nit) = tn(ji,jj,  jk)*tnmsk(ji,jk)
-                  tnbnd(ji,jk,nibm ,nit) = tn(ji,jj-1,jk)*tnmsk(ji,jk)
-                  snbnd(ji,jk,nib  ,nit) = sn(ji,jj,  jk)*tnmsk(ji,jk)
-                  snbnd(ji,jk,nibm ,nit) = sn(ji,jj-1,jk)*tnmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(tnbnd,jpind,jpinf,jpjnob+1,jpk*2*2,1,jpi, numout )
-         IF( lk_mpp )   CALL mppobc(snbnd,jpind,jpinf,jpjnob+1,jpk*2*2,1,jpi, numout )
-
-         ! ... extremeties  njn0,njn1
-         ii = jpind + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               tnbnd(ii,jk,nibm,nitm) = tnbnd(ii+1,jk,nibm,nitm)
-               snbnd(ii,jk,nibm,nitm) = snbnd(ii+1,jk,nibm,nitm)
-            END DO
-         END IF
-         ii = jpinf + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               tnbnd(ii,jk,nibm,nitm) = tnbnd(ii-1,jk,nibm,nitm)
-               snbnd(ii,jk,nibm,nitm) = snbnd(ii-1,jk,nibm,nitm)
-            END DO
-         END IF
-
-      END IF     ! End of array swap
-
-      ! 2 - Calculation of radiation velocities
-      ! ---------------------------------------
-
-      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
-
-         ! 2.1  Calculate the normal velocity based on phase velocity u_cynbnd
-         ! -------------------------------------------------------------------
-         !
-         !           ji-row
-         !             |
-         !     nib -///u//////  jpjnob + 1
-         !        /////|//////
-         !   nib  -----f-----   jpjnob
-         !             |    
-         !     nibm--  u   ---- jpjnob
-         !             |        
-         !  nibm  -----f-----   jpjnob-1
-         !             |        
-         !    nibm2--  u   ---- jpjnob-1
-         !             |        
-         !  nibm2 -----f-----   jpjnob-2
-         !             |
-         ! ... radiative condition
-         ! ... jpjnob+1,(jpindp1, jpinfm1)
-         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 2, jpim1
-         ! ... 2* j-gradient of u (f-point i=nibm, time mean)
-                  z2dx = ( unbnd(ji,jk,nibm ,nit) + unbnd(ji,jk,nibm ,nitm2) &
-                        - 2.*unbnd(ji,jk,nibm2,nitm)) / e2f(ji,jj-2)
-         ! ... 2* i-gradient of u (u-point i=nibm, time nitm)
-                  z2dy = ( unbnd(ji+1,jk,nibm,nitm) - unbnd(ji-1,jk,nibm,nitm) ) / e1u(ji,jj-1)
-         ! ... square of the norm of grad(v)
-                  z4nor2 = z2dx * z2dx + z2dy * z2dy
-         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
-                  zdt = unbnd(ji,jk,nibm,nitm2) - unbnd(ji,jk,nibm,nit)
-         ! ... i-phase speed ratio (bounded by 1) and save the unbounded phase
-         !     velocity ratio no divided by e1f for the tracer radiation
-                  IF( z4nor2 == 0.) THEN
-                     z4nor2=.000001
-                  END IF
-                  z05cx = zdt * z2dx / z4nor2
-                  u_cynbnd(ji,jk) = z05cx *unmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(u_cynbnd,jpind,jpinf,jpjnob+1,jpk,1,jpi, numout )
-
-         ! ... extremeties  njn0,njn1
-         ii = jpind + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               u_cynbnd(ii,jk) = u_cynbnd(ii+1,jk)
-            END DO
-         END IF
-         ii = jpinf + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               u_cynbnd(ii,jk) = u_cynbnd(ii-1,jk)
-            END DO
-         END IF
-
-         ! 2.2 Calculate the normal velocity based on phase velocity v_cynbnd 
-         ! ------------------------------------------------------------------
-         !
-         !                ji-row  ji-row
-         !                     |
-         !        /////|/////////////////
-         !   nib  -----f----v----f----  jpjnob
-         !             |         |
-         !     nib  -  u -- T -- u ---- jpjnob
-         !             |         |
-         !  nibm  -----f----v----f----  jpjnob-1
-         !             |         |
-         !    nibm --  u -- T -- u ---  jpjnob-1
-         !             |         |
-         !  nibm2 -----f----v----f----  jpjnob-2
-         !             |         |
-         ! ... Free surface formulation:
-         ! ... radiative conditions on the total part + relaxation toward climatology 
-         ! ... jpjnob,(jpindp1, jpinfm1)
-         DO jj = fs_njn0, fs_njn1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 2, jpim1
-         ! ... 2* gradj(v) (T-point i=nibm, time mean)
-                  ii = ji -1 + nimpp
-                  z2dx = ( vnbnd(ji,jk,nibm ,nit) + vnbnd(ji,jk,nibm ,nitm2) &
-                          - 2.*vnbnd(ji,jk,nibm2,nitm)) / e2t(ji,jj-1)
-         ! ... 2* gradi(v) (v-point i=nibm, time nitm)
-                  z2dy = ( vnbnd(ji+1,jk,nibm,nitm) - vnbnd(ji-1,jk,nibm,nitm) ) / e1v(ji,jj-1)
-         ! ... square of the norm of grad(u)
-                  z4nor2 = z2dx * z2dx + z2dy * z2dy
-         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
-                  zdt = vnbnd(ji,jk,nibm,nitm2) - vnbnd(ji,jk,nibm,nit)
-         ! ... j-phase speed ratio (bounded by 1)
-                  IF( z4nor2 == 0. ) THEN
-                     z4nor2=.00001
-                  END IF
-                  z05cx = zdt * z2dx / z4nor2
-                  v_cynbnd(ji,jk)=z05cx *vnmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-
-      END IF
-
-   END SUBROUTINE obc_rad_north
-
-
-   SUBROUTINE obc_rad_south ( kt )
-      !!------------------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_rad_south  ***
-      !!           
-      !! ** Purpose :
-      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
-      !!      south boundary and calculate those phase speeds if this OBC is not fixed.
-      !!      In case of fixed OBC, this subrountine is not called.
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declarations
-      INTEGER ::   ii
-      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
-      REAL(wp) ::   zvcb, zvcbm, zvcbm2
-      !!------------------------------------------------------------------------------
-
-      ! 1. Swap arrays before calculating radiative velocities
-      ! ------------------------------------------------------
-
-      ! 1.1  zonal velocity 
-      ! --------------------
-  
-      IF( kt > nit000 .OR. ln_rstart ) THEN 
-
-         ! ... advance in time (time filter, array swap)
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-         ! ... fields nitm2 <== nitm
-                  usbnd(ji,jk,nib  ,nitm2) = usbnd(ji,jk,nib  ,nitm)*usmsk(ji,jk)
-                  usbnd(ji,jk,nibm ,nitm2) = usbnd(ji,jk,nibm ,nitm)*usmsk(ji,jk)
-                  usbnd(ji,jk,nibm2,nitm2) = usbnd(ji,jk,nibm2,nitm)*usmsk(ji,jk)
-            END DO
-         END DO
- 
-         DO jj = fs_njs0, fs_njs1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  usbnd(ji,jk,nib  ,nitm) = usbnd(ji,jk,nib,  nit)*usmsk(ji,jk)
-                  usbnd(ji,jk,nibm ,nitm) = usbnd(ji,jk,nibm ,nit)*usmsk(ji,jk)
-                  usbnd(ji,jk,nibm2,nitm) = usbnd(ji,jk,nibm2,nit)*usmsk(ji,jk)
-         ! ... fields nit <== now (kt+1)
-                  usbnd(ji,jk,nib  ,nit) = un(ji,jj  ,jk)*usmsk(ji,jk)
-                  usbnd(ji,jk,nibm ,nit) = un(ji,jj+1,jk)*usmsk(ji,jk)
-                  usbnd(ji,jk,nibm2,nit) = un(ji,jj+2,jk)*usmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(usbnd,jpisd,jpisf,jpjsob,jpk*3*3,1,jpi, numout )
-
-         ! ... extremeties njs0,njs1
-         ii = jpisd + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               usbnd(ii,jk,nibm,nitm) = usbnd(ii+1,jk,nibm,nitm)
-            END DO
-         END IF
-         ii = jpisf + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               usbnd(ii,jk,nibm,nitm) = usbnd(ii-1,jk,nibm,nitm)
-            END DO
-         END IF
- 
-         ! 1.2 normal velocity
-         ! -------------------
- 
-         !.. advance in time (time filter, array swap) 
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-         ! ... fields nitm2 <== nitm 
-               vsbnd(ji,jk,nib  ,nitm2) = vsbnd(ji,jk,nib  ,nitm)*vsmsk(ji,jk)
-               vsbnd(ji,jk,nibm ,nitm2) = vsbnd(ji,jk,nibm ,nitm)*vsmsk(ji,jk)
-            END DO
-         END DO
-
-         DO jj = fs_njs0, fs_njs1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  vsbnd(ji,jk,nib  ,nitm) = vsbnd(ji,jk,nib,  nit)*vsmsk(ji,jk)
-                  vsbnd(ji,jk,nibm ,nitm) = vsbnd(ji,jk,nibm ,nit)*vsmsk(ji,jk)
-                  vsbnd(ji,jk,nibm2,nitm) = vsbnd(ji,jk,nibm2,nit)*vsmsk(ji,jk)
-         ! ... total or baroclinic velocity at b, bm and bm2
-                  zvcb   = vn (ji,jj,jk)
-                  zvcbm  = vn (ji,jj+1,jk)
-                  zvcbm2 = vn (ji,jj+2,jk)
-         ! ... fields nit <== now (kt+1) 
-                  vsbnd(ji,jk,nib  ,nit) = zvcb   *vsmsk(ji,jk)
-                  vsbnd(ji,jk,nibm ,nit) = zvcbm  *vsmsk(ji,jk)
-                  vsbnd(ji,jk,nibm2,nit) = zvcbm2 *vsmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(vsbnd,jpisd,jpisf,jpjsob,jpk*3*3,1,jpi, numout )
-
-         ! ... extremeties njs0,njs1
-         ii = jpisd + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               vsbnd(ii,jk,nibm,nitm) = vsbnd(ii+1,jk,nibm,nitm)
-            END DO
-         END IF
-         ii = jpisf + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               vsbnd(ii,jk,nibm,nitm) = vsbnd(ii-1,jk,nibm,nitm)
-            END DO
-         END IF
-
-         ! 1.3 Temperature and salinity
-         ! ----------------------------
-
-         ! ... advance in time (time filter, array swap)
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-         ! ... fields nitm <== nit  plus time filter at the boundary
-               tsbnd(ji,jk,nib,nitm) = tsbnd(ji,jk,nib,nit)*tsmsk(ji,jk)
-               ssbnd(ji,jk,nib,nitm) = ssbnd(ji,jk,nib,nit)*tsmsk(ji,jk)
-            END DO
-         END DO
-
-         DO jj = fs_njs0, fs_njs1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  tsbnd(ji,jk,nibm ,nitm) = tsbnd(ji,jk,nibm ,nit)*tsmsk(ji,jk)
-                  ssbnd(ji,jk,nibm ,nitm) = ssbnd(ji,jk,nibm ,nit)*tsmsk(ji,jk)
-         ! ... fields nit <== now (kt+1)
-                  tsbnd(ji,jk,nib  ,nit) = tn(ji,jj   ,jk)*tsmsk(ji,jk)
-                  tsbnd(ji,jk,nibm ,nit) = tn(ji,jj+1 ,jk)*tsmsk(ji,jk)
-                  ssbnd(ji,jk,nib  ,nit) = sn(ji,jj   ,jk)*tsmsk(ji,jk)
-                  ssbnd(ji,jk,nibm ,nit) = sn(ji,jj+1 ,jk)*tsmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(tsbnd,jpisd,jpisf,jpjsob,jpk*2*2,1,jpi, numout )
-         IF( lk_mpp )   CALL mppobc(ssbnd,jpisd,jpisf,jpjsob,jpk*2*2,1,jpi, numout )
-
-         ! ... extremeties  njs0,njs1
-         ii = jpisd + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               tsbnd(ii,jk,nibm,nitm) = tsbnd(ii+1,jk,nibm,nitm)
-               ssbnd(ii,jk,nibm,nitm) = ssbnd(ii+1,jk,nibm,nitm)
-            END DO
-         END IF
-         ii = jpisf + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               tsbnd(ii,jk,nibm,nitm) = tsbnd(ii-1,jk,nibm,nitm)
-               ssbnd(ii,jk,nibm,nitm) = ssbnd(ii-1,jk,nibm,nitm)
-            END DO
-         END IF
-
-      END IF     ! End of array swap
-
-      ! 2 - Calculation of radiation velocities
-      ! ---------------------------------------
-
-      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
-
-         ! 2.1  Calculate the normal velocity based on phase velocity u_cysbnd
-         ! -------------------------------------------------------------------
-         !
-         !          ji-row
-         !            |
-         ! nibm2 -----f-----   jpjsob +2
-         !            |    
-         !  nibm2 --  u  ----- jpjsob +2 
-         !            |        
-         !  nibm -----f-----   jpjsob +1
-         !            |        
-         !  nibm  --  u  ----- jpjsob +1
-         !            |        
-         !  nib  -----f-----   jpjsob
-         !       /////|//////
-         !  nib   ////u/////   jpjsob 
-         !
-         ! ... radiative condition plus Raymond-Kuo
-         ! ... jpjsob,(jpisdp1, jpisfm1)
-         DO jj = fs_njs0, fs_njs1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 2, jpim1
-         ! ... 2* j-gradient of u (f-point i=nibm, time mean)
-                  z2dx = (- usbnd(ji,jk,nibm ,nit) - usbnd(ji,jk,nibm ,nitm2) &
-                          + 2.*usbnd(ji,jk,nibm2,nitm) ) / e2f(ji,jj+1)
-         ! ... 2* i-gradient of u (u-point i=nibm, time nitm)
-                  z2dy = ( usbnd(ji+1,jk,nibm,nitm) - usbnd(ji-1,jk,nibm,nitm) ) / e1u(ji, jj+1)
-         ! ... square of the norm of grad(v)
-                  z4nor2 = z2dx * z2dx + z2dy * z2dy
-                  IF( z4nor2 == 0.) THEN
-                     z4nor2 = 0.000001
-                  END IF
-         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
-                  zdt = usbnd(ji,jk,nibm,nitm2) - usbnd(ji,jk,nibm,nit)
-         ! ... i-phase speed ratio (bounded by -1) and save the unbounded phase
-         !     velocity ratio no divided by e1f for the tracer radiation
-                  z05cx = zdt * z2dx / z4nor2
-                  u_cysbnd(ji,jk) = z05cx*usmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mppobc(u_cysbnd,jpisd,jpisf,jpjsob,jpk,1,jpi, numout )
-
-         ! ... extremeties  njs0,njs1
-         ii = jpisd + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               u_cysbnd(ii,jk) = u_cysbnd(ii+1,jk)
-            END DO
-         END IF
-         ii = jpisf + 1 - nimpp
-         IF( ii >= 2 .AND. ii < jpim1 ) THEN
-            DO jk = 1, jpkm1
-               u_cysbnd(ii,jk) = u_cysbnd(ii-1,jk)
-            END DO
-         END IF
-
-         ! 2.2 Calculate the normal velocity based on phase velocity v_cysbnd 
-         ! -------------------------------------------------------------------
-         !
-         !               ji-row  ji-row
-         !            |         |
-         ! nibm2 -----f----v----f----  jpjsob+2
-         !            |         |
-         !  nibm   -  u -- T -- u ---- jpjsob+2
-         !            |         |
-         ! nibm  -----f----v----f----  jpjsob+1 
-         !            |         |
-         ! nib    --  u -- T -- u ---  jpjsob+1
-         !            |         |
-         ! nib   -----f----v----f----  jpjsob
-         !       /////////////////////
-         !
-         ! ... Free surface formulation:
-         ! ... radiative conditions on the total part + relaxation toward climatology
-         ! ... jpjsob,(jpisdp1,jpisfm1)
-         DO jj = fs_njs0, fs_njs1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 2, jpim1
-         ! ... 2* gradj(v) (T-point i=nibm, time mean)
-                  z2dx = ( - vsbnd(ji,jk,nibm ,nit) - vsbnd(ji,jk,nibm ,nitm2) &
-                           + 2.*vsbnd(ji,jk,nibm2,nitm) ) / e2t(ji,jj+1)
-         ! ... 2* gradi(v) (v-point i=nibm, time nitm)
-                  z2dy = ( vsbnd(ji+1,jk,nibm,nitm) - vsbnd(ji-1,jk,nibm,nitm) ) / e1v(ji,jj+1)
-         ! ... square of the norm of grad(u)
-                  z4nor2 = z2dx * z2dx + z2dy * z2dy
-                  IF( z4nor2 == 0.) THEN
-                     z4nor2 = 0.000001
-                  END IF
-         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
-                  zdt = vsbnd(ji,jk,nibm,nitm2) - vsbnd(ji,jk,nibm,nit)
-         ! ... j-phase speed ratio (bounded by -1)
-                  z05cx = zdt * z2dx / z4nor2
-                  v_cysbnd(ji,jk)=z05cx*vsmsk(ji,jk)
-               END DO
-            END DO
-         END DO
-
-      ENDIF
- 
-   END SUBROUTINE obc_rad_south
-
-#else
+!!$   !!---------------------------------------------------------------------------------
+!!$   !!   obc_rad        : call the subroutine for each open boundary
+!!$   !!   obc_rad_east   : compute the east phase velocities
+!!$   !!   obc_rad_west   : compute the west phase velocities
+!!$   !!   obc_rad_north  : compute the north phase velocities
+!!$   !!   obc_rad_south  : compute the south phase velocities
+!!$   !!---------------------------------------------------------------------------------
+!!$   USE oce             ! ocean dynamics and tracers variables
+!!$   USE dom_oce         ! ocean space and time domain variables
+!!$   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+!!$   USE phycst          ! physical constants
+!!$   USE obc_oce         ! ocean open boundary conditions
+!!$   USE lib_mpp         ! for mppobc
+!!$   USE in_out_manager  ! I/O units
+!!$
+!!$   IMPLICIT NONE
+!!$   PRIVATE
+!!$
+!!$   PUBLIC   obc_rad    ! routine called by step.F90
+!!$
+!!$   INTEGER ::   ji, jj, jk     ! dummy loop indices
+!!$
+!!$   INTEGER ::      & ! ... boundary space indices 
+!!$      nib   = 1,   & ! nib   = boundary point
+!!$      nibm  = 2,   & ! nibm  = 1st interior point
+!!$      nibm2 = 3,   & ! nibm2 = 2nd interior point
+!!$                     ! ... boundary time indices 
+!!$      nit   = 1,   & ! nit    = now
+!!$      nitm  = 2,   & ! nitm   = before
+!!$      nitm2 = 3      ! nitm2  = before-before
+!!$
+!!$   !! * Substitutions
+!!$#  include "obc_vectopt_loop_substitute.h90"
+!!$   !!---------------------------------------------------------------------------------
+!!$   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+!!$   !! $Id$ 
+!!$   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+!!$   !!---------------------------------------------------------------------------------
+!!$
+!!$CONTAINS
+!!$
+!!$   SUBROUTINE obc_rad ( kt )
+!!$      !!------------------------------------------------------------------------------
+!!$      !!                     SUBROUTINE obc_rad
+!!$      !!                    ********************
+!!$      !! ** Purpose :
+!!$      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
+!!$      !!      boundaries and calculate those phase speeds if the open boundaries are 
+!!$      !!      not fixed. In case of fixed open boundaries does nothing.
+!!$      !!
+!!$      !!     The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north,
+!!$      !!     and/or lp_obc_south allow the user to determine which boundary is an
+!!$      !!     open one (must be done in the param_obc.h90 file).
+!!$      !! 
+!!$      !! ** Reference : 
+!!$      !!     Marchesiello P., 1995, these de l'universite J. Fourier, Grenoble, France.
+!!$      !!
+!!$      !!  History :
+!!$      !!    8.5  !  02-10  (C. Talandier, A-M. Treguier) Free surface, F90 from the 
+!!$      !!                                                 J. Molines and G. Madec version
+!!$      !!------------------------------------------------------------------------------
+!!$      INTEGER, INTENT( in ) ::   kt
+!!$      !!----------------------------------------------------------------------
+!!$
+!!$      IF( lp_obc_east  .AND. .NOT.lfbceast  )   CALL obc_rad_east ( kt )   ! East open boundary
+!!$
+!!$      IF( lp_obc_west  .AND. .NOT.lfbcwest  )   CALL obc_rad_west ( kt )   ! West open boundary
+!!$
+!!$      IF( lp_obc_north .AND. .NOT.lfbcnorth )   CALL obc_rad_north( kt )   ! North open boundary
+!!$
+!!$      IF( lp_obc_south .AND. .NOT.lfbcsouth )   CALL obc_rad_south( kt )   ! South open boundary
+!!$
+!!$   END SUBROUTINE obc_rad
+!!$
+!!$
+!!$   SUBROUTINE obc_rad_east ( kt )
+!!$      !!------------------------------------------------------------------------------
+!!$      !!                     ***  SUBROUTINE obc_rad_east  ***
+!!$      !!                   
+!!$      !! ** Purpose :
+!!$      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
+!!$      !!      east boundary and calculate those phase speeds if this OBC is not fixed.
+!!$      !!      In case of fixed OBC, this subrountine is not called.
+!!$      !!
+!!$      !!  History :
+!!$      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+!!$      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+!!$      !!         ! 97-12 (M. Imbard) Mpp adaptation
+!!$      !!         ! 00-06 (J.-M. Molines) 
+!!$      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+!!$      !!------------------------------------------------------------------------------
+!!$      !! * Arguments
+!!$      INTEGER, INTENT( in ) ::   kt
+!!$
+!!$      !! * Local declarations
+!!$      INTEGER  ::   ij
+!!$      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
+!!$      REAL(wp) ::   zucb, zucbm, zucbm2
+!!$      !!------------------------------------------------------------------------------
+!!$
+!!$      ! 1. Swap arrays before calculating radiative velocities
+!!$      ! ------------------------------------------------------
+!!$
+!!$      ! 1.1  zonal velocity 
+!!$      ! -------------------
+!!$
+!!$      IF( kt > nit000 .OR. ln_rstart ) THEN 
+!!$
+!!$         ! ... advance in time (time filter, array swap) 
+!!$         DO jk = 1, jpkm1
+!!$            DO jj = 1, jpj
+!!$               uebnd(jj,jk,nib  ,nitm2) = uebnd(jj,jk,nib  ,nitm)*uemsk(jj,jk)
+!!$               uebnd(jj,jk,nibm ,nitm2) = uebnd(jj,jk,nibm ,nitm)*uemsk(jj,jk)
+!!$               uebnd(jj,jk,nibm2,nitm2) = uebnd(jj,jk,nibm2,nitm)*uemsk(jj,jk)
+!!$            END DO
+!!$         END DO
+!!$         ! ... fields nitm <== nit  plus time filter at the boundary 
+!!$         DO ji = fs_nie0, fs_nie1 ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO jj = 1, jpj
+!!$                  uebnd(jj,jk,nib  ,nitm) = uebnd(jj,jk,nib,  nit)*uemsk(jj,jk)
+!!$                  uebnd(jj,jk,nibm ,nitm) = uebnd(jj,jk,nibm ,nit)*uemsk(jj,jk)
+!!$                  uebnd(jj,jk,nibm2,nitm) = uebnd(jj,jk,nibm2,nit)*uemsk(jj,jk)
+!!$         ! ... fields nit <== now (kt+1) 
+!!$         ! ... Total or baroclinic velocity at b, bm and bm2
+!!$                  zucb   = un(ji,jj,jk)
+!!$                  zucbm  = un(ji-1,jj,jk)
+!!$                  zucbm2 = un(ji-2,jj,jk)
+!!$                  uebnd(jj,jk,nib  ,nit) = zucb   *uemsk(jj,jk)
+!!$                  uebnd(jj,jk,nibm ,nit) = zucbm  *uemsk(jj,jk) 
+!!$                  uebnd(jj,jk,nibm2,nit) = zucbm2 *uemsk(jj,jk) 
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(uebnd,jpjed,jpjef,jpieob,jpk*3*3,2,jpj, numout )
+!!$
+!!$         ! ... extremeties nie0, nie1
+!!$         ij = jpjed +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               uebnd(ij,jk,nibm,nitm) = uebnd(ij+1 ,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$         ij = jpjef +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               uebnd(ij,jk,nibm,nitm) = uebnd(ij-1 ,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$
+!!$         ! 1.2 tangential velocity
+!!$         ! -----------------------
+!!$
+!!$         ! ... advance in time (time filter, array swap)
+!!$         DO jk = 1, jpkm1
+!!$            DO jj = 1, jpj
+!!$         ! ... fields nitm2 <== nitm
+!!$               vebnd(jj,jk,nib  ,nitm2) = vebnd(jj,jk,nib  ,nitm)*vemsk(jj,jk)
+!!$               vebnd(jj,jk,nibm ,nitm2) = vebnd(jj,jk,nibm ,nitm)*vemsk(jj,jk)
+!!$               vebnd(jj,jk,nibm2,nitm2) = vebnd(jj,jk,nibm2,nitm)*vemsk(jj,jk)
+!!$            END DO
+!!$         END DO
+!!$
+!!$         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO jj = 1, jpj
+!!$                  vebnd(jj,jk,nib  ,nitm) = vebnd(jj,jk,nib,  nit)*vemsk(jj,jk)
+!!$                  vebnd(jj,jk,nibm ,nitm) = vebnd(jj,jk,nibm ,nit)*vemsk(jj,jk)
+!!$                  vebnd(jj,jk,nibm2,nitm) = vebnd(jj,jk,nibm2,nit)*vemsk(jj,jk)
+!!$         ! ... fields nit <== now (kt+1)
+!!$                  vebnd(jj,jk,nib  ,nit) = vn(ji  ,jj,jk)*vemsk(jj,jk)
+!!$                  vebnd(jj,jk,nibm ,nit) = vn(ji-1,jj,jk)*vemsk(jj,jk)
+!!$                  vebnd(jj,jk,nibm2,nit) = vn(ji-2,jj,jk)*vemsk(jj,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(vebnd,jpjed,jpjef,jpieob+1,jpk*3*3,2,jpj, numout )
+!!$
+!!$         !... extremeties nie0, nie1
+!!$         ij = jpjed +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               vebnd(ij,jk,nibm,nitm) = vebnd(ij+1 ,jk,nibm,nitm)
+!!$            END DO 
+!!$         END IF 
+!!$         ij = jpjef +1 - njmpp 
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN 
+!!$            DO jk = 1,jpkm1 
+!!$               vebnd(ij,jk,nibm,nitm) = vebnd(ij-1 ,jk,nibm,nitm)
+!!$            END DO 
+!!$         END IF 
+!!$
+!!$         ! 1.3 Temperature and salinity
+!!$         ! ----------------------------
+!!$
+!!$         ! ... advance in time (time filter, array swap)
+!!$         DO jk = 1, jpkm1
+!!$            DO jj = 1, jpj
+!!$         ! ... fields nitm <== nit  plus time filter at the boundary
+!!$               tebnd(jj,jk,nib,nitm) = tebnd(jj,jk,nib,nit)*temsk(jj,jk)
+!!$               sebnd(jj,jk,nib,nitm) = sebnd(jj,jk,nib,nit)*temsk(jj,jk)
+!!$            END DO
+!!$         END DO
+!!$
+!!$         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO jj = 1, jpj
+!!$                  tebnd(jj,jk,nibm,nitm) = tebnd(jj,jk,nibm,nit)*temsk(jj,jk)
+!!$                  sebnd(jj,jk,nibm,nitm) = sebnd(jj,jk,nibm,nit)*temsk(jj,jk)
+!!$         ! ... fields nit <== now (kt+1)
+!!$                  tebnd(jj,jk,nib  ,nit) = tn(ji  ,jj,jk)*temsk(jj,jk)
+!!$                  tebnd(jj,jk,nibm ,nit) = tn(ji-1,jj,jk)*temsk(jj,jk)
+!!$                  sebnd(jj,jk,nib  ,nit) = sn(ji  ,jj,jk)*temsk(jj,jk)
+!!$                  sebnd(jj,jk,nibm ,nit) = sn(ji-1,jj,jk)*temsk(jj,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(tebnd,jpjed,jpjef,jpieob+1,jpk*2*2,2,jpj, numout )
+!!$         IF( lk_mpp )   CALL mppobc(sebnd,jpjed,jpjef,jpieob+1,jpk*2*2,2,jpj, numout )
+!!$
+!!$         ! ... extremeties nie0, nie1
+!!$         ij = jpjed +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               tebnd(ij,jk,nibm,nitm) = tebnd(ij+1 ,jk,nibm,nitm)
+!!$               sebnd(ij,jk,nibm,nitm) = sebnd(ij+1 ,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$         ij = jpjef +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               tebnd(ij,jk,nibm,nitm) = tebnd(ij-1 ,jk,nibm,nitm)
+!!$               sebnd(ij,jk,nibm,nitm) = sebnd(ij-1 ,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$
+!!$      END IF     ! End of array swap
+!!$
+!!$      ! 2 - Calculation of radiation velocities
+!!$      ! ---------------------------------------
+!!$
+!!$      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
+!!$
+!!$         ! 2.1  Calculate the normal velocity U based on phase velocity u_cxebnd
+!!$         ! ---------------------------------------------------------------------
+!!$         !
+!!$         !          nibm2      nibm      nib
+!!$         !            |  nibm   |   nib   |///
+!!$         !            |    |    |    |    |///
+!!$         !  jj-line --f----v----f----v----f---
+!!$         !            |    |    |    |    |///
+!!$         !            |         |         |///
+!!$         !  jj-line   u    T    u    T    u///
+!!$         !            |         |         |///
+!!$         !            |    |    |    |    |///
+!!$         !          jpieob-2   jpieob-1   jpieob
+!!$         !                 |         |        
+!!$         !              jpieob-1    jpieob      
+!!$         !
+!!$         ! ... (jpjedp1, jpjefm1),jpieob
+!!$         DO ji = fs_nie0, fs_nie1 ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO jj = 2, jpjm1
+!!$         ! ... 2* gradi(u) (T-point i=nibm, time mean)
+!!$                  z2dx = ( uebnd(jj,jk,nibm ,nit) + uebnd(jj,jk,nibm ,nitm2) &
+!!$                           - 2.*uebnd(jj,jk,nibm2,nitm) ) / e1t(ji-1,jj)
+!!$         ! ... 2* gradj(u) (u-point i=nibm, time nitm)
+!!$                  z2dy = ( uebnd(jj+1,jk,nibm,nitm) - uebnd(jj-1,jk,nibm,nitm) ) / e2u(ji-1,jj)
+!!$         ! ... square of the norm of grad(u)
+!!$                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+!!$         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+!!$                  zdt = uebnd(jj,jk,nibm,nitm2) - uebnd(jj,jk,nibm,nit)
+!!$         ! ... i-phase speed ratio (bounded by 1)               
+!!$                  IF( z4nor2 == 0. ) THEN
+!!$                     z4nor2=.00001
+!!$                  END IF
+!!$                  z05cx = zdt * z2dx / z4nor2
+!!$                  u_cxebnd(jj,jk) = z05cx*uemsk(jj,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$
+!!$         ! 2.2  Calculate the tangential velocity based on phase velocity v_cxebnd
+!!$         ! -----------------------------------------------------------------------
+!!$         !
+!!$         !          nibm2      nibm      nib
+!!$         !            |   nibm  |   nib///|///
+!!$         !            |    |    |    |////|///
+!!$         !  jj-line --v----f----v----f----v---
+!!$         !            |    |    |    |////|///
+!!$         !            |    |    |    |////|///
+!!$         !            | jpieob-1| jpieob /|///
+!!$         !            |         |         |   
+!!$         !         jpieob-1    jpieob     jpieob+1
+!!$         !
+!!$         ! ... (jpjedp1, jpjefm1), jpieob+1
+!!$         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO jj = 2, jpjm1
+!!$         ! ... 2* i-gradient of v (f-point i=nibm, time mean)
+!!$                  z2dx = ( vebnd(jj,jk,nibm ,nit) + vebnd(jj,jk,nibm ,nitm2) &
+!!$                          - 2.*vebnd(jj,jk,nibm2,nitm) ) / e1f(ji-2,jj)
+!!$         ! ... 2* j-gradient of v (v-point i=nibm, time nitm)
+!!$                  z2dy = ( vebnd(jj+1,jk,nibm,nitm) -  vebnd(jj-1,jk,nibm,nitm) ) / e2v(ji-1,jj)
+!!$         ! ... square of the norm of grad(v)
+!!$                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+!!$         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+!!$                  zdt = vebnd(jj,jk,nibm,nitm2) - vebnd(jj,jk,nibm,nit)
+!!$         ! ... i-phase speed ratio (bounded by 1) and save the unbounded phase
+!!$         !     velocity ratio no divided by e1f for the tracer radiation
+!!$                  IF( z4nor2 == 0. ) THEN
+!!$                     z4nor2=.000001
+!!$                  END IF
+!!$                  z05cx = zdt * z2dx / z4nor2
+!!$                  v_cxebnd(jj,jk) = z05cx*vemsk(jj,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(v_cxebnd,jpjed,jpjef,jpieob+1,jpk,2,jpj, numout )
+!!$
+!!$         ! ... extremeties nie0, nie1
+!!$         ij = jpjed +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               v_cxebnd(ij,jk) = v_cxebnd(ij+1 ,jk)
+!!$            END DO
+!!$         END IF
+!!$         ij = jpjef +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               v_cxebnd(ij,jk) = v_cxebnd(ij-1 ,jk)
+!!$            END DO
+!!$         END IF
+!!$
+!!$      END IF
+!!$
+!!$   END SUBROUTINE obc_rad_east
+!!$
+!!$
+!!$   SUBROUTINE obc_rad_west ( kt )
+!!$      !!------------------------------------------------------------------------------
+!!$      !!                  ***  SUBROUTINE obc_rad_west  ***
+!!$      !!                    
+!!$      !! ** Purpose :
+!!$      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
+!!$      !!      west boundary and calculate those phase speeds if this OBC is not fixed.
+!!$      !!      In case of fixed OBC, this subrountine is not called.
+!!$      !!
+!!$      !!  History :
+!!$      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+!!$      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+!!$      !!         ! 97-12 (M. Imbard) Mpp adaptation
+!!$      !!         ! 00-06 (J.-M. Molines) 
+!!$      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+!!$      !!------------------------------------------------------------------------------
+!!$      !! * Arguments
+!!$      INTEGER, INTENT( in ) ::   kt
+!!$
+!!$      !! * Local declarations
+!!$      INTEGER ::   ij
+!!$      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
+!!$      REAL(wp) ::   zucb, zucbm, zucbm2
+!!$      !!------------------------------------------------------------------------------
+!!$
+!!$      ! 1. Swap arrays before calculating radiative velocities
+!!$      ! ------------------------------------------------------
+!!$
+!!$      ! 1.1  zonal velocity 
+!!$      ! -------------------
+!!$
+!!$      IF( kt > nit000 .OR. ln_rstart ) THEN
+!!$
+!!$         ! ... advance in time (time filter, array swap) 
+!!$         DO jk = 1, jpkm1
+!!$            DO jj = 1, jpj 
+!!$               uwbnd(jj,jk,nib  ,nitm2) = uwbnd(jj,jk,nib  ,nitm)*uwmsk(jj,jk)
+!!$               uwbnd(jj,jk,nibm ,nitm2) = uwbnd(jj,jk,nibm ,nitm)*uwmsk(jj,jk)
+!!$               uwbnd(jj,jk,nibm2,nitm2) = uwbnd(jj,jk,nibm2,nitm)*uwmsk(jj,jk)
+!!$            END DO
+!!$         END DO
+!!$
+!!$         ! ... fields nitm <== nit  plus time filter at the boundary 
+!!$         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO jj = 1, jpj
+!!$                  uwbnd(jj,jk,nib  ,nitm) = uwbnd(jj,jk,nib  ,nit)*uwmsk(jj,jk)
+!!$                  uwbnd(jj,jk,nibm ,nitm) = uwbnd(jj,jk,nibm ,nit)*uwmsk(jj,jk)
+!!$                  uwbnd(jj,jk,nibm2,nitm) = uwbnd(jj,jk,nibm2,nit)*uwmsk(jj,jk)
+!!$         ! ... total or baroclinic velocity at b, bm and bm2
+!!$                  zucb   = un (ji,jj,jk)
+!!$                  zucbm  = un (ji+1,jj,jk)
+!!$                  zucbm2 = un (ji+2,jj,jk)
+!!$
+!!$         ! ... fields nit <== now (kt+1) 
+!!$                  uwbnd(jj,jk,nib  ,nit) = zucb  *uwmsk(jj,jk)
+!!$                  uwbnd(jj,jk,nibm ,nit) = zucbm *uwmsk(jj,jk)
+!!$                  uwbnd(jj,jk,nibm2,nit) = zucbm2*uwmsk(jj,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(uwbnd,jpjwd,jpjwf,jpiwob,jpk*3*3,2,jpj, numout )
+!!$
+!!$         ! ... extremeties niw0, niw1
+!!$         ij = jpjwd +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               uwbnd(ij,jk,nibm,nitm) = uwbnd(ij+1 ,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$         ij = jpjwf +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               uwbnd(ij,jk,nibm,nitm) = uwbnd(ij-1 ,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$
+!!$         ! 1.2 tangential velocity
+!!$         ! -----------------------
+!!$
+!!$         ! ... advance in time (time filter, array swap)
+!!$         DO jk = 1, jpkm1
+!!$            DO jj = 1, jpj 
+!!$         ! ... fields nitm2 <== nitm
+!!$                  vwbnd(jj,jk,nib  ,nitm2) = vwbnd(jj,jk,nib  ,nitm)*vwmsk(jj,jk)
+!!$                  vwbnd(jj,jk,nibm ,nitm2) = vwbnd(jj,jk,nibm ,nitm)*vwmsk(jj,jk)
+!!$                  vwbnd(jj,jk,nibm2,nitm2) = vwbnd(jj,jk,nibm2,nitm)*vwmsk(jj,jk)
+!!$            END DO
+!!$         END DO
+!!$
+!!$         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO jj = 1, jpj
+!!$                  vwbnd(jj,jk,nib  ,nitm) = vwbnd(jj,jk,nib,  nit)*vwmsk(jj,jk)
+!!$                  vwbnd(jj,jk,nibm ,nitm) = vwbnd(jj,jk,nibm ,nit)*vwmsk(jj,jk)
+!!$                  vwbnd(jj,jk,nibm2,nitm) = vwbnd(jj,jk,nibm2,nit)*vwmsk(jj,jk)
+!!$         ! ... fields nit <== now (kt+1)
+!!$                  vwbnd(jj,jk,nib  ,nit) = vn(ji  ,jj,jk)*vwmsk(jj,jk)
+!!$                  vwbnd(jj,jk,nibm ,nit) = vn(ji+1,jj,jk)*vwmsk(jj,jk)
+!!$                  vwbnd(jj,jk,nibm2,nit) = vn(ji+2,jj,jk)*vwmsk(jj,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(vwbnd,jpjwd,jpjwf,jpiwob,jpk*3*3,2,jpj, numout )
+!!$
+!!$         ! ... extremeties niw0, niw1 
+!!$         ij = jpjwd +1 - njmpp 
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN 
+!!$            DO jk = 1,jpkm1 
+!!$               vwbnd(ij,jk,nibm,nitm) = vwbnd(ij+1 ,jk,nibm,nitm)
+!!$            END DO 
+!!$         END IF
+!!$         ij = jpjwf +1 - njmpp 
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN 
+!!$            DO jk = 1,jpkm1 
+!!$               vwbnd(ij,jk,nibm,nitm) = vwbnd(ij-1 ,jk,nibm,nitm)
+!!$            END DO 
+!!$         END IF 
+!!$ 
+!!$         ! 1.3 Temperature and salinity
+!!$         ! ----------------------------
+!!$ 
+!!$         ! ... advance in time (time filter, array swap)
+!!$         DO jk = 1, jpkm1
+!!$            DO jj = 1, jpj
+!!$         ! ... fields nitm <== nit  plus time filter at the boundary
+!!$               twbnd(jj,jk,nib,nitm) = twbnd(jj,jk,nib,nit)*twmsk(jj,jk)
+!!$               swbnd(jj,jk,nib,nitm) = swbnd(jj,jk,nib,nit)*twmsk(jj,jk)
+!!$            END DO
+!!$         END DO
+!!$ 
+!!$         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO jj = 1, jpj
+!!$                  twbnd(jj,jk,nibm ,nitm) = twbnd(jj,jk,nibm ,nit)*twmsk(jj,jk)
+!!$                  swbnd(jj,jk,nibm ,nitm) = swbnd(jj,jk,nibm ,nit)*twmsk(jj,jk)
+!!$         ! ... fields nit <== now (kt+1)
+!!$                  twbnd(jj,jk,nib  ,nit) = tn(ji   ,jj,jk)*twmsk(jj,jk)
+!!$                  twbnd(jj,jk,nibm ,nit) = tn(ji+1 ,jj,jk)*twmsk(jj,jk)
+!!$                  swbnd(jj,jk,nib  ,nit) = sn(ji   ,jj,jk)*twmsk(jj,jk)
+!!$                  swbnd(jj,jk,nibm ,nit) = sn(ji+1 ,jj,jk)*twmsk(jj,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(twbnd,jpjwd,jpjwf,jpiwob,jpk*2*2,2,jpj, numout )
+!!$         IF( lk_mpp )   CALL mppobc(swbnd,jpjwd,jpjwf,jpiwob,jpk*2*2,2,jpj, numout )
+!!$
+!!$         ! ... extremeties niw0, niw1
+!!$         ij = jpjwd +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               twbnd(ij,jk,nibm,nitm) = twbnd(ij+1 ,jk,nibm,nitm)
+!!$               swbnd(ij,jk,nibm,nitm) = swbnd(ij+1 ,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$         ij = jpjwf +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               twbnd(ij,jk,nibm,nitm) = twbnd(ij-1 ,jk,nibm,nitm)
+!!$               swbnd(ij,jk,nibm,nitm) = swbnd(ij-1 ,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$ 
+!!$      END IF     ! End of array swap
+!!$
+!!$      ! 2 - Calculation of radiation velocities
+!!$      ! ---------------------------------------
+!!$   
+!!$      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
+!!$  
+!!$         ! 2.1  Calculate the normal velocity U based on phase velocity u_cxwbnd
+!!$         ! ----------------------------------------------------------------------
+!!$         !
+!!$         !          nib       nibm      nibm2
+!!$         !        ///|   nib   |   nibm  |
+!!$         !        ///|    |    |    |    |
+!!$         !        ---f----v----f----v----f-- jj-line
+!!$         !        ///|    |    |    |    |
+!!$         !        ///|         |         |
+!!$         !        ///u    T    u    T    u   jj-line
+!!$         !        ///|         |         |
+!!$         !        ///|    |    |    |    |
+!!$         !         jpiwob    jpiwob+1    jpiwob+2
+!!$         !                |         |        
+!!$         !              jpiwob+1    jpiwob+2     
+!!$         !
+!!$         ! ... If free surface formulation:
+!!$         ! ... radiative conditions on the total part + relaxation toward climatology
+!!$         ! ... (jpjwdp1, jpjwfm1), jpiwob
+!!$         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO jj = 2, jpjm1
+!!$         ! ... 2* gradi(u) (T-point i=nibm, time mean)
+!!$                  z2dx = ( - uwbnd(jj,jk,nibm ,nit) -  uwbnd(jj,jk,nibm ,nitm2) &
+!!$                           + 2.*uwbnd(jj,jk,nibm2,nitm) ) / e1t(ji+2,jj)
+!!$         ! ... 2* gradj(u) (u-point i=nibm, time nitm)
+!!$                  z2dy = ( uwbnd(jj+1,jk,nibm,nitm) - uwbnd(jj-1,jk,nibm,nitm) ) / e2u(ji+1,jj)
+!!$         ! ... square of the norm of grad(u)
+!!$                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+!!$         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+!!$                  zdt = uwbnd(jj,jk,nibm,nitm2) - uwbnd(jj,jk,nibm,nit)
+!!$         ! ... i-phase speed ratio (bounded by -1)
+!!$                  IF( z4nor2 == 0. ) THEN
+!!$                     z4nor2=0.00001
+!!$                  END IF
+!!$                  z05cx = zdt * z2dx / z4nor2
+!!$                  u_cxwbnd(jj,jk)=z05cx*uwmsk(jj,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$
+!!$         ! 2.2  Calculate the tangential velocity based on phase velocity v_cxwbnd
+!!$         ! -----------------------------------------------------------------------
+!!$         !
+!!$         !      nib       nibm     nibm2
+!!$         !    ///|///nib   |   nibm  |  nibm2
+!!$         !    ///|////|    |    |    |    |    |
+!!$         !    ---v----f----v----f----v----f----v-- jj-line
+!!$         !    ///|////|    |    |    |    |    |
+!!$         !    ///|////|    |    |    |    |    |
+!!$         !   jpiwob     jpiwob+1    jpiwob+2
+!!$         !            |         |         |   
+!!$         !          jpiwob   jpiwob+1   jpiwob+2    
+!!$         !
+!!$         ! ... radiative condition plus Raymond-Kuo
+!!$         ! ... (jpjwdp1, jpjwfm1),jpiwob
+!!$         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO jj = 2, jpjm1
+!!$         ! ... 2* i-gradient of v (f-point i=nibm, time mean)
+!!$                  z2dx = ( - vwbnd(jj,jk,nibm ,nit) - vwbnd(jj,jk,nibm ,nitm2) &
+!!$                           + 2.*vwbnd(jj,jk,nibm2,nitm) ) / e1f(ji+1,jj)
+!!$         ! ... 2* j-gradient of v (v-point i=nibm, time nitm)
+!!$                  z2dy = ( vwbnd(jj+1,jk,nibm,nitm) - vwbnd(jj-1,jk,nibm,nitm) ) / e2v(ji+1,jj)
+!!$         ! ... square of the norm of grad(v)
+!!$                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+!!$         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+!!$                  zdt = vwbnd(jj,jk,nibm,nitm2) - vwbnd(jj,jk,nibm,nit)
+!!$         ! ... i-phase speed ratio (bounded by -1) and save the unbounded phase
+!!$         !     velocity ratio no divided by e1f for the tracer radiation
+!!$                  IF( z4nor2 == 0) THEN
+!!$                     z4nor2=0.000001
+!!$                  endif
+!!$                  z05cx = zdt * z2dx / z4nor2
+!!$                  v_cxwbnd(jj,jk) = z05cx*vwmsk(jj,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(v_cxwbnd,jpjwd,jpjwf,jpiwob,jpk,2,jpj, numout )
+!!$
+!!$         ! ... extremeties niw0, niw1
+!!$         ij = jpjwd +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               v_cxwbnd(ij,jk) = v_cxwbnd(ij+1 ,jk)
+!!$            END DO
+!!$         END IF
+!!$         ij = jpjwf +1 - njmpp
+!!$         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+!!$            DO jk = 1,jpkm1
+!!$               v_cxwbnd(ij,jk) = v_cxwbnd(ij-1 ,jk)
+!!$            END DO
+!!$         END IF
+!!$
+!!$      END IF
+!!$
+!!$   END SUBROUTINE obc_rad_west
+!!$
+!!$
+!!$   SUBROUTINE obc_rad_north ( kt )
+!!$      !!------------------------------------------------------------------------------
+!!$      !!                  ***  SUBROUTINE obc_rad_north  ***
+!!$      !!           
+!!$      !! ** Purpose :
+!!$      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
+!!$      !!      north boundary and calculate those phase speeds if this OBC is not fixed.
+!!$      !!      In case of fixed OBC, this subrountine is not called.
+!!$      !!
+!!$      !!  History :
+!!$      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+!!$      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+!!$      !!         ! 97-12 (M. Imbard) Mpp adaptation
+!!$      !!         ! 00-06 (J.-M. Molines) 
+!!$      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+!!$      !!------------------------------------------------------------------------------
+!!$      !! * Arguments
+!!$      INTEGER, INTENT( in ) ::   kt
+!!$
+!!$      !! * Local declarations
+!!$      INTEGER  ::   ii
+!!$      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
+!!$      REAL(wp) ::   zvcb, zvcbm, zvcbm2
+!!$      !!------------------------------------------------------------------------------
+!!$
+!!$      ! 1. Swap arrays before calculating radiative velocities
+!!$      ! ------------------------------------------------------
+!!$
+!!$      ! 1.1  zonal velocity 
+!!$      ! -------------------
+!!$
+!!$      IF( kt > nit000 .OR. ln_rstart ) THEN 
+!!$
+!!$         ! ... advance in time (time filter, array swap)
+!!$         DO jk = 1, jpkm1
+!!$            DO ji = 1, jpi
+!!$         ! ... fields nitm2 <== nitm
+!!$               unbnd(ji,jk,nib  ,nitm2) = unbnd(ji,jk,nib  ,nitm)*unmsk(ji,jk)
+!!$               unbnd(ji,jk,nibm ,nitm2) = unbnd(ji,jk,nibm ,nitm)*unmsk(ji,jk)
+!!$               unbnd(ji,jk,nibm2,nitm2) = unbnd(ji,jk,nibm2,nitm)*unmsk(ji,jk)
+!!$            END DO
+!!$         END DO
+!!$
+!!$         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO ji = 1, jpi
+!!$                  unbnd(ji,jk,nib  ,nitm) = unbnd(ji,jk,nib,  nit)*unmsk(ji,jk)
+!!$                  unbnd(ji,jk,nibm ,nitm) = unbnd(ji,jk,nibm ,nit)*unmsk(ji,jk)
+!!$                  unbnd(ji,jk,nibm2,nitm) = unbnd(ji,jk,nibm2,nit)*unmsk(ji,jk)
+!!$         ! ... fields nit <== now (kt+1)
+!!$                  unbnd(ji,jk,nib  ,nit) = un(ji,jj,  jk)*unmsk(ji,jk)
+!!$                  unbnd(ji,jk,nibm ,nit) = un(ji,jj-1,jk)*unmsk(ji,jk)
+!!$                  unbnd(ji,jk,nibm2,nit) = un(ji,jj-2,jk)*unmsk(ji,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(unbnd,jpind,jpinf,jpjnob+1,jpk*3*3,1,jpi, numout )
+!!$
+!!$         ! ... extremeties njn0,njn1 
+!!$         ii = jpind + 1 - nimpp 
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN 
+!!$            DO jk = 1, jpkm1
+!!$                unbnd(ii,jk,nibm,nitm) = unbnd(ii+1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF 
+!!$         ii = jpinf + 1 - nimpp 
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               unbnd(ii,jk,nibm,nitm) = unbnd(ii-1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$ 
+!!$         ! 1.2. normal velocity 
+!!$         ! --------------------
+!!$
+!!$         ! ... advance in time (time filter, array swap) 
+!!$         DO jk = 1, jpkm1
+!!$            DO ji = 1, jpi
+!!$         ! ... fields nitm2 <== nitm 
+!!$               vnbnd(ji,jk,nib  ,nitm2) = vnbnd(ji,jk,nib  ,nitm)*vnmsk(ji,jk)
+!!$               vnbnd(ji,jk,nibm ,nitm2) = vnbnd(ji,jk,nibm ,nitm)*vnmsk(ji,jk)
+!!$               vnbnd(ji,jk,nibm2,nitm2) = vnbnd(ji,jk,nibm2,nitm)*vnmsk(ji,jk)
+!!$            END DO
+!!$         END DO
+!!$
+!!$         DO jj = fs_njn0, fs_njn1  ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO ji = 1, jpi
+!!$                  vnbnd(ji,jk,nib  ,nitm) = vnbnd(ji,jk,nib,  nit)*vnmsk(ji,jk)
+!!$                  vnbnd(ji,jk,nibm ,nitm) = vnbnd(ji,jk,nibm ,nit)*vnmsk(ji,jk)
+!!$                  vnbnd(ji,jk,nibm2,nitm) = vnbnd(ji,jk,nibm2,nit)*vnmsk(ji,jk)
+!!$         ! ... fields nit <== now (kt+1)
+!!$         ! ... total or baroclinic velocity at b, bm and bm2
+!!$                  zvcb   = vn (ji,jj,jk)
+!!$                  zvcbm  = vn (ji,jj-1,jk)
+!!$                  zvcbm2 = vn (ji,jj-2,jk)
+!!$         ! ... fields nit <== now (kt+1) 
+!!$                  vnbnd(ji,jk,nib  ,nit) = zvcb  *vnmsk(ji,jk)
+!!$                  vnbnd(ji,jk,nibm ,nit) = zvcbm *vnmsk(ji,jk)
+!!$                  vnbnd(ji,jk,nibm2,nit) = zvcbm2*vnmsk(ji,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(vnbnd,jpind,jpinf,jpjnob,jpk*3*3,1,jpi, numout )
+!!$
+!!$         ! ... extremeties njn0,njn1
+!!$         ii = jpind + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               vnbnd(ii,jk,nibm,nitm) = vnbnd(ii+1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$         ii = jpinf + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               vnbnd(ii,jk,nibm,nitm) = vnbnd(ii-1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$
+!!$         ! 1.3 Temperature and salinity
+!!$         ! ----------------------------
+!!$
+!!$         ! ... advance in time (time filter, array swap)
+!!$         DO jk = 1, jpkm1
+!!$            DO ji = 1, jpi
+!!$         ! ... fields nitm <== nit  plus time filter at the boundary
+!!$               tnbnd(ji,jk,nib ,nitm) = tnbnd(ji,jk,nib,nit)*tnmsk(ji,jk)
+!!$               snbnd(ji,jk,nib ,nitm) = snbnd(ji,jk,nib,nit)*tnmsk(ji,jk)
+!!$            END DO
+!!$         END DO
+!!$
+!!$         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO ji = 1, jpi
+!!$                  tnbnd(ji,jk,nibm ,nitm) = tnbnd(ji,jk,nibm ,nit)*tnmsk(ji,jk)
+!!$                  snbnd(ji,jk,nibm ,nitm) = snbnd(ji,jk,nibm ,nit)*tnmsk(ji,jk)
+!!$         ! ... fields nit <== now (kt+1)
+!!$                  tnbnd(ji,jk,nib  ,nit) = tn(ji,jj,  jk)*tnmsk(ji,jk)
+!!$                  tnbnd(ji,jk,nibm ,nit) = tn(ji,jj-1,jk)*tnmsk(ji,jk)
+!!$                  snbnd(ji,jk,nib  ,nit) = sn(ji,jj,  jk)*tnmsk(ji,jk)
+!!$                  snbnd(ji,jk,nibm ,nit) = sn(ji,jj-1,jk)*tnmsk(ji,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(tnbnd,jpind,jpinf,jpjnob+1,jpk*2*2,1,jpi, numout )
+!!$         IF( lk_mpp )   CALL mppobc(snbnd,jpind,jpinf,jpjnob+1,jpk*2*2,1,jpi, numout )
+!!$
+!!$         ! ... extremeties  njn0,njn1
+!!$         ii = jpind + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               tnbnd(ii,jk,nibm,nitm) = tnbnd(ii+1,jk,nibm,nitm)
+!!$               snbnd(ii,jk,nibm,nitm) = snbnd(ii+1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$         ii = jpinf + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               tnbnd(ii,jk,nibm,nitm) = tnbnd(ii-1,jk,nibm,nitm)
+!!$               snbnd(ii,jk,nibm,nitm) = snbnd(ii-1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$
+!!$      END IF     ! End of array swap
+!!$
+!!$      ! 2 - Calculation of radiation velocities
+!!$      ! ---------------------------------------
+!!$
+!!$      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
+!!$
+!!$         ! 2.1  Calculate the normal velocity based on phase velocity u_cynbnd
+!!$         ! -------------------------------------------------------------------
+!!$         !
+!!$         !           ji-row
+!!$         !             |
+!!$         !     nib -///u//////  jpjnob + 1
+!!$         !        /////|//////
+!!$         !   nib  -----f-----   jpjnob
+!!$         !             |    
+!!$         !     nibm--  u   ---- jpjnob
+!!$         !             |        
+!!$         !  nibm  -----f-----   jpjnob-1
+!!$         !             |        
+!!$         !    nibm2--  u   ---- jpjnob-1
+!!$         !             |        
+!!$         !  nibm2 -----f-----   jpjnob-2
+!!$         !             |
+!!$         ! ... radiative condition
+!!$         ! ... jpjnob+1,(jpindp1, jpinfm1)
+!!$         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO ji = 2, jpim1
+!!$         ! ... 2* j-gradient of u (f-point i=nibm, time mean)
+!!$                  z2dx = ( unbnd(ji,jk,nibm ,nit) + unbnd(ji,jk,nibm ,nitm2) &
+!!$                        - 2.*unbnd(ji,jk,nibm2,nitm)) / e2f(ji,jj-2)
+!!$         ! ... 2* i-gradient of u (u-point i=nibm, time nitm)
+!!$                  z2dy = ( unbnd(ji+1,jk,nibm,nitm) - unbnd(ji-1,jk,nibm,nitm) ) / e1u(ji,jj-1)
+!!$         ! ... square of the norm of grad(v)
+!!$                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+!!$         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+!!$                  zdt = unbnd(ji,jk,nibm,nitm2) - unbnd(ji,jk,nibm,nit)
+!!$         ! ... i-phase speed ratio (bounded by 1) and save the unbounded phase
+!!$         !     velocity ratio no divided by e1f for the tracer radiation
+!!$                  IF( z4nor2 == 0.) THEN
+!!$                     z4nor2=.000001
+!!$                  END IF
+!!$                  z05cx = zdt * z2dx / z4nor2
+!!$                  u_cynbnd(ji,jk) = z05cx *unmsk(ji,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(u_cynbnd,jpind,jpinf,jpjnob+1,jpk,1,jpi, numout )
+!!$
+!!$         ! ... extremeties  njn0,njn1
+!!$         ii = jpind + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               u_cynbnd(ii,jk) = u_cynbnd(ii+1,jk)
+!!$            END DO
+!!$         END IF
+!!$         ii = jpinf + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               u_cynbnd(ii,jk) = u_cynbnd(ii-1,jk)
+!!$            END DO
+!!$         END IF
+!!$
+!!$         ! 2.2 Calculate the normal velocity based on phase velocity v_cynbnd 
+!!$         ! ------------------------------------------------------------------
+!!$         !
+!!$         !                ji-row  ji-row
+!!$         !                     |
+!!$         !        /////|/////////////////
+!!$         !   nib  -----f----v----f----  jpjnob
+!!$         !             |         |
+!!$         !     nib  -  u -- T -- u ---- jpjnob
+!!$         !             |         |
+!!$         !  nibm  -----f----v----f----  jpjnob-1
+!!$         !             |         |
+!!$         !    nibm --  u -- T -- u ---  jpjnob-1
+!!$         !             |         |
+!!$         !  nibm2 -----f----v----f----  jpjnob-2
+!!$         !             |         |
+!!$         ! ... Free surface formulation:
+!!$         ! ... radiative conditions on the total part + relaxation toward climatology 
+!!$         ! ... jpjnob,(jpindp1, jpinfm1)
+!!$         DO jj = fs_njn0, fs_njn1  ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO ji = 2, jpim1
+!!$         ! ... 2* gradj(v) (T-point i=nibm, time mean)
+!!$                  ii = ji -1 + nimpp
+!!$                  z2dx = ( vnbnd(ji,jk,nibm ,nit) + vnbnd(ji,jk,nibm ,nitm2) &
+!!$                          - 2.*vnbnd(ji,jk,nibm2,nitm)) / e2t(ji,jj-1)
+!!$         ! ... 2* gradi(v) (v-point i=nibm, time nitm)
+!!$                  z2dy = ( vnbnd(ji+1,jk,nibm,nitm) - vnbnd(ji-1,jk,nibm,nitm) ) / e1v(ji,jj-1)
+!!$         ! ... square of the norm of grad(u)
+!!$                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+!!$         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+!!$                  zdt = vnbnd(ji,jk,nibm,nitm2) - vnbnd(ji,jk,nibm,nit)
+!!$         ! ... j-phase speed ratio (bounded by 1)
+!!$                  IF( z4nor2 == 0. ) THEN
+!!$                     z4nor2=.00001
+!!$                  END IF
+!!$                  z05cx = zdt * z2dx / z4nor2
+!!$                  v_cynbnd(ji,jk)=z05cx *vnmsk(ji,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$
+!!$      END IF
+!!$
+!!$   END SUBROUTINE obc_rad_north
+!!$
+!!$
+!!$   SUBROUTINE obc_rad_south ( kt )
+!!$      !!------------------------------------------------------------------------------
+!!$      !!                  ***  SUBROUTINE obc_rad_south  ***
+!!$      !!           
+!!$      !! ** Purpose :
+!!$      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
+!!$      !!      south boundary and calculate those phase speeds if this OBC is not fixed.
+!!$      !!      In case of fixed OBC, this subrountine is not called.
+!!$      !!
+!!$      !!  History :
+!!$      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+!!$      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+!!$      !!         ! 97-12 (M. Imbard) Mpp adaptation
+!!$      !!         ! 00-06 (J.-M. Molines) 
+!!$      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+!!$      !!------------------------------------------------------------------------------
+!!$      !! * Arguments
+!!$      INTEGER, INTENT( in ) ::   kt
+!!$
+!!$      !! * Local declarations
+!!$      INTEGER ::   ii
+!!$      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
+!!$      REAL(wp) ::   zvcb, zvcbm, zvcbm2
+!!$      !!------------------------------------------------------------------------------
+!!$
+!!$      ! 1. Swap arrays before calculating radiative velocities
+!!$      ! ------------------------------------------------------
+!!$
+!!$      ! 1.1  zonal velocity 
+!!$      ! --------------------
+!!$  
+!!$      IF( kt > nit000 .OR. ln_rstart ) THEN 
+!!$
+!!$         ! ... advance in time (time filter, array swap)
+!!$         DO jk = 1, jpkm1
+!!$            DO ji = 1, jpi
+!!$         ! ... fields nitm2 <== nitm
+!!$                  usbnd(ji,jk,nib  ,nitm2) = usbnd(ji,jk,nib  ,nitm)*usmsk(ji,jk)
+!!$                  usbnd(ji,jk,nibm ,nitm2) = usbnd(ji,jk,nibm ,nitm)*usmsk(ji,jk)
+!!$                  usbnd(ji,jk,nibm2,nitm2) = usbnd(ji,jk,nibm2,nitm)*usmsk(ji,jk)
+!!$            END DO
+!!$         END DO
+!!$ 
+!!$         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO ji = 1, jpi
+!!$                  usbnd(ji,jk,nib  ,nitm) = usbnd(ji,jk,nib,  nit)*usmsk(ji,jk)
+!!$                  usbnd(ji,jk,nibm ,nitm) = usbnd(ji,jk,nibm ,nit)*usmsk(ji,jk)
+!!$                  usbnd(ji,jk,nibm2,nitm) = usbnd(ji,jk,nibm2,nit)*usmsk(ji,jk)
+!!$         ! ... fields nit <== now (kt+1)
+!!$                  usbnd(ji,jk,nib  ,nit) = un(ji,jj  ,jk)*usmsk(ji,jk)
+!!$                  usbnd(ji,jk,nibm ,nit) = un(ji,jj+1,jk)*usmsk(ji,jk)
+!!$                  usbnd(ji,jk,nibm2,nit) = un(ji,jj+2,jk)*usmsk(ji,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(usbnd,jpisd,jpisf,jpjsob,jpk*3*3,1,jpi, numout )
+!!$
+!!$         ! ... extremeties njs0,njs1
+!!$         ii = jpisd + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               usbnd(ii,jk,nibm,nitm) = usbnd(ii+1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$         ii = jpisf + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               usbnd(ii,jk,nibm,nitm) = usbnd(ii-1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$ 
+!!$         ! 1.2 normal velocity
+!!$         ! -------------------
+!!$ 
+!!$         !.. advance in time (time filter, array swap) 
+!!$         DO jk = 1, jpkm1
+!!$            DO ji = 1, jpi
+!!$         ! ... fields nitm2 <== nitm 
+!!$               vsbnd(ji,jk,nib  ,nitm2) = vsbnd(ji,jk,nib  ,nitm)*vsmsk(ji,jk)
+!!$               vsbnd(ji,jk,nibm ,nitm2) = vsbnd(ji,jk,nibm ,nitm)*vsmsk(ji,jk)
+!!$            END DO
+!!$         END DO
+!!$
+!!$         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO ji = 1, jpi
+!!$                  vsbnd(ji,jk,nib  ,nitm) = vsbnd(ji,jk,nib,  nit)*vsmsk(ji,jk)
+!!$                  vsbnd(ji,jk,nibm ,nitm) = vsbnd(ji,jk,nibm ,nit)*vsmsk(ji,jk)
+!!$                  vsbnd(ji,jk,nibm2,nitm) = vsbnd(ji,jk,nibm2,nit)*vsmsk(ji,jk)
+!!$         ! ... total or baroclinic velocity at b, bm and bm2
+!!$                  zvcb   = vn (ji,jj,jk)
+!!$                  zvcbm  = vn (ji,jj+1,jk)
+!!$                  zvcbm2 = vn (ji,jj+2,jk)
+!!$         ! ... fields nit <== now (kt+1) 
+!!$                  vsbnd(ji,jk,nib  ,nit) = zvcb   *vsmsk(ji,jk)
+!!$                  vsbnd(ji,jk,nibm ,nit) = zvcbm  *vsmsk(ji,jk)
+!!$                  vsbnd(ji,jk,nibm2,nit) = zvcbm2 *vsmsk(ji,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(vsbnd,jpisd,jpisf,jpjsob,jpk*3*3,1,jpi, numout )
+!!$
+!!$         ! ... extremeties njs0,njs1
+!!$         ii = jpisd + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               vsbnd(ii,jk,nibm,nitm) = vsbnd(ii+1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$         ii = jpisf + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               vsbnd(ii,jk,nibm,nitm) = vsbnd(ii-1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$
+!!$         ! 1.3 Temperature and salinity
+!!$         ! ----------------------------
+!!$
+!!$         ! ... advance in time (time filter, array swap)
+!!$         DO jk = 1, jpkm1
+!!$            DO ji = 1, jpi
+!!$         ! ... fields nitm <== nit  plus time filter at the boundary
+!!$               tsbnd(ji,jk,nib,nitm) = tsbnd(ji,jk,nib,nit)*tsmsk(ji,jk)
+!!$               ssbnd(ji,jk,nib,nitm) = ssbnd(ji,jk,nib,nit)*tsmsk(ji,jk)
+!!$            END DO
+!!$         END DO
+!!$
+!!$         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO ji = 1, jpi
+!!$                  tsbnd(ji,jk,nibm ,nitm) = tsbnd(ji,jk,nibm ,nit)*tsmsk(ji,jk)
+!!$                  ssbnd(ji,jk,nibm ,nitm) = ssbnd(ji,jk,nibm ,nit)*tsmsk(ji,jk)
+!!$         ! ... fields nit <== now (kt+1)
+!!$                  tsbnd(ji,jk,nib  ,nit) = tn(ji,jj   ,jk)*tsmsk(ji,jk)
+!!$                  tsbnd(ji,jk,nibm ,nit) = tn(ji,jj+1 ,jk)*tsmsk(ji,jk)
+!!$                  ssbnd(ji,jk,nib  ,nit) = sn(ji,jj   ,jk)*tsmsk(ji,jk)
+!!$                  ssbnd(ji,jk,nibm ,nit) = sn(ji,jj+1 ,jk)*tsmsk(ji,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(tsbnd,jpisd,jpisf,jpjsob,jpk*2*2,1,jpi, numout )
+!!$         IF( lk_mpp )   CALL mppobc(ssbnd,jpisd,jpisf,jpjsob,jpk*2*2,1,jpi, numout )
+!!$
+!!$         ! ... extremeties  njs0,njs1
+!!$         ii = jpisd + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               tsbnd(ii,jk,nibm,nitm) = tsbnd(ii+1,jk,nibm,nitm)
+!!$               ssbnd(ii,jk,nibm,nitm) = ssbnd(ii+1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$         ii = jpisf + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               tsbnd(ii,jk,nibm,nitm) = tsbnd(ii-1,jk,nibm,nitm)
+!!$               ssbnd(ii,jk,nibm,nitm) = ssbnd(ii-1,jk,nibm,nitm)
+!!$            END DO
+!!$         END IF
+!!$
+!!$      END IF     ! End of array swap
+!!$
+!!$      ! 2 - Calculation of radiation velocities
+!!$      ! ---------------------------------------
+!!$
+!!$      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
+!!$
+!!$         ! 2.1  Calculate the normal velocity based on phase velocity u_cysbnd
+!!$         ! -------------------------------------------------------------------
+!!$         !
+!!$         !          ji-row
+!!$         !            |
+!!$         ! nibm2 -----f-----   jpjsob +2
+!!$         !            |    
+!!$         !  nibm2 --  u  ----- jpjsob +2 
+!!$         !            |        
+!!$         !  nibm -----f-----   jpjsob +1
+!!$         !            |        
+!!$         !  nibm  --  u  ----- jpjsob +1
+!!$         !            |        
+!!$         !  nib  -----f-----   jpjsob
+!!$         !       /////|//////
+!!$         !  nib   ////u/////   jpjsob 
+!!$         !
+!!$         ! ... radiative condition plus Raymond-Kuo
+!!$         ! ... jpjsob,(jpisdp1, jpisfm1)
+!!$         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO ji = 2, jpim1
+!!$         ! ... 2* j-gradient of u (f-point i=nibm, time mean)
+!!$                  z2dx = (- usbnd(ji,jk,nibm ,nit) - usbnd(ji,jk,nibm ,nitm2) &
+!!$                          + 2.*usbnd(ji,jk,nibm2,nitm) ) / e2f(ji,jj+1)
+!!$         ! ... 2* i-gradient of u (u-point i=nibm, time nitm)
+!!$                  z2dy = ( usbnd(ji+1,jk,nibm,nitm) - usbnd(ji-1,jk,nibm,nitm) ) / e1u(ji, jj+1)
+!!$         ! ... square of the norm of grad(v)
+!!$                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+!!$                  IF( z4nor2 == 0.) THEN
+!!$                     z4nor2 = 0.000001
+!!$                  END IF
+!!$         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+!!$                  zdt = usbnd(ji,jk,nibm,nitm2) - usbnd(ji,jk,nibm,nit)
+!!$         ! ... i-phase speed ratio (bounded by -1) and save the unbounded phase
+!!$         !     velocity ratio no divided by e1f for the tracer radiation
+!!$                  z05cx = zdt * z2dx / z4nor2
+!!$                  u_cysbnd(ji,jk) = z05cx*usmsk(ji,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$         IF( lk_mpp )   CALL mppobc(u_cysbnd,jpisd,jpisf,jpjsob,jpk,1,jpi, numout )
+!!$
+!!$         ! ... extremeties  njs0,njs1
+!!$         ii = jpisd + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               u_cysbnd(ii,jk) = u_cysbnd(ii+1,jk)
+!!$            END DO
+!!$         END IF
+!!$         ii = jpisf + 1 - nimpp
+!!$         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+!!$            DO jk = 1, jpkm1
+!!$               u_cysbnd(ii,jk) = u_cysbnd(ii-1,jk)
+!!$            END DO
+!!$         END IF
+!!$
+!!$         ! 2.2 Calculate the normal velocity based on phase velocity v_cysbnd 
+!!$         ! -------------------------------------------------------------------
+!!$         !
+!!$         !               ji-row  ji-row
+!!$         !            |         |
+!!$         ! nibm2 -----f----v----f----  jpjsob+2
+!!$         !            |         |
+!!$         !  nibm   -  u -- T -- u ---- jpjsob+2
+!!$         !            |         |
+!!$         ! nibm  -----f----v----f----  jpjsob+1 
+!!$         !            |         |
+!!$         ! nib    --  u -- T -- u ---  jpjsob+1
+!!$         !            |         |
+!!$         ! nib   -----f----v----f----  jpjsob
+!!$         !       /////////////////////
+!!$         !
+!!$         ! ... Free surface formulation:
+!!$         ! ... radiative conditions on the total part + relaxation toward climatology
+!!$         ! ... jpjsob,(jpisdp1,jpisfm1)
+!!$         DO jj = fs_njs0, fs_njs1 ! Vector opt.
+!!$            DO jk = 1, jpkm1
+!!$               DO ji = 2, jpim1
+!!$         ! ... 2* gradj(v) (T-point i=nibm, time mean)
+!!$                  z2dx = ( - vsbnd(ji,jk,nibm ,nit) - vsbnd(ji,jk,nibm ,nitm2) &
+!!$                           + 2.*vsbnd(ji,jk,nibm2,nitm) ) / e2t(ji,jj+1)
+!!$         ! ... 2* gradi(v) (v-point i=nibm, time nitm)
+!!$                  z2dy = ( vsbnd(ji+1,jk,nibm,nitm) - vsbnd(ji-1,jk,nibm,nitm) ) / e1v(ji,jj+1)
+!!$         ! ... square of the norm of grad(u)
+!!$                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+!!$                  IF( z4nor2 == 0.) THEN
+!!$                     z4nor2 = 0.000001
+!!$                  END IF
+!!$         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+!!$                  zdt = vsbnd(ji,jk,nibm,nitm2) - vsbnd(ji,jk,nibm,nit)
+!!$         ! ... j-phase speed ratio (bounded by -1)
+!!$                  z05cx = zdt * z2dx / z4nor2
+!!$                  v_cysbnd(ji,jk)=z05cx*vsmsk(ji,jk)
+!!$               END DO
+!!$            END DO
+!!$         END DO
+!!$
+!!$      ENDIF
+!!$ 
+!!$   END SUBROUTINE obc_rad_south
+!!$
+!!$#else
    !!=================================================================================
    !!                       ***  MODULE  obcrad  ***
Index: anches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcrst.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcrst.F90	(revision 2796)
+++ 	(revision )
@@ -1,606 +1,0 @@
-MODULE obcrst
-#if defined key_obc
-   !!=================================================================================
-   !!                       ***  MODULE  obcrst  ***
-   !! Ocean dynamic :  Input/Output files for restart on OBC
-   !!=================================================================================
-
-   !!---------------------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE phycst          ! physical constants
-   USE obc_oce         ! ocean open boundary conditions
-   USE lib_mpp         ! for mppobc
-   USE in_out_manager  ! I/O manager
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   obc_rst_read    ! routine called by obc_ini
-   PUBLIC   obc_rst_write   ! routine called by step
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE obc_rst_write ( kt )
-      !!--------------------------------------------------------------------------------
-      !!                  ***  SUBROUTINE obc_rst_write  ***
-      !!                
-      !! ** Purpose :   Write open boundary restart fields in restart.obc.output file 
-      !!
-      !! ** Method  :   restart.obc.output file: Direct access non formatted file.
-      !!      Each nstock time step , save fields which are necessary for restart.
-      !!      - This routine is called if at least the key_obc is defined. It is called
-      !!        at the same time step than rstwrite.
-      !!      - First record holds OBC parameters nbobc,jpieob,jpiwob,jpjnob,jpjsob and 
-      !!        the OBC layout jpjed, jpjef ... for checking purposes.
-      !!      - Following records hold the boundary arrays, in the order east west north
-      !!        south, if they exist.
-      !!      - The writing is realised by vertical slab across the boundary, for bsf, u,
-      !!        v, t, and s boundary arrays. Each record hold a vertical slab.
-      !!      - For mpp, this allows each processor to write only the correct informations
-      !!        it hold. If a processor has no valid informations on boundary, it just 
-      !!        skip the writing part (automatically).
-      !!      - Special care is taken for dumping the starting point of a boundary (jpjed,
-      !!        jpjwd, jpind, jpisd) because of the general definition of nje0 njw0,nin0,
-      !!        nis0. This is done to avoid records to be written by 2 adjacent processors.
-      !!
-      !!  History :
-      !!         ! 97-11 (J.M. Molines) Original code
-      !!         ! 98-11 (J.M. Molines) Bug fix for adjacent processors
-      !!   8.5   ! 02-10 (C. Talandier, A-M. Treguier) F90
-      !!         ! 03-06 (J.M. Molines) Bug fix for adjacent processors
-      !!   9.0   ! 04-02 (G. Madec)  suppression of numwob, use inum
-      !!-----------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   inum               ! temporary logical unit
-      INTEGER ::   ibloc, nreclo, jrec, jt, jb 
-      INTEGER ::   jfoe, jfow, ifon, ifos
-      INTEGER ::   ino0, it0
-      !!-----------------------------------------------------------------------------
-
-      ! 1. Output of restart fields (inum)
-      ! ------------------------------------
- 
-      IF( ( mod(kt,nstock) == 0 ) .OR. ( kt == nitend ) ) THEN
-
-         ! 1.0 Initializations
-         ! -------------------
-         IF(lwp) THEN
-              WRITE(numout,*) ' '
-              WRITE(numout,*) 'obcrst: OBC output for restart with obc_rst_write routine'
-              WRITE(numout,*) '~~~~~~'
-              WRITE(numout,*) '        output done in restart.obc.output file at it= ', kt, ' date= ', ndastp
-         END IF
-
-         ino0 = no
-         it0  = kt
-         ibloc  = 4096*4
-         nreclo = ibloc*( ( ( 26 *jpk + 9 )*jpbyt -1)/ibloc + 1)
-         IF(lwp) WRITE(numout,*) '             '
-         IF(lwp) WRITE(numout,*) '        OBC restart file opened with nreclo = ',nreclo
-
-         ! 1.1 Open file
-         ! -------------
-
-         CALL ctl_opn( inum, 'restart.obc.output', 'UNKNOWN', 'UNFORMATTED', 'DIRECT', nreclo, numout, lwp )
- 
-         ! 1.2 Write header
-         ! ----------------
-         WRITE (inum,REC=1) ino0,it0,nbobc,jpieob,jpiwob,jpjnob,jpjsob,     &
-                              jpjed,jpjef,jpjwd,jpjwf,jpind,jpinf,jpisd,jpisf
-
-         ! 1.3 Write east boundary array if any.
-         ! -------------------------------------
-         IF( lp_obc_east ) THEN
-            IF( lfbceast ) THEN
-               IF(lwp) THEN
-                  WRITE(numout,*) ' '
-                  WRITE(numout,*) '        No restart file for the fixed east OBC'
-               END IF
-            ELSE
-               IF( jpieob /= 0 ) THEN
-                  IF( nje0+njmpp-1  == jpjed .AND. nie1 >= nie0 ) THEN
-            ! ... dump of jpjed if it is on this proc.
-                     jrec = 2
-                     jfoe = jpjed - njmpp + 1
-                     PRINT *,'Narea =',narea,' write jrec =2 east'
-                     WRITE(inum,REC=jrec)                                    &
-                           ((( uebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                           ((( vebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                           ((( tebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                           ((( sebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-                  ENDIF
-                  DO ji = nie0, nie1
-                     DO jj = nje0, nje1
-            ! ... only interested processors go through the following lines
-            !           jfoe = jj + njmpp -1
-                        jfoe = jj 
-                        jrec = 2 + jj + njmpp -1 -jpjed
-                        WRITE (inum,REC=jrec)                                   &
-                              ((( uebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                              ((( vebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                              ((( tebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                              ((( sebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-                     END DO
-                  END DO
-               END IF
-            END IF
-         END IF
- 
-         ! 1.4 Write west boundary arrays if any
-         ! -------------------------------------
-         IF( lp_obc_west ) THEN
-            IF( lfbcwest ) THEN
-               IF(lwp) THEN
-                  WRITE(numout,*) ' '
-                  WRITE(numout,*) '        No restart file for the fixed west OBC'
-               END IF
-            ELSE
-               IF( jpiwob /= 0 ) THEN
-                  IF( njw0+njmpp+1 == jpjwd .AND. niw1 >= niw0 ) THEN
-            ! ... dump of jpjwd if it is on this proc.
-                     jrec = 3 + jpjef - jpjed
-            !        jfow = jpjwd
-                     jfow = jpjwd -njmpp + 1
-                     PRINT *,'Narea =',narea,' write jrec =',jrec,' west'
-                     WRITE (inum,REC=jrec)                                   &
-                           ((( uwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                           ((( vwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                           ((( twbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                           ((( swbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-                  END IF
-                  DO ji = niw0, niw1
-                     DO jj = njw0, njw1
-            ! ... only interested processors go through the following lines
-            !           jfow = jj + njmpp -1
-                        jfow = jj 
-                        jrec = 3 + jpjef -jpjed + jj + njmpp -1 -jpjwd
-                        WRITE (inum,REC=jrec)                                   &
-                              ((( uwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                              ((( vwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                              ((( twbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                              ((( swbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-                     END DO
-                  END DO
-               END IF
-            END IF
-         END IF
- 
-         ! 1.5 Write north boundary arrays if any
-         ! --------------------------------------
-         IF( lp_obc_north ) THEN
-            IF( lfbcnorth ) THEN
-               IF(lwp) THEN
-                  WRITE(numout,*) ' '
-                  WRITE(numout,*) '        No restart file for the fixed north OBC'
-               END IF
-            ELSE
-               IF( jpjnob /= 0) THEN
-                  IF( nin0+nimpp-1 == jpind .AND. njn1 >= njn0 ) THEN
-            ! ... dump of jpind if it is on this proc.
-                     jrec = 4 + jpjef -jpjed + jpjwf -jpjwd
-            !        ifon = jpind
-                     ifon = jpind -nimpp +1
-                     WRITE (inum,REC=jrec)                                   &
-                           ((( unbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                           ((( vnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                           ((( tnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                           ((( snbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-                  END IF
-                  DO jj = njn0, njn1
-                     DO ji = nin0, nin1
-            ! ... only interested processors go through the following lines
-            !           ifon = ji + nimpp -1
-                        ifon = ji 
-                        jrec = 4 + jpjef -jpjed + jpjwf -jpjwd +ji + nimpp -1  -jpind
-                        WRITE (inum,REC=jrec)                                   &
-                              ((( unbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                              ((( vnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                              ((( tnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                              ((( snbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-                     END DO
-                  END DO
-               END IF
-            END IF
-         END IF
- 
-         ! 1.6 Write south boundary arrays if any
-         ! --------------------------------------
-         IF( lp_obc_south ) THEN
-            IF( lfbcsouth ) THEN
-               IF(lwp) THEN
-                  WRITE(numout,*) ' '
-                  WRITE(numout,*) '        No restart file for the fixed south OBC'
-                  WRITE(numout,*) ' '
-               END IF
-            ELSE
-               IF( jpjsob /= 0 ) THEN
-                  IF( nis0+nimpp-1 == jpisd .AND. njs1 >= njs0 ) THEN
-            ! ... dump of jpisd if it is on this proc.
-                     jrec = 5 + jpjef -jpjed + jpjwf -jpjwd +jpinf -jpind
-            !        ifos = jpisd
-                     ifos = jpisd -nimpp + 1
-                     WRITE (inum,REC=jrec)                                   &
-                           ((( usbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                           ((( vsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                           ((( tsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                           ((( ssbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-                  END IF
-                  DO jj = njs0, njs1
-                     DO ji = nis0, nis1
-            ! ... only interested processors go through the following lines
-            !           ifos = ji + nimpp -1
-                        ifos = ji 
-                        jrec = 5 + jpjef -jpjed + jpjwf -jpjwd +jpinf -jpind + &
-                              ji + nimpp -1 -jpisd
-                        WRITE (inum,REC=jrec) &
-                              ((( usbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                              ((( vsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                              ((( tsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                              ((( ssbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-                     END DO
-                  END DO
-               END IF
-            END IF
-         END IF
-      CLOSE(inum)
-      END IF
-
-   END SUBROUTINE obc_rst_write
-
-
-   SUBROUTINE obc_rst_read
-      !!----------------------------------------------------------------------------
-      !!                   ***  SUBROUTINE obc_rst_read  ***
-      !!                   
-      !! ** Purpose :   Read files for restart at open boundaries
-      !!
-      !! ** Method  :   Read the previous boundary arrays on unit inum
-      !!      The first record indicates previous characterics
-      !!
-      !! History :
-      !!        ! 97-11 (J.M. Molines) Original code
-      !!   8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
-      !!----------------------------------------------------------------------------
-      !! * Local declarations
-      INTEGER ::   inum = 11            ! temporary logical unit
-      INTEGER ::   ji,jj,jk
-      INTEGER ::   ino0,it0,nbobc0,jpieob0,jpiwob0,jpjnob0,jpjsob0
-      INTEGER ::   ino1,it1,nbobc1,jpieob1,jpiwob1,jpjnob1,jpjsob1
-      INTEGER ::   ied0,ief0,iwd0,iwf0,ind0,inf0,isd0,isf0
-      INTEGER ::   ied1,ief1,iwd1,iwf1,ind1,inf1,isd1,isf1
-      INTEGER ::   ibloc, nreclo, jrec, jt, jb
-      INTEGER ::   jfoe, jfow, ifon, ifos
-      !!-----------------------------------------------------------------------------
-
-      ! 0. Initialisations
-      ! ------------------
- 
-      ino0    = no
-      it0     = nit000
-      nbobc0  = nbobc
-      jpieob0 = jpieob
-      jpiwob0 = jpiwob
-      jpjnob0 = jpjnob
-      jpjsob0 = jpjsob
- 
-      ied0   = jpjed
-      ief0   = jpjef
-      iwd0   = jpjwd
-      iwf0   = jpjwf
-      ind0   = jpind
-      inf0   = jpinf
-      isd0   = jpisd
-      isf0   = jpisf
- 
-      ibloc  = 4096*4
-      nreclo = ibloc *( ( ( 26 *jpk + 9 )*jpbyt -1)/ibloc + 1)
- 
-      IF(lwp) THEN
-         WRITE(numout,*) 'obcrst: beginning of restart with obc_rst_read routine'
-         WRITE(numout,*) '~~~~~~'
-         WRITE(numout,*) ' '
-         WRITE(numout,*) '        The present run :'
-         WRITE(numout,*) '        number job is  : ',no 
-         WRITE(numout,*) '        with the time nit000 : ',nit000
-         WRITE(numout,*) '        OBC restart file opened with nreclo = ',nreclo 
-      END IF
- 
-      ! 0.1 Open files
-      ! ---------------
-      CALL ctl_opn( inum, 'restart.obc', 'UNKNOWN', 'UNFORMATTED', 'DIRECT', nreclo, numout, lwp )
-
-      ! 1. Read
-      ! -------
- 
-      ! 1.1 First record
-      ! -----------------
-      READ(inum,REC=1) ino1,it1,nbobc1,jpieob1,jpiwob1,jpjnob1,     &
-                         jpjsob1,ied1,ief1,iwd1,iwf1,ind1,inf1,isd1,isf1
- 
-      IF(lwp) THEN
-         WRITE(numout,*) ' '
-         WRITE(numout,*) '        READ inum with number job : ',ino1,' with the time it: ',it1
-         WRITE(numout,*) ' '
-      END IF
- 
-      ! 1.2 Control of date
-      ! --------------------
-      IF( ( it0-it1 ) /= 1 .AND. abs(nrstdt) == 1 ) THEN
-          CALL ctl_stop( '        ===>>>> : problem with nit000 for the restart',   &
-               &         '        ==============',   &
-               &         '        we stop in obc_rst_read routine. Verify the file or rerun with the value',   &
-               &         '        0 for the control of time parameter nrstdt' )
-             
-      END IF
- 
-      ! 1.3 Control of number of open boundaries
-      ! ----------------------------------------
-      IF( nbobc1 /= nbobc0 ) THEN
-         IF(lwp) THEN
-            WRITE(numout,*) '        ===> W A R N I N G: The number of OBC have changed:'
-            WRITE(numout,*) '        Last run : ',nbobc0,' obcs'
-            WRITE(numout,*) '        This run : ',nbobc1,' obcs'
-         END IF
-      END IF
- 
-      ! 1.4 Control of which boundary is open
-      ! -------------------------------------
-      IF( lp_obc_east .AND. ( jpieob1 /= 0 ) ) THEN
-         IF(lwp) THEN
-            WRITE(numout,*) '         '
-            WRITE(numout,*) '        East open boundary'
-            IF( jpieob0 /= jpieob1 ) CALL ctl_stop( '         ==>>>> : Problem in obc_rst_read, jpieob have changed' )
-         END IF
-      END IF
- 
-      IF( lp_obc_west .AND. ( jpiwob1 /= 0 ) ) THEN
-         IF(lwp) THEN
-            WRITE(numout,*) '         '
-            WRITE(numout,*) '        West open boundary'
-            IF( jpiwob0 /= jpiwob1 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_read, jpiwob has changed' )
-         END IF
-      END IF
- 
-      IF( lp_obc_north .AND. ( jpjnob1 /= 0 ) ) THEN
-         IF(lwp) THEN
-            WRITE(numout,*) '         '
-            WRITE(numout,*) '        North open boundary'
-            IF( jpjnob0 /= jpjnob1 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_read, jpjnob has changed' )
-         END IF
-      END IF
- 
-      IF( lp_obc_south .AND. ( jpjsob1 /= 0 ) ) THEN
-         IF(lwp) THEN
-            WRITE(numout,*) '         '
-            WRITE(numout,*) '        South open boundary'
-            IF( jpjsob0 /= jpjsob1) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_read, jpjsob has changed' )
-         END IF
-      END IF
- 
- 
-      ! 1.5 Control of the limit of the boundaries
-      ! ------------------------------------------
-      IF( lp_obc_east .AND. ( jpieob1 /= 0 ) ) THEN
-         IF( ied1 /= ied0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_read, jpjed has changed' )
-         IF( ief1 /= ief0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_read, jpjef has changed' )
-      END IF
-
-      IF( lp_obc_west .AND. ( jpiwob1 /= 0 ) ) THEN
-         IF( iwd1 /= iwd0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_read, jpjwd has changed' )
-         IF( iwf1 /= iwf0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_read, jpjwf has changed' )
-      END IF
- 
-      IF( lp_obc_north .AND. ( jpjnob1 /= 0 ) ) THEN
-         IF( ind1 /= ind0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_read, jpind has changed' )
-         IF( inf1 /= inf0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_read, jpinf has changed' )
-      END IF
- 
-      IF( lp_obc_south .AND. ( jpjsob1 /= 0 ) ) THEN
-         IF( isd1 /= isd0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_read, jpisd has changed' )
-         IF( isf1 /= isf0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_read, jpisf has changed' )
-      END IF
- 
- 
-      ! 2. Now read the boundary arrays
-      ! -------------------------------
- 
-      ! 2.1 Read east boundary array if any.
-      ! ------------------------------------
-      IF( lp_obc_east ) THEN
-         IF( jpieob1 /= 0) THEN
-            IF( nje0+njmpp-1 == jpjed .AND. nie1 >= nie0 ) THEN
-      ! ... read of jpjed if it is on this proc.
-               jrec = 2
-      !        jfoe = jpjed
-               jfoe = jpjed -njmpp + 1
-               READ (inum,REC=jrec)                                   &
-                    ((( uebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                    ((( vebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                    ((( tebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                    ((( sebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-            END IF
-            DO ji = nie0, nie1
-               DO jj = nje0, nje1
-      ! ... only interested processors go through the following lines
-      !           jfoe = jj + njmpp -1
-                  jfoe = jj 
-                  jrec = 2 + jj + njmpp -1 -jpjed
-                  READ (inum,REC=jrec)                                   &
-                       ((( uebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                       ((( vebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                       ((( tebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                       ((( sebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-               END DO
-            END DO
-
-         ELSE
-
-            !  lp_obc_east was not TRUE previously
-         END IF
-
-      END IF
- 
-      ! 2.2 Read west boundary arrays if any.
-      ! -------------------------------------
-      IF( lp_obc_west ) THEN
-         IF( jpiwob1 /= 0) THEN
-            IF( njw0+njmpp-1 == jpjwd .AND. niw1 >= niw0 ) THEN
-      ! ... read of jpjwd if it is on this proc.
-               jrec = 3 + jpjef - jpjed
-      !        jfow = jpjwd
-               jfow = jpjwd -njmpp + 1
-               READ (inum,REC=jrec)                                   &
-                    ((( uwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                    ((( vwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                    ((( twbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                    ((( swbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-            END IF
-            DO ji = niw0, niw1
-               DO jj = njw0, njw1
-      ! ... only interested processors go through the following lines
-      !           jfow = jj + njmpp -1
-                  jfow = jj 
-                  jrec = 3 + jpjef -jpjed + jj + njmpp -1 -jpjwd
-                  READ (inum,REC=jrec)                                   &
-                       ((( uwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                       ((( vwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                       ((( twbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                       ((( swbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-               END DO
-            END DO
-
-         ELSE
-
-            !  lp_obc_west was not TRUE previously
-         END IF
-
-      END IF
- 
-      ! 2.3 Read north boundary arrays if any.
-      ! --------------------------------------
-      IF( lp_obc_north ) THEN
-         IF( jpjnob1 /= 0) THEN
-            IF( nin0+nimpp-1 == jpind .AND. njn1 >= njn0 ) THEN
-      ! ... read of jpind if it is on this proc.
-               jrec = 4 + jpjef -jpjed + jpjwf -jpjwd
-      !        ifon = jpind
-               ifon = jpind -nimpp +1
-               READ (inum,REC=jrec)                                   &
-                    ((( unbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                    ((( vnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                    ((( tnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), & 
-                    ((( snbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-            END IF
-            DO jj = njn0, njn1
-               DO ji = nin0, nin1
-      ! ... only interested processors go through the following lines
-      !           ifon = ji + nimpp -1
-                  ifon = ji 
-                  jrec = 4 + jpjef -jpjed + jpjwf -jpjwd +ji + nimpp -1  -jpind
-                  READ (inum,REC=jrec)                                   & 
-                       ((( unbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                       ((( vnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                       ((( tnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                       ((( snbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-               END DO
-            END DO
-
-         ELSE
-
-           !  lp_obc_north was not TRUE previously
-         END IF
-
-      END IF
- 
-      ! 2.4 Read south boundary arrays if any.
-      ! -------------------------------------
-      IF( lp_obc_south ) THEN
-         IF( jpjsob1 /= 0) THEN
-            IF( nis0+nimpp-1 == jpisd .AND. njs1 >= njs0 ) THEN
-      ! ... read of jpisd if it is on this proc.
-               jrec = 5 + jpjef -jpjed + jpjwf -jpjwd +jpinf -jpind
-      !        ifos = jpisd
-               ifos = jpisd -nimpp + 1
-               READ (inum,REC=jrec)                                   &
-                    ((( usbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                    ((( vsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                    ((( tsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                    ((( ssbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-            END IF
-            DO jj = njs0, njs1
-               DO ji = nis0, nis1
-      ! ... only interested processors go through the following lines
-      !           ifos = ji + nimpp -1
-                  ifos = ji 
-                  jrec = 5 + jpjef -jpjed + jpjwf -jpjwd +jpinf -jpind +  &
-                        ji + nimpp -1 -jpisd
-                  READ (inum,REC=jrec)                                   & 
-                       ((( usbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                       ((( vsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
-                       ((( tsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
-                       ((( ssbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
-               END DO
-            END DO
-         ELSE
-            !  lp_obc_south was not TRUE previously
-         END IF
-
-      END IF
-      CLOSE(inum)
-
-      IF( lk_mpp ) THEN
-         IF( lp_obc_east ) THEN
-            CALL mppobc(uebnd,jpjed,jpjef,jpieob  ,jpk*3*3,2,jpj, numout )
-            CALL mppobc(vebnd,jpjed,jpjef,jpieob+1,jpk*3*3,2,jpj, numout )
-            CALL mppobc(tebnd,jpjed,jpjef,jpieob+1,jpk*2*2,2,jpj, numout )
-            CALL mppobc(sebnd,jpjed,jpjef,jpieob+1,jpk*2*2,2,jpj, numout )
-         ENDIF
-         IF( lp_obc_west ) THEN
-            CALL mppobc(uwbnd,jpjwd,jpjwf,jpiwob,jpk*3*3,2,jpj, numout )
-            CALL mppobc(vwbnd,jpjwd,jpjwf,jpiwob,jpk*3*3,2,jpj, numout )
-            CALL mppobc(twbnd,jpjwd,jpjwf,jpiwob,jpk*2*2,2,jpj, numout )
-            CALL mppobc(swbnd,jpjwd,jpjwf,jpiwob,jpk*2*2,2,jpj, numout )
-         ENDIF
-         IF( lp_obc_north ) THEN 
-            CALL mppobc(unbnd,jpind,jpinf,jpjnob+1,jpk*3*3,1,jpi, numout )
-            CALL mppobc(vnbnd,jpind,jpinf,jpjnob  ,jpk*3*3,1,jpi, numout )
-            CALL mppobc(tnbnd,jpind,jpinf,jpjnob+1,jpk*2*2,1,jpi, numout )
-            CALL mppobc(snbnd,jpind,jpinf,jpjnob+1,jpk*2*2,1,jpi, numout )
-         ENDIF
-         IF( lp_obc_south ) THEN
-            CALL mppobc(usbnd,jpisd,jpisf,jpjsob,jpk*3*3,1,jpi, numout )
-            CALL mppobc(vsbnd,jpisd,jpisf,jpjsob,jpk*3*3,1,jpi, numout )
-            CALL mppobc(tsbnd,jpisd,jpisf,jpjsob,jpk*2*2,1,jpi, numout )
-            CALL mppobc(ssbnd,jpisd,jpisf,jpjsob,jpk*2*2,1,jpi, numout )
-         ENDIF
-      ENDIF
- 
-   END SUBROUTINE obc_rst_read
-#else
-   !!=================================================================================
-   !!                       ***  MODULE  obcrst  ***
-   !! Ocean dynamic :  Input/Output files for restart on OBC
-   !!=================================================================================
-CONTAINS
-   SUBROUTINE obc_rst_write( kt )           !  No Open boundary ==> empty routine
-      INTEGER,INTENT(in) :: kt
-      WRITE(*,*) 'obc_rst_write: You should not have seen this print! error?', kt
-   END SUBROUTINE obc_rst_write
-   SUBROUTINE obc_rst_read                 !  No Open boundary ==> empty routine
-   END SUBROUTINE obc_rst_read
-#endif
-
-   !!=================================================================================
-END MODULE obcrst
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obctides.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obctides.F90	(revision 2797)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obctides.F90	(revision 2797)
@@ -0,0 +1,735 @@
+MODULE obctides
+   !!======================================================================
+   !!                       ***  MODULE  obctides  ***
+   !! Ocean dynamics:   Tidal forcing at open boundaries
+   !!======================================================================
+   !! History :  2.0  !  2007-01  (D.Storkey)  Original code
+   !!            2.3  !  2008-01  (J.Holt)  Add date correction. Origins POLCOMS v6.3 2007
+   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
+   !!            3.3  !  2010-09  (D.Storkey and E.O'Dea)  bug fixes
+   !!----------------------------------------------------------------------
+#if defined key_obc
+!!$   !!----------------------------------------------------------------------
+!!$   !!   'key_obc'     Unstructured Open Boundary Condition
+!!$   !!----------------------------------------------------------------------
+!!$   !!   PUBLIC
+!!$   !!      tide_init     : read of namelist
+!!$   !!      tide_data     : read in and initialisation of tidal constituents at boundary
+!!$   !!      tide_update   : calculation of tidal forcing at each timestep
+!!$   !!   PRIVATE
+!!$   !!      uvset         :\
+!!$   !!      vday          : | Routines to correct tidal harmonics forcing for
+!!$   !!      shpen         : | start time of integration
+!!$   !!      ufset         : |
+!!$   !!      vset          :/
+!!$   !!----------------------------------------------------------------------
+!!$   USE oce             ! ocean dynamics and tracers 
+!!$   USE dom_oce         ! ocean space and time domain
+!!$   USE iom
+!!$   USE in_out_manager  ! I/O units
+!!$   USE phycst          ! physical constants
+!!$   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+!!$   USE obc_par         ! Unstructured boundary parameters
+!!$   USE obc_oce         ! ocean open boundary conditions
+!!$   USE daymod          ! calendar
+!!$
+!!$   IMPLICIT NONE
+!!$   PRIVATE
+!!$
+!!$   PUBLIC   tide_init     ! routine called in obcini
+!!$   PUBLIC   tide_data     ! routine called in obcini
+!!$   PUBLIC   tide_update   ! routine called in obcdyn
+!!$
+!!$   LOGICAL, PUBLIC            ::   ln_tide_date          !: =T correct tide phases and amplitude for model start date
+!!$   INTEGER, PUBLIC, PARAMETER ::   jptides_max = 15      !: Max number of tidal contituents
+!!$   INTEGER, PUBLIC            ::   ntide                 !: Actual number of tidal constituents
+!!$
+!!$   CHARACTER(len=80), PUBLIC                         ::   filtide    !: Filename root for tidal input files
+!!$   CHARACTER(len= 4), PUBLIC, DIMENSION(jptides_max) ::   tide_cpt   !: Names of tidal components used.
+!!$
+!!$   INTEGER , PUBLIC, DIMENSION(jptides_max) ::   nindx        !: ???
+!!$   REAL(wp), PUBLIC, DIMENSION(jptides_max) ::   tide_speed   !: Phase speed of tidal constituent (deg/hr)
+!!$   
+!!$   REAL(wp), DIMENSION(jpbdim,jptides_max)  ::   ssh1, ssh2   ! Tidal constituents : SSH
+!!$   REAL(wp), DIMENSION(jpbdim,jptides_max)  ::   u1  , u2     ! Tidal constituents : U
+!!$   REAL(wp), DIMENSION(jpbdim,jptides_max)  ::   v1  , v2     ! Tidal constituents : V
+!!$   
+!!$   !!----------------------------------------------------------------------
+!!$   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+!!$   !! $Id: obctides.F90 2528 2010-12-27 17:33:53Z rblod $ 
+!!$   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+!!$   !!----------------------------------------------------------------------
+!!$CONTAINS
+!!$
+!!$   SUBROUTINE tide_init
+!!$      !!----------------------------------------------------------------------
+!!$      !!                    ***  SUBROUTINE tide_init  ***
+!!$      !!                     
+!!$      !! ** Purpose : - Read in namelist for tides
+!!$      !!
+!!$      !!----------------------------------------------------------------------
+!!$      INTEGER ::   itide                  ! dummy loop index 
+!!$      !!
+!!$      NAMELIST/namobc_tide/ln_tide_date, filtide, tide_cpt, tide_speed
+!!$      !!----------------------------------------------------------------------
+!!$
+!!$      IF(lwp) WRITE(numout,*)
+!!$      IF(lwp) WRITE(numout,*) 'tide_init : initialization of tidal harmonic forcing at open boundaries'
+!!$      IF(lwp) WRITE(numout,*) '~~~~~~~~~'
+!!$
+!!$      ! Namelist namobc_tide : tidal harmonic forcing at open boundaries
+!!$      ln_tide_date = .false.
+!!$      filtide(:) = ''
+!!$      tide_speed(:) = 0.0
+!!$      tide_cpt(:) = ''
+!!$      REWIND( numnam )                                ! Read namelist parameters
+!!$      READ  ( numnam, namobc_tide )
+!!$      !                                               ! Count number of components specified
+!!$      ntide = jptides_max
+!!$      DO itide = 1, jptides_max
+!!$        IF( tide_cpt(itide) == '' ) THEN
+!!$           ntide = itide-1
+!!$           exit
+!!$        ENDIF
+!!$      END DO
+!!$
+!!$      !                                               ! find constituents in standard list
+!!$      DO itide = 1, ntide
+!!$         nindx(itide) = 0
+!!$         IF( TRIM( tide_cpt(itide) ) == 'Q1'  )   nindx(itide) =  1
+!!$         IF( TRIM( tide_cpt(itide) ) == 'O1'  )   nindx(itide) =  2
+!!$         IF( TRIM( tide_cpt(itide) ) == 'P1'  )   nindx(itide) =  3
+!!$         IF( TRIM( tide_cpt(itide) ) == 'S1'  )   nindx(itide) =  4
+!!$         IF( TRIM( tide_cpt(itide) ) == 'K1'  )   nindx(itide) =  5
+!!$         IF( TRIM( tide_cpt(itide) ) == '2N2' )   nindx(itide) =  6
+!!$         IF( TRIM( tide_cpt(itide) ) == 'MU2' )   nindx(itide) =  7
+!!$         IF( TRIM( tide_cpt(itide) ) == 'N2'  )   nindx(itide) =  8
+!!$         IF( TRIM( tide_cpt(itide) ) == 'NU2' )   nindx(itide) =  9
+!!$         IF( TRIM( tide_cpt(itide) ) == 'M2'  )   nindx(itide) = 10
+!!$         IF( TRIM( tide_cpt(itide) ) == 'L2'  )   nindx(itide) = 11
+!!$         IF( TRIM( tide_cpt(itide) ) == 'T2'  )   nindx(itide) = 12
+!!$         IF( TRIM( tide_cpt(itide) ) == 'S2'  )   nindx(itide) = 13
+!!$         IF( TRIM( tide_cpt(itide) ) == 'K2'  )   nindx(itide) = 14
+!!$         IF( TRIM( tide_cpt(itide) ) == 'M4'  )   nindx(itide) = 15
+!!$         IF( nindx(itide) == 0  .AND. lwp ) THEN
+!!$            WRITE(ctmp1,*) 'constitunent', itide,':', tide_cpt(itide), 'not in standard list'
+!!$            CALL ctl_warn( ctmp1 )
+!!$         ENDIF
+!!$      END DO
+!!$      !                                               ! Parameter control and print
+!!$      IF( ntide < 1 ) THEN 
+!!$         CALL ctl_stop( '          Did not find any tidal components in namelist namobc_tide' )
+!!$      ELSE
+!!$         IF(lwp) WRITE(numout,*) '          Namelist namobc_tide : tidal harmonic forcing at open boundaries'
+!!$         IF(lwp) WRITE(numout,*) '             tidal components specified ', ntide
+!!$         IF(lwp) WRITE(numout,*) '                ', tide_cpt(1:ntide)
+!!$         IF(lwp) WRITE(numout,*) '             associated phase speeds (deg/hr) : '
+!!$         IF(lwp) WRITE(numout,*) '                ', tide_speed(1:ntide)
+!!$      ENDIF
+!!$
+!!$      ! Initialisation of tidal harmonics arrays
+!!$      sshtide(:) = 0.e0
+!!$      utide  (:) = 0.e0
+!!$      vtide  (:) = 0.e0
+!!$      !
+!!$   END SUBROUTINE tide_init
+!!$
+!!$
+!!$   SUBROUTINE tide_data
+!!$      !!----------------------------------------------------------------------
+!!$      !!                    ***  SUBROUTINE tide_data  ***
+!!$      !!                    
+!!$      !! ** Purpose : - Read in tidal harmonics data and adjust for the start 
+!!$      !!                time of the model run. 
+!!$      !!
+!!$      !!----------------------------------------------------------------------
+!!$      INTEGER ::   itide, igrd, ib        ! dummy loop indices
+!!$      CHARACTER(len=80) :: clfile         ! full file name for tidal input file 
+!!$      INTEGER ::   ipi, ipj, inum, idvar  ! temporary integers (netcdf read)
+!!$      INTEGER, DIMENSION(6) :: lendta=0   ! length of data in the file (note may be different from nblendta!)
+!!$      REAL(wp) ::  z_arg, z_atde, z_btde, z1t, z2t           
+!!$      REAL(wp), DIMENSION(jpbdta,1) ::   zdta   ! temporary array for data fields
+!!$      REAL(wp), DIMENSION(jptides_max) :: z_vplu, z_ftc
+!!$      !!------------------------------------------------------------------------------
+!!$
+!!$      ! Open files and read in tidal forcing data
+!!$      ! -----------------------------------------
+!!$
+!!$      ipj = 1
+!!$
+!!$      DO itide = 1, ntide
+!!$         !                                                              ! SSH fields
+!!$         clfile = TRIM(filtide)//TRIM(tide_cpt(itide))//'_grid_T.nc'
+!!$         IF(lwp) WRITE(numout,*) 'Reading data from file ', clfile
+!!$         CALL iom_open( clfile, inum )
+!!$         igrd = 4
+!!$         IF( nblendta(igrd) <= 0 ) THEN 
+!!$            idvar = iom_varid( inum,'z1' )
+!!$            IF(lwp) WRITE(numout,*) 'iom_file(1)%ndims(idvar) : ',iom_file%ndims(idvar)
+!!$            nblendta(igrd) = iom_file(inum)%dimsz(1,idvar)
+!!$            WRITE(numout,*) 'Dim size for z1 is ', nblendta(igrd)
+!!$         ENDIF
+!!$         ipi = nblendta(igrd)
+!!$         CALL iom_get( inum, jpdom_unknown, 'z1', zdta(1:ipi,1:ipj) )
+!!$         DO ib = 1, nblenrim(igrd)
+!!$            ssh1(ib,itide) = zdta(nbmap(ib,igrd),1)
+!!$         END DO
+!!$         CALL iom_get( inum, jpdom_unknown, 'z2', zdta(1:ipi,1:ipj) )
+!!$         DO ib = 1, nblenrim(igrd)
+!!$            ssh2(ib,itide) = zdta(nbmap(ib,igrd),1)
+!!$         END DO
+!!$         CALL iom_close( inum )
+!!$         !
+!!$         !                                                              ! U fields
+!!$         clfile = TRIM(filtide)//TRIM(tide_cpt(itide))//'_grid_U.nc'
+!!$         IF(lwp) WRITE(numout,*) 'Reading data from file ', clfile
+!!$         CALL iom_open( clfile, inum )
+!!$         igrd = 5
+!!$         IF( lendta(igrd) <= 0 ) THEN 
+!!$            idvar = iom_varid( inum,'u1' )
+!!$            lendta(igrd) = iom_file(inum)%dimsz(1,idvar)
+!!$            WRITE(numout,*) 'Dim size for u1 is ',lendta(igrd)
+!!$         ENDIF
+!!$         ipi = lendta(igrd)
+!!$         CALL iom_get( inum, jpdom_unknown, 'u1', zdta(1:ipi,1:ipj) )
+!!$         DO ib = 1, nblenrim(igrd)
+!!$            u1(ib,itide) = zdta(nbmap(ib,igrd),1)
+!!$         END DO
+!!$         CALL iom_get( inum, jpdom_unknown, 'u2', zdta(1:ipi,1:ipj) )
+!!$         DO ib = 1, nblenrim(igrd)
+!!$            u2(ib,itide) = zdta(nbmap(ib,igrd),1)
+!!$         END DO
+!!$         CALL iom_close( inum )
+!!$         !
+!!$         !                                                              ! V fields
+!!$         clfile = TRIM(filtide)//TRIM(tide_cpt(itide))//'_grid_V.nc'
+!!$         if(lwp) write(numout,*) 'Reading data from file ', clfile
+!!$         CALL iom_open( clfile, inum )
+!!$         igrd = 6
+!!$         IF( lendta(igrd) <= 0 ) THEN 
+!!$            idvar = iom_varid( inum,'v1' )
+!!$            lendta(igrd) = iom_file(inum)%dimsz(1,idvar)
+!!$            WRITE(numout,*) 'Dim size for v1 is ', lendta(igrd)
+!!$         ENDIF
+!!$         ipi = lendta(igrd)
+!!$         CALL iom_get( inum, jpdom_unknown, 'v1', zdta(1:ipi,1:ipj) )
+!!$         DO ib = 1, nblenrim(igrd)
+!!$            v1(ib,itide) = zdta(nbmap(ib,igrd),1)
+!!$         END DO
+!!$         CALL iom_get( inum, jpdom_unknown, 'v2', zdta(1:ipi,1:ipj) )
+!!$         DO ib=1, nblenrim(igrd)
+!!$            v2(ib,itide) = zdta(nbmap(ib,igrd),1)
+!!$         END DO
+!!$         CALL iom_close( inum )
+!!$         !
+!!$      END DO ! end loop on tidal components
+!!$
+!!$      IF( ln_tide_date ) THEN      ! correct for date factors
+!!$
+!!$!! used nmonth, nyear and nday from daymod....
+!!$         ! Calculate date corrects for 15 standard consituents
+!!$         ! This is the initialisation step, so nday, nmonth, nyear are the 
+!!$         ! initial date/time of the integration.
+!!$           print *, nday,nmonth,nyear
+!!$           nyear  = int(ndate0 / 10000  )                           ! initial year
+!!$           nmonth = int((ndate0 - nyear * 10000 ) / 100 )          ! initial month
+!!$           nday   = int(ndate0 - nyear * 10000 - nmonth * 100)
+!!$
+!!$         CALL uvset( 0, nday, nmonth, nyear, z_ftc, z_vplu )
+!!$
+!!$         IF(lwp) WRITE(numout,*) 'Correcting tide for date:', nday, nmonth, nyear
+!!$
+!!$         DO itide = 1, ntide       ! loop on tidal components
+!!$            !
+!!$            IF( nindx(itide) /= 0 ) THEN
+!!$!!gm use rpi  and rad global variable  
+!!$               z_arg = 3.14159265d0 * z_vplu(nindx(itide)) / 180.0d0
+!!$               z_atde=z_ftc(nindx(itide))*cos(z_arg)
+!!$               z_btde=z_ftc(nindx(itide))*sin(z_arg)
+!!$               IF(lwp) WRITE(numout,'(2i5,8f10.6)') itide, nindx(itide), tide_speed(itide),   &
+!!$                  &                                 z_ftc(nindx(itide)), z_vplu(nindx(itide))
+!!$            ELSE
+!!$               z_atde = 1.0_wp
+!!$               z_btde = 0.0_wp
+!!$            ENDIF
+!!$            !                                         !  elevation         
+!!$            igrd = 4
+!!$            DO ib = 1, nblenrim(igrd)                
+!!$               z1t = z_atde * ssh1(ib,itide) + z_btde * ssh2(ib,itide)
+!!$               z2t = z_atde * ssh2(ib,itide) - z_btde * ssh1(ib,itide)
+!!$               ssh1(ib,itide) = z1t
+!!$               ssh2(ib,itide) = z2t
+!!$            END DO
+!!$            !                                         !  u       
+!!$            igrd = 5
+!!$            DO ib = 1, nblenrim(igrd)                
+!!$               z1t = z_atde * u1(ib,itide) + z_btde * u2(ib,itide)
+!!$               z2t = z_atde * u2(ib,itide) - z_btde * u1(ib,itide)
+!!$               u1(ib,itide) = z1t
+!!$               u2(ib,itide) = z2t
+!!$            END DO
+!!$            !                                         !  v       
+!!$            igrd = 6
+!!$            DO ib = 1, nblenrim(igrd)                
+!!$               z1t = z_atde * v1(ib,itide) + z_btde * v2(ib,itide)
+!!$               z2t = z_atde * v2(ib,itide) - z_btde * v1(ib,itide)
+!!$               v1(ib,itide) = z1t
+!!$               v2(ib,itide) = z2t
+!!$            END DO
+!!$            !
+!!$         END DO   ! end loop on tidal components
+!!$         !
+!!$      ENDIF ! date correction
+!!$      !
+!!$   END SUBROUTINE tide_data
+!!$
+!!$
+!!$   SUBROUTINE tide_update ( kt, jit )
+!!$      !!----------------------------------------------------------------------
+!!$      !!                 ***  SUBROUTINE tide_update  ***
+!!$      !!                
+!!$      !! ** Purpose : - Add tidal forcing to ssh_obc, ubt_obc and vbt_obc arrays. 
+!!$      !!                
+!!$      !!----------------------------------------------------------------------
+!!$      INTEGER, INTENT( in ) ::   kt      ! Main timestep counter
+!!$!!gm doctor jit ==> kit
+!!$      INTEGER, INTENT( in ) ::   jit     ! Barotropic timestep counter (for timesplitting option)
+!!$      !!
+!!$      INTEGER  ::   itide, igrd, ib      ! dummy loop indices
+!!$      REAL(wp) ::   z_arg, z_sarg            !            
+!!$      REAL(wp), DIMENSION(jptides_max) :: z_sist, z_cost
+!!$      !!----------------------------------------------------------------------
+!!$
+!!$      ! Note tide phase speeds are in deg/hour, so we need to convert the
+!!$      ! elapsed time in seconds to hours by dividing by 3600.0
+!!$      IF( jit == 0 ) THEN  
+!!$         z_arg = kt * rdt * rad / 3600.0
+!!$      ELSE                              ! we are in a barotropic subcycle (for timesplitting option)
+!!$!         z_arg = ( (kt-1) * rdt + jit * rdt / REAL(nn_baro,lwp) ) * rad / 3600.0
+!!$         z_arg = ( (kt-1) * rdt + jit * rdt / REAL(nn_baro,wp) ) * rad / 3600.0
+!!$      ENDIF
+!!$
+!!$      DO itide = 1, ntide
+!!$         z_sarg = z_arg * tide_speed(itide)
+!!$         z_cost(itide) = COS( z_sarg )
+!!$         z_sist(itide) = SIN( z_sarg )
+!!$      END DO
+!!$
+!!$      ! summing of tidal constituents into BDY arrays
+!!$      sshtide(:) = 0.0
+!!$      utide (:) = 0.0
+!!$      vtide (:) = 0.0
+!!$      !
+!!$      DO itide = 1, ntide
+!!$         igrd=4                              ! SSH on tracer grid.
+!!$         DO ib = 1, nblenrim(igrd)
+!!$            sshtide(ib) =sshtide(ib)+ ssh1(ib,itide)*z_cost(itide) + ssh2(ib,itide)*z_sist(itide)
+!!$            !    if(lwp) write(numout,*) 'z',ib,itide,sshtide(ib), ssh1(ib,itide),ssh2(ib,itide)
+!!$         END DO
+!!$         igrd=5                              ! U grid
+!!$         DO ib=1, nblenrim(igrd)
+!!$            utide(ib) = utide(ib)+ u1(ib,itide)*z_cost(itide) + u2(ib,itide)*z_sist(itide)
+!!$            !    if(lwp) write(numout,*) 'u',ib,itide,utide(ib), u1(ib,itide),u2(ib,itide)
+!!$         END DO
+!!$         igrd=6                              ! V grid
+!!$         DO ib=1, nblenrim(igrd)
+!!$            vtide(ib) = vtide(ib)+ v1(ib,itide)*z_cost(itide) + v2(ib,itide)*z_sist(itide)
+!!$            !    if(lwp) write(numout,*) 'v',ib,itide,vtide(ib), v1(ib,itide),v2(ib,itide)
+!!$         END DO
+!!$      END DO
+!!$      !
+!!$   END SUBROUTINE tide_update
+!!$
+!!$!!gm  doctor naming of dummy argument variables!!!   and all local variables
+!!$
+!!$   SUBROUTINE uvset( ihs, iday, imnth, iyr, f, z_vplu )
+!!$      !!----------------------------------------------------------------------
+!!$      !!                   ***  SUBROUTINE uvset  ***
+!!$      !!                     
+!!$      !! ** Purpose : - adjust tidal forcing for date factors
+!!$      !!                
+!!$      !!----------------------------------------------------------------------
+!!$      implicit none
+!!$      INTEGER, INTENT( in ) ::   ihs     ! Start time hours
+!!$      INTEGER, INTENT( in ) ::   iday    ! start time days
+!!$      INTEGER, INTENT( in ) ::   imnth   ! start time month
+!!$      INTEGER, INTENT( in ) ::   iyr     ! start time year
+!!$      !!
+!!$!!gm  nc is jptides_max ????
+!!$      INTEGER , PARAMETER     ::  nc =15    ! maximum number of constituents
+!!$      CHARACTER(len=8), DIMENSION(nc) :: cname
+!!$      INTEGER                 ::   year, vd, ivdy, ndc, i, k
+!!$      REAL(wp)                ::   ss, h, p, en, p1, rtd
+!!$      REAL(wp), DIMENSION(nc) ::   f                          ! nodal correction
+!!$      REAL(wp), DIMENSION(nc) ::   z_vplu                     ! phase correction
+!!$      REAL(wp), DIMENSION(nc) ::   u, v, zig
+!!$      !!
+!!$      DATA cname/  'q1'    ,    'o1'    ,     'p1'   ,    's1'    ,     'k1'    ,   &
+!!$         &         '2n2'   ,    'mu2'   ,     'n2'   ,    'nu2'   ,     'm2'    ,   &
+!!$         &         'l2'    ,    't2'    ,     's2'   ,    'k2'    ,     'm4'      /
+!!$      DATA zig/ .2338507481, .2433518789, .2610826055, .2617993878,  .2625161701,   &
+!!$         &      .4868657873, .4881373225, .4963669182, .4976384533,  .5058680490,   &
+!!$         &      .5153691799, .5228820265, .5235987756, .5250323419, 1.011736098   /
+!!$      !!----------------------------------------------------------------------
+!!$!
+!!$!     ihs             -  start time gmt on ...
+!!$!     iday/imnth/iyr  -  date   e.g.   12/10/87
+!!$!
+!!$      CALL vday(iday,imnth,iyr,ivdy)
+!!$      vd = ivdy
+!!$!
+!!$!rp   note change of year number for d. blackman shpen
+!!$!rp   if(iyr.ge.1000) year=iyr-1900
+!!$!rp   if(iyr.lt.1000) year=iyr
+!!$      year = iyr
+!!$!
+!!$!.....year  =  year of required data
+!!$!.....vd    =  day of required data..set up for 0000gmt day year
+!!$      ndc = nc
+!!$!.....ndc   =  number of constituents allowed
+!!$!!gm use rpi ?
+!!$      rtd = 360.0 / 6.2831852
+!!$      DO i = 1, ndc
+!!$         zig(i) = zig(i)*rtd
+!!$         ! sigo(i)= zig(i)
+!!$      END DO
+!!$
+!!$!!gm try to avoid RETURN  in F90
+!!$      IF( year == 0 )   RETURN
+!!$      
+!!$         CALL shpen( year, vd, ss, h , p , en, p1 )
+!!$         CALL ufset( p   , en, u , f )
+!!$         CALL vset ( ss  , h , p , en, p1, v )
+!!$         !
+!!$         DO k = 1, nc
+!!$            z_vplu(k) = v(k) + u(k)
+!!$            z_vplu(k) = z_vplu(k) + dble(ihs) * zig(k)
+!!$            DO WHILE( z_vplu(k) < 0    )
+!!$               z_vplu(k) = z_vplu(k) + 360.0
+!!$            END DO
+!!$            DO WHILE( z_vplu(k) > 360. )
+!!$               z_vplu(k) = z_vplu(k) - 360.0
+!!$            END DO
+!!$         END DO
+!!$         !
+!!$      END SUBROUTINE uvset
+!!$
+!!$
+!!$      SUBROUTINE vday( iday, imnth, iy, ivdy )
+!!$      !!----------------------------------------------------------------------
+!!$      !!                   *** SUBROUTINE vday  ***
+!!$      !!                  
+!!$      !! ** Purpose : - adjust tidal forcing for date factors
+!!$      !!                
+!!$      !!----------------------------------------------------------------------
+!!$      INTEGER, INTENT(in   ) ::   iday, imnth, iy   ! ????
+!!$      INTEGER, INTENT(  out) ::   ivdy              ! ???
+!!$      !! 
+!!$      INTEGER ::   iyr
+!!$      !!------------------------------------------------------------------------------
+!!$
+!!$!!gm   nday_year in day mode is the variable compiuted here, no?
+!!$!!gm      nday_year ,   &  !: curent day counted from jan 1st of the current year
+!!$
+!!$      !calculate day number in year from day/month/year
+!!$       if(imnth.eq.1) ivdy=iday
+!!$       if(imnth.eq.2) ivdy=iday+31
+!!$       if(imnth.eq.3) ivdy=iday+59
+!!$       if(imnth.eq.4) ivdy=iday+90
+!!$       if(imnth.eq.5) ivdy=iday+120
+!!$       if(imnth.eq.6) ivdy=iday+151
+!!$       if(imnth.eq.7) ivdy=iday+181
+!!$       if(imnth.eq.8) ivdy=iday+212
+!!$       if(imnth.eq.9) ivdy=iday+243
+!!$       if(imnth.eq.10) ivdy=iday+273
+!!$       if(imnth.eq.11) ivdy=iday+304
+!!$       if(imnth.eq.12) ivdy=iday+334
+!!$       iyr=iy
+!!$       if(mod(iyr,4).eq.0.and.imnth.gt.2) ivdy=ivdy+1
+!!$       if(mod(iyr,100).eq.0.and.imnth.gt.2) ivdy=ivdy-1
+!!$       if(mod(iyr,400).eq.0.and.imnth.gt.2) ivdy=ivdy+1
+!!$      !
+!!$   END SUBROUTINE vday
+!!$
+!!$!!doctor norme for dummy arguments
+!!$
+!!$   SUBROUTINE shpen( year, vd, s, h, p, en, p1 )
+!!$      !!----------------------------------------------------------------------
+!!$      !!                    ***  SUBROUTINE shpen  ***
+!!$      !!                   
+!!$      !! ** Purpose : - calculate astronomical arguments for tides
+!!$      !!                this version from d. blackman 30 nove 1990
+!!$      !!
+!!$      !!----------------------------------------------------------------------
+!!$!!gm add INTENT in, out or inout....    DOCTOR name....
+!!$!!gm please do not use variable name with a single letter:  impossible to search in a code
+!!$      INTEGER  ::   year,vd
+!!$      REAL(wp) ::   s,h,p,en,p1
+!!$      !!
+!!$      INTEGER  ::   yr,ilc,icent,it,iday,ild,ipos,nn,iyd
+!!$      REAL(wp) ::   cycle,t,td,delt(84),delta,deltat
+!!$      !!
+!!$      DATA delt /-5.04, -3.90, -2.87, -0.58,  0.71,  1.80,           &
+!!$         &        3.08,  4.63,  5.86,  7.21,  8.58, 10.50, 12.10,    &
+!!$         &       12.49, 14.41, 15.59, 15.81, 17.52, 19.01, 18.39,    &
+!!$         &       19.55, 20.36, 21.01, 21.81, 21.76, 22.35, 22.68,    &
+!!$         &       22.94, 22.93, 22.69, 22.94, 23.20, 23.31, 23.63,    &
+!!$         &       23.47, 23.68, 23.62, 23.53, 23.59, 23.99, 23.80,    &
+!!$         &       24.20, 24.99, 24.97, 25.72, 26.21, 26.37, 26.89,    &
+!!$         &       27.68, 28.13, 28.94, 29.42, 29.66, 30.29, 30.96,    &
+!!$         &       31.09, 31.59, 31.52, 31.92, 32.45, 32.91, 33.39,    &
+!!$         &       33.80, 34.23, 34.73, 35.40, 36.14, 36.99, 37.87,    &
+!!$         &       38.75, 39.70, 40.70, 41.68, 42.82, 43.96, 45.00,    &
+!!$         &       45.98, 47.00, 48.03, 49.10, 50.10, 50.97, 51.81,    &
+!!$         &       52.57 /
+!!$      !!----------------------------------------------------------------------
+!!$
+!!$      cycle = 360.0
+!!$      ilc = 0
+!!$      icent = year / 100
+!!$      yr = year - icent * 100
+!!$      t = icent - 20
+!!$!
+!!$!     for the following equations
+!!$!     time origin is fixed at 00 hr of jan 1st,2000.
+!!$!     see notes by cartwright
+!!$!
+!!$!!gm  old coding style, use CASE instead  and avoid GOTO (obsolescence in fortran 90)
+!!$!!gm obsol(   1): Arithmetic IF statement is used   ===>  remove this in Fortran 90
+!!$      it = icent - 20
+!!$      if (it) 1,2,2
+!!$    1 iday = it/4 -it
+!!$      go to 3
+!!$    2 iday = (it+3)/4 - it
+!!$!
+!!$!     t is in julian century
+!!$!     correction in gegorian calander where only century year divisible
+!!$!     by 4 is leap year.
+!!$!
+!!$    3 continue
+!!$!
+!!$      td = 0.0
+!!$!
+!!$!!gm obsol(   1): Arithmetic IF statement is used   ===>  remove this in Fortran 90
+!!$      if (yr) 4,5,4
+!!$!
+!!$    4 iyd = 365*yr
+!!$      ild = (yr-1)/4
+!!$      if((icent - (icent/4)*4) .eq. 0) ilc = 1
+!!$      td = iyd + ild + ilc
+!!$!
+!!$    5 td = td + iday + vd -1.0 - 0.5
+!!$      t = t + (td/36525.0)
+!!$!
+!!$      ipos=year-1899
+!!$      if (ipos .lt. 0) go to 7
+!!$      if (ipos .gt. 83) go to 6
+!!$!
+!!$      delta = (delt(ipos+1)+delt(ipos))/2.0
+!!$      go to 7
+!!$!
+!!$    6 delta= (65.0-50.5)/20.0*(year-1980)+50.5
+!!$!
+!!$    7 deltat = delta * 1.0e-6
+!!$!
+!!$!!gm   precision of the computation   :  example for s it should be replace by:
+!!$!!gm  s   = 218.3165 + (481267.8813 - 0.0016*t)*t + 152.0*deltat   ==>  more precise  modify the last digits results
+!!$      s   = 218.3165 + 481267.8813*t - 0.0016*t*t + 152.0*deltat
+!!$      h   = 280.4661 + 36000.7698 *t + 0.0003*t*t +  11.0*deltat
+!!$      p   =  83.3535 + 4069.0139  *t - 0.0103*t*t +       deltat
+!!$      en  = 234.9555 + 1934.1363  *t - 0.0021*t*t +       deltat
+!!$      p1  = 282.9384 + 1.7195     *t + 0.0005*t*t
+!!$      !
+!!$      nn = s / cycle
+!!$      s = s - nn * cycle
+!!$      IF( s < 0.e0 )   s = s + cycle
+!!$      !
+!!$      nn = h / cycle
+!!$      h = h - cycle * nn
+!!$      IF( h < 0.e0 )   h = h + cycle
+!!$      !
+!!$      nn = p / cycle
+!!$      p = p - cycle * nn
+!!$      IF( p < 0.e0)   p = p + cycle
+!!$      !
+!!$      nn = en / cycle
+!!$      en = en - cycle * nn
+!!$      IF( en < 0.e0 )   en = en + cycle
+!!$      en = cycle - en
+!!$      !
+!!$      nn = p1 / cycle
+!!$      p1 = p1 - nn * cycle
+!!$      !
+!!$   END SUBROUTINE shpen
+!!$
+!!$
+!!$   SUBROUTINE ufset( p, cn, b, a )
+!!$      !!----------------------------------------------------------------------
+!!$      !!                    ***  SUBROUTINE ufset  ***
+!!$      !!                    
+!!$      !! ** Purpose : - calculate nodal parameters for the tides
+!!$      !!                
+!!$      !!----------------------------------------------------------------------
+!!$!!gm  doctor naming of dummy argument variables!!!   and all local variables
+!!$!!gm  nc is jptides_max ????
+!!$      integer nc
+!!$      parameter (nc=15)
+!!$      REAL(wp) p,cn
+!!$      !!
+!!$      
+!!$!!gm  rad is already a public variable defined in phycst.F90 ....   ==> doctor norme  local real start with "z"
+!!$      REAL(wp) ::   w1, w2, w3, w4, w5, w6, w7, w8, nw, pw, rad
+!!$      REAL(wp) ::   a(nc), b(nc)
+!!$      INTEGER  ::   ndc, k
+!!$      !!----------------------------------------------------------------------
+!!$
+!!$      ndc = nc
+!!$
+!!$!    a=f       ,  b =u
+!!$!    t is  zero as compared to tifa.
+!!$!! use rad defined in phycst   (i.e.  add a USE phycst at the begining of the module
+!!$      rad = 6.2831852d0/360.0
+!!$      pw = p  * rad
+!!$      nw = cn * rad
+!!$      w1 = cos(   nw )
+!!$      w2 = cos( 2*nw )
+!!$      w3 = cos( 3*nw )
+!!$      w4 = sin(   nw )
+!!$      w5 = sin( 2*nw )
+!!$      w6 = sin( 3*nw )
+!!$      w7 = 1. - 0.2505 * COS( 2*pw      ) - 0.1102 * COS(2*pw-nw )   &
+!!$         &    - 0.156  * COS( 2*pw-2*nw ) - 0.037  * COS(     nw )
+!!$      w8 =    - 0.2505 * SIN( 2*pw      ) - 0.1102 * SIN(2*pw-nw )   &
+!!$         &    - 0.0156 * SIN( 2*pw-2*nw ) - 0.037  * SIN(     nw )
+!!$      !
+!!$      a(1) = 1.0089 + 0.1871 * w1 - 0.0147 * w2 + 0.0014 * w3
+!!$      b(1) =          0.1885 * w4 - 0.0234 * w5 + 0.0033 * w6
+!!$      !   q1
+!!$      a(2) = a(1)
+!!$      b(2) = b(1)
+!!$      !   o1
+!!$      a(3) = 1.0
+!!$      b(3) = 0.0
+!!$      !   p1
+!!$      a(4) = 1.0
+!!$      b(4) = 0.0
+!!$      !   s1
+!!$      a(5) = 1.0060+0.1150*w1- 0.0088*w2 +0.0006*w3
+!!$      b(5) = -0.1546*w4 + 0.0119*w5 -0.0012*w6
+!!$      !   k1
+!!$      a(6) =1.0004 -0.0373*w1+ 0.0002*w2
+!!$      b(6) = -0.0374*w4
+!!$      !  2n2
+!!$      a(7) = a(6)
+!!$      b(7) = b(6)
+!!$      !  mu2
+!!$      a(8) = a(6)
+!!$      b(8) = b(6)
+!!$      !   n2
+!!$      a(9) = a(6)
+!!$      b(9) = b(6)
+!!$      !  nu2
+!!$      a(10) = a(6)
+!!$      b(10) = b(6)
+!!$      !   m2
+!!$      a(11) = SQRT( w7 * w7 + w8 * w8 )
+!!$      b(11) = ATAN( w8 / w7 )
+!!$!!gmuse rpi  instead of 3.141992 ???   true pi is rpi=3.141592653589793_wp  .....   ????
+!!$      IF( w7 < 0.e0 )   b(11) = b(11) + 3.141992
+!!$      !   l2
+!!$      a(12) = 1.0
+!!$      b(12) = 0.0
+!!$      !   t2
+!!$      a(13)= a(12)
+!!$      b(13)= b(12)
+!!$      !   s2
+!!$      a(14) = 1.0241+0.2863*w1+0.0083*w2 -0.0015*w3
+!!$      b(14) = -0.3096*w4 + 0.0119*w5 - 0.0007*w6
+!!$      !   k2
+!!$      a(15) = a(6)*a(6)
+!!$      b(15) = 2*b(6)
+!!$      !   m4
+!!$!!gm  old coding,  remove GOTO and label of lines
+!!$!!gm obsol(   1): Arithmetic IF statement is used   ===>  remove this in Fortran 90
+!!$      DO 40 k = 1,ndc
+!!$         b(k) = b(k)/rad
+!!$32       if (b(k)) 34,35,35
+!!$34       b(k) = b(k) + 360.0
+!!$         go to 32
+!!$35       if (b(k)-360.0) 40,37,37
+!!$37       b(k) = b(k)-360.0
+!!$         go to 35
+!!$40    continue
+!!$      !
+!!$   END SUBROUTINE ufset
+!!$   
+!!$
+!!$   SUBROUTINE vset( s,h,p,en,p1,v)
+!!$      !!----------------------------------------------------------------------
+!!$      !!                    ***  SUBROUTINE vset  ***
+!!$      !!                   
+!!$      !! ** Purpose : - calculate tidal phases for 0000gmt on start day of run
+!!$      !!                
+!!$      !!----------------------------------------------------------------------
+!!$!!gm  doctor naming of dummy argument variables!!!   and all local variables
+!!$!!gm  nc is jptides_max ????
+!!$!!gm  en argument is not used: suppress it ?
+!!$      integer nc
+!!$      parameter (nc=15)
+!!$      real(wp) s,h,p,en,p1
+!!$      real(wp)   v(nc)
+!!$      !!
+!!$      integer ndc, k
+!!$      !!----------------------------------------------------------------------
+!!$
+!!$      ndc = nc
+!!$      !   v s  are computed here.
+!!$      v(1) =-3*s +h +p +270      ! Q1
+!!$      v(2) =-2*s +h +270.0       ! O1
+!!$      v(3) =-h +270              ! P1
+!!$      v(4) =180                  ! S1
+!!$      v(5) =h +90.0              ! K1
+!!$      v(6) =-4*s +2*h +2*p       ! 2N2
+!!$      v(7) =-4*(s-h)             ! MU2
+!!$      v(8) =-3*s +2*h +p         ! N2
+!!$      v(9) =-3*s +4*h -p         ! MU2
+!!$      v(10) =-2*s +2*h           ! M2
+!!$      v(11) =-s +2*h -p +180     ! L2 
+!!$      v(12) =-h +p1              ! T2
+!!$      v(13) =0                   ! S2
+!!$      v(14) =h+h                 ! K2
+!!$      v(15) =2*v(10)             ! M4
+!!$!
+!!$!!gm  old coding,  remove GOTO and label of lines
+!!$!!gm obsol(   1): Arithmetic IF statement is used   ===>  remove this in Fortran 90
+!!$      do 72 k = 1, ndc
+!!$69       if( v(k) )   70,71,71
+!!$70       v(k) = v(k)+360.0
+!!$         go to 69
+!!$71       if( v(k) - 360.0 )   72,73,73
+!!$73       v(k) = v(k)-360.0
+!!$         go to 71
+!!$72    continue
+!!$      !
+!!$   END SUBROUTINE vset
+!!$
+!!$#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module         NO Unstruct Open Boundary Conditions for tides
+   !!----------------------------------------------------------------------
+!!gm  are you sure we need to define filtide and tide_cpt ?
+   CHARACTER(len=80), PUBLIC               ::   filtide                !: Filename root for tidal input files
+   CHARACTER(len=4 ), PUBLIC, DIMENSION(1) ::   tide_cpt               !: Names of tidal components used.
+
+CONTAINS
+   SUBROUTINE tide_init                ! Empty routine
+   END SUBROUTINE tide_init
+   SUBROUTINE tide_data                ! Empty routine
+   END SUBROUTINE tide_data
+   SUBROUTINE tide_update( kt, kit )   ! Empty routine
+      WRITE(*,*) 'tide_update: You should not have seen this print! error?', kt, kit
+   END SUBROUTINE tide_update
+#endif
+
+   !!======================================================================
+END MODULE obctides
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obctra.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obctra.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obctra.F90	(revision 2797)
@@ -1,24 +1,22 @@
 MODULE obctra
-   !!=================================================================================
+   !!======================================================================
    !!                       ***  MODULE  obctra  ***
-   !! Ocean tracers:   Radiation of tracers on each open boundary
-   !!=================================================================================
+   !! Ocean tracers:   Flow Relaxation Scheme of tracers on each open boundary
+   !!======================================================================
+   !! History :  1.0  !  2005-01  (J. Chanut, A. Sellar)  Original code
+   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
+   !!----------------------------------------------------------------------
 #if defined key_obc
-   !!---------------------------------------------------------------------------------
-   !!   'key_obc'      :                                      Open Boundary Conditions
-   !!---------------------------------------------------------------------------------
-   !!   obc_tra        : call the subroutine for each open boundary
-   !!   obc_tra_east   : radiation of the east open boundary tracers
-   !!   obc_tra_west   : radiation of the west open boundary tracers
-   !!   obc_tra_north  : radiation of the north open boundary tracers
-   !!   obc_tra_south  : radiation of the south open boundary tracers
-   !!----------------------------------------------------------------------------------
-   !! * Modules used
+   !!----------------------------------------------------------------------
+   !!   'key_obc'                     Unstructured Open Boundary Conditions
+   !!----------------------------------------------------------------------
+   !!   obc_tra            : Apply open boundary conditions to T and S
+   !!   obc_tra_frs        : Apply Flow Relaxation Scheme
+   !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables 
-   USE phycst          ! physical constants
    USE obc_oce         ! ocean open boundary conditions
-   USE lib_mpp         ! ???
-   USE lbclnk          ! ???
+   USE obcdta, ONLY:   bf
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE in_out_manager  ! I/O manager
 
@@ -26,499 +24,83 @@
    PRIVATE
 
-   !! * Accessibility
-   PUBLIC obc_tra     ! routine called in tranxt.F90 
+   PUBLIC obc_tra      ! routine called in tranxt.F90 
 
-   !! * Module variables
-   INTEGER ::      & ! ... boundary space indices 
-      nib   = 1,   & ! nib   = boundary point
-      nibm  = 2,   & ! nibm  = 1st interior point
-      nibm2 = 3,   & ! nibm2 = 2nd interior point
-                     ! ... boundary time indices 
-      nit   = 1,   & ! nit    = now
-      nitm  = 2,   & ! nitm   = before
-      nitm2 = 3      ! nitm2  = before-before
-
-   REAL(wp) ::     &
-      rtaue  , rtauw  , rtaun  , rtaus  ,  &  ! Boundary restoring coefficient
-      rtauein, rtauwin, rtaunin, rtausin      ! Boundary restoring coefficient for inflow 
-
-   !! * Substitutions
-#  include "obc_vectopt_loop_substitute.h90"
-   !!---------------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
    !! $Id$ 
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!---------------------------------------------------------------------------------
-
+   !!----------------------------------------------------------------------
 CONTAINS
 
    SUBROUTINE obc_tra( kt )
-      !!-------------------------------------------------------------------------------
-      !!                 ***  SUBROUTINE obc_tra  ***
-      !!                    
-      !! ** Purpose :   Compute tracer fields (t,s) along the open boundaries.
-      !!      This routine is called by the tranxt.F routine and updates ta,sa
-      !!      which are the actual temperature and salinity fields.
-      !!        The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north,
-      !!      and/or lp_obc_south allow the user to determine which boundary is an
-      !!      open one (must be done in the param_obc.h90 file).
+      !!----------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn3d  ***
       !!
-      !! Reference : 
-      !!   Marchesiello P., 1995, these de l'universite J. Fourier, Grenoble, France.
+      !! ** Purpose : - Apply open boundary conditions for baroclinic velocities
       !!
-      !!  History :
-      !!        !  95-03 (J.-M. Molines) Original, SPEM
-      !!        !  97-07 (G. Madec, J.-M. Molines) addition
-      !!   8.5  !  02-10 (C. Talandier, A-M. Treguier) F90
       !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt     ! Main time step counter
+      !!
+      INTEGER               :: ib_obc ! Loop index
 
-      ! 0. Local constant initialization
+      DO ib_obc=1, nb_obc
 
-      IF( kt == nit000 .OR. ln_rstart) THEN
-         ! ... Boundary restoring coefficient
-         rtaue = 2. * rdt / rdpeob
-         rtauw = 2. * rdt / rdpwob
-         rtaun = 2. * rdt / rdpnob
-         rtaus = 2. * rdt / rdpsob
-         ! ... Boundary restoring coefficient for inflow ( all boundaries)
-         rtauein = 2. * rdt / rdpein 
-         rtauwin = 2. * rdt / rdpwin
-         rtaunin = 2. * rdt / rdpnin
-         rtausin = 2. * rdt / rdpsin 
-      END IF
-
-      IF( lp_obc_east  )   CALL obc_tra_east ( kt )    ! East open boundary
-
-      IF( lp_obc_west  )   CALL obc_tra_west ( kt )    ! West open boundary
-
-      IF( lp_obc_north )   CALL obc_tra_north( kt )    ! North open boundary
-
-      IF( lp_obc_south )   CALL obc_tra_south( kt )    ! South open boundary
-
-      IF( lk_mpp ) THEN                  !!bug ???
-         IF( kt >= nit000+3 .AND. ln_rstart ) THEN
-            CALL lbc_lnk( tb, 'T', 1. )
-            CALL lbc_lnk( sb, 'T', 1. )
-         END IF
-         CALL lbc_lnk( ta, 'T', 1. )
-         CALL lbc_lnk( sa, 'T', 1. )
-      ENDIF
+         SELECT CASE( nn_tra(ib_obc) )
+         CASE(jp_none)
+            CYCLE
+         CASE(jp_frs)
+            CALL obc_tra_frs( idx_obc(ib_obc), dta_obc(ib_obc), kt )
+         CASE DEFAULT
+            CALL ctl_stop( 'obc_tra : unrecognised option for open boundaries for T an S' )
+         END SELECT
+      ENDDO
 
    END SUBROUTINE obc_tra
 
-
-   SUBROUTINE obc_tra_east ( kt )
-      !!------------------------------------------------------------------------------
-      !!                ***  SUBROUTINE obc_tra_east  ***
-      !!                  
-      !! ** Purpose :
-      !!      Apply the radiation algorithm on east OBC tracers ta, sa using the 
-      !!      phase velocities calculated in obc_rad_east subroutine in obcrad.F90 module
-      !!      If the logical lfbceast is .TRUE., there is no radiation but only fixed OBC
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declaration
-      INTEGER ::   ji, jj, jk      ! dummy loop indices
-      REAL(wp) ::   z05cx, ztau, zin
-      !!------------------------------------------------------------------------------
-
-      ! 1. First three time steps and more if lfbceast is .TRUE.
-      !    In that case open boundary conditions are FIXED.
-      ! --------------------------------------------------------
-
-      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbceast ) THEN
-         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1. - temsk(jj,jk)) + &
-                                 tfoe(jj,jk)*temsk(jj,jk)
-                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1. - temsk(jj,jk)) + &
-                                 sfoe(jj,jk)*temsk(jj,jk)
-               END DO
-            END DO
+   SUBROUTINE obc_tra_frs( idx, dta, kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_tra_frs  ***
+      !!                    
+      !! ** Purpose : Apply the Flow Relaxation Scheme for tracers at open boundaries.
+      !! 
+      !! Reference : Engedahl H., 1995, Tellus, 365-382.
+      !!----------------------------------------------------------------------
+      INTEGER,         INTENT(in) ::   kt
+      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
+      !! 
+      REAL(wp) ::   zwgt           ! boundary weight
+      INTEGER  ::   ib, ik, igrd   ! dummy loop indices
+      INTEGER  ::   ii, ij         ! 2D addresses
+      !!----------------------------------------------------------------------
+      !
+      !
+      igrd = 1                       ! Everything is at T-points here
+      DO ib = 1, idx%nblen(igrd)
+         DO ik = 1, jpkm1
+            ii = idx%nbi(ib,igrd)
+            ij = idx%nbj(ib,igrd)
+            zwgt = idx%nbw(ib,igrd)
+            ta(ii,ij,ik) = ( ta(ii,ij,ik) + zwgt * ( dta%tem(ib,ik) - ta(ii,ij,ik) ) ) * tmask(ii,ij,ik)         
+            sa(ii,ij,ik) = ( sa(ii,ij,ik) + zwgt * ( dta%sal(ib,ik) - sa(ii,ij,ik) ) ) * tmask(ii,ij,ik)
          END DO
-
-      ELSE
-
-      ! 2. Beyond the fourth time step if lfbceast is .FALSE.
-      ! -----------------------------------------------------
-
-         ! Temperature and salinity radiation
-         ! ----------------------------------
-         !
-         !            nibm2      nibm      nib
-         !              |   nibm  |   nib///|///
-         !              |    |    |    |////|///
-         !  jj   line --v----f----v----f----v---
-         !              |    |    |    |////|///
-         !                   |         |///   //
-         !  jj   line   T    u    T    u/// T //
-         !                   |         |///   //
-         !              |    |    |    |////|///
-         !  jj-1 line --v----f----v----f----v---
-         !              |    |    |    |////|///
-         !                jpieob-1    jpieob / ///
-         !              |         |         |
-         !           jpieob-1    jpieob     jpieob+1
-         !
-         ! ... radiative conditions + relaxation toward a climatology
-         !     the phase velocity is taken as the phase velocity of the tangen-
-         !     tial velocity (here vn), which have been saved in (u_cxebnd,v_cxebnd)
-         ! ... (jpjedp1, jpjefm1), jpieob+1
-         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 2, jpjm1
-         ! ... i-phase speed ratio (from averaged of v_cxebnd)
-                  z05cx = ( 0.5 * ( v_cxebnd(jj,jk) + v_cxebnd(jj-1,jk) ) ) / e1t(ji-1,jj)
-                  z05cx = min( z05cx, 1. )
-         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
-         !           > 0, outflow zin=1, ztau=rtaue
-                  zin = sign( 1., z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-         ! ... for inflow rtauein is used for relaxation coefficient else rtaue
-                  ztau = (1.-zin ) * rtauein  + zin * rtaue
-                  z05cx = z05cx * zin
-         ! ... update ( ta, sa ) with radiative or climatological (t, s)
-                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1. - temsk(jj,jk)) +           & 
-                                 temsk(jj,jk) * ( ( 1. - z05cx - ztau )         &
-                                 * tebnd(jj,jk,nib ,nitm) + 2.*z05cx              &
-                                 * tebnd(jj,jk,nibm,nit ) + ztau * tfoe (jj,jk) ) &
-                                 / (1. + z05cx)
-                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1. - temsk(jj,jk)) +           & 
-                                 temsk(jj,jk) * ( ( 1. - z05cx - ztau )         &
-                                 * sebnd(jj,jk,nib ,nitm) + 2.*z05cx              &
-                                 * sebnd(jj,jk,nibm,nit ) + ztau * sfoe (jj,jk) ) &
-                                 / (1. + z05cx)
-               END DO
-            END DO
-         END DO
-
-      END IF
-
-   END SUBROUTINE obc_tra_east
-
-
-   SUBROUTINE obc_tra_west ( kt )
-      !!------------------------------------------------------------------------------
-      !!                 ***  SUBROUTINE obc_tra_west  ***
-      !!           
-      !! ** Purpose :
-      !!      Apply the radiation algorithm on west OBC tracers ta, sa using the 
-      !!      phase velocities calculated in obc_rad_west subroutine in obcrad.F90 module
-      !!      If the logical lfbcwest is .TRUE., there is no radiation but only fixed OBC
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declaration
-      INTEGER ::   ji, jj, jk      ! dummy loop indices
-      REAL(wp) ::   z05cx, ztau, zin
-      !!------------------------------------------------------------------------------
-
-      ! 1. First three time steps and more if lfbcwest is .TRUE.
-      !    In that case open boundary conditions are FIXED.
-      ! --------------------------------------------------------
-
-      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcwest ) THEN
-
-         DO ji = fs_niw0, fs_niw1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1. - twmsk(jj,jk)) + &
-                                 tfow(jj,jk)*twmsk(jj,jk)
-                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1. - twmsk(jj,jk)) + &
-                                 sfow(jj,jk)*twmsk(jj,jk)
-               END DO
-            END DO
-         END DO
-
-      ELSE
-
-      ! 2. Beyond the fourth time step if lfbcwest is .FALSE.
-      ! -----------------------------------------------------
-          
-         ! Temperature and salinity radiation
-         ! ----------------------------------
-         !
-         !          nib       nibm     nibm2
-         !     nib///|   nibm  |  nibm2  |
-         !   ///|////|    |    |    |    |   
-         !   ---v----f----v----f----v----f-- jj   line
-         !   ///|////|    |    |    |    |   
-         !   //   ///|         |         |   
-         !   // T ///u    T    u    T    u   jj   line
-         !   //   ///|         |         |   
-         !   ///|////|    |    |    |    |   
-         !   ---v----f----v----f----v----f-- jj-1 line
-         !   ///|////|    |    |    |    |   
-         !         jpiwob    jpiwob+1    jpiwob+2
-         !      |         |         |        
-         !    jpiwob    jpiwob+1   jpiwob+2
-         !
-         ! ... radiative conditions + relaxation toward a climatology
-         ! ... the phase velocity is taken as the phase velocity of the tangen-
-         ! ... tial velocity (here vn), which have been saved in (v_cxwbnd)
-         DO ji = fs_niw0, fs_niw1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 2, jpjm1
-         ! ... i-phase speed ratio (from averaged of v_cxwbnd)
-                  z05cx = (  0.5 * ( v_cxwbnd(jj,jk) + v_cxwbnd(jj-1,jk) ) ) / e1t(ji+1,jj)
-                  z05cx = max( z05cx, -1. )
-         ! ... z05cx > 0, inflow  zin=0, ztau=1    
-         !           < 0, outflow zin=1, ztau=rtauw
-                  zin = sign( 1., -1.* z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-                  ztau = (1.-zin )*rtauwin + zin * rtauw
-                  z05cx = z05cx * zin
-         ! ... update (ta,sa) with radiative or climatological (t, s)
-                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1. - twmsk(jj,jk)) +           &
-                                 twmsk(jj,jk) * ( ( 1. + z05cx - ztau )         &
-                                 * twbnd(jj,jk,nib ,nitm) - 2.*z05cx              &
-                                 * twbnd(jj,jk,nibm,nit ) + ztau * tfow (jj,jk) ) &
-                                 / (1. - z05cx)
-                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1. - twmsk(jj,jk)) +           &
-                                 twmsk(jj,jk) * ( ( 1. + z05cx - ztau )         &
-                                 * swbnd(jj,jk,nib ,nitm) - 2.*z05cx              &
-                                 * swbnd(jj,jk,nibm,nit ) + ztau * sfow (jj,jk) ) &
-                                 / (1. - z05cx)
-               END DO
-            END DO
-         END DO
-
-      END IF
-
-   END SUBROUTINE obc_tra_west
-
-
-   SUBROUTINE obc_tra_north ( kt )
-      !!------------------------------------------------------------------------------
-      !!                 ***  SUBROUTINE obc_tra_north  ***
-      !!
-      !! ** Purpose :
-      !!      Apply the radiation algorithm on north OBC tracers ta, sa using the 
-      !!      phase velocities calculated in obc_rad_north subroutine in obcrad.F90 module
-      !!      If the logical lfbcnorth is .TRUE., there is no radiation but only fixed OBC
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declaration
-      INTEGER ::   ji, jj, jk      ! dummy loop indices
-      REAL(wp) ::   z05cx, ztau, zin
-      !!------------------------------------------------------------------------------
-
-      ! 1. First three time steps and more if lfbcnorth is .TRUE.
-      !    In that case open boundary conditions are FIXED.
-      ! --------------------------------------------------------
-
-      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcnorth ) THEN
-
-         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  ta(ji,jj,jk)= ta(ji,jj,jk) * (1.-tnmsk(ji,jk)) + &
-                                tnmsk(ji,jk) * tfon(ji,jk)
-                  sa(ji,jj,jk)= sa(ji,jj,jk) * (1.-tnmsk(ji,jk)) + &
-                                tnmsk(ji,jk) * sfon(ji,jk)
-               END DO
-            END DO
-         END DO
-
-      ELSE
-
-      ! 2. Beyond the fourth time step if lfbcnorth is .FALSE.
-      ! -------------------------------------------------------
-          
-         ! Temperature and salinity radiation
-         ! ----------------------------------
-         !
-         !           ji-1   ji   ji   ji +1
-         !             |
-         !    nib //// u // T // u // T //   jpjnob + 1
-         !        /////|//////////////////
-         !    nib  ----f----v----f----v---   jpjnob
-         !             |         |       
-         !      nibm-- u -- T -- u -- T --   jpjnob
-         !             |         |            
-         !   nibm  ----f----v----f----v---  jpjnob-1
-         !             |         |      
-         !     nibm2-- u -- T -- T -- T --  jpjnob-1
-         !             |         |    
-         !   nibm2 ----f----v----f----v---  jpjnob-2
-         !             |         |
-         !
-         ! ... radiative conditions + relaxation toward a climatology
-         ! ... the phase velocity is taken as the normal phase velocity of the tangen-
-         ! ... tial velocity (here un), which has been saved in (u_cynbnd)
-         ! ... jpjnob+1,(jpindp1, jpinfm1)
-         DO jj = fs_njn0+1, fs_njn1+1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 2, jpim1
-         ! ... j-phase speed ratio (from averaged of vtnbnd)
-         !        (bounded by 1)
-                  z05cx = ( 0.5 * ( u_cynbnd(ji,jk) + u_cynbnd(ji-1,jk) ) ) / e2t(ji,jj-1)
-                  z05cx = min( z05cx, 1. )
-         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
-         !           > 0, outflow zin=1, ztau=rtaun
-                  zin = sign( 1., z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-         ! ... for inflow rtaunin is used for relaxation coefficient else rtaun
-                  ztau = (1.-zin ) * rtaunin + zin * rtaun
-                  z05cx = z05cx * zin
-         ! ... update (ta,sa) with radiative or climatological (t, s)
-                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1.-tnmsk(ji,jk)) +             &
-                                 tnmsk(ji,jk) * ( ( 1. - z05cx - ztau )         &
-                                 * tnbnd(ji,jk,nib ,nitm) + 2.*z05cx              &
-                                 * tnbnd(ji,jk,nibm,nit ) + ztau * tfon (ji,jk) ) &
-                                 / (1. + z05cx)
-                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1.-tnmsk(ji,jk)) +             &
-                                 tnmsk(ji,jk) * ( ( 1. - z05cx - ztau )         &
-                                 * snbnd(ji,jk,nib ,nitm) + 2.*z05cx              &
-                                 * snbnd(ji,jk,nibm,nit ) + ztau * sfon (ji,jk) ) &
-                                 / (1. + z05cx)
-               END DO
-            END DO
-         END DO
-
-      END IF
-
-   END SUBROUTINE obc_tra_north
-
-
-   SUBROUTINE obc_tra_south ( kt )
-      !!------------------------------------------------------------------------------
-      !!                ***  SUBROUTINE obc_tra_south  ***
-      !!     
-      !! ** Purpose :
-      !!      Apply the radiation algorithm on south OBC tracers ta, sa using the 
-      !!      phase velocities calculated in obc_rad_south subroutine in obcrad.F90 module
-      !!      If the logical lfbcsouth is .TRUE., there is no radiation but only fixed OBC
-      !!
-      !!  History :
-      !!         ! 95-03 (J.-M. Molines) Original from SPEM
-      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
-      !!         ! 97-12 (M. Imbard) Mpp adaptation
-      !!         ! 00-06 (J.-M. Molines) 
-      !!    8.5  ! 02-10 (C. Talandier, A-M Treguier) F90
-      !!------------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt
-
-      !! * Local declaration
-      INTEGER ::   ji, jj, jk      ! dummy loop indices
-      REAL(wp) ::   z05cx, ztau, zin
-      !!------------------------------------------------------------------------------
-
-      ! 1. First three time steps and more if lfbcsouth is .TRUE.
-      !    In that case open boundary conditions are FIXED.
-      ! --------------------------------------------------------
-
-      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcsouth ) THEN
-
-         DO jj = fs_njs0, fs_njs1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  ta(ji,jj,jk)= ta(ji,jj,jk) * (1.-tsmsk(ji,jk)) + &
-                                tsmsk(ji,jk) * tfos(ji,jk)
-                  sa(ji,jj,jk)= sa(ji,jj,jk) * (1.-tsmsk(ji,jk)) + &
-                                tsmsk(ji,jk) * sfos(ji,jk)
-               END DO
-            END DO
-         END DO
-
-      ELSE
-
-      ! 2. Beyond the fourth time step if lfbcsouth is .FALSE.
-      ! -------------------------------------------------------
-          
-         ! Temperature and salinity radiation
-         ! ----------------------------------
-         !
-         !           ji-1   ji   ji   ji +1
-         !             |         |
-         !   nibm2 ----f----v----f----v---   jpjsob+2
-         !             |         |       
-         !   nibm2 --  u -- T -- u -- T --   jpjsob+2
-         !             |         |            
-         !   nibm  ----f----v----f----v---   jpjsob+1
-         !             |         |      
-         !    nibm --  u -- T -- T -- T --   jpjsob+1
-         !             |         |    
-         !   nib  -----f----v----f----v---   jpjsob
-         !       //////|/////////|//////// 
-         !    nib //// u // T // u // T //   jpjsob 
-         !
-         !... radiative conditions + relaxation toward a climatology
-         !... the phase velocity is taken as the phase velocity of the tangen-
-         !... tial velocity (here un), which has been saved in (u_cysbnd)
-         !... jpjsob,(jpisdp1, jpisfm1)
-         DO jj = fs_njs0, fs_njs1  ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 2, jpim1
-         !... j-phase speed ratio (from averaged of u_cysbnd)
-         !       (bounded by 1)
-                  z05cx = ( 0.5 * ( u_cysbnd(ji,jk) + u_cysbnd(ji-1,jk) ) ) / e2t(ji,jj+1)
-                  z05cx = max( z05cx, -1. )
-         !... z05cx > 0, inflow  zin=0, ztau=1
-         !          < 0, outflow zin=1, ztau=rtaus
-                  zin = sign( 1., -1.* z05cx )
-                  zin = 0.5*( zin + abs(zin) )
-                  ztau = (1.-zin ) * rtausin + zin * rtaus
-                  z05cx = z05cx * zin
-
-         !... update (ta,sa) with radiative or climatological (t, s)
-                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1.-tsmsk(ji,jk)) +             &
-                                 tsmsk(ji,jk) * ( ( 1. + z05cx - ztau )         &
-                                 * tsbnd(ji,jk,nib ,nitm) - 2.*z05cx              &
-                                 * tsbnd(ji,jk,nibm,nit ) + ztau * tfos (ji,jk) ) &
-                                 / (1. - z05cx)
-                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1.-tsmsk(ji,jk)) +             &
-                                 tsmsk(ji,jk) * (  ( 1. + z05cx - ztau )        &
-                                 * ssbnd(ji,jk,nib ,nitm) - 2.*z05cx              &
-                                 * ssbnd(ji,jk,nibm,nit ) + ztau * sfos (ji,jk) ) &
-                                 / (1. - z05cx)
-               END DO
-            END DO
-         END DO
-
-      END IF   
-
-   END SUBROUTINE obc_tra_south
-
+      END DO 
+      !
+      CALL lbc_lnk( ta, 'T', 1. )   ; CALL lbc_lnk( sa, 'T', 1. )    ! Boundary points should be updated
+      !
+      IF( kt .eq. nit000 ) CLOSE( unit = 102 )
+   !
+   END SUBROUTINE obc_tra_frs
+   
 #else
-   !!---------------------------------------------------------------------------------
-   !!   Default option                                                    Empty module
-   !!---------------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   Dummy module                   NO Unstruct Open Boundary Conditions
+   !!----------------------------------------------------------------------
 CONTAINS
-   SUBROUTINE obc_tra      ! Empty routine
+   SUBROUTINE obc_tra(kt)      ! Empty routine
+      WRITE(*,*) 'obc_tra: You should not have seen this print! error?', kt
    END SUBROUTINE obc_tra
 #endif
 
-   !!=================================================================================
+   !!======================================================================
 END MODULE obctra
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcvol.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcvol.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/OBC/obcvol.F90	(revision 2797)
@@ -1,288 +1,167 @@
 MODULE obcvol
-   !!=================================================================================
+   !!======================================================================
    !!                       ***  MODULE  obcvol  ***
-   !! Ocean dynamic :  Volume constraint when OBC and Free surface are used
-   !!=================================================================================
-#if   defined key_obc   &&   ! defined key_vvl
-   !!---------------------------------------------------------------------------------
-   !!   'key_obc'               and   NOT                 open boundary conditions
-   !!   'key_vvl'                                         constant volume free surface
-   !!---------------------------------------------------------------------------------
-   !! * Modules used
-   USE oce             ! ocean dynamics and tracers 
-   USE dom_oce         ! ocean space and time domain 
-   USE sbc_oce         ! ocean surface boundary conditions
-   USE phycst          ! physical constants
-   USE obc_oce         ! ocean open boundary conditions
-   USE lib_mpp         ! for mppsum
-   USE in_out_manager  ! I/O manager
-
-   IMPLICIT NONE
-   PRIVATE
-
-   !! * Accessibility
-   PUBLIC obc_vol        ! routine called by dynspg_flt
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "obc_vectopt_loop_substitute.h90"
-   !!---------------------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!---------------------------------------------------------------------------------
-
+   !! Ocean dynamic :  Volume constraint when unstructured boundary 
+   !!                  and Free surface are used
+   !!======================================================================
+   !! History :  1.0  !  2005-01  (J. Chanut, A. Sellar)  Original code
+   !!             -   !  2006-01  (J. Chanut) Bug correction
+   !!            3.0  !  2008-04  (NEMO team)  add in the reference version
+   !!----------------------------------------------------------------------
+#if   defined key_obc   &&   defined key_dynspg_flt
+!!$   !!----------------------------------------------------------------------
+!!$   !!   'key_obc'            AND      unstructured open boundary conditions
+!!$   !!   'key_dynspg_flt'                              filtered free surface
+!!$   !!----------------------------------------------------------------------
+!!$   USE oce             ! ocean dynamics and tracers 
+!!$   USE dom_oce         ! ocean space and time domain 
+!!$   USE phycst          ! physical constants
+!!$   USE obc_oce         ! ocean open boundary conditions
+!!$   USE lib_mpp         ! for mppsum
+!!$   USE in_out_manager  ! I/O manager
+!!$   USE sbc_oce         ! ocean surface boundary conditions
+!!$
+!!$   IMPLICIT NONE
+!!$   PRIVATE
+!!$
+!!$   PUBLIC obc_vol        ! routine called by dynspg_flt.h90
+!!$
+!!$   !! * Substitutions
+!!$#  include "domzgr_substitute.h90"
+!!$   !!----------------------------------------------------------------------
+!!$   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+!!$   !! $Id$ 
+!!$   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+!!$   !!----------------------------------------------------------------------
+!!$CONTAINS
+!!$
+!!$   SUBROUTINE obc_vol( kt )
+!!$      !!----------------------------------------------------------------------
+!!$      !!                      ***  ROUTINE obcvol  ***
+!!$      !!
+!!$      !! ** Purpose :   This routine is called in dynspg_flt to control 
+!!$      !!      the volume of the system. A correction velocity is calculated
+!!$      !!      to correct the total transport through the unstructured OBC. 
+!!$      !!      The total depth used is constant (H0) to be consistent with the 
+!!$      !!      linear free surface coded in OPA 8.2
+!!$      !!
+!!$      !! ** Method  :   The correction velocity (zubtpecor here) is defined calculating
+!!$      !!      the total transport through all open boundaries (trans_obc) minus
+!!$      !!      the cumulate E-P flux (z_cflxemp) divided by the total lateral 
+!!$      !!      surface (obcsurftot) of the unstructured boundary. 
+!!$      !!         zubtpecor = [trans_obc - z_cflxemp ]*(1./obcsurftot)
+!!$      !!      with z_cflxemp => sum of (Evaporation minus Precipitation)
+!!$      !!                       over all the domain in m3/s at each time step.
+!!$      !!      z_cflxemp < 0 when precipitation dominate
+!!$      !!      z_cflxemp > 0 when evaporation dominate
+!!$      !!
+!!$      !!      There are 2 options (user's desiderata): 
+!!$      !!         1/ The volume changes according to E-P, this is the default
+!!$      !!            option. In this case the cumulate E-P flux are setting to
+!!$      !!            zero (z_cflxemp=0) to calculate the correction velocity. So
+!!$      !!            it will only balance the flux through open boundaries.
+!!$      !!            (set nn_volctl to 0 in tne namelist for this option)
+!!$      !!         2/ The volume is constant even with E-P flux. In this case
+!!$      !!            the correction velocity must balance both the flux 
+!!$      !!            through open boundaries and the ones through the free
+!!$      !!            surface. 
+!!$      !!            (set nn_volctl to 1 in tne namelist for this option)
+!!$      !!----------------------------------------------------------------------
+!!$      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+!!$      !!
+!!$      INTEGER  ::   ji, jj, jk, jb, jgrd
+!!$      INTEGER  ::   ii, ij
+!!$      REAL(wp) ::   zubtpecor, z_cflxemp, ztranst
+!!$      !!-----------------------------------------------------------------------------
+!!$
+!!$      IF( ln_vol ) THEN
+!!$
+!!$      IF( kt == nit000 ) THEN 
+!!$         IF(lwp) WRITE(numout,*)
+!!$         IF(lwp) WRITE(numout,*)'obc_vol : Correction of velocities along unstructured OBC'
+!!$         IF(lwp) WRITE(numout,*)'~~~~~~~'
+!!$      END IF 
+!!$
+!!$      ! Calculate the cumulate surface Flux z_cflxemp (m3/s) over all the domain
+!!$      ! -----------------------------------------------------------------------
+!!$      z_cflxemp = SUM ( ( emp(:,:)-rnf(:,:) ) * obctmask(:,:) * e1t(:,:) * e2t(:,:) ) / rau0
+!!$      IF( lk_mpp )   CALL mpp_sum( z_cflxemp )     ! sum over the global domain
+!!$
+!!$      ! Transport through the unstructured open boundary
+!!$      ! ------------------------------------------------
+!!$      zubtpecor = 0.e0
+!!$      jgrd = 2                               ! cumulate u component contribution first 
+!!$      DO jb = 1, nblenrim(jgrd)
+!!$         DO jk = 1, jpkm1
+!!$            ii = nbi(jb,jgrd)
+!!$            ij = nbj(jb,jgrd)
+!!$            zubtpecor = zubtpecor + flagu(jb) * ua(ii,ij, jk) * e2u(ii,ij) * fse3u(ii,ij,jk)
+!!$         END DO
+!!$      END DO
+!!$      jgrd = 3                               ! then add v component contribution
+!!$      DO jb = 1, nblenrim(jgrd)
+!!$         DO jk = 1, jpkm1
+!!$            ii = nbi(jb,jgrd)
+!!$            ij = nbj(jb,jgrd)
+!!$            zubtpecor = zubtpecor + flagv(jb) * va(ii,ij, jk) * e1v(ii,ij) * fse3v(ii,ij,jk) 
+!!$         END DO
+!!$      END DO
+!!$      IF( lk_mpp )   CALL mpp_sum( zubtpecor )   ! sum over the global domain
+!!$
+!!$      ! The normal velocity correction
+!!$      ! ------------------------------
+!!$      IF( nn_volctl==1 ) THEN   ;   zubtpecor = ( zubtpecor - z_cflxemp) / obcsurftot 
+!!$      ELSE                   ;   zubtpecor =   zubtpecor             / obcsurftot
+!!$      END IF
+!!$
+!!$      ! Correction of the total velocity on the unstructured boundary to respect the mass flux conservation
+!!$      ! -------------------------------------------------------------
+!!$      ztranst = 0.e0
+!!$      jgrd = 2                               ! correct u component
+!!$      DO jb = 1, nblenrim(jgrd)
+!!$         DO jk = 1, jpkm1
+!!$            ii = nbi(jb,jgrd)
+!!$            ij = nbj(jb,jgrd)
+!!$            ua(ii,ij,jk) = ua(ii,ij,jk) - flagu(jb) * zubtpecor * umask(ii,ij,jk)
+!!$            ztranst = ztranst + flagu(jb) * ua(ii,ij,jk) * e2u(ii,ij) * fse3u(ii,ij,jk)
+!!$         END DO
+!!$      END DO
+!!$      jgrd = 3                              ! correct v component
+!!$      DO jb = 1, nblenrim(jgrd)
+!!$         DO jk = 1, jpkm1
+!!$            ii = nbi(jb,jgrd)
+!!$            ij = nbj(jb,jgrd)
+!!$            va(ii,ij,jk) = va(ii,ij,jk) -flagv(jb) * zubtpecor * vmask(ii,ij,jk)
+!!$            ztranst = ztranst + flagv(jb) * va(ii,ij,jk) * e1v(ii,ij) * fse3v(ii,ij,jk)
+!!$         END DO
+!!$      END DO
+!!$      IF( lk_mpp )   CALL mpp_sum( ztranst )   ! sum over the global domain
+!!$ 
+!!$      ! Check the cumulated transport through unstructured OBC once barotropic velocities corrected
+!!$      ! ------------------------------------------------------
+!!$      IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
+!!$         IF(lwp) WRITE(numout,*)
+!!$         IF(lwp) WRITE(numout,*)'obc_vol : time step :', kt
+!!$         IF(lwp) WRITE(numout,*)'~~~~~~~ '
+!!$         IF(lwp) WRITE(numout,*)'          cumulate flux EMP             =', z_cflxemp  , ' (m3/s)'
+!!$         IF(lwp) WRITE(numout,*)'          total lateral surface of OBC  =', obcsurftot, '(m2)'
+!!$         IF(lwp) WRITE(numout,*)'          correction velocity zubtpecor =', zubtpecor , '(m/s)'
+!!$         IF(lwp) WRITE(numout,*)'          cumulated transport ztranst   =', ztranst   , '(m3/s)'
+!!$      END IF 
+!!$      !
+!!$      END IF ! ln_vol
+!!$
+!!$   END SUBROUTINE obc_vol
+!!$
+!!$#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                   NO Unstruct Open Boundary Conditions
+   !!----------------------------------------------------------------------
 CONTAINS
-
-   SUBROUTINE obc_vol ( kt )
-      !!------------------------------------------------------------------------------
-      !!                      ***  ROUTINE obcvol  ***
-      !!
-      !! ** Purpose : 
-      !!      This routine is called in dynspg_flt to control 
-      !!      the volume of the system. A correction velocity is calculated
-      !!      to correct the total transport through the OBC. 
-      !!      The total depth used is constant (H0) to be consistent with the 
-      !!      linear free surface coded in OPA 8.2
-      !!
-      !! ** Method :  
-      !!      The correction velocity (zubtpecor here) is defined calculating
-      !!      the total transport through all open boundaries (trans_obc) minus
-      !!      the cumulate E-P flux (zCflxemp) divided by the total lateral 
-      !!      surface (obcsurftot) of these OBC. 
-      !!
-      !!      zubtpecor = [trans_obc - zCflxemp ]*(1./obcsurftot)
-      !!
-      !!      with zCflxemp => sum of (Evaporation minus Precipitation)
-      !!                       over all the domain in m3/s at each time step.
-      !!
-      !!      zCflxemp < 0 when precipitation dominate
-      !!      zCflxemp > 0 when evaporation dominate
-      !!
-      !!      There are 2 options (user's desiderata): 
-      !!
-      !!         1/ The volume changes according to E-P, this is the default
-      !!            option. In this case the cumulate E-P flux are setting to
-      !!            zero (zCflxemp=0) to calculate the correction velocity. So
-      !!            it will only balance the flux through open boundaries.
-      !!            (set volemp to 0 in tne namelist for this option)
-      !!
-      !!         2/ The volume is constant even with E-P flux. In this case
-      !!            the correction velocity must balance both the flux 
-      !!            through open boundaries and the ones through the free
-      !!            surface. 
-      !!            (set volemp to 1 in tne namelist for this option)
-      !!
-      !! History :
-      !!   8.5  !  02-10 (C. Talandier, A-M. Treguier) Original code
-      !!----------------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk
-      REAL(wp) ::   zubtpecor
-      REAL(wp) ::   zCflxemp
-      REAL(wp) ::   ztransw, ztranse, ztransn, ztranss, ztranst
-      !!-----------------------------------------------------------------------------
-
-      IF( kt == nit000 ) THEN 
-         IF(lwp) WRITE(numout,*)'        '
-         IF(lwp) WRITE(numout,*)'obc_vol : Correction of velocities along OBC'
-         IF(lwp) WRITE(numout,*)'~~~~~~~'
-         IF(lwp) WRITE(numout,*)'        '
-      END IF 
-
-      ! 1. Calculate the cumulate surface Flux zCflxemp (m3/s) over all the domain.
-      ! ---------------------------------------------------------------------------
-
-      zCflxemp = SUM ( ( emp(:,:)-rnf(:,:) )*obctmsk(:,:)* e1t(:,:) * e2t(:,:)  / rau0 ) 
-
-      IF( lk_mpp )   CALL mpp_sum( zCflxemp )   ! sum over the global domain
-
-      ! 2. Barotropic velocity for each open boundary
-      ! ---------------------------------------------
-
-      zubtpecor = 0.e0
-
-      ! ... East open boundary
-      IF( lp_obc_east ) THEN                      ! ... Total transport through the East OBC
-         DO ji = fs_nie0, fs_nie1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  zubtpecor = zubtpecor - ua(ji,jj,jk)*e2u(ji,jj)*fse3u(ji,jj,jk) * &
-             &     uemsk(jj,jk)*MAX(obctmsk(ji,jj),obctmsk(ji+1,jj) )
-               END DO
-            END DO
-         END DO
-      END IF 
-
-      ! ... West open boundary
-      IF( lp_obc_west ) THEN                      ! ... Total transport through the West OBC
-         DO ji = fs_niw0, fs_niw1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  zubtpecor = zubtpecor + ua(ji,jj,jk)*e2u(ji,jj)*fse3u(ji,jj,jk) * &
-             &    uwmsk(jj,jk) *MAX(obctmsk(ji,jj),obctmsk(ji+1,jj) )
-               END DO
-            END DO
-         END DO
-       ENDIF
-
-      ! ... North open boundary
-      IF( lp_obc_north ) THEN                     ! ... Total transport through the North OBC
-         DO jj = fs_njn0, fs_njn1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  zubtpecor = zubtpecor - va(ji,jj,jk)*e1v(ji,jj)*fse3v(ji,jj,jk) * &
-             &    vnmsk(ji,jk) * MAX(obctmsk(ji,jj),obctmsk(ji,jj+1) )
-               END DO
-            END DO
-         END DO
-       ENDIF
-
-      ! ... South open boundary
-      IF( lp_obc_south ) THEN                     ! ... Total transport through the South OBC
-         DO jj = fs_njs0, fs_njs1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  zubtpecor = zubtpecor + va(ji,jj,jk)*e1v(ji,jj)*fse3v(ji,jj,jk) * &
-             &    vsmsk(ji,jk) * MAX(obctmsk(ji,jj),obctmsk(ji,jj+1) )
-               END DO
-            END DO
-         END DO
-       ENDIF
-
-      IF( lk_mpp )   CALL mpp_sum( zubtpecor )   ! sum over the global domain
-
-
-      ! 3. The normal velocity correction
-      ! ---------------------------------
-      IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
-         IF(lwp) WRITE(numout,*)'        '
-         IF(lwp) WRITE(numout,*)'obc_vol : time step :', kt
-         IF(lwp) WRITE(numout,*)'~~~~~~~ '
-         IF(lwp) WRITE(numout,*)'          cumulate flux EMP :', zCflxemp,' (m3/s)'
-         IF(lwp) WRITE(numout,*)'          lateral transport :',zubtpecor,'(m3/s)'
-         IF(lwp) WRITE(numout,*)'          net inflow        :',zubtpecor-zCflxemp,'(m3/s)'
-      ENDIF
-
-      zubtpecor = (zubtpecor - zCflxemp*volemp)*(1./obcsurftot)
-
-      IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
-         IF(lwp) WRITE(numout,*)'          total lateral surface of OBC :',obcsurftot,'(m2)'
-         IF(lwp) WRITE(numout,*)'          correction velocity zubtpecor :',zubtpecor,'(m/s)'
-         IF(lwp) WRITE(numout,*)'        '
-      END IF 
-
-      ! 4. Correction of the total velocity on each open 
-      !    boundary to respect the mass flux conservation
-      ! -------------------------------------------------
-
-      ztranse = 0.e0   ; ztransw = 0.e0 ; ztransn = 0.e0 ; ztranss = 0.e0
-      ztranst = 0.e0  ! total
-
-      IF( lp_obc_west ) THEN
-         ! ... correction of the west velocity
-         DO ji = fs_niw0, fs_niw1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  ua(ji,jj,jk) = ua(ji,jj,jk) - zubtpecor*uwmsk(jj,jk)
-                  ztransw= ztransw + ua(ji,jj,jk)*fse3u(ji,jj,jk)*e2u(ji,jj)*uwmsk(jj,jk) * &
-             &    MAX(obctmsk(ji,jj),obctmsk(ji+1,jj) )
-               END DO
-            END DO
-         END DO
-
-         IF( lk_mpp )   CALL mpp_sum( ztransw )   ! sum over the global domain
-
-         IF( lwp .AND. MOD( kt, nwrite ) == 0)  WRITE(numout,*)'          West OB transport ztransw :', ztransw,'(m3/s)'
-      END IF 
-
-      IF( lp_obc_east ) THEN
-
-         ! ... correction of the east velocity
-         DO ji = fs_nie0, fs_nie1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  ua(ji,jj,jk) = ua(ji,jj,jk) + zubtpecor*uemsk(jj,jk)
-                  ztranse= ztranse + ua(ji,jj,jk)*fse3u(ji,jj,jk)*e2u(ji,jj)*uemsk(jj,jk) * &
-            &     MAX(obctmsk(ji,jj),obctmsk(ji+1,jj) )
-               END DO
-            END DO
-         END DO
-
-         IF( lk_mpp )   CALL mpp_sum( ztranse )   ! sum over the global domain
-
-         IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
-            IF(lwp) WRITE(numout,*)'          East OB transport ztranse :', ztranse,'(m3/s)'
-         END IF 
-
-      END IF 
-
-      IF( lp_obc_north ) THEN
-
-         ! ... correction of the north velocity
-         DO jj = fs_njn0, fs_njn1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji =  1, jpi
-                  va(ji,jj,jk) = va(ji,jj,jk) + zubtpecor*vnmsk(ji,jk)
-                  ztransn= ztransn + va(ji,jj,jk)*fse3v(ji,jj,jk)*e1v(ji,jj)*vnmsk(ji,jk) * &
-           &      MAX(obctmsk(ji,jj),obctmsk(ji,jj+1) )
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mpp_sum( ztransn )   ! sum over the global domain
-
-         IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
-            IF(lwp) WRITE(numout,*)'          North OB transport ztransn :', ztransn,'(m3/s)'
-         END IF 
-
-      END IF 
-
-      IF( lp_obc_south ) THEN
-
-         ! ... correction of the south velocity
-         DO jj = fs_njs0, fs_njs1 ! Vector opt.
-            DO jk = 1, jpkm1
-               DO ji =  1, jpi
-                  va(ji,jj,jk) = va(ji,jj,jk) - zubtpecor*vsmsk(ji,jk)
-                  ztranss= ztranss + va(ji,jj,jk)*fse3v(ji,jj,jk)*e1v(ji,jj)*vsmsk(ji,jk) * &
-            &     MAX(obctmsk(ji,jj),obctmsk(ji,jj+1) )
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mpp_sum( ztranss )   ! sum over the global domain
-
-         IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
-            IF(lwp) WRITE(numout,*)'          South OB transport ztranss :', ztranss,'(m3/s)'
-         END IF 
-
-      END IF 
-
-      ! 5. Check the cumulate transport through OBC
-      !    once barotropic velocities corrected
-      ! -------------------------------------------
-
-
-      IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
-         ztranst = ztransw - ztranse + ztranss - ztransn
-         IF(lwp) WRITE(numout,*)'        '
-         IF(lwp) WRITE(numout,*)'          Cumulate transport ztranst =', ztranst,'(m3/s)'
-         IF(lwp) WRITE(numout,*)'          Balance  =', ztranst - zCflxemp ,'(m3/s)'
-         IF(lwp) WRITE(numout,*)'        '
-      END IF 
-
-   END SUBROUTINE obc_vol
-
-#else
-   !!---------------------------------------------------------------------------------
-   !!  Default option :                                                   Empty module
-   !!---------------------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE obc_vol        ! Empty routine
+   SUBROUTINE obc_vol( kt )        ! Empty routine
+      WRITE(*,*) 'obc_vol: You should not have seen this print! error?', kt
    END SUBROUTINE obc_vol
 #endif
 
-   !!=================================================================================
+   !!======================================================================
 END MODULE obcvol
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 2797)
@@ -56,4 +56,8 @@
       LOGICAL                         ::   rotn         ! flag to indicate whether field has been rotated
    END TYPE FLD
+
+   TYPE, PUBLIC ::   MAP_POINTER      !: Array of integer pointers to 1D arrays
+      INTEGER, POINTER   ::  ptr(:)
+   END TYPE MAP_POINTER
 
 !$AGRIF_DO_NOT_TREAT
@@ -98,5 +102,5 @@
 CONTAINS
 
-   SUBROUTINE fld_read( kt, kn_fsbc, sd )
+   SUBROUTINE fld_read( kt, kn_fsbc, sd, map, jit, timeshift )
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE fld_read  ***
@@ -113,4 +117,7 @@
       INTEGER  , INTENT(in   )               ::   kn_fsbc   ! sbc computation period (in time step) 
       TYPE(FLD), INTENT(inout), DIMENSION(:) ::   sd        ! input field related variables
+      TYPE(MAP_POINTER),INTENT(in), OPTIONAL, DIMENSION(:) ::   map   ! global-to-local mapping index
+      INTEGER  , INTENT(in   ), OPTIONAL     ::   jit       ! subcycle timestep for timesplitting option
+      INTEGER  , INTENT(in   ), OPTIONAL     ::   timeshift ! provide fields at time other than "now"
       !!
       INTEGER  ::   imf        ! size of the structure sd
@@ -127,11 +134,21 @@
       !!---------------------------------------------------------------------
       ! Note that shifting time to be centrered in the middle of sbc time step impacts only nsec_* variables of the calendar 
-      isecsbc = nsec_year + nsec1jan000 + NINT(0.5 * REAL(kn_fsbc - 1,wp) * rdttra(1))   ! middle of sbc time step
+      IF( present(timeshift) ) THEN
+         isecsbc = nsec_year + nsec1jan000 + NINT(0.5 * REAL(kn_fsbc - 1,wp) * rdttra(1)) + timeshift * rdttra(1)  ! middle of sbc time step
+      ELSE
+         isecsbc = nsec_year + nsec1jan000 + NINT(0.5 * REAL(kn_fsbc - 1,wp) * rdttra(1))  ! middle of sbc time step
+      ENDIF
       imf = SIZE( sd )
       !
       IF( kt == nit000 ) THEN                      ! initialization
-         DO jf = 1, imf 
-            CALL fld_init( kn_fsbc, sd(jf) )       ! read each before field (put them in after as they will be swapped)
-         END DO
+         IF( PRESENT(map) ) THEN
+            DO jf = 1, imf 
+               CALL fld_init( kn_fsbc, sd(jf), map(jf)%ptr )  ! read each before field (put them in after as they will be swapped)
+            END DO
+         ELSE
+            DO jf = 1, imf 
+               CALL fld_init( kn_fsbc, sd(jf) )       ! read each before field (put them in after as they will be swapped)
+            END DO
+         ENDIF
          IF( lwp ) CALL wgt_print()                ! control print
          CALL fld_rot( kt, sd )                    ! rotate vector fiels if needed
@@ -212,5 +229,9 @@
 
                ! read after data
-               CALL fld_get( sd(jf) )
+               IF( PRESENT(map) ) THEN
+                  CALL fld_get( sd(jf), map(jf)%ptr )
+               ELSE
+                  CALL fld_get( sd(jf) )
+               ENDIF
 
             ENDIF
@@ -230,4 +251,10 @@
                ! temporal interpolation weights
                ztinta =  REAL( isecsbc - sd(jf)%nrec_b(2), wp ) / REAL( sd(jf)%nrec_a(2) - sd(jf)%nrec_b(2), wp )
+               IF( PRESENT(map) ) THEN 
+                  IF(lwp) WRITE(numout,*) '============================================'
+                  IF(lwp) WRITE(numout,*) 'Output from fld_read(map) on timestep ',kt
+                  IF(lwp) WRITE(numout,*) '============================================'
+                  IF(lwp) WRITE(numout,*) 'sd(jf)%nrec_b(2), sd(jf)%nrec_a(2), isecsbc, ztinta, ztintb : ',sd(jf)%nrec_b(2),sd(jf)%nrec_a(2),isecsbc,ztinta,ztintb
+               ENDIF
                ztintb =  1. - ztinta
 !CDIR COLLAPSE
@@ -253,5 +280,5 @@
 
 
-   SUBROUTINE fld_init( kn_fsbc, sdjf )
+   SUBROUTINE fld_init( kn_fsbc, sdjf, map )
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE fld_init  ***
@@ -262,4 +289,5 @@
       INTEGER  , INTENT(in   ) ::   kn_fsbc   ! sbc computation period (in time step) 
       TYPE(FLD), INTENT(inout) ::   sdjf      ! input field related variables
+      INTEGER  , INTENT(in), OPTIONAL, DIMENSION(:) :: map ! global-to-local mapping indices
       !!
       LOGICAL :: llprevyr              ! are we reading previous year  file?
@@ -364,5 +392,9 @@
 
          ! read before data 
-         CALL fld_get( sdjf )  ! read before values in after arrays(as we will swap it later)
+         IF( PRESENT(map) ) THEN
+            CALL fld_get( sdjf, map )  ! read before values in after arrays(as we will swap it later)
+         ELSE
+            CALL fld_get( sdjf )  ! read before values in after arrays(as we will swap it later)
+         ENDIF
 
          clfmt = "('fld_init : time-interpolation for ', a, ' read previous record = ', i4, ' at time = ', f7.2, ' days')"
@@ -546,11 +578,12 @@
 
 
-   SUBROUTINE fld_get( sdjf )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE fld_clopn  ***
+   SUBROUTINE fld_get( sdjf, map )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE fld_get  ***
       !!
       !! ** Purpose :   read the data
       !!----------------------------------------------------------------------
       TYPE(FLD), INTENT(inout) ::   sdjf   ! input field related variables
+      INTEGER  , INTENT(in), OPTIONAL, DIMENSION(:) :: map ! global-to-local mapping indices
       !!
       INTEGER                  ::   ipk    ! number of vertical levels of sdjf%fdta ( 2D: ipk=1 ; 3D: ipk=jpk )
@@ -559,5 +592,10 @@
             
       ipk = SIZE( sdjf%fnow, 3 )
-      IF( LEN(TRIM(sdjf%wgtname)) > 0 ) THEN
+
+      IF( PRESENT(map) ) THEN
+         IF( sdjf%ln_tint ) THEN   ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fdta(:,:,:,2), sdjf%nrec_a(1), map )
+         ELSE                      ;   CALL fld_map( sdjf%num, sdjf%clvar, sdjf%fnow(:,:,:  ), sdjf%nrec_a(1), map )
+         ENDIF
+      ELSE IF( LEN(TRIM(sdjf%wgtname)) > 0 ) THEN
          CALL wgt_list( sdjf, iw )
          IF( sdjf%ln_tint ) THEN   ;   CALL fld_interp( sdjf%num, sdjf%clvar, iw , ipk  , sdjf%fdta(:,:,:,2), sdjf%nrec_a(1) )
@@ -581,8 +619,51 @@
    END SUBROUTINE fld_get
 
+   SUBROUTINE fld_map( num, clvar, dta, nrec, map )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE fld_get  ***
+      !!
+      !! ** Purpose :   read global data from file and map onto local data
+      !!                using a general mapping (for open boundaries)
+      !!----------------------------------------------------------------------
+      USE obc_oce, ONLY:  dta_global         ! workspace to read in global data arrays
+
+      INTEGER                   , INTENT(in ) ::   num     ! stream number
+      CHARACTER(LEN=*)          , INTENT(in ) ::   clvar   ! variable name
+      REAL(wp), DIMENSION(:,:,:), INTENT(out) ::   dta     ! output field on model grid
+      INTEGER                   , INTENT(in ) ::   nrec    ! record number to read (ie time slice)
+      INTEGER,  DIMENSION(:)    , INTENT(in ) ::   map     ! global-to-local mapping indices
+      !!
+      INTEGER                  ::   ipi      ! length of boundary data on local process
+      INTEGER                  ::   ipj      ! length of dummy dimension ( = 1 )
+      INTEGER                  ::   ipk      ! number of vertical levels of dta ( 2D: ipk=1 ; 3D: ipk=jpk )
+      INTEGER                  ::   ilendta  ! length of data in file
+      INTEGER                  ::   idvar    ! variable ID
+      INTEGER                  ::   ib, ik   ! loop counters
+      INTEGER                  ::   ierr
+      !!
+      CHARACTER(len=80)                   :: zfile
+      !!---------------------------------------------------------------------
+            
+      ipi = SIZE( dta, 1 )
+      ipj = 1
+      ipk = SIZE( dta, 3 )
+
+      idvar   = iom_varid( num, clvar )
+      ilendta = iom_file(num)%dimsz(1,idvar)
+      IF(lwp) WRITE(numout,*) 'Dim size for ',TRIM(clvar),' is ', ilendta
+
+      CALL iom_get ( num, jpdom_unknown, clvar, dta_global(1:ilendta,1:ipj,1:ipk), nrec )
+      !
+      DO ib = 1, ipi
+         DO ik = 1, ipk
+            dta(ib,1,ik) =  dta_global(map(ib),1,ik)
+         END DO
+      END DO
+
+   END SUBROUTINE fld_map
 
    SUBROUTINE fld_rot( kt, sd )
       !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE fld_clopn  ***
+      !!                    ***  ROUTINE fld_rot  ***
       !!
       !! ** Purpose :   Vector fields may need to be rotated onto the local grid direction
@@ -672,5 +753,5 @@
       !
       CALL iom_open( sdjf%clname, sdjf%num, ldstop = ldstop, ldiof =  LEN(TRIM(sdjf%wgtname)) > 0 )
-      !
+     !
    END SUBROUTINE fld_clopn
 
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90	(revision 2797)
@@ -10,5 +10,4 @@
    !!   sbc_apr        : read atmospheric pressure in netcdf files 
    !!----------------------------------------------------------------------
-   USE bdy_par         ! Unstructured boundary parameters
    USE obc_par         ! open boundary condition parameters
    USE dom_oce         ! ocean space and time domain
@@ -30,5 +29,4 @@
    !                                         !!* namsbc_apr namelist (Atmospheric PRessure) *
    LOGICAL, PUBLIC ::   ln_apr_obc = .FALSE.  !: inverse barometer added to OBC ssh data 
-   LOGICAL, PUBLIC ::   ln_apr_bdy = .FALSE.  !: inverse barometer added to BDY ssh data
    LOGICAL, PUBLIC ::   ln_ref_apr = .FALSE.  !: ref. pressure: global mean Patm (F) or a constant (F)
 
@@ -115,13 +113,11 @@
          !
          !                                            !* control check
-         IF( ln_apr_obc .OR. ln_apr_bdy   )   &
-            CALL ctl_stop( 'sbc_apr: inverse barometer added to OBC or BDY ssh data not yet implemented ' )
+         IF( ln_apr_obc  )   &
+            CALL ctl_stop( 'sbc_apr: inverse barometer added to OBC ssh data not yet implemented ' )
          IF( ln_apr_obc .AND. .NOT. lk_obc )   &
             CALL ctl_stop( 'sbc_apr: add inverse barometer to OBC requires to use key_obc' )
-         IF( ln_apr_bdy .AND. .NOT. lk_bdy )   &
-            CALL ctl_stop( 'sbc_apr: add inverse barometer to OBC requires to use key_bdy' )
-         IF( ( ln_apr_obc .OR. ln_apr_bdy ) .AND. .NOT. lk_dynspg_ts )   &
+         IF( ( ln_apr_obc ) .AND. .NOT. lk_dynspg_ts )   &
             CALL ctl_stop( 'sbc_apr: use inverse barometer ssh at open boundary ONLY possible with time-splitting' )
-         IF( ( ln_apr_obc .OR. ln_apr_bdy ) .AND. .NOT. ln_apr_dyn   )   &
+         IF( ( ln_apr_obc ) .AND. .NOT. ln_apr_dyn   )   &
             CALL ctl_stop( 'sbc_apr: use inverse barometer ssh at open boundary ONLY requires ln_apr_dyn=T' )
       ENDIF
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 2797)
@@ -38,6 +38,6 @@
    USE sbcfwb           ! surface boundary condition: freshwater budget
    USE closea           ! closed sea
-   USE bdy_par          ! unstructured open boundary data variables
-   USE bdyice           ! unstructured open boundary data  (bdy_ice_frs routine)
+   USE obc_par          ! for lk_obc
+   USE obcice_lim2      ! unstructured open boundary data  (obc_ice_lim_2 routine)
 
    USE prtctl           ! Print control                    (prt_ctl routine)
@@ -253,5 +253,5 @@
          !                                                      
       CASE(  2 )   ;       CALL sbc_ice_lim_2( kt, nsbc )            ! LIM-2 ice model
-         IF( lk_bdy )      CALL bdy_ice_frs  ( kt )                  ! BDY boundary condition
+         IF( lk_obc )      CALL obc_ice_lim_2( kt )                  ! OBC boundary condition
          !                                                     
       CASE(  3 )   ;       CALL sbc_ice_lim  ( kt, nsbc )            ! LIM-3 ice model
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SOL/solmat.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SOL/solmat.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SOL/solmat.F90	(revision 2797)
@@ -27,5 +27,4 @@
    USE phycst          ! physical constants
    USE obc_oce         ! ocean open boundary conditions
-   USE bdy_oce         ! unstructured open boundary conditions
    USE lbclnk          ! lateral boudary conditions
    USE lib_mpp         ! distributed memory computing
@@ -81,5 +80,5 @@
       ENDIF
 
-#if defined key_dynspg_flt && ! defined key_bdy
+#if defined key_dynspg_flt 
 #   if ! defined key_obc
 
@@ -99,68 +98,8 @@
          END DO
       END DO
+
 #   else
-    IF ( Agrif_Root() ) THEN
-      DO jj = 2, jpjm1                      ! matrix of free surface elliptic system with open boundaries
-         DO ji = 2, jpim1
-            zcoef = z2dt * z2dt * grav * bmask(ji,jj)
-            !                                    ! south coefficient
-            IF( lp_obc_south .AND. ( jj == njs0p1 ) ) THEN
-               zcoefs = -zcoef * hv(ji,jj-1) * e1v(ji,jj-1)/e2v(ji,jj-1)*(1.-vsmsk(ji,1))
-            ELSE
-               zcoefs = -zcoef * hv(ji,jj-1) * e1v(ji,jj-1)/e2v(ji,jj-1)
-            END IF
-            gcp(ji,jj,1) = zcoefs
-            !
-            !                                    ! west coefficient
-            IF( lp_obc_west  .AND. ( ji == niw0p1 ) ) THEN
-               zcoefw = -zcoef * hu(ji-1,jj) * e2u(ji-1,jj)/e1u(ji-1,jj)*(1.-uwmsk(jj,1))
-            ELSE
-               zcoefw = -zcoef * hu(ji-1,jj) * e2u(ji-1,jj)/e1u(ji-1,jj)
-            END IF
-            gcp(ji,jj,2) = zcoefw
-            !
-            !                                    ! east coefficient
-            IF( lp_obc_east  .AND. ( ji == nie0 ) ) THEN
-               zcoefe = -zcoef * hu(ji,jj) * e2u(ji,jj)/e1u(ji,jj)*(1.-uemsk(jj,1))
-            ELSE
-               zcoefe = -zcoef * hu(ji,jj) * e2u(ji,jj)/e1u(ji,jj)
-            END IF
-            gcp(ji,jj,3) = zcoefe
-            !
-            !                                    ! north coefficient
-            IF( lp_obc_north .AND. ( jj == njn0 ) ) THEN
-               zcoefn = -zcoef * hv(ji,jj) * e1v(ji,jj)/e2v(ji,jj)*(1.-vnmsk(ji,1))
-            ELSE
-               zcoefn = -zcoef * hv(ji,jj) * e1v(ji,jj)/e2v(ji,jj)
-            END IF
-            gcp(ji,jj,4) = zcoefn
-            !
-            !                                    ! diagonal coefficient
-            gcdmat(ji,jj) = e1t(ji,jj)*e2t(ji,jj)*bmask(ji,jj)   &
-               &            - zcoefs -zcoefw -zcoefe -zcoefn
-         END DO
-      END DO
-    ELSE
-      DO jj = 2, jpjm1                      ! matrix of free surface elliptic system
-         DO ji = 2, jpim1
-            zcoef = z2dt * z2dt * grav * bmask(ji,jj)
-            zcoefs = -zcoef * hv(ji  ,jj-1) * e1v(ji  ,jj-1) / e2v(ji  ,jj-1)    ! south coefficient
-            zcoefw = -zcoef * hu(ji-1,jj  ) * e2u(ji-1,jj  ) / e1u(ji-1,jj  )    ! west coefficient
-            zcoefe = -zcoef * hu(ji  ,jj  ) * e2u(ji  ,jj  ) / e1u(ji  ,jj  )    ! east coefficient
-            zcoefn = -zcoef * hv(ji  ,jj  ) * e1v(ji  ,jj  ) / e2v(ji  ,jj  )    ! north coefficient
-            gcp(ji,jj,1) = zcoefs
-            gcp(ji,jj,2) = zcoefw
-            gcp(ji,jj,3) = zcoefe
-            gcp(ji,jj,4) = zcoefn
-            gcdmat(ji,jj) = e1t(ji,jj) * e2t(ji,jj) * bmask(ji,jj)    &          ! diagonal coefficient
-               &          - zcoefs -zcoefw -zcoefe -zcoefn
-         END DO
-      END DO
-    ENDIF
-#   endif
-
-#  elif defined key_dynspg_flt && defined key_bdy 
-
-      !   defined gcdmat in the case of unstructured open boundaries
+
+      !   defined gcdmat in the case of open boundaries
       DO jj = 2, jpjm1
          DO ji = 2, jpim1
@@ -169,20 +108,20 @@
             !  south coefficient
             zcoefs = -zcoef * hv(ji,jj-1) * e1v(ji,jj-1)/e2v(ji,jj-1)
-            zcoefs = zcoefs * bdyvmask(ji,jj-1)
+            zcoefs = zcoefs * obcvmask(ji,jj-1)
             gcp(ji,jj,1) = zcoefs
 
             !  west coefficient
             zcoefw = -zcoef * hu(ji-1,jj) * e2u(ji-1,jj)/e1u(ji-1,jj)
-            zcoefw = zcoefw * bdyumask(ji-1,jj)
+            zcoefw = zcoefw * obcumask(ji-1,jj)
             gcp(ji,jj,2) = zcoefw
 
             !  east coefficient
             zcoefe = -zcoef * hu(ji,jj) * e2u(ji,jj)/e1u(ji,jj)
-            zcoefe = zcoefe * bdyumask(ji,jj)
+            zcoefe = zcoefe * obcumask(ji,jj)
             gcp(ji,jj,3) = zcoefe
 
             !  north coefficient
             zcoefn = -zcoef * hv(ji,jj) * e1v(ji,jj)/e2v(ji,jj)
-            zcoefn = zcoefn * bdyvmask(ji,jj)
+            zcoefn = zcoefn * obcvmask(ji,jj)
             gcp(ji,jj,4) = zcoefn
 
@@ -193,4 +132,5 @@
       END DO
 
+#endif
 #endif
 
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SOL/solver.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SOL/solver.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/SOL/solver.F90	(revision 2797)
@@ -23,5 +23,4 @@
    USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
    USE solmat          ! matrix of the solver
-   USE obc_oce         ! Lateral open boundary condition
    USE in_out_manager  ! I/O manager
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 2797)
@@ -36,6 +36,4 @@
    USE obc_oce
    USE obctra          ! open boundary condition (obc_tra routine)
-   USE bdy_par         ! Unstructured open boundary condition (bdy_tra_frs routine)
-   USE bdytra          ! Unstructured open boundary condition (bdy_tra_frs routine)
    USE in_out_manager  ! I/O manager
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
@@ -43,5 +41,4 @@
    USE traqsr          ! penetrative solar radiation (needed for nksr)
    USE traswp          ! swap array
-   USE obc_oce 
 #if defined key_agrif
    USE agrif_opa_update
@@ -81,6 +78,5 @@
       !!              - Apply lateral boundary conditions on (ta,sa) 
       !!             at the local domain   boundaries through lbc_lnk call, 
-      !!             at the radiative open boundaries (lk_obc=T), 
-      !!             at the relaxed   open boundaries (lk_bdy=T), and
+      !!             at the one-way open boundaries (lk_obc=T), 
       !!             at the AGRIF zoom     boundaries (lk_agrif=T)
       !!
@@ -111,5 +107,5 @@
       CALL lbc_lnk( tsa(:,:,:,jp_sal), 'T', 1. )
       !
-#if defined key_obc || defined key_bdy || defined key_agrif
+#if defined key_obc || defined key_agrif
       CALL tra_unswap
 #endif
@@ -118,12 +114,9 @@
       IF( lk_obc )   CALL obc_tra( kt )  ! OBC open boundaries
 #endif
-#if defined key_bdy 
-      IF( lk_bdy )   CALL bdy_tra_frs( kt )  ! BDY open boundaries
-#endif
 #if defined key_agrif
       CALL Agrif_tra                     ! AGRIF zoom boundaries
 #endif
 
-#if defined key_obc || defined key_bdy || defined key_agrif
+#if defined key_obc || defined key_agrif
       CALL tra_swap
 #endif
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 2797)
@@ -45,6 +45,6 @@
    USE mppini          ! shared/distributed memory setting (mpp_init routine)
    USE domain          ! domain initialization             (dom_init routine)
-   USE obcini          ! open boundary cond. initialization (obc_ini routine)
-   USE bdyini          ! unstructured open boundary cond. initialization (bdy_init routine)
+   USE obcini          ! open boundary cond. initialization (obc_init routine)
+   USE obcdta          ! open boundary cond. initialization (obc_dta_init routine)
    USE istate          ! initial state setting          (istate_init routine)
    USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
@@ -294,6 +294,6 @@
       IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
 
-      IF( lk_obc        )   CALL     obc_init   ! Open boundaries 
-      IF( lk_bdy        )   CALL     bdy_init   ! Unstructured open boundaries
+      IF( lk_obc        )   CALL     obc_init       ! Open boundaries initialisation
+      IF( lk_obc        )   CALL     obc_dta_init   ! Open boundaries initialisation of external data arrays
 
                             CALL  istate_init   ! ocean initial state (Dynamics and tracers)
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 2797)
@@ -98,6 +98,4 @@
                          CALL sbc    ( kstp )         ! Sea Boundary Condition (including sea-ice)
       IF( lk_obc     )   CALL obc_dta( kstp )         ! update dynamic and tracer data at open boundaries
-      IF( lk_obc     )   CALL obc_rad( kstp )         ! compute phase velocities at open boundaries
-      IF( lk_bdy     )   CALL bdy_dta_frs( kstp )     ! update dynamic and tracer data for FRS conditions (BDY)
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -247,5 +245,4 @@
       IF( kstp == nit000   )   CALL iom_close( numror )     ! close input  ocean restart file
       IF( lrst_oce         )   CALL rst_write    ( kstp )   ! write output ocean restart file
-      IF( lk_obc           )   CALL obc_rst_write( kstp )   ! write open boundary restart file
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Index: /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/step_oce.F90
===================================================================
--- /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 2796)
+++ /branches/2011/UKMO_MERCATOR_obc_bdy_merge/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 2797)
@@ -48,11 +48,6 @@
    USE dynnxt           ! time-stepping                    (dyn_nxt routine)
 
-   USE obc_par          ! open boundary condition variables
+   USE obc_par          ! for lk_obc
    USE obcdta           ! open boundary condition data     (obc_dta routine)
-   USE obcrst           ! open boundary cond. restart      (obc_rst routine)
-   USE obcrad           ! open boundary cond. radiation    (obc_rad routine)
-
-   USE bdy_par          ! unstructured open boundary data variables
-   USE bdydta           ! unstructured open boundary data  (bdy_dta routine)
 
    USE sshwzv           ! vertical velocity and ssh        (ssh_wzv routine)
