!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= Subroutine AdvectScalar
!
!   * Developer: SUGIYAMA Ko-ichiro (sugiyama@gfd-dennou.org)
!   * Version: $Id: advectscalar.f90,v 1.5 2005/02/02 10:07:26 odakker Exp $ 
!   * Tag Name: $Name:  $
!   * Change History: 
!
!== Overview 
!
!スカラー量の移流を計算する. 
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!== Future Plans
!
                                                                 !=end

subroutine AdvectScalar(fs_VelX_n, sf_VelZ_n, ss_Scalar_n, ss_AdvScalar_n)
                                                                 !=begin
  !== Dependency
  use dc_trace,      only: BeginSub, EndSub 
  use gridset,       only: DimXMin, DimXMax, DimZMin, DimZMax
  use average,       only: ss_avr_fs, ss_avr_sf
  use differentiate_center2, only: fs_dx_ss, sf_dz_ss
                                                                 !=end  
  !--- 暗黙の型宣言禁止
  implicit none
                                                                 !=begin
  !== Input
  real(8), intent(in)  :: fs_VelX_n(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(in)  :: sf_VelZ_n(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(in)  :: ss_Scalar_n(DimXMin:DimXMax, DimZMin:DimZMax)

  !== Output
  real(8), intent(out) :: ss_AdvScalar_n(DimXMin:DimXMax, DimZMin:DimZMax)
                                                                 !=end

  call BeginSub("AdvectScalar", &
&               fmt="%c",       &
&          c1="Calculate advection term for scalar variables (ss_AdvScalar).")
  
  !--- スカラー量の移流
  ss_AdvScalar_n = &
       &   ss_avr_fs( fs_VelX_n * fs_dx_ss( ss_Scalar_n ) ) &
       & + ss_avr_sf( sf_VelZ_n * sf_dz_ss( ss_Scalar_n ) ) 

  call EndSub("AdvectScalar")
  
end subroutine AdvectScalar
