Skip to content

Commit

Permalink
*Added plotAll() and plotAll(model) commands
Browse files Browse the repository at this point in the history
*Changed default value of "points" to false

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@3216 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Henrik Eriksson committed Feb 19, 2008
1 parent 8cb7506 commit 4f47921
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 8 deletions.
152 changes: 152 additions & 0 deletions Compiler/Ceval.mo
Expand Up @@ -2173,6 +2173,158 @@ algorithm
then
(cache,Values.STRING("Unknown error while plotting"),st);

//plotAll(model) - file missing
case (cache,env,
Exp.CALL(
path = Absyn.IDENT(name = "plotAll"),
expLst = {
Exp.CODE(Absyn.C_TYPENAME(className),_),
Exp.SCONST(string = interpolation), Exp.SCONST(string = title), Exp.BCONST(bool = legend), Exp.BCONST(bool = grid), Exp.BCONST(bool = logX), Exp.BCONST(bool = logY), Exp.SCONST(string = xLabel), Exp.SCONST(string = yLabel), Exp.BCONST(bool = points), xRange, yRange
}),
(st as Interactive.SYMBOLTABLE(
ast = p,explodedAst = sp,instClsLst = ic,
lstVarVal = iv,compiledFunctions = cf,
loadedFiles = lf)),msg)
local
Integer res;
Exp.Exp xRange, yRange;
list<Exp.Exp> vars;
// list<String> vars_3;
String interpolation, title, xLabel, yLabel, str, filename2;
Boolean legend, grid, logX, logY, points;
equation

// vars = Util.listMap(vars,Exp.CodeVarToCref);
// vars_1 = Util.listMap(vars, Exp.printExpStr) "plot" ;
// vars_2 = Util.listUnionElt("time", vars_1);

filename = Absyn.pathString(className);
filename2 = Util.stringAppendList({filename, "_res.plt"});

failure(_ = System.getVariableNames(filename2));
// vars_2 = Util.stringSplitAtChar(str, " ");
// vars_2 =


// value = System.readPtolemyplotDataset(filename2, vars_2, 0);


// failure(_ = System.readPtolemyplotDataset(filename2, vars_2, 0));

then
(cache,Values.STRING("Error reading the simulation result."),st);
// res = Values.sendPtolemyplotDataset(value, vars_2, "Plot by OpenModelica", interpolation, title, legend, grid, logX, logY, xLabel, yLabel, points, Exp.printExpStr(xRange), Exp.printExpStr(yRange));

// then
// (cache,Values.BOOL(true),st);

//plotAll(model)
case (cache,env,
Exp.CALL(
path = Absyn.IDENT(name = "plotAll"),
expLst = {
Exp.CODE(Absyn.C_TYPENAME(className),_),
Exp.SCONST(string = interpolation), Exp.SCONST(string = title), Exp.BCONST(bool = legend), Exp.BCONST(bool = grid), Exp.BCONST(bool = logX), Exp.BCONST(bool = logY), Exp.SCONST(string = xLabel), Exp.SCONST(string = yLabel), Exp.BCONST(bool = points), xRange, yRange
}),
(st as Interactive.SYMBOLTABLE(
ast = p,explodedAst = sp,instClsLst = ic,
lstVarVal = iv,compiledFunctions = cf,
loadedFiles = lf)),msg)
local
Integer res;
Exp.Exp xRange, yRange;
list<Exp.Exp> vars;
// list<String> vars_3;
String interpolation, title, xLabel, yLabel, str, filename2;
Boolean legend, grid, logX, logY, points;
equation

// vars = Util.listMap(vars,Exp.CodeVarToCref);
// vars_1 = Util.listMap(vars, Exp.printExpStr) "plot" ;
// vars_2 = Util.listUnionElt("time", vars_1);

filename = Absyn.pathString(className);
filename2 = Util.stringAppendList({filename, "_res.plt"});

str = System.getVariableNames(filename2);
vars_2 = Util.stringSplitAtChar(str, " ");
// vars_2 =


value = System.readPtolemyplotDataset(filename2, vars_2, 0);

res = Values.sendPtolemyplotDataset(value, vars_2, "Plot by OpenModelica", interpolation, title, legend, grid, logX, logY, xLabel, yLabel, points, Exp.printExpStr(xRange), Exp.printExpStr(yRange));

then
(cache,Values.BOOL(true),st);


//plotAll() - missing file
case (cache,env,
Exp.CALL(
path = Absyn.IDENT(name = "plotAll"),
expLst = {
// Exp.CODE(Absyn.C_TYPENAME(className),_),
Exp.SCONST(string = interpolation), Exp.SCONST(string = title), Exp.BCONST(bool = legend), Exp.BCONST(bool = grid), Exp.BCONST(bool = logX), Exp.BCONST(bool = logY), Exp.SCONST(string = xLabel), Exp.SCONST(string = yLabel), Exp.BCONST(bool = points), xRange, yRange
}),
(st as Interactive.SYMBOLTABLE(
ast = p,explodedAst = sp,instClsLst = ic,
lstVarVal = iv,compiledFunctions = cf,
loadedFiles = lf)),msg)
local
Integer res;
Exp.Exp xRange, yRange;
list<Exp.Exp> vars;
// list<String> vars_3;
String interpolation, title, xLabel, yLabel, str;//, filename2;
Boolean legend, grid, logX, logY, points;
equation

(cache,Values.RECORD(_,{Values.STRING(filename)},_),_) = ceval(cache,env,
Exp.CREF(Exp.CREF_IDENT("currentSimulationResult",{}),Exp.OTHER()), true, SOME(st), NONE, msg);
failure(_ = System.getVariableNames(filename));
// vars_2 = Util.stringSplitAtChar(str, " ");

// failure(_ = System.readPtolemyplotDataset(filename, vars_2, 0));

then
(cache,Values.STRING("Error reading the simulation result."),st);


//plotAll()
case (cache,env,
Exp.CALL(
path = Absyn.IDENT(name = "plotAll"),
expLst = {
// Exp.CODE(Absyn.C_TYPENAME(className),_),
Exp.SCONST(string = interpolation), Exp.SCONST(string = title), Exp.BCONST(bool = legend), Exp.BCONST(bool = grid), Exp.BCONST(bool = logX), Exp.BCONST(bool = logY), Exp.SCONST(string = xLabel), Exp.SCONST(string = yLabel), Exp.BCONST(bool = points), xRange, yRange
}),
(st as Interactive.SYMBOLTABLE(
ast = p,explodedAst = sp,instClsLst = ic,
lstVarVal = iv,compiledFunctions = cf,
loadedFiles = lf)),msg)
local
Integer res;
Exp.Exp xRange, yRange;
list<Exp.Exp> vars;
// list<String> vars_3;
String interpolation, title, xLabel, yLabel, str;//, filename2;
Boolean legend, grid, logX, logY, points;
equation

(cache,Values.RECORD(_,{Values.STRING(filename)},_),_) = ceval(cache,env,
Exp.CREF(Exp.CREF_IDENT("currentSimulationResult",{}),Exp.OTHER()), true, SOME(st), NONE, msg);
str = System.getVariableNames(filename);
vars_2 = Util.stringSplitAtChar(str, " ");
value = System.readPtolemyplotDataset(filename, vars_2, 0);

res = Values.sendPtolemyplotDataset(value, vars_2, "Plot by OpenModelica", interpolation, title, legend, grid, logX, logY, xLabel, yLabel, points, Exp.printExpStr(xRange), Exp.printExpStr(yRange));

then
(cache,Values.BOOL(true),st);



// plot(model, x)
case (cache,env,
Exp.CALL(
Expand Down
89 changes: 82 additions & 7 deletions Compiler/Static.mo
Expand Up @@ -5211,6 +5211,81 @@ algorithm
(cache,Exp.CALL(Absyn.IDENT("plot"),{Exp.ARRAY(Exp.OTHER(),false,vars_1)},
false,true,Exp.BOOL()),Types.PROP((Types.T_BOOL({}),NONE),Types.C_VAR()),SOME(st));

//plotAll(model)
case (cache,env,Absyn.CREF_IDENT(name = "plotAll"),{Absyn.CREF(componentReg = cr)},args,impl,SOME(st)) /* Fill in rest of defaults here */
local Absyn.Path className; Exp.Exp storeInTemp;
Exp.Exp interpolation, title, legend, grid, logX, logY, xLabel, yLabel, points, xRange, yRange;

equation
// vars_1 = elabVariablenames({cr2});
className = Absyn.crefToPath(cr);
(cache,interpolation) = getOptionalNamedArg(cache,env, SOME(st), impl, "interpolation", (Types.T_STRING({}),NONE),
args, Exp.SCONST("linear"));
(cache,title) = getOptionalNamedArg(cache,env, SOME(st), impl, "title", (Types.T_STRING({}),NONE),
args, Exp.SCONST("Plot by OpenModelica"));
(cache,legend) = getOptionalNamedArg(cache,env, SOME(st), impl, "legend", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(true));
(cache,grid) = getOptionalNamedArg(cache,env, SOME(st), impl, "grid", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(true));
(cache,logX) = getOptionalNamedArg(cache,env, SOME(st), impl, "logX", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(false));
(cache,logY) = getOptionalNamedArg(cache,env, SOME(st), impl, "logY", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(false));
(cache,xLabel) = getOptionalNamedArg(cache,env, SOME(st), impl, "xLabel", (Types.T_STRING({}),NONE),
args, Exp.SCONST("time"));
(cache,yLabel) = getOptionalNamedArg(cache,env, SOME(st), impl, "yLabel", (Types.T_STRING({}),NONE),
args, Exp.SCONST(""));
(cache,points) = getOptionalNamedArg(cache,env, SOME(st), impl, "points", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(false));

(cache,xRange) = getOptionalNamedArg(cache,env, SOME(st), impl, "xRange", (Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_REAL({}), NONE)),NONE),
args, Exp.ARRAY(Exp.REAL(), false, {Exp.RCONST(0.0), Exp.RCONST(0.0)}));// Exp.ARRAY(Exp.REAL(), false, {0, 0}));
(cache,yRange) = getOptionalNamedArg(cache,env, SOME(st), impl, "yRange", (Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_REAL({}), NONE)),NONE),
args, Exp.ARRAY(Exp.REAL(), false, {Exp.RCONST(0.0), Exp.RCONST(0.0)}));// Exp.ARRAY(Exp.REAL(), false, {0, 0}));


then
(cache,Exp.CALL(Absyn.IDENT("plotAll"),{Exp.CODE(Absyn.C_TYPENAME(className),Exp.OTHER()), interpolation, title, legend, grid, logX, logY, xLabel, yLabel, points, xRange, yRange},
false,true,Exp.BOOL()),Types.PROP((Types.T_BOOL({}),NONE),Types.C_VAR()),SOME(st));

//plotAll()
case (cache,env,Absyn.CREF_IDENT(name = "plotAll"),{},args,impl,SOME(st)) /* Fill in rest of defaults here */
local Absyn.Path className; Exp.Exp storeInTemp;
Exp.Exp interpolation, title, legend, grid, logX, logY, xLabel, yLabel, points, xRange, yRange;

equation
// vars_1 = elabVariablenames({cr2});
// className = Absyn.crefToPath(cr);
(cache,interpolation) = getOptionalNamedArg(cache,env, SOME(st), impl, "interpolation", (Types.T_STRING({}),NONE),
args, Exp.SCONST("linear"));
(cache,title) = getOptionalNamedArg(cache,env, SOME(st), impl, "title", (Types.T_STRING({}),NONE),
args, Exp.SCONST("Plot by OpenModelica"));
(cache,legend) = getOptionalNamedArg(cache,env, SOME(st), impl, "legend", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(true));
(cache,grid) = getOptionalNamedArg(cache,env, SOME(st), impl, "grid", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(true));
(cache,logX) = getOptionalNamedArg(cache,env, SOME(st), impl, "logX", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(false));
(cache,logY) = getOptionalNamedArg(cache,env, SOME(st), impl, "logY", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(false));
(cache,xLabel) = getOptionalNamedArg(cache,env, SOME(st), impl, "xLabel", (Types.T_STRING({}),NONE),
args, Exp.SCONST("time"));
(cache,yLabel) = getOptionalNamedArg(cache,env, SOME(st), impl, "yLabel", (Types.T_STRING({}),NONE),
args, Exp.SCONST(""));
(cache,points) = getOptionalNamedArg(cache,env, SOME(st), impl, "points", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(false));

(cache,xRange) = getOptionalNamedArg(cache,env, SOME(st), impl, "xRange", (Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_REAL({}), NONE)),NONE),
args, Exp.ARRAY(Exp.REAL(), false, {Exp.RCONST(0.0), Exp.RCONST(0.0)}));// Exp.ARRAY(Exp.REAL(), false, {0, 0}));
(cache,yRange) = getOptionalNamedArg(cache,env, SOME(st), impl, "yRange", (Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_REAL({}), NONE)),NONE),
args, Exp.ARRAY(Exp.REAL(), false, {Exp.RCONST(0.0), Exp.RCONST(0.0)}));// Exp.ARRAY(Exp.REAL(), false, {0, 0}));


then
(cache,Exp.CALL(Absyn.IDENT("plotAll"),{interpolation, title, legend, grid, logX, logY, xLabel, yLabel, points, xRange, yRange},
false,true,Exp.BOOL()),Types.PROP((Types.T_BOOL({}),NONE),Types.C_VAR()),SOME(st));


//plot2(model, x)
case (cache,env,Absyn.CREF_IDENT(name = "plot2"),{Absyn.CREF(componentReg = cr), cr2 as Absyn.CREF(componentReg = _)},args,impl,SOME(st)) /* Fill in rest of defaults here */
local Absyn.Path className; Exp.Exp storeInTemp; Absyn.Exp cr2;
Expand All @@ -5236,7 +5311,7 @@ algorithm
(cache,yLabel) = getOptionalNamedArg(cache,env, SOME(st), impl, "yLabel", (Types.T_STRING({}),NONE),
args, Exp.SCONST(""));
(cache,points) = getOptionalNamedArg(cache,env, SOME(st), impl, "points", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(true));
args, Exp.BCONST(false));

(cache,xRange) = getOptionalNamedArg(cache,env, SOME(st), impl, "xRange", (Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_REAL({}), NONE)),NONE),
args, Exp.ARRAY(Exp.REAL(), false, {Exp.RCONST(0.0), Exp.RCONST(0.0)}));// Exp.ARRAY(Exp.REAL(), false, {0, 0}));
Expand Down Expand Up @@ -5275,7 +5350,7 @@ algorithm
(cache,yLabel) = getOptionalNamedArg(cache,env, SOME(st), impl, "yLabel", (Types.T_STRING({}),NONE),
args, Exp.SCONST(""));
(cache,points) = getOptionalNamedArg(cache,env, SOME(st), impl, "points", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(true));
args, Exp.BCONST(false));

(cache,xRange) = getOptionalNamedArg(cache,env, SOME(st), impl, "xRange", (Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_REAL({}), NONE)),NONE),
args, Exp.ARRAY(Exp.REAL(), false, {Exp.RCONST(0.0), Exp.RCONST(0.0)}));// Exp.ARRAY(Exp.REAL(), false, {0, 0}));
Expand Down Expand Up @@ -5312,7 +5387,7 @@ algorithm
(cache,yLabel) = getOptionalNamedArg(cache,env, SOME(st), impl, "yLabel", (Types.T_STRING({}),NONE),
args, Exp.SCONST(""));
(cache,points) = getOptionalNamedArg(cache,env, SOME(st), impl, "points", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(true));
args, Exp.BCONST(false));

(cache,xRange) = getOptionalNamedArg(cache,env, SOME(st), impl, "xRange", (Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_REAL({}), NONE)),NONE),
args, Exp.ARRAY(Exp.REAL(), false, {Exp.RCONST(0.0), Exp.RCONST(0.0)}));// Exp.ARRAY(Exp.REAL(), false, {0, 0}));
Expand Down Expand Up @@ -5346,7 +5421,7 @@ algorithm
(cache,yLabel) = getOptionalNamedArg(cache,env, SOME(st), impl, "yLabel", (Types.T_STRING({}),NONE),
args, Exp.SCONST(""));
(cache,points) = getOptionalNamedArg(cache,env, SOME(st), impl, "points", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(true));
args, Exp.BCONST(false));

(cache,xRange) = getOptionalNamedArg(cache,env, SOME(st), impl, "xRange", (Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_REAL({}), NONE)),NONE),
args, Exp.ARRAY(Exp.REAL(), false, {Exp.RCONST(0.0), Exp.RCONST(0.0)}));// Exp.ARRAY(Exp.REAL(), false, {0, 0}));
Expand Down Expand Up @@ -5422,7 +5497,7 @@ algorithm
(cache,yLabel) = getOptionalNamedArg(cache,env, SOME(st), impl, "yLabel", (Types.T_STRING({}),NONE),
args, Exp.SCONST(""));
(cache,points) = getOptionalNamedArg(cache,env, SOME(st), impl, "points", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(true));
args, Exp.BCONST(false));

(cache,xRange) = getOptionalNamedArg(cache,env, SOME(st), impl, "xRange", (Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_REAL({}), NONE)),NONE),
args, Exp.ARRAY(Exp.REAL(), false, {Exp.RCONST(0.0), Exp.RCONST(0.0)}));// Exp.ARRAY(Exp.REAL(), false, {0, 0}));
Expand Down Expand Up @@ -5465,7 +5540,7 @@ algorithm
(cache,yLabel) = getOptionalNamedArg(cache,env, SOME(st), impl, "yLabel", (Types.T_STRING({}),NONE),
args, Exp.SCONST(""));
(cache,points) = getOptionalNamedArg(cache,env, SOME(st), impl, "points", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(true));
args, Exp.BCONST(false));

(cache,xRange) = getOptionalNamedArg(cache,env, SOME(st), impl, "xRange", (Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_REAL({}), NONE)),NONE),
args, Exp.ARRAY(Exp.REAL(), false, {Exp.RCONST(0.0), Exp.RCONST(0.0)}));// Exp.ARRAY(Exp.REAL(), false, {0, 0}));
Expand Down Expand Up @@ -5503,7 +5578,7 @@ algorithm
(cache,yLabel) = getOptionalNamedArg(cache,env, SOME(st), impl, "yLabel", (Types.T_STRING({}),NONE),
args, Exp.SCONST(""));
(cache,points) = getOptionalNamedArg(cache,env, SOME(st), impl, "points", (Types.T_BOOL({}),NONE),
args, Exp.BCONST(true));
args, Exp.BCONST(false));

(cache,xRange) = getOptionalNamedArg(cache,env, SOME(st), impl, "xRange", (Types.T_ARRAY(Types.DIM(SOME(2)),(Types.T_REAL({}), NONE)),NONE),
args, Exp.ARRAY(Exp.REAL(), false, {Exp.RCONST(0.0), Exp.RCONST(0.0)}));// Exp.ARRAY(Exp.REAL(), false, {0, 0}));
Expand Down
7 changes: 7 additions & 0 deletions Compiler/System.mo
Expand Up @@ -276,6 +276,13 @@ public function readPtolemyplotDataset
external "C" ;
end readPtolemyplotDataset;

public function getVariableNames
input String modelname;
output String variables;

external "C";
end getVariableNames;

public function readPtolemyplotDatasetSize
input String inString;
output Values.Value outValue;
Expand Down
32 changes: 32 additions & 0 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -945,6 +945,22 @@ RML_BEGIN_LABEL(System__moFiles)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__getVariableNames)
{
char* model = RML_STRINGDATA(rmlA0);
int size = getVariableListSize(model);

if(!size)
RML_TAILCALLK(rmlFC);

char* lst = (char*)malloc(sizeof(char)*size +1);

getVariableList(model, lst);
rmlA0 = (void*)mk_scon(lst);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__readPtolemyplotDataset)
{
rml_sint_t i,size;
Expand Down Expand Up @@ -2170,6 +2186,22 @@ RML_BEGIN_LABEL(System__moFiles)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__getVariableNames)
{
char* model = RML_STRINGDATA(rmlA0);
int size = getVariableListSize(model);

if(!size)
RML_TAILCALLK(rmlFC);

char* lst = (char*)malloc(sizeof(char)*size +1);

getVariableList(model, lst);
rmlA0 = (void*)mk_scon(lst);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__readPtolemyplotDataset)
{
rml_sint_t i,size;
Expand Down
15 changes: 15 additions & 0 deletions c_runtime/sendData/humbug.cpp
Expand Up @@ -141,3 +141,18 @@ bool Static::enabled()
{
return false;
}


int getVariableListSize(const char* model)
{
errmsg();
return 0;

}

bool getVariableList(const char* model, char* lst)
{
errmsg();
return false;

}
2 changes: 2 additions & 0 deletions c_runtime/sendData/humbug.h
Expand Up @@ -95,6 +95,8 @@ void errmsg();
bool hold(int = 1);
bool pltWait(unsigned long msecs);

int getVariableListSize(const char* model);
bool getVariableList(const char* model, char* lst);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 4f47921

Please sign in to comment.