1 /**********
2 Copyright 1990 Regents of the University of California. All rights reserved.
3 Author: 1988 Thomas L. Quarles
4 **********/
5
6 #include "ngspice/ngspice.h"
7 #include "ngspice/ifsim.h"
8 #include "ngspice/inpdefs.h"
9 #include "ngspice/inpmacs.h"
10 #include "ngspice/fteext.h"
11 #include "inpxx.h"
12
INP2L(CKTcircuit * ckt,INPtables * tab,struct card * current)13 void INP2L(CKTcircuit *ckt, INPtables * tab, struct card *current)
14 {
15
16 /* parse an inductor card */
17 /* Lname <node> <node> [<val>] [<mname>] [IC=<val>] */
18
19 int mytype = -1; /* the type we determine inductors are */
20 int type = 0; /* the type the model says it is */
21 char *line; /* the part of the current line left to parse */
22 char *saveline; /* ... just in case we need to go back... */
23 char *name; /* the resistor's name */
24 char *model; /* the name of the inductor's model */
25 char *nname1; /* the first node's name */
26 char *nname2; /* the second node's name */
27 CKTnode *node1; /* the first node's node pointer */
28 CKTnode *node2; /* the second node's node pointer */
29 double val; /* temp to held inductance */
30 int error; /* error code temporary */
31 int error1; /* secondary error code temporary */
32 INPmodel *thismodel; /* pointer to model structure describing our model */
33 GENmodel *mdfast = NULL; /* pointer to the actual model */
34 GENinstance *fast; /* pointer to the actual instance */
35 IFvalue ptemp; /* a value structure to package inductance into */
36 int waslead; /* flag to indicate that funny unlabeled number was found */
37 double leadval; /* actual value of unlabeled number */
38 IFuid uid; /* uid for default cap model */
39
40 #ifdef TRACE
41 printf("In INP2L, Current line: %s\n", current->line);
42 #endif
43
44 if (mytype < 0) {
45 if ((mytype = INPtypelook("Inductor")) < 0) {
46 LITERR("Device type Inductor not supported by this binary\n");
47 return;
48 }
49 }
50 line = current->line;
51 INPgetNetTok(&line, &name, 1);
52 INPinsert(&name, tab);
53 INPgetNetTok(&line, &nname1, 1);
54 INPtermInsert(ckt, &nname1, tab, &node1);
55 INPgetNetTok(&line, &nname2, 1);
56 INPtermInsert(ckt, &nname2, tab, &node2);
57 val = INPevaluate(&line, &error1, 1);
58
59 saveline = line;
60
61 INPgetNetTok(&line, &model, 1);
62
63 if (*model && (strcmp(model, "l") != 0)) {
64 /* token isn't null */
65 if (INPlookMod(model)) {
66 /* If this is a valid model connect it */
67 INPinsert(&model, tab);
68 current->error = INPgetMod(ckt, model, &thismodel, tab);
69 if (thismodel != NULL) {
70 if (mytype != thismodel->INPmodType) {
71 LITERR("incorrect model type");
72 return;
73 }
74 mdfast = thismodel->INPmodfast;
75 type = thismodel->INPmodType;
76 }
77 } else {
78 tfree(model);
79 /* It is not a model */
80 line = saveline; /* go back */
81 type = mytype;
82 if (!tab->defLmod) { /* create default L model */
83 IFnewUid(ckt, &uid, NULL, "L", UID_MODEL, NULL);
84 IFC(newModel, (ckt, type, &(tab->defLmod), uid));
85 }
86 mdfast = tab->defLmod;
87 }
88 IFC(newInstance, (ckt, mdfast, &fast, name));
89 } else {
90 tfree(model);
91 /* The token is null or we have l=val - a default model will be created */
92 type = mytype;
93 if (!tab->defLmod) {
94 /* create default L model */
95 IFnewUid(ckt, &uid, NULL, "L", UID_MODEL, NULL);
96 IFC(newModel, (ckt, type, &(tab->defLmod), uid));
97 }
98 IFC(newInstance, (ckt, tab->defLmod, &fast, name));
99 if (error1 == 1) { /* was a l=val construction */
100 val = INPevaluate(&line, &error1, 1); /* [<val>] */
101 #ifdef TRACE
102 printf ("In INP2L, L=val construction: val=%g\n", val);
103 #endif
104 }
105 }
106
107 if (error1 == 0) { /* Looks like a number */
108 ptemp.rValue = val;
109 GCA(INPpName, ("inductance", &ptemp, ckt, type, fast));
110 }
111
112 IFC(bindNode, (ckt, fast, 1, node1));
113 IFC(bindNode, (ckt, fast, 2, node2));
114 PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab));
115 if (waslead) {
116 ptemp.rValue = leadval;
117 GCA(INPpName, ("inductance", &ptemp, ckt, type, fast));
118 }
119
120 return;
121 }
122