# -*- coding: euc-jp -*-
# Title: Ruby script drawing contour map for deepconv/arare5 output data 
#
# History: 2011/09/27 (Masatsugu Odaka)
#
require "numru/ggraph"
include NumRu

filehead = "BS1998-all_"

adv   = GPhys::IO.open("../time_000000000-000172000/#{filehead}PTempAdv.nc",   'PTempAdv'  )
nDiff = GPhys::IO.open("../time_000000000-000172000/#{filehead}PTempNDiff.nc", 'PTempNDiff')
turb  = GPhys::IO.open("../time_000000000-000172000/#{filehead}PTempTurb.nc",  'PTempTurb' )
disp  = GPhys::IO.open("../time_000000000-000172000/#{filehead}PTempDisp.nc",  'PTempDisp' )
rad   = GPhys::IO.open("../time_000000000-000172000/#{filehead}PTempRad.nc",   'PTempRad'  )
sfc   = GPhys::IO.open("../time_000000000-000172000/#{filehead}PTempSfc.nc",   'PTempSfc'  )
dens0 = GPhys::IO.open("./restart_long-DensBZ.nc",   'DensBZ'  )

#time  = GPhys::IO.open("../time_000000000-000172000/#{filehead}PTempAdv.nc", 't').val

zz  = GPhys::IO.open("../time_000000000-000172000/#{filehead}PTempAdv.nc", 'z').val

turb  = turb + sfc
nz = 100
dz = 200.0
cpdry = 891.0
zlength = 20000.0

#x-y Ê¿¶Ñ¤·, K.s-1 ¤ò W.m-3 ¤ËÊÑ´¹¤¹¤ë
denscut = dens0.mean('y').mean('x')
adv_XYmean  = adv.average('x').average('y').cut('t'=>100000) * cpdry * denscut
turb_XYmean = turb.average('x').average('y') * cpdry * denscut
rad_XYmean  = rad.average('x').average('y') * cpdry * denscut
disp_XYmean  = disp.average('x').average('y') * cpdry * denscut
nDiff_XYmean  = nDiff.average('x').average('y') * cpdry * denscut
z_Z = VArray.new( NArray.sfloat(nz).indgen(100, zlength / nz), \
                  {"long_name"=>"z-coordinate", "units"=>"m"}, \
                  "z" )
z = Axis.new.set_pos(z_Z)
adv_int = VArray.new( NArray.sfloat(nz).indgen, \
                   {"long_name"=>"Energy Flux", "units"=>"W.m-2"}, \
                     "EnergyFlux")
adv_gphys = GPhys.new( Grid.new(z), adv_int)
p adv_XYmean
#puts adv_int[]
#z Êý¸þ¤ËÀÑÊ¬¤·, W.m-2 ¤òµá¤á¤ë
#=begin


  adv_gphys= adv_XYmean *dz 


p adv_int
#=end
# <Open DCL>
#DCL.swlset( 'ldump', true )



#=begin



DCL.gropn(2)


# <Drawing data by GGraph>

#comax = 3.0e2
#comin = -3.0e2
comax = 400.0
comin = -400.0
#=begin
  GGraph.line( adv_gphys, \
               true, 'exchange'=>true , \
               'index'=>22, 'type'=>1, 'label'=>'adv', \
               'title'=>'PTemp tendency', \
               'max'=>comax, 'min'=>comin)    # °ÜÎ®
=begin
  GGraph.line( turb_XYmean.cut('t'=>time[i]), \
               false, 'exchange'=>true , \
                'index'=>32, 'type'=>1, 'label'=>'turb', \
               'max'=>comax, 'min'=>comin)    # ÍðÎ®³È»¶

  GGraph.line( disp_XYmean.cut('t'=>time[i]), \
               false, 'exchange'=>true , \
                'index'=>52, 'type'=>1, 'label'=>'disp', \
               'max'=>comax, 'min'=>comin)    # ÍðÎ®³È»¶

  GGraph.line( nDiff_XYmean.cut('t'=>time[i]), \
               false, 'exchange'=>true , \
                'index'=>62, 'type'=>1, 'label'=>'ndiff', \
               'max'=>comax, 'min'=>comin)    # ÍðÎ®³È»¶

#=end
#  GGraph.line( - rad_int_XYmean.cut('t'=>time[i]), \
  GGraph.line( rad_XYmean.cut('t'=>time[i]), \
               false, 'exchange'=>true , \
               'index'=>42, 'type'=>1, 'label'=>'rad', \
               'max'=>comax, 'min'=>comin)    # Êü¼Í²ÃÇ®
=end
# <Close DCL>
DCL.grcls
#=end
