!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= subroutine SurfaceMomentumFlux
!
!   * Developer: KITAMORI Taichi 
!   * Version: $ 
!   * Tag Name: $Name:  $
!   * Change History: 
!
!== Overview 
!
!地表面運動量フラックスを計算する. 
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!  
!
!== Future Plans
!
                                                                 !=end
subroutine SurfaceMomentumFlux(ss_DensBasicZ,  &
                      &    fs_VelX_ns,      &
                      &    sf_SfcMomentumFlux)

  !==Dependency
  use dc_trace, only: BeginSub, EndSub  
  use gridset,  only: DimXMin, DimXMax, DimZMin, DimZMax, RegZMin
  use average,  only: ss_avr_fs

  !==暗黙の型宣言を禁止
  implicit none
  
  !==Input
  real(8), intent(in)   :: ss_DensBasicZ(DimXMin:DimXMax,DimZMin:DimZMax)   
  real(8), intent(in)   :: fs_VelX_ns(DimXMin:DimXMax,DimZMin:DimZMax)

  !==Output
  real(8), intent(out)  :: sf_SfcMomentumFlux(DimXMin:DimXMax)
  
  !==Work
  real(8)               :: ss_Temp(DimXMin:DimXMax)
  real(8)               :: ss_VelX_ns(DimXMin:DimXMax,DimZMin:DimZMax)
  real(8), parameter    :: Bulk = 0.01d0

  call BeginSub("SurfaceMomentumFlux", &
&           fmt="%c",        &
&           c1="Calculate momentum flux on surface (sf_SfcMomentumFlux).")

  !--- 平均操作
  ss_VelX_ns = ss_avr_fs( fs_VelX_ns )

  !--- 地表面運動量フラックスを計算
  sf_SfcMomentumFlux =  - Bulk    &
       & * ss_DensBasicZ(DimXMin:DimXMax, RegZMin + 1) &
       & * abs( ss_VelX_ns(DimXMin:DimXMax, RegZMin + 1) ) &
       & * ss_VelX_ns(DimXMin:DimXMax, RegZMin + 1)

  call EndSub("SurfaceMomentumFlux")

end subroutine SurfaceMomentumFlux

