Opened 7 years ago
Last modified 7 years ago
#4524 reopened defect
Simple KeyWordIO example does not work in OM
Reported by: | Jan Kokert | Owned by: | Adrian Pop |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | Frontend | Version: | v1.13.0-dev-nightly |
Keywords: | KeyWordIO | Cc: | dr.christian.kral@… |
Description
Hi,
Today I wanted to test the KeyWordIO library with a simple example for my dissertation:
model test import KeyWordIO.*; parameter String outputFileName = Modelica.Utilities.Files.loadResource("modelica://test/myoutput.txt"); Real M[2,2] = [1,2;3,4]; algorithm when initial() then KeyWordIO.writeRealCSV(outputFileName, "\t", M); end when; annotation ( uses(KeyWordIO(version = "0.7.0"))); end test;
Unfortunately, the process crashes in the latest nightly build (v1.13.0-dev-27) and also in a version before (v1.12.0-dev-580):
stdout | error | <p>Process crashed stdout | error | <p>Process crashed<br> Simulation process failed. Exited with code -1073741819.
Furthermore, it is interesting that it crashed two times...
On the compilation tab it says:
test_functions.c: In function 'omc_KeyWordIO_writeRealCSV': test_functions.c:48:10: warning: assignment makes pointer from integer without a cast [-Wint-conversion] tmp5 = tmp6; ^
Maybe these tickets are related:
ticket:3638
ticket:4313
I would highly appreciate if this simple example could work.
Many thanks in advance!
Attachments (1)
Change History (9)
by , 7 years ago
comment:1 by , 7 years ago
Component: | Run-time → Frontend |
---|
comment:2 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 7 years ago
Hi!
Thank you very much for working on that ticket, Henning Kiel!
It's interesting how such a small line case SIZE(sz=SOME(__))
can avoid the crash.
I will test it asap. in the next nightly build.
comment:4 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixed in r7fb6389.
The issue was in the code generation on this line in expTypeFromExpFlag
:
case SIZE(__) then expTypeFlag(typeof(exp), flag)
exp
is an argument to expTypefromExpFlag
, so this was supposed to simply delegate to expTypeFlag
with the type of the size expression as the first argument. But SIZE
happens to have a member called exp
which accidentally shadowed the argument exp
due to how the template language works, so it used the type of the first expression to size instead. This fix was simply to rebind exp
with another name:
case e as SIZE(__) then expTypeFlag(typeof(e), flag)
comment:5 by , 7 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:6 by , 7 years ago
Good morning, thanks for the fix of the size operator.
I tested my simple example again with the latest nightly build. The simulation doesn't crash any longer which is good, but unfortunately it still doesn't do the job.
There comes an assertion error from the library:
writeRealCSV: number of columns of matrix (2) and header (0) do not match
It seems that fill("",0,size(matrix,2))
with the 0
is the problem.
When I change my example to the following it works:
... String H[1,2] = fill("Head",1,size(M,2)); algorithm when initial() then KeyWordIO.writeRealCSV(outputFileName, "\t", M, H); end when; ...
@christian.kral: Will you also please take a look at it?
comment:7 by , 7 years ago
Summary: | Simple KeyWordIO example crashes in OM → Simple KeyWordIO example does not work in OM |
---|
comment:8 by , 7 years ago
Two issues here:
- I discovered, that the error message of the function does not write the correct text, see https://github.com/christiankral/KeyWordIO/issues/5, but this has nothing to do with the functionality of function
writeRealCSV
- The functionality issue arising in
writeRealCSV
is reported in #4549
Regarding your test function:
In case you can accept having a header string in your output text file, you could change your test source code to:
KeyWordIO.writeRealCSV(outputFileName, "\t", M,{{"col1","col2"}});
This will then write the file correctly (including header) in OpenModelica.
I have tracked the problem down to this MWE:
The problem is in the front end that
size(header,1)
is seen as a string, because header is a string,but size should alsways be integer (same forsize(matrix,1)
which is seen as a rea, but does not crash).