Multiple outputs using Legacy Toolbox

5 次查看(过去 30 天)
Hi, i'm currently working on a project and I have to create a s-function written in C language. I have multiple outputs (V, m, h & fm) and multiple inputs(q1, q2, qe & qo). Here's my main file:
#include "Reservoir.h"
#include <math.h>
double Reservoir(double q1,
double q2,
double qe,
double qo,
double *V,
double *m,
double *h,
double *fm)
{
*V = q1 + q2 + qe - qo;
*m = 1875.0 * q1 + 1667.0 * q2 + 1000.0 * qe - 1468.48 * qo;
*h = sqrt(*V + 1) - 1;
*fm = ((3000.0) * (1 - 1000.0)) / ((3000.0 - 1000.0) * (*m/*V))
}
And here's my header file :
#ifndef RESERVOIR_H_INCLUDED
#define RESERVOIR_H_INCLUDED
double Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm);
#endif // RESERVOIR_H_INCLUDED
I'M also working with Legacy Toolbox to generate a tlc file and the s-function. I'm using these lines to generate the s-function :
def = legacy_code('initialize')
def.SFunctionName = 'S_function1'
def.OutputFcnSpec = 'Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm)'
def.HeaderFiles = {'Reservoir.h'}
def.SourceFiles = {'main.c'}
legacy_code('sfcn_cmex_generate', def)
When i execute the last line, i receive this error :
Error using legacycode.LCT.legacyCodeImpl
Unrecognized elements in the function specification:
--> Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm)
Error in legacy_code (line 103)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
Thus, I was wondering what i've done wrong ? Thanks for your help.
  2 个评论
Jeremy
Jeremy 2023-3-31
running into a similar issue. unsure if the fix will be the same as I am incorporating a struct in the args as a simulink.bus obj, but legacy tool returns a successful import of that. Commenting in hope someone returns to this question.
Sabarish
Sabarish 2024-5-30
Try using this and see Reservoir(double u1, double u2, double u3, double u4, double u5, double u6, double u7, double u8); I met this isuue too. The reason is that the input parameters of function must be named to u1, u2 etc.Similar to output parameters, they must be named to y1. Hope this helps. Thanks.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by