!=======================================
! 2D cumulus model - kaminari
!  - subroutine base
! 
! Author    : TAKAHASHI Koko
! Date      : 2003/12/04 $B?75,:n@.(B
! Note      : $B4pK\>l$N7W;;(B
! 
!=======================================
subroutine base(im,km,dz,prss_sfc,rd,cp,cv,grv,g_sqrt,      &
     &          qv_bs,prss_bs,pi_bs,temp_bs,ptemp_bs,       &
     &          vptemp_bs,dens_bs)

  implicit none

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

  real(8), intent(in) :: dz
  real(8), intent(in) :: prss_sfc, rd, cp, cv, grv

  real(8), intent(in) :: g_sqrt(-2:im,-2:km)

  real(8), intent(out) :: qv_bs(-2:im,-2:km)
  real(8), intent(out) :: prss_bs(-2:im,-2:km)
  real(8), intent(out) :: pi_bs(-2:im,-2:km)
  real(8), intent(out) :: temp_bs(-2:im,-2:km)
  real(8), intent(out) :: ptemp_bs(-2:im,-2:km)
  real(8), intent(out) :: vptemp_bs(-2:im,-2:km)
  real(8), intent(out) :: dens_bs(-2:im,-2:km)

  integer(8)           :: i, k

  !--- $BA4BN$N29EY$H?e>x5$$N:.9gHf$rM?$($k(B
  do k = 0, km-2
     do i = 0, im-3
        !--- $B29EY(B
        temp_bs(i,k) = 3.0d2! - 6.5d-3*z(i,k)

        !--- $B?e>x5$$N:.9gHf(B
        qv_bs(i,k) = 0.0d0
     end do
  end do

  !--- $BCOI=LL05NO$rM?$($k(B
  do i =0,im-3
     prss_bs(i,0) = prss_sfc
  end do

  !--- $BCOI=LL$G$N3FCM$N7W;;(B
  do i = 0, im-3
     !--- $BL5<!8505NO(B
     pi_bs(i,0) = (prss_bs(i,0)/prss_sfc)**(rd/cp)

     !--- $B290L(B
     ptemp_bs(i,0) = temp_bs(i,0)/pi_bs(i,0)

     !--- $B2>290L(B
     vptemp_bs(i,0) = ptemp_bs(i,0)*(1.0d0 + 6.1d-2*qv_bs(i,0))

     !--- $BL)EY(B
     dens_bs(i,0) = prss_sfc/rd*pi_bs(i,0)**(cv/rd)/vptemp_bs(i,0)
  end do

  !--- $BCOI=LL$h$j>e$G$N3FCM(B
!  k = 1
  do i = 0, im-3
     !--- $B@E?e05J?9U$N<0(B -> $BL5<!8505NO(B
     pi_bs(i,1) = pi_bs(i,0)                           &
          &       - dz*g_sqrt(i,0)*grv/(cp*vptemp_bs(i,0))

     !--- $B05NO(B
     prss_bs(i,1) = prss_sfc*pi_bs(i,1)**(cp/rd)

     !--- $B290L(B
     ptemp_bs(i,1) = temp_bs(i,1)/pi_bs(i,1)

     !--- $B2>290L(B
     vptemp_bs(i,1) = ptemp_bs(i,1)*(1.0d0 + 6.1d-2*qv_bs(i,1))

     !--- $BL)EY(B
     dens_bs(i,1) = prss_sfc*pi_bs(i,1)**(cv/cp)/(rd*vptemp_bs(i,1))
  end do

  !--- $BCOI=LL$h$j>e$G$N3FCM(B
  do k = 2, km-2
     do i = 0, im-3
        !--- $B@E?e05J?9U$N<0(B -> $BL5<!8505NO(B
        pi_bs(i,k) = pi_bs(i,k-2)                           &
             &       - 2.0d0*dz*g_sqrt(i,k-1)               &
             &         *grv/(cp*vptemp_bs(i,k-1))

        !--- $B05NO(B
        prss_bs(i,k) = prss_sfc*pi_bs(i,k)**(cp/rd)

        !--- $B290L(B
        ptemp_bs(i,k) = temp_bs(i,k)/pi_bs(i,k)

        !--- $B2>290L(B
        vptemp_bs(i,k) = ptemp_bs(i,k)*(1.0d0 + 6.1d-2*qv_bs(i,k))

        !--- $BL)EY(B
        dens_bs(i,k) = prss_sfc*pi_bs(i,k)**(cv/rd)/(rd*vptemp_bs(i,k))
     end do
  end do

end subroutine base
