# -*- coding: euc-jp -*-
require "numru/ggraph"
include NumRu

#time  = ARGV[0].to_i
tn = ARGV[0].to_i
dt = ARGV[1].to_i
time = tn * dt

x1 = 250
x2 = 124750                       # エラーはいたので変えてみる
z1 = 100
z2 = 29900                        # エラーはいたので変えてみる


files = '../../netCDF/thermal-moist_restart.nc'
gphys10 = GPhys::IO.open(files, 'PTempBZ')
files = '../../netCDF/PTemp.nc'
gphys1  = GPhys::IO.open(files, 'PTemp')

files = '../../netCDF/thermal-moist_restart.nc'
gphys20 = GPhys::IO.open(files, 'QMixBZ')
gphys20 = gphys20.cut( 's'=>1 )
files = '../../netCDF/H2O-g.nc'
gphys2  = GPhys::IO.open(files, 'H2O-g')

files = '../../netCDF/thermal-moist_restart.nc'
gphys30 = GPhys::IO.open(files, 'QMixBZ')
gphys30 = gphys30.cut( 's'=>2 )
files = '../../netCDF/H2O-l-Cloud.nc'
gphys3  = GPhys::IO.open(files, 'H2O-l-Cloud')

files = '../../netCDF/thermal-moist_restart.nc'
gphys40 = GPhys::IO.open(files, 'QMixBZ')
gphys40 = gphys40.cut( 's'=>3 )
files = '../../netCDF/H2O-l-Rain.nc'
gphys4  = GPhys::IO.open(files, 'H2O-l-Rain')


#DCL.gropn(1)
DCL.gropn(4)
DCL.sldiv('y',1,4)
#DCL.sldiv('y',2,2)
#DCL.sldiv('y',1,2)
DCL.sgpset('lfull',true)
DCL.sgpset('lcntl', false)
DCL.uzfact(0.3)
#GGraph.set_fig( 'viewport'=>[0.25,0.7,0.15,0.6] )
GGraph.set_fig( 'viewport'=>[0.25,0.8,0.05,0.15] )

xax = gphys1.coord(0)
zax = gphys1.coord(2)

vpy1 = 0.05
vpy2 = 0.14

#-----

gphysdisp0 = gphys10.cut( 'x'=>x1..x2 ).cut( 'y'=>100 ).cut( 'z'=>z1..z2 ) + gphys1.cut( 't'=>time ).cut( 'x'=>x1..x2 ).cut( 'y'=>100 ).cut( 'z'=>z1..z2 )
#gphysdisp0 = gphysdisp0.mean( 'y' )

gphysdisp0.long_name = 'Potential Temperature'
gphysdisp0.units = 'K'

gphysdisp = gphysdisp0
GGraph.fig( xax, zax, 'new_frame'=>false, 
            'viewport'=>[0.25,0.9,vpy1,vpy2], 'window'=>[x1,x2,z1,z2] )
GGraph.set_tone_levels( 
             'lev'=>[300.0,350.0,400.0,450.0,500.0,550.0,600.0,650.0,700.0,750.0,800.0],
             'pat'=>[10999,15999,20999,25999,30999,40999,50999,65999,70999,80999,90999] )
GGraph.tone( gphysdisp )

#GGraph.axes( xax, zax )
#GGraph.title( gphysdisp.long_name )
GGraph.color_bar( 'vlength'=>0.07, 'inffact'=>0.5 )

GGraph.annotate( [ ( time / 3600.0 ).to_s + ' hours' ] )

#-----

gphysdisp0 = gphys20.cut( 'x'=>x1..x2 ).cut( 'y'=>100 ).cut( 'z'=>z1..z2 ) + gphys2.cut( 't'=>time ).cut( 'x'=>x1..x2 ).cut( 'y'=>100 ).cut( 'z'=>z1..z2 )
gphysdisp0.long_name = 'Water vapor mixing ratio'

gphysdisp = gphysdisp0
GGraph.fig( xax, zax, 'new_frame'=>false, 
            'viewport'=>[0.25,0.9,vpy1,vpy2], 'window'=>[x1,x2,z1,z2] )
GGraph.set_tone_levels(
   'lev'=>[0,0.000001,0.00015,0.00030,0.00045,0.00060,0.00075,0.00090,0.00105,0.00120,0.00135,0.0015],
   'pat'=>[1,10999,15999,20999,25999,30999,40999,50999,65999,70999,80999,90999] )

GGraph.tone( gphysdisp )

#GGraph.axes( xax, zax )
#GGraph.title( gphysdisp.long_name )
GGraph.color_bar( 'vlength'=>0.07, 'inffact'=>0.5 )

#-----

gphysdisp0 = gphys30.cut( 'x'=>x1..x2 ).cut( 'y'=>100 ).cut( 'z'=>z1..z2 ) + gphys3.cut( 't'=>time ).cut( 'x'=>x1..x2 ).cut( 'y'=>100 ).cut( 'z'=>z1..z2 )
#gphysdisp0 = gphysdisp0.mean( 'y' )
gphysdisp0.long_name = 'Cloud mixing ratio'

gphysdisp = gphysdisp0
GGraph.fig( xax, zax, 'new_frame'=>false, 
            'viewport'=>[0.25,0.9,vpy1,vpy2], 'window'=>[x1,x2,z1,z2] )
GGraph.set_tone_levels(
   'levels'=>[0,0.0000001,0.00003,0.00006,0.00009,0.00012,0.00015,0.00018,0.00021,0.00024,0.00027,0.0003],
   'patterns'=>[1,10999,15999,20999,25999,30999,40999,50999,65999,70999,80999,90999] )
GGraph.tone( gphysdisp )

#GGraph.axes( xax, zax )
#GGraph.title( gphysdisp.long_name )
GGraph.color_bar( 'vlength'=>0.07, 'inffact'=>0.5 )


#-----

gphysdisp0 = gphys40.cut( 'x'=>x1..x2 ).cut( 'y'=>100 ).cut( 'z'=>z1..z2 ) + gphys4.cut( 't'=>time ).cut( 'x'=>x1..x2 ).cut( 'y'=>100 ).cut( 'z'=>z1..z2 )
#gphysdisp0 = gphysdisp0.mean( 'y' )
gphysdisp0.long_name = 'Rain mixing ratio'

gphysdisp = gphysdisp0
GGraph.fig( xax, zax, 'new_frame'=>false, 
            'viewport'=>[0.25,0.9,vpy1,vpy2], 'window'=>[x1,x2,z1,z2] )
GGraph.set_tone_levels(
   'levels'=>[0,0.0000001,0.0005,0.0010,0.0015,0.0020,0.0025,0.0030,0.0035,0.0040,0.0045,0.0050],
   'patterns'=>[1,10999,15999,20999,25999,30999,40999,50999,65999,70999,80999,90999] )
GGraph.tone( gphysdisp )

#GGraph.axes( xax, zax )
#GGraph.title( gphysdisp.long_name )
GGraph.color_bar( 'vlength'=>0.07, 'inffact'=>0.5 )


DCL.grcls


