!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= Subroutine AdvectPotTemp
!
!   * Developer: SUGIYAMA Ko-ichiro (sugiyama@gfd-dennou.org)
!   * Version: $Id: advectpottemp.f90,v 1.1 2005/01/31 06:56:48 sugiyama Exp $ 
!   * Tag Name: $Name:  $
!   * Change History: 
!
!== Overview 
!
!温位の移流を計算する. 
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!温位の式の移流には \bar{\theta} が含まれるために, AdvectScalar ルーチン
!を用いて計算するこことはできない. 
!
!== Future Plans
!
                                                                 !=end

subroutine AdvectPotTemp(fs_VelX_n, sf_VelZ_n, ss_PotTemp_n, ss_AdvPotTemp_n)
                                                                 !=begin
  !== Dependency
  use gridset,       only: DimXMin, DimXMax, DimZMin, DimZMax
  use average,       only: ss_avr_fs, ss_avr_sf
  use differentiate, only: fs_dx_ss, sf_dz_ss
  use basicset,      only: ss_PotTempBasicZ
                                                                 !=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_PotTemp_n(DimXMin:DimXMax, DimZMin:DimZMax)

  !== Output
  real(8), intent(out) :: ss_AdvPotTemp_n(DimXMin:DimXMax, DimZMin:DimZMax)
                                                                 !=end
  
  !--- 温位の移流
  ss_AdvPotTemp_n = &
       &   ss_avr_fs( fs_VelX_n * fs_dx_ss( ss_PotTemp_n ) ) &
       & + ss_avr_sf( sf_VelZ_n * sf_dz_ss( ss_PotTemp_n + ss_PotTempBasicZ ) ) 
  
end subroutine AdvectPotTemp
