# -*- coding: euc-jp -*-
require "numru/ggraph"
include NumRu

#
# = 初期の擾乱場をかくスクリプト
#
# * 初期の all の値から基本場を引いただけ
# * 対応 (予定) 物理量
#   * 温位
#   * 温度
#   * 水蒸気混合比？
#
# * 履歴
#   * 2013/01/24 新規作成
#
##########################################

var = ARGV[0]

x1 = 0
x2 = 256000
z1 = 0
#z2 = 30000
#z2 = 36000
z2 = 48000

files = "thermal-moist_TempAll.nc"
gphysTempAll  = GPhys::IO.open(files, 'TempAll')
files = "thermal-moist_PTempAll.nc"
gphysPTempAll = GPhys::IO.open(files, 'PTempAll')
files = "thermal-moist_H2O-gAll.nc"
gphysH2OgAll  = GPhys::IO.open(files, 'H2O-gAll')
files = "thermal-moist_restart.nc"
gphysTempBZ   = GPhys::IO.open(files, 'TempBZ')
files = "thermal-moist_restart.nc"
gphysPTempBZ  = GPhys::IO.open(files, 'PTempBZ')
files = "thermal-moist_restart.nc"
gphysQMixBZ   = GPhys::IO.open(files, 'QMixBZ')

#DCL.gropn(1)
DCL.gropn(2)
#DCL.sldiv('y',1,2)
DCL.sgpset('lfull',true)
DCL.sgpset('lcntl',false)
DCL.uzfact(0.7)
#DCL.uzfact(0.3)
#GGraph.set_fig( 'viewport'=>[0.25,0.7,0.15,0.6] )
# アスペクト比をそれっぽくする
GGraph.set_fig( 'viewport'=>[0.1,0.85,0.15,0.6] )
#GGraph.set_fig( 'viewport'=>[0.25,0.8,0.10,0.275] )

#xax = gphys1.coord(0)
#zax = gphys1.coord(2)
#tax = gphys1.coord(0)

gphysTempBZ = gphysTempBZ.cut( 'x'=>x1..x2 )
gphysTempBZ = gphysTempBZ.cut( 'z'=>z1..z2 )
gphysPTempBZ = gphysPTempBZ.cut( 'x'=>x1..x2 )
gphysPTempBZ = gphysPTempBZ.cut( 'z'=>z1..z2 )
gphysQMixBZ = gphysQMixBZ.cut( 's'=>1 )
gphysQMixBZ = gphysQMixBZ.cut( 'x'=>x1..x2 )
gphysQMixBZ = gphysQMixBZ.cut( 'z'=>z1..z2 )

gphysTempDist = gphysTempAll.cut( 't'=>0 ) - gphysTempBZ
gphysTempDist = gphysTempDist.mean( 'y' )
gphysTempDist = gphysTempDist.cut( 'x'=>0..10000 )
gphysTempDist = gphysTempDist.cut( 'z'=>0..10000 )

gphysPTempDist = gphysPTempAll.cut( 't'=>0 ) - gphysPTempBZ
gphysPTempDist = gphysPTempDist.mean( 'y' )
gphysPTempDist = gphysPTempDist.cut( 'x'=>0..10000 )
gphysPTempDist = gphysPTempDist.cut( 'z'=>0..10000 )

gphysH2OgDist = gphysH2OgAll.cut( 't'=>0 ) - gphysQMixBZ
gphysH2OgDist = gphysH2OgDist.mean( 'y' )
gphysH2OgDist = gphysH2OgDist.cut( 'x'=>0..10000 )
gphysH2OgDist = gphysH2OgDist.cut( 'z'=>0..10000 )

#gphysdisp = gphysdisp1

if var == "Temp"
    gphysdisp = gphysTempDist
  elsif var == "PTemp"
    gphysdisp = gphysPTempDist
  elsif var == "H2Og" or var == "H2O-g"
    gphysdisp = gphysH2OgDist
  else
    p "No such variables."
end

#GGraph.line( gphysdisp, true, 'exchange'=>true ) 
GGraph.tone( gphysdisp, true )

GGraph.color_bar

DCL.grcls
