#!/usr/bin/env ruby

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

include NumRu

Daytime = UNumeric.new(86400.0, "s/day")

file = "./arare_diag-20050903-2.nc"  # NetCDF file

# open file and initialize GPhys object

gp_adv = GPhys::IO.open(file, "PotTempTendAdvZ")
gp_turb = GPhys::IO.open(file, "PotTempTendTurbZ")
gp_rad = GPhys::IO.open(file, "PotTempTendRadZ")
gp_dis = GPhys::IO.open(file, "PotTempTendDisZ")
#gp_sfc = GPhys::IO.open(file, "PotTempTendSfcZ")

# unit convertion

gp_adv = gp_adv * Daytime
gp_turb = gp_turb * Daytime
gp_rad = gp_rad * Daytime
gp_dis = gp_dis * Daytime
#gp_sfc = gp_dis * Daytime

# mean

gp_adv = gp_adv.mean('t')
gp_turb = gp_turb.mean('t')
gp_rad = gp_rad.mean('t')
gp_dis = gp_dis.mean('t')
#gp_sfc = gp_sfc.mean('t')

# total tendency calculation

gp_total = gp_adv + gp_turb + gp_rad + gp_dis #+ gp_sfc

# drawing

DCL.gropn(4)
DCL.sgpset('lcntl', false)
DCL.uzfact(0.7)
GGraph.line( gp_total, true, 'exchange'=>true, 'title'=>'POTENTIAL TEMPARETURE TENDENCY',
             'max'=>150, 'min'=>-150, 'index'=>12 )
GGraph.line( gp_adv, false, 'exchange'=>true, 'index'=>22 )
GGraph.line( gp_rad, false, 'exchange'=>true, 'index'=>32 )
GGraph.line( gp_turb, false, 'exchange'=>true, 'index'=>42 )
GGraph.line( gp_dis, false, 'exchange'=>true, 'index'=>62 )
#GGraph.line( gp_sfc, false, 'exchange'=>true, 'index'=>72 )
DCL.grcls