I have a Matlab script that I'm trying to convert to C++ (see below) because it is extremely slow. I'm a C++ newbie and to start I tried using codegen
but it doesn't work (I got the message ??? This text contains non-empty top-level expressions. It appears to be a script.)
Do you have any suggestion on how to start to convert the code? Also, what is the best C++ function to do the job of fitsread
?
Here is my code:
clear;
number_projections = 10;
imgs_per_proj = 2000; % Number of images per projection
% Lets load the reference images relative to the various wavelengths
R1 = zeros(imgs_per_proj, 512, 512);
R2 = zeros(imgs_per_proj, 512, 512);
l = 0;
for k = 1:imgs_per_proj
s = sprintf('Ref/R1_000_%05i.fits',k-1);
t = sprintf('Ref/R2_000_%05i.fits',k-1);
l = l + 1;
R1(l,:,:) = fitsread(s);
R2(l,:,:) = fitsread(t);
end
codegen
requires that the MATLAB code you're trying to convert be in a function and it seems you are trying to convert a script
However, even if you do that, fitsread
does not appear to be a supported function within codegen
. Here's a list of supported functions:
http://www.mathworks.com/help/simulink/ug/functions-supported-for-code-generation--alphabetical-list.html
There's no "built-in" function within C++ that's going to replace fitsread
- for that you need a library. There's a C++ FITS library called CCFits
that you can find here: http://heasarc.gsfc.nasa.gov/fitsio/CCfits/
They should have tutorials that you could follow.