# -*- 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}")

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'=>-1.60e-4, 'max'=>1.60e-4, 'interval'=>1.0e-5)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  when 'VelZ' then
    #速度
    GGraph.set_linear_tone_options('min'=>1.70e-5, 'max'=>3.70e-3, 'interval'=>1.0e-4)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  when 'PTemp' then
    #温位
    GGraph.set_linear_tone_options('min'=>0.0, 'max'=>10.0, 'interval'=>0.50)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  when 'Exner' then
    #エクスナー関数
    GGraph.set_linear_tone_options('min'=>-4.50e-4, 'max'=>8.60e-4, 'interval'=>1.0e-4)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  when 'Km' then
    #乱流拡散係数
    GGraph.set_linear_tone_options('min'=>0.0, 'max'=>10.0, 'interval'=>1.0)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
    
  when 'H2O-g' then
    GGraph.set_linear_tone_options('min'=>-4.0, 'max'=>10.0, 'interval'=>1.0)
    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'=>1.0, 'interval'=>0.1)
    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.000005, 'interval'=>0.000001)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )

  when 'NH3-g' then
    GGraph.set_linear_tone_options('min'=>-0.000008, 'max'=>0.000009, 'interval'=>0.000001)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
    
  when 'NH3-s-Rain' then
    GGraph.set_linear_tone_options('min'=>0.0, 'max'=>0.000005, 'interval'=>0.000001)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )
  
  when 'NH3-s-Cloud' then
    GGraph.set_linear_tone_options('min'=>0.0, 'max'=>0.000005, 'interval'=>0.000001)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )

  when 'NH4SH-s-Cloud' then
    GGraph.set_linear_tone_options('min'=>0.0, 'max'=>0.0000008, 'interval'=>0.0000001)
    GGraph.tone( main.cut('t'=>num.to_f, 'y'=>0), true )

  when 'NH4SH-s-Rain' then
    GGraph.set_linear_tone_options('min'=>0.0, 'max'=>0.000015, 'interval'=>0.000001)
    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)
  
