#!/usr/bin/ruby # coding: cp932 =begin ヘディングの不連続をなくす =end if RUBY_VERSION >= "1.9.0" then STDIN.set_encoding('cp932', Encoding.default_internal) STDOUT.set_encoding('cp932', Encoding.default_internal) end $options = { :mode => :sylphide_N, } ARGV.reject!{|arg| if arg =~ /--([^=]+)=?/ then $options[$1.to_sym] = $' true else false end } target_index = Integer($options[:index]) rescue { :sylphide_N => 7, # Sylphide Nページはindex(7)に真方位 :GAIA => 9, # GAIAはindex(9)に真方位 }[$options[:mode].to_sym] rotate_count = 0 values = $stdin.readline.chomp.split(/,/) heading_previous = values[target_index].to_f $stdout.puts values.join(',') $stdin.each{|line| values = line.chomp.split(/,/) heading_new = values[target_index].to_f + (rotate_count * 360) if heading_new - heading_previous < -180 then # 179 => -179(181) rotate_count += 1 heading_new += 360 elsif heading_new - heading_previous > 180 then # -179 => 179(-181) rotate_count -= 1 heading_new -= 360 end values[target_index] = sprintf('%.2f', heading_new) $stdout.puts values.join(',') heading_previous = heading_new }