!=======================================
! 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,-2:km+2)
  real(8), intent(inout) :: w(-2:im+2,-2:km+2)

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

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

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

  ! $B6-3&7W;;MQ$NG[Ns(B
  !---  k = -1 : $B2<It6-3&(B
  u(0:im,-1) = u(0:im,0)
  w(0:im,-1) = w(0:im,0)
  pi(0:im,-1) = pi(0:im,0)
  ptemp(0:im,-1) = ptemp(0:im,0)

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

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

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

  ! $B6-3&7W;;MQ$NG[Ns(B
  !---  i = im+1 : $B1&C<B&LL6-3&(B
  u(im+1,-2:km+2) = u(0,-2:km+2)
  w(im+1,-2:km+2) = w(0,-2:km+2)
  pi(im+1,-2:km+2) = pi(0,-2:km+2)
  ptemp(im+1,-2:km+2) = ptemp(0,-2:km+2)

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

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

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

end subroutine boundary

