!c Description: 
!c   仮温位の数値積分 (Eular 法)
!c
!c Current Code Owner: 
!c   sugiyama@gfd-dennou.org
!c
!c Copyright (C) SUGIYAMA Ko-ichiro, 2004, All rights reserved

subroutine ThetaEular(fs_VelX_LB, sf_VelZ_LB, ss_Theta_LB, ss_Theta_LA)

  !--- モジュールの読み込み
  use gridset,  only: DimXMin, DimXMax, DimZMin, DimZMax
  use bcset,    only: ss_Bc
  use timeset,  only: DelTLong
  use if_avr,   only: ss_avr_fs, ss_avr_sf
  use if_diff,  only: ss_dx_ss, ss_dz_ss
  use if_boundary
  
  !--- 暗黙の型宣言禁止
  implicit none
  
  !--- 入出力変数
  real(8), intent(in)     :: fs_VelX_LB(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(in)     :: sf_VelZ_LB(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(in)     :: ss_Theta_LB(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)    :: ss_Theta_LA(DimXMin:DimXMax, DimZMin:DimZMax)

  !--- 内部変数
  real(8)       :: ss_AdvTheta_LB(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8)       :: ss_DiffuseTheta_LB(DimXMin:DimXMax, DimZMin:DimZMax)
  integer       :: k


  !--- 温位の移流
  ss_AdvTheta_LB = &
       &   ss_avr_fs( fs_VelX_LB ) * ss_dx_ss( ss_Theta_LB ) &
       & + ss_avr_sf( sf_VelZ_LB ) * ss_dz_ss( ss_Theta_LB ) 
  
!  write(*,*) "Advection term of Theta"
!  do k = 1, 100
!     write(*,*)  ss_Theta_LB(50,k) 
!  end do
  
  !--- 温位の拡散
  ss_DiffuseTheta_LB = 0.0d0
  
  !--- 温位の積分
  ss_Theta_LA = &
       & ss_Theta_LB &
       &  + DelTLong * ( - ss_AdvTheta_LB + ss_DiffuseTheta_LB )
  
!  write(*,*) "Advection term of Theta"
!  do k = 1, 100
!     write(*,*)  DelTLong * ( - ss_AdvTheta_LB(50,k) )
!  end do
  
  !--- 境界条件
  call boundary(ss_Bc, ss_Theta_LA)
  
end subroutine ThetaEular

  
