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

cut = ARGV[0]
line = ARGV[1]
#timestep  = ARGV[0].to_i

t2 = 86400 * 50
dt = 1800

files = "thermal-moist_Exner-ThermExpTerm-DqDt.nc"
gphys1 = GPhys::IO.open(files, 'ExnerThermExpTerm')

if line == "all"
  files = "thermal-moist_Exner-ThermExpTerm-DqDt_z24km.nc"
  gphys2 = GPhys::IO.open(files, 'ExnerThermExpTerm')
  files = "thermal-moist_Exner-ThermExpTerm-DqDt_z36km.nc"
  gphys3 = GPhys::IO.open(files, 'ExnerThermExpTerm')
  files = "thermal-moist_Exner-ThermExpTerm-DqDt_z48km.nc"
  gphys4 = GPhys::IO.open(files, 'ExnerThermExpTerm')
end

#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
gphysdisp1 = gphysdisp1.mean( 'x' )
gphysdisp1 = gphysdisp1.sum( 't' ) * dt

if line == "all"
  gphysdisp2 = gphys2
  gphysdisp2 = gphysdisp2.mean( 'x' )
  gphysdisp2 = gphysdisp2.sum( 't' ) * dt

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

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

if cut == "yes"
  gphysdisp1 = gphysdisp1.cut( 'z'=>0..12000 )

  if line == "all"
    gphysdisp2 = gphysdisp2.cut( 'z'=>0..12000 )
    gphysdisp3 = gphysdisp3.cut( 'z'=>0..12000 )
    gphysdisp4 = gphysdisp4.cut( 'z'=>0..12000 )
  end

end

if line == "all"

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

  elsif line == "1"
  gphysdisp = gphysdisp1
  GGraph.line( gphysdisp, true, 'exchange'=>true, 'min'=> -0.55, 'max'=>0.4,  'type'=>1 ) 

end

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 ) 

