Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#3261 closed defect (fixed)

Cannot override array variables

Reported by: crupp@… Owned by: Adrian Pop
Priority: high Milestone: 1.9.3
Component: Run-time Version: trunk
Keywords: Cc:

Description

The command line option -override and -overrideFile do not allow overrides of array variables. This is because the override string is tokenized by ",", which also catches the array dimension separator. This happens at simulation_input_xml.cpp:838.

The same problem happens with the -output option in solver_main.c:773. Could this happen anywhere else?

A quick fix would be to use a different separator character that would never exist in a variable name such as ";" and thereby avoid this issue.

Here is an example that reproduces the problem:

model overrideBug
  parameter Real[2,2] A = {{1,2},{3,4}};
  Real[2] x(start={1,2});
  Real[2] y;
equation
  y = der(x);
  der(y) = A * x;
end overrideBug;

Output:

./overrideBug.exe -override A[1,1]=0
stdout            | warning | simulation_input_xml.cpp: override variable name not found in model: 1]
stdout            | warning | simulation_input_xml.cpp: override variable name not found in model: A[1

Change History (9)

comment:1 by Adrian Pop, 10 years ago

Ouch, I didn't think of that. We can either fix this as you suggest using ";" as separator or we make the parsing of variables a bit more clever.

comment:2 by Martin Sjölund, 10 years ago

; is allowed in variable names :)

comment:3 by Adrian Pop, 10 years ago

Milestone: Future1.9.3
Owner: changed from somebody to Adrian Pop
Status: newaccepted

Yeah. We should change this to ignore "," inside [ ]:

char *p = strtok(overrideStr, ",");

I'll see what I can do.

comment:4 by Adrian Pop, 10 years ago

Resolution: fixed
Status: acceptedclosed

Fixed in r25370.

comment:5 by crupp@…, 10 years ago

What about command line outputs? Same problem, should be the same fix.

comment:6 by Adrian Pop, 10 years ago

What do you mean? I don't get it.
The command line outputs should be parsed by the external program that reads them :)

comment:7 by crupp@…, 10 years ago

The -output flag won't dump the value of an array variable. For example,

./overrideBug.exe -output x[1],A[1,1]
time=1,x[1]=4.846927041353899

does not dump out A[1,1] due to a similar tokenizing bug at solver_main.c:773.

comment:8 by Adrian Pop, 10 years ago

Ok. Now I get it. I'll have a look.

comment:9 by Adrian Pop, 10 years ago

Properly fixed in r25376.

Note: See TracTickets for help on using tickets.