!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= Subroutine GetDisturbVar
!
!   * Developer: SUGIYAMA Ko-ichiro (sugiyama@gfd-dennou.org)
!   * Version: $Id: getdisturbvar.f90,v 1.2 2005/04/22 15:01:52 sugiyama Exp $ 
!   * Tag Name: $Name:  $
!   * Change History: 
!
!== Overview 
!
!$B>qMp>l$N=i4|CM$r(B netCDF $B%U%!%$%k$+$i<hF@$9$k(B. 
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!== Future Plans
!
!   * $B;~4V9o$_$N%A%'%C%/$@$1$G$J$/(B, $B2rA|EY$N%A%'%C%/$*$h$SJ*M}Dj?t$N%A%'%C%/$bI,MW$@$m$&(B.
!
                                                                 !=end
subroutine GetDisturbVar(disturbfile, ReStartTime,   &
     & fs_VelX_b,    sf_VelZ_b, ss_Exner_b, &
     & ss_PotTemp_b, ss_Km_b,   ss_Kh_b,    &
     & ss_MixRtSat_b, ss_MixRtV_b, ss_MixRtC_b, ss_MixRtR_b, &
     & fs_VelX_n,    sf_VelZ_n, ss_Exner_n, &
     & ss_PotTemp_n, ss_Km_n,   ss_Kh_n,    &
     & ss_MixRtV_n, ss_MixRtC_n, ss_MixRtR_n )
                                                                 !=begin
  !== Dependency
  use gt4_history
  use dc_trace,   only: BeginSub, EndSub
  use dc_message ,only: MessageNotify
  use timeset,    only: DelTimeLong
  use gridset,    only: DimXMin, DimXMax, DimZMin, DimZMax
                                                                 !=end    
  !== $B0EL[$N7?@k8@6X;_(B
  implicit none
                                                                 !=begin
  !== Input 
  character(*), intent(in)  :: disturbfile  !$B>qMp>l$N%U%!%$%k(B

  !== Output
  real(8), intent(out)  :: ReStartTime(2)
  real(8), intent(out)  :: fs_VelX_n(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: fs_VelX_b(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: sf_VelZ_n(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: sf_VelZ_b(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_Exner_n(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_Exner_b(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_PotTemp_n(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_PotTemp_b(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_Km_n(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_Km_b(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_Kh_n(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_Kh_b(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_MixRtSat_b(DimXMin:DimXMax, DimZMin:DimZMax)  
  real(8), intent(out)  :: ss_MixRtV_n(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_MixRtV_b(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_MixRtC_n(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_MixRtC_b(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_MixRtR_n(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)  :: ss_MixRtR_b(DimXMin:DimXMax, DimZMin:DimZMax)
                                                                 !=end    
  !== Work
  real           :: DelTime
  character(30)  :: name            !$BJQ?tL>(B
  

  call BeginSub("GetDisturbVar", &
&                 fmt="%c",       &
&                 c1="Input initial disturbance variables.")

  !=== Get a Value from netCDF File
  name = "t"
  call HistoryGet( disturbfile, name, ReStartTime )

  !=== $B;~4V9o$_$N%A%'%C%/(B
  DelTime = ReStartTime(2) - ReStartTime(1)
  if ( DelTime /= real(DelTimeLong, 4) ) then 
    write(*,*) DelTime, DelTimeLong
    call MessageNotify("Error", "getdistrbvar", &
      &    "DelTime for ReStartFile is not the same as DelTimeLong")
    stop
  end if
  

  !=== Get a Value from netCDF File 
  name = "VelX_n"
  call HistoryGet( disturbfile, name, fs_VelX_n )
  
  name = "VelX_b"
  call HistoryGet( disturbfile, name, fs_VelX_b )
  
  name = "VelZ_n"
  call HistoryGet( disturbfile, name, sf_VelZ_n )
  
  name = "VelZ_b"
  call HistoryGet( disturbfile, name, sf_VelZ_b )
  
  name = "Exner_n"
  call HistoryGet( disturbfile, name, ss_Exner_n )
  
  name = "Exner_b"
  call HistoryGet( disturbfile, name, ss_Exner_b )
  
  name = "PotTemp_n"
  call HistoryGet( disturbfile, name, ss_PotTemp_n )
  
  name = "PotTemp_b"
  call HistoryGet( disturbfile, name, ss_PotTemp_b )

  name = "Km_n"
  call HistoryGet( disturbfile, name, ss_Km_n )
  
  name = "Km_b"
  call HistoryGet( disturbfile, name, ss_Km_b )
  
  name = "Kh_n"
  call HistoryGet( disturbfile, name, ss_Kh_n )
  
  name = "Kh_b"
  call HistoryGet( disturbfile, name, ss_Kh_b )
  
  name = "MixRtSat"
  call HistoryGet( disturbfile, name, ss_MixRtSat_b )
  
  name = "MixRtV_n"
  call HistoryGet( disturbfile, name, ss_MixRtV_n )
  
  name = "MixRtV_b"
  call HistoryGet( disturbfile, name, ss_MixRtV_b )
  
  name = "MixRtC_n"
  call HistoryGet( disturbfile, name, ss_MixRtC_n )
  
  name = "MixRtC_b"
  call HistoryGet( disturbfile, name, ss_MixRtC_b )
  
  name = "MixRtR_n"
  call HistoryGet( disturbfile, name, ss_MixRtR_n )
  
  name = "MixRtR_b"
  call HistoryGet( disturbfile, name, ss_MixRtR_b )
  
  call EndSub("GetDisturbVar")
  
end subroutine GetDisturbVar
