diff --git a/src/frontend/shyu.c b/src/frontend/shyu.c index 967798190..d139394a1 100644 --- a/src/frontend/shyu.c +++ b/src/frontend/shyu.c @@ -40,7 +40,6 @@ if_sens_run(CKTcircuit *ckt, wordlist *args, INPtables *tab) char *line; card deck; int i; - int j; int error; int save; int flag = 0; @@ -73,11 +72,7 @@ if_sens_run(CKTcircuit *ckt, wordlist *args, INPtables *tab) return (0); /* temporary */ } - for (j = 0; j < ft_sim->numAnalyses; j++) - if (strcmp(ft_sim->analyses[j]->name, "options") == 0) { - which = j; - break; - } + which = ft_find_analysis("options"); if (which == -1) { /* in DEEP trouble */ @@ -95,12 +90,7 @@ if_sens_run(CKTcircuit *ckt, wordlist *args, INPtables *tab) ft_curckt->ci_curOpt = ft_curckt->ci_specOpt; ft_curckt->ci_curTask = ft_curckt->ci_specTask; - which = -1; - for (j = 0; j < ft_sim->numAnalyses; j++) - if (strcmp(ft_sim->analyses[j]->name, "SEN") == 0) { - which = j; - break; - } + which = ft_find_analysis("SEN"); if (which == -1) { current->error = INPerrCat( @@ -122,12 +112,7 @@ if_sens_run(CKTcircuit *ckt, wordlist *args, INPtables *tab) if (strcmp(token, "ac") == 0) { JOB *acJob; - which = -1; - for (j = 0; j < ft_sim->numAnalyses; j++) - if (strcmp(ft_sim->analyses[j]->name, "AC") == 0) { - which = j; - break; - } + which = ft_find_analysis("AC"); if (which == -1) { current->error = INPerrCat (current->error, @@ -162,12 +147,7 @@ if_sens_run(CKTcircuit *ckt, wordlist *args, INPtables *tab) } if (strcmp(token, "op") == 0) { - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) - if (strcmp(ft_sim->analyses[i]->name, "DCOP") == 0) { - which = i; - break; - } + which = ft_find_analysis("DCOP"); if (which == -1) { current->error = INPerrCat (current->error, @@ -186,12 +166,7 @@ if_sens_run(CKTcircuit *ckt, wordlist *args, INPtables *tab) JOB *dcJob; /* .dc SRC1NAME Vstart1 Vstop1 Vinc1 [SRC2NAME Vstart2 */ /* Vstop2 Vinc2 */ - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) - if (strcmp(ft_sim->analyses[i]->name, "DCTransfer") == 0) { - which = i; - break; - } + which = ft_find_analysis("DCTransfer"); if (which == -1) { current->error = INPerrCat (current->error, @@ -248,12 +223,7 @@ if_sens_run(CKTcircuit *ckt, wordlist *args, INPtables *tab) if (strcmp(token, "tran") == 0) { JOB *tranJob; - which = -1; - for (j = 0; j < ft_sim->numAnalyses; j++) - if (strcmp(ft_sim->analyses[j]->name, "TRAN") == 0) { - which = j; - break; - } + which = ft_find_analysis("TRAN"); if (which == -1) { current->error = INPerrCat (current->error, @@ -309,12 +279,7 @@ if_sens_run(CKTcircuit *ckt, wordlist *args, INPtables *tab) /* *********************** */ if (strcmp(token, "pss") == 0) { JOB *pssJob; - which = -1; - for (j = 0; j < ft_sim->numAnalyses; j++) - if (strcmp(ft_sim->analyses[j]->name, "PSS") == 0) { - which = j; - break; - } + which = ft_find_analysis("PSS"); if (which == -1) { current->error = INPerrCat (current->error, diff --git a/src/frontend/spiceif.c b/src/frontend/spiceif.c index 5a73c5250..3996fa5ff 100644 --- a/src/frontend/spiceif.c +++ b/src/frontend/spiceif.c @@ -93,7 +93,7 @@ CKTcircuit * if_inpdeck(struct line *deck, INPtables **tab) { CKTcircuit *ckt; - int err, i, j; + int err, i; struct line *ll; IFuid taskUid; IFuid optUid; @@ -130,11 +130,7 @@ if_inpdeck(struct line *deck, INPtables **tab) /*CDHW which options available for this simulator? CDHW*/ - for (j = 0; j < ft_sim->numAnalyses; j++) - if (strcmp(ft_sim->analyses[j]->name, "options") == 0) { - which = j; - break; - } + which = ft_find_analysis("options"); if (which != -1) { err = IFnewUid(ckt, &optUid, NULL, "options", UID_ANALYSIS, NULL); @@ -201,7 +197,6 @@ if_run(CKTcircuit *ckt, char *what, wordlist *args, INPtables *tab) int err; struct line deck; char buf[BSIZE_SP]; - int j; int which = -1; IFuid specUid, optUid; char *s; @@ -273,11 +268,7 @@ if_run(CKTcircuit *ckt, char *what, wordlist *args, INPtables *tab) /*CDHW which options available for this simulator? CDHW*/ - for (j = 0; j < ft_sim->numAnalyses; j++) - if (strcmp(ft_sim->analyses[j]->name, "options") == 0) { - which = j; - break; - } + which = ft_find_analysis("options"); if (which != -1) { /*CDHW options are available CDHW*/ err = IFnewUid(ft_curckt->ci_ckt, &optUid, NULL, "options", UID_ANALYSIS, NULL); @@ -429,11 +420,7 @@ if_option(CKTcircuit *ckt, char *name, enum cp_types type, void *value) return 0; } - for (i = 0; i < ft_sim->numAnalyses; i++) - if (strcmp(ft_sim->analyses[i]->name, "options") == 0) { - which = i; - break; - } + which = ft_find_analysis("options"); if (which == -1) { fprintf(cp_err, "Warning: .options line unsupported\n"); @@ -1243,18 +1230,13 @@ if_tranparams(struct circ *ci, double *start, double *stop, double *step) IFvalue tmp; int err; int which = -1; - int i; JOB *anal; IFuid tranUid; if (!ci->ci_curTask) return (FALSE); - for (i = 0; i < ft_sim->numAnalyses; i++) - if (strcmp(ft_sim->analyses[i]->name, "TRAN") == 0) { - which = i; - break; - } + which = ft_find_analysis("TRAN"); if (which == -1) return (FALSE); @@ -1301,11 +1283,7 @@ if_getstat(CKTcircuit *ckt, char *name) IFvalue parm; int which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) - if (strcmp(ft_sim->analyses[i]->name, "options") == 0) { - which = i; - break; - } + which = ft_find_analysis("options"); if (which == -1) { fprintf(cp_err, "Warning: statistics unsupported\n"); @@ -1740,3 +1718,14 @@ void com_snsave(wordlist *wl) fclose(file); fprintf(stdout, "Snapshot saved to %s.\n", wl->wl_word); } + + +int +ft_find_analysis(char *name) +{ + int j; + for (j = 0; j < ft_sim->numAnalyses; j++) + if (strcmp(ft_sim->analyses[j]->name, name) == 0) + return j; + return -1; +} diff --git a/src/include/ngspice/fteext.h b/src/include/ngspice/fteext.h index ae7ca077a..2a7a987a1 100644 --- a/src/include/ngspice/fteext.h +++ b/src/include/ngspice/fteext.h @@ -306,6 +306,7 @@ extern void if_setndnames(char *line); extern void if_setparam_model(CKTcircuit *ckt, char **name, char *val ); extern void if_setparam(CKTcircuit *ckt, char **name, char *param, struct dvec *val, int do_model); extern struct variable *if_getstat(CKTcircuit *ckt, char *name); +extern int ft_find_analysis(char *name); /* typesdef.c */ diff --git a/src/spicelib/parser/inp2dot.c b/src/spicelib/parser/inp2dot.c index c7be635d2..2d3f90719 100644 --- a/src/spicelib/parser/inp2dot.c +++ b/src/spicelib/parser/inp2dot.c @@ -19,7 +19,6 @@ dot_noise(char *line, CKTcircuit *ckt, INPtables *tab, card *current, TSKtask *task, CKTnode *gnode, JOB *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 */ @@ -34,13 +33,7 @@ dot_noise(char *line, CKTcircuit *ckt, INPtables *tab, card *current, char *point; /* .noise V(OUTPUT,REF) SRC {DEC OCT LIN} NP FSTART FSTOP */ - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) { - if (strcmp(ft_sim->analyses[i]->name, "NOISE") == 0) { - which = i; - break; - } - } + which = ft_find_analysis("NOISE"); if (which == -1) { LITERR("Noise analysis unsupported.\n"); return (0); @@ -125,7 +118,6 @@ dot_op(char *line, CKTcircuit *ckt, INPtables *tab, card *current, TSKtask *task, CKTnode *gnode, JOB *foo) { int which; /* which analysis we are performing */ - int i; /* generic loop variable */ int error; /* error code temporary */ NG_IGNORE(line); @@ -133,13 +125,7 @@ dot_op(char *line, CKTcircuit *ckt, INPtables *tab, card *current, NG_IGNORE(gnode); /* .op */ - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) { - if (strcmp(ft_sim->analyses[i]->name, "OP") == 0) { - which = i; - break; - } - } + which = ft_find_analysis("OP"); if (which == -1) { LITERR("DC operating point analysis unsupported\n"); return (0); @@ -154,7 +140,6 @@ dot_disto(char *line, CKTcircuit *ckt, INPtables *tab, card *current, TSKtask *task, CKTnode *gnode, JOB *foo) { int which; /* which analysis we are performing */ - int i; /* generic loop variable */ 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 */ @@ -163,13 +148,7 @@ dot_disto(char *line, CKTcircuit *ckt, INPtables *tab, card *current, NG_IGNORE(gnode); /* .disto {DEC OCT LIN} NP FSTART FSTOP */ - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) { - if (strcmp(ft_sim->analyses[i]->name, "DISTO") == 0) { - which = i; - break; - } - } + which = ft_find_analysis("DISTO"); if (which == -1) { LITERR("Small signal distortion analysis unsupported.\n"); return (0); @@ -200,19 +179,12 @@ dot_ac(char *line, CKTcircuit *ckt, INPtables *tab, card *current, 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 */ - int i; /* generic loop variable */ char *steptype; /* ac analysis, type of stepping function */ NG_IGNORE(gnode); /* .ac {DEC OCT LIN} NP FSTART FSTOP */ - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) { - if (strcmp(ft_sim->analyses[i]->name, "AC") == 0) { - which = i; - break; - } - } + which = ft_find_analysis("AC"); if (which == -1) { LITERR("AC small signal analysis unsupported.\n"); return (0); @@ -239,19 +211,12 @@ dot_pz(char *line, CKTcircuit *ckt, INPtables *tab, card *current, 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 */ - int i; /* generic loop variable */ char *steptype; /* ac analysis, type of stepping function */ NG_IGNORE(gnode); /* .pz nodeI nodeG nodeJ nodeK {V I} {POL ZER PZ} */ - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) { - if (strcmp(ft_sim->analyses[i]->name, "PZ") == 0) { - which = i; - break; - } - } + which = ft_find_analysis("PZ"); if (which == -1) { LITERR("Pole-zero analysis unsupported.\n"); return (0); @@ -284,19 +249,12 @@ dot_dc(char *line, CKTcircuit *ckt, INPtables *tab, card *current, 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 */ - int i; /* generic loop variable */ NG_IGNORE(gnode); /* .dc SRC1NAME Vstart1 Vstop1 Vinc1 [SRC2NAME Vstart2 */ /* Vstop2 Vinc2 */ - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) { - if (strcmp(ft_sim->analyses[i]->name, "DC") == 0) { - which = i; - break; - } - } + which = ft_find_analysis("DC"); if (which == -1) { LITERR("DC transfer curve analysis unsupported\n"); return (0); @@ -336,7 +294,6 @@ dot_tf(char *line, CKTcircuit *ckt, INPtables *tab, card *current, int error; /* error code temporary */ IFvalue ptemp; /* a value structure to package resistance into */ int which; /* which analysis we are performing */ - int i; /* generic loop variable */ char *nname1; /* the first node's name */ char *nname2; /* the second node's name */ CKTnode *node1; /* the first node's node pointer */ @@ -344,13 +301,7 @@ dot_tf(char *line, CKTcircuit *ckt, INPtables *tab, card *current, /* .tf v( node1, node2 ) src */ /* .tf vsrc2 src */ - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) { - if (strcmp(ft_sim->analyses[i]->name, "TF") == 0) { - which = i; - break; - } - } + which = ft_find_analysis("TF"); if (which == -1) { LITERR("Transfer Function analysis unsupported.\n"); return (0); @@ -408,20 +359,13 @@ dot_tran(char *line, CKTcircuit *ckt, INPtables *tab, card *current, 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 */ - int i; /* generic loop variable */ double dtemp; /* random double precision temporary */ char *word; /* something to stick a word of input into */ NG_IGNORE(gnode); /* .tran Tstep Tstop > */ - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) { - if (strcmp(ft_sim->analyses[i]->name, "TRAN") == 0) { - which = i; - break; - } - } + which = ft_find_analysis("TRAN"); if (which == -1) { LITERR("Transient analysis unsupported.\n"); return (0); @@ -465,20 +409,13 @@ dot_sens(char *line, CKTcircuit *ckt, INPtables *tab, card *current, 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 */ - int i; /* generic loop variable */ 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 */ char *steptype; /* ac analysis, type of stepping function */ - which = -1; /* Bug fix from Glao Dezai */ - for (i = 0; i < ft_sim->numAnalyses; i++) { - if (strcmp(ft_sim->analyses[i]->name, "SENS") == 0) { - which = i; - break; - } - } + which = ft_find_analysis("SENS"); if (which == -1) { LITERR("Sensitivity unsupported.\n"); return (0); @@ -570,13 +507,7 @@ dot_sens2(char *line, CKTcircuit *ckt, INPtables *tab, card *current, NG_IGNORE(gnode); /* .sens {AC} {DC} {TRAN} [dev=nnn parm=nnn]* */ - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) { - if (strcmp(ft_sim->analyses[i]->name, "SENS2") == 0) { - which = i; - break; - } - } + which = ft_find_analysis("SENS2"); if (which == -1) { LITERR("Sensitivity-2 analysis unsupported\n"); return (0); @@ -639,19 +570,12 @@ dot_pss(char *line, void *ckt, INPtables *tab, card *current, char *nname; /* the oscNode name */ CKTnode *nnode; /* the oscNode node */ int which; /* which analysis we are performing */ - int i; /* generic loop variable */ char *word; /* something to stick a word of input into */ NG_IGNORE(gnode); /* .pss Fguess StabTime OscNode */ - which = -1; - for (i = 0; i < ft_sim->numAnalyses; i++) { - if (strcmp(ft_sim->analyses[i]->name, "PSS") == 0) { - which = i; - break; - } - } + which = ft_find_analysis("PSS"); if (which == -1) { LITERR("Periodic steady state analysis unsupported.\n"); return (0); diff --git a/src/spicelib/parser/inpdoopt.c b/src/spicelib/parser/inpdoopt.c index c21f26417..976492f2d 100644 --- a/src/spicelib/parser/inpdoopt.c +++ b/src/spicelib/parser/inpdoopt.c @@ -33,20 +33,13 @@ INPdoOpts( int which; IFanalysis *prm = NULL; - which = -1; - i=0; - for(i=0;inumAnalyses;i++) { - prm = ft_sim->analyses[i]; - if(strcmp(prm->name,"options")==0) { - which = i; - break; - } - } + which = ft_find_analysis("options"); if(which == -1) { optCard->error = INPerrCat(optCard->error,INPmkTemp( "error: analysis options table not found\n")); return; } + prm = ft_sim->analyses[which]; line = optCard->line; INPgetTok(&line,&token,1); /* throw away '.option' */ while (*line) {