📄 enhtranslate_poly.c
字号:
/* ===========================================================================FILE ENHtranslate_poly.cMEMBER OF process XSPICECopyright 1991Georgia Tech Research CorporationAtlanta, Georgia 30332All Rights ReservedPROJECT A-8503AUTHORS 9/12/91 Bill KuhnMODIFICATIONS <date> <person name> <nature of modifications>SUMMARY This file contains functions used by the simulator in calling the internal "poly" code model to substitute for SPICE 2G6 style poly sources found in the input deck.INTERFACES ENHtranslate_poly()REFERENCED FILES None.NON-STANDARD FEATURES None.=========================================================================== *//*=== FUNCTION PROTOTYPES ===*/ void free(void *);int atoi(char *);/*=== INCLUDE FILES ===*/#include "prefix.h"#include "ENH.h"#include "CPdefs.h"#include "FTEdefs.h"#include "FTEinp.h"#include "MIFproto.h"#include "suffix.h"/*=== FUNCTION PROTOTYPES ===*/ static int needs_translating(char *card);static int count_tokens(char *card);static char *translate(char *orig_card, char **inst_card, char **mod_card);static int get_poly_dimension(char *card);/*ENHtranslate_poly()Translate all 2G6 style polynomial controlled sources in the deckto new polynomial controlled source code model syntax.*/struct line * ENHtranslate_poly( struct line *deck) /* Linked list of lines in input deck */{ struct line *d; struct line *l1; struct line *l2; char *card; /* Iterate through each card in the deck and translate as needed */ for(d = deck; d; d = d->li_next) { /* If doesn't need to be translated, continue to next card */ if(! needs_translating(d->li_line)) continue; /* Create two new line structs and splice into deck */ l1 = alloc(line); l2 = alloc(line); l2->li_next = d->li_next; l1->li_next = l2; d->li_next = l1; /* Create the translated cards */ d->li_error = translate(d->li_line, &(l1->li_line), &(l2->li_line)); /* Comment out the original line */ card = (void *) malloc(strlen(d->li_line) + 2); strcpy(card,"*"); strcat(card, d->li_line); d->li_line = card; /* Advance deck pointer to last line added */ d = l2; } /* Return head of deck */ return(deck);} /* ENHtranslate_poly *//*needs_translating()Test to see if card needs translating. Return true if card definesan e,f,g, or h controlled source and has too many tokens to bea simple linear dependent source. Otherwise return false.*/static int needs_translating( char *card) /* the card text to check */{ switch(*card) { case 'e': case 'g': if(count_tokens(card) <=6) return(0); else return(1); case 'f': case 'h': if(count_tokens(card) <= 5) return(0); else return(1); default: return(0); }} /* needs_translating *//*count_tokens()Count and return the number of tokens on the card.*/static int count_tokens( char *card) /* the card text on which to count tokens */{ int i; /* Get and count tokens until end of line reached */ for(i = 0; *card != '\0'; i++) free(MIFgettok(&card)); return(i);} /* count_tokens *//*translate()Do the syntax translation of the 2G6 source to the new code model syntax.*/static char *translate( char *orig_card, /* the original untranslated card */ char **inst_card, /* the instance card created by the translation */ char **mod_card) /* the model card created by the translation */{ int dim; int num_tokens; int num_conns; int num_coefs; int inst_card_len; int mod_card_len; int i; char type; char *name; char **out_conn; char **in_conn; char **coef; char *card; /* Get the first character into local storage for checking type */ type = *orig_card; /* Count the number of tokens for use in parsing */ num_tokens = count_tokens(orig_card); /* Determine the dimension of the poly source */ dim = get_poly_dimension(orig_card); if(dim <= 0) return("ERROR - Argument to poly() is not an integer\n"); /* Compute number of input connections based on type and dimension */ switch(type) { case 'e': case 'g': num_conns = 2 * dim; break; default: num_conns = dim; } /* Compute number of coefficients. Return error if less than one. */ if(dim == 1) num_coefs = num_tokens - num_conns - 3; else num_coefs = num_tokens - num_conns - 5; if(num_coefs < 1) return("ERROR - Number of connections differs from poly dimension\n"); /* Split card into name, output connections, input connections, */ /* and coefficients */ card = orig_card; name = MIFgettok(&card); out_conn = (void *) malloc(2 * sizeof(char *)); for(i = 0; i < 2; i++) out_conn[i] = MIFgettok(&card); if(dim > 1) for(i = 0; i < 2; i++) free(MIFgettok(&card)); in_conn = (void *) malloc(num_conns * sizeof(char *)); for(i = 0; i < num_conns; i++) in_conn[i] = MIFgettok(&card); coef = (void *) malloc(num_coefs * sizeof(char *)); for(i = 0; i < num_coefs; i++) coef[i] = MIFgettok(&card); /* Compute the size needed for the new cards to be created */ /* Allow a fair amount of extra space for connection types, etc. */ /* to be safe... */ inst_card_len = 50; inst_card_len += 2 * (strlen(name) + 1); for(i = 0; i < 2; i++) inst_card_len += strlen(out_conn[i]) + 1; for(i = 0; i < num_conns; i++) inst_card_len += strlen(in_conn[i]) + 1; mod_card_len = 50; mod_card_len += strlen(name) + 1; for(i = 0; i < num_coefs; i++) mod_card_len += strlen(coef[i]) + 1; /* Allocate space for the cards and write them into the strings */ *inst_card = (void *) malloc(inst_card_len); *mod_card = (void *) malloc(mod_card_len); strcpy(*inst_card, "a$poly$"); sprintf(*inst_card + strlen(*inst_card), "%s ", name); if((type == 'e') || (type == 'g')) sprintf(*inst_card + strlen(*inst_card), "%%vd [ "); else sprintf(*inst_card + strlen(*inst_card), "%%vnam [ "); for(i = 0; i < num_conns; i++) sprintf(*inst_card + strlen(*inst_card), "%s ", in_conn[i]); sprintf(*inst_card + strlen(*inst_card), "] "); if((type == 'e') || (type == 'h')) sprintf(*inst_card + strlen(*inst_card), "%%vd "); else sprintf(*inst_card + strlen(*inst_card), "%%id "); for(i = 0; i < 2; i++) sprintf(*inst_card + strlen(*inst_card), "%s ", out_conn[i]); sprintf(*inst_card + strlen(*inst_card), "a$poly$%s", name); sprintf(*mod_card, ".model a$poly$%s poly coef = [ ", name); for(i = 0; i < num_coefs; i++) sprintf(*mod_card + strlen(*mod_card), "%s ", coef[i]); sprintf(*mod_card + strlen(*mod_card), "]"); /* Free the temporary space */ free(name); for(i = 0; i < 2; i++) free(out_conn[i]); free(out_conn); for(i = 0; i < num_conns; i++) free(in_conn[i]); free(in_conn); for(i = 0; i < num_coefs; i++) free(coef[i]); free(coef); /* Return NULL to indicate no error */ return(NULL);} /* translate *//*get_poly_dimension()Get the poly source dimension from the token immediately followingthe 'poly' if any. If 'poly' is not present, return 1. If poly ispresent and token following is a valid integer, return it. Elsereturn 0.*/static int get_poly_dimension( char *card) /* the card text */{ int i; int dim; char *tok; /* Skip over name and output connections */ for(i = 0; i < 3; i++) free(MIFgettok(&card)); /* Check the next token to see if it is "poly" */ /* If not, return a dimension of 1 */ tok = MIFgettok(&card); if(strcmp(tok, "poly")) { free(tok); return(1); } free(tok); /* Must have been "poly", so next line must be a number */ /* Try to convert it. If successful, return the number */ /* else, return 0 to indicate an error... */ tok = MIFgettok(&card); dim = atoi(tok); free(tok); return(dim);} /* get_poly_dimension */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -