!= åº§æ¨™ãƒ‡ãƒ¼ã‚¿è¨å®š
!
!= Axes data settings
!
! Authors::   Yoshiyuki O. Takahashi, Yasuhiro MORIKAWA
! Version::   $Id: axesset.F90,v 1.20 2014/05/07 09:39:21 murashin Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2008. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!

module axesset
  !
  != åº§æ¨™ãƒ‡ãƒ¼ã‚¿è¨å®š
  !
  != Axes data settings
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !
  ! åº§æ¨™ãƒ‡ãƒ¼ã‚¿ã®è¨å®šãŠã‚ˆã³ä¿ç®¡ã‚’è¡Œã„ã¾ã™.
  !
  ! ç·¯åº¦ $ \varphi $ ãŠã‚ˆã³çµŒåº¦ $ \lambda $ ã®æ ¼åç‚¹ã¯,
  ! gridset ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã§è¨å®šã•ã‚Œã‚‹æ ¼åç‚¹æ•°ã‹ã‚‰,
  ! {SPMODEL ãƒ©ã‚¤ãƒ–ãƒ©ãƒª}[http://www.gfd-dennou.org/library/spmodel]
  ! ã‚’ç”¨ã„ã¦æ±ºå®šã•ã‚Œã¾ã™.
  ! ç·¯åº¦ã®æ ¼åç‚¹ã®ä½ç½®ã¯ã‚¬ã‚¦ã‚¹ç·¯åº¦,
  ! çµŒåº¦ã®æ ¼åç‚¹ã®ä½ç½®ã¯ç‰é–“éš”ã«ã¨ã‚‹ã“ã¨ã«ãªã‚Šã¾ã™.
  !
  ! é‰›ç›´Ïƒã®æ ¼åç‚¹ã¯, åŠæ•´æ•°ãƒ¬ãƒ™ãƒ« (å„å±¤ã®ç«¯) ã«ã¤ã„ã¦
  ! NAMELIST#Sigma ã«æŒ‡å®šã—ã¾ã™.
  ! æ•´æ•°ãƒ¬ãƒ™ãƒ« (å„å±¤ã®ä¸å¿ƒç‚¹) ã¯, åŠæ•´æ•°ãƒ¬ãƒ™ãƒ«ã¨ constants
  ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã§è¨å®šã•ã‚Œã‚‹ä¹¾ç‡¥å¤§æ°—ã®å®šåœ§æ¯”ç†± $ C_p $ ãŠã‚ˆã³
  ! ä¹¾ç‡¥å¤§æ°—ã®æ°—ä½“å®šæ•° $ R $ ã‚’ç”¨ã„ã¦æ±ºå®šã—ã¾ã™.
  ! é‰›ç›´Ïƒã®æ ¼åç‚¹ã«ã¤ã„ã¦ã¯, sigma_data ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã§ç”¨æ„ã•ã‚Œã¦ã„ã‚‹
  ! ã‚‚ã®ã‚’ä½¿ç”¨ã™ã‚‹ã“ã¨ã‚‚å¯èƒ½ã§ã™.
  !
  ! Axes data is set and stored.
  !
  ! Grid points of latitude $ \varphi $ and longitude $ \lambda $ are
  ! determined
  ! with number of grid points configured in "gridset" module
  ! by {SPMODEL Library}[http://www.gfd-dennou.org/library/spmodel/index.htm.en]
  ! Grid points of latitude becomes Gaussian latitude,
  ! and grid points of latitude becomes equally spaced.
  !
  !== Variables List
  !
  ! x_Lon               :: çµŒåº¦åº§æ¨™
  ! x_Lon_Weight        :: çµŒåº¦åº§æ¨™é‡ã¿
  ! DeltaLon            :: çµŒåº¦æ ¼åç‚¹é–“éš”
  ! InvDeltaLon         :: çµŒåº¦æ ¼åç‚¹é–“éš”ã®é€†æ•°
  ! y_Lat               :: ç·¯åº¦åº§æ¨™
  ! y_Lat_Weight        :: ç·¯åº¦åº§æ¨™é‡ã¿
  ! z_Sigma             :: $ \sigma $ ãƒ¬ãƒ™ãƒ« (æ•´æ•°)
  ! r_Sigma             :: $ \sigma $ ãƒ¬ãƒ™ãƒ« (åŠæ•´æ•°)
  ! z_DelSigma          :: $ \Delta \sigma $ (æ•´æ•°)
  ! r_DelSigma          :: $ \Delta \sigma $ (åŠæ•´æ•°)
  ! w_Number            :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®æ·»å—ç•ªå·
  ! spml_inited         :: SPML ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã®åˆæœŸè¨å®šãƒ•ãƒ©ã‚°
  ! ------------        :: ------------
  ! x_Lon               :: Longitude
  ! x_Lon_Weight        :: Weight of longitude
  ! DeltaLon            :: Interval of longitude grids
  ! InvDeltaLon         :: Inverse of DeltaLon
  ! y_Lat               :: Latitude
  ! y_Lat_Weight        :: Weight of latitude
  ! z_Sigma             :: Full $ \sigma $ level
  ! r_Sigma             :: Half $ \sigma $ level
  ! z_DelSigma          :: $ \Delta \sigma $ (Full)
  ! r_DelSigma          :: $ \Delta \sigma $ (Half)
  ! w_Number            :: Subscript of spectral data
  ! spml_inited         :: Initialization flag of SPML library
  !
  !== Procedures List
  !
  ! AxessetInit     :: åº§æ¨™ãƒ‡ãƒ¼ã‚¿ã®è¨å®š
  ! AxessetFinalize :: çµ‚äº†å‡¦ç† (ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«å†…éƒ¨ã®å¤‰æ•°ã®å‰²ã‚Šä»˜ã‘è§£é™¤)
  ! ------------    :: ------------
  ! AxessetInit     :: Settings of axes data
  ! AxessetFinalize :: Termination (deallocate variables in this module)
  !

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

  ! æ ¼åç‚¹è¨å®š
  ! Grid points settings
  !
  use gridset, only: &
    &                nmax       , & ! æœ€å¤§å…¨æ³¢æ•°.
                                    ! Maximum truncated wavenumber
    &                imax       , & ! çµŒåº¦æ ¼åç‚¹æ•°.
                                    ! Number of grid points in longitude
    &                jmax_global, & ! ç·¯åº¦æ ¼åç‚¹æ•° (å…¨çƒ).
                                    ! Number of grid points in latitude on whole globe
    &                jmax       , & ! ç·¯åº¦æ ¼åç‚¹æ•°.
                                    ! Number of grid points in latitude
    &                kmax       , & ! é‰›ç›´å±¤æ•°.
                                    ! Number of vertical level
    &                kslmax         ! åœ°ä¸‹ã®é‰›ç›´å±¤æ•°.
                                    ! Number of subsurface 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

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

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

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

  real(DP), allocatable, save, public:: x_Lon (:)
                              ! $ \lambda $ [rad.] . çµŒåº¦. Longitude
  real(DP), allocatable, save, public:: x_Lon_Weight (:)
                              ! $ \Delta \lambda $ [rad.] .
                              ! çµŒåº¦åº§æ¨™é‡ã¿.
                              ! Weight of longitude
  real(DP), allocatable, save, public:: y_Lat (:)
                              ! $ \varphi $ [rad.] . ç·¯åº¦. Latitude
  real(DP), allocatable, save, public:: y_Lat_Weight (:)
                              ! $ \Delta \varphi $ [rad.] .
                              ! ç·¯åº¦åº§æ¨™é‡ã¿.
                              ! Weight of latitude
  real(DP), allocatable, save, public:: z_Sigma (:)
                              ! $ \sigma $ ãƒ¬ãƒ™ãƒ« (æ•´æ•°).
                              ! Full $ \sigma $ level
  real(DP), allocatable, save, public:: r_Sigma (:)
                              ! $ \sigma $ ãƒ¬ãƒ™ãƒ« (åŠæ•´æ•°).
                              ! Half $ \sigma $ level
  real(DP), allocatable, save, public:: z_DelSigma (:)
                              ! $ \Delta \sigma $ (æ•´æ•°).
                              ! $ \Delta \sigma $ (Full)
  real(DP), allocatable, save, public:: r_DelSigma (:)
                              ! $ \Delta \sigma $ (åŠæ•´æ•°).
                              ! $ \Delta \sigma $ (half)
  integer, allocatable, save, public:: w_Number (:)
                              ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®æ·»å—ç•ªå·.
                              ! Subscript of spectral data
  real(DP), allocatable, save, public:: z_SSDepth(:)
                              ! åœ°ä¸‹ã®æ ¼åç‚¹ã®æ·±ã•
                              ! subsurface grid at midpoint of layer
  real(DP), allocatable, save, public:: r_SSDepth(:)
                              ! åœ°ä¸‹ã®å±¤ã®å¢ƒç•Œé¢ã®æ·±ã•
                              ! subsurface grid on interface of layer
  real(DP), save, public:: DeltaLon
                              ! çµŒåº¦æ ¼åç‚¹é–“éš”.
                              ! grid interval in longitude
  real(DP), save, public:: InvDeltaLon
                              ! çµŒåº¦æ ¼åç‚¹é–“éš”ã®é€†æ•°.
                              ! Inverse of the grid interval in longitude

  logical, save, public:: spml_inited = .false.
                              ! SPML ãƒ©ã‚¤ãƒ–ãƒ©ãƒªã®åˆæœŸè¨å®šãƒ•ãƒ©ã‚°.
                              ! Initialization flag of SPML library

  character(STRING), parameter, public :: AxnameX   = 'lon'
                              ! axis name for x
  character(STRING), parameter, public :: AxnameY   = 'lat'
                              ! axis name for y
  character(STRING), parameter, public :: AxnameZ   = 'sig'
                              ! axis name for z
  character(STRING), parameter, public :: AxnameR   = 'sigm'
                              ! axis name for r
  character(STRING), parameter, public :: AxnameSSZ = 'ssz'
                              ! axis name for z (subsurface)
  character(STRING), parameter, public :: AxnameSSR = 'sszi'
                              ! axis name for r (subsurface)
  character(STRING), parameter, public :: AxnameWN  = 'wn'
                              ! axis name for wavenumber
  character(STRING), parameter, public :: AxnameT   = 'time'
                              ! axis name for t

  ! éžå…¬é–‹å¤‰æ•°
  ! Private variables
  !
  real(DP), save:: Sigma (1:MaxNmlArySize)
                              ! $ \sigma $ ãƒ¬ãƒ™ãƒ« (åŠæ•´æ•°).
                              ! Half $ \sigma $ level
  real(DP), save:: Depth(1:MaxNmlArySize)
                              ! å…¥åŠ›ç”¨é…åˆ—, åœ°ä¸‹ã®é‰›ç›´å±¤å¢ƒç•Œ
                              ! array for input, layer interface of subsurface
                              ! vertical layer

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

contains

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

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

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

    ! ç‰©ç†ãƒ»æ•°å¦å®šæ•°è¨å®š
    ! Physical and mathematical constants settings
    !
    use constants0, only: PI      ! $ \pi $ .
                                  ! å††å‘¨çŽ‡.  Circular constant

    ! ç‰©ç†å®šæ•°è¨å®š
    ! Physical constants settings
    !
    use constants, only: &
      &                  CpDry, & ! $ C_p $ [J kg-1 K-1].
                                  ! ä¹¾ç‡¥å¤§æ°—ã®å®šåœ§æ¯”ç†±.
                                  ! Specific heat of air at constant pressure
      &                  GasRDry  ! $ R $ [J kg-1 K-1].
                                  ! ä¹¾ç‡¥å¤§æ°—ã®æ°—ä½“å®šæ•°.
                                  ! Gas constant of air

    ! æ ¼åç‚¹æ•°ãƒ»æœ€å¤§æ³¢æ•°è¨å®š
    ! Number of grid points and maximum truncated wavenumber settings
    !
    use gridset, only: GridsetCheckNumberOfLatGrid

    ! SPMODEL ãƒ©ã‚¤ãƒ–ãƒ©ãƒª, çƒé¢ä¸Šã®å•é¡Œã‚’çƒé¢èª¿å’Œå‡½æ•°å¤‰æ›ã«ã‚ˆã‚Šè§£ã(å¤šå±¤å¯¾å¿œ)
    ! SPMODEL library, problems on sphere are solved with spherical harmonics
    ! (multi layer is supported)
    !
#ifdef LIB_MPI
#ifdef SJPACK
    use wa_mpi_module_sjpack, only: wa_mpi_Initial, &
      & spml_x_Lon        => x_Lon, &
                              ! $ \lambda $ [rad.] . çµŒåº¦. Longitude
      & spml_x_Lon_Weight => x_Lon_Weight, &
                              ! $ \Delta \lambda $ [rad.] .
                              ! çµŒåº¦åº§æ¨™é‡ã¿.
                              ! Weight of longitude
      & spml_y_Lat        => v_Lat, &
                              ! $ \varphi $ [rad.] . ç·¯åº¦. Latitude
      & spml_y_Lat_Weight => v_Lat_Weight, &
                              ! $ \Delta \varphi $ [rad.] .
                              ! ç·¯åº¦åº§æ¨™é‡ã¿.
                              ! Weight of latitude
      & spml_jc => jc
#else
    use wa_mpi_module, only: wa_mpi_Initial, &
      & spml_x_Lon        => x_Lon, &
                              ! $ \lambda $ [rad.] . çµŒåº¦. Longitude
      & spml_x_Lon_Weight => x_Lon_Weight, &
                              ! $ \Delta \lambda $ [rad.] .
                              ! çµŒåº¦åº§æ¨™é‡ã¿.
                              ! Weight of longitude
      & spml_y_Lat        => v_Lat, &
                              ! $ \varphi $ [rad.] . ç·¯åº¦. Latitude
      & spml_y_Lat_Weight => v_Lat_Weight, &
                              ! $ \Delta \varphi $ [rad.] .
                              ! ç·¯åº¦åº§æ¨™é‡ã¿.
                              ! Weight of latitude
      & spml_jc => jc
#endif
#elif AXISYMMETRY
    use wa_zonal_module, only: wa_Initial, &
      & spml_x_Lon        => x_Lon, &
                              ! $ \lambda $ [rad.] . çµŒåº¦. Longitude
      & spml_x_Lon_Weight => x_Lon_Weight, &
                              ! $ \Delta \lambda $ [rad.] .
                              ! çµŒåº¦åº§æ¨™é‡ã¿.
                              ! Weight of longitude
      & spml_y_Lat        => y_Lat, &
                              ! $ \varphi $ [rad.] . ç·¯åº¦. Latitude
      & spml_y_Lat_Weight => y_Lat_Weight
                              ! $ \Delta \varphi $ [rad.] .
                              ! ç·¯åº¦åº§æ¨™é‡ã¿.
                              ! Weight of latitude
#elif SJPACK
    use wa_module_sjpack, only: wa_Initial, &
      & spml_x_Lon        => x_Lon, &
                              ! $ \lambda $ [rad.] . çµŒåº¦. Longitude
      & spml_x_Lon_Weight => x_Lon_Weight, &
                              ! $ \Delta \lambda $ [rad.] .
                              ! çµŒåº¦åº§æ¨™é‡ã¿.
                              ! Weight of longitude
      & spml_y_Lat        => y_Lat, &
                              ! $ \varphi $ [rad.] . ç·¯åº¦. Latitude
      & spml_y_Lat_Weight => y_Lat_Weight
                              ! $ \Delta \varphi $ [rad.] .
                              ! ç·¯åº¦åº§æ¨™é‡ã¿.
                              ! Weight of latitude
#elif AXISYMMETRY_SJPACK
    use wa_zonal_module_sjpack, only: wa_Initial, &
      & spml_x_Lon        => x_Lon, &
                              ! $ \lambda $ [rad.] . çµŒåº¦. Longitude
      & spml_x_Lon_Weight => x_Lon_Weight, &
                              ! $ \Delta \lambda $ [rad.] .
                              ! çµŒåº¦åº§æ¨™é‡ã¿.
                              ! Weight of longitude
      & spml_y_Lat        => y_Lat, &
                              ! $ \varphi $ [rad.] . ç·¯åº¦. Latitude
      & spml_y_Lat_Weight => y_Lat_Weight
                              ! $ \Delta \varphi $ [rad.] .
                              ! ç·¯åº¦åº§æ¨™é‡ã¿.
                              ! Weight of latitude
#else
    use wa_module, only: wa_Initial, &
      & spml_x_Lon        => x_Lon, &
                              ! $ \lambda $ [rad.] . çµŒåº¦. Longitude
      & spml_x_Lon_Weight => x_Lon_Weight, &
                              ! $ \Delta \lambda $ [rad.] .
                              ! çµŒåº¦åº§æ¨™é‡ã¿.
                              ! Weight of longitude
      & spml_y_Lat        => y_Lat, &
                              ! $ \varphi $ [rad.] . ç·¯åº¦. Latitude
      & spml_y_Lat_Weight => y_Lat_Weight
                              ! $ \Delta \varphi $ [rad.] .
                              ! ç·¯åº¦åº§æ¨™é‡ã¿.
                              ! Weight of latitude
#endif

    ! é‰›ç›´Ïƒãƒ¬ãƒ™ãƒ«ãƒ‡ãƒ¼ã‚¿æº–å‚™
    ! Prepare vertical sigma level data
    !
    use sigma_data, only: SigmaDataGetHalf

    ! 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
      &                 TOKEN      ! ã‚ãƒ¼ãƒ¯ãƒ¼ãƒ‰.   Keywords.

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

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

    ! OpenMP
    !
    !$ use omp_lib

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

    ! ä½œæ¥å¤‰æ•°
    ! Work variables
    !
    logical:: flag_generate_sigma
                              ! é‰›ç›´å±¤æ•°ã®å†…éƒ¨ç”Ÿæˆã®ãŸã‚ã®ãƒ•ãƒ©ã‚°
                              ! Flag for generation of sigma levels internally
    integer:: i               ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ã®æ·»å—ç•ªå·ã§å›žã‚‹ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop in subscript of spectral data
    integer:: k               ! é‰›ç›´æ–¹å‘ã«å›žã‚‹ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop in vertical direction
    real(DP):: Kappa          ! $ \kappa = R / C_p $ .
                              ! ä¹¾ç‡¥å¤§æ°—ã«ãŠã‘ã‚‹, æ°—ä½“å®šæ•°ã®å®šåœ§æ¯”ç†±ã«å¯¾ã™ã‚‹æ¯”.
                              ! Ratio of gas constant to specific heat in dry air

    real(DP):: LonInDeg       ! Longitude in unit of degree of a grid point in 1D mode
    real(DP):: LatInDeg       ! Latitude in unit of degree of a grid point in 1D mode

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

    integer:: OMPNumThreads
                              ! OpenMP ã§ã®æœ€å¤§ã‚¹ãƒ¬ãƒƒãƒ‰æ•°.
                              ! openmp_threads ã« 1 ã‚ˆã‚Šå¤§ããªå€¤ã‚’æŒ‡å®šã™ã‚Œã°
                              ! ISPACK[http://www.gfd-dennou.org/library/ispack/]
                              ! ã®çƒé¢èª¿å’Œå‡½æ•°å¤‰æ› OpenMP ä¸¦åˆ—è¨ˆç®—
                              ! ãƒ«ãƒ¼ãƒãƒ³ãŒç”¨ã„ã‚‰ã‚Œã‚‹. ä¸¦åˆ—è¨ˆç®—ã‚’å®Ÿè¡Œã™ã‚‹ã«ã¯,
                              ! å®Ÿè¡Œæ™‚ã«ç’°å¢ƒå¤‰æ•° OMP_NUM_THREADS
                              ! ã‚’ OMPNumThreads ä»¥ä¸‹ã®æ•°å—ã«è¨å®šã™ã‚‹
                              ! ç‰ã®ã‚·ã‚¹ãƒ†ãƒ ã«å¿œã˜ãŸæº–å‚™ãŒå¿…è¦ã¨ãªã‚‹.
                              !
                              ! OMPNumThreads ã« 1 ã‚ˆã‚Šå¤§ããªå€¤ã‚’
                              ! æŒ‡å®šã—ãªã‘ã‚Œã°ä¸¦åˆ—è¨ˆç®—ãƒ«ãƒ¼ãƒãƒ³ã¯å‘¼ã°ã‚Œãªã„.

    character(TOKEN):: rank_str
                              ! ãƒ©ãƒ³ã‚¯æ•°. Rank number
    integer:: myrank_mpi      ! ç·ãƒ—ãƒã‚»ã‚¹æ•°. Number of total processes
    integer:: nprocs_mpi      ! è‡ªèº«ã®ãƒ—ãƒã‚»ã‚¹. Number of my process
    integer:: ra              ! MPI ã®ãƒ©ãƒ³ã‚¯æ•°æ–¹å‘ã«å›žã‚‹ DO ãƒ«ãƒ¼ãƒ—ç”¨ä½œæ¥å¤‰æ•°
                              ! Work variables for DO loop in rank number of MPI direction

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

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

    if ( axesset_inited ) return

    !
    ! Set number of OpenMP threads
    !
    OMPNumThreads = 1
    !$ OMPNumThreads = omp_get_max_threads()

    ! å‰²ã‚Šä»˜ã‘
    ! Allocation
    !
    allocate( z_Sigma      (1:kmax)   )
    allocate( r_Sigma      (0:kmax)   )
    allocate( z_DelSigma   (1:kmax)   )
    allocate( r_DelSigma   (0:kmax)   )
    allocate( w_Number     (1:(nmax+1)**2) )

    allocate( r_SSDepth( 0:kslmax ) )
    allocate( z_SSDepth( 1:kslmax ) )

    ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã®è¨å®š
    ! Default values settings
    !

    ! Sigma (åŠæ•´æ•°ãƒ¬ãƒ™ãƒ«Ïƒ) ã®åˆæœŸå€¤ (ç„¡åŠ¹ãªå€¤) ã®è¨å®š
    ! Setting of initial value (invalid value) of "Sigma" (half level sigma)
    !
    Sigma = -999.0d0

    ! åœ°ä¸‹ã®å±¤ã®å¢ƒç•Œé¢æ·±ã•ã®åˆæœŸå€¤ (ç„¡åŠ¹ãªå€¤) ã®è¨å®š
    ! Setting of initial value (invalid value) of depth of subsurface layer interface
    !
    Depth = -999.0d0

    ! é‰›ç›´å±¤æ•°ã®å†…éƒ¨ç”Ÿæˆã®ãŸã‚ã®ãƒ•ãƒ©ã‚°ã®è¨å®š
    ! Setting of flag for generation of sigma levels internally
    !
    flag_generate_sigma = .false.

    ! Longitude in unit of degree of a grid point in 1D mode
    !
    LonInDeg = 0.0_DP

    ! Latitude in unit of degree of a grid point in 1D mode
    !
    LatInDeg  = 0.0_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 = axesset_nml, &  ! (out)
        & iostat = iostat_nml ) ! (out)
      close( unit_nml )

      call NmlutilMsg( iostat_nml, module_name ) ! (in)
    end if

    ! Sigma (åŠæ•´æ•°ãƒ¬ãƒ™ãƒ«Ïƒ) ã®è‡ªå‹•è¨å®š
    ! Automation setting of "Sigma" (half level sigma)
    !
    if ( all( Sigma == -999.0d0 ) ) then
      if ( flag_generate_sigma ) then
        call SigmaDataGetHalf( Sigma(1:kmax+1) ) ! (out)
      else
        call MessageNotify( 'E', module_name, &
          & '  Sigma levels have to be specified if flag_generate_sigma is not true.' )
      end if
    end if

    ! Sigma (åŠæ•´æ•°ãƒ¬ãƒ™ãƒ«Ïƒ) ãƒã‚§ãƒƒã‚¯
    ! Check "Sigma" (half level sigma)
    !
    if ( Sigma(1) /= 1.0_DP ) then
      call MessageNotify( 'E', module_name, '  Sigma(1) is not 1, but is %f', &
        & d = (/ Sigma(1) /) )
    end if
    if ( Sigma(kmax+1) /= 0.0_DP ) then
      call MessageNotify( 'E', module_name, '  Sigma(kmax+1) is not 0, but is %f', &
        & d = (/ Sigma(kmax+1) /) )
    end if
    do k = 1, kmax
      if ( Sigma(k+1) > Sigma(k) ) then
        call MessageNotify( 'M', module_name, '  Sigma(%d) = %f > Sigma(%d) = %f', &
            & i = (/ k+1, k /), d = (/ Sigma(k+1), Sigma(k) /) )
        call MessageNotify( 'E', module_name, '  Value of Sigma has to decrease with index.' )
      end if
    end do

    ! r_Sigma (åŠæ•´æ•°ãƒ¬ãƒ™ãƒ«Ïƒ) è¨å®š
    ! Setting of "r_Sigma" (half level sigma)
    !
    r_Sigma(0:kmax) = Sigma(1:kmax+1)

    ! z_DelSigma (æ•´æ•°ãƒ¬ãƒ™ãƒ« $ \Delta \sigma $ ) è¨å®š
    ! Setting of "z_DelSigma" (full level $ \Delta \sigma $ )
    !
    do k = 1, kmax
      z_DelSigma(k) = r_Sigma(k-1) - r_Sigma(k)
    enddo

    ! z_Sigma (æ•´æ•°ãƒ¬ãƒ™ãƒ«Ïƒ) è¨å®š
    ! Setting of "z_Sigma" (full level sigma)
    !
    Kappa = GasRDry / CpDry
    do k = 1, kmax
      z_Sigma(k) = &
        & ( &
        &   (   r_Sigma(k-1) ** ( 1.0_DP + Kappa ) &
        &     - r_Sigma(k)   ** ( 1.0_DP + Kappa ) &
        &   ) / ( z_DelSigma(k) * ( 1.0_DP + Kappa ) ) &
        & ) ** ( 1.0_DP / Kappa )
    enddo

    ! r_DelSigma (åŠæ•´æ•°ãƒ¬ãƒ™ãƒ« $ \Delta \sigma $ ) è¨å®š
    ! Setting of "r_DelSigma" (half level $ \Delta \sigma $ )
    !
    r_DelSigma(0)    = r_Sigma(0)    - z_Sigma(1)
    r_DelSigma(kmax) = z_Sigma(kmax) - r_Sigma(kmax)
    do k = 1, kmax - 1
      r_DelSigma(k) = z_Sigma(k) - z_Sigma(k+1)
    end do

    ! åœ°ä¸‹ã®å±¤ã®å¢ƒç•Œé¢æ·±ã•ã®ãƒã‚§ãƒƒã‚¯
    ! Check depth of subsurface layer interface
    !
    if ( all( Depth == -999.0d0 ) ) then
      Depth(0+1:kslmax+1 ) = 0.0_DP
      call MessageNotify( 'W', module_name, 'Depth is not found in namelist file.' )
    end if
    !
    if ( Depth(0+1) /= 0.0_DP ) then
      call MessageNotify( 'E', module_name, '  Depth(0) is not zero, but is %f', &
        & d = (/ Depth(0+1) /) )
    end if
    if ( kslmax >= 1 ) then
      if ( all( Depth(1+1:kslmax+1) >= 0.0_DP ) ) then
        do k = 0, kslmax
          call MessageNotify( 'M', module_name, '  Depth(%d) = %f', &
            & i = (/ k /), d = (/ Depth(k+1) /) )
        end do
        call MessageNotify( 'E', module_name, '  Depth has to be zero or negative.' )
      end if
    end if
    do k = 0, kslmax-1
      if ( Depth(k+1+1) > Depth(k+1) ) then
        call MessageNotify( 'M', module_name, '  Depth(%d) = %f > Depth(%d) = %f', &
            & i = (/ k+1, k /), d = (/ Depth(k+1+1), Depth(k+1) /) )
        call MessageNotify( 'E', module_name, '  Value of Depth has to decrease with index.' )
      end if
    end do

    r_SSDepth(0:kslmax) = Depth(1:kslmax+1)

    do k = 0, kslmax
      call MessageNotify( 'M', module_name, '  r_SSDepth(%d) = %f', &
        i = (/ k /), d = (/ r_SSDepth(k) /) )
    end do

    ! åœ°ä¸‹ã®é‰›ç›´å±¤ã®ä¸å¿ƒç‚¹ã®è¨å®š
    ! Set midpoint of subsurface grid
    !
    do k = 1, kslmax
      z_SSDepth( k ) = ( r_SSDepth( k-1 ) + r_SSDepth( k ) ) / 2.0d0
    end do

    ! ç·¯åº¦çµŒåº¦ã®è¨å®š
    ! Settings of longitude and latitude
    !
    allocate( x_Lon        (0:imax-1) )
    allocate( x_Lon_Weight (0:imax-1) )
    allocate( y_Lat        (1:jmax)   )
    allocate( y_Lat_Weight (1:jmax)   )

    if ( ( imax == 1 ) .and. ( jmax == 1 ) ) then

      x_Lon          = LonInDeg * PI / 180.0_DP
      x_Lon_Weight   = 1.0_DP
      y_Lat          = LatInDeg * PI / 180.0_DP
      y_Lat_Weight   = 1.0_DP

    else
      if ( .not. spml_inited ) then
#ifdef LIB_MPI
        call wa_mpi_Initial( nmax, imax, jmax_global, kmax, OMPNumThreads ) ! (in)
        ! Check number of latitudinal grid on each process
        call GridsetCheckNumberOfLatGrid( spml_jc )
#else
        call wa_Initial( nmax, imax, jmax_global, kmax, OMPNumThreads ) ! (in)
#endif
        spml_inited = .true.
      end if

      x_Lon          = spml_x_Lon
      x_Lon_Weight   = spml_x_Lon_Weight
      y_Lat          = spml_y_Lat
      y_Lat_Weight   = spml_y_Lat_Weight
    end if

    if ( imax /= 1  ) then
      ! DeltaLon, InvDeltaLonã®è¨ˆç®—
      ! Caluculate DeltaLon and InvDeltaLon
      DeltaLon = x_Lon(1) - x_Lon(0)
      InvDeltaLon = 1.0_DP/DeltaLon
    else
      DeltaLon = 0.0_DP
      InvDeltaLon = 0.0_DP ! not used
    endif

    ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®æ·»å—ç•ªå·ã®è¨å®š
    ! Settings of subscript of spectral data
    !
    do i = 1, size(w_Number)
      w_Number(i) = i
    end do

    ! ãƒ©ãƒ³ã‚¯ã«é–¢ã™ã‚‹æƒ…å ±ã®å–å¾—
    ! Get information about rank
    !
    myrank_mpi = -1
    nprocs_mpi = 1
    rank_str = ''

    ! å°å— ; Print
    !
    call MessageNotify( 'M', module_name, '----- Initialization Messages -----' )

#ifdef SJPACK
    call MessageNotify( 'M', module_name, 'SJPACK : %c', c1 = 'used.' )
#else
    call MessageNotify( 'M', module_name, 'SJPACK : %c', c1 = 'not used.' )
#endif

    call MessageNotify( 'M', module_name, 'OMPNumThreads = %d', i = (/OMPNumThreads/) )

    do ra = 0, nprocs_mpi - 1

      call MessageNotify( 'M', module_name, 'Axes:%c', c1 = trim(rank_str), rank_mpi = -1 )
      call MessageNotify( 'M', module_name, '  x_Lon(%d:%d) [deg.] = %*f', &
        & i = (/ 0, imax - 1/), &
        & d = format_print(x_Lon / PI * 180.0_DP, imax), &
        & n =(/ imax /), rank_mpi = -1 )
      call MessageNotify( 'M', module_name, '  y_Lat(%d:%d) [deg.] = %*f', &
        & i = (/ 1, jmax/), &
        & d = format_print(y_Lat / PI * 180.0_DP, jmax), &
        & n =(/ jmax /), rank_mpi = -1 )
      call MessageNotify( 'M', module_name, '  z_Sigma(%d:%d) = %*f', &
        & i = (/ 1, kmax /), &
        & d = format_print(z_Sigma, kmax), n =(/ kmax /), rank_mpi = -1 )
      call MessageNotify( 'M', module_name, '  r_Sigma(%d:%d) = %*f', &
        & i = (/ 0, kmax /), &
        & d = format_print(r_Sigma, kmax+1), n =(/ kmax+1 /), rank_mpi = -1 )
      call MessageNotify( 'M', module_name, '  w_Number(%d:%d) = %d .. %d', &
        & i = (/ 1, size(w_Number), 1, size(w_Number) /), rank_mpi = -1 )
  !
      call MessageNotify( 'M', module_name, 'Weight:' )
      call MessageNotify( 'M', module_name, '  x_Lon_Weight(%d:%d) = %*f', &
        & i = (/ 0, imax - 1/), &
        & d = format_print(x_Lon_Weight, imax), n =(/ imax /), rank_mpi = -1 )
      call MessageNotify( 'M', module_name, '  y_Lat_Weight(%d:%d) = %*f', &
        & i = (/ 1, jmax/), &
        & d = format_print(y_Lat_Weight, jmax), n =(/ jmax /), rank_mpi = -1 )
      call MessageNotify( 'M', module_name, '  z_DelSigma(%d:%d) = %*f', &
        & i = (/ 1, kmax /), &
        & d = format_print(z_DelSigma, kmax), n =(/ kmax /), rank_mpi = -1 )
      call MessageNotify( 'M', module_name, '' )
    end do

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

    axesset_inited = .true.

  end subroutine AxessetInit

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

  subroutine AxessetFinalize
    !
    ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«å†…éƒ¨ã®å¤‰æ•°ã®å‰²ã‚Šä»˜ã‘è§£é™¤ã‚’è¡Œã„ã¾ã™.
    !
    ! Deallocate variables in this module.
    !

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

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

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

    if ( .not. axesset_inited ) return

    ! å‰²ã‚Šä»˜ã‘è§£é™¤
    ! Deallocation
    !
    if ( allocated( z_Sigma    ) ) deallocate( z_Sigma    )
    if ( allocated( r_Sigma    ) ) deallocate( r_Sigma    )
    if ( allocated( z_DelSigma ) ) deallocate( z_DelSigma )
    if ( allocated( r_DelSigma ) ) deallocate( r_DelSigma )
    if ( allocated( w_Number   ) ) deallocate( w_Number   )

    if ( allocated( r_SSDepth ) ) deallocate( r_SSDepth )
    if ( allocated( z_SSDepth ) ) deallocate( z_SSDepth )

    if ( allocated( x_Lon        ) ) deallocate( x_Lon        )
    if ( allocated( x_Lon_Weight ) ) deallocate( x_Lon_Weight )
    if ( allocated( y_Lat        ) ) deallocate( y_Lat        )
    if ( allocated( y_Lat_Weight ) ) deallocate( y_Lat_Weight )

    axesset_inited = .false.

  end subroutine AxessetFinalize

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

  function format_print( ary, size ) result(result)
    !
    ! æ¨™æº–å‡ºåŠ›ã—ã¦è¦‹ã‚„ã™ã„ã‚ˆã†ã«é©å½“ã«æœ‰åŠ¹æ•°å—ã®æ¡ã‚’è½ã¨ã—ã¦è¿”ã™.
    !
    ! Effective digit is reduced for output to standard output and returned.
    !

    ! å®£è¨€æ–‡ ; Declaration statements
    !
    implicit none
    integer, intent(in):: size
    real(DP), intent(in):: ary(size)
    real(DP):: result(size)

    ! å®Ÿè¡Œæ–‡ ; Executable statement
    !
    result(1:size) = int( ary(1:size) * 1000.0_DP ) / 1000.0_DP

  end function format_print

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

end module axesset