Skip to content

Commit f13b50c

Browse files
authored
Try to preserve fmu name if running from command line (#1059)
1 parent d54078e commit f13b50c

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/OMSimulatorLib/OMSimulator.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,24 +1058,20 @@ static int do_simulation(std::string model, std::chrono::duration<double> timeou
10581058
return 0;
10591059
}
10601060

1061-
oms_status_enu_t oms_RunFile(const char* filename_)
1061+
oms_status_enu_t oms_RunFile(const char* filename)
10621062
{
10631063
oms_status_enu_t status;
1064-
std::string filename(filename_);
1065-
std::string type = "";
1066-
if (filename.length() > 4)
1067-
type = filename.substr(filename.length() - 4);
1068-
else
1069-
return logError("Not able to process file '" + filename + "'\nUse OMSimulator --help for more information.");
1064+
filesystem::path path(filename);
1065+
std::string type = path.extension().string();
10701066

10711067
if (type == ".fmu")
10721068
{
10731069
std::string modelName("model");
10741070
std::string systemName = modelName + ".root";
1075-
std::string fmuName = systemName + ".fmu";
1071+
std::string fmuName = systemName + (oms::ComRef::isValidIdent(path.stem().string()) ? ("." + path.stem().string()) : ".fmu");
10761072
oms_fmi_kind_enu_t kind;
10771073

1078-
status = oms_extractFMIKind(filename.c_str(), &kind);
1074+
status = oms_extractFMIKind(filename, &kind);
10791075
if (oms_status_ok != status) return logError("oms_extractFMIKind failed");
10801076

10811077
status = oms_newModel(modelName.c_str());
@@ -1092,7 +1088,7 @@ oms_status_enu_t oms_RunFile(const char* filename_)
10921088
status = oms_addSystem(systemName.c_str(), (kind == oms_fmi_kind_cs) ? oms_system_wc : oms_system_sc);
10931089
if (oms_status_ok != status) return logError("oms_addSystem failed");
10941090

1095-
status = oms_addSubModel(fmuName.c_str(), filename.c_str());
1091+
status = oms_addSubModel(fmuName.c_str(), filename);
10961092
if (oms_status_ok != status) return logError("oms_addSubModel failed");
10971093

10981094
if (oms::Flags::ResultFile() != "<default>")
@@ -1114,7 +1110,7 @@ oms_status_enu_t oms_RunFile(const char* filename_)
11141110
else if (type == ".ssp")
11151111
{
11161112
char* cref;
1117-
oms_importFile(filename.c_str(), &cref);
1113+
oms_importFile(filename, &cref);
11181114

11191115
if (oms::Flags::ResultFile() != "<default>")
11201116
oms_setResultFile(cref, oms::Flags::ResultFile().c_str(), 1);
@@ -1133,7 +1129,7 @@ oms_status_enu_t oms_RunFile(const char* filename_)
11331129
lua_State *L = luaL_newstate();
11341130
luaL_openlibs(L);
11351131
luaopen_OMSimulatorLua(L);
1136-
if (luaL_loadfile(L, filename.c_str()))
1132+
if (luaL_loadfile(L, filename))
11371133
return logError(lua_tostring(L, -1));
11381134

11391135
if (lua_pcall(L, 0, 0, 0))
@@ -1145,7 +1141,7 @@ oms_status_enu_t oms_RunFile(const char* filename_)
11451141
#endif
11461142
}
11471143
else
1148-
return logError("Not able to process file '" + filename + "'\nUse OMSimulator --help for more information.");
1144+
return logError("Not able to process file '" + std::string(filename) + "'\nUse OMSimulator --help for more information.");
11491145

11501146
return oms_status_ok;
11511147
}

0 commit comments

Comments
 (0)