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

Equivalent for Modelica.Utilities.Streams.print() ???

Equivalent for Modelica.Utilities.Streams.print() ???

I need to print out some control values at specific events in the simulation.  The book I read uses "Modelica.Utilities.Streams.print()" but as I have figured out Open Modelica does not support this function.

So is there any alternative for this in Open Modelica or not?

Re: Equivalent for Modelica.Utilities.Streams.print() ???

Bugs go here: https://trac.openmodelica.org/OpenModelica/newticket

I created a new one: https://trac.openmodelica.org/OpenModelica/ticket/1827

The work-around is using any function that prints and returns a value.

Code:

model M

  function myPrint
    input String str;
    input String file := "";
    output Boolean ok;
  algorithm
    Modelica.Utilities.Streams.print(str, file);
    ok := true;
  end myPrint;
  Integer i;
protected
  Boolean dummy;
equation
  when sample(0,0.1) then
    dummy = myPrint("printing at time: " + String(time) + "\n");
    i = pre(i) + 1;
  end when;
end M;

Which gives you output:

Code:


printing at time: 0
printing at time: 0.1
printing at time: 0.2
printing at time: 0.3
printing at time: 0.4
printing at time: 0.5
printing at time: 0.6
printing at time: 0.7
printing at time: 0.8
printing at time: 0.9
printing at time: 1

Re: Equivalent for Modelica.Utilities.Streams.print() ???

I've Simulated your Modelica Code and cannot find any text messages.

Do I have to open any special output window? And if so where do I open it?  I haven't found any entries in the menu about any text output windows.

Or do I have to execute Open Modellica in the Windows Shell?

Re: Equivalent for Modelica.Utilities.Streams.print() ???

Yes, OMEdit sucks at displaying simulation output. Like "your model ended before the stop-time due to xyz". You can set the filename and read that if you prefer OMEdit over OMShell current/wink

Re: Equivalent for Modelica.Utilities.Streams.print() ???

Thank's so far for your answers. So what you're saying is: No way around Shell??? That  sucks.

I'm kind of new to OM so what do I enter in the OEMShell?

Re: Equivalent for Modelica.Utilities.Streams.print() ???

Well, you could always send Adeel a message complaining you don't get the output from the executable... Or adding a bug to trac.openmodelica.org.

OMShell works the same way as you do in OpenModelica scripting from command-line current/smile

Code:

loadModel(Modelica)

getErrorString()
loadFile("path/to/myFile.mo")
getErrorString()
simulate(myModelName, stopTime=0.10)
getErrorString()

Re: Equivalent for Modelica.Utilities.Streams.print() ???

Thank's a lot!!!

Re: Equivalent for Modelica.Utilities.Streams.print() ???

works since r13361

There are 0 guests and 0 other users also viewing this topic
You are here: