38 #define strcasecmp stricmp
89 static struct property_t req_spice_NODESET[] = {
100 req_spice_R, opt_spice_R },
103 req_spice_L, spice_noprops },
106 req_spice_C, spice_noprops },
109 req_spice_V, spice_noprops },
112 req_spice_I, spice_noprops },
115 req_spice_G, spice_noprops },
118 req_spice_E, spice_noprops },
121 req_spice_F, spice_noprops },
124 req_spice_H, spice_noprops },
127 spice_noprops, spice_noprops },
130 spice_noprops, spice_noprops },
133 spice_noprops, spice_noprops },
136 spice_noprops, spice_noprops },
139 spice_noprops, spice_noprops },
142 spice_noprops, spice_noprops },
145 req_spice_T, spice_noprops },
148 spice_noprops, spice_noprops },
151 spice_noprops, spice_noprops },
154 spice_noprops, spice_noprops },
157 spice_noprops, spice_noprops },
160 spice_noprops, spice_noprops },
163 spice_noprops, spice_noprops },
166 req_spice_NODESET, spice_noprops },
169 req_spice_IC, spice_noprops },
172 { NULL, 0, 0, 0, 0, spice_noprops, spice_noprops },
179 #define foreach_value(values,val) \
180 for ((val) = (values); (val) != NULL; (val) = (val)->next) \
181 if (!((val)->hint & HINT_DONE))
187 for (root = NULL; values != NULL; values =
next) {
199 for (root = NULL; pairs != NULL; pairs =
next) {
211 for (root = NULL; nodes != NULL; nodes =
next) {
222 if (p1 == NULL)
return p2;
224 for (pair = p1; pair->
next != NULL; pair = pair->
next) ;
232 if (v1 == NULL)
return v2;
234 for (val = v1; val->
next != NULL; val = val->
next) ;
242 if (n1 == NULL)
return n2;
244 for (node = n1; node->
next != NULL; node = node->
next) ;
251 static struct define_t * spice_find_definition (
const char *
n) {
253 for (def = spice_definition_available; def->
type != NULL; def++)
254 if (!strcasecmp (n, def->
type))
return def;
259 static struct node_t * spice_translate_node (
char *
node) {
261 if (!strcmp (node,
"0")) {
265 n->
node = (
char *) malloc (5 + strlen (node));
266 strcpy (n->
node,
"_net");
267 strcat (n->
node, node);
269 for (
unsigned int i = 0;
i < strlen (n->
node);
i++) {
270 if (!isalpha (n->
node[
i]) && !isdigit (n->
node[
i])) {
271 switch (n->
node[
i]) {
272 case '+': n->
node[
i] =
'P';
break;
273 case '-': n->
node[
i] =
'N';
break;
274 default : n->
node[
i] =
'_';
break;
284 static void spice_value_done (
struct value_t * val) {
296 if (nodes == 0)
return NULL;
300 struct node_t * root = NULL;
304 struct node_t * n = spice_translate_node (val->
ident);
307 spice_value_done (val);
309 if (++i >= nodes && nodes !=
PROP_NODES)
break;
324 spice_evaluate_scale (
char * value,
char ** endptr,
double * factor) {
325 const char * scale = NULL;
329 value++; scale =
"T";
break;
331 value++; scale =
"G";
break;
333 value++; scale = (
char *) ((*value ==
'M') ?
"M" :
"m");
334 if ((value[0] ==
'i' || value[0] ==
'I') &&
335 (value[1] ==
'l' || value[1] ==
'L')) {
336 value += 2; *factor = 2.54e-5; scale = NULL;
338 if ((value[0] ==
'e' || value[0] ==
'E') &&
339 (value[1] ==
'g' || value[1] ==
'G')) {
340 value += 2; scale =
"M";
344 value++; scale =
"k";
break;
346 value++; scale =
"u";
break;
348 value++; scale =
"n";
break;
350 value++; scale =
"p";
break;
352 value++; scale =
"f";
break;
360 static struct value_t * spice_create_value (
const char *
ident) {
366 val->
value = strtod (ident, &end);
368 str = spice_evaluate_scale (end, &end, &value);
370 val->
scale = str ? strdup (str) : NULL;
371 if (*end) val->
unit = strdup (end);
380 struct pair_t * p, * root = NULL;
390 p->
key = strdup (prop->
key);
394 spice_value_done (val);
398 else if ((def->
type[0] ==
'F' || def->
type[0] ==
'H') &&
399 strcasecmp (val->
ident,
"POLY") &&
412 p->
value = spice_create_value (val->
unit);
415 spice_value_done (val);
427 if (def->
action && !strcasecmp (def->
type,
"MODEL") &&
428 !strcasecmp (def->
instance, type)) {
439 spice_find_device_instance (
struct definition_t * def) {
454 {
"NPN",
"BJT",
"npn" },
455 {
"PNP",
"BJT",
"pnp" },
456 {
"NJF",
"JFET",
"nfet" },
457 {
"PJF",
"JFET",
"pfet" },
458 {
"NMOS",
"MOSFET",
"nfet" },
459 {
"PMOS",
"MOSFET",
"pfet" },
460 {
"D",
"Diode", NULL },
461 {
"SW",
"Relais", NULL },
462 {
"VSWITCH",
"Relais", NULL },
463 {
"RES",
"R", NULL },
472 static struct pair_t * spice_generate_Model_pairs (
struct value_t * values) {
473 struct pair_t * root = NULL;
479 p->
value = spice_create_value (val->
unit);
493 spice_find_property (
struct definition_t * def,
const char * prop) {
495 for (pair = def->
pairs; pair != NULL; pair = pair->
next) {
496 if (!strcmp (pair->
key, prop))
504 spice_find_property_nocase (
struct definition_t * def,
const char * prop) {
506 for (pair = def->
pairs; pair != NULL; pair = pair->
next) {
507 if (!strcasecmp (pair->
key, prop))
516 spice_find_property_nocase (
struct pair_t * pair,
const char * prop) {
517 for (; pair != NULL; pair = pair->
next) {
518 if (!strcasecmp (pair->
key, prop))
528 spice_find_property (
struct value_t * values,
const char * prop) {
531 if (!strcasecmp (prop, val->
ident))
return val;
539 spice_set_property_string (
struct definition_t * def,
const char * key,
541 struct pair_t * prop = spice_find_property (def, key);
548 prop->
key = strdup (key);
557 static double spice_evaluate_value (
struct value_t * value) {
558 double val = value->
value, factor = 1.0;
559 if (value->
scale != NULL) {
560 switch (*(value->
scale)) {
561 case 'T': factor = 1e12;
break;
562 case 'G': factor = 1e9;
break;
563 case 'M': factor = 1e6;
break;
564 case 'k': factor = 1e3;
break;
565 case 'm': factor = 1
e-3;
break;
566 case 'u': factor = 1
e-6;
break;
567 case 'n': factor = 1
e-9;
break;
568 case 'p': factor = 1
e-12;
break;
569 case 'f': factor = 1
e-15;
break;
576 static void netlist_free_value (
struct value_t * value) {
578 if (value->
unit) free (value->
unit);
584 static void netlist_free_values (
struct value_t * value) {
586 for (; value != NULL; value =
next) {
588 netlist_free_value (value);
594 if (pair->
value) netlist_free_values (pair->
value);
609 for (prev = root; prev != NULL && prev->
next != pair; prev = prev->
next) ;
620 static void spice_adjust_device (
struct definition_t * def,
624 struct value_t * val, * start = NULL;
637 if (!strcasecmp (tran->
type, start->
ident)) {
640 p = spice_generate_Model_pairs (start->
next);
649 if ((p1 = spice_find_property (def,
"LEVEL")) != NULL) {
650 double level = spice_evaluate_value (p1->
value);
652 if ((p2 = spice_find_property (def,
"VERSION")) != NULL) {
653 double version = spice_evaluate_value (p2->
value);
656 if (version >= 1.11) {
658 def->
type = strdup (
"hicumL0V1p3");
659 else if (version >= 1.2)
660 def->
type = strdup (
"hicumL0V1p2");
662 def->
type = strdup (
"hic0_full");
664 spice_set_property_string (def,
"Type",
670 else if (level == 2 && version == 2.1) {
671 def->
type = strdup (
"hicumL2V2p1");
674 else if (level == 2 && version >= 2.21 && version <= 2.22) {
675 def->
type = strdup (
"hic2_full");
678 else if (level == 2 && version == 2.23) {
679 def->
type = strdup (
"hicumL2V2p23");
682 else if (level == 2 && version >= 2.24) {
683 def->
type = strdup (
"hicumL2V2p24");
703 static void spice_translate_device (
struct definition_t * root,
705 struct value_t * inst = spice_find_device_instance (def);
708 if (inst == NULL)
return;
713 if ((tran = spice_find_device (root, inst->
ident)) == NULL)
714 tran = spice_find_device (definition_root, inst->
ident);
717 spice_value_done (inst);
718 spice_adjust_device (def, tran);
720 else if (!strcasecmp (def->
type,
"C")) {
724 fprintf (stderr,
"spice error, no such .MODEL `%s' found as specified in "
736 if (!strcmp (entry->
type, def->
type))
return entry;
764 static int spice_translate_type (
struct definition_t * def) {
769 if (!strcasecmp (tran->
type, def->
type)) {
770 if (!spice_find_property (def->
values,
"POLY")) {
845 { NULL, 0, { -1 }, { -1 } }
849 static int spice_count_nodes (
struct definition_t * def) {
851 for (
struct node_t * node = def->
nodes; node != NULL; node = node->
next)
857 static void netlist_free_nodes (
struct node_t * node) {
859 for (; node != NULL; node =
n) {
867 static void netlist_free_pairs (
struct pair_t * pair) {
869 for (; pair != NULL; pair =
n) {
879 for (i = 1, node = def->
nodes; node != NULL; node = node->
next, i++)
880 if (i == pos)
return node;
886 static void spice_translate_nodes (
struct definition_t * def,
int pass) {
891 if (!strcmp (nodes->
type, def->
type))
break;
892 if (nodes->
type == NULL || pass != nodes->
pass)
return;
894 struct define_t * entry = spice_get_qucs_definition (def);
896 if (entry->
nodes > spice_count_nodes (def)) {
897 for (
int n = spice_count_nodes (def); n < entry->
nodes; n++) {
909 sprintf (txt,
"%s%d",
"_node", n);
910 node->
node = strdup (txt);
917 struct node_t * root = NULL;
918 for (
int n = entry->
nodes - 1; n >= 0; n--) {
925 netlist_free_nodes (def->
nodes);
951 static void spice_translate_units (
struct definition_t * def) {
952 for (
struct pair_t * pair = def->
pairs; pair != NULL; pair = pair->
next) {
958 if (!strcasecmp (unit->
key, value->
unit)) {
975 static void spice_adjust_default_properties (
struct definition_t * def) {
976 struct define_t * entry = spice_get_qucs_definition (def);
977 if (entry == NULL)
return;
982 if (spice_find_property (def, prop->
key) == NULL) {
984 pair->
key = strdup (prop->
key);
999 static void spice_adjust_optional_properties (
struct definition_t * def) {
1000 struct define_t * entry = spice_get_qucs_definition (def);
1001 if (entry == NULL)
return;
1006 if (spice_find_property (def, prop->
key) == NULL) {
1008 pair->
key = strdup (prop->
key);
1029 { NULL,
"CCS",
"Cjs" },
1030 { NULL,
"VA",
"Vaf" },
1031 { NULL,
"VB",
"Var" },
1032 { NULL,
"IK",
"Ikf" },
1033 { NULL,
"PE",
"Vje" },
1034 { NULL,
"ME",
"Mje" },
1035 { NULL,
"PC",
"Vjc" },
1036 { NULL,
"MC",
"Mjc" },
1037 { NULL,
"PS",
"Vjs" },
1038 { NULL,
"MS",
"Mjs" },
1040 { NULL,
"VTO",
"Vt0" },
1041 { NULL,
"U0",
"Uo" },
1043 { NULL,
"CJO",
"Cj0" },
1047 { NULL,
"Z0",
"Z" },
1048 {
"R",
"TC",
"Tc1" },
1050 { NULL, NULL, NULL }
1058 for (; prop->
key != NULL; prop++) {
1060 if (!strcasecmp (prop->
key, pair->
key)) {
1072 struct define_t * entry = spice_get_qucs_definition (def);
1075 for (pair = def->
pairs; pair != NULL; pair = pair->
next) {
1105 static void spice_append_pair (
struct definition_t * def,
const char * prop,
1106 const char * value,
int replace) {
1107 struct pair_t * p = spice_find_property (def, prop);
1110 netlist_free_value (p->
value);
1111 p->
value = spice_create_value (value);
1117 p->
key = strdup (prop);
1118 p->
value = spice_create_value (value);
1124 static void spice_append_node (
struct definition_t * def,
char * node) {
1126 n->
node = strdup (node);
1131 static char * spice_toupper (
char * str) {
1132 for (
unsigned int i = 0; i < strlen (str); i++) {
1133 if (str[i] >=
'a' && str[i] <=
'z') str[
i] = toupper (str[i]);
1140 static void spice_adjust_instance (
struct definition_t * def) {
1147 static void spice_fixup_definition (
struct definition_t * def) {
1148 spice_adjust_instance (def);
1150 spice_translate_nodes (def, 0);
1151 spice_translate_units (def);
1152 spice_adjust_default_properties (def);
1160 spice_fixup_definition (def);
1166 static void netlist_destroy_intern (
struct definition_t *);
1171 netlist_free_nodes (def->
nodes);
1172 netlist_free_pairs (def->
pairs);
1173 netlist_free_values (def->
values);
1176 if (def->
sub) netlist_destroy_intern (def->
sub);
1183 static void netlist_destroy_intern (
struct definition_t * root) {
1185 for (def = root; def != NULL; def =
next) {
1187 netlist_free_definition (def);
1193 netlist_destroy_intern (definition_root);
1194 netlist_destroy_intern (device_root);
1196 netlist_destroy_intern (def->
sub);
1198 netlist_destroy_intern (subcircuit_root);
1199 definition_root = subcircuit_root = device_root = NULL;
1212 netlist_free_definition (def);
1216 for (prev = root; prev != NULL && prev->
next != def; prev = prev->
next) ;
1219 netlist_free_definition (def);
1229 static char * spice_create_intern_node (
void) {
1230 static int intern = 0;
1231 static char txt[32];
1232 sprintf (txt,
"_cnet%d", intern++);
1239 static void spice_adjust_vsource_nodes (
struct definition_t * up,
1241 struct node_t * node = spice_get_node (dn, 1);
1242 spice_append_node (up, node->
node);
1243 char * inode = spice_create_intern_node ();
1244 spice_append_node (up, inode);
1246 node->
node = strdup (inode);
1251 static void spice_adjust_isource_nodes (
struct definition_t * left,
1254 node = spice_get_node (right, 1);
1255 spice_append_node (left, node->
node);
1256 node = spice_get_node (right, 2);
1257 spice_append_node (left, node->
node);
1264 spice_create_definition (
struct definition_t * base,
const char * type) {
1266 res->
type = strdup (type);
1277 spice_get_property_value (
struct definition_t * def,
const char * key) {
1278 struct pair_t * prop = spice_find_property (def, key);
1279 return prop ? spice_evaluate_value (prop->
value) : 0;
1285 spice_set_property_value (
struct definition_t * def,
const char * key,
1287 struct pair_t * prop = spice_find_property (def, key);
1303 prop->
key = strdup (key);
1319 static void spice_extract_properties (
struct definition_t * def,
1326 if (field->
field[i] == NULL)
break;
1328 spice_set_property_string (def, field->
field[i], val->
ident);
1331 spice_append_pair (def, field->
field[i], val->
ident, 0);
1334 spice_value_done (val);
1343 static char * spice_untranslated_text (
struct definition_t * def) {
1347 char * txt = (
char *) malloc (strlen (str) + 1);
1349 for (val = def->
values; val != NULL; val = val->
next) {
1351 sprintf (str,
"%s ", val->
ident);
1361 sprintf (str,
"%s%s%s%s",
1370 txt = (
char *) realloc (txt, strlen (txt) + strlen (str) + 1);
1373 return spice_toupper (txt);
1376 #define VAL_IS_NUMBER(val) \
1378 (val)->hint & (HINT_NUMBER | HINT_NODE) && \
1379 !((val)->hint & HINT_DONE))
1381 #define VAL_IS_DONE(val) \
1382 ((val) == NULL || (val)->hint & HINT_DONE)
1386 static int spice_count_real_values (
struct value_t * values) {
1405 struct definition_t * ac = NULL, * dc = def, * pulse = NULL, * expo = NULL;
1407 char * ui = (
char *) ((type ==
'U') ?
"U" :
"I");
1410 if ((prop = spice_find_property (dc->values,
"DC")) != NULL) {
1411 spice_value_done (prop);
1414 spice_append_pair (def, ui, prop->
ident, 1);
1415 spice_value_done (prop);
1419 dc->type = strdup (type ==
'U' ?
"Vdc" :
"Idc");
1422 if ((prop = spice_find_property (dc->values,
"SIN")) != NULL) {
1423 ac = spice_create_definition (dc, type ==
'U' ?
"Vac" :
"Iac");
1424 spice_value_done (prop);
1429 off = spice_get_property_value (dc, ui);
1430 spice_append_pair (dc, ui, prop->
ident, 1);
1431 off += spice_get_property_value (dc, ui);
1432 spice_set_property_value (dc, ui, off);
1433 spice_value_done (prop);
1437 { { ui,
"f",
"Phase",
"Theta", NULL } };
1438 spice_extract_properties (ac, prop, &field);
1441 f = spice_get_property_value (ac,
"f");
1442 v = spice_get_property_value (ac,
"Phase") * f * -360.0;
1443 spice_set_property_value (ac,
"Phase", v);
1444 v = spice_get_property_value (ac,
"Theta") / f;
1445 spice_set_property_value (ac,
"Theta", f > 0 ? v : 0);
1449 if ((prop = spice_find_property (dc->values,
"AC")) != NULL) {
1450 char * Mag = NULL, * Phase = NULL;
1451 spice_value_done (prop);
1454 Mag = strdup (prop->
ident);
1455 spice_value_done (prop);
1458 Phase = strdup (prop->
ident);
1459 spice_value_done (prop);
1463 ac = spice_create_definition (dc, type ==
'U' ?
"Vac" :
"Iac");
1466 spice_append_pair (ac, ui, Mag, 1);
1470 spice_append_pair (ac, ui,
"0", 0);
1473 spice_append_pair (ac,
"Phase", Phase, 1);
1479 if ((prop = spice_find_property (dc->values,
"PULSE")) != NULL) {
1480 pulse = spice_create_definition (dc, type ==
'U' ?
"Vpulse" :
"Ipulse");
1481 spice_value_done (prop);
1485 if (spice_count_real_values (prop) > 6) {
1487 pulse->type = type ==
'U' ? strdup (
"Vrect") : strdup (
"Irect");
1488 double add, off = 0;
1490 add = spice_get_property_value (dc, ui);
1491 spice_append_pair (dc, ui, prop->
ident, 1);
1492 off = spice_get_property_value (dc, ui);
1494 spice_set_property_value (dc, ui, add);
1499 { { ui,
"Td",
"Tr",
"Tf",
"TH",
"TL", NULL } };
1500 spice_extract_properties (pulse, prop, &field);
1503 v = spice_get_property_value (pulse, ui);
1505 spice_set_property_value (pulse, ui, v);
1506 v = spice_get_property_value (pulse,
"TH");
1507 v += spice_get_property_value (pulse,
"Tr");
1508 spice_set_property_value (pulse,
"TH", v);
1509 v = spice_get_property_value (pulse,
"TL");
1510 v -= spice_get_property_value (pulse,
"TH");
1511 spice_set_property_value (pulse,
"TL", v);
1516 spice_append_pair (pulse, type ==
'U' ?
"U1" :
"I1", prop->
ident, 0);
1517 spice_append_pair (dc, ui,
"0", 0);
1518 spice_value_done (prop);
1521 { { type ==
'U' ?
"U2" :
"I2",
"T1",
"Tr",
"Tf",
"T2", NULL } };
1522 spice_extract_properties (pulse, prop, &field);
1525 v = spice_get_property_value (pulse,
"T1");
1526 v += spice_get_property_value (pulse,
"Tr");
1527 v += spice_get_property_value (pulse,
"Tf");
1528 v += spice_get_property_value (pulse,
"T2");
1529 spice_set_property_value (pulse,
"T2", v);
1534 if ((prop = spice_find_property (dc->values,
"EXP")) != NULL) {
1535 expo = spice_create_definition (dc, type ==
'U' ?
"Vexp" :
"Iexp");
1536 spice_value_done (prop);
1540 { { type ==
'U' ?
"U1" :
"I1", type ==
'U' ?
"U2" :
"I2",
"T1",
"Tr",
1541 "T2",
"Tf", NULL } };
1542 spice_extract_properties (expo, prop, &field);
1546 if (spice_find_property (dc, ui) == NULL) {
1547 spice_append_pair (def, ui,
"0", 1);
1553 spice_adjust_vsource_nodes (ac, dc);
1555 spice_adjust_isource_nodes (ac, dc);
1556 root = spice_add_definition (root, ac);
1560 spice_adjust_vsource_nodes (pulse, ac ? ac : dc);
1562 spice_adjust_isource_nodes (pulse, ac ? ac : dc);
1563 root = spice_add_definition (root, pulse);
1567 spice_adjust_vsource_nodes (expo, pulse ? pulse : ac ? ac : dc);
1569 spice_adjust_isource_nodes (expo, pulse ? pulse : ac ? ac : dc);
1570 root = spice_add_definition (root, expo);
1578 static char * spice_create_intern_para (
void) {
1579 static int intern = 1;
1580 static char txt[32];
1581 sprintf (txt,
"SW%d", intern++);
1589 static int spice_evaluate_points (
char ** type,
double start,
double stop,
1592 if (!strcasecmp (*type,
"dec")) {
1593 ret = (int) ((
log10 (stop) -
log10 (start)) * points);
1595 *type = strdup (
"log");
1597 else if (!strcasecmp (*type,
"lin")) {
1600 *type = strdup (
"lin");
1602 else if (!strcasecmp (*type,
"oct")) {
1603 ret = (int) (((
log10 (stop) -
log10 (start)) /
log10 (8.0)) * points);
1605 *type = strdup (
"log");
1615 { {
"Param",
"Start",
"Stop",
"Points", NULL } };
1618 para->
type = strdup (
"SW");
1620 para->
instance = strdup (spice_create_intern_para ());
1622 spice_extract_properties (para, base->
values, &props);
1623 spice_set_property_string (para,
"Type",
"lin");
1625 v = spice_get_property_value (para,
"Stop");
1626 v -= spice_get_property_value (para,
"Start");
1627 v /= spice_get_property_value (para,
"Points");
1629 spice_set_property_value (para,
"Points", v);
1636 static int spice_count_values (
struct value_t * values) {
1637 int res = 0;
struct value_t * val;
1646 spice_find_definition (struct
definition_t * root, const
char * type,
1649 if (!strcasecmp (def->
type, type) && !strcasecmp (def->
instance, inst))
1659 spice_find_definition (
struct definition_t * root,
const char * type) {
1661 if (!strcasecmp (def->
type, type))
1669 static void spice_add_property (
struct definition_t * root,
const char * type,
1670 const char * key,
char * value) {
1672 if (!strcmp (def->
type, type))
1673 spice_append_pair (def, key, value, 0);
1679 static void spice_free_values (
struct definition_t * def) {
1680 if (spice_count_values (def->
values) <= 0) {
1682 for (val = def->
values; val != NULL; val = next) {
1684 netlist_free_value (val);
1695 static void spice_collect_external_nodes (
struct definition_t * def) {
1704 else netlist_free_nodes (n);
1714 for (dev = device_root; dev; dev = dev->
next) {
1715 if (!strcmp (dev->
instance, instance))
1726 if (strcasecmp (def->
type,
"MODEL"))
1728 if (spice_find_Model (def->
instance))
1734 spice_adjust_device (Model, def);
1735 if (spice_translate_type (Model)) {
1736 spice_fixup_definition (Model);
1737 spice_adjust_optional_properties (Model);
1739 device_root = Model;
1753 const char * type,
char * inst) {
1755 if (def != coupled && !strcmp (def->
type, type) && !def->
action) {
1760 if (!strcasecmp (linst1, inst) || !strcasecmp (linst2, inst))
1770 spice_find_coupled (
struct definition_t * root,
const char * type,
1771 char * inst1,
char * inst2) {
1773 if (!strcmp (def->
type, type) && !def->
action) {
1778 if ((!strcasecmp (linst1, inst1) && !strcasecmp (linst2, inst2)) ||
1779 (!strcasecmp (linst1, inst2) && !strcasecmp (linst2, inst1)))
1789 spice_find_coupled_inductor (
struct definition_t * root,
1793 target = spice_find_definition (root, type, inst);
1794 if (target == NULL) {
1795 fprintf (stderr,
"spice error, no such inductor `%s' found as "
1796 "referenced by %s `%s'\n", inst, def->
type, def->
instance);
1816 char * inst = (
char *) malloc (strlen (k1->
instance) +
1832 nr_double_t l1, l2, l3, k,
t;
1837 n1 = n2 = n3 = n4 = NULL;
1838 l1 = l2 = l3 = k = t = 0;
1841 target1 = spice_find_coupled_inductor (root, def,
"L", linst1);
1844 target2 = spice_find_coupled_inductor (root, def,
"L", linst2);
1847 if (!target1 || !target2)
return root;
1849 l1 = spice_get_property_value (target1,
"L");
1850 l2 = spice_get_property_value (target2,
"L");
1854 char * k12, * k13, * k23;
1855 k2 = spice_find_coupled (root, k1,
"Tr", linst1);
1856 k3 = spice_find_coupled (root, k1,
"Tr", linst2);
1859 if (k2 != NULL && k3 != NULL) {
1860 char * linst3, * linst4;
1861 if (!strcasecmp (k2->values->ident, linst1))
1862 linst3 = k2->values->next->ident;
1864 linst3 = k2->values->ident;
1865 if (!strcasecmp (k3->values->ident, linst2))
1866 linst4 = k3->values->next->ident;
1868 linst4 = k3->values->ident;
1869 spice_value_done (k1->
values);
1872 if (strcasecmp (linst3, linst4)) {
1873 fprintf (stderr,
"spice error, cannot translate coupled inductors "
1874 "`%s' and `%s'\n", linst3, linst4);
1877 else if (k2 != k3) {
1879 target3 = spice_find_coupled_inductor (root, k2,
"L", linst3);
1880 if (target3 != NULL) {
1883 char * inst = spice_coupled_instance (k1, k2, k3);
1884 free (k1->
type); k1->
type = strdup (
"MUT2");
1886 netlist_free_pairs (k1->
pairs); k1->
pairs = NULL;
1887 spice_value_done (k2->values);
1888 spice_value_done (k2->values->next);
1889 spice_value_done (k3->values);
1890 spice_value_done (k3->values->next);
1891 spice_append_node (k1, spice_get_node(target1, 1)->node);
1892 spice_append_node (k1, spice_get_node(target3, 1)->node);
1893 spice_append_node (k1, spice_get_node(target3, 2)->node);
1894 spice_append_node (k1, spice_get_node(target2, 2)->node);
1895 spice_append_node (k1, spice_get_node(target2, 1)->node);
1896 spice_append_node (k1, spice_get_node(target1, 2)->node);
1897 l3 = spice_get_property_value (target3,
"L");
1898 spice_set_property_value (k1,
"L1", l1);
1899 spice_set_property_value (k1,
"L2", l2);
1900 spice_set_property_value (k1,
"L3", l3);
1901 if ((val = spice_get_value_coupled (k1)) != NULL) {
1903 spice_append_pair (k1,
"k12", k12, 0);
1904 spice_value_done (val);
1906 if ((val = spice_get_value_coupled (k2)) != NULL) {
1908 spice_append_pair (k1,
"k13", k13, 0);
1909 spice_value_done (val);
1911 if ((val = spice_get_value_coupled (k3)) != NULL) {
1913 spice_append_pair (k1,
"k23", k23, 0);
1914 spice_value_done (val);
1926 spice_value_done (def->
values);
1930 nn = spice_get_node (target1, 2);
1932 nn->
node = strdup (spice_create_intern_node ());
1933 n1 = strdup (nn->
node);
1936 nn = spice_get_node (target2, 2);
1938 nn->
node = strdup (spice_create_intern_node ());
1939 n2 = strdup (nn->
node);
1943 spice_append_pair (def,
"T",
"1", 1);
1944 if ((val = spice_get_value_coupled (def)) != NULL) {
1945 spice_append_pair (def,
"T", val->
ident, 1);
1946 spice_value_done (val);
1950 k = spice_get_property_value (def,
"T");
1952 spice_set_property_value (def,
"T", t);
1953 spice_append_node (def, n1);
1954 spice_append_node (def, n2);
1955 spice_append_node (def, n3);
1956 spice_append_node (def, n4);
1958 spice_set_property_value (target1,
"L", l1 - k * l1);
1959 spice_set_property_value (target2,
"L", l2 - k * l1 / t / t);
1962 struct definition_t * Mind = spice_create_definition (def,
"L");
1963 spice_append_node (Mind, n1);
1964 spice_append_node (Mind, n4);
1965 spice_set_property_value (Mind,
"L", k * l1);
1966 root = spice_add_definition (root, Mind);
1968 free (n1); free (n2); free (n3); free (n4);
1977 const char * type,
char * inst) {
1979 if (!strcmp (def->
type, type) && !def->
action) {
1985 if (!strcasecmp (linst1, inst) || !strcasecmp (linst2, inst))
2000 const char * type,
char * inst) {
2005 while ((k = spice_find_coupled (root, K_hash, type, inst)) != NULL) {
2013 if (!L_hash->
get (linst)) {
2014 if ((l = spice_find_coupled_inductor (root, k,
"L", linst)) != NULL) {
2015 L_hash->
put (linst, l);
2017 root = spice_search_coupled (root, K_hash, L_hash, type, linst);
2023 if (!L_hash->
get (linst)) {
2024 if ((l = spice_find_coupled_inductor (root, k,
"L", linst)) != NULL) {
2025 L_hash->
put (linst, l);
2027 root = spice_search_coupled (root, K_hash, L_hash, type, linst);
2038 char * linst1, * linst2;
2046 if ((l = spice_find_coupled_inductor (root, def,
"L", linst1)) != NULL)
2047 L_hash.
put (linst1, l);
2049 if ((l = spice_find_coupled_inductor (root, def,
"L", linst2)) != NULL)
2050 L_hash.
put (linst2, l);
2054 root = spice_search_coupled (root, &K_hash, &L_hash,
"Tr", linst1);
2055 root = spice_search_coupled (root, &K_hash, &L_hash,
"Tr", linst2);
2058 int i, o,
s = L_hash.
count ();
2059 nr_double_t * kval =
new nr_double_t[s *
s];
2071 nr_double_t kvalue = 0;
2072 k = spice_find_coupled (root,
"Tr",
2075 if ((val = spice_get_value_coupled (k)) != NULL) {
2076 kvalue = spice_evaluate_value (val);
2079 kval[s * o +
i] = kvalue;
2080 kval[s * i + o] = kvalue;
2084 kval[s * o +
i] = 1;
2089 spice_value_done (def->
values);
2093 free (def->
type); def->
type = strdup (
"MUTX");
2094 netlist_free_pairs (def->
pairs); def->
pairs = NULL;
2098 pair->
key = strdup (
"L");
2101 spice_append_node (def, spice_get_node(it.
currentVal (), 1)->node);
2102 spice_append_node (def, spice_get_node(it.
currentVal (), 2)->node);
2111 pair->
key = strdup (
"k");
2113 for (i = 0; i < s *
s; i++) {
2132 spice_create_eqnstr (
struct definition_t * def,
int p,
char type) {
2133 char * n = (
char *) malloc (strlen (def->
instance) + 4 + 3);
2134 sprintf (n,
"%s.%c%d", def->
instance, type, p);
2146 char * ieq = spice_create_eqnstr (def, p,
'I');
2147 char * qeq = spice_create_eqnstr (def, p,
'Q');
2148 sprintf (I_,
"I%d", p);
2149 sprintf (Q_,
"Q%d", p);
2150 spice_set_property_string (def, Q_, qeq);
2151 spice_set_property_string (def, I_, ieq);
2152 ieqn = spice_create_definition (def,
"Eqn");
2153 qeqn = spice_create_definition (def,
"Eqn");
2154 spice_set_property_string (ieqn,
"Export",
"no");
2155 spice_set_property_string (qeqn,
"Export",
"no");
2156 spice_set_property_string (ieqn, ieq,
"0");
2157 spice_set_property_string (qeqn, qeq,
"0");
2158 root = spice_add_definition (root, qeqn);
2159 root = spice_add_definition (root, ieqn);
2160 sprintf (ieq,
"Eqn%sI%d", def->
instance, p);
2161 sprintf (qeq,
"Eqn%sQ%d", def->
instance, p);
2176 static void spice2g6_nxtpwr (
int * seq,
int nd) {
2188 if (seq[k - 1] != 0)
break;
2200 for (i = 0; i < k - 1; i++)
2201 if (seq[i] != 0)
break;
2203 seq[0] = seq[nd - 1] + 1;
2209 while (seq[k - 1] < 1) {
2222 static double spice_get_value (
struct value_t * val) {
2228 str = spice_evaluate_scale (end, &end, &v);
2230 val->
scale = str ? strdup (str) : NULL;
2231 if (*end) val->
unit = strdup (end);
2243 int * pn = (
int *) calloc (nd,
sizeof (
int));
2244 static char expr[1024];
2252 double k = spice_get_value (val);
2253 spice_value_done (val);
2259 sprintf (value,
"%+g", k);
2260 strcat (expr, value);
2263 for (
int i = 0; i < nd; i++) {
2264 int n = integrate ? i + 1 : i + 2;
2265 int e = integrate ? pn[
i] + 2 : pn[
i];
2271 sprintf (value,
"*V%d", n);
2274 sprintf (value,
"*V%d*V%d", n, n);
2277 sprintf (value,
"*V%d^%d", n, e);
2280 strcat (expr, value);
2283 if (integrate && e > 1) {
2284 sprintf (value,
"/%d", e);
2285 strcat (expr, value);
2291 spice2g6_nxtpwr (pn, nd);
2304 if (strcasecmp (def->
type,
"E") && strcasecmp (def->
type,
"G") &&
2305 strcasecmp (def->
type,
"F") && strcasecmp (def->
type,
"H"))
2309 if (!strcasecmp (def->
type,
"E"))
2311 else if (!strcasecmp (def->
type,
"G"))
2313 else if (!strcasecmp (def->
type,
"H"))
2315 else if (!strcasecmp (def->
type,
"F"))
2318 if ((prop = spice_find_property (def->
values,
"POLY")) != NULL) {
2321 def->
type = strdup (
"EDD");
2322 spice_value_done (prop);
2325 nd = (int) spice_evaluate_value (prop);
2326 spice_value_done (prop);
2332 for (
int i = nd * 2 - 1; i >= 0; i--) {
2333 int p = (i + 1) / 2 + 1;
2334 struct node_t * node = spice_translate_node (prop->
ident);
2336 if (i & 1) root = spice_add_edd_equation (root, def, p, NULL, NULL);
2337 spice_value_done (prop);
2344 for (
int i = nd; i > 0; i--) {
2346 char * vn, * np, * nn;
2350 vdc = spice_find_definition (root,
"Vdc", vn);
2354 ibuf = spice_create_definition (def,
"CCVS");
2355 vn = (
char *) malloc (strlen (ibuf->
instance) + 3);
2356 sprintf (vn,
"%sV%d", ibuf->
instance, p);
2359 struct node_t * node = spice_get_node (vdc, 1);
2360 np = strdup (spice_create_intern_node ());
2361 nn = strdup (spice_create_intern_node ());
2362 spice_append_node (ibuf, node->
node);
2364 node->
node = strdup (nn);
2365 spice_append_node (def, np);
2366 spice_append_node (def, (
char *)
"gnd");
2367 spice_append_node (ibuf, np);
2368 spice_append_node (ibuf, (
char *)
"gnd");
2369 spice_append_node (ibuf, nn);
2370 spice_set_property_string (ibuf,
"G",
"1");
2371 root = spice_add_definition (root, ibuf);
2376 fprintf (stderr,
"spice error, no such voltage source `%s' found as "
2377 "referenced by the %s `%s' instance\n", def->
type,
2381 root = spice_add_edd_equation (root, def, p, NULL, NULL);
2382 spice_value_done (prop);
2389 root = spice_add_edd_equation (root, def, 1, &ieqn, &qeqn);
2392 char * expr = spice_create_poly (prop, nd, 0);
2395 char * ieq = spice_create_eqnstr (def, 1,
'I');
2396 spice_set_property_string (ieqn, ieq, expr);
2401 struct node_t * pnode, * nnode;
2404 if ((type & 1) == 0)
2405 obuf = spice_create_definition (def,
"CCVS");
2406 else if ((type & 1) == 1)
2407 obuf = spice_create_definition (def,
"CCCS");
2409 pnode = spice_get_node (def, 1);
2410 nnode = spice_get_node (def, 2);
2411 intp = strdup (spice_create_intern_node ());
2413 spice_append_node (obuf, intp);
2414 spice_append_node (obuf, nnode->
node);
2415 spice_append_node (obuf, pnode->
node);
2416 spice_append_node (obuf, (
char *)
"gnd");
2419 pnode->
node = strdup (intp);
2421 nnode->
node = strdup (
"gnd");
2424 spice_set_property_string (obuf,
"G",
"1");
2425 root = spice_add_definition (root, obuf);
2439 if (!strcasecmp (def->
type,
"C"))
2441 else if (!strcasecmp (def->
type,
"L"))
2444 if ((prop = spice_find_property (def->
values,
"POLY")) != NULL) {
2447 def->
type = strdup (
"EDD");
2448 spice_value_done (prop);
2452 if ((p = spice_find_property (def,
"C")) != NULL) {
2453 lc = spice_get_property_value (def,
"C");
2456 else if ((p = spice_find_property (def,
"L")) != NULL) {
2457 lc = spice_get_property_value (def,
"L");
2463 root = spice_add_edd_equation (root, def, 1, &ieqn, &qeqn);
2466 char * expr1 = strdup (spice_create_poly (prop, 1, 1));
2467 char * expr2 = expr1;
2469 expr2 = (
char *) malloc (strlen (expr1) + 256);
2470 sprintf (expr2,
"%+g*V1%s", lc, expr1);
2475 char * qeq = spice_create_eqnstr (def, 1,
'Q');
2476 spice_set_property_string (qeqn, qeq, expr2);
2483 struct node_t * pnode, * nnode;
2486 gyra = spice_create_definition (def,
"Gyrator");
2488 pnode = spice_get_node (def, 1);
2489 nnode = spice_get_node (def, 2);
2490 intp = strdup (spice_create_intern_node ());
2492 spice_append_node (gyra, intp);
2493 spice_append_node (gyra, nnode->
node);
2494 spice_append_node (gyra, pnode->
node);
2495 spice_append_node (gyra, (
char *)
"gnd");
2498 pnode->
node = strdup (intp);
2500 nnode->
node = strdup (
"gnd");
2503 spice_set_property_string (gyra,
"R",
"1");
2504 root = spice_add_definition (root, gyra);
2517 if (def->
action && !strcmp (def->
type,
"SW")) {
2519 struct pair_t * prop = spice_find_property (def,
"Param");
2520 char * val = spice_toupper (prop->
value->
ident);
2523 target = spice_find_definition (root,
"Vdc", val);
2525 prop = spice_find_property (target,
"U");
2529 target = spice_find_definition (root,
"Idc", val);
2531 prop = spice_find_property (target,
"I");
2535 fprintf (stderr,
"spice error, no such source `%s' found as "
2536 "referenced by the .DC analysis\n", val);
2542 if (!def->
action && (!strcmp (def->
type,
"CCCS") ||
2543 !strcmp (def->
type,
"CCVS"))) {
2545 struct value_t * val = spice_find_device_instance (def);
2547 char * key = val->
ident;
2548 target = spice_find_definition (root,
"Vdc", key);
2551 spice_adjust_vsource_nodes (def, target);
2552 spice_translate_nodes (def, 1);
2555 fprintf (stderr,
"spice error, no such voltage source `%s' found "
2556 "as referenced by the %s `%s' instance\n", def->
type,
2563 if (!def->
action && (!strcmp (def->
type,
"F") ||
2564 !strcmp (def->
type,
"H"))) {
2565 root = spice_translate_poly (root, def);
2568 if (!def->
action && !strcmp (def->
type,
"Relais")) {
2569 struct pair_t * pon = spice_find_property_nocase (def,
"VON");
2570 struct pair_t * pof = spice_find_property_nocase (def,
"VOFF");
2571 if (pon != NULL && pof != NULL) {
2572 nr_double_t von = spice_evaluate_value (pon->
value);
2573 nr_double_t vof = spice_evaluate_value (pof->
value);
2576 nr_double_t vh = (von - vof) / 2;
2577 nr_double_t vt = (von + vof) / 2;
2578 spice_set_property_value (def,
"Vt", vt);
2579 spice_set_property_value (def,
"Vh", fabs (vh));
2583 if (!def->
action && (!strcmp (def->
type,
"Vpulse") ||
2584 !strcmp (def->
type,
"Ipulse") ||
2585 !strcmp (def->
type,
"Vrect") ||
2586 !strcmp (def->
type,
"Irect"))) {
2588 struct pair_t * tr = spice_find_property (def,
"Tr");
2589 struct pair_t * tf = spice_find_property (def,
"Tf");
2590 if (tr == NULL || tf == NULL) {
2591 if ((tran = spice_find_definition (definition_root,
"TR")) != NULL) {
2592 nr_double_t start = spice_get_property_value (tran,
"Start");
2593 nr_double_t stop = spice_get_property_value (tran,
"Stop");
2594 nr_double_t points = spice_get_property_value (tran,
"Points");
2595 nr_double_t tstep = (stop - start) / (points - 1);
2596 nr_double_t add = 0;
2598 spice_set_property_value (def,
"Tf", tstep);
2602 spice_set_property_value (def,
"Tr", tstep);
2605 if (!strcmp (&def->
type[1],
"pulse")) {
2606 nr_double_t t2 = spice_get_property_value (def,
"T2");
2607 spice_set_property_value (def,
"T2", t2 + add);
2613 if (!def->
action && (!strcmp (def->
type,
"Vac") ||
2614 !strcmp (def->
type,
"Iac"))) {
2616 struct pair_t * f = spice_find_property (def,
"f");
2618 if ((tran = spice_find_definition (definition_root,
"TR")) != NULL) {
2619 nr_double_t stop = spice_get_property_value (tran,
"Stop");
2620 spice_set_property_value (def,
"f", 1 / stop);
2625 if (!def->
action && !strcmp (def->
type,
"R")) {
2627 struct pair_t * r1 = spice_find_property_nocase (def,
"R");
2628 struct pair_t * r2 = spice_find_property_nocase (r1->
next,
"R");
2633 struct pair_t *
L = spice_find_property_nocase (def,
"L");
2634 struct pair_t * W = spice_find_property_nocase (def,
"W");
2635 struct pair_t *
R = spice_find_property_nocase (def,
"RSH");
2636 struct pair_t *
D = spice_find_property_nocase (def,
"DEFW");
2637 struct pair_t *
N = spice_find_property_nocase (def,
"NARROW");
2638 nr_double_t l = 0, w = 0, r = 0, d = 0, n = 0;
2640 l = spice_evaluate_value (L->
value);
2644 w = spice_evaluate_value (W->
value);
2648 r = spice_evaluate_value (R->
value);
2652 d = spice_evaluate_value (D->
value);
2656 n = spice_evaluate_value (N->
value);
2659 if (d == 0) d = 1
e-6;
2661 if (l != 0 && w != 0 && r != 0) {
2662 r = r * (l -
n) / (w - n);
2663 spice_set_property_value (def,
"R", r);
2669 spice_append_pair (def,
"Tc2", val->
ident, 0);
2670 spice_value_done (val);
2676 if (!def->
action && !strcmp (def->
type,
"C")) {
2678 struct pair_t * L = spice_find_property_nocase (def,
"L");
2679 struct pair_t * W = spice_find_property_nocase (def,
"W");
2680 struct pair_t *
C = spice_find_property_nocase (def,
"CJ");
2681 struct pair_t *
S = spice_find_property_nocase (def,
"CJSW");
2682 struct pair_t * D = spice_find_property_nocase (def,
"DEFW");
2683 struct pair_t * N = spice_find_property_nocase (def,
"NARROW");
2684 nr_double_t l = 0, w = 0,
c = 0, d = 0, n = 0, s = 0;
2686 l = spice_evaluate_value (L->
value);
2690 w = spice_evaluate_value (W->
value);
2694 c = spice_evaluate_value (C->
value);
2698 s = spice_evaluate_value (S->
value);
2702 d = spice_evaluate_value (D->
value);
2706 n = spice_evaluate_value (N->
value);
2709 if (d == 0) d = 1
e-6;
2711 if (l != 0 && w != 0 &&
c != 0) {
2712 c =
c * (l -
n) * (w - n) + 2 * s * (l + w - 2 *
n);
2713 spice_set_property_value (def,
"C",
c);
2717 if (!def->
action && !strcmp (def->
type,
"TLIN4P")) {
2718 struct pair_t * pt = spice_find_property (def,
"TD");
2719 struct pair_t * pf = spice_find_property (def,
"F");
2720 struct pair_t * pl = spice_find_property (def,
"NL");
2721 nr_double_t len = 1
e-3;
2724 len = spice_evaluate_value (pt->
value) *
C0;
2726 spice_set_property_value (def,
"L", len);
2728 else if (pf != NULL && pl != NULL) {
2730 nr_double_t f = spice_evaluate_value (pf->
value);
2731 nr_double_t l = spice_evaluate_value (pl->
value);
2735 spice_set_property_value (def,
"L", len);
2737 else if (pf != NULL) {
2739 nr_double_t f = spice_evaluate_value (pf->
value);
2741 len =
C0 / f * 0.25;
2742 spice_set_property_value (def,
"L", len);
2745 fprintf (stderr,
"spice error, either TD or F required in "
2746 "lossless `%s' line \n", def->
instance);
2751 if (!def->
action && !strcmp (def->
type,
"Tr")) {
2753 root = spice_translate_coupled_x (root, def);
2755 root = spice_translate_coupled (root, def);
2758 if (def->
action && strstr (def->
type,
"OPT")) {
2760 if ((val = spice_find_property (def->
values,
"ABSTOL")) != NULL) {
2761 spice_add_property (root,
"DC",
"abstol", val->
unit);
2762 spice_add_property (root,
"TR",
"abstol", val->
unit);
2764 if ((val = spice_find_property (def->
values,
"RELTOL")) != NULL) {
2765 spice_add_property (root,
"DC",
"reltol", val->
unit);
2766 spice_add_property (root,
"TR",
"reltol", val->
unit);
2768 if ((val = spice_find_property (def->
values,
"VNTOL")) != NULL) {
2769 spice_add_property (root,
"DC",
"vntol", val->
unit);
2770 spice_add_property (root,
"TR",
"vntol", val->
unit);
2772 if ((val = spice_find_property (def->
values,
"ITL1")) != NULL) {
2773 spice_add_property (root,
"DC",
"MaxIter", val->
unit);
2775 if ((val = spice_find_property (def->
values,
"ITL4")) != NULL) {
2776 spice_add_property (root,
"TR",
"MaxIter", val->
unit);
2780 if ((def->
action && !strcmp (def->
type,
"PRINT")) ||
2781 !strcmp (def->
type,
"PLOT")) {
2782 spice_collect_external_nodes (def);
2785 if (def->
define == NULL) {
2786 def->
text = spice_untranslated_text (def);
2789 spice_free_values (def);
2800 if (!strcasecmp (def->
type,
"TRAN")) {
2802 def->
type = strdup (
"TR");
2808 spice_append_pair (def,
"Points", val->
ident, 0);
2811 spice_append_pair (def,
"Stop", val->
ident, 0);
2814 spice_append_pair (def,
"Start", val->
ident, 0);
2819 spice_value_done (val);
2822 v = spice_get_property_value (def,
"Stop");
2823 v -= spice_get_property_value (def,
"Start");
2824 v /= spice_get_property_value (def,
"Points");
2826 spice_set_property_value (def,
"Points", v);
2829 else if (!strcasecmp (def->
type,
"AC")) {
2836 type = strdup (val->
ident);
2839 spice_append_pair (def,
"Points", val->
ident, 0);
2842 spice_append_pair (def,
"Start", val->
ident, 0);
2845 spice_append_pair (def,
"Stop", val->
ident, 0);
2848 spice_value_done (val);
2851 v = spice_evaluate_points (&type,
2852 spice_get_property_value (def,
"Start"),
2853 spice_get_property_value (def,
"Stop"),
2854 spice_get_property_value (def,
"Points"));
2855 spice_set_property_value (def,
"Points", v + 1);
2856 spice_set_property_string (def,
"Type", type);
2860 else if (!strcasecmp (def->
type,
"DC")) {
2862 if (spice_count_values (def->
values) >= 4) {
2863 para1 = spice_create_para (def);
2864 spice_set_property_string (para1,
"Sim",
2866 if (spice_count_values (def->
values) >= 4) {
2867 para2 = spice_create_para (def);
2868 spice_set_property_string (para2,
"Sim",
2872 if (para1) root = spice_add_definition (root, para1);
2873 if (para2) root = spice_add_definition (root, para2);
2876 else if (!strcasecmp (def->
type,
"SUBCKT")) {
2878 def->
type = strdup (
"Def");
2882 else if (!strcasecmp (def->
type,
"OP")) {
2884 def->
type = strdup (
"DC");
2885 spice_set_property_string (def,
"saveOPs",
"yes");
2895 sub->
type = strdup (
"Sub");
2898 spice_set_property_string (sub,
"Type", val->
ident);
2906 static char * spice_create_intern_nodeset (
void) {
2907 static int intern = 1;
2908 static char txt[32];
2909 sprintf (txt,
"NS%d", intern++);
2921 def->
type = strdup (
"NodeSet");
2923 node->
instance = strdup (spice_create_intern_nodeset ());
2927 node->
nodes = spice_translate_node (val->
ident);
2930 spice_append_pair (node,
"U", val->
ident, 1);
2933 node = spice_create_definition (node,
"NodeSet");
2934 root = spice_add_definition (root, node);
2936 node->
instance = strdup (spice_create_intern_nodeset ());
2946 if ((def->
define = spice_find_definition (def->
type)) != NULL) {
2948 def->
nodes = spice_get_nodes (def);
2949 def->
pairs = spice_get_pairs (def);
2952 if (!strcasecmp (def->
type,
"Q") || !strcasecmp (def->
type,
"M") ||
2953 !strcasecmp (def->
type,
"J") || !strcasecmp (def->
type,
"D") ||
2954 !strcasecmp (def->
type,
"S") || !strcasecmp (def->
type,
"R") ||
2955 !strcasecmp (def->
type,
"C")) {
2956 spice_translate_device (root, def);
2959 if (!strcasecmp (def->
type,
"E") || !strcasecmp (def->
type,
"G")) {
2960 root = spice_translate_poly (root, def);
2963 if (!strcasecmp (def->
type,
"C") || !strcasecmp (def->
type,
"L")) {
2964 root = spice_translate_poly_lc (root, def);
2967 if (!strcasecmp (def->
type,
"V")) {
2968 root = spice_translate_source (root, def,
'U');
2971 if (!strcasecmp (def->
type,
"I")) {
2972 root = spice_translate_source (root, def,
'I');
2975 if (!strcasecmp (def->
type,
"X")) {
2976 spice_translate_subcircuit (def);
2978 spice_translate_type (def);
2982 if (!strcasecmp (def->
type,
"NODESET") ||
2983 !strcasecmp (def->
type,
"IC")) {
2984 root = spice_translate_nodeset (root, def);
2987 root = spice_translate_action (root, def);
2990 spice_fixup_definition (def);
2994 if (!strcasecmp (def->
type,
"MODEL")) {
2995 spice_add_Model (def);
2999 spice_free_values (def);
3029 static void spice_lister (
struct definition_t * root) {
3033 for (val = def->
values; val != NULL; val = val->
next) {
3046 if (val == NULL)
return;
3047 for (; val->
next != NULL; val = val->
next) ;
3053 if (val == NULL)
return;
3054 for (; val->
next != NULL; val = val->
next) ;
3061 spice_lister (root);
3063 root = spice_translator (root);
3064 root = spice_post_translator (root);