require "numru/ggraph"
include NumRu
# 水蒸気混合比擾乱の初期場分を引くタイプ(乾燥肌用)
### ARGV[0] は引数をもってくるときつかう
time  = ARGV[0].to_i

#time = 1200

### 範囲指定
x1 = 10000
x2 = 30000
z1 = 0
z2 = 20000
#ymid = 10000

files = "thermal1_H2O-g.nc"
gphys  = GPhys::IO.open(files, 'H2O-g')


#DCL.gropn(1)
DCL.gropn(2)
#DCL.sldiv('y',1,2)           # 複数枚のときにいる( 'y方向に'1x2') で分割
DCL.sgpset('lfull',true)
DCL.sgpset('lcntl', false)
#DCL.sgpset('lclip', true)
DCL.uzfact(0.6)
GGraph.set_fig( 'viewport'=>[0.3, 0.6, 0.2, 0.5] )
#xmin,xmax,ymin,ymax
#-- axis じゃないとだめ. coord では to_gphys が通らない
xax = gphys.axis(0)
zax = gphys.axis(2)

#p xax
#p zax

xax = xax.to_gphys.cut('x'=>x1..x2)
zax = zax.to_gphys.cut('z'=>z1..z2)

gphys = gphys.cut( 'x'=>x1..x2 )
gphys = gphys.cut( 'z'=>z1..z2 )

### 時間でカット
gphysinit0 = gphys.cut( 't'=>0 )
gphysdisp0 = gphys.cut( 't'=>time )
#-- 初期場の擾乱分を毎回引く
gphysdisp0 = gphysdisp0 - gphysinit0

gphysdisp0 = gphysdisp0.mean( 'y' )
#gphysdisp0 = gphysdisp0.cut( 'y'=>ymid )

### x平均からの差分を出すとき
#gphysdisp0 = gphysdisp0 - gphysdisp0.mean( 'x' )

gphysdisp = gphysdisp0
GGraph.fig( xax, zax, 'new_frame'=>true ) 
## new_frame fales の場合 'viewport'=>[0.25,0.9,vpy1,vpy2], 'window'=>[x1,x2,z1,z2] )
GGraph.tone( gphysdisp, false, 
#             'lev'=>[260,280,300,320,340,360,380,400,420,440,460],
#             'lev'=>[-2.5,-2.0,-1.5,-1.0,-0.5,0,0.5,1.0,1.5,2.0,2.5],
           'lev'=>[-1.2e-2, -1e-2,-8e-3,-6e-3,-4e-3,-2e-3,-1e-3,0,5e-4,1e-3, 2e-3,4e-3, 6e-3,  8e-3, 1e-2],
             # レベル&パターンを陽に指定
             'pat'=>[ 15999,18999,20999,30999,35999,45999,65999,70999,75999,77999,80999,85999,90999,95999,99999]
)
#

GGraph.axes( xax, zax )
GGraph.title( gphysdisp.long_name )
GGraph.color_bar ( 'vlength'=>0.24, 'inffact'=>0.5 )

GGraph.annotate ( [ time.to_s + ' s' ] )

DCL.grcls