Matlab return C call by reference

5 ビュー (過去 30 日間)
Kurt
Kurt 2023 年 2 月 21 日
回答済み: Kurt 2023 年 2 月 23 日
I am using a compiled C DLL library to compute various astronomical functions, for example time since epoch and ra/dec to az/el conversions. I figured out how to call these functions from Python, but Matlab is another matter. The call is of this form:
time_since_1950 = TimeFunc.TimeComps(c_int(year), c_int(dayOfYear), c_int(hour), c_int(minute), c_double(seconds));
Astro.RaDecToAzEl(c_double(time_since_1950), c_double(float(lat)), c_double(float(lon)), ...
c_double(RA), c_double(dec), byref(az), byref(el));
There are several issues here:
  1. Dot indexing is not supported for function calls
  2. c_int and c_double typecasting are not supported. Can I just replace these with Matlab int32 and double?
  3. RaDecToAzEl returns az and el by reference. I don't know how to make this work.
I have already defined my Matlab input arguments as int32 and double, as appropriate.
Is there a way to make this work with the existing C libraries?
  2 件のコメント
dpb
dpb 2023 年 2 月 21 日
I wonder if the following will be of any use ... <cpp-interface>
Kurt
Kurt 2023 年 2 月 21 日
I'll take a look. Thanks

サインインしてコメントする。

採用された回答

Kurt
Kurt 2023 年 2 月 23 日
The solution was to first load my Dynamic Link Libraries (DLLs).
Then the Matlab calls to my library functions look like this:
time_since_1950 = calllib('TimeFunc','TimeComps', year, dayOfYear, hour, minute, seconds);
azPtr = libpointer('doublePtr', az);
elPtr = libpointer('doublePtr', el);
calllib('Astro','RaDecToAzEl',time_since_1950, lat, lon, RA, dec, azPtr, elPtr);
az = azPtr.Value;
el = elPtr.Value;
Turns out, Matlab really CAN work with pointers to and from C code.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by