Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
[Cpp] Normalize paths for simple concatenation of file names
Browse files Browse the repository at this point in the history
This also reverts changes introduced in 2661fa9
to FMU GlobalSettings.

Belonging to [master]:
  - #2814
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Dec 4, 2018
1 parent 6770e63 commit de12219
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -1576,7 +1576,7 @@ template simulationResults(Boolean test, SimCode simCode ,Text& extraFuncs,Text&
::=
match simCode
case SIMCODE(modelInfo=MODELINFO(__),makefileParams=MAKEFILE_PARAMS(__),simulationSettingsOpt = SOME(settings as SIMULATION_SETTINGS(__))) then
let results = if test then "" else '<%makefileParams.compileDir%>/'
let results = if test then "" else '<%makefileParams.compileDir%>'
<<
<%results%><%fileNamePrefix%>_res.<%settings.outputFormat%>
>>
Expand Down Expand Up @@ -2280,9 +2280,9 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
opts["-T"] = "<%tol%>";
opts["-I"] = "<%solver%>";
opts["-P"] = "<%outputtype%>";
opts["-R"] = "<%simulationLibDir(simulationCodeTarget(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>";
opts["-R"] = "<%simulationLibDir(simulationCodeTarget(), simCode, &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>";
opts["-M"] = "<%moLib%>";
opts["-F"] = "<%simulationResults(getRunningTestsuite(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>";
opts["-F"] = "<%simulationResults(getRunningTestsuite(), simCode, &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)%>";
opts["--solver-threads"] = "<%if(intGt(getConfigInt(NUM_PROC), 0)) then getConfigInt(NUM_PROC) else 1%>";
<%if (stringEq(settings.outputFormat, "empty")) then 'opts["-O"] = "none";' else ""%>
<%
Expand Down
Expand Up @@ -12,7 +12,7 @@
XmlPropertyReader::XmlPropertyReader(IGlobalSettings *globalSettings, std::string propertyFile)
: IPropertyReader()
,_globalSettings(globalSettings)
,_propertyFile(globalSettings->getInputPath() + string("/") + propertyFile)
,_propertyFile(globalSettings->getInputPath() + propertyFile)
,_isInitialized(false)
{
}
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Include/FMU/FMUGlobalSettings.h
Expand Up @@ -32,8 +32,8 @@ class FMUGlobalSettings : public IGlobalSettings
///< Write out statistical simulation infos, e.g. number of steps (at the end of simulation); [false,true]; default: true)
virtual bool getInfoOutput() { return false; }
virtual void setInfoOutput(bool) {}
virtual string getOutputPath() { return "."; }
virtual string getInputPath() { return "."; }
virtual string getOutputPath() { return "./"; }
virtual string getInputPath() { return "./"; }
virtual LogSettings getLogSettings() {return LogSettings(LF_FMI);}
virtual void setLogSettings(LogSettings) {}
virtual OutputPointType getOutputPointType() { return OPT_ALL; };
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Include/FMU2/FMU2GlobalSettings.h
Expand Up @@ -64,8 +64,8 @@ class FMU2GlobalSettings : public IGlobalSettings
///< Write out statistical simulation infos, e.g. number of steps (at the end of simulation); [false,true]; default: true)
virtual bool getInfoOutput() { return false; }
virtual void setInfoOutput(bool) {}
virtual string getOutputPath() { return "."; }
virtual string getInputPath() { return "."; }
virtual string getOutputPath() { return "./"; }
virtual string getInputPath() { return "./"; }
virtual LogSettings getLogSettings() { return LogSettings(LF_FMI2); }
virtual void setLogSettings(LogSettings) {}
virtual OutputPointType getOutputPointType() { return OPT_ALL; };
Expand Down
28 changes: 20 additions & 8 deletions SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp
Expand Up @@ -89,6 +89,12 @@ class LoggerXMLTCP: public LoggerXML
std::stringstream _sstream;
};

inline void normalizePath(std::string& path)
{
if (path.length() > 0 && path[path.length() - 1] != '/')
path += "/";
}

/**
* Implementation of OMCFactory
*/
Expand Down Expand Up @@ -382,34 +388,40 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
if (!(stepsize > 0.0))
stepsize = (stoptime - starttime) / vm["number-of-intervals"].as<int>();

double tolerance =vm["tolerance"].as<double>();
string solver = vm["solver"].as<string>();
string nonLinSolver = vm["non-lin-solver"].as<string>();
string linSolver = vm["lin-solver"].as<string>();
unsigned int timeOut = vm["alarm"].as<unsigned int>();
double tolerance = vm["tolerance"].as<double>();
string solver = vm["solver"].as<string>();
string nonLinSolver = vm["non-lin-solver"].as<string>();
string linSolver = vm["lin-solver"].as<string>();
unsigned int timeOut = vm["alarm"].as<unsigned int>();
if (vm.count("runtime-library"))
{
//cout << "runtime library path set to " << vm["runtime-library"].as<string>() << endl;
runtime_lib_path = vm["runtime-library"].as<string>();
normalizePath(runtime_lib_path);
}
else
throw ModelicaSimulationError(MODEL_FACTORY,"runtime libraries path is not set");

if (vm.count("modelica-system-library"))
{
//cout << "Modelica library path set to " << vm["Modelica-system-library"].as<string>() << endl;
modelica_lib_path =vm["modelica-system-library"].as<string>();
modelica_lib_path = vm["modelica-system-library"].as<string>();
normalizePath(modelica_lib_path);
}
else
throw ModelicaSimulationError(MODEL_FACTORY,"Modelica library path is not set");

string inputPath, outputPath;
if (vm.count("input-path"))
if (vm.count("input-path")) {
inputPath = vm["input-path"].as<string>();
normalizePath(inputPath);
}
else
inputPath = modelica_lib_path;
if (vm.count("output-path"))
if (vm.count("output-path")) {
outputPath = vm["output-path"].as<string>();
normalizePath(outputPath);
}
else
outputPath = modelica_lib_path;

Expand Down

0 comments on commit de12219

Please sign in to comment.