# -*- coding: euc-jp -*-
require "numru/ggraph"
include NumRu

casenum = 25

gpuf = GPhys::IO.open("RadLUWFLXB.nc","RadLUWFLXB")
gpdf = GPhys::IO.open("RadLDWFLXB.nc","RadLDWFLXB")

gpuf = gpuf.cut('lon'=>0).cut('lat'=>0).cut('time'=>0).copy
gpdf = gpdf.cut('lon'=>0).cut('lat'=>0).cut('time'=>0).copy

gpuf.long_name = 'Radiation flux'
gpdf.long_name = 'Radiation flux'

ps = 1013.00
p 'Surface pressure is assumed to be ' + ps.to_s + ' hPa'

plev = gpuf.coord('sigm').val
plev = plev * ps
varrayplev = VArray.new( plev,
                         { "long_name"=>'Pressure',
                           "units"=>'hPa' }, "plev" )
gpuf.axis('sigm').set_pos(varrayplev)
gpdf.axis('sigm').set_pos(varrayplev)

gpuflblrtm = GPhys::IO.open("lblrtm/Case"+casenum.to_s+"flux.nc","upflux")
gpdflblrtm = GPhys::IO.open("lblrtm/Case"+casenum.to_s+"flux.nc","downflux")
z = gpuflblrtm.axis('level').pos.convert_units( Units['hPa'] )
gpuflblrtm.axis('level').set_pos(z)
z = gpdflblrtm.axis('level').pos.convert_units( Units['hPa'] )
gpdflblrtm.axis('level').set_pos(z)

iws= 4
DCL.gropn(iws)                            # iws : DCL出力デバイス．1,4:画面, 2:PS
DCL.glpset('lmiss',true)                  # DCLの欠損値処理を on に
GGraph.set_fig "window"=>[0,500,ps,0], "viewport"=>[0.15,0.85,0.15,0.85]

GGraph.line gpuf, true, 'exchange'=>true, 
  "annot"=>false,  # 右脇のアノテーション非表示
  "title"=>"Longwave radiation flux", 'type'=>1, 'index'=>20, 
  'legend_vx'=>0.2, "legend"=>'Upward flux'
GGraph.line gpdf, false, 'exchange'=>true, 
  "annot"=>false,  # 右脇のアノテーション非表示
  "title"=>"Longwave radiation flux", 'type'=>1, 'index'=>40, 
  'legend_vx'=>0.2, "legend"=>'Downward flux'

GGraph.line gpuflblrtm, false, 'exchange'=>true, 
  "annot"=>false,  # 右脇のアノテーション非表示
  "title"=>"Longwave radiation flux", 'type'=>2, 'index'=>20
#, 
#  'legend_vx'=>0.2, "legend"=>'Upward flux (LBLRTM)'
GGraph.line gpdflblrtm, false, 'exchange'=>true, 
  "annot"=>false,  # 右脇のアノテーション非表示
  "title"=>"Longwave radiation flux", 'type'=>2, 'index'=>40
#, 
#  'legend_vx'=>0.2, "legend"=>'Downward flux (LBLRTM)'

DCL.grcls
