Target Language Compiler | ![]() ![]() |
Understanding the model.rtw File
You need to understand the basic format of the model
.rtw
file if you are writing a TLC file for an S-function (i.e., inlining the S-function). You do not, however, need to know all the details about the model
.rtw
file. For the purpose of inlining an S-function, you only need to understand the concepts of the model
.rtw
file and how to access the information using the Target Language Compiler.
Items such as signal connectivity and obtaining input and output connections for your S-function are contained within the model
.rtw
file using mapping tables. Processing this information directly in the Target Language Compiler is difficult and will not remain compatible between releases of our tools. To simplify writing TLC files for S-functions and provide compatibility between, many library functions (which start with the prefix Lib
) are provided. For example to access your inputs to your S-function, you should use LibBlockInputSignal
.
When the Target Language Compiler calls the various functions that exist in your TLC file, the Block
record for your S-function will be scoped. In this case, you have access to the Parameters
and ParamSettings
records shown in the Block Type: S-Function section.
If your S-function has an mdlRTW
method, then you can control several fields within the Block
record. For example, you can use the function ssWriteRTWParamSettings
to have rtwgen
create a SFcnParameterSettings
record containing the "nontunable" (see ssSetSFcnParamTunable
in the Simulink book Writing S-Functions) parameter values in the Block
record for your S-function. There are several other functions available to mdlRTW
for adding information to the model
.rtw
file. See matlabroot
/simulink/src/sfuntmpl.doc
for more information.
In addition, there are many Target Language Compiler library functions available to help you inline S-functions. See Chapter 9, TLC Function Library Reference, for a complete list of Target Language Compiler library functions.
How TLC Operates on a Record File
To understand the format of the model
.rtw
file, you need to understand how the Target Language Compiler operates on a record (database) file, e.g., model
.rtw
. The model
.rtw
contains parameter value pairs, records, lists, default records, and parameter records.
An example of a parameter value pair (or field) is
SigLabel "velocity"
which specifies that the field (or variable) SigLabel
contains the value "velocity".
You can place this field in a record named Signal
with
Signal { SigLabel "velocity" }
Accessing Record Fields. To access fields within a record, use the dot
operator. For example, Signal.SignalLabel
accesses the signal label field of the Signal
record.
Changing Scope. You can change the local scope to any record in the Target Language Compiler using the with
directive. This allows for both relative and absolute scoping. The Target Language Compiler first checks for the item being accessed in the local scope; if the item is not there, it then searches the global name pool (global scope).
Creating a List. The Target Language Compiler creates a list by contacting several records. For example,
NumSignals 2 Signal { SigLabel "velocity" } Signal { SigLabel "position" }
This code creates a parameter called NumSignals
that specifies the length of the list. This is useful when using the foreach
directive. To access the second signal, use Signal[1]
. Note, the first index in a Target Language Compiler list is 0.
You can create a default record by appending the word Defaults
to the record name. For example,
SignalDefaults { ComplexSignal no } Signal { SigLabel "velocity" }
An access to the field Signal.ComplexSignal
returns no
. The Target Language Compiler first checks the Signal
record for the field (parameter) ComplexSignal
. Since it does not exist in this example, the Target Language Compiler searches for the field SignalDefaults.ComplexSignal
, which has the value no
. (If SignalDefaults.ComplexSignal
did not exist, it would generate an error.)
A parameter record is a record named Parameter
that contains, at a minimum, the fields Name
and Value
. The Target Language Compiler automatically promotes the parameter up one level and creates a new field containing Name
and Value
.
Block { Parameter { Name Velocity Value 10.0 } }
You can access the Velocity
parameter using Block.Velocity
. The value returned is 10.0.
![]() | model.rtw | General model.rtw Concepts | ![]() |