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

Commit dc05202

Browse files
adrpoOpenModelica-Hudson
authored andcommitted
fix linearization file generation in Windows (ticket:5223)
Belonging to [master]: - #2794
1 parent 19f18d6 commit dc05202

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

SimulationRuntime/c/linearization/linearize.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ int functionJacC(DATA* data, threadData_t *threadData, double* jac){
376376
data->simulationInfo->analyticJacobians[index].seedVars[i] = 1.0;
377377
if(ACTIVE_STREAM(LOG_JAC))
378378
{
379-
printf("Caluculate one col:\n");
379+
printf("Calculate one col:\n");
380380
for(j=0; j < data->simulationInfo->analyticJacobians[index].sizeCols;j++)
381381
infoStreamPrint(LOG_JAC,0,"seed: data->simulationInfo->analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo->analyticJacobians[index].seedVars[j]);
382382
}
@@ -414,7 +414,7 @@ int functionJacD(DATA* data, threadData_t *threadData, double* jac){
414414
data->simulationInfo->analyticJacobians[index].seedVars[i] = 1.0;
415415
if(ACTIVE_STREAM(LOG_JAC))
416416
{
417-
printf("Caluculate one col:\n");
417+
printf("Calculate one col:\n");
418418
for(j=0; j < data->simulationInfo->analyticJacobians[index].sizeCols;j++) {
419419
infoStreamPrint(LOG_JAC,0,"seed: data->simulationInfo->analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo->analyticJacobians[index].seedVars[j]);
420420
}
@@ -464,6 +464,7 @@ int linearize(DATA* data, threadData_t *threadData)
464464
double* matrixCz = 0;
465465
double* matrixDz = 0;
466466
string strA, strB, strC, strD, strCz, strDz, strX, strU, strZ0, filename;
467+
std::size_t pos, pos1, pos2;
467468

468469
assertStreamPrint(threadData,0!=matrixA,"calloc failed");
469470
assertStreamPrint(threadData,0!=matrixB,"calloc failed");
@@ -560,12 +561,31 @@ int linearize(DATA* data, threadData_t *threadData)
560561

561562
/* Use the result file name rather than the model name so that the linear file name can be changed with the -r flag, however strip _res.mat from the filename */
562563
filename = string(data->modelData->resultFileName) + ".mo";
563-
filename = filename.substr(0, filename.rfind("_res.mat")) + ".mo";
564+
pos = filename.rfind("_res.mat");
565+
if (pos != std::string::npos)
566+
{
567+
// not found, use the modelFilePrefix
568+
filename = string(data->modelData->modelFilePrefix) + ".mo";
569+
}
570+
else
571+
{
572+
filename = filename.substr(0, pos) + ".mo";
573+
}
564574
#if defined(__MINGW32__) || defined(_MSC_VER)
565-
if(filename.rfind('\\') >= filename.length()) {
575+
pos1 = filename.rfind('\\');
576+
pos2 = filename.rfind('/');
577+
if (pos1 < pos2)
578+
{
579+
pos = pos2;
580+
}
581+
else
582+
{
583+
pos = pos1;
584+
}
585+
if(pos >= filename.length()) {
566586
filename = "linear_" + filename;
567587
}else{
568-
filename.replace(filename.rfind('\\'), 1, "\\linear_");
588+
filename.replace(pos, 1, "/linear_");
569589
}
570590
#else
571591
if(filename.rfind('/') >= filename.length()) {

0 commit comments

Comments
 (0)