Skip to content

Commit

Permalink
- Fix not caching modified result-files
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16316 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jun 12, 2013
1 parent bcaed16 commit e312435
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
24 changes: 23 additions & 1 deletion Compiler/runtime/SimulationResults.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "read_csv.h"
#include <math.h>
#include "omc_msvc.h" /* For INFINITY and NAN */
#if !defined(__MINGW32__) && !defined(_MSC_VER)
#include <time.h>
#include <sys/stat.h>
#endif

#if defined(_MSC_VER)
#define fmax(x, y) ((x>y)?x:y)
Expand All @@ -25,6 +29,9 @@ const char *PlotFormatStr[] = {"Unknown","MATLAB4","PLT","CSV"};
typedef struct {
PlotFormat curFormat;
char *curFileName;
#if !defined(__MINGW32__) && !defined(_MSC_VER)
time_t mtime;
#endif
ModelicaMatReader matReader;
FILE *pltReader;
FILE *csvReader;
Expand All @@ -48,7 +55,19 @@ static PlotFormat SimulationResultsImpl__openFile(const char *filename, Simulati
PlotFormat format;
int len = strlen(filename);
const char *msg[] = {"",""};
if (simresglob->curFileName && 0==strcmp(filename,simresglob->curFileName)) return simresglob->curFormat; // Super cache :)
#if !defined(__MINGW32__) && !defined(_MSC_VER)
struct stat buf;
#endif
if (simresglob->curFileName && 0==strcmp(filename,simresglob->curFileName)) {
#if defined(__MINGW32__) || defined(_MSC_VER)
return simresglob->curFormat; // Super cache :)
#else
/* Also check that the file was not modified */
if (stat(filename, &buf)==0 && difftime(buf.st_mtime,simresglob->mtime)==0.0) {
return simresglob->curFormat; // Super cache :)
}
#endif
}
// Start by closing the old file...
SimulationResultsImpl__close(simresglob);

Expand Down Expand Up @@ -93,6 +112,9 @@ static PlotFormat SimulationResultsImpl__openFile(const char *filename, Simulati

simresglob->curFormat = format;
simresglob->curFileName = strdup(filename);
#if !defined(__MINGW32__) && !defined(_MSC_VER)
simresglob->mtime = buf.st_mtime;
#endif
// fprintf(stderr, "SimulationResultsImpl__openFile(%s) => %s\n", filename, PlotFormatStr[curFormat]);
return simresglob->curFormat;
}
Expand Down
4 changes: 2 additions & 2 deletions Compiler/runtime/SimulationResultsCmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ typedef struct {
#define DOUBLEEQUAL_TOTAL 0.0000000001
#define DOUBLEEQUAL_REL 0.00001

static SimulationResult_Globals simresglob_c = {UNKNOWN_PLOT,NULL,{NULL,NULL,0,NULL,0,NULL,0,0,0,NULL},NULL,NULL};
static SimulationResult_Globals simresglob_ref = {UNKNOWN_PLOT,NULL,{NULL,NULL,0,NULL,0,NULL,0,0,0,NULL},NULL,NULL};
static SimulationResult_Globals simresglob_c = {UNKNOWN_PLOT,0};
static SimulationResult_Globals simresglob_ref = {UNKNOWN_PLOT,0};

/* from an array of string creates flatten 'char*'-array suitable to be */
/* stored as MAT-file matrix */
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/SimulationResults_omc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {
#include "SimulationResults.c"
#include "SimulationResultsCmp.c"

static SimulationResult_Globals simresglob = {UNKNOWN_PLOT,NULL,{NULL,NULL,0,NULL,0,NULL,0,0,0,NULL},NULL,NULL};
static SimulationResult_Globals simresglob = {UNKNOWN_PLOT,0};

void* SimulationResults_readVariables(const char *filename, const char *visvars)
{
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/SimulationResults_rml.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "SimulationResults.c"
#include "SimulationResultsCmp.c"

static SimulationResult_Globals simresglob = {UNKNOWN_PLOT,NULL,{NULL,NULL,0,NULL,0,NULL,0,0,0,NULL},NULL,NULL};
static SimulationResult_Globals simresglob = {UNKNOWN_PLOT,0};

void SimulationResults_5finit(void)
{
Expand Down

0 comments on commit e312435

Please sign in to comment.