#!/usr/bin/env ruby

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    = "PotTemp"
gphys3 = GPhys::IO.open( ARGV[0], var )

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

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

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

#gphys3 = gphys1 + gphys2

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.line( gphys2.cut('x'=> $OPT_X.to_f).cut('t'=>$OPT_T.to_f), 
             true,  
             'exchange'=>true,
             'title'=>'Buoyancy',
	     'index'=>43,
	     'type'=>1, 
             'max'=>($OPT_MaxLine == nil) ? nil :   $OPT_MaxLine.to_f,
             'min'=>($OPT_MaxLine == nil) ? nil : - $OPT_MaxLine.to_f
            )

GGraph.line( gphys1.cut('x'=> $OPT_X.to_f).cut('t'=>$OPT_T.to_f), 
             false, 
             'exchange'=>true,
	     'annotate'=>true,
	     'index'=>23,
	     'type'=>1
            )

GGraph.line( gphys12.cut('x'=> $OPT_X.to_f).cut('t'=>$OPT_T.to_f), 
             false, 
             'exchange'=>true,
	     'annotate'=>true,
             'index'=>11, 
	     'type'=>3
            )

#GGraph.contour( gphys4.cut('t'=>$OPT_T.to_f), 
#             true,
#	     'annotate'=>false
#            )
GGraph.tone( gphys3.cut('t'=>$OPT_T.to_f), 
             true, 
	     'annotate'=>false,
	     'max' => ($OPT_MaxTone == nil) ? nil :   $OPT_MaxTone.to_f, 
	     'min' => ($OPT_MaxTone == nil) ? nil : - $OPT_MaxTone.to_f
            )
GGraph.color_bar 


GGraph.tone( gphys4.cut('t'=>$OPT_T.to_f), 
             true, 
	     'annotate'=>false, 
	     'max' => ($OPT_MaxTone == nil) ? nil :   $OPT_MaxTone.to_f,
	     'min' => ($OPT_MaxTone == nil) ? nil : - $OPT_MaxTone.to_f
            )
GGraph.color_bar 

GGraph.tone( gphys6.cut('t'=>$OPT_T.to_f), 
             true, 
	     'annotate'=>false, 
	     'max' => ($OPT_MaxTone == nil) ? nil :   $OPT_MaxTone.to_f,
	     'min' => ($OPT_MaxTone == nil) ? nil : - $OPT_MaxTone.to_f 
            )
GGraph.color_bar 

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

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

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

DCL.grcls
