!=======================================
! 2D cumulus model - kaminari
!  - subroutine boundary
! 
! Author    : TAKAHASHI Koko
! Date      : 2003/12/04 $B?75,:n@.(B
! Note      : $B6-3&>r7o$H6-3&$h$j30$NG[Ns$NCM(B
!             $B>e2<6-3&(B: $B$9$Y$j$J$7>r7o(B
!             $BB&LL6-3&(B: $B<~4|6-3&>r7o(B
! 
!=======================================
subroutine boundary(im,km,                  &
     &              u,w,pi,ptemp)

  implicit none

  integer(8), intent(in) :: im, km

  real(8), intent(inout) :: u(-2:im,-2:km+1)
  real(8), intent(inout) :: w(-2:im+1,-2:km)

  real(8), intent(inout) :: pi(-2:im,-2:km)
  real(8), intent(inout) :: ptemp(-2:im,-2:km)

  ! $B>e2<6-3&(B
  !---  k = 0 : $B2<It6-3&(B
  u(0:im-3,0) = 0.0d0
  w(0:im-3,0) = 0.0d0

  !---  k = km+1 : $B>eIt6-3&(B
  u(0:im-3,km-1) = 0.0d0
  w(0:im-3,km-2) = 0.0d0

  ! $B6-3&MQ$NG[Ns(B
  !---  $B2<It(B-1$B6-3&(B
  u(0:im-3,-1) = u(0:im-3,0)
  w(0:im-2,-1) = w(0:im-2,0)
  pi(0:im-3,-1) = pi(0:im-3,0)
  ptemp(0:im-3,-1) = ptemp(0:im-3,0)

  !---  $B2<It(B-2$B6-3&(B
  u(0:im-3,-2) = u(0:im-3,0)
  w(0:im-2,-2) = w(0:im-2,0)
  pi(0:im-3,-2) = pi(0:im-3,0)
  ptemp(0:im-3,-2) = ptemp(0:im-3,0)

  !---  $B>eIt(B+1$B6-3&(B
  u(0:im-3,km) = u(0:im-3,km-1)
  w(0:im-2,km-1) = w(0:im-2,km-2)
  pi(0:im-3,km-1) = pi(0:im-3,km-2)
  ptemp(0:im-3,km-1) = ptemp(0:im-3,km-2)

  !---  $B>eIt(B+2$B6-3&(B
  u(0:im-3,km+1) = u(0:im-3,km-1)
  w(0:im-2,km) = w(0:im-2,km-2)
  pi(0:im-3,km) = pi(0:im-3,km-2)
  ptemp(0:im-3,km) = ptemp(0:im-3,km-2)

  !---  $B1&C<B&LL6-3&(B
  !--- $B<~4|6-3&>r7o(B
  u(im-2,-2:km+1) = u(0,-2:km+1)
  w(im-1,-2:km) = w(0,-2:km)
  pi(im-2,-2:km) = pi(0,-2:km)
  ptemp(im-2,-2:km) = ptemp(0,-2:km)

  !---  $B1&C<(B+1 $BB&LL6-3&(B
  u(im-1,-2:km+1) = u(1,-2:km+1)
  w(im,-2:km) = w(1,-2:km)
  pi(im-1,-2:km) = pi(1,-2:km)
  ptemp(im-1,-2:km) = ptemp(1,-2:km)

  !---  $B1&C<(B+2 $BB&LL6-3&(B
  u(im,-2:km+1) = u(2,-2:km+1)
  w(im+1,-2:km) = w(2,-2:km)
  pi(im,-2:km) = pi(2,-2:km)
  ptemp(im,-2:km) = ptemp(2,-2:km)

  !---  $B:8C<(B-1 $BB&LL6-3&(B
  u(-1,-2:km+1) = u(im-3,-2:km+1)
  w(-1,-2:km) = w(im-2,-2:km)
  pi(-1,-2:km) = pi(im-3,-2:km)
  ptemp(-1,-2:km) = ptemp(im-3,-2:km)

  !---  $B:8C<(B-2 $BB&LL6-3&(B
  u(-2,-2:km+1) = u(im-4,-2:km+1)
  w(-2,-2:km) = w(im-3,-2:km)
  pi(-2,-2:km) = pi(im-4,-2:km)
  ptemp(-2,-2:km) = ptemp(im-4,-2:km)

end subroutine boundary

