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

Fix capgen Fortran parser to recognize nested subroutines/functions #424

Conversation

climbfuji
Copy link
Collaborator

Fixes #359 (#359).

The capgen Fortran parser is updated to know whether it is inside a contains section of a CCPP scheme. If so, the contents is ignored until an end subroutine scheme_name_ccpp_phase (e.g. end subroutine mp_thompson_run) is found.

Note that this fix requires that end subroutine statements are labeled with the subroutine name, i.e. subroutine mp_thompson_run requires the end statement to be end subroutine mp_thompson_run and not just end_subroutine). This has been a soft requirement for ccpp_prebuild.py, which warns users that an unlabeled end subroutine statement was found, but in must cases was able to proceed.

A more complicated solution that does not require labeled end subroutine statements would require counting the number of [begin] subroutine and end subroutine statements inside contains regions.

User interface changes?: No (since labeled end subroutine statements have been a soft requirement for ccpp_prebuild.py from the beginning)

Fixes #359.

Testing: The existing test of scheme temp_calc_adjust was extended to include a contains section in temp_calc_adjust_run. Without the changes to scripts/fortran_tools/parse_fortran_file.py in this PR, the capgen test for this scheme failed. After making the changes suggested here, all tests pass (cd tests && ./run_test.sh).

@gold2718
Copy link
Collaborator

gold2718 commented Jan 4, 2022

I'm not sure I believe your assertion that the end subroutine statement needs to label.
I will submit a PR to your branch demonstrating this.

…ntains

Do not require label on end subroutine statement
Copy link
Collaborator

@gold2718 gold2718 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@climbfuji climbfuji changed the base branch from main to feature/capgen January 4, 2022 21:07
@climbfuji climbfuji merged commit e88f77a into NCAR:feature/capgen Jan 4, 2022
@climbfuji climbfuji deleted the fix_parsing_nested_subroutines_contains branch June 27, 2022 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fortran parser not recognizing nested subroutines/functions
2 participants