home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-28 | 57.3 KB | 1,995 lines |
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!haven.umd.edu!darwin.sura.net!ukma!cs.widener.edu!dsinc!ub!galileo.cc.rochester.edu!ee.rochester.edu!rbc!al
- From: al@rbc.uucp (Al Davis)
- Newsgroups: alt.sources
- Subject: ACS circuit simulator part 11/20
- Message-ID: <1993Jan27.040710.11435@rbc.uucp>
- Date: 27 Jan 93 04:07:10 GMT
- Sender: al@rbc.uucp (Al Davis)
- Organization: Huh?
- Lines: 1984
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # src/branch.c
- # src/cmath.c
- # src/crtset.c
- # src/ctof.c
- # src/ctoi.c
- # src/ctostr.c
- # src/dc.c
- # src/dc_setup.c
- # src/dc_sweep.c
- # src/dealloc.c
- # src/delete.c
- # src/dev.c
- # src/d_admit.c
- # This archive created: Tue Jan 26 22:51:00 1993
- export PATH; PATH=/bin:$PATH
- if test -f 'src/branch.c'
- then
- echo shar: will not over-write existing file "'src/branch.c'"
- else
- cat << \SHAR_EOF > 'src/branch.c'
- /* branch 04/18/92
- * Copyright 1983-1992 Albert Davis
- * accesses branch array.
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- branch_t *firstbranch_dev(void);
- branch_t *firstbranch_all(void);
- branch_t *nextbranch_dev(const branch_t*);
- branch_t *nextbranch_all(const branch_t*);
- branch_t *lastbranch_dev(void);
- branch_t *lastbranch_all(void);
- branch_t *insertbranch(branch_t*);
- int deletebranch(branch_t*);
- static void freelist(generic_t**);
- /*--------------------------------------------------------------------------*/
- extern const char e_int[];
- static branch_t ends = {(generic_t*)NULL, sizeof(branch_t),
- (functions_t*)NULL, &ends, &ends, &ends, &ends, /*more*/};
- /*--------------------------------------------------------------------------*/
- /* firstbranch_dev: return pointer to first device in the parts list
- * pointer to ends if empty list, or no devices
- */
- branch_t *firstbranch_dev()
- {
- branch_t *x;
- for (x = ends.next; exists(x) && !isdevice(x); x = x->next)
- /* skip */;
- return x;
- }
- /*--------------------------------------------------------------------------*/
- /* firstbranch_all: return pointer to first item in the parts list
- * pointer to ends if empty list
- */
- branch_t *firstbranch_all()
- {
- return ends.next;
- }
- /*--------------------------------------------------------------------------*/
- /* nextbranch_dev: return pointer to next non-comment branch in list
- */
- branch_t *nextbranch_dev(x)
- const branch_t *x;
- {
- branch_t *y;
- if (!x)
- return &ends;
- while (y = x->next, !isdevice(y))
- x = y;;
- return y;
- }
- /*--------------------------------------------------------------------------*/
- /* nextbranch_all: return pointer to next line in netlist (incl comments)
- * pointer to ends if at end of list or null arg
- */
- branch_t *nextbranch_all(x)
- const branch_t *x;
- {
- return (x) ? x->next : &ends;
- }
- /*--------------------------------------------------------------------------*/
- /* lastbranch_dev: return pointer to last device in the parts list
- * pointer to ends if empty list, or no devices
- */
- branch_t *lastbranch_dev()
- {
- branch_t *x;
- for (x = ends.prev; exists(x) && !isdevice(x); x = x->prev)
- /* skip */;
- return x;
- }
- /*--------------------------------------------------------------------------*/
- /* lastbranch_all: return pointer to last item in the parts list
- * pointer to ends if empty list
- */
- branch_t *lastbranch_all()
- {
- return ends.prev;
- }
- /*--------------------------------------------------------------------------*/
- /* insertbranch: insert a branch into the parts list
- * either pre or post inserts, depending....
- * specify after, inserts after that one (post)
- * specify before, inserts before that one (pre)
- * specify both (bad. don't do it) after wins.
- * specify neither, makes self link, for a new list.
- * then set up same-type links
- * if one of the links is done, fill in the others
- * else make same type point to self
- * actually inserts the branch passed in into the list. no copies.
- * links are never null, after this returns
- * returns pointer to actual new element
- */
- branch_t *insertbranch(brh)
- branch_t *brh;
- {
- if (brh->prev && brh->next)
- error(bERROR, e_int, "bad branch link");
- else if (brh->prev)
- brh->next = brh->prev->next;
- else if (brh->next)
- brh->prev = brh->next->prev;
- else /* make self link */
- brh->prev = brh->next = brh;
-
- brh->next->prev = brh->prev->next = brh;
-
- if (brh->stprev && brh->stnext){
- if (brh->stprev != brh || brh->stnext != brh)
- error(bERROR, e_int, "bad st link");
- }else if (brh->stprev){
- brh->stnext = brh->stprev->stnext;
- }else if (brh->stnext){
- brh->stprev = brh->stnext->stprev;
- }else{ /* make self link */
- brh->stprev = brh->stnext = brh;
- }
-
- brh->stnext->stprev = brh->stprev->stnext = brh;
- return brh;
- }
- /*--------------------------------------------------------------------------*/
- /* deletebranch: delete a branch from parts list
- * returns count actually deleted (either 1 or 0)
- * updates pointers, first, last, etc.
- * so list is consistent on return
- */
- int deletebranch(brh) /* delete a branch. */
- branch_t *brh; /* return count actually deleted */
- {
- if (exists(brh)){
- brh->next->prev = brh->prev;
- brh->prev->next = brh->next;
- brh->stnext->stprev = brh->stprev;
- brh->stprev->stnext = brh->stnext;
- freelist((generic_t**)&brh);
- return 1;
- }else{
- return 0;
- }
- }
- /*--------------------------------------------------------------------------*/
- /* freelist: free a (singly linked) list of structures (recursive)
- * struct generic is an attempt to tame type clashes
- */
- static void freelist(x)
- generic_t **x;
- {
- if ((*x)->x && (*x)->x != (*x)->x->x)
- freelist(&((*x)->x));
- qfree((void**)x);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/cmath.c'
- then
- echo shar: will not over-write existing file "'src/cmath.c'"
- else
- cat << \SHAR_EOF > 'src/cmath.c'
- /* cmath 12/31/92
- * Copyright 1983-1992 Albert Davis
- * complex math
- */
- #include "ecah.h"
- #include "declare.h"
- /*LINTLIBRARY*/
- /*--------------------------------------------------------------------------*/
- complex_t cxadd(double,double,double,double);
- complex_t cxsub(double,double,double,double);
- complex_t cxmul(double,double,double,double);
- complex_t cxdiv(double,double,double,double);
- complex_t cxflip(double,double);
- complex_t cadd(complex_t,complex_t);
- complex_t csub(complex_t,complex_t);
- complex_t cmul(complex_t,complex_t);
- complex_t ccmul(complex_t,complex_t);
- complex_t cdiv(complex_t,complex_t);
- complex_t cflip(complex_t);
- /*--------------------------------------------------------------------------*/
- complex_t cxadd(x1,y1,x2,y2)
- double x1,y1,x2,y2;
- {
- complex_t z;
- z.x = x1 + x2;
- z.y = y1 + y2;
- return z;
- }
- /*--------------------------------------------------------------------------*/
- complex_t cxsub(x1,y1,x2,y2)
- double x1,y1,x2,y2;
- {
- complex_t z;
- z.x = x1 - x2;
- z.y = y1 - y2;
- return z;
- }
- /*--------------------------------------------------------------------------*/
- complex_t cxmul(x1,y1,x2,y2)
- double x1,y1,x2,y2;
- {
- complex_t z;
- z.x = x1*x2 - y1*y2 ;
- z.y = x1*y2 + y1*x2 ;
- return z;
- }
- /*--------------------------------------------------------------------------*/
- complex_t cxdiv(x1,y1,x2,y2)
- double x1,y1,x2,y2;
- {
- complex_t z;
- double d;
- d = x2*x2 + y2*y2;
- z.x = (x1*x2 + y1*y2) / d;
- z.y = (y1*x2 - x1*y2) / d;
- return z;
- }
- /*--------------------------------------------------------------------------*/
- complex_t cxflip(x2,y2)
- double x2,y2;
- {
- complex_t z;
- double d;
- d = x2*x2 + y2*y2;
- z.x = x2 / d;
- z.y = -y2 / d;
- return z;
- }
- /*--------------------------------------------------------------------------*/
-
- complex_t cadd(a,b)
- complex_t a,b;
- {
- complex_t z;
- z.x = a.x + b.x;
- z.y = a.y + b.y;
- return z;
- }
- /*--------------------------------------------------------------------------*/
- complex_t csub(a,b)
- complex_t a,b;
- {
- complex_t z;
- z.x = a.x - b.x;
- z.y = a.y - b.y;
- return z;
- }
- /*--------------------------------------------------------------------------*/
- complex_t cmul(a,b)
- complex_t a,b;
- {
- complex_t z;
- z.x = a.x*b.x - a.y*b.y ;
- z.y = a.x*b.y + a.y*b.x ;
- return z;
- }
- /*--------------------------------------------------------------------------*/
- complex_t ccmul(a,b) /* conjugate multiply */
- complex_t a,b;
- {
- complex_t z;
- z.x = a.x*b.x + a.y*b.y ;
- z.y = a.y*b.x - a.x*b.y ;
- return z;
- }
- /*--------------------------------------------------------------------------*/
- complex_t cdiv(a,b)
- complex_t a,b;
- {
- complex_t z;
- double d;
- d = b.x*b.x + b.y*b.y;
- z.x = (a.x*b.x + a.y*b.y) / d;
- z.y = (a.y*b.x - a.x*b.y) / d;
- return z;
- }
- /*--------------------------------------------------------------------------*/
- complex_t cflip(b)
- complex_t b;
- {
- complex_t z;
- double d;
- d = b.x*b.x + b.y*b.y;
- z.x = b.x / d;
- z.y = -b.y / d;
- return z;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/crtset.c'
- then
- echo shar: will not over-write existing file "'src/crtset.c'"
- else
- cat << \SHAR_EOF > 'src/crtset.c'
- /* crtset 10/08/91
- * Copyright 1983-1992 Albert Davis
- * set up crt plotting parameters
- */
- #include "ecah.h"
- #include "error.h"
- #include "io.h"
- #include "pixelh.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_crtset(const char*,int*);
- static void setq(const char*,int*,int*);
- int testcrt(void);
- struct graph *initcrt(void);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
-
- extern struct graph *initsun();
- extern struct graph *initibm();
- extern struct graph *initherc();
- extern struct graph *initz100();
- extern struct graph *initbasic();
- extern struct graph *initpostscript();
- extern struct graph *initunix();
- extern struct graph *initx();
- static int crttype;
- static struct graph d;
- /*--------------------------------------------------------------------------*/
- void cmd_crtset(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- static int sw_c, sh_c;
- static int beenhere = NO;
-
- if (!beenhere)
- {
- d.sw = 640;
- d.sh = 200;
- sw_c = 80;
- sh_c = 25;
- d.ppc = d.sw / sw_c;
- d.lpc = d.sh / sh_c;
- d.gmode = 6;
- d.tmode = 2;
- d.pri = 1;
- d.sec = -2;
- d.grid = -8;
- d.back = 0;
- d.palette = 0;
- }
- beenhere = YES;
-
- if (pmatch(cmd,cnt,"Ascii"))
- crttype = '\0';
- else if (pmatch(cmd,cnt,"None"))
- crttype = '\0';
- else if (pmatch(cmd,cnt,"Basic"))
- crttype = 'b';
- else if (pmatch(cmd,cnt,"Hercules"))
- crttype = 'h';
- else if (pmatch(cmd,cnt,"Ibm"))
- crttype = 'i';
- else if (pmatch(cmd,cnt,"Postscript"))
- crttype = 'p';
- else if (pmatch(cmd,cnt,"Sun"))
- crttype = 's';
- else if (pmatch(cmd,cnt,"Unix"))
- crttype = 'u';
- else if (pmatch(cmd,cnt,"X"))
- crttype = 'x';
- else if (pmatch(cmd,cnt,"Zenith"))
- crttype = 'z';
- else if (!cmd[*cnt])
- {
- mprintf(io.mstdout,"%c\n", crttype);
- mprintf(io.mstdout,"%dx%d, %dx%d\n", d.sw, d.sh, sw_c, sh_c);
- mprintf(io.mstdout,"%d, %d\n", d.gmode, d.tmode);
- mprintf(io.mstdout,"%d, %d, %d, %d\n", d.pri, d.sec, d.grid, d.back);
- mprintf(io.mstdout,"%d\n", d.palette);
- return ;
- }
- else
- syntax(cmd,cnt,bERROR);
-
- setq(cmd,cnt,&d.sw);
- setq(cmd,cnt,&d.sh);
- setq(cmd,cnt,&sw_c);
- setq(cmd,cnt,&sh_c);
- d.ppc = d.sw / sw_c;
- d.lpc = d.sh / sh_c;
- setq(cmd,cnt,&d.gmode);
- setq(cmd,cnt,&d.tmode);
- setq(cmd,cnt,&d.pri);
- setq(cmd,cnt,&d.sec);
- setq(cmd,cnt,&d.grid);
- setq(cmd,cnt,&d.back);
- setq(cmd,cnt,&d.palette);
- }
- /*--------------------------------------------------------------------------*/
- static void setq(cmd,cnt,value)
- const char *cmd;
- int *cnt;
- int *value;
- {
- skipbl(cmd,cnt);
- if (isdigit(cmd[*cnt]) || cmd[*cnt]=='-')
- *value = (int)ctof(cmd,cnt);
- else
- skiparg(cmd,cnt);
- }
- /*--------------------------------------------------------------------------*/
- int testcrt()
- {
- return crttype;
- }
- /*--------------------------------------------------------------------------*/
- struct graph *initcrt()
- {
- switch (crttype)
- {
- case 'b':
- return initbasic(&d);
- #ifdef MSDOS
- case 'i':
- return initibm(&d);
- #endif
- #ifdef HERCULES
- case 'h':
- return initherc(&d);
- #endif
- case 'p':
- return initpostscript(&d);
- #ifdef SUNVIEW
- case 's':
- return initsun(&d);
- #endif
- case 'u':
- return initunix(&d);
- case 'x':
- return initx(&d);
- #ifdef MSDOS
- case 'z':
- return initz100(&d);
- #endif
- default:
- return (struct graph*)NULL;
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/ctof.c'
- then
- echo shar: will not over-write existing file "'src/ctof.c'"
- else
- cat << \SHAR_EOF > 'src/ctof.c'
- /* ctof 04/02/92
- * Copyright 1983-1992 Albert Davis
- * get double from string
- * update string pointer
- * return double number if got, else 0
- * supports letter multipliers (spice style)
- * skips trailing letters (10uhenries == 10u)
- * skips trailing spaces and one comma
- * pointer points to char following comma
- * or first non-space following number just got
- * or first non-space (if non-number)
- */
- #include "ecah.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- double ctof(const char*,int*);
- double x10(int);
- /*--------------------------------------------------------------------------*/
- double ctof(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- double val, power;
- int sign;
- char pc;
-
- skipbl(cmd,cnt);
- if (!isfloat(cmd[*cnt])){
- skipcom(cmd,cnt);
- return 0.;
- }
-
- sign = 1; /* sign */
- if (cmd[*cnt]=='+'){
- (*cnt)++;
- }else if (cmd[*cnt]=='-'){
- sign = -1;
- (*cnt)++;
- }
-
- for (val=0.0; isdigit(cmd[*cnt]); (*cnt)++) /* up to dec pt */
- val = 10.0 * val + (cmd[*cnt]-'0');
-
- if (cmd[*cnt] == '.') /* dec pt */
- (*cnt)++;
-
- for (power=1.; isdigit(cmd[*cnt]); (*cnt)++){ /* after dec pt */
- val = 10.0 * val + (cmd[*cnt]-'0');
- power *= .1;
- }
-
- pc = to_upper(cmd[*cnt]);
- (*cnt)++;
- if (pc == 'E'){ /* exponent: E form */
- int es, expo;
- es = 1;
- if (cmd[*cnt]=='+'){
- (*cnt)++;
- }else if (cmd[*cnt]=='-'){
- (*cnt)++;
- es = -1;
- }
- for (expo=0; isdigit(cmd[*cnt]); (*cnt)++)
- expo = 10 * expo + (cmd[*cnt]-'0');
- expo *= es;
- power *= x10(expo);
- }else if (pc == 'M'){ /* M is special */
- int pc2;
- pc2 = to_upper(cmd[*cnt]);
- (*cnt)++;
- if (pc2 == 'E'){ /* meg */
- power *= 1e6;
- }else if (pc2 == 'I'){ /* mil */
- power *= 25.4e-6;
- }else{ /* plain m (milli) */
- power *= 1e-3;
- (*cnt)--;
- }
- }else if (pc == 'U'){ /* other letters */
- power *= 1e-6;
- }else if (pc == 'N'){
- power *= 1e-9;
- }else if (pc == 'P'){
- power *= 1e-12;
- }else if (pc == 'F'){
- power *= 1e-15;
- }else if (pc == 'K'){
- power *= 1e3;
- }else if (pc == 'G'){
- power *= 1e9;
- }else if (pc == 'T'){
- power *= 1e12;
- }else{
- (*cnt)--;
- }
- while (isalpha(cmd[*cnt])) /* skip letters */
- (*cnt)++;
-
- skipcom(cmd,cnt);
- return (sign*val*power);
- }
- /*--------------------------------------------------------------------------*/
- double x10(ex)
- int ex;
- {
- double r;
- r = 1.;
- for (; ex>0; ex-- )
- r *= 10.0;
- for (; ex<0; ex++ )
- r *= .1;
- return r;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/ctoi.c'
- then
- echo shar: will not over-write existing file "'src/ctoi.c'"
- else
- cat << \SHAR_EOF > 'src/ctoi.c'
- /* ctoi 04/02/92
- * Copyright 1983-1992 Albert Davis
- * get integer from string
- * update string pointer
- * return integer if got, else 0
- * pointer points to char following number just got
- * or first non-space
- */
- #include "ecah.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- int ctoi(const char*,int*);
- /*--------------------------------------------------------------------------*/
- /* ctoi: character input to integer
- * Returns signed integer, or 0 if the string is not a number.
- * Input must be integer: no multipliers, no decimal point.
- * Dot or letter belongs to the next token.
- */
- int ctoi(cmd,cnt)
- const char *cmd ;
- int *cnt ;
- {
- int val, sign ;
-
- skipbl(cmd,cnt) ;
-
- sign = 1 ; /* sign */
- if (cmd[*cnt]=='+'){
- (*cnt)++ ;
- }else if (cmd[*cnt]=='-'){
- sign = -1 ;
- (*cnt)++ ;
- }
-
- for ( val=0 ; isdigit(cmd[*cnt]) ; (*cnt)++ )
- val = 10 * val + (cmd[*cnt]-'0') ;
-
- skipcom(cmd,cnt) ;
- return val * sign ;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/ctostr.c'
- then
- echo shar: will not over-write existing file "'src/ctostr.c'"
- else
- cat << \SHAR_EOF > 'src/ctostr.c'
- /* ctostr.c 04/02/92
- * Copyright 1983-1992 Albert Davis
- * get string from string
- */
- #include "ecah.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- char *ctostr(const char*,int*,char*,int);
- /*--------------------------------------------------------------------------*/
- /* ctostr: character input to string
- * scan (and eat) an input string (cmd) using index (cnt).
- * result in (des) (null terminated).
- * max length (actual char count) is (len).
- * (des) must be at least (len)+1 characters long.
- * (cmd) unchanged. (*cnt) updated to point to next argument.
- * skips leading whitespace. skips trailing whitespace and comma
- * skips parts of input word too big for destination
- */
- char *ctostr(cmd,cnt,des,len)
- const char *cmd;
- int *cnt;
- char *des;
- int len;
- {
- char chr;
- int dind;
-
- skipbl(cmd,cnt);
- for (dind = 0; dind < len; (*cnt)++, dind++){
- chr = cmd[*cnt];
- if (isterm(chr))
- break;
- des[dind] = chr;
- }
- des[dind] = '\0';
-
- while (!isterm(cmd[*cnt]))
- (*cnt)++;
- skipcom(cmd,cnt);
- return des;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/dc.c'
- then
- echo shar: will not over-write existing file "'src/dc.c'"
- else
- cat << \SHAR_EOF > 'src/dc.c'
- /* dc 03/26/92
- * Copyright 1983-1992 Albert Davis
- * dc analysis top
- */
- #include "ecah.h"
- #include "branch.h"
- #include "dc.h"
- #include "mode.h"
- #include "options.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_dc(const char*,int*);
- void cmd_op(const char*,int*);
- /*--------------------------------------------------------------------------*/
- extern const struct options opt;
- extern struct status stats;
-
- extern int run_mode; /* variations on handling of dot cmds */
- extern int sim_mode; /* simulation type (AC, DC, ...) */
- extern double trtime; /* transient analysis time, -1 means dc */
- /*--------------------------------------------------------------------------*/
- void cmd_dc(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- static dc_t dc;
-
- sim_mode = sDC;
- time_zstart(&(stats.total));
- time_zstart(&(stats.dc));
- stats.iter[sim_mode] = 0;
- stats.iter[iPRINTSTEP] = 0;
-
- trtime = -1.;
-
- allocate(sim_mode);
- dc_setup(cmd,cnt,&dc);
- if (run_mode != rEXECUTE)
- return;
- dc_sweep(&dc);
-
- time_stop(&(stats.dc));
- time_stop(&(stats.total));
- }
- /*--------------------------------------------------------------------------*/
- void cmd_op(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- static dc_t op;
-
- sim_mode = sOP;
- time_zstart(&(stats.total));
- time_zstart(&(stats.op));
- stats.iter[sim_mode] = 0;
- stats.iter[iPRINTSTEP] = 0;
-
- trtime = -1.;
-
- allocate(sim_mode);
- op_setup(cmd,cnt,&op);
- if (run_mode != rEXECUTE)
- return;
- dc_sweep(&op);
-
- time_stop(&(stats.op));
- time_stop(&(stats.total));
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/dc_setup.c'
- then
- echo shar: will not over-write existing file "'src/dc_setup.c'"
- else
- cat << \SHAR_EOF > 'src/dc_setup.c'
- /* dc_setup 12/29/92
- * Copyright 1983-1992 Albert Davis
- * dc analysis setup
- */
- #include "ecah.h"
- #include "argparse.h"
- #include "branch.h"
- #include "dc.h"
- #include "dev.h"
- #include "error.h"
- #include "io.h"
- #include "mode.h"
- #include "options.h"
- #include "worst.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void dc_finish(void);
- void op_setup(const char*,int*,dc_t*);
- void dc_setup(const char*,int*,dc_t*);
- static void dc_options(const char*,int*,dc_t*);
- static void dcoptby(const char*,int*);
- static void dcoptdecade(const char*,int*);
- static void dcopttimes(const char*,int*);
- /*--------------------------------------------------------------------------*/
- extern struct ioctrl io;
- extern const struct options opt;
- extern int sim_mode; /* simulation type (AC, DC, ...) */
- extern int worstcase; /* worst case, monte carlo mode (enum type, worst.h)*/
- extern double temp; /* actual ambient temperature, kelvin */
- extern double genout; /* output of signal generator (ckt input) */
- static dc_t *par; /* latest parameters for arg passing and "finish" */
- static branch_t stash[DCNEST]; /* store std values of elements being swept */
- /*--------------------------------------------------------------------------*/
- void dc_finish()
- {
- int ii;
- for (ii = 0; ii < DCNEST; ii++){
- if (par && exists(par->zap[ii])){
- par->zap[ii]->subckt = stash[ii].subckt;
- par->zap[ii]->x = stash[ii].x;
- par->zap[ii]->val = stash[ii].val;
- expand_branch(par->zap[ii]);
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- void op_setup(cmd,cnt,dc)
- const char *cmd;
- int *cnt;
- dc_t *dc;
- {
- dc->zap[0] = (branch_t*)NULL;
- dc->sweep[0] = &temp;
- dc->start[0] = (isfloat(cmd[*cnt])) ? ctof(cmd,cnt)-ABS_ZERO : opt.tempamb;
- dc->stop[0] = (isfloat(cmd[*cnt])) ? ctof(cmd,cnt)-ABS_ZERO : dc->start[0];
- dc->step[0] = 0.;
- genout = 0.;
- dc_options(cmd,cnt,dc);
- if (dc->step[0] == 0.){
- dc->step[0] = dc->stop[0] - dc->start[0];
- dc->linswp[0] = YES;
- }
- }
- /*--------------------------------------------------------------------------*/
- void dc_setup(cmd,cnt,dc)
- const char *cmd;
- int *cnt;
- dc_t *dc;
- {
- branch_t *target;
-
- target = findbranch(cmd,cnt,firstbranch_all(),lastbranch_all());
- if (exists(target)){
- dc->zap[0] = target;
- stash[0] = *(dc->zap[0]);
- dc->zap[0]->x = (generic_t*)NULL;
- dc->zap[0]->subckt = (branch_t*)NULL;
- if (isfloat(cmd[*cnt])){
- dc->sweep[0] = &(dc->zap[0]->val);
- dc->start[0] = ctof(cmd,cnt);
- dc->stop[0] = (isfloat(cmd[*cnt])) ? ctof(cmd,cnt) : dc->start[0];
- dc->step[0] = 0.;
- }else{
- dc->sweep[0] = (double*)NULL;
- syntax(cmd,cnt,bERROR);
- }
- }else if (isfloat(cmd[*cnt])){
- dc->zap[0] = (branch_t*)NULL;
- dc->sweep[0] = &genout;
- dc->start[0] = ctof(cmd,cnt);
- dc->stop[0] = (isfloat(cmd[*cnt])) ? ctof(cmd,cnt) : dc->start[0];
- dc->step[0] = 0.;
- }
- if (!dc->sweep[0])
- error(bERROR, "dc: nothing to sweep\n");
-
- genout = 0.;
- temp = opt.tempamb;
- dc_options(cmd,cnt,dc);
- if (dc->step[0] == 0.){
- dc->step[0] = dc->stop[0] - dc->start[0];
- dc->linswp[0] = YES;
- }
- }
- /*--------------------------------------------------------------------------*/
- static void dc_options(cmd,cnt,dc)
- const char *cmd;
- int *cnt;
- dc_t *dc;
- {
- par = dc;
- io.where |= io.mstdout;
- io.ploton = io.plotset;
- dc->loop = dc->reverse = dc->cont = dc->watch = worstcase = NO;
- for (;;){
- if (argparse(cmd,cnt,REPEAT,
- "*", aFUNCTION, dcopttimes,
- "ACMAx", aENUM, &worstcase, wMAXAC,
- "ACMIn", aENUM, &worstcase, wMINAC,
- "Ambient", aODOUBLE, &temp, opt.tempamb,
- "By", aFUNCTION, dcoptby,
- "Continue", aENUM, &dc->cont, YES,
- "DCMAx", aENUM, &worstcase, wMAXDC,
- "DCMIn", aENUM, &worstcase, wMINDC,
- "Decade", aFUNCTION, dcoptdecade,
- "LAg", aENUM, &worstcase, wLAG,
- "LEad", aENUM, &worstcase, wLEAD,
- "LOop", aENUM, &dc->loop, YES,
- "MAx", aENUM, &worstcase, wMAXDC,
- "MIn", aENUM, &worstcase, wMINDC,
- "NOPlot", aENUM, &io.ploton, NO,
- "PLot", aENUM, &io.ploton, YES,
- "Reftemp", aODOUBLE, &temp, opt.tnom,
- "REverse", aENUM, &dc->reverse, YES,
- "SEnsitivity", aENUM, &worstcase, wSENS,
- "Temperature", aODOUBLE, &temp, -ABS_ZERO,
- "TImes", aFUNCTION, dcopttimes,
- "WAtch", aENUM, &dc->watch, YES,
- ""))
- ;
- else if (isfloat(cmd[*cnt]))
- dcoptby(cmd,cnt);
- else if (outset(cmd,cnt,(char*)NULL,((sim_mode==sOP)?"bi ":"dc ")))
- ;
- else{
- syntax(cmd,cnt,bWARNING);
- break;
- }
- }
- initio(io.where,(FILE*)NULL);
- if (worstcase == wRAND || worstcase == wWORST)
- io.ploton = NO;
- }
- /*--------------------------------------------------------------------------*/
- static void dcoptby(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- par->step[0] = ctof(cmd,cnt);
- par->linswp[0] = YES;
- if (par->step[0] == 0.)
- par->step[0] = par->stop[0] - par->start[0];
- }
- /*--------------------------------------------------------------------------*/
- static void dcoptdecade(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- double junk;
- junk = fabs(ctof(cmd,cnt));
- if (junk == 0.)
- junk = 1.;
- junk = pow(10., 1./junk);
- par->step[0] = junk;
- par->linswp[0] = NO;
- }
- /*--------------------------------------------------------------------------*/
- static void dcopttimes(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- par->step[0] = fabs(ctof(cmd,cnt));
- par->linswp[0] = NO;
- if (par->step[0] == 0. && par->start[0] != 0.)
- par->step[0] = par->stop[0] / par->start[0];
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/dc_sweep.c'
- then
- echo shar: will not over-write existing file "'src/dc_sweep.c'"
- else
- cat << \SHAR_EOF > 'src/dc_sweep.c'
- /* dc_sweep 12/29/92
- * Copyright 1983-1992 Albert Davis
- * dc analysis sweep
- */
- #include "ecah.h"
- #include "branch.h"
- #include "convstat.h"
- #include "dev.h"
- #include "dc.h"
- #include "error.h"
- #include "io.h"
- #include "mode.h"
- #include "options.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void dc_sweep(dc_t*);
- static void dc_first(dc_t*,int);
- static int dc_next(dc_t*,int);
- /*--------------------------------------------------------------------------*/
- extern struct ioctrl io;
- extern const struct options opt;
- extern struct status stats;
- extern const int sim_mode; /* simulation type (AC, DC, ...) */
- extern int currents_bad;
- /*--------------------------------------------------------------------------*/
- void dc_sweep(dc)
- dc_t *dc;
- {
- int conv;
-
- tr_head(dc->start[0], dc->stop[0], dc->linswp[0], " ");
- currents_bad = YES;
- if (dc->cont){
- trestor();
- }
-
- dc_first(dc,0);
- io.suppresserrors = !dc->watch;
- conv = tr_solve(opt.itl[1]);
- if (conv != cGOOD)
- error(bWARNING, "did not converge\n");
- dc_out(dc);
-
- while (dc_next(dc,0)){
- io.suppresserrors = !dc->watch;
- conv = tr_solve(opt.itl[2]);
- if (conv != cGOOD)
- error(bWARNING, "did not converge\n");
- dc_out(dc);
- }
- }
- /*--------------------------------------------------------------------------*/
- static void dc_first(dc,ii)
- dc_t *dc;
- int ii;
- {
- *dc->sweep[ii] = dc->start[ii];
- expand_branch(dc->zap[ii]);
-
- if (dc->reverse){
- dc->reverse = NO;
- while (dc_next(dc,ii))
- /* nothing */;
- dc->reverse = YES;
- dc_next(dc,ii);
- }
- dc->printnow = YES;
- }
- /*--------------------------------------------------------------------------*/
- static int dc_next(dc,ii)
- dc_t *dc;
- int ii;
- {
- int ok = NO;
- if (dc->linswp[ii]){
- double fudge = dc->step[ii] / 10.;
- if (dc->step[ii] == 0.){
- ok = NO;
- }else{
- if (!dc->reverse){
- *(dc->sweep[ii]) += dc->step[ii];
- ok=inorder(dc->start[ii]-fudge,*(dc->sweep[ii]),dc->stop[ii]+fudge);
- if (!ok && dc->loop)
- dc->reverse = YES;
- }
- if (dc->reverse){
- *(dc->sweep[ii]) -= dc->step[ii];
- ok=inorder(dc->start[ii]-fudge,*(dc->sweep[ii]),dc->stop[ii]+fudge);
- }
- }
- }else{
- double fudge = pow(dc->step[ii], .1);
- if (dc->step[ii] == 1.){
- ok = NO;
- }else{
- if (!dc->reverse){
- *(dc->sweep[ii]) *= dc->step[ii];
- ok=inorder(dc->start[ii]/fudge,*(dc->sweep[ii]),dc->stop[ii]*fudge);
- if (!ok && dc->loop)
- dc->reverse = YES;
- }
- if (dc->reverse){
- *(dc->sweep[ii]) /= dc->step[ii];
- ok=inorder(dc->start[ii]/fudge,*(dc->sweep[ii]),dc->stop[ii]*fudge);
- }
- }
- }
- expand_branch(dc->zap[ii]);
- dc->printnow = YES;
- return ok;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/dealloc.c'
- then
- echo shar: will not over-write existing file "'src/dealloc.c'"
- else
- cat << \SHAR_EOF > 'src/dealloc.c'
- /* dealloc 12/30/92
- * Copyright 1983-1992 Albert Davis
- * Deallocates all heap space except the main parts list
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "nodestat.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void dealloc(int);
- /*--------------------------------------------------------------------------*/
- extern double last_time;
- extern double *volts;
- extern int *basnode; /* lowest node connected to this node*/
- extern int *nm; /* node map table */
- extern double **rerow, **imrow; /* array of row pointers */
- extern double **recol, **imcol; /* array of column pointers */
- extern double *recon,*imcon,*oldcon,*fwcon;/* constant terms */
- extern double *reals, *imags; /* big array allocation bases */
- extern complex_t *fodata; /* for fourier analysis */
- extern struct nodestat *nstat; /* node status flags */
- /*--------------------------------------------------------------------------*/
- void dealloc(all)
- int all;
- {
- if (all){
- last_time = 0.;
- qfree((void**)&volts);
- qfree((void**)&basnode);
- qfree((void**)&nm);
- }
- qfree((void**)&rerow);
- qfree((void**)&imrow);
- qfree((void**)&recol);
- qfree((void**)&imcol);
- qfree((void**)&reals);
- qfree((void**)&imags);
- qfree((void**)&recon);
- qfree((void**)&imcon);
- qfree((void**)&fwcon);
- qfree((void**)&nstat);
- qfree((void**)&oldcon);
- qfree((void**)&fodata);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/delete.c'
- then
- echo shar: will not over-write existing file "'src/delete.c'"
- else
- cat << \SHAR_EOF > 'src/delete.c'
- /* delete 01/11/93
- * Copyright 1983-1992 Albert Davis
- * delete and clear commands
- * (for now, also unexpand)
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_clear(void);
- void cmd_delete(const char*,int*);
- static void bylabel(const char*,int*);
- static void all(void);
- /*--------------------------------------------------------------------------*/
- #ifndef MAXINT
- #define MAXINT 32000
- #endif
- /*--------------------------------------------------------------------------*/
- /* cmd_clear: clear the whole circuit, including faults, etc
- * equivalent to unfault; unkeep; delete all; title = (blank)
- */
- void cmd_clear()
- {
- volatile int dummy = 0;
-
- cmd_unfault();
- cmd_unkeep();
- dummy = 0;
- cmd_ic("clear",&dummy);
- dummy = 0;
- cmd_nodeset("clear",&dummy);
- dummy = 0;
- cmd_print("clear",&dummy);
- dummy = 0;
- cmd_delete("all",&dummy);
- dummy = 0;
- cmd_title("'",&dummy);
- }
- /*--------------------------------------------------------------------------*/
- /* cmd_delete: delete command
- */
- void cmd_delete(cmd,cnt)
- const char *cmd; /* command string */
- int *cnt; /* pointer to cmd string counter */
- {
- dealloc(YES);
- if (pmatch(cmd,cnt,"ALL")){
- all();
- }else{
- while (isalpha(cmd[*cnt]))
- bylabel(cmd,cnt);
- }
- }
- /*--------------------------------------------------------------------------*/
- /* bylabel: delete circuit element by label
- * all lines with matching label (with wild cards * and ?) deleted.
- * syntax warning if no match
- */
- static void bylabel(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- branch_t *brh; /* scanning branch */
- /*volatile*/ int idx; /* temporary string index */
- int count = 0; /* deleted line counter */
- int x = 0; /* fudge: place to stash new index */
-
- for (brh = firstbranch_all();
- idx= *cnt, brh = findbranch(cmd,&idx,brh,lastbranch_all()), exists(brh);
- brh=nextbranch_all(brh)){
- x = idx;
- count += deletebranch(brh);
- }
-
- if (count != 0){
- *cnt = x;
- }else{
- syntax(cmd,cnt,bWARNING);
- skiparg(cmd,cnt);
- }
- }
- /*--------------------------------------------------------------------------*/
- /* all: delete all parts of a circuit, line by line
- */
- static void all() /* the whole circuit */
- {
- branch_t *brh;
- for (brh=firstbranch_all(); exists(brh); brh=nextbranch_all(brh))
- (void)deletebranch(brh);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/dev.c'
- then
- echo shar: will not over-write existing file "'src/dev.c'"
- else
- cat << \SHAR_EOF > 'src/dev.c'
- /* dev.c 01/18/93
- * Copyright 1983-1992 Albert Davis
- * generic functions to be used as part of specific devices
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "expr.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- branch_t* createbranch(
- const branch_t*,const generic_t*,const functions_t*);
- static generic_t* create_extra_stuff(const branch_t*,const generic_t*);
- void parsegeneric(branch_t*,const char*,int*,int);
- static void parseexpr(branch_t*,const char*,int*);
- static void getkey(int*,int*,const char*,int*);
- void parselabel(branch_t*,const char*,int*);
- void printgeneric(const branch_t*,int,int);
- static void printexpr(const branch_t*,int);
- char* printlabel(const branch_t*,int);
- double trprobegeneric(const branch_t*,const char*);
- double acprobegeneric(const branch_t*,const char*);
- double trprobe_branch(branch_t*,const char*);
- double acprobe_branch(branch_t*,const char*);
- void expandgeneric(branch_t*, const branch_t*);
- /*--------------------------------------------------------------------------*/
- extern const double *recon, *imcon;
- extern const char e_om[], e_int[];
- /*--------------------------------------------------------------------------*/
- /* createbranch: create an empty branch structure, or copy a prototype
- * returns pointer to it.
- * doesn't actually copy extra stuff, up to caller to do it
- */
- branch_t *createbranch(proto,xproto,func)
- const branch_t *proto;
- const generic_t *xproto;
- const functions_t *func;
- {
- branch_t *brh;
-
- if (proto){
- brh = (branch_t*)calloc(1,proto->ssize);
- if (!brh)
- error(bERROR, e_om, "createbranch");
- (void)memcpy((void*)brh, (void*)proto, proto->ssize);
- }else if (func){
- int ii;
- brh = (branch_t*)calloc(1, func->ssize);
- if (!brh)
- error(bERROR, e_om, "createbranch");
- for (ii = 0; ii <= NODESPERBRANCH; ii++)
- brh->nodes[ii].e = brh->nodes[ii].t = brh->nodes[ii].m = INVALIDNODE;
- brh->f = func;
- brh->ssize = func->ssize;
- }else{
- brh = (branch_t*)NULL;
- error(bERROR, e_int, "nothing to create");
- }
- brh->n = brh->nodes;
- brh->subckt = (branch_t*)NULL;
- brh->x = create_extra_stuff(brh,((brh->x)?(const generic_t*)brh->x:xproto));
-
- brh->prev = brh->next = (branch_t*)NULL;
- brh->stprev = brh->stnext = (branch_t*)NULL;
- brh->parent = (branch_t*)NULL;
- brh->wcg = brh->wcd = brh->wcp = 2;
-
- return brh;
- }
- /*--------------------------------------------------------------------------*/
- /* create_extra_stuff: copy the extra info for special parts (mosfets, etc)
- */
- static generic_t *create_extra_stuff(brh,proto)
- const branch_t *brh;
- const generic_t *proto;
- {
- if (proto){
- generic_t *x;
- x = (generic_t*)calloc(1,proto->ssize);
- if (!x)
- error(bERROR, e_om, "extra_stuff");
- (void)memcpy((void*)x, (void*)proto, proto->ssize);
- x->x = create_extra_stuff(brh, x->x);
- return x;
- }else{
- return (generic_t*)NULL;
- }
- }
- /*--------------------------------------------------------------------------*/
- /* parsegeneric: parse most ordinary elements (resistor, vccs, cap, etc.)
- * called mostly by functions that parse particular elements
- */
- void parsegeneric(brh,cmd,cnt,nodecount)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- int nodecount;
- {
- parselabel(brh,cmd,cnt);
- (void)parsenodes(brh,cmd,cnt,nodecount);
- parseexpr(brh,cmd,cnt);
- }
- /*--------------------------------------------------------------------------*/
- /* parseexpr: parse ureca style expressions.
- */
- static void parseexpr(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- double numbers[EXPRSIZE]; /* there are two dynamic arrays */
- int keys[EXPRSIZE]; /* one for the keys */
- int numcount; /* other for arguments (doubles) */
- int keycount; /* keys are first. */
- /* Initially, they are unknown size, so */
- brh->val = ctof(cmd,cnt);
- numcount = keycount = 0; /* use local fixed allocation. Then copy */
- for (;;){ /* in appropriate size to malloc space, */
- int key; /* with links to parent branch struct. */
- int args;
- int arg;
- int paren = 0;
- getkey(&key, &args, cmd, cnt);
- if (!key)
- break;
- if ((keycount + 1 >= EXPRSIZE) || (numcount + args > EXPRSIZE))
- error(bERROR, "expression too long\n");
- keys[keycount++] = key;
- if (args == aVARIABLE){ /* variable # of args */
- double *argcount; /* 1st arg is count */
- paren += skiplparen(cmd,cnt);
- argcount = &(numbers[numcount++]);
- *argcount = 1.;
- while (isfloat(cmd[*cnt])){
- numbers[numcount++] = ctof(cmd,cnt);
- (*argcount)++;
- }
- paren -= skiprparen(cmd,cnt);
- }else if (args == aASSIGN){
- skipequal(cmd,cnt);
- numbers[numcount++] = ctof(cmd,cnt);
- }else if (args > 0){
- paren += skiplparen(cmd,cnt);
- for (arg = 1; arg <= args; arg++)
- numbers[numcount++] = ctof(cmd,cnt);
- paren -= skiprparen(cmd,cnt);
- }else{
- /* no args, do nothing */
- }
- if (paren != 0)
- syntax(cmd,cnt,bWARNING);
- }
-
- if (keycount != 0){ /* allocate mem to save this stuff, */
- struct expr *x; /* then copy. */
- size_t ssize;
-
- brh->x = (generic_t*)calloc(1,sizeof(struct expr));
- if (!brh->x)
- error(bERROR, e_om, "partslist (expression)");
- x = (struct expr*)brh->x;
- x->ssize = sizeof(struct expr);
-
- keys[keycount++] = eEND;
-
- ssize = sizeof(generic_t) + keycount*sizeof(int);
- x->x = (generic_t*)calloc(1, ssize);
- if (!x->x)
- error(bERROR, e_om, "partslist (expression)");
- x->x->ssize = ssize;
- x->keys = (struct ints*)x->x;
-
- ssize = sizeof(generic_t) + numcount*sizeof(double);
- x->x->x = (generic_t*)calloc(1, ssize);
- if (!x->x->x)
- error(bERROR, e_om, "partslist (expression)");
- x->x->x->ssize = ssize;
- x->args = (struct dbls*)x->x->x;
-
- x->x->x->x = (generic_t*)NULL;
-
- (void)memcpy((void*)x->keys->args,(void*)keys, keycount*sizeof(int));
- (void)memcpy((void*)x->args->args,(void*)numbers,numcount*sizeof(double));
- }else{
- brh->x = (generic_t*)NULL;
- }
- }
- /*--------------------------------------------------------------------------*/
- /* getkey: scan for a keyword. Return its key and desired arg count.
- * returns key == eNO if no match.
- */
- static void getkey(key,args,cmd,cnt)
- int *key;
- int *args;
- const char *cmd;
- int *cnt;
- {
- setmatch(cmd,cnt);
- if (rematch("AC" )) { *key = eAC; *args = aAC; }
- else if (rematch("DC" )) { *key = eDC; *args = aDC; }
- else if (rematch("DCTran" )) { *key = eDCTRAN; *args = aDCTRAN; }
- else if (rematch("Frequency" )) { *key = eFREQUENCY; *args = aFREQUENCY; }
- else if (rematch("PEriod" )) { *key = ePERIOD; *args = aPERIOD; }
- else if (rematch("Ramp" )) { *key = eRAMP; *args = aRAMP; }
- else if (rematch("TIme" )) { *key = eTIME; *args = aTIME; }
- else if (rematch("TRansient" )) { *key = eTRAN; *args = aTRAN; }
-
- else if (rematch("BAndwidth" )) { *key = eBANDWIDTH; *args = aBANDWIDTH; }
- else if (rematch("COMplex" )) { *key = eCOMPLEX; *args = aCOMPLEX; }
- else if (rematch("CORNERDown" )) { *key = eCORNERDOWN;*args = aCORNERDOWN; }
- else if (rematch("CORNERUp" )) { *key = eCORNERUP; *args = aCORNERUP; }
- else if (rematch("DElay" )) { *key = eDELAY; *args = aDELAY; }
- else if (rematch("EXP" )) { *key = eEXP; *args = aEXP; }
- else if (rematch("EXPTerm" )) { *key = eEXPTERM; *args = aEXPTERM; }
- else if (rematch("Generator" )) { *key = eGENERATOR; *args = aGENERATOR; }
- else if (rematch("Max" )) { *key = eMAX; *args = aMAX; }
- else if (rematch("NEtfunction" )) { *key = eNETFUNC; *args = aNETFUNC; }
- else if (rematch("NOtch" )) { *key = eNOTCH; *args = aNOTCH; }
- else if (isfloat(cmd[*cnt] )) { *key = eNUMERIC; *args = aNUMERIC; }
- else if (rematch("Offset" )) { *key = eOFFSET; *args = aOFFSET; }
- else if (rematch("POLAr" )) { *key = ePOLAR; *args = aPOLAR; }
- else if (rematch("POLYTerm" )) { *key = ePOLYTERM; *args = aPOLYTERM; }
- else if (rematch("PUlse" )) { *key = ePULSE; *args = aPULSE; }
- else if (rematch("PWl" )) { *key = ePWL; *args = aPWL;}
- else if (rematch("SFfm" )) { *key = eSFFM; *args = aSFFM; }
- else if (rematch("SIn" )) { *key = eSIN; *args = aSIN; }
- else if (rematch("Tanh" )) { *key = eTANH; *args = aTANH; }
-
- else if (rematch("IC" )) { *key = eIC; *args = aIC; }
- else if (rematch("II" )) { *key = eII; *args = aII; }
- else if (rematch("IV" )) { *key = eIV; *args = aIV; }
- else if (rematch("TEmpco" )) { *key = eTEMPCO; *args = aTEMPCO; }
- else { syntax(cmd,cnt,bWARNING); *key = eNO; *args = 0; }
- }
- /*--------------------------------------------------------------------------*/
- /* parselabel: parse element label from input string
- * result in brh.
- */
- void parselabel(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- (void)ctostr(cmd, cnt, brh->label, LABELEN);
- brh->label[0] = to_upper(brh->label[0]);
- }
- /*--------------------------------------------------------------------------*/
- void printgeneric(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- (void)printlabel(brh,where);
- printnodes(brh,where);
- printexpr(brh,where);
- mputc('\n', where);
- }
- /*--------------------------------------------------------------------------*/
- static void printexpr(brh,where)
- const branch_t *brh;
- int where;
- {
- if (!brh->x || brh->val != 0.){
- mprintf(where, "%s", ftos(brh->val, "", 7, 0));
- }
-
- if (brh->x){
- struct expr *x;
- double *arg;
- int *key;
- char *fname;
- int terms;
-
- x = (struct expr*)brh->x;
- arg = x->args->args;
- for (key = x->keys->args; *key; key++){
- switch (*key){
- case eAC: fname = "ac"; terms = aAC; break;
- case eDC: fname = "dc"; terms = aDC; break;
- case eDCTRAN: fname = "dctran"; terms = aDCTRAN; break;
- case eFREQUENCY: fname = "freq"; terms = aFREQUENCY; break;
- case ePERIOD: fname = "period"; terms = aPERIOD; break;
- case eRAMP: fname = "ramp"; terms = aRAMP; break;
- case eTIME: fname = "time"; terms = aTIME; break;
- case eTRAN: fname = "tran"; terms = aTRAN; break;
-
- case eBANDWIDTH: fname = "bandwidth"; terms = aBANDWIDTH; break;
- case eCOMPLEX: fname = "complex"; terms = aCOMPLEX; break;
- case eCORNERDOWN:fname = "cornerdown"; terms = aCORNERDOWN; break;
- case eCORNERUP: fname = "cornerup"; terms = aCORNERUP; break;
- case eDELAY: fname = "delay"; terms = aDELAY; break;
- case eEXP: fname = "exp"; terms = aEXP; break;
- case eEXPTERM: fname = "expterm"; terms = aEXPTERM; break;
- case eGENERATOR: fname = "generator"; terms = aGENERATOR; break;
- case eMAX: fname = "max"; terms = aMAX; break;
- case eNOTCH: fname = "notch"; terms = aNOTCH; break;
- case eNETFUNC: fname = "netfunction";terms = aNETFUNC; break;
- case eNUMERIC: fname = ""; terms = aNUMERIC; break;
- case eOFFSET: fname = "offset"; terms = aOFFSET; break;
- case ePOLAR: fname = "polar"; terms = aPOLAR; break;
- case ePOLYTERM: fname = "polyterm"; terms = aPOLYTERM; break;
- case ePULSE: fname = "pulse"; terms = aPULSE; break;
- case ePWL: fname = "pwl"; terms = aPWL; break;
- case eSFFM: fname = "sffm"; terms = aSFFM; break;
- case eSIN: fname = "sin"; terms = aSIN; break;
- case eTANH: fname = "tanh"; terms = aTANH; break;
-
- case eIC: fname = "ic"; terms = aIC; break;
- case eII: fname = "ii"; terms = aII; break;
- case eIV: fname = "iv"; terms = aIV; break;
- case eTEMPCO: fname = "tempco"; terms = aTEMPCO; break;
- default: fname = "\n+ ERROR"; terms = 0; break;
- }
- mprintf(where, " %s", fname);
- if (*key == eNUMERIC){
- mprintf(where,"%s ",ftos(*(arg++), "", 7, 0));
- }else if (terms == aVARIABLE){
- int i;
- terms = (int)(*(arg++)) - 1;
- mprintf(where, "(", fname);
- for (i = 1; i <= terms; i++){
- mprintf(where,"%s ",ftos(*(arg++), "", 7, 0));
- }
- mprintf(where, ") ");
- }else if (terms == aASSIGN){
- mprintf(where, "=", fname);
- mprintf(where,"%s ",ftos(*(arg++), "", 7, 0));
- }else if (terms > 0){
- int i;
- mprintf(where, "(", fname);
- for (i = 1; i <= terms; i++){
- mprintf(where,"%s ",ftos(*(arg++), "", 7, 0));
- }
- mprintf(where, ") ");
- }
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- char* printlabel(brh,where)
- const branch_t *brh;
- int where;
- {
- static char label[BUFLEN];/* CAUTION: static area overwritten every call */
-
- strcpy(label, brh->label);
- while (brh = brh->parent, exists(brh)){
- strcat(label, ".");
- strncat(label, brh->label, BUFLEN-strlen(label)-2);
- }
- strcpy(&(label[BUFLEN-3]), "++");
- if (where)
- mprintf(where, "%s ", label);
- return label;
- }
- /*--------------------------------------------------------------------------*/
- double trprobegeneric(brh,what)
- const branch_t *brh;
- const char *what;
- {
- double volts;
- int dummy = 0;
-
- volts = tr_volts(brh->n[OUT1],brh->n[OUT2]);
-
- setmatch(what,&dummy);
- if (rematch("V")){
- return volts;
- }else if (rematch("I")){
- return brh->m0.f1 * volts + brh->m0.c0;
- }else if (rematch("P")){
- return (brh->m0.f1 * volts + brh->m0.c0) * volts;
- }else if (rematch("EV")){
- return brh->ev;
- }else if (rematch("Y")){
- return brh->m0.f1;
- }else if (rematch("R")){
- return (brh->m0.f1!=0.) ? 1/brh->m0.f1 : MAXDOUBLE;
- }else if (rematch("Z")){
- return trz(brh->n[OUT1],brh->n[OUT2],0.);
- }else{ /* bad parameter */
- return NOT_VALID;
- }
- }
- /*--------------------------------------------------------------------------*/
- double acprobegeneric(brh,what)
- const branch_t *brh;
- const char *what;
- {
- complex_t xvolts;
- int dummy = 0;
-
- xvolts.x = recon[brh->n[OUT1].m] - recon[brh->n[OUT2].m];
- xvolts.y = imcon[brh->n[OUT1].m] - imcon[brh->n[OUT2].m];
-
- setmatch(what,&dummy);
- if (rematch("V") || rematch("VM")){ /* volts, magnitude */
- return cabs(xvolts);
- }else if (rematch("VDB")){ /* volts, db re 1v */
- double v = cabs(xvolts);
- return (v > VMIN) ? 20. * log10(v) : DBVMIN;
- }else if (rematch("VP")){ /* voltage phase */
- return phase(xvolts.x,xvolts.y);
-
- }else if (rematch("I") || rematch("IM")){ /* amps, magnitude */
- return cabs(cmul(xvolts,brh->acg));
- }else if (rematch("IDB")){ /* amps, db re 1a */
- double i = cabs(cmul(xvolts,brh->acg));
- return (i > VMIN) ? 20. * log10(i) : DBVMIN;
- }else if (rematch("IP")){ /* current phase */
- complex_t xamps;
- xamps = cmul(xvolts,brh->acg);
- return phase(xamps.x,xamps.y);
-
- }else if (rematch("P")){ /* real power */
- complex_t va;
- va = ccmul(ccmul(xvolts,xvolts),brh->acg);
- return va.x;
- }else if (rematch("PDB")){ /* real pwr db re 1w */
- complex_t va;
- double x;
- va = ccmul(ccmul(xvolts,xvolts),brh->acg);
- x = fabs(va.x);
- return (x > PMIN) ? 10. * log10(x) : DBPMIN;
- }else if (rematch("PX")){ /* volt amp reactive */
- complex_t va;
- va = ccmul(ccmul(xvolts,xvolts),brh->acg);
- return va.y;
- }else if (rematch("PXDB")){ /* var db re 1 va */
- complex_t va;
- double y;
- va = ccmul(ccmul(xvolts,xvolts),brh->acg);
- y = fabs(va.y);
- return (y > PMIN) ? 10. * log10(y) : DBPMIN;
- }else if (rematch("PM")){ /* volt amp magnitude */
- return cabs(ccmul(ccmul(xvolts,xvolts),brh->acg));
- }else if (rematch("PMDB")){ /* va db re 1 va */
- double pm = cabs(ccmul(ccmul(xvolts,xvolts),brh->acg));
- return (pm > PMIN) ? 10. * log10(pm) : DBPMIN;
- }else if (rematch("PP")){ /* va phase */
- complex_t va;
- va = ccmul(ccmul(xvolts,xvolts),brh->acg);
- return phase(va.x,va.y);
- }else if (rematch("PF")){ /* power factor */
- complex_t va;
- va = ccmul(ccmul(xvolts,xvolts),brh->acg);
- return va.x / cabs(va);
-
- }else if (rematch("EV")){ /* effective value */
- return brh->ev;
-
- }else if (rematch("Y") || rematch("YM")){ /* admittance magnitude */
- return cabs(brh->acg);
- }else if (rematch("YP")){ /* admittance phase */
- return phase(brh->acg.x,brh->acg.y);
- }else if (rematch("YR")){ /* admittance real part */
- return brh->acg.x;
- }else if (rematch("YI")){ /* admittance imag part */
- return brh->acg.y;
-
- }else if (rematch("R") || rematch("RM")){ /* "resistance" magnitude */
- double r = cabs(brh->acg);
- return (r==0.) ? MAXDOUBLE : 1./r;
- }else if (rematch("RP")){ /* "resistance" phase */
- return phase(brh->acg.x,brh->acg.y);
- }else if (rematch("RR")){ /* "resistance" real part */
- return (brh->acg.x==0.) ? MAXDOUBLE : 1./brh->acg.x;
- }else if (rematch("RI")){ /* "resistance" imag part */
- return (brh->acg.y==0.) ? MAXDOUBLE : 1./brh->acg.y;
-
- }else if (rematch("Z") || rematch("ZM")){ /* port impedance magnitude */
- complex_t zz;
- zz = acz(brh->n[OUT1].m,brh->n[OUT2].m,brh->acg);
- return cabs(zz);
- }else if (rematch("ZP")){ /* port impedance phase */
- complex_t zz;
- zz = acz(brh->n[OUT1].m,brh->n[OUT2].m,brh->acg);
- return phase(zz.x,zz.y);
- }else if (rematch("ZR")){ /* port impedance real part */
- complex_t zz;
- zz = acz(brh->n[OUT1].m,brh->n[OUT2].m,brh->acg);
- return zz.x;
- }else if (rematch("ZI")){ /* port impedance imag part */
- complex_t zz;
- zz = acz(brh->n[OUT1].m,brh->n[OUT2].m,brh->acg);
- return zz.y;
-
- }else{ /* bad parameter */
- return NOT_VALID;
- }
- }
- /*--------------------------------------------------------------------------*/
- double trprobe_branch(brh,what)
- branch_t *brh;
- const char *what;
- {
- return (exists(brh) && brh->f->trprobe)
- ? (*(brh->f->trprobe))(brh,what)
- : 0.0;
- }
- /*--------------------------------------------------------------------------*/
- double acprobe_branch(brh,what)
- branch_t *brh;
- const char *what;
- {
- return (exists(brh) && brh->f->acprobe)
- ? (*(brh->f->acprobe))(brh,what)
- : 0.0;
- }
- /*--------------------------------------------------------------------------*/
- void expandgeneric(brh,modellist)
- branch_t *brh;
- const branch_t *modellist;
- {
- if (!brh->subckt){
- error(bTRACE, "%s: expanding\n", printlabel(brh,NO));
- }else{
- error(bTRACE, "%s: re-expanding\n", printlabel(brh,NO));
- brh->subckt = (branch_t*)NULL; /* detach subckt */
- }
-
- if (brh->x){
- if (!brh->x->m){
- const branch_t *model;
- model = modellist;
- for (;;){ /* search for thing to copy */
- model = model->stnext;
- if (wmatch(brh->x->modelname, model->label)){
- break; /* found it */
- }else if (model == modellist){
- error(bERROR, "%s: can't find model: %s\n",
- printlabel(brh,NO), brh->x->modelname);
- }
- }
- brh->x->m = model->x; /* link device to model */
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_admit.c'
- then
- echo shar: will not over-write existing file "'src/d_admit.c'"
- else
- cat << \SHAR_EOF > 'src/d_admit.c'
- /* devadmit.c 12/30/92
- * Copyright 1983-1992 Albert Davis
- * functions for admittance (type 'Y')
- * does not exist in spice
- * x = volts, y.f0 = amps, ev = y.f1 = mhos.
- */
- #include "ecah.h"
- #include "branch.h"
- #include "convstat.h"
- #include "mode.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_admittance(const branch_t*);
- static void parse_admittance(branch_t*,const char*,int*);
- static void print_admittance(const branch_t*,int,int);
- static void expand_admittance(branch_t*);
- static double trprobe_admittance(const branch_t*,const char*);
- static double acprobe_admittance(const branch_t*,const char*);
- static int tr_admittance_lin(branch_t*);
- static int tr_admittance_nl(branch_t*);
- static void un_admittance(branch_t*);
- static void ac_admittance_lin(branch_t*);
- static void ac_admittance_nl(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_admittance_lin = {
- sizeof(branch_t),
- create_admittance,
- parse_admittance,
- print_admittance,
- expand_admittance,
- trprobe_admittance,
- acprobe_admittance,
- tr_admittance_lin,
- un_admittance,
- ac_admittance_lin,
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- functions_t dev_admittance = {
- sizeof(branch_t),
- create_admittance,
- parse_admittance,
- print_admittance,
- expand_admittance,
- trprobe_admittance,
- acprobe_admittance,
- tr_admittance_nl,
- un_admittance,
- ac_admittance_nl,
- trfix1,
- trfix0,
- acfix,
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- extern const struct status stats;
- /*--------------------------------------------------------------------------*/
- static branch_t *create_admittance(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)NULL,&dev_admittance);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_admittance(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- parsegeneric(brh,cmd,cnt,2);
- brh->f = &dev_admittance;
- }
- /*--------------------------------------------------------------------------*/
- static void print_admittance(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- printgeneric(brh,where,detail);
- }
- /*--------------------------------------------------------------------------*/
- static void expand_admittance(brh)
- branch_t *brh;
- {
- if (!brh->x){
- brh->f = &dev_admittance_lin;
- brh->ev = brh->val;
- brh->y0.f1 = brh->val;
- brh->y0.f0 = LINEAR;
- brh->m0.x = brh->y0.x;
- brh->m0.c0 = 0.;
- brh->m0.f1 = brh->y0.f1;
- }
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_admittance(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return trprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static double acprobe_admittance(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return acprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static int tr_admittance_lin(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- trloadpassive(brh);
- return brh->status = cGOOD;
- }
- /*--------------------------------------------------------------------------*/
- static int tr_admittance_nl(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- trsetup(brh);
- brh->m0.x = tr_volts_limited(brh->n[OUT1],brh->n[OUT2]);
- brh->y0.x = brh->m0.x;
- if (brh->f->trfun1){
- (*brh->f->trfun1)(brh);
- }else{
- brh->y0.f1 = brh->val;
- brh->y0.f0 = LINEAR;
- }
- brh->ev = brh->y0.f1;
- brh->m0.x = brh->y0.x;
- brh->m0.c0 = brh->y0.f0 - brh->y0.x * brh->y0.f1;
- brh->m0.f1 = brh->y0.f1;
- trloadpassive(brh);
- return brh->status = conv_check(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void un_admittance(brh)
- branch_t *brh;
- {
- unloadpassive(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_admittance_lin(brh)
- branch_t *brh;
- {
- brh->acg.x = brh->m0.f1;
- brh->acg.y = 0.;
- acloadpassivereal(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_admittance_nl(brh)
- branch_t *brh;
- {
- if (brh->f->acfun){
- brh->acbias = dc_volts(brh->n[OUT1],brh->n[OUT2]);
- brh->acg = (*brh->f->acfun)(brh);
- acloadpassive(brh);
- }else{
- brh->acg.x = brh->ev;
- brh->acg.y = 0.;
- acloadpassivereal(brh);
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- # End of shell archive
- exit 0
-