3 autoEdit - A Python tool to automatically edit a set of files
4 according to the specified user rules:
20 patt_modules = re.compile(
r"(\s*use\s*\w*)(_b)\s*")
21 patt_module = re.compile(
r"\s*module\s\w*")
22 patt_module_start = re.compile(
"(\s*module\s)(\w*)(_b)\s*")
23 patt_module_end = re.compile(
"(\s*end module\s)(\w*)(_b)\s*")
25 re.compile(
r"(\s*call pushreal8)"),
26 re.compile(
r"(\s*call popreal8)"),
27 re.compile(
r"(\s*call pushinteger4)"),
28 re.compile(
r"(\s*call popinteger4)"),
30 patt_pushcontrol1b = re.compile(
r"(\s*call pushcontrol1b\()(.*)\)")
31 patt_popcontrol1b = re.compile(
r"(\s*call popcontrol1b\()(.*)\)")
32 patt_subroutine = re.compile(
r"\s*subroutine\s\w*")
33 patt_subend = re.compile(
r"\s*end\s*subroutine")
34 patt_comment = re.compile(
r"\s*!.*")
35 patt_inttype = re.compile(
r"\s*integer\*4\s\w*")
37 print(
"Directory of input source files :", DIR_ORI)
38 print(
"Directory of output source files :", DIR_MOD)
45 "initializeflow_fast_b",
49 "surfaceintegrations_fast_b",
50 "turbbcroutines_fast_b",
53 "walldistance_fast_b",
57 "adjointExtra_fast_b.f90",
59 "oversetUtilities_fast_b.f90",
60 "zipperIntegrations_fast_b.f90",
61 "actuatorRegion_fast_b.f90",
64 for f
in os.listdir(DIR_ORI):
65 if f
not in FILE_IGNORE
and f.endswith(EXT):
67 file_object_ori = open(os.path.join(DIR_ORI, f),
"r")
68 print(
"\nParsing input file", file_object_ori.name)
72 file_object_ori.seek(0)
79 for line
in file_object_ori:
81 if patt_module.match(line):
83 if patt_subroutine.match(line):
87 if isModule
and not hasSubroutine:
88 file_object_ori.close()
90 elif isModule
and hasSubroutine:
92 f = f.replace(
"_b",
"_b")
95 file_object_mod = open(os.path.join(DIR_MOD, f),
"w")
101 file_object_ori.seek(0)
104 for line
in file_object_ori:
110 line = line.replace(
"_cb",
"")
114 m = patt_modules.match(line)
117 for m
in useful_modules:
121 line = line.replace(
"_b",
"_b", 1)
123 line = line.replace(
"_fast_b",
"")
126 m = patt_pushcontrol1b.match(line)
129 line =
"myIntPtr = myIntPtr + 1\n myIntStack(myIntPtr) = %s\n" % num
132 m = patt_popcontrol1b.match(line)
135 line =
"%s = myIntStack(myIntPtr)\n myIntPtr = myIntPtr - 1\n" % num
140 m = patt_inttype.match(line)
142 line = line.replace(
"integer*4",
"integer")
154 if not f.lower() ==
"bcroutines_b.f90":
155 for p
in del_patterns:
160 if patt_subroutine.match(line)
and "inviscidupwindflux_fast_b" in line:
164 if inSubroutine
and "use flowutils_fast_b, only : etot" in line:
165 line = line.strip(
"\n") +
", etot_fast_b\n"
167 if patt_subend.match(line):
171 file_object_mod.write(line)
174 file_object_ori.close()
175 file_object_mod.close()
178 print(
" Modified file saved", file_object_mod.name)