#!/usr/bin/env ruby

require "getoptlong"

###
###$B0z?t=hM}(B
###
parser = GetoptLong.new
parser.set_options(
                   ###    global option   ###
                   ['--delt',         GetoptLong::REQUIRED_ARGUMENT],
                   ['--time',         GetoptLong::REQUIRED_ARGUMENT],
                   ['--num',          GetoptLong::REQUIRED_ARGUMENT],
                   ['--dump',         GetoptLong::NO_ARGUMENT],
                   ['--strm',         GetoptLong::NO_ARGUMENT],
                   ['--wind',         GetoptLong::NO_ARGUMENT]
                   )
begin
  parser.each_option do |name, arg|
    eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_')} = '#{arg}'"
  end
rescue
  exit(1)
end


###
### $B=i4|2=(B
###

deltime = $OPT_delt.to_f
time0   = $OPT_time.to_f
num     = $OPT_num.to_i

info = ARGV[0]
order = Math::log10(time0+deltime*num).to_i + 1
fmt = "%0"+(order.to_i).to_s+"d"

for i in 0..num
  time = sprintf(fmt, time0 + i * deltime)
  p time

  file1 = info+"-node0_PotTemp_t"+time.to_s+".png"
  file2 = info+"-node1_PotTemp_t"+time.to_s+".png"

  output1   = info+"_t"+time.to_s+".png"

  convert1 = "convert +append "+file1+" "+file2+" "+output1

  system( convert1 )
  p convert1

end

#convert4 = "convert -delay 50 "+out+"_t*png "+out+".gif"
#system( convert4 )
#p convert4
