Write values of nontunable parameters to the
filemodel
.rtw
int_T ssWriteRTWParamSettings(SimStruct *S, int_T nParamSettings, int_T paramType, const char_T *settingName, ...)
S
SimStruct representing an S-Function block.
nParamSettings
Number of parameter settings.
paramType
Type of parameter (see Parameter Setting Type-Specific Arguments).
settingName
Name of the parameter.
...
Remaining arguments depend on the parameter type (see Parameter Setting Type-Specific Arguments).
An int_T
(1
or 0
) or
boolean_T
(true
or
false
) indicating the success or failure of the
function.
Use this function in mdlRTW
to write nontunable parameter
setting information to this S-function's
file. You can also use
this macro to write out other constant values required to generate code for this
S-function.model
.rtw
This section lists the parameter-specific arguments required by each parameter type.
SSWRITE_VALUE_STR
(unquoted character vector): Use
SSWRITE_VALUE_STR
for any single word character
vector that does not begin with a number or contain mixed characters. In
some cases, ssWriteRTWParamSettings
encloses the
character vector in quotation marks even though you used
SSWRITE_VALUE_STR
. For example, if the length of
the character vector causes the corresponding line in the model file to
wrap in the middle of the character vector,
ssWriteRTWParamSettings
uses quotation marks to
maintain the value of the character vector.
Argument | Description |
---|---|
const char_T *value | Character vector (e.g.,
USA ) |
SSWRITE_VALUE_QSTR
(quoted character vector): Use
SSWRITE_VALUE_QSTR
for any multi-word or mixed
character vector or for single word character vectors that begin with a
number. Code generation with the Simulink®
Coder™ product errors out if any beginning with a number is not
enclosed in quotation mark.
Argument | Description |
---|---|
const char_T *value | Character vector (e.g.,
"U.S.A." ) |
SSWRITE_VALUE_VECT_STR
(vector of character
vector): Use SSWRITE_VALUE_VECT_STR
to write a vector
of character vectors with each element enclosed in quotation
marks.
Argument | Description |
---|---|
const char_T *value | Vector of character vectors (e.g., ["USA",
"Mexico"] ) |
int_T nItemsInVect | Size of the vector |
SSWRITE_VALUE_NUM
(number): Use
SSWRITE_VALUE_NUM
to a write real, floating-point
value.
Argument | Description |
---|---|
const real_T value | Number (e.g., 2 ) |
SSWRITE_VALUE_VECT
(vector of numbers): Use
SSWRITE_VALUE_VECT
to a write real,
floating-point vector of values.
Argument | Description |
---|---|
const real_T *value | Vector of numbers (e.g., [300,
100] ) |
int_T vectLen | Size of the vector |
SSWRITE_VALUE_2DMAT
(matrix of numbers): Use
SSWRITE_VALUE_2DMAT
to a write real,
floating-point 2-D matrix of values.
Argument | Description |
---|---|
const real_T *value | Matrix of numbers (e.g.,
[[170, 130],[60, 40]] ) |
int_T nRows | Number of rows in the matrix |
int_T nCols | Number of columns in the matrix |
SSWRITE_VALUE_DTYPE_NUM
(data-typed number): Use
SSWRITE_VALUE_DTYPE_NUM
to write a complex value
in Simulink format, or with a data type other than double.
Argument | Description |
---|---|
const void *value | Number (e.g., [3+4i] ) |
int_T dtInfo | Data type (see Specifying Data Type Info) |
SSWRITE_VALUE_DTYPE_VECT
(data-typed vector): Use
SSWRITE_VALUE_DTYPE_VECT
to write a complex
vector of values in Simulink format, or with a data type other than double.
Argument | Description |
---|---|
const void *value | Data-typed vector (e.g., [1+2i,
3+4i] ) |
int_T vectLen | Size of the vector |
int_T dtInfo | Data type (see Specifying Data Type Info) |
SSWRITE_VALUE_DTYPE_2DMAT
(data-typed matrix): Use
SSWRITE_VALUE_DTYPE_2DMAT
to write a complex 2-D
matrix of values in Simulink format, or with a data type other than double.
Argument | Description |
---|---|
const void *value | Matrix (e.g., [1+2i 3+4i; 5
6] ) |
int_T nRows | Number of rows in the matrix |
int_T nCols | Number of columns in the matrix |
int_T dtInfo | Data type (see Specifying Data Type Info) |
SSWRITE_VALUE_DTYPE_ML_VECTOR
(data-typed
MATLAB® vector): Use
SSWRITE_VALUE_DTYPE_ML_VECTOR
to write the real
and imaginary parts of a complex vector of values as separate arrays.
SSWRITE_VALUE_DTYPE_ML_VECTOR
allows you to
specify a data type for the vector.
Argument | Description |
---|---|
const void *RValue | Real component of the vector (e.g., [1
3] ) |
const void *IValue | Imaginary component of the vector
(e.g., [2
5] ) |
int_T vectLen | Number of elements in the vector |
int_T dtInfo | Data type (see Specifying Data Type Info) |
SSWRITE_VALUE_DTYPE_ML_2DMAT
(data-typed
MATLAB matrix): Use
SSWRITE_VALUE_DTYPE_ML_2DMAT
to write the real
and imaginary parts of a complex 2-D matrix of values as separate
matrices. SSWRITE_VALUE_DTYPE_ML_2DMAT
allows you to
specify a data type for the values.
Argument | Description |
---|---|
const void *RValue | Real component of the matrix (e.g., [1 5 3 6] ) |
const void *IValue | Imaginary component of the matrix
(e.g., [2 0 4
0] ) |
int_T nRows | Number of rows in the matrix |
int_T nCols | Number of columns in the matrix |
int_T dtInfo | Data type (see Specifying Data Type Info) |
C, C++
See the S-function sfun_frmad.c
used in sfcndemo_frame
for a complete example that uses this
function. Running this model requires a DSP System Toolbox™ license.
This S-function begins with the following variable declarations associated with the S-function parameters.
/* Parameters */ enum {FCN_ARGC = 0, AMP_ARGC, FREQ_ARGC, TS_ARGC, FRMSIZE_ARGC, NOISAMP_ARGC, NOISFREQ_ARGC, NUM_ARGS}; #define FCN_ARG(S) (ssGetSFcnParam(S,FCN_ARGC)) #define AMP_ARG(S) (ssGetSFcnParam(S,AMP_ARGC)) #define FREQ_ARG(S) (ssGetSFcnParam(S,FREQ_ARGC)) #define TS_ARG(S) (ssGetSFcnParam(S,TS_ARGC)) #define FRMSIZE_ARG(S) (ssGetSFcnParam(S,FRMSIZE_ARGC)) #define NOISAMP_ARG(S) (ssGetSFcnParam(S,NOISAMP_ARGC)) #define NOISFREQ_ARG(S) (ssGetSFcnParam(S,NOISFREQ_ARGC)) #define GET_FRMSIZE(S) (mxGetPr(FRMSIZE_ARG(S)))[0]
The S-function's mdlRTW
function then uses
ssWriteRTWParamSettings
to write the S-function parameters to
the model
.rtw
file.
real_T noisA = mxGetPr(NOISAMP_ARG(S))[0]; real_T noisF = mxGetPr(NOISFREQ_ARG(S))[0]; real_T ts = mxGetPr(TS_ARG(S))[0]; int_T fcn = (int) (mxGetPr(FCN_ARG(S))[0]); int32_T fsize = mxGetPr(FRMSIZE_ARG(S))[0]; if (!ssWriteRTWParamSettings(S, 5, SSWRITE_VALUE_STR, "Function", (fcn == 1) ? "Constant" : "Sine", SSWRITE_VALUE_NUM, "Ts", ts, SSWRITE_VALUE_DTYPE_NUM, "FrameSize", &fsize, DTINFO(SS_INT32, COMPLEX_NO), SSWRITE_VALUE_NUM, "NoiseAmp", noisA, SSWRITE_VALUE_NUM, "NoiseFreq", noisF)) { return; /* An error occurred. */ }
When code is generated for the model, the Simulink
Coder product first writes a structure named
SFcnParamSettings
to the
model
.rtw
file based on the
information provided in the S-function's mdlRTW
method. In this
example, the resulting SFcnParamSettings
is:
SFcnParamSettings { Function Sine Ts 0.005 FrameSize 64 NoiseAmp 4.0 NoiseFreq 80.0 }
The S-function's Target Language Compiler file sfun_frmad.tlc
then accesses the S-function parameters using
the variable names in the SFcnParamSettings
structure. For
example:
%assign fnName = SFcnParamSettings.Function %assign frmSize = SFcnParamSettings.FrameSize %assign ts = SFcnParamSettings.Ts %assign noisA = SFcnParamSettings.NoiseAmp %assign noisF = SFcnParamSettings.NoiseFreq