   !!======================================================================

  SUBROUTINE obc2d_rank_rotated

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE obc2d_rank_rotated ***
   !&E
   !&E ** Purpose : Read a sea surface height from an obc file issued from
   !&E              a previous rank
   !&E
   !&E ** Description : At open boundaries, the final signal is
   !&E                  - the sea level issued from a previous rank
   !&E
   !&E                  Rotated boundaries case : variables have been
   !&E                  previously interpolated on the child grid
   !&E
   !&E ** Called by : obc2drank.F90
   !&E
   !&E ** External calls :
   !&E
   !&E ** Used ij-arrays :
   !&E
   !&E ** Modified variables : obc_tide_sshw,obc_tide_sshe,
   !&E                         obc_tide_sshs,obc_tide_sshn,
   !&E                         obc_tide_us,obc_tide_vs,obc_tide_uw,obc_tide_vw,
   !&E                         obc_tide_un,obc_tide_vn,obc_tide_ue,obc_tide_ve
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2008-02  (F. Dumas)  Original code
   !&E       !  2009-03 (V. Garnier)  removing of xeuv argument
   !&E                                initialization of obc_tide_ssh*
   !&E                                old obc2drankstraight.F90
   !&E       !  2009-10 (F. Dumas) Introduction of overtide functionality
   !&E       !  2010-05 (F. Vandermeirsch) Interpolation of velocities
   !&E       !          (dirichlet and characteristics methodology
   !&E       !  2011-11  (V. Garnier) Spatial extension of ssh(liminm2:limaxp2,ljminm2:ljmaxp2)
   !&E
   !&E---------------------------------------------------------------------

#include "toolcpp.h"

   !! * Modules used
   USE parameters, ONLY : imin,imax,jmin,jmax,valmanq,liminm2,limaxp2,ljminm2,ljmaxp2
   USE comvars2d
   USE comstatic
   USE obccombine, ONLY : obc_tide_sshs,obc_tide_sshn,obc_tide_sshe,obc_tide_sshw, &
                          obc_tide_us,obc_tide_vs,obc_tide_uw,obc_tide_vw,         &
                          obc_tide_un,obc_tide_vn,obc_tide_ue,obc_tide_ve
   USE_MPI toolmpi,ONLY : MASTER

   IMPLICIT NONE

   !! * Arguments

   !! * Local declarations
   INTEGER              :: i,j
   REAL(kind=rsh)       :: alf
   CHARACTER (len=19) :: tool_sectodat,ccdate

   !!----------------------------------------------------------------------
   !! * Executable part

   IF (.NOT. l_tide_surge) THEN
     obc_tide_sshs(:)=0.0_rsh
     obc_tide_sshn(:)=0.0_rsh
     obc_tide_sshe(:)=0.0_rsh
     obc_tide_sshw(:)=0.0_rsh
   ELSE
     filecl=file_surge_meteo
   END IF

   IF(nbouc == 0) THEN

     OPEN(13,file = filecl,form='unformatted')
     READ(13) t1,(xe1_n(i),xe1_s(i),u1_n(i),v1_n(i,1),v1_n(i,2),u1_s(i),v1_s(i,1),v1_s(i,2),i=imin,imax)
     READ(13)    (xe1_w(j),xe1_e(j),u1_w(1,j),u1_w(2,j),v1_w(j),u1_e(1,j),u1_e(2,j),v1_e(j),j=jmin,jmax)

     IF(t < t1) THEN
       WRITE(ierrorlog,*) 'ERROR: In OBC2D_RANK_ROTATED.F90,'
       WRITE(ierrorlog,*) 'the simulation starts before the 1st available SSH condition'
       WRITE(ierrorlog,*) 'If this is not rank 0, modify the "date_startshift" parameter'
       WRITE(ierrorlog,*) 'in the "paraspec.txt" file.'
       WRITE(ierrorlog,*) 'Simulation stopped.'
       STOP
     ENDIF

     ccdate=tool_sectodat(t1)
     IF_MPI (MASTER) THEN
     WRITE(iscreenlog,*) ' '
     WRITE(iscreenlog,*) 'OBC2D_RANK_ROTATED.F90:'
     WRITE(iscreenlog,*) 'The 1st open boundary condition is available at: '
     WRITE(iscreenlog,*) 'time = ',t1,' in sec., corresponding to the date: ',ccdate
     ENDIF_MPI
     ccdate=tool_sectodat(t)
     IF_MPI (MASTER) &
     WRITE(iscreenlog,*) 'The start date of the simulation is: ',ccdate

     READ(13,END=34,err=35)t2,(xe2_n(i),xe2_s(i),u2_n(i),v2_n(i,1),v2_n(i,2),u2_s(i),v2_s(i,1),v2_s(i,2),i=imin,imax)
     READ(13)                 (xe2_w(j),xe2_e(j),u2_w(1,j),u2_w(2,j),v2_w(j),u2_e(1,j),u2_e(2,j),v2_e(j),j=jmin,jmax)

   END IF

!---------------------------
9 CONTINUE                 !     deroulement normal
   IF(t-t1 <= 0.0_rlg)THEN

     ulim_n(imin:imax)=u1_n(imin:imax)
     ulim_s(imin:imax)=u1_s(imin:imax)
     ulim_e(1:2,jmin:jmax)=u1_e(1:2,jmin:jmax)
     ulim_w(1:2,jmin:jmax)=u1_w(1:2,jmin:jmax)

     vlim_n(imin:imax,1:2)=v1_n(imin:imax,1:2)
     vlim_s(imin:imax,1:2)=v1_s(imin:imax,1:2)
     vlim_e(jmin:jmax)=v1_e(jmin:jmax)
     vlim_w(jmin:jmax)=v1_w(jmin:jmax)

     hlim_s(imin:imax)=xe1_s(imin:imax)
     hlim_n(imin:imax)=xe1_n(imin:imax)
     hlim_w(jmin:jmax)=xe1_w(jmin:jmax)
     hlim_e(jmin:jmax)=xe1_e(jmin:jmax)

   ELSE

     IF(t-t2 <= 0.0_rlg) THEN
       alf=(t2-t)/(t2-t1)

       ulim_s(imin:imax)=alf*u1_s(imin:imax)+(1.0_rlg-alf)*u2_s(imin:imax)
       ulim_n(imin:imax)=alf*u1_n(imin:imax)+(1.0_rlg-alf)*u2_n(imin:imax)
       ulim_w(1:2,jmin:jmax)=alf*u1_w(1:2,jmin:jmax)+(1.0_rlg-alf)*u2_w(1:2,jmin:jmax)
       ulim_e(1:2,jmin:jmax)=alf*u1_e(1:2,jmin:jmax)+(1.0_rlg-alf)*u2_e(1:2,jmin:jmax)

       vlim_s(imin:imax,1:2)=alf*v1_s(imin:imax,1:2)+(1.0_rlg-alf)*v2_s(imin:imax,1:2)
       vlim_n(imin:imax,1:2)=alf*v1_n(imin:imax,1:2)+(1.0_rlg-alf)*v2_n(imin:imax,1:2)
       vlim_w(jmin:jmax)=alf*v1_w(jmin:jmax)+(1.0_rlg-alf)*v2_w(jmin:jmax)
       vlim_e(jmin:jmax)=alf*v1_e(jmin:jmax)+(1.0_rlg-alf)*v2_e(jmin:jmax)

       hlim_s(imin:imax)=alf*xe1_s(imin:imax)+(1.0_rlg-alf)*xe2_s(imin:imax)
       hlim_n(imin:imax)=alf*xe1_n(imin:imax)+(1.0_rlg-alf)*xe2_n(imin:imax)
       hlim_w(jmin:jmax)=alf*xe1_w(jmin:jmax)+(1.0_rlg-alf)*xe2_w(jmin:jmax)
       hlim_e(jmin:jmax)=alf*xe1_e(jmin:jmax)+(1.0_rlg-alf)*xe2_e(jmin:jmax)

     ELSE
       t1=t2

       u1_s(imin:imax)=u2_s(imin:imax)
       u1_n(imin:imax)=u2_n(imin:imax)
       u1_w(1:2,jmin:jmax)=u2_w(1:2,jmin:jmax)
       u1_e(1:2,jmin:jmax)=u2_e(1:2,jmin:jmax)

       v1_s(imin:imax,1:2)=v2_s(imin:imax,1:2)
       v1_n(imin:imax,1:2)=v2_n(imin:imax,1:2)
       v1_w(jmin:jmax)=v2_w(jmin:jmax)
       v1_e(jmin:jmax)=v2_e(jmin:jmax)

       xe1_s(imin:imax)=xe2_s(imin:imax)
       xe1_n(imin:imax)=xe2_n(imin:imax)
       xe1_w(jmin:jmax)=xe2_w(jmin:jmax)
       xe1_e(jmin:jmax)=xe2_e(jmin:jmax)

       READ(13,END=34,err=35)t2,(xe2_n(i),xe2_s(i),u2_n(i),v2_n(i,1),v2_n(i,2),u2_s(i),v2_s(i,1),v2_s(i,2),i=imin,imax)
       READ(13)                 (xe2_w(j),xe2_e(j),u2_w(1,j),u2_w(2,j),v2_w(j),u2_e(1,j),u2_e(2,j),v2_e(j),j=jmin,jmax)

       GOTO 9
     END IF

   END IF


   IF_MPI (ljmin==jmin) THEN
     obc_tide_sshs(liminm2:limaxp2)=obc_tide_sshs(liminm2:limaxp2)+hlim_s(liminm2:limaxp2)
     WHERE(h0(liminp1m2:limaxp2,jmin+1)==-valmanq) obc_tide_sshs(liminp1m2:limaxp2)=valmanq
     obc_tide_us(limin:limax,jmin+1)=ulim_s(limin:limax)
     obc_tide_vs(limin:limax,jmin:jmin+1)=vlim_s(limin:limax,1:2)
     WHERE(hx(limin:limax,jmin+1)==-valmanq) obc_tide_us(limin:limax,jmin+1)=0.0_rsh
     WHERE(hy(limin:limax,jmin:jmin+1)==-valmanq) obc_tide_vs(limin:limax,jmin:jmin+1)=0.0_rsh
   ENDIF_MPI

   IF_MPI (ljmax==jmax) THEN
     obc_tide_sshn(liminm2:limaxp2)=obc_tide_sshn(liminm2:limaxp2)+hlim_n(liminm2:limaxp2)
     WHERE(h0(liminp1m2:limaxp2,jmax)==-valmanq) obc_tide_sshn(liminp1m2:limaxp2)=valmanq
     obc_tide_un(limin:limax,jmax)=ulim_n(limin:limax)
     obc_tide_vn(limin:limax,jmax-1:jmax)=vlim_n(limin:limax,1:2)
     WHERE(hx(limin:limax,jmax)==-valmanq) obc_tide_un(limin:limax,jmax)=0.0_rsh
     WHERE(hy(limin:limax,jmax-1:jmax)==-valmanq) obc_tide_vn(limin:limax,jmax-1:jmax)=0.0_rsh
   ENDIF_MPI

   IF_MPI (limin==imin) THEN
     obc_tide_sshw(ljminm2:ljmaxp2)=obc_tide_sshw(ljminm2:ljmaxp2)+hlim_w(ljminm2:ljmaxp2)
     WHERE(h0(imin+1,ljminp1m2:ljmaxp2)==-valmanq) obc_tide_sshw(ljminp1m2:ljmaxp2)=valmanq
     obc_tide_vw(imin+1,ljmin:ljmax)=vlim_w(ljmin:ljmax)
     obc_tide_uw(imin:imin+1,ljmin:ljmax)=ulim_w(1:2,ljmin:ljmax)
     WHERE(hx(imin:imin+1,ljmin:ljmax)==-valmanq) obc_tide_uw(imin:imin+1,ljmin:ljmax)=0.0_rsh
     WHERE(hy(imin+1,ljmin:ljmax)==-valmanq) obc_tide_vw(imin+1,ljmin:ljmax)=0.0_rsh
   ENDIF_MPI

   IF_MPI (limax==imax) THEN
     obc_tide_sshe(ljminm2:ljmaxp2)=obc_tide_sshe(ljminm2:ljmaxp2)+hlim_e(ljminm2:ljmaxp2)
     WHERE(h0(imax,ljminp1m2:ljmaxp2)==-valmanq) obc_tide_sshe(ljminp1m2:ljmaxp2)=valmanq
     obc_tide_ve(imax,ljmin:ljmax)=vlim_e(ljmin:ljmax)
     obc_tide_ue(imax-1:imax,ljmin:ljmax)=ulim_e(1:2,ljmin:ljmax)
     WHERE(hx(imax-1:imax,ljmin:ljmax)==-valmanq) obc_tide_ue(imax-1:imax,ljmin:ljmax)=0.0_rsh
     WHERE(hy(imax,ljmin:ljmax)==-valmanq) obc_tide_ve(imax,ljmin:ljmax)=0.0_rsh
   ENDIF_MPI


   RETURN
34 WRITE(ierrorlog,*) 'ERROR: In OBC2D_RANK_ROTATED.F90,'
   WRITE(ierrorlog,*) 'The open boundary file (from previous rank) is not long enough.'
   WRITE(ierrorlog,*) 'Simulation stopped.'
   STOP
35 WRITE(ierrorlog,*) 'ERROR: In OBC2D_RANK_ROTATED.F90,'
   WRITE(ierrorlog,*) 'Problem while reading the 2nd open boundary file (from previous rank).'
   WRITE(ierrorlog,*) 'Simulation stopped.'
   STOP

  END SUBROUTINE obc2d_rank_rotated
