Skip to content

Commit

Permalink
-changed simulation arguments to program_options, modified CevalScrip…
Browse files Browse the repository at this point in the history
…t for cpp simulation call

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12397 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Aug 2, 2012
1 parent d6af769 commit 74f8575
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Compiler/Script/CevalScript.mo
Expand Up @@ -1343,7 +1343,7 @@ algorithm
libDir= Settings.getInstallationDirectoryPath() +& "/lib/omc" ;
configDir=Settings.getInstallationDirectoryPath() +& "/share/omc/runtime/cpp/";
result_file = stringAppendList(List.consOnTrue(not Config.getRunningTestsuite(),compileDir,{executable,"_res.",outputFormat_str}));
simflags2=Util.if_(ifcpp,stringAppendList({libDir," ",compileDir," ",result_file," ",configDir}), simflags);
simflags2=Util.if_(ifcpp,stringAppendList({"-r ",libDir," ","-m ",compileDir," ","-R ",result_file," ","-c ",configDir}), simflags);
executable1=Util.if_(ifcpp,"OMCppSimulation",executable);
executableSuffixedExe = stringAppend(executable1, System.getExeExt());
// sim_call = stringAppendList({"sh -c ",cit,"ulimit -t 60; ",cit,pwd,pd,executableSuffixedExe,cit," > output.log 2>&1",cit});
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/cpp/Source/CMakeLists.txt
Expand Up @@ -48,7 +48,7 @@ SET(USE_SUNDIALS ON)
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREADED ON)
SET(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.45.0 COMPONENTS filesystem system serialization REQUIRED)
find_package(Boost 1.45.0 COMPONENTS filesystem system serialization program_options REQUIRED)
# Lapack and Blas
find_package( BLAS )
find_package( LAPACK )
Expand Down
129 changes: 100 additions & 29 deletions SimulationRuntime/cpp/Source/SimManager/Main.cpp
Expand Up @@ -3,51 +3,115 @@
#include "Configuration.h"
#include "System/Interfaces/ISystemProperties.h"
#include "LibrariesConfig.h"
#include <boost/program_options.hpp>

namespace po = boost::program_options;
namespace fs = boost::filesystem;
using namespace std;



int nargc=5;
int lib_index= 1;
int modelica_index = 2;
int modelname_index = 3;
int config_index = 4;
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <tchar.h>
int _tmain(int argc, _TCHAR* argv[])
#else
int main(int argc, const char* argv[])
#endif
{
if(argc < nargc)
throw std::invalid_argument("No runtime library path and Modelica system library path defined");

string runtime_lib_path = argv[lib_index];
fs::path libraries_path = fs::path( runtime_lib_path) ;
fs::path modelica_path = fs::path( argv[modelica_index] ) ;
fs::path config_path = fs::path( argv[config_index] ) ;
libraries_path.make_preferred();
modelica_path.make_preferred();
config_path.make_preferred();
string resultsfilename(argv[modelname_index]);


fs::path results_file_path = fs::path( resultsfilename) ;
if(!(results_file_path.extension().string() == ".csv"))
{
std::string eception_msg = "The output format is not supported yet. Please use outputFormat=\"csv\" in simulate command ";
throw std::invalid_argument(eception_msg.c_str());
}
//std::cout << libraries_path << " end" << std::endl;
try
{

try
{
int opt;
int portnum;

po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("runtime-libray,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")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
string runtime_lib_path;

if (vm.count("runtime-libray"))
{
//cout << "runtime library path set to " << vm["runtime-libray"].as<string>() << std::endl;
runtime_lib_path = vm["runtime-libray"].as<string>();
}
else
{
cerr << "runtime libraries path is not set";
return 0;
}
fs::path libraries_path = fs::path( runtime_lib_path) ;

fs::path modelica_path;
if (vm.count("Modelica-system-library"))
{
//cout << "Modelica library path set to " << vm["Modelica-system-library"].as<string>() << std::endl;
modelica_path = fs::path(vm["Modelica-system-library"].as<string>());
}
else
{
cerr << "Modelica library path is not set";
return 0;
}
fs::path config_path;
if (vm.count("config-path"))
{
//cout << "config path set to " << vm["config-path"].as<string>() << std::endl;
config_path = fs::path(vm["config-path"].as<string>());

}
else
{
cerr << "config path is not set";
return 0;
}
string resultsfilename;
if (vm.count("results-file"))
{
//cout << "results file: " << vm["results-file"].as<string>() << std::endl;
resultsfilename = vm["results-file"].as<string>();

}
else
{
cerr << "resultsfilename is not set";
return 0;
}

libraries_path.make_preferred();
modelica_path.make_preferred();
config_path.make_preferred();



fs::path results_file_path = fs::path( resultsfilename) ;
if(!(results_file_path.extension().string() == ".csv"))
{
std::string eception_msg = "The output format is not supported yet. Please use outputFormat=\"csv\" in simulate command ";
cerr << eception_msg.c_str();
return 0;
}

//std::cout << libraries_path << " end" << std::endl;


Configuration config(libraries_path,config_path);
IGlobalSettings* global_settings = config.getGlobalSettings();
global_settings->setRuntimeLibrarypath(runtime_lib_path);
global_settings->setResultsFileName(resultsfilename);
//Load Modelica sytem library


fs::path modelica_system_name(MODELICASYSTEM_LIB);
fs::path modelica_system_path = modelica_path;
Expand Down Expand Up @@ -103,12 +167,19 @@ int main(int argc, const char* argv[])
//solver->reportErrorMessage(std::cout);
return 0;
}

catch(exception& e)
{
cerr << "error: " << e.what() << "\n";
return 1;
}
catch(std::exception& ex)
{
std::string error = ex.what();
std::cout << "Simulation stopped: "<< std::endl << error << std::endl;
cerr << "Simulation stopped: "<< error ;
return 1;
}

}


0 comments on commit 74f8575

Please sign in to comment.