!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
!= Module HistoryFileIO
!
!   * Developer: SUGIYAMA Ko-ichiro (sugiyama@gfd-dennou.org)
!   * Version: $Id: historyfileio.f90,v 1.1.1.1 2006/04/25 03:43:58 deepconv Exp $ 
!   * Tag Name: $Name:  $
!   * Change History: 
!
!== Overview 
!
!$B%U%!%$%k=PNO(B. $BD9$$;~4V%9%F%C%W$NCM$r=PNO(B.
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!== Future Plans
!

module HistoryFileIO
  !
  !$B%U%!%$%k=PNO(B. $BD9$$;~4V%9%F%C%W$NCM$r=PNO(B.
  !

  !$B%b%8%e!<%kFI$_9~$_(B
  use gt4_history
  use gridset,  only: s_X,               &!X $B:BI8<4(B($B%9%+%i!<3J;RE@(B)
    &                 s_Z,               &!Z $B:BI8<4(B($B%9%+%i!<3J;RE@(B)
    &                 FileNX,            &!X $BJ}8~$N3J;RE@(B($B%U%!%$%k=PNO(B)
    &                 FileNZ,            &!Z $BJ}8~$N3J;RE@(B($B%U%!%$%k=PNO(B)
    &                 FileXMin,          &!X $BJ}8~$NG[Ns$N2<8B(B($B%U%!%$%k=PNO(B)
    &                 FileXMax,          &!X $BJ}8~$NG[Ns$N>e8B(B($B%U%!%$%k=PNO(B)
    &                 FileZMin,          &!Z $BJ}8~$NG[Ns$N2<8B(B($B%U%!%$%k=PNO(B)
    &                 FileZMax,          &!Z $BJ}8~$NG[Ns$N>e8B(B($B%U%!%$%k=PNO(B)
    &                 DimXMin,           &!X $BJ}8~$NG[Ns$N2<8B(B
    &                 DimXMax,           &!X $BJ}8~$NG[Ns$N>e8B(B
    &                 DimZMin,           &!Z $BJ}8~$NG[Ns$N2<8B(B
    &                 DimZMax,           &!Z $BJ}8~$NG[Ns$N>e8B(B
    &                 SpcNum              !$B6E=L@.J,$N?t(B
  use fileset,  only: HistoryFile,       &!$B%R%9%H%j%U%!%$%kL>(B
    &                 exptitle,          &!$B%G!<%?$NI=Bj(B
    &                 expsrc,            &!$B%G!<%?$r:n@.$9$k<j=g(B
    &                 expinst             !$B:G=*JQ99<T!&AH?%(B
  use basicset, only: SpcWetID,          &!$B6E=L@.J,$N(B ID
    &                 xz_ExnerBasicZ,    &!$B4pK\>l$N%(%/%9%J!<4X?t(B
    &                 xz_DensBasicZ,     &!$B4pK\>l$NL)EY(B
    &                 xz_PotTempBasicZ,  &!$B4pK\>l$N290L(B
    &                 xz_VelSoundBasicZ, &!$B4pK\>l$N2;B.(B
    &                 xz_PressBasicZ,    &!$B4pK\>l$N05NO(B
    &                 xz_TempBasicZ,     &!$B4pK\>l$N29EY(B
    &                 xza_MixRtBasicZ,    &!$B4pK\>l$N:.9gHf(B
    &                 xz_EffMolWtBasicZ   !$B4pK\>l$NJ,;RNL8z2L(B

  !$B0EL[$N7?@k8@6X;_(B
  implicit none
  
  !$BB0@-$N;XDj(B
  private

  !$B4X?t$r(B public $B$K;XDj(B
  public HistoryFile_Open
  public HistoryFile_OutPut
  public HistoryFile_OutPutAnal
  public HistoryFile_Close

contains 

!!!------------------------------------------------------------------------------!!!
  subroutine HistoryFile_Open( )
    !
    !$B%R%9%H%j%U%!%$%k$NDj5A(B
    !
    
    !$B0EL[$N7?@k8@6X;_(B
    implicit none
    
    !$BJQ?tDj5A(B
    real(4)        :: SpcID(SpcNum)
    integer        :: s
    
    do s = 1, SpcNum
      SpcID(s) = s * 1.0d0
    end do


    !-----------------------------------------------------------
    ! $B%R%9%H%j!<:n@.(B
    !-----------------------------------------------------------
    call HistoryCreate(                              &
      & file = HistoryFile,                          &
      & title = exptitle,                            &
      & source = expsrc,                             &
      & institution = expinst,                       &
      & dims=(/'x','z','s','t'/),                    &
      & dimsizes=(/FileNX, FileNZ, SpcNum, 0/),      &
      & longnames=(/'X-coordinate',                  &
      &             'Z-coordinate',                  &
      &             'Species Num ',                  &
      &             'Time        '/),                &
      & units=(/'m','m','1','s'/), origin=0.0,       &
      & interval=0.0 )
    
    !-----------------------------------------------------------  
    ! $B<4$N=PNO(B
    !-----------------------------------------------------------
    call HistoryPut('x', s_X( FileXMin: FileXMax ) )
    call HistoryPut('z', s_Z( FileZMin: FileZMax ) )
    call HistoryPut('s', real(SpcID, 4))

    !-----------------------------------------------------------  
    ! $BM=JsJQ?t$N=PNO(B
    !-----------------------------------------------------------  
    !$BL5<!8505NO$N>qMp(B
    call HistoryAddVariable(                               &
      & varname='Exner', dims=(/'x','z','t'/),             &
      & longname='disturbunce of nondimensional pressure', &
      & units=' ', xtype='double' )
    
    !$B290L$N>qMp(B
    call HistoryAddVariable(                              &
      & varname='PotTemp', dims=(/'x','z','t'/),          &
      & longname='disturbunce of potential temperature',  &
      & units='K', xtype='double' )

    !$B?eJ?B.EY(B
    call HistoryAddVariable(                         &
      & varname='VelX', dims=(/'x','z','t'/),        &
      & longname='zonal velocity',                   &
      & units='m s|-1"', xtype='double' )

    !$B1tD>B.EY(B
    call HistoryAddVariable(                         &
      & varname='VelZ', dims=(/'x','z','t'/),        &
      & longname='vertical velocity',                &
      & units='m s|-1"', xtype='double' )

    !$B12G4@-78?t(B
    call HistoryAddVariable(                         &
      & varname='Km', dims=(/'x','z','t'/),          &
      & longname='Km',                               &
      & units='1', xtype='double' )
  
    !$B:.9gHf(B
    call HistoryAddVariable(                         &
      & varname='MixRt', dims=(/'x','z','s','t'/),   &
      & longname='Mixing Ratio',                     &
      & units='kg kg|-1"', xtype='double' )
    
    !-----------------------------------------------------------  
    ! $B4pK\>l$N=PNO(B
    !-----------------------------------------------------------  
    !$BL5<!8505NO$N4pK\>l(B
    call HistoryAddVariable(                          &
      & varname='ExnerBasicZ', dims=(/'x','z'/),      &
      & longname='nondimensional pressure', units='1',&
      & xtype='double' )
    
    !$B290L$N4pK\>l(B
    call HistoryAddVariable(                          &
      & varname='PotTempBasicZ', dims=(/'x','z'/),    &
      & longname='potential temperature',             &
      & units='K', xtype='double' )
    
    !$BL)EY$N4pK\>l(B
    call HistoryAddVariable(                         &
      & varname='DensBasicZ', dims=(/'x','z'/),      &
      & longname='density',                          &
      & units='Kg/m^3', xtype='double' )
    
    !$B2;GHB.EY$N4pK\>l(B
    call HistoryAddVariable(                         &
      & varname='VelSoundBasicZ', dims=(/'x','z'/),  &
      & longname='sound velocity',                   &
      & units='m/s|2', xtype='double' )
    
    !$B29EY$N4pK\>l(B
    call HistoryAddVariable(                         &
      & varname='TempBasicZ', dims=(/'x','z'/),      &
      & longname='Temperature of basic state',       &
      & units='K', xtype='double' ) 
    
    !$B05NO$N4pK\>l(B
    call HistoryAddVariable(                         &
      & varname='PressBasicZ', dims=(/'x','z'/),     &
      & longname='Pressure of basic state',          &
      & units='Pa', xtype='double' ) 
    
    !$B?e>x5$:.9gHf$N4pK\>l(B
    call HistoryAddVariable(                               &
      & varname='MixRtBasicZ', dims=(/'x','z','s'/),      &
      & longname='Mixing ratio of Condensible volatiles',  &
      & units='kg/kg', xtype='double' ) 
    
    !$BJ,;RNL8z2L(B
    call HistoryAddVariable(                         &
      & varname='EffMolWtBasicZ', dims=(/'x','z'/),  &
      & longname='Effect of Mole Weight',            &
      & units='1', xtype='double' ) 

    !-----------------------------------------------------------  
    ! $B2r@OMQ$NJQ?t$N=PNO(B
    !-----------------------------------------------------------  
    !$B2>290L$N>qMp(B
    call HistoryAddVariable(                                     &
      & varname='VPotTemp', dims=(/'x','z','t'/),                &
      & longname='disturbunce of virtual potential temperature', &
      & units='K', xtype='double' )

    !$B29EY>qMp(B
    call HistoryAddVariable(                         &
      & varname='Temp', dims=(/'x','z','t'/),        &
      & longname='disturbunce of temperature',       &
      & units='K', xtype='double' )

    !$BL)EY(B
    call HistoryAddVariable(                          &
      & varname='Rho', dims=(/'x','z','s','t'/),      &
      & longname='Density of condensable components', &
      & units='kg m|-2"', xtype='double' )

    !$BK0OB>x5$05(B
    call HistoryAddVariable(                          &
      & varname='MixRtSat', dims=(/'x','z','s','t'/),      &
      & longname='Saturated Mixing ratio of condensable components', &
      & units='kg kg|-1"', xtype='double' )

    call HistoryAddVariable(                                         &
      & varname='Cloud2Rain', dims=(/'x','z','s','t'/),              &
      & longname='WarmRainPrm Cloud2Rain of condensable components', &
      & units='kg kg|-1"', xtype='double' ) 
 
    call HistoryAddVariable(                                       &
      & varname='Rain2Gas', dims=(/'x','z','s','t'/),              &
      & longname='WarmRainPrm Rain2Gas of condensable components', &
      & units='kg kg|-1"', xtype='double' ) 

    call HistoryAddVariable(                                        &
      & varname='FallRain', dims=(/'x','z','s','t'/),               &
      & longname='WarmRainPrm FallRain of condensable components',  &
      & units='kg kg|-1"', xtype='double' ) 

    call HistoryAddVariable(                                        &
      & varname='BuoyAll', dims=(/'x','z','t'/),                       &
      & longname='Buoyancy',                                        &
      & units=' ', xtype='double' ) 

    call HistoryAddVariable(                                        &
      & varname='Buoy', dims=(/'x','z','t'/),                       &
      & longname='Buoyancy',                                        &
      & units=' ', xtype='double' ) 

    call HistoryAddVariable(                                        &
      & varname='MoistBuoy', dims=(/'x','z','t'/),                  &
      & longname='Buoyancy of condensable components',              &
      & units=' ', xtype='double' ) 

    call HistoryAddVariable(                                        &
      & varname='AdvKm', dims=(/'x','z','t'/),                  &
      & longname='Advection of Km',              &
      & units=' ', xtype='double' ) 

    call HistoryAddVariable(                                        &
      & varname='BuoyKm', dims=(/'x','z','t'/),                  &
      & longname='Buoyancy of Km',              &
      & units=' ', xtype='double' ) 

    call HistoryAddVariable(                                        &
      & varname='MoistBuoyKm', dims=(/'x','z','t'/),                  &
      & longname='Moist Buoyancy of Km',              &
      & units=' ', xtype='double' ) 

    call HistoryAddVariable(                                        &
      & varname='ShearKm', dims=(/'x','z','t'/),                  &
      & longname='Shear of Km',              &
      & units=' ', xtype='double' ) 

    call HistoryAddVariable(                                        &
      & varname='NumDiffKm', dims=(/'x','z','t'/),                  &
      & longname='Numerical Diffusion of Km',              &
      & units=' ', xtype='double' ) 

    call HistoryAddVariable(                                        &
      & varname='DispKm', dims=(/'x','z','t'/),                  &
      & longname='Dissipation of Km',              &
      & units=' ', xtype='double' ) 

    
    !-------------------------------------------------------------
    ! $B4pK\>l$N%U%!%$%k=PNO(B
    !-------------------------------------------------------------
    call HistoryPut( 'DensBasicZ',     xz_DensBasicZ(FileXMin:FileXMax, FileZMin:FileZMax))
    call HistoryPut( 'ExnerBasicZ',    xz_ExnerBasicZ(FileXMin:FileXMax, FileZMin:FileZMax))
    call HistoryPut( 'PotTempBasicZ',  xz_PotTempBasicZ(FileXMin:FileXMax, FileZMin:FileZMax))
    call HistoryPut( 'VelSoundBasicZ', xz_VelSoundBasicZ(FileXMin:FileXMax, FileZMin:FileZMax))
    call HistoryPut( 'TempBasicZ',     xz_TempBasicZ(FileXMin:FileXMax, FileZMin:FileZMax))
    call HistoryPut( 'PressBasicZ',    xz_PressBasicZ(FileXMin:FileXMax, FileZMin:FileZMax))
    call HistoryPut( 'MixRtBasicZ',    xza_MixRtBasicZ(FileXMin:FileXMax, FileZMin:FileZMax, 1:SpcNum))
    call HistoryPut( 'EffMolWtBasicZ', xz_EffMolWtBasicZ(FileXMin:FileXMax, FileZMin:FileZMax))
    
  end subroutine HistoryFile_Open


!!!------------------------------------------------------------------------------!!!
  subroutine HistoryFile_OutPut(   &
    & Time,                        &
    & xz_PotTemp,                  &
    & xz_Exner,                    &   
    & pz_VelX,                     &
    & xr_VelZ,                     &
    & xza_MixRt,                    &
    & xz_Km        )
    !
    !$BM=JsJQ?t$N%R%9%H%j%U%!%$%k$X$N=PNO(B. $B=PNO;~$K$OH>3J;RE@$N0LCV$G%W%m%C%H$9$k(B. 
    !
    
    !$B%b%8%e!<%kFI$_9~$_(B
    use average,   only: xz_avr_pz, xz_avr_xr

    !$B0EL[$N7?@k8@6X;_(B
    implicit none
    
    !$BJQ?tDj5A(B
    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) :: xza_MixRt(DimXMin:DimXMax, DimZMin:DimZMax, SpcNum)

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

    !----------------------------------------------------------------
    ! $B3J;RE@0LCV$rJQ49(B
    !----------------------------------------------------------------
    xz_VelX = xz_avr_pz( pz_VelX )
    xz_VelZ = xz_avr_xr( xr_VelZ )
    

    !----------------------------------------------------------------
    ! $BCM$r=PNO(B
    !----------------------------------------------------------------
    call HistoryPut( 't', Time )
    
    call HistoryPut('Exner',                                  &
      & xz_Exner(FileXMin:FileXMax, FileZMin:FileZMax) )
    
    call HistoryPut('PotTemp',                                &
      & xz_PotTemp(FileXMin:FileXMax, FileZMin:FileZMax) )
    
    call HistoryPut( 'VelX',                                  &
      & xz_VelX(FileXMin:FileXMax, FileZMin:FileZMax)    )
    
    call HistoryPut( 'VelZ',                                  &
      & xz_VelZ(FileXMin:FileXMax, FileZMin:FileZMax)    )

    call HistoryPut( 'Km',                                    &
      & xz_Km(FileXMin:FileXMax, FileZMin:FileZMax)      )
    
    call HistoryPut( 'MixRt',                                 &
      & xza_MixRt(FileXMin:FileXMax, FileZMin:FileZMax, 1:SpcNum)  )
    
  end subroutine HistoryFile_OutPut


!!!------------------------------------------------------------------------------!!!
  subroutine HistoryFile_OutPutAnal(  &
    &          xz_PotTemp,            &
    &          xz_Exner,              &
    &          pz_VelX,               &
    &          xr_VelZ,               &
    &          xza_MixRt,              &
    &          xz_Km                  &
    &         )
    !
    !$B2r@OMQ$NJQ?t$N%R%9%H%j%U%!%$%k$X$N=PNO(B.
    !

    use Average,       only: xz_avr_xr
    use WarmRainPrm, only: xz_FallRain, xza_Cloud2Rain, xza_Rain2Gas, xza_Rain2GasNH4SH
    use DynFunc
    use MoistBuoyancy
    use Turbulence
    use NumDiffusion    
    
    !$B0EL[$N7?@k8@6X;_(B
    implicit none
    
    !$BJQ?tDj5A(B
    real(8), intent(in) :: xz_PotTemp(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8), intent(in) :: xz_Exner(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8), intent(in) :: pz_VelX(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8), intent(in) :: xr_VelZ(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8), intent(in) :: xza_MixRt(DimXMin:DimXMax, DimZMin:DimZMax, SpcNum)
    real(8), intent(in) :: xz_Km(DimXMin:DimXMax, DimZMin:DimZMax)

    real(8)             :: xz_Temp(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8)             :: xz_VPotTemp(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8)             :: xz_Rho(DimXMin:DimXMax, DimZMin:DimZMax,SpcNum)
    real(8)             :: xz_CloudPhys1(DimXMin:DimXMax, DimZMin:DimZMax,SpcNum)
    real(8)             :: xz_CloudPhys2(DimXMin:DimXMax, DimZMin:DimZMax,SpcNum)
    real(8)             :: xz_CloudPhys3(DimXMin:DimXMax, DimZMin:DimZMax,SpcNum)
    real(8)             :: xz_Buoy(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8)             :: xz_MoistBuoy(DimXMin:DimXMax, DimZMin:DimZMax)

    real(8)             :: xz_Km1(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8)             :: xz_Km2(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8)             :: xz_Km3(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8)             :: xz_Km4(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8)             :: xz_Km5(DimXMin:DimXMax, DimZMin:DimZMax)
    real(8)             :: xz_Km6(DimXMin:DimXMax, DimZMin:DimZMax)

    integer             :: spc

    
    !----------------------------------------------------------------
    ! $BL)EY(B, $B29EY(B, $B2>290L$N7W;;(B
    !----------------------------------------------------------------
    do spc = 1, SpcNum
      xz_Rho(:,:,spc) =                                                       &
        &  xz_DensBasicZ(:,:) * ( xza_MixRtBasicZ(:,:,spc) + xza_MixRt(:,:,spc) )
    end do

    xz_Temp = ( xz_Exner + xz_ExnerBasicZ ) * ( xz_PotTemp + xz_PotTempBasicZ ) &
      &       - xz_ExnerBasicZ * xz_PotTempBasicZ 

    xz_VPotTemp = xz_PotTemp / xz_EffMolWtBasicZ 
    
    xz_Buoy      =  xz_avr_xr( xr_Buoy(xz_PotTemp) )
    xz_MoistBuoy =  xz_avr_xr( xr_MoistBuoy(xza_MixRt) )
    
    !----------------------------------------------------------------
    ! $B1@J*M}NL$r7W;;(B
    !----------------------------------------------------------------
    xz_Km1 = xz_AdvScalar(xz_Km, pz_VelX, xr_VelZ)           
    xz_Km2 = xz_BuoyKm(xz_PotTemp)                               
!    xz_Km3 = xz_MoistBuoyKm(xz_Exner, xz_PotTemp, xza_MixRt) 
    xz_Km4 = xz_ShearKm(xz_Km, pz_VelX, xr_VelZ)                
    xz_Km5 = xz_NumDiffScalar(xz_Km)                            
    xz_Km6 = xz_DispKm(xz_Km)                                   

    !----------------------------------------------------------------
    ! $B1@J*M}NL$r7W;;(B
    !----------------------------------------------------------------
    xz_CloudPhys1(:,:,:) = xza_Cloud2Rain( xza_MixRt(:,:,:) )                   
    xz_CloudPhys2(:,:,:) = xza_Rain2Gas(xz_Exner, xz_PotTemp, xza_MixRt(:,:,:)) &
      &                    + xza_Rain2GasNH4SH(xz_Exner, xz_PotTemp, xza_MixRt(:,:,:)) 
    do spc = 1, SpcNum      
      xz_CloudPhys3(:,:,spc) = xz_FallRain(xza_MixRt(:,:,spc), spc)
    end do
    
    !----------------------------------------------------------------
    ! $BCM$r=PNO(B
    !----------------------------------------------------------------
    call HistoryPut( 'Temp',                                            &
      & xz_Temp(FileXMin:FileXMax, FileZMin:FileZMax)    )    
    
    call HistoryPut( 'VPotTemp',                                        &
      & xz_VPotTemp(FileXMin:FileXMax, FileZMin:FileZMax)    )    
    
    call HistoryPut( 'Rho',                                             &
      & xz_Rho(FileXMin:FileXMax, FileZMin:FileZMax, 1:SpcNum) )
    
    call HistoryPut( 'Cloud2Rain',                                      &
      & xz_CloudPhys1(FileXMin:FileXMax, FileZMin:FileZMax, 1:SpcNum) )

    call HistoryPut( 'Rain2Gas',                                        & 
      & xz_CloudPhys2(FileXMin:FileXMax, FileZMin:FileZMax, 1:SpcNum) )
    
    call HistoryPut( 'FallRain',                                        &
      & xz_CloudPhys3(FileXMin:FileXMax, FileZMin:FileZMax, 1:SpcNum) )

    call HistoryPut( 'BuoyAll',                                 &
      &   xz_Buoy(FileXMin:FileXMax, FileZMin:FileZMax)         &
      & + xz_MoistBuoy(FileXMin:FileXMax, FileZMin:FileZMax)  )

    call HistoryPut( 'Buoy',                                          &
      & xz_Buoy(FileXMin:FileXMax, FileZMin:FileZMax) )

    call HistoryPut( 'MoistBuoy',                                          &
      & xz_MoistBuoy(FileXMin:FileXMax, FileZMin:FileZMax) )
    
    call HistoryPut( 'AdvKm',                                         &
      & xz_Km1(FileXMin:FileXMax, FileZMin:FileZMax) )

    call HistoryPut( 'BuoyKm',                                        &
      & xz_Km2(FileXMin:FileXMax, FileZMin:FileZMax) )

    call HistoryPut( 'MoistBuoyKm',                                   &
      & xz_Km3(FileXMin:FileXMax, FileZMin:FileZMax) )

    call HistoryPut( 'ShearKm',                                       &
      & xz_Km4(FileXMin:FileXMax, FileZMin:FileZMax) )

    call HistoryPut( 'NumDiffKm',                                     &
      & xz_Km5(FileXMin:FileXMax, FileZMin:FileZMax) )

    call HistoryPut( 'DispKm',                                        &
      & xz_Km6(FileXMin:FileXMax, FileZMin:FileZMax) )


  end subroutine HistoryFile_OutPutAnal


!!!------------------------------------------------------------------------------!!!
  subroutine HistoryFile_Close
    !
    !$B%R%9%H%j%U%!%$%k$N%/%m!<%:(B
    !
    
    !$B0EL[$N7?@k8@6X;_(B
    implicit none

    !$B%U%!%$%k$rJD$8$k(B
    call HistoryClose
  
  end subroutine HistoryFile_Close


end module HistoryFileIO
