Skip to content

Conversation

@gold2718
Copy link
Collaborator

@gold2718 gold2718 commented Aug 24, 2025

Add a new metadata table keyword, source_path, which allows a Fortran source file to be in a different directory from its metadata file. source_path is a path relative to the metadata file path.

User interface changes?: Yes
New optional metadata table keyword, source_path.
Backwards compatibility is maintained by using the metadata file path as the default value for the Fortran source path.

Testing:
test removed: none
unit tests: pass
system tests: pass (capgen test modified to test new feature)
manual testing: NA

Fixes #674
Fixes #676

@gold2718 gold2718 self-assigned this Aug 24, 2025
@gold2718 gold2718 added the capgen bugs, requests, etc. that involve ccpp_capgen label Aug 24, 2025
@gold2718
Copy link
Collaborator Author

I have a couple of questions about this PR:

  1. I'm not in love with the name, source_path. We now have relative_path (for dependencies) and source_path (for Fortran source files). Any ideas?
  2. When a metadata file has multiple tables, I am currently only checking the first one. Do we want to require (and check) that all the tables have the same source_path? Since there is supposed to be a single Fortran file or the metadata file, I'm not sure what we want here.

@climbfuji
Copy link
Collaborator

I have a couple of questions about this PR:

  1. I'm not in love with the name, source_path. We now have relative_path (for dependencies) and source_path (for Fortran source files). Any ideas?
  2. When a metadata file has multiple tables, I am currently only checking the first one. Do we want to require (and check) that all the tables have the same source_path? Since there is supposed to be a single Fortran file or the metadata file, I'm not sure what we want here.

I also have a couple of questions!

Regarding your question 1. Would it be too difficult to use/reuse/abuse the existing relative_path and just search for the Fortran source file that corresponds to the .meta file? We know that the name must be the same, all we need to do is search all paths in relative_path (since this is a list) for thismetadatafilewithoutfileending.fortranfileendigs. This would be a "new-in-capgen" thing, since we cannot break the assumption that Fortran and Metadata file are in separate directories in prebuild.

Regarding your question 2. How is capgen handling the relative_path entires for the multiple tables?

In general, the use case for this new functionality is to be able to add metadata files for code that we do not "own", e.g. when we pull in a physics scheme for an authoritative source as a submodule?

@gold2718
Copy link
Collaborator Author

I thought relative_path was for dependencies, are you sure it would not cause any issues to use it for the source file location? In particular, I'm worried about a case where there might be more than one file with the correct name. If you discount this, I could try to adapt my PR to do the search (and remove the new keyword).

@climbfuji
Copy link
Collaborator

I thought relative_path was for dependencies, are you sure it would not cause any issues to use it for the source file location? In particular, I'm worried about a case where there might be more than one file with the correct name. If you discount this, I could try to adapt my PR to do the search (and remove the new keyword).

I am fairly confident that there is currently no case where there is more than one file with the correct name, and it wouldn't be overly restrictive to make this a requirement?

@gold2718
Copy link
Collaborator Author

I am fairly confident that there is currently no case where there is more than one file with the correct name, and it wouldn't be overly restrictive to make this a requirement?

I've seen duplicate filenames in a number of projects. DART comes to mind. RRTMGP has two files named mo_gas_optics_rrtmgp_kernels.F90 (and possibly other duplicates, I did not check).

@climbfuji
Copy link
Collaborator

I am fairly confident that there is currently no case where there is more than one file with the correct name, and it wouldn't be overly restrictive to make this a requirement?

I've seen duplicate filenames in a number of projects. DART comes to mind. RRTMGP has two files named mo_gas_optics_rrtmgp_kernels.F90 (and possibly other duplicates, I did not check).

True, but if I understand this PR and the underlying issue correctly, the restrictions would apply to files that correspond to a CCPP scheme (i.e. a metadata file with a certain prefix) only? In other words, if mp_thompson.meta was looking for a Fortran file that contains the CCPP entry points for the Thompson microphysics scheme, we would require that there can only be one mp_thompson.{F90,F,f,f90} in any of the directories that mp_thompson.meta lists in relative_path?

@peverwhee
Copy link
Collaborator

@gold2718 @climbfuji

I'd vote for a separate (optional) metadata field as Steve implemented here, rather than extending the use of relative_path. It feels clearer and more explicit (i.e. the user has to specify explicitly where the source file is, which would hopefully encourage people to keep the metadata and source files together).

As for the name, I can't think of anything better than source_path myself. In a perfect world, I'd say we should rename relative_path, but I don't want to break existing, functioning metadata files.

@climbfuji
Copy link
Collaborator

relative_path is all over the place, but it can be changed easily witha recursive search and replace call. I'd rather rename relative_path to dependency_path or dependencies_path or something else that makes more sense when paired with source_path.

Copy link
Collaborator

@peverwhee peverwhee left a comment

Choose a reason for hiding this comment

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

one optional thing

if(DEFINED arg_VERBOSITY)
string(REPEAT "--verbose" ${arg_VERBOSITY} VERBOSE_PARAMS_SEPERATED)
separate_arguments(VERBOSE_PARAMS UNIX_COMMAND "${VERBOSE_PARAMS_SEPERATED}")
string(REPEAT "--verbose " ${arg_VERBOSITY} VERBOSE_PARAMS_SEPARATED)
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for fixing this!

dependencies = <dependencies>
module = <module name> # only needed if module name differs from filename
source_path = <relative source directory of Fortran source (if different)>
dynamic_constituent_routine = <routine name>
Copy link
Collaborator

Choose a reason for hiding this comment

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

oops! I know this is unrelated to your changes, but can you remove this residual dynamic constituents line left by me?

Copy link
Member

@dustinswales dustinswales 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.
Thanks for adding this functionality. It will come in handy for rte-rrtmgp!

@mkavulich mkavulich merged commit 903b314 into NCAR:develop Sep 15, 2025
19 checks passed
@gold2718 gold2718 deleted the different_fort_dir branch December 29, 2025 12:12
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 enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants