# -*- 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

dz = 200.0
cpdry = 891.0

#x-y Ê¿¶Ñ¤·, K.s-1 ¤ò W.m-3 ¤ËÊÑ´¹¤¹¤ë
denscut = dens0.mean('y').mean('x')
adv_XYmean  = adv.average('x').average('y') * 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

p adv_XYmean

#z Êý¸þ¤ËÀÑÊ¬¤·, W.m-2 ¤òµá¤á¤ë
=begin
adv_int = adv_XYmean.cut[1,0..-1] * dz * 0.50
for i in 2...zz.length do
  adv_int[i,0..-1] = adv_XYmean.cut[i-1,0..-1] *dz * 0.50
end
p adv_int
=end
# <Open DCL>
#DCL.swlset( 'ldump', true )

=begin

DCL.gropn(2)

for i in 0...time.length do
# <Drawing data by GGraph>

if (time[i].to_i % 1000) == 0 

#comax = 3.0e2
#comin = -3.0e2
comax = 4.0e-4
comin = -4.0e-4
#=begin
  GGraph.line( adv_XYmean.cut('t'=>time[i]), \
               true, 'exchange'=>true , \
               'index'=>22, 'type'=>1, 'label'=>'adv', \
               'title'=>'PTemp tendency', \
               'max'=>comax, 'min'=>comin)    # °ÜÎ®

  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
end
# <Close DCL>
DCL.grcls
=end
