From ba6955a1aa6898ef7d49f71b7041c2c9ef261c49 Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 11 Mar 2017 21:11:32 +0100 Subject: [PATCH] inp2q.c, sanitise optional ports processing Tie ports 4 and up to ground, iff not connected. Actually, I think the model's DEVsetup routine should do this business, we should pass -1 to denote the fact of being unconnected --- src/spicelib/parser/inp2q.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/spicelib/parser/inp2q.c b/src/spicelib/parser/inp2q.c index f3c79b49d..df63507b3 100644 --- a/src/spicelib/parser/inp2q.c +++ b/src/spicelib/parser/inp2q.c @@ -45,7 +45,7 @@ void INP2Q(CKTcircuit *ckt, INPtables * tab, card * current, CKTnode *gnode) CKTnode *node[4]; #endif int error; /* error code temporary */ - int nodeflag; /* flag indicating 4 or 5 nodes */ + int numnodes; /* flag indicating 4 or 5 nodes */ GENinstance *fast; /* pointer to the actual instance */ IFvalue ptemp; /* a value structure to package resistance into */ int waslead; /* flag to indicate that funny unlabeled number was found */ @@ -58,7 +58,6 @@ void INP2Q(CKTcircuit *ckt, INPtables * tab, card * current, CKTnode *gnode) printf("INP2Q: Parsing '%s'\n", current->line); #endif - nodeflag = 4; /* initially specify a 4 terminal device */ line = current->line; INPgetTok(&line, &name, 1); @@ -83,24 +82,17 @@ void INP2Q(CKTcircuit *ckt, INPtables * tab, card * current, CKTnode *gnode) INPtermInsert(ckt, &token, tab, &node[i]); } - if (i == 3) { - /* 3-terminal device - substrate to ground */ - node[3] = gnode; - nodeflag = 4; + int model_numnodes_ = model_numnodes(thismodel->INPmodType); + if (i > model_numnodes_) { + LITERR("Too much nodes for this model type"); + return; } - if (i == 4) { - nodeflag = 4; - if (5 == model_numnodes(thismodel->INPmodType)) { - char *token = copy("0"); - node[4] = gnode; /* 4-terminal adms device - thermal node to ground */ - INPtermInsert(ckt, &token, tab, &node[4]); - nodeflag = 5; /* now specify a 5 node device */ - } - } + /* tie missing ports to ground, (substrate and thermal node) */ + while (i < model_numnodes_) + node[i++] = gnode; - if (i == 5) - nodeflag = 5; + numnodes = i; #ifdef TRACE printf("INP2Q: Looking up model\n"); @@ -122,21 +114,15 @@ void INP2Q(CKTcircuit *ckt, INPtables * tab, card * current, CKTnode *gnode) return; } - if (nodeflag > model_numnodes(thismodel->INPmodType)) - { - LITERR("Too much nodes for this model type"); - return; - } - type = thismodel->INPmodType; mdfast = thismodel->INPmodfast; #ifdef TRACE - printf("INP2Q: Type: %d nodeflag: %d instancename: %s\n", type, nodeflag, name); + printf("INP2Q: Type: %d numnodes: %d instancename: %s\n", type, numnodes, name); #endif IFC(newInstance, (ckt, mdfast, &fast, name)); - for (i = 0; i < nodeflag; i++) + for (i = 0; i < numnodes; i++) IFC(bindNode, (ckt, fast, i + 1, node[i])); PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab));