Created
May 8, 2014 02:01
-
-
Save josnidhin/3aba5faedfd0a2574a22 to your computer and use it in GitHub Desktop.
A script to parse polhemus liberty motion data output. The script separates a single file containing data from 2 stations into separate files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 20.465 -16.439 -4.668 65.601 -6.760 -144.382 1853586 0x75d90b 0 | |
2 21.251 -26.413 -5.341 172.982 25.081 -151.184 1853586 0x75d90b 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
class String | |
def convert_base(from, to) | |
self.to_i(from).to_s(to) | |
end | |
end | |
orig = ARGV[0] | |
# station 1 Left | |
file_left = File.new("#{orig}_left", 'w+') | |
# station 2 Right | |
file_right = File.new("#{orig}_right", 'w+') | |
if orig.nil? | |
exit | |
end | |
File.open(orig).each do |line| | |
items = line.split(' ') | |
if items.length > 1 | |
items[-2] = items[-2].convert_base(16,10) | |
if items[0].to_i == 1 | |
items[0] = "0#{items[0]}" | |
file_left.write(items.join(' ')) | |
file_left.write("\n") | |
elsif items[0].to_i == 2 | |
items[0] = "01" | |
file_right.write(items.join(' ')) | |
file_right.write("\n") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment