From b3c950634fb4ef366a89f4522d0d5e4d96abd934 Mon Sep 17 00:00:00 2001 From: pnenzi Date: Mon, 4 Sep 2000 05:53:10 +0000 Subject: [PATCH] Added some file I forgot to add in the previous commit (was rather big) --- src/spicelib/devices/csw/cswtrunc.c | 53 ++++++++++++++ src/spicelib/devices/sw/swtrunc.c | 53 ++++++++++++++ src/spicelib/parser/inpdoopt.c | 88 +++++++++++++++++++++++ src/spicelib/parser/inppas3.c | 107 ++++++++++++++++++++++++++++ src/spicelib/parser/inppas3.h | 10 +++ 5 files changed, 311 insertions(+) create mode 100644 src/spicelib/devices/csw/cswtrunc.c create mode 100644 src/spicelib/devices/sw/swtrunc.c create mode 100644 src/spicelib/parser/inpdoopt.c create mode 100644 src/spicelib/parser/inppas3.c create mode 100644 src/spicelib/parser/inppas3.h diff --git a/src/spicelib/devices/csw/cswtrunc.c b/src/spicelib/devices/csw/cswtrunc.c new file mode 100644 index 000000000..47ca868a8 --- /dev/null +++ b/src/spicelib/devices/csw/cswtrunc.c @@ -0,0 +1,53 @@ +/********** +Copyright 1990 Regents of the University of California. All rights reserved. +Author: 1985 Thomas L. Quarles +Modified: 2000 AlansFixes +**********/ +/* + */ + +#include "spice.h" +#include +#include "cktdefs.h" +#include "csw\cswdefs.h" +#include "sperror.h" +#include "suffix.h" + + +int +CSWtrunc(inModel,ckt,timeStep) + GENmodel *inModel; + register CKTcircuit *ckt; + register double *timeStep; +{ + register CSWmodel *model = (CSWmodel*)inModel; + register CSWinstance *here; + + double lastChange, maxChange, maxStep, ref; + + for( ; model!= NULL; model = model->CSWnextModel) { + for(here = model->CSWinstances ; here != NULL ; + here = here->CSWnextInstance) { + lastChange = *(ckt->CKTstate0+(here->CSWstate+1)) - + *(ckt->CKTstate1+(here->CSWstate+1)); + if (*(ckt->CKTstate0+(here->CSWstate))==0) { + ref = (model->CSWiThreshold + model->CSWiHysteresis); + if ((*(ckt->CKTstate0+(here->CSWstate+1))0)) { + maxChange = (ref - *(ckt->CKTstate0+(here->CSWstate+1))) * + 0.75 + 0.00005; + maxStep = maxChange/lastChange * ckt->CKTdeltaOld[0]; + if (*timeStep > maxStep) { *timeStep = maxStep; } + } + } else { + ref = (model->CSWiThreshold - model->CSWiHysteresis); + if ((*(ckt->CKTstate0+(here->CSWstate+1))>ref) && (lastChange<0)) { + maxChange = (ref - *(ckt->CKTstate0+(here->CSWstate+1))) * + 0.75 - 0.00005; + maxStep = maxChange/lastChange * ckt->CKTdeltaOld[0]; + if (*timeStep > maxStep) { *timeStep = maxStep; } + } + } + } + } + return(OK); +} diff --git a/src/spicelib/devices/sw/swtrunc.c b/src/spicelib/devices/sw/swtrunc.c new file mode 100644 index 000000000..c75b0e92d --- /dev/null +++ b/src/spicelib/devices/sw/swtrunc.c @@ -0,0 +1,53 @@ +/********** +Copyright 1990 Regents of the University of California. All rights reserved. +Author: 1985 Thomas L. Quarles +Modified: 2000 AlansFixes +**********/ +/* + */ + +#include "spice.h" +#include +#include "cktdefs.h" +#include "sw\swdefs.h" +#include "sperror.h" +#include "suffix.h" + + +int +SWtrunc(inModel,ckt,timeStep) + GENmodel *inModel; + register CKTcircuit *ckt; + register double *timeStep; +{ + register SWmodel *model = (SWmodel*)inModel; + register SWinstance *here; + + double lastChange, maxChange, maxStep, ref; + + for( ; model!= NULL; model = model->SWnextModel) { + for(here = model->SWinstances ; here != NULL ; + here = here->SWnextInstance) { + lastChange = *(ckt->CKTstate0+(here->SWstate+1)) - + *(ckt->CKTstate1+(here->SWstate+1)); + if (*(ckt->CKTstate0+(here->SWstate))==0) { + ref = (model->SWvThreshold + model->SWvHysteresis); + if ((*(ckt->CKTstate0+(here->SWstate+1))0)) { + maxChange = (ref - *(ckt->CKTstate0+(here->SWstate+1))) * + 0.75 + 0.05; + maxStep = maxChange/lastChange * ckt->CKTdeltaOld[0]; + if (*timeStep > maxStep) { *timeStep = maxStep; } + } + } else { + ref = (model->SWvThreshold - model->SWvHysteresis); + if ((*(ckt->CKTstate0+(here->SWstate+1))>ref) && (lastChange<0)) { + maxChange = (ref - *(ckt->CKTstate0+(here->SWstate+1))) * + 0.75 - 0.05; + maxStep = maxChange/lastChange * ckt->CKTdeltaOld[0]; + if (*timeStep > maxStep) { *timeStep = maxStep; } + } + } + } + } + return(OK); +} diff --git a/src/spicelib/parser/inpdoopt.c b/src/spicelib/parser/inpdoopt.c new file mode 100644 index 000000000..447314e1b --- /dev/null +++ b/src/spicelib/parser/inpdoopt.c @@ -0,0 +1,88 @@ +/********** +Copyright 1990 Regents of the University of California. All rights reserved. +Author: 1985 Thomas L. Quarles +Modified: 2000 AlansFixes +**********/ + + /* INPdoOpts(ckt,option card) + * parse the options off of the given option card and add them to + * the given circuit + */ + +#include "ngspice.h" +#include +#include "inpdefs.h" +#include "ifsim.h" +#include "cpdefs.h" +#include "fteext.h" + + +void +INPdoOpts(ckt,anal,optCard,tab) + void *ckt; + void *anal; + card *optCard; + INPtables *tab; +{ + char *line; + char *token; + char *errmsg; + IFvalue *val; + int error; + int i; + int which; + IFanalysis *prm; + + which = -1; + i=0; + for(i=0;inumAnalyses;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;inumParms;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); + fprintf(stderr, "%s\n", optCard->error); + } + } +} diff --git a/src/spicelib/parser/inppas3.c b/src/spicelib/parser/inppas3.c new file mode 100644 index 000000000..d675ea259 --- /dev/null +++ b/src/spicelib/parser/inppas3.c @@ -0,0 +1,107 @@ +/********** +Copyright 1990 Regents of the University of California. All rights reserved. +Author: 1985 Thomas L. Quarles +Modified: AlansFixes +**********/ + +#include +#include +#include +#include + +#include "inppas3.h" + + +/* pass 3 - Read all nodeset and IC lines. All circuit nodes will have been + * created by now, (except for internal device nodes), so any nodeset or IC + * nodes which have to be created are flagged with a warning. + */ + +void +INPpas3(void *ckt, card *data, INPtables *tab, void *task) +{ + +card *current; +int error; /* used by the macros defined above */ +char *line; /* the part of the current line left to parse */ +char *name; /* the node's name */ +char *token; /* a token from the line */ +IFparm *prm; /* pointer to parameter to search through array */ +IFvalue ptemp; /* a value structure to package resistance into */ +int which; /* which analysis we are performing */ +int length; /* length of a name */ +void *node1; /* the first node's node pointer */ + + for(current = data; current != NULL; current = current->nextcard) { + + line = current->line; + INPgetTok(&line,&token,1); + + if (strcmp(token,".nodeset")==0) { + which = -1; + for(prm=ft_sim->nodeParms; + prmnodeParms+ft_sim->numNodeParms;prm++) { + if(strcmp(prm->keyword,"nodeset")==0) { + which=prm->id; + break; + } + } + if(which == -1) { + LITERR("nodeset unknown to simulator. \n") + return; + } + for(;;) { /* loop until we run out of data */ + INPgetTok(&line,&name,1); + /* check to see if in the form V(xxx) and grab the xxx */ + if( *name == (char)NULL) break; /* end of line */ + length = strlen(name); + if( (*name == 'V' || *(name) == 'v') && (length == 1)){ + /* looks like V - must be V(xx) - get xx now*/ + INPgetTok(&line,&name,1); + if (INPtermInsert(ckt,&name,tab,&node1)!=E_EXISTS) + fprintf(stderr, + "Warning : Nodeset on non-existant node - %s\n", name); + ptemp.rValue = INPevaluate(&line,&error,1); + IFC(setNodeParm,(ckt,node1,which,&ptemp,(IFvalue*)NULL)) + continue; + } + LITERR(" Error: .nodeset syntax error.\n") + break; + } + } else if ( (strcmp(token,".ic")==0)){ + /* .ic */ + which = -1; + for(prm=ft_sim->nodeParms; + prmnodeParms+ft_sim->numNodeParms;prm++) { + if(strcmp(prm->keyword,"ic")==0) { + which=prm->id; + break; + } + } + if(which==-1) { + LITERR("ic unknown to simulator. \n") + return; + } + for(;;) { /* loop until we run out of data */ + INPgetTok(&line,&name,1); + /* check to see if in the form V(xxx) and grab the xxx */ + if( *name == 0) break; /* end of line */ + length = strlen(name); + if( (*name == 'V' || *(name) == 'v') && (length == 1)){ + /* looks like V - must be V(xx) - get xx now*/ + INPgetTok(&line,&name,1); + if (INPtermInsert(ckt,&name,tab,&node1)!=E_EXISTS) + fprintf(stderr, + "Warning : IC on non-existant node - %s\n", name); + ptemp.rValue = INPevaluate(&line,&error,1); + IFC(setNodeParm,(ckt,node1,which,&ptemp,(IFvalue*)NULL)) + continue; + } + LITERR(" Error: .ic syntax error.\n") + break; + } + } + } + return; +} + diff --git a/src/spicelib/parser/inppas3.h b/src/spicelib/parser/inppas3.h new file mode 100644 index 000000000..27b46885a --- /dev/null +++ b/src/spicelib/parser/inppas3.h @@ -0,0 +1,10 @@ +/* AlansFixes */ +#ifndef _INPPAS3_H +#define _INPPAS3_H + +#include + +void INPpas3(void *ckt, card *data, INPtables *tab, void *task); + + +#endif