[Spice_discussion] Query CSPICE within Matlab MEX dynamical model
Alex Pascarella
alexpascarella96 at gmail.com
Fri Apr 1 12:39:05 PDT 2022
Hi all,
For my research, I have a dynamical model implemented as a Matlab file that
I compile into .mex file through the codegen command.
In the dynamical model file, I need to query the position of the planets
using spkezr.
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.
My current workaround is as follows:
function [...] = dynamics(..)
[...]
% Include C files required for code generation
coder.updateBuildInfo('addIncludePaths', '[...]\mice\include')
coder.updateBuildInfo('addIncludePaths', '[...]\mice\src\cspice')
libPriority = '';
libPreCompiled = true;
libLinkOnly = true;
libName = 'cspice.lib';
libPath = '[...]\mice\lib';
coder.updateBuildInfo('addLinkObjects', libName, libPath, libPriority,
libPreCompiled, libLinkOnly);
coder.cinclude('[...]\mice\src\cspice\SpiceUsr.h')
% Preallocate output
starg = zeros(6, 1);
lt = 0;
% Query cspice
coder.ceval('spkezr_c', [targ 0], et, [ref 0], [abcorr 0], [obs 0],
coder.wref(starg), coder.wref(lt));
[...]
end
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.
Is there any workaround that would allow me to fix this problem and keep
using codegen to generate the .mex file?
Thanks!
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://naif.jpl.nasa.gov/pipermail/spice_discussion/attachments/20220401/f2d1f9c5/attachment-0001.html>
More information about the Spice_discussion
mailing list