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

# ----- コマンドラインオプション -----
file = "ens-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')
tro_2 = (GPhys::IO.open file, 'tro_flux2')
cli_1 = (GPhys::IO.open file, 'cli_flux1')
cli_2 = (GPhys::IO.open file, 'cli_flux2')
cli_3 = (GPhys::IO.open file, 'cli_flux3')

# ----- 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"
tro_2_cli_1 = tro_2 + cli_1
tro_2_cli_1.name = "barotro II+barocli I"
cli_2_cli_3 = cli_2 + cli_3
cli_2_cli_3.name = "barocli II+barocli III"

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"=>"Enstrophy Flux")
GGraph.line tro_flux.cut("t"=>t0..t1).mean('t'),true,"title"=>"Enstrophy Flux","legend"=>true,"type"=>1, "max"=>7.5*10**(0), "min"=>-2.0*10**(0),"index"=>9
GGraph.line tro_2_cli_1.cut("t"=>t0..t1).mean('t'),false,"legend"=>true,"type"=>2, "index"=>9
GGraph.line cli_2_cli_3.cut("t"=>t0..t1).mean('t'),false,"legend"=>true,"type"=>3, "index"=>9

DCL.grcls      # 描画終了処理
