#!/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   ###
                   ['--delt',         GetoptLong::REQUIRED_ARGUMENT],
                   ['--dump',         GetoptLong::NO_ARGUMENT]
                   )
begin
  parser.each_option do |name, arg|
    eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_')} = '#{arg}'" 
  end
rescue
  exit(1)
end

###
### 値の取得
###
var = "Rho"
Rho = GPhys::IO.open( ARGV[1], var ).sum('x').sum('z').sum('s')

###
### 図の作成
###

DCL::swpset('IHEIGHT', 600 )
DCL::swpset('IWIDTH',  600 )
#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) 

GGraph.set_fig('viewport'=>[0.1,0.9,0.1,0.9])

DCL.uzfact(0.75)
#DCL.sldiv('y',2,1)   
GGraph.set_axes('ytitle'=>'','xtitle'=>'')


GGraph.set_fig( 'itr'=> 1)
GGraph.line( Rho, 
             true, 
             'title' => 'Total Density of H2O',
	     'annotate'=>false,
             'index'=> 11,
             'type' => 1 
             )

DCL.grcls


if ( $OPT_dump )

  output = "~/work/deepconv/arare4/tools/dcmodel-dclps2png.rb dcl2.ps "+ARGV[2]+"_Budjet_H2O.png"
  p output
  system( "psselect 1 dcl.ps > dcl2.ps")
  system( output )

end	


