require "numru/ggraph"
include NumRu

### ARGV[0] は引数をもってくるときつかう
time  = ARGV[0].to_i

#time = 1200

### 範囲指定
x1 = 0
x2 = 128000
#x2 = 500 * 1000 - 500 * 10
z1 = 0
z2 = 30000


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

#files = /Nakajima_H2O-gAll_rank(\d\d\d\d\d\d).nc/
#gphys2  = GPhys::IO.open(files, 'H2O-gAll')

#files = /thermal-moist_H2O-l-CloudAll_rank(\d\d\d\d\d\d).nc/
#gphys3  = GPhys::IO.open(files, 'H2O-l-CloudAll')

#files = /thermal-moist_H2O-l-RainAll_rank(\d\d\d\d\d\d).nc/
#gphys4  = GPhys::IO.open(files, 'H2O-l-RainAll')


#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.15, 0.75, 0.2, 0.5] )
#xmin,xmax,ymin,ymax

xax = gphys.coord(0)
zax = gphys.coord(2)

#vpy1 = 0.075
#vpy2 = 0.2
#vpy1 = 0.05
#vpy2 = 0.14

#gphysdisp0 = gphys1.cut( 't'=>time )
#gphysdisp0 = gphysdisp0.mean( 'y' )
#
#gphysdispd = gphysdisp0
#
#gphysdispq = gphys2.cut( 't'=>time )
#gphysdispq = gphysdispq.mean( 'y' )
#gphysdisp0 = gphysdisp0 * ( 1.0 + ( 1.0 / 0.622 - 1.0 ) * gphysdispq )
#
#gphysdisp1 = gphysdisp0.copy
#gphysdisp0[true,1..-2] = ( gphysdisp1[true,2..-1] - gphysdisp1[true,0..-3] ) / ( 200.0 * 2 ) * 9.8 / gphysdisp1[true,1..-2]
#gphysdisp0[true,0] = ( gphysdisp1[true,1] - gphysdisp1[true,0] ) / ( 200.0 * 1 ) * 9.8 / gphysdisp1[true,0]
#gphysdisp0[true,-1] = ( gphysdisp1[true,-1] - gphysdisp1[true,-2] ) / ( 200.0 * 1 ) * 9.8 / gphysdisp1[true,-1]
#gphysdisp0.long_name = 'Static stability'
#gphysdisp0.units = 's-2'
#
#gphysdisp1 = gphysdispd.copy
#gphysdispd[true,1..-2] = ( gphysdisp1[true,2..-1] - gphysdisp1[true,0..-3] ) / ( 200.0 * 2 ) * 9.8 / gphysdisp1[true,1..-2]
#gphysdispd[true,0] = ( gphysdisp1[true,1] - gphysdisp1[true,0] ) / ( 200.0 * 1 ) * 9.8 / gphysdisp1[true,0]
#gphysdispd[true,-1] = ( gphysdisp1[true,-1] - gphysdisp1[true,-2] ) / ( 200.0 * 1 ) * 9.8 / gphysdisp1[true,-1]
#gphysdispd.long_name = 'Static stability'
#gphysdispd.units = 's-2'


### 時間でカット
gphysdisp0 = gphys.cut( 't'=>time )
### yで平均
gphysdisp0 = gphysdisp0.mean( 'y' )

#gphysdispt = gphysdisp0

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

gphysdisp0.long_name = 'H2O-g Mixing Ratio'

#gphysdisp = gphysdispt.mean( 'x' )
#gphysdisp = gphysdispd.mean( 'x' )
#gphysdisp.long_name = ''

###四枚かく場合
#GGraph.next_fig( 'viewport'=>[0.1,0.2,vpy1,vpy2], 'window'=>[280,450,z1,z2] )
#GGraph.next_fig( 'viewport'=>[0.1,0.2,vpy1,vpy2], 'window'=>[-1e-3,1e-3,z1,z2] )
###線でかくとき
#GGraph.line( gphysdisp, true, 'exchange'=>true, 'annotate'=>false, 'title'=>'' )

#gphysdisp = gphysdispd.mean( 'x' )
#gphysdisp.long_name = ''
#GGraph.line( gphysdisp, false, 'exchange'=>true, 'annotate'=>false, 'title'=>'', 'type'=>2 )

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'=>[-1e-2,-8e-3,-6e-3,-4e-3,-2e-3,-1e-3, -5e-4, 0,  5e-4, 1e-3,  2e-3, 4e-3, 6e-3, 8e-3, 1e-2],
             # レベル＆パターンを陽に指定
             'pat'=>[ 10999,15999,20999,30999,35999,45999,65999,70999,75999,77999,80999,85999,90999,95999,99999]
)
#
#GGraph.tone( gphysdisp, false, 
##             'lev'=>[0,1e-4,2e-4,3e-4,4e-4,5e-4,6e-4,7e-4,8e-4,9e-4,10e-4,11e-4],
##             # レベル＆パターンを陽に指定
##             'pat'=>[1,10999,15999,20999,25999,30999,40999,50999,60999,65999,70999,80999,90999]
#
#             'lev'=>[0,5e-5,10e-5,15e-5,20e-5,25e-5,30e-5,35e-5,40e-5,45e-5,50e-5,55e-5,60e-5,65e-5,70e-5],
#             # レベル＆パターンを陽に指定
#             'pat'=>[1,10999,15999,20999,25999,30999,35999,40999,45999,50999,55999,60999,65999,70999,80999,90999]
#)

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
