4
|
1 '''Utility fns for dealing with block .tsv files'''
|
|
2 import math,re
|
|
3
|
|
4 IPAT=re.compile('-?[0-9][0-9]*$')
|
|
5 PPAT=re.compile('[ ,;\[\]]')
|
|
6
|
|
7 def intsMaybe(ii):
|
|
8 return (int(i) for i in ii if IPAT.match(i))
|
|
9
|
|
10 def readHeaders(host,infile,skipColHdrs=True):
|
|
11 l=infile.readline().rstrip()
|
|
12 ff=PPAT.split(l)
|
|
13 (host.nr,host.ox,host.oy,host.oz)=intsMaybe(ff)
|
|
14 host.et=ff[9]
|
|
15 l=infile.readline().rstrip()
|
|
16 (host.orad,host.ymin,host.ymax)=intsMaybe(PPAT.split(l))
|
|
17 if skipColHdrs:
|
|
18 _=infile.readline()
|
|
19
|
|
20 def d(p1,p2):
|
|
21 dx=p1[0]-p2[0]
|
|
22 dz=p1[1]-p2[1]
|
|
23 dy=p1[2]-p2[2]
|
|
24 return math.sqrt((dx*dx)+(dy*dy)+(dz*dz))
|