Skip to content

Commit

Permalink
- Added a new command plot3 that uses OMPlot
Browse files Browse the repository at this point in the history
- plot3(x, true/false(externalWindow), filename, title, legend.....)
- added spawnCall function in system.mo since system method blocks the execution so using spawn instead.
- small update in plotwindow

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8511 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Apr 6, 2011
1 parent 0c30aa8 commit 73cc6b0
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 3 deletions.
27 changes: 27 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -1096,6 +1096,33 @@ function plot "Launches a plot window using OMPlotWindow. Returns true on succes
external "builtin";
end plot;

function plot3 "Launches a plot window using OMPlot. Returns true on success.
Don't require sendData support.
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 Boolean externalWindow := false "Opens the plot in a new plot window";
input String fileName := "<default>" "The filename containing the variables. <default> will read the last simulation result";
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 String plotType := "plot" "This text will be used to tell OMPlot what type of plot is requested.";
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 Real xRange1 := 0.0 "Determines the horizontal interval that is visible in the diagram. {0,0} will select a suitable range.";
input Real xRange2 := 0.0 "Determines the horizontal interval that is visible in the diagram. {0,0} will select a suitable range.";
input Real yRange1 := 0.0 "Determines the vertical interval that is visible in the diagram. {0,0} will select a suitable range.";
input Real yRange2 := 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 plot3;

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.
Expand Down
54 changes: 51 additions & 3 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -633,7 +633,7 @@ algorithm
list<SCode.Class> scodeP,sp,fp;
list<Env.Frame> env;
SCode.Class c;
String s1,str,str1,str2,str3,re,token,varid,cmd,executable,method_str,outputFormat_str,initfilename,cit,pd,executableSuffixedExe,sim_call,result_file,filename_1,filename,omhome_1,plotCmd,tmpPlotFile,call,str_1,mp,pathstr,name,cname,fileNamePrefix_s,errMsg,errorStr,uniqueStr,interpolation, title,xLabel,yLabel,filename2,varNameStr,xml_filename,xml_contents,visvar_str,pwd,omhome,omlib,omcpath,os,platform,usercflags,senddata,res,workdir,gcc,confcmd,touch_file,uname,filenameprefix;
String s1,str,str1,str2,str3,re,token,varid,cmd,executable,method_str,outputFormat_str,initfilename,cit,pd,executableSuffixedExe,sim_call,result_file,filename_1,filename,omhome_1,plotCmd,tmpPlotFile,call,str_1,mp,pathstr,name,cname,fileNamePrefix_s,errMsg,errorStr,uniqueStr,interpolation,plotType,title,xLabel,yLabel,filename2,varNameStr,xml_filename,xml_contents,visvar_str,pwd,omhome,omlib,omcpath,os,platform,usercflags,senddata,res,workdir,gcc,confcmd,touch_file,uname,filenameprefix;
DAE.ComponentRef cr,cref,classname;
Interactive.InteractiveSymbolTable newst,st_1;
Absyn.Program p,pnew,newp,ptot;
Expand All @@ -651,14 +651,14 @@ algorithm
array<list<Integer>> m,mt;
Option<array<list<Integer>>> om,omt;
Option<list<tuple<Integer, Integer, BackendDAE.Equation>>> jac;
Values.Value ret_val,simValue,size_value,value,v,cvar,xRange,yRange;
Values.Value ret_val,simValue,size_value,value,v,cvar,xRange,yRange,xRange1,xRange2,yRange1,yRange2;
DAE.Exp exp,size_expression,bool_exp,storeInTemp,translationLevel,addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals,varName,varTimeStamp;
Absyn.ComponentRef cr_1;
Integer size,length,resI,timeStampI,i,n;
list<String> vars_1,vars_2,args,strings,strVars,strs,visvars;
Real t1,t2,time,timeTotal,timeSimulation,timeStamp,val;
Interactive.InteractiveStmts istmts;
Boolean bval, b, legend, grid, logX, logY, points, gcc_res, omcfound, rm_res, touch_res, uname_res, extended, insensitive;
Boolean bval, b, externalWindow, legend, grid, logX, logY, points, gcc_res, omcfound, rm_res, touch_res, uname_res, extended, insensitive;
Env.Cache cache;
list<Interactive.LoadedFile> lf;
AbsynDep.Depends aDep;
Expand Down Expand Up @@ -1565,6 +1565,54 @@ algorithm
case (cache,env,"plot",_,st,msg)
then
(cache,Values.BOOL(false),st);

// plot3(x, model)
case (cache,env,"plot3",
{
Values.ARRAY(valueLst = cvars),
Values.BOOL(externalWindow),
Values.STRING(filename),
Values.STRING(title),
Values.BOOL(legend),
Values.BOOL(grid),
Values.STRING(plotType),
Values.BOOL(logX),
Values.BOOL(logY),
Values.STRING(xLabel),
Values.STRING(yLabel),
xRange1,
xRange2,
yRange1,
yRange2
},
st,msg)
equation
// get the variables list
vars_1 = Util.listMap(cvars, ValuesUtil.printCodeVariableName);
// seperate the variables
str = Util.stringDelimitList(vars_1,"\" \"");
// get OPENMODELICAHOME
omhome = Settings.getInstallationDirectoryPath();
// get the simulation filename
(cache,filename) = cevalCurrentSimulationResultExp(cache,env,filename,st,msg);
pd = System.pathDelimiter();
// create absolute path of simulation result file
str1 = System.pwd() +& pd +& filename;
s1 = Util.if_(System.os() ==& "Windows_NT", ".exe", "");
filename = Util.if_(System.regularFileExists(str1), str1, filename);
// create the path till OMPlot
str2 = stringAppendList({omhome,"..",pd,"OMPlot",pd,"bin",pd,"OMPlot",s1});
// create the list of arguments for OMPlot
str3 = "\"" +& filename +& "\" \"" +& title +& "\" \"" +& boolString(legend) +& "\" \"" +& boolString(grid) +& "\" \"" +& plotType +& "\" \"" +& boolString(logX) +& "\" \"" +& boolString(logY) +& "\" \"" +& xLabel +& "\" \"" +& yLabel +& "\" \"" +& ValuesUtil.valString(xRange1) +& "\" \"" +& ValuesUtil.valString(xRange2) +& "\" \"" +& ValuesUtil.valString(yRange1) +& "\" \"" +& ValuesUtil.valString(yRange2) +& "\" \"" +& str +& "\" -ew \"" +& boolString(externalWindow) +& "\"";
call = str2 +& " " +& str3;

_ = System.spawnCall(str2, call);
then
(cache,Values.BOOL(true),st);

case (cache,env,"plot3",_,st,msg)
then
(cache,Values.BOOL(false),st);

// he-mag, visualize
// visualize(model, x)
Expand Down
7 changes: 7 additions & 0 deletions Compiler/Util/System.mo
Expand Up @@ -327,6 +327,13 @@ public function systemCall
external "C" outInteger=SystemImpl__systemCall(inString) annotation(Library = "omcruntime");
end systemCall;

public function spawnCall
input String path "The absolute path to the executable";
input String str "The list of arguments with executable";
output Integer outInteger;
external "C" outInteger=SystemImpl__spawnCall(path,str) annotation(Library = "omcruntime");
end spawnCall;

public function cd
input String inString;
output Integer outInteger;
Expand Down
9 changes: 9 additions & 0 deletions Compiler/runtime/System_rml.c
Expand Up @@ -799,6 +799,15 @@ RML_BEGIN_LABEL(System__systemCall)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__spawnCall)
{
const char* path = RML_STRINGDATA(rmlA0);
const char* str = RML_STRINGDATA(rmlA1);
rmlA0 = (void*) mk_icon(SystemImpl__spawnCall(path, str));
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__windowsNewline)
{
rmlA0 = (void*) mk_scon("\r\n");
Expand Down
55 changes: 55 additions & 0 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -74,6 +74,7 @@ extern "C" {
/* includes/defines specific for Windows*/
#include <assert.h>
#include <direct.h>
#include <process.h>

#define MAXPATHLEN MAX_PATH
#define S_IFLNK 0120000 /* symbolic link */
Expand Down Expand Up @@ -520,6 +521,60 @@ int SystemImpl__systemCall(const char* str)
return ret_val;
}

int SystemImpl__spawnCall(const char* path, const char* str)
{
int status = -1,ret_val = -1;
const int debug = 0;
if (debug) {
fprintf(stderr, "System.spawnCall: %s\n", str); fflush(NULL);
}

fflush(NULL); /* flush output so the testsuite is deterministic */
#if defined(__MINGW32__) || defined(_MSC_VER)
status = spawnl(P_NOWAIT, path, str, "", NULL);
#else
pid_t pID = vfork();
if (pID == 0) { // child
execl("/bin/sh", "/bin/sh", "-c", str, NULL);
if (debug) {
fprintf(stderr, "System.spawnCall: execl failed %s\n", strerror(errno));
fflush(NULL);
}
_exit(1);
} else if (pID < 0) {
const char *tokens[2] = {strerror(errno),str};
c_add_message(-1,"SCRIPTING","ERROR","system(%s) failed: %s",tokens,2);
return -1;
} else {

if (waitpid(pID, &status, 0) == -1) {
const char *tokens[2] = {strerror(errno),str};
c_add_message(-1,"SCRIPTING","ERROR","system(%s) failed: %s",tokens,2);
}
}
#endif
fflush(NULL); /* flush output so the testsuite is deterministic */

if (debug) {
fprintf(stderr, "System.spawnCall: returned\n"); fflush(NULL);
}

#if defined(__MINGW32__) || defined(_MSC_VER)
ret_val = status;
#else
if (WIFEXITED(status)) /* Did the process exit normally? */
ret_val = WEXITSTATUS(status); /* Fetch the actual exit status */
else
ret_val = -1;
#endif

if (debug) {
fprintf(stderr, "System.spawnCall: returned value: %d\n", ret_val); fflush(NULL);
}

return ret_val;
}

double SystemImpl__time()
{
clock_t cl = clock();
Expand Down

0 comments on commit 73cc6b0

Please sign in to comment.