Provide convenience methods for Fortran interface #47
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed in MESSy that the current Fortran bindings might be hard to use for people not familiar with C-style programming or calling C functions from Fortran. Specifically, the use of
trim(adjustl(string)) // c_null_charfor string arguments such as(source) or the awkward comparison of boolean-intent return values against
0/1such as(source).
This PR changes the Fortran bindings to our C API such that all subroutines/functions that expect a string argument can now be supplied a regular Fortran string (i.e., a scalar of type
character) and do the necessary conversions (trimming, appendingnull) internally. Similarly, functions expecting/returning a boolean value in the form of an integer (C-style booleans) now will work with Fortranlogicals. Thus, the above two snippets can now be written asCALL trixi_initialize(trixi_runtime_path)and
For full control/as a fallback, the original functions/subroutines are available with a
_cprefix, e.g., the Fortran subroutinejulia_eval_string_cwill directly call the C functionjulia_eval_string, while the Fortran subroutinejulia_eval_stringwill exhibit the convenience behavior described above an internally calljulia_eval_string_c.Please let me know what you think about this @bgeihe @KerstinHartung, since I am not sure if this makes it easier to use libtrixi for Fortran or is just another source of confusion. (Note that we do not have any documentation of the official API yet, so please do not hold this against this PR 😬)