# -*- coding: utf-8 -*-
# エネルギーの散逸と強制のスペクトルを描く
require "numru/ggraph"
include NumRu

# ----- コマンドラインオプション -----
iws = ( ARGV[0] || 1 ).to_i     # 装置番号 (1,2,or 4)
tsleep = [ ( ARGV[3] || 0.0 ).to_f, 0.0 ].max  # 第5引数は描画間隔(秒)
wait = ( tsleep <= 0.0 )            #->true/false; 0以下(true)ならマウスクリックを待つ

# ----- 使用データ -----
tro_term4 = GPhys::IO.open "ek-analysis.nc", 'tro_T4'
tro_term5 = GPhys::IO.open "ek-analysis.nc", 'tro_T5'
cli_term5 = GPhys::IO.open "ek-analysis.nc", 'cli_T5'
cli_term6 = GPhys::IO.open "ek-analysis.nc", 'cli_T6'
cli_term7 = GPhys::IO.open "ek-analysis.nc", 'cli_T7'

# ----- 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.swpset("ifl",1)          # png で出力
  DCL.gropn(iws)
  DCL.sgpset('isub', 96)       # 下付き添字を表す制御文字を '_' から '`' に
  DCL.sgscmn(39)               # カラーマップ番号の指定
  DCL.sglset("lcntl",true)     # 上付き下付き文字を有効
  DCL.sgiset("ifont",2)
  DCL.glpset('lmiss',true)     # DCLの欠損値処理を on に
end

forcing = cli_term5.copy
forcing.name = "forcing"
ekman = tro_term4 + cli_term6
ekman.name = "Ekman"
dissipation = tro_term5 + cli_term7
dissipation.name = "viscosity"

title = DCL.csgi(131) + DCL.csgi(164) + "= -5.280" + DCL.csgi(194) + '10|-17"'

prep_dcl(iws,wait)
t0 = 300
t1 = 500
GGraph.set_fig("itr"=>3,"viewport"=>[0.2, 0.7, 0.2, 0.8])
GGraph.set_axes("ytitle"=>" ","xtitle"=>"k",'xside'=>'b', 'yside'=>'l')
#--------- 全波数 ---------
GGraph.line forcing.cut("t"=>t0..t1).mean("t"),true,"title"=>title,"max"=>8.0*10**(-2),"min"=>-7.0*10**(-2),"legend"=>true,"type"=>1,"index"=>283,"annotate"=>false
GGraph.line ekman.cut("t"=>t0..t1).mean("t"),false,"legend"=>true,"type"=>1,"index"=>863
GGraph.line dissipation.cut("t"=>t0..t1).mean("t"),false,"legend"=>true,"type"=>1,"index"=>503
#--------- 変形半径より高波数側のみ ---------
GGraph.line forcing.cut("t"=>t0..t1,"n"=>10..341).mean("t"),true,"title"=>title,"max"=>5.0*10**(-5),"min"=>-2.5*10**(-4),"legend"=>true,"type"=>1,"index"=>283,"annotate"=>false
GGraph.line ekman.cut("t"=>t0..t1,"n"=>10..341).mean("t"),false,"legend"=>true,"type"=>1,"index"=>863
GGraph.line dissipation.cut("t"=>t0..t1,"n"=>10..341).mean("t"),false,"legend"=>true,"type"=>1,"index"=>503

DCL.grcls      # 描画終了処理
