Skip to content

Commit

Permalink
Assume the filename to load if none is specified
Browse files Browse the repository at this point in the history
* If no filename is specified and the current directory only
  contains a single result file, then that one is loaded
  automatically.
* Add error message to command line if no variable is specified.
  • Loading branch information
lochel committed Jan 23, 2017
1 parent 6205bff commit 0ca376f
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions OMPlot/OMPlotGUI/main.cpp
Expand Up @@ -75,6 +75,12 @@ void printUsage()
printf(" --auto-scale=[true|false] Use auto scale while plotting.\n");
}

void printShortUsage()
{
printf("Usage: OMPlot [OPTIONS] [--filename=NAME] [variable names]\n");
printf(" For detailed usage information, use 'OMPlot --help'.\n");
}

int main(int argc, char *argv[])
{
// read the arguments
Expand Down Expand Up @@ -158,11 +164,43 @@ int main(int argc, char *argv[])
vars.append(argv[i]);
}
}

if (filename.length() == 0) {
fprintf(stderr, "Error: No filename given\n");
printUsage();
QStringList nameFilter = (QStringList() << "*.mat" << "*.csv");

QDir directory(".");
QStringList resultFiles = directory.entryList(nameFilter);
int count = resultFiles.count();

if(count == 0)
{
fprintf(stderr, "Error: No filename specified.\n");
printShortUsage();
return 1;
}
else if(count == 1)
{
filename = resultFiles.at(0);
fprintf(stdout, "WARN: No filename specified, so the following filename is assumed:\n '%s'\n", filename.toUtf8().constData());
}
else
{
fprintf(stdout, "Info: This directory contains following result files:\n");
for(int i=0;i<count;i++)
fprintf(stderr, " * '%s'\n", resultFiles.at(i).toUtf8().constData());

fprintf(stderr, "Error: No filename specified.\n");
printShortUsage();
return 1;
}
}

if (vars.count() == 0) {
fprintf(stderr, "Error: No variables specified.\n");
printShortUsage();
return 1;
}

// Hack to get the expected format of PlotApplication. Yes, this is totally crazy :)
arguments.append(argv[0]);
arguments.append(filename);
Expand Down

0 comments on commit 0ca376f

Please sign in to comment.