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

#filedir = "time_000000000-000172000"
filedir = "time_000000000-004181000"
filehead = "BS1998_PTemp"
#file0 = 'BS1998_restart_rank000000.nc'
file_base = 'restart_long-PTempBZ.nc'
file0 = "../#{filedir}/#{filehead}_rank000000.nc"
file1 = "../#{filedir}/#{filehead}_rank000001.nc"
file2 = "../#{filedir}/#{filehead}_rank000002.nc"
file3 = "../#{filedir}/#{filehead}_rank000003.nc"
file4 = "../#{filedir}/#{filehead}_rank000004.nc"
file5 = "../#{filedir}/#{filehead}_rank000005.nc"

varname_conv = 'PTemp'
varunit_conv = 'K'
varname0 = 'PTempBZ'
varname1 = 'PTemp'
cuttime  = 
#comax = 249.0
#comin = 247.0
comax = 270.0
comin = 220.0
var_base  = GPhys::IO.open(file_base, varname0)
var0  = GPhys::IO.open(file0, varname1)
var1  = GPhys::IO.open(file1, varname1)
var2  = GPhys::IO.open(file2, varname1)
var3  = GPhys::IO.open(file3, varname1)
var4  = GPhys::IO.open(file4, varname1)
var5  = GPhys::IO.open(file5, varname1)



var0_cut = var0.cut('t'=>cuttime)



time  = GPhys::IO.open(file1, 't').val
x_co  = GPhys::IO.open(file1, 'x').val

# <Open DCL>
DCL.gropn(2)
#var0 = var0[5..104,0..-1,5..104]
nx = 1200
ny = 1
nz = 100
nt = 200
node = 6
xlength = 180000.0 # Áí¿åÊ¿µ÷Î¥
ylength = 100.0
zlength = 20000.0
tlength = 172000.0
nx_par_node = nx / node

x_X = VArray.new( NArray.sfloat(nx).indgen(75, xlength / nx), \
                  {"long_name"=>"x-coordinate", "units"=>"m"}, \
                  "x" )

x = Axis.new.set_pos(x_X)

y_Y = VArray.new( NArray.sfloat(ny).indgen(ylength / ny), \
                  {"long_name"=>"y-coordinate", "units"=>"m"}, \
                  "y" )

y = Axis.new.set_pos(y_Y)

z_Z = VArray.new( NArray.sfloat(nz).indgen(75, zlength / nz), \
                  {"long_name"=>"z-coordinate", "units"=>"m"}, \
                  "z" )

z = Axis.new.set_pos(z_Z)

t_T = VArray.new( NArray.sfloat(nt).indgen(0, tlength / nt), \
                  {"long_name"=>"time", "units"=>"s"}, \
                  "t" )

t = Axis.new.set_pos(t_T)

data = VArray.new( NArray.sfloat(nx,ny,nz,nt).indgen, \
                   {"long_name"=>"#{varname_conv}", "units"=>"#{varunit_conv}"}, \
                     "#{varname_conv}")



VarAll = var1.cut(true,true,true,0.0) + var0
#VarAll = var1.cut(true,true,true,0.0) + var0[5..14,0..-1,5..124]
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..2 do

time = 3600.0*20.0*i

VarAll = var1.cut(true,true,true,time)+var0
VarMean = VarAll.mean(0,1)

str = (i*2.0).to_s

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

# <Close DCL>
DCL.grcls
