#! /usr/bin/ruby
#
# 2013-5-12 石渡正樹
# 1 次元放射対流平衡モデル用描画 : 上向き長波フラックスの鉛直分布

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

## データ切出し
upward_longflux = GPhys::IO.open('RadLUWFLXB.nc', 'RadLUWFLXB')

upward_longflux_250K = upward_longflux.cut('time'=>0.0,'lon'=>0.0,'sigm'=>1.0..1e-6,'lat'=>-85.76)
upward_longflux_300K = upward_longflux.cut('time'=>0.0,'lon'=>0.0,'sigm'=>1.0..1e-6, 'lat'=>-58.14)
upward_longflux_350K = upward_longflux.cut('time'=>0.0,'lon'=>0.0,'sigm'=>1.0..1e-6, 'lat'=>-30.45)
upward_longflux_400K = upward_longflux.cut('time'=>0.0,'lon'=>0.0,'sigm'=>1.0..1e-6, 'lat'=>-2.76)
upward_longflux_450K = upward_longflux.cut('time'=>0.0,'lon'=>0.0,'sigm'=>1.0..1e-6, 'lat'=>24.91)
upward_longflux_500K = upward_longflux.cut('time'=>0.0,'lon'=>0.0,'sigm'=>1.0..1e-6, 'lat'=>52.6)
upward_longflux_550K = upward_longflux.cut('time'=>0.0,'lon'=>0.0,'sigm'=>1.0..1e-6, 'lat'=>80.26)

## 作図
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( upward_longflux_250K, true, "min"=>0.0, "max"=>6000.0, "index"=>195, "annotate"=>false, "exchange"=>true )
GGraph.line( upward_longflux_300K, false, "index"=>295, "exchange"=>true)
GGraph.line( upward_longflux_350K, false, "index"=>405, "exchange"=>true)
GGraph.line( upward_longflux_400K, false, "index"=>555, "exchange"=>true)
GGraph.line( upward_longflux_450K, false, "index"=>705, "exchange"=>true)
GGraph.line( upward_longflux_500K, false, "index"=>795, "exchange"=>true)
GGraph.line( upward_longflux_550K, false, "index"=>855, "exchange"=>true)
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
