#!/usr/bin/env ruby

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

include NumRu

file = "./arare_diag-20050905-5.nc"  # NetCDF file

# Daytime = UNumeric.new(86400.0, "s/day")  # daytime definition
Starttime = 0.0
Endtime   = 300.0

# open file and initialize GPhys object

gp_adv = GPhys::IO.open(file, "VelZTendAdvZ")
gp_pgrad = GPhys::IO.open(file, "VelZTendPGradZ")
gp_buoy = GPhys::IO.open(file, "VelZTendBuoyZ")
gp_turb = GPhys::IO.open(file, "VelZTendTurbZ")

# unit convertion

gp_adv = gp_adv # * Daytime
gp_pgrad = gp_pgrad # * Daytime
gp_buoy = gp_buoy # * Daytime
gp_turb = gp_turb # * Daytime

# cut

gp_adv = gp_adv.cut('t'=>Starttime..Endtime)
gp_pgrad = gp_pgrad.cut('t'=>Starttime..Endtime)
gp_buoy = gp_buoy.cut('t'=>Starttime..Endtime)
gp_turb = gp_turb.cut('t'=>Starttime..Endtime)

# mean

gp_adv = gp_adv.mean('t')
gp_pgrad = gp_pgrad.mean('t')
gp_buoy = gp_buoy.mean('t')
gp_turb = gp_turb.mean('t')

gp_buoy = gp_buoy

# total tendency calculation

gp_total = gp_adv + gp_pgrad + gp_buoy + gp_turb

# drawing

DCL.gropn(4)
DCL.sgpset('lcntl', false)
DCL.uzfact(0.7)
GGraph.line( gp_total, true, 'exchange'=>true, 'title'=>'VERTICAL VELOCITY TENDENCY',
#             'max'=>5e-3, 'min'=>-5e-3, 
'index'=>12 )
GGraph.line( gp_adv, false, 'exchange'=>true, 'index'=>22 )
GGraph.line( gp_pgrad, false, 'exchange'=>true, 'index'=>32 )
GGraph.line( gp_buoy, false, 'exchange'=>true, 'index'=>72 )
GGraph.line( gp_turb, false, 'exchange'=>true, 'index'=>42 )

DCL.grcls
