!= Module ReStartFileIO
!
! Authors::   SUGIYAMA Ko-ichiro, ODAKA Masatsugu
! Version::   $Id: restartfileio.f90,v 1.18 2015/02/19 02:17:23 sugiyama Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2007. All rights reserved.
! License::   See COPYRIGHT[link:../../COPYRIGHT]

module ReStartFileIO
  !
  !繝ｪ繧ｹ繧ｿ繝ｼ繝育畑縺ｮ蝣ｴ縺ｮ諠��ｱ繧� netCDF 繝輔ぃ繧､繝ｫ縺ｫ蜃ｺ蜉帙☆繧九◆繧√�繝ｫ繝ｼ繝√Φ
  !

  !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
  use gtool_history, only : GT_HISTORY
  use dc_types,      only : STRING

  !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
  implicit none

  !髢｢謨ｰ繧� public 縺ｫ謖�ｮ�
  public ReStartFileIO_init
  public ReStartFileio_Finalize
  public ReStartFileio_BasicZ_Get
  public ReStartFileio_Var_Get

  type(GT_HISTORY), save, public   :: rstat
  character(STRING), save, private :: InitialFile = ""
  character(STRING), save, private :: InputFile   = ""
  character(STRING), save, private :: OutputFile  = "output.nc"
  integer, save, private :: rNum

contains

  subroutine ReStartFileio_Init ( FlagInitData )
    !
    !繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺ｮ譖ｸ縺榊�縺�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use gtool_history, only : HistoryCreate,  &
      &                       HistoryPut,     &
      &                       HistoryAddVariable
    use dc_message,    only : MessageNotify
    use dc_iounit,     only : FileOpen
    use mpi_wrapper,   only : FLAG_LIB_MPI
    use axesset,       only : x_X,            &!X 蠎ｧ讓呵ｻｸ(繧ｹ繧ｫ繝ｩ繝ｼ譬ｼ蟄千せ)
      &                       y_Y,            &!Y 蠎ｧ讓呵ｻｸ(繧ｹ繧ｫ繝ｩ繝ｼ譬ｼ蟄千せ)
      &                       z_Z              !Z 蠎ｧ讓呵ｻｸ(繧ｹ繧ｫ繝ｩ繝ｼ譬ｼ蟄千せ)
    use gridset,       only : ncmax            !蜃晉ｸｮ謌仙�縺ｮ謨ｰ
    use fileset,       only : filetitle,      &!繝��繧ｿ縺ｮ陦ｨ鬘�
      &                       filesource,     &!繝��繧ｿ繧剃ｽ懈�縺吶ｋ謇矩��
      &                       FileInstitution  !譛邨ょ､画峩閠��邨�ｹ�
    use namelist_util, only: namelist_filename

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    logical, intent(in), optional :: FlagInitData  ! 蛻晄悄蛟､逕滓�繝励Ο繧ｰ繝ｩ繝�縺ｮ蝣ｴ蜷医� .true.

    real(4)            :: SpcID(ncmax)
    integer            :: N, L, M
    integer            :: s
    integer            :: unit     !陬�ｽｮ逡ｪ蜿ｷ

    !NAMELIST 縺九ｉ諠��ｱ繧貞叙蠕�
    NAMELIST /restartfileio_nml/ InitialFile, InputFile, OutputFile, rNum

    call FileOpen(unit, file=namelist_filename, mode='r')
    read(unit, NML=restartfileio_nml)
    close(unit)

    !遒ｺ隱�
    call MessageNotify( "M", &
      & "restartfileioIO_init", "InitialFile  = %c", c1=trim(InitialFile) )
    call MessageNotify( "M", &
      & "restartfileioIO_init", "InputFile  = %c", c1=trim(InputFile) )
    call MessageNotify( "M", &
      & "restartfileioIO_init", "OutputFile = %c", c1=trim(OutputFile) )

    ! InputFile 縺檎ｩｺ縺ｮ蝣ｴ蜷医�, 蛻晄悄蛟､繝輔ぃ繧､繝ｫ繧剃ｽｿ縺�.
    if ( InputFile == "" ) then
      InputFile = InitialFile
    end if

    !蛻晄悄蛟､逕滓�縺ｮ蝣ｴ蜷医↓縺ｯ, outputfile 蜷阪ｒ螟画峩
    if ( present( FlagInitData ) ) then
      if ( FlagInitData ) then
        if ( .NOT. InitialFile == "" ) then  ! 繝輔ぃ繧､繝ｫ蜷阪′遨ｺ縺ｪ繧峨�
          InputFile  = ""
          OutputFile = InitialFile
        end if
      end if
    end if

    !遒ｺ隱�
    call MessageNotify( "M", &
      & "restartfileioIO_init", "INPUT  = %c", c1=trim(InputFile) )
    call MessageNotify( "M", &
      & "restartfileioIO_init", "OUTPUT = %c", c1=trim(OutputFile) )

    SpcID = 0.0d0
    do s = 1, ncmax
      SpcID(s) = real( s, 4 )
    end do

    N = size(x_X, 1)
    L = size(y_Y, 1)
    M = size(z_Z, 1)

    !-------------------------------------------------------------
    ! 繝偵せ繝医Μ繝ｼ菴懈�
    !-------------------------------------------------------------
    call HistoryCreate(                              &
      & file = Outputfile,                           &
      & title = filetitle,                           &
      & source = filesource,                         &
      & institution = FileInstitution,               &
      & dims=(/'x','y','z','s','t'/),                &
      & dimsizes=(/N, L, M, ncmax, 0/),              &
      & longnames=(/'X-coordinate',                  &
      &             'Y-coordinate',                  &
      &             'Z-coordinate',                  &
      &             'Species Num ',                  &
      &             'Time        '/),                &
      & units=(/'m  ','m  ','m  ','1  ','sec'/),     &
      & xtypes=(/'double', 'double', 'double', 'double', 'double'/), &
      & flag_mpi_split = FLAG_LIB_MPI,               &
      & origin=0.0, interval=1.0,                    &
      & history=rstat, quiet=.true. )

    !-------------------------------------------------------------
    ! 螟画焚蜃ｺ蜉�
    !-------------------------------------------------------------
    call HistoryPut('x', x_X, rstat )
    call HistoryPut('y', y_Y, rstat )
    call HistoryPut('z', z_Z, rstat )
    call HistoryPut('s', real(SpcID, 4), rstat )

    !辟｡谺｡蜈�悸蜉帙�蝓ｺ譛ｬ蝣ｴ
    call HistoryAddVariable(                           &
      & varname='ExnerBZ', dims=(/'x','y','z'/),       &
      & longname='nondimensional pressure', units='1', &
      & xtype='double', history=rstat )

    !貂ｩ菴阪�蝓ｺ譛ｬ蝣ｴ
    call HistoryAddVariable(                           &
      & varname='PTempBZ', dims=(/'x','y','z'/),       &
      & longname='potential temperature',              &
      & units='K', xtype='double', history=rstat )

    !貂ｩ菴阪�蝓ｺ譛ｬ蝣ｴ
    call HistoryAddVariable(                           &
      & varname='VPTempBZ', dims=(/'x','y','z'/),      &
      & longname='virtual potential temperature',      &
      & units='K', xtype='double', history=rstat )

    !蟇�ｺｦ縺ｮ蝓ｺ譛ｬ蝣ｴ
    call HistoryAddVariable(                           &
      & varname='DensBZ', dims=(/'x','y','z'/),        &
      & longname='density',                            &
      & units='Kg.m-3', xtype='double', history=rstat )

    !髻ｳ豕｢騾溷ｺｦ縺ｮ蝓ｺ譛ｬ蝣ｴ
    call HistoryAddVariable(                           &
      & varname='VelSoundBZ', dims=(/'x','y','z'/),    &
      & longname='sound velocity',                     &
      & units='m.s-2', xtype='double', history=rstat )

    !貂ｩ蠎ｦ縺ｮ蝓ｺ譛ｬ蝣ｴ
    call HistoryAddVariable(                           &
      & varname='TempBZ', dims=(/'x','y','z'/),        &
      & longname='Temperature of basic state',         &
      & units='K', xtype='double', history=rstat )

    !蝨ｧ蜉帙�蝓ｺ譛ｬ蝣ｴ
    call HistoryAddVariable(                           &
      & varname='PressBZ', dims=(/'x','y','z'/),       &
      & longname='Pressure of basic state',            &
      & units='Pa', xtype='double', history=rstat )

    !豌ｴ闥ｸ豌玲ｷｷ蜷域ｯ斐�蝓ｺ譛ｬ蝣ｴ
    call HistoryAddVariable(                              &
      & varname='QMixBZ', dims=(/'x','y','z','s'/),       &
      & longname='Mixing ratio of Condensible volatiles', &
      & units='kg.kg-1', xtype='double', history=rstat )

    !蛻�ｭ宣㍼蜉ｹ譫�
    call HistoryAddVariable(                         &
      & varname='EffMolWtBZ', dims=(/'x','y','z'/),  &
      & longname='Effect of Mole Weight',            &
      & units='1', xtype='double', history=rstat )

    !貉ｿ蠎ｦ
    call HistoryAddVariable(                        &
      & varname='HumBZ', dims=(/'x','y','z','s'/),  &
      & longname='Humidity',                        &
      & units='1', xtype='double', history=rstat )

    !騾溷ｺｦ
    call HistoryAddVariable(                         &
      & varname='VelX', dims=(/'x','y','z','t'/),    &
      & longname='zonal velocity',                   &
      & units='m.s-1',                               &
      & xtype='double', history=rstat )

    !騾溷ｺｦ
    call HistoryAddVariable(                         &
      & varname='VelY', dims=(/'x','y','z','t'/),    &
      & longname='meridional velocity',              &
      & units='m.s-1',                               &
      & xtype='double', history=rstat )

    !騾溷ｺｦ
    call HistoryAddVariable(                         &
      & varname='VelZ', dims=(/'x','y','z','t'/),    &
      & longname='vertical velocity',                &
      & units='m.s-1',                               &
      & xtype='double', history=rstat )

    !辟｡谺｡蜈�悸蜉�
    call HistoryAddVariable(                         &
      & varname='Exner', dims=(/'x','y','z','t'/),   &
      & longname='nondimensional pressure',          &
      & units='1',                                   &
      & xtype='double', history=rstat )

    !貂ｩ菴阪�謫ｾ荵ｱ
    call HistoryAddVariable(                         &
      & varname='PTemp', dims=(/'x','y','z','t'/),   &
      & longname='virtual potential temperature',    &
      & units='K',                                   &
      & xtype='double', history=rstat )

    !貂ｦ邊俶ｧ菫よ焚
    call HistoryAddVariable(                         &
      & varname='Km', dims=(/'x','y','z','t'/),      &
      & longname='Km',                               &
      & units='m2.s-1',                              &
      & xtype='double', history=rstat )

    !貂ｦ邊俶ｧ菫よ焚
    call HistoryAddVariable(                         &
      & varname='Kh', dims=(/'x','y','z','t'/),      &
      & longname='Kh',                               &
      & units='m2.s-1',                              &
      & xtype='double', history=rstat )

    !髮ｲ蟇�ｺｦ
    call HistoryAddVariable(                         &
      & varname='CDens', dims=(/'x','y','z','t'/),   &
      & longname='CDens',                            &
      & units='m2.s-1',                              &
      & xtype='double', history=rstat )

    !豺ｷ蜷域ｯ�
    call HistoryAddVariable(                         &
      & varname='QMix', dims=(/'x','y','z','s','t'/),&
      & longname='Mixing Ratio',                     &
      & units='kg.kg-1"',                            &
      & xtype='double', history=rstat )

  end subroutine ReStartFileio_Init

  subroutine ReStartFileIO_Finalize
    !
    !繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺ｮ繧ｯ繝ｭ繝ｼ繧ｺ
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use gtool_history, only: HistoryClose

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !繝輔ぃ繧､繝ｫ繧帝哩縺倥ｋ
    call HistoryClose(rstat, quiet=.true.)

  end subroutine ReStartFileIO_Finalize

  subroutine ReStartFileio_Var_Get(   &
    & pyz_VelXB,  pyz_VelXN,    & ! (out)
    & xqz_VelYB,  xqz_VelYN,    & ! (out)
    & xyr_VelZB,  xyr_VelZN,    & ! (out)
    & xyz_PTempB, xyz_PTempN,   & ! (out)
    & xyz_ExnerB, xyz_ExnerN,   & ! (out)
    & xyzf_QMixB, xyzf_QMixN,   & ! (out)
    & xyz_KmB,    xyz_KmN,      & ! (out)
    & xyz_KhB,    xyz_KhN,      & ! (out)
    & xyz_CDensB, xyz_CDensN  )   ! (out)
    !
    !繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺九ｉ諠��ｱ蜿門ｾ�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use dc_message,    only : MessageNotify
    use gtool_history, only : HistoryGet
    use dc_types,      only : DP, STRING
    use dc_string,     only : toChar
    use mpi_wrapper,   only : FLAG_LIB_MPI
    use gridset,       only : imin, imax,    &!驟榊�繧ｵ繧､繧ｺ (X 譁ｹ蜷�)
      &                       jmin, jmax,    &!驟榊�繧ｵ繧､繧ｺ (Y 譁ｹ蜷�)
      &                       kmin, kmax,    &!驟榊�繧ｵ繧､繧ｺ (Z 譁ｹ蜷�)
      &                       ncmax           !蜃晉ｸｮ謌仙�縺ｮ謨ｰ
    use timeset,       only : DelTimeLong,   &
      &                       RestartTime

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(out) :: pyz_VelXN &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xqz_VelYN &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyr_VelZN &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyz_ExnerN &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyz_PTempN &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyz_KmN &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyz_KhN &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyz_CDensN &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyzf_QMixN &
      &                     (imin:imax,jmin:jmax,kmin:kmax,ncmax)
    real(DP), intent(out) :: pyz_VelXB &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xqz_VelYB &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyr_VelZB &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyz_ExnerB &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyz_PTempB &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyz_KmB &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyz_KhB &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyz_CDensB &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP), intent(out) :: xyzf_QMixB &
      &                     (imin:imax,jmin:jmax,kmin:kmax,ncmax)

    character(STRING)    :: name               !螟画焚蜷�
    character(STRING)    :: TimeN = ""
    character(STRING)    :: TimeB = ""

    real(DP)  :: RTimeN, RTimeB, RTimeRtnB, RTimeRtnN
    logical   :: flag_time_exist
    logical   :: flag_time_err

    !-------------------------------------------------------------
    ! Get a Value from netCDF File
    !-------------------------------------------------------------
    RTimeN = RestartTime
    if (RestartTime /= 0.0d0) then
     RTimeB = RestartTime - DelTimeLong
    else
     RTimeB = RestartTime
    end if

!!    timeB = 't=' // toChar( RTimeB )
!!    timeN = 't=' // toChar( RTimeN )
    timeB = 't=^' // toChar( rNum - 1 )
    timeN = 't=^' // toChar( rNum )

!!!
!!! 遒ｺ隱�
!!!
    name = "PTemp"
    call HistoryGet( InputFile, name, xyz_PTempB, range=TimeB, flag_mpi_split = FLAG_LIB_MPI, &
      & returned_time = RTimeRtnB, flag_time_exist = flag_time_exist, err = flag_time_err )
    call HistoryGet( InputFile, name, xyz_PTempN, range=TimeN, flag_mpi_split = FLAG_LIB_MPI, &
      & returned_time = RTimeRtnN, flag_time_exist = flag_time_exist, err = flag_time_err )

    if ( .NOT. flag_time_exist .OR. flag_time_err ) then
     call MessageNotify( "M", "restartfileio", "flag_time_exist = %b", L=(/flag_time_exist/) )
     call MessageNotify( "M", "restartfileio", "flag_time_err   = %b", L=(/flag_time_err/)   )
     call MessageNotify( "E", "restartfileio", "restart error occure" )
    end if

    if ( RTimeRtnB - RTimeB /= 0.0d0 .OR. RTimeRtnN - RTimeN /= 0.0d0 ) then
      call MessageNotify( "M", "restartfileio", "RTimeRtnB  = %f", d=(/RTimeRtnB/)  )
      call MessageNotify( "M", "restartfileio", "RTimeRtnN  = %f", d=(/RTimeRtnN/)  )
      call MessageNotify( "M", "restartfileio", "RTimeB     = %f", d=(/RTimeB/) )
      call MessageNotify( "M", "restartfileio", "RTimeN     = %f", d=(/RTimeN/) )
      call MessageNotify( "E", "restartfileio", "restart time is incorrect " )
    end if

!!!
!!! 繝輔ぃ繧､繝ｫ繧ｪ繝ｼ繝励Φ & 蛟､縺ｮ蜿悶ｊ蜃ｺ縺�
!!!
    name = "PTemp"
    call HistoryGet( InputFile, name, xyz_PTempB, range=TimeB, flag_mpi_split = FLAG_LIB_MPI )
    call HistoryGet( InputFile, name, xyz_PTempN, range=TimeN, flag_mpi_split = FLAG_LIB_MPI )

    name = "VelX"
    call HistoryGet( InputFile, name, pyz_VelXB, range=TimeB, flag_mpi_split = FLAG_LIB_MPI )
    call HistoryGet( InputFile, name, pyz_VelXN, range=TimeN, flag_mpi_split = FLAG_LIB_MPI )

    name = "VelY"
    call HistoryGet( InputFile, name, xqz_VelYB, range=TimeB, flag_mpi_split = FLAG_LIB_MPI )
    call HistoryGet( InputFile, name, xqz_VelYN, range=TimeN, flag_mpi_split = FLAG_LIB_MPI )

    name = "VelZ"
    call HistoryGet( InputFile, name, xyr_VelZB, range=TimeB, flag_mpi_split = FLAG_LIB_MPI )
    call HistoryGet( InputFile, name, xyr_VelZN, range=TimeN, flag_mpi_split = FLAG_LIB_MPI )

    name = "Exner"
    call HistoryGet( InputFile, name, xyz_ExnerB, range=TimeB, flag_mpi_split = FLAG_LIB_MPI )
    call HistoryGet( InputFile, name, xyz_ExnerN, range=TimeN, flag_mpi_split = FLAG_LIB_MPI )

    name = "Km"
    call HistoryGet( InputFile, name, xyz_KmB, range=TimeB, flag_mpi_split = FLAG_LIB_MPI )
    call HistoryGet( InputFile, name, xyz_KmN, range=TimeN, flag_mpi_split = FLAG_LIB_MPI )

    name = "Kh"
    call HistoryGet( InputFile, name, xyz_KhB, range=TimeB, flag_mpi_split = FLAG_LIB_MPI )
    call HistoryGet( InputFile, name, xyz_KhN, range=TimeN, flag_mpi_split = FLAG_LIB_MPI )

    name = "CDens"
    call HistoryGet( InputFile, name, xyz_CDensB, range=TimeB, flag_mpi_split = FLAG_LIB_MPI )
    call HistoryGet( InputFile, name, xyz_CDensN, range=TimeN, flag_mpi_split = FLAG_LIB_MPI )

    name = "QMix"
    call HistoryGet( InputFile, name, xyzf_QMixB, range=TimeB, flag_mpi_split = FLAG_LIB_MPI )
    call HistoryGet( InputFile, name, xyzf_QMixN, range=TimeN, flag_mpi_split = FLAG_LIB_MPI )

  end subroutine ReStartFileio_Var_Get

  subroutine ReStartFileio_BasicZ_Get()
    !
    !繝ｪ繧ｹ繧ｿ繝ｼ繝医ヵ繧｡繧､繝ｫ縺九ｉ諠��ｱ蜿門ｾ�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use gtool_history, only : HistoryGet
    use dc_types,      only : DP, STRING
    use mpi_wrapper,   only : FLAG_LIB_MPI
    use gridset,       only : imin, imax,    &!驟榊�繧ｵ繧､繧ｺ (X 譁ｹ蜷�)
      &                       jmin, jmax,    &!驟榊�繧ｵ繧､繧ｺ (Y 譁ｹ蜷�)
      &                       kmin, kmax,    &!驟榊�繧ｵ繧､繧ｺ (Z 譁ｹ蜷�)
      &                       ncmax           !蜃晉ｸｮ謌仙�縺ｮ謨ｰ
    use basicset,      only : basicset_init

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP)              :: Var3D &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
    real(DP)              :: Var4D &
      &                     (imin:imax,jmin:jmax,kmin:kmax,ncmax)
    real(DP)              :: xyz_ExnerBZ &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
                                               !蝓ｺ譛ｬ蝣ｴ縺ｮ繧ｨ繧ｯ繧ｹ繝翫�髢｢謨ｰ
    real(DP)              :: xyz_DensBZ &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
                                               !蝓ｺ譛ｬ蝣ｴ縺ｮ蟇�ｺｦ
    real(DP)              :: xyz_PTempBZ &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
                                               !蝓ｺ譛ｬ蝣ｴ縺ｮ貂ｩ菴�
    real(DP)              :: xyz_VelSoundBZ &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
                                               !蝓ｺ譛ｬ蝣ｴ縺ｮ髻ｳ騾�
    real(DP)              :: xyz_PressBZ &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
                                               !蝓ｺ譛ｬ蝣ｴ縺ｮ蝨ｧ蜉�
    real(DP)              :: xyz_TempBZ &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
                                               !蝓ｺ譛ｬ蝣ｴ縺ｮ貂ｩ蠎ｦ
    real(DP)              :: xyzf_QMixBZ &
      &                     (imin:imax,jmin:jmax,kmin:kmax, ncmax)
                                               !蝓ｺ譛ｬ蝣ｴ縺ｮ豺ｷ蜷域ｯ�
    real(DP)              :: xyz_EffMolWtBZ &
      &                     (imin:imax,jmin:jmax,kmin:kmax)
                                               !蝓ｺ譛ｬ蝣ｴ縺ｮ蛻�ｭ宣㍼蜉ｹ譫�
    character(STRING)    :: name               !螟画焚蜷�

    !-------------------------------------------------------------
    ! 蝓ｺ譛ｬ蝣ｴ縺ｮ蜿門ｾ�
    !
    name = "DensBZ"
    call HistoryGet( InputFile, name, Var3D, flag_mpi_split = FLAG_LIB_MPI )
    xyz_DensBZ = Var3D

    name = "ExnerBZ"
    call HistoryGet( InputFile, name, Var3D, flag_mpi_split = FLAG_LIB_MPI )
    xyz_ExnerBZ = Var3D

    name = "PTempBZ"
    call HistoryGet( InputFile, name, Var3D, flag_mpi_split = FLAG_LIB_MPI )
    xyz_PTempBZ = Var3D

    name = "VelSoundBZ"
    call HistoryGet( InputFile, name, Var3D, flag_mpi_split = FLAG_LIB_MPI )
    xyz_VelSoundBZ = Var3D

    name = "TempBZ"
    call HistoryGet( InputFile, name, Var3D, flag_mpi_split = FLAG_LIB_MPI )
    xyz_TempBZ = Var3D

    name = "PressBZ"
    call HistoryGet( InputFile, name, Var3D, flag_mpi_split = FLAG_LIB_MPI )
    xyz_PressBZ = Var3D

    name = "QMixBZ"
    call HistoryGet( InputFile, name, Var4D, flag_mpi_split = FLAG_LIB_MPI )
    xyzf_QMixBZ = Var4D

    name = "EffMolWtBZ"
    call HistoryGet( InputFile, name, Var3D, flag_mpi_split = FLAG_LIB_MPI )
    xyz_EffMolWtBZ = Var3D

    !----------------------------------------------------------
    ! BasicSet 繝｢繧ｸ繝･繝ｼ繝ｫ縺ｫ蛟､繧定ｨｭ螳�
    !----------------------------------------------------------
    call basicset_init( &
      & xyz_PressBZ,    &
      & xyz_ExnerBZ,    &
      & xyz_TempBZ,     &
      & xyz_PTempBZ,    &
      & xyz_DensBZ,     &
      & xyz_VelSoundBZ, &
      & xyzf_QMixBZ,    &
      & xyz_EffMolWtBZ  &
      & )

  end subroutine ReStartFileio_BasicZ_Get

end module ReStartFileIO