require "numru/ggraph"
include NumRu

minval = 1.0e-80
ncfn = "kdactbl_radmodels-2018-01-23_mkckdtbl_hitemp_dwn1e1_61_Venus.nc"
ncfn = "kdactbl_radmodels-2018-01-23_mkckdtbl_hitemp_dwn1e1_64_Venus_px8.nc"

vname = "BinAbsCoef"
gphys = GPhys::IO.open( ncfn, vname )

gphys = gphys.cut('VMRMol1'=>0.0)
gphys = gphys.cut('VMRMol2'=>0.0)
gphys = gphys.cut('VMRMol3'=>0.0)
gphys = gphys.cut('Temp'=>700.0)
gphys = gphys.cut('MolNum'=>1)

gphys = gphys + minval
gphys = gphys.log10

nbin = gphys.coord('BinWaveNum').val.size
nband = 28
nbineach = nbin/nband

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

DCL.sldiv('y',5,6)
DCL.sgpset('isub', 96)   # control character of subscription: '_' --> '`'
DCL.sgpset('lfull',true)
DCL.uzfact(0.6)

press = gphys.coord('Press').val

binnum = NArray.sfloat(nbin).indgen! + 1
varraytime = VArray.new( binnum,
                         { "long_name"=>'bin number',
                           "units"=>'1' }, "BinNum" )
gphys.axis('BinWaveNum').set_pos(varraytime)

for iband in 0..(nband-1)

  x1 = iband    *nbineach + 1
  x2 = (iband+1)*nbineach

  GGraph.set_fig 'itr'=> 1, 'viewport'=>[0.15,0.9,0.15,0.6], 'window'=>[x1,x2,-30,-20]

  for k in 0..(press.size-1)
    if k == 0 then
      flag_first = true
    else
      flag_first = false
    end

    gphysout = gphys.cut('Press'=>press[k])
    gphysout = gphysout.cut('BinNum'=>x1..x2)

    GGraph.line gphysout, flag_first, 'exchange'=>false, 'index'=>(k+1)*10+1, 'title'=>nil, 'annotate'=>false
  end
end

DCL.grcls
