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

##### thermal-moist_TempAll_rank000000.nc を作成 #####

#gphys = GPhys::NetCDF_IO.open('T.jan.nc', 'T')
#gphys1 = GPhys::NetCDF_IO.open('thermal-moist_ExnerAll_rank000000.nc', 'ExnerAll')
#gphys2 = GPhys::NetCDF_IO.open('thermal-moist_PTempAll_rank000000.nc', 'PTempAll')
gphys1 = GPhys::NetCDF_IO.open('thermal-moist_ExnerAll.nc', 'ExnerAll')
gphys2 = GPhys::NetCDF_IO.open('thermal-moist_PTempAll.nc', 'PTempAll')

# 温度 = エクスナー関数 x 温位
gphys = gphys1 * gphys2
#gphys = gphys1.cut( 't'=>0..86400 ) * gphys2.cut( 't'=>0..86400 )

# 変数の rename など
gphys.data.rename!("TempAll")
gphys.data.set_att('long_name', "Temperature")

# 出力らへん
#outfile = NetCDF.create('tmp.nc')
#outfile = NetCDF.create('thermal-moist_TempAll_rank000000.nc')
outfile = NetCDF.create('thermal-moist_TempAll.nc')
#GPhys::NetCDF_IO.write( outfile, gphys.cut('level'=>1000..250).mean(0) )
#GPhys::NetCDF_IO.write( outfile, gphys.cut('level'=>1000..250).mean(0,1).rename('T00') )
#GPhys::NetCDF_IO.write( outfile, ( gphys1*gphys2 ).rename('Temp') )
GPhys::NetCDF_IO.write( outfile, gphys )

# outfile を閉じる
outfile.close

exit

##### thermal-moist_TempAll_rank000001.nc を作成 #####

#gphys = GPhys::NetCDF_IO.open('T.jan.nc', 'T')
gphys1 = GPhys::NetCDF_IO.open('thermal-moist_ExnerAll_rank000001.nc', 'ExnerAll')
gphys2 = GPhys::NetCDF_IO.open('thermal-moist_PTempAll_rank000001.nc', 'PTempAll')

# 温度 = エクスナー関数 x 温位
gphys = gphys1 * gphys2

# 変数の rename など
gphys.data.rename!("TempAll")
gphys.data.set_att('long_name', "Temperature")

# 出力らへん
#outfile = NetCDF.create('tmp.nc')
outfile = NetCDF.create('thermal-moist_TempAll_rank000001.nc')
#GPhys::NetCDF_IO.write( outfile, gphys.cut('level'=>1000..250).mean(0) )
#GPhys::NetCDF_IO.write( outfile, gphys.cut('level'=>1000..250).mean(0,1).rename('T00') )
#GPhys::NetCDF_IO.write( outfile, ( gphys1*gphys2 ).rename('Temp') )
GPhys::NetCDF_IO.write( outfile, gphys )

# outfile を閉じる
outfile.close





