diff --git a/modules/openfast-registry/src/registry.hpp b/modules/openfast-registry/src/registry.hpp index f615fb7a15..0232f8c5bc 100644 --- a/modules/openfast-registry/src/registry.hpp +++ b/modules/openfast-registry/src/registry.hpp @@ -438,9 +438,11 @@ struct Registry std::map, ci_less> interface_map; std::map, ci_less> modules; std::map, ci_less> data_types; + std::map, ci_less> data_types_isocbinding; bool gen_c_code = false; bool no_extrap_interp = false; bool gen_inc_subs = false; + bool use_isocbinding = false; Registry() { @@ -453,6 +455,10 @@ struct Registry auto R8Ki = std::make_shared("R8Ki", "REAL(R8Ki)", DataType::Tag::Real, 64); auto DbKi = std::make_shared("DbKi", "REAL(DbKi)", DataType::Tag::Real, 64); auto logical = std::make_shared("Logical", "LOGICAL", DataType::Tag::Logical); + auto c_int = std::make_shared("c_int", "INTEGER(c_int)", DataType::Tag::Integer, 32); + auto c_float = std::make_shared("c_float", "REAL(c_float)", DataType::Tag::Real, 32); + auto c_double = std::make_shared("c_double","REAL(c_double)", DataType::Tag::Real, 64); + auto c_char = std::make_shared("c_char", "CHARACTER(c_char)", DataType::Tag::Character); // Derived types auto mesh = std::make_shared(nullptr, "MeshType", "MeshType", "MeshType"); @@ -473,6 +479,10 @@ struct Registry {"logical", logical}, {"meshtype", mesh}, {"dll_type", dll}, + {"c_int",c_int}, + {"c_float",c_float}, + {"c_double",c_double}, + {"c_char",c_char}, }; this->interface_map = std::map, ci_less>{ @@ -500,6 +510,15 @@ struct Registry {"PartialConstrStatePInputType", std::make_shared("PartialConstrStatePInputType", "dZdu", true)}, }; + + // Map of ISO_C_BINDING types (for checks only) + this->data_types_isocbinding = std::map, ci_less>{ + {"c_int",c_int}, + {"c_float",c_float}, + {"c_double",c_double}, + {"c_char",c_char}, + }; + } // Parsing @@ -512,12 +531,20 @@ struct Registry // Pointer to type std::shared_ptr data_type; + // if using ISO_C_BINDING, search these types first + auto it = data_types_isocbinding.find(type_name); + if (it != data_types_isocbinding.end()) + { + this->use_isocbinding = true; + return it->second; + } + // Get map of data types to search // If module was provided, search it; otherwise, search registry auto &data_types = mod == nullptr ? this->data_types : mod->data_types; // Search for type in registry, return if found - auto it = data_types.find(type_name); + it = data_types.find(type_name); if (it != data_types.end()) { return it->second; diff --git a/modules/openfast-registry/src/registry_gen_fortran.cpp b/modules/openfast-registry/src/registry_gen_fortran.cpp index 00b103cea0..f08e4ac58e 100644 --- a/modules/openfast-registry/src/registry_gen_fortran.cpp +++ b/modules/openfast-registry/src/registry_gen_fortran.cpp @@ -97,6 +97,10 @@ void Registry::gen_fortran_module(const Module &mod, const std::string &out_dir) // Write preamble w << std::regex_replace(FAST_preamble, std::regex("ModuleName"), mod.name); + // Output USE statements for literal passthroughs (i.e. ISO_C_BINDING) + if (this->use_isocbinding) + w << "USE ISO_C_BINDING\n"; + // Output USE statements for non-root modules for (auto const &mod : this->use_modules) if (tolower(mod).compare("nwtc_library") != 0)