!--
! *** Caution!! ***
! 
! This file is generated from "gt4_historyauto.rb2f90" by Ruby 1.8.5.
! Please do not edit this file directly.
!
! [JAPANESE]
!
! ※※※ 注意!!! ※※※
!
! このファイルは "gt4_historyauto.rb2f90" から Ruby 1.8.5
! によって自動生成されたファイルです.
! このファイルを直接編集しませんようお願い致します.
!
!
!++
!
!= gtool4 netCDF データの入出力インターフェース (大規模モデル用)
!= Interface of Input/Output of gtool4 netCDF data (For large models)
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id: gt4_historyauto.f90,v 1.19 2008-07-20 17:59:37 morikawa Exp $
! Tag Name::  $Name: gt4f90io-20080720 $
! Copyright:: Copyright (C) GFD Dennou Club, 2008. All rights reserved. 
! License::   See COPYRIGHT[link:../../COPYRIGHT]
!

module gt4_historyauto
  !
  != gtool4 netCDF データの入出力インターフェース (大規模モデル用)
  != Interface of Input/Output of gtool4 netCDF data (For large models)
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !
  ! gt4_historyauto モジュールは gt4_history モジュールの応用版であり, 
  ! 出力変数が 10 を超えるような大規模な数値モデルを想定した, 
  ! データ出力のための簡便な入出力インターフェースを
  ! 提供します. 
  ! このモジュールは以下のような特徴を持ちます. 
  !
  ! * 複数のファイルへの出力を行う場合, 
  !   gt4_history モジュールではファイルごとに 
  !   gt4_history#HistoryCreate を何度も
  !   呼び出す必要がありましたが, このモジュールでは
  !   HistoryAutoCreate をモデル内で一度呼び出すだけで済みます. 
  ! * 個別の変数について, 出力ファイルや出力間隔を手軽に変更可能です. 
  !   実際には, HistoryAutoAddVariable の引数もしくは, 
  !   NAMELIST#gt4_historyauto_nml によって変更することが可能です. 
  ! * gt4_history#GT_HISTORY 構造体を直接使用することなく
  !   出力を行うことが可能となっています. 
  !
  !
  ! "gt4_historyauto" module is an application of "gt4_history" module, 
  ! and provides data output easy-to-use interfaces
  ! for large numerical models that output 10 or more variables. 
  ! This module has following features. 
  !
  ! * In case that multiple files are output, 
  !   "gt4_history#HistoryCreate" must be called many times at each file
  !   using "gt4_history" module, while 
  !   "HistoryAutoCreate" has to be called once in a numerical model
  !   using this module. 
  ! * Output filename or output interval, etc can be changed easily. 
  !   In practice, their settings are changed by arguments of
  !   "HistoryAutoAddVariable" or "NAMELIST#gt4_historyauto_nml". 
  ! * "gt4_history#GT_HISTORY" need not be used. 
  !
  !
  !== Procedures list
  !
  ! HistoryAutoCreate       :: 初期化
  ! HistoryAutoAddVariable  :: 変数追加
  ! HistoryAutoPut          :: データ出力
  ! HistoryAutoProgress     :: 時刻進行
  ! HistoryAutoClose        :: 終了処理
  ! HistoryAutoPutAxis      :: 座標データ追加
  ! HistoryAutoAddWeight    :: 座標重み追加
  ! HistoryAutoAddAttr      :: 属性追加
  ! ---------------------   :: ---------------------
  ! HistoryAutoCreate       :: Initialization
  ! HistoryAutoAddVariable  :: Addition of variables
  ! HistoryAutoPut          :: Output of data
  ! HistoryAutoProgress     :: Progression of time
  ! HistoryAutoClose        :: Termination
  ! HistoryAutoPutAxis      :: Addition of data of axes
  ! HistoryAutoAddWeight    :: Addition of weights of axes
  ! HistoryAutoAddAttr      :: Addition of attributes
  !
  !
  !== NAMELIST
  !
  ! NAMELIST#gt4_historyauto_nml
  !
  !== Acknowledgment
  !
  ! * このモジュールは, 堀之内氏による gt4_history の
  !   アプリケーション "gt4_historyauto_h" を参照に作成しました. 
  !
  ! * "gt4_historyauto_h" that is an application of "gt4_history"
  !   by Horinouchi is referred when this module is created. 
  !

  ! gt4_history モジュール
  ! "gt4_history" module
  !
  use gt4_history, only: GT_HISTORY_AXIS, GT_HISTORY_VARINFO

  ! NAMELIST の使用を想定したヒストリデータ出力情報管理用ユーティリティ
  ! Utilities for history data output information management assuming use of NAMELIST
  !
  use gt4_history_nmlinfo, only: GTHST_NMLINFO

  ! NetCDF ライブラリで規定される最大の次元の数, 変数の数
  ! Maximum number of dimensions and variables prescribed by the NetCDF library
  !
  use netcdf_f77, only: NF_MAX_DIMS, NF_MAX_VARS

  ! 日付および時刻の取り扱い
  ! Date and time handler
  !
  use dc_date_types, only: DC_DIFFTIME
                              ! 日時の差を表現するデータ型. 
                              ! Data type for difference about date and time
  ! 種別型パラメタ
  ! Kind type parameter
  !
  use dc_types, only: DP, &      ! 倍精度実数型. Double precision. 
    &                 STRING, &  ! 文字列.       Strings. 
    &                 TOKEN      ! キーワード.   Keywords. 

  ! gt4_historyauto_h (堀之内版 gt4_historyauto) をカスケード提供
  ! gt4_historyauto_h (Horinouchi version of gt4_historyauto) is
  ! cascaded and provided. 
  !
  !--
  use gt4_historyauto_h, only: &
    & GT4_ATTRIBUTE, init_gt4_attribute, &
    & GT4_REAL1D, init_gt4_real1d, &
    & GT4_NAMED_REALARY, init_gt4_named_realary, &
    & HistoryAutoPut, HistoryAutoCreate, HistoryAutoCopyCreate, &
    & HistoryAutoWhetherPutNow, HistoryAutoSetRunInfo, HistoryAutoSetGrid
  !++
  implicit none
  private
  public:: HistoryAutoCreate
  public:: HistoryAutoClose
  public:: HistoryAutoAddWeight
  public:: HistoryAutoPutAxis
  public:: HistoryAutoAddVariable
  public:: HistoryAutoPut
  public:: HistoryAutoAddAttr
  public:: HistoryAutoProgress


  ! gt4_historyauto_h (堀之内版 gt4_historyauto) をカスケード提供
  ! gt4_historyauto_h (Horinouchi version of gt4_historyauto) is provided. 
  !
  !--
  public :: GT4_ATTRIBUTE, init_gt4_attribute
  public :: GT4_REAL1D, init_gt4_real1d
  public :: GT4_NAMED_REALARY, init_gt4_named_realary
!  public :: HistoryAutoPut
!  public :: HistoryAutoCreate
  public :: HistoryAutoCopyCreate
  public :: HistoryAutoWhetherPutNow
  public :: HistoryAutoSetRunInfo
  public :: HistoryAutoSetGrid
  !++

  ! 次元数
  ! Number of dimensions
  !
  integer, save:: numdims

  ! 座標重み変数の数
  ! Number of variables of axes weight
  !
  integer, save:: numwgts = 0

  ! 変数の数
  ! Number of variables
  !
  integer, save:: numvars = 0

  ! 出力ファイルの基本メタデータ
  ! Basic meta data for output file
  !
  character(STRING), save:: title_save
  character(STRING), save:: source_save
  character(STRING), save:: institution_save
  character(STRING), save:: conventions_save
  character(TOKEN),  save:: gt_version_save
  character(TOKEN),  save:: node_save

  ! 時刻データ
  ! Time data
  !
  type(DC_DIFFTIME), save:: start_difftime
  type(DC_DIFFTIME), save:: current_difftime
  type(DC_DIFFTIME), save:: delta_difftime
  integer, save:: Nstep = 0

  ! NAMELIST の使用を想定したヒストリデータ出力情報管理用ユーティリティ
  ! Utilities for history data output information management assuming use of NAMELIST
  !
  type(GTHST_NMLINFO), save:: gthstnml

  type GT_HISTORY_AXIS_DATA
    ! 
    ! 座標軸データ用の構造型
    ! Derived type for axes data
    !
    real(DP), pointer:: a_axis(:) =>null()
  end type GT_HISTORY_AXIS_DATA

  ! 座標軸情報
  ! Information of axes
  !
  type(GT_HISTORY_AXIS), save:: gthst_axes(1:NF_MAX_DIMS)
  type(GT_HISTORY_AXIS_DATA), save:: data_axes(1:NF_MAX_DIMS)
  type(GT_HISTORY_VARINFO), save:: gthst_weights(1:NF_MAX_DIMS)
  type(GT_HISTORY_AXIS_DATA), save:: data_weights(1:NF_MAX_DIMS)

  ! 変数情報
  ! Information of variables
  !
  type(GT_HISTORY_VARINFO), save:: gthst_vars(1:NF_MAX_VARS)


  ! 登録変数を全て出力するためのフラグ. 
  ! Flag for output all registered variables. 
  !
  logical, save:: all_output_save = .false.

  ! 時刻の進行が行われたかどうか
  ! * HistoryAutoProgress が一度でも呼ばれると .true. になる. 
  ! * 一度 .true. になると, HistoryAutoAddVariable を呼ぶことはできない. 
  ! 
  ! Whether the progress of time was done or not. 
  ! * Once "HistoryAutoProgress" is called, this argument becomes .true.
  ! * Once this argument becomes .true., "HistoryAutoAddVariable" can not be called. 
  !
  logical, save:: once_progressed = .false.

  ! 初期設定フラグ
  ! Initialization flag
  !
  logical, save:: initialized = .false.

  character(*), parameter:: sub_sname = "HistAuto"

  character(*), parameter:: version = &
    & '$Name: gt4f90io-20080720 $' // &
    & '$Id: gt4_historyauto.f90,v 1.19 2008-07-20 17:59:37 morikawa Exp $'

  interface HistoryAutoCreate
    module procedure HistoryAutoCreate1
  end interface

  interface HistoryAutoClose
    module procedure HistoryAutoClose1
  end interface

  interface HistoryAutoAddWeight
                        module procedure HistoryAutoAddWeightDouble
                    
    module procedure HistoryAutoAddWeightReal
                    
    module procedure HistoryAutoAddWeightInt
                    
  end interface

  interface HistoryAutoPutAxis
                        module procedure HistoryAutoPutAxisDouble
                    
    module procedure HistoryAutoPutAxisReal
                    
    module procedure HistoryAutoPutAxisInt
                    
  end interface

  interface HistoryAutoAddVariable
    module procedure HistoryAutoAddVariable1
  end interface

  interface HistoryAutoAddAttr
                        module procedure HistoryAutoAddAttrChar0
                    
    module procedure HistoryAutoAddAttrLogical0
                    
                                            module procedure HistoryAutoAddAttrInt0
                    
    module procedure HistoryAutoAddAttrInt1
                    
                        module procedure HistoryAutoAddAttrReal0
                    
    module procedure HistoryAutoAddAttrReal1
                    
                        module procedure HistoryAutoAddAttrDouble0
                    
    module procedure HistoryAutoAddAttrDouble1
                    
  end interface

  interface HistoryAutoPut
                                            module procedure HistoryAutoPutDouble1
                    
    module procedure HistoryAutoPutDouble2
                    
    module procedure HistoryAutoPutDouble3
                    
    module procedure HistoryAutoPutDouble4
                    
    module procedure HistoryAutoPutDouble5
                    
    module procedure HistoryAutoPutDouble6
                    
    module procedure HistoryAutoPutDouble7
                    
    module procedure HistoryAutoPutDouble0
                    
                        module procedure HistoryAutoPutReal1
                    
    module procedure HistoryAutoPutReal2
                    
    module procedure HistoryAutoPutReal3
                    
    module procedure HistoryAutoPutReal4
                    
    module procedure HistoryAutoPutReal5
                    
    module procedure HistoryAutoPutReal6
                    
    module procedure HistoryAutoPutReal7
                    
    module procedure HistoryAutoPutReal0
                    
                        module procedure HistoryAutoPutInt1
                    
    module procedure HistoryAutoPutInt2
                    
    module procedure HistoryAutoPutInt3
                    
    module procedure HistoryAutoPutInt4
                    
    module procedure HistoryAutoPutInt5
                    
    module procedure HistoryAutoPutInt6
                    
    module procedure HistoryAutoPutInt7
                    
    module procedure HistoryAutoPutInt0
                    
  end interface

  interface HistoryAutoProgress
    module procedure HistoryAutoProgress
  end interface

contains

  subroutine HistoryAutoCreate1( &
    & title, source, institution, &           ! (in)
    & dims, dimsizes, longnames, units, &     ! (in)
    & xtypes, conventions, gt_version,&       ! (in) optional
    & all_output, &                           ! (in) optional
    & file_prefix, &                          ! (in) optional
    & namelist_filename, &                    ! (in) optional
    & current_time, delta_time, &             ! (in) optional
    & interval, origin, terminus, &           ! (in) optional
    & slice_start, slice_end, slice_stride, & ! (in) optional
    & space_average, &                        ! (in) optional
    & time_average, &                         ! (in) optional
    & newfile_interval, &                     ! (in) optional
    & node &                                  ! (in) optional
    & )
    !
    ! 複数のヒストリデータ出力を行うための初期化を行います. 
    !
    ! この HistoryAutoCreate には, モデル内で出力する
    ! 変数が依存する座標や座標重みなどを全てを設定してください. 
    !
    ! all_output に .true. を与えた場合や,
    ! namelist_filename を与えない (空文字を与える) 場合には, 
    ! HistoryAutoAddVariable で登録される全ての変数が出力されます. 
    ! 一方で namelist_filename に NAMELIST ファイル名を与える場合には, 
    ! その NAMELIST ファイルから出力のオンオフや, 
    ! 出力ファイル名, 出力間隔などを変更可能です. 
    ! 変更可能な項目に関しては NAMELIST#gt4_historyauto_nml 
    ! を参照して下さい. 
    !
    ! interval
    !--
    ! , origin, terminus, slice_start, slice_end, slice_stride,
    ! space_average, time_average, newfile_interval 
    !++
    ! などの設定はデフォルト値として使用されます. 
    ! これらの設定値は HistoryAutoAddVariable および
    ! NAMELIST#gt4_historyauto_nml で上書きされます. 
    ! (優先度が高いのは NAMELIST#gt4_historyauto_nml ,
    ! HistoryAutoAddVariable の引数, 
    ! HistoryAutoCreate の引数 の順です). 
    !
    !
    ! Initialization for multiple history data output 
    !
    ! Set all axes and their weights depended by variables 
    ! output from numerical models to this "HistoryAutoCreate". 
    !
    ! All variables registered by "HistoryAutoAddVariable" 
    ! are output if .true. is given to "all_output" or 
    ! "namelist_filename" is not given (or blanks are given)
    ! On the other hand, if a filename of NAMELIST file is 
    ! given to "namelist_filename", on/off of output, 
    ! output filename and output interval, etc. can be changed 
    ! from the NAMELIST file. 
    ! For available items, see "NAMELIST#gt4_historyauto_nml". 
    !
    ! Settings about 
    ! "interval", 
    !--
    ! "origin", "terminus", "slice_start", "slice_end", "slice_stride",
    ! "space_average", "time_average", "newfile_interval" 
    !++
    ! etc. are used as default values. 
    ! Their set values are overwritten by 
    ! "HistoryAutoAddVariable" or 
    ! "NAMELIST#gt4_historyauto_nml". 
    ! ("NAMELIST#gt4_historyauto_nml" is high priority, 
    ! arguments of "HistoryAutoAddVariable" are medium, 
    ! arguments of "HistoryAutoCreate" are low). 
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, DC_EALREADYINIT, &
      & GT_EARGSIZEMISMATCH, HST_ENOTIMEDIM
    use netcdf_f77, only: NF_EMAXDIMS
    use dc_string, only: PutLine, Printf, Split, StrInclude, StoA, JoinChar
    use dc_present, only: present_and_not_empty, present_and_true, &
      & present_select
    use dc_date, only: DCDiffTimeCreate, EvalbyUnit
    use dc_message, only: MessageNotify
    use dc_iounit, only: FileOpen
    use gt4_history, only: HistoryAxisCreate
    use gt4_history_nmlinfo, only: HstNmlInfoCreate, HstNmlInfoAdd, &
      & HstNmlInfoEndDefine, HstNmlInfoPutLine, HstNmlInfoAllNameValid, &
      & HstNmlInfoInquire
    implicit none
    character(*), intent(in):: title
                              ! データ全体の表題. 
                              ! Title of entire data
    character(*), intent(in):: source
                              ! データを作成する際の手段. 
                              ! Source of data file
    character(*), intent(in):: institution
                              ! ファイルを最終的に変更した組織/個人. 
                              ! Institution or person that changes files for the last time
    character(*), intent(in):: dims(:)
                              ! 次元の名前. 
                              ! 
                              ! 配列の大きさに制限はありません.
                              ! 個々の次元の文字数は dc_types#TOKEN まで.
                              ! 配列内の文字数は
                              ! 全て同じでなければなりません.
                              ! 足りない文字分は空白で
                              ! 補ってください.
                              ! 
                              ! Names of dimensions.
                              ! 
                              ! Length of array is unlimited. 
                              ! Limits of numbers of characters of each 
                              ! dimensions are "dc_types#TOKEN". 
                              ! Numbers of characters in this array
                              ! must be same. 
                              ! Make up a deficit with blanks. 
                              ! 
    integer, intent(in):: dimsizes (:)
                              ! dims で指定したそれぞれの次元大きさ. 
                              ! 
                              ! 配列の大きさは dims の大きさと等しい
                              ! 必要があります.  '0' (数字のゼロ) を指定
                              ! するとその次元は 無制限次元 (unlimited
                              ! dimension) となります. (gt4_history 
                              ! では時間の次元に対して無制限次元を
                              ! 用いることを想定しています). ただし, 
                              ! 1 つの NetCDF ファイル (バージョン 3) 
                              ! は最大で 1 つの無制限次元しか持てないので, 
                              ! 2 ヶ所以上に '0' を指定しないでください. 
                              ! その場合, 正しく gtool4 データが出力されません.
                              ! 
                              ! Lengths of dimensions specified with "dims". 
                              ! 
                              ! Length of this array must be same as 
                              ! length of "dim".  If '0' (zero) is 
                              ! specified, the dimension is treated as 
                              ! unlimited dimension.  
                              ! (In "gt4_history", unlimited dimension is 
                              ! expected to be used as time). 
                              ! Note that one NetCDF file (version 3) 
                              ! can not have two or more unlimited 
                              ! dimensions, so that do not specify '0' 
                              ! to two or more places. In that case, 
                              ! gtoo4 data is not output currently 
                              ! 
    character(*), intent(in):: longnames (:)
                              ! dims で指定したそれぞれの次元の名前. 
                              !
                              ! 配列の大きさは dims の大きさ
                              ! と等しい必要があります. 文字数
                              ! は dc_types#STRING まで.
                              ! 配列内の文字数は
                              ! 全て同じでなければなりません.
                              ! 足りない文字分は空白で補います.
                              ! 
                              ! Names of dimensions specified with "dims". 
                              !
                              ! Length of this array must be same as 
                              ! length of "dim".  
                              ! Limits of numbers of characters are 
                              ! "dc_types#STRING". 
                              ! Numbers of characters in this array
                              ! must be same. 
                              ! Make up a deficit with blanks. 
                              ! 
    character(*), intent(in):: units(:)
                              ! dims で指定したそれぞれの次元の単位. 
                              !
                              ! 配列の大きさは dims の大きさ
                              ! と等しい必要があります. 文字数
                              ! は dc_types#STRING まで.
                              ! 配列内の文字数は
                              ! 全て同じでなければなりません.
                              ! 足りない文字分は空白で補います.
                              ! 
                              ! Units of dimensions specified with "dims". 
                              !
                              ! Length of this array must be same as 
                              ! length of "dim".  
                              ! Limits of numbers of characters are 
                              ! "dc_types#STRING". 
                              ! Numbers of characters in this array
                              ! must be same. 
                              ! Make up a deficit with blanks. 
                              ! 
    character(*), intent(in),  optional:: xtypes(:)
                              ! dims で指定したそれぞれの
                              ! 次元のデータ型. 
                              !
                              ! デフォルトは float (単精度実数型)
                              ! です. 有効なのは,
                              ! double (倍精度実数型), 
                              ! int (整数型) です. 指定しない
                              ! 場合や, 無効な型を指定した場合には,
                              ! float となります. なお, 配列の大きさ
                              ! は *dims* の大きさと等しい必要が
                              ! あります. 配列内の文字数は全て
                              ! 同じでなければなりません.
                              ! 足りない文字分は空白で補います.
                              !
                              ! Data types of dimensions specified 
                              ! with "dims". 
                              !
                              ! Default value is "float" (single precision). 
                              ! Other valid values are 
                              ! "double" (double precision), 
                              ! "int" (integer). 
                              ! If no value or invalid value is specified, 
                              ! "float" is applied. 
                              ! Length of this array must be same as 
                              ! length of "dim".  
                              ! Numbers of characters in this array
                              ! must be same. 
                              ! Make up a deficit with blanks. 
                              ! 
    character(*), intent(in), optional:: conventions
                              ! 出力するファイルの netCDF
                              ! 規約
                              !
                              ! 省略した場合,
                              ! もしくは空文字を与えた場合,
                              ! 出力する netCDF 規約の
                              ! Conventions 属性に値
                              ! gtool4_netCDF_Conventions
                              ! が自動的に与えられます.
                              ! 
                              ! NetCDF conventions of output file. 
                              !
                              ! If this argument is omitted or, 
                              ! blanks are given,
                              ! gtool4_netCDF_Conventions is given to 
                              ! attribute "Conventions" of an output file
                              ! automatically. 
                              ! 
    character(*), intent(in), optional:: gt_version
                              ! gtool4 netCDF 規約のバージョン
                              !
                              ! 省略した場合, gt_version 属性に
                              ! 規約の最新版のバージョンナンバー
                              ! gtool4_netCDF_version
                              ! が与えられます.
                              ! (ただし, 引数 conventions に
                              ! gtool4_netCDF_Conventions
                              ! 以外が与えられる場合は
                              ! gt_version 属性を作成しません).
                              ! 
                              ! Version of gtool4 netCDF Conventions. 
                              !
                              ! If this argument is omitted, 
                              ! latest version number of gtool4 netCDF 
                              ! Conventions is given to attribute 
                              ! "gt_version" of an output file 
                              ! (However, gtool4_netCDF_Conventions is 
                              ! not given to an argument "conventions", 
                              ! attribute "gt_version" is not created).
                              ! 
    logical, intent(in), optional:: all_output
                              ! 登録変数を全て出力するためのフラグ. 
                              !
                              ! .true. を指定すると, 
                              ! HistoryAutoAddVariable で登録された
                              ! 変数が全て出力されるようになります. 
                              !
                              ! *namelist_filename* が指定される場合
                              ! には, デフォルトは .false. となります. 
                              ! この場合には, 
                              ! *namelist_filename* に指定された 
                              ! NAMELIST ファイルから読み込まれる
                              ! NAMELIST#gt4_historyauto_nml
                              ! で指定された変数のみ出力されます.
                              !
                              ! *namelist_filename* が指定されない場合
                              ! には, .true. となります. 
                              !
                              !
                              ! Flag for output all registered variables. 
                              ! 
                              ! When .true. is specified, 
                              ! all variables registered by
                              ! "HistoryAutoAddVariable" are output. 
                              ! 
                              ! If *namelist_filename* is specified, 
                              ! default value becomes .false. .
                              ! In this case, 
                              ! only variables specified in 
                              ! "NAMELIST#gt4_historyauto_nml"
                              ! loaded from a NAMELIST file
                              ! *namelist_filename*. 
                              ! 
                              ! If *namelist_filename* is not specified, 
                              ! this value becomes .true. .
                              ! 
    character(*), intent(in), optional:: file_prefix
                              ! ヒストリデータのファイル名の接頭詞. 
                              ! Prefixes of history data filenames
    character(*), intent(in), optional:: namelist_filename
                              ! NAMELIST ファイルの名称. 
                              !
                              ! 省略した場合, もしくは空白文字を与えた場合, 
                              ! NAMELIST ファイルは読み込みません. 
                              ! 
                              ! Name of NAMELIST file. 
                              !
                              ! If this argument is omitted, 
                              ! or blanks are specified, 
                              ! no NAMELIST file is loaded. 
                              ! 
    real, intent(in), optional:: current_time
                              ! 数値モデル内の現在時刻 (単位: 秒). 
                              !
                              ! 省略した場合, 自動的にゼロが設定されます. 
                              ! 
                              ! Current time in a numerical model
                              ! (unit: seconds). 
                              ! 
                              ! If this argument is omitted, 
                              ! zero is set automatically. 
                              ! 
    real, intent(in), optional:: delta_time
                              ! 数値モデル内のタイムステップ (単位: 秒). 
                              !
                              ! 省略した場合, 自動的に 1.0 が設定されます. 
                              ! 
                              ! Time step in a numerical model
                              ! (unit: seconds). 
                              ! 
                              ! If this argument is omitted, 
                              ! 1.0 is set automatically. 
                              ! 
    real, intent(in), optional:: interval
                              ! 出力時間間隔. 
                              !
                              ! 省略した場合, 
                              ! 自動的に delta_time の値が設定されます.
                              !
                              ! Interval of output time. 
                              !
                              ! If this argument is omitted, 
                              ! a value of "delta_time" is specified 
                              ! automatically. 
                              ! 
    real, intent(in), optional:: origin
                              ! 出力開始時刻. 
                              !
                              ! 省略した場合, 自動的に current_time の値が
                              ! 設定されます.
                              ! 
                              ! Start time of output. 
                              !
                              ! If this argument is omitted, 
                              ! a value of "current_time" is specified
                              ! automatically. 
                              ! 
    real, intent(in), optional:: terminus
                              ! 出力終了時刻. 
                              !
                              ! 省略した場合, 数値モデルの実行が終了するまで
                              ! 出力を行います. 
                              ! 
                              ! End time of output. 
                              !
                              ! If this argument is omitted, 
                              ! output is continued until a numerical model
                              ! is finished. 
                              ! 
    real, intent(in), optional:: slice_start(:)
                              ! 空間方向の開始点. 
                              !
                              ! 省略した場合, 座標データの開始点が設定されます.
                              ! 
                              ! Start points of spaces. 
                              ! 
                              ! If this argument is omitted, 
                              ! start points of dimensions are set. 
                              ! 
    real, intent(in), optional:: slice_end(:)
                              ! 空間方向の終了点. 
                              !
                              ! 省略した場合, 座標データの終了点が設定されます.
                              ! 
                              ! End points of spaces. 
                              ! 
                              ! If this argument is omitted, 
                              ! End points of dimensions are set. 
                              ! 
    integer, intent(in), optional:: slice_stride(:)
                              ! 空間方向の刻み幅. 
                              !
                              ! 省略した場合, 1 が設定されます.
                              ! 
                              ! Strides of spaces
                              ! 
                              ! If this argument is omitted, 
                              ! 1 is set. 
                              ! 
    logical, intent(in), optional:: space_average(:)
                              ! 平均化のフラグ. 
                              !
                              ! .true. が指定される座標に対して平均化を
                              ! 行います. 
                              ! 省略した場合, .false. が設定されます.
                              ! 
                              ! Flag of average. 
                              ! 
                              ! Axes specified .true. are averaged. 
                              ! If this argument is omitted, 
                              ! .false. is set. 
                              ! 
    logical, intent(in), optional:: time_average
                              ! 出力データの時間平均フラグ. 
                              ! デフォルトは .false. 
                              ! Flag for time average of output data
                              ! Default value is .false.
    real, intent(in), optional:: newfile_interval
                              ! ファイル分割時間間隔. 
                              !
                              ! 省略した場合, 
                              ! 時間方向へのファイル分割を行いません. 
                              !
                              ! Interval of time of separation of a file. 
                              !
                              ! If this argument is omitted, 
                              ! a files is not separated in time direction.
                              ! 
    character(*), intent(in), optional:: node
                              ! ノードの名称. 
                              !
                              ! Name of a node. 
                              !

    ! NAMELIST 変数群 ; NAMELIST group of variables
    character(STRING):: Name
                              ! 変数名. 
                              ! 空白の場合には, この他の設定値は
                              ! gt4_historyauto モジュールにおいて
                              ! 出力されるデータ全ての
                              ! デフォルト値となります. 
                              ! 
                              ! "Data1,Data2" のようにカンマで区切って複数
                              ! の変数を指定することも可能です. 
                              ! 
                              ! Variable identifier. 
                              ! If blank is given, other values are 
                              ! used as default values of output data 
                              ! in "gt4_historyauto". 
                              ! 
                              ! Multiple variables can be specified 
                              ! as "Data1,Data2" too. Delimiter is comma. 
    character(STRING):: File
                              ! 出力ファイル名. 
                              ! これはデフォルト値としては使用されません. 
                              ! *Name* に値が設定されている時のみ有効です. 
                              ! 
                              ! Output file name. 
                              ! This is not used as default value. 
                              ! This value is valid only when *Name* is 
                              ! specified. 

    real:: IntValue
                              ! ヒストリデータの出力間隔の数値. 
                              ! 負の値を与えると, 出力を抑止します. 
                              ! Numerical value for interval of history data output
                              ! Negative values suppresses output.
    character(TOKEN):: IntUnit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    character(TOKEN):: Precision
                              ! ヒストリデータの精度. 
                              ! Precision of history data
    character(STRING):: FilePrefix
                              ! ヒストリデータのファイル名の接頭詞. 
                              ! Prefixes of history data filenames
    logical:: TimeAverage
                              ! 出力データの時間平均フラグ. 
                              ! Flag for time average of output data
    logical:: AllOutput
                              ! 登録変数を全て出力するためのフラグ. 
                              ! Flag for output all registered variables. 

!!$    real:: OriginValue
!!$                              ! 出力開始時刻. 
!!$                              ! Start time of output. 
!!$    character(TOKEN):: OriginUnit
!!$                              ! 出力開始時刻の単位. 
!!$                              ! Unit of start time of output. 
!!$    real:: TerminusValue
!!$                              ! 出力終了時刻. 
!!$                              ! End time of output. 
!!$    character(TOKEN):: TerminusUnit
!!$                              ! 出力終了時刻の単位. 
!!$                              ! Unit of end time of output. 
!!$    real:: SliceStart(1:NF_MAX_DIMS)
!!$                              ! 空間方向の開始点. 
!!$                              ! Start points of spaces. 
!!$    real:: SliceEnd(1:NF_MAX_DIMS)
!!$                              ! 空間方向の終了点. 
!!$                              ! End points of spaces. 
!!$    integer:: SliceStride(1:NF_MAX_DIMS)
!!$                              ! 空間方向の刻み幅. 
!!$                              ! Strides of spaces. 
!!$    logical:: SpaceAverage(1:NF_MAX_DIMS)
!!$                              ! 平均化のフラグ. 
!!$                              ! Flag of average. 
!!$    real:: NewFileIntValue
!!$                              ! ファイル分割時間間隔. 
!!$                              ! Interval of time of separation of a file. 
!!$    character(TOKEN):: NewFileIntUnit
!!$                              ! ファイル分割時間間隔の単位. 
!!$                              ! Unit of interval of time of separation of a file. 

    namelist /gt4_historyauto_nml/ &
      & Name, File, &
      & IntValue, IntUnit, &
      & Precision, &
      & FilePrefix, &
!!$      & OriginValue, OriginUnit, &
!!$      & TerminusValue, TerminusUnit, &
!!$      & SliceStart, SliceEnd, SliceStride, SpaceAverage, &
!!$      & NewFileIntValue, NewFileIntUnit, &
      & TimeAverage, AllOutput
                              ! gt4_historyauto モジュールのヒストリデータ用
                              ! NAMELIST 変数群名. 
                              !
                              ! gt4_historyauto#HistoryAutoCreate
                              ! を使用する際に, オプショナル引数 *namelist_filename* 
                              ! へ NAMELIST ファイル名を指定することで, 
                              ! そのファイルからこの NAMELIST 変数群を
                              ! 読み込みます. 
                              !
                              ! NAMELIST group name for 
                              ! history data of "gt4_historyauto" module. 
                              ! 
                              ! If a NAMELIST filename is specified to 
                              ! an optional argument *namelist_filename* when 
                              ! "gt4_historyauto#HistoryAutoCreate" 
                              ! is used, this NAMELIST group is 
                              ! loaded from the file. 


    ! 作業変数 ; Work variables
    integer:: stat
    character(STRING):: cause_c
    integer:: unit_nml        ! NAMELIST ファイルオープン用装置番号. 
                              ! Unit number for NAMELIST file open
    integer:: iostat_nml      ! NAMELIST 読み込み時の IOSTAT. 
                              ! IOSTAT of NAMELIST read
    character(TOKEN):: pos_nml
                              ! NAMELIST 読み込み時のファイル位置. 
                              ! File position of NAMELIST read
    integer:: i, j
    character(TOKEN):: my_xtype

    real:: interval_work
    character(*), parameter:: subname = "HistoryAutoCreate1"
  continue
    call BeginSub(subname, version = version)
    stat = DC_NOERR
    cause_c = ""

    ! このサブルーチンが 2 度呼ばれたらエラー
    ! Error is occurred when this subroutine is called twice
    !
    if ( initialized ) then
      stat = DC_EALREADYINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 次元の数に関するエラー処理
    ! Error handling for number of dimensions
    !
    numdims = size(dims)

    if ( size(dimsizes) /= numdims ) then
      cause_c = 'dimsizes, dims'
    elseif ( size(longnames) /= numdims ) then
      cause_c = 'longnames, dims'
    elseif ( size(units) /= numdims ) then
      cause_c = 'units, dims'
    endif
    if ( trim(cause_c) /= "" ) then
      stat = GT_EARGSIZEMISMATCH
      goto 999
    end if

    if ( numdims > NF_MAX_DIMS ) then
      stat = NF_EMAXDIMS
      goto 999
    end if

    ! 時刻次元に関するエラー処理
    ! Error handling for time dimension
    !
    if ( dimsizes(numdims) /= 0 ) then
      call MessageNotify( 'W', subname, &
        & 'time dimension must be specified to the last of "dims"' )
      stat = HST_ENOTIMEDIM
      goto 999
    end if

    ! 出力ファイルの基本メタデータの保管
    ! Save basic meta data for output file
    !
    title_save       = title
    source_save      = source
    institution_save = institution

    conventions_save = ''
    if ( present(conventions) ) conventions_save = conventions

    gt_version_save = ''
    if ( present(gt_version) ) gt_version_save = gt_version

    node_save = ''
    if ( present(node) ) node_save = node

    ! 座標軸データの保管
    ! Save axes data
    !
    do i = 1, numdims
      my_xtype = ''
      if ( present(xtypes) ) then
        if ( size(xtypes) >= i ) then
          my_xtype = xtypes(i)
        end if
      end if

      call HistoryAxisCreate( &
        &     axis = gthst_axes(i), &                     ! (out)
        &     name = dims(i),       size = dimsizes(i), & ! (in)
        & longname = longnames(i), units = units(i), &    ! (in)
        &    xtype = my_xtype )                           ! (in)

      allocate( data_axes(i) % a_axis( dimsizes(i) ) )
      data_axes(i) % a_axis = (/ ( real( j, DP ), j = 1, dimsizes(i) ) /)

    end do

    ! 登録変数を全て出力するためのフラグの保管
    ! Save flag for output all registered variables
    !
    if ( present(all_output) ) all_output_save = all_output
    if ( .not. present_and_not_empty(namelist_filename) ) all_output_save = .true.
    AllOutput = all_output_save

    ! 時刻データの設定
    ! Configure time data
    !
    if ( present(current_time ) ) then
      call DCDiffTimeCreate( &
        & start_difftime, &                 ! (out)
        & real( current_time, DP ), 'sec' ) ! (in)
    else
      call DCDiffTimeCreate( &
        & start_difftime, & ! (out)
        & 0.0_DP, 'sec' )   ! (in)
    end if

    current_difftime = start_difftime

    if ( present(delta_time) ) then
      call DCDiffTimeCreate( &
        & delta_difftime, &               ! (out)
        & real( delta_time, DP ), 'sec' ) ! (in)
    else
      call DCDiffTimeCreate( &
        & delta_difftime, & ! (out)
        & 1.0_DP, 'sec' )   ! (in)
    end if

    ! 出力時間間隔のデフォルト値設定
    ! Configure default interval of output time
    !
    if ( all_output_save ) then
      if ( present(interval) ) then
        interval_work = interval
      else
        interval_work = EvalbyUnit( delta_difftime, units(numdims) )
      end if
    else
      interval_work = - 1.0
    end if

    ! gt4_historyauto_nml へデフォルト値の設定
    ! Configure default values for "gt4_historyauto_nml"
    !
    call HstNmlInfoCreate( gthstnml ) ! (out)

    call HstNmlInfoAdd( &
      & gthstnml = gthstnml, &              ! (inout)
      & name = '', &                        ! (in) optional
      & interval_value = interval_work, &   ! (in) optional
      & interval_unit  = units(numdims), &  ! (in) optional
!!$      & origin_value   = origin, &          ! (in) optional
!!$      & origin_unit    = units(numdims), &  ! (in) optional
!!$      & terminus_value = terminus, &        ! (in) optional
!!$      & terminus_unit  = units(numdims), &  ! (in) optional
      & precision = 'float', &              ! (in) optional
      & time_average = time_average, &         ! (in) optional
!!$      & slice_start  = slice_start, &       ! (in) optional
!!$      & slice_end    = slice_end, &         ! (in) optional
!!$      & slice_stride = slice_stride, &      ! (in) optional
!!$      & space_average = space_average, &       ! (in) optional
!!$      & newfile_interval_value = newfile_interval, & ! (in) optional
!!$      & newfile_interval_unit = units(numdims), & ! (in) optional
      & fileprefix = file_prefix )             ! (in) optional

    ! NAMELIST ファイルの読み込み
    ! Load NAMELIST file
    !
    if ( present_and_not_empty(namelist_filename) ) then
      call FileOpen( unit_nml, &          ! (out)
        & namelist_filename, mode = 'r' ) ! (in)
      
      iostat_nml = 0
      pos_nml = ''

      call MessageNotify( 'M', sub_sname, '----- "gt4_historyauto_nml" is loaded from "%c" -----', &
        & c1 = trim(namelist_filename) )

      do while ( trim(pos_nml) /= 'APPEND' .and. iostat_nml == 0 )

        Name = ''
        File = ''
        call HstNmlInfoInquire( &
          & gthstnml = gthstnml, &             ! (in)
          & interval_value = IntValue, &       ! (out) optional
          & interval_unit = IntUnit, &         ! (out) optional
          & precision = Precision, &           ! (out) optional
          & time_average = TimeAverage, &      ! (out) optional
!!$          & origin_value   = OriginValue, &    ! (out) optional
!!$          & origin_unit    = OriginUnit, &     ! (out) optional
!!$          & terminus_value = TerminusValue, &  ! (out) optional
!!$          & terminus_unit  = TerminusUnit, &   ! (out) optional
!!$          & slice_start  = SliceStart, &       ! (out) optional
!!$          & slice_end    = SliceEnd, &         ! (out) optional
!!$          & slice_stride = SliceStride, &      ! (out) optional
!!$          & space_average = SpaceAverage, &    ! (out) optional
!!$          & newfile_interval_value = NewFileIntValue, & ! (out) optional
!!$          & newfile_interval_unit  = NewFileIntUnit, &  ! (out) optional
          & fileprefix = FilePrefix )          ! (out) optional

        read( unit = unit_nml, &            ! (in)
          &    nml = gt4_historyauto_nml, & ! (out)
          & iostat = iostat_nml )           ! (out)
        inquire( unit = unit_nml, & ! (in)
          &  position = pos_nml )   ! (out)

        if ( iostat_nml == 0 ) then

          ! 情報の登録
          ! Register information
          !
          call HstNmlInfoAdd( &
            & gthstnml = gthstnml, &             ! (inout)
            & name = Name, &                     ! (in) optional
            & file = File, &                     ! (in) optional
            & interval_value = IntValue, &       ! (in) optional
            & interval_unit = IntUnit, &         ! (in) optional
            & precision = Precision, &           ! (in) optional
            & time_average = TimeAverage, &      ! (in) optional
!!$            & origin_value   = OriginValue, &    ! (in) optional
!!$            & origin_unit    = OriginUnit, &     ! (in) optional
!!$            & terminus_value = TerminusValue, &  ! (in) optional
!!$            & terminus_unit  = TerminusUnit, &   ! (in) optional
!!$            & slice_start  = SliceStart, &       ! (in) optional
!!$            & slice_end    = SliceEnd, &         ! (in) optional
!!$            & slice_stride = SliceStride, &      ! (in) optional
!!$            & space_average = SpaceAverage, &    ! (in) optional
!!$            & newfile_interval_value = NewFileIntValue, & ! (in) optional
!!$            & newfile_interval_unit  = NewFileIntUnit, &  ! (in) optional
            & fileprefix = FilePrefix )          ! (in) optional

          ! 登録変数を全て出力するためのフラグの保管
          ! Save flag for output all registered variables
          !
          if ( trim(Name) == '' ) then
            all_output_save = AllOutput
          end if

          ! 印字 ; Print
          !
          if ( trim(File) == '' ) File = '<Name>.nc'

          if ( trim(Name) == '' ) then
            call MessageNotify( 'M', sub_sname, 'Global Settings:' )
            call MessageNotify( 'M', sub_sname, '  AllOutput       = %b', l  = (/ AllOutput   /) )
          else
            call MessageNotify( 'M', sub_sname, 'Individual Settings:' )
            call MessageNotify( 'M', sub_sname, '  Name            = %c', c1 = trim(Name           ) )
            call MessageNotify( 'M', sub_sname, '  File            = %c', c1 = trim(File           ) )
          end if
          call MessageNotify( 'M', sub_sname, '  Interval        = %r [%c]', &
            & r = (/ IntValue /), c1 = trim( IntUnit ) )
          call MessageNotify( 'M', sub_sname, '  Precision       = %c', c1 = trim(Precision    ) )
          call MessageNotify( 'M', sub_sname, '  TimeAverage     = %b', l  = (/ TimeAverage   /) )
          call MessageNotify( 'M', sub_sname, '  FilePrefix      = %c', c1 = trim(FilePrefix   ) )
!!$          call MessageNotify( 'M', sub_sname, '  Origin          = %r [%c]', &
!!$            & r = (/ OriginValue /), c1 = trim( OriginUnit ) )
!!$          call MessageNotify( 'M', sub_sname, '  Terminus        = %r [%c]', &
!!$            & r = (/ TerminusValue /), c1 = trim( TerminusUnit ) )
!!$          call MessageNotify( 'M', sub_sname, '  SliceStart      = (/ %*r /)', &
!!$            &                                r = SliceStart(1:numdims-1), n = (/ ndims-1 /) )
!!$          call MessageNotify( 'M', sub_sname, '  SliceEnd        = (/ %*r /)', &
!!$            &                                r = SliceEnd(1:numdims-1), n = (/ ndims-1 /) )
!!$          call MessageNotify( 'M', sub_sname, '  SliceStride     = (/ %*r /)', &
!!$            &                                r = SliceStride(1:numdims-1), n = (/ ndims-1 /) )
!!$          call MessageNotify( 'M', sub_sname, '  SpaceAverage    = (/ %*b /)', &
!!$            &                                l = SpaceAverage(1:numdims-1), n = (/ ndims-1 /) )
!!$          call MessageNotify( 'M', sub_sname, '  NewFileInterval = %r [%c]', &
!!$            & r = (/ NewFileIntValue /), c1 = trim( NewFileIntUnit ) )
          call MessageNotify( 'M', sub_sname, '' )

        else
          call MessageNotify( 'M', sub_sname, '----- loading is finished (iostat=%d) -----', &
            & i = (/iostat_nml/) )
        end if
      end do

      close( unit_nml )


    ! NAMELIST ファイルを読み込まない場合
    ! NAMELIST file is not loaded
    !
    else
      call MessageNotify( 'M', sub_sname, '----- "gt4_historyauto_nml" is not loaded" -----' )
      Name = ''
      File = ''
      call HstNmlInfoInquire( &
        & gthstnml = gthstnml, &             ! (in)
        & interval_value = IntValue, &       ! (out) optional
        & interval_unit = IntUnit, &         ! (out) optional
        & precision = Precision, &           ! (out) optional
        & time_average = TimeAverage, &      ! (out) optional
!!$        & origin_value   = OriginValue, &    ! (out) optional
!!$        & origin_unit    = OriginUnit, &     ! (out) optional
!!$        & terminus_value = TerminusValue, &  ! (out) optional
!!$        & terminus_unit  = TerminusUnit, &   ! (out) optional
!!$        & slice_start  = SliceStart, &       ! (out) optional
!!$        & slice_end    = SliceEnd, &         ! (out) optional
!!$        & slice_stride = SliceStride, &      ! (out) optional
!!$        & space_average = SpaceAverage, &    ! (out) optional
!!$        & newfile_interval_value = NewFileIntValue, & ! (out) optional
!!$        & newfile_interval_unit  = NewFileIntUnit, &  ! (out) optional
        & fileprefix = FilePrefix )          ! (out) optional

      ! 印字 ; Print
      !
      call MessageNotify( 'M', sub_sname, 'Global Settings:' )
      call MessageNotify( 'M', sub_sname, '  AllOutput       = %b', l  = (/ AllOutput   /) )
      call MessageNotify( 'M', sub_sname, '  Interval        = %r [%c]', &
        & r = (/ IntValue /), c1 = trim( IntUnit ) )
      call MessageNotify( 'M', sub_sname, '  Precision       = %c', c1 = trim(Precision    ) )
      call MessageNotify( 'M', sub_sname, '  TimeAverage     = %b', l  = (/ TimeAverage   /) )
      call MessageNotify( 'M', sub_sname, '  FilePrefix      = %c', c1 = trim(FilePrefix   ) )
!!$      call MessageNotify( 'M', sub_sname, '  Origin          = %r [%c]', &
!!$        & r = (/ OriginValue /), c1 = trim( OriginUnit ) )
!!$      call MessageNotify( 'M', sub_sname, '  Terminus        = %r [%c]', &
!!$        & r = (/ TerminusValue /), c1 = trim( TerminusUnit ) )
!!$      call MessageNotify( 'M', sub_sname, '  SliceStart      = (/ %*r /)', &
!!$        &                                r = SliceStart(1:numdims-1), n = (/ ndims-1 /) )
!!$      call MessageNotify( 'M', sub_sname, '  SliceEnd        = (/ %*r /)', &
!!$        &                                r = SliceEnd(1:numdims-1), n = (/ ndims-1 /) )
!!$      call MessageNotify( 'M', sub_sname, '  SliceStride     = (/ %*r /)', &
!!$        &                                r = SliceStride(1:numdims-1), n = (/ ndims-1 /) )
!!$      call MessageNotify( 'M', sub_sname, '  SpaceAverage    = (/ %*b /)', &
!!$        &                                l = SpaceAverage(1:numdims-1), n = (/ ndims-1 /) )
!!$      call MessageNotify( 'M', sub_sname, '  NewFileInterval = %r [%c]', &
!!$        & r = (/ NewFileIntValue /), c1 = trim( NewFileIntUnit ) )
      call MessageNotify( 'M', sub_sname, '' )

    end if

    ! 終了処理, 例外処理
    ! Termination and Exception handling
    !
    initialized = .true.

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname, 'stat=%d', i = (/stat/) )
  end subroutine HistoryAutoCreate1

  subroutine HistoryAutoClose1
    !
    ! HistoryAutoCreate で始まったデータ出力の終了処理を行います. 
    ! プログラムを終了する前に必ずこのサブルーチンを呼んでください. 
    ! 
    ! Terminates data output with "HistoryAutoCreate". 
    ! Call this subroutine certainly before a progrem is finished. 
    ! 
    use dc_trace, only: BeginSub, EndSub
    use dc_string, only: PutLine, Printf, Split, StrInclude, StoA, JoinChar
    use dc_error, only: StoreError, DC_NOERR, DC_ENOTINIT
    use gt4_history_nmlinfo, only: HstNmlInfoClose, HstNmlInfoNames, &
      & HstNmlInfoAssocGtHist, HstNmlInfoPutLine
    use gt4_history, only: GT_HISTORY, HistoryClose, HistoryInitialized, &
      & HistoryAxisClear, HistoryVarinfoClear

    ! ヒストリファイルへのデータ出力設定
    ! Configure the settings for history data output
    !
    character(STRING):: name = ''
                              ! 変数名. Variable identifier
    character(STRING):: varnames
                              ! 変数名リスト. 
                              ! List of variables
    character(TOKEN), pointer:: varnames_array(:) =>null()
                              ! 変数名リスト配列. 
                              ! List of variables (array) 
    integer:: i, vnmax
    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    ! 作業変数
    ! Work variables
    !
    integer:: stat
    character(STRING):: cause_c
    character(*), parameter:: subname = 'HistoryAutoClose1'
  continue
    call BeginSub( subname )
    stat = DC_NOERR
    cause_c = ''

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! ヒストリファイルへのデータ出力の終了処理
    ! Terminate the settings for history data output
    !
    varnames = HstNmlInfoNames( gthstnml )
    call Split( str = varnames, sep = ',', & ! (in)
      & carray = varnames_array )            ! (out)
    vnmax = size( varnames_array )

    do i = 1, vnmax
      name = varnames_array(i)
      if ( trim( name ) == '' ) exit
      nullify( gthist )
      call HstNmlInfoAssocGtHist( & 
        & gthstnml = gthstnml, & ! (in)
        & name = name, &         ! (in)
        & history = gthist )     ! (out)
      if ( HistoryInitialized( gthist ) ) then
        call HistoryClose( history = gthist ) ! (inout)
      end if
    end do

    ! ヒストリファイルへのデータ出力設定の割付解除
    ! Deallocate the settings for history data output
    !
    call HstNmlInfoClose( gthstnml ) ! (inout)

    ! 座標軸情報のクリア
    ! Create axes information
    !
    do i = 1, numdims
      call HistoryAxisClear( gthst_axes(i) )
      deallocate( data_axes(i) % a_axis )
    end do
    numdims = 0

    ! 座標重み情報のクリア
    ! Create axes weights information
    !
    do i = 1, numwgts
      call HistoryVarinfoClear( gthst_weights(i) )
      deallocate( data_weights(i) % a_axis )
    end do
    numwgts = 0

    ! 変数情報のクリア
    ! Create variables information
    !
    do i = 1, numvars
      call HistoryVarinfoClear( gthst_vars(i) )
    end do
    numvars = 0

    ! 時刻データのクリア
    ! Clear time data
    !
    Nstep = 0

    ! 終了処理, 例外処理
    ! Termination and Exception handling
    !
    initialized = .false.
    once_progressed = .false.
    all_output_save = .false.

999 continue
    call StoreError( stat, subname, cause_c = cause_c )
    call EndSub( subname )
  end subroutine HistoryAutoClose1


  subroutine HistoryAutoAddWeightReal( &
    & dim, weight, &  ! (in)
    & units, xtype &  ! (in) optional
    & )
    !
    ! 座標の重みデータを設定します. 
    !
    ! Set weights of axes. 
    !

    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, &
      & GT_EARGSIZEMISMATCH, HST_ENOAXISNAME, DC_ENOTINIT
    use gt4_history, only: HistoryAxisInquire, HistoryAxisAddAttr, &
      &                    HistoryVarinfoCreate

    implicit none
    character(*), intent(in):: dim
                              ! 座標重みを設定する座標の名称. 
                              !
                              ! ただし, ここで指定するもの
                              ! は, HistoryAutoCreate の *dims*
                              ! 既に指定されていなければなりません.
                              !
                              ! Name of axis to which "weight" are set. 
                              !
                              ! Note that this value must be set 
                              ! as "dims" of "HistoryAutoCreate". 
                              !
    real, intent(in):: weight(:)
                              ! 座標重みデータ. 
                              !
                              ! データ型は整数, 単精度実数型, 
                              ! 倍精度実数型のどれでもかまいません. 
                              ! ただし, ファイルへ出力される際には, 
                              ! xtype もしくは座標データの型へと
                              ! 変換されます. 
                              ! 
                              ! Weight of axis. 
                              ! 
                              ! Integer, single or double precision are 
                              ! acceptable as data type. 
                              ! Note that when this is output to a file, 
                              ! data type is converted into "xtype" or 
                              ! type of the axis. 
                              ! 
    character(*), intent(in), optional:: units
                              ! 座標重みの単位. 
                              ! 省略した場合には, 座標の単位が
                              ! 使用されます. 
                              !
                              ! Units of axis weight.
                              ! If this argument is omitted, 
                              ! unit of the dimension is used. 
                              !
    character(*), intent(in),  optional:: xtype
                              ! 座標重みのデータ型. 
                              ! 省略した場合には, 座標のデータ型が
                              ! 使用されます. 
                              ! 
                              ! Data type of weight of the dimension. 
                              ! If this argument is omitted, 
                              ! data type of the dimension is used. 
                              ! 

    character(STRING):: name, longname
    character(TOKEN):: dim_units, dim_xtype
    integer:: dim_size
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoAddWeightReal"
  continue
    call BeginSub(subname, 'dim=<%c>', c1=trim(dim) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name, &           ! (out)
        & size = dim_size, &       ! (out)
        & longname = longname, &   ! (out)
        & units = dim_units, &     ! (out)
        & xtype = dim_xtype )      ! (out)
      if ( trim(dim) == trim(name) ) then
        if ( dim_size /= size(weight) ) then
          stat = GT_EARGSIZEMISMATCH
          cause_c = 'weight'
        end if
        if ( present(units) ) dim_units = units
        if ( present(xtype) ) dim_xtype = xtype
        call HistoryVarinfoCreate( &
          & varinfo = gthst_weights(numwgts + 1), &             ! (out)
          & name = trim(dim) // '_weight', dims = (/ dim /), &  ! (in)
          & longname = 'weight for integration or average in ' // &
          &            trim(longname), &                        ! (in)
          & units = dim_units, xtype = dim_xtype )              ! (in)

        call HistoryAxisAddAttr( &
          & axis = gthst_axes(i), &           ! (inout)
          & attrname = 'gt_calc_weight', &    ! (in)
          & value = trim(dim) // '_weight' )  ! (in)

        allocate( data_weights(numwgts + 1) % a_axis( dim_size ) )
        data_weights(numwgts + 1) % a_axis = weight

        numwgts = numwgts + 1
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = dim
    
999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoAddWeightReal


  subroutine HistoryAutoAddWeightDouble( &
    & dim, weight, &  ! (in)
    & units, xtype &  ! (in) optional
    & )
    !
    ! 座標の重みデータを設定します. 
    !
    ! Set weights of axes. 
    !

    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, &
      & GT_EARGSIZEMISMATCH, HST_ENOAXISNAME, DC_ENOTINIT
    use gt4_history, only: HistoryAxisInquire, HistoryAxisAddAttr, &
      &                    HistoryVarinfoCreate

    implicit none
    character(*), intent(in):: dim
                              ! 座標重みを設定する座標の名称. 
                              !
                              ! ただし, ここで指定するもの
                              ! は, HistoryAutoCreate の *dims*
                              ! 既に指定されていなければなりません.
                              !
                              ! Name of axis to which "weight" are set. 
                              !
                              ! Note that this value must be set 
                              ! as "dims" of "HistoryAutoCreate". 
                              !
    real(DP), intent(in):: weight(:)
                              ! 座標重みデータ. 
                              !
                              ! データ型は整数, 単精度実数型, 
                              ! 倍精度実数型のどれでもかまいません. 
                              ! ただし, ファイルへ出力される際には, 
                              ! xtype もしくは座標データの型へと
                              ! 変換されます. 
                              ! 
                              ! Weight of axis. 
                              ! 
                              ! Integer, single or double precision are 
                              ! acceptable as data type. 
                              ! Note that when this is output to a file, 
                              ! data type is converted into "xtype" or 
                              ! type of the axis. 
                              ! 
    character(*), intent(in), optional:: units
                              ! 座標重みの単位. 
                              ! 省略した場合には, 座標の単位が
                              ! 使用されます. 
                              !
                              ! Units of axis weight.
                              ! If this argument is omitted, 
                              ! unit of the dimension is used. 
                              !
    character(*), intent(in),  optional:: xtype
                              ! 座標重みのデータ型. 
                              ! 省略した場合には, 座標のデータ型が
                              ! 使用されます. 
                              ! 
                              ! Data type of weight of the dimension. 
                              ! If this argument is omitted, 
                              ! data type of the dimension is used. 
                              ! 

    character(STRING):: name, longname
    character(TOKEN):: dim_units, dim_xtype
    integer:: dim_size
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoAddWeightDouble"
  continue
    call BeginSub(subname, 'dim=<%c>', c1=trim(dim) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name, &           ! (out)
        & size = dim_size, &       ! (out)
        & longname = longname, &   ! (out)
        & units = dim_units, &     ! (out)
        & xtype = dim_xtype )      ! (out)
      if ( trim(dim) == trim(name) ) then
        if ( dim_size /= size(weight) ) then
          stat = GT_EARGSIZEMISMATCH
          cause_c = 'weight'
        end if
        if ( present(units) ) dim_units = units
        if ( present(xtype) ) dim_xtype = xtype
        call HistoryVarinfoCreate( &
          & varinfo = gthst_weights(numwgts + 1), &             ! (out)
          & name = trim(dim) // '_weight', dims = (/ dim /), &  ! (in)
          & longname = 'weight for integration or average in ' // &
          &            trim(longname), &                        ! (in)
          & units = dim_units, xtype = dim_xtype )              ! (in)

        call HistoryAxisAddAttr( &
          & axis = gthst_axes(i), &           ! (inout)
          & attrname = 'gt_calc_weight', &    ! (in)
          & value = trim(dim) // '_weight' )  ! (in)

        allocate( data_weights(numwgts + 1) % a_axis( dim_size ) )
        data_weights(numwgts + 1) % a_axis = weight

        numwgts = numwgts + 1
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = dim
    
999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoAddWeightDouble


  subroutine HistoryAutoAddWeightInt( &
    & dim, weight, &  ! (in)
    & units, xtype &  ! (in) optional
    & )
    !
    ! 座標の重みデータを設定します. 
    !
    ! Set weights of axes. 
    !

    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, &
      & GT_EARGSIZEMISMATCH, HST_ENOAXISNAME, DC_ENOTINIT
    use gt4_history, only: HistoryAxisInquire, HistoryAxisAddAttr, &
      &                    HistoryVarinfoCreate

    implicit none
    character(*), intent(in):: dim
                              ! 座標重みを設定する座標の名称. 
                              !
                              ! ただし, ここで指定するもの
                              ! は, HistoryAutoCreate の *dims*
                              ! 既に指定されていなければなりません.
                              !
                              ! Name of axis to which "weight" are set. 
                              !
                              ! Note that this value must be set 
                              ! as "dims" of "HistoryAutoCreate". 
                              !
    integer, intent(in):: weight(:)
                              ! 座標重みデータ. 
                              !
                              ! データ型は整数, 単精度実数型, 
                              ! 倍精度実数型のどれでもかまいません. 
                              ! ただし, ファイルへ出力される際には, 
                              ! xtype もしくは座標データの型へと
                              ! 変換されます. 
                              ! 
                              ! Weight of axis. 
                              ! 
                              ! Integer, single or double precision are 
                              ! acceptable as data type. 
                              ! Note that when this is output to a file, 
                              ! data type is converted into "xtype" or 
                              ! type of the axis. 
                              ! 
    character(*), intent(in), optional:: units
                              ! 座標重みの単位. 
                              ! 省略した場合には, 座標の単位が
                              ! 使用されます. 
                              !
                              ! Units of axis weight.
                              ! If this argument is omitted, 
                              ! unit of the dimension is used. 
                              !
    character(*), intent(in),  optional:: xtype
                              ! 座標重みのデータ型. 
                              ! 省略した場合には, 座標のデータ型が
                              ! 使用されます. 
                              ! 
                              ! Data type of weight of the dimension. 
                              ! If this argument is omitted, 
                              ! data type of the dimension is used. 
                              ! 

    character(STRING):: name, longname
    character(TOKEN):: dim_units, dim_xtype
    integer:: dim_size
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoAddWeightInt"
  continue
    call BeginSub(subname, 'dim=<%c>', c1=trim(dim) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name, &           ! (out)
        & size = dim_size, &       ! (out)
        & longname = longname, &   ! (out)
        & units = dim_units, &     ! (out)
        & xtype = dim_xtype )      ! (out)
      if ( trim(dim) == trim(name) ) then
        if ( dim_size /= size(weight) ) then
          stat = GT_EARGSIZEMISMATCH
          cause_c = 'weight'
        end if
        if ( present(units) ) dim_units = units
        if ( present(xtype) ) dim_xtype = xtype
        call HistoryVarinfoCreate( &
          & varinfo = gthst_weights(numwgts + 1), &             ! (out)
          & name = trim(dim) // '_weight', dims = (/ dim /), &  ! (in)
          & longname = 'weight for integration or average in ' // &
          &            trim(longname), &                        ! (in)
          & units = dim_units, xtype = dim_xtype )              ! (in)

        call HistoryAxisAddAttr( &
          & axis = gthst_axes(i), &           ! (inout)
          & attrname = 'gt_calc_weight', &    ! (in)
          & value = trim(dim) // '_weight' )  ! (in)

        allocate( data_weights(numwgts + 1) % a_axis( dim_size ) )
        data_weights(numwgts + 1) % a_axis = weight

        numwgts = numwgts + 1
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = dim
    
999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoAddWeightInt


  subroutine HistoryAutoPutAxisReal( &
    & dim, array &  ! (in)
    & )
    !
    ! 座標データを設定します. 
    !
    ! Set data of an axis. 
    !

    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, &
      & GT_EARGSIZEMISMATCH, HST_ENOAXISNAME, DC_ENOTINIT
    use gt4_history, only: HistoryAxisInquire, HistoryAxisAddAttr, &
      &                    HistoryVarinfoCreate

    implicit none
    character(*), intent(in):: dim
                              ! 座標の名称. 
                              !
                              ! ただし, ここで指定するもの
                              ! は, HistoryAutoCreate の *dims*
                              ! 既に指定されていなければなりません.
                              !
                              ! Name of axis. 
                              !
                              ! Note that this value must be set 
                              ! as "dims" of "HistoryAutoCreate". 
                              !
    real, intent(in):: array(:)
                              ! 座標データ
                              !
                              ! データ型は整数, 単精度実数型, 
                              ! 倍精度実数型のどれでもかまいません. 
                              ! ただし, ファイルへ出力される際には, 
                              ! HistoryAutoCreate の *xtypes* で指定した
                              ! データ型へ変換されます. 
                              ! 
                              ! Data of axis
                              !
                              ! Integer, single or double precision are 
                              ! acceptable as data type. 
                              ! Note that when this is output to a file, 
                              ! data type is converted into "xtypes" 
                              ! specified in "HistoryAutoCreate"
                              ! 

    character(STRING):: name
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoPutAxisReal"
  continue
    call BeginSub(subname, 'dim=<%c>', c1=trim(dim) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name )            ! (out)
      if ( trim(dim) == trim(name) ) then
        data_axes(i) % a_axis = array
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = dim

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoPutAxisReal


  subroutine HistoryAutoPutAxisDouble( &
    & dim, array &  ! (in)
    & )
    !
    ! 座標データを設定します. 
    !
    ! Set data of an axis. 
    !

    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, &
      & GT_EARGSIZEMISMATCH, HST_ENOAXISNAME, DC_ENOTINIT
    use gt4_history, only: HistoryAxisInquire, HistoryAxisAddAttr, &
      &                    HistoryVarinfoCreate

    implicit none
    character(*), intent(in):: dim
                              ! 座標の名称. 
                              !
                              ! ただし, ここで指定するもの
                              ! は, HistoryAutoCreate の *dims*
                              ! 既に指定されていなければなりません.
                              !
                              ! Name of axis. 
                              !
                              ! Note that this value must be set 
                              ! as "dims" of "HistoryAutoCreate". 
                              !
    real(DP), intent(in):: array(:)
                              ! 座標データ
                              !
                              ! データ型は整数, 単精度実数型, 
                              ! 倍精度実数型のどれでもかまいません. 
                              ! ただし, ファイルへ出力される際には, 
                              ! HistoryAutoCreate の *xtypes* で指定した
                              ! データ型へ変換されます. 
                              ! 
                              ! Data of axis
                              !
                              ! Integer, single or double precision are 
                              ! acceptable as data type. 
                              ! Note that when this is output to a file, 
                              ! data type is converted into "xtypes" 
                              ! specified in "HistoryAutoCreate"
                              ! 

    character(STRING):: name
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoPutAxisDouble"
  continue
    call BeginSub(subname, 'dim=<%c>', c1=trim(dim) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name )            ! (out)
      if ( trim(dim) == trim(name) ) then
        data_axes(i) % a_axis = array
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = dim

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoPutAxisDouble


  subroutine HistoryAutoPutAxisInt( &
    & dim, array &  ! (in)
    & )
    !
    ! 座標データを設定します. 
    !
    ! Set data of an axis. 
    !

    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, &
      & GT_EARGSIZEMISMATCH, HST_ENOAXISNAME, DC_ENOTINIT
    use gt4_history, only: HistoryAxisInquire, HistoryAxisAddAttr, &
      &                    HistoryVarinfoCreate

    implicit none
    character(*), intent(in):: dim
                              ! 座標の名称. 
                              !
                              ! ただし, ここで指定するもの
                              ! は, HistoryAutoCreate の *dims*
                              ! 既に指定されていなければなりません.
                              !
                              ! Name of axis. 
                              !
                              ! Note that this value must be set 
                              ! as "dims" of "HistoryAutoCreate". 
                              !
    integer, intent(in):: array(:)
                              ! 座標データ
                              !
                              ! データ型は整数, 単精度実数型, 
                              ! 倍精度実数型のどれでもかまいません. 
                              ! ただし, ファイルへ出力される際には, 
                              ! HistoryAutoCreate の *xtypes* で指定した
                              ! データ型へ変換されます. 
                              ! 
                              ! Data of axis
                              !
                              ! Integer, single or double precision are 
                              ! acceptable as data type. 
                              ! Note that when this is output to a file, 
                              ! data type is converted into "xtypes" 
                              ! specified in "HistoryAutoCreate"
                              ! 

    character(STRING):: name
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoPutAxisInt"
  continue
    call BeginSub(subname, 'dim=<%c>', c1=trim(dim) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name )            ! (out)
      if ( trim(dim) == trim(name) ) then
        data_axes(i) % a_axis = array
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = dim

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoPutAxisInt


  subroutine HistoryAutoAddVariable1( &
    & varname, dims, longname, units, &      ! (in)
    & xtype, average, &                      ! (in) optional
    & file &                                 ! (in) optional
!!$    & origin, terminus, interval, &           ! (in) optional
!!$    & slice_start, slice_end, slice_stride, & ! (in) optional
!!$    & space_average, &                        ! (in) optional
!!$    & newfile_interval &                      ! (in) optional
    & )
    !
    ! ヒストリデータ出力するための変数登録を行います. 
    !
    ! HistoryAutoProgress を呼ぶ前にこのサブルーチンを使用してください. 
    !
    ! Register variables for history data output
    !
    ! Use this subroutine before "HistoryAutoProgress" is called. 
    !

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

    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, HST_EVARINUSE, &
      & HST_EALREADYPROGRESS, DC_ENOTINIT
    use dc_message, only: MessageNotify
    use netcdf_f77, only: NF_EMAXVARS
    use gt4_history, only: HistoryVarinfoCreate, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoSetValidName, &
      & HstNmlInfoDefineMode, HstNmlInfoReDefine, HstNmlInfoEndDefine, &
      & HstNmlInfoAdd, HstNmlInfoInquire

    ! 宣言文 ; Declaration statements
    !
    implicit none
    character(*), intent(in):: varname
                              ! 変数名. Variable name
    character(*), intent(in):: dims(:)
                              ! 変数が依存する次元の名前. 
                              ! 時間の次元は配列の最後に指定すること. 
                              !
                              ! Names of dependency dimensions of a variable. 
                              ! Dimension of time must be specified 
                              ! to last of an array. 
    character(*), intent(in):: longname
                              ! 変数の記述的名称. 
                              ! 
                              ! Descriptive name of a variable
    character(*), intent(in):: units
                              ! 変数の単位. 
                              ! 
                              ! Units of a variable
    character(*), intent(in), optional:: xtype
                              ! 
                              ! 変数のデータ型
                              ! 
                              ! デフォルトは float (単精度実数型) であ
                              ! る. 有効なのは, double (倍精度実数型),
                              ! int (整数型) である. 指定しない 場合や, 
                              ! 無効な型を指定した場合には, float (単
                              ! 精度実数型) となる.
                              ! 
                              ! Data types of dimensions specified 
                              ! with "dims". 
                              !
                              ! Default value is "float" (single precision). 
                              ! Other valid values are 
                              ! "double" (double precision), 
                              ! "int" (integer). 
                              ! If no value or invalid value is specified, 
                              ! "float" is applied. 
                              !
    logical, intent(in), optional:: average
                              ! 
                              ! 出力データを時間平均する場合には 
                              ! .true. を与えます. デフォルトは 
                              ! .false. です.
                              ! 
                              ! If output data is averaged, specify
                              ! ".true.". Default is ".false.".
                              ! 
    character(*), intent(in), optional:: file
                              ! 出力ファイル名. 
                              ! Output file name. 

!!$    real, intent(in), optional:: slice_start(:)
!!$                              ! 空間方向の開始点. 
!!$                              !
!!$                              ! 省略した場合, 座標データの開始点が設定されます.
!!$                              ! 
!!$                              ! Start points of spaces. 
!!$                              ! 
!!$                              ! If this argument is omitted, 
!!$                              ! start points of dimensions are set. 
!!$                              ! 
!!$    real, intent(in), optional:: slice_end(:)
!!$                              ! 空間方向の終了点. 
!!$                              !
!!$                              ! 省略した場合, 座標データの終了点が設定されます.
!!$                              ! 
!!$                              ! End points of spaces. 
!!$                              ! 
!!$                              ! If this argument is omitted, 
!!$                              ! End points of dimensions are set. 
!!$                              ! 
!!$    integer, intent(in), optional:: slice_stride(:)
!!$                              ! 空間方向の刻み幅. 
!!$                              !
!!$                              ! 省略した場合, 1 が設定されます.
!!$                              ! 
!!$                              ! Strides of spaces
!!$                              ! 
!!$                              ! If this argument is omitted, 
!!$                              ! 1 is set. 
!!$                              ! 
!!$    logical, intent(in), optional:: average(:)
!!$                              ! 平均化のフラグ. 
!!$                              !
!!$                              ! .true. が指定される座標に対して平均化を
!!$                              ! 行います. 
!!$                              ! 省略した場合, .false. が設定されます.
!!$                              ! 
!!$                              ! Flag of average. 
!!$                              ! 
!!$                              ! Axes specified .true. are averaged. 
!!$                              ! If this argument is omitted, 
!!$                              ! .false. is set. 
!!$                              ! 
!!$    real, intent(in), optional:: origin
!!$                              ! 出力開始時刻. 
!!$                              !
!!$                              ! 省略した場合, 自動的に current_time の値が
!!$                              ! 設定されます.
!!$                              ! 
!!$                              ! Start time of output. 
!!$                              !
!!$                              ! If this argument is omitted, 
!!$                              ! a value of "current_time" is specified
!!$                              ! automatically. 
!!$                              ! 
!!$    real, intent(in), optional:: terminus
!!$                              ! 出力終了時刻. 
!!$                              !
!!$                              ! 省略した場合, 数値モデルの実行が終了するまで
!!$                              ! 出力を行います. 
!!$                              ! 
!!$                              ! End time of output. 
!!$                              !
!!$                              ! If this argument is omitted, 
!!$                              ! output is continued until a numerical model
!!$                              ! is finished. 
!!$                              ! 
!!$    real, intent(in), optional:: interval
!!$                              ! 出力時間間隔. 
!!$                              !
!!$                              ! 省略した場合, 
!!$                              ! 自動的に delta_time の値が設定されます.
!!$                              !
!!$                              ! Interval of output time. 
!!$                              !
!!$                              ! If this argument is omitted, 
!!$                              ! a value of "delta_time" is specified 
!!$                              ! automatically. 
!!$                              ! 
!!$    real, intent(in), optional:: newfile_interval
!!$                              ! ファイル分割時間間隔. 
!!$                              !
!!$                              ! 省略した場合, 
!!$                              ! 時間方向へのファイル分割を行いません. 
!!$                              !
!!$                              ! Interval of time of separation of a file. 
!!$                              !
!!$                              ! If this argument is omitted, 
!!$                              ! a files is not separated in time direction.
!!$                              ! 

    ! 作業変数
    ! Work variables
    !
    logical:: define_mode, varname_not_found
    integer:: stat, i
    character(STRING):: name, cause_c
    character(*), parameter:: subname = "HistoryAutoAddVariable1"
  continue
    call BeginSub(subname, version = version)
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 既に HistoryAutoProgress が呼ばれていたらエラー
    ! Error is occurred if "HistoryAutoProgress" is called already
    !
    if ( once_progressed ) then
      call MessageNotify( 'W', subname, &
        & '"HistoryAutoAddVariable" (varname = %c) must be called before "HistoryAutoProgress"', &
        & c1 = trim(varname) )
      stat = HST_EALREADYPROGRESS
      cause_c = 'HistoryAutoProgress'
      goto 999
    end if

    ! 重複のチェック
    ! Check duplication
    !
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) then
        stat = HST_EVARINUSE
        cause_c = varname
        goto 999
      end if
    end do

    ! 変数の数の限界チェック
    ! Check limit of number of variables
    !
    if ( numvars + 1 > NF_MAX_VARS ) then
      stat = NF_EMAXVARS
      goto 999
    end if

    ! 全ての変数を出力する際には, ここで登録
    ! Register here if all variables are output
    !
    if ( all_output_save ) then
      call HstNmlInfoInquire( &
        & gthstnml = gthstnml, name = varname, &  ! (in)
        & err = varname_not_found )               ! (out) optional
      if ( varname_not_found ) then
        define_mode = HstNmlInfoDefineMode( gthstnml )
        if ( .not. define_mode ) call HstNmlInfoReDefine( gthstnml ) ! (inout)
        call HstNmlInfoAdd( &
          & gthstnml       = gthstnml, &                ! (inout)
          & name           = varname, &                 ! (in) optional
          & file           = file, &                    ! (in) optional
          & precision      = xtype, &                   ! (in) optional
!!$          & origin_value   = origin, &                  ! (in) optional
!!$          & terminus_value = terminus, &                ! (in) optional
!!$          & interval_value = interval, &                ! (in) optional
!!$          & slice_start    = slice_start, &             ! (in) optional
!!$          & slice_end      = slice_end, &               ! (in) optional
!!$          & slice_stride   = slice_stride, &            ! (in) optional
!!$          & space_average  = space_average, &           ! (in) optional
!!$          & newfile_interval_value = newfile_interval, & ! (in) optional
          & time_average   = average )                  ! (in) optional
        if ( .not. define_mode ) call HstNmlInfoEndDefine( gthstnml ) ! (inout)
      end if
    end if

    ! 変数名の有効性を設定
    ! Set validation of the variable name
    !
    call HstNmlInfoSetValidName( &
      & gthstnml = gthstnml, name = varname ) ! (in)

    ! 登録 ; Register
    !
    call HistoryVarinfoCreate( &
      & varinfo = gthst_vars(numvars + 1), &  ! (out)
      & name = varname, dims = dims, &        ! (in)
      & longname = longname, &                ! (in)
      & units = units, xtype = xtype )        ! (in)

    numvars = numvars + 1

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname, 'stat=%d', i = (/stat/) )
  end subroutine HistoryAutoAddVariable1


  subroutine HistoryAutoAddAttrChar0( &
    & varname, attrname, value &                 ! (in)
    & )
    !
                        !
    ! 座標変数および座標重み変数に属性を付加します. 
    ! このサブルーチンを用いる前に, HistoryAutoCreate による初期設定が
    ! 必要です.
    ! 
    ! * 座標変数については, HistoryAutoCreate の "dims" に与えられた
    !   もののみ指定可能です. 
    !
    ! * 座標重み変数については, HistoryAutoAddWeight で与えられた
    !   もののみ指定可能です. 
    !
    ! * *HistoryAutoAddAttr* は複数のサブルーチンの総称名です. *value* 
    !   にはいくつかの型を与えることが可能です.
    !   下記のサブルーチンを参照ください.
    !
    ! Add attributes axes or weights of axes. 
    ! Initialization by "HistoryAutoCreate" is needed 
    ! before use of this subroutine. 
    ! 
    ! * About axes, "dims" specified by "HistoryAutoCreate" can be
    !   specified. 
    !
    ! * About weights of axes, "dims" specified by "HistoryAutoAddWeight" 
    !   can be specified. 
    !
    ! * "HistoryAutoAddAttr" is a generic name of multiple subroutines. 
    !   Then some data type can be specified to "value". 
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, HST_ENOAXISNAME, DC_ENOTINIT
    use dc_string, only: toChar
    use gt4_history, only: HistoryAxisAddAttr, HistoryAxisInquire, &
      &                    HistoryVarinfoAddAttr, HistoryVarinfoInquire
    implicit none
    character(*), intent(in):: varname
                                                  ! 変数の名前.
                              !
                              ! ここで指定するものは,
                              ! HistoryAutoCreate の *dims* ,
                              ! または HistoryAutoAddWeight の
                              ! *varname* で既に指定されてい
                              ! なければなりません.
                              ! 
                              ! Name of a variable. 
                              !
                              ! This must be specified with *dims*
                              ! in HistoryAutoCreate, or 
                              ! *varname* in "HistoryAutoAddWeight". 
                              ! 
                    
    character(*), intent(in):: attrname
                                                  ! 属性の名前. 
                              ! Name of an attribute. 
                    
    character(*), intent(in):: value
                                                  ! 属性の値. 
                              ! Value of an attribute. 
                    

    character(STRING):: name
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoAddAttrChar0"
  continue
    call BeginSub(subname, &
      & 'varname=<%c> attrname=<%c>, value=<%c>', &
      & c1=trim(varname), c2=trim(attrname), c3=trim(value))
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name )            ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryAxisAddAttr( &
          & axis = gthst_axes(i), &              ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    do i = 1, numwgts
      call HistoryVarinfoInquire( &
        & varinfo = gthst_weights(i), &  ! (in)
        & name = name )                  ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryVarinfoAddAttr( &
          & varinfo = gthst_weights(i), &        ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = varname

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoAddAttrChar0


  subroutine HistoryAutoAddAttrLogical0( &
    & varname, attrname, value &                 ! (in)
    & )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, HST_ENOAXISNAME, DC_ENOTINIT
    use dc_string, only: toChar
    use gt4_history, only: HistoryAxisAddAttr, HistoryAxisInquire, &
      &                    HistoryVarinfoAddAttr, HistoryVarinfoInquire
    implicit none
    character(*), intent(in):: varname
                    
    character(*), intent(in):: attrname
                    
    logical, intent(in):: value
                    

    character(STRING):: name
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoAddAttrLogical0"
  continue
    call BeginSub(subname, &
      & 'varname=<%c> attrname=<%c>, value=<%c>', &
      & c1=trim(varname), c2=trim(attrname), c3=trim(toChar(value)))
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name )            ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryAxisAddAttr( &
          & axis = gthst_axes(i), &              ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    do i = 1, numwgts
      call HistoryVarinfoInquire( &
        & varinfo = gthst_weights(i), &  ! (in)
        & name = name )                  ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryVarinfoAddAttr( &
          & varinfo = gthst_weights(i), &        ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = varname

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoAddAttrLogical0


  subroutine HistoryAutoAddAttrInt0( &
    & varname, attrname, value &                 ! (in)
    & )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, HST_ENOAXISNAME, DC_ENOTINIT
    use dc_string, only: toChar
    use gt4_history, only: HistoryAxisAddAttr, HistoryAxisInquire, &
      &                    HistoryVarinfoAddAttr, HistoryVarinfoInquire
    implicit none
    character(*), intent(in):: varname
                    
    character(*), intent(in):: attrname
                    
    integer, intent(in):: value
                    

    character(STRING):: name
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoAddAttrInt0"
  continue
    call BeginSub(subname, &
      & 'varname=<%c> attrname=<%c>, value=<%c>', &
      & c1=trim(varname), c2=trim(attrname), c3=trim(toChar(value)))
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name )            ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryAxisAddAttr( &
          & axis = gthst_axes(i), &              ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    do i = 1, numwgts
      call HistoryVarinfoInquire( &
        & varinfo = gthst_weights(i), &  ! (in)
        & name = name )                  ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryVarinfoAddAttr( &
          & varinfo = gthst_weights(i), &        ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = varname

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoAddAttrInt0


  subroutine HistoryAutoAddAttrInt1( &
    & varname, attrname, value &                 ! (in)
    & )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, HST_ENOAXISNAME, DC_ENOTINIT
    use dc_string, only: toChar
    use gt4_history, only: HistoryAxisAddAttr, HistoryAxisInquire, &
      &                    HistoryVarinfoAddAttr, HistoryVarinfoInquire
    implicit none
    character(*), intent(in):: varname
                    
    character(*), intent(in):: attrname
                    
    integer, intent(in):: value(:)
                    

    character(STRING):: name
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoAddAttrInt1"
  continue
    call BeginSub(subname, &
      & 'varname=<%c> attrname=<%c>, value=<%c>', &
      & c1=trim(varname), c2=trim(attrname), c3=trim(toChar(value)))
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name )            ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryAxisAddAttr( &
          & axis = gthst_axes(i), &              ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    do i = 1, numwgts
      call HistoryVarinfoInquire( &
        & varinfo = gthst_weights(i), &  ! (in)
        & name = name )                  ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryVarinfoAddAttr( &
          & varinfo = gthst_weights(i), &        ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = varname

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoAddAttrInt1


  subroutine HistoryAutoAddAttrReal0( &
    & varname, attrname, value &                 ! (in)
    & )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, HST_ENOAXISNAME, DC_ENOTINIT
    use dc_string, only: toChar
    use gt4_history, only: HistoryAxisAddAttr, HistoryAxisInquire, &
      &                    HistoryVarinfoAddAttr, HistoryVarinfoInquire
    implicit none
    character(*), intent(in):: varname
                    
    character(*), intent(in):: attrname
                    
    real, intent(in):: value
                    

    character(STRING):: name
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoAddAttrReal0"
  continue
    call BeginSub(subname, &
      & 'varname=<%c> attrname=<%c>, value=<%c>', &
      & c1=trim(varname), c2=trim(attrname), c3=trim(toChar(value)))
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name )            ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryAxisAddAttr( &
          & axis = gthst_axes(i), &              ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    do i = 1, numwgts
      call HistoryVarinfoInquire( &
        & varinfo = gthst_weights(i), &  ! (in)
        & name = name )                  ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryVarinfoAddAttr( &
          & varinfo = gthst_weights(i), &        ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = varname

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoAddAttrReal0


  subroutine HistoryAutoAddAttrReal1( &
    & varname, attrname, value &                 ! (in)
    & )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, HST_ENOAXISNAME, DC_ENOTINIT
    use dc_string, only: toChar
    use gt4_history, only: HistoryAxisAddAttr, HistoryAxisInquire, &
      &                    HistoryVarinfoAddAttr, HistoryVarinfoInquire
    implicit none
    character(*), intent(in):: varname
                    
    character(*), intent(in):: attrname
                    
    real, intent(in):: value(:)
                    

    character(STRING):: name
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoAddAttrReal1"
  continue
    call BeginSub(subname, &
      & 'varname=<%c> attrname=<%c>, value=<%c>', &
      & c1=trim(varname), c2=trim(attrname), c3=trim(toChar(value)))
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name )            ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryAxisAddAttr( &
          & axis = gthst_axes(i), &              ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    do i = 1, numwgts
      call HistoryVarinfoInquire( &
        & varinfo = gthst_weights(i), &  ! (in)
        & name = name )                  ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryVarinfoAddAttr( &
          & varinfo = gthst_weights(i), &        ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = varname

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoAddAttrReal1


  subroutine HistoryAutoAddAttrDouble0( &
    & varname, attrname, value &                 ! (in)
    & )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, HST_ENOAXISNAME, DC_ENOTINIT
    use dc_string, only: toChar
    use gt4_history, only: HistoryAxisAddAttr, HistoryAxisInquire, &
      &                    HistoryVarinfoAddAttr, HistoryVarinfoInquire
    implicit none
    character(*), intent(in):: varname
                    
    character(*), intent(in):: attrname
                    
    real(DP), intent(in):: value
                    

    character(STRING):: name
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoAddAttrDouble0"
  continue
    call BeginSub(subname, &
      & 'varname=<%c> attrname=<%c>, value=<%c>', &
      & c1=trim(varname), c2=trim(attrname), c3=trim(toChar(value)))
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name )            ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryAxisAddAttr( &
          & axis = gthst_axes(i), &              ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    do i = 1, numwgts
      call HistoryVarinfoInquire( &
        & varinfo = gthst_weights(i), &  ! (in)
        & name = name )                  ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryVarinfoAddAttr( &
          & varinfo = gthst_weights(i), &        ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = varname

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoAddAttrDouble0


  subroutine HistoryAutoAddAttrDouble1( &
    & varname, attrname, value &                 ! (in)
    & )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, HST_ENOAXISNAME, DC_ENOTINIT
    use dc_string, only: toChar
    use gt4_history, only: HistoryAxisAddAttr, HistoryAxisInquire, &
      &                    HistoryVarinfoAddAttr, HistoryVarinfoInquire
    implicit none
    character(*), intent(in):: varname
                    
    character(*), intent(in):: attrname
                    
    real(DP), intent(in):: value(:)
                    

    character(STRING):: name
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoAddAttrDouble1"
  continue
    call BeginSub(subname, &
      & 'varname=<%c> attrname=<%c>, value=<%c>', &
      & c1=trim(varname), c2=trim(attrname), c3=trim(toChar(value)))
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    do i = 1, numdims
      call HistoryAxisInquire( &
        & axis = gthst_axes(i), &  ! (in)
        & name = name )            ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryAxisAddAttr( &
          & axis = gthst_axes(i), &              ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    do i = 1, numwgts
      call HistoryVarinfoInquire( &
        & varinfo = gthst_weights(i), &  ! (in)
        & name = name )                  ! (out)
      if ( trim(varname) == trim(name) ) then
        call HistoryVarinfoAddAttr( &
          & varinfo = gthst_weights(i), &        ! (inout)
          & attrname = attrname, value = value ) ! (in)
        goto 999
      end if
    end do

    stat = HST_ENOAXISNAME
    cause_c = varname

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HistoryAutoAddAttrDouble1


  subroutine HistoryAutoPutReal0( &
    & varname, value, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real, intent(in):: value
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutReal0"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & (/value/), & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutReal0


  subroutine HistoryAutoPutReal1( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                                        
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                                        
    real, intent(in):: array(:)
                                        
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutReal1"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutReal1


  subroutine HistoryAutoPutReal2( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real, intent(in):: array(:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutReal2"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutReal2


  subroutine HistoryAutoPutReal3( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real, intent(in):: array(:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutReal3"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutReal3


  subroutine HistoryAutoPutReal4( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real, intent(in):: array(:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutReal4"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutReal4


  subroutine HistoryAutoPutReal5( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real, intent(in):: array(:,:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutReal5"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutReal5


  subroutine HistoryAutoPutReal6( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real, intent(in):: array(:,:,:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutReal6"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutReal6


  subroutine HistoryAutoPutReal7( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real, intent(in):: array(:,:,:,:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutReal7"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutReal7


  subroutine HistoryAutoPutDouble0( &
    & varname, value, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real(DP), intent(in):: value
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutDouble0"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & (/value/), & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutDouble0


  subroutine HistoryAutoPutDouble1( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                                            !
    ! データの出力を行います.
    ! このサブルーチンを用いる前に, "HistoryAutoCreate"
    ! による初期設定が必要です.
    !
    ! *varname* は HistoryAutoAddVariable で指定されている必要があります. 
    !
    ! *HistoryAutoPut* は複数のサブルーチンの総称名です. *array* には
    ! 0 〜 7 次元のデータを与えることが可能です. 
    ! (下記のサブルーチンを参照ください).
    ! また, 整数, 単精度実数, 倍精度実数を与えることが可能です. 
    ! ただし, 0 次元のデータを与える際の引数キーワードは
    ! *value* を用いてください.
    !
    ! Output data. 
    ! Initialization by "HistoryAutoCreate" is needed 
    ! before use of this subroutine. 
    ! 
    ! "varname" must be specified by "HistoryAutoAddVariable". 
    !
    ! "HistoryAutoPut" is a generic name of multiple subroutines. 
    ! Then 0 -- 7 dimensional data can be given to "array". 
    ! (See bellow subroutines). 
    ! And, integer, sinble or double precision can be given. 
    ! However, if 0 dimensional data is given, use "value" as a 
    ! keyword argument. 
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                                                                      ! 変数の名前. 
                              !
                              ! ただし, ここで指定するものは, 
                              ! HistoryAutoAddVariable の
                              ! *varname* で既に指定されてい
                              ! なければなりません. 
                              !
                              ! Name of a variable. 
                              !
                              ! This must be specified  
                              ! *varname* in "HistoryAutoAddVariable". 
                    
    real(DP), intent(in):: array(:)
                                                                      ! 出力データ. 
                              !
                              ! データ型は整数, 単精度実数型, 
                              ! 倍精度実数型のどれでもかまいません. 
                              ! ただし, ファイルへ出力される際には, 
                              ! HistoryAutoAddVariable の *xtypes* で指定した
                              ! データ型へ変換されます. 
                              ! 
                              ! Output data. 
                              !
                              ! Integer, single or double precision are 
                              ! acceptable as data type. 
                              ! Note that when this is output to a file, 
                              ! data type is converted into "xtype" 
                              ! specified in "HistoryAutoAddVariable"
                              ! 
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutDouble1"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutDouble1


  subroutine HistoryAutoPutDouble2( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real(DP), intent(in):: array(:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutDouble2"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutDouble2


  subroutine HistoryAutoPutDouble3( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real(DP), intent(in):: array(:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutDouble3"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutDouble3


  subroutine HistoryAutoPutDouble4( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real(DP), intent(in):: array(:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutDouble4"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutDouble4


  subroutine HistoryAutoPutDouble5( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real(DP), intent(in):: array(:,:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutDouble5"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutDouble5


  subroutine HistoryAutoPutDouble6( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real(DP), intent(in):: array(:,:,:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutDouble6"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutDouble6


  subroutine HistoryAutoPutDouble7( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    real(DP), intent(in):: array(:,:,:,:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutDouble7"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutDouble7


  subroutine HistoryAutoPutInt0( &
    & varname, value, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    integer, intent(in):: value
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutInt0"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & (/value/), & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutInt0


  subroutine HistoryAutoPutInt1( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                                        
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                                        
    integer, intent(in):: array(:)
                                        
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutInt1"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutInt1


  subroutine HistoryAutoPutInt2( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    integer, intent(in):: array(:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutInt2"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutInt2


  subroutine HistoryAutoPutInt3( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    integer, intent(in):: array(:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutInt3"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutInt3


  subroutine HistoryAutoPutInt4( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    integer, intent(in):: array(:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutInt4"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutInt4


  subroutine HistoryAutoPutInt5( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    integer, intent(in):: array(:,:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutInt5"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutInt5


  subroutine HistoryAutoPutInt6( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    integer, intent(in):: array(:,:,:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutInt6"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutInt6


  subroutine HistoryAutoPutInt7( &
    & varname, array, &  ! (in)
    & err &                             ! (out) optional
    &  )
    !
                    
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, GT_EARGSIZEMISMATCH, &
      & HST_EBADVARNAME, DC_ENOTINIT
    use dc_date, only: EvalbyUnit, EvalSec, operator(-)
    use gt4_history, only: GT_HISTORY, HistoryPut, HistoryInitialized, &
      & HistoryAddVariable, HistoryInquire, HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoOutputValid, &
      & HstNmlInfoAssocGtHist, HstNmlInfoInquire, HstNmlInfoEndDefine, &
      & HstNmlInfoDefineMode
    implicit none
    character(*), intent(in):: varname
                    
    integer, intent(in):: array(:,:,:,:,:,:,:)
                    
    logical, intent(out), optional:: err
                              ! 例外処理用フラグ. 
                              ! デフォルトでは, この手続き内でエラーが
                              ! 生じた場合, プログラムは強制終了します. 
                              ! 引数 *err* が与えられる場合, 
                              ! プログラムは強制終了せず, 代わりに
                              ! *err* に .true. が代入されます. 
                              !
                              ! Exception handling flag. 
                              ! By default, when error occur in 
                              ! this procedure, the program aborts. 
                              ! If this *err* argument is given, 
                              ! .true. is substituted to *err* and 
                              ! the program does not abort. 


    type(GT_HISTORY), pointer:: gthist =>null()
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module

    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: time
    character(TOKEN):: name
    logical:: var_not_register
    type(GT_HISTORY_VARINFO), pointer:: varinfo_list(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c

    character(*), parameter:: subname = "HistoryAutoPutInt7"
  continue
    call BeginSub(subname, 'varname=%c', c1 = trim(varname) )
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 定義モードからデータモードへ
    ! Transit from define mode to data mode
    !
    if ( HstNmlInfoDefineMode( gthstnml ) ) then 
      call HstNmlInfoEndDefine( gthstnml ) ! (inout)
    end if

    ! 未定義の変数かどうかをチェック
    ! Check undefined variables
    !
    var_not_register = .true.
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    if ( var_not_register ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! GT_HISTORY 変数の取得
    ! Get "GT_HISTORY" variable
    !
    call HstNmlInfoAssocGtHist( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & history = gthist )                      ! (out)

    ! ファイルが未作成の場合はファイル作成
    ! File is created if file is not created yet
    !
    ! ※ 複数の変数を一つのファイルに登録する場合はこれではうまく行かない
    !    他にも以下の判定が必要. 
    !    * terminus より前か (出力しない)
    !    * origin より後ろか (出力しない)
    !    * newfile_interval のステップ数にヒットする時, 
    !      (一旦閉じて, 再度出力)
    !
    if ( .not. HistoryInitialized( gthist ) ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力ファイルに変数登録されていない場合には登録
    ! If the variable is not registered in the output file
    !
    ! ※ たぶん毎回呼ぶと速度が非常に落ちるのでは...
    !
    call HistoryInquire( history = gthist, &  ! (in)
      & varinfo = varinfo_list )              ! (out)
    var_not_register = .true.
    do i = 1, size( varinfo_list )
      call HistoryVarinfoInquire( &
        & varinfo = varinfo_list(i), &  ! (in)
        & name = name )                 ! (out)
      if ( trim(varname) == trim(name) ) var_not_register = .false.
    end do
    deallocate( varinfo_list )
    if ( var_not_register ) then
      call HstFileCreate( gthist, & ! (inout)
        & varname )                 ! (in)
    end if

    ! 出力のタイミングのチェック
    ! Check output timing 
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, &           ! (in)
      & name = varname, &                ! (in)
      & interval_unit = interval_unit )  ! (out)

    time = real( EvalbyUnit( current_difftime, interval_unit ) )

    ! 空間平均
    ! Spatial average
    !


    ! 空間切り出し情報の取得
    ! Get information of slice of spaces
    !
!!$    range = slice_to_range( gthstnml % slice_start, &
!!$      &                     gthstnml % slice_end, &
!!$      &                     gthstnml % slice_stride )
!!$    または, 始めから gthstnml に range ごと入れておく. 
!!$
!!$

    ! 出力
    ! OutPut
    !
    call HistoryPut( &
      & varname, &             ! (in)
      & array, & ! (in)
!!$      & range = range, &       ! (in) optional
      & time = time, &         ! (in) optional
      & history = gthist )     ! (inout) optional

    nullify( gthist )

999 continue
    call StoreError(stat, subname, cause_c = cause_c, err = err)
    call EndSub(subname)
  end subroutine HistoryAutoPutInt7


  subroutine HistoryAutoProgress
    !
    ! 時刻を進めます. 
    ! 
    ! 時刻は HistoryAutoCreate の delta_time で指定された分
    ! (省略した場合は 1.0) だけ進みます. 
    !
    ! HistoryAutoAddVariable はサブルーチンを呼ぶ前に, 
    ! 使用してください. 
    !
    ! 一度目に呼んだ際には, 以下の事を行います. 
    ! 
    ! * NAMELIST から読み込んだ値に無効なものが存在したかどうかをチェック
    ! * HistoryAutoAddVariable で登録した変数群を印字
    !
    !
    ! Progress time. 
    !
    ! Time is progressed to the extent that specified with
    ! "delta_time" of "HistoryAutoCreate" (1.0 when omitting
    ! "delta_time").
    !
    ! Use "HistoryAutoAddVariable" before this subroutine is called. 
    !
    ! When this subroutine called at first, following things are done.
    ! 
    ! * Check that invalid values are loaded from NAMELIST or not. 
    ! * Print registered variables by "HistoryAutoAddVariable"
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, HST_EBADVARNAME, DC_ENOTINIT
    use dc_message, only: MessageNotify
    use dc_date, only: operator(*), operator(+)
    use dc_string, only: JoinChar
    use gt4_history, only: HistoryVarinfoInquire
    use gt4_history_nmlinfo, only: HstNmlInfoAllNameValid

    implicit none
    logical:: allvar_invalid
                              ! 無効な変数名のチェックフラグ. 
                              ! Check flag of invalid variable names. 

    integer, parameter:: names_limit = 100
    character(names_limit):: names_invalid
                              ! 無効な変数名. 
                              ! Invalid variable names. 

    character(STRING):: name, units, longname, var_info_str
    character(TOKEN), pointer:: dims(:) =>null()
    integer:: stat, i
    character(STRING):: cause_c
    character(*), parameter:: subname = "HistoryAutoProgress"
  continue
    call BeginSub(subname)
    stat = DC_NOERR
    cause_c = ""

    ! 初期設定チェック
    ! Check initialization
    !
    if ( .not. initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'gt4_historyauto'
      goto 999
    end if

    ! 無効な変数名のチェック (初回のみ)
    ! Check invalid variable names (at only first time)
    !
    if ( Nstep == 0 ) then
      call HstNmlInfoAllNameValid( &
        & gthstnml = gthstnml, &               ! (inout)
        & invalid = allvar_invalid, names = names_invalid ) ! (out)

      if ( len_trim(names_invalid) > (names_limit - 5)  ) then
        names_invalid = names_invalid(1:names_limit - 5) // ' ....'
      end if

      if ( allvar_invalid ) then
        stat = HST_EBADVARNAME
        cause_c = names_invalid
        call MessageNotify( 'W', subname, &
          & 'names "%c" from NAMELIST "gt4_historyauto_nml" are invalid.', &
          & c1 = trim(names_invalid) )
        goto 999
      end if

    end if

    ! 登録された変数の印字 (初回のみ)
    ! Print registered variables (at only first time)
    !
    if ( Nstep == 0 ) then
      call MessageNotify( 'M', sub_sname, '-------------------------------------------' )
      call MessageNotify( 'M', sub_sname, '----- Registered variables for output -----' )
      call MessageNotify( 'M', sub_sname, '-------------------------------------------' )

      do i = 1, numvars
        call HistoryVarinfoInquire( &
          & varinfo = gthst_vars(i), &    ! (in)
          & name = name, &                ! (out) optional
          & dims = dims, &                ! (out) optional
          & longname = longname, &        ! (out) optional
          & units = units )               ! (out) optional

        var_info_str = trim( longname ) // ' [' // &
          &            trim( units ) // '] {' // &
          &            trim( JoinChar( dims, ',' ) ) // '}'
        deallocate( dims )

        call MessageNotify( 'M', sub_sname, '  %c  (%c)', &
          & c1 = trim(name), c2 = trim(var_info_str) )

      end do
      call MessageNotify( 'M', sub_sname, '-----' )
    end if

    ! 時刻を進める
    ! Progress time
    !
    Nstep = Nstep + 1
    current_difftime = start_difftime + delta_difftime * Nstep

    if ( .not. once_progressed ) once_progressed = .true.

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname, 'stat=%d', i = (/stat/) )
  end subroutine HistoryAutoProgress


  !-------------------------------------------------------------------
  !------------------ 内部サブルーチン -------------------------------
  !-------------------------------------------------------------------

  subroutine HstFileCreate( &
    & gthist, & ! (inout)
    & varname & ! (in)
    & )
    !
    ! ファイル作成用内部サブルーチン
    !
    ! Internal subroutine for creation of files
    !
    use dc_trace, only: BeginSub, EndSub
    use dc_error, only: StoreError, DC_NOERR, HST_EBADVARNAME
    use dc_date_types, only: DC_DIFFTIME
    use dc_date, only: DCDiffTimeCreate, EvalbyUnit
    use gt4_history_nmlinfo, only: &
      & HstNmlInfoOutputValid, HstNmlInfoInquire
    use gt4_history, only: GT_HISTORY, &
      & HistoryCreate, HistoryAddVariable, HistoryAddAttr, &
      & HistoryInitialized, HistoryPut, &
      & HistoryVarinfoInquire, HistoryVarinfoCreate, &
      & HistoryAxisInquire

    implicit none
    type(GT_HISTORY), intent(inout):: gthist
                              ! gt4_history モジュール用構造体. 
                              ! Derived type for "gt4_history" module
    character(*), intent(in):: varname
                              ! 変数の名前. 
                              ! Variable name

    real:: interval_value
                              ! ヒストリデータの出力間隔の数値. 
                              ! Numerical value for interval of history data output
    character(TOKEN):: interval_unit
                              ! ヒストリデータの出力間隔の単位. 
                              ! Unit for interval of history data output
    real:: origin_value
                              ! ヒストリデータの出力開始時刻の数値. 
                              ! Numerical value for start time of history data output
    character(TOKEN):: origin_unit
                              ! ヒストリデータの出力開始時刻の単位. 
                              ! Unit for start time of history data output

    type(DC_DIFFTIME):: origin_difftime
    character(TOKEN):: precision
                              ! ヒストリデータの精度. 
                              ! Precision of history data
    logical:: time_average
                              ! 出力データの時間平均フラグ. 
                              ! Flag for time average of output data

    character(STRING):: file
                              ! 出力ファイル名. 
                              ! Output file name. 
    character(TOKEN):: time_name
                              ! 時刻次元の名称. 
                              ! Name of time dimension
    integer:: stat, i, vnum
    character(STRING):: name, units, longname, cause_c
    character(TOKEN), pointer:: dims(:) =>null()
    character(*), parameter:: subname = "HstFileCreate"
  continue
    call BeginSub(subname)
    stat = DC_NOERR
    cause_c = ""

    ! varname から変数情報の探査
    ! Search information of a variable from "varname"
    !
    vnum = 0
    do i = 1, numvars
      call HistoryVarinfoInquire( &
        & varinfo = gthst_vars(i), &  ! (in)
        & name = name )               ! (out)
      if ( trim(varname) == trim(name) ) vnum = i
    end do

    if ( vnum == 0 ) then
      stat = HST_EBADVARNAME
      cause_c = varname
      goto 999
    end if

    ! 未登録の場合は自動的に変数追加
    ! Add variable if the variable is not registered yet
    !
    ! ※ 配列サイズから自動的に次元の設定


    ! 出力が有効かどうかを確認する
    ! Confirm whether the output is effective
    !
    ! ※ 今は, dcpam4 で培った構造をそのまま引継ぎ, NAMELIST で
    !    interval に正を与えたときのみ出力するようにしている. 
    !    将来的には, write 文的な使用が可能なようにするため変更予定
    !
    if ( .not. HstNmlInfoOutputValid( gthstnml, varname ) ) then
      goto 999
    end if

    ! ファイルが未作成の場合は, まずファイル作成
    ! At first, the file is created if the file is not created yet
    ! 
    if ( .not. HistoryInitialized( gthist ) ) then

      ! 空間方向のスライスに対応して, 座標および座標重み情報の作り直し
      ! Remake axes and weights information correspond to spatial slices
      !

      ! HistoryCreate のための設定値の取得
      ! Get the settings for "HistoryCreate"
      !
      call HstNmlInfoInquire( &
        & gthstnml = gthstnml, &               ! (in)
        & name = varname, &                    ! (in)
        & file = file, &                       ! (out)
!!$        & origin_value   = origin_value, &     ! (out)
!!$        & origin_unit    = origin_unit, &      ! (out)
        & interval_value = interval_value, &   ! (out)
        & interval_unit  = interval_unit )     ! (out)

!        ※ gt4_history_nmlinfo が改良されたら復帰
!
!!$      call DCDiffTimeCreate( &
!!$        & diff = origin_difftime, &           ! (out)
!!$        & value = real( origin_value, DP ), & ! (in)
!!$        & unit = origin_unit )                ! (in)
!!$
!!$      origin_value = EvalbyUnit( origin_difftime, interval_unit )

      origin_value = EvalbyUnit( start_difftime, interval_unit )

      ! HistoryCreate によるファイル作成
      ! Files are created by "HistoryCreate"
      !
      call HistoryCreate( &
        & history = gthist, &                                     ! (inout)
        & file = file, title = title_save, &                      ! (in)
        & source = source_save, institution = institution_save, & ! (in)
        & axes = gthst_axes(1:numdims), &                         ! (in)
        & origin = origin_value, &                                ! (in)
        & interval = interval_value )                             ! (in)

      ! 時刻の単位を変更
      ! Change unit of time
      !
      call HistoryAxisInquire( &
        & axis = gthst_axes(numdims), & ! (in)
        & name = time_name )            ! (out)

      call HistoryAddAttr( &
        & history = gthist, &                        ! (inout)
        & varname = time_name, attrname = 'units', & ! (in)
        & value = interval_unit )                    ! (in)

      ! 座標データを出力
      ! Output axes data
      !
      do i = 1, numdims - 1
        call HistoryAxisInquire( &
          & axis = gthst_axes(i), &  ! (in)
          & name = name )            ! (out)
        call HistoryPut( &
          & history = gthist, &             ! (inout) optional
          & varname = name, &               ! (in)
          & array = data_axes(i) % a_axis ) ! (in)
      end do

      ! 座標重みデータを追加
      ! Add axes weights data
      !
      do i = 1, numwgts
        call HistoryAddVariable( &
          & history = gthist, &           ! (inout)
          & varinfo = gthst_weights(i) )  ! (in)
        call HistoryVarinfoInquire( &
          & varinfo = gthst_weights(i), &  ! (in)
          & name = name )                  ! (out)
        call HistoryPut( &
          & history = gthist, &                ! (inout) optional
          & varname = name, &                  ! (in)
          & array = data_weights(i) % a_axis ) ! (in)
      end do

    end if

    ! 平均化に伴う次元の縮退を反映した変数情報の作り直し
    ! Remake information of variables that reflects reduction of dimensions
    !   correspond to average
    !
    ! ※ これはもっと早い段階で作り直して良い (初回で良い)
    !    空間方向に関しては今後改善の予定
    !
    call HstNmlInfoInquire( &
      & gthstnml = gthstnml, name = varname, &  ! (in)
      & precision = precision, &                ! (out) optional
      & time_average = time_average )           ! (out) optional

    call HistoryVarinfoInquire( &
      & varinfo = gthst_vars(vnum), &    ! (in)
      & dims = dims, &                   ! (out) optional
      & longname = longname, &           ! (out) optional
      & units = units )                  ! (out) optional

    call HistoryVarinfoCreate( &
      & varinfo = gthst_vars(vnum), &        ! (out)
      & name = varname, dims = dims, &       ! (in)
      & longname = longname, &               ! (in)
      & units = units, xtype = precision, &  ! (in)
      & time_average = time_average )        ! (in) optional

    deallocate( dims )

    ! 変数情報を追加
    ! Add information of variables
    !
    call HistoryAddVariable( &
      & varinfo = gthst_vars(vnum), &  ! (in)
      & history = gthist )             ! (inout) optional

999 continue
    call StoreError(stat, subname, cause_c = cause_c)
    call EndSub(subname)
  end subroutine HstFileCreate

end module gt4_historyauto

!--
! vi:set readonly sw=4 ts=8:
!
!Local Variables:
!mode: f90
!buffer-read-only: t
!End:
!
!++
