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

Commit 74e8456

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
filterSimulationResults option to remove descriptions
The string comments on variables take up a lot of space in the result- file. This option allows filtering them all away. Belonging to [master]: - #2428
1 parent a3a1750 commit 74e8456

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,11 +2869,18 @@ public function filterSimulationResults
28692869
input String outFile;
28702870
input String[:] vars;
28712871
input Integer numberOfIntervals = 0 "0=Do not resample";
2872+
input Boolean removeDescription = false;
28722873
output Boolean success;
28732874
external "builtin";
28742875
annotation(Documentation(info="<html>
28752876
<p>Takes one simulation result and filters out the selected variables only, producing the output file.</p>
28762877
<p>If numberOfIntervals<>0, re-sample to that number of intervals, ignoring event points (might be changed in the future).</p>
2878+
<p>if removeDescription=true, the description matrix will contain 0-length strings, making the file smaller.</p>
2879+
</html>",revisions="<html>
2880+
<table>
2881+
<tr><th>Revision</th><th>Author</th><th>Comment</th></tr>
2882+
<tr><td>1.13.0</td><td>sjoelund.se</td><td>Introduced removeDescription.</td></tr>
2883+
</table>
28772884
</html>"),preferredView="text");
28782885
end filterSimulationResults;
28792886

Compiler/Script/CevalScriptBackend.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,10 +2272,10 @@ algorithm
22722272
case (cache,_,"compareSimulationResults",_,_)
22732273
then (cache,Values.STRING("Error in compareSimulationResults"));
22742274

2275-
case (cache,_,"filterSimulationResults",{Values.STRING(filename),Values.STRING(filename_1),Values.ARRAY(valueLst=cvars),Values.INTEGER(numberOfIntervals)},_)
2275+
case (cache,_,"filterSimulationResults",{Values.STRING(filename),Values.STRING(filename_1),Values.ARRAY(valueLst=cvars),Values.INTEGER(numberOfIntervals),Values.BOOL(b)},_)
22762276
equation
22772277
vars_1 = List.map(cvars, ValuesUtil.extractValueString);
2278-
b = SimulationResults.filterSimulationResults(filename,filename_1,vars_1,numberOfIntervals);
2278+
b = SimulationResults.filterSimulationResults(filename,filename_1,vars_1,numberOfIntervals,b);
22792279
then
22802280
(cache,Values.BOOL(b));
22812281

Compiler/Util/SimulationResults.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ public function filterSimulationResults
149149
input String outFile;
150150
input list<String> vars;
151151
input Integer numberOfIntervals=0;
152+
input Boolean removeDescription;
152153
output Boolean result;
153-
external "C" result=SimulationResults_filterSimulationResults(inFile,outFile,vars,numberOfIntervals) annotation(Library = "omcruntime");
154+
external "C" result=SimulationResults_filterSimulationResults(inFile,outFile,vars,numberOfIntervals,removeDescription) annotation(Library = "omcruntime");
154155
end filterSimulationResults;
155156

156157
annotation(__OpenModelica_Interface="frontend");

Compiler/runtime/SimulationResults.c

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,18 @@ static void* SimulationResultsImpl__readDataset(const char *filename, void *vars
392392
}
393393
}
394394

395-
static inline int failedToWriteToFile(const char *file)
395+
static inline int failedToWriteToFileImpl(const char *file, const char *sourceFile, const char *line)
396396
{
397-
c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_error, gettext("Failed to write to file %s."), &file, 1);
397+
const char *msg[3] = {file,line,sourceFile};
398+
c_add_message(NULL,-1, ErrorType_scripting, ErrorLevel_error, gettext("%s:%s: Failed to write to file %s."), msg, 3);
398399
return 0;
399400
}
400401

402+
#define STR_HELPER(x) #x
403+
#define STR(x) STR_HELPER(x)
404+
#define failedToWriteToFile(file) failedToWriteToFileImpl(file, __FILE__, STR(__LINE__))
405+
406+
401407
static inline int intMax(int a, int b)
402408
{
403409
return a>b ? a : b;
@@ -412,7 +418,7 @@ static int endsWith(const char *s, const char *suffix)
412418
return 0;
413419
}
414420
}
415-
int SimulationResults_filterSimulationResults(const char *inFile, const char *outFile, void *vars, int numberOfIntervals)
421+
int SimulationResults_filterSimulationResults(const char *inFile, const char *outFile, void *vars, int numberOfIntervals, int removeDescription)
416422
{
417423
const char *msg[5] = {"","","","",""};
418424
void *tmp;
@@ -545,21 +551,27 @@ int SimulationResults_filterSimulationResults(const char *inFile, const char *ou
545551
}
546552
GC_free(tmp);
547553

548-
if (writeMatVer4MatrixHeader(fout, "description", numToFilter, longestDesc, sizeof(int8_t))) {
549-
return failedToWriteToFile(outFile);
550-
}
554+
if (removeDescription) {
555+
if (writeMatVer4MatrixHeader(fout, "description", numToFilter, 0, sizeof(int8_t))) {
556+
return failedToWriteToFile(outFile);
557+
}
558+
} else {
559+
if (writeMatVer4MatrixHeader(fout, "description", numToFilter, longestDesc, sizeof(int8_t))) {
560+
return failedToWriteToFile(outFile);
561+
}
551562

552-
tmp = omc_alloc_interface.malloc(numToFilter*longestDesc);
553-
for (i=0; i<numToFilter; i++) {
554-
int len = strlen(mat_var[i]->descr);
555-
for (j=0; j<len; j++) {
556-
tmp[numToFilter*j+i] = mat_var[i]->descr[j];
563+
tmp = omc_alloc_interface.malloc(numToFilter*longestDesc);
564+
for (i=0; i<numToFilter; i++) {
565+
int len = strlen(mat_var[i]->descr);
566+
for (j=0; j<len; j++) {
567+
tmp[numToFilter*j+i] = mat_var[i]->descr[j];
568+
}
557569
}
570+
if (1 != fwrite(tmp, numToFilter*longestDesc, 1, fout)) {
571+
return failedToWriteToFile(outFile);
572+
}
573+
GC_free(tmp);
558574
}
559-
if (1 != fwrite(tmp, numToFilter*longestDesc, 1, fout)) {
560-
return failedToWriteToFile(outFile);
561-
}
562-
GC_free(tmp);
563575

564576
if (writeMatVer4MatrixHeader(fout, "dataInfo", numToFilter, 4, sizeof(int32_t))) {
565577
return failedToWriteToFile(outFile);
@@ -660,8 +672,11 @@ int SimulationResults_filterSimulationResults(const char *inFile, const char *ou
660672
vals = omc_matlab4_read_vals(&simresglob.matReader, indexesToOutput[i]);
661673
nrows = simresglob.matReader.nrows;
662674
}
663-
if (1!=fwrite(vals, sizeof(double)*nrows, 1, fout)) {
664-
return failedToWriteToFile(outFile);
675+
if (nrows > 0) {
676+
if (1!=fwrite(vals, sizeof(double)*nrows, 1, fout)) {
677+
fprintf(stderr, "nrows=%d\n", nrows);
678+
return failedToWriteToFile(outFile);
679+
}
665680
}
666681
if (numberOfIntervals) {
667682
GC_free(vals);

0 commit comments

Comments
 (0)