!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= subroutine SurfaceMomentumFlux
!
!   * Developer: KITAMORI Taichi 
!   * Version: $Id: surfacemomentumflux.f90,v 1.1.2.4 2005/07/26 10:50:34 kitamo Exp $
!   * Tag Name: $Name: arare3m $
!   * Change History: 
!
!== Overview 
!
!地表面運動量フラックスを計算する. 
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!  
!
!== Future Plans
!
                                                                 !=end
subroutine SurfaceMomentumFlux(ss_DensBasicZ,  &
                      &    fs_VelX_ns,      &
                      &    ff_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)  :: ff_SfcMomentumFlux(DimXMin:DimXMax)
  
  !==Work
  real(8), parameter    :: Bulk = 0.01d0   ! バルク係数

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

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

  call EndSub("SurfaceMomentumFlux")

end subroutine SurfaceMomentumFlux

