@@ -950,39 +950,39 @@ def getSolutions(self, varList=None, resultfile=None): # 12
950
950
>>> getSolutions(["Name1","Name2"],resultfile=""c:/a.mat"")
951
951
"""
952
952
if resultfile is None :
953
- resFile = self .resultfile . as_posix ()
953
+ result_file = self .resultfile
954
954
else :
955
- resFile = resultfile
955
+ result_file = pathlib . Path ( resultfile )
956
956
957
957
# check for result file exits
958
- if not os .path .exists (resFile ):
959
- raise ModelicaSystemError (f"Result file does not exist { resFile } " )
960
- resultVars = self .sendExpression (f'readSimulationResultVars("{ resFile } ")' )
958
+ if not result_file .is_file ():
959
+ raise ModelicaSystemError (f"Result file does not exist { result_file } " )
960
+
961
+ # get absolute path
962
+ result_file = result_file .absolute ()
963
+
964
+ result_vars = self .sendExpression (f'readSimulationResultVars("{ result_file .as_posix ()} ")' )
961
965
self .sendExpression ("closeSimulationResultFile()" )
962
966
if varList is None :
963
- return resultVars
967
+ return result_vars
964
968
965
969
if isinstance (varList , str ):
966
- if varList not in resultVars and varList != "time" :
967
- raise ModelicaSystemError (f"Requested data { repr (varList )} does not exist" )
968
- res = self .sendExpression (f'readSimulationResult("{ resFile } ", {{{ varList } }})' )
969
- npRes = np .array (res )
970
- self .sendExpression ("closeSimulationResultFile()" )
971
- return npRes
972
-
973
- if isinstance (varList , list ):
974
- for var in varList :
975
- if var == "time" :
976
- continue
977
- if var not in resultVars :
978
- raise ModelicaSystemError (f"Requested data { repr (var )} does not exist" )
979
- variables = "," .join (varList )
980
- res = self .sendExpression (f'readSimulationResult("{ resFile } ",{{{ variables } }})' )
981
- npRes = np .array (res )
982
- self .sendExpression ("closeSimulationResultFile()" )
983
- return npRes
984
-
985
- raise ModelicaSystemError ("Unhandled input for getSolutions()" )
970
+ var_list_checked = [varList ]
971
+ elif isinstance (varList , list ):
972
+ var_list_checked = varList
973
+ else :
974
+ raise ModelicaSystemError ("Unhandled input for getSolutions()" )
975
+
976
+ for var in var_list_checked :
977
+ if var == "time" :
978
+ continue
979
+ if var not in result_vars :
980
+ raise ModelicaSystemError (f"Requested data { repr (var )} does not exist" )
981
+ variables = "," .join (var_list_checked )
982
+ res = self .sendExpression (f'readSimulationResult("{ result_file .as_posix ()} ",{{{ variables } }})' )
983
+ np_res = np .array (res )
984
+ self .sendExpression ("closeSimulationResultFile()" )
985
+ return np_res
986
986
987
987
@staticmethod
988
988
def _strip_space (name ):
0 commit comments