Hi all,

I have updated the order of arguments in some of the plotting functions used by OpenModelica.

Previously, this was:
plot({x,y})
plot(A,{x,y})

Now, it is:
plot({x,y})
plot({x,y},"A_res.mat")

This won't affect most of you as the first command is the most commonly used.

The optional first argument was moved to the second argument because this is the way default arguments are supposed to look like using Modelica function syntax.

Note that the second argument is a filename instead of a class because:
1) The old syntax had no way of saying if we should look for a plt or mat file. 2) When you use quoted identifiers in your classname, you need to use the fileNamePrefix option of simulate() in order to compile it. This may or may not be a valid classname. 3) Now you can rename your plot-files to anything you like, for backup, and still be able to plot them any time you like without renaming them back again.

When using enableSendData(true), setVariableFilter() should no longer be used (it has been removed). Use the variableFilter option of the simulate() command instead. Now, we only send the variables that are actually requested to the sendData library (instead of doing hash-table lookup on every variable in every time step; 10000 variables and filtering only 1 used to be terribly slow, now it's just slow because the plot widget is a bit crazy).

The new plot functions are part of http://openmodelica.org/svn/OpenModelica/trunk/Compiler/FrontEnd/ModelicaBuiltin.mo. They are also reproduced below so you can see all parameters easily.

--
Martin Sjölund

function plot "Launches a plot window using OMPlotWindow. Returns true on success. If OpenModelica was compiled without sendData support, this function will return false.

  Example command sequences:
  simulate(A);plot({x,y,z});
  simulate(A);plot(x);

simulate(A,fileNamePrefix=\"B\");simulate(C);plot(z,\"B.mat\",legend=false);
  "
  input VariableNames vars "The variables you want to plot";
input String fileName := "<default>" "The filename containing the variables. <default> will read the last simulation result";
  input String interpolation := "linear" "
Determines if the simulation data should be interpolated to allow drawing of continuous lines in the diagram. \"linear\" results in linear interpolation between data points, \"constant\" keeps the value of the last known data point until a new one is found and \"none\" results in a diagram where only known data points are plotted."
  ;
input String title := "Plot by OpenModelica" "This text will be used as the diagram title."; input Boolean legend := true "Determines whether or not the variable legend is shown."; input Boolean grid := true "Determines whether or not a grid is shown in the diagram."; input Boolean logX := false "Determines whether or not the horizontal axis is logarithmically scaled."; input Boolean logY := false "Determines whether or not the vertical axis is logarithmically scaled."; input String xLabel := "time" "This text will be used as the horizontal label in the diagram."; input String yLabel := "" "This text will be used as the vertical label in the diagram."; input Boolean points := false "Determines whether or not the data points should be indicated by a dot in the diagram."; input Real xRange[2] := {0.0,0.0} "Determines the horizontal interval that is visible in the diagram. {0,0} will select a suitable range."; input Real yRange[2] := {0.0,0.0} "Determines the vertical interval that is visible in the diagram. {0,0} will select a suitable range.";
  output Boolean success "Returns true on success";
external "builtin";
end plot;

function plotAll "Works in the same way as plot(), but does not accept any
variable names as input. Instead, all variables are part of the plot window.

  Example command sequences:
  simulate(A);plotAll();
  simulate(A,fileNamePrefix=\"B\");simulate(C);plotAll(x,\"B.mat\");
  "
input String fileName := "<default>" "The filename containing the variables. <default> will read the last simulation result";
  input String interpolation := "linear" "
Determines if the simulation data should be interpolated to allow drawing of continuous lines in the diagram. \"linear\" results in linear interpolation between data points, \"constant\" keeps the value of the last known data point until a new one is found and \"none\" results in a diagram where only known data points are plotted."
  ;
input String title := "Plot by OpenModelica" "This text will be used as the diagram title."; input Boolean legend := true "Determines whether or not the variable legend is shown."; input Boolean grid := true "Determines whether or not a grid is shown in the diagram."; input Boolean logX := false "Determines whether or not the horizontal axis is logarithmically scaled."; input Boolean logY := false "Determines whether or not the vertical axis is logarithmically scaled."; input String xLabel := "time" "This text will be used as the horizontal label in the diagram."; input String yLabel := "" "This text will be used as the vertical label in the diagram."; input Boolean points := false "Determines whether or not the data points should be indicated by a dot in the diagram."; input Real xRange[2] := {0.0,0.0} "Determines the horizontal interval that is visible in the diagram. {0,0} will select a suitable range."; input Real yRange[2] := {0.0,0.0} "Determines the vertical interval that is visible in the diagram. {0,0} will select a suitable range.";
  output Boolean success "Returns true on success";
external "builtin";
end plotAll;

function plot2 "Uses the Java-based plot window (ptplot.jar) to launch a plot, similar to the plot() command. This command accepts fewer options, but works
  even when OpenModelica was not compiled with sendData support.

  Example command sequences:
  simulate(A);plot2({x,y});
  simulate(A,fileNamePrefix=\"B\");simulate(C);plot2(x,\"B.mat\");
  "
  input VariableNames vars;
  input String fileName := "<default>";
  output Boolean success "Returns true on success";
external "builtin";
end plot2;

function visualize "Uses the 3D visualization package, SimpleVisual.mo, to
  visualize the model. See chapter 3.4 (3D Animation) of the OpenModelica
  System Documentation for more details.

  Example command sequence:
  simulate(A,outputFormat=\"plt\");visualize(A);
  "
  input TypeName classToVisualize;
  output Boolean success "Returns true on success";
end visualize;

function plotParametric "Plots the y-variables as a function of the x-variable.

  Example command sequences:
  simulate(A);plotParametric(x,y);

simulate(A,fileNamePrefix=\"B\");simulate(C);plotParametric(x,{y1,y2,y3},fileName=\"B.mat\",yLabel=\"[V]\");
  "
  input VariableName xVariable;
  input VariableNames yVariables;
input String fileName := "<default>" "The filename containing the variables. <default> will read the last simulation result";
  input String interpolation := "linear" "
Determines if the simulation data should be interpolated to allow drawing of continuous lines in the diagram. \"linear\" results in linear interpolation between data points, \"constant\" keeps the value of the last known data point until a new one is found and \"none\" results in a diagram where only known data points are plotted."
  ;
input String title := "Plot by OpenModelica" "This text will be used as the diagram title."; input Boolean legend := true "Determines whether or not the variable legend is shown."; input Boolean grid := true "Determines whether or not a grid is shown in the diagram."; input Boolean logX := false "Determines whether or not the horizontal axis is logarithmically scaled."; input Boolean logY := false "Determines whether or not the vertical axis is logarithmically scaled."; input String xLabel := "" "This text will be used as the horizontal label in the diagram."; input String yLabel := "" "This text will be used as the vertical label in the diagram."; input Boolean points := false "Determines whether or not the data points should be indicated by a dot in the diagram."; input Real xRange[2] := {0.0,0.0} "Determines the horizontal interval that is visible in the diagram. {0,0} will select a suitable range."; input Real yRange[2] := {0.0,0.0} "Determines the vertical interval that is visible in the diagram. {0,0} will select a suitable range.";
  output Boolean success "Returns true on success";
external "builtin";
end plotParametric;

function plotParametric2 "Plots the y-variables as a function of the x-variable.

  Example command sequences:
  simulate(A);plotParametric2(x,y);

simulate(A,fileNamePrefix=\"B\");simulate(C);plotParametric2(x,{y1,y2,y3},\"B.mat\");
  "
  input VariableName xVariable;
  input VariableNames yVariables;
  input String fileName := "<default>";
  output Boolean success "Returns true on success";
external "builtin";
end plotParametric2;

Reply via email to