From cd90e0c3208a74b9bd232fabc329eb24c33af0ab Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Sun, 7 Sep 2025 17:16:07 -0600 Subject: [PATCH 1/5] Registry: add basic ISO_C_BINDING types to use, add "ISO_C_BINDING" by itself on a line someplace in the registry text file --- modules/openfast-registry/src/registry.hpp | 27 +++++++++++++++++++ .../src/registry_gen_fortran.cpp | 4 +++ .../openfast-registry/src/registry_parse.cpp | 9 +++++++ 3 files changed, 40 insertions(+) diff --git a/modules/openfast-registry/src/registry.hpp b/modules/openfast-registry/src/registry.hpp index f615fb7a15..5b6acb1c63 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() { @@ -500,6 +502,21 @@ struct Registry {"PartialConstrStatePInputType", std::make_shared("PartialConstrStatePInputType", "dZdu", true)}, }; + + // Basic iso_c_binding types + 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, 32); + auto c_char = std::make_shared("c_char", "CHARACTER(c_char)", DataType::Tag::Character); + + // Map of ISO_C_BINIDNG types + 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,6 +529,16 @@ struct Registry // Pointer to type std::shared_ptr data_type; + // if using ISO_C_BINDING, search these types first + if (this->use_isocbinding) + { + auto it = data_types_isocbinding.find(type_name); + if (it != data_types_isocbinding.end()) + { + 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; 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) diff --git a/modules/openfast-registry/src/registry_parse.cpp b/modules/openfast-registry/src/registry_parse.cpp index e8ad7cdaf9..4ed6521323 100644 --- a/modules/openfast-registry/src/registry_parse.cpp +++ b/modules/openfast-registry/src/registry_parse.cpp @@ -94,6 +94,15 @@ int Registry::parse_line(const std::string &line, std::vector &fiel if (fields.size() == 0 || fields[0][0] == '#') return EXIT_SUCCESS; + //-------------------------------------------------------------------------- + // ISO C BINDING + // put a literal "USE ISO_C_BINDING" at start of file and allow c_* types + //-------------------------------------------------------------------------- + if (fields.size() == 1 && tolower(fields[0]).compare("iso_c_binding") == 0) + { + this->use_isocbinding = true; + return EXIT_SUCCESS; + } //-------------------------------------------------------------------------- // Include Line //-------------------------------------------------------------------------- From 4c1301ea74b91bf377bdd69afd74e86d00808c08 Mon Sep 17 00:00:00 2001 From: Andy Platt Date: Sun, 7 Sep 2025 17:32:15 -0600 Subject: [PATCH 2/5] Registry Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- modules/openfast-registry/src/registry.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openfast-registry/src/registry.hpp b/modules/openfast-registry/src/registry.hpp index 5b6acb1c63..bf102c21f8 100644 --- a/modules/openfast-registry/src/registry.hpp +++ b/modules/openfast-registry/src/registry.hpp @@ -506,7 +506,7 @@ struct Registry // Basic iso_c_binding types 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, 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); // Map of ISO_C_BINIDNG types From 3b5aee0f4d0b389e73d1bc640896eebee3c4e355 Mon Sep 17 00:00:00 2001 From: Andy Platt Date: Sun, 7 Sep 2025 17:32:33 -0600 Subject: [PATCH 3/5] Update modules/openfast-registry/src/registry.hpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- modules/openfast-registry/src/registry.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openfast-registry/src/registry.hpp b/modules/openfast-registry/src/registry.hpp index bf102c21f8..dd0ab9cbd3 100644 --- a/modules/openfast-registry/src/registry.hpp +++ b/modules/openfast-registry/src/registry.hpp @@ -509,7 +509,7 @@ struct Registry 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); - // Map of ISO_C_BINIDNG types + // Map of ISO_C_BINDING types this->data_types_isocbinding = std::map, ci_less>{ {"c_int",c_int}, {"c_float",c_float}, From c4391d45f50028e27ccf4793b03dba6441132f07 Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Mon, 8 Sep 2025 08:50:33 -0600 Subject: [PATCH 4/5] Registry: revise the iso_c_binding logic per @deslaughter's recommendations --- modules/openfast-registry/src/registry.hpp | 26 +++++++++---------- .../openfast-registry/src/registry_parse.cpp | 9 ------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/modules/openfast-registry/src/registry.hpp b/modules/openfast-registry/src/registry.hpp index dd0ab9cbd3..8888455f6a 100644 --- a/modules/openfast-registry/src/registry.hpp +++ b/modules/openfast-registry/src/registry.hpp @@ -455,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"); @@ -475,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>{ @@ -503,13 +511,7 @@ struct Registry std::make_shared("PartialConstrStatePInputType", "dZdu", true)}, }; - // Basic iso_c_binding types - 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); - - // Map of ISO_C_BINDING types + // 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}, @@ -530,13 +532,11 @@ struct Registry std::shared_ptr data_type; // if using ISO_C_BINDING, search these types first - if (this->use_isocbinding) + auto it = data_types_isocbinding.find(type_name); + if (it != data_types_isocbinding.end()) { - auto it = data_types_isocbinding.find(type_name); - if (it != data_types_isocbinding.end()) - { - return it->second; - } + this->use_isocbinding = true; + return it->second; } // Get map of data types to search diff --git a/modules/openfast-registry/src/registry_parse.cpp b/modules/openfast-registry/src/registry_parse.cpp index 4ed6521323..e8ad7cdaf9 100644 --- a/modules/openfast-registry/src/registry_parse.cpp +++ b/modules/openfast-registry/src/registry_parse.cpp @@ -94,15 +94,6 @@ int Registry::parse_line(const std::string &line, std::vector &fiel if (fields.size() == 0 || fields[0][0] == '#') return EXIT_SUCCESS; - //-------------------------------------------------------------------------- - // ISO C BINDING - // put a literal "USE ISO_C_BINDING" at start of file and allow c_* types - //-------------------------------------------------------------------------- - if (fields.size() == 1 && tolower(fields[0]).compare("iso_c_binding") == 0) - { - this->use_isocbinding = true; - return EXIT_SUCCESS; - } //-------------------------------------------------------------------------- // Include Line //-------------------------------------------------------------------------- From 5e851bd58dba0e19a646c4784f8f3bf44c594e34 Mon Sep 17 00:00:00 2001 From: andrew-platt Date: Mon, 8 Sep 2025 10:01:06 -0600 Subject: [PATCH 5/5] Registry: typo in registry.hpp --- modules/openfast-registry/src/registry.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openfast-registry/src/registry.hpp b/modules/openfast-registry/src/registry.hpp index 8888455f6a..0232f8c5bc 100644 --- a/modules/openfast-registry/src/registry.hpp +++ b/modules/openfast-registry/src/registry.hpp @@ -544,7 +544,7 @@ struct 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;