Allow declaration of a scheme-dependent kind#719
Conversation
kind declaration now available in a metadata_table header. Add test to the capgen system test (test/capgen_test)
|
This PR is an alternative to #713 |
|
I'm not in love with the syntax I am using in the How do folks feel about this? I thought about at least distinguishing the module name with different syntax which would make it easier to check. Something like: or Thoughts? |
gold2718
left a comment
There was a problem hiding this comment.
A comment and a few changes based on test output warnings.
| '.true.', '.false.', '.lt.', '.le.', '.eq.', '.ge.', '.gt.', '.ne.', | ||
| '.not.', '.and.', '.or.', '.xor.'] | ||
| FORTRAN_CONDITIONAL_REGEX = re.compile(r"[\w']+|" + "|".join([word.replace('(','\(').replace(')', '\)') for word in FORTRAN_CONDITIONAL_REGEX_WORDS])) | ||
| FORTRAN_CONDITIONAL_REGEX = re.compile(r"[\w']+|" + "|".join([word.replace('(',r'\(').replace(')', r'\)') for word in FORTRAN_CONDITIONAL_REGEX_WORDS])) |
There was a problem hiding this comment.
Changed due to warnings in the test output.
|
|
||
| _UNITLESS_REGEX = "1" | ||
| _NON_LEADING_ZERO_NUM = "[1-9]\d*" | ||
| _NON_LEADING_ZERO_NUM = r"[1-9]\d*" |
There was a problem hiding this comment.
Changed due to warnings in the test output.
| _UNIT_EXPONENT = f"({_NEGATIVE_NON_LEADING_ZERO_NUM}|{_POSITIVE_NON_LEADING_ZERO_NUM}|{_NON_LEADING_ZERO_NUM})" | ||
| _UNIT_REGEX = f"[a-zA-Z]+{_UNIT_EXPONENT}?" | ||
| _UNITS_REGEX = f"^({_CHAR_WITH_UNDERSCORE}|{_UNIT_REGEX}(\s{_UNIT_REGEX})*|{_UNITLESS_REGEX})$" | ||
| _UNITS_REGEX = rf"^({_CHAR_WITH_UNDERSCORE}|{_UNIT_REGEX}(\s{_UNIT_REGEX})*|{_UNITLESS_REGEX})$" |
There was a problem hiding this comment.
Changed due to warnings in the test output.
scripts/ccpp_capgen.py
Outdated
| msg = f'Writing {KINDS_FILENAME} to {output_dir}' | ||
| run_env.logger.info(msg) |
There was a problem hiding this comment.
This was a change that @nusbaume made. I never saw a response as to why this is a good change. Should I set it back?
There was a problem hiding this comment.
Sorry, I was assuming it would be reverted so I didn't comment on it in the previous PR, but this change was leftover from some debugging I was doing, and I just missed it when cleaning up afterwards (I have been training my brain to default to f-strings so this happens more than I care to admit).
So I am personally happy if this gets reverted. Thanks for checking though!
| e.g., --kind-type "kind_phys=REAL64" | ||
| Enter more than one --kind-type entry to define multiple CCPP kinds. | ||
| <kind_val> SHOULD be a valid ISO_FORTRAN_ENV type""") | ||
| <kind_val> MUST be a valid ISO_FORTRAN_ENV type""") |
There was a problem hiding this comment.
This rule only applies on the command line.
climbfuji
left a comment
There was a problem hiding this comment.
My immediate thought is that the kind_spec syntax would be more intuitive if it followed the Fortran syntax. For example:
use temp_kinds, only: kind_temp => temp_r8
could be
kind_spec = temp_kinds:kind_temp=>temp_r8
and
use temp_kinds, only: temp_r8
could be
kind_spec = temp_kinds:temp_r8
| 'suites':''}, \ | ||
| kind_types=["kind_phys=REAL64", \ | ||
| "kind_dyn=REAL32", \ | ||
| "kind_dyn=REAL32", \ |
There was a problem hiding this comment.
| "kind_dyn=REAL32", \ | |
| "kind_dyn=REAL32", \ |
| 'suites':''}, \ | ||
| kind_types=["kind_phys=REAL64", \ | ||
| "kind_dyn=REAL32", \ | ||
| "kind_dyn=REAL32", \ |
There was a problem hiding this comment.
| "kind_dyn=REAL32", \ | |
| "kind_dyn=REAL32", \ |
I agree with this proposal. The original format is really hard to get correct. |
|
@gold2718 - I brought your branch into my code which needs this fix and it works great. So from a proof-of-concept review, I give my approval. I'll let someone else on my team do the official "code review" review. |
- Modified the syntax for new-kind declaration as suggested by @climbfuji - Reverted string formatting for log message
Well, it's 3-0 so I went ahead and implemented this change. Thanks for the suggestion! |
Co-authored-by: Dom Heinzeller <dom.heinzeller@icloud.com>
Co-authored-by: Dom Heinzeller <dom.heinzeller@icloud.com>
@gold2718 - Could you edit the description at the top of this PR to reflect this new syntax (so when we refer back to it we get the correct way to implement it)? Thanks! |
|
@dustinswales can you review this when you get time? |
dustinswales
left a comment
There was a problem hiding this comment.
Sorry for the late review!
There are two ways to use the new keyword:
kind_spec = temp_kinds:kind_temp=>temp_r8Results in an entry in ccpp_kinds.F90:
use temp_kinds, only: kind_temp => temp_r8kind_spec = temp_kinds:temp_r8Results in an entry in ccpp_kinds.F90:
use temp_kinds, only: temp_r8In both cases, the Fortran module file (temp_kinds.F90) SHOULD be added as a dependency in the
same metadata table header.
User interface changes?: Yes
A new metadata keyword
Fixes: #712
Testing:
unit tests: all PASS
system tests: all PASS