!
! This is an old version of code to be deleted.
!

!= ç©é›²ãƒ‘ãƒ©ãƒ¡ã‚¿ãƒªã‚¼ãƒ¼ã‚·ãƒ§ãƒ³: å¯¾æµèª¿ç¯€ã‚¹ã‚ãƒ¼ãƒ
!
!= Cumulus parameterization: Convective adjustment scheme
!
! Authors::   Yoshiyuki O. Takahashi, Yasuhiro MORIKAWA, Yukiko YAMADA
! Version::   $Id: cumulus_adjust.F90,v 1.7 2014/05/07 09:39:11 murashin Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2008. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!

module cumulus_adjust
  !
  != ç©é›²ãƒ‘ãƒ©ãƒ¡ã‚¿ãƒªã‚¼ãƒ¼ã‚·ãƒ§ãƒ³: å¯¾æµèª¿ç¯€ã‚¹ã‚ãƒ¼ãƒ
  !
  != Cumulus parameterization: Convective adjustment scheme
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !
  ! å¯¾æµèª¿ç¯€ã‚¹ã‚ãƒ¼ãƒ ã«ã‚ˆã‚Š, æ¸©åº¦ã¨æ¯”æ¹¿ã‚’èª¿ç¯€ã—ã¾ã™.
  !
  ! é£½å’Œæ¯”æ¹¿ã®è¨ˆç®—ã«ã¯ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã§ã¯
  ! Tetens (1930) ã‚’ç”¨ã„ã¾ã™ (saturate_t1930 å‚ç…§).
  ! ã¾ãŸ, Config.mk ã® CPPFLAGS ã« -DLIB_SATURATE_NHA1992 ã‚’æŒ‡å®šã™ã‚‹ã¨
  ! Nakajima et al. (1992) ã‚’ç”¨ã„ã¾ã™ (saturate_tnha1992 å‚ç…§).
  !
  ! Adjust temperature and specific humidity by
  ! convective adjustment scheme.
  !
  ! By default, Tetens (1930) is used for calculation of
  ! saturation specific humidity (See "saturate_t1930").
  ! If "-DLIB_SATURATE_NHA1992" is specified to "CPPFLAGS" in Config.mk,
  ! Nakajima et al. (1992) is used (See "saturate_nha1992").
  !
  !== Procedures List
  !
  ! Cumulus       :: æ¸©åº¦ã¨æ¯”æ¹¿ã®èª¿ç¯€
  ! ------------  :: ------------
  ! Cumulus       :: Adjust temperature and specific humidity
  !
  !== NAMELIST
  !
  ! NAMELIST#cumulus_adjust_nml
  !

  ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«å¼•ç”¨ ; 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

  ! ç¨®åˆ¥åž‹ãƒ‘ãƒ©ãƒ¡ã‚¿
  ! Kind type parameter
  !
  use dc_types, only: DP, &      ! å€ç²¾åº¦å®Ÿæ•°åž‹. Double precision.
    &                 STRING     ! æ–‡å—åˆ—.       Strings.

  ! NAMELIST ãƒ•ã‚¡ã‚¤ãƒ«å…¥åŠ›ã«é–¢ã™ã‚‹ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£
  ! Utilities for NAMELIST file input
  !
  use namelist_util, only: MaxNmlArySize
                              ! NAMELIST ã‹ã‚‰èªã¿è¾¼ã‚€é…åˆ—ã®æœ€å¤§ã‚µã‚¤ã‚º.
                              ! Maximum size of arrays loaded from NAMELIST

  ! ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸å‡ºåŠ›
  ! Message output
  !
  use dc_message, only: MessageNotify

  ! å®£è¨€æ–‡ ; Declaration statements
  !
  implicit none
  private

  ! å…¬é–‹æ‰‹ç¶šã
  ! Public procedure
  !
  public:: Cumulus

  ! å…¬é–‹å¤‰æ•°
  ! Public variables
  !
  logical, save, public:: cumulus_adjust_inited = .false.
                              ! åˆæœŸè¨å®šãƒ•ãƒ©ã‚°.
                              ! Initialization flag

  ! éžå…¬é–‹å¤‰æ•°
  ! Private variables
  !
  real(DP), save:: CrtlRH
                              ! è‡¨ç•Œç›¸å¯¾æ¹¿åº¦.
                              ! Critical relative humidity
  integer, save:: ItrtMax
                              ! ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚·ãƒ§ãƒ³å›žæ•°.
                              ! Number of iteration

  real(DP), save:: TempSatMax(1:MaxNmlArySize)
                              ! ä¸å®‰å®šã®è¨±å®¹èª¤å·®.
                              ! Admissible error of unstability

  character(*), parameter:: saturate_scheme = &
#ifdef LIB_SATURATE_NHA1992
    & 'Nakajima et al. (1992)'
#elif LIB_SATURATE_T1930
    & 'Tetens (1930)'
#else
    & 'Tetens (1930)'
#endif

  character(*), parameter:: module_name = 'cumulus_adjust'
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åç§°.
                              ! Module name
  character(*), parameter:: version = &
    & '$Name:  $' // &
    & '$Id: cumulus_adjust.F90,v 1.7 2014/05/07 09:39:11 murashin Exp $'
                              ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³
                              ! Module version

  ! INTERFACE æ–‡ ; INTERFACE statements
  !
  interface Cumulus
    module procedure Cumulus
  end interface

contains

  subroutine Cumulus( &
    & xyz_Temp, xyz_QVap, xy_Rain, &  ! (inout)
    & xyz_DTempDt, xyz_DQVapDt, &     ! (inout)
    & xyz_Press, xyr_Press, &         ! (in)
    & xyz_DDelLWDtCCP &               ! (out) optional
    & )
    !
    ! å¯¾æµèª¿ç¯€ã‚¹ã‚ãƒ¼ãƒ ã«ã‚ˆã‚Š, æ¸©åº¦ã¨æ¯”æ¹¿ã‚’èª¿ç¯€ã—ã¾ã™.
    !
    ! Adjust temperature and specific humidity by
    ! convective adjustment scheme.
    !

    ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«å¼•ç”¨ ; USE statements
    !

    ! ç‰©ç†å®šæ•°è¨å®š
    ! Physical constants settings
    !
    use constants, only: &
      & GasRUniv, &
                              ! $ R^{*} $ [J K-1 mol-1].
                              ! æ™®éæ°—ä½“å®šæ•°.  Universal gas constant
      & Grav, &
                              ! $ g $ [m s-2].
                              ! é‡åŠ›åŠ é€Ÿåº¦.
                              ! Gravitational acceleration
      & GasRDry, &
                              ! $ R $ [J kg-1 K-1].
                              ! ä¹¾ç‡¥å¤§æ°—ã®æ°—ä½“å®šæ•°.
                              ! Gas constant of air
      & CpDry, &
                              ! $ C_p $ [J kg-1 K-1].
                              ! ä¹¾ç‡¥å¤§æ°—ã®å®šåœ§æ¯”ç†±.
                              ! Specific heat of air at constant pressure
      & GasRWet, &
                              ! $ R_v $ [J kg-1 K-1].
                              ! å‡çµæˆåˆ†ã®æ°—ä½“å®šæ•°.
                              ! Gas constant of condensible elements
      & LatentHeat, &
                              ! $ L $ [J kg-1] .
                              ! å‡çµã®æ½œç†±.
                              ! Latent heat of condensation
      & EpsV
                              ! $ \epsilon_v $ .
                              ! æ°´è’¸æ°—åˆ†åé‡æ¯”.
                              ! Molecular weight of water vapor

    ! æ™‚åˆ»ç®¡ç†
    ! Time control
    !
    use timeset, only: &
      & DelTime, &            ! $ \Delta t $
      & TimeN, &              ! ã‚¹ãƒ†ãƒƒãƒ— $ t $ ã®æ™‚åˆ». Time of step $ t $.
      & TimesetClockStart, TimesetClockStop

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    use gtool_historyauto, only: HistoryAutoPut

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none

    real(DP), intent(inout):: xyz_Temp (0:imax-1, 1:jmax, 1:kmax)
                              ! $ T $ .     æ¸©åº¦. Temperature
    real(DP), intent(inout):: xyz_QVap (0:imax-1, 1:jmax, 1:kmax)
                              ! $ q $ .     æ¯”æ¹¿. Specific humidity
    real(DP), intent(inout):: xy_Rain (0:imax-1, 1:jmax)
                              ! é™æ°´é‡.
                              ! Precipitation
    real(DP), intent(inout):: xyz_DTempDt (0:imax-1, 1:jmax, 1:kmax)
                              ! æ¸©åº¦å¤‰åŒ–çŽ‡.
                              ! Temperature tendency
    real(DP), intent(inout):: xyz_DQVapDt (0:imax-1, 1:jmax, 1:kmax)
                              ! æ¯”æ¹¿å¤‰åŒ–çŽ‡.
                              ! Specific humidity tendency

    real(DP), intent(in):: xyz_Press (0:imax-1, 1:jmax, 1:kmax)
                              ! $ p $ . æ°—åœ§ (æ•´æ•°ãƒ¬ãƒ™ãƒ«).
                              ! Air pressure (full level)
    real(DP), intent(in):: xyr_Press (0:imax-1, 1:jmax, 0:kmax)
                              ! $ \hat{p} $ . æ°—åœ§ (åŠæ•´æ•°ãƒ¬ãƒ™ãƒ«).
                              ! Air pressure (half level)
    real(DP), intent(out), optional:: xyz_DDelLWDtCCP(0:imax-1, 1:jmax, 1:kmax)
                              ! Production rate of liquid water in the layer
                              ! due to condensation in cumulus convection
                              ! parameterization (kg m-2 s-1)

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    real(DP):: xy_RainCumulus (0:imax-1, 1:jmax)
                              ! é™æ°´é‡.
                              ! Precipitation
    real(DP):: xyz_DTempDtCumulus (0:imax-1, 1:jmax, 1:kmax)
                              ! æ¸©åº¦å¤‰åŒ–çŽ‡.
                              ! Temperature tendency
    real(DP):: xyz_DQVapDtCumulus (0:imax-1, 1:jmax, 1:kmax)
                              ! æ¯”æ¹¿å¤‰åŒ–çŽ‡.
                              ! Specific humidity tendency

    real(DP):: xyz_QVapB (0:imax-1, 1:jmax, 1:kmax)
                              ! èª¿ç¯€å‰ã®æ¯”æ¹¿.
                              ! Specific humidity before adjust.
    real(DP):: xyz_TempB (0:imax-1, 1:jmax, 1:kmax)
                              ! èª¿ç¯€å‰ã®æ¸©åº¦.
                              ! Temperature before adjust.
    logical:: xy_Adjust (0:imax-1, 1:jmax)
                              ! ä»Šå›žèª¿ç¯€ã•ã‚ŒãŸã‹å¦ã‹?.
                              ! Whether it was adjusted this time or not?
    logical:: xy_AdjustB (0:imax-1, 1:jmax)
                              ! å‰å›žèª¿ç¯€ã•ã‚ŒãŸã‹å¦ã‹?.
                              ! Whether it was adjusted last time or not?
    real(DP):: xyz_DPressDz (0:imax-1, 1:jmax, 1:kmax)
                              ! $ \DD{p}{z} $
                              !
    real(DP):: xyz_QVapSat (0:imax-1, 1:jmax, 1:kmax)
                              ! é£½å’Œæ¯”æ¹¿.
                              ! Saturation specific humidity.
    real(DP):: xyz_DDPressDDPress (0:imax-1, 1:jmax, 1:kmax)
                              ! $ \DD{p_{k}}{p_{k-1}} $
                              !
    real(DP):: xyz_DPFact (0:imax-1, 1:jmax, 1:kmax)
                              ! $ (R / C_p)
                              ! \frac{p_{k-1} - p_{k}}{2 p_{k-1/2}} $ .
                              !
                              ! ãƒ•ã‚¡ã‚¯ã‚¿ãƒ¼.
                              ! Factor
    real(DP):: TempSat        ! $ S_t $ .
                              ! é£½å’Œæ¸©åº¦.
                              ! Saturation temperature
    real(DP):: DelTempSat
                              ! èª¿ç¯€ã«ã‚ˆã‚‹é£½å’Œæ¸©åº¦ã®å¤‰åŒ–é‡.
                              ! Saturation temperature variation by adjustment
    real(DP):: DelQVap
                              ! èª¿ç¯€ã«ã‚ˆã‚‹æ¯”æ¹¿ã®å¤‰åŒ–é‡.
                              ! Specific humidity variation by adjustment
    real(DP):: DelTempUpper
                              ! èª¿ç¯€ã«ã‚ˆã‚‹æ¸©åº¦ (k) ã®å¤‰åŒ–é‡.
                              ! Temperature (k) variation by adjustment
    real(DP):: DelTempLower
                              ! èª¿ç¯€ã«ã‚ˆã‚‹æ¸©åº¦ (k-1) ã®å¤‰åŒ–é‡.
                              ! Temperature (k-1) variation by adjustment
    real(DP):: DQVapSatDTempUpper
                              ! $ \DD{q^{*}} (k)}{T} $
    real(DP):: DQVapSatDTempLower
                              ! $ \DD{q^{*}} (k-1)}{T} $
    real(DP):: DHDTempUpper
                              ! $ 1 + \gamma_{k} =
                              ! 1 + \frac{L}{C_p} \DP{q^{*}}{T}_{k} $
    real(DP):: DHDTempLower
                              ! $ 1 + \gamma_{k-1} =
                              ! 1 + \frac{L}{C_p} \DP{q^{*}}{T}_{k-1} $
    logical:: Adjust
                              ! ä»Šå›žå…¨é ˜åŸŸã«ãŠã„ã¦ä¸€åº¦ã§ã‚‚èª¿ç¯€ã•ã‚ŒãŸã‹å¦ã‹?.
                              ! Whether it was adjusted even once in global
                              ! this time or not?

    integer:: i               ! çµŒåº¦æ–¹å‘ã«å›žã‚‹ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop in longitude
    integer:: j               ! ç·¯åº¦æ–¹å‘ã«å›žã‚‹ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop in latitude
    integer:: k               ! é‰›ç›´æ–¹å‘ã«å›žã‚‹ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop in vertical direction
    integer:: itr             ! ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚·ãƒ§ãƒ³æ–¹å‘ã«å›žã‚‹ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop in iteration direction

    real(DP):: xyz_RainCumulus (0:imax-1, 1:jmax, 1:kmax)

    ! é£½å’Œæ¯”æ¹¿è¨ˆç®—ã®ãŸã‚ã®æ–‡é–¢æ•°å®šç¾©
    ! Declaration of statement function for
    !   calculation of saturation specific humidity
    !
#ifdef LIB_SATURATE_NHA1992
#include "../saturate/saturate_nha1992_sf.f90"
    EpsVSF     = EpsV
    GasRUnivSF = GasRUniv
#elif LIB_SATURATE_T1930
#include "../saturate/saturate_t1930_sf.f90"
    EpsVSF    = EpsV
    LatHeatSF = LatentHeat
    GasRWetSF = GasRWet
#else
#include "../saturate/saturate_t1930_sf.f90"
    EpsVSF    = EpsV
    LatHeatSF = LatentHeat
    GasRWetSF = GasRWet
#endif

    ! å®Ÿè¡Œæ–‡ ; Executable statement
    !

    ! è¨ˆç®—æ™‚é–“è¨ˆæ¸¬é–‹å§‹
    ! Start measurement of computation time
    !
    call TimesetClockStart( module_name )

    ! åˆæœŸåŒ–
    ! Initialization
    !
    if ( .not. cumulus_adjust_inited ) call CumAdjInit

    ! èª¿ç¯€å‰ "QVap", "Temp" ã®ä¿å˜
    ! Store "QVap", "Temp" before adjustment
    !
    xyz_QVapB  = xyz_QVap
    xyz_TempB  = xyz_Temp

    ! ãƒ•ã‚¡ã‚¯ã‚¿ãƒ¼ã®è¨ˆç®—
    ! Calculate factor
    !
    do k = 1, kmax
      xyz_DPressDz(:,:,k) = xyr_Press(:,:,k-1) - xyr_Press(:,:,k)
    end do

    ! é£½å’Œæ¯”æ¹¿è¨ˆç®—
    ! Calculate saturation specific humidity
    !

    ! Nakajima et al. (1992) ã‚’ç”¨ã„ãŸé£½å’Œæ¯”æ¹¿ã®è¨ˆç®—
    ! Calculate saturation specific humidity with Nakajima et al. (1992)
    !
    do k = 1, kmax
      do j = 1, jmax
        do i = 0, imax-1
          ! CalcQVapSatSF ã¯æ–‡é–¢æ•°. (å®Ÿè¡Œæ–‡ã®ç›´å‰ã§å®šç¾©)
          ! "CalcQVapSatSF" is statement function and
          !   is declared just before executable statement.
          !
          xyz_QVapSat(i,j,k) = &
            & CalcQVapSatSF( xyz_Temp(i,j,k), xyz_Press(i,j,k) )
        end do
      end do
    end do

    xyz_DDPressDDPress(:,:,1) = 0.
    do k = 2, kmax
      xyz_DDPressDDPress(:,:,k) = xyz_DPressDz(:,:,k) / xyz_DPressDz(:,:,k-1)
      xyz_DPFact(:,:,k) = &
        &   GasRDry / CpDry &
        &   * ( xyz_Press(:,:,k-1) - xyz_Press(:,:,k) ) &
        &   / xyr_Press(:,:,k-1) / 2.0_DP
    end do

    ! èª¿ç¯€
    ! Adjustment
    !
    xy_AdjustB = .true.

    ! ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚·ãƒ§ãƒ³
    ! Iteration
    !
    do itr = 1, ItrtMax
      xy_Adjust = .false.

      do k = 2, kmax
        do j = 1, jmax
          do i = 0, imax-1
            if ( xy_AdjustB(i,j) ) then

              TempSat = &
                &   xyz_Temp(i,j,k-1) - xyz_Temp(i,j,k) &
                & + ( xyz_QVapSat(i,j,k-1) - xyz_QVapSat(i,j,k) ) * LatentHeat / CpDry &
                & - xyz_DPFact(i,j,k) * ( xyz_Temp(i,j,k-1) + xyz_Temp(i,j,k) )

              ! ä¸å®‰å®šã§ã‚ã‚‹ãªã‚‰ã°
              ! If it is unstable
              !
              if ( TempSat > TempSatMax(itr) ) then

                ! .. ã‹ã¤, é£½å’Œã—ã¦ã„ã‚‹ãªã‚‰ã°
                ! .. and, if it is saturated
                !
                if ( ( xyz_QVap(i,j,k) / xyz_QVapSat(i,j,k) >= CrtlRH ) &
                  &  .and. &
                  &  ( xyz_QVap(i,j,k-1) / xyz_QVapSat(i,j,k-1) >= CrtlRH ) &
                  &    ) then

                  DelQVap = &
                    &   xyz_DPressDz(i,j,k-1) &
                    &     * (xyz_QVap(i,j,k-1) - xyz_QVapSat(i,j,k-1) ) &
                    & + xyz_DPressDz(i,j,k) &
                    &     * (xyz_QVap(i,j,k) - xyz_QVapSat(i,j,k) )

                  ! CalcDQVapSatDTempSF ã¯æ–‡é–¢æ•°. (å®Ÿè¡Œæ–‡ã®ç›´å‰ã§å®šç¾©)
                  ! "CalcDQVapSatDTempSF" is statement function and
                  !   is declared just before executable statement.
                  !
                  DQVapSatDTempUpper = &
                    & CalcDQVapSatDTempSF( xyz_Temp(i,j,k), xyz_QVapSat(i,j,k) )

                  DQVapSatDTempLower = &
                    & CalcDQVapSatDTempSF( xyz_Temp(i,j,k-1), xyz_QVapSat(i,j,k-1) )

                  DHDTempUpper = 1.0_DP + LatentHeat/CpDry * DQVapSatDTempUpper
                  DHDTempLower = 1.0_DP + LatentHeat/CpDry * DQVapSatDTempLower

                  DelTempSat = &
                    &   TempSat &
                    & + ( 1.0_DP - xyz_DPFact(i,j,k) / DHDTempLower ) &
                    &     * LatentHeat/CpDry * DelQVap / xyz_DPressDz(i,j,k-1)

                  ! æ¸©åº¦ã®èª¿ç¯€
                  ! Adjust temperature
                  !
                  DelTempUpper = &
                    & DelTempSat &
                    & / ( &
                    &       ( 1.0_DP + xyz_DDPressDDPress(i,j,k) ) &
                    &        * DHDTempUpper &
                    &     + xyz_DPFact(i,j,k) &
                    &        * ( 1.0_DP - xyz_DDPressDDPress(i,j,k)  &
                    &                       * DHDTempUpper / DHDTempLower ) &
                    &   )

                  DelTempLower = &
                    & - DHDTempUpper / DHDTempLower &
                    &    * xyz_DDPressDDPress(i,j,k) * DelTempUpper &
                    & + LatentHeat / CpDry * DelQVap &
                    &    / ( xyz_DPressDz(i,j,k-1) * DHDTempLower )

                  xyz_Temp(i,j,k)   = xyz_Temp(i,j,k) + DelTempUpper
                  xyz_Temp(i,j,k-1) = xyz_Temp(i,j,k-1) + DelTempLower

                  ! æ¯”æ¹¿ã®èª¿ç¯€
                  ! Adjust specific humidity
                  !
                  xyz_QVap(i,j,k) = &
                    &   xyz_QVapSat(i,j,k) &
                    & + DQVapSatDTempUpper * DelTempUpper

                  xyz_QVap(i,j,k-1) = &
                    &   xyz_QVapSat(i,j,k-1) &
                    & + DQVapSatDTempLower * DelTempLower

                  xyz_QVapSat(i,j,k)   = xyz_QVap(i,j,k)
                  xyz_QVapSat(i,j,k-1) = xyz_QVap(i,j,k-1)

                  ! èª¿ç¯€ã—ãŸã‹å¦ã‹?
                  ! Whether it was adjusted or not?
                  !
                  xy_Adjust(i,j) = .true.
                end if

              end if

            end if
          end do
        end do
      end do

      Adjust = .false.
      do i = 0, imax-1
        do j = 1, jmax
          xy_AdjustB(i,j) = xy_Adjust(i,j)
          Adjust          = Adjust .or. xy_Adjust(i,j)
        end do
      end do

      if ( .not. Adjust ) exit

    end do

    ! æ¯”æ¹¿å¤‰åŒ–çŽ‡, æ¸©åº¦å¤‰åŒ–çŽ‡, é™æ°´é‡ã®ç®—å‡º
    ! Calculate specific humidity tendency, temperature tendency, precipitation
    !
    xy_RainCumulus     = 0.
    xyz_DTempDtCumulus = 0.
    xyz_DQVapDtCumulus = 0.

    xyz_DQVapDtCumulus = xyz_DQVapDtCumulus &
      & + ( xyz_QVap - xyz_QVapB ) / ( 2.0_DP * DelTime )

    xyz_DTempDtCumulus = xyz_DTempDtCumulus &
      & + ( xyz_Temp - xyz_TempB ) / ( 2.0_DP * DelTime )

    do k = 1, kmax
      xy_RainCumulus = xy_RainCumulus &
        & + ( xyz_QVapB(:,:,k) - xyz_QVap(:,:,k) ) &
        &       * xyz_DPressDz(:,:,k) / Grav / ( 2.0_DP * DelTime )
    end do

    xy_Rain     = xy_Rain     + xy_RainCumulus
    xyz_DTempDt = xyz_DTempDt + xyz_DTempDtCumulus
    xyz_DQVapDt = xyz_DQVapDt + xyz_DQVapDtCumulus

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    call HistoryAutoPut( TimeN, 'RainCumulus',    xy_RainCumulus * LatentHeat )
    call HistoryAutoPut( TimeN, 'DTempDtCumulus', xyz_DTempDtCumulus )
    call HistoryAutoPut( TimeN, 'DQVapDtCumulus', xyz_DQVapDtCumulus )

    if ( present( xyz_DDelLWDtCCP ) ) then
      xyz_DDelLWDtCCP = &
        & + ( xyz_QVapB - xyz_QVap ) &
        &       * xyz_DPressDz / Grav / ( 2.0_DP * DelTime )
    end if

    ! è¨ˆç®—æ™‚é–“è¨ˆæ¸¬ä¸€æ™‚åœæ¢
    ! Pause measurement of computation time
    !
    call TimesetClockStop( module_name )

  end subroutine Cumulus

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

  subroutine CumAdjInit
    !
    ! cumulus_adjust ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åˆæœŸåŒ–ã‚’è¡Œã„ã¾ã™.
    ! NAMELIST#cumulus_adjust_nml ã®èªã¿è¾¼ã¿ã¯ã“ã®æ‰‹ç¶šãã§è¡Œã‚ã‚Œã¾ã™.
    !
    ! "cumulus_adjust" module is initialized.
    ! "NAMELIST#cumulus_adjust_nml" is loaded in this procedure.
    !

    ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«å¼•ç”¨ ; USE statements
    !

    ! NAMELIST ãƒ•ã‚¡ã‚¤ãƒ«å…¥åŠ›ã«é–¢ã™ã‚‹ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£
    ! Utilities for NAMELIST file input
    !
    use namelist_util, only: namelist_filename, NmlutilMsg, NmlutilAryValid

    ! ãƒ•ã‚¡ã‚¤ãƒ«å…¥å‡ºåŠ›è£œåŠ©
    ! File I/O support
    !
    use dc_iounit, only: FileOpen

    ! ç¨®åˆ¥åž‹ãƒ‘ãƒ©ãƒ¡ã‚¿
    ! Kind type parameter
    !
    use dc_types, only: STDOUT ! æ¨™æº–å‡ºåŠ›ã®è£…ç½®ç•ªå·. Unit number of standard output

    ! æ–‡å—åˆ—æ“ä½œ
    ! Character handling
    !
    use dc_string, only: StoA

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›
    ! History data output
    !
    use gtool_historyauto, only: HistoryAutoAddVariable

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none

    integer:: unit_nml        ! NAMELIST ãƒ•ã‚¡ã‚¤ãƒ«ã‚ªãƒ¼ãƒ—ãƒ³ç”¨è£…ç½®ç•ªå·.
                              ! Unit number for NAMELIST file open
    integer:: iostat_nml      ! NAMELIST èªã¿è¾¼ã¿æ™‚ã® IOSTAT.
                              ! IOSTAT of NAMELIST read

    ! NAMELIST å¤‰æ•°ç¾¤
    ! NAMELIST group name
    !
    namelist /cumulus_adjust_nml/ &
      & CrtlRH, ItrtMax, TempSatMax
          !
          ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã«ã¤ã„ã¦ã¯åˆæœŸåŒ–æ‰‹ç¶š "cumulus_adjust#CumAdjInit"
          ! ã®ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã‚’å‚ç…§ã®ã“ã¨.
          !
          ! Refer to source codes in the initialization procedure
          ! "cumulus_adjust#CumAdjInit" for the default values.
          !

    ! å®Ÿè¡Œæ–‡ ; Executable statement
    !

    if ( cumulus_adjust_inited ) return
    call InitCheck

    ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã®è¨å®š
    ! Default values settings
    !
    CrtlRH  = 0.990_DP
    ItrtMax = 10
    TempSatMax(1:ItrtMax) = &
      & (/ 0.01_DP, 0.02_DP, 0.02_DP, 0.05_DP, 0.05_DP, &
      &    0.10_DP, 0.10_DP, 0.20_DP, 0.20_DP, 0.40_DP  /)

    ! 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 = cumulus_adjust_nml, &  ! (out)
        & iostat = iostat_nml )        ! (out)
      close( unit_nml )

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

    ! ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚·ãƒ§ãƒ³å›žæ•°, ä¸å®‰å®šã®è¨±å®¹èª¤å·®ã®ãƒã‚§ãƒƒã‚¯
    ! Check number of iteration, admissible error of unstability
    !
    call NmlutilAryValid( module_name, & ! (in)
      & TempSatMax, 'TempSatMax', &      ! (in)
      & ItrtMax,    'ItrtMax' )          ! (in)

    ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿å‡ºåŠ›ã®ãŸã‚ã®ã¸ã®å¤‰æ•°ç™»éŒ²
    ! Register of variables for history data output
    !
    call HistoryAutoAddVariable( 'RainCumulus', &
      & (/ 'lon ', 'lat ', 'time' /), &
      & 'precipitation by cumulus scheme', 'W m-2' )
    call HistoryAutoAddVariable( 'DTempDtCumulus', &
      & (/ 'lon ', 'lat ', 'sig ', 'time' /), &
      & 'cumulus condensation heating', 'K s-1' )
    call HistoryAutoAddVariable( 'DQVapDtCumulus', &
      & (/ 'lon ', 'lat ', 'sig ', 'time' /), &
      & 'cumulus condensation moistening', 'kg kg-1 s-1' )

    ! å°å— ; Print
    !
    call MessageNotify( 'M', module_name, '----- Initialization Messages -----' )
    call MessageNotify( 'M', module_name, '  CrtlRH  = %f', d = (/ CrtlRH /) )
    call MessageNotify( 'M', module_name, '  ItrtMax = %d', i = (/ ItrtMax /) )
    call MessageNotify( 'M', module_name, '  TempSatMax = (/ %*r /)', &
      & r = real( TempSatMax(1:ItrtMax) ), n = (/ ItrtMax /) )
    call MessageNotify( 'M', module_name, '' )
    call MessageNotify( 'M', module_name, '  Scheme of saturation = %c', &
      & c1 = saturate_scheme )

    call MessageNotify( 'M', module_name, '-- version = %c', c1 = trim(version) )

    cumulus_adjust_inited = .true.
  end subroutine CumAdjInit

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

  subroutine InitCheck
    !
    ! ä¾å˜ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®åˆæœŸåŒ–ãƒã‚§ãƒƒã‚¯
    !
    ! Check initialization of dependency modules

    ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«å¼•ç”¨ ; USE statements
    !

    ! NAMELIST ãƒ•ã‚¡ã‚¤ãƒ«å…¥åŠ›ã«é–¢ã™ã‚‹ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£
    ! Utilities for NAMELIST file input
    !
    use namelist_util, only: namelist_util_inited

    ! æ ¼åç‚¹è¨å®š
    ! Grid points settings
    !
    use gridset, only: gridset_inited

    ! ç‰©ç†å®šæ•°è¨å®š
    ! Physical constants settings
    !
    use constants, only: constants_inited

    ! åº§æ¨™ãƒ‡ãƒ¼ã‚¿è¨å®š
    ! Axes data settings
    !
    use axesset, only: axesset_inited

    ! æ™‚åˆ»ç®¡ç†
    ! Time control
    !
    use timeset, only: timeset_inited

    ! å®Ÿè¡Œæ–‡ ; Executable statement
    !

    if ( .not. namelist_util_inited ) &
      & call MessageNotify( 'E', module_name, '"namelist_util" module is not initialized.' )

    if ( .not. gridset_inited ) &
      & call MessageNotify( 'E', module_name, '"gridset" module is not initialized.' )

    if ( .not. constants_inited ) &
      & call MessageNotify( 'E', module_name, '"constants" module is not initialized.' )

    if ( .not. axesset_inited ) &
      & call MessageNotify( 'E', module_name, '"axesset" module is not initialized.' )

    if ( .not. timeset_inited ) &
      & call MessageNotify( 'E', module_name, '"timeset" module is not initialized.' )

  end subroutine InitCheck

end module cumulus_adjust