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

  integer              :: i, k

  ! $B>e2<6-3&(B
  !---  k = 0 : $B2<It6-3&(B
  !--- $B$9$Y$j$J$7>r7o(B
  do i = 0,im-2
     u(i,0) = 0.0d0
     w(i,0) = 0.0d0
  end do

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

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

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

  !---  k = km : $B>eIt6-3&(B
  do i = 0,im-2
     u(i,km) = 0.0d0
     w(i,km) = 0.0d0
     pi(i,km) = pi(i,km-1)
     ptemp(i,km) = ptemp(i,km-1)
  end do

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

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

  !---  i = im : $BB&LL6-3&(B
  do k = -2,km+1
     u(im,k) = u(1,k)
     w(im,k) = w(1,k)
     pi(im,k) = pi(1,k)
     ptemp(im,k) = ptemp(1,k)
  end do

  !---  i = im+1 : $BB&LL6-3&(B
  do k = -2,km+1
     u(im+1,k) = u(2,k)
     w(im+1,k) = w(2,k)
     pi(im+1,k) = pi(2,k)
     ptemp(im+1,k) = ptemp(2,k)
  end do

  !---  i = -1 : $BB&LL6-3&(B
  do k = -2,km+1
     u(-1,k) = u(im-2,k)
     w(-1,k) = w(im-2,k)
     pi(-1,k) = pi(im-2,k)
     ptemp(-1,k) = ptemp(im-2,k)
  end do

  !---  i = -2 : $BB&LL6-3&(B
  do k = -2,km+1
     u(-2,k) = u(im-3,k)
     w(-2,k) = w(im-3,k)
     pi(-2,k) = pi(im-3,k)
     ptemp(-2,k) = ptemp(im-3,k)
  end do

end subroutine boundary

