Opened 7 years ago
Last modified 7 years ago
#4549 assigned defect
Zero size string array
Reported by: | Owned by: | Willi Braun | |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | Run-time | Version: | |
Keywords: | Cc: | Jan Kokert, Adrian Pop |
Description
When investigating #4524, I stumbled into a problem with zero size string variables of functions. Please consider the following example:
package TestString function zeroSize input Real matrix[:, :] "Matrix"; input String[:,:] header = fill("", 0, size(matrix, 2)) "String matrix"; algorithm Modelica.Utilities.Streams.print("Size of matrix: " + String(size(matrix, 1)) + " x " + String(size(matrix, 2))); Modelica.Utilities.Streams.print("Size of header: " + String(size(header, 1)) + " x " + String(size(header, 2))); if size(matrix,2)<>size(header,2) then Modelica.Utilities.Streams.error("zeroSize: number of columns of matrix ("+String(size(matrix,2))+") and header ("+String(size(header,2))+") do not match"); end if; end zeroSize; model TestZeroSize parameter Real M[2,2] = [1,2;3,4]; algorithm when initial() then // zeroSize({{1,2},{3,4}}); zeroSize(M); end when; end TestZeroSize; end TestString;
In this example the function zeroSize
has the two input variables, matrix
and header
. Variable header
is assigned with a default input: a string zero rows and two columns. The function here just serves as dummy function, logging the dimensions of the two arrays matrix
and header
and cause an error, in case their number of rows were different.
In the test model TestString
the function zeroSize
is tested. When simulating the modell, the following error is triggered:
stdout | error | <p>Simulation process failed. Exited with code 255.</p> stdout | info | <p>Size of matrix: 2 x 2<br> stdout | info | <p>Size of header: 0 x 0<br> assert | debug | <p>zeroSize: number of columns of matrix (2) and header (0) do not match</p> assert | info | <p>simulation terminated by an assertion at initialization</p>
So apparently the number of columns is not determined correctly in the function call. Now change the test model to:
zeroSize({{1,2},{3,4}}); // zeroSize(M);
an re-run the simulation test model: everything works fine with no complaints...
Change History (3)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Cc: | added |
---|---|
Component: | OMEdit → Run-time |
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 7 years ago
Weird. When I run this, I get the same error for both versions of the zeroSize call...
Refers to