Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

How to print a message

How to print a message

I just want to output some text when something occurs.
I suppose it should go to the "Message Browser" in OMEdit.

I tried with the following code:

Code:

model msg

  Real x, y;
equation
  x = time;
  when time > 0.5 then
    print("message");
    y = time;
  end when;
end msg;

It should print at t=0.5, but I don't see any message (unless I watch the wrong place"!)

Thank anyone that wants to help.

Re: How to print a message

You can use print or this:
https://build.openmodelica.org/Document … print.html

print seems to work fine: (see messages="message")

Code:


adrpo@ida-liu050 ~/dev/OpenModelica/build/bin/
$ cat > msg.mo
model msg
  Real x, y;
equation
  x = time;
  when time > 0.5 then
    print("message");
    y = time;
  end when;
end msg;

adrpo@ida-liu050 ~/dev/OpenModelica/build/bin/
$ cat > msg.mos
loadFile("msg.mo"); getErrorString();
simulate(msg); getErrorString();

adrpo@ida-liu050 ~/dev/OpenModelica/build/bin/
$ ../omc msg.mos
true
""
record SimulationResult
    resultFile = "c:/bin/cygwin/home/adrpo/dev/OpenModelica/build/bin/msg_res.mat",
    simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'msg', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
    messages = "message",
    timeFrontend = 0.02278212030280691,
    timeBackend = 0.008754299484735505,
    timeSimCode = 0.001498251334356035,
    timeTemplates = 0.04028148031235384,
    timeCompile = 3.071980736768558,
    timeSimulation = 0.1831265795253099,
    timeTotal = 3.329325806147373
end SimulationResult;
"Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
"
adrpo@ida-liu050 ~/dev/OpenModelica/build/bin/
$ ./msg.exe
message

Re: How to print a message

The message will show up in the simulation output window and not in Messages Browser.

Adeel.

Re: How to print a message

print() is sent to stdout directly and thus messes up the OMEdit output parsing. https://build.openmodelica.org/Document … print.html should work as expected. But it also does not. Seems we send it directly to stdout current/sad

Re: How to print a message

I could replicate the suggestion from adrpo involving OMShell, and worked as expected.

As sioelund mentions, things seem not to be as good in OMEdit.

I tried both
...
    print("message");
...
and
    Modelica.Utilities.Streams.print("message");

but I could not see "message" in the simulation output window of OMEdit.

Re: How to print a message

The coming nightly build should handle Streams.print correctly, but not the OpenModelica print extension

Re: How to print a message

I checked today (with r24422) and saw
    Modelica.Utilities.Streams.print("message");
working as expected also in OMEdit.

Thanks again!

There are 0 guests and 0 other users also viewing this topic