-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenTbl.py
More file actions
126 lines (123 loc) · 3.39 KB
/
openTbl.py
File metadata and controls
126 lines (123 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from struct import unpack,unpack_from
import sys
def readLabVoltTBL(fileName):
fid = open(fileName,'rb')
ind = 128
fid.seek(ind)
a = unpack('c',fid.read(1))[0]
while a>chr(12):
ind += 1
a = unpack('c',fid.read(1))[0]
ind += 1
a = unpack('c',fid.read(1))[0]
while a>chr(12):
ind += 1
a = unpack('c',fid.read(1))[0]
d_count = 1
fcon =1
ind += 36
while fcon == 1:
fid.seek(ind)
marker1 = unpack('B',fid.read(1))[0]
marker2 = unpack('B',fid.read(1))[0]
if marker1 == 0 and marker2 == 75:
fcon = 0
else:
d_count += 1
ind += 12
ind = 122
data = []
labels = []
fcon = 1;
output = []
while fcon == 1:
fid.seek(ind)
marker1 = unpack('B',fid.read(1))[0]
marker2 = unpack('B',fid.read(1))[0]
if marker1 == 0 and marker2 == 75:
out = []
ind = ind + 6
fid.seek(ind)
units = ''
a = unpack('c',fid.read(1))[0]
while a > chr(12):
units += a
ind += 1
a = unpack('c',fid.read(1))[0]
ind += 1
chann = '';
a = unpack('c',fid.read(1))[0]
while a > chr(12):
chann += a
ind += 1
a = unpack('c',fid.read(1))[0]
labels.append((chann + ',' + units))
ind += 17
#start aquiring data entries
for x in range(0,d_count):
fid.seek(ind)
aux = unpack('d',fid.read(8))[0]
if abs(aux) < 10**-150:
aux=0
out.append(aux)
ind += 12
out.reverse()
output.append(out)
ind +=7
else:
fcon = 0
out= map(lambda *row: list(row), *output )
return labels, out
def usage():
print 'usage: '+sys.argv[0] + ' [option] ... -i inputFile ...'
print 'Options and arguments (and corresponding environment variables):'
print '-h\t: Help'
print '-i file\t: Input File'
print '-t\t: Display Titles'
if __name__ == '__main__':
import getopt
input_file = ''
titles_on = False
CSV = False
try: opts, args = getopt.getopt(sys.argv[1:], "htci:",
['help','csv','input=', 'titles'])
except getopt.GetoptError, err:
print str(err)
usage()
sys.exit(2)
for o,a in opts:
if o in ('-h','--help'):
usage()
sys.exit()
elif o in ('-c','--csv'):
CSV = False
print 'not printing csv, broken'
elif o in ('-i','--input'):
input_file = a
elif o in ('-t','--titles'):
titles_on = True
else:
assert False, "unhanded option"
if not input_file:
print 'need input file'
usage()
sys.exit(3)
labels, out = readLabVoltTBL(input_file)
if not CSV:
if titles_on:
for label in labels:
print label,'\t',
print ''
for x in out:
for y in x:
print y,'\t',
print '\n',
else:
if titles_on:
for label in labels:
print label,',',
print ''
for x in out:
for y in x:
print y,',',
print '\n',