22 #include "config_test.h" 32 printf(
"Annotation element %s start (tool: %s, parent:%s)\n", elm, parentName,
35 printf(
"Attribute %s = %s\n", attr[i], attr[i+1]);
38 printf(
"Annotation data:\n");
44 for(i = 0; i < len; i++)
50 printf(
"\nAnnotation element %s end\n", elm);
63 printf(
"Press 'Enter' to exit\n");
88 printf(
"No type definition\n");
99 printf(
"Quantity: %s\n", quan);
110 printf(
"Min %g, max %g, nominal %g\n", min, max, nom);
115 printf(
"Unit: %s, base unit %s, factor %g, offset %g\n",
122 printf(
"Display unit: %s, factor: %g, offset: %g, is relative: %s\n",
136 printf(
"Min %d, max %d\n", min, max);
149 printf(
"Min %d, max %d\n", min, max);
153 printf(
"There are %d items \n",ni);
154 for(i = 1; i <= ni; i++) {
158 assert(strcmp(itnm, str)==0);
159 printf(
"[%d] %s=%d (%s) \n", i,
168 printf(
"Error in fmiGetBaseType()\n");
183 printf(
"Searching by name worked fine\n");
187 printf(
"Searching by vr failed for variable '%s'\n", a_name);
199 printf(
"Searching by vr worked fine\n");
207 assert(vr == (
unsigned)vr);
210 printf(
"VR: %u\n", (
unsigned)vr);
227 printf(
"There is a start value\n");
252 printf(
"Error in fmiGetBaseType()\n");
256 printf(
"The variable is aliased to %s\n",
260 printf(
"The variable is not an alias\n");
266 printf(
"Listing aliases: \n");
286 if(!rows || !cols || !start) {
287 printf(
"Dependencies are not available\n");
290 for(i = 0; i < nr; i++) {
297 for(i = 0; i < nr; i++) {
298 if(start[i] == start[i+1]) {
301 else if((start[i] + 1 == start[i+1]) && (dep[start[i]] == 0)) {
306 for(j = start[i]; j < start[i+1]; j++) {
314 int main(
int argc,
char *argv[])
325 printf(
"Usage: %s <path to a dir with modelDescription.xml>\n", argv[0]);
332 callbacks.
malloc = malloc;
333 callbacks.
calloc = calloc;
335 callbacks.
free = free;
340 #ifdef FMILIB_GENERATE_BUILD_STAMP 341 printf(
"Library build stamp:\n%s\n", fmilib_get_build_stamp());
351 t = (double) (stop-start)/CLOCKS_PER_SEC;
352 printf(
"Parsing took %g seconds\n", t);
354 printf(
"Error parsing XML, exiting\n");
379 printf(
"Default experiment start = %g, end = %g, tolerance = %g, step = %g\n",
388 printf(
"There are %d source files for ME\n", n_sources);
389 for (k=0; k < n_sources; k++) {
396 printf(
"There are %d source files for CS\n", n_sources);
397 for (k=0; k < n_sources; k++) {
405 printf(
"There are %u tool annotation records \n", (
unsigned)nv);
406 for( i = 0; i < nv; i++) {
414 printf(
"There are %d different units used \n", nu);
416 for(i = 0; i < nu; i++) {
424 printf(
"Unit [%d] is %s, base unit %s, factor %g, offset %g, it has %d display units\n",
440 printf(
"There are %d defs\n", ntd);
441 for(i = 0; i < ntd; i++) {
464 printf(
"There are %u variables in total \n",(
unsigned)nv);
465 for(i = 0; i < nv; i++) {
469 printf(
"Something wrong with variable %u \n",(
unsigned)i);
562 printf(
"Everything seems to be OK since you got this far=)!\n");
FMILIB_EXPORT int fmi2_import_get_integer_type_max(fmi2_import_integer_typedef_t *)
Get maximum value for the type.
fmi2_base_type_enu_t
Base types used in type definitions.
FMILIB_EXPORT const char * fmi2_import_get_unit_name(fmi2_import_unit_t *)
Get a unit name.
FMILIB_EXPORT size_t fmi2_import_get_variable_list_size(fmi2_import_variable_list_t *vl)
Get number of variables in a list.
void testVariableSearch(fmi2_import_t *fmu, fmi2_import_variable_t *v)
FMILIB_EXPORT fmi2_import_integer_typedef_t * fmi2_import_get_type_as_int(fmi2_import_variable_typedef_t *)
Cast the general type definition object to an object with a specific base type.
FMILIB_EXPORT fmi2_import_integer_variable_t * fmi2_import_get_variable_as_integer(fmi2_import_variable_t *)
Cast general variable to a one with the specific type.
FMILIB_EXPORT fmi2_real_t fmi2_import_get_real_variable_start(fmi2_import_real_variable_t *v)
Get the variable start attribute.
fmi2_dependency_factor_kind_enu_t
Dependency factor kinds are used as part of ModelStructure definition.
jm_calloc_f calloc
Allocate zero initialized memory.
FMILIB_EXPORT unsigned int fmi2_import_get_type_definition_number(fmi2_import_type_definitions_t *td)
Get the number of available type definitions.
void mylogger(jm_callbacks *c, jm_string module, jm_log_level_enu_t log_level, jm_string message)
FMILIB_EXPORT fmi2_import_string_variable_t * fmi2_import_get_variable_as_string(fmi2_import_variable_t *)
Cast general variable to a one with the specific type.
FMILIB_EXPORT const char * fmi2_import_get_generation_tool(fmi2_import_t *fmu)
Get FMU generation tool.
FMILIB_EXPORT double fmi2_import_get_default_experiment_tolerance(fmi2_import_t *fmu)
Get the tolerance for default experiment as specified in the XML file.
FMILIB_EXPORT const char * fmi2_import_get_model_version(fmi2_import_t *fmu)
Get FMU version.
FMILIB_EXPORT fmi2_import_variable_t * fmi2_import_get_variable_by_vr(fmi2_import_t *fmu, fmi2_base_type_enu_t baseType, fmi2_value_reference_t vr)
Get variable by value reference.
FMILIB_EXPORT const char * fmi2_import_get_type_name(fmi2_import_variable_typedef_t *)
Get the type name.
FMILIB_EXPORT const char * fmi2_variability_to_string(fmi2_variability_enu_t v)
Convert a fmi2_variability_enu_t constant into string.
FMILIB_EXPORT const char * fmi2_fmu_kind_to_string(fmi2_fmu_kind_enu_t kind)
Convert a fmi2_fmu_kind_enu_t constant into string.
FMILIB_EXPORT fmi2_import_real_typedef_t * fmi2_import_get_type_as_real(fmi2_import_variable_typedef_t *)
Cast the general type definition object to an object with a specific base type.
struct fmi2_xml_real_variable_t fmi2_import_real_variable_t
Opaque real variable.
FMILIB_EXPORT double fmi2_import_get_default_experiment_stop(fmi2_import_t *fmu)
Get the stop time for default experiment as specified in the XML file.
FMILIB_EXPORT fmi2_base_type_enu_t fmi2_import_get_base_type(fmi2_import_variable_typedef_t *)
Get base type used for the type definition.
Import context is the entry point to the library. It is used to initialize, unzip, get FMI version and start parsing.
FMILIB_EXPORT const char * fmi2_import_get_source_file_me(fmi2_import_t *fmu, size_t index)
Get the ME source file by index.
FMILIB_EXPORT fmi2_import_variable_typedef_t * fmi2_import_get_variable_declared_type(fmi2_import_variable_t *)
For scalar variable gives the type definition is present.
FMILIB_EXPORT unsigned int fmi2_import_get_capability(fmi2_import_t *, fmi2_capabilities_enu_t id)
Retrieve capability flags by ID.
FMILIB_EXPORT int fmi2_import_get_enum_variable_start(fmi2_import_enum_variable_t *v)
Get start value for the variable.
FMILIB_EXPORT const int * fmi2_import_get_SI_unit_exponents(fmi2_import_unit_t *)
Get fmi2_SI_base_units_Num SI base units exponents associated with the unit.
FMILIB_EXPORT const char * fmi2_import_get_string_variable_start(fmi2_import_string_variable_t *v)
Get start value for the variable.
FMILIB_EXPORT const char * fmi2_import_get_type_quantity(fmi2_import_variable_typedef_t *)
Get the quantity associated with the type definition.
struct fmi2_import_variable_list_t fmi2_import_variable_list_t
List of variables.
FMILIB_EXPORT fmi2_base_type_enu_t fmi2_import_get_variable_base_type(fmi2_import_variable_t *)
Get variable base type.
void printCapabilitiesInfo(fmi2_import_t *fmu)
fmi2_xml_callbacks_t annotation_callbacks
XML callbacks are used to process parts of XML that are not handled by the library.
int annotation_data_handle(void *context, const char *s, int len)
FMILIB_EXPORT const char * fmi2_import_get_variable_description(fmi2_import_variable_t *)
Get variable description.
fmi2_capabilities_enu_t
Capability flags for ModelExchange and CoSimulation.
FMILIB_EXPORT const char * fmi2_import_get_author(fmi2_import_t *fmu)
Get FMU author.
FMILIB_EXPORT unsigned int fmi2_import_get_unit_definitions_number(fmi2_import_unit_definitions_t *)
Get the number of unit definitions.
FMILIB_EXPORT fmi2_import_type_definitions_t * fmi2_import_get_type_definitions(fmi2_import_t *)
Get the list of all the type definitions in the model.
FMILIB_EXPORT fmi2_import_variable_list_t * fmi2_import_get_variable_list(fmi2_import_t *fmu, int sortOrder)
Get the list of all the variables in the model.
FMILIB_EXPORT fmi2_variable_naming_convension_enu_t fmi2_import_get_naming_convention(fmi2_import_t *fmu)
Get variable naming convention used.
FMILIB_EXPORT const char * fmi2_import_get_vendor_name(fmi2_import_t *fmu, size_t index)
Get the name of the vendor with that had annotations in the XML by index.
FMILIB_EXPORT const char * jm_log_level_to_string(jm_log_level_enu_t level)
Convert log level into a string.
FMILIB_EXPORT unsigned int fmi2_import_get_unit_display_unit_number(fmi2_import_unit_t *)
Get the number of display units associated with this unit.
struct fmi2_xml_unit_definitions_t fmi2_import_unit_definitions_t
The list of all the unit definitions in the model.
jm_log_level_enu_t
Log levels supported via the logger functions in jm_callbacks.
FMILIB_EXPORT size_t fmi2_import_get_number_of_event_indicators(fmi2_import_t *fmu)
Get the number of event indicators.
FMILIB_EXPORT int fmi2_import_get_integer_type_min(fmi2_import_integer_typedef_t *)
Get minimal value for the type.
FMILIB_EXPORT fmi2_import_t * fmi2_import_parse_xml(fmi_import_context_t *context, const char *dirPath, fmi2_xml_callbacks_t *xml_callbacks)
Create fmi2_import_t structure and parse the FMI 2.0 XML file found in the directory dirName...
FMILIB_EXPORT fmi2_import_variable_t * fmi2_import_get_variable_alias_base(fmi2_import_t *fmu, fmi2_import_variable_t *)
Get the variable with the same value reference that is not an alias.
FMILIB_EXPORT const char * fmi2_import_get_model_standard_version(fmi2_import_t *fmu)
Get FMI standard version (always 2.0).
FMILIB_EXPORT const char * fmi2_import_get_model_name(fmi2_import_t *fmu)
Get model name.
FMILIB_EXPORT fmi2_initial_enu_t fmi2_import_get_initial(fmi2_import_variable_t *)
Get initial attribute.
XML callbacks are used to process parts of XML that are not handled by the library.
struct fmi2_xml_enumeration_typedef_t fmi2_import_enumeration_typedef_t
Opaque enumeration type definition object.
FMILIB_EXPORT fmi2_fmu_kind_enu_t fmi2_import_get_fmu_kind(fmi2_import_t *fmu)
Get the type of the FMU (model exchange or co-simulation)
FMILIB_EXPORT fmi2_import_enum_variable_t * fmi2_import_get_variable_as_enum(fmi2_import_variable_t *)
Cast general variable to a one with the specific type.
FMILIB_EXPORT const char * fmi2_import_get_enum_type_item_description(fmi2_import_enumeration_typedef_t *, unsigned int item)
Get an enumeration item description by index.
jm_log_level_enu_t log_level
Logging level.
FMILIB_EXPORT double fmi2_import_get_default_experiment_step(fmi2_import_t *fmu)
Get the step size for default experiment as specified in the XML file.
int annotation_start_handle(void *context, const char *parentName, void *parent, const char *elm, const char **attr)
struct fmi2_xml_variable_t fmi2_import_variable_t
General variable type.
FMILIB_EXPORT fmi2_import_real_variable_t * fmi2_import_get_variable_as_real(fmi2_import_variable_t *)
Cast general variable to a one with the specific type.
FMILIB_EXPORT void fmi2_import_free_variable_list(fmi2_import_variable_list_t *vl)
Free a variable list. Note that variable lists are allocated dynamically and must be freed when not n...
int annotation_end_handle(void *context, const char *elm)
struct fmi2_xml_variable_typedef_t fmi2_import_variable_typedef_t
Opaque general variable type definition object.
FMILIB_EXPORT size_t fmi2_import_get_source_files_me_num(fmi2_import_t *fmu)
Get the number of source files for ME defined in the XML.
FMILIB_EXPORT int fmi2_import_get_enum_type_item_value(fmi2_import_enumeration_typedef_t *, unsigned int item)
Get an enumeration item value by index.
FMILIB_EXPORT double fmi2_import_get_real_type_max(fmi2_import_real_typedef_t *)
Get maximum value for the type.
FMILIB_EXPORT const char * fmi2_causality_to_string(fmi2_causality_enu_t c)
Convert a fmi2_causality_enu_t constant into string.
FMILIB_EXPORT fmi2_variability_enu_t fmi2_import_get_variability(fmi2_import_variable_t *)
Get variability attribute.
FMILIB_EXPORT fmi2_import_enumeration_typedef_t * fmi2_import_get_type_as_enum(fmi2_import_variable_typedef_t *)
Cast the general type definition object to an object with a specific base type.
FMILIB_EXPORT fmi2_real_t fmi2_import_get_display_unit_offset(fmi2_import_display_unit_t *)
Get the "offset" associated with the display unit.
FMILIB_EXPORT fmi2_import_variable_t * fmi2_import_get_variable_by_name(fmi2_import_t *fmu, const char *name)
Get variable by variable name.
FMILIB_EXPORT const char * fmi2_import_get_generation_date_and_time(fmi2_import_t *fmu)
Get FMU generation date and time.
FMILIB_EXPORT const char * fmi2_import_get_model_identifier_CS(fmi2_import_t *fmu)
Get model identifier for CoSimulation.
jm_malloc_f malloc
Allocate non-initialized memory.
FMILIB_EXPORT fmi2_import_display_unit_t * fmi2_import_get_type_display_unit(fmi2_import_real_typedef_t *)
Get associated display unit for a type defition if any.
jm_voidp context
Arbitrary context pointer passed to the logger function.
const char * jm_string
A constant string.
FMILIB_EXPORT unsigned int fmi2_import_get_enum_type_size(fmi2_import_enumeration_typedef_t *)
Get the number of elements in the enum.
FMILIB_EXPORT double fmi2_import_get_default_experiment_start(fmi2_import_t *fmu)
Get the start time for default experiment as specified in the XML file.
FMILIB_EXPORT double fmi2_import_get_SI_unit_offset(fmi2_import_unit_t *)
Get offset to the corresponding SI base units.
struct fmi2_xml_type_definitions_t fmi2_import_type_definitions_t
Opaque list of the type definitions in the model.
struct fmi2_xml_unit_t fmi2_import_unit_t
A variable unit defined with a unit defition.
FMILIB_EXPORT fmi2_import_unit_t * fmi2_import_get_real_variable_unit(fmi2_import_real_variable_t *v)
Get associated "unit" object if any.
FMILIB_EXPORT const fmi2_value_reference_t * fmi2_import_get_value_referece_list(fmi2_import_variable_list_t *vl)
Get a pointer to the list of the value references for all the variables.
FMILIB_EXPORT unsigned int fmi2_import_get_enum_type_max(fmi2_import_enumeration_typedef_t *)
Get maximum value for the type.
FMILIB_EXPORT size_t fmi2_import_get_source_files_cs_num(fmi2_import_t *fmu)
Get the number of source files for CS defined in the XML.
The callbacks struct is sent to all the modules in the library.
struct fmi2_xml_display_unit_t fmi2_import_display_unit_t
A display unit.
void print_dbl(double d, void *data)
FMILIB_EXPORT fmi2_import_unit_definitions_t * fmi2_import_get_unit_definitions(fmi2_import_t *fmu)
Get a list of all the unit definitions in the model.
FMILIB_EXPORT size_t fmi2_import_get_vendors_num(fmi2_import_t *fmu)
Get the number of vendors that had annotations in the XML.
struct fmi_xml_context_t fmi_import_context_t
FMI version independent library context. Opaque struct returned from fmi_import_allocate_context() ...
void printVariableInfo(fmi2_import_t *fmu, fmi2_import_variable_t *v)
FMILIB_EXPORT fmi2_causality_enu_t fmi2_import_get_causality(fmi2_import_variable_t *)
Get causality attribute.
FMILIB_EXPORT void fmi2_import_free(fmi2_import_t *fmu)
Release the memory allocated.
FMILIB_EXPORT unsigned int fmi2_import_get_enum_type_min(fmi2_import_enumeration_typedef_t *)
Get minimal value for the type.
FMILIB_EXPORT const char * fmi2_import_get_enum_type_item_name(fmi2_import_enumeration_typedef_t *, unsigned int item)
Get an enumeration item name by index.
struct fmi2_xml_real_typedef_t fmi2_import_real_typedef_t
Opaque type definition object.
FMILIB_EXPORT fmi_import_context_t * fmi_import_allocate_context(jm_callbacks *callbacks)
Create fmi_import_context_t structure.
FMILIB_EXPORT const char * fmi2_import_get_source_file_cs(fmi2_import_t *fmu, size_t index)
Get the CS source file by index.
FMILIB_EXPORT double fmi2_import_get_real_type_min(fmi2_import_real_typedef_t *)
Get minimal value for the type.
FMILIB_EXPORT const char * fmi2_import_get_variable_name(fmi2_import_variable_t *)
Get the variable name.
FMILIB_EXPORT size_t fmi2_import_get_number_of_continuous_states(fmi2_import_t *fmu)
Get the number of continuous states.
FMILIB_EXPORT fmi2_variable_alias_kind_enu_t fmi2_import_get_variable_alias_kind(fmi2_import_variable_t *)
Get the variable alias kind.
FMILIB_EXPORT fmi2_import_unit_t * fmi2_import_get_real_type_unit(fmi2_import_real_typedef_t *)
Get the unit object associated with the type definition if any.
FMILIB_EXPORT const char * fmi2_import_get_display_unit_name(fmi2_import_display_unit_t *)
Get display unit name.
Public interface to the FMI import C-library.
void print_int(int i, void *data)
FMILIB_EXPORT fmi2_value_reference_t fmi2_import_get_variable_vr(fmi2_import_variable_t *)
Get variable value reference.
FMILIB_EXPORT const char * fmi2_import_get_description(fmi2_import_t *fmu)
Get FMU description.
FMILIB_EXPORT const char * fmi2_import_get_GUID(fmi2_import_t *fmu)
Get FMU GUID.
FMILIB_EXPORT int fmi2_import_get_variable_has_start(fmi2_import_variable_t *)
Check if the variable has "start" attribute.
FMILIB_EXPORT const char * fmi2_initial_to_string(fmi2_initial_enu_t c)
Convert a fmi2_initial_enu_t constant into string.
FMILIB_EXPORT fmi2_import_unit_t * fmi2_import_get_unit(fmi2_import_unit_definitions_t *, unsigned int index)
Get a unit definition.
FMILIB_EXPORT size_t fmi2_SI_base_unit_exp_to_string(const int exp[fmi2_SI_base_units_Num], size_t bufSize, char buf[])
Convert a list of SI base unit exponents (corresponding to the IDs from fmi2_SI_base_units_enu_t) to ...
FMILIB_EXPORT fmi2_import_variable_t * fmi2_import_get_variable(fmi2_import_variable_list_t *vl, size_t index)
Get a single variable from the list.
void printDependenciesInfo(fmi2_import_t *fmu, fmi2_import_variable_list_t *rows, fmi2_import_variable_list_t *cols, size_t *start, size_t *dep, char *factor)
FMILIB_EXPORT fmi2_boolean_t fmi2_import_get_boolean_variable_start(fmi2_import_bool_variable_t *v)
Get start value for the variable.
FMILIB_EXPORT fmi2_import_display_unit_t * fmi2_import_get_real_variable_display_unit(fmi2_import_real_variable_t *v)
Get associated "display unit" object if any.
int main(int argc, char *argv[])
FMILIB_EXPORT fmi2_import_variable_typedef_t * fmi2_import_get_typedef(fmi2_import_type_definitions_t *td, unsigned int index)
Get a type definition specified by the index.
FMILIB_EXPORT const char * fmi2_base_type_to_string(fmi2_base_type_enu_t bt)
Convert base type constant to string.
FMILIB_EXPORT fmi2_import_variable_list_t * fmi2_import_get_variable_aliases(fmi2_import_t *fmu, fmi2_import_variable_t *)
FMILIB_EXPORT double fmi2_import_get_SI_unit_factor(fmi2_import_unit_t *)
Get factor to the corresponding SI base units.
FMILIB_EXPORT void fmi_import_free_context(fmi_import_context_t *c)
Free memory allocated for the library context.
struct fmi2_xml_integer_typedef_t fmi2_import_integer_typedef_t
Opaque integer type definition object.
jm_realloc_f realloc
Re-allocate memory.
FMILIB_EXPORT const char * fmi2_import_get_last_error(fmi2_import_t *fmu)
Retrieve the last error message.
FMILIB_EXPORT const char * fmi2_dependency_factor_kind_to_string(fmi2_dependency_factor_kind_enu_t fc)
Convert dependency factor kind constant to string.
jm_free_f free
Free-allocated memory.
FMILIB_EXPORT const char * fmi2_import_get_model_identifier_ME(fmi2_import_t *fmu)
Get model identifier for ModelExchange.
FMILIB_EXPORT fmi2_import_bool_variable_t * fmi2_import_get_variable_as_boolean(fmi2_import_variable_t *)
Cast general variable to a one with the specific type.
FMILIB_EXPORT const char * fmi2_naming_convention_to_string(fmi2_variable_naming_convension_enu_t convention)
Convert a fmi2_variable_naming_convension_enu_t constant into string.
#define FMILIB_SIZET_FORMAT
FMILIB_EXPORT int fmi2_import_get_real_type_is_relative_quantity(fmi2_import_real_typedef_t *)
Get the 'relativeQuantity' flag.
jm_logger_f logger
Logging callback.
FMILIB_EXPORT double fmi2_import_get_real_type_nominal(fmi2_import_real_typedef_t *)
Get the nominal value associated with the type definition.
FMILIB_EXPORT const char * fmi2_import_get_type_description(fmi2_import_variable_typedef_t *)
Get type description.
FMILIB_EXPORT int fmi2_import_get_integer_variable_start(fmi2_import_integer_variable_t *v)
Get start value for the variable.
struct fmi2_import_t fmi2_import_t
FMU version 2.0 object.
FMILIB_EXPORT const char * fmi2_import_get_enum_type_value_name(fmi2_import_enumeration_typedef_t *t, int value)
Get an enumeration item name for the given value.
void printTypeInfo(fmi2_import_variable_typedef_t *vt)
FMILIB_EXPORT const char * fmi2_capability_to_string(fmi2_capabilities_enu_t id)
Convert capability flag to a string.
FMILIB_EXPORT fmi2_real_t fmi2_import_get_display_unit_factor(fmi2_import_display_unit_t *)
Get the "factor" associated with the display unit.