!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= Module DistrbSet
!
!   * Developer: SUGIYAMA Ko-ichiro (sugiyama@gfd-dennou.org)
!   * Version: $Id: distrbset.f90,v 1.2 2005/01/28 12:41:21 sugiyama Exp $ 
!   * Tag Name: $Name:  $
!   * Change History: 
!
!== Overview 
!
!擾乱場の初期値を netCDF ファイルから取得する. 
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!== Future Plans
!
                                                                 !=end

module distrbset
  implicit none
  save
                                                                 !=begin
  !== Public Interface
  real(8), allocatable   :: fs_VelXDistrb(:,:)  !速度 u
  real(8), allocatable   :: sf_VelZDistrb(:,:)  !速度 w
  real(8), allocatable   :: ss_ExnerDistrb(:,:) !無次元圧力
  real(8), allocatable   :: ss_PotTempDistrb(:,:) !温位
                                                                 !=end

contains
                                                                 !=begin
  !== Procedure Interface 
  !
  !=== Initialize module and acquire NAMELIST
  !
  !擾乱場の初期値を netCDF ファイルから取得する. 
  !netCDF から値を取得するために gt4f90io を利用する. 
  !

  subroutine distrbset_init(distrbfile)
    !=== Dependency
    use gt4_history
    use bcset,   only: ss_BC, sf_BC, fs_BC
    use gridset, only: DimXMin, DimXMax, DimZMin, DimZMax

    !=== Input 
    character(*), intent(in)  :: distrbfile  !擾乱場のファイル
                                                                 !=end    
    character(20)  :: name            !変数名
    
    !--- 配列の割り当て
    allocate(  &
         & fs_VelXDistrb(DimXMin:DimXMax, DimZMin:DimZMax), &
         & sf_VelZDistrb(DimXMin:DimXMax, DimZMin:DimZMax), &
         & ss_ExnerDistrb(DimXMin:DimXMax, DimZMin:DimZMax), &
         & ss_PotTempDistrb(DimXMin:DimXMax, DimZMin:DimZMax) )
                                                                 !=begin
    !=== Get a Value from netCDF File
    name = "VelXDistrb"
    call HistoryGet( distrbfile, name, fs_VelXDistrb )

    name = "VelZDistrb"
    call HistoryGet( distrbfile, name, sf_VelZDistrb )

    name = "ExnerDistrb"
    call HistoryGet( distrbfile, name, ss_ExnerDistrb )

    name = "PotTempDistrb"
    call HistoryGet( distrbfile, name, ss_PotTempDistrb )
                                                                 !=end

    !--- 境界条件
    call boundary( ss_BC, ss_ExnerDistrb )
    call boundary( ss_BC, ss_PotTempDistrb )
    call boundary( fs_BC, fs_VelXDistrb )
    call boundary( sf_BC, sf_VelZDistrb )


  end subroutine distrbset_init
  
end module distrbset
