=begin = module Draw : rgtview から呼び出される描画および設定メソッド. ==Index ==GGraph(redef) ==module Draw ---settei_hoge 変数 hoge 描画用設定部分. =end module Draw require "colorbar" require "numru/ggraph" =begin #デフォルトのメソッド def GGraph::annotate(str_ary) charsize = 0.5 * DCL.uzpget('rsizec1') dvx = 0.01 dvy = charsize*1.5 raise TypeError,"Array expected" if ! str_ary.is_a?(Array) vxmin,vxmax,vymin,vymax = DCL.sgqvpt vx = vxmax + dvx vy = vymax - charsize/2 str_ary.each{|str| DCL::sgtxzv(vx,vy,str,charsize,0,-1,1) vy -= dvy } nil end =end ##----------------------- # 切断面情報の表示メソッド def GGraph::annotate(str_ary) # GGraph の annotate メソッドを再定義 lnum = 0 str_ary.each{ |str|lnum += 1 } charsize = 0.7 * DCL.uzpget('rsizec1') dvx = 0.01 dvy = charsize*1.5 raise TypeError,"Array expected" if ! str_ary.is_a?(Array) vxmin,vxmax,vymin,vymax = DCL.sgqvpt vx = 0.65 vy = 0.045 + (lnum-1)*dvy str_ary.each{|str| DCL::sgtxzv(vx,vy,str,charsize,0,-1,1) vy -= dvy } nil end def GGraph::line(gphys, newframe=true, options=nil) if newframe!=true && newframe!=false raise ArgumentError, "2nd arg (newframe) must be true or false" end if ! defined?(@@line_options) @@line_options = Misc::KeywordOptAutoHelp.new( ['title', nil, 'Title of the figure(if nil, internally determined)'], ['annotate', true, 'if false, do not put texts on the right margin even when newframe==true'], ['exchange', false, 'whether to exchange x and y axes'], ['index', 1, 'line/mark index'], ['type', 1, 'line type'], ['label', nil, 'if a String is given, it is shown as the label'], ['max', nil, 'maximam value for draw line'], ['min', nil, 'minimam value for draw line'] ) end opts = @@line_options.interpret(options) gp = gphys.first1D if !opts['exchange'] x = gp.coord(0) y = gp.data xax = x if opts['min'] ymin = opts['min'].to_f else ymin = gp.data.val.min end if opts['max'] ymax = opts['max'].to_f else ymax = gp.data.val.max end yax = VArray.new(NArray[ymin, ymax], gp.data, gp.data.name) else y = gp.coord(0) x = gp.data yax = y if opts['min'] xmin = opts['min'] else xmin = gp.data.val.min end if opts['max'] xmax = opts['max'] if opts['max'] else xmax = gp.data.val.max end xax = VArray.new(NArray[xmin, xmax], gp.data, gp.data.name) end if newframe fig(xax, yax) axes(xax, yax) title( (opts['title'] || gp.data.get_att('long_name')) ) annotate(gp.lost_axes) if opts['annotate'] end if opts['label'] lcharbk = DCL.sgpget('lchar') DCL.sgpset('lchar',true) DCL.sgsplc(opts['label']) end DCL.uulinz(x.val, y.val, opts['type'], opts['index']) DCL.sgpset('lchar',lcharbk) if opts['label'] nil end ##----------------------- # ラインメソッド再定義? def plot_line_main(gphys_array, line_opts={}) line_index_ary = Array.new; name_ary = Array.new default_index = 12 line_hash = { "index"=> default_index }.update(line_opts) line_index_ary.push(default_index) name_ary.push(gphys_array[0].data.get_att("line_name")) GGraph.line( gphys_array[0], true, line_hash ) gphys_array.size.times{ |num| unless num == 0 line_hash = { "index"=> (num*10 + default_index)} line_index_ary.push(num*10 +default_index) name_ary.push(gphys_array[num].data.get_att("line_name")) GGraph.line( gphys_array[num], false, line_hash ) end } # nc # if $gropn == 2 # # charsize = 0.79 - $file_label.size * 0.0115 # DCL::sgtxzv(charsize,0.62,$file_label,0.8 * DCL.uzpget('rsizec1'),0,-1,1) # else # charsize = 0.81 - $file_label.size * 0.0095 # DCL::sgtxzv(charsize,0.6,$file_label,0.8 * DCL.uzpget('rsizec1'),0,-1,1) # end Draw::__show_line_index(name_ary,line_index_ary) end ##----------------------- # ラインインデックスの種類を表示 def __show_line_index(str_ary,line_index_ary) charsize = 0.7 * DCL.uzpget('rsizec1') dvx = 0.01 dvy = charsize*1.5 raise TypeError,"Array expected" if ! str_ary.is_a?(Array) vxmin,vxmax,vymin,vymax = DCL.sgqvpt vx = 0.15 vy = 0.12 - charsize/2 str_ary.size.times{|num| DCL::sgtxzv(vx,vy,"--- #{str_ary[num]}", charsize, 0, -1, line_index_ary[num]) vy -= dvy if num == 3 vx = 0.30 vy = 0.12 - charsize/2 end } nil end ########################################################## # 色合い, 等値線設定 # ########################################################## ##----------------------- # 東西風 def settei_U(opts) GGraph.set_linear_contour_options('min'=>-50,'int'=>2.5, 'max'=>70) levels = NArray[-1000, -15, -5, 0, 5, 15, 25, 1000] patterns = NArray[30999, 35999, 40999, 55999, 70999, 75999, 85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "nobound"=>0, "tick1"=>20,"tick2"=>1 } end ##----------------------- # 南北風 def settei_V(opts) GGraph.set_linear_contour_options('int'=>0.5) levels = NArray[-1000, -1.5, -0.5, 0, 0.5, 1.5, 1000] patterns = NArray[30999,40999,55999,70999,75999,85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "nobound"=>0, "tick1"=>20,"tick2"=>1 } end ##----------------------- # 鉛直風 def settei_W(opts) GGraph.set_linear_contour_options( 'int'=>0.01) levels = NArray[-10, -0.04, -0.02, -0.01, 0.0, 0.01, 0.02, 10] patterns = NArray[30999, 35999, 40999, 55999, 70999, 75999, 85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "nobound"=>0, "tick1"=>20,"tick2"=>1 } end ##----------------------- # 温度 def settei_T(opts) GGraph.set_linear_contour_options( 'min'=>180, 'max'=>330, 'int'=>10) levels = levels = NArray.int(8).indgen!(0, 20)+180 levels[0] = 150 patterns = NArray[25999, 30999, 40999, 55999, 70999, 75999, 85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "tick1"=>20,"tick2"=>1 } end ##----------------------- # 表面温度 def settei_SKT(opts) GGraph.set_linear_contour_options( 'min'=>180, 'max'=>330, 'int'=>10) levels = NArray[190.0, 210.0, 230.0, 250.0, 270.0, 290.0, 310.0] patterns = NArray[35999, 45999, 60999, 70999,75999,85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, # "nobound"=>1, "tick1"=>7,"tick2"=>1 } end ##----------------------- # 対流性降雨 def settei_CP $levels = NArray[0.0002, 0.0015, 0.002, 0.0025, 0.003, 0.0035, 1000] $patterns = NArray[35999, 45999, 60999, 70999,75999,85999] $draw_opts["levels"] = $levels $draw_opts["patterns"] = $patterns $cbar_conf = { "levels"=>$levels, "colors"=>$patterns, "eqlev"=>true, "nobound"=>2, "tick1"=>7,"tick2"=>1 } end ##----------------------- # 層状性降雨 def settei_LSP $levels = NArray[0.0007, 0.0009, 0.0011, 0.0014, 0.0017, 0.002, 1000] $patterns = NArray[35999, 45999, 60999, 70999, 75999, 85999] $draw_opts["levels"] = $levels $draw_opts["patterns"] = $patterns $cbar_conf = { "levels"=>$levels, "colors"=>$patterns, "eqlev"=>true, "nobound"=>2, "tick1"=>7,"tick2"=>1 } end ##----------------------- # 総降雨 def settei_TP(opts) GGraph.set_linear_tone_options( 'max'=>0.03, 'nlev'=>50, 'min'=>0.003) opts["colorbar_opts"] = { "tick1"=>100,"tick2"=>10 } return opts end ##----------------------- # 降雨強度 def settei_PRATE(opts) levels = NArray[0.00005, 0.00006, 0.00007, 0.00008, 0.00009, 0.0001, 1000] patterns = NArray[35999, 45999, 60999, 70999, 75999, 85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "nobound"=>2, "tick1"=>7,"tick2"=>1 } return opts end ##----------------------- # 正味の地表面長波放射 def settei_NLWRS(opts) GGraph.set_linear_contour_options( 'int'=>10) levels = NArray[0, 25, 50, 75, 100, 125, 150, 10000] patterns = NArray[35999, 45999, 60999, 70999, 75999, 80999, 85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "nobound"=>2, "tick1"=>7,"tick2"=>1 } return opts end ##----------------------- # 上向き地表面長波放射 def settei_ULWRF(opts) levels = NArray[100, 160, 180, 200, 220, 240, 260, 300, 350] patterns = NArray[20999, 25999, 35999, 40999, 99999, 95999, 90999, 85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "tick1"=>8,"tick2"=>1 } return opts end ##----------------------- # ジオポテンシャルハイト def settei_HGT(opts) GGraph.set_linear_contour_options( 'int'=>50) levels = NArray.int(8).indgen!(0, 200)+4800 levels[0] = 0 patterns = NArray[30999, 35999, 40999, 55999, 70999, 75999, 85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "nobound"=>2, "tick1"=>8,"tick2"=>1 } return opts end ##----------------------- # 相対湿度 def settei_RHUM(opts) GGraph.set_linear_contour_options( 'int'=>5) levels = NArray.int(11).indgen!(0, 10) patterns = NArray[15999, 25999, 30999, 35999, 40999, 50999, 70999, 75999, 80999, 85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "tick1"=>10,"tick2"=>1 } return opts end ##----------------------- # 比湿 def settei_SHUM(opts) GGraph.set_linear_contour_options('int'=>0.001) levels = NArray[0, 0.002, 0.004, 0.006, 0.008, 0.01, 0.012, 0.014, 0.016, 0.018, 0.02] patterns = NArray[15999, 25999, 30999, 35999, 40999, 50999, 70999, 75999, 80999, 85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "tick1"=>10,"tick2"=>1 } return opts end ##----------------------- # 潜熱フラックス def settei_LHTFL(opts) GGraph.set_linear_contour_options('int'=>25) levels = NArray[0, 50, 100, 150, 200, 250, 10000] patterns = NArray[30999,40999,55999,70999,75999,85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "nobound"=>1, "tick1"=>10,"tick2"=>1 } return opts end ##----------------------- # 顕熱フラックス def settei_SHTFL(opts) GGraph.set_linear_contour_options('int'=>25) levels = NArray[0, 1, 10, 20, 50, 100, 10000] patterns = NArray[30999,40999,55999,70999,75999,85999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "nobound"=>1, "tick1"=>10,"tick2"=>1 } return opts end ##----------------------- # パワースペクトル def settei_PWS(opts) GGraph.set_linear_tone_options( 'nlev'=>10) opts["colorbar_opts"] = { "tick1"=>10,"tick2"=>1 } end ##----------------------- # 質量流線関数 def settei_strm(opts, obj=nil) @flag_tonf = true; @flag_tonc = true # these flag is WITHOUT tonf or c!! GGraph.set_linear_contour_options( 'interval'=>1.0e10 ) levels = NArray[obj.val.min, 0.0, obj.val.max] patterns = NArray[35999,70999] # patterns = NArray[1201,1204] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "nobound"=>0, "tick1"=>7,"tick2"=>1 } end ##----------------------- # 質量流線関数 def settei_strm_rmean(opts, obj=nil) # @flag_tonf = true; @flag_tonc = true # these flag is WITHOUT tonf or c!! GGraph.set_linear_contour_options( 'interval'=>1.0e10 ) levels = NArray[obj.val.min, 0.0, obj.val.max] patterns = NArray[35999,70999] opts["levels"] = levels opts["patterns"] = patterns opts["colorbar_opts"] = { "levels"=>levels, "colors"=>patterns, "eqlev"=>true, "nobound"=>0, "tick1"=>7,"tick2"=>1 } end ##----------------------- # 温位 def settei_Theta lev = [370, 400, 450, 500, 600, 700, 800] $levels = NArray::to_na(NArray.int(16).indgen!(200, 10).to_a + lev) mj = 1; mn = 1 $index = [mj, mn] $draw_opts["levels"] = $levels end ##----------------------- # 有効位置エネルギー def settei_Available GGraph.set_linear_contour_options( 'nlev'=>30 ) levels = NArray[-100, -0.05, 0, 0.05, 0.1, 100] patterns = NArray[35999, 45999, 60999, 70999, 85999] $draw_opts["levels"] = levels $draw_opts["patterns"] = patterns $cbar_conf = { "levels"=>$levels, "colors"=>$patterns, "eqlev"=>true, "nobound"=>2, "tick1"=>7,"tick2"=>1 } end ##----------------------- # native def settei_native end ##----------------------- # 質量流線関数と温度 def settei_strm_temp GGraph.set_linear_contour_options( 'nlev'=>15 ) GGraph.set_linear_tone_options( 'min'=>180, 'nlev'=>90, 'max'=>300 ) end ########################################################## # 描画方法 設定 # ########################################################## ##----------------------- # window 作成 def mkwin(vp=[0.15,0.85,0.23,0.58]) # -f, --file オプションが有効ならば dcl.ps に保存. if ($OPT_f) || ($OPT_file) then output = 2 else output = 1 # デフォルトは標準出力に. end # viewport の大きさ, 軸の設定 GGraph.set_fig('viewport'=>vp) # set_*: 縦横比は 2 : 1 GGraph.set_fig('itr'=> ($OPT_itr).to_i) if ($OPT_itr) GGraph.set_fig( "xrev"=>"units:mb,units:hPa,units:millibar", "yrev"=>"units:mb,units:hPa,units:millibar") # 窓開く DCL.gropn(output) # フォンとの設定 DCL.sgpset('lcntl', false) ; DCL.uzfact(0.7) DCL.sgpset('lfull', true) ; DCL.sgpset('lfprop',true) DCL.uscset('cyspos', 'B' ) # y 軸の単位の位置を下方へ end ##----------------------- # お絵描きメソッド初期値 Draw_opts_default = { "levels" => nil, "patterns" => nil, "line" => false, "cont" => true, "tone" => true, "colorbar" => true, "colorbar_opts" => nil, "annot" => true, "map" => false, "exchange" => false, "min" => false, "max" => false, "filename" => nil } ##----------------------- # お絵描きメインメソッド def draw(gphys, frame_flag, options=Draw_opts_default) # check missing valu if gphys.data.val.is_a?(NArrayMiss) for nam if gphys.data.val.is_a?(NArrayMiss) rmiss = (gphys.data.val.max * 2) grid = gphys.grid_copy data = gphys.data + 0 nam = data.val.dup nam.set_missing_value(rmiss) data.replace_val(nam) gphys = GPhys.new(grid, data) before = DCLExt.gl_set_params('lmiss'=>true,'rmiss'=>rmiss) end # check use tonf or tonc if @flag_tonf flag_tonf = false elsif flag_tonf = true end if @flag_tonc flag_tonc = false elsif flag_tonc = true end # set options levels = options["levels"] patterns = options["patterns"] if (options["line"] || gphys.data.val.dim == 1) draw_flag = "line" elsif (!options["line"] && options["mark"]) draw_flag = "mark" elsif (!options["line"] && gphys.data.val.dim >= 2) && options["tone"] && options["cont"] draw_flag = "full" elsif (!options["line"] && gphys.data.val.dim >= 2) && options["tone"] && !options["cont"] draw_flag = "nocont" elsif (!options["line"] && gphys.data.val.dim >= 2) && !options["tone"] && options["cont"] draw_flag = "noshade" end case draw_flag when "line" GGraph.line(gphys, frame_flag, "min"=>options["min"], "max"=>options["max"]) when "mark" GGraph.mark(gphys, frame_flag) when "full" if levels && patterns GGraph.tone(gphys, frame_flag, "lev"=>levels, "patterns"=>patterns, "tonf"=>flag_tonf, "tonc"=>flag_tonc, "annot"=>options["annot"], # "exchange"=>($OPT_exch), "title"=>$title ) else GGraph.tone(gphys, frame_flag, "annot"=>options["annot"], "tonf"=>flag_tonf, "tonc"=>flag_tonc, # "exchange"=>($OPT_exch), "title"=>$title ) end GGraph.contour(gphys, false, "annot"=>options["annot"]) when "nocont" if levels && patterns GGraph.tone(gphys, frame_flag, "lev"=>levels, "patterns"=>patterns, "tonf"=>flag_tonf, "tonc"=>flag_tonc, "annot"=>options["annot"], # "exchange"=>($OPT_exch), "title"=>$title ) else GGraph.tone(gphys, frame_flag, "title"=>$title, "tonf"=>flag_tonf, "tonc"=>flag_tonc, # "exchange"=>($OPT_exch), "annot"=>options["annot"] ) end when "noshade" mj = DCL.udpget('indxmj') mn = DCL.udpget('indxmn') GGraph.contour(gphys, frame_flag, "title"=>$title, "annot"=>true,#options["annot"], "levels"=>levels, "index" =>[mj,mn], # "exchange"=>($OPT_exch), "label" =>true ) end # print unit DCL::sgtxzv(0.78,0.58+0.02,"(units:#{gphys.data.units.to_s})", 0.7*DCL.uzpget('rsizec2'),0,0,3) # print filename DCL::sgtxzv(0.27,0.58+0.02,"[#{options["filename"]}]", 0.5*DCL.uzpget('rsizec2'),0,0,3) if options["filename"] # 地図描画 DCL.draw_map if options["map"] unless (draw_flag == "mark" || draw_flag == "line") if (options["colorbar"] && options["tone"] ) DCL::Util::color_bar(options["colorbar_opts"]) if !options["colorbar_opts"].nil? DCL::Util::color_bar if options["colorbar_opts"].nil? end end DCL.ueitlv # 色設定を白紙に end ##----------------------- # window 閉じる def clwin DCL.grcls end ##----------------------- # 地図描画 def draw_map(vp=[0.15,0.85,0.23,0.58]) DCL::grfig # 改ページしない DCL::grstrn(10) # 正距円筒図法 DCL::grswnd(0.0,360.0,-90.0,90.0) # 緯度経度を設定 DCL::grsvpt(vp[0],vp[1],vp[2],vp[3]) DCL::umpfit # あとはおまかせ DCL::grstrf # 確定 DCL::umpmap("coast_world") # 地図を描く end end