home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / sources / 3110 < prev    next >
Encoding:
Text File  |  1993-01-28  |  49.2 KB  |  1,714 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 12/20
  5. Message-ID: <1993Jan27.040747.11522@rbc.uucp>
  6. Date: 27 Jan 93 04:07:47 GMT
  7. Sender: al@rbc.uucp (Al Davis)
  8. Organization: Huh?
  9. Lines: 1703
  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_bjt.c
  17. #    src/d_cap.c
  18. #    src/d_coil.c
  19. #    src/d_coment.c
  20. #    src/d_cs.c
  21. #    src/d_diode.c
  22. #    src/d_dot.c
  23. # This archive created: Tue Jan 26 22:51:02 1993
  24. export PATH; PATH=/bin:$PATH
  25. if test -f 'src/d_bjt.c'
  26. then
  27.     echo shar: will not over-write existing file "'src/d_bjt.c'"
  28. else
  29. cat << \SHAR_EOF > 'src/d_bjt.c'
  30. /* dev_bjt.c  12/30/92
  31.  * Copyright 1983-1992   Albert Davis
  32.  * bjt model.
  33.  * this is not really a bjt, but a diode
  34.  * It exists only as a frame.  Don't use it!!!!
  35.  * netlist syntax:
  36.  * device:  qxxxx n+ n- mname <area> <off> <ic=vd> <model-card-args>
  37.  * model:   .model mname D <args>
  38.  */
  39. #include "ecah.h"
  40. #include "argparse.h"
  41. #include "branch.h"
  42. #include "d_bjt.h"
  43. #include "d_diode.h"
  44. #include "error.h"
  45. #include "mode.h"
  46. #include "status.h"
  47. #include "types.h"
  48. #include "declare.h"
  49. /*--------------------------------------------------------------------------*/
  50. static     branch_t    *create_bjt(const branch_t*);
  51. static     void    parse_bjt(branch_t*,const char*,int*);
  52. static     void    print_bjt(const branch_t*,int,int);
  53. static    branch_t    *create_model_bjt(const branch_t*);
  54. static     void    parse_model_bjt(branch_t*,const char*,int*);
  55. static     void    print_model_bjt(const branch_t*,int,int);
  56. static     void    expand_bjt(branch_t*);
  57. static    double    trprobe_bjt(const branch_t*,const char*);
  58. static     int    tr_bjt(branch_t*);
  59. static     void    ac_bjt(branch_t*);
  60. static    void    evalbjt(branch_t*);
  61. static    void    bjtcap(branch_t*);
  62. /*--------------------------------------------------------------------------*/
  63. functions_t dev_bjt = {
  64.    sizeof(branch_t),
  65.    create_bjt,
  66.    parse_bjt,
  67.    print_bjt,
  68.    expand_bjt,
  69.    trprobe_bjt,
  70.    (double(*)())NULL,
  71.    tr_bjt,
  72.    (void(*)())NULL,
  73.    ac_bjt,
  74.    (void(*)())NULL,
  75.    (void(*)())NULL,
  76.    (complex_t(*)())NULL,
  77.    (void(*)())NULL,    /* tr_guess */
  78.    (void(*)())NULL,    /* tr_advance */
  79.    (double(*)())NULL    /* tr_review */
  80. };
  81. functions_t model_bjt = {
  82.    sizeof(branch_t),
  83.    create_model_bjt,
  84.    parse_model_bjt,
  85.    print_model_bjt,
  86.    (void(*)())NULL,
  87.    trprobe_bjt,
  88.    (double(*)())NULL,
  89.    (int(*)())NULL,
  90.    (void(*)())NULL,
  91.    (void(*)())NULL,
  92.    (void(*)())NULL,
  93.    (void(*)())NULL,
  94.    (complex_t(*)())NULL,
  95.    (void(*)())NULL,    /* tr_guess */
  96.    (void(*)())NULL,    /* tr_advance */
  97.    (double(*)())NULL    /* tr_review */
  98. };
  99. /*--------------------------------------------------------------------------*/
  100. extern const struct status stats;
  101. static struct bjt *x;
  102.  
  103. static struct bjt defalt = {(generic_t*)NULL, sizeof(struct bjt),
  104.     (struct qmod*)NULL, qDEFDEV_modelname, qDEFDEV_is, qDEFDEV_rs,
  105.     qDEFDEV_cj, qDEFDEV_cjsw, qDEFDEV_area, qDEFDEV_perim,
  106.     qDEFDEV_ic, qDEFDEV_off};
  107. static struct qmod defaltmodel = {(generic_t*)NULL, sizeof(struct qmod),
  108.     qDEFMOD_js, qDEFMOD_rs, qDEFMOD_n, qDEFMOD_tt, qDEFMOD_cj,
  109.     qDEFMOD_pb, qDEFMOD_mj, qDEFMOD_eg, qDEFMOD_xti, qDEFMOD_kf,
  110.     qDEFMOD_af, qDEFMOD_fc, qDEFMOD_bv, qDEFMOD_ibv, qDEFMOD_cjsw,
  111.     qDEFMOD_mjsw, qDEFMOD_fcpb};
  112. static branch_t modellist = {(generic_t*)&defaltmodel, sizeof(branch_t),
  113.     &model_bjt, &modellist, &modellist, &modellist, &modellist,
  114.     (branch_t*)NULL, (branch_t*)NULL, qDEFMOD_modelname, /* more */};
  115. /*--------------------------------------------------------------------------*/
  116. static branch_t *create_bjt(proto)
  117. const branch_t *proto;
  118. {
  119.  return createbranch(proto,(generic_t*)&defalt,&dev_bjt);
  120. }
  121. /*--------------------------------------------------------------------------*/
  122. static void parse_bjt(brh,cmd,cnt)
  123. branch_t *brh;
  124. const char *cmd;
  125. int *cnt;
  126. {
  127.  struct bjt *x;
  128.  
  129.  x = (struct bjt*)brh->x;
  130.  
  131.  parselabel(brh,cmd,cnt);
  132.  (void)parsenodes(brh,cmd,cnt,2);
  133.  (void)ctostr(cmd, cnt, x->modelname, LABELEN);
  134.  x->m = (struct qmod*)NULL;
  135.  if (isdigit(cmd[*cnt])  ||  cmd[*cnt] == '.')
  136.     x->area = fabs(ctof(cmd,cnt));
  137.  for (;;){
  138.     if (argparse(cmd,cnt,REPEAT,
  139.     "Area",    aUDOUBLE,    &x->area,
  140.     "Perim",aUDOUBLE,    &x->perim,
  141.     "IC",    aDOUBLE,    &x->ic,
  142.     "OFF",    aENUM,        &x->off,    YES,
  143.     "IS",    aUDOUBLE,    &x->is,
  144.     "Rs",    aUDOUBLE,    &x->rs,
  145.     "Cjo",    aUDOUBLE,    &x->cj,
  146.     "CJSW",    aUDOUBLE,    &x->cjsw,
  147.     ""))
  148.     ;
  149.     else{
  150.        syntax(cmd,cnt,bWARNING);
  151.        break;
  152.     }
  153.  }
  154. }
  155. /*--------------------------------------------------------------------------*/
  156. static void print_bjt(brh,where,detail)
  157. const branch_t *brh;
  158. int where;
  159. int detail;
  160. {
  161.  struct bjt *x;
  162.  
  163.  x = (struct bjt*)brh->x;
  164.  
  165.  (void)printlabel(brh,where);
  166.  printnodes(brh,where);
  167.  mprintf(where, " %s ", x->modelname);
  168.  
  169.     mprintf(where,    " %s ", ftos(x->area,"", 7, 0));
  170.  if (x->perim != 0.)
  171.     mprintf(where,"perim=%s ",ftos(x->perim,"", 7, 0));
  172.  if (x->off)
  173.     mprintf(where, " off ");
  174.  if (x->ic != NOT_INPUT)
  175.     mprintf(where, " ic=%s ", ftos(x->ic,  "", 7, 0));
  176.  if (!x->calc.is  &&  x->is != NOT_INPUT)
  177.     mprintf(where, " is=%s ", ftos(x->is,  "", 7, 0));
  178.  if (!x->calc.rs  &&  x->rs != NOT_INPUT)
  179.     mprintf(where, " rs=%s ", ftos(x->rs,  "", 7, 0));
  180.  if (!x->calc.cj  &&  x->cj != NOT_INPUT)
  181.     mprintf(where, " cj=%s ", ftos(x->cj,  "", 7, 0));
  182.  if (!x->calc.cjsw  &&  x->cjsw != NOT_INPUT)
  183.     mprintf(where, " cjsw=%s ",ftos(x->cjsw,"", 7, 0));
  184.  if (x->calc.is  &&  x->calc.rs  &&  x->calc.cj  &&  x->calc.cjsw)
  185.     mprintf(where, "\n*+");
  186.  if (x->calc.is  &&  x->is != NOT_INPUT)
  187.     mprintf(where, " is=%s ", ftos(x->is,  "", 7, 0));
  188.  if (x->calc.rs  &&  x->rs != NOT_INPUT)
  189.     mprintf(where, " rs=%s ", ftos(x->rs,  "", 7, 0));
  190.  if (x->calc.cj  &&  x->cj != NOT_INPUT)
  191.     mprintf(where, " cj=%s ", ftos(x->cj,  "", 7, 0));
  192.  if (x->calc.cjsw  &&  x->cjsw != NOT_INPUT)
  193.     mprintf(where, " cjsw=%s ",ftos(x->cjsw,"", 7, 0));
  194.  mprintf(where, "\n");
  195. }
  196. /*--------------------------------------------------------------------------*/
  197. static branch_t *create_model_bjt(proto)
  198. const branch_t *proto;
  199. {
  200.  branch_t *brh;
  201.  
  202.  brh = createbranch(proto,(generic_t*)&defaltmodel,&model_bjt);
  203.  brh->stprev = &modellist;
  204.  return brh;
  205. }
  206. /*--------------------------------------------------------------------------*/
  207. static void parse_model_bjt(brh,cmd,cnt)
  208. branch_t *brh;
  209. const char *cmd;
  210. int *cnt;
  211. {
  212.  struct qmod *m;
  213.  
  214.  m = (struct qmod*)brh->x;
  215.  
  216.  (void)ctostr(cmd, cnt, brh->label, LABELEN);
  217.  skiparg(cmd,cnt);    /* skip known "d" */
  218.  
  219.  for (;;){
  220.     if (argparse(cmd,cnt,REPEAT,
  221.     "IS",    aUDOUBLE,    &m->js,
  222.     "RS",    aUDOUBLE,    &m->rs,
  223.     "N",    aUDOUBLE,    &m->n,
  224.     "TT",    aUDOUBLE,    &m->tt,
  225.     "CJo",    aUDOUBLE,    &m->cj,
  226.     "VJ",    aUDOUBLE,    &m->pb,
  227.     "PB",    aUDOUBLE,    &m->pb,
  228.     "Mj",    aUDOUBLE,    &m->mj,
  229.     "EGap",    aUDOUBLE,    &m->eg,
  230.      ""))
  231.        ;
  232.     else if (argparse(cmd,cnt,REPEAT,
  233.     "XTI",    aUDOUBLE,    &m->xti,
  234.     "KF",    aUDOUBLE,    &m->kf,
  235.     "AF",    aUDOUBLE,    &m->af,
  236.     "FC",    aUDOUBLE,    &m->fc,
  237.     "BV",    aUDOUBLE,    &m->bv,
  238.     "IBV",    aUDOUBLE,    &m->ibv,
  239.     "CJSw",    aUDOUBLE,    &m->cjsw,
  240.     "MJSw",    aUDOUBLE,    &m->mjsw,
  241.     ""))
  242.     ;
  243.     else{
  244.        syntax(cmd,cnt,bWARNING);
  245.        break;
  246.     }
  247.  }
  248.  m->fcpb = m->fc * m->pb;
  249.  if (m->tt != 0.)
  250.     error(bWARNING, "%s: tt not implemented\n", printlabel(brh,NO));
  251. }
  252. /*--------------------------------------------------------------------------*/
  253. static void print_model_bjt(brh,where,detail)
  254. const branch_t *brh;
  255. int where;
  256. int detail;
  257. {
  258.  struct qmod *m;
  259.  m = (struct qmod*)brh->x;
  260.  
  261.  mprintf(where, ".model  %s  d  (", brh->label);
  262.  mprintf(where, " is=%s ",  ftos(m->js,  "", 7, 0));
  263.  mprintf(where, " rs=%s ",  ftos(m->rs,  "", 7, 0));
  264.  mprintf(where, " n=%s ",   ftos(m->n,   "", 7, 0));
  265.  mprintf(where, " tt=%s ",  ftos(m->tt,  "", 7, 0));
  266.  mprintf(where, " cjo=%s ", ftos(m->cj, "", 7, 0));
  267.  mprintf(where, " vj=%s ",  ftos(m->pb,  "", 7, 0));
  268.  mprintf(where, " m=%s ",   ftos(m->mj,   "", 7, 0));
  269.  mprintf(where, " eg=%s ",  ftos(m->eg,  "", 7, 0));
  270.  mprintf(where, " xti=%s ", ftos(m->xti, "", 7, 0));
  271.  mprintf(where, " kf=%s ",  ftos(m->kf,  "", 7, 0));
  272.  mprintf(where, " af=%s ",  ftos(m->af,  "", 7, 0));
  273.  mprintf(where, " fc=%s ",  ftos(m->fc,  "", 7, 0));
  274.  mprintf(where, " bv=%s ",  ftos(m->bv,  "", 7, 0));
  275.  mprintf(where, " ibv=%s ", ftos(m->ibv, "", 7, 0));
  276.  if (m->cjsw != 0.){
  277.     mprintf(where, " cjsw=%s ", ftos(m->cjsw,"", 7, 0));
  278.     mprintf(where, " mjsw=%s ", ftos(m->mjsw,"", 7, 0));
  279.  }
  280.  mprintf(where, ")\n");
  281. }
  282. /*--------------------------------------------------------------------------*/
  283. static void expand_bjt(brh)
  284. branch_t *brh;
  285. {
  286.  const struct qmod *m;
  287.  struct bjt *x;
  288.  branch_t *scratch;
  289.  
  290.  expandgeneric(brh,&modellist);
  291.  x = (struct bjt*)brh->x;
  292.  m = x->m;
  293.  
  294.  if (x->calc.is  ||  x->is == NOT_INPUT){        /* calculate parameters */
  295.     x->is = m->js * x->area;
  296.     x->calc.is = YES;
  297.  }
  298.  if (x->calc.rs  ||  x->rs == NOT_INPUT){
  299.     x->rs = m->rs * x->area;
  300.     x->calc.rs = YES;
  301.  }
  302.  if (x->calc.cj  ||  x->cj == NOT_INPUT){
  303.     x->cj = m->cj * x->area;
  304.     x->calc.cj = YES;
  305.  }
  306.  if (x->calc.cjsw  ||  x->cjsw == NOT_INPUT){
  307.     x->cjsw = m->cjsw * x->perim;
  308.     x->calc.cjsw = YES;
  309.  }
  310.  
  311.                                 /* build subckt */
  312.  if (x->cj != 0.  ||  x->cjsw != 0.){
  313.     scratch = (*(dev_cap.create))((branch_t*)NULL);
  314.     scratch->parent = brh;
  315.     {functions_t *ff;
  316.      ff = (functions_t*)calloc(1, sizeof(functions_t));
  317.      *ff = *(scratch->f);
  318.      ff->expand = (void(*)())NULL;
  319.      ff->trfun1 = bjtcap;
  320.      ff->acfun = (complex_t(*)())NULL;
  321.      scratch->f = ff;}
  322.     strcpy(scratch->label,"Cj");
  323.     scratch->n[OUT1].t = brh->n[OUT1].t;
  324.     scratch->n[OUT2].t = brh->n[OUT2].t;
  325.     scratch->next = brh->subckt;
  326.     brh->subckt = insertbranch(scratch);
  327.  }
  328.  
  329.  scratch = (*(dev_admittance.create))((branch_t*)NULL);
  330.  scratch->parent = brh;
  331.  {functions_t *ff;
  332.   ff = (functions_t*)calloc(1, sizeof(functions_t));
  333.   *ff = *(scratch->f);
  334.   ff->expand = (void(*)())NULL;
  335.   ff->trfun1 = evalbjt;
  336.   ff->acfun = (complex_t(*)())NULL;
  337.   scratch->f = ff;}
  338.  strcpy(scratch->label,"Yj");
  339.  scratch->n[OUT1].t = brh->n[OUT1].t;
  340.  scratch->n[OUT2].t = brh->n[OUT2].t;
  341.  scratch->next = brh->subckt;
  342.  brh->subckt = insertbranch(scratch);
  343. }
  344. /*--------------------------------------------------------------------------*/
  345. static double trprobe_bjt(brh,what)
  346. const branch_t *brh;
  347. const char *what;
  348. {
  349.  return NOT_VALID;
  350. }
  351. /*--------------------------------------------------------------------------*/
  352. static int tr_bjt(brh)
  353. branch_t *brh;
  354. {
  355.  if (brh->iter == stats.iter[iTOTAL]){
  356.     return brh->status;
  357.  }else{
  358.     brh->iter = stats.iter[iTOTAL];
  359.  }
  360.  x = (struct bjt*)brh->x;
  361.  if (!x->m)
  362.     error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
  363.  return brh->status = tr_fill_rl(brh->subckt);
  364. }
  365. /*--------------------------------------------------------------------------*/
  366. static void ac_bjt(brh)
  367. branch_t *brh;
  368. {
  369.  x = (struct bjt*)brh->x;
  370.  if (!x->m)
  371.     error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
  372.  ac_fill_rl(brh->subckt);
  373. }
  374. /*--------------------------------------------------------------------------*/
  375. static void evalbjt(brh)
  376. branch_t *brh;
  377. {;}
  378. /*--------------------------------------------------------------------------*/
  379. static void bjtcap(brh)
  380. branch_t *brh;
  381. {;}
  382. /*--------------------------------------------------------------------------*/
  383. /*--------------------------------------------------------------------------*/
  384. SHAR_EOF
  385. fi # end of overwriting check
  386. if test -f 'src/d_cap.c'
  387. then
  388.     echo shar: will not over-write existing file "'src/d_cap.c'"
  389. else
  390. cat << \SHAR_EOF > 'src/d_cap.c'
  391. /* dev_cap.c  12/30/92
  392.  * Copyright 1983-1992   Albert Davis
  393.  * capacitor models
  394.  * two levels: linear (lin) and nonlinear (nl)
  395.  * y.x = volts, y.f0 = coulombs, ev = y.f1 = farads
  396.  */
  397. #include "ecah.h"
  398. #include "ac.h"
  399. #include "branch.h"
  400. #include "convstat.h"
  401. #include "error.h"
  402. #include "mode.h"
  403. #include "options.h"
  404. #include "status.h"
  405. #include "declare.h"
  406. /*--------------------------------------------------------------------------*/
  407. static     branch_t *create_cap(const branch_t*);
  408. static     void    parse_cap(branch_t*,const char*,int*);
  409. static     void    print_cap(const branch_t*,int,int);
  410. static    void    expand_cap(branch_t*);
  411. static    double    trprobe_cap(const branch_t*,const char*);
  412. static    double    acprobe_cap(const branch_t*,const char*);
  413. static     int    tr_cap_lin(branch_t*);
  414. static     int    tr_cap_nl(branch_t*);
  415. static    void    un_cap(branch_t*);
  416. static    void    integrate(branch_t*);
  417. static     void    ac_cap_lin(branch_t*);
  418. static     void    ac_cap_nl(branch_t*);
  419. static    double    tr_review_cap(branch_t*);
  420. /*--------------------------------------------------------------------------*/
  421. functions_t dev_cap_lin = {
  422.    sizeof(branch_t),
  423.    create_cap,
  424.    parse_cap,
  425.    print_cap,
  426.    expand_cap,
  427.    trprobe_cap,
  428.    acprobe_cap,
  429.    tr_cap_lin,
  430.    un_cap,
  431.    ac_cap_lin,
  432.    (void(*)())NULL,    /* trfun1 */
  433.    (void(*)())NULL,    /* trfun0 */
  434.    (complex_t(*)())NULL,/* acfun */
  435.    (void(*)())NULL,    /* tr_guess */
  436.    (void(*)())NULL,    /* tr_advance */
  437.    tr_review_cap
  438. };
  439. functions_t dev_cap = {
  440.    sizeof(branch_t),
  441.    create_cap,
  442.    parse_cap,
  443.    print_cap,
  444.    expand_cap,
  445.    trprobe_cap,
  446.    acprobe_cap,
  447.    tr_cap_nl,
  448.    un_cap,
  449.    ac_cap_nl,
  450.    trfix1,
  451.    trfix0,
  452.    acfix,
  453.    (void(*)())NULL,    /* tr_guess */
  454.    (void(*)())NULL,    /* tr_advance */
  455.    tr_review_cap
  456. };
  457. /*--------------------------------------------------------------------------*/
  458. extern const int stiff;        /* flag: use "stiff" integration method        */
  459. extern const double init_curr;    /* initial current                */
  460. extern const double init_volt;    /* initial voltage                */
  461. extern const double trtime;    /* transient analysis time            */
  462. extern const int sim_mode;    /* what type simulation is this            */
  463. extern const int sim_phase;    /* how far it got                */
  464. extern const ac_t ac;
  465. extern const struct options opt;
  466. extern const struct status stats;
  467. extern const char e_int[];
  468.  
  469. extern int in_curr;        /* flag: initial current            */
  470. extern int in_volt;        /* flag: initial voltage            */
  471. /*--------------------------------------------------------------------------*/
  472. static branch_t *create_cap(proto)
  473. const branch_t *proto;
  474. {
  475.  return createbranch(proto,(generic_t*)NULL,&dev_cap);
  476. }
  477. /*--------------------------------------------------------------------------*/
  478. static void parse_cap(brh,cmd,cnt)
  479. branch_t *brh;
  480. const char *cmd;
  481. int *cnt;
  482. {
  483.  parsegeneric(brh,cmd,cnt,2);
  484.  brh->f = &dev_cap;
  485. }
  486. /*--------------------------------------------------------------------------*/
  487. static void print_cap(brh,where,detail)
  488. const branch_t *brh;
  489. int where;
  490. int detail;
  491. {
  492.  printgeneric(brh,where,detail);
  493. }
  494. /*--------------------------------------------------------------------------*/
  495. static void expand_cap(brh)
  496. branch_t *brh;
  497. {
  498.  if (!brh->x){
  499.     brh->f = &dev_cap_lin;
  500.     brh->y0.f0 = 0.;
  501.     brh->y0.f1 = brh->ev = brh->val;
  502.  }
  503. }
  504. /*--------------------------------------------------------------------------*/
  505. static double trprobe_cap(brh,what)
  506. const branch_t *brh;
  507. const char *what;
  508. {
  509.  return trprobegeneric(brh,what);
  510. }
  511. /*--------------------------------------------------------------------------*/
  512. static double acprobe_cap(brh,what)
  513. const branch_t *brh;
  514. const char *what;
  515. {
  516.  return acprobegeneric(brh,what);
  517. }
  518. /*--------------------------------------------------------------------------*/
  519. static int tr_cap_lin(brh)
  520. branch_t *brh;
  521. {
  522.  if (brh->iter == stats.iter[iTOTAL]){
  523.     return brh->status;
  524.  }else{
  525.     brh->iter = stats.iter[iTOTAL];
  526.  }
  527.  trsetup(brh);
  528.  brh->m0.x = tr_volts_limited(brh->n[OUT1],brh->n[OUT2]);
  529.  integrate(brh);
  530.  trloadpassive(brh);
  531.  return brh->status = cGOOD;
  532. }
  533. /*--------------------------------------------------------------------------*/
  534. static int tr_cap_nl(brh)
  535. branch_t *brh;
  536. {
  537.  if (brh->iter == stats.iter[iTOTAL]){
  538.     return brh->status;
  539.  }else{
  540.     brh->iter = stats.iter[iTOTAL];
  541.  }
  542.  in_volt = in_curr = NO;
  543.  trsetup(brh);
  544.  brh->m0.x = tr_volts_limited(brh->n[OUT1],brh->n[OUT2]);
  545.  brh->y0.x = brh->m0.x;
  546.  if (brh->f->trfun1){
  547.     (*brh->f->trfun1)(brh);
  548.     brh->ev = brh->y0.f1;
  549.  }
  550.  integrate(brh);
  551.  trloadpassive(brh);
  552.  return brh->status = cGOOD;
  553.  return brh->status = conv_check(brh);
  554. }
  555. /*--------------------------------------------------------------------------*/
  556. static void un_cap(brh)
  557. branch_t *brh;
  558. {
  559.  unloadpassive(brh);
  560. }
  561. /*--------------------------------------------------------------------------*/
  562. static void integrate(brh)
  563. branch_t *brh;
  564. {
  565.  if (sim_mode == sDC  ||  sim_mode == sOP){
  566.     brh->m0.c0 = brh->m0.f1 = 0.;
  567.  }else if (sim_phase == pINIT_DC){
  568.     if (trtime == 0.){
  569.        if (in_curr){
  570.       brh->m0.f1 = 0.;
  571.       brh->m0.c0 = -init_curr;
  572.        }else if (in_volt){
  573.       brh->m0.f1 = 1./opt.shortckt;
  574.       brh->m0.c0 = -init_volt * brh->m0.f1;
  575.        }else{
  576.       brh->m0.c0 = brh->m0.f1 = 0.;
  577.        }
  578.     }else{
  579.        /* leave it alone to restore */
  580.     }
  581.  }else if (brh->dt == 0.){
  582.     error(bERROR, e_int, "time step is 0.\n");
  583.  }else{
  584.     double oldv;
  585.     oldv = tr_volts_t1(brh->n[OUT1],brh->n[OUT2]);
  586.     if (stiff){
  587.        brh->m0.f1 = brh->ev / brh->dt;        /* first order             */
  588.        brh->m0.c0 = -brh->m0.f1 * oldv;        /* (stiff) (backward Euler) */
  589.     }else{
  590.        double oldi;                /* second order         */
  591.        oldi = brh->mt1.c0 + brh->mt1.f1*oldv;    /* (non-stiff) (trapezoid)  */
  592.        brh->m0.f1 = 2. * brh->ev / brh->dt;
  593.        brh->m0.c0 = -brh->m0.f1 * oldv - oldi;
  594.     }
  595.  }
  596. }
  597. /*--------------------------------------------------------------------------*/
  598. static void ac_cap_lin(brh)
  599. branch_t *brh;
  600. {
  601.  brh->acg.x = 0.;
  602.  brh->acg.y = brh->val * ac.omega;
  603.  acloadpassiveimaginary(brh);
  604. }
  605. /*--------------------------------------------------------------------------*/
  606. static void ac_cap_nl(brh)
  607. branch_t *brh;
  608. {
  609.  complex_t y;
  610.  
  611.  if (brh->f->acfun){
  612.     brh->acbias = dc_volts(brh->n[OUT1],brh->n[OUT2]);
  613.     y = (*brh->f->acfun)(brh);
  614.     brh->acg.x = -y.y * ac.omega;
  615.     brh->acg.y =  y.x * ac.omega;
  616.     acloadpassive(brh);
  617.  }else{
  618.     brh->acg.x = 0.;
  619.     brh->acg.y = brh->ev * ac.omega;
  620.     acloadpassiveimaginary(brh);
  621.  }
  622. }
  623. /*--------------------------------------------------------------------------*/
  624. static double tr_review_cap(brh)
  625. branch_t *brh;
  626. {
  627.  return BIGBIG;
  628. }
  629. /*--------------------------------------------------------------------------*/
  630. /*--------------------------------------------------------------------------*/
  631. SHAR_EOF
  632. fi # end of overwriting check
  633. if test -f 'src/d_coil.c'
  634. then
  635.     echo shar: will not over-write existing file "'src/d_coil.c'"
  636. else
  637. cat << \SHAR_EOF > 'src/d_coil.c'
  638. /* dev_coil.c  12/30/92
  639.  * Copyright 1983-1992   Albert Davis
  640.  * inductors
  641.  * two levels: linear (lin) and nonlinear (nl) (not really)
  642.  * x = amps, y.f0 = flux, ev = y.f1 = henrys
  643.  */
  644. #include "ecah.h"
  645. #include "ac.h"
  646. #include "branch.h"
  647. #include "error.h"
  648. #include "mode.h"
  649. #include "options.h"
  650. #include "status.h"
  651. #include "declare.h"
  652. /*--------------------------------------------------------------------------*/
  653. static     branch_t *create_coil(const branch_t*);
  654. static     void    parse_coil(branch_t*,const char*,int*);
  655. static     void    print_coil(const branch_t*,int,int);
  656. static    void    expand_coil(branch_t*);
  657. static    double    trprobe_coil(const branch_t*,const char*);
  658. static    double    acprobe_coil(const branch_t*,const char*);
  659. static     int    tr_coil(branch_t*);
  660. static     void    un_coil(branch_t*);
  661. static    void    integrate(branch_t*);
  662. static     void    ac_coil_lin(branch_t*);
  663. static     void    ac_coil_nl(branch_t*);
  664. static    double    tr_review_coil(branch_t*);
  665. /*--------------------------------------------------------------------------*/
  666. functions_t dev_coil_lin = {
  667.    sizeof(branch_t),
  668.    create_coil,
  669.    parse_coil,
  670.    print_coil,
  671.    expand_coil,
  672.    trprobe_coil,
  673.    acprobe_coil,
  674.    tr_coil,
  675.    un_coil,
  676.    ac_coil_lin,
  677.    (void(*)())NULL,    /* trfun1 */
  678.    (void(*)())NULL,    /* trfun0 */
  679.    (complex_t(*)())NULL,/* acfun */
  680.    (void(*)())NULL,    /* tr_guess */
  681.    (void(*)())NULL,    /* tr_advance */
  682.    tr_review_coil
  683. };
  684. functions_t dev_coil = {
  685.    sizeof(branch_t),
  686.    create_coil,
  687.    parse_coil,
  688.    print_coil,
  689.    expand_coil,
  690.    trprobe_coil,
  691.    acprobe_coil,
  692.    tr_coil,
  693.    un_coil,
  694.    ac_coil_nl,
  695.    trfix1,
  696.    trfix0,
  697.    acfix,
  698.    (void(*)())NULL,    /* tr_guess */
  699.    (void(*)())NULL,    /* tr_advance */
  700.    tr_review_coil
  701. };
  702. /*--------------------------------------------------------------------------*/
  703. extern const int stiff;        /* flag: use "stiff" integration method        */
  704. extern const double init_curr;    /* initial current                */
  705. extern const double init_volt;    /* initial voltage                */
  706. extern const double trtime;    /* transient analysis time            */
  707. extern const int sim_mode;    /* what type simulation is this            */
  708. extern const int sim_phase;    /* how far it got                */
  709. extern const ac_t ac;
  710. extern const struct options opt;
  711. extern const struct status stats;
  712.  
  713. extern int in_curr;        /* flag: initial current            */
  714. extern int in_volt;        /* flag: initial voltage            */
  715. /*--------------------------------------------------------------------------*/
  716. static branch_t *create_coil(proto)
  717. const branch_t *proto;
  718. {
  719.  return createbranch(proto,(generic_t*)NULL,&dev_coil);
  720. }
  721. /*--------------------------------------------------------------------------*/
  722. static void parse_coil(brh,cmd,cnt)
  723. branch_t *brh;
  724. const char *cmd;
  725. int *cnt;
  726. {
  727.  parsegeneric(brh,cmd,cnt,2);
  728.  brh->f = &dev_coil;
  729. }
  730. /*--------------------------------------------------------------------------*/
  731. static void print_coil(brh,where,detail)
  732. const branch_t *brh;
  733. int where;
  734. int detail;
  735. {
  736.  printgeneric(brh,where,detail);
  737. }
  738. /*--------------------------------------------------------------------------*/
  739. static void expand_coil(brh)
  740. branch_t *brh;
  741. {
  742.  if (!brh->x){
  743.     brh->f = &dev_coil_lin;
  744.  }
  745. }
  746. /*--------------------------------------------------------------------------*/
  747. static double trprobe_coil(brh,what)
  748. const branch_t *brh;
  749. const char *what;
  750. {
  751.  return trprobegeneric(brh,what);
  752. }
  753. /*--------------------------------------------------------------------------*/
  754. static double acprobe_coil(brh,what)
  755. const branch_t *brh;
  756. const char *what;
  757. {
  758.  return acprobegeneric(brh,what);
  759. }
  760. /*--------------------------------------------------------------------------*/
  761. static int tr_coil(brh)
  762. branch_t *brh;
  763. {
  764.  if (brh->iter == stats.iter[iTOTAL]){
  765.     return brh->status;
  766.  }else{
  767.     brh->iter = stats.iter[iTOTAL];
  768.  }
  769.  in_volt = in_curr = NO;
  770.  trsetup(brh);
  771.  brh->m0.x = tr_volts_limited(brh->n[OUT1],brh->n[OUT2]);
  772.  brh->y0.x = brh->m0.c0 + brh->m0.f1 * brh->m0.x;
  773.  if (brh->f->trfun1){
  774.     (*brh->f->trfun1)(brh);
  775.  }else{
  776.     brh->y0.f1 = brh->val;
  777.     brh->y0.f0 = LINEAR;
  778.  }
  779.  brh->ev = brh->y0.f1;
  780.  if (brh->y0.f1 == 0.){
  781.     error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
  782.  }
  783.  
  784.  integrate(brh);
  785.  trloadpassive(brh);
  786.  return brh->status = conv_check(brh);
  787. }
  788. /*--------------------------------------------------------------------------*/
  789. static void un_coil(brh)
  790. branch_t *brh;
  791. {
  792.  unloadpassive(brh);
  793. }
  794. /*--------------------------------------------------------------------------*/
  795. static void integrate(brh)
  796. branch_t *brh;
  797. {
  798.  if (sim_mode == sDC  ||  sim_mode == sOP  ||  brh->y0.f1 == 0.){
  799.     brh->m0.f1 = 1./opt.shortckt;
  800.     brh->m0.c0 = 0.;
  801.  }else if (sim_phase == pINIT_DC){
  802.     if (trtime == 0.){
  803.        if (in_curr){
  804.       brh->m0.f1 = 0.;
  805.       brh->m0.c0 = -init_curr;
  806.        }else if (in_volt){
  807.       brh->m0.f1 = 1./opt.shortckt;
  808.       brh->m0.c0 = -init_volt * brh->m0.f1;
  809.        }else{
  810.       brh->m0.f1 = 1./opt.shortckt;
  811.       brh->m0.c0 = 0.;
  812.        }
  813.     }else{
  814.        /* leave it alone to restore */
  815.     }
  816.  }else{
  817.     if (stiff){
  818.        brh->m0.f1 = brh->dt / brh->y0.f1;
  819.        brh->m0.c0 = brh->mt1.c0 + brh->mt1.f1 * brh->mt1.x; /* oldi */
  820.     }else{ /* not stiff */
  821.        /* oldi = brh->mt1.c0 + brh->mt1.f1 * brh->mt1.x; */
  822.        brh->m0.f1 = brh->dt/(2*brh->y0.f1);
  823.        brh->m0.c0 = brh->mt1.c0 + (brh->mt1.f1 + brh->m0.f1) * brh->mt1.x;
  824.                    /* oldi + f1*oldv, with combined terms */
  825.     }
  826.  }
  827. }
  828. /*--------------------------------------------------------------------------*/
  829. static void ac_coil_lin(brh)
  830. branch_t *brh;
  831. {
  832.  if (ac.omega == 0.){
  833.     brh->acg.x = 1. / opt.shortckt;
  834.     brh->acg.y = 0.;
  835.     acloadpassivereal(brh);
  836.     error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
  837.  }else{
  838.     brh->acg.x = 0.;
  839.     brh->acg.y = -1. / (brh->val * ac.omega);
  840.     acloadpassiveimaginary(brh);
  841.  }
  842. }
  843. /*--------------------------------------------------------------------------*/
  844. static void ac_coil_nl(brh)
  845. branch_t *brh;
  846. {
  847.  double dcvolts;
  848.  complex_t y;
  849.  
  850.  if (brh->f->acfun){
  851.     dcvolts = dc_volts(brh->n[OUT1],brh->n[OUT2]);
  852.     brh->acbias = brh->m0.c0 + brh->m0.f1*dcvolts;
  853.     y = (*brh->f->acfun)(brh);
  854.     if (ac.omega == 0.){
  855.        brh->acg.x = 1. / opt.shortckt;
  856.        brh->acg.y = 0.;
  857.        error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
  858.     }else{
  859.        y.x *= ac.omega;
  860.        y.y *= ac.omega;
  861.        y = cflip(y);
  862.        brh->acg.x =  y.y;
  863.        brh->acg.y = -y.x;
  864.     }
  865.     acloadpassive(brh);
  866.  }else{
  867.     if (ac.omega == 0.){
  868.        brh->acg.x = 1. / opt.shortckt;
  869.        brh->acg.y = 0.;
  870.        acloadpassivereal(brh);
  871.        error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
  872.     }else{
  873.        brh->acg.x = 0.;
  874.        brh->acg.y = -1. / (brh->ev * ac.omega);
  875.        acloadpassiveimaginary(brh);
  876.     }
  877.  }
  878. }
  879. /*--------------------------------------------------------------------------*/
  880. static double tr_review_coil(brh)
  881. branch_t *brh;
  882. {
  883.  return BIGBIG;
  884. }
  885. /*--------------------------------------------------------------------------*/
  886. /*--------------------------------------------------------------------------*/
  887. SHAR_EOF
  888. fi # end of overwriting check
  889. if test -f 'src/d_coment.c'
  890. then
  891.     echo shar: will not over-write existing file "'src/d_coment.c'"
  892. else
  893. cat << \SHAR_EOF > 'src/d_coment.c'
  894. /* dev_coment.c  12/30/92
  895.  * Copyright 1983-1992   Albert Davis
  896.  * processing for COMMENT netlist item (pseudo-device)
  897.  */
  898. #include "ecah.h"
  899. #include "branch.h"
  900. #include "error.h"
  901. #include "declare.h"
  902. /*--------------------------------------------------------------------------*/
  903. static     branch_t *create_comment(const branch_t*);
  904. static     void    parse_comment(branch_t*,const char*,int*);
  905. static     void    print_comment(const branch_t*,int,int);
  906. /*--------------------------------------------------------------------------*/
  907. functions_t dev_comment = {
  908.    sizeof(branch_t),
  909.    create_comment,
  910.    parse_comment,
  911.    print_comment,
  912.    (void(*)())NULL,    /* expand */
  913.    (double(*)())NULL,    /* trprobe */
  914.    (double(*)())NULL,    /* acprobe */
  915.    (int(*)())NULL,    /* dotr */
  916.    (void(*)())NULL,    /* untr */
  917.    (void(*)())NULL,    /* doac */
  918.    (void(*)())NULL,    /* trfun1 */
  919.    (void(*)())NULL,    /* trfun0 */
  920.    (complex_t(*)())NULL,/* acfun */
  921.    (void(*)())NULL,    /* tr_guess */
  922.    (void(*)())NULL,    /* tr_advance */
  923.    (double(*)())NULL    /* tr_review */
  924. };
  925. /*--------------------------------------------------------------------------*/
  926. /*--------------------------------------------------------------------------*/
  927. static branch_t *create_comment(proto)
  928. const branch_t *proto;
  929. {
  930.  return createbranch(proto,(generic_t*)NULL,&dev_comment);
  931. }
  932. /*--------------------------------------------------------------------------*/
  933. static void parse_comment(brh,cmd,cnt)
  934. branch_t *brh;
  935. const char *cmd;
  936. int *cnt;
  937. {
  938.  (*cnt)++;
  939.  if (cmd[*cnt] == '+'){    /* throw away comments starting with "*+"        */
  940.     brh->f = (functions_t*)NULL;
  941.  }else{
  942.     int maxlen = sizeof(branch_t) - (&(brh->label[0]) - (char*)brh);
  943.     (void)strncpy(brh->label, &cmd[*cnt], maxlen);
  944.  }
  945. }
  946. /*--------------------------------------------------------------------------*/
  947. static void print_comment(brh,where,detail)
  948. const branch_t *brh;
  949. int where;
  950. int detail;
  951. {
  952.  mprintf(where, "*%s\n", brh->label);
  953. }
  954. /*--------------------------------------------------------------------------*/
  955. /*--------------------------------------------------------------------------*/
  956. SHAR_EOF
  957. fi # end of overwriting check
  958. if test -f 'src/d_cs.c'
  959. then
  960.     echo shar: will not over-write existing file "'src/d_cs.c'"
  961. else
  962. cat << \SHAR_EOF > 'src/d_cs.c'
  963. /* dev_cs.c  12/30/92
  964.  * Copyright 1983-1992   Albert Davis
  965.  * functions for fixed current source
  966.  * x = 0, y.f0 = nothing, ev = y.f1 = amps.
  967.  */
  968. #include "ecah.h"
  969. #include "branch.h"
  970. #include "mode.h"
  971. #include "status.h"
  972. #include "declare.h"
  973. /*--------------------------------------------------------------------------*/
  974. static     branch_t *create_cs(const branch_t*);
  975. static     void    parse_cs(branch_t*,const char*,int*);
  976. static     void    print_cs(const branch_t*,int,int);
  977. static    double    trprobe_cs(const branch_t*,const char*);
  978. static    double    acprobe_cs(const branch_t*,const char*);
  979. static     int    tr_cs(branch_t*);
  980. static     void    un_cs(branch_t*);
  981. static     void    ac_cs(branch_t*);
  982. /*--------------------------------------------------------------------------*/
  983. functions_t dev_cs = {
  984.    sizeof(branch_t),
  985.    create_cs,
  986.    parse_cs,
  987.    print_cs,
  988.    (void(*)())NULL,    /* expand */
  989.    trprobe_cs,
  990.    acprobe_cs,
  991.    tr_cs,
  992.    un_cs,
  993.    ac_cs,
  994.    trfix1,
  995.    trfix0,
  996.    acfix,
  997.    (void(*)())NULL,    /* tr_guess */
  998.    (void(*)())NULL,    /* tr_advance */
  999.    (double(*)())NULL    /* tr_review */
  1000. };
  1001. /*--------------------------------------------------------------------------*/
  1002. extern const struct status stats;
  1003. /*--------------------------------------------------------------------------*/
  1004. static branch_t *create_cs(proto)
  1005. const branch_t *proto;
  1006. {
  1007.  return createbranch(proto,(generic_t*)NULL,&dev_cs);
  1008. }
  1009. /*--------------------------------------------------------------------------*/
  1010. static void parse_cs(brh,cmd,cnt)
  1011. branch_t *brh;
  1012. const char *cmd;
  1013. int *cnt;
  1014. {
  1015.  parsegeneric(brh,cmd,cnt,2);
  1016. }
  1017. /*--------------------------------------------------------------------------*/
  1018. static void print_cs(brh,where,detail)
  1019. const branch_t *brh;
  1020. int where;
  1021. int detail;
  1022. {
  1023.  printgeneric(brh,where,detail);
  1024. }
  1025. /*--------------------------------------------------------------------------*/
  1026. static double trprobe_cs(brh,what)
  1027. const branch_t *brh;
  1028. const char *what;
  1029. {
  1030.  return trprobegeneric(brh,what);
  1031. }
  1032. /*--------------------------------------------------------------------------*/
  1033. static double acprobe_cs(brh,what)
  1034. const branch_t *brh;
  1035. const char *what;
  1036. {
  1037.  return acprobegeneric(brh,what);
  1038. }
  1039. /*--------------------------------------------------------------------------*/
  1040. static int tr_cs(brh)
  1041. branch_t *brh;
  1042. {
  1043.  if (brh->iter == stats.iter[iTOTAL]){
  1044.     return brh->status;
  1045.  }else{
  1046.     brh->iter = stats.iter[iTOTAL];
  1047.  }
  1048.  trsetup(brh);
  1049.  brh->m0.x = NOT_VALID;        /* anything * 0 = 0 */
  1050.  brh->y0.x = 0.;
  1051.  if (brh->f->trfun1){
  1052.     (*brh->f->trfun1)(brh);
  1053.  }else{
  1054.     brh->y0.f1 = brh->val;
  1055.     brh->y0.f0 = 0.;
  1056.  }
  1057.  brh->ev = brh->y0.f1;
  1058.  brh->m0.f1 = 0.;
  1059.  brh->m0.c0 = brh->ev;
  1060.  trloadsource(brh);
  1061.  return brh->status = conv_check(brh);
  1062. }
  1063. /*--------------------------------------------------------------------------*/
  1064. static void un_cs(brh)
  1065. branch_t *brh;
  1066. {
  1067.  unloadsource(brh);
  1068. }
  1069. /*--------------------------------------------------------------------------*/
  1070. static void ac_cs(brh)
  1071. branch_t *brh;
  1072. {
  1073.  if (brh->f->acfun){
  1074.     brh->acbias = 0.;
  1075.     brh->acg = (*brh->f->acfun)(brh);
  1076.  }else{
  1077.     brh->acg.x = brh->ev;
  1078.     brh->acg.y = 0.;
  1079.  }
  1080.  acloadsource(brh);
  1081. }
  1082. /*--------------------------------------------------------------------------*/
  1083. /*--------------------------------------------------------------------------*/
  1084. SHAR_EOF
  1085. fi # end of overwriting check
  1086. if test -f 'src/d_diode.c'
  1087. then
  1088.     echo shar: will not over-write existing file "'src/d_diode.c'"
  1089. else
  1090. cat << \SHAR_EOF > 'src/d_diode.c'
  1091. /* dev_diod.c  01/05/93
  1092.  * Copyright 1983-1992   Albert Davis
  1093.  * diode model.
  1094.  * netlist syntax:
  1095.  * device:  dxxxx n+ n- mname <area> <off> <ic=vd> <model-card-args>
  1096.  * model:   .model mname D <args>
  1097.  */
  1098. #include "ecah.h"
  1099. #include "argparse.h"
  1100. #include "branch.h"
  1101. #include "convstat.h"
  1102. #include "dev.h"
  1103. #include "d_diode.h"
  1104. #include "error.h"
  1105. #include "mode.h"
  1106. #include "options.h"
  1107. #include "status.h"
  1108. #include "types.h"
  1109. #include "declare.h"
  1110. /*--------------------------------------------------------------------------*/
  1111. static     branch_t *create_diode(const branch_t*);
  1112. static     void    parse_diode(branch_t*,const char*,int*);
  1113. static     void    print_diode(const branch_t*,int,int);
  1114. static    branch_t *create_model_diode(const branch_t*);
  1115. static     void    parse_model_diode(branch_t*,const char*,int*);
  1116. static     void    print_model_diode(const branch_t*,int,int);
  1117. static     void    expand_diode(branch_t*);
  1118. static    double    trprobe_diode(const branch_t*,const char*);
  1119. static     int    tr_diode(branch_t*);
  1120. static     void    un_diode(branch_t*);
  1121. static     void    ac_diode(branch_t*);
  1122. static    void    evaldiode0(branch_t*);
  1123. static    void    evaldiode1(branch_t*);
  1124. static    void    diodecap0(branch_t*);
  1125. static    void    diodecap1(branch_t*);
  1126. static    double    tr_review_diode(branch_t*);
  1127. /*--------------------------------------------------------------------------*/
  1128. functions_t dev_diode = {
  1129.    sizeof(branch_t),
  1130.    create_diode,
  1131.    parse_diode,
  1132.    print_diode,
  1133.    expand_diode,
  1134.    trprobe_diode,
  1135.    (double(*)())NULL,/* acprobe */
  1136.    tr_diode,
  1137.    un_diode,
  1138.    ac_diode,
  1139.    (void(*)())NULL,    /* trfun1 */
  1140.    (void(*)())NULL,    /* trfun0 */
  1141.    (complex_t(*)())NULL,/* acfun */
  1142.    (void(*)())NULL,    /* tr_guess */
  1143.    (void(*)())NULL,    /* tr_advance */
  1144.    tr_review_diode
  1145. };
  1146. functions_t model_diode = {
  1147.    sizeof(branch_t),
  1148.    create_model_diode,
  1149.    parse_model_diode,
  1150.    print_model_diode,
  1151.    (void(*)())NULL,    /* expand */
  1152.    (double(*)())NULL,    /* trprobe */
  1153.    (double(*)())NULL,/* acprobe */
  1154.    (int(*)())NULL,    /* dotr */
  1155.    (void(*)())NULL,    /* untr */
  1156.    (void(*)())NULL,    /* doac */
  1157.    (void(*)())NULL,    /* trfun1 */
  1158.    (void(*)())NULL,    /* trfun0 */
  1159.    (complex_t(*)())NULL,/* acfun */
  1160.    (void(*)())NULL,    /* tr_guess */
  1161.    (void(*)())NULL,    /* tr_advance */
  1162.    (double(*)())NULL    /* tr_review */
  1163. };
  1164. /*--------------------------------------------------------------------------*/
  1165. extern const struct options opt;
  1166. extern const struct status stats;
  1167. extern const double temp;    /* temperature (ambient)            */
  1168. static struct diode *x;
  1169.  
  1170. static struct diode defalt = {(generic_t*)NULL, sizeof(struct diode),
  1171.     (struct dmod*)NULL, dDEFDEV_modelname, dDEFDEV_is, dDEFDEV_rs,
  1172.     dDEFDEV_cj, dDEFDEV_cjsw, dDEFDEV_area, dDEFDEV_perim,
  1173.     dDEFDEV_ic, dDEFDEV_off};
  1174. static struct dmod defaltmodel = {(generic_t*)NULL, sizeof(struct dmod),
  1175.     dDEFMOD_js, dDEFMOD_rs, dDEFMOD_n, dDEFMOD_tt, dDEFMOD_cj,
  1176.     dDEFMOD_pb, dDEFMOD_mj, dDEFMOD_eg, dDEFMOD_xti, dDEFMOD_kf,
  1177.     dDEFMOD_af, dDEFMOD_fc, dDEFMOD_bv, dDEFMOD_ibv, dDEFMOD_cjsw,
  1178.     dDEFMOD_mjsw, dDEFMOD_fcpb};
  1179. static branch_t modellist = {(generic_t*)&defaltmodel, sizeof(branch_t),
  1180.     &model_diode, &modellist, &modellist, &modellist, &modellist,
  1181.     (branch_t*)NULL, (branch_t*)NULL, dDEFMOD_modelname, /* more */};
  1182. /*--------------------------------------------------------------------------*/
  1183. static branch_t *create_diode(proto)
  1184. const branch_t *proto;
  1185. {
  1186.  return createbranch(proto,(generic_t*)&defalt,&dev_diode);
  1187. }
  1188. /*--------------------------------------------------------------------------*/
  1189. static void parse_diode(brh,cmd,cnt)
  1190. branch_t *brh;
  1191. const char *cmd;
  1192. int *cnt;
  1193. {
  1194.  struct diode *x;
  1195.  
  1196.  x = (struct diode*)brh->x;
  1197.  
  1198.  parselabel(brh,cmd,cnt);
  1199.  (void)parsenodes(brh,cmd,cnt,2);
  1200.  (void)ctostr(cmd, cnt, x->modelname, LABELEN);
  1201.  x->m = (struct dmod*)NULL;
  1202.  if (isdigit(cmd[*cnt])  ||  cmd[*cnt] == '.')
  1203.     x->area = fabs(ctof(cmd,cnt));
  1204.  for (;;){
  1205.     if (argparse(cmd,cnt,REPEAT,
  1206.     "Area",    aUDOUBLE,    &x->area,
  1207.     "Perim",aUDOUBLE,    &x->perim,
  1208.     "IC",    aDOUBLE,    &x->ic,
  1209.     "OFF",    aENUM,        &x->off,    YES,
  1210.     "IS",    aUDOUBLE,    &x->is,
  1211.     "Rs",    aUDOUBLE,    &x->rs,
  1212.     "Cjo",    aUDOUBLE,    &x->cj,
  1213.     "CJSW",    aUDOUBLE,    &x->cjsw,
  1214.     ""))
  1215.     ;
  1216.     else{
  1217.        syntax(cmd,cnt,bWARNING);
  1218.        break;
  1219.     }
  1220.  }
  1221. }
  1222. /*--------------------------------------------------------------------------*/
  1223. static void print_diode(brh,where,detail)
  1224. const branch_t *brh;
  1225. int where;
  1226. int detail;
  1227. {
  1228.  struct diode *x;
  1229.  
  1230.  x = (struct diode*)brh->x;
  1231.  
  1232.  (void)printlabel(brh,where);
  1233.  printnodes(brh,where);
  1234.  mprintf(where, " %s ", x->modelname);
  1235.  
  1236.     mprintf(where,    " %s ", ftos(x->area,"", 7, 0));
  1237.  if (x->perim != 0.)
  1238.     mprintf(where,"perim=%s ",ftos(x->perim,"", 7, 0));
  1239.  if (x->off)
  1240.     mprintf(where, " off ");
  1241.  if (x->ic != NOT_INPUT)
  1242.     mprintf(where, " ic=%s ", ftos(x->ic,  "", 7, 0));
  1243.  if (!x->calc.is  &&  x->is != NOT_INPUT)
  1244.     mprintf(where, " is=%s ", ftos(x->is,  "", 7, 0));
  1245.  if (!x->calc.rs  &&  x->rs != NOT_INPUT)
  1246.     mprintf(where, " rs=%s ", ftos(x->rs,  "", 7, 0));
  1247.  if (!x->calc.cj  &&  x->cj != NOT_INPUT)
  1248.     mprintf(where, " cj=%s ", ftos(x->cj,  "", 7, 0));
  1249.  if (!x->calc.cjsw  &&  x->cjsw != NOT_INPUT)
  1250.     mprintf(where, " cjsw=%s ",ftos(x->cjsw,"", 7, 0));
  1251.  if (x->calc.is  &&  x->calc.rs  &&  x->calc.cj  &&  x->calc.cjsw)
  1252.     mprintf(where, "\n*+");
  1253.  if (x->calc.is  &&  x->is != NOT_INPUT)
  1254.     mprintf(where, " is=%s ", ftos(x->is,  "", 7, 0));
  1255.  if (x->calc.rs  &&  x->rs != NOT_INPUT)
  1256.     mprintf(where, " rs=%s ", ftos(x->rs,  "", 7, 0));
  1257.  if (x->calc.cj  &&  x->cj != NOT_INPUT)
  1258.     mprintf(where, " cj=%s ", ftos(x->cj,  "", 7, 0));
  1259.  if (x->calc.cjsw  &&  x->cjsw != NOT_INPUT)
  1260.     mprintf(where, " cjsw=%s ",ftos(x->cjsw,"", 7, 0));
  1261.  mprintf(where, "\n");
  1262. }
  1263. /*--------------------------------------------------------------------------*/
  1264. static branch_t *create_model_diode(proto)
  1265. const branch_t *proto;
  1266. {
  1267.  branch_t *brh;
  1268.  
  1269.  brh = createbranch(proto,(generic_t*)&defaltmodel,&model_diode);
  1270.  brh->stprev = &modellist;
  1271.  return brh;
  1272. }
  1273. /*--------------------------------------------------------------------------*/
  1274. static void parse_model_diode(brh,cmd,cnt)
  1275. branch_t *brh;
  1276. const char *cmd;
  1277. int *cnt;
  1278. {
  1279.  struct dmod *m;
  1280.  
  1281.  m = (struct dmod*)brh->x;
  1282.  
  1283.  (void)ctostr(cmd, cnt, brh->label, LABELEN);
  1284.  skiparg(cmd,cnt);    /* skip known "d" */
  1285.  (void)skiplparen(cmd,cnt);
  1286.  for (;;){
  1287.     if (argparse(cmd,cnt,REPEAT,
  1288.     "IS",    aUDOUBLE,    &m->js,
  1289.     "RS",    aUDOUBLE,    &m->rs,
  1290.     "N",    aUDOUBLE,    &m->n,
  1291.     "TT",    aUDOUBLE,    &m->tt,
  1292.     "CJo",    aUDOUBLE,    &m->cj,
  1293.     "VJ",    aUDOUBLE,    &m->pb,
  1294.     "PB",    aUDOUBLE,    &m->pb,
  1295.     "Mj",    aUDOUBLE,    &m->mj,
  1296.     "EGap",    aUDOUBLE,    &m->eg,
  1297.      ""))
  1298.        ;
  1299.     else if (argparse(cmd,cnt,REPEAT,
  1300.     "XTI",    aUDOUBLE,    &m->xti,
  1301.     "KF",    aUDOUBLE,    &m->kf,
  1302.     "AF",    aUDOUBLE,    &m->af,
  1303.     "FC",    aUDOUBLE,    &m->fc,
  1304.     "BV",    aUDOUBLE,    &m->bv,
  1305.     "IBV",    aUDOUBLE,    &m->ibv,
  1306.     "CJSw",    aUDOUBLE,    &m->cjsw,
  1307.     "MJSw",    aUDOUBLE,    &m->mjsw,
  1308.     ""))
  1309.     ;
  1310.     else{
  1311.        (void)skiprparen(cmd,cnt);
  1312.        syntax(cmd,cnt,bWARNING);
  1313.        break;
  1314.     }
  1315.  }
  1316.  m->fcpb = m->fc * m->pb;
  1317.  if (m->tt != 0.)
  1318.     error(bWARNING, "%s: tt not implemented\n", printlabel(brh,NO));
  1319. }
  1320. /*--------------------------------------------------------------------------*/
  1321. static void print_model_diode(brh,where,detail)
  1322. const branch_t *brh;
  1323. int where;
  1324. int detail;
  1325. {
  1326.  struct dmod *m;
  1327.  m = (struct dmod*)brh->x;
  1328.  
  1329.  mprintf(where, ".model  %s  d  (", brh->label);
  1330.  mprintf(where, " is=%s ",  ftos(m->js,  "", 7, 0));
  1331.  mprintf(where, " rs=%s ",  ftos(m->rs,  "", 7, 0));
  1332.  mprintf(where, " n=%s ",   ftos(m->n,   "", 7, 0));
  1333.  mprintf(where, " tt=%s ",  ftos(m->tt,  "", 7, 0));
  1334.  mprintf(where, " cjo=%s ", ftos(m->cj, "", 7, 0));
  1335.  mprintf(where, " vj=%s ",  ftos(m->pb,  "", 7, 0));
  1336.  mprintf(where, " m=%s ",   ftos(m->mj,   "", 7, 0));
  1337.  mprintf(where, " eg=%s ",  ftos(m->eg,  "", 7, 0));
  1338.  mprintf(where, " xti=%s ", ftos(m->xti, "", 7, 0));
  1339.  mprintf(where, " kf=%s ",  ftos(m->kf,  "", 7, 0));
  1340.  mprintf(where, " af=%s ",  ftos(m->af,  "", 7, 0));
  1341.  mprintf(where, " fc=%s ",  ftos(m->fc,  "", 7, 0));
  1342.  mprintf(where, " bv=%s ",  ftos(m->bv,  "", 7, 0));
  1343.  mprintf(where, " ibv=%s ", ftos(m->ibv, "", 7, 0));
  1344.  if (m->cjsw != 0.){
  1345.     mprintf(where, " cjsw=%s ", ftos(m->cjsw,"", 7, 0));
  1346.     mprintf(where, " mjsw=%s ", ftos(m->mjsw,"", 7, 0));
  1347.  }
  1348.  mprintf(where, ")\n");
  1349. }
  1350. /*--------------------------------------------------------------------------*/
  1351. static void expand_diode(brh)
  1352. branch_t *brh;
  1353. {
  1354.  const struct dmod *m;
  1355.  struct diode *x;
  1356.  
  1357.  expandgeneric(brh,&modellist);
  1358.  x = (struct diode*)brh->x;
  1359.  m = x->m;
  1360.  
  1361.  if (x->calc.is  ||  x->is == NOT_INPUT){        /* calculate parameters */
  1362.     x->is = m->js * x->area;
  1363.     x->calc.is = YES;
  1364.  }
  1365.  if (x->calc.rs  ||  x->rs == NOT_INPUT){
  1366.     x->rs = m->rs * x->area;
  1367.     x->calc.rs = YES;
  1368.  }
  1369.  if (x->calc.cj  ||  x->cj == NOT_INPUT){
  1370.     x->cj = m->cj * x->area;
  1371.     x->calc.cj = YES;
  1372.  }
  1373.  if (x->calc.cjsw  ||  x->cjsw == NOT_INPUT){
  1374.     x->cjsw = m->cjsw * x->perim;
  1375.     x->calc.cjsw = YES;
  1376.  }
  1377.  
  1378.                                 /* build subckt */
  1379.  if (x->cj != 0.  ||  x->cjsw != 0.){
  1380.     if (!x->Cj){
  1381.        static functions_t *ff;
  1382.        x->Cj = (*(dev_cap.create))((branch_t*)NULL);
  1383.        if (!ff){
  1384.       ff = (functions_t*)calloc(1, sizeof(functions_t));
  1385.       *ff = *(x->Cj->f);
  1386.       ff->expand = (void(*)())NULL;
  1387.       ff->trfun1 = diodecap1;
  1388.       ff->trfun0 = diodecap0;
  1389.       ff->acfun = (complex_t(*)())NULL;
  1390.        }
  1391.        x->Cj->f = ff;
  1392.     }
  1393.     x->Cj->parent = brh;
  1394.     strcpy(x->Cj->label,"Cj");
  1395.     x->Cj->n[OUT1] = brh->n[OUT1];
  1396.     x->Cj->n[OUT2] = brh->n[OUT2];
  1397.     x->Cj->next = brh->subckt;
  1398.     x->Cj->prev = (branch_t*)NULL;
  1399.     brh->subckt = insertbranch(x->Cj);
  1400.  }else{
  1401.     x->Cj = (branch_t*)NULL;
  1402.  }
  1403.  
  1404.  if (!x->Yj){
  1405.     static functions_t *ff;
  1406.     x->Yj = (*(dev_admittance.create))((branch_t*)NULL);
  1407.     if (!ff){
  1408.        ff = (functions_t*)calloc(1, sizeof(functions_t));
  1409.        *ff = *(x->Yj->f);
  1410.        ff->expand = (void(*)())NULL;
  1411.        ff->trfun1 = evaldiode1;
  1412.        ff->trfun0 = evaldiode0;
  1413.        ff->acfun = (complex_t(*)())NULL;
  1414.     }
  1415.     x->Yj->f = ff;
  1416.  }
  1417.  x->Yj->parent = brh;
  1418.  strcpy(x->Yj->label,"Yj");
  1419.  x->Yj->n[OUT1] = brh->n[OUT1];
  1420.  x->Yj->n[OUT2] = brh->n[OUT2];
  1421.  x->Yj->next = brh->subckt;
  1422.  x->Yj->prev = (branch_t*)NULL;
  1423.  brh->subckt = insertbranch(x->Yj);
  1424.  brh->tracesubckt = YES;
  1425. }
  1426. /*--------------------------------------------------------------------------*/
  1427. static double trprobe_diode(brh,what)
  1428. const branch_t *brh;
  1429. const char *what;
  1430. {
  1431.  struct diode *x;
  1432.  double volts;
  1433.  int dummy = 0;
  1434.  
  1435.  x = (struct diode*)brh->x;
  1436.  if (!x->m  ||  !brh->subckt)
  1437.     error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
  1438.  
  1439.  volts = tr_volts(brh->n[OUT1],brh->n[OUT2]);
  1440.  
  1441.  setmatch(what,&dummy);
  1442.  if (rematch("V")){
  1443.     return volts;
  1444.  }else if (rematch("I")){
  1445.     return trprobe_branch(x->Yj,"I") + trprobe_branch(x->Cj,"I");
  1446.  }else if (rematch("IJ")){
  1447.     return trprobe_branch(x->Yj,"I");
  1448.  }else if (rematch("IC")){
  1449.     return trprobe_branch(x->Cj,"I");
  1450.  }else if (rematch("P")){
  1451.     return trprobe_branch(x->Yj,"P") + trprobe_branch(x->Cj,"P");
  1452.  }else if (rematch("PJ")){
  1453.     return trprobe_branch(x->Yj,"P");
  1454.  }else if (rematch("PC")){
  1455.     return trprobe_branch(x->Cj,"P");
  1456.  }else if (rematch("R")){
  1457.     return trprobe_branch(x->Yj,"R");
  1458.  }else if (rematch("Z")){
  1459.     return trz(brh->n[OUT1],brh->n[OUT2],0.);
  1460.  }else { /* bad parameter */
  1461.     return NOT_VALID;
  1462.  }
  1463. }
  1464. /*--------------------------------------------------------------------------*/
  1465. static int tr_diode(brh)
  1466. branch_t *brh;
  1467. {
  1468.  if (brh->iter == stats.iter[iTOTAL]){
  1469.     return brh->status;
  1470.  }else{
  1471.     brh->iter = stats.iter[iTOTAL];
  1472.  }
  1473.  x = (struct diode*)brh->x;
  1474.  if (!x->m  ||  !brh->subckt)
  1475.     error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
  1476.  return brh->status = tr_fill_rl(brh->subckt);
  1477. }
  1478. /*--------------------------------------------------------------------------*/
  1479. static void un_diode(brh)
  1480. branch_t *brh;
  1481. {
  1482.  tr_unfill_rl(brh->subckt);
  1483. }
  1484. /*--------------------------------------------------------------------------*/
  1485. static void ac_diode(brh)
  1486. branch_t *brh;
  1487. {
  1488.  x = (struct diode*)brh->x;
  1489.  if (!x->m  ||  !brh->subckt)
  1490.     error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
  1491.  ac_fill_rl(brh->subckt);
  1492. }
  1493. /*--------------------------------------------------------------------------*/
  1494. static void evaldiode0(brh)
  1495. branch_t *brh;
  1496. {
  1497.  evaldiode1(brh);
  1498.  brh->y0.f1 = brh->y1.f1;    /* BUG */
  1499. }
  1500. /*--------------------------------------------------------------------------*/
  1501. static void evaldiode1(brh)
  1502. branch_t *brh;
  1503. {
  1504. #define y (brh->y0)
  1505.  double volts;
  1506.  double amps;
  1507.  double vt;
  1508.  double isat;
  1509.  double tempratio;
  1510.  const struct dmod *m;
  1511.  
  1512.  m = x->m;
  1513.  
  1514.  y = brh->y0;
  1515.  volts = y.x;
  1516.  amps  = y.f0;
  1517.  
  1518.  tempratio = temp / opt.tnom;
  1519.  vt = (K/Q) * temp;
  1520.  vt *= m->n;
  1521.  isat = x->isat = x->is * pow(tempratio, m->xti) * exp((m->eg/vt) * (tempratio-1));
  1522.  
  1523.  
  1524.  if (volts < 0.  &&  amps < 0.){    /* reverse biased                */
  1525.     double expterm;            /* x = volts, f(x) = amps            */
  1526.     expterm = isat * exp(volts/vt);    
  1527.     y.f0 = expterm - isat;        /* i = f(x) = isat * (exp(volts/vt)-1)  */
  1528.     y.f1 = expterm / vt;        /* f'(x) = (isat/vt) * exp(volts/vt)    */
  1529.  }else if (volts > 0.  &&  amps > 0.){    /* forward biased            */
  1530.     /*poly1 r;*/            /* x = amps, f(x) = volts        */
  1531.     /*r.f0 = vt * log(amps/isat +1.);*/
  1532.     /*r.f1 = vt / (isat + amps);*/  /* if f(x) = log(u): f'(x)=(1/u)(du/dx) */
  1533.     /*y.f1 = 1. / r.f1;*/
  1534.     y.f1 = (isat + amps) / vt;
  1535.     /*y.f0 = amps - r.f0*y.f1 + volts*y.f1;*/
  1536.     /*y.f0 = amps - log(amps/isat +1.)*(isat + amps) + volts*y.f1;*/
  1537.     y.f0 = amps - log1p(amps/isat)*(isat + amps) + volts*y.f1;
  1538.  }else{                    /* non-converged, inconsistent        */
  1539.     y.f1 = isat/vt;            /* volts and amps have different signs  */
  1540.     y.f0 = y.x * y.f1;            /* guess that the voltage should be 0   */
  1541.                         /* (it usually is very close)        */
  1542.  }                    /* use the correct value there        */
  1543. #undef y
  1544. }
  1545. /*--------------------------------------------------------------------------*/
  1546. static void diodecap0(brh)
  1547. branch_t *brh;
  1548. {
  1549.  diodecap1(brh);
  1550.  brh->y0.f1 = brh->y1.f1;    /* BUG */
  1551. }
  1552. /*--------------------------------------------------------------------------*/
  1553. static void diodecap1(brh)
  1554. branch_t *brh;
  1555. {
  1556.  double volts;
  1557.  double cd;
  1558.  const struct dmod *m;
  1559.  
  1560.  m = x->m;
  1561.  
  1562.  volts = brh->y0.x;
  1563.  if (x->cj != 0.){
  1564.     if (volts < m->fcpb){
  1565.        cd = x->cj / pow(1. - (volts / m->pb),  m->mj);
  1566.     }else{
  1567.        cd = (x->cj / pow(1. - m->fc, 1. + m->mj))
  1568.             * (1. - m->fc*(1.+m->mj) + (volts/m->pb)*m->mj);
  1569.     }
  1570.  }else{
  1571.     cd = 0.;
  1572.  }
  1573.  if (x->cjsw != 0.){
  1574.     if (volts < m->fcpb){
  1575.        cd += x->cjsw / pow(1. - (volts / m->pb),  m->mjsw);
  1576.     }else{
  1577.        cd += (x->cjsw / pow(1. - m->fc, 1. + m->mjsw))
  1578.             * (1. - m->fc*(1.+m->mjsw) + (volts/m->pb)*m->mjsw);
  1579.     }
  1580.  }
  1581.  
  1582.  brh->y0.f1 = cd;
  1583.  brh->y0.f0 = brh->y0.x * brh->y0.f1;
  1584. }
  1585. /*--------------------------------------------------------------------------*/
  1586. static double tr_review_diode(brh)
  1587. branch_t *brh;
  1588. {
  1589.  return tr_review_rl(brh->subckt);
  1590. }
  1591. /*--------------------------------------------------------------------------*/
  1592. /*--------------------------------------------------------------------------*/
  1593. SHAR_EOF
  1594. fi # end of overwriting check
  1595. if test -f 'src/d_dot.c'
  1596. then
  1597.     echo shar: will not over-write existing file "'src/d_dot.c'"
  1598. else
  1599. cat << \SHAR_EOF > 'src/d_dot.c'
  1600. /* dev_dot.c  12/30/92
  1601.  * Copyright 1983-1992   Albert Davis
  1602.  * processing for DOTCARD netlist item (pseudo-device)
  1603.  */
  1604. #include "ecah.h"
  1605. #include "argparse.h"
  1606. #include "branch.h"
  1607. #include "dev.h"
  1608. #include "error.h"
  1609. #include "mode.h"
  1610. #include "types.h"
  1611. #include "declare.h"
  1612. /*--------------------------------------------------------------------------*/
  1613. static     branch_t *create_dotcard(const branch_t*);
  1614. static     void    parse_dotcard(branch_t*,const char*,int*);
  1615. static     void    print_dotcard(const branch_t*,int,int);
  1616. static    void    parse_dot_generic(branch_t*,const char*);
  1617. static    void    parse_dot_model(branch_t*,const char*,int*);
  1618. /*--------------------------------------------------------------------------*/
  1619. functions_t dev_dotcard = {
  1620.    sizeof(branch_t),
  1621.    create_dotcard,
  1622.    parse_dotcard,
  1623.    print_dotcard,
  1624.    (void(*)())NULL,    /* expand */
  1625.    (double(*)())NULL,    /* trprobe */
  1626.    (double(*)())NULL,    /* acprobe */
  1627.    (int(*)())NULL,    /* dotr */
  1628.    (void(*)())NULL,    /* untr */
  1629.    (void(*)())NULL,    /* doac */
  1630.    (void(*)())NULL,    /* trfun1 */
  1631.    (void(*)())NULL,    /* trfun0 */
  1632.    (complex_t(*)())NULL,/* acfun */
  1633.    (void(*)())NULL,    /* tr_guess */
  1634.    (void(*)())NULL,    /* tr_advance */
  1635.    (double(*)())NULL    /* tr_review */
  1636. };
  1637. /*--------------------------------------------------------------------------*/
  1638. extern int run_mode;
  1639. /*--------------------------------------------------------------------------*/
  1640. static branch_t *create_dotcard(proto)
  1641. const branch_t *proto;
  1642. {
  1643.  return createbranch(proto,(generic_t*)NULL,&dev_dotcard);
  1644. }
  1645. /*--------------------------------------------------------------------------*/
  1646. static void parse_dotcard(brh,cmd,cnt)
  1647. branch_t *brh;
  1648. const char *cmd;
  1649. int *cnt;
  1650. {
  1651.  (*cnt)++;
  1652.  setmatch(cmd,cnt);
  1653.  if (rematch("MODEL") || rematch("SUBCKT")){
  1654.     parse_dot_model(brh,cmd,cnt);
  1655.  }else{
  1656.     parse_dot_generic(brh,cmd);
  1657.     if (run_mode != rIGNORE)
  1658.        cmdproc(&cmd[*cnt]);
  1659.  }
  1660. }
  1661. /*--------------------------------------------------------------------------*/
  1662. static void print_dotcard(brh,where,detail)
  1663. const branch_t *brh;
  1664. int where;
  1665. int detail;
  1666. {
  1667.  mprintf(where, "%s\n", brh->label);
  1668. }
  1669. /*--------------------------------------------------------------------------*/
  1670. /*ARGSUSED*/
  1671. static void parse_dot_generic(brh,cmd)
  1672. branch_t *brh;
  1673. const char *cmd;
  1674. {
  1675.  int maxlen = sizeof(branch_t) - (&(brh->label[0]) - (char*)brh);
  1676.  (void)strncpy(brh->label, cmd, maxlen);
  1677. }
  1678. /*--------------------------------------------------------------------------*/
  1679. static void parse_dot_model(brh,cmd,cnt)
  1680. branch_t *brh;
  1681. const char *cmd;
  1682. int *cnt;
  1683. {
  1684.  branch_t *new;
  1685.  volatile int labelcnt;
  1686.  
  1687.  new = brh;
  1688.  labelcnt = *cnt;
  1689.  (void)ctostr(cmd, cnt, brh->label, LABELEN);
  1690.  setmatch(cmd,cnt);
  1691.       if (rematch("D"    ))  new = (*(model_diode.create))((branch_t*)NULL);
  1692.  else if (rematch("NPn"    ))  new = (*(model_bjt.create))((branch_t*)NULL);
  1693.  else if (rematch("PNp"    ))  new = (*(model_bjt.create))((branch_t*)NULL);
  1694.  else if (rematch("NJf"    ))  syntax(cmd,cnt,bWARNING);
  1695.  else if (rematch("PJf"    ))  syntax(cmd,cnt,bWARNING);
  1696.  else if (rematch("NMos"))  new = (*(model_mos.create))((branch_t*)NULL);
  1697.  else if (rematch("PMos"))  new = (*(model_mos.create))((branch_t*)NULL);
  1698.  else if (rematch("Logic")) new = (*(model_logic.create))((branch_t*)NULL);
  1699.  else                new = (*(model_subckt.create))((branch_t*)NULL);
  1700.  if (new != brh){
  1701.     *brh = *new;
  1702.     if (new->n == new->nodes)
  1703.        brh->n = brh->nodes;    
  1704.     free((void*)new);
  1705.     parse_branch(brh,cmd,&labelcnt);
  1706.  }
  1707. }
  1708. /*--------------------------------------------------------------------------*/
  1709. /*--------------------------------------------------------------------------*/
  1710. SHAR_EOF
  1711. fi # end of overwriting check
  1712. #    End of shell archive
  1713. exit 0
  1714.