#!/usr/bin/env ruby

require "numru/netcdf"
require "numru/dcl"
require "numru/ggraph"
require "getoptlong"
include NumRu

###
###引数処理
###
parser = GetoptLong.new
parser.set_options(
                   ###    global option   ###
                   ['--num',         GetoptLong::REQUIRED_ARGUMENT],
                   ['--delt',        GetoptLong::REQUIRED_ARGUMENT],
                   ['--range',       GetoptLong::REQUIRED_ARGUMENT],
                   ['--aspect',      GetoptLong::REQUIRED_ARGUMENT],
                   ['--int',         GetoptLong::REQUIRED_ARGUMENT],
                   ['--MaxTone',     GetoptLong::REQUIRED_ARGUMENT],
                   ['--MaxLine',     GetoptLong::REQUIRED_ARGUMENT],
                   ['--X',           GetoptLong::REQUIRED_ARGUMENT],
                   ['--T',           GetoptLong::REQUIRED_ARGUMENT],
                   ['--dump',         GetoptLong::NO_ARGUMENT],
                   ['--nocont',      GetoptLong::NO_ARGUMENT]
                   )
begin
  parser.each_option do |name, arg|
    eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_')} = '#{arg}'" 
  end
rescue
  exit(1)
end

###
### 値の取得
###

var   = "MoistBuoy"
gphys1 = GPhys::IO.open( ARGV[0], var )

var   = "Buoy"
gphys2 = GPhys::IO.open( ARGV[0], var )

var   = "BuoyAll"
gphys12 = GPhys::IO.open( ARGV[0], var )

var    = "VelZ"
gphys_w = GPhys::IO.open( ARGV[0], var )

var    = "VelX"
gphys_u = GPhys::IO.open( ARGV[0], var )

var    = "Temp"
gphys_T = GPhys::IO.open( ARGV[0], var )

var    = "MixRt"
gphys_q = GPhys::IO.open( ARGV[0], var )


var    = "Temp"
gphysCloud = GPhys::IO.open( ARGV[0], var )  #初期化の代わり
gphysRain  = GPhys::IO.open( ARGV[0], var )  #初期化の代わり

gphysCloud = gphys_q[true, true, 3, true] + gphys_q[true, true, 5, true] + gphys_q[true, true, 7, true]
gphysRain = gphys_q[true, true, 4, true] + gphys_q[true, true, 6, true] + gphys_q[true, true, 8, true]


time = $OPT_T.to_f
X    = $OPT_X.to_f

DCL::swpset('IHEIGHT', 500 )
DCL::swpset('IWIDTH',  500 )


if ( $OPT_dump )
  DCL.gropn( 2 )
else
  DCL.gropn( 1 )
end

DCL.sgpset('lfull',true) 
DCL.sgpset('lfprop',true) 
#DCL.sglset('lclip',true)
DCL.sgpset('lcntl', false) 

DCL.uzfact(0.75)


###
### 温度
###
GGraph.tone( gphys_T.cut('t'=>time), 
             true, 
	     'annotate'=>false,
	     'max' => 1.5,
	     'min' => -1.5
            )
GGraph.color_bar 


###
### 浮力のプロット
###
GGraph.line( gphys2.cut('x'=> X).cut('t'=>time), 
             true,  
             'exchange'=>true,
             'title'=>'Buoyancy',
	     'index'=>43,
	     'type'=>1, 
             'max'=>1.5e-1,
             'min'=>-1.5e-1
            )

GGraph.line( gphys1.cut('x'=>X).cut('t'=>time), 
             false, 
             'exchange'=>true,
	     'annotate'=>true,
	     'index'=>23,
	     'type'=>1
            )

GGraph.line( gphys12.cut('x'=>X).cut('t'=>time), 
             false, 
             'exchange'=>true,
	     'annotate'=>true,
             'index'=>11, 
	     'type'=>3
            )

###
### 鉛直速度のプロット
###
GGraph.line( gphys_w.cut('t'=>5000).cut('x'=>X), 
	     true,
             'exchange'=>true,
	     'annotate'=>true,
	     'max' => 40,	
	     'min' => -40,	
             'index'=>13, 
	     'type'=>1
            )
GGraph.line( gphys_w.cut('t'=>3000).cut('x'=>X), 
	     false,
             'exchange'=>true,
	     'annotate'=>true,
             'index'=>13, 
	     'type'=>3
            )
GGraph.line( gphys_w.cut('t'=>2000).cut('x'=>X), 
	     false,
             'exchange'=>true,
	     'annotate'=>true,
             'index'=>13, 
	     'type'=>2
            )

###
### 鉛直速度
###

GGraph.tone( gphys_w.cut('t'=>$OPT_T.to_f), 
             true, 
	     'annotate'=>false
            )
GGraph.color_bar 





GGraph.tone( gphysCloud.cut('t'=>$OPT_T.to_f), 
             true, 
	     'annotate'=>false,
	     'max'=> 2.0e-4,
	     'min'=> -1.0e-6,
             'levels'=>[-1e-2,0, 0.25e-5, 5e-5, 0.75e-4, 1e-4, 1.25e-4, 1.5e-4, 1.75e-4,2e-4]
#	     'nlev'=> 50
            )
GGraph.color_bar 

GGraph.tone( gphysRain.cut('t'=>$OPT_T.to_f), 
             true, 
	     'annotate'=>false,
	     'max'=> 3e-3,	
	     'min'=> -1.0e-5,
	     'nlev'=> 50
            )
GGraph.color_bar 

GGraph.tone( gphys_q.cut('t'=>$OPT_T.to_f).cut('s'=>1), 
             true, 
	     'annotate'=>false
            )
GGraph.color_bar 

GGraph.tone( gphys_q.cut('t'=>$OPT_T.to_f).cut('s'=>2), 
             true, 
	     'annotate'=>false 
            )
GGraph.color_bar 

GGraph.tone( gphys_q.cut('t'=>$OPT_T.to_f).cut('s'=>3), 
             true, 
	     'annotate'=>false 
            )
GGraph.color_bar 

GGraph.tone( gphys_q.cut('t'=>$OPT_T.to_f).cut('s'=>4), 
             true, 
	     'annotate'=>false 
            )
GGraph.color_bar 

GGraph.tone( gphys_q.cut('t'=>$OPT_T.to_f).cut('s'=>5), 
             true, 
	     'annotate'=>false 
            )
GGraph.color_bar 

GGraph.tone( gphys_q.cut('t'=>$OPT_T.to_f).cut('s'=>6), 
             true, 
	     'annotate'=>false 
            )
GGraph.color_bar 

GGraph.tone( gphys_q.cut('t'=>$OPT_T.to_f).cut('s'=>7), 
             true, 
	     'annotate'=>false 
            )
GGraph.color_bar 

GGraph.tone( gphys_q.cut('t'=>$OPT_T.to_f).cut('s'=>8), 
             true, 
	     'annotate'=>false 
            )
GGraph.color_bar 

GGraph.tone( gphys_q.cut('t'=>$OPT_T.to_f).cut('s'=>9), 
             true, 
	     'annotate'=>false 
            )
GGraph.color_bar 

DCL.grcls
