Revert "Redo the transformation vswitch -> pswitch"
This reverts commit b78bb48ead.
This commit is contained in:
parent
b78bb48ead
commit
a41cbad50e
|
|
@ -8754,12 +8754,12 @@ static struct card *pspice_compat(struct card *oldcard)
|
||||||
|
|
||||||
/* first scan: find the vswitch models, transform them and put them into a
|
/* first scan: find the vswitch models, transform them and put them into a
|
||||||
* list */
|
* list */
|
||||||
|
bool have_vt = FALSE, have_vh = FALSE;
|
||||||
for (card = newcard; card; card = card->nextcard) {
|
for (card = newcard; card; card = card->nextcard) {
|
||||||
char* str;
|
char *str;
|
||||||
static struct card* subcktline = NULL;
|
static struct card *subcktline = NULL;
|
||||||
static int nesting = 0;
|
static int nesting = 0;
|
||||||
char* cut_line = card->line;
|
char *cut_line = card->line;
|
||||||
if (ciprefix(".subckt", cut_line)) {
|
if (ciprefix(".subckt", cut_line)) {
|
||||||
subcktline = card;
|
subcktline = card;
|
||||||
nesting++;
|
nesting++;
|
||||||
|
|
@ -8768,11 +8768,9 @@ static struct card *pspice_compat(struct card *oldcard)
|
||||||
nesting--;
|
nesting--;
|
||||||
|
|
||||||
if (ciprefix(".model", card->line) && strstr(card->line, "vswitch")) {
|
if (ciprefix(".model", card->line) && strstr(card->line, "vswitch")) {
|
||||||
/* roff ron voff von */
|
char *modpar[4];
|
||||||
double s_values[4] = { 1e6, 1., 0., 1. }; /* default values */
|
char *modname;
|
||||||
/* roff ron vt vh */
|
int i;
|
||||||
double s_st_values[4] = { 1e12, 1., 0., 0. }; /* default values */
|
|
||||||
char* modname;
|
|
||||||
|
|
||||||
card->line = str = inp_remove_ws(card->line);
|
card->line = str = inp_remove_ws(card->line);
|
||||||
str = nexttok(str); /* throw away '.model' */
|
str = nexttok(str); /* throw away '.model' */
|
||||||
|
|
@ -8781,72 +8779,73 @@ static struct card *pspice_compat(struct card *oldcard)
|
||||||
tfree(modname);
|
tfree(modname);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
str = nexttok_noparens(str); /* throw away 'vswitch' */
|
/* we have to find 4 parameters, identified by '=', separated by
|
||||||
/* the S_ST switch */
|
* spaces */
|
||||||
if (strstr(str, "vt=") || strstr(str, "vh=")) {
|
char *equalptr[4];
|
||||||
int error;
|
equalptr[0] = strstr(str, "=");
|
||||||
while (str) {
|
if (!equalptr[0]) {
|
||||||
char* token = gettok_noparens(&str);
|
fprintf(stderr,
|
||||||
if (!token)
|
"Error: not enough parameters in vswitch model\n "
|
||||||
break;
|
"%s\n",
|
||||||
char* ntoken = strchr(token, '=');
|
card->line);
|
||||||
if (!ntoken)
|
controlled_exit(1);
|
||||||
break;
|
|
||||||
ntoken++;
|
|
||||||
double val = INPevaluate(&ntoken, &error, 0);
|
|
||||||
if (ciprefix("roff=", token))
|
|
||||||
s_st_values[0] = val;
|
|
||||||
else if (ciprefix("ron=", token))
|
|
||||||
s_st_values[1] = val;
|
|
||||||
else if (ciprefix("vt=", token))
|
|
||||||
s_st_values[2] = val;
|
|
||||||
else if (ciprefix("vh=", token))
|
|
||||||
s_st_values[3] = val;
|
|
||||||
tfree(token);
|
|
||||||
}
|
|
||||||
char* newline = tprintf(".model %s sw (roff=%g ron=%g vt=%g vh=%g)", modname,
|
|
||||||
s_st_values[0], s_st_values[1], s_st_values[2], s_st_values[3]);
|
|
||||||
tfree(card->line);
|
|
||||||
card->line = newline;
|
|
||||||
}
|
}
|
||||||
/* the S switch */
|
for (i = 1; i < 4; i++) {
|
||||||
else if (strstr(str, "von=") || strstr(str, "voff=")) {
|
equalptr[i] = strstr(equalptr[i - 1] + 1, "=");
|
||||||
int error;
|
if (!equalptr[i]) {
|
||||||
while (str) {
|
fprintf(stderr,
|
||||||
char* token = gettok_noparens(&str);
|
"Error: not enough parameters in vswitch model\n "
|
||||||
if (!token)
|
" %s\n",
|
||||||
break;
|
card->line);
|
||||||
char* ntoken = strchr(token, '=');
|
controlled_exit(1);
|
||||||
if (!ntoken)
|
|
||||||
break;
|
|
||||||
ntoken++;
|
|
||||||
double val = INPevaluate(&ntoken, &error, 0);
|
|
||||||
if (ciprefix("roff=", token))
|
|
||||||
s_values[0] = val;
|
|
||||||
else if (ciprefix("ron=", token))
|
|
||||||
s_values[1] = val;
|
|
||||||
else if (ciprefix("voff=", token))
|
|
||||||
s_values[2] = val;
|
|
||||||
else if (ciprefix("von=", token))
|
|
||||||
s_values[3] = val;
|
|
||||||
tfree(token);
|
|
||||||
}
|
}
|
||||||
/* replace VON by cntl_on, VOFF by cntl_off, RON by r_on, and ROFF by r_off */
|
}
|
||||||
char* newline = tprintf(".model a%s pswitch (r_off=%g r_on=%g cntl_off=%g cntl_on=%g log=TRUE)", modname,
|
for (i = 0; i < 4; i++) {
|
||||||
s_values[0], s_values[1], s_values[2], s_values[3]);
|
equalptr[i] = skip_back_ws(equalptr[i], str);
|
||||||
tfree(card->line);
|
while (*(equalptr[i]) != '(' && !isspace_c(*(equalptr[i])) &&
|
||||||
card->line = newline;
|
*(equalptr[i]) != ',')
|
||||||
/* enter models into list only for code models */
|
(equalptr[i])--;
|
||||||
if (nesting > 0)
|
(equalptr[i])++;
|
||||||
modelsfound = insert_new_model(
|
}
|
||||||
modelsfound, modname, subcktline->line);
|
for (i = 0; i < 3; i++)
|
||||||
else
|
modpar[i] = copy_substring(equalptr[i], equalptr[i + 1] - 1);
|
||||||
modelsfound = insert_new_model(modelsfound, modname, "top");
|
if (strrchr(equalptr[3], ')'))
|
||||||
|
modpar[3] = copy_substring(
|
||||||
|
equalptr[3], strrchr(equalptr[3], ')'));
|
||||||
|
else
|
||||||
|
/* vswitch defined without parens */
|
||||||
|
modpar[3] = copy(equalptr[3]);
|
||||||
|
|
||||||
|
/* check if we have parameters VT and VH */
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
if (ciprefix("vh", modpar[i]))
|
||||||
|
have_vh = TRUE;
|
||||||
|
if (ciprefix("vt", modpar[i]))
|
||||||
|
have_vt = TRUE;
|
||||||
|
}
|
||||||
|
if (have_vh && have_vt) {
|
||||||
|
/* replace vswitch by sw */
|
||||||
|
char *vs = strstr(card->line, "vswitch");
|
||||||
|
memmove(vs, " sw", 7);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "Error: Bad switch model in line %s\n", card->line);
|
/* replace VON by cntl_on, VOFF by cntl_off, RON by r_on, and
|
||||||
|
* ROFF by r_off */
|
||||||
|
tfree(card->line);
|
||||||
|
rep_spar(modpar);
|
||||||
|
card->line = tprintf(
|
||||||
|
// ".model a%s aswitch(%s %s %s %s log=TRUE limit=TRUE)", modname,
|
||||||
|
// modpar[0], modpar[1], modpar[2], modpar[3]);
|
||||||
|
".model a%s pswitch(%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");
|
||||||
tfree(modname);
|
tfree(modname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8855,6 +8854,10 @@ static struct card *pspice_compat(struct card *oldcard)
|
||||||
if (!modelsfound)
|
if (!modelsfound)
|
||||||
goto iswi;
|
goto iswi;
|
||||||
|
|
||||||
|
/* no need to change the switch instances if switch sw is used */
|
||||||
|
if (have_vh && have_vt)
|
||||||
|
goto iswi;
|
||||||
|
|
||||||
/* second scan: find the switch instances s calling a vswitch model and
|
/* second scan: find the switch instances s calling a vswitch model and
|
||||||
* transform them */
|
* transform them */
|
||||||
for (card = newcard; card; card = card->nextcard) {
|
for (card = newcard; card; card = card->nextcard) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue