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

📄 postcoms.c

📁 spice中支持多层次元件模型仿真的可单独运行的插件源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    else        names = ft_getpnames(&all, true);    if (names == NULL)        return;    for (n = names; n; n = n->pn_next) {        d = ft_evaluate(n);        if (!d)            return;        if (vecs)            lv->v_link2 = d;        else            vecs = d;        for (lv = d; lv->v_link2; lv = lv->v_link2)            ;    }    /* Now we have to write them out plot by plot. */    while (vecs) {        tpl = vecs->v_plot;        tpl->pl_written = true;        end = NULL;        bcopy((char *) tpl, (char *) &newplot, sizeof (struct plot));        scalefound = false;        /* Figure out how many vectors are in this plot. Also look         * for the scale, or a copy of it, which may have a different         * name.         */        for (d = vecs; d; d = d->v_link2) {            if (d->v_plot == tpl) {                vv = vec_copy(d);                /* Note that since we are building a new plot                 * we don't want to vec_new this one...                 */                vv->v_name = vec_basename(vv);                if (end)                    end->v_next = vv;                else                    end = newplot.pl_dvecs = vv;                end = vv;                if (vec_eq(d, tpl->pl_scale)) {                    newplot.pl_scale = vv;                    scalefound = true;                }            }        }        end->v_next = NULL;        /* Maybe we shouldn't make sure that the default scale is         * present if nobody uses it.         */        if (!scalefound) {            newplot.pl_scale = vec_copy(tpl->pl_scale);            newplot.pl_scale->v_next = newplot.pl_dvecs;            newplot.pl_dvecs = newplot.pl_scale;        }        /* Now let's go through and make sure that everything that          * has its own scale has it in the plot.         */        for (;;) {            scalefound = false;            for (d = newplot.pl_dvecs; d; d = d->v_next) {                if (d->v_scale) {                    for (vv = newplot.pl_dvecs; vv; vv =                            vv->v_next)                        if (vec_eq(vv, d->v_scale))                            break;                    /* We have to grab it... */                    vv = vec_copy(d->v_scale);                    vv->v_next = newplot.pl_dvecs;                    newplot.pl_dvecs = vv;                    scalefound = true;                }            }            if (!scalefound)                break;            /* Otherwise loop through again... */        }        if (ascii)            raw_write(file, &newplot, appendwrite, false);        else            raw_write(file, &newplot, appendwrite, true);        /* Now throw out the vectors we have written already... */        for (d = vecs, lv = NULL;  d; d = d->v_link2)            if (d->v_plot == tpl) {                if (lv) {                    lv->v_link2 = d->v_link2;                    d = lv;                } else                    vecs = d->v_link2;            } else                lv = d;        /* If there are more plots we want them appended... */        appendwrite = true;    }    return;}/* If the named vectors have more than 1 dimension, then consider * to be a collection of one or more matrices.  This command transposes * each named matrix. */voidcom_transpose(wl)    wordlist *wl;{    struct dvec *d;    char *s;    while (wl) {        s = cp_unquote(wl->wl_word);        d = vec_get(s);        if (d == NULL)            fprintf(cp_err, "Error: no such vector as %s.\n",                 wl->wl_word);        else            while (d) {                vec_transpose(d);                d = d->v_link2;            }        if (wl->wl_next == NULL)            return;        wl = wl->wl_next;    }}/* Set the default scale to the named vector.  If no vector named, * find and print the default scale. */voidcom_setscale(wl)    wordlist *wl;{    struct dvec *d;    char *s;    if (plot_cur) {	if (wl) {	    s = cp_unquote(wl->wl_word);	    d = vec_get(s);	    if (d == NULL)		fprintf(cp_err, "Error: no such vector as %s.\n", 		    wl->wl_word);	    else		plot_cur->pl_scale = d;	} else if (plot_cur->pl_scale) {	    pvec(plot_cur->pl_scale);	}    } else {	fprintf(cp_err, "Error: no current plot.\n");    }}/* Display vector status, etc.  Note that this only displays stuff from the * current plot, and you must do a setplot to see the rest of it. */voidcom_display(wl)    wordlist *wl;{    struct dvec *d;    struct dvec **dvs;    int len = 0, i = 0;    bool b;    char *s;    /* Maybe he wants to know about just a few vectors. */    out_init();    while (wl) {        s = cp_unquote(wl->wl_word);        d = vec_get(s);        if (d == NULL)            fprintf(cp_err, "Error: no such vector as %s.\n",                 wl->wl_word);        else            while (d) {                pvec(d);                d = d->v_link2;            }        if (wl->wl_next == NULL)            return;        wl = wl->wl_next;    }    if (plot_cur)        for (d = plot_cur->pl_dvecs; d; d = d->v_next)            len++;    if (len == 0) {        fprintf(cp_out, "There are no vectors currently active.\n");        return;    }    out_printf("Here are the vectors currently active:\n\n");    dvs = (struct dvec **) tmalloc(len * (sizeof (struct dvec *)));    for (d = plot_cur->pl_dvecs, i = 0; d; d = d->v_next, i++)        dvs[i] = d;    if (!cp_getvar("nosort", VT_BOOL, (char *) &b))        qsort((char *) dvs, len, sizeof (struct dvec *), dcomp);    out_printf("Title: %s\n",  plot_cur->pl_title);    out_printf("Name: %s (%s)\nDate: %s\n\n",         plot_cur->pl_typename, plot_cur->pl_name,         plot_cur->pl_date);    for (i = 0; i < len; i++) {        d = dvs[i];        pvec(d);    }    return;}static voidpvec(d)    struct dvec *d;{    int i;    char buf[BSIZE_SP], buf2[BSIZE_SP];    sprintf(buf, "    %-20s: %s, %s, %d long", d->v_name,            ft_typenames(d->v_type), isreal(d) ? "real" :            "complex", d->v_length);    if (d->v_flags & VF_MINGIVEN) {        sprintf(buf2, ", min = %lg", d->v_minsignal);        strcat(buf, buf2);    }    if (d->v_flags & VF_MAXGIVEN) {        sprintf(buf2, ", max = %lg", d->v_maxsignal);        strcat(buf, buf2);    }    switch (d->v_gridtype) {        case GRID_LOGLOG:        strcat(buf, ", grid = loglog");        break;        case GRID_XLOG:        strcat(buf, ", grid = xlog");        break;        case GRID_YLOG:        strcat(buf, ", grid = ylog");        break;        case GRID_POLAR:        strcat(buf, ", grid = polar");        break;        case GRID_SMITH:        strcat(buf, ", grid = smith (xformed)");        break;        case GRID_SMITHGRID:        strcat(buf, ", grid = smithgrid (not xformed)");        break;    }    switch (d->v_plottype) {        case PLOT_COMB:        strcat(buf, ", plot = comb");        break;        case PLOT_POINT:        strcat(buf, ", plot = point");        break;    }    if (d->v_defcolor) {        sprintf(buf2, ", color = %s", d->v_defcolor);        strcat(buf, buf2);    }    if (d->v_scale) {        sprintf(buf2, ", scale = %s", d->v_scale->v_name);        strcat(buf, buf2);    }    if (d->v_numdims > 1) {	sprintf(buf2, ", dims = [%s]", dimstring(d->v_dims, d->v_numdims));        strcat(buf, buf2);    }    if (d->v_plot->pl_scale == d) {        strcat(buf, " [default scale]\n");    } else {        strcat(buf, "\n");    }    out_send(buf);    return;}#ifdef notdef/* Set the current working plot. */voidcom_splot(wl)    wordlist *wl;{    struct plot *p;    char buf[BSIZE_SP], *s;    if (wl == NULL) {        fprintf(cp_out, "\tType the name of the desired plot:\n\n");        fprintf(cp_out, "\tnew\tNew plot\n");        for (p = plot_list; p; p = p->pl_next) {            if (plot_cur == p)                fprintf(cp_out, "Current");            fprintf(cp_out, "\t%s\t%s (%s)\n",                p->pl_typename, p->pl_title, p->pl_name);        }        fprintf(cp_out, "? ");        (void) fflush(cp_out);        (void) fgets(buf, BSIZE_SP, cp_in);        clearerr(cp_in);        for (s = buf; *s && !isspace(*s); s++)            ;        *s = '\0';    } else {        (void) strcpy(buf, wl->wl_word);    }    if (prefix("new", buf)) {        p = plot_alloc("unknown");        p->pl_title = copy("Anonymous");        p->pl_name = copy("unknown");        p->pl_next = plot_list;        plot_list = p;    } else {        for (p = plot_list; p; p = p->pl_next)            if (plot_prefix(buf, p->pl_typename))                break;        if (!p) {            fprintf(cp_err, "Error: no such plot.\n");            return;        }    }    plot_cur->pl_ccom = cp_kwswitch(CT_VECTOR, p->pl_ccom);    plot_cur = p;    plot_docoms(plot_cur->pl_commands);    if (wl)        fprintf(cp_out, "%s %s (%s)\n", p->pl_typename, p->pl_title,                p->pl_name);    return;}#endif/* For the sort in display. */static intdcomp(v1, v2)    struct dvec **v1, **v2;{    return (strcmp((*v1)->v_name, (*v2)->v_name));}#ifdef notdef/* Figure out what the name of this vector should be (if it is a number, * then make it 'V' or 'I')... Note that the data is static. */static char *dname(d)    struct dvec *d;{    static char buf[128];    char *s;    for (s = d->v_name; *s; s++)        if (!isdigit(*s))            return (d->v_name);    switch (d->v_type) {        case SV_VOLTAGE:            (void) sprintf(buf, "V(%s)", d->v_name);            return (buf);        case SV_CURRENT:            (void) sprintf(buf, "I(%s)", d->v_name);            return (buf);    }    return (d->v_name);}#endif/* Take a set of vectors and form a new vector of the nth elements of each. */voidcom_cross(wl)    wordlist *wl;{    char *newvec, *s;    struct dvec *n, *v, *vecs = NULL, *lv = NULL;    struct pnode *pn;    int i, ind;    bool comp = false;    double *d;    newvec = wl->wl_word;    wl = wl->wl_next;    s = wl->wl_word;    if (!(d = ft_numparse(&s, false))) {        fprintf(cp_err, "Error: bad number %s\n", wl->wl_word);        return;    }    if ((ind = *d) < 0) {        fprintf(cp_err, "Error: bad index %d\n", ind);        return;    }    wl = wl->wl_next;    pn = ft_getpnames(wl, true);    while (pn) {        if (!(n = ft_evaluate(pn)))            return;        if (!vecs)            vecs = lv = n;        else            lv->v_link2 = n;        for (lv = n; lv->v_link2; lv = lv->v_link2)            ;        pn = pn->pn_next;    }    for (n = vecs, i = 0; n; n = n->v_link2) {        if (iscomplex(n))            comp = true;        i++;    }        vec_remove(newvec);    v = alloc(struct dvec);    v->v_name = copy(newvec);    v->v_type = vecs ? vecs->v_type : SV_NOTYPE;    v->v_length = i;    v->v_flags |= VF_PERMANENT;    v->v_flags = comp ? VF_COMPLEX : VF_REAL;    if (comp)        v->v_compdata = (complex *) tmalloc(i * sizeof (complex));    else        v->v_realdata = (double *) tmalloc(i * sizeof (double));        /* Now copy the ind'ths elements into this one. */    for (n = vecs, i = 0; n; n = n->v_link2, i++)        if (n->v_length > ind) {            if (comp) {                realpart(&v->v_compdata[i]) =                        realpart(&n->v_compdata[ind]);                imagpart(&v->v_compdata[i]) =                        imagpart(&n->v_compdata[ind]);            } else                v->v_realdata[i] = n->v_realdata[ind];        } else {            if (comp) {                realpart(&v->v_compdata[i]) = 0.0;                imagpart(&v->v_compdata[i]) = 0.0;            } else                v->v_realdata[i] = 0.0;        }    vec_new(v);    v->v_flags |= VF_PERMANENT;    cp_addkword(CT_VECTOR, v->v_name);    return;}voidcom_destroy(wl)    wordlist *wl;{    struct plot *pl, *npl = NULL;    if (!wl)        killplot(plot_cur);    else if (eq(wl->wl_word, "all")) {        for (pl = plot_list; pl; pl = npl) {            npl = pl->pl_next;            if (!eq(pl->pl_typename, "const"))                killplot(pl);        }    } else {        while (wl) {            for (pl = plot_list; pl; pl = pl->pl_next)                if (eq(pl->pl_typename, wl->wl_word))                    break;            if (pl)                killplot(pl);            else                fprintf(cp_err, "Error: no such plot %s\n",                        wl->wl_word);            wl = wl->wl_next;        }    }    return;}static voidkillplot(pl)    struct plot *pl;{    struct dvec *v, *nv = NULL;    struct plot *op;    if (eq(pl->pl_typename, "const")) {        fprintf(cp_err, "Error: can't destroy the constant plot\n");        return;    }    for (v = pl->pl_dvecs; v; v = nv) {        nv = v->v_next;        vec_free(v);    }    if (pl == plot_list) {        plot_list = pl->pl_next;        if (pl == plot_cur)            plot_cur = plot_list;    } else {        for (op = plot_list; op; op = op->pl_next)            if (op->pl_next == pl)                break;        if (!op)            fprintf(cp_err,                "Internal Error: kill plot -- not in list\n");        op->pl_next = pl->pl_next;        if (pl == plot_cur)            plot_cur = op;    }    tfree(pl->pl_title);    tfree(pl->pl_name);    tfree(pl->pl_typename);    wl_free(pl->pl_commands);    /* Never mind about the rest... */    return;}voidcom_splot(wl)    wordlist *wl;{    struct plot *pl;    char buf[BSIZE_SP], *s, *t;    if (wl) {        plot_setcur(wl->wl_word);        return;    }    fprintf(cp_out, "\tType the name of the desired plot:\n\n");    fprintf(cp_out, "\tnew\tNew plot\n");    for (pl = plot_list; pl; pl = pl->pl_next)        fprintf(cp_out, "%s%s\t%s (%s)\n",                (pl == plot_cur) ? "Current " : "\t",                pl->pl_typename, pl->pl_title, pl->pl_name);        fprintf(cp_out, "? ");    if (!fgets(buf, BSIZE_SP, cp_in)) {        clearerr(cp_in);        return;    }    t = buf;    if (!(s = gettok(&t)))        return;    plot_setcur(s);    return;}

⌨️ 快捷键说明

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