model
.rtw
File
and Scopes
model
.rtwThe code generation software creates a
file
from your Simulink® model. A model
.rtw
file
is a partial representation of a model generated by the build process
for use by the Target Language Compiler. It describes blocks, inputs,
outputs, parameters, states, storage, and other model components and
properties from the corresponding model file.model
.rtw
The generated
file is input to the
Target Language Compiler. If you select Retain .rtw file from the Configuration Parameters > Code Generation pane, after building a model, you can view the
model
.rtw
file that was generated.model
.rtw
A
file
is implemented as an ASCII file of parameter-value pairs stored in
a hierarchy of records. A parameter name/parameter
value pair is specified asmodel
.rtw
ParameterName value
where ParameterName
(also called an identifier)
is the name of the TLC identifier and value
is
a string, scalar, vector, or matrix. For example, in the parameter
name/parameter value pair
NumDataOutputPorts 1
NumDataOutputPorts
is the identifier and
1 is its value.
RecordName { . . . }
A record contains parameter name/parameter value pairs and/or subrecords. For example, this record contains one parameter name/parameter value pair:
DataStores { NumDataStores 0 }
Note
The structure of the
file is
very likely to change between releases, which is a compelling reason to limit your access to
model
.rtw
to the library functions
documented under TLC Function Library Reference: Target Language Compiler. For additional information, see Exception to Using the Library Functions that Access model.rtw.model
.rtw
Scopes in the model
.rtw
File
model
.rtwEach record creates a new scope. The
file uses curly
braces model
.rtw{
and }
to open and close records (or scopes).
Using scopes, you can access values within the
file.model
.rtw
The scope in this example begins with CompiledModel
. Use periods (.
) to access
values within particular scopes. The format of
ismodel
.rtw
CompiledModel { Name "modelname" -- Example of a parameter-value ... pair (record field). System { -- There is one system for each nonvirtual subsystem. Block { -- Block records for each Type "S-Function" nonvirtual block in the system. Name "<S3>/S-Function" ... Parameter { Name "P1" Value Matrix(1,2) [[1, 2];] } ... Block { } } ... System { -- The last system is for the root of your model. }
For example, to access Name
within CompiledModel
,
you would use
CompiledModel.Name
Multiple records of the same name form a list where the index of the first record starts at 0. To access the above S-function block record, you would use
CompiledModel.System[0].Block[0]
To access the name field of this block, you would use
CompiledModel.System[0].Block[0].Name
To simplify this process, you can use the %with
directive, which
changes the current scope. For example:
%with CompiledModel.System[0].Block[0] %assign blockName = Name %endwith
blockName
will have the value
"<S3>/S-Function"
.
When inlining S-function blocks, your S-function block record is scoped as though the
above %with
directive was done. In an inlined .tlc
file, you should access fields without a fully qualified path.
The following code shows a more detailed scoping example where the
Block
record has several parameter-value pairs
(Type
, Name
, Identifier
, and so
on), and three subrecords, each called Parameter
.
Block
is a subrecord of System
, which is a subrecord
of CompiledModel
. Note that the parameter names in this file changes from
release to release.