diff options
author | Thomas White <taw@physics.org> | 2018-11-13 14:14:44 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2018-11-13 14:14:44 +0100 |
commit | 71f4e6a5752f6586ec83a8c9606b100f2fe497fb (patch) | |
tree | e943dd39bb33493edc60b49d79bebdb0dcbb76fb /scripts/transfer-geom | |
parent | 7c89d56e87a24877fd07d515b70051c141ad62d8 (diff) |
Add some new scripts
Diffstat (limited to 'scripts/transfer-geom')
-rwxr-xr-x | scripts/transfer-geom | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/scripts/transfer-geom b/scripts/transfer-geom new file mode 100755 index 00000000..6109f5ed --- /dev/null +++ b/scripts/transfer-geom @@ -0,0 +1,91 @@ +#!/usr/bin/python3 + +import sys + +corner_x = dict() +corner_y = dict() +fs = dict() +ss = dict() +coffset = dict() + +# Go through "ingeom" and find all corner_{x,y}/fs/ss/coffset lines +with open(sys.argv[1]) as ingeom: + while True: + line = ingeom.readline() + if not line: + break + line = line.rstrip("\r\n") + slash = line.find("/") + if slash != -1: + panel = line[0:slash] + else: + panel = None + if line.find("/corner_x") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + corner_x[panel] = line.split(" = ")[1] + if line.find("/corner_y") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + corner_y[panel] = line.split(" = ")[1] + if line.find("/fs") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + fs[panel] = line.split(" = ")[1] + if line.find("/ss") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + ss[panel] = line.split(" = ")[1] + if line.find("/coffset") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + coffset[panel] = line.split(" = ")[1] + +# Go through "template", and replace all corner_{x,y}/fs/ss lines from memory +out = open(sys.argv[3], "w") +with open(sys.argv[2]) as template: + while True: + line = template.readline() + if not line: + break + line = line.rstrip("\r\n") + slash = line.find("/") + if slash != -1: + panel = line[0:slash] + else: + panel = None + if line.find("/corner_x") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + out.write("%s/corner_x = %s\n" % (panel, corner_x[panel])) + elif line.find("/corner_y") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + out.write("%s/corner_y = %s\n" % (panel, corner_y[panel])) + elif line.find("/fs") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + out.write("%s/fs = %s\n" % (panel, fs[panel])) + elif line.find("/ss") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + out.write("%s/ss = %s\n" % (panel, ss[panel])) + elif line.find("/coffset") != -1: + if not panel: + print("No panel for line: %s\n" % line) + sys.exit(1) + out.write("%s/coffset = %s\n" % (panel, coffset[panel])) + else: + out.write("%s\n" % line) + +out.close() + |