Skip to content

When allocating dyn_const_array pre-calculate size to avoid line length limits - #724

Closed
jimmielin wants to merge 1 commit into
NCAR:developfrom
jimmielin:hplin/host_cap_dyn_const_line_limit
Closed

jimmielin wants to merge 1 commit into
NCAR:developfrom
jimmielin:hplin/host_cap_dyn_const_line_limit

Conversation

@jimmielin

Copy link
Copy Markdown
Contributor

[ 50 character, one line summary ]

Avoid syntax error in long dyn_const_array alloc.

[ Description of the changes in this commit. It should be enough
information for someone not following this development to understand.
Lines should be wrapped at about 72 characters. ]

When multiple schemes return dynamic constituents, the host cap generator
builds the allocate statement as a single long expression like:

allocate(tracer_data_test_dynamic_constituents(0+size(ozone_constituents)+size(aerosol_constituents)+size(volcaero_consti&
     tuents)))

This got chopped off mid-identifier, producing a syntax error.

Fix: compute the total size incrementally into num_dyn_consts
before the allocate, so no single line is long enough (hopefully!)
to trigger continuation:

num_dyn_consts = 0
num_dyn_consts = num_dyn_consts + size(ozone_constituents)
num_dyn_consts = num_dyn_consts + size(aerosol_constituents)
num_dyn_consts = num_dyn_consts + size(volcaero_constituents)
allocate(tracer_data_test_dynamic_constituents(num_dyn_consts))

I reset num_dyn_consts to 0 afterward for the packing loop so there is no logic
change downstream.

User interface changes?: No

Fixes: TBA

Testing:
test removed:
unit tests:
system tests:
manual testing: tested to work in CAM-SIMA where it previously was not

@climbfuji climbfuji left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks great to me, thanks for fixing the bug. I am ok with not creating a separate issue here, because it's all explained nicely in the PR description.

@climbfuji climbfuji added the capgen bugs, requests, etc. that involve ccpp_capgen label Mar 13, 2026

@peverwhee peverwhee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks @jimmielin

@gold2718

Copy link
Copy Markdown
Collaborator

While this PR fixes this particular problem, I feel the issue arises from a bug in the FortranWriter class. Thus, these syntax errors could still occur. I have submitted what I feel is a broader fix (#727) along with a unit-test modification that fails on the current develop branch. Note that this reproducer closely follows the example given in this PR.

@jimmielin

Copy link
Copy Markdown
Contributor Author

Thanks @gold2718, I agree #727 is a better fix. It looks good to me.

@climbfuji

Copy link
Copy Markdown
Collaborator

Should we close this as "superseded by #727" ?

@mkavulich

Copy link
Copy Markdown
Collaborator

superseded by #727

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capgen bugs, requests, etc. that involve ccpp_capgen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants