#!/usr/bin/env ruby
# ----------------------------------------------
# local load path

 $local_path = '/work11/ape/yukiko/lib'
# $local_path = '/home/yukiko/tmp/ape-data/lib'
$: << $local_path

# ----------------------------------------------
# 必要なライブラリ, モジュールの読み込み

load "#{$local_path}/ape-view.rb"


# gif, netcdf の格納場所
$fig_path = "/work11/yukiko/wavecisk/figs/tmp/"
$ncfile_path = "/work11/yukiko/spmodel-yukiko/data/"


#----------------------------------------------
# ユーザ設定

# 鉛直層 
$layer = 4

# 加熱型 0:linear, 1:positive, 2: noheat
$heat = 0

# 加熱幅 0: control, 1: 4times X half-width
$width = 0

# 加熱モード 0: eta1=1.5,eta2=-1.5, 1: eta1=1.5, eta2=0
$eta = 0

# β項 0: beta=0, 1:beta=1
$beta = 1

# 加熱源の中心位置 0: y=0, 1 y=1
$y1shift = "0"

# 次元 0: 2dim, 1: 1dim(初期値1次元問題)
$dim = 1

# 変数 height, u, v
$variable = "wvel"



# ----------------------------------------------

END{

  # -- 
  $beta = 1; $heat = 0; $width = 0; $variable = "wvel"
  set_filename
  t = ape_new($filename)
  g = t.go($variable)
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  File.rename("#{$fig_path}_#{g.name}.ps", "#{$fig_path}#{$gifname}")  

  # --
  $beta = 1; $heat = 1; $width = 0; $variable = "wvel"
  set_filename
  t = ape_new($filename)
  g = t.go($variable)
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  File.rename("#{$fig_path}_#{g.name}.ps", "#{$fig_path}#{$gifname}")
  
  # --
#  $beta = 1; $heat = 0; $width = 1; $variable = "wvel"
#  set_filename
  t = ape_new($filename)
  g = t.go($variable)
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  File.rename("#{$fig_path}_#{g.name}.ps", "#{$fig_path}#{$gifname}")

  # --
#  $beta = 1; $heat = 1; $width = 1; $variable = "wvel"
#  set_filename
  t = ape_new($filename)
  g = t.go($variable)
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  File.rename("#{$fig_path}_#{g.name}.ps", "#{$fig_path}#{$gifname}")

  # --
  $beta = 0; $heat = 0; $width = 0; $variable = "wvel"
  set_filename
  t = ape_new($filename)
  g = t.go($variable)
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  File.rename("#{$fig_path}_#{g.name}.ps", "#{$fig_path}#{$gifname}")

  # --
  $beta = 0; $heat = 1; $width = 0; $variable = "wvel"
  set_filename
  t = ape_new($filename)
  g = t.go($variable)
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  File.rename("#{$fig_path}_#{g.name}.ps", "#{$fig_path}#{$gifname}")


  # --
  $beta = 1; $heat = 2; $width = 0; $variable = "wvel"
  set_filename
  t = ape_new($filename)
  g = t.go($variable)
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  File.rename("#{$fig_path}_#{g.name}.ps", "#{$fig_path}#{$gifname}")

  # --
  $beta = 0; $heat = 2; $width = 0; $variable = "wvel"
  set_filename
  t = ape_new($filename)
  g = t.go($variable)
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  File.rename("#{$fig_path}_#{g.name}.ps", "#{$fig_path}#{$gifname}")

  # --
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  t.mkps(g.cut(true,0,true)[true,true].set_att("ape_name","wvel").
	   set_lost_axes($lost_axis))
  File.rename("#{$fig_path}_#{g.name}.ps", "#{$fig_path}#{$gifname}")

  t.grcls




}

#----------------------------------------------
# 設定

def set_filename

  heat_ary = ["linear","positive","noheat"]
  width_ary = ["","-4width"]
  eta_ary = ["","-eta1"]
  beta_ary = ["-beta0",""]
  dim_ary = ["","-1dim"]
  y1shift_ary  = ["","-y1shift"]


  $filename = 
    "wavecisk-#{heat_ary[$heat]}#{eta_ary[$eta]}#{beta_ary[$beta]}#{width_ary[$width]}#{y1shift_ary[$y1shift]}#{dim_ary[$dim]}.nc"

  print "#{$filename}@#{$variable}\n"


  $gifname =
    "wavecisk-#{heat_ary[$heat]}#{eta_ary[$eta]}#{beta_ary[$beta]}#{width_ary[$width]}#{y1shift_ary[$y1shift]}#{dim_ary[$dim]}-xteq-#{$variable}.ps" 
#    "wavecisk-#{$layer}layer-#{heat_ary[$heat]}#{width_ary[$width]}-xteq-#{$variable}.ps"

  $file_label = ""
  
  heat_ary = ["linear","positive_only","no"]
  eta_ary = [
    "eta1 = 1.5, eta2 = -1.5",
    "eta1 = 1.5, eta2 = 0.0"
  ]
  beta_ary = ["beta=0","beta=1"]
  
  sign = "YU.YAMADA #{Time.now.strftime("%Y/%m/%d %H:%M:%S JST")}"
  
  $lost_axis = [
    sign,
    "y=0, z=3/2", 
    "rezol: k=l=64, z=#{$layer}", 
    "#{heat_ary[$heat]}_heat, linear_equation", 
    "#{beta_ary[$beta]}, #{eta_ary[$eta]}"
  ]

  $lost_axis.push("init-heat: 4 times X-width") if $width == 1
  $lost_axis.push("init-heat: uniform along the Y-axis") if $dim == 1
  $lost_axis.push("init-heat: shift center position to y0=1") if $y1shift == 1

end




