!=======================================
! 2D cumulus model - kaminari
!  - subroutine init_value
!
! Author    : TAKAHASHI Koko
! Date      : 2003/12/23  最終更新
!             2003/11/11  新規作成
! Note      : 初期値設定
!
!=======================================
!--- 1行目入力変数, 2,3行目出力q変数
subroutine init_value(im,km,dx,dz,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)

  !---------------------------
  !--- 座標軸
  do k = 0,km
     do i = 0,im
        x(i,k) = dx*i
        z(i,k) = dz*k
     end do
  end do

  !---------------------------
  !--- 初期値を与える
  !--- 水平速度 u
  u(0:im,0:km) = 0.0d0

  !--- 鉛直速度 w
  w(0:im,1:km) = 0.0d0

  do k = 0,km
     do i = 0,im
        !--- 圧力
!        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)

        !--- 温度
        temp(i,k) = temp_bs(i,k)                                 &
             &      + 1.0d-0*exp(-(x(i,k) - 2.4d4/2.0d0)**2.0d0/5.0d6 &
             &             -(z(i,k))**2.0d0/5.0d4)
!        temp(i,k) = temp_bs(i,k)

        !--- 水蒸気の混合比
        qv(i,k) = 0.0d0

        !--- 雲水の混合比
        !  qc(i,k) = 0.00d0

        !--- 雨水の混合比
        !  qr(i,k) = 0.00d0

        !--- 渦混合係数
        !  km_sub(i,k) = 0.0d0

        !-------------------------------
        !--- 与えた初期値から計算
        !--- 基本場を含む無次元圧力
        call prss2pi(i,k,im,km,prss_sfc,rd,cp,prss,pi_all)
        !--- 擾乱のみの無次元圧力
        pi(i,k) = pi_all(i,k) - pi_bs(i,k)

        !--- 温位
        ptemp(i,k) = temp(i,k)/pi_all(i,k)

        !--- 仮温位
        vptemp(i,k) = ptemp(i,k)*(1.0d0 + 6.1d-2*qv(i,k))
     end do
  end do

end subroutine init_value