#894 hs/spe binning: the pruner takes wnflag from the circuit loaded before (since faf926c6f)
Version: pre-master-48 8077acf20. ngspice-45.2 loads the deck below on x1:card.1.
Under hs and spe, doit() in subckt.c drops the .model cards of the bins that a size does not fit, and since faf926c6f it asks INPgetWnflag() which width to bin on. INPg
etWnflag() uses cp_getvar(), and when there is no variable wnflag, cp_getvar() goes on to the options of the current circuit. While a deck is being expanded its own cir
cuit does not exist yet, so that is the circuit loaded before it. INPgetModBin() runs later, when the new circuit is the current one, and does not see those options. Th
e two then bin on different widths and the load stops with "could not find a valid modelname".
It needs a session with two decks, the first with .option wnflag=0, and the variable wnflag absent when the second is read: after "unset wnflag", or when the first deck
was loaded with no compatibility mode and hs is set afterwards. So it is narrow; a program that keeps one ngspice running and loads deck after deck can get there.
2-wnflag-previous-circuit.cir (it sets ngbehavior itself, no .spiceinit needed):
wnflag is read from the circuit that was loaded before
.control
set ngbehavior=hsa
circbyline * first deck: .option wnflag=0
circbyline .option wnflag=0
circbyline v1 1 0 1
circbyline r1 1 0 1k
circbyline .end
op
unset wnflag
circbyline * second deck: no wnflag anywhere
circbyline .option scale=1u
circbyline .subckt dut d g s b l=1 w=1 nf=1
circbyline mn d g s b card l={l} w={w} nf={nf}
circbyline .model card.2 nmos level=54 version=4.8 lmin=1.5e-7 lmax=1e-6 wmin=3e-6 wmax=1.01e-3
circbyline .model card.1 nmos level=54 version=4.8 lmin=1.5e-7 lmax=1e-6 wmin=4.2e-7 wmax=3e-6
circbyline .ends dut
circbyline vd d 0 0.9
circbyline vg g 0 0.9
circbyline x1 d g 0 0 dut l=0.5 w=15 nf=15
circbyline .end
op
showmod m.x1.mn : model
.endc
.end
8077acf20: "could not find a valid modelname" for m.x1.mn.
ngspice-45.2: x1:card.1 (one finger is 1 um).
I did not build the parent of faf926c6f; "since" is from git log -S INPgetWnflag on subckt.c.
Patch attached, against 8077acf20. doit() reads wnflag from the variables of the session only; under hs and spe an .option wnflag of the deck itself is such a variable by then (inp_set_wnflag()). With it the deck loads on x1:card.1. It adds tests/regression/model/binning-wnflag-session.cir with the two sequences above; both stop without the change.
If you also take the patch of my report on the segmentation fault with a binned .model first in a subcircuit: both patches add a test to the same line of tests/regression/model/Makefile.am, so the second one needs that line merged by hand. Their changes to subckt.c do not touch.
INPbinOuterMax(), one line above in doit(), reads its variable the same way. I left it: I found no wrong result from it. With a binoutermax left over from the circuit before, a deck without the option that has a size on the top edge still stops with "could not find a valid modelname", which is what it should do.
make -k check with DISPLAY unset: 79 PASS and 1 FAIL (alter-1.cmd) on 8077acf20. I ran it once with this patch and the patch of my other report of today together: 81 PASS and the same FAIL, the two more being the tests the two patches add.
I checked this with help from an AI coding assistant (Claude); I have NOT reviewed the results.
Patch file