# -*- 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'  )
ptemp   = GPhys::IO.open("../time_000000000-000172000/#{filehead}PTemp.nc",   'PTemp'  )
velz   = GPhys::IO.open("../time_000000000-000172000/#{filehead}VelZ.nc",   'VelZ'  )
dens0 = GPhys::IO.open("./restart_long-DensBZ.nc",   'DensBZ'  )
ptemp0 = GPhys::IO.open("./restart_long-PTempBZ.nc",   'PTempBZ'  )

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
#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
for i in 0...time.length
  ptempresi = ptemp.cut(true,true,true,time[i]) + ptemp0
#  ptempresi = ptempresi.eddy(0)
end

adv_flux = denscut * ptempresi * velz
p adv_flux
#adv_flux = adv_flux.mean('x')


#=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_flux.cut('t'=>time[250]), \
               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
