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
13 count3
, count4
, count5
, count6
, count7
= 0,0,0,0,0
16 for line
in fileinput
.input():
18 # reset counters for each new expression
19 match
= re
.search(r
'=', line
)
21 count3
, count4
, count5
, count6
, count7
= 0,0,0,0,0
24 match
= re
.search(r
'tmpF\(3\)', line
)
27 line
= re
.sub(r
'\+ tmpF\(3\)\*',r
"#if 'w' >= 3\n\t + ", line
.rstrip())
29 replaced
= replaced
+ 1
31 line
= re
.sub(r
'\+ tmpF\(3\)\*',r
"+ ", line
.rstrip())
33 match
= re
.search(r
'tmpF\(4\)', line
)
36 line
= re
.sub(r
'\+ tmpF\(4\)\*',r
"#if 'w' >= 4\n\t + ", line
.rstrip())
38 replaced
= replaced
+ 1
40 line
= re
.sub(r
'\+ tmpF\(4\)\*',r
"+ ", line
.rstrip())
42 match
= re
.search(r
'tmpF\(5\)', line
)
45 line
= re
.sub(r
'\+ tmpF\(5\)\*',r
"#if 'w' >= 5\n\t + ", line
.rstrip())
47 replaced
= replaced
+ 1
49 line
= re
.sub(r
'\+ tmpF\(5\)\*',r
"+ ", line
.rstrip())
51 match
= re
.search(r
'tmpF\(6\)', line
)
54 line
= re
.sub(r
'\+ tmpF\(6\)\*',r
"#if 'w' >= 6\n\t + ", line
.rstrip())
56 replaced
= replaced
+ 1
58 line
= re
.sub(r
'\+ tmpF\(6\)\*',r
"+ ", line
.rstrip())
60 match
= re
.search(r
'tmpF\(7\)', line
)
63 line
= re
.sub(r
'\+ tmpF\(7\)\*',r
"#if 'w' >= 7\n\t + ", line
.rstrip())
65 replaced
= replaced
+ 1
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
)
73 line
= re
.sub(r
';',r
"\n\t#endif\n\t;", line
.rstrip())
75 line
= re
.sub(r
';',r
"\n\t#endif\n\t#endif\n\t;", line
.rstrip())
77 line
= re
.sub(r
';',r
"\n\t#endif\n\t#endif\n\t#endif\n\t;", line
.rstrip())
79 line
= re
.sub(r
';',r
"\n\t#endif\n\t#endif\n\t#endif\n\t#endif\n\t;", line
.rstrip())
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())
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())