From 1be12b0db99faeaaa987c33d84969b50fef22b8d Mon Sep 17 00:00:00 2001 From: Adrian Buerger Date: Thu, 25 May 2017 10:15:22 +0200 Subject: [PATCH 1/4] If a parameter is a string that is not true or false and cannot be converted to a float, return the string value instead of throwing an error --- OMPython/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/OMPython/__init__.py b/OMPython/__init__.py index be815f04..8fd17dbf 100755 --- a/OMPython/__init__.py +++ b/OMPython/__init__.py @@ -944,7 +944,10 @@ def __getParameterValues(self, paraName = None): str_ = False self.pValuesList.append(str_) else: - self.pValuesList.append(float(str_)) + try: + self.pValuesList.append(float(str_)) + except ValueError: + self.pValuesList.append(str_) return self.pValuesList else: try: From a0473c6d626db471b128d1577372637689b9f8e4 Mon Sep 17 00:00:00 2001 From: Adrian Buerger Date: Thu, 25 May 2017 10:16:04 +0200 Subject: [PATCH 2/4] exit() is not defined, calling sys.exit() instead --- OMPython/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OMPython/__init__.py b/OMPython/__init__.py index 8fd17dbf..87129d97 100755 --- a/OMPython/__init__.py +++ b/OMPython/__init__.py @@ -1167,7 +1167,7 @@ def getSolutions(self, *varList):#12 resFile = "".join([self.modelName, res_mat]) if (not os.path.exists(resFile)): print ("Error: Result file does not exist") - exit() + sys.exit() else: if len(varList) == 0: #validSolution = ['time'] + self.__getInputNames() + self.__getContinuousNames() + self.__getParameterNames() From 7a2c6c4c58804dd5de7798b4176c554aee50f299 Mon Sep 17 00:00:00 2001 From: Adrian Buerger Date: Thu, 25 May 2017 10:44:49 +0200 Subject: [PATCH 3/4] throw an error if the results file does not exist instead of exiting the process --- OMPython/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OMPython/__init__.py b/OMPython/__init__.py index 87129d97..ea13d2e6 100755 --- a/OMPython/__init__.py +++ b/OMPython/__init__.py @@ -1166,8 +1166,7 @@ def getSolutions(self, *varList):#12 res_mat = '_res.mat' resFile = "".join([self.modelName, res_mat]) if (not os.path.exists(resFile)): - print ("Error: Result file does not exist") - sys.exit() + raise IOError("Result file does not exist") else: if len(varList) == 0: #validSolution = ['time'] + self.__getInputNames() + self.__getContinuousNames() + self.__getParameterNames() From 843a2e5b1674943e140c85ee5e9ca457b3d06611 Mon Sep 17 00:00:00 2001 From: Adrian Buerger Date: Sat, 27 May 2017 16:52:36 +0200 Subject: [PATCH 4/4] enable passing parameter types different from float --- OMPython/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OMPython/__init__.py b/OMPython/__init__.py index ea13d2e6..ad9a30d8 100755 --- a/OMPython/__init__.py +++ b/OMPython/__init__.py @@ -1396,7 +1396,8 @@ def __setValue(self, nameVal, namesList, valuesList, quantity, index): if l.changable == 'false': print ("!!! value cannot be set for " + n) else: - l.start = float(nameVal.get(n)) + # l.start = float(nameVal.get(n)) + l.start = nameVal.get(n) index_ = namesList.index(n) valuesList[index_] = l.start @@ -1405,7 +1406,8 @@ def __setValue(self, nameVal, namesList, valuesList, quantity, index): if paramVar.get('name') == str(n): c=paramVar.getchildren() for attr in c: - val = float(nameVal.get(n)) + # val = float(nameVal.get(n)) + val = nameVal.get(n) attr.set('start', str(val)) self.tree.write(self.xmlFile, encoding='UTF-8', xml_declaration=True) index = index + 1