# -*- coding: euc-jp -*-
require "numru/ggraph"
include NumRu

# added
timestep  = ARGV[0].to_i

# 引数で渡そうと思ったがうまくいかない... 
IntegPeriod  = 4320000.0e0
tn = 20
dt = IntegPeriod / tn
#IntegPeriod  = 432000.0e0
#tn = 2
#dt = IntegPeriod / tn

x1 = 0
x2 = 512000
#x2 = 500 * 1000 - 500 * 10
z1 = 0
z2 = 30000


#files = /thermal-moist_H2O-l-Rain_rank(\d\d\d\d\d\d).nc/
#gphys  = GPhys::IO.open(files, 'H2O-l-Rain')
#files = /thermal-moist_H2O-l-Rain_Fall_rank(\d\d\d\d\d\d).nc/
#gphys  = GPhys::IO.open(files, 'H2O-l-Rain_Fall')

#files = /thermal-moist_H2O-l-Rain_FallFluxAtLB_rank(\d\d\d\d\d\d).nc/
#gphys  = GPhys::IO.open(files, 'H2O-l-Rain_FallFluxAtLB')
#files = /thermal-moist_H2O-g_SfcMassFlux_rank(\d\d\d\d\d\d).nc/
#gphys  = GPhys::IO.open(files, 'H2O-g_SfcMassFlux')
#files = /thermal-moist_SfcHeatFlux_rank(\d\d\d\d\d\d).nc/
#gphys  = GPhys::IO.open(files, 'SfcHeatFlux')
#files = /thermal-moist_VelX_rank(\d\d\d\d\d\d).nc/
#gphys  = GPhys::IO.open(files, 'VelX')
files1 = /thermal-moist_ExnerAll_rank(\d\d\d\d\d\d).nc/
gphys1  = GPhys::IO.open(files1, 'ExnerAll')
files2 = /thermal-moist_PTempAll_rank(\d\d\d\d\d\d).nc/
gphys2  = GPhys::IO.open(files2, 'PTempAll')


#DCL.gropn(1)
DCL.gropn(2)
#DCL.sldiv('y',1,3)
DCL.sgpset('lfull',true)
DCL.sgpset('lcntl', false)
DCL.uzfact(0.7)
#DCL.uzfact(0.3)
GGraph.set_fig( 'viewport'=>[0.25,0.7,0.15,0.6] )
# アスペクト比をそれっぽくする
#GGraph.set_fig( 'viewport'=>[0.1,0.85,0.15,0.6] ) 
#GGraph.set_fig( 'viewport'=>[0.1,0.85,0.2,0.45] )

xax = gphys1.coord(0)
#tax = gphys1.coord(3)

#gphysdisp0 = -gphys
#gphysdisp0 = gphys
gphysdisp0 = gphys1 * gphys2
gphysdisp0 = gphysdisp0.mean( 'y' )
gphysdisp0 = gphysdisp0.cut( 'z'=>450 )
#gphysdisp0 = gphysdisp0.cut( 't'=>2e6..2.2e6 )
gphysdisp0 = gphysdisp0.cut( 't'=>dt*(timestep-1)..dt*timestep )
#gphysdisp0 = gphysdisp0.cut( 't'=>2.16e5*(timestep-1)..2.16e5*timestep )
gphysdisp  = gphysdisp0
gphysdisp.long_name = 'Temperature at z = 450 m'

tax = gphysdisp.coord(1)  # <- gphysdisp は mean や cut して 2 次元になった

gphysdisp = gphysdisp0
#GGraph.fig( xax, zax, 'new_frame'=>false, 
GGraph.fig( xax, tax, 'new_frame'=>true ) 
#            'viewport'=>[0.25,0.9,vpy1,vpy2], 'window'=>[x1,x2,z1,z2] )
#            'viewport'=>[0.1,0.9,0.1,0.8], 'window'=>[x1,x2,z1,z2] )


#GGraph.contour( gphysdisp, true )
#GGraph.tone( gphysdisp, true )
#GGraph.tone( gphysdisp, false )
#GGraph.tone( gphysdisp, true,
GGraph.tone( gphysdisp, false,
#            'lev'=>[0,0.5e-3,1.0e-3,1.5e-3,2.0e-3,2.5e-3,3.0e-3,3.5e-3,4.0e-3,4.5e-3,5.0e3,5.5e-3,6.0e-3,6.5e-3,7.0e-3,7.5e-3],
#             # レベル＆パターンを陽に指定
#             'pat'=>[1,10999,15999,20999,25999,30999,35999,40999,45999,50999,60999,65999,70999,80999,90999]
#           降水量(デフォルト)
#            'lev'=>[1.0e-4,0.5e-3,1.0e-3,1.5e-3,2.0e-3,2.5e-3,3.0e-3,3.5e-3,4.0e-3,4.5e-3],
#           海面からの蒸発量
#            'lev'=>[1.0e-5,0.5e-4,1.0e-4,1.5e-4,2.0e-4,2.5e-4,3.0e-4,3.5e-4,4.0e-4,4.5e-4],
#           高度 500 m あたりでの温度
#            'lev'=>[   294.5,294.75,295,295.25,295.5,295.75,296,296.25,296.5,296.75,297],
#            'lev'=>[   294.25,294.5,294.75,295,295.25,295.5,295.75,296,296.25,296.5,296.75,297],
#            'lev'=>[   294, 294.4,294.8, 295.2,295.6,296,296.4,296.8],
#            'lev'=>[   287, 287.5, 288, 288.5, 289, 289.5, 290, 290.5, 291, 291.5, 292, 292.5],
#            'lev'=>[    288.5, 289, 289.5, 290, 291.5, 292, 292.5,293, 293.5, 294, 294.5, 295, 295.5, 296],
#            'lev'=>[    292.5,293, 293.5, 294, 294.5, 295, 295.5, 296, 296.5],
#            'lev'=>[    293, 293.5, 294, 294.5, 295, 295.5, 296, 296.5, 297, 297.5],
#            'lev'=>[    293.5, 294, 294.5, 295, 295.5, 296, 296.5, 297, 297.5],
#            'lev'=>[   287.4, 288,  288.6, 289.2,289.8,290.4,291,  291.6,292.2,292.8,293.4,294],
#            'lev'=>[   287.2, 288, 288.8, 289.6,290.4,291.2,292, 292.8, 293.6,294.4, 295.2],
#            'lev'=>[    288, 289,  290,  291,   292,  293, 294,   295,  296, 297],
#            'pat'=>[10999,15999,20999,30999,40999,50999,60999,70999,75999,85999,95999]
            'lev'=>[    294,294.25,294.5,294.75,295,295.25,295.5,295.75,296,296.25,296.5,296.75],
###---------------------------------
###
### ゼロしろ
##
#            'pat'=>[1,10999,15999,20999,      30999,35999,40999,            55999,65999,70999,75999,80999,90999,95999] # 14 色
#            'pat'=>[1,10999,15999,20999,      30999,      40999,      50999,      60999,70999,75999,80999,90999]       # 12 色
# (降水量, 蒸発量)
#            'pat'=>[1,10999,      20999,      30999,      40999,            55999,65999,70999,75999,80999,90999]       # 11 色
###
### non ゼロしろ
##
# (エクスナー関数)
#            'pat'=>[  10999,15999,20999,25999,30999,35999,40999,45999,50999,      67999,70999,80999,85999,90999]
# (水平風, 鉛直風まま)
#            'pat'=>[  10999,15999,20999,25999,30999,      40999,            55999,      70999,75999,80999,90999,95999] # 12 色
# (地表面熱フラックス)
#            'pat'=>[  10999,15999,20999,25999,30999,      40999,            55999,65999,70999,      80999,90999]       # 11 色
#            'pat'=>[  10999,15999,20999,      30999,      40999,            55999,65999,70999,75999,80999,90999]       # 11 色
#            'pat'=>[  10999,      20999,      30999,      40999,            55999,65999,70999,75999,80999,90999]       # 10 色
###
### 試作中
##
# (水蒸気混合比まま)
#            'pat'=>[  10999,15999,20999,      30999,      40999,            55999,65999,70999,75999,80999,90999]       # 11 色
###
###
# (水蒸気混合比たまに)
#            'pat'=>[  10999,15999,20999,      30999,      40999,                  65999,70999,75999,80999,90999]       # 10 色
#            'pat'=>[  10999,15999,20999,      30999,      40999,                  65999,70999,75999,80999,90999]       # 9 色
###
###
### でふぉ
##
# (温度)
#            'pat'=>[  10999,12999,15999,20999,25999,30999,35999,40999,55999,65999,70999,75999,80999,90999,95999] # 15 色
)
GGraph.axes( xax, tax )
GGraph.title( gphysdisp.long_name )
#GGraph.color_bar( 'vlength'=>0.07, 'inffact'=>0.5 )
GGraph.color_bar
DCL.grcls

