Beispiel #1
0
static int
dot_tran(char *line, CKTcircuit *ckt, INPtables *tab, struct card *current,
         TSKtask *task, CKTnode *gnode, JOB *foo)
{
    int error;			/* error code temporary */
    IFvalue ptemp;		/* a value structure to package resistance into */
    IFvalue *parm;		/* a pointer to a value struct for function returns */
    int which;			/* which analysis we are performing */
    double dtemp;		/* random double precision temporary */
    char *word;			/* something to stick a word of input into */

    NG_IGNORE(gnode);

    /* .tran Tstep Tstop <Tstart <Tmax> > <UIC> */
    which = ft_find_analysis("TRAN");
    if (which == -1) {
        LITERR("Transient analysis unsupported.\n");
        return (0);
    }
    IFC(newAnalysis, (ckt, which, "Transient Analysis", &foo, task));
    parm = INPgetValue(ckt, &line, IF_REAL, tab);	/* Tstep */
    GCA(INPapName, (ckt, which, foo, "tstep", parm));
    parm = INPgetValue(ckt, &line, IF_REAL, tab);	/* Tstop */
    GCA(INPapName, (ckt, which, foo, "tstop", parm));
    if (*line) {
        dtemp = INPevaluate(&line, &error, 1);	/* tstart? */
        if (error == 0) {
            ptemp.rValue = dtemp;
            GCA(INPapName, (ckt, which, foo, "tstart", &ptemp));
            dtemp = INPevaluate(&line, &error, 1);	/* tmax? */
            if (error == 0) {
                ptemp.rValue = dtemp;
                GCA(INPapName, (ckt, which, foo, "tmax", &ptemp));
            }
        }
    }
    if (*line) {
        INPgetTok(&line, &word, 1);	/* uic? */
        if (strcmp(word, "uic") == 0) {
            ptemp.iValue = 1;
            GCA(INPapName, (ckt, which, foo, "uic", &ptemp));
        } else {
            LITERR(" Error: unknown parameter on .tran - ignored\n");
        }
        tfree(word);
    }
    return (0);
}
Beispiel #2
0
static int
get_vcdval(char *xspiceval, char **newval)
{
    int i, err;
    double retval;

    static char *map[] = {
        "0s", "1s", "Us",
        "0r", "1r", "Ur",
        "0z", "1z", "Uz",
        "0u", "1u", "Uu"
    };
    static char *returnmap[] = {
        "0", "1", "x",
        "0", "1", "x",
        "0", "1", "z",
        "0", "1", "x"
    };

    for (i = 0; i < 12; i++)
        if (eq(xspiceval, map[i])) {
            *newval = copy(returnmap[i]);
            return 0;
        }

    /* is it a real number ? */
    retval = INPevaluate(&xspiceval, &err, 1);
    if (err) {
        *newval = copy("unknown");
        return 2;
    }
    *newval = tprintf("%.16g", retval);
    return 1;
}
Beispiel #3
0
//static bool
//get_double_value(
//    char **line,   /*in|out: pointer to line to be parsed */
//    char *name,    /*in: xxx e.g. 'val' from 'val=0.5' */
//    double *value, /*out: return value (e.g. 0.5) from 'val=0.5'*/
//    bool just_chk_meas /* in: just check measurement if true */
//)
static int
get_double_value(
                 char **line,   /*in|out: pointer to line to be parsed */
                 char *name,    /*in: xxx e.g. 'val' from 'val=0.5' */
                 double *value, /*out: return value (e.g. 0.5) from 'val=0.5'*/
                 int just_chk_meas /* in: just check measurement if true */
)
{
    char *token     = gettok(line);
    //bool return_val = TRUE;
    int return_val = TRUE;
    char *equal_ptr, *junk;
    int  err = 0;

    if (name && (strncmp(token, name, strlen(name)) != 0)) {
        if (just_chk_meas != TRUE) fprintf(cp_err, "Error: syntax error for measure statement; expecting next field to be '%s'.\n", name);
        return_val = FALSE;
    } else {
        /* see if '=' is last char of current token -- implies we need to read value in next token */
        if (token[strlen(token) - 1] == '=') {
            txfree(token);
            junk = token = gettok(line);

            *value = INPevaluate(&junk, &err, 1);
        } else {
            if ((equal_ptr = strstr(token, "=")) != NULL) {
                equal_ptr += 1;
                *value = INPevaluate(&equal_ptr, &err, 1);
            } else {
                if (just_chk_meas != TRUE)
                    fprintf(cp_err, "Error: syntax error for measure statement; missing '='!\n");
                return_val = FALSE;
            }
        }
        if (err) {
            if (just_chk_meas != TRUE)
                fprintf(cp_err, "Error: Bad value.\n");
            return_val = FALSE;
        }
    }
    txfree(token);

    return return_val;
}
Beispiel #4
0
char *INPfindLev(char *line, int *level)
{
    char *where;
    int error1;

    /*
     *where = line;
     */

    where = strstr(line, "level");

    if (where != NULL) {	/* found a level keyword on the line */

        where += 5;		/* skip the level keyword */
        while ((*where == ' ') || (*where == '\t') || (*where == '=') ||
                (*where == ',') || (*where == '(') || (*where == ')') ||
                (*where == '+'))
        {   /* legal white space - ignore */
            where++;
        }
        /* now the magic number,
           allow scientific notation of level, e.g. 4.900e1,
           offers only limited error checking.
         */
        *level = (int)(INPevaluate(&where, &error1, 0) + 0.5);

        if (*level < 0) {
            *level = 1;
            fprintf(stderr,"Illegal value for level.\n");
            fprintf(stderr,"Level must be >0 (Setting level to 1)\n");
            return (INPmkTemp
                    (" illegal (negative) argument to level parameter - level=1 assumed"));
        }

        if (*level > 99) {	/* Limit to change in the future */
            *level = 1;
            fprintf(stderr,"Illegal value for level.\n");
            fprintf(stderr,"Level must be < 99 (Setting Level to 1)\n");
            return (INPmkTemp
                    (" illegal (too high) argument to level parameter - level=1 assumed"));
        }

        return (NULL);
    }


    else {			/* no level on the line => default */
        *level = 1;
#ifdef TRACE			/* this is annoying for bjt's */
        fprintf(stderr,"Warning -- Level not specified on line \"%s\"\nUsing level 1.\n", line);
#endif
        return (NULL);
    }
}
Beispiel #5
0
void getdata(double vals[], int count, int width)
{
	int i;
	int error = false;
	int start;
	char *c;

	do
	{
		if (fgets(dataline, 1023, p) == NULL)
		{
			printf("premature end of file getting input data line\n");
			exit(1);
		}

		start = 0;

	} while (*dataline == '*');

	c = dataline;

	for (i = 0; i < count; i++)
	{
		/* This was once a goto statement */
		do
		{
			vals[i] = INPevaluate(&c, &error, 1);
			start++;
			if (error || (start > width)) /* end of line, so read another one */
			{
				do
				{
					if (fgets(dataline, 1023, p) == NULL)
					{
						printf("premature end of file reading input data line \n");
						exit(1);
					}
					start = 0;
				} while (*dataline == '*');

				c = dataline;
			}
		} while (error || (start > width));
	}
}
Beispiel #6
0
void
com_meas(wordlist *wl)
{
    /* wl: in, input line of meas command */
    char *line_in, *outvar;
    wordlist *wl_count, *wl_let;

    char *vec_found, *token, *equal_ptr;
    wordlist *wl_index;
    struct dvec *d;
    int err = 0;

    int fail;
    double result = 0;

    if (!wl) {
        com_display(NULL);
        return;
    }
    wl_count = wl;

    /* check each wl entry, if it contain '=' and if the following token is
       a single valued vector. If yes, replace this vector by its value.
       Vectors may stem from other meas commands, or be generated elsewhere
       within the .control .endc script. All other right hand side vectors are
       treated in com_measure2.c. */
    wl_index = wl;

    while (wl_index) {
        token = wl_index->wl_word;
        /* find the vector vec_found, next token after each '=' sign.
           May be in the next wl_word */
        if (token[strlen(token) - 1] == '=') {
            wl_index = wl_index->wl_next;
            vec_found = wl_index->wl_word;
            /* token may be already a value, maybe 'LAST', which we have to keep, or maybe a vector */
            if (!cieq(vec_found, "LAST")) {
                INPevaluate(&vec_found, &err, 1);
                /* if not a valid number */
                if (err) {
                    /* check if vec_found is a valid vector */
                    d = vec_get(vec_found);
                    /* Only if we have a single valued vector, replacing
                       of the rigt hand side does make sense */
                    if (d && (d->v_length == 1) && (d->v_numdims == 1)) {
                        /* get its value */
                        wl_index->wl_word = tprintf("%e", d->v_realdata[0]);
                        tfree(vec_found);
                    }
                }
            }
        }
        /* may be inside the same wl_word */
        else if ((equal_ptr = strstr(token, "=")) != NULL) {
            vec_found = equal_ptr + 1;
            if (!cieq(vec_found, "LAST")) {
                INPevaluate(&vec_found, &err, 1);
                if (err) {
                    d = vec_get(vec_found);
                    /* Only if we have a single valued vector, replacing
                    of the rigt hand side does make sense */
                    if (d && (d->v_length == 1) && (d->v_numdims == 1)) {
                        int lhs_len = (int)(equal_ptr - token);
                        wl_index->wl_word =
                            tprintf("%.*s=%e", lhs_len, token, d->v_realdata[0]);
                        tfree(token);
                    }
                }
            }
        } else {
            ;                   // nothing
        }
        wl_index = wl_index->wl_next;
    }

    line_in = wl_flatten(wl);

    /* get output var name */
    wl_count = wl_count->wl_next;
    if (!wl_count) {
        fprintf(stdout,
                " meas %s failed!\n"
                "   unspecified output var name\n\n", line_in);
        return;
    }
    outvar = wl_count->wl_word;

    fail = get_measure2(wl, &result, NULL, FALSE);

    if (fail) {
        fprintf(stdout, " meas %s failed!\n\n", line_in);
        return;
    }

    wl_let = wl_cons(tprintf("%s = %e", outvar, result), NULL);
    com_let(wl_let);
    wl_free(wl_let);
    tfree(line_in);
}
Beispiel #7
0
void
INPpas3(CKTcircuit *ckt, card *data, INPtables *tab, TSKtask *task,
        IFparm *nodeParms, int numNodeParms)
{

    card *current;
    int error;			/* used by the macros defined above */
    char *line;			/* the part of the current line left
                                   to parse */
    char *token=NULL;		/* a token from the line */
    IFparm *prm;		/* pointer to parameter to search
                                   through array */
    IFvalue ptemp;		/* a value structure to package
                                   resistance into */
    int which;			/* which analysis we are performing */
    CKTnode *node1;		/* the first node's node pointer */

    NG_IGNORE(task);

#ifdef TRACE
    /* SDB debug statement */
    printf("In INPpas3 . . . \n");
#endif

    for(current = data; current != NULL; current = current->nextcard) {
        line = current->line;
        FREE(token);
        INPgetTok(&line,&token,1);

        if (strcmp(token,".nodeset")==0) {
            which = -1;

            for(prm = nodeParms; prm < nodeParms + numNodeParms; prm++) {
                if(strcmp(prm->keyword,"nodeset")==0) {
                    which = prm->id;
                    break;
                }
            }

            if(which == -1) {
                LITERR("nodeset unknown to simulator. \n");
                goto quit;
            }

            for(;;) {
                char *name;     /* the node's name */

                /* loop until we run out of data */
                INPgetTok(&line,&name,1);
                if( *name == '\0') {
                    FREE(name);
                    break; /* end of line */
                }

                /* If we have 'all = value' , then set all voltage nodes to 'value',
                   except for ground node at node->number 0 */
                if ( cieq(name, "all")) {
                    ptemp.rValue = INPevaluate(&line,&error,1);
                    for (node1 = ckt->CKTnodes; node1 != NULL; node1 = node1->next) {
                        if ((node1->type == SP_VOLTAGE) && (node1->number > 0))
                            IFC(setNodeParm, (ckt, node1, which, &ptemp, NULL));
                    }
                    FREE(name);
                    break;
                }
                /* check to see if in the form V(xxx) and grab the xxx */
                if( (*name == 'V' || *name == 'v') && !name[1] ) {
                    /* looks like V - must be V(xx) - get xx now*/
                    char *nodename;
                    INPgetTok(&line,&nodename,1);
                    if (INPtermInsert(ckt,&nodename,tab,&node1)!=E_EXISTS)
                        fprintf(stderr,
                                "Warning : Nodeset on non-existant node - %s\n", nodename);
                    ptemp.rValue = INPevaluate(&line,&error,1);
                    IFC(setNodeParm, (ckt, node1, which, &ptemp, NULL));
                    FREE(name);
                    continue;
                }
                LITERR(" Error: .nodeset syntax error.\n");
                FREE(name);
                break;
            }
        } else if ((strcmp(token,".ic") == 0)) {
            /* .ic */
            which = -1;
            for(prm = nodeParms; prm < nodeParms + numNodeParms; prm++) {
                if(strcmp(prm->keyword,"ic")==0) {
                    which = prm->id;
                    break;
                }
            }

            if(which==-1) {
                LITERR("ic unknown to simulator. \n");
                goto quit;
            }

            for(;;) {
                char *name;     /* the node's name */

                /* loop until we run out of data */
                INPgetTok(&line,&name,1);
                /* check to see if in the form V(xxx) and grab the xxx */
                if( *name == '\0') {
                    FREE(name);
                    break; /* end of line */
                }
                if( (*name == 'V' || *name == 'v') && !name[1] ) {
                    /* looks like V - must be V(xx) - get xx now*/
                    char *nodename;
                    INPgetTok(&line,&nodename,1);
                    if (INPtermInsert(ckt,&nodename,tab,&node1)!=E_EXISTS)
                        fprintf(stderr,
                                "Warning : IC on non-existant node - %s\n", nodename);
                    ptemp.rValue = INPevaluate(&line,&error,1);
                    IFC(setNodeParm, (ckt, node1, which, &ptemp, NULL));
                    FREE(name);
                    continue;
                }
                LITERR(" Error: .ic syntax error.\n");
                FREE(name);
                break;
            }
        }
    }
quit:
    FREE(token);
    return;
}
Beispiel #8
0
///<param name = "**line"> Input line </param>
static PTelement *PTlexer(char **line)
{
	double td;
	int err;
	static PTelement el;
	static char *specials = " \t()^+-*/,";
	static int lasttoken = TOK_END, lasttype;
	char *sbuf, *s;

	sbuf = *line;
#ifdef notdef
	printf("entering lexer, sbuf = '%s', lastoken = %d, lasttype = %d\n", sbuf, lasttoken, lasttype);
#endif
	while ((*sbuf == ' ') || (*sbuf == '\t') || (*sbuf == '='))
		sbuf++;

	switch (*sbuf)
	{
	case '\0':
		el.token = TOK_END;
		break;

	case ',':
		el.token = TOK_COMMA;
		sbuf++;
		break;

	case '-':
		if ((lasttoken == TOK_VALUE) || (lasttoken == TOK_RPAREN))
			el.token = TOK_MINUS;
		else
			el.token = TOK_UMINUS;

		sbuf++;
		break;

	case '+':
		el.token = TOK_PLUS;
		sbuf++;
		break;

	case '*':
		el.token = TOK_TIMES;
		sbuf++;
		break;

	case '/':
		el.token = TOK_DIVIDE;
		sbuf++;
		break;

	case '^':
		el.token = TOK_POWER;
		sbuf++;
		break;

	case '(':
		if (((lasttoken == TOK_VALUE) && ((lasttype == TYP_NUM))) || (lasttoken == TOK_RPAREN))
		{
			el.token = TOK_END;
		}
		else
		{
			el.token = TOK_LPAREN;
			sbuf++;
		}
		break;

	case ')':
		el.token = TOK_RPAREN;
		sbuf++;
		break;

	default:
		if ((lasttoken == TOK_VALUE) || (lasttoken == TOK_RPAREN))
		{
			el.token = TOK_END;
			break;
		}

		td = INPevaluate(&sbuf, &err, 0);
		if (err == OK)
		{
			el.token = TOK_VALUE;
			el.type = TYP_NUM;
			el.value.real = td;
		}
		else
		{
			el.token = TOK_VALUE;
			el.type = TYP_STRING;

			for (s = sbuf; *s; s++)
			{
				if (index(specials, *s))
					break;
			}

			el.value.string = MALLOC(s - sbuf + 1);
			strncpy(el.value.string, sbuf, s - sbuf);
			el.value.string[s - sbuf] = '\0';
			sbuf = s;
		}
	}

	lasttoken = el.token;
	lasttype = el.type;

	*line = sbuf;

	/* printf("PTlexer: token = %d, type = %d, left = '%s'\n",
			el.token, el.type, sbuf); */

	return (&el);
}
Beispiel #9
0
void INP2C(CKTcircuit *ckt, INPtables * tab, struct card *current)
{

/* parse a capacitor card */
/* Cname <node> <node> [<val>] [<mname>] [IC=<val>] */

    static int mytype = -1; /* the type we determine capacitors are */
    int type = 0;        /* the type the model says it is */
    char *line;          /* the part of the current line left to parse */
    char *saveline;      /* ... just in case we need to go back... */
    char *name;          /* the resistor's name */
    char *model;         /* the name of the capacitor's model */
    char *nname1;        /* the first node's name */
    char *nname2;        /* the second node's name */
    CKTnode *node1;      /* the first node's node pointer */
    CKTnode *node2;      /* the second node's node pointer */
    double val;          /* temp to held resistance */
    int error;           /* error code temporary */
    int error1;          /* secondary error code temporary */
    INPmodel *thismodel; /* pointer to model structure describing our model */
    GENmodel *mdfast = NULL; /* pointer to the actual model */
    GENinstance *fast;   /* pointer to the actual instance */
    IFvalue ptemp;       /* a value structure to package resistance into */
    int waslead;         /* flag to indicate that funny unlabeled number was found */
    double leadval;      /* actual value of unlabeled number */
    IFuid uid;           /* uid for default cap model */

#ifdef TRACE
    printf("In INP2C, Current line: %s\n", current->line);
#endif

    if (mytype < 0) {
        if ((mytype = INPtypelook("Capacitor")) < 0) {
            LITERR("Device type Capacitor not supported by this binary\n");
            return;
        }
    }
    line = current->line;
    INPgetNetTok(&line, &name, 1);
    INPinsert(&name, tab);
    INPgetNetTok(&line, &nname1, 1);
    INPtermInsert(ckt, &nname1, tab, &node1);
    INPgetNetTok(&line, &nname2, 1);
    INPtermInsert(ckt, &nname2, tab, &node2);
    val = INPevaluate(&line, &error1, 1);
    
    saveline = line;
    
    INPgetNetTok(&line, &model, 1);
    
    if (*model && (strcmp(model, "c") != 0)) {
    /* token isn't null */
      if (INPlookMod(model)) {
          /* If this is a valid model connect it */
          INPinsert(&model, tab);
          current->error = INPgetMod(ckt, model, &thismodel, tab);
          if (thismodel != NULL) {
          if (mytype != thismodel->INPmodType) {
              LITERR("incorrect model type");
              return;
          }
          mdfast = thismodel->INPmodfast;
          type = thismodel->INPmodType;
          }
      } else {
          tfree(model);
          /* It is not a model */
          line = saveline;    /* go back */
          type = mytype;
          if (!tab->defCmod) {    /* create default C model */
          IFnewUid(ckt, &uid, NULL, "C", UID_MODEL, NULL);
          IFC(newModel, (ckt, type, &(tab->defCmod), uid));
          }
          mdfast = tab->defCmod;
      }
      IFC(newInstance, (ckt, mdfast, &fast, name));
    } else {
      tfree(model);
      /* The token is null and a default model will be created */
      type = mytype;
      if (!tab->defCmod) {
          /* create default C model */
          IFnewUid(ckt, &uid, NULL, "C", UID_MODEL, NULL);
          IFC(newModel, (ckt, type, &(tab->defCmod), uid));
      }
      IFC(newInstance, (ckt, tab->defCmod, &fast, name));
      if (error1 == 1) {		/* was a c=val construction */
        val = INPevaluate(&line, &error1, 1);	/* [<val>] */
#ifdef TRACE
        printf ("In INP2C, C=val construction: val=%g\n", val);
#endif
      }
    }
    
    if (error1 == 0) {        /* Looks like a number */
      ptemp.rValue = val;
      GCA(INPpName, ("capacitance", &ptemp, ckt, type, fast));
    } 
    
    IFC(bindNode, (ckt, fast, 1, node1));
    IFC(bindNode, (ckt, fast, 2, node2));
    PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab));
    if (waslead) {
      ptemp.rValue = leadval;
      GCA(INPpName, ("capacitance", &ptemp, ckt, type, fast));
    }

    return;
}
Beispiel #10
0
void INP2R(void *ckt, INPtables * tab, card * current)
{
/* parse a resistor card */
/* Rname <node> <node> [<val>][<mname>][w=<val>][l=<val>][ac=<val>] */

    int mytype;			/* the type we determine resistors are */
    int type = 0;		/* the type the model says it is */
    char *line;			/* the part of the current line left to parse */
    char *saveline;		/* ... just in case we need to go back... */
    char *name;			/* the resistor's name */
    char *model;		/* the name of the resistor's model */
    char *nname1;		/* the first node's name */
    char *nname2;		/* the second node's name */
    void *node1;		/* the first node's node pointer */
    void *node2;		/* the second node's node pointer */
    double val;			/* temp to held resistance */
    int error;			/* error code temporary */
    int error1;			/* secondary error code temporary */
    INPmodel *thismodel;	/* pointer to model structure describing our model */
    void *mdfast = NULL;	/* pointer to the actual model */
    void *fast;			/* pointer to the actual instance */
    IFvalue ptemp;		/* a value structure to package resistance into */
    int waslead;		/* flag to indicate that funny unlabeled number was found */
    double leadval;		/* actual value of unlabeled number */
    IFuid uid;			/* uid for default model */

    char *s,*t;/* Temporary buffer and pointer for translation */
    int i;
	
#ifdef TRACE
    printf("In INP2R()\n");
    printf("  Current line: %s\n",current->line);
#endif

    mytype = INPtypelook("Resistor");
    if (mytype < 0) {
	LITERR("Device type Resistor not supported by this binary\n");
	return;
    }
    line = current->line;
    INPgetTok(&line, &name, 1);			/* Rname */
    INPinsert(&name, tab);
    INPgetNetTok(&line, &nname1, 1);		/* <node> */
    INPtermInsert(ckt, &nname1, tab, &node1);
    INPgetNetTok(&line, &nname2, 1);		/* <node> */
    INPtermInsert(ckt, &nname2, tab, &node2);
    val = INPevaluate(&line, &error1, 1);	/* [<val>] */
    /* either not a number -> model, or
     * follows a number, so must be a model name
     * -> MUST be a model name (or null)
     */
    
    saveline = line;		/* save then old pointer */
    
#ifdef TRACE
    printf("Begining tc=xxx yyyy search and translation in '%s'\n", line);
#endif /* TRACE */    
    
    /* This routine translates "tc=xxx yyy" to "tc=xxx tc2=yyy".
       This is a re-write of the routine originally proposed by Hitoshi tanaka.
       In my version we simply look for the first occurence of 'tc' followed
       by '=' followed by two numbers. If we find it then we splice in "tc2=".
       sjb - 2005-05-09 */
    for(s=line; *s; s++) { /* scan the remainder of the line */
	
	/* reject anything other than "tc" */
	if(*s!='t') continue;
	s++;
	if(*s!='c') continue;
	s++;
	
	/* skip any white space */
	while(isspace(*s)) s++;
	      
	/* reject if not '=' */
	if(*s!='=') continue;
	s++;
	
	/* skip any white space */
	while(isspace(*s)) s++;
	
	/* if we now have +, - or a decimal digit then assume we have a number,
	   otherwise reject */
	if((*s!='+') && (*s!='-') && !isdigit(*s)) continue;
	s++;
	
	/* look for next white space or null */
	while(!isspace(*s) && *s) s++;
	
	/* reject whole line if null (i.e not white space) */
	if(*s==0) break;
	s++;
	
	/* remember this location in the line.
	   Note that just before this location is a white space character. */
	t = s;
	
	/* skip any additional white space */
	while(isspace(*s)) s++;
	
	/* if we now have +, - or a decimal digit then assume we have the 
	    second number, otherwise reject */
	if((*s!='+') && (*s!='-') && !isdigit(*s)) continue;
	
	/* if we get this far we have met all are criterea,
	   so now we splice in a "tc2=" at the location remembered above. */
	
	/* first alocate memory for the new longer line */
	i = strlen(current->line);  /* length of existing line */	
	line = tmalloc(i + 4 + 1);  /* alocate enough for "tc2=" & terminating NULL */
	if(line == NULL) {
	    /* failed to allocate memory so we recover rather crudely
	       by rejecting the translation */
	    line = saveline;
	    break;
	}
	
	/* copy first part of line */
	i -= strlen(t);
	strncpy(line,current->line,i);
	line[i]=0;  /* terminate */
	
	/* add "tc2=" */
	strcat(line, "tc2=");
	
	/* add rest of line */
	strcat(line, t);
	
	/* calculate our saveline position in the new line */
	saveline = line + (saveline - current->line);
	
	/* replace old line with new */
	tfree(current->line);
	current->line = line;
	line = saveline;
    }
    
#ifdef TRACE
    printf("(Translated) Res line: %s\n",current->line);
#endif

    INPgetTok(&line, &model, 1);

    if (*model) {
	/* token isn't null */
	if (INPlookMod(model)) {
	    /* If this is a valid model connect it */
	    INPinsert(&model, tab);
	    thismodel = (INPmodel *) NULL;
	    current->error = INPgetMod(ckt, model, &thismodel, tab);
	    if (thismodel != NULL) {
		if (mytype != thismodel->INPmodType) {
		    LITERR("incorrect model type for resistor");
		    return;
		}
		mdfast = thismodel->INPmodfast;
		type = thismodel->INPmodType;
	    }
	} else {
	    tfree(model);
	    /* It is not a model */
	    line = saveline;	/* go back */
	    type = mytype;
	    if (!tab->defRmod) {	/* create default R model */
		IFnewUid(ckt, &uid, (IFuid) NULL, "R", UID_MODEL,
			 (void **) NULL);
		IFC(newModel, (ckt, type, &(tab->defRmod), uid));
	    }
	    mdfast = tab->defRmod;
	}
	IFC(newInstance, (ckt, mdfast, &fast, name));
    } else {
	tfree(model);
	/* The token is null and a default model will be created */
	type = mytype;
	if (!tab->defRmod) {
	    /* create default R model */
	    IFnewUid(ckt, &uid, (IFuid) NULL, "R", UID_MODEL,
		     (void **) NULL);
	    IFC(newModel, (ckt, type, &(tab->defRmod), uid));
	}
	IFC(newInstance, (ckt, tab->defRmod, &fast, name));
    }

    if (error1 == 0) {		/* got a resistance above */
	ptemp.rValue = val;
	GCA(INPpName, ("resistance", &ptemp, ckt, type, fast))
    }