Skip to content

Throw clearer error message when integer dimension indices are present; remove known ddt case sensitivity#662

Merged
mkavulich merged 6 commits into
NCAR:developfrom
peverwhee:small-bugfixes
Jul 9, 2025
Merged

Throw clearer error message when integer dimension indices are present; remove known ddt case sensitivity#662
mkavulich merged 6 commits into
NCAR:developfrom
peverwhee:small-bugfixes

Conversation

@peverwhee
Copy link
Copy Markdown
Collaborator

@peverwhee peverwhee commented Jun 25, 2025

Add error handling for integer dimension indices; remove case sensitivity for known DDTs

Description

  • Updates to scripts/parse_tools/parse_checkers.py to append additional information to the error message when numerical indices are supplied for dimensions
  • In scripts/metadata_table.py, remove case sensitivity for known DDTs
  • Also fixes issue when a line is exactly equal to the max fortran line length and does not need to be continued.

User interface changes?: No

Closes #661 - numerical dimension indices error in capgen
Closes #664 - long standard name bug

Testing:
test removed: n/a
unit tests: all PASS, added two new doctests
system tests:
manual testing:

Copy link
Copy Markdown
Collaborator

@climbfuji climbfuji left a comment

Choose a reason for hiding this comment

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

This all looks reasonable to me, thanks for adding the doctests

Copy link
Copy Markdown
Collaborator

@mkavulich mkavulich 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 to me, just a minor fix suggestion

Comment thread scripts/parse_tools/parse_checkers.py Outdated
errmsg = "'{}' is an invalid dimension name"
raise CCPPError(errmsg.format(item))
if info_msg:
errmsg = f"'{item} is an invalid dimension name; {info_msg}"
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.

Suggested change
errmsg = f"'{item} is an invalid dimension name; {info_msg}"
errmsg = f"'{item}' is an invalid dimension name; {info_msg}"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

good catch! fixed!

Copy link
Copy Markdown
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.

I am confused by what is allowed and what is not. What purpose do integers serve and when are they allowed? Is this documented?

Comment thread scripts/fortran_tools/fortran_write.py Outdated
# in an ugly spot
best = self.__line_max - 1
if len(outstr) > best:
if len(outstr) > best + 1:
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.

Does this work if self.__line_max == 132 (Fortran maximum)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Looking into this more, I'm going to back this out and open an issue because it's more complicated than I thought (as you've noticed).

Due to quotation marks and indenting, when a standard name is

  1. 113 characters, I get an error trying to do line 218 of fortran_write.py - line_continue = outstr[best+1:].lstrip()[0] != '!'
  2. longer than 113 characters, the generated code for ccpp_physics_suite_variables tries to split the standard name string like:
            variable_list(3) =                                                                    &
                 'tendency_of_dry_air_enthalpy_at_constant_pressure_due_to_shortwave_radiation_adjusted_by_air_pressure_thicknesse&
&s'

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.

            variable_list(3) =                                                                    &
                 'tendency_of_dry_air_enthalpy_at_constant_pressure_due_to_shortwave_radiation_adjusted_by_air_pressure_thicknesse&
&s'

Is that not okay? I thought that is how you were supposed to split a character context across lines.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

oh! well, then, I suppose we're good on that front. i'm showing my fortran ignorance! so it's just the first issue that i'll look into a bit more tomorrow.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks again @gold2718

I took another stab at fixing the issue where the line is exactly equal to the max line length and doesn't need to be continued. If you have other ideas on how to fix it, I'm all ears!

Traceback (most recent call last):
CCPPError: '1:dim1 is an invalid dimension name; integer dimension indices not supported
>>> check_dimensions(["ccpp_constant_one:1", "dim2name"], None, True)
['ccpp_constant_one:1', 'dim2name']
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.

Why is this okay? Isn't 1 an integer dimension index?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

a valid question! The problem I ran into is that sometimes the parse checker is called after the "ccpp_constant_one:" is prepended to the integer dimension (which I believe we're allowing) and sometimes it's called before.

So, the metadata could specify dimensions = (2) and we'd end up calling check_dimensions on ccpp_constant_one:2

I thought about diving deeper into figuring out what the specifics were of when we're calling what, but decided that ccpp_constant_one:1 is the same as saying 1 and left it at that.

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.

Here is what is confusing: If "integer dimension indices not supported", how is the 1, an integer okay? Also, when did we decide it is okay to use integers for array extents?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

basically, it's only ok if you do ccpp_constant_one:1. any other use of integer indices isn't ok. And that's because of my earlier comment - to appease the checker.

As for when we started allowing integer sizes, i believe @dustinswales brought that in recently for his work in SCM - #652

@peverwhee peverwhee changed the title Throw clearer error message when integer dimension indices are present; two bugfixes Throw clearer error message when integer dimension indices are present; remove known ddt case sensitivity Jun 26, 2025
@peverwhee peverwhee requested a review from gold2718 June 27, 2025 16:18
Copy link
Copy Markdown
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.

I think this is okay. I wrote a test to check.

Add test for writing long strings
@mkavulich mkavulich merged commit 981eeae into NCAR:develop Jul 9, 2025
19 checks passed
@peverwhee peverwhee deleted the small-bugfixes branch November 18, 2025 23:42
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.

4 participants