Target Language Compiler | ![]() ![]() |
Records
One of the constructs most relevant to generating code from the model
.rtw
file is a record. A record is very similar to a structure in C or a record in Pascal. The syntax of a record declaration is
where recVar
is the name of the variable that references this record while recType
is the record itself. fieldi
is a string and valuei
is the corresponding Target Language Compiler value. Record processing is summarized and illustrated in the tutorial Reading Record Files with TLC and in Processing model.rtw Files with TLC Scripts.
Records can have nested records, or subrecords, within them. The model
.rtw
file is essentially one large record, named CompiledModel
, containing levels of subrecords. Thus, a simple script that loops through a model and outputs the name of all blocks in the model would have the following form. The tutorial Processing model.rtw Files with TLC Scripts presents and discusses in detail the working of such a script.
%include "utillib.tlc" %selectfile STDOUT %with CompiledModel %foreach sysIdx = NumNonvirtSubsystems + 1 %assign ss = System[sysIdx] %with ss %foreach blkIdx = NumBlocks %assign block = Block[blkIdx] %<LibGetFormattedBlockPath(block)> %endforeach %endwith %endforeach %endwith
Unlike MATLAB, the Target Language Compiler requires that you explicitly load any function definitions not located in the same target file. In MATLAB, the line A = myfunc(B)
causes MATLAB to automatically search for and load an M-file or MEX-file named myfunc
. The Target Language Compiler, on the other hand, requires that you specifically include the file that defines the function. In this case, utillib.tlc
contains the definition of LibGetFormattedBlockPath
.
Like Pascal, the Target Language Compiler provides a %with
directive that facilitates using records. See Directives and Built-in Functions, for a detailed description of the directive and its associated scoping rules.
Note
model.rtw, describes in detail the current structure of the model .rtw file including all the field names and the interpretation of their values. The format and structure of this file are subject to change from one release of Real-Time Workshop to another.
|
A record read in from a file is not immutable. It is like any other record that you might declare in a program. In fact, the global CompiledModel
Real-Time Workshop record is modified many times during code generation. CompiledModel
is the global record in the model
.rtw
file. It contains all the variables necessary for code generation such as NumNonvirtSubsystems
, NumBlocks
, etc. It is also appended during code generation with many new variables, flags, and subrecords as needed.
Functions such as LibGetFormattedBlockPath
are provided in the Target Language Compiler libraries located in matlabroot
/rtw/c/tlc/lib/*.tlc
. For a complete list of available functions, refer to TLC Function Library Reference.
Assigning Values to Fields of Records
To assign a value to a field of a record you must use a qualified variable expression.
A qualified variable expression references a variable in one of the following forms:
![]() | Output Streams | Record Aliases | ![]() |