forked from OpenModelica/OpenModelica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation_input_xml.c
1210 lines (1074 loc) · 48 KB
/
simulation_input_xml.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2010, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THIS OSMC PUBLIC
* LICENSE (OSMC-PL). ANY USE, REPRODUCTION OR DISTRIBUTION OF
* THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THE OSMC
* PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköpings University, either from the above address,
* from the URL: http://www.ida.liu.se/projects/OpenModelica
* and in the OpenModelica distribution.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* file simulation_input_xml.c
* this file reads the model input from Model_init.xml
* file using the Expat XML parser.
* basically a structure with maps is created (see omc_ModelInput)
* and populated during the XML parser. after, the values from it
* are used to populate the outputs of the read_input_xml function.
*/
#include "simulation_input_xml.h"
#include "simulation_runtime.h"
#include "options.h"
#include "../util/omc_error.h"
#include "../util/omc_file.h"
#include "../meta/meta_modelica.h"
#include "../util/modelica_string.h"
#include <limits.h>
#include "../util/uthash.h"
#include <string.h>
#include <ctype.h>
#include <expat.h>
typedef struct hash_string_string
{
const char *id;
const char *val;
UT_hash_handle hh;
} hash_string_string;
typedef hash_string_string omc_ModelDescription;
typedef hash_string_string omc_DefaultExperiment;
typedef hash_string_string omc_ScalarVariable;
typedef struct hash_long_var
{
long id;
omc_ScalarVariable *val;
UT_hash_handle hh;
} hash_long_var;
typedef hash_long_var omc_ModelVariables;
typedef struct hash_string_long
{
const char *id;
long val;
UT_hash_handle hh;
} hash_string_long;
static inline const char* findHashStringStringNull(hash_string_string *ht, const char *key)
{
hash_string_string *res;
HASH_FIND_STR( ht, key, res );
return res ? res->val : NULL;
}
static inline const char* findHashStringStringEmpty(hash_string_string *ht, const char *key)
{
const char *res = findHashStringStringNull(ht,key);
return res ? res : "";
}
static inline const char* findHashStringString(hash_string_string *ht, const char *key)
{
const char *res = findHashStringStringNull(ht,key);
if (0==res) {
hash_string_string *c, *tmp;
HASH_ITER(hh, ht, c, tmp) {
fprintf(stderr, "HashMap contained: %s->%s\n", c->id, c->val);
}
throwStreamPrint(NULL, "Failed to lookup %s in hashmap %p", key, ht);
}
return res;
}
static inline void addHashStringString(hash_string_string **ht, const char *key, const char *val)
{
hash_string_string *v = (hash_string_string*) calloc(1, sizeof(hash_string_string)); /* FIXME this isn't always freed correctly */
v->id=strdup(key);
v->val=strdup(val);
HASH_ADD_KEYPTR( hh, *ht, v->id, strlen(v->id), v );
}
static inline long findHashStringLongOrZero(hash_string_long *ht, const char *key)
{
hash_string_long *res;
HASH_FIND_STR( ht, key, res );
return res ? res->val : 0;
}
static inline long* findHashStringLongPtr(hash_string_long *ht, const char *key)
{
hash_string_long *res;
HASH_FIND_STR( ht, key, res );
return res ? &res->val : 0;
}
static inline void addHashStringLong(hash_string_long **ht, const char *key, long val)
{
hash_string_long *v2;
HASH_FIND_STR( *ht, key, v2 );
if (v2) {
v2->val = val;
} else {
hash_string_long *v = (hash_string_long*) calloc(1, sizeof(hash_string_long));
v->id=strdup(key);
v->val=val;
HASH_ADD_KEYPTR( hh, *ht, v->id, strlen(v->id), v );
}
}
static inline omc_ScalarVariable** findHashLongVar(hash_long_var *ht, long key)
{
hash_long_var *res;
HASH_FIND_INT( ht, &key, res );
if (0==res) {
hash_long_var *c, *tmp;
HASH_ITER(hh, ht, c, tmp) {
fprintf(stderr, "HashMap contained: %ld->*map*\n", c->id);
}
throwStreamPrint(NULL, "Failed to lookup %ld in hashmap %p", key, ht);
}
return &res->val;
}
static inline void addHashLongVar(hash_long_var **ht, long key, omc_ScalarVariable *val)
{
hash_long_var *v = (hash_long_var*) calloc(1, sizeof(hash_long_var));
v->id=key;
v->val=val;
HASH_ADD_INT( *ht, id, v );
}
static int endsWith(const char *str, const char *suffix) {
int str_len = strlen(str);
int suffix_len = strlen(suffix);
return (str_len >= suffix_len) && (0 == strcmp(str + (str_len-suffix_len), suffix));
}
/* maybe use a map below {"rSta" -> omc_ModelVariables} */
/* typedef map < string, omc_ModelVariables > omc_ModelVariablesClassified; */
/* structure used to collect data from the xml input file */
typedef struct omc_ModelInput
{
omc_ModelDescription *md; /* model description */
omc_DefaultExperiment *de; /* default experiment */
omc_ModelVariables *rSta; /* states */
omc_ModelVariables *rDer; /* derivatives */
omc_ModelVariables *rAlg; /* algebraic */
omc_ModelVariables *rPar; /* parameters */
omc_ModelVariables *rAli; /* aliases */
omc_ModelVariables *rSen; /* sensitivities */
omc_ModelVariables *iAlg; /* int algebraic */
omc_ModelVariables *iPar; /* int parameters */
omc_ModelVariables *iAli; /* int aliases */
omc_ModelVariables *bAlg; /* bool algebraic */
omc_ModelVariables *bPar; /* bool parameters */
omc_ModelVariables *bAli; /* bool aliases */
omc_ModelVariables *sAlg; /* string algebraic */
omc_ModelVariables *sPar; /* string parameters */
omc_ModelVariables *sAli; /* string aliases */
/* these two we need to know to be able to add
the stuff in <Real ... />, <String ... /> to
the correct variable in the correct map */
mmc_sint_t lastCI; /* index */
omc_ModelVariables** lastCT; /* type (classification) */
} omc_ModelInput;
// a map for overrides
typedef hash_string_string omc_CommandLineOverrides;
// a map to find out which names were used
#define OMC_OVERRIDE_UNUSED 0
#define OMC_OVERRIDE_USED 1
typedef hash_string_long omc_CommandLineOverridesUses;
// function to handle command line settings override
modelica_boolean doOverride(omc_ModelInput *mi, MODEL_DATA *modelData, const char *override, const char *overrideFile);
static const double REAL_MIN = -DBL_MAX;
static const double REAL_MAX = DBL_MAX;
static const double INTEGER_MIN = (double)MODELICA_INT_MIN;
/* Avoid integer overflow */
static const double INTEGER_MAX = (double)MODELICA_INT_MAX;
/* reads double value from a string */
static void read_value_real(const char *s, modelica_real* res, modelica_real default_value);
/* reads integer value from a string */
static void read_value_long(const char *s, modelica_integer* res, modelica_integer default_value);
/* reads integer value from a string */
static void read_value_int(const char *s, int* res);
/* reads modelica_string value from a string */
static void read_value_string(const char *s, const char** str);
/* reads boolean value from a string */
static void read_value_bool(const char *s, modelica_boolean* str);
static void XMLCALL startElement(void *userData, const char *name, const char **attr)
{
omc_ModelInput* mi = (omc_ModelInput*)userData;
mmc_sint_t i = 0;
/* handle fmiModelDescription */
if(!strcmp(name, "fmiModelDescription")) {
for(i = 0; attr[i]; i += 2) {
addHashStringString(&mi->md, attr[i], attr[i+1]);
}
return;
}
/* handle DefaultExperiment */
if(!strcmp(name, "DefaultExperiment")) {
for(i = 0; attr[i]; i += 2) {
addHashStringString(&mi->de, attr[i], attr[i+1]);
}
return;
}
/* handle ScalarVariable */
if(!strcmp(name, "ScalarVariable"))
{
omc_ScalarVariable *v = NULL, *vfind;
const char *ci, *ct;
int fail=0;
mi->lastCI = -1;
mi->lastCT = NULL;
for(i = 0; attr[i]; i += 2) {
addHashStringString(&v, attr[i], attr[i+1]);
}
/* fetch the class index/type */
ci = findHashStringString(v, "classIndex");
ct = findHashStringString(v, "classType");
/* transform to mmc_sint_t */
mi->lastCI = atoi(ci);
/* which one of the classifications? */
if (strlen(ct) == 4) {
if (ct[0]=='r') {
if (0 == strcmp(ct+1,"Sta")) {
mi->lastCT = &mi->rSta;
} else if (0 == strcmp(ct+1,"Der")) {
mi->lastCT = &mi->rDer;
} else if (0 == strcmp(ct+1,"Alg")) {
mi->lastCT = &mi->rAlg;
} else if (0 == strcmp(ct+1,"Par")) {
mi->lastCT = &mi->rPar;
} else if (0 == strcmp(ct+1,"Ali")) {
mi->lastCT = &mi->rAli;
} else if (0 == strcmp(ct+1,"Sen")) {
mi->lastCT = &mi->rSen;
} else {
fail = 1;
}
} else if (ct[0]=='i') {
if (0 == strcmp(ct+1,"Alg")) {
mi->lastCT = &mi->iAlg;
} else if (0 == strcmp(ct+1,"Par")) {
mi->lastCT = &mi->iPar;
} else if (0 == strcmp(ct+1,"Ali")) {
mi->lastCT = &mi->iAli;
} else {
fail = 1;
}
} else if (ct[0]=='b') {
if (0 == strcmp(ct+1,"Alg")) {
mi->lastCT = &mi->bAlg;
} else if (0 == strcmp(ct+1,"Par")) {
mi->lastCT = &mi->bPar;
} else if (0 == strcmp(ct+1,"Ali")) {
mi->lastCT = &mi->bAli;
} else {
fail = 1;
}
} else if (ct[0]=='s') {
if (0 == strcmp(ct+1,"Alg")) {
mi->lastCT = &mi->sAlg;
} else if (0 == strcmp(ct+1,"Par")) {
mi->lastCT = &mi->sPar;
} else if (0 == strcmp(ct+1,"Ali")) {
mi->lastCT = &mi->sAli;
} else {
fail = 1;
}
} else {
fail = 1;
}
} else {
fail = 1;
}
if (fail) {
throwStreamPrint(NULL, "simulation_input_xml.c: error reading the xml file, found unknown class: %s for variable: %s",ct,findHashStringString(v,"name"));
}
/* add the ScalarVariable map to the correct map! */
addHashLongVar(mi->lastCT, mi->lastCI, v);
return;
}
/* handle Real/Integer/Boolean/String */
if(!strcmp(name, "Real") || !strcmp(name, "Integer") || !strcmp(name, "Boolean") || !strcmp(name, "String")) {
/* add keys/value to the last variable */
for(i = 0; attr[i]; i += 2) {
/* add more key/value pairs to the last variable */
addHashStringString(findHashLongVar(*mi->lastCT, mi->lastCI), attr[i], attr[i+1]);
}
addHashStringString(findHashLongVar(*mi->lastCT, mi->lastCI), "variableType", name);
return;
}
/* anything else, we don't handle! */
}
static void XMLCALL endElement(void *userData, const char *name)
{
/* do nothing! */
}
static void read_var_info(omc_ScalarVariable *v, VAR_INFO *info)
{
modelica_integer inputIndex;
read_value_string(findHashStringString(v,"name"), &info->name);
debugStreamPrint(LOG_DEBUG, 1, "read var %s from setup file", info->name);
read_value_long(findHashStringStringNull(v,"inputIndex"), &inputIndex, -1);
info->inputIndex = inputIndex;
debugStreamPrint(LOG_DEBUG, 0, "read input index %d from setup file", info->inputIndex);
read_value_int(findHashStringString(v,"valueReference"), &info->id);
debugStreamPrint(LOG_DEBUG, 0, "read for %s id %d from setup file", info->name, info->id);
read_value_string(findHashStringStringEmpty(v,"description"), &info->comment);
debugStreamPrint(LOG_DEBUG, 0, "read for %s description \"%s\" from setup file", info->name, info->comment);
read_value_string(findHashStringString(v,"fileName"), &info->info.filename);
debugStreamPrint(LOG_DEBUG, 0, "read for %s filename %s from setup file", info->name, info->info.filename);
read_value_long(findHashStringString(v,"startLine"), (modelica_integer*)&(info->info.lineStart), 0);
debugStreamPrint(LOG_DEBUG, 0, "read for %s lineStart %d from setup file", info->name, info->info.lineStart);
read_value_long(findHashStringString(v,"startColumn"), (modelica_integer*)&(info->info.colStart), 0);
debugStreamPrint(LOG_DEBUG, 0, "read for %s colStart %d from setup file", info->name, info->info.colStart);
read_value_long(findHashStringString(v,"endLine"), (modelica_integer*)&(info->info.lineEnd), 0);
debugStreamPrint(LOG_DEBUG, 0, "read for %s lineEnd %d from setup file", info->name, info->info.lineEnd);
read_value_long(findHashStringString(v,"endColumn"), (modelica_integer*)&(info->info.colEnd), 0);
debugStreamPrint(LOG_DEBUG, 0, "read for %s colEnd %d from setup file", info->name, info->info.colEnd);
read_value_long(findHashStringString(v,"fileWritable"), (modelica_integer*)&(info->info.readonly), 0);
debugStreamPrint(LOG_DEBUG, 0, "read for %s readonly %d from setup file", info->name, info->info.readonly);
if (DEBUG_STREAM(LOG_DEBUG)) messageClose(LOG_DEBUG);
}
static void read_var_attribute_real(omc_ScalarVariable *v, REAL_ATTRIBUTE *attribute)
{
const char *unit = NULL;
const char *displayUnit = NULL;
read_value_real(findHashStringStringEmpty(v,"start"), &(attribute->start), 0.0);
read_value_bool(findHashStringString(v,"fixed"), (modelica_boolean*)&(attribute->fixed));
read_value_bool(findHashStringString(v,"useNominal"), (modelica_boolean*)&(attribute->useNominal));
read_value_real(findHashStringStringEmpty(v,"nominal"), &(attribute->nominal), 1.0);
read_value_real(findHashStringStringEmpty(v,"min"), &(attribute->min), REAL_MIN);
read_value_real(findHashStringStringEmpty(v,"max"), &(attribute->max), REAL_MAX);
read_value_string(findHashStringStringEmpty(v,"unit"), &unit);
attribute->unit = mmc_mk_scon_persist(unit); /* this function returns a copy, so unit can be freed */
free((char*)unit);
// read displayUnit
read_value_string(findHashStringStringEmpty(v,"displayUnit"), &displayUnit);
attribute->displayUnit = mmc_mk_scon_persist(displayUnit); /* this function returns a copy, so unit can be freed */
free((char*)displayUnit);
infoStreamPrint(LOG_DEBUG, 0, "Real %s(start=%g, fixed=%s, %snominal=%g%s, min=%g, max=%g)", findHashStringString(v,"name"), attribute->start, (attribute->fixed)?"true":"false", (attribute->useNominal)?"":"{", attribute->nominal, attribute->useNominal?"":"}", attribute->min, attribute->max);
}
static void read_var_attribute_int(omc_ScalarVariable *v, INTEGER_ATTRIBUTE *attribute)
{
read_value_long(findHashStringStringEmpty(v,"start"), &attribute->start, 0);
read_value_bool(findHashStringString(v,"fixed"), &attribute->fixed);
read_value_long(findHashStringStringEmpty(v,"min"), &attribute->min, INTEGER_MIN);
read_value_long(findHashStringStringEmpty(v,"max"), &attribute->max, INTEGER_MAX);
infoStreamPrint(LOG_DEBUG, 0, "Integer %s(start=%ld, fixed=%s, min=%ld, max=%ld)", findHashStringString(v,"name"), attribute->start, attribute->fixed?"true":"false", attribute->min, attribute->max);
}
static void read_var_attribute_bool(omc_ScalarVariable *v, BOOLEAN_ATTRIBUTE *attribute)
{
read_value_bool(findHashStringStringEmpty(v,"start"), &attribute->start);
read_value_bool(findHashStringString(v,"fixed"), &attribute->fixed);
infoStreamPrint(LOG_DEBUG, 0, "Boolean %s(start=%s, fixed=%s)", findHashStringString(v,"name"), attribute->start?"true":"false", attribute->fixed?"true":"false");
}
static void read_var_attribute_string(omc_ScalarVariable *v, STRING_ATTRIBUTE *attribute)
{
const char *start = NULL;
read_value_string(findHashStringStringEmpty(v,"start"), &start);
attribute->start = mmc_mk_scon_persist(start); /* this function returns a copy, so start can be freed */
free((char*)start);
infoStreamPrint(LOG_DEBUG, 0, "String %s(start=%s)", findHashStringString(v,"name"), MMC_STRINGDATA(attribute->start));
}
/* \brief
* Reads initial values from a text file.
*
* The textfile should be given as argument to the main function using
* the -f file flag.
*/
void read_input_xml(MODEL_DATA* modelData,
SIMULATION_INFO* simulationInfo)
{
omc_ModelInput mi = {0};
const char *filename, *guid, *override, *overrideFile;
FILE* file = NULL;
XML_Parser parser = NULL;
hash_string_long *mapAlias = NULL, *mapAliasParam = NULL, *mapAliasSen = NULL;
long *it, *itParam;
mmc_sint_t i;
int inputIndex = 0;
int k = 0;
modelica_integer nxchk, nychk, npchk;
modelica_integer nyintchk, npintchk;
modelica_integer nyboolchk, npboolchk;
modelica_integer nystrchk, npstrchk;
if(NULL == modelData->initXMLData)
{
/* read the filename from the command line (if any) */
if (omc_flag[FLAG_F]) {
filename = omc_flagValue[FLAG_F];
} else if (omc_flag[FLAG_INPUT_PATH]) { /* read the input path from the command line (if any) */
if (0 > GC_asprintf(&filename, "%s/%s_init.xml", omc_flagValue[FLAG_INPUT_PATH], modelData->modelFilePrefix)) {
throwStreamPrint(NULL, "simulation_input_xml.c: Error: can not allocate memory.");
}
} else {
/* no file given on the command line? use the default
* model_name defined in generated code for model.*/
if (0 > GC_asprintf(&filename, "%s_init.xml", modelData->modelFilePrefix)) {
throwStreamPrint(NULL, "simulation_input_xml.c: Error: can not allocate memory.");
}
}
/* open the file and fail on error. we open it read-write to be sure other processes can overwrite it */
file = omc_fopen(filename, "r");
if(!file) {
throwStreamPrint(NULL, "simulation_input_xml.c: Error: can not read file %s as setup file to the generated simulation code.",filename);
}
}
/* create the XML parser */
parser = XML_ParserCreate(NULL);
if(!parser)
{
fclose(file);
throwStreamPrint(NULL, "simulation_input_xml.c: Error: couldn't allocate memory for the XML parser!");
}
/* set our user data */
XML_SetUserData(parser, &mi);
/* set the handlers for start/end of element. */
XML_SetElementHandler(parser, startElement, endElement);
if(NULL == modelData->initXMLData)
{
int done;
char buf[BUFSIZ] = {0};
do
{
size_t len = omc_fread(buf, 1, sizeof(buf), file, 1);
done = len < sizeof(buf);
if(XML_STATUS_ERROR == XML_Parse(parser, buf, len, done))
{
fclose(file);
warningStreamPrint(LOG_STDOUT, 0, "simulation_input_xml.c: Error: failed to read the XML file %s: %s at line %lu\n",
filename,
XML_ErrorString(XML_GetErrorCode(parser)),
XML_GetCurrentLineNumber(parser));
XML_ParserFree(parser);
throwStreamPrint(NULL, "see last warning");
}
}while(!done);
fclose(file);
} else if(XML_STATUS_ERROR == XML_Parse(parser, modelData->initXMLData, strlen(modelData->initXMLData), 1)) { /* Got the full string already */
fprintf(stderr, "%s, %s %lu\n", modelData->initXMLData, XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser));
warningStreamPrint(LOG_STDOUT, 0, "simulation_input_xml.c: Error: failed to read the XML data %s: %s at line %lu\n",
modelData->initXMLData,
XML_ErrorString(XML_GetErrorCode(parser)),
XML_GetCurrentLineNumber(parser));
XML_ParserFree(parser);
throwStreamPrint(NULL, "see last warning");
}
/* now we should have all the data inside omc_ModelInput mi. */
/* first, check the modelGUID!
TODO! FIXME! THIS SEEMS TO FAIL!
ARE WE READING THE OLD XML FILE?? */
guid = findHashStringStringNull(mi.md,"guid");
if (NULL==guid) {
warningStreamPrint(LOG_STDOUT, 0, "The Model GUID: %s is not set in file: %s",
modelData->modelGUID,
filename);
} else if (strcmp(modelData->modelGUID, guid)) {
XML_ParserFree(parser);
warningStreamPrint(LOG_STDOUT, 0, "Error, the GUID: %s from input data file: %s does not match the GUID compiled in the model: %s",
guid,
filename,
modelData->modelGUID);
throwStreamPrint(NULL, "see last warning");
}
// deal with override
override = omc_flagValue[FLAG_OVERRIDE];
overrideFile = omc_flagValue[FLAG_OVERRIDE_FILE];
modelica_boolean reCalcStepSize = doOverride(&mi, modelData, override, overrideFile);
/* read all the DefaultExperiment values */
infoStreamPrint(LOG_SIMULATION, 1, "read all the DefaultExperiment values:");
read_value_real(findHashStringString(mi.de,"startTime"), &(simulationInfo->startTime), 0);
infoStreamPrint(LOG_SIMULATION, 0, "startTime = %g", simulationInfo->startTime);
read_value_real(findHashStringString(mi.de,"stopTime"), &(simulationInfo->stopTime), 1.0);
infoStreamPrint(LOG_SIMULATION, 0, "stopTime = %g", simulationInfo->stopTime);
if (reCalcStepSize) {
simulationInfo->stepSize = (simulationInfo->stopTime - simulationInfo->startTime) / 500;
warningStreamPrint(LOG_STDOUT, 1, "Start or stop time was overwritten, but no new integrator step size was provided.");
infoStreamPrint(LOG_STDOUT, 0, "Re-calculating step size for 500 intervals.");
infoStreamPrint(LOG_STDOUT, 0, "Add `stepSize=<value>` to `-override=` or override file to silence this warning.");
messageClose(LOG_STDOUT);
} else {
read_value_real(findHashStringString(mi.de,"stepSize"), &(simulationInfo->stepSize), (simulationInfo->stopTime - simulationInfo->startTime) / 500);
}
infoStreamPrint(LOG_SIMULATION, 0, "stepSize = %g", simulationInfo->stepSize);
read_value_real(findHashStringString(mi.de,"tolerance"), &(simulationInfo->tolerance), 1e-5);
infoStreamPrint(LOG_SIMULATION, 0, "tolerance = %g", simulationInfo->tolerance);
read_value_string(findHashStringString(mi.de,"solver"), &simulationInfo->solverMethod);
infoStreamPrint(LOG_SIMULATION, 0, "solver method: %s", simulationInfo->solverMethod);
read_value_string(findHashStringString(mi.de,"outputFormat"), &(simulationInfo->outputFormat));
infoStreamPrint(LOG_SIMULATION, 0, "output format: %s", simulationInfo->outputFormat);
read_value_string(findHashStringString(mi.de,"variableFilter"), &(simulationInfo->variableFilter));
infoStreamPrint(LOG_SIMULATION, 0, "variable filter: %s", simulationInfo->variableFilter);
read_value_string(findHashStringString(mi.md,"OPENMODELICAHOME"), &simulationInfo->OPENMODELICAHOME);
infoStreamPrint(LOG_SIMULATION, 0, "OPENMODELICAHOME: %s", simulationInfo->OPENMODELICAHOME);
messageClose(LOG_SIMULATION);
read_value_long(findHashStringString(mi.md,"numberOfContinuousStates"), &nxchk, 0);
read_value_long(findHashStringString(mi.md,"numberOfRealAlgebraicVariables"), &nychk, 0);
read_value_long(findHashStringString(mi.md,"numberOfRealParameters"), &npchk, 0);
read_value_long(findHashStringString(mi.md,"numberOfIntegerParameters"), &npintchk, 0);
read_value_long(findHashStringString(mi.md,"numberOfIntegerAlgebraicVariables"), &nyintchk, 0);
read_value_long(findHashStringString(mi.md,"numberOfBooleanParameters"), &npboolchk, 0);
read_value_long(findHashStringString(mi.md,"numberOfBooleanAlgebraicVariables"), &nyboolchk, 0);
read_value_long(findHashStringString(mi.md,"numberOfStringParameters"), &npstrchk, 0);
read_value_long(findHashStringString(mi.md,"numberOfStringAlgebraicVariables"), &nystrchk, 0);
if(nxchk != modelData->nStates
|| nychk != modelData->nVariablesReal - 2*modelData->nStates
|| npchk != modelData->nParametersReal
|| npintchk != modelData->nParametersInteger
|| nyintchk != modelData->nVariablesInteger
|| npboolchk != modelData->nParametersBoolean
|| nyboolchk != modelData->nVariablesBoolean
|| npstrchk != modelData->nParametersString
|| nystrchk != modelData->nVariablesString)
{
if (ACTIVE_WARNING_STREAM(LOG_SIMULATION))
{
warningStreamPrint(LOG_SIMULATION, 1, "Error, input data file does not match model.");
warningStreamPrint(LOG_SIMULATION, 0, "nx in setup file: %ld from model code: %d", nxchk, (int)modelData->nStates);
warningStreamPrint(LOG_SIMULATION, 0, "ny in setup file: %ld from model code: %ld", nychk, modelData->nVariablesReal - 2*modelData->nStates);
warningStreamPrint(LOG_SIMULATION, 0, "np in setup file: %ld from model code: %ld", npchk, modelData->nParametersReal);
warningStreamPrint(LOG_SIMULATION, 0, "npint in setup file: %ld from model code: %ld", npintchk, modelData->nParametersInteger);
warningStreamPrint(LOG_SIMULATION, 0, "nyint in setup file: %ld from model code: %ld", nyintchk, modelData->nVariablesInteger);
warningStreamPrint(LOG_SIMULATION, 0, "npbool in setup file: %ld from model code: %ld", npboolchk, modelData->nParametersBoolean);
warningStreamPrint(LOG_SIMULATION, 0, "nybool in setup file: %ld from model code: %ld", nyboolchk, modelData->nVariablesBoolean);
warningStreamPrint(LOG_SIMULATION, 0, "npstr in setup file: %ld from model code: %ld", npstrchk, modelData->nParametersString);
warningStreamPrint(LOG_SIMULATION, 0, "nystr in setup file: %ld from model code: %ld", nystrchk, modelData->nVariablesString);
messageClose(LOG_SIMULATION);
}
XML_ParserFree(parser);
EXIT(-1);
}
/* general check for filtering the output for a variable
* defined here to be reused everywhere
* the check is like this:
* - we filter if isProtected (protected variables)
* - we filter if annotation(HideResult=true)
* - we emit (remove filtering) if !encrypted && emitProtected && isProtected
* - we emit (remove filtering) if ignoreHideResult && annotation(HideResult=true)
*/
#define setFilterOuput(v, s, n, e) \
{ \
int ep = omc_flag[FLAG_EMIT_PROTECTED]; \
int ihr = omc_flag[FLAG_IGNORE_HIDERESULT]; \
const char *ipstr = findHashStringString((v), "isProtected"); \
const char *hrstr = findHashStringString((v), "hideResult"); \
int ipcmptrue = (0 == strcmp(ipstr, "true")); \
int hrcmptrue = (0 == strcmp(hrstr, "true")); \
if (ipcmptrue) \
{ \
infoStreamPrint(LOG_DEBUG, 0, "filtering protected variable %s", (n)); \
(s).filterOutput = 1; \
} \
if (hrcmptrue) \
{ \
infoStreamPrint(LOG_DEBUG, 0, "filtering variable %s due to HideResult annotation", (n)); \
(s).filterOutput = 1; \
} \
if (!e && ep && ipcmptrue) \
{ \
infoStreamPrint(LOG_DEBUG, 0, "emitting protected variable %s due to flag %s", (n), omc_flagValue[FLAG_EMIT_PROTECTED]); \
(s).filterOutput = 0; \
} \
if (ihr && hrcmptrue) \
{ \
infoStreamPrint(LOG_DEBUG, 0, "emitting variable %s with HideResult=true annotation due to flag %s", (n), omc_flagValue[FLAG_IGNORE_HIDERESULT]); \
(s).filterOutput = 0; \
} \
}
/* read all static data from File for every variable */
#define READ_VARIABLES(out, in, attributeKind, read_var_attribute, debugName, start, nStates, mapAlias, e) \
infoStreamPrint(LOG_DEBUG, 1, "read xml file for %s", debugName); \
for(i = 0; i < nStates; i++) \
{ \
mmc_sint_t j = start+i; \
VAR_INFO *info = &out[j].info; \
attributeKind *attribute = &out[j].attribute; \
omc_ScalarVariable *v = *findHashLongVar(in, i); \
read_var_info(v, info); \
read_var_attribute(v, attribute); \
setFilterOuput(v, out[j], info->name, (e || endsWith(info->info.filename, ".moc"))); \
addHashStringLong(&mapAlias, info->name, j); /* create a mapping for Alias variable to get the correct index */ \
debugStreamPrint(LOG_DEBUG, 0, "real %s: mapAlias[%s] = %ld", debugName, info->name, (long) j); \
if (omc_flag[FLAG_IDAS] && 0 == strcmp(debugName, "real sensitivities")) \
{ \
if (0 == strcmp(findHashStringString(v, "isValueChangeable"), "true")) \
{ \
long *it = findHashStringLongPtr(mapAliasParam, info->name); \
simulationInfo->sensitivityParList[k] = *it; \
infoStreamPrint(LOG_SOLVER, 0, "%d. sensitivity parameter %s at index %d", k, info->name, simulationInfo->sensitivityParList[k]); \
k++; \
} \
} \
} \
messageClose(LOG_DEBUG);
READ_VARIABLES(modelData->realVarsData,mi.rSta,REAL_ATTRIBUTE,read_var_attribute_real,"real states",0,modelData->nStates,mapAlias,modelData->encrypted);
READ_VARIABLES(modelData->realVarsData,mi.rDer,REAL_ATTRIBUTE,read_var_attribute_real,"real state derivatives",modelData->nStates,modelData->nStates,mapAlias,modelData->encrypted);
READ_VARIABLES(modelData->realVarsData,mi.rAlg,REAL_ATTRIBUTE,read_var_attribute_real,"real algebraics",2*modelData->nStates,modelData->nVariablesReal - 2*modelData->nStates,mapAlias,modelData->encrypted);
READ_VARIABLES(modelData->integerVarsData,mi.iAlg,INTEGER_ATTRIBUTE,read_var_attribute_int,"integer variables",0,modelData->nVariablesInteger,mapAlias,modelData->encrypted);
READ_VARIABLES(modelData->booleanVarsData,mi.bAlg,BOOLEAN_ATTRIBUTE,read_var_attribute_bool,"boolean variables",0,modelData->nVariablesBoolean,mapAlias,modelData->encrypted);
READ_VARIABLES(modelData->stringVarsData,mi.sAlg,STRING_ATTRIBUTE,read_var_attribute_string,"string variables",0,modelData->nVariablesString,mapAlias,modelData->encrypted);
READ_VARIABLES(modelData->realParameterData,mi.rPar,REAL_ATTRIBUTE,read_var_attribute_real,"real parameters",0,modelData->nParametersReal,mapAliasParam,modelData->encrypted);
READ_VARIABLES(modelData->integerParameterData,mi.iPar,INTEGER_ATTRIBUTE,read_var_attribute_int,"integer parameters",0,modelData->nParametersInteger,mapAliasParam,modelData->encrypted);
READ_VARIABLES(modelData->booleanParameterData,mi.bPar,BOOLEAN_ATTRIBUTE,read_var_attribute_bool,"boolean parameters",0,modelData->nParametersBoolean,mapAliasParam,modelData->encrypted);
READ_VARIABLES(modelData->stringParameterData,mi.sPar,STRING_ATTRIBUTE,read_var_attribute_string,"string parameters",0,modelData->nParametersString,mapAliasParam,modelData->encrypted);
if (omc_flag[FLAG_IDAS])
{
READ_VARIABLES(modelData->realSensitivityData,mi.rSen,REAL_ATTRIBUTE,read_var_attribute_real,"real sensitivities",0, modelData->nSensitivityVars,mapAliasSen,modelData->encrypted);
}
/*
* real all alias vars
*/
infoStreamPrint(LOG_DEBUG, 1, "read xml file for real alias vars");
for(i=0; i<modelData->nAliasReal; i++)
{
const char *aliasTmp = NULL;
read_var_info(*findHashLongVar(mi.rAli,i), &modelData->realAlias[i].info);
read_value_string(findHashStringStringNull(*findHashLongVar(mi.rAli,i),"alias"), &aliasTmp);
if (0 == strcmp(aliasTmp,"negatedAlias")) {
modelData->realAlias[i].negate = 1;
} else {
modelData->realAlias[i].negate = 0;
}
infoStreamPrint(LOG_DEBUG, 0, "read for %s negated %d from setup file", modelData->realAlias[i].info.name, modelData->realAlias[i].negate);
setFilterOuput(*findHashLongVar(mi.rAli,i), modelData->realAlias[i], modelData->realAlias[i].info.name, (modelData->encrypted || endsWith(modelData->realAlias[i].info.info.filename, ".moc")));
free((char*)aliasTmp);
aliasTmp = NULL;
read_value_string(findHashStringStringNull(*findHashLongVar(mi.rAli,i),"aliasVariable"), &aliasTmp);
it = findHashStringLongPtr(mapAlias, aliasTmp);
itParam = findHashStringLongPtr(mapAliasParam, aliasTmp);
if (NULL != it) {
modelData->realAlias[i].nameID = *it;
modelData->realAlias[i].aliasType = 0;
} else if (NULL != itParam) {
modelData->realAlias[i].nameID = *itParam;
modelData->realAlias[i].aliasType = 1;
} else if (0==strcmp(aliasTmp,"time")) {
modelData->realAlias[i].aliasType = 2;
} else {
throwStreamPrint(NULL, "Real Alias variable %s not found.", aliasTmp);
}
debugStreamPrint(LOG_DEBUG, 0, "read for %s aliasID %d from %s from setup file",
modelData->realAlias[i].info.name,
modelData->realAlias[i].nameID,
modelData->realAlias[i].aliasType ? ((modelData->realAlias[i].aliasType==2) ? "time" : "real parameters") : "real variables");
free((char*)aliasTmp);
}
messageClose(LOG_DEBUG);
/*
* integer all alias vars
*/
infoStreamPrint(LOG_DEBUG, 1, "read xml file for integer alias vars");
for(i=0; i<modelData->nAliasInteger; i++)
{
const char *aliasTmp = NULL;
read_var_info(*findHashLongVar(mi.iAli,i), &modelData->integerAlias[i].info);
read_value_string(findHashStringStringNull(*findHashLongVar(mi.iAli,i),"alias"), &aliasTmp);
if (0 == strcmp(aliasTmp,"negatedAlias")) {
modelData->integerAlias[i].negate = 1;
} else {
modelData->integerAlias[i].negate = 0;
}
infoStreamPrint(LOG_DEBUG, 0, "read for %s negated %d from setup file",modelData->integerAlias[i].info.name,modelData->integerAlias[i].negate);
setFilterOuput(*findHashLongVar(mi.iAli,i), modelData->integerAlias[i], modelData->integerAlias[i].info.name, (modelData->encrypted || endsWith(modelData->integerAlias[i].info.info.filename, ".moc")));
free((char*)aliasTmp);
aliasTmp = NULL;
read_value_string(findHashStringString(*findHashLongVar(mi.iAli,i),"aliasVariable"), &aliasTmp);
it = findHashStringLongPtr(mapAlias, aliasTmp);
itParam = findHashStringLongPtr(mapAliasParam, aliasTmp);
if(NULL != it) {
modelData->integerAlias[i].nameID = *it;
modelData->integerAlias[i].aliasType = 0;
} else if(NULL != itParam) {
modelData->integerAlias[i].nameID = *itParam;
modelData->integerAlias[i].aliasType = 1;
} else {
throwStreamPrint(NULL, "Integer Alias variable %s not found.", aliasTmp);
}
debugStreamPrint(LOG_DEBUG, 0, "read for %s aliasID %d from %s from setup file",
modelData->integerAlias[i].info.name,
modelData->integerAlias[i].nameID,
modelData->integerAlias[i].aliasType?"integer parameters":"integer variables");
free((char*)aliasTmp);
}
messageClose(LOG_DEBUG);
/*
* boolean all alias vars
*/
infoStreamPrint(LOG_DEBUG, 1, "read xml file for boolean alias vars");
for(i=0; i<modelData->nAliasBoolean; i++)
{
const char *aliasTmp = NULL;
read_var_info(*findHashLongVar(mi.bAli,i), &modelData->booleanAlias[i].info);
read_value_string(findHashStringString(*findHashLongVar(mi.bAli,i),"alias"), &aliasTmp);
if (0 == strcmp(aliasTmp,"negatedAlias")) {
modelData->booleanAlias[i].negate = 1;
} else {
modelData->booleanAlias[i].negate = 0;
}
infoStreamPrint(LOG_DEBUG, 0, "read for %s negated %d from setup file", modelData->booleanAlias[i].info.name, modelData->booleanAlias[i].negate);
setFilterOuput(*findHashLongVar(mi.bAli,i), modelData->booleanAlias[i], modelData->booleanAlias[i].info.name, (modelData->encrypted || endsWith(modelData->booleanAlias[i].info.info.filename, ".moc")));
free((char*)aliasTmp);
aliasTmp = NULL;
read_value_string(findHashStringString(*findHashLongVar(mi.bAli,i),"aliasVariable"), &aliasTmp);
it = findHashStringLongPtr(mapAlias, aliasTmp);
itParam = findHashStringLongPtr(mapAliasParam, aliasTmp);
if (NULL != it) {
modelData->booleanAlias[i].nameID = *it;
modelData->booleanAlias[i].aliasType = 0;
} else if (NULL != itParam) {
modelData->booleanAlias[i].nameID = *itParam;
modelData->booleanAlias[i].aliasType = 1;
} else {
throwStreamPrint(NULL, "Boolean Alias variable %s not found.", aliasTmp);
}
debugStreamPrint(LOG_DEBUG, 0, "read for %s aliasID %d from %s from setup file",
modelData->booleanAlias[i].info.name,
modelData->booleanAlias[i].nameID,
modelData->booleanAlias[i].aliasType ? "boolean parameters" : "boolean variables");
free((char*)aliasTmp);
}
messageClose(LOG_DEBUG);
/*
* string all alias vars
*/
infoStreamPrint(LOG_DEBUG, 1, "read xml file for string alias vars");
for(i=0; i<modelData->nAliasString; i++)
{
const char *aliasTmp = NULL;
read_var_info(*findHashLongVar(mi.sAli,i), &modelData->stringAlias[i].info);
read_value_string(findHashStringString(*findHashLongVar(mi.sAli,i),"alias"), &aliasTmp);
if (0 == strcmp(aliasTmp,"negatedAlias")) {
modelData->stringAlias[i].negate = 1;
} else {
modelData->stringAlias[i].negate = 0;
}
infoStreamPrint(LOG_DEBUG, 0, "read for %s negated %d from setup file", modelData->stringAlias[i].info.name, modelData->stringAlias[i].negate);
setFilterOuput(*findHashLongVar(mi.sAli,i), modelData->stringAlias[i], modelData->stringAlias[i].info.name, (modelData->encrypted || endsWith(modelData->stringAlias[i].info.info.filename, ".moc")));
free((char*)aliasTmp);
aliasTmp = NULL;
read_value_string(findHashStringString(*findHashLongVar(mi.sAli,i),"aliasVariable"), &aliasTmp);
it = findHashStringLongPtr(mapAlias, aliasTmp);
itParam = findHashStringLongPtr(mapAliasParam, aliasTmp);
if (NULL != it) {
modelData->stringAlias[i].nameID = *it;
modelData->stringAlias[i].aliasType = 0;
} else if (NULL != itParam) {
modelData->stringAlias[i].nameID = *itParam;
modelData->stringAlias[i].aliasType = 1;
} else {
throwStreamPrint(NULL, "String Alias variable %s not found.", aliasTmp);
}
debugStreamPrint(LOG_DEBUG, 0, "read for %s aliasID %d from %s from setup file",
modelData->stringAlias[i].info.name,
modelData->stringAlias[i].nameID,
modelData->stringAlias[i].aliasType ? "string parameters" : "string variables");
free((char*)aliasTmp);
}
messageClose(LOG_DEBUG);
XML_ParserFree(parser);
}
/* reads modelica_string value from a string */
static inline void read_value_string(const char *s, const char **str)
{
if(str == NULL)
{
warningStreamPrint(LOG_SIMULATION, 0, "error read_value, no data allocated for storing string");
return;
}
*str = strdup(s); /* memory is allocated here, must be freed by the caller */
}
/* reads double value from a string */
static inline void read_value_real(const char *s, modelica_real* res, modelica_real default_value)
{
if (*s == '\0') {
*res = default_value;
} else if (0 == strcmp(s, "true")) {
*res = 1.0;
} else if (0 == strcmp(s, "false")) {
*res = 0.0;
} else {
*res = atof(s);
}
}
/* reads boolean value from a string */
static inline void read_value_bool(const char *s, modelica_boolean* res)
{
*res = 0 == strcmp(s, "true");
}
/* reads integer value from a string */
static inline void read_value_long(const char *s, modelica_integer* res, modelica_integer default_value)
{
if (s == NULL || *s == '\0') {
*res = default_value;
} else if (0 == strcmp(s, "true")) {
*res = 1;
} else if (0 == strcmp(s, "false")) {
*res = 0;
} else {
*res = atol(s);
}
}
/* reads int value from a string */
static inline void read_value_int(const char *s, int* res)
{
if (0 == strcmp(s, "true")) {
*res = 1;
} else if (0 == strcmp(s, "false")) {
*res = 0;
} else {
*res = atoi(s);
}
}
static char* trim(char *str) {
char *res=str,*end=str+strlen(str)-1;
while (isspace(*res)) {
res++;
}
while (isspace(*end)) {
*end='\0';
end--;
}
return res;
}
static const char* getOverrideValue(omc_CommandLineOverrides *mOverrides, omc_CommandLineOverridesUses **mOverridesUses, const char *name)
{
addHashStringLong(mOverridesUses, name, OMC_OVERRIDE_USED);
return findHashStringString(mOverrides, name);
}
/**
* @brief Read override values from simulation flags `-override` and `-overrideFile` and update variables.
*
* Return if step sizes needs to be re-calculated because start or stop time was changed, but step size wasn't changed.
*
* @param mi Model input from info XML file.
* @param modelData Pointer to model data containing variable values to override.
* @param overrideFile Path to override file given by `-overrideFile`.
* @return modelica_boolean True if integrator step size should be re-caclualted.
*/
modelica_boolean doOverride(omc_ModelInput *mi, MODEL_DATA *modelData, const char *override, const char *overrideFile)
{
omc_CommandLineOverrides *mOverrides = NULL;
omc_CommandLineOverridesUses *mOverridesUses = NULL, *it = NULL, *ittmp = NULL;
mmc_sint_t i;
modelica_boolean changedStartStop = 0 /* false */;
modelica_boolean changedStepSize = 0 /* false */;
modelica_boolean reCalcStepSize = 0 /* false */;
char* overrideStr1 = NULL, *overrideStr2 = NULL, *overrideStr = NULL;
if((override != NULL) && (overrideFile != NULL)) {
infoStreamPrint(LOG_SOLVER, 0, "using -override=%s and -overrideFile=%s", override, overrideFile);
}
if(override != NULL) {
overrideStr1 = strdup(override);
}
if(overrideFile != NULL) {
FILE *infile = NULL;
char *line=NULL, *tline=NULL, *tline2=NULL;
char *overrideLine;
size_t n=0;
/* read override values from file */
infoStreamPrint(LOG_SOLVER, 0, "read override values from file: %s", overrideFile);
infile = omc_fopen(overrideFile, "rb");
if (0==infile) {
throwStreamPrint(NULL, "simulation_input_xml.c: could not open the file given to -overrideFile=%s", overrideFile);
}
fseek(infile, 0L, SEEK_END);
n = ftell(infile);