require './analysis_rad'
require "numru/ggraph"
include NumRu

ncfn  = "out/Jupiter_Simple_Spectral_Flux.nc"
vname = "DRadFluxDPress"

grav = 8.9   # gravitational acceleration (m s-2)
cp   = 10998 # specific heat at constant pressure (J K-1 kg-1)


url = ncfn + "@" + vname
gphys = GPhys::IO.open_gturl( url )


# set number of data for running averaging
nave = 15
gphysout = wn_running_mean( gphys, nave )
# convert unit of temperature tendency from W m-2 m Pa-1 to K s-1 m
#   unit of DRadFluxDPress is W m-2 m Pa-1
#   DRadFluxDPress is multiplied by dp/dz / (rho*cp) and its unit is K s-1 m
gphysout = gphysout * grav / cp
gphysout.units = 'K s-1 m'

# change name of pressure axis
ax_press = gphysout.coord("PressLC").copy
ax_press.long_name = 'pressure'
gphysout.axis("PressLC").set_pos(ax_press)


#gphysout = axis_conv_wn( gphysout, false )
gphysout = axis_conv_wl( gphysout, false )
#gphysout = axis_conv_wl( gphysout, true )


iws = (ARGV[0] || (puts ' WORKSTATION ID (I)  ? ;'; DCL::sgpwsn; gets)).to_i
DCL.gropn(iws)

#DCL.sldiv('y',1,4)
#DCL.sgpset('isub', 96)     # control character of subscription: '_' --> '`'
DCL.sglset('LCNTL',true)
DCL.sgpset('lfull',true)
DCL.uzfact(0.6)            # font size
DCL.sgpset('lclip', true)  # clip graph
#DCL.udlset('LMSG', false)  # flag for message of contour interval
DCL.glpset('lmiss',true)   # missing value

#DCL.sgscmn(4)  # blue-cyan-white-yellow-red
#DCL.sgscmn(5)  # gray-scale
DCL.sgscmn(14) # blue-white-red

levels = [-12e-13,-10e-13,-8e-13,-6e-13,-4e-13,-2e-13,0,2e-13,4e-13,6e-13,8e-13,10e-13,12e-13]
patterns = [10999,15999,20999,25999,30999,35999,40999,50999,60999,70999,75999,80999,90999,95999]
levels = [-40e-14,-20e-14,-10e-14,-8e-14,-6e-14,-4e-14,-2e-14,0,2e-14,4e-14,6e-14,8e-14,10e-14,20e-14,40e-14]
patterns = [10999,15999,20999,25999,30999,35999,40999,50999,60999,65999,70999,75999,80999,85999,90999,95999]

GGraph.set_fig 'itr'=> 4, 'viewport'=>[0.1,0.87,0.1,0.65]

GGraph.tone    gphysout, true , 'exchange'=>true,
               'lev'=>levels, 'pat'=>patterns,
               'title'=>'flux convergence'
#GGraph.contour gphysout, false, 'exchange'=>true, 'lev'=>levels
GGraph.color_bar

DCL.grcls
