!&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
      subroutine bocov3_cb(ub,im,jm)
!     ******************************************************************
!     *                                                                *
!     *  boundary conditions for a wind related scalar defined in the  *
!     *  wind points on the cube                                       *
!     *                                                                *
!     ******************************************************************
!-----------------------------------------------------------------------
       implicit none
       integer,parameter:: nm=6
       integer, intent(in):: im,jm
       real, dimension(0:im+1,0:jm+1,nm):: ub,vb
       integer:: i,j,im1,jm1,n,nl,nr

       im1=im-1
       jm1=jm-1

       vb=ub
!-----------------------------------------------------------------------
!                lateral faces                                          
!-----------------------------------------------------------------------
!
! lateral conditions
!
      do n=1,4
        nl=n-1+4*((5-n)/4)
        nr=n+1-4*(n/4)
          do j=1,jm1
            ub(im,j,n)=ub(1  ,j,nr)
            ub(0 ,j,n)=ub(im1,j,nl)
          end do
      end do
!
! lower and upper conditions
!
      do i=1,im1
        ub(i,0 ,1)= ub(i,jm1,6)              !   face 1
        ub(i,jm,1)= ub(i,1  ,5)
        ub(i,0 ,2)=-vb(im1,jm-i,6)           !   face 2
        ub(i,jm,2)=-vb(im1,i   ,5)
        ub(i,0 ,3)=ub(im-i,  1,6)            !   face 3
        ub(i,jm,3)=ub(im-i,jm1,5)
        ub(i, 0,4)=-vb(1,i   ,6)             !   face 4
        ub(i,jm,4)=-vb(1,jm-i,5)
      end do
!-----------------------------------------------------------------------
!                upper and lower faces                                  
!-----------------------------------------------------------------------
!
! lateral conditions
!
      do j=1,jm1
        ub(0 ,j,5)= -vb(im-j,jm1,4)             !   face 5
        ub(im,j,5)=-vb(j   ,jm1,2)
        ub(0 ,j,6)=-vb(j   ,1,4)                !   face 6
        ub(im,j,6)= -vb(im-j,1,2)
      end do
!
! lower and upper conditions
!
      do i=1,im1
        ub(i,0 ,5)= ub(i   ,jm1,1)              !   face 5
        ub(i,jm,5)=ub(im-i,jm1,3)
        ub(i, 0,6)=ub(im-i,1,3)                 !   face 6
        ub(i,im,6)= ub(i   ,1,1)
      end do

      ub(0,0,:)=0.
      ub(0,jm,:)=0.
      ub(im,0,:)=0.
      ub(im,jm,:)=0.

!-----------------------------------------------------------------------
      return
      end subroutine bocov3_cb
