If — Private/Subsystem Components
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)andu1(r,c)withend(column-major),true,false,abs,min,maxand 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#
| Fact | Value |
|---|---|
| registered type | Private/Subsystem_Components/If |
| family | Private/Subsystem_Components |
| solver environment class | ICoreBlock_0_Private_1_Subsystem_Components_2_If |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Private/Subsystem_Components/If/ICoreBlock_0_Private_1_Subsystem_Components_2_If.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Private/Subsystem_Components/If/ICoreBlock_0_Private_1_Subsystem_Components_2_If.h |
| default size on canvas | 90 × 80 px |
| ports at insert | 1 in, 2 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreDouble | u1 |
| 2 | out | ICoreDouble | if |
| 3 | out | ICoreDouble | else |
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 variable | Default | Simulink parameter |
|---|---|---|
Number of inputs | 1 | NumInputs |
If expression | u1 > 0 | IfExpression |
Elseif expressions | — | ElseIfExpressions |
Show else condition | Off%~%On~~On | ShowElse |
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.
Simulink bridge#
| support | Support::Both |
| Simulink path | simulink/Ports & Subsystems/If |
| port-count rule | PortsParam::ActionDriverPorts |
SampleTime parameter | yes |
| ICore config | Simulink parameter | Value translation |
|---|---|---|
Number of inputs | NumInputs | passes through |
If expression | IfExpression | passes through |
Elseif expressions | ElseIfExpressions | passes through |
Show else condition | ShowElse | On → 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.