# -*- coding: utf-8 -*-
require "numru/ggraph"
include NumRu
include Math

# ----- コマンドラインオプション -----
file = "ek-analysis.nc" # 第1引数はスペクトルを取り出してくるファイル名(必須)
iws = ( ARGV[0] || 1 ).to_i                    # 装置番号 (1,2,or 4)
tsleep = [ ( ARGV[1] || 0.0 ).to_f, 0.0 ].max  # 描画間隔(秒)
wait = ( tsleep <= 0.0 )            #->true/false; 0以下(true)ならマウスクリックを待つ

# ----- 使用データ -----
tro_flux    = (GPhys::IO.open file, 'tro_flux1')
cli_flux    = (GPhys::IO.open file, 'cli_flux3')
tro_2 = (GPhys::IO.open file, 'tro_flux2')
cli_2 = (GPhys::IO.open file, 'cli_flux2')

# ----- DCL設定 -----
def prep_dcl(iws=1,wait=false) # iws : DCL出力デバイス．1,4:画面, 2:PS
  DCL.swpset("iwidth",700)     # 画面の幅
  DCL.swpset("iheight",700)    # 画面の高さ
  DCL.swpset("lwait",wait)     # 次の描画の前にマウスクリックを待つ
  DCL.swpset("lalt",true)      # 裏で描画（パラパラアニメ用）
  DCL.gropn(iws)
  DCL.sgpset('isub', 96)       # 下付き添字を表す制御文字を '_' から '`' に
  DCL.glpset('lmiss',true)     # DCLの欠損値処理を on に
end

tro_flux = tro_flux.copy
tro_flux.name = "barotropic I"
cli_flux = cli_flux.copy
cli_flux.name = "baroclinic III"
tro_cli_2 = tro_2 + cli_2
tro_cli_2.name = "barotro+barocli II"

t0=300
t1=500

# ----- 描画 -----
prep_dcl(iws,wait)
GGraph.set_fig("itr"=>3,"viewport"=>[0.20, 0.6, 0.25, 0.6])
GGraph.set_axes("ytitle"=>"Energy Flux")
GGraph.line tro_flux.cut("t"=>t0..t1).mean('t'),true,"title"=>"Energy Flux","legend"=>true,"type"=>2, "max"=>6.0*10**(-2), "min"=>-6.0*10**(-2),"index"=>6
GGraph.line cli_flux.cut("t"=>t0..t1).mean('t'),false,"legend"=>true,"type"=>3,"index"=>6
GGraph.line tro_cli_2.cut("t"=>t0..t1).mean('t'),false,"legend"=>true,"type"=>4,"index"=>6

DCL.grcls      # 描画終了処理
