#!/usr/bin/ruby $: << '~/src/eclipse/autopilot/common/ruby' require 'allan' TARGET_DIR = './CVS_IGNORE' target_file_list = [] Dir::open(TARGET_DIR){|dir| dir.each{|file| # 誤差モデルを入れた結果だけ取ってくる(入っていない_trueは除く) target_file_list << file if file =~ /^FEM_out[_\d]+\.csv/ } } #p target_file_list values = [] target_file_list.each_with_index{|file, index| v = [] open("#{TARGET_DIR}/#{file}").each{|line| v << line.chop!.split(/,/).collect!{|item| item.to_f} } #p v if values.empty? then values = v.clone values.collect!{|item| a = [] item.size.times{|i| a << []} a } end v.each_with_index{|v1, i| v1.each_with_index{|v2, j| #p v2 values[i][j] << v2 } } #p values #if index == 2 then break end } #p values values.each{|v1| #p v1 #v1 = [[推定値],[誤差分散の推定値]] mean, std = v1.first.mean_std rel_std = std / mean puts "#{mean}, #{std}, #{rel_std}" } # 固有モードプロットを行う # シンボルごとの推定値 ests_per_sym = values.collect{|v1| v1.first} # 推定していた係数 EST_SYMBOLS = [:Xu, :Xa, :Zu, :Za, :Zq, :Zde, :Mu, :Ma, :Mq, :Mde] # paddingして標準の推定ログ形式ででてくる値 STANDARD_SYMBOLS = [ :t, :u, :a, :theta, :q, :Xu, :Xa, :Xdt, :Zu, :Za, :Zq, :Zde, :Zdt, :Mu, :Maa, :Ma, :Mq, :Mde, :Mdt] # 両者を比較して足りない部分はpaddingする ests_per_sym = STANDARD_SYMBOLS.collect{|sym| i = EST_SYMBOLS.index(sym) i ? ests_per_sym[i] : ([0] * ests_per_sym.first.size) } PLOTTER = File::join(File::dirname(__FILE__), "plot_est.rb") SIMULATOR_SRC = File::join(File::dirname(__FILE__), "sim", "longitudinal.cpp") # 推定値のみの集合 ests_per_file = ests_per_sym.transpose #p ests_per_file plot_options = [ [:prefix, 'MC_sim']] # 定常値および参照値をファイルから拾ってくる open(SIMULATOR_SRC){|io| io.each{|line| if line =~ /set_sta\( *([^,]+), *([+\-\d\.]+)\);/ plot_options << [:sta, "#{$1},#{$2}"] elsif line =~ /set_coef\( *([^,]+), *([+\-\d\.]+)\);/ plot_options << [:ref, "#{$1},#{$2}"] end } } plot_cmd = "#{PLOTTER} -,nobeginend " plot_cmd += plot_options.collect{|k, v| "--#{k}=#{v}"}.join(' ') $stderr.puts plot_cmd # パイプで流し込む IO::popen(plot_cmd, 'w'){|io| ests_per_file.each{|est| io.puts est.join(',') } io.puts 'e' }