2 Copyright (C) 2012 Modelon AB
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the BSD style license.
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.
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>.
19 #include <JM/jm_named_ptr.h>
20 #include "fmi1_import_impl.h"
21 #include "fmi1_import_variable_list_impl.h"
23 #include <FMI1/fmi1_types.h>
24 #include <FMI1/fmi1_functions.h>
25 #include <FMI1/fmi1_enums.h>
\r
26 #include <FMI1/fmi1_capi.h>
28 static const char* module = "FMILIB";
30 /*#include "fmi1_import_vendor_annotations_impl.h"
31 #include "fmi1_import_parser.h"
33 fmi1_import_t* fmi1_import_allocate(jm_callbacks* cb) {
34 fmi1_import_t* fmu = (fmi1_import_t*)cb->calloc(1, sizeof(fmi1_import_t));
36 if(!fmu || (jm_vector_init(char)(&fmu->logMessageBufferCoded,JM_MAX_ERROR_MESSAGE_SIZE,cb) < JM_MAX_ERROR_MESSAGE_SIZE)) {
37 jm_log_fatal(cb, module, "Could not allocate memory");
38 if(fmu) cb->free(fmu);
47 fmu->md = fmi1_xml_allocate_model_description(cb);
48 fmu->registerGlobally = 0;
49 jm_vector_init(char)(&fmu->logMessageBufferExpanded,0,cb);
59 const char* fmi1_import_get_last_error(fmi1_import_t* fmu) {
\r
60 return jm_get_last_error(fmu->callbacks);
\r
63 fmi1_import_t* fmi1_import_parse_xml( fmi_import_context_t* context, const char* dirPath) {
65 char absPath[FILENAME_MAX + 2];
68 int configuration = 0;
70 if(!context) return 0;
72 cb = context->callbacks;
74 xmlPath = fmi_import_get_model_description_path(dirPath, context->callbacks);
76 fmu = fmi1_import_allocate(context->callbacks);
79 context->callbacks->free(xmlPath);
83 jm_log_verbose( cb, "FMILIB", "Parsing model description XML");
85 /* convert the import configuration to the xml configuration */
86 if (context->configuration & FMI_IMPORT_NAME_CHECK) {
87 configuration |= FMI1_XML_NAME_CHECK;
90 if(fmi1_xml_parse_model_description( fmu->md, xmlPath, configuration)) {
91 fmi1_import_free(fmu);
97 fmu->dirPath = (char*)cb->calloc(strlen(dirPath) + 1, sizeof(char));
99 if(jm_get_dir_abspath(cb, dirPath, absPath, FILENAME_MAX + 2)) {
\r
100 fmu->location = fmi_import_create_URL_from_abs_path(cb, absPath);
\r
103 if ((fmu->dirPath == NULL) || (fmu->location == 0)){
104 jm_log_fatal( cb, "FMILIB", "Could not allocated memory");
105 fmi1_import_free(fmu);
109 strcpy(fmu->dirPath, dirPath);
111 jm_log_verbose( cb, "FMILIB", "Parsing finished successfully");
116 void fmi1_import_free(fmi1_import_t* fmu) {
117 jm_callbacks* cb = fmu->callbacks;
120 jm_log_verbose( fmu->callbacks, "FMILIB", "Releasing allocated library resources");
122 fmi1_import_destroy_dllfmu(fmu);
\r
123 fmi1_xml_free_model_description(fmu->md);
124 jm_vector_free_data(char)(&fmu->logMessageBufferCoded);
125 jm_vector_free_data(char)(&fmu->logMessageBufferExpanded);
127 cb->free(fmu->dirPath);
128 cb->free(fmu->location);
132 const char* fmi1_import_get_model_name(fmi1_import_t* fmu) {
134 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
137 return fmi1_xml_get_model_name(fmu->md);
140 const char* fmi1_import_get_model_identifier(fmi1_import_t* fmu) {
142 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
145 return fmi1_xml_get_model_identifier(fmu->md);
148 const char* fmi1_import_get_GUID(fmi1_import_t* fmu){
150 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
153 return fmi1_xml_get_GUID(fmu->md);
156 const char* fmi1_import_get_description(fmi1_import_t* fmu) {
158 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
161 return fmi1_xml_get_description(fmu->md);
164 const char* fmi1_import_get_author(fmi1_import_t* fmu) {
166 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
169 return fmi1_xml_get_author(fmu->md);
172 const char* fmi1_import_get_model_standard_version(fmi1_import_t* fmu) {
174 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
177 return fmi1_xml_get_model_standard_version(fmu->md);
180 const char* fmi1_import_get_model_version(fmi1_import_t* fmu) {
182 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
185 return fmi1_xml_get_model_version(fmu->md);
188 const char* fmi1_import_get_generation_tool(fmi1_import_t* fmu) {
190 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
193 return fmi1_xml_get_generation_tool(fmu->md);
196 const char* fmi1_import_get_generation_date_and_time(fmi1_import_t* fmu) {
198 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
201 return fmi1_xml_get_generation_date_and_time(fmu->md);
204 fmi1_variable_naming_convension_enu_t fmi1_import_get_naming_convention(fmi1_import_t* fmu) {
206 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
207 return fmi1_naming_enu_unknown;
209 return fmi1_xml_get_naming_convention(fmu->md);
212 unsigned int fmi1_import_get_number_of_continuous_states(fmi1_import_t* fmu) {
214 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
217 return fmi1_xml_get_number_of_continuous_states(fmu->md);
220 unsigned int fmi1_import_get_number_of_event_indicators(fmi1_import_t* fmu) {
222 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
225 return fmi1_xml_get_number_of_event_indicators(fmu->md);
228 double fmi1_import_get_default_experiment_start(fmi1_import_t* fmu) {
230 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
233 return fmi1_xml_get_default_experiment_start(fmu->md);
236 void fmi1_import_set_default_experiment_start(fmi1_import_t* fmu, double t) {
238 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
241 fmi1_xml_set_default_experiment_start(fmu->md, t);
244 double fmi1_import_get_default_experiment_stop(fmi1_import_t* fmu) {
246 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
249 return fmi1_xml_get_default_experiment_stop(fmu->md);
252 void fmi1_import_set_default_experiment_stop(fmi1_import_t* fmu, double t) {
254 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
257 fmi1_xml_set_default_experiment_stop(fmu->md, t);
260 double fmi1_import_get_default_experiment_tolerance(fmi1_import_t* fmu) {
262 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
265 return fmi1_xml_get_default_experiment_tolerance(fmu->md);
268 void fmi1_import_set_default_experiment_tolerance(fmi1_import_t* fmu, double tol) {
270 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
273 fmi1_xml_set_default_experiment_tolerance(fmu->md, tol);
276 fmi1_import_vendor_list_t* fmi1_import_get_vendor_list(fmi1_import_t* fmu) {
278 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
281 return fmi1_xml_get_vendor_list(fmu->md);
284 unsigned int fmi1_import_get_number_of_vendors(fmi1_import_vendor_list_t* vl) {
285 return fmi1_xml_get_number_of_vendors(vl);
288 fmi1_import_vendor_t* fmi1_import_get_vendor(fmi1_import_vendor_list_t* v, unsigned int index) {
289 return fmi1_xml_get_vendor(v, index);
292 fmi1_import_unit_definitions_t* fmi1_import_get_unit_definitions(fmi1_import_t* fmu) {
294 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
297 return fmi1_xml_get_unit_definitions(fmu->md);
300 unsigned int fmi1_import_get_unit_definitions_number(fmi1_import_unit_definitions_t* ud) {
301 return fmi1_xml_get_unit_definitions_number(ud);
304 fmi1_import_type_definitions_t* fmi1_import_get_type_definitions(fmi1_import_t* fmu) {
306 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
309 return fmi1_xml_get_type_definitions(fmu->md);
312 /* Get the list of all the variables in the model */
313 fmi1_import_variable_list_t* fmi1_import_get_variable_list(fmi1_import_t* fmu) {
314 jm_vector(jm_voidp)* vars;
315 fmi1_import_variable_list_t* vl;
318 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
321 vars = fmi1_xml_get_variables_original_order(fmu->md);
323 nv = jm_vector_get_size(jm_voidp)(vars);
326 vl = fmi1_import_alloc_variable_list(fmu, nv);
328 for(i = 0; i< nv; i++) {
329 jm_vector_set_item(jm_voidp)(&vl->variables, i, jm_vector_get_item(jm_voidp)(vars, i));
334 /* Get the list of all the variables in the model in alphabetical order */
335 fmi1_import_variable_list_t* fmi1_import_get_variable_list_alphabetical_order(fmi1_import_t* fmu) {
336 jm_vector(jm_named_ptr)* vars;
337 fmi1_import_variable_list_t* vl;
340 jm_log_error(fmu->callbacks, module,"No FMU is loaded");
343 vars = fmi1_xml_get_variables_alphabetical_order(fmu->md);
344 nv = jm_vector_get_size(jm_named_ptr)(vars);
345 vl = fmi1_import_alloc_variable_list(fmu, nv);
347 for(i = 0; i< nv; i++) {
348 jm_vector_set_item(jm_voidp)(&vl->variables, i, jm_vector_get_item(jm_named_ptr)(vars, i).ptr);