Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C interface #276

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions scripts/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def get_public(fortran_code):


def transform_fortran_file(filename):

subroutine_re = re.compile(r'subroutine\s+([a-zA-Z0-9_]+)\s*\(([\s\S]*)\)', re.DOTALL)

# use to find the argument names of each subroutine
argument_re = re.compile(r'(real\(8\)|real\(dp\)|real\(PREC\)|integer|logical|type\(bml_matrix_t\)|character\(\d+\)|character\(len=\*\))(,.+?)?\s+::\s+([a-zA-Z0-9_,\s\(\):]+)')

Expand Down Expand Up @@ -65,6 +68,7 @@ def transform_fortran_file(filename):
"type(bml_matrix_t)": "bml_matrix_t*",
"integer": "int",
"character(len=*)":"char*",
"character(100)":"char*",
"character(10)":"char*",
"character(20)":"char*",
"character(50)":"char*",
Expand Down Expand Up @@ -92,6 +96,11 @@ def transform_fortran_file(filename):
line = line.replace("\n","").strip()
line = line + content[k+1].strip()
line = line.replace("&", "")
if "&" in content[k+1]:
line = line.replace("\n","").strip()
line = line + content[k+2].strip()
line = line.replace("&", "")

match = subroutine_re.match(line.strip())
if match:
subroutine_name = match.group(1)
Expand All @@ -103,8 +112,8 @@ def transform_fortran_file(filename):


ispublic = subroutine_name in public_subroutines
print(f"\ndebug-zy: a subroutine {subroutine_name} is found!", ispublic)
print(f"debug-zy: its arguments are: {argument_names}")
print(f"\nA subroutine {subroutine_name} is found!", ispublic)
print(f"Its arguments are: {argument_names}")
# skip the subroutine if it's not public
if not ispublic: continue
is_inside_subroutine = True
Expand Down
Loading