Commit d92080e7 authored by Sigurd M. Albrektsen's avatar Sigurd M. Albrektsen

Support for different separators

parent 46da1829
Pipeline #124 passed with stages
in 1 minute and 3 seconds
......@@ -2,6 +2,7 @@
import sys
import os
import re
import numpy as np
dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(dir_path, '..'))
......@@ -11,8 +12,15 @@ def print_usage():
print(' python rtklib2matlab.py [rover.pos]')
sys.exit(1)
def split_line(line):
if '|' in line:
return line.split('|')
if '\t' in line:
return line.split('\t')
return re.sub(' +', ' ', line).split(' ')
def parseline(line, names):
values = line.split()
values = split_line(line)
converters = [int] + [float]*4 + [int]*2 + [float]*8
conv_vals = [c(v) for c, v in zip(converters, values) ]
return dict(zip(names, conv_vals))
......@@ -48,7 +56,7 @@ if __name__ == '__main__':
for line in f:
if line.startswith('%'):
if 'ratio' in line:
names = [fix_name(name) for name in line[1:].split()]
names = [fix_name(name) for name in split_line(line.strip('% '))]
if 'gpst' in names:
names.insert(0, 'week')
continue
......@@ -82,3 +90,4 @@ if __name__ == '__main__':
print('')
print('Mean: %s' % np.mean(valid_arr, axis=1)[:3])
print('Std : %s' % np.std(valid_arr, axis=1)[:3])
......@@ -2,18 +2,26 @@
import sys
import os
import re
from scipy.io import savemat
dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(dir_path, '..'))
def print_usage():
print('Usage:')
print(' python rtklib2matlab.py [rover.pos]')
sys.exit(1)
def parseline(line, names):
def split_line(line):
if '|' in line:
return line.split('|')
if '\t' in line:
return line.split('\t')
return re.sub(' +', ' ', line).split(' ')
values = line.split('|')
def parseline(line, names):
values = split_line(line)
converters = [int] + [float]*4 + [int]*2 + [float]*8
conv_vals = [c(v) for c, v in zip(converters, values) ]
return dict(zip(names, conv_vals))
......@@ -38,7 +46,7 @@ if __name__ == '__main__':
infile = sys.argv[1]
outfile = os.path.splitext(infile)[0] + '.mat'
print('Converting %s to to %s' % (infile, outfile))
print('Converting %s to %s' % (infile, outfile))
names = ['week', 'tow', 'ecef_x', 'ecef_y', 'ecef_z', 'Q', 'ns', 'sdx', 'sdy',
'sdz', 'sdxy', 'sdyz', 'sdzx', 'age', 'ratio']
......@@ -58,7 +66,7 @@ if __name__ == '__main__':
for line in f:
if line.startswith('%'):
if 'age' in line:
names = [handle_name(name) for name in line.strip('% ').split('|')]
names = [handle_name(name) for name in split_line(line.strip('% '))]
if names[0] == 'gpst':
names.insert(0, 'week')
continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment