Target Language Compiler | ![]() ![]() |
Passing and Using a Parameter
As we described above, and as you demonstrated by using the built-in function GET_COMMAND_SWITCH(), you can use the MATLAB tlc
command to pass parameters from the command line to the TLC file being executed. The most general command switch is -a
, which assigns arbitrary variables. For example:
The result of passing this pair of strings via -a
is the same as declaring and initializing local variables in the file being executed (here, any.tlc
), i.e.,
Note that such variables need not be declared in the TLC file, and are available for use when set with -a
. However, errors result if the code assigns undeclared variables that are not specified by an -a
switch when invoking the file. Also note that (in contrast to the -r
switch) no space should separate -a
from the parameter being declared.
In the final section of this exercise, we provide a parameter to control whether or not the names of blocks are printed out. By default block names are listed, but are suppressed if the command line contains -alist=0
.
%include "utillib.tlc"
you need to check whether a list
parameter has been declared, via the intrinsic (built-in) function EXISTS()
. Should no list
variable exist, your program assigns one:
This code ensures that list
is defined and by default its value is TRUE
.
listrtw1.tlc
, except that the input filename is reported as well as the block and subsystem counts.
tlc -r f14a.rtw listrtw3.tlc
This yields the same results as you obtained with listrtw2.tlc
. Here is the output printed to the MATLAB command window:
*** SYSTEMS AND BLOCKS IN RECORDFILE [f14a.rtw] f14a/Aircraft Dynamics Model/Transfer Fcn.1 f14a/Aircraft Dynamics Model/Gain3 f14a/Aircraft Dynamics Model/Transfer Fcn.2 f14a/Aircraft Dynamics Model/Gain4 f14a/Aircraft Dynamics Model/Gain5 f14a/Aircraft Dynamics Model/Gain6 f14a/Aircraft Dynamics Model/Sum1 f14a/Aircraft Dynamics Model/Sum2 *** 8 blocks in system 1 f14a/Controller/Alpha-sensor Low-pass Filter f14a/Controller/Stick Prefilter f14a/Controller/Pitch Rate Lead Filter f14a/Controller/Gain2 f14a/Controller/Gain3 f14a/Controller/Sum1 f14a/Controller/Sum2 f14a/Controller/Gain f14a/Controller/Proportional plus integral compensator f14a/Controller/Sum *** 10 blocks in system 2 f14a/Dryden Wind Gust Models/Band-Limited White Noise/White Noise f14a/Dryden Wind Gust Models/Band-Limited White Noise/Gain f14a/Dryden Wind Gust Models/W-gust model f14a/Dryden Wind Gust Models/Q-gust model *** 4 blocks in system 3 f14a/Nz pilot calculation/Constant f14a/Nz pilot calculation/Derivative f14a/Nz pilot calculation/Derivative1 f14a/Nz pilot calculation/Gain1 f14a/Nz pilot calculation/Product f14a/Nz pilot calculation/Sum1 f14a/Nz pilot calculation/Gain2 *** 7 blocks in system 4 f14a/Actuator Model f14a/Dryden Wind Gust Models f14a/Gain f14a/Gain2 f14a/Gain1 f14a/Sum f14a/Aircraft Dynamics Model f14a/Gain5 f14a/alpha (rad) f14a/Nz pilot calculation f14a/Nz Pilot (g) f14a/Angle of Attack f14a/Pilot G force Scope f14a/Pilot f14a/Sum1 f14a/Stick Input f14a/Controller *** 17 blocks in system 5 *** recordfile [f14a.rtw] contains 46 blocks in 5 systems *** END LISTING
Congratulations! You have crafted several Target Language Compiler programs that access model
.rtw
files, and run them from the command line.
![]() | Listing Block Names | Inlining S-Functions with TLC | ![]() |