User`s guide
Writing Wrapper S-Functions
4-11
Using an S-function wrapper to import algorithms in your Simulink model
means that the S-function serves as an interface that calls your C code
algorithmsfrom
mdlOutputs.S-functionwrappershavetheadvantagethatyou
can quickly integrate large stand-alone C code into your model without having
to make changes to the code.
This is an example of a model that includes an S-function wrapper.
Figure 4-1: An Example Model That Includes an S-Function Wrapper
There are two files asso ciatedwithwrapsfcn blo c k, the S-function wrapperan d
the C code that contains the algorithm. This is the S -function wrapper code for
this example, called
wrapsfcn.c:
#define S_FUNCTION_NAME wrapsfcn
#define S_FUNCTION_LEVEL 2
#include “simstruc.h”
extern real_T my_alg(real_T u);
/*
* mdlInitializeSizes - initialize the sizes array
*/
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams( S, 0); /*number of input arguments*/
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 1);
ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S,1)) return;
ssSetOutputPortWidth(S, 0, 1);
ssSetNumSampleTimes( S, 1);
}
Declare my_alg as
extern.