##// END OF EJS Templates
-Writing files bug fixed
Julio Valdez -
r704:ee7eb10341f5
parent child
Show More
@@ -1,734 +1,734
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
5 '''
6 import numpy
6 import numpy
7 import copy
7 import copy
8 import datetime
8 import datetime
9
9
10 SPEED_OF_LIGHT = 299792458
10 SPEED_OF_LIGHT = 299792458
11 SPEED_OF_LIGHT = 3e8
11 SPEED_OF_LIGHT = 3e8
12
12
13 BASIC_STRUCTURE = numpy.dtype([
13 BASIC_STRUCTURE = numpy.dtype([
14 ('nSize','<u4'),
14 ('nSize','<u4'),
15 ('nVersion','<u2'),
15 ('nVersion','<u2'),
16 ('nDataBlockId','<u4'),
16 ('nDataBlockId','<u4'),
17 ('nUtime','<u4'),
17 ('nUtime','<u4'),
18 ('nMilsec','<u2'),
18 ('nMilsec','<u2'),
19 ('nTimezone','<i2'),
19 ('nTimezone','<i2'),
20 ('nDstflag','<i2'),
20 ('nDstflag','<i2'),
21 ('nErrorCount','<u4')
21 ('nErrorCount','<u4')
22 ])
22 ])
23
23
24 SYSTEM_STRUCTURE = numpy.dtype([
24 SYSTEM_STRUCTURE = numpy.dtype([
25 ('nSize','<u4'),
25 ('nSize','<u4'),
26 ('nNumSamples','<u4'),
26 ('nNumSamples','<u4'),
27 ('nNumProfiles','<u4'),
27 ('nNumProfiles','<u4'),
28 ('nNumChannels','<u4'),
28 ('nNumChannels','<u4'),
29 ('nADCResolution','<u4'),
29 ('nADCResolution','<u4'),
30 ('nPCDIOBusWidth','<u4'),
30 ('nPCDIOBusWidth','<u4'),
31 ])
31 ])
32
32
33 RADAR_STRUCTURE = numpy.dtype([
33 RADAR_STRUCTURE = numpy.dtype([
34 ('nSize','<u4'),
34 ('nSize','<u4'),
35 ('nExpType','<u4'),
35 ('nExpType','<u4'),
36 ('nNTx','<u4'),
36 ('nNTx','<u4'),
37 ('fIpp','<f4'),
37 ('fIpp','<f4'),
38 ('fTxA','<f4'),
38 ('fTxA','<f4'),
39 ('fTxB','<f4'),
39 ('fTxB','<f4'),
40 ('nNumWindows','<u4'),
40 ('nNumWindows','<u4'),
41 ('nNumTaus','<u4'),
41 ('nNumTaus','<u4'),
42 ('nCodeType','<u4'),
42 ('nCodeType','<u4'),
43 ('nLine6Function','<u4'),
43 ('nLine6Function','<u4'),
44 ('nLine5Function','<u4'),
44 ('nLine5Function','<u4'),
45 ('fClock','<f4'),
45 ('fClock','<f4'),
46 ('nPrePulseBefore','<u4'),
46 ('nPrePulseBefore','<u4'),
47 ('nPrePulseAfter','<u4'),
47 ('nPrePulseAfter','<u4'),
48 ('sRangeIPP','<a20'),
48 ('sRangeIPP','<a20'),
49 ('sRangeTxA','<a20'),
49 ('sRangeTxA','<a20'),
50 ('sRangeTxB','<a20'),
50 ('sRangeTxB','<a20'),
51 ])
51 ])
52
52
53 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
53 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
54
54
55
55
56 PROCESSING_STRUCTURE = numpy.dtype([
56 PROCESSING_STRUCTURE = numpy.dtype([
57 ('nSize','<u4'),
57 ('nSize','<u4'),
58 ('nDataType','<u4'),
58 ('nDataType','<u4'),
59 ('nSizeOfDataBlock','<u4'),
59 ('nSizeOfDataBlock','<u4'),
60 ('nProfilesperBlock','<u4'),
60 ('nProfilesperBlock','<u4'),
61 ('nDataBlocksperFile','<u4'),
61 ('nDataBlocksperFile','<u4'),
62 ('nNumWindows','<u4'),
62 ('nNumWindows','<u4'),
63 ('nProcessFlags','<u4'),
63 ('nProcessFlags','<u4'),
64 ('nCoherentIntegrations','<u4'),
64 ('nCoherentIntegrations','<u4'),
65 ('nIncoherentIntegrations','<u4'),
65 ('nIncoherentIntegrations','<u4'),
66 ('nTotalSpectra','<u4')
66 ('nTotalSpectra','<u4')
67 ])
67 ])
68
68
69 class Header(object):
69 class Header(object):
70
70
71 def __init__(self):
71 def __init__(self):
72 raise NotImplementedError
72 raise NotImplementedError
73
73
74 def copy(self):
74 def copy(self):
75 return copy.deepcopy(self)
75 return copy.deepcopy(self)
76
76
77 def read(self):
77 def read(self):
78
78
79 raise NotImplementedError
79 raise NotImplementedError
80
80
81 def write(self):
81 def write(self):
82
82
83 raise NotImplementedError
83 raise NotImplementedError
84
84
85 def printInfo(self):
85 def printInfo(self):
86
86
87 message = "#"*50 + "\n"
87 message = "#"*50 + "\n"
88 message += self.__class__.__name__.upper() + "\n"
88 message += self.__class__.__name__.upper() + "\n"
89 message += "#"*50 + "\n"
89 message += "#"*50 + "\n"
90
90
91 for key in self.__dict__.keys():
91 for key in self.__dict__.keys():
92 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
92 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
93
93
94 print message
94 print message
95
95
96 class BasicHeader(Header):
96 class BasicHeader(Header):
97
97
98 size = None
98 size = None
99 version = None
99 version = None
100 dataBlock = None
100 dataBlock = None
101 utc = None
101 utc = None
102 ltc = None
102 ltc = None
103 miliSecond = None
103 miliSecond = None
104 timeZone = None
104 timeZone = None
105 dstFlag = None
105 dstFlag = None
106 errorCount = None
106 errorCount = None
107 datatime = None
107 datatime = None
108
108
109 __LOCALTIME = None
109 __LOCALTIME = None
110
110
111 def __init__(self, useLocalTime=True):
111 def __init__(self, useLocalTime=True):
112
112
113 self.size = 24
113 self.size = 24
114 self.version = 0
114 self.version = 0
115 self.dataBlock = 0
115 self.dataBlock = 0
116 self.utc = 0
116 self.utc = 0
117 self.miliSecond = 0
117 self.miliSecond = 0
118 self.timeZone = 0
118 self.timeZone = 0
119 self.dstFlag = 0
119 self.dstFlag = 0
120 self.errorCount = 0
120 self.errorCount = 0
121
121
122 self.useLocalTime = useLocalTime
122 self.useLocalTime = useLocalTime
123
123
124 def read(self, fp):
124 def read(self, fp):
125
125
126 try:
126 try:
127 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
127 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
128
128
129 except Exception, e:
129 except Exception, e:
130 print "BasicHeader: "
130 print "BasicHeader: "
131 print e
131 print e
132 return 0
132 return 0
133
133
134 self.size = int(header['nSize'][0])
134 self.size = int(header['nSize'][0])
135 self.version = int(header['nVersion'][0])
135 self.version = int(header['nVersion'][0])
136 self.dataBlock = int(header['nDataBlockId'][0])
136 self.dataBlock = int(header['nDataBlockId'][0])
137 self.utc = int(header['nUtime'][0])
137 self.utc = int(header['nUtime'][0])
138 self.miliSecond = int(header['nMilsec'][0])
138 self.miliSecond = int(header['nMilsec'][0])
139 self.timeZone = int(header['nTimezone'][0])
139 self.timeZone = int(header['nTimezone'][0])
140 self.dstFlag = int(header['nDstflag'][0])
140 self.dstFlag = int(header['nDstflag'][0])
141 self.errorCount = int(header['nErrorCount'][0])
141 self.errorCount = int(header['nErrorCount'][0])
142
142
143 return 1
143 return 1
144
144
145 def write(self, fp):
145 def write(self, fp):
146
146
147 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
147 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
148 header = numpy.array(headerTuple, BASIC_STRUCTURE)
148 header = numpy.array(headerTuple, BASIC_STRUCTURE)
149 header.tofile(fp)
149 header.tofile(fp)
150
150
151 return 1
151 return 1
152
152
153 def get_ltc(self):
153 def get_ltc(self):
154
154
155 return self.utc - self.timeZone*60
155 return self.utc - self.timeZone*60
156
156
157 def set_ltc(self, value):
157 def set_ltc(self, value):
158
158
159 self.utc = value + self.timeZone*60
159 self.utc = value + self.timeZone*60
160
160
161 def get_datatime(self):
161 def get_datatime(self):
162
162
163 return datetime.datetime.utcfromtimestamp(self.ltc)
163 return datetime.datetime.utcfromtimestamp(self.ltc)
164
164
165 ltc = property(get_ltc, set_ltc)
165 ltc = property(get_ltc, set_ltc)
166 datatime = property(get_datatime)
166 datatime = property(get_datatime)
167
167
168 class SystemHeader(Header):
168 class SystemHeader(Header):
169
169
170 size = None
170 size = None
171 nSamples = None
171 nSamples = None
172 nProfiles = None
172 nProfiles = None
173 nChannels = None
173 nChannels = None
174 adcResolution = None
174 adcResolution = None
175 pciDioBusWidth = None
175 pciDioBusWidth = None
176
176
177 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
177 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
178
178
179 self.size = 24
179 self.size = 24
180 self.nSamples = nSamples
180 self.nSamples = nSamples
181 self.nProfiles = nProfiles
181 self.nProfiles = nProfiles
182 self.nChannels = nChannels
182 self.nChannels = nChannels
183 self.adcResolution = adcResolution
183 self.adcResolution = adcResolution
184 self.pciDioBusWidth = pciDioBusWith
184 self.pciDioBusWidth = pciDioBusWith
185
185
186 def read(self, fp):
186 def read(self, fp):
187
187
188 startFp = fp.tell()
188 startFp = fp.tell()
189
189
190 try:
190 try:
191 header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1)
191 header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1)
192 except Exception, e:
192 except Exception, e:
193 print "SystemHeader: " + e
193 print "SystemHeader: " + e
194 return 0
194 return 0
195
195
196 self.size = header['nSize'][0]
196 self.size = header['nSize'][0]
197 self.nSamples = header['nNumSamples'][0]
197 self.nSamples = header['nNumSamples'][0]
198 self.nProfiles = header['nNumProfiles'][0]
198 self.nProfiles = header['nNumProfiles'][0]
199 self.nChannels = header['nNumChannels'][0]
199 self.nChannels = header['nNumChannels'][0]
200 self.adcResolution = header['nADCResolution'][0]
200 self.adcResolution = header['nADCResolution'][0]
201 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
201 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
202
202
203 endFp = self.size + startFp
203 endFp = self.size + startFp
204
204
205 if fp.tell() != endFp:
205 if fp.tell() != endFp:
206 print "System Header is not consistent"
206 print "System Header is not consistent"
207 return 0
207 return 0
208
208
209 return 1
209 return 1
210
210
211 def write(self, fp):
211 def write(self, fp):
212
212
213 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
213 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
214 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
214 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
215 header.tofile(fp)
215 header.tofile(fp)
216
216
217 return 1
217 return 1
218
218
219 class RadarControllerHeader(Header):
219 class RadarControllerHeader(Header):
220
220
221 size = None
221 size = None
222 expType = None
222 expType = None
223 nTx = None
223 nTx = None
224 ipp = None
224 ipp = None
225 txA = None
225 txA = None
226 txB = None
226 txB = None
227 nWindows = None
227 nWindows = None
228 numTaus = None
228 numTaus = None
229 codeType = None
229 codeType = None
230 line6Function = None
230 line6Function = None
231 line5Function = None
231 line5Function = None
232 fClock = None
232 fClock = None
233 prePulseBefore = None
233 prePulseBefore = None
234 prePulserAfter = None
234 prePulserAfter = None
235 rangeIpp = None
235 rangeIpp = None
236 rangeTxA = None
236 rangeTxA = None
237 rangeTxB = None
237 rangeTxB = None
238
238
239 __size = None
239 __size = None
240
240
241 def __init__(self, expType=2, nTx=1,
241 def __init__(self, expType=2, nTx=1,
242 ippKm=None, txA=0, txB=0,
242 ippKm=None, txA=0, txB=0,
243 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
243 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
244 numTaus=0, line6Function=0, line5Function=0, fClock=None,
244 numTaus=0, line6Function=0, line5Function=0, fClock=None,
245 prePulseBefore=0, prePulseAfter=0,
245 prePulseBefore=0, prePulseAfter=0,
246 codeType=0, nCode=0, nBaud=0, code=None,
246 codeType=0, nCode=0, nBaud=0, code=None,
247 flip1=0, flip2=0):
247 flip1=0, flip2=0):
248
248
249 self.size = 116
249 self.size = 116
250 self.expType = expType
250 self.expType = expType
251 self.nTx = nTx
251 self.nTx = nTx
252 self.ipp = ippKm
252 self.ipp = ippKm
253 self.txA = txA
253 self.txA = txA
254 self.txB = txB
254 self.txB = txB
255 self.rangeIpp = ippKm
255 self.rangeIpp = ippKm
256 self.rangeTxA = txA
256 self.rangeTxA = txA
257 self.rangeTxB = txB
257 self.rangeTxB = txB
258
258
259 self.nWindows = nWindows
259 self.nWindows = nWindows
260 self.numTaus = numTaus
260 self.numTaus = numTaus
261 self.codeType = codeType
261 self.codeType = codeType
262 self.line6Function = line6Function
262 self.line6Function = line6Function
263 self.line5Function = line5Function
263 self.line5Function = line5Function
264 self.fClock = fClock
264 self.fClock = fClock
265 self.prePulseBefore = prePulseBefore
265 self.prePulseBefore = prePulseBefore
266 self.prePulserAfter = prePulseAfter
266 self.prePulserAfter = prePulseAfter
267
267
268 self.nHeights = nHeights
268 self.nHeights = nHeights
269 self.firstHeight = firstHeight
269 self.firstHeight = firstHeight
270 self.deltaHeight = deltaHeight
270 self.deltaHeight = deltaHeight
271 self.samplesWin = nHeights
271 self.samplesWin = nHeights
272
272
273 self.nCode = nCode
273 self.nCode = nCode
274 self.nBaud = nBaud
274 self.nBaud = nBaud
275 self.code = code
275 self.code = code
276 self.flip1 = flip1
276 self.flip1 = flip1
277 self.flip2 = flip2
277 self.flip2 = flip2
278
278
279 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
279 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
280 # self.dynamic = numpy.array([],numpy.dtype('byte'))
280 # self.dynamic = numpy.array([],numpy.dtype('byte'))
281
281
282 if self.fClock is None and self.deltaHeight is not None:
282 if self.fClock is None and self.deltaHeight is not None:
283 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
283 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
284
284
285 def read(self, fp):
285 def read(self, fp):
286
286
287
287
288 startFp = fp.tell()
288 startFp = fp.tell()
289 try:
289 try:
290 header = numpy.fromfile(fp,RADAR_STRUCTURE,1)
290 header = numpy.fromfile(fp,RADAR_STRUCTURE,1)
291 except Exception, e:
291 except Exception, e:
292 print "RadarControllerHeader: " + e
292 print "RadarControllerHeader: " + e
293 return 0
293 return 0
294
294
295 size = int(header['nSize'][0])
295 size = int(header['nSize'][0])
296 self.expType = int(header['nExpType'][0])
296 self.expType = int(header['nExpType'][0])
297 self.nTx = int(header['nNTx'][0])
297 self.nTx = int(header['nNTx'][0])
298 self.ipp = float(header['fIpp'][0])
298 self.ipp = float(header['fIpp'][0])
299 self.txA = float(header['fTxA'][0])
299 self.txA = float(header['fTxA'][0])
300 self.txB = float(header['fTxB'][0])
300 self.txB = float(header['fTxB'][0])
301 self.nWindows = int(header['nNumWindows'][0])
301 self.nWindows = int(header['nNumWindows'][0])
302 self.numTaus = int(header['nNumTaus'][0])
302 self.numTaus = int(header['nNumTaus'][0])
303 self.codeType = int(header['nCodeType'][0])
303 self.codeType = int(header['nCodeType'][0])
304 self.line6Function = int(header['nLine6Function'][0])
304 self.line6Function = int(header['nLine6Function'][0])
305 self.line5Function = int(header['nLine5Function'][0])
305 self.line5Function = int(header['nLine5Function'][0])
306 self.fClock = float(header['fClock'][0])
306 self.fClock = float(header['fClock'][0])
307 self.prePulseBefore = int(header['nPrePulseBefore'][0])
307 self.prePulseBefore = int(header['nPrePulseBefore'][0])
308 self.prePulserAfter = int(header['nPrePulseAfter'][0])
308 self.prePulserAfter = int(header['nPrePulseAfter'][0])
309 self.rangeIpp = header['sRangeIPP'][0]
309 self.rangeIpp = header['sRangeIPP'][0]
310 self.rangeTxA = header['sRangeTxA'][0]
310 self.rangeTxA = header['sRangeTxA'][0]
311 self.rangeTxB = header['sRangeTxB'][0]
311 self.rangeTxB = header['sRangeTxB'][0]
312
312
313 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
313 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
314
314
315 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
315 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
316 self.firstHeight = samplingWindow['h0']
316 self.firstHeight = samplingWindow['h0']
317 self.deltaHeight = samplingWindow['dh']
317 self.deltaHeight = samplingWindow['dh']
318 self.samplesWin = samplingWindow['nsa']
318 self.samplesWin = samplingWindow['nsa']
319
319
320 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
320 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
321
321
322 self.code_size = 0
322 self.code_size = 0
323 if self.codeType != 0:
323 if self.codeType != 0:
324 self.nCode = int(numpy.fromfile(fp,'<u4',1))
324 self.nCode = int(numpy.fromfile(fp,'<u4',1))
325 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
325 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
326
326
327 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
327 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
328 for ic in range(self.nCode):
328 for ic in range(self.nCode):
329 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
329 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
330 for ib in range(self.nBaud-1,-1,-1):
330 for ib in range(self.nBaud-1,-1,-1):
331 code[ic,ib] = temp[ib/32]%2
331 code[ic,ib] = temp[ib/32]%2
332 temp[ib/32] = temp[ib/32]/2
332 temp[ib/32] = temp[ib/32]/2
333
333
334 self.code = 2.0*code - 1.0
334 self.code = 2.0*code - 1.0
335 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
335 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
336
336
337 # if self.line5Function == RCfunction.FLIP:
337 # if self.line5Function == RCfunction.FLIP:
338 # self.flip1 = numpy.fromfile(fp,'<u4',1)
338 # self.flip1 = numpy.fromfile(fp,'<u4',1)
339 #
339 #
340 # if self.line6Function == RCfunction.FLIP:
340 # if self.line6Function == RCfunction.FLIP:
341 # self.flip2 = numpy.fromfile(fp,'<u4',1)
341 # self.flip2 = numpy.fromfile(fp,'<u4',1)
342
342
343 endFp = size + startFp
343 endFp = size + startFp
344
344
345 if fp.tell() != endFp:
345 if fp.tell() != endFp:
346 print "Radar Controller Header is not consistent"
346 print "Radar Controller Header is not consistent"
347 return 0
347 return 0
348
348
349 return 1
349 return 1
350
350
351 def write(self, fp):
351 def write(self, fp):
352
352
353 headerTuple = (self.size,
353 headerTuple = (self.size,
354 self.expType,
354 self.expType,
355 self.nTx,
355 self.nTx,
356 self.ipp,
356 self.ipp,
357 self.txA,
357 self.txA,
358 self.txB,
358 self.txB,
359 self.nWindows,
359 self.nWindows,
360 self.numTaus,
360 self.numTaus,
361 self.codeType,
361 self.codeType,
362 self.line6Function,
362 self.line6Function,
363 self.line5Function,
363 self.line5Function,
364 self.fClock,
364 self.fClock,
365 self.prePulseBefore,
365 self.prePulseBefore,
366 self.prePulserAfter,
366 self.prePulserAfter,
367 self.rangeIpp,
367 self.rangeIpp,
368 self.rangeTxA,
368 self.rangeTxA,
369 self.rangeTxB)
369 self.rangeTxB)
370
370
371 header = numpy.array(headerTuple,RADAR_STRUCTURE)
371 header = numpy.array(headerTuple,RADAR_STRUCTURE)
372 header.tofile(fp)
372 header.tofile(fp)
373
373
374 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
374 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
375 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
375 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
376 samplingWindow.tofile(fp)
376 samplingWindow.tofile(fp)
377
377
378 if self.numTaus > 0:
378 if self.numTaus > 0:
379 self.Taus.tofile(fp)
379 self.Taus.tofile(fp)
380
380
381 if self.codeType !=0:
381 if self.codeType !=0:
382 nCode = numpy.array(self.nCode, '<u4')
382 nCode = numpy.array(self.nCode, '<u4')
383 nCode.tofile(fp)
383 nCode.tofile(fp)
384 nBaud = numpy.array(self.nBaud, '<u4')
384 nBaud = numpy.array(self.nBaud, '<u4')
385 nBaud.tofile(fp)
385 nBaud.tofile(fp)
386 code1 = (self.code + 1.0)/2.
386 code1 = (self.code + 1.0)/2.
387
387
388 for ic in range(self.nCode):
388 for ic in range(self.nCode):
389 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
389 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
390 start = 0
390 start = 0
391 end = 32
391 end = 32
392 for i in range(len(tempx)):
392 for i in range(len(tempx)):
393 code_selected = code1[ic,start:end]
393 code_selected = code1[ic,start:end]
394 for j in range(len(code_selected)-1,-1,-1):
394 for j in range(len(code_selected)-1,-1,-1):
395 if code_selected[j] == 1:
395 if code_selected[j] == 1:
396 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
396 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
397 start = start + 32
397 start = start + 32
398 end = end + 32
398 end = end + 32
399
399
400 tempx = tempx.astype('u4')
400 tempx = tempx.astype('u4')
401 tempx.tofile(fp)
401 tempx.tofile(fp)
402
402
403 # if self.line5Function == RCfunction.FLIP:
403 # if self.line5Function == RCfunction.FLIP:
404 # self.flip1.tofile(fp)
404 # self.flip1.tofile(fp)
405 #
405 #
406 # if self.line6Function == RCfunction.FLIP:
406 # if self.line6Function == RCfunction.FLIP:
407 # self.flip2.tofile(fp)
407 # self.flip2.tofile(fp)
408
408
409 return 1
409 return 1
410
410
411 def get_ippSeconds(self):
411 def get_ippSeconds(self):
412 '''
412 '''
413 '''
413 '''
414 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
414 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
415
415
416 return ippSeconds
416 return ippSeconds
417
417
418 def set_ippSeconds(self, ippSeconds):
418 def set_ippSeconds(self, ippSeconds):
419 '''
419 '''
420 '''
420 '''
421
421
422 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
422 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
423
423
424 return
424 return
425
425
426 def get_size(self):
426 def get_size(self):
427
427
428 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
428 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
429
429
430 if self.codeType != 0:
430 if self.codeType != 0:
431 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
431 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
432
432
433 return self.__size
433 return self.__size
434
434
435 def set_size(self, value):
435 def set_size(self, value):
436
436
437 self.__size = value
437 self.__size = value
438
438
439 return
439 return
440
440
441 ippSeconds = property(get_ippSeconds, set_ippSeconds)
441 ippSeconds = property(get_ippSeconds, set_ippSeconds)
442 size = property(get_size, set_size)
442 size = property(get_size, set_size)
443
443
444 class ProcessingHeader(Header):
444 class ProcessingHeader(Header):
445
445
446 # size = None
446 # size = None
447 dtype = None
447 dtype = None
448 blockSize = None
448 blockSize = None
449 profilesPerBlock = None
449 profilesPerBlock = None
450 dataBlocksPerFile = None
450 dataBlocksPerFile = None
451 nWindows = None
451 nWindows = None
452 processFlags = None
452 processFlags = None
453 nCohInt = None
453 nCohInt = None
454 nIncohInt = None
454 nIncohInt = None
455 totalSpectra = None
455 totalSpectra = None
456
456
457 flag_dc = None
457 flag_dc = None
458 flag_cspc = None
458 flag_cspc = None
459
459
460 def __init__(self):
460 def __init__(self):
461
461
462 # self.size = 0
462 # self.size = 0
463 self.dtype = 0
463 self.dtype = 0
464 self.blockSize = 0
464 self.blockSize = 0
465 self.profilesPerBlock = 0
465 self.profilesPerBlock = 0
466 self.dataBlocksPerFile = 0
466 self.dataBlocksPerFile = 0
467 self.nWindows = 0
467 self.nWindows = 0
468 self.processFlags = 0
468 self.processFlags = 0
469 self.nCohInt = 0
469 self.nCohInt = 0
470 self.nIncohInt = 0
470 self.nIncohInt = 0
471 self.totalSpectra = 0
471 self.totalSpectra = 0
472
472
473 self.nHeights = 0
473 self.nHeights = 0
474 self.firstHeight = 0
474 self.firstHeight = 0
475 self.deltaHeight = 0
475 self.deltaHeight = 0
476 self.samplesWin = 0
476 self.samplesWin = 0
477 self.spectraComb = 0
477 self.spectraComb = 0
478 self.nCode = None
478 self.nCode = None
479 self.code = None
479 self.code = None
480 self.nBaud = None
480 self.nBaud = None
481
481
482 self.shif_fft = False
482 self.shif_fft = False
483 self.flag_dc = False
483 self.flag_dc = False
484 self.flag_cspc = False
484 self.flag_cspc = False
485 self.flag_decode = False
485 self.flag_decode = False
486 self.flag_deflip = False
486 self.flag_deflip = False
487
487
488 def read(self, fp):
488 def read(self, fp):
489
489
490 startFp = fp.tell()
490 startFp = fp.tell()
491
491
492 try:
492 try:
493 header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1)
493 header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1)
494 except Exception, e:
494 except Exception, e:
495 print "ProcessingHeader: " + e
495 print "ProcessingHeader: " + e
496 return 0
496 return 0
497
497
498 size = int(header['nSize'][0])
498 size = int(header['nSize'][0])
499 self.dtype = int(header['nDataType'][0])
499 self.dtype = int(header['nDataType'][0])
500 self.blockSize = int(header['nSizeOfDataBlock'][0])
500 self.blockSize = int(header['nSizeOfDataBlock'][0])
501 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
501 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
502 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
502 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
503 self.nWindows = int(header['nNumWindows'][0])
503 self.nWindows = int(header['nNumWindows'][0])
504 self.processFlags = header['nProcessFlags']
504 self.processFlags = header['nProcessFlags']
505 self.nCohInt = int(header['nCoherentIntegrations'][0])
505 self.nCohInt = int(header['nCoherentIntegrations'][0])
506 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
506 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
507 self.totalSpectra = int(header['nTotalSpectra'][0])
507 self.totalSpectra = int(header['nTotalSpectra'][0])
508
508
509 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
509 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
510
510
511 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
511 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
512 self.firstHeight = float(samplingWindow['h0'][0])
512 self.firstHeight = float(samplingWindow['h0'][0])
513 self.deltaHeight = float(samplingWindow['dh'][0])
513 self.deltaHeight = float(samplingWindow['dh'][0])
514 self.samplesWin = samplingWindow['nsa'][0]
514 self.samplesWin = samplingWindow['nsa'][0]
515
515
516 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
516 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
517
517
518 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
518 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
519 self.nCode = int(numpy.fromfile(fp,'<u4',1))
519 self.nCode = int(numpy.fromfile(fp,'<u4',1))
520 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
520 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
521 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
521 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
522
522
523 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
523 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
524 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
524 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
525 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
525 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
526
526
527 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
527 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
528 self.shif_fft = True
528 self.shif_fft = True
529 else:
529 else:
530 self.shif_fft = False
530 self.shif_fft = False
531
531
532 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
532 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
533 self.flag_dc = True
533 self.flag_dc = True
534 else:
534 else:
535 self.flag_dc = False
535 self.flag_dc = False
536
536
537 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
537 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
538 self.flag_decode = True
538 self.flag_decode = True
539 else:
539 else:
540 self.flag_decode = False
540 self.flag_decode = False
541
541
542 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
542 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
543 self.flag_deflip = True
543 self.flag_deflip = True
544 else:
544 else:
545 self.flag_deflip = False
545 self.flag_deflip = False
546
546
547 nChannels = 0
547 nChannels = 0
548 nPairs = 0
548 nPairs = 0
549 pairList = []
549 pairList = []
550
550
551 for i in range( 0, self.totalSpectra*2, 2 ):
551 for i in range( 0, self.totalSpectra*2, 2 ):
552 if self.spectraComb[i] == self.spectraComb[i+1]:
552 if self.spectraComb[i] == self.spectraComb[i+1]:
553 nChannels = nChannels + 1 #par de canales iguales
553 nChannels = nChannels + 1 #par de canales iguales
554 else:
554 else:
555 nPairs = nPairs + 1 #par de canales diferentes
555 nPairs = nPairs + 1 #par de canales diferentes
556 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
556 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
557
557
558 self.flag_cspc = False
558 self.flag_cspc = False
559 if nPairs > 0:
559 if nPairs > 0:
560 self.flag_cspc = True
560 self.flag_cspc = True
561
561
562 endFp = size + startFp
562 endFp = size + startFp
563
563
564 if fp.tell() != endFp:
564 if fp.tell() != endFp:
565 print "Processing Header is not consistent"
565 print "Processing Header is not consistent"
566 return 0
566 return 0
567
567
568 return 1
568 return 1
569
569
570 def write(self, fp):
570 def write(self, fp):
571 #Clear DEFINE_PROCESS_CODE
571 #Clear DEFINE_PROCESS_CODE
572 # self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
572 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
573
573
574 headerTuple = (self.size,
574 headerTuple = (self.size,
575 self.dtype,
575 self.dtype,
576 self.blockSize,
576 self.blockSize,
577 self.profilesPerBlock,
577 self.profilesPerBlock,
578 self.dataBlocksPerFile,
578 self.dataBlocksPerFile,
579 self.nWindows,
579 self.nWindows,
580 self.processFlags,
580 self.processFlags,
581 self.nCohInt,
581 self.nCohInt,
582 self.nIncohInt,
582 self.nIncohInt,
583 self.totalSpectra)
583 self.totalSpectra)
584
584
585 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
585 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
586 header.tofile(fp)
586 header.tofile(fp)
587
587
588 if self.nWindows != 0:
588 if self.nWindows != 0:
589 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
589 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
590 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
590 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
591 samplingWindow.tofile(fp)
591 samplingWindow.tofile(fp)
592
592
593 if self.totalSpectra != 0:
593 if self.totalSpectra != 0:
594 # spectraComb = numpy.array([],numpy.dtype('u1'))
594 # spectraComb = numpy.array([],numpy.dtype('u1'))
595 spectraComb = self.spectraComb
595 spectraComb = self.spectraComb
596 spectraComb.tofile(fp)
596 spectraComb.tofile(fp)
597
597
598 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
598 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
599 nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
599 nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
600 nCode.tofile(fp)
600 nCode.tofile(fp)
601
601
602 nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
602 nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
603 nBaud.tofile(fp)
603 nBaud.tofile(fp)
604
604
605 code = self.code.reshape(self.nCode*self.nBaud)
605 code = self.code.reshape(self.nCode*self.nBaud)
606 code = code.astype(numpy.dtype('<f4'))
606 code = code.astype(numpy.dtype('<f4'))
607 code.tofile(fp)
607 code.tofile(fp)
608
608
609 return 1
609 return 1
610
610
611 def get_size(self):
611 def get_size(self):
612
612
613 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
613 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
614
614
615 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
615 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
616 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
616 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
617 self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
617 self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
618
618
619 return self.__size
619 return self.__size
620
620
621 def set_size(self, value):
621 def set_size(self, value):
622
622
623 self.__size = value
623 self.__size = value
624
624
625 return
625 return
626
626
627 size = property(get_size, set_size)
627 size = property(get_size, set_size)
628
628
629 class RCfunction:
629 class RCfunction:
630 NONE=0
630 NONE=0
631 FLIP=1
631 FLIP=1
632 CODE=2
632 CODE=2
633 SAMPLING=3
633 SAMPLING=3
634 LIN6DIV256=4
634 LIN6DIV256=4
635 SYNCHRO=5
635 SYNCHRO=5
636
636
637 class nCodeType:
637 class nCodeType:
638 NONE=0
638 NONE=0
639 USERDEFINE=1
639 USERDEFINE=1
640 BARKER2=2
640 BARKER2=2
641 BARKER3=3
641 BARKER3=3
642 BARKER4=4
642 BARKER4=4
643 BARKER5=5
643 BARKER5=5
644 BARKER7=6
644 BARKER7=6
645 BARKER11=7
645 BARKER11=7
646 BARKER13=8
646 BARKER13=8
647 AC128=9
647 AC128=9
648 COMPLEMENTARYCODE2=10
648 COMPLEMENTARYCODE2=10
649 COMPLEMENTARYCODE4=11
649 COMPLEMENTARYCODE4=11
650 COMPLEMENTARYCODE8=12
650 COMPLEMENTARYCODE8=12
651 COMPLEMENTARYCODE16=13
651 COMPLEMENTARYCODE16=13
652 COMPLEMENTARYCODE32=14
652 COMPLEMENTARYCODE32=14
653 COMPLEMENTARYCODE64=15
653 COMPLEMENTARYCODE64=15
654 COMPLEMENTARYCODE128=16
654 COMPLEMENTARYCODE128=16
655 CODE_BINARY28=17
655 CODE_BINARY28=17
656
656
657 class PROCFLAG:
657 class PROCFLAG:
658
658
659 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
659 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
660 DECODE_DATA = numpy.uint32(0x00000002)
660 DECODE_DATA = numpy.uint32(0x00000002)
661 SPECTRA_CALC = numpy.uint32(0x00000004)
661 SPECTRA_CALC = numpy.uint32(0x00000004)
662 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
662 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
663 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
663 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
664 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
664 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
665
665
666 DATATYPE_CHAR = numpy.uint32(0x00000040)
666 DATATYPE_CHAR = numpy.uint32(0x00000040)
667 DATATYPE_SHORT = numpy.uint32(0x00000080)
667 DATATYPE_SHORT = numpy.uint32(0x00000080)
668 DATATYPE_LONG = numpy.uint32(0x00000100)
668 DATATYPE_LONG = numpy.uint32(0x00000100)
669 DATATYPE_INT64 = numpy.uint32(0x00000200)
669 DATATYPE_INT64 = numpy.uint32(0x00000200)
670 DATATYPE_FLOAT = numpy.uint32(0x00000400)
670 DATATYPE_FLOAT = numpy.uint32(0x00000400)
671 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
671 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
672
672
673 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
673 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
674 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
674 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
675 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
675 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
676
676
677 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
677 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
678 DEFLIP_DATA = numpy.uint32(0x00010000)
678 DEFLIP_DATA = numpy.uint32(0x00010000)
679 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
679 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
680
680
681 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
681 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
682 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
682 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
683 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
683 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
684 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
684 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
685 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
685 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
686
686
687 EXP_NAME_ESP = numpy.uint32(0x00200000)
687 EXP_NAME_ESP = numpy.uint32(0x00200000)
688 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
688 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
689
689
690 OPERATION_MASK = numpy.uint32(0x0000003F)
690 OPERATION_MASK = numpy.uint32(0x0000003F)
691 DATATYPE_MASK = numpy.uint32(0x00000FC0)
691 DATATYPE_MASK = numpy.uint32(0x00000FC0)
692 DATAARRANGE_MASK = numpy.uint32(0x00007000)
692 DATAARRANGE_MASK = numpy.uint32(0x00007000)
693 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
693 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
694
694
695 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
695 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
696 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
696 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
697 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
697 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
698 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
698 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
699 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
699 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
700 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
700 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
701
701
702 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
702 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
703
703
704 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
704 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
705 PROCFLAG.DATATYPE_SHORT,
705 PROCFLAG.DATATYPE_SHORT,
706 PROCFLAG.DATATYPE_LONG,
706 PROCFLAG.DATATYPE_LONG,
707 PROCFLAG.DATATYPE_INT64,
707 PROCFLAG.DATATYPE_INT64,
708 PROCFLAG.DATATYPE_FLOAT,
708 PROCFLAG.DATATYPE_FLOAT,
709 PROCFLAG.DATATYPE_DOUBLE]
709 PROCFLAG.DATATYPE_DOUBLE]
710
710
711 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
711 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
712
712
713 def get_dtype_index(numpy_dtype):
713 def get_dtype_index(numpy_dtype):
714
714
715 index = None
715 index = None
716
716
717 for i in range(len(NUMPY_DTYPE_LIST)):
717 for i in range(len(NUMPY_DTYPE_LIST)):
718 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
718 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
719 index = i
719 index = i
720 break
720 break
721
721
722 return index
722 return index
723
723
724 def get_numpy_dtype(index):
724 def get_numpy_dtype(index):
725
725
726 return NUMPY_DTYPE_LIST[index]
726 return NUMPY_DTYPE_LIST[index]
727
727
728 def get_procflag_dtype(index):
728 def get_procflag_dtype(index):
729
729
730 return PROCFLAG_DTYPE_LIST[index]
730 return PROCFLAG_DTYPE_LIST[index]
731
731
732 def get_dtype_width(index):
732 def get_dtype_width(index):
733
733
734 return DTYPE_WIDTH[index] No newline at end of file
734 return DTYPE_WIDTH[index]
General Comments 0
You need to be logged in to leave comments. Login now