# -*- 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
autoscale=ARGV[3].to_i
#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) )
if autoscale == 1 then
  #オートスケール
  GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0) )
else
  case "#{var}"
  when 'VelX' then
    #速度
    GGraph.set_linear_tone_options('min'=>-40.0, 'max'=>31.0, 'interval'=>1.0)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  when 'VelZ' then
    #速度
    GGraph.set_linear_tone_options('min'=>-27.0, 'max'=>31.0, 'interval'=>1.0)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  when 'PTemp' then
    #温位
    GGraph.set_linear_tone_options('min'=>-5.0, 'max'=>14.0, 'interval'=>0.5)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  when 'Exner' then
    #エクスナー関数
    GGraph.set_linear_tone_options('min'=>-0.0012, 'max'=>0.0046, 'interval'=>0.0005)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  when 'Km' then
    #乱流拡散係数
    GGraph.set_linear_tone_options('min'=>0, 'max'=>480, 'interval'=>20)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
    
  when 'H2O-g' then
    GGraph.set_linear_tone_options('min'=>-0.0060, 'max'=>0.0020, 'interval'=>0.0002)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  when 'H2O-s-Rain' then
    GGraph.set_linear_tone_options('min'=>0.0, 'max'=>0.0040, 'interval'=>0.0002)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  when 'H2O-s-Cloud' then
    GGraph.set_linear_tone_options('min'=>0.0, 'max'=>0.0020, 'interval'=>0.0001)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  else
    #オートスケール
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0) )
  end
end
GGraph.color_bar('vlength'=>0.5,"landscape"=>true,'tickintv'=>0)
  
