⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 device.c

📁 spice中支持多层次元件模型仿真的可单独运行的插件源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	    p->id, &val, &val);    else	(*ft_sim->askModelQuest)(ft_curckt->ci_ckt, dg->model,	    p->id, &val, &val);    if (p->dataType & IF_VECTOR)	n = val.v.numValue;    else	n = 1;    if (((p->dataType & IF_VARTYPES) & ~IF_VECTOR) == IF_COMPLEX)	n *= 2;    if (i >= n) {	if (i == 0)	    printf("         -");	else	    printf("          ");	return 0;    }    if (p->dataType & IF_VECTOR) {	switch ((p->dataType & IF_VARTYPES) & ~IF_VECTOR) {	    case IF_FLAG:		    printf(" % 9d", val.v.vec.iVec[i]);		    break;	    case IF_INTEGER:		    printf(" % 9d", val.v.vec.iVec[i]);		    break;	    case IF_REAL:		    printf(" % 9.3g", val.v.vec.rVec[i]);		    break;	    case IF_COMPLEX:		    if (!(i % 2))			    printf(" % 9.3g", val.v.vec.cVec[i / 2].real);		    else			    printf(" % 9.3g", val.v.vec.cVec[i / 2].imag);		    break;	    case IF_STRING:		    printf(" % 9.9s", val.v.vec.sVec[i]);		    break;	    case IF_INSTANCE:		    printf(" % 9.9s", val.v.vec.uVec[i]);		    break;	    default:		    printf(" ******** ");	}    } else {	switch ((p->dataType & IF_VARTYPES) & ~IF_VECTOR) {	    case IF_FLAG:		    printf(" % 9d", val.iValue);		    break;	    case IF_INTEGER:		    printf(" % 9d", val.iValue);		    break;	    case IF_REAL:		    printf(" % 9.3g", val.rValue);		    break;	    case IF_COMPLEX:		    if (i % 2)			    printf(" % 9.3g", val.cValue.real);		    else			    printf(" % 9.3g", val.cValue.imag);		    break;	    case IF_STRING:		    printf(" % 9.9s", val.sValue);		    break;	    case IF_INSTANCE:		    printf(" % 9.9s ", val.uValue);		    break;	    default:		    printf(" ******** ");	}    }    return n - 1;}/* (old "show" command) * Display various device parameters.  The syntax of this command is  *   show devicelist : parmlist * where devicelist can be "all", the name of a device, a string like r*, * which means all devices with names that begin with 'r', repeated one * or more times.   The parms are names of parameters that are (hopefully) * valid for all the named devices, or "all". */voidold_show(wl)    wordlist *wl;{    wordlist *devs, *parms, *tw, *ww;    struct variable *v;    char *nn;    devs = wl;    while (wl && !eq(wl->wl_word, ":"))        wl = wl->wl_next;    if (!wl)        parms = NULL;    else {        if (wl->wl_prev)            wl->wl_prev->wl_next = NULL;        parms = wl->wl_next;        if (parms)            parms->wl_prev = NULL;    }    /* Now expand the devicelist... */    for (tw = NULL; devs; devs = devs->wl_next) {        inp_casefix(devs->wl_word);        tw = wl_append(tw, devexpand(devs->wl_word));    }        devs = tw;    for (tw = parms; tw; tw = tw->wl_next)        if (eq(tw->wl_word, "all"))            break;    if (tw)        parms = NULL;    /* This is a crock... */    if (!devs)        devs = cp_cctowl(ft_curckt->ci_devices);    out_init();    while (devs) {        out_printf("%s:\n", devs->wl_word);        if (parms) {            for (tw = parms; tw; tw = tw->wl_next) {                nn = copy(devs->wl_word);                v = (*if_getparam)(ft_curckt->ci_ckt,			&nn, tw->wl_word, 0, 0);		if (!v)		    v = (*if_getparam)(ft_curckt->ci_ckt,			    &nn, tw->wl_word, 0, 1);                if (v) {                    out_printf("\t%s =", tw->wl_word);                    for (ww = cp_varwl(v); ww; ww =                            ww->wl_next)                        out_printf(" %s", ww->wl_word);                    out_send("\n");                }            }        } else {            nn = copy(devs->wl_word);            v = (*if_getparam)(ft_curckt->ci_ckt, &nn, "all", 0, 0);	    if (!v)		v = (*if_getparam)(ft_curckt->ci_ckt, &nn, "all", 0, 1);            while (v) {                out_printf("\t%s =", v->va_name);                for (ww = cp_varwl(v); ww; ww = ww->wl_next)                    out_printf(" %s", ww->wl_word);                out_send("\n");                v = v->va_next;            }        }        devs = devs->wl_next;    }    return;}/* Alter a device parameter.  The new syntax here is *	alter @device[parameter] = expr *	alter device = expr *	alter device parameter = expr * expr must be real (complex isn't handled right now, integer is fine though, * but no strings ... for booleans, use 0/1). */voidcom_alter(wl)    wordlist *wl;{    if (!wl) {	fprintf(cp_err, "usage: alter dev param = expression\n");	fprintf(cp_err, "  or   alter @dev[param] = expression\n");	fprintf(cp_err, "  or   alter dev = expression\n");	return;    }    com_alter_common(wl, 0);}voidcom_altermod(wl)    wordlist *wl;{    com_alter_common(wl, 1);}com_alter_common(wl, do_model)    wordlist *wl;    int	do_model;{#ifdef notdef    struct variable var, *nv, *prev;    double *dd;#endif    wordlist *eqword, *words;    char *dev, *p;    char *param;    struct dvec *dv;    struct pnode *names, *n2;    int err, type;    if (!ft_curckt) {        fprintf(cp_err, "Error: no circuit loaded\n");        return;    }    words = wl;    while (words) {	p = words->wl_word;	eqword = words;	words = words->wl_next;	if (eq(p, "=")) {	    break;	}    }    if (!words) {	fprintf(cp_err, "Error: no assignment found.\n");	return;    }    /* device parameter = expr       device = expr       @dev[param] = expr     */    dev = NULL;    param = NULL;    words = wl;    while (words != eqword) {	p = words->wl_word;	if (param) {	    fprintf(cp_err, "Error: excess parameter name \"%s\" ignored.\n",		p);	} else if (dev) {	    param = words->wl_word;	} else if (*p == '@' || *p == '#') {	    dev = p + 1;	    p = index(p, '[');	    if (p) {		*p++ = 0;		param = p;		p = index(p, ']');		if (p)		    *p = 0;	    }	} else {	    dev = p;	}	words = words->wl_next;    }    if (!dev) {	fprintf(cp_err, "Error: no model or device name provided.\n" );	return;    }    words = eqword->wl_next;    names = ft_getpnames(words, false);    if (!names) {	fprintf(cp_err, "Error: cannot parse new parameter value.\n");	return;    }    dv = ft_evaluate(names);    free_pnode(names);    if (!dv)	return;    if (dv->v_length < 1) {	fprintf(cp_err, "Error: cannot evaluate new parameter value.\n");	return;    }    if_setparam(ft_curckt->ci_ckt, &dev, param, dv, do_model);    /* Vector data (dv) should get garbage-collected. */    return;#ifdef notdef    while (wl) {	param = wl->wl_word;	wl = wl->wl_next;	if (!wl) {	    val = param;	    param = NULL;	} else {	    val = wl->wl_word;	    wl = wl->wl_next;	}	/* Now figure out what the value should be... */	if (eq(val, "true")) {	    var.va_type = VT_BOOL;	    var.va_bool = true;	} else if (eq(val, "false")) { 	    var.va_type = VT_BOOL;	    var.va_bool = false;	} else if (eq(val, "[")) { 	    var.va_type = VT_LIST;	    prev = NULL;	    while (wl && !eq(wl->wl_word, "]")) {		val = wl->wl_word;		nv = alloc(struct variable);		if (dd = ft_numparse(&val, false)) {			nv->va_type = VT_REAL;			nv->va_real = *dd;		} else {			fprintf(cp_err, "Error: \"%s\" is not a number\n", val);			break;		}		if (!prev)		    var.va_vlist = nv;		else		    prev->va_next = nv;		nv->va_next = NULL;		wl = wl->wl_next;		prev = nv;	    }	    if (wl && eq(wl->wl_word, "]")) {		wl = wl->wl_next;	    } else {		while (nv) {			prev = nv->va_next;			tfree(nv);			nv = prev;		}		return;	    }	} else if (dd = ft_numparse(&val, false)) {	    var.va_type = VT_REAL;	    var.va_real = *dd;	} else {	    var.va_type = VT_STRING;	    var.va_string = val;	}        if_setparam(ft_curckt->ci_ckt, &dev, param, &var, do_model);	if (var.va_type == VT_LIST) {	    for (nv = var.va_vlist; nv; nv = prev) {		prev = nv->va_next;		tfree(nv);	    }	}    }#endif}/* Given a device name, possibly with wildcards, return the matches. */static wordlist *devexpand(name)    char *name;{    wordlist *wl, *devices, *tw;    if (index(name, '*') || index(name, '[') || index(name, '?')) {        devices = cp_cctowl(ft_curckt->ci_devices);        for (wl = NULL; devices; devices = devices->wl_next)            if (cp_globmatch(name, devices->wl_word)) {                tw = alloc(struct wordlist);                if (wl) {                    wl->wl_prev = tw;                    tw->wl_next = wl;                    wl = tw;                } else                    wl = tw;                wl->wl_word = devices->wl_word;            }    } else if (eq(name, "all")) {        wl = cp_cctowl(ft_curckt->ci_devices);    } else {        wl = alloc(struct wordlist);        wl->wl_word = name;    }    wl_sort(wl);    return (wl);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -