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

  SUBROUTINE tide_saveobc(x,u,v)

!&E---------------------------------------------------------------------
!&E                 ***  ROUTINE flx_cd  ***
!&E
!&E ** Purpose : Save obc file for embedded child configuration (rank)
!&E
!&E ** Description : save the sea surface height and the baroitropic velocities
!&E
!&E ** Called by :
!&E
!&E ** External calls :
!&E
!&E ** Used ij-arrays :
!&E
!&E ** Modified variables :
!&E
!&E ** Reference :
!&E
!&E ** History :
!&E       !  1987-02  (J.-C. Salomon, P. Lazure)  Original code
!&E       !  2008-08  (T. Odaka) MPI
!&E       !  2008-08 (P. Karleskind) simultaneous saving of obc for different child grids
!&E       !  2011-11  (V. Garnier) Spatial extension of ssh(liminm2:limaxp2,ljminm2:ljmaxp2)
!&E
!&E---------------------------------------------------------------------





























































!! * Modules used
   USE parameters
   USE comvars2d, only : obcrk_maxnbfile
   USE toolmpi, only:MASTER,correct_rsh


   IMPLICIT NONE

!! * Arguments
   REAL(KIND=rsh),DIMENSION(liminm2:limaxp2,ljminm2:ljmaxp2),INTENT(IN) :: x
   REAL(KIND=rsh),DIMENSION(liminm2:limaxp2,ljminm2:ljmaxp2),INTENT(IN) :: u,v

!! * Local declarations

   INTEGER :: obcrk_num    ! index of the child grid

   REAL(KIND=rsh), ALLOCATABLE,DIMENSION(:,:)                 :: gx,gu,gv

!!----------------------------------------------------------------------
!! * Executable part
!tina:
!for the moment, MASTER corrects x u and v and only the master writes
!down. i.e. it communicate a lot. thus if this subroutine will be used a lot
!I need only to exchange some edge value.
   ALLOCATE(gx(imin:imax,jmin:jmax))
   ALLOCATE(gu(imin:imax,jmin:jmax))
   ALLOCATE(gv(imin:imax,jmin:jmax))
   gx(limin:limax,ljmin:ljmax)=x(limin:limax,ljmin:ljmax)
   gu(limin:limax,ljmin:ljmax)=u(limin:limax,ljmin:ljmax)
   gv(limin:limax,ljmin:ljmax)=v(limin:limax,ljmin:ljmax)
   CALL correct_rsh(gx,x(limin:limax,ljmin:ljmax),1)
   CALL correct_rsh(gu,u(limin:limax,ljmin:ljmax),1)
   CALL correct_rsh(gv,v(limin:limax,ljmin:ljmax),1)
   IF (MASTER) THEN
     DO obcrk_num=1,obcrk_maxnbfile  ! loop on child grids

       CALL tide_saveobcns(gx,gu,gv,obcrk_num)
       CALL tide_saveobcew(gx,gu,gv,obcrk_num)

     END DO
   END IF
   DEALLOCATE(gx,gu,gv)



  END SUBROUTINE tide_saveobc
