home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-28 | 49.4 KB | 1,629 lines |
- Path: sparky!uunet!das.wang.com!ulowell!m2c!nic.umass.edu!caen!spool.mu.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 15/20
- Message-ID: <1993Jan27.040920.11780@rbc.uucp>
- Date: 27 Jan 93 04:09:20 GMT
- Sender: al@rbc.uucp (Al Davis)
- Organization: Huh?
- Lines: 1618
-
- #! /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/error.c
- # src/fft.c
- # src/file.c
- # src/findbr.c
- # src/findfile.c
- # src/fourier.c
- # src/ftos.c
- # src/generat.c
- # src/getckt.c
- # src/getlines.c
- # src/globals.c
- # This archive created: Tue Jan 26 22:51:05 1993
- export PATH; PATH=/bin:$PATH
- if test -f 'src/error.c'
- then
- echo shar: will not over-write existing file "'src/error.c'"
- else
- cat << \SHAR_EOF > 'src/error.c'
- /* error.c 12/30/92
- * Copyright 1983-1992 Albert Davis
- * Error handler.
- * Collection of functions to handle all types of errors
- * including user interrupts, system errors, overflow, etc.
- * Also, some user patience functions like "pause" and "comment".
- * (that don't really belong here)
- */
- #include "ecah.h"
- #include "error.h"
- #include "io.h"
- #include "options.h"
- #include <signal.h>
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void stubmess(void);
- void syntax(const char*,int*,int);
- void error();
- void sig_int(int);
- void sig_fpe(int);
- void ccck(void);
- void cmd_pause(const char*,int*);
- void cmd_comment(const char*,int*);
- int matherr(struct exception*);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
- extern const struct options opt;
- extern int errorcount;
- extern int cmdcount;
- extern jmp_buf envp;
- static int count;
- /*--------------------------------------------------------------------------*/
- /* stubmess: generic function that doesn't work
- */
- void stubmess()
- {
- error(bDISASTER, "stub mess\n");
- }
- /*--------------------------------------------------------------------------*/
- /* syntax: handle syntax errors
- * called on parsing an input string when nothing else matches.
- * if the rest of the line is nothing, just return
- * if comment, increment *cnt, so what is left is a valid comment string
- * otherwise, it is an error (the arrow pointing at the offending word)
- */
- void syntax(cmd,cnt,badness)
- const char *cmd;
- int *cnt;
- int badness;
- {
- char cc;
-
- skipbl(cmd,cnt);
- cc = cmd[*cnt];
- switch (cc) {
- case '\'':
- (*cnt)++;
- case '\0':
- break;
- default:
- if (badness >= opt.picky){
- if (*cnt < 20){
- mprintf(io.mstderr, "%.40s\n", cmd);
- mtab(*cnt, io.mstderr);
- error(badness,"^ ?\n");
- }else{
- mprintf(io.mstderr, "... %.36s\n", &cmd[(*cnt)-16]);
- mtab(20, io.mstderr);
- error(badness,"^ ?\n");
- }
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- /* error: error message printer
- * print it, if severe enough
- * terminate command, if really bad
- */
- /*VARARGS2*/
- void error(badness,fmt,va_alist)
- int badness;
- const char *fmt;
- va_dcl /* ; */
- {
- char buffer[BIGBUFLEN];
- va_list arg_ptr;
-
- if (badness >= opt.picky){
- errorcount++;
- va_start(arg_ptr);
- vsprintf(buffer,fmt,arg_ptr);
- va_end(arg_ptr);
- mputs(buffer,io.mstderr);
- }
- if (badness >= bDISASTER)
- abort();
- if (badness >= bEXIT)
- exit(badness);
- if (badness >= bERROR)
- longjmp(envp,1);
- }
- /*--------------------------------------------------------------------------*/
- #ifdef ANSI /* ANSI C varargs (stdarg.h) */
- void error(badness,fmt)
- int badness;
- char *fmt;
- {
- char buffer[BIGBUFLEN];
- va_list arg_ptr;
-
- if (badness >= picky) {
- va_start(arg_ptr,fmt);
- vsprintf(buffer,fmt,arg_ptr);
- va_end(arg_ptr);
- mputs(buffer,io.mstderr);
- }
- if (badness >= bEXIT)
- exit(badness);
- if (badness >= bERROR)
- longjmp(envp,1);
- }
- #endif
- /*--------------------------------------------------------------------------*/
- /* sig_int: what to do on receipt of interrupt signal (SIGINT)
- * cancel batch files, then back to command mode.
- * (actually, control-c trap)
- */
- /*ARGSUSED*/
- void sig_int(sig)
- int sig;
- {
- (void)signal(SIGINT,sig_int);
- error(bERROR, "\n");
- }
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- void sig_fpe(sig)
- int sig;
- {
- error(bERROR, "floating point error\n");
- reset_fpe();
- }
- /*--------------------------------------------------------------------------*/
- /* ccck: control-c check.
- * process user interrupts: ^c, ^s, escape
- * this is necessary because the solution could lock out the user
- * when there is no i/o.
- * called periodically when it is likely to have a long time with no i/o
- */
- void ccck()
- {
- switch (csts()) {
- case 'S'-'@':
- (void)ci();
- (void)ci();
- break;
- case 'C'-'@':
- (void)ci();
- error(bERROR, "\r");
- break;
- case '['-'@':
- (void)ci();
- error(bERROR, "\r");
- break;
- default:
- break;
- }
- }
- /*--------------------------------------------------------------------------*/
- /* cmd_pause: user command
- */
- /*ARGSUSED*/
- void cmd_pause(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- register int ch;
-
- count = cmdcount;
- mprintf( io.mstderr, "Continue? " );
- ch = ci();
- mprintf( io.mstderr, "%c\n", ch );
- if ( ch=='n' || ch=='N' || ch=='C'-'@' || ch=='['-'@' ) {
- error(bERROR, "\r");
- }
- }
- /*--------------------------------------------------------------------------*/
- /* cmd_comment: user command
- * if there are two consecutive comments, exit graphics mode
- * (this is a kluge)
- * the syntax check exists because this is called whenever nothing else is,
- * by the command interpreter. another kluge.
- */
- void cmd_comment(cmd,cnt) /* switch back to text mode */
- const char *cmd; /* on second consecutive comment */
- int *cnt;
- { /* also, check syntax. */
- if (cmdcount == count+1)
- plclear();
- count = cmdcount;
- syntax(cmd,cnt,bWARNING);
- }
- /*--------------------------------------------------------------------------*/
- /* matherr: handle math function errors.
- * replacement for the standard library function.
- */
- int matherr(x)
- struct exception *x;
- {
- if (x->type==DOMAIN) {
- if (strcmp(x->name,"atan2")==0) { /* both args are 0. */
- x->retval = 0.;
- return 1;
- }
- } else if (x->type==SING) {
- if (strncmp(x->name,"log",3)==0) { /* arg is 0. */
- x->retval = -HUGE; /* return -HUGE (it is, usually */
- return 1; /* but some return 0.) */
- }
- } else if (x->type==UNDERFLOW) {
- if (strcmp(x->name,"exp")==0) { /* arg is big negative */
- x->retval = 0.;
- return 1;
- }
- }
- mprintf(io.mstderr,"internal error: %s %u %g %g %g\n",
- x->name, x->type, x->arg1, x->arg2, x->retval);
- return 0;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/fft.c'
- then
- echo shar: will not over-write existing file "'src/fft.c'"
- else
- cat << \SHAR_EOF > 'src/fft.c'
- /* fft 03/23/92
- * Copyright 1983-1992 Albert Davis
- * fast fourier transform
- */
- #include "ecah.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void fft(complex_t*,int,int);
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- void fft(x, n, inv)
- complex_t *x;
- int n, inv;
- {
- complex_t w, t;
- int s, nxp, nxp2, m;
- double wpwr, arg;
-
- s = (inv) ? 1 : -1;
- for (nxp=n ; nxp2=nxp/2 ; nxp=nxp2){
- wpwr = PI2 / nxp;
- for (m=0 ; m<nxp2 ; m++){
- register int j1, j2;
- arg = m * wpwr;
- w.x = cos(arg);
- w.y = s*sin(arg);
- for (j1=m ; j1+nxp-m<=n ; j1+=nxp){
- j2 = j1 + nxp2;
- t.x = x[j1].x - x[j2].x;
- t.y = x[j1].y - x[j2].y;
- x[j1].x += x[j2].x;
- x[j1].y += x[j2].y;
- x[j2].x = t.x * w.x - t.y * w.y;
- x[j2].y = t.y * w.x + t.x * w.y;
- }
- }
- }
- /* unscramble */
- {
- register int j, k;
- int i;
- for (i=j=0 ; i<n-1 ; i++, j+=k){
- if (i<j){
- t = x[j];
- x[j] = x[i];
- x[i] = t;
- }
- for (k=n/2 ; k<=j ; k/=2)
- j -= k;
- }
- }
- /* fix level */
- {
- if (!inv){
- register int i;
- register int nn;
- nn = n;
- for ( i=0 ; i<nn ; i++ ){
- x[i].x /= nn;
- x[i].y /= nn;
- }
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/file.c'
- then
- echo shar: will not over-write existing file "'src/file.c'"
- else
- cat << \SHAR_EOF > 'src/file.c'
- /* file 01/05/93
- * Copyright 1983-1992 Albert Davis
- * route output to & from files, get command
- */
- #include "ecah.h"
- #include "error.h"
- #include "io.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_log(const char*,int*);
- void cmd_file(const char*,int*);
- char* getcmd(const char*,char*,int);
- /*--------------------------------------------------------------------------*/
- extern struct ioctrl io;
- extern char e_int[];
-
- static FILE *fin = stdin; /* file to use for stdin */
- static int mout; /* > file bitmap */
- static int mlog; /* log file bitmap */
- /*--------------------------------------------------------------------------*/
- /* cmd_log: "log" command processing
- * open a file for logging (history)
- * arg is name of file (.eca is appended)
- * no arg closes the one most recently opened
- * the file will contain a list of commands executed, for use by "<"
- * multiple files can be open, they are nested, output to all.
- */
- void cmd_log(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- char *access;
- static FILE *files[RECURSE];
- static int nest = 0;
-
- if (cmd[*cnt]){
- if (nest >= RECURSE){
- error(bWARNING, "too many files open\n");
- }else{
- access = "w";
- while (cmd[*cnt] == '>'){
- access = "a";
- ++*cnt;
- skipbl(cmd,cnt);
- }
- files[nest] = xopen(cmd,cnt,"eca",access);
- if (files[nest]){
- mlog |= 1<<fileno(files[nest]);
- nest++;
- }
- }
- }else{ /* empty command */
- if (nest == 0){ /* close it. */
- error(bWARNING, "no files open\n");
- }else{
- nest--;
- mlog &= ~(1<<fileno(files[nest]));
- (void)fclose(files[nest]);
- files[nest] = (FILE*)NULL;
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- /* cmd_file: ">" command processing
- * open a file for all output
- * the file will contain a copy of all screen output.
- * arg is name of file (.eca is appended)
- * no arg closes it
- * the file will contain all that would go to stdout
- */
- void cmd_file(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- char *access;
- static FILE *files[RECURSE];
- static int nest = 0;
-
- if (cmd[*cnt]){ /* if there is more to the command, */
- if (nest >= RECURSE){ /* open a new file. */
- error(bWARNING, "too many files open\n");
- }else{
- access = "w";
- while (cmd[*cnt] == '>'){
- access = "a";
- ++*cnt;
- skipbl(cmd,cnt);
- }
- files[nest] = xopen(cmd,cnt," ",access);
- if (files[nest]){
- mout |= 1<<fileno(files[nest]);
- io.mstdout |= 1<<fileno(files[nest]);
- nest++;
- }
- }
- }else{ /* empty command */
- if (nest == 0){ /* close it. */
- error(bWARNING, "no files open\n");
- }else{
- nest--;
- mout &= ~(1<<fileno(files[nest]));
- io.mstdout &= ~(1<<fileno(files[nest]));
- (void)fclose(files[nest]);
- files[nest] = (FILE*)NULL;
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- /* getcmd: get a command.
- * if "fin" is stdin, display a prompt first.
- * Also, actually do logging, echo, etc.
- */
- char *getcmd(prompt,buffer,buflen)
- const char *prompt;
- char *buffer;
- int buflen;
- {
- pllocate();
- if (!fin) /* 1st time thru */
- error(bWARNING, e_int, "stdin != stdin");
- if (fin == stdin){
- mputs( prompt, io.mstdout );
- mputs( " \b", io.mstdout );
- }
-
- if (!fgets(buffer, buflen, fin)){
- if (fin == stdin)
- error(bEXIT, "\n");
- buffer[0] = '\0';
- }
-
- (void)trim(buffer);
- mprintf(mlog, "%s\n", buffer);
- if (fin == stdin){
- mputc('\r', io.mstdout&~mout); /* reset col counter */
- mprintf(mout, "%s\n", buffer);
- }else{ /* echo disk reads, if reading a file */
- volatile int n = 0;
- skipbl(buffer,&n); /* normally, print the prompt first */
- switch (buffer[n]){ /* (default) but if the line is a blank */
- case '\0': /* or comment, do not print the prompt */
- mputc('\n', io.mstdout);
- break;
- case '\'':
- mprintf(io.mstdout, "%s\n", &buffer[n+1]);
- break;
- default:
- mprintf(io.mstdout, "%s%s\n", prompt, buffer);
- break;
- }
- }
- return buffer;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/findbr.c'
- then
- echo shar: will not over-write existing file "'src/findbr.c'"
- else
- cat << \SHAR_EOF > 'src/findbr.c'
- /* findbr 01/01/93
- * Copyright 1983-1992 Albert Davis
- * find a branch with matching label
- * returns the branch pointer
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- branch_t *findbranch(const char*,int*,const branch_t*,const branch_t*);
- int wmatch(const char*,const char*);
- /*--------------------------------------------------------------------------*/
- extern const char e_int[];
- /*--------------------------------------------------------------------------*/
- /* findbranch: find a matching label, by (ugh) linear search
- * start searching at "start", stop at "stop"
- * label to look for is in command line: &cmd[*cnt]
- * return pointer to match if exists (and eat input)
- * pointer to a non-existent branch if no match (don't eat input)
- * caution: caller must check return value before using
- */
- branch_t *findbranch(cmd,cnt,start,stop)
- const char *cmd;
- int *cnt;
- const branch_t *start, *stop;
- {
- int save;
- const branch_t *brh;
- char labelwanted[LABELEN+1];
- char thislabel[LABELEN+1];
- char *dot;
- char *wanted;
-
- save = *cnt; /* copy the name to local space */
- (void)ctostr(cmd, cnt, labelwanted, LABELEN);
-
- if (!labelwanted[1] || !isalpha(labelwanted[0])){
- *cnt = save; /* don't match single letter or dot */
- return (branch_t*)NULL; /* probably a command */
- }
-
- labelwanted[LABELEN] = thislabel[LABELEN] = '\0';
-
- dot = strrchr(labelwanted,'.'); /* trim off front stuff for subckt */
- if (dot){
- *dot = '\0';
- wanted = dot + 1;
- }else{
- wanted = labelwanted;
- }
-
- brh = start;
- do {
- volatile int dummy = 0;
- (void)ctostr( brh->label, &dummy, thislabel, LABELEN );
- if (wmatch(wanted,thislabel)){
- if (!dot){ /* found it */
- return (branch_t*)brh;
- }else{
- branch_t *subbrh;
- int dummy = 0;
- subbrh=findbranch(labelwanted,&dummy,brh->subckt,brh->subckt->prev);
- if (exists(subbrh)){
- return subbrh;
- }else if (brh == stop){ /* found subckt but */
- *cnt = save; /* no match within it */
- return (branch_t*)NULL;
- }
- }
- }else if (brh == stop){
- *cnt = save;
- return (branch_t*)NULL; /* didn't find it */
- }
- } while (brh = nextbranch_all(brh), brh != start);
-
- error(bWARNING, e_int, "findbranch: no stop");
- *cnt = save; /* trap endless loop */
- return (branch_t*)NULL;
- }
- /*--------------------------------------------------------------------------*/
- /* wmatch: string match with wild cards
- * s1 may have wild cards: ? any character matches; * any repeated 0 or more
- * returns YES or NO
- * normally not case sensitive,
- * but \ before any letter in s1 forces exact match
- * recursive
- * in the wrong file, but it started here as a static.....
- */
- int wmatch(s1, s2)
- const char *s1, *s2;
- {
- for ( ; (*s1 && *s2) || (*s1=='*'); s1++, s2++){
- if (*s1 == '?'){ /* '?' matches anything */
- ;
- }else if (*s1 == '*'){ /* '*' matches 0 or more of anything */
- if (wmatch(s1+1,s2)){ /* try '*' matches nothing */
- return YES;
- }else{ /* '*' matches at least one character */
- s1--; /* match it, try for more */
- if (*s2 == '\0') /* there is more in s1. If this were */
- return NO; /* all, the recursive call above would */
- } /* have matched. */
- }else if (*s1 == '\\'){ /* '\' requires an exact match */
- s1++; /* including case */
- if (*s1 != *s2)
- return NO;
- }else if (to_lower(*s1) != to_lower(*s2)){
- return NO; /* try to match, ignoring case */
- }
- }
- return *s1 == *s2; /* one of the strings ended */
- } /* if match, both will be '\0' */
- /* and return YES, otherwise NO */
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/findfile.c'
- then
- echo shar: will not over-write existing file "'src/findfile.c'"
- else
- cat << \SHAR_EOF > 'src/findfile.c'
- /* findfile 04/02/92
- * Modified by AD. Sent to me by C-WARE
- * This file contains the routine to locate a file,
- * using a path string for the directories to search.
- * Interface:
- * findfile(filename, paths, mode)
- * filename is the name of the file to be searched for,
- * paths is the path to follow to find it.
- * mode is how you want to open the file
- * returns full path name, if successful, else NULL.
- */
- #include "ecah.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- char* findfile(const char*,const char*,int);
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- char *findfile(filename, paths, mode)
- const char *filename, *paths;
- int mode;
- {
- const char *p_ptr;
- static char target_buf[BUFSIZ];
-
- #if CHECK_LOCAL_FIRST
- strcpy(target_buf, filename); /* check in the local directory */
- if (access(target_buf, mode) == GOOD)
- return target_buf;
- #endif
-
- if (!paths)
- paths = "";
-
- for (p_ptr=paths; *p_ptr != '\0'; ) { /* for each item in the path ...*/
- char *t_ptr;
- t_ptr = target_buf; /* copy the directory name */
- while (*p_ptr != PATHSEP && *p_ptr != '\0')
- *t_ptr++ = *p_ptr++;
- if (t_ptr != target_buf && t_ptr[-1] != '/' && t_ptr[-1] != '\\')
- *t_ptr++ = '/'; /* append '/' if needed */
- *t_ptr = '\0';
-
- strcat(target_buf, filename);
- if (access(target_buf, mode) == GOOD)
- return target_buf;
- if (*p_ptr) /* beyond the SEP */
- p_ptr++;
- }
- return (char*)NULL; /* can't find one */
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/fourier.c'
- then
- echo shar: will not over-write existing file "'src/fourier.c'"
- else
- cat << \SHAR_EOF > 'src/fourier.c'
- /* fourier 01/03/93
- * Copyright 1983-1992 Albert Davis
- * all functions needed in addition to the transient analysis
- * to perform the fourier command.
- */
- #include "ecah.h"
- #include "error.h"
- #include "io.h"
- #include "mode.h"
- #include "probh.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void foinit(long);
- void fonext(void);
- void fosave(double);
- void foout(double,double,double);
- static void head(void);
- static double topolar(complex_t*);
- static void tagmax(double*,double*,double*,int,complex_t*);
- static int stepno(double,double,double);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
-
- extern complex_t *fodata;
- extern probe_t *probelist[];
- extern char e_om[], e_int[];
- static long datapts, timesteps;
- static long indx;
- static int timestepno, probes;
- /*--------------------------------------------------------------------------*/
- void foinit(points) /* initialize fourier analysis. */
- long points; /* allocate memory, set up arrays, etc. */
- {
- long statsize;
-
- qfree((void**)&fodata);
- timesteps = points+1;
- probes = probcount(sTRAN);
- datapts = probes * timesteps;
- statsize = datapts * sizeof(complex_t);
- if ( statsize>SEGSIZ )
- error(bERROR, "too many data points\n");
- fodata = (complex_t*)calloc( (unsigned int)statsize, 1 );
- if ( !fodata )
- error(bERROR, e_om, "fourier");
- timestepno = 0;
- indx = -timesteps; /* skip the first probe. It is the time. */
- }
- /*--------------------------------------------------------------------------*/
- void fonext() /* next time step */
- { /* set to next column in 2d array.*/
- indx = ++timestepno - timesteps; /* stored by row */
- } /* ignore the first (time) */
- /*--------------------------------------------------------------------------*/
- void fosave(realvalue) /* save single point of trans. analysis */
- double realvalue; /* no need to save imag value. always 0. */
- { /* all points at a probe are a vector */
- if (fodata)
- {
- if (indx >= datapts)
- error(bERROR, e_int, "fourier");
- if (indx >= 0L) /* don't save time */
- fodata[indx].x = realvalue;
- indx += timesteps;
- }
- }
- /*--------------------------------------------------------------------------*/
- void foout(sstart,sstop,sstep) /* print out the results of the transform */
- double sstart, sstop, sstep;
- {
- register int fstep, prob;
- double mag, phz, db, relmag, relphz, reldb, freq;
- double maxmag[20], maxphz[20], maxdb[20];
- int startstep, stopstep;
-
- plclose();
- plclear();
- if (probes >= 20)
- error(bERROR, e_int, "fourier: too many probes");
- startstep = stepno( 0., sstep, sstart );
- stopstep = stepno( 0., sstep, sstop );
- head();
- for ( prob=0 ; prob < probes ; prob++ ) /* each probe */
- {
- fft( &fodata[prob*timesteps], (int)timesteps-1, 0 );
- maxmag[prob]=0.;
- for ( fstep=startstep ; fstep<=stopstep ; fstep++ ) /* each step */
- {
- int ind; /* find the largest */
- ind = (int)(prob*timesteps) + fstep;
- mag = topolar(&fodata[ind]);
- if (fstep > 0)
- fodata[ind].x *= 2;
- tagmax(maxmag,maxphz,maxdb,prob,&fodata[ind]);
- }
- if (maxmag[prob]==0.) /* if all zero, don't normalize */
- {
- maxmag[prob] = 1.;
- maxphz[prob] = 0.;
- maxdb[prob] = 0.;
- }
- }
- for ( fstep=startstep ; fstep<=stopstep ; ++fstep ) /* each step */
- {
- freq = sstep * fstep;
- for ( prob=0 ; prob < probes ; prob++ ) /* each probe */
- {
- int ind;
- ind = (int)(prob*timesteps) + fstep;
- mag = fodata[ind].x;
- phz = fodata[ind].y;
- db = 20. * log10(mag); /* BUG:it is not always 20 */
- relmag = mag / maxmag[prob];
- relphz = phz - maxphz[prob];
- reldb = db - maxdb[prob];
- if (relphz > 180.)
- relphz -= 360.;
- if (relphz < -180.)
- relphz += 360.;
- if (db < -999.99)
- db = -999.99;
- if (reldb < -999.99)
- reldb = -999.99;
- mprintf(io.where, "%-12s", ftos(freq," ",6,io.formaat) );
- mprintf(io.where, "%-11s", probename(probelist[sFOURIER][prob]));
- mprintf(io.where, "%s%7.2f %8.3f %s%7.2f %8.3f\n",
- ftos(mag, " ",5,io.formaat),
- db,
- phz,
- ftos(relmag, " ",5,io.formaat),
- reldb,
- relphz ) ;
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- static void head()
- {
- register int w;
- w = io.where&(io.mstdout|io.mprint);
- mprintf(w," ");
- mprintf(w,"--------- actual --------- -------- relative --------\n");
- mprintf(w," freq probe ");
- mprintf(w,"value dB phase value dB phase\n");
- }
- /*--------------------------------------------------------------------------*/
- static double topolar(arg) /* convert rectangular to polar */
- complex_t *arg; /* rotates 90 degrees! */
- { /* (ref to sine instead of cosine) */
- double mag, phz;
- mag = hypot( arg->x, arg->y);
- phz = phase(-arg->y, arg->x);
- arg->x = mag;
- arg->y = phz;
- return mag;
- }
- /*--------------------------------------------------------------------------*/
- static void tagmax(maxmag,maxphz,maxdb,prob,arg)
- double *maxmag, *maxphz, *maxdb;
- register int prob;
- complex_t *arg;
- {
- if (arg->x > maxmag[prob]) /* find max */
- {
- maxmag[prob] = arg->x;
- maxphz[prob] = arg->y;
- maxdb[prob] = 20. * log10(arg->x); /* BUG:it is not always 20 */
- }
- }
- /*--------------------------------------------------------------------------*/
- static int stepno(start, step, this)
- double start, step, this;
- {
- double num;
- num = (this-start)/step + .5;
- return (int)num;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/ftos.c'
- then
- echo shar: will not over-write existing file "'src/ftos.c'"
- else
- cat << \SHAR_EOF > 'src/ftos.c'
- /* ftos 12/08/91
- * Copyright 1983-1992 Albert Davis
- * float to string
- * builds string representing floating number
- * num = number to convert.
- * str = string to put it in. Must be big enough, or else!!
- * Must have length at least len+6.
- * sig digits + dec.pt.(1) + sign(1) + exp(4)
- * len = max number of displayed digits. (left + right of dp)
- * (includes d.p. if 'e' notation and 2 digit exp)
- * fmt = format : 0 = alpha for exp notation
- * FMTEXP = exponential notation
- * FMTSIGN = always inlcude sign
- * FMTFILL = fill in zeros
- * BUG:
- * returns a pointer to static space where the string is.
- * there is a finite pool, so repeated calls work, to a point.
- * after that, the space is overwritten, every POOLSIZE calls
- */
- #include "ecah.h"
- #include "formats.h"
- #include "options.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- char *ftos(double,const char*,int,int);
- /*--------------------------------------------------------------------------*/
- #define POOLSIZE 10
- #define MAXLENGTH 40
- extern const struct options opt;
- /*--------------------------------------------------------------------------*/
- /*VARARGS4*/
- char *ftos(num, dummy, len, fmt)
- double num; /* number to convert */
- const char *dummy;/* place holder, was where to put it */
- int len; /* max length of new string */
- int fmt; /* how to format it */
- {
- char sign; /* sign storage ( +,-,bl ) */
- int expo; /* exponent */
- int flg; /* flag used to supress leading zeros */
- int dig; /* the next digit to print */
- int iii; /* loop counter */
- int nnn; /* char counter -- pos in string */
- double rnd; /* rounding adder */
- static char strpool[POOLSIZE][MAXLENGTH]; /* destination string pool */
- static int poolindex = 0;
- char *str;
-
- poolindex++;
- if (poolindex >= POOLSIZE)
- poolindex = 0;
- str = strpool[poolindex];
- for (iii=0; iii<strlen(dummy); ++iii)
- str[iii] = ' ';
- for ( ; iii<MAXLENGTH; ++iii)
- str[iii] = '\0';
-
- nnn = 0;
- if (len <= 3)
- return str; /* error */
-
- if (fabs(num) < 1e-99 || fabs(num) < opt.floor)
- num = 0.;
-
- for ( iii=len+5; iii>=0; --iii )
- str[iii] = ' '; /* fill with blanks */
-
- if (num == 0.){
- strcpy( str, " 0." );
- nnn = strlen( str ); /* num==0 .. build string 0.000... */
- while ( --len )
- str[nnn++] = '0';
- expo = 0;
- sign = ' ';
- }else{ /* num != 0 */
- if (num < 0.){
- sign = '-'; /* sign */
- num = -num;
- }else if (fmt & FMTSIGN){
- sign = '+';
- }else{
- sign = ' ';
- }
-
- expo = -3;
- while (num < .001){ /* scale to .001 - 1.0 */
- num *= 1000.;
- expo -= 3;
- }
- while (num >= 1.){
- num *= .001;
- expo += 3;
- }
- if ((fmt&FMTEXP&&expo<-9) || expo>10 || expo<-13)
- --len; /* one less digit if 'e' notation */
- if (len <= 3){ /* and exp is 2 digits */
- return str;
- }
-
- rnd = .5 / x10(len); /* find amt to add to round */
- if (num < .01)
- rnd /= 100.;
- else if (num < .1)
- rnd /= 10.;
- num += rnd; /* add it */
- if (num >= 1.){
- num *= .001; /* created an extra digit: rescale */
- expo += 3;
- }
-
- flg = 0;
- nnn = 1;
- if (expo == -3){ /* exp is -3. */
- expo = 0; /* print in fixed point, no exponent*/
- str[nnn++] = '0';
- str[nnn++] = '.';
- while (len > 0){
- num *= 10.;
- dig = (int)floor(num);
- num -= (double)dig;
- str[nnn++] = (char)(dig + '0');
- if (flg += dig)
- --len;
- }
- }else{
- for (iii=2; len>0; --iii){ /* mantissa */
- num *= 10.; /* get next digit */
- dig = (int)floor(num);
- num -= (double)dig; /* subtract off last digit */
- if (flg += dig){ /* if int part !=0 */
- str[nnn++]=(char)dig+'0'; /* (not all zeros so far) */
- --len; /* stuff the digit into the string */
- }
- if (!iii && len>0){ /* if we found the dec.pt. and */
- str[nnn++] = '.'; /* haven't used up all the space */
- } /* put a dec.pt. in the string */
- }
- }
- }
-
- for (iii=1; str[iii]==' '; ++iii) /* insert sign at beginning */
- ;
- str[iii-1] = sign;
-
- if (!(fmt&FMTFILL)) /* supress trailing zeros */
- while ( str[nnn-1]=='0' )
- str[--nnn] = (char)((nnn<strlen(dummy)) ? ' ' : '\0');
-
- if (expo == 0)
- return str;
-
- if (fmt&FMTEXP || expo>10 || expo<-13){ /* if exponential format */
- str[nnn++] = 'E'; /* put the letter 'E' and */
- if (expo < 100) /* convert the exponent */
- (void)itos( expo, &str[nnn], -2, FMTSIGN );
- else
- (void)utos( (unsigned)expo, &str[nnn], -3 );
- }else{ /* if letter-scale format */
- str[nnn++] = "fpnum KMGT"[(expo+15)/3];/* put the appropriate letter */
- } /* note that letter-scale is not valid */
- /* for exp==-3 or exp not in -15..+12 */
- /* this is trapped but letter-scale is also*/
- /* not valid if exp not divisible by 3. */
- /* This is not trapped, since it supposedly*/
- /* cant happen. */
- if (str[nnn-1] == 'M'){
- str[nnn++] = 'e';
- str[nnn++] = 'g';
- }
- if (strlen(dummy)==0) /* BUG: this cleans up stray trailing */
- trim(str); /* blanks. I don't know why they exist */
-
- return str;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/generat.c'
- then
- echo shar: will not over-write existing file "'src/generat.c'"
- else
- cat << \SHAR_EOF > 'src/generat.c'
- /* generator 02/23/92
- * Copyright 1983-1992 Albert Davis
- * set up generator for transient analysis
- */
- #include "ecah.h"
- #include "error.h"
- #include "io.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_generator(const char*,int*);
- double gen(void);
- /*--------------------------------------------------------------------------*/
- #define ARGS 12
- #define freq argv[0]
- #define ampl argv[1]
- #define phaz argv[2]
-
- #define maxv argv[3]
- #define minv argv[4]
- #define offset argv[5]
-
- #define init argv[6]
- #define rise argv[7]
- #define fall argv[8]
-
- #define delay argv[9]
- #define width argv[10]
- #define period argv[11]
-
- extern const struct ioctrl io;
- extern double trtime;
- static double argv[ARGS] =
- { 0. , 1. , 0. , 1. , 0. , 0. ,
- 0. , 1e-12, 1e-12 , 0. , 0. , 0. };
- static char *argnam[ARGS] =
- {"Freq","Ampl","Phase","MAx" ,"MIn" ,"Offset",
- "Init","Rise","Fall" ,"Delay","Width","PEriod"};
- static int positive[ARGS] =
- { YES , NO , NO , NO , NO , NO ,
- NO , YES , YES , YES , YES , YES };
- /*--------------------------------------------------------------------------*/
- void cmd_generator(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- int ii; /* iteration counter */
- int where;
-
- where = (cmd[*cnt]) ? 0 : io.mstdout;
-
- for (ii=0; ii<ARGS; ++ii){ /* try to match each name in the list */
- if (pmatch(cmd,cnt,argnam[ii])){ /* match the control name */
- if (isfloat(cmd[*cnt])) /* if match, assign a value */
- argv[ii] = (positive[ii])
- ? fabs(ctof(cmd,cnt))
- : ctof(cmd,cnt);
- ii = -1; /* start over */
- }
- }
-
- syntax(cmd,cnt,bWARNING);
-
- for (ii=0; ii<ARGS; ++ii){
- mprintf( where, " %s=%s ",
- argnam[ii],
- ftos(argv[ii], "", 6, 0));
- }
- mprintf( where, "\n" );
- }
- /*--------------------------------------------------------------------------*/
- double gen()
- {
- double loctime;
- double level;
-
- if (trtime <= delay)
- return init;
- loctime = trtime - delay;
- if (period > 0.){
- if (loctime > period * 1048576)
- error(bERROR, "step size much too large\n");
- while (loctime > period * 65536)
- loctime -= period * 65536;
- while (loctime > period * 4096) /* to improve code, */
- loctime -= period * 4096; /* use fmod. */
- while (loctime > period * 256)
- loctime -= period * 256;
- while (loctime > period * 16)
- loctime -= period * 16;
- while (loctime > period)
- loctime -= period;
- }
- if (trtime <= delay + rise) /* initial rise */
- level = (maxv - 0) * (loctime/rise) + 0;
- else if (loctime <= rise) /* rising */
- level = (maxv - minv) * (loctime/rise) + minv;
- else if (width==0. || (loctime-=rise) <= width) /* pulse on */
- level = maxv;
- else if ((loctime-=width) <= fall) /* falling */
- level = (minv - maxv) * (loctime/fall) + maxv;
- else /* pulse off */
- level = minv;
- level *= (freq == 0.)
- ? ampl
- : ampl * sin(PI2*freq*(trtime-delay) + phaz*DTOR);
- return (trtime <= delay + rise)
- ? level + (offset - init) * (loctime/rise) + init
- : level + offset;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/getckt.c'
- then
- echo shar: will not over-write existing file "'src/getckt.c'"
- else
- cat << \SHAR_EOF > 'src/getckt.c'
- /* getckt 02/15/92
- * Copyright 1983-1992 Albert Davis
- * build, get, merge, "<" commands
- * process circuit files, and keyboard entry
- */
- #include "ecah.h"
- #include "argparse.h"
- #include "branch.h"
- #include "dev.h"
- #include "error.h"
- #include "io.h"
- #include "mode.h"
- #include "options.h"
- #include "status.h"
- #include "types.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_build(const char*, int*);
- void cmd_get(const char*,int*);
- void cmd_merge(const char*,int*);
- void cmd_run(const char*,int*);
- static void getmerge(const char*,int*,int);
- static branch_t *parsebranch(char*,int);
- static branch_t *cparse(const char*);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
- extern const struct options opt;
- extern struct status stats;
-
- extern char head[]; /* place to store title line */
- extern char e_int[];
- extern int run_mode;
- extern branch_t *insertbefore;
- /*--------------------------------------------------------------------------*/
- /* cmd_build: build command
- * get circuit description direct from keyboard (or stdin if redirected)
- * Command syntax: build <before>
- * Bare command: add to end of list
- * If there is an arg: add before that element
- * null line exits this mode
- * preset, but do not execute "dot cards"
- */
- void cmd_build(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- branch_t *brh;
-
- time_zstart(&(stats.get));
- stats.iter[iTOTAL] = 1;
- run_mode = rPRESET;
- dealloc(YES);
- insertbefore = findbranch(cmd,cnt, firstbranch_all(), lastbranch_all());
- if (!(exists(insertbefore))){
- insertbefore = lastbranch_all()->next;
- if (!insertbefore)
- error(bWARNING, e_int, "build: insertbefore");
- }
- do {
- char buffer[BIGBUFLEN];
- (void)getcmd(">",buffer,BIGBUFLEN);
- brh = parsebranch(buffer,YES);
- } while (exists(brh));
- time_stop(&(stats.get));
- }
- /*--------------------------------------------------------------------------*/
- /* cmd_get: get command
- * get circuit from a file, after clearing the old one
- * preset, but do not execute "dot cards"
- */
- void cmd_get(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- time_zstart(&(stats.get));
- run_mode = rPRESET;
- getmerge(cmd,cnt,YES);
- time_stop(&(stats.get));
- }
- /*--------------------------------------------------------------------------*/
- /* cmd_merge: merge command
- * as get, but do not clear first
- */
- void cmd_merge(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- time_zstart(&(stats.get));
- run_mode = rPRESET;
- getmerge(cmd,cnt,NO);
- time_stop(&(stats.get));
- }
- /*--------------------------------------------------------------------------*/
- /* cmd_run: "<" and "<<" commands
- * run in batch mode
- * "<<" clears old circuit first, "<" does not
- * get circuit from file, execute dot cards in sequence
- */
- void cmd_run(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- int deleteold = NO;
- time_zstart(&(stats.get));
- while (cmd[*cnt] == '<'){
- deleteold = YES;
- ++*cnt;
- skipbl(cmd,cnt);
- }
- run_mode = rEXECUTE;
- getmerge(cmd,cnt,deleteold);
- time_stop(&(stats.get));
- }
- /*--------------------------------------------------------------------------*/
- /* getmerge: actually do the work for "get", "merge", etc.
- */
- static void getmerge(cmd,cnt,deleteold)
- const char *cmd;
- int *cnt;
- int deleteold;
- {
- char buffer[BIGBUFLEN];
- int echoon; /* echo on/off flag (echo as read from file) */
- int liston; /* list on/off flag (list actual values) */
- int quiet; /* don't echo title */
- static FILE *filen; /* file number (static for safety) */
-
- stats.iter[iTOTAL] = 1;
- dealloc(YES);
- xclose(&filen);
- filen = xopen(cmd,cnt,"ckt","r");
- if (!filen)
- error(bERROR, "");
-
- echoon = liston = quiet = NO;
- for (;;){
- if (argparse(cmd,cnt,REPEAT,
- "Echo", aENUM, &echoon, YES,
- "List", aENUM, &liston, YES,
- "Quiet", aENUM, &quiet, YES,
- "")){
- ;
- }else if (cmd[*cnt]){
- xclose(&filen);
- syntax(cmd, cnt, bERROR);
- }else{
- break;
- }
- }
-
- if (deleteold)
- cmd_clear();
-
- if (!getlines(buffer, BIGBUFLEN, filen)) /* title */
- error(bWARNING, "empty circuit file\n");
- (void)trim(buffer);
- if (!quiet)
- mprintf(io.mstdout, "%s\n", buffer);
- if (*buffer)
- strcpy(head, buffer);
-
- insertbefore = lastbranch_all()->next;
- if (!insertbefore)
- error(bWARNING, e_int, "getmerge: insertbefore");
- while (getlines(buffer, BIGBUFLEN, filen)){
- branch_t *brh;
- if (echoon)
- mprintf(io.mstdout, "%s\n", buffer);
- brh = parsebranch(buffer,NO);
- if (liston && exists(brh)){
- print_branch(brh, io.mstdout, NO);
- }
- }
- xclose(&filen);
- }
- /*--------------------------------------------------------------------------*/
- /* parsebranch: parse an input line, and process it
- */
- static branch_t *parsebranch(buffer,alwaysdupcheck)
- char *buffer;
- int alwaysdupcheck;
- {
- branch_t *brh; /* place for cparse to return data */
- branch_t *old; /* possible replace this one */
- branch_t *before; /* actually insert here */
-
- before = insertbefore; /* save insert place in case something like */
- /* a subckt changes it */
-
- brh = cparse(buffer); /* parse it */
- if (exists(brh)){
- if (opt.dupcheck || alwaysdupcheck){
- volatile int dummy; /* string index for parse package */
- dummy = 0;
- old = findbranch(brh->label, &dummy, insertbefore, insertbefore->prev);
- if (exists(old)){ /* already exists, replace it */
- error(bWARNING, "replacing: %s\n", brh->label);
- brh->next = old->next; /* set link so new is in same */
- (void)deletebranch(old); /* place, then delete. */
- }else{
- brh->next = before;
- }
- }else{
- brh->next = before;
- }
- brh = insertbranch(brh);
- }
- if (isdevice(brh)){
- dealloc(YES);
- }
- return brh;
- }
- /*--------------------------------------------------------------------------*/
- /* cparse: circuit parse: parse one line of a netlist
- * mostly, dispatches to the proper function.
- */
- static branch_t *cparse(cmd)
- const char *cmd; /* string to parse */
- {
- functions_t *dev;
- branch_t *brh;
- volatile int i = 0;
- volatile int *cnt = &i;
-
- skipbl(cmd,cnt);
- if (isdigit(cmd[*cnt]))
- (void)ctoi(cmd,cnt); /* ignore line numbers */
-
- dev = (functions_t*)NULL;
- switch (to_upper(cmd[*cnt])){
- case '\0': /* nothing */ break;
- case '.': dev = &dev_dotcard; break;
- case '\'':
- case '"':
- case '*': dev = &dev_comment; break;
- case 'A': syntax(cmd,cnt,bWARNING); break;
- case 'B': syntax(cmd,cnt,bWARNING); break;
- case 'C': dev = &dev_cap; break;
- case 'D': dev = &dev_diode; break;
- case 'E': dev = &dev_vcvs; break;
- case 'F': syntax(cmd,cnt,bWARNING); break;
- case 'G': dev = &dev_vccs; break;
- case 'H': syntax(cmd,cnt,bWARNING); break;
- case 'I': dev = &dev_cs; break;
- case 'J': syntax(cmd,cnt,bWARNING); break;
- case 'K': syntax(cmd,cnt,bWARNING); break;
- case 'L': dev = &dev_coil; break;
- case 'M': dev = &dev_mos; break;
- case 'N': syntax(cmd,cnt,bWARNING); break;
- case 'O': syntax(cmd,cnt,bWARNING); break;
- case 'P': syntax(cmd,cnt,bWARNING); break;
- case 'Q': dev = &dev_bjt; break;
- case 'R': dev = &dev_resistor; break;
- case 'S': syntax(cmd,cnt,bWARNING); break;
- case 'T': dev = &dev_trnlin; break;
- case 'U': dev = &dev_logic; break;
- case 'V': dev = &dev_vs; break;
- case 'W': syntax(cmd,cnt,bWARNING); break;
- case 'X': dev = &dev_subckt; break;
- case 'Y': dev = &dev_admittance; break;
- case 'Z': syntax(cmd,cnt,bWARNING); break;
- default: syntax(cmd,cnt,bWARNING); break;
- }
- if (dev){ /* new device created */
- brh = (*(dev->create))((branch_t*)NULL);
- }else{ /* either syntax error or empty line */
- brh = (branch_t*)NULL;
- }
-
- if (exists(brh)){
- parse_branch(brh,cmd,cnt);
- }else if (brh){
- error(bWARNING, "internal error: branch has no type <%s>\n", cmd);
- free((void*)brh);
- brh = (branch_t*)NULL;
- }
-
- return brh;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/getlines.c'
- then
- echo shar: will not over-write existing file "'src/getlines.c'"
- else
- cat << \SHAR_EOF > 'src/getlines.c'
- /* getlines.c 04/02/92
- * Copyright 1983-1992 Albert Davis
- * get a bunch of lines, from a file
- * interface is just line fgets.
- * hooks together extension lines
- * not recommended for getting from stdin. use for files only.
- * is always a line ahead
- * start with + is extension line, spice compatibility.
- */
- #include "ecah.h"
- #include "error.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- char *getlines(char*,int,FILE*);
- /*--------------------------------------------------------------------------*/
- extern const char e_int[];
- /*--------------------------------------------------------------------------*/
- char *getlines(s, n, stream)
- char *s;
- int n;
- FILE *stream;
- {
- int count = 0;
- int c;
- char *got;
-
- do {
- got = fgets(&s[count], n-count, stream);
- if (!got){
- if (count == 0)
- return (char*)NULL;
- else
- error(bWARNING, e_int, "getlines");
- }
- (void)trim(s);
- count = strlen(s);
- c = fgetc(stream);
- if (count >= n-1)
- break;
- s[count++] = ' ';
- } while (c == '+');
-
- (void)ungetc(c,stream);
- return s;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/globals.c'
- then
- echo shar: will not over-write existing file "'src/globals.c'"
- else
- cat << \SHAR_EOF > 'src/globals.c'
- /* globals 01/06/93
- * Copyright 1983-1992 Albert Davis
- */
- #include "ecah.h"
- #include "ac.h"
- #include "branch.h"
- #include "defaults.h"
- #include "error.h"
- #include "io.h"
- #include "mode.h"
- #include "nodestat.h"
- #include "options.h"
- #include "probh.h"
- #include "status.h"
- /*--------------------------------------------------------------------------*/
- /* sparse matrix */
- /* far heap, temporary */
- double *reals, *imags; /* big array allocation bases */
-
- /* near heap, hold between commands */
- int *basnode; /* lowest node connected to this node */
- int *nm; /* node map (correspondence) table */
- double *volts; /* node voltages */
-
- /* near heap, temporary */
- double **rerow, **imrow; /* array of row pointers */
- double **recol, **imcol; /* array of column pointers */
- double **redia, **imdia; /* array of diagonal pointers */
- double *recon,*imcon; /* right side vector */
- double *oldcon,*fwcon; /* old versions of right side vector */
- complex_t *fodata; /* Fourier analysis data collection */
- struct nodestat *nstat; /* node status flags */
-
- /* other sparse matrix stuff */
- unsigned aspace; /* count of non-zero array elements */
- int decomp; /* how far the matrix has been decomposed */
- double zero; /* a constant, could change if bugs */
- /*--------------------------------------------------------------------------*/
- /* other (the ultimate in disorder) */
- ac_t ac; /* stuff for ac analysis */
- struct status stats; /* timing data for status command */
- branch_t *insertbefore; /* place to add new elements (subckt?) */
- int inc_mode; /* flag: make incremental changes */
- int currents_bad; /* flag: stored currents are bad */
- int stiff; /* flag: use "stiff" integration method */
- double last_time; /* time at which "volts" is valid */
- double trtime; /* transient analysis time */
- double genout; /* tr dc input to circuit (generator) */
- probe_t *plotlist[sCOUNT]; /* list of plot points */
- probe_t *probelist[sCOUNT]; /* list of print points */
- double temp; /* local temperature */
- char head[BUFLEN+3];
- /*--------------------------------------------------------------------------*/
- /* command interpreter, control stuff */
- jmp_buf envp; /* environment for setjmp, longjmp */
- int errorcount; /* count of errors since last reset */
- int cmdcount; /* command counter, for history */
- int crtplot = NO; /* flag: is plotting on the crt */
-
- /* sweep command */
- int swp_count[RECURSE]; /* sweep counter */
- int swp_steps[RECURSE]; /* sweep number of steps */
- int swp_type[RECURSE]; /* type of sweep (log or linear) */
- int swp_nest; /* sweep nesting (recursion) level */
-
- /* flags: what is it doing */
- int worstcase; /* bits flag: worst case, etc. mode */
- int run_mode; /* variations on handling of dot cmds */
- int sim_mode; /* simulation type (AC, DC, ...) */
- int sim_phase; /* phase of simulation (iter, init-dc, )*/
-
- /* initial conditions fudge (yuck) */
- int in_curr; /* flag: initial current exists */
- int in_volt; /* flag: initial voltage exists */
- int in_cond; /* flag: generic initial cond exists */
- double init_curr; /* initial current */
- double init_volt; /* initial voltage */
- double init_cond; /* generic initial condition */
-
- /* options : set command */
- struct options opt = {oDEFAULT_acct, oDEFAULT_list, oDEFAULT_nomod,
- oDEFAULT_page, oDEFAULT_node, oDEFAULT_opts, oDEFAULT_gmin,
- oDEFAULT_reltol, oDEFAULT_abstol, oDEFAULT_vntol, oDEFAULT_trtol,
- oDEFAULT_chgtol, oDEFAULT_pivtol, oDEFAULT_pivrel, oDEFAULT_numdgt,
- oDEFAULT_tnom, oDEFAULT_cptime, oDEFAULT_limtim, oDEFAULT_limpts,
- oDEFAULT_lvlcod, oDEFAULT_lvltim, oDEFAULT_method, oDEFAULT_maxord,
- oDEFAULT_seed, oDEFAULT_wczero, oDEFAULT_damp, oDEFAULT_floor,
- oDEFAULT_tempamb, oDEFAULT_short, oDEFAULT_picky, oDEFAULT_inwidth,
- oDEFAULT_outwidth, oDEFAULT_xdivisions, oDEFAULT_ydivisions,
- oDEFAULT_order, oDEFAULT_mode, oDEFAULT_transits,
- oDEFAULT_dupcheck, oDEFAULT_bypass, oDEFAULT_incmode, oDEFAULT_limit,
- oDEFAULT_mrt,
- oDEFAULT_foooo, oDEFAULT_lowlim, oDEFAULT_uplim,
- {oDEFAULT_itl0, oDEFAULT_itl1, oDEFAULT_itl2, oDEFAULT_itl3,
- oDEFAULT_itl4, oDEFAULT_itl5, oDEFAULT_itl6, oDEFAULT_itl7, oDEFAULT_itl8}};
-
- /* io control */
- struct ioctrl io = {ioDEFmstdin, ioDEFmstdout, ioDEFmstderr, ioDEFmpr,
- ioDEFwhere, ioDEFformaat, ioDEFwhence, ioDEFsuppresserrors, ioDEFechoflag,
- ioDEFprintflag, ioDEFincipher, ioDEFoutcipher, ioDEFpack, ioDEFploton,
- ioDEFplotset};
-
- /* commonly used error messages */
- char e_int[] = "internal error: %s\n";
- char e_om[] = "out of memory: %s\n";
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- # End of shell archive
- exit 0
-