Main Content

model.rtw File and Scopes

The code generation software creates a model.rtw 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.

The generated model.rtw 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.

A model.rtw 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 as

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.

A record is specified as

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 model.rtw 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.

Scopes in the model.rtw File

Each record creates a new scope. The model.rtw file uses curly braces { and } to open and close records (or scopes). Using scopes, you can access values within the model.rtw file.

The scope in this example begins with CompiledModel. Use periods (.) to access values within particular scopes. The format of model.rtw is

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.

Related Topics