# -*- coding: utf-8 -*-
# NetCDF ファイルから画像を切り出す Ruby スクリプト
# main = で NetCDF データを指定

require "numru/ggraph"
include NumRu
include GGraph

#<< Graphic Setting >>
DCL.swpset('iwidth',700)      # window width
DCL.swpset('iheight',700)     # window height
###DCL.swpset('ldump',true)      # dump image files
DCL.swpset('lwait',false)     # do not wait mouse click to show the next page
###DCL.swpset('lalt',true)       # background plot
DCL.sgscmn(10)                # change colomap (see below)
###DCL.sgscmn(5)                 # change colomap (see below)

DCL.gropn(2)
DCL.sgpset('lfprop',true)   # to use the propotional font
DCL.sgpset('lcorner',false) # do not show the corner mark
DCL.sgpset('isub', 96)      # control character of subscription: '_' --> '`'
DCL.glpset('lmiss',true)    # handle data missing

#puts "Please input the time."
#num=gets.chomp
#puts "#{num.to_f}"
num=ARGV[2]
var=ARGV[1].to_s
#puts var
filename=ARGV[0].to_s
main = GPhys::IO.open("#{filename}", "#{var}")
#main = GPhys::IO.open("#{filename}", 'Km')
#main = GPhys::IO.open("#{filename}", 'Exner')
#main = GPhys::IO.open("#{filename}", 'PTemp')
#GGraph.contour( main.cut('t'=>num.to_f) )

case "#{var}"
when 'VelX' then
  #速度
  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true, 'levels'=>[-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6])

when 'VelZ' then
  #速度
  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true, 'levels'=>[-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6])

when 'PTemp' then
  #温位
  #GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true, 'levels'=>[-0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6])
  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true, 'levels'=>[-2, -1, 0.0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])

when 'Exner' then
  #エクスナー関数
#  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true, 'levels'=>[-0.00006, -0.00005, -0.00004, -0.00003, -0.00002, -0.00001, 0.0, 0.00001, 0.00002, 0.00003, 0.00004, 0.00005, 0.00006])
  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true, 'levels'=>[-0.006, -0.005, -0.004, -0.003, -0.002, -0.001, 0.0, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006])

when 'Km' then
#乱流拡散係数
  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true, 'levels'=>[0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325])
#  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true, 'levels'=>[0, 5, 10, 15, 20, 25, 30, 35, 40])

when 'H2O-g' then
  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true, 'levels'=>[0, 0.0003, 0.0006, 0.0009, 0.0012, 0.0015])
when 'H2O-s-Rain' then
  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true, 'levels'=>[0, 0.0003, 0.0006, 0.0009, 0.0012, 0.0015])

when 'H2O-s-Cloud' then
  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true, 'levels'=>[0, 0.0001, 0.0002, 0.0003, 0.0004, 0.0005, 0.0006, 0.0007, 0.0008, 0.0009])

else
  #オートスケール
  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0) )
end

GGraph.color_bar('vlength'=>0.5,"landscape"=>true,'tickintv'=>0)
