From ce5bd5b5aaffb7d62b9ef1a9db7feeefb7a27c18 Mon Sep 17 00:00:00 2001 From: tbeu Date: Wed, 27 Sep 2017 20:19:05 +0200 Subject: [PATCH] refs #21: Do not error if cell/node/key is not found * Report validity by new Boolean output flag ''exist'' (on scalar get functions only) * Use ModelicaMessage (and not ModelicaError) (Can be changed to ModelicaWarning once there is proper tool support). --- ExternData/Resources/C-Sources/ED_INIFile.c | 81 ++- ExternData/Resources/C-Sources/ED_JSONFile.c | 548 +++++++++++-------- ExternData/Resources/C-Sources/ED_XLSFile.c | 260 ++++++--- ExternData/Resources/C-Sources/ED_XLSXFile.c | 32 +- ExternData/Resources/C-Sources/ED_XMLFile.c | 72 ++- ExternData/Resources/Include/ED_INIFile.h | 6 +- ExternData/Resources/Include/ED_JSONFile.h | 24 +- ExternData/Resources/Include/ED_XLSFile.h | 6 +- ExternData/Resources/Include/ED_XLSXFile.h | 6 +- ExternData/Resources/Include/ED_XMLFile.h | 6 +- ExternData/package.mo | 62 ++- 11 files changed, 706 insertions(+), 397 deletions(-) diff --git a/ExternData/Resources/C-Sources/ED_INIFile.c b/ExternData/Resources/C-Sources/ED_INIFile.c index 25267248..d8742040 100644 --- a/ExternData/Resources/C-Sources/ED_INIFile.c +++ b/ExternData/Resources/C-Sources/ED_INIFile.c @@ -160,7 +160,7 @@ void ED_destroyINI(void* _ini) } } -double ED_getDoubleFromINI(void* _ini, const char* varName, const char* section, int strict) +double ED_getDoubleFromINI(void* _ini, const char* varName, const char* section, int strict, int* exist) { double ret = 0.; INIFile* ini = (INIFile*)_ini; @@ -168,63 +168,89 @@ double ED_getDoubleFromINI(void* _ini, const char* varName, const char* section, INISection* _section = findSection(ini, section); if (_section != NULL) { INIPair* pair = findKey(_section, varName); + *exist = 1; if (pair != NULL) { - if (ED_strtod(pair->value, ini->loc, &ret, strict)) { - ModelicaFormatError("Cannot read double value \"%s\" from file \"%s\"\n", - pair->value, ini->fileName); + if (NULL != pair->value) { + if (ED_strtod(pair->value, ini->loc, &ret, strict)) { + ModelicaFormatError("Cannot read double value \"%s\" from file \"%s\"\n", + pair->value, ini->fileName); + } + } + else { + ModelicaFormatError("Cannot read value for key \"%s\" from file \"%s\"\n", + varName, ini->fileName); + *exist = 0; } } else { - ModelicaFormatError("Cannot read key \"%s\" from file \"%s\"\n", + ModelicaFormatMessage("Cannot read key \"%s\" from file \"%s\"\n", varName, ini->fileName); + *exist = 0; } } else { if (strlen(section) > 0) { - ModelicaFormatError("Cannot read section \"%s\" from file \"%s\"\n", + ModelicaFormatMessage("Cannot read section \"%s\" from file \"%s\"\n", section, ini->fileName); } else { - ModelicaFormatError("Cannot read empty section from file \"%s\"\n", + ModelicaFormatMessage("Cannot read empty section from file \"%s\"\n", ini->fileName); } + *exist = 0; } } + else { + *exist = 0; + } return ret; } -const char* ED_getStringFromINI(void* _ini, const char* varName, const char* section) +const char* ED_getStringFromINI(void* _ini, const char* varName, const char* section, int* exist) { INIFile* ini = (INIFile*)_ini; if (ini != NULL) { INISection* _section = findSection(ini, section); if (_section != NULL) { INIPair* pair = findKey(_section, varName); + *exist = 1; if (pair != NULL) { - char* ret = ModelicaAllocateString(strlen(pair->value)); - strcpy(ret, pair->value); - return (const char*)ret; + if (NULL != pair->value) { + char* ret = ModelicaAllocateString(strlen(pair->value)); + strcpy(ret, pair->value); + return (const char*)ret; + } + else { + ModelicaFormatError("Cannot read value for key \"%s\" from file \"%s\"\n", + varName, ini->fileName); + *exist = 0; + } } else { - ModelicaFormatError("Cannot read key \"%s\" from file \"%s\"\n", + ModelicaFormatMessage("Cannot read key \"%s\" from file \"%s\"\n", varName, ini->fileName); + *exist = 0; } } else { if (strlen(section) > 0) { - ModelicaFormatError("Cannot read section \"%s\" from file \"%s\"\n", + ModelicaFormatMessage("Cannot read section \"%s\" from file \"%s\"\n", section, ini->fileName); } else { - ModelicaFormatError("Cannot read empty section from file \"%s\"\n", + ModelicaFormatMessage("Cannot read empty section from file \"%s\"\n", ini->fileName); } + *exist = 0; } } + else { + *exist = 0; + } return ""; } -int ED_getIntFromINI(void* _ini, const char* varName, const char* section, int strict) +int ED_getIntFromINI(void* _ini, const char* varName, const char* section, int strict, int* exist) { long ret = 0; INIFile* ini = (INIFile*)_ini; @@ -232,27 +258,40 @@ int ED_getIntFromINI(void* _ini, const char* varName, const char* section, int s INISection* _section = findSection(ini, section); if (_section != NULL) { INIPair* pair = findKey(_section, varName); + *exist = 1; if (pair != NULL) { - if (ED_strtol(pair->value, ini->loc, &ret, strict)) { - ModelicaFormatError("Cannot read int value \"%s\" from file \"%s\"\n", - pair->value, ini->fileName); + if (NULL != pair->value) { + if (ED_strtol(pair->value, ini->loc, &ret, strict)) { + ModelicaFormatError("Cannot read int value \"%s\" from file \"%s\"\n", + pair->value, ini->fileName); + } + } + else { + ModelicaFormatError("Cannot read value for key \"%s\" from file \"%s\"\n", + varName, ini->fileName); + *exist = 0; } } else { - ModelicaFormatError("Cannot read key \"%s\" from file \"%s\"\n", + ModelicaFormatMessage("Cannot read key \"%s\" from file \"%s\"\n", varName, ini->fileName); + *exist = 0; } } else { if (strlen(section) > 0) { - ModelicaFormatError("Cannot read section \"%s\" from file \"%s\"\n", + ModelicaFormatMessage("Cannot read section \"%s\" from file \"%s\"\n", section, ini->fileName); } else { - ModelicaFormatError("Cannot read empty section from file \"%s\"\n", + ModelicaFormatMessage("Cannot read empty section from file \"%s\"\n", ini->fileName); } + *exist = 0; } } + else { + *exist = 0; + } return (int)ret; } diff --git a/ExternData/Resources/C-Sources/ED_JSONFile.c b/ExternData/Resources/C-Sources/ED_JSONFile.c index 863e9be7..3d0de9c1 100644 --- a/ExternData/Resources/C-Sources/ED_JSONFile.c +++ b/ExternData/Resources/C-Sources/ED_JSONFile.c @@ -38,24 +38,6 @@ #include "ModelicaUtilities.h" #include "../Include/ED_JSONFile.h" -/* The standard way to detect posix is to check _POSIX_VERSION, - * which is defined in - */ -#if defined(__unix__) || defined(__linux__) || defined(__APPLE_CC__) -#include -#endif -#if !defined(_POSIX_) && defined(_POSIX_VERSION) -#define _POSIX_ 1 -#endif - -/* Use re-entrant string tokenize function if available */ -#if defined(_POSIX_) -#elif defined(_MSC_VER) && _MSC_VER >= 1400 -#define strtok_r(str, delim, saveptr) strtok_s((str), (delim), (saveptr)) -#else -#define strtok_r(str, delim, saveptr) strtok((str), (delim)) -#endif - static JSON_Value_Type json_array_get_type(const JSON_Array *array); static JSON_Value_Type json_array_get_type2D(const JSON_Array *array); static int json_array_check_dimensions2D(const JSON_Array *array); @@ -114,97 +96,159 @@ void ED_destroyJSON(void* _json) { } } -double ED_getDoubleFromJSON(void* _json, const char* varName) { - char* strValue; - double ret = 0; +double ED_getDoubleFromJSON(void* _json, const char* varName, int* exist) { + double ret = 0.; JSONFile* json = (JSONFile*)_json; if (json != NULL) { + *exist = 1; if (json_object_dothas_value_of_type(json->root, varName, JSONNumber)) { return json_object_dotget_number(json->root, varName); - } else if (json_object_dothas_value_of_type(json->root, varName, JSONString)) { - strValue = strdup(json_object_dotget_string(json->root, varName)); - if (ED_strtod(strValue, json->loc, &ret, ED_STRICT)) { - ModelicaFormatError("Could not parse double from \"%s\" at \"%s\" in file \"%s\"\n", - strValue, varName, json->fileName); + } + else if (json_object_dothas_value_of_type(json->root, varName, JSONString)) { + const char* token = json_object_dotget_string(json->root, varName); + if (NULL != token) { + char* tokenCopy = strdup(token); + if (NULL != tokenCopy) { + int ok = ED_strtod(tokenCopy, json->loc, &ret, ED_STRICT); + free(tokenCopy); + if (ED_OK != ok) { + ModelicaFormatError("Could not parse double from \"%s\" at \"%s\" in file \"%s\"\n", + token, varName, json->fileName); + } + } + else { + ModelicaError("Memory allocation error\n"); + } + } + else { + *exist = 0; } - free(strValue); - } else { - ModelicaFormatError("Cannot find numeric value \"%s\" in file \"%s\"\n", + } + else { + ModelicaFormatMessage("Cannot find numeric value \"%s\" in file \"%s\"\n", varName, json->fileName); + *exist = 0; } } + else { + *exist = 0; + } return ret; } -const char* ED_getStringFromJSON(void* _json, const char* varName) { +const char* ED_getStringFromJSON(void* _json, const char* varName, int* exist) { JSONFile* json = (JSONFile*)_json; if (json != NULL) { + *exist = 1; if (json_object_dothas_value_of_type(json->root, varName, JSONString)) { - return json_object_dotget_string(json->root, varName); - } else { - ModelicaFormatError("Cannot find string value \"%s\" in file \"%s\"\n", + const char* token = json_object_dotget_string(json->root, varName); + if (NULL != token) { + char* ret = ModelicaAllocateString(strlen(token)); + strcpy(ret, token); + return (const char*)ret; + } + else { + *exist = 0; + } + } + else { + ModelicaFormatMessage("Cannot find string value \"%s\" in file \"%s\"\n", varName, json->fileName); + *exist = 0; } } + else { + *exist = 0; + } return ""; } -int ED_getIntFromJSON(void* _json, const char* varName) { - char* strValue; +int ED_getIntFromJSON(void* _json, const char* varName, int* exist) { long ret = 0; JSONFile* json = (JSONFile*)_json; if (json != NULL) { + *exist = 1; if (json_object_dothas_value_of_type(json->root, varName, JSONNumber)) { return (int)json_object_dotget_number(json->root, varName); - } else if (json_object_dothas_value_of_type(json->root, varName, JSONString)) { - strValue = strdup(json_object_dotget_string(json->root, varName)); - if (ED_strtol(strValue, json->loc, &ret, ED_STRICT)) { - ModelicaFormatError("Could not parse integer from \"%s\" at \"%s\" in file \"%s\"\n", - strValue, varName, json->fileName); + } + else if (json_object_dothas_value_of_type(json->root, varName, JSONString)) { + const char* token = json_object_dotget_string(json->root, varName); + if (NULL != token) { + char* tokenCopy = strdup(token); + if (NULL != tokenCopy) { + int ok = ED_strtol(tokenCopy, json->loc, &ret, ED_STRICT); + free(tokenCopy); + if (ED_OK != ok) { + ModelicaFormatError("Could not parse integer from \"%s\" at \"%s\" in file \"%s\"\n", + token, varName, json->fileName); + } + } + else { + ModelicaError("Memory allocation error\n"); + } } - free(strValue); - } else { - ModelicaFormatError("Cannot find numeric value \"%s\" in file \"%s\"\n", + else { + *exist = 0; + } + } + else { + ModelicaFormatMessage("Cannot find numeric value \"%s\" in file \"%s\"\n", varName, json->fileName); + *exist = 0; } } + else { + *exist = 0; + } return (int)ret; } -int ED_getBooleanFromJSON(void* _json, const char* varName) { - char* strValue; +int ED_getBooleanFromJSON(void* _json, const char* varName, int* exist) { int ret = 0; JSONFile* json = (JSONFile*)_json; if (json != NULL) { + *exist = 1; if (json_object_dothas_value_of_type(json->root, varName, JSONBoolean)) { return json_object_dotget_boolean(json->root, varName); - } else if (json_object_dothas_value_of_type(json->root, varName, JSONString)) { - strValue = strdup(json_object_dotget_string(json->root, varName)); - if (strcmp(strValue, "true")==0) { - ret = 1; - } else if (strcmp(strValue, "false")==0) { - ret = 0; - } else { - ModelicaFormatError("Could not parse boolean from \"%s\" at \"%s\" in file \"%s\"\n", - strValue, varName, json->fileName); + } + else if (json_object_dothas_value_of_type(json->root, varName, JSONString)) { + const char* token = json_object_dotget_string(json->root, varName); + if (NULL != token) { + if (strcmp(token, "true") == 0) { + ret = 1; + } + else if (strcmp(token, "false") == 0) { + ret = 0; + } + else { + ModelicaFormatError("Could not parse boolean from \"%s\" at \"%s\" in file \"%s\"\n", + token, varName, json->fileName); + } + } + else { + *exist = 0; } - free(strValue); - } else { - ModelicaFormatError("Cannot find boolean value \"%s\" in file \"%s\"\n", + } + else { + ModelicaFormatMessage("Cannot find boolean value \"%s\" in file \"%s\"\n", varName, json->fileName); + *exist = 0; } } + else { + *exist = 0; + } return ret; } void ED_getArray1DDimensionFromJSON(void* _json, const char* varName, int* n) { - JSON_Array* jsonArray; JSONFile* json = (JSONFile*)_json; if (json != NULL) { if (json_object_dothas_value_of_type(json->root, varName, JSONArray)) { - jsonArray = json_object_dotget_array(json->root, varName); + JSON_Array* jsonArray = json_object_dotget_array(json->root, varName); *n = (int)json_array_get_count(jsonArray); - } else { + } + else { ModelicaFormatError("Cannot find array value \"%s\" in file \"%s\"\n", varName, json->fileName); } @@ -212,336 +256,403 @@ void ED_getArray1DDimensionFromJSON(void* _json, const char* varName, int* n) { } void ED_getArray2DDimensionsFromJSON(void* _json, const char* varName, int* m, int* n) { - JSON_Array* jsonArray; JSONFile* json = (JSONFile*)_json; if (json != NULL) { if (json_object_dothas_value_of_type(json->root, varName, JSONArray)) { - jsonArray = json_object_dotget_array(json->root, varName); - if (JSONArray==json_array_get_type(jsonArray)) { + JSON_Array* jsonArray = json_object_dotget_array(json->root, varName); + if (JSONArray == json_array_get_type(jsonArray)) { *m = (int)json_array_get_count(jsonArray); *n = json_array_check_dimensions2D(jsonArray); if (*n==-1) { ModelicaFormatError("Array value has 2 dimensions, but not all rows have same column dimension \"%s\" in file \"%s\"\n", varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Array value has 1 dimension, not 2 \"%s\" in file \"%s\"\n", varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Cannot find array value \"%s\" in file \"%s\"\n", varName, json->fileName); } } } -void ED_getDoubleArray1DFromJSON(void* _json, const char* varName, double* arr, size_t n) { - JSON_Array* jsonArray; - size_t i; - char* strValue; +void ED_getDoubleArray1DFromJSON(void* _json, const char* varName, double* a, size_t n) { JSONFile* json = (JSONFile*)_json; if (json != NULL) { if (json_object_dothas_value_of_type(json->root, varName, JSONArray)) { - jsonArray = json_object_dotget_array(json->root, varName); + JSON_Array* jsonArray = json_object_dotget_array(json->root, varName); if (n<=json_array_get_count(jsonArray)) { - if (JSONNumber==json_array_get_type(jsonArray)) { + size_t i; + if (JSONNumber == json_array_get_type(jsonArray)) { for (i=0; iloc, &(arr[i]), ED_STRICT)) { - ModelicaFormatError("Could not parse double from \"%s\" in array at \"%s\" in file \"%s\"\n", - strValue, varName, json->fileName); + const char* token = json_array_get_string(jsonArray, i); + if (NULL != token) { + char* tokenCopy = strdup(token); + if (NULL != tokenCopy) { + int ok = ED_strtod(tokenCopy, json->loc, &a[i], ED_STRICT); + free(tokenCopy); + if (ED_OK != ok) { + ModelicaFormatError("Could not parse double from \"%s\" in array at \"%s\" in file \"%s\"\n", + token, varName, json->fileName); + } + } + else { + ModelicaError("Memory allocation error\n"); + } } - free(strValue); } - } else { + } + else { ModelicaFormatError("Array value is not numeric \"%s\" in file \"%s\"\n", varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Array value dimension (%d) does not match requested size (%d) \"%s\" in file \"%s\"\n", json_array_get_count(jsonArray), n, varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Cannot find array value \"%s\" in file \"%s\"\n", varName, json->fileName); } } } -void ED_getStringArray1DFromJSON(void* _json, const char* varName, char** arr, size_t n) { - JSON_Array* jsonArray; - size_t i; +void ED_getStringArray1DFromJSON(void* _json, const char* varName, char** a, size_t n) { JSONFile* json = (JSONFile*)_json; if (json != NULL) { if (json_object_dothas_value_of_type(json->root, varName, JSONArray)) { - jsonArray = json_object_dotget_array(json->root, varName); + JSON_Array* jsonArray = json_object_dotget_array(json->root, varName); if (n<=json_array_get_count(jsonArray)) { - if (JSONString==json_array_get_type(jsonArray)) { + if (JSONString == json_array_get_type(jsonArray)) { + size_t i; for (i=0; ifileName); } - } else { + } + else { ModelicaFormatError("Array value dimension does not match requested size \"%s\" in file \"%s\"\n", varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Cannot find array value \"%s\" in file \"%s\"\n", varName, json->fileName); } } } -void ED_getIntArray1DFromJSON(void* _json, const char* varName, int* arr, size_t n) { - JSON_Array* jsonArray; - size_t i; - char* strValue; - long lValue; +void ED_getIntArray1DFromJSON(void* _json, const char* varName, int* a, size_t n) { JSONFile* json = (JSONFile*)_json; if (json != NULL) { if (json_object_dothas_value_of_type(json->root, varName, JSONArray)) { - jsonArray = json_object_dotget_array(json->root, varName); + JSON_Array* jsonArray = json_object_dotget_array(json->root, varName); if (n<=json_array_get_count(jsonArray)) { - if (JSONNumber==json_array_get_type(jsonArray)) { + size_t i; + if (JSONNumber == json_array_get_type(jsonArray)) { for (i=0; iloc, &lValue, ED_STRICT)) { - ModelicaFormatError("Could not parse integer from \"%s\" in array at \"%s\" in file \"%s\"\n", - strValue, varName, json->fileName); + const char* token = json_array_get_string(jsonArray, i); + if (NULL != token) { + char* tokenCopy = strdup(token); + if (NULL != tokenCopy) { + long val; + int ok = ED_strtol(tokenCopy, json->loc, &val, ED_STRICT); + free(tokenCopy); + if (ED_OK == ok) { + a[i] = (int)val; + } + else { + ModelicaFormatError("Could not parse integer from \"%s\" in array at \"%s\" in file \"%s\"\n", + token, varName, json->fileName); + } + } + else { + ModelicaError("Memory allocation error\n"); + } } - arr[i] = (int)lValue; - free(strValue); } - } else { + } + else { ModelicaFormatError("Array value is not numeric \"%s\" in file \"%s\"\n", varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Array value dimension does not match requested size \"%s\" in file \"%s\"\n", varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Cannot find array value \"%s\" in file \"%s\"\n", varName, json->fileName); } } } -void ED_getBooleanArray1DFromJSON(void* _json, const char* varName, int* arr, size_t n) { - JSON_Array* jsonArray; - size_t i; - char* strValue; +void ED_getBooleanArray1DFromJSON(void* _json, const char* varName, int* a, size_t n) { JSONFile* json = (JSONFile*)_json; if (json != NULL) { if (json_object_dothas_value_of_type(json->root, varName, JSONArray)) { - jsonArray = json_object_dotget_array(json->root, varName); + JSON_Array* jsonArray = json_object_dotget_array(json->root, varName); if (n<=json_array_get_count(jsonArray)) { - if (JSONBoolean==json_array_get_type(jsonArray)) { + size_t i; + if (JSONBoolean == json_array_get_type(jsonArray)) { for (i=0; ifileName); + const char* token = json_array_get_string(jsonArray, i); + if (NULL != token) { + if (strcmp(token, "true") == 0) { + a[i] = 1; + } + else if (strcmp(token, "false") == 0) { + a[i] = 0; + } + else { + ModelicaFormatError("Could not parse boolean from \"%s\" at \"%s\" in file \"%s\"\n", + token, varName, json->fileName); + } } - free(strValue); } - } else { + } + else { ModelicaFormatError("Array value is not numeric \"%s\" in file \"%s\"\n", varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Array value dimension does not match requested size \"%s\" in file \"%s\"\n", varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Cannot find array value \"%s\" in file \"%s\"\n", varName, json->fileName); } } } -void ED_getDoubleArray2DFromJSON(void* _json, const char* varName, double* arr, size_t m, size_t n) { - JSON_Array* jsonArray; - JSON_Array* subArray; - size_t i, j; - char* strValue; +void ED_getDoubleArray2DFromJSON(void* _json, const char* varName, double* a, size_t m, size_t n) { JSONFile* json = (JSONFile*)_json; if (json != NULL) { if (json_object_dothas_value_of_type(json->root, varName, JSONArray)) { - jsonArray = json_object_dotget_array(json->root, varName); - if (m<=json_array_get_count(jsonArray) && n==json_array_check_dimensions2D(jsonArray)) { - if (JSONNumber==json_array_get_type2D(jsonArray)) { + JSON_Array* jsonArray = json_object_dotget_array(json->root, varName); + if (m <= json_array_get_count(jsonArray) && n == json_array_check_dimensions2D(jsonArray)) { + size_t i, j; + if (JSONNumber == json_array_get_type2D(jsonArray)) { for (i=0; iloc, &(arr[i*n + j]), ED_STRICT)) { - ModelicaFormatError("Could not parse double from \"%s\" in array at \"%s\" in file \"%s\"\n", - strValue, varName, json->fileName); + const char* token = json_array_get_string(subArray, i); + if (NULL != token) { + char* tokenCopy = strdup(token); + if (NULL != tokenCopy) { + int ok = ED_strtod(tokenCopy, json->loc, &a[i*n + j], ED_STRICT); + free(tokenCopy); + if (ED_OK != ok) { + ModelicaFormatError("Could not parse double from \"%s\" in array at \"%s\" in file \"%s\"\n", + token, varName, json->fileName); + } + } + else { + ModelicaError("Memory allocation error\n"); + } } - free(strValue); } } - } else { + } + else { ModelicaFormatError("Array value is not numeric \"%s\" in file \"%s\"\n", varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Array value dimensions (%dx%d) do not match requested size (%dx%d) \"%s\" in file \"%s\"\n", json_array_get_count(jsonArray), json_array_check_dimensions2D(jsonArray), m, n, varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Cannot find array value \"%s\" in file \"%s\"\n", varName, json->fileName); } } } -void ED_getStringArray2DFromJSON(void* _json, const char* varName, char** arr, size_t m, size_t n) { - JSON_Array* jsonArray; - JSON_Array* subArray; - size_t i, j; +void ED_getStringArray2DFromJSON(void* _json, const char* varName, char** a, size_t m, size_t n) { JSONFile* json = (JSONFile*)_json; if (json != NULL) { if (json_object_dothas_value_of_type(json->root, varName, JSONArray)) { - jsonArray = json_object_dotget_array(json->root, varName); - if (m<=json_array_get_count(jsonArray) && n==json_array_check_dimensions2D(jsonArray)) { - if (JSONString==json_array_get_type2D(jsonArray)) { + JSON_Array* jsonArray = json_object_dotget_array(json->root, varName); + if (m <= json_array_get_count(jsonArray) && n == json_array_check_dimensions2D(jsonArray)) { + if (JSONString == json_array_get_type2D(jsonArray)) { + size_t i, j; for (i=0; ifileName); } - } else { + } + else { ModelicaFormatError("Array value dimensions (%dx%d) do not match requested size (%dx%d) \"%s\" in file \"%s\"\n", json_array_get_count(jsonArray), json_array_check_dimensions2D(jsonArray), m, n, varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Cannot find array value \"%s\" in file \"%s\"\n", varName, json->fileName); } } } -void ED_getIntArray2DFromJSON(void* _json, const char* varName, int* arr, size_t m, size_t n) { - JSON_Array* jsonArray; - JSON_Array* subArray; - size_t i, j; - char* strValue; - long lValue; +void ED_getIntArray2DFromJSON(void* _json, const char* varName, int* a, size_t m, size_t n) { JSONFile* json = (JSONFile*)_json; if (json != NULL) { if (json_object_dothas_value_of_type(json->root, varName, JSONArray)) { - jsonArray = json_object_dotget_array(json->root, varName); - if (m<=json_array_get_count(jsonArray) && n==json_array_check_dimensions2D(jsonArray)) { - if (JSONNumber==json_array_get_type2D(jsonArray)) { + JSON_Array* jsonArray = json_object_dotget_array(json->root, varName); + if (m <= json_array_get_count(jsonArray) && n == json_array_check_dimensions2D(jsonArray)) { + size_t i, j; + if (JSONNumber == json_array_get_type2D(jsonArray)) { for (i=0; iloc, &lValue, ED_STRICT)) { - ModelicaFormatError("Could not parse double from \"%s\" in array at \"%s\" in file \"%s\"\n", - strValue, varName, json->fileName); + const char* token = json_array_get_string(subArray, i); + if (NULL != token) { + char* tokenCopy = strdup(token); + if (NULL != tokenCopy) { + long val; + int ok = ED_strtol(tokenCopy, json->loc, &val, ED_STRICT); + free(tokenCopy); + if (ED_OK == ok) { + a[i*n + j] = val; + } + else { + ModelicaFormatError("Could not parse integer from \"%s\" in array at \"%s\" in file \"%s\"\n", + token, varName, json->fileName); + } + } + else { + ModelicaError("Memory allocation error\n"); + } } - arr[i*n + j] = lValue; - free(strValue); } } - } else { + } + else { ModelicaFormatError("Array value is not numeric \"%s\" in file \"%s\"\n", varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Array value dimensions (%dx%d) do not match requested size (%dx%d) \"%s\" in file \"%s\"\n", json_array_get_count(jsonArray), json_array_check_dimensions2D(jsonArray), m, n, varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Cannot find array value \"%s\" in file \"%s\"\n", varName, json->fileName); } } } -void ED_getBooleanArray2DFromJSON(void* _json, const char* varName, int* arr, size_t m, size_t n) { - JSON_Array* jsonArray; - JSON_Array* subArray; - size_t i, j; - char* strValue; +void ED_getBooleanArray2DFromJSON(void* _json, const char* varName, int* a, size_t m, size_t n) { JSONFile* json = (JSONFile*)_json; if (json != NULL) { if (json_object_dothas_value_of_type(json->root, varName, JSONArray)) { - jsonArray = json_object_dotget_array(json->root, varName); - if (m<=json_array_get_count(jsonArray) && n==json_array_check_dimensions2D(jsonArray)) { - if (JSONBoolean==json_array_get_type2D(jsonArray)) { + JSON_Array* jsonArray = json_object_dotget_array(json->root, varName); + if (m <= json_array_get_count(jsonArray) && n == json_array_check_dimensions2D(jsonArray)) { + size_t i, j; + if (JSONBoolean == json_array_get_type2D(jsonArray)) { for (i=0; ifileName); + const char* token = json_array_get_string(subArray, i); + if (NULL != token) { + if (strcmp(token, "true") == 0) { + a[i*n + j] = 1; + } + else if (strcmp(token, "false") == 0) { + a[i*n + j] = 0; + } + else { + ModelicaFormatError("Could not parse boolean from \"%s\" at \"%s\" in file \"%s\"\n", + token, varName, json->fileName); + } } - free(strValue); } } - } else { + } + else { ModelicaFormatError("Array value is not boolean \"%s\" in file \"%s\"\n", varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Array value dimensions (%dx%d) do not match requested size (%dx%d) \"%s\" in file \"%s\"\n", json_array_get_count(jsonArray), json_array_check_dimensions2D(jsonArray), m, n, varName, json->fileName); } - } else { + } + else { ModelicaFormatError("Cannot find array value \"%s\" in file \"%s\"\n", varName, json->fileName); } @@ -554,9 +665,10 @@ static JSON_Value_Type json_array_get_type(const JSON_Array *array) { size_t n = json_array_get_count(array); for (i=0; i=0 && n!=json_array_get_count(subarray)) { + if (i == 0) { + n = (int)json_array_get_count(subarray); + } + else if (n >= 0 && n != json_array_get_count(subarray)) { n = -1; } } } - return (int)n; + return n; } diff --git a/ExternData/Resources/C-Sources/ED_XLSFile.c b/ExternData/Resources/C-Sources/ED_XLSFile.c index d109a7b6..da636b98 100644 --- a/ExternData/Resources/C-Sources/ED_XLSFile.c +++ b/ExternData/Resources/C-Sources/ED_XLSFile.c @@ -150,7 +150,7 @@ static xlsWorkSheet* findSheet(XLSFile* xls, char** sheetName) } } if (sheet < 0) { - ModelicaFormatError("Cannot find sheet \"%s\" in file \"%s\"\n", + ModelicaFormatMessage("Cannot find sheet \"%s\" in file \"%s\"\n", *sheetName, xls->fileName); return NULL; } @@ -167,99 +167,183 @@ static xlsWorkSheet* findSheet(XLSFile* xls, char** sheetName) return pWS; } -double ED_getDoubleFromXLS(void* _xls, const char* cellAddress, const char* sheetName) +double ED_getDoubleFromXLS(void* _xls, const char* cellAddress, const char* sheetName, int* exist) { double ret = 0.; - ED_getDoubleArray2DFromXLS(_xls, cellAddress, sheetName, &ret, 1, 1); + XLSFile* xls = (XLSFile*)_xls; + if (xls != NULL) { + char* _sheetName = (char*)sheetName; + xlsWorkSheet* pWS = findSheet(xls, &_sheetName); + if (NULL != pWS) { + xlsCell* cell; + WORD row = 0, col = 0; + + *exist = 1; + rc(cellAddress, &row, &col); + cell = xls_cell(pWS, row, col); + if (cell != NULL && !cell->isHidden) { + /* Get the value of the cell (either numeric or string) */ + if (cell->id == XLS_RECORD_RK || cell->id == XLS_RECORD_MULRK || cell->id == XLS_RECORD_NUMBER) { + ret = cell->d; + } + else if (cell->id == XLS_RECORD_FORMULA) { + if (cell->l == 0) { /* It is a number */ + ret = cell->d; + } + else { + if (0 == strcmp((char*)cell->str, "bool")) { /* It is boolean */ + ret = (int)cell->d ? 1. : 0.; + } + else if (0 == strcmp((char*)cell->str, "error")) { /* Formula is in error */ + ModelicaFormatError("Error in formula of cell (%u,%u) in sheet \"%s\" of file \"%s\"\n", + (unsigned int)row, (unsigned int)col, _sheetName, xls->fileName); + } + else { /* Valid formula result */ + if (ED_strtod((char*)cell->str, xls->loc, &ret, ED_STRICT)) { + ModelicaFormatError("Error in cell (%u,%u) when reading double value \"%s\" from sheet \"%s\" of file \"%s\"\n", + (unsigned int)row, (unsigned int)col, cell->str, _sheetName, xls->fileName); + } + } + } + } + else if (cell->str != NULL) { + if (ED_strtod((char*)cell->str, xls->loc, &ret, ED_STRICT)) { + ModelicaFormatError("Error in cell (%u,%u) when reading double value \"%s\" from sheet \"%s\" of file \"%s\"\n", + (unsigned int)row, (unsigned int)col, cell->str, _sheetName, xls->fileName); + } + } + else { + *exist = 0; + } + } + else { + ModelicaFormatMessage("Cannot get cell (%u,%u) in sheet \"%s\" from file \"%s\"\n", + (unsigned int)row, (unsigned int)col, _sheetName, xls->fileName); + *exist = 0; + } + } + else { + *exist = 0; + } + } + else { + *exist = 0; + } return ret; } -const char* ED_getStringFromXLS(void* _xls, const char* cellAddress, const char* sheetName) +const char* ED_getStringFromXLS(void* _xls, const char* cellAddress, const char* sheetName, int* exist) { XLSFile* xls = (XLSFile*)_xls; if (xls != NULL) { char* _sheetName = (char*)sheetName; xlsWorkSheet* pWS = findSheet(xls, &_sheetName); - xlsCell* cell; - WORD row = 0, col = 0; + if (NULL != pWS) { + xlsCell* cell; + WORD row = 0, col = 0; - rc(cellAddress, &row, &col); - cell = xls_cell(pWS, row, col); - if (cell != NULL && !cell->isHidden) { - /* Get the string value of the cell */ - if (cell->id == XLS_RECORD_FORMULA) { - if (cell->l != 0) { /* It is not a number */ - if ((0 != strcmp((char*)cell->str, "bool")) && /* It is not boolean and */ - (0 != strcmp((char*)cell->str, "error"))) { /* formula is not in error */ - char* ret = ModelicaAllocateString(strlen((char*)cell->str)); - strcpy(ret, (char*)cell->str); - return (const char*)ret; + *exist = 1; + rc(cellAddress, &row, &col); + cell = xls_cell(pWS, row, col); + if (cell != NULL && !cell->isHidden) { + /* Get the string value of the cell */ + if (cell->id == XLS_RECORD_FORMULA) { + if (cell->l != 0) { /* It is not a number */ + if ((0 != strcmp((char*)cell->str, "bool")) && /* It is not boolean and */ + (0 != strcmp((char*)cell->str, "error"))) { /* formula is not in error */ + char* ret = ModelicaAllocateString(strlen((char*)cell->str)); + strcpy(ret, (char*)cell->str); + return (const char*)ret; + } } } + else if (cell->str != NULL) { + char* ret = ModelicaAllocateString(strlen((char*)cell->str)); + strcpy(ret, (char*)cell->str); + return (const char*)ret; + } + else { + *exist = 0; + } } - else if (cell->str != NULL) { - char* ret = ModelicaAllocateString(strlen((char*)cell->str)); - strcpy(ret, (char*)cell->str); - return (const char*)ret; + else { + ModelicaFormatMessage("Cannot get cell (%u,%u) in sheet \"%s\" from file \"%s\"\n", + (unsigned int)row, (unsigned int)col, _sheetName, xls->fileName); + *exist = 0; } } else { - ModelicaFormatMessage("Cannot get cell (%u,%u) in sheet \"%s\" from file \"%s\"\n", - (unsigned int)row, (unsigned int)col, _sheetName, xls->fileName); + *exist = 0; } } + else { + *exist = 0; + } return ""; } -int ED_getIntFromXLS(void* _xls, const char* cellAddress, const char* sheetName) +int ED_getIntFromXLS(void* _xls, const char* cellAddress, const char* sheetName, int* exist) { long ret = 0; XLSFile* xls = (XLSFile*)_xls; if (xls != NULL) { char* _sheetName = (char*)sheetName; xlsWorkSheet* pWS = findSheet(xls, &_sheetName); - xlsCell* cell; - WORD row = 0, col = 0; + if (NULL != pWS) { + xlsCell* cell; + WORD row = 0, col = 0; - rc(cellAddress, &row, &col); - cell = xls_cell(pWS, row, col); - if (cell != NULL && !cell->isHidden) { - /* Get the value of the cell (either numeric or string) */ - if (cell->id == XLS_RECORD_RK || cell->id == XLS_RECORD_MULRK || cell->id == XLS_RECORD_NUMBER) { - ret = (long)cell->d; - } - else if (cell->id == XLS_RECORD_FORMULA) { - if (cell->l == 0) { /* It is a number */ + *exist = 1; + rc(cellAddress, &row, &col); + cell = xls_cell(pWS, row, col); + if (cell != NULL && !cell->isHidden) { + /* Get the value of the cell (either numeric or string) */ + if (cell->id == XLS_RECORD_RK || cell->id == XLS_RECORD_MULRK || cell->id == XLS_RECORD_NUMBER) { ret = (long)cell->d; } - else { - if (0 == strcmp((char*)cell->str, "bool")) { /* It is boolean */ - ret = (long)cell->d ? 1 : 0; - } - else if (0 == strcmp((char*)cell->str, "error")) { /* Formula is in error */ - ModelicaFormatError("Error in formula of cell (%u,%u) in sheet \"%s\" of file \"%s\"\n", - (unsigned int)row, (unsigned int)col, _sheetName, xls->fileName); + else if (cell->id == XLS_RECORD_FORMULA) { + if (cell->l == 0) { /* It is a number */ + ret = (long)cell->d; } - else { /* Valid formula result */ - if (ED_strtol((char*)cell->str, xls->loc, &ret, ED_STRICT)) { - ModelicaFormatError("Error in cell (%u,%u) when reading int value \"%s\" from sheet \"%s\" of file \"%s\"\n", - (unsigned int)row, (unsigned int)col, (char*)cell->str, _sheetName, xls->fileName); + else { + if (0 == strcmp((char*)cell->str, "bool")) { /* It is boolean */ + ret = (long)cell->d ? 1 : 0; + } + else if (0 == strcmp((char*)cell->str, "error")) { /* Formula is in error */ + ModelicaFormatError("Error in formula of cell (%u,%u) in sheet \"%s\" of file \"%s\"\n", + (unsigned int)row, (unsigned int)col, _sheetName, xls->fileName); + } + else { /* Valid formula result */ + if (ED_strtol((char*)cell->str, xls->loc, &ret, ED_STRICT)) { + ModelicaFormatError("Error in cell (%u,%u) when reading int value \"%s\" from sheet \"%s\" of file \"%s\"\n", + (unsigned int)row, (unsigned int)col, (char*)cell->str, _sheetName, xls->fileName); + } } } } - } - else if (cell->str != NULL) { - if (ED_strtol((char*)cell->str, xls->loc, &ret, ED_STRICT)) { - ModelicaFormatError("Error in cell (%u,%u) when reading int value \"%s\" from sheet \"%s\" of file \"%s\"\n", - (unsigned int)row, (unsigned int)col, (char*)cell->str, _sheetName, xls->fileName); + else if (cell->str != NULL) { + if (ED_strtol((char*)cell->str, xls->loc, &ret, ED_STRICT)) { + ModelicaFormatError("Error in cell (%u,%u) when reading int value \"%s\" from sheet \"%s\" of file \"%s\"\n", + (unsigned int)row, (unsigned int)col, (char*)cell->str, _sheetName, xls->fileName); + } + } + else { + *exist = 0; } } + else { + ModelicaFormatMessage("Cannot get cell (%u,%u) in sheet \"%s\" from file \"%s\"\n", + (unsigned int)row, (unsigned int)col, _sheetName, xls->fileName); + *exist = 0; + } } else { - ModelicaFormatMessage("Cannot get cell (%u,%u) in sheet \"%s\" from file \"%s\"\n", - (unsigned int)row, (unsigned int)col, _sheetName, xls->fileName); + *exist = 0; } } + else { + *exist = 0; + } return (int)ret; } @@ -269,49 +353,51 @@ void ED_getDoubleArray2DFromXLS(void* _xls, const char* cellAddress, const char* if (xls != NULL) { char* _sheetName = (char*)sheetName; xlsWorkSheet* pWS = findSheet(xls, &_sheetName); - WORD row = 0, col = 0; - WORD i, j; + if (NULL != pWS) { + WORD row = 0, col = 0; + WORD i, j; - rc(cellAddress, &row, &col); - for (i = 0; i < m; i++) { - for (j = 0; j < n; j++) { - xlsCell* cell = xls_cell(pWS, row + i, col + j); - if (cell != NULL && !cell->isHidden) { - /* Get the value of the cell (either numeric or string) */ - if (cell->id == XLS_RECORD_RK || cell->id == XLS_RECORD_MULRK || cell->id == XLS_RECORD_NUMBER) { - a[i*n + j] = cell->d; - } - else if (cell->id == XLS_RECORD_FORMULA) { - if (cell->l == 0) { /* It is a number */ + rc(cellAddress, &row, &col); + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { + xlsCell* cell = xls_cell(pWS, row + i, col + j); + if (cell != NULL && !cell->isHidden) { + /* Get the value of the cell (either numeric or string) */ + if (cell->id == XLS_RECORD_RK || cell->id == XLS_RECORD_MULRK || cell->id == XLS_RECORD_NUMBER) { a[i*n + j] = cell->d; } - else { - if (0 == strcmp((char*)cell->str, "bool")) { /* It is boolean */ - a[i*n + j] = (int)cell->d ? 1. : 0.; - } - else if (0 == strcmp((char*)cell->str, "error")) { /* Formula is in error */ - ModelicaFormatError("Error in formula of cell (%u,%u) in sheet \"%s\" of file \"%s\"\n", - (unsigned int)(row + i), (unsigned int)(col + j), _sheetName, xls->fileName); + else if (cell->id == XLS_RECORD_FORMULA) { + if (cell->l == 0) { /* It is a number */ + a[i*n + j] = cell->d; } - else { /* Valid formula result */ - if (ED_strtod((char*)cell->str, xls->loc, &a[i*n + j], ED_STRICT)) { - ModelicaFormatError("Error in cell (%u,%u) when reading double value \"%s\" from sheet \"%s\" of file \"%s\"\n", - (unsigned int)(row + i), (unsigned int)(col + j), cell->str, _sheetName, xls->fileName); + else { + if (0 == strcmp((char*)cell->str, "bool")) { /* It is boolean */ + a[i*n + j] = (int)cell->d ? 1. : 0.; + } + else if (0 == strcmp((char*)cell->str, "error")) { /* Formula is in error */ + ModelicaFormatError("Error in formula of cell (%u,%u) in sheet \"%s\" of file \"%s\"\n", + (unsigned int)(row + i), (unsigned int)(col + j), _sheetName, xls->fileName); + } + else { /* Valid formula result */ + if (ED_strtod((char*)cell->str, xls->loc, &a[i*n + j], ED_STRICT)) { + ModelicaFormatError("Error in cell (%u,%u) when reading double value \"%s\" from sheet \"%s\" of file \"%s\"\n", + (unsigned int)(row + i), (unsigned int)(col + j), cell->str, _sheetName, xls->fileName); + } } } } - } - else if (cell->str != NULL) { - if (ED_strtod((char*)cell->str, xls->loc, &a[i*n + j], ED_STRICT)) { - ModelicaFormatError("Error in cell (%u,%u) when reading double value \"%s\" from sheet \"%s\" of file \"%s\"\n", - (unsigned int)(row + i), (unsigned int)(col + j), cell->str, _sheetName, xls->fileName); + else if (cell->str != NULL) { + if (ED_strtod((char*)cell->str, xls->loc, &a[i*n + j], ED_STRICT)) { + ModelicaFormatError("Error in cell (%u,%u) when reading double value \"%s\" from sheet \"%s\" of file \"%s\"\n", + (unsigned int)(row + i), (unsigned int)(col + j), cell->str, _sheetName, xls->fileName); + } } } - } - else { - a[i*n + j] = 0.; - ModelicaFormatMessage("Cannot get cell (%u,%u) in sheet \"%s\" from file \"%s\"\n", - (unsigned int)(row + i), (unsigned int)(col + j), _sheetName, xls->fileName); + else { + a[i*n + j] = 0.; + ModelicaFormatMessage("Cannot get cell (%u,%u) in sheet \"%s\" from file \"%s\"\n", + (unsigned int)(row + i), (unsigned int)(col + j), _sheetName, xls->fileName); + } } } } diff --git a/ExternData/Resources/C-Sources/ED_XLSXFile.c b/ExternData/Resources/C-Sources/ED_XLSXFile.c index 33a0daa7..394d0834 100644 --- a/ExternData/Resources/C-Sources/ED_XLSXFile.c +++ b/ExternData/Resources/C-Sources/ED_XLSXFile.c @@ -266,7 +266,7 @@ static XmlNodeRef findSheet(XLSXFile* xlsx, char** sheetName) HASH_FIND_STR(xlsx->sheets, *sheetName, iter); if (iter == NULL) { - ModelicaFormatError("Cannot find sheet name \"%s\" in file \"%s\" of file \"%s\"\n", + ModelicaFormatMessage("Cannot find sheet name \"%s\" in file \"%s\" of file \"%s\"\n", *sheetName, WB_XML, xlsx->fileName); return NULL; } @@ -369,7 +369,7 @@ static char* findCellValue(XLSXFile* xlsx, const char* cellAddress, XmlNodeRef r return token; } -double ED_getDoubleFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName) +double ED_getDoubleFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName, int* exist) { double ret = 0.; XLSXFile* xlsx = (XLSXFile*)_xlsx; @@ -378,6 +378,7 @@ double ED_getDoubleFromXLSX(void* _xlsx, const char* cellAddress, const char* sh XmlNodeRef root = findSheet(xlsx, &_sheetName); if (root != NULL) { char* token = findCellValue(xlsx, cellAddress, root, _sheetName); + *exist = 1; if (token != NULL) { if (ED_strtod(token, xlsx->loc, &ret, ED_STRICT)) { ModelicaFormatError("Cannot read double value \"%s\" from file \"%s\"\n", @@ -389,13 +390,20 @@ double ED_getDoubleFromXLSX(void* _xlsx, const char* cellAddress, const char* sh rc(cellAddress, &row, &col); ModelicaFormatMessage("Cannot get cell (%u,%u) in sheet \"%s\" from file \"%s\"\n", (unsigned int)row, (unsigned int)col, sheetName, xlsx->fileName); + *exist = 0; } } + else { + *exist = 0; + } + } + else { + *exist = 0; } return ret; } -const char* ED_getStringFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName) +const char* ED_getStringFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName, int* exist) { XLSXFile* xlsx = (XLSXFile*)_xlsx; if (xlsx != NULL) { @@ -403,6 +411,7 @@ const char* ED_getStringFromXLSX(void* _xlsx, const char* cellAddress, const cha XmlNodeRef root = findSheet(xlsx, &_sheetName); if (root != NULL) { char* token = findCellValue(xlsx, cellAddress, root, _sheetName); + *exist = 1; if (token != NULL) { char* ret = ModelicaAllocateString(strlen(token)); strcpy(ret, token); @@ -413,13 +422,20 @@ const char* ED_getStringFromXLSX(void* _xlsx, const char* cellAddress, const cha rc(cellAddress, &row, &col); ModelicaFormatMessage("Cannot get cell (%u,%u) in sheet \"%s\" from file \"%s\"\n", (unsigned int)row, (unsigned int)col, sheetName, xlsx->fileName); + *exist = 0; } } + else { + *exist = 0; + } + } + else { + *exist = 0; } return ""; } -int ED_getIntFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName) +int ED_getIntFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName, int* exist) { long ret = 0; XLSXFile* xlsx = (XLSXFile*)_xlsx; @@ -428,6 +444,7 @@ int ED_getIntFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetNam XmlNodeRef root = findSheet(xlsx, &_sheetName); if (root != NULL) { char* token = findCellValue(xlsx, cellAddress, root, _sheetName); + *exist = 1; if (token != NULL) { if (ED_strtol(token, xlsx->loc, &ret, ED_STRICT)) { ModelicaFormatError("Cannot read int value \"%s\" from file \"%s\"\n", @@ -439,8 +456,15 @@ int ED_getIntFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetNam rc(cellAddress, &row, &col); ModelicaFormatMessage("Cannot get cell (%u,%u) in sheet \"%s\" from file \"%s\"\n", (unsigned int)row, (unsigned int)col, sheetName, xlsx->fileName); + *exist = 0; } } + else { + *exist = 0; + } + } + else { + *exist = 0; } return (int)ret; } diff --git a/ExternData/Resources/C-Sources/ED_XMLFile.c b/ExternData/Resources/C-Sources/ED_XMLFile.c index a4a6f990..48125360 100644 --- a/ExternData/Resources/C-Sources/ED_XMLFile.c +++ b/ExternData/Resources/C-Sources/ED_XMLFile.c @@ -123,27 +123,25 @@ static char* findValue(XmlNodeRef* root, const char* varName, const char* fileNa elementError = 1; } while (token != NULL && elementError == 0) { - size_t i; - int foundToken = 0; - for (i = 0; i < XmlNode_getChildCount(*root); i++) { - XmlNodeRef child = XmlNode_getChild(*root, i); - if (XmlNode_isTag(child, token)) { - *root = child; - token = strtok_r(NULL, ".", &nextToken); - foundToken = 1; - break; - } + XmlNodeRef iter = XmlNode_findChild(*root, token); + if (NULL != iter) { + *root = iter; + token = strtok_r(NULL, ".", &nextToken); } - if (foundToken == 0) { + else { elementError = 1; } } free(buf); - if (elementError == 1) { - ModelicaFormatError("Error in line %i: Cannot find element \"%s\" in file \"%s\"\n", + if (0 == elementError) { + XmlNode_getValue(*root, &token); + } + else { + ModelicaFormatMessage("Error in line %i: Cannot find element \"%s\" in file \"%s\"\n", XmlNode_getLine(*root), varName, fileName); + *root = NULL; + token = NULL; } - XmlNode_getValue(*root, &token); } else { ModelicaError("Memory allocation error\n"); @@ -151,64 +149,88 @@ static char* findValue(XmlNodeRef* root, const char* varName, const char* fileNa return token; } -double ED_getDoubleFromXML(void* _xml, const char* varName) +double ED_getDoubleFromXML(void* _xml, const char* varName, int* exist) { double ret = 0.; XMLFile* xml = (XMLFile*)_xml; if (xml != NULL) { XmlNodeRef root = xml->root; char* token = findValue(&root, varName, xml->fileName); + *exist = 1; if (token != NULL) { if (ED_strtod(token, xml->loc, &ret, ED_STRICT)) { ModelicaFormatError("Error in line %i: Cannot read double value \"%s\" from file \"%s\"\n", XmlNode_getLine(root), token, xml->fileName); } } - else { - ModelicaFormatError("Error in line %i: Cannot read double value from file \"%s\"\n", + else if (NULL != root) { + ModelicaFormatMessage("Error in line %i: Cannot read double value from file \"%s\"\n", XmlNode_getLine(root), xml->fileName); + *exist = 0; + } + else { + *exist = 0; } } + else { + *exist = 0; + } return ret; } -const char* ED_getStringFromXML(void* _xml, const char* varName) +const char* ED_getStringFromXML(void* _xml, const char* varName, int* exist) { XMLFile* xml = (XMLFile*)_xml; if (xml != NULL) { XmlNodeRef root = xml->root; char* token = findValue(&root, varName, xml->fileName); + *exist = 1; if (token != NULL) { char* ret = ModelicaAllocateString(strlen(token)); strcpy(ret, token); return (const char*)ret; } - else { - ModelicaFormatError("Error in line %i: Cannot read value from file \"%s\"\n", + else if (NULL != root) { + ModelicaFormatMessage("Error in line %i: Cannot read value from file \"%s\"\n", XmlNode_getLine(root), xml->fileName); + *exist = 0; + } + else { + *exist = 0; } } + else { + *exist = 0; + } return ""; } -int ED_getIntFromXML(void* _xml, const char* varName) +int ED_getIntFromXML(void* _xml, const char* varName, int* exist) { long ret = 0; XMLFile* xml = (XMLFile*)_xml; if (xml != NULL) { XmlNodeRef root = xml->root; char* token = findValue(&root, varName, xml->fileName); + *exist = 1; if (token != NULL) { if (ED_strtol(token, xml->loc, &ret, ED_STRICT)) { ModelicaFormatError("Error in line %i: Cannot read int value \"%s\" from file \"%s\"\n", XmlNode_getLine(root), token, xml->fileName); } } - else { - ModelicaFormatError("Error in line %i: Cannot read int value from file \"%s\"\n", + else if (NULL != root) { + ModelicaFormatMessage("Error in line %i: Cannot read int value from file \"%s\"\n", XmlNode_getLine(root), xml->fileName); + *exist = 0; + } + else { + *exist = 0; } } + else { + *exist = 0; + } return (int)ret; } @@ -219,7 +241,7 @@ void ED_getDoubleArray1DFromXML(void* _xml, const char* varName, double* a, size XmlNodeRef root = xml->root; int iLevel = 0; char* token = findValue(&root, varName, xml->fileName); - while (token == NULL && XmlNode_getChildCount(root) > 0) { + while (NULL == token && NULL != root && XmlNode_getChildCount(root) > 0) { /* Try children if root is empty */ root = XmlNode_getChild(root, 0); XmlNode_getValue(root, &token); @@ -298,7 +320,7 @@ void ED_getDoubleArray1DFromXML(void* _xml, const char* varName, double* a, size ModelicaError("Memory allocation error\n"); } } - else { + else if (NULL != root) { ModelicaFormatError("Error in line %i: Cannot read empty element \"%s\" in file \"%s\"\n", XmlNode_getLine(root), varName, xml->fileName); } diff --git a/ExternData/Resources/Include/ED_INIFile.h b/ExternData/Resources/Include/ED_INIFile.h index 8384df6a..174f5536 100644 --- a/ExternData/Resources/Include/ED_INIFile.h +++ b/ExternData/Resources/Include/ED_INIFile.h @@ -31,8 +31,8 @@ void* ED_createINI(const char* fileName, int verbose); void ED_destroyINI(void* _ini); -double ED_getDoubleFromINI(void* _ini, const char* varName, const char* section, int strict); -const char* ED_getStringFromINI(void* _ini, const char* varName, const char* section); -int ED_getIntFromINI(void* _ini, const char* varName, const char* section, int strict); +double ED_getDoubleFromINI(void* _ini, const char* varName, const char* section, int strict, int* exist); +const char* ED_getStringFromINI(void* _ini, const char* varName, const char* section, int* exist); +int ED_getIntFromINI(void* _ini, const char* varName, const char* section, int strict, int* exist); #endif diff --git a/ExternData/Resources/Include/ED_JSONFile.h b/ExternData/Resources/Include/ED_JSONFile.h index ec0bc64c..26a08788 100644 --- a/ExternData/Resources/Include/ED_JSONFile.h +++ b/ExternData/Resources/Include/ED_JSONFile.h @@ -31,19 +31,19 @@ void* ED_createJSON(const char* fileName, int verbose); void ED_destroyJSON(void* _json); -double ED_getDoubleFromJSON(void* _json, const char* varName); -const char* ED_getStringFromJSON(void* _json, const char* varName); -int ED_getIntFromJSON(void* _json, const char* varName); -int ED_getBooleanFromJSON(void* _json, const char* varName); +double ED_getDoubleFromJSON(void* _json, const char* varName, int* exist); +const char* ED_getStringFromJSON(void* _json, const char* varName, int* exist); +int ED_getIntFromJSON(void* _json, const char* varName, int* exist); +int ED_getBooleanFromJSON(void* _json, const char* varName, int* exist); void ED_getArray1DDimensionFromJSON(void* _json, const char* varName, int* n); void ED_getArray2DDimensionsFromJSON(void* _json, const char* varName, int* m, int* n); -void ED_getDoubleArray1DFromJSON(void* _json, const char* varName, double* arr, size_t n); -void ED_getStringArray1DFromJSON(void* _json, const char* varName, char** arr, size_t n); -void ED_getIntArray1DFromJSON(void* _json, const char* varName, int* arr, size_t n); -void ED_getBooleanArray1DFromJSON(void* _json, const char* varName, int* arr, size_t n); -void ED_getDoubleArray2DFromJSON(void* _json, const char* varName, double* arr, size_t m, size_t n); -void ED_getStringArray2DFromJSON(void* _json, const char* varName, char** arr, size_t m, size_t n); -void ED_getIntArray2DFromJSON(void* _json, const char* varName, int* arr, size_t m, size_t n); -void ED_getBooleanArray2DFromJSON(void* _json, const char* varName, int* arr, size_t m, size_t n); +void ED_getDoubleArray1DFromJSON(void* _json, const char* varName, double* a, size_t n); +void ED_getStringArray1DFromJSON(void* _json, const char* varName, char** a, size_t n); +void ED_getIntArray1DFromJSON(void* _json, const char* varName, int* a, size_t n); +void ED_getBooleanArray1DFromJSON(void* _json, const char* varName, int* a, size_t n); +void ED_getDoubleArray2DFromJSON(void* _json, const char* varName, double* a, size_t m, size_t n); +void ED_getStringArray2DFromJSON(void* _json, const char* varName, char** a, size_t m, size_t n); +void ED_getIntArray2DFromJSON(void* _json, const char* varName, int* a, size_t m, size_t n); +void ED_getBooleanArray2DFromJSON(void* _json, const char* varName, int* a, size_t m, size_t n); #endif diff --git a/ExternData/Resources/Include/ED_XLSFile.h b/ExternData/Resources/Include/ED_XLSFile.h index e4520e3e..df5e416c 100644 --- a/ExternData/Resources/Include/ED_XLSFile.h +++ b/ExternData/Resources/Include/ED_XLSFile.h @@ -31,9 +31,9 @@ void* ED_createXLS(const char* fileName, const char* encoding, int verbose); void ED_destroyXLS(void* _xls); -double ED_getDoubleFromXLS(void* _xls, const char* cellAddress, const char* sheetName); -const char* ED_getStringFromXLS(void* _xls, const char* cellAddress, const char* sheetName); -int ED_getIntFromXLS(void* _xls, const char* cellAddress, const char* sheetName); +double ED_getDoubleFromXLS(void* _xls, const char* cellAddress, const char* sheetName, int* exist); +const char* ED_getStringFromXLS(void* _xls, const char* cellAddress, const char* sheetName, int* exist); +int ED_getIntFromXLS(void* _xls, const char* cellAddress, const char* sheetName, int* exist); void ED_getDoubleArray2DFromXLS(void* _xls, const char* cellAddress, const char* sheetName, double* a, size_t m, size_t n); #endif diff --git a/ExternData/Resources/Include/ED_XLSXFile.h b/ExternData/Resources/Include/ED_XLSXFile.h index 2c262e08..46aa9ae3 100644 --- a/ExternData/Resources/Include/ED_XLSXFile.h +++ b/ExternData/Resources/Include/ED_XLSXFile.h @@ -31,9 +31,9 @@ void* ED_createXLSX(const char* fileName, int verbose); void ED_destroyXLSX(void* _xlsx); -double ED_getDoubleFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName); -const char* ED_getStringFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName); -int ED_getIntFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName); +double ED_getDoubleFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName, int* exist); +const char* ED_getStringFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName, int* exist); +int ED_getIntFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName, int* exist); void ED_getDoubleArray2DFromXLSX(void* _xlsx, const char* cellAddress, const char* sheetName, double* a, size_t m, size_t n); #endif diff --git a/ExternData/Resources/Include/ED_XMLFile.h b/ExternData/Resources/Include/ED_XMLFile.h index 27689738..2232b369 100644 --- a/ExternData/Resources/Include/ED_XMLFile.h +++ b/ExternData/Resources/Include/ED_XMLFile.h @@ -32,9 +32,9 @@ void* ED_createXML(const char* fileName, int verbose); void ED_destroyXML(void* _xml); -double ED_getDoubleFromXML(void* _xml, const char* varName); -const char* ED_getStringFromXML(void* _xml, const char* varName); -int ED_getIntFromXML(void* _xml, const char* varName); +double ED_getDoubleFromXML(void* _xml, const char* varName, int* exist); +const char* ED_getStringFromXML(void* _xml, const char* varName, int* exist); +int ED_getIntFromXML(void* _xml, const char* varName, int* exist); void ED_getDoubleArray1DFromXML(void* _xml, const char* varName, double* a, size_t n); void ED_getDoubleArray2DFromXML(void* _xml, const char* varName, double* a, size_t m, size_t n); diff --git a/ExternData/package.mo b/ExternData/package.mo index 5dd44430..735b7823 100644 --- a/ExternData/package.mo +++ b/ExternData/package.mo @@ -306,7 +306,7 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc input String section="" "Section"; input Types.ExternINIFile ini "External INI file object"; input Boolean strict=true "Return an error if there are characters on the line that aren't part of the value"; - external "C" y=ED_getDoubleFromINI(ini, varName, section, strict) annotation( + external "C" y=ED_getDoubleFromINI(ini, varName, section, strict, exist) annotation( __iti_dll = "ITI_ED_INIFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_INIFile.h\"", @@ -324,7 +324,7 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc input String section="" "Section"; input Types.ExternINIFile ini "External INI file object"; input Boolean strict=true "Return an error if there are characters on the line that aren't part of the value"; - external "C" y=ED_getIntFromINI(ini, varName, section, strict) annotation( + external "C" y=ED_getIntFromINI(ini, varName, section, strict, exist) annotation( __iti_dll = "ITI_ED_INIFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_INIFile.h\"", @@ -342,8 +342,11 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc input String section="" "Section"; input Types.ExternINIFile ini "External INI file object"; input Boolean strict=true "Return an error if there are characters on the line that aren't part of the value"; + protected + Real aux; algorithm - y := getReal(ini=ini, varName=varName, section=section, strict=strict) <> 0; + (aux, exist) := getReal(ini=ini, varName=varName, section=section, strict=strict); + y := aux <> 0; annotation(Inline=true); end getBoolean; @@ -351,7 +354,7 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc extends Interfaces.partialGetString; input String section="" "Section"; input Types.ExternINIFile ini "External INI file object"; - external "C" str=ED_getStringFromINI(ini, varName, section) annotation( + external "C" str=ED_getStringFromINI(ini, varName, section, exist) annotation( __iti_dll = "ITI_ED_INIFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_INIFile.h\"", @@ -365,7 +368,7 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc function getReal "Get scalar Real value from JSON file" extends Interfaces.partialGetReal; input Types.ExternJSONFile json "External JSON file object"; - external "C" y=ED_getDoubleFromJSON(json, varName) annotation( + external "C" y=ED_getDoubleFromJSON(json, varName, exist) annotation( __iti_dll = "ITI_ED_JSONFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_JSONFile.h\"", @@ -402,7 +405,7 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc function getInteger "Get scalar Integer value from JSON file" extends Interfaces.partialGetInteger; input Types.ExternJSONFile json "External JSON file object"; - external "C" y=ED_getIntFromJSON(json, varName) annotation( + external "C" y=ED_getIntFromJSON(json, varName, exist) annotation( __iti_dll = "ITI_ED_JSONFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_JSONFile.h\"", @@ -476,7 +479,7 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc function getString "Get scalar String value from JSON file" extends Interfaces.partialGetString; input Types.ExternJSONFile json "External JSON file object"; - external "C" str=ED_getStringFromJSON(json, varName) annotation( + external "C" str=ED_getStringFromJSON(json, varName, exist) annotation( __iti_dll = "ITI_ED_JSONFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_JSONFile.h\"", @@ -604,7 +607,8 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc input String sheetName="" "Sheet name"; input Types.ExternXLSFile xls "External Excel XLS file object"; output Real y "Real value"; - external "C" y=ED_getDoubleFromXLS(xls, cellAddress, sheetName) annotation( + output Boolean exist "= true, if cellAddress exits; = false, if it does not exist and y is set to 0.0"; + external "C" y=ED_getDoubleFromXLS(xls, cellAddress, sheetName, exist) annotation( __iti_dll = "ITI_ED_XLSFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_XLSFile.h\"", @@ -632,7 +636,8 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc input String sheetName="" "Sheet name"; input Types.ExternXLSFile xls "External Excel XLS file object"; output Integer y "Integer value"; - external "C" y=ED_getIntFromXLS(xls, cellAddress, sheetName) annotation( + output Boolean exist "= true, if cellAddress exits; = false, if it does not exist and y is set to 0"; + external "C" y=ED_getIntFromXLS(xls, cellAddress, sheetName, exist) annotation( __iti_dll = "ITI_ED_XLSFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_XLSFile.h\"", @@ -645,8 +650,12 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc input String sheetName="" "Sheet name"; input Types.ExternXLSFile xls "External Excel XLS file object"; output Boolean y "Boolean value"; + output Boolean exist "= true, if cellAddress exits; = false, if it does not exist and y is set to false"; + protected + Real aux; algorithm - y := getReal(xls=xls, cellAddress=cellAddress, sheetName=sheetName) <> 0; + (aux, exist) := getReal(xls=xls, cellAddress=cellAddress, sheetName=sheetName); + y := aux <> 0; annotation(Inline=true); end getBoolean; @@ -656,7 +665,8 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc input String sheetName="" "Sheet name"; input Types.ExternXLSFile xls "External Excel XLS file object"; output String str "String value"; - external "C" str=ED_getStringFromXLS(xls, cellAddress, sheetName) annotation( + output Boolean exist "= true, if cellAddress exits; = false, if it does not exist and y is set to an empty string"; + external "C" str=ED_getStringFromXLS(xls, cellAddress, sheetName, exist) annotation( __iti_dll = "ITI_ED_XLSFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_XLSFile.h\"", @@ -673,7 +683,8 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc input String sheetName="" "Sheet name"; input Types.ExternXLSXFile xlsx "External Excel XLSX file object"; output Real y "Real value"; - external "C" y=ED_getDoubleFromXLSX(xlsx, cellAddress, sheetName) annotation( + output Boolean exist "= true, if cellAddress exits; = false, if it does not exist and y is set to 0.0"; + external "C" y=ED_getDoubleFromXLSX(xlsx, cellAddress, sheetName, exist) annotation( __iti_dll = "ITI_ED_XLSXFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_XLSXFile.h\"", @@ -701,7 +712,8 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc input String sheetName="" "Sheet name"; input Types.ExternXLSXFile xlsx "External Excel XLSX file object"; output Integer y "Integer value"; - external "C" y=ED_getIntFromXLSX(xlsx, cellAddress, sheetName) annotation( + output Boolean exist "= true, if cellAddress exits; = false, if it does not exist and y is set 0"; + external "C" y=ED_getIntFromXLSX(xlsx, cellAddress, sheetName, true) annotation( __iti_dll = "ITI_ED_XLSXFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_XLSXFile.h\"", @@ -714,8 +726,12 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc input String sheetName="" "Sheet name"; input Types.ExternXLSXFile xlsx "External Excel XLSX file object"; output Boolean y "Boolean value"; + output Boolean exist "= true, if cellAddress exits; = false, if it does not exist and y is set to false"; + protected + Real aux; algorithm - y := getReal(xlsx=xlsx, cellAddress=cellAddress, sheetName=sheetName) <> 0; + (aux, exist) := getReal(xlsx=xlsx, cellAddress=cellAddress, sheetName=sheetName); + y := aux <> 0; annotation(Inline=true); end getBoolean; @@ -725,7 +741,8 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc input String sheetName="" "Sheet name"; input Types.ExternXLSXFile xlsx "External Excel XLSX file object"; output String str "String value"; - external "C" str=ED_getStringFromXLSX(xlsx, cellAddress, sheetName) annotation( + output Boolean exist "= true, if cellAddress exits; = false, if it does not exist and y is set to an empty string"; + external "C" str=ED_getStringFromXLSX(xlsx, cellAddress, sheetName, exist) annotation( __iti_dll = "ITI_ED_XLSXFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_XLSXFile.h\"", @@ -739,7 +756,7 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc function getReal "Get scalar Real value from XML file" extends Interfaces.partialGetReal; input Types.ExternXMLFile xml "External XML file object"; - external "C" y=ED_getDoubleFromXML(xml, varName) annotation( + external "C" y=ED_getDoubleFromXML(xml, varName, exist) annotation( __iti_dll = "ITI_ED_XMLFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_XMLFile.h\"", @@ -776,7 +793,7 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc function getInteger "Get scalar Integer value from XML file" extends Interfaces.partialGetInteger; input Types.ExternXMLFile xml "External XML file object"; - external "C" y=ED_getIntFromXML(xml, varName) annotation( + external "C" y=ED_getIntFromXML(xml, varName, exist) annotation( __iti_dll = "ITI_ED_XMLFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_XMLFile.h\"", @@ -786,15 +803,18 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc function getBoolean "Get scalar Boolean value from XML file" extends Interfaces.partialGetBoolean; input Types.ExternXMLFile xml "External XML file object"; + protected + Real aux; algorithm - y := getReal(xml=xml, varName=varName) <> 0; + (aux, exist) := getReal(xml=xml, varName=varName); + y := aux <> 0; annotation(Inline=true); end getBoolean; function getString "Get scalar String value from XML file" extends Interfaces.partialGetString; input Types.ExternXMLFile xml "External XML file object"; - external "C" str=ED_getStringFromXML(xml, varName) annotation( + external "C" str=ED_getStringFromXML(xml, varName, exist) annotation( __iti_dll = "ITI_ED_XMLFile.dll", __iti_dllNoExport = true, Include = "#include \"ED_XMLFile.h\"", @@ -811,24 +831,28 @@ package ExternData "Library for data I/O of CSV, INI, JSON, MATLAB MAT, TIR, Exc extends Modelica.Icons.Function; input String varName "Key"; output Real y "Real value"; + output Boolean exist "= true, if varName exits; = false, if it does not exist and y is set to 0.0"; end partialGetReal; partial function partialGetInteger extends Modelica.Icons.Function; input String varName "Key"; output Integer y "Integer value"; + output Boolean exist "= true, if varName exits; = false, if it does not exist and y is set to 0"; end partialGetInteger; partial function partialGetBoolean extends Modelica.Icons.Function; input String varName "Key"; output Boolean y "Boolean value"; + output Boolean exist "= true, if varName exits; = false, if it does not exist and y is set to false"; end partialGetBoolean; partial function partialGetString extends Modelica.Icons.Function; input String varName "Key"; output String str "String value"; + output Boolean exist "= true, if varName exits; = false, if it does not exist and str is set to a an empty string"; end partialGetString; end Interfaces;