The .IF / .ELSE / .ENDIF statements provide conditional inclusion of netlist sections based on parameter expressions evaluated at parse time.
.IF (<condition>)
...statements included when condition is true...
.ELSE
...statements included when condition is false...
.ENDIF
The .ELSE block is optional.
.PARAM use_fast=1
.IF (use_fast == 1)
R1 IN OUT 100
.ELSE
R1 IN OUT 10k
.ENDIF
.IF chooses which netlist statements exist before circuit setup. It does not
stamp MNA directly.
The selected branch can still change the matrix. For example, choosing a resistor value changes a conductance stamp; including or excluding a capacitor changes whether transient integration history exists for that node.
.PARAM add_cap=1
.IF (add_cap > 0)
C1 OUT 0 100p
.ENDIF
.PARAM version=2
.IF (version == 1)
.INCLUDE "model_v1.lib"
.ELSE
.INCLUDE "model_v2.lib"
.ENDIF
The condition can use any expression that evaluates to a numeric value:
- Non-zero = true
- Zero = false
Standard comparison operators (==, !=, >, <, >=, <=) and logical operators are supported.
- Conditions are evaluated at parse time using the current parameter values.
- The conditional blocks can contain any valid SPICE statements: components, models, subcircuits, analysis commands, etc.