# -*- coding: euc-jp -*-

# 全領域での水蒸気, 雲水, 雨水のトータルの値の時間積分計算するスクリプト

require "numru/ggraph"
include NumRu

#timestep  = ARGV[0].to_i

x1 = 0
x2 = 256000
z1 = 0
z2 = 24000
#z2 = 30000
#z2 = 48000
dz = 300
t1 = 0
t2 = 2592000
#t2 = 86400 * 30
tn = 1440
#tn = 2400

files = "thermal-moist_H2O-gInt.nc"
gphys1 = GPhys::IO.open(files, 'H2O-gInt')
files = "thermal-moist_H2O-l-CloudInt.nc"
gphys11 = GPhys::IO.open(files, 'H2O-l-CloudInt')
files = "thermal-moist_H2O-l-RainInt.nc"
gphys12 = GPhys::IO.open(files, 'H2O-l-RainInt')
#files = "thermal-moist_H2O-g_SfcMassFlux.nc"
files = "thermal-moist_H2O-g_SfcMassFlux_IntValue30day.nc"
gphys2 = GPhys::IO.open(files, 'H2O-g_SfcMassFlux')
#files = "thermal-moist_H2O-l-Rain_FallFluxAtLB.nc"
files = "thermal-moist_H2O-l-Rain_FallFluxAtLB_IntValue30day.nc"
gphys3 = GPhys::IO.open(files, 'H2O-l-Rain_FallFluxAtLB')


#-- 水蒸気混合比の鉛直積分の時間変化を求める --#
gphysdisp0 = gphys1.cut( 't'=>t2 ).val - gphys1.cut( 't'=>t1 ).val
#gphysdisp0 = gphysdisp0 * dz
gphysdisp1 = gphysdisp0

print "\n Variation of Integral of H2O-gAll in z :\n"
p gphysdisp1

#-- 雲水混合比の鉛直積分の時間変化を求める --#
gphysdisp0 = gphys11.cut( 't'=>t2 ).val - gphys11.cut( 't'=>t1 ).val
#gphysdisp0 = gphysdisp0 * dz
gphysdisp11 = gphysdisp0

print "\n Variation of Integral of H2O-l-CloudAll in z :\n"
p gphysdisp11

#-- 雨水混合比の鉛直積分の時間変化を求める --#
gphysdisp0 = gphys12.cut( 't'=>t2 ).val - gphys12.cut( 't'=>t1 ).val
#gphysdisp0 = gphysdisp0 * dz
gphysdisp12 = gphysdisp0

print "\n Variation of Integral of H2O-l-RainAll in z :\n"
p gphysdisp12

#gphysdisp0 = gphys
gphysdisp0 = gphys2
gphysdisp0 = gphysdisp0.mean( 'x' )
gphysdisp0 = gphysdisp0.mean( 'y' )
gphysdisp0 = gphysdisp0.cut( 't'=>t2 ).val
gphysdisp0 = gphysdisp0 * t2
#gphysdisp0 = gphysdisp0.cut( 'z'=>150 )
#gphysdisp  = gphysdisp0
gphysdisp2 = gphysdisp0

print "\n Total of H2O-g_SfcMassFlux :\n"
p gphysdisp2

gphysdisp0 = gphys3
gphysdisp0 = gphysdisp0.mean( 'x' )
gphysdisp0 = gphysdisp0.mean( 'y' )
gphysdisp0 = gphysdisp0.cut( 't'=>t2 ).val
gphysdisp0 = gphysdisp0 * t2
#gphysdisp0 = gphysdisp0.cut( 'z'=>150 )
#gphysdisp  = gphysdisp0
gphysdisp3 = gphysdisp0

print "\n Total of H2O-l-Rain_FallFlux at Lower Boundary :\n"
p gphysdisp3

gphysdisp = gphysdisp2 + gphysdisp3 - gphysdisp1 - gphysdisp11 - gphysdisp12
print "\n Budget of water vapor :\n"
#print "\n Budget of water vapor = H2O-g_SfcMassFlux - H2O-l-Rain_FallFluxAtLB + Variation of H2O-gAll \n"
p gphysdisp

