home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / sources / 3104 < prev    next >
Encoding:
Text File  |  1993-01-28  |  34.2 KB  |  1,234 lines

  1. 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
  2. From: al@rbc.uucp (Al Davis)
  3. Newsgroups: alt.sources
  4. Subject: ACS  circuit simulator  part 19/20
  5. Message-ID: <1993Jan27.041125.12131@rbc.uucp>
  6. Date: 27 Jan 93 04:11:25 GMT
  7. Sender: al@rbc.uucp (Al Davis)
  8. Organization: Huh?
  9. Lines: 1223
  10.  
  11. #! /bin/sh
  12. # This is a shell archive, meaning:
  13. # 1. Remove everything above the #! /bin/sh line.
  14. # 2. Save the resulting text in a file.
  15. # 3. Execute the file with /bin/sh (not csh) to create the files:
  16. #    src/skiparg.c
  17. #    src/skipbl.c
  18. #    src/solve.c
  19. #    src/status.c
  20. #    src/stubs.c
  21. #    src/sweep.c
  22. #    src/syscall.c
  23. #    src/utos.c
  24. #    src/version.c
  25. #    src/xopen.c
  26. #    src/xsolve.c
  27. #    src/_msc.c
  28. #    src/_unix.c
  29. # This archive created: Tue Jan 26 22:51:14 1993
  30. export PATH; PATH=/bin:$PATH
  31. if test -f 'src/skiparg.c'
  32. then
  33.     echo shar: will not over-write existing file "'src/skiparg.c'"
  34. else
  35. cat << \SHAR_EOF > 'src/skiparg.c'
  36. /* skiparg  01/05/93
  37.  * Copyright 1983-1992   Albert Davis
  38.  * skip an argument in a string
  39.  */
  40. #include "ecah.h"
  41. #include "declare.h"
  42.  
  43. void skiparg(cmd,cnt)
  44. const char *cmd;
  45. int  *cnt;
  46. {
  47.  if (!skipcom(cmd,cnt)){
  48.     if (cmd[*cnt])
  49.        (*cnt)++;
  50.     while (isalnum(cmd[*cnt]) || cmd[*cnt]=='.')
  51.        (*cnt)++;
  52.     skipcom(cmd,cnt);
  53.  }
  54. }
  55. SHAR_EOF
  56. fi # end of overwriting check
  57. if test -f 'src/skipbl.c'
  58. then
  59.     echo shar: will not over-write existing file "'src/skipbl.c'"
  60. else
  61. cat << \SHAR_EOF > 'src/skipbl.c'
  62. /* skipbl  01/05/93
  63.  * Copyright 1983-1992   Albert Davis
  64.  * skip whitespace.  (any non-graphic character is ws)
  65.  * =,(,) are also ws
  66.  * update string pointer
  67.  * pointer points to first non-space
  68.  * also ..... skipcom, skiplparen, skiprparen.  obvious
  69.  * all but skipbl returns the # of them skipped (1 or 0).
  70.  */
  71. #include "ecah.h"
  72. #include "declare.h"
  73. /*--------------------------------------------------------------------------*/
  74.     void    skipbl(const char*,int*);
  75.     int    skipcom(const char*,int*);
  76.     int    skiplparen(const char*,int*);
  77.     int    skiprparen(const char*,int*);
  78.     int    skipequal(const char*,int*);
  79. /*--------------------------------------------------------------------------*/
  80. void skipbl(cmd,cnt)
  81. const char *cmd;
  82. int  *cnt;
  83. {
  84.  while (cmd[*cnt]  &&  (!isgraph(cmd[*cnt])))
  85.     (*cnt)++ ;
  86. }
  87. /*--------------------------------------------------------------------------*/
  88. int skipcom(cmd,cnt)
  89. const char *cmd;
  90. int  *cnt;
  91. {
  92.  skipbl(cmd,cnt);
  93.  if (cmd[*cnt] == ','  ||  cmd[*cnt] == '='){
  94.     (*cnt)++;
  95.     skipbl(cmd,cnt);
  96.     return 1;
  97.  }else{
  98.     skipbl(cmd,cnt);
  99.     return 0;
  100.  }
  101. }
  102. /*--------------------------------------------------------------------------*/
  103. int skiplparen(cmd,cnt)
  104. const char *cmd;
  105. int  *cnt;
  106. {
  107.  skipbl(cmd,cnt);
  108.  if (cmd[*cnt] == '('  ||  cmd[*cnt] == '['){
  109.     (*cnt)++;
  110.     skipbl(cmd,cnt);
  111.     return 1;
  112.  }else{
  113.     skipbl(cmd,cnt);
  114.     return 0;
  115.  }
  116. }
  117. /*--------------------------------------------------------------------------*/
  118. int skiprparen(cmd,cnt)
  119. const char *cmd;
  120. int  *cnt;
  121. {
  122.  skipbl(cmd,cnt);
  123.  if (cmd[*cnt] == ')'  ||  cmd[*cnt] == ']'){
  124.     (*cnt)++;
  125.     skipbl(cmd,cnt);
  126.     return 1;
  127.  }else{
  128.     skipbl(cmd,cnt);
  129.     return 0;
  130.  }
  131. }
  132. /*--------------------------------------------------------------------------*/
  133. int skipequal(cmd,cnt)
  134. const char *cmd;
  135. int  *cnt;
  136. {
  137.  skipbl(cmd,cnt);
  138.  if (cmd[*cnt] == '='){
  139.     (*cnt)++;
  140.     skipbl(cmd,cnt);
  141.     return 1;
  142.  }else{
  143.     skipbl(cmd,cnt);
  144.     return 0;
  145.  }
  146. }
  147. /*--------------------------------------------------------------------------*/
  148. /*--------------------------------------------------------------------------*/
  149. SHAR_EOF
  150. fi # end of overwriting check
  151. if test -f 'src/solve.c'
  152. then
  153.     echo shar: will not over-write existing file "'src/solve.c'"
  154. else
  155. cat << \SHAR_EOF > 'src/solve.c'
  156. /* solve  12/29/92
  157.  * Copyright 1983-1992   Albert Davis
  158.  * LU decomposition and fwd-back substitution for real numbers
  159.  * 2 modules:  lu() and solve()
  160.  * lu() does LU decomposition using the Crout algorithm (modified)
  161.  * solve() does forward and back substitution after calling lu() if necessary
  162.  */
  163. #include "ecah.h"
  164. #include "array.h"
  165. #include "error.h"
  166. #include "mode.h"
  167. #include "nodestat.h"
  168. #include "options.h"
  169. #include "status.h"
  170. #include "declare.h"
  171. /*--------------------------------------------------------------------------*/
  172.     void    solve(void);
  173. static    void    lu(void);
  174. static    double    dotprod(int,int,int);
  175. /*--------------------------------------------------------------------------*/
  176. extern const struct options opt;
  177. extern       struct status stats;
  178.  
  179. extern double *recon,*imcon,*fwcon; /* constant terms, answer column        */
  180. extern struct nodestat *nstat;
  181.  
  182. extern const double trtime;
  183. extern const int *basnode;        /* array of lowest node connected here  */
  184. /*--------------------------------------------------------------------------*/
  185. #ifdef max
  186. #undef max
  187. #endif
  188. #define max(x,y)    ( ((x)>(y)) ? (x) : (y) )
  189. /*--------------------------------------------------------------------------*/
  190. void solve()
  191. {
  192.  int jj, ii;
  193.  
  194.  lu();
  195.  time_start(&(stats.back));
  196.  for (ii = 1;  ii <= stats.total_nodes;  ++ii){        /* forward substitution */
  197.     fwcon[ii] = recon[ii];
  198.     for (jj = basnode[ii];   jj < ii;   ++jj)
  199.        fwcon[ii] -= *LUl(ii,jj) * fwcon[jj];
  200.     fwcon[ii] /= *LUd(ii,ii);
  201.  }
  202.  if (opt.foooo!=4){
  203.     for (ii = stats.total_nodes;  ii >= 1;  --ii){
  204.       imcon[ii] = fwcon[ii];
  205.       nstat[ii].aiter = stats.iter[iTOTAL];
  206.     }
  207.     for (jj = stats.total_nodes;  jj > 1;  --jj){   /* back substitution    */
  208.        for (ii = basnode[jj];   ii < jj;   ++ii){
  209.        imcon[ii] -= *LUu(ii,jj) * imcon[jj];
  210.        }
  211.     }
  212.  }else{
  213.     for (ii = stats.total_nodes;  ii >= 1;  --ii){
  214.        /*if (nstat[ii].mode != mGATE){*/
  215.       imcon[ii] = fwcon[ii];
  216.       for (jj = ii+1;  jj <= stats.total_nodes;  ++jj){
  217.          imcon[ii] -= *im(ii,jj) * imcon[jj];
  218.       }
  219.       nstat[ii].aiter = stats.iter[iTOTAL];
  220.       /*nstat[ii].mode = mLU;*/
  221.       /*nstat[ii].lastchange = trtime;*/
  222.        /*}*/
  223.     }
  224.  }
  225.  time_stop(&(stats.back));
  226.  if (opt.foooo == 1){
  227.     for (ii=1; ii<=stats.total_nodes; ++ii){
  228.        for (jj=1; jj<=stats.total_nodes; ++jj){
  229.       printf("%9.2e ", *re(ii,jj));
  230.        }
  231.        printf("%9.2e\n", recon[ii]);
  232.     }
  233.  }
  234. }
  235. /*--------------------------------------------------------------------------*/
  236. static void lu()
  237. {
  238.  int ii, jj, mm;
  239.  int bn;
  240.  
  241.  time_start(&(stats.lu));
  242.  for (mm = 1;   mm <= stats.total_nodes;   ++mm){
  243.     bn = basnode[mm];
  244.     if (bn < mm){
  245.        *LUu(bn,mm) = *AAu(bn,mm) / *LUd(bn,bn);
  246.        for (ii = bn+1;  ii<mm;  ii++){
  247.       *LUu(ii,mm) = (*AAu(ii,mm) - dotprod(ii,mm,ii)) / *LUd(ii,ii);
  248.        }
  249.        *LUl(mm,bn) = *AAl(mm,bn);
  250.        for (jj = bn+1;  jj<mm;  jj++){
  251.       *LUl(mm,jj) = *AAl(mm,jj) - dotprod(mm,jj,jj);
  252.        }
  253.        /* jj == mm */{
  254.       *LUd(mm,mm) = *AAd(mm,mm) - dotprod(mm,mm,mm);
  255.       if (*LUd(mm,mm) == 0.){
  256.          error(bTRACE, "open circuit: node %u\n", mm);
  257.          *LUd(mm,mm) = opt.gmin;
  258.       }
  259.        }
  260.     }else{    /* bn == mm */
  261.        *LUd(mm,mm) = *AAd(mm,mm);
  262.        if (*LUd(mm,mm) == 0.){
  263.       error(bTRACE, "open circuit: node %u\n", mm);
  264.       *LUd(mm,mm) = opt.gmin;
  265.        }
  266.     }
  267.  }
  268.  time_stop(&(stats.lu));
  269. }
  270. /*--------------------------------------------------------------------------*/
  271. static double dotprod(ii,jj,mm)
  272. int ii, jj, mm;
  273. {
  274.  int ind, len;
  275.  int kk;
  276.  double *row, *col;
  277.  double dot = 0.;
  278.  
  279.  kk = max(basnode[ii], basnode[jj]);
  280.  len = mm - kk;
  281.  if (len > 0){
  282.     row = LUl(ii,kk);
  283.     col = LUu(kk,jj);
  284.     /* for (i = kk;   i < mm;   i++) */
  285.     for (ind = 0;   ind < len;   ind++)
  286.         dot += row[-ind] * col[ind];
  287.  }
  288.  return dot;
  289. }
  290. /*--------------------------------------------------------------------------*/
  291. /*--------------------------------------------------------------------------*/
  292. SHAR_EOF
  293. fi # end of overwriting check
  294. if test -f 'src/status.c'
  295. then
  296.     echo shar: will not over-write existing file "'src/status.c'"
  297. else
  298. cat << \SHAR_EOF > 'src/status.c'
  299. /* status  02/15/92
  300.  * Copyright 1983-1992   Albert Davis
  301.     Displays the status of the system.    Makes all the calculations associated
  302. with allocating memory but does not actually allocate it, unless necessary to
  303. make the rest of the calculations.
  304.  
  305.     If "allocate" is changed, this must also be changed.
  306.  
  307. */
  308. #include "ecah.h"
  309. #include "branch.h"
  310. #include "error.h"
  311. #include "io.h"
  312. #include "mode.h"
  313. #include "status.h"
  314. #include "declare.h"
  315. /*--------------------------------------------------------------------------*/
  316.     void    cmd_status(void);
  317. static    void    fixoverhead(struct status*);
  318. static    void    printtime(char*, struct time_s);
  319. /*--------------------------------------------------------------------------*/
  320. extern const struct ioctrl io;
  321. extern       struct status stats;
  322.  
  323. extern const unsigned aspace;
  324. /*--------------------------------------------------------------------------*/
  325. void cmd_status()
  326.  mprintf(io.mstdout,"ACS   System status\n");
  327.  allocate(sSTATUS);
  328.  
  329.  if (stats.total_nodes)
  330.     stats.density = ((double)(aspace-1)*100.)/
  331.                 ((double)stats.total_nodes*(double)stats.total_nodes);
  332.  else
  333.     stats.density = 0.;
  334.  
  335.  mprintf(io.mstdout,
  336.  "command      --------  last  --------    --------  total  --------\n");
  337.  mprintf(io.mstdout,
  338.  "               user      sys    total       user      sys    total\n");
  339.  printtime("get",     stats.get);
  340.  printtime("op",      stats.op);
  341.  printtime("dc",      stats.dc);
  342.  printtime("tran",    stats.tran);
  343.  printtime("fourier", stats.four);
  344.  printtime("ac",      stats.ac);
  345.  
  346.  mprintf(io.mstdout,
  347.  "function     --------  last  --------    --------  total  --------\n");
  348.  mprintf(io.mstdout,
  349.  "               user      sys    total       user      sys    total\n");
  350.  printtime("setup",   stats.setup);
  351.  printtime("order",   stats.order);
  352.  
  353.  fixoverhead(&stats);
  354.  mprintf(io.mstdout,
  355.  "function     --------  last  --------    --------  total  --------\n");
  356.  mprintf(io.mstdout,
  357.  "               user      sys    total       user      sys    total\n");
  358.  printtime("load",    stats.load);
  359.  printtime("lu",      stats.lu);
  360.  printtime("back",    stats.back);
  361.  printtime("review",  stats.review);
  362.  printtime("output",  stats.output);
  363.  printtime("overhead",stats.overhead);
  364.  printtime("total",   stats.total);
  365.  
  366.  mprintf(io.mstdout,"iterations: op=%d, dc=%d, tran=%d, fourier=%d, total=%d\n",
  367.      stats.iter[sOP], stats.iter[sDC], stats.iter[sTRAN], stats.iter[sFOURIER],
  368.      stats.iter[iTOTAL]);
  369.  mprintf(io.mstdout,"nodes: user=%d, subckt=%d, model=%d, total=%d\n",
  370.      stats.user_nodes, stats.subckt_nodes, stats.model_nodes,
  371.      stats.total_nodes);
  372.  mprintf(io.mstdout,"density=%.1f%%\n", stats.density);
  373. #ifdef NEVER
  374.  mprintf(io.mstdout,"diodes=%d, bjts=%d, mosfets=%d, gates=%d subckts=%d\n",
  375.      stats.diodes, stats.bjts, stats.mosfets, stats.gates, stats.subckts);
  376.  mprintf(io.mstdout,"matrix: terms=%d, fills=%d, total=%d, ops=%d\n",
  377.      stats.matrix_terms, stats.matrix_fills, stats.matrix_total,
  378.      stats.matrix_ops);
  379. #endif
  380. }
  381. /*--------------------------------------------------------------------------*/
  382. static void fixoverhead(x)
  383. struct status *x;
  384. {
  385.  x->overhead.last_user = x->total.last_user - x->load.last_user -
  386.     x->lu.last_user - x->back.last_user - x->output.last_user - x->review.last_user;
  387.  
  388.  x->overhead.last_system = x->total.last_system - x->load.last_system -
  389.     x->lu.last_system - x->back.last_system - x->output.last_system - x->review.last_system;
  390.  
  391.  x->overhead.total_user = x->total.total_user - x->load.total_user -
  392.     x->lu.total_user - x->back.total_user - x->output.total_user - x->review.total_user;
  393.  
  394.  x->overhead.total_system = x->total.total_system - x->load.total_system -
  395.     x->lu.total_system - x->back.total_system - x->output.total_system - x->review.total_system;
  396. }
  397. /*--------------------------------------------------------------------------*/
  398. static void printtime(name, v)
  399. char *name;
  400. struct time_s v;
  401. {
  402.  mprintf(io.mstdout, "%10s %8.2f %8.2f %8.2f   %8.2f %8.2f %8.2f\n", name,
  403.     v.last_user,  v.last_system,  v.last_user  + v.last_system,
  404.     v.total_user, v.total_system, v.total_user + v.total_system);
  405. }
  406. /*--------------------------------------------------------------------------*/
  407. /*--------------------------------------------------------------------------*/
  408. SHAR_EOF
  409. fi # end of overwriting check
  410. if test -f 'src/stubs.c'
  411. then
  412.     echo shar: will not over-write existing file "'src/stubs.c'"
  413. else
  414. cat << \SHAR_EOF > 'src/stubs.c'
  415. /* stubs.c  01/01/93
  416.  * Copyright 1983-1992   Albert Davis
  417.  * stubs to satisfy references to Spice commands not supported here
  418.  */
  419. #include "ecah.h"
  420. #include "error.h"
  421. #include "declare.h"
  422. /*--------------------------------------------------------------------------*/
  423.     void    cmd_alter(const char*,int*);
  424.     void    cmd_disto(const char*,int*);
  425.     void    cmd_model(const char*,int*);
  426.     void    cmd_noise(const char*,int*);
  427.     void    cmd_sens(const char*,int*);
  428.     void    cmd_subckt(const char*,int*);
  429.     void    cmd_temp(const char*,int*);
  430.     void    cmd_tf(const char*,int*);
  431. /*--------------------------------------------------------------------------*/
  432. static    char    e_spice[] = "Spice dot-card not implemented: %s\n";
  433. /*--------------------------------------------------------------------------*/
  434. /*ARGSUSED*/
  435. void cmd_alter(cmd,cnt)
  436. const char *cmd;
  437. int *cnt;
  438. {
  439.  error(bWARNING, e_spice, cmd);
  440. }
  441. /*--------------------------------------------------------------------------*/
  442. /*ARGSUSED*/
  443. void cmd_disto(cmd,cnt)
  444. const char *cmd;
  445. int *cnt;
  446. {
  447.  error(bWARNING, e_spice, cmd);
  448. }
  449. /*--------------------------------------------------------------------------*/
  450. /*ARGSUSED*/
  451. void cmd_model(cmd,cnt)
  452. const char *cmd;
  453. int *cnt;
  454. {
  455.  error(bWARNING, e_spice, cmd);
  456. }
  457. /*--------------------------------------------------------------------------*/
  458. /*ARGSUSED*/
  459. void cmd_noise(cmd,cnt)
  460. const char *cmd;
  461. int *cnt;
  462. {
  463.  error(bWARNING, e_spice, cmd);
  464. }
  465. /*--------------------------------------------------------------------------*/
  466. /*ARGSUSED*/
  467. void cmd_sens(cmd,cnt)
  468. const char *cmd;
  469. int *cnt;
  470. {
  471.  error(bWARNING, e_spice, cmd);
  472. }
  473. /*--------------------------------------------------------------------------*/
  474. /*ARGSUSED*/
  475. void cmd_subckt(cmd,cnt)
  476. const char *cmd;
  477. int *cnt;
  478. {
  479.  error(bWARNING, e_spice, cmd);
  480. }
  481. /*--------------------------------------------------------------------------*/
  482. /*ARGSUSED*/
  483. void cmd_temp(cmd,cnt)
  484. const char *cmd;
  485. int *cnt;
  486. {
  487.  error(bWARNING, e_spice, cmd);
  488. }
  489. /*--------------------------------------------------------------------------*/
  490. /*ARGSUSED*/
  491. void cmd_tf(cmd,cnt)
  492. const char *cmd;
  493. int *cnt;
  494. {
  495.  error(bWARNING, e_spice, cmd);
  496. }
  497. /*--------------------------------------------------------------------------*/
  498. /*--------------------------------------------------------------------------*/
  499. SHAR_EOF
  500. fi # end of overwriting check
  501. if test -f 'src/sweep.c'
  502. then
  503.     echo shar: will not over-write existing file "'src/sweep.c'"
  504. else
  505. cat << \SHAR_EOF > 'src/sweep.c'
  506. /* sweep  12/31/92
  507.  * Copyright 1983-1992   Albert Davis
  508.  * Step a parameter and repeat a group of commands
  509.  */
  510. #include "ecah.h"
  511. #include "branch.h"
  512. #include "error.h"
  513. #include "io.h"
  514. #include "declare.h"
  515. /*--------------------------------------------------------------------------*/
  516.     void    cmd_sweep(const char*,int*);
  517. static    void    buildfile(const char*,int*);
  518. static    void    doit(void);
  519. static    void    setup(const char*,int*);
  520. /*--------------------------------------------------------------------------*/
  521. extern const struct ioctrl io;
  522. extern int crtplot;
  523. extern int swp_count[], swp_steps[];
  524. extern int swp_type[];
  525. extern int swp_nest;
  526. static char tempfile[] = STEPFILE;
  527. /*--------------------------------------------------------------------------*/
  528. void cmd_sweep(cmd,cnt)
  529. const char *cmd;
  530. int  *cnt;
  531. {
  532.  if (cmd[*cnt])
  533.     buildfile(cmd,cnt);
  534.  doit();
  535.  cmd_unfault();
  536. }
  537. /*--------------------------------------------------------------------------*/
  538. static void buildfile(cmd,cnt)
  539. const char *cmd;
  540. int  *cnt;
  541. {
  542.  auto char buffer[BUFLEN];
  543.  static FILE *fptr;
  544.  
  545.  setup(cmd,cnt);
  546.  if (fptr)
  547.      (void)fclose(fptr);
  548.  fptr = fopen( tempfile, "w" );
  549.  if (!fptr)
  550.     error(bERROR, "can't open temporary file\n" );
  551.  (void)fprintf(fptr, "%s\n", cmd );
  552.  
  553.  for (;;){
  554.     (void)getcmd( ">>>", buffer, BUFLEN );
  555.     if ( match(buffer,"GO") )
  556.        break;
  557.     (void)fprintf(fptr,"%s\n",buffer);
  558.  }
  559.  (void)fclose(fptr);
  560.  fptr = (FILE*)NULL;
  561. }
  562. /*--------------------------------------------------------------------------*/
  563. static void doit()
  564. {
  565.  auto char buffer[BUFLEN];
  566.  static FILE *fptr;
  567.  volatile int ind;
  568.  
  569.  for ( swp_count[swp_nest]=0 ; swp_count[swp_nest]<=swp_steps[swp_nest] ;
  570.        swp_count[swp_nest]++ ){
  571.     if (fptr)
  572.        (void)fclose(fptr);
  573.     fptr = fopen(tempfile, "r");
  574.     if (!fptr)
  575.        error(bERROR, "can't open %s\n", tempfile);
  576.     (void)fgets(buffer,BUFLEN,fptr);
  577.     ind = 0;
  578.     if ( pmatch(buffer,&ind,"SWeep") )
  579.        setup(buffer,&ind);
  580.     else
  581.        error(bERROR, "bad file format: %s\n", tempfile);
  582.     strncpy( buffer, "fault                              ", ind);
  583.     buffer[ind-1] = ' ';        /* make sure there is a delimiter   */
  584.                     /* in case the words run together   */
  585.     for (;;){                /* may wipe out one letter of fault */
  586.        (void)cmdproc(buffer);
  587.        if (!fgets(buffer,BUFLEN,fptr))
  588.       break;
  589.        if (!crtplot)
  590.       mprintf(io.mstdout,"%u> %s", swp_count[swp_nest]+1, buffer);
  591.     }
  592.  }
  593.  (void)fclose(fptr);
  594.  fptr = (FILE*)NULL;
  595.  swp_count[swp_nest] = 0;
  596. }
  597. /*--------------------------------------------------------------------------*/
  598. static void setup(cmd,cnt)
  599. const char *cmd;
  600. int  *cnt;
  601. {
  602.  for (;;){
  603.     if (isdigit(cmd[*cnt])){
  604.        swp_steps[swp_nest] = ctoi(cmd,cnt) ;
  605.        swp_steps[swp_nest] = (swp_steps[swp_nest]) ? swp_steps[swp_nest]-1
  606.                            : 0;
  607.     }else if (pmatch(cmd,cnt,"LInear")){
  608.        swp_type[swp_nest] = 0;
  609.     }else if (pmatch(cmd,cnt,"LOg")){
  610.        swp_type[swp_nest] = 'L';
  611.     }else{
  612.        break;
  613.     }
  614.  }
  615. }
  616. /*--------------------------------------------------------------------------*/
  617. /*--------------------------------------------------------------------------*/
  618. SHAR_EOF
  619. fi # end of overwriting check
  620. if test -f 'src/syscall.c'
  621. then
  622.     echo shar: will not over-write existing file "'src/syscall.c'"
  623. else
  624. cat << \SHAR_EOF > 'src/syscall.c'
  625. /* syscall  10/08/91
  626.  * Copyright 1983-1992   Albert Davis
  627.  * system calls: change directory, invoke another program, invoke editor, etc.
  628.  */
  629. #include "ecah.h"
  630. #include "error.h"
  631. #include "io.h"
  632. #include "declare.h"
  633. /*--------------------------------------------------------------------------*/
  634.     void    cmd_edit(const char*,int*);
  635.     void    cmd_system(const char*,int*);
  636.     void    cmd_chdir(const char*,int*);
  637. /*--------------------------------------------------------------------------*/
  638. extern const struct ioctrl io;
  639. extern char e_int[];
  640. /*--------------------------------------------------------------------------*/
  641. /* cmd_edit: (command) invoke user defined editor on the netlist
  642.  * if command has an argument, it edits that file instead
  643.  * else actually edits a temporary file, and reads it back.
  644.  */
  645. void cmd_edit(cmd,cnt)
  646. const char *cmd;
  647. int  *cnt;
  648. {
  649.  char *editor;
  650.  char name[BUFLEN];
  651.  char args[BUFLEN];
  652.  
  653.  editor = getenv("EDITOR");
  654.  if (!editor)
  655.     error(bERROR, "no editor defined\n");
  656.  
  657.  if (cmd[*cnt]) {
  658.     sprintf(args, "%s %s\n", editor, &cmd[*cnt]);
  659.     system(args);
  660.  } else {
  661.     strcpy(name, EDITFILE);
  662.     (void)mktemp(name);
  663.     sprintf(args, "save %s\n", name);
  664.     (void)cmdproc(args);
  665.     sprintf(args, "%s %s\n", editor, name);
  666.     system(args);
  667.     sprintf(args, "get %s quiet\n", name);
  668.     (void)cmdproc(args);
  669.     unlink(name);
  670.  }
  671. }
  672. /*--------------------------------------------------------------------------*/
  673. /* cmd_system: (! command) call the system to execute a command
  674.  * no arg spawns a shell.
  675.  */
  676. void cmd_system(cmd,cnt)
  677. const char *cmd;
  678. int  *cnt;
  679. {
  680.  if (cmd[*cnt])
  681.     system(&cmd[*cnt]);
  682.  else
  683.     shell();
  684. }
  685. /*--------------------------------------------------------------------------*/
  686. /* cmd_chdir: (cd, chdir command)
  687.  * change working directory, print name of where it ends up
  688.  * no arg just prints, does not change to a default.
  689.  */
  690. void cmd_chdir(cmd,cnt)
  691. const char *cmd;
  692. int  *cnt;
  693. {
  694.  char buf[BUFLEN];
  695.  
  696.  if (cmd[*cnt])
  697.     (void)chdir( ctostr(cmd,cnt,buf,BUFLEN-1) );
  698.  if (getwd(buf))
  699.     mprintf(io.mstderr, "%s\n", buf);
  700.  else
  701.     error(bERROR, e_int, "getcwd");
  702. }
  703. /*--------------------------------------------------------------------------*/
  704. /*--------------------------------------------------------------------------*/
  705. SHAR_EOF
  706. fi # end of overwriting check
  707. if test -f 'src/utos.c'
  708. then
  709.     echo shar: will not over-write existing file "'src/utos.c'"
  710. else
  711. cat << \SHAR_EOF > 'src/utos.c'
  712. /* utos     11/06/89
  713.  * Copyright 1983-1992   Albert Davis
  714.  * unsigned to string
  715.  * num = number to convert.
  716.  * str = string to put it in.  Must be big enough, or else!!
  717.  *        Must have length at least len.
  718.  * len = number of significant digits.
  719.  *     If minus, left justify, else right.
  720.  */
  721. #include "ecah.h"
  722. #include "declare.h"
  723. /*--------------------------------------------------------------------------*/
  724.     char      *utos(unsigned,char*,int);
  725. /*--------------------------------------------------------------------------*/
  726. char *utos( num, str, len )
  727. char *str;
  728. unsigned  num;
  729. int len;
  730. {
  731.  int ii, jj;
  732.  
  733.  if ( len==0 ) return str;                /*    reject zero length  */
  734.  ii = abs(len);
  735.  
  736.  do {                    /*   build string starting at tail  */
  737.     str[--ii] = (char)(num % 10 + '0');
  738.  } while ( (num/=10)>0 && ii>0 );
  739.  
  740.  if (len > 0){                /*     if right justify, fill with blank  */
  741.     while (ii > 0)
  742.        str[--ii] = ' ';
  743.  }else{                    /* else if left justify, move left  */
  744.     for (jj=0;  ii<-len;  )        /*    then fill with blanks        */
  745.        str[jj++] = str[ii++];
  746.     while (jj < -len)
  747.        str[jj++] = ' ';
  748.  }
  749.  return str;
  750. }
  751. /*--------------------------------------------------------------------------*/
  752. /*--------------------------------------------------------------------------*/
  753. SHAR_EOF
  754. fi # end of overwriting check
  755. if test -f 'src/version.c'
  756. then
  757.     echo shar: will not over-write existing file "'src/version.c'"
  758. else
  759. cat << \SHAR_EOF > 'src/version.c'
  760. /* version.c  10/08/91
  761.  * Copyright 1983-1992   Albert Davis
  762.  * a dumb selector for portability
  763.  */
  764. #include "ecah.h"
  765. #include "io.h"
  766. #include "declare.h"
  767. /*--------------------------------------------------------------------------*/
  768. #ifdef UNIX
  769. #include "_unix.c"
  770. #endif
  771.  
  772. #ifdef MSC
  773. #include "_msc.c"
  774. #endif
  775. /*--------------------------------------------------------------------------*/
  776. /*--------------------------------------------------------------------------*/
  777. SHAR_EOF
  778. fi # end of overwriting check
  779. if test -f 'src/xopen.c'
  780. then
  781.     echo shar: will not over-write existing file "'src/xopen.c'"
  782. else
  783. cat << \SHAR_EOF > 'src/xopen.c'
  784. /* xopen  01/11/93
  785.  * Copyright 1983-1992   Albert Davis
  786.  * scan a string for a file name
  787.  * fill in extension, if necessary
  788.  * open file
  789.  */
  790. #include "ecah.h"
  791. #include "error.h"
  792. #include <time.h>
  793. #include "declare.h"
  794. /*--------------------------------------------------------------------------*/
  795.     void    xclose(FILE**);
  796.     FILE*    xopen(const char*,int*,const char*,const char*);
  797. /*--------------------------------------------------------------------------*/
  798. extern FILE *stream[];
  799. /*--------------------------------------------------------------------------*/
  800. void xclose(fn)
  801. FILE **fn;
  802. {
  803.  if (*fn){
  804.     (void)fclose(*fn);
  805.     *fn = (FILE*)NULL;
  806.  }
  807. }
  808. /*--------------------------------------------------------------------------*/
  809. FILE *xopen(cmd,cnt,ext,how)
  810. const char *cmd, *ext, *how;
  811. int *cnt;
  812. {
  813.  int i;
  814.  int defalt;
  815.  FILE *code;
  816.  char fname[BUFLEN+5];
  817.  
  818.  skipbl(cmd,cnt);
  819.  if (!cmd[*cnt]){
  820.     volatile int loccount;
  821.     cmd = getcmd ("file name?  ",fname,BUFLEN);
  822.     loccount = 0;
  823.     cnt = &loccount;
  824.  }
  825.  
  826.  skipbl(cmd,cnt);            /* find out if we want to add the   */
  827.  defalt = YES;                /* default extension            */
  828.  for (i = 0;   i < BUFLEN;   ){
  829.     char c;
  830.     c = cmd[(*cnt)++];
  831.     if (isterm(c))
  832.        break;
  833.     if (c == '$'){
  834.        sprintf(&(fname[i]), "%ld", time((long*)NULL));
  835.        i = strlen(fname);
  836.     }else{
  837.        fname[i++] = c;
  838.        if (c == '.')
  839.           defalt = NO;
  840.        else if (c == '\\'  ||  c == '/')
  841.           defalt = YES;
  842.     }
  843.  }
  844.  (*cnt)--;
  845.  if (defalt){                /* add the extension            */
  846.     fname[i++] = '.';
  847.     strcpy(&fname[i],ext);
  848.  }else{
  849.     fname[i] = '\0';
  850.  }
  851.  
  852.  (void)trim(fname);
  853.  skipcom(cmd,cnt);
  854.  
  855.  if ((*how == 'w')   &&   (access(fname,F_OK) == GOOD)){
  856.     char buffer[BUFLEN];        
  857.     error(bWARNING, "%s exists.  replace? ", fname);
  858.     (void)getcmd ("", buffer, BUFLEN);
  859.     if (match(buffer,"Yes"))        /* should be new file, but        */
  860.     code = fopen(fname,how);    /* file already exists,  ask        */
  861.     else
  862.     return (FILE*)NULL;
  863.  }else{
  864.     code = fopen(fname,how);
  865.  }
  866.  
  867.  if (code && fileno(code)>MAXHANDLE){
  868.     error(bWARNING, "internal error: files: %d\n", fileno(code));
  869.     (void)fclose(code);
  870.     code = (FILE*)NULL;
  871.  }
  872.  if (code)
  873.     stream[fileno(code)] = code;
  874.  else
  875.     error(bWARNING, "can't open %s\n", fname);
  876.  return code;
  877. }
  878. /*--------------------------------------------------------------------------*/
  879. /*--------------------------------------------------------------------------*/
  880. SHAR_EOF
  881. fi # end of overwriting check
  882. if test -f 'src/xsolve.c'
  883. then
  884.     echo shar: will not over-write existing file "'src/xsolve.c'"
  885. else
  886. cat << \SHAR_EOF > 'src/xsolve.c'
  887. /* xsolve  12/29/92
  888.  * Copyright 1983-1992   Albert Davis
  889.  * LU decomposition and fwd-back substitution for complex numbers
  890.  * 2 modules:  xlu() and xsolve()
  891.  * xlu() does LU decomposition using the Crout algorithm
  892.  * xsolve() does forward and back substitution after calling xlu() if necessary
  893.  * For a readable version of this, see the real number version: solve
  894.  */
  895. #include "ecah.h"
  896. #include "array.h"
  897. #include "error.h"
  898. #include "options.h"
  899. #include "status.h"
  900. #include "declare.h"
  901. /*--------------------------------------------------------------------------*/
  902.     void      xsolve(void);
  903. static    void      lu(void);
  904. static    complex_t dotprod(int,int,int);
  905. /*--------------------------------------------------------------------------*/
  906. extern const struct options opt;
  907. extern       struct status stats;
  908.  
  909. extern double *recon,*imcon;        /* constant terms, answer column        */
  910. extern int decomp;            /* how far been decomposed            */
  911. extern const int *basnode;        /* array of lowest node connected here  */
  912. /*--------------------------------------------------------------------------*/
  913. void xsolve()
  914. {
  915.  int jj, ii;
  916.  
  917.  lu();
  918.  ccck();
  919.  time_start(&(stats.back));
  920.  for (ii = 1; ii <= stats.total_nodes; ++ii){        /* forward substitution */
  921.     complex_t acc;
  922.     acc.x = recon[ii];
  923.     acc.y = imcon[ii];
  924.     for ( jj=basnode[ii]; jj<ii; ++jj ){
  925.        /* con[ii] -= Lower[ii][jj] * con[jj] */
  926.        acc = csub(acc, cxmul(*Rel(ii,jj),*Iml(ii,jj), recon[jj],imcon[jj]));
  927.     }
  928.  
  929.     /*  con[ii] /= *xy(ii,ii)   */
  930.     acc = cxdiv(acc.x,acc.y, *Red(ii,ii),*Imd(ii,ii));
  931.     recon[ii] = acc.x;
  932.     imcon[ii] = acc.y;
  933.  }
  934.  ccck();
  935.  for (jj = stats.total_nodes; jj > 1; --jj)        /* back substitution    */
  936.     for (ii = basnode[jj];   ii < jj;   ++ii){
  937.        /* con[ii] -= *Upper[ii][jj] * con[jj] */
  938.        complex_t acc;
  939.        acc = cxmul(*Reu(ii,jj),*Imu(ii,jj), recon[jj],imcon[jj]);
  940.        acc = cxsub(recon[ii],imcon[ii], acc.x,acc.y);
  941.        recon[ii] = acc.x;
  942.        imcon[ii] = acc.y;
  943.     }
  944.  time_stop(&(stats.back));
  945.  ccck();
  946. }
  947. /*--------------------------------------------------------------------------*/
  948. static void lu()
  949. {
  950.  complex_t acc;
  951.  int ii, jj, mm;
  952.  int bn;
  953.  
  954.  time_start(&(stats.lu));
  955.  for (mm = decomp+1;   mm <= stats.total_nodes;   ++mm){
  956.     bn = basnode[mm];
  957.     if (bn < mm){
  958.        /* *Upper(bn,mm) /= *Diag(bn,bn); */
  959.        acc = cxdiv(*Reu(bn,mm),*Imu(bn,mm), *Red(bn,bn),*Imd(bn,bn));
  960.        *Reu(bn,mm) = acc.x;
  961.        *Imu(bn,mm) = acc.y;
  962.  
  963.        for (ii =bn+1;  ii<mm;  ii++){
  964.       acc = dotprod(ii,mm,ii);
  965.       acc = cxsub(*Reu(ii,mm),*Imu(ii,mm), acc.x,acc.y);
  966.       acc = cxdiv(acc.x,acc.y, *Red(ii,ii),*Imd(ii,ii));
  967.       *Reu(ii,mm) = acc.x;
  968.       *Imu(ii,mm) = acc.y;
  969.        }
  970.        for (jj = bn+1;  jj<mm;  jj++){
  971.       acc = dotprod(mm,jj,jj);
  972.       acc = cxsub(*Rel(mm,jj),*Iml(mm,jj), acc.x,acc.y);
  973.       *Rel(mm,jj) = acc.x;
  974.       *Iml(mm,jj) = acc.y;
  975.        }
  976.        /* jj == mm */{
  977.       acc = dotprod(mm,mm,mm);
  978.       acc = cxsub(*Red(mm,mm),*Imd(mm,mm), acc.x,acc.y);
  979.       if (acc.x == 0.  &&  acc.y == 0.){
  980.          error(bWARNING, "open circuit: node %u\n", mm);
  981.          acc.x = opt.gmin;
  982.       }
  983.       *Red(mm,mm) = acc.x;
  984.       *Imd(mm,mm) = acc.y;
  985.        }
  986.     }else{    /* bn == mm */
  987.        if (*Red(mm,mm)==0. && *Imd(mm,mm)==0.){
  988.       if (recon[mm]!=0. || imcon[mm]!=0.)
  989.          error(bWARNING, "open circuit: node %u\n", mm);
  990.       *Red(mm,mm) = opt.gmin;
  991.        }
  992.     }
  993.     ccck();
  994.  }
  995.  decomp = stats.total_nodes;
  996.  time_stop(&(stats.lu));
  997. }
  998. /*--------------------------------------------------------------------------*/
  999. static complex_t dotprod(ii,jj,mm)
  1000. int ii, jj, mm;
  1001. {
  1002.  int ind, len;
  1003.  int kk;
  1004.  double *xrow, *xcol;
  1005.  double *yrow, *ycol;
  1006.  complex_t dot;
  1007.  
  1008.  dot.x = dot.y = 0.;
  1009.  kk = (basnode[ii]>basnode[jj]) ? basnode[ii] : basnode[jj];
  1010.  len = mm-kk;
  1011.  if (len > 0){
  1012.     xrow = Rel(ii,kk);
  1013.     xcol = Reu(kk,jj);
  1014.     yrow = Iml(ii,kk);
  1015.     ycol = Imu(kk,jj);
  1016.     /* for (i = kk;   i < mm;   i++) */
  1017.     for (ind = 0;   ind < len;   ind++){
  1018.        dot.x += (xrow[-ind] * xcol[ind]) - (yrow[-ind] * ycol[ind]);
  1019.        dot.y += (xrow[-ind] * ycol[ind]) + (yrow[-ind] * xcol[ind]);
  1020.        /*dot = cadd(dot, cxmul(xrow[-ind],yrow[-ind],xcol[ind],ycol[ind]));*/
  1021.     }
  1022.  }
  1023.  return dot;
  1024. }
  1025. /*--------------------------------------------------------------------------*/
  1026. /*--------------------------------------------------------------------------*/
  1027. SHAR_EOF
  1028. fi # end of overwriting check
  1029. if test -f 'src/_msc.c'
  1030. then
  1031.     echo shar: will not over-write existing file "'src/_msc.c'"
  1032. else
  1033. cat << \SHAR_EOF > 'src/_msc.c'
  1034. /* _msc  12/29/92
  1035.  * Copyright 1983-1992   Albert Davis
  1036.  * Non-portable functions for Microsoft C.
  1037.  */
  1038. #include "error.h"
  1039. #include <dos.h>
  1040. #include <process.h>
  1041. #include <time.h>
  1042. /*--------------------------------------------------------------------------*/
  1043.     void    initialize(void);
  1044.     char    csts(void);
  1045.     char    ci(void);
  1046.     void    shell(void);
  1047.     int    system(const char*);
  1048. static    char    getswitchar(void);
  1049.     double    Exp(double);
  1050.     char*    getwd(char*);
  1051. /*--------------------------------------------------------------------------*/
  1052. struct tms {
  1053.     time_t    tms_utime;        /* user time */
  1054.     time_t    tms_stime;        /* system time */
  1055.     time_t    tms_cutime;        /* user time, children */
  1056.     time_t    tms_cstime;        /* system time, children */
  1057. };
  1058. #define times(x) ((x)->tms_utime=clock(),(x)->tms_stime=0)
  1059.  
  1060. /*extern int _fmode;*/        /* defined in stdlib.h */
  1061. /*extern char **environ;*/  /* defined in stdlib.h */
  1062. extern struct ioctrl io;
  1063. extern char e_int[], e_om[];
  1064. extern FILE *stream[];        /* reverse of fileno() */
  1065. /*--------------------------------------------------------------------------*/
  1066. void initialize()
  1067. {
  1068.  _fpreset();
  1069.  _fmode = (int)O_BINARY;
  1070.  setbuf( stdprn, NULL );
  1071.  setmode( fileno(stdin), (int)O_BINARY );
  1072.  stream[fileno(stdaux)] = stdaux;
  1073.  stream[fileno(stdprn)] = stdprn;
  1074.  io.mprint = 1<<fileno(stdprn);
  1075. }
  1076. /*--------------------------------------------------------------------------*/
  1077. static char cc;
  1078. char csts()
  1079. {
  1080.  return cc = (char)bdos(6,0xff,0);
  1081. }
  1082. char ci()
  1083. {
  1084.  char x;
  1085.  x = cc;
  1086.  if (x) {
  1087.     cc = '\0';
  1088.     return x;
  1089.  } else {
  1090.     return (char)bdos(7,0,0);
  1091.  }
  1092. }
  1093. /*--------------------------------------------------------------------------*/
  1094. void shell()
  1095. {
  1096.  char *shell;
  1097.  int errcod;
  1098.  
  1099.  if (!(shell=getenv("COMSPEC")))
  1100.     error(bERROR, e_int, "comspec");
  1101.  
  1102.  errcod = spawnle(P_WAIT, shell, shell, NULL, environ);
  1103.  _fpreset();
  1104.  if (errcod == EOF) {
  1105.     switch (errno) {
  1106.        case E2BIG:
  1107.           error(bERROR, e_int, "arg list");
  1108.        case EINVAL:
  1109.           error(bERROR, e_int, "mode flag");
  1110.        case ENOENT:
  1111.           error(bERROR, "no shell");
  1112.        case ENOEXEC:
  1113.           error(bERROR, "bad shell");
  1114.        case ENOMEM:
  1115.           error(bERROR, e_om,"");
  1116.        default:
  1117.           error(bERROR, e_int, "system");
  1118.     }
  1119.  }
  1120. }
  1121. /*--------------------------------------------------------------------------*/
  1122. int system(string)
  1123. const char *string;
  1124. {
  1125.  char *shell;
  1126.  char args[200];
  1127.  int errcod;
  1128.  
  1129.  if (!(shell=getenv("COMSPEC")))
  1130.     error(bERROR, e_int, "comspec");
  1131.  
  1132.  sprintf(args,"%cc %s",getswitchar(),string);
  1133.  
  1134.  errcod = spawnle(P_WAIT, shell, shell, args, NULL, environ);
  1135.  _fpreset();
  1136.  if (errcod == EOF) {
  1137.     switch (errno) {
  1138.        case E2BIG:
  1139.           error(bERROR, e_int, "arg list");
  1140.        case EINVAL:
  1141.           error(bERROR, e_int, "mode flag");
  1142.        case ENOENT:
  1143.           error(bERROR, "no shell");
  1144.        case ENOEXEC:
  1145.           error(bERROR, "bad shell");
  1146.        case ENOMEM:
  1147.           error(bERROR, e_om, "");
  1148.        default:
  1149.           error(bERROR, e_int, "system");
  1150.     }
  1151.  }
  1152. return 0;
  1153. }
  1154. /*--------------------------------------------------------------------------*/
  1155. static char getswitchar()
  1156. {
  1157.  union REGS r;
  1158.  
  1159.  r.h.al = 0;
  1160.  r.h.ah = 0x37;
  1161.  intdos(&r, &r);
  1162.  return r.h.dl;
  1163. }
  1164. /*--------------------------------------------------------------------------*/
  1165. double Exp(x)        /* exp with trap.                    */
  1166. double x;        /* function that comes with compiler gives strange  */
  1167. {            /* answers for large negative args,            */
  1168.             /* after spawning a process                */
  1169. #undef exp        /* temporary fix is to return 0 for more negative   */
  1170.             /* than -200.  (about -700 is the threshold)        */
  1171.  return (x>-200.) ? exp(x) : 0.;
  1172. }
  1173. /*--------------------------------------------------------------------------*/
  1174. char *getwd(buf)
  1175. char *buf;
  1176. {
  1177.  char *getcwd();
  1178.  return getcwd(buf,BUFSIZ);
  1179. }
  1180. /*--------------------------------------------------------------------------*/
  1181. /*--------------------------------------------------------------------------*/
  1182. SHAR_EOF
  1183. fi # end of overwriting check
  1184. if test -f 'src/_unix.c'
  1185. then
  1186.     echo shar: will not over-write existing file "'src/_unix.c'"
  1187. else
  1188. cat << \SHAR_EOF > 'src/_unix.c'
  1189. /* _unix.c  12/29/92
  1190.  * Copyright 1983-1992   Albert Davis
  1191.  * Non-portable functions for unix systems (Sun, Next, ....)
  1192.  */
  1193. #include <signal.h>
  1194. /*--------------------------------------------------------------------------*/
  1195.     void    initialize(void);
  1196.     char    csts(void);
  1197.     char    ci(void);
  1198.     void    shell(void);
  1199.     int    min(int,int);
  1200. /*--------------------------------------------------------------------------*/
  1201. extern struct ioctrl io;
  1202. /*--------------------------------------------------------------------------*/
  1203. void initialize()
  1204. {
  1205.  io.mprint = 0;
  1206. }
  1207. /*--------------------------------------------------------------------------*/
  1208. char csts()
  1209. {
  1210.  return '\0';
  1211. }
  1212. char ci()
  1213. {
  1214.  return '\0';
  1215. }
  1216. /*--------------------------------------------------------------------------*/
  1217. void shell()
  1218. {
  1219.  (void)system(getenv("SHELL"));
  1220. }
  1221. /*--------------------------------------------------------------------------*/
  1222. int min(a,b)
  1223. int a,b;
  1224. {
  1225.  return (a<b) ? a : b;
  1226. }
  1227. /*--------------------------------------------------------------------------*/
  1228. /*--------------------------------------------------------------------------*/
  1229. SHAR_EOF
  1230. fi # end of overwriting check
  1231. #    End of shell archive
  1232. exit 0
  1233.