ssWriteRTWParamSettings
Write values of nontunable parameters to the
filemodel.rtw
Syntax
int_T ssWriteRTWParamSettings(SimStruct *S, int_T nParamSettings, int_T paramType, const char_T *settingName, ...)
Arguments
SSimStruct that represents an S-Function block.
nParamSettingsNumber of parameter settings.
paramTypeType of parameter (see Parameter Setting Type-Specific Arguments).
settingNameName of the parameter.
...Remaining arguments depend on the parameter type (see Parameter Setting Type-Specific Arguments).
Returns
An int_T (1 or 0) or
boolean_T (true or
false) indicating the success or failure of the
function.
Description
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
Parameter Setting Type-Specific Arguments
This section lists the parameter-specific arguments required by each parameter type.
SSWRITE_VALUE_STR(unquoted character vector): UseSSWRITE_VALUE_STRfor any single word character vector that does not begin with a number or contain mixed characters. In some cases,ssWriteRTWParamSettingsencloses the character vector in quotation marks even though you usedSSWRITE_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,ssWriteRTWParamSettingsuses quotation marks to maintain the value of the character vector.Argument Description const char_T *valueCharacter vector (e.g., USA)SSWRITE_VALUE_QSTR(quoted character vector): UseSSWRITE_VALUE_QSTRfor 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 *valueCharacter vector (e.g., "U.S.A.")SSWRITE_VALUE_VECT_STR(vector of character vector): UseSSWRITE_VALUE_VECT_STRto write a vector of character vectors with each element enclosed in quotation marks.Argument Description const char_T *valueVector of character vectors (e.g., ["USA", "Mexico"])int_T nItemsInVectSize of the vector SSWRITE_VALUE_NUM(number): UseSSWRITE_VALUE_NUMto a write real, floating-point value.Argument Description const real_T valueNumber (e.g., 2)SSWRITE_VALUE_VECT(vector of numbers): UseSSWRITE_VALUE_VECTto a write real, floating-point vector of values.Argument Description const real_T *valueVector of numbers (e.g., [300, 100])int_T vectLenSize of the vector SSWRITE_VALUE_2DMAT(matrix of numbers): UseSSWRITE_VALUE_2DMATto a write real, floating-point 2-D matrix of values.Argument Description const real_T *valueMatrix of numbers (e.g.,
[[170, 130],[60, 40]])int_T nRowsNumber of rows in the matrix int_T nColsNumber of columns in the matrix SSWRITE_VALUE_DTYPE_NUM(data-typed number): UseSSWRITE_VALUE_DTYPE_NUMto write a complex value in Simulink format, or with a data type other than double.Argument Description const void *valueNumber (e.g., [3+4i])int_T dtInfoData type (see Specifying Data Type Info) SSWRITE_VALUE_DTYPE_VECT(data-typed vector): UseSSWRITE_VALUE_DTYPE_VECTto write a complex vector of values in Simulink format, or with a data type other than double.Argument Description const void *valueData-typed vector (e.g., [1+2i, 3+4i])int_T vectLenSize of the vector int_T dtInfoData type (see Specifying Data Type Info) SSWRITE_VALUE_DTYPE_2DMAT(data-typed matrix): UseSSWRITE_VALUE_DTYPE_2DMATto write a complex 2-D matrix of values in Simulink format, or with a data type other than double.Argument Description const void *valueMatrix (e.g., [1+2i 3+4i; 5 6])int_T nRowsNumber of rows in the matrix int_T nColsNumber of columns in the matrix int_T dtInfoData type (see Specifying Data Type Info) SSWRITE_VALUE_DTYPE_ML_VECTOR(data-typed MATLAB® vector): UseSSWRITE_VALUE_DTYPE_ML_VECTORto write the real and imaginary parts of a complex vector of values as separate arrays.SSWRITE_VALUE_DTYPE_ML_VECTORallows you to specify a data type for the vector.Argument Description const void *RValueReal component of the vector (e.g., [1 3])const void *IValueImaginary component of the vector
(e.g.,[2 5])int_T vectLenNumber of elements in the vector int_T dtInfoData type (see Specifying Data Type Info) SSWRITE_VALUE_DTYPE_ML_2DMAT(data-typed MATLAB matrix): UseSSWRITE_VALUE_DTYPE_ML_2DMATto write the real and imaginary parts of a complex 2-D matrix of values as separate matrices.SSWRITE_VALUE_DTYPE_ML_2DMATallows you to specify a data type for the values.Argument Description const void *RValueReal component of the matrix
(e.g.,[1 5 3 6])const void *IValueImaginary component of the matrix
(e.g.,[2 0 4 0])int_T nRowsNumber of rows in the matrix int_T nColsNumber of columns in the matrix int_T dtInfoData type (see Specifying Data Type Info)
Languages
C, C++
Examples
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
See Also
Version History
Introduced before R2006a