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

cut = "no"

#timestep  = ARGV[0].to_i

x1 = 0
x2 = 256000
#x2 = 512000
#x2 = 500 * 1000 - 500 * 10
z1 = 0
#z2 = 30000
z2 = 36000
#z2 = 48000
t1 = 0
#t2 = 2592000
t2 = 86400 * 50
dt = 1800
#tn = 1440
#tn = 2400
tn = t2 / dt

files = "thermal-moist_Exner-ThermExpTerm-DthetaDt.nc"
gphys1 = GPhys::IO.open(files, 'ExnerThermExpTerm')
files = "thermal-moist_Exner-ThermExpTerm-DthetaDt_z24km.nc"
gphys2 = GPhys::IO.open(files, 'ExnerThermExpTerm')
files = "thermal-moist_Exner-ThermExpTerm-DthetaDt_z36km.nc"
gphys3 = GPhys::IO.open(files, 'ExnerThermExpTerm')
files = "thermal-moist_Exner-ThermExpTerm-DthetaDt_z48km.nc"
gphys4 = GPhys::IO.open(files, 'ExnerThermExpTerm')

files = "thermal-moist_Exner-ThermExpTerm-DqDt.nc"
gphys11 = GPhys::IO.open(files, 'ExnerThermExpTerm')
files = "thermal-moist_Exner-ThermExpTerm-DqDt_z24km.nc"
gphys12 = GPhys::IO.open(files, 'ExnerThermExpTerm')
files = "thermal-moist_Exner-ThermExpTerm-DqDt_z36km.nc"
gphys13 = GPhys::IO.open(files, 'ExnerThermExpTerm')
files = "thermal-moist_Exner-ThermExpTerm-DqDt_z48km.nc"
gphys14 = GPhys::IO.open(files, 'ExnerThermExpTerm')

#DCL.gropn(1)
DCL.gropn(2)
#DCL.sldiv('y',1,2)
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.25,0.8,0.10,0.275] )

gphysdisp1 = gphys1 + gphys11
gphysdisp1 = gphysdisp1.mean( 'x' )
gphysdisp1 = gphysdisp1.sum( 't' ) * dt

gphysdisp2 = gphys2 + gphys12
gphysdisp2 = gphysdisp2.mean( 'x' )
gphysdisp2 = gphysdisp2.sum( 't' ) * dt

gphysdisp3 = gphys3 + gphys13
gphysdisp3 = gphysdisp3.mean( 'x' )
gphysdisp3 = gphysdisp3.sum( 't' ) * dt

gphysdisp4 = gphys4 + gphys14
gphysdisp4 = gphysdisp4.mean( 'x' )
gphysdisp4 = gphysdisp4.sum( 't' ) * dt

if cut == "yes"

gphysdisp1 = gphysdisp1.cut( 'z'=>0..12000 )
gphysdisp2 = gphysdisp2.cut( 'z'=>0..12000 )
gphysdisp3 = gphysdisp3.cut( 'z'=>0..12000 )
gphysdisp4 = gphysdisp4.cut( 'z'=>0..12000 )

end

#gphysdisp = gphysdisp1

#GGraph.line( gphysdisp, true, 'exchange'=>true, 'min'=> -0.3, 'max'=>0.5,  'type'=>1 ) 
GGraph.line( gphysdisp4, true, 'exchange'=>true, 'min'=> -0.3, 'max'=>0.5, 'type'=>1 ) 
GGraph.line( gphysdisp1, false, 'exchange'=>true, 'min'=> -0.3, 'max'=>0.5, 'type'=>3 ) 
GGraph.line( gphysdisp2, false, 'exchange'=>true, 'min'=> -0.3, 'max'=>0.5,  'type'=>4 ) 
GGraph.line( gphysdisp3, false, 'exchange'=>true, 'min'=> -0.3, 'max'=>0.5, 'type'=>2 ) 

DCL.grcls

#GGraph.contour( gphysdisp, true, 'transpose'=>true )
#GGraph.line( gphysdisp, true, 'min' => 0.956, 'max' => 0.996 )
#GGraph.line( gphysdisp4, true, 'exchange'=>true  ) 
#GGraph.line( gphysdisp1, true, 'min' => 0.956, 'max' => 0.996 )
#GGraph.line( gphysdisp2, false, 'min' => 0.956, 'max' => 0.996, 'type' => 2 )
#GGraph.line( gphysdisp3, false, 'min' => 0.956, 'max' => 0.996, 'type' => 2 )
#GGraph.line( gphysdisp, true, 'exchange'=>true, 'min'=> -0.45, 'max'=>0.2,  'type'=>1 ) 
#GGraph.line( gphysdisp4, true, 'exchange'=>true ) 
#GGraph.line( gphysdisp4, true, 'exchange'=>true, 'min'=> -0.55, 'max'=>0.4,  'type'=>1 ) 

