!= 諠第弌陦ｨ髱｢繝��繧ｿ縺ｮ險ｭ螳�
!
!= Setting planetary surface properties
!
! Authors::   Yasuhiro Morikawa, Yukiko Yamada, Yoshiyuki O. Takahashi
! Version::   $Id: surface_properties.f90,v 1.20 2015/01/31 06:16:26 yot Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2008. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!

module surface_properties
  !
  != 諠第弌陦ｨ髱｢迚ｹ諤ｧ縺ｮ險ｭ螳�
  !
  != Setting planetary surface properties
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !
  ! 豬ｷ髱｢貂ｩ蠎ｦ繧�慍陦ｨ髱｢隲ｸ驥上ｒ險ｭ螳壹＠縺ｾ縺�.
  !
  ! Data about sea surface temperature (SST) or various values on surface
  ! are set.
  !
  !== Procedures List
  ! SetSurfaceProperties  :: 諠第弌陦ｨ髱｢迚ｹ諤ｧ縺ｮ險ｭ螳�
  !--
!!$  ! GroundFileOpen   :: 蝨ｰ陦ｨ髱｢繝��繧ｿ繝輔ぃ繧､繝ｫ縺ｮ繧ｪ繝ｼ繝励Φ
!!$  ! GroundFileOutput :: 蝨ｰ陦ｨ髱｢繝��繧ｿ繝輔ぃ繧､繝ｫ縺ｸ縺ｮ繝��繧ｿ蜃ｺ蜉�
!!$  ! GroundFileClose  :: 蝨ｰ陦ｨ髱｢繝��繧ｿ繝輔ぃ繧､繝ｫ縺ｮ繧ｯ繝ｭ繝ｼ繧ｺ
  !++
  ! ------------     :: ------------
  ! SetSurfaceProperties  :: Setting surface properties
  !--
!!$  ! GroundFileOpen   :: Open ground data file
!!$  ! GroundFileOutput :: Data output to ground data file
!!$  ! GroundFileClose  :: Close ground data file
  !++
  !
  !== NAMELIST
  !
  ! NAMELIST#surface_properties_nml
  !

  ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
  !

  ! 遞ｮ蛻･蝙九ヱ繝ｩ繝｡繧ｿ
  ! Kind type parameter
  !
  use dc_types, only: DP, &      ! 蛟咲ｲｾ蠎ｦ螳滓焚蝙�. Double precision.
    &                 STRING, &  ! 譁�ｭ怜�.       Strings.
    &                 TOKEN      ! 繧ｭ繝ｼ繝ｯ繝ｼ繝�.   Keywords.

  ! 繝｡繝�そ繝ｼ繧ｸ蜃ｺ蜉�
  ! Message output
  !
  use dc_message, only: MessageNotify

  ! gtool5 繝��繧ｿ蜃ｺ蜉�
  ! Gtool5 data output
  !
  use gtool_history, only: GT_HISTORY

  ! 譬ｼ蟄千せ險ｭ螳�
  ! 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

  ! 螳｣險譁� ; Declaration statements
  !
  implicit none
  private

  ! 蜈ｬ髢区焔邯壹″
  ! Public procedure
  !
  public:: SetSurfaceProperties
  public:: SurfacePropertiesInit

  ! 蜈ｬ髢句､画焚
  ! Public variables
  !
  logical, save :: surface_properties_inited = .false.
                              ! 蛻晄悄險ｭ螳壹ヵ繝ｩ繧ｰ.
                              ! Initialization flag

!!$  logical, save, public:: ground_file_opened = .false.
!!$                              ! 蝨ｰ陦ｨ髱｢繝��繧ｿ繝輔ぃ繧､繝ｫ縺ｮ繧ｪ繝ｼ繝励Φ縺ｫ髢｢縺吶ｋ繝輔Λ繧ｰ.
!!$                              ! Flag of ground data file open

  ! 髱槫�髢句､画焚
  ! Private variables
  !
  logical          , save:: FlagSlabOcean
                              ! 繧ｹ繝ｩ繝悶が繝ｼ繧ｷ繝｣繝ｳ 繧ｪ繝ｳ�上が繝�.
                              ! flag for use of slab ocean on/off

  character(STRING), save:: SurfTempSetting
                              ! 蝨ｰ陦ｨ髱｢貂ｩ蠎ｦ縺ｮ險ｭ螳壽婿豕�
                              ! Setting of surface temperature
  character(STRING), save:: SurfTempFile
                              ! 蝨ｰ陦ｨ髱｢貂ｩ蠎ｦ縺ｮ繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of surface temperature
  character(TOKEN) , save:: SurfTempName
                              ! 蝨ｰ陦ｨ髱｢貂ｩ蠎ｦ縺ｮ螟画焚蜷�.
                              ! Variable name of surface temperature

  character(STRING), save:: SeaIceSetting
                              ! 豬ｷ豌ｷ髱｢蟇�ｺｦ縺ｮ險ｭ螳壽婿豕�
                              ! Setting of sea ice concentration
  character(STRING), save:: SeaIceFile
                              ! 豬ｷ豌ｷ髱｢蟇�ｺｦ縺ｮ繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of sea ice concentration
  character(TOKEN) , save:: SeaIceName
                              ! 豬ｷ豌ｷ髱｢蟇�ｺｦ縺ｮ螟画焚蜷�.
                              ! Variable name of sea ice concentration

  character(STRING), save:: AlbedoSetting
                              ! 蝨ｰ陦ｨ繧｢繝ｫ繝吶ラ縺ｮ險ｭ螳壽婿豕�
                              ! Settingof surface albedo
  character(STRING), save:: AlbedoFile
                              ! 蝨ｰ陦ｨ繧｢繝ｫ繝吶ラ縺ｮ繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of surface albedo
  character(TOKEN) , save:: AlbedoName
                              ! 蝨ｰ陦ｨ繧｢繝ｫ繝吶ラ縺ｮ螟画焚蜷�.
                              ! Variable name of surface albedo

  character(STRING), save:: HumidCoefSetting
                              ! 蝨ｰ陦ｨ貉ｿ貎､蠎ｦ縺ｮ險ｭ螳壽婿豕�
                              ! Setting of surface humidity coefficient
  character(STRING), save:: HumidCoefFile
                              ! 蝨ｰ陦ｨ貉ｿ貎､蠎ｦ縺ｮ繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of surface humidity coefficient
  character(TOKEN) , save:: HumidCoefName
                              ! 蝨ｰ陦ｨ貉ｿ貎､蠎ｦ縺ｮ螟画焚蜷�.
                              ! Variable name of surface humidity coefficient

  character(STRING), save:: RoughLengthSetting
                              ! 蝨ｰ陦ｨ邊怜ｺｦ髟ｷ縺ｮ險ｭ螳壽婿豕�
                              ! Setting of surface rough length
  character(STRING), save:: RoughLengthFile
                              ! 蝨ｰ陦ｨ邊怜ｺｦ髟ｷ縺ｮ繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of surface rough length
  character(TOKEN) , save:: RoughLengthName
                              ! 蝨ｰ陦ｨ邊怜ｺｦ髟ｷ縺ｮ螟画焚蜷�.
                              ! Variable name of surface rough length
  character(STRING), save:: HeatCapacitySetting
                              ! 蝨ｰ陦ｨ辭ｱ螳ｹ驥上�險ｭ螳壽婿豕�
                              ! Setting of surface heat capacity
  character(STRING), save:: HeatCapacityFile
                              ! 蝨ｰ陦ｨ辭ｱ螳ｹ驥上�繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of surface heat capacity
  character(TOKEN) , save:: HeatCapacityName
                              ! 蝨ｰ陦ｨ辭ｱ螳ｹ驥上�螟画焚蜷�.
                              ! Variable name of surface heat capacity

  character(STRING), save:: TempFluxSetting
                              ! 蝨ｰ荳ｭ辭ｱ繝輔Λ繝�け繧ｹ縺ｮ險ｭ螳壽婿豕�
                              ! Setting of ground temperature flux
  character(STRING), save:: TempFluxFile
                              ! 蝨ｰ荳ｭ辭ｱ繝輔Λ繝�け繧ｹ縺ｮ繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of ground temperature flux
  character(TOKEN) , save:: TempFluxName
                              ! 蝨ｰ荳ｭ辭ｱ繝輔Λ繝�け繧ｹ縺ｮ螟画焚蜷�.
                              ! Variable name of ground temperature flux

  character(STRING), save:: SurfCondSetting
                              ! 諠第弌陦ｨ髱｢迥ｶ諷九�險ｭ螳壽婿豕�
                              ! Setting of surface condition
  character(STRING), save:: SurfCondFile
                              ! 諠第弌陦ｨ髱｢迥ｶ諷九�繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of surface condition
  character(TOKEN) , save:: SurfCondName
                              ! 諠第弌陦ｨ髱｢迥ｶ諷九�螟画焚蜷�.
                              ! Variable name of surface condition

  character(STRING), save:: SurfTypeSetting
                              ! 諠第弌陦ｨ髱｢繧ｿ繧､繝� (蝨溷慍蛻ｩ逕ｨ) 縺ｮ險ｭ螳壽婿豕�
                              ! Setting of surface type (land use)
  character(STRING), save:: SurfTypeFile
                              ! 諠第弌陦ｨ髱｢繧ｿ繧､繝� (蝨溷慍蛻ｩ逕ｨ) 縺ｮ繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of surface type (land use)
  character(TOKEN) , save:: SurfTypeName
                              ! 諠第弌陦ｨ髱｢繧ｿ繧､繝� (蝨溷慍蛻ｩ逕ｨ) 縺ｮ螟画焚蜷�.
                              ! Variable name of surface type (land use)

  character(STRING), save:: SurfCulIntSetting
                              ! ... 縺ｮ險ｭ螳壽婿豕�
                              ! Setting of surface cultivation intensity
  character(STRING), save:: SurfCulIntFile
                              ! ... 縺ｮ繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of surface cultivation intensity
  character(TOKEN) , save:: SurfCulIntName
                              ! ... 縺ｮ螟画焚蜷�.
                              ! Variable name of surface cultivation intensity

  character(STRING), save:: SurfHeightSetting
                              ! 蝨ｰ陦ｨ髱｢鬮伜ｺｦ縺ｮ險ｭ螳壽婿豕�
                              ! Setting of surface height
  character(STRING), save:: SurfHeightFile
                              ! 蝨ｰ陦ｨ髱｢鬮伜ｺｦ縺ｮ繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of surface height
  character(TOKEN) , save:: SurfHeightName
                              ! 蝨ｰ陦ｨ髱｢鬮伜ｺｦ縺ｮ螟画焚蜷�.
                              ! Variable name of surface height

  character(STRING), save:: SurfHeightStdSetting
                              !
                              ! Setting of surface height standard deviation
  character(STRING), save:: SurfHeightStdFile
                              !
                              ! File name of surface height standard deviation
  character(TOKEN) , save:: SurfHeightStdName
                              !
                              ! Variable name of surface height standard deviation

  character(STRING), save:: SoilHeatCapSetting
                              ! 蝨溷｣檎�螳ｹ驥上�險ｭ螳壽婿豕�
                              ! Setting of heat conduction coefficient of soil
  character(STRING), save:: SoilHeatCapFile
                              ! 蝨溷｣檎�螳ｹ驥上�繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of heat conduction coefficient of soil
  character(TOKEN) , save:: SoilHeatCapName
                              ! 蝨溷｣檎�螳ｹ驥上�螟画焚蜷�.
                              ! Variable name of heat conduction coefficient of soil

  character(STRING), save:: SoilHeatDiffCoefSetting
                              ! 蝨溷｣檎�莨晏ｰ守紫縺ｮ險ｭ螳壽婿豕�
                              ! Setting of heat conduction coefficient of soil
  character(STRING), save:: SoilHeatDiffCoefFile
                              ! 蝨溷｣檎�莨晏ｰ守紫縺ｮ繝輔ぃ繧､繝ｫ蜷�.
                              ! File name of heat conduction coefficient of soil
  character(TOKEN) , save:: SoilHeatDiffCoefName
                              ! 蝨溷｣檎�莨晏ｰ守紫縺ｮ螟画焚蜷�.
                              ! Variable name of heat conduction coefficient of soil

  real(DP), save:: RoughLenHeatFactor
                              ! 驕句虚驥上→辭ｱ縺ｮ蝨ｰ陦ｨ邊怜ｺｦ髟ｷ縺ｮ豈�.
                              ! Ratio of roughness length for momentum and heat

  logical, save:: FlagUseBucket

!!$  character(STRING), save:: OutputFile
!!$                              ! 蜃ｺ蜉帙☆繧句慍陦ｨ髱｢繝��繧ｿ縺ｮ繝輔ぃ繧､繝ｫ蜷�
!!$                              ! filename of output ground data
!!$  real(DP), save:: IntValue
!!$                              ! 蝨ｰ陦ｨ髱｢繝��繧ｿ縺ｮ蜃ｺ蜉幃俣髫�.
!!$                              ! Interval of ground data output
!!$  character(TOKEN):: IntUnit
!!$                              ! 蝨ｰ陦ｨ髱｢繝��繧ｿ縺ｮ蜃ｺ蜉幃俣髫斐�蜊倅ｽ�.
!!$                              ! Unit for interval of ground data output
!!$
!!$  type(GT_HISTORY), save:: gthst_grd
!!$                              ! 蝨ｰ陦ｨ髱｢繝��繧ｿ逕ｨ gtool_history#GT_HISTORY 螟画焚
!!$                              ! "gtool_history#GT_HISTORY" variable for ground data
!!$
!!$
!!$  type(DC_DIFFTIME), save:: PrevOutputTime
!!$                              ! 蜑榊屓縺ｮ蜃ｺ蜉帶凾髢�.
!!$                              ! Previous output time
!!$
!!$  type(DC_DIFFTIME), save:: IntTime
!!$                              ! 繝ｪ繧ｹ繧ｿ繝ｼ繝医ョ繝ｼ繧ｿ縺ｮ蜃ｺ蜉帶凾髢�.
!!$                              ! Time interval of restart data output

  character(*), parameter:: module_name = 'surface_properties'
                              ! 繝｢繧ｸ繝･繝ｼ繝ｫ縺ｮ蜷咲ｧｰ.
                              ! Module name
  character(*), parameter:: version = &
    & '$Name:  $' // &
    & '$Id: surface_properties.f90,v 1.20 2015/01/31 06:16:26 yot Exp $'
                              ! 繝｢繧ｸ繝･繝ｼ繝ｫ縺ｮ繝舌�繧ｸ繝ｧ繝ｳ
                              ! Module version

contains

  subroutine SetSurfaceProperties(                       &
    & xy_SurfMajCompIceB, xy_SoilMoistB, xy_SurfSnowB,   & ! (in)    optional
    & xy_SurfTemp, xy_SurfAlbedo, xy_SurfHumidCoef,      & ! (inout) optional
    & xy_SurfRoughLenMom, xy_SurfRoughLenHeat,           & ! (inout) optional
    & xy_SurfHeatCapacity,                               & ! (inout) optional
    & xy_DeepSubSurfHeatFlux, xy_SurfCond, xy_SurfType,  & ! (inout) optional
    & xy_SurfHeight, xy_SurfHeightStd,                   & ! (inout) optional
    & xy_SeaIceConc,                                     & ! (inout) optional
    & xy_SoilHeatCap, xy_SoilHeatDiffCoef                & ! (inout) optional
    & )
    !
    ! 諠第弌陦ｨ髱｢迚ｹ諤ｧ繧定ｨｭ螳壹＠縺ｾ縺�.
    !
    ! Set surface properties.
    !

    ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
    !

    ! 譁�ｭ怜�謫堺ｽ�
    ! Character handling
    !
    use dc_string, only: toChar

    ! gtool4 繝��繧ｿ蜈･蜉�
    ! Gtool4 data input
    !
    use gtool_history, only: HistoryGet

    ! 繝偵せ繝医Μ繝��繧ｿ蜃ｺ蜉�
    ! History data output
    !
    use gtool_historyauto, only: HistoryAutoPut

    ! 譎らｳｻ蛻励ョ繝ｼ繧ｿ縺ｮ隱ｭ縺ｿ霎ｼ縺ｿ
    ! Reading time series
    !
    use read_time_series, only: SetValuesFromTimeSeriesWrapper

    ! 譎ょ綾邂｡逅�
    ! Time control
    !
    use timeset, only: &
      & TimeN, &              ! 繧ｹ繝�ャ繝� $ t $ 縺ｮ譎ょ綾.
                              ! Time of step $ t $.
      & EndTime, &            ! 險育ｮ礼ｵゆｺ�凾蛻ｻ.
                              ! End time of calculation
      & TimesetClockStart, TimesetClockStop

    ! 蝨ｰ陦ｨ髱｢繝��繧ｿ謠蝉ｾ�
    ! Prepare surface data
    !
    use surface_data, only: SetSurfData

    !
    ! Routines for GABLS tests
    !
    use gabls, only : SetGabls2SurfTemp

    ! Matthews 縺ｮ繝��繧ｿ縺ｫ蝓ｺ縺･縺乗ヱ譏溯｡ｨ髱｢繧｢繝ｫ繝吶ラ險ｭ螳�
    ! set surface albedo based on data by Matthews
    !
    use albedo_Matthews, only: SetAlbedoMatthews, ModAlbedoMatthewsCultivation

    ! 繝舌こ繝�Δ繝�Ν
    ! Bucket model
    !
    use Bucket_Model, only : BucketSetFlagOceanFromMatthews, BucketModHumidCoef

    ! 髮ｪ縺ｨ豬ｷ豌ｷ縺ｫ繧医ｋ繧｢繝ｫ繝吶ラ螟牙喧
    ! modification of surface albedo on the snow covered ground and on the sea ice
    !
    use modify_albedo_snowseaice, only: ModAlbedoDueToSnowSeaIce

    ! 繧｢繝ｫ繝吶ラ, 邊怜ｺｦ髟ｷ縺ｮ險ｭ螳�, 髯ｸ髱｢縺ｨ豬ｷ豢九�蟾ｮ縺ｮ縺ｿ閠��
    ! Set albedo and roughness length, only considering land-ocean contrast
    !
    use surface_properties_lo, only: &
      & SetAlbedoLO, SetRoughLenLO

    ! Matthews 縺ｮ繝��繧ｿ縺ｫ蝓ｺ縺･縺丞慍髱｢邊怜ｺｦ縺ｮ險ｭ螳�
    ! set roughness length on land surface based on data by Matthews
    !
    use roughlen_Matthews, only: SetRoughLenLandMatthews, ModRoughLenMatthewsCultivation

    ! 蝨溷｣檎�莨晏ｰ惹ｿよ焚縺ｮ險ｭ螳�
    ! set soil thermal diffusion coefficient
    !
    use soil_thermdiffcoef, only : SetSoilThermDiffCoefSimple

    ! 髮ｪ, 豌ｷ縺ｮ蜑ｲ蜷�
    ! snow/ice fraction
    !
    use snowice_frac, only : SeaIceAboveThreshold

    ! 螳｣險譁� ; Declaration statements
    !
    real(DP), intent(in   ), optional:: xy_SurfMajCompIceB(0:imax-1, 1:jmax)
                              ! $ M_mcs (t-\Delta t) $ .
                              ! Surface major component ice amount (kg m-2)
    real(DP), intent(in   ), optional:: xy_SoilMoistB(0:imax-1, 1:jmax)
                              ! $ M_ws (t-\Delta t) $ . 蝨溷｣梧ｰｴ蛻� (kg m-2)
                              ! Soil moisture (kg m-2)
    real(DP), intent(in   ), optional:: xy_SurfSnowB(0:imax-1, 1:jmax)
                              ! $ M_ss (t-\Delta t) $ . 遨埼妛驥� (kg m-2)
                              ! Surface snow amount (kg m-2)
    real(DP), intent(inout), optional:: xy_SurfTemp (0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ髱｢貂ｩ蠎ｦ.
                              ! Surface temperature
    real(DP), intent(inout), optional:: xy_SurfAlbedo (0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ繧｢繝ｫ繝吶ラ.
                              ! Surface albedo
    real(DP), intent(inout), optional:: xy_SurfHumidCoef (0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ貉ｿ貎､蠎ｦ.
                              ! Surface humidity coefficient
    real(DP), intent(inout), optional:: xy_SurfRoughLenMom (0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ邊怜ｺｦ髟ｷ.
                              ! Surface rough length for momentum
    real(DP), intent(inout), optional:: xy_SurfRoughLenHeat(0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ邊怜ｺｦ髟ｷ.
                              ! Surface rough length for heat
    real(DP), intent(inout), optional:: xy_SurfHeatCapacity (0:imax-1, 1:jmax)
                              ! 蝨ｰ陦ｨ辭ｱ螳ｹ驥�.
                              ! Surface heat capacity
    real(DP), intent(inout), optional:: xy_DeepSubSurfHeatFlux (0:imax-1, 1:jmax)
                              ! 蝨ｰ荳ｭ辭ｱ繝輔Λ繝�け繧ｹ.
                              ! "Deep subsurface heat flux"
                              ! Heat flux at the bottom of surface/soil layer.
    integer , intent(inout), optional:: xy_SurfCond (0:imax-1, 1:jmax)
                              ! 諠第弌陦ｨ髱｢迥ｶ諷� (0: 蝗ｺ螳�, 1: 蜿ｯ螟�).
                              ! Surface condition (0: fixed, 1: variable)
    integer , intent(inout), optional:: xy_SurfType (0:imax-1, 1:jmax)
                              ! 諠第弌陦ｨ髱｢繧ｿ繧､繝� (蝨溷慍蛻ｩ逕ｨ)
                              ! Surface type (land use)
    real(DP), intent(inout), optional:: xy_SurfHeight   (0:imax-1, 1:jmax)
                              ! $ z_s $ . 蝨ｰ陦ｨ髱｢鬮伜ｺｦ.
                              ! Surface height.
    real(DP), intent(inout), optional:: xy_SurfHeightStd(0:imax-1, 1:jmax)
                              ! $ z_s $ . 蝨ｰ陦ｨ髱｢鬮伜ｺｦ.
                              ! Surface height.
    real(DP), intent(inout), optional:: xy_SeaIceConc(0:imax-1,1:jmax)
                              ! 豬ｷ豌ｷ蟇�ｺｦ (0 <= xy_SeaIceConc <= 1)
                              ! Sea ice concentration (0 <= xy_SeaIceConc <= 1)
    real(DP), intent(inout), optional:: xy_SoilHeatCap(0:imax-1,1:jmax)
                              ! 蝨溷｣檎�螳ｹ驥� (J K-1 kg-1)
                              ! Specific heat of soil (J K-1 kg-1)
    real(DP), intent(inout), optional:: xy_SoilHeatDiffCoef(0:imax-1,1:jmax)
                              ! 蝨溷｣檎�莨晏ｰ守紫 (W m-1 K-1)
                              ! Heat conduction coefficient of soil (W m-1 K-1)

    ! 菴懈･ｭ螟画焚
    ! Work variables
    !
    real(DP), allocatable, save:: xy_SurfTempSave (:,:)
                              ! 蝨ｰ陦ｨ髱｢貂ｩ蠎ｦ縺ｮ菫晏ｭ伜､ (K)
                              ! Saved values of surface temperature (K)
    real(DP), allocatable, save:: xy_SeaIceConcSave(:,:)
                              ! 豬ｷ豌ｷ髱｢蟇�ｺｦ縺ｮ菫晏ｭ伜､
                              ! Saved values of sea ice concentration
    real(DP), allocatable, save:: xy_SurfAlbedoSave(:,:)
                              ! 繧｢繝ｫ繝吶ラ縺ｮ菫晏ｭ伜､
                              ! Saved values of albedo

    logical      :: xy_BucketFlagOceanGrid(0:imax-1,1:jmax)
                              !
                              ! Flag for ocean grid point used in bucket model
    real(DP), allocatable, save:: xy_SurfCulIntSave(:,:)
    real(DP)                   :: xy_SurfCulInt    (0:imax-1,1:jmax)
                              !
                              ! Surface cultivation intensity

    logical, save:: flag_first_SurfCond            = .true.
                              ! 蛻晏屓繧堤､ｺ縺吶ヵ繝ｩ繧ｰ.
                              ! Flag that indicates first loop
                              !
    logical, save:: flag_first_SurfType            = .true.
    logical, save:: flag_first_SurfCulInt          = .true.
    logical, save:: flag_first_SeaIceConc          = .true.
    logical, save:: flag_first_SurfTemp            = .true.
    logical, save:: flag_first_SurfHeight          = .true.
    logical, save:: flag_first_SurfHeightStd       = .true.
    logical, save:: flag_first_SurfAlbedo          = .true.
    logical, save:: flag_first_SurfHumidCoef       = .true.
    logical, save:: flag_first_SurfRoughLen        = .true.
    logical, save:: flag_first_SurfHeatCapacity    = .true.
    logical, save:: flag_first_DeepSubSurfHeatFlux = .true.
    logical, save:: flag_first_SoilHeatCap         = .true.
    logical, save:: flag_first_SoilHeatDiffCoef    = .true.

    logical :: FlagSetSurfType
    logical :: FlagSetSeaIceConc
    logical :: FlagSetSurfCond
    logical :: FlagSetSurfCulInt
    logical :: FlagSetSurfTemp
    logical :: FlagSetSurfHeight
    logical :: FlagSetSurfHeightStd
    logical :: FlagSetSurfAlbedo
    logical :: FlagSetSurfHumidCoef
    logical :: FlagSetSurfRoughLenMom
    logical :: FlagSetSurfRoughLenHeat
    logical :: FlagSetSurfHeatCapacity
    logical :: FlagSetDeepSubSurfHeatFlux
    logical :: FlagSetSoilHeatCap
    logical :: FlagSetSoilHeatDiffCoef

    logical:: flag_mpi_init

    integer:: i               ! 邨悟ｺｦ譁ｹ蜷代↓蝗槭ｋ DO 繝ｫ繝ｼ繝礼畑菴懈･ｭ螟画焚
                              ! Work variables for DO loop in longitude
    integer:: j               ! 邱ｯ蠎ｦ譁ｹ蜷代↓蝗槭ｋ DO 繝ｫ繝ｼ繝礼畑菴懈･ｭ螟画焚
                              ! Work variables for DO loop in latitude

    ! 螳溯｡梧枚 ; Executable statement
    !

    ! 蛻晄悄蛹也｢ｺ隱�
    ! Initialization check
    !
    if ( .not. surface_properties_inited ) then
      call MessageNotify( 'E', module_name, 'This module has not been initialized.' )
    end if

    ! 險育ｮ玲凾髢楢ｨ域ｸｬ髢句ｧ�
    ! Start measurement of computation time
    !
    call TimesetClockStart( module_name )

    flag_mpi_init = .true.

    FlagSetSurfType            = .false.
    FlagSetSeaIceConc          = .false.
    FlagSetSurfCond            = .false.
    FlagSetSurfCulInt          = .false.
    FlagSetSurfTemp            = .false.
    FlagSetSurfHeight          = .false.
    FlagSetSurfHeightStd       = .false.
    FlagSetSurfAlbedo          = .false.
    FlagSetSurfHumidCoef       = .false.
    FlagSetSurfRoughLenMom     = .false.
    FlagSetSurfRoughLenHeat    = .false.
    FlagSetSurfHeatCapacity    = .false.
    FlagSetDeepSubSurfHeatFlux = .false.
    FlagSetSoilHeatCap         = .false.
    FlagSetSoilHeatDiffCoef    = .false.

    ! NOTICE:
    ! The surface condition has to be set, before other fields are set.
    !
    ! 諠第弌陦ｨ髱｢繧ｿ繧､繝� (蝨溷慍蛻ｩ逕ｨ)
    ! Surface type (land use)
    !
    if ( present(xy_SurfType) ) then

      if ( SurfTypeSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_SurfType ) then
          call HistoryGet( &
            & SurfTypeFile, SurfTypeName, &     ! (in)
            & xy_SurfType, &                    ! (out)
            & flag_mpi_split = flag_mpi_init )  ! (in) optional
        end if
        if ( SurfCondSetting /= 'generate_from_SurfType' ) then
          call MessageNotify( 'E', module_name, &
            & " SurfCond has to be 'generate_from_SurfType', if SurfTypeSetting = %c.", &
            & c1 = trim(SurfTypeSetting) )
        end if
      else if ( SurfTypeSetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_SurfType ) then
          call SetSurfData( &
            & xy_SurfType = xy_SurfType &                   ! (out)
            & )
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' SurfTypeSetting = %c is not appropriate.', &
          & c1 = trim(SurfTypeSetting) )
      end if

      FlagSetSurfType = .true.

      flag_first_SurfType = .false.

    end if

    ! NOTICE:
    ! The sea ice distribution has to be set,
    ! before set SurfTemp (surface temperature) and SurfCond.
    !
    ! 豬ｷ豌ｷ髱｢蟇�ｺｦ
    ! Sea ice concentration
    !
    if ( present(xy_SeaIceConc) ) then

      if ( flag_first_SeaIceConc ) then
        ! 菫晏ｭ倡畑螟画焚縺ｮ蜑ｲ莉�
        ! Allocate a variable for save
        !
        allocate( xy_SeaIceConcSave(0:imax-1, 1:jmax) )
      end if
      if ( SeaIceSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !

        ! This will be deleted near future (yot, 2010/10/11)
!!$        if ( flag_first_SeaIceConc ) then
!!$          call HistoryGet( &
!!$            & SeaIceFile, SeaIceName,          & ! (in)
!!$            & xy_SeaIceConcSave,               & ! (out)
!!$            & flag_mpi_split = flag_mpi_init )   ! (in) optional
!!$        end if
        call SetValuesFromTimeSeriesWrapper(    &
          & 'SIC',                              &
          & SeaIceFile, SeaIceName,             &
          & xy_SeaIceConcSave                   &               ! (inout)
          & )
      else if ( SeaIceSetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_SeaIceConc ) then
          call SetSurfData( &
            & xy_SeaIceConc = xy_SeaIceConcSave &                   ! (out)
            & )
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' SeaIceSetting = %c is not appropriate.', &
          & c1 = trim(SeaIceSetting) )
      end if
      ! 豬ｷ豌ｷ髱｢蟇�ｺｦ縺ｮ險ｭ螳� ( xy_SurfCond == 0 縺ｮ蝣ｴ謇縺ｮ縺ｿ )
      ! Setting of sea ice concentration ( where xy_SurfCond == 0 only )
      !
      xy_SeaIceConc = xy_SeaIceConcSave

      FlagSetSeaIceConc = .true.

      flag_first_SeaIceConc = .false.

    end if

    ! 諠第弌陦ｨ髱｢迥ｶ諷�
    ! Surface condition
    ! Flag whether surface temperature is calculated or not
    ! 0 : surface temperature is not calculated
    ! 1 : surface temperature is     calculated
    !
    if ( present(xy_SurfCond) ) then

      ! NOTICE:
      ! Before set SurfCond, SeaIceConc has to be set.
      if ( .not. FlagSetSeaIceConc ) then
        call MessageNotify( 'E', module_name, &
          & " SeaIceConc has to be set before setting SurfCond is set." )
      end if

      if ( SurfCondSetting == 'generate_from_SurfType' ) then
        if ( flag_first_SurfCond ) then
!!$          if ( ( SurfTypeSetting /= 'file' ) .and. ( SurfTypeSetting /= 'generate_internally' ) ) then
!!$            call MessageNotify( 'E', module_name, &
!!$              & " SurfCond has to be 'generate_from_SurfType' or 'generate_internally', if SurfTypeSetting = %c.", &
!!$              & c1 = trim(SurfTypeSetting) )
!!$          end if
          call MessageNotify( 'M', module_name, &
            & ' xy_SurfCond is constructed by use of xy_SurfType values because SurfTypeSetting = %c.', &
            & c1 = trim(SurfTypeSetting) )
        end if
        do j = 1, jmax
          do i = 0, imax-1
            if ( xy_SurfType(i,j) == 0 ) then
              if ( SeaIceAboveThreshold( xy_SeaIceConc(i,j) ) ) then
                xy_SurfCond(i,j) = 1
              else if ( FlagSlabOcean ) then
                xy_SurfCond(i,j) = 1
              else
                xy_SurfCond(i,j) = 0
              end if
            else
              xy_SurfCond(i,j) = 1
            end if
          end do
        end do

      else if ( SurfCondSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_SurfCond ) then
          call HistoryGet( &
            & SurfCondFile, SurfCondName, &     ! (in)
            & xy_SurfCond, &                    ! (out)
            & flag_mpi_split = flag_mpi_init )  ! (in) optional
        end if
      else if ( SurfCondSetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_SurfCond ) then
          call SetSurfData( &
            & xy_SurfCond = xy_SurfCond &                   ! (out)
            & )
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' SurfCondSetting = %c is not appropriate.', &
          & c1 = trim(SurfCondSetting) )
      end if

      ! Check of SurfCond values
      !
      do j = 1, jmax
        do i = 0, imax-1
          if ( ( xy_SurfCond(i,j) < 0 ) .or. ( xy_SurfCond(i,j) > 1 ) ) then
            call MessageNotify( 'E', module_name, &
              & ' SurfCond value of %d is not appropriate.', &
              & i = (/ xy_SurfCond(i,j) /) )
          end if
        end do
      end do

      FlagSetSurfCond = .true.

      flag_first_SurfCond = .false.

    end if

    !
    ! Surface cultivation index
    !
    ! Cultivation intensity is set only when xy_SurfType is present.
    if ( present( xy_SurfType ) ) then

      ! NOTICE:
      ! Before set SurfCulInt, SurfType has to be set.
      if ( .not. FlagSetSurfType ) then
        call MessageNotify( 'E', module_name, &
          & " SurfType has to be set before setting SurfCulInt is set." )
      end if

      if ( flag_first_SurfCulInt ) then
        ! 菫晏ｭ倡畑螟画焚縺ｮ蜑ｲ莉�
        ! Allocate a variable for save
        !
        allocate( xy_SurfCulIntSave(0:imax-1, 1:jmax) )
      end if
      if ( SurfCulIntSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( SurfTypeSetting /= 'file' ) then
          call MessageNotify( 'E', module_name, &
            & " SurfType has to be 'file', when SurfCulIntSetting = %c.", &
            & c1 = trim(SurfCulIntSetting) )
        end if
        call SetValuesFromTimeSeriesWrapper(    &
          & 'CI',                               &
          & SurfCulIntFile, SurfCulIntName,     &
          & xy_SurfCulIntSave                   &               ! (inout)
          & )
      else if ( SurfCulIntSetting == 'generate_internally' ) then
        xy_SurfCulIntSave = 0.0_DP
      else
        call MessageNotify( 'E', module_name, &
          & ' SurfCulIntSetting = %c is not appropriate.', &
          & c1 = trim(SurfCulIntSetting) )
      end if
      !
      xy_SurfCulInt = xy_SurfCulIntSave

      FlagSetSurfCulInt = .true.
      flag_first_SurfCulInt = .false.
    else
      xy_SurfCulInt = 0.0_DP

      FlagSetSurfCulInt = .true.
    end if

    ! 蝨ｰ陦ｨ髱｢貂ｩ蠎ｦ
    ! surface temperature
    !
    if ( present(xy_SurfTemp) ) then

      ! NOTICE:
      ! Before set surface temperature, sea ice distribution has to be set.
      if ( .not. FlagSetSeaIceConc ) then
        call MessageNotify( 'E', module_name, &
          & " SeaIceConc has to be set before setting SurfTemp is set." )
      end if

      if ( flag_first_SurfTemp ) then
        ! 菫晏ｭ倡畑螟画焚縺ｮ蜑ｲ莉�
        ! Allocate a variable for save
        !
        allocate( xy_SurfTempSave  (0:imax-1, 1:jmax) )
      end if
      if ( SurfTempSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !

        ! This will be deleted near future (yot, 2010/10/11)
!!$        if ( flag_first_SurfTemp ) then
!!$          call HistoryGet( &
!!$            & SurfTempFile, SurfTempName, &    ! (in)
!!$            & xy_SurfTempSave, &               ! (out)
!!$            & flag_mpi_split = flag_mpi_init ) ! (in) optional
!!$        end if
        call SetValuesFromTimeSeriesWrapper(    &
          & 'SST',                              &
          & SurfTempFile, SurfTempName,         &
          & xy_SurfTempSave                     &               ! (inout)
          & )
      else if ( SurfTempSetting == 'GABLS2' ) then
        !
        ! Routines for GABLS tests
        !
        call SetGabls2SurfTemp(     &
          & xy_SurfTempSave         & ! (out)
          & )
      else if ( SurfTempSetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_SurfTemp ) then
          call SetSurfData( &
            & xy_SurfTemp = xy_SurfTempSave & ! (out) optional
            & )
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' SurfTempSetting = %c is not appropriate.', &
          & c1 = trim(SurfTempSetting) )
      end if
      ! 蝨ｰ陦ｨ髱｢貂ｩ蠎ｦ繧� SST 縺ｧ鄂ｮ縺肴鋤縺� ( xy_SurfCond <=0 縺ｮ蝣ｴ謇縺ｮ縺ｿ )
      ! Surface temperature is replaced with SST ( only xy_SurfCond <=0 )
      !
      if ( present(xy_SurfTemp) ) then

        if ( .not. present( xy_SurfCond ) ) then
          call MessageNotify( 'E', module_name, &
            & ' xy_SurfCond has to be present to set xy_SurfTemp.' )
        end if
        if ( .not. present( xy_SeaIceConc ) ) then
          call MessageNotify( 'E', module_name, &
            & ' xy_SeaIceConc has to be present to set xy_SurfTemp.' )
        end if

        do j = 1, jmax
          do i = 0, imax-1
            if ( xy_SurfCond(i,j) == 0 ) then
              xy_SurfTemp(i,j) = xy_SurfTempSave(i,j)
            end if
          end do
        end do

      end if

      FlagSetSurfTemp = .true.

      flag_first_SurfTemp = .false.
    end if

    ! 蝨ｰ蠖｢
    ! Topography
    !
    if ( present(xy_SurfHeight) ) then

      if ( SurfHeightSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_SurfHeight ) then
          call HistoryGet( &
            & SurfHeightFile, SurfHeightName, &  ! (in)
            & xy_SurfHeight, &                   ! (out)
            & flag_mpi_split = flag_mpi_init )   ! (in) optional
        end if
      else if ( SurfHeightSetting == 'generate_internally' ) then
        if ( flag_first_SurfHeight ) then
          xy_SurfHeight = 0.0_DP
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' SurfHeightSetting = %c is not appropriate.', &
          & c1 = trim(SurfHeightSetting) )
      end if

      FlagSetSurfHeight = .true.

      flag_first_SurfHeight = .false.
    end if

    !
    ! Surface height standard deviation
    !
    if ( present(xy_SurfHeightStd) ) then

      if ( SurfHeightStdSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_SurfHeightStd ) then
          call HistoryGet( &
            & SurfHeightStdFile, SurfHeightStdName, & ! (in)
            & xy_SurfHeightStd, &                     ! (out)
            & flag_mpi_split = flag_mpi_init )        ! (in) optional
        end if
      else if ( SurfHeightStdSetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_SurfHeightStd ) then
          call SetSurfData( &
            & xy_SurfHeightStd = xy_SurfHeightStd  & ! (out)
            & )
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' SurfHeightStdSetting = %c is not appropriate.', &
          & c1 = trim(SurfHeightStdSetting) )
      end if

      FlagSetSurfHeightStd = .true.

      flag_first_SurfHeightStd = .false.
    end if

    ! 繧｢繝ｫ繝吶ラ
    ! Albedo
    !
    if ( present(xy_SurfAlbedo) ) then

      ! NOTICE:
      ! The surface condition and sea ice concentration have to be set,
      ! before albedo is set.
      if ( ( .not. FlagSetSurfCond ) .or. ( .not. FlagSetSeaIceConc ) ) then
        call MessageNotify( 'E', module_name, &
          & " SurfCond and SeaIceConc have to be set before setting SurfAlbedo is set." )
      end if

      if ( flag_first_SurfAlbedo ) then
        ! 菫晏ｭ倡畑螟画焚縺ｮ蜑ｲ莉�
        ! Allocate a variable for save
        !
        allocate( xy_SurfAlbedoSave(0:imax-1, 1:jmax) )
      end if
      if ( AlbedoSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_SurfAlbedo ) then
          call HistoryGet( &
            & AlbedoFile, AlbedoName, &        ! (in)
            & xy_SurfAlbedoSave,      &        ! (out)
            & flag_mpi_split = flag_mpi_init ) ! (in) optional
        end if
!!$        call SetValuesFromTimeSeriesWrapper(    &
!!$          & 'surface_albedo',                   &
!!$          & AlbedoFile, AlbedoName,             &
!!$          & xy_SurfAlbedoSave                   &               ! (inout)
!!$          & )
      else if ( AlbedoSetting == 'Matthews' ) then
        ! 繧｢繝ｫ繝吶ラ繧� Matthews 縺ｮ繝��繧ｿ繧偵ｂ縺ｨ縺ｫ險ｭ螳�
        ! Surface albedo is set based on Matthews' data
        !
        if ( .not. present( xy_SurfType ) ) then
          call MessageNotify( 'E', module_name, &
            & ' xy_SurfType has to be present to set xy_SurfAlbedo.' )
        end if
        if ( SurfTypeSetting /= 'file' ) then
          call MessageNotify( 'E', module_name, &
            & " SurfType has to be 'file', when AlbedoSetting = %c.", &
            & c1 = trim(AlbedoSetting) )
        end if
        call SetAlbedoMatthews( &
          & xy_SurfType,      &
          & xy_SurfAlbedoSave &
          & )
        ! Modify albedo due to cultivation
        call ModAlbedoMatthewsCultivation( &
          & xy_SurfType, xy_SurfCulInt,    &
          & xy_SurfAlbedoSave              &
          & )
      else if ( AlbedoSetting == 'LOContrast' ) then
        ! 繧｢繝ｫ繝吶ラ縺ｮ險ｭ螳�, 髯ｸ髱｢縺ｨ豬ｷ豢九�蟾ｮ縺ｮ縺ｿ閠��
        ! Set albedo, only considering land-ocean contrast
        !
        if ( .not. present( xy_SurfType ) ) then
          call MessageNotify( 'E', module_name, &
            & ' xy_SurfType has to be present to set xy_SurfAlbedo.' )
        end if
        if ( SurfTypeSetting /= 'file' ) then
          call MessageNotify( 'E', module_name, &
            & " SurfType has to be 'file', when AlbedoSetting = %c.", &
            & c1 = trim(AlbedoSetting) )
        end if
        call SetAlbedoLO(      &
          & xy_SurfType,       &
          & xy_SurfAlbedoSave  &
          & )
      else if ( AlbedoSetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_SurfAlbedo ) then
          call SetSurfData( &
            & xy_SurfAlbedo = xy_SurfAlbedoSave  & ! (out)
            & )
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' AlbedoSetting = %c is not appropriate.', &
          & c1 = trim(AlbedoSetting) )
      end if
      ! 繧｢繝ｫ繝吶ラ縺ｮ險ｭ螳�
      ! Setting of albedo
      !
      xy_SurfAlbedo = xy_SurfAlbedoSave

      if ( present( xy_SurfType ) ) then
        ! 髮ｪ縺ｨ豬ｷ豌ｷ縺ｫ繧医ｋ繧｢繝ｫ繝吶ラ螟牙喧
        ! modification of surface albedo on the snow covered ground and on the sea ice
        !

        if ( .not. present( xy_SurfMajCompIceB ) ) then
          call MessageNotify( 'E', module_name, &
            & ' xy_SurfMajCompIceB has to be present to set xy_SurfAlbedo.' )
        end if
        if ( .not. present( xy_SurfSnowB ) ) then
          call MessageNotify( 'E', module_name, &
            & ' xy_SurfSnowB has to be present to set xy_SurfAlbedo.' )
        end if
        if ( .not. present( xy_SeaIceConc ) ) then
          call MessageNotify( 'E', module_name, &
            & ' xy_SeaIceConc has to be present to set xy_SurfAlbedo.' )
        end if

        if ( .not. present( xy_SurfType ) ) then
          call MessageNotify( 'E', module_name, &
            & ' xy_SurfType has to be present to set xy_SurfAlbedo.' )
        end if
!!$        if ( SurfTypeSetting /= 'file' ) then
!!$          call MessageNotify( 'E', module_name, &
!!$            & " SurfType has to be 'file'." )
!!$        end if

        call ModAlbedoDueToSnowSeaIce(                        &
          & xy_SurfType,                                      &
          & xy_SurfMajCompIceB, xy_SurfSnowB, xy_SeaIceConc,  & ! (in   ) optional
          & xy_SurfAlbedo                                     & ! (inout)
          & )
      else
        call MessageNotify( 'E', module_name, &
          & ' xy_SurfType has to be present to modify albedo due to snow and sea ice.' )
      end if

      FlagSetSurfAlbedo = .true.

      flag_first_SurfAlbedo = .false.
    end if

    ! 諠第弌陦ｨ髱｢貉ｿ貎､蠎ｦ
    ! Surface humidity coefficient
    !
    if ( present(xy_SurfHumidCoef) ) then

      ! NOTICE:
      ! The surface condition has to be set, before humidity coefficient
      ! is set.
      if ( .not. FlagSetSurfCond ) then
        call MessageNotify( 'E', module_name, &
          & " SurfCond has to be set before setting SurfHumidCoef is set." )
      end if

      if ( HumidCoefSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_SurfHumidCoef ) then
          call HistoryGet( &
            & HumidcoefFile, HumidcoefName, &  ! (in)
            & xy_SurfHumidcoef, &              ! (out)
            & flag_mpi_split = flag_mpi_init ) ! (in) optional
        end if
      else if ( HumidCoefSetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_SurfHumidCoef ) then
          call SetSurfData( &
            & xy_SurfHumidCoef = xy_SurfHumidCoef  & ! (out)
            & )
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' HumidCoefSetting = %c is not appropriate.', &
          & c1 = trim(HumidCoefSetting) )
      end if

      if ( FlagUseBucket ) then
        if ( &
          & ( present( xy_SurfType   ) ) .and. &
          & ( present( xy_SoilMoistB ) ) .and. &
          & ( present( xy_SurfSnowB  ) )       &
          & ) then
          ! 繝舌こ繝�Δ繝�Ν縺ｫ髢｢繧上ｋ蝨ｰ陦ｨ髱｢貉ｿ貎､蠎ｦ縺ｮ險ｭ螳�
          ! Setting of surface humidity coefficient
          !
          call BucketSetFlagOceanFromMatthews( &
            & xy_SurfType,                     & ! (in)
            & xy_BucketFlagOceanGrid           & ! (out)
            & )
          call BucketModHumidCoef(                                 &
            & xy_BucketFlagOceanGrid, xy_SoilMoistB, xy_SurfSnowB, & ! (in   )
            & xy_SurfHumidCoef                                     & ! (inout)
            & )
        else
          call MessageNotify( 'E', module_name, &
            & ' xy_SurfType, xy_SoilMoistB and xy_SurfSnowB have to be present to modify humidity coefficient with bucket model.' )
        end if
      end if

      FlagSetSurfHumidCoef = .true.

      flag_first_SurfHumidCoef = .false.
    end if

    ! 邊怜ｺｦ髟ｷ
    ! Roughness length
    !
    if ( present(xy_SurfRoughLenMom) ) then
      if ( .not. present(xy_SurfRoughLenHeat) ) then
        call MessageNotify( 'E', module_name, &
          & ' xy_SurfRoughLenHeat has to be present if xy_SurfRoughLenMom is present.' )
      end if
    else
      if ( present(xy_SurfRoughLenHeat) ) then
        call MessageNotify( 'E', module_name, &
          & ' xy_SurfRoughLenMom has to be present if xy_SurfRoughLenHeat is present.' )
      end if
    end if
    if ( present(xy_SurfRoughLenMom) .and. present(xy_SurfRoughLenHeat) ) then

      if ( RoughLengthSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_SurfRoughLen ) then
          call HistoryGet( &
            & RoughLengthFile, RoughLengthName, & ! (in)
            & xy_SurfRoughLenMom, &               ! (out)
            & flag_mpi_split = flag_mpi_init )    ! (in) optional
          ! set roughness length for heat
          xy_SurfRoughLenHeat = xy_SurfRoughLenMom * RoughLenHeatFactor
        end if
      else if ( RoughLengthSetting == 'LOContrast' ) then
        ! 邊怜ｺｦ髟ｷ縺ｮ險ｭ螳�, 髯ｸ髱｢縺ｨ豬ｷ豢九�蟾ｮ縺ｮ縺ｿ閠��
        ! Set roughness length, only considering land-ocean contrast
        !
        if ( .not. present( xy_SurfType ) ) then
          call MessageNotify( 'E', module_name, &
            & ' xy_SurfType has to be present to set xy_SurfAlbedo.' )
        end if
        if ( SurfTypeSetting /= 'file' ) then
          call MessageNotify( 'E', module_name, &
            & " SurfType has to be 'file', when RoughLengthSetting = %c.", &
            & c1 = trim(RoughLengthSetting) )
        end if
        call SetRoughLenLO(    &
          & xy_SurfType,       &
          & xy_SurfRoughLenMom &
          & )
        ! set roughness length for heat
        xy_SurfRoughLenHeat = xy_SurfRoughLenMom * RoughLenHeatFactor
      else if ( RoughLengthSetting == 'Matthews' ) then
        ! 邊怜ｺｦ髟ｷ縺ｮ險ｭ螳�, Matthews 縺ｮ繝��繧ｿ縺ｫ蝓ｺ縺･縺�
        ! Set roughness length based on Matthews dataset
        !
        if ( .not. FlagSetSurfType ) then
          call MessageNotify( 'E', module_name, &
            & ' xy_SurfType has to be set to set xy_SurfRoughLenMom.' )
        end if
        if ( SurfTypeSetting /= 'file' ) then
          call MessageNotify( 'E', module_name, &
            & " SurfType has to be 'file', when RoughLengthSetting = %c.", &
            & c1 = trim(RoughLengthSetting) )
        end if
        call SetRoughLenLandMatthews( &
          & "Mom", xy_SurfType,       &
          & xy_SurfRoughLenMom        &
          & )
        ! Modify albedo due to cultivation
        call ModRoughLenMatthewsCultivation(   &
          & "Mom", xy_SurfType, xy_SurfCulInt, &
          & xy_SurfRoughLenMom                 &
          & )

        ! set roughness length for heat
        call SetRoughLenLandMatthews( &
          & "Heat", xy_SurfType,      &
          & xy_SurfRoughLenHeat       &
          & )
        ! Modify albedo due to cultivation
        call ModRoughLenMatthewsCultivation(    &
          & "Heat", xy_SurfType, xy_SurfCulInt, &
          & xy_SurfRoughLenHeat                 &
          & )

      else if ( RoughLengthSetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_SurfRoughLen ) then
          call SetSurfData( &
            & xy_SurfRoughLength = xy_SurfRoughLenMom &          ! (out)
            & )
          ! set roughness length for heat
          xy_SurfRoughLenHeat = xy_SurfRoughLenMom * RoughLenHeatFactor
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' RoughLengthSetting = %c is not appropriate.', &
          & c1 = trim(RoughLengthSetting) )
      end if

      FlagSetSurfRoughLenMom  = .true.
      FlagSetSurfRoughLenHeat = .true.

      flag_first_SurfRoughLen = .false.
    end if

    ! 蝨ｰ陦ｨ辭ｱ螳ｹ驥�
    ! Surface heat capacity
    !
    if ( present(xy_SurfHeatCapacity) ) then

      if ( HeatCapacitySetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_SurfHeatCapacity ) then
          call HistoryGet( &
            & HeatCapacityFile, HeatCapacityName, & ! (in)
            & xy_SurfHeatCapacity, &                ! (out)
            & flag_mpi_split = flag_mpi_init )      ! (in) optional
        end if
      else if ( HeatCapacitySetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_SurfHeatCapacity ) then
          call SetSurfData( &
            & xy_SurfHeatCapacity = xy_SurfHeatCapacity &          ! (out)
            & )
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' HeatCapacitySetting = %c is not appropriate.', &
          & c1 = trim(HeatCapacitySetting) )
      end if

      FlagSetSurfHeatCapacity = .true.

      flag_first_SurfHeatCapacity = .false.
    end if

    ! 蝨ｰ荳ｭ辭ｱ繝輔Λ繝�け繧ｹ
    ! Ground temperature flux
    !
    if ( present(xy_DeepSubSurfHeatFlux) ) then

      if ( TempFluxSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_DeepSubSurfHeatFlux ) then
          call HistoryGet( &
            & TempFluxFile, TempFluxName, &     ! (in)
            & xy_DeepSubSurfHeatFlux, &              ! (out)
            & flag_mpi_split = flag_mpi_init )  ! (in) optional
        end if
      else if ( TempFluxSetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_DeepSubSurfHeatFlux ) then
          call SetSurfData( &
            & xy_DeepSubSurfHeatFlux = xy_DeepSubSurfHeatFlux &          ! (out)
            & )
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' TempFluxSetting = %c is not appropriate.', &
          & c1 = trim(TempFluxSetting) )
      end if

      FlagSetDeepSubSurfHeatFlux = .true.

      flag_first_DeepSubSurfHeatFlux = .false.
    end if

    ! 蝨溷｣檎�螳ｹ驥� (J K-1 kg-1)
    ! Specific heat of soil (J K-1 kg-1)
    !
    if ( present(xy_SoilHeatCap) ) then

      if ( SoilHeatCapSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_SoilHeatCap ) then
          call HistoryGet( &
            & SoilHeatCapFile, SoilHeatCapName, &     ! (in)
            & xy_SoilHeatCap, &              ! (out)
            & flag_mpi_split = flag_mpi_init )  ! (in) optional
        end if
      else if ( SoilHeatCapSetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_SoilHeatCap ) then
          call SetSurfData( &
            & xy_SoilHeatCap = xy_SoilHeatCap &          ! (out)
            & )
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' SoilHeatCapSetting = %c is not appropriate.', &
          & c1 = trim(SoilHeatCapSetting) )
      end if

      FlagSetSoilHeatCap = .true.

      flag_first_SoilHeatCap = .false.
    end if

    ! 蝨溷｣檎�莨晏ｰ守紫 (W m-1 K-1)
    ! Heat conduction coefficient of soil (W m-1 K-1)
    !
    if ( present(xy_SoilHeatDiffCoef) ) then

      if ( SoilHeatDiffCoefSetting == 'file' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_SoilHeatDiffCoef ) then
          call HistoryGet( &
            & SoilHeatDiffCoefFile, SoilHeatDiffCoefName, &     ! (in)
            & xy_SoilHeatDiffCoef, &              ! (out)
            & flag_mpi_split = flag_mpi_init )  ! (in) optional
        end if
      else if ( SoilHeatDiffCoefSetting == 'file_thermal_inertia' ) then
        ! 繝��繧ｿ繧偵ヵ繧｡繧､繝ｫ縺九ｉ蜿門ｾ�
        ! Data is input from files
        !
        if ( flag_first_SoilHeatDiffCoef ) then
          call HistoryGet( &
            & SoilHeatDiffCoefFile, SoilHeatDiffCoefName, &     ! (in)
            & xy_SoilHeatDiffCoef, &              ! (out)
            & flag_mpi_split = flag_mpi_init )  ! (in) optional

          if ( present( xy_SoilHeatCap ) ) then
            xy_SoilHeatDiffCoef = xy_SoilHeatDiffCoef**2 / xy_SoilHeatCap
          else
            call MessageNotify( 'E', module_name, &
              & ' xy_SoilHeatCap has to be present to calculate heat diffusion coefficient of soil from thermal inertia.' )
          end if
        end if
      else if ( SoilHeatDiffCoefSetting == 'generate_internally' ) then
        ! 繝��繧ｿ (繝�ヵ繧ｩ繝ｫ繝亥､) 繧� surface_data 繝｢繧ｸ繝･繝ｼ繝ｫ縺九ｉ蜿門ｾ�
        ! Data (default values) is input from "surface_data" module
        !
        if ( flag_first_SoilHeatDiffCoef ) then
          call SetSurfData( &
            & xy_SoilHeatDiffCoef = xy_SoilHeatDiffCoef &          ! (out)
            & )
        end if
      else if ( SoilHeatDiffCoefSetting == 'simple' ) then
        if ( .not. FlagUseBucket ) then
          call MessageNotify( 'E', module_name, &
            & ' FlagUseBucket has to be .true. to set soil thermal diffusion coefficient.' )
        end if
        if ( &
          & ( FlagSetSurfType          ) .and. &
          & ( present( xy_SoilMoistB ) )       &
          & ) then
          ! 蝨溷｣檎�莨晏ｰ惹ｿよ焚縺ｮ險ｭ螳�
          ! set soil thermal diffusion coefficient
          !
          call SetSoilThermDiffCoefSimple( &
            & xy_SurfType, xy_SoilMoistB,  & ! (in )
            & xy_SoilHeatDiffCoef          & ! (out)
            & )
        else
          call MessageNotify( 'E', module_name, &
            & ' xy_SurfType and xy_SoilMoistB have to be present to set soil thermal diffusion coefficient.' )
        end if
      else
        call MessageNotify( 'E', module_name, &
          & ' SoilHeatDiffCoefSetting = %c is not appropriate.', &
          & c1 = trim(TempFluxSetting) )
      end if

      FlagSetSoilHeatDiffCoef = .true.

      flag_first_SoilHeatDiffCoef = .false.
    end if

    ! 繝偵せ繝医Μ繝��繧ｿ蜃ｺ蜉�
    ! History data output
    !
    call HistoryAutoPut( TimeN, 'SurfCulInt', xy_SurfCulInt )

    ! 險育ｮ玲凾髢楢ｨ域ｸｬ荳譎ょ●豁｢
    ! Pause measurement of computation time
    !
    call TimesetClockStop( module_name )

  end subroutine SetSurfaceProperties

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

!!$  subroutine GroundFileOpen
!!$    !
!!$    ! 蝨ｰ陦ｨ髱｢繝��繧ｿ繝輔ぃ繧､繝ｫ繧偵が繝ｼ繝励Φ縺励∪縺�.
!!$    !
!!$    ! A ground data file is opened.
!!$    !
!!$
!!$    ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
!!$    !
!!$
!!$    ! 蜃ｺ蜉帙ヵ繧｡繧､繝ｫ縺ｮ蝓ｺ譛ｬ諠��ｱ
!!$    ! Basic information for output files
!!$    !
!!$    use fileset, only: &
!!$      & FileTitle, &
!!$                              ! 蜃ｺ蜉帙ョ繝ｼ繧ｿ繝輔ぃ繧､繝ｫ縺ｮ陦ｨ鬘�.
!!$                              ! Title of output data files
!!$      & FileSource, &
!!$                              ! 繝��繧ｿ繝輔ぃ繧､繝ｫ菴懈�縺ｮ謇区ｮｵ.
!!$                              ! Source of data file
!!$      & FileInstitution
!!$                              ! 繝��繧ｿ繝輔ぃ繧､繝ｫ繧呈怙邨ら噪縺ｫ螟画峩縺励◆邨�ｹ�/蛟倶ｺｺ.
!!$                              ! Institution or person that changes data files for the last time
!!$
!!$    ! 迚ｩ逅�ｮ壽焚險ｭ螳�
!!$    ! Physical constants settings
!!$    !
!!$    use constants, only: PI   ! $ \pi $ .
!!$                              ! 蜀�捉邇�.  Circular constant
!!$
!!$    ! 蠎ｧ讓吶ョ繝ｼ繧ｿ險ｭ螳�
!!$    ! Axes data settings
!!$    !
!!$    use axesset, only: &
!!$      & x_Lon, &
!!$                              ! $ \lambda $ [rad.] . 邨悟ｺｦ. Longitude
!!$      & x_Lon_Weight, &
!!$                              ! $ \Delta \lambda $ [rad.] .
!!$                              ! 邨悟ｺｦ蠎ｧ讓咎㍾縺ｿ.
!!$                              ! Weight of longitude
!!$      & y_Lat, &
!!$                              ! $ \varphi $ [rad.] . 邱ｯ蠎ｦ. Latitude
!!$      & y_Lat_Weight, &
!!$                              ! $ \Delta \varphi $ [rad.] .
!!$                              ! 邱ｯ蠎ｦ蠎ｧ讓咎㍾縺ｿ.
!!$                              ! Weight of latitude
!!$      & z_Sigma, &
!!$                              ! $ \sigma $ 繝ｬ繝吶Ν (謨ｴ謨ｰ).
!!$                              ! Full $ \sigma $ level
!!$      & r_Sigma, &
!!$                              ! $ \sigma $ 繝ｬ繝吶Ν (蜊頑紛謨ｰ).
!!$                              ! Half $ \sigma $ level
!!$      & z_DelSigma
!!$                              ! $ \Delta \sigma $ (謨ｴ謨ｰ).
!!$                              ! $ \Delta \sigma $ (Full)
!!$
!!$    ! 譎ょ綾邂｡逅�
!!$    ! Time control
!!$    !
!!$    use timeset, only: &
!!$      & DelTime, &            ! $ \Delta t $ [s]
!!$      & StartTime, &          ! 險育ｮ鈴幕蟋区凾蛻ｻ.
!!$                              ! Start time of calculation
!!$      & StartDate, &          ! 險育ｮ鈴幕蟋区律譎�.
!!$                              ! Start date of calculation
!!$      & StartDateValid        ! 險育ｮ鈴幕蟋区律譎ゅ�譛牙柑諤ｧ.
!!$                              ! Validation of start date of calculation
!!$
!!$    ! gtool4 繝��繧ｿ蜃ｺ蜉�
!!$    ! Gtool4 data output
!!$    !
!!$    use gtool_history, only: HistoryCreate, HistoryAddVariable, &
!!$      & HistoryPut, HistoryAddAttr
!!$
!!$    ! 譁�ｭ怜�謫堺ｽ�
!!$    ! Character handling
!!$    !
!!$    use dc_string, only: StoA
!!$
!!$    ! 譌･莉倥♀繧医�譎ょ綾縺ｮ蜿悶ｊ謇ｱ縺�
!!$    ! Date and time handler
!!$    !
!!$    use dc_date, only: toChar, EvalByUnit
!!$
!!$    ! 螳｣險譁� ; Declaration statements
!!$    !
!!$    implicit none
!!$
!!$    ! 菴懈･ｭ螟画焚
!!$    ! Work variables
!!$    !
!!$    real(DP):: origin_time
!!$                              ! 險育ｮ鈴幕蟋区凾蛻ｻ.
!!$                              ! Start time of calculation
!!$
!!$    ! 螳溯｡梧枚 ; Executable statement
!!$    !
!!$
!!$    ! 蛻晄悄蛹�
!!$    ! Initialization
!!$    !
!!$    if ( .not. ground_file_io_inited ) call GroundFileInit
!!$    if ( ground_file_opened ) return
!!$
!!$    ! 譎ょ綾諠��ｱ縺ｮ蜿門ｾ�
!!$    ! Get time information
!!$    !
!!$    origin_time = EvalByUnit( StartTime, IntUnit )
!!$
!!$    ! 蝨ｰ陦ｨ髱｢繝��繧ｿ繝輔ぃ繧､繝ｫ縺ｮ繧ｪ繝ｼ繝励Φ
!!$    ! Open a ground data file
!!$    !
!!$    call HistoryCreate( &
!!$      &      file = OutputFile,   &
!!$      &     title = trim(FileTitle) // ' ground data', &          ! (in)
!!$      &    source = FileSource, institution = FileInstitution, &   ! (in)
!!$      &      dims = StoA( 'lon', 'lat', 'sig', 'sigm', 'time' ), & ! (in)
!!$      &  dimsizes = (/ imax, jmax, kmax, kmax + 1, 0 /), &         ! (in)
!!$      & longnames = StoA( 'longitude', 'latitude', &
!!$      &                   'sigma at layer midpoints', &
!!$      &                   'sigma at layer end-points (half level)', &
!!$      &                   'time' ), &                              ! (in)
!!$      &     units = StoA( 'degree_east', 'degree_north', &
!!$      &                   '1', '1', IntUnit ), &                   ! (in)
!!$      &    origin = real( origin_time ), &                         ! (in)
!!$      &  interval = real( IntValue ), &                            ! (in)
!!$      &   history = gthst_grd )                                    ! (out)
!!$
!!$    ! $ \Delta t $ 縺ｫ髢｢縺吶ｋ諠��ｱ繧定ｿｽ蜉�
!!$    ! Add information about $ \Delta t $
!!$    !
!!$    call HistoryAddVariable( &
!!$      & varname = 'deltime', &            ! (in)
!!$      & dims = StoA(''), &                ! (in)
!!$      & longname = 'delta time', &        ! (in)
!!$      & units = 's', xtype = 'float', &   ! (in)
!!$      & history = gthst_grd )             ! (inout)
!!$    call HistoryPut( &
!!$      & varname = 'deltime', &            ! (in)
!!$      & array = (/ DelTime /), &          ! (in)
!!$      & history = gthst_grd )             ! (inout)
!!$
!!$    ! 蠎ｧ讓吶ョ繝ｼ繧ｿ縺ｮ險ｭ螳�
!!$    ! Axes data settings
!!$    !
!!$    call HistoryAddAttr( &
!!$      & varname = 'lon', attrname = 'standard_name', &   ! (in)
!!$      & value = 'longitude', &                           ! (in)
!!$      & history = gthst_grd )                            ! (inout)
!!$    call HistoryAddAttr( &
!!$      & varname = 'lat', attrname = 'standard_name', &   ! (in)
!!$      & value = 'latitude', &                            ! (in)
!!$      & history = gthst_grd )                            ! (inout)
!!$    call HistoryAddAttr( &
!!$      & varname = 'sig', attrname = 'standard_name', &   ! (in)
!!$      & value = 'atmosphere_sigma_coordinate', &         ! (in)
!!$      & history = gthst_grd )                            ! (inout)
!!$    call HistoryAddAttr( &
!!$      & varname = 'sigm', attrname = 'standard_name', &  ! (in)
!!$      & value = 'atmosphere_sigma_coordinate', &         ! (in)
!!$      & history = gthst_grd )                            ! (inout)
!!$    call HistoryAddAttr( &
!!$      & varname = 'time', attrname = 'standard_name', &  ! (in)
!!$      & value = 'time', &                                ! (in)
!!$      & history = gthst_grd )                            ! (inout)
!!$    call HistoryAddAttr( &
!!$      & varname = 'sig', attrname = 'positive', &        ! (in)
!!$      & value = 'down', &                                ! (in)
!!$      & history = gthst_grd )                            ! (inout)
!!$    call HistoryAddAttr( &
!!$      & varname = 'sigm', attrname = 'positive', &       ! (in)
!!$      & value = 'down', &                                ! (in)
!!$      & history = gthst_grd )                            ! (inout)
!!$
!!$    call HistoryPut( &
!!$      & varname = 'lon', &               ! (in)
!!$      & array = x_Lon / PI * 180.0_DP, & ! (in)
!!$      & history = gthst_grd )            ! (inout)
!!$    call HistoryPut( &
!!$      & varname = 'lat', &               ! (in)
!!$      & array = y_Lat / PI * 180.0_DP, & ! (in)
!!$      & history = gthst_grd )            ! (inout)
!!$    call HistoryPut( &
!!$      & varname = 'sig', &               ! (in)
!!$      & array = z_Sigma, &               ! (in)
!!$      & history = gthst_grd )            ! (inout)
!!$    call HistoryPut( &
!!$      & varname = 'sigm', &              ! (in)
!!$      & array = r_Sigma, &               ! (in)
!!$      & history = gthst_grd )            ! (inout)
!!$
!!$    ! 蠎ｧ讓咎㍾縺ｿ縺ｮ險ｭ螳�
!!$    ! Axes weights settings
!!$    !
!!$    call HistoryAddVariable( &
!!$      & varname = 'lon_weight', &                           ! (in)
!!$      & dims = StoA('lon'), &                               ! (in)
!!$      & longname = 'weight for integration in longitude', & ! (in)
!!$      & units = 'radian', xtype = 'double', &               ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryAddAttr( &
!!$      & varname = 'lon', attrname = 'gt_calc_weight', &     ! (in)
!!$      & value = 'lon_weight', &                             ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryPut( &
!!$      & varname = 'lon_weight', array = x_Lon_Weight, &     ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$
!!$    call HistoryAddVariable( &
!!$      & varname = 'lat_weight', &                           ! (in)
!!$      & dims = StoA('lat'), &                               ! (in)
!!$      & longname = 'weight for integration in latitude', &  ! (in)
!!$      & units = 'radian', xtype = 'double', &               ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryAddAttr( &
!!$      & varname = 'lat', attrname = 'gt_calc_weight', &     ! (in)
!!$      & value = 'lat_weight', &                             ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryPut( &
!!$      & varname = 'lat_weight', array = y_Lat_Weight, &     ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$
!!$    call HistoryAddVariable( &
!!$      & varname = 'sig_weight', &                           ! (in)
!!$      & dims = StoA('sig'), &                               ! (in)
!!$      & longname = 'weight for integration in sigma', &     ! (in)
!!$      & units = '1', xtype = 'double', &                    ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryAddAttr( &
!!$      & varname = 'sig', attrname = 'gt_calc_weight', &     ! (in)
!!$      & value = 'sig_weight', &                             ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryPut( &
!!$      & varname = 'sig_weight', array = z_DelSigma, &       ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$
!!$    ! 莠亥�ｱ螟画焚縺ｮ險ｭ螳�
!!$    ! Predictional variables settings
!!$    !
!!$    call HistoryAddVariable( &
!!$      & varname = 'UB', &                                   ! (in)
!!$      & dims = StoA('lon', 'lat', 'sig', 'time'), &         ! (in)
!!$      & longname = 'eastward wind (at t-\Delta t)', &       ! (in)
!!$      & units = 'm s-1', xtype = 'double', &                ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryAddVariable( &
!!$      & varname = 'VB', &                                   ! (in)
!!$      & dims = StoA('lon', 'lat', 'sig', 'time'), &         ! (in)
!!$      & longname = 'northward wind (at t-\Delta t)', &      ! (in)
!!$      & units = 'm s-1', xtype = 'double', &                ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryAddVariable( &
!!$      & varname = 'TempB', &                                ! (in)
!!$      & dims = StoA('lon', 'lat', 'sig', 'time'), &         ! (in)
!!$      & longname = 'temperature (at t-\Delta t)', &         ! (in)
!!$      & units = 'K', xtype = 'double', &                    ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryAddVariable( &
!!$      & varname = 'QVapB', &                                ! (in)
!!$      & dims = StoA('lon', 'lat', 'sig', 'time'), &         ! (in)
!!$      & longname = 'specific humidity (at t-\Delta t)', &   ! (in)
!!$      & units = 'kg kg-1', xtype = 'double', &              ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryAddVariable( &
!!$      & varname = 'PsB', &                                  ! (in)
!!$      & dims = StoA('lon', 'lat', 'time'), &                ! (in)
!!$      & longname = 'surface pressure (at t-\Delta t)', &    ! (in)
!!$      & units = 'Pa', xtype = 'double', &                   ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$
!!$    call HistoryAddVariable( &
!!$      & varname = 'UN', &                                   ! (in)
!!$      & dims = StoA('lon', 'lat', 'sig', 'time'), &         ! (in)
!!$      & longname = 'eastward wind (at t)', &                ! (in)
!!$      & units = 'm s-1', xtype = 'double', &                ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryAddVariable( &
!!$      & varname = 'VN', &                                   ! (in)
!!$      & dims = StoA('lon', 'lat', 'sig', 'time'), &         ! (in)
!!$      & longname = 'northward wind (at t)', &               ! (in)
!!$      & units = 'm s-1', xtype = 'double', &                ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryAddVariable( &
!!$      & varname = 'TempN', &                                ! (in)
!!$      & dims = StoA('lon', 'lat', 'sig', 'time'), &         ! (in)
!!$      & longname = 'temperature (at t)', &                  ! (in)
!!$      & units = 'K', xtype = 'double', &                    ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryAddVariable( &
!!$      & varname = 'QVapN', &                                ! (in)
!!$      & dims = StoA('lon', 'lat', 'sig', 'time'), &         ! (in)
!!$      & longname = 'specific humidity (at t)', &            ! (in)
!!$      & units = 'kg kg-1', xtype = 'double', &              ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$    call HistoryAddVariable( &
!!$      & varname = 'PsN', &                                  ! (in)
!!$      & dims = StoA('lon', 'lat', 'time'), &                ! (in)
!!$      & longname = 'surface pressure (at t)', &             ! (in)
!!$      & units = 'Pa', xtype = 'double', &                   ! (in)
!!$      & history = gthst_grd )                               ! (inout)
!!$
!!$    ground_file_opened = .true.
!!$  end subroutine GroundFileOpen
!!$
!!$  !-------------------------------------------------------------------
!!$
!!$  subroutine GroundFileOutput( &
!!$    & xyz_UB, xyz_VB, xyz_TempB, xyz_QVapB, xy_PsB, &   ! (in)
!!$    & xyz_UN, xyz_VN, xyz_TempN, xyz_QVapN, xy_PsN  &   ! (in)
!!$    & )
!!$    !
!!$    ! 蝨ｰ陦ｨ髱｢繝��繧ｿ縺ｮ蜃ｺ蜉帙ｒ陦後＞縺ｾ縺�.
!!$    !
!!$    ! Output ground data
!!$
!!$    ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
!!$    !
!!$
!!$    ! gtool4 繝��繧ｿ蜃ｺ蜉�
!!$    ! Gtool4 data output
!!$    !
!!$    use gtool_history, only: HistoryPut
!!$
!!$    ! 譎ょ綾邂｡逅�
!!$    ! Time control
!!$    !
!!$    use timeset, only: TimeN  ! 繧ｹ繝�ャ繝� $ t $ 縺ｮ譎ょ綾.
!!$                              ! Time of step $ t $.
!!$
!!$    ! 螳｣險譁� ; Declaration statements
!!$    !
!!$    implicit none
!!$    real(DP), intent(in):: xyz_UB  (0:imax-1, 1:jmax, 1:kmax)
!!$                              ! $ u (t-\Delta t) $ .   譚ｱ隘ｿ鬚ｨ騾�. Eastward wind
!!$    real(DP), intent(in):: xyz_VB  (0:imax-1, 1:jmax, 1:kmax)
!!$                              ! $ v (t-\Delta t) $ .   蜊怜圏鬚ｨ騾�. Northward wind
!!$    real(DP), intent(in):: xyz_TempB  (0:imax-1, 1:jmax, 1:kmax)
!!$                              ! $ T (t-\Delta t) $ .   貂ｩ蠎ｦ. Temperature
!!$    real(DP), intent(in):: xyz_QVapB  (0:imax-1, 1:jmax, 1:kmax)
!!$                              ! $ q (t-\Delta t) $ .   豈疲ｹｿ. Specific humidity
!!$    real(DP), intent(in):: xy_PsB (0:imax-1, 1:jmax)
!!$                              ! $ p_s (t-\Delta t) $ . 蝨ｰ陦ｨ髱｢豌怜悸. Surface pressure
!!$    real(DP), intent(in):: xyz_UN  (0:imax-1, 1:jmax, 1:kmax)
!!$                              ! $ u (t) $ .     譚ｱ隘ｿ鬚ｨ騾�. Eastward wind
!!$    real(DP), intent(in):: xyz_VN  (0:imax-1, 1:jmax, 1:kmax)
!!$                              ! $ v (t) $ .     蜊怜圏鬚ｨ騾�. Northward wind
!!$    real(DP), intent(in):: xyz_TempN  (0:imax-1, 1:jmax, 1:kmax)
!!$                              ! $ T (t) $ .     貂ｩ蠎ｦ. Temperature
!!$    real(DP), intent(in):: xyz_QVapN  (0:imax-1, 1:jmax, 1:kmax)
!!$                              ! $ q (t) $ .     豈疲ｹｿ. Specific humidity
!!$    real(DP), intent(in):: xy_PsN (0:imax-1, 1:jmax)
!!$                              ! $ p_s (t) $ .   蝨ｰ陦ｨ髱｢豌怜悸. Surface pressure
!!$
!!$    ! 菴懈･ｭ螟画焚
!!$    ! Work variables
!!$    !
!!$
!!$
!!$    ! 螳溯｡梧枚 ; Executable statement
!!$    !
!!$
!!$    if ( .not. ground_file_opened ) call GroundFileOpen
!!$
!!$    ! 蜃ｺ蜉帙ち繧､繝溘Φ繧ｰ縺ｮ繝√ぉ繝�け
!!$    ! Check output timing
!!$    !
!!$    if ( TimeN - PrevOutputTime < IntTime ) return
!!$    PrevOutputTime = TimeN
!!$
!!$    ! 繝��繧ｿ蜃ｺ蜉�
!!$    ! Data output
!!$    !
!!$    call HistoryPut( &
!!$      & 'UB', xyz_UB, history = gthst_grd ) ! (in)
!!$    call HistoryPut( &
!!$      & 'VB', xyz_VB, history = gthst_grd ) ! (in)
!!$    call HistoryPut( &
!!$      & 'TempB', xyz_TempB, history = gthst_grd ) ! (in)
!!$    call HistoryPut( &
!!$      & 'QVapB', xyz_QVapB, history = gthst_grd ) ! (in)
!!$    call HistoryPut( &
!!$      & 'PsB', xy_PsB, history = gthst_grd ) ! (in)
!!$
!!$    call HistoryPut( &
!!$      & 'UN', xyz_UN, history = gthst_grd ) ! (in)
!!$    call HistoryPut( &
!!$      & 'VN', xyz_VN, history = gthst_grd ) ! (in)
!!$    call HistoryPut( &
!!$      & 'TempN', xyz_TempN, history = gthst_grd ) ! (in)
!!$    call HistoryPut( &
!!$      & 'QVapN', xyz_QVapN, history = gthst_grd ) ! (in)
!!$    call HistoryPut( &
!!$      & 'PsN', xy_PsN, history = gthst_grd ) ! (in)
!!$
!!$  end subroutine GroundFileOutput
!!$
!!$  !-------------------------------------------------------------------
!!$
!!$  subroutine GroundFileClose
!!$    !
!!$    ! 蝨ｰ陦ｨ髱｢繝��繧ｿ繝輔ぃ繧､繝ｫ蜃ｺ蜉帙�邨ゆｺ��逅�ｒ陦後＞縺ｾ縺�.
!!$    !
!!$    ! Terminate ground data files output.
!!$
!!$    ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
!!$    !
!!$
!!$    ! gtool4 繝��繧ｿ蜃ｺ蜉�
!!$    ! Gtool4 data output
!!$    !
!!$    use gtool_history, only: HistoryClose
!!$
!!$    ! 螳｣險譁� ; Declaration statements
!!$    !
!!$    implicit none
!!$
!!$    ! 菴懈･ｭ螟画焚
!!$    ! Work variables
!!$    !
!!$
!!$    ! 螳溯｡梧枚 ; Executable statement
!!$    !
!!$    if ( .not. ground_file_opened ) return
!!$
!!$    call HistoryClose( history = gthst_grd ) ! (inout)
!!$
!!$    ground_file_opened = .false.
!!$  end subroutine GroundFileClose

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

  subroutine SurfacePropertiesInit(                     &
    & ArgFlagSlabOcean, ArgFlagUseBucket, ArgFlagSnow   & ! (in)
    & )
    !
    ! surface_properties 繝｢繧ｸ繝･繝ｼ繝ｫ縺ｮ蛻晄悄蛹悶ｒ陦後＞縺ｾ縺�.
    ! NAMELIST#surface_properties_nml 縺ｮ隱ｭ縺ｿ霎ｼ縺ｿ縺ｯ縺薙�謇狗ｶ壹″縺ｧ陦後ｏ繧後∪縺�.
    !
    ! "surface_properties" module is initialized.
    ! "NAMELIST#surface_properties_nml" is loaded in this procedure.
    !

    ! 繝｢繧ｸ繝･繝ｼ繝ｫ蠑慕畑 ; USE statements
    !

    ! 遞ｮ蛻･蝙九ヱ繝ｩ繝｡繧ｿ
    ! Kind type parameter
    !
    use dc_types, only: STDOUT ! 讓呎ｺ門�蜉帙�陬�ｽｮ逡ｪ蜿ｷ. Unit number of standard output

    ! 繝輔ぃ繧､繝ｫ蜈･蜃ｺ蜉幄｣懷勧
    ! File I/O support
    !
    use dc_iounit, only: FileOpen

    ! 繝偵せ繝医Μ繝��繧ｿ蜃ｺ蜉�
    ! History data output
    !
    use gtool_historyauto, only: HistoryAutoAddVariable

    ! NAMELIST 繝輔ぃ繧､繝ｫ蜈･蜉帙↓髢｢縺吶ｋ繝ｦ繝ｼ繝�ぅ繝ｪ繝�ぅ
    ! Utilities for NAMELIST file input
    !
    use namelist_util, only: namelist_filename, NmlutilMsg

    ! 譎ょ綾邂｡逅�
    ! Time control
    !
    use timeset, only: DelTime  ! $ \Delta t $ [s]

    !
    ! Routines for GABLS tests
    !
    use gabls, only : GablsInit

    ! Matthews 縺ｮ繝��繧ｿ縺ｫ蝓ｺ縺･縺乗ヱ譏溯｡ｨ髱｢繧｢繝ｫ繝吶ラ險ｭ螳�
    ! set surface albedo based on data by Matthews
    !
    use albedo_Matthews, only : AlbedoMatthewsInit

    ! 繝舌こ繝�Δ繝�Ν
    ! Bucket model
    !
    use Bucket_Model, only : BucketModelInit

    ! 髮ｪ縺ｨ豬ｷ豌ｷ縺ｫ繧医ｋ繧｢繝ｫ繝吶ラ螟牙喧
    ! modification of surface albedo on the snow covered ground and on the sea ice
    !
    use modify_albedo_snowseaice, only : ModAlbedoSnowSeaIceInit

    ! 繧｢繝ｫ繝吶ラ, 邊怜ｺｦ髟ｷ縺ｮ險ｭ螳�, 髯ｸ髱｢縺ｨ豬ｷ豢九�蟾ｮ縺ｮ縺ｿ閠��
    ! Set albedo and roughness length, only considering land-ocean contrast
    !
    use surface_properties_lo, only : SurfacePropertiesLOInit

    ! Matthews 縺ｮ繝��繧ｿ縺ｫ蝓ｺ縺･縺丞慍髱｢邊怜ｺｦ縺ｮ險ｭ螳�
    ! set roughness length on land surface based on data by Matthews
    !
    use roughlen_Matthews, only : RoughLenMatthewsInit

    ! 蝨溷｣檎�莨晏ｰ惹ｿよ焚縺ｮ險ｭ螳�
    ! set soil thermal diffusion coefficient
    !
    use soil_thermdiffcoef, only : SoilThermDiffCoefInit

    ! 螳｣險譁� ; Declaration statements
    !
    logical, intent(in ) :: ArgFlagSlabOcean
                              ! 繧ｹ繝ｩ繝悶が繝ｼ繧ｷ繝｣繝ｳ 繧ｪ繝ｳ�上が繝�.
                              ! flag for use of slab ocean on/off
    logical, intent(in ) :: ArgFlagUseBucket
                              !
                              ! flag for bucket model
    logical, intent(in ) :: ArgFlagSnow
                              !
                              ! flag for snow

    ! 菴懈･ｭ螟画焚
    ! Work variables
    !
    integer:: unit_nml        ! NAMELIST 繝輔ぃ繧､繝ｫ繧ｪ繝ｼ繝励Φ逕ｨ陬�ｽｮ逡ｪ蜿ｷ.
                              ! Unit number for NAMELIST file open
    integer:: iostat_nml      ! NAMELIST 隱ｭ縺ｿ霎ｼ縺ｿ譎ゅ� IOSTAT.
                              ! IOSTAT of NAMELIST read

    ! NAMELIST 螟画焚鄒､
    ! NAMELIST group name
    !
    namelist /surface_properties_nml/ &
      & SurfTempSetting,     &
      & SurfTempFile,        &
      & SurfTempName,        &
      & SeaIceSetting,       &
      & SeaIceFile,          &
      & SeaIceName,          &
      & AlbedoSetting,       &
      & AlbedoFile,          &
      & AlbedoName,          &
      & HumidCoefSetting,    &
      & HumidCoefFile,       &
      & HumidCoefName,       &
      & RoughLengthSetting,  &
      & RoughLengthFile,     &
      & RoughLengthName,     &
      & HeatCapacitySetting, &
      & HeatCapacityFile,    &
      & HeatCapacityName,    &
      & TempFluxSetting,     &
      & TempFluxFile,        &
      & TempFluxName,        &
      & SurfCondSetting,     &
      & SurfCondFile,        &
      & SurfCondName,        &
      & SurfTypeSetting,     &
      & SurfTypeFile,        &
      & SurfTypeName,        &
      & SurfCulIntSetting,   &
      & SurfCulIntFile,      &
      & SurfCulIntName,      &
      & SurfHeightSetting,   &
      & SurfHeightFile,      &
      & SurfHeightName,      &
      & SurfHeightStdSetting,&
      & SurfHeightStdFile,   &
      & SurfHeightStdName,   &
      & SoilHeatCapSetting,  &
      & SoilHeatCapFile,     &
      & SoilHeatCapName,     &
      & SoilHeatDiffCoefSetting, &
      & SoilHeatDiffCoefFile,    &
      & SoilHeatDiffCoefName,    &
      & RoughLenHeatFactor

          ! 繝�ヵ繧ｩ繝ｫ繝亥､縺ｫ縺､縺�※縺ｯ蛻晄悄蛹匁焔邯� "surface_properties#SurfacePropertiesInit"
          ! 縺ｮ繧ｽ繝ｼ繧ｹ繧ｳ繝ｼ繝峨ｒ蜿ら�縺ｮ縺薙→.
          !
          ! Refer to source codes in the initialization procedure
          ! "surface_properties#SurfacePropertiesInit" for the default values.
          !

!!$      & OutputFile, &
!!$      & IntValue, IntUnit

    ! 螳溯｡梧枚 ; Executable statement
    !

    if ( surface_properties_inited ) return

    ! Set flag for slab ocean
    FlagUseBucket = ArgFlagUseBucket

    FlagSlabOcean = ArgFlagSlabOcean

    ! 繝�ヵ繧ｩ繝ｫ繝亥､縺ｮ險ｭ螳�
    ! Default values settings
    !
    SurfTempSetting         = 'generate_internally'
    SurfTempFile            = ''
    SurfTempName            = ''
    SeaIceSetting           = 'generate_internally'
    SeaIceFile              = ''
    SeaIceName              = ''
    AlbedoSetting           = 'generate_internally'
    AlbedoFile              = ''
    AlbedoName              = ''
    HumidCoefSetting        = 'generate_internally'
    HumidCoefFile           = ''
    HumidCoefName           = ''
    RoughLengthSetting      = 'generate_internally'
    RoughLengthFile         = ''
    RoughLengthName         = ''
    HeatCapacitySetting     = 'generate_internally'
    HeatCapacityFile        = ''
    HeatCapacityName        = ''
    TempFluxSetting         = 'generate_internally'
    TempFluxFile            = ''
    TempFluxName            = ''
    SurfCondSetting         = 'generate_internally'
    SurfCondFile            = ''
    SurfCondName            = ''
    SurfTypeSetting         = 'generate_internally'
    SurfTypeFile            = ''
    SurfTypeName            = ''
    SurfCulIntSetting       = 'generate_internally'
    SurfCulIntFile          = ''
    SurfCulIntName          = ''
    SurfHeightSetting       = 'generate_internally'
    SurfHeightFile          = ''
    SurfHeightName          = ''
    SurfHeightStdSetting    = 'generate_internally'
    SurfHeightStdFile       = ''
    SurfHeightStdName       = ''
    SoilHeatCapSetting      = 'generate_internally'
    SoilHeatCapFile         = ''
    SoilHeatCapName         = ''
    SoilHeatDiffCoefSetting = 'generate_internally'
    SoilHeatDiffCoefFile    = ''
    SoilHeatDiffCoefName    = ''

    RoughLenHeatFactor = 1.0_DP

!!$    OutputFile = 'sst.nc'
!!$    IntValue   = 1.0_DP
!!$    IntUnit    = 'day'

    ! NAMELIST 縺ｮ隱ｭ縺ｿ霎ｼ縺ｿ
    ! NAMELIST is input
    !
    if ( trim(namelist_filename) /= '' ) then
      call FileOpen( unit_nml, &          ! (out)
        & namelist_filename, mode = 'r' ) ! (in)

      rewind( unit_nml )
      read( unit_nml,                   &  ! (in)
        & nml = surface_properties_nml, &  ! (out)
        & iostat = iostat_nml           &  ! (out)
        & )
      close( unit_nml )

      call NmlutilMsg( iostat_nml, module_name ) ! (in)
      if ( iostat_nml == 0 ) write( STDOUT, nml = surface_properties_nml )
    end if

!!$    ! 蜃ｺ蜉帶凾髢馴俣髫斐�險ｭ螳�
!!$    ! Configure time interval of output
!!$    !
!!$    call DCDiffTimeCreate( PrevOutputTime, & ! (out)
!!$      & sec = 0.0_DP )                       ! (in)
!!$    call DCDiffTimeCreate( IntTime, & ! (out)
!!$      & IntValue, IntUnit )           ! (in)

    ! A Value of "SurfTempSetting" is checked.
    !
    if ( ( SurfTempSetting == 'file' ) .and. ( FlagSlabOcean ) ) then
      call MessageNotify( 'E', module_name, &
        & "If FlagSlabOcean is .true., SurfTempSetting must not be 'file'." )
    end if

    ! Initialization of modules used in this module
    !

    ! Matthews 縺ｮ繝��繧ｿ縺ｫ蝓ｺ縺･縺乗ヱ譏溯｡ｨ髱｢繧｢繝ｫ繝吶ラ險ｭ螳�
    ! set surface albedo based on data by Matthews
    !
    call AlbedoMatthewsInit

    if ( FlagUseBucket ) then
      ! 繝舌こ繝�Δ繝�Ν
      ! Bucket model
      !
      call BucketModelInit( &
        & ArgFlagSnow       &
        & )
    end if

    !
    ! Routines for GABLS tests
    !
    call GablsInit

    ! 髮ｪ縺ｨ豬ｷ豌ｷ縺ｫ繧医ｋ繧｢繝ｫ繝吶ラ螟牙喧
    ! modification of surface albedo on the snow covered ground and on the sea ice
    !
    call ModAlbedoSnowSeaIceInit

    ! 繧｢繝ｫ繝吶ラ, 邊怜ｺｦ髟ｷ縺ｮ險ｭ螳�, 髯ｸ髱｢縺ｨ豬ｷ豢九�蟾ｮ縺ｮ縺ｿ閠��
    ! Set albedo and roughness length, only considering land-ocean contrast
    !
    call SurfacePropertiesLOInit

    ! Matthews 縺ｮ繝��繧ｿ縺ｫ蝓ｺ縺･縺丞慍髱｢邊怜ｺｦ縺ｮ險ｭ螳�
    ! set roughness length on land surface based on data by Matthews
    !
    call RoughLenMatthewsInit

    ! 蝨溷｣檎�莨晏ｰ惹ｿよ焚縺ｮ險ｭ螳�
    ! set soil thermal diffusion coefficient
    !
    call SoilThermDiffCoefInit( &
      & ArgFlagSnow &
      & )

    ! 繝偵せ繝医Μ繝��繧ｿ蜃ｺ蜉帙�縺溘ａ縺ｮ縺ｸ縺ｮ螟画焚逋ｻ骭ｲ
    ! Register of variables for history data output
    !
    call HistoryAutoAddVariable( 'SurfCulInt' , &  ! (in)
      & (/ 'lon ', 'lat ', 'time' /),           &  ! (in)
      & 'cultivation intensity', '1' )             ! (in)

    ! 蜊ｰ蟄� ; Print
    !
    call MessageNotify( 'M', module_name, '----- Initialization Messages -----' )
    call MessageNotify( 'M', module_name, 'Input:: ' )
    call MessageNotify( 'M', module_name, '  SurfTempSetting         = %c', c1 = trim(SurfTempSetting) )
    call MessageNotify( 'M', module_name, '  SurfTempFile            = %c', c1 = trim(SurfTempFile) )
    call MessageNotify( 'M', module_name, '  SurfTempName            = %c', c1 = trim(SurfTempName        ) )
    call MessageNotify( 'M', module_name, '  SeaIceSetting           = %c', c1 = trim(SeaIceSetting) )
    call MessageNotify( 'M', module_name, '  SeaIceFile              = %c', c1 = trim(SeaIceFile) )
    call MessageNotify( 'M', module_name, '  SeaIceName              = %c', c1 = trim(SeaIceName        ) )
    call MessageNotify( 'M', module_name, '  AlbedoSetting           = %c', c1 = trim(AlbedoSetting      ) )
    call MessageNotify( 'M', module_name, '  AlbedoFile              = %c', c1 = trim(AlbedoFile      ) )
    call MessageNotify( 'M', module_name, '  AlbedoName              = %c', c1 = trim(AlbedoName      ) )
    call MessageNotify( 'M', module_name, '  HumidCoefSetting        = %c', c1 = trim(HumidCoefSetting ) )
    call MessageNotify( 'M', module_name, '  HumidCoefFile           = %c', c1 = trim(HumidCoefFile  ) )
    call MessageNotify( 'M', module_name, '  HumidCoefName           = %c', c1 = trim(HumidCoefName  ) )
    call MessageNotify( 'M', module_name, '  RoughLengthSetting      = %c', c1 = trim(RoughLengthSetting ) )
    call MessageNotify( 'M', module_name, '  RoughLengthFile         = %c', c1 = trim(RoughLengthFile ) )
    call MessageNotify( 'M', module_name, '  RoughLengthName         = %c', c1 = trim(RoughLengthName ) )
    call MessageNotify( 'M', module_name, '  HeatCapacitySetting     = %c', c1 = trim(HeatCapacitySetting) )
    call MessageNotify( 'M', module_name, '  HeatCapacityFile        = %c', c1 = trim(HeatCapacityFile) )
    call MessageNotify( 'M', module_name, '  HeatCapacityName        = %c', c1 = trim(HeatCapacityName) )
    call MessageNotify( 'M', module_name, '  TempFluxSetting         = %c', c1 = trim(TempFluxSetting  ) )
    call MessageNotify( 'M', module_name, '  TempFluxFile            = %c', c1 = trim(TempFluxFile  ) )
    call MessageNotify( 'M', module_name, '  TempFluxName            = %c', c1 = trim(TempFluxName  ) )
    call MessageNotify( 'M', module_name, '  SurfCondSetting         = %c', c1 = trim(SurfCondSetting   ) )
    call MessageNotify( 'M', module_name, '  SurfCondFile            = %c', c1 = trim(SurfCondFile   ) )
    call MessageNotify( 'M', module_name, '  SurfCondName            = %c', c1 = trim(SurfCondName   ) )
    call MessageNotify( 'M', module_name, '  SurfTypeSetting         = %c', c1 = trim(SurfTypeSetting   ) )
    call MessageNotify( 'M', module_name, '  SurfTypeFile            = %c', c1 = trim(SurfTypeFile   ) )
    call MessageNotify( 'M', module_name, '  SurfTypeName            = %c', c1 = trim(SurfTypeName   ) )
    call MessageNotify( 'M', module_name, '  SurfCulIntSetting       = %c', c1 = trim(SurfCulIntSetting   ) )
    call MessageNotify( 'M', module_name, '  SurfCulIntFile          = %c', c1 = trim(SurfCulIntFile   ) )
    call MessageNotify( 'M', module_name, '  SurfCulIntName          = %c', c1 = trim(SurfCulIntName   ) )
    call MessageNotify( 'M', module_name, '  SurfHeightSetting       = %c', c1 = trim(SurfHeightSetting   ) )
    call MessageNotify( 'M', module_name, '  SurfHeightFile          = %c', c1 = trim(SurfHeightFile   ) )
    call MessageNotify( 'M', module_name, '  SurfHeightName          = %c', c1 = trim(SurfHeightName   ) )
    call MessageNotify( 'M', module_name, '  SurfHeightStdSetting    = %c', c1 = trim(SurfHeightStdSetting   ) )
    call MessageNotify( 'M', module_name, '  SurfHeightStdFile       = %c', c1 = trim(SurfHeightStdFile   ) )
    call MessageNotify( 'M', module_name, '  SurfHeightStdName       = %c', c1 = trim(SurfHeightStdName   ) )
    call MessageNotify( 'M', module_name, '  SoilHeatCapSetting      = %c', c1 = trim(SoilHeatCapSetting   ) )
    call MessageNotify( 'M', module_name, '  SoilHeatCapFile         = %c', c1 = trim(SoilHeatCapFile   ) )
    call MessageNotify( 'M', module_name, '  SoilHeatCapName         = %c', c1 = trim(SoilHeatCapName   ) )
    call MessageNotify( 'M', module_name, '  SoilHeatDiffCoefSetting = %c', c1 = trim(SoilHeatDiffCoefSetting   ) )
    call MessageNotify( 'M', module_name, '  SoilHeatDiffCoefFile    = %c', c1 = trim(SoilHeatDiffCoefFile   ) )
    call MessageNotify( 'M', module_name, '  SoilHeatDiffCoefName    = %c', c1 = trim(SoilHeatDiffCoefName   ) )

    call MessageNotify( 'M', module_name, '  RoughLenHeatFactor      = %f', d = (/RoughLenHeatFactor/) )

!!$    call MessageNotify( 'M', module_name, 'Output:: ' )
!!$    call MessageNotify( 'M', module_name, '  OutputFile = %c', c1 = trim(OutputFile) )
!!$    call MessageNotify( 'M', module_name, '  IntTime    = %f [%c]', d = (/ IntValue /), c1 = trim(IntUnit) )
    call MessageNotify( 'M', module_name, '-- version = %c', c1 = trim(version) )

    surface_properties_inited = .true.

  end subroutine SurfacePropertiesInit

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

end module surface_properties