Target Language Compiler    

Using the model.rtw File

You need to understand the format and structure of the model.rtw file if you are writing a TLC script for an S-function (i.e., inlining the S-function), or if you wish to generate code in a language other than C. Most users only need to know a few of the details about the model.rtw file. For example, to inline 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.

Information such as signal connectivity and obtaining input and output connections for your S-function is encoded within the model.rtw file using mapping tables. Processing this information directly in the Target Language Compiler is difficult and may be handled differently from one release of our tools to another. To simplify writing TLC scripts for S-functions, and to provide compatibility between releases, many TLC library functions (which start with the prefix Lib) are provided. For example to access your inputs to your S-function, you should use LibBlockInputSignal. See TLC Function Library Reference, for a complete list of Target Language Compiler library functions.

When the Target Language Compiler calls the various functions that exist in your TLC script, 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.c for more information.

To understand the format of the model.rtw file, you need to understand how the Target Language Compiler operates on the model.rtw record (database) file. The model.rtw contains parameter value pairs, records, lists, default records, and parameter records.

An example of a parameter value pair (also called a field) is

which specifies that the field (or variable) SigLabel contains the value "velocity". You can place this field in a record named Signal with

Accessing Record Fields.   To access fields within a record in a TLC script, use the dot (.) operator. For example, Signal.SigLabel 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 lets you use both relative and absolute scoping at will, similar to specifying files via absolute or relative pathnames. 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,

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 that TLC indexing is zero-based (the first index in a list is 0).

You can create a default record by appending the word Defaults to the record name. For example,

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.

For example,

You can access the Velocity parameter using Block.Velocity. The value returned is 10.0.


  model.rtw File Contents General model.rtw Concepts