FMI Library: part of JModelica.org
fmi2_import_xml_test.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 Modelon AB
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the BSD style license.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  FMILIB_License.txt file for more details.
11 
12  You should have received a copy of the FMILIB_License.txt file
13  along with this program. If not, contact Modelon AB <http://www.modelon.com>.
14 */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <stdarg.h>
19 #include <assert.h>
20 #include <time.h>
21 
22 #include "config_test.h"
23 
24 #include <FMI/fmi_import_context.h>
25 
26 #include <FMI2/fmi2_import.h>
27 
29 
30 int annotation_start_handle(void *context, const char *parentName, void *parent, const char *elm, const char **attr) {
31  int i = 0;
32  printf("Annotation element %s start (tool: %s, parent:%s)\n", elm, parentName,
33  parent?fmi2_import_get_variable_name((fmi2_import_variable_t*)parent):"model");
34  while(attr[i]) {
35  printf("Attribute %s = %s\n", attr[i], attr[i+1]);
36  i+=2;
37  }
38  printf("Annotation data:\n");
39  return 0;
40 }
41 
42 int annotation_data_handle(void* context, const char *s, int len) {
43  int i;
44  for(i = 0; i < len; i++)
45  printf("%c", s[i]);
46  return 0;
47 }
48 
49 int annotation_end_handle(void *context, const char *elm) {
50  printf("\nAnnotation element %s end\n", elm);
51  return 0;
52 }
53 
58  annotation_end_handle, NULL};
59 
60 
61 void do_exit(int code)
62 {
63  printf("Press 'Enter' to exit\n");
64 /* getchar(); */
65  exit(code);
66 }
67 
68 void mylogger(jm_callbacks* c, jm_string module, jm_log_level_enu_t log_level, jm_string message)
69 {
70  printf("[%s][%s] %s\n", module, jm_log_level_to_string(log_level), message);
71  if (!expect_error && log_level == jm_log_level_error) {
72  do_exit(1);
73  }
74 }
75 
76 void print_int(int i,void* data) {
77  printf("%d\n", i);
78 }
79 
80 void print_dbl(double d,void* data) {
81  printf("%g\n", d);
82 }
83 
85  const char* quan;
86 
87  if(!vt) {
88  printf("No type definition\n");
89  return;
90  }
91 
93 
94  printf("Type %s\n description: %s\n", fmi2_import_get_type_name(vt), fmi2_import_get_type_description(vt));
95 
96  printf("Base type: %s\n", fmi2_base_type_to_string(fmi2_import_get_base_type(vt)));
97 
98  if(quan) {
99  printf("Quantity: %s\n", quan);
100  }
101  switch(fmi2_import_get_base_type(vt)) {
102  case fmi2_base_type_real: {
104  fmi2_real_t min = fmi2_import_get_real_type_min(rt);
105  fmi2_real_t max = fmi2_import_get_real_type_max(rt);
106  fmi2_real_t nom = fmi2_import_get_real_type_nominal(rt);
109 
110  printf("Min %g, max %g, nominal %g\n", min, max, nom);
111 
112  if(u) {
113  char buf[1000];
115  printf("Unit: %s, base unit %s, factor %g, offset %g\n",
117  buf,
120  }
121  if(du) {
122  printf("Display unit: %s, factor: %g, offset: %g, is relative: %s\n",
127  );
128  }
129 
130  break;
131  }
132  case fmi2_base_type_int:{
134  int min = fmi2_import_get_integer_type_min(it);
135  int max = fmi2_import_get_integer_type_max(it);
136  printf("Min %d, max %d\n", min, max);
137  break;
138  }
139  case fmi2_base_type_bool:{
140  break;
141  }
142  case fmi2_base_type_str:{
143  break;
144  }
145  case fmi2_base_type_enum:{
147  int min = fmi2_import_get_enum_type_min(et);
148  int max = fmi2_import_get_enum_type_max(et);
149  printf("Min %d, max %d\n", min, max);
150  {
151  unsigned ni, i;
153  printf("There are %d items \n",ni);
154  for(i = 1; i <= ni; i++) {
155  int val = fmi2_import_get_enum_type_item_value(et, i);
156  const char* str = fmi2_import_get_enum_type_value_name(et, val);
157  const char* itnm = fmi2_import_get_enum_type_item_name(et, i);
158  assert(strcmp(itnm, str)==0);
159  printf("[%d] %s=%d (%s) \n", i,
160  itnm,
161  val,
163  }
164  }
165  break;
166  }
167  default:
168  printf("Error in fmiGetBaseType()\n");
169  }
170 
171 }
172 
175 
176  const char * a_name = fmi2_import_get_variable_name(v);
178  if(found != v) {
179  printf("Searching by name %s found var %s\n", a_name, found?fmi2_import_get_variable_name(found):"nothing");
180  do_exit(1);
181  }
182  else {
183  printf("Searching by name worked fine\n");
184  }
186  if(!found) {
187  printf("Searching by vr failed for variable '%s'\n", a_name);
188  do_exit(1);
189  }
191  printf("Searching %s found var %s", a_name, fmi2_import_get_variable_name(found));
192  do_exit(1);
193  }
195  printf("Searching %s found var %s", a_name, fmi2_import_get_variable_name(found));
196  do_exit(1);
197  }
198  else {
199  printf("Searching by vr worked fine\n");
200  }
201 }
202 
206  size_t vr = fmi2_import_get_variable_vr(v);
207  assert(vr == (unsigned)vr);
208  printf("Variable name: %s\n", fmi2_import_get_variable_name(v));
209  printf("Description: %s\n", fmi2_import_get_variable_description(v));
210  printf("VR: %u\n", (unsigned)vr);
211  printf("Variability: %s\n", fmi2_variability_to_string(fmi2_import_get_variability(v)));
212  printf("Causality: %s\n", fmi2_causality_to_string(fmi2_import_get_causality(v)));
213  printf("Initial: %s\n", fmi2_initial_to_string(fmi2_import_get_initial(v)));
214 
216  printf("Base type: %s\n", fmi2_base_type_to_string(bt));
217 
219  if(bt == fmi2_base_type_real) {
223  printf("Unit: %s, display unit: %s\n", u ? fmi2_import_get_unit_name(u):0, du?fmi2_import_get_display_unit_name(du):"not provided");
224  }
225 
227  printf("There is a start value\n");
228 
230  case fmi2_base_type_real: {
232  printf("start =%g\n", fmi2_import_get_real_variable_start(rv));
233  break;
234  }
235  case fmi2_base_type_int:{
237  break;
238  }
239  case fmi2_base_type_bool:{
241  break;
242  }
243  case fmi2_base_type_str:{
245  break;
246  }
247  case fmi2_base_type_enum:{
249  break;
250  }
251  default:
252  printf("Error in fmiGetBaseType()\n");
253  }
254  }
256  printf("The variable is aliased to %s\n",
258  }
259  else {
260  printf("The variable is not an alias\n");
261  }
262  {
264  size_t i, n = fmi2_import_get_variable_list_size(vl);
265  if(n>1) {
266  printf("Listing aliases: \n");
267  for(i = 0;i<n;i++)
269  }
271  }
272 }
273 
275  size_t i;
276 
277  for( i = 0; i < fmi2_capabilities_Num; ++i) {
278  printf("%s = %u\n",
281  }
282 }
283 
284 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) {
285  size_t i, j, nr;
286  if(!rows || !cols || !start) {
287  printf("Dependencies are not available\n");
288  if(rows) {
290  for(i = 0; i < nr; i++) {
291  printf("\t%s\n",fmi2_import_get_variable_name(fmi2_import_get_variable(rows, i)));
292  }
293  }
294  return;
295  }
297  for(i = 0; i < nr; i++) {
298  if(start[i] == start[i+1]) {
299  printf("\t%s has no dependencies\n",fmi2_import_get_variable_name(fmi2_import_get_variable(rows, i)));
300  }
301  else if((start[i] + 1 == start[i+1]) && (dep[start[i]] == 0)) {
302  printf("\t%s depends on all\n",fmi2_import_get_variable_name(fmi2_import_get_variable(rows, i)));
303  }
304  else {
305  printf("\t%s depends on:\n",fmi2_import_get_variable_name(fmi2_import_get_variable(rows, i)));
306  for(j = start[i]; j < start[i+1]; j++) {
307  printf("\t\t%s (factor kind: %s)\n",fmi2_import_get_variable_name(fmi2_import_get_variable(cols, dep[j]-1)),
309  }
310  }
311  }
312 }
313 
314 int main(int argc, char *argv[])
315 {
316  clock_t start, stop;
317  double t = 0.0;
318  const char* tmpPath;
320  fmi_import_context_t* context;
321 
323 
324  if(argc < 2) {
325  printf("Usage: %s <path to a dir with modelDescription.xml>\n", argv[0]);
326  do_exit(1);
327  }
328 
329  tmpPath = argv[1];
330  expect_error = argc > 2;
331 
332  callbacks.malloc = malloc;
333  callbacks.calloc = calloc;
334  callbacks.realloc = realloc;
335  callbacks.free = free;
336  callbacks.logger = mylogger;
337  callbacks.context = 0;
338  callbacks.log_level = jm_log_level_debug;
339 
340 #ifdef FMILIB_GENERATE_BUILD_STAMP
341  printf("Library build stamp:\n%s\n", fmilib_get_build_stamp());
342 #endif
343 
344  context = fmi_import_allocate_context(&callbacks);
345 
346  start = clock();
347  fmu = fmi2_import_parse_xml(context, tmpPath, &annotation_callbacks);
348 
349  /* Stop timer */
350  stop = clock();
351  t = (double) (stop-start)/CLOCKS_PER_SEC;
352  printf("Parsing took %g seconds\n", t);
353  if(!fmu) {
354  printf("Error parsing XML, exiting\n");
355  fmi_import_free_context(context);
356  do_exit(1);
357  }
358 
359  printf("Model name: %s\n", fmi2_import_get_model_name(fmu));
360  printf("Model GUID: %s\n", fmi2_import_get_GUID(fmu));
361  printf("FMU kind: %s\n", fmi2_fmu_kind_to_string(fmi2_import_get_fmu_kind(fmu)));
362  printf("Description: %s\n", fmi2_import_get_description(fmu));
363  printf("Author: %s\n", fmi2_import_get_author(fmu));
364  printf("FMI Version: %s\n", fmi2_import_get_model_standard_version(fmu));
365  printf("Generation tool: %s\n", fmi2_import_get_generation_tool(fmu));
366  printf("Generation date and time: %s\n", fmi2_import_get_generation_date_and_time(fmu));
367  printf("Version: %s\n", fmi2_import_get_model_version(fmu));
369 
371  printf("Model identifier ME: %s\n", fmi2_import_get_model_identifier_ME(fmu));
373  printf("Model identifier CS: %s\n", fmi2_import_get_model_identifier_CS(fmu));
375 
376  printf("NumberOfContinuousStates = " FMILIB_SIZET_FORMAT "\n", fmi2_import_get_number_of_continuous_states(fmu));
377  printf("NumberOfEventIndicators = " FMILIB_SIZET_FORMAT "\n", fmi2_import_get_number_of_event_indicators(fmu));
378 
379  printf("Default experiment start = %g, end = %g, tolerance = %g, step = %g\n",
384 
385  {
386  int n_sources = fmi2_import_get_source_files_me_num(fmu);
387  int k;
388  printf("There are %d source files for ME\n", n_sources);
389  for (k=0; k < n_sources; k++) {
390  printf("\t%s\n", fmi2_import_get_source_file_me(fmu, k));
391  }
392  }
393  {
394  int n_sources = fmi2_import_get_source_files_cs_num(fmu);
395  int k;
396  printf("There are %d source files for CS\n", n_sources);
397  for (k=0; k < n_sources; k++) {
398  printf("\t%s\n", fmi2_import_get_source_file_cs(fmu, k));
399  }
400  }
401 
402 
403  {
404  size_t i, nv = fmi2_import_get_vendors_num(fmu);
405  printf("There are %u tool annotation records \n", (unsigned)nv);
406  for( i = 0; i < nv; i++) {
407  printf("Vendor name [%u] %s", (unsigned)i, fmi2_import_get_vendor_name(fmu, i));
408  }
409  }
410  {
412  if(ud) {
413  unsigned i, nu = fmi2_import_get_unit_definitions_number(ud);
414  printf("There are %d different units used \n", nu);
415 
416  for(i = 0; i < nu; i++) {
418  char buf[1000];
419  if(!u) {
420  printf("Error getting unit for index %d (%s)\n", i, fmi2_import_get_last_error(fmu));
421  break;
422  }
424  printf("Unit [%d] is %s, base unit %s, factor %g, offset %g, it has %d display units\n",
426  buf,
430  }
431  }
432  else
433  printf("Error getting unit definitions (%s)\n", fmi2_import_get_last_error(fmu));
434  }
435  {
437  if(td) {
438  {
439  unsigned i, ntd = fmi2_import_get_type_definition_number(td);
440  printf("There are %d defs\n", ntd);
441  for(i = 0; i < ntd; i++) {
443  if(!vt) {
444  printf("Error getting vartype for index %d (%s)\n", i, fmi2_import_get_last_error(fmu));
445  break;
446  }
447  printTypeInfo(vt);
448  }
449  }
450  }
451  else
452  printf("Error getting type definitions (%s)\n", fmi2_import_get_last_error(fmu));
453  }
454  {
455  size_t nv, i;
457 /* fmi2_import_variable_list_t* ders = fmi2_import_get_derivatives_list( fmu); */
458  const fmi2_value_reference_t* vrl = fmi2_import_get_value_referece_list(vl);
459 
460 
461  assert(vl);
462 
464  printf("There are %u variables in total \n",(unsigned)nv);
465  for(i = 0; i < nv; i++) {
467  assert(vrl[i] == fmi2_import_get_variable_vr(var));
468  if(!var) {
469  printf("Something wrong with variable %u \n",(unsigned)i);
470  do_exit(1);
471  }
472  else {
473  printVariableInfo(fmu, var);
474 /* size_t stateIndex = fmi2_import_get_state_index(var);
475  if(stateIndex) {
476  printf("This variable is a state. Its derivative: %s\n",
477  fmi2_import_get_variable_name(fmi2_import_get_variable(ders, stateIndex-1)));
478  } */
479  testVariableSearch(fmu, var);
480  }
481  }
483 /* fmi2_import_free_variable_list(ders); */
484  }
485 /* {
486  fmi2_import_variable_list_t* vl = fmi2_import_get_inputs_list( fmu);
487  size_t i, n = 0;
488  if(vl)
489  n = fmi2_import_get_variable_list_size(vl);
490  if(n>0) {
491  printf("Listing inputs: \n");
492  for(i = 0;i<n;i++)
493  printf("\t%s\n",fmi2_import_get_variable_name(fmi2_import_get_variable(vl, i)));
494  }
495  else {
496  printf("There are no inputs\n");
497  }
498  fmi2_import_free_variable_list(vl);
499  }
500  {
501  fmi2_import_variable_list_t* states = fmi2_import_get_states_list( fmu);
502  fmi2_import_variable_list_t* inputs = fmi2_import_get_inputs_list( fmu);
503  size_t n = 0;
504  if(states)
505  n = fmi2_import_get_variable_list_size(states);
506  if(n>0) {
507  size_t *start, *dep;
508  char* factor;
509  printf("Listing states and dependencies on inputs: \n");
510  fmi2_import_get_dependencies_derivatives_on_inputs(fmu, &start, &dep, &factor);
511  printDependenciesInfo( fmu, states, inputs, start, dep, factor);
512 
513  fmi2_import_get_dependencies_derivatives_on_states(fmu, &start, &dep, &factor);
514  if(start) {
515  printf("Listing states and dependencies on other states: \n");
516  printDependenciesInfo( fmu, states, states, start, dep, factor);
517  }
518  else {
519  printf("No dependencies on states available\n");
520  }
521  }
522  else {
523  printf("There are no states\n");
524  }
525  fmi2_import_free_variable_list(inputs);
526  fmi2_import_free_variable_list(states);
527  }
528  {
529  fmi2_import_variable_list_t* states = fmi2_import_get_states_list( fmu);
530  fmi2_import_variable_list_t* inputs = fmi2_import_get_inputs_list( fmu);
531  fmi2_import_variable_list_t* outputs = fmi2_import_get_outputs_list( fmu);
532  size_t n = 0;
533  if(outputs)
534  n = fmi2_import_get_variable_list_size(outputs);
535  if(n>0) {
536  size_t *start, *dep;
537  char* factor;
538  printf("Listing outputs and dependencies on inputs: \n");
539  fmi2_import_get_dependencies_outputs_on_inputs(fmu, &start, &dep, &factor);
540  printDependenciesInfo( fmu, outputs, inputs, start, dep, factor);
541 
542  fmi2_import_get_dependencies_outputs_on_states(fmu, &start, &dep, &factor);
543  if(start) {
544  printf("Listing outputs and dependencies on states: \n");
545  printDependenciesInfo( fmu, outputs, states, start, dep, factor);
546  }
547  else {
548  printf("No dependencies on states available\n");
549  }
550  }
551  else {
552  printf("There are no outputs\n");
553  }
554  fmi2_import_free_variable_list(outputs);
555  fmi2_import_free_variable_list(inputs);
556  fmi2_import_free_variable_list(states);
557  }
558 */
559  fmi2_import_free(fmu);
560  fmi_import_free_context(context);
561 
562  printf("Everything seems to be OK since you got this far=)!\n");
563 
564  do_exit(0);
565 }
566 
567 
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.
Definition: fmi2_enums.h:118
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.
Definition: fmi2_enums.h:201
jm_calloc_f calloc
Allocate zero initialized memory.
Definition: jm_callbacks.h:77
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.
size_t jm_callbacks * c
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.
Unrecoverable errors.
Definition: jm_types.h:54
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.
Definition: fmi2_enums.h:158
FMILIB_EXPORT const char * fmi2_import_get_author(fmi2_import_t *fmu)
Get FMU author.
int expect_error
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.
Definition: jm_types.h:51
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).
return v
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.
Definition: jm_callbacks.h:85
void do_exit(int code)
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.
v callbacks
int annotation_start_handle(void *context, const char *parentName, void *parent, const char *elm, const char **attr)
fmi1_capi_t * fmu
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.
Verbose messages.
Definition: jm_types.h:58
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.
Definition: jm_callbacks.h:75
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.
Definition: jm_callbacks.h:87
const char * jm_string
A constant string.
Definition: jm_types.h:33
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.
Definition: jm_callbacks.h:73
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.
Definition: jm_callbacks.h:79
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.
Definition: jm_callbacks.h:81
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 &#39;relativeQuantity&#39; flag.
jm_logger_f logger
Logging callback.
Definition: jm_callbacks.h:83
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.