#!/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]
                   )
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
spc     = $OPT_spc.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)

  file = [ 
    info+"_VPotTemp_t"+time.to_s+".png",
    info+"_StrmFunc_t"+time.to_s+".png",
    info+"_VelX_t"+time.to_s+".png",
    info+"_VelZ_t"+time.to_s+".png",
    info+"_NH3-g_lin_t"+time.to_s+".png",
    info+"_H2S-g_lin_t"+time.to_s+".png",
    info+"_H2O-g_lin_t"+time.to_s+".png",
    "spacer_854x519.png",
    info+"_NH3-s_t"+time.to_s+".png",
    info+"_NH4SH-s_t"+time.to_s+".png",
    info+"_H2O-s_t"+time.to_s+".png",
    info+"_Cloud-Rain_t"+time.to_s+".png"
  ]

  for j in 0..5
    l = 2 * j
    m = 2 * j + 1
    k = sprintf("%02d", j+1)
    output   = info+"_Dron_t"+time.to_i.to_s+"_"+k.to_s+".eps"
    convert = "convert +append "+file[l]+" "+file[m]+" "+output
    
    system( convert )
    p convert
  end
end

