Skip to content

Conversation

@gold2718
Copy link
Collaborator

  • Added UseStatement type, test for unknown DDT
  • Add space between --verbose inputs
  • Check for imported type before raising an invalid Fortran type error

User interface changes?: No

Testing:

  • unit tests: PASS
  • system tests: PASS
    • added inline DDT plus DDT from another file as undocumented (no metadata) member variables of vmr_type in capgen_test.

Added UseStatement type, test for unknown DDT
Add space between --verbose inputs
Check for imported type before raising an invalid Fortran type error
@gold2718 gold2718 added the bugfix Fix for issue with 'bug' label. label Sep 15, 2025
@gold2718
Copy link
Collaborator Author

Alternative to #673

else:
scheme_args = list()
# End if
# end if
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that the changes in this file are mostly unrelated to this PR, I am wondering if we should do one pass of the codebase to convert all these "end block" comments to lowercase in its own PR.

emsg = "{}: {}"
raise ParseSyntaxError(emsg.format(lname, cperr),
context=self.context) from cperr
# Raise this error unless it represents an imported DDT type
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do I understand correctly that this will allow us to import DDTs from some other module if we use

   use mpi_f08, only : mpi_comm

but it will still fail if we do

   use mpi_f08

?

Copy link
Collaborator

Choose a reason for hiding this comment

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

my understanding is that

use mpi_f08

is still allowed, but if you're trying to do something like:

use ddt_library

type(ty_ddt_from_ddt_library) :: ddt_from_ddt_library

you'll get a parsing error because the framework has no way of knowing if "ty_ddt_from_ddt_library" is defined within "ddt_library"

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 small request

emsg = "{}: {}"
raise ParseSyntaxError(emsg.format(lname, cperr),
context=self.context) from cperr
# Raise this error unless it represents an imported DDT type
Copy link
Collaborator

Choose a reason for hiding this comment

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

my understanding is that

use mpi_f08

is still allowed, but if you're trying to do something like:

use ddt_library

type(ty_ddt_from_ddt_library) :: ddt_from_ddt_library

you'll get a parsing error because the framework has no way of knowing if "ty_ddt_from_ddt_library" is defined within "ddt_library"

@climbfuji
Copy link
Collaborator

I am wondering if a different approach altogether would be better, not just but also given the limitations that we can't use use mpi_f08 etc without listing all the symbols. Do you think the following would work?

In the metadata header for a scheme:

...
[ccpp-table-properties]
  name = mp_thompson
  type = scheme
  dependencies = machine.F,module_mp_radar.F90,module_mp_thompson.F90,module_mp_thompson_make_number_concentrations.F90
  external_types = my_type_a, my_type_b
...

@gold2718
Copy link
Collaborator Author

I am wondering if a different approach altogether would be better, not just but also given the limitations that we can't use use mpi_f08 etc without listing all the symbols. Do you think the following would work?

In the metadata header for a scheme:

...
[ccpp-table-properties]
  name = mp_thompson
  type = scheme
  dependencies = machine.F,module_mp_radar.F90,module_mp_thompson.F90,module_mp_thompson_make_number_concentrations.F90
  external_types = my_type_a, my_type_b
...

This could be an additional method for models that allow naked use statements. CESM/CAM coding standards and NorESM coding standards do not allow naked use statements.

@climbfuji
Copy link
Collaborator

I am wondering if a different approach altogether would be better, not just but also given the limitations that we can't use use mpi_f08 etc without listing all the symbols. Do you think the following would work?
In the metadata header for a scheme:

...
[ccpp-table-properties]
  name = mp_thompson
  type = scheme
  dependencies = machine.F,module_mp_radar.F90,module_mp_thompson.F90,module_mp_thompson_make_number_concentrations.F90
  external_types = my_type_a, my_type_b
...

This could be an additional method for models that allow naked use statements. CESM/CAM coding standards and NorESM coding standards do not allow naked use statements.

I would be ok with requiring this, but I didn't expect CESM/CAM to be on board with that.

Some models end up with long use statements, though. Real world example:

  use mpi_f08, only : mpi_comm, mpi_comm_null, mpi_info, mpi_datatype, mpi_request, &
                      mpi_status, mpi_max_error_string, mpi_logical, mpi_character, &
                      mpi_sum, mpi_integer, mpi_integer8, mpi_byte, mpi_min, mpi_max, &
                      mpi_real, mpi_2real, mpi_minloc, mpi_maxloc, mpi_thread_funneled, &
                      mpi_comm_world, mpi_success, mpi_info_null, mpi_errors_return, &
                      mpi_datatype_null

@gold2718
Copy link
Collaborator Author

I am wondering if a different approach altogether would be better, not just but also given the limitations that we can't use use mpi_f08 etc without listing all the symbols. Do you think the following would work?
In the metadata header for a scheme:

...
[ccpp-table-properties]
  name = mp_thompson
  type = scheme
  dependencies = machine.F,module_mp_radar.F90,module_mp_thompson.F90,module_mp_thompson_make_number_concentrations.F90
  external_types = my_type_a, my_type_b
...

This could be an additional method for models that allow naked use statements. CESM/CAM coding standards and NorESM coding standards do not allow naked use statements.

I would be ok with requiring this, but I didn't expect CESM/CAM to be on board with that.

Some models end up with long use statements, though. Real world example:

  use mpi_f08, only : mpi_comm, mpi_comm_null, mpi_info, mpi_datatype, mpi_request, &
                      mpi_status, mpi_max_error_string, mpi_logical, mpi_character, &
                      mpi_sum, mpi_integer, mpi_integer8, mpi_byte, mpi_min, mpi_max, &
                      mpi_real, mpi_2real, mpi_minloc, mpi_maxloc, mpi_thread_funneled, &
                      mpi_comm_world, mpi_success, mpi_info_null, mpi_errors_return, &
                      mpi_datatype_null

Some times the long statements are a pain but in CAM, another SHOULD rule (see the same link) tries to help: "use statements should be brought in at the smallest scope possible (e.g. inside individual subroutines instead of at the module level)".

@climbfuji
Copy link
Collaborator

I am wondering if a different approach altogether would be better, not just but also given the limitations that we can't use use mpi_f08 etc without listing all the symbols. Do you think the following would work?
In the metadata header for a scheme:

...
[ccpp-table-properties]
  name = mp_thompson
  type = scheme
  dependencies = machine.F,module_mp_radar.F90,module_mp_thompson.F90,module_mp_thompson_make_number_concentrations.F90
  external_types = my_type_a, my_type_b
...

This could be an additional method for models that allow naked use statements. CESM/CAM coding standards and NorESM coding standards do not allow naked use statements.

I would be ok with requiring this, but I didn't expect CESM/CAM to be on board with that.
Some models end up with long use statements, though. Real world example:

  use mpi_f08, only : mpi_comm, mpi_comm_null, mpi_info, mpi_datatype, mpi_request, &
                      mpi_status, mpi_max_error_string, mpi_logical, mpi_character, &
                      mpi_sum, mpi_integer, mpi_integer8, mpi_byte, mpi_min, mpi_max, &
                      mpi_real, mpi_2real, mpi_minloc, mpi_maxloc, mpi_thread_funneled, &
                      mpi_comm_world, mpi_success, mpi_info_null, mpi_errors_return, &
                      mpi_datatype_null

Some times the long statements are a pain but in CAM, another SHOULD rule (see the same link) tries to help: "use statements should be brought in at the smallest scope possible (e.g. inside individual subroutines instead of at the module level)".

Not possible in this case, unfortunately. Support for Fortran submodules is limited with certain compilers.

@peverwhee peverwhee self-requested a review October 1, 2025 17:37
@climbfuji
Copy link
Collaborator

Coming back to this, if we decide that we require named module use statements for imported DDTs to work, then we need to update the documentation accordingly. I prefer to not add an alternative solution as I suggested previously in this case. We can do that if the need arises. @mkavulich FYI (you are our doc master)

@peverwhee
Copy link
Collaborator

@mkavulich @climbfuji can this be merged or do we need to update the documentation first?

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

I'll go ahead and merge this PR...the documentation/rule changes will need some more discussion (i.e. I'll need help from more knowledgeable people) since, from a brief review of the ccpp-physics code, there are many examples of these bare use statements, not just use mpi_f08.

@mkavulich mkavulich merged commit 37db348 into NCAR:develop Oct 15, 2025
19 checks passed
@gold2718 gold2718 deleted the check_use_statements 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

bugfix Fix for issue with 'bug' label.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants