Fix type handling of Fortran BMI adapter#915
Conversation
Fixing get_analogous_cxx_type and correcting getter/setter functions to properly consider both the type name string and the item size of a BMI module variable in handling the analogous internal typing, since Fortran type sizes (and thus the required analogous C++ type) can be changed by compiler settings. Also, since corrected getter/setter implementation relied on nested calls to non-inner get_analogous_cxx_type method, moving the getter/setter logic to be directly within GetValue/SetValue methods.
|
This sounds like a nice change. Did the case(s) in question come up with one of the BMI models we have at hand? |
Indirectly. As part of the SacSMA mass balance issue investigation, one of the things that was tried was changing the precision of That said, it may be the case that ISO_C_BINDING middleware also doesn't play nicely with such precision changes ... I'm still doing some testing. But accounting for variable type size changes at the adapter level may turn out to be moot unless the middleware is also updated. |
The existing BMI adapter for Fortran modules will not behave correctly in situations when the size of Fortran types is modified from the "standard" expected size. This is because the adapter does not ask the module directly for variable item sizes when deciding what corresponding type to use for values inside the framework.
For example, consider this method from Bmi_Fortran_Adapter:
The adapter only asks for a variable's type and assumes the appropriate item size strictly based on the type name string: e.g., that an advertised
integerwill be the same size as a C++int. This is not guaranteed to be correct, as type resizing can be done at compile time, using flags like gfortran's-fdefault-real-8.Changes
get_analogous_cxx_typeto get the C++ type corresponding to not just the category (i.e., integer, float) but also the memory size of a variableget_analogous_cxx_typefor determining how types should be handledGetValue/SetValueimplementations, since updated implementations now violated the intended premise of "inner" functions for the class.Testing
Existing unit tests pass as they did previously(actually, they are ... there are a few failing (though seemingly unrelated) tests ... I'm investigating)Notes
Todos
Checklist
Testing checklist (automated report can be put here)
Target Environment support