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

require "numru/ggraph"
include NumRu
include GGraph

filename = "BS1998_PTemp.nc"
filenameBZ = "test_restart.nc" 
var = "PTemp"
varBZ = "PTempBZ"
=begin
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)   
=end
DCL.swlset( 'ldump', true )
DCL.gropn(2)

ptemp      = GPhys::IO.open("#{filename}", "#{var}")
ptempBZ    = GPhys::IO.open("#{filenameBZ}", "#{varBZ}")
ptempAll   = ptemp + ptempBZ[5..104, 0..-1, 5..104]
ptempMeanX = ptempAll.mean("x")
for i in 0..100
  ptempResi  = ptempAll.cut("x"=>i.to_s, "y"=>100) - ptempMeanX
end
time = GPhys::IO.open("#{filename}", 't').val

GGraph.set_linear_contour_options( 'min'=>0, 'max'=>6.0, 'interval'=>1)
GGraph.set_linear_tone_options( 'min'=>0, 'max'=>6.0, 'interval'=>1)


#=begin
for i in 0...time.length do
  GGraph.tone(ptempResi.cut('y'=>100, 't'=>time[i]), true)
  GGraph.contour(ptempResi.cut('y'=>100,'t'=>time[i]),true)
#  GGraph.tone(main.cut('y'=>100, 't'=>time[i])-main.mean('x').cut('y'=>100,'t'=>time[i]),true)
#  GGraph.contour(main.cut('y'=>100,'t'=>time[i])-main.mean('x').cut('y'=>100,'t'=>time[i]),true)

  GGraph.color_bar( 'tickintv'=>4 )
end
#=end
DCL.grcls
