Skip to content

Commit

Permalink
Turns out that we can't use a const version of logCategories because …
Browse files Browse the repository at this point in the history
…parseArgs() updates it. Also fixed platform dependency issue concerning shared library extension.
  • Loading branch information
cxbrooks committed Sep 30, 2014
1 parent 228deed commit 4487ec3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ distclean: clean
rm -f fmu20/bin/fmusim_cs* fmu20/bin/fmusim_me*
rm -rf fmu10/fmu
rm -rf fmu20/fmu
rm -rf fmuTmp*
rm -f *.csv
find . -name "*~" -exec rm {} \;
find . -name "#*~" -exec rm {} \;

Expand Down
4 changes: 4 additions & 0 deletions fmu10/src/shared/sim_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ void loadFMU(const char* fmuFileName) {
void deleteUnzippedFiles() {
const char *fmuTempPath = getTmpPath();
char *cmd = (char *)calloc(15 + strlen(fmuTempPath), sizeof(char));
#if WINDOWS
sprintf(cmd, "rmdir /S /Q %s", fmuTempPath);
#else
sprintf(cmd, "rm -rf %s", fmuTempPath);
#endif
system(cmd);
free(cmd);
}
Expand Down
2 changes: 1 addition & 1 deletion fmu20/src/co_simulation/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int main(int argc, char *argv[]) {
dlclose(fmu.dllHandle);
#endif
freeModelDescription(fmu.modelDescription);
if (categories) free(categories);
//if (categories) free(categories);

// delete temp files obtained by unzipping the FMU
deleteUnzippedFiles();
Expand Down
1 change: 1 addition & 0 deletions fmu20/src/model_exchange/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <stdlib.h>
#include <stdio.h>
#include <string.h> //strerror()
#include "fmi2.h"
#include "sim_support.h"

Expand Down
18 changes: 13 additions & 5 deletions fmu20/src/shared/sim_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,14 @@ void loadFMU(const char* fmuFileName) {
#endif
// load the FMU dll
dllPath = calloc(sizeof(char), strlen(tmpPath) + strlen(DLL_DIR)
+ strlen(modelId) + strlen(".dll") + 1);
sprintf(dllPath, "%s%s%s.dll", tmpPath, DLL_DIR, modelId);
+ strlen(modelId) + strlen(DLL_SUFFIX) + 1);
sprintf(dllPath,"%s%s%s%s", tmpPath, DLL_DIR, modelId, DLL_SUFFIX);
if (!loadDll(dllPath, &fmu)) {
exit(EXIT_FAILURE);
// try the alternative directory and suffix
dllPath = calloc(sizeof(char), strlen(tmpPath) + strlen(DLL_DIR2)
+ strlen(modelId) + strlen(DLL_SUFFIX2) + 1);
sprintf(dllPath,"%s%s%s%s", tmpPath, DLL_DIR2, modelId, DLL_SUFFIX2);
if (!loadDll(dllPath, &fmu)) exit(EXIT_FAILURE);
}
free(dllPath);
free(fmuPath);
Expand All @@ -400,7 +404,11 @@ void loadFMU(const char* fmuFileName) {
void deleteUnzippedFiles() {
const char *fmuTempPath = getTmpPath();
char *cmd = (char *)calloc(15 + strlen(fmuTempPath), sizeof(char));
#if WINDOWS
sprintf(cmd, "rmdir /S /Q %s", fmuTempPath);
#else
sprintf(cmd, "rm -rf %s", fmuTempPath);
#endif
system(cmd);
free(cmd);
}
Expand Down Expand Up @@ -612,7 +620,7 @@ int error(const char* message){
}

void parseArguments(int argc, char *argv[], const char **fmuFileName, double *tEnd, double *h,
int *loggingOn, char *csv_separator, int *nCategories, const fmi2String *logCategories[]) {
int *loggingOn, char *csv_separator, int *nCategories, /*const*/ fmi2String *logCategories[]) {
// parse command line arguments
if (argc > 1) {
*fmuFileName = argv[1];
Expand Down Expand Up @@ -653,7 +661,7 @@ void parseArguments(int argc, char *argv[], const char **fmuFileName, double *tE
if (argc > 6) {
int i;
*nCategories = argc - 6;
*logCategories = (char **)calloc(sizeof(char *), *nCategories);
*logCategories = (/*const*/ fmi2String *)calloc(sizeof(char *), *nCategories);
for (i = 0; i < *nCategories; i++) {
(*logCategories)[i] = argv[i + 6];
}
Expand Down
36 changes: 35 additions & 1 deletion fmu20/src/shared/sim_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,45 @@
#define XML_FILE "modelDescription.xml"
#define RESULT_FILE "result.csv"
#define BUFSIZE 4096
#if WINDOWS
#ifdef _WIN64
#define DLL_DIR "binaries\\win64\\"
#define DLL_DIR2 "binaries\\win64\\"
#else
#define DLL_DIR "binaries\\win32\\"
#define DLL_DIR2 "binaries\\win32\\"
#endif

#define DLL_SUFFIX ".dll"
#define DLL_SUFFIX2 ".dll"

#else
#if __APPLE__

// Use these for platforms other than OpenModelica
#define DLL_DIR "binaries/darwin64/"
#define DLL_SUFFIX ".dylib"

// Use these for OpenModelica 1.8.1
#define DLL_DIR2 "binaries/darwin-x86_64/"
#define DLL_SUFFIX2 ".so"


#else /*__APPLE__*/
// Linux
#ifdef __x86_64
#define DLL_DIR "binaries/linux64/"
#define DLL_DIR2 "binaries/linux32/"
#else
// It may be necessary to compile with -m32, see ../Makefile
#define DLL_DIR "binaries/linux32/"
#define DLL_DIR2 "binaries/linux64/"
#endif /*__x86_64*/
#define DLL_SUFFIX ".so"
#define DLL_SUFFIX2 ".so"
#endif /*__APPLE__*/
#endif /*WINDOWS*/

#define RESOURCES_DIR "resources\\"

// return codes of the 7z command line tool
Expand All @@ -30,7 +64,7 @@
void fmuLogger(fmi2Component c, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message, ...);
int unzip(const char *zipPath, const char *outPath);
void parseArguments(int argc, char *argv[], const char **fmuFileName, double *tEnd, double *h,
int *loggingOn, char *csv_separator, int *nCategories, const fmi2String *logCategories[]);
int *loggingOn, char *csv_separator, int *nCategories, /*const*/ fmi2String *logCategories[]);
void loadFMU(const char *fmuFileName);
void deleteUnzippedFiles();
void outputRow(FMU *fmu, fmi2Component c, double time, FILE* file, char separator, fmi2Boolean header);
Expand Down

0 comments on commit 4487ec3

Please sign in to comment.