Mercurial > hg > lib > markup
comparison python/util.py @ 11:e411408d64ec
from python repo
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Sat, 11 Dec 2021 16:13:04 -0500 |
parents | 56508a6033a9 |
children |
comparison
equal
deleted
inserted
replaced
10:73bb35b96624 | 11:e411408d64ec |
---|---|
1 '''Utility fns for dealing with block .tsv files''' | 1 '''Utility fns for dealing with block .tsv files''' |
2 import math,re | 2 import math,re |
3 | 3 |
4 IPAT=re.compile('-?[0-9][0-9]*$') | 4 IPAT=re.compile('-?[0-9][0-9]*$') |
5 PPAT=re.compile('[ ,;\[\]]') | 5 PPAT=re.compile('[ ,;\[\]]') |
6 | |
7 Red='[31m' | |
8 eRed='[39m' | |
9 RedFmt=Red+'%s'+eRed | |
6 | 10 |
7 def intsMaybe(ii): | 11 def intsMaybe(ii): |
8 return (int(i) for i in ii if IPAT.match(i)) | 12 return (int(i) for i in ii if IPAT.match(i)) |
9 | 13 |
10 def readHeaders(host,infile,skipColHdrs=True): | 14 def readHeaders(host,infile,skipColHdrs=True): |
11 l=infile.readline().rstrip() | 15 l=infile.readline().rstrip() |
12 ff=PPAT.split(l) | 16 ff=PPAT.split(l) |
13 (host.nr,host.ox,host.oy,host.oz)=intsMaybe(ff) | 17 (host.nr,host.ox,host.oy,host.oz)=intsMaybe(ff) |
14 host.et=ff[9] | 18 host.et=ff[9] |
15 l=infile.readline().rstrip() | 19 l=infile.readline().rstrip() |
16 (host.orad,host.ymin,host.ymax)=intsMaybe(PPAT.split(l)) | 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)) | |
17 if skipColHdrs: | 26 if skipColHdrs: |
18 _=infile.readline() | 27 _=infile.readline() |
19 | 28 |
20 def d(p1,p2): | 29 def d(p1,p2): |
21 dx=p1[0]-p2[0] | 30 dx=p1[0]-p2[0] |