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

  1. Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!haven.umd.edu!darwin.sura.net!ukma!cs.widener.edu!dsinc!ub!galileo.cc.rochester.edu!ee.rochester.edu!rbc!al
  2. From: al@rbc.uucp (Al Davis)
  3. Newsgroups: alt.sources
  4. Subject: ACS  circuit simulator  part 17/20
  5. Message-ID: <1993Jan27.041026.11957@rbc.uucp>
  6. Date: 27 Jan 93 04:10:26 GMT
  7. Sender: al@rbc.uucp (Al Davis)
  8. Organization: Huh?
  9. Lines: 2094
  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/plot.c
  17. #    src/plotbasi.c
  18. #    src/plotherc.c
  19. #    src/plotibm.c
  20. #    src/plotpost.c
  21. #    src/plotunix.c
  22. #    src/plotx.c
  23. #    src/plotz100.c
  24. #    src/polar.c
  25. #    src/probe.c
  26. #    src/probe2.c
  27. #    src/probe3.c
  28. #    src/qfree.c
  29. #    src/quit.c
  30. #    src/time_it.c
  31. #    src/title.c
  32. #    src/tr.c
  33. #    src/trim.c
  34. #    src/tr_adv.c
  35. #    src/tr_volts.c
  36. #    src/tr_z.c
  37. # This archive created: Tue Jan 26 22:51:07 1993
  38. export PATH; PATH=/bin:$PATH
  39. if test -f 'src/plot.c'
  40. then
  41.     echo shar: will not over-write existing file "'src/plot.c'"
  42. else
  43. cat << \SHAR_EOF > 'src/plot.c'
  44. /* plot  01/26/93
  45.  * Copyright 1983-1992   Albert Davis
  46.  * (this file is a mess.  it should be redone.)
  47.  */
  48. #include "ecah.h"
  49. #include "error.h"
  50. #include "io.h"
  51. #include "mode.h"
  52. #include "options.h"
  53. #include "pixelh.h"
  54. #include "probh.h"
  55. #include "declare.h"
  56. /*--------------------------------------------------------------------------*/
  57.     void    plottr(double);
  58.     void    plotdc(double);
  59.     void    plotac(double);
  60.     int    plopen(int,double,double,int);
  61.     void    plclose(void);
  62.     void    plclear(void);
  63.     void    pllocate(void);
  64. static    void    plborder(void);
  65. static    void    calibrate(char*,double,double);
  66. static    int    round(double);
  67. static    void    plhead(int);
  68. static    int    point(double,double,double,int,int,int);
  69. static    void    plotarg(double,double,double,double,double,double,
  70.              double,double,double,double,double,double);
  71. static    void    crtopen(int,int);
  72. static    void    ycal(double,double,double,double);
  73. static    void    xcal(void);
  74. /*--------------------------------------------------------------------------*/
  75. #define INDENT 8                                /* beware mprintf!  */
  76. #define CONSSCALE (opt.outwidth - INDENT - 2)     /*console scale size in chr*/
  77. #define RESRVLINES 4
  78. extern const struct options opt;
  79. extern struct ioctrl io;
  80. extern char e_int[];
  81. extern struct graph *initcrt();
  82. extern int crtplot;            /* flag: crt is in graphics mode        */
  83. static int reset;                   /* flag: new graph.  suppress 1st line  */
  84. static int active;                  /* flag: plotting has opened            */
  85. static int xmode;
  86. static double xstart, xstop;
  87. static int xlinswp;
  88. static char border[BUFLEN];         /* border string (keep, repeat at end)  */
  89. static char emptydata[BUFLEN];      /* empty data, to copy then insert data */
  90. extern probe_t *plotlist[];
  91. extern const int sim_mode;
  92. static char *device;
  93. static struct graph *c;
  94. /*--------------------------------------------------------------------------*/
  95. void plottr(xx)                     /* plot a data point,  transient        */
  96. double xx;
  97. {
  98.  if (active){
  99.     double yy, zz;
  100.     int ii;
  101.     double lo[2], hi[2];
  102.     probe_t prb;    /* to hide MSC BUG */
  103.     prb = plotlist[sim_mode][0];
  104.     yy = trprobe(prb);
  105.     prb = plotlist[sim_mode][1];
  106.     zz = trprobe(prb);
  107.     if (zz == NOT_VALID)
  108.        zz = yy;
  109.     for (ii = 0;  ii <= 1;  ii++){
  110.        if (plotlist[sim_mode][ii].lo != plotlist[sim_mode][ii].hi){
  111.       lo[ii] = plotlist[sim_mode][ii].lo;
  112.       hi[ii] = plotlist[sim_mode][ii].hi;
  113.        }else{
  114.       lo[ii] = -5.;
  115.       hi[ii] = 5.;
  116.        }
  117.     }
  118.     plotarg( xx, yy,     zz,
  119.      xstart, lo[0],  lo[1],
  120.      xstop,  hi[0],  hi[1],
  121.      0.,     0.,     0. );
  122.  }
  123. }
  124. /*--------------------------------------------------------------------------*/
  125. void plotdc(xx)                     /* plot a data point,  DC               */
  126. double xx;
  127. {
  128.  plottr(xx);
  129. }
  130. /*--------------------------------------------------------------------------*/
  131. void plotac(xx)                     /* plot a data point -- AC              */
  132. double xx;
  133. {
  134.  if (active){
  135.     double yy, zz;
  136.     int ii;
  137.     double lo[2], hi[2];
  138.     probe_t prb;    /* to hide MSC BUG */
  139.     prb = plotlist[sim_mode][0];
  140.     yy = acprobe(prb);
  141.     prb = plotlist[sim_mode][1];
  142.     zz = acprobe(prb);
  143.     if (zz == NOT_VALID)
  144.        zz = yy;
  145.     for (ii = 0;  ii <= 1;  ii++){
  146.        if (plotlist[sim_mode][ii].lo != plotlist[sim_mode][ii].hi){
  147.       lo[ii] = plotlist[sim_mode][ii].lo;
  148.       hi[ii] = plotlist[sim_mode][ii].hi;
  149.        }else{
  150.       lo[ii] = -5.;
  151.       hi[ii] = 5.;
  152.        }
  153.     }
  154.     plotarg( xx, yy,     zz,
  155.      xstart, lo[0],  lo[1],
  156.      xstop,  hi[0],  hi[1],
  157.      0.,     0.,     0. );
  158.  }
  159. }
  160. /*--------------------------------------------------------------------------*/
  161. /* plopen: begin the plot.  any type
  162.  */
  163. int plopen(mode,start,stop,linswp)             /* begin the plot (any type) */
  164. int mode;
  165. double start, stop;
  166. int linswp;
  167. {
  168.  int fullgrid;
  169.  if (start == stop)
  170.      io.ploton = NO;
  171.  if (!device){
  172.     device = (testcrt()) ? "CRt" : "Ascii" ;
  173.  }
  174.  if (!io.ploton){
  175.     plclear();
  176.     return NO;
  177.  }
  178.  fullgrid = !(crtplot && mode==xmode && start==xstart && stop==xstop);
  179.  xmode   = mode;
  180.  xstart  = start;
  181.  xstop   = stop;
  182.  xlinswp = linswp;
  183.  if (*device=='C')
  184.     crtopen(mode,fullgrid);
  185.  else if (*device=='A')
  186.     plhead(mode);
  187.  else
  188.     error(bWARNING, e_int, "plopen" );
  189.  active = YES;
  190.  return YES;
  191. }
  192. /*--------------------------------------------------------------------------*/
  193. /* plclose: finish up the plot (any type)
  194.  */
  195. void plclose()
  196. {
  197.  if (!active)
  198.     return;
  199.  if (*device=='C')
  200.     (*c->fin)();                    /* usually a stub, except for Hercules  */
  201.  else if (*device=='A')
  202.     plborder();
  203.  else
  204.     error(bWARNING, e_int, "plclose" );
  205.  active = NO;
  206.  io.ploton = NO;
  207. }
  208. /*--------------------------------------------------------------------------*/
  209. /* plclear: clear graphics mode
  210.  */
  211. void plclear()
  212. {
  213.  active = NO;
  214.  if (crtplot){
  215.     crtplot = NO;
  216.     (*c->can)();
  217.  }
  218. }
  219. /*--------------------------------------------------------------------------*/
  220. /* pllocate: locate the cursor at the bottom of the plot.
  221.  *         select the primary color  (CRT plot)
  222.  */
  223. void pllocate()
  224. {
  225.  if (crtplot)
  226.     stext( 0, c->wh+2*c->lpc, "", c->pri);
  227. }
  228. /*--------------------------------------------------------------------------*/
  229. /* plborder: draw the border -- Ascii graphics
  230.  */
  231. static void plborder()
  232. {
  233.  mtab(  INDENT, io.where );
  234.  mputs( border, io.where );
  235.  mputc( '\n',   io.where );
  236. }
  237. /*--------------------------------------------------------------------------*/
  238. /* calibrate: calibrate the y axis.  ascii plot.
  239.  */
  240. static void calibrate(note,lo,hi)           /* calibrate the y axis         */
  241. char *note;
  242. double lo,hi;
  243. {
  244.  static char nums[20];        /* this label string        */
  245.  static char highs[20];        /* the last label string    */
  246.  double number;            /* value of this label                      */
  247.  double range;            /* hi - lo                                  */
  248.  int cal;            /* char position within line                */
  249.  int stop;            /* location of last label, stop printing    */
  250.  int filled;            /* how far (characters) have been printed   */
  251.  int numsize;            /* number of characters in this label       */
  252.  int start;            /* starting position of this label          */
  253.  double markno;            /* loop counter                             */
  254.  
  255.  (void)strcpy(highs, ftos(hi, "", 5, io.formaat));
  256.  highs[8] = '\0';                      /* trim to 8 chrs */
  257.  /* *strchr(&highs[2],' ') = '\0'; */        /* make the top label, and save */
  258.  stop = opt.outwidth - strlen(highs);        /* space for it.                */
  259.  
  260.  mputs(note, io.where);
  261.  range = hi-lo;
  262.  filled = 0;
  263.  for (markno = 0.;  markno < opt.ydivisions;  markno++){
  264.     number = lo + range * markno/opt.ydivisions ;
  265.     if (fabs(number) < fabs(range)/(10.*CONSSCALE)){
  266.        number = 0.;
  267.     }                               /* label to put on this div. */
  268.     (void)strcpy(nums, ftos(number, "", 5, io.formaat));
  269.     nums[8] = '\0';                      /* trim to 8 chrs */
  270.     numsize = strlen(nums);             /* center it over the mark */
  271.     cal = round(INDENT + CONSSCALE * (markno/opt.ydivisions));
  272.     start = cal - (numsize+1)/2;
  273.     if (start > filled  &&  start+numsize < stop){
  274.        mtab( start, io.where );                /* if it fits, print it */
  275.        mputs( nums, io.where );
  276.        filled = start + numsize ;
  277.     }
  278.  }
  279.  mtab(  stop,   io.where );              /* print the last calibration */
  280.  mputs( highs,  io.where );
  281.  mputc( '\n',   io.where );
  282. }
  283. /*--------------------------------------------------------------------------*/
  284. static int round(x)
  285. double x;
  286. {
  287.  return (int)floor(x+.5);
  288. }
  289. /*--------------------------------------------------------------------------*/
  290. /* plhead: begin ascii graphics
  291.  * print opening border, calibrations, etc.
  292.  */ 
  293. static void plhead(mode)
  294. int mode;
  295. {
  296.  int ii;
  297.  double place;        /* where to put this calibration mark */
  298.  double incr;        /* exact increment in characters */
  299.  
  300.  for (ii = 0;  ii <= 1;  ii++){
  301.     double lo, hi;
  302.     probe_t prb;    /* to hide MSC BUG */
  303.     if (plotlist[sim_mode][ii].lo != plotlist[sim_mode][ii].hi){
  304.        lo = plotlist[sim_mode][ii].lo;
  305.        hi = plotlist[sim_mode][ii].hi;
  306.     }else{
  307.        lo = -5.;
  308.        hi = 5.;
  309.     }
  310.     prb = plotlist[sim_mode][ii];
  311.     calibrate(probename(prb), lo, hi);
  312.  }
  313.  incr = (double)CONSSCALE / opt.ydivisions;
  314.  (void)memset((void*)border,   '-',(int)CONSSCALE); /*build strings : border*/
  315.  (void)memset((void*)emptydata,' ',(int)CONSSCALE); /*     and emptydata    */
  316.  for (place = 0.;   place < (double)CONSSCALE;   place += incr){
  317.     border[round(place)] = '+';
  318.     emptydata[round(place)] = '.';        /* tics in emptydata */
  319.  }
  320.  border[CONSSCALE] = '+';            /* fix ends of the strings */
  321.  border[CONSSCALE+1] = '\0';
  322.  emptydata[CONSSCALE] = emptydata[0] = '|';
  323.  emptydata[CONSSCALE+1] = '\0';
  324.  
  325.  plborder();                    /* print the border */
  326. }
  327. /*--------------------------------------------------------------------------*/
  328. /* point: return coordinate to plot in pixel #
  329.  */
  330. static int point(yy,lo,hi,scale,offset,linswp)
  331. double yy;    /* raw data */
  332. double lo,hi;    /* limits: both ends of the plot */
  333. int scale;    /* length of scale in pixels */
  334. int offset;    /* pixel offset of start of plot area */
  335. int linswp;    /* flag: linear scale (else log scale) */
  336. {
  337.  int place;
  338.  
  339.  if (linswp)
  340.     place = round( scale*(yy-lo)/(hi-lo));
  341.  else
  342.     place = round( scale*(log(yy/lo))/(log(hi/lo)));
  343.     
  344.  if (place < 0)
  345.     place = 0;
  346.  if (place > scale)
  347.     place = scale;
  348.  return  place + offset;
  349. }
  350. /*--------------------------------------------------------------------------*/
  351. /* plotarg: plot all 2 selected probes at one time, freq, etc. point.
  352.  */
  353. /*ARGSUSED*/
  354. static void plotarg(xx,yy,zz,xlo,ylo,zlo,xhi,yhi,zhi,xf,yf,zf)
  355. double xx, yy, zz;  /* values */
  356. double xlo,ylo,zlo; /* lower limits */
  357. double xhi,yhi,zhi; /* upper limits */
  358. double xf, yf, zf;  /* fold modulus != 0 means to suppress line */
  359.             /*         when the change is too big    */
  360. {
  361.  if (*device=='A'){
  362.     auto char adata[BUFLEN];         /* actual data. copy emptydata, insert */
  363.     char *xxs;                     /* string representation of xx */
  364.     (void)memcpy((void*)adata,(void*)emptydata,BUFLEN);      /* copy prototype */
  365.     xxs = ftos( xx, "           ", 5, io.formaat );
  366.     adata[point(zz,zlo,zhi,CONSSCALE,0,1)] = '+';   /* zap data into string */
  367.     adata[point(yy,ylo,yhi,CONSSCALE,0,1)] = '*';
  368.     mprintf( io.where, "%-8.8s%s", xxs, adata );
  369.     mputc( '\n', io.where );
  370.  }else if (*device=='C'){
  371.     static int xold, yold, zold;
  372.     auto   int xpt,  ypt,  zpt;
  373.     auto   int       dy,   dz;
  374.     xpt = point( xx, xlo, xhi, c->ww, c->lm, xlinswp );
  375.     ypt = point( yy, yhi, ylo, c->wh, c->tm, YES     );
  376.     zpt = point( zz, zhi, zlo, c->wh, c->tm, YES     );
  377.     if (reset){
  378.        reset = NO;
  379.        xold = xpt;
  380.        yold = ypt;
  381.        zold = zpt;
  382.     }
  383.     dy = ypt - yold;
  384.     dz = zpt - zold;
  385.     if ( !zf || ((double)abs(dz) < (double)(c->wh)*.8) )
  386.        line( xold, zold, xpt, zpt, c->sec );
  387.     if ( !yf || ((double)abs(dy) < (double)(c->wh)*.8) )
  388.        line( xold, yold, xpt, ypt, c->pri );
  389.     xold = xpt;
  390.     yold = ypt;
  391.     zold = zpt;
  392.  }else{
  393.     error(bWARNING, e_int, "plotarg");
  394.  }
  395. }
  396. /*--------------------------------------------------------------------------*/
  397. /* crtopen: begin CRT graphics mode
  398.  * clear screen, draw box, calibrate, etc.
  399.  */
  400. static void crtopen(mode,fullgrid)
  401. int mode;
  402. int fullgrid;
  403. {
  404.  int ii;
  405.  double lo[2], hi[2];
  406.  reset = YES;
  407.  if (!fullgrid)
  408.     return;
  409.  crtplot = YES;
  410.  c = initcrt();
  411.  if (!c)
  412.     error(bERROR, e_int, "crtopen: device not installed");
  413.  initgraph(c);
  414.  c->lm =          INDENT     * c->ppc    ;
  415.  c->rm = c->sw - (INDENT     * c->ppc) -2;
  416.  c->tm =          0          * c->lpc    ;
  417.  c->bm = c->sh - (RESRVLINES * c->lpc) -2;
  418.  c->ww = c->rm - c->lm;
  419.  c->wh = c->bm - c->tm;
  420.  box( c->lm, c->tm, c->rm, c->bm, c->grid );
  421.  for (ii = 0;  ii <= 1;  ii++){
  422.     if (plotlist[sim_mode][ii].lo != plotlist[sim_mode][ii].hi){
  423.        lo[ii] = plotlist[sim_mode][ii].lo;
  424.        hi[ii] = plotlist[sim_mode][ii].hi;
  425.     }else{
  426.        lo[ii] = -5.;
  427.        hi[ii] = 5.;
  428.     }
  429.  }
  430.  ycal(lo[0],hi[0],lo[1],hi[1]);
  431.  xcal();
  432.  stext( 0, c->wh+2*c->lpc, "", c->pri);
  433. }
  434. /*--------------------------------------------------------------------------*/
  435. /* ycal: calibrate the Y axis on CRT display
  436.  */
  437. static void ycal(ylo,yhi,zlo,zhi)
  438. double ylo,yhi,zlo,zhi;
  439. {
  440.  double ynum, znum, yrange, zrange;
  441.  double ratio;
  442.  int cal;
  443.  double markno;
  444.  static char ystr[] = "           ";
  445.  static char zstr[] = "           ";
  446.  yrange = yhi-ylo;
  447.  zrange = zhi-zlo;
  448.  for (markno = 0.;  markno < opt.ydivisions;  markno++){
  449.     ratio = markno / opt.ydivisions;
  450.     ynum = ylo + yrange * ratio ;
  451.     znum = zlo + zrange * ratio ;
  452.     if (fabs(ynum) < fabs(yrange)/(10.*c->wh))
  453.        ynum = 0.;
  454.     if (fabs(znum) < fabs(zrange)/(10.*c->wh))
  455.        znum = 0.;
  456.     (void)strcpy(ystr, ftos(ynum,ystr,5,0));
  457.     (void)strcpy(zstr, ftos(znum,zstr,5,0));
  458.     ystr[8] = zstr[8] = '\0';                /* trim to 8 chrs */
  459.     cal = round(c->bm - c->wh * ratio);
  460.     if (cal != c->bm   &&   cal != c->tm)
  461.        line( c->lm, cal, c->rm, cal, c->grid );
  462.     if (cal < c->lpc)
  463.        cal = c->lpc-1;
  464.     stext( 0,              cal, ystr, c->pri);
  465.     stext( c->rm+1*c->ppc, cal, zstr, c->sec);
  466.     }
  467.  (void)strcpy(ystr, ftos(yhi,ystr,5,0));
  468.  (void)strcpy(zstr, ftos(zhi,zstr,5,0));
  469.  ystr[8] = zstr[8] = '\0';                /* trim to 8 chrs */
  470.  cal = (c->tm < c->lpc) ? c->lpc-1 : c->tm ;
  471.  stext(0,              cal, ystr, c->pri);
  472.  stext(c->rm+1*c->ppc, cal, zstr, c->sec);
  473. }
  474. /*--------------------------------------------------------------------------*/
  475. /* xcal: calibrate the X axis on CRT display
  476.  */
  477. static void xcal()
  478. {
  479.  double xcal, ratio;
  480.  int cal;
  481.  double markno;
  482.  static char str[] = "           ";
  483.  
  484.  for (markno = 0.;  markno <= opt.xdivisions;  markno++){
  485.     ratio = markno / opt.xdivisions;
  486.     xcal = (xlinswp)
  487.     ? xstart +      (xstop-xstart) * ratio
  488.     : xstart * pow( (xstop/xstart) , ratio );
  489.     cal = round(c->lm + c->ww * ratio);
  490.     if (cal != c->lm   &&   cal != c->rm)
  491.        line(cal, c->tm, cal, c->bm, c->grid);
  492.     (void)strcpy(str, ftos(xcal, str, 5, 0));
  493.     str[8] = '\0';
  494.     stext(cal-2*c->ppc, c->wh+c->lpc, str, c->pri);
  495.  }
  496. }
  497. /*--------------------------------------------------------------------------*/
  498. /*--------------------------------------------------------------------------*/
  499. SHAR_EOF
  500. fi # end of overwriting check
  501. if test -f 'src/plotbasi.c'
  502. then
  503.     echo shar: will not over-write existing file "'src/plotbasi.c'"
  504. else
  505. cat << \SHAR_EOF > 'src/plotbasi.c'
  506. /* plotbasic  04/02/92
  507.  * Copyright 1983-1992   Albert Davis
  508.  * vector graphics, for pen plotters, etc.
  509.  * indirect through basic draw strings.
  510.  */
  511. #include "ecah.h"
  512. #include "pixelh.h"
  513. #include "declare.h"
  514. /*--------------------------------------------------------------------------*/
  515.     struct graph    *initbasic(struct graph *);
  516. static    void        text(int,int,char*,int);
  517. static    void        drawline(int,int,int,int,int);
  518. static    void        finishp(void);
  519. static    void        cancel(void);
  520. /*--------------------------------------------------------------------------*/
  521. static FILE *device;
  522. static struct graph *d;
  523. /*--------------------------------------------------------------------------*/
  524. struct graph *initbasic(g)
  525. struct graph *g;
  526. {
  527. d = g;
  528. d->spx = (void(*)())NULL;
  529. d->lin = drawline;
  530. d->box = (void(*)())NULL;
  531. d->txt = text;
  532. d->can = cancel;
  533. d->fin = finishp;
  534. xclose( &device );
  535. device = fopen( PLOTFILE, "wt" ) ;
  536. return d;
  537. }
  538. /*--------------------------------------------------------------------------*/
  539. static void text(x,y,string,color)
  540. int x, y, color;
  541. char *string;
  542. {
  543. fprintf( device, "bm%d,%dc%d\"%s\"\n", x, y, color, string);
  544. }
  545. /*--------------------------------------------------------------------------*/
  546. static void drawline( x1, y1, x2, y2, color )
  547. int x1, y1, x2, y2, color;
  548. {
  549. fprintf( device, "BM%d,%dC%dM%d,%d\n", x1, y1, color, x2, y2 );
  550. }
  551. /*--------------------------------------------------------------------------*/
  552. static void finishp()
  553. {
  554. xclose( &device );
  555. if ( access("/dev/ecaplot", 00) == BAD)        /* no driver */    /* is exe   */
  556.     if ( findfile("ecaplot.com", getenv("PATH"), X_OK)
  557.       || findfile("ecaplot.exe", getenv("PATH"), X_OK)
  558.       || findfile("ecaplot.bat", getenv("PATH"), X_OK) )
  559.     system( "ecaplot" );
  560. }
  561. /*--------------------------------------------------------------------------*/
  562. static void cancel()
  563. {;}
  564. /*--------------------------------------------------------------------------*/
  565. /*--------------------------------------------------------------------------*/
  566. SHAR_EOF
  567. fi # end of overwriting check
  568. if test -f 'src/plotherc.c'
  569. then
  570.     echo shar: will not over-write existing file "'src/plotherc.c'"
  571. else
  572. cat << \SHAR_EOF > 'src/plotherc.c'
  573. /* Hercules video graphics primitives  04/02/92
  574.  * Copyright 1983-1992   Albert Davis
  575.  * 
  576.  */
  577. #include "ecah.h"
  578. #include "pixelh.h"
  579. #include <dos.h>
  580. /*--------------------------------------------------------------------------*/
  581. struct graph *initherc(struct graph *);
  582. static void text(int,int,char*,int);
  583. static void setpixel(int,int,int);
  584. static void finish(void);
  585. static void cancel(void);
  586. /*--------------------------------------------------------------------------*/
  587. extern void GMODE(void);
  588. extern void CLRSCR(void);
  589. extern void TEXTC(int,int,char*);
  590. extern void PLOT(int,int);
  591. extern void TMODE(void);
  592. static struct graph *d;
  593. /*--------------------------------------------------------------------------*/
  594. struct graph *initherc(g)
  595. struct graph *g;
  596. {
  597. d = g;
  598. d->spx = setpixel;
  599. d->lin = NULL;
  600. d->box = NULL;
  601. d->txt = text;
  602. d->can = cancel;
  603. d->fin = finish;
  604. GMODE();
  605. CLRSCR();
  606. return d;
  607. }
  608. /*--------------------------------------------------------------------------*/
  609. static void text(col,lin,string,color)
  610. int col, lin, color;
  611. char *string;
  612. {
  613. TEXTC(col,lin,string);
  614. }
  615. /*--------------------------------------------------------------------------*/
  616. static void setpixel(x,y,color)
  617. int x,y,color;
  618. {
  619. static int skip, oldcolor;
  620.  
  621. if (!(--skip) || (color!=oldcolor))
  622.     {
  623.     oldcolor = color;
  624.     skip = (color>=0) ? 1 : -color;
  625.     PLOT(x,y);
  626.     }
  627. }
  628. /*--------------------------------------------------------------------------*/
  629. static void finish()
  630. {
  631. auto int n;
  632. int ch;
  633.  
  634. ch = ci();
  635. plclear();
  636. if (ch=='C'-'@')
  637.     {
  638.     n = 0;
  639.     submit("",&n);
  640.     xerror("\r");
  641.     }
  642. }
  643. /*--------------------------------------------------------------------------*/
  644. static void cancel()
  645. {
  646. TMODE();
  647. }
  648. /*--------------------------------------------------------------------------*/
  649. /*--------------------------------------------------------------------------*/
  650. SHAR_EOF
  651. fi # end of overwriting check
  652. if test -f 'src/plotibm.c'
  653. then
  654.     echo shar: will not over-write existing file "'src/plotibm.c'"
  655. else
  656. cat << \SHAR_EOF > 'src/plotibm.c'
  657. /* IBM video graphics primitives  04/02/92
  658.  * Copyright 1983-1992   Albert Davis
  659.  */
  660. #include "pixelh.h"
  661. #include <stdio.h>
  662. #include <dos.h>
  663. /*--------------------------------------------------------------------------*/
  664. struct graph *initibm(struct graph*);
  665. static void text(int,int,char*,int);
  666. static void setpixel(int,int,int);
  667. static void finish(void);
  668. static void cancel(void);
  669. static void mode(int);
  670. static void scr_curs(int,int);
  671. static void scr_puts(char*,int);
  672. /*--------------------------------------------------------------------------*/
  673. #define VIDEO_INT   0x10
  674. static struct graph *d;
  675. /*--------------------------------------------------------------------------*/
  676. struct graph *initibm(g)
  677. struct graph *g;
  678. {
  679. d = g;
  680. d->spx = setpixel;
  681. d->lin = NULL;
  682. d->box = NULL;
  683. d->txt = text;
  684. d->can = cancel;
  685. d->fin = finish;
  686. mode(d->gmode);
  687. return d;
  688. }
  689. /*--------------------------------------------------------------------------*/
  690. static void text(col,lin,string,color)
  691. int col, lin, color;
  692. char *string;
  693. {
  694. col /= d->ppc;
  695. lin /= d->lpc;
  696. scr_curs(lin,col);
  697. scr_puts(string,color);
  698. }
  699. /*--------------------------------------------------------------------------*/
  700. static void setpixel(x,y,color)
  701. int x,y,color;
  702. {
  703. union REGS inregs;
  704. static int skip, oldcolor;
  705.  
  706. if (!(--skip) || (color!=oldcolor))
  707.     {
  708.     oldcolor = color;
  709.     skip = (color>=0) ? 1 : -color;
  710.  
  711.     inregs.h.ah = 12;    /* write dot */
  712.     inregs.h.al = (unsigned char)((color>=0) ? color : d->pri) ;
  713.     inregs.x.bx = 0;    /* page, palette??????? */
  714.     inregs.x.cx = x;
  715.     inregs.x.dx = y;
  716.     int86(VIDEO_INT, &inregs, &inregs); /*inregs changed */
  717.     }
  718. }
  719. /*--------------------------------------------------------------------------*/
  720.  
  721. static void finish()
  722. {;}
  723. /*--------------------------------------------------------------------------*/
  724. static void cancel()
  725. {
  726. if (d->gmode != d->tmode)
  727.     mode(d->tmode);
  728. }
  729. /*--------------------------------------------------------------------------*/
  730. static void mode(video_mode)
  731. int video_mode;
  732. {
  733. union REGS inregs;
  734.  
  735. inregs.h.al = (unsigned char)video_mode;
  736. inregs.h.ah = 0; /* set mode */
  737. int86(VIDEO_INT, &inregs, &inregs);
  738. }
  739. /*--------------------------------------------------------------------------*/
  740. static void scr_curs(lin,col)
  741. int lin, col;
  742. {
  743. union REGS inregs;
  744.  
  745. inregs.h.ah = 2; /* move cursor */
  746. inregs.h.dh = (unsigned char)lin;
  747. inregs.h.dl = (unsigned char)col;
  748. inregs.h.bh = 0; /* page */
  749. int86(VIDEO_INT, &inregs, &inregs);
  750. }
  751. /*--------------------------------------------------------------------------*/
  752. static void scr_puts(string,color)
  753. char *string;
  754. int color;
  755. {
  756. union REGS inregs, outregs;
  757.  
  758. inregs.h.ah = 14; /* write char, advance */
  759. inregs.h.bh = 0; /* page */
  760. inregs.h.bl = (unsigned char)((color>=0) ? color : d->pri) ;
  761. while (*string)
  762.     {
  763.     inregs.h.al = *string++;
  764.     int86(VIDEO_INT, &inregs, &outregs);
  765.     }
  766. }
  767. /*--------------------------------------------------------------------------*/
  768. /*--------------------------------------------------------------------------*/
  769. SHAR_EOF
  770. fi # end of overwriting check
  771. if test -f 'src/plotpost.c'
  772. then
  773.     echo shar: will not over-write existing file "'src/plotpost.c'"
  774. else
  775. cat << \SHAR_EOF > 'src/plotpost.c'
  776. /* plotpostscript  04/02/92
  777.  * Copyright 1983-1992   Albert Davis
  778.  * vector graphics, for pen plotters, etc.
  779.  * This is bogus.  Use it only as a frame.
  780.  */
  781. #include "ecah.h"
  782. #include "pixelh.h"
  783. #include "declare.h"
  784. /*--------------------------------------------------------------------------*/
  785.     struct graph    *initpostscript(struct graph *);
  786. static    void        text(int,int,char*,int);
  787. static    void        drawline(int,int,int,int,int);
  788. static    void        finishp(void);
  789. static    void        cancel(void);
  790. /*--------------------------------------------------------------------------*/
  791. static FILE *device;
  792. static struct graph *d;
  793. /*--------------------------------------------------------------------------*/
  794. struct graph *initpostscript(g)
  795. struct graph *g;
  796. {
  797. d = g;
  798. d->spx = (void(*)())NULL;
  799. d->lin = drawline;
  800. d->box = (void(*)())NULL;
  801. d->txt = text;
  802. d->can = cancel;
  803. d->fin = finishp;
  804. xclose( &device );
  805. device = fopen( PLOTFILE, "wt" ) ;
  806. return d;
  807. }
  808. /*--------------------------------------------------------------------------*/
  809. static void text(x,y,string,color)
  810. int x, y, color;
  811. char *string;
  812. {
  813. int red, green, blue;
  814. red   = (color & 0x03) << 2;
  815. green = ((color>>2) & 0x03) << 2;
  816. blue  = ((color>>4) & 0x03) << 2;
  817. fprintf( device, "C%c%c%cm%c%c%c%c\"%s\"", red, green, blue,
  818.     (x&0x7f), ((x>>8)&0x7f), (y&0x7f), ((y>>8)&0x7f), string );
  819. }
  820. /*--------------------------------------------------------------------------*/
  821. static void drawline( x1, y1, x2, y2, color )
  822. int x1, y1, x2, y2, color;
  823. {
  824. int red, green, blue;
  825. red   = (color & 0x03) << 2;
  826. green = ((color>>2) & 0x03) << 2;
  827. blue  = ((color>>4) & 0x03) << 2;
  828. fprintf( device, "C%c%c%cl%c%c%c%c%c%c%c%c", red, green, blue,
  829.     (x1&0x7f), ((x1>>8)&0x7f), (y1&0x7f), ((y1>>8)&0x7f),
  830.     (x2&0x7f), ((x2>>8)&0x7f), (y2&0x7f), ((y2>>8)&0x7f) );
  831.  
  832. }
  833. /*--------------------------------------------------------------------------*/
  834. static void finishp()
  835. {
  836. xclose( &device );
  837. if ( access("/dev/ecaplot", 00) == BAD)        /* no driver */    /* is exe   */
  838.     if ( findfile("ecaplot.com", getenv("PATH"), X_OK)
  839.       || findfile("ecaplot.exe", getenv("PATH"), X_OK)
  840.       || findfile("ecaplot.bat", getenv("PATH"), X_OK) )
  841.     system( "ecaplot" );
  842. }
  843. /*--------------------------------------------------------------------------*/
  844. static void cancel()
  845. {;}
  846. /*--------------------------------------------------------------------------*/
  847. /*--------------------------------------------------------------------------*/
  848. SHAR_EOF
  849. fi # end of overwriting check
  850. if test -f 'src/plotunix.c'
  851. then
  852.     echo shar: will not over-write existing file "'src/plotunix.c'"
  853. else
  854. cat << \SHAR_EOF > 'src/plotunix.c'
  855. /* plotunix  04/02/92
  856.  * Copyright 1983-1992   Albert Davis
  857.  * vector graphics, for pen plotters, etc.
  858.  * indirect through unix plot filters
  859.  * This is bogus.  It might work with minor changes.
  860.  */
  861. #include "ecah.h"
  862. #include "pixelh.h"
  863. #include "declare.h"
  864. /*--------------------------------------------------------------------------*/
  865.     struct graph    *initunix(struct graph *);
  866. static    void        text(int,int,char*,int);
  867. static    void        drawline(int,int,int,int,int);
  868. static    void        finishp(void);
  869. static    void        cancel(void);
  870. /*--------------------------------------------------------------------------*/
  871. static FILE *device;
  872. static struct graph *d;
  873. /*--------------------------------------------------------------------------*/
  874. struct graph *initunix(g)
  875. struct graph *g;
  876. {
  877. d = g;
  878. d->spx = (void(*)())NULL;
  879. d->lin = drawline;
  880. d->box = (void(*)())NULL;
  881. d->txt = text;
  882. d->can = cancel;
  883. d->fin = finishp;
  884. xclose( &device );
  885. device = fopen( PLOTFILE, "wt" ) ;
  886. return d;
  887. }
  888. /*--------------------------------------------------------------------------*/
  889. static void text(x,y,string,color)
  890. int x, y, color;
  891. char *string;
  892. {
  893. int red, green, blue;
  894. red   = (color & 0x03) << 2;
  895. green = ((color>>2) & 0x03) << 2;
  896. blue  = ((color>>4) & 0x03) << 2;
  897. fprintf( device, "C%c%c%cm%c%c%c%c\"%s\"", red, green, blue,
  898.     (x&0x7f), ((x>>8)&0x7f), (y&0x7f), ((y>>8)&0x7f), string );
  899. }
  900. /*--------------------------------------------------------------------------*/
  901. static void drawline( x1, y1, x2, y2, color )
  902. int x1, y1, x2, y2, color;
  903. {
  904. int red, green, blue;
  905. red   = (color & 0x03) << 2;
  906. green = ((color>>2) & 0x03) << 2;
  907. blue  = ((color>>4) & 0x03) << 2;
  908. fprintf( device, "C%c%c%cl%c%c%c%c%c%c%c%c", red, green, blue,
  909.     (x1&0x7f), ((x1>>8)&0x7f), (y1&0x7f), ((y1>>8)&0x7f),
  910.     (x2&0x7f), ((x2>>8)&0x7f), (y2&0x7f), ((y2>>8)&0x7f) );
  911.  
  912. }
  913. /*--------------------------------------------------------------------------*/
  914. static void finishp()
  915. {
  916. xclose( &device );
  917. if ( access("/dev/ecaplot", 00) == BAD)        /* no driver */    /* is exe   */
  918.     if ( findfile("ecaplot.com", getenv("PATH"), X_OK)
  919.       || findfile("ecaplot.exe", getenv("PATH"), X_OK)
  920.       || findfile("ecaplot.bat", getenv("PATH"), X_OK) )
  921.     system( "ecaplot" );
  922. }
  923. /*--------------------------------------------------------------------------*/
  924. static void cancel()
  925. {;}
  926. /*--------------------------------------------------------------------------*/
  927. /*--------------------------------------------------------------------------*/
  928. SHAR_EOF
  929. fi # end of overwriting check
  930. if test -f 'src/plotx.c'
  931. then
  932.     echo shar: will not over-write existing file "'src/plotx.c'"
  933. else
  934. cat << \SHAR_EOF > 'src/plotx.c'
  935. /* plotx  04/02/92
  936.  * Copyright 1983-1992   Albert Davis
  937.  * vector graphics, for pen plotters, etc.
  938.  * indirect through x plot filters
  939.  * This is bogus.  Use it only as a frame.
  940.  */
  941. #include "ecah.h"
  942. #include "pixelh.h"
  943. #include "declare.h"
  944. /*--------------------------------------------------------------------------*/
  945.     struct graph    *initx(struct graph *);
  946. static    void        text(int,int,char*,int);
  947. static    void        drawline(int,int,int,int,int);
  948. static    void        finishp(void);
  949. static    void        cancel(void);
  950. /*--------------------------------------------------------------------------*/
  951. static FILE *device;
  952. static struct graph *d;
  953. /*--------------------------------------------------------------------------*/
  954. struct graph *initx(g)
  955. struct graph *g;
  956. {
  957. d = g;
  958. d->spx = (void(*)())NULL;
  959. d->lin = drawline;
  960. d->box = (void(*)())NULL;
  961. d->txt = text;
  962. d->can = cancel;
  963. d->fin = finishp;
  964. xclose( &device );
  965. device = fopen( PLOTFILE, "wt" ) ;
  966. return d;
  967. }
  968. /*--------------------------------------------------------------------------*/
  969. static void text(x,y,string,color)
  970. int x, y, color;
  971. char *string;
  972. {
  973. int red, green, blue;
  974. red   = (color & 0x03) << 2;
  975. green = ((color>>2) & 0x03) << 2;
  976. blue  = ((color>>4) & 0x03) << 2;
  977. fprintf( device, "C%c%c%cm%c%c%c%c\"%s\"", red, green, blue,
  978.     (x&0x7f), ((x>>8)&0x7f), (y&0x7f), ((y>>8)&0x7f), string );
  979. }
  980. /*--------------------------------------------------------------------------*/
  981. static void drawline( x1, y1, x2, y2, color )
  982. int x1, y1, x2, y2, color;
  983. {
  984. int red, green, blue;
  985. red   = (color & 0x03) << 2;
  986. green = ((color>>2) & 0x03) << 2;
  987. blue  = ((color>>4) & 0x03) << 2;
  988. fprintf( device, "C%c%c%cl%c%c%c%c%c%c%c%c", red, green, blue,
  989.     (x1&0x7f), ((x1>>8)&0x7f), (y1&0x7f), ((y1>>8)&0x7f),
  990.     (x2&0x7f), ((x2>>8)&0x7f), (y2&0x7f), ((y2>>8)&0x7f) );
  991.  
  992. }
  993. /*--------------------------------------------------------------------------*/
  994. static void finishp()
  995. {
  996. xclose( &device );
  997. if ( access("/dev/ecaplot", 00) == BAD)        /* no driver */    /* is exe   */
  998.     if ( findfile("ecaplot.com", getenv("PATH"), X_OK)
  999.       || findfile("ecaplot.exe", getenv("PATH"), X_OK)
  1000.       || findfile("ecaplot.bat", getenv("PATH"), X_OK) )
  1001.     system( "ecaplot" );
  1002. }
  1003. /*--------------------------------------------------------------------------*/
  1004. static void cancel()
  1005. {;}
  1006. /*--------------------------------------------------------------------------*/
  1007. /*--------------------------------------------------------------------------*/
  1008. SHAR_EOF
  1009. fi # end of overwriting check
  1010. if test -f 'src/plotz100.c'
  1011. then
  1012.     echo shar: will not over-write existing file "'src/plotz100.c'"
  1013. else
  1014. cat << \SHAR_EOF > 'src/plotz100.c'
  1015. /* Z-100 video graphics primitives  04/02/92
  1016.  * Copyright 1983-1992   Albert Davis
  1017.  * low resolution color
  1018.  * interlace off, 640 pixels per scan line
  1019.  */
  1020. #include "ecah.h"
  1021. #include "pixelh.h"
  1022. /*--------------------------------------------------------------------------*/
  1023.     struct graph    *initz100(struct graph *);
  1024. static    void        text(int,int,char*,int);
  1025. static    int        readpixl(int,int);
  1026. static    void        setpixel(int,int,int);
  1027. static    void        pokebit(int,unsigned int,unsigned int,char);
  1028. static    void        putstr(char*);
  1029. static    void        finish(void);
  1030. static    void        cancel(void);
  1031. /*--------------------------------------------------------------------------*/
  1032. #define        BLUMEM  (unsigned)0xc000
  1033. #define        REDMEM  (unsigned)0xd000
  1034. #define        GRNMEM  (unsigned)0xe000
  1035. #define        XCOFF   32
  1036. #define        YCOFF   32
  1037. #define        BLUE    1
  1038. #define        RED        2
  1039. #define        GREEN   4
  1040. /*--------------------------------------------------------------------------*/
  1041. #define        vidbit(z)    (0x80>>(z%8))
  1042. #define        vidmem(x,y) (((y/9)<<11) + ((y%9)<<7) + (x/8))
  1043. /*--------------------------------------------------------------------------*/
  1044. static struct graph *d;
  1045. /*--------------------------------------------------------------------------*/
  1046. struct graph *initz100(g)
  1047. struct graph *g;
  1048. {
  1049. d = g;
  1050. d->spx = setpixel;
  1051. d->lin = NULL;
  1052. d->box = NULL;
  1053. d->txt = text;
  1054. d->can = cancel;
  1055. d->fin = finish;
  1056. putstr("\33E");
  1057. outp(0xd8,0x78); /* port, value */
  1058. return d;
  1059. }
  1060. /*--------------------------------------------------------------------------*/
  1061. static void text(col,lin,string,color)
  1062. int col, lin, color;
  1063. char *string;
  1064. {
  1065. static char pos[5] = { 27, 'Y', ' ', ' ', 0 };
  1066. static char clr[5] = { 27, 'm', ' ', ' ', 0 };
  1067.  
  1068. col /= d->ppc;
  1069. lin /= d->lpc;
  1070. pos[3] = (char)(col + XCOFF);
  1071. pos[2] = (char)(lin + YCOFF);
  1072. clr[2] = (char)(color + '0');
  1073. clr[3] = (char)(d->back + '0');
  1074. putstr(clr);
  1075. putstr(pos);
  1076. putstr(string);
  1077. }
  1078. /*--------------------------------------------------------------------------*/
  1079. static int readpixl(x,y)
  1080. int x,y;
  1081. {
  1082. unsigned int place, bitmask;
  1083. int blue, red, green;
  1084. place = vidmem(x,y);
  1085. bitmask = vidbit(x);
  1086. blue  = !!( peekb(BLUMEM,place) & bitmask );
  1087. red   = !!( peekb(REDMEM,place) & bitmask );
  1088. green = !!( peekb(GRNMEM,place) & bitmask );
  1089. return ( blue + (red<<1) + (green<<2) );
  1090. }
  1091. /*--------------------------------------------------------------------------*/
  1092. static void setpixel(x,y,color)
  1093. int x,y,color;
  1094. {
  1095. register int  place;
  1096. register char bitmask;
  1097. static     int  skip, oldcolor;
  1098.  
  1099. if (!(--skip) || (color!=oldcolor))
  1100.     {
  1101.     oldcolor = color;
  1102.     if (color>=0)
  1103.     skip = 1;
  1104.     else
  1105.     {
  1106.     skip = -color;
  1107.     color = d->pri;
  1108.     }
  1109.     place = vidmem(x,y);
  1110.     bitmask = (char)vidbit(x);
  1111.     pokebit (color&BLUE,  BLUMEM, place, bitmask);
  1112.     pokebit (color&RED,      REDMEM, place, bitmask);
  1113.     pokebit (color&GREEN, GRNMEM, place, bitmask);
  1114.     }
  1115. }
  1116. /*--------------------------------------------------------------------------*/
  1117. static void pokebit (test, para, offset, bitmask)
  1118. unsigned int para, offset;
  1119. int  test;
  1120. char bitmask;
  1121. {
  1122. char ch;
  1123. if (test)
  1124.     ch = peekb(para,offset) |  bitmask;
  1125. else
  1126.     ch = peekb(para,offset) & ~bitmask;
  1127. pokeb(para,offset,ch);
  1128. }
  1129. /*--------------------------------------------------------------------------*/
  1130. static void putstr(str)
  1131. char *str;
  1132. {
  1133. while ( *str )
  1134.     putchar(*str++);
  1135. }
  1136. /*--------------------------------------------------------------------------*/
  1137. static void finish()
  1138. {
  1139. putstr("\r");
  1140. }
  1141. /*--------------------------------------------------------------------------*/
  1142. static void cancel()
  1143. {;}
  1144. /*--------------------------------------------------------------------------*/
  1145. /*--------------------------------------------------------------------------*/
  1146. SHAR_EOF
  1147. fi # end of overwriting check
  1148. if test -f 'src/polar.c'
  1149. then
  1150.     echo shar: will not over-write existing file "'src/polar.c'"
  1151. else
  1152. cat << \SHAR_EOF > 'src/polar.c'
  1153. /* polar  03/23/92
  1154.  * Copyright 1983-1992   Albert Davis
  1155.  * Functions for use in converting to and from polar coordinates, etc.
  1156.  */
  1157. #include "ecah.h"
  1158. #include "options.h"
  1159. #include "declare.h"
  1160. /*LINTLIBRARY*/
  1161. /*--------------------------------------------------------------------------*/
  1162.     complex_t polartocomplex(polar_t);
  1163.     polar_t      complextopolar(complex_t);
  1164.     double      real(double,double);
  1165.     double      imag(double,double);
  1166.     double      phase(double,double);
  1167.     double      db(double);
  1168. /*--------------------------------------------------------------------------*/
  1169. extern const struct options opt;
  1170. /*--------------------------------------------------------------------------*/
  1171. complex_t polartocomplex(p)
  1172. polar_t p;
  1173. {
  1174.  complex_t c;
  1175.  c.x = p.mag * cos(p.phz*DTOR);
  1176.  c.y = p.mag * sin(p.phz*DTOR);
  1177.  return c;
  1178. }
  1179. /*--------------------------------------------------------------------------*/
  1180. polar_t complextopolar(c)
  1181. complex_t c;
  1182. {
  1183.  polar_t p;
  1184.  p.mag = cabs(c);
  1185.  p.phz = RTOD * atan2(c.y,c.x);
  1186.  return p;
  1187. }
  1188. /*--------------------------------------------------------------------------*/
  1189. double real(mag,phase)
  1190. double mag, phase;
  1191. {
  1192.  return ( mag * cos(phase*DTOR) );
  1193. }
  1194. /*--------------------------------------------------------------------------*/
  1195. double imag(mag,phase)
  1196. double mag, phase;
  1197. {
  1198.  return ( mag * sin(phase*DTOR) );
  1199. }
  1200. /*--------------------------------------------------------------------------*/
  1201. double phase(real,imag)
  1202. double real,imag;
  1203. {
  1204.  return ( RTOD * atan2(imag,real) );
  1205. }
  1206. /*--------------------------------------------------------------------------*/
  1207. double db(value)
  1208. double value;
  1209. {
  1210.  return ( value<1.001e-50 || value<opt.floor ) ? -999.999 : (20*log10(value));
  1211. }
  1212. /*--------------------------------------------------------------------------*/
  1213. /*--------------------------------------------------------------------------*/
  1214. SHAR_EOF
  1215. fi # end of overwriting check
  1216. if test -f 'src/probe.c'
  1217. then
  1218.     echo shar: will not over-write existing file "'src/probe.c'"
  1219. else
  1220. cat << \SHAR_EOF > 'src/probe.c'
  1221. /* probe  01/06/93
  1222.  * Copyright 1983-1992   Albert Davis
  1223.  * select which point in circuit to look at.
  1224.  * command line operations
  1225.  */
  1226. #include "ecah.h"
  1227. #include "argparse.h"
  1228. #include "branch.h"
  1229. #include "error.h"
  1230. #include "io.h"
  1231. #include "mode.h"
  1232. #include "probh.h"
  1233. #include "status.h"
  1234. #include "declare.h"
  1235. /*--------------------------------------------------------------------------*/
  1236.     void    cmd_plot(const char*,int*);
  1237.     void    cmd_print(const char*,int*);
  1238. static    void    do_probe(const char*,int*,probe_t*[]);
  1239. static    void    alloc_probe_list(probe_t**);
  1240. static    void    add_probes(const char*,int*,probe_t*);
  1241. static    int     add_all_nodes(int,probe_t*,probe_t*);
  1242. static    int     add_branches(const char*,int*,int,probe_t*,probe_t*);
  1243. static    int     add_node_list(const char*,int*,int,probe_t*,probe_t*);
  1244. static    void    clear_probes(probe_t*);
  1245. static    void    list_probes(probe_t*,const char*);
  1246. /*--------------------------------------------------------------------------*/
  1247. extern const struct ioctrl io;
  1248. extern const struct status stats;
  1249.  
  1250. extern probe_t *plotlist[];
  1251. extern probe_t *probelist[];
  1252. extern char e_om[], e_int[];
  1253. /*--------------------------------------------------------------------------*/
  1254. void cmd_plot(cmd,cnt)
  1255. const char *cmd;
  1256. int  *cnt;
  1257. {
  1258.  do_probe(cmd,cnt,plotlist);
  1259. }
  1260. /*--------------------------------------------------------------------------*/
  1261. void cmd_print(cmd,cnt)
  1262. const char *cmd;
  1263. int  *cnt;
  1264. {
  1265.  do_probe(cmd,cnt,probelist);
  1266. }
  1267. /*--------------------------------------------------------------------------*/
  1268. static void do_probe(cmd,cnt,probes)
  1269. const char *cmd;
  1270. int  *cnt;
  1271. probe_t *probes[];
  1272. {
  1273.  int simtype = sNONE;
  1274.  
  1275.  allocate(sSTATUS);
  1276.  
  1277.  (void)argparse(cmd,cnt,ONEPASS,
  1278.     "TRan",       aENUM,   &simtype,    sTRAN,
  1279.     "AC",       aENUM,   &simtype,    sAC,
  1280.     "DC",       aENUM,   &simtype,    sDC,
  1281.     "OP",       aENUM,   &simtype,    sOP,
  1282.     "FOurier", aENUM,   &simtype,    sFOURIER,
  1283.     "");
  1284.  if (!simtype){
  1285.     if (!cmd[*cnt]){
  1286.        list_probes(probes[sTRAN]   ,"tran");
  1287.        list_probes(probes[sAC]     ,"ac");
  1288.        list_probes(probes[sDC]     ,"dc");
  1289.        list_probes(probes[sOP]     ,"op");
  1290.        list_probes(probes[sFOURIER],"fourier");
  1291.     }else if (pmatch(cmd,cnt,"CLEAR")){
  1292.        int ii;
  1293.        for (ii = sSTART;  ii < sCOUNT;  ++ii)
  1294.       clear_probes(probes[ii]);
  1295.     }else{
  1296.        syntax(cmd,cnt,bERROR);
  1297.     }
  1298.  }else{
  1299.     if (!cmd[*cnt]){
  1300.        list_probes(probes[simtype],"");
  1301.     }else if (pmatch(cmd,cnt,"CLEAR")){
  1302.        clear_probes(probes[simtype]);
  1303.     }else{
  1304.        alloc_probe_list(&(probes[simtype]));
  1305.        add_probes(cmd,cnt,probes[simtype]);
  1306.     }
  1307.  }
  1308. }
  1309. /*--------------------------------------------------------------------------*/
  1310. static void alloc_probe_list(probes)
  1311. probe_t **probes;
  1312. {
  1313.  if (!*probes)
  1314.     *probes=(probe_t*)calloc(PROBECOUNT,sizeof(probe_t));
  1315.  if (!*probes)
  1316.     error(bERROR, e_om, "alloc_probe_list");
  1317. }
  1318. /*--------------------------------------------------------------------------*/
  1319. static void add_probes(cmd,cnt,probes)
  1320. const char *cmd;
  1321. int  *cnt;
  1322. probe_t *probes;
  1323. {                        /* BUG: ctostr may not advance */
  1324.  int probecount = 0;            /* if its 1st char is a term */
  1325.  while (cmd[*cnt]){            /* can cause loss of rest or str */
  1326.     probe_t prb;
  1327.     int oldcount = probecount;
  1328.     int paren = 0;
  1329.     prb.lo = prb.hi = 0.;
  1330.     (void)ctostr(cmd,cnt,prb.what,LABELEN);
  1331.     if (!*(prb.what))
  1332.        syntax(cmd,cnt,bWARNING);
  1333.     paren += skiplparen(cmd,cnt);
  1334.     if (pmatch(cmd,cnt,"NODES")){        /* all nodes */
  1335.        probecount = add_all_nodes(probecount,probes,&prb);
  1336.     }else if (isdigit(cmd[*cnt])){        /* listed nodes (numbered) */
  1337.        probecount = add_node_list(cmd,cnt,probecount,probes,&prb);
  1338.     }else{                    /* branches */
  1339.        probecount = add_branches(cmd,cnt,probecount,probes,&prb);
  1340.     }
  1341.     paren -= skiprparen(cmd,cnt);
  1342.     if (paren != 0)
  1343.        syntax(cmd,cnt,bWARNING);
  1344.     if (skiplparen(cmd,cnt)){
  1345.        double lo, hi;
  1346.        lo = ctof(cmd,cnt);
  1347.        hi = ctof(cmd,cnt);
  1348.        while (oldcount < probecount){
  1349.           probes[oldcount].lo = lo;
  1350.       probes[oldcount].hi = hi;
  1351.       ++oldcount;
  1352.        }
  1353.        if (!skiprparen(cmd,cnt))
  1354.           syntax(cmd,cnt,bWARNING);
  1355.     }
  1356.     if (probecount > PROBECOUNT)
  1357.        error(bERROR, e_int, "too many probes (missed trap)");
  1358.  }
  1359.  *probes[probecount].what = '\0';
  1360. }
  1361. /*--------------------------------------------------------------------------*/
  1362. static int add_all_nodes(probecount,probes,prb)
  1363. int probecount;
  1364. probe_t *probes;
  1365. probe_t *prb;
  1366. {
  1367.  for (prb->p.node = 1;
  1368.       prb->p.node <= stats.user_nodes  &&  prb->p.node < PROBECOUNT;
  1369.       prb->p.node++){
  1370.     probes[probecount++] = *prb;
  1371.     if (probecount > PROBECOUNT-1)
  1372.        error(bERROR, e_int, "too many probes");
  1373.  }
  1374.  return probecount;
  1375. }
  1376. /*--------------------------------------------------------------------------*/
  1377. static int add_branches(cmd,cnt,probecount,probes,prb)
  1378. const char *cmd;
  1379. int  *cnt;
  1380. int  probecount;
  1381. probe_t *probes;
  1382. probe_t *prb;
  1383. {    
  1384.  int savecnt;
  1385.  const branch_t *stop;
  1386.  savecnt = *cnt;
  1387.  stop = prb->p.brh = firstbranch_dev();
  1388.  if (exists(stop)){
  1389.     int savecnt;
  1390.     int newcnt;
  1391.     newcnt = savecnt = *cnt;
  1392.     do {                /* look for all matching branches */
  1393.        *cnt = savecnt;
  1394.        prb->p.brh = findbranch(cmd, cnt, prb->p.brh, lastbranch_dev());
  1395.        if (exists(prb->p.brh)){
  1396.       probes[probecount++] = *prb;
  1397.       if (probecount > PROBECOUNT-1)
  1398.          error(bERROR, e_int, "too many probes");
  1399.       newcnt = *cnt;
  1400.       while (exists(prb->p.brh->parent)){    /* don't get lost */
  1401.          prb->p.brh = prb->p.brh->parent;    /* in a subckt */
  1402.       }
  1403.        }else{
  1404.       *cnt = newcnt;
  1405.       break; /* didn't find, this time */
  1406.        }
  1407.     } while (prb->p.brh = nextbranch_dev(prb->p.brh),  prb->p.brh != stop);
  1408.  }
  1409.  if (savecnt == *cnt){            /* didn't find matching branch */
  1410.     syntax(cmd,&savecnt,bWARNING);
  1411.     skiparg(cmd,cnt);
  1412.  }
  1413.  return probecount;
  1414. }
  1415. /*--------------------------------------------------------------------------*/
  1416. static int add_node_list(cmd,cnt,probecount,probes,prb)
  1417. const char *cmd;
  1418. int *cnt;
  1419. int probecount;
  1420. probe_t *probes;
  1421. probe_t *prb;
  1422. {    
  1423.  while (isdigit(cmd[*cnt])){
  1424.     int savecnt;
  1425.     savecnt = *cnt;
  1426.     prb->p.node = ctoi(cmd,cnt);
  1427.     if (prb->p.node <= stats.total_nodes){
  1428.        probes[probecount++] = *prb;
  1429.        if (probecount > PROBECOUNT-1)
  1430.       error(bERROR, e_int, "too many probes");
  1431.     }else{
  1432.        syntax(cmd,&savecnt,bWARNING);
  1433.     }
  1434.  }
  1435.  return probecount;
  1436. }
  1437. /*--------------------------------------------------------------------------*/
  1438. static void clear_probes(probes)
  1439. probe_t *probes;
  1440. {
  1441.  if (probes)
  1442.     *probes[0].what = '\0';
  1443. }
  1444. /*--------------------------------------------------------------------------*/
  1445. static void list_probes(probes,label)
  1446. probe_t *probes;
  1447. const char *label;
  1448. {
  1449.  mprintf(io.mstdout, "%-7s", label);
  1450.  if (probes){
  1451.     int ii;
  1452.     for (ii = 0;  *probes[ii].what;  ii++){
  1453.        mprintf(io.mstdout, " %s", probename(probes[ii]));
  1454.        if (probes[ii].lo != probes[ii].hi){
  1455.           mprintf(io.mstdout, "(%s,%s)",
  1456.                ftos(probes[ii].lo,"",5,io.formaat),
  1457.              ftos(probes[ii].hi,"",5,io.formaat));
  1458.        }
  1459.     }
  1460.  }
  1461.  mprintf(io.mstdout, "\n");
  1462. }
  1463. /*--------------------------------------------------------------------------*/
  1464. /*--------------------------------------------------------------------------*/
  1465. SHAR_EOF
  1466. fi # end of overwriting check
  1467. if test -f 'src/probe2.c'
  1468. then
  1469.     echo shar: will not over-write existing file "'src/probe2.c'"
  1470. else
  1471. cat << \SHAR_EOF > 'src/probe2.c'
  1472. /* probe2  01/03/93
  1473.  * Copyright 1983-1992   Albert Davis
  1474.  * probe utilities - not related to the official list, but the strange ones
  1475.  * like worstcase and plotting
  1476.  */
  1477. #include "ecah.h"
  1478. #include "argparse.h"
  1479. #include "branch.h"
  1480. #include "error.h"
  1481. #include "probh.h"
  1482. #include "status.h"
  1483. #include "declare.h"
  1484. /*--------------------------------------------------------------------------*/
  1485.     probe_t    pr1set(const char*,int*);
  1486.     char    *probename(probe_t);
  1487. /*--------------------------------------------------------------------------*/
  1488. extern const struct status stats;
  1489. /*--------------------------------------------------------------------------*/
  1490. /* pr1set: (set one probe)
  1491.  * Scan a command string.
  1492.  * Return a probe structure corresponding to the argument (eat it)
  1493.  * It does not actually set a probe point.
  1494.  * If the element or node does not exist, both what are brh are nulled.
  1495.  * There is no check for validity of the parameter name.
  1496.  */
  1497. probe_t pr1set(cmd,cnt)
  1498. const char *cmd;
  1499. int  *cnt;
  1500. {
  1501.  probe_t prb;
  1502.  
  1503.  if (isalpha(cmd[*cnt])){
  1504.     (void)ctostr(cmd,cnt,prb.what,LABELEN);
  1505.  }else if (isdigit(cmd[*cnt])){
  1506.     (void)strcpy(prb.what, "V");
  1507.  }else{
  1508.     *prb.what = '\0';
  1509.     prb.p.node = 0;
  1510.     syntax(cmd,cnt,bWARNING);
  1511.  }
  1512.  
  1513.  if (isdigit(cmd[*cnt])){
  1514.     prb.p.node = ctoi(cmd,cnt);
  1515.     if (prb.p.node > stats.total_nodes){
  1516.        *prb.what = '\0';
  1517.        prb.p.node = 0;
  1518.        syntax(cmd,cnt,bWARNING);
  1519.     }
  1520.  }else{
  1521.     prb.p.brh = findbranch(cmd,cnt,firstbranch_dev(),lastbranch_dev());
  1522.     if (!exists(prb.p.brh)){
  1523.        *prb.what = '\0';
  1524.        prb.p.brh = (branch_t*)NULL;
  1525.        syntax(cmd,cnt,bWARNING);
  1526.     }
  1527.  }
  1528.  return prb;
  1529. }
  1530. /*--------------------------------------------------------------------------*/
  1531. /* probename: returns a string corresponding to a possible probe point
  1532.  * (suitable for printing)
  1533.  * It has nothing to do with whether it was selected or not
  1534.  * the return string is static, and overwritten on every call.
  1535.  */
  1536. char *probename(prb)
  1537. probe_t prb;
  1538. {
  1539.  static char string[BUFLEN+8];
  1540.     
  1541.  if (*prb.what){
  1542.     if (prb.p.node <= stats.total_nodes){
  1543.        sprintf(string, "%s(%u)", prb.what, prb.p.node);
  1544.     }else{
  1545.        sprintf(string, "%s(%s)", prb.what, printlabel(prb.p.brh,NO));
  1546.     }
  1547.  }else{
  1548.     sprintf(string,"undefined");
  1549.  }
  1550.  strcpy(&(string[BUFLEN-3]), "++");
  1551.  return string;
  1552. }
  1553. /*--------------------------------------------------------------------------*/
  1554. /*--------------------------------------------------------------------------*/
  1555. SHAR_EOF
  1556. fi # end of overwriting check
  1557. if test -f 'src/probe3.c'
  1558. then
  1559.     echo shar: will not over-write existing file "'src/probe3.c'"
  1560. else
  1561. cat << \SHAR_EOF > 'src/probe3.c'
  1562. /* probe3  01/03/93
  1563.  * Copyright 1983-1992   Albert Davis
  1564.  * probe utilities, related to the signal and bias probe lists
  1565.  */
  1566. #include "ecah.h"
  1567. #include "probh.h"
  1568. #include "declare.h"
  1569. /*--------------------------------------------------------------------------*/
  1570.     int    probcount(int);
  1571. /*--------------------------------------------------------------------------*/
  1572. extern probe_t *probelist[];
  1573. /*--------------------------------------------------------------------------*/
  1574. int probcount(simtype)            /* count probes                */
  1575. int simtype;                /* called by: fourier, random        */
  1576. {
  1577.  int ii;
  1578.  int count = 0;
  1579.  
  1580.  if (probelist[simtype]){
  1581.     for (ii = 0;  *probelist[simtype][ii].what;  ii++){
  1582.        count++;
  1583.     }
  1584.  }
  1585.  return count;
  1586. }
  1587. /*--------------------------------------------------------------------------*/
  1588. /*--------------------------------------------------------------------------*/
  1589. SHAR_EOF
  1590. fi # end of overwriting check
  1591. if test -f 'src/qfree.c'
  1592. then
  1593.     echo shar: will not over-write existing file "'src/qfree.c'"
  1594. else
  1595. cat << \SHAR_EOF > 'src/qfree.c'
  1596. /* qfree  04/02/92
  1597.  * Copyright 1983-1992   Albert Davis
  1598.  * free an area (as in free) and NULL its pointer
  1599.  *
  1600.  */
  1601. #include "ecah.h"
  1602. #include "declare.h"
  1603. /*--------------------------------------------------------------------------*/
  1604.     void    qfree(void**);
  1605. /*--------------------------------------------------------------------------*/
  1606. void qfree(ptr)
  1607. void **ptr;
  1608. {
  1609.  if (*ptr)
  1610.     free(*ptr);
  1611.  *ptr = (void*)NULL;
  1612. }
  1613. /*--------------------------------------------------------------------------*/
  1614. /*--------------------------------------------------------------------------*/
  1615. SHAR_EOF
  1616. fi # end of overwriting check
  1617. if test -f 'src/quit.c'
  1618. then
  1619.     echo shar: will not over-write existing file "'src/quit.c'"
  1620. else
  1621. cat << \SHAR_EOF > 'src/quit.c'
  1622. /* quit  04/02/92
  1623.  * Copyright 1983-1992   Albert Davis
  1624.  * exits the program
  1625.  */
  1626. #include "ecah.h"
  1627. #include "mode.h"
  1628. #include "options.h"
  1629. #include "declare.h"
  1630. /*--------------------------------------------------------------------------*/
  1631.     void    cmd_quit(const char*, int*);
  1632. /*--------------------------------------------------------------------------*/
  1633. extern const struct options opt;
  1634. extern int run_mode;    /* variations on handling of dot cmds            */
  1635. /*--------------------------------------------------------------------------*/
  1636. /*ARGSUSED*/
  1637. void cmd_quit(cmd,cnt)
  1638. const char *cmd;
  1639. int *cnt;
  1640. {
  1641.  if (run_mode == rEXECUTE){
  1642.     if (match(cmd,"END") && opt.acct)
  1643.        cmd_status();
  1644.     exit(0);
  1645.  }
  1646. }
  1647. /*--------------------------------------------------------------------------*/
  1648. /*--------------------------------------------------------------------------*/
  1649. SHAR_EOF
  1650. fi # end of overwriting check
  1651. if test -f 'src/time_it.c'
  1652. then
  1653.     echo shar: will not over-write existing file "'src/time_it.c'"
  1654. else
  1655. cat << \SHAR_EOF > 'src/time_it.c'
  1656. /* time_it.c  12/31/92
  1657.  * Copyright 1983-1992   Albert Davis
  1658.  * Time a command, or whatever
  1659.  */
  1660. /*--------------------------------------------------------------------------*/
  1661. #include "ecah.h"
  1662. #ifndef NOTIME
  1663. /*--------------------------------------------------------------------------*/
  1664. #include "error.h"
  1665. #include "status.h"
  1666. #include <sys/resource.h>
  1667. #include "declare.h"
  1668. /*--------------------------------------------------------------------------*/
  1669.     void    time_fullreset(struct time_s*);
  1670.     void    time_reset(struct time_s*);
  1671.     void    time_zstart(struct time_s*);
  1672.     void    time_start(struct time_s*);
  1673.     void    time_stop(struct time_s*);
  1674.     void    time_check(struct time_s*);
  1675. /*--------------------------------------------------------------------------*/
  1676. extern char e_int[];
  1677. /*--------------------------------------------------------------------------*/
  1678. void time_fullreset(y)
  1679. struct time_s *y;
  1680. {
  1681.  y->total_user  = 0.;
  1682.  y->total_system= 0.;
  1683.  time_reset(y);
  1684. }
  1685. /*--------------------------------------------------------------------------*/
  1686. void time_reset(y)
  1687. struct time_s *y;
  1688. {
  1689.  y->last_user   = 0.;
  1690.  y->last_system = 0.;
  1691.  y->ref_user    = 0.;
  1692.  y->ref_system  = 0.;
  1693.  y->running = NO;
  1694. }
  1695. /*--------------------------------------------------------------------------*/
  1696. void time_zstart(y)
  1697. struct time_s *y;
  1698. {
  1699.  time_reset(y);
  1700.  time_start(y);
  1701. }
  1702. /*--------------------------------------------------------------------------*/
  1703. void time_start(y)
  1704. struct time_s *y;
  1705. {
  1706.  if (y->running){
  1707.     error(bWARNING, e_int, "clock already running");
  1708.     time_check(y);
  1709.  }else{
  1710.     struct rusage x;
  1711.     (void)getrusage(RUSAGE_SELF,&x);
  1712.     y->ref_user =
  1713.        (double)(x.ru_utime.tv_sec) + (double)(x.ru_utime.tv_usec)*1e-6; 
  1714.     y->ref_system =
  1715.        (double)(x.ru_stime.tv_sec) + (double)(x.ru_stime.tv_usec)*1e-6; 
  1716.     y->running = YES;
  1717.  }
  1718. }
  1719. /*--------------------------------------------------------------------------*/
  1720. void time_stop(y)
  1721. struct time_s *y;
  1722. {
  1723.  if (!y->running){
  1724.     error(bWARNING, e_int, "clock not running");
  1725.  }else{
  1726.     struct rusage x;
  1727.     double utime, stime;
  1728.     double runtime;
  1729.     (void)getrusage(RUSAGE_SELF,&x);
  1730.     
  1731.     utime=(double)(x.ru_utime.tv_sec)+(double)(x.ru_utime.tv_usec)*1e-6; 
  1732.     runtime = utime - y->ref_user;
  1733.     y->ref_user    =  0.;
  1734.     y->last_user   += runtime;
  1735.     y->total_user  += runtime;
  1736.     
  1737.     stime=(double)(x.ru_stime.tv_sec)+(double)(x.ru_stime.tv_usec)*1e-6; 
  1738.     runtime = stime - y->ref_system;
  1739.     y->ref_system  =  0.;
  1740.     y->last_system += runtime;
  1741.     y->total_system+= runtime;
  1742.     y->running = NO;
  1743.  }
  1744. }
  1745. /*--------------------------------------------------------------------------*/
  1746. void time_check(y)
  1747. struct time_s *y;
  1748. {
  1749.  if (y->running){
  1750.     time_stop(y);
  1751.     time_start(y);
  1752.  }
  1753. }
  1754. /*--------------------------------------------------------------------------*/
  1755. #endif
  1756. /*--------------------------------------------------------------------------*/
  1757. /*--------------------------------------------------------------------------*/
  1758. SHAR_EOF
  1759. fi # end of overwriting check
  1760. if test -f 'src/title.c'
  1761. then
  1762.     echo shar: will not over-write existing file "'src/title.c'"
  1763. else
  1764. cat << \SHAR_EOF > 'src/title.c'
  1765. /* title  10/08/91
  1766.  * Copyright 1983-1992   Albert Davis
  1767.  * set title on printouts, etc.
  1768.  */
  1769. #include "ecah.h"
  1770. #include "io.h"
  1771. #include "declare.h"
  1772. /*--------------------------------------------------------------------------*/
  1773.     void      cmd_title(const char*,int*);
  1774. /*--------------------------------------------------------------------------*/
  1775. extern struct ioctrl io;
  1776. extern char head[];
  1777. /*--------------------------------------------------------------------------*/
  1778. void cmd_title(cmd,cnt)
  1779. const char *cmd;
  1780. int  *cnt;
  1781. {
  1782.  io.where = (cmd[*cnt]) ? 0 : io.mstdout;
  1783.  
  1784.  if (cmd[*cnt])
  1785.     strcpy(head, &cmd[*cnt]);
  1786.  mprintf(io.where,"%s\n",head);
  1787. }
  1788. /*--------------------------------------------------------------------------*/
  1789. /*--------------------------------------------------------------------------*/
  1790. SHAR_EOF
  1791. fi # end of overwriting check
  1792. if test -f 'src/tr.c'
  1793. then
  1794.     echo shar: will not over-write existing file "'src/tr.c'"
  1795. else
  1796. cat << \SHAR_EOF > 'src/tr.c'
  1797. /* tr  03/23/92
  1798.  * Copyright 1983-1992   Albert Davis
  1799.  * tran and fourier commands -- top
  1800.  */
  1801. #include "ecah.h"
  1802. #include "mode.h"
  1803. #include "status.h"
  1804. #include "tr.h"
  1805. #include "declare.h"
  1806. /*--------------------------------------------------------------------------*/
  1807.     void    cmd_tr(const char*,int*);
  1808.     void    cmd_fourier(const char*,int*);
  1809. /*--------------------------------------------------------------------------*/
  1810. extern struct status stats;
  1811. extern int run_mode;    /* variations on handling of dot cmds            */
  1812. extern int sim_mode;    /* simulation type (AC, DC, ...)            */
  1813. /*--------------------------------------------------------------------------*/
  1814. /* cmd_tr: transient analysis command
  1815.  */
  1816. void cmd_tr(cmd,cnt)
  1817. const char *cmd;
  1818. int  *cnt;
  1819. {
  1820.  static transient_t tr;
  1821.  
  1822.  sim_mode = sTRAN;
  1823.  time_zstart(&(stats.total));
  1824.  time_zstart(&(stats.tran));
  1825.  stats.iter[sim_mode] = 0;
  1826.  stats.iter[iPRINTSTEP] = 0;
  1827.  
  1828.  allocate(sim_mode);
  1829.  tr_setup(cmd,cnt,&tr);
  1830.  if (run_mode != rEXECUTE)
  1831.     return;
  1832.  tr_sweep(&tr);
  1833.  
  1834.  time_stop(&(stats.tran));
  1835.  time_stop(&(stats.total));
  1836. }
  1837. /*--------------------------------------------------------------------------*/
  1838. /* cmd_fourier: fourier analysis command
  1839.  * performs transient analysis, silently, then fft.
  1840.  * outputs results of fft
  1841.  */
  1842. void cmd_fourier(cmd,cnt)
  1843. const char *cmd;
  1844. int  *cnt;
  1845. {
  1846.  static fourier_t fo;
  1847.  
  1848.  sim_mode = sFOURIER;
  1849.  time_zstart(&(stats.total));
  1850.  time_zstart(&(stats.four));
  1851.  stats.iter[sim_mode] = 0;
  1852.  stats.iter[iPRINTSTEP] = 0;
  1853.  
  1854.  allocate(sim_mode);
  1855.  fo_setup(cmd,cnt,&fo);
  1856.  if (run_mode != rEXECUTE)
  1857.     return;
  1858.  tr_sweep(&fo.tr);
  1859.  foout(fo.start,fo.stop,fo.step);
  1860.  
  1861.  time_stop(&(stats.four));
  1862.  time_stop(&(stats.total));
  1863. }
  1864. /*--------------------------------------------------------------------------*/
  1865. /*--------------------------------------------------------------------------*/
  1866. SHAR_EOF
  1867. fi # end of overwriting check
  1868. if test -f 'src/trim.c'
  1869. then
  1870.     echo shar: will not over-write existing file "'src/trim.c'"
  1871. else
  1872. cat << \SHAR_EOF > 'src/trim.c'
  1873. /* trim  11/06/89
  1874.  * Copyright 1983-1992   Albert Davis
  1875.  * remove whitespace from the end of strings
  1876.  */
  1877. #include "ecah.h"
  1878. #include "declare.h"
  1879. /*--------------------------------------------------------------------------*/
  1880.     char      *trim(char*);
  1881. /*--------------------------------------------------------------------------*/
  1882. char *trim(string)
  1883. char *string;
  1884. {
  1885.  int index;
  1886.  
  1887.  index = strlen(string);
  1888.  while (index > 0  &&  !isgraph(string[--index]))
  1889.     string[index] = '\0' ;
  1890.  return string;
  1891. }
  1892. /*--------------------------------------------------------------------------*/
  1893. /*--------------------------------------------------------------------------*/
  1894. SHAR_EOF
  1895. fi # end of overwriting check
  1896. if test -f 'src/tr_adv.c'
  1897. then
  1898.     echo shar: will not over-write existing file "'src/tr_adv.c'"
  1899. else
  1900. cat << \SHAR_EOF > 'src/tr_adv.c'
  1901. /* tr_adv  02/15/92
  1902.  * Copyright 1983-1992   Albert Davis
  1903.  * Functions to set up the next time step, and next iteration
  1904.  */
  1905. #include "ecah.h"
  1906. #include "branch.h"
  1907. #include "error.h"
  1908. #include "mode.h"
  1909. #include "status.h"
  1910. #include "declare.h"
  1911. /*--------------------------------------------------------------------------*/
  1912.     void    trsetup(branch_t*);
  1913. /*--------------------------------------------------------------------------*/
  1914. extern       struct status stats;
  1915. extern const int    sim_mode;
  1916. extern const int    sim_phase;
  1917. extern const double trtime;        /* transient analysis time            */
  1918. /*--------------------------------------------------------------------------*/
  1919. /* trsetup: set up guesses for model evaluation
  1920.  * saves old model inputs, and computes new inputs (volts and current)
  1921.  * also saves old matrix parameters, for convergence checking
  1922.  */
  1923. void trsetup(brh)
  1924. branch_t *brh;
  1925. {
  1926.  if (exists(brh->parent)){
  1927.     brh->bypass = brh->parent->bypass;
  1928.  }
  1929.  brh->y2 = brh->y1;
  1930.  brh->y1 = brh->y0;
  1931.  brh->iter = stats.iter[iTOTAL];
  1932.  if (sim_mode == sDC  ||  sim_phase == pINIT_DC){    /* initial dc */
  1933.     brh->mt1 = brh->m0;
  1934.     brh->steptime = brh->oldsteptime = trtime;
  1935.     brh->dt = 0.;
  1936.  }else if (brh->steptime != trtime){    /* new time step */
  1937.     if (brh->steptime < trtime){        /* forward */
  1938.        brh->oldsteptime = brh->steptime;
  1939.        brh->mt1 = brh->m0;
  1940.        brh->dt = trtime - brh->oldsteptime;
  1941.        brh->steptime = trtime;
  1942.     }else{ /*(brh->steptime > trtime)*/        /* backward */
  1943.        brh->dt = trtime - brh->oldsteptime;
  1944.        brh->steptime = trtime;
  1945.     }
  1946.  }
  1947. }
  1948. /*--------------------------------------------------------------------------*/
  1949. /*--------------------------------------------------------------------------*/
  1950. SHAR_EOF
  1951. fi # end of overwriting check
  1952. if test -f 'src/tr_volts.c'
  1953. then
  1954.     echo shar: will not over-write existing file "'src/tr_volts.c'"
  1955. else
  1956. cat << \SHAR_EOF > 'src/tr_volts.c'
  1957. /* trvolts  03/22/92
  1958.  * Copyright 1983-1992   Albert Davis
  1959.  * dc and tr volts between two nodes (4 different versions)
  1960.  */
  1961. #include "ecah.h"
  1962. #include "branch.h"
  1963. #include "nodestat.h"
  1964. #include "options.h"
  1965. #include "declare.h"
  1966. /*--------------------------------------------------------------------------*/
  1967.     double    dc_volts(node_t,node_t);
  1968.     double    tr_volts(node_t,node_t);
  1969.     double    tr_volts_limited(node_t,node_t);
  1970.     double    tr_volts_t1(node_t,node_t);
  1971.     double    logicval(int);
  1972. /*--------------------------------------------------------------------------*/
  1973. extern const double *volts;    /* dc bias voltages                */
  1974. extern const double *imcon;    /* transient voltages, most recent        */
  1975. extern const double *oldcon;    /* transient voltages, 1 time ago        */
  1976. extern const struct nodestat *nstat;
  1977. extern const struct options opt;
  1978. /*--------------------------------------------------------------------------*/
  1979. /* dc_volts: dc voltage for bias calculations
  1980.  */
  1981. double dc_volts(n1,n2)
  1982. node_t n1,n2;
  1983. {
  1984.  return volts[n1.m] - volts[n2.m];
  1985. }
  1986. /*--------------------------------------------------------------------------*/
  1987. /* tr_volts: transient voltage, best approximation, no limiting
  1988.  */
  1989. double tr_volts(n1,n2)
  1990. node_t n1,n2;
  1991. {
  1992.  return imcon[n1.m] - imcon[n2.m];
  1993. }
  1994. /*--------------------------------------------------------------------------*/
  1995. /* tr_volts_limited: transient voltage, best approximation, with limiting
  1996.  */
  1997. double tr_volts_limited(n1,n2)
  1998. node_t n1,n2;
  1999. {
  2000.  double v;
  2001.  v = imcon[n1.m] - imcon[n2.m];
  2002.  if (v > opt.limit)
  2003.     v = opt.limit;
  2004.  if (v < -opt.limit)
  2005.     v = -opt.limit;
  2006.  return v;
  2007. }
  2008. /*--------------------------------------------------------------------------*/
  2009. /* tr_volts_t1: transient voltage, 1 time ago
  2010.  */
  2011. double tr_volts_t1(n1,n2)
  2012. node_t n1,n2;
  2013. {
  2014.  return oldcon[n1.m] - oldcon[n2.m];
  2015. }
  2016. /*--------------------------------------------------------------------------*/
  2017. double logicval(n1)        /* cryptic interpretation of logic value    */
  2018. int n1;
  2019. {
  2020.  struct nodestat s;
  2021.  s = nstat[n1];
  2022.  return (     (2*s.lv0 + s.lv1)
  2023.     + (.1  * (opt.transits - s.quality))
  2024.     + (.01 * (2 - s.nodemode)));
  2025. }
  2026. /*--------------------------------------------------------------------------*/
  2027. /*--------------------------------------------------------------------------*/
  2028. SHAR_EOF
  2029. fi # end of overwriting check
  2030. if test -f 'src/tr_z.c'
  2031. then
  2032.     echo shar: will not over-write existing file "'src/tr_z.c'"
  2033. else
  2034. cat << \SHAR_EOF > 'src/tr_z.c'
  2035. /* tr_z  12/31/92
  2036.  * Copyright 1983-1992   Albert Davis
  2037.  * impedance looking across two nodes
  2038.  */
  2039. #include "ecah.h"
  2040. #include "branch.h"
  2041. #include "error.h"
  2042. #include "status.h"
  2043. #include "declare.h"
  2044. /*--------------------------------------------------------------------------*/
  2045.     double    trz(node_t,node_t,double);
  2046. /*--------------------------------------------------------------------------*/
  2047. extern const struct status stats;
  2048.  
  2049. extern const int decomp;
  2050. extern const char e_om[];
  2051.  
  2052. extern double *recon, *imcon;
  2053. /*--------------------------------------------------------------------------*/
  2054. /* trz: impedance looking across two nodes
  2055.  */
  2056. /*ARGSUSED*/
  2057. double trz(n1,n2,parallel)
  2058. node_t n1,n2;
  2059. double parallel;
  2060. {
  2061.  static double *zapit;
  2062.  static unsigned gotsize;
  2063.  unsigned newsize;
  2064.  double *voltages;    /* save right side vector */
  2065.  double *rightside;
  2066.  double raw_z;
  2067.  
  2068.  if (!decomp)        /* can't do Z on transient first step.  */
  2069.     return 0.0;
  2070.  
  2071.  newsize = ((unsigned)stats.total_nodes+2) * sizeof(double);
  2072.  if (!zapit){
  2073.     zapit = (double*)calloc(newsize,1);        /* alloc memory */
  2074.     gotsize = newsize;
  2075.  }else if (newsize > gotsize){
  2076.     zapit = (double*)realloc((void*)zapit,newsize);
  2077.     gotsize = newsize;
  2078.  }
  2079.  if (!zapit)
  2080.     error(bERROR, e_om, "trz");
  2081.  
  2082.  rightside = recon;            /* stash real voltages */
  2083.  voltages = imcon;
  2084.  imcon = recon = zapit;
  2085.  
  2086.  (void)memset((void*)recon,0,newsize);
  2087.  if (n1.m)                /* build new rt side */
  2088.     recon[n1.m] =  1.;            /* 1 amp current source */
  2089.  if (n2.m)
  2090.     recon[n2.m] = -1.;
  2091.  
  2092.  solve();                /* solve for volts */
  2093.  raw_z = tr_volts(n1,n2);        /* volts is impedance */
  2094.  
  2095.  imcon = voltages;            /* restore real stuff */
  2096.  recon = rightside;
  2097.  return  1. / ((1./raw_z)-parallel);
  2098. }
  2099. /*--------------------------------------------------------------------------*/
  2100. /*--------------------------------------------------------------------------*/
  2101. SHAR_EOF
  2102. fi # end of overwriting check
  2103. #    End of shell archive
  2104. exit 0
  2105.