Skip to content

Fix for multiply occurring nml options in active_when attribute#1461

Open
abishekg7 wants to merge 1 commit into
MPAS-Dev:developfrom
abishekg7:framework/fix_duplicate_activewhen
Open

Fix for multiply occurring nml options in active_when attribute#1461
abishekg7 wants to merge 1 commit into
MPAS-Dev:developfrom
abishekg7:framework/fix_duplicate_activewhen

Conversation

@abishekg7
Copy link
Copy Markdown
Collaborator

@abishekg7 abishekg7 commented May 27, 2026

Problem

When declaring a package with the optional active_when attribute in Registry.xml, if a namelist option appeared more than once in an active_when attribute (e.g., config_foo > 0 .and. config_foo < 10), the code generation logic in gen_inc.c would produce duplicate Fortran variable declarations and mpas_pool_get_config calls in the generated setup_packages.inc. This caused compiler errors associated the generated code.

Solution

The solution involves modifying the logic in package_logic_routine and gen_pkg_debug_info in gen_inc.c to identify unique namelist options in the active_when attributes.

This PR introduces a simple helper function, add_unique_key_to_list, to add unique namelist options to a string list. This list is then iterated over by subsequent logic in order to ensure that there are no multiply defined variables in the generated Fortran code.

Presently, the MAX_LIST_SIZE macro caps the maximum number of unique namelist options allowed in the active_when attribute at 20.

Comment thread src/tools/registry/gen_inc.c Outdated
Comment thread src/tools/registry/gen_inc.c Outdated
Comment thread src/tools/registry/gen_inc.c Outdated
Comment thread src/tools/registry/gen_inc.c Outdated
@mgduda mgduda self-requested a review May 28, 2026 20:52
Comment thread src/tools/registry/gen_inc.c Outdated
Comment thread src/tools/registry/gen_inc.c Outdated
Comment thread src/tools/registry/gen_inc.c Outdated
Copy link
Copy Markdown
Contributor

@mgduda mgduda left a comment

Choose a reason for hiding this comment

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

I added just two minor comments, and otherwise, I think this is ready to go as an open PR after tidying up the commit history and adding a PR description.

Comment thread src/tools/registry/gen_inc.c Outdated
Comment thread src/tools/registry/gen_inc.c Outdated
This commit addresses the compiler errors that occur with the generated code
when a namelist option appears more than once in an active_when attribute in a
package definition in Registry.xml. e.g., config_foo > 0 .and. config_foo < 10.

The solution involves modifying the logic in package_logic_routine and
gen_pkg_debug_info in src/tools/registry/gen_inc.c to identify the unique
namelist options in the active_when attributes.

This commit introduces a simple helper function, add_unique_key_to_list, to add
unique namelist options to a string list. This list is then iterated over by
subsequent logic in order to ensure that there are no multiply defined
variables in the generated Fortran code.

Presently, the MAX_LIST_SIZE macro caps the maximum number of unique namelist
options allowed in the active_when attribute at 20.
@abishekg7 abishekg7 force-pushed the framework/fix_duplicate_activewhen branch from aa98712 to 3a8e802 Compare May 29, 2026 17:22
@abishekg7 abishekg7 marked this pull request as ready for review May 29, 2026 17:23
@abishekg7
Copy link
Copy Markdown
Collaborator Author

Addressed the last two comments and squashed to a single commit. I think the change set is small enough for one commit, but can also move the new function definition to its separate commit.

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.

2 participants