#!/usr/bin/env ruby
=begin

=draw_energy.rb

  * $B%(%M%k%.!<$N;~4VJQ2=$N@^$l@~?^$rIA$/(B
  * $B=i4|$N%(%M%k%.!<$KBP$9$kHf$rIA$$$F$$$k(B

=end

require "numru/ggraph"
require "numru/dcl"

include NumRu

#file = ARGV[0]
file = ["./nc/arare_diag-odaka1998-dx100-20051130.nc", 
        "./nc/arare_diag-odaka1998-dx100-20051130-2.nc"] 
Inittime = 0.0


# open file and initialize GPhys object

gp_ke = GPhys::IO.open(file, "KineticEnergyTotal")
gp_pe = GPhys::IO.open(file, "PotentialEnergyTotal")
gp_ae = GPhys::IO.open(file, "AvailPotentialEnergyTotal")
gp_ee = GPhys::IO.open(file, "ElasticEnergyTotal")

# disturb from value at initial time

gp_ke = gp_ke - gp_ke.cut("t"=>Inittime)
gp_pe = gp_pe - gp_pe.cut("t"=>Inittime)
gp_ae = gp_ae - gp_ae.cut("t"=>Inittime)
gp_ee = gp_ee - gp_ee.cut("t"=>Inittime)

gp_te = gp_ke + gp_pe + gp_ae + gp_ee

DCL.gropn(4)
DCL.sgpset("lcntl", false)
DCL.uzfact(0.7)
GGraph.line(gp_te, true, "index"=>13, "max"=>5.5e+9, "min"=>-5.0e+8, "title"=>"Total Energy")
GGraph.line(gp_pe, false, "index"=>73 )
GGraph.line(gp_ke, false, "index"=>23 )
GGraph.line(gp_ae, false, "index"=>43 )
GGraph.line(gp_ee, false, "index"=>33 )
DCL.grcls