-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdgram_iter_xtc1.py
35 lines (33 loc) · 1.23 KB
/
dgram_iter_xtc1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys
import numpy as np
class Dgram:
def __init__(self,f):
headerwords = 10
self._header = np.fromfile(f,dtype=np.uint32,count=headerwords)
self._xtcsize = 20
self._payload = np.fromfile(f,dtype=np.uint8,count=self.extent()-self._xtcsize)
#print 'payload',self.extent(),len(self._payload)
def clocklow(self): return self._header[0]
def clockhigh(self): return self._header[1]
def tslow(self): return self._header[2]&0xffffff
def transitionId(self): return (self._header[2]>>24)&0x1f
def tshigh(self): return self._header[3]
def fiducials(self): return self.tshigh()&0x1ffff
def env(self): return self._header[4]
def dmg(self): return self._header[5]
def srclog(self): return self._header[6]
def srcphy(self): return self._header[7]
def contains(self): return self._header[8]
def extent(self): return self._header[9]
def next(self): return self.extent()+self._xtcsize
def data(self): return self._header
def write(self,outfile):
self._header.tofile(outfile)
self._payload.tofile(outfile)
infile = open(sys.argv[1],'r')
outfile = open('junk.xtc','w')
while (1):
dg = Dgram(infile)
dg.write(outfile)
outfile.close()
infile.close()