#!/usr/bin/env ruby

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

# °ú¿ô½èÍý
parser = GetoptLong.new
parser.set_options(
                   ###    global option   ###
                   ['--file',        GetoptLong::REQUIRED_ARGUMENT],
                   ['--var',         GetoptLong::REQUIRED_ARGUMENT],
                   ['--var2',        GetoptLong::REQUIRED_ARGUMENT],
                   ['--var3',        GetoptLong::REQUIRED_ARGUMENT],
                   ['--itr',         GetoptLong::REQUIRED_ARGUMENT],
                   ['--dump',        GetoptLong::REQUIRED_ARGUMENT],
                   ['--max',         GetoptLong::REQUIRED_ARGUMENT],
                   ['--min',         GetoptLong::REQUIRED_ARGUMENT],
                   ['--max2',        GetoptLong::REQUIRED_ARGUMENT],
                   ['--min2',        GetoptLong::REQUIRED_ARGUMENT]
                   )
begin
  parser.each_option do |name, arg|
    eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_')} = '#{arg}'"  # strage option value to $OPT_val
  end
rescue
  exit(1)
end

gphys = GPhys::IO.open( $OPT_file, 'stab' )
gphys2  = GPhys::IO.open( $OPT_file, 'stab_low' )
gphys3 = GPhys::IO.open( $OPT_file, 'stab_high' )

unless ( $OPT_dump == nil ) 
  DCL::swpset('LDUMP', true) 
  DCL::swpset('LWAIT',false)
  DCL::swpset('LWAIT1',false)  
  DCL::swpset('IPOSX', 50)
  DCL::swpset('IPOSY',50)
end
DCL::swpset('IHEIGHT', 600 )
DCL::swpset('IWIDTH',  600 )

DCL.gropn(1)
DCL.sgpset('lfull',true) 

GGraph.set_fig( 'itr'=>($OPT_itr == nil) ? 1 : $OPT_itr.to_i )


GGraph.line( gphys, 
             true, 
             'exchange'=>true, 
             'index'=> 3, 
             'type' => 2, 
             'title'=>'Jupiter' ,
             'annot'=> false ,
             'max'=>($OPT_max == nil) ? nil : $OPT_max.to_f, 
             'min'=>($OPT_min == nil) ? nil : $OPT_min.to_f
)

p $OPT_min2, $OPT_max2

GGraph.line( gphys2.cut('pres'=>$OPT_min2.to_f..$OPT_max2.to_f),
             false, 
             'exchange'=>true, 
             'index'=> 3, 
             'type' => 1, 
             'title'=>'Jupiter',
             'max'=>($OPT_max == nil) ? nil : $OPT_max.to_f, 
             'min'=>($OPT_min == nil) ? nil : $OPT_min.to_f
             )

GGraph.line( gphys3.cut('pres'=>$OPT_min2.to_f..$OPT_max2.to_f),
             false, 
             'exchange'=>true, 
             'index'=> 3, 
             'type' => 3, 
             'title'=>'Jupiter', 
             'max'=>($OPT_max == nil) ? nil : $OPT_max.to_f, 
             'min'=>($OPT_min == nil) ? nil : $OPT_min.to_f 
             )

DCL.grcls
