!= Module initialdata_Odaka2001
!
! Authors::   MURAHASHI Kuriki
! Version::   $Id: initialdata_odaka2001.f90,v 1.0 2015-12-11 04:49:40 mkuriki Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2006. All rights reserved.
! License::   See COPYRIGHT[link:../../COPYRIGHT]

module initialdata_odaka2001
  !
  ! Odaka et al. (2001) を用いて初期値を与える(mkuriki)
  ! gtool5 関連 
  ! gtool5 modules
  !
  ! gtool の nc データ読み込み用の関数を追加 (mkuriki)
  use gtool_history, only: HistoryGet

  !モジュール読み込み
  use dc_types,   only: STRING, DP
  use dc_iounit,   only : FileOpen      
  use dc_message, only: MessageNotify
!  use mpi_wrapper, only: myrank         
  use gridset,  only: kmin,       &!配列の Z 方向の下限
    &                 kmax,       &!配列の Z 方向の上限
    &                 nz
  use axesset, only:  z_Z,        &!スカラー格子点での高度
    &                 z_dz         !Z 方向の格子点間隔
  use constants, only: &
    &                 GasRDry,       &!乾燥成分の定圧比熱
    &                 CpDry,         &!乾燥成分の定圧比熱
    &                 Grav,          &!重力加速度
    &                 TempSfc,       &!地表面温度
    &                 PressSfc        !地表面圧力
 
  !暗黙の型宣言禁止
  implicit none

  !デフォルトは private
  private

  real(DP), parameter  :: AntA    = 27.4d0 
  real(DP), parameter  :: AntB    = 3103.0d0
  real(DP), parameter  :: TempLTP = 135.0d0
  real(DP), parameter  :: Dhight  = 6.0d2

  !初期化だけ公開
  public  initialdata_odaka2001_basic

contains

!!!------------------------------------------------------------------------------!!!

  subroutine initialdata_odaka2001_basic( z_Temp, z_Press )

    implicit none
    
    real(DP), intent(out):: z_Press(kmin:kmax)           !圧力
    real(DP), intent(out):: z_Temp(kmin:kmax)            !温度
    integer              :: k
    real(DP)             :: srcProf(1:205) ! 外部データを読み込む配列
    

    ! ncSrc/vprof.nc より気温の鉛直分布を読み込む
    !
    call HistoryGet('ncSrc/vprof.nc', 'temp', srcProf, range='t=30') 
    do k = 1, nz
      z_Temp(k) = srcProf(k + 5)
    end do

    z_Press(1) = PressSfc - (Grav * PressSfc * z_dz(1) * 5.0d-1) / (GasRDry * TempSfc)
    ! 静水圧平衡から圧力を決める
    !
    do k = 2, nz
      z_Press(k) = z_Press(k-1) - (Grav * z_Press(k-1) * z_dz(k-1)) &
        & / ( GasRDry * z_Temp(k-1) )
    end do

  end subroutine initialdata_odaka2001_basic
  
end module initialdata_odaka2001
