home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / sources / 3109 < prev    next >
Encoding:
Text File  |  1993-01-28  |  49.5 KB  |  1,777 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 13/20
  5. Message-ID: <1993Jan27.040819.11609@rbc.uucp>
  6. Date: 27 Jan 93 04:08:19 GMT
  7. Sender: al@rbc.uucp (Al Davis)
  8. Organization: Huh?
  9. Lines: 1766
  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/d_logic.c
  17. #    src/d_res.c
  18. #    src/d_subckt.c
  19. #    src/d_trln.c
  20. #    src/d_vccs.c
  21. #    src/d_vcvs.c
  22. #    src/d_vs.c
  23. # This archive created: Tue Jan 26 22:51:03 1993
  24. export PATH; PATH=/bin:$PATH
  25. if test -f 'src/d_logic.c'
  26. then
  27.     echo shar: will not over-write existing file "'src/d_logic.c'"
  28. else
  29. cat << \SHAR_EOF > 'src/d_logic.c'
  30. /* dev_log.c  01/05/93
  31.  * Copyright 1983-1992   Albert Davis
  32.  * logic model.
  33.  */
  34. #include "ecah.h"
  35. #include "argparse.h"
  36. #include "branch.h"
  37. #include "convstat.h"
  38. #include "dev.h"
  39. #include "error.h"
  40. #include "mode.h"
  41. #include "nodestat.h"
  42. #include "options.h"
  43. #include "status.h"
  44. #include "types.h"
  45. #include "d_logic.h"
  46. #include "d_subckt.h"
  47. #include "declare.h"
  48. /*--------------------------------------------------------------------------*/
  49. static     branch_t *create_logic(const branch_t*);
  50. static     void    parse_logic(branch_t*,const char*,int*);
  51. static     void    print_logic(const branch_t*,int,int);
  52. static    branch_t *create_model_logic(const branch_t*);
  53. static     void    parse_model_logic(branch_t*,const char*,int*);
  54. static     void    print_model_logic(const branch_t*,int,int);
  55. static     void    expand_logic(branch_t*);
  56. static    double    trprobe_logic(const branch_t*,const char*);
  57. static     int    tr_logic(branch_t*);
  58. static     void    un_logic(branch_t*);
  59. static     void    ac_logic(branch_t*);
  60. static    struct nodestat *tologic(const struct lmod*,node_t);
  61. static    double    toanalog(const struct lmod*,node_t);
  62. static    double    tr_review_logic(branch_t*);
  63. /*--------------------------------------------------------------------------*/
  64. functions_t dev_logic = {
  65.    sizeof(branch_t),
  66.    create_logic,
  67.    parse_logic,
  68.    print_logic,
  69.    expand_logic,
  70.    trprobe_logic,
  71.    (double(*)())NULL,/* acprobe */
  72.    tr_logic,
  73.    un_logic,
  74.    ac_logic,
  75.    (void(*)())NULL,    /* trfun1 */
  76.    (void(*)())NULL,    /* trfun0 */
  77.    (complex_t(*)())NULL,/* acfun */
  78.    (void(*)())NULL,    /* tr_guess */
  79.    (void(*)())NULL,    /* tr_advance */
  80.    tr_review_logic
  81. };
  82. functions_t model_logic = {
  83.    sizeof(branch_t),
  84.    create_model_logic,
  85.    parse_model_logic,
  86.    print_model_logic,
  87.    (void(*)())NULL,    /* expand */
  88.    (double(*)())NULL,    /* trprobe */
  89.    (double(*)())NULL,/* acprobe */
  90.    (int(*)())NULL,    /* dotr */
  91.    (void(*)())NULL,    /* untr */
  92.    (void(*)())NULL,    /* doac */
  93.    (void(*)())NULL,    /* trfun1 */
  94.    (void(*)())NULL,    /* trfun0 */
  95.    (complex_t(*)())NULL,/* acfun */
  96.    (void(*)())NULL,    /* tr_guess */
  97.    (void(*)())NULL,    /* tr_advance */
  98.    tr_review_logic
  99. };
  100. /*--------------------------------------------------------------------------*/
  101. extern struct nodestat *nstat;    /* node status flags                */
  102. extern const int inc_mode;    /* make incremental changes            */
  103. extern const int sim_phase;
  104. extern const double trtime;    /* transient analysis time            */
  105. extern const struct options opt;
  106. extern const struct status stats;
  107.  
  108. static char *(typename[]) = {"error", "and", "nand", "or", "nor", "xor",
  109.     "inv", ""};
  110. static struct logic defalt = {(generic_t*)NULL, sizeof(struct logic),
  111.     (struct lmod*)NULL, lDEFAULT_modelname, lDEFAULT_type, INVALIDNODE};
  112. static struct lmod defaltmodel = {(generic_t*)NULL, sizeof(struct lmod),
  113.     lDEFAULT_delay, lDEFAULT_rise, lDEFAULT_fall, lDEFAULT_rs,
  114.     lDEFAULT_rw, lDEFAULT_th1, lDEFAULT_th0, lDEFAULT_mr, lDEFAULT_mf,
  115.     lDEFAULT_over, lDEFAULT_vmax, lDEFAULT_vmin, lDEFAULT_range};
  116. static branch_t modellist = {(generic_t*)&defaltmodel, sizeof(branch_t),
  117.     &model_logic, &modellist, &modellist, &modellist, &modellist,
  118.     (branch_t*)NULL, (branch_t*)NULL, lDEFAULT_modelname, /* more */};
  119. /*--------------------------------------------------------------------------*/
  120. static branch_t *create_logic(proto)
  121. const branch_t *proto;
  122. {
  123.  branch_t *brh;
  124.  struct logic *x;
  125.  
  126.  brh = createbranch(proto,(generic_t*)&defalt,&dev_logic);
  127.  x = (struct logic*)brh->x;
  128.  brh->n = x->n;
  129.  return brh;
  130. }
  131. /*--------------------------------------------------------------------------*/
  132. static void parse_logic(brh,cmd,cnt)
  133. branch_t *brh;
  134. const char *cmd;
  135. int *cnt;
  136. {
  137.  struct logic *x;
  138.  x = (struct logic*)brh->x;
  139.  
  140.  parselabel(brh,cmd,cnt);
  141.  x->incount = parsenodes(brh,cmd,cnt,PORTSPERGATE);
  142.  (void)ctostr(cmd, cnt, x->modelname, LABELEN);
  143.  if (argparse(cmd,cnt,ONEPASS,
  144.         "AND",    aENUM,        &x->type,    lAND,
  145.     "NAND",    aENUM,        &x->type,    lNAND,
  146.     "OR",    aENUM,        &x->type,    lOR,
  147.     "NOR",    aENUM,        &x->type,    lNOR,
  148.     "XOR",    aENUM,        &x->type,    lXOR,
  149.     "INV",    aENUM,        &x->type,    lINV,
  150.      ""))
  151.     x->incount -= 2;
  152.  else{
  153.     syntax(cmd,cnt,bWARNING);
  154.  }
  155. }
  156. /*--------------------------------------------------------------------------*/
  157. static void print_logic(brh,where,detail)
  158. const branch_t *brh;
  159. int where;
  160. int detail;
  161. {
  162.  struct logic *x;
  163.  x = (struct logic*)brh->x;
  164.  
  165.  (void)printlabel(brh,where);
  166.  printnodes(brh,where);
  167.  mprintf(where, " %s %s\n", x->modelname, typename[x->type]); 
  168. }
  169. /*--------------------------------------------------------------------------*/
  170. static branch_t *create_model_logic(proto)
  171. const branch_t *proto;
  172. {
  173.  branch_t *brh;
  174.  struct lmod *m;
  175.  
  176.  brh = createbranch(proto,(generic_t*)&defaltmodel,&model_logic);
  177.  m = (struct lmod*)brh->x;
  178.  brh->stprev = &modellist;
  179.  return brh;
  180. }
  181. /*--------------------------------------------------------------------------*/
  182. static void parse_model_logic(brh,cmd,cnt)
  183. branch_t *brh;
  184. const char *cmd;
  185. int *cnt;
  186. {
  187.  struct lmod *m;
  188.  m = (struct lmod*)brh->x;
  189.  
  190.  (void)ctostr(cmd, cnt, brh->label, LABELEN);
  191.  skiparg(cmd,cnt);    /* skip known "logic" */
  192.  (void)skiplparen(cmd,cnt);
  193.  for (;;){
  194.     if (argparse(cmd,cnt,REPEAT,
  195.     "DElay",aUDOUBLE,    &m->delay,
  196.     "RIse",    aUDOUBLE,    &m->rise,
  197.     "FAll",    aUDOUBLE,    &m->fall,
  198.     "RS",    aUDOUBLE,    &m->rs,
  199.     "RW",    aUDOUBLE,    &m->rw,
  200.     "THH",    aDOUBLE,    &m->th1,
  201.     "THL",    aDOUBLE,    &m->th0,
  202.     "MR",    aUDOUBLE,    &m->mr,
  203.     "MF",    aUDOUBLE,    &m->mf,
  204.     "OVer",    aUDOUBLE,    &m->over,
  205.     "VMAx",    aDOUBLE,    &m->vmax,
  206.     "VMIn",    aDOUBLE,    &m->vmin,
  207.     ""))
  208.     ;
  209.    else{
  210.       (void)skiprparen(cmd,cnt);
  211.       syntax(cmd,cnt,bWARNING);
  212.       break;
  213.    }
  214.  m->range = m->vmax - m->vmin;
  215.  }
  216. }
  217. /*--------------------------------------------------------------------------*/
  218. static void print_model_logic(brh,where,detail)
  219. const branch_t *brh;
  220. int where;
  221. int detail;
  222. {
  223.  struct lmod *m;
  224.  m = (struct lmod*)brh->x;
  225.  
  226.  mprintf(where, ".model  %s logic (", brh->label); 
  227.  mprintf(where, " delay=%s ",ftos(m->delay,"", 7, 0));
  228.  mprintf(where, " rise=%s ", ftos(m->rise, "", 7, 0));
  229.  mprintf(where, " fall=%s ", ftos(m->fall, "", 7, 0));
  230.  mprintf(where, " rs=%s ",   ftos(m->rs,   "", 7, 0));
  231.  mprintf(where, " rw=%s ",   ftos(m->rw,   "", 7, 0));
  232.  mprintf(where, " thh=%s ",  ftos(m->th1,  "", 7, 0));
  233.  mprintf(where, " thl=%s ",  ftos(m->th0,  "", 7, 0));
  234.  mprintf(where, " mr=%s ",   ftos(m->mf,   "", 7, 0));
  235.  mprintf(where, " mf=%s ",   ftos(m->mr,   "", 7, 0));
  236.  mprintf(where, " over=%s ", ftos(m->over, "", 7, 0));
  237.  mprintf(where, " vmax=%s ", ftos(m->vmax, "", 7, 0));
  238.  mprintf(where, " vmin=%s ", ftos(m->vmin, "", 7, 0));
  239.  mprintf(where, ")\n");
  240. }
  241. /*--------------------------------------------------------------------------*/
  242. static void expand_logic(brh)
  243. branch_t *brh;
  244. {
  245.  char cktname[BUFLEN];
  246.  struct logic *x;
  247.  
  248.  branch_t *foo;
  249.  foo = brh->subckt;
  250.  
  251.  x = (struct logic*)brh->x;
  252.  sprintf(cktname, "%s%s%u", x->modelname, typename[x->type], x->incount);
  253.  expandgeneric(brh,&modellist);
  254.  brh->subckt = foo;
  255.  expandsubckt(brh,cktname);
  256.  if (!brh->subckt){
  257.     error(bDANGER, "%s: no model, forcing digital\n", printlabel(brh,0));
  258.  }
  259.  brh->tracesubckt = YES;
  260. }
  261. /*--------------------------------------------------------------------------*/
  262. static double trprobe_logic(brh,what)
  263. const branch_t *brh;
  264. const char *what;
  265. {
  266.  struct logic *x;
  267.  double volts;
  268.  int dummy = 0;
  269.  
  270.  x = (struct logic*)brh->x;
  271.  if (!x->m  ||  !brh->subckt)
  272.     error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
  273.  
  274.  volts = tr_volts(brh->n[OUT1],brh->n[OUT2]);
  275.  
  276.  setmatch(what,&dummy);
  277.  if (rematch("V")){
  278.     return volts;
  279.  }else { /* bad parameter */
  280.     return NOT_VALID;
  281.  }
  282. }
  283. /*--------------------------------------------------------------------------*/
  284. static int tr_logic(brh)
  285. branch_t *brh;
  286. {
  287.  struct nodestat *n;
  288.  struct logic *x;
  289.  const struct lmod *m;
  290.  
  291.  if (brh->iter == stats.iter[iTOTAL]){
  292.     return brh->status;
  293.  }else{
  294.     brh->iter = stats.iter[iTOTAL];
  295.  }
  296.  x = (struct logic*)brh->x;
  297.  m = x->m;
  298.  n = &(nstat[brh->n[1].m]);
  299.  
  300.  if ((x->gatemode == mANALOG)
  301.  ||  (opt.mode == mMIXED && sim_phase == pINIT_DC)
  302.  ||  (opt.mode == mANALOG)){
  303.     x->gatemode = n->nodemode = mANALOG;
  304.     return brh->status = tr_fill_rl(brh->subckt);
  305.  }
  306.  
  307. /* if it gets here, either opt.mode == mMIXED  &&  quality == qGOOD
  308.  *            or opt.mode == mDIGITAL
  309.  */
  310.  
  311.  brh->bypass = YES;
  312.  x->gatemode = n->nodemode = mDIGITAL;
  313.                     /* in transition */
  314.  if (trtime >= n->finaltime){            /* time to propagate */
  315.     brh->bypass = NO;
  316.     n->lv0 = n->lv1;
  317.     n->ls0 = n->ls1;
  318.     n->isanalog = NO;
  319.     n->quality = qGOOD;
  320.     n->diter = stats.iter[iTOTAL];
  321.     n->finaltime = BIGBIG;
  322.     n->lastchange = trtime;
  323.  }
  324.  
  325.  if (n->finaltime != BIGBIG  ||  !brh->bypass  ||  !inc_mode){
  326.     trsetup(brh);
  327.     brh->m0.x = 0.;
  328.     brh->y0.x = 0.;
  329.     brh->y0.f1 = -toanalog(m,brh->n[1]);
  330.     brh->y0.f0 = 0.;
  331.     brh->ev = brh->y0.f1;
  332.     brh->m0.f1 = 1./m->rs;
  333.     brh->m0.c0 = brh->y0.f1 / -m->rs;
  334.     trloadpassive(brh);
  335.  }
  336.  return brh->status = cGOOD;
  337. }
  338. /*--------------------------------------------------------------------------*/
  339. static void un_logic(brh)
  340. branch_t *brh;
  341. {
  342.  tr_unfill_rl(brh->subckt);
  343.  unloadpassive(brh);
  344. }
  345. /*--------------------------------------------------------------------------*/
  346. static void ac_logic(brh)
  347. branch_t *brh;
  348. {
  349.  error(bWARNING, "%s: no logic in AC analysis\n", printlabel(brh,NO));
  350. }
  351. /*--------------------------------------------------------------------------*/
  352. static struct nodestat *tologic(m,node)
  353. const struct lmod *m;
  354. node_t node;
  355. {
  356.  struct nodestat *n;
  357.  
  358.  if (node.m == INVALIDNODE){
  359.     node_t ground;
  360.     ground.e = ground.m = ground.t = 0;
  361.     error(bDANGER, "%u:(%u,%u,%u):internal error: invalid node\n",
  362.               stats.iter[iTOTAL], node.e, node.t, node.m);
  363.     return &(nstat[ground.m]);
  364.  }
  365.  
  366.  n = &(nstat[node.m]);
  367.  if (!m){
  368.     m = n->family;
  369.  }else if (!n->family){
  370.     n->family = m;
  371.  }
  372.  
  373.  if (n->nodemode == mDIGITAL){
  374.     /* nothing */;
  375.  }else{ /* n->nodemode == mANALOG */
  376.     if (n->diter < n->aiter){
  377.        double newv;
  378.        double sv;
  379.        int oldstate;
  380.        node_t ground;
  381.        
  382.        ground.e = ground.m = ground.t = 0;
  383.        newv = tr_volts(node,ground);
  384.        sv = newv / m->range;
  385.        
  386.        n->dt = trtime - n->lastchange;
  387.        oldstate = n->lv0;
  388.  
  389.        if (sv >= m->th1){
  390.           n->lv0 = n->lv1 = YES;
  391.        }else if (sv <= m->th0){
  392.           n->lv0 = n->lv1 = NO;
  393.        }else{                    /* transition region */
  394.           int lv1old = n->lv1;
  395.           double oldv = tr_volts_t1(node,ground);
  396.       double oldsv = oldv / m->range;
  397.       double diff = sv - oldsv;
  398.       
  399.       if (diff > opt.abstol){                /* rising */
  400.          n->lv1 = YES;
  401.          if ((n->lv1 == lv1old)
  402.          &&  (n->lv0 == n->lv1  ||  diff < n->dt/(m->mr * m->rise))){
  403.             n->quality = qBAD;        /* inflection or too slow */
  404.         n->failuremode = "slow rise";
  405.          }
  406.       }else if (diff < -opt.abstol){            /* falling */
  407.          n->lv1 = NO;
  408.          if ((n->lv1 == lv1old)
  409.          &&  (n->lv0 == n->lv1  ||  -diff < n->dt/(m->mf * m->fall))){
  410.             n->quality = qBAD;        /* inflection or too slow */
  411.         n->failuremode = "slow fall";
  412.          }
  413.       }
  414.        }
  415.        if (sv > 1.+m->over  ||  sv < -m->over){    /* out of range */
  416.           n->quality = qBAD;
  417.       n->failuremode = "out of range";
  418.        }
  419.        if (n->quality != qGOOD  &&  n->lv0 != oldstate){
  420.           ++n->quality;
  421.        }
  422.        n->family = m;
  423.        n->diter = stats.iter[iTOTAL];
  424.        n->lastchange = trtime;
  425.     }else{
  426.     }
  427.  }
  428.  if (m != n->family){
  429.     n->quality = qBAD;
  430.     n->failuremode = "family mismatch";
  431.  } 
  432.  return n;
  433. }
  434. /*--------------------------------------------------------------------------*/
  435. static double toanalog(m,node)
  436. const struct lmod *m;
  437. node_t node;
  438. {
  439.  struct nodestat *n;
  440.  
  441.  n = &(nstat[node.m]);
  442.  if (!m){
  443.     m = n->family;
  444.  }else if (!n->family){
  445.     n->family = m;
  446.  }
  447.  
  448.  if (n->lv0 == n->lv1){
  449.     return (n->lv0) ? m->vmax : m->vmin;
  450.  }else if (trtime <= (n->finaltime - ((n->lv0)?(m->fall):(m->rise)))){
  451.     return (n->lv0) ? m->vmax : m->vmin;
  452.  }else if (trtime >= n->finaltime){    
  453.     return (n->lv1) ? m->vmax : m->vmin;
  454.  }else{
  455.     double start,end,interp;
  456.     start = (n->lv0) ? m->vmax : m->vmin;
  457.     end   = (n->lv1) ? m->vmax : m->vmin;
  458.     interp = (n->finaltime-trtime) / ((n->lv0)?(m->fall):(m->rise));
  459.     return end - (end - start) * interp;
  460.  }
  461. }
  462. /*--------------------------------------------------------------------------*/
  463. static double tr_review_logic(brh)
  464. branch_t *brh;
  465. {
  466.  struct nodestat *n[PORTSPERGATE];
  467.  struct logic *x;
  468.  const struct lmod *m;
  469.  int count;            /* review */
  470.  int lastchangenode = 0;    /* review */
  471.  int lastchangeiter = 0;    /* review, once */
  472.  int quality = qGOOD;        /* both */
  473.  char* failuremode = "default";    /* review & print */
  474.  
  475.  if (brh->iter == stats.iter[iTOTAL]){
  476.     error(bDANGER, "%s:%u:%g internal error: skip review\n",
  477.             printlabel(brh,0), stats.iter[iTOTAL], trtime);
  478.     return BIGBIG;
  479.  }else{
  480.     brh->iter = stats.iter[iTOTAL];
  481.  }
  482.  x = (struct logic*)brh->x;
  483.  m = x->m;
  484.  
  485.  for (count = 1;
  486.       count < PORTSPERGATE  &&  brh->n[count].e != INVALIDNODE;
  487.  /**/ count++){
  488.     n[count] = tologic(m,brh->n[count]);
  489.     if (quality > n[count]->quality){
  490.        quality = n[count]->quality;
  491.        failuremode = n[count]->failuremode;
  492.     }
  493.     if (n[count]->diter >= lastchangeiter){
  494.        lastchangeiter = n[count]->diter;
  495.        lastchangenode = count;
  496.     }
  497.  }
  498.  
  499.  /* count == number of connections, now const */
  500.  /* if lastchangenode == 1, no new changes, bypass */
  501.  
  502.  if ((opt.mode == mANALOG)  ||  (opt.mode == mMIXED && quality != qGOOD)){
  503.     if (x->gatemode == mDIGITAL){
  504.        error(bTRACE, "%s:%u:%g switch to analog (review), %s\n",
  505.                printlabel(brh,0), stats.iter[iTOTAL], trtime, failuremode);
  506.        unloadpassive(brh);
  507.     }
  508.     x->gatemode = nstat[brh->n[1].m].nodemode = mANALOG;
  509.     return tr_review_rl(brh->subckt);
  510.  }
  511.  
  512. /* if it gets here, either opt.mode == mMIXED  &&  quality == qGOOD
  513.  *            or opt.mode == mDIGITAL
  514.  */
  515.  
  516.  if (x->gatemode == mANALOG){
  517.     error(bTRACE, "%s:%u:%g switch to digital (review)\n",
  518.             printlabel(brh,0), stats.iter[iTOTAL], trtime);
  519.     tr_unfill_rl(brh->subckt);
  520.  }
  521.  x->gatemode = n[1]->nodemode = mDIGITAL;
  522.  brh->bypass = YES;
  523.  
  524.  if (!opt.bypass || lastchangenode!=1 || sim_phase==pINIT_DC){
  525.     struct nodestat new;
  526.     int ii;
  527.     new = *n[1];
  528.     brh->bypass = NO;
  529.     switch (x->type){
  530.     case lAND:
  531.        new.lv1 = YES;
  532.        for (ii = 2;  ii < count;  ii++)
  533.              new.lv1 &= n[ii]->lv0;
  534.        break;
  535.     case lNAND:
  536.        new.lv1 = YES;
  537.        for (ii = 2;  ii < count;  ii++)
  538.              new.lv1 &= n[ii]->lv0;
  539.        new.lv1 = !new.lv1;
  540.        break;
  541.     case lOR:
  542.        new.lv1 = NO;
  543.        for (ii = 2;  ii < count;  ii++)
  544.              new.lv1 |= n[ii]->lv0;
  545.        break;
  546.     case lNOR:
  547.        new.lv1 = NO;
  548.        for (ii = 2;  ii < count;  ii++)
  549.              new.lv1 |= n[ii]->lv0;
  550.        new.lv1 = !new.lv1;
  551.        break;
  552.     case lXOR:
  553.        new.lv1 = n[2]->lv0 ^ n[3]->lv0;
  554.        break;
  555.     case lINV:
  556.        new.lv1 = !n[2]->lv0;
  557.        break;
  558.     default:
  559.        error(bWARNING,"%s: %s, bad logic type\n",printlabel(brh,NO),x->type);
  560.        break;
  561.     }
  562.     if (new.lv1 != n[1]->lv1){
  563.        if (new.finaltime != BIGBIG){             /* in transition */
  564.       new.quality = qBAD;
  565.       new.failuremode = "race";
  566.        }
  567.        new.diter = stats.iter[iTOTAL];
  568.        new.finaltime = trtime + m->delay;
  569.        error(bTRACE, "%s:%u:%g new event\n",
  570.             printlabel(brh,0), stats.iter[iTOTAL], trtime);
  571.        new_event(new.finaltime);
  572.        new.lastchange = trtime;
  573.        *n[1] = new;
  574.        if (lastchangenode == 1){
  575.           error(bDANGER, "%s:%u:%g non-event state change\n",
  576.           printlabel(brh,0), stats.iter[iTOTAL], trtime);
  577.        }
  578.     }else if (lastchangenode != 1){
  579.        error(bTRACE,"%s:%u:%g null transition\n",
  580.                printlabel(brh,0), stats.iter[iTOTAL], trtime);
  581.     }else{
  582.        error(bTRACE,"%s:%u:%g null evaluation\n",
  583.                printlabel(brh,0), stats.iter[iTOTAL], trtime);
  584.     }
  585.  }
  586.  return BIGBIG;
  587. }
  588. /*--------------------------------------------------------------------------*/
  589. /*--------------------------------------------------------------------------*/
  590. SHAR_EOF
  591. fi # end of overwriting check
  592. if test -f 'src/d_res.c'
  593. then
  594.     echo shar: will not over-write existing file "'src/d_res.c'"
  595. else
  596. cat << \SHAR_EOF > 'src/d_res.c'
  597. /* dev_res.c  12/30/92
  598.  * Copyright 1983-1992   Albert Davis
  599.  * functions for resistor.
  600.  * x = amps, y.f0 = volts, ev = y.f1 = ohms
  601.  */
  602. #include "ecah.h"
  603. #include "branch.h"
  604. #include "convstat.h"
  605. #include "error.h"
  606. #include "mode.h"
  607. #include "options.h"
  608. #include "status.h"
  609. #include "declare.h"
  610. /*--------------------------------------------------------------------------*/
  611. static     branch_t    *create_resistor(const branch_t*);
  612. static     void    parse_resistor(branch_t*,const char*,int*);
  613. static     void    print_resistor(const branch_t*,int,int);
  614. static    void    expand_resistor(branch_t*);
  615. static    double    trprobe_resistor(const branch_t*,const char*);
  616. static    double    acprobe_resistor(const branch_t*,const char*);
  617. static     int    tr_resistor_lin(branch_t*);
  618. static     int    tr_resistor_nl(branch_t*);
  619. static     void    un_resistor(branch_t*);
  620. static     void    ac_resistor_lin(branch_t*);
  621. static     void    ac_resistor_nl(branch_t*);
  622. /*--------------------------------------------------------------------------*/
  623. functions_t dev_resistor_lin = {
  624.    sizeof(branch_t),
  625.    create_resistor,
  626.    parse_resistor,
  627.    print_resistor,
  628.    expand_resistor,
  629.    trprobe_resistor,
  630.    acprobe_resistor,
  631.    tr_resistor_lin,
  632.    un_resistor,
  633.    ac_resistor_lin,
  634.    (void(*)())NULL,    /* trfun1 */
  635.    (void(*)())NULL,    /* trfun0 */
  636.    (complex_t(*)())NULL,/* acfun */
  637.    (void(*)())NULL,    /* tr_guess */
  638.    (void(*)())NULL,    /* tr_advance */
  639.    (double(*)())NULL,    /* tr_review */
  640. };
  641. functions_t dev_resistor = {
  642.    sizeof(branch_t),
  643.    create_resistor,
  644.    parse_resistor,
  645.    print_resistor,
  646.    expand_resistor,
  647.    trprobe_resistor,
  648.    acprobe_resistor,
  649.    tr_resistor_nl,
  650.    un_resistor,
  651.    ac_resistor_nl,
  652.    trfix1,
  653.    trfix0,
  654.    acfix,
  655.    (void(*)())NULL,    /* tr_guess */
  656.    (void(*)())NULL,    /* tr_advance */
  657.    (double(*)())NULL    /* tr_review */
  658. };
  659. /*--------------------------------------------------------------------------*/
  660. extern const struct options opt;
  661. extern const struct status stats;
  662. /*--------------------------------------------------------------------------*/
  663. static branch_t *create_resistor(proto)
  664. const branch_t *proto;
  665. {
  666.  return createbranch(proto,(generic_t*)NULL,&dev_resistor);
  667. }
  668. /*--------------------------------------------------------------------------*/
  669. static void parse_resistor(brh,cmd,cnt)
  670. branch_t *brh;
  671. const char *cmd;
  672. int *cnt;
  673. {
  674.  parsegeneric(brh,cmd,cnt,2);
  675.  brh->f = &dev_resistor;
  676. }
  677. /*--------------------------------------------------------------------------*/
  678. static void print_resistor(brh,where,detail)
  679. const branch_t *brh;
  680. int where;
  681. int detail;
  682. {
  683.  printgeneric(brh,where,detail);
  684. }
  685. /*--------------------------------------------------------------------------*/
  686. static void expand_resistor(brh)
  687. branch_t *brh;
  688. {
  689.  if (!brh->x){
  690.     brh->f = &dev_resistor_lin;
  691.     if (brh->val == 0.){
  692.        error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
  693.        brh->ev = opt.shortckt;
  694.     }else{
  695.        brh->ev = brh->val;
  696.     }
  697.     brh->y0.f1 = brh->ev;
  698.     brh->y0.f0 = LINEAR;
  699.  
  700.     brh->m0.f1 = 1./brh->ev;
  701.     brh->m0.c0 = 0.;
  702.  }
  703. }
  704. /*--------------------------------------------------------------------------*/
  705. static double trprobe_resistor(brh,what)
  706. const branch_t *brh;
  707. const char *what;
  708. {
  709.  return trprobegeneric(brh,what);
  710. }
  711. /*--------------------------------------------------------------------------*/
  712. static double acprobe_resistor(brh,what)
  713. const branch_t *brh;
  714. const char *what;
  715. {
  716.  return acprobegeneric(brh,what);
  717. }
  718. /*--------------------------------------------------------------------------*/
  719. static int tr_resistor_lin(brh)
  720. branch_t *brh;
  721. {
  722.  if (brh->iter == stats.iter[iTOTAL]){
  723.     return brh->status;
  724.  }else{
  725.     brh->iter = stats.iter[iTOTAL];
  726.  }
  727.  trloadpassive(brh);
  728.  return brh->status = cGOOD;
  729. }
  730. /*--------------------------------------------------------------------------*/
  731. static int tr_resistor_nl(brh)
  732. branch_t *brh;
  733. {
  734.  if (brh->iter == stats.iter[iTOTAL]){
  735.     return brh->status;
  736.  }else{
  737.     brh->iter = stats.iter[iTOTAL];
  738.  }
  739.  trsetup(brh);
  740.  brh->m0.x = tr_volts_limited(brh->n[OUT1],brh->n[OUT2]);
  741.  brh->y0.x = brh->m0.c0 + brh->m0.f1 * brh->m0.x;
  742.  
  743.  if (brh->f->trfun1){
  744.     (*brh->f->trfun1)(brh);
  745.  }else{
  746.     brh->y0.f1 = brh->val;
  747.     brh->y0.f0 = LINEAR;
  748.  }
  749.  if (brh->y0.f1 == 0.){
  750.     error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
  751.     brh->y0.f1 = opt.shortckt;
  752.  }
  753.  brh->ev = brh->y0.f1;
  754.  brh->m0.f1 = 1./brh->y0.f1;
  755.  brh->m0.c0 = brh->y0.x - brh->y0.f0 / brh->y0.f1;
  756.  
  757.  trloadpassive(brh);
  758.  return brh->status = conv_check(brh);
  759. }
  760. /*--------------------------------------------------------------------------*/
  761. static void un_resistor(brh)
  762. branch_t *brh;
  763. {
  764.  unloadpassive(brh);
  765. }
  766. /*--------------------------------------------------------------------------*/
  767. static void ac_resistor_lin(brh)
  768. branch_t *brh;
  769. {
  770.  brh->acg.x = brh->m0.f1;
  771.  brh->acg.y = 0.;
  772.  acloadpassivereal(brh);
  773. }
  774. /*--------------------------------------------------------------------------*/
  775. static void ac_resistor_nl(brh)
  776. branch_t *brh;
  777. {
  778.  double dcvolts;
  779.  
  780.  if (brh->f->acfun){
  781.     dcvolts = dc_volts(brh->n[OUT1],brh->n[OUT2]);
  782.     brh->acbias = brh->m0.c0 + brh->m0.f1*dcvolts;
  783.     brh->acg = (*brh->f->acfun)(brh);
  784.     if (brh->acg.y == 0.){
  785.        if (brh->acg.x == 0.){
  786.           error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
  787.           brh->acg.x = opt.shortckt;
  788.        }
  789.        brh->acg.x = 1. / brh->acg.x;
  790.     }else{
  791.        brh->acg = cflip(brh->acg);
  792.     }
  793.     acloadpassive(brh);
  794.  }else{
  795.     brh->acg.x = brh->m0.f1;  /* == 1/ev */
  796.     brh->acg.y = 0.;
  797.     acloadpassivereal(brh);
  798.  }
  799. }
  800. /*--------------------------------------------------------------------------*/
  801. /*--------------------------------------------------------------------------*/
  802. SHAR_EOF
  803. fi # end of overwriting check
  804. if test -f 'src/d_subckt.c'
  805. then
  806.     echo shar: will not over-write existing file "'src/d_subckt.c'"
  807. else
  808. cat << \SHAR_EOF > 'src/d_subckt.c'
  809. /* dev_subc.c  12/30/92
  810.  * Copyright 1983-1992   Albert Davis
  811.  * subcircuit stuff
  812.  * netlist syntax:
  813.  * device: Xxxxx <nodelist> <subckt-name>
  814.  * model:  .subckt <subckt-name> <nodelist>
  815.  *       (device cards)
  816.  *       .ends <subckt-name>
  817.  */
  818. #include "ecah.h"
  819. #include "branch.h"
  820. #include "dev.h"
  821. #include "d_subckt.h"
  822. #include "error.h"
  823. #include "mode.h"
  824. #include "status.h"
  825. #include "types.h"
  826. #include "declare.h"
  827. /*--------------------------------------------------------------------------*/
  828.     void    cmd_ends(const char*,int*);
  829. static  branch_t  *create_subckt(const branch_t*);
  830. static  void    parse_subckt(branch_t*,const char*,int*);
  831. static  void    print_subckt(const branch_t*,int,int);
  832. static  branch_t  *create_model_subckt(const branch_t*);
  833. static  void    parse_model_subckt(branch_t*,const char*,int*);
  834. static  void    print_model_subckt(const branch_t*,int,int);
  835. static  void    expand_subckt(branch_t*);
  836.     void    expandsubckt(branch_t*,const char*);
  837. static    double    trprobe_subckt(const branch_t*,const char*);
  838. static  int     tr_subckt(branch_t*);
  839. static  void    un_subckt(branch_t*);
  840. static  void    ac_subckt(branch_t*);
  841. static    double    tr_review_subckt(branch_t*);
  842. /*--------------------------------------------------------------------------*/
  843. functions_t dev_subckt = {
  844.    sizeof(branch_t),
  845.    create_subckt,
  846.    parse_subckt,
  847.    print_subckt,
  848.    expand_subckt,
  849.    trprobe_subckt,
  850.    (double(*)())NULL,/* acprobe */
  851.    tr_subckt,
  852.    un_subckt,
  853.    ac_subckt,
  854.    (void(*)())NULL,    /* trfun1 */
  855.    (void(*)())NULL,    /* trfun0 */
  856.    (complex_t(*)())NULL,/* acfun */
  857.    (void(*)())NULL,    /* tr_guess */
  858.    (void(*)())NULL,    /* tr_advance */
  859.    tr_review_subckt
  860. };
  861. functions_t model_subckt = {
  862.    sizeof(branch_t),
  863.    create_model_subckt,
  864.    parse_model_subckt,
  865.    print_model_subckt,
  866.    (void(*)())NULL,    /* expand */
  867.    (double(*)())NULL,    /* trprobe */
  868.    (double(*)())NULL,/* acprobe */
  869.    (int(*)())NULL,    /* dotr */
  870.    (void(*)())NULL,    /* untr */
  871.    (void(*)())NULL,    /* doac */
  872.    (void(*)())NULL,    /* trfun1 */
  873.    (void(*)())NULL,    /* trfun0 */
  874.    (complex_t(*)())NULL,/* acfun */
  875.    (void(*)())NULL,    /* tr_guess */
  876.    (void(*)())NULL,    /* tr_advance */
  877.    (double(*)())NULL    /* tr_review */
  878. };
  879. /*--------------------------------------------------------------------------*/
  880. static struct subckt defalt =
  881.    {(generic_t*)NULL, sizeof(struct subckt),
  882.    (generic_t*)NULL, sDEFAULT_modelname, INVALIDNODE};
  883. static struct smod defaltmodel =
  884.    {(generic_t*)NULL, sizeof(struct smod),
  885.    (generic_t*)NULL, sDEFAULT_modelname, INVALIDNODE};
  886. static branch_t modellist = {(generic_t*)NULL, sizeof(branch_t), &model_subckt,
  887.    &modellist, &modellist, &modellist, &modellist, (branch_t*)NULL,
  888.    (branch_t*)NULL, sDEFAULT_modelname, /* more */};
  889. static branch_t *(neststack[RECURSE]);
  890. static char namestack[LABELEN+1][RECURSE];
  891. static int nestlevel;
  892.  
  893. extern branch_t *insertbefore;
  894. extern const struct status stats;
  895. extern const char e_int[];
  896. /*--------------------------------------------------------------------------*/
  897. void cmd_ends(cmd,cnt)
  898. const char* cmd;
  899. int *cnt;
  900. {
  901.  if (nestlevel == 0)
  902.     error(bWARNING, "ends not in subckt\n");
  903.  else
  904.     nestlevel--;
  905.  
  906.  if (cmd[*cnt]){
  907.     if (!pmatch(cmd, cnt, namestack[nestlevel]))
  908.        error(bERROR, "ends tag [%s] does not match subckt [%s]\n",
  909.           &cmd[*cnt], namestack[nestlevel]);
  910.  }else{
  911.     nestlevel = 0;
  912.  }
  913.  insertbefore = neststack[nestlevel];
  914. }
  915. /*--------------------------------------------------------------------------*/
  916. static branch_t *create_subckt(proto)
  917. const branch_t *proto;
  918. {
  919.  branch_t *brh;
  920.  struct subckt *x;
  921.  
  922.  brh = createbranch(proto,(generic_t*)&defalt,&dev_subckt);
  923.  x = (struct subckt*)brh->x;
  924.  brh->n = x->n;
  925.  return brh;
  926. }
  927. /*--------------------------------------------------------------------------*/
  928. static void parse_subckt(brh,cmd,cnt)
  929. branch_t *brh;
  930. const char *cmd;
  931. int *cnt;
  932. {
  933.  struct subckt *x;
  934.  x = (struct subckt*)brh->x;
  935.  
  936.  parselabel(brh,cmd,cnt);
  937.  (void)parsenodes(brh,cmd,cnt,PORTSPERSUBCKT);
  938.  (void)ctostr(cmd, cnt, x->modelname, LABELEN);
  939. }
  940. /*--------------------------------------------------------------------------*/
  941. static void print_subckt(brh,where,detail)
  942. const branch_t *brh;
  943. int where;
  944. int detail;
  945. {
  946.  struct subckt *x;
  947.  x = (struct subckt*)brh->x;
  948.  
  949.  (void)printlabel(brh,where);
  950.  printnodes(brh,where);
  951.  mprintf(where, " %s\n",    x->modelname);
  952. }
  953. /*--------------------------------------------------------------------------*/
  954. static branch_t *create_model_subckt(proto)
  955. const branch_t *proto;
  956. {
  957.  branch_t *brh;
  958.  struct smod *x;
  959.  
  960.  brh = createbranch(proto,(generic_t*)&defaltmodel,&model_subckt);
  961.  x = (struct smod*)brh->x;
  962.  brh->n = x->n;
  963.  brh->stprev = &modellist;
  964.  return brh;
  965. }
  966. /*--------------------------------------------------------------------------*/
  967. static void parse_model_subckt(brh,cmd,cnt)
  968. branch_t *brh;
  969. const char *cmd;
  970. int *cnt;
  971. {
  972.  struct smod *m;
  973.  m = (struct smod*)brh->x;
  974.  
  975.  if (nestlevel >= RECURSE)
  976.     error(bERROR,"%s: subckt nesting too deep\n", printlabel(brh,NO));
  977.  
  978.  (void)ctostr(cmd, cnt, brh->label, LABELEN);
  979.  (void)parsenodes(brh,cmd,cnt,PORTSPERSUBCKT);
  980.  
  981.  strcpy(namestack[nestlevel], brh->label);
  982.  neststack[nestlevel] = insertbefore;
  983.  nestlevel++;
  984.  brh->subckt = insertbefore =
  985.          insertbranch((*(dev_comment.create))((branch_t*)NULL));
  986.  m->x = (generic_t*)NULL;
  987. }
  988. /*--------------------------------------------------------------------------*/
  989. static void print_model_subckt(brh,where,detail)
  990. const branch_t *brh;
  991. int where;
  992. int detail;
  993. {
  994.  branch_t *x, *stop;
  995.  
  996.  mprintf(where, ".subckt %s ", brh->label);
  997.  printnodes(brh,where);
  998.  mprintf(where, "\n");
  999.  
  1000.  x = stop = brh->subckt;
  1001.  if (x){
  1002.     do {
  1003.        print_branch(x, where, NO);
  1004.     } while (x = x->next,  x != stop);
  1005.  }
  1006.  mprintf(where, "*+ends %s\n", brh->label);
  1007. }
  1008. /*--------------------------------------------------------------------------*/
  1009. static void expand_subckt(brh)
  1010. branch_t *brh;
  1011. {
  1012.  struct subckt *x;
  1013.  x = (struct subckt*)brh->x;
  1014.  expandsubckt(brh,x->modelname);
  1015.  if (!brh->subckt){
  1016.     error(bERROR, "");
  1017.  }
  1018.  brh->tracesubckt = YES;
  1019. }
  1020. /*--------------------------------------------------------------------------*/
  1021. void expandsubckt(brh,modelname)
  1022. branch_t *brh;
  1023. const char *modelname;
  1024. {
  1025.  const branch_t *model;
  1026.  /*struct subckt *x;*/
  1027.  branch_t *scan;
  1028.  branch_t *stop;
  1029.  int port, i;
  1030.  int map[NODESPERSUBCKT];
  1031.  
  1032.  /*x = (struct subckt*)brh->x;*/
  1033.  model = &modellist;                /* search for thing to copy */
  1034.  for (;;){
  1035.     model = model->stnext;
  1036.     if (wmatch(modelname, model->label)){
  1037.        break;
  1038.     }else if (model == &modellist){
  1039.        error(bDANGER, "%s: can't find model: %s\n",
  1040.               printlabel(brh,NO), modelname);
  1041.        if (brh->subckt){
  1042.           error(bERROR, e_int, "subckt exists but has no def\n");
  1043.        }else{
  1044.           return;
  1045.        }
  1046.     }
  1047.  }
  1048.  
  1049.  for (i = 0;  i < NODESPERSUBCKT;  i++)        /* initialize: all nodes unused */
  1050.     map[i] = UNUSED;
  1051.  
  1052.  stop = scan = nextbranch_dev(model->subckt);
  1053.  do {                         /* scan elements of subckt */
  1054.     int ii;                         /* mark nodes used */
  1055.     for (ii = 0;  scan->n[ii].e != INVALIDNODE;  ii++){
  1056.        if (scan->n[ii].e > NODESPERSUBCKT)
  1057.           error(bERROR, "%s: too many internal nodes\n", model->label);
  1058.        map[scan->n[ii].e] = USED;
  1059.     }
  1060.  } while (scan=nextbranch_dev(scan),  scan != stop);
  1061.  
  1062.  map[0] = 0;
  1063.  for (port = 0;  model->n[port].e != INVALIDNODE;  port++){    /* map ports */
  1064.     if (model->n[port].e > NODESPERSUBCKT)
  1065.        error(bERROR, "internal error: subckt node out of range: %s\n",
  1066.                    model->label);
  1067.     map[model->n[port].e] = brh->n[port].t;
  1068.  }
  1069.  
  1070.  for (i = 0;  i < NODESPERSUBCKT;  i++){
  1071.     if (map[i] == USED){
  1072.        map[i] = newnode_subckt();     /* assign number to internal nodes */
  1073.     }
  1074.  }
  1075.  
  1076.  if (!brh->subckt){
  1077.     error(bTRACE, "%s: expanding\n", printlabel(brh,NO));
  1078.     stop = scan = nextbranch_dev(model->subckt);
  1079.     do {
  1080.        branch_t *scratch;                     /* copy subckt */
  1081.        scratch = create_branch(scan);
  1082.        scratch->parent = brh;
  1083.        scratch->next = brh->subckt;
  1084.        brh->subckt = insertbranch(scratch);
  1085.     } while (scan=nextbranch_dev(scan),  scan != stop);
  1086.  }else{
  1087.     error(bTRACE, "%s: re-expanding\n", printlabel(brh,NO));
  1088.  }
  1089.  
  1090.  stop = scan = nextbranch_dev(brh->subckt);
  1091.  do {                                 /* patch nodes */
  1092.     int ii;
  1093.     for (ii = 0;  scan->n[ii].e != INVALIDNODE;  ii++){
  1094.        if (scan->n[ii].e < 0)
  1095.       error(bERROR, e_int, "bad node");
  1096.        if (map[scan->n[ii].e] < 0)
  1097.           error(bERROR, e_int, "node map");
  1098.        scan->n[ii].t = map[scan->n[ii].e];
  1099.     }
  1100.     scan->n[ii].t = INVALIDNODE;
  1101.  } while (scan=nextbranch_dev(scan),  scan != stop);
  1102. }
  1103. /*--------------------------------------------------------------------------*/
  1104. static double trprobe_subckt(brh,what)
  1105. const branch_t *brh;
  1106. const char *what;
  1107. {
  1108.  struct subckt *x;
  1109.  int dummy = 0;
  1110.  
  1111.  x = (struct subckt*)brh->x;
  1112.  if (!brh->subckt)
  1113.     error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
  1114.  
  1115.  setmatch(what,&dummy);
  1116.  if (rematch("P")){
  1117.     branch_t *pb, *stop;
  1118.     double power = 0.;
  1119.     stop = pb = brh->subckt;
  1120.     do {
  1121.        power += trprobe_branch(pb,"P");
  1122.     } while (pb=nextbranch_dev(pb), pb != stop);
  1123.     return power;
  1124.  }else{ /* bad parameter */
  1125.     return NOT_VALID;
  1126.  }
  1127.  /*NOTREACHED*/
  1128. }
  1129. /*--------------------------------------------------------------------------*/
  1130. static int tr_subckt(brh)
  1131. branch_t *brh;
  1132. {
  1133.  if (brh->iter == stats.iter[iTOTAL]){
  1134.     return brh->status;
  1135.  }else{
  1136.     brh->iter = stats.iter[iTOTAL];
  1137.  }
  1138.  if (!brh->subckt)
  1139.     error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
  1140.  return brh->status = tr_fill_rl(brh->subckt);
  1141. }
  1142. /*--------------------------------------------------------------------------*/
  1143. static void un_subckt(brh)
  1144. branch_t *brh;
  1145. {
  1146.  tr_unfill_rl(brh->subckt);
  1147. }
  1148. /*--------------------------------------------------------------------------*/
  1149. static void ac_subckt(brh)
  1150. branch_t *brh;
  1151. {
  1152.  if (!brh->subckt)
  1153.     error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
  1154.  ac_fill_rl(brh->subckt);
  1155. }
  1156. /*--------------------------------------------------------------------------*/
  1157. static double tr_review_subckt(brh)
  1158. branch_t *brh;
  1159. {
  1160.  return tr_review_rl(brh->subckt);
  1161. }
  1162. /*--------------------------------------------------------------------------*/
  1163. /*--------------------------------------------------------------------------*/
  1164. SHAR_EOF
  1165. fi # end of overwriting check
  1166. if test -f 'src/d_trln.c'
  1167. then
  1168.     echo shar: will not over-write existing file "'src/d_trln.c'"
  1169. else
  1170. cat << \SHAR_EOF > 'src/d_trln.c'
  1171. /* dev_trln  12/30/92
  1172.  * Copyright 1983-1992   Albert Davis
  1173.  * Transmission line. (ideal lossless.  for now, AC only)
  1174.  */
  1175. #include "ecah.h"
  1176. #include "ac.h"
  1177. #include "argparse.h"
  1178. #include "branch.h"
  1179. #include "d_trln.h"
  1180. #include "error.h"
  1181. #include "mode.h"
  1182. #include "status.h"
  1183. #include "declare.h"
  1184. /*--------------------------------------------------------------------------*/
  1185. static     branch_t *create_trnlin(const branch_t*);
  1186. static     void    parse_trnlin(branch_t*,const char*,int*);
  1187. static    void    setinitcond(const char*,int*);
  1188. static     void    print_trnlin(const branch_t*,int,int);
  1189. static     int    tr_trnlin(branch_t*);
  1190. static     void    ac_trnlin(branch_t*);
  1191. /*--------------------------------------------------------------------------*/
  1192. functions_t dev_trnlin = {
  1193.    sizeof(branch_t),
  1194.    create_trnlin,
  1195.    parse_trnlin,
  1196.    print_trnlin,
  1197.    (void(*)())NULL,    /* expand */
  1198.    (double(*)())NULL,    /* trprobe */
  1199.    (double(*)())NULL,   /* acprobe */
  1200.    tr_trnlin,
  1201.    (void(*)())NULL,    /* untr */
  1202.    ac_trnlin,
  1203.    (void(*)())NULL,    /* trfun1 */
  1204.    (void(*)())NULL,    /* trfun0 */
  1205.    (complex_t(*)())NULL,/* acfun */
  1206.    (void(*)())NULL,    /* tr_guess */
  1207.    (void(*)())NULL,    /* tr_advance */
  1208.    (double(*)())NULL    /* tr_review */
  1209. };
  1210. /*--------------------------------------------------------------------------*/
  1211. #define LINLENTOL .000001
  1212. extern const ac_t ac;
  1213. extern const struct status stats;
  1214.  
  1215. static struct trnlin *x;
  1216. static struct trnlin defalt = {(generic_t*)NULL, sizeof(struct trnlin),
  1217.     DEFAULT_Z0, DEFAULT_TD, DEFAULT_F, DEFAULT_NL, {0.,0.,0.,0.}, 0., NO};
  1218. /*--------------------------------------------------------------------------*/
  1219. static branch_t *create_trnlin(proto)
  1220. const branch_t* proto;
  1221. {
  1222.  return createbranch(proto,(generic_t*)&defalt,&dev_trnlin);
  1223. }
  1224. /*--------------------------------------------------------------------------*/
  1225. /* parse_trnlin: parse input for transmission line, set up branch structure
  1226.  */
  1227. static void parse_trnlin(brh,cmd,cnt)
  1228. branch_t *brh;
  1229. const char *cmd;
  1230. int *cnt;
  1231. {
  1232.  x = (struct trnlin*)brh->x;
  1233.  
  1234.  parselabel(brh,cmd,cnt);
  1235.  (void)parsenodes(brh,cmd,cnt,4);
  1236.  for (;;){
  1237.     if (argparse(cmd,cnt,REPEAT,
  1238.     "Z",    a2DOUBLE,   &x->z0,    &x->z0,
  1239.     "Freq",    aUDOUBLE,   &x->f,
  1240.     "Nl",    aUDOUBLE,   &x->nl,
  1241.     "Ic",    aFUNCTION,  setinitcond,
  1242.     ""))
  1243.     ;
  1244.     else{
  1245.     syntax(cmd,cnt,bWARNING);
  1246.     break;
  1247.     }
  1248.  }
  1249.  if (x->nl == 0.)
  1250.     x->nl = DEFAULT_NL;
  1251.  x->reson = x->f * (.25 / x->nl);
  1252. }
  1253. /*--------------------------------------------------------------------------*/
  1254. /* setinitcond: set initial conditions
  1255.  * called indirectly thru argparse
  1256.  * reads NUM_INIT_COND args, put them in static struct x.
  1257.  * passed this way because of inability of argparse to return values,
  1258.  * and that only cmd and cnt are passed by argparse
  1259.  */
  1260. static void setinitcond(cmd,cnt)
  1261. const char *cmd;
  1262. int *cnt;
  1263. {
  1264.  int i;
  1265.  x->icset = YES;
  1266.  for (i=0;  i<NUM_INIT_COND;  i++)
  1267.     x->ic[i] = ctof(cmd,cnt);
  1268. }
  1269. /*--------------------------------------------------------------------------*/
  1270. /* print_trnlin: print (to "where") the transmission line data structure
  1271.  */
  1272. static void print_trnlin(brh,where,detail)
  1273. const branch_t *brh;
  1274. int where;
  1275. int detail;
  1276. {
  1277.  struct trnlin *x;
  1278.  (void)printlabel(brh,where);
  1279.  printnodes(brh,where);
  1280.  x = (struct trnlin*)brh->x;
  1281.  mprintf(where, "  Z0=%s  F=%s  NL=%s",
  1282.     ftos(x->z0, "", 7, 0),
  1283.     ftos(x->f,  "", 7, 0),
  1284.     ftos(x->nl, "", 7, 0));
  1285.  if (x->icset){
  1286.     int i;
  1287.     mprintf(where, "  IC=");
  1288.     for (i=0;  i<NUM_INIT_COND;  i++)
  1289.     mprintf(where, "%s ",ftos(x->ic[i],"", 7, 0));
  1290.  }
  1291.  mputc('\n', where);
  1292. }
  1293. /*--------------------------------------------------------------------------*/
  1294. /* tr_trnlin:  transmission line for transient analysis
  1295.  * stub: doesn't work
  1296.  * always returns failure
  1297.  */
  1298. static int tr_trnlin(brh)
  1299. branch_t *brh;
  1300. {
  1301.  if (brh->iter == stats.iter[iTOTAL]){
  1302.     return brh->status;
  1303.  }else{
  1304.     brh->iter = stats.iter[iTOTAL];
  1305.  }
  1306.  error(bWARNING, "%s: no transmission line in dc or transient\n",
  1307.          printlabel(brh,NO));
  1308.  return brh->status = NO;
  1309. }
  1310. /*--------------------------------------------------------------------------*/
  1311. /* ac_trnlin:  transmission line procesing for AC analysis
  1312.  */
  1313. static void ac_trnlin(brh)
  1314. branch_t *brh;
  1315. {
  1316.  double y11, y12;    /* equivalent y parameters (y22, y21 are same)        */
  1317.  double lenth;        /* length, first in quarter waves, then radians        */
  1318.  double dif;        /* difference between actual length and resonance   */
  1319.  struct trnlin *x;
  1320.  
  1321.  x = (struct trnlin*)brh->x;
  1322.  
  1323.  lenth = ac.freq / x->reson;
  1324.  dif = lenth - floor(lenth+.5);
  1325.  if (fabs(dif) < LINLENTOL){                            
  1326.     error(bPICKY,
  1327.       "%s: transmission line too close to resonance\n", printlabel(brh,NO));
  1328.     lenth = (dif<0.) ? floor(lenth+.5)-LINLENTOL : floor(lenth+.5)+LINLENTOL;
  1329.  }
  1330.  lenth *= (PId2);                      /* now in radians */
  1331.  
  1332.  y12 = -1 / ( x->z0 * sin(lenth) );
  1333.  y11 = tan(lenth/2) / x->z0 + y12;
  1334.  
  1335.  *im(brh->n[OUT1].m,brh->n[OUT1].m) += y11;
  1336.  *im(brh->n[OUT2].m,brh->n[OUT2].m) += y11;
  1337.  *im(brh->n[OUT1].m,brh->n[OUT2].m) -= y11;
  1338.  *im(brh->n[OUT2].m,brh->n[OUT1].m) -= y11;
  1339.  
  1340.  *im(brh->n[IN1].m,brh->n[IN1].m) += y11;
  1341.  *im(brh->n[IN2].m,brh->n[IN2].m) += y11;
  1342.  *im(brh->n[IN1].m,brh->n[IN2].m) -= y11;
  1343.  *im(brh->n[IN2].m,brh->n[IN1].m) -= y11;
  1344.  
  1345.  *im(brh->n[OUT1].m,brh->n[IN1].m) -= y12;
  1346.  *im(brh->n[OUT2].m,brh->n[IN2].m) -= y12;
  1347.  *im(brh->n[OUT1].m,brh->n[IN2].m) += y12;
  1348.  *im(brh->n[OUT2].m,brh->n[IN1].m) += y12;
  1349.  
  1350.  *im(brh->n[IN1].m,brh->n[OUT1].m) -= y12;
  1351.  *im(brh->n[IN2].m,brh->n[OUT2].m) -= y12;
  1352.  *im(brh->n[IN1].m,brh->n[OUT2].m) += y12;
  1353.  *im(brh->n[IN2].m,brh->n[OUT1].m) += y12;
  1354. }
  1355. /*--------------------------------------------------------------------------*/
  1356. /*--------------------------------------------------------------------------*/
  1357. SHAR_EOF
  1358. fi # end of overwriting check
  1359. if test -f 'src/d_vccs.c'
  1360. then
  1361.     echo shar: will not over-write existing file "'src/d_vccs.c'"
  1362. else
  1363. cat << \SHAR_EOF > 'src/d_vccs.c'
  1364. /* dev_vccs  12/30/92
  1365.  * Copyright 1983-1992   Albert Davis
  1366.  * functions for vccs
  1367.  */
  1368. #include "ecah.h"
  1369. #include "branch.h"
  1370. #include "mode.h"
  1371. #include "status.h"
  1372. #include "declare.h"
  1373. /*--------------------------------------------------------------------------*/
  1374. static     branch_t *create_vccs(const branch_t*);
  1375. static     void    parse_vccs(branch_t*,const char*,int*);
  1376. static     void    print_vccs(const branch_t*,int,int);
  1377. static    double    trprobe_vccs(const branch_t*,const char*);
  1378. static    double    acprobe_vccs(const branch_t*,const char*);
  1379. static     int    tr_vccs(branch_t*);
  1380. static     void    un_vccs(branch_t*);
  1381. static     void    ac_vccs(branch_t*);
  1382. /*--------------------------------------------------------------------------*/
  1383. functions_t dev_vccs = {
  1384.    sizeof(branch_t),
  1385.    create_vccs,
  1386.    parse_vccs,
  1387.    print_vccs,
  1388.    (void(*)())NULL,    /* expand */
  1389.    trprobe_vccs,
  1390.    acprobe_vccs,
  1391.    tr_vccs,
  1392.    un_vccs,
  1393.    ac_vccs,
  1394.    trfix1,
  1395.    trfix0,
  1396.    acfix,
  1397.    (void(*)())NULL,    /* tr_guess */
  1398.    (void(*)())NULL,    /* tr_advance */
  1399.    (double(*)())NULL    /* tr_review */
  1400. };
  1401. /*--------------------------------------------------------------------------*/
  1402. extern const struct status stats;
  1403. /*--------------------------------------------------------------------------*/
  1404. static branch_t *create_vccs(proto)
  1405. const branch_t *proto;
  1406. {
  1407.  return createbranch(proto,(generic_t*)NULL,&dev_vccs);
  1408. }
  1409. /*--------------------------------------------------------------------------*/
  1410. static void parse_vccs(brh,cmd,cnt)
  1411. branch_t *brh;
  1412. const char *cmd;
  1413. int *cnt;
  1414. {
  1415.  parsegeneric(brh,cmd,cnt,4);
  1416. }
  1417. /*--------------------------------------------------------------------------*/
  1418. static void print_vccs(brh,where,detail)
  1419. const branch_t *brh;
  1420. int where;
  1421. int detail;
  1422. {
  1423.  printgeneric(brh,where,detail);
  1424. }
  1425. /*--------------------------------------------------------------------------*/
  1426. static double trprobe_vccs(brh,what)
  1427. const branch_t *brh;
  1428. const char *what;
  1429. {
  1430.  return trprobegeneric(brh,what);
  1431. }
  1432. /*--------------------------------------------------------------------------*/
  1433. static double acprobe_vccs(brh,what)
  1434. const branch_t *brh;
  1435. const char *what;
  1436. {
  1437.  return acprobegeneric(brh,what);
  1438. }
  1439. /*--------------------------------------------------------------------------*/
  1440. static int tr_vccs(brh)
  1441. branch_t *brh;
  1442. {
  1443.  if (brh->iter == stats.iter[iTOTAL]){
  1444.     return brh->status;
  1445.  }else{
  1446.     brh->iter = stats.iter[iTOTAL];
  1447.  }
  1448.  trsetup(brh);
  1449.  brh->m0.x = tr_volts_limited(brh->n[IN1],brh->n[IN2]);
  1450.  brh->y0.x = brh->m0.x;
  1451.  if (brh->f->trfun1){
  1452.     (*brh->f->trfun1)(brh);
  1453.  }else{
  1454.     brh->y0.f1 = brh->val;
  1455.     brh->y0.f0 = LINEAR;
  1456.  }
  1457.  brh->ev = brh->y0.f1;
  1458.  brh->m0.x  = brh->y0.x;
  1459.  brh->m0.c0 = brh->y0.f0 - brh->y0.x * brh->y0.f1;
  1460.  brh->m0.f1 = brh->y0.f1;
  1461.  trloadactive(brh);
  1462.  return brh->status = conv_check(brh);
  1463. }
  1464. /*--------------------------------------------------------------------------*/
  1465. static void un_vccs(brh)
  1466. branch_t *brh;
  1467. {
  1468.  unloadactive(brh);
  1469. }
  1470. /*--------------------------------------------------------------------------*/
  1471. static void ac_vccs(brh)
  1472. branch_t *brh;
  1473. {
  1474.  if (brh->f->acfun){
  1475.     brh->acbias = dc_volts(brh->n[IN1],brh->n[IN2]);
  1476.     brh->acg = (*brh->f->acfun)(brh);
  1477.  }else{
  1478.     brh->acg.x = brh->ev;
  1479.     brh->acg.y = 0.;
  1480.  }
  1481.  acloadactive(brh);
  1482. }
  1483. /*--------------------------------------------------------------------------*/
  1484. /*--------------------------------------------------------------------------*/
  1485. SHAR_EOF
  1486. fi # end of overwriting check
  1487. if test -f 'src/d_vcvs.c'
  1488. then
  1489.     echo shar: will not over-write existing file "'src/d_vcvs.c'"
  1490. else
  1491. cat << \SHAR_EOF > 'src/d_vcvs.c'
  1492. /* dev_vcvs  12/30/92
  1493.  * Copyright 1983-1992   Albert Davis
  1494.  * functions for vcvs
  1495.  * temporary kluge: it has resistance
  1496.  * BUG: doesn't work in incmode
  1497.  */
  1498. #include "ecah.h"
  1499. #include "branch.h"
  1500. #include "mode.h"
  1501. #include "options.h"
  1502. #include "status.h"
  1503. #include "declare.h"
  1504. /*--------------------------------------------------------------------------*/
  1505. static     branch_t    *create_vcvs(const branch_t*);
  1506. static     void    parse_vcvs(branch_t*,const char*,int*);
  1507. static     void    print_vcvs(const branch_t*,int,int);
  1508. static    double    trprobe_vcvs(const branch_t*,const char*);
  1509. static    double    acprobe_vcvs(const branch_t*,const char*);
  1510. static     int    tr_vcvs(branch_t*);
  1511. static    void    un_vcvs(branch_t*);
  1512. static    void    ac_vcvs(branch_t*);
  1513. /*--------------------------------------------------------------------------*/
  1514. functions_t dev_vcvs = {
  1515.    sizeof(branch_t),
  1516.    create_vcvs,
  1517.    parse_vcvs,
  1518.    print_vcvs,
  1519.    (void(*)())NULL,    /* expand */
  1520.    trprobe_vcvs,
  1521.    acprobe_vcvs,
  1522.    tr_vcvs,
  1523.    un_vcvs,
  1524.    ac_vcvs,
  1525.    trfix1,
  1526.    trfix0,
  1527.    acfix,
  1528.    (void(*)())NULL,    /* tr_guess */
  1529.    (void(*)())NULL,    /* tr_advance */
  1530.    (double(*)())NULL    /* tr_review */
  1531. };
  1532. /*--------------------------------------------------------------------------*/
  1533. extern const struct options opt;
  1534. extern const struct status stats;
  1535. static branch_t resistor = {(generic_t*)NULL, sizeof(branch_t),
  1536.     (functions_t*)NULL, (branch_t*)NULL, (branch_t*)NULL, (branch_t*)NULL,
  1537.     (branch_t*)NULL, /*more*/};
  1538. /*--------------------------------------------------------------------------*/
  1539. static branch_t *create_vcvs(proto)
  1540. const branch_t *proto;
  1541. {
  1542.  return createbranch(proto,(generic_t*)NULL,&dev_vcvs);
  1543. }
  1544. /*--------------------------------------------------------------------------*/
  1545. static void parse_vcvs(brh,cmd,cnt)
  1546. branch_t *brh;
  1547. const char *cmd;
  1548. int *cnt;
  1549. {
  1550.  parsegeneric(brh,cmd,cnt,4);
  1551. }
  1552. /*--------------------------------------------------------------------------*/
  1553. static void print_vcvs(brh,where,detail)
  1554. const branch_t *brh;
  1555. int where;
  1556. int detail;
  1557. {
  1558.  printgeneric(brh,where,detail);
  1559. }
  1560. /*--------------------------------------------------------------------------*/
  1561. static double trprobe_vcvs(brh,what)
  1562. const branch_t *brh;
  1563. const char *what;
  1564. {
  1565.  return trprobegeneric(brh,what);
  1566. }
  1567. /*--------------------------------------------------------------------------*/
  1568. static double acprobe_vcvs(brh,what)
  1569. const branch_t *brh;
  1570. const char *what;
  1571. {
  1572.  return acprobegeneric(brh,what);
  1573. }
  1574. /*--------------------------------------------------------------------------*/
  1575. static int tr_vcvs(brh)
  1576. branch_t *brh;
  1577. {
  1578.  if (brh->iter == stats.iter[iTOTAL]){
  1579.     return brh->status;
  1580.  }else{
  1581.     brh->iter = stats.iter[iTOTAL];
  1582.  }
  1583.  trsetup(brh);
  1584.  
  1585.  resistor.n = brh->n;
  1586.  resistor.loaditer = 0;
  1587.  resistor.y0.f1 = 1./opt.shortckt;        /* load the resistor */
  1588.  resistor.y0.f0 = LINEAR;            /* a big fudge */
  1589.  resistor.m0.x  = resistor.y0.x;
  1590.  resistor.m0.c0 = 0.;
  1591.  resistor.m0.f1 = resistor.y0.f1;
  1592.  trloadpassive(&resistor);
  1593.  
  1594.                         /* then do vccs */
  1595.  brh->m0.x = tr_volts_limited(brh->n[IN1],brh->n[IN2]);
  1596.  brh->y0.x = brh->m0.x;
  1597.  if (brh->f->trfun1){
  1598.     (*brh->f->trfun1)(brh);
  1599.  }else{
  1600.     brh->y0.f1 = brh->val;
  1601.     brh->y0.f0 = LINEAR;
  1602.  }
  1603.  brh->ev = brh->y0.f1;
  1604.  brh->m0.f1 = brh->y0.f1 / -opt.shortckt;
  1605.  brh->m0.c0 = (brh->y0.f0 - brh->y0.x * brh->y0.f1) / -opt.shortckt;
  1606.  trloadactive(brh);
  1607.  return brh->status = conv_check(brh);
  1608. }
  1609. /*--------------------------------------------------------------------------*/
  1610. static void un_vcvs(brh)
  1611. branch_t *brh;
  1612. {
  1613.  unloadactive(brh);
  1614. }
  1615. /*--------------------------------------------------------------------------*/
  1616. static void ac_vcvs(brh)
  1617. branch_t *brh;
  1618. {
  1619.  brh->acg.x = 1./opt.shortckt;
  1620.  brh->acg.y = 0.;
  1621.  acloadpassivereal(brh);
  1622.  
  1623.  if (brh->f->acfun){
  1624.     brh->acbias = dc_volts(brh->n[IN1],brh->n[IN2]);
  1625.     brh->acg = (*brh->f->acfun)(brh);
  1626.     brh->acg.x /= -opt.shortckt;
  1627.     brh->acg.y /= -opt.shortckt;
  1628.  }else{
  1629.     brh->acg.x = brh->ev / -opt.shortckt;
  1630.     brh->acg.y = 0.;
  1631.  }
  1632.  acloadactive(brh);
  1633. }
  1634. /*--------------------------------------------------------------------------*/
  1635. /*--------------------------------------------------------------------------*/
  1636. SHAR_EOF
  1637. fi # end of overwriting check
  1638. if test -f 'src/d_vs.c'
  1639. then
  1640.     echo shar: will not over-write existing file "'src/d_vs.c'"
  1641. else
  1642. cat << \SHAR_EOF > 'src/d_vs.c'
  1643. /* dev_vs.c  12/30/92
  1644.  * Copyright 1983-1992   Albert Davis
  1645.  * functions for fixed voltage sources
  1646.  * temporary kluge: it has resistance
  1647.  */
  1648. #include "ecah.h"
  1649. #include "branch.h"
  1650. #include "mode.h"
  1651. #include "options.h"
  1652. #include "status.h"
  1653. #include "declare.h"
  1654. /*--------------------------------------------------------------------------*/
  1655. static     branch_t *create_vs(const branch_t*);
  1656. static     void    parse_vs(branch_t*,const char*,int*);
  1657. static     void    print_vs(const branch_t*,int,int);
  1658. static    double    trprobe_vs(const branch_t*,const char*);
  1659. static    double    acprobe_vs(const branch_t*,const char*);
  1660. static     int    tr_vs(branch_t*);
  1661. static     void    un_vs(branch_t*);
  1662. static     void    ac_vs(branch_t*);
  1663. /*--------------------------------------------------------------------------*/
  1664. functions_t dev_vs = {
  1665.    sizeof(branch_t),
  1666.    create_vs,
  1667.    parse_vs,
  1668.    print_vs,
  1669.    (void(*)())NULL,    /* expand */
  1670.    trprobe_vs,
  1671.    acprobe_vs,
  1672.    tr_vs,
  1673.    un_vs,
  1674.    ac_vs,
  1675.    trfix1,
  1676.    trfix0,
  1677.    acfix,
  1678.    (void(*)())NULL,    /* tr_guess */
  1679.    (void(*)())NULL,    /* tr_advance */
  1680.    (double(*)())NULL    /* tr_review */
  1681. };
  1682. /*--------------------------------------------------------------------------*/
  1683. extern const struct options opt;
  1684. extern const struct status stats;
  1685. /*--------------------------------------------------------------------------*/
  1686. static branch_t *create_vs(proto)
  1687. const branch_t *proto;
  1688. {
  1689.  return createbranch(proto,(generic_t*)NULL,&dev_vs);
  1690. }
  1691. /*--------------------------------------------------------------------------*/
  1692. static void parse_vs(brh,cmd,cnt)
  1693. branch_t *brh;
  1694. const char *cmd;
  1695. int *cnt;
  1696. {
  1697.  parsegeneric(brh,cmd,cnt,2);
  1698. }
  1699. /*--------------------------------------------------------------------------*/
  1700. static void print_vs(brh,where,detail)
  1701. const branch_t *brh;
  1702. int where;
  1703. int detail;
  1704. {
  1705.  printgeneric(brh,where,detail);
  1706. }
  1707. /*--------------------------------------------------------------------------*/
  1708. static double trprobe_vs(brh,what)
  1709. const branch_t *brh;
  1710. const char *what;
  1711. {
  1712.  return trprobegeneric(brh,what);
  1713. }
  1714. /*--------------------------------------------------------------------------*/
  1715. static double acprobe_vs(brh,what)
  1716. const branch_t *brh;
  1717. const char *what;
  1718. {
  1719.  return acprobegeneric(brh,what);
  1720. }
  1721. /*--------------------------------------------------------------------------*/
  1722. static int tr_vs(brh)
  1723. branch_t *brh;
  1724. {
  1725.  if (brh->iter == stats.iter[iTOTAL]){
  1726.     return brh->status;
  1727.  }else{
  1728.     brh->iter = stats.iter[iTOTAL];
  1729.  }
  1730.  trsetup(brh);
  1731.  brh->m0.x = 0.;
  1732.  brh->y0.x = 0.;
  1733.  if (brh->f->trfun1){
  1734.     (*brh->f->trfun1)(brh);
  1735.  }else{
  1736.     brh->y0.f1 = brh->val;
  1737.     brh->y0.f0 = 0.;
  1738.  }
  1739.  brh->ev = brh->y0.f1;
  1740.  brh->m0.f1 = 1./opt.shortckt;
  1741.  brh->m0.c0 = brh->y0.f1 / -opt.shortckt;
  1742.  
  1743.  trloadpassive(brh);
  1744.  return brh->status = conv_check(brh);
  1745. }
  1746. /*--------------------------------------------------------------------------*/
  1747. static void un_vs(brh)
  1748. branch_t *brh;
  1749. {
  1750.  unloadpassive(brh);
  1751. }
  1752. /*--------------------------------------------------------------------------*/
  1753. static void ac_vs(brh)
  1754. branch_t *brh;
  1755. {
  1756.  brh->acg.x = 1./opt.shortckt;
  1757.  brh->acg.y = 0.;
  1758.  acloadpassivereal(brh);
  1759.  
  1760.  if (brh->f->acfun){
  1761.     brh->acbias = 0.;
  1762.     brh->acg = (*brh->f->acfun)(brh);
  1763.     brh->acg.x /= -opt.shortckt;
  1764.     brh->acg.y /= -opt.shortckt;
  1765.  }else{
  1766.     brh->acg.x = brh->ev / -opt.shortckt;
  1767.     brh->acg.y = 0.;
  1768.  }
  1769.  acloadsource(brh);
  1770. }
  1771. /*--------------------------------------------------------------------------*/
  1772. /*--------------------------------------------------------------------------*/
  1773. SHAR_EOF
  1774. fi # end of overwriting check
  1775. #    End of shell archive
  1776. exit 0
  1777.