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

Commit c842427

Browse files
rfrankeOpenModelica-Hudson
authored andcommitted
[Cpp] Don't use outputPath for results file, ticket:4773
The results file has its own call argument -F (or -r for the C runtime) that is typically used with an absolute file name, including path. A results file with relative name should be placed in the current directory according to discussions at dev meeting on 12/03, 2018. Moreover raise an error if open of the results file fails. Belonging to [master]: - #2813
1 parent aa64ed4 commit c842427

File tree

5 files changed

+17
-29
lines changed

5 files changed

+17
-29
lines changed

SimulationRuntime/cpp/Include/Core/DataExchange/HistoryImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class HistoryImpl : public IHistory,
2020
{
2121
public:
2222
HistoryImpl(IGlobalSettings& globalSettings,size_t dim)
23-
: ResultsPolicy((globalSettings.getEndTime()-globalSettings.getStartTime())/globalSettings.gethOutput(),globalSettings.getOutputPath(),globalSettings.getResultsFileName())
23+
: ResultsPolicy((globalSettings.getEndTime()-globalSettings.getStartTime())/globalSettings.gethOutput(), globalSettings.getResultsFileName())
2424
, _globalSettings(globalSettings)
2525
, _dim(dim)
2626
{
@@ -40,7 +40,7 @@ class HistoryImpl : public IHistory,
4040

4141
virtual void init()
4242
{
43-
ResultsPolicy::init(_globalSettings.getOutputPath(), _globalSettings.getResultsFileName(),_dim);
43+
ResultsPolicy::init(_globalSettings.getResultsFileName(), _dim);
4444
}
4545

4646
virtual void getOutputNames(vector<string>& output_names)

SimulationRuntime/cpp/Include/Core/DataExchange/Policies/BufferReaderWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class BufferReaderWriter : public ContainerManager
2121
{
2222
//typedef TextFileWriter<dim_1,dim_2> TextwriterType;
2323
public:
24-
BufferReaderWriter(unsigned long size, string output_path, string file_name)
24+
BufferReaderWriter(unsigned long size, string file_name)
2525
: ContainerManager(),
2626
_buffer_pos(0)
2727
{
@@ -45,7 +45,7 @@ class BufferReaderWriter : public ContainerManager
4545
}
4646
}
4747

48-
void init(/*string output_path,string file_name*/std::string output_path, std::string file_name, size_t dim)
48+
void init(std::string file_name, size_t dim)
4949
{
5050
}
5151
/**

SimulationRuntime/cpp/Include/Core/DataExchange/Policies/DefaultWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class DefaultWriter : public ContainerManager
1515
{
1616
public:
17-
DefaultWriter(unsigned long size, string output_path, string file_name)
17+
DefaultWriter(unsigned long size, string file_name)
1818
: ContainerManager()
1919

2020
{
@@ -25,7 +25,7 @@ class DefaultWriter : public ContainerManager
2525

2626
}
2727

28-
void init(std::string output_path, std::string file_name,size_t dim)
28+
void init(std::string file_name, size_t dim)
2929
{
3030

3131
}

SimulationRuntime/cpp/Include/Core/DataExchange/Policies/MatfileWriter.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ using std::ios;
2727
class MatFileWriter : public ContainerManager
2828
{
2929
public:
30-
MatFileWriter(unsigned long size, string output_path, string file_name)
30+
MatFileWriter(unsigned long size, string file_name)
3131
: ContainerManager(),
3232
_dataHdrPos(),
3333
_dataEofPos(),
3434
_curser_position(0),
3535
_uiValueCount(0),
36-
_output_path(output_path),
3736
_file_name(file_name),
3837
_doubleMatrixData1(NULL),
3938
_doubleMatrixData2(NULL),
@@ -221,39 +220,32 @@ class MatFileWriter : public ContainerManager
221220

222221
/*=={function}===================================================================================*/
223222
/*!
224-
* void init(std::string output_path,std::string file_name)
223+
* void init(std::string file_name)
225224
*
226225
* brief:
227226
* ------
228227
* function initialize a matlab file
229228
*
230-
* \param[in] output_path
231-
* \n usage: path name
232-
* \n range: not relevant
233-
*
234229
* \param[in] file_name
235230
* \n usage: file name
236231
* \n range: not relevant
237232
*
238233
* \return
239234
*/
240235
/*========================================================================================{end}==*/
241-
void init(std::string output_path, std::string file_name,size_t dim)
236+
void init(std::string file_name, size_t dim)
242237
{
243238
const char Aclass[] = "A1 bt. ir1 na Tj re ac nt so r y "; // special header string
244239

245240
_file_name = file_name;
246-
_output_path = output_path;
247241

248242
if (_output_stream.is_open())
249243
_output_stream.close();
250244

251-
// building complete file path
252-
std::stringstream res_output_path;
253-
res_output_path << output_path << file_name;
254-
255245
// open new file
256-
_output_stream.open(res_output_path.str().c_str(), ios::binary | ios::trunc);
246+
_output_stream.open(file_name.c_str(), ios::binary | ios::trunc);
247+
if (_output_stream.fail())
248+
throw ModelicaSimulationError(DATASTORAGE, string("Failed to open results file ") + file_name);
257249

258250
// write header matrix
259251
writeMatVer4Matrix("Aclass", 4, 11, Aclass, sizeof(char));
@@ -815,7 +807,6 @@ class MatFileWriter : public ContainerManager
815807
std::ofstream::pos_type _dataEofPos;
816808
unsigned int _curser_position;
817809
unsigned int _uiValueCount;
818-
std::string _output_path;
819810
std::string _file_name;
820811
double *_doubleMatrixData1;
821812
double *_doubleMatrixData2;

SimulationRuntime/cpp/Include/Core/DataExchange/Policies/TextfileWriter.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ const char EXTENSION = ',';
1616
class TextFileWriter : public ContainerManager
1717
{
1818
public:
19-
TextFileWriter(unsigned long size, string output_path, string file_name)
19+
TextFileWriter(unsigned long size, string file_name)
2020
: ContainerManager(),
2121
_output_stream(),
2222
_curser_position(0),
23-
_output_path(output_path),
2423
_file_name(file_name)
2524
{
2625
}
@@ -31,16 +30,15 @@ class TextFileWriter : public ContainerManager
3130
_output_stream.close();
3231
}
3332

34-
void init(std::string output_path, std::string file_name,size_t dim)
33+
void init(std::string file_name, size_t dim)
3534
{
3635
_file_name = file_name;
37-
_output_path = output_path;
3836
if (_output_stream.is_open())
3937
_output_stream.close();
40-
std::stringstream res_output_path;
41-
res_output_path << output_path << file_name;
42-
_output_stream.open(res_output_path.str().c_str(), ios::out);
4338

39+
_output_stream.open(file_name.c_str(), ios::out);
40+
if (_output_stream.fail())
41+
throw ModelicaSimulationError(DATASTORAGE, string("Failed to open results file ") + file_name);
4442
}
4543
void read(ublas::matrix<double>& R, ublas::matrix<double>& dR)
4644
{
@@ -150,7 +148,6 @@ class TextFileWriter : public ContainerManager
150148

151149
std::fstream _output_stream;
152150
unsigned int _curser_position; ///< Controls current Curser-Position
153-
std::string _output_path;
154151
std::string _file_name;
155152
vector<string> _var_outputs;
156153
};

0 commit comments

Comments
 (0)