@@ -66,6 +66,33 @@ def zip_if_several(*params) -> tuple | list[tuple]:
6666 return zip (* params , strict = False )
6767 return [params ]
6868
69+ def __opaque_to_string (opaque ):
70+ """Extract java string from MATLABOpaque object.
71+
72+ Parameters
73+ ----------
74+ opaque : MATLABOpaque
75+ object containing java string.
76+
77+ Returns
78+ -------
79+ str
80+ string extracted from object.
81+
82+ Raises
83+ ------
84+ ValueError
85+ Raised if there is no java string array in the object.
86+ """
87+ entries = opaque [0 ]
88+ for entry in entries :
89+ if isinstance (entry , ndarray ):
90+ break
91+ else :
92+ raise ValueError ("No array in MatlabOpaque" )
93+
94+ return bytes (entry [7 :]).decode ("ascii" )
95+
6996 def read_param (names , constrs , values , fits ):
7097 """Read in a parameter list from the relevant keys, and fix constraints for non-fit parameters.
7198
@@ -217,11 +244,11 @@ def fix_invalid_constraints(name: str, constrs: tuple[float, float], value: floa
217244 # which is given as the byte data of a Java string; this consists of 7 metadata bytes (ignored)
218245 # and then the actual string characters (index [7:]) in ascii format (.decode("ascii"))
219246 if len (mat_project ["contrastNames" ]) == 1 and isinstance (mat_project ["contrastNames" ], MatlabOpaque ):
220- mat_project ["contrastNames" ] = bytes (mat_project ["contrastNames" ][ 0 ][ 3 ][ 7 :]). decode ( "ascii" )
247+ mat_project ["contrastNames" ] = __opaque_to_string (mat_project ["contrastNames" ])
221248 else :
222249 for i , contrast_name in enumerate (mat_project ["contrastNames" ]):
223250 if isinstance (contrast_name , MatlabOpaque ):
224- mat_project ["contrastNames" ][i ] = bytes (contrast_name [ 0 ][ 3 ][ 7 :]). decode ( "ascii" )
251+ mat_project ["contrastNames" ][i ] = __opaque_to_string (contrast_name )
225252
226253 # if just one contrast, resolNames is a string; fix that here
227254 if isinstance (mat_project ["resolNames" ], str ):
0 commit comments