Commit 59ea83af authored by enfo's avatar enfo

Automatic detection of field names

parent f53f638b
......@@ -11,14 +11,22 @@ def print_usage():
print(' python rtklib2matlab.py [rover.pos]')
sys.exit(1)
def parseline(line):
names = ['week', 'tow', 'ecef_x', 'ecef_y', 'ecef_z', 'Q', 'ns', 'sdx', 'sdy',
'sdz', 'sdxy', 'sdyz', 'sdzx', 'age', 'ratio']
values = line.split()
def parseline(line, names):
values = line.split('|')
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))
def handle_name(name):
name = name.strip().lower()
if '(' in name:
name = name[:name.index('(')]
name = name.replace('-', '_')
return name
if __name__ == '__main__':
import sys
......@@ -32,6 +40,9 @@ if __name__ == '__main__':
outfile = os.path.splitext(infile)[0] + '.mat'
print('Converting %s to to %s' % (infile, outfile))
names = ['week', 'tow', 'ecef_x', 'ecef_y', 'ecef_z', 'Q', 'ns', 'sdx', 'sdy',
'sdz', 'sdxy', 'sdyz', 'sdzx', 'age', 'ratio']
n_lines = 0
with open(infile, 'rU') as f:
for line in f:
......@@ -46,8 +57,12 @@ if __name__ == '__main__':
c_line = 0
for line in f:
if line.startswith('%'):
if 'age' in line:
names = [handle_name(name) for name in line.strip('% ').split('|')]
if names[0] == 'gpst':
names.insert(0, 'week')
continue
data_line = parseline(line)
data_line = parseline(line, names)
for key, val in data_line.items():
try:
data[key][c_line] = val
......
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