Menu ▾ ▴

#885 pre-master-48: option commands in .control are applied at netlist parsing, last value wins for all analyses

v1.0 (example)
open
None
5
21 hours ago
21 hours ago
No

Description:
Since pre-master-48, option commands inside a .control section no longer take effect at the point where they are executed. They are already applied when the netlist is read, so all analyses in the control script run with the value of the last option command. Scripts that change options between analyses therefore give wrong results without any warning, for example to remove gmin from a result by a second run with doubled gmin.

Test case:

  • option in .control
    V1 a 0 -10
    D1 a 0 dm
    .model dm d is=1e-30
    .control
    op
    print i(V1)
    option gmin=3e-14
    op
    print i(V1)
    option gmin=5e-14
    op
    print i(V1)
    .endc
    .end

The diode is reverse biased with is=1e-30, so i(V1) = gmin * 10 V.

Expected (ngspice-47):

i(v1) = 1.000000e-11 (default gmin 1e-12)
i(v1) = 3.000000e-13
i(v1) = 5.000000e-13

Actual (pre-master-48):

i(v1) = 5.000000e-13
i(v1) = 5.000000e-13
i(v1) = 5.000000e-13

Probable cause:
inp_getopts() in src/frontend/options.c, branch for comfile == FALSE:

c
if ((ciprefix(".opt", dd->line) && !strchr(dd->line, '{')) || ciprefix("option", dd->line)) {

The added || ciprefix("option", dd->line) also collects the option ... command lines of the .control section and turns them into .options of the circuit. ngspice-47 only checked ciprefix(".opt", ...). Because the prefix test also matches options, that spelling is affected too.

Suggested fix:
Restrict the netlist branch to .option / .options again. If option without a dot is needed for seed=, cshunt= or rshunt=, handle only these keywords, as in the comfile branch, and exclude lines that belong to a .control section.

Discussion


Log in to post a comment.