<div dir="ltr">Hi all,<br>For my research, I have a dynamical model implemented as a Matlab file that I compile into .mex file through the codegen command.<br>In the dynamical model file, I need to query the position of the planets using spkezr. <br>Since mice comes as a precompiled MEX application, I can't use it within my matlab file, because that is not compatible with code generation.<br><br>My current workaround is as follows:<br><br>function [...] = dynamics(..)<br><br>    [...]<br><br>    % Include C files required for code generation <br>    coder.updateBuildInfo('addIncludePaths', '[...]\mice\include')<br>    coder.updateBuildInfo('addIncludePaths', '[...]\mice\src\cspice')<br>    libPriority = '';<br>    libPreCompiled = true;<br>    libLinkOnly = true;<br>    libName = 'cspice.lib';<br>    libPath = '[...]\mice\lib';<br>    coder.updateBuildInfo('addLinkObjects', libName, libPath, libPriority, libPreCompiled, libLinkOnly);<br>    coder.cinclude('[...]\mice\src\cspice\SpiceUsr.h')<br>    <br>    % Preallocate output<br>    starg = zeros(6, 1);<br>    lt = 0;<br><br>    % Query cspice<div>    coder.ceval('spkezr_c', [targ 0], et, [ref 0], [abcorr 0], [obs 0], coder.wref(starg), coder.wref(lt));<br>    <br>    [...]</div><div>end</div><div><br></div><div>The code above compiles successfully when using codegen and the .mex files produces the expected results, however there is a glaring issue: if an error is encountered within the spkezr_c call (e.g. kernels are not loaded, strings are incorrect, etc.) the entire Matlab application crashes without errors.<br>Is there any workaround that would allow me to fix this problem and keep using codegen to generate the .mex file?</div><div>Thanks!</div><div>Alex<br><br><br></div></div>