#! /usr/bin/ruby
#
# 2013-5-12 石渡正樹
# 1 次元放射対流平衡モデル用描画 : Ps-Ts 関係

require "getoptlong"        # for option_parse
require "numru/ggraph"
include NumRu

## オプション解析
parser = GetoptLong.new
parser.set_options(
                   ###    global option   ###
                   ['--wsn',                      GetoptLong::REQUIRED_ARGUMENT]
                   )
parser.each_option do |name, arg|
    eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_')} = '#{arg}'"  # strage option value to $OPT_val
end

## データ切出し, Ts 軸データの作成
ps = GPhys::IO.open('Ps.nc', 'Ps').cut('time'=>0.0,'lon'=>0.0)
ps_a = VArray.new( ps.val, 
                    {"long name"=>"surface pressure","units"=>"Pa"},
                    "Ps")

surftemp = GPhys::IO.open('sst_1dim.nc', 'SurfTemp').cut('time'=>0.0,'lon'=>0.0)
surftemp_a = VArray.new ( surftemp.val, 
                          {"long name"=>"Surface Temperature","units"=>"K"},
                         "SurfTemp")
surftemp_axis = Axis.new.set_pos(surftemp_a)

ps_temp_axis = GPhys.new( Grid.new(surftemp_axis), ps_a )

## 作図
DCL.gropn($OPT_wsn||4)

DCL.sgpset('lcntl', false) ; DCL.uzfact(0.7)

GGraph.set_fig( 'itr'=> 2, 'viewport'=>[0.2,0.8,0.3,0.6] )

#GGraph.line( ps, true, "min"=>1e4, "max"=>1e8, "index"=>255, "annotate"=>false, "exchange"=>false )
GGraph.line( ps_temp_axis, true, "min"=>1e4, "max"=>1e8, "index"=>255, "annotate"=>false, "exchange"=>false )

DCL.grcls

#-85.76059: 250K
#-80.26878, -74.74454, -69.21297, -63.67863, -58.14296: 300K
#-52.60653, -47.06964, -41.53246, -35.99508, -30.45755: 350K
#-24.91993, -19.38223, -13.84448, -8.306703, -2.768903: 400K
# 2.768903,  8.306703,  13.84448,  19.38223,  24.91993: 450K
# 30.45755,  35.99508,  41.53246,  47.06964,  52.60653: 500K
# 58.14296,  63.67863,  69.21297,  74.74454,  80.26878: 550K
# 85.76059: 560K
