abstraction, new function `ft_find_analysis_parm()'

This commit is contained in:
rlar 2013-07-27 22:26:03 +02:00
parent 9d0500027c
commit fc2dd436fe
6 changed files with 59 additions and 57 deletions

View File

@ -323,9 +323,16 @@ next:
else
flag = 1;
for (i = 0; i < ft_sim->analyses[save]->numParms; i++) {
/* find the parameter */
if (0 == strcmp(token, ft_sim->analyses[save]->analysisParms[i].keyword)) {
i = ft_find_analysis_parm(save, token);
if (i < 0) {
/* didn't find it! */
current->error = INPerrCat
(current->error,
INPmkTemp(" Error: unknown parameter on .sens - ignored \n"));
continue;
}
/* found it, analysis which, parameter i */
if (ft_sim->analyses[save]->analysisParms[i].dataType & IF_FLAG) {
/* one of the keywords! */
@ -345,16 +352,6 @@ next:
if (error)
current->error = INPerrCat(current->error, INPerror(error));
}
break;
}
}
if (i == ft_sim->analyses[save]->numParms) {
/* didn't find it! */
current->error = INPerrCat
(current->error,
INPmkTemp(" Error: unknown parameter on .sens - ignored \n"));
}
}
if ((err = ft_sim->doAnalyses (ckt, 1, ft_curckt->ci_curTask)) != OK) {

View File

@ -427,11 +427,8 @@ if_option(CKTcircuit *ckt, char *name, enum cp_types type, void *value)
return 0;
}
for (i = 0; i < ft_sim->analyses[which]->numParms; i++)
if (eq(ft_sim->analyses[which]->analysisParms[i].keyword, name) &&
(ft_sim->analyses[which]->analysisParms[i].dataType & IF_SET))
break;
if (i == ft_sim->analyses[which]->numParms) {
i = ft_find_analysis_parm(which, name);
if (i < 0 || !(ft_sim->analyses[which]->analysisParms[i].dataType & IF_SET)) {
/* See if this is unsupported or obsolete. */
for (vv = unsupported; *vv; vv++)
if (eq(name, *vv)) {
@ -1212,11 +1209,12 @@ int
if_analQbyName(CKTcircuit *ckt, int which, JOB *anal, char *name, IFvalue *parm)
{
int i;
for (i = 0; i < ft_sim->analyses[which]->numParms; i++)
if (strcmp(ft_sim->analyses[which]->analysisParms[i].keyword, name) == 0)
return (ft_sim->askAnalysisQuest
(ckt, anal, ft_sim->analyses[which]->analysisParms[i].id, parm, NULL));
return (E_BADPARM);
i = ft_find_analysis_parm(which, name);
if (i < 0)
return (E_BADPARM);
return (ft_sim->askAnalysisQuest
(ckt, anal, ft_sim->analyses[which]->analysisParms[i].id, parm, NULL));
}
@ -1291,10 +1289,8 @@ if_getstat(CKTcircuit *ckt, char *name)
}
if (name) {
for (i = 0; i < ft_sim->analyses[which]->numParms; i++)
if (eq(ft_sim->analyses[which]->analysisParms[i].keyword, name))
break;
if (i == ft_sim->analyses[which]->numParms)
i = ft_find_analysis_parm(which, name);
if (i < 0)
return (NULL);
if (ft_sim->askAnalysisQuest (ckt, &(ft_curckt->ci_curTask->taskOptions),
ft_sim->analyses[which]->analysisParms[i].id, &parm,
@ -1729,3 +1725,14 @@ ft_find_analysis(char *name)
return j;
return -1;
}
int
ft_find_analysis_parm(int which, char *name)
{
int i;
for (i = 0; i < ft_sim->analyses[which]->numParms; i++)
if (!strcmp(ft_sim->analyses[which]->analysisParms[i].keyword, name))
return i;
return -1;
}

View File

@ -307,6 +307,7 @@ 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);
extern int ft_find_analysis_parm(int which, char *name);
/* typesdef.c */

View File

@ -516,10 +516,12 @@ dot_sens2(char *line, CKTcircuit *ckt, INPtables *tab, card *current,
while (*line) {
/* read the entire line */
INPgetTok(&line, &token, 1);
for (i = 0; i < ft_sim->analyses[which]->numParms; i++) {
/* find the parameter */
if (0 == strcmp(token,
ft_sim->analyses[which]->analysisParms[i].keyword)) {
i = ft_find_analysis_parm(which, token);
if (i < 0) {
/* didn't find it! */
LITERR(" Error: unknown parameter on .sens-ignored \n");
continue;
}
/* found it, analysis which, parameter i */
if (ft_sim->analyses[which]->analysisParms[i].dataType & IF_FLAG) {
/* one of the keywords! */
@ -546,13 +548,6 @@ dot_sens2(char *line, CKTcircuit *ckt, INPtables *tab, card *current,
INPerrCat(current->error, INPerror(error));
}
break;
}
}
if (i == ft_sim->analyses[which]->numParms) {
/* didn't find it! */
LITERR(" Error: unknown parameter on .sens-ignored \n");
}
}
return (0);
}

View File

@ -17,16 +17,19 @@ INPapName(CKTcircuit *ckt, int type, JOB *analPtr, char *parmname,
{
int i;
if (parmname && ft_sim->analyses[type]) {
for (i = 0; i < ft_sim->analyses[type]->numParms; i++)
if (strcmp(parmname,
ft_sim->analyses[type]->analysisParms[i].keyword) ==
0) {
return ft_sim->setAnalysisParm (ckt, analPtr,
ft_sim->analyses[type]->analysisParms[i].id,
value,
NULL);
}
}
return (E_BADPARM);
if (!parmname)
return (E_BADPARM);
if (!ft_sim->analyses[type])
return (E_BADPARM);
i = ft_find_analysis_parm(type, parmname);
if (i < 0)
return (E_BADPARM);
return ft_sim->setAnalysisParm (ckt, analPtr,
ft_sim->analyses[type]->analysisParms[i].id,
value,
NULL);
}

View File

@ -44,8 +44,8 @@ INPdoOpts(
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) {
i = ft_find_analysis_parm(which, token);
if(i >= 0) {
if(!(prm->analysisParms[i].dataType & IF_UNIMP_MASK)) {
errmsg = TMALLOC(char, 45 + strlen(token));
(void) sprintf(errmsg,
@ -53,8 +53,10 @@ INPdoOpts(
optCard->error = INPerrCat(optCard->error,errmsg);
val = INPgetValue(ckt,&line,
prm->analysisParms[i].dataType, tab);
break;
continue;
}
}
if(i >= 0) {
if(prm->analysisParms[i].dataType & IF_SET) {
val = INPgetValue(ckt,&line,
prm->analysisParms[i].dataType&IF_VARTYPES, tab);
@ -66,15 +68,12 @@ INPdoOpts(
"Warning: can't set option %s\n", token);
optCard->error = INPerrCat(optCard->error, errmsg);
}
break;
continue;
}
}
}
if(i == prm->numParms) {
errmsg = TMALLOC(char, 100);
(void) strcpy(errmsg," Error: unknown option - ignored\n");
optCard->error = INPerrCat(optCard->error,errmsg);
fprintf(stderr, "%s\n", optCard->error);
}
}
}