read_trace.py

Mon, 10 Dec 2007 21:22:33 +0100

author
David Douard <david.douard@logilab.fr>
date
Mon, 10 Dec 2007 21:22:33 +0100
changeset 4
269aacbb2bf2
parent 0
9af1509775b6
child 6
6b6dc68588b2
permissions
-rw-r--r--

small cleanup

0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 import struct
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6 def decode_float(s):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 assert len(s) in [4,8]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 # exponential term
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9 e = ord(s[-1])
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 if e & 0x80:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11 e = e - 256
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
12
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13 # mantissa
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 m = [ord(x) for x in s[:-1]]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
15 M = 0.
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
16 for i in range(len(s)-1):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 #M += m[i]<<(i*8)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18 M += float(m[i])/2**((i+1)*8)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20 #if m[0] & 0x80:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21 # M = M - 2^(len(s))
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23 return M * 2**(e+1)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24 mm = str(M)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 mm = '0.'+mm + 'e' + str(e)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 if len(s) == 8:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28 print "mm = ", mm
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29 return eval(mm)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
31 def decode_string(s):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32 nb = ord(s[0])
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
33 s = s[1:nb+2]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34 r = ""
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35 for c in s:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
36 if ord(c)>128:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
37 c = chr(ord(c)-128)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
38 r += c
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
39 return r
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
41 EDSP = {0: "No data",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
42 1: "Frequency response",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
43 2: "Power spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
44 3: "Power spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
45 4: "Coherence",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
46 5: "Cross spectrum",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
47 6: "Input time 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
48 7: "Input time 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
49 8: "Input linear spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
50 9: "Input linear spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
51 10: "Impulse response",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
52 11: "Cross correlation",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
53 12: "Auto correlation 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
54 13: "Auto correlation 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
55 14: "Histogram 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
56 15: "Histogram 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
57 16: "Cumulative density function 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
58 17: "Cumulative density function 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
59 18: "Probability density function 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
60 19: "Probability density function 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
61 20: "Average linear spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
62 21: "Average linear spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
63 22: "Average time record 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
64 23: "Average time record 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
65 24: "Synthesis pole-zeros",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
66 25: "Synthesis pole-residue",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
67 26: "Synthesis polynomial",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
68 27: "Synthesis constant",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
69 28: "Windowed time record 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
70 29: "Windowed time record 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
71 30: "Windowed linear spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
72 31: "Windowed linear spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
73 32: "Filtered time record 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
74 33: "Filtered time record 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
75 34: "Filtered linear spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
76 35: "Filtered linear spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
77 36: "Time capture buffer",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
78 37: "Captured linear spectrum",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
79 38: "Captured time record",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
80 39: "Throughput time record 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
81 40: "Throughput time record 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
82 41: "Curve fit",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
83 42: "Weighted function",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
84 43: "Not used",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
85 44: "Orbits",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
86 45: "Demodulation polar",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
87 46: "Preview demod record 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
88 47: "Preview demod record 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
89 48: "Preview demod linear spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
90 49: "Preview demod linear spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
91 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
92
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
93 ECH = {0: "Channel 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
94 1: "Channel 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
95 2: "Channel 1&2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
96 3: "No channel",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
97 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
98
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
99 EOVR = ECH
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
100
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
101 EDOM = {0: 'Time',
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
102 1: 'Frequency',
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
103 2: 'Voltage (amplitude)',
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
104 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
105
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
106 EVLT = {0: "Peak",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
107 1: "RMS",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
108 2: "Volt (indicates peak only)",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
109 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
110
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
111 EAMP = {0: "Volts",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
112 1: "Volts squared",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
113 2: "PSD (V²/Hz)",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
114 3: "ESD (V²s/Hz)",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
115 4: "PSD¹² (V/Hz¹²)",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
116 5: "No unit",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
117 6: "Unit volts",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
118 7: "Unit volts²",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
119 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
120
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
121 EXAXIS= {0: "No units",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
122 1: "Hertz",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
123 2: "RPM",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
124 3: "Orders",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
125 4: "Seconds",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
126 5: "Revs",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
127 6: "Degrees",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
128 7: "dB",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
129 8: "dBV",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
130 9: "Volts",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
131 10: "V Hz¹²",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
132 11: "Hz/s",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
133 12: "V/EU",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
134 13: "Vrms",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
135 14: "V²/Hz",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
136 15: "%",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
137 16: "Points",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
138 17: "Records",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
139 18: "Ohms",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
140 19: "Hertz/octave",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
141 20: "Pulse/Rev",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
142 21: "Decades",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
143 22: "Minutes",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
144 23: "V²s/Hz",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
145 24: "Octave",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
146 25: "Seconds/Decade",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
147 26: "Seconds/Octave",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
148 #...
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
149 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
150
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
151 EMEAS = {0: "Linear resolution",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
152 1: "Log resolution",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
153 2: "Swept sine",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
154 3: "Time capture",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
155 4: "Linear resolution throughput",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
156 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
157
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
158 EDEMOD1 = {45: "AM",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
159 46: "FM",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
160 47: "PM",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
161 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
162
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
163 EDEMOD2 = EDEMOD1
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
164
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
165 EAVG = {0: "No data",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
166 1: "Not averaged",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
167 2: "Averaged",}
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
168
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
169
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
170
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
171 EWIN = {0: "N/A",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
172 1: "Hann",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
173 2: "Flat top",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
174 #...
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
175 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
176
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
177 HEADER = [ ("Display function", EDSP, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
178 ('Number of elements', int, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
179 ('Displayed elements', int, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
180 ('Number of averages', int, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
181 ('Channel selection', ECH, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
182 ('Overflow status', EOVR, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
183 ('Overlap percentage', int, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
184 ('Domain', EDOM, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
185 ('Volts peak/rms', EVLT, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
186 ('Amplitude units', EAMP, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
187 ('X axis units', EXAXIS, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
188 ('Auto math label', str, 's', 14),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
189 ('Trace label', str, 's', 22),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
190 ('EU label 1', str, 's', 6),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
191 ('EU label 2', str, 's', 6),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
192 ('Float/Interger', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
193 ('Complex/Real', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
194 ('Live/Recalled', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
195 ('Math result', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
196 ('Real/Complex input', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
197 ('Log/Linear data', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
198 ('Auto math', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
199 ('Real time status', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
200 ('Measurement mode', EMEAS, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
201 ('Window', EWIN, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
202 ('Demod type channel 1', EDEMOD1, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
203 ('Demod type channel 2', EDEMOD2, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
204 ('Demod active channel 1', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
205 ('Demod active channel 2', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
206 ('Average status', EAVG, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
207 ('Not used', int, 'hh', 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
208 ('Samp freq/2 (real)', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
209 ('Samp freq/2 (imag)', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
210 ('Not used', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
211 ('Delta X-axis', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
212 ('Max range', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
213 ('Start time value', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
214 ('Expon wind const 1', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
215 ('Expon wind const 2', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
216 ('EU value chan 1', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
217 ('EU value chan 2', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
218 ('Trig delay chan 1', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
219 ('Trig delay chan 2', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
220 ('Start freq value', decode_float, None, 8),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
221 ('Start data value', decode_float, None, 8),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
222 ]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
223
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
224 def decode_file(filename):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
225 d = open(filename).read()
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
226
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
227 typ = d[:2]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
228 assert typ == "#A"
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
229
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
230 totlen = struct.unpack('>h', d[2:4])[0]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
231 idx = 4
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
232 tt=0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
233 header = {}
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
234 for i, (nam, dtype, fmt, nbytes) in enumerate(HEADER):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
235 if dtype == str:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
236 val = decode_string(d[idx:])
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
237 else:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
238 if fmt:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
239 v = struct.unpack('>'+fmt, d[idx: idx+nbytes])[0]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
240 if isinstance(dtype, dict):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
241 val = dtype.get(int(v), "N/A")
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
242 else:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
243 val = dtype(v)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
244 else:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
245 val = dtype(d[idx: idx+nbytes])
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
246
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
247 print idx, hex(idx), nam, ":", val
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
248 header[nam] = val
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
249 idx += nbytes
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
250
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
251 resu = []
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
252
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
253 for i in range(header["Number of elements"]):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
254 resu.append(decode_float(d[idx: idx+4]))
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
255 idx += 4
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
256
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
257 #print "resu = ", resu
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
258 #return
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
259 import pylab
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
260 import numpy
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
261 resu = numpy.array(resu, dtype=float)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
262 print "max = ", max(resu)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
263 #xr = numpy.linspace(0, header['Delta X-axis'], len(resu))
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
264 sf = header['Start freq value']
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
265 xr = numpy.linspace(sf, sf+20000, len(resu))
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
266 mn = min(resu[resu>0])
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
267 resu[resu==0] = mn
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
268 pylab.plot(xr, 10*numpy.log10(resu))
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
269 pylab.show()
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
270
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
271 # tt=0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
272 # for i, (nam, dtype, nbytes) in enumerate(HEADER):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
273 # if dtype == str:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
274 # nb = ord(struct.unpack('c', d[idx])[0])
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
275 # val = d[idx+1:idx+1+nb]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
276 # else:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
277 # v = struct.unpack('>d', d[idx: idx+(nbytes*4)])[0]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
278 # if isinstance(dtype, dict):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
279 # val = dtype.get(int(v), "N/A")
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
280 # else:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
281 # val = dtype(v)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
282 # print idx, nam, ":", val
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
283 # idx += nbytes*4
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
284
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
285
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
286
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
287
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
288 if __name__ == "__main__":
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
289 import sys
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
290 decode_file(sys.argv[1])
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
291
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
292
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
293
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
294

mercurial