!= Module HistoryFileIOMPI
!
! Authors::   SUGIYAMA Ko-ichiro
! Version::   $Id: historyfileiompi.f90,v 1.3 2009-03-05 05:42:30 sugiyama Exp $ 
! Tag Name::  $Name: arare4-20090306 $
! Copyright:: Copyright (C) GFD Dennou Club, 2006. All rights reserved.
! License::   See COPYRIGHT[link:../../COPYRIGHT]
!
!== Overview 
!
!ファイル出力. 長い時間ステップの値を出力.
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!== Future Plans
!

module HistoryFileIOMPI
  !
  !ファイル出力. 長い時間ステップの値を出力.
  !

  !モジュール読み込み
  use gtool_historyauto, only: HistoryAutoCreate, HistoryAutoPutAxis, HistoryAutoPut, &
    &                    HistoryAutoAddVariable, HistoryAutoClose, &
    &                    HistoryAutoPutAxisMPI
!  use gc_date, only: DC_DIFFTIME
  use gtool5
  use gtool_history
  use DebugSet, only: DebugOn
  use timeset,  only: TimeDisp,          &!ファイル出力する時間間隔
    &                 TimeInt             !積分時間
  use gridset,  only: s_X,               &!X 座標軸(スカラー格子点)
    &                 s_Z,               &!Z 座標軸(スカラー格子点)
    &                 FileNX,            &!X 方向の格子点(ファイル出力)
    &                 FileNZ,            &!Z 方向の格子点(ファイル出力)
    &                 FileXMin,          &!X 方向の配列の下限(ファイル出力)
    &                 FileXMax,          &!X 方向の配列の上限(ファイル出力)
    &                 FileZMin,          &!Z 方向の配列の下限(ファイル出力)
    &                 FileZMax,          &!Z 方向の配列の上限(ファイル出力)
    &                 DimXMin,           &!X 方向の配列の下限
    &                 DimXMax,           &!X 方向の配列の上限
    &                 DimZMin,           &!Z 方向の配列の下限
    &                 DimZMax,           &!Z 方向の配列の上限
    &                 RegXMin,           &!X 方向の配列の下限
    &                 RegXMax,           &!X 方向の配列の上限
    &                 RegZMin,           &!Z 方向の配列の下限
    &                 RegZMax,           &!Z 方向の配列の上限
    &                 MarginX,           &!Z 方向の配列の上限
    &                 DelX,              &!格子間隔
    &                 NX,                &!格子点数
    &                 XMin,              &!X 方向の始点
    &                 XMax,              &!X 方向の終点
    &                 SpcNum              !凝縮成分の数
  use basicset, only: xz_ExnerBasicZ,    &!基本場のエクスナー関数
    &                 xz_DensBasicZ,     &!基本場の密度
    &                 xz_PotTempBasicZ,  &!基本場の温位
    &                 xz_VelSoundBasicZ, &!基本場の音速
    &                 xz_PressBasicZ,    &!基本場の圧力
    &                 xz_TempBasicZ,     &!基本場の温度
    &                 xza_MixRtBasicZ,   &!基本場の混合比
    &                 xz_EffMolWtBasicZ, &!基本場の分子量効果
    &                 SpcWetSymbol        !湿潤成分の化学種名
  use filesetMPI,only: HistoryFilePrefix ,&!ヒストリファイル名
    &                 exptitle,          &!データの表題
    &                 expsrc,            &!データを作成する手順
    &                 expinst,           &!最終変更者・組織
    &                 FileNum,           &!ヒストリファイルの数
    &                 gt_hist  
  use StorePotTemp, only: StorePotTempMeanX, z_Adv, z_Turb, z_Disp, z_Diff, z_Rad, z_Cond, z_Flux,z_Damp 
  use StoreMixRt,   only: StoreMixRtMeanX, za_Adv, za_Turb, za_Diff, za_Flux, za_Rain, za_Fill1, za_Fill2, za_Cond
  use mpiset,   only:  myrank, nprocs

  !暗黙の型宣言禁止
  implicit none
  
  !属性の指定
  private

  !関数を public に指定
  public HistoryFile_Open
  public HistoryFile_OutPut
  public HistoryFile_Close

contains 

!!!------------------------------------------------------------------------
  subroutine HistoryFile_Open( cfgfile, Time )
    !
    !ヒストリファイルの定義
    !
    
    !暗黙の型宣言禁止
    implicit none
    
    !変数定義
    real(8), intent(in) :: Time
    integer :: s
    character(*), intent(in) :: cfgfile            !設定ファイル
    type(DC_DIFFTIME):: dispint                    ! 出力時間間隔
    type(DC_DIFFTIME):: endtime                    ! 計算終了時間
    type(DC_DIFFTIME):: ct                         ! 現在時刻
    logical :: flag_mpi_init
    integer :: err_mpi
    integer :: MPIXMin, MPIXMax
    real(8), allocatable :: f_Xmpi(:), s_Xmpi(:)
   
    !-----------------------------------------------------------
    ! ヒストリー作成
    !-----------------------------------------------------------
    flag_mpi_init = .true.
    call DCDiffTimeCreate(ct, Time, 'sec')      ! 現在時刻     
    call DCDiffTimeCreate(dispint, TimeDisp, 'sec')! 時間間隔
    call DCDiffTimeCreate(endtime, Time+TimeInt, 'sec') ! 積分時間

    MPIXMin = RegXMin
    MPIXMax = RegXMax * nprocs
    write(*,*) MPIXMin, MPIXMax, "(", RegXMax, ")"

    allocate( f_Xmpi(MPIXMin: MPIXMax), s_Xmpi(MPIXMin: MPIXMax) )
    do s = MPIXMin, MPIXMax
      f_Xmpi(s) = XMin + DelX * s 
    end do

    s_Xmpi(MPIXMin+1:MPIXMax) =           &
      &  (                             &
      &     f_Xmpi(MPIXMin+1:MPIXMax)     &
      &   + f_Xmpi(MPIXMin:MPIXMax-1)     &
      &  ) * 5.0d-1
    s_Xmpi(mpiXMin) = s_Xmpi(mpiXMin+1) - DelX
    write(*,*) s_Xmpi( MPIXMin+1: MPIXMax)
    write(*,*) s_X( FileXMin: FileXMax ) + myrank * (XMax - XMin)

    call HistoryAutoCreate(                          &
      & title = exptitle,                            &
      & source = expsrc,                             &
      & institution = expinst,                       &
      & dims=(/'x','z','t'/),                        &
      & dimsizes=(/FileNX, FileNZ, 0/),              &
      & longnames=(/'X-coordinate',                  &
      &             'Z-coordinate',                  &
      &             'Time        '/),                &
      & units=(/'m  ','m  ','sec'/),                 &
      & origin=ct,                                   &
      & interval=dispint,                            &
      & terminus=endtime,                            &
      & flag_mpi_gather = flag_mpi_init,             &
      & file_prefix = HistoryFilePrefix,             &
      & namelist_filename=cfgfile )


    call HistoryAutoPutAxis('x', s_X( FileXMin: FileXMax ) + myrank * (XMax - XMin))
    call HistoryAutoPutAxis('x', s_X( FileXMin: FileXMax ))
    call HistoryAutoPutAxis('z', s_Z( FileZMin: FileZMax ))    
    call HistoryAutoPutAxisMPI('x', s_Xmpi( MPIXMin+1: MPIXMax ))
    call HistoryAutoPutAxisMPI('z', s_Z( FileZMin: FileZMax))

    !-----------------------------------------------------------  
    ! 予報変数の出力
    !-----------------------------------------------------------  
    !無次元圧力の擾乱
    call HistoryAutoAddVariable(  &
      & varname='Exner',      &  
      & dims=(/'x','z','t'/), &
      & longname='disturbunce of nondimensional pressure', &
      & units=' ',            &        
      & xtype='double' )
    
    !温位の擾乱
    call HistoryAutoAddVariable(  &
      & varname='PotTemp',    &
      & dims=(/'x','z','t'/), &
      & longname='disturbunce of potential temperature',  &
      & units='K',            &
      & xtype='double')

    !水平速度
    call HistoryAutoAddVariable(  &
      & varname='VelX',       &
      & dims=(/'x','z','t'/), &
      & longname='zonal velocity', &
      & units='m s|-1"',      &
      & xtype='double')

    !鉛直速度
    call HistoryAutoAddVariable(  &
      & varname='VelZ',       &
      & dims=(/'x','z','t'/), &
      & longname='vertical velocity', &
      & units='m s|-1"',      &
      & xtype='double')

    !渦粘性係数(運動量)
    call HistoryAutoAddVariable(  &
      & varname='Km',         &
      & dims=(/'x','z','t'/), &
      & longname='turbulet diffusion coefficient', &
      & units='1',            &
      & xtype='double')
  
    !渦粘性係数(熱)
    call HistoryAutoAddVariable(  &
      & varname='Kh',         &
      & dims=(/'x','z','t'/), &
      & longname='turbulet diffusion coefficient for heat', &
      & units='1',            &
      & xtype='double' )
  
    !混合比
    do s = 1, SpcNum
      call HistoryAutoAddVariable(                               &
        & varname=trim(SpcWetSymbol(s)),                     &
        & dims=(/'x','z','t'/),                              &
        & longname=trim(SpcWetSymbol(s))//' Mixing Ratio',   &
        & units='kg kg|-1"',                                 &
        & xtype='double' )
    end do
    
    !----------------------------------------------------------------
    ! 温位の時間変化
    !----------------------------------------------------------------
    call HistoryAutoAddVariable(  &
      & varname='PotTempAdv', &
      & dims=(/'z','t'/),     &
      & longname='Advection term of potential temperature',  &
      & units='K day|-1"',    &
      & xtype='double' )

    call HistoryAutoAddVariable(  &
      & varname='PotTempTurb',&
      & dims=(/'z','t'/),     &
      & longname='Turbulence term of potential temperature', &
      & units='K day|-1"',    &
      & xtype='double'  )

    call HistoryAutoAddVariable(  &
      & varname='PotTempDisp',&
      & dims=(/'z','t'/),     &
      & longname='Dissipation term of potential temperature', &
      & units='K day|-1"',    &
      & xtype='double'  )

    call HistoryAutoAddVariable(  &
      & varname='PotTempRad', &
      & dims=(/'z','t'/),     &
      & longname='Radiation term of potential temperature', &
      & units='K day|-1"',    &
      & xtype='double'  )
    
    call HistoryAutoAddVariable(  &
      & varname='PotTempDiff',&
      & dims=(/'z','t'/),     &
      & longname='Numerical diffusion term of potential temperature',&
      & units='K day|-1"',    &
      & xtype='double'  )
    
    call HistoryAutoAddVariable(  &
      & varname='PotTempCond',&
      & dims=(/'z','t'/),     &
      & longname='Latent heat term of potential temperature', &
      & units='K day|-1"',    &
      & xtype='double'  )

    call HistoryAutoAddVariable(  &
      & varname='PotTempFlux',&
      & dims=(/'z','t'/),     &
      & longname='Surface Flux term of potential temperature', &
      & units='K day|-1"',    &
      & xtype='double'  )

    call HistoryAutoAddVariable(  &
      & varname='PotTempDamp',&
      & dims=(/'z','t'/),     &
      & longname='Newtonian Cooling term of potential temperature',  &
      & units='K day|-1"',    &
      & xtype='double'  )

    !----------------------------------------------------------------
    ! Mixing Ratio time change
    !----------------------------------------------------------------
    do s = 1, SpcNum
      call HistoryAutoAddVariable(  &
        & varname=trim(SpcWetSymbol(s))//'_Adv', &
        & dims=(/'z','t'/),     &
        & longname='Advection term of '          &
        &           //trim(SpcWetSymbol(s))//' mixing ratio',  &
        & units='kg kg|-1" s|-1"',    &
        & xtype='double' )
      
      call HistoryAutoAddVariable(  &
        & varname=trim(SpcWetSymbol(s))//'_Turb', & 
        & dims=(/'z','t'/),     &
        & longname='Turbulence term of '          &
        &           //trim(SpcWetSymbol(s))//' mixing ratio',  &
        & units='kg kg|-1" s|-1"',    &
        & xtype='double' )
      
      call HistoryAutoAddVariable(  &
        & varname=trim(SpcWetSymbol(s))//'_Diff', & 
        & dims=(/'z','t'/),     &
        & longname='Diffusion term of '          &
        &           //trim(SpcWetSymbol(s))//' mixing ratio',  &
        & units='kg kg|-1" s|-1"',    &
        & xtype='double'  )
      
      call HistoryAutoAddVariable(  &
        & varname=trim(SpcWetSymbol(s))//'_Flux', & 
        & dims=(/'z','t'/),     &
        & longname='Surface Flux term of '          &
        &           //trim(SpcWetSymbol(s))//' mixing ratio',  &
        & units='kg kg|-1" s|-1"',    &
        & xtype='double'  )
    
      call HistoryAutoAddVariable(  &
        & varname=trim(SpcWetSymbol(s))//'_Rain', & 
        & dims=(/'z','t'/),     &
        & longname='Fall Rain term of '          &
        &           //trim(SpcWetSymbol(s))//' mixing ratio',  &
        & units='kg kg|-1" s|-1"',    &
        & xtype='double'  )
    
      call HistoryAutoAddVariable(  &
        & varname=trim(SpcWetSymbol(s))//'_Fill1', & 
        & dims=(/'z','t'/),     &
        & longname='Filling Negative term 1 of '          &
        &           //trim(SpcWetSymbol(s))//' mixing ratio',  &
        & units='kg kg|-1" s|-1"',    &
        & xtype='double'  )
    
      call HistoryAutoAddVariable(  &
        & varname=trim(SpcWetSymbol(s))//'_Fill2', & 
        & dims=(/'z','t'/),     &
        & longname='Filling Negative term 2 of '          &
        &           //trim(SpcWetSymbol(s))//' mixing ratio',  &
        & units='kg kg|-1" s|-1"',    &
        & xtype='double'  )
    
      call HistoryAutoAddVariable(  &
        & varname=trim(SpcWetSymbol(s))//'_Cond', & 
        & dims=(/'z','t'/),     &
        & longname='Condensation term of '          &
        &           //trim(SpcWetSymbol(s))//' mixing ratio',  &
        & units='kg kg|-1" s|-1"',    &
        & xtype='double'  )
    
!      call HistoryAutoAddVariable(  &
!        & varname=trim(SpcWetSymbol(s))//'_Asln', & 
!        & dims=(/'z','t'/),     &
!        & longname='Asselin time filter term of '          &
!        &           //trim(SpcWetSymbol(s))//' mixing ratio',  &
!        & units='kg kg|-1" s|-1"',    &
!        & xtype='double'  )
    
    end do

    !-----------------------------------------------------------  
    ! 基本場の出力
    !-----------------------------------------------------------  
    call HistoryCreate(                              &
      & file = trim(HistoryFilePrefix)//"BasicZ.nc", &
      & title = exptitle,                            &
      & source = expsrc,                             &
      & institution = expinst,                       &
      & dims=(/'x','z','t'/),                        &
      & dimsizes=(/FileNX, FileNZ, 0/),              &
      & longnames=(/'X-coordinate',                  &
      &             'Z-coordinate',                  &
      &             'Time        '/),                &
      & units=(/'m','m','s'/), origin=0.0,           &
      & xtypes=(/'double', 'double', 'double'/),     &
      & interval=0.0,                                &
      & history=gt_hist(1) )

    !無次元圧力の基本場
    call HistoryAddVariable(  &
      & varname='ExnerBasicZ',&
      & dims=(/'x','z'/),     &
      & longname='nondimensional pressure', units='1',&
      & xtype='double',       &
      & history=gt_hist(1) ) 
    
    !温位の基本場
    call HistoryAddVariable(  &
      & varname='PotTempBasicZ',&
      & dims=(/'x','z'/),     &
      & longname='potential temperature', &
      & units='K',            &
      & xtype='double',       &
      & history=gt_hist(1) ) 
    
    !仮温位の基本場
    call HistoryAddVariable(  &
      & varname='VPotTempBasicZ',&
      & dims=(/'x','z'/),     &
      & longname='vertial potential temperature', &
      & units='K',            &
      & xtype='double',       &
      & history=gt_hist(1) ) 
    
    !密度の基本場
    call HistoryAddVariable(  &
      & varname='DensBasicZ', &
      & dims=(/'x','z'/),     &
      & longname='density',   &
      & units='Kg.m-3',       &
      & xtype='double',       &
      & history=gt_hist(1) ) 
    
    !音波速度の基本場
    call HistoryAddVariable(  &
      & varname='VelSoundBasicZ',&
      & dims=(/'x','z'/),     &
      & longname='sound velocity',&
      & units='m.s-2',        &
      & xtype='double',       &
      & history=gt_hist(1) ) 
    
    !温度の基本場
    call HistoryAddVariable(  &
      & varname='TempBasicZ', &
      & dims=(/'x','z'/),     &
      & longname='Temperature of basic state', &
      & units='K',            &
      & xtype='double',       &
      & history=gt_hist(1) ) 
    
    !圧力の基本場
    call HistoryAddVariable(  &
      & varname='PressBasicZ',&
      & dims=(/'x','z'/),     &
      & longname='Pressure of basic state', &
      & units='Pa',           &
      & xtype='double',       &
      & history=gt_hist(1) ) 
    
    !混合比の基本場
    do s = 1, SpcNum
      call HistoryAddVariable(  &
        & varname=trim(SpcWetSymbol(s))//'BasicZ',&
        & dims=(/'x','z'/), &
        & longname=trim(SpcWetSymbol(s))//' Mixing Ratio of basic state', &
        & units='kg.kg-1',        &
        & xtype='double',       &
        & history=gt_hist(1) ) 
    end do

    !分子量効果
    call HistoryAddVariable(  &
      & varname='EffMolWtBasicZ', &
      & dims=(/'x','z'/),     &
      & longname='Effect of Mole Weight', &
      & units='1',            &
      & xtype='double',       &
      & history=gt_hist(1) ) 

    !-------------------------------------------------------------
    ! 基本場のファイル出力
    !-------------------------------------------------------------
    call HistoryPut(   &
      & 'DensBasicZ',  &
      & xz_DensBasicZ(FileXMin:FileXMax, FileZMin:FileZMax), &
      & gt_hist(1) )

    call HistoryPut(   &
      & 'ExnerBasicZ', &
      & xz_ExnerBasicZ(FileXMin:FileXMax, FileZMin:FileZMax), &
      & gt_hist(1) )

    call HistoryPut(   &
      & 'PotTempBasicZ',&
      & xz_PotTempBasicZ(FileXMin:FileXMax, FileZMin:FileZMax), &
      & gt_hist(1) )

    call HistoryPut(   &
      & 'VPotTempBasicZ',&
      & xz_PotTempBasicZ(FileXMin:FileXMax, FileZMin:FileZMax)    &
      & / xz_EffMolWtBasicZ(FileXMin:FileXMax, FileZMin:FileZMax),&
      & gt_hist(1) )

    call HistoryPut(   &
      & 'VelSoundBasicZ', &
      & xz_VelSoundBasicZ(FileXMin:FileXMax, FileZMin:FileZMax), &
      & gt_hist(1) )

    call HistoryPut(   &
      & 'TempBasicZ',  &
      & xz_TempBasicZ(FileXMin:FileXMax, FileZMin:FileZMax), &
      & gt_hist(1) )

    call HistoryPut(   &
      & 'PressBasicZ', &
      & xz_PressBasicZ(FileXMin:FileXMax, FileZMin:FileZMax), &
      & gt_hist(1) )

    do s = 1, SpcNum
      call HistoryPut( &
        & trim(SpcWetSymbol(s))//'BasicZ',    &
        & xza_MixRtBasicZ(FileXMin:FileXMax, FileZMin:FileZMax, s), &
        & gt_hist(1) )
    end do

    call HistoryPut(   &
      & 'EffMolWtBasicZ', &
      & xz_EffMolWtBasicZ(FileXMin:FileXMax, FileZMin:FileZMax), &
      & gt_hist(1) )

    call HistoryClose(gt_hist(1))
    
  end subroutine HistoryFile_Open


!!!---------------------------------------------------------------------------
  subroutine HistoryFile_OutPut(   &
    & Time,                        &
    & xz_PotTemp,                  &
    & xz_Exner,                    &   
    & pz_VelX,                     &
    & xr_VelZ,                     &
    & xza_MixRt,                   &
    & xz_Km,                       &
    & xz_Kh                        &
    )
    !
    !予報変数のヒストリファイルへの出力. 出力時には半格子点の位置でプロット. 
    !
    
    !モジュール読み込み
    use average,   only: xz_avr_pz, xz_avr_xr

    !暗黙の型宣言禁止
    implicit none
    
    !変数定義
    type(DC_DIFFTIME)   :: ct                         ! 現在時刻
    real(8), intent(in) :: Time
    real(8), intent(in) :: pz_VelX(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8), intent(in) :: xr_VelZ(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8), intent(in) :: xz_Exner(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8), intent(in) :: xz_PotTemp(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8), intent(in) :: xz_Km(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8), intent(in) :: xz_Kh(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8), intent(in) :: xza_MixRt(DimXMin:DimXMax, DimZMin:DimZMax, SpcNum)

    real(8)             :: xz_VelX(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8)             :: xz_VelZ(DimXMin:DimXMax, DimZMin:DimZMax)
    integer             :: s


    call DCDiffTimeCreate(ct, Time, 'sec')      ! 現在時刻     

    !----------------------------------------------------------------
    ! 格子点位置を変換
    !----------------------------------------------------------------
    xz_VelX = xz_avr_pz( pz_VelX )
    xz_VelZ = xz_avr_xr( xr_VelZ )

    !----------------------------------------------------------------
    ! 値を出力
    !----------------------------------------------------------------

!    do s = 1, 8 + SpcNum
!      call HistoryAutoPut( 't', Time )
!    end do
    
    call HistoryAutoPut(  &
      & ct, 'Exner',      &
      & xz_Exner(FileXMin:FileXMax, FileZMin:FileZMax) )

    call HistoryAutoPut(  &
      & ct, 'PotTemp',    &
      & xz_PotTemp(FileXMin:FileXMax, FileZMin:FileZMax) )

    call HistoryAutoPut(  &
      & ct, 'VelX',       &
      & xz_VelX(FileXMin:FileXMax, FileZMin:FileZMax) )
    
    call HistoryAutoPut(  &
      & ct, 'VelZ',       &
      & xz_VelZ(FileXMin:FileXMax, FileZMin:FileZMax) )

    call HistoryAutoPut(  &
      & ct, 'Km',         &
      & xz_Km(FileXMin:FileXMax, FileZMin:FileZMax) )
    
    call HistoryAutoPut(  &
      & ct, 'Kh',         &
      & xz_Kh(FileXMin:FileXMax, FileZMin:FileZMax) )
    
    do s = 1, SpcNum
      call HistoryAutoPut(     &
        & ct, trim(SpcWetSymbol(s)), &
        & xza_MixRt(FileXMin:FileXMax, FileZMin:FileZMax, s) )
    end do

    !----------------------------------------------------------------
    ! 解析値を出力
    !----------------------------------------------------------------
    call StorePotTempMeanX()
    call StoreMixRtMeanX()

    call HistoryAutoPut(   &
      & ct, 'PotTempAdv',  &
      & z_Adv(FileZMin:FileZMax) )

    call HistoryAutoPut(   &
      & ct, 'PotTempTurb', &
      & z_Turb(FileZMin:FileZMax) )

    call HistoryAutoPut(   &
      & ct, 'PotTempDisp', &
      & z_Disp(FileZMin:FileZMax) )

    call HistoryAutoPut(   &
      & ct, 'PotTempDiff', &
      & z_Diff(FileZMin:FileZMax) )

    call HistoryAutoPut(   &
      & ct, 'PotTempRad',  &
      & z_Rad(FileZMin:FileZMax) )

    call HistoryAutoPut(   &
      & ct, 'PotTempCond', &
      & z_Cond(FileZMin:FileZMax) )

    call HistoryAutoPut(   &
      & ct, 'PotTempFlux', &
      & z_Flux(FileZMin:FileZMax) )

    call HistoryAutoPut(   &
      & ct, 'PotTempDamp', &
      & z_Damp(FileZMin:FileZMax) )

    do s = 1, SpcNum
      call HistoryAutoPut(                &
        & ct, trim(SpcWetSymbol(s))//'_Adv',  &
        & za_Adv(FileZMin:FileZMax, s) )

      call HistoryAutoPut(                &
        & ct, trim(SpcWetSymbol(s))//'_Turb', &
        & za_Turb(FileZMin:FileZMax, s) )

      call HistoryAutoPut(                 &
        & ct, trim(SpcWetSymbol(s))//'_Diff',  &
        & za_Diff(FileZMin:FileZMax, s) )

      call HistoryAutoPut(                 &
        & ct, trim(SpcWetSymbol(s))//'_Flux',  &
        & za_Flux(FileZMin:FileZMax, s) )

      call HistoryAutoPut(                 &
        & ct, trim(SpcWetSymbol(s))//'_Rain',  &
        & za_Rain(FileZMin:FileZMax, s) )

      call HistoryAutoPut(                  &
        & ct, trim(SpcWetSymbol(s))//'_Fill1',  &
        & za_Fill1(FileZMin:FileZMax, s) )

      call HistoryAutoPut(                  &
        & ct, trim(SpcWetSymbol(s))//'_Fill2',  &
        & za_Fill2(FileZMin:FileZMax, s) )

      call HistoryAutoPut(                 &
        & ct, trim(SpcWetSymbol(s))//'_Cond',  &
        & za_cond(FileZMin:FileZMax, s) )

!      call HistoryAutoPut(                 &
!        & ct, trim(SpcWetSymbol(s))//'_Asln',  &
!        & za_Asln(FileZMin:FileZMax, s) )

    end do

  end subroutine HistoryFile_OutPut


!!!--------------------------------------------------------------------------
  subroutine HistoryFile_Close
    !
    !ヒストリファイルのクローズ
    !
    
    !暗黙の型宣言禁止
    implicit none

    !ファイルを閉じる
    call HistoryAutoClose

  end subroutine HistoryFile_Close

  
end module HistoryFileIOMPI
