/* Fetch sha's for the libraries at locations 'libPaths' and print them to the file 'fileName'. */ void tagCommit(const char *fileName, const char **libNames, const char **libPaths, int nLib, int verbose){ /* Buffers */ char sha[44]; char buffer[250]; /* Write header */ FILE *fOut = fopen(fileName, "w"); sprintf(buffer, "Library: sha\n---------------------------\n"); if (fputs(buffer, fOut)==EOF){ ModelicaFormatError("In tagcommit.c: failed to write to file %s.", fileName); } /* Fetch library sha's and print to file */ int i; for (i = 0; i < nLib; ++i) { getCommit(libPaths[i], sha); sprintf(buffer, "%s: %s\n", libNames[i],sha); if (verbose) ModelicaFormatMessage("Library %s has sha %s. Writing to file path %s\n", libNames[i], sha, fileName); if (fputs(buffer, fOut)==EOF){ ModelicaFormatError("In tagcommit.c: failed to write to file %s.", fileName); } } fclose(fOut); }
/* Fetch the sha of a library in the folder 'path' and return it in 'res'. */ void getCommit(const char *path, char* res){ /* Buffers */ char buffer[250]; char sha[42]; /* Command to fetch sha */ sprintf(buffer, "cd %s && git rev-parse HEAD", path); /* Read command result */ FILE *fp; #ifdef __linux__ fp = popen(buffer, "r"); #elif _WIN32 fp = _popen(buffer, "r"); #else ModelicaFormatError("Unsupported operating system\n"); #endif if (fp == NULL) { ModelicaFormatError("Failed to call git command\n"); } if (fgets(sha, sizeof(sha)-1, fp) == NULL){ ModelicaFormatError("Path %s does not exist or git cannot be called\n", path); } #ifdef __linux__ pclose(fp); #else _pclose(fp); #endif /* Return result */ strcpy(res,sha); }
void ED_getDoubleArray1DFromXML(void* _xml, const char* varName, double* a, size_t n) { XMLFile* xml = (XMLFile*)_xml; if (xml != NULL) { XmlNodeRef root = xml->root; char* token = findValue(&root, varName, xml->fileName); if (token != NULL) { char* buf = _strdup(token); if (buf != NULL) { size_t i; strcpy(buf, token); token = strtok(buf, "[]{},; \t"); for (i = 0; i < n; i++) { if (ED_strtod(token, xml->loc, &a[i])) { ModelicaFormatError("Error in line %i when reading double value \"%s\" from file \"%s\"\n", XmlNode_getLine(root), token, xml->fileName); } token = strtok(NULL, "[]{},; \t"); } free(buf); } } else { ModelicaFormatError("Error in line %i when reading double value from file \"%s\"\n", XmlNode_getLine(root), xml->fileName); } } }
static const char* ModelicaInternal_fullPathName(const char* name) { /* Get full path name of file or directory */ char* fullName; #if defined(_WIN32) char* tempName = _fullpath(buffer, name, sizeof(buffer)); if (tempName == NULL) { ModelicaFormatError("Not possible to construct full path name of \"%s\"\n%s", name, strerror(errno)); return ""; } fullName = ModelicaAllocateString(strlen(tempName)); strcpy(fullName, tempName); ModelicaConvertToUnixDirectorySeparator(fullName); #else /* No such system call in _POSIX_ available */ char* cwd = getcwd(buffer, sizeof(buffer)); if (cwd == NULL) { ModelicaFormatError("Not possible to get current working directory:\n%s", strerror(errno)); } fullName = ModelicaAllocateString(strlen(cwd) + strlen(name) + 1); strcpy(fullName, cwd); strcat(fullName, "/"); strcat(fullName, name); #endif return fullName; }
MODELICA_EXPORT const char* ModelicaStrings_substring(const char* string, int startIndex, int endIndex) { /* Return string1(startIndex:endIndex) if endIndex >= startIndex, or return string1(startIndex:startIndex), if endIndex = 0. An assert is triggered, if startIndex/endIndex are not valid. */ char* substring; int len1 = (int) strlen(string); int len2; /* Check arguments */ if ( startIndex < 1 ) { ModelicaFormatError("Wrong call of Utilities.Strings.substring:\n" " startIndex = %d (has to be > 0).\n" " string = \"%s\"\n", startIndex, string); } else if ( endIndex == -999 ) { endIndex = startIndex; } else if ( endIndex < startIndex ) { ModelicaFormatError("Wrong call of Utilities.Strings.substring:\n" " startIndex = %d\n" " endIndex = %d (>= startIndex required)\n" " string = \"%s\"\n", startIndex, endIndex, string); } else if ( endIndex > len1 ) { ModelicaFormatError("Wrong call of Utilities.Strings.substring:\n" " endIndex = %d (<= %d required (=length(string)).\n" " string = \"%s\"\n", endIndex, len1, string); }; /* Allocate memory and copy string */ len2 = endIndex - startIndex + 1; substring = ModelicaAllocateString(len2); strncpy(substring, &string[startIndex-1], len2); substring[len2] = '\0'; return substring; }
static void ModelicaInternal_readFile(const char* fileName, const char* string[], size_t nLines) { /* Read file into string vector string[nLines] */ FILE* fp = ModelicaStreams_openFileForReading(fileName); char* line; int c; size_t lineLen; size_t iLines; long offset; size_t nc; /* Read data from file */ iLines = 1; while ( iLines <= nLines ) { /* Determine length of next line */ offset = ftell(fp); lineLen = 0; c = fgetc(fp); while ( c != '\n' && c != EOF ) { lineLen++; c = fgetc(fp); } /* Allocate storage for next line */ line = ModelicaAllocateStringWithErrorReturn(lineLen); if ( line == NULL ) { fclose(fp); ModelicaFormatError("Not enough memory to allocate string for reading line %i from file\n" "\"%s\".\n" "(this file contains %i lines)\n", iLines, fileName, nLines); } /* Read next line */ if ( fseek(fp, offset, SEEK_SET != 0) ) { fclose(fp); ModelicaFormatError("Error when reading line %i from file\n\"%s\":\n" "%s\n", iLines, fileName, strerror(errno)); }; nc = ( iLines < nLines ? lineLen+1 : lineLen); if ( fread(line, sizeof(char), nc, fp) != nc ) { fclose(fp); ModelicaFormatError("Error when reading line %i from file\n\"%s\"\n", iLines, fileName); }; line[lineLen] = '\0'; string[iLines-1] = line; iLines++; } fclose(fp); }
MODELICA_EXPORT void ModelicaInternal_rename(const char* oldName, const char* newName) { /* Change the name of a file or of a directory */ if ( rename(oldName, newName) != 0 ) { ModelicaFormatError("renaming \"%s\" to \"%s\" failed:\n%s", oldName, newName, strerror(errno)); } }
char* ModelicaAllocateString(size_t len) { char *res = ModelicaAllocateStringWithErrorReturn(len); if (!res) { ModelicaFormatError("%s:%d: ModelicaAllocateString failed\n", __FILE__, __LINE__); } return res; }
static int ModelicaInternal_getNumberOfFiles(const char* directory) { /* Get number of files and directories in a directory */ #if defined(_WIN32) || defined(_POSIX_) int nFiles = 0; int errnoTemp; struct dirent *pinfo; DIR* pdir; pdir = opendir(directory); if ( pdir == NULL ) goto ERROR; errno = 0; while ( (pinfo = readdir(pdir)) != NULL ) { if ( (strcmp(pinfo->d_name, "." ) != 0) && (strcmp(pinfo->d_name, "..") != 0) ) { nFiles++; }; }; errnoTemp = errno; closedir(pdir); if ( errnoTemp != 0 ) {errno = errnoTemp; goto ERROR;} return nFiles; ERROR: ModelicaFormatError("Not possible to get number of files in \"%s\":\n%s", directory, strerror(errno)); return 0; #else ModelicaNotExistError("ModelicaInternal_getNumberOfFiles"); return 0; #endif };
static void ModelicaNotExistError(const char* name) { /* Print error message if a function is not implemented */ ModelicaFormatError("C-Function \"%s\" is called\n" "but is not implemented for the actual environment\n" "(e.g., because there is no file system available on the machine\n" "as for dSpace or xPC systems)", name); }
static void ModelicaInternal_removeFile(const char* file) { /* Remove file. */ if ( remove(file) != 0 ) { ModelicaFormatError("Not possible to remove file \"%s\":\n%s", file, strerror(errno)); } }
static const char* ModelicaInternal_getcwd(int dummy) { const char* cwd; char* directory; #if defined(_WIN32) cwd = _getcwd(buffer, sizeof(buffer)); #elif defined(_POSIX_) cwd = getcwd(buffer, sizeof(buffer)); #else ModelicaNotExistError("ModelicaInternal_getcwd"); cwd = ""; #endif if (cwd == NULL) { ModelicaFormatError("Not possible to get current working directory:\n%s", strerror(errno)); cwd = ""; } directory = ModelicaAllocateString(strlen(cwd)); strcpy(directory, cwd); ModelicaConvertToUnixDirectorySeparator(directory); return directory; }
/* * Wrapper for the FMI function fmi2GetContinuousStates. * parameter flowParams is dummy and is only used to run the equations in sequence. * Returns states. */ void fmi2GetContinuousStates_OMC(void* in_fmi2me, int numberOfContinuousStates, double flowParams, double* states) { FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; fmi2_status_t status = fmi2_import_get_continuous_states(FMI2ME->FMIImportInstance, (fmi2_real_t*)states, numberOfContinuousStates); if (status != fmi1_status_ok && status != fmi1_status_warning) { ModelicaFormatError("fmi2GetContinuousStates failed with status : %s\n", fmi2_status_to_string(status)); } }
/* * Wrapper for the FMI function fmi2GetEventIndicators. * parameter flowStates is dummy and is only used to run the equations in sequence. * Returns events. */ void fmi2GetEventIndicators_OMC(void* in_fmi2me, int numberOfEventIndicators, double flowStates, double* events) { FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; fmi2_status_t status = fmi2_import_get_event_indicators(FMI2ME->FMIImportInstance, (fmi2_real_t*)events, numberOfEventIndicators); if (status != fmi1_status_ok && status != fmi1_status_warning) { ModelicaFormatError("fmi2GetEventIndicators failed with status : %s\n", fmi2_status_to_string(status)); } }
/* * Wrapper for the FMI function fmi2ExitInitializationMode. */ void fmi2ExitInitializationModel_OMC(void* in_fmi2me) { FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; fmi2_status_t status = fmi2_import_exit_initialization_mode(FMI2ME->FMIImportInstance); FMI2ME->FMISolvingMode = fmi2_event_mode; if (status != fmi1_status_ok && status != fmi1_status_warning) { ModelicaFormatError("fmi2ExitInitializationMode failed with status : %s\n", fmi2_status_to_string(status)); } }
/* * Wrapper for the FMI function fmi2SetTime. * Returns status. */ void fmi2SetTime_OMC(void* in_fmi2me, double time) { FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; if (FMI2ME->FMISolvingMode == fmi2_instantiated_mode || FMI2ME->FMISolvingMode == fmi2_event_mode || FMI2ME->FMISolvingMode == fmi2_continuousTime_mode) { fmi2_status_t status = fmi2_import_set_time(FMI2ME->FMIImportInstance, time); if (status != fmi1_status_ok && status != fmi1_status_warning) { ModelicaFormatError("fmi2SetTime failed with status : %s\n", fmi2_status_to_string(status)); } } }
double interpolateVectorTable(void *object, double x) { VectorTable *table = (VectorTable *)object; size_t i = table->lastIndex; double p; ModelicaFormatMessage("Request to compute value of y at %g\n", x); if (x<table->x[0]) ModelicaFormatError("Requested value of x=%g is below the lower bound of %g\n", x, table->x[0]); if (x>table->x[table->npoints-1]) ModelicaFormatError("Requested value of x=%g is above the upper bound of %g\n", x, table->x[table->npoints-1]); while(x>=table->x[i+1]) i = i + 1; while(x<table->x[i]) i = i - 1; p = (x-table->x[i])/(table->x[i+1]-table->x[i]); table->lastIndex = i; return p*table->y[i+1]+(1-p)*table->y[i]; }
_Ret_z_ const char* ModelicaInternal_fullPathName(_In_z_ const char* name) { /* Get full path name of file or directory */ #if defined(_WIN32) || (_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || (_POSIX_VERSION >= 200112L)) char* fullName; char localbuf[BUFFER_LENGTH]; #if (_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || _POSIX_VERSION >= 200112L) /* realpath availability: 4.4BSD, POSIX.1-2001. Using the behaviour of NULL: POSIX.1-2008 */ char* tempName = realpath(name, localbuf); #else char* tempName = _fullpath(localbuf, name, sizeof(localbuf)); #endif if (tempName == NULL) { ModelicaFormatError("Not possible to construct full path name of \"%s\"\n%s", name, strerror(errno)); return ""; } fullName = ModelicaAllocateString(strlen(tempName)); strcpy(fullName, tempName); ModelicaConvertToUnixDirectorySeparator(fullName); #elif defined(_POSIX_) char* fullName; char localbuf[BUFFER_LENGTH]; /* No such system call in _POSIX_ available (except realpath above) */ char* cwd = getcwd(localbuf, sizeof(localbuf)); if (cwd == NULL) { ModelicaFormatError("Not possible to get current working directory:\n%s", strerror(errno)); } fullName = ModelicaAllocateString(strlen(cwd) + strlen(name) + 1); if (name[0] != '/') { /* Any name beginning with "/" is regarded as already being a full path. */ strcpy(fullName, cwd); strcat(fullName, "/"); } strcat(fullName, name); #else char* fullName = ""; ModelicaNotExistError("ModelicaInternal_fullPathName"); #endif return fullName; }
int ED_getIntFromXML(void* _xml, const char* varName) { int ret = 0; XMLFile* xml = (XMLFile*)_xml; if (xml != NULL) { XmlNodeRef root = xml->root; char* token = findValue(&root, varName, xml->fileName); if (token != NULL) { if (ED_strtoi(token, xml->loc, &ret)) { ModelicaFormatError("Error in line %i when reading int value \"%s\" from file \"%s\"\n", XmlNode_getLine(root), token, xml->fileName); } } else { ModelicaFormatError("Error in line %i when reading int value from file \"%s\"\n", XmlNode_getLine(root), xml->fileName); } } return ret; }
static FILE* ModelicaStreams_openFileForReading(const char* fileName) { /* Open text file for reading */ FILE* fp; /* Open file */ fp = fopen(fileName, "r"); if ( fp == NULL ) { ModelicaFormatError("Not possible to open file \"%s\" for reading:\n" "%s\n", fileName, strerror(errno)); } return fp; }
static const char* ModelicaInternal_readLine(const char* fileName, int lineNumber, int* endOfFile) { /* Read line lineNumber from file fileName */ FILE* fp = ModelicaStreams_openFileForReading(fileName); char* line; int c; size_t lineLen; size_t iLines; long offset; /* Read upto line lineNumber-1 */ iLines = 0; c = 1; while ( iLines != (size_t) lineNumber-1 && c != EOF ) { c = fgetc(fp); while ( c != '\n' && c != EOF ) { c = fgetc(fp); } iLines++; } if ( iLines != (size_t) lineNumber-1 ) goto END_OF_FILE; /* Determine length of line lineNumber */ offset = ftell(fp); lineLen = 0; c = fgetc(fp); while ( c != '\n' && c != EOF ) { lineLen++; c = fgetc(fp); } if ( lineLen == 0 && c == EOF ) goto END_OF_FILE; /* Read line lineNumber */ line = ModelicaAllocateStringWithErrorReturn(lineLen); if ( line == NULL ) goto ERROR; if ( fseek(fp, offset, SEEK_SET != 0) ) goto ERROR; if ( fread(line, sizeof(char), lineLen, fp) != lineLen ) goto ERROR; fclose(fp); line[lineLen] = '\0'; *endOfFile = 0; return line; /* End-of-File or error */ END_OF_FILE: fclose(fp); *endOfFile = 1; line = ModelicaAllocateString(0); return line; ERROR : fclose(fp); ModelicaFormatError("Error when reading line %i from file\n\"%s\":\n%s", lineNumber, fileName, strerror(errno)); return ""; }
void* allocateFileWriter( const char* instanceName, const char* fileName){ FileWriter* ID; FILE* fp; if ( FileWriterNames_n == 0 ){ /* Allocate memory for array of file names */ FileWriterNames = malloc(sizeof(char*)); InstanceNames = malloc(sizeof(char*)); if ( FileWriterNames == NULL || InstanceNames == NULL) ModelicaError("Not enough memory in fileWriterStructure.c for allocating FileWriterNames and InstanceNames."); } else{ /* Check if the file name is unique */ signed int index = fileWriterIsUnique(fileName); if (index>=0){ ModelicaFormatError("FileWriter %s writes to file %s which is already used by FileWriter %s.\nEach FileWriter must use a unique file name.", instanceName, fileName, InstanceNames[index]); } /* Reallocate memory for array of file names */ FileWriterNames = realloc(FileWriterNames, (FileWriterNames_n+1) * sizeof(char*)); InstanceNames = realloc(InstanceNames, (FileWriterNames_n+1) * sizeof(char*)); if ( FileWriterNames == NULL || InstanceNames == NULL ) ModelicaError("Not enough memory in fileWriterStructure.c for reallocating FileWriterNames and InstanceNames."); } /* Allocate memory for this file name */ FileWriterNames[FileWriterNames_n] = malloc((strlen(fileName)+1) * sizeof(char)); InstanceNames[FileWriterNames_n] = malloc((strlen(instanceName)+1) * sizeof(char)); if ( FileWriterNames[FileWriterNames_n] == NULL || InstanceNames[FileWriterNames_n] == NULL) ModelicaError("Not enough memory in fileWriterStructure.c for allocating FileWriterNames[] and InstanceNames[]."); /* Copy the file name */ strcpy(FileWriterNames[FileWriterNames_n], fileName); strcpy(InstanceNames[FileWriterNames_n], instanceName); FileWriterNames_n++; ID = (FileWriter*)malloc(sizeof(*ID)); if ( ID == NULL ) ModelicaFormatError("Not enough memory in fileWriterStructure.c for allocating ID of FileWriter %s.", instanceName); ID->fileWriterName = malloc((strlen(fileName)+1) * sizeof(char)); if ( ID->fileWriterName == NULL ) ModelicaFormatError("Not enough memory in fileWriterStructure.c for allocating ID->fileWriterName in FileWriter %s.", instanceName); strcpy(ID->fileWriterName, fileName); ID->instanceName = malloc((strlen(instanceName)+1) * sizeof(char)); if ( ID->instanceName == NULL ) ModelicaFormatError("Not enough memory in fileWriterStructure.c for allocating ID->instanceName in FileWriter %s.", instanceName); strcpy(ID->instanceName, instanceName); fp = fopen(fileName, "w"); if (fp == NULL) ModelicaFormatError("In fileWriterStructure.c: Failed to create empty file %s during initialisation.", fileName); if (fclose(fp)==EOF) ModelicaFormatError("In fileWriterStructure.c: Returned an error when closing %s.", fileName); return (void*)ID; }
/* * Wrapper for the FMI function fmi2CompletedIntegratorStep. */ int fmi2CompletedIntegratorStep_OMC(void* in_fmi2me, double flowStates) { FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; if (FMI2ME->FMISolvingMode == fmi2_continuousTime_mode){ fmi2_boolean_t callEventUpdate = fmi2_false; fmi2_boolean_t terminateSimulation = fmi2_false; fmi2_status_t status = fmi2_import_completed_integrator_step(FMI2ME->FMIImportInstance, fmi2_true, &callEventUpdate, &terminateSimulation); if (status != fmi1_status_ok && status != fmi1_status_warning) { ModelicaFormatError("fmi2CompletedIntegratorStep failed with status : %s\n", fmi2_status_to_string(status)); } return callEventUpdate; } return fmi2_false; }
/* * Wrapper for the FMI function fmi2GetReal. * parameter flowStatesInput is dummy and is only used to run the equations in sequence. * Returns realValues. */ void fmi2GetReal_OMC(void* in_fmi2, int numberOfValueReferences, double* realValuesReferences, double flowStatesInput, double* realValues, int fmiType) { if (fmiType == 1) { FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2; fmi2_value_reference_t* valuesReferences_int = real_to_fmi2_value_reference(numberOfValueReferences, realValuesReferences); fmi2_status_t status = fmi2_import_get_real(FMI2ME->FMIImportInstance, valuesReferences_int, numberOfValueReferences, (fmi2_real_t*)realValues); free(valuesReferences_int); if (status != fmi2_status_ok && status != fmi2_status_warning) { ModelicaFormatError("fmi2GetReal failed with status : %s\n", fmi2_status_to_string(status)); } } else if (fmiType == 2) { } }
static void ModelicaInternal_setenv(const char* name, const char* value, int convertFromSlash) { #if defined(_WIN32) || defined(_POSIX_) int valueStart; if (strlen(name) + strlen(value) + 1 > sizeof(buffer)) { ModelicaFormatError("Environment variable\n" "\"%s\"=\"%s\"\n" "cannot be set, because the internal buffer\n" "in file \"ModelicaInternal.c\" is too small (= %d)", name, value, sizeof(buffer)); } strcpy(buffer,name); strcat(buffer, "="); valueStart = strlen(buffer); strcat(buffer, value); if ( convertFromSlash == 1 ) ModelicaConvertFromUnixDirectorySeparator(&buffer[valueStart]); #endif /* Set environment variable */ #if defined(_WIN32) if (_putenv(buffer) != 0) { ModelicaFormatError("Environment variable\n" "\"%s\"=\"%s\"\n" "cannot be set: %s", name, value, strerror(errno)); } #elif defined(_POSIX_) if (putenv(buffer) != 0) { ModelicaFormatError("Environment variable\n" "\"%s\"=\"%s\"\n" "cannot be set: %s", name, value, strerror(errno)); } #else ModelicaNotExistError("ModelicaInternal_setenv"); #endif }
void ModelicaInternal_copyFile(_In_z_ const char* oldFile, _In_z_ const char* newFile) { /* Copy file */ #ifdef _WIN32 const char* modeOld = "rb"; const char* modeNew = "wb"; #else const char* modeOld = "r"; const char* modeNew = "w"; #endif FILE* fpOld; FILE* fpNew; ModelicaFileType type; int c; /* Check file existence */ type = Internal_stat(oldFile); if ( type == FileType_NoFile ) { ModelicaFormatError("\"%s\" cannot be copied\nbecause it does not exist", oldFile); return; } else if ( type == FileType_Directory ) { ModelicaFormatError("\"%s\" cannot be copied\nbecause it is a directory", oldFile); return; } else if ( type == FileType_SpecialFile ) { ModelicaFormatError("\"%s\" cannot be copied\n" "because it is not a regular file", oldFile); return; } type = Internal_stat(newFile); if ( type != FileType_NoFile ) { ModelicaFormatError("\"%s\" cannot be copied\nbecause the target " "\"%s\" exists", oldFile, newFile); return; } /* Copy file */ fpOld = fopen(oldFile, modeOld); if ( fpOld == NULL ) { ModelicaFormatError("\"%s\" cannot be copied:\n%s", oldFile, strerror(errno)); return; } fpNew = fopen(newFile, modeNew); if ( fpNew == NULL ) { fclose(fpOld); ModelicaFormatError("\"%s\" cannot be copied to \"%s\":\n%s", oldFile, newFile, strerror(errno)); return; } while ( (c = getc(fpOld)) != EOF ) { putc(c, fpNew); } fclose(fpOld); fclose(fpNew); }
/* * Wrapper for the FMI function fmi2NewDiscreteStates. * Returns valuesOfContinuousStatesChanged */ int fmi2EventUpdate_OMC(void* in_fmi2me) { FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; fmi2_event_info_t *eventInfo = FMI2ME->FMIEventInfo; fmi2_status_t status = fmi2_import_enter_event_mode(FMI2ME->FMIImportInstance); if (status != fmi1_status_ok && status != fmi1_status_warning) { ModelicaFormatError("fmi2EnterEventMode failed with status : %s\n", fmi2_status_to_string(status)); } FMI2ME->FMISolvingMode = fmi2_event_mode; eventInfo->newDiscreteStatesNeeded = fmi2_true; eventInfo->terminateSimulation = fmi2_false; status = fmi2_import_new_discrete_states(FMI2ME->FMIImportInstance, eventInfo); if (status != fmi1_status_ok && status != fmi1_status_warning) { ModelicaFormatError("fmi2NewDiscreteStates failed with status : %s\n", fmi2_status_to_string(status)); } status = fmi2_import_enter_continuous_time_mode(FMI2ME->FMIImportInstance); if (status != fmi1_status_ok && status != fmi1_status_warning) { ModelicaFormatError("fmi2EnterContinuousTimeMode failed with status : %s\n", fmi2_status_to_string(status)); } FMI2ME->FMISolvingMode = fmi2_continuousTime_mode; return eventInfo->valuesOfContinuousStatesChanged; }
_Ret_z_ const char* ModelicaInternal_temporaryFileName(void) { /* Get full path name of a temporary file name which does not exist */ char* fullName; char* tempName = tmpnam(NULL); if (tempName == NULL) { ModelicaFormatError("Not possible to get temporary filename\n%s", strerror(errno)); return ""; } fullName = ModelicaAllocateString(strlen(tempName)); strcpy(fullName, tempName); ModelicaConvertToUnixDirectorySeparator(fullName); return fullName; }
void ModelicaInternal_rmdir(_In_z_ const char* directoryName) { /* Remove directory */ #if defined(__WATCOMC__) || defined(__LCC__) || defined(_POSIX_) || defined(__GNUC__) int result = rmdir(directoryName); #elif defined(__BORLANDC__) || defined(_WIN32) int result = _rmdir(directoryName); #else ModelicaNotExistError("ModelicaInternal_rmdir"); #endif #if defined(__WATCOMC__) || defined(__LCC__) || defined(__BORLANDC__) || defined(_WIN32) || defined(_POSIX_) || defined(__GNUC__) if (result != 0) { ModelicaFormatError("Not possible to remove directory\n" "\"%s\":\n%s", directoryName, strerror(errno)); } #endif }
/* * Wrapper for the FMI function fmi2SetString. * Returns status. */ void fmi2SetString_OMC(void* in_fmi2, int numberOfValueReferences, double* stringValuesReferences, char** stringValues, int fmiType) { if (fmiType == 1) { FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2; if (FMI2ME->FMISolvingMode == fmi2_instantiated_mode || FMI2ME->FMISolvingMode == fmi2_initialization_mode || FMI2ME->FMISolvingMode == fmi2_event_mode) { fmi2_value_reference_t* valuesReferences_int = real_to_fmi2_value_reference(numberOfValueReferences, stringValuesReferences); fmi2_status_t status = fmi2_import_set_string(FMI2ME->FMIImportInstance, valuesReferences_int, numberOfValueReferences, (fmi2_string_t*)stringValues); free(valuesReferences_int); if (status != fmi2_status_ok && status != fmi2_status_warning) { ModelicaFormatError("fmi2SetString failed with status : %s\n", fmi2_status_to_string(status)); } } } else if (fmiType == 2) { } }