From 51fca39bc979d4ec51715ba784feb694b4411c3b Mon Sep 17 00:00:00 2001 From: dwarning Date: Wed, 1 Apr 2015 22:21:27 +0200 Subject: [PATCH] mhx: introduce INPaSpecName() --- src/frontend/outitf.c | 1 + src/frontend/outitf.h | 1 + src/include/ngspice/inpdefs.h | 1 + src/spicelib/parser/inpaname.c | 59 ++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/src/frontend/outitf.c b/src/frontend/outitf.c index e82937ead..41ea67b1b 100644 --- a/src/frontend/outitf.c +++ b/src/frontend/outitf.c @@ -175,6 +175,7 @@ beginPlot(JOB *analysisPtr, CKTcircuit *circuitPtr, char *cktName, char *analNam run->type = copy(analName); run->windowed = windowed; run->numData = 0; + run->spindex = -1; // mhx an_name = spice_analysis_get_name(analysisPtr->JOBtype); ft_curckt->ci_last_an = an_name; diff --git a/src/frontend/outitf.h b/src/frontend/outitf.h index 5374a405f..354b4a37f 100644 --- a/src/frontend/outitf.h +++ b/src/frontend/outitf.h @@ -42,6 +42,7 @@ struct runDesc { int pointCount; int isComplex; int windowCount; + int spindex; /* mhx */ }; diff --git a/src/include/ngspice/inpdefs.h b/src/include/ngspice/inpdefs.h index b4623f77b..04b334e4f 100644 --- a/src/include/ngspice/inpdefs.h +++ b/src/include/ngspice/inpdefs.h @@ -89,6 +89,7 @@ int IFnewUid(CKTcircuit *, IFuid *, IFuid, char *, int, CKTnode **); int IFdelUid(CKTcircuit *, IFuid, int); int INPaName(char *, IFvalue *, CKTcircuit *, int *, char *, GENinstance **, IFsimulator *, int *, IFvalue *); +int INPaSpecName(char *, IFvalue *, CKTcircuit *, int *, char *, GENinstance **, IFsimulator *, int *, IFvalue *, int *); int INPapName(CKTcircuit *, int, JOB *, char *, IFvalue *); void INPcaseFix(char *); char *INPdevParse(char **, CKTcircuit *, int, GENinstance *, double *, int *, INPtables *); diff --git a/src/spicelib/parser/inpaname.c b/src/spicelib/parser/inpaname.c index c9d294b46..1a28de01d 100644 --- a/src/spicelib/parser/inpaname.c +++ b/src/spicelib/parser/inpaname.c @@ -69,3 +69,62 @@ INPaName(char *parm, IFvalue * val, CKTcircuit *ckt, int *dev, char *devnam, } return (E_BADPARM); } + + +// mhx: specialized (faster) version that directly returns/uses the index of the parameter we seek +int INPaSpecName ( + char *parm, // the name of the parameter to set, + IFvalue *val, // the parameter union containing the value to set, + CKTcircuit *ckt, // the circuit this device is a member of, + int *dev, // the device type code to the device being parsed, + char *devnam, // the name of the device, + GENinstance **fast, // direct pointer to device being parsed, + IFsimulator *sim, // the simulator data structure, + int *dataType, // the datatype of the returned value structure, + IFvalue *selector, // data sub-selector for questions. + int *spindex) // special index +{ + int error; // int to store evaluate error return codes in + int i; + + /* + * find the instance - don't know about model, so use null there, + * otherwise pass on as much info as we have about the device + * (name, type, direct pointer) - the type and direct pointer + * WILL be set on return unless error is not OK + */ + if (*fast == NULL) + *fast = sim->findInstance(ckt, devnam); + if (*fast == NULL) + return (E_NODEV); + + *dev = (*fast)->GENmodPtr->GENmodType; + + /* now find the parameter - hunt through the parameter tables for + * this device type and look for a name match of an 'ask'able + * parameter. + */ + if (*spindex != -1) { // mhx: shortcut for repeated question + error = sim->askInstanceQuest(ckt, *fast, sim->devices[*dev]->instanceParms[*spindex].id, val, selector); + if (dataType) + *dataType = sim->devices[*dev]->instanceParms[*spindex].dataType; + return error; + } + + for (i = 0; i < *(sim->devices[*dev]->numInstanceParms); i++) { + if (strcmp(parm, sim->devices[*dev]->instanceParms[i].keyword) == 0 + && (sim->devices[*dev]->instanceParms[i].dataType & IF_ASK)) { + /* + * found it, so we ask the question using the device info we got + * above and put the results in the IFvalue structure our caller gave us originally + */ + *spindex = i; /* mhx: shortcut for repeated questioning */ + error = sim->askInstanceQuest(ckt, *fast, sim->devices[*dev]->instanceParms[i].id, val, selector); + if (dataType) + *dataType = sim->devices[*dev]->instanceParms[i].dataType; // probably double + return error; + } + } + + return E_BADPARM; +}