Each .CALC record defines a calculated response. The format for the .CALC record is as follows:
.CALC name { calculation }
where 'name' is the name given by the user to the calculated response variable. The calculation is specified between a '{' and a '}'. A .CALC calculation is specified using Reverse Polish Notation (RPN) operators and a stack data structure. See the section on RPN for details of this syntax and of the CCICAP implementation.
.CALC calculations are performed during the circuit analysis and are processed in the order that they appear in the input file. .CALC calculations can refer to parameters (see the .PAR Record description); inputs (V or I elements); outputs (VM or AM elements); element values that are defined in the .CKT to .END section; and previously defined .CALC variables.
Calculations are performed in the natural units (volts, amps, etc.) and then converted to any requested output format such as dB or magnitude.
If an attempted calculation would result in an illegal operation (such as divide by 0.0) an error message is added to the ASCII output file and the calculated response is set to 0.0.
Examples:
.CALC Gm { Eout Iin / }
calculates the ratio of the variable 'Eout' to the variable 'Iin' and names the ratio 'Gm'. 'Eout' and 'Iin' must be requested inputs or outputs for the current analysis.
.CALC Watt { e45 i53 X }
calculates the product of the variables 'e45' and 'i53' and names the result 'Watt'. 'e45' and 'i53' must be requested inputs or outputs for the current analysis.
.CALC Wsqr { Watt Watt X }
calculates the square of the previously calculated Watt as Wsqr. Watt must be a unique variable name and must be defined as a .CALC variable before Wsqr is defined.
.CALC Gm { Icq Vt / }
calculates Gm from the variables Icq and Vt. If Vt represents the thermal voltage (k*T/q) it can be defined in a PAR record as follows:
.PAR Vt .0258
The value of Vt must be defined before it is used in the Gm calculation.
.CALC pwr1 { vr1 vr1 X r1 / }
calculates the power in element r1 as vr1 * vr1 / r1. The requested VM output element named vr1 would define the voltage across the specified resistor r1.