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

file0 = 'BS1998_restart.nc'
file1 = 'BS1998_PTemp.nc'

varname0 = 'PTempBZ'
varname1 = 'PTemp'
ltime = 172800.0
#comax = 249.0
#comin = 247.0
comax = 270.0
comin = 220.0
var0  = GPhys::IO.open(file0, varname0)
#var1  = GPhys::IO.open([file1,file2,file3,file4,file5,file6,file7,file8,file9,file10], varname1)
#time  = GPhys::IO.open([file1,file2,file3,file4,file5,file6,file7,file8,file9,file10], 't').val

var1  = GPhys::IO.open(file1, varname1)
time  = GPhys::IO.open(file1, 't').val

# <Open DCL>
DCL.swlset( 'ldump', true )
DCL.gropn(2)

#VarAll = var1.cut(true,true,true,0.0) + var0[5..14,0..-1,5..124]
VarAll = var1.cut(true,true,true,0.0) + var0[5..104,0..-1,5..104]
VarMean = VarAll.average('x').average('y')

GGraph.line( VarMean, 
             true, 'exchange'=>true ,
             'index'=>2, 'type'=>1, 'label'=>'00',
             'title'=>'Mean Potemtial Temp.',
             'max'=>comax, 'min'=>comin)    

for i in 1..48 do

time = 3600.0*20.0*i
#time = 86400.0*i*2

#VarAll = var1.cut(true,true,true,time) + var0[5..14,0..-1,5..124]
VarAll = var1.cut(true,true,true,time) + var0[5..104,0..-1,5..104]
VarMean = VarAll.mean(0,1)

str = (i*20).to_s

GGraph.line( VarMean, 
               false, 'exchange'=>true ,
               'index'=>2, 'type'=>1, 'label'=>str,
               'max'=>comax, 'min'=>comin)    
end

# <Close DCL>
DCL.grcls
