Skip to content

Commit 00f4f91

Browse files
author
Jens Frenkel
committed
- bugfix for compare SimulationResults , Dymola uses a[1, 2], OMC use a[1,2] (no white space)
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8627 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 3940412 commit 00f4f91

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

Compiler/runtime/SimulationResultsCmp.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,33 @@ static inline void fixDerInName(char *str, size_t len)
7878
}
7979
}
8080

81-
static inline void fixCommaInName(char *str, size_t len)
81+
static inline void fixCommaInName(char **str, size_t len)
8282
{
83-
size_t i;
84-
char* dot;
83+
size_t i,nc;
84+
unsigned int j,k;
85+
char* newvar;
8586
if (len < 2) return;
8687

87-
// check if name start with "der(" and includes at least one dot
88-
while (strncmp(str,",",4) == 0 && (dot = strrchr(str,'.')) != NULL) {
89-
size_t pos = (size_t)(dot-str)+1;
90-
// move prefix to the begining of string :"der(a.b.c.d)" -> "a.b.c.b.c.d)"
91-
for(i = 4; i < pos; ++i)
92-
str[i-4] = str[i];
93-
// move "der(" to the end of prefix
94-
// "a.b.c.b.c.d)" -> "a.b.c.der(d)"
95-
strncpy(&str[pos-4],"der(",4);
88+
nc = 0;
89+
for (j=0;j<len;j++)
90+
if ((*str)[j] ==',' )
91+
nc +=1;
92+
93+
if (nc > 0) {
94+
95+
newvar = (char*) malloc(len+nc+1);
96+
memset(newvar,0,len+nc+1);
97+
k = 0;
98+
for (j=0;j<len+nc+1;j++) {
99+
newvar[k] = (*str)[j];
100+
k +=1;
101+
if ((*str)[j] ==',' ) {
102+
newvar[k] = ' ';
103+
k +=1;
104+
}
105+
}
106+
free(str);
107+
*str = newvar;
96108
}
97109
}
98110

@@ -145,7 +157,7 @@ DataField getData(const char *varname,const char *filename, unsigned int size, S
145157
res.n = 0;
146158
res.data = NULL;
147159

148-
//fprintf(stderr, "getData of Var: %s from file %s\n", varname,filename);
160+
// fprintf(stderr, "getData of Var: %s from file %s\n", varname,filename);
149161
cmpvar = mk_nil();
150162
cmpvar = mk_cons(mk_scon(varname),cmpvar);
151163
dataset = SimulationResultsImpl__readDataset(filename,cmpvar,size,srg);
@@ -366,6 +378,7 @@ void* SimulationResultsCmp_compareResults(const char *filename, const char *reff
366378
var2 = (char*) malloc(len);
367379
strncpy(var2,var1,len+1);
368380
fixDerInName(var2,len);
381+
fixCommaInName(&var2,len);
369382
dataref = getData(var2,reffilename,size_ref,&simresglob_ref);
370383
if (dataref.n==0) {
371384
fprintf(stderr, "Get Data of Var %s from file %s failed\n",var,reffilename);
@@ -377,6 +390,7 @@ void* SimulationResultsCmp_compareResults(const char *filename, const char *reff
377390
data = getData(var1,filename,size,&simresglob_c);
378391
if (data.n==0) {
379392
fixDerInName(var1,len);
393+
fixCommaInName(&var1,len);
380394
data = getData(var1,filename,size,&simresglob_c);
381395
if (data.n==0) {
382396
if (data.data) free(data.data);

0 commit comments

Comments
 (0)