!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= Subroutine OutputDataFile
!
!   * Developer: SUGIYAMA Ko-ichiro
!   * Version: $Id: outputdatafile.f90,v 1.2.2.1 2005/09/01 14:44:23 kitamo Exp $ 
!   * Tag Name: $Name: arare3m-20051114 $
!   * Change History: 
!
!== Overview 
!
!ファイル出力. 長い時間ステップの値を出力.
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!== Future Plans
!
                                                                 !=end

subroutine OutputDataFile(history, Time, &
     & fs_VelX_nl, sf_VelZ_nl, ss_Exner_nl, ss_PotTemp_nl, ss_Km_nl, ss_Kh_nl)
                                                                 !=begin
  !== Dependency
  use gt4_history
  use dc_trace, only: BeginSub, EndSub
  use gridset, only: FileXMin, FileXMax, FileZMin, FileZMax, &
       &             DimXMin,  DimXMax,  DimZMin,  DimZMax
  use average, only: ss_avr_fs, ss_avr_sf
                                                                 !=end
  !== 暗黙の型宣言禁止
  implicit none
                                                                 !=begin
  !== Input/Output
  type(GT_HISTORY), intent(inout) :: history
  real(8), intent(in) :: Time
  real(8), intent(in) :: fs_VelX_nl(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(in) :: sf_VelZ_nl(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(in) :: ss_Exner_nl(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(in) :: ss_PotTemp_nl(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(in) :: ss_Km_nl(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(in) :: ss_Kh_nl(DimXMin:DimXMax, DimZMin:DimZMax)
                                                                 !=end
  !== Work
  real(8)             :: ss_VelX_nl(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8)             :: ss_VelZ_nl(DimXMin:DimXMax, DimZMin:DimZMax)

  
  call BeginSub("OutputDataFile", &
       &         fmt="%c",            &
       &         c1="Output variables in netCDF file.")


  !=== 格子点位置を変換
  ss_VelX_nl = ss_avr_fs( fs_VelX_nl )
  ss_VelZ_nl = ss_avr_sf( sf_VelZ_nl )


  !=== 値を出力
  call HistoryPut( 't', Time, history )
  
  call HistoryPut( 'Exner',   &
       & ss_Exner_nl(FileXMin:FileXMax, FileZMin:FileZMax), history   )
  call HistoryPut( 'PotTemp', &
       & ss_PotTemp_nl(FileXMin:FileXMax, FileZMin:FileZMax), history )
  call HistoryPut( 'Km',      &
       & ss_Km_nl(FileXMin:FileXMax, FileZMin:FileZMax), history      )
  call HistoryPut( 'Kh',      &
       & ss_Kh_nl(FileXMin:FileXMax, FileZMin:FileZMax), history      )
  call HistoryPut( 'VelX',    &
       & ss_VelX_nl(FileXMin:FileXMax, FileZMin:FileZMax), history    )
  call HistoryPut( 'VelZ',    &
       & ss_VelZ_nl(FileXMin:FileXMax, FileZMin:FileZMax), history    )

  
  call EndSub("OutputDataFile")
  
end subroutine OutputDataFile

