Skip to content

Commit d55aa1a

Browse files
committed
OMPlot
- Added support for MATLAB files with any name of the time variable (it is always index 0) - Added support for reading parameters (previously, the variables matrix was read for these) - Added error messages for invalid input - Added better Usage text git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8226 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent ac2d895 commit d55aa1a

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

OMPlot/OMPlotGUI/PlotWindow.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,31 @@ PlotWindow::PlotWindow(QStringList arguments, QWidget *parent)
5353
setLegend(true);
5454
else if(QString(arguments[3]) == "false")
5555
setLegend(false);
56+
else
57+
throw PlotException("Invalid input");
5658
// read the grid
5759
if(QString(arguments[4]) == "true")
5860
setGrid(true);
5961
else if(QString(arguments[4]) == "false")
6062
setGrid(false);
63+
else
64+
throw PlotException("Invalid input");
6165
// read the plot type
6266
QString plotType = arguments[5];
6367
// read the logx
6468
if(QString(arguments[6]) == "true")
6569
setLogX(true);
6670
else if(QString(arguments[6]) == "false")
6771
setLogX(false);
72+
else
73+
throw PlotException("Invalid input");
6874
// read the logy
6975
if(QString(arguments[7]) == "true")
7076
setLogY(true);
7177
else if(QString(arguments[7]) == "false")
7278
setLogY(false);
79+
else
80+
throw PlotException("Invalid input");
7381
// read the x label value
7482
setXLabel(QString(arguments[8]));
7583
// read the y label value
@@ -344,8 +352,9 @@ void PlotWindow::plot(QStringList variables)
344352

345353
//Read in timevector
346354
QVector<double> timeVector;
347-
var = omc_matlab4_find_var(&reader, "Time");
348-
double *vals = omc_matlab4_read_vals(&reader,var->index);
355+
if (reader.nvar < 1)
356+
throw NoVariableException("Variable doesnt exist: time");
357+
double *vals = omc_matlab4_read_vals(&reader,0);
349358
for (int j = 0; j<reader.nrows; j++)
350359
timeVector.push_back(vals[j]);
351360

@@ -360,8 +369,6 @@ void PlotWindow::plot(QStringList variables)
360369
for(int i = 0; i < variables.length(); i++)
361370
{
362371
QString currentPlotVariable = variables[i];
363-
if(currentPlotVariable == "time")
364-
currentPlotVariable = "Time";
365372

366373
PlotCurve *pPlotCurve = new PlotCurve(mpPlot);
367374
pPlotCurve->setXAxisVector(timeVector);
@@ -370,9 +377,17 @@ void PlotWindow::plot(QStringList variables)
370377
var = omc_matlab4_find_var(&reader, currentPlotVariable.toStdString().c_str());
371378
if(!var)
372379
throw NoVariableException(QString("Variable doesnt exist : ").append(currentPlotVariable).toStdString().c_str());
373-
vals = omc_matlab4_read_vals(&reader, var->index);
374-
for (int j = 0; j < reader.nrows; j++)
375-
pPlotCurve->addYAxisValue(vals[j]);
380+
if (!var->isParam) {
381+
vals = omc_matlab4_read_vals(&reader, var->index);
382+
for (int j = 0; j < reader.nrows; j++)
383+
pPlotCurve->addYAxisValue(vals[j]);
384+
} else {
385+
double val;
386+
if (omc_matlab4_val(&val,&reader,var,0.0))
387+
throw NoVariableException(QString("Parameter doesn't have a value : ").append(currentPlotVariable).toStdString().c_str());
388+
for (int j = 0; j < reader.nrows; j++)
389+
pPlotCurve->addYAxisValue(val);
390+
}
376391

377392
//Set curvename and push back to list
378393
pPlotCurve->setTitle(variables[i]);
@@ -518,11 +533,6 @@ void PlotWindow::plotParametric(QString xVariable, QString yVariable)
518533
if(0 != (msg = omc_new_matlab4_reader(mpFile->fileName().toStdString().c_str(), &reader)))
519534
return;
520535

521-
if(xVariable == "time")
522-
xVariable = "Time";
523-
if(yVariable == "time")
524-
yVariable = "Time";
525-
526536
PlotCurve *pPlotCurve = new PlotCurve(mpPlot);
527537

528538
//Fill variable x with data

OMPlot/OMPlotGUI/PlotWindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class NoFileException : public PlotException
115115
class NoVariableException : public PlotException
116116
{
117117
public:
118-
NoVariableException(const char * fileName) : PlotException(fileName) {}
118+
NoVariableException(const char * varName) : PlotException(varName) {}
119119
};
120120

121121
//Options Class

OMPlot/OMPlotGUI/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ using namespace OMPlot;
3939
int main(int argc, char *argv[])
4040
{
4141
if (argc < 14) {
42-
printf("Usage: %s arg1 ... arg13 variables\n", *argv);
42+
printf("Usage: %s filename title legend grid plottype logx logy xlabel ylabel xrange1 xrange2 yrange1 yrange2 variables\n", *argv);
4343
return 1;
4444
}
4545
QApplication a(argc, argv);

0 commit comments

Comments
 (0)