#!/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],
                   ['--range',       GetoptLong::REQUIRED_ARGUMENT],
                   ['--aspect',      GetoptLong::REQUIRED_ARGUMENT],
                   ['--int',         GetoptLong::REQUIRED_ARGUMENT],
                   ['--T',           GetoptLong::REQUIRED_ARGUMENT],
                   ['--X',           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    = "VelX"
gphysU = GPhys::IO.open( ARGV[0], var )

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

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

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

var    = "MixRtBasicZ"
gphysQ = GPhys::IO.open( ARGV[0], var )

var    = "PotTempBasicZ"
gphysR = GPhys::IO.open( ARGV[0], var )

var    = "PotTempBasicZ"
gphysA = GPhys::IO.open( ARGV[0], var )

var    = "Exner"
gphys3 = GPhys::IO.open( ARGV[0], var )

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

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

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

var    = "PotTemp"
gphysT = GPhys::IO.open( ARGV[0], var )


time = $OPT_T.to_f
x    = $OPT_X.to_f

DCL::swpset('IHEIGHT', 470 )
DCL::swpset('IWIDTH',  800 )
#DCL.sgscmn(3)
#DCL.sgscmn(5)

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


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


#DCL.sldiv('y',2,1)           # 2x1に画面分割, 'y'=yoko: 左上→右上→左下...
DCL.uzfact(0.75)             # 座標軸の文字列サイズを 0.75 倍

GGraph.set_fig( 'itr'=> 1)
GGraph.set_fig('viewport'=>[0.1,0.8,0.1,0.47])

gphysQ = gphys1.cut('t'=>$OPT_T.to_f) + gphys2
gphysR = gphysQ.cut('s'=>5) + gphysQ.cut('s'=>7) + gphysQ.cut('s'=>9) 

gphysA = gphys1.cut('t'=>$OPT_T.to_f) .cut('s'=>1) + gphys1.cut('t'=>$OPT_T.to_f) .cut('s'=>4) + gphys1.cut('t'=>$OPT_T.to_f) .cut('s'=>5) 


GGraph.line( gphysA.mean('x'), 
             true, 
	     'exchange'=>true,
             'title' => 'H2O Mixing Ratio',
	     'annotate'=>false,
#             'max'=> 0.015,
             'index'=> 23,
             'type' => 1
            )
GGraph.line( gphys2.cut('s'=>1).mean('x'), 
             false, 
	     'exchange'=>true,
             'index'=> 11,
             'type' => 3
            )

GGraph.line( gphysQ.cut('s'=>1).mean('x'), 
             true, 
	     'exchange'=>true,
             'title' => 'H2O Mixing Ratio',
	     'annotate'=>false,
#             'max'=> 0.015,
             'index'=> 23,
             'type' => 1
            )
GGraph.line( gphys2.cut('s'=>1).mean('x'), 
             false, 
	     'exchange'=>true,
             'index'=> 11,
             'type' => 3
            )


GGraph.line( gphysQ.cut('s'=>2).mean('x'), 
             true, 
	     'exchange'=>true,
             'title' => 'NH3 Mixing Ratio',
	     'annotate'=>false,
             'max'=> 0.004,
             'index'=> 23,
             'type' => 1
            )
GGraph.line( gphys2.cut('s'=>2).mean('x'), 
             false, 
	     'exchange'=>true,
             'index'=> 11,
             'type' => 3
            )


GGraph.line( gphysQ.cut('s'=>3).mean('x'), 
             true, 
	     'exchange'=>true,
             'title' => 'H2S Mixing Ratio',
	     'annotate'=>false,
             'max'=> 0.0012,
             'index'=> 23,
             'type' => 1
            )
GGraph.line( gphys2.cut('s'=>3).mean('x'), 
             false, 
	     'exchange'=>true,
             'index'=> 11,
             'type' => 3
            )

GGraph.tone( gphysQ.cut('s'=>1), 
             true, 
             'title' => 'H2O Mixing Ratio',
	     'annotate'=>false, 
	    'levels'=> [1e-8,5e-7,1e-6,2e-6,5e-6,1e-5,2e-5,5e-5,1e-4,2e-4,5e-4,1e-3,2e-3,5e-3,1e-2,2e-2]
            )

GGraph.tone( gphysQ.cut('s'=>2), 
             true, 
             'title' => 'NH3 Mixing Ratio',
	     'annotate'=>false, 
	    'levels'=> [1e-8,5e-7,1e-6,2e-6,5e-6,1e-5,2e-5,5e-5,1e-4,2e-4,5e-4,1e-3,2e-3,5e-3,1e-2,2e-2]
            )

GGraph.tone( gphysQ.cut('s'=>3), 
             true, 
             'title' => 'H2S Mixing Ratio',
	     'annotate'=>false, 
	    'levels'=> [1e-8,5e-7,1e-6,2e-6,5e-6,1e-5,2e-5,5e-5,1e-4,2e-4,5e-4,1e-3,2e-3,5e-3,1e-2,2e-2]
            )


GGraph.tone( gphysU, 
             true, 
             'title' => 'Zonal Velocity',
	     'annotate'=>false, 
	    'max'=> 60,
	    'min'=> -60
            )
GGraph.color_bar

GGraph.tone( gphysW, 
             true, 
             'title' => 'Vertial Velocity',
	     'annotate'=>false, 
	    'max'=> 60,
	    'min'=> -60
            )
GGraph.color_bar

GGraph.tone( gphysR, 
             true, 
             'title' => 'Mixing Ratio of Rain',
	     'annotate'=>false, 
	    'levels'=> [-1e-5,1e-8,2e-8,5e-8,1e-7,2e-7,5e-7,1e-6,2e-6,5e-6,1e-5,2e-5,5e-5,1e-4,2e-4,5e-4,1e-3,2e-3,5e-3]
            )
GGraph.color_bar

GGraph.tone( gphysQ.cut('s'=>5), 
             true, 
             'title' => 'Mixing Ratio of Rain',
	     'annotate'=>false, 
	    'levels'=> [-1e-5,1e-8,2e-8,5e-8,1e-7,2e-7,5e-7,1e-6,2e-6,5e-6,1e-5,2e-5,5e-5,1e-4,2e-4,5e-4,1e-3,2e-3,5e-3]
            )
GGraph.tone( gphysQ.cut('s'=>7), 
             true, 
             'title' => 'Mixing Ratio of Rain',
	     'annotate'=>false, 
	    'levels'=> [-1e-5,1e-8,2e-8,5e-8,1e-7,2e-7,5e-7,1e-6,2e-6,5e-6,1e-5,2e-5,5e-5,1e-4,2e-4,5e-4,1e-3,2e-3,5e-3]
            )
GGraph.tone( gphysQ.cut('s'=>9), 
             true, 
             'title' => 'Mixing Ratio of Rain',
	     'annotate'=>false, 
	    'levels'=> [-1e-5,1e-8,2e-8,5e-8,1e-7,2e-7,5e-7,1e-6,2e-6,5e-6,1e-5,2e-5,5e-5,1e-4,2e-4,5e-4,1e-3,2e-3,5e-3]
            )



DCL.grcls
