#! /usr/bin/ruby
# -*- coding: euc-jp -*-

# 同期回転惑星計算用描画スクリプト
# == 説明
# * このスクリプトは同期回転惑星設定実験の結果の図を作成するものである.
# * このスクリプトでは, gpview, fig_heatflux-lat-dependence.rb などの
#   スクリプトが使われる.
# * 使用する場合には, fig_heatflux-lat-dependence.rb などを格納した
#   ディレクトリを指定する必要がある.
#   そのために, script_dir を適宜書き換えねばならない.
#
# == オプション
# --time_start 開始時刻
# --time_end   終了時刻
# --wsn        出力先. ps だったら --wsn=2
# --prefix     生成する画像ファイルに付ける接頭詞
#
# == USAGE
#   % fig_SyncRot.rb --time_start=731 --time_end=1095 --wsn=2 --prefix=EXPNAME_
#
# == 履歴
# * 2013-6-19 石渡正樹 作成


require "getoptlong"        # for option_parse
require "numru/ggraph"
include NumRu

script_dir = "/GFD_Dennou_Work3/momoko/SyncRotEarthRad/script"
## オプション解析
parser = GetoptLong.new
parser.set_options(
        ###    global option   ###
       ['--time_start',              GetoptLong::REQUIRED_ARGUMENT],
       ['--time_end',                GetoptLong::REQUIRED_ARGUMENT],
       ['--cint_cloud',              GetoptLong::REQUIRED_ARGUMENT],
       ['--range_cloud',             GetoptLong::REQUIRED_ARGUMENT],
       ['--fact_qvaptrnsprt',        GetoptLong::REQUIRED_ARGUMENT],
       ['--vecunit_qvaptrnsprt',     GetoptLong::REQUIRED_ARGUMENT],
       ['--wsn',                     GetoptLong::REQUIRED_ARGUMENT],
       ['--prefix',                  GetoptLong::REQUIRED_ARGUMENT]
                   )
parser.each_option do |name, arg|
    eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_')} = '#{arg}'"  # strage option value to $OPT_val
end

wsn = ($OPT_wsn||4)

fact_qvaptrnsprt = ($OPT_fact_qvaptrnsprt||'0.3')
vecunit_qvaptrnsprt = ($OPT_vecunit_qvaptrnsprt||'0.2')

range_stream = ($OPT_range_stream||'-100:100')
minval_stream = range_stream.split(':')[0].to_f
maxval_stream = range_stream.split(':')[1].to_f

cint_cloud = ($OPT_cint_cloud||0.05).to_s
range_cloud = ($OPT_range_cloud||'0:2').to_s
 
time_start = ($OPT_time_start||1).to_s
time_end = ($OPT_time_end||9999).to_s

timespan = time_start + ':' + time_end

# dennou-h でメモリが足りなくなる場合は, 最後の 300 日だけにする.

#p time_end.class

# ちょっと前までは 289 を引いていた.
value_time_start_newdata = time_end.to_i - 200
time_start_newdata = value_time_start_newdata.to_s

# 冷却率 これはソースを変更して出力したもののはず.
#system("{script_dir}/fig_CoolRate.rb --time_start=#{time_start} --time_end=#{time_end} --wsn=#{wsn} --prefix=#{$OPT_prefix}")




# 0 次元量の時間変化

# 表面温度の水平平均 時系列
if File.exist?($OPT_prefix + 'SurfTemp_horimean_timeseries.png') then
  puts("MESSAGE: #{$OPT_prefix}SurfTemp_horimean_timeseries.png exists. process skipped.")
else
  system("#{script_dir}/fig_horimean-timeseries.rb --var=SurfTemp --range=200:500 --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}SurfTemp_horimean_timeseries.png")
end



# OSRの水平平均 時系列
if File.exist?($OPT_prefix + 'OSRA_horimean_timeseries.png') then
  puts("MESSAGE: #{$OPT_prefix}OSRA_horimean_timeseries.png exists. process skipped.")
else
  system("#{script_dir}/fig_horimean-timeseries.rb --var=OSRA --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}OSRA_horimean_timeseries.png")
end


# 熱フラックス
if File.exist?($OPT_prefix + 'HeatFlux-all_timeseries.png') then
  puts("MESSAGE: #{$OPT_prefix}HeatFlux-all_timeseries.png exists. process skipped.")
else
  system("#{script_dir}/fig_timeseries-heat.rb --region=all --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}HeatFlux-all_timeseries.png")
end


# OSR & OLR
if File.exist?($OPT_prefix + 'OSR-OLR_timeseries.png') then
  puts("MESSAGE: #{$OPT_prefix}OSR-OLR_timeseries.png exists. process skipped.")
else
  system("#{script_dir}/fig_absorb.rb --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}OSR-OLR_timeseries.png")
end


# 雲水量全球積算値
if File.exist?('VertIntH2OLiq.nc') then
  puts("MESSAGE: VertIntH2OLiq.nc exists. process skipped.")
else
  system("#{script_dir}/make_vertinteg.rb --var=H2OLiq") unless File.exist?('VerIntH2OLiq.nc')
end
if File.exist?($OPT_prefix + 'H2OLiq_globalinteg_timeseries.png') then
  puts("MESSAGE: #{$OPT_prefix}H2OLiq_globalinteg_timeseries.png exists. process skipped.")
else
  system("#{script_dir}/fig_horimean-timeseries.rb --var=VertIntH2OLiq --time_start=#{time_start} --time_end=#{time_end} --range=0:0.2 --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}H2OLiq_globalinteg_timeseries.png")
end

# 雲水量 昼半球積算値
if File.exist?('VertIntH2OLiq.nc') then
  puts("MESSAGE: VertIntH2OLiq.nc exists. process skipped.")
else
  system("#{script_dir}/make_vertinteg.rb --var=H2OLiq") unless File.exist?('VerIntH2OLiq.nc')
end
if File.exist?($OPT_prefix + 'H2OLiq_westinteg_timeseries.png') then
  puts("MESSAGE: #{$OPT_prefix}H2OLiq_westinteg_timeseries.png exists. process skipped.")
else
  system("#{script_dir}/fig_horimean-timeseries.rb --var=VertIntH2OLiq --lon_start=0 --lon_end=180 --time_start=#{time_start} --time_end=#{time_end} --range=0:0.2 --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}H2OLiq_westinteg_timeseries.png")
end

# 雲水量 夜半球積算値
if File.exist?('VertIntH2OLiq.nc') then
  puts("MESSAGE: VertIntH2OLiq.nc exists. process skipped.")
else
  system("#{script_dir}/make_vertinteg.rb --var=H2OLiq") unless File.exist?('VerIntH2OLiq.nc')
end

if File.exist?($OPT_prefix + 'H2OLiq_eastinteg_timeseries.png') then
  puts("MESSAGE: #{$OPT_prefix}H2OLiq_eastinteg_timeseries.png exists. process skipped.")
else
  system("#{script_dir}/fig_horimean-timeseries.rb --var=VertIntH2OLiq --lon_start=180 --lon_end=359 --time_start=#{time_start} --time_end=#{time_end} --range=0:0.2 --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}H2OLiq_eastinteg_timeseries.png")
end



# Tg-OLR 散布図
if File.exist?($OPT_prefix + 'scatter_Tg-OLR_180x180.png') then
  puts("MESSAGE: #{$OPT_prefix}scatter_Tg-OLR_180x180.png exists. process skipped.")
else
  system("#{script_dir}/scatter_Tg-OLR.rb --time_start=#{time_start} --time_end=#{time_end} --area=180 --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}scatter_Tg-OLR_180x180.png") 
end



if File.exist?($OPT_prefix + 'scatter_Tg-OLR_120x120.png') then
  puts("MESSAGE: #{$OPT_prefix}scatter_Tg-OLR_120x120.png exists. process skipped.")
else
  system("#{script_dir}/scatter_Tg-OLR.rb --time_start=#{time_start} --time_end=#{time_end} --area=120 --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}scatter_Tg-OLR_120x120.png") 
end

if File.exist?($OPT_prefix + 'scatter_Tg-OLR_90x90.png') then
  puts("MESSAGE: #{$OPT_prefix}scatter_Tg-OLR_90x90.png exists. process skipped.")
else
  system("#{script_dir}/scatter_Tg-OLR.rb --time_start=#{time_start} --time_end=#{time_end} --area=90 --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}scatter_Tg-OLR_90x90.png") 
end



# 等値線とベクトル
if File.exist?($OPT_prefix + 'qvap-column_trnsprt_q_all.png') then
  puts("MESSAGE: #{$OPT_prefix}qvap-column_trnsprt_q_all.png exists. process skipped.")
else
  system("#{script_dir}/qvap-column_trnsprt_q.rb --range_time #{time_start_newdata}:#{time_end} --xfact1 #{fact_qvaptrnsprt} --yfact1 #{fact_qvaptrnsprt} --uxunit #{vecunit_qvaptrnsprt} --uyunit #{vecunit_qvaptrnsprt} --type 1 --wsn #{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}qvap-column_trnsprt_q_all.png") 
#  system("#{script_dir}/qvap-column_trnsprt_q.rb --range_time #{time_start_newdata}:#{time_end} --xfact1 0.3 --yfact1 0.3 --uxunit 0.2 --uyunit 0.2 --type 1 --wsn #{wsn} && dclpsrot dcl.ps > #{$OPT_prefix}qvap-column_trnsprt_q_all.ps && convert #{$OPT_prefix}qvap-column_trnsprt_q_all.ps #{$OPT_prefix}qvap-column_trnsprt_q_all.png") 
end


# 乾燥静的エネルギーの輸送 (矢印プロット)
if File.exist?($OPT_prefix + 'trnsprt_s_all.png') then
  puts("MESSAGE: #{$OPT_prefix}trnsprt_s_all.png exists. process skipped.")
else
  system("#{script_dir}/trnsprt_s_v2.rb --range_time #{time_start}:#{time_end} --xfact1 2e-8 --yfact1 2e-8 --uxunit 3e6 --uyunit 3e6 --type 1 --wsn #{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}trnsprt_s_all.png") 
#  system("#{script_dir}/trnsprt_s.rb --range_time #{time_start_newdata}:#{time_end} --xfact1 2e-8 --yfact1 2e-8 --uxunit 3e6 --uyunit 3e6 --type 1 --wsn #{wsn} && dclpsrot dcl.ps > #{$OPT_prefix}trnsprt_s_all.ps && convert #{$OPT_prefix}trnsprt_s_all.ps #{$OPT_prefix}trnsprt_s_all.png") 
end


# 潜熱エネルギーの輸送 (矢印プロット)
if File.exist?($OPT_prefix + 'trnsprt_lq_all.png') then
  puts("MESSAGE: #{$OPT_prefix}trnsprt_lq_all.png exists. process skipped.")
else
  system("#{script_dir}/trnsprt_lq_v2.rb --range_time #{time_start}:#{time_end} --xfact1 2e-7 --yfact1 2e-7 --uxunit 3e5 --uyunit 3e5 --type 1 --wsn #{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}trnsprt_lq_all.png") 
end


# 土壌データ
if File.exist?("#{$OPT_prefix}SoilTemp.png") then
  puts("MESSAGE: #{$OPT_prefix}SoilTemp.png exists. process skipped.")
else
  system("gpview SoilTemp.nc@SoilTemp,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}SoilTemp.png")
end

if File.exist?("#{$OPT_prefix}SoilMoist.png") then
  puts("MESSAGE: #{$OPT_prefix}SoilMoist.png exists. process skipped.")
else
  system("gpview SoilMoist.nc@SoilMoist,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}SoilMoist.png")
end


# 鉛直積算量 水平分布
if File.exist?('VertIntQVap.nc') then
  puts("MESSAGE: VertIntQVap.nc exists. process skipped.")
else
  system("#{script_dir}/make_vertinteg.rb --var=QVap") unless File.exist?('VerIntQVap.nc')
end
if File.exist?($OPT_prefix + 'IntegratedQVap.png') then
  puts("MESSAGE: #{$OPT_prefix}IntegratedQVap.png exists. process skipped.")
else
  system("gpview VertIntQVap.nc@VertIntQVap,time=#{timespan} --mean time --noannotate --cint=5 --range=0:120 --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}IntegratedQVap.png")
end

if File.exist?('VertIntH2OLiq.nc') then
  puts("MESSAGE: VertIntH2OLiq.nc exists. process skipped.")
else
  system("#{script_dir}/make_vertinteg.rb --var=H2OLiq") unless File.exist?('VerIntH2OLiq.nc')
end
if File.exist?($OPT_prefix + 'IntegratedH2OLiq.png') then
  puts("MESSAGE: #{$OPT_prefix}IntegratedH2OLiq.png exists. process skipped.")
else
  system("gpview VertIntH2OLiq.nc@VertIntH2OLiq,time=#{timespan} --mean time --noannotate --int=#{cint_cloud} --range=#{range_cloud} --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}IntegratedH2OLiq.png")
end


# 2 次元データ 水平分布
if File.exist?("#{$OPT_prefix}SurfTemp.png") then
  puts("MESSAGE: #{$OPT_prefix}SurfTemp.png exists. process skipped.")
else
  # for SyncRot with increased S
  system("gpview SurfTemp.nc@SurfTemp,time=#{timespan} --mean time --range=180:340 --wsn=#{wsn} --cint=5 --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}SurfTemp.png")
# for standard of S=1366
#  system("gpview SurfTemp.nc@SurfTemp,time=#{timespan} --mean time --range=180:330 --wsn=#{wsn} --cint=5 --noannotate && dclpsrot dcl.ps > #{$OPT_prefix}SurfTemp.ps && convert #{$OPT_prefix}SurfTemp.ps #{$OPT_prefix}SurfTemp.png")
end

if File.exist?("#{$OPT_prefix}SurfTemp_Ecolor.png") then
  puts("MESSAGE: #{$OPT_prefix}SurfTemp_Ecolor.png exists. process skipped.")
else
  system("gpview SurfTemp.nc@SurfTemp,time=#{timespan} --mean time --wsn=#{wsn} --noannotate --levels 999,210,220,230,240,250,260,270,280,290,300,999 --pattern 20999,29999,40999,45999,50999,55999,60999,70999,80999,85999,90999 && #{script_dir}/conv_image.rb #{$OPT_prefix}SurfTemp_Ecolor.png")
end

if File.exist?("#{$OPT_prefix}OLR.png") then
  puts("MESSAGE: #{$OPT_prefix}OLR.png exists. process skipped.")
else
#  system("gpview OLR.nc@OLR,time=#{timespan} --mean time --wsn=#{wsn} --noannotate --sint=10 --range=130:440 && dclpsrot dcl.ps > #{$OPT_prefix}OLR.ps && convert #{$OPT_prefix}OLR.ps #{$OPT_prefix}OLR.png")
  system("gpview OLR.nc@OLR,time=#{timespan} --mean time --wsn=#{wsn} --noannotate --sint=10 --range=130:440 && #{script_dir}/conv_image.rb #{$OPT_prefix}OLR.png")
end

if File.exist?("#{$OPT_prefix}OLRA.png") then
  puts("MESSAGE: #{$OPT_prefix}OLRA.png exists. process skipped.")
else
  system("gpview OLRA.nc@OLRA,time=#{timespan} --mean time --wsn=#{wsn} --noannotate --cint=10 --range=100:420 && #{script_dir}/conv_image.rb #{$OPT_prefix}OLRA.png")
end

if File.exist?("#{$OPT_prefix}OLRA_Ecolor.png") then
  puts("MESSAGE: #{$OPT_prefix}OLRA_Ecolor.png exists. process skipped.")
else
  system("gpview OLRA.nc@OLRA,time=#{timespan} --mean time --wsn=#{wsn} --noannotate --levels 999,100,120,140,160,180,200,220,240,260,280,300,999 --pattern 10999,16999,20999,24999,29999,35999,40999,45999,55999,70999,80999,90999 && #{script_dir}/conv_image.rb #{$OPT_prefix}OLRA_Ecolor.png")
end

if File.exist?("#{$OPT_prefix}SLRA.png") then
  puts("MESSAGE: #{$OPT_prefix}SLRA.png exists. process skipped.")
else
  system("gpview SLRA.nc@SLRA,time=#{timespan} --mean time --wsn=#{wsn} --noannotate --cint=10 --range=100:420 && #{script_dir}/conv_image.rb #{$OPT_prefix}SLRA.png")
end

if File.exist?("#{$OPT_prefix}Rain.png") then
  puts("MESSAGE: #{$OPT_prefix}Rain.png exists. process skipped.")
else
  system("gpview Rain.nc@Rain,time=#{timespan} --mean time --range=0:1e-4 --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}Rain.png")
end

if File.exist?("#{$OPT_prefix}PRCP.png") then
  puts("MESSAGE: #{$OPT_prefix}PRCP.png exists. process skipped.")
else
  system("gpview PRCP.nc@PRCP,time=#{timespan} --mean time --range=1e-6:1e-4 --cint=5.0e-6 --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}PRCP.png")
end

if File.exist?("#{$OPT_prefix}PRCP_Ecolor.png") then
  puts("MESSAGE: #{$OPT_prefix}PRCP_Ecolor.png exists. process skipped.")
else
  system("gpview PRCP.nc@PRCP,time=#{timespan} --mean time --range=0:1e-3 --cint=5e-5 --wsn=#{wsn} --noannotate --levels 999,0,1e-5,2e-5,4e-5,8e-5,1.2e-4,1.6e-4,2.0e-4,2.4e-4,2.8e-4,3.2e-4,999 --pattern 99999,20999,29999,35999,40999,45999,55999,65999,70999,75999,80999,90999 && #{script_dir}/conv_image.rb #{$OPT_prefix}PRCP_Ecolor.png")
end

if File.exist?("#{$OPT_prefix}SurfH2OVapFluxU.png") then
  puts("MESSAGE: #{$OPT_prefix}SurfH2OVapFluxU.png exists. process skipped.")
else
  system("gpview SurfH2OVapFluxU.nc@SurfH2OVapFluxU,time=#{timespan} --mean time --cint=1.0e-5 --range=0:1e-4 --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}SurfH2OVapFluxU.png")
end

if File.exist?("#{$OPT_prefix}Evap.png") then
  puts("MESSAGE: #{$OPT_prefix}Evap.png exists. process skipped.")
else
  system("gpview Evap.nc@Evap,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}Evap.png")
end

if File.exist?("#{$OPT_prefix}EvapU.png") then
  puts("MESSAGE: #{$OPT_prefix}EvapU.png exists. process skipped.")
else
  system("gpview EvapU.nc@EvapU,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}EvapU.png")
end

if File.exist?("#{$OPT_prefix}Sens.png") then
  puts("MESSAGE: #{$OPT_prefix}Sens.png exists. process skipped.")
else
  system("gpview Sens.nc@Sens,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}Sens.png")
end

if File.exist?("#{$OPT_prefix}SensA.png") then
  puts("MESSAGE: #{$OPT_prefix}SensA.png exists. process skipped.")
else
  system("gpview SensA.nc@SensA,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}SensA.png")
end

if File.exist?("#{$OPT_prefix}OSR.png") then
  puts("MESSAGE: #{$OPT_prefix}OSR.png exists. process skipped.")
else
  system("gpview OSR.nc@OSR,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}OSR.png")
end

if File.exist?("#{$OPT_prefix}OSRA.png") then
  puts("MESSAGE: #{$OPT_prefix}OSRA.png exists. process skipped.")
else
  system("gpview OSRA.nc@OSRA,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}OSRA.png")
end

if File.exist?("#{$OPT_prefix}SSR.png") then
  puts("MESSAGE: #{$OPT_prefix}SSR.png exists. process skipped.")
else
  system("gpview SSR.nc@SSR,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}SSR.png")
end

if File.exist?("#{$OPT_prefix}SSRA.png") then
  puts("MESSAGE: #{$OPT_prefix}SSRA.png exists. process skipped.")
else
  system("gpview SSRA.nc@SSRA,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}SSRA.png")
end

if File.exist?("#{$OPT_prefix}SurfAlbedo.png") then
  puts("MESSAGE: #{$OPT_prefix}SurfAlbedo.png exists. process skipped.")
else
  system("gpview SurfAlbedo.nc@SurfAlbedo,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}SurfAlbedo.png")
end

if File.exist?("#{$OPT_prefix}Ps.png") then
  puts("MESSAGE: #{$OPT_prefix}Ps.png exists. process skipped.")
else
  system("gpview Ps.nc@Ps,time=#{timespan} --mean time --cint=1000 --range=86000:105000 --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}Ps.png")
end

if File.exist?("#{$OPT_prefix}SurfSnow.png") then
  puts("MESSAGE: #{$OPT_prefix}SurfSnow.png exists. process skipped.")
else
  system("gpview SurfSnow.nc@SurfSnow,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}SurfSnow.png")
end

if File.exist?("#{$OPT_prefix}SeaIceConc.png") then
  puts("MESSAGE: #{$OPT_prefix}SeaIceConc.png exists. process skipped.")
else
  system("gpview SeaIceConc.nc@SeaIceConc,time=#{timespan} --mean time --wsn=#{wsn} --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}SeaIceConc.png")
end


# 2 次元データ 水平分布 (noshade)
if File.exist?("#{$OPT_prefix}SurfTemp-noshade.png") then
  puts("MESSAGE: #{$OPT_prefix}SurfTemp-noshade.png exists. process skipped.")
else
  system("gpview SurfTemp.nc@SurfTemp,time=#{timespan} --mean time --noshade --wsn=#{wsn} --cint=5 --range=200:320 --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}SurfTemp-noshade.png")
end

if File.exist?("#{$OPT_prefix}OLRA-noshade.png") then
  puts("MESSAGE: #{$OPT_prefix}OLRA-noshade.png exists. process skipped.")
else
  system("gpview OLRA.nc@OLRA,time=#{timespan} --mean time --wsn=#{wsn} --noannotate --cint=10 --range=100:350 --noshade && #{script_dir}/conv_image.rb #{$OPT_prefix}OLRA-noshade.png")
end

# 温度 水平分布
if File.exist?("#{$OPT_prefix}Temp_sig0.1.png") then
  puts("MESSAGE: #{$OPT_prefix}Temp_sig0.1.png exists. process skipped.")
else
  system("gpview Temp.nc@Temp,sig=0.1,time=#{timespan} --mean time --wsn=#{wsn}  --noannotate --sint=10 --range=140:300 && #{script_dir}/conv_image.rb #{$OPT_prefix}Temp_sig0.1.png")
end

if File.exist?("#{$OPT_prefix}Temp_sig0.077.png") then
  puts("MESSAGE: #{$OPT_prefix}Temp_sig0.077.png exists. process skipped.")
else
  system("gpview Temp.nc@Temp,sig=0.077,time=#{timespan} --mean time --wsn=#{wsn}  --noannotate --sint=10 --range=140:300 && #{script_dir}/conv_image.rb #{$OPT_prefix}Temp_sig0.077.png")
end

# 温度 赤道断面 (itr=2)
if File.exist?("#{$OPT_prefix}Temp_lat0_itr2.png") then
  puts("MESSAGE: #{$OPT_prefix}Temp_lat0_itr2.png exists. process skipped.")
else
  system("gpview Temp.nc@Temp,lat=0,time=#{timespan} --mean time --wsn=#{wsn} --itr=2 --noannotate --sint=10 --range=140:300 && #{script_dir}/conv_image.rb  #{$OPT_prefix}Temp_lat0_itr2.png")
end

# 温度 赤道断面
if File.exist?("#{$OPT_prefix}Temp_lat0_itr1.png") then
  puts("MESSAGE: #{$OPT_prefix}Temp_lat0_itr1.png exists. process skipped.")
else
  system("gpview Temp.nc@Temp,lat=0,time=#{timespan} --mean time --wsn=#{wsn} --itr=1 --noannotate --sint=10 --range=140:300 && #{script_dir}/conv_image.rb #{$OPT_prefix}Temp_lat0_itr1.png")
end

# 東西風 赤道断面
if File.exist?("#{$OPT_prefix}U_lat0_itr1.png") then
  puts("MESSAGE: #{$OPT_prefix}U_lat0_itr1.png exists. process skipped.")
else
  system("gpview U.nc@U,lat=0,time=#{timespan} --mean time --wsn=#{wsn} --itr=1 --noannotate --cint=15 --range=-70:110 && #{script_dir}/conv_image.rb #{$OPT_prefix}U_lat0_itr1.png")
end

# 東西風 水平分布(sigma=0.077)
if File.exist?("#{$OPT_prefix}U_sig0.077.png") then
  puts("MESSAGE: #{$OPT_prefix}U_sig0.077.png exists. process skipped.")
else
  system("gpview U.nc@U,sig=0.077,time=#{timespan} --mean time --wsn=#{wsn}  --noannotate --cint=20 --range=-70:150 && #{script_dir}/conv_image.rb #{$OPT_prefix}U_sig0.077.png")
end


# 南北風 (水平分布)
if File.exist?("#{$OPT_prefix}V_sig0.1.png") then
  puts("MESSAGE: #{$OPT_prefix}V_sig0.1.png exists. process skipped.")
else
  system("gpview V.nc@V,sig=0.1,time=#{timespan} --mean time --wsn=#{wsn}  --noannotate --sint=10 --range=-50:50 && #{script_dir}/conv_image.rb #{$OPT_prefix}V_sig0.1.png")
end

if File.exist?("#{$OPT_prefix}V_sig0.077.png") then
  puts("MESSAGE: #{$OPT_prefix}V_sig0.077.png exists. process skipped.")
else
  system("gpview V.nc@V,sig=0.077,time=#{timespan} --mean time --wsn=#{wsn}  --noannotate --sint=10 --range=-50:50 && #{script_dir}/conv_image.rb #{$OPT_prefix}V_sig0.077.png")
end

# 鉛直風 水平分布
if File.exist?("#{$OPT_prefix}SigDot_sig0.1.png") then
  puts("MESSAGE: #{$OPT_prefix}SigDot_sig0.1.png exists. process skipped.")
else
  system("gpview SigDot.nc@SigDot,sigm=0.1,time=#{timespan} --mean time --wsn=#{wsn}  --noannotate --range=-2e-6:2e-6 --cint=1e-7 --clrmap 14 && #{script_dir}/conv_image.rb #{$OPT_prefix}SigDot_sig0.1.png")
end

if File.exist?("#{$OPT_prefix}SigDot_sig0.077.png") then
  puts("MESSAGE: #{$OPT_prefix}SigDot_sig0.077.png exists. process skipped.")
else
  system("gpview SigDot.nc@SigDot,sigm=0.077,time=#{timespan} --mean time --wsn=#{wsn}  --noannotate --range=-2e-6:2e-6 --cint=1e-7 --clrmap 14 && #{script_dir}/conv_image.rb #{$OPT_prefix}SigDot_sig0.077.png")
end

if File.exist?("#{$OPT_prefix}SigDot_sig0.5.png") then
  puts("MESSAGE: #{$OPT_prefix}SigDot_sig0.5.png exists. process skipped.")
else
  system("gpview SigDot.nc@SigDot,sigm=0.5,time=#{timespan} --mean time --wsn=#{wsn}  --noannotate --range=-2e-6:2e-6 --cint=1e-7 --clrmap 14 && #{script_dir}/conv_image.rb #{$OPT_prefix}SigDot_sig0.5.png")
end


# 比湿 水平分布
if File.exist?("#{$OPT_prefix}QVap_sig0.1.png") then
  puts("MESSAGE: #{$OPT_prefix}QVap_sig0.1.png exists. process skipped.")
else
  system("gpview QVap.nc@QVap,sig=0.1,time=#{timespan} --mean time --wsn=#{wsn}  --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}QVap_sig0.1.png")
end

if File.exist?("#{$OPT_prefix}QVap_sig0.077.png") then
  puts("MESSAGE: #{$OPT_prefix}QVap_sig0.077.png exists. process skipped.")
else
  system("gpview QVap.nc@QVap,sig=0.077,time=#{timespan} --mean time --wsn=#{wsn}  --noannotate && #{script_dir}/conv_image.rb #{$OPT_prefix}QVap_sig0.077.png")
end


# 角運動量
if File.exist?('AngMom.nc') then
  puts("MESSAGE: AngMom.nc exists. process skipped.")
else
  system("#{script_dir}/make_AngMom.rb") unless File.exist?('AngMom.nc')
end

if File.exist?("#{$OPT_prefix}AngularMomentum.png") then
  puts("MESSAGE: #{$OPT_prefix}AngularMomentum.png exists. process skipped.")
else
  system("gpview AngMom.nc@AngMom,time=#{timespan} --range 1e7:4e9 --cint 2e8 --mean lon,time --wsn #{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}AngularMomentum.png")
end

# 温位
if File.exist?("PotTemp.nc") then
  puts("MESSAGE: PotTemp.nc exists. process skipped.")
else
  system("#{script_dir}/make_PotTemp.rb --range_time #{timespan}") unless File.exist?('PotTemp.nc')
end

if File.exist?("#{$OPT_prefix}PotTemp.png") then
  puts("MESSAGE: #{$OPT_prefix}PotTemp.png exists. process skipped.")
else
#  system("#{script_dir}/potential-temperature.rb --range_time #{timespan} --range_val 200:800 --cint 40.0 --wsn #{wsn} && dclpsrot dcl.ps > #{$OPT_prefix}PotTemp.ps && convert #{$OPT_prefix}PotTemp.ps #{$OPT_prefix}PotTemp.png")
#  system("#{script_dir}/potential-temperature.rb --range_time 995:1095 --range_val 200:800 --cint 40.0 --wsn #{wsn} && dclpsrot dcl.ps > #{$OPT_prefix}PotTemp.ps && convert #{$OPT_prefix}PotTemp.ps #{$OPT_prefix}PotTemp.png")
  system("gpview  PotTemp.nc@theta,time=#{timespan} --range 200:800 --cint 40.0 --wsn #{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}PotTemp.png")
end


# 赤道断面
if File.exist?("#{$OPT_prefix}QVap_lat0_itr1.png") then
  puts("MESSAGE: #{$OPT_prefix}QVap_lat0_itr1.png exists. process skipped.")
else
  system("gpview QVap.nc@QVap,lat=0,time=#{timespan} --mean time --wsn=#{wsn} --itr=1 --noannotate --cint=1e-3 --range=1e-19:1e-2 && #{script_dir}/conv_image.rb #{$OPT_prefix}QVap_lat0_itr1.png")
end

if File.exist?("#{$OPT_prefix}QVap_lat0_itr1_Ecolor.png") then
  puts("MESSAGE: #{$OPT_prefix}QVap_lat0_itr1_Ecolor.png exists. process skipped.")
else
  system("gpview QVap.nc@QVap,lat=0,time=#{timespan} --mean time --wsn=#{wsn} --itr=1 --noannotate --levels 999,1e-4,0.002,0.004,0.006,0.008,0.01,0.012,0.014,0.016,0.018,0.02,999 --pattern 99999,10999,20999,32999,45999,50999,55999,60999,70999,80999,88999,95999  && #{script_dir}/conv_image.rb #{$OPT_prefix}QVap_lat0_itr1_Ecolor.png")
end

# (u,v)
if File.exist?($OPT_prefix + 'UV-eddy_sig0.2.png') then
  puts("MESSAGE: #{$OPT_prefix}UV-eddy_sig0.2.png exists. process skipped.")
else
  system("#{script_dir}/wind-vector_geopot.rb --time_start #{time_start} --time_end #{time_end} --wsn #{wsn} --sigma 0.2 --eddy && #{script_dir}/conv_image.rb #{$OPT_prefix}UV-eddy_sig0.2.png") 
end

if File.exist?($OPT_prefix + 'UV_sig0.2.png') then
  puts("MESSAGE: #{$OPT_prefix}UV_sig0.2.png exists. process skipped.")
else
  system("#{script_dir}/wind-vector_geopot.rb --time_start #{time_start} --time_end #{time_end} --xintv 8 --yintv 5 --wsn #{wsn} --sigma 0.2 && #{script_dir}/conv_image.rb #{$OPT_prefix}UV_sig0.2.png") 
end

if File.exist?($OPT_prefix + 'UV-eddy_sig0.1.png') then
  puts("MESSAGE: #{$OPT_prefix}UV-eddy_sig0.1.png exists. process skipped.")
else
  system("#{script_dir}/wind-vector_geopot.rb --time_start #{time_start} --time_end #{time_end} --wsn #{wsn} --sigma 0.2 --eddy && #{script_dir}/conv_image.rb #{$OPT_prefix}UV-eddy_sig0.1.png") 
end

if File.exist?($OPT_prefix + 'UV_sig0.1.png') then
  puts("MESSAGE: #{$OPT_prefix}UV_sig0.1.png exists. process skipped.")
else
  system("#{script_dir}/wind-vector_geopot.rb --time_start #{time_start} --time_end #{time_end} --xintv 8 --yintv 5 --wsn #{wsn} --sigma 0.2 && #{script_dir}/conv_image.rb #{$OPT_prefix}UV_sig0.1.png") 
end

# 水平速度場
# system("#{script_dir}/fig_olr-uv.rb --xfact1 0.001 --yfact1 0.001 --uxunit 1 --uyunit 1 --loncnt 0 --wsn 2 && dclpsrot dcl.ps > #{$OPT_prefix}OLR-UV.ps && convert #{$OPT_prefix}OLR-UV.ps #{$OPT_prefix}OLR-UV_from0.png")


# 熱フラックス (経度分布)
if File.exist?("#{$OPT_prefix}fluxesA_latmean.png") then
  puts("MESSAGE: #{$OPT_prefix}fluxesA_latmean.png exists. process skipped.")
else
  system("#{script_dir}/fig_heatfluxA-lon-dependence.rb \
    --time_start=#{time_start} --time_end=#{time_end} \
    --range=0:400 --lat=mean --wsn=#{wsn} \
    && #{script_dir}/conv_image.rb #{$OPT_prefix}fluxesA_latmean.png")
end

if File.exist?("#{$OPT_prefix}fluxes_lat0.png") then
  puts("MESSAGE: #{$OPT_prefix}fluxes_lat0.png exists. process skipped.")
else
  system("#{script_dir}/fig_heatfluxA-lon-dependence.rb --time_start=#{time_start} --time_end=#{time_end} --range=0:400 --lat=0 --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}fluxesA_lat0.png")
end

if File.exist?("#{$OPT_prefix}fluxes_latmean.png") then
  puts("MESSAGE: #{$OPT_prefix}fluxes_latmean.png exists. process skipped.")
else
  system("#{script_dir}/fig_heatflux-lon-dependence.rb --time_start=#{time_start} --time_end=#{time_end} --range=0:400 --lat=mean --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}fluxes_latmean.png")
end

if File.exist?("#{$OPT_prefix}fluxes_lat0.png") then
  puts("MESSAGE: #{$OPT_prefix}fluxes_lat0.png exists. process skipped.")
else
  system("#{script_dir}/fig_heatflux-lon-dependence.rb --time_start=#{time_start} --time_end=#{time_end} --range=0:400 --lat=0 --wsn=#{wsn} && #{script_dir}/conv_image.rb #{$OPT_prefix}fluxes_lat0.png")
end

