void INPpas1(void *ckt, card * deck, INPtables * tab) { card *current; char *INPdomodel(void *ckt, card * image, INPtables * tab); char *temp, *thisline; for (current = deck; current != NULL; current = current->nextcard) { /* SPICE-2 keys off of the first character of the line */ thisline = current->line; while (*thisline && ((*thisline == ' ') || (*thisline == '\t'))) thisline++; if (*thisline == '.') { if (strncmp(thisline, ".model", 6) == 0) { /* First check to see if model is multi-line. If so, read in all lines & stick them into tab. */ #ifdef TRACE /* SDB debug statement */ printf("In INPpas1, handling line = %s \n", thisline); #endif /* Now invoke INPdomodel to stick model into model table. */ temp = INPdomodel(ckt, current, tab); current->error = INPerrCat(current->error, temp); } } /* for now, we do nothing with the other cards - just * keep them in the list for pass 2 */ } }
static int dot_sens2(char *line, CKTcircuit *ckt, INPtables *tab, struct card *current, TSKtask *task, CKTnode *gnode, JOB *foo) { int error; /* error code temporary */ IFvalue ptemp; /* a value structure to package resistance into */ IFvalue *parm; /* a pointer to a value struct for function returns */ int which; /* which analysis we are performing */ char *token; /* a token from the line */ NG_IGNORE(gnode); /* .sens {AC} {DC} {TRAN} [dev=nnn parm=nnn]* */ which = ft_find_analysis("SENS2"); if (which == -1) { LITERR("Sensitivity-2 analysis unsupported\n"); return (0); } IFC(newAnalysis, (ckt, which, "Sensitivity-2 Analysis", &foo, task)); while (*line) { IFparm *if_parm; /* read the entire line */ INPgetTok(&line, &token, 1); if_parm = ft_find_analysis_parm(which, token); if (!if_parm) { /* didn't find it! */ LITERR(" Error: unknown parameter on .sens-ignored \n"); continue; } /* found it, analysis which, parameter i */ if (if_parm->dataType & IF_FLAG) { /* one of the keywords! */ ptemp.iValue = 1; error = ft_sim->setAnalysisParm (ckt, foo, if_parm->id, &ptemp, NULL); if (error) current->error = INPerrCat(current->error, INPerror(error)); } else { parm = INPgetValue(ckt, &line, if_parm->dataType, tab); error = ft_sim->setAnalysisParm (ckt, foo, if_parm->id, parm, NULL); if (error) current->error = INPerrCat(current->error, INPerror(error)); } } return (0); }
static int dot_noise(char *line, CKTcircuit *ckt, INPtables *tab, struct card *current, TSKtask *task, CKTnode *gnode, JOB *foo) { int which; /* which analysis we are performing */ int error; /* error code temporary */ char *name; /* the resistor's name */ char *nname1; /* the first node's name */ char *nname2; /* the second node's name */ CKTnode *node1; /* the first node's node pointer */ CKTnode *node2; /* the second node's node pointer */ IFvalue ptemp; /* a value structure to package resistance into */ IFvalue *parm; /* a pointer to a value struct for function returns */ char *steptype; /* ac analysis, type of stepping function */ int found; char *point; /* .noise V(OUTPUT,REF) SRC {DEC OCT LIN} NP FSTART FSTOP <PTSPRSUM> */ which = ft_find_analysis("NOISE"); if (which == -1) { LITERR("Noise analysis unsupported.\n"); return (0); } IFC(newAnalysis, (ckt, which, "Noise Analysis", &foo, task)); INPgetTok(&line, &name, 1); /* Make sure the ".noise" command is followed by V(xxxx). If it is, extract 'xxxx'. If not, report an error. */ if (name != NULL) { if ((*name == 'V' || *name == 'v') && !name[1]) { INPgetNetTok(&line, &nname1, 0); INPtermInsert(ckt, &nname1, tab, &node1); ptemp.nValue = node1; GCA(INPapName, (ckt, which, foo, "output", &ptemp)); if (*line != ')') { INPgetNetTok(&line, &nname2, 1); INPtermInsert(ckt, &nname2, tab, &node2); ptemp.nValue = node2; } else { ptemp.nValue = gnode; } GCA(INPapName, (ckt, which, foo, "outputref", &ptemp)); tfree(name); INPgetTok(&line, &name, 1); INPinsert(&name, tab); ptemp.uValue = name; GCA(INPapName, (ckt, which, foo, "input", &ptemp)); INPgetTok(&line, &steptype, 1); ptemp.iValue = 1; error = INPapName(ckt, which, foo, steptype, &ptemp); tfree(steptype); if (error) current->error = INPerrCat(current->error, INPerror(error)); parm = INPgetValue(ckt, &line, IF_INTEGER, tab); error = INPapName(ckt, which, foo, "numsteps", parm); if (error) current->error = INPerrCat(current->error, INPerror(error)); parm = INPgetValue(ckt, &line, IF_REAL, tab); error = INPapName(ckt, which, foo, "start", parm); if (error) current->error = INPerrCat(current->error, INPerror(error)); parm = INPgetValue(ckt, &line, IF_REAL, tab); error = INPapName(ckt, which, foo, "stop", parm); if (error) current->error = INPerrCat(current->error, INPerror(error)); /* now see if "ptspersum" has been specified by the user */ for (found = 0, point = line; (!found) && (*point != '\0'); found = ((*point != ' ') && (*(point++) != '\t'))) ; if (found) { parm = INPgetValue(ckt, &line, IF_INTEGER, tab); error = INPapName(ckt, which, foo, "ptspersum", parm); if (error) current->error = INPerrCat(current->error, INPerror(error)); } else { ptemp.iValue = 0; error = INPapName(ckt, which, foo, "ptspersum", &ptemp); if (error) current->error = INPerrCat(current->error, INPerror(error)); } } else LITERR("bad syntax " "[.noise v(OUT) SRC {DEC OCT LIN} " "NP FSTART FSTOP <PTSPRSUM>]\n"); } else { LITERR("bad syntax " "[.noise v(OUT) SRC {DEC OCT LIN} " "NP FSTART FSTOP <PTSPRSUM>]\n"); } return 0; }
char *MIFgetMod( CKTcircuit *ckt, /* The circuit structure */ char *name, /* The name of the model to look for */ INPmodel **model, /* The model found/created */ INPtables *tab /* Table of model info from first pass */ ) { INPmodel *modtmp; IFvalue * val; register int j; char * line; char *parm; char *err = NULL; int error; int i; char *err1; char *err2; MIFmodel *mdfast; /* Mif_Param_Info_t *param_info;*/ /* =========== First locate the named model in the modtab list ================= */ #ifdef TRACE /* SDB debug statement */ printf("In MIFgetMod, looking for model name = %s . . .\n", name); #endif /* maschmann : remove : from name * char *pos; * if((pos=strstr(name,":"))!=NULL) *pos=0; */ /*------------------------------------ for (i = &modtab; *i != NULL; i = &((*i)->INPnextModel)) { if (strcmp((*i)->INPmodName, token) == 0) { return (OK); } } --------------------------*/ /* loop through modtable looking for this model (*name) */ for (modtmp = modtab; modtmp != NULL; modtmp = modtmp->INPnextModel) { #ifdef TRACE /* SDB debug statement */ printf("In MIFgetMod, checking model against stored model = %s . . .\n", modtmp->INPmodName); #endif if (strcmp(modtmp->INPmodName, name) == 0) { #ifdef TRACE /* SDB debug statement */ printf("In MIFgetMod, found model!!!\n"); #endif /* ========= found the model in question - now instantiate if necessary ========== */ /* ============== and return an appropriate pointer to it ===================== */ /* make sure the type is valid before proceeding */ if(modtmp->INPmodType < 0) { /* illegal device type, so can't handle */ *model = NULL; return tprintf("MIF: Unknown device type for model %s\n", name); } /* check to see if this model's parameters have been processed */ if(! modtmp->INPmodfast) { /* not already processed, so create data struct */ error = ft_sim->newModel ( ckt, modtmp->INPmodType, &(modtmp->INPmodfast), modtmp->INPmodName); if(error) return(INPerror(error)); /* gtri modification: allocate and initialize MIF specific model struct items */ mdfast = (MIFmodel*) modtmp->INPmodfast; mdfast->num_param = DEVices[modtmp->INPmodType]->DEVpublic.num_param; mdfast->param = TMALLOC(Mif_Param_Data_t *, mdfast->num_param); for(i = 0; i < mdfast->num_param; i++) { mdfast->param[i] = TMALLOC(Mif_Param_Data_t, 1); mdfast->param[i]->is_null = MIF_TRUE; mdfast->param[i]->size = 0; mdfast->param[i]->element = NULL; } /* remaining initializations will be done by MIFmParam() and MIFsetup() */ /* parameter isolation, identification, binding */ line = modtmp->INPmodLine->line; INPgetTok(&line,&parm,1); /* throw away '.model' */ tfree(parm); INPgetTok(&line,&parm,1); /* throw away 'modname' */ tfree(parm); /* throw away the modtype - we don't treat it as a parameter */ /* like SPICE does */ INPgetTok(&line,&parm,1); /* throw away 'modtype' */ tfree(parm); while(*line != '\0') { INPgetTok(&line,&parm,1); for(j=0 ; j < *(ft_sim->devices[modtmp->INPmodType]->numModelParms); j++) { if (strcmp(parm, ft_sim->devices[modtmp->INPmodType]->modelParms[j].keyword) == 0) { /* gtri modification: call MIFgetValue instead of INPgetValue */ err1 = NULL; val = MIFgetValue(ckt,&line, ft_sim->devices[modtmp->INPmodType]->modelParms[j].dataType, tab, &err1); if(err1) { err2 = tprintf("MIF-ERROR - model: %s - %s\n", name, err1); return(err2); } error = ft_sim->setModelParm (ckt, modtmp->INPmodfast, ft_sim->devices[modtmp->INPmodType]->modelParms[j].id, val, NULL); if(error) return(INPerror(error)); break; } } /* gtri modification: processing of special parameter "level" removed */ if(j >= *(ft_sim->devices[modtmp->INPmodType]->numModelParms)) { char *temp = tprintf("MIF: unrecognized parameter (%s) - ignored", parm); err = INPerrCat(err, temp); } FREE(parm); } /* end while end of line not reached */ modtmp->INPmodLine->error = err; } /* end if model parameters not processed yet */ *model = modtmp; return(NULL); } /* end if name matches */
static int dot_noise(char *line, void *ckt, INPtables *tab, card *current, void *task, void *gnode, void *foo) { int which; /* which analysis we are performing */ int i; /* generic loop variable */ int error; /* error code temporary */ char *name; /* the resistor's name */ char *nname1; /* the first node's name */ char *nname2; /* the second node's name */ void *node1; /* the first node's node pointer */ void *node2; /* the second node's node pointer */ IFvalue ptemp; /* a value structure to package resistance into */ IFvalue *parm; /* a pointer to a value struct for function returns */ char *steptype; /* ac analysis, type of stepping function */ int found; char *point; /* .noise V(OUTPUT,REF) SRC {DEC OCT LIN} NP FSTART FSTOP <PTSPRSUM> */ which = -1; for (i = 0; i < ft_sim->numAnalyses; i++) { if (strcmp(ft_sim->analyses[i]->name, "NOISE") == 0) { which = i; break; } } if (which == -1) { LITERR("Noise analysis unsupported.\n"); return (0); } IFC(newAnalysis, (ckt, which, "Noise Analysis", &foo, task)); INPgetTok(&line, &name, 1); /* Make sure the ".noise" command is followed by V(xxxx). If it is, extract 'xxxx'. If not, report an error. */ if (name != NULL) { int length; length = strlen(name); if (((*name == 'V') || (*name == 'v')) && (length == 1)) { INPgetNetTok(&line, &nname1, 0); INPtermInsert(ckt, &nname1, tab, &node1); ptemp.nValue = (IFnode) node1; GCA(INPapName, (ckt, which, foo, "output", &ptemp)) if (*line != ')') { INPgetNetTok(&line, &nname2, 1); INPtermInsert(ckt, &nname2, tab, &node2); ptemp.nValue = (IFnode) node2; } else { ptemp.nValue = (IFnode) gnode; } GCA(INPapName, (ckt, which, foo, "outputref", &ptemp)) INPgetTok(&line, &name, 1); INPinsert(&name, tab); ptemp.uValue = name; GCA(INPapName, (ckt, which, foo, "input", &ptemp)) INPgetTok(&line, &steptype, 1); ptemp.iValue = 1; error = INPapName(ckt, which, foo, steptype, &ptemp); if (error) current->error = INPerrCat(current->error, INPerror(error)); parm = INPgetValue(ckt, &line, IF_INTEGER, tab); error = INPapName(ckt, which, foo, "numsteps", parm); if (error) current->error = INPerrCat(current->error, INPerror(error)); parm = INPgetValue(ckt, &line, IF_REAL, tab); error = INPapName(ckt, which, foo, "start", parm); if (error) current->error = INPerrCat(current->error, INPerror(error)); parm = INPgetValue(ckt, &line, IF_REAL, tab); error = INPapName(ckt, which, foo, "stop", parm); if (error) current->error = INPerrCat(current->error, INPerror(error)); /* now see if "ptspersum" has been specified by the user */ for (found = 0, point = line; (!found) && (*point != '\0'); found = ((*point != ' ') && (*(point++) != '\t'))); if (found) { parm = INPgetValue(ckt, &line, IF_INTEGER, tab); error = INPapName(ckt, which, foo, "ptspersum", parm); if (error) current->error = INPerrCat(current->error, INPerror(error)); } else { ptemp.iValue = 0; error = INPapName(ckt, which, foo, "ptspersum", &ptemp); if (error) current->error = INPerrCat(current->error, INPerror(error)); } } else
///<param name = "*ckt"> ircuit being parsed </param> ///<param name = "*anal"> The options analysis to add to </param> ///<param name = "*optCard"> The card image to get data from </param> ///<param name = "*tab"> The parse tables for this circuit </param> void INPdoOpts(GENERIC *ckt, GENERIC *anal, card *optCard, INPtables *tab) { char *line; char *token; char *errmsg; IFvalue *val = NULL; int error; int i; int which; IFanalysis *prm = NULL; which = -1; i = 0; for (i = 0; i < ft_sim->numAnalyses; i++) { prm = ft_sim->analyses[i]; if (strcmp(prm->name, "options") == 0) { which = i; break; } i++; } if (which == -1) { optCard->error = INPerrCat(optCard->error, INPmkTemp("errr: analysis options table not found\n")); return; } line = optCard->line; INPgetTok(&line, &token, 1); /* throw away '.option' */ while (*line) { INPgetTok(&line, &token, 1); for (i = 0; i < prm->numParms; i++) { if (strcmp(token, prm->analysisParms[i].keyword) == 0) { if (!(prm->analysisParms[i].dataType & IF_UNIMP_MASK)) { errmsg = (char *)MALLOC((45 + strlen(token)) * sizeof(char)); (void)sprintf(errmsg, " Warning: %s not yet implemented - ignored \n", token); optCard->error = INPerrCat(optCard->error, errmsg); val = INPgetValue(ckt, &line, prm->analysisParms[i].dataType, tab); break; } if (prm->analysisParms[i].dataType & IF_SET) { val = INPgetValue(ckt, &line, prm->analysisParms[i].dataType&IF_VARTYPES, tab); error = (*(ft_sim->setAnalysisParm))(ckt, anal, prm->analysisParms[i].id, val, (IFvalue*)NULL); if (error) { errmsg = (char *)MALLOC((35 + strlen(token))*sizeof(char)); (void)sprintf(errmsg, "Warning: can't set optione %s\n", token); optCard->error = INPerrCat(optCard->error, errmsg); } break; } } } if (i == prm->numParms) { errmsg = (char *)MALLOC(100 * sizeof(char)); (void)strcpy(errmsg, " Error: unknown option - ignored\n"); optCard->error = INPerrCat(optCard->error, errmsg); } } }
void INPpas2(CKTcircuit *ckt, card * data, INPtables * tab, TSKtask *task) { card *current; char c; char *groundname = "0"; char *gname; CKTnode *gnode; int error; /* used by the macros defined above */ #ifdef HAS_PROGREP int linecount = 0, actcount = 0; #endif #ifdef TRACE /* SDB debug statement */ printf("Entered INPpas2 . . . .\n"); #endif #ifdef XSPICE if (!ckt->CKTadevFlag) ckt->CKTadevFlag = 0; #endif error = INPgetTok(&groundname, &gname, 1); if (error) data->error = INPerrCat(data->error, INPmkTemp ("can't read internal ground node name!\n")); error = INPgndInsert(ckt, &gname, tab, &gnode); if (error && error != E_EXISTS) data->error = INPerrCat(data->error, INPmkTemp ("can't insert internal ground node in symbol table!\n")); #ifdef TRACE printf("Examining this deck:\n"); for (current = data; current != NULL; current = current->nextcard) { printf("%s\n", current->line); } printf("\n"); #endif #ifdef HAS_PROGREP for (current = data; current != NULL; current = current->nextcard) linecount++; #endif for (current = data; current != NULL; current = current->nextcard) { #ifdef TRACE /* SDB debug statement */ printf("In INPpas2, examining card %s . . .\n", current->line); #endif #ifdef HAS_PROGREP if (linecount > 0) { SetAnalyse( "Circuit2", (int) (1000.*actcount/linecount)); actcount++; } #endif c = *(current->line); if(islower(c)) c = (char) toupper(c); switch (c) { case ' ': /* blank line (space leading) */ case '\t': /* blank line (tab leading) */ break; #ifdef XSPICE /* gtri - add - wbk - 10/23/90 - add case for 'A' devices */ case 'A': /* Aname <cm connections> <mname> */ MIF_INP2A(ckt, tab, current); ckt->CKTadevFlag = 1; /* an 'A' device is requested */ break; /* gtri - end - wbk - 10/23/90 */ #endif case 'R': /* Rname <node> <node> [<val>][<mname>][w=<val>][l=<val>] */ INP2R(ckt, tab, current); break; case 'C': /* Cname <node> <node> <val> [IC=<val>] */ INP2C(ckt, tab, current); break; case 'L': /* Lname <node> <node> <val> [IC=<val>] */ INP2L(ckt, tab, current); break; case 'G': /* Gname <node> <node> <node> <node> <val> */ INP2G(ckt, tab, current); break; case 'E': /* Ename <node> <node> <node> <node> <val> */ INP2E(ckt, tab, current); break; case 'F': /* Fname <node> <node> <vname> <val> */ INP2F(ckt, tab, current); break; case 'H': /* Hname <node> <node> <vname> <val> */ INP2H(ckt, tab, current); break; case 'D': /* Dname <node> <node> <model> [<val>] [OFF] [IC=<val>] */ INP2D(ckt, tab, current); break; case 'J': /* Jname <node> <node> <node> <model> [<val>] [OFF] [IC=<val>,<val>] */ INP2J(ckt, tab, current); break; case 'Z': /* Zname <node> <node> <node> <model> [<val>] [OFF] [IC=<val>,<val>] */ INP2Z(ckt, tab, current); break; case 'M': /* Mname <node> <node> <node> <node> <model> [L=<val>] [W=<val>] [AD=<val>] [AS=<val>] [PD=<val>] [PS=<val>] [NRD=<val>] [NRS=<val>] [OFF] [IC=<val>,<val>,<val>] */ INP2M(ckt, tab, current); break; #ifdef NDEV case 'N': /* Nname [<node>...] [<mname>] */ INP2N(ckt, tab, current); break; #endif case 'O': /* Oname <node> <node> <node> <node> <model> [IC=<val>,<val>,<val>,<val>] */ INP2O(ckt, tab, current); break; case 'V': /* Vname <node> <node> [ [DC] <val>] [AC [<val> [<val> ] ] ] [<tran function>] */ INP2V(ckt, tab, current); break; case 'I': /* Iname <node> <node> [ [DC] <val>] [AC [<val> [<val> ] ] ] [<tran function>] */ INP2I(ckt, tab, current); break; case 'Q': /* Qname <node> <node> <node> [<node>] <model> [<val>] [OFF] [IC=<val>,<val>] */ INP2Q(ckt, tab, current, gnode); break; case 'T': /* Tname <node> <node> <node> <node> [TD=<val>] [F=<val> [NL=<val>]][IC=<val>,<val>,<val>,<val>] */ INP2T(ckt, tab, current); break; case 'S': /* Sname <node> <node> <node> <node> [<modname>] [IC] */ INP2S(ckt, tab, current); break; case 'W': /* Wname <node> <node> <vctrl> [<modname>] [IC] */ /* CURRENT CONTROLLED SWITCH */ INP2W(ckt, tab, current); break; case 'U': /* Uname <node> <node> <model> [l=<val>] [n=<val>] */ INP2U(ckt, tab, current); break; /* Kspice addition - saj */ case 'P': /* Pname <node> <node> ... <gnd> <node> <node> ... <gnd> [<modname>] */ /* R=<vector> L=<matrix> G=<vector> C=<matrix> len=<val> */ INP2P(ckt, tab, current); break; case 'Y': /* Yname <node> <node> R=<val> L=<val> G=<val> C=<val> len=<val> */ INP2Y(ckt, tab, current); break; /* end Kspice */ case 'K': /* Kname Lname Lname <val> */ INP2K(ckt, tab, current); break; case '*': case '$': /* *<anything> - a comment - ignore */ break; case 'B': /* Bname <node> <node> [V=expr] [I=expr] */ /* Arbitrary source. */ INP2B(ckt, tab, current); break; case '.': /* .<something> Many possibilities */ if (INP2dot(ckt,tab,current,task,gnode)) return; break; case '\0': break; default: /* the un-implemented device */ LITERR(" unknown device type - error \n"); break; } } return; }
///<param name = "*ckt"> THe current circuit </param> ///<param name = "*name"> The name of the model </param> ///<param name = "**model"> The parse model structure </param> ///<param name = "*tab"> The current symbol table </param> char *INPgetMod(GENERIC * ckt, char *name, INPmodel **model, INPtables *tab) { INPmodel *modtmp; IFvalue * val; register int j; char * line; char *parm; char *err = NULL; char *temp; int error; for (modtmp = modtab; modtmp != (INPmodel *)NULL; modtmp = ((modtmp)->INPnextModel)) { if (strcmp((modtmp)->INPmodName, name) == 0) { /* found the model in question - now instantiate if necessary */ /* and return an appropriate pointer to it */ if (modtmp->INPmodType < 0) { /* illegal device type, so can't handle */ *model = (INPmodel *)NULL; err = (char *)MALLOC((35 + strlen(name)) * sizeof(char)); (void)sprintf(err, "Unknown device type for model %s \n", name); return(err); } if (!((modtmp)->INPmodUsed)) { /* not already defined, so create & give parameters */ error = (*(ft_sim->newModel))(ckt, (modtmp)->INPmodType, &((modtmp)->INPmodfast), (modtmp)->INPmodName); if (error) return(INPerror(error)); /* parameter isolation, identification, binding */ line = ((modtmp)->INPmodLine)->line; INPgetTok(&line, &parm, 1); /* throw away '.model' */ INPgetTok(&line, &parm, 1); /* throw away 'modname' */ while (*line != 0) { INPgetTok(&line, &parm, 1); if (!*parm) continue; for (j = 0; j < (*(*(ft_sim->devices)[(modtmp)->INPmodType]).numModelParms); j++) { if (strcmp(parm, ((*(ft_sim->devices)[(modtmp)->INPmodType]).modelParms[j].keyword)) == 0) { val = INPgetValue(ckt, &line, ((*(ft_sim->devices)[(modtmp)->INPmodType]).modelParms[j].dataType), tab); error = (*(ft_sim->setModelParm))(ckt, ((modtmp)->INPmodfast), (*(ft_sim->devices)[(modtmp)->INPmodType]).modelParms[j].id, val, (IFvalue*)NULL); if (error) return(INPerror(error)); break; } } if (strcmp(parm, "level") == 0) { /* just grab the level number and throw away */ /* since we already have that info from pass1 */ val = INPgetValue(ckt, &line, IF_REAL, tab); } else if (j >= (*(*(ft_sim->devices)[(modtmp)->INPmodType]).numModelParms)) { temp = (char *)MALLOC((40 + strlen(parm)) * sizeof(char)); (void)sprintf(temp, "unrecognized parameter (%s) - ignored\n", parm); err = INPerrCat(err, temp); } FREE(parm); } (modtmp)->INPmodUsed = 1; (modtmp)->INPmodLine->error = err; } *model = modtmp; return((char *)NULL); } } /* didn't find model - ERROR - return model */ *model = (INPmodel *)NULL; err = (char *)MALLOC((60 + strlen(name)) * sizeof(char)); (void)sprintf(err, " unable to find definition of model %s - default assumed \n", name); return(err); }