Skip to content

Commit

Permalink
rename Cpp command line arguments
Browse files Browse the repository at this point in the history
avoid name clashes with the C runtime, e.g. when used from OMEdit
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Aug 10, 2015
1 parent ec27dd8 commit 19060fd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
20 changes: 10 additions & 10 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -1666,7 +1666,7 @@ template simulationMainRunScript(SimCode simCode ,Text& extraFuncs,Text& extraFu
let solver = settings.method
let moLib = makefileParams.compileDir
let home = makefileParams.omhome
let execParameters = '-s <%start%> -e <%end%> -f <%stepsize%> -v <%intervals%> -y <%tol%> -i <%solver%> -r <%simulationLibDir(simulationCodeTarget(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%> -m <%moLib%> -R <%simulationResults(getRunningTestsuite(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>'
let execParameters = '-S <%start%> -E <%end%> -H <%stepsize%> -G <%intervals%> -T <%tol%> -I <%solver%> -R <%simulationLibDir(simulationCodeTarget(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%> -M <%moLib%> -r <%simulationResults(getRunningTestsuite(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>'
let outputParameter = if (stringEq(settings.outputFormat, "empty")) then "-O none" else ""
let fileNamePrefixx = fileNamePrefix

Expand Down Expand Up @@ -2288,15 +2288,15 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
{
// default program options
std::map<std::string, std::string> opts;
opts["-s"] = "<%start%>";
opts["-e"] = "<%end%>";
opts["-f"] = "<%stepsize%>";
opts["-v"] = "<%intervals%>";
opts["-y"] = "<%tol%>";
opts["-i"] = "<%solver%>";
opts["-r"] = "<%simulationLibDir(simulationCodeTarget(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>";
opts["-m"] = "<%moLib%>";
opts["-R"] = "<%simulationResults(getRunningTestsuite(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>";
opts["-S"] = "<%start%>";
opts["-E"] = "<%end%>";
opts["-H"] = "<%stepsize%>";
opts["-G"] = "<%intervals%>";
opts["-T"] = "<%tol%>";
opts["-I"] = "<%solver%>";
opts["-R"] = "<%simulationLibDir(simulationCodeTarget(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>";
opts["-M"] = "<%moLib%>";
opts["-r"] = "<%simulationResults(getRunningTestsuite(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>";
<%if (stringEq(settings.outputFormat, "empty")) then 'opts["-O"] = "none";' else ""%>
<%
match(getConfigString(PROFILING_LEVEL))
Expand Down
Expand Up @@ -32,7 +32,8 @@ class OMCFactory
virtual std::pair<boost::shared_ptr<ISimController>,SimSettings> createSimulation(int argc, const char* argv[], std::map<std::string, std::string> &opts);

protected:
std::vector<const char *> modifyArguments(int argc, const char* argv[], std::map<std::string, std::string> &opts);
/** merge command line args with built-in args and adapt OMEdit args to Cpp */
std::vector<const char *> preprocessArguments(int argc, const char* argv[], std::map<std::string, std::string> &opts);
SimSettings readSimulationParameter(int argc, const char* argv[]);

//boost::shared_ptr<ISimController> _simController;
Expand Down
44 changes: 25 additions & 19 deletions SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp
Expand Up @@ -62,20 +62,20 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
desc.add_options()
("help", "produce help message")
("emit_protected", "emits protected variables to the result file")
("runtime-library,r", po::value<string>(),"path to cpp runtime libraries")
("Modelica-system-library,m", po::value<string>(), "path to Modelica library")
("results-file,R", po::value<string>(),"name of results file")
//("config-path,c", po::value< string >(), "path to xml files")
("start-time,s", po::value< double >()->default_value(0.0), "simulation start time")
("stop-time,e", po::value< double >()->default_value(1.0), "simulation stop time")
("step-size,f", po::value< double >()->default_value(0.0), "simulation step size")
("solver,i", po::value< string >()->default_value("euler"), "solver method")
("runtime-library,R", po::value<string>(),"path to cpp runtime libraries")
("Modelica-system-library,M", po::value<string>(), "path to Modelica library")
("results-file,r", po::value<string>(),"name of results file")
//("config-path,f", po::value< string >(), "path to xml files")
("start-time,S", po::value< double >()->default_value(0.0), "simulation start time")
("stop-time,E", po::value< double >()->default_value(1.0), "simulation stop time")
("step-size,H", po::value< double >()->default_value(0.0), "simulation step size")
("solver,I", po::value< string >()->default_value("euler"), "solver method")
("lin-solver,L", po::value< string >()->default_value(_defaultLinSolver), "linear solver method")
("non-lin-solver,N", po::value< string >()->default_value(_defaultNonLinSolver), "non linear solver method")
("number-of-intervals,v", po::value< int >()->default_value(500), "number of intervals")
("tolerance,y", po::value< double >()->default_value(1e-6), "solver tolerance")
("log-settings,l", po::value< std::vector<std::string> >(), "log information: init, nls, ls, solv, output, event, model, other")
("alarm,a", po::value<unsigned int >()->default_value(360), "sets timeout in seconds for simulation")
("number-of-intervals,G", po::value< int >()->default_value(500), "number of intervals in equidistant grid")
("tolerance,T", po::value< double >()->default_value(1e-6), "solver tolerance")
("log-settings,V", po::value< std::vector<std::string> >(), "log information: init, nls, ls, solv, output, event, model, other")
("alarm,A", po::value<unsigned int >()->default_value(360), "sets timeout in seconds for simulation")
("output-type,O", po::value< string >()->default_value("all"), "the points in time written to result file: all (output steps + events), step (just output points), none")
("OMEdit", po::value<vector<string> >(), "OMEdit options")
;
Expand Down Expand Up @@ -108,7 +108,7 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
double stepsize =vm["step-size"].as<double>();

if (!(stepsize > 0.0))
stepsize = stoptime/vm["number-of-intervals"].as<int>();
stepsize = (stoptime - starttime) / vm["number-of-intervals"].as<int>();

double tolerance =vm["tolerance"].as<double>();
string solver = vm["solver"].as<string>();
Expand Down Expand Up @@ -161,7 +161,7 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
}
else
{
throw ModelicaSimulationError(MODEL_FACTORY,"results-filename is not set");
throw ModelicaSimulationError(MODEL_FACTORY, "output-type is not set");
}

LogSettings logSet;
Expand Down Expand Up @@ -211,19 +211,25 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])

}

std::vector<const char *> OMCFactory::modifyArguments(int argc, const char* argv[], std::map<std::string, std::string> &opts)
std::vector<const char *> OMCFactory::preprocessArguments(int argc, const char* argv[], std::map<std::string, std::string> &opts)
{
std::map<std::string, std::string>::const_iterator oit;
std::vector<const char *> optv;
optv.push_back(argv[0]);
std::string override; // OMEdit override option
for (int i = 1; i < argc; i++) {
if ((oit = opts.find(argv[i])) != opts.end() && i < argc - 1)
string arg = argv[i];
int j;
if (arg[0] == '-' && arg[1] != '-' && (j = arg.find('=')) > 0
&& (oit = opts.find(arg.substr(0, j))) != opts.end())
opts[oit->first] = arg.substr(j + 1); // split at = and override
else if ((oit = opts.find(arg)) != opts.end() && i < argc - 1)
opts[oit->first] = argv[++i]; // regular override
else if (strncmp(argv[i], "-override=", 10) == 0) {
std::map<std::string, std::string> supported = map_list_of
("startTime", "-s")("stopTime", "-e")("stepSize", "-f")
("tolerance", "-y")("solver", "-i");
("startTime", "-S")("stopTime", "-E")("stepSize", "-H")
("numberOfIntervals", "-G")("solver", "-I")("tolerance", "-T")
("outputFormat", "-O");
std::vector<std::string> strs;
boost::split(strs, argv[i], boost::is_any_of(",="));
for (int j = 1; j < strs.size(); j++) {
Expand Down Expand Up @@ -260,7 +266,7 @@ std::pair<boost::shared_ptr<ISimController>,SimSettings>
OMCFactory::createSimulation(int argc, const char* argv[],
std::map<std::string, std::string> &opts)
{
std::vector<const char *> optv = modifyArguments(argc, argv, opts);
std::vector<const char *> optv = preprocessArguments(argc, argv, opts);

SimSettings settings = readSimulationParameter(optv.size(), &optv[0]);
type_map simcontroller_type_map;
Expand Down
Expand Up @@ -50,7 +50,7 @@ boost::shared_ptr<ISettingsFactory> StaticOMCFactory::createSettingsFactory()

std::pair<boost::shared_ptr<ISimController>,SimSettings> StaticOMCFactory::createSimulation(int argc, const char* argv[], std::map<std::string, std::string> &opts)
{
std::vector<const char *> optv = modifyArguments(argc, argv, opts);
std::vector<const char *> optv = preprocessArguments(argc, argv, opts);
SimSettings settings = readSimulationParameter(optv.size(), &optv[0]);
boost::shared_ptr<ISimController> simcontroller = boost::shared_ptr<ISimController>(new SimController(_library_path,_modelicasystem_path));
return std::make_pair(simcontroller,settings);
Expand Down

0 comments on commit 19060fd

Please sign in to comment.