GenerateCode
 Generate MATLAB(R) C S-Function code and a .m block script

 Calling Sequence GenerateCode(system, options)

Parameters

 system - module; Msim model options - (optional) equation(s) of the form name = value

Returns

 • none

Options

 • blockname : string
 Specifies the name of the generated block. Default is "MsimModel".
 • path : string
 Specifies the output directory for the generated files. Default is "kernelopts('homedir')".
 • inputs : list of functions
 Specifies system's input variables.
 • outputs : list of functions
 Specifies system's output variables.
 • params : list of equations
 Specifies values of system's parameters.
 • nosubs : true or false
 Specifies whether the parameters are entered as the original model names or the substituted names.  Default is false.
 • optimize =  one of the following: false, "subexpronly", "fast", true
 Specifies level of code optimization (false = None, true = Full).  Default is "subexpronly".
 • coniter = non negative integer
 Specifies constraint iteration count.  Default is 20, 100 for single precision.
 • contol = positive
 Specifies constraint tolerance.  Default is 1e-7, 1e-4 for single precision.
 • evtiter = positive integer
 Specifies maximum number of event iterations.  Default is 10.
 • evtproj = true of false
 Specifies use projection in events.  Default is true.
 • evthyst = non negative
 Specifies width of event hysteresis band.  Default is 1e-10, 1e-6 for single precision.
 • fixedstep = true or false
 Specifies whether to optimize the generated code for use with fixed-step integrators. If set to true, engine optimizes events handling, as well as relaxes the inconsistencies detection tolerance. Default is false.
 • reinitonfail = true or false or hold
 Specifies whether to handle reinitialization of the model on failure.
 – Specification of true will reinitialize the model to the initial values when a failure occurs, while specification of hold will reinitialize the model to the values at the end of the last successful step.
 – When specified as true or hold, the engine will add one input, ForceReinit(t), and one output, ReinitCode(t), to the generated Simulink® block. These are generally added as the last input and the last output to the block. If diagnosticinfo option below is set to true then the ReinitCode(t) becomes the second-last output.
 – The ForceReinit(t) is a floating point input that will force a reinitialization of the model (which reinitializes all variables, except time to their starting values) whenever it's value becomes nonzero.
 – The ReinitCode(t) output is an integer-valued float that has the value zero if no reinitialization is being performed, and has the following values otherwise:
 • 1.0 - user-specified reinitialization (via setting ForceReinit(t) to a nonzero value),
 • 2.0 - index-1 variable/derivative evaluation failure,
 • -3.0 - if the event iteration limit is exceeded, the lowest energy level solution (computed as the 2-norm of the index-1 variables) for the last 3 iterations is used to continue the integration. Note that the negative error code indicates that the no full reinitialization has been performed.
 • 4.0 - an undefined value is encountered during event processing,
 • 5.0 - fatal constraint projection failure,
 • 6.0 - ignored terminate (includes the case when invalid configuration is reached).
 – Note that a user can force a conditional reinitialization in their model by specifying a terminate when a reinitialization is desired.
 – If the Simulink® inputs/outputs are grouped into vectors, then the reinitialization input/output is automatically put into a group with the same name as the input/output.
 – This option is only available for Simulink® fixed-step integration.
 Default is false.
 • diagnosticinfo = true or false
 Specifies whether to provide run-time diagnostics in the generated Simulink® block.
 – When specified as true, engine will add four (4) outputs to the bottom of the Simulink® block, LogStepSize(t), EventIterations(t), ConstraintIterations(t) and ConstraintResidual(t), in that order. These will be added after ReinitCode(t), if present (see option reinitonfail above).
 – Note that if the Simulink® inputs/outputs are grouped into vectors, these outputs will be placed in the group DiagnosticInfo.
 – This option will be available for both, Simulink® fixed-step integrators, and for Simulink® variable-step integrators, and in the latter case, will report on the maximum of the value obtained since the last output point.
 Default is false.
 • baumgarte : list
 Specifies derivative (alpha) and proportional (beta) gains for Baumgarte constraint stabilization in the form baumgarte=[alpha,beta]. If this parameter is set to the empty list, the Baumgarte constraint stabilization is not carried out.
 • discretize = true or false
 Specifies whether to export as a discrete model (no continuous states).  Default is false.
 • allowintermediatesteps = false or a list of [num::non negative integer, tol::positive number]
 If the discretize option above is set to true, and the solver option is set to either "Euler", or "ImplicitEuler", this option specifies that events should be triggered inside a fixed step, by taking at most num internal steps, which are taken according to the following methodology: If the stepsize is h, then if an event occurrence is estimated at r*h (0 < r <1), step to (r+tol)*h. Note an optimal value of tol is dependent on the model behaviour.  If the behaviour of the solution between steps is fairly linear, then the small value of tol (e.g. 1e-7) can be used to get accurate event crossings.  If the solution is far from linear, then a larger value of tol (e.g. 1e-2) will be required to ensure that the event trigger process before (r+tol)*h. If the value of this option is set to false, then all events that occur in a step will be triggered at the end of the step. Default is false.
 • solver = one of the following: "Euler", "RK2", "RK3", "RK4", "ImplicitEuler"
 If discretize option above is set to true, specifies which external solver to be included in the exported discrete model.  Default is "Euler".
 • timestep = non negative
 If discretize option above is set to true, specifies the exported model's discrete timestep. Default is 1e-3.
 • inpnumdiff = true or false
 Specifies whether to use numeric derivatives for inputs.  Default is false.
 • addoutputs = one of the following: "none", "states", "statevals", "continuous", "all"
 Specifies which additional variables need to be included in outputs.  Default is "none".
 • scriptparameters = true or false
 Specifies whether an additional parameters' initialization .m script should be generated. Default is false.
 • splitparameters = true or false
 Specifies whether, on a S-function mask/dialog box, parameters should be spplit into individual entities. Default is false (i.e. all parameters are kept in a list).
 • singleprec = true or false
 Specifies whether the S-function code should be generated to work with single precision floating point. Note that when this is set, all tolerances are loosened to work with the lower precision, which can result in accuracy degredation when compared with double precision. Default is false.

Description

 • The GenerateCode command generates Simulink(R) block component code from a MapleSim system.