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
|
11
|
7 Red='[31m'
|
|
8 eRed='[39m'
|
|
9 RedFmt=Red+'%s'+eRed
|
|
10
|
4
|
11 def intsMaybe(ii):
|
|
12 return (int(i) for i in ii if IPAT.match(i))
|
|
13
|
|
14 def readHeaders(host,infile,skipColHdrs=True):
|
|
15 l=infile.readline().rstrip()
|
|
16 ff=PPAT.split(l)
|
|
17 (host.nr,host.ox,host.oy,host.oz)=intsMaybe(ff)
|
|
18 host.et=ff[9]
|
|
19 l=infile.readline().rstrip()
|
11
|
20 l2=PPAT.split(l)
|
|
21 if l2[-1]=='bounded':
|
|
22 host.orad=int(l2[1])
|
|
23 host.ymin=host.ymax=-1
|
|
24 else:
|
|
25 (host.orad,host.ymin,host.ymax)=intsMaybe(PPAT.split(l))
|
4
|
26 if skipColHdrs:
|
|
27 _=infile.readline()
|
|
28
|
|
29 def d(p1,p2):
|
|
30 dx=p1[0]-p2[0]
|
|
31 dz=p1[1]-p2[1]
|
|
32 dy=p1[2]-p2[2]
|
|
33 return math.sqrt((dx*dx)+(dy*dy)+(dz*dz))
|