#!/usr/bin/ruby $: << File::dirname(__FILE__) require 'plot_log_longitudinal.rb' if $0 == __FILE__ then class SI_in_FormatData LABELS = FlightLogReader::FLIGHT_LOG_LABELS def initialize(file, options = {}) @data = FlightLogReader::read(file, 1) if range = options[:time_range] then time_index = LABELS.index(:Time) @data.reject!{|item| !range.include?(item[time_index])} end @data= @data.transpose end def get(target) if i = LABELS.index(target) then return @data[i] end return nil end end class ObsFormatData LABELS = [ :Time, # GPS時刻(秒) :TAS, :SideSlip, :Roll, :Yaw, :RollRate, :YawRate, :RollAccel, :YawAccel, :AccY, # 加速度(m/s^2) y軸(右) ] def initialize(file, options = {}) @data = [] line_no = 0 denom = options[:denom] || 1 range = options[:time_range] time_index = LABELS.index(:Time) open(file).each{|line| temp = line.chop.split(/,/) if temp.size >= LABELS::size then temp = temp[0...LABELS::size].collect{|item| item.to_f} if range then next unless range.include?(temp[time_index]) end line_no += 1 next if line_no % denom != 0 # データを間引く @data << temp end } @data = @data.transpose end def get(target) if i = LABELS::index(target) then return @data[i] end return [] end end $options.merge!({ :da => 2, :dr => 3, :dasf => 1, :drsf => 1, :datrim => 0, :drtrim => 0}) prologue log_file = ARGV.shift $options[:fname_base] = File::basename(log_file, ".*") if log_file == '-' then log_file = $stdin end additional_log_files = [] opt_check(ARGV).each{|item| case item when /^--(d[ar])=(\d+)/ then $options[$1.to_sym] = $2.to_i when /^--(d[ar](?:sf|trim))=([+-.\d]+)/ then # 舵面SFの単位[deg] $options[$1.to_sym] = $2.to_f when /^--add=/ then # 追加プロットファイル(ファイル名,suffix[,ファイル形式、デフォルトは観測量形式]) f, suffix, format = $'.split(',') format ||= 'obs' case format when 'si_in' # システム同定入力ファイル $options[:additional_logs] << [SI_in_FormatData::new(f, $options), suffix] else # 'obs'形式 $options[:additional_logs] << [ObsFormatData::new(f, $options), suffix] end else raise "Unknown option #{item}" end } log = SI_in_FormatData::new(log_file, $options) [ # [name, y_label, title, sf] [:TAS, 'V_{wind} [m/s]', 'True Airspeed', 1.0], [:Pitch, '{/Symbol q} [deg]', 'Pitch', 180.0 / Math::PI], [:SideSlip, '{/Symbol b} [deg]', 'Sideslip Angle', 180.0 / Math::PI], [:RollRate, 'p [deg/s]', 'Roll Rate', 180.0 / Math::PI], [:YawRate, 'r [deg/s]', 'Yaw Rate', 180.0 / Math::PI], [:Roll, '{/Symbol f} [deg]', 'Roll', 180.0 / Math::PI], [:Yaw, '{/Symbol y} [deg]', 'Yaw', 180.0 / Math::PI], [:AccY, 'a_{y} [m/s^{2}]', 'Acceleration Y', 1], ].each{|item| plot1(log, item, $options)} [[:a, 'Aileron'], [:r, 'Rudder']].each{|item| plot2(log, item, $options)} end