Documentation

CslibFrontier.Languages.Electrical.NetlistText

Netlist text: a SPICE subset for linear circuits #

A reader (Cslib.Electrical.Text.parse) for the netlists of Cslib.Electrical.Netlist, in a subset of the SPICE netlist format, with one directive of its own (.probe, below). The format follows the ngspice manual [VAWN26] where the two overlap (§2.1.1 for the file structure, §2.1.3 for fields, numbers and node names, §2.4 for the title, .end and comment lines, §4.1 for the independent sources); the tests use node names of the form a schematic editor writes (/out, Net-_R1-Pad2_), but no exporter's actual output has been checked against this reader. An exported netlist is accepted only after its analysis and output lines (.tran, .ac, .save, .control blocks, …) are replaced by .probe lines.

The grammar #

The text is a list of lines, separated by \n; a line's words are separated by spaces, tabs or carriage returns, so leading and trailing blanks and \r\n line ends are allowed.

Nodes. The node 0 is the ground. Every other node name is numbered 1, 2, … in the order of first appearance on the element lines (positive, negative, then control nodes). Names are compared exactly, and a text with two distinct names that differ only in case is rejected, since ngspice does not distinguish them (§2.1.3.4). The name gnd (in any case) is rejected: ngspice reads it as the ground (§2.1.3.5). Node and element names consist of letters, digits and _ - / + . #, without //; two elements with the same name (up to case) are rejected.

Values are exact rationals: an optional sign, decimal digits, an optional fractional part .digits with at least one digit, an optional exponent e[sign]digits and an optional scale suffix, in either case, t (10¹²), g (10⁹), meg (10⁶), k (10³), m (10⁻³), u (10⁻⁶), n (10⁻⁹), p (10⁻¹²) or f (10⁻¹⁵) (§2.1.3.2). Thus 1.e2, 1. and .5 are rejected, and so are the suffixes mil and a. Nothing may follow the suffix: ngspice ignores trailing letters (§2.1.3.3), so that 1F is 10⁻¹⁵ there, and a unit written after a value is rejected rather than guessed.

Rejected. Every other line is rejected with a message, and nothing is silently omitted: other elements (diodes, transistors, subcircuit instances X, mutual inductances K, current-controlled sources F, H, behavioural sources B), every other directive (.include, .lib, .model, .subckt, .param, .options, analyses such as .tran or .ac), continuation lines (+), parameter expressions and malformed values. A netlist that parse accepts may still fail Cslib.Electrical.Netlist.check (a nonpositive R, C or L), and then no certificate is accepted for it.

Main definitions #

References #

Lines and words #

Whether c separates words: a space, a tab or a carriage return.

The pieces of cs between the characters satisfying p (with empty pieces).

The lines of a text.

The words of a line.

The lower-case form of a word.

Values #

The decimal digits at the front of cs, and the rest.

The value of decimal digits.

An optional sign: true for -.

The power of ten of a scale suffix (lower case).

The optional exponent e[sign]digits at the front of cs, and the rest. A trailing e without digits is left in the rest, where no suffix accepts it.

The optional fractional part .digits at the front of cs, and the rest. A . without digits is left in the rest, where no suffix accepts it.

A value: [sign] digits [. digits] [e [sign] digits] [suffix], exactly, with at least one digit before and (if there is a .) after the dot.

Cards #

A line of the text that describes part of the circuit, with node names not yet resolved.

  • element (name : List Char) (nodes : List (List Char)) (value : ℚ) (ac : Bool) : Card

    An element line: the name, the nodes (two, or four for a controlled source), the value and whether a source is an input port.

  • probeV (p q : List Char) : Card

    .probe v p q.

  • probeI (name : List Char) : Card

    .probe i name.

Whether c may occur in a name.

Whether w is a well-formed name: nonempty, of name characters, without // (which ngspice reads as the start of an end-of-line comment).

Whether w is a well-formed node name: a name other than gnd.

The number of nodes of an element with first letter c (lower case): 2 for R, C, L, V, I, 4 for G, E, and 0 (unsupported) otherwise.

Whether the element with first letter c (lower case) is an independent source.

The value of a source, [[dc] value] (0 if omitted), and the rest.

The value and input flag of a source: [[dc] value] [ac [1]].

A probe line, after .probe.

The cards of the lines after the title, up to the .end line, which must be present, alone on its line and followed by blank lines only.

Resolving names #

A netlist read from text: the circuit, its probes, and the names of its nodes 1, 2, … and of its branches, in order.

  • netlist : Netlist

    The circuit.

  • probes : List Probe

    The output probes.

  • nodeNames : List (List Char)

    The names of the nodes 1, …, netlist.nodes.

  • branchNames : List (List Char)

    The names of the branches, in order.

The node names of the element cards, in order of appearance, without the ground.

The number of node w in the table names (0 for the ground).

The element of an element card, with the nodes numbered by names and input port k if it is an input port.

The branches of the element cards, numbering the input ports in order.

The number of input ports among the cards.

The names of the element cards.

The probe of a probe card.

Whether a card is a probe card.

The probes of the probe cards.

Resolving the names of the cards.

The reader: the netlist described by a text, or the reason it is rejected. The first line is the title and is skipped.