!=======================================
! 2D cumulus model - kaminari
!  - subroutine init_value
! 
! Author    : TAKAHASHI Koko
! Date      : 2003/12/23  $B:G=*99?7(B
!             2003/11/11  $B?75,:n@.(B
! Note      : $B=i4|CM@_Dj(B
!
!=======================================
!--- 1$B9TL\F~NOJQ?t(B, 2,3$B9TL\=PNO(Bq$BJQ?t(B
subroutine init_value(im,km,dx,cp,rd,prss_sfc,prss_bs,   &
     &                pi_bs,temp_bs,                        &
     &                u,w,prss,pi,temp,ptemp,vptemp,qv)
 
  implicit none

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

  real(8), intent(in) :: dx
!  real(8), intent(in) :: dz
  real(8), intent(in) :: cp, rd, prss_sfc

  real(8), intent(in) :: prss_bs(-2:im+2,-2:km+2)
  real(8), intent(in) :: pi_bs(-2:im+2,-2:km+2)
  real(8), intent(in) :: temp_bs(-2:im+2,-2:km+2)

  real(8), intent(out) :: u(-2:im+2,-2:km+2)
  real(8), intent(out) :: w(-2:im+2,-2:km+3)
  real(8), intent(out) :: prss(-2:im+2,-2:km+2)
  real(8), intent(out) :: pi(-2:im+2,-2:km+2)
  real(8), intent(out) :: temp(-2:im+2,-2:km+2)
  real(8), intent(out) :: ptemp(-2:im+2,-2:km+2)
  real(8), intent(out) :: vptemp(-2:im+2,-2:km+2)
  real(8), intent(out) :: qv(-2:im+2,-2:km+2)
!  real(8), intent(out) :: qc(-2:im+2,-2:km+2)
!  real(8), intent(out) :: qr(-2:im+2,-2:km+2)
!  real(8), intent(out) :: km_sub(-2:im+2,-2:km+2)

  integer(8)             :: i, k

  real(8)             :: x(0:im,0:km)
!  real(8)             :: z(0:im,0:km)
  real(8)             :: pi_all(-2:im+2,-2:km+2)

  !---------------------------
  !--- $B:BI8<4(B
  do k = 0,km
     do i = 0,im
        x(i,k) = dx*i
!        z(i,k) = dz*k
     end do
  end do

  !---------------------------
  !--- $B=i4|CM$rM?$($k(B
  !--- $B?eJ?B.EY(B u
  u(0:im,0:km) = 1.0d1

  !--- $B1tD>B.EY(B w
  w(0:im,1:km) = 0.0d0

  do k = 0,km
     do i = 0,im
        !--- $B05NO(B
!        prss(i,k) = prss_bs(i,k)                                &
!             &      + 1.0d3*exp(-(x(i,k)-2.4d4/2.0d0)**2.0d0/(5.0d6) &
!             &          -(z(i,k)-1.0d4/2.0d0)**2.0d0/(1.0d6))
        prss(i,k) = prss_bs(i,k)

        !--- $B29EY(B
        temp(i,k) = temp_bs(i,k)                                 &
             &      + 5.0d-1*exp(-(x(i,k) - 1.0d4/2.0d0)**2.0d0/5.0d6)! &
!             &             -(z(i,k))**2.0d0/5.0d4)
!        temp(i,k) = temp_bs(i,k)

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

        !--- $B1@?e$N:.9gHf(B
        !  qc(i,k) = 0.00d0

        !--- $B1+?e$N:.9gHf(B
        !  qr(i,k) = 0.00d0

        !--- $B12:.9g78?t(B
        !  km_sub(i,k) = 0.0d0

        !-------------------------------
        !--- $BM?$($?=i4|CM$+$i7W;;(B
        !--- $B4pK\>l$r4^$`L5<!8505NO(B
        call prss2pi(i,k,im,km,prss_sfc,rd,cp,prss,pi_all)
        !--- $B>qMp$N$_$NL5<!8505NO(B
        pi(i,k) = pi_all(i,k) - pi_bs(i,k)

        !--- $B290L(B
        ptemp(i,k) = temp(i,k)/pi_all(i,k)

        !--- $B2>290L(B
        vptemp(i,k) = ptemp(i,k)*(1.0d0 + 6.1d-2*qv(i,k))
     end do
  end do

end subroutine init_value

