!= 粗度長の設定, 陸面と海洋の差のみ考慮
!
!= Set roughness length, only considering land-ocean contrast
!
! Authors::   Yoshiyuki O. Takahashi
! Version::   $Id: roughlen_landoceancontrast.f90,v 1.3 2011-06-19 11:12:46 yot Exp $
! Tag Name::  $Name: dcpam5-20110911 $
! Copyright:: Copyright (C) GFD Dennou Club, 2008-2009. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!

module roughlen_landoceancontrast

  ! モジュール引用 ; USE statements
  !

  ! 種別型パラメタ
  ! Kind type parameter
  !
  use dc_types, only: DP, &      ! 倍精度実数型. Double precision.
    &                 STRING     ! 文字列.       Strings.

  ! メッセージ出力
  ! Message output
  !
  use dc_message, only: MessageNotify


  ! 宣言文 ; Declaration statements
  !
  implicit none
  private

  ! 公開手続き
  ! Public procedure
  !
  public :: SetRoughLenLandOceanContrast
  public :: RoughLenLandOceanContrastInit


  ! 公開変数
  ! Public variables
  !

  ! 非公開変数
  ! Private variables
  !
  logical, save :: roughlen_landoceancontrast_inited = .false.
                              ! 初期設定フラグ.
                              ! Initialization flag

  character(*), parameter:: module_name = 'roughlen_landoceancontrast'
                              ! モジュールの名称.
                              ! Module name
  character(*), parameter:: version = &
    & '$Name: dcpam5-20110911 $' // &
    & '$Id: roughlen_landoceancontrast.f90,v 1.3 2011-06-19 11:12:46 yot Exp $'
                              ! モジュールのバージョン
                              ! Module version


contains

  !--------------------------------------------------------------------------------------

  subroutine SetRoughLenLandOceanContrast( &
    & xy_SurfCond, &
    & xy_RoughLen  &
    )

    ! モジュール引用 ; USE statements
    !

    ! 格子点設定
    ! Grid points settings
    !
    use gridset, only: imax, & ! 経度格子点数.
                               ! Number of grid points in longitude
      &                jmax, & ! 緯度格子点数.
                               ! Number of grid points in latitude
      &                kmax    ! 鉛直層数.
                               ! Number of vertical level


    integer , intent(in   ) :: xy_SurfCond( 0:imax-1, 1:jmax )
    real(DP), intent(inout) :: xy_RoughLen( 0:imax-1, 1:jmax )

    ! 作業変数
    ! Work variables
    !
    integer:: i               ! 経度方向に回る DO ループ用作業変数
                              ! Work variables for DO loop in longitude
    integer:: j               ! 緯度方向に回る DO ループ用作業変数
                              ! Work variables for DO loop in latitude

    ! 初期化確認
    ! Initialization check
    !
    if ( .not. roughlen_landoceancontrast_inited ) then
      call MessageNotify( 'E', module_name, 'This module has not been initialized.' )
    end if


    do j = 1, jmax
      do i = 0, imax-1

        if( xy_SurfCond(i,j) == 0 ) then
          xy_RoughLen(i,j) = 1.0d-4
        else
          xy_RoughLen(i,j) = 1.0d-1
        end if

      end do
    end do


  end subroutine SetRoughLenLandOceanContrast

  !--------------------------------------------------------------------------------------

  subroutine RoughLenLandOceanContrastInit

    if ( roughlen_landoceancontrast_inited ) return


    ! 印字 ; Print
    !
    call MessageNotify( 'M', module_name, '----- Initialization Messages -----' )
    call MessageNotify( 'M', module_name, '-- version = %c', c1 = trim(version) )


    roughlen_landoceancontrast_inited = .true.

  end subroutine RoughLenLandOceanContrastInit

  !--------------------------------------------------------------------------------------

end module roughlen_landoceancontrast

