Generated reference › If — Private/Subsystem Components
kind: generated#block#private-subsystem-components

If — Private/Subsystem Components

if else

Private/Subsystem_Components/If · 1 input / 2 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Description#

The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.

If

Control Systems / Ports And Subsystems

Chooses, each step, which one of the action subsystems it drives runs: the first output whose condition holds, in order, else the else output, else none. Simulink’s If block (BlockType=If). Each subsystem it drives holds an Action Port; the library’s Subsystem Templates hold a ready-made If Action Subsystem.

Ports

  • Inputs – Number of inputs of them, u1 … un, the names the conditions use.
  • Outputs – one for the If expression, one per Elseif expressions entry, and one more for else while Show else condition is On. Each drives the Action input of one action subsystem.

Parameters

  • Number of inputs – 1 (default).
  • If expression – a MATLAB-style scalar condition over u1 … un: ~, ~=, &&, ||, u1(k), arithmetic. u1 > 0 (default).
  • Elseif expressions – comma-separated, one output each; none by default. Every comma separates two expressions, as in Simulink, so a condition with a comma inside it (max(u1, u2) > 0, u1(2,1) > 0) belongs in the If expression; in this list it is refused by name.
  • Show else condition – On (default) gives the else output.

Notes

  • Each output drives exactly one action subsystem, through its Action input. The port counts are checked against the parameters before a run, by name.
  • It runs: each step the expressions are evaluated in order and the first true one's subsystem runs, or the else subsystem, or none. A nonzero value is true. The grammar is MATLAB's reduced to a scalar: arithmetic and ^, comparisons, ~, &, |, &&, ||, u1(k) and u1(r,c) with end (column-major), true, false, abs, min, max and a few more functions, and a name from the variables space. C syntax (!, !=, u1[2]), an input past n, an index out of range and a condition that is not one number are refused by name, with Simulink’s message ID – an If never vectorises.

Code export

All ten targets. Each step the generated code writes 1 on the output it chooses and 0 on the rest, and the action subsystem behind it runs under its guard. Python, MATLAB, Java, Rust, C++ and C carry the whole grammar, with the same rules as the simulation. VHDL, Verilog and SystemVerilog carry comparisons, ~, &, |, && and || over + and - of numbers and input elements; PLC-ST adds *, /, ^, abs, sqrt, exp, log, sin, cos, tan, min and max. An expression a target does not carry, and an index that depends on an input's value, are refused by name.

Simulink bridge

Both directions, as simulink/Ports & Subsystems/If. Number of inputs goes to NumInputs, If expression to IfExpression, Elseif expressions to ElseIfExpressions and Show else condition to ShowElse (On and Off to on and off). No parameter carries a port count: Simulink derives both lists from these four, and an import does the same. Simulink’s If knows abs, sqrt, exp, log, sin, cos, tan, floor, ceil, sign, mod and rem but not round, fix, min or max: a condition using one of those four still exports, and the export says, in its report and in the script, that Simulink will not compile it. "Sampling Time (s)" goes to SampleTime, as on every block.

Code facts#

FactValue
registered typePrivate/Subsystem_Components/If
familyPrivate/Subsystem_Components
solver environment classICoreBlock_0_Private_1_Subsystem_Components_2_If
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Private/Subsystem_Components/If/ICoreBlock_0_Private_1_Subsystem_Components_2_If.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Private/Subsystem_Components/If/ICoreBlock_0_Private_1_Subsystem_Components_2_If.h
default size on canvas90 × 80 px
ports at insert1 in, 2 out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDoubleu1
2outICoreDoubleif
3outICoreDoubleelse

Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.

Configuration variables#

Config variableDefaultSimulink parameter
Number of inputs1NumInputs
If expressionu1 > 0IfExpression
Elseif expressions—ElseIfExpressions
Show else conditionOff%~%On~~OnShowElse

Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.

supportSupport::Both
Simulink pathsimulink/Ports & Subsystems/If
port-count rulePortsParam::ActionDriverPorts
SampleTime parameteryes
ICore configSimulink parameterValue translation
Number of inputsNumInputspasses through
If expressionIfExpressionpasses through
Elseif expressionsElseIfExpressionspasses through
Show else conditionShowElseOn → on, Off → off

Caveat (shown to the user): Simulink's If block; its port lists follow its parameters on both sides (FEATURES_TO_ADD.md BF8.5).

Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h

Description vs code#

tools/docs/check_block_descriptions.py (P7.1) could not be run when this page was generated, so no verdict is shown. Run it yourself; a page cannot claim an agreement it did not measure.

The verdict above is tools/docs/check_block_descriptions.py (P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.

Sample results#

No sample run is committed for this block. Samples come from the headless harness (DOCS_PLAN.md P8.1) into docs/generated/samples/; until one exists this block's behaviour is witnessed by the parity and export-verification suites, not by a plot here.