diff --git a/src/spicelib/parser/Makefile.am b/src/spicelib/parser/Makefile.am index b38ce4c70..0b7133d3d 100644 --- a/src/spicelib/parser/Makefile.am +++ b/src/spicelib/parser/Makefile.am @@ -18,6 +18,7 @@ libinp_a_SOURCES = \ inp2k.c \ inp2l.c \ inp2m.c \ + inp2n.c \ inp2o.c \ inp2p.c \ inp2q.c \ diff --git a/src/spicelib/parser/inp2n.c b/src/spicelib/parser/inp2n.c new file mode 100644 index 000000000..8ee5d6fd5 --- /dev/null +++ b/src/spicelib/parser/inp2n.c @@ -0,0 +1,128 @@ +/********** +Permit to use it as your wish. +Author: 2007 Gong Ding, gdiso@ustc.edu +University of Science and Technology of China +**********/ + +#include + +#ifdef NDEV + +#include "ngspice.h" +#include +#include "ifsim.h" +#include "inpdefs.h" +#include "../devices/ndev/ndevdefs.h" +#include "inpmacs.h" +#include "fteext.h" +#include "inp.h" + +void INP2N(void *ckt, INPtables * tab, card * current) +{ +/* parse a numerical device card */ +/* Nname [ ...] [] */ +/* The NUMD should have a private .model card */ + + int mytype; /* the type we determine NDEV are */ + int type = 0; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *saveline; /* ... just in case we need to go back... */ + char *name; /* the NDEV's name */ + char *model; /* the name of the NDEV's model */ + + int term; /* the number of node */ + char *nnamex; /* serve as a temporary name */ + char *nname[7]; /* the array of CKT node's name */ + char *bname[7]; /* the array of NDEV electrode's name */ + void *node[7]; /* the array of CKT node's node pointer */ + + int error; /* error code temporary */ + int error1; /* secondary error code temporary */ + int i; + INPmodel *thismodel; /* pointer to model structure describing our model */ + void *mdfast = NULL; /* pointer to the actual model */ + void *fast; /* pointer to the actual instance */ + NDEVinstance *pinst; + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + + mytype = INPtypelook("NDEV"); + if (mytype < 0) { + LITERR("Device type NDEV not supported by this binary\n"); + return; + } + line = current->line; + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + + /* get the node number here */ + saveline=line; + term = 0; + do { + INPgetNetTok(&line, &nnamex, 1); + term++; + }while(*nnamex); + line=saveline; + term=(term-2)/2; + if (term > 7) { + LITERR("Numerical device has too much nodes, the limitation is 7\n"); + return; + } + for(i=0;ierror = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (mytype != thismodel->INPmodType) { + LITERR("incorrect model type"); + return; + } + mdfast = thismodel->INPmodfast; + type = thismodel->INPmodType; + } + } else { + LITERR("Numerical device should always have a model card\n"); + return; + } + IFC(newInstance, (ckt, mdfast, &fast, name)); + } else { + LITERR("Numerical device should always have a model card\n"); + return; + } + + for(i=0;iterm = term; + for(i=0;ibname[i]=bname[i]; + pinst->node[i]=node[i]; + } + + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)); + if (waslead) { + LITERR("The numerical device was lead berfor.\n"); + return; + } + + + return; +} + +#endif diff --git a/src/spicelib/parser/inpdomod.c b/src/spicelib/parser/inpdomod.c index 534a11834..441f38f89 100644 --- a/src/spicelib/parser/inpdomod.c +++ b/src/spicelib/parser/inpdomod.c @@ -434,7 +434,18 @@ printf("found psp102 lev=%i\n",lev); } INPmakeMod(modname, type, image); } - +#ifdef NDEV + /* -------- Check if model is a numerical device --------- */ + else if (strcmp(typename, "ndev") == 0) { + type = INPtypelook("NDEV"); + if (type < 0) { + err = + INPmkTemp + ("Device type NDEV not available in this binary\n"); + } + INPmakeMod(modname, type, image); + } +#endif /* -------- Check if model is a resistor --------- */ else if (strcmp(typename, "r") == 0) { type = INPtypelook("Resistor"); diff --git a/src/spicelib/parser/inppas2.c b/src/spicelib/parser/inppas2.c index e84bc964a..7392b4154 100644 --- a/src/spicelib/parser/inppas2.c +++ b/src/spicelib/parser/inppas2.c @@ -146,7 +146,12 @@ void INPpas2(void *ckt, card * data, INPtables * tab, void *task) [IC=,,] */ INP2M(ckt, tab, current); break; - +#ifdef NDEV + case 'N': + /* Nname [...] [] */ + INP2N(ckt, tab, current); + break; +#endif case 'O': /* Oname [IC=,,,] */