home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-28 | 34.2 KB | 1,234 lines |
- Path: sparky!uunet!crdgw1!rpi!usc!howland.reston.ans.net!bogus.sura.net!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 19/20
- Message-ID: <1993Jan27.041125.12131@rbc.uucp>
- Date: 27 Jan 93 04:11:25 GMT
- Sender: al@rbc.uucp (Al Davis)
- Organization: Huh?
- Lines: 1223
-
- #! /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/skiparg.c
- # src/skipbl.c
- # src/solve.c
- # src/status.c
- # src/stubs.c
- # src/sweep.c
- # src/syscall.c
- # src/utos.c
- # src/version.c
- # src/xopen.c
- # src/xsolve.c
- # src/_msc.c
- # src/_unix.c
- # This archive created: Tue Jan 26 22:51:14 1993
- export PATH; PATH=/bin:$PATH
- if test -f 'src/skiparg.c'
- then
- echo shar: will not over-write existing file "'src/skiparg.c'"
- else
- cat << \SHAR_EOF > 'src/skiparg.c'
- /* skiparg 01/05/93
- * Copyright 1983-1992 Albert Davis
- * skip an argument in a string
- */
- #include "ecah.h"
- #include "declare.h"
-
- void skiparg(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- if (!skipcom(cmd,cnt)){
- if (cmd[*cnt])
- (*cnt)++;
- while (isalnum(cmd[*cnt]) || cmd[*cnt]=='.')
- (*cnt)++;
- skipcom(cmd,cnt);
- }
- }
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/skipbl.c'
- then
- echo shar: will not over-write existing file "'src/skipbl.c'"
- else
- cat << \SHAR_EOF > 'src/skipbl.c'
- /* skipbl 01/05/93
- * Copyright 1983-1992 Albert Davis
- * skip whitespace. (any non-graphic character is ws)
- * =,(,) are also ws
- * update string pointer
- * pointer points to first non-space
- * also ..... skipcom, skiplparen, skiprparen. obvious
- * all but skipbl returns the # of them skipped (1 or 0).
- */
- #include "ecah.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void skipbl(const char*,int*);
- int skipcom(const char*,int*);
- int skiplparen(const char*,int*);
- int skiprparen(const char*,int*);
- int skipequal(const char*,int*);
- /*--------------------------------------------------------------------------*/
- void skipbl(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- while (cmd[*cnt] && (!isgraph(cmd[*cnt])))
- (*cnt)++ ;
- }
- /*--------------------------------------------------------------------------*/
- int skipcom(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- skipbl(cmd,cnt);
- if (cmd[*cnt] == ',' || cmd[*cnt] == '='){
- (*cnt)++;
- skipbl(cmd,cnt);
- return 1;
- }else{
- skipbl(cmd,cnt);
- return 0;
- }
- }
- /*--------------------------------------------------------------------------*/
- int skiplparen(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- skipbl(cmd,cnt);
- if (cmd[*cnt] == '(' || cmd[*cnt] == '['){
- (*cnt)++;
- skipbl(cmd,cnt);
- return 1;
- }else{
- skipbl(cmd,cnt);
- return 0;
- }
- }
- /*--------------------------------------------------------------------------*/
- int skiprparen(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- skipbl(cmd,cnt);
- if (cmd[*cnt] == ')' || cmd[*cnt] == ']'){
- (*cnt)++;
- skipbl(cmd,cnt);
- return 1;
- }else{
- skipbl(cmd,cnt);
- return 0;
- }
- }
- /*--------------------------------------------------------------------------*/
- int skipequal(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- skipbl(cmd,cnt);
- if (cmd[*cnt] == '='){
- (*cnt)++;
- skipbl(cmd,cnt);
- return 1;
- }else{
- skipbl(cmd,cnt);
- return 0;
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/solve.c'
- then
- echo shar: will not over-write existing file "'src/solve.c'"
- else
- cat << \SHAR_EOF > 'src/solve.c'
- /* solve 12/29/92
- * Copyright 1983-1992 Albert Davis
- * LU decomposition and fwd-back substitution for real numbers
- * 2 modules: lu() and solve()
- * lu() does LU decomposition using the Crout algorithm (modified)
- * solve() does forward and back substitution after calling lu() if necessary
- */
- #include "ecah.h"
- #include "array.h"
- #include "error.h"
- #include "mode.h"
- #include "nodestat.h"
- #include "options.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void solve(void);
- static void lu(void);
- static double dotprod(int,int,int);
- /*--------------------------------------------------------------------------*/
- extern const struct options opt;
- extern struct status stats;
-
- extern double *recon,*imcon,*fwcon; /* constant terms, answer column */
- extern struct nodestat *nstat;
-
- extern const double trtime;
- extern const int *basnode; /* array of lowest node connected here */
- /*--------------------------------------------------------------------------*/
- #ifdef max
- #undef max
- #endif
- #define max(x,y) ( ((x)>(y)) ? (x) : (y) )
- /*--------------------------------------------------------------------------*/
- void solve()
- {
- int jj, ii;
-
- lu();
- time_start(&(stats.back));
- for (ii = 1; ii <= stats.total_nodes; ++ii){ /* forward substitution */
- fwcon[ii] = recon[ii];
- for (jj = basnode[ii]; jj < ii; ++jj)
- fwcon[ii] -= *LUl(ii,jj) * fwcon[jj];
- fwcon[ii] /= *LUd(ii,ii);
- }
- if (opt.foooo!=4){
- for (ii = stats.total_nodes; ii >= 1; --ii){
- imcon[ii] = fwcon[ii];
- nstat[ii].aiter = stats.iter[iTOTAL];
- }
- for (jj = stats.total_nodes; jj > 1; --jj){ /* back substitution */
- for (ii = basnode[jj]; ii < jj; ++ii){
- imcon[ii] -= *LUu(ii,jj) * imcon[jj];
- }
- }
- }else{
- for (ii = stats.total_nodes; ii >= 1; --ii){
- /*if (nstat[ii].mode != mGATE){*/
- imcon[ii] = fwcon[ii];
- for (jj = ii+1; jj <= stats.total_nodes; ++jj){
- imcon[ii] -= *im(ii,jj) * imcon[jj];
- }
- nstat[ii].aiter = stats.iter[iTOTAL];
- /*nstat[ii].mode = mLU;*/
- /*nstat[ii].lastchange = trtime;*/
- /*}*/
- }
- }
- time_stop(&(stats.back));
- if (opt.foooo == 1){
- for (ii=1; ii<=stats.total_nodes; ++ii){
- for (jj=1; jj<=stats.total_nodes; ++jj){
- printf("%9.2e ", *re(ii,jj));
- }
- printf("%9.2e\n", recon[ii]);
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- static void lu()
- {
- int ii, jj, mm;
- int bn;
-
- time_start(&(stats.lu));
- for (mm = 1; mm <= stats.total_nodes; ++mm){
- bn = basnode[mm];
- if (bn < mm){
- *LUu(bn,mm) = *AAu(bn,mm) / *LUd(bn,bn);
- for (ii = bn+1; ii<mm; ii++){
- *LUu(ii,mm) = (*AAu(ii,mm) - dotprod(ii,mm,ii)) / *LUd(ii,ii);
- }
- *LUl(mm,bn) = *AAl(mm,bn);
- for (jj = bn+1; jj<mm; jj++){
- *LUl(mm,jj) = *AAl(mm,jj) - dotprod(mm,jj,jj);
- }
- /* jj == mm */{
- *LUd(mm,mm) = *AAd(mm,mm) - dotprod(mm,mm,mm);
- if (*LUd(mm,mm) == 0.){
- error(bTRACE, "open circuit: node %u\n", mm);
- *LUd(mm,mm) = opt.gmin;
- }
- }
- }else{ /* bn == mm */
- *LUd(mm,mm) = *AAd(mm,mm);
- if (*LUd(mm,mm) == 0.){
- error(bTRACE, "open circuit: node %u\n", mm);
- *LUd(mm,mm) = opt.gmin;
- }
- }
- }
- time_stop(&(stats.lu));
- }
- /*--------------------------------------------------------------------------*/
- static double dotprod(ii,jj,mm)
- int ii, jj, mm;
- {
- int ind, len;
- int kk;
- double *row, *col;
- double dot = 0.;
-
- kk = max(basnode[ii], basnode[jj]);
- len = mm - kk;
- if (len > 0){
- row = LUl(ii,kk);
- col = LUu(kk,jj);
- /* for (i = kk; i < mm; i++) */
- for (ind = 0; ind < len; ind++)
- dot += row[-ind] * col[ind];
- }
- return dot;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/status.c'
- then
- echo shar: will not over-write existing file "'src/status.c'"
- else
- cat << \SHAR_EOF > 'src/status.c'
- /* status 02/15/92
- * Copyright 1983-1992 Albert Davis
- Displays the status of the system. Makes all the calculations associated
- with allocating memory but does not actually allocate it, unless necessary to
- make the rest of the calculations.
-
- If "allocate" is changed, this must also be changed.
-
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "io.h"
- #include "mode.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_status(void);
- static void fixoverhead(struct status*);
- static void printtime(char*, struct time_s);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
- extern struct status stats;
-
- extern const unsigned aspace;
- /*--------------------------------------------------------------------------*/
- void cmd_status()
- {
- mprintf(io.mstdout,"ACS System status\n");
- allocate(sSTATUS);
-
- if (stats.total_nodes)
- stats.density = ((double)(aspace-1)*100.)/
- ((double)stats.total_nodes*(double)stats.total_nodes);
- else
- stats.density = 0.;
-
- mprintf(io.mstdout,
- "command -------- last -------- -------- total --------\n");
- mprintf(io.mstdout,
- " user sys total user sys total\n");
- printtime("get", stats.get);
- printtime("op", stats.op);
- printtime("dc", stats.dc);
- printtime("tran", stats.tran);
- printtime("fourier", stats.four);
- printtime("ac", stats.ac);
-
- mprintf(io.mstdout,
- "function -------- last -------- -------- total --------\n");
- mprintf(io.mstdout,
- " user sys total user sys total\n");
- printtime("setup", stats.setup);
- printtime("order", stats.order);
-
- fixoverhead(&stats);
- mprintf(io.mstdout,
- "function -------- last -------- -------- total --------\n");
- mprintf(io.mstdout,
- " user sys total user sys total\n");
- printtime("load", stats.load);
- printtime("lu", stats.lu);
- printtime("back", stats.back);
- printtime("review", stats.review);
- printtime("output", stats.output);
- printtime("overhead",stats.overhead);
- printtime("total", stats.total);
-
- mprintf(io.mstdout,"iterations: op=%d, dc=%d, tran=%d, fourier=%d, total=%d\n",
- stats.iter[sOP], stats.iter[sDC], stats.iter[sTRAN], stats.iter[sFOURIER],
- stats.iter[iTOTAL]);
- mprintf(io.mstdout,"nodes: user=%d, subckt=%d, model=%d, total=%d\n",
- stats.user_nodes, stats.subckt_nodes, stats.model_nodes,
- stats.total_nodes);
- mprintf(io.mstdout,"density=%.1f%%\n", stats.density);
- #ifdef NEVER
- mprintf(io.mstdout,"diodes=%d, bjts=%d, mosfets=%d, gates=%d subckts=%d\n",
- stats.diodes, stats.bjts, stats.mosfets, stats.gates, stats.subckts);
- mprintf(io.mstdout,"matrix: terms=%d, fills=%d, total=%d, ops=%d\n",
- stats.matrix_terms, stats.matrix_fills, stats.matrix_total,
- stats.matrix_ops);
- #endif
- }
- /*--------------------------------------------------------------------------*/
- static void fixoverhead(x)
- struct status *x;
- {
- x->overhead.last_user = x->total.last_user - x->load.last_user -
- x->lu.last_user - x->back.last_user - x->output.last_user - x->review.last_user;
-
- x->overhead.last_system = x->total.last_system - x->load.last_system -
- x->lu.last_system - x->back.last_system - x->output.last_system - x->review.last_system;
-
- x->overhead.total_user = x->total.total_user - x->load.total_user -
- x->lu.total_user - x->back.total_user - x->output.total_user - x->review.total_user;
-
- x->overhead.total_system = x->total.total_system - x->load.total_system -
- x->lu.total_system - x->back.total_system - x->output.total_system - x->review.total_system;
- }
- /*--------------------------------------------------------------------------*/
- static void printtime(name, v)
- char *name;
- struct time_s v;
- {
- mprintf(io.mstdout, "%10s %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n", name,
- v.last_user, v.last_system, v.last_user + v.last_system,
- v.total_user, v.total_system, v.total_user + v.total_system);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/stubs.c'
- then
- echo shar: will not over-write existing file "'src/stubs.c'"
- else
- cat << \SHAR_EOF > 'src/stubs.c'
- /* stubs.c 01/01/93
- * Copyright 1983-1992 Albert Davis
- * stubs to satisfy references to Spice commands not supported here
- */
- #include "ecah.h"
- #include "error.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_alter(const char*,int*);
- void cmd_disto(const char*,int*);
- void cmd_model(const char*,int*);
- void cmd_noise(const char*,int*);
- void cmd_sens(const char*,int*);
- void cmd_subckt(const char*,int*);
- void cmd_temp(const char*,int*);
- void cmd_tf(const char*,int*);
- /*--------------------------------------------------------------------------*/
- static char e_spice[] = "Spice dot-card not implemented: %s\n";
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- void cmd_alter(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- error(bWARNING, e_spice, cmd);
- }
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- void cmd_disto(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- error(bWARNING, e_spice, cmd);
- }
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- void cmd_model(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- error(bWARNING, e_spice, cmd);
- }
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- void cmd_noise(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- error(bWARNING, e_spice, cmd);
- }
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- void cmd_sens(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- error(bWARNING, e_spice, cmd);
- }
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- void cmd_subckt(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- error(bWARNING, e_spice, cmd);
- }
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- void cmd_temp(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- error(bWARNING, e_spice, cmd);
- }
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- void cmd_tf(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- error(bWARNING, e_spice, cmd);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/sweep.c'
- then
- echo shar: will not over-write existing file "'src/sweep.c'"
- else
- cat << \SHAR_EOF > 'src/sweep.c'
- /* sweep 12/31/92
- * Copyright 1983-1992 Albert Davis
- * Step a parameter and repeat a group of commands
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "io.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_sweep(const char*,int*);
- static void buildfile(const char*,int*);
- static void doit(void);
- static void setup(const char*,int*);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
- extern int crtplot;
- extern int swp_count[], swp_steps[];
- extern int swp_type[];
- extern int swp_nest;
- static char tempfile[] = STEPFILE;
- /*--------------------------------------------------------------------------*/
- void cmd_sweep(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- if (cmd[*cnt])
- buildfile(cmd,cnt);
- doit();
- cmd_unfault();
- }
- /*--------------------------------------------------------------------------*/
- static void buildfile(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- auto char buffer[BUFLEN];
- static FILE *fptr;
-
- setup(cmd,cnt);
- if (fptr)
- (void)fclose(fptr);
- fptr = fopen( tempfile, "w" );
- if (!fptr)
- error(bERROR, "can't open temporary file\n" );
- (void)fprintf(fptr, "%s\n", cmd );
-
- for (;;){
- (void)getcmd( ">>>", buffer, BUFLEN );
- if ( match(buffer,"GO") )
- break;
- (void)fprintf(fptr,"%s\n",buffer);
- }
- (void)fclose(fptr);
- fptr = (FILE*)NULL;
- }
- /*--------------------------------------------------------------------------*/
- static void doit()
- {
- auto char buffer[BUFLEN];
- static FILE *fptr;
- volatile int ind;
-
- for ( swp_count[swp_nest]=0 ; swp_count[swp_nest]<=swp_steps[swp_nest] ;
- swp_count[swp_nest]++ ){
- if (fptr)
- (void)fclose(fptr);
- fptr = fopen(tempfile, "r");
- if (!fptr)
- error(bERROR, "can't open %s\n", tempfile);
- (void)fgets(buffer,BUFLEN,fptr);
- ind = 0;
- if ( pmatch(buffer,&ind,"SWeep") )
- setup(buffer,&ind);
- else
- error(bERROR, "bad file format: %s\n", tempfile);
- strncpy( buffer, "fault ", ind);
- buffer[ind-1] = ' '; /* make sure there is a delimiter */
- /* in case the words run together */
- for (;;){ /* may wipe out one letter of fault */
- (void)cmdproc(buffer);
- if (!fgets(buffer,BUFLEN,fptr))
- break;
- if (!crtplot)
- mprintf(io.mstdout,"%u> %s", swp_count[swp_nest]+1, buffer);
- }
- }
- (void)fclose(fptr);
- fptr = (FILE*)NULL;
- swp_count[swp_nest] = 0;
- }
- /*--------------------------------------------------------------------------*/
- static void setup(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- for (;;){
- if (isdigit(cmd[*cnt])){
- swp_steps[swp_nest] = ctoi(cmd,cnt) ;
- swp_steps[swp_nest] = (swp_steps[swp_nest]) ? swp_steps[swp_nest]-1
- : 0;
- }else if (pmatch(cmd,cnt,"LInear")){
- swp_type[swp_nest] = 0;
- }else if (pmatch(cmd,cnt,"LOg")){
- swp_type[swp_nest] = 'L';
- }else{
- break;
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/syscall.c'
- then
- echo shar: will not over-write existing file "'src/syscall.c'"
- else
- cat << \SHAR_EOF > 'src/syscall.c'
- /* syscall 10/08/91
- * Copyright 1983-1992 Albert Davis
- * system calls: change directory, invoke another program, invoke editor, etc.
- */
- #include "ecah.h"
- #include "error.h"
- #include "io.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_edit(const char*,int*);
- void cmd_system(const char*,int*);
- void cmd_chdir(const char*,int*);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
- extern char e_int[];
- /*--------------------------------------------------------------------------*/
- /* cmd_edit: (command) invoke user defined editor on the netlist
- * if command has an argument, it edits that file instead
- * else actually edits a temporary file, and reads it back.
- */
- void cmd_edit(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- char *editor;
- char name[BUFLEN];
- char args[BUFLEN];
-
- editor = getenv("EDITOR");
- if (!editor)
- error(bERROR, "no editor defined\n");
-
- if (cmd[*cnt]) {
- sprintf(args, "%s %s\n", editor, &cmd[*cnt]);
- system(args);
- } else {
- strcpy(name, EDITFILE);
- (void)mktemp(name);
- sprintf(args, "save %s\n", name);
- (void)cmdproc(args);
- sprintf(args, "%s %s\n", editor, name);
- system(args);
- sprintf(args, "get %s quiet\n", name);
- (void)cmdproc(args);
- unlink(name);
- }
- }
- /*--------------------------------------------------------------------------*/
- /* cmd_system: (! command) call the system to execute a command
- * no arg spawns a shell.
- */
- void cmd_system(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- if (cmd[*cnt])
- system(&cmd[*cnt]);
- else
- shell();
- }
- /*--------------------------------------------------------------------------*/
- /* cmd_chdir: (cd, chdir command)
- * change working directory, print name of where it ends up
- * no arg just prints, does not change to a default.
- */
- void cmd_chdir(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- char buf[BUFLEN];
-
- if (cmd[*cnt])
- (void)chdir( ctostr(cmd,cnt,buf,BUFLEN-1) );
- if (getwd(buf))
- mprintf(io.mstderr, "%s\n", buf);
- else
- error(bERROR, e_int, "getcwd");
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/utos.c'
- then
- echo shar: will not over-write existing file "'src/utos.c'"
- else
- cat << \SHAR_EOF > 'src/utos.c'
- /* utos 11/06/89
- * Copyright 1983-1992 Albert Davis
- * unsigned to string
- * num = number to convert.
- * str = string to put it in. Must be big enough, or else!!
- * Must have length at least len.
- * len = number of significant digits.
- * If minus, left justify, else right.
- */
- #include "ecah.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- char *utos(unsigned,char*,int);
- /*--------------------------------------------------------------------------*/
- char *utos( num, str, len )
- char *str;
- unsigned num;
- int len;
- {
- int ii, jj;
-
- if ( len==0 ) return str; /* reject zero length */
- ii = abs(len);
-
- do { /* build string starting at tail */
- str[--ii] = (char)(num % 10 + '0');
- } while ( (num/=10)>0 && ii>0 );
-
- if (len > 0){ /* if right justify, fill with blank */
- while (ii > 0)
- str[--ii] = ' ';
- }else{ /* else if left justify, move left */
- for (jj=0; ii<-len; ) /* then fill with blanks */
- str[jj++] = str[ii++];
- while (jj < -len)
- str[jj++] = ' ';
- }
- return str;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/version.c'
- then
- echo shar: will not over-write existing file "'src/version.c'"
- else
- cat << \SHAR_EOF > 'src/version.c'
- /* version.c 10/08/91
- * Copyright 1983-1992 Albert Davis
- * a dumb selector for portability
- */
- #include "ecah.h"
- #include "io.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- #ifdef UNIX
- #include "_unix.c"
- #endif
-
- #ifdef MSC
- #include "_msc.c"
- #endif
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/xopen.c'
- then
- echo shar: will not over-write existing file "'src/xopen.c'"
- else
- cat << \SHAR_EOF > 'src/xopen.c'
- /* xopen 01/11/93
- * Copyright 1983-1992 Albert Davis
- * scan a string for a file name
- * fill in extension, if necessary
- * open file
- */
- #include "ecah.h"
- #include "error.h"
- #include <time.h>
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void xclose(FILE**);
- FILE* xopen(const char*,int*,const char*,const char*);
- /*--------------------------------------------------------------------------*/
- extern FILE *stream[];
- /*--------------------------------------------------------------------------*/
- void xclose(fn)
- FILE **fn;
- {
- if (*fn){
- (void)fclose(*fn);
- *fn = (FILE*)NULL;
- }
- }
- /*--------------------------------------------------------------------------*/
- FILE *xopen(cmd,cnt,ext,how)
- const char *cmd, *ext, *how;
- int *cnt;
- {
- int i;
- int defalt;
- FILE *code;
- char fname[BUFLEN+5];
-
- skipbl(cmd,cnt);
- if (!cmd[*cnt]){
- volatile int loccount;
- cmd = getcmd ("file name? ",fname,BUFLEN);
- loccount = 0;
- cnt = &loccount;
- }
-
- skipbl(cmd,cnt); /* find out if we want to add the */
- defalt = YES; /* default extension */
- for (i = 0; i < BUFLEN; ){
- char c;
- c = cmd[(*cnt)++];
- if (isterm(c))
- break;
- if (c == '$'){
- sprintf(&(fname[i]), "%ld", time((long*)NULL));
- i = strlen(fname);
- }else{
- fname[i++] = c;
- if (c == '.')
- defalt = NO;
- else if (c == '\\' || c == '/')
- defalt = YES;
- }
- }
- (*cnt)--;
- if (defalt){ /* add the extension */
- fname[i++] = '.';
- strcpy(&fname[i],ext);
- }else{
- fname[i] = '\0';
- }
-
- (void)trim(fname);
- skipcom(cmd,cnt);
-
- if ((*how == 'w') && (access(fname,F_OK) == GOOD)){
- char buffer[BUFLEN];
- error(bWARNING, "%s exists. replace? ", fname);
- (void)getcmd ("", buffer, BUFLEN);
- if (match(buffer,"Yes")) /* should be new file, but */
- code = fopen(fname,how); /* file already exists, ask */
- else
- return (FILE*)NULL;
- }else{
- code = fopen(fname,how);
- }
-
- if (code && fileno(code)>MAXHANDLE){
- error(bWARNING, "internal error: files: %d\n", fileno(code));
- (void)fclose(code);
- code = (FILE*)NULL;
- }
- if (code)
- stream[fileno(code)] = code;
- else
- error(bWARNING, "can't open %s\n", fname);
- return code;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/xsolve.c'
- then
- echo shar: will not over-write existing file "'src/xsolve.c'"
- else
- cat << \SHAR_EOF > 'src/xsolve.c'
- /* xsolve 12/29/92
- * Copyright 1983-1992 Albert Davis
- * LU decomposition and fwd-back substitution for complex numbers
- * 2 modules: xlu() and xsolve()
- * xlu() does LU decomposition using the Crout algorithm
- * xsolve() does forward and back substitution after calling xlu() if necessary
- * For a readable version of this, see the real number version: solve
- */
- #include "ecah.h"
- #include "array.h"
- #include "error.h"
- #include "options.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void xsolve(void);
- static void lu(void);
- static complex_t dotprod(int,int,int);
- /*--------------------------------------------------------------------------*/
- extern const struct options opt;
- extern struct status stats;
-
- extern double *recon,*imcon; /* constant terms, answer column */
- extern int decomp; /* how far been decomposed */
- extern const int *basnode; /* array of lowest node connected here */
- /*--------------------------------------------------------------------------*/
- void xsolve()
- {
- int jj, ii;
-
- lu();
- ccck();
- time_start(&(stats.back));
- for (ii = 1; ii <= stats.total_nodes; ++ii){ /* forward substitution */
- complex_t acc;
- acc.x = recon[ii];
- acc.y = imcon[ii];
- for ( jj=basnode[ii]; jj<ii; ++jj ){
- /* con[ii] -= Lower[ii][jj] * con[jj] */
- acc = csub(acc, cxmul(*Rel(ii,jj),*Iml(ii,jj), recon[jj],imcon[jj]));
- }
-
- /* con[ii] /= *xy(ii,ii) */
- acc = cxdiv(acc.x,acc.y, *Red(ii,ii),*Imd(ii,ii));
- recon[ii] = acc.x;
- imcon[ii] = acc.y;
- }
- ccck();
- for (jj = stats.total_nodes; jj > 1; --jj) /* back substitution */
- for (ii = basnode[jj]; ii < jj; ++ii){
- /* con[ii] -= *Upper[ii][jj] * con[jj] */
- complex_t acc;
- acc = cxmul(*Reu(ii,jj),*Imu(ii,jj), recon[jj],imcon[jj]);
- acc = cxsub(recon[ii],imcon[ii], acc.x,acc.y);
- recon[ii] = acc.x;
- imcon[ii] = acc.y;
- }
- time_stop(&(stats.back));
- ccck();
- }
- /*--------------------------------------------------------------------------*/
- static void lu()
- {
- complex_t acc;
- int ii, jj, mm;
- int bn;
-
- time_start(&(stats.lu));
- for (mm = decomp+1; mm <= stats.total_nodes; ++mm){
- bn = basnode[mm];
- if (bn < mm){
- /* *Upper(bn,mm) /= *Diag(bn,bn); */
- acc = cxdiv(*Reu(bn,mm),*Imu(bn,mm), *Red(bn,bn),*Imd(bn,bn));
- *Reu(bn,mm) = acc.x;
- *Imu(bn,mm) = acc.y;
-
- for (ii =bn+1; ii<mm; ii++){
- acc = dotprod(ii,mm,ii);
- acc = cxsub(*Reu(ii,mm),*Imu(ii,mm), acc.x,acc.y);
- acc = cxdiv(acc.x,acc.y, *Red(ii,ii),*Imd(ii,ii));
- *Reu(ii,mm) = acc.x;
- *Imu(ii,mm) = acc.y;
- }
- for (jj = bn+1; jj<mm; jj++){
- acc = dotprod(mm,jj,jj);
- acc = cxsub(*Rel(mm,jj),*Iml(mm,jj), acc.x,acc.y);
- *Rel(mm,jj) = acc.x;
- *Iml(mm,jj) = acc.y;
- }
- /* jj == mm */{
- acc = dotprod(mm,mm,mm);
- acc = cxsub(*Red(mm,mm),*Imd(mm,mm), acc.x,acc.y);
- if (acc.x == 0. && acc.y == 0.){
- error(bWARNING, "open circuit: node %u\n", mm);
- acc.x = opt.gmin;
- }
- *Red(mm,mm) = acc.x;
- *Imd(mm,mm) = acc.y;
- }
- }else{ /* bn == mm */
- if (*Red(mm,mm)==0. && *Imd(mm,mm)==0.){
- if (recon[mm]!=0. || imcon[mm]!=0.)
- error(bWARNING, "open circuit: node %u\n", mm);
- *Red(mm,mm) = opt.gmin;
- }
- }
- ccck();
- }
- decomp = stats.total_nodes;
- time_stop(&(stats.lu));
- }
- /*--------------------------------------------------------------------------*/
- static complex_t dotprod(ii,jj,mm)
- int ii, jj, mm;
- {
- int ind, len;
- int kk;
- double *xrow, *xcol;
- double *yrow, *ycol;
- complex_t dot;
-
- dot.x = dot.y = 0.;
- kk = (basnode[ii]>basnode[jj]) ? basnode[ii] : basnode[jj];
- len = mm-kk;
- if (len > 0){
- xrow = Rel(ii,kk);
- xcol = Reu(kk,jj);
- yrow = Iml(ii,kk);
- ycol = Imu(kk,jj);
- /* for (i = kk; i < mm; i++) */
- for (ind = 0; ind < len; ind++){
- dot.x += (xrow[-ind] * xcol[ind]) - (yrow[-ind] * ycol[ind]);
- dot.y += (xrow[-ind] * ycol[ind]) + (yrow[-ind] * xcol[ind]);
- /*dot = cadd(dot, cxmul(xrow[-ind],yrow[-ind],xcol[ind],ycol[ind]));*/
- }
- }
- return dot;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/_msc.c'
- then
- echo shar: will not over-write existing file "'src/_msc.c'"
- else
- cat << \SHAR_EOF > 'src/_msc.c'
- /* _msc 12/29/92
- * Copyright 1983-1992 Albert Davis
- * Non-portable functions for Microsoft C.
- */
- #include "error.h"
- #include <dos.h>
- #include <process.h>
- #include <time.h>
- /*--------------------------------------------------------------------------*/
- void initialize(void);
- char csts(void);
- char ci(void);
- void shell(void);
- int system(const char*);
- static char getswitchar(void);
- double Exp(double);
- char* getwd(char*);
- /*--------------------------------------------------------------------------*/
- struct tms {
- time_t tms_utime; /* user time */
- time_t tms_stime; /* system time */
- time_t tms_cutime; /* user time, children */
- time_t tms_cstime; /* system time, children */
- };
- #define times(x) ((x)->tms_utime=clock(),(x)->tms_stime=0)
-
- /*extern int _fmode;*/ /* defined in stdlib.h */
- /*extern char **environ;*/ /* defined in stdlib.h */
- extern struct ioctrl io;
- extern char e_int[], e_om[];
- extern FILE *stream[]; /* reverse of fileno() */
- /*--------------------------------------------------------------------------*/
- void initialize()
- {
- _fpreset();
- _fmode = (int)O_BINARY;
- setbuf( stdprn, NULL );
- setmode( fileno(stdin), (int)O_BINARY );
- stream[fileno(stdaux)] = stdaux;
- stream[fileno(stdprn)] = stdprn;
- io.mprint = 1<<fileno(stdprn);
- }
- /*--------------------------------------------------------------------------*/
- static char cc;
- char csts()
- {
- return cc = (char)bdos(6,0xff,0);
- }
- char ci()
- {
- char x;
- x = cc;
- if (x) {
- cc = '\0';
- return x;
- } else {
- return (char)bdos(7,0,0);
- }
- }
- /*--------------------------------------------------------------------------*/
- void shell()
- {
- char *shell;
- int errcod;
-
- if (!(shell=getenv("COMSPEC")))
- error(bERROR, e_int, "comspec");
-
- errcod = spawnle(P_WAIT, shell, shell, NULL, environ);
- _fpreset();
- if (errcod == EOF) {
- switch (errno) {
- case E2BIG:
- error(bERROR, e_int, "arg list");
- case EINVAL:
- error(bERROR, e_int, "mode flag");
- case ENOENT:
- error(bERROR, "no shell");
- case ENOEXEC:
- error(bERROR, "bad shell");
- case ENOMEM:
- error(bERROR, e_om,"");
- default:
- error(bERROR, e_int, "system");
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- int system(string)
- const char *string;
- {
- char *shell;
- char args[200];
- int errcod;
-
- if (!(shell=getenv("COMSPEC")))
- error(bERROR, e_int, "comspec");
-
- sprintf(args,"%cc %s",getswitchar(),string);
-
- errcod = spawnle(P_WAIT, shell, shell, args, NULL, environ);
- _fpreset();
- if (errcod == EOF) {
- switch (errno) {
- case E2BIG:
- error(bERROR, e_int, "arg list");
- case EINVAL:
- error(bERROR, e_int, "mode flag");
- case ENOENT:
- error(bERROR, "no shell");
- case ENOEXEC:
- error(bERROR, "bad shell");
- case ENOMEM:
- error(bERROR, e_om, "");
- default:
- error(bERROR, e_int, "system");
- }
- }
- return 0;
- }
- /*--------------------------------------------------------------------------*/
- static char getswitchar()
- {
- union REGS r;
-
- r.h.al = 0;
- r.h.ah = 0x37;
- intdos(&r, &r);
- return r.h.dl;
- }
- /*--------------------------------------------------------------------------*/
- double Exp(x) /* exp with trap. */
- double x; /* function that comes with compiler gives strange */
- { /* answers for large negative args, */
- /* after spawning a process */
- #undef exp /* temporary fix is to return 0 for more negative */
- /* than -200. (about -700 is the threshold) */
- return (x>-200.) ? exp(x) : 0.;
- }
- /*--------------------------------------------------------------------------*/
- char *getwd(buf)
- char *buf;
- {
- char *getcwd();
- return getcwd(buf,BUFSIZ);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/_unix.c'
- then
- echo shar: will not over-write existing file "'src/_unix.c'"
- else
- cat << \SHAR_EOF > 'src/_unix.c'
- /* _unix.c 12/29/92
- * Copyright 1983-1992 Albert Davis
- * Non-portable functions for unix systems (Sun, Next, ....)
- */
- #include <signal.h>
- /*--------------------------------------------------------------------------*/
- void initialize(void);
- char csts(void);
- char ci(void);
- void shell(void);
- int min(int,int);
- /*--------------------------------------------------------------------------*/
- extern struct ioctrl io;
- /*--------------------------------------------------------------------------*/
- void initialize()
- {
- io.mprint = 0;
- }
- /*--------------------------------------------------------------------------*/
- char csts()
- {
- return '\0';
- }
- char ci()
- {
- return '\0';
- }
- /*--------------------------------------------------------------------------*/
- void shell()
- {
- (void)system(getenv("SHELL"));
- }
- /*--------------------------------------------------------------------------*/
- int min(a,b)
- int a,b;
- {
- return (a<b) ? a : b;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- # End of shell archive
- exit 0
-