Bug Summary

File:OMCompiler/SimulationRuntime/c/./simulation/simulation_input_xml.c
Warning:line 386, column 19
Potential leak of memory pointed to by 'unit'

Annotated Source Code

[?] Use j/k keys for keyboard navigation

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