|
|
|
@ -6930,68 +6930,68 @@ pspice_compat(struct card *oldcard) |
|
|
|
* simple hierachy, as nested subcircuits are not allowed in PSPICE */ |
|
|
|
|
|
|
|
/* first scan: find the vswitch models, transform them and put them into a list */ |
|
|
|
for (card = newcard; card; card = card->nextcard) { |
|
|
|
char *str; |
|
|
|
static struct card *subcktline = NULL; |
|
|
|
static int nesting = 0; |
|
|
|
char *cut_line = card->line; |
|
|
|
if (ciprefix(".subckt", cut_line)) { |
|
|
|
subcktline = card; |
|
|
|
nesting++; |
|
|
|
} |
|
|
|
if (ciprefix(".ends", cut_line)) |
|
|
|
nesting--; |
|
|
|
|
|
|
|
if (ciprefix(".model", card->line) && strstr(card->line, "vswitch")) { |
|
|
|
char *modpar[4]; |
|
|
|
char *modname; |
|
|
|
int i; |
|
|
|
|
|
|
|
card->line = str = inp_remove_ws(card->line); |
|
|
|
str = nexttok(str); /* throw away '.model' */ |
|
|
|
INPgetNetTok(&str, &modname, 0); /* model name */ |
|
|
|
if (!ciprefix("vswitch", str)) |
|
|
|
continue; |
|
|
|
/* we have to find 4 parameters, identified by '=', separated by spaces */ |
|
|
|
char *equalptr[4]; |
|
|
|
equalptr[0] = strstr(str, "="); |
|
|
|
if (!equalptr[0]) { |
|
|
|
fprintf(stderr, "Error: not enough parameters in vswitch model\n %s\n", card->line); |
|
|
|
controlled_exit(1); |
|
|
|
} |
|
|
|
for (i = 1; i < 4; i++) { |
|
|
|
equalptr[i] = strstr(equalptr[i - 1] + 1, "="); |
|
|
|
if (!equalptr[i]) { |
|
|
|
fprintf(stderr, "Error: not enough parameters in vswitch model\n %s\n", card->line); |
|
|
|
controlled_exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
for (i = 0; i < 4; i++) { |
|
|
|
equalptr[i] = skip_back_ws(equalptr[i], str); |
|
|
|
equalptr[i] = skip_back_non_ws(equalptr[i], str); |
|
|
|
} |
|
|
|
for (i = 0; i < 3; i++) |
|
|
|
modpar[i] = copy_substring(equalptr[i], equalptr[i + 1] - 1); |
|
|
|
if (strrchr(equalptr[3], ')')) |
|
|
|
modpar[3] = copy_substring(equalptr[3], strrchr(equalptr[3], ')')); |
|
|
|
else |
|
|
|
/* vswitch defined without parens */ |
|
|
|
modpar[3] = copy(equalptr[3]); |
|
|
|
tfree(card->line); |
|
|
|
/* replace VON by cntl_on, VOFF by cntl_off, RON by r_on, and ROFF by r_off */ |
|
|
|
rep_spar(modpar); |
|
|
|
card->line = tprintf(".model a%s aswitch(%s %s %s %s log=TRUE)", |
|
|
|
modname, modpar[0], modpar[1], modpar[2], modpar[3]); |
|
|
|
for (i = 0; i < 4; i++) |
|
|
|
tfree(modpar[i]); |
|
|
|
if (nesting > 0) |
|
|
|
modelsfound = insert_new_model(modelsfound, modname, subcktline->line); |
|
|
|
else |
|
|
|
modelsfound = insert_new_model(modelsfound, modname, "top"); |
|
|
|
} |
|
|
|
} |
|
|
|
/* second scan: find the switch instances s calling a vswitch model and transform them */ |
|
|
|
for (card = newcard; card; card = card->nextcard) { |
|
|
|
for (card = newcard; card; card = card->nextcard) { |
|
|
|
char *str; |
|
|
|
static struct card *subcktline = NULL; |
|
|
|
static int nesting = 0; |
|
|
|
char *cut_line = card->line; |
|
|
|
if (ciprefix(".subckt", cut_line)) { |
|
|
|
subcktline = card; |
|
|
|
nesting++; |
|
|
|
} |
|
|
|
if (ciprefix(".ends", cut_line)) |
|
|
|
nesting--; |
|
|
|
|
|
|
|
if (ciprefix(".model", card->line) && strstr(card->line, "vswitch")) { |
|
|
|
char *modpar[4]; |
|
|
|
char *modname; |
|
|
|
int i; |
|
|
|
|
|
|
|
card->line = str = inp_remove_ws(card->line); |
|
|
|
str = nexttok(str); /* throw away '.model' */ |
|
|
|
INPgetNetTok(&str, &modname, 0); /* model name */ |
|
|
|
if (!ciprefix("vswitch", str)) |
|
|
|
continue; |
|
|
|
/* we have to find 4 parameters, identified by '=', separated by spaces */ |
|
|
|
char *equalptr[4]; |
|
|
|
equalptr[0] = strstr(str, "="); |
|
|
|
if (!equalptr[0]) { |
|
|
|
fprintf(stderr, "Error: not enough parameters in vswitch model\n %s\n", card->line); |
|
|
|
controlled_exit(1); |
|
|
|
} |
|
|
|
for (i = 1; i < 4; i++) { |
|
|
|
equalptr[i] = strstr(equalptr[i - 1] + 1, "="); |
|
|
|
if (!equalptr[i]) { |
|
|
|
fprintf(stderr, "Error: not enough parameters in vswitch model\n %s\n", card->line); |
|
|
|
controlled_exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
for (i = 0; i < 4; i++) { |
|
|
|
equalptr[i] = skip_back_ws(equalptr[i], str); |
|
|
|
equalptr[i] = skip_back_non_ws(equalptr[i], str); |
|
|
|
} |
|
|
|
for (i = 0; i < 3; i++) |
|
|
|
modpar[i] = copy_substring(equalptr[i], equalptr[i + 1] - 1); |
|
|
|
if (strrchr(equalptr[3], ')')) |
|
|
|
modpar[3] = copy_substring(equalptr[3], strrchr(equalptr[3], ')')); |
|
|
|
else |
|
|
|
/* vswitch defined without parens */ |
|
|
|
modpar[3] = copy(equalptr[3]); |
|
|
|
tfree(card->line); |
|
|
|
/* replace VON by cntl_on, VOFF by cntl_off, RON by r_on, and ROFF by r_off */ |
|
|
|
rep_spar(modpar); |
|
|
|
card->line = tprintf(".model a%s aswitch(%s %s %s %s log=TRUE)", |
|
|
|
modname, modpar[0], modpar[1], modpar[2], modpar[3]); |
|
|
|
for (i = 0; i < 4; i++) |
|
|
|
tfree(modpar[i]); |
|
|
|
if (nesting > 0) |
|
|
|
modelsfound = insert_new_model(modelsfound, modname, subcktline->line); |
|
|
|
else |
|
|
|
modelsfound = insert_new_model(modelsfound, modname, "top"); |
|
|
|
} |
|
|
|
} |
|
|
|
/* second scan: find the switch instances s calling a vswitch model and transform them */ |
|
|
|
for (card = newcard; card; card = card->nextcard) { |
|
|
|
static struct card *subcktline = NULL; |
|
|
|
static int nesting = 0; |
|
|
|
char *cut_line = card->line; |
|
|
|
@ -7016,27 +7016,27 @@ pspice_compat(struct card *oldcard) |
|
|
|
if (ciprefix(".ends", cut_line)) |
|
|
|
nesting--; |
|
|
|
|
|
|
|
if (ciprefix("s", cut_line)) { |
|
|
|
/* check for the model name */ |
|
|
|
int i; |
|
|
|
char *stoks[6]; |
|
|
|
for (i = 0; i < 6; i++) |
|
|
|
stoks[i] = gettok(&cut_line); |
|
|
|
/* rewrite s line and replace it if a model is found */ |
|
|
|
if (find_a_model(modelsfound, stoks[5], subcktline->line)) { |
|
|
|
tfree(card->line); |
|
|
|
card->line = tprintf("a%s %%vd(%s %s) %%gd(%s %s) a%s", |
|
|
|
stoks[0], stoks[3], stoks[4], stoks[1], stoks[2], stoks[5]); |
|
|
|
} |
|
|
|
/* if model is not within same subcircuit, search at top level */ |
|
|
|
else if (find_a_model(modelsfound, stoks[5], "top")) { |
|
|
|
tfree(card->line); |
|
|
|
card->line = tprintf("a%s %%vd(%s %s) %%gd(%s %s) a%s", |
|
|
|
stoks[0], stoks[3], stoks[4], stoks[1], stoks[2], stoks[5]); |
|
|
|
} |
|
|
|
for (i = 0; i < 6; i++) |
|
|
|
tfree(stoks[i]); |
|
|
|
} |
|
|
|
if (ciprefix("s", cut_line)) { |
|
|
|
/* check for the model name */ |
|
|
|
int i; |
|
|
|
char *stoks[6]; |
|
|
|
for (i = 0; i < 6; i++) |
|
|
|
stoks[i] = gettok(&cut_line); |
|
|
|
/* rewrite s line and replace it if a model is found */ |
|
|
|
if (find_a_model(modelsfound, stoks[5], subcktline->line)) { |
|
|
|
tfree(card->line); |
|
|
|
card->line = tprintf("a%s %%vd(%s %s) %%gd(%s %s) a%s", |
|
|
|
stoks[0], stoks[3], stoks[4], stoks[1], stoks[2], stoks[5]); |
|
|
|
} |
|
|
|
/* if model is not within same subcircuit, search at top level */ |
|
|
|
else if (find_a_model(modelsfound, stoks[5], "top")) { |
|
|
|
tfree(card->line); |
|
|
|
card->line = tprintf("a%s %%vd(%s %s) %%gd(%s %s) a%s", |
|
|
|
stoks[0], stoks[3], stoks[4], stoks[1], stoks[2], stoks[5]); |
|
|
|
} |
|
|
|
for (i = 0; i < 6; i++) |
|
|
|
tfree(stoks[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
del_models(modelsfound); |
|
|
|
|
|
|
|
|