3 header_str =
""" pyf_processor.py is used to automatically process a
4 particular form of pyf file that allows the specification of both the
5 real and complex wrapping functions in one place. This is eliminates
6 duplication in the pyf files.
8 pyf_processor.py is called in the following manner:
10 python pyf_processor.py <real|complex> <pyf_file>
12 The resulting "clean" pyf file is written to pyf_file.autogen. This
13 .autogen file is what should be passed to f2py to generate the actual
17 if len(sys.argv) != 3:
22 if sys.argv[1]
in [
"real",
"complex"]:
30 f = open(sys.argv[2],
"r")
31 orig_lines = f.readlines()
33 print(
"Error opening/reading pyf file!")
38 g = open(sys.argv[2] +
".autogen",
"w")
41 g.write(
"!" +
"#" * 78 +
"!" +
"\n")
42 g.write(
"!" +
" " * 27 +
"DO NOT MODIFY THIS FILE!" +
" " * 27 +
"!" +
"\n")
43 g.write(
"!" +
" " * 27 +
"MODIFY adflow.pyf INSTEAD!" +
" " * 27 +
"!" +
"\n")
44 g.write(
"!" +
"#" * 78 +
"!" +
"\n")
48 for i
in range(len(orig_lines)):
49 if "#ifdef USE_COMPLEX" in orig_lines[i]:
51 elif "#ifndef USE_COMPLEX" in orig_lines[i]:
53 elif "#else" in orig_lines[i]:
55 if cur_mode ==
"complex":
57 elif cur_mode ==
"real":
60 print(
"Error occured. Mismatched #else statement")
63 elif "#endif" in orig_lines[i]:
67 if cur_mode ==
"both" or cur_mode == mode:
69 if "kind=inttype" in orig_lines[i]:
70 orig_lines[i] = orig_lines[i].replace(
"kind=inttype",
"kind=4")
72 if "real(kind=realtype)" in orig_lines[i]:
74 orig_lines[i] = orig_lines[i].replace(
"kind=realtype",
"kind=8")
76 orig_lines[i] = orig_lines[i].replace(
"real(kind=realtype)",
"complex(kind=8)")
78 if "real(kind=alwaysrealtype)" in orig_lines[i]:
79 orig_lines[i] = orig_lines[i].replace(
"kind=alwaysrealtype",
"kind=8")
82 g.write(orig_lines[i])