#!/usr/bin/ruby =begin 規則に従って書かれたCSVをgnuplotでeps化するためのスクリプト 1行目 A列 X軸名 B列 Y軸名 2行目以降 A列 プロパティ key B列 プロパティ value それ以降1行目 A列 空白 B,...列 凡例(なしの場合はnotitle) [それ以降2行目(あってもなくてもよい)] A列 空白 B,...列 凡例(なしの場合はnotitle) さらに A列 X軸データ B,...列 Y軸データ =end $: << '~/src/eclipse/autopilot/common/ruby/' require 'gnuplot_support' if ARGV.size < 1 then puts "Usage: #{__FILE__} input.csv" exit end labels = [] titles = [] ds_with = [] properties = {} x = [] y_s = [] line_no = 0 open(ARGV.shift).each{|line| item = line.chop!.split(/,/) case line_no when 0 labels = item else p item if titles.empty? and item[0] != '' then properties[item[0]] = item[1..-1].join(',') if properties[item[0]] =~ /^"([^"]*)"/ then properties[item[0]] = $1 end elsif x.empty? and item[0] == '' then if titles.empty? then titles = item[1..-1] titles.size.times{|i| y_s << []} else ds_with = item[1..-1] end else item.collect!{|v| v.to_f} x << item.shift item.each_with_index{|v, i| y_s[i] << v } end end line_no += 1 } Plotter::plot_basic('out.eps'){|plot| plot.xlabel "'#{labels[0]}'" plot.ylabel "'#{labels[1]}'" properties.each{|key, value| if value then plot.set(key, value) else plot.set(key) end } items = [] y_s.each_with_index{|y, i| items << Gnuplot::DataSet::new([x, y]){|ds| if titles[i] == 'notitle' then ds.notitle else ds.title = titles[i] end if ds_with[i] and ds_with[i] != '' then ds.with = ds_with[i] else ds.with = "lines lw 2" end } } plot.data = items }