aboutsummaryrefslogtreecommitdiff
path: root/scripts/transfer-geom
blob: 6109f5ed117f07ae91e66184282130f6d82bbeba (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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()