From 9eaba91bf2fbfe3042b8831ab719bcba6d1dce14 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sat, 8 May 2010 14:21:31 +0000 Subject: [PATCH] update on E, G sources with expressions --- ChangeLog | 1 + src/frontend/inpcom.c | 142 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 126 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8ce5fca1..0e7fb7fe3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2010-05-08 Holger Vogt * inpcom.c: patch 20/05/10 by Robert: avoid substraction from a builtin 1.0 + * inpcom.c: update to E, G sources with expressions 2010-04-26 Dietmar Warning * parser/inpgval.c: correct parsing of integer model parameter given as double diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 05b69ce9b..9cbd380c6 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -3486,8 +3486,18 @@ inp_split_multi_param_lines( struct line *deck, int line_num ) /* compatibility: Exxx n1 n2 VCVS n3 n4 gain --> Exxx n1 n2 n3 n4 gain Gxxx n1 n2 VCCS n3 n4 tr --> Exxx n1 n2 n3 n4 tr - Exxx n1 n2 VOL = {equation} --> BExxx n1 n2 V = {equation} - Gxxx n1 n2 CUR = {equation} --> BGxxx n1 n2 I = {equation} + + Two step approach to keep the original names for reuse, + i.e. for current measurements like i(Exxx): + Exxx n1 n2 VOL = {equation} + --> + Exxx n1 n2 int1 0 1 + BExxx int1 0 V = {equation} + + Gxxx n1 n2 CUR = {equation} + --> + Gxxx n1 n2 int1 0 1 + BGxxx int1 0 V = {equation} Do the following transformations only if {equation} contains simulation output like v(node), v(node1, node2), i(branch). @@ -3530,6 +3540,7 @@ static void inp_compat(struct line *deck) char *curr_line = card->li_line; + /* exclude any command inside .control ... .endc */ if ( ciprefix(".control", curr_line) ) { skip_control ++; continue; @@ -3550,33 +3561,130 @@ static void inp_compat(struct line *deck) *str_ptr = ' '; *(str_ptr + 1) = ' '; *(str_ptr + 2) = ' '; *(str_ptr + 3) = ' '; } - /* Exxx n1 n2 VOL = {equation} --> BExxx n1 n2 V = {equation} */ + + /* Exxx n1 n2 VOL = {equation} + --> + Exxx n1 n2 int1 0 1 + BExxx int1 0 V = {equation} + */ if (str_ptr = strstr( curr_line, "vol" ) ) { - *(str_ptr + 2) = ' '; - while (str_ptr > curr_line) { - *(str_ptr + 1) = *str_ptr; - str_ptr--; + cut_line = curr_line; + /* title and nodes */ + title_tok = gettok(&cut_line); + node1 = gettok(&cut_line); + node2 = gettok(&cut_line); + /* Find equation, starts with '{', till end of line */ + str_ptr = strstr(cut_line, "{"); + + // Exxx n1 n2 int1 0 1 + xlen = 2*strlen(title_tok) + strlen(node1) + strlen(node2) + + 12; + ckt_array[0] = (char*)tmalloc(xlen); + sprintf(ckt_array[0], "%s %s %s %s_int1 0 1", + title_tok, node1, node2, title_tok); + // BExxx int1 0 V = {equation} + xlen = 2*strlen(title_tok) + strlen(str_ptr) + + 15; + ckt_array[1] = (char*)tmalloc(xlen); + sprintf(ckt_array[1], "b%s %s_int1 0 v = %s", + title_tok, title_tok, str_ptr); + + // insert new B source line immediately after current line + tmp_ptr = card->li_next; + for ( i = 0; i < 2; i++ ) + { + if ( param_end ) + { + param_end->li_next = alloc(struct line); + param_end = param_end->li_next; + } + else + { + param_end = param_beg = alloc(struct line); + } + param_end->li_next = NULL; + param_end->li_error = NULL; + param_end->li_actual = NULL; + param_end->li_line = ckt_array[i]; + param_end->li_linenum = 0; } - *(str_ptr + 1) = *str_ptr; - *str_ptr = 'b'; + // comment out current variable e line + *(card->li_line) = '*'; + // insert new param lines immediately after current line + tmp_ptr = card->li_next; + card->li_next = param_beg; + param_end->li_next = tmp_ptr; + // point 'card' pointer to last in scalar list + card = param_end; + + param_beg = param_end = NULL; } } else if ( *curr_line == 'g' ) { - /* Gxxx n1 n2 VCCS n3 n4 tr --> Exxx n1 n2 n3 n4 tr + /* Gxxx n1 n2 VCCS n3 n4 tr --> Gxxx n1 n2 n3 n4 tr remove vccs */ if (str_ptr = strstr( curr_line, "vccs" ) ) { *str_ptr = ' '; *(str_ptr + 1) = ' '; *(str_ptr + 2) = ' '; *(str_ptr + 3) = ' '; } - /* Gxxx n1 n2 CUR = {equation} --> BGxxx n1 n2 I = {equation} */ + + /* + Gxxx n1 n2 CUR = {equation} + --> + Gxxx n1 n2 int1 0 1 + BGxxx int1 0 V = {equation} + */ if (str_ptr = strstr( curr_line, "cur" ) ) { - *(str_ptr + 2) = ' '; *str_ptr = 'i'; - while (str_ptr > curr_line) { - *(str_ptr + 1) = *str_ptr; - str_ptr--; + cut_line = curr_line; + /* title and nodes */ + title_tok = gettok(&cut_line); + node1 = gettok(&cut_line); + node2 = gettok(&cut_line); + /* Find equation, starts with '{', till end of line */ + str_ptr = strstr(cut_line, "{"); + + // Gxxx n1 n2 int1 0 1 + xlen = 2*strlen(title_tok) + strlen(node1) + strlen(node2) + + 12; + ckt_array[0] = (char*)tmalloc(xlen); + sprintf(ckt_array[0], "%s %s %s %s_int1 0 1", + title_tok, node1, node2, title_tok); + // BGxxx int1 0 V = {equation} + xlen = 2*strlen(title_tok) + strlen(str_ptr) + + 15; + ckt_array[1] = (char*)tmalloc(xlen); + sprintf(ckt_array[1], "b%s %s_int1 0 v = %s", + title_tok, title_tok, str_ptr); + + // insert new B source line immediately after current line + tmp_ptr = card->li_next; + for ( i = 0; i < 2; i++ ) + { + if ( param_end ) + { + param_end->li_next = alloc(struct line); + param_end = param_end->li_next; + } + else + { + param_end = param_beg = alloc(struct line); + } + param_end->li_next = NULL; + param_end->li_error = NULL; + param_end->li_actual = NULL; + param_end->li_line = ckt_array[i]; + param_end->li_linenum = 0; } - *(str_ptr + 1) = *str_ptr; - *str_ptr = 'b'; + // comment out current variable g line + *(card->li_line) = '*'; + // insert new param lines immediately after current line + tmp_ptr = card->li_next; + card->li_next = param_beg; + param_end->li_next = tmp_ptr; + // point 'card' pointer to last in scalar list + card = param_end; + + param_beg = param_end = NULL; } } /* Rxxx n1 n2 R = {equation} or Rxxx n1 n2 {equation}