!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= Subroutine OutputDiagDataFile
!
!   * Developer: KITAMORI Taichi
!   * Version: $Id: outputdiagdatafile.f90,v 1.1.2.6 2005/09/17 07:52:18 kitamo Exp $ 
!   * Tag Name: $Name: arare3m $
!   * Change History: 
!
!== Overview 
!
!診断量をファイル出力.
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!== Future Plans
!
                                                                 !=end

subroutine OutputDiagDataFile(history,   & 
     & Time, & 
     & s_PotTempTendAdvZ_nl,  & 
     & s_PotTempTendSrcZ_nl,  & 
     & s_PotTempTendTurbZ_nl, & 
     & s_PotTempTendRadZ_nl,  &
     & s_PotTempTendDisZ_nl,  &
     & s_PotTempTendSfcZ_nl,  &
     & MassTotal,             &
     & KineticEnergyTotal,    &
     & PotentialEnergyTotal)

                                                                 !=begin
  !== Dependency
  use gt4_history
  use dc_trace, only: BeginSub, EndSub
  use gridset, only: FileZMin, FileZMax, DimZMin,  DimZMax
                                                                !=end
  !== 暗黙の型宣言禁止
  implicit none
                                                                 !=begin
  !== Input
  type(GT_HISTORY), intent(inout) :: history
  real(8), intent(in) :: Time
  real(8), intent(in) :: s_PotTempTendAdvZ_nl(DimZMin:DimZMax)
  real(8), intent(in) :: s_PotTempTendSrcZ_nl(DimZMin:DimZMax)
  real(8), intent(in) :: s_PotTempTendTurbZ_nl(DimZMin:DimZMax)
  real(8), intent(in) :: s_PotTempTendRadZ_nl(DimZMin:DimZMax)
  real(8), intent(in) :: s_PotTempTendDisZ_nl(DimZMin:DimZMax)
  real(8), intent(in) :: s_PotTempTendSfcZ_nl(DimZMin:DimZMax)
  real(8), intent(in) :: MassTotal
  real(8), intent(in) :: KineticEnergyTotal
  real(8), intent(in) :: PotentialEnergyTotal
                                                                 !=end
  
  call BeginSub("OutputDiagDataFile", &
       &         fmt="%c",            &
       &         c1="Output diagnostic values in netCDF file.")

  !=== 値を出力
  call HistoryPut( 't', Time, history )

  ! 熱の式の各項の寄与

  call HistoryPut( 'PotTempTendAdvZ',    &
       & s_PotTempTendAdvZ_nl(FileZMin:FileZMax), history )
  call HistoryPut( 'PotTempTendSrcZ',    &
       & s_PotTempTendSrcZ_nl(FileZMin:FileZMax), history )
  call HistoryPut( 'PotTempTendTurbZ',    &
       & s_PotTempTendTurbZ_nl(FileZMin:FileZMax), history )
  call HistoryPut( 'PotTempTendRadZ',    &
       & s_PotTempTendRadZ_nl(FileZMin:FileZMax), history )
  call HistoryPut( 'PotTempTendDisZ',    &
       & s_PotTempTendDisZ_nl(FileZMin:FileZMax), history )
  call HistoryPut( 'PotTempTendSfcZ',    &
       & s_PotTempTendSfcZ_nl(FileZMin:FileZMax), history )

  ! 保存量

  call HistoryPut( 'MassTotal', MassTotal, history )
  call HistoryPut( 'KineticEnergyTotal', KineticEnergyTotal, history )
  call HistoryPut( 'PotentialEnergyTotal', PotentialEnergyTotal, history )

  call EndSub("OutputDiagDataFile")
  
end subroutine OutputDiagDataFile

