NptJregs: Avoid loading weights higher than requested
[BGap.git] / NptJregs / add_conditionals.py
blob7315c6ec6e0341c3f39447c1229aeccf2194747f
1 # Python script to modify the NptJregs.h files to avoid loading
2 # the terms containing zeta's of weight higher than specified in
3 # the call to BGexpand(weight)
5 # This is how it was used:
6 # python add_conditionals.py 6ptJregs.h > 6ptJregs-new.h
8 # After deciding 6ptJregs-new.h is OK, rename it to 6ptJregs.h etc
10 import fileinput
11 import re
13 count3, count4, count5, count6, count7 = 0,0,0,0,0
14 replaced = 0
16 for line in fileinput.input():
18 # reset counters for each new expression
19 match = re.search(r'=', line)
20 if match:
21 count3, count4, count5, count6, count7 = 0,0,0,0,0
22 replaced = 0
24 match = re.search(r'tmpF\(3\)', line)
25 if match:
26 if count3 == 0:
27 line = re.sub(r'\+ tmpF\(3\)\*',r"#if 'w' >= 3\n\t + ", line.rstrip())
28 count3 = count3 + 1
29 replaced = replaced + 1
30 else:
31 line = re.sub(r'\+ tmpF\(3\)\*',r"+ ", line.rstrip())
33 match = re.search(r'tmpF\(4\)', line)
34 if match:
35 if count4 == 0:
36 line = re.sub(r'\+ tmpF\(4\)\*',r"#if 'w' >= 4\n\t + ", line.rstrip())
37 count4 = count4 + 1
38 replaced = replaced + 1
39 else:
40 line = re.sub(r'\+ tmpF\(4\)\*',r"+ ", line.rstrip())
42 match = re.search(r'tmpF\(5\)', line)
43 if match:
44 if count5 == 0:
45 line = re.sub(r'\+ tmpF\(5\)\*',r"#if 'w' >= 5\n\t + ", line.rstrip())
46 count5 = count5 + 1
47 replaced = replaced + 1
48 else:
49 line = re.sub(r'\+ tmpF\(5\)\*',r"+ ", line.rstrip())
51 match = re.search(r'tmpF\(6\)', line)
52 if match:
53 if count6 == 0:
54 line = re.sub(r'\+ tmpF\(6\)\*',r"#if 'w' >= 6\n\t + ", line.rstrip())
55 count6 = count6 + 1
56 replaced = replaced + 1
57 else:
58 line = re.sub(r'\+ tmpF\(6\)\*',r"+ ", line.rstrip())
60 match = re.search(r'tmpF\(7\)', line)
61 if match:
62 if count7 == 0:
63 line = re.sub(r'\+ tmpF\(7\)\*',r"#if 'w' >= 7\n\t + ", line.rstrip())
64 count7 = count7 + 1
65 replaced = replaced + 1
66 else:
67 line = re.sub(r'\+ tmpF\(7\)\*',r"+ ", line.rstrip())
69 # We need to write a matching number of #endif's at the end of the expression
70 match = re.search(r';', line)
71 if match:
72 if replaced == 1:
73 line = re.sub(r';',r"\n\t#endif\n\t;", line.rstrip())
74 if replaced == 2:
75 line = re.sub(r';',r"\n\t#endif\n\t#endif\n\t;", line.rstrip())
76 if replaced == 3:
77 line = re.sub(r';',r"\n\t#endif\n\t#endif\n\t#endif\n\t;", line.rstrip())
78 if replaced == 4:
79 line = re.sub(r';',r"\n\t#endif\n\t#endif\n\t#endif\n\t#endif\n\t;", line.rstrip())
80 if replaced == 5:
81 line = re.sub(r';',r"\n\t#endif\n\t#endif\n\t#endif\n\t#endif\n\t#endif\n\t;", line.rstrip())
82 if replaced == 6:
83 line = re.sub(r';',r"\n\t#endif\n\t#endif\n\t#endif\n\t#endif\n\t#endif\n\t#endif\n\t;", line.rstrip())
85 print(line.rstrip())