read_trace.py

Tue, 11 Dec 2007 00:07:54 +0100

author
David Douard <david.douard@logilab.fr>
date
Tue, 11 Dec 2007 00:07:54 +0100
changeset 8
aa3d55f78563
parent 6
6b6dc68588b2
child 10
2999318b49a2
permissions
-rw-r--r--

adjust timing parameters & fixes

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

mercurial